implements "neg" instruction code

This commit is contained in:
Volker Berlin 2018-04-02 19:15:42 +02:00
parent d78e958342
commit 7ba809ac86
5 changed files with 32 additions and 3 deletions

View File

@ -15,8 +15,8 @@ Status of the project
* Public API of the Compiler * Public API of the Compiler
### Partially Finished ### Partially Finished
* Binary format file writer (130 of 201 byte code instructions) * Binary format file writer (134 of 201 byte code instructions)
* Text format file writer (130 of 201 byte code instructions) * Text format file writer (134 of 201 byte code instructions)
### Open Features ### Open Features
* Exception handling - required the next version of WebAssembly * Exception handling - required the next version of WebAssembly

View File

@ -336,6 +336,16 @@ public class BinaryModuleWriter extends ModuleWriter implements InstructionOpcod
break; break;
} }
break; break;
case neg:
switch( valueType ) {
case f32:
op = F32_NEG;
break;
case f64:
op = F64_NEG;
break;
}
break;
case mul: case mul:
switch( valueType ) { switch( valueType ) {
case i32: case i32:

View File

@ -548,6 +548,20 @@ public abstract class ModuleWriter implements Closeable {
case 115: // drem case 115: // drem
//TODO can be implemented with a helper function like: (a - (long)(a / b) * (double)b) //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, sourceFile, lineNumber ); throw new WasmException( "Modulo/Remainder for floating numbers is not supported in WASM. Use int or long data types." + op, sourceFile, lineNumber );
case 116: // ineg
writeConstInt( -1 );
writeNumericOperator( NumericOperator.mul, ValueType.i32 );
break;
case 117: // lneg
writeConstLong( -1 );
writeNumericOperator( NumericOperator.mul, ValueType.i64 );
break;
case 118: // fneg
writeNumericOperator( NumericOperator.neg, ValueType.f32 );
break;
case 119: // dneg
writeNumericOperator( NumericOperator.neg, ValueType.f64 );
break;
case 120: // ishl case 120: // ishl
writeNumericOperator( NumericOperator.shl, ValueType.i32 ); writeNumericOperator( NumericOperator.shl, ValueType.i32 );
break; break;

View File

@ -21,6 +21,7 @@ package de.inetsoftware.jwebassembly.module;
public enum NumericOperator { public enum NumericOperator {
add, add,
sub, sub,
neg,
mul, mul,
div, div,
rem, rem,

View File

@ -90,6 +90,7 @@ public class MathOperations extends AbstractBaseTest {
static int addInt( int a, int b ) { static int addInt( int a, int b ) {
int c = 1234567; int c = 1234567;
int e = -1; int e = -1;
e = -e;
double d = -1234567; double d = -1234567;
int i = 1; int i = 1;
long l = 2; long l = 2;
@ -101,7 +102,8 @@ public class MathOperations extends AbstractBaseTest {
@Export @Export
static int addLong() { static int addLong() {
long a = 1L; long a = 1L;
long b = 3L; long b = -3L;
b = -b;
return (int)(a + b); return (int)(a + b);
} }
@ -110,6 +112,7 @@ public class MathOperations extends AbstractBaseTest {
float c = -1; float c = -1;
float e = 1.25F; float e = 1.25F;
double d = 1234; double d = 1234;
e = -e;
int i = 1; int i = 1;
long l = 2; long l = 2;
float f = 3; float f = 3;
@ -121,6 +124,7 @@ public class MathOperations extends AbstractBaseTest {
double c = -1; double c = -1;
double d = 1234; double d = 1234;
double e = 1.25; double e = 1.25;
e = -e;
int i = 1; int i = 1;
long l = 2; long l = 2;
float f = 3; float f = 3;