blob: e92998575be19e71d9e86634ff85e2cf288ba9a3 [file] [log] [blame]
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001// 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 = 1048577;
59f(0, 0);
60f(1048577, 1);
61f(2097154, 2);
62f(3145731, 3);
63f(4194308, 4);
64f(5242885, 5);
65f(7340039, 7);
66f(8388616, 8);
67f(9437193, 9);
68f(15728655, 15);
69f(16777232, 16);
70f(17825809, 17);
71f(32505887, 31);
72f(33554464, 32);
73f(34603041, 33);
74f(66060351, 63);
75f(67108928, 64);
76f(68157505, 65);
77f(133169279, 127);
78f(134217856, 128);
79f(135266433, 129);
80f(267387135, 255);
81f(268435712, 256);
82f(269484289, 257);
83f(535822847, 511);
84f(536871424, 512);
85f(537920001, 513);
86f(1072694271, 1023);
87f(1073742848, 1024);
88f(1074791425, 1025);
89f(2146437119, 2047);
90f(2147485696, 2048);
91f(2148534273, 2049);
92f(4293922815, 4095);
93f(4294971392, 4096);
94f(4296019969, 4097);
95f(8588894207, 8191);
96f(8589942784, 8192);
97f(8590991361, 8193);
98f(17178836991, 16383);
99f(17179885568, 16384);
100f(17180934145, 16385);
101f(34358722559, 32767);
102f(34359771136, 32768);
103f(34360819713, 32769);
104f(68718493695, 65535);
105f(68719542272, 65536);
106f(68720590849, 65537);
107f(137438035967, 131071);
108f(137439084544, 131072);
109f(137440133121, 131073);
110f(274877120511, 262143);
111f(274878169088, 262144);
112f(274879217665, 262145);
113f(549755289599, 524287);
114f(549756338176, 524288);
115f(549757386753, 524289);
116f(1099511627775, 1048575);
117f(1099512676352, 1048576);
118f(1099513724929, 1048577);
119x = 2097151;
120f(0, 0);
121f(2097151, 1);
122f(4194302, 2);
123f(6291453, 3);
124f(8388604, 4);
125f(10485755, 5);
126f(14680057, 7);
127f(16777208, 8);
128f(18874359, 9);
129f(31457265, 15);
130f(33554416, 16);
131f(35651567, 17);
132f(65011681, 31);
133f(67108832, 32);
134f(69205983, 33);
135f(132120513, 63);
136f(134217664, 64);
137f(136314815, 65);
138f(266338177, 127);
139f(268435328, 128);
140f(270532479, 129);
141f(534773505, 255);
142f(536870656, 256);
143f(538967807, 257);
144f(1071644161, 511);
145f(1073741312, 512);
146f(1075838463, 513);
147f(2145385473, 1023);
148f(2147482624, 1024);
149f(2149579775, 1025);
150f(4292868097, 2047);
151f(4294965248, 2048);
152f(4297062399, 2049);
153f(8587833345, 4095);
154f(8589930496, 4096);
155f(8592027647, 4097);
156f(17177763841, 8191);
157f(17179860992, 8192);
158f(17181958143, 8193);
159f(34357624833, 16383);
160f(34359721984, 16384);
161f(34361819135, 16385);
162f(68717346817, 32767);
163f(68719443968, 32768);
164f(68721541119, 32769);
165f(137436790785, 65535);
166f(137438887936, 65536);
167f(137440985087, 65537);
168f(274875678721, 131071);
169f(274877775872, 131072);
170f(274879873023, 131073);
171f(549753454593, 262143);
172f(549755551744, 262144);
173f(549757648895, 262145);
174f(1099509006337, 524287);
175f(1099511103488, 524288);
176f(1099513200639, 524289);
177f(2199020109825, 1048575);
178f(2199022206976, 1048576);
179f(2199024304127, 1048577);
180f(4398042316801, 2097151);
181x = 2097152;
182f(0, 0);
183f(2097152, 1);
184f(4194304, 2);
185f(6291456, 3);
186f(8388608, 4);
187f(10485760, 5);
188f(14680064, 7);
189f(16777216, 8);
190f(18874368, 9);
191f(31457280, 15);
192f(33554432, 16);
193f(35651584, 17);
194f(65011712, 31);
195f(67108864, 32);
196f(69206016, 33);
197f(132120576, 63);
198f(134217728, 64);
199f(136314880, 65);
200f(266338304, 127);
201f(268435456, 128);
202f(270532608, 129);
203f(534773760, 255);
204f(536870912, 256);
205f(538968064, 257);
206f(1071644672, 511);
207f(1073741824, 512);
208f(1075838976, 513);
209f(2145386496, 1023);
210f(2147483648, 1024);
211f(2149580800, 1025);
212f(4292870144, 2047);
213f(4294967296, 2048);
214f(4297064448, 2049);
215f(8587837440, 4095);
216f(8589934592, 4096);
217f(8592031744, 4097);
218f(17177772032, 8191);
219f(17179869184, 8192);
220f(17181966336, 8193);
221f(34357641216, 16383);
222f(34359738368, 16384);
223f(34361835520, 16385);
224f(68717379584, 32767);
225f(68719476736, 32768);
226f(68721573888, 32769);
227f(137436856320, 65535);
228f(137438953472, 65536);
229f(137441050624, 65537);
230f(274875809792, 131071);
231f(274877906944, 131072);
232f(274880004096, 131073);
233f(549753716736, 262143);
234f(549755813888, 262144);
235f(549757911040, 262145);
236f(1099509530624, 524287);
237f(1099511627776, 524288);
238f(1099513724928, 524289);
239f(2199021158400, 1048575);
240f(2199023255552, 1048576);
241f(2199025352704, 1048577);
242f(4398044413952, 2097151);
243f(4398046511104, 2097152);
244x = 2097153;
245f(0, 0);
246f(2097153, 1);
247f(4194306, 2);
248f(6291459, 3);
249f(8388612, 4);
250f(10485765, 5);
251f(14680071, 7);
252f(16777224, 8);
253f(18874377, 9);
254f(31457295, 15);
255f(33554448, 16);
256f(35651601, 17);
257f(65011743, 31);
258f(67108896, 32);
259f(69206049, 33);
260f(132120639, 63);
261f(134217792, 64);
262f(136314945, 65);
263f(266338431, 127);
264f(268435584, 128);
265f(270532737, 129);
266f(534774015, 255);
267f(536871168, 256);
268f(538968321, 257);
269f(1071645183, 511);
270f(1073742336, 512);
271f(1075839489, 513);
272f(2145387519, 1023);
273f(2147484672, 1024);
274f(2149581825, 1025);
275f(4292872191, 2047);
276f(4294969344, 2048);
277f(4297066497, 2049);
278f(8587841535, 4095);
279f(8589938688, 4096);
280f(8592035841, 4097);
281f(17177780223, 8191);
282f(17179877376, 8192);
283f(17181974529, 8193);
284f(34357657599, 16383);
285f(34359754752, 16384);
286f(34361851905, 16385);
287f(68717412351, 32767);
288f(68719509504, 32768);
289f(68721606657, 32769);
290f(137436921855, 65535);
291f(137439019008, 65536);
292f(137441116161, 65537);
293f(274875940863, 131071);
294f(274878038016, 131072);
295f(274880135169, 131073);
296f(549753978879, 262143);
297f(549756076032, 262144);
298f(549758173185, 262145);
299f(1099510054911, 524287);
300f(1099512152064, 524288);
301f(1099514249217, 524289);
302f(2199022206975, 1048575);
303f(2199024304128, 1048576);
304f(2199026401281, 1048577);
305f(4398046511103, 2097151);
306f(4398048608256, 2097152);
307f(4398050705409, 2097153);
308x = 4194303;
309f(0, 0);
310f(4194303, 1);
311f(8388606, 2);
312f(12582909, 3);
313f(16777212, 4);
314f(20971515, 5);
315f(29360121, 7);
316f(33554424, 8);
317f(37748727, 9);
318f(62914545, 15);
319f(67108848, 16);
320f(71303151, 17);
321f(130023393, 31);
322f(134217696, 32);
323f(138411999, 33);
324f(264241089, 63);
325f(268435392, 64);
326f(272629695, 65);
327f(532676481, 127);
328f(536870784, 128);
329f(541065087, 129);
330f(1069547265, 255);
331f(1073741568, 256);
332f(1077935871, 257);
333f(2143288833, 511);
334f(2147483136, 512);
335f(2151677439, 513);
336f(4290771969, 1023);
337f(4294966272, 1024);
338f(4299160575, 1025);
339f(8585738241, 2047);
340f(8589932544, 2048);
341f(8594126847, 2049);
342f(17175670785, 4095);
343f(17179865088, 4096);
344f(17184059391, 4097);
345f(34355535873, 8191);
346f(34359730176, 8192);
347f(34363924479, 8193);
348f(68715266049, 16383);
349f(68719460352, 16384);
350f(68723654655, 16385);
351f(137434726401, 32767);
352f(137438920704, 32768);
353f(137443115007, 32769);
354f(274873647105, 65535);
355f(274877841408, 65536);
356f(274882035711, 65537);
357f(549751488513, 131071);
358f(549755682816, 131072);
359f(549759877119, 131073);
360f(1099507171329, 262143);
361f(1099511365632, 262144);
362f(1099515559935, 262145);
363f(2199018536961, 524287);
364f(2199022731264, 524288);
365f(2199026925567, 524289);
366f(4398041268225, 1048575);
367f(4398045462528, 1048576);
368f(4398049656831, 1048577);
369f(8796086730753, 2097151);
370f(8796090925056, 2097152);
371f(8796095119359, 2097153);
372f(17592177655809, 4194303);
373x = 4194304;
374f(0, 0);
375f(4194304, 1);
376f(8388608, 2);
377f(12582912, 3);
378f(16777216, 4);
379f(20971520, 5);
380f(29360128, 7);
381f(33554432, 8);
382f(37748736, 9);
383f(62914560, 15);
384f(67108864, 16);
385f(71303168, 17);
386f(130023424, 31);
387f(134217728, 32);
388f(138412032, 33);
389f(264241152, 63);
390f(268435456, 64);
391f(272629760, 65);
392f(532676608, 127);
393f(536870912, 128);
394f(541065216, 129);
395f(1069547520, 255);
396f(1073741824, 256);
397f(1077936128, 257);
398f(2143289344, 511);
399f(2147483648, 512);
400f(2151677952, 513);
401f(4290772992, 1023);
402f(4294967296, 1024);
403f(4299161600, 1025);
404f(8585740288, 2047);
405f(8589934592, 2048);
406f(8594128896, 2049);
407f(17175674880, 4095);
408f(17179869184, 4096);
409f(17184063488, 4097);
410f(34355544064, 8191);
411f(34359738368, 8192);
412f(34363932672, 8193);
413f(68715282432, 16383);
414f(68719476736, 16384);
415f(68723671040, 16385);
416f(137434759168, 32767);
417f(137438953472, 32768);
418f(137443147776, 32769);
419f(274873712640, 65535);
420f(274877906944, 65536);
421f(274882101248, 65537);
422f(549751619584, 131071);
423f(549755813888, 131072);
424f(549760008192, 131073);
425f(1099507433472, 262143);
426f(1099511627776, 262144);
427f(1099515822080, 262145);
428f(2199019061248, 524287);
429f(2199023255552, 524288);
430f(2199027449856, 524289);
431f(4398042316800, 1048575);
432f(4398046511104, 1048576);
433f(4398050705408, 1048577);
434f(8796088827904, 2097151);
435f(8796093022208, 2097152);
436f(8796097216512, 2097153);
437f(17592181850112, 4194303);
438f(17592186044416, 4194304);
439x = 4194305;
440f(0, 0);
441f(4194305, 1);
442f(8388610, 2);
443f(12582915, 3);
444f(16777220, 4);
445f(20971525, 5);
446f(29360135, 7);
447f(33554440, 8);
448f(37748745, 9);
449f(62914575, 15);
450f(67108880, 16);
451f(71303185, 17);
452f(130023455, 31);
453f(134217760, 32);
454f(138412065, 33);
455f(264241215, 63);
456f(268435520, 64);
457f(272629825, 65);
458f(532676735, 127);
459f(536871040, 128);
460f(541065345, 129);
461f(1069547775, 255);
462f(1073742080, 256);
463f(1077936385, 257);
464f(2143289855, 511);
465f(2147484160, 512);
466f(2151678465, 513);
467f(4290774015, 1023);
468f(4294968320, 1024);
469f(4299162625, 1025);
470f(8585742335, 2047);
471f(8589936640, 2048);
472f(8594130945, 2049);
473f(17175678975, 4095);
474f(17179873280, 4096);
475f(17184067585, 4097);
476f(34355552255, 8191);
477f(34359746560, 8192);
478f(34363940865, 8193);
479f(68715298815, 16383);
480f(68719493120, 16384);
481f(68723687425, 16385);
482f(137434791935, 32767);
483f(137438986240, 32768);
484f(137443180545, 32769);
485f(274873778175, 65535);
486f(274877972480, 65536);
487f(274882166785, 65537);
488f(549751750655, 131071);
489f(549755944960, 131072);
490f(549760139265, 131073);
491f(1099507695615, 262143);
492f(1099511889920, 262144);
493f(1099516084225, 262145);
494f(2199019585535, 524287);
495f(2199023779840, 524288);
496f(2199027974145, 524289);
497f(4398043365375, 1048575);
498f(4398047559680, 1048576);
499f(4398051753985, 1048577);
500f(8796090925055, 2097151);
501f(8796095119360, 2097152);
502f(8796099313665, 2097153);
503f(17592186044415, 4194303);
504f(17592190238720, 4194304);
505f(17592194433025, 4194305);