diff options
author | Alon Zakai <alonzakai@gmail.com> | 2015-10-31 22:02:45 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2015-10-31 22:02:45 -0700 |
commit | 70e280d07d9bdc54d299daf85dfcf0cefd614232 (patch) | |
tree | 734125010e4b536b56cb1b25b7b7fa6f2748450b | |
parent | 4536c4935aa936505c56d600c78e814a07393430 (diff) | |
download | binaryen-70e280d07d9bdc54d299daf85dfcf0cefd614232.tar.gz binaryen-70e280d07d9bdc54d299daf85dfcf0cefd614232.tar.bz2 binaryen-70e280d07d9bdc54d299daf85dfcf0cefd614232.zip |
int ops test
-rw-r--r-- | test/add.c | 6 | ||||
-rw-r--r-- | test/add.emcc | 1 | ||||
-rw-r--r-- | test/add.post.js | 6 | ||||
-rw-r--r-- | test/add.txt | 5 | ||||
-rw-r--r-- | test/int_ops.c | 32 | ||||
-rw-r--r-- | test/int_ops.post.js | 50 | ||||
-rw-r--r-- | test/int_ops.txt | 281 |
7 files changed, 363 insertions, 18 deletions
diff --git a/test/add.c b/test/add.c deleted file mode 100644 index a7d7e982f..000000000 --- a/test/add.c +++ /dev/null @@ -1,6 +0,0 @@ -#include <emscripten.h> - -int EMSCRIPTEN_KEEPALIVE add(int x, int y) { - return x + y; -} - diff --git a/test/add.emcc b/test/add.emcc deleted file mode 100644 index ff5a1f8b0..000000000 --- a/test/add.emcc +++ /dev/null @@ -1 +0,0 @@ -["-s", "EXPORTED_FUNCTIONS=[\"_add\"]"] diff --git a/test/add.post.js b/test/add.post.js deleted file mode 100644 index a5ceeda53..000000000 --- a/test/add.post.js +++ /dev/null @@ -1,6 +0,0 @@ - -Module.print(Module._add(1, 1)); -Module.print(Module._add(5, 6)); -Module.print(Module._add(6, 5)); -Module.print(Module._add(-12, 101)); - diff --git a/test/add.txt b/test/add.txt deleted file mode 100644 index f57c2a3b9..000000000 --- a/test/add.txt +++ /dev/null @@ -1,5 +0,0 @@ -2 -11 -11 -89 - diff --git a/test/int_ops.c b/test/int_ops.c new file mode 100644 index 000000000..2e4a9b17d --- /dev/null +++ b/test/int_ops.c @@ -0,0 +1,32 @@ +#include <emscripten.h> + +// unary +int EMSCRIPTEN_KEEPALIVE clz(int x) { return __builtin_clz(x); } + +// binary +int EMSCRIPTEN_KEEPALIVE add(int x, int y) { return x + y; } +int EMSCRIPTEN_KEEPALIVE sub(int x, int y) { return x - y; } +int EMSCRIPTEN_KEEPALIVE mul(int x, int y) { return x * y; } +int EMSCRIPTEN_KEEPALIVE sdiv(int x, int y) { return x / y; } +unsigned EMSCRIPTEN_KEEPALIVE udiv(unsigned x, unsigned y) { return x / y; } +int EMSCRIPTEN_KEEPALIVE srem(int x, int y) { return x % y; } +unsigned EMSCRIPTEN_KEEPALIVE urem(unsigned x, unsigned y) { return x % y; } +int EMSCRIPTEN_KEEPALIVE and(int x, int y) { return x & y; } +int EMSCRIPTEN_KEEPALIVE or(int x, int y) { return x | y; } +int EMSCRIPTEN_KEEPALIVE xor(int x, int y) { return x ^ y; } +int EMSCRIPTEN_KEEPALIVE shl(int x, int y) { return x << y; } +int EMSCRIPTEN_KEEPALIVE sshr(int x, int y) { return x >> y; } +unsigned EMSCRIPTEN_KEEPALIVE ushr(unsigned x, unsigned y) { return x >> y; } + +// comparisons +int EMSCRIPTEN_KEEPALIVE eq(int x, int y) { return x == y; } +int EMSCRIPTEN_KEEPALIVE ne(int x, int y) { return x != y; } +int EMSCRIPTEN_KEEPALIVE lts(int x, int y) { return x < y; } +int EMSCRIPTEN_KEEPALIVE ltu(unsigned x, unsigned y) { return x < y; } +int EMSCRIPTEN_KEEPALIVE les(int x, int y) { return x <= y; } +int EMSCRIPTEN_KEEPALIVE leu(unsigned x, unsigned y) { return x <= y; } +int EMSCRIPTEN_KEEPALIVE gts(int x, int y) { return x > y; } +int EMSCRIPTEN_KEEPALIVE gtu(unsigned x, unsigned y) { return x > y; } +int EMSCRIPTEN_KEEPALIVE ges(int x, int y) { return x >= y; } +int EMSCRIPTEN_KEEPALIVE geu(unsigned x, unsigned y) { return x >= y; } + diff --git a/test/int_ops.post.js b/test/int_ops.post.js new file mode 100644 index 000000000..4ac57fa39 --- /dev/null +++ b/test/int_ops.post.js @@ -0,0 +1,50 @@ + +// unary +Module.print('clz'); +Module.print(Module._clz(1)); +Module.print(Module._clz(-1)); +Module.print(Module._clz(8)); + +// binary +function testBinary(name) { + Module.print(name); + Module.print(Module['_' + name](0, 0)); + Module.print(Module['_' + name](0, 1)); + Module.print(Module['_' + name](1, 0)); + Module.print(Module['_' + name](1, 1)); + Module.print(Module['_' + name](5, 6)); + Module.print(Module['_' + name](6, 5)); + Module.print(Module['_' + name](101, -12)); + Module.print(Module['_' + name](-12, 101)); + Module.print(Module['_' + name](-1, 5)); + Module.print(Module['_' + name](5, -1)); + Module.print(Module['_' + name](-1, -1)); +} +testBinary('add'); +testBinary('sub'); +testBinary('mul'); +testBinary('sdiv'); +testBinary('udiv'); +testBinary('srem'); +testBinary('urem'); +testBinary('and'); +testBinary('or'); +testBinary('xor'); +testBinary('shl'); +testBinary('sshr'); +testBinary('ushr'); + +// comparisons +testBinary('eq'); +testBinary('ne'); +testBinary('lts'); +testBinary('ltu'); +testBinary('les'); +testBinary('leu'); +testBinary('gts'); +testBinary('gtu'); +testBinary('ges'); +testBinary('geu'); + +Module.print('done.'); + diff --git a/test/int_ops.txt b/test/int_ops.txt new file mode 100644 index 000000000..a2a344434 --- /dev/null +++ b/test/int_ops.txt @@ -0,0 +1,281 @@ +clz +31 +0 +28 +add +0 +1 +1 +2 +11 +11 +89 +89 +4 +4 +-2 +sub +0 +-1 +1 +0 +-1 +1 +113 +-113 +-6 +6 +0 +mul +0 +0 +0 +1 +30 +30 +-1212 +-1212 +-5 +-5 +1 +sdiv +0 +0 +0 +1 +0 +1 +-8 +0 +0 +-5 +1 +udiv +0 +0 +0 +1 +0 +1 +0 +42524428 +858993459 +0 +1 +srem +0 +0 +0 +0 +5 +1 +5 +-12 +-1 +0 +0 +urem +0 +0 +0 +0 +5 +1 +101 +56 +0 +5 +0 +and +0 +0 +0 +1 +4 +4 +100 +100 +5 +5 +-1 +or +0 +1 +1 +1 +7 +7 +-11 +-11 +-1 +-1 +-1 +xor +0 +1 +1 +0 +3 +3 +-111 +-111 +-6 +-6 +0 +shl +0 +0 +1 +2 +320 +192 +105906176 +-384 +-32 +-2147483648 +-2147483648 +sshr +0 +0 +1 +0 +0 +0 +0 +-1 +-1 +0 +-1 +ushr +0 +0 +1 +0 +0 +0 +0 +134217727 +134217727 +0 +1 +eq +1 +0 +0 +1 +0 +0 +0 +0 +0 +0 +1 +ne +0 +1 +1 +0 +1 +1 +1 +1 +1 +1 +0 +lts +0 +1 +0 +0 +1 +0 +0 +1 +1 +0 +0 +ltu +0 +1 +0 +0 +1 +0 +1 +0 +0 +1 +0 +les +1 +1 +0 +1 +1 +0 +0 +1 +1 +0 +1 +leu +1 +1 +0 +1 +1 +0 +1 +0 +0 +1 +1 +gts +0 +0 +1 +0 +0 +1 +1 +0 +0 +1 +0 +gtu +0 +0 +1 +0 +0 +1 +0 +1 +1 +0 +0 +ges +1 +0 +1 +1 +0 +1 +1 +0 +0 +1 +1 +geu +1 +0 +1 +1 +0 +1 +0 +1 +1 +0 +1 +done. |