MCPcopy Create free account
hub / github.com/ROCm/clr / float2half_rtz

Function float2half_rtz

rocclr/platform/memory.cpp:1322–1361  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1320}
1321
1322static uint16_t float2half_rtz(float f) {
1323 union {
1324 float f;
1325 uint32_t u;
1326 } u = {f};
1327 uint32_t sign = (u.u >> 16) & 0x8000;
1328 float x = fabsf(f);
1329
1330 // Nan
1331 if (x != x) {
1332 u.u >>= (24 - 11);
1333 u.u &= 0x7fff;
1334 u.u |= 0x0200; // silence the NaN
1335 return u.u | sign;
1336 }
1337 int values[5] = {0x47800000, 0x33800000, 0x38800000, 0x4b800000, 0x7f800000};
1338 // overflow
1339 if (x >= interpret_value<int, float>(values[0])) {
1340 if (x == interpret_value<int, float>(values[4])) {
1341 return 0x7c00 | sign;
1342 }
1343 return 0x7bff | sign;
1344 }
1345
1346 // underflow
1347 if (x < interpret_value<int, float>(values[1])) {
1348 return sign; // The halfway case can return 0x0001 or 0. 0 is even.
1349 }
1350
1351 // half denormal
1352 if (x < interpret_value<int, float>(values[2])) {
1353 x *= interpret_value<int, float>(values[3]);
1354 return static_cast<uint16_t>((int)x | sign);
1355 }
1356
1357 u.u &= 0xFFFFE000U;
1358 u.u -= 0x38000000U;
1359
1360 return (u.u >> (24 - 11)) | sign;
1361}
1362
1363void Image::Format::getChannelOrder(uint8_t* channelOrder) const {
1364 enum { CH_ORDER_R = 0, CH_ORDER_G, CH_ORDER_B, CH_ORDER_A };

Callers 1

formatColorMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected