1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/devtools/jint/sunspider/bitops-3bit-bits-in-byte.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,37 @@ 1.4 +// Copyright (c) 2004 by Arthur Langereis (arthur_ext at domain xfinitegames, tld com 1.5 + 1.6 +// 1 op = 6 ANDs, 3 SHRs, 3 SHLs, 4 assigns, 2 ADDs 1.7 +// O(1) 1.8 +function fast3bitlookup(b) { 1.9 +var c, bi3b = 0xE994; // 0b1110 1001 1001 0100; // 3 2 2 1 2 1 1 0 1.10 +c = 3 & (bi3b >> ((b << 1) & 14)); 1.11 +c += 3 & (bi3b >> ((b >> 2) & 14)); 1.12 +c += 3 & (bi3b >> ((b >> 5) & 6)); 1.13 +return c; 1.14 + 1.15 +/* 1.16 +lir4,0xE994; 9 instructions, no memory access, minimal register dependence, 6 shifts, 2 adds, 1 inline assign 1.17 +rlwinmr5,r3,1,28,30 1.18 +rlwinmr6,r3,30,28,30 1.19 +rlwinmr7,r3,27,29,30 1.20 +rlwnmr8,r4,r5,30,31 1.21 +rlwnmr9,r4,r6,30,31 1.22 +rlwnmr10,r4,r7,30,31 1.23 +addr3,r8,r9 1.24 +addr3,r3,r10 1.25 +*/ 1.26 +} 1.27 + 1.28 + 1.29 +function TimeFunc(func) { 1.30 +var x, y, t; 1.31 +/* BEGIN LOOP */ 1.32 +for(var x=0; x<500; x++) { 1.33 + /* BEGIN LOOP */ 1.34 +for(var y=0; y<256; y++) func(y); 1.35 + /* END LOOP */ 1.36 +} 1.37 +/* END LOOP */ 1.38 +} 1.39 + 1.40 +TimeFunc(fast3bitlookup);