MCPcopy Create free account
hub / github.com/ARM-software/ComputeLibrary / float2half_impl

Function float2half_impl

include/half/half.hpp:454–568  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 7

builtin_signbitFunction · 0.85
builtin_isnanFunction · 0.85
builtin_isinfFunction · 0.85
frexpFunction · 0.85
ldexpFunction · 0.85
modfFunction · 0.85
absFunction · 0.85

Tested by

no test coverage detected