From 43668f48268fcff07d9317f083e3955d4bdb2922 Mon Sep 17 00:00:00 2001 From: lkcl Date: Wed, 25 May 2022 11:48:15 +0100 Subject: [PATCH] --- openpower/sv/int_fp_mv.mdwn | 116 +++++++++++++++++------------------- 1 file changed, 56 insertions(+), 60 deletions(-) diff --git a/openpower/sv/int_fp_mv.mdwn b/openpower/sv/int_fp_mv.mdwn index 068f39742..a164c8b65 100644 --- a/openpower/sv/int_fp_mv.mdwn +++ b/openpower/sv/int_fp_mv.mdwn @@ -62,60 +62,6 @@ The assembly listings in the [[int_fp_mv/appendix]] show how costly some of these language-specific conversions are: Javascript is 32 scalar instructions, including seven branch instructions. -## FP -> Integer conversions - -Different programming languages turn out to have completely different -semantics for FP to Integer conversion. This section gives an overview -of the different variants, listing the languages and hardware that -implements each variant. - -### standard IEEE754 conversion - -This conversion is outlined in the IEEE754 specification. It is used -by nearly all programming languages and CPUs. In the case of OpenPOWER, -the rounding mode is read from FPSCR - -### standard OpenPower conversion - -This conversion, instead of exact IEEE754 Compliance, performs -"saturation with NaN converted to minimum valid integer". This -is also exactly the same as the x86 ISA conversion senantics. -OpenPOWER however has instructions for both: - -* rounding mode read from FPSCR -* rounding mode always set to truncate - -### Java conversion - -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): - -* 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 -* SPIR-V's OpenCL dialect's - [`OpConvertFToU`](https://www.khronos.org/registry/spir-v/specs/unified1/SPIRV.html#OpConvertFToU) and - [`OpConvertFToS`](https://www.khronos.org/registry/spir-v/specs/unified1/SPIRV.html#OpConvertFToS) - instructions when decorated with - [the `SaturatedConversion` decorator](https://www.khronos.org/registry/spir-v/specs/unified1/SPIRV.html#_a_id_decoration_a_decoration). - -### JavaScript conversion - -For the sake of simplicity, the FP -> Integer conversion semantics generalized from those used by JavaScripts's `ToInt32` abstract operation will be referred to as [JavaScript conversion semantics](#fp-to-int-javascript-conversion-semantics). - -This instruction is present in ARM assembler as FJCVTZS - - -### Other languages - -TODO: review and investigate other language semantics - # Proposed New Scalar Instructions All of the following instructions use the standard OpenPower conversion to/from 64-bit float format when reading/writing a 32-bit float from/to a FPR. All integers however are sourced/stored in the *GPR*. @@ -233,16 +179,64 @@ allowing clearing FPRs. fp32 = bf16 || [0]*16 FRT = Single_to_Double(fp32) -## FPR to GPR conversions +## FPR to GPR (Integer) conversions
-X-Form: +Different programming languages turn out to have completely different +semantics for FP to Integer conversion. Below is an overview +of the different variants, listing the languages and hardware that +implements each variant. + +**Standard IEEE754 conversion** + +This conversion is outlined in the IEEE754 specification. It is used +by nearly all programming languages and CPUs. In the case of OpenPOWER, +the rounding mode is read from FPSCR -| 0-5 | 6-10 | 11-15 | 16-25 | 26-30 | 31 | -|--------|------|--------|-------|-------|----| -| Major | RT | //Mode | FRA | XO | Rc | -| Major | FRT | //Mode | RA | XO | Rc | +**Standard OpenPower conversion** + +This conversion, instead of exact IEEE754 Compliance, performs +"saturation with NaN converted to minimum valid integer". This +is also exactly the same as the x86 ISA conversion senantics. +OpenPOWER however has instructions for both: + +* rounding mode read from FPSCR +* rounding mode always set to truncate + +**Java conversion** + +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): + +* 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 +* SPIR-V's OpenCL dialect's + [`OpConvertFToU`](https://www.khronos.org/registry/spir-v/specs/unified1/SPIRV.html#OpConvertFToU) and + [`OpConvertFToS`](https://www.khronos.org/registry/spir-v/specs/unified1/SPIRV.html#OpConvertFToS) + instructions when decorated with + [the `SaturatedConversion` decorator](https://www.khronos.org/registry/spir-v/specs/unified1/SPIRV.html#_a_id_decoration_a_decoration). + +**JavaScript conversion** + +For the sake of simplicity, the FP -> Integer conversion semantics generalized from those used by JavaScripts's `ToInt32` abstract operation will be referred to as [JavaScript conversion semantics](#fp-to-int-javascript-conversion-semantics). + +This instruction is present in ARM assembler as FJCVTZS + + +**Format** + +| 0-5 | 6-10 | 11-15 | 16-25 | 26-30 | 31 | Form | +|--------|------|--------|-------|-------|----|------| +| Major | RT | //Mode | FRA | XO | Rc |X-Form| +| Major | FRT | //Mode | RA | XO | Rc |X-Form| Mode values: @@ -260,6 +254,8 @@ Mode values: [Java semantics]: #fp-to-int-java-conversion-semantics [JavaScript semantics]: #fp-to-int-javascript-conversion-semantics +**Instructions** + * `fcvttgw RT, FRA, Mode` Convert from 64-bit float to 32-bit signed integer, writing the result to the GPR `RT`. Converts using [mode `Mode`] -- 2.30.2