[GHC] #14206: Add bit deposit and bit extraction primops

GHC ghc-devs at haskell.org
Sat Sep 9 11:26:25 UTC 2017


#14206: Add bit deposit and bit extraction primops
-------------------------------------+-------------------------------------
           Reporter:  newhoggy       |             Owner:  (none)
               Type:  feature        |            Status:  new
  request                            |
           Priority:  normal         |         Milestone:
          Component:  Compiler       |           Version:  8.2.1
           Keywords:                 |  Operating System:  Unknown/Multiple
       Architecture:                 |   Type of failure:  None/Unknown
  Unknown/Multiple                   |
          Test Case:                 |        Blocked By:
           Blocking:                 |   Related Tickets:
Differential Rev(s):                 |         Wiki Page:
-------------------------------------+-------------------------------------
 Modern CPUs (on x86, Haswell and newer) have a PDEP instruction for
 efficient bit deposit and a PEXT instruction for efficient bit extraction.
 These instructions can be used to implement various data structures.

 I propose we add the following set of primops

 {{{#!hs
 pdep8#  :: Word#   -> Word#   -> Word#
 pdep16# :: Word#   -> Word#   -> Word#
 pdep32# :: Word#   -> Word#   -> Word#
 pdep64# :: Word64# -> Word64# -> Word64#
 pdep#   :: Word#   -> Word#   -> Word#

 pext8#  :: Word#   -> Word#   -> Word#
 pext16# :: Word#   -> Word#   -> Word#
 pext32# :: Word#   -> Word#   -> Word#
 pext64# :: Word64# -> Word64# -> Word64#
 pext#   :: Word#   -> Word#   -> Word#
 }}}

 Each primop compiles into either a single PDEP/PEXT instruction or a call
 to some fallback function, implemented in C.

 For reference, see the following library that implements FFI wrapper
 32-bit and 64-bit functions for these instructions:

 https://github.com/haskell-works/hw-prim-bits

-- 
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14206>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list