implements abs instruction

This commit is contained in:
Volker Berlin 2019-07-17 18:45:36 +02:00
parent eed21966d4
commit 03ed725262
5 changed files with 45 additions and 0 deletions

View File

@ -973,6 +973,17 @@ public class BinaryModuleWriter extends ModuleWriter implements InstructionOpcod
default: default:
} }
break; break;
case abs:
switch( valueType ) {
case f32:
op = F32_ABS;
break;
case f64:
op = F64_ABS;
break;
default:
}
break;
case ceil: case ceil:
switch( valueType ) { switch( valueType ) {
case f32: case f32:

View File

@ -95,6 +95,7 @@ class WasmNumericInstruction extends WasmInstruction {
switch( numOp ) { switch( numOp ) {
case neg: case neg:
case sqrt: case sqrt:
case abs:
case ceil: case ceil:
case floor: case floor:
case trunc: case trunc:

View File

@ -44,6 +44,7 @@ public enum NumericOperator {
ref_eq, ref_eq,
ref_ne, ref_ne,
sqrt, sqrt,
abs,
ceil, ceil,
floor, floor,
trunc, trunc,

View File

@ -84,6 +84,9 @@ public class WatParser extends WasmCodeBuilder {
case "i64.trunc_sat_f64_s": case "i64.trunc_sat_f64_s":
addConvertInstruction( ValueTypeConvertion.d2l, javaCodePos, lineNumber ); addConvertInstruction( ValueTypeConvertion.d2l, javaCodePos, lineNumber );
break; break;
case "f32.abs":
addNumericInstruction( NumericOperator.abs, ValueType.f32, javaCodePos, lineNumber );
break;
case "f32.ceil": case "f32.ceil":
addNumericInstruction( NumericOperator.ceil, ValueType.f32, javaCodePos, lineNumber ); addNumericInstruction( NumericOperator.ceil, ValueType.f32, javaCodePos, lineNumber );
break; break;
@ -117,6 +120,9 @@ public class WatParser extends WasmCodeBuilder {
case "f32.trunc": case "f32.trunc":
addNumericInstruction( NumericOperator.trunc, ValueType.f32, javaCodePos, lineNumber ); addNumericInstruction( NumericOperator.trunc, ValueType.f32, javaCodePos, lineNumber );
break; break;
case "f64.abs":
addNumericInstruction( NumericOperator.abs, ValueType.f64, javaCodePos, lineNumber );
break;
case "f64.ceil": case "f64.ceil":
addNumericInstruction( NumericOperator.ceil, ValueType.f64, javaCodePos, lineNumber ); addNumericInstruction( NumericOperator.ceil, ValueType.f64, javaCodePos, lineNumber );
break; break;

View File

@ -69,6 +69,9 @@ public class MathAPI extends AbstractBaseTest {
addParam( list, script, "roundF_3_5" ); addParam( list, script, "roundF_3_5" );
addParam( list, script, "roundD3_8" ); addParam( list, script, "roundD3_8" );
addParam( list, script, "roundD_3_8" ); addParam( list, script, "roundD_3_8" );
addParam( list, script, "random" );
addParam( list, script, "absF" );
addParam( list, script, "absD" );
} }
rule.setTestParameters( list ); rule.setTestParameters( list );
return list; return list;
@ -217,5 +220,28 @@ public class MathAPI extends AbstractBaseTest {
// SpiderMonkey does not support BigInt currently // SpiderMonkey does not support BigInt currently
return (int)Math.round( -3.8 ); return (int)Math.round( -3.8 );
} }
@Export
static int random() {
if( Math.random() < 0 ) {
return 1;
} else if( Math.random() > 1 ) {
return 2;
} else if( Math.random() == Math.random() ) {
return 3;
} else {
return 4;
}
}
@Export
static float absF() {
return Math.abs( -3.8F );
}
@Export
static double absD() {
return Math.abs( -3.8 );
}
} }
} }