module GHC.Utils.Word64 (
    intToWord64,
    word64ToInt,
    truncateWord64ToWord32,
  ) where

import GHC.Prelude
import GHC.Utils.Panic.Plain (assert)

import Data.Word
import GHC.Stack

intToWord64 :: HasCallStack => Int -> Word64
intToWord64 :: HasCallStack => Int -> Word64
intToWord64 Int
x = Bool -> Word64 -> Word64
forall a. HasCallStack => Bool -> a -> a
assert (Int
0 Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
x) (Int -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
x)

word64ToInt :: HasCallStack => Word64 -> Int
word64ToInt :: HasCallStack => Word64 -> Int
word64ToInt Word64
x = Bool -> Int -> Int
forall a. HasCallStack => Bool -> a -> a
assert (Word64
x Word64 -> Word64 -> Bool
forall a. Ord a => a -> a -> Bool
<= Int -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int
forall a. Bounded a => a
maxBound :: Int)) (Word64 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word64
x)

truncateWord64ToWord32 :: Word64 -> Word32
truncateWord64ToWord32 :: Word64 -> Word32
truncateWord64ToWord32 = Word64 -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral