|
|
|
#include <ck_pr.h>
|
ck_cc: add a disable builtin flag for the FreeBSD kernel.
This primarily affects the FreeBSD kernel, where the popcount builtin
can be problematic (relies on compiler-provided libraries). See the
history of __POPCNT__ for details [1].
- A new flag, CK_MD_CC_BUILTIN_DISABLE, can be set to indicate that CK
should not rely on compiler builtins when possible.
- ck_cc_clz has been removed, it was unused.
- ck_internal_bsf has been removed, it was duplicate of ck_cc_ffs but broken,
replaced in favor of ck_cc_ffs. Previous consumers were using the bsf
instruction, eitherway.
- ck_{rhs,hs,ht} have been updated to use ck_cc_ffs*.
If FreeBSD requires the builtins for performance reasons, we will lift the
appropriate detection into ck_md (at least, bt* bs* family of functions don't
have the same problems on most targets unlike popcount).
1: https://lists.freebsd.org/pipermail/svn-src-head/2015-March/069663.html
7 years ago
|
|
|
#include <limits.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "../../common.h"
|
|
|
|
|
|
|
|
int
|
|
|
|
main(void)
|
|
|
|
{
|
|
|
|
unsigned int x;
|
|
|
|
|
ck_cc: add a disable builtin flag for the FreeBSD kernel.
This primarily affects the FreeBSD kernel, where the popcount builtin
can be problematic (relies on compiler-provided libraries). See the
history of __POPCNT__ for details [1].
- A new flag, CK_MD_CC_BUILTIN_DISABLE, can be set to indicate that CK
should not rely on compiler builtins when possible.
- ck_cc_clz has been removed, it was unused.
- ck_internal_bsf has been removed, it was duplicate of ck_cc_ffs but broken,
replaced in favor of ck_cc_ffs. Previous consumers were using the bsf
instruction, eitherway.
- ck_{rhs,hs,ht} have been updated to use ck_cc_ffs*.
If FreeBSD requires the builtins for performance reasons, we will lift the
appropriate detection into ck_md (at least, bt* bs* family of functions don't
have the same problems on most targets unlike popcount).
1: https://lists.freebsd.org/pipermail/svn-src-head/2015-March/069663.html
7 years ago
|
|
|
ck_pr_store_uint(&x, 0x10110);
|
|
|
|
|
|
|
|
if (ck_cc_ffs(0) != 0)
|
|
|
|
ck_error("ffs(0) = %d\n", ck_cc_ffs(0));
|
|
|
|
if (ck_cc_ffs(4) != 3)
|
|
|
|
ck_error("ffs(4) = %d\n", ck_cc_ffs(4));
|
|
|
|
if (ck_cc_ffs(UINT_MAX) != 1)
|
|
|
|
ck_error("ffs(UINT_MAX) = %d\n", ck_cc_ffs(UINT_MAX));
|
|
|
|
if (ck_cc_ffs(x) != 5)
|
|
|
|
ck_error("ffs(%u) = %d\n", x, ck_cc_ffs(x));
|
|
|
|
|
|
|
|
if (ck_cc_ffs(x) != ck_cc_ffsl(x) ||
|
|
|
|
ck_cc_ffsl(x) != ck_cc_ffsll(x) ||
|
|
|
|
ck_cc_ffs(x) != ck_cc_ffsll(x)) {
|
|
|
|
ck_error(" ffs = %d, ffsl = %d, ffsll = %d\n",
|
|
|
|
ck_cc_ffs(x), ck_cc_ffsl(x), ck_cc_ffsll(x));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ck_cc_ctz(x) != 4)
|
|
|
|
ck_error("ctz = %d\n", ck_cc_ctz(x));
|
|
|
|
|
|
|
|
if (ck_cc_popcount(x) != 3)
|
|
|
|
ck_error("popcount = %d\n", ck_cc_popcount(x));
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|