diff options
author | Artem Pyanykh <artem.pyanykh@gmail.com> | 2019-04-11 14:20:03 +0300 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2019-04-14 01:26:35 -0400 |
commit | edcef7b384ca5af6e67d58c39779d03f80768538 (patch) | |
tree | 0a873348e5fc80f17cabdc0f5b6dddf15b70d07d /testsuite/tests/codeGen | |
parent | 6febc444c0abea6c033174aa0e813c950b9b2877 (diff) | |
download | haskell-edcef7b384ca5af6e67d58c39779d03f80768538.tar.gz |
codegen: unroll memcpy calls for small bytearrays
Diffstat (limited to 'testsuite/tests/codeGen')
3 files changed, 28 insertions, 0 deletions
diff --git a/testsuite/tests/codeGen/should_gen_asm/all.T b/testsuite/tests/codeGen/should_gen_asm/all.T index 7e35ec3431..fbacf2b86b 100644 --- a/testsuite/tests/codeGen/should_gen_asm/all.T +++ b/testsuite/tests/codeGen/should_gen_asm/all.T @@ -8,3 +8,4 @@ test('memcpy-unroll', is_amd64_codegen, compile_cmp_asm, ['cmm', '']) test('memcpy-unroll-conprop', is_amd64_codegen, compile_cmp_asm, ['cmm', '']) test('memset-unroll', is_amd64_codegen, compile_cmp_asm, ['cmm', '']) test('bytearray-memset-unroll', is_amd64_codegen, compile_grep_asm, ['hs', True, '']) +test('bytearray-memcpy-unroll', is_amd64_codegen, compile_grep_asm, ['hs', True, '']) diff --git a/testsuite/tests/codeGen/should_gen_asm/bytearray-memcpy-unroll.asm b/testsuite/tests/codeGen/should_gen_asm/bytearray-memcpy-unroll.asm new file mode 100644 index 0000000000..b81654cb6a --- /dev/null +++ b/testsuite/tests/codeGen/should_gen_asm/bytearray-memcpy-unroll.asm @@ -0,0 +1,8 @@ +movw 0(%rax),%dx +movw %dx,0(%rcx) +movw 2(%rax),%dx +movw %dx,2(%rcx) +movw 4(%rax),%dx +movw %dx,4(%rcx) +movw 6(%rax),%ax +movw %ax,6(%rcx) diff --git a/testsuite/tests/codeGen/should_gen_asm/bytearray-memcpy-unroll.hs b/testsuite/tests/codeGen/should_gen_asm/bytearray-memcpy-unroll.hs new file mode 100644 index 0000000000..7a7cea966b --- /dev/null +++ b/testsuite/tests/codeGen/should_gen_asm/bytearray-memcpy-unroll.hs @@ -0,0 +1,19 @@ +{-# language MagicHash #-} +{-# language UnboxedTuples #-} + +module CopyArray + ( smallCopy + ) where + +import GHC.Exts +import GHC.IO + +data ByteArray = ByteArray ByteArray# + +-- Does an 8 byte copy with sub-word (2 bytes) alignment +-- Should be unrolled into 4 aligned stores (MOVWs) +smallCopy :: ByteArray -> IO ByteArray +smallCopy (ByteArray ba) = IO $ \s0 -> case newByteArray# 8# s0 of + (# s1, mut #) -> case copyByteArray# ba 2# mut 0# 8# s1 of + s2 -> case unsafeFreezeByteArray# mut s2 of + (# s3, frozen #) -> (# s3, ByteArray frozen #) |