- x .&. y = to (binop (wordop and#) x y)
- x .|. y = to (binop (wordop or# ) x y)
- x `xor` y = to (binop (wordop xor#) x y)
- complement x = x `xor` -1
- shift (I32 (I# x)) i@(I# i#)
- | i > 0 = I32 (I# (iShiftL# x i#))
- | otherwise = I32 (I# (iShiftRA# x i#))
--- rotate
- bit i = 1 `shift` i
+ (I32# x) .&. (I32# y) = I32# (word2Int# ((int2Word# x) `and#` (int2Word# y)))
+ (I32# x) .|. (I32# y) = I32# (word2Int# ((int2Word# x) `or#` (int2Word# y)))
+ (I32# x) `xor` (I32# y) = I32# (word2Int# ((int2Word# x) `xor#` (int2Word# y)))
+#if WORD_SIZE_IN_BYTES > 4
+ complement (I32# x) = I32# (word2Int# ((int2Word# x) `xor#` (int2Word# 0xffffffff#)))
+#else
+ complement (I32# x) = I32# (word2Int# ((int2Word# x) `xor#` (int2Word# (negateInt# 1#))))
+#endif
+ shift (I32# x) i@(I# i#)
+ | i > 0 = I32# (intToInt32# (iShiftL# (int32ToInt# x) i#))
+ | otherwise = I32# (intToInt32# (iShiftRA# (int32ToInt# x) i#))
+ i32@(I32# x) `rotate` (I# i)
+ | i ==# 0# = i32
+ | i ># 0# =
+ -- ( (x<<i') | ((x&(0x100000000-2^i2))>>i2)
+ I32# (intToInt32# ( word2Int# (
+ (int2Word# (iShiftL# (int32ToInt# x) i'))
+ `or#`
+ (int2Word# (iShiftRA# (word2Int# (
+ (int2Word# x)
+ `and#`
+ (int2Word# (maxBound# -# pow2# i2 +# 1#))))
+ i2)))))
+ | otherwise = rotate i32 (I# (32# +# i))
+ where
+ i' = word2Int# (int2Word# i `and#` int2Word# 31#)
+ i2 = 32# -# i'
+ (I32# maxBound#) = maxBound
+ bit i = shift 1 i