mirror of https://github.com/inolen/redream.git
cross-platform clz
This commit is contained in:
parent
f98eeba82b
commit
614e30e443
|
@ -1,6 +1,8 @@
|
|||
#ifndef DREAVM_MATH_H
|
||||
#define DREAVM_MATH_H
|
||||
|
||||
#include "core/platform.h"
|
||||
|
||||
namespace dreavm {
|
||||
namespace core {
|
||||
|
||||
|
@ -8,6 +10,27 @@ template <typename T>
|
|||
T align(T v, T alignment) {
|
||||
return (v + alignment - 1) & -alignment;
|
||||
}
|
||||
|
||||
#if defined(PLATFORM_LINUX) || defined(PLATFORM_DARWIN)
|
||||
inline int clz(uint32_t v) {
|
||||
return __builtin_clz(v);
|
||||
}
|
||||
inline int clz(uint64_t v) {
|
||||
return __builtin_clzll(v);
|
||||
}
|
||||
#else
|
||||
inline int clz(uint32_t v) {
|
||||
unsigned long r = 0;
|
||||
_BitScanReverse(&r, v);
|
||||
return 31 - r;
|
||||
}
|
||||
inline int clz(uint64_t v) {
|
||||
unsigned long r = 0;
|
||||
_BitScanReverse64(&r, v);
|
||||
return 63 - r;
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -65,7 +65,7 @@ X64Fn X64Emitter::Emit(IRBuilder &builder) {
|
|||
// TODO align each local
|
||||
int stack_size = 16 + builder.locals_size();
|
||||
// add 8 for function return value which will be pushed when this is called
|
||||
stack_size = align(stack_size, 16) + 8;
|
||||
stack_size = core::align(stack_size, 16) + 8;
|
||||
assert((stack_size + 8) % 16 == 0);
|
||||
|
||||
// emit prolog
|
||||
|
|
|
@ -390,7 +390,7 @@ void SH4::CheckPendingInterrupts() {
|
|||
}
|
||||
|
||||
// process the highest priority in the pending vector
|
||||
int n = 63 - __builtin_clzll(pending_interrupts_);
|
||||
int n = 63 - core::clz(pending_interrupts_);
|
||||
Interrupt intr = sorted_interrupts_[n];
|
||||
InterruptInfo &int_info = interrupts[intr];
|
||||
|
||||
|
|
|
@ -87,7 +87,7 @@ class PageTable {
|
|||
return;
|
||||
}
|
||||
|
||||
int n = 31 - __builtin_clz(mirror_mask);
|
||||
int n = 31 - core::clz(mirror_mask);
|
||||
uint32_t next_mask = mirror_mask & ~(1 << n);
|
||||
|
||||
start |= mirror_mask;
|
||||
|
|
Loading…
Reference in New Issue