diff options
author | John Ericson <git@JohnEricson.me> | 2019-06-03 23:47:10 -0400 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2021-01-07 00:11:31 -0500 |
commit | 06982b6cc886d65aa325475ddfb4ad38c69b2d96 (patch) | |
tree | a09811c44dd0e4fd774bc2de3fa10ea34f6409f4 /testsuite/tests/ffi | |
parent | e981023eb1cfb2a0f6052763469252feee3e2d51 (diff) | |
download | haskell-06982b6cc886d65aa325475ddfb4ad38c69b2d96.tar.gz |
Make primops for `{Int,Word}32#`
Progress towards #19026.
The type was added before, but not its primops. We follow the
conventions in 36fcf9edee31513db2ddbf716ee0aa79766cbe69 and
2c959a1894311e59cd2fd469c1967491c1e488f3 for names and testing.
Along with the previous 8- and 16-bit primops, this will allow us to
avoid many conversions for 8-, 16-, and 32-bit sized numeric types.
Co-authored-by: Sylvain Henry <hsyl20@gmail.com>
Diffstat (limited to 'testsuite/tests/ffi')
-rw-r--r-- | testsuite/tests/ffi/should_run/PrimFFIInt32.hs | 28 | ||||
-rw-r--r-- | testsuite/tests/ffi/should_run/PrimFFIInt32.stdout | 1 | ||||
-rw-r--r-- | testsuite/tests/ffi/should_run/PrimFFIInt32_c.c | 7 | ||||
-rw-r--r-- | testsuite/tests/ffi/should_run/PrimFFIWord32.hs | 28 | ||||
-rw-r--r-- | testsuite/tests/ffi/should_run/PrimFFIWord32.stdout | 1 | ||||
-rw-r--r-- | testsuite/tests/ffi/should_run/PrimFFIWord32_c.c | 7 | ||||
-rw-r--r-- | testsuite/tests/ffi/should_run/all.T | 4 |
7 files changed, 76 insertions, 0 deletions
diff --git a/testsuite/tests/ffi/should_run/PrimFFIInt32.hs b/testsuite/tests/ffi/should_run/PrimFFIInt32.hs new file mode 100644 index 0000000000..511e3cec10 --- /dev/null +++ b/testsuite/tests/ffi/should_run/PrimFFIInt32.hs @@ -0,0 +1,28 @@ +{-# LANGUAGE ForeignFunctionInterface #-} +{-# LANGUAGE MagicHash #-} +{-# LANGUAGE UnliftedFFITypes #-} + +module Main where + +import GHC.Exts + +foreign import ccall "add_all_int32" + add_all_int32 + :: Int32# -> Int32# -> Int32# -> Int32# -> Int32# + -> Int32# -> Int32# -> Int32# -> Int32# -> Int32# + -> Int32# + +main :: IO () +main = do + let a = narrowInt32# 0# + b = narrowInt32# 1# + c = narrowInt32# 2# + d = narrowInt32# 3# + e = narrowInt32# 4# + f = narrowInt32# 5# + g = narrowInt32# 6# + h = narrowInt32# 7# + i = narrowInt32# 8# + j = narrowInt32# 9# + x = I# (extendInt32# (add_all_int32 a b c d e f g h i j)) + print x diff --git a/testsuite/tests/ffi/should_run/PrimFFIInt32.stdout b/testsuite/tests/ffi/should_run/PrimFFIInt32.stdout new file mode 100644 index 0000000000..ea90ee3198 --- /dev/null +++ b/testsuite/tests/ffi/should_run/PrimFFIInt32.stdout @@ -0,0 +1 @@ +45 diff --git a/testsuite/tests/ffi/should_run/PrimFFIInt32_c.c b/testsuite/tests/ffi/should_run/PrimFFIInt32_c.c new file mode 100644 index 0000000000..5671e7d698 --- /dev/null +++ b/testsuite/tests/ffi/should_run/PrimFFIInt32_c.c @@ -0,0 +1,7 @@ +#include <stdint.h> + +int32_t add_all_int32( + int32_t a, int32_t b, int32_t c, int32_t d, int32_t e, + int32_t f, int32_t g, int32_t h, int32_t i, int32_t j) { + return a + b + c + d + e + f + g + h + i + j; +} diff --git a/testsuite/tests/ffi/should_run/PrimFFIWord32.hs b/testsuite/tests/ffi/should_run/PrimFFIWord32.hs new file mode 100644 index 0000000000..996bae1b61 --- /dev/null +++ b/testsuite/tests/ffi/should_run/PrimFFIWord32.hs @@ -0,0 +1,28 @@ +{-# LANGUAGE ForeignFunctionInterface #-} +{-# LANGUAGE MagicHash #-} +{-# LANGUAGE UnliftedFFITypes #-} + +module Main where + +import GHC.Exts + +foreign import ccall "add_all_word32" + add_all_word32 + :: Word32# -> Word32# -> Word32# -> Word32# -> Word32# + -> Word32# -> Word32# -> Word32# -> Word32# -> Word32# + -> Word32# + +main :: IO () +main = do + let a = narrowWord32# 0## + b = narrowWord32# 1## + c = narrowWord32# 2## + d = narrowWord32# 3## + e = narrowWord32# 4## + f = narrowWord32# 5## + g = narrowWord32# 6## + h = narrowWord32# 7## + i = narrowWord32# 8## + j = narrowWord32# 9## + x = W# (extendWord32# (add_all_word32 a b c d e f g h i j)) + print x diff --git a/testsuite/tests/ffi/should_run/PrimFFIWord32.stdout b/testsuite/tests/ffi/should_run/PrimFFIWord32.stdout new file mode 100644 index 0000000000..ea90ee3198 --- /dev/null +++ b/testsuite/tests/ffi/should_run/PrimFFIWord32.stdout @@ -0,0 +1 @@ +45 diff --git a/testsuite/tests/ffi/should_run/PrimFFIWord32_c.c b/testsuite/tests/ffi/should_run/PrimFFIWord32_c.c new file mode 100644 index 0000000000..40d617b3ee --- /dev/null +++ b/testsuite/tests/ffi/should_run/PrimFFIWord32_c.c @@ -0,0 +1,7 @@ +#include <stdint.h> + +uint32_t add_all_word32( + uint32_t a, uint32_t b, uint32_t c, uint32_t d, uint32_t e, + uint32_t f, uint32_t g, uint32_t h, uint32_t i, uint32_t j) { + return a + b + c + d + e + f + g + h + i + j; +} diff --git a/testsuite/tests/ffi/should_run/all.T b/testsuite/tests/ffi/should_run/all.T index 95213d38b4..3116946d29 100644 --- a/testsuite/tests/ffi/should_run/all.T +++ b/testsuite/tests/ffi/should_run/all.T @@ -212,6 +212,10 @@ test('PrimFFIInt16', [omit_ways(['ghci'])], compile_and_run, ['PrimFFIInt16_c.c' test('PrimFFIWord16', [omit_ways(['ghci'])], compile_and_run, ['PrimFFIWord16_c.c']) +test('PrimFFIInt32', [omit_ways(['ghci'])], compile_and_run, ['PrimFFIInt32_c.c']) + +test('PrimFFIWord32', [omit_ways(['ghci'])], compile_and_run, ['PrimFFIWord32_c.c']) + test('T493', [omit_ways(['ghci'])], compile_and_run, ['T493_c.c']) test('UnliftedNewtypesByteArrayOffset', [omit_ways(['ghci'])], compile_and_run, ['UnliftedNewtypesByteArrayOffset_c.c']) |