1 /* SPDX-License-Identifier: GPL-2.0-or-later * 1 2 /* 3 * Linux/PA-RISC Project (http://www.parisc-li 4 * 5 * Floating-point emulation code 6 * Copyright (C) 2001 Hewlett-Packard (Paul B 7 */ 8 9 #ifdef __NO_PA_HDRS 10 PA header file -- do not include this head 11 #endif 12 13 /* 32-bit word grabbing functions */ 14 #define Sgl_firstword(value) Sall(value) 15 #define Sgl_secondword(value) dummy_location 16 #define Sgl_thirdword(value) dummy_location 17 #define Sgl_fourthword(value) dummy_location 18 19 #define Sgl_sign(object) Ssign(object) 20 #define Sgl_exponent(object) Sexponent(object) 21 #define Sgl_signexponent(object) Ssignexponent 22 #define Sgl_mantissa(object) Smantissa(object) 23 #define Sgl_exponentmantissa(object) Sexponent 24 #define Sgl_all(object) Sall(object) 25 26 /* sgl_and_signs ANDs the sign bits of each ar 27 * into the first argument. sgl_or_signs ors t 28 #define Sgl_and_signs( src1dst, src2) 29 Sall(src1dst) = (Sall(src2)|~((unsigned in 30 #define Sgl_or_signs( src1dst, src2) 31 Sall(src1dst) = (Sall(src2)&((unsigned int 32 33 /* The hidden bit is always the low bit of the 34 #define Sgl_clear_exponent_set_hidden(srcdst) 35 #define Sgl_clear_signexponent_set_hidden(srcd 36 Deposit_ssignexponent(srcdst,1) 37 #define Sgl_clear_sign(srcdst) Sall(srcdst) &= 38 #define Sgl_clear_signexponent(srcdst) Sall(sr 39 40 /* varamount must be less than 32 for the next 41 #define Sgl_rightshift(srcdst, varamount) 42 Sall(srcdst) >>= varamount 43 #define Sgl_leftshift(srcdst, varamount) 44 Sall(srcdst) <<= varamount 45 #define Sgl_rightshift_exponentmantissa(srcdst 46 Sall(srcdst) = \ 47 (Sexponentmantissa(srcdst) >> varamoun 48 (Sall(srcdst) & ((unsigned int)1<<31)) 49 50 #define Sgl_leftshiftby1_withextent(left,right 51 Shiftdouble(Sall(left),Extall(right),31,Sa 52 53 #define Sgl_rightshiftby1_withextent(left,righ 54 Shiftdouble(Sall(left),Extall(right),1,Ext 55 #define Sgl_arithrightshiftby1(srcdst) \ 56 Sall(srcdst) = (int)Sall(srcdst) >> 1 57 58 /* Sign extend the sign bit with an integer de 59 #define Sgl_signextendedsign(value) Ssignedsig 60 61 #define Sgl_isone_hidden(sgl_value) (Shidden(s 62 #define Sgl_increment(sgl_value) Sall(sgl_valu 63 #define Sgl_increment_mantissa(sgl_value) \ 64 Deposit_smantissa(sgl_value,sgl_value+1) 65 #define Sgl_decrement(sgl_value) Sall(sgl_valu 66 67 #define Sgl_isone_sign(sgl_value) (Is_ssign(sg 68 #define Sgl_isone_hiddenoverflow(sgl_value) \ 69 (Is_shiddenoverflow(sgl_value)!=0) 70 #define Sgl_isone_lowmantissa(sgl_value) (Is_s 71 #define Sgl_isone_signaling(sgl_value) (Is_ssi 72 #define Sgl_is_signalingnan(sgl_value) (Ssigna 73 #define Sgl_isnotzero(sgl_value) (Sall(sgl_val 74 #define Sgl_isnotzero_hiddenhigh7mantissa(sgl_ 75 (Shiddenhigh7mantissa(sgl_value)!=0) 76 #define Sgl_isnotzero_low4(sgl_value) (Slow4(s 77 #define Sgl_isnotzero_exponent(sgl_value) (Sex 78 #define Sgl_isnotzero_mantissa(sgl_value) (Sma 79 #define Sgl_isnotzero_exponentmantissa(sgl_val 80 (Sexponentmantissa(sgl_value)!=0) 81 #define Sgl_iszero(sgl_value) (Sall(sgl_value) 82 #define Sgl_iszero_signaling(sgl_value) (Is_ss 83 #define Sgl_iszero_hidden(sgl_value) (Is_shidd 84 #define Sgl_iszero_hiddenoverflow(sgl_value) \ 85 (Is_shiddenoverflow(sgl_value)==0) 86 #define Sgl_iszero_hiddenhigh3mantissa(sgl_val 87 (Shiddenhigh3mantissa(sgl_value)==0) 88 #define Sgl_iszero_hiddenhigh7mantissa(sgl_val 89 (Shiddenhigh7mantissa(sgl_value)==0) 90 #define Sgl_iszero_sign(sgl_value) (Is_ssign(s 91 #define Sgl_iszero_exponent(sgl_value) (Sexpon 92 #define Sgl_iszero_mantissa(sgl_value) (Smanti 93 #define Sgl_iszero_exponentmantissa(sgl_value) 94 (Sexponentmantissa(sgl_value)==0) 95 #define Sgl_isinfinity_exponent(sgl_value) 96 (Sgl_exponent(sgl_value)==SGL_INFINITY_EXP 97 #define Sgl_isnotinfinity_exponent(sgl_value) 98 (Sgl_exponent(sgl_value)!=SGL_INFINITY_EXP 99 #define Sgl_isinfinity(sgl_value) 100 (Sgl_exponent(sgl_value)==SGL_INFINITY_EXP 101 Sgl_mantissa(sgl_value)==0) 102 #define Sgl_isnan(sgl_value) 103 (Sgl_exponent(sgl_value)==SGL_INFINITY_EXP 104 Sgl_mantissa(sgl_value)!=0) 105 #define Sgl_isnotnan(sgl_value) 106 (Sgl_exponent(sgl_value)!=SGL_INFINITY_EXP 107 Sgl_mantissa(sgl_value)==0) 108 #define Sgl_islessthan(sgl_op1,sgl_op2) 109 (Sall(sgl_op1) < Sall(sgl_op2)) 110 #define Sgl_isgreaterthan(sgl_op1,sgl_op2) 111 (Sall(sgl_op1) > Sall(sgl_op2)) 112 #define Sgl_isnotlessthan(sgl_op1,sgl_op2) 113 (Sall(sgl_op1) >= Sall(sgl_op2)) 114 #define Sgl_isequal(sgl_op1,sgl_op2) 115 (Sall(sgl_op1) == Sall(sgl_op2)) 116 117 #define Sgl_leftshiftby8(sgl_value) \ 118 Sall(sgl_value) <<= 8 119 #define Sgl_leftshiftby4(sgl_value) \ 120 Sall(sgl_value) <<= 4 121 #define Sgl_leftshiftby3(sgl_value) \ 122 Sall(sgl_value) <<= 3 123 #define Sgl_leftshiftby2(sgl_value) \ 124 Sall(sgl_value) <<= 2 125 #define Sgl_leftshiftby1(sgl_value) \ 126 Sall(sgl_value) <<= 1 127 #define Sgl_rightshiftby1(sgl_value) \ 128 Sall(sgl_value) >>= 1 129 #define Sgl_rightshiftby4(sgl_value) \ 130 Sall(sgl_value) >>= 4 131 #define Sgl_rightshiftby8(sgl_value) \ 132 Sall(sgl_value) >>= 8 133 134 #define Sgl_ismagnitudeless(signlessleft,signl 135 /* unsigned int signlessleft, signlessright; 136 (signlessleft < signlessright) 137 138 139 #define Sgl_copytoint_exponentmantissa(source, 140 dest = Sexponentmantissa(source) 141 142 /* A quiet NaN has the high mantissa bit clear 143 * case the adjacent bit) bit set. */ 144 #define Sgl_set_quiet(sgl_value) Deposit_shigh 145 #define Sgl_set_exponent(sgl_value,exp) Deposi 146 147 #define Sgl_set_mantissa(dest,value) Deposit_s 148 #define Sgl_set_exponentmantissa(dest,value) \ 149 Deposit_sexponentmantissa(dest,value) 150 151 /* An infinity is represented with the max ex 152 #define Sgl_setinfinity_exponent(sgl_value) \ 153 Deposit_sexponent(sgl_value,SGL_INFINITY_E 154 #define Sgl_setinfinity_exponentmantissa(sgl_v 155 Deposit_sexponentmantissa(sgl_value, \ 156 (SGL_INFINITY_EXPONENT << (32-(1+SGL_E 157 #define Sgl_setinfinitypositive(sgl_value) 158 Sall(sgl_value) = (SGL_INFINITY_EXPONENT < 159 #define Sgl_setinfinitynegative(sgl_value) 160 Sall(sgl_value) = (SGL_INFINITY_EXPONENT < 161 | ((unsigned int)1<<31) 162 #define Sgl_setinfinity(sgl_value,sign) 163 Sall(sgl_value) = (SGL_INFINITY_EXPONENT < 164 ((unsigned int)sign << 31) 165 #define Sgl_sethigh4bits(sgl_value, extsign) 166 Deposit_shigh4(sgl_value,extsign) 167 #define Sgl_set_sign(sgl_value,sign) Deposit_s 168 #define Sgl_invert_sign(sgl_value) \ 169 Deposit_ssign(sgl_value,~Ssign(sgl_value)) 170 #define Sgl_setone_sign(sgl_value) Deposit_ssi 171 #define Sgl_setone_lowmantissa(sgl_value) Depo 172 #define Sgl_setzero_sign(sgl_value) Sall(sgl_ 173 #define Sgl_setzero_exponent(sgl_value) Sall(s 174 #define Sgl_setzero_mantissa(sgl_value) Sall(s 175 #define Sgl_setzero_exponentmantissa(sgl_value 176 #define Sgl_setzero(sgl_value) Sall(sgl_value) 177 #define Sgl_setnegativezero(sgl_value) Sall(sg 178 179 /* Use following macro for both overflow & und 180 #define ovfl - 181 #define unfl + 182 #define Sgl_setwrapped_exponent(sgl_value,expo 183 Deposit_sexponent(sgl_value,(exponent op S 184 185 #define Sgl_setlargestpositive(sgl_value) 186 Sall(sgl_value) = ((SGL_EMAX+SGL_BIAS) << 187 | ((1<<(32-(1+SGL_EXP_LE 188 #define Sgl_setlargestnegative(sgl_value) 189 Sall(sgl_value) = ((SGL_EMAX+SGL_BIAS) << 190 | ((1<<(32-(1+SGL_EXP_LE 191 | ((unsigned int)1<<31) 192 193 #define Sgl_setnegativeinfinity(sgl_value) 194 Sall(sgl_value) = 195 ((1<<SGL_EXP_LENGTH) | SGL_INFINITY_EXPONE 196 #define Sgl_setlargest(sgl_value,sign) 197 Sall(sgl_value) = (unsigned int)sign << 31 198 (((SGL_EMAX+SGL_BIAS) << (32-(1+SGL_EX 199 | ((1 << (32-(1+SGL_EXP_LENGTH))) - 200 #define Sgl_setlargest_exponentmantissa(sgl_va 201 Sall(sgl_value) = Sall(sgl_value) & ((unsi 202 (((SGL_EMAX+SGL_BIAS) << (32-(1+SGL_EX 203 | ((1 << (32-(1+SGL_EXP_LENGTH))) - 204 205 /* The high bit is always zero so arithmetic o 206 #define Sgl_right_align(srcdst,shift,extent) 207 /* sgl_floating_point srcdst; int shift; e 208 if (shift < 32) { 209 Extall(extent) = Sall(srcdst) << (32-( 210 Sall(srcdst) >>= shift; 211 } 212 else { 213 Extall(extent) = Sall(srcdst); 214 Sall(srcdst) = 0; 215 } 216 #define Sgl_hiddenhigh3mantissa(sgl_value) Shi 217 #define Sgl_hidden(sgl_value) Shidden(sgl_valu 218 #define Sgl_lowmantissa(sgl_value) Slow(sgl_va 219 220 /* The left argument is never smaller than the 221 #define Sgl_subtract(sgl_left,sgl_right,sgl_re 222 Sall(sgl_result) = Sall(sgl_left) - Sall(s 223 224 /* Subtract right augmented with extension fro 225 * store into result and extension. */ 226 #define Sgl_subtract_withextension(left,right, 227 /* sgl_floating_point left,right,result; e 228 Sgl_subtract(left,right,result); 229 if((Extall(extent) = 0-Extall(extent))) 230 Sall(result) = Sall(result)-1 231 232 #define Sgl_addition(sgl_left,sgl_right,sgl_re 233 Sall(sgl_result) = Sall(sgl_left) + Sall(s 234 235 #define Sgl_xortointp1(left,right,result) 236 result = Sall(left) XOR Sall(right); 237 238 #define Sgl_xorfromintp1(left,right,result) 239 Sall(result) = left XOR Sall(right) 240 241 /* Need to Initialize */ 242 #define Sgl_makequietnan(dest) 243 Sall(dest) = ((SGL_EMAX+SGL_BIAS)+1)<< (32 244 | (1<<(32-(1+SGL_EXP_LENGTH+2 245 #define Sgl_makesignalingnan(dest) 246 Sall(dest) = ((SGL_EMAX+SGL_BIAS)+1)<< (32 247 | (1<<(32-(1+SGL_EXP_LENGTH+1 248 249 #define Sgl_normalize(sgl_opnd,exponent) 250 while(Sgl_iszero_hiddenhigh7mantissa(s 251 Sgl_leftshiftby8(sgl_opnd); 252 exponent -= 8; 253 } 254 if(Sgl_iszero_hiddenhigh3mantissa(sgl_ 255 Sgl_leftshiftby4(sgl_opnd); 256 exponent -= 4; 257 } 258 while(Sgl_iszero_hidden(sgl_opnd)) { 259 Sgl_leftshiftby1(sgl_opnd); 260 exponent -= 1; 261 } 262 263 #define Sgl_setoverflow(sgl_opnd) 264 /* set result to infinity or largest n 265 switch (Rounding_mode()) { 266 case ROUNDPLUS: 267 if (Sgl_isone_sign(sgl 268 Sgl_setlargest 269 } 270 else { 271 Sgl_setinfinit 272 } 273 break; 274 case ROUNDMINUS: 275 if (Sgl_iszero_sign(sg 276 Sgl_setlargest 277 } 278 else { 279 Sgl_setinfinit 280 } 281 break; 282 case ROUNDNEAREST: 283 Sgl_setinfinity_expone 284 break; 285 case ROUNDZERO: 286 Sgl_setlargest_exponen 287 } 288 289 #define Sgl_denormalize(opnd,exponent,guard,st 290 Sgl_clear_signexponent_set_hidden(opnd 291 if (exponent >= (1 - SGL_P)) { 292 guard = (Sall(opnd) >> -expone 293 if (exponent < 0) sticky |= Sa 294 inexact = guard | sticky; 295 Sall(opnd) >>= (1-exponent); 296 } 297 else { 298 guard = 0; 299 sticky |= Sall(opnd); 300 inexact = sticky; 301 Sgl_setzero(opnd); 302 } 303 304 /* 305 * The fused multiply add instructions require 306 * with 48 bits of mantissa. 307 */ 308 #define SGLEXT_THRESHOLD 48 309 310 #define Sglext_setzero(valA,valB) \ 311 Sextallp1(valA) = 0; Sextallp2(valB) = 0 312 313 #define Sglext_isnotzero_mantissap2(valB) (Sex 314 #define Sglext_isone_lowp1(val) (Sextlowp1(val 315 #define Sglext_isone_highp2(val) (Sexthighp2(v 316 #define Sglext_isnotzero_low31p2(val) (Sextlow 317 #define Sglext_iszero(valA,valB) (Sextallp1(va 318 319 #define Sgl_copytoptr(src,destptr) *destptr = 320 #define Sgl_copyfromptr(srcptr,dest) dest = *s 321 #define Sglext_copy(srca,srcb,desta,destb) \ 322 Sextallp1(desta) = Sextallp1(srca); \ 323 Sextallp2(destb) = Sextallp2(srcb) 324 #define Sgl_copyto_sglext(src1,dest1,dest2) \ 325 Sextallp1(dest1) = Sall(src1); Sextall 326 327 #define Sglext_swap_lower(leftp2,rightp2) \ 328 Sextallp2(leftp2) = Sextallp2(leftp2) XOR 329 Sextallp2(rightp2) = Sextallp2(leftp2) XOR 330 Sextallp2(leftp2) = Sextallp2(leftp2) XOR 331 332 #define Sglext_setone_lowmantissap2(value) Dep 333 334 /* The high bit is always zero so arithmetic o 335 #define Sglext_right_align(srcdstA,srcdstB,shi 336 {int shiftamt, sticky; 337 shiftamt = shift % 32; 338 sticky = 0; 339 switch (shift/32) { 340 case 0: if (shiftamt > 0) { 341 sticky = Sextallp2(srcdstB) << 342 Variable_shift_double(Sextallp 343 Sextallp2(srcdstB),shiftamt,S 344 Sextallp1(srcdstA) >>= shiftam 345 } 346 break; 347 case 1: if (shiftamt > 0) { 348 sticky = (Sextallp1(srcdstA) < 349 Sextallp2(srcdstB); 350 } 351 else { 352 sticky = Sextallp2(srcdstB); 353 } 354 Sextallp2(srcdstB) = Sextallp1(sr 355 Sextallp1(srcdstA) = 0; 356 break; 357 } 358 if (sticky) Sglext_setone_lowmantissap2(sr 359 } 360 361 /* The left argument is never smaller than the 362 #define Sglext_subtract(lefta,leftb,righta,rig 363 if( Sextallp2(rightb) > Sextallp2(leftb) ) 364 Sextallp2(resultb) = Sextallp2(leftb) - Se 365 Sextallp1(resulta) = Sextallp1(lefta) - Se 366 367 #define Sglext_addition(lefta,leftb,righta,rig 368 /* If the sum of the low words is less tha 369 * an overflow into the next word occurred 370 if ((Sextallp2(resultb) = Sextallp2(leftb) 371 Sextallp2(rightb)) \ 372 Sextallp1(resulta) = Sextallp1(lef 373 else Sextallp1(resulta) = Sextallp1(lefta) 374 375 376 #define Sglext_arithrightshiftby1(srcdstA,srcd 377 Shiftdouble(Sextallp1(srcdstA),Sextallp2(s 378 Sextallp1(srcdstA) = (int)Sextallp1(srcdst 379 380 #define Sglext_leftshiftby8(valA,valB) \ 381 Shiftdouble(Sextallp1(valA),Sextallp2(valB 382 Sextallp2(valB) <<= 8 383 #define Sglext_leftshiftby4(valA,valB) \ 384 Shiftdouble(Sextallp1(valA),Sextallp2(valB 385 Sextallp2(valB) <<= 4 386 #define Sglext_leftshiftby3(valA,valB) \ 387 Shiftdouble(Sextallp1(valA),Sextallp2(valB 388 Sextallp2(valB) <<= 3 389 #define Sglext_leftshiftby2(valA,valB) \ 390 Shiftdouble(Sextallp1(valA),Sextallp2(valB 391 Sextallp2(valB) <<= 2 392 #define Sglext_leftshiftby1(valA,valB) \ 393 Shiftdouble(Sextallp1(valA),Sextallp2(valB 394 Sextallp2(valB) <<= 1 395 396 #define Sglext_rightshiftby4(valueA,valueB) \ 397 Shiftdouble(Sextallp1(valueA),Sextallp2(va 398 Sextallp1(valueA) >>= 4 399 #define Sglext_rightshiftby3(valueA,valueB) \ 400 Shiftdouble(Sextallp1(valueA),Sextallp2(va 401 Sextallp1(valueA) >>= 3 402 #define Sglext_rightshiftby1(valueA,valueB) \ 403 Shiftdouble(Sextallp1(valueA),Sextallp2(va 404 Sextallp1(valueA) >>= 1 405 406 #define Sglext_xortointp1(left,right,result) S 407 #define Sglext_xorfromintp1(left,right,result) 408 Sgl_xorfromintp1(left,right,result) 409 #define Sglext_copytoint_exponentmantissa(src, 410 Sgl_copytoint_exponentmantissa(src,des 411 #define Sglext_ismagnitudeless(signlessleft,si 412 Sgl_ismagnitudeless(signlessleft,signl 413 414 #define Sglext_set_sign(dbl_value,sign) Sgl_s 415 #define Sglext_clear_signexponent_set_hidden(s 416 Sgl_clear_signexponent_set_hidden(srcd 417 #define Sglext_clear_signexponent(srcdst) Sgl_ 418 #define Sglext_clear_sign(srcdst) Sgl_clear_si 419 #define Sglext_isone_hidden(dbl_value) Sgl_iso 420 421 #define Sglext_denormalize(opndp1,opndp2,expon 422 {int sticky; 423 is_tiny = TRUE; 424 if (exponent == 0 && Sextallp2(opndp2)) { 425 switch (Rounding_mode()) { 426 case ROUNDPLUS: 427 if (Sgl_iszero_sign(opndp1)) 428 if (Sgl_isone_hiddenov 429 is_tiny = FALS 430 break; 431 case ROUNDMINUS: 432 if (Sgl_isone_sign(opndp1)) { 433 if (Sgl_isone_hiddenov 434 is_tiny = FALS 435 } 436 break; 437 case ROUNDNEAREST: 438 if (Sglext_isone_highp2(opndp2 439 (Sglext_isone_lowp1(opndp1 440 Sglext_isnotzero_low31p2( 441 if (Sgl_isone_hiddenov 442 is_tiny = FALS 443 break; 444 } 445 } 446 Sglext_clear_signexponent_set_hidden(opndp 447 if (exponent >= (1-DBL_P)) { 448 if (exponent >= -31) { 449 if (exponent > -31) { 450 sticky = Sextallp2(opndp2) << 451 Variable_shift_double(opndp1,o 452 Sextallp1(opndp1) >>= 1-expone 453 } 454 else { 455 sticky = Sextallp2(opndp2); 456 Sextallp2(opndp2) = Sextallp1( 457 Sextallp1(opndp1) = 0; 458 } 459 } 460 else { 461 sticky = (Sextallp1(opndp1) << 31+ 462 Sextallp2(opndp2); 463 Sextallp2(opndp2) = Sextallp1(opnd 464 Sextallp1(opndp1) = 0; 465 } 466 } 467 else { 468 sticky = Sextallp1(opndp1) | Sextallp2 469 Sglext_setzero(opndp1,opndp2); 470 } 471 if (sticky) Sglext_setone_lowmantissap2(op 472 exponent = 0; 473 } 474
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.