2015-04-13 16:45:56 +10:00
|
|
|
#include "bitwise.hpp"
|
|
|
|
#include "tap.hpp"
|
2013-03-11 20:41:19 +11:00
|
|
|
|
2014-09-01 16:23:46 +10:00
|
|
|
|
2015-04-13 16:45:56 +10:00
|
|
|
//-----------------------------------------------------------------------------
|
2014-09-01 16:23:46 +10:00
|
|
|
static void
|
2015-04-13 16:45:56 +10:00
|
|
|
test_rotate (util::TAP::logger &tap)
|
|
|
|
{
|
|
|
|
tap.expect_eq (rotatel (uint8_t (0x0F), 0), 0x0F);
|
|
|
|
tap.expect_eq (rotatel (uint8_t (0x0F), 4), 0xF0);
|
|
|
|
tap.expect_eq (rotatel (uint8_t (0xF0), 4), 0x0F);
|
|
|
|
tap.expect_eq (rotatel (uint8_t (0x0F), 8), 0x0F);
|
|
|
|
|
|
|
|
tap.expect_eq (rotater (uint8_t (0x0F), 0), 0x0F);
|
|
|
|
tap.expect_eq (rotater (uint8_t (0x0F), 4), 0xF0);
|
|
|
|
tap.expect_eq (rotater (uint8_t (0xF0), 4), 0x0F);
|
|
|
|
tap.expect_eq (rotater (uint8_t (0x0F), 8), 0x0F);
|
|
|
|
|
|
|
|
tap.expect_eq (rotatel (uint16_t (0xABCD), 0), 0xABCD);
|
|
|
|
tap.expect_eq (rotatel (uint16_t (0xABCD), 4), 0xBCDA);
|
|
|
|
tap.expect_eq (rotatel (uint16_t (0xABCD), 8), 0xCDAB);
|
|
|
|
tap.expect_eq (rotatel (uint16_t (0xABCD), 12), 0xDABC);
|
|
|
|
tap.expect_eq (rotatel (uint16_t (0xABCD), 16), 0xABCD);
|
|
|
|
|
|
|
|
tap.expect_eq (rotater (uint16_t (0xABCD), 0), 0xABCD);
|
|
|
|
tap.expect_eq (rotater (uint16_t (0xABCD), 4), 0xDABC);
|
|
|
|
tap.expect_eq (rotater (uint16_t (0xABCD), 8), 0xCDAB);
|
|
|
|
tap.expect_eq (rotater (uint16_t (0xABCD), 12), 0xBCDA);
|
|
|
|
tap.expect_eq (rotater (uint16_t (0xABCD), 16), 0xABCD);
|
|
|
|
|
|
|
|
tap.expect_eq (rotatel (uint32_t (0x12345670), 12), 0x45670123);
|
|
|
|
tap.expect_eq (rotater (uint32_t (0x12345670), 12), 0x67012345);
|
|
|
|
|
|
|
|
tap.expect_eq (rotatel (uint64_t (0x1234567890ABCDEF), 12), 0x4567890ABCDEF123);
|
|
|
|
tap.expect_eq (rotater (uint64_t (0x1234567890ABCDEF), 12), 0xDEF1234567890ABC);
|
2014-09-01 16:23:46 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-04-13 16:45:56 +10:00
|
|
|
//-----------------------------------------------------------------------------
|
2014-09-01 16:23:46 +10:00
|
|
|
void
|
2015-04-13 16:45:56 +10:00
|
|
|
test_reverse (util::TAP::logger &tap)
|
|
|
|
{
|
|
|
|
size_t matches = 0;
|
2014-09-01 16:23:46 +10:00
|
|
|
for (unsigned i = 0; i < 256; ++i) {
|
|
|
|
auto first = reverse<uint8_t> (i);
|
|
|
|
auto last = reverse<uint8_t> (first);
|
2015-04-13 16:45:56 +10:00
|
|
|
if (last == i)
|
|
|
|
matches++;
|
2014-09-01 16:23:46 +10:00
|
|
|
}
|
2015-04-13 16:45:56 +10:00
|
|
|
|
|
|
|
tap.expect_eq (matches, 256, "exhaustive 8 bit reverse");
|
2014-09-01 16:23:46 +10:00
|
|
|
}
|
|
|
|
|
2015-04-13 16:45:56 +10:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2014-09-01 16:23:46 +10:00
|
|
|
int
|
2015-04-13 16:45:56 +10:00
|
|
|
main (int, char**)
|
|
|
|
{
|
|
|
|
util::TAP::logger tap;
|
|
|
|
|
|
|
|
test_rotate (tap);
|
|
|
|
test_reverse (tap);
|
2013-03-11 20:41:19 +11:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|