[FP16] Implement unary operations.#6867
Conversation
| ;; 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.
Some of these tests result in -nan. Should I be avoiding those since they're non-deterministic?
There was a problem hiding this comment.
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.
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.
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.
According to my quick test using soft float, the results appear the same for sqrt:
https://gist.github.com/brendandahl/10b3ab8d4ac8abc7212e862833322c26
| ;; 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.
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.
Specified at https://github.com/WebAssembly/half-precision/blob/main/proposals/half-precision/Overview.md