MCPcopy Create free account
hub / github.com/defold/defold / count_leading_zeros_alt

Method count_leading_zeros_alt

engine/dlib/src/basis/encoder/cppspmd_math.h:609–634  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

607}
608
609CPPSPMD_FORCE_INLINE vint spmd_kernel::count_leading_zeros_alt(vint x)
610{
611 //x <= 0x0000ffff
612 vbool c0 = (x & 0xFFFF0000) == 0;
613 vint n0 = spmd_ternaryi(c0, 16, 0);
614 vint x0 = spmd_ternaryi(c0, VINT_SHIFT_LEFT(x, 16), x);
615
616 //x <= 0x00ffffff
617 vbool c1 = (x0 & 0xFF000000) == 0;
618 vint n1 = spmd_ternaryi(c1, n0 + 8, n0);
619 vint x1 = spmd_ternaryi(c1, VINT_SHIFT_LEFT(x0, 8), x0);
620
621 //x <= 0x0fffffff
622 vbool c2 = (x1 & 0xF0000000) == 0;
623 vint n2 = spmd_ternaryi(c2, n1 + 4, n1);
624 vint x2 = spmd_ternaryi(c2, VINT_SHIFT_LEFT(x1, 4), x1);
625
626 // x <= 0x3fffffff
627 vbool c3 = (x2 & 0xC0000000) == 0;
628 vint n3 = spmd_ternaryi(c3, n2 + 2, n2);
629 vint x3 = spmd_ternaryi(c3, VINT_SHIFT_LEFT(x2, 2), x2);
630
631 // x <= 0x7fffffff
632 vbool c4 = (x3 & 0x80000000) == 0;
633 return spmd_ternaryi(c4, n3 + 1, n3);
634}
635
636CPPSPMD_FORCE_INLINE vint spmd_kernel::count_trailing_zeros(vint x)
637{

Callers

nothing calls this directly

Calls 1

spmd_ternaryiFunction · 0.85

Tested by

no test coverage detected