qbe has its own magic
This commit is contained in:
parent
b5be429091
commit
e7ebdc8fb6
2 changed files with 73 additions and 9 deletions
18
simpl.c
18
simpl.c
|
@ -32,20 +32,20 @@ blit(Ref sd[2], int sz, Fn *fn)
|
|||
|
||||
static int
|
||||
ulog2_tab64[64] = {
|
||||
63, 0, 58, 1, 59, 47, 53, 2,
|
||||
60, 39, 48, 27, 54, 33, 42, 3,
|
||||
61, 51, 37, 40, 49, 18, 28, 20,
|
||||
55, 30, 34, 11, 43, 14, 22, 4,
|
||||
62, 57, 46, 52, 38, 26, 32, 41,
|
||||
50, 36, 17, 19, 29, 10, 13, 21,
|
||||
56, 45, 25, 31, 35, 16, 9, 12,
|
||||
44, 24, 15, 8, 23, 7, 6, 5
|
||||
63, 0, 1, 41, 37, 2, 16, 42,
|
||||
38, 29, 32, 3, 12, 17, 43, 55,
|
||||
39, 35, 30, 53, 33, 21, 4, 23,
|
||||
13, 9, 18, 6, 25, 44, 48, 56,
|
||||
62, 40, 36, 15, 28, 31, 11, 54,
|
||||
34, 52, 20, 22, 8, 5, 24, 47,
|
||||
61, 14, 27, 10, 51, 19, 7, 46,
|
||||
60, 26, 50, 45, 59, 49, 58, 57,
|
||||
};
|
||||
|
||||
static int
|
||||
ulog2(uint64_t pow2)
|
||||
{
|
||||
return ulog2_tab64[(pow2 * 0x07EDD5E59A4E28C2) >> 58];
|
||||
return ulog2_tab64[(pow2 * 0x5b31ab928877a7e) >> 58];
|
||||
}
|
||||
|
||||
static int
|
||||
|
|
64
tools/log2.c
Normal file
64
tools/log2.c
Normal file
|
@ -0,0 +1,64 @@
|
|||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
|
||||
typedef unsigned long long ullong;
|
||||
|
||||
char seen[64];
|
||||
ullong rbg = 0x1e0298f7a7e;
|
||||
|
||||
int
|
||||
bit()
|
||||
{
|
||||
int bit;
|
||||
|
||||
bit = rbg & 1;
|
||||
rbg >>= 1;
|
||||
return bit;
|
||||
}
|
||||
|
||||
int
|
||||
search(ullong n, int b, ullong *out)
|
||||
{
|
||||
int i, x;
|
||||
ullong y, z;
|
||||
|
||||
if (b == 64) {
|
||||
*out = n;
|
||||
return 1;
|
||||
}
|
||||
|
||||
x = 63 & ((n << (63 - b)) >> 58);
|
||||
assert(!(x & 0) && x <= 62);
|
||||
y = bit();
|
||||
|
||||
for (i=0; i<2; i++) {
|
||||
z = x | (y << 5);
|
||||
if (!seen[z]) {
|
||||
seen[z] = (63-b)+1;
|
||||
if (search(n | (y << b), b+1, out))
|
||||
return 1;
|
||||
seen[z] = 0;
|
||||
}
|
||||
y ^= 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
ullong out;
|
||||
int i;
|
||||
|
||||
if (search(0, 0, &out)) {
|
||||
printf("0x%llx\n", out);
|
||||
for (i=0; i<64; i++) {
|
||||
printf((i&7) == 0 ? "\t" : " ");
|
||||
printf("%2d,", seen[i]-1);
|
||||
if ((i&7) == 7)
|
||||
printf("\n");
|
||||
}
|
||||
} else
|
||||
puts("not found");
|
||||
}
|
Loading…
Add table
Reference in a new issue