From 42fdd9766d51dfbdb08297223a6ece45c4f0e669 Mon Sep 17 00:00:00 2001 From: Wanming Lin Date: Fri, 17 Jan 2020 09:33:42 +0800 Subject: [PATCH] [test] Test more alignment for load extend and splat ops Tests are synced from https://github.com/WAVM/WAVM/pull/251 --- test/core/simd/simd_align.wast | 345 +++++++++++++++++++++++++-------- 1 file changed, 268 insertions(+), 77 deletions(-) diff --git a/test/core/simd/simd_align.wast b/test/core/simd/simd_align.wast index 1dc95c904..35fb68036 100644 --- a/test/core/simd/simd_align.wast +++ b/test/core/simd/simd_align.wast @@ -1,116 +1,307 @@ -;; Vaild alignment (align=1, 2, 4, 8, 16) +;; Valid alignment -(module - (memory 1) - (data (i32.const 0) "\00\01\02\03\04\05\06\07\08\09\10\11\12\13\14\15") +(module (memory 1) (func (drop (v128.load align=1 (i32.const 0))))) +(module (memory 1) (func (drop (v128.load align=2 (i32.const 0))))) +(module (memory 1) (func (drop (v128.load align=4 (i32.const 0))))) +(module (memory 1) (func (drop (v128.load align=8 (i32.const 0))))) +(module (memory 1) (func (drop (v128.load align=16 (i32.const 0))))) + +(module (memory 1) (func (v128.store align=1 (i32.const 0) (v128.const i32x4 0 1 2 3)))) +(module (memory 1) (func (v128.store align=2 (i32.const 0) (v128.const i32x4 0 1 2 3)))) +(module (memory 1) (func (v128.store align=4 (i32.const 0) (v128.const i32x4 0 1 2 3)))) +(module (memory 1) (func (v128.store align=8 (i32.const 0) (v128.const i32x4 0 1 2 3)))) +(module (memory 1) (func (v128.store align=16 (i32.const 0) (v128.const i32x4 0 1 2 3)))) + +(module (memory 1) (func (drop (i16x8.load8x8_s align=1 (i32.const 0))))) +(module (memory 1) (func (drop (i16x8.load8x8_s align=2 (i32.const 0))))) +(module (memory 1) (func (drop (i16x8.load8x8_s align=4 (i32.const 0))))) +(module (memory 1) (func (drop (i16x8.load8x8_s align=8 (i32.const 0))))) +(module (memory 1) (func (drop (i16x8.load8x8_u align=1 (i32.const 0))))) +(module (memory 1) (func (drop (i16x8.load8x8_u align=2 (i32.const 0))))) +(module (memory 1) (func (drop (i16x8.load8x8_u align=4 (i32.const 0))))) +(module (memory 1) (func (drop (i16x8.load8x8_u align=8 (i32.const 0))))) +(module (memory 1) (func (drop (i32x4.load16x4_s align=1 (i32.const 0))))) +(module (memory 1) (func (drop (i32x4.load16x4_s align=2 (i32.const 0))))) +(module (memory 1) (func (drop (i32x4.load16x4_s align=4 (i32.const 0))))) +(module (memory 1) (func (drop (i32x4.load16x4_s align=8 (i32.const 0))))) +(module (memory 1) (func (drop (i32x4.load16x4_u align=1 (i32.const 0))))) +(module (memory 1) (func (drop (i32x4.load16x4_u align=2 (i32.const 0))))) +(module (memory 1) (func (drop (i32x4.load16x4_u align=4 (i32.const 0))))) +(module (memory 1) (func (drop (i32x4.load16x4_u align=8 (i32.const 0))))) +(module (memory 1) (func (drop (i64x2.load32x2_s align=1 (i32.const 0))))) +(module (memory 1) (func (drop (i64x2.load32x2_s align=2 (i32.const 0))))) +(module (memory 1) (func (drop (i64x2.load32x2_s align=4 (i32.const 0))))) +(module (memory 1) (func (drop (i64x2.load32x2_s align=8 (i32.const 0))))) +(module (memory 1) (func (drop (i64x2.load32x2_u align=1 (i32.const 0))))) +(module (memory 1) (func (drop (i64x2.load32x2_u align=2 (i32.const 0))))) +(module (memory 1) (func (drop (i64x2.load32x2_u align=4 (i32.const 0))))) +(module (memory 1) (func (drop (i64x2.load32x2_u align=8 (i32.const 0))))) + +(module (memory 1) (func (drop (v8x16.load_splat align=1 (i32.const 0))))) +(module (memory 1) (func (drop (v16x8.load_splat align=1 (i32.const 0))))) +(module (memory 1) (func (drop (v16x8.load_splat align=2 (i32.const 0))))) +(module (memory 1) (func (drop (v32x4.load_splat align=1 (i32.const 0))))) +(module (memory 1) (func (drop (v32x4.load_splat align=2 (i32.const 0))))) +(module (memory 1) (func (drop (v32x4.load_splat align=4 (i32.const 0))))) +(module (memory 1) (func (drop (v64x2.load_splat align=1 (i32.const 0))))) +(module (memory 1) (func (drop (v64x2.load_splat align=2 (i32.const 0))))) +(module (memory 1) (func (drop (v64x2.load_splat align=4 (i32.const 0))))) +(module (memory 1) (func (drop (v64x2.load_splat align=8 (i32.const 0))))) + +;; Invalid alignment + +(assert_invalid + (module (memory 1) (func (drop (v128.load align=32 (i32.const 0))))) + "alignment must not be larger than natural" +) +(assert_invalid + (module (memory 0) (func(v128.store align=32 (i32.const 0) (v128.const i32x4 0 0 0 0)))) + "alignment must not be larger than natural" +) +(assert_invalid + (module (memory 1) (func (result v128) (i16x8.load8x8_s align=16 (i32.const 0)))) + "alignment must not be larger than natural" +) +(assert_invalid + (module (memory 1) (func (result v128) (i16x8.load8x8_u align=16 (i32.const 0)))) + "alignment must not be larger than natural" +) +(assert_invalid + (module (memory 1) (func (result v128) (i32x4.load16x4_s align=16 (i32.const 0)))) + "alignment must not be larger than natural" +) +(assert_invalid + (module (memory 1) (func (result v128) (i32x4.load16x4_u align=16 (i32.const 0)))) + "alignment must not be larger than natural" +) +(assert_invalid + (module (memory 1) (func (result v128) (i64x2.load32x2_s align=16 (i32.const 0)))) + "alignment must not be larger than natural" +) +(assert_invalid + (module (memory 1) (func (result v128) (i64x2.load32x2_u align=16 (i32.const 0)))) + "alignment must not be larger than natural" +) +(assert_invalid + (module (memory 1) (func (result v128) (v8x16.load_splat align=2 (i32.const 0)))) + "alignment must not be larger than natural" +) +(assert_invalid + (module (memory 1) (func (result v128) (v16x8.load_splat align=4 (i32.const 0)))) + "alignment must not be larger than natural" +) +(assert_invalid + (module (memory 1) (func (result v128) (v32x4.load_splat align=8 (i32.const 0)))) + "alignment must not be larger than natural" +) +(assert_invalid + (module (memory 1) (func (result v128) (v64x2.load_splat align=16 (i32.const 0)))) + "alignment must not be larger than natural" +) + +;; Malformed alignment - (func (export "v128.load_align_1") (result v128) - (v128.load align=1 (i32.const 0)) +(assert_malformed + (module quote + "(memory 1) (func (drop (v128.load align=-1 (i32.const 0))))" ) - (func (export "v128.load_align_2") (result v128) - (v128.load align=2 (i32.const 0)) + "alignment must be a power of two" +) +(assert_malformed + (module quote + "(memory 1) (func (drop (v128.load align=0 (i32.const 0))))" ) - (func (export "v128.load_align_4") (result v128) - (v128.load align=4 (i32.const 0)) + "alignment must be a power of two" +) +(assert_malformed + (module quote + "(memory 1) (func (drop (v128.load align=7 (i32.const 0))))" ) - (func (export "v128.load_align_8") (result v128) - (v128.load align=8 (i32.const 0)) + "alignment must be a power of two" +) +(assert_malformed + (module quote + "(memory 1) (func (v128.store align=-1 (i32.const 0) (v128.const i32x4 0 0 0 0)))" ) - (func (export "v128.load_align_16") (result v128) - (v128.load align=16 (i32.const 0)) + "alignment must be a power of two" +) +(assert_malformed + (module quote + "(memory 0) (func (v128.store align=0 (i32.const 0) (v128.const i32x4 0 0 0 0)))" ) - - (func (export "v128.store_align_1") (result v128) - (v128.store align=1 (i32.const 0) (v128.const i32x4 0 1 2 3)) - (v128.load (i32.const 0)) + "alignment must be a power of two" +) +(assert_malformed + (module quote + "(memory 0) (func (v128.store align=7 (i32.const 0) (v128.const i32x4 0 0 0 0)))" ) - (func (export "v128.store_align_2") (result v128) - (v128.store align=2 (i32.const 0) (v128.const i32x4 0 1 2 3)) - (v128.load (i32.const 0)) + "alignment must be a power of two" +) +(assert_malformed + (module quote + "(memory 1) (func (result v128) (i16x8.load8x8_s align=-1 (i32.const 0)))" ) - (func (export "v128.store_align_4") (result v128) - (v128.store align=4 (i32.const 0) (v128.const i32x4 0 1 2 3)) - (v128.load (i32.const 0)) + "alignment must be a power of two" +) +(assert_malformed + (module quote + "(memory 1) (func (result v128) (i16x8.load8x8_s align=0 (i32.const 0)))" ) - (func (export "v128.store_align_8") (result v128) - (v128.store align=8 (i32.const 0) (v128.const i32x4 0 1 2 3)) - (v128.load (i32.const 0)) + "alignment must be a power of two" +) +(assert_malformed + (module quote + "(memory 1) (func (result v128) (i16x8.load8x8_s align=7 (i32.const 0)))" ) - (func (export "v128.store_align_16") (result v128) - (v128.store align=16 (i32.const 0) (v128.const i32x4 0 1 2 3)) - (v128.load (i32.const 0)) + "alignment must be a power of two" +) +(assert_malformed + (module quote + "(memory 1) (func (result v128) (i16x8.load8x8_u align=-1 (i32.const 0)))" ) + "alignment must be a power of two" ) - -(assert_return (invoke "v128.load_align_1") (v128.const i32x4 0x03020100 0x07060504 0x11100908 0x15141312)) -(assert_return (invoke "v128.load_align_2") (v128.const i32x4 0x03020100 0x07060504 0x11100908 0x15141312)) -(assert_return (invoke "v128.load_align_4") (v128.const i32x4 0x03020100 0x07060504 0x11100908 0x15141312)) -(assert_return (invoke "v128.load_align_8") (v128.const i32x4 0x03020100 0x07060504 0x11100908 0x15141312)) -(assert_return (invoke "v128.load_align_16") (v128.const i32x4 0x03020100 0x07060504 0x11100908 0x15141312)) - -(assert_return (invoke "v128.store_align_1") (v128.const i32x4 0 1 2 3)) -(assert_return (invoke "v128.store_align_2") (v128.const i32x4 0 1 2 3)) -(assert_return (invoke "v128.store_align_4") (v128.const i32x4 0 1 2 3)) -(assert_return (invoke "v128.store_align_8") (v128.const i32x4 0 1 2 3)) -(assert_return (invoke "v128.store_align_16") (v128.const i32x4 0 1 2 3)) - - -;; Invalid alignment - -(assert_invalid - (module - (memory 1) - (func (drop (v128.load align=32 (i32.const 0)))) +(assert_malformed + (module quote + "(memory 1) (func (result v128) (i16x8.load8x8_u align=0 (i32.const 0)))" ) - "alignment must not be larger than natural" + "alignment must be a power of two" ) (assert_malformed (module quote - "(memory 1)" - "(func (drop (v128.load align=-1 (i32.const 0))))" + "(memory 1) (func (result v128) (i16x8.load8x8_u align=7 (i32.const 0)))" ) - "unknown operator" + "alignment must be a power of two" ) (assert_malformed (module quote - "(memory 1)" - "(func (drop (v128.load align=0 (i32.const 0))))" + "(memory 1) (func (result v128) (i32x4.load16x4_s align=-1 (i32.const 0)))" ) "alignment must be a power of two" ) (assert_malformed (module quote - "(memory 1)" - "(func (drop (v128.load align=7 (i32.const 0))))" + "(memory 1) (func (result v128) (i32x4.load16x4_s align=0 (i32.const 0)))" ) "alignment must be a power of two" ) - -(assert_invalid - (module - (memory 0) - (func(v128.store align=32 (i32.const 0) (v128.const i32x4 0 0 0 0))) +(assert_malformed + (module quote + "(memory 1) (func (result v128) (i32x4.load16x4_s align=7 (i32.const 0)))" ) - "alignment must not be larger than natural" + "alignment must be a power of two" +) +(assert_malformed + (module quote + "(memory 1) (func (result v128) (i32x4.load16x4_u align=-1 (i32.const 0)))" + ) + "alignment must be a power of two" +) +(assert_malformed + (module quote + "(memory 1) (func (result v128) (i32x4.load16x4_u align=0 (i32.const 0)))" + ) + "alignment must be a power of two" ) (assert_malformed (module quote - "(memory 1)" - " (func (v128.store align=-1 (i32.const 0) (v128.const i32x4 0 0 0 0)))" + "(memory 1) (func (result v128) (i32x4.load16x4_u align=7 (i32.const 0)))" ) - "unknown operator" + "alignment must be a power of two" +) +(assert_malformed + (module quote + "(memory 1) (func (result v128) (i64x2.load32x2_s align=-1 (i32.const 0)))" + ) + "alignment must be a power of two" +) +(assert_malformed + (module quote + "(memory 1) (func (result v128) (i64x2.load32x2_s align=0 (i32.const 0)))" + ) + "alignment must be a power of two" +) +(assert_malformed + (module quote + "(memory 1) (func (result v128) (i64x2.load32x2_s align=7 (i32.const 0)))" + ) + "alignment must be a power of two" +) +(assert_malformed + (module quote + "(memory 1) (func (result v128) (i64x2.load32x2_u align=-1 (i32.const 0)))" + ) + "alignment must be a power of two" +) +(assert_malformed + (module quote + "(memory 1) (func (result v128) (i64x2.load32x2_u align=0 (i32.const 0)))" + ) + "alignment must be a power of two" +) +(assert_malformed + (module quote + "(memory 1) (func (result v128) (i64x2.load32x2_u align=7 (i32.const 0)))" + ) + "alignment must be a power of two" +) +(assert_malformed + (module quote + "(memory 1) (func (result v128) (v8x16.load_splat align=-1 (i32.const 0)))" + ) + "alignment must be a power of two" +) +(assert_malformed + (module quote + "(memory 1) (func (result v128) (v8x16.load_splat align=0 (i32.const 0)))" + ) + "alignment must be a power of two" +) +(assert_malformed + (module quote + "(memory 1) (func (result v128) (v16x8.load_splat align=-1 (i32.const 0)))" + ) + "alignment must be a power of two" +) +(assert_malformed + (module quote + "(memory 1) (func (result v128) (v16x8.load_splat align=0 (i32.const 0)))" + ) + "alignment must be a power of two" +) +(assert_malformed + (module quote + "(memory 1) (func (result v128) (v32x4.load_splat align=-1 (i32.const 0)))" + ) + "alignment must be a power of two" +) +(assert_malformed + (module quote + "(memory 1) (func (result v128) (v32x4.load_splat align=0 (i32.const 0)))" + ) + "alignment must be a power of two" +) +(assert_malformed + (module quote + "(memory 1) (func (result v128) (v32x4.load_splat align=3 (i32.const 0)))" + ) + "alignment must be a power of two" +) +(assert_malformed + (module quote + "(memory 1) (func (result v128) (v64x2.load_splat align=-1 (i32.const 0)))" + ) + "alignment must be a power of two" ) (assert_malformed (module quote - "(memory 0)" - " (func (v128.store align=0 (i32.const 0) (v128.const i32x4 0 0 0 0)))" + "(memory 1) (func (result v128) (v64x2.load_splat align=0 (i32.const 0)))" ) "alignment must be a power of two" ) (assert_malformed (module quote - "(memory 0)" - " (func (v128.store align=7 (i32.const 0) (v128.const i32x4 0 0 0 0)))" + "(memory 1) (func (result v128) (v64x2.load_splat align=7 (i32.const 0)))" ) "alignment must be a power of two" ) @@ -136,7 +327,7 @@ (module (memory 1) - (func (export "v128_unalign_read_and_write") (result v128) + (func (export "v128_unaligned_read_and_write") (result v128) (local v128) (v128.store (i32.const 0) (v128.const i8x16 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15)) (v128.load (i32.const 0)) @@ -146,19 +337,19 @@ (v128.store align=2 (i32.const 0) (v128.const i16x8 0 1 2 3 4 5 6 7)) (v128.load align=2 (i32.const 0)) ) - (func (export "v128_aligned_read_and_unalign_write") (result v128) + (func (export "v128_aligned_read_and_unaligned_write") (result v128) (local v128) (v128.store (i32.const 0) (v128.const i32x4 0 1 2 3)) (v128.load align=2 (i32.const 0)) ) - (func (export "v128_unalign_read_and_aligned_write") (result v128) + (func (export "v128_unaligned_read_and_aligned_write") (result v128) (local v128) (v128.store align=2 (i32.const 0) (v128.const i32x4 0 1 2 3)) (v128.load (i32.const 0)) ) ) -(assert_return (invoke "v128_unalign_read_and_write") (v128.const i8x16 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15)) +(assert_return (invoke "v128_unaligned_read_and_write") (v128.const i8x16 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15)) (assert_return (invoke "v128_aligned_read_and_write") (v128.const i16x8 0 1 2 3 4 5 6 7)) -(assert_return (invoke "v128_aligned_read_and_unalign_write") (v128.const i32x4 0 1 2 3)) -(assert_return (invoke "v128_unalign_read_and_aligned_write") (v128.const i32x4 0 1 2 3)) +(assert_return (invoke "v128_aligned_read_and_unaligned_write") (v128.const i32x4 0 1 2 3)) +(assert_return (invoke "v128_unaligned_read_and_aligned_write") (v128.const i32x4 0 1 2 3)) \ No newline at end of file