Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Side by Side Diff: test/mjsunit/smi-ops.js

Issue 155281: X64: Fixed more bad smi operations. (Closed)
Patch Set: Different approach to unifying tests in count operations. Created 11 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test/mjsunit/date-parse.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2008 the V8 project authors. All rights reserved. 1 // Copyright 2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 return 1 + x; 49 return 1 + x;
50 } 50 }
51 51
52 function Add100Reversed(x) { 52 function Add100Reversed(x) {
53 return 100 + x; 53 return 100 + x;
54 } 54 }
55 55
56 56
57 assertEquals(1, Add1(0)); // fast case 57 assertEquals(1, Add1(0)); // fast case
58 assertEquals(1, Add1Reversed(0)); // fast case 58 assertEquals(1, Add1Reversed(0)); // fast case
59 assertEquals(SMI_MAX + ONE, Add1(SMI_MAX)); // overflow 59 assertEquals(SMI_MAX + ONE, Add1(SMI_MAX), "smimax + 1");
60 assertEquals(SMI_MAX + ONE, Add1Reversed(SMI_MAX)); // overflow 60 assertEquals(SMI_MAX + ONE, Add1Reversed(SMI_MAX), "1 + smimax");
61 assertEquals(42 + ONE, Add1(OBJ_42)); // non-smi 61 assertEquals(42 + ONE, Add1(OBJ_42)); // non-smi
62 assertEquals(42 + ONE, Add1Reversed(OBJ_42)); // non-smi 62 assertEquals(42 + ONE, Add1Reversed(OBJ_42)); // non-smi
63 63
64 assertEquals(100, Add100(0)); // fast case 64 assertEquals(100, Add100(0)); // fast case
65 assertEquals(100, Add100Reversed(0)); // fast case 65 assertEquals(100, Add100Reversed(0)); // fast case
66 assertEquals(SMI_MAX + ONE_HUNDRED, Add100(SMI_MAX)); // overflow 66 assertEquals(SMI_MAX + ONE_HUNDRED, Add100(SMI_MAX), "smimax + 100");
67 assertEquals(SMI_MAX + ONE_HUNDRED, Add100Reversed(SMI_MAX)); // overflow 67 assertEquals(SMI_MAX + ONE_HUNDRED, Add100Reversed(SMI_MAX), " 100 + smimax");
68 assertEquals(42 + ONE_HUNDRED, Add100(OBJ_42)); // non-smi 68 assertEquals(42 + ONE_HUNDRED, Add100(OBJ_42)); // non-smi
69 assertEquals(42 + ONE_HUNDRED, Add100Reversed(OBJ_42)); // non-smi 69 assertEquals(42 + ONE_HUNDRED, Add100Reversed(OBJ_42)); // non-smi
70 70
71 71
72 72
73 function Sub1(x) { 73 function Sub1(x) {
74 return x - 1; 74 return x - 1;
75 } 75 }
76 76
77 function Sub100(x) { 77 function Sub100(x) {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 assertEquals(0, Sar1Reversed(2)); 141 assertEquals(0, Sar1Reversed(2));
142 assertEquals(1610612736, Shr1(SMI_MIN)); 142 assertEquals(1610612736, Shr1(SMI_MIN));
143 assertEquals(-536870912, Sar1(SMI_MIN)); 143 assertEquals(-536870912, Sar1(SMI_MIN));
144 assertEquals(1, Shr1Reversed(SMI_MIN)); 144 assertEquals(1, Shr1Reversed(SMI_MIN));
145 assertEquals(1, Sar1Reversed(SMI_MIN)); 145 assertEquals(1, Sar1Reversed(SMI_MIN));
146 assertEquals(21, Shr1(OBJ_42)); 146 assertEquals(21, Shr1(OBJ_42));
147 assertEquals(21, Sar1(OBJ_42)); 147 assertEquals(21, Sar1(OBJ_42));
148 assertEquals(0, Shr1Reversed(OBJ_42)); 148 assertEquals(0, Shr1Reversed(OBJ_42));
149 assertEquals(0, Sar1Reversed(OBJ_42)); 149 assertEquals(0, Sar1Reversed(OBJ_42));
150 150
151 assertEquals(6, Shr100(100)); 151 assertEquals(6, Shr100(100), "100 >>> 100");
152 assertEquals(6, Sar100(100)); 152 assertEquals(6, Sar100(100), "100 >> 100");
153 assertEquals(12, Shr100Reversed(99)); 153 assertEquals(12, Shr100Reversed(99));
154 assertEquals(12, Sar100Reversed(99)); 154 assertEquals(12, Sar100Reversed(99));
155 assertEquals(201326592, Shr100(SMI_MIN)); 155 assertEquals(201326592, Shr100(SMI_MIN));
156 assertEquals(-67108864, Sar100(SMI_MIN)); 156 assertEquals(-67108864, Sar100(SMI_MIN));
157 assertEquals(100, Shr100Reversed(SMI_MIN)); 157 assertEquals(100, Shr100Reversed(SMI_MIN));
158 assertEquals(100, Sar100Reversed(SMI_MIN)); 158 assertEquals(100, Sar100Reversed(SMI_MIN));
159 assertEquals(2, Shr100(OBJ_42)); 159 assertEquals(2, Shr100(OBJ_42));
160 assertEquals(2, Sar100(OBJ_42)); 160 assertEquals(2, Sar100(OBJ_42));
161 assertEquals(0, Shr100Reversed(OBJ_42)); 161 assertEquals(0, Shr100Reversed(OBJ_42));
162 assertEquals(0, Sar100Reversed(OBJ_42)); 162 assertEquals(0, Sar100Reversed(OBJ_42));
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 assertEquals(78, Xor100Reversed(OBJ_42)); 194 assertEquals(78, Xor100Reversed(OBJ_42));
195 195
196 var x = 0x23; var y = 0x35; 196 var x = 0x23; var y = 0x35;
197 assertEquals(0x16, x ^ y); 197 assertEquals(0x16, x ^ y);
198 198
199 199
200 // Bitwise not. 200 // Bitwise not.
201 var v = 0; 201 var v = 0;
202 assertEquals(-1, ~v); 202 assertEquals(-1, ~v);
203 v = SMI_MIN; 203 v = SMI_MIN;
204 assertEquals(0x3fffffff, ~v); 204 assertEquals(0x3fffffff, ~v, "~smimin");
205 v = SMI_MAX; 205 v = SMI_MAX;
206 assertEquals(-0x40000000, ~v); 206 assertEquals(-0x40000000, ~v, "~smimax");
207 207
208 // Overflowing ++ and --. 208 // Overflowing ++ and --.
209 v = SMI_MAX; 209 v = SMI_MAX;
210 v++; 210 v++;
211 assertEquals(0x40000000, v); 211 assertEquals(0x40000000, v, "smimax++");
212 v = SMI_MIN; 212 v = SMI_MIN;
213 v--; 213 v--;
214 assertEquals(-0x40000001, v); 214 assertEquals(-0x40000001, v, "smimin--");
215 215
216 // Not actually Smi operations. 216 // Not actually Smi operations.
217 // Check that relations on unary ops work. 217 // Check that relations on unary ops work.
218 var v = -1.2; 218 var v = -1.2;
219 assertTrue(v == v); 219 assertTrue(v == v);
220 assertTrue(v === v); 220 assertTrue(v === v);
221 assertTrue(v <= v); 221 assertTrue(v <= v);
222 assertTrue(v >= v); 222 assertTrue(v >= v);
223 assertFalse(v < v); 223 assertFalse(v < v);
224 assertFalse(v > v); 224 assertFalse(v > v);
225 assertFalse(v != v); 225 assertFalse(v != v);
226 assertFalse(v !== v); 226 assertFalse(v !== v);
227 227
228 // Right hand side of unary minus is overwritable. 228 // Right hand side of unary minus is overwritable.
229 v = 1.5 229 v = 1.5
230 assertEquals(-2.25, -(v * v)); 230 assertEquals(-2.25, -(v * v));
231 231
232 // Smi input to bitop gives non-smi result where the rhs is a float that 232 // Smi input to bitop gives non-smi result where the rhs is a float that
233 // can be overwritten. 233 // can be overwritten.
234 var x1 = 0x10000000; 234 var x1 = 0x10000000;
235 var x2 = 0x40000002; 235 var x2 = 0x40000002;
236 var x3 = 0x40000000; 236 var x3 = 0x40000000;
237 assertEquals(0x40000000, x1 << (x2 - x3)); 237 assertEquals(0x40000000, x1 << (x2 - x3), "0x10000000<<1(1)");
238 238
239 // Smi input to bitop gives non-smi result where the rhs could be overwritten 239 // Smi input to bitop gives non-smi result where the rhs could be overwritten
240 // if it were a float, but it isn't. 240 // if it were a float, but it isn't.
241 x1 = 0x10000000 241 x1 = 0x10000000
242 x2 = 4 242 x2 = 4
243 x3 = 2 243 x3 = 2
244 assertEquals(0x40000000, x1 << (x2 - x3)); 244 assertEquals(0x40000000, x1 << (x2 - x3), "0x10000000<<2(2)");
245 245
246 246
247 // Test shift operators on non-smi inputs, giving smi and non-smi results. 247 // Test shift operators on non-smi inputs, giving smi and non-smi results.
248 function testShiftNonSmis() { 248 function testShiftNonSmis() {
249 var pos_non_smi = 2000000000; 249 var pos_non_smi = 2000000000;
250 var neg_non_smi = -pos_non_smi; 250 var neg_non_smi = -pos_non_smi;
251 var pos_smi = 1000000000; 251 var pos_smi = 1000000000;
252 var neg_smi = -pos_smi; 252 var neg_smi = -pos_smi;
253 253
254 // Begin block A 254 // Begin block A
255 assertEquals(pos_non_smi, (pos_non_smi) >> 0); 255 assertEquals(pos_non_smi, (pos_non_smi) >> 0);
256 assertEquals(pos_non_smi, (pos_non_smi) >>> 0); 256 assertEquals(pos_non_smi, (pos_non_smi) >>> 0);
257 assertEquals(pos_non_smi, (pos_non_smi) << 0); 257 assertEquals(pos_non_smi, (pos_non_smi) << 0);
258 assertEquals(neg_non_smi, (neg_non_smi) >> 0); 258 assertEquals(neg_non_smi, (neg_non_smi) >> 0);
259 assertEquals(neg_non_smi + 0x100000000, (neg_non_smi) >>> 0); 259 assertEquals(neg_non_smi + 0x100000000, (neg_non_smi) >>> 0);
260 assertEquals(neg_non_smi, (neg_non_smi) << 0); 260 assertEquals(neg_non_smi, (neg_non_smi) << 0);
261 assertEquals(pos_smi, (pos_smi) >> 0); 261 assertEquals(pos_smi, (pos_smi) >> 0, "possmi >> 0");
262 assertEquals(pos_smi, (pos_smi) >>> 0); 262 assertEquals(pos_smi, (pos_smi) >>> 0, "possmi >>>0");
263 assertEquals(pos_smi, (pos_smi) << 0); 263 assertEquals(pos_smi, (pos_smi) << 0, "possmi << 0");
264 assertEquals(neg_smi, (neg_smi) >> 0); 264 assertEquals(neg_smi, (neg_smi) >> 0, "negsmi >> 0");
265 assertEquals(neg_smi + 0x100000000, (neg_smi) >>> 0); 265 assertEquals(neg_smi + 0x100000000, (neg_smi) >>> 0, "negsmi >>> 0");
266 assertEquals(neg_smi, (neg_smi) << 0); 266 assertEquals(neg_smi, (neg_smi) << 0), "negsmi << 0";
267 267
268 assertEquals(pos_non_smi / 2, (pos_non_smi) >> 1); 268 assertEquals(pos_non_smi / 2, (pos_non_smi) >> 1);
269 assertEquals(pos_non_smi / 2, (pos_non_smi) >>> 1); 269 assertEquals(pos_non_smi / 2, (pos_non_smi) >>> 1);
270 assertEquals(-0x1194D800, (pos_non_smi) << 1); 270 assertEquals(-0x1194D800, (pos_non_smi) << 1);
271 assertEquals(pos_non_smi / 8, (pos_non_smi) >> 3); 271 assertEquals(pos_non_smi / 8, (pos_non_smi) >> 3);
272 assertEquals(pos_non_smi / 8, (pos_non_smi) >>> 3); 272 assertEquals(pos_non_smi / 8, (pos_non_smi) >>> 3);
273 assertEquals(-0x46536000, (pos_non_smi) << 3); 273 assertEquals(-0x46536000, (pos_non_smi) << 3);
274 assertEquals(0x73594000, (pos_non_smi) << 4); 274 assertEquals(0x73594000, (pos_non_smi) << 4);
275 assertEquals(pos_non_smi, (pos_non_smi + 0.5) >> 0); 275 assertEquals(pos_non_smi, (pos_non_smi + 0.5) >> 0);
276 assertEquals(pos_non_smi, (pos_non_smi + 0.5) >>> 0); 276 assertEquals(pos_non_smi, (pos_non_smi + 0.5) >>> 0);
277 assertEquals(pos_non_smi, (pos_non_smi + 0.5) << 0); 277 assertEquals(pos_non_smi, (pos_non_smi + 0.5) << 0);
278 assertEquals(pos_non_smi / 2, (pos_non_smi + 0.5) >> 1); 278 assertEquals(pos_non_smi / 2, (pos_non_smi + 0.5) >> 1);
279 assertEquals(pos_non_smi / 2, (pos_non_smi + 0.5) >>> 1); 279 assertEquals(pos_non_smi / 2, (pos_non_smi + 0.5) >>> 1);
280 assertEquals(-0x1194D800, (pos_non_smi + 0.5) << 1); 280 assertEquals(-0x1194D800, (pos_non_smi + 0.5) << 1);
281 assertEquals(pos_non_smi / 8, (pos_non_smi + 0.5) >> 3); 281 assertEquals(pos_non_smi / 8, (pos_non_smi + 0.5) >> 3);
282 assertEquals(pos_non_smi / 8, (pos_non_smi + 0.5) >>> 3); 282 assertEquals(pos_non_smi / 8, (pos_non_smi + 0.5) >>> 3);
283 assertEquals(-0x46536000, (pos_non_smi + 0.5) << 3); 283 assertEquals(-0x46536000, (pos_non_smi + 0.5) << 3);
284 assertEquals(0x73594000, (pos_non_smi + 0.5) << 4); 284 assertEquals(0x73594000, (pos_non_smi + 0.5) << 4);
285 285
286 assertEquals(neg_non_smi / 2, (neg_non_smi) >> 1); 286 assertEquals(neg_non_smi / 2, (neg_non_smi) >> 1, "negnonsmi >> 1");
287 assertEquals(neg_non_smi / 2 + 0x100000000 / 2, (neg_non_smi) >>> 1); 287
288 assertEquals(neg_non_smi / 2 + 0x100000000 / 2, (neg_non_smi) >>> 1,
289 "negnonsmi >>> 1");
288 assertEquals(0x1194D800, (neg_non_smi) << 1); 290 assertEquals(0x1194D800, (neg_non_smi) << 1);
289 assertEquals(neg_non_smi / 8, (neg_non_smi) >> 3); 291 assertEquals(neg_non_smi / 8, (neg_non_smi) >> 3);
290 assertEquals(neg_non_smi / 8 + 0x100000000 / 8, (neg_non_smi) >>> 3); 292 assertEquals(neg_non_smi / 8 + 0x100000000 / 8, (neg_non_smi) >>> 3);
291 assertEquals(0x46536000, (neg_non_smi) << 3); 293 assertEquals(0x46536000, (neg_non_smi) << 3);
292 assertEquals(-0x73594000, (neg_non_smi) << 4); 294 assertEquals(-0x73594000, (neg_non_smi) << 4);
293 assertEquals(neg_non_smi, (neg_non_smi - 0.5) >> 0); 295 assertEquals(neg_non_smi, (neg_non_smi - 0.5) >> 0);
294 assertEquals(neg_non_smi + 0x100000000, (neg_non_smi - 0.5) >>> 0); 296 assertEquals(neg_non_smi + 0x100000000, (neg_non_smi - 0.5) >>> 0,
297 "negnonsmi.5 >>> 0");
295 assertEquals(neg_non_smi, (neg_non_smi - 0.5) << 0); 298 assertEquals(neg_non_smi, (neg_non_smi - 0.5) << 0);
296 assertEquals(neg_non_smi / 2, (neg_non_smi - 0.5) >> 1); 299 assertEquals(neg_non_smi / 2, (neg_non_smi - 0.5) >> 1);
297 assertEquals(neg_non_smi / 2 + 0x100000000 / 2, (neg_non_smi - 0.5) >>> 1); 300 assertEquals(neg_non_smi / 2 + 0x100000000 / 2, (neg_non_smi - 0.5) >>> 1,
301 "negnonsmi.5 >>> 1");
298 assertEquals(0x1194D800, (neg_non_smi - 0.5) << 1); 302 assertEquals(0x1194D800, (neg_non_smi - 0.5) << 1);
299 assertEquals(neg_non_smi / 8, (neg_non_smi - 0.5) >> 3); 303 assertEquals(neg_non_smi / 8, (neg_non_smi - 0.5) >> 3);
300 assertEquals(neg_non_smi / 8 + 0x100000000 / 8, (neg_non_smi - 0.5) >>> 3); 304 assertEquals(neg_non_smi / 8 + 0x100000000 / 8, (neg_non_smi - 0.5) >>> 3);
301 assertEquals(0x46536000, (neg_non_smi - 0.5) << 3); 305 assertEquals(0x46536000, (neg_non_smi - 0.5) << 3);
302 assertEquals(-0x73594000, (neg_non_smi - 0.5) << 4); 306 assertEquals(-0x73594000, (neg_non_smi - 0.5) << 4);
303 307
304 assertEquals(pos_smi / 2, (pos_smi) >> 1); 308 assertEquals(pos_smi / 2, (pos_smi) >> 1);
305 assertEquals(pos_smi / 2, (pos_smi) >>> 1); 309 assertEquals(pos_smi / 2, (pos_smi) >>> 1);
306 assertEquals(pos_non_smi, (pos_smi) << 1); 310 assertEquals(pos_non_smi, (pos_smi) << 1);
307 assertEquals(pos_smi / 8, (pos_smi) >> 3); 311 assertEquals(pos_smi / 8, (pos_smi) >> 3);
308 assertEquals(pos_smi / 8, (pos_smi) >>> 3); 312 assertEquals(pos_smi / 8, (pos_smi) >>> 3);
309 assertEquals(-0x2329b000, (pos_smi) << 3); 313 assertEquals(-0x2329b000, (pos_smi) << 3);
310 assertEquals(0x73594000, (pos_smi) << 5); 314 assertEquals(0x73594000, (pos_smi) << 5);
311 assertEquals(pos_smi, (pos_smi + 0.5) >> 0); 315 assertEquals(pos_smi, (pos_smi + 0.5) >> 0, "possmi.5 >> 0");
312 assertEquals(pos_smi, (pos_smi + 0.5) >>> 0); 316 assertEquals(pos_smi, (pos_smi + 0.5) >>> 0, "possmi.5 >>> 0");
313 assertEquals(pos_smi, (pos_smi + 0.5) << 0); 317 assertEquals(pos_smi, (pos_smi + 0.5) << 0, "possmi.5 << 0");
314 assertEquals(pos_smi / 2, (pos_smi + 0.5) >> 1); 318 assertEquals(pos_smi / 2, (pos_smi + 0.5) >> 1);
315 assertEquals(pos_smi / 2, (pos_smi + 0.5) >>> 1); 319 assertEquals(pos_smi / 2, (pos_smi + 0.5) >>> 1);
316 assertEquals(pos_non_smi, (pos_smi + 0.5) << 1); 320 assertEquals(pos_non_smi, (pos_smi + 0.5) << 1);
317 assertEquals(pos_smi / 8, (pos_smi + 0.5) >> 3); 321 assertEquals(pos_smi / 8, (pos_smi + 0.5) >> 3);
318 assertEquals(pos_smi / 8, (pos_smi + 0.5) >>> 3); 322 assertEquals(pos_smi / 8, (pos_smi + 0.5) >>> 3);
319 assertEquals(-0x2329b000, (pos_smi + 0.5) << 3); 323 assertEquals(-0x2329b000, (pos_smi + 0.5) << 3);
320 assertEquals(0x73594000, (pos_smi + 0.5) << 5); 324 assertEquals(0x73594000, (pos_smi + 0.5) << 5);
321 325
322 assertEquals(neg_smi / 2, (neg_smi) >> 1); 326 assertEquals(neg_smi / 2, (neg_smi) >> 1);
323 assertEquals(neg_smi / 2 + 0x100000000 / 2, (neg_smi) >>> 1); 327 assertEquals(neg_smi / 2 + 0x100000000 / 2, (neg_smi) >>> 1);
324 assertEquals(neg_non_smi, (neg_smi) << 1); 328 assertEquals(neg_non_smi, (neg_smi) << 1);
325 assertEquals(neg_smi / 8, (neg_smi) >> 3); 329 assertEquals(neg_smi / 8, (neg_smi) >> 3);
326 assertEquals(neg_smi / 8 + 0x100000000 / 8, (neg_smi) >>> 3); 330 assertEquals(neg_smi / 8 + 0x100000000 / 8, (neg_smi) >>> 3);
327 assertEquals(0x46536000, (neg_smi) << 4); 331 assertEquals(0x46536000, (neg_smi) << 4);
328 assertEquals(-0x73594000, (neg_smi) << 5); 332 assertEquals(-0x73594000, (neg_smi) << 5);
329 assertEquals(neg_smi, (neg_smi - 0.5) >> 0); 333 assertEquals(neg_smi, (neg_smi - 0.5) >> 0, "negsmi.5 >> 0");
330 assertEquals(neg_smi + 0x100000000, (neg_smi - 0.5) >>> 0); 334 assertEquals(neg_smi + 0x100000000, (neg_smi - 0.5) >>> 0, "negsmi.5 >>> 0");
331 assertEquals(neg_smi, (neg_smi - 0.5) << 0); 335 assertEquals(neg_smi, (neg_smi - 0.5) << 0, "negsmi.5 << 0");
332 assertEquals(neg_smi / 2, (neg_smi - 0.5) >> 1); 336 assertEquals(neg_smi / 2, (neg_smi - 0.5) >> 1);
333 assertEquals(neg_smi / 2 + 0x100000000 / 2, (neg_smi - 0.5) >>> 1); 337 assertEquals(neg_smi / 2 + 0x100000000 / 2, (neg_smi - 0.5) >>> 1);
334 assertEquals(neg_non_smi, (neg_smi - 0.5) << 1); 338 assertEquals(neg_non_smi, (neg_smi - 0.5) << 1);
335 assertEquals(neg_smi / 8, (neg_smi - 0.5) >> 3); 339 assertEquals(neg_smi / 8, (neg_smi - 0.5) >> 3);
336 assertEquals(neg_smi / 8 + 0x100000000 / 8, (neg_smi - 0.5) >>> 3); 340 assertEquals(neg_smi / 8 + 0x100000000 / 8, (neg_smi - 0.5) >>> 3);
337 assertEquals(0x46536000, (neg_smi - 0.5) << 4); 341 assertEquals(0x46536000, (neg_smi - 0.5) << 4);
338 assertEquals(-0x73594000, (neg_smi - 0.5) << 5); 342 assertEquals(-0x73594000, (neg_smi - 0.5) << 5);
339 // End block A 343 // End block A
340 344
341 // Repeat block A with 2^32 added to positive numbers and 345 // Repeat block A with 2^32 added to positive numbers and
342 // 2^32 subtracted from negative numbers. 346 // 2^32 subtracted from negative numbers.
343 // Begin block A repeat 1 347 // Begin block A repeat 1
344 var two_32 = 0x100000000; 348 var two_32 = 0x100000000;
345 var neg_32 = -two_32; 349 var neg_32 = -two_32;
346 assertEquals(pos_non_smi, (two_32 + pos_non_smi) >> 0); 350 assertEquals(pos_non_smi, (two_32 + pos_non_smi) >> 0);
347 assertEquals(pos_non_smi, (two_32 + pos_non_smi) >>> 0); 351 assertEquals(pos_non_smi, (two_32 + pos_non_smi) >>> 0);
348 assertEquals(pos_non_smi, (two_32 + pos_non_smi) << 0); 352 assertEquals(pos_non_smi, (two_32 + pos_non_smi) << 0);
349 assertEquals(neg_non_smi, (neg_32 + neg_non_smi) >> 0); 353 assertEquals(neg_non_smi, (neg_32 + neg_non_smi) >> 0);
350 assertEquals(neg_non_smi + 0x100000000, (neg_32 + neg_non_smi) >>> 0); 354 assertEquals(neg_non_smi + 0x100000000, (neg_32 + neg_non_smi) >>> 0);
351 assertEquals(neg_non_smi, (neg_32 + neg_non_smi) << 0); 355 assertEquals(neg_non_smi, (neg_32 + neg_non_smi) << 0);
352 assertEquals(pos_smi, (two_32 + pos_smi) >> 0); 356 assertEquals(pos_smi, (two_32 + pos_smi) >> 0, "2^32+possmi >> 0");
353 assertEquals(pos_smi, (two_32 + pos_smi) >>> 0); 357 assertEquals(pos_smi, (two_32 + pos_smi) >>> 0, "2^32+possmi >>> 0");
354 assertEquals(pos_smi, (two_32 + pos_smi) << 0); 358 assertEquals(pos_smi, (two_32 + pos_smi) << 0, "2^32+possmi << 0");
355 assertEquals(neg_smi, (neg_32 + neg_smi) >> 0); 359 assertEquals(neg_smi, (neg_32 + neg_smi) >> 0, "2^32+negsmi >> 0");
356 assertEquals(neg_smi + 0x100000000, (neg_32 + neg_smi) >>> 0); 360 assertEquals(neg_smi + 0x100000000, (neg_32 + neg_smi) >>> 0);
357 assertEquals(neg_smi, (neg_32 + neg_smi) << 0); 361 assertEquals(neg_smi, (neg_32 + neg_smi) << 0, "2^32+negsmi << 0");
358 362
359 assertEquals(pos_non_smi / 2, (two_32 + pos_non_smi) >> 1); 363 assertEquals(pos_non_smi / 2, (two_32 + pos_non_smi) >> 1);
360 assertEquals(pos_non_smi / 2, (two_32 + pos_non_smi) >>> 1); 364 assertEquals(pos_non_smi / 2, (two_32 + pos_non_smi) >>> 1);
361 assertEquals(-0x1194D800, (two_32 + pos_non_smi) << 1); 365 assertEquals(-0x1194D800, (two_32 + pos_non_smi) << 1);
362 assertEquals(pos_non_smi / 8, (two_32 + pos_non_smi) >> 3); 366 assertEquals(pos_non_smi / 8, (two_32 + pos_non_smi) >> 3);
363 assertEquals(pos_non_smi / 8, (two_32 + pos_non_smi) >>> 3); 367 assertEquals(pos_non_smi / 8, (two_32 + pos_non_smi) >>> 3);
364 assertEquals(-0x46536000, (two_32 + pos_non_smi) << 3); 368 assertEquals(-0x46536000, (two_32 + pos_non_smi) << 3);
365 assertEquals(0x73594000, (two_32 + pos_non_smi) << 4); 369 assertEquals(0x73594000, (two_32 + pos_non_smi) << 4);
366 assertEquals(pos_non_smi, (two_32 + pos_non_smi + 0.5) >> 0); 370 assertEquals(pos_non_smi, (two_32 + pos_non_smi + 0.5) >> 0);
367 assertEquals(pos_non_smi, (two_32 + pos_non_smi + 0.5) >>> 0); 371 assertEquals(pos_non_smi, (two_32 + pos_non_smi + 0.5) >>> 0);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 assertEquals(-0x2329b000, (two_32 + pos_smi + 0.5) << 3); 416 assertEquals(-0x2329b000, (two_32 + pos_smi + 0.5) << 3);
413 assertEquals(0x73594000, (two_32 + pos_smi + 0.5) << 5); 417 assertEquals(0x73594000, (two_32 + pos_smi + 0.5) << 5);
414 418
415 assertEquals(neg_smi / 2, (neg_32 + neg_smi) >> 1); 419 assertEquals(neg_smi / 2, (neg_32 + neg_smi) >> 1);
416 assertEquals(neg_smi / 2 + 0x100000000 / 2, (neg_32 + neg_smi) >>> 1); 420 assertEquals(neg_smi / 2 + 0x100000000 / 2, (neg_32 + neg_smi) >>> 1);
417 assertEquals(neg_non_smi, (neg_32 + neg_smi) << 1); 421 assertEquals(neg_non_smi, (neg_32 + neg_smi) << 1);
418 assertEquals(neg_smi / 8, (neg_32 + neg_smi) >> 3); 422 assertEquals(neg_smi / 8, (neg_32 + neg_smi) >> 3);
419 assertEquals((neg_smi + 0x100000000) / 8, (neg_32 + neg_smi) >>> 3); 423 assertEquals((neg_smi + 0x100000000) / 8, (neg_32 + neg_smi) >>> 3);
420 assertEquals(0x46536000, (neg_32 + neg_smi) << 4); 424 assertEquals(0x46536000, (neg_32 + neg_smi) << 4);
421 assertEquals(-0x73594000, (neg_32 + neg_smi) << 5); 425 assertEquals(-0x73594000, (neg_32 + neg_smi) << 5);
422 assertEquals(neg_smi, (neg_32 + neg_smi - 0.5) >> 0); 426 assertEquals(neg_smi, (neg_32 + neg_smi - 0.5) >> 0, "-2^32+negsmi.5 >> 0");
423 assertEquals(neg_smi + 0x100000000, (neg_32 + neg_smi - 0.5) >>> 0); 427 assertEquals(neg_smi + 0x100000000, (neg_32 + neg_smi - 0.5) >>> 0);
424 assertEquals(neg_smi, (neg_32 + neg_smi - 0.5) << 0); 428 assertEquals(neg_smi, (neg_32 + neg_smi - 0.5) << 0, "-2^32+negsmi.5 << 0");
425 assertEquals(neg_smi / 2, (neg_32 + neg_smi - 0.5) >> 1); 429 assertEquals(neg_smi / 2, (neg_32 + neg_smi - 0.5) >> 1);
426 assertEquals(neg_smi / 2 + 0x100000000 / 2, (neg_32 + neg_smi - 0.5) >>> 1); 430 assertEquals(neg_smi / 2 + 0x100000000 / 2, (neg_32 + neg_smi - 0.5) >>> 1);
427 assertEquals(neg_non_smi, (neg_32 + neg_smi - 0.5) << 1); 431 assertEquals(neg_non_smi, (neg_32 + neg_smi - 0.5) << 1);
428 assertEquals(neg_smi / 8, (neg_32 + neg_smi - 0.5) >> 3); 432 assertEquals(neg_smi / 8, (neg_32 + neg_smi - 0.5) >> 3);
429 assertEquals(neg_smi / 8 + 0x100000000 / 8, (neg_32 + neg_smi - 0.5) >>> 3); 433 assertEquals(neg_smi / 8 + 0x100000000 / 8, (neg_32 + neg_smi - 0.5) >>> 3);
430 assertEquals(0x46536000, (neg_32 + neg_smi - 0.5) << 4); 434 assertEquals(0x46536000, (neg_32 + neg_smi - 0.5) << 4);
431 assertEquals(-0x73594000, (neg_32 + neg_smi - 0.5) << 5); 435 assertEquals(-0x73594000, (neg_32 + neg_smi - 0.5) << 5);
432 // End block A repeat 1 436 // End block A repeat 1
433 // Repeat block A with shift amounts in variables intialized with 437 // Repeat block A with shift amounts in variables intialized with
434 // a constant. 438 // a constant.
435 var zero = 0; 439 var zero = 0;
436 var one = 1; 440 var one = 1;
437 var three = 3; 441 var three = 3;
438 var four = 4; 442 var four = 4;
439 var five = 5; 443 var five = 5;
440 // Begin block A repeat 2 444 // Begin block A repeat 2
441 assertEquals(pos_non_smi, (pos_non_smi) >> zero); 445 assertEquals(pos_non_smi, (pos_non_smi) >> zero);
442 assertEquals(pos_non_smi, (pos_non_smi) >>> zero); 446 assertEquals(pos_non_smi, (pos_non_smi) >>> zero);
443 assertEquals(pos_non_smi, (pos_non_smi) << zero); 447 assertEquals(pos_non_smi, (pos_non_smi) << zero);
444 assertEquals(neg_non_smi, (neg_non_smi) >> zero); 448 assertEquals(neg_non_smi, (neg_non_smi) >> zero);
445 assertEquals(neg_non_smi + 0x100000000, (neg_non_smi) >>> zero); 449 assertEquals(neg_non_smi + 0x100000000, (neg_non_smi) >>> zero);
446 assertEquals(neg_non_smi, (neg_non_smi) << zero); 450 assertEquals(neg_non_smi, (neg_non_smi) << zero);
447 assertEquals(pos_smi, (pos_smi) >> zero); 451 assertEquals(pos_smi, (pos_smi) >> zero);
448 assertEquals(pos_smi, (pos_smi) >>> zero); 452 assertEquals(pos_smi, (pos_smi) >>> zero);
449 assertEquals(pos_smi, (pos_smi) << zero); 453 assertEquals(pos_smi, (pos_smi) << zero);
450 assertEquals(neg_smi, (neg_smi) >> zero); 454 assertEquals(neg_smi, (neg_smi) >> zero, "negsmi >> zero");
451 assertEquals(neg_smi + 0x100000000, (neg_smi) >>> zero); 455 assertEquals(neg_smi + 0x100000000, (neg_smi) >>> zero);
452 assertEquals(neg_smi, (neg_smi) << zero); 456 assertEquals(neg_smi, (neg_smi) << zero, "negsmi << zero");
453 457
454 assertEquals(pos_non_smi / 2, (pos_non_smi) >> one); 458 assertEquals(pos_non_smi / 2, (pos_non_smi) >> one);
455 assertEquals(pos_non_smi / 2, (pos_non_smi) >>> one); 459 assertEquals(pos_non_smi / 2, (pos_non_smi) >>> one);
456 assertEquals(-0x1194D800, (pos_non_smi) << one); 460 assertEquals(-0x1194D800, (pos_non_smi) << one);
457 assertEquals(pos_non_smi / 8, (pos_non_smi) >> three); 461 assertEquals(pos_non_smi / 8, (pos_non_smi) >> three);
458 assertEquals(pos_non_smi / 8, (pos_non_smi) >>> three); 462 assertEquals(pos_non_smi / 8, (pos_non_smi) >>> three);
459 assertEquals(-0x46536000, (pos_non_smi) << three); 463 assertEquals(-0x46536000, (pos_non_smi) << three);
460 assertEquals(0x73594000, (pos_non_smi) << four); 464 assertEquals(0x73594000, (pos_non_smi) << four);
461 assertEquals(pos_non_smi, (pos_non_smi + 0.5) >> zero); 465 assertEquals(pos_non_smi, (pos_non_smi + 0.5) >> zero);
462 assertEquals(pos_non_smi, (pos_non_smi + 0.5) >>> zero); 466 assertEquals(pos_non_smi, (pos_non_smi + 0.5) >>> zero);
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 // Begin block A repeat 3 540 // Begin block A repeat 3
537 assertEquals(pos_non_smi, (pos_non_smi) >> zero); 541 assertEquals(pos_non_smi, (pos_non_smi) >> zero);
538 assertEquals(pos_non_smi, (pos_non_smi) >>> zero); 542 assertEquals(pos_non_smi, (pos_non_smi) >>> zero);
539 assertEquals(pos_non_smi, (pos_non_smi) << zero); 543 assertEquals(pos_non_smi, (pos_non_smi) << zero);
540 assertEquals(neg_non_smi, (neg_non_smi) >> zero); 544 assertEquals(neg_non_smi, (neg_non_smi) >> zero);
541 assertEquals(neg_non_smi + 0x100000000, (neg_non_smi) >>> zero); 545 assertEquals(neg_non_smi + 0x100000000, (neg_non_smi) >>> zero);
542 assertEquals(neg_non_smi, (neg_non_smi) << zero); 546 assertEquals(neg_non_smi, (neg_non_smi) << zero);
543 assertEquals(pos_smi, (pos_smi) >> zero); 547 assertEquals(pos_smi, (pos_smi) >> zero);
544 assertEquals(pos_smi, (pos_smi) >>> zero); 548 assertEquals(pos_smi, (pos_smi) >>> zero);
545 assertEquals(pos_smi, (pos_smi) << zero); 549 assertEquals(pos_smi, (pos_smi) << zero);
546 assertEquals(neg_smi, (neg_smi) >> zero); 550 assertEquals(neg_smi, (neg_smi) >> zero, "negsmi >> zero(2)");
547 assertEquals(neg_smi + 0x100000000, (neg_smi) >>> zero); 551 assertEquals(neg_smi + 0x100000000, (neg_smi) >>> zero);
548 assertEquals(neg_smi, (neg_smi) << zero); 552 assertEquals(neg_smi, (neg_smi) << zero, "negsmi << zero(2)");
549 553
550 assertEquals(pos_non_smi / 2, (pos_non_smi) >> one); 554 assertEquals(pos_non_smi / 2, (pos_non_smi) >> one);
551 assertEquals(pos_non_smi / 2, (pos_non_smi) >>> one); 555 assertEquals(pos_non_smi / 2, (pos_non_smi) >>> one);
552 assertEquals(-0x1194D800, (pos_non_smi) << one); 556 assertEquals(-0x1194D800, (pos_non_smi) << one);
553 assertEquals(pos_non_smi / 8, (pos_non_smi) >> three); 557 assertEquals(pos_non_smi / 8, (pos_non_smi) >> three);
554 assertEquals(pos_non_smi / 8, (pos_non_smi) >>> three); 558 assertEquals(pos_non_smi / 8, (pos_non_smi) >>> three);
555 assertEquals(-0x46536000, (pos_non_smi) << three); 559 assertEquals(-0x46536000, (pos_non_smi) << three);
556 assertEquals(0x73594000, (pos_non_smi) << four); 560 assertEquals(0x73594000, (pos_non_smi) << four);
557 assertEquals(pos_non_smi, (pos_non_smi + 0.5) >> zero); 561 assertEquals(pos_non_smi, (pos_non_smi + 0.5) >> zero);
558 assertEquals(pos_non_smi, (pos_non_smi + 0.5) >>> zero); 562 assertEquals(pos_non_smi, (pos_non_smi + 0.5) >>> zero);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
602 assertEquals(-0x2329b000, (pos_smi + 0.5) << three); 606 assertEquals(-0x2329b000, (pos_smi + 0.5) << three);
603 assertEquals(0x73594000, (pos_smi + 0.5) << five); 607 assertEquals(0x73594000, (pos_smi + 0.5) << five);
604 608
605 assertEquals(neg_smi / 2, (neg_smi) >> one); 609 assertEquals(neg_smi / 2, (neg_smi) >> one);
606 assertEquals(neg_smi / 2 + 0x100000000 / 2, (neg_smi) >>> one); 610 assertEquals(neg_smi / 2 + 0x100000000 / 2, (neg_smi) >>> one);
607 assertEquals(neg_non_smi, (neg_smi) << one); 611 assertEquals(neg_non_smi, (neg_smi) << one);
608 assertEquals(neg_smi / 8, (neg_smi) >> three); 612 assertEquals(neg_smi / 8, (neg_smi) >> three);
609 assertEquals(neg_smi / 8 + 0x100000000 / 8, (neg_smi) >>> three); 613 assertEquals(neg_smi / 8 + 0x100000000 / 8, (neg_smi) >>> three);
610 assertEquals(0x46536000, (neg_smi) << four); 614 assertEquals(0x46536000, (neg_smi) << four);
611 assertEquals(-0x73594000, (neg_smi) << five); 615 assertEquals(-0x73594000, (neg_smi) << five);
612 assertEquals(neg_smi, (neg_smi - 0.5) >> zero); 616 assertEquals(neg_smi, (neg_smi - 0.5) >> zero, "negsmi.5 >> zero");
613 assertEquals(neg_smi + 0x100000000, (neg_smi - 0.5) >>> zero); 617 assertEquals(neg_smi + 0x100000000, (neg_smi - 0.5) >>> zero);
614 assertEquals(neg_smi, (neg_smi - 0.5) << zero); 618 assertEquals(neg_smi, (neg_smi - 0.5) << zero, "negsmi.5 << zero");
615 assertEquals(neg_smi / 2, (neg_smi - 0.5) >> one); 619 assertEquals(neg_smi / 2, (neg_smi - 0.5) >> one);
616 assertEquals(neg_smi / 2 + 0x100000000 / 2, (neg_smi - 0.5) >>> one); 620 assertEquals(neg_smi / 2 + 0x100000000 / 2, (neg_smi - 0.5) >>> one);
617 assertEquals(neg_non_smi, (neg_smi - 0.5) << one); 621 assertEquals(neg_non_smi, (neg_smi - 0.5) << one);
618 assertEquals(neg_smi / 8, (neg_smi - 0.5) >> three); 622 assertEquals(neg_smi / 8, (neg_smi - 0.5) >> three);
619 assertEquals(neg_smi / 8 + 0x100000000 / 8, (neg_smi - 0.5) >>> three); 623 assertEquals(neg_smi / 8 + 0x100000000 / 8, (neg_smi - 0.5) >>> three);
620 assertEquals(0x46536000, (neg_smi - 0.5) << four); 624 assertEquals(0x46536000, (neg_smi - 0.5) << four);
621 assertEquals(-0x73594000, (neg_smi - 0.5) << five); 625 assertEquals(-0x73594000, (neg_smi - 0.5) << five);
622 // End block A repeat 3 626 // End block A repeat 3
623 627
624 // Test non-integer shift value 628 // Test non-integer shift value
625 assertEquals(5, 20.5 >> 2.4); 629 assertEquals(5, 20.5 >> 2.4);
626 assertEquals(5, 20.5 >> 2.7); 630 assertEquals(5, 20.5 >> 2.7);
627 var shift = 2.4; 631 var shift = 2.4;
628 assertEquals(5, 20.5 >> shift); 632 assertEquals(5, 20.5 >> shift);
629 assertEquals(5, 20.5 >> shift + 0.3); 633 assertEquals(5, 20.5 >> shift + 0.3);
630 shift = shift + zero; 634 shift = shift + zero;
631 assertEquals(5, 20.5 >> shift); 635 assertEquals(5, 20.5 >> shift);
632 assertEquals(5, 20.5 >> shift + 0.3); 636 assertEquals(5, 20.5 >> shift + 0.3);
633 } 637 }
634 638
635 testShiftNonSmis(); 639 testShiftNonSmis();
636 640
637 641
638 // Verify that we handle the (optimized) corner case of shifting by 642 // Verify that we handle the (optimized) corner case of shifting by
639 // zero even for non-smis. 643 // zero even for non-smis.
640 function shiftByZero(n) { return n << 0; } 644 function shiftByZero(n) { return n << 0; }
641 645
642 assertEquals(3, shiftByZero(3.1415)); 646 assertEquals(3, shiftByZero(3.1415));
OLDNEW
« no previous file with comments | « test/mjsunit/date-parse.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698