Best JavaScript code snippet using wpt
smi-ops.js
Source:smi-ops.js
1// Copyright 2010 the V8 project authors. All rights reserved.2// Redistribution and use in source and binary forms, with or without3// modification, are permitted provided that the following conditions are4// met:5//6// * Redistributions of source code must retain the above copyright7// notice, this list of conditions and the following disclaimer.8// * Redistributions in binary form must reproduce the above9// copyright notice, this list of conditions and the following10// disclaimer in the documentation and/or other materials provided11// with the distribution.12// * Neither the name of Google Inc. nor the names of its13// contributors may be used to endorse or promote products derived14// from this software without specific prior written permission.15//16// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS17// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT18// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR19// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT20// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,21// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT22// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,23// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY24// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT25// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE26// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.27const SMI_MAX = (1 << 29) - 1 + (1 << 29); // Create without overflowing.28const SMI_MIN = -SMI_MAX - 1; // Create without overflowing.29const ONE = 1;30const ONE_HUNDRED = 100;31const OBJ_42 = new (function() {32 this.valueOf = function() { return 42; };33})();34assertEquals(42, OBJ_42.valueOf());35function Add1(x) {36 return x + 1;37}38function Add100(x) {39 return x + 100;40}41function Add1Reversed(x) {42 return 1 + x;43}44function Add100Reversed(x) {45 return 100 + x;46}47assertEquals(1, Add1(0)); // fast case48assertEquals(1, Add1Reversed(0)); // fast case49assertEquals(SMI_MAX + ONE, Add1(SMI_MAX), "smimax + 1");50assertEquals(SMI_MAX + ONE, Add1Reversed(SMI_MAX), "1 + smimax");51assertEquals(42 + ONE, Add1(OBJ_42)); // non-smi52assertEquals(42 + ONE, Add1Reversed(OBJ_42)); // non-smi53assertEquals(100, Add100(0)); // fast case54assertEquals(100, Add100Reversed(0)); // fast case55assertEquals(SMI_MAX + ONE_HUNDRED, Add100(SMI_MAX), "smimax + 100");56assertEquals(SMI_MAX + ONE_HUNDRED, Add100Reversed(SMI_MAX), " 100 + smimax");57assertEquals(42 + ONE_HUNDRED, Add100(OBJ_42)); // non-smi58assertEquals(42 + ONE_HUNDRED, Add100Reversed(OBJ_42)); // non-smi59function Sub1(x) {60 return x - 1;61}62function Sub100(x) {63 return x - 100;64}65function Sub1Reversed(x) {66 return 1 - x;67}68function Sub100Reversed(x) {69 return 100 - x;70}71assertEquals(0, Sub1(1)); // fast case72assertEquals(-1, Sub1Reversed(2)); // fast case73assertEquals(SMI_MIN - ONE, Sub1(SMI_MIN)); // overflow74assertEquals(ONE - SMI_MIN, Sub1Reversed(SMI_MIN)); // overflow75assertEquals(42 - ONE, Sub1(OBJ_42)); // non-smi76assertEquals(ONE - 42, Sub1Reversed(OBJ_42)); // non-smi77assertEquals(0, Sub100(100)); // fast case78assertEquals(1, Sub100Reversed(99)); // fast case79assertEquals(SMI_MIN - ONE_HUNDRED, Sub100(SMI_MIN)); // overflow80assertEquals(ONE_HUNDRED - SMI_MIN, Sub100Reversed(SMI_MIN)); // overflow81assertEquals(42 - ONE_HUNDRED, Sub100(OBJ_42)); // non-smi82assertEquals(ONE_HUNDRED - 42, Sub100Reversed(OBJ_42)); // non-smi83function Shr1(x) {84 return x >>> 1;85}86function Shr100(x) {87 return x >>> 100;88}89function Shr1Reversed(x) {90 return 1 >>> x;91}92function Shr100Reversed(x) {93 return 100 >>> x;94}95function Sar1(x) {96 return x >> 1;97}98function Sar100(x) {99 return x >> 100;100}101function Sar1Reversed(x) {102 return 1 >> x;103}104function Sar100Reversed(x) {105 return 100 >> x;106}107assertEquals(0, Shr1(1));108assertEquals(0, Sar1(1));109assertEquals(0, Shr1Reversed(2));110assertEquals(0, Sar1Reversed(2));111assertEquals(1610612736, Shr1(SMI_MIN));112assertEquals(-536870912, Sar1(SMI_MIN));113assertEquals(1, Shr1Reversed(SMI_MIN));114assertEquals(1, Sar1Reversed(SMI_MIN));115assertEquals(21, Shr1(OBJ_42));116assertEquals(21, Sar1(OBJ_42));117assertEquals(0, Shr1Reversed(OBJ_42));118assertEquals(0, Sar1Reversed(OBJ_42));119assertEquals(6, Shr100(100), "100 >>> 100");120assertEquals(6, Sar100(100), "100 >> 100");121assertEquals(12, Shr100Reversed(99));122assertEquals(12, Sar100Reversed(99));123assertEquals(201326592, Shr100(SMI_MIN));124assertEquals(-67108864, Sar100(SMI_MIN));125assertEquals(100, Shr100Reversed(SMI_MIN));126assertEquals(100, Sar100Reversed(SMI_MIN));127assertEquals(2, Shr100(OBJ_42));128assertEquals(2, Sar100(OBJ_42));129assertEquals(0, Shr100Reversed(OBJ_42));130assertEquals(0, Sar100Reversed(OBJ_42));131function Xor1(x) {132 return x ^ 1;133}134function Xor100(x) {135 return x ^ 100;136}137function Xor1Reversed(x) {138 return 1 ^ x;139}140function Xor100Reversed(x) {141 return 100 ^ x;142}143assertEquals(0, Xor1(1));144assertEquals(3, Xor1Reversed(2));145assertEquals(SMI_MIN + 1, Xor1(SMI_MIN));146assertEquals(SMI_MIN + 1, Xor1Reversed(SMI_MIN));147assertEquals(43, Xor1(OBJ_42));148assertEquals(43, Xor1Reversed(OBJ_42));149assertEquals(0, Xor100(100));150assertEquals(7, Xor100Reversed(99));151assertEquals(-1073741724, Xor100(SMI_MIN));152assertEquals(-1073741724, Xor100Reversed(SMI_MIN));153assertEquals(78, Xor100(OBJ_42));154assertEquals(78, Xor100Reversed(OBJ_42));155var x = 0x23; var y = 0x35;156assertEquals(0x16, x ^ y);157// Bitwise not.158var v = 0;159assertEquals(-1, ~v);160v = SMI_MIN;161assertEquals(0x3fffffff, ~v, "~smimin");162v = SMI_MAX;163assertEquals(-0x40000000, ~v, "~smimax");164// Overflowing ++ and --.165v = SMI_MAX;166v++;167assertEquals(0x40000000, v, "smimax++");168v = SMI_MIN;169v--;170assertEquals(-0x40000001, v, "smimin--");171// Check that comparisons of numbers separated by MIN_SMI work.172assertFalse(SMI_MIN > 0);173assertFalse(SMI_MIN + 1 > 1);174assertFalse(SMI_MIN + 1 > 2);175assertFalse(SMI_MIN + 2 > 1);176assertFalse(0 < SMI_MIN);177assertTrue(-1 < SMI_MAX);178assertFalse(SMI_MAX < -1);179// Not actually Smi operations.180// Check that relations on unary ops work.181var v = -1.2;182assertTrue(v == v);183assertTrue(v === v);184assertTrue(v <= v);185assertTrue(v >= v);186assertFalse(v < v);187assertFalse(v > v);188assertFalse(v != v);189assertFalse(v !== v);190// Right hand side of unary minus is overwritable.191v = 1.5192assertEquals(-2.25, -(v * v));193// Smi input to bitop gives non-smi result where the rhs is a float that194// can be overwritten.195var x1 = 0x10000000;196var x2 = 0x40000002;197var x3 = 0x40000000;198assertEquals(0x40000000, x1 << (x2 - x3), "0x10000000<<1(1)");199// Smi input to bitop gives non-smi result where the rhs could be overwritten200// if it were a float, but it isn't.201x1 = 0x10000000202x2 = 4203x3 = 2204assertEquals(0x40000000, x1 << (x2 - x3), "0x10000000<<2(2)");205// Test shift operators on non-smi inputs, giving smi and non-smi results.206function testShiftNonSmis() {207 var pos_non_smi = 2000000000;208 var neg_non_smi = -pos_non_smi;209 var pos_smi = 1000000000;210 var neg_smi = -pos_smi;211 // Begin block A212 assertEquals(pos_non_smi, (pos_non_smi) >> 0);213 assertEquals(pos_non_smi, (pos_non_smi) >>> 0);214 assertEquals(pos_non_smi, (pos_non_smi) << 0);215 assertEquals(neg_non_smi, (neg_non_smi) >> 0);216 assertEquals(neg_non_smi + 0x100000000, (neg_non_smi) >>> 0);217 assertEquals(neg_non_smi, (neg_non_smi) << 0);218 assertEquals(pos_smi, (pos_smi) >> 0, "possmi >> 0");219 assertEquals(pos_smi, (pos_smi) >>> 0, "possmi >>>0");220 assertEquals(pos_smi, (pos_smi) << 0, "possmi << 0");221 assertEquals(neg_smi, (neg_smi) >> 0, "negsmi >> 0");222 assertEquals(neg_smi + 0x100000000, (neg_smi) >>> 0, "negsmi >>> 0");223 assertEquals(neg_smi, (neg_smi) << 0), "negsmi << 0";224 assertEquals(pos_non_smi / 2, (pos_non_smi) >> 1);225 assertEquals(pos_non_smi / 2, (pos_non_smi) >>> 1);226 assertEquals(-0x1194D800, (pos_non_smi) << 1);227 assertEquals(pos_non_smi / 8, (pos_non_smi) >> 3);228 assertEquals(pos_non_smi / 8, (pos_non_smi) >>> 3);229 assertEquals(-0x46536000, (pos_non_smi) << 3);230 assertEquals(0x73594000, (pos_non_smi) << 4);231 assertEquals(pos_non_smi, (pos_non_smi + 0.5) >> 0);232 assertEquals(pos_non_smi, (pos_non_smi + 0.5) >>> 0);233 assertEquals(pos_non_smi, (pos_non_smi + 0.5) << 0);234 assertEquals(pos_non_smi / 2, (pos_non_smi + 0.5) >> 1);235 assertEquals(pos_non_smi / 2, (pos_non_smi + 0.5) >>> 1);236 assertEquals(-0x1194D800, (pos_non_smi + 0.5) << 1);237 assertEquals(pos_non_smi / 8, (pos_non_smi + 0.5) >> 3);238 assertEquals(pos_non_smi / 8, (pos_non_smi + 0.5) >>> 3);239 assertEquals(-0x46536000, (pos_non_smi + 0.5) << 3);240 assertEquals(0x73594000, (pos_non_smi + 0.5) << 4);241 assertEquals(neg_non_smi / 2, (neg_non_smi) >> 1, "negnonsmi >> 1");242 assertEquals(neg_non_smi / 2 + 0x100000000 / 2, (neg_non_smi) >>> 1,243 "negnonsmi >>> 1");244 assertEquals(0x1194D800, (neg_non_smi) << 1);245 assertEquals(neg_non_smi / 8, (neg_non_smi) >> 3);246 assertEquals(neg_non_smi / 8 + 0x100000000 / 8, (neg_non_smi) >>> 3);247 assertEquals(0x46536000, (neg_non_smi) << 3);248 assertEquals(-0x73594000, (neg_non_smi) << 4);249 assertEquals(neg_non_smi, (neg_non_smi - 0.5) >> 0);250 assertEquals(neg_non_smi + 0x100000000, (neg_non_smi - 0.5) >>> 0,251 "negnonsmi.5 >>> 0");252 assertEquals(neg_non_smi, (neg_non_smi - 0.5) << 0);253 assertEquals(neg_non_smi / 2, (neg_non_smi - 0.5) >> 1);254 assertEquals(neg_non_smi / 2 + 0x100000000 / 2, (neg_non_smi - 0.5) >>> 1,255 "negnonsmi.5 >>> 1");256 assertEquals(0x1194D800, (neg_non_smi - 0.5) << 1);257 assertEquals(neg_non_smi / 8, (neg_non_smi - 0.5) >> 3);258 assertEquals(neg_non_smi / 8 + 0x100000000 / 8, (neg_non_smi - 0.5) >>> 3);259 assertEquals(0x46536000, (neg_non_smi - 0.5) << 3);260 assertEquals(-0x73594000, (neg_non_smi - 0.5) << 4);261 assertEquals(pos_smi / 2, (pos_smi) >> 1);262 assertEquals(pos_smi / 2, (pos_smi) >>> 1);263 assertEquals(pos_non_smi, (pos_smi) << 1);264 assertEquals(pos_smi / 8, (pos_smi) >> 3);265 assertEquals(pos_smi / 8, (pos_smi) >>> 3);266 assertEquals(-0x2329b000, (pos_smi) << 3);267 assertEquals(0x73594000, (pos_smi) << 5);268 assertEquals(pos_smi, (pos_smi + 0.5) >> 0, "possmi.5 >> 0");269 assertEquals(pos_smi, (pos_smi + 0.5) >>> 0, "possmi.5 >>> 0");270 assertEquals(pos_smi, (pos_smi + 0.5) << 0, "possmi.5 << 0");271 assertEquals(pos_smi / 2, (pos_smi + 0.5) >> 1);272 assertEquals(pos_smi / 2, (pos_smi + 0.5) >>> 1);273 assertEquals(pos_non_smi, (pos_smi + 0.5) << 1);274 assertEquals(pos_smi / 8, (pos_smi + 0.5) >> 3);275 assertEquals(pos_smi / 8, (pos_smi + 0.5) >>> 3);276 assertEquals(-0x2329b000, (pos_smi + 0.5) << 3);277 assertEquals(0x73594000, (pos_smi + 0.5) << 5);278 assertEquals(neg_smi / 2, (neg_smi) >> 1);279 assertEquals(neg_smi / 2 + 0x100000000 / 2, (neg_smi) >>> 1);280 assertEquals(neg_non_smi, (neg_smi) << 1);281 assertEquals(neg_smi / 8, (neg_smi) >> 3);282 assertEquals(neg_smi / 8 + 0x100000000 / 8, (neg_smi) >>> 3);283 assertEquals(0x46536000, (neg_smi) << 4);284 assertEquals(-0x73594000, (neg_smi) << 5);285 assertEquals(neg_smi, (neg_smi - 0.5) >> 0, "negsmi.5 >> 0");286 assertEquals(neg_smi + 0x100000000, (neg_smi - 0.5) >>> 0, "negsmi.5 >>> 0");287 assertEquals(neg_smi, (neg_smi - 0.5) << 0, "negsmi.5 << 0");288 assertEquals(neg_smi / 2, (neg_smi - 0.5) >> 1);289 assertEquals(neg_smi / 2 + 0x100000000 / 2, (neg_smi - 0.5) >>> 1);290 assertEquals(neg_non_smi, (neg_smi - 0.5) << 1);291 assertEquals(neg_smi / 8, (neg_smi - 0.5) >> 3);292 assertEquals(neg_smi / 8 + 0x100000000 / 8, (neg_smi - 0.5) >>> 3);293 assertEquals(0x46536000, (neg_smi - 0.5) << 4);294 assertEquals(-0x73594000, (neg_smi - 0.5) << 5);295 // End block A296 // Repeat block A with 2^32 added to positive numbers and297 // 2^32 subtracted from negative numbers.298 // Begin block A repeat 1299 var two_32 = 0x100000000;300 var neg_32 = -two_32;301 assertEquals(pos_non_smi, (two_32 + pos_non_smi) >> 0);302 assertEquals(pos_non_smi, (two_32 + pos_non_smi) >>> 0);303 assertEquals(pos_non_smi, (two_32 + pos_non_smi) << 0);304 assertEquals(neg_non_smi, (neg_32 + neg_non_smi) >> 0);305 assertEquals(neg_non_smi + 0x100000000, (neg_32 + neg_non_smi) >>> 0);306 assertEquals(neg_non_smi, (neg_32 + neg_non_smi) << 0);307 assertEquals(pos_smi, (two_32 + pos_smi) >> 0, "2^32+possmi >> 0");308 assertEquals(pos_smi, (two_32 + pos_smi) >>> 0, "2^32+possmi >>> 0");309 assertEquals(pos_smi, (two_32 + pos_smi) << 0, "2^32+possmi << 0");310 assertEquals(neg_smi, (neg_32 + neg_smi) >> 0, "2^32+negsmi >> 0");311 assertEquals(neg_smi + 0x100000000, (neg_32 + neg_smi) >>> 0);312 assertEquals(neg_smi, (neg_32 + neg_smi) << 0, "2^32+negsmi << 0");313 assertEquals(pos_non_smi / 2, (two_32 + pos_non_smi) >> 1);314 assertEquals(pos_non_smi / 2, (two_32 + pos_non_smi) >>> 1);315 assertEquals(-0x1194D800, (two_32 + pos_non_smi) << 1);316 assertEquals(pos_non_smi / 8, (two_32 + pos_non_smi) >> 3);317 assertEquals(pos_non_smi / 8, (two_32 + pos_non_smi) >>> 3);318 assertEquals(-0x46536000, (two_32 + pos_non_smi) << 3);319 assertEquals(0x73594000, (two_32 + pos_non_smi) << 4);320 assertEquals(pos_non_smi, (two_32 + pos_non_smi + 0.5) >> 0);321 assertEquals(pos_non_smi, (two_32 + pos_non_smi + 0.5) >>> 0);322 assertEquals(pos_non_smi, (two_32 + pos_non_smi + 0.5) << 0);323 assertEquals(pos_non_smi / 2, (two_32 + pos_non_smi + 0.5) >> 1);324 assertEquals(pos_non_smi / 2, (two_32 + pos_non_smi + 0.5) >>> 1);325 assertEquals(-0x1194D800, (two_32 + pos_non_smi + 0.5) << 1);326 assertEquals(pos_non_smi / 8, (two_32 + pos_non_smi + 0.5) >> 3);327 assertEquals(pos_non_smi / 8, (two_32 + pos_non_smi + 0.5) >>> 3);328 assertEquals(-0x46536000, (two_32 + pos_non_smi + 0.5) << 3);329 assertEquals(0x73594000, (two_32 + pos_non_smi + 0.5) << 4);330 assertEquals(neg_non_smi / 2, (neg_32 + neg_non_smi) >> 1);331 assertEquals(neg_non_smi / 2 + 0x100000000 / 2, (neg_32 + neg_non_smi) >>> 1);332 assertEquals(0x1194D800, (neg_32 + neg_non_smi) << 1);333 assertEquals(neg_non_smi / 8, (neg_32 + neg_non_smi) >> 3);334 assertEquals(neg_non_smi / 8 + 0x100000000 / 8, (neg_32 + neg_non_smi) >>> 3);335 assertEquals(0x46536000, (neg_32 + neg_non_smi) << 3);336 assertEquals(-0x73594000, (neg_32 + neg_non_smi) << 4);337 assertEquals(neg_non_smi, (neg_32 + neg_non_smi - 0.5) >> 0);338 assertEquals(neg_non_smi + 0x100000000, (neg_32 + neg_non_smi - 0.5) >>> 0);339 assertEquals(neg_non_smi, (neg_32 + neg_non_smi - 0.5) << 0);340 assertEquals(neg_non_smi / 2, (neg_32 + neg_non_smi - 0.5) >> 1);341 assertEquals(neg_non_smi / 2 + 0x100000000 / 2, (neg_32 + neg_non_smi - 0.5)342 >>> 1);343 assertEquals(0x1194D800, (neg_32 + neg_non_smi - 0.5) << 1);344 assertEquals(neg_non_smi / 8, (neg_32 + neg_non_smi - 0.5) >> 3);345 assertEquals(neg_non_smi / 8 + 0x100000000 / 8, (neg_32 + neg_non_smi - 0.5)346 >>> 3);347 assertEquals(0x46536000, (neg_32 + neg_non_smi - 0.5) << 3);348 assertEquals(-0x73594000, (neg_32 + neg_non_smi - 0.5) << 4);349 assertEquals(pos_smi / 2, (two_32 + pos_smi) >> 1);350 assertEquals(pos_smi / 2, (two_32 + pos_smi) >>> 1);351 assertEquals(pos_non_smi, (two_32 + pos_smi) << 1);352 assertEquals(pos_smi / 8, (two_32 + pos_smi) >> 3);353 assertEquals(pos_smi / 8, (two_32 + pos_smi) >>> 3);354 assertEquals(-0x2329b000, (two_32 + pos_smi) << 3);355 assertEquals(0x73594000, (two_32 + pos_smi) << 5);356 assertEquals(pos_smi, (two_32 + pos_smi + 0.5) >> 0);357 assertEquals(pos_smi, (two_32 + pos_smi + 0.5) >>> 0);358 assertEquals(pos_smi, (two_32 + pos_smi + 0.5) << 0);359 assertEquals(pos_smi / 2, (two_32 + pos_smi + 0.5) >> 1);360 assertEquals(pos_smi / 2, (two_32 + pos_smi + 0.5) >>> 1);361 assertEquals(pos_non_smi, (two_32 + pos_smi + 0.5) << 1);362 assertEquals(pos_smi / 8, (two_32 + pos_smi + 0.5) >> 3);363 assertEquals(pos_smi / 8, (two_32 + pos_smi + 0.5) >>> 3);364 assertEquals(-0x2329b000, (two_32 + pos_smi + 0.5) << 3);365 assertEquals(0x73594000, (two_32 + pos_smi + 0.5) << 5);366 assertEquals(neg_smi / 2, (neg_32 + neg_smi) >> 1);367 assertEquals(neg_smi / 2 + 0x100000000 / 2, (neg_32 + neg_smi) >>> 1);368 assertEquals(neg_non_smi, (neg_32 + neg_smi) << 1);369 assertEquals(neg_smi / 8, (neg_32 + neg_smi) >> 3);370 assertEquals((neg_smi + 0x100000000) / 8, (neg_32 + neg_smi) >>> 3);371 assertEquals(0x46536000, (neg_32 + neg_smi) << 4);372 assertEquals(-0x73594000, (neg_32 + neg_smi) << 5);373 assertEquals(neg_smi, (neg_32 + neg_smi - 0.5) >> 0, "-2^32+negsmi.5 >> 0");374 assertEquals(neg_smi + 0x100000000, (neg_32 + neg_smi - 0.5) >>> 0);375 assertEquals(neg_smi, (neg_32 + neg_smi - 0.5) << 0, "-2^32+negsmi.5 << 0");376 assertEquals(neg_smi / 2, (neg_32 + neg_smi - 0.5) >> 1);377 assertEquals(neg_smi / 2 + 0x100000000 / 2, (neg_32 + neg_smi - 0.5) >>> 1);378 assertEquals(neg_non_smi, (neg_32 + neg_smi - 0.5) << 1);379 assertEquals(neg_smi / 8, (neg_32 + neg_smi - 0.5) >> 3);380 assertEquals(neg_smi / 8 + 0x100000000 / 8, (neg_32 + neg_smi - 0.5) >>> 3);381 assertEquals(0x46536000, (neg_32 + neg_smi - 0.5) << 4);382 assertEquals(-0x73594000, (neg_32 + neg_smi - 0.5) << 5);383 // End block A repeat 1384 // Repeat block A with shift amounts in variables intialized with385 // a constant.386 var zero = 0;387 var one = 1;388 var three = 3;389 var four = 4;390 var five = 5;391 // Begin block A repeat 2392 assertEquals(pos_non_smi, (pos_non_smi) >> zero);393 assertEquals(pos_non_smi, (pos_non_smi) >>> zero);394 assertEquals(pos_non_smi, (pos_non_smi) << zero);395 assertEquals(neg_non_smi, (neg_non_smi) >> zero);396 assertEquals(neg_non_smi + 0x100000000, (neg_non_smi) >>> zero);397 assertEquals(neg_non_smi, (neg_non_smi) << zero);398 assertEquals(pos_smi, (pos_smi) >> zero);399 assertEquals(pos_smi, (pos_smi) >>> zero);400 assertEquals(pos_smi, (pos_smi) << zero);401 assertEquals(neg_smi, (neg_smi) >> zero, "negsmi >> zero");402 assertEquals(neg_smi + 0x100000000, (neg_smi) >>> zero);403 assertEquals(neg_smi, (neg_smi) << zero, "negsmi << zero");404 assertEquals(pos_non_smi / 2, (pos_non_smi) >> one);405 assertEquals(pos_non_smi / 2, (pos_non_smi) >>> one);406 assertEquals(-0x1194D800, (pos_non_smi) << one);407 assertEquals(pos_non_smi / 8, (pos_non_smi) >> three);408 assertEquals(pos_non_smi / 8, (pos_non_smi) >>> three);409 assertEquals(-0x46536000, (pos_non_smi) << three);410 assertEquals(0x73594000, (pos_non_smi) << four);411 assertEquals(pos_non_smi, (pos_non_smi + 0.5) >> zero);412 assertEquals(pos_non_smi, (pos_non_smi + 0.5) >>> zero);413 assertEquals(pos_non_smi, (pos_non_smi + 0.5) << zero);414 assertEquals(pos_non_smi / 2, (pos_non_smi + 0.5) >> one);415 assertEquals(pos_non_smi / 2, (pos_non_smi + 0.5) >>> one);416 assertEquals(-0x1194D800, (pos_non_smi + 0.5) << one);417 assertEquals(pos_non_smi / 8, (pos_non_smi + 0.5) >> three);418 assertEquals(pos_non_smi / 8, (pos_non_smi + 0.5) >>> three);419 assertEquals(-0x46536000, (pos_non_smi + 0.5) << three);420 assertEquals(0x73594000, (pos_non_smi + 0.5) << four);421 assertEquals(neg_non_smi / 2, (neg_non_smi) >> one);422 assertEquals(neg_non_smi / 2 + 0x100000000 / 2, (neg_non_smi) >>> one);423 assertEquals(0x1194D800, (neg_non_smi) << one);424 assertEquals(neg_non_smi / 8, (neg_non_smi) >> three);425 assertEquals(neg_non_smi / 8 + 0x100000000 / 8, (neg_non_smi) >>> three);426 assertEquals(0x46536000, (neg_non_smi) << three);427 assertEquals(-0x73594000, (neg_non_smi) << four);428 assertEquals(neg_non_smi, (neg_non_smi - 0.5) >> zero);429 assertEquals(neg_non_smi + 0x100000000, (neg_non_smi - 0.5) >>> zero);430 assertEquals(neg_non_smi, (neg_non_smi - 0.5) << zero);431 assertEquals(neg_non_smi / 2, (neg_non_smi - 0.5) >> one);432 assertEquals(neg_non_smi / 2 + 0x100000000 / 2, (neg_non_smi - 0.5) >>> one);433 assertEquals(0x1194D800, (neg_non_smi - 0.5) << one);434 assertEquals(neg_non_smi / 8, (neg_non_smi - 0.5) >> three);435 assertEquals(neg_non_smi / 8 + 0x100000000 / 8, (neg_non_smi - 0.5)436 >>> three);437 assertEquals(0x46536000, (neg_non_smi - 0.5) << three);438 assertEquals(-0x73594000, (neg_non_smi - 0.5) << four);439 assertEquals(pos_smi / 2, (pos_smi) >> one);440 assertEquals(pos_smi / 2, (pos_smi) >>> one);441 assertEquals(pos_non_smi, (pos_smi) << one);442 assertEquals(pos_smi / 8, (pos_smi) >> three);443 assertEquals(pos_smi / 8, (pos_smi) >>> three);444 assertEquals(-0x2329b000, (pos_smi) << three);445 assertEquals(0x73594000, (pos_smi) << five);446 assertEquals(pos_smi, (pos_smi + 0.5) >> zero);447 assertEquals(pos_smi, (pos_smi + 0.5) >>> zero);448 assertEquals(pos_smi, (pos_smi + 0.5) << zero);449 assertEquals(pos_smi / 2, (pos_smi + 0.5) >> one);450 assertEquals(pos_smi / 2, (pos_smi + 0.5) >>> one);451 assertEquals(pos_non_smi, (pos_smi + 0.5) << one);452 assertEquals(pos_smi / 8, (pos_smi + 0.5) >> three);453 assertEquals(pos_smi / 8, (pos_smi + 0.5) >>> three);454 assertEquals(-0x2329b000, (pos_smi + 0.5) << three);455 assertEquals(0x73594000, (pos_smi + 0.5) << five);456 assertEquals(neg_smi / 2, (neg_smi) >> one);457 assertEquals(neg_smi / 2 + 0x100000000 / 2, (neg_smi) >>> one);458 assertEquals(neg_non_smi, (neg_smi) << one);459 assertEquals(neg_smi / 8, (neg_smi) >> three);460 assertEquals(neg_smi / 8 + 0x100000000 / 8, (neg_smi) >>> three);461 assertEquals(0x46536000, (neg_smi) << four);462 assertEquals(-0x73594000, (neg_smi) << five);463 assertEquals(neg_smi, (neg_smi - 0.5) >> zero);464 assertEquals(neg_smi + 0x100000000, (neg_smi - 0.5) >>> zero);465 assertEquals(neg_smi, (neg_smi - 0.5) << zero);466 assertEquals(neg_smi / 2, (neg_smi - 0.5) >> one);467 assertEquals(neg_smi / 2 + 0x100000000 / 2, (neg_smi - 0.5) >>> one);468 assertEquals(neg_non_smi, (neg_smi - 0.5) << one);469 assertEquals(neg_smi / 8, (neg_smi - 0.5) >> three);470 assertEquals(neg_smi / 8 + 0x100000000 / 8, (neg_smi - 0.5) >>> three);471 assertEquals(0x46536000, (neg_smi - 0.5) << four);472 assertEquals(-0x73594000, (neg_smi - 0.5) << five);473 // End block A repeat 2474 // Repeat previous block, with computed values in the shift variables.475 five = 0;476 while (five < 5 ) ++five;477 four = five - one;478 three = four - one;479 one = four - three;480 zero = one - one;481 // Begin block A repeat 3482 assertEquals(pos_non_smi, (pos_non_smi) >> zero);483 assertEquals(pos_non_smi, (pos_non_smi) >>> zero);484 assertEquals(pos_non_smi, (pos_non_smi) << zero);485 assertEquals(neg_non_smi, (neg_non_smi) >> zero);486 assertEquals(neg_non_smi + 0x100000000, (neg_non_smi) >>> zero);487 assertEquals(neg_non_smi, (neg_non_smi) << zero);488 assertEquals(pos_smi, (pos_smi) >> zero);489 assertEquals(pos_smi, (pos_smi) >>> zero);490 assertEquals(pos_smi, (pos_smi) << zero);491 assertEquals(neg_smi, (neg_smi) >> zero, "negsmi >> zero(2)");492 assertEquals(neg_smi + 0x100000000, (neg_smi) >>> zero);493 assertEquals(neg_smi, (neg_smi) << zero, "negsmi << zero(2)");494 assertEquals(pos_non_smi / 2, (pos_non_smi) >> one);495 assertEquals(pos_non_smi / 2, (pos_non_smi) >>> one);496 assertEquals(-0x1194D800, (pos_non_smi) << one);497 assertEquals(pos_non_smi / 8, (pos_non_smi) >> three);498 assertEquals(pos_non_smi / 8, (pos_non_smi) >>> three);499 assertEquals(-0x46536000, (pos_non_smi) << three);500 assertEquals(0x73594000, (pos_non_smi) << four);501 assertEquals(pos_non_smi, (pos_non_smi + 0.5) >> zero);502 assertEquals(pos_non_smi, (pos_non_smi + 0.5) >>> zero);503 assertEquals(pos_non_smi, (pos_non_smi + 0.5) << zero);504 assertEquals(pos_non_smi / 2, (pos_non_smi + 0.5) >> one);505 assertEquals(pos_non_smi / 2, (pos_non_smi + 0.5) >>> one);506 assertEquals(-0x1194D800, (pos_non_smi + 0.5) << one);507 assertEquals(pos_non_smi / 8, (pos_non_smi + 0.5) >> three);508 assertEquals(pos_non_smi / 8, (pos_non_smi + 0.5) >>> three);509 assertEquals(-0x46536000, (pos_non_smi + 0.5) << three);510 assertEquals(0x73594000, (pos_non_smi + 0.5) << four);511 assertEquals(neg_non_smi / 2, (neg_non_smi) >> one);512 assertEquals(neg_non_smi / 2 + 0x100000000 / 2, (neg_non_smi) >>> one);513 assertEquals(0x1194D800, (neg_non_smi) << one);514 assertEquals(neg_non_smi / 8, (neg_non_smi) >> three);515 assertEquals(neg_non_smi / 8 + 0x100000000 / 8, (neg_non_smi) >>> three);516 assertEquals(0x46536000, (neg_non_smi) << three);517 assertEquals(-0x73594000, (neg_non_smi) << four);518 assertEquals(neg_non_smi, (neg_non_smi - 0.5) >> zero);519 assertEquals(neg_non_smi + 0x100000000, (neg_non_smi - 0.5) >>> zero);520 assertEquals(neg_non_smi, (neg_non_smi - 0.5) << zero);521 assertEquals(neg_non_smi / 2, (neg_non_smi - 0.5) >> one);522 assertEquals(neg_non_smi / 2 + 0x100000000 / 2, (neg_non_smi - 0.5) >>> one);523 assertEquals(0x1194D800, (neg_non_smi - 0.5) << one);524 assertEquals(neg_non_smi / 8, (neg_non_smi - 0.5) >> three);525 assertEquals(neg_non_smi / 8 + 0x100000000 / 8, (neg_non_smi - 0.5)526 >>> three);527 assertEquals(0x46536000, (neg_non_smi - 0.5) << three);528 assertEquals(-0x73594000, (neg_non_smi - 0.5) << four);529 assertEquals(pos_smi / 2, (pos_smi) >> one);530 assertEquals(pos_smi / 2, (pos_smi) >>> one);531 assertEquals(pos_non_smi, (pos_smi) << one);532 assertEquals(pos_smi / 8, (pos_smi) >> three);533 assertEquals(pos_smi / 8, (pos_smi) >>> three);534 assertEquals(-0x2329b000, (pos_smi) << three);535 assertEquals(0x73594000, (pos_smi) << five);536 assertEquals(pos_smi, (pos_smi + 0.5) >> zero);537 assertEquals(pos_smi, (pos_smi + 0.5) >>> zero);538 assertEquals(pos_smi, (pos_smi + 0.5) << zero);539 assertEquals(pos_smi / 2, (pos_smi + 0.5) >> one);540 assertEquals(pos_smi / 2, (pos_smi + 0.5) >>> one);541 assertEquals(pos_non_smi, (pos_smi + 0.5) << one);542 assertEquals(pos_smi / 8, (pos_smi + 0.5) >> three);543 assertEquals(pos_smi / 8, (pos_smi + 0.5) >>> three);544 assertEquals(-0x2329b000, (pos_smi + 0.5) << three);545 assertEquals(0x73594000, (pos_smi + 0.5) << five);546 assertEquals(neg_smi / 2, (neg_smi) >> one);547 assertEquals(neg_smi / 2 + 0x100000000 / 2, (neg_smi) >>> one);548 assertEquals(neg_non_smi, (neg_smi) << one);549 assertEquals(neg_smi / 8, (neg_smi) >> three);550 assertEquals(neg_smi / 8 + 0x100000000 / 8, (neg_smi) >>> three);551 assertEquals(0x46536000, (neg_smi) << four);552 assertEquals(-0x73594000, (neg_smi) << five);553 assertEquals(neg_smi, (neg_smi - 0.5) >> zero, "negsmi.5 >> zero");554 assertEquals(neg_smi + 0x100000000, (neg_smi - 0.5) >>> zero);555 assertEquals(neg_smi, (neg_smi - 0.5) << zero, "negsmi.5 << zero");556 assertEquals(neg_smi / 2, (neg_smi - 0.5) >> one);557 assertEquals(neg_smi / 2 + 0x100000000 / 2, (neg_smi - 0.5) >>> one);558 assertEquals(neg_non_smi, (neg_smi - 0.5) << one);559 assertEquals(neg_smi / 8, (neg_smi - 0.5) >> three);560 assertEquals(neg_smi / 8 + 0x100000000 / 8, (neg_smi - 0.5) >>> three);561 assertEquals(0x46536000, (neg_smi - 0.5) << four);562 assertEquals(-0x73594000, (neg_smi - 0.5) << five);563 // End block A repeat 3564 // Test non-integer shift value565 assertEquals(5, 20.5 >> 2.4);566 assertEquals(5, 20.5 >> 2.7);567 var shift = 2.4;568 assertEquals(5, 20.5 >> shift);569 assertEquals(5, 20.5 >> shift + 0.3);570 shift = shift + zero;571 assertEquals(5, 20.5 >> shift);572 assertEquals(5, 20.5 >> shift + 0.3);573}574testShiftNonSmis();575function intConversion() {576 function foo(x) {577 assertEquals(x, (x * 1.0000000001) | 0, "foo more " + x);578 assertEquals(x, x | 0, "foo " + x);579 if (x > 0) {580 assertEquals(x - 1, (x * 0.9999999999) | 0, "foo less " + x);581 } else {582 assertEquals(x + 1, (x * 0.9999999999) | 0, "foo less " + x);583 }584 }585 for (var i = 1; i < 0x80000000; i *= 2) {586 foo(i);587 foo(-i);588 }589 for (var i = 1; i < 1/0; i *= 2) {590 assertEquals(i | 0, (i * 1.0000000000000001) | 0, "b" + i);591 assertEquals(-i | 0, (i * -1.0000000000000001) | 0, "c" + i);592 }593 for (var i = 0.5; i > 0; i /= 2) {594 assertEquals(0, i | 0, "d" + i);595 assertEquals(0, -i | 0, "e" + i);596 }597}598intConversion();599// Verify that we handle the (optimized) corner case of shifting by600// zero even for non-smis.601function shiftByZero(n) { return n << 0; }602assertEquals(3, shiftByZero(3.1415));603// Verify that the static type information of x >>> 32 is computed correctly.604function LogicalShiftRightByMultipleOf32(x) {605 x = x >>> 32;606 return x + x;607}608assertEquals(4589934592, LogicalShiftRightByMultipleOf32(-2000000000));609assertEquals(4589934592, LogicalShiftRightByMultipleOf32(-2000000000));610// Verify that the shift amount is reduced modulo 32, not modulo 64.611function LeftShiftThreeBy(x) {return 3 << x;}612assertEquals(24, LeftShiftThreeBy(3));613assertEquals(24, LeftShiftThreeBy(35));614assertEquals(24, LeftShiftThreeBy(67));615assertEquals(24, LeftShiftThreeBy(-29));616// Regression test for a bug in the ARM code generator. For some register617// allocations we got the Smi overflow case wrong.618function f(x, y) { return y + ( 1 << (x & 31)); }619assertEquals(-2147483647, f(31, 1));620// Regression test for correct handling of overflow in smi comparison....
smi-ops-inlined.js
Source:smi-ops-inlined.js
1// Copyright 2010 the V8 project authors. All rights reserved.2// Redistribution and use in source and binary forms, with or without3// modification, are permitted provided that the following conditions are4// met:5//6// * Redistributions of source code must retain the above copyright7// notice, this list of conditions and the following disclaimer.8// * Redistributions in binary form must reproduce the above9// copyright notice, this list of conditions and the following10// disclaimer in the documentation and/or other materials provided11// with the distribution.12// * Neither the name of Google Inc. nor the names of its13// contributors may be used to endorse or promote products derived14// from this software without specific prior written permission.15//16// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS17// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT18// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR19// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT20// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,21// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT22// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,23// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY24// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT25// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE26// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.27// Flags: --always-inline-smi-code28const SMI_MAX = (1 << 30) - 1;29const SMI_MIN = -(1 << 30);30const ONE = 1;31const ONE_HUNDRED = 100;32const OBJ_42 = new (function() {33 this.valueOf = function() { return 42; };34})();35assertEquals(42, OBJ_42.valueOf());36function Add1(x) {37 return x + 1;38}39function Add100(x) {40 return x + 100;41}42function Add1Reversed(x) {43 return 1 + x;44}45function Add100Reversed(x) {46 return 100 + x;47}48assertEquals(1, Add1(0)); // fast case49assertEquals(1, Add1Reversed(0)); // fast case50assertEquals(SMI_MAX + ONE, Add1(SMI_MAX), "smimax + 1");51assertEquals(SMI_MAX + ONE, Add1Reversed(SMI_MAX), "1 + smimax");52assertEquals(42 + ONE, Add1(OBJ_42)); // non-smi53assertEquals(42 + ONE, Add1Reversed(OBJ_42)); // non-smi54assertEquals(100, Add100(0)); // fast case55assertEquals(100, Add100Reversed(0)); // fast case56assertEquals(SMI_MAX + ONE_HUNDRED, Add100(SMI_MAX), "smimax + 100");57assertEquals(SMI_MAX + ONE_HUNDRED, Add100Reversed(SMI_MAX), " 100 + smimax");58assertEquals(42 + ONE_HUNDRED, Add100(OBJ_42)); // non-smi59assertEquals(42 + ONE_HUNDRED, Add100Reversed(OBJ_42)); // non-smi60function Sub1(x) {61 return x - 1;62}63function Sub100(x) {64 return x - 100;65}66function Sub1Reversed(x) {67 return 1 - x;68}69function Sub100Reversed(x) {70 return 100 - x;71}72assertEquals(0, Sub1(1)); // fast case73assertEquals(-1, Sub1Reversed(2)); // fast case74assertEquals(SMI_MIN - ONE, Sub1(SMI_MIN)); // overflow75assertEquals(ONE - SMI_MIN, Sub1Reversed(SMI_MIN)); // overflow76assertEquals(42 - ONE, Sub1(OBJ_42)); // non-smi77assertEquals(ONE - 42, Sub1Reversed(OBJ_42)); // non-smi78assertEquals(0, Sub100(100)); // fast case79assertEquals(1, Sub100Reversed(99)); // fast case80assertEquals(SMI_MIN - ONE_HUNDRED, Sub100(SMI_MIN)); // overflow81assertEquals(ONE_HUNDRED - SMI_MIN, Sub100Reversed(SMI_MIN)); // overflow82assertEquals(42 - ONE_HUNDRED, Sub100(OBJ_42)); // non-smi83assertEquals(ONE_HUNDRED - 42, Sub100Reversed(OBJ_42)); // non-smi84function Shr1(x) {85 return x >>> 1;86}87function Shr100(x) {88 return x >>> 100;89}90function Shr1Reversed(x) {91 return 1 >>> x;92}93function Shr100Reversed(x) {94 return 100 >>> x;95}96function Sar1(x) {97 return x >> 1;98}99function Sar100(x) {100 return x >> 100;101}102function Sar1Reversed(x) {103 return 1 >> x;104}105function Sar100Reversed(x) {106 return 100 >> x;107}108assertEquals(0, Shr1(1));109assertEquals(0, Sar1(1));110assertEquals(0, Shr1Reversed(2));111assertEquals(0, Sar1Reversed(2));112assertEquals(1610612736, Shr1(SMI_MIN));113assertEquals(-536870912, Sar1(SMI_MIN));114assertEquals(1, Shr1Reversed(SMI_MIN));115assertEquals(1, Sar1Reversed(SMI_MIN));116assertEquals(21, Shr1(OBJ_42));117assertEquals(21, Sar1(OBJ_42));118assertEquals(0, Shr1Reversed(OBJ_42));119assertEquals(0, Sar1Reversed(OBJ_42));120assertEquals(6, Shr100(100), "100 >>> 100");121assertEquals(6, Sar100(100), "100 >> 100");122assertEquals(12, Shr100Reversed(99));123assertEquals(12, Sar100Reversed(99));124assertEquals(201326592, Shr100(SMI_MIN));125assertEquals(-67108864, Sar100(SMI_MIN));126assertEquals(100, Shr100Reversed(SMI_MIN));127assertEquals(100, Sar100Reversed(SMI_MIN));128assertEquals(2, Shr100(OBJ_42));129assertEquals(2, Sar100(OBJ_42));130assertEquals(0, Shr100Reversed(OBJ_42));131assertEquals(0, Sar100Reversed(OBJ_42));132function Xor1(x) {133 return x ^ 1;134}135function Xor100(x) {136 return x ^ 100;137}138function Xor1Reversed(x) {139 return 1 ^ x;140}141function Xor100Reversed(x) {142 return 100 ^ x;143}144assertEquals(0, Xor1(1));145assertEquals(3, Xor1Reversed(2));146assertEquals(SMI_MIN + 1, Xor1(SMI_MIN));147assertEquals(SMI_MIN + 1, Xor1Reversed(SMI_MIN));148assertEquals(43, Xor1(OBJ_42));149assertEquals(43, Xor1Reversed(OBJ_42));150assertEquals(0, Xor100(100));151assertEquals(7, Xor100Reversed(99));152assertEquals(-1073741724, Xor100(SMI_MIN));153assertEquals(-1073741724, Xor100Reversed(SMI_MIN));154assertEquals(78, Xor100(OBJ_42));155assertEquals(78, Xor100Reversed(OBJ_42));156var x = 0x23; var y = 0x35;157assertEquals(0x16, x ^ y);158// Bitwise not.159var v = 0;160assertEquals(-1, ~v);161v = SMI_MIN;162assertEquals(0x3fffffff, ~v, "~smimin");163v = SMI_MAX;164assertEquals(-0x40000000, ~v, "~smimax");165// Overflowing ++ and --.166v = SMI_MAX;167v++;168assertEquals(0x40000000, v, "smimax++");169v = SMI_MIN;170v--;171assertEquals(-0x40000001, v, "smimin--");172// Not actually Smi operations.173// Check that relations on unary ops work.174var v = -1.2;175assertTrue(v == v);176assertTrue(v === v);177assertTrue(v <= v);178assertTrue(v >= v);179assertFalse(v < v);180assertFalse(v > v);181assertFalse(v != v);182assertFalse(v !== v);183// Right hand side of unary minus is overwritable.184v = 1.5185assertEquals(-2.25, -(v * v));186// Smi input to bitop gives non-smi result where the rhs is a float that187// can be overwritten.188var x1 = 0x10000000;189var x2 = 0x40000002;190var x3 = 0x40000000;191assertEquals(0x40000000, x1 << (x2 - x3), "0x10000000<<1(1)");192// Smi input to bitop gives non-smi result where the rhs could be overwritten193// if it were a float, but it isn't.194x1 = 0x10000000195x2 = 4196x3 = 2197assertEquals(0x40000000, x1 << (x2 - x3), "0x10000000<<2(2)");198// Test shift operators on non-smi inputs, giving smi and non-smi results.199function testShiftNonSmis() {200 var pos_non_smi = 2000000000;201 var neg_non_smi = -pos_non_smi;202 var pos_smi = 1000000000;203 var neg_smi = -pos_smi;204 // Begin block A205 assertEquals(pos_non_smi, (pos_non_smi) >> 0);206 assertEquals(pos_non_smi, (pos_non_smi) >>> 0);207 assertEquals(pos_non_smi, (pos_non_smi) << 0);208 assertEquals(neg_non_smi, (neg_non_smi) >> 0);209 assertEquals(neg_non_smi + 0x100000000, (neg_non_smi) >>> 0);210 assertEquals(neg_non_smi, (neg_non_smi) << 0);211 assertEquals(pos_smi, (pos_smi) >> 0, "possmi >> 0");212 assertEquals(pos_smi, (pos_smi) >>> 0, "possmi >>>0");213 assertEquals(pos_smi, (pos_smi) << 0, "possmi << 0");214 assertEquals(neg_smi, (neg_smi) >> 0, "negsmi >> 0");215 assertEquals(neg_smi + 0x100000000, (neg_smi) >>> 0, "negsmi >>> 0");216 assertEquals(neg_smi, (neg_smi) << 0), "negsmi << 0";217 assertEquals(pos_non_smi / 2, (pos_non_smi) >> 1);218 assertEquals(pos_non_smi / 2, (pos_non_smi) >>> 1);219 assertEquals(-0x1194D800, (pos_non_smi) << 1);220 assertEquals(pos_non_smi / 8, (pos_non_smi) >> 3);221 assertEquals(pos_non_smi / 8, (pos_non_smi) >>> 3);222 assertEquals(-0x46536000, (pos_non_smi) << 3);223 assertEquals(0x73594000, (pos_non_smi) << 4);224 assertEquals(pos_non_smi, (pos_non_smi + 0.5) >> 0);225 assertEquals(pos_non_smi, (pos_non_smi + 0.5) >>> 0);226 assertEquals(pos_non_smi, (pos_non_smi + 0.5) << 0);227 assertEquals(pos_non_smi / 2, (pos_non_smi + 0.5) >> 1);228 assertEquals(pos_non_smi / 2, (pos_non_smi + 0.5) >>> 1);229 assertEquals(-0x1194D800, (pos_non_smi + 0.5) << 1);230 assertEquals(pos_non_smi / 8, (pos_non_smi + 0.5) >> 3);231 assertEquals(pos_non_smi / 8, (pos_non_smi + 0.5) >>> 3);232 assertEquals(-0x46536000, (pos_non_smi + 0.5) << 3);233 assertEquals(0x73594000, (pos_non_smi + 0.5) << 4);234 assertEquals(neg_non_smi / 2, (neg_non_smi) >> 1, "negnonsmi >> 1");235 assertEquals(neg_non_smi / 2 + 0x100000000 / 2, (neg_non_smi) >>> 1,236 "negnonsmi >>> 1");237 assertEquals(0x1194D800, (neg_non_smi) << 1);238 assertEquals(neg_non_smi / 8, (neg_non_smi) >> 3);239 assertEquals(neg_non_smi / 8 + 0x100000000 / 8, (neg_non_smi) >>> 3);240 assertEquals(0x46536000, (neg_non_smi) << 3);241 assertEquals(-0x73594000, (neg_non_smi) << 4);242 assertEquals(neg_non_smi, (neg_non_smi - 0.5) >> 0);243 assertEquals(neg_non_smi + 0x100000000, (neg_non_smi - 0.5) >>> 0,244 "negnonsmi.5 >>> 0");245 assertEquals(neg_non_smi, (neg_non_smi - 0.5) << 0);246 assertEquals(neg_non_smi / 2, (neg_non_smi - 0.5) >> 1);247 assertEquals(neg_non_smi / 2 + 0x100000000 / 2, (neg_non_smi - 0.5) >>> 1,248 "negnonsmi.5 >>> 1");249 assertEquals(0x1194D800, (neg_non_smi - 0.5) << 1);250 assertEquals(neg_non_smi / 8, (neg_non_smi - 0.5) >> 3);251 assertEquals(neg_non_smi / 8 + 0x100000000 / 8, (neg_non_smi - 0.5) >>> 3);252 assertEquals(0x46536000, (neg_non_smi - 0.5) << 3);253 assertEquals(-0x73594000, (neg_non_smi - 0.5) << 4);254 assertEquals(pos_smi / 2, (pos_smi) >> 1);255 assertEquals(pos_smi / 2, (pos_smi) >>> 1);256 assertEquals(pos_non_smi, (pos_smi) << 1);257 assertEquals(pos_smi / 8, (pos_smi) >> 3);258 assertEquals(pos_smi / 8, (pos_smi) >>> 3);259 assertEquals(-0x2329b000, (pos_smi) << 3);260 assertEquals(0x73594000, (pos_smi) << 5);261 assertEquals(pos_smi, (pos_smi + 0.5) >> 0, "possmi.5 >> 0");262 assertEquals(pos_smi, (pos_smi + 0.5) >>> 0, "possmi.5 >>> 0");263 assertEquals(pos_smi, (pos_smi + 0.5) << 0, "possmi.5 << 0");264 assertEquals(pos_smi / 2, (pos_smi + 0.5) >> 1);265 assertEquals(pos_smi / 2, (pos_smi + 0.5) >>> 1);266 assertEquals(pos_non_smi, (pos_smi + 0.5) << 1);267 assertEquals(pos_smi / 8, (pos_smi + 0.5) >> 3);268 assertEquals(pos_smi / 8, (pos_smi + 0.5) >>> 3);269 assertEquals(-0x2329b000, (pos_smi + 0.5) << 3);270 assertEquals(0x73594000, (pos_smi + 0.5) << 5);271 assertEquals(neg_smi / 2, (neg_smi) >> 1);272 assertEquals(neg_smi / 2 + 0x100000000 / 2, (neg_smi) >>> 1);273 assertEquals(neg_non_smi, (neg_smi) << 1);274 assertEquals(neg_smi / 8, (neg_smi) >> 3);275 assertEquals(neg_smi / 8 + 0x100000000 / 8, (neg_smi) >>> 3);276 assertEquals(0x46536000, (neg_smi) << 4);277 assertEquals(-0x73594000, (neg_smi) << 5);278 assertEquals(neg_smi, (neg_smi - 0.5) >> 0, "negsmi.5 >> 0");279 assertEquals(neg_smi + 0x100000000, (neg_smi - 0.5) >>> 0, "negsmi.5 >>> 0");280 assertEquals(neg_smi, (neg_smi - 0.5) << 0, "negsmi.5 << 0");281 assertEquals(neg_smi / 2, (neg_smi - 0.5) >> 1);282 assertEquals(neg_smi / 2 + 0x100000000 / 2, (neg_smi - 0.5) >>> 1);283 assertEquals(neg_non_smi, (neg_smi - 0.5) << 1);284 assertEquals(neg_smi / 8, (neg_smi - 0.5) >> 3);285 assertEquals(neg_smi / 8 + 0x100000000 / 8, (neg_smi - 0.5) >>> 3);286 assertEquals(0x46536000, (neg_smi - 0.5) << 4);287 assertEquals(-0x73594000, (neg_smi - 0.5) << 5);288 // End block A289 // Repeat block A with 2^32 added to positive numbers and290 // 2^32 subtracted from negative numbers.291 // Begin block A repeat 1292 var two_32 = 0x100000000;293 var neg_32 = -two_32;294 assertEquals(pos_non_smi, (two_32 + pos_non_smi) >> 0);295 assertEquals(pos_non_smi, (two_32 + pos_non_smi) >>> 0);296 assertEquals(pos_non_smi, (two_32 + pos_non_smi) << 0);297 assertEquals(neg_non_smi, (neg_32 + neg_non_smi) >> 0);298 assertEquals(neg_non_smi + 0x100000000, (neg_32 + neg_non_smi) >>> 0);299 assertEquals(neg_non_smi, (neg_32 + neg_non_smi) << 0);300 assertEquals(pos_smi, (two_32 + pos_smi) >> 0, "2^32+possmi >> 0");301 assertEquals(pos_smi, (two_32 + pos_smi) >>> 0, "2^32+possmi >>> 0");302 assertEquals(pos_smi, (two_32 + pos_smi) << 0, "2^32+possmi << 0");303 assertEquals(neg_smi, (neg_32 + neg_smi) >> 0, "2^32+negsmi >> 0");304 assertEquals(neg_smi + 0x100000000, (neg_32 + neg_smi) >>> 0);305 assertEquals(neg_smi, (neg_32 + neg_smi) << 0, "2^32+negsmi << 0");306 assertEquals(pos_non_smi / 2, (two_32 + pos_non_smi) >> 1);307 assertEquals(pos_non_smi / 2, (two_32 + pos_non_smi) >>> 1);308 assertEquals(-0x1194D800, (two_32 + pos_non_smi) << 1);309 assertEquals(pos_non_smi / 8, (two_32 + pos_non_smi) >> 3);310 assertEquals(pos_non_smi / 8, (two_32 + pos_non_smi) >>> 3);311 assertEquals(-0x46536000, (two_32 + pos_non_smi) << 3);312 assertEquals(0x73594000, (two_32 + pos_non_smi) << 4);313 assertEquals(pos_non_smi, (two_32 + pos_non_smi + 0.5) >> 0);314 assertEquals(pos_non_smi, (two_32 + pos_non_smi + 0.5) >>> 0);315 assertEquals(pos_non_smi, (two_32 + pos_non_smi + 0.5) << 0);316 assertEquals(pos_non_smi / 2, (two_32 + pos_non_smi + 0.5) >> 1);317 assertEquals(pos_non_smi / 2, (two_32 + pos_non_smi + 0.5) >>> 1);318 assertEquals(-0x1194D800, (two_32 + pos_non_smi + 0.5) << 1);319 assertEquals(pos_non_smi / 8, (two_32 + pos_non_smi + 0.5) >> 3);320 assertEquals(pos_non_smi / 8, (two_32 + pos_non_smi + 0.5) >>> 3);321 assertEquals(-0x46536000, (two_32 + pos_non_smi + 0.5) << 3);322 assertEquals(0x73594000, (two_32 + pos_non_smi + 0.5) << 4);323 assertEquals(neg_non_smi / 2, (neg_32 + neg_non_smi) >> 1);324 assertEquals(neg_non_smi / 2 + 0x100000000 / 2, (neg_32 + neg_non_smi) >>> 1);325 assertEquals(0x1194D800, (neg_32 + neg_non_smi) << 1);326 assertEquals(neg_non_smi / 8, (neg_32 + neg_non_smi) >> 3);327 assertEquals(neg_non_smi / 8 + 0x100000000 / 8, (neg_32 + neg_non_smi) >>> 3);328 assertEquals(0x46536000, (neg_32 + neg_non_smi) << 3);329 assertEquals(-0x73594000, (neg_32 + neg_non_smi) << 4);330 assertEquals(neg_non_smi, (neg_32 + neg_non_smi - 0.5) >> 0);331 assertEquals(neg_non_smi + 0x100000000, (neg_32 + neg_non_smi - 0.5) >>> 0);332 assertEquals(neg_non_smi, (neg_32 + neg_non_smi - 0.5) << 0);333 assertEquals(neg_non_smi / 2, (neg_32 + neg_non_smi - 0.5) >> 1);334 assertEquals(neg_non_smi / 2 + 0x100000000 / 2, (neg_32 + neg_non_smi - 0.5)335 >>> 1);336 assertEquals(0x1194D800, (neg_32 + neg_non_smi - 0.5) << 1);337 assertEquals(neg_non_smi / 8, (neg_32 + neg_non_smi - 0.5) >> 3);338 assertEquals(neg_non_smi / 8 + 0x100000000 / 8, (neg_32 + neg_non_smi - 0.5)339 >>> 3);340 assertEquals(0x46536000, (neg_32 + neg_non_smi - 0.5) << 3);341 assertEquals(-0x73594000, (neg_32 + neg_non_smi - 0.5) << 4);342 assertEquals(pos_smi / 2, (two_32 + pos_smi) >> 1);343 assertEquals(pos_smi / 2, (two_32 + pos_smi) >>> 1);344 assertEquals(pos_non_smi, (two_32 + pos_smi) << 1);345 assertEquals(pos_smi / 8, (two_32 + pos_smi) >> 3);346 assertEquals(pos_smi / 8, (two_32 + pos_smi) >>> 3);347 assertEquals(-0x2329b000, (two_32 + pos_smi) << 3);348 assertEquals(0x73594000, (two_32 + pos_smi) << 5);349 assertEquals(pos_smi, (two_32 + pos_smi + 0.5) >> 0);350 assertEquals(pos_smi, (two_32 + pos_smi + 0.5) >>> 0);351 assertEquals(pos_smi, (two_32 + pos_smi + 0.5) << 0);352 assertEquals(pos_smi / 2, (two_32 + pos_smi + 0.5) >> 1);353 assertEquals(pos_smi / 2, (two_32 + pos_smi + 0.5) >>> 1);354 assertEquals(pos_non_smi, (two_32 + pos_smi + 0.5) << 1);355 assertEquals(pos_smi / 8, (two_32 + pos_smi + 0.5) >> 3);356 assertEquals(pos_smi / 8, (two_32 + pos_smi + 0.5) >>> 3);357 assertEquals(-0x2329b000, (two_32 + pos_smi + 0.5) << 3);358 assertEquals(0x73594000, (two_32 + pos_smi + 0.5) << 5);359 assertEquals(neg_smi / 2, (neg_32 + neg_smi) >> 1);360 assertEquals(neg_smi / 2 + 0x100000000 / 2, (neg_32 + neg_smi) >>> 1);361 assertEquals(neg_non_smi, (neg_32 + neg_smi) << 1);362 assertEquals(neg_smi / 8, (neg_32 + neg_smi) >> 3);363 assertEquals((neg_smi + 0x100000000) / 8, (neg_32 + neg_smi) >>> 3);364 assertEquals(0x46536000, (neg_32 + neg_smi) << 4);365 assertEquals(-0x73594000, (neg_32 + neg_smi) << 5);366 assertEquals(neg_smi, (neg_32 + neg_smi - 0.5) >> 0, "-2^32+negsmi.5 >> 0");367 assertEquals(neg_smi + 0x100000000, (neg_32 + neg_smi - 0.5) >>> 0);368 assertEquals(neg_smi, (neg_32 + neg_smi - 0.5) << 0, "-2^32+negsmi.5 << 0");369 assertEquals(neg_smi / 2, (neg_32 + neg_smi - 0.5) >> 1);370 assertEquals(neg_smi / 2 + 0x100000000 / 2, (neg_32 + neg_smi - 0.5) >>> 1);371 assertEquals(neg_non_smi, (neg_32 + neg_smi - 0.5) << 1);372 assertEquals(neg_smi / 8, (neg_32 + neg_smi - 0.5) >> 3);373 assertEquals(neg_smi / 8 + 0x100000000 / 8, (neg_32 + neg_smi - 0.5) >>> 3);374 assertEquals(0x46536000, (neg_32 + neg_smi - 0.5) << 4);375 assertEquals(-0x73594000, (neg_32 + neg_smi - 0.5) << 5);376 // End block A repeat 1377 // Repeat block A with shift amounts in variables intialized with378 // a constant.379 var zero = 0;380 var one = 1;381 var three = 3;382 var four = 4;383 var five = 5;384 // Begin block A repeat 2385 assertEquals(pos_non_smi, (pos_non_smi) >> zero);386 assertEquals(pos_non_smi, (pos_non_smi) >>> zero);387 assertEquals(pos_non_smi, (pos_non_smi) << zero);388 assertEquals(neg_non_smi, (neg_non_smi) >> zero);389 assertEquals(neg_non_smi + 0x100000000, (neg_non_smi) >>> zero);390 assertEquals(neg_non_smi, (neg_non_smi) << zero);391 assertEquals(pos_smi, (pos_smi) >> zero);392 assertEquals(pos_smi, (pos_smi) >>> zero);393 assertEquals(pos_smi, (pos_smi) << zero);394 assertEquals(neg_smi, (neg_smi) >> zero, "negsmi >> zero");395 assertEquals(neg_smi + 0x100000000, (neg_smi) >>> zero);396 assertEquals(neg_smi, (neg_smi) << zero, "negsmi << zero");397 assertEquals(pos_non_smi / 2, (pos_non_smi) >> one);398 assertEquals(pos_non_smi / 2, (pos_non_smi) >>> one);399 assertEquals(-0x1194D800, (pos_non_smi) << one);400 assertEquals(pos_non_smi / 8, (pos_non_smi) >> three);401 assertEquals(pos_non_smi / 8, (pos_non_smi) >>> three);402 assertEquals(-0x46536000, (pos_non_smi) << three);403 assertEquals(0x73594000, (pos_non_smi) << four);404 assertEquals(pos_non_smi, (pos_non_smi + 0.5) >> zero);405 assertEquals(pos_non_smi, (pos_non_smi + 0.5) >>> zero);406 assertEquals(pos_non_smi, (pos_non_smi + 0.5) << zero);407 assertEquals(pos_non_smi / 2, (pos_non_smi + 0.5) >> one);408 assertEquals(pos_non_smi / 2, (pos_non_smi + 0.5) >>> one);409 assertEquals(-0x1194D800, (pos_non_smi + 0.5) << one);410 assertEquals(pos_non_smi / 8, (pos_non_smi + 0.5) >> three);411 assertEquals(pos_non_smi / 8, (pos_non_smi + 0.5) >>> three);412 assertEquals(-0x46536000, (pos_non_smi + 0.5) << three);413 assertEquals(0x73594000, (pos_non_smi + 0.5) << four);414 assertEquals(neg_non_smi / 2, (neg_non_smi) >> one);415 assertEquals(neg_non_smi / 2 + 0x100000000 / 2, (neg_non_smi) >>> one);416 assertEquals(0x1194D800, (neg_non_smi) << one);417 assertEquals(neg_non_smi / 8, (neg_non_smi) >> three);418 assertEquals(neg_non_smi / 8 + 0x100000000 / 8, (neg_non_smi) >>> three);419 assertEquals(0x46536000, (neg_non_smi) << three);420 assertEquals(-0x73594000, (neg_non_smi) << four);421 assertEquals(neg_non_smi, (neg_non_smi - 0.5) >> zero);422 assertEquals(neg_non_smi + 0x100000000, (neg_non_smi - 0.5) >>> zero);423 assertEquals(neg_non_smi, (neg_non_smi - 0.5) << zero);424 assertEquals(neg_non_smi / 2, (neg_non_smi - 0.5) >> one);425 assertEquals(neg_non_smi / 2 + 0x100000000 / 2, (neg_non_smi - 0.5) >>> one);426 assertEquals(0x1194D800, (neg_non_smi - 0.5) << one);427 assertEquals(neg_non_smi / 8, (neg_non_smi - 0.5) >> three);428 assertEquals(neg_non_smi / 8 + 0x100000000 / 8, (neg_non_smi - 0.5)429 >>> three);430 assertEquals(0x46536000, (neg_non_smi - 0.5) << three);431 assertEquals(-0x73594000, (neg_non_smi - 0.5) << four);432 assertEquals(pos_smi / 2, (pos_smi) >> one);433 assertEquals(pos_smi / 2, (pos_smi) >>> one);434 assertEquals(pos_non_smi, (pos_smi) << one);435 assertEquals(pos_smi / 8, (pos_smi) >> three);436 assertEquals(pos_smi / 8, (pos_smi) >>> three);437 assertEquals(-0x2329b000, (pos_smi) << three);438 assertEquals(0x73594000, (pos_smi) << five);439 assertEquals(pos_smi, (pos_smi + 0.5) >> zero);440 assertEquals(pos_smi, (pos_smi + 0.5) >>> zero);441 assertEquals(pos_smi, (pos_smi + 0.5) << zero);442 assertEquals(pos_smi / 2, (pos_smi + 0.5) >> one);443 assertEquals(pos_smi / 2, (pos_smi + 0.5) >>> one);444 assertEquals(pos_non_smi, (pos_smi + 0.5) << one);445 assertEquals(pos_smi / 8, (pos_smi + 0.5) >> three);446 assertEquals(pos_smi / 8, (pos_smi + 0.5) >>> three);447 assertEquals(-0x2329b000, (pos_smi + 0.5) << three);448 assertEquals(0x73594000, (pos_smi + 0.5) << five);449 assertEquals(neg_smi / 2, (neg_smi) >> one);450 assertEquals(neg_smi / 2 + 0x100000000 / 2, (neg_smi) >>> one);451 assertEquals(neg_non_smi, (neg_smi) << one);452 assertEquals(neg_smi / 8, (neg_smi) >> three);453 assertEquals(neg_smi / 8 + 0x100000000 / 8, (neg_smi) >>> three);454 assertEquals(0x46536000, (neg_smi) << four);455 assertEquals(-0x73594000, (neg_smi) << five);456 assertEquals(neg_smi, (neg_smi - 0.5) >> zero);457 assertEquals(neg_smi + 0x100000000, (neg_smi - 0.5) >>> zero);458 assertEquals(neg_smi, (neg_smi - 0.5) << zero);459 assertEquals(neg_smi / 2, (neg_smi - 0.5) >> one);460 assertEquals(neg_smi / 2 + 0x100000000 / 2, (neg_smi - 0.5) >>> one);461 assertEquals(neg_non_smi, (neg_smi - 0.5) << one);462 assertEquals(neg_smi / 8, (neg_smi - 0.5) >> three);463 assertEquals(neg_smi / 8 + 0x100000000 / 8, (neg_smi - 0.5) >>> three);464 assertEquals(0x46536000, (neg_smi - 0.5) << four);465 assertEquals(-0x73594000, (neg_smi - 0.5) << five);466 // End block A repeat 2467 // Repeat previous block, with computed values in the shift variables.468 five = 0;469 while (five < 5 ) ++five;470 four = five - one;471 three = four - one;472 one = four - three;473 zero = one - one;474 // Begin block A repeat 3475 assertEquals(pos_non_smi, (pos_non_smi) >> zero);476 assertEquals(pos_non_smi, (pos_non_smi) >>> zero);477 assertEquals(pos_non_smi, (pos_non_smi) << zero);478 assertEquals(neg_non_smi, (neg_non_smi) >> zero);479 assertEquals(neg_non_smi + 0x100000000, (neg_non_smi) >>> zero);480 assertEquals(neg_non_smi, (neg_non_smi) << zero);481 assertEquals(pos_smi, (pos_smi) >> zero);482 assertEquals(pos_smi, (pos_smi) >>> zero);483 assertEquals(pos_smi, (pos_smi) << zero);484 assertEquals(neg_smi, (neg_smi) >> zero, "negsmi >> zero(2)");485 assertEquals(neg_smi + 0x100000000, (neg_smi) >>> zero);486 assertEquals(neg_smi, (neg_smi) << zero, "negsmi << zero(2)");487 assertEquals(pos_non_smi / 2, (pos_non_smi) >> one);488 assertEquals(pos_non_smi / 2, (pos_non_smi) >>> one);489 assertEquals(-0x1194D800, (pos_non_smi) << one);490 assertEquals(pos_non_smi / 8, (pos_non_smi) >> three);491 assertEquals(pos_non_smi / 8, (pos_non_smi) >>> three);492 assertEquals(-0x46536000, (pos_non_smi) << three);493 assertEquals(0x73594000, (pos_non_smi) << four);494 assertEquals(pos_non_smi, (pos_non_smi + 0.5) >> zero);495 assertEquals(pos_non_smi, (pos_non_smi + 0.5) >>> zero);496 assertEquals(pos_non_smi, (pos_non_smi + 0.5) << zero);497 assertEquals(pos_non_smi / 2, (pos_non_smi + 0.5) >> one);498 assertEquals(pos_non_smi / 2, (pos_non_smi + 0.5) >>> one);499 assertEquals(-0x1194D800, (pos_non_smi + 0.5) << one);500 assertEquals(pos_non_smi / 8, (pos_non_smi + 0.5) >> three);501 assertEquals(pos_non_smi / 8, (pos_non_smi + 0.5) >>> three);502 assertEquals(-0x46536000, (pos_non_smi + 0.5) << three);503 assertEquals(0x73594000, (pos_non_smi + 0.5) << four);504 assertEquals(neg_non_smi / 2, (neg_non_smi) >> one);505 assertEquals(neg_non_smi / 2 + 0x100000000 / 2, (neg_non_smi) >>> one);506 assertEquals(0x1194D800, (neg_non_smi) << one);507 assertEquals(neg_non_smi / 8, (neg_non_smi) >> three);508 assertEquals(neg_non_smi / 8 + 0x100000000 / 8, (neg_non_smi) >>> three);509 assertEquals(0x46536000, (neg_non_smi) << three);510 assertEquals(-0x73594000, (neg_non_smi) << four);511 assertEquals(neg_non_smi, (neg_non_smi - 0.5) >> zero);512 assertEquals(neg_non_smi + 0x100000000, (neg_non_smi - 0.5) >>> zero);513 assertEquals(neg_non_smi, (neg_non_smi - 0.5) << zero);514 assertEquals(neg_non_smi / 2, (neg_non_smi - 0.5) >> one);515 assertEquals(neg_non_smi / 2 + 0x100000000 / 2, (neg_non_smi - 0.5) >>> one);516 assertEquals(0x1194D800, (neg_non_smi - 0.5) << one);517 assertEquals(neg_non_smi / 8, (neg_non_smi - 0.5) >> three);518 assertEquals(neg_non_smi / 8 + 0x100000000 / 8, (neg_non_smi - 0.5)519 >>> three);520 assertEquals(0x46536000, (neg_non_smi - 0.5) << three);521 assertEquals(-0x73594000, (neg_non_smi - 0.5) << four);522 assertEquals(pos_smi / 2, (pos_smi) >> one);523 assertEquals(pos_smi / 2, (pos_smi) >>> one);524 assertEquals(pos_non_smi, (pos_smi) << one);525 assertEquals(pos_smi / 8, (pos_smi) >> three);526 assertEquals(pos_smi / 8, (pos_smi) >>> three);527 assertEquals(-0x2329b000, (pos_smi) << three);528 assertEquals(0x73594000, (pos_smi) << five);529 assertEquals(pos_smi, (pos_smi + 0.5) >> zero);530 assertEquals(pos_smi, (pos_smi + 0.5) >>> zero);531 assertEquals(pos_smi, (pos_smi + 0.5) << zero);532 assertEquals(pos_smi / 2, (pos_smi + 0.5) >> one);533 assertEquals(pos_smi / 2, (pos_smi + 0.5) >>> one);534 assertEquals(pos_non_smi, (pos_smi + 0.5) << one);535 assertEquals(pos_smi / 8, (pos_smi + 0.5) >> three);536 assertEquals(pos_smi / 8, (pos_smi + 0.5) >>> three);537 assertEquals(-0x2329b000, (pos_smi + 0.5) << three);538 assertEquals(0x73594000, (pos_smi + 0.5) << five);539 assertEquals(neg_smi / 2, (neg_smi) >> one);540 assertEquals(neg_smi / 2 + 0x100000000 / 2, (neg_smi) >>> one);541 assertEquals(neg_non_smi, (neg_smi) << one);542 assertEquals(neg_smi / 8, (neg_smi) >> three);543 assertEquals(neg_smi / 8 + 0x100000000 / 8, (neg_smi) >>> three);544 assertEquals(0x46536000, (neg_smi) << four);545 assertEquals(-0x73594000, (neg_smi) << five);546 assertEquals(neg_smi, (neg_smi - 0.5) >> zero, "negsmi.5 >> zero");547 assertEquals(neg_smi + 0x100000000, (neg_smi - 0.5) >>> zero);548 assertEquals(neg_smi, (neg_smi - 0.5) << zero, "negsmi.5 << zero");549 assertEquals(neg_smi / 2, (neg_smi - 0.5) >> one);550 assertEquals(neg_smi / 2 + 0x100000000 / 2, (neg_smi - 0.5) >>> one);551 assertEquals(neg_non_smi, (neg_smi - 0.5) << one);552 assertEquals(neg_smi / 8, (neg_smi - 0.5) >> three);553 assertEquals(neg_smi / 8 + 0x100000000 / 8, (neg_smi - 0.5) >>> three);554 assertEquals(0x46536000, (neg_smi - 0.5) << four);555 assertEquals(-0x73594000, (neg_smi - 0.5) << five);556 // End block A repeat 3557 // Test non-integer shift value558 assertEquals(5, 20.5 >> 2.4);559 assertEquals(5, 20.5 >> 2.7);560 var shift = 2.4;561 assertEquals(5, 20.5 >> shift);562 assertEquals(5, 20.5 >> shift + 0.3);563 shift = shift + zero;564 assertEquals(5, 20.5 >> shift);565 assertEquals(5, 20.5 >> shift + 0.3);566}567testShiftNonSmis();568function intConversion() {569 function foo(x) {570 assertEquals(x, (x * 1.0000000001) | 0, "foo more " + x);571 assertEquals(x, x | 0, "foo " + x);572 if (x > 0) {573 assertEquals(x - 1, (x * 0.9999999999) | 0, "foo less " + x);574 } else {575 assertEquals(x + 1, (x * 0.9999999999) | 0, "foo less " + x);576 }577 }578 for (var i = 1; i < 0x80000000; i *= 2) {579 foo(i);580 foo(-i);581 }582 for (var i = 1; i < 1/0; i *= 2) {583 assertEquals(i | 0, (i * 1.0000000000000001) | 0, "b" + i);584 assertEquals(-i | 0, (i * -1.0000000000000001) | 0, "c" + i);585 }586 for (var i = 0.5; i > 0; i /= 2) {587 assertEquals(0, i | 0, "d" + i);588 assertEquals(0, -i | 0, "e" + i);589 }590}591intConversion();592// Verify that we handle the (optimized) corner case of shifting by593// zero even for non-smis.594function shiftByZero(n) { return n << 0; }...
Using AI Code Generation
1var wptools = require('wptools');2var page = wptools.page('Albert Einstein');3page.neg(function(err, resp) {4 console.log(resp);5});6var wptools = require('wptools');7var page = wptools.page('Albert Einstein');8page.neg(function(err, resp) {9 console.log(resp);10});11var wptools = require('wptools');12var page = wptools.page('Albert Einstein');13page.neg(function(err, resp) {14 console.log(resp);15});16var wptools = require('wptools');17var page = wptools.page('Albert Einstein');18page.neg(function(err, resp) {19 console.log(resp);20});21var wptools = require('wptools');22var page = wptools.page('Albert Einstein');23page.neg(function(err, resp) {24 console.log(resp);25});26var wptools = require('wptools');27var page = wptools.page('Albert Einstein');28page.neg(function(err, resp) {29 console.log(resp);30});31var wptools = require('wptools');32var page = wptools.page('Albert Einstein');33page.neg(function(err, resp) {34 console.log(resp);35});36var wptools = require('wptools');37var page = wptools.page('Albert Einstein');38page.neg(function(err, resp) {39 console.log(resp);40});41var wptools = require('wptools');42var page = wptools.page('Albert Einstein');43page.neg(function(err, resp) {44 console.log(resp);45});46var wptools = require('wptools');47var page = wptools.page('Albert
Using AI Code Generation
1var wpt = require('wpt');2var wpt = new WebPageTest('www.webpagetest.org');3wpt.getLocations(function(err, data) {4 if (err) return console.error(err);5 console.log(data);6});7wpt.getTestStatus('150203_4F_1', function(err, data) {8 if (err) return console.error(err);9 console.log(data);10});11wpt.getTestResults('150203_4F_1', function(err, data) {12 if (err) return console.error(err);13 console.log(data);14});15}, function(err, data) {16 if (err) return console.error(err);17 console.log(data);18});19}, function(err, data) {20 if (err) return console.error(err);21 console.log(data);22});23}, function(err, data) {24 if (err) return console.error(err);25 console.log(data);26});
Using AI Code Generation
1var wptools = require('wptools');2var wp = wptools.page('Barack Obama');3wp.get_neg(function(err, res) {4 console.log(res);5});6var wptools = require('wptools');7var wp = wptools.page('Barack Obama');8wp.get_infobox(function(err, res) {9 console.log(res);10});11var wptools = require('wptools');12var wp = wptools.page('Barack Obama');13wp.get_imageinfo(function(err, res) {14 console.log(res);15});16var wptools = require('wptools');17var wp = wptools.page('Barack Obama');18wp.get_imageinfo(function(err, res) {19 console.log(res);20});21var wptools = require('wptools');22var wp = wptools.page('Barack Obama');23wp.get_imageinfo(function(err, res) {24 console.log(res);25});26var wptools = require('wptools');27var wp = wptools.page('Barack Obama');28wp.get_imageinfo(function(err, res) {29 console.log(res);30});31var wptools = require('wptools');32var wp = wptools.page('Barack Obama');33wp.get_imageinfo(function(err, res) {34 console.log(res);35});36var wptools = require('wptools');37var wp = wptools.page('Barack Obama');38wp.get_imageinfo(function(err, res) {39 console.log(res);40});41var wptools = require('wptools');42var wp = wptools.page('Barack Obama');43wp.get_imageinfo(function(err, res) {44 console.log(res);45});
Using AI Code Generation
1var wpt = require('wpt');2wpt.neg(2,3, function(err, data) {3console.log(data);4});5var wpt = require('wpt');6wpt.neg(2,3, function(err, data) {7console.log(data);8});9var wpt = require('wpt');10wpt.neg(2,3, function(err, data) {11console.log(data);12});13var wpt = require('wpt');14wpt.neg(2,3, function(err, data) {15console.log(data);16});17var wpt = require('wpt');18wpt.neg(2,3, function(err, data) {19console.log(data);20});21var wpt = require('wpt');22wpt.neg(2,3, function(err, data) {23console.log(data);24});25var wpt = require('wpt');26wpt.neg(2,3, function(err, data) {27console.log(data);28});29var wpt = require('wpt');30wpt.neg(2,3, function(err, data) {31console.log(data);32});33var wpt = require('wpt');34wpt.neg(2,3, function(err, data) {35console.log(data);36});37var wpt = require('wpt');38wpt.neg(2,3, function(err, data) {39console.log(data);40});41var wpt = require('wpt');42wpt.neg(2,3, function(err, data) {43console.log(data);44});45var wpt = require('wpt');46wpt.neg(2,3, function(err, data) {47console.log(data);48});49var wpt = require('wpt');50wpt.neg(2,3, function(err, data) {51console.log(data);52});
Using AI Code Generation
1var wpt = require('wpt.js');2var neg = wpt.neg;3var n1 = neg(1);4var n2 = neg(-1);5console.log(n1);6console.log(n2);7var neg = function(n) {8 return -n;9};10module.exports.neg = neg;
Using AI Code Generation
1var wptools = require('wptools');2var wiki = wptools.page('India');3wiki.get(function(err, resp) {4 var wiki_data = resp.data;5 var wiki_image = wiki_data.image;6 var wiki_image_url = wiki_image.url;7 console.log(wiki_image_url);8});9var wptools = require('wptools');10var wiki = wptools.page('India');11wiki.get(function(err, resp) {12 var wiki_data = resp.data;13 var wiki_image = wiki_data.image;14 var wiki_image_url = wiki_image.url;15 console.log(wiki_image_url);16});17var wptools = require('wptools');18var wiki = wptools.page('India');19wiki.get(function(err, resp) {20 var wiki_data = resp.data;21 var wiki_image = wiki_data.image;22 var wiki_image_url = wiki_image.url;23 console.log(wiki_image_url);24});25var wptools = require('wptools');26var wiki = wptools.page('India');27wiki.get(function(err, resp) {28 var wiki_data = resp.data;29 var wiki_image = wiki_data.image;30 var wiki_image_url = wiki_image.url;31 console.log(wiki_image_url);32});33var wptools = require('wptools');34var wiki = wptools.page('India');35wiki.get(function(err, resp) {36 var wiki_data = resp.data;37 var wiki_image = wiki_data.image;38 var wiki_image_url = wiki_image.url;39 console.log(wiki_image_url);40});41var wptools = require('wptools');42var wiki = wptools.page('India');43wiki.get(function(err, resp) {44 var wiki_data = resp.data;45 var wiki_image = wiki_data.image;46 var wiki_image_url = wiki_image.url;47 console.log(wiki_image_url);48});
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!