Kernel: Use BAN::Math::{ctz,popcount} instead of builtins
This commit is contained in:
@@ -347,7 +347,7 @@ namespace Kernel::Input
|
||||
result.command_port = data->as.fixed_io_port.range_base;
|
||||
break;
|
||||
case ACPI::ResourceData::Type::IRQ:
|
||||
if (__builtin_popcount(data->as.irq.irq_mask) != 1)
|
||||
if (BAN::Math::popcount(data->as.irq.irq_mask) != 1)
|
||||
break;
|
||||
for (int i = 0; i < 16; i++)
|
||||
if (data->as.irq.irq_mask & (1 << i))
|
||||
|
||||
@@ -43,11 +43,10 @@ namespace Kernel
|
||||
PageTable::with_per_cpu_fast_page(current_paddr, [&page_matched_bit](void* addr) {
|
||||
for (size_t j = 0; j < PAGE_SIZE / sizeof(size_t); j++)
|
||||
{
|
||||
static_assert(sizeof(size_t) == sizeof(long));
|
||||
auto& current = static_cast<size_t*>(addr)[j];
|
||||
if (current == BAN::numeric_limits<size_t>::max())
|
||||
continue;
|
||||
const int ctz = __builtin_ctzl(~current);
|
||||
const int ctz = BAN::Math::ctz(~current);
|
||||
current |= static_cast<size_t>(1) << ctz;
|
||||
page_matched_bit = j * sizeof(size_t) * 8 + ctz;
|
||||
return;
|
||||
|
||||
@@ -125,8 +125,6 @@ struct BitmapAllocator
|
||||
// NOTE: We could optimize other bitmap functions than this
|
||||
// but this one is the bottle neck so it doesn't matter
|
||||
|
||||
static_assert(sizeof(unsigned long long) == sizeof(uint64_t));
|
||||
|
||||
if (index >= total_chunks)
|
||||
return index;
|
||||
|
||||
@@ -134,7 +132,7 @@ struct BitmapAllocator
|
||||
{
|
||||
const uint64_t qword = *reinterpret_cast<const uint64_t*>(base + (index - rem) / 8) >> rem;
|
||||
if (qword != (1ull << (64 - rem)) - 1)
|
||||
return index + __builtin_ctzll(~qword);
|
||||
return index + BAN::Math::ctz(~qword);
|
||||
index += 64 - rem;
|
||||
}
|
||||
|
||||
@@ -142,7 +140,7 @@ struct BitmapAllocator
|
||||
{
|
||||
const uint64_t qword = *reinterpret_cast<const uint64_t*>(base + index / 8);
|
||||
if (qword != UINT64_MAX)
|
||||
return index + __builtin_ctzll(~qword);
|
||||
return index + BAN::Math::ctz(~qword);
|
||||
index += 64;
|
||||
}
|
||||
|
||||
|
||||
@@ -75,7 +75,7 @@ namespace Kernel
|
||||
if (flags & ~(O_ACCMODE | O_NOFOLLOW | O_APPEND | O_TRUNC | O_CLOEXEC | O_TTY_INIT | O_NOCTTY | O_DIRECTORY | O_CREAT | O_EXCL | O_NONBLOCK))
|
||||
return BAN::Error::from_errno(ENOTSUP);
|
||||
|
||||
if ((flags & O_ACCMODE) != O_RDWR && __builtin_popcount(flags & O_ACCMODE) != 1)
|
||||
if ((flags & O_ACCMODE) != O_RDWR && BAN::Math::popcount<unsigned>(flags & O_ACCMODE) != 1)
|
||||
return BAN::Error::from_errno(EINVAL);
|
||||
|
||||
if ((flags & O_DIRECTORY) && !file.inode->mode().ifdir())
|
||||
|
||||
@@ -94,7 +94,7 @@ namespace Kernel
|
||||
|
||||
while (is != 0)
|
||||
{
|
||||
const size_t idx = __builtin_ctz(is);
|
||||
const size_t idx = BAN::Math::ctz(is);
|
||||
if (auto& device = m_devices[idx])
|
||||
device->handle_irq();
|
||||
else
|
||||
|
||||
@@ -425,7 +425,7 @@ namespace Kernel
|
||||
{
|
||||
if (const uint32_t usable_slots = ~(m_port->sact | m_port->ci) & m_free_slots)
|
||||
{
|
||||
const uint32_t slot = __builtin_ctz(usable_slots);
|
||||
const uint32_t slot = BAN::Math::ctz(usable_slots);
|
||||
m_free_slots &= ~(1u << slot);
|
||||
return slot;
|
||||
}
|
||||
|
||||
@@ -121,7 +121,7 @@ namespace Kernel
|
||||
for (size_t i = 0; i < 16; i++)
|
||||
if (page_size_bits & (1 << i))
|
||||
dwarnln(" {} bytes", 1 << (12 + i));
|
||||
if (__builtin_popcount(page_size_bits) != 1)
|
||||
if (BAN::Math::popcount(page_size_bits) != 1)
|
||||
dwarnln(" ... XHCI spec only allows a single supported page size???");
|
||||
return BAN::Error::from_errno(ENOTSUP);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user