Hex Literals in GHC Core
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
.
Trac metadata
Trac field | Value |
---|---|
Version | 8.2.2 |
Type | FeatureRequest |
TypeOfFailure | OtherFailure |
Priority | lowest |
Resolution | Unresolved |
Component | Compiler |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | |
Operating system | |
Architecture |