Changeset 41455a22 in mainline for uspace/lib/softfloat/include/sftypes.h
- Timestamp:
- 2012-04-07T17:56:35Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 44c1a48, f3378ba
- Parents:
- 6bb169b5 (diff), 88d5c1e (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/softfloat/include/sftypes.h
r6bb169b5 r41455a22 40 40 #include <stdint.h> 41 41 42 typedef union { 43 float f; 44 uint32_t binary; 45 46 struct { 42 /* 43 * For recognizing NaNs or infinity use specialized comparison 44 * functions, comparing with these constants is not sufficient. 45 */ 46 47 #define FLOAT32_NAN UINT32_C(0x7FC00001) 48 #define FLOAT32_SIGNAN UINT32_C(0x7F800001) 49 #define FLOAT32_INF UINT32_C(0x7F800000) 50 51 #define FLOAT64_NAN UINT64_C(0x7FF8000000000001) 52 #define FLOAT64_SIGNAN UINT64_C(0x7FF0000000000001) 53 #define FLOAT64_INF UINT64_C(0x7FF0000000000000) 54 55 #define FLOAT96_NAN_HI UINT64_C(0x7FFF80000000) 56 #define FLOAT96_NAN_LO UINT32_C(0x00010000) 57 #define FLOAT96_SIGNAN_HI UINT64_C(0x7FFF00000000) 58 #define FLOAT96_SIGNAN_LO UINT32_C(0x00010000) 59 60 #define FLOAT128_NAN_HI UINT64_C(0x7FFF800000000000) 61 #define FLOAT128_NAN_LO UINT64_C(0x0000000000000001) 62 #define FLOAT128_SIGNAN_HI UINT64_C(0x7FFF000000000000) 63 #define FLOAT128_SIGNAN_LO UINT64_C(0x0000000000000001) 64 #define FLOAT128_INF_HI UINT64_C(0x7FFF000000000000) 65 #define FLOAT128_INF_LO UINT64_C(0x0000000000000000) 66 67 #define FLOAT32_FRACTION_SIZE 23 68 #define FLOAT64_FRACTION_SIZE 52 69 #define FLOAT96_FRACTION_SIZE 64 70 #define FLOAT128_FRACTION_SIZE 112 71 #define FLOAT128_FRAC_HI_SIZE 48 72 #define FLOAT128_FRAC_LO_SIZE 64 73 74 #define FLOAT32_HIDDEN_BIT_MASK UINT32_C(0x800000) 75 #define FLOAT64_HIDDEN_BIT_MASK UINT64_C(0x10000000000000) 76 #define FLOAT128_HIDDEN_BIT_MASK_HI UINT64_C(0x1000000000000) 77 #define FLOAT128_HIDDEN_BIT_MASK_LO UINT64_C(0x0000000000000000) 78 79 #define FLOAT32_MAX_EXPONENT 0xFF 80 #define FLOAT64_MAX_EXPONENT 0x7FF 81 #define FLOAT96_MAX_EXPONENT 0x7FFF 82 #define FLOAT128_MAX_EXPONENT 0x7FFF 83 84 #define FLOAT32_BIAS 0x7F 85 #define FLOAT64_BIAS 0x3FF 86 #define FLOAT96_BIAS 0x3FFF 87 #define FLOAT128_BIAS 0x3FFF 88 47 89 #if defined(__BE__) 90 91 typedef union { 92 uint32_t bin; 93 94 struct { 48 95 uint32_t sign : 1; 49 96 uint32_t exp : 8; 50 97 uint32_t fraction : 23; 51 #elif defined(__LE__) 52 uint32_t fraction : 23; 53 uint32_t exp : 8; 54 uint32_t sign : 1; 55 #else 56 #error Unknown endianess 57 #endif 58 } parts __attribute__ ((packed)); 98 } parts __attribute__((packed)); 59 99 } float32; 60 100 61 101 typedef union { 62 double d; 63 uint64_t binary; 64 65 struct { 66 #if defined(__BE__) 102 uint64_t bin; 103 104 struct { 67 105 uint64_t sign : 1; 68 106 uint64_t exp : 11; 69 107 uint64_t fraction : 52; 70 #elif defined(__LE__) 71 uint64_t fraction : 52; 72 uint64_t exp : 11; 108 } parts __attribute__((packed)); 109 } float64; 110 111 typedef union { 112 struct { 113 uint64_t hi; 114 uint32_t lo; 115 } bin __attribute__((packed)); 116 117 struct { 118 uint64_t padding : 16; 73 119 uint64_t sign : 1; 74 #else 75 #error Unknown endianess 76 #endif 77 } parts __attribute__ ((packed)); 78 } float64; 79 80 typedef union { 81 long double ld; 82 struct { 83 #if defined(__BE__) 120 uint64_t exp : 15; 121 uint64_t fraction : 64; 122 } parts __attribute__((packed)); 123 } float96; 124 125 typedef union { 126 struct { 84 127 uint64_t hi; 85 128 uint64_t lo; 86 #elif defined(__LE__) 87 uint64_t lo; 88 uint64_t hi; 89 #else 90 #error Unknown endianess 91 #endif 92 } binary; 93 94 struct { 95 #if defined(__BE__) 129 } bin __attribute__((packed)); 130 131 struct { 96 132 uint64_t sign : 1; 97 133 uint64_t exp : 15; 98 134 uint64_t frac_hi : 48; 99 135 uint64_t frac_lo : 64; 136 } parts __attribute__((packed)); 137 } float128; 138 100 139 #elif defined(__LE__) 140 141 typedef union { 142 uint32_t bin; 143 144 struct { 145 uint32_t fraction : 23; 146 uint32_t exp : 8; 147 uint32_t sign : 1; 148 } parts __attribute__((packed)); 149 } float32; 150 151 typedef union { 152 uint64_t bin; 153 154 struct { 155 uint64_t fraction : 52; 156 uint64_t exp : 11; 157 uint64_t sign : 1; 158 } parts __attribute__((packed)); 159 } float64; 160 161 typedef union { 162 struct { 163 uint32_t lo; 164 uint64_t hi; 165 } bin __attribute__((packed)); 166 167 struct { 168 uint64_t fraction : 64; 169 uint64_t exp : 15; 170 uint64_t sign : 1; 171 uint64_t padding : 16; 172 } parts __attribute__((packed)); 173 } float96; 174 175 typedef union { 176 struct { 177 uint64_t lo; 178 uint64_t hi; 179 } bin __attribute__((packed)); 180 181 struct { 101 182 uint64_t frac_lo : 64; 102 183 uint64_t frac_hi : 48; 103 184 uint64_t exp : 15; 104 185 uint64_t sign : 1; 186 } parts __attribute__((packed)); 187 } float128; 188 105 189 #else 106 190 #error Unknown endianess 107 191 #endif 108 } parts __attribute__ ((packed)); 109 } float128; 110 111 /* 112 * For recognizing NaNs or infinity use specialized comparison functions, 113 * comparing with these constants is not sufficient. 114 */ 115 116 #define FLOAT32_NAN 0x7FC00001 117 #define FLOAT32_SIGNAN 0x7F800001 118 #define FLOAT32_INF 0x7F800000 119 120 #define FLOAT64_NAN 0x7FF8000000000001ll 121 #define FLOAT64_SIGNAN 0x7FF0000000000001ll 122 #define FLOAT64_INF 0x7FF0000000000000ll 123 124 #define FLOAT128_NAN_HI 0x7FFF800000000000ll 125 #define FLOAT128_NAN_LO 0x0000000000000001ll 126 #define FLOAT128_SIGNAN_HI 0x7FFF000000000000ll 127 #define FLOAT128_SIGNAN_LO 0x0000000000000001ll 128 #define FLOAT128_INF_HI 0x7FFF000000000000ll 129 #define FLOAT128_INF_LO 0x0000000000000000ll 130 131 #define FLOAT32_FRACTION_SIZE 23 132 #define FLOAT64_FRACTION_SIZE 52 133 #define FLOAT128_FRACTION_SIZE 112 134 #define FLOAT128_FRAC_HI_SIZE 48 135 #define FLOAT128_FRAC_LO_SIZE 64 136 137 #define FLOAT32_HIDDEN_BIT_MASK 0x800000 138 #define FLOAT64_HIDDEN_BIT_MASK 0x10000000000000ll 139 #define FLOAT128_HIDDEN_BIT_MASK_HI 0x1000000000000ll 140 #define FLOAT128_HIDDEN_BIT_MASK_LO 0x0000000000000000ll 141 142 #define FLOAT32_MAX_EXPONENT 0xFF 143 #define FLOAT64_MAX_EXPONENT 0x7FF 144 #define FLOAT128_MAX_EXPONENT 0x7FFF 145 146 #define FLOAT32_BIAS 0x7F 147 #define FLOAT64_BIAS 0x3FF 148 #define FLOAT80_BIAS 0x3FFF 149 #define FLOAT128_BIAS 0x3FFF 192 193 typedef union { 194 float val; 195 196 #if defined(FLOAT_SIZE_32) 197 float32 data; 198 #elif defined(FLOAT_SIZE_64) 199 float64 data; 200 #elif defined(FLOAT_SIZE_96) 201 float96 data; 202 #elif defined(FLOAT_SIZE_128) 203 float128 data; 204 #else 205 #error Unsupported float size 206 #endif 207 } float_t; 208 209 typedef union { 210 double val; 211 212 #if defined(DOUBLE_SIZE_32) 213 float32 data; 214 #elif defined(DOUBLE_SIZE_64) 215 float64 data; 216 #elif defined(DOUBLE_SIZE_96) 217 float96 data; 218 #elif defined(DOUBLE_SIZE_128) 219 float128 data; 220 #else 221 #error Unsupported double size 222 #endif 223 } double_t; 224 225 typedef union { 226 long double val; 227 228 #if defined(LONG_DOUBLE_SIZE_32) 229 float32 data; 230 #elif defined(LONG_DOUBLE_SIZE_64) 231 float64 data; 232 #elif defined(LONG_DOUBLE_SIZE_96) 233 float96 data; 234 #elif defined(LONG_DOUBLE_SIZE_128) 235 float128 data; 236 #else 237 #error Unsupported long double size 238 #endif 239 } long_double_t; 240 241 242 #if defined(INT_SIZE_8) 243 244 #define _to_int _to_int8 245 #define from_int int8 246 247 #elif defined(INT_SIZE_16) 248 249 #define _to_int _to_int16 250 #define from_int int16 251 252 #elif defined(INT_SIZE_32) 253 254 #define _to_int _to_int32 255 #define from_int int32 256 257 #elif defined(INT_SIZE_64) 258 259 #define _to_int _to_int64 260 #define from_int int64 261 262 #endif 263 264 265 #if defined(UINT_SIZE_8) 266 267 #define _to_uint _to_uint8 268 #define from_uint uint8 269 270 #elif defined(UINT_SIZE_16) 271 272 #define _to_uint _to_uint16 273 #define from_uint uint16 274 275 #elif defined(UINT_SIZE_32) 276 277 #define _to_uint _to_uint32 278 #define from_uint uint32 279 280 #elif defined(UINT_SIZE_64) 281 282 #define _to_uint _to_uint64 283 #define from_uint uint64 284 285 #endif 286 287 288 #if defined(LONG_SIZE_8) 289 290 #define _to_long _to_int8 291 #define from_long int8 292 293 #elif defined(LONG_SIZE_16) 294 295 #define _to_long _to_int16 296 #define from_long int16 297 298 #elif defined(LONG_SIZE_32) 299 300 #define _to_long _to_int32 301 #define from_long int32 302 303 #elif defined(LONG_SIZE_64) 304 305 #define _to_long _to_int64 306 #define from_long int64 307 308 #endif 309 310 311 #if defined(ULONG_SIZE_8) 312 313 #define _to_ulong _to_uint8 314 #define from_ulong uint8 315 316 #elif defined(ULONG_SIZE_16) 317 318 #define _to_ulong _to_uint16 319 #define from_ulong uint16 320 321 #elif defined(ULONG_SIZE_32) 322 323 #define _to_ulong _to_uint32 324 #define from_ulong uint32 325 326 #elif defined(ULONG_SIZE_64) 327 328 #define _to_ulong _to_uint64 329 #define from_ulong uint64 330 331 #endif 332 333 334 #if defined(LLONG_SIZE_8) 335 336 #define _to_llong _to_int8 337 #define from_llong int8 338 339 #elif defined(LLONG_SIZE_16) 340 341 #define _to_llong _to_int16 342 #define from_llong int16 343 344 #elif defined(LLONG_SIZE_32) 345 346 #define _to_llong _to_int32 347 #define from_llong int32 348 349 #elif defined(LLONG_SIZE_64) 350 351 #define _to_llong _to_int64 352 #define from_llong int64 353 354 #endif 355 356 357 #if defined(ULLONG_SIZE_8) 358 359 #define _to_ullong _to_uint8 360 #define from_ullong uint8 361 362 #elif defined(ULLONG_SIZE_16) 363 364 #define _to_ullong _to_uint16 365 #define from_ullong uint16 366 367 #elif defined(ULLONG_SIZE_32) 368 369 #define _to_ullong _to_uint32 370 #define from_ullong uint32 371 372 #elif defined(ULLONG_SIZE_64) 373 374 #define _to_ullong _to_uint64 375 #define from_ullong uint64 376 377 #endif 378 379 380 #if defined(FLOAT_SIZE_32) 381 382 #define add_float add_float32 383 #define sub_float sub_float32 384 #define mul_float mul_float32 385 #define div_float div_float32 386 #define _to_float _to_float32 387 #define from_float float32 388 #define is_float_nan is_float32_nan 389 #define is_float_eq is_float32_eq 390 #define is_float_lt is_float32_lt 391 #define is_float_gt is_float32_gt 392 393 #elif defined(FLOAT_SIZE_64) 394 395 #define add_float add_float64 396 #define sub_float sub_float64 397 #define mul_float mul_float64 398 #define div_float div_float64 399 #define _to_float _to_float64 400 #define from_float float64 401 #define is_float_nan is_float64_nan 402 #define is_float_eq is_float64_eq 403 #define is_float_lt is_float64_lt 404 #define is_float_gt is_float64_gt 405 406 #elif defined(FLOAT_SIZE_96) 407 408 #define add_float add_float96 409 #define sub_float sub_float96 410 #define mul_float mul_float96 411 #define div_float div_float96 412 #define _to_float _to_float96 413 #define from_float float96 414 #define is_float_nan is_float96_nan 415 #define is_float_eq is_float96_eq 416 #define is_float_lt is_float96_lt 417 #define is_float_gt is_float96_gt 418 419 #elif defined(FLOAT_SIZE_128) 420 421 #define add_float add_float128 422 #define sub_float sub_float128 423 #define mul_float mul_float128 424 #define div_float div_float128 425 #define _to_float _to_float128 426 #define from_float float128 427 #define is_float_nan is_float128_nan 428 #define is_float_eq is_float128_eq 429 #define is_float_lt is_float128_lt 430 #define is_float_gt is_float128_gt 431 432 #endif 433 434 435 #if defined(DOUBLE_SIZE_32) 436 437 #define add_double add_float32 438 #define sub_double sub_float32 439 #define mul_double mul_float32 440 #define div_double div_float32 441 #define _to_double _to_float32 442 #define from_double float32 443 #define is_double_nan is_float32_nan 444 #define is_double_eq is_float32_eq 445 #define is_double_lt is_float32_lt 446 #define is_double_gt is_float32_gt 447 448 #elif defined(DOUBLE_SIZE_64) 449 450 #define add_double add_float64 451 #define sub_double sub_float64 452 #define mul_double mul_float64 453 #define div_double div_float64 454 #define _to_double _to_float64 455 #define from_double float64 456 #define is_double_nan is_float64_nan 457 #define is_double_eq is_float64_eq 458 #define is_double_lt is_float64_lt 459 #define is_double_gt is_float64_gt 460 461 #elif defined(DOUBLE_SIZE_96) 462 463 #define add_double add_float96 464 #define sub_double sub_float96 465 #define mul_double mul_float96 466 #define div_double div_float96 467 #define _to_double _to_float96 468 #define from_double float96 469 #define is_double_nan is_float96_nan 470 #define is_double_eq is_float96_eq 471 #define is_double_lt is_float96_lt 472 #define is_double_gt is_float96_gt 473 474 #elif defined(DOUBLE_SIZE_128) 475 476 #define add_double add_float128 477 #define sub_double sub_float128 478 #define mul_double mul_float128 479 #define div_double div_float128 480 #define _to_double _to_float128 481 #define from_double float128 482 #define is_double_nan is_float128_nan 483 #define is_double_eq is_float128_eq 484 #define is_double_lt is_float128_lt 485 #define is_double_gt is_float128_gt 486 487 #endif 488 489 490 #if defined(LONG_DOUBLE_SIZE_32) 491 492 #define add_long_double add_float32 493 #define sub_long_double sub_float32 494 #define mul_long_double mul_float32 495 #define div_long_double div_float32 496 #define _to_long_double _to_float32 497 #define from_long_double float32 498 #define is_long_double_nan is_float32_nan 499 #define is_long_double_eq is_float32_eq 500 #define is_long_double_lt is_float32_lt 501 #define is_long_double_gt is_float32_gt 502 503 #elif defined(LONG_DOUBLE_SIZE_64) 504 505 #define add_long_double add_float64 506 #define sub_long_double sub_float64 507 #define mul_long_double mul_float64 508 #define div_long_double div_float64 509 #define _to_long_double _to_float64 510 #define from_long_double float64 511 #define is_long_double_nan is_float64_nan 512 #define is_long_double_eq is_float64_eq 513 #define is_long_double_lt is_float64_lt 514 #define is_long_double_gt is_float64_gt 515 516 #elif defined(LONG_DOUBLE_SIZE_96) 517 518 #define add_long_double add_float96 519 #define sub_long_double sub_float96 520 #define mul_long_double mul_float96 521 #define div_long_double div_float96 522 #define _to_long_double _to_float96 523 #define from_long_double float96 524 #define is_long_double_nan is_float96_nan 525 #define is_long_double_eq is_float96_eq 526 #define is_long_double_lt is_float96_lt 527 #define is_long_double_gt is_float96_gt 528 529 #elif defined(LONG_DOUBLE_SIZE_128) 530 531 #define add_long_double add_float128 532 #define sub_long_double sub_float128 533 #define mul_long_double mul_float128 534 #define div_long_double div_float128 535 #define _to_long_double _to_float128 536 #define from_long_double float128 537 #define is_long_double_nan is_float128_nan 538 #define is_long_double_eq is_float128_eq 539 #define is_long_double_lt is_float128_lt 540 #define is_long_double_gt is_float128_gt 541 542 #endif 543 544 545 #define CONCAT(a, b) CONCAT_ARGS(a, b) 546 #define CONCAT_ARGS(a, b) a ## b 547 548 #define float32_to_float32(arg) (arg) 549 #define float64_to_float64(arg) (arg) 550 #define float96_to_float96(arg) (arg) 551 #define float128_to_float128(arg) (arg) 552 553 #define float_to_double CONCAT(from_float, _to_double) 554 #define float_to_long_double CONCAT(from_float, _to_long_double) 555 #define float_to_int CONCAT(from_float, _to_int) 556 #define float_to_uint CONCAT(from_float, _to_uint) 557 #define float_to_long CONCAT(from_float, _to_long) 558 #define float_to_ulong CONCAT(from_float, _to_ulong) 559 #define float_to_llong CONCAT(from_float, _to_llong) 560 #define float_to_ullong CONCAT(from_float, _to_ullong) 561 562 #define double_to_float CONCAT(from_double, _to_float) 563 #define double_to_long_double CONCAT(from_double, _to_long_double) 564 #define double_to_int CONCAT(from_double, _to_int) 565 #define double_to_uint CONCAT(from_double, _to_uint) 566 #define double_to_long CONCAT(from_double, _to_long) 567 #define double_to_ulong CONCAT(from_double, _to_ulong) 568 #define double_to_llong CONCAT(from_double, _to_llong) 569 #define double_to_ullong CONCAT(from_double, _to_ullong) 570 571 #define long_double_to_float CONCAT(from_long_double, _to_float) 572 #define long_double_to_double CONCAT(from_long_double, _to_double) 573 #define long_double_to_int CONCAT(from_long_double, _to_int) 574 #define long_double_to_uint CONCAT(from_long_double, _to_uint) 575 #define long_double_to_long CONCAT(from_long_double, _to_long) 576 #define long_double_to_ulong CONCAT(from_long_double, _to_ulong) 577 #define long_double_to_llong CONCAT(from_long_double, _to_llong) 578 #define long_double_to_ullong CONCAT(from_long_double, _to_ullong) 579 580 #define int_to_float CONCAT(from_int, _to_float) 581 #define int_to_double CONCAT(from_int, _to_double) 582 #define int_to_long_double CONCAT(from_int, _to_long_double) 583 584 #define uint_to_float CONCAT(from_uint, _to_float) 585 #define uint_to_double CONCAT(from_uint, _to_double) 586 #define uint_to_long_double CONCAT(from_uint, _to_long_double) 587 588 #define long_to_float CONCAT(from_long, _to_float) 589 #define long_to_double CONCAT(from_long, _to_double) 590 #define long_to_long_double CONCAT(from_long, _to_long_double) 591 592 #define ulong_to_float CONCAT(from_ulong, _to_float) 593 #define ulong_to_double CONCAT(from_ulong, _to_double) 594 #define ulong_to_long_double CONCAT(from_ulong, _to_long_double) 595 596 #define llong_to_float CONCAT(from_llong, _to_float) 597 #define llong_to_double CONCAT(from_llong, _to_double) 598 #define llong_to_long_double CONCAT(from_llong, _to_long_double) 599 600 #define ullong_to_float CONCAT(from_ullong, _to_float) 601 #define ullong_to_double CONCAT(from_ullong, _to_double) 602 #define ullong_to_long_double CONCAT(from_ullong, _to_long_double) 603 150 604 151 605 #endif
Note:
See TracChangeset
for help on using the changeset viewer.