Commit 52037f72 authored by Ian Lynagh's avatar Ian Lynagh
Browse files

Add a test for 2-word-multiply

parent 1128d8a3
......@@ -55,4 +55,5 @@ test('4381', normal, compile_and_run, [''])
test('4383', normal, compile_and_run, [''])
test('add2', normal, compile_and_run, [''])
test('mul2', normal, compile_and_run, [''])
{-# LANGUAGE MagicHash, UnboxedTuples #-}
import GHC.Prim
import GHC.Word
import Data.Bits
main :: IO ()
main = do f 5 6
f 0xFE36FB18 49
f 0xFE36FB18 0xFB29FC6A
f :: Word -> Word -> IO ()
f wx@(W# x) wy@(W# y)
= do putStrLn "-----"
putStrLn ("Doing " ++ show wx ++ " * " ++ show wy)
case x `timesWord2#` y of
(# h, l #) ->
do let wh = W# h
wl = W# l
r = shiftL (fromIntegral wh) (bitSize wh)
+ fromIntegral wl
putStrLn ("High: " ++ show wh)
putStrLn ("Low: " ++ show wl)
putStrLn ("Result: " ++ show (r :: Integer))
-----
Doing 5 * 6
High: 0
Low: 30
Result: 30
-----
Doing 4265016088 * 49
High: 0
Low: 208985788312
Result: 208985788312
-----
Doing 4265016088 * 4213832810
High: 0
Low: 17972064726792247280
Result: 17972064726792247280
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment