Skip to content

Commit c1bfe2a

Browse files
author
James Marsh
committed
Add V128 comparison operations
Tested using ``` (module (import "wasi_snapshot_preview1" "proc_exit" (func $proc_exit (param i32))) (memory (export "memory") 1) (func $assert_true (param v128) local.get 0 v128.any_true i32.eqz if unreachable end ) (func $main (export "_start") ;; Test v128.not v128.const i8x16 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 v128.not v128.const i8x16 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 i8x16.eq call $assert_true ;; Test v128.and v128.const i8x16 255 255 255 255 0 0 0 0 255 255 255 255 0 0 0 0 v128.const i8x16 255 255 0 0 255 255 0 0 255 255 0 0 255 255 0 0 v128.and v128.const i8x16 255 255 0 0 0 0 0 0 255 255 0 0 0 0 0 0 i8x16.eq call $assert_true ;; Test v128.andnot v128.const i8x16 255 255 255 255 0 0 0 0 255 255 255 255 0 0 0 0 v128.const i8x16 255 255 0 0 255 255 0 0 255 255 0 0 255 255 0 0 v128.andnot v128.const i8x16 0 0 255 255 0 0 0 0 0 0 255 255 0 0 0 0 i8x16.eq call $assert_true ;; Test v128.or v128.const i8x16 255 255 0 0 0 0 255 255 255 255 0 0 0 0 255 0 v128.const i8x16 0 0 255 255 255 255 0 0 0 0 255 255 255 255 0 0 v128.or v128.const i8x16 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 0 i8x16.eq call $assert_true ;; Test v128.xor v128.const i8x16 255 255 0 0 255 255 0 0 255 255 0 0 255 255 0 0 v128.const i8x16 255 255 255 255 0 0 0 0 255 255 255 255 0 0 0 0 v128.xor v128.const i8x16 0 0 255 255 255 255 0 0 0 0 255 255 255 255 0 0 i8x16.eq call $assert_true i32.const 0 call $proc_exit ) ) ```
1 parent 5b2ab61 commit c1bfe2a

1 file changed

Lines changed: 75 additions & 1 deletion

File tree

core/iwasm/interpreter/wasm_interp_fast.c

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5722,6 +5722,20 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
57225722

57235723
/* i8x16 comparison operations */
57245724
case SIMD_i8x16_eq:
5725+
{
5726+
V128 v1 = POP_V128();
5727+
V128 v2 = POP_V128();
5728+
int i;
5729+
addr_ret = GET_OFFSET();
5730+
5731+
V128 result;
5732+
for (i = 0; i < 16; i++) {
5733+
result.i8x16[i] =
5734+
v1.i8x16[i] == v2.i8x16[i] ? 0xff : 0;
5735+
}
5736+
PUT_V128_TO_ADDR(frame_lp + addr_ret, result);
5737+
break;
5738+
}
57255739
case SIMD_i8x16_ne:
57265740
case SIMD_i8x16_lt_s:
57275741
case SIMD_i8x16_lt_u:
@@ -5792,12 +5806,56 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
57925806
break;
57935807
}
57945808

5795-
/* v128 comparison operations */
5809+
/* v128 bitwise operations */
5810+
#define SIMD_V128_BITWISE_OP_COMMON(result_expr_0, result_expr_1) \
5811+
do { \
5812+
V128 result; \
5813+
result.i64x2[0] = (result_expr_0); \
5814+
result.i64x2[1] = (result_expr_1); \
5815+
addr_ret = GET_OFFSET(); \
5816+
PUT_V128_TO_ADDR(frame_lp + addr_ret, result); \
5817+
} while (0)
5818+
57965819
case SIMD_v128_not:
5820+
{
5821+
V128 value = POP_V128();
5822+
SIMD_V128_BITWISE_OP_COMMON(~value.i64x2[0],
5823+
~value.i64x2[1]);
5824+
break;
5825+
}
57975826
case SIMD_v128_and:
5827+
{
5828+
V128 v2 = POP_V128();
5829+
V128 v1 = POP_V128();
5830+
SIMD_V128_BITWISE_OP_COMMON(v1.i64x2[0] & v2.i64x2[0],
5831+
v1.i64x2[1] & v2.i64x2[1]);
5832+
break;
5833+
}
57985834
case SIMD_v128_andnot:
5835+
{
5836+
V128 v2 = POP_V128();
5837+
V128 v1 = POP_V128();
5838+
SIMD_V128_BITWISE_OP_COMMON(
5839+
v1.i64x2[0] & (~v2.i64x2[0]),
5840+
v1.i64x2[1] & (~v2.i64x2[1]));
5841+
break;
5842+
}
57995843
case SIMD_v128_or:
5844+
{
5845+
V128 v2 = POP_V128();
5846+
V128 v1 = POP_V128();
5847+
SIMD_V128_BITWISE_OP_COMMON(v1.i64x2[0] | v2.i64x2[0],
5848+
v1.i64x2[1] | v2.i64x2[1]);
5849+
break;
5850+
}
58005851
case SIMD_v128_xor:
5852+
{
5853+
V128 v2 = POP_V128();
5854+
V128 v1 = POP_V128();
5855+
SIMD_V128_BITWISE_OP_COMMON(v1.i64x2[0] ^ v2.i64x2[0],
5856+
v1.i64x2[1] ^ v2.i64x2[1]);
5857+
break;
5858+
}
58015859
case SIMD_v128_bitselect:
58025860
{
58035861
wasm_set_exception(module, "unsupported SIMD opcode");
@@ -5841,6 +5899,22 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
58415899
case SIMD_i8x16_neg:
58425900
case SIMD_i8x16_popcnt:
58435901
case SIMD_i8x16_all_true:
5902+
{
5903+
V128 v = POP_V128();
5904+
uint8_t *bytes = (uint8_t *)&v;
5905+
bool all_true = true;
5906+
5907+
for (int i = 0; i < 16; i++) {
5908+
if (bytes[i] == 0) {
5909+
all_true = false;
5910+
break;
5911+
}
5912+
}
5913+
5914+
PUSH_I32(all_true ? 1 : 0);
5915+
break;
5916+
}
5917+
58445918
case SIMD_i8x16_bitmask:
58455919
case SIMD_i8x16_narrow_i16x8_s:
58465920
case SIMD_i8x16_narrow_i16x8_u:

0 commit comments

Comments
 (0)