1
1
/*
2
- * Copyright (c) 2019, 2024 , Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 2019, 2025 , Oracle and/or its affiliates. All rights reserved.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* The Universal Permissive License (UPL), Version 1.0
57
57
import static org .graalvm .wasm .WasmType .NULL_TYPE ;
58
58
import static org .graalvm .wasm .WasmType .V128_TYPE ;
59
59
import static org .graalvm .wasm .WasmType .VOID_TYPE ;
60
+ import static org .graalvm .wasm .constants .Bytecode .vectorOpcodeToBytecode ;
60
61
import static org .graalvm .wasm .constants .Sizes .MAX_MEMORY_64_DECLARATION_SIZE ;
61
62
import static org .graalvm .wasm .constants .Sizes .MAX_MEMORY_DECLARATION_SIZE ;
62
63
import static org .graalvm .wasm .constants .Sizes .MAX_TABLE_DECLARATION_SIZE ;
@@ -1827,6 +1828,9 @@ private void readNumericInstructions(ParserState state, int opcode) {
1827
1828
checkSIMDSupport ();
1828
1829
int vectorOpcode = readUnsignedInt32 ();
1829
1830
state .addVectorFlag ();
1831
+ if (vectorOpcode > 0xFF ) {
1832
+ checkRelaxedSIMDSupport (vectorOpcode );
1833
+ }
1830
1834
switch (vectorOpcode ) {
1831
1835
case Instructions .VECTOR_V128_LOAD :
1832
1836
load (state , V128_TYPE , 128 , longMultiResult );
@@ -1839,7 +1843,7 @@ private void readNumericInstructions(ParserState state, int opcode) {
1839
1843
case Instructions .VECTOR_V128_LOAD32X2_S :
1840
1844
case Instructions .VECTOR_V128_LOAD32X2_U :
1841
1845
load (state , V128_TYPE , 64 , longMultiResult );
1842
- state .addExtendedMemoryInstruction (vectorOpcode , (int ) longMultiResult [0 ], longMultiResult [1 ], module .memoryHasIndexType64 ((int ) longMultiResult [0 ]));
1846
+ state .addExtendedMemoryInstruction (vectorOpcodeToBytecode ( vectorOpcode ) , (int ) longMultiResult [0 ], longMultiResult [1 ], module .memoryHasIndexType64 ((int ) longMultiResult [0 ]));
1843
1847
break ;
1844
1848
case Instructions .VECTOR_V128_LOAD8_SPLAT :
1845
1849
load (state , V128_TYPE , 8 , longMultiResult );
@@ -1969,7 +1973,7 @@ private void readNumericInstructions(ParserState state, int opcode) {
1969
1973
state .popChecked (V128_TYPE );
1970
1974
state .popChecked (V128_TYPE );
1971
1975
state .push (V128_TYPE );
1972
- state .addInstruction (vectorOpcode , indices );
1976
+ state .addInstruction (Bytecode . VECTOR_I8X16_SHUFFLE , indices );
1973
1977
break ;
1974
1978
}
1975
1979
case Instructions .VECTOR_I8X16_EXTRACT_LANE_S :
@@ -1987,7 +1991,7 @@ private void readNumericInstructions(ParserState state, int opcode) {
1987
1991
}
1988
1992
state .popChecked (V128_TYPE );
1989
1993
state .push (shape .getUnpackedType ());
1990
- state .addVectorLaneInstruction (vectorOpcode , laneIndex );
1994
+ state .addVectorLaneInstruction (vectorOpcodeToBytecode ( vectorOpcode ) , laneIndex );
1991
1995
break ;
1992
1996
}
1993
1997
case Instructions .VECTOR_I8X16_REPLACE_LANE :
@@ -2004,7 +2008,7 @@ private void readNumericInstructions(ParserState state, int opcode) {
2004
2008
state .popChecked (shape .getUnpackedType ());
2005
2009
state .popChecked (V128_TYPE );
2006
2010
state .push (V128_TYPE );
2007
- state .addVectorLaneInstruction (vectorOpcode , laneIndex );
2011
+ state .addVectorLaneInstruction (vectorOpcodeToBytecode ( vectorOpcode ) , laneIndex );
2008
2012
break ;
2009
2013
}
2010
2014
case Instructions .VECTOR_I8X16_SPLAT :
@@ -2016,7 +2020,7 @@ private void readNumericInstructions(ParserState state, int opcode) {
2016
2020
Vector128Shape shape = Vector128Shape .ofInstruction (vectorOpcode );
2017
2021
state .popChecked (shape .getUnpackedType ());
2018
2022
state .push (V128_TYPE );
2019
- state .addInstruction (vectorOpcode );
2023
+ state .addInstruction (vectorOpcodeToBytecode ( vectorOpcode ) );
2020
2024
break ;
2021
2025
}
2022
2026
case Instructions .VECTOR_V128_ANY_TRUE :
@@ -2030,7 +2034,7 @@ private void readNumericInstructions(ParserState state, int opcode) {
2030
2034
case Instructions .VECTOR_I64X2_BITMASK :
2031
2035
state .popChecked (V128_TYPE );
2032
2036
state .push (I32_TYPE );
2033
- state .addInstruction (vectorOpcode );
2037
+ state .addInstruction (vectorOpcodeToBytecode ( vectorOpcode ) );
2034
2038
break ;
2035
2039
case Instructions .VECTOR_V128_NOT :
2036
2040
case Instructions .VECTOR_I8X16_ABS :
@@ -2082,9 +2086,13 @@ private void readNumericInstructions(ParserState state, int opcode) {
2082
2086
case Instructions .VECTOR_F64X2_CONVERT_LOW_I32X4_U :
2083
2087
case Instructions .VECTOR_F32X4_DEMOTE_F64X2_ZERO :
2084
2088
case Instructions .VECTOR_F64X2_PROMOTE_LOW_F32X4 :
2089
+ case Instructions .VECTOR_I32X4_RELAXED_TRUNC_F32X4_S :
2090
+ case Instructions .VECTOR_I32X4_RELAXED_TRUNC_F32X4_U :
2091
+ case Instructions .VECTOR_I32X4_RELAXED_TRUNC_F64X2_S_ZERO :
2092
+ case Instructions .VECTOR_I32X4_RELAXED_TRUNC_F64X2_U_ZERO :
2085
2093
state .popChecked (V128_TYPE );
2086
2094
state .push (V128_TYPE );
2087
- state .addInstruction (vectorOpcode );
2095
+ state .addInstruction (vectorOpcodeToBytecode ( vectorOpcode ) );
2088
2096
break ;
2089
2097
case Instructions .VECTOR_I8X16_SWIZZLE :
2090
2098
case Instructions .VECTOR_I8X16_EQ :
@@ -2206,10 +2214,17 @@ private void readNumericInstructions(ParserState state, int opcode) {
2206
2214
case Instructions .VECTOR_F64X2_MAX :
2207
2215
case Instructions .VECTOR_F64X2_PMIN :
2208
2216
case Instructions .VECTOR_F64X2_PMAX :
2217
+ case Instructions .VECTOR_I8X16_RELAXED_SWIZZLE :
2218
+ case Instructions .VECTOR_F32X4_RELAXED_MIN :
2219
+ case Instructions .VECTOR_F32X4_RELAXED_MAX :
2220
+ case Instructions .VECTOR_F64X2_RELAXED_MIN :
2221
+ case Instructions .VECTOR_F64X2_RELAXED_MAX :
2222
+ case Instructions .VECTOR_I16X8_RELAXED_Q15MULR_S :
2223
+ case Instructions .VECTOR_I16X8_RELAXED_DOT_I8X16_I7X16_S :
2209
2224
state .popChecked (V128_TYPE );
2210
2225
state .popChecked (V128_TYPE );
2211
2226
state .push (V128_TYPE );
2212
- state .addInstruction (vectorOpcode );
2227
+ state .addInstruction (vectorOpcodeToBytecode ( vectorOpcode ) );
2213
2228
break ;
2214
2229
case Instructions .VECTOR_I8X16_SHL :
2215
2230
case Instructions .VECTOR_I8X16_SHR_S :
@@ -2226,14 +2241,23 @@ private void readNumericInstructions(ParserState state, int opcode) {
2226
2241
state .popChecked (I32_TYPE );
2227
2242
state .popChecked (V128_TYPE );
2228
2243
state .push (V128_TYPE );
2229
- state .addInstruction (vectorOpcode );
2244
+ state .addInstruction (vectorOpcodeToBytecode ( vectorOpcode ) );
2230
2245
break ;
2231
2246
case Instructions .VECTOR_V128_BITSELECT :
2247
+ case Instructions .VECTOR_F32X4_RELAXED_MADD :
2248
+ case Instructions .VECTOR_F32X4_RELAXED_NMADD :
2249
+ case Instructions .VECTOR_F64X2_RELAXED_MADD :
2250
+ case Instructions .VECTOR_F64X2_RELAXED_NMADD :
2251
+ case Instructions .VECTOR_I8X16_RELAXED_LANESELECT :
2252
+ case Instructions .VECTOR_I16X8_RELAXED_LANESELECT :
2253
+ case Instructions .VECTOR_I32X4_RELAXED_LANESELECT :
2254
+ case Instructions .VECTOR_I64X2_RELAXED_LANESELECT :
2255
+ case Instructions .VECTOR_I32X4_RELAXED_DOT_I8X16_I7X16_ADD_S :
2232
2256
state .popChecked (V128_TYPE );
2233
2257
state .popChecked (V128_TYPE );
2234
2258
state .popChecked (V128_TYPE );
2235
2259
state .push (V128_TYPE );
2236
- state .addInstruction (vectorOpcode );
2260
+ state .addInstruction (vectorOpcodeToBytecode ( vectorOpcode ) );
2237
2261
break ;
2238
2262
default :
2239
2263
fail (Failure .UNSPECIFIED_MALFORMED , "Unknown opcode: 0xFD 0x%02x" , vectorOpcode );
@@ -2271,6 +2295,10 @@ private void checkSIMDSupport() {
2271
2295
checkContextOption (wasmContext .getContextOptions ().supportSIMD (), "Vector instructions are not enabled (opcode: 0x%02x)" , Instructions .VECTOR );
2272
2296
}
2273
2297
2298
+ private void checkRelaxedSIMDSupport (int vectorOpcode ) {
2299
+ checkContextOption (wasmContext .getContextOptions ().supportRelaxedSIMD (), "Relaxed vector instructions are not enabled (opcode: 0x%02x 0x%x)" , Instructions .VECTOR , vectorOpcode );
2300
+ }
2301
+
2274
2302
private void store (ParserState state , byte type , int n , long [] result ) {
2275
2303
int alignHint = readAlignHint (n );
2276
2304
final int memoryIndex = readMemoryIndexFromAlignHint (alignHint );
0 commit comments