[Libre-soc-bugs] [Bug 230] Video opcode development and discussion

bugzilla-daemon at libre-soc.org bugzilla-daemon at libre-soc.org
Wed Jun 2 19:35:42 BST 2021


https://bugs.libre-soc.org/show_bug.cgi?id=230

--- Comment #76 from Jacob Lifshay <programmerjake at gmail.com> ---
(In reply to Luke Kenneth Casson Leighton from comment #75)
> (In reply to Jacob Lifshay from comment #74)
> > fp -> int conversions should convert NaN to 0 and saturate for
> > +-infinity/too-big-to-fit values -- that's the behavior needed for Rust,
> > Java, LLVM's fptosi.sat/fptoui.sat intrinsics, and for OpenCL and Direct3D.
> > IDK if that matches the other OpenPower conversion instructions (it doesn't
> > match on x86, which makes conversions on x86 take more instructions in many
> > cases).
> 
> can you double-check? p159 section 4.6.7

yup, checked: fp -> uint conversions are ok, fp -> sint conversions are like
x86 conversions in that NaNs convert to -2^31 or -2^63.

the rounding modes supported for fp -> int conversions are either truncate, or
use rounding mode from FPSCR -- so that's good enough.

so, the new fp in FPR -> int in GPR instructions we're adding should probably
have a mode-select field:

000: fp -> int with rounding mode from FPSCR and OpenPower semantics
001: fp -> int with rounding mode set to truncate and OpenPower semantics
010: fp -> int with rounding mode from FPSCR and Rust semantics
011: fp -> int with rounding mode set to truncate and Rust semantics
100: fp -> int with rounding mode from FPSCR and JavaScript semantics
101: fp -> int with rounding mode set to truncate and JavaScript semantics
rest: illegal instruction trap for now

In the following pseudo-code, fp is f32 or f64 (or other types from SimpleV),
int is u32/u64/i32/i64 (or other types from SimpleV), uint is the unsigned
integer of the same bitwidth as int, int::BITS is the bitwidth of int,
int::MIN_VALUE is the minimum value `int` can store (0 if unsigned,
-2^(int::BITS-1) if signed), int::MAX_VALUE is the maximum value `int` can
store.

OpenPower conversion semantics (section A.2 page 999 (page 1023) of OpenPower
ISA v3.1):
fp -> int:
if fp is NaN:
    return int::MIN_VALUE
if fp >= int::MAX_VALUE:
    return int::MAX_VALUE
if fp <= int::MIN_VALUE:
    return int::MIN_VALUE
return (int)round(fp, rounding_mode)

Rust conversion semantics (with adjustment to add non-truncate rounding modes):
https://doc.rust-lang.org/reference/expressions/operator-expr.html#semantics
fp -> int:
if fp is NaN:
    return 0
if fp >= int::MAX_VALUE:
    return int::MAX_VALUE
if fp <= int::MIN_VALUE:
    return int::MIN_VALUE
return (int)round(fp, rounding_mode)

JavaScript conversion semantics (with adjustment to add non-truncate rounding
modes):
https://262.ecma-international.org/11.0/#sec-toint32
fp -> int:
if fp is NaN or infinite:
    return 0
fp = round(fp, rounding_mode)
fp = fp mod 2^int::BITS  # 2^32 for u32/i32, 2^64 for u64/i64, the result is
nonnegative
bits = (uint)fp
return (int)bits

-- 
You are receiving this mail because:
You are on the CC list for the bug.


More information about the libre-soc-bugs mailing list