From: Jacob Lifshay Date: Wed, 26 Apr 2023 01:44:18 +0000 (-0700) Subject: add fminmax pseudo-code X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=8967ddf3e3fbcc16b0dfe07dfd68453b2665e661;p=libreriscv.git add fminmax pseudo-code --- diff --git a/openpower/sv/rfc/ls013.mdwn b/openpower/sv/rfc/ls013.mdwn index 08e5817eb..118003485 100644 --- a/openpower/sv/rfc/ls013.mdwn +++ b/openpower/sv/rfc/ls013.mdwn @@ -156,6 +156,64 @@ Note (3): TODO: icr if IEEE 754-2008 has min/maxMagNum like IEEE 754-2019's | PO | FRT | FRA | FRB | FMM | XO | Rc | ``` +``` + result <- [0] * 64 + a <- (FRA) + b <- (FRB) + abs_a <- 0b0 || a[1:63] + abs_b <- 0b0 || b[1:63] + a_is_nan <- abs_a >u 0x7FF0_0000_0000_0000 + a_is_snan <- a_is_nan and a[12] = 0 + b_is_nan <- abs_b >u 0x7FF0_0000_0000_0000 + b_is_snan <- b_is_nan and b[12] = 0 + any_snan <- a_is_snan or b_is_snan + a_quieted <- a + a_quieted[12] = 1 + b_quieted <- b + b_quieted[12] = 1 + if a_is_nan or b_is_nan then + if FMM[2:3] = 0b00 then # min/maxnum08 + if a_is_snan then result <- a_quieted + else if b_is_snan then result <- b_quieted + else if a_is_nan and b_is_nan then result <- a_quieted + else if a_is_nan then result <- b + else result <- a + if FMM[2:3] = 0b01 then # min/max19 + if a_is_nan then result <- a_quieted + else result <- b_quieted + if FMM[2:3] = 0b10 then # min/maxnum19 + if a_is_nan and b_is_nan then result <- a_quieted + else if a_is_nan then result <- b + else result <- a + if FMM[2:3] = 0b11 then # min/maxc + result <- b + else + cmp_l <- a + cmp_r <- b + if FMM[1] then # min/maxmag + if abs_a != abs_b then + cmp_l <- abs_a + cmp_r <- abs_b + if FMM[2:3] = 0b11 then # min/maxc + if abs_a = 0 then cmp_l <- 0 + if abs_b = 0 then cmp_r <- 0 + if FMM[0] then # max + # swap cmp_* so comparison goes the other way + cmp_l, cmp_r <- cmp_r, cmp_l + if cmp_l[0] = 1 then + if cmp_r[0] = 0 then result <- a + else if cmp_l >u cmp_r then + # IEEE 754 is sign-magnitude, + # so bigger magnitude negative is smaller + result <- a + else result <- b + else if cmp_r[0] = 1 then result <- b + else if cmp_l