mirror of
https://github.com/i-net-software/JWebAssembly.git
synced 2025-03-25 07:27:52 +01:00
implement reinterpret opcodes and use it in the WatParser.
This commit is contained in:
parent
ed0eb9e4b6
commit
588ac6db47
@ -1075,8 +1075,20 @@ public class BinaryModuleWriter extends ModuleWriter implements InstructionOpcod
|
|||||||
case i2s:
|
case i2s:
|
||||||
op = I32_EXTEND16_S;
|
op = I32_EXTEND16_S;
|
||||||
break;
|
break;
|
||||||
|
case f2i_re:
|
||||||
|
op = I32_REINTERPRET_F32;
|
||||||
|
break;
|
||||||
|
case i2f_re:
|
||||||
|
op = F32_REINTERPRET_I32;
|
||||||
|
break;
|
||||||
|
case d2l_re:
|
||||||
|
op = I64_REINTERPRET_F64;
|
||||||
|
break;
|
||||||
|
case l2d_re:
|
||||||
|
op = F64_REINTERPRET_I64;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
throw new Error( "Unknown cast: " + cast );
|
throw new Error( "Unknown cast/type conversion: " + cast );
|
||||||
}
|
}
|
||||||
codeStream.writeOpCode( op );
|
codeStream.writeOpCode( op );
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2017 - 2018 Volker Berlin (i-net software)
|
* Copyright 2017 - 2019 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.
|
||||||
@ -37,4 +37,8 @@ public enum ValueTypeConvertion {
|
|||||||
i2b,
|
i2b,
|
||||||
i2c,
|
i2c,
|
||||||
i2s,
|
i2s,
|
||||||
|
f2i_re,
|
||||||
|
i2f_re,
|
||||||
|
d2l_re,
|
||||||
|
l2d_re,
|
||||||
}
|
}
|
@ -566,8 +566,20 @@ public class TextModuleWriter extends ModuleWriter {
|
|||||||
case i2s:
|
case i2s:
|
||||||
op = "i32.extend16_s";
|
op = "i32.extend16_s";
|
||||||
break;
|
break;
|
||||||
|
case f2i_re:
|
||||||
|
op = "i32.reinterpret_f32";
|
||||||
|
break;
|
||||||
|
case i2f_re:
|
||||||
|
op = "f32.reinterpret_i32";
|
||||||
|
break;
|
||||||
|
case d2l_re:
|
||||||
|
op = "i64.reinterpret_f64";
|
||||||
|
break;
|
||||||
|
case l2d_re:
|
||||||
|
op = "f64.reinterpret_i64";
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
throw new Error( "Unknown cast: " + cast );
|
throw new Error( "Unknown cast/type conversion: " + cast );
|
||||||
}
|
}
|
||||||
newline( methodOutput );
|
newline( methodOutput );
|
||||||
methodOutput.append( op );
|
methodOutput.append( op );
|
||||||
|
@ -69,12 +69,18 @@ public class WatParser extends WasmCodeBuilder {
|
|||||||
case "i32.add":
|
case "i32.add":
|
||||||
addNumericInstruction( NumericOperator.add, ValueType.i32, javaCodePos, lineNumber );
|
addNumericInstruction( NumericOperator.add, ValueType.i32, javaCodePos, lineNumber );
|
||||||
break;
|
break;
|
||||||
|
case "i32.reinterpret_f32":
|
||||||
|
addConvertInstruction( ValueTypeConvertion.f2i_re, javaCodePos, lineNumber );
|
||||||
|
break;
|
||||||
case "i32.trunc_sat_f32_s":
|
case "i32.trunc_sat_f32_s":
|
||||||
addConvertInstruction( ValueTypeConvertion.f2i, javaCodePos, lineNumber );
|
addConvertInstruction( ValueTypeConvertion.f2i, javaCodePos, lineNumber );
|
||||||
break;
|
break;
|
||||||
case "i64.extend_i32_s":
|
case "i64.extend_i32_s":
|
||||||
addConvertInstruction( ValueTypeConvertion.i2l, javaCodePos, lineNumber );
|
addConvertInstruction( ValueTypeConvertion.i2l, javaCodePos, lineNumber );
|
||||||
break;
|
break;
|
||||||
|
case "i64.reinterpret_f64":
|
||||||
|
addConvertInstruction( ValueTypeConvertion.d2l_re, javaCodePos, lineNumber );
|
||||||
|
break;
|
||||||
case "i64.trunc_sat_f64_s":
|
case "i64.trunc_sat_f64_s":
|
||||||
addConvertInstruction( ValueTypeConvertion.d2l, javaCodePos, lineNumber );
|
addConvertInstruction( ValueTypeConvertion.d2l, javaCodePos, lineNumber );
|
||||||
break;
|
break;
|
||||||
@ -99,6 +105,9 @@ public class WatParser extends WasmCodeBuilder {
|
|||||||
case "f32.nearest":
|
case "f32.nearest":
|
||||||
addNumericInstruction( NumericOperator.nearest, ValueType.f32, javaCodePos, lineNumber );
|
addNumericInstruction( NumericOperator.nearest, ValueType.f32, javaCodePos, lineNumber );
|
||||||
break;
|
break;
|
||||||
|
case "f32.reinterpret_i32":
|
||||||
|
addConvertInstruction( ValueTypeConvertion.i2f_re, javaCodePos, lineNumber );
|
||||||
|
break;
|
||||||
case "f32.sqrt":
|
case "f32.sqrt":
|
||||||
addNumericInstruction( NumericOperator.sqrt, ValueType.f32, javaCodePos, lineNumber );
|
addNumericInstruction( NumericOperator.sqrt, ValueType.f32, javaCodePos, lineNumber );
|
||||||
break;
|
break;
|
||||||
@ -129,6 +138,9 @@ public class WatParser extends WasmCodeBuilder {
|
|||||||
case "f64.nearest":
|
case "f64.nearest":
|
||||||
addNumericInstruction( NumericOperator.nearest, ValueType.f64, javaCodePos, lineNumber );
|
addNumericInstruction( NumericOperator.nearest, ValueType.f64, javaCodePos, lineNumber );
|
||||||
break;
|
break;
|
||||||
|
case "f64.reinterpret_i64":
|
||||||
|
addConvertInstruction( ValueTypeConvertion.l2d_re, javaCodePos, lineNumber );
|
||||||
|
break;
|
||||||
case "f64.sqrt":
|
case "f64.sqrt":
|
||||||
addNumericInstruction( NumericOperator.sqrt, ValueType.f64, javaCodePos, lineNumber );
|
addNumericInstruction( NumericOperator.sqrt, ValueType.f64, javaCodePos, lineNumber );
|
||||||
break;
|
break;
|
||||||
|
@ -116,6 +116,11 @@ public class WatParserTest {
|
|||||||
test( " i32.const -7 " );
|
test( " i32.const -7 " );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void i32_reinterpret_f32() throws IOException {
|
||||||
|
test( "i32.reinterpret_f32" );
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void i32_trunc_sat_f32_s() throws IOException {
|
public void i32_trunc_sat_f32_s() throws IOException {
|
||||||
test( "i32.trunc_sat_f32_s" );
|
test( "i32.trunc_sat_f32_s" );
|
||||||
@ -126,6 +131,11 @@ public class WatParserTest {
|
|||||||
test( "i64.extend_i32_s" );
|
test( "i64.extend_i32_s" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void i64_reinterpret_f64() throws IOException {
|
||||||
|
test( "i64.reinterpret_f64" );
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void i64_trunc_sat_f64_s() throws IOException {
|
public void i64_trunc_sat_f64_s() throws IOException {
|
||||||
test( "i64.trunc_sat_f64_s" );
|
test( "i64.trunc_sat_f64_s" );
|
||||||
@ -166,6 +176,11 @@ public class WatParserTest {
|
|||||||
test( "f32.nearest" );
|
test( "f32.nearest" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void f32_reinterpret_i32() throws IOException {
|
||||||
|
test( "f32.reinterpret_i32" );
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void f32_sqrt() throws IOException {
|
public void f32_sqrt() throws IOException {
|
||||||
test( "f32.sqrt" );
|
test( "f32.sqrt" );
|
||||||
@ -216,6 +231,11 @@ public class WatParserTest {
|
|||||||
test( "f64.mul" );
|
test( "f64.mul" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void f64_reinterpret_i64() throws IOException {
|
||||||
|
test( "f64.reinterpret_i64" );
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void f64_sqrt() throws IOException {
|
public void f64_sqrt() throws IOException {
|
||||||
test( "f64.sqrt" );
|
test( "f64.sqrt" );
|
||||||
|
@ -42,6 +42,10 @@ public class MathAPI extends AbstractBaseTest {
|
|||||||
ArrayList<Object[]> list = new ArrayList<>();
|
ArrayList<Object[]> list = new ArrayList<>();
|
||||||
for( ScriptEngine[] val : ScriptEngine.testParams() ) {
|
for( ScriptEngine[] val : ScriptEngine.testParams() ) {
|
||||||
ScriptEngine script = val[0];
|
ScriptEngine script = val[0];
|
||||||
|
addParam( list, script, "floatToIntBits" );
|
||||||
|
addParam( list, script, "intBitsToFloat" );
|
||||||
|
addParam( list, script, "doubleToLongBits" );
|
||||||
|
addParam( list, script, "longBitsToDouble" );
|
||||||
addParam( list, script, "sin0" );
|
addParam( list, script, "sin0" );
|
||||||
addParam( list, script, "sinPI" );
|
addParam( list, script, "sinPI" );
|
||||||
addParam( list, script, "cos0" );
|
addParam( list, script, "cos0" );
|
||||||
@ -59,6 +63,10 @@ public class MathAPI extends AbstractBaseTest {
|
|||||||
addParam( list, script, "ceil8_5" );
|
addParam( list, script, "ceil8_5" );
|
||||||
addParam( list, script, "floor8_5" );
|
addParam( list, script, "floor8_5" );
|
||||||
addParam( list, script, "rint8_5" );
|
addParam( list, script, "rint8_5" );
|
||||||
|
addParam( list, script, "atan2_5_5" );
|
||||||
|
addParam( list, script, "pow3_4" );
|
||||||
|
addParam( list, script, "round3_5" );
|
||||||
|
addParam( list, script, "round_3_5" );
|
||||||
}
|
}
|
||||||
rule.setTestParameters( list );
|
rule.setTestParameters( list );
|
||||||
return list;
|
return list;
|
||||||
@ -66,6 +74,26 @@ public class MathAPI extends AbstractBaseTest {
|
|||||||
|
|
||||||
static class TestClass {
|
static class TestClass {
|
||||||
|
|
||||||
|
@Export
|
||||||
|
static int floatToIntBits() {
|
||||||
|
return Float.floatToIntBits( 7 );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Export
|
||||||
|
static float intBitsToFloat() {
|
||||||
|
return Float.intBitsToFloat( 0x41f8_0000 ); // 31.0
|
||||||
|
}
|
||||||
|
|
||||||
|
@Export
|
||||||
|
static int doubleToLongBits() {
|
||||||
|
return (int)Double.doubleToLongBits( 7 );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Export
|
||||||
|
static double longBitsToDouble() {
|
||||||
|
return Double.longBitsToDouble( 0x41f8_0000 ); // 31.0
|
||||||
|
}
|
||||||
|
|
||||||
@Export
|
@Export
|
||||||
static double sin0() {
|
static double sin0() {
|
||||||
return Math.sin( 0 );
|
return Math.sin( 0 );
|
||||||
@ -155,5 +183,25 @@ public class MathAPI extends AbstractBaseTest {
|
|||||||
static double rint8_5() {
|
static double rint8_5() {
|
||||||
return Math.rint( 8.5 );
|
return Math.rint( 8.5 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Export
|
||||||
|
static double atan2_5_5() {
|
||||||
|
return Math.atan2( 5, 5 );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Export
|
||||||
|
static double pow3_4() {
|
||||||
|
return Math.pow( 3, 4 );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Export
|
||||||
|
static int round3_5() {
|
||||||
|
return Math.round( 3.5F );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Export
|
||||||
|
static double round_3_5() {
|
||||||
|
return Math.round( -3.5F );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user