1// Copyright 2008 the V8 project authors. All rights reserved. 2// Redistribution and use in source and binary forms, with or without 3// modification, are permitted provided that the following conditions are 4// met: 5// 6// * Redistributions of source code must retain the above copyright 7// notice, this list of conditions and the following disclaimer. 8// * Redistributions in binary form must reproduce the above 9// copyright notice, this list of conditions and the following 10// disclaimer in the documentation and/or other materials provided 11// with the distribution. 12// * Neither the name of Google Inc. nor the names of its 13// contributors may be used to endorse or promote products derived 14// from this software without specific prior written permission. 15// 16// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 28var x; 29 30// Converts a number to string respecting -0. 31function stringify(n) { 32 if ((1 / n) === -Infinity) return "-0"; 33 return String(n); 34} 35 36function f(expected, y) { 37 function testEval(string, x, y) { 38 var mulFunction = Function("x, y", "return " + string); 39 return mulFunction(x, y); 40 } 41 function mulTest(expected, x, y) { 42 assertEquals(expected, x * y); 43 assertEquals(expected, testEval(stringify(x) + " * y", x, y)); 44 assertEquals(expected, testEval("x * " + stringify(y), x, y)); 45 assertEquals(expected, testEval(stringify(x) + " * " + stringify(y), x, y)); 46 } 47 mulTest(expected, x, y); 48 mulTest(-expected, -x, y); 49 mulTest(-expected, x, -y); 50 mulTest(expected, -x, -y); 51 if (x === y) return; // Symmetric cases not necessary. 52 mulTest(expected, y, x); 53 mulTest(-expected, -y, x); 54 mulTest(-expected, y, -x); 55 mulTest(expected, -y, -x); 56} 57 58x = 1024; 59f(0, 0); 60f(1024, 1); 61f(2048, 2); 62f(3072, 3); 63f(4096, 4); 64f(5120, 5); 65f(7168, 7); 66f(8192, 8); 67f(9216, 9); 68f(15360, 15); 69f(16384, 16); 70f(17408, 17); 71f(31744, 31); 72f(32768, 32); 73f(33792, 33); 74f(64512, 63); 75f(65536, 64); 76f(66560, 65); 77f(130048, 127); 78f(131072, 128); 79f(132096, 129); 80f(261120, 255); 81f(262144, 256); 82f(263168, 257); 83f(523264, 511); 84f(524288, 512); 85f(525312, 513); 86f(1047552, 1023); 87f(1048576, 1024); 88x = 1025; 89f(0, 0); 90f(1025, 1); 91f(2050, 2); 92f(3075, 3); 93f(4100, 4); 94f(5125, 5); 95f(7175, 7); 96f(8200, 8); 97f(9225, 9); 98f(15375, 15); 99f(16400, 16); 100f(17425, 17); 101f(31775, 31); 102f(32800, 32); 103f(33825, 33); 104f(64575, 63); 105f(65600, 64); 106f(66625, 65); 107f(130175, 127); 108f(131200, 128); 109f(132225, 129); 110f(261375, 255); 111f(262400, 256); 112f(263425, 257); 113f(523775, 511); 114f(524800, 512); 115f(525825, 513); 116f(1048575, 1023); 117f(1049600, 1024); 118f(1050625, 1025); 119x = 2047; 120f(0, 0); 121f(2047, 1); 122f(4094, 2); 123f(6141, 3); 124f(8188, 4); 125f(10235, 5); 126f(14329, 7); 127f(16376, 8); 128f(18423, 9); 129f(30705, 15); 130f(32752, 16); 131f(34799, 17); 132f(63457, 31); 133f(65504, 32); 134f(67551, 33); 135f(128961, 63); 136f(131008, 64); 137f(133055, 65); 138f(259969, 127); 139f(262016, 128); 140f(264063, 129); 141f(521985, 255); 142f(524032, 256); 143f(526079, 257); 144f(1046017, 511); 145f(1048064, 512); 146f(1050111, 513); 147f(2094081, 1023); 148f(2096128, 1024); 149f(2098175, 1025); 150f(4190209, 2047); 151x = 2048; 152f(0, 0); 153f(2048, 1); 154f(4096, 2); 155f(6144, 3); 156f(8192, 4); 157f(10240, 5); 158f(14336, 7); 159f(16384, 8); 160f(18432, 9); 161f(30720, 15); 162f(32768, 16); 163f(34816, 17); 164f(63488, 31); 165f(65536, 32); 166f(67584, 33); 167f(129024, 63); 168f(131072, 64); 169f(133120, 65); 170f(260096, 127); 171f(262144, 128); 172f(264192, 129); 173f(522240, 255); 174f(524288, 256); 175f(526336, 257); 176f(1046528, 511); 177f(1048576, 512); 178f(1050624, 513); 179f(2095104, 1023); 180f(2097152, 1024); 181f(2099200, 1025); 182f(4192256, 2047); 183f(4194304, 2048); 184x = 2049; 185f(0, 0); 186f(2049, 1); 187f(4098, 2); 188f(6147, 3); 189f(8196, 4); 190f(10245, 5); 191f(14343, 7); 192f(16392, 8); 193f(18441, 9); 194f(30735, 15); 195f(32784, 16); 196f(34833, 17); 197f(63519, 31); 198f(65568, 32); 199f(67617, 33); 200f(129087, 63); 201f(131136, 64); 202f(133185, 65); 203f(260223, 127); 204f(262272, 128); 205f(264321, 129); 206f(522495, 255); 207f(524544, 256); 208f(526593, 257); 209f(1047039, 511); 210f(1049088, 512); 211f(1051137, 513); 212f(2096127, 1023); 213f(2098176, 1024); 214f(2100225, 1025); 215f(4194303, 2047); 216f(4196352, 2048); 217f(4198401, 2049); 218x = 4095; 219f(0, 0); 220f(4095, 1); 221f(8190, 2); 222f(12285, 3); 223f(16380, 4); 224f(20475, 5); 225f(28665, 7); 226f(32760, 8); 227f(36855, 9); 228f(61425, 15); 229f(65520, 16); 230f(69615, 17); 231f(126945, 31); 232f(131040, 32); 233f(135135, 33); 234f(257985, 63); 235f(262080, 64); 236f(266175, 65); 237f(520065, 127); 238f(524160, 128); 239f(528255, 129); 240f(1044225, 255); 241f(1048320, 256); 242f(1052415, 257); 243f(2092545, 511); 244f(2096640, 512); 245f(2100735, 513); 246f(4189185, 1023); 247f(4193280, 1024); 248f(4197375, 1025); 249f(8382465, 2047); 250f(8386560, 2048); 251f(8390655, 2049); 252f(16769025, 4095); 253x = 4096; 254f(0, 0); 255f(4096, 1); 256f(8192, 2); 257f(12288, 3); 258f(16384, 4); 259f(20480, 5); 260f(28672, 7); 261f(32768, 8); 262f(36864, 9); 263f(61440, 15); 264f(65536, 16); 265f(69632, 17); 266f(126976, 31); 267f(131072, 32); 268f(135168, 33); 269f(258048, 63); 270f(262144, 64); 271f(266240, 65); 272f(520192, 127); 273f(524288, 128); 274f(528384, 129); 275f(1044480, 255); 276f(1048576, 256); 277f(1052672, 257); 278f(2093056, 511); 279f(2097152, 512); 280f(2101248, 513); 281f(4190208, 1023); 282f(4194304, 1024); 283f(4198400, 1025); 284f(8384512, 2047); 285f(8388608, 2048); 286f(8392704, 2049); 287f(16773120, 4095); 288f(16777216, 4096); 289x = 4097; 290f(0, 0); 291f(4097, 1); 292f(8194, 2); 293f(12291, 3); 294f(16388, 4); 295f(20485, 5); 296f(28679, 7); 297f(32776, 8); 298f(36873, 9); 299f(61455, 15); 300f(65552, 16); 301f(69649, 17); 302f(127007, 31); 303f(131104, 32); 304f(135201, 33); 305f(258111, 63); 306f(262208, 64); 307f(266305, 65); 308f(520319, 127); 309f(524416, 128); 310f(528513, 129); 311f(1044735, 255); 312f(1048832, 256); 313f(1052929, 257); 314f(2093567, 511); 315f(2097664, 512); 316f(2101761, 513); 317f(4191231, 1023); 318f(4195328, 1024); 319f(4199425, 1025); 320f(8386559, 2047); 321f(8390656, 2048); 322f(8394753, 2049); 323f(16777215, 4095); 324f(16781312, 4096); 325f(16785409, 4097); 326x = 8191; 327f(0, 0); 328f(8191, 1); 329f(16382, 2); 330f(24573, 3); 331f(32764, 4); 332f(40955, 5); 333f(57337, 7); 334f(65528, 8); 335f(73719, 9); 336f(122865, 15); 337f(131056, 16); 338f(139247, 17); 339f(253921, 31); 340f(262112, 32); 341f(270303, 33); 342f(516033, 63); 343f(524224, 64); 344f(532415, 65); 345f(1040257, 127); 346f(1048448, 128); 347f(1056639, 129); 348f(2088705, 255); 349f(2096896, 256); 350f(2105087, 257); 351f(4185601, 511); 352f(4193792, 512); 353f(4201983, 513); 354f(8379393, 1023); 355f(8387584, 1024); 356f(8395775, 1025); 357f(16766977, 2047); 358f(16775168, 2048); 359f(16783359, 2049); 360f(33542145, 4095); 361f(33550336, 4096); 362f(33558527, 4097); 363f(67092481, 8191); 364x = 8192; 365f(0, 0); 366f(8192, 1); 367f(16384, 2); 368f(24576, 3); 369f(32768, 4); 370f(40960, 5); 371f(57344, 7); 372f(65536, 8); 373f(73728, 9); 374f(122880, 15); 375f(131072, 16); 376f(139264, 17); 377f(253952, 31); 378f(262144, 32); 379f(270336, 33); 380f(516096, 63); 381f(524288, 64); 382f(532480, 65); 383f(1040384, 127); 384f(1048576, 128); 385f(1056768, 129); 386f(2088960, 255); 387f(2097152, 256); 388f(2105344, 257); 389f(4186112, 511); 390f(4194304, 512); 391f(4202496, 513); 392f(8380416, 1023); 393f(8388608, 1024); 394f(8396800, 1025); 395f(16769024, 2047); 396f(16777216, 2048); 397f(16785408, 2049); 398f(33546240, 4095); 399f(33554432, 4096); 400f(33562624, 4097); 401f(67100672, 8191); 402f(67108864, 8192); 403x = 8193; 404f(0, 0); 405f(8193, 1); 406f(16386, 2); 407f(24579, 3); 408f(32772, 4); 409f(40965, 5); 410f(57351, 7); 411f(65544, 8); 412f(73737, 9); 413f(122895, 15); 414f(131088, 16); 415f(139281, 17); 416f(253983, 31); 417f(262176, 32); 418f(270369, 33); 419f(516159, 63); 420f(524352, 64); 421f(532545, 65); 422f(1040511, 127); 423f(1048704, 128); 424f(1056897, 129); 425f(2089215, 255); 426f(2097408, 256); 427f(2105601, 257); 428f(4186623, 511); 429f(4194816, 512); 430f(4203009, 513); 431f(8381439, 1023); 432f(8389632, 1024); 433f(8397825, 1025); 434f(16771071, 2047); 435f(16779264, 2048); 436f(16787457, 2049); 437f(33550335, 4095); 438f(33558528, 4096); 439f(33566721, 4097); 440f(67108863, 8191); 441f(67117056, 8192); 442f(67125249, 8193); 443x = 16383; 444f(0, 0); 445f(16383, 1); 446f(32766, 2); 447f(49149, 3); 448f(65532, 4); 449f(81915, 5); 450f(114681, 7); 451f(131064, 8); 452f(147447, 9); 453f(245745, 15); 454f(262128, 16); 455f(278511, 17); 456f(507873, 31); 457f(524256, 32); 458f(540639, 33); 459f(1032129, 63); 460f(1048512, 64); 461f(1064895, 65); 462f(2080641, 127); 463f(2097024, 128); 464f(2113407, 129); 465f(4177665, 255); 466f(4194048, 256); 467f(4210431, 257); 468f(8371713, 511); 469f(8388096, 512); 470f(8404479, 513); 471f(16759809, 1023); 472f(16776192, 1024); 473f(16792575, 1025); 474f(33536001, 2047); 475f(33552384, 2048); 476f(33568767, 2049); 477f(67088385, 4095); 478f(67104768, 4096); 479f(67121151, 4097); 480f(134193153, 8191); 481f(134209536, 8192); 482f(134225919, 8193); 483f(268402689, 16383); 484x = 16384; 485f(0, 0); 486f(16384, 1); 487f(32768, 2); 488f(49152, 3); 489f(65536, 4); 490f(81920, 5); 491f(114688, 7); 492f(131072, 8); 493f(147456, 9); 494f(245760, 15); 495f(262144, 16); 496f(278528, 17); 497f(507904, 31); 498f(524288, 32); 499f(540672, 33); 500f(1032192, 63); 501f(1048576, 64); 502f(1064960, 65); 503f(2080768, 127); 504f(2097152, 128); 505f(2113536, 129); 506f(4177920, 255); 507f(4194304, 256); 508f(4210688, 257); 509f(8372224, 511); 510f(8388608, 512); 511f(8404992, 513); 512f(16760832, 1023); 513f(16777216, 1024); 514f(16793600, 1025); 515f(33538048, 2047); 516f(33554432, 2048); 517f(33570816, 2049); 518f(67092480, 4095); 519f(67108864, 4096); 520f(67125248, 4097); 521f(134201344, 8191); 522f(134217728, 8192); 523f(134234112, 8193); 524f(268419072, 16383); 525f(268435456, 16384); 526