move cutest_bfe data to first set

This commit is contained in:
2024-01-13 10:59:24 +01:00
parent a8a82a3121
commit 32fd923192
2 changed files with 106 additions and 86 deletions

View File

@@ -18,13 +18,15 @@
if [[ ! -v _BRLIB_ENV_ ]]; then
export _BRLIB_ENV_=1 BRLIB_ROOT LD_LIBRARY_PATH
BRLIB_SCRIPTDIR=$(realpath -L "$(dirname "${BASH_SOURCE[0]}")")
BRLIB_ROOT=$(realpath -L "$(dirname "${BASH_SOURCE[0]}")/..")
BRLIB_LIBDIR="$BRLIB_ROOT/lib"
BRLIB_SCRIPTDIR="$BRLIB_ROOT/scripts"
BRLIB_BINDIR="$BRLIB_ROOT/bin"
LD_LIBRARY_PATH="${BRLIB_LIBDIR}${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
PATH="$PATH:$BRLIB_BINDIR:$BRLIB_SCRIPTDIR"
BRLIB_LIBDIR="$BRLIB_ROOT/lib"
LD_LIBRARY_PATH="${BRLIB_LIBDIR}${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
#printf "R=%s L=%s LD=%s\n" "$BRLIB_ROOT" "$BRLIB_DIR" "$LD_LIBRARY_PATH"
unset BRLIB_LIBDIR BRLIB_BINDIR BRLIB_SCRIPTDIR
unset BRLIB_SCRIPTDIR BRLIB_BINDIR BRLIB_LIBDIR
printf "brlib environment complete.\n"
fi

View File

@@ -27,13 +27,27 @@ static const struct test32_1 {
int ffz;
int fls;
int ilog2;
struct {
int size;
uchar bfe[32];
};
} test32_1[] = {
{ 0x00000000, 0, 32, 32, 0, 1, 0, 0 }, /* C undefined for some values */
{ 0xffffffff, 32, 0, 0, 1, 0, 32, 31 },
{ 0x00000001, 1, 0, 31, 1, 2, 1, 0 },
{ 0x80000000, 1, 31, 0, 32, 1, 32, 31 },
{ 0x71800718, 10, 3, 1, 4, 1, 31, 30 },
{ 0x07eeeef7, 22, 0, 5, 1, 4, 27, 26 },
{ 0x00000000, 0, 32, 32, 0, 1, 0, 0, /* sometimes undefined */
{ 0, { 0 } } },
{ 0xffffffff, 32, 0, 0, 1, 0, 32, 31,
{ 32, { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31 } } },
{ 0x00000001, 1, 0, 31, 1, 2, 1, 0,
{ 1, { 0 } } },
{ 0x80000000, 1, 31, 0, 32, 1, 32, 31,
{ 1, { 31 } } },
{ 0x71800718, 10, 3, 1, 4, 1, 31, 30,
/* 0111 0001 1000 0000 0000 0111 0001 1000 */
{ 10, { 3, 4, 8, 9, 10, 23, 24, 28, 29, 30 } } },
{ 0x07eeeef7, 22, 0, 5, 1, 4, 27, 26,
/* 0000 0111 1110 1110 1110 1110 0111 1111*/
{ 22, { 0, 1, 2, 4, 5, 6, 7, 9, 10, 11, 13,
14, 15, 17, 18, 19, 21, 22, 23, 24, 25, 26 } } },
};
static const struct test64_1 {
@@ -45,13 +59,32 @@ static const struct test64_1 {
int ffz;
int fls;
int ilog2;
struct {
int size;
uchar bfe[64];
};
} test64_1[] = {
{ 0x0000000000000000, 0, 64, 64, 0, 1, 0, 0 }, /* undefined for some values */
{ 0xffffffffffffffff, 64, 0, 0, 1, 0, 64, 63 },
{ 0x0000000100000001, 2, 0, 31, 1, 2, 33, 32 },
{ 0x8000000000000000, 1, 63, 0, 64, 1, 64, 63 },
{ 0x7180071871800718, 20, 3, 1, 4, 1, 63, 62 },
{ 0x07eeeef707eeeef7, 44, 0, 5, 1, 4, 59, 58 },
{ 0x0000000000000000, 0, 64, 64, 0, 1, 0, 0, /* sometimes undefined */
{ 0, { 0 } } },
{ 0xffffffffffffffff, 64, 0, 0, 1, 0, 64, 63,
{ 64, { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63 } } },
{ 0x0000000100000001, 2, 0, 31, 1, 2, 33, 32,
{ 2, { 0, 32 } } },
{ 0x8000000000000000, 1, 63, 0, 64, 1, 64, 63,
{ 1, { 63 } } },
{ 0x7180071871800718, 20, 3, 1, 4, 1, 63, 62,
/* 2 x 0111 0001 1000 0000 0000 0111 0001 1000 */
{ 20, { 3, 4, 8, 9, 10, 23, 24, 28, 29, 30,
35, 36, 40, 41, 42, 55, 56, 60, 61, 62 } } },
{ 0x07eeeef707eeeef7, 44, 0, 5, 1, 4, 59, 58 ,
/* 2 x 0000 0111 1110 1110 1110 1110 0111 1111*/
{ 44, { 0, 1, 2, 4, 5, 6, 7, 9, 10, 11, 13,
14, 15, 17, 18, 19, 21, 22, 23, 24, 25, 26,
32, 33, 34, 36, 37, 38, 39, 41, 42, 43, 45,
46, 47, 49, 50, 51, 53, 54, 55, 56, 57, 58 } } },
};
static void cutest_popcount(CuTest *tc)
@@ -158,6 +191,54 @@ static void cutest_ilog(CuTest *tc)
}
}
static void cutest_bfe(CuTest *tc)
{
char s[64];
for (uint i = 0; i < ARRAY_SIZE(test32_1); ++i) {
u32 tmp;
int cur, nb = 0;
char bfe_ffs[32];
/* create bit_for_each32_ffs values */
for (int j = 0; j < test32_1[i].size; ++j)
bfe_ffs[j] = test32_1[i].bfe[j] + 1;
bit_for_each32(cur, tmp, test32_1[i].t32) {
s[nb++] = cur;
}
CuAssertIntEquals(tc, test32_1[i].size, nb);
CuAssertMemEquals(tc, test32_1[i].bfe, s, test32_1[i].size);
nb = 0;
bit_for_each32_ffs(cur, tmp, test32_1[i].t32) {
s[nb++] = cur;
}
CuAssertMemEquals(tc, bfe_ffs, s, test32_1[i].size);
}
for (uint i = 0; i < ARRAY_SIZE(test64_1); ++i) {
u64 tmp;
int cur, nb = 0;
char bfe_ffs[64];
/* create bit_for_each64_ffs values */
for (int j = 0; j < test64_1[i].size; ++j)
bfe_ffs[j] = test64_1[i].bfe[j] + 1;
bit_for_each64(cur, tmp, test64_1[i].t64) {
s[nb++] = cur;
}
//printf("\n64 nb=%d size=%d\n", nb, test64_1[i].size);
CuAssertIntEquals(tc, test64_1[i].size, nb);
CuAssertMemEquals(tc, test64_1[i].bfe, s, test64_1[i].size);
nb = 0;
bit_for_each64_ffs(cur, tmp, test64_1[i].t64) {
s[nb++] = cur;
}
CuAssertMemEquals(tc, bfe_ffs, s, test64_1[i].size);
}
}
struct test32_2 {
u32 t32; /* input */
u32 arg;
@@ -189,28 +270,13 @@ struct test64_2 {
u32 arg;
u64 rol;
u64 ror;
struct {
int size;
uchar bfe[64];
};
} test64_2[] = {
{ 0x0000000000000000, 0, 0, 0,
{ 0, { 0 } } },
{ 0x0000000000000000, 1, 0, 0,
{ 0, { 0 } } },
{ 0x1000000110000001, 2, 0x4000000440000004, 0x4400000044000000,
{ 4, { 0, 28, 32, 60 } } },
{ 0x8000000880000008, 3, 0x0000004400000044, 0x1000000110000001,
{ 4, { 3, 31, 35, 63 } } },
{ 0x7180071871800718, 8, 0x8007187180071871, 0x1871800718718007,
{ 20, { 3, 4, 8, 9, 10, 23, 24, 28, 29, 30,
35, 36, 40, 41, 42, 55, 56, 60, 61, 62 } } },
{ 0x07eeeef707eeeef7, 4, 0x7eeeef707eeeef70, 0x707eeeef707eeeef,
{ 44, { 0, 1, 2, 4, 5, 6, 7, 9, 10, 11, 13, 14, 15, 17, 18, 19,
21, 22, 23, 24, 25, 26,
32, 33, 34, 36, 37, 38, 39, 41, 42, 43, 45, 46, 47, 49, 50, 51,
53, 54, 55, 56, 57, 58 } } },
{ 0x0000000000000000, 0, 0, 0 },
{ 0x0000000000000000, 1, 0, 0 },
{ 0x1000000110000001, 2, 0x4000000440000004, 0x4400000044000000 },
{ 0x8000000880000008, 3, 0x0000004400000044, 0x1000000110000001 },
{ 0x7180071871800718, 8, 0x8007187180071871, 0x1871800718718007 },
{ 0x07eeeef707eeeef7, 4, 0x7eeeef707eeeef70, 0x707eeeef707eeeef }
};
static void cutest_rol(CuTest *tc)
@@ -245,54 +311,6 @@ static void cutest_ror(CuTest *tc)
}
}
static void cutest_bfe(CuTest *tc)
{
char s[64];
for (uint i = 0; i < ARRAY_SIZE(test32_2); ++i) {
u32 tmp;
int cur, nb = 0;
char bfe_ffs[32];
/* create bit_for_each32_ffs values */
for (int j = 0; j < test32_2[i].size; ++j)
bfe_ffs[j] = test32_2[i].bfe[j] + 1;
bit_for_each32(cur, tmp, test32_2[i].t32) {
s[nb++] = cur;
}
CuAssertIntEquals(tc, test32_2[i].size, nb);
CuAssertMemEquals(tc, test32_2[i].bfe, s, test32_2[i].size);
nb = 0;
bit_for_each32_ffs(cur, tmp, test32_2[i].t32) {
s[nb++] = cur;
}
CuAssertMemEquals(tc, bfe_ffs, s, test32_2[i].size);
}
for (uint i = 0; i < ARRAY_SIZE(test64_2); ++i) {
u64 tmp;
int cur, nb = 0;
char bfe_ffs[64];
/* create bit_for_each64_ffs values */
for (int j = 0; j < test64_2[i].size; ++j)
bfe_ffs[j] = test64_2[i].bfe[j] + 1;
bit_for_each64(cur, tmp, test64_2[i].t64) {
s[nb++] = cur;
}
//printf("\n64 nb=%d size=%d\n", nb, test64_2[i].size);
CuAssertIntEquals(tc, test64_2[i].size, nb);
CuAssertMemEquals(tc, test64_2[i].bfe, s, test64_2[i].size);
nb = 0;
bit_for_each64_ffs(cur, tmp, test64_2[i].t64) {
s[nb++] = cur;
}
CuAssertMemEquals(tc, bfe_ffs, s, test64_2[i].size);
}
}
static CuSuite *bitops_GetSuite()
{
CuSuite* suite = CuSuiteNew();
@@ -303,10 +321,10 @@ static CuSuite *bitops_GetSuite()
SUITE_ADD_TEST(suite, cutest_ffz);
SUITE_ADD_TEST(suite, cutest_fls);
SUITE_ADD_TEST(suite, cutest_ilog);
SUITE_ADD_TEST(suite, cutest_bfe);
SUITE_ADD_TEST(suite, cutest_rol);
SUITE_ADD_TEST(suite, cutest_ror);
SUITE_ADD_TEST(suite, cutest_bfe);
return suite;
}