[GHC] #7860: Add more bit fiddling functions to 'integer-gmp'

GHC ghc-devs at haskell.org
Sun Jun 9 19:39:50 CEST 2013


#7860: Add more bit fiddling functions to 'integer-gmp'
--------------------------------+-------------------------------------------
  Reporter:  lebedev            |          Owner:                  
      Type:  feature request    |         Status:  new             
  Priority:  normal             |      Milestone:                  
 Component:  libraries (other)  |        Version:  7.6.3           
Resolution:                     |       Keywords:  gmp             
        Os:  Unknown/Multiple   |   Architecture:  Unknown/Multiple
   Failure:  None/Unknown       |     Difficulty:  Unknown         
  Testcase:                     |      Blockedby:                  
  Blocking:                     |        Related:  #3489           
--------------------------------+-------------------------------------------

Comment(by lebedev):

 Well, it looks like it's always safe to clear bit in a small-ish integer
 using operations on Int# and Word#:

 {{{
 clearBitInteger :: Integer -> Int# -> Integer
 clearBitInteger (S# j) i   =
     -- We can always safely celear a bit of a _small_ integer.
     let !mask =
             int2Word# (1# `iShiftL#` i) `xor#` int2Word# (negateInt# 1#)
     in S# (word2Int# (int2Word# j `and#` mask))
 clearBitInteger (J# s d) i =
     let !(# s', d' #) = clearBitInteger# s d i in J# s' d'
 }}}

 What do you think? I can modify {{{setBitInteger}}} in a similar way.

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/7860#comment:7>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler



More information about the ghc-tickets mailing list