made search strategy switchable

between cmov and branch
and use a simple heuristic based on wlog to select between them.

note: performance is not good on clang (yet)
This commit is contained in:
Yann Collet
2024-10-08 13:52:56 -07:00
parent 2cc600bab2
commit 186b132495
2 changed files with 47 additions and 37 deletions
+6 -6
View File
@@ -558,21 +558,21 @@ MEM_STATIC int ZSTD_cParam_withinBounds(ZSTD_cParameter cParam, int value)
}
/* ZSTD_selectAddr:
* @return a >= b ? trueAddr : falseAddr,
* @return index >= lowLimit ? candidate : backup,
* tries to force branchless codegen. */
MEM_STATIC const BYTE*
ZSTD_selectAddr(U32 index, U32 lowLimit, const BYTE* trueAddr, const BYTE* falseAddr)
ZSTD_selectAddr(U32 index, U32 lowLimit, const BYTE* candidate, const BYTE* backup)
{
#if defined(__GNUC__) && defined(__x86_64__)
__asm__ (
"cmp %1, %2\n"
"cmova %3, %0\n"
: "+r"(trueAddr)
: "r"(index), "r"(lowLimit), "r"(falseAddr)
: "+r"(candidate)
: "r"(index), "r"(lowLimit), "r"(backup)
);
return trueAddr;
return candidate;
#else
return a >= b ? trueAddr : falseAddr;
return index >= lowLimit ? candidate : backup;
#endif
}