^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0-or-later */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Linux/PA-RISC Project (http://www.parisc-linux.org/)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Floating-point emulation code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright (C) 2001 Hewlett-Packard (Paul Bame) <bame@debian.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #ifdef __NO_PA_HDRS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) PA header file -- do not include this header file for non-PA builds.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * Some more constants
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #define SGL_FX_MAX_EXP 30
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #define DBL_FX_MAX_EXP 62
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #define QUAD_FX_MAX_EXP 126
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #define Dintp1(object) (object)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #define Dintp2(object) (object)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #define Duintp1(object) (object)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #define Duintp2(object) (object)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #define Qintp0(object) (object)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #define Qintp1(object) (object)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #define Qintp2(object) (object)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #define Qintp3(object) (object)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) * These macros will be used specifically by the convert instructions.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) * Single format macros
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #define Sgl_to_dbl_exponent(src_exponent,dest) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) Deposit_dexponent(dest,src_exponent+(DBL_BIAS-SGL_BIAS))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) #define Sgl_to_dbl_mantissa(src_mantissa,destA,destB) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) Deposit_dmantissap1(destA,src_mantissa>>3); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) Dmantissap2(destB) = src_mantissa << 29
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) #define Sgl_isinexact_to_fix(sgl_value,exponent) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) ((exponent < (SGL_P - 1)) ? \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) (Sall(sgl_value) << (SGL_EXP_LENGTH + 1 + exponent)) : FALSE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) #define Int_isinexact_to_sgl(int_value) ((int_value << 33 - SGL_EXP_LENGTH) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) #define Sgl_roundnearest_from_int(int_value,sgl_value) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) if (int_value & 1<<(SGL_EXP_LENGTH - 2)) /* round bit */ \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) if (((int_value << 34 - SGL_EXP_LENGTH) != 0) || Slow(sgl_value)) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) Sall(sgl_value)++
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) #define Dint_isinexact_to_sgl(dint_valueA,dint_valueB) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) (((Dintp1(dint_valueA) << 33 - SGL_EXP_LENGTH) != 0) || Dintp2(dint_valueB))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) #define Sgl_roundnearest_from_dint(dint_valueA,dint_valueB,sgl_value) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) if (Dintp1(dint_valueA) & 1<<(SGL_EXP_LENGTH - 2)) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) if (((Dintp1(dint_valueA) << 34 - SGL_EXP_LENGTH) != 0) || \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) Dintp2(dint_valueB) || Slow(sgl_value)) Sall(sgl_value)++
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) #define Dint_isinexact_to_dbl(dint_value) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) (Dintp2(dint_value) << 33 - DBL_EXP_LENGTH)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) #define Dbl_roundnearest_from_dint(dint_opndB,dbl_opndA,dbl_opndB) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) if (Dintp2(dint_opndB) & 1<<(DBL_EXP_LENGTH - 2)) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) if ((Dintp2(dint_opndB) << 34 - DBL_EXP_LENGTH) || Dlowp2(dbl_opndB)) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) if ((++Dallp2(dbl_opndB))==0) Dallp1(dbl_opndA)++
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) #define Sgl_isone_roundbit(sgl_value,exponent) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) ((Sall(sgl_value) << (SGL_EXP_LENGTH + 1 + exponent)) >> 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) #define Sgl_isone_stickybit(sgl_value,exponent) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) (exponent < (SGL_P - 2) ? \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) Sall(sgl_value) << (SGL_EXP_LENGTH + 2 + exponent) : FALSE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) * Double format macros
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) #define Dbl_to_sgl_exponent(src_exponent,dest) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) dest = src_exponent + (SGL_BIAS - DBL_BIAS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) #define Dbl_to_sgl_mantissa(srcA,srcB,dest,inexact,guard,sticky,odd) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) Shiftdouble(Dmantissap1(srcA),Dmantissap2(srcB),29,dest); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) guard = Dbit3p2(srcB); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) sticky = Dallp2(srcB)<<4; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) inexact = guard | sticky; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) odd = Dbit2p2(srcB)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) #define Dbl_to_sgl_denormalized(srcA,srcB,exp,dest,inexact,guard,sticky,odd,tiny) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) Deposit_dexponent(srcA,1); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) tiny = TRUE; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) if (exp >= -2) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) if (exp == 0) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) inexact = Dallp2(srcB) << 3; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) guard = inexact >> 31; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) sticky = inexact << 1; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) Shiftdouble(Dmantissap1(srcA),Dmantissap2(srcB),29,dest); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) odd = dest << 31; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) if (inexact) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) switch(Rounding_mode()) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) case ROUNDPLUS: \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) if (Dbl_iszero_sign(srcA)) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) dest++; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) if (Sgl_isone_hidden(dest)) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) tiny = FALSE; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) dest--; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) } \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) break; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) case ROUNDMINUS: \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) if (Dbl_isone_sign(srcA)) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) dest++; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) if (Sgl_isone_hidden(dest)) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) tiny = FALSE; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) dest--; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) } \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) break; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) case ROUNDNEAREST: \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) if (guard && (sticky || odd)) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) dest++; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) if (Sgl_isone_hidden(dest)) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) tiny = FALSE; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) dest--; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) } \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) break; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) } \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) } \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) /* shift right by one to get correct result */ \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) guard = odd; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) sticky = inexact; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) inexact |= guard; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) dest >>= 1; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) Deposit_dsign(srcA,0); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) Shiftdouble(Dallp1(srcA),Dallp2(srcB),30,dest); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) odd = dest << 31; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) } \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) else { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) inexact = Dallp2(srcB) << (2 + exp); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) guard = inexact >> 31; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) sticky = inexact << 1; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) Deposit_dsign(srcA,0); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) if (exp == -2) dest = Dallp1(srcA); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) else Variable_shift_double(Dallp1(srcA),Dallp2(srcB),30-exp,dest); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) odd = dest << 31; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) } \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) } \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) else { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) Deposit_dsign(srcA,0); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) if (exp > (1 - SGL_P)) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) dest = Dallp1(srcA) >> (- 2 - exp); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) inexact = Dallp1(srcA) << (34 + exp); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) guard = inexact >> 31; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) sticky = (inexact << 1) | Dallp2(srcB); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) inexact |= Dallp2(srcB); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) odd = dest << 31; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) } \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) else { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) dest = 0; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) inexact = Dallp1(srcA) | Dallp2(srcB); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) if (exp == (1 - SGL_P)) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) guard = Dhidden(srcA); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) sticky = Dmantissap1(srcA) | Dallp2(srcB); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) } \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) else { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) guard = 0; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) sticky = inexact; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) } \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) odd = 0; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) } \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) } \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) exp = 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) #define Dbl_isinexact_to_fix(dbl_valueA,dbl_valueB,exponent) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) (exponent < (DBL_P-33) ? \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) Dallp2(dbl_valueB) || Dallp1(dbl_valueA) << (DBL_EXP_LENGTH+1+exponent) : \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) (exponent < (DBL_P-1) ? Dallp2(dbl_valueB) << (exponent + (33-DBL_P)) : \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) FALSE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) #define Dbl_isoverflow_to_int(exponent,dbl_valueA,dbl_valueB) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) ((exponent > SGL_FX_MAX_EXP + 1) || Dsign(dbl_valueA)==0 || \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) Dmantissap1(dbl_valueA)!=0 || (Dallp2(dbl_valueB)>>21)!=0 )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) #define Dbl_isone_roundbit(dbl_valueA,dbl_valueB,exponent) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) ((exponent < (DBL_P - 33) ? \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) Dallp1(dbl_valueA) >> ((30 - DBL_EXP_LENGTH) - exponent) : \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) Dallp2(dbl_valueB) >> ((DBL_P - 2) - exponent)) & 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) #define Dbl_isone_stickybit(dbl_valueA,dbl_valueB,exponent) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) (exponent < (DBL_P-34) ? \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) (Dallp2(dbl_valueB) || Dallp1(dbl_valueA)<<(DBL_EXP_LENGTH+2+exponent)) : \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) (exponent<(DBL_P-2) ? (Dallp2(dbl_valueB) << (exponent + (34-DBL_P))) : \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) FALSE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) /* Int macros */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) #define Int_from_sgl_mantissa(sgl_value,exponent) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) Sall(sgl_value) = \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) (unsigned)(Sall(sgl_value) << SGL_EXP_LENGTH)>>(31 - exponent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) #define Int_from_dbl_mantissa(dbl_valueA,dbl_valueB,exponent) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) Shiftdouble(Dallp1(dbl_valueA),Dallp2(dbl_valueB),22,Dallp1(dbl_valueA)); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) if (exponent < 31) Dallp1(dbl_valueA) >>= 30 - exponent; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) else Dallp1(dbl_valueA) <<= 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) #define Int_negate(int_value) int_value = -int_value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) /* Dint macros */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) #define Dint_from_sgl_mantissa(sgl_value,exponent,dresultA,dresultB) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) {Sall(sgl_value) <<= SGL_EXP_LENGTH; /* left-justify */ \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) if (exponent <= 31) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) Dintp1(dresultA) = 0; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) Dintp2(dresultB) = (unsigned)Sall(sgl_value) >> (31 - exponent); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) } \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) else { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) Dintp1(dresultA) = Sall(sgl_value) >> (63 - exponent); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) Dintp2(dresultB) = Sall(sgl_value) << (exponent - 31); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) }}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) #define Dint_from_dbl_mantissa(dbl_valueA,dbl_valueB,exponent,destA,destB) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) {if (exponent < 32) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) Dintp1(destA) = 0; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) if (exponent <= 20) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) Dintp2(destB) = Dallp1(dbl_valueA) >> 20-exponent; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) else Variable_shift_double(Dallp1(dbl_valueA),Dallp2(dbl_valueB), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 52-exponent,Dintp2(destB)); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) } \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) else { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) if (exponent <= 52) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) Dintp1(destA) = Dallp1(dbl_valueA) >> 52-exponent; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) if (exponent == 52) Dintp2(destB) = Dallp2(dbl_valueB); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) else Variable_shift_double(Dallp1(dbl_valueA),Dallp2(dbl_valueB), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 52-exponent,Dintp2(destB)); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) } \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) else { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) Variable_shift_double(Dallp1(dbl_valueA),Dallp2(dbl_valueB), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 84-exponent,Dintp1(destA)); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) Dintp2(destB) = Dallp2(dbl_valueB) << exponent-52; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) } \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) }}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) #define Dint_setzero(dresultA,dresultB) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) Dintp1(dresultA) = 0; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) Dintp2(dresultB) = 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) #define Dint_setone_sign(dresultA,dresultB) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) Dintp1(dresultA) = ~Dintp1(dresultA); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) if ((Dintp2(dresultB) = -Dintp2(dresultB)) == 0) Dintp1(dresultA)++
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) #define Dint_set_minint(dresultA,dresultB) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) Dintp1(dresultA) = (unsigned int)1<<31; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) Dintp2(dresultB) = 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) #define Dint_isone_lowp2(dresultB) (Dintp2(dresultB) & 01)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) #define Dint_increment(dresultA,dresultB) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) if ((++Dintp2(dresultB))==0) Dintp1(dresultA)++
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) #define Dint_decrement(dresultA,dresultB) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) if ((Dintp2(dresultB)--)==0) Dintp1(dresultA)--
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) #define Dint_negate(dresultA,dresultB) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) Dintp1(dresultA) = ~Dintp1(dresultA); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) if ((Dintp2(dresultB) = -Dintp2(dresultB))==0) Dintp1(dresultA)++
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) #define Dint_copyfromptr(src,destA,destB) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) Dintp1(destA) = src->wd0; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) Dintp2(destB) = src->wd1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) #define Dint_copytoptr(srcA,srcB,dest) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) dest->wd0 = Dintp1(srcA); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) dest->wd1 = Dintp2(srcB)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) /* other macros */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) #define Find_ms_one_bit(value, position) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) int var; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) for (var=8; var >=1; var >>= 1) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) if (value >> 32 - position) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) position -= var; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) else position += var; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) } \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) if ((value >> 32 - position) == 0) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) position--; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) else position -= 2; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) * Unsigned int macros
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) #define Duint_copyfromptr(src,destA,destB) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) Dint_copyfromptr(src,destA,destB)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) #define Duint_copytoptr(srcA,srcB,dest) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) Dint_copytoptr(srcA,srcB,dest)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) #define Suint_isinexact_to_sgl(int_value) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) (int_value << 32 - SGL_EXP_LENGTH)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) #define Sgl_roundnearest_from_suint(suint_value,sgl_value) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) if (suint_value & 1<<(SGL_EXP_LENGTH - 1)) /* round bit */ \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) if ((suint_value << 33 - SGL_EXP_LENGTH) || Slow(sgl_value)) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) Sall(sgl_value)++
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) #define Duint_isinexact_to_sgl(duint_valueA,duint_valueB) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) ((Duintp1(duint_valueA) << 32 - SGL_EXP_LENGTH) || Duintp2(duint_valueB))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) #define Sgl_roundnearest_from_duint(duint_valueA,duint_valueB,sgl_value) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) if (Duintp1(duint_valueA) & 1<<(SGL_EXP_LENGTH - 1)) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) if ((Duintp1(duint_valueA) << 33 - SGL_EXP_LENGTH) || \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) Duintp2(duint_valueB) || Slow(sgl_value)) Sall(sgl_value)++
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) #define Duint_isinexact_to_dbl(duint_value) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) (Duintp2(duint_value) << 32 - DBL_EXP_LENGTH)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) #define Dbl_roundnearest_from_duint(duint_opndB,dbl_opndA,dbl_opndB) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) if (Duintp2(duint_opndB) & 1<<(DBL_EXP_LENGTH - 1)) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) if ((Duintp2(duint_opndB) << 33 - DBL_EXP_LENGTH) || Dlowp2(dbl_opndB)) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) if ((++Dallp2(dbl_opndB))==0) Dallp1(dbl_opndA)++
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) #define Suint_from_sgl_mantissa(src,exponent,result) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) Sall(result) = (unsigned)(Sall(src) << SGL_EXP_LENGTH)>>(31 - exponent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) #define Sgl_isinexact_to_unsigned(sgl_value,exponent) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) Sgl_isinexact_to_fix(sgl_value,exponent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) #define Duint_from_sgl_mantissa(sgl_value,exponent,dresultA,dresultB) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) {unsigned int val = Sall(sgl_value) << SGL_EXP_LENGTH; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) if (exponent <= 31) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) Dintp1(dresultA) = 0; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) Dintp2(dresultB) = val >> (31 - exponent); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) } \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) else { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) Dintp1(dresultA) = val >> (63 - exponent); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) Dintp2(dresultB) = exponent <= 62 ? val << (exponent - 31) : 0; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) } \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) #define Duint_setzero(dresultA,dresultB) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) Dint_setzero(dresultA,dresultB)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) #define Duint_increment(dresultA,dresultB) Dint_increment(dresultA,dresultB)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) #define Duint_isone_lowp2(dresultB) Dint_isone_lowp2(dresultB)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) #define Suint_from_dbl_mantissa(srcA,srcB,exponent,dest) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) Shiftdouble(Dallp1(srcA),Dallp2(srcB),21,dest); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) dest = (unsigned)dest >> 31 - exponent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) #define Dbl_isinexact_to_unsigned(dbl_valueA,dbl_valueB,exponent) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) Dbl_isinexact_to_fix(dbl_valueA,dbl_valueB,exponent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) #define Duint_from_dbl_mantissa(dbl_valueA,dbl_valueB,exponent,destA,destB) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) Dint_from_dbl_mantissa(dbl_valueA,dbl_valueB,exponent,destA,destB)