diff options
author | Alon Zakai <alonzakai@gmail.com> | 2013-03-07 18:16:04 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2013-03-07 18:16:04 -0800 |
commit | f7e59e31bf9652293c9c96e90866e73236a2ae51 (patch) | |
tree | 42f9fd9fc652a6221feb523f008a7b584b0ebef1 | |
parent | 97ffe5025c4cebcfcf84795635d466fd748236be (diff) |
support llvm_ctpop_*; fixes #918
-rw-r--r-- | src/library.js | 14 | ||||
-rwxr-xr-x | tests/runner.py | 4 |
2 files changed, 18 insertions, 0 deletions
diff --git a/src/library.js b/src/library.js index 6ba6dab3..d787e30c 100644 --- a/src/library.js +++ b/src/library.js @@ -4896,6 +4896,20 @@ LibraryManager.library = { #endif }, + llvm_ctpop_i32: function(x) { + var ret = 0; + while (x) { + if (x&1) ret++; + x >>= 1; + } + return ret; + }, + + llvm_ctpop_i64__deps: ['llvm_ctpop_i32'], + llvm_ctpop_i64: function(l, h) { + return _llvm_ctpop_i32(l) + _llvm_ctpop_i32(h); + }, + llvm_trap: function() { throw 'trap! ' + new Error().stack; }, diff --git a/tests/runner.py b/tests/runner.py index b631dfc2..1f40d69c 100755 --- a/tests/runner.py +++ b/tests/runner.py @@ -1253,6 +1253,8 @@ m_divisor is 1091269979 extern int64_t llvm_ctlz_i64(int64_t x); extern int32_t llvm_cttz_i32(int32_t x); extern int64_t llvm_cttz_i64(int64_t x); + extern int32_t llvm_ctpop_i32(int32_t x); + extern int64_t llvm_ctpop_i64(int64_t x); extern int llvm_expect_i32(int x, int y); } @@ -1269,6 +1271,7 @@ m_divisor is 1091269979 printf("%d,%d\n", (int)llvm_ctlz_i64(((int64_t)1) << 40), llvm_ctlz_i32(1<<10)); printf("%d,%d\n", (int)llvm_cttz_i64(((int64_t)1) << 40), llvm_cttz_i32(1<<10)); + printf("%d,%d\n", (int)llvm_ctpop_i64((0x3101ULL << 32) | 1), llvm_ctpop_i32(0x3101)); printf("%d\n", llvm_expect_i32(x % 27, 3)); @@ -1285,6 +1288,7 @@ c8,ef c5,de,15,8a 23,21 40,10 +5,4 13 72057594037927936 ''') |