{-# Language MagicHash #-}
{-# Language ForeignFunctionInterface #-}
{-# Language UnliftedFFITypes #-}
{-# Language GHCForeignImportPrim #-}
{-# Language UnboxedTuples #-}
{-# Language CPP #-}
module Data.Ord.Fast where
import GHC.Exts
class FastMinMax x where
fastmin :: x -> x -> x
fastmax :: x -> x -> x
clamp :: x -> x
instance FastMinMax Int where
fastmin :: Int -> Int -> Int
fastmin (I# Int#
x) (I# Int#
y) =
let !xmy :: Int#
xmy = Int#
x Int# -> Int# -> Int#
-# Int#
y
res :: Int
res = Int# -> Int
I# ( Int#
y Int# -> Int# -> Int#
+# ( Int#
xmy Int# -> Int# -> Int#
`andI#` Int# -> Int# -> Int#
uncheckedIShiftRA# Int#
xmy Int#
63# ) )
in Int
res
{-# Inline fastmin #-}
fastmax :: Int -> Int -> Int
fastmax (I# Int#
x) (I# Int#
y) =
let !xmy :: Int#
xmy = Int#
x Int# -> Int# -> Int#
-# Int#
y
res :: Int
res = Int# -> Int
I# ( Int#
x Int# -> Int# -> Int#
-# ( Int#
xmy Int# -> Int# -> Int#
`andI#` Int# -> Int# -> Int#
uncheckedIShiftRA# Int#
xmy Int#
63# ) )
in Int
res
{-# Inline fastmax #-}
clamp :: Int -> Int
clamp (I# Int#
x) = Int# -> Int
I# (Int# -> Int# -> Int#
andI# Int#
x (Int# -> Int#
notI# (Int# -> Int# -> Int#
uncheckedIShiftRA# Int#
x Int#
63#)))
{-# Inline clamp #-}