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

Function log2

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

* @brief Compute an approximate log2(x) for each lane in the vector. * * Based on 5th degree minimax polynomials, ported from this blog * https://jrfonseca.blogspot.com/2008/09/fast-sse2-pow-tables-or-polynomials.html */

Source from the content-addressed store, hash-verified

390 * https://jrfonseca.blogspot.com/2008/09/fast-sse2-pow-tables-or-polynomials.html
391 */
392static ASTCENC_SIMD_INLINE vfloat4 log2(vfloat4 x)
393{
394 vint4 exp(0x7F800000);
395 vint4 mant(0x007FFFFF);
396 vint4 one(0x3F800000);
397
398 vint4 i = float_as_int(x);
399
400 vfloat4 e = int_to_float(lsr<23>(i & exp) - 127);
401
402 vfloat4 m = int_as_float((i & mant) | one);
403
404 // Polynomial fit of log2(x)/(x - 1), for x in range [1, 2)
405 vfloat4 p = POLY4(m,
406 2.8882704548164776201f,
407 -2.52074962577807006663f,
408 1.48116647521213171641f,
409 -0.465725644288844778798f,
410 0.0596515482674574969533f);
411
412 // Increases the polynomial degree, but ensures that log2(1) == 0
413 p = p * (m - 1.0f);
414
415 return p + e;
416}
417
418/**
419 * @brief Compute an approximate pow(x, y) for each lane in the vector.

Callers 2

powFunction · 0.70
compute_error_metricsFunction · 0.70

Calls 3

float_as_intFunction · 0.70
int_to_floatFunction · 0.70
int_as_floatFunction · 0.70

Tested by

no test coverage detected