result.sign <- 0
return result
+ def si32_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
+ 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
+ si32max <- bfp_CONVERT_FROM_SI32(0b0 || [1] * 31)
+ si32min <- bfp_CONVERT_FROM_SI32(0b1 || [0] * 31)
+ if bfp_COMPARE_GT(rnd, si32max) then
+ vxcvi_flag <- 1
+ return 0x7FFF_FFFF
+ if bfp_COMPARE_LT(rnd, si32min) then
+ vxcvi_flag <- 1
+ return 0x8000_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:31] / pow(2, 31 - exponent)
+ if IsNeg(rnd) then significand <- -significand
+ return significand[0:31]
+
+ def si64_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
+ 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
+ si64max <- bfp_CONVERT_FROM_SI64(0b0 || [1] * 63)
+ si64min <- bfp_CONVERT_FROM_SI64(0b1 || [0] * 63)
+ if bfp_COMPARE_GT(rnd, si64max) then
+ vxcvi_flag <- 1
+ return 0x7FFF_FFFF_FFFF_FFFF
+ if bfp_COMPARE_LT(rnd, si64min) then
+ vxcvi_flag <- 1
+ return 0x8000_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:63] / pow(2, 63 - exponent)
+ if IsNeg(rnd) then significand <- -significand
+ return significand[0:63]
+
def si128_CONVERT_FROM_BFP(x):
# x is an integer value represented in the
# binary floating-point working format.
significand <- significand[0:127] / pow(2, 127 - exponent)
if IsNeg(rnd) then significand <- -significand
return significand[0:127]
+
+ def ui32_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 0x0000_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
+ ui32max <- bfp_CONVERT_FROM_UI32([1] * 32)
+ if bfp_COMPARE_GT(rnd, ui32max) then
+ vxcvi_flag <- 1
+ return 0xFFFF_FFFF
+ if IsNeg(rnd) then
+ vxcvi_flag <- 1
+ return 0x0000_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:31] / pow(2, 31 - exponent)
+ return significand[0:31]
+
+ def ui64_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 0x0000_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
+ ui64max <- bfp_CONVERT_FROM_UI64([1] * 64)
+ if bfp_COMPARE_GT(rnd, ui64max) then
+ vxcvi_flag <- 1
+ return 0xFFFF_FFFF_FFFF_FFFF
+ if IsNeg(rnd) then
+ vxcvi_flag <- 1
+ return 0x0000_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:63] / pow(2, 63 - exponent)
+ return significand[0:63]
+
+ def ui128_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 0x0000_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
+ ui128max <- bfp_CONVERT_FROM_UI128([1] * 128)
+ if bfp_COMPARE_GT(rnd, ui128max) then
+ vxcvi_flag <- 1
+ return 0xFFFF_FFFF_FFFF_FFFF_FFFF_FFFF_FFFF_FFFF
+ if IsNeg(rnd) then
+ vxcvi_flag <- 1
+ return 0x0000_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)
+ return significand[0:127]