1 var testContents = [ "<!DOCTYPE html>\n\
7 Copyright (C) 2007 Apple Inc. All rights reserved.\n\
9 Redistribution and use in source and binary forms, with or without\n\
10 modification, are permitted provided that the following conditions\n\
12 1. Redistributions of source code must retain the above copyright\n\
13 notice, this list of conditions and the following disclaimer.\n\
14 2. Redistributions in binary form must reproduce the above copyright\n\
15 notice, this list of conditions and the following disclaimer in the\n\
16 documentation and/or other materials provided with the distribution.\n\
18 THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY\n\
19 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n\
20 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\n\
21 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR\n\
22 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,\n\
23 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,\n\
24 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n\
25 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY\n\
26 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n\
27 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n\
28 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \n\
31 <title>SunSpider 3d-cube</title>\n\
32 <link rel=\"stylesheet\" href=\"../sunspider.css\">\n\
37 <div id=\"console\">\n\
40 function record(time) {\n\
41 document.getElementById(\"console\").innerHTML = time + \"ms\";\n\
42 if (window.parent) {\n\
43 parent.recordResult(time);\n\
47 window.onerror = function(e) {\n\
48 console.log(\"3d-cube failed with error: \" + e);\n\
52 var _sunSpiderStartDate = new Date();\n\
54 // 3D Cube Rotation\n\
55 // http://www.speich.net/computer/moztesting/3d.htm\n\
56 // Created by Simon Speich\n\
58 var Q = new Array();\n\
59 var MTrans = new Array(); // transformation matrix\n\
60 var MQube = new Array(); // position information of qube\n\
61 var I = new Array(); // entity matrix\n\
62 var Origin = new Object();\n\
63 var Testing = new Object();\n\
67 20: 2889.0000000000045,\n\
68 40: 2889.0000000000055,\n\
69 80: 2889.000000000005,\n\
70 160: 2889.0000000000055\n\
73 var DisplArea = new Object();\n\
74 DisplArea.Width = 300;\n\
75 DisplArea.Height = 300;\n\
77 function DrawLine(From, To) {\n\
78 var x1 = From.V[0];\n\
80 var y1 = From.V[1];\n\
82 var dx = Math.abs(x2 - x1);\n\
83 var dy = Math.abs(y2 - y1);\n\
93 if (x2 >= x1) { IncX1 = 1; IncX2 = 1; }\n\
94 else { IncX1 = -1; IncX2 = -1; }\n\
95 if (y2 >= y1) { IncY1 = 1; IncY2 = 1; }\n\
96 else { IncY1 = -1; IncY2 = -1; }\n\
114 NumPix = Math.round(Q.LastPx + NumPix);\n\
117 for (; i < NumPix; i++) {\n\
127 Q.LastPx = NumPix;\n\
130 function CalcCross(V0, V1) {\n\
131 var Cross = new Array();\n\
132 Cross[0] = V0[1]*V1[2] - V0[2]*V1[1];\n\
133 Cross[1] = V0[2]*V1[0] - V0[0]*V1[2];\n\
134 Cross[2] = V0[0]*V1[1] - V0[1]*V1[0];\n\
138 function CalcNormal(V0, V1, V2) {\n\
139 var A = new Array(); var B = new Array(); \n\
140 for (var i = 0; i < 3; i++) {\n\
141 A[i] = V0[i] - V1[i];\n\
142 B[i] = V2[i] - V1[i];\n\
144 A = CalcCross(A, B);\n\
145 var Length = Math.sqrt(A[0]*A[0] + A[1]*A[1] + A[2]*A[2]); \n\
146 for (var i = 0; i < 3; i++) A[i] = A[i] / Length;\n\
151 function CreateP(X,Y,Z) {\n\
152 this.V = [X,Y,Z,1];\n\
155 // multiplies two matrices\n\
156 function MMulti(M1, M2) {\n\
157 var M = [[],[],[],[]];\n\
160 for (; i < 4; i++) {\n\
162 for (; j < 4; j++) M[i][j] = M1[i][0] * M2[0][j] + M1[i][1] * M2[1][j] + M1[i][2] * M2[2][j] + M1[i][3] * M2[3][j];\n\
167 //multiplies matrix with vector\n\
168 function VMulti(M, V) {\n\
169 var Vect = new Array();\n\
171 for (;i < 4; i++) Vect[i] = M[i][0] * V[0] + M[i][1] * V[1] + M[i][2] * V[2] + M[i][3] * V[3];\n\
175 function VMulti2(M, V) {\n\
176 var Vect = new Array();\n\
178 for (;i < 3; i++) Vect[i] = M[i][0] * V[0] + M[i][1] * V[1] + M[i][2] * V[2];\n\
182 // add to matrices\n\
183 function MAdd(M1, M2) {\n\
184 var M = [[],[],[],[]];\n\
187 for (; i < 4; i++) {\n\
189 for (; j < 4; j++) M[i][j] = M1[i][j] + M2[i][j];\n\
194 function Translate(M, Dx, Dy, Dz) {\n\
201 return MMulti(T, M);\n\
204 function RotateX(M, Phi) {\n\
206 a *= Math.PI / 180;\n\
207 var Cos = Math.cos(a);\n\
208 var Sin = Math.sin(a);\n\
215 return MMulti(R, M);\n\
218 function RotateY(M, Phi) {\n\
220 a *= Math.PI / 180;\n\
221 var Cos = Math.cos(a);\n\
222 var Sin = Math.sin(a);\n\
229 return MMulti(R, M);\n\
232 function RotateZ(M, Phi) {\n\
234 a *= Math.PI / 180;\n\
235 var Cos = Math.cos(a);\n\
236 var Sin = Math.sin(a);\n\
243 return MMulti(R, M);\n\
246 function DrawQube() {\n\
247 // calc current normals\n\
248 var CurN = new Array();\n\
251 for (; i > -1; i--) CurN[i] = VMulti2(MQube, Q.Normal[i]);\n\
252 if (CurN[0][2] < 0) {\n\
253 if (!Q.Line[0]) { DrawLine(Q[0], Q[1]); Q.Line[0] = true; };\n\
254 if (!Q.Line[1]) { DrawLine(Q[1], Q[2]); Q.Line[1] = true; };\n\
255 if (!Q.Line[2]) { DrawLine(Q[2], Q[3]); Q.Line[2] = true; };\n\
256 if (!Q.Line[3]) { DrawLine(Q[3], Q[0]); Q.Line[3] = true; };\n\
258 if (CurN[1][2] < 0) {\n\
259 if (!Q.Line[2]) { DrawLine(Q[3], Q[2]); Q.Line[2] = true; };\n\
260 if (!Q.Line[9]) { DrawLine(Q[2], Q[6]); Q.Line[9] = true; };\n\
261 if (!Q.Line[6]) { DrawLine(Q[6], Q[7]); Q.Line[6] = true; };\n\
262 if (!Q.Line[10]) { DrawLine(Q[7], Q[3]); Q.Line[10] = true; };\n\
264 if (CurN[2][2] < 0) {\n\
265 if (!Q.Line[4]) { DrawLine(Q[4], Q[5]); Q.Line[4] = true; };\n\
266 if (!Q.Line[5]) { DrawLine(Q[5], Q[6]); Q.Line[5] = true; };\n\
267 if (!Q.Line[6]) { DrawLine(Q[6], Q[7]); Q.Line[6] = true; };\n\
268 if (!Q.Line[7]) { DrawLine(Q[7], Q[4]); Q.Line[7] = true; };\n\
270 if (CurN[3][2] < 0) {\n\
271 if (!Q.Line[4]) { DrawLine(Q[4], Q[5]); Q.Line[4] = true; };\n\
272 if (!Q.Line[8]) { DrawLine(Q[5], Q[1]); Q.Line[8] = true; };\n\
273 if (!Q.Line[0]) { DrawLine(Q[1], Q[0]); Q.Line[0] = true; };\n\
274 if (!Q.Line[11]) { DrawLine(Q[0], Q[4]); Q.Line[11] = true; };\n\
276 if (CurN[4][2] < 0) {\n\
277 if (!Q.Line[11]) { DrawLine(Q[4], Q[0]); Q.Line[11] = true; };\n\
278 if (!Q.Line[3]) { DrawLine(Q[0], Q[3]); Q.Line[3] = true; };\n\
279 if (!Q.Line[10]) { DrawLine(Q[3], Q[7]); Q.Line[10] = true; };\n\
280 if (!Q.Line[7]) { DrawLine(Q[7], Q[4]); Q.Line[7] = true; };\n\
282 if (CurN[5][2] < 0) {\n\
283 if (!Q.Line[8]) { DrawLine(Q[1], Q[5]); Q.Line[8] = true; };\n\
284 if (!Q.Line[5]) { DrawLine(Q[5], Q[6]); Q.Line[5] = true; };\n\
285 if (!Q.Line[9]) { DrawLine(Q[6], Q[2]); Q.Line[9] = true; };\n\
286 if (!Q.Line[1]) { DrawLine(Q[2], Q[1]); Q.Line[1] = true; };\n\
288 Q.Line = [false,false,false,false,false,false,false,false,false,false,false,false];\n\
293 if (Testing.LoopCount > Testing.LoopMax) return;\n\
294 var TestingStr = String(Testing.LoopCount);\n\
295 while (TestingStr.length < 3) TestingStr = \"0\" + TestingStr;\n\
296 MTrans = Translate(I, -Q[8].V[0], -Q[8].V[1], -Q[8].V[2]);\n\
297 MTrans = RotateX(MTrans, 1);\n\
298 MTrans = RotateY(MTrans, 3);\n\
299 MTrans = RotateZ(MTrans, 5);\n\
300 MTrans = Translate(MTrans, Q[8].V[0], Q[8].V[1], Q[8].V[2]);\n\
301 MQube = MMulti(MTrans, MQube);\n\
303 for (; i > -1; i--) {\n\
304 Q[i].V = VMulti(MTrans, Q[i].V);\n\
307 Testing.LoopCount++;\n\
311 function Init(CubeSize) {\n\
312 // init/reset vars\n\
313 Origin.V = [150,150,20,1];\n\
314 Testing.LoopCount = 0;\n\
315 Testing.LoopMax = 50;\n\
316 Testing.TimeMax = 0;\n\
317 Testing.TimeAvg = 0;\n\
318 Testing.TimeMin = 0;\n\
319 Testing.TimeTemp = 0;\n\
320 Testing.TimeTotal = 0;\n\
321 Testing.Init = false;\n\
323 // transformation matrix\n\
331 // position information of qube\n\
348 Q[0] = new CreateP(-CubeSize,-CubeSize, CubeSize);\n\
349 Q[1] = new CreateP(-CubeSize, CubeSize, CubeSize);\n\
350 Q[2] = new CreateP( CubeSize, CubeSize, CubeSize);\n\
351 Q[3] = new CreateP( CubeSize,-CubeSize, CubeSize);\n\
352 Q[4] = new CreateP(-CubeSize,-CubeSize,-CubeSize);\n\
353 Q[5] = new CreateP(-CubeSize, CubeSize,-CubeSize);\n\
354 Q[6] = new CreateP( CubeSize, CubeSize,-CubeSize);\n\
355 Q[7] = new CreateP( CubeSize,-CubeSize,-CubeSize);\n\
357 // center of gravity\n\
358 Q[8] = new CreateP(0, 0, 0);\n\
360 // anti-clockwise edge check\n\
361 Q.Edge = [[0,1,2],[3,2,6],[7,6,5],[4,5,1],[4,0,3],[1,5,6]];\n\
363 // calculate squad normals\n\
364 Q.Normal = new Array();\n\
365 for (var i = 0; i < Q.Edge.length; i++) Q.Normal[i] = CalcNormal(Q[Q.Edge[i][0]].V, Q[Q.Edge[i][1]].V, Q[Q.Edge[i][2]].V);\n\
368 Q.Line = [false,false,false,false,false,false,false,false,false,false,false,false];\n\
370 // create line pixels\n\
371 Q.NumPx = 9 * 2 * CubeSize;\n\
372 for (var i = 0; i < Q.NumPx; i++) CreateP(0,0,0);\n\
374 MTrans = Translate(MTrans, Origin.V[0], Origin.V[1], Origin.V[2]);\n\
375 MQube = MMulti(MTrans, MQube);\n\
378 for (; i < 9; i++) {\n\
379 Q[i].V = VMulti(MTrans, Q[i].V);\n\
382 Testing.Init = true;\n\
385 // Perform a simple sum-based verification.\n\
387 for (var i = 0; i < Q.length; ++i) {\n\
388 var vector = Q[i].V;\n\
389 for (var j = 0; j < vector.length; ++j)\n\
392 if (sum != validation[CubeSize])\n\
393 throw \"Error: bad vector sum for CubeSize = \" + CubeSize + \"; expected \" + validation[CubeSize] + \" but got \" + sum;\n\
396 for ( var i = 20; i <= 160; i *= 2 ) {\n\
411 var _sunSpiderInterval = new Date() - _sunSpiderStartDate;\n\
413 record(_sunSpiderInterval);\n\
419 ", "<!DOCTYPE html>\n\
422 <meta charset=utf8>\n\
425 Copyright (C) 2007 Apple Inc. All rights reserved.\n\
427 Redistribution and use in source and binary forms, with or without\n\
428 modification, are permitted provided that the following conditions\n\
430 1. Redistributions of source code must retain the above copyright\n\
431 notice, this list of conditions and the following disclaimer.\n\
432 2. Redistributions in binary form must reproduce the above copyright\n\
433 notice, this list of conditions and the following disclaimer in the\n\
434 documentation and/or other materials provided with the distribution.\n\
436 THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY\n\
437 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n\
438 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\n\
439 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR\n\
440 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,\n\
441 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,\n\
442 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n\
443 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY\n\
444 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n\
445 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n\
446 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \n\
449 <title>SunSpider 3d-morph</title>\n\
450 <link rel=\"stylesheet\" href=\"../sunspider.css\">\n\
455 <div id=\"console\">\n\
458 function record(time) {\n\
459 document.getElementById(\"console\").innerHTML = time + \"ms\";\n\
460 if (window.parent) {\n\
461 parent.recordResult(time);\n\
465 window.onerror = function(e) {\n\
466 console.log(\"3d-morph failed with error: \" + e);\n\
470 var _sunSpiderStartDate = new Date();\n\
473 * Copyright (C) 2007 Apple Inc. All rights reserved.\n\
475 * Redistribution and use in source and binary forms, with or without\n\
476 * modification, are permitted provided that the following conditions\n\
478 * 1. Redistributions of source code must retain the above copyright\n\
479 * notice, this list of conditions and the following disclaimer.\n\
480 * 2. Redistributions in binary form must reproduce the above copyright\n\
481 * notice, this list of conditions and the following disclaimer in the\n\
482 * documentation and/or other materials provided with the distribution.\n\
484 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY\n\
485 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n\
486 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\n\
487 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR\n\
488 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,\n\
489 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,\n\
490 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n\
491 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY\n\
492 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n\
493 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n\
494 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \n\
501 function morph(a, f) {\n\
502 var PI2nx = Math.PI * 8/nx\n\
503 var sin = Math.sin\n\
504 var f30 = -(50 * sin(f*Math.PI*2))\n\
506 for (var i = 0; i < nz; ++i) {\n\
507 for (var j = 0; j < nx; ++j) {\n\
508 a[3*(i*nx+j)+1] = sin((j-1) * PI2nx ) * -f30\n\
515 for (var i=0; i < nx*nz*3; ++i) \n\
518 for (var i = 0; i < loops; ++i) {\n\
523 for (var i = 0; i < nx; i++)\n\
524 testOutput += a[3*(i*nx+i)+1];\n\
527 // This has to be an approximate test since ECMAscript doesn't formally specify\n\
528 // what sin() returns. Even if it did specify something like for example what Java 7\n\
529 // says - that sin() has to return a value within 1 ulp of exact - then we still\n\
530 // would not be able to do an exact test here since that would allow for just enough\n\
531 // low-bit slop to create possibly big errors due to testOutput being a sum.\n\
532 var epsilon = 1e-13;\n\
533 if (Math.abs(testOutput) >= epsilon)\n\
534 throw \"Error: bad test output: expected magnitude below \" + epsilon + \" but got \" + testOutput;\n\
537 var _sunSpiderInterval = new Date() - _sunSpiderStartDate;\n\
539 record(_sunSpiderInterval);\n\
545 ", "<!DOCTYPE html>\n\
548 <meta charset=utf8>\n\
551 Copyright (C) 2007 Apple Inc. All rights reserved.\n\
553 Redistribution and use in source and binary forms, with or without\n\
554 modification, are permitted provided that the following conditions\n\
556 1. Redistributions of source code must retain the above copyright\n\
557 notice, this list of conditions and the following disclaimer.\n\
558 2. Redistributions in binary form must reproduce the above copyright\n\
559 notice, this list of conditions and the following disclaimer in the\n\
560 documentation and/or other materials provided with the distribution.\n\
562 THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY\n\
563 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n\
564 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\n\
565 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR\n\
566 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,\n\
567 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,\n\
568 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n\
569 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY\n\
570 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n\
571 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n\
572 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \n\
575 <title>SunSpider 3d-raytrace</title>\n\
576 <link rel=\"stylesheet\" href=\"../sunspider.css\">\n\
580 <h3>3d-raytrace</h3>\n\
581 <div id=\"console\">\n\
584 function record(time) {\n\
585 document.getElementById(\"console\").innerHTML = time + \"ms\";\n\
586 if (window.parent) {\n\
587 parent.recordResult(time);\n\
591 window.onerror = function(e) {\n\
592 console.log(\"3d-raytrace failed with error: \" + e);\n\
596 var _sunSpiderStartDate = new Date();\n\
599 * Copyright (C) 2007 Apple Inc. All rights reserved.\n\
601 * Redistribution and use in source and binary forms, with or without\n\
602 * modification, are permitted provided that the following conditions\n\
604 * 1. Redistributions of source code must retain the above copyright\n\
605 * notice, this list of conditions and the following disclaimer.\n\
606 * 2. Redistributions in binary form must reproduce the above copyright\n\
607 * notice, this list of conditions and the following disclaimer in the\n\
608 * documentation and/or other materials provided with the distribution.\n\
610 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY\n\
611 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n\
612 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\n\
613 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR\n\
614 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,\n\
615 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,\n\
616 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n\
617 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY\n\
618 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n\
619 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n\
620 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \n\
623 function createVector(x,y,z) {\n\
624 return new Array(x,y,z);\n\
627 function sqrLengthVector(self) {\n\
628 return self[0] * self[0] + self[1] * self[1] + self[2] * self[2];\n\
631 function lengthVector(self) {\n\
632 return Math.sqrt(self[0] * self[0] + self[1] * self[1] + self[2] * self[2]);\n\
635 function addVector(self, v) {\n\
642 function subVector(self, v) {\n\
649 function scaleVector(self, scale) {\n\
656 function normaliseVector(self) {\n\
657 var len = Math.sqrt(self[0] * self[0] + self[1] * self[1] + self[2] * self[2]);\n\
664 function add(v1, v2) {\n\
665 return new Array(v1[0] + v2[0], v1[1] + v2[1], v1[2] + v2[2]);\n\
668 function sub(v1, v2) {\n\
669 return new Array(v1[0] - v2[0], v1[1] - v2[1], v1[2] - v2[2]);\n\
672 function scalev(v1, v2) {\n\
673 return new Array(v1[0] * v2[0], v1[1] * v2[1], v1[2] * v2[2]);\n\
676 function dot(v1, v2) {\n\
677 return v1[0] * v2[0] + v1[1] * v2[1] + v1[2] * v2[2];\n\
680 function scale(v, scale) {\n\
681 return [v[0] * scale, v[1] * scale, v[2] * scale];\n\
684 function cross(v1, v2) {\n\
685 return [v1[1] * v2[2] - v1[2] * v2[1], \n\
686 v1[2] * v2[0] - v1[0] * v2[2],\n\
687 v1[0] * v2[1] - v1[1] * v2[0]];\n\
691 function normalise(v) {\n\
692 var len = lengthVector(v);\n\
693 return [v[0] / len, v[1] / len, v[2] / len];\n\
696 function transformMatrix(self, v) {\n\
698 var x = vals[0] * v[0] + vals[1] * v[1] + vals[2] * v[2] + vals[3];\n\
699 var y = vals[4] * v[0] + vals[5] * v[1] + vals[6] * v[2] + vals[7];\n\
700 var z = vals[8] * v[0] + vals[9] * v[1] + vals[10] * v[2] + vals[11];\n\
704 function invertMatrix(self) {\n\
705 var temp = new Array(16);\n\
706 var tx = -self[3];\n\
707 var ty = -self[7];\n\
708 var tz = -self[11];\n\
709 for (h = 0; h < 3; h++) \n\
710 for (v = 0; v < 3; v++) \n\
711 temp[h + v * 4] = self[v + h * 4];\n\
712 for (i = 0; i < 11; i++)\n\
713 self[i] = temp[i];\n\
714 self[3] = tx * self[0] + ty * self[1] + tz * self[2];\n\
715 self[7] = tx * self[4] + ty * self[5] + tz * self[6];\n\
716 self[11] = tx * self[8] + ty * self[9] + tz * self[10];\n\
721 // Triangle intersection using barycentric coord method\n\
722 function Triangle(p1, p2, p3) {\n\
723 var edge1 = sub(p3, p1);\n\
724 var edge2 = sub(p2, p1);\n\
725 var normal = cross(edge1, edge2);\n\
726 if (Math.abs(normal[0]) > Math.abs(normal[1]))\n\
727 if (Math.abs(normal[0]) > Math.abs(normal[2]))\n\
732 if (Math.abs(normal[1]) > Math.abs(normal[2])) \n\
736 var u = (this.axis + 1) % 3;\n\
737 var v = (this.axis + 2) % 3;\n\
738 var u1 = edge1[u];\n\
739 var v1 = edge1[v];\n\
741 var u2 = edge2[u];\n\
742 var v2 = edge2[v];\n\
743 this.normal = normalise(normal);\n\
744 this.nu = normal[u] / normal[this.axis];\n\
745 this.nv = normal[v] / normal[this.axis];\n\
746 this.nd = dot(normal, p1) / normal[this.axis];\n\
747 var det = u1 * v2 - v1 * u2;\n\
750 this.nu1 = u1 / det;\n\
751 this.nv1 = -v1 / det;\n\
752 this.nu2 = v2 / det;\n\
753 this.nv2 = -u2 / det; \n\
754 this.material = [0.7, 0.7, 0.7];\n\
757 Triangle.prototype.intersect = function(orig, dir, near, far) {\n\
758 var u = (this.axis + 1) % 3;\n\
759 var v = (this.axis + 2) % 3;\n\
760 var d = dir[this.axis] + this.nu * dir[u] + this.nv * dir[v];\n\
761 var t = (this.nd - orig[this.axis] - this.nu * orig[u] - this.nv * orig[v]) / d;\n\
762 if (t < near || t > far)\n\
764 var Pu = orig[u] + t * dir[u] - this.eu;\n\
765 var Pv = orig[v] + t * dir[v] - this.ev;\n\
766 var a2 = Pv * this.nu1 + Pu * this.nv1;\n\
769 var a3 = Pu * this.nu2 + Pv * this.nv2;\n\
773 if ((a2 + a3) > 1) \n\
778 function Scene(a_triangles) {\n\
779 this.triangles = a_triangles;\n\
781 this.ambient = [0,0,0];\n\
782 this.background = [0.8,0.8,1];\n\
784 var zero = new Array(0,0,0);\n\
786 Scene.prototype.intersect = function(origin, dir, near, far) {\n\
787 var closest = null;\n\
788 for (i = 0; i < this.triangles.length; i++) {\n\
789 var triangle = this.triangles[i]; \n\
790 var d = triangle.intersect(origin, dir, near, far);\n\
791 if (d == null || d > far || d < near)\n\
794 closest = triangle;\n\
798 return [this.background[0],this.background[1],this.background[2]];\n\
800 var normal = closest.normal;\n\
801 var hit = add(origin, scale(dir, far)); \n\
802 if (dot(dir, normal) > 0)\n\
803 normal = [-normal[0], -normal[1], -normal[2]];\n\
805 var colour = null;\n\
806 if (closest.shader) {\n\
807 colour = closest.shader(closest, hit, dir);\n\
809 colour = closest.material;\n\
813 var reflected = null;\n\
814 if (colour.reflection > 0.001) {\n\
815 var reflection = addVector(scale(normal, -2*dot(dir, normal)), dir);\n\
816 reflected = this.intersect(hit, reflection, 0.0001, 1000000);\n\
817 if (colour.reflection >= 0.999999)\n\
821 var l = [this.ambient[0], this.ambient[1], this.ambient[2]];\n\
822 for (var i = 0; i < this.lights.length; i++) {\n\
823 var light = this.lights[i];\n\
824 var toLight = sub(light, hit);\n\
825 var distance = lengthVector(toLight);\n\
826 scaleVector(toLight, 1.0/distance);\n\
827 distance -= 0.0001;\n\
828 if (this.blocked(hit, toLight, distance))\n\
830 var nl = dot(normal, toLight);\n\
832 addVector(l, scale(light.colour, nl));\n\
834 l = scalev(l, colour);\n\
836 l = addVector(scaleVector(l, 1 - colour.reflection), scaleVector(reflected, colour.reflection));\n\
841 Scene.prototype.blocked = function(O, D, far) {\n\
842 var near = 0.0001;\n\
843 var closest = null;\n\
844 for (i = 0; i < this.triangles.length; i++) {\n\
845 var triangle = this.triangles[i]; \n\
846 var d = triangle.intersect(O, D, near, far);\n\
847 if (d == null || d > far || d < near)\n\
856 // this camera code is from notes i made ages ago, it is from *somewhere* -- i cannot remember where\n\
857 // that somewhere is\n\
858 function Camera(origin, lookat, up) {\n\
859 var zaxis = normaliseVector(subVector(lookat, origin));\n\
860 var xaxis = normaliseVector(cross(up, zaxis));\n\
861 var yaxis = normaliseVector(cross(xaxis, subVector([0,0,0], zaxis)));\n\
862 var m = new Array(16);\n\
863 m[0] = xaxis[0]; m[1] = xaxis[1]; m[2] = xaxis[2];\n\
864 m[4] = yaxis[0]; m[5] = yaxis[1]; m[6] = yaxis[2];\n\
865 m[8] = zaxis[0]; m[9] = zaxis[1]; m[10] = zaxis[2];\n\
867 m[3] = 0; m[7] = 0; m[11] = 0;\n\
868 this.origin = origin;\n\
869 this.directions = new Array(4);\n\
870 this.directions[0] = normalise([-0.7, 0.7, 1]);\n\
871 this.directions[1] = normalise([ 0.7, 0.7, 1]);\n\
872 this.directions[2] = normalise([ 0.7, -0.7, 1]);\n\
873 this.directions[3] = normalise([-0.7, -0.7, 1]);\n\
874 this.directions[0] = transformMatrix(m, this.directions[0]);\n\
875 this.directions[1] = transformMatrix(m, this.directions[1]);\n\
876 this.directions[2] = transformMatrix(m, this.directions[2]);\n\
877 this.directions[3] = transformMatrix(m, this.directions[3]);\n\
880 Camera.prototype.generateRayPair = function(y) {\n\
881 rays = new Array(new Object(), new Object());\n\
882 rays[0].origin = this.origin;\n\
883 rays[1].origin = this.origin;\n\
884 rays[0].dir = addVector(scale(this.directions[0], y), scale(this.directions[3], 1 - y));\n\
885 rays[1].dir = addVector(scale(this.directions[1], y), scale(this.directions[2], 1 - y));\n\
889 function renderRows(camera, scene, pixels, width, height, starty, stopy) {\n\
890 for (var y = starty; y < stopy; y++) {\n\
891 var rays = camera.generateRayPair(y / height);\n\
892 for (var x = 0; x < width; x++) {\n\
893 var xp = x / width;\n\
894 var origin = addVector(scale(rays[0].origin, xp), scale(rays[1].origin, 1 - xp));\n\
895 var dir = normaliseVector(addVector(scale(rays[0].dir, xp), scale(rays[1].dir, 1 - xp)));\n\
896 var l = scene.intersect(origin, dir);\n\
902 Camera.prototype.render = function(scene, pixels, width, height) {\n\
905 renderRows(cam, scene, pixels, width, height, 0, height);\n\
910 function raytraceScene()\n\
912 var startDate = new Date().getTime();\n\
913 var numTriangles = 2 * 6;\n\
914 var triangles = new Array();//numTriangles);\n\
915 var tfl = createVector(-10, 10, -10);\n\
916 var tfr = createVector( 10, 10, -10);\n\
917 var tbl = createVector(-10, 10, 10);\n\
918 var tbr = createVector( 10, 10, 10);\n\
919 var bfl = createVector(-10, -10, -10);\n\
920 var bfr = createVector( 10, -10, -10);\n\
921 var bbl = createVector(-10, -10, 10);\n\
922 var bbr = createVector( 10, -10, 10);\n\
928 triangles[i++] = new Triangle(tfl, tfr, bfr);\n\
929 triangles[i++] = new Triangle(tfl, bfr, bfl);\n\
931 triangles[i++] = new Triangle(tbl, tbr, bbr);\n\
932 triangles[i++] = new Triangle(tbl, bbr, bbl);\n\
933 // triangles[i-1].material = [0.7,0.2,0.2];\n\
934 // triangles[i-1].material.reflection = 0.8;\n\
936 triangles[i++] = new Triangle(tbl, tfl, bbl);\n\
937 // triangles[i-1].reflection = 0.6;\n\
938 triangles[i++] = new Triangle(tfl, bfl, bbl);\n\
939 // triangles[i-1].reflection = 0.6;\n\
941 triangles[i++] = new Triangle(tbr, tfr, bbr);\n\
942 triangles[i++] = new Triangle(tfr, bfr, bbr);\n\
944 triangles[i++] = new Triangle(tbl, tbr, tfr);\n\
945 triangles[i++] = new Triangle(tbl, tfr, tfl);\n\
947 triangles[i++] = new Triangle(bbl, bbr, bfr);\n\
948 triangles[i++] = new Triangle(bbl, bfr, bfl);\n\
951 var green = createVector(0.0, 0.4, 0.0);\n\
952 var grey = createVector(0.4, 0.4, 0.4);\n\
953 grey.reflection = 1.0;\n\
954 var floorShader = function(tri, pos, view) {\n\
955 var x = ((pos[0]/32) % 2 + 2) % 2;\n\
956 var z = ((pos[2]/32 + 0.3) % 2 + 2) % 2;\n\
957 if (x < 1 != z < 1) {\n\
958 //in the real world we use the fresnel term...\n\
959 // var angle = 1-dot(view, tri.normal);\n\
960 // angle *= angle;\n\
961 // angle *= angle;\n\
962 // angle *= angle;\n\
963 //grey.reflection = angle;\n\
968 var ffl = createVector(-1000, -30, -1000);\n\
969 var ffr = createVector( 1000, -30, -1000);\n\
970 var fbl = createVector(-1000, -30, 1000);\n\
971 var fbr = createVector( 1000, -30, 1000);\n\
972 triangles[i++] = new Triangle(fbl, fbr, ffr);\n\
973 triangles[i-1].shader = floorShader;\n\
974 triangles[i++] = new Triangle(fbl, ffr, ffl);\n\
975 triangles[i-1].shader = floorShader;\n\
977 var _scene = new Scene(triangles);\n\
978 _scene.lights[0] = createVector(20, 38, -22);\n\
979 _scene.lights[0].colour = createVector(0.7, 0.3, 0.3);\n\
980 _scene.lights[1] = createVector(-23, 40, 17);\n\
981 _scene.lights[1].colour = createVector(0.7, 0.3, 0.3);\n\
982 _scene.lights[2] = createVector(23, 20, 17);\n\
983 _scene.lights[2].colour = createVector(0.7, 0.7, 0.7);\n\
984 _scene.ambient = createVector(0.1, 0.1, 0.1);\n\
985 // _scene.background = createVector(0.7, 0.7, 1.0);\n\
988 var pixels = new Array();\n\
989 for (var y = 0; y < size; y++) {\n\
990 pixels[y] = new Array();\n\
991 for (var x = 0; x < size; x++) {\n\
996 var _camera = new Camera(createVector(-40, 40, 40), createVector(0, 0, 0), createVector(0, 1, 0));\n\
997 _camera.render(_scene, pixels, size, size);\n\
1002 function arrayToCanvasCommands(pixels)\n\
1004 var s = '<canvas id=\"renderCanvas\" width=\"30px\" height=\"30px\"></canvas><scr' + 'ipt>\\nvar pixels = [';\n\
1006 for (var y = 0; y < size; y++) {\n\
1008 for (var x = 0; x < size; x++) {\n\
1009 s += \"[\" + pixels[y][x] + \"],\";\n\
1013 s += '];\\n var canvas = document.getElementById(\"renderCanvas\").getContext(\"2d\");\\n\\\n\
1016 var size = 30;\\n\\\n\
1017 canvas.fillStyle = \"red\";\\n\\\n\
1018 canvas.fillRect(0, 0, size, size);\\n\\\n\
1019 canvas.scale(1, -1);\\n\\\n\
1020 canvas.translate(0, -size);\\n\\\n\
1022 if (!canvas.setFillColor)\\n\\\n\
1023 canvas.setFillColor = function(r, g, b, a) {\\n\\\n\
1024 this.fillStyle = \"rgb(\"+[Math.floor(r * 255), Math.floor(g * 255), Math.floor(b * 255)]+\")\";\\n\\\n\
1027 for (var y = 0; y < size; y++) {\\n\\\n\
1028 for (var x = 0; x < size; x++) {\\n\\\n\
1029 var l = pixels[y][x];\\n\\\n\
1030 canvas.setFillColor(l[0], l[1], l[2], 1);\\n\\\n\
1031 canvas.fillRect(x, y, 1, 1);\\n\\\n\
1033 }</scr' + 'ipt>';\n\
1038 testOutput = arrayToCanvasCommands(raytraceScene());\n\
1040 var expectedLength = 20970;\n\
1042 if (testOutput.length != expectedLength)\n\
1043 throw \"Error: bad result: expected length \" + expectedLength + \" but got \" + testOutput.length;\n\
1047 var _sunSpiderInterval = new Date() - _sunSpiderStartDate;\n\
1049 record(_sunSpiderInterval);\n\
1055 ", "<!DOCTYPE html>\n\
1058 <meta charset=utf8>\n\
1061 Copyright (C) 2007 Apple Inc. All rights reserved.\n\
1063 Redistribution and use in source and binary forms, with or without\n\
1064 modification, are permitted provided that the following conditions\n\
1066 1. Redistributions of source code must retain the above copyright\n\
1067 notice, this list of conditions and the following disclaimer.\n\
1068 2. Redistributions in binary form must reproduce the above copyright\n\
1069 notice, this list of conditions and the following disclaimer in the\n\
1070 documentation and/or other materials provided with the distribution.\n\
1072 THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY\n\
1073 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n\
1074 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\n\
1075 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR\n\
1076 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,\n\
1077 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,\n\
1078 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n\
1079 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY\n\
1080 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n\
1081 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n\
1082 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \n\
1085 <title>SunSpider access-binary-trees</title>\n\
1086 <link rel=\"stylesheet\" href=\"../sunspider.css\">\n\
1090 <h3>access-binary-trees</h3>\n\
1091 <div id=\"console\">\n\
1094 function record(time) {\n\
1095 document.getElementById(\"console\").innerHTML = time + \"ms\";\n\
1096 if (window.parent) {\n\
1097 parent.recordResult(time);\n\
1101 window.onerror = function(e) {\n\
1102 console.log(\"access-binary-trees failed with error: \" + e);\n\
1106 var _sunSpiderStartDate = new Date();\n\
1108 /* The Great Computer Language Shootout\n\
1109 http://shootout.alioth.debian.org/\n\
1110 contributed by Isaac Gouy */\n\
1112 function TreeNode(left,right,item){\n\
1113 this.left = left;\n\
1114 this.right = right;\n\
1115 this.item = item;\n\
1118 TreeNode.prototype.itemCheck = function(){\n\
1119 if (this.left==null) return this.item;\n\
1120 else return this.item + this.left.itemCheck() - this.right.itemCheck();\n\
1123 function bottomUpTree(item,depth){\n\
1125 return new TreeNode(\n\
1126 bottomUpTree(2*item-1, depth-1)\n\
1127 ,bottomUpTree(2*item, depth-1)\n\
1132 return new TreeNode(null,null,item);\n\
1138 for ( var n = 4; n <= 7; n += 1 ) {\n\
1139 var minDepth = 4;\n\
1140 var maxDepth = Math.max(minDepth + 2, n);\n\
1141 var stretchDepth = maxDepth + 1;\n\
1143 var check = bottomUpTree(0,stretchDepth).itemCheck();\n\
1145 var longLivedTree = bottomUpTree(0,maxDepth);\n\
1146 for (var depth=minDepth; depth<=maxDepth; depth+=2){\n\
1147 var iterations = 1 << (maxDepth - depth + minDepth);\n\
1150 for (var i=1; i<=iterations; i++){\n\
1151 check += bottomUpTree(i,depth).itemCheck();\n\
1152 check += bottomUpTree(-i,depth).itemCheck();\n\
1156 ret += longLivedTree.itemCheck();\n\
1159 var expected = -4;\n\
1160 if (ret != expected)\n\
1161 throw \"ERROR: bad result: expected \" + expected + \" but got \" + ret;\n\
1163 var _sunSpiderInterval = new Date() - _sunSpiderStartDate;\n\
1165 record(_sunSpiderInterval);\n\
1171 ", "<!DOCTYPE html>\n\
1174 <meta charset=utf8>\n\
1177 Copyright (C) 2007 Apple Inc. All rights reserved.\n\
1179 Redistribution and use in source and binary forms, with or without\n\
1180 modification, are permitted provided that the following conditions\n\
1182 1. Redistributions of source code must retain the above copyright\n\
1183 notice, this list of conditions and the following disclaimer.\n\
1184 2. Redistributions in binary form must reproduce the above copyright\n\
1185 notice, this list of conditions and the following disclaimer in the\n\
1186 documentation and/or other materials provided with the distribution.\n\
1188 THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY\n\
1189 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n\
1190 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\n\
1191 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR\n\
1192 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,\n\
1193 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,\n\
1194 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n\
1195 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY\n\
1196 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n\
1197 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n\
1198 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \n\
1201 <title>SunSpider access-fannkuch</title>\n\
1202 <link rel=\"stylesheet\" href=\"../sunspider.css\">\n\
1206 <h3>access-fannkuch</h3>\n\
1207 <div id=\"console\">\n\
1210 function record(time) {\n\
1211 document.getElementById(\"console\").innerHTML = time + \"ms\";\n\
1212 if (window.parent) {\n\
1213 parent.recordResult(time);\n\
1217 window.onerror = function(e) {\n\
1218 console.log(\"access-fannkuch failed with error: \" + e);\n\
1222 var _sunSpiderStartDate = new Date();\n\
1224 /* The Great Computer Language Shootout\n\
1225 http://shootout.alioth.debian.org/\n\
1226 contributed by Isaac Gouy */\n\
1228 function fannkuch(n) {\n\
1230 var perm = Array(n);\n\
1231 var perm1 = Array(n);\n\
1232 var count = Array(n);\n\
1233 var maxPerm = Array(n);\n\
1234 var maxFlipsCount = 0;\n\
1237 for (var i = 0; i < n; i++) perm1[i] = i;\n\
1241 // write-out the first 30 permutations\n\
1244 for(var i=0; i<n; i++) s += (perm1[i]+1).toString();\n\
1248 while (r != 1) { count[r - 1] = r; r--; }\n\
1249 if (!(perm1[0] == 0 || perm1[m] == m)) {\n\
1250 for (var i = 0; i < n; i++) perm[i] = perm1[i];\n\
1252 var flipsCount = 0;\n\
1255 while (!((k = perm[0]) == 0)) {\n\
1256 var k2 = (k + 1) >> 1;\n\
1257 for (var i = 0; i < k2; i++) {\n\
1258 var temp = perm[i]; perm[i] = perm[k - i]; perm[k - i] = temp;\n\
1263 if (flipsCount > maxFlipsCount) {\n\
1264 maxFlipsCount = flipsCount;\n\
1265 for (var i = 0; i < n; i++) maxPerm[i] = perm1[i];\n\
1270 if (r == n) return maxFlipsCount;\n\
1271 var perm0 = perm1[0];\n\
1275 perm1[i] = perm1[j];\n\
1278 perm1[r] = perm0;\n\
1280 count[r] = count[r] - 1;\n\
1281 if (count[r] > 0) break;\n\
1288 var ret = fannkuch(n);\n\
1290 var expected = 22;\n\
1291 if (ret != expected)\n\
1292 throw \"ERROR: bad result: expected \" + expected + \" but got \" + ret;\n\
1296 var _sunSpiderInterval = new Date() - _sunSpiderStartDate;\n\
1298 record(_sunSpiderInterval);\n\
1304 ", "<!DOCTYPE html>\n\
1307 <meta charset=utf8>\n\
1310 Copyright (C) 2007 Apple Inc. All rights reserved.\n\
1312 Redistribution and use in source and binary forms, with or without\n\
1313 modification, are permitted provided that the following conditions\n\
1315 1. Redistributions of source code must retain the above copyright\n\
1316 notice, this list of conditions and the following disclaimer.\n\
1317 2. Redistributions in binary form must reproduce the above copyright\n\
1318 notice, this list of conditions and the following disclaimer in the\n\
1319 documentation and/or other materials provided with the distribution.\n\
1321 THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY\n\
1322 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n\
1323 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\n\
1324 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR\n\
1325 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,\n\
1326 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,\n\
1327 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n\
1328 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY\n\
1329 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n\
1330 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n\
1331 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \n\
1334 <title>SunSpider access-nbody</title>\n\
1335 <link rel=\"stylesheet\" href=\"../sunspider.css\">\n\
1339 <h3>access-nbody</h3>\n\
1340 <div id=\"console\">\n\
1343 function record(time) {\n\
1344 document.getElementById(\"console\").innerHTML = time + \"ms\";\n\
1345 if (window.parent) {\n\
1346 parent.recordResult(time);\n\
1350 window.onerror = function(e) {\n\
1351 console.log(\"access-nbody failed with error: \" + e);\n\
1355 var _sunSpiderStartDate = new Date();\n\
1357 /* The Great Computer Language Shootout\n\
1358 http://shootout.alioth.debian.org/\n\
1359 contributed by Isaac Gouy */\n\
1361 var PI = 3.141592653589793;\n\
1362 var SOLAR_MASS = 4 * PI * PI;\n\
1363 var DAYS_PER_YEAR = 365.24;\n\
1365 function Body(x,y,z,vx,vy,vz,mass){\n\
1372 this.mass = mass;\n\
1375 Body.prototype.offsetMomentum = function(px,py,pz) {\n\
1376 this.vx = -px / SOLAR_MASS;\n\
1377 this.vy = -py / SOLAR_MASS;\n\
1378 this.vz = -pz / SOLAR_MASS;\n\
1382 function Jupiter(){\n\
1384 4.84143144246472090e+00,\n\
1385 -1.16032004402742839e+00,\n\
1386 -1.03622044471123109e-01,\n\
1387 1.66007664274403694e-03 * DAYS_PER_YEAR,\n\
1388 7.69901118419740425e-03 * DAYS_PER_YEAR,\n\
1389 -6.90460016972063023e-05 * DAYS_PER_YEAR,\n\
1390 9.54791938424326609e-04 * SOLAR_MASS\n\
1394 function Saturn(){\n\
1396 8.34336671824457987e+00,\n\
1397 4.12479856412430479e+00,\n\
1398 -4.03523417114321381e-01,\n\
1399 -2.76742510726862411e-03 * DAYS_PER_YEAR,\n\
1400 4.99852801234917238e-03 * DAYS_PER_YEAR,\n\
1401 2.30417297573763929e-05 * DAYS_PER_YEAR,\n\
1402 2.85885980666130812e-04 * SOLAR_MASS\n\
1406 function Uranus(){\n\
1408 1.28943695621391310e+01,\n\
1409 -1.51111514016986312e+01,\n\
1410 -2.23307578892655734e-01,\n\
1411 2.96460137564761618e-03 * DAYS_PER_YEAR,\n\
1412 2.37847173959480950e-03 * DAYS_PER_YEAR,\n\
1413 -2.96589568540237556e-05 * DAYS_PER_YEAR,\n\
1414 4.36624404335156298e-05 * SOLAR_MASS\n\
1418 function Neptune(){\n\
1420 1.53796971148509165e+01,\n\
1421 -2.59193146099879641e+01,\n\
1422 1.79258772950371181e-01,\n\
1423 2.68067772490389322e-03 * DAYS_PER_YEAR,\n\
1424 1.62824170038242295e-03 * DAYS_PER_YEAR,\n\
1425 -9.51592254519715870e-05 * DAYS_PER_YEAR,\n\
1426 5.15138902046611451e-05 * SOLAR_MASS\n\
1431 return new Body(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, SOLAR_MASS);\n\
1435 function NBodySystem(bodies){\n\
1436 this.bodies = bodies;\n\
1440 var size = this.bodies.length;\n\
1441 for (var i=0; i<size; i++){\n\
1442 var b = this.bodies[i];\n\
1448 this.bodies[0].offsetMomentum(px,py,pz);\n\
1451 NBodySystem.prototype.advance = function(dt){\n\
1452 var dx, dy, dz, distance, mag;\n\
1453 var size = this.bodies.length;\n\
1455 for (var i=0; i<size; i++) {\n\
1456 var bodyi = this.bodies[i];\n\
1457 for (var j=i+1; j<size; j++) {\n\
1458 var bodyj = this.bodies[j];\n\
1459 dx = bodyi.x - bodyj.x;\n\
1460 dy = bodyi.y - bodyj.y;\n\
1461 dz = bodyi.z - bodyj.z;\n\
1463 distance = Math.sqrt(dx*dx + dy*dy + dz*dz);\n\
1464 mag = dt / (distance * distance * distance);\n\
1466 bodyi.vx -= dx * bodyj.mass * mag;\n\
1467 bodyi.vy -= dy * bodyj.mass * mag;\n\
1468 bodyi.vz -= dz * bodyj.mass * mag;\n\
1470 bodyj.vx += dx * bodyi.mass * mag;\n\
1471 bodyj.vy += dy * bodyi.mass * mag;\n\
1472 bodyj.vz += dz * bodyi.mass * mag;\n\
1476 for (var i=0; i<size; i++) {\n\
1477 var body = this.bodies[i];\n\
1478 body.x += dt * body.vx;\n\
1479 body.y += dt * body.vy;\n\
1480 body.z += dt * body.vz;\n\
1484 NBodySystem.prototype.energy = function(){\n\
1485 var dx, dy, dz, distance;\n\
1487 var size = this.bodies.length;\n\
1489 for (var i=0; i<size; i++) {\n\
1490 var bodyi = this.bodies[i];\n\
1492 e += 0.5 * bodyi.mass *\n\
1493 ( bodyi.vx * bodyi.vx\n\
1494 + bodyi.vy * bodyi.vy\n\
1495 + bodyi.vz * bodyi.vz );\n\
1497 for (var j=i+1; j<size; j++) {\n\
1498 var bodyj = this.bodies[j];\n\
1499 dx = bodyi.x - bodyj.x;\n\
1500 dy = bodyi.y - bodyj.y;\n\
1501 dz = bodyi.z - bodyj.z;\n\
1503 distance = Math.sqrt(dx*dx + dy*dy + dz*dz);\n\
1504 e -= (bodyi.mass * bodyj.mass) / distance;\n\
1512 for ( var n = 3; n <= 24; n *= 2 ) {\n\
1514 var bodies = new NBodySystem( Array(\n\
1515 Sun(),Jupiter(),Saturn(),Uranus(),Neptune()\n\
1517 var max = n * 100;\n\
1519 ret += bodies.energy();\n\
1520 for (var i=0; i<max; i++){\n\
1521 bodies.advance(0.01);\n\
1523 ret += bodies.energy();\n\
1527 var expected = -1.3524862408537381;\n\
1528 if (ret != expected)\n\
1529 throw \"ERROR: bad result: expected \" + expected + \" but got \" + ret;\n\
1533 var _sunSpiderInterval = new Date() - _sunSpiderStartDate;\n\
1535 record(_sunSpiderInterval);\n\
1541 ", "<!DOCTYPE html>\n\
1544 <meta charset=utf8>\n\
1547 Copyright (C) 2007 Apple Inc. All rights reserved.\n\
1549 Redistribution and use in source and binary forms, with or without\n\
1550 modification, are permitted provided that the following conditions\n\
1552 1. Redistributions of source code must retain the above copyright\n\
1553 notice, this list of conditions and the following disclaimer.\n\
1554 2. Redistributions in binary form must reproduce the above copyright\n\
1555 notice, this list of conditions and the following disclaimer in the\n\
1556 documentation and/or other materials provided with the distribution.\n\
1558 THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY\n\
1559 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n\
1560 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\n\
1561 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR\n\
1562 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,\n\
1563 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,\n\
1564 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n\
1565 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY\n\
1566 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n\
1567 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n\
1568 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \n\
1571 <title>SunSpider access-nsieve</title>\n\
1572 <link rel=\"stylesheet\" href=\"../sunspider.css\">\n\
1576 <h3>access-nsieve</h3>\n\
1577 <div id=\"console\">\n\
1580 function record(time) {\n\
1581 document.getElementById(\"console\").innerHTML = time + \"ms\";\n\
1582 if (window.parent) {\n\
1583 parent.recordResult(time);\n\
1587 window.onerror = function(e) {\n\
1588 console.log(\"access-nsieve failed with error: \" + e);\n\
1592 var _sunSpiderStartDate = new Date();\n\
1594 // The Great Computer Language Shootout\n\
1595 // http://shootout.alioth.debian.org/\n\
1597 // modified by Isaac Gouy\n\
1599 function pad(number,width){\n\
1600 var s = number.toString();\n\
1601 var prefixWidth = width - s.length;\n\
1602 if (prefixWidth>0){\n\
1603 for (var i=1; i<=prefixWidth; i++) s = \" \" + s;\n\
1608 function nsieve(m, isPrime){\n\
1611 for (i=2; i<=m; i++) { isPrime[i] = true; }\n\
1614 for (i=2; i<=m; i++){\n\
1615 if (isPrime[i]) {\n\
1616 for (k=i+i; k<=m; k+=i) isPrime[k] = false;\n\
1623 function sieve() {\n\
1625 for (var i = 1; i <= 3; i++ ) {\n\
1626 var m = (1<<i)*10000;\n\
1627 var flags = Array(m+1);\n\
1628 sum += nsieve(m, flags);\n\
1633 var result = sieve();\n\
1635 var expected = 14302;\n\
1636 if (result != expected)\n\
1637 throw \"ERROR: bad result: expected \" + expected + \" but got \" + result;\n\
1642 var _sunSpiderInterval = new Date() - _sunSpiderStartDate;\n\
1644 record(_sunSpiderInterval);\n\
1650 ", "<!DOCTYPE html>\n\
1653 <meta charset=utf8>\n\
1656 Copyright (C) 2007 Apple Inc. All rights reserved.\n\
1658 Redistribution and use in source and binary forms, with or without\n\
1659 modification, are permitted provided that the following conditions\n\
1661 1. Redistributions of source code must retain the above copyright\n\
1662 notice, this list of conditions and the following disclaimer.\n\
1663 2. Redistributions in binary form must reproduce the above copyright\n\
1664 notice, this list of conditions and the following disclaimer in the\n\
1665 documentation and/or other materials provided with the distribution.\n\
1667 THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY\n\
1668 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n\
1669 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\n\
1670 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR\n\
1671 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,\n\
1672 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,\n\
1673 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n\
1674 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY\n\
1675 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n\
1676 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n\
1677 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \n\
1680 <title>SunSpider bitops-3bit-bits-in-byte</title>\n\
1681 <link rel=\"stylesheet\" href=\"../sunspider.css\">\n\
1685 <h3>bitops-3bit-bits-in-byte</h3>\n\
1686 <div id=\"console\">\n\
1689 function record(time) {\n\
1690 document.getElementById(\"console\").innerHTML = time + \"ms\";\n\
1691 if (window.parent) {\n\
1692 parent.recordResult(time);\n\
1696 window.onerror = function(e) {\n\
1697 console.log(\"bitops-3bit-bits-in-byte failed with error: \" + e);\n\
1701 var _sunSpiderStartDate = new Date();\n\
1703 // Copyright (c) 2004 by Arthur Langereis (arthur_ext at domain xfinitegames, tld com\n\
1707 // 1 op = 6 ANDs, 3 SHRs, 3 SHLs, 4 assigns, 2 ADDs\n\
1709 function fast3bitlookup(b) {\n\
1710 var c, bi3b = 0xE994; // 0b1110 1001 1001 0100; // 3 2 2 1 2 1 1 0\n\
1711 c = 3 & (bi3b >> ((b << 1) & 14));\n\
1712 c += 3 & (bi3b >> ((b >> 2) & 14));\n\
1713 c += 3 & (bi3b >> ((b >> 5) & 6));\n\
1717 lir4,0xE994; 9 instructions, no memory access, minimal register dependence, 6 shifts, 2 adds, 1 inline assign\n\
1718 rlwinmr5,r3,1,28,30\n\
1719 rlwinmr6,r3,30,28,30\n\
1720 rlwinmr7,r3,27,29,30\n\
1721 rlwnmr8,r4,r5,30,31\n\
1722 rlwnmr9,r4,r6,30,31\n\
1723 rlwnmr10,r4,r7,30,31\n\
1730 function TimeFunc(func) {\n\
1733 for(var x=0; x<500; x++)\n\
1734 for(var y=0; y<256; y++) sum += func(y);\n\
1738 sum = TimeFunc(fast3bitlookup);\n\
1740 var expected = 512000;\n\
1741 if (sum != expected)\n\
1742 throw \"ERROR: bad result: expected \" + expected + \" but got \" + sum;\n\
1745 var _sunSpiderInterval = new Date() - _sunSpiderStartDate;\n\
1747 record(_sunSpiderInterval);\n\
1753 ", "<!DOCTYPE html>\n\
1756 <meta charset=utf8>\n\
1759 Copyright (C) 2007 Apple Inc. All rights reserved.\n\
1761 Redistribution and use in source and binary forms, with or without\n\
1762 modification, are permitted provided that the following conditions\n\
1764 1. Redistributions of source code must retain the above copyright\n\
1765 notice, this list of conditions and the following disclaimer.\n\
1766 2. Redistributions in binary form must reproduce the above copyright\n\
1767 notice, this list of conditions and the following disclaimer in the\n\
1768 documentation and/or other materials provided with the distribution.\n\
1770 THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY\n\
1771 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n\
1772 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\n\
1773 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR\n\
1774 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,\n\
1775 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,\n\
1776 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n\
1777 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY\n\
1778 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n\
1779 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n\
1780 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \n\
1783 <title>SunSpider bitops-bits-in-byte</title>\n\
1784 <link rel=\"stylesheet\" href=\"../sunspider.css\">\n\
1788 <h3>bitops-bits-in-byte</h3>\n\
1789 <div id=\"console\">\n\
1792 function record(time) {\n\
1793 document.getElementById(\"console\").innerHTML = time + \"ms\";\n\
1794 if (window.parent) {\n\
1795 parent.recordResult(time);\n\
1799 window.onerror = function(e) {\n\
1800 console.log(\"bitops-bits-in-byte failed with error: \" + e);\n\
1804 var _sunSpiderStartDate = new Date();\n\
1806 // Copyright (c) 2004 by Arthur Langereis (arthur_ext at domain xfinitegames, tld com)\n\
1811 // 1 op = 2 assigns, 16 compare/branches, 8 ANDs, (0-8) ADDs, 8 SHLs\n\
1813 function bitsinbyte(b) {\n\
1814 var m = 1, c = 0;\n\
1822 function TimeFunc(func) {\n\
1825 for(var x=0; x<350; x++)\n\
1826 for(var y=0; y<256; y++) sum += func(y);\n\
1830 result = TimeFunc(bitsinbyte);\n\
1832 var expected = 358400;\n\
1833 if (result != expected)\n\
1834 throw \"ERROR: bad result: expected \" + expected + \" but got \" + result;\n\
1838 var _sunSpiderInterval = new Date() - _sunSpiderStartDate;\n\
1840 record(_sunSpiderInterval);\n\
1846 ", "<!DOCTYPE html>\n\
1849 <meta charset=utf8>\n\
1852 Copyright (C) 2007 Apple Inc. All rights reserved.\n\
1854 Redistribution and use in source and binary forms, with or without\n\
1855 modification, are permitted provided that the following conditions\n\
1857 1. Redistributions of source code must retain the above copyright\n\
1858 notice, this list of conditions and the following disclaimer.\n\
1859 2. Redistributions in binary form must reproduce the above copyright\n\
1860 notice, this list of conditions and the following disclaimer in the\n\
1861 documentation and/or other materials provided with the distribution.\n\
1863 THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY\n\
1864 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n\
1865 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\n\
1866 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR\n\
1867 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,\n\
1868 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,\n\
1869 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n\
1870 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY\n\
1871 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n\
1872 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n\
1873 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \n\
1876 <title>SunSpider bitops-bitwise-and</title>\n\
1877 <link rel=\"stylesheet\" href=\"../sunspider.css\">\n\
1881 <h3>bitops-bitwise-and</h3>\n\
1882 <div id=\"console\">\n\
1885 function record(time) {\n\
1886 document.getElementById(\"console\").innerHTML = time + \"ms\";\n\
1887 if (window.parent) {\n\
1888 parent.recordResult(time);\n\
1892 window.onerror = function(e) {\n\
1893 console.log(\"bitops-bitwise-and failed with error: \" + e);\n\
1897 var _sunSpiderStartDate = new Date();\n\
1900 * Copyright (C) 2007 Apple Inc. All rights reserved.\n\
1902 * Redistribution and use in source and binary forms, with or without\n\
1903 * modification, are permitted provided that the following conditions\n\
1905 * 1. Redistributions of source code must retain the above copyright\n\
1906 * notice, this list of conditions and the following disclaimer.\n\
1907 * 2. Redistributions in binary form must reproduce the above copyright\n\
1908 * notice, this list of conditions and the following disclaimer in the\n\
1909 * documentation and/or other materials provided with the distribution.\n\
1911 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY\n\
1912 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n\
1913 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\n\
1914 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR\n\
1915 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,\n\
1916 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,\n\
1917 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n\
1918 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY\n\
1919 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n\
1920 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n\
1921 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \n\
1924 bitwiseAndValue = 4294967296;\n\
1925 for (var i = 0; i < 600000; i++)\n\
1926 bitwiseAndValue = bitwiseAndValue & i;\n\
1928 var result = bitwiseAndValue;\n\
1930 var expected = 0;\n\
1931 if (result != expected)\n\
1932 throw \"ERROR: bad result: expected \" + expected + \" but got \" + result;\n\
1936 var _sunSpiderInterval = new Date() - _sunSpiderStartDate;\n\
1938 record(_sunSpiderInterval);\n\
1944 ", "<!DOCTYPE html>\n\
1947 <meta charset=utf8>\n\
1950 Copyright (C) 2007 Apple Inc. All rights reserved.\n\
1952 Redistribution and use in source and binary forms, with or without\n\
1953 modification, are permitted provided that the following conditions\n\
1955 1. Redistributions of source code must retain the above copyright\n\
1956 notice, this list of conditions and the following disclaimer.\n\
1957 2. Redistributions in binary form must reproduce the above copyright\n\
1958 notice, this list of conditions and the following disclaimer in the\n\
1959 documentation and/or other materials provided with the distribution.\n\
1961 THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY\n\
1962 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n\
1963 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\n\
1964 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR\n\
1965 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,\n\
1966 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,\n\
1967 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n\
1968 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY\n\
1969 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n\
1970 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n\
1971 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \n\
1974 <title>SunSpider bitops-nsieve-bits</title>\n\
1975 <link rel=\"stylesheet\" href=\"../sunspider.css\">\n\
1979 <h3>bitops-nsieve-bits</h3>\n\
1980 <div id=\"console\">\n\
1983 function record(time) {\n\
1984 document.getElementById(\"console\").innerHTML = time + \"ms\";\n\
1985 if (window.parent) {\n\
1986 parent.recordResult(time);\n\
1990 window.onerror = function(e) {\n\
1991 console.log(\"bitops-nsieve-bits failed with error: \" + e);\n\
1995 var _sunSpiderStartDate = new Date();\n\
1997 // The Great Computer Language Shootout\n\
1998 // http://shootout.alioth.debian.org\n\
2000 // Contributed by Ian Osgood\n\
2002 function pad(n,width) {\n\
2003 var s = n.toString();\n\
2004 while (s.length < width) s = ' ' + s;\n\
2008 function primes(isPrime, n) {\n\
2009 var i, count = 0, m = 10000<<n, size = m+31>>5;\n\
2011 for (i=0; i<size; i++) isPrime[i] = 0xffffffff;\n\
2013 for (i=2; i<m; i++)\n\
2014 if (isPrime[i>>5] & 1<<(i&31)) {\n\
2015 for (var j=i+i; j<m; j+=i)\n\
2016 isPrime[j>>5] &= ~(1<<(j&31));\n\
2021 function sieve() {\n\
2022 for (var i = 4; i <= 4; i++) {\n\
2023 var isPrime = new Array((10000<<i)+31>>5);\n\
2024 primes(isPrime, i);\n\
2029 var result = sieve();\n\
2032 for (var i = 0; i < result.length; ++i)\n\
2033 sum += result[i];\n\
2035 var expected = -1286749544853;\n\
2036 if (sum != expected)\n\
2037 throw \"ERROR: bad result: expected \" + expected + \" but got \" + sum;\n\
2041 var _sunSpiderInterval = new Date() - _sunSpiderStartDate;\n\
2043 record(_sunSpiderInterval);\n\
2049 ", "<!DOCTYPE html>\n\
2052 <meta charset=utf8>\n\
2055 Copyright (C) 2007 Apple Inc. All rights reserved.\n\
2057 Redistribution and use in source and binary forms, with or without\n\
2058 modification, are permitted provided that the following conditions\n\
2060 1. Redistributions of source code must retain the above copyright\n\
2061 notice, this list of conditions and the following disclaimer.\n\
2062 2. Redistributions in binary form must reproduce the above copyright\n\
2063 notice, this list of conditions and the following disclaimer in the\n\
2064 documentation and/or other materials provided with the distribution.\n\
2066 THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY\n\
2067 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n\
2068 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\n\
2069 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR\n\
2070 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,\n\
2071 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,\n\
2072 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n\
2073 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY\n\
2074 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n\
2075 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n\
2076 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \n\
2079 <title>SunSpider controlflow-recursive</title>\n\
2080 <link rel=\"stylesheet\" href=\"../sunspider.css\">\n\
2084 <h3>controlflow-recursive</h3>\n\
2085 <div id=\"console\">\n\
2088 function record(time) {\n\
2089 document.getElementById(\"console\").innerHTML = time + \"ms\";\n\
2090 if (window.parent) {\n\
2091 parent.recordResult(time);\n\
2095 window.onerror = function(e) {\n\
2096 console.log(\"controlflow-recursive failed with error: \" + e);\n\
2100 var _sunSpiderStartDate = new Date();\n\
2102 // The Computer Language Shootout\n\
2103 // http://shootout.alioth.debian.org/\n\
2104 // contributed by Isaac Gouy\n\
2106 function ack(m,n){\n\
2107 if (m==0) { return n+1; }\n\
2108 if (n==0) { return ack(m-1,1); }\n\
2109 return ack(m-1, ack(m,n-1) );\n\
2112 function fib(n) {\n\
2113 if (n < 2){ return 1; }\n\
2114 return fib(n-2) + fib(n-1);\n\
2117 function tak(x,y,z) {\n\
2118 if (y >= x) return z;\n\
2119 return tak(tak(x-1,y,z), tak(y-1,z,x), tak(z-1,x,y));\n\
2124 for ( var i = 3; i <= 5; i++ ) {\n\
2125 result += ack(3,i);\n\
2126 result += fib(17.0+i);\n\
2127 result += tak(3*i+3,2*i+2,i+1);\n\
2130 var expected = 57775;\n\
2131 if (result != expected)\n\
2132 throw \"ERROR: bad result: expected \" + expected + \" but got \" + result;\n\
2136 var _sunSpiderInterval = new Date() - _sunSpiderStartDate;\n\
2138 record(_sunSpiderInterval);\n\
2144 ", "<!DOCTYPE html>\n\
2147 <meta charset=utf8>\n\
2150 Copyright (C) 2007 Apple Inc. All rights reserved.\n\
2152 Redistribution and use in source and binary forms, with or without\n\
2153 modification, are permitted provided that the following conditions\n\
2155 1. Redistributions of source code must retain the above copyright\n\
2156 notice, this list of conditions and the following disclaimer.\n\
2157 2. Redistributions in binary form must reproduce the above copyright\n\
2158 notice, this list of conditions and the following disclaimer in the\n\
2159 documentation and/or other materials provided with the distribution.\n\
2161 THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY\n\
2162 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n\
2163 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\n\
2164 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR\n\
2165 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,\n\
2166 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,\n\
2167 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n\
2168 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY\n\
2169 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n\
2170 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n\
2171 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \n\
2174 <title>SunSpider crypto-aes</title>\n\
2175 <link rel=\"stylesheet\" href=\"../sunspider.css\">\n\
2179 <h3>crypto-aes</h3>\n\
2180 <div id=\"console\">\n\
2183 function record(time) {\n\
2184 document.getElementById(\"console\").innerHTML = time + \"ms\";\n\
2185 if (window.parent) {\n\
2186 parent.recordResult(time);\n\
2190 window.onerror = function(e) {\n\
2191 console.log(\"crypto-aes failed with error: \" + e);\n\
2195 var _sunSpiderStartDate = new Date();\n\
2197 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */\n\
2200 * AES Cipher function: encrypt 'input' with Rijndael algorithm\n\
2202 * takes byte-array 'input' (16 bytes)\n\
2203 * 2D byte-array key schedule 'w' (Nr+1 x Nb bytes)\n\
2205 * applies Nr rounds (10/12/14) using key schedule w for 'add round key' stage\n\
2207 * returns byte-array encrypted value (16 bytes)\n\
2209 function Cipher(input, w) { // main Cipher function [§5.1]\n\
2210 var Nb = 4; // block size (in words): no of columns in state (fixed at 4 for AES)\n\
2211 var Nr = w.length/Nb - 1; // no of rounds: 10/12/14 for 128/192/256-bit keys\n\
2213 var state = [[],[],[],[]]; // initialise 4xNb byte-array 'state' with input [§3.4]\n\
2214 for (var i=0; i<4*Nb; i++) state[i%4][Math.floor(i/4)] = input[i];\n\
2216 state = AddRoundKey(state, w, 0, Nb);\n\
2218 for (var round=1; round<Nr; round++) {\n\
2219 state = SubBytes(state, Nb);\n\
2220 state = ShiftRows(state, Nb);\n\
2221 state = MixColumns(state, Nb);\n\
2222 state = AddRoundKey(state, w, round, Nb);\n\
2225 state = SubBytes(state, Nb);\n\
2226 state = ShiftRows(state, Nb);\n\
2227 state = AddRoundKey(state, w, Nr, Nb);\n\
2229 var output = new Array(4*Nb); // convert state to 1-d array before returning [§3.4]\n\
2230 for (var i=0; i<4*Nb; i++) output[i] = state[i%4][Math.floor(i/4)];\n\
2235 function SubBytes(s, Nb) { // apply SBox to state S [§5.1.1]\n\
2236 for (var r=0; r<4; r++) {\n\
2237 for (var c=0; c<Nb; c++) s[r][c] = Sbox[s[r][c]];\n\
2243 function ShiftRows(s, Nb) { // shift row r of state S left by r bytes [§5.1.2]\n\
2244 var t = new Array(4);\n\
2245 for (var r=1; r<4; r++) {\n\
2246 for (var c=0; c<4; c++) t[c] = s[r][(c+r)%Nb]; // shift into temp copy\n\
2247 for (var c=0; c<4; c++) s[r][c] = t[c]; // and copy back\n\
2248 } // note that this will work for Nb=4,5,6, but not 7,8 (always 4 for AES):\n\
2249 return s; // see fp.gladman.plus.com/cryptography_technology/rijndael/aes.spec.311.pdf \n\
2253 function MixColumns(s, Nb) { // combine bytes of each col of state S [§5.1.3]\n\
2254 for (var c=0; c<4; c++) {\n\
2255 var a = new Array(4); // 'a' is a copy of the current column from 's'\n\
2256 var b = new Array(4); // 'b' is a•{02} in GF(2^8)\n\
2257 for (var i=0; i<4; i++) {\n\
2259 b[i] = s[i][c]&0x80 ? s[i][c]<<1 ^ 0x011b : s[i][c]<<1;\n\
2261 // a[n] ^ b[n] is a•{03} in GF(2^8)\n\
2262 s[0][c] = b[0] ^ a[1] ^ b[1] ^ a[2] ^ a[3]; // 2*a0 + 3*a1 + a2 + a3\n\
2263 s[1][c] = a[0] ^ b[1] ^ a[2] ^ b[2] ^ a[3]; // a0 * 2*a1 + 3*a2 + a3\n\
2264 s[2][c] = a[0] ^ a[1] ^ b[2] ^ a[3] ^ b[3]; // a0 + a1 + 2*a2 + 3*a3\n\
2265 s[3][c] = a[0] ^ b[0] ^ a[1] ^ a[2] ^ b[3]; // 3*a0 + a1 + a2 + 2*a3\n\
2271 function AddRoundKey(state, w, rnd, Nb) { // xor Round Key into state S [§5.1.4]\n\
2272 for (var r=0; r<4; r++) {\n\
2273 for (var c=0; c<Nb; c++) state[r][c] ^= w[rnd*4+c][r];\n\
2279 function KeyExpansion(key) { // generate Key Schedule (byte-array Nr+1 x Nb) from Key [§5.2]\n\
2280 var Nb = 4; // block size (in words): no of columns in state (fixed at 4 for AES)\n\
2281 var Nk = key.length/4 // key length (in words): 4/6/8 for 128/192/256-bit keys\n\
2282 var Nr = Nk + 6; // no of rounds: 10/12/14 for 128/192/256-bit keys\n\
2284 var w = new Array(Nb*(Nr+1));\n\
2285 var temp = new Array(4);\n\
2287 for (var i=0; i<Nk; i++) {\n\
2288 var r = [key[4*i], key[4*i+1], key[4*i+2], key[4*i+3]];\n\
2292 for (var i=Nk; i<(Nb*(Nr+1)); i++) {\n\
2293 w[i] = new Array(4);\n\
2294 for (var t=0; t<4; t++) temp[t] = w[i-1][t];\n\
2295 if (i % Nk == 0) {\n\
2296 temp = SubWord(RotWord(temp));\n\
2297 for (var t=0; t<4; t++) temp[t] ^= Rcon[i/Nk][t];\n\
2298 } else if (Nk > 6 && i%Nk == 4) {\n\
2299 temp = SubWord(temp);\n\
2301 for (var t=0; t<4; t++) w[i][t] = w[i-Nk][t] ^ temp[t];\n\
2307 function SubWord(w) { // apply SBox to 4-byte word w\n\
2308 for (var i=0; i<4; i++) w[i] = Sbox[w[i]];\n\
2312 function RotWord(w) { // rotate 4-byte word w left by one byte\n\
2314 for (var i=0; i<4; i++) w[i] = w[i+1];\n\
2319 // Sbox is pre-computed multiplicative inverse in GF(2^8) used in SubBytes and KeyExpansion [§5.1.1]\n\
2320 var Sbox = [0x63,0x7c,0x77,0x7b,0xf2,0x6b,0x6f,0xc5,0x30,0x01,0x67,0x2b,0xfe,0xd7,0xab,0x76,\n\
2321 0xca,0x82,0xc9,0x7d,0xfa,0x59,0x47,0xf0,0xad,0xd4,0xa2,0xaf,0x9c,0xa4,0x72,0xc0,\n\
2322 0xb7,0xfd,0x93,0x26,0x36,0x3f,0xf7,0xcc,0x34,0xa5,0xe5,0xf1,0x71,0xd8,0x31,0x15,\n\
2323 0x04,0xc7,0x23,0xc3,0x18,0x96,0x05,0x9a,0x07,0x12,0x80,0xe2,0xeb,0x27,0xb2,0x75,\n\
2324 0x09,0x83,0x2c,0x1a,0x1b,0x6e,0x5a,0xa0,0x52,0x3b,0xd6,0xb3,0x29,0xe3,0x2f,0x84,\n\
2325 0x53,0xd1,0x00,0xed,0x20,0xfc,0xb1,0x5b,0x6a,0xcb,0xbe,0x39,0x4a,0x4c,0x58,0xcf,\n\
2326 0xd0,0xef,0xaa,0xfb,0x43,0x4d,0x33,0x85,0x45,0xf9,0x02,0x7f,0x50,0x3c,0x9f,0xa8,\n\
2327 0x51,0xa3,0x40,0x8f,0x92,0x9d,0x38,0xf5,0xbc,0xb6,0xda,0x21,0x10,0xff,0xf3,0xd2,\n\
2328 0xcd,0x0c,0x13,0xec,0x5f,0x97,0x44,0x17,0xc4,0xa7,0x7e,0x3d,0x64,0x5d,0x19,0x73,\n\
2329 0x60,0x81,0x4f,0xdc,0x22,0x2a,0x90,0x88,0x46,0xee,0xb8,0x14,0xde,0x5e,0x0b,0xdb,\n\
2330 0xe0,0x32,0x3a,0x0a,0x49,0x06,0x24,0x5c,0xc2,0xd3,0xac,0x62,0x91,0x95,0xe4,0x79,\n\
2331 0xe7,0xc8,0x37,0x6d,0x8d,0xd5,0x4e,0xa9,0x6c,0x56,0xf4,0xea,0x65,0x7a,0xae,0x08,\n\
2332 0xba,0x78,0x25,0x2e,0x1c,0xa6,0xb4,0xc6,0xe8,0xdd,0x74,0x1f,0x4b,0xbd,0x8b,0x8a,\n\
2333 0x70,0x3e,0xb5,0x66,0x48,0x03,0xf6,0x0e,0x61,0x35,0x57,0xb9,0x86,0xc1,0x1d,0x9e,\n\
2334 0xe1,0xf8,0x98,0x11,0x69,0xd9,0x8e,0x94,0x9b,0x1e,0x87,0xe9,0xce,0x55,0x28,0xdf,\n\
2335 0x8c,0xa1,0x89,0x0d,0xbf,0xe6,0x42,0x68,0x41,0x99,0x2d,0x0f,0xb0,0x54,0xbb,0x16];\n\
2337 // Rcon is Round Constant used for the Key Expansion [1st col is 2^(r-1) in GF(2^8)] [§5.2]\n\
2338 var Rcon = [ [0x00, 0x00, 0x00, 0x00],\n\
2339 [0x01, 0x00, 0x00, 0x00],\n\
2340 [0x02, 0x00, 0x00, 0x00],\n\
2341 [0x04, 0x00, 0x00, 0x00],\n\
2342 [0x08, 0x00, 0x00, 0x00],\n\
2343 [0x10, 0x00, 0x00, 0x00],\n\
2344 [0x20, 0x00, 0x00, 0x00],\n\
2345 [0x40, 0x00, 0x00, 0x00],\n\
2346 [0x80, 0x00, 0x00, 0x00],\n\
2347 [0x1b, 0x00, 0x00, 0x00],\n\
2348 [0x36, 0x00, 0x00, 0x00] ]; \n\
2351 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */\n\
2354 * Use AES to encrypt 'plaintext' with 'password' using 'nBits' key, in 'Counter' mode of operation\n\
2355 * - see http://csrc.nist.gov/publications/nistpubs/800-38a/sp800-38a.pdf\n\
2357 * - outputblock = cipher(counter, key)\n\
2358 * - cipherblock = plaintext xor outputblock\n\
2360 function AESEncryptCtr(plaintext, password, nBits) {\n\
2361 if (!(nBits==128 || nBits==192 || nBits==256)) return ''; // standard allows 128/192/256 bit keys\n\
2363 // for this example script, generate the key by applying Cipher to 1st 16/24/32 chars of password; \n\
2364 // for real-world applications, a more secure approach would be to hash the password e.g. with SHA-1\n\
2365 var nBytes = nBits/8; // no bytes in key\n\
2366 var pwBytes = new Array(nBytes);\n\
2367 for (var i=0; i<nBytes; i++) pwBytes[i] = password.charCodeAt(i) & 0xff;\n\
2368 var key = Cipher(pwBytes, KeyExpansion(pwBytes));\n\
2369 key = key.concat(key.slice(0, nBytes-16)); // key is now 16/24/32 bytes long\n\
2371 // initialise counter block (NIST SP800-38A §B.2): millisecond time-stamp for nonce in 1st 8 bytes,\n\
2372 // block counter in 2nd 8 bytes\n\
2373 var blockSize = 16; // block size fixed at 16 bytes / 128 bits (Nb=4) for AES\n\
2374 var counterBlock = new Array(blockSize); // block size fixed at 16 bytes / 128 bits (Nb=4) for AES\n\
2375 var nonce = (new Date()).getTime(); // milliseconds since 1-Jan-1970\n\
2377 // encode nonce in two stages to cater for JavaScript 32-bit limit on bitwise ops\n\
2378 for (var i=0; i<4; i++) counterBlock[i] = (nonce >>> i*8) & 0xff;\n\
2379 for (var i=0; i<4; i++) counterBlock[i+4] = (nonce/0x100000000 >>> i*8) & 0xff; \n\
2381 // generate key schedule - an expansion of the key into distinct Key Rounds for each round\n\
2382 var keySchedule = KeyExpansion(key);\n\
2384 var blockCount = Math.ceil(plaintext.length/blockSize);\n\
2385 var ciphertext = new Array(blockCount); // ciphertext as array of strings\n\
2387 for (var b=0; b<blockCount; b++) {\n\
2388 // set counter (block #) in last 8 bytes of counter block (leaving nonce in 1st 8 bytes)\n\
2389 // again done in two stages for 32-bit ops\n\
2390 for (var c=0; c<4; c++) counterBlock[15-c] = (b >>> c*8) & 0xff;\n\
2391 for (var c=0; c<4; c++) counterBlock[15-c-4] = (b/0x100000000 >>> c*8)\n\
2393 var cipherCntr = Cipher(counterBlock, keySchedule); // -- encrypt counter block --\n\
2395 // calculate length of final block:\n\
2396 var blockLength = b<blockCount-1 ? blockSize : (plaintext.length-1)%blockSize+1;\n\
2399 for (var i=0; i<blockLength; i++) { // -- xor plaintext with ciphered counter byte-by-byte --\n\
2400 var plaintextByte = plaintext.charCodeAt(b*blockSize+i);\n\
2401 var cipherByte = plaintextByte ^ cipherCntr[i];\n\
2402 ct += String.fromCharCode(cipherByte);\n\
2404 // ct is now ciphertext for this block\n\
2406 ciphertext[b] = escCtrlChars(ct); // escape troublesome characters in ciphertext\n\
2409 // convert the nonce to a string to go on the front of the ciphertext\n\
2411 for (var i=0; i<8; i++) ctrTxt += String.fromCharCode(counterBlock[i]);\n\
2412 ctrTxt = escCtrlChars(ctrTxt);\n\
2414 // use '-' to separate blocks, use Array.join to concatenate arrays of strings for efficiency\n\
2415 return ctrTxt + '-' + ciphertext.join('-');\n\
2420 * Use AES to decrypt 'ciphertext' with 'password' using 'nBits' key, in Counter mode of operation\n\
2423 * - outputblock = cipher(counter, key)\n\
2424 * - cipherblock = plaintext xor outputblock\n\
2426 function AESDecryptCtr(ciphertext, password, nBits) {\n\
2427 if (!(nBits==128 || nBits==192 || nBits==256)) return ''; // standard allows 128/192/256 bit keys\n\
2429 var nBytes = nBits/8; // no bytes in key\n\
2430 var pwBytes = new Array(nBytes);\n\
2431 for (var i=0; i<nBytes; i++) pwBytes[i] = password.charCodeAt(i) & 0xff;\n\
2432 var pwKeySchedule = KeyExpansion(pwBytes);\n\
2433 var key = Cipher(pwBytes, pwKeySchedule);\n\
2434 key = key.concat(key.slice(0, nBytes-16)); // key is now 16/24/32 bytes long\n\
2436 var keySchedule = KeyExpansion(key);\n\
2438 ciphertext = ciphertext.split('-'); // split ciphertext into array of block-length strings \n\
2440 // recover nonce from 1st element of ciphertext\n\
2441 var blockSize = 16; // block size fixed at 16 bytes / 128 bits (Nb=4) for AES\n\
2442 var counterBlock = new Array(blockSize);\n\
2443 var ctrTxt = unescCtrlChars(ciphertext[0]);\n\
2444 for (var i=0; i<8; i++) counterBlock[i] = ctrTxt.charCodeAt(i);\n\
2446 var plaintext = new Array(ciphertext.length-1);\n\
2448 for (var b=1; b<ciphertext.length; b++) {\n\
2449 // set counter (block #) in last 8 bytes of counter block (leaving nonce in 1st 8 bytes)\n\
2450 for (var c=0; c<4; c++) counterBlock[15-c] = ((b-1) >>> c*8) & 0xff;\n\
2451 for (var c=0; c<4; c++) counterBlock[15-c-4] = ((b/0x100000000-1) >>> c*8) & 0xff;\n\
2453 var cipherCntr = Cipher(counterBlock, keySchedule); // encrypt counter block\n\
2455 ciphertext[b] = unescCtrlChars(ciphertext[b]);\n\
2458 for (var i=0; i<ciphertext[b].length; i++) {\n\
2459 // -- xor plaintext with ciphered counter byte-by-byte --\n\
2460 var ciphertextByte = ciphertext[b].charCodeAt(i);\n\
2461 var plaintextByte = ciphertextByte ^ cipherCntr[i];\n\
2462 pt += String.fromCharCode(plaintextByte);\n\
2464 // pt is now plaintext for this block\n\
2466 plaintext[b-1] = pt; // b-1 'cos no initial nonce block in plaintext\n\
2469 return plaintext.join('');\n\
2472 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */\n\
2474 function escCtrlChars(str) { // escape control chars which might cause problems handling ciphertext\n\
2475 return str.replace(/[\\0\\t\\n\\v\\f\\r\\xa0'\"!-]/g, function(c) { return '!' + c.charCodeAt(0) + '!'; });\n\
2476 } // \\xa0 to cater for bug in Firefox; include '-' to leave it free for use as a block marker\n\
2478 function unescCtrlChars(str) { // unescape potentially problematic control characters\n\
2479 return str.replace(/!\\d\\d?\\d?!/g, function(c) { return String.fromCharCode(c.slice(1,-1)); });\n\
2481 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */\n\
2484 * if escCtrlChars()/unescCtrlChars() still gives problems, use encodeBase64()/decodeBase64() instead\n\
2486 var b64 = \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=\";\n\
2488 function encodeBase64(str) { // http://tools.ietf.org/html/rfc4648\n\
2489 var o1, o2, o3, h1, h2, h3, h4, bits, i=0, enc='';\n\
2491 str = encodeUTF8(str); // encode multi-byte chars into UTF-8 for byte-array\n\
2493 do { // pack three octets into four hexets\n\
2494 o1 = str.charCodeAt(i++);\n\
2495 o2 = str.charCodeAt(i++);\n\
2496 o3 = str.charCodeAt(i++);\n\
2498 bits = o1<<16 | o2<<8 | o3;\n\
2500 h1 = bits>>18 & 0x3f;\n\
2501 h2 = bits>>12 & 0x3f;\n\
2502 h3 = bits>>6 & 0x3f;\n\
2503 h4 = bits & 0x3f;\n\
2505 // end of string? index to '=' in b64\n\
2506 if (isNaN(o3)) h4 = 64;\n\
2507 if (isNaN(o2)) h3 = 64;\n\
2509 // use hexets to index into b64, and append result to encoded string\n\
2510 enc += b64.charAt(h1) + b64.charAt(h2) + b64.charAt(h3) + b64.charAt(h4);\n\
2511 } while (i < str.length);\n\
2516 function decodeBase64(str) {\n\
2517 var o1, o2, o3, h1, h2, h3, h4, bits, i=0, enc='';\n\
2519 do { // unpack four hexets into three octets using index points in b64\n\
2520 h1 = b64.indexOf(str.charAt(i++));\n\
2521 h2 = b64.indexOf(str.charAt(i++));\n\
2522 h3 = b64.indexOf(str.charAt(i++));\n\
2523 h4 = b64.indexOf(str.charAt(i++));\n\
2525 bits = h1<<18 | h2<<12 | h3<<6 | h4;\n\
2527 o1 = bits>>16 & 0xff;\n\
2528 o2 = bits>>8 & 0xff;\n\
2529 o3 = bits & 0xff;\n\
2531 if (h3 == 64) enc += String.fromCharCode(o1);\n\
2532 else if (h4 == 64) enc += String.fromCharCode(o1, o2);\n\
2533 else enc += String.fromCharCode(o1, o2, o3);\n\
2534 } while (i < str.length);\n\
2536 return decodeUTF8(enc); // decode UTF-8 byte-array back to Unicode\n\
2539 function encodeUTF8(str) { // encode multi-byte string into utf-8 multiple single-byte characters \n\
2540 str = str.replace(\n\
2541 /[\\u0080-\\u07ff]/g, // U+0080 - U+07FF = 2-byte chars\n\
2543 var cc = c.charCodeAt(0);\n\
2544 return String.fromCharCode(0xc0 | cc>>6, 0x80 | cc&0x3f); }\n\
2546 str = str.replace(\n\
2547 /[\\u0800-\\uffff]/g, // U+0800 - U+FFFF = 3-byte chars\n\
2549 var cc = c.charCodeAt(0); \n\
2550 return String.fromCharCode(0xe0 | cc>>12, 0x80 | cc>>6&0x3F, 0x80 | cc&0x3f); }\n\
2555 function decodeUTF8(str) { // decode utf-8 encoded string back into multi-byte characters\n\
2556 str = str.replace(\n\
2557 /[\\u00c0-\\u00df][\\u0080-\\u00bf]/g, // 2-byte chars\n\
2559 var cc = (c.charCodeAt(0)&0x1f)<<6 | c.charCodeAt(1)&0x3f;\n\
2560 return String.fromCharCode(cc); }\n\
2562 str = str.replace(\n\
2563 /[\\u00e0-\\u00ef][\\u0080-\\u00bf][\\u0080-\\u00bf]/g, // 3-byte chars\n\
2565 var cc = (c.charCodeAt(0)&0x0f)<<12 | (c.charCodeAt(1)&0x3f<<6) | c.charCodeAt(2)&0x3f; \n\
2566 return String.fromCharCode(cc); }\n\
2572 function byteArrayToHexStr(b) { // convert byte array to hex string for displaying test vectors\n\
2574 for (var i=0; i<b.length; i++) s += b[i].toString(16) + ' ';\n\
2578 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */\n\
2581 var plainText = \"ROMEO: But, soft! what light through yonder window breaks?\\n\\\n\
2582 It is the east, and Juliet is the sun.\\n\\\n\
2583 Arise, fair sun, and kill the envious moon,\\n\\\n\
2584 Who is already sick and pale with grief,\\n\\\n\
2585 That thou her maid art far more fair than she:\\n\\\n\
2586 Be not her maid, since she is envious;\\n\\\n\
2587 Her vestal livery is but sick and green\\n\\\n\
2588 And none but fools do wear it; cast it off.\\n\\\n\
2589 It is my lady, O, it is my love!\\n\\\n\
2590 O, that she knew she were!\\n\\\n\
2591 She speaks yet she says nothing: what of that?\\n\\\n\
2592 Her eye discourses; I will answer it.\\n\\\n\
2593 I am too bold, 'tis not to me she speaks:\\n\\\n\
2594 Two of the fairest stars in all the heaven,\\n\\\n\
2595 Having some business, do entreat her eyes\\n\\\n\
2596 To twinkle in their spheres till they return.\\n\\\n\
2597 What if her eyes were there, they in her head?\\n\\\n\
2598 The brightness of her cheek would shame those stars,\\n\\\n\
2599 As daylight doth a lamp; her eyes in heaven\\n\\\n\
2600 Would through the airy region stream so bright\\n\\\n\
2601 That birds would sing and think it were not night.\\n\\\n\
2602 See, how she leans her cheek upon her hand!\\n\\\n\
2603 O, that I were a glove upon that hand,\\n\\\n\
2604 That I might touch that cheek!\\n\\\n\
2605 JULIET: Ay me!\\n\\\n\
2606 ROMEO: She speaks:\\n\\\n\
2607 O, speak again, bright angel! for thou art\\n\\\n\
2608 As glorious to this night, being o'er my head\\n\\\n\
2609 As is a winged messenger of heaven\\n\\\n\
2610 Unto the white-upturned wondering eyes\\n\\\n\
2611 Of mortals that fall back to gaze on him\\n\\\n\
2612 When he bestrides the lazy-pacing clouds\\n\\\n\
2613 And sails upon the bosom of the air.\";\n\
2615 var password = \"O Romeo, Romeo! wherefore art thou Romeo?\";\n\
2617 var cipherText = AESEncryptCtr(plainText, password, 256);\n\
2618 var decryptedText = AESDecryptCtr(cipherText, password, 256);\n\
2620 if (decryptedText != plainText)\n\
2621 throw \"ERROR: bad result: expected \" + plainText + \" but got \" + decryptedText;\n\
2625 var _sunSpiderInterval = new Date() - _sunSpiderStartDate;\n\
2627 record(_sunSpiderInterval);\n\
2633 ", "<!DOCTYPE html>\n\
2636 <meta charset=utf8>\n\
2639 Copyright (C) 2007 Apple Inc. All rights reserved.\n\
2641 Redistribution and use in source and binary forms, with or without\n\
2642 modification, are permitted provided that the following conditions\n\
2644 1. Redistributions of source code must retain the above copyright\n\
2645 notice, this list of conditions and the following disclaimer.\n\
2646 2. Redistributions in binary form must reproduce the above copyright\n\
2647 notice, this list of conditions and the following disclaimer in the\n\
2648 documentation and/or other materials provided with the distribution.\n\
2650 THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY\n\
2651 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n\
2652 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\n\
2653 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR\n\
2654 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,\n\
2655 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,\n\
2656 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n\
2657 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY\n\
2658 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n\
2659 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n\
2660 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \n\
2663 <title>SunSpider crypto-md5</title>\n\
2664 <link rel=\"stylesheet\" href=\"../sunspider.css\">\n\
2668 <h3>crypto-md5</h3>\n\
2669 <div id=\"console\">\n\
2672 function record(time) {\n\
2673 document.getElementById(\"console\").innerHTML = time + \"ms\";\n\
2674 if (window.parent) {\n\
2675 parent.recordResult(time);\n\
2679 window.onerror = function(e) {\n\
2680 console.log(\"crypto-md5 failed with error: \" + e);\n\
2684 var _sunSpiderStartDate = new Date();\n\
2687 * A JavaScript implementation of the RSA Data Security, Inc. MD5 Message\n\
2688 * Digest Algorithm, as defined in RFC 1321.\n\
2689 * Version 2.1 Copyright (C) Paul Johnston 1999 - 2002.\n\
2690 * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet\n\
2691 * Distributed under the BSD License\n\
2692 * See http://pajhome.org.uk/crypt/md5 for more info.\n\
2696 * Configurable variables. You may need to tweak these to be compatible with\n\
2697 * the server-side, but the defaults work in most cases.\n\
2699 var hexcase = 0; /* hex output format. 0 - lowercase; 1 - uppercase */\n\
2700 var b64pad = \"\"; /* base-64 pad character. \"=\" for strict RFC compliance */\n\
2701 var chrsz = 8; /* bits per input character. 8 - ASCII; 16 - Unicode */\n\
2704 * These are the functions you'll usually want to call\n\
2705 * They take string arguments and return either hex or base-64 encoded strings\n\
2707 function hex_md5(s){ return binl2hex(core_md5(str2binl(s), s.length * chrsz));}\n\
2708 function b64_md5(s){ return binl2b64(core_md5(str2binl(s), s.length * chrsz));}\n\
2709 function str_md5(s){ return binl2str(core_md5(str2binl(s), s.length * chrsz));}\n\
2710 function hex_hmac_md5(key, data) { return binl2hex(core_hmac_md5(key, data)); }\n\
2711 function b64_hmac_md5(key, data) { return binl2b64(core_hmac_md5(key, data)); }\n\
2712 function str_hmac_md5(key, data) { return binl2str(core_hmac_md5(key, data)); }\n\
2715 * Perform a simple self-test to see if the VM is working\n\
2717 function md5_vm_test()\n\
2719 return hex_md5(\"abc\") == \"900150983cd24fb0d6963f7d28e17f72\";\n\
2723 * Calculate the MD5 of an array of little-endian words, and a bit length\n\
2725 function core_md5(x, len)\n\
2727 /* append padding */\n\
2728 x[len >> 5] |= 0x80 << ((len) % 32);\n\
2729 x[(((len + 64) >>> 9) << 4) + 14] = len;\n\
2731 var a = 1732584193;\n\
2732 var b = -271733879;\n\
2733 var c = -1732584194;\n\
2734 var d = 271733878;\n\
2736 for(var i = 0; i < x.length; i += 16)\n\
2743 a = md5_ff(a, b, c, d, x[i+ 0], 7 , -680876936);\n\
2744 d = md5_ff(d, a, b, c, x[i+ 1], 12, -389564586);\n\
2745 c = md5_ff(c, d, a, b, x[i+ 2], 17, 606105819);\n\
2746 b = md5_ff(b, c, d, a, x[i+ 3], 22, -1044525330);\n\
2747 a = md5_ff(a, b, c, d, x[i+ 4], 7 , -176418897);\n\
2748 d = md5_ff(d, a, b, c, x[i+ 5], 12, 1200080426);\n\
2749 c = md5_ff(c, d, a, b, x[i+ 6], 17, -1473231341);\n\
2750 b = md5_ff(b, c, d, a, x[i+ 7], 22, -45705983);\n\
2751 a = md5_ff(a, b, c, d, x[i+ 8], 7 , 1770035416);\n\
2752 d = md5_ff(d, a, b, c, x[i+ 9], 12, -1958414417);\n\
2753 c = md5_ff(c, d, a, b, x[i+10], 17, -42063);\n\
2754 b = md5_ff(b, c, d, a, x[i+11], 22, -1990404162);\n\
2755 a = md5_ff(a, b, c, d, x[i+12], 7 , 1804603682);\n\
2756 d = md5_ff(d, a, b, c, x[i+13], 12, -40341101);\n\
2757 c = md5_ff(c, d, a, b, x[i+14], 17, -1502002290);\n\
2758 b = md5_ff(b, c, d, a, x[i+15], 22, 1236535329);\n\
2760 a = md5_gg(a, b, c, d, x[i+ 1], 5 , -165796510);\n\
2761 d = md5_gg(d, a, b, c, x[i+ 6], 9 , -1069501632);\n\
2762 c = md5_gg(c, d, a, b, x[i+11], 14, 643717713);\n\
2763 b = md5_gg(b, c, d, a, x[i+ 0], 20, -373897302);\n\
2764 a = md5_gg(a, b, c, d, x[i+ 5], 5 , -701558691);\n\
2765 d = md5_gg(d, a, b, c, x[i+10], 9 , 38016083);\n\
2766 c = md5_gg(c, d, a, b, x[i+15], 14, -660478335);\n\
2767 b = md5_gg(b, c, d, a, x[i+ 4], 20, -405537848);\n\
2768 a = md5_gg(a, b, c, d, x[i+ 9], 5 , 568446438);\n\
2769 d = md5_gg(d, a, b, c, x[i+14], 9 , -1019803690);\n\
2770 c = md5_gg(c, d, a, b, x[i+ 3], 14, -187363961);\n\
2771 b = md5_gg(b, c, d, a, x[i+ 8], 20, 1163531501);\n\
2772 a = md5_gg(a, b, c, d, x[i+13], 5 , -1444681467);\n\
2773 d = md5_gg(d, a, b, c, x[i+ 2], 9 , -51403784);\n\
2774 c = md5_gg(c, d, a, b, x[i+ 7], 14, 1735328473);\n\
2775 b = md5_gg(b, c, d, a, x[i+12], 20, -1926607734);\n\
2777 a = md5_hh(a, b, c, d, x[i+ 5], 4 , -378558);\n\
2778 d = md5_hh(d, a, b, c, x[i+ 8], 11, -2022574463);\n\
2779 c = md5_hh(c, d, a, b, x[i+11], 16, 1839030562);\n\
2780 b = md5_hh(b, c, d, a, x[i+14], 23, -35309556);\n\
2781 a = md5_hh(a, b, c, d, x[i+ 1], 4 , -1530992060);\n\
2782 d = md5_hh(d, a, b, c, x[i+ 4], 11, 1272893353);\n\
2783 c = md5_hh(c, d, a, b, x[i+ 7], 16, -155497632);\n\
2784 b = md5_hh(b, c, d, a, x[i+10], 23, -1094730640);\n\
2785 a = md5_hh(a, b, c, d, x[i+13], 4 , 681279174);\n\
2786 d = md5_hh(d, a, b, c, x[i+ 0], 11, -358537222);\n\
2787 c = md5_hh(c, d, a, b, x[i+ 3], 16, -722521979);\n\
2788 b = md5_hh(b, c, d, a, x[i+ 6], 23, 76029189);\n\
2789 a = md5_hh(a, b, c, d, x[i+ 9], 4 , -640364487);\n\
2790 d = md5_hh(d, a, b, c, x[i+12], 11, -421815835);\n\
2791 c = md5_hh(c, d, a, b, x[i+15], 16, 530742520);\n\
2792 b = md5_hh(b, c, d, a, x[i+ 2], 23, -995338651);\n\
2794 a = md5_ii(a, b, c, d, x[i+ 0], 6 , -198630844);\n\
2795 d = md5_ii(d, a, b, c, x[i+ 7], 10, 1126891415);\n\
2796 c = md5_ii(c, d, a, b, x[i+14], 15, -1416354905);\n\
2797 b = md5_ii(b, c, d, a, x[i+ 5], 21, -57434055);\n\
2798 a = md5_ii(a, b, c, d, x[i+12], 6 , 1700485571);\n\
2799 d = md5_ii(d, a, b, c, x[i+ 3], 10, -1894986606);\n\
2800 c = md5_ii(c, d, a, b, x[i+10], 15, -1051523);\n\
2801 b = md5_ii(b, c, d, a, x[i+ 1], 21, -2054922799);\n\
2802 a = md5_ii(a, b, c, d, x[i+ 8], 6 , 1873313359);\n\
2803 d = md5_ii(d, a, b, c, x[i+15], 10, -30611744);\n\
2804 c = md5_ii(c, d, a, b, x[i+ 6], 15, -1560198380);\n\
2805 b = md5_ii(b, c, d, a, x[i+13], 21, 1309151649);\n\
2806 a = md5_ii(a, b, c, d, x[i+ 4], 6 , -145523070);\n\
2807 d = md5_ii(d, a, b, c, x[i+11], 10, -1120210379);\n\
2808 c = md5_ii(c, d, a, b, x[i+ 2], 15, 718787259);\n\
2809 b = md5_ii(b, c, d, a, x[i+ 9], 21, -343485551);\n\
2811 a = safe_add(a, olda);\n\
2812 b = safe_add(b, oldb);\n\
2813 c = safe_add(c, oldc);\n\
2814 d = safe_add(d, oldd);\n\
2816 return Array(a, b, c, d);\n\
2821 * These functions implement the four basic operations the algorithm uses.\n\
2823 function md5_cmn(q, a, b, x, s, t)\n\
2825 return safe_add(bit_rol(safe_add(safe_add(a, q), safe_add(x, t)), s),b);\n\
2827 function md5_ff(a, b, c, d, x, s, t)\n\
2829 return md5_cmn((b & c) | ((~b) & d), a, b, x, s, t);\n\
2831 function md5_gg(a, b, c, d, x, s, t)\n\
2833 return md5_cmn((b & d) | (c & (~d)), a, b, x, s, t);\n\
2835 function md5_hh(a, b, c, d, x, s, t)\n\
2837 return md5_cmn(b ^ c ^ d, a, b, x, s, t);\n\
2839 function md5_ii(a, b, c, d, x, s, t)\n\
2841 return md5_cmn(c ^ (b | (~d)), a, b, x, s, t);\n\
2845 * Calculate the HMAC-MD5, of a key and some data\n\
2847 function core_hmac_md5(key, data)\n\
2849 var bkey = str2binl(key);\n\
2850 if(bkey.length > 16) bkey = core_md5(bkey, key.length * chrsz);\n\
2852 var ipad = Array(16), opad = Array(16);\n\
2853 for(var i = 0; i < 16; i++)\n\
2855 ipad[i] = bkey[i] ^ 0x36363636;\n\
2856 opad[i] = bkey[i] ^ 0x5C5C5C5C;\n\
2859 var hash = core_md5(ipad.concat(str2binl(data)), 512 + data.length * chrsz);\n\
2860 return core_md5(opad.concat(hash), 512 + 128);\n\
2864 * Add integers, wrapping at 2^32. This uses 16-bit operations internally\n\
2865 * to work around bugs in some JS interpreters.\n\
2867 function safe_add(x, y)\n\
2869 var lsw = (x & 0xFFFF) + (y & 0xFFFF);\n\
2870 var msw = (x >> 16) + (y >> 16) + (lsw >> 16);\n\
2871 return (msw << 16) | (lsw & 0xFFFF);\n\
2875 * Bitwise rotate a 32-bit number to the left.\n\
2877 function bit_rol(num, cnt)\n\
2879 return (num << cnt) | (num >>> (32 - cnt));\n\
2883 * Convert a string to an array of little-endian words\n\
2884 * If chrsz is ASCII, characters >255 have their hi-byte silently ignored.\n\
2886 function str2binl(str)\n\
2888 var bin = Array();\n\
2889 var mask = (1 << chrsz) - 1;\n\
2890 for(var i = 0; i < str.length * chrsz; i += chrsz)\n\
2891 bin[i>>5] |= (str.charCodeAt(i / chrsz) & mask) << (i%32);\n\
2896 * Convert an array of little-endian words to a string\n\
2898 function binl2str(bin)\n\
2901 var mask = (1 << chrsz) - 1;\n\
2902 for(var i = 0; i < bin.length * 32; i += chrsz)\n\
2903 str += String.fromCharCode((bin[i>>5] >>> (i % 32)) & mask);\n\
2908 * Convert an array of little-endian words to a hex string.\n\
2910 function binl2hex(binarray)\n\
2912 var hex_tab = hexcase ? \"0123456789ABCDEF\" : \"0123456789abcdef\";\n\
2914 for(var i = 0; i < binarray.length * 4; i++)\n\
2916 str += hex_tab.charAt((binarray[i>>2] >> ((i%4)*8+4)) & 0xF) +\n\
2917 hex_tab.charAt((binarray[i>>2] >> ((i%4)*8 )) & 0xF);\n\
2923 * Convert an array of little-endian words to a base-64 string\n\
2925 function binl2b64(binarray)\n\
2927 var tab = \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\";\n\
2929 for(var i = 0; i < binarray.length * 4; i += 3)\n\
2931 var triplet = (((binarray[i >> 2] >> 8 * ( i %4)) & 0xFF) << 16)\n\
2932 | (((binarray[i+1 >> 2] >> 8 * ((i+1)%4)) & 0xFF) << 8 )\n\
2933 | ((binarray[i+2 >> 2] >> 8 * ((i+2)%4)) & 0xFF);\n\
2934 for(var j = 0; j < 4; j++)\n\
2936 if(i * 8 + j * 6 > binarray.length * 32) str += b64pad;\n\
2937 else str += tab.charAt((triplet >> 6*(3-j)) & 0x3F);\n\
2943 var plainText = \"Rebellious subjects, enemies to peace,\\n\\\n\
2944 Profaners of this neighbour-stained steel,--\\n\\\n\
2945 Will they not hear? What, ho! you men, you beasts,\\n\\\n\
2946 That quench the fire of your pernicious rage\\n\\\n\
2947 With purple fountains issuing from your veins,\\n\\\n\
2948 On pain of torture, from those bloody hands\\n\\\n\
2949 Throw your mistemper'd weapons to the ground,\\n\\\n\
2950 And hear the sentence of your moved prince.\\n\\\n\
2951 Three civil brawls, bred of an airy word,\\n\\\n\
2952 By thee, old Capulet, and Montague,\\n\\\n\
2953 Have thrice disturb'd the quiet of our streets,\\n\\\n\
2954 And made Verona's ancient citizens\\n\\\n\
2955 Cast by their grave beseeming ornaments,\\n\\\n\
2956 To wield old partisans, in hands as old,\\n\\\n\
2957 Canker'd with peace, to part your canker'd hate:\\n\\\n\
2958 If ever you disturb our streets again,\\n\\\n\
2959 Your lives shall pay the forfeit of the peace.\\n\\\n\
2960 For this time, all the rest depart away:\\n\\\n\
2961 You Capulet; shall go along with me:\\n\\\n\
2962 And, Montague, come you this afternoon,\\n\\\n\
2963 To know our further pleasure in this case,\\n\\\n\
2964 To old Free-town, our common judgment-place.\\n\\\n\
2965 Once more, on pain of death, all men depart.\"\n\
2967 for (var i = 0; i <4; i++) {\n\
2968 plainText += plainText;\n\
2971 var md5Output = hex_md5(plainText);\n\
2973 var expected = \"a831e91e0f70eddcb70dc61c6f82f6cd\";\n\
2975 if (md5Output != expected)\n\
2976 throw \"ERROR: bad result: expected \" + expected + \" but got \" + md5Output;\n\
2980 var _sunSpiderInterval = new Date() - _sunSpiderStartDate;\n\
2982 record(_sunSpiderInterval);\n\
2988 ", "<!DOCTYPE html>\n\
2991 <meta charset=utf8>\n\
2994 Copyright (C) 2007 Apple Inc. All rights reserved.\n\
2996 Redistribution and use in source and binary forms, with or without\n\
2997 modification, are permitted provided that the following conditions\n\
2999 1. Redistributions of source code must retain the above copyright\n\
3000 notice, this list of conditions and the following disclaimer.\n\
3001 2. Redistributions in binary form must reproduce the above copyright\n\
3002 notice, this list of conditions and the following disclaimer in the\n\
3003 documentation and/or other materials provided with the distribution.\n\
3005 THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY\n\
3006 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n\
3007 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\n\
3008 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR\n\
3009 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,\n\
3010 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,\n\
3011 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n\
3012 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY\n\
3013 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n\
3014 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n\
3015 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \n\
3018 <title>SunSpider crypto-sha1</title>\n\
3019 <link rel=\"stylesheet\" href=\"../sunspider.css\">\n\
3023 <h3>crypto-sha1</h3>\n\
3024 <div id=\"console\">\n\
3027 function record(time) {\n\
3028 document.getElementById(\"console\").innerHTML = time + \"ms\";\n\
3029 if (window.parent) {\n\
3030 parent.recordResult(time);\n\
3034 window.onerror = function(e) {\n\
3035 console.log(\"crypto-sha1 failed with error: \" + e);\n\
3039 var _sunSpiderStartDate = new Date();\n\
3042 * A JavaScript implementation of the Secure Hash Algorithm, SHA-1, as defined\n\
3043 * in FIPS PUB 180-1\n\
3044 * Version 2.1a Copyright Paul Johnston 2000 - 2002.\n\
3045 * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet\n\
3046 * Distributed under the BSD License\n\
3047 * See http://pajhome.org.uk/crypt/md5 for details.\n\
3051 * Configurable variables. You may need to tweak these to be compatible with\n\
3052 * the server-side, but the defaults work in most cases.\n\
3054 var hexcase = 0; /* hex output format. 0 - lowercase; 1 - uppercase */\n\
3055 var b64pad = \"\"; /* base-64 pad character. \"=\" for strict RFC compliance */\n\
3056 var chrsz = 8; /* bits per input character. 8 - ASCII; 16 - Unicode */\n\
3059 * These are the functions you'll usually want to call\n\
3060 * They take string arguments and return either hex or base-64 encoded strings\n\
3062 function hex_sha1(s){return binb2hex(core_sha1(str2binb(s),s.length * chrsz));}\n\
3063 function b64_sha1(s){return binb2b64(core_sha1(str2binb(s),s.length * chrsz));}\n\
3064 function str_sha1(s){return binb2str(core_sha1(str2binb(s),s.length * chrsz));}\n\
3065 function hex_hmac_sha1(key, data){ return binb2hex(core_hmac_sha1(key, data));}\n\
3066 function b64_hmac_sha1(key, data){ return binb2b64(core_hmac_sha1(key, data));}\n\
3067 function str_hmac_sha1(key, data){ return binb2str(core_hmac_sha1(k