diff options
author | Michal Terepeta <michal.terepeta@gmail.com> | 2018-10-04 13:56:59 -0400 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2018-10-07 18:36:07 -0400 |
commit | 5d5307f943d7581d7013ffe20af22233273fba06 (patch) | |
tree | ec9ae993cfa44d2cfe797e0422eb388933277100 /testsuite/tests/ffi | |
parent | e4bec29cb475b7e1431dad41fb8d4438814641c9 (diff) | |
download | haskell-5d5307f943d7581d7013ffe20af22233273fba06.tar.gz |
Add Int8# and Word8#
This is the first step of implementing:
https://github.com/ghc-proposals/ghc-proposals/pull/74
The main highlights/changes:
- `primops.txt.pp` gets two new sections for two new primitive types
for signed and unsigned 8-bit integers (`Int8#` and `Word8`
respectively) along with basic arithmetic and comparison
operations. `PrimRep`/`RuntimeRep` get two new constructors for
them. All of the primops translate into the existing `MachOP`s.
- For `CmmCall`s the codegen will now zero-extend the values at call
site (so that they can be moved to the right register) and then
truncate them back their original width.
- x86 native codegen needed some updates, since it wasn't able to deal
with the new widths, but all the changes are quite localized. LLVM
backend seems to just work.
Bumps binary submodule.
Signed-off-by: Michal Terepeta <michal.terepeta@gmail.com>
Test Plan: ./validate with new tests
Reviewers: hvr, goldfire, bgamari, simonmar
Subscribers: Abhiroop, dfeuer, rwbarton, thomie, carter
Differential Revision: https://phabricator.haskell.org/D4475
Diffstat (limited to 'testsuite/tests/ffi')
-rw-r--r-- | testsuite/tests/ffi/should_run/PrimFFIInt8.hs | 28 | ||||
-rw-r--r-- | testsuite/tests/ffi/should_run/PrimFFIInt8.stdout | 1 | ||||
-rw-r--r-- | testsuite/tests/ffi/should_run/PrimFFIInt8_c.c | 7 | ||||
-rw-r--r-- | testsuite/tests/ffi/should_run/PrimFFIWord8.hs | 28 | ||||
-rw-r--r-- | testsuite/tests/ffi/should_run/PrimFFIWord8.stdout | 1 | ||||
-rw-r--r-- | testsuite/tests/ffi/should_run/PrimFFIWord8_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/PrimFFIInt8.hs b/testsuite/tests/ffi/should_run/PrimFFIInt8.hs new file mode 100644 index 0000000000..4124e074aa --- /dev/null +++ b/testsuite/tests/ffi/should_run/PrimFFIInt8.hs @@ -0,0 +1,28 @@ +{-# LANGUAGE ForeignFunctionInterface #-} +{-# LANGUAGE MagicHash #-} +{-# LANGUAGE UnliftedFFITypes #-} + +module Main where + +import GHC.Exts + +foreign import ccall "add_all_int8" + add_all_int8 + :: Int8# -> Int8# -> Int8# -> Int8# -> Int8# + -> Int8# -> Int8# -> Int8# -> Int8# -> Int8# + -> Int8# + +main :: IO () +main = do + let a = narrowInt8# 0# + b = narrowInt8# 1# + c = narrowInt8# 2# + d = narrowInt8# 3# + e = narrowInt8# 4# + f = narrowInt8# 5# + g = narrowInt8# 6# + h = narrowInt8# 7# + i = narrowInt8# 8# + j = narrowInt8# 9# + x = I# (extendInt8# (add_all_int8 a b c d e f g h i j)) + print x diff --git a/testsuite/tests/ffi/should_run/PrimFFIInt8.stdout b/testsuite/tests/ffi/should_run/PrimFFIInt8.stdout new file mode 100644 index 0000000000..ea90ee3198 --- /dev/null +++ b/testsuite/tests/ffi/should_run/PrimFFIInt8.stdout @@ -0,0 +1 @@ +45 diff --git a/testsuite/tests/ffi/should_run/PrimFFIInt8_c.c b/testsuite/tests/ffi/should_run/PrimFFIInt8_c.c new file mode 100644 index 0000000000..dc51687530 --- /dev/null +++ b/testsuite/tests/ffi/should_run/PrimFFIInt8_c.c @@ -0,0 +1,7 @@ +#include <stdint.h> + +int8_t add_all_int8( + int8_t a, int8_t b, int8_t c, int8_t d, int8_t e, + int8_t f, int8_t g, int8_t h, int8_t i, int8_t j) { + return a + b + c + d + e + f + g + h + i + j; +} diff --git a/testsuite/tests/ffi/should_run/PrimFFIWord8.hs b/testsuite/tests/ffi/should_run/PrimFFIWord8.hs new file mode 100644 index 0000000000..87e46636d1 --- /dev/null +++ b/testsuite/tests/ffi/should_run/PrimFFIWord8.hs @@ -0,0 +1,28 @@ +{-# LANGUAGE ForeignFunctionInterface #-} +{-# LANGUAGE MagicHash #-} +{-# LANGUAGE UnliftedFFITypes #-} + +module Main where + +import GHC.Exts + +foreign import ccall "add_all_word8" + add_all_word8 + :: Word8# -> Word8# -> Word8# -> Word8# -> Word8# + -> Word8# -> Word8# -> Word8# -> Word8# -> Word8# + -> Word8# + +main :: IO () +main = do + let a = narrowWord8# 0## + b = narrowWord8# 1## + c = narrowWord8# 2## + d = narrowWord8# 3## + e = narrowWord8# 4## + f = narrowWord8# 5## + g = narrowWord8# 6## + h = narrowWord8# 7## + i = narrowWord8# 8## + j = narrowWord8# 9## + x = W# (extendWord8# (add_all_word8 a b c d e f g h i j)) + print x diff --git a/testsuite/tests/ffi/should_run/PrimFFIWord8.stdout b/testsuite/tests/ffi/should_run/PrimFFIWord8.stdout new file mode 100644 index 0000000000..ea90ee3198 --- /dev/null +++ b/testsuite/tests/ffi/should_run/PrimFFIWord8.stdout @@ -0,0 +1 @@ +45 diff --git a/testsuite/tests/ffi/should_run/PrimFFIWord8_c.c b/testsuite/tests/ffi/should_run/PrimFFIWord8_c.c new file mode 100644 index 0000000000..535ed4185c --- /dev/null +++ b/testsuite/tests/ffi/should_run/PrimFFIWord8_c.c @@ -0,0 +1,7 @@ +#include <stdint.h> + +uint8_t add_all_word8( + uint8_t a, uint8_t b, uint8_t c, uint8_t d, uint8_t e, + uint8_t f, uint8_t g, uint8_t h, uint8_t i, uint8_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 fd0af7ebc3..9223b3d1b3 100644 --- a/testsuite/tests/ffi/should_run/all.T +++ b/testsuite/tests/ffi/should_run/all.T @@ -188,3 +188,7 @@ test('ffi023', [ omit_ways(['ghci']), test('T12134', [omit_ways(['ghci'])], compile_and_run, ['T12134_c.c']) test('T12614', [omit_ways(['ghci'])], compile_and_run, ['T12614_c.c']) + +test('PrimFFIInt8', [omit_ways(['ghci'])], compile_and_run, ['PrimFFIInt8_c.c']) + +test('PrimFFIWord8', [omit_ways(['ghci'])], compile_and_run, ['PrimFFIWord8_c.c']) |