-
Notifications
You must be signed in to change notification settings - Fork 479
implementation and tests for clz, ctz, and popcnt #50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It'd be nice to keep the function name identical to the opcode name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On 16 September 2015 at 01:36, Dan Gohman [email protected] wrote:
Btw, despite it being what Intel picked on a bad day,
popcnt
really is anodd name out. It is both inconsistent with the other count operators, and
it sounds like some kind of stack operator.
Would anybody mind if we changed it? For example, how about
cnz
(countnon-zeros), which would be in line with the other count operators. (If you
say it's a worthwhile idea I can create an issue or PR.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I may be wrong, but IIRC, the “population count” terminology long precedes Intel. It is used in GHC base package, GCC, Sparc, Cray, and CDC (the latter ones long before Intel). Even the Mark I had it but called it Sideways Add.
From: rossberg-chromium [mailto:[email protected]]
Sent: Wednesday, September 16, 2015 12:33 AM
To: WebAssembly/spec
Cc: Kuan, George
Subject: Re: [spec] implementation and tests for clz, ctz, and popcnt (#50)
In ml-proto/test/int32.wasmhttps://github.com//pull/50#discussion_r39600610:
—
Reply to this email directly or view it on GitHubhttps://github.com//pull/50/files#r39600610.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On UltraSparc, it is known as POPC if that is any better.
From: rossberg-chromium [mailto:[email protected]]
Sent: Wednesday, September 16, 2015 12:33 AM
To: WebAssembly/spec
Cc: Kuan, George
Subject: Re: [spec] implementation and tests for clz, ctz, and popcnt (#50)
In ml-proto/test/int32.wasmhttps://github.com//pull/50#discussion_r39600610:
—
Reply to this email directly or view it on GitHubhttps://github.com//pull/50/files#r39600610.