| 616 | /// \return binary representation of half-precision value |
| 617 | template <std::float_round_style R> |
| 618 | uint16 float2half_impl(float value, true_type) |
| 619 | { |
| 620 | typedef bits<float>::type uint32; |
| 621 | uint32 bits; // = *reinterpret_cast<uint32*>(&value); //violating strict aliasing! |
| 622 | std::memcpy(&bits, &value, sizeof(float)); |
| 623 | /* uint16 hbits = (bits>>16) & 0x8000; |
| 624 | bits &= 0x7FFFFFFF; |
| 625 | int exp = bits >> 23; |
| 626 | if(exp == 255) |
| 627 | return hbits | 0x7C00 | (0x3FF&-static_cast<unsigned>((bits&0x7FFFFF)!=0)); |
| 628 | if(exp > 142) |
| 629 | { |
| 630 | if(R == std::round_toward_infinity) |
| 631 | return hbits | 0x7C00 - (hbits>>15); |
| 632 | if(R == std::round_toward_neg_infinity) |
| 633 | return hbits | 0x7BFF + (hbits>>15); |
| 634 | return hbits | 0x7BFF + (R!=std::round_toward_zero); |
| 635 | } |
| 636 | int g, s; |
| 637 | if(exp > 112) |
| 638 | { |
| 639 | g = (bits>>12) & 1; |
| 640 | s = (bits&0xFFF) != 0; |
| 641 | hbits |= ((exp-112)<<10) | ((bits>>13)&0x3FF); |
| 642 | } |
| 643 | else if(exp > 101) |
| 644 | { |
| 645 | int i = 125 - exp; |
| 646 | bits = (bits&0x7FFFFF) | 0x800000; |
| 647 | g = (bits>>i) & 1; |
| 648 | s = (bits&((1L<<i)-1)) != 0; |
| 649 | hbits |= bits >> (i+1); |
| 650 | } |
| 651 | else |
| 652 | { |
| 653 | g = 0; |
| 654 | s = bits != 0; |
| 655 | } |
| 656 | if(R == std::round_to_nearest) |
| 657 | #if HALF_ROUND_TIES_TO_EVEN |
| 658 | hbits += g & (s|hbits); |
| 659 | #else |
| 660 | hbits += g; |
| 661 | #endif |
| 662 | else if(R == std::round_toward_infinity) |
| 663 | hbits += ~(hbits>>15) & (s|g); |
| 664 | else if(R == std::round_toward_neg_infinity) |
| 665 | hbits += (hbits>>15) & (g|s); |
| 666 | */ |
| 667 | static const uint16 base_table[512] = {0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, |
| 668 | 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, |
| 669 | 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, |
| 670 | 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, |
| 671 | 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, |
| 672 | 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, |
| 673 | 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, |
| 674 | 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0001, 0x0002, 0x0004, 0x0008, |
| 675 | 0x0010, 0x0020, 0x0040, 0x0080, 0x0100, 0x0200, 0x0400, 0x0800, 0x0C00, 0x1000, 0x1400, 0x1800, 0x1C00, 0x2000, |
nothing calls this directly
no test coverage detected