Merge pull request #384 from LouisRiverstone/shader-cvt16-saturate
Shaders: v_cvt_u16_f16 and v_cvt_i16_f16 saturate at 16 bits
This commit is contained in:
commit
2c96e0e304
2 files changed
+53
-6
No files matched your search
@@ -4408,15 +4408,22 @@ impl<'a> Lower<'a> {
|
||||
}
|
||||
let r = match name {
|
||||
"v_cvt_u16_f16" | "v_cvt_i16_f16" => {
|
||||
// shortcut: converted through 32 bits, so out-of-range values
|
||||
// wrap instead of saturating at 16 bits.
|
||||
// Toward zero, saturating at the 16-bit range (infinities
|
||||
// included); NaN gives 0. Clamped in f32 first, where every
|
||||
// f16 is exact, so the conversion never leaves i32's range.
|
||||
let a = self.half_fsrc(inst, 0)?;
|
||||
let op = if name == "v_cvt_u16_f16" {
|
||||
Cast::FpToUi
|
||||
let (lo, hi) = if name == "v_cvt_u16_f16" {
|
||||
(0.0f32, 65535.0f32)
|
||||
} else {
|
||||
Cast::FpToSi
|
||||
(-32768.0, 32767.0)
|
||||
};
|
||||
self.s.m.cast(c, op, a, i32t)
|
||||
let (lo, hi) = (self.s.m.f32(lo.to_bits()), self.s.m.f32(hi.to_bits()));
|
||||
let t = self.binary(35, a, lo);
|
||||
let t = self.binary(36, t, hi);
|
||||
let r = self.s.m.cast(c, Cast::FpToSi, t, i32t);
|
||||
let nan = self.s.m.cmp(c, pred::UNO, a, a);
|
||||
let z = self.s.m.i32(0);
|
||||
self.s.m.select(c, nan, z, r)
|
||||
}
|
||||
_ => {
|
||||
let (mut a, mut b) = (self.half_src(inst, 0)?, self.half_src(inst, 1)?);
|
||||
|
||||
Reference in new issue
Block a user