-
Notifications
You must be signed in to change notification settings - Fork 451
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50 from naturaltransformation/master
implementation and tests for clz, ctz, and popcnt
- Loading branch information
Showing
2 changed files
with
68 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
(; Int arith operations ;) | ||
|
||
(module | ||
(func $clz (param $x i32) (result i32) | ||
(i32.clz (get_local $x)) | ||
) | ||
|
||
(func $ctz (param $x i32) (result i32) | ||
(i32.ctz (get_local $x)) | ||
) | ||
|
||
(func $popcnt (param $x i32) (result i32) | ||
(i32.popcnt (get_local $x)) | ||
) | ||
|
||
(export "clz" $clz) | ||
(export "ctz" $ctz) | ||
(export "popcnt" $popcnt) | ||
) | ||
|
||
(assert_eq (invoke "clz" (i32.const -1)) (i32.const 0)) ;; 0xFFFFFFFF | ||
(assert_eq (invoke "clz" (i32.const 0)) (i32.const 32)) | ||
(assert_eq (invoke "clz" (i32.const 32768)) (i32.const 16)) ;; 0x00008000 | ||
(assert_eq (invoke "clz" (i32.const 255)) (i32.const 24)) ;; 0xFF | ||
(assert_eq (invoke "clz" (i32.const -2147483648)) (i32.const 0)) ;; 0x80000000 | ||
(assert_eq (invoke "clz" (i32.const 1)) (i32.const 31)) | ||
(assert_eq (invoke "clz" (i32.const 2)) (i32.const 30)) | ||
|
||
(assert_eq (invoke "ctz" (i32.const -1)) (i32.const 0)) | ||
(assert_eq (invoke "ctz" (i32.const 0)) (i32.const 32)) | ||
(assert_eq (invoke "ctz" (i32.const 32768)) (i32.const 15)) ;; 0x00008000 | ||
(assert_eq (invoke "ctz" (i32.const 65536)) (i32.const 16)) ;; 0x00010000 | ||
(assert_eq (invoke "ctz" (i32.const -2147483648)) (i32.const 31)) ;; 0x80000000 | ||
|
||
(assert_eq (invoke "popcnt" (i32.const -1)) (i32.const 32)) | ||
(assert_eq (invoke "popcnt" (i32.const 0)) (i32.const 0)) | ||
(assert_eq (invoke "popcnt" (i32.const 32768)) (i32.const 1)) ;; 0x00008000 |