Replace padlength tables with inline functions from misc.h

Adds new function padding_for_int32() and uses existing pad_to_int32()
depending on required results.

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Reviewed-by: Keith Packard <keithp@keithp.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Tested-by: Daniel Stone <daniel@fooishbar.org>
This commit is contained in:
Alan Coopersmith
2012-07-09 19:12:44 -07:00
committed by Keith Packard
parent 2b1c1300cc
commit ad4092cf7d
5 changed files with 50 additions and 13 deletions

View File

@@ -964,6 +964,19 @@ test_pad_to_int32(int i)
assert(expected_bytes == pad_to_int32(i));
}
static void
test_padding_for_int32(int i)
{
static const int padlength[4] = { 0, 3, 2, 1 };
int expected_bytes = (((i + 3) / 4) * 4) - i;
assert(padding_for_int32(i) >= 0);
assert(padding_for_int32(i) <= 3);
assert(padding_for_int32(i) == expected_bytes);
assert(padding_for_int32(i) == padlength[i & 3]);
assert((padding_for_int32(i) + i) == pad_to_int32(i));
}
static void
include_byte_padding_macros(void)
{
@@ -996,12 +1009,12 @@ include_byte_padding_macros(void)
test_bytes_to_int32(INT_MAX - 4);
test_bytes_to_int32(INT_MAX - 3);
printf("Testing pad_to_int32\n");
printf("Testing pad_to_int32()\n");
test_pad_to_int32(0);
test_pad_to_int32(0);
test_pad_to_int32(1);
test_pad_to_int32(2);
test_pad_to_int32(3);
test_pad_to_int32(7);
test_pad_to_int32(8);
test_pad_to_int32(0xFF);
@@ -1012,6 +1025,23 @@ include_byte_padding_macros(void)
test_pad_to_int32(0x1000000);
test_pad_to_int32(INT_MAX - 4);
test_pad_to_int32(INT_MAX - 3);
printf("Testing padding_for_int32()\n");
test_padding_for_int32(0);
test_padding_for_int32(1);
test_padding_for_int32(2);
test_padding_for_int32(3);
test_padding_for_int32(7);
test_padding_for_int32(8);
test_padding_for_int32(0xFF);
test_padding_for_int32(0x100);
test_padding_for_int32(0xFFFF);
test_padding_for_int32(0x10000);
test_padding_for_int32(0xFFFFFF);
test_padding_for_int32(0x1000000);
test_padding_for_int32(INT_MAX - 4);
test_padding_for_int32(INT_MAX - 3);
}
static void