mirror of
https://github.com/WerWolv/ImHex-Patterns.git
synced 2026-03-28 15:57:02 -05:00
* libstd: Initial standard library work bit operations, fixed point, numeric limits and math functions * libstd: Added ctype, rustint, stdint and string library, expand bit, fxpt and math library * patterns: Drastically improve ELF pattern * patterns: Added atmosphere AFE2 * patterns: tabs -> spaces * patterns: Added archive file pattern
35 lines
667 B
Plaintext
35 lines
667 B
Plaintext
namespace std::bit {
|
|
|
|
fn popcount(u128 x) {
|
|
x = (x & (std::limits::u128_max() / 3)) + ((x >> 1) & (std::limits::u128_max() / 3));
|
|
x = (x & (std::limits::u128_max() / 5)) + ((x >> 2) & (std::limits::u128_max() / 5));
|
|
x = (x & (std::limits::u128_max() / 17)) + ((x >> 4) & (std::limits::u128_max() / 17));
|
|
|
|
return x % 0xFF;
|
|
};
|
|
|
|
fn has_single_bit(u128 x) {
|
|
return x != 0 && (x & (x - 1)) == 0;
|
|
};
|
|
|
|
fn bit_ceil(u128 x) {
|
|
if (x == 0) return 0;
|
|
|
|
u8 i;
|
|
while ((1 << i) < x)
|
|
i = i + 1;
|
|
|
|
return 1 << i;
|
|
};
|
|
|
|
fn bit_floor(u128 x) {
|
|
if (x == 0) return 0;
|
|
|
|
u8 i;
|
|
while ((x >> i) > 0)
|
|
i = i + 1;
|
|
|
|
return 1 << (i - 1);
|
|
};
|
|
|
|
} |