| 6651 | }; |
| 6652 | |
| 6653 | FP32 half_to_float(FP16 h) { |
| 6654 | static const FP32 magic = {113 << 23}; |
| 6655 | static const unsigned int shifted_exp = 0x7c00 |
| 6656 | << 13; // exponent mask after shift |
| 6657 | FP32 o; |
| 6658 | |
| 6659 | o.u = (h.u & 0x7fff) << 13; // exponent/mantissa bits |
| 6660 | unsigned int exp_ = shifted_exp & o.u; // just the exponent |
| 6661 | o.u += (127 - 15) << 23; // exponent adjust |
| 6662 | |
| 6663 | // handle exponent special cases |
| 6664 | if (exp_ == shifted_exp) // Inf/NaN? |
| 6665 | o.u += (128 - 16) << 23; // extra exp adjust |
| 6666 | else if (exp_ == 0) // Zero/Denormal? |
| 6667 | { |
| 6668 | o.u += 1 << 23; // extra exp adjust |
| 6669 | o.f -= magic.f; // renormalize |
| 6670 | } |
| 6671 | |
| 6672 | o.u |= (h.u & 0x8000) << 16; // sign bit |
| 6673 | return o; |
| 6674 | } |
| 6675 | |
| 6676 | FP16 float_to_half_full(FP32 f) { |
| 6677 | FP16 o = {0}; |
no outgoing calls
no test coverage detected