File: Compat.hs

package info (click to toggle)
haskell-mod 0.2.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 148 kB
  • sloc: haskell: 1,422; ansic: 10; makefile: 3
file content (57 lines) | stat: -rw-r--r-- 1,244 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
-- | See https://gitlab.haskell.org/ghc/ghc/-/issues/22933
--   and https://gitlab.haskell.org/ghc/ghc/-/issues/22966
--

{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE CApiFFI #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE MagicHash #-}
{-# LANGUAGE UnboxedTuples #-}
{-# LANGUAGE UnliftedFFITypes #-}

module Data.Mod.Compat
  ( timesWord2#
  , remWord2#
  ) where

#if defined(aarch64_HOST_ARCH) && __GLASGOW_HASKELL__ < 912

import GHC.Exts (Word(..), Word#)

#if __GLASGOW_HASKELL__ < 904

import GHC.Exts (timesWord#)

timesWord2# :: Word# -> Word# -> (# Word#, Word# #)
timesWord2# x y = (# z, timesWord# x y #)
  where
    !(W# z) = c_umulh (W# x) (W# y)
{-# INLINE timesWord2# #-}

foreign import capi unsafe "aarch64.h umulh" c_umulh :: Word -> Word -> Word

#else

import GHC.Exts (timesWord2#)

#endif

remWord2# :: Word# -> Word# -> Word# -> Word#
remWord2# lo hi m = r
  where
    !(W# r) = c_umodh (W# lo) (W# hi) (W# m)
{-# INLINE remWord2# #-}

foreign import capi unsafe "aarch64.h umodh" c_umodh :: Word -> Word -> Word -> Word

#else

import GHC.Exts (Word#, timesWord2#, quotRemWord2#)

remWord2# :: Word# -> Word# -> Word# -> Word#
remWord2# lo hi m = r
  where
    !(# _, r #) = quotRemWord2# hi lo m
{-# INLINE remWord2# #-}

#endif