PageRenderTime 19ms CodeModel.GetById 10ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 1ms

/js/src/metrics/jint/sunspider/bitops-3bit-bits-in-byte.js

http://github.com/zpao/v8monkey
JavaScript | 37 lines | 14 code | 5 blank | 18 comment | 2 complexity | 68289bcc2de42778b9baee081d3e02f9 MD5 | raw file
 1// Copyright (c) 2004 by Arthur Langereis (arthur_ext at domain xfinitegames, tld com
 2
 3// 1 op = 6 ANDs, 3 SHRs, 3 SHLs, 4 assigns, 2 ADDs
 4// O(1)
 5function fast3bitlookup(b) {
 6var c, bi3b = 0xE994; // 0b1110 1001 1001 0100; // 3 2 2 1  2 1 1 0
 7c  = 3 & (bi3b >> ((b << 1) & 14));
 8c += 3 & (bi3b >> ((b >> 2) & 14));
 9c += 3 & (bi3b >> ((b >> 5) & 6));
10return c;
11
12/*
13lir4,0xE994; 9 instructions, no memory access, minimal register dependence, 6 shifts, 2 adds, 1 inline assign
14rlwinmr5,r3,1,28,30
15rlwinmr6,r3,30,28,30
16rlwinmr7,r3,27,29,30
17rlwnmr8,r4,r5,30,31
18rlwnmr9,r4,r6,30,31
19rlwnmr10,r4,r7,30,31
20addr3,r8,r9
21addr3,r3,r10
22*/
23}
24
25
26function TimeFunc(func) {
27var x, y, t;
28/* BEGIN LOOP */
29for(var x=0; x<500; x++) {
30	/* BEGIN LOOP */
31for(var y=0; y<256; y++) func(y);
32	/* END LOOP */
33}
34/* END LOOP */
35}
36
37TimeFunc(fast3bitlookup);