[GHC] #14872: Hex Literals in GHC Core

GHC ghc-devs at haskell.org
Thu Mar 1 13:14:00 UTC 2018


#14872: Hex Literals in GHC Core
-------------------------------------+-------------------------------------
           Reporter:  andrewthad     |             Owner:  (none)
               Type:  feature        |            Status:  new
  request                            |
           Priority:  lowest         |         Milestone:
          Component:  Compiler       |           Version:  8.2.2
           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:
-------------------------------------+-------------------------------------
 Sometimes, when I'm doing stuff that involves twiddling bits, it would be
 nicer to see integer literals in hexadecimal when I dump core with
 `-ddump-simpl`. For example, in a project I'm working on, I've got this:

 {{{
 detectNull :: Word -> Word
 detectNull x = (x - repeatHexZeroOne) .&. complement x .&.
 repeatHexEightZero

 detectArtifact :: Word -> Word -> Word
 detectArtifact x artifact = detectNull (applyArtifact x artifact)

 applyArtifact :: Word -> Word -> Word
 applyArtifact = xor

 repeatHexZeroOne :: Word
 repeatHexZeroOne = div maxBound 255

 repeatHexEightZero :: Word
 repeatHexEightZero = 128 * (div maxBound 255 :: Word)
 }}}

 Once everything gets unboxed and constant-folding happens, in GHC core,
 the places where I used `repeatHexZeroOne` show `72340172838076673##` (on
 a 64-bit machine). This is accurate, but it would be nice I could give a
 flag to make it show `0x0101010101010101##` instead. This would make it
 easier for me to confirm that the arithmetic I used to generate a bit
 pattern actually generated what I thought it did. Admittedly, we'd
 probably want leading zeroes to get chopped off so that small integer
 literals didn't show up with 15 zeroes in front of them. So,
 realistically, it might show up as `0x101010101010101##`. Or maybe it
 could always to padded with leading zeroes until the length was a power of
 two. Anyway, not important, but I thought it would be nice to have.
 Possible flag name: `-ddump-hex-literals`.

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


More information about the ghc-tickets mailing list