From 0b39809bf91ba6ef15bfadf9a00b23030bd2027e Mon Sep 17 00:00:00 2001 From: amesgen Date: Sun, 10 Sep 2023 20:03:40 +0200 Subject: [PATCH 1/3] Fix compilation on 32bit --- cborg/src/Codec/CBOR/Decoding.hs | 11 ++++++++--- cborg/src/Codec/CBOR/Magic.hs | 4 ++-- cborg/src/Codec/CBOR/Read.hs | 28 ++++++++++++++-------------- 3 files changed, 24 insertions(+), 19 deletions(-) diff --git a/cborg/src/Codec/CBOR/Decoding.hs b/cborg/src/Codec/CBOR/Decoding.hs index a7d774c..308f78d 100644 --- a/cborg/src/Codec/CBOR/Decoding.hs +++ b/cborg/src/Codec/CBOR/Decoding.hs @@ -315,11 +315,16 @@ getDecodeAction (Decoder k) = k (\x -> return (Done x)) toInt8 :: Int# -> Int8 toInt16 :: Int# -> Int16 toInt32 :: Int# -> Int32 -toInt64 :: Int# -> Int64 toWord8 :: Word# -> Word8 toWord16 :: Word# -> Word16 toWord32 :: Word# -> Word32 +#if defined(ARCH_64bit) +toInt64 :: Int# -> Int64 toWord64 :: Word# -> Word64 +#else +toInt64 :: Int64# -> Int64 +toWord64 :: Word64# -> Word64 +#endif #if MIN_VERSION_ghc_prim(0,8,0) toInt8 n = I8# (intToInt8# n) toInt16 n = I16# (intToInt16# n) @@ -327,7 +332,7 @@ toInt32 n = I32# (intToInt32# n) toWord8 n = W8# (wordToWord8# n) toWord16 n = W16# (wordToWord16# n) toWord32 n = W32# (wordToWord32# n) -#if WORD_SIZE_IN_BITS == 64 +#if defined(ARCH_64bit) #if MIN_VERSION_base(4,17,0) toInt64 n = I64# (intToInt64# n) toWord64 n = W64# (wordToWord64# n) @@ -986,7 +991,7 @@ type ByteOffset = Int64 -- @since 0.2.2.0 peekByteOffset :: Decoder s ByteOffset peekByteOffset = Decoder (\k -> return (PeekByteOffset (\off# -> k (I64# -#if MIN_VERSION_base(4,17,0) +#if MIN_VERSION_base(4,17,0) && !defined(ARCH_32bit) (intToInt64# off#) #else off# diff --git a/cborg/src/Codec/CBOR/Magic.hs b/cborg/src/Codec/CBOR/Magic.hs index cdeb455..1e16cc6 100644 --- a/cborg/src/Codec/CBOR/Magic.hs +++ b/cborg/src/Codec/CBOR/Magic.hs @@ -173,7 +173,7 @@ grabWord64 (Ptr ip#) = W64# (wordToWord64# (byteSwap# (word64ToWord# (indexWord6 grabWord64 (Ptr ip#) = W64# (byteSwap# (indexWord64OffAddr# ip# 0#)) #endif #else -grabWord64 (Ptr ip#) = W64# (byteSwap64# (word64ToWord# (indexWord64OffAddr# ip# 0#))) +grabWord64 (Ptr ip#) = W64# (byteSwap64# (indexWord64OffAddr# ip# 0#)) #endif #elif defined(MEM_UNALIGNED_OPS) && \ @@ -484,7 +484,7 @@ word16ToInt (W16# w#) = I# (word2Int# (word16ToWord# w#)) word32ToInt (W32# w#) = I# (word2Int# (word32ToWord# w#)) #else word32ToInt (W32# w#) = - case isTrue# (w# `ltWord#` 0x80000000##) of + case isTrue# (word32ToWord# w# `ltWord#` 0x80000000##) of True -> Just (I# (word2Int# (word32ToWord# w#))) False -> Nothing #endif diff --git a/cborg/src/Codec/CBOR/Read.hs b/cborg/src/Codec/CBOR/Read.hs index 6546575..e21fb5d 100644 --- a/cborg/src/Codec/CBOR/Read.hs +++ b/cborg/src/Codec/CBOR/Read.hs @@ -510,8 +510,8 @@ go_fast !bs da@(ConsumeNegWord64Canonical k) = go_fast !bs da@(ConsumeInt64Canonical k) = case tryConsumeInt64 (BS.unsafeHead bs) bs of DecodeFailure -> go_fast_end bs da - DecodedToken sz i@(I64# i#) - | isInt64Canonical sz i -> k i# >>= go_fast (BS.unsafeDrop sz bs) + DecodedToken sz (I64# i#) + | isInt64Canonical sz i# -> k i# >>= go_fast (BS.unsafeDrop sz bs) | otherwise -> go_fast_end bs da go_fast !bs da@(ConsumeListLen64Canonical k) = @@ -994,8 +994,8 @@ go_fast_end !bs (ConsumeNegWord64Canonical k) = go_fast_end !bs (ConsumeInt64Canonical k) = case tryConsumeInt64 (BS.unsafeHead bs) bs of DecodeFailure -> return $! SlowFail bs "expected int64" - DecodedToken sz i@(I64# i#) - | isInt64Canonical sz i -> k i# >>= go_fast_end (BS.unsafeDrop sz bs) + DecodedToken sz (I64# i#) + | isInt64Canonical sz i# -> k i# >>= go_fast_end (BS.unsafeDrop sz bs) | otherwise -> return $! SlowFail bs "non-canonical int64" go_fast_end !bs (ConsumeListLen64Canonical k) = @@ -1271,7 +1271,7 @@ go_slow da bs !offset = do SlowPeekByteOffset bs' k -> lift -#if MIN_VERSION_base(4,17,0) +#if MIN_VERSION_base(4,17,0) && !defined(ARCH_32bit) (k (int64ToInt# off#)) #else (k off#) @@ -1381,7 +1381,7 @@ go_slow_overlapped da sz bs_cur bs_next !offset = SlowPeekByteOffset bs_empty k -> assert (BS.null bs_empty) $ do lift -#if MIN_VERSION_base(4,17,0) +#if MIN_VERSION_base(4,17,0) && !defined(ARCH_32bit) (k (int64ToInt# off#)) #else (k off#) @@ -1565,17 +1565,17 @@ isIntCanonical sz i {-# INLINE isWord64Canonical #-} isWord64Canonical :: Int -> Word64 -> Bool isWord64Canonical sz w - | sz == 2 = w > 0x17) - | sz == 3 = w > 0xff) - | sz == 5 = w > 0xffff) - | sz == 9 = w > 0xffffffff) + | sz == 2 = w > 0x17 + | sz == 3 = w > 0xff + | sz == 5 = w > 0xffff + | sz == 9 = w > 0xffffffff | otherwise = True {-# INLINE isInt64Canonical #-} isInt64Canonical :: Int -> Int64# -> Bool isInt64Canonical sz i# - | isTrue# (i# `ltInt64#` intToInt64# 0#) = isWord64Canonical sz (not64# w#) - | otherwise = isWord64Canonical sz w# + | isTrue# (i# `ltInt64#` intToInt64# 0#) = isWord64Canonical sz (W64# (not64# w#)) + | otherwise = isWord64Canonical sz (W64# w#) where w# = int64ToWord64# i# #endif @@ -1796,7 +1796,7 @@ tryConsumeInteger hdr !bs = case word8ToWord hdr of 0x1b -> let !w = eatTailWord64 bs sz = 9 #if defined(ARCH_32bit) - in DecodedToken sz (BigIntToken (isWord64Canonical sz (word64ToWord w)) $! toInteger w) + in DecodedToken sz (BigIntToken (isWord64Canonical sz w) $! toInteger w) #else in DecodedToken sz (BigIntToken (isWordCanonical sz (word64ToWord w)) $! toInteger w) #endif @@ -1838,7 +1838,7 @@ tryConsumeInteger hdr !bs = case word8ToWord hdr of 0x3b -> let !w = eatTailWord64 bs sz = 9 #if defined(ARCH_32bit) - in DecodedToken sz (BigIntToken (isWord64Canonical sz (word64ToWord w)) $! (-1 - toInteger w)) + in DecodedToken sz (BigIntToken (isWord64Canonical sz w) $! (-1 - toInteger w)) #else in DecodedToken sz (BigIntToken (isWordCanonical sz (word64ToWord w)) $! (-1 - toInteger w)) #endif From 3a699b2225b7142b3b6fbbb20de9959c7098828d Mon Sep 17 00:00:00 2001 From: amesgen Date: Sun, 10 Sep 2023 20:04:16 +0200 Subject: [PATCH 2/3] Support GHC >=9.2 on 32bit --- cborg/src/Codec/CBOR/Decoding.hs | 7 +------ cborg/src/Codec/CBOR/Magic.hs | 16 +++++++++++++++- cborg/src/Codec/CBOR/Read.hs | 2 +- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/cborg/src/Codec/CBOR/Decoding.hs b/cborg/src/Codec/CBOR/Decoding.hs index 308f78d..bf68e68 100644 --- a/cborg/src/Codec/CBOR/Decoding.hs +++ b/cborg/src/Codec/CBOR/Decoding.hs @@ -332,8 +332,7 @@ toInt32 n = I32# (intToInt32# n) toWord8 n = W8# (wordToWord8# n) toWord16 n = W16# (wordToWord16# n) toWord32 n = W32# (wordToWord32# n) -#if defined(ARCH_64bit) -#if MIN_VERSION_base(4,17,0) +#if MIN_VERSION_base(4,17,0) && defined(ARCH_64bit) toInt64 n = I64# (intToInt64# n) toWord64 n = W64# (wordToWord64# n) #else @@ -341,10 +340,6 @@ toInt64 n = I64# n toWord64 n = W64# n #endif #else -toInt64 n = I64# (intToInt64# n) -toWord64 n = W64# (wordToWord64# n) -#endif -#else toInt8 n = I8# n toInt16 n = I16# n toInt32 n = I32# n diff --git a/cborg/src/Codec/CBOR/Magic.hs b/cborg/src/Codec/CBOR/Magic.hs index 1e16cc6..bfae638 100644 --- a/cborg/src/Codec/CBOR/Magic.hs +++ b/cborg/src/Codec/CBOR/Magic.hs @@ -120,7 +120,7 @@ import qualified Numeric.Half as Half import Data.Bits ((.|.), unsafeShiftL) #endif -#if defined(ARCH_32bit) +#if defined(ARCH_32bit) && !MIN_VERSION_ghc_prim(0,8,0) import GHC.IntWord64 (wordToWord64#, word64ToWord#, intToInt64#, int64ToInt#, leWord64#, ltWord64#, word64ToInt64#) @@ -530,6 +530,19 @@ word64ToInt (W64# w#) = {-# INLINE word64ToInt #-} #if defined(ARCH_32bit) +#if MIN_VERSION_ghc_prim(0,8,0) +word8ToInt64 (W8# w#) = I64# (intToInt64# (word2Int# (word8ToWord# w#))) +word16ToInt64 (W16# w#) = I64# (intToInt64# (word2Int# (word16ToWord# w#))) +word32ToInt64 (W32# w#) = I64# (word64ToInt64# (wordToWord64# (word32ToWord# w#))) +word64ToInt64 (W64# w#) = + case isTrue# (w# `ltWord64#` uncheckedShiftL64# (wordToWord64# 1##) 63#) of + True -> Just (I64# (word64ToInt64# w#)) + False -> Nothing + +word8ToWord64 (W8# w#) = W64# (wordToWord64# (word8ToWord# w#)) +word16ToWord64 (W16# w#) = W64# (wordToWord64# (word16ToWord# w#)) +word32ToWord64 (W32# w#) = W64# (wordToWord64# (word32ToWord# w#)) +#else word8ToInt64 (W8# w#) = I64# (intToInt64# (word2Int# w#)) word16ToInt64 (W16# w#) = I64# (intToInt64# (word2Int# w#)) word32ToInt64 (W32# w#) = I64# (word64ToInt64# (wordToWord64# w#)) @@ -541,6 +554,7 @@ word64ToInt64 (W64# w#) = word8ToWord64 (W8# w#) = W64# (wordToWord64# w#) word16ToWord64 (W16# w#) = W64# (wordToWord64# w#) word32ToWord64 (W32# w#) = W64# (wordToWord64# w#) +#endif {-# INLINE word8ToInt64 #-} {-# INLINE word16ToInt64 #-} diff --git a/cborg/src/Codec/CBOR/Read.hs b/cborg/src/Codec/CBOR/Read.hs index e21fb5d..c4dc761 100644 --- a/cborg/src/Codec/CBOR/Read.hs +++ b/cborg/src/Codec/CBOR/Read.hs @@ -63,7 +63,7 @@ import qualified Data.Text as T import qualified Data.Text.Encoding as T import Data.Word import GHC.Word -#if defined(ARCH_32bit) +#if defined(ARCH_32bit) && !MIN_VERSION_ghc_prim(0,8,0) import GHC.IntWord64 #endif import GHC.Exts From 2dff24d241d9940c5a7f5e817fcf4c1aa4a8d4bf Mon Sep 17 00:00:00 2001 From: amesgen Date: Mon, 12 Jun 2023 20:57:46 +0200 Subject: [PATCH 3/3] i386 CI --- .github/workflows/other.yml | 43 +++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 .github/workflows/other.yml diff --git a/.github/workflows/other.yml b/.github/workflows/other.yml new file mode 100644 index 0000000..0ad9a52 --- /dev/null +++ b/.github/workflows/other.yml @@ -0,0 +1,43 @@ +name: Other CI +on: +- push +- pull_request +jobs: + i386: + name: i386 - ${{ matrix.ghc }} + runs-on: ubuntu-latest + container: + image: i386/debian:bookworm + strategy: + fail-fast: false + matrix: + ghc: + - '9.12' + # 9.10.1 causes test failures due to a miscompilation + # https://gitlab.haskell.org/ghc/ghc/-/issues/24893 + - '9.10.2' + - '9.8' + - '9.6' + - '9.4' + - '9.2' + - '9.0' + - '8.10' + - '8.8' + steps: + - name: Install system dependencies + run: | + apt-get update -y + apt-get install -y build-essential curl libffi-dev libffi8 libgmp-dev libgmp10 libncurses-dev libncurses5 libtinfo5 zlib1g-dev + # https://github.com/haskell/ghcup-hs/issues/1107 + curl https://downloads.haskell.org/ghcup/0.1.20.0/i386-linux-ghcup-0.1.20.0 > ghcup + chmod a+x ghcup + ./ghcup install cabal latest --set + ./ghcup install ghc ${{ matrix.ghc }} --set + echo "$HOME/.ghcup/bin" >> "$GITHUB_PATH" + - uses: actions/checkout@v1 + - name: Build and test + run: | + cabal update + cabal configure --enable-tests --enable-benchmarks + cabal build all + cabal test all --test-show-details=direct