| // Copyright (c) 2004 by Arthur Langereis (arthur_ext at domain xfinitegames, tld com |
| // 1 op = 6 ANDs, 3 SHRs, 3 SHLs, 4 assigns, 2 ADDs |
| function fast3bitlookup(b) { |
| var c, bi3b = 0xE994; // 0b1110 1001 1001 0100; // 3 2 2 1 2 1 1 0 |
| c = 3 & (bi3b >> ((b << 1) & 14)); |
| c += 3 & (bi3b >> ((b >> 2) & 14)); |
| c += 3 & (bi3b >> ((b >> 5) & 6)); |
| lir4,0xE994; 9 instructions, no memory access, minimal register dependence, 6 shifts, 2 adds, 1 inline assign |
| function TimeFunc(func) { |
| for(var x=0; x<50000; x++) |
| for(var y=0; y<256; y++) sum += func(y); |
| sum = TimeFunc(fast3bitlookup); |
| throw "ERROR: bad result: expected " + expected + " but got " + sum; |