diff options
-rw-r--r-- | testsuite/tests/cmm/opt/T20142.hs | 30 | ||||
-rw-r--r-- | testsuite/tests/cmm/opt/all.T | 1 |
2 files changed, 31 insertions, 0 deletions
diff --git a/testsuite/tests/cmm/opt/T20142.hs b/testsuite/tests/cmm/opt/T20142.hs new file mode 100644 index 0000000000..c729265009 --- /dev/null +++ b/testsuite/tests/cmm/opt/T20142.hs @@ -0,0 +1,30 @@ +{-# LANGUAGE BangPatterns, CPP, MagicHash, RankNTypes, ScopedTypeVariables, UnboxedTuples #-} +{-# OPTIONS_GHC -O2 -dcmm-lint #-} + +module Data.Text.Lazy.Builder.Int ( hexadecimal) where + +import GHC.Exts +import Data.Int (Int8) +import Prelude + +type Builder = [Char] + +singleton :: a -> [a] +singleton x = [x] + +hexadecimal :: Int8 -> Builder +hexadecimal i = go i + where + go n | n < 16 = hexDigit n + | otherwise = go (n `quot` 16) <> hexDigit (n `rem` 16) +{-# NOINLINE[0] hexadecimal #-} + +hexDigit :: Integral a => a -> Builder +hexDigit n + | n <= 9 = singleton $! i2d (fromIntegral n) + | otherwise = singleton $! toEnum (fromIntegral n + 87) +{-# INLINE hexDigit #-} + +{-# INLINE i2d #-} +i2d :: Int -> Char +i2d (I# i#) = C# (chr# (ord# '0'# +# i#)) diff --git a/testsuite/tests/cmm/opt/all.T b/testsuite/tests/cmm/opt/all.T index da7e95d5c4..0e4fc9abf2 100644 --- a/testsuite/tests/cmm/opt/all.T +++ b/testsuite/tests/cmm/opt/all.T @@ -2,3 +2,4 @@ # to the same target. test('T15188', normal, makefile_test, []) test('T18141', normal, compile, ['']) +test('T20142', normal, compile, ['']) |