|
| 1 | +;; Tests for dot products. |
| 2 | +;; |
| 3 | +;; This is the same as the upstream relaxed_dot_product.wast test in |
| 4 | +;; relaxed-simd, but with the non-relaxed versions, and with picking the proper |
| 5 | +;; outcome in the multiple-choice questions (which use either() in the original |
| 6 | +;; test). |
| 7 | + |
| 8 | +(module |
| 9 | + (func (export "i16x8.dot_i8x16_i7x16_s") (param v128 v128) (result v128) (i16x8.dot_i8x16_i7x16_s (local.get 0) (local.get 1))) |
| 10 | + (func (export "i32x4.dot_i8x16_i7x16_add_s") (param v128 v128 v128) (result v128) (i32x4.dot_i8x16_i7x16_add_s (local.get 0) (local.get 1) (local.get 2))) |
| 11 | + |
| 12 | + (func (export "i16x8.dot_i8x16_i7x16_s_cmp") (param v128 v128) (result v128) |
| 13 | + (i16x8.eq |
| 14 | + (i16x8.dot_i8x16_i7x16_s (local.get 0) (local.get 1)) |
| 15 | + (i16x8.dot_i8x16_i7x16_s (local.get 0) (local.get 1)))) |
| 16 | + (func (export "i32x4.dot_i8x16_i7x16_add_s_cmp") (param v128 v128 v128) (result v128) |
| 17 | + (i16x8.eq |
| 18 | + (i32x4.dot_i8x16_i7x16_add_s (local.get 0) (local.get 1) (local.get 2)) |
| 19 | + (i32x4.dot_i8x16_i7x16_add_s (local.get 0) (local.get 1) (local.get 2)))) |
| 20 | +) |
| 21 | + |
| 22 | +;; Simple values to ensure things are functional. |
| 23 | +(assert_return (invoke "i16x8.dot_i8x16_i7x16_s" |
| 24 | + (v128.const i8x16 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15) |
| 25 | + (v128.const i8x16 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15)) |
| 26 | + (v128.const i16x8 1 13 41 85 145 221 313 421)) |
| 27 | + |
| 28 | +;; Test max and min i8 values; |
| 29 | +(assert_return (invoke "i16x8.dot_i8x16_i7x16_s" |
| 30 | + (v128.const i8x16 -128 -128 127 127 0 0 0 0 0 0 0 0 0 0 0 0) |
| 31 | + (v128.const i8x16 127 127 127 127 0 0 0 0 0 0 0 0 0 0 0 0)) |
| 32 | + (v128.const i16x8 -32512 32258 0 0 0 0 0 0)) |
| 33 | + |
| 34 | +;; signed * unsigned : -128 * 129 * 2 = -33,024 saturated to -32,768 |
| 35 | +;; signed * signed : -128 * -127 * 2 = 32,512 |
| 36 | +;; unsigned * unsigned : 128 * 129 * 2 = 33,024 |
| 37 | +(assert_return (invoke "i16x8.dot_i8x16_i7x16_s" |
| 38 | + (v128.const i8x16 -128 -128 0 0 0 0 0 0 0 0 0 0 0 0 0 0) |
| 39 | + (v128.const i8x16 -127 -127 0 0 0 0 0 0 0 0 0 0 0 0 0 0)) |
| 40 | + (v128.const i16x8 32512 0 0 0 0 0 0 0)) |
| 41 | + |
| 42 | +;; Simple values to ensure things are functional. |
| 43 | +(assert_return (invoke "i32x4.dot_i8x16_i7x16_add_s" |
| 44 | + (v128.const i8x16 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15) |
| 45 | + (v128.const i8x16 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15) |
| 46 | + (v128.const i32x4 0 1 2 3)) |
| 47 | + ;; intermediate result is [14, 126, 366, 734] |
| 48 | + (v128.const i32x4 14 127 368 737)) |
| 49 | + |
| 50 | +;; Test max and min i8 values; |
| 51 | +(assert_return (invoke "i32x4.dot_i8x16_i7x16_add_s" |
| 52 | + (v128.const i8x16 -128 -128 -128 -128 127 127 127 127 0 0 0 0 0 0 0 0) |
| 53 | + (v128.const i8x16 127 127 127 127 127 127 127 127 0 0 0 0 0 0 0 0) |
| 54 | + (v128.const i32x4 1 2 3 4)) |
| 55 | + ;; intermediate result is [-65024, 64516, 0, 0] |
| 56 | + (v128.const i32x4 -65023 64518 3 4)) |
| 57 | + |
| 58 | +;; signed * unsigned : -128 * 129 * 4 = -66,048 (+ 1) VPDPBUSD AVX2-VNNI or AVX512-VNNI |
| 59 | +;; signed * unsigned with intermediate saturation : |
| 60 | +;; (-128 * 129) + (-128 * 129) = -33024 saturated to -32768 (PMADDUBSW) |
| 61 | +;; -32768 + -32768 = -65536 (+ 1) |
| 62 | +;; signed * signed : -128 * -127 * 4 = 65,024 (+ 1) |
| 63 | +;; unsigned * unsigned : 128 * 129 * 2 = 66,048 (+ 1) |
| 64 | +(assert_return (invoke "i32x4.dot_i8x16_i7x16_add_s" |
| 65 | + (v128.const i8x16 -128 -128 -128 -128 0 0 0 0 0 0 0 0 0 0 0 0) |
| 66 | + (v128.const i8x16 -127 -127 -127 -127 0 0 0 0 0 0 0 0 0 0 0 0) |
| 67 | + (v128.const i32x4 1 2 3 4)) |
| 68 | + (v128.const i32x4 65025 2 3 4)) |
| 69 | + |
| 70 | +;; Check that multiple calls to the relaxed instruction with same inputs returns same results. |
| 71 | + |
| 72 | +;; Test max and min i8 values; |
| 73 | +(assert_return (invoke "i16x8.dot_i8x16_i7x16_s_cmp" |
| 74 | + (v128.const i8x16 -128 -128 127 127 0 0 0 0 0 0 0 0 0 0 0 0) |
| 75 | + (v128.const i8x16 127 127 127 127 0 0 0 0 0 0 0 0 0 0 0 0)) |
| 76 | + (v128.const i16x8 -1 -1 -1 -1 -1 -1 -1 -1)) |
| 77 | + |
| 78 | +;; Test max and min i8 values; |
| 79 | +(assert_return (invoke "i32x4.dot_i8x16_i7x16_add_s_cmp" |
| 80 | + (v128.const i8x16 -128 -128 -128 -128 127 127 127 127 0 0 0 0 0 0 0 0) |
| 81 | + (v128.const i8x16 127 127 127 127 127 127 127 127 0 0 0 0 0 0 0 0) |
| 82 | + (v128.const i32x4 1 2 3 4)) |
| 83 | + ;; intermediate result is [-65024, 64516, 0, 0] |
| 84 | + (v128.const i32x4 -1 -1 -1 -1)) |
| 85 | + |
| 86 | +;; signed * unsigned : -128 * 129 * 2 = -33,024 saturated to -32,768 |
| 87 | +;; signed * signed : -128 * -127 * 2 = 32,512 |
| 88 | +;; unsigned * unsigned : 128 * 129 * 2 = 33,024 |
| 89 | +(assert_return (invoke "i16x8.dot_i8x16_i7x16_s_cmp" |
| 90 | + (v128.const i8x16 -128 -128 0 0 0 0 0 0 0 0 0 0 0 0 0 0) |
| 91 | + (v128.const i8x16 -127 -127 0 0 0 0 0 0 0 0 0 0 0 0 0 0)) |
| 92 | + (v128.const i16x8 -1 -1 -1 -1 -1 -1 -1 -1)) |
| 93 | + |
| 94 | +;; signed * unsigned : -128 * 129 * 4 = -66,048 (+ 1) VPDPBUSD AVX2-VNNI or AVX512-VNNI |
| 95 | +;; signed * unsigned with intermediate saturation : |
| 96 | +;; (-128 * 129) + (-128 * 129) = -33024 saturated to -32768 (PMADDUBSW) |
| 97 | +;; -32768 + -32768 = -65536 (+ 1) |
| 98 | +;; signed * signed : -128 * -127 * 4 = 65,024 (+ 1) |
| 99 | +;; unsigned * unsigned : 128 * 129 * 2 = 66,048 (+ 1) |
| 100 | +(assert_return (invoke "i32x4.dot_i8x16_i7x16_add_s_cmp" |
| 101 | + (v128.const i8x16 -128 -128 -128 -128 0 0 0 0 0 0 0 0 0 0 0 0) |
| 102 | + (v128.const i8x16 -127 -127 -127 -127 0 0 0 0 0 0 0 0 0 0 0 0) |
| 103 | + (v128.const i32x4 1 2 3 4)) |
| 104 | + (v128.const i32x4 -1 -1 -1 -1)) |
0 commit comments