| 465 | /// \param value single-precision value |
| 466 | /// \return binary representation of half-precision value |
| 467 | template<std::float_round_style R> uint16 float2half_impl(float value, true_type) |
| 468 | { |
| 469 | typedef bits<float>::type uint32; |
| 470 | uint32 bits;// = *reinterpret_cast<uint32*>(&value); //violating strict aliasing! |
| 471 | std::memcpy(&bits, &value, sizeof(float)); |
| 472 | /* uint16 hbits = (bits>>16) & 0x8000; |
| 473 | bits &= 0x7FFFFFFF; |
| 474 | int exp = bits >> 23; |
| 475 | if(exp == 255) |
| 476 | return hbits | 0x7C00 | (0x3FF&-static_cast<unsigned>((bits&0x7FFFFF)!=0)); |
| 477 | if(exp > 142) |
| 478 | { |
| 479 | if(R == std::round_toward_infinity) |
| 480 | return hbits | 0x7C00 - (hbits>>15); |
| 481 | if(R == std::round_toward_neg_infinity) |
| 482 | return hbits | 0x7BFF + (hbits>>15); |
| 483 | return hbits | 0x7BFF + (R!=std::round_toward_zero); |
| 484 | } |
| 485 | int g, s; |
| 486 | if(exp > 112) |
| 487 | { |
| 488 | g = (bits>>12) & 1; |
| 489 | s = (bits&0xFFF) != 0; |
| 490 | hbits |= ((exp-112)<<10) | ((bits>>13)&0x3FF); |
| 491 | } |
| 492 | else if(exp > 101) |
| 493 | { |
| 494 | int i = 125 - exp; |
| 495 | bits = (bits&0x7FFFFF) | 0x800000; |
| 496 | g = (bits>>i) & 1; |
| 497 | s = (bits&((1L<<i)-1)) != 0; |
| 498 | hbits |= bits >> (i+1); |
| 499 | } |
| 500 | else |
| 501 | { |
| 502 | g = 0; |
| 503 | s = bits != 0; |
| 504 | } |
| 505 | if(R == std::round_to_nearest) |
| 506 | #if HALF_ROUND_TIES_TO_EVEN |
| 507 | hbits += g & (s|hbits); |
| 508 | #else |
| 509 | hbits += g; |
| 510 | #endif |
| 511 | else if(R == std::round_toward_infinity) |
| 512 | hbits += ~(hbits>>15) & (s|g); |
| 513 | else if(R == std::round_toward_neg_infinity) |
| 514 | hbits += (hbits>>15) & (g|s); |
| 515 | */ static const uint16 base_table[512] = { |
| 516 | 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, |
| 517 | 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, |
| 518 | 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, |
| 519 | 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, |
| 520 | 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, |
| 521 | 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, |
| 522 | 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080, 0x0100, |
| 523 | 0x0200, 0x0400, 0x0800, 0x0C00, 0x1000, 0x1400, 0x1800, 0x1C00, 0x2000, 0x2400, 0x2800, 0x2C00, 0x3000, 0x3400, 0x3800, 0x3C00, |
| 524 | 0x4000, 0x4400, 0x4800, 0x4C00, 0x5000, 0x5400, 0x5800, 0x5C00, 0x6000, 0x6400, 0x6800, 0x6C00, 0x7000, 0x7400, 0x7800, 0x7C00, |
nothing calls this directly
no test coverage detected