implements java bytecode frem and drem

This commit is contained in:
Volker Berlin 2019-03-12 21:27:23 +01:00
parent 3d5a98627f
commit c2be64a525
4 changed files with 9 additions and 15 deletions

View File

@ -342,9 +342,13 @@ class JavaMethodWasmCodeBuilder extends WasmCodeBuilder {
addNumericInstruction( NumericOperator.rem, ValueType.i64, codePos );
break;
case 114: // frem
//helper function like: (a - (int)(a / b) * (float)b)
addCallInstruction( new SyntheticFunctionName( "frem", "local.get 0 local.get 0 local.get 1 f32.div i32.trunc_sat_f32_s f32.convert_i32_s local.get 1 f32.mul f32.sub return", ValueType.f32, ValueType.f32, null, ValueType.f32 ), codePos );
break;
case 115: // drem
//TODO can be implemented with a helper function like: (a - (long)(a / b) * (double)b)
throw new WasmException( "Modulo/Remainder for floating numbers is not supported in WASM. Use int or long data types." + op, byteCode.getLineNumber() );
//helper function like: (a - (long)(a / b) * (double)b)
addCallInstruction( new SyntheticFunctionName( "drem", "local.get 0 local.get 0 local.get 1 f64.div i64.trunc_sat_f64_s f64.convert_i64_s local.get 1 f64.mul f64.sub return", ValueType.f64, ValueType.f64, null, ValueType.f64 ), codePos );
break;
case 116: // ineg
addConstInstruction( -1, ValueType.i32, codePos );
addNumericInstruction( NumericOperator.mul, ValueType.i32, codePos );

View File

@ -40,7 +40,7 @@ public class SyntheticFunctionName extends FunctionName {
* @param code
* the WAT code (WASM in text form)
* @param signature
* the method signature
* the method signature, first the parameters, then null and the the return types
*/
public SyntheticFunctionName( String name, String code, AnyType... signature ) {
super( "", name, "()V" ); //TODO better signature name

View File

@ -181,6 +181,7 @@ public class MathOperations extends AbstractBaseTest {
float a = -54321F;
a *= 3F;
a /= -8F;
a %= 37.5F;
return a;
}
@ -189,6 +190,7 @@ public class MathOperations extends AbstractBaseTest {
double a = -54321.0;
a *= 3F;
a /= -5F;
a %= 37.5;
return a;
}

View File

@ -85,18 +85,6 @@ public class RuntimeErrors {
}
}
@Test
public void floatRem() throws IOException {
compileErrorTest( "Modulo/Remainder", TestModulo.class );
}
static class TestModulo {
@Export
static float longReturn() {
float a = 3.4F;
return a % 2F;
}
}
@Test
public void nonStaticExport() throws IOException {