acme
Foundational cross-platform layer of the ca2 framework
Loading...
Searching...
No Matches
logarithm.h
1// Created by camilo on 2022-11-08 18:21 <3ThomasBorregaardSorensen!!
2#pragma once
3
4
5CLASS_DECL_ACME extern const ::i8 log2_LogTable256[256];
6
7//inline bool is_found(::collection::index i) { return i >= 0; }
8//inline bool not_found(::collection::index i) { return i < 0; }
9//inline bool is_found(::collection::index i) { return i >= 0; }
10//inline bool not_found(::collection::index i) { return i < 0; }
11
12inline ::u32 u32_log2(::u32 v)
13{
14
15 //::u32 v; // 32-bit word to find the plogwriter of
16 ::u32 r; // r will be lg(v)
17 ::u32 t, tt; // temporaries
18
19 if ((tt = (v >> 16)))
20 {
21 r = (t = tt >> 8) ? 24 + log2_LogTable256[t] : 16 + log2_LogTable256[tt];
22 }
23 else
24 {
25 r = (t = v >> 8) ? 8 + log2_LogTable256[t] : log2_LogTable256[v];
26 }
27
28 return r;
29}