From: Jacob Lifshay Date: Sat, 13 May 2023 01:06:47 +0000 (-0700) Subject: add rest of bfp_* helpers needed to run fcvt js test X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=bc7235fd47993ae0b374bd0d296775c9c1c65f6e;p=openpower-isa.git add rest of bfp_* helpers needed to run fcvt js test --- diff --git a/openpower/isafunctions/bfp.mdwn b/openpower/isafunctions/bfp.mdwn index 4cf13db8..7ab2ab2b 100644 --- a/openpower/isafunctions/bfp.mdwn +++ b/openpower/isafunctions/bfp.mdwn @@ -132,6 +132,36 @@ section 7.6.2.2 result.exponent <- result.exponent - 1 return result + def bfp_CONVERT_FROM_SI128(x): + # x is a 128-bit signed integer value. + + result <- BFPState() + result.sign <- 0 + result.exponent <- 0 + result.significand <- 0 + result.class.SNaN <- 0 + result.class.QNaN <- 0 + result.class.Infinity <- 0 + result.class.Zero <- 0 + result.class.Denormal <- 0 + result.class.Normal <- 0 + + if x = 0x0000_0000_0000_0000_0000_0000_0000_0000 then + result.class.Zero <- 1 + else + result.class.Normal <- 1 + result.sign <- x[0] + result.exponent <- 128 + result.significand[0:128] <- EXTS(x) + + if result.significand[0] = 1 then + result.sign <- 1 + result.significand[0:128] <- -result.significand[0:128] + do while result.significand[0] = 0 + result.significand <- result.significand * 2 + result.exponent <- result.exponent - 1 + return result + def bfp_CONVERT_FROM_UI128(x): # x is a 128-bit unsigned integer value. @@ -311,4 +341,38 @@ section 7.6.2.2 # binary floating-point working format. result <- x result.sign <- 0 - return result \ No newline at end of file + return result + + def si128_CONVERT_FROM_BFP(x): + # x is an integer value represented in the + # binary floating-point working format. + + if IsNaN(x) then + vxcvi_flag <- 1 + if IsSNaN(x) then vxsnan_flag <- 1 + return 0x8000_0000_0000_0000_0000_0000_0000_0000 + else + temp_xx <- xx_flag + temp_inc <- inc_flag + rnd <- bfp_ROUND_TO_INTEGER_TRUNC(x) + # TODO: does the spec say these are preserved? + xx_flag <- temp_xx + inc_flag <- temp_inc + exponent <- rnd.exponent + significand <- rnd.significand + si128max <- bfp_CONVERT_FROM_SI128(0b0 || [1] * 127) + si128min <- bfp_CONVERT_FROM_SI128(0b1 || [0] * 127) + if bfp_COMPARE_GT(rnd, si128max) then + vxcvi_flag <- 1 + return 0x7FFF_FFFF_FFFF_FFFF_FFFF_FFFF_FFFF_FFFF + if bfp_COMPARE_LT(rnd, si128min) then + vxcvi_flag <- 1 + return 0x8000_0000_0000_0000_0000_0000_0000_0000 + else + if ¬bfp_COMPARE_EQ(rnd, x) then xx_flag <- 1 + else xx_flag <- 0 # TODO: does the spec specify this? + inc_flag <- 0 + # TODO: spec says this is logical shift right: + significand <- significand[0:127] / pow(2, 127 - exponent) + if IsNeg(rnd) then significand <- -significand + return significand[0:127] diff --git a/src/openpower/decoder/helpers.py b/src/openpower/decoder/helpers.py index 982f1396..2c937134 100644 --- a/src/openpower/decoder/helpers.py +++ b/src/openpower/decoder/helpers.py @@ -883,6 +883,13 @@ def IsZero(v): raise NotImplementedError("not yet implemented for non-BFPState values") +def SetFX(fpscr, field): + assert isinstance(fpscr, FPSCRState), "SetFX only works on FPSCR fields" + if eq(getattr(fpscr, field), SelectableInt(0, 1)): + setattr(fpscr, field, SelectableInt(1, 1)) + fpscr.FX = SelectableInt(1, 1) + + class ISACallerHelper: def __init__(self, XLEN, FPSCR): self.__XLEN = XLEN