From: Luke Kenneth Casson Leighton Date: Thu, 3 Jun 2021 22:18:08 +0000 (+0100) Subject: add c version of double-to-int32 X-Git-Tag: DRAFT_SVP64_0_1~824 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=acd452e32c5680b727b39ee9f469825ed210d1ed;p=libreriscv.git add c version of double-to-int32 --- diff --git a/openpower/sv/int_fp_mv/appendix.mdwn b/openpower/sv/int_fp_mv/appendix.mdwn index 1bcd34e68..2d4ca89c9 100644 --- a/openpower/sv/int_fp_mv/appendix.mdwn +++ b/openpower/sv/int_fp_mv/appendix.mdwn @@ -1,5 +1,29 @@ # Equivalent OpenPower ISA v3.0 Assembly Language for FP -> Integer Conversion Modes +## c (IEEE754 standard compliant) + +``` +int32_t toInt32(double number) +{ + uint32_t result = (int32_t)number; + return result; +} +``` + +### 64-bit float -> 32-bit signed integer + +``` +toInt32(double): + fctiwz 1,1 + addi 9,1,-16 + stfiwx 1,0,9 + lwz 3,-16(1) + extsw 3,3 + blr + .long 0 + .byte 0,9,0,0,0,0,0,0 +``` + ## Rust ```pub fn fcvttgd_rust(v: f64) -> i64 {