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:
opCode = ARRAY_GET;
break;
case GET_S:
opCode = ARRAY_GET_S;
break;
case GET_U:
opCode = ARRAY_GET_U;
break;
case SET:
opCode = ARRAY_SET;
break;

View File

@ -502,6 +502,10 @@ interface InstructionOpcodes {
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_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");
* 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 );
break;
case 51: // baload
addArrayInstruction( ArrayOperator.GET, ValueType.i8, codePos, lineNumber );
addArrayInstruction( ArrayOperator.GET_S, ValueType.i8, codePos, lineNumber );
break;
case 52: // caload
addArrayInstruction( ArrayOperator.GET, ValueType.i16, codePos, lineNumber );
addArrayInstruction( ArrayOperator.GET_U, ValueType.i16, codePos, lineNumber );
break;
case 53: // saload
addArrayInstruction( ArrayOperator.GET, ValueType.i16, codePos, lineNumber );
addArrayInstruction( ArrayOperator.GET_S, ValueType.i16, codePos, lineNumber );
break;
case 54: // istore
addLoadStoreInstruction( ValueType.i32, false, byteCode.readUnsignedIndex( wide ), codePos, lineNumber );

View File

@ -137,6 +137,8 @@ class WasmArrayInstruction extends WasmInstruction {
}, ValueType.i32, null, ValueType.externref );
break;
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 );
break;
case SET:
@ -194,6 +196,8 @@ class WasmArrayInstruction extends WasmInstruction {
case NEW_ARRAY_WITH_RTT:
return arrayType;
case GET:
case GET_S:
case GET_U:
return type instanceof ValueType ? (ValueType)type : ValueType.externref;
case SET:
return null;
@ -211,6 +215,8 @@ class WasmArrayInstruction extends WasmInstruction {
int getPopCount() {
switch( op ) {
case GET:
case GET_S:
case GET_U:
case NEW_ARRAY_WITH_RTT:
return 2;
case NEW:

View File

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

View File

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

View File

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