|
|
|
@ -121,71 +121,3 @@ CYBOZU_TEST_AUTO(getRandVal) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
CYBOZU_TEST_AUTO(shiftLeftOr) |
|
|
|
|
{ |
|
|
|
|
const struct { |
|
|
|
|
uint32_t x[4]; |
|
|
|
|
size_t n; |
|
|
|
|
size_t shift; |
|
|
|
|
uint32_t y; |
|
|
|
|
uint32_t z[4]; |
|
|
|
|
uint32_t ret; |
|
|
|
|
} tbl[] = { |
|
|
|
|
{ { 0x12345678, 0, 0, 0 }, 1, 0, 0, { 0x12345678, 0, 0, 0 }, 0 }, |
|
|
|
|
{ { 0x12345678, 0, 0, 0 }, 1, 1, 0, { 0x2468acf0, 0, 0, 0 }, 0 }, |
|
|
|
|
{ { 0xf2345678, 0, 0, 0 }, 1, 1, 5, { 0xe468acf5, 0, 0, 0 }, 1 }, |
|
|
|
|
{ { 0x12345678, 0x9abcdef0, 0x11112222, 0xffccaaee }, 4, 19, 0x1234, { 0xb3c01234, 0xf78091a2, 0x1114d5e6, 0x57708889 }, 0x7fe65 }, |
|
|
|
|
}; |
|
|
|
|
for (size_t i = 0; i < CYBOZU_NUM_OF_ARRAY(tbl); i++) { |
|
|
|
|
uint32_t z[4]; |
|
|
|
|
uint32_t ret = mcl::fp::shiftLeftOr(z, tbl[i].x, tbl[i].n, tbl[i].shift, tbl[i].y); |
|
|
|
|
CYBOZU_TEST_EQUAL_ARRAY(z, tbl[i].z, tbl[i].n); |
|
|
|
|
CYBOZU_TEST_EQUAL(ret, tbl[i].ret); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
CYBOZU_TEST_AUTO(shiftRight) |
|
|
|
|
{ |
|
|
|
|
const struct { |
|
|
|
|
uint32_t x[4]; |
|
|
|
|
size_t n; |
|
|
|
|
size_t shift; |
|
|
|
|
uint32_t z[4]; |
|
|
|
|
} tbl[] = { |
|
|
|
|
{ { 0x12345678, 0, 0, 0 }, 4, 0, { 0x12345678, 0, 0, 0 } }, |
|
|
|
|
{ { 0x12345678, 0xaaaabbbb, 0xffeebbcc, 0xfeba9874 }, 4, 1, { 0x891a2b3c, 0x55555ddd, 0x7ff75de6, 0x7f5d4c3a } }, |
|
|
|
|
{ { 0x12345678, 0xaaaabbbb, 0xffeebbcc, 0xfeba9874 }, 4, 18, { 0xaeeec48d, 0xaef32aaa, 0xa61d3ffb, 0x3fae } }, |
|
|
|
|
}; |
|
|
|
|
for (size_t i = 0; i < CYBOZU_NUM_OF_ARRAY(tbl); i++) { |
|
|
|
|
uint32_t z[4]; |
|
|
|
|
mcl::fp::shiftRight(z, tbl[i].x, tbl[i].n, tbl[i].shift); |
|
|
|
|
CYBOZU_TEST_EQUAL_ARRAY(z, tbl[i].z, tbl[i].n); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
CYBOZU_TEST_AUTO(splitBitVec) |
|
|
|
|
{ |
|
|
|
|
uint32_t tbl[] = { 0x12345678, 0xaaaabbbb, 0xffeebbcc }; |
|
|
|
|
typedef cybozu::BitVectorT<uint32_t> BitVec; |
|
|
|
|
typedef std::vector<int> IntVec; |
|
|
|
|
BitVec bv; |
|
|
|
|
bv.append(tbl, sizeof(tbl) * 8); |
|
|
|
|
for (size_t len = bv.size(); len > 0; len--) { |
|
|
|
|
bv.resize(len); |
|
|
|
|
for (size_t w = 1; w < 18; w++) { |
|
|
|
|
IntVec iv; |
|
|
|
|
size_t last = mcl::fp::splitBitVec(iv, bv, w); |
|
|
|
|
size_t q = len / w; |
|
|
|
|
size_t r = len % w; |
|
|
|
|
if (r == 0) { |
|
|
|
|
r = w; |
|
|
|
|
} else { |
|
|
|
|
q++; |
|
|
|
|
} |
|
|
|
|
CYBOZU_TEST_EQUAL(iv.size(), q); |
|
|
|
|
BitVec bv2; |
|
|
|
|
mcl::fp::concatBitVec(bv2, iv, w, last); |
|
|
|
|
CYBOZU_TEST_ASSERT(bv == bv2); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|