use array.get_s/get_u for packed array types (i8/i16)

This commit is contained in:
Volker Berlin 2021-01-02 21:43:02 +01:00
parent 6bd993617c
commit 4d2dfdeaa2
7 changed files with 30 additions and 4 deletions

View File

@ -1371,6 +1371,12 @@ public class BinaryModuleWriter extends ModuleWriter implements InstructionOpcod
case GET: case GET:
opCode = ARRAY_GET; opCode = ARRAY_GET;
break; break;
case GET_S:
opCode = ARRAY_GET_S;
break;
case GET_U:
opCode = ARRAY_GET_U;
break;
case SET: case SET:
opCode = ARRAY_SET; opCode = ARRAY_SET;
break; break;

View File

@ -502,6 +502,10 @@ interface InstructionOpcodes {
static final int ARRAY_GET = 0xFB13; static final int ARRAY_GET = 0xFB13;
static final int ARRAY_GET_S = 0xFB14;
static final int ARRAY_GET_U = 0xFB15;
static final int ARRAY_SET = 0xFB16; static final int ARRAY_SET = 0xFB16;
static final int ARRAY_LEN = 0xFB17; static final int ARRAY_LEN = 0xFB17;

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2018 - 2020 Volker Berlin (i-net software) * Copyright 2018 - 2021 Volker Berlin (i-net software)
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -207,13 +207,13 @@ class JavaMethodWasmCodeBuilder extends WasmCodeBuilder {
addArrayInstruction( ArrayOperator.GET, storeType, codePos, lineNumber ); addArrayInstruction( ArrayOperator.GET, storeType, codePos, lineNumber );
break; break;
case 51: // baload case 51: // baload
addArrayInstruction( ArrayOperator.GET, ValueType.i8, codePos, lineNumber ); addArrayInstruction( ArrayOperator.GET_S, ValueType.i8, codePos, lineNumber );
break; break;
case 52: // caload case 52: // caload
addArrayInstruction( ArrayOperator.GET, ValueType.i16, codePos, lineNumber ); addArrayInstruction( ArrayOperator.GET_U, ValueType.i16, codePos, lineNumber );
break; break;
case 53: // saload case 53: // saload
addArrayInstruction( ArrayOperator.GET, ValueType.i16, codePos, lineNumber ); addArrayInstruction( ArrayOperator.GET_S, ValueType.i16, codePos, lineNumber );
break; break;
case 54: // istore case 54: // istore
addLoadStoreInstruction( ValueType.i32, false, byteCode.readUnsignedIndex( wide ), codePos, lineNumber ); addLoadStoreInstruction( ValueType.i32, false, byteCode.readUnsignedIndex( wide ), codePos, lineNumber );

View File

@ -137,6 +137,8 @@ class WasmArrayInstruction extends WasmInstruction {
}, ValueType.i32, null, ValueType.externref ); }, ValueType.i32, null, ValueType.externref );
break; break;
case GET: case GET:
case GET_S:
case GET_U:
functionName = new JavaScriptSyntheticFunctionName( "NonGC", "array_get_" + validJsName( functionType ), () -> "(a,i)=>a[2][i]", ValueType.externref, ValueType.i32, null, functionType ); functionName = new JavaScriptSyntheticFunctionName( "NonGC", "array_get_" + validJsName( functionType ), () -> "(a,i)=>a[2][i]", ValueType.externref, ValueType.i32, null, functionType );
break; break;
case SET: case SET:
@ -194,6 +196,8 @@ class WasmArrayInstruction extends WasmInstruction {
case NEW_ARRAY_WITH_RTT: case NEW_ARRAY_WITH_RTT:
return arrayType; return arrayType;
case GET: case GET:
case GET_S:
case GET_U:
return type instanceof ValueType ? (ValueType)type : ValueType.externref; return type instanceof ValueType ? (ValueType)type : ValueType.externref;
case SET: case SET:
return null; return null;
@ -211,6 +215,8 @@ class WasmArrayInstruction extends WasmInstruction {
int getPopCount() { int getPopCount() {
switch( op ) { switch( op ) {
case GET: case GET:
case GET_S:
case GET_U:
case NEW_ARRAY_WITH_RTT: case NEW_ARRAY_WITH_RTT:
return 2; return 2;
case NEW: case NEW:

View File

@ -741,6 +741,8 @@ public abstract class WasmCodeBuilder {
int idx; int idx;
switch( op ) { switch( op ) {
case GET: case GET:
case GET_S:
case GET_U:
idx = StackInspector.findInstructionThatPushValue( instructions, 1, javaCodePos ).idx; idx = StackInspector.findInstructionThatPushValue( instructions, 1, javaCodePos ).idx;
break; break;
case SET: case SET:

View File

@ -838,6 +838,12 @@ public class TextModuleWriter extends ModuleWriter {
case GET: case GET:
operation = "get"; operation = "get";
break; break;
case GET_S:
operation = "get_s";
break;
case GET_U:
operation = "get_u";
break;
case SET: case SET:
operation = "set"; operation = "set";
break; break;

View File

@ -24,6 +24,8 @@ package de.inetsoftware.jwebassembly.wasm;
public enum ArrayOperator { public enum ArrayOperator {
NEW, NEW,
GET, GET,
GET_S,
GET_U,
SET, SET,
LEN, LEN,
NEW_ARRAY_WITH_RTT, NEW_ARRAY_WITH_RTT,