Fixes to ctz on Windows Clang.

This commit is contained in:
Matthew Parkinson
2020-08-26 16:25:57 +01:00
committed by Matthew Parkinson
parent c171de9a89
commit 0728db1413
2 changed files with 61 additions and 12 deletions

View File

@@ -0,0 +1,43 @@
/**
* Unit tests for operations in bits.h
*/
#include <iostream>
#include <test/setup.h>
#include <ds/bits.h>
void
test_ctz()
{
for (size_t i = 0; i < sizeof(size_t) * 8; i++)
if (snmalloc::bits::ctz(snmalloc::bits::one_at_bit(i)) != i)
{
std::cout << "Failed with ctz(one_at_bit(i)) != i for i=" << i << std::endl;
abort();
}
}
void
test_clz()
{
const size_t PTRSIZE_LOG = sizeof(size_t) * 8;
for (size_t i = 0; i < sizeof(size_t) * 8; i++)
if (snmalloc::bits::clz(snmalloc::bits::one_at_bit(i)) != (PTRSIZE_LOG - i - 1))
{
std::cout << "Failed with clz(one_at_bit(i)) != (PTRSIZE_LOG - i - 1) for i=" << i << std::endl;
abort();
}
}
int main(int argc, char** argv)
{
UNUSED(argc);
UNUSED(argv);
setup();
test_clz();
test_ctz();
}