MCPcopy Create free account
hub / github.com/bulletphysics/bullet3 / compare

Method compare

src/Bullet3Geometry/b3ConvexHullComputer.cpp:901–944  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

899}
900
901int b3ConvexHullInternal::Rational64::compare(const Rational64& b) const
902{
903 if (sign != b.sign)
904 {
905 return sign - b.sign;
906 }
907 else if (sign == 0)
908 {
909 return 0;
910 }
911
912 // return (numerator * b.denominator > b.numerator * denominator) ? sign : (numerator * b.denominator < b.numerator * denominator) ? -sign : 0;
913
914#ifdef USE_X86_64_ASM
915
916 int result;
917 btInt64_t tmp;
918 btInt64_t dummy;
919 __asm__(
920 "mulq %[bn]\n\t"
921 "movq %%rax, %[tmp]\n\t"
922 "movq %%rdx, %%rbx\n\t"
923 "movq %[tn], %%rax\n\t"
924 "mulq %[bd]\n\t"
925 "subq %[tmp], %%rax\n\t"
926 "sbbq %%rbx, %%rdx\n\t" // rdx:rax contains 128-bit-difference "numerator*b.denominator - b.numerator*denominator"
927 "setnsb %%bh\n\t" // bh=1 if difference is non-negative, bh=0 otherwise
928 "orq %%rdx, %%rax\n\t"
929 "setnzb %%bl\n\t" // bl=1 if difference if non-zero, bl=0 if it is zero
930 "decb %%bh\n\t" // now bx=0x0000 if difference is zero, 0xff01 if it is negative, 0x0001 if it is positive (i.e., same sign as difference)
931 "shll $16, %%ebx\n\t" // ebx has same sign as difference
932 : "=&b"(result), [tmp] "=&r"(tmp), "=a"(dummy)
933 : "a"(denominator), [bn] "g"(b.numerator), [tn] "g"(numerator), [bd] "g"(b.denominator)
934 : "%rdx", "cc");
935 return result ? result ^ sign // if sign is +1, only bit 0 of result is inverted, which does not change the sign of result (and cannot result in zero)
936 // if sign is -1, all bits of result are inverted, which changes the sign of result (and again cannot result in zero)
937 : 0;
938
939#else
940
941 return sign * Int128::mul(m_numerator, b.m_denominator).ucmp(Int128::mul(m_denominator, b.m_numerator));
942
943#endif
944}
945
946int b3ConvexHullInternal::Rational128::compare(const Rational128& b) const
947{

Callers 4

findMaxAngleMethod · 0.45
mergeMethod · 0.45
shiftFaceMethod · 0.45

Calls 2

mulFunction · 0.50
ucmpMethod · 0.45

Tested by

no test coverage detected