From 135acbe2f97c4b7e7f51a8ae02bd4dc16d5b1666 Mon Sep 17 00:00:00 2001 From: lkcl Date: Wed, 25 May 2022 10:42:03 +0100 Subject: [PATCH] --- openpower/sv/int_fp_mv.mdwn | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/openpower/sv/int_fp_mv.mdwn b/openpower/sv/int_fp_mv.mdwn index de0cc7157..517db3dee 100644 --- a/openpower/sv/int_fp_mv.mdwn +++ b/openpower/sv/int_fp_mv.mdwn @@ -54,7 +54,7 @@ well suited for common/important conversion sequences: * standard Integer -> FP IEEE754 conversion (used by most languages and CPUs) * standard OpenPower FP -> Integer conversion (saturation with NaN converted to minimum valid integer) -* Rust FP -> Integer conversion (saturation with NaN converted to 0) +* Java FP -> Integer conversion (saturation with NaN converted to 0) * JavaScript FP -> Integer conversion (modular with Inf/NaN converted to 0) The assembly listings in the [[int_fp_mv/appendix]] show how costly @@ -84,16 +84,17 @@ OpenPOWER however has instructions for both: * rounding mode read from FPSCR * rounding mode always set to truncate -### Rust FP -> Integer conversion +### Java FP -> Integer conversion -For the sake of simplicity, the FP -> Integer conversion semantics generalized from those used by Rust's `as` operator will be referred to as [Rust conversion semantics](#fp-to-int-rust-conversion-semantics). +For the sake of simplicity, the FP -> Integer conversion semantics generalized from those used by Java's semantics (and Rust's `as` operator) will be referred to as +[Java conversion semantics](#fp-to-int-java-conversion-semantics). Those same semantics are used in some way by all of the following languages (not necessarily for the default conversion method): -* Rust's FP -> Integer conversion using the - [`as` operator](https://doc.rust-lang.org/reference/expressions/operator-expr.html#semantics) * Java's [FP -> Integer conversion](https://docs.oracle.com/javase/specs/jls/se16/html/jls-5.html#jls-5.1.3) +* Rust's FP -> Integer conversion using the + [`as` operator](https://doc.rust-lang.org/reference/expressions/operator-expr.html#semantics) * LLVM's [`llvm.fptosi.sat`](https://llvm.org/docs/LangRef.html#llvm-fptosi-sat-intrinsic) and [`llvm.fptoui.sat`](https://llvm.org/docs/LangRef.html#llvm-fptoui-sat-intrinsic) intrinsics @@ -248,14 +249,14 @@ Mode values: |------|-----------------|----------------------------------| | 000 | from `FPSCR` | [OpenPower semantics] | | 001 | Truncate | [OpenPower semantics] | -| 010 | from `FPSCR` | [Rust semantics] | -| 011 | Truncate | [Rust semantics] | +| 010 | from `FPSCR` | [Java semantics] | +| 011 | Truncate | [Java semantics] | | 100 | from `FPSCR` | [JavaScript semantics] | | 101 | Truncate | [JavaScript semantics] | | rest | -- | illegal instruction trap for now | [OpenPower semantics]: #fp-to-int-openpower-conversion-semantics -[Rust semantics]: #fp-to-int-rust-conversion-semantics +[Java semantics]: #fp-to-int-java-conversion-semantics [JavaScript semantics]: #fp-to-int-javascript-conversion-semantics * `fcvttgw RT, FRA, Mode` @@ -343,11 +344,14 @@ def fp_to_int_open_power(v: fp) -> int: return (int)rint(v, rounding_mode) ``` -
-Rust [conversion semantics](https://doc.rust-lang.org/reference/expressions/operator-expr.html#semantics) (with adjustment to add non-truncate rounding modes): +
+[Java conversion semantics]((https://docs.oracle.com/javase/specs/jls/se16/html/jls-5.html#jls-5.1.3)) +/ +[Rust semantics](https://doc.rust-lang.org/reference/expressions/operator-expr.html#semantics) +(with adjustment to add non-truncate rounding modes): ``` -def fp_to_int_rust(v: fp) -> int: +def fp_to_int_java(v: fp) -> int: if v is NaN: return 0 if v >= int::MAX_VALUE: -- 2.30.2