1-- | 2-- Module : Data.Memory.Internal.CompatPrim 3-- License : BSD-style 4-- Maintainer : Vincent Hanquez <vincent@snarc.org> 5-- Stability : stable 6-- Portability : Compat 7-- 8-- This module try to keep all the difference between versions of ghc primitive 9-- or other needed packages, so that modules don't need to use CPP. 10-- 11-- Note that MagicHash and CPP conflicts in places, making it "more interesting" 12-- to write compat code for primitives 13-- 14{-# LANGUAGE CPP #-} 15{-# LANGUAGE BangPatterns #-} 16{-# LANGUAGE MagicHash #-} 17{-# LANGUAGE UnboxedTuples #-} 18#include "MachDeps.h" 19module Data.Memory.Internal.CompatPrim64 20 ( Word64# 21 , Int64# 22 , eqInt64# 23 , neInt64# 24 , ltInt64# 25 , leInt64# 26 , gtInt64# 27 , geInt64# 28 , quotInt64# 29 , remInt64# 30 , eqWord64# 31 , neWord64# 32 , ltWord64# 33 , leWord64# 34 , gtWord64# 35 , geWord64# 36 , and64# 37 , or64# 38 , xor64# 39 , not64# 40 , timesWord64# 41 , uncheckedShiftL64# 42 , uncheckedShiftRL64# 43 44 , int64ToWord64# 45 , word64ToInt64# 46 , intToInt64# 47 , int64ToInt# 48 , wordToWord64# 49 , word64ToWord# 50 , w64# 51 ) where 52 53 54#if WORD_SIZE_IN_BITS == 64 55import GHC.Prim hiding (Word64#, Int64#) 56 57#if __GLASGOW_HASKELL__ >= 708 58type OutBool = Int# 59#else 60type OutBool = Bool 61#endif 62 63type Word64# = Word# 64type Int64# = Int# 65 66eqWord64# :: Word64# -> Word64# -> OutBool 67eqWord64# = eqWord# 68 69neWord64# :: Word64# -> Word64# -> OutBool 70neWord64# = neWord# 71 72ltWord64# :: Word64# -> Word64# -> OutBool 73ltWord64# = ltWord# 74 75leWord64# :: Word64# -> Word64# -> OutBool 76leWord64# = leWord# 77 78gtWord64# :: Word64# -> Word64# -> OutBool 79gtWord64# = gtWord# 80 81geWord64# :: Word64# -> Word64# -> OutBool 82geWord64# = geWord# 83 84eqInt64# :: Int64# -> Int64# -> OutBool 85eqInt64# = (==#) 86 87neInt64# :: Int64# -> Int64# -> OutBool 88neInt64# = (/=#) 89 90ltInt64# :: Int64# -> Int64# -> OutBool 91ltInt64# = (<#) 92 93leInt64# :: Int64# -> Int64# -> OutBool 94leInt64# = (<=#) 95 96gtInt64# :: Int64# -> Int64# -> OutBool 97gtInt64# = (>#) 98 99geInt64# :: Int64# -> Int64# -> OutBool 100geInt64# = (<=#) 101 102quotInt64# :: Int64# -> Int64# -> Int64# 103quotInt64# = quotInt# 104 105remInt64# :: Int64# -> Int64# -> Int64# 106remInt64# = remInt# 107 108and64# :: Word64# -> Word64# -> Word64# 109and64# = and# 110 111or64# :: Word64# -> Word64# -> Word64# 112or64# = or# 113 114xor64# :: Word64# -> Word64# -> Word64# 115xor64# = xor# 116 117not64# :: Word64# -> Word64# 118not64# = not# 119 120uncheckedShiftL64# :: Word64# -> Int# -> Word64# 121uncheckedShiftL64# = uncheckedShiftL# 122 123uncheckedShiftRL64# :: Word64# -> Int# -> Word64# 124uncheckedShiftRL64# = uncheckedShiftL# 125 126int64ToWord64# :: Int64# -> Word64# 127int64ToWord64# = int2Word# 128 129word64ToInt64# :: Word64# -> Int64# 130word64ToInt64# = word2Int# 131 132intToInt64# :: Int# -> Int64# 133intToInt64# w = w 134 135int64ToInt# :: Int64# -> Int# 136int64ToInt# w = w 137 138wordToWord64# :: Word# -> Word64# 139wordToWord64# w = w 140 141word64ToWord# :: Word64# -> Word# 142word64ToWord# w = w 143 144timesWord64# :: Word64# -> Word64# -> Word64# 145timesWord64# = timesWord# 146 147w64# :: Word# -> Word# -> Word# -> Word64# 148w64# w _ _ = w 149 150#elif WORD_SIZE_IN_BITS == 32 151import GHC.IntWord64 152import GHC.Prim (Word#) 153 154timesWord64# :: Word64# -> Word64# -> Word64# 155timesWord64# a b = 156 let !ai = word64ToInt64# a 157 !bi = word64ToInt64# b 158 in int64ToWord64# (timesInt64# ai bi) 159 160w64# :: Word# -> Word# -> Word# -> Word64# 161w64# _ hw lw = 162 let !h = wordToWord64# hw 163 !l = wordToWord64# lw 164 in or64# (uncheckedShiftL64# h 32#) l 165#else 166#error "not a supported architecture. supported WORD_SIZE_IN_BITS is 32 bits or 64 bits" 167#endif 168