-
Notifications
You must be signed in to change notification settings - Fork 745
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
[FP16] Implement unary operations. #6867
Conversation
@@ -147,3 +154,36 @@ | |||
(v128.const i16x8 0x5140 0xfe00 0x7c00 0x3e00 0 0x3c00 0 0x3c00)) | |||
;; nan -nan inf 1.5 0 1 1 1 | |||
(v128.const i16x8 0x7e00 0xfe00 0x7c00 0x3e00 0 0x3c00 0x3c00 0x3c00)) | |||
|
|||
;; unary arithmetic |
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.
Some of these tests result in -nan
. Should I be avoiding those since they're non-deterministic?
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.
We support using nan:canonical
and nan:arithmetic
and nan:<payload>
constants in spec tests, so perhaps that is an option as well. Although that might not support f16 constants out of the box, and either the interpreter or the wast runner seems to have some bugs in this area, so that may also be a problem.
If it's a pain, I'd say don't worry about changing it for now.
Literal Literal::sqrtF16x8() const { | ||
return unary<8, &Literal::getLanesF16x8, &Literal::sqrt, &toFP16>(*this); | ||
} |
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.
Does this convert the f16s to f32s and then do the sqrt? IIUC, that would round incorrectly in some cases.
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.
IIUC the paper in this area did prove that f32 sqrt can be done in f64 safely, and I'd guess the same should be true of f16 to f32.
But in this case there are only 2^16
f16 values, so we can just check them all 😎
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.
According to my quick test using soft float, the results appear the same for sqrt:
https://gist.github.com/brendandahl/10b3ab8d4ac8abc7212e862833322c26
@@ -147,3 +154,36 @@ | |||
(v128.const i16x8 0x5140 0xfe00 0x7c00 0x3e00 0 0x3c00 0 0x3c00)) | |||
;; nan -nan inf 1.5 0 1 1 1 | |||
(v128.const i16x8 0x7e00 0xfe00 0x7c00 0x3e00 0 0x3c00 0x3c00 0x3c00)) | |||
|
|||
;; unary arithmetic |
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.
We support using nan:canonical
and nan:arithmetic
and nan:<payload>
constants in spec tests, so perhaps that is an option as well. Although that might not support f16 constants out of the box, and either the interpreter or the wast runner seems to have some bugs in this area, so that may also be a problem.
If it's a pain, I'd say don't worry about changing it for now.
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.
lgtm % open discussions
Specified at https://github.com/WebAssembly/half-precision/blob/main/proposals/half-precision/Overview.md