MCPcopy Create free account
hub / github.com/KhronosGroup/KTX-Software / clz

Function clz

external/astc-encoder/Source/astcenc_vecmathlib.h:437–452  ·  view source on GitHub ↗

* @brief Count the leading zeros for each lane in @c a. * * Valid for all data values of @c a; will return a per-lane value [0, 32]. */

Source from the content-addressed store, hash-verified

435 * Valid for all data values of @c a; will return a per-lane value [0, 32].
436 */
437static ASTCENC_SIMD_INLINE vint4 clz(vint4 a)
438{
439 // This function is a horrible abuse of floating point exponents to convert
440 // the original integer value into a 2^N encoding we can recover easily.
441
442 // Convert to float without risk of rounding up by keeping only top 8 bits.
443 // This trick is is guaranteed to keep top 8 bits and clear the 9th.
444 a = (~lsr<8>(a)) & a;
445 a = float_as_int(int_to_float(a));
446
447 // Extract and unbias exponent
448 a = vint4(127 + 31) - lsr<23>(a);
449
450 // Clamp result to a valid 32-bit range
451 return clamp(0, 32, a);
452}
453
454/**
455 * @brief Return lanewise 2^a for each lane in @c a.

Callers 2

unorm16_to_sf16Function · 0.70
TESTFunction · 0.50

Calls 4

float_as_intFunction · 0.70
int_to_floatFunction · 0.70
vint4Class · 0.70
clampFunction · 0.70

Tested by 1

TESTFunction · 0.40