* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#include <babeltrace/bitfield-internal.h>
+#include "compat/bitfield.h"
#include <time.h>
#include <stdlib.h>
#include <stdio.h>
unsigned long long readval;
unsigned int s, l;
+ /* The number of bits needed to represent 0 is 0. */
nrbits_ui = fls_u32(src_ui);
/* Write from unsigned integer src input. */
for (s = 0; s < CHAR_BIT * TEST_LEN; s++) {
- for (l = nrbits_ui; l < (CHAR_BIT * TEST_LEN) - s; l++) {
+ for (l = nrbits_ui; l <= (CHAR_BIT * TEST_LEN) - s; l++) {
init_byte_array(target.c, TEST_LEN, 0xFF);
bt_bitfield_write(target.c, unsigned char, s, l, src_ui);
bt_bitfield_read(target.c, unsigned char, s, l, &readval);
}
pass(UNSIGNED_INT_WRITE_TEST_DESC_FMT_STR, src_ui);
+ /* The number of bits needed to represent 0 is 0. */
nrbits_ull = fls_u64(src_ull);
/* Write from unsigned long long src input. */
for (s = 0; s < CHAR_BIT * TEST_LEN; s++) {
- for (l = nrbits_ull; l < (CHAR_BIT * TEST_LEN) - s; l++) {
+ for (l = nrbits_ull; l <= (CHAR_BIT * TEST_LEN) - s; l++) {
init_byte_array(target.c, TEST_LEN, 0xFF);
bt_bitfield_write(target.c, unsigned char, s, l, src_ull);
bt_bitfield_read(target.c, unsigned char, s, l, &readval);
unsigned long long readval_ull;
unsigned int s, l;
+ /* The number of bits needed to represent 0 is 0. */
nrbits_ui = fls_u32(src_ui);
/* Read to unsigned integer readval output. */
for (s = 0; s < CHAR_BIT * TEST_LEN; s++) {
- for (l = nrbits_ui; l < (CHAR_BIT * TEST_LEN) - s; l++) {
+ for (l = nrbits_ui; l <= (CHAR_BIT * TEST_LEN) - s; l++) {
init_byte_array(target.c, TEST_LEN, 0xFF);
bt_bitfield_write(target.c, unsigned char, s, l, src_ui);
bt_bitfield_read(target.c, unsigned char, s, l, &readval_ui);
}
pass(UNSIGNED_INT_READ_TEST_DESC_FMT_STR, src_ui);
+ /* The number of bits needed to represent 0 is 0. */
nrbits_ull = fls_u64(src_ull);
/* Read to unsigned long long readval output. */
for (s = 0; s < CHAR_BIT * TEST_LEN; s++) {
- for (l = nrbits_ull; l < (CHAR_BIT * TEST_LEN) - s; l++) {
+ for (l = nrbits_ull; l <= (CHAR_BIT * TEST_LEN) - s; l++) {
init_byte_array(target.c, TEST_LEN, 0xFF);
bt_bitfield_write(target.c, unsigned char, s, l, src_ull);
bt_bitfield_read(target.c, unsigned char, s, l, &readval_ull);
void run_test_signed_write(int src_i, long long src_ll)
{
- int nrbits_i, nrbits_ll;
+ unsigned int nrbits_i, nrbits_ll;
union {
signed char c[TEST_LEN];
short s[TEST_LEN/sizeof(short)];
long long readval;
unsigned int s, l;
- if (src_i & 0x80000000U)
+ if (!src_i)
+ nrbits_i = 0; /* The number of bits needed to represent 0 is 0. */
+ else if (src_i & 0x80000000U)
nrbits_i = fls_u32(~src_i) + 1; /* Find least significant bit conveying sign */
else
nrbits_i = fls_u32(src_i) + 1; /* Keep sign at 0 */
/* Write from signed integer src input. */
for (s = 0; s < CHAR_BIT * TEST_LEN; s++) {
- for (l = nrbits_i; l < (CHAR_BIT * TEST_LEN) - s; l++) {
+ for (l = nrbits_i; l <= (CHAR_BIT * TEST_LEN) - s; l++) {
init_byte_array(target.c, TEST_LEN, 0x0);
bt_bitfield_write(target.c, signed char, s, l, src_i);
bt_bitfield_read(target.c, signed char, s, l, &readval);
}
pass(SIGNED_INT_WRITE_TEST_DESC_FMT_STR, src_i);
- if (src_ll & 0x8000000000000000ULL)
+ if (!src_ll)
+ nrbits_ll = 0; /* The number of bits needed to represent 0 is 0. */
+ else if (src_ll & 0x8000000000000000ULL)
nrbits_ll = fls_u64(~src_ll) + 1; /* Find least significant bit conveying sign */
else
nrbits_ll = fls_u64(src_ll) + 1; /* Keep sign at 0 */
/* Write from signed long long src input. */
for (s = 0; s < CHAR_BIT * TEST_LEN; s++) {
- for (l = nrbits_ll; l < (CHAR_BIT * TEST_LEN) - s; l++) {
+ for (l = nrbits_ll; l <= (CHAR_BIT * TEST_LEN) - s; l++) {
init_byte_array(target.c, TEST_LEN, 0x0);
bt_bitfield_write(target.c, signed char, s, l, src_ll);
bt_bitfield_read(target.c, signed char, s, l, &readval);
void run_test_signed_read(int src_i, long long src_ll)
{
- int nrbits_i, nrbits_ll, readval_i;
+ unsigned int nrbits_i, nrbits_ll;
+ int readval_i;
union {
unsigned char c[TEST_LEN];
unsigned short s[TEST_LEN/sizeof(unsigned short)];
long long readval_ll;
unsigned int s, l;
- if (src_i & 0x80000000U)
+ if (!src_i)
+ nrbits_i = 0; /* The number of bits needed to represent 0 is 0. */
+ else if (src_i & 0x80000000U)
nrbits_i = fls_u32(~src_i) + 1; /* Find least significant bit conveying sign */
else
nrbits_i = fls_u32(src_i) + 1; /* Keep sign at 0 */
/* Read to signed integer readval output. */
for (s = 0; s < CHAR_BIT * TEST_LEN; s++) {
- for (l = nrbits_i; l < (CHAR_BIT * TEST_LEN) - s; l++) {
+ for (l = nrbits_i; l <= (CHAR_BIT * TEST_LEN) - s; l++) {
init_byte_array(target.c, TEST_LEN, 0xFF);
bt_bitfield_write(target.c, signed char, s, l, src_i);
bt_bitfield_read(target.c, signed char, s, l, &readval_i);
}
pass(SIGNED_INT_READ_TEST_DESC_FMT_STR, src_i);
+ if (!src_ll)
+ nrbits_ll = 0; /* The number of bits needed to represent 0 is 0. */
if (src_ll & 0x8000000000000000ULL)
nrbits_ll = fls_u64(~src_ll) + 1; /* Find least significant bit conveying sign */
else
/* Read to signed long long readval output. */
for (s = 0; s < CHAR_BIT * TEST_LEN; s++) {
- for (l = nrbits_ll; l < (CHAR_BIT * TEST_LEN) - s; l++) {
+ for (l = nrbits_ll; l <= (CHAR_BIT * TEST_LEN) - s; l++) {
init_byte_array(target.c, TEST_LEN, 0xFF);
bt_bitfield_write(target.c, signed char, s, l, src_ll);
bt_bitfield_read(target.c, signed char, s, l, &readval_ll);