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

Side by Side Diff: test/cctest/test-macro-assembler-x64.cc

Issue 6682026: Fix SmiCompare on 64 bit to distinguish between comparisons where... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 9 years, 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2009 the V8 project authors. All rights reserved. 1 // Copyright 2009 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 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 __ SmiCompare(rdx, rcx); 213 __ SmiCompare(rdx, rcx);
214 if (y < x) { 214 if (y < x) {
215 __ movl(rax, Immediate(id + 9)); 215 __ movl(rax, Immediate(id + 9));
216 __ j(greater_equal, exit); 216 __ j(greater_equal, exit);
217 } else { 217 } else {
218 ASSERT(y > x); 218 ASSERT(y > x);
219 __ movl(rax, Immediate(id + 10)); 219 __ movl(rax, Immediate(id + 10));
220 __ j(less_equal, exit); 220 __ j(less_equal, exit);
221 } 221 }
222 } else { 222 } else {
223 __ SmiCompare(rcx, rcx); 223 __ cmpq(rcx, rcx);
Lasse Reichstein 2011/03/15 09:07:01 Really should be SmiCompare in this function.
Erik Corry 2011/03/15 10:00:50 Since we are only testing for equality cmpq seems
Lasse Reichstein 2011/03/15 12:29:23 But we are testing SmiCompare :)
224 __ movl(rax, Immediate(id + 11)); 224 __ movl(rax, Immediate(id + 11));
225 __ j(not_equal, exit); 225 __ j(not_equal, exit);
226 __ incq(rax); 226 __ incq(rax);
227 __ cmpq(rcx, r8); 227 __ cmpq(rcx, r8);
228 __ j(not_equal, exit); 228 __ j(not_equal, exit);
229 } 229 }
230 } 230 }
231 231
232 232
233 // Test that we can compare smis for equality (and more). 233 // Test that we can compare smis for equality (and more).
234 TEST(SmiCompare) { 234 TEST(SmiCompare) {
235 v8::V8::Initialize();
235 // Allocate an executable page of memory. 236 // Allocate an executable page of memory.
236 size_t actual_size; 237 size_t actual_size;
237 byte* buffer = 238 byte* buffer =
238 static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, 239 static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize * 2,
239 &actual_size, 240 &actual_size,
240 true)); 241 true));
241 CHECK(buffer); 242 CHECK(buffer);
242 HandleScope handles; 243 HandleScope handles;
243 MacroAssembler assembler(buffer, static_cast<int>(actual_size)); 244 MacroAssembler assembler(buffer, static_cast<int>(actual_size));
244 245
245 MacroAssembler* masm = &assembler; 246 MacroAssembler* masm = &assembler;
246 masm->set_allow_stub_calls(false); 247 masm->set_allow_stub_calls(false);
247 EntryCode(masm); 248 EntryCode(masm);
248 Label exit; 249 Label exit;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 294
294 MacroAssembler* masm = &assembler; 295 MacroAssembler* masm = &assembler;
295 masm->set_allow_stub_calls(false); 296 masm->set_allow_stub_calls(false);
296 EntryCode(masm); 297 EntryCode(masm);
297 Label exit; 298 Label exit;
298 299
299 __ movq(rax, Immediate(1)); // Test number. 300 __ movq(rax, Immediate(1)); // Test number.
300 __ movl(rcx, Immediate(0)); 301 __ movl(rcx, Immediate(0));
301 __ Integer32ToSmi(rcx, rcx); 302 __ Integer32ToSmi(rcx, rcx);
302 __ Set(rdx, reinterpret_cast<intptr_t>(Smi::FromInt(0))); 303 __ Set(rdx, reinterpret_cast<intptr_t>(Smi::FromInt(0)));
303 __ SmiCompare(rcx, rdx); 304 __ cmpq(rcx, rdx);
304 __ j(not_equal, &exit); 305 __ j(not_equal, &exit);
305 306
306 __ movq(rax, Immediate(2)); // Test number. 307 __ movq(rax, Immediate(2)); // Test number.
307 __ movl(rcx, Immediate(1024)); 308 __ movl(rcx, Immediate(1024));
308 __ Integer32ToSmi(rcx, rcx); 309 __ Integer32ToSmi(rcx, rcx);
309 __ Set(rdx, reinterpret_cast<intptr_t>(Smi::FromInt(1024))); 310 __ Set(rdx, reinterpret_cast<intptr_t>(Smi::FromInt(1024)));
310 __ SmiCompare(rcx, rdx); 311 __ cmpq(rcx, rdx);
311 __ j(not_equal, &exit); 312 __ j(not_equal, &exit);
312 313
313 __ movq(rax, Immediate(3)); // Test number. 314 __ movq(rax, Immediate(3)); // Test number.
314 __ movl(rcx, Immediate(-1)); 315 __ movl(rcx, Immediate(-1));
315 __ Integer32ToSmi(rcx, rcx); 316 __ Integer32ToSmi(rcx, rcx);
316 __ Set(rdx, reinterpret_cast<intptr_t>(Smi::FromInt(-1))); 317 __ Set(rdx, reinterpret_cast<intptr_t>(Smi::FromInt(-1)));
317 __ SmiCompare(rcx, rdx); 318 __ cmpq(rcx, rdx);
318 __ j(not_equal, &exit); 319 __ j(not_equal, &exit);
319 320
320 __ movq(rax, Immediate(4)); // Test number. 321 __ movq(rax, Immediate(4)); // Test number.
321 __ movl(rcx, Immediate(Smi::kMaxValue)); 322 __ movl(rcx, Immediate(Smi::kMaxValue));
322 __ Integer32ToSmi(rcx, rcx); 323 __ Integer32ToSmi(rcx, rcx);
323 __ Set(rdx, reinterpret_cast<intptr_t>(Smi::FromInt(Smi::kMaxValue))); 324 __ Set(rdx, reinterpret_cast<intptr_t>(Smi::FromInt(Smi::kMaxValue)));
324 __ SmiCompare(rcx, rdx); 325 __ cmpq(rcx, rdx);
325 __ j(not_equal, &exit); 326 __ j(not_equal, &exit);
326 327
327 __ movq(rax, Immediate(5)); // Test number. 328 __ movq(rax, Immediate(5)); // Test number.
328 __ movl(rcx, Immediate(Smi::kMinValue)); 329 __ movl(rcx, Immediate(Smi::kMinValue));
329 __ Integer32ToSmi(rcx, rcx); 330 __ Integer32ToSmi(rcx, rcx);
330 __ Set(rdx, reinterpret_cast<intptr_t>(Smi::FromInt(Smi::kMinValue))); 331 __ Set(rdx, reinterpret_cast<intptr_t>(Smi::FromInt(Smi::kMinValue)));
331 __ SmiCompare(rcx, rdx); 332 __ cmpq(rcx, rdx);
332 __ j(not_equal, &exit); 333 __ j(not_equal, &exit);
333 334
334 // Different target register. 335 // Different target register.
335 336
336 __ movq(rax, Immediate(6)); // Test number. 337 __ movq(rax, Immediate(6)); // Test number.
337 __ movl(rcx, Immediate(0)); 338 __ movl(rcx, Immediate(0));
338 __ Integer32ToSmi(r8, rcx); 339 __ Integer32ToSmi(r8, rcx);
339 __ Set(rdx, reinterpret_cast<intptr_t>(Smi::FromInt(0))); 340 __ Set(rdx, reinterpret_cast<intptr_t>(Smi::FromInt(0)));
340 __ SmiCompare(r8, rdx); 341 __ cmpq(r8, rdx);
341 __ j(not_equal, &exit); 342 __ j(not_equal, &exit);
342 343
343 __ movq(rax, Immediate(7)); // Test number. 344 __ movq(rax, Immediate(7)); // Test number.
344 __ movl(rcx, Immediate(1024)); 345 __ movl(rcx, Immediate(1024));
345 __ Integer32ToSmi(r8, rcx); 346 __ Integer32ToSmi(r8, rcx);
346 __ Set(rdx, reinterpret_cast<intptr_t>(Smi::FromInt(1024))); 347 __ Set(rdx, reinterpret_cast<intptr_t>(Smi::FromInt(1024)));
347 __ SmiCompare(r8, rdx); 348 __ cmpq(r8, rdx);
348 __ j(not_equal, &exit); 349 __ j(not_equal, &exit);
349 350
350 __ movq(rax, Immediate(8)); // Test number. 351 __ movq(rax, Immediate(8)); // Test number.
351 __ movl(rcx, Immediate(-1)); 352 __ movl(rcx, Immediate(-1));
352 __ Integer32ToSmi(r8, rcx); 353 __ Integer32ToSmi(r8, rcx);
353 __ Set(rdx, reinterpret_cast<intptr_t>(Smi::FromInt(-1))); 354 __ Set(rdx, reinterpret_cast<intptr_t>(Smi::FromInt(-1)));
354 __ SmiCompare(r8, rdx); 355 __ cmpq(r8, rdx);
355 __ j(not_equal, &exit); 356 __ j(not_equal, &exit);
356 357
357 __ movq(rax, Immediate(9)); // Test number. 358 __ movq(rax, Immediate(9)); // Test number.
358 __ movl(rcx, Immediate(Smi::kMaxValue)); 359 __ movl(rcx, Immediate(Smi::kMaxValue));
359 __ Integer32ToSmi(r8, rcx); 360 __ Integer32ToSmi(r8, rcx);
360 __ Set(rdx, reinterpret_cast<intptr_t>(Smi::FromInt(Smi::kMaxValue))); 361 __ Set(rdx, reinterpret_cast<intptr_t>(Smi::FromInt(Smi::kMaxValue)));
361 __ SmiCompare(r8, rdx); 362 __ cmpq(r8, rdx);
362 __ j(not_equal, &exit); 363 __ j(not_equal, &exit);
363 364
364 __ movq(rax, Immediate(10)); // Test number. 365 __ movq(rax, Immediate(10)); // Test number.
365 __ movl(rcx, Immediate(Smi::kMinValue)); 366 __ movl(rcx, Immediate(Smi::kMinValue));
366 __ Integer32ToSmi(r8, rcx); 367 __ Integer32ToSmi(r8, rcx);
367 __ Set(rdx, reinterpret_cast<intptr_t>(Smi::FromInt(Smi::kMinValue))); 368 __ Set(rdx, reinterpret_cast<intptr_t>(Smi::FromInt(Smi::kMinValue)));
368 __ SmiCompare(r8, rdx); 369 __ cmpq(r8, rdx);
369 __ j(not_equal, &exit); 370 __ j(not_equal, &exit);
370 371
371 372
372 __ xor_(rax, rax); // Success. 373 __ xor_(rax, rax); // Success.
373 __ bind(&exit); 374 __ bind(&exit);
374 ExitCode(masm); 375 ExitCode(masm);
375 __ ret(0); 376 __ ret(0);
376 377
377 CodeDesc desc; 378 CodeDesc desc;
378 masm->GetCode(&desc); 379 masm->GetCode(&desc);
379 // Call the function from C++. 380 // Call the function from C++.
380 int result = FUNCTION_CAST<F0>(buffer)(); 381 int result = FUNCTION_CAST<F0>(buffer)();
381 CHECK_EQ(0, result); 382 CHECK_EQ(0, result);
382 } 383 }
383 384
384 385
385 void TestI64PlusConstantToSmi(MacroAssembler* masm, 386 void TestI64PlusConstantToSmi(MacroAssembler* masm,
386 Label* exit, 387 Label* exit,
387 int id, 388 int id,
388 int64_t x, 389 int64_t x,
389 int y) { 390 int y) {
390 int64_t result = x + y; 391 int64_t result = x + y;
391 ASSERT(Smi::IsValid(result)); 392 ASSERT(Smi::IsValid(result));
392 __ movl(rax, Immediate(id)); 393 __ movl(rax, Immediate(id));
393 __ Move(r8, Smi::FromInt(static_cast<int>(result))); 394 __ Move(r8, Smi::FromInt(static_cast<int>(result)));
394 __ movq(rcx, x, RelocInfo::NONE); 395 __ movq(rcx, x, RelocInfo::NONE);
395 __ movq(r11, rcx); 396 __ movq(r11, rcx);
396 __ Integer64PlusConstantToSmi(rdx, rcx, y); 397 __ Integer64PlusConstantToSmi(rdx, rcx, y);
397 __ SmiCompare(rdx, r8); 398 __ cmpq(rdx, r8);
398 __ j(not_equal, exit); 399 __ j(not_equal, exit);
399 400
400 __ incq(rax); 401 __ incq(rax);
401 __ SmiCompare(r11, rcx); 402 __ cmpq(r11, rcx);
402 __ j(not_equal, exit); 403 __ j(not_equal, exit);
403 404
404 __ incq(rax); 405 __ incq(rax);
405 __ Integer64PlusConstantToSmi(rcx, rcx, y); 406 __ Integer64PlusConstantToSmi(rcx, rcx, y);
406 __ SmiCompare(rcx, r8); 407 __ cmpq(rcx, r8);
407 __ j(not_equal, exit); 408 __ j(not_equal, exit);
408 } 409 }
409 410
410 411
411 TEST(Integer64PlusConstantToSmi) { 412 TEST(Integer64PlusConstantToSmi) {
412 // Allocate an executable page of memory. 413 // Allocate an executable page of memory.
413 size_t actual_size; 414 size_t actual_size;
414 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, 415 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize,
415 &actual_size, 416 &actual_size,
416 true)); 417 true));
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
653 654
654 void TestSmiNeg(MacroAssembler* masm, Label* exit, int id, int x) { 655 void TestSmiNeg(MacroAssembler* masm, Label* exit, int id, int x) {
655 __ Move(rcx, Smi::FromInt(x)); 656 __ Move(rcx, Smi::FromInt(x));
656 __ movq(r11, rcx); 657 __ movq(r11, rcx);
657 if (x == Smi::kMinValue || x == 0) { 658 if (x == Smi::kMinValue || x == 0) {
658 // Negation fails. 659 // Negation fails.
659 __ movl(rax, Immediate(id + 8)); 660 __ movl(rax, Immediate(id + 8));
660 __ SmiNeg(r9, rcx, exit); 661 __ SmiNeg(r9, rcx, exit);
661 662
662 __ incq(rax); 663 __ incq(rax);
663 __ SmiCompare(r11, rcx); 664 __ cmpq(r11, rcx);
664 __ j(not_equal, exit); 665 __ j(not_equal, exit);
665 666
666 __ incq(rax); 667 __ incq(rax);
667 __ SmiNeg(rcx, rcx, exit); 668 __ SmiNeg(rcx, rcx, exit);
668 669
669 __ incq(rax); 670 __ incq(rax);
670 __ SmiCompare(r11, rcx); 671 __ cmpq(r11, rcx);
671 __ j(not_equal, exit); 672 __ j(not_equal, exit);
672 } else { 673 } else {
673 Label smi_ok, smi_ok2; 674 Label smi_ok, smi_ok2;
674 int result = -x; 675 int result = -x;
675 __ movl(rax, Immediate(id)); 676 __ movl(rax, Immediate(id));
676 __ Move(r8, Smi::FromInt(result)); 677 __ Move(r8, Smi::FromInt(result));
677 678
678 __ SmiNeg(r9, rcx, &smi_ok); 679 __ SmiNeg(r9, rcx, &smi_ok);
679 __ jmp(exit); 680 __ jmp(exit);
680 __ bind(&smi_ok); 681 __ bind(&smi_ok);
681 __ incq(rax); 682 __ incq(rax);
682 __ SmiCompare(r9, r8); 683 __ cmpq(r9, r8);
683 __ j(not_equal, exit); 684 __ j(not_equal, exit);
684 685
685 __ incq(rax); 686 __ incq(rax);
686 __ SmiCompare(r11, rcx); 687 __ cmpq(r11, rcx);
687 __ j(not_equal, exit); 688 __ j(not_equal, exit);
688 689
689 __ incq(rax); 690 __ incq(rax);
690 __ SmiNeg(rcx, rcx, &smi_ok2); 691 __ SmiNeg(rcx, rcx, &smi_ok2);
691 __ jmp(exit); 692 __ jmp(exit);
692 __ bind(&smi_ok2); 693 __ bind(&smi_ok2);
693 __ incq(rax); 694 __ incq(rax);
694 __ SmiCompare(rcx, r8); 695 __ cmpq(rcx, r8);
695 __ j(not_equal, exit); 696 __ j(not_equal, exit);
696 } 697 }
697 } 698 }
698 699
699 700
700 TEST(SmiNeg) { 701 TEST(SmiNeg) {
701 // Allocate an executable page of memory. 702 // Allocate an executable page of memory.
702 size_t actual_size; 703 size_t actual_size;
703 byte* buffer = 704 byte* buffer =
704 static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, 705 static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize,
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
744 int second) { 745 int second) {
745 __ movl(rcx, Immediate(first)); 746 __ movl(rcx, Immediate(first));
746 __ Integer32ToSmi(rcx, rcx); 747 __ Integer32ToSmi(rcx, rcx);
747 __ movl(rdx, Immediate(second)); 748 __ movl(rdx, Immediate(second));
748 __ Integer32ToSmi(rdx, rdx); 749 __ Integer32ToSmi(rdx, rdx);
749 __ movl(r8, Immediate(first + second)); 750 __ movl(r8, Immediate(first + second));
750 __ Integer32ToSmi(r8, r8); 751 __ Integer32ToSmi(r8, r8);
751 752
752 __ movl(rax, Immediate(id)); // Test number. 753 __ movl(rax, Immediate(id)); // Test number.
753 __ SmiAdd(r9, rcx, rdx, exit); 754 __ SmiAdd(r9, rcx, rdx, exit);
754 __ SmiCompare(r9, r8); 755 __ cmpq(r9, r8);
755 __ j(not_equal, exit); 756 __ j(not_equal, exit);
756 757
757 __ incq(rax); 758 __ incq(rax);
758 __ SmiAdd(rcx, rcx, rdx, exit); \ 759 __ SmiAdd(rcx, rcx, rdx, exit); \
759 __ SmiCompare(rcx, r8); 760 __ cmpq(rcx, r8);
760 __ j(not_equal, exit); 761 __ j(not_equal, exit);
761 762
762 __ movl(rcx, Immediate(first)); 763 __ movl(rcx, Immediate(first));
763 __ Integer32ToSmi(rcx, rcx); 764 __ Integer32ToSmi(rcx, rcx);
764 765
765 __ incq(rax); 766 __ incq(rax);
766 __ SmiAddConstant(r9, rcx, Smi::FromInt(second)); 767 __ SmiAddConstant(r9, rcx, Smi::FromInt(second));
767 __ SmiCompare(r9, r8); 768 __ cmpq(r9, r8);
768 __ j(not_equal, exit); 769 __ j(not_equal, exit);
769 770
770 __ SmiAddConstant(rcx, rcx, Smi::FromInt(second)); 771 __ SmiAddConstant(rcx, rcx, Smi::FromInt(second));
771 __ SmiCompare(rcx, r8); 772 __ cmpq(rcx, r8);
772 __ j(not_equal, exit); 773 __ j(not_equal, exit);
773 774
774 __ movl(rcx, Immediate(first)); 775 __ movl(rcx, Immediate(first));
775 __ Integer32ToSmi(rcx, rcx); 776 __ Integer32ToSmi(rcx, rcx);
776 777
777 __ incq(rax); 778 __ incq(rax);
778 __ SmiAddConstant(r9, rcx, Smi::FromInt(second), exit); 779 __ SmiAddConstant(r9, rcx, Smi::FromInt(second), exit);
779 __ SmiCompare(r9, r8); 780 __ cmpq(r9, r8);
780 __ j(not_equal, exit); 781 __ j(not_equal, exit);
781 782
782 __ incq(rax); 783 __ incq(rax);
783 __ SmiAddConstant(rcx, rcx, Smi::FromInt(second), exit); 784 __ SmiAddConstant(rcx, rcx, Smi::FromInt(second), exit);
784 __ SmiCompare(rcx, r8); 785 __ cmpq(rcx, r8);
785 __ j(not_equal, exit); 786 __ j(not_equal, exit);
786 } 787 }
787 788
788 TEST(SmiAdd) { 789 TEST(SmiAdd) {
789 // Allocate an executable page of memory. 790 // Allocate an executable page of memory.
790 size_t actual_size; 791 size_t actual_size;
791 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, 792 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize,
792 &actual_size, 793 &actual_size,
793 true)); 794 true));
794 CHECK(buffer); 795 CHECK(buffer);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
827 Label* exit, 828 Label* exit,
828 int id, 829 int id,
829 int first, 830 int first,
830 int second) { 831 int second) {
831 __ Move(rcx, Smi::FromInt(first)); 832 __ Move(rcx, Smi::FromInt(first));
832 __ Move(rdx, Smi::FromInt(second)); 833 __ Move(rdx, Smi::FromInt(second));
833 __ Move(r8, Smi::FromInt(first - second)); 834 __ Move(r8, Smi::FromInt(first - second));
834 835
835 __ movl(rax, Immediate(id)); // Test 0. 836 __ movl(rax, Immediate(id)); // Test 0.
836 __ SmiSub(r9, rcx, rdx, exit); 837 __ SmiSub(r9, rcx, rdx, exit);
837 __ SmiCompare(r9, r8); 838 __ cmpq(r9, r8);
838 __ j(not_equal, exit); 839 __ j(not_equal, exit);
839 840
840 __ incq(rax); // Test 1. 841 __ incq(rax); // Test 1.
841 __ SmiSub(rcx, rcx, rdx, exit); 842 __ SmiSub(rcx, rcx, rdx, exit);
842 __ SmiCompare(rcx, r8); 843 __ cmpq(rcx, r8);
843 __ j(not_equal, exit); 844 __ j(not_equal, exit);
844 845
845 __ Move(rcx, Smi::FromInt(first)); 846 __ Move(rcx, Smi::FromInt(first));
846 847
847 __ incq(rax); // Test 2. 848 __ incq(rax); // Test 2.
848 __ SmiSubConstant(r9, rcx, Smi::FromInt(second)); 849 __ SmiSubConstant(r9, rcx, Smi::FromInt(second));
849 __ SmiCompare(r9, r8); 850 __ cmpq(r9, r8);
850 __ j(not_equal, exit); 851 __ j(not_equal, exit);
851 852
852 __ incq(rax); // Test 3. 853 __ incq(rax); // Test 3.
853 __ SmiSubConstant(rcx, rcx, Smi::FromInt(second)); 854 __ SmiSubConstant(rcx, rcx, Smi::FromInt(second));
854 __ SmiCompare(rcx, r8); 855 __ cmpq(rcx, r8);
855 __ j(not_equal, exit); 856 __ j(not_equal, exit);
856 857
857 __ Move(rcx, Smi::FromInt(first)); 858 __ Move(rcx, Smi::FromInt(first));
858 859
859 __ incq(rax); // Test 4. 860 __ incq(rax); // Test 4.
860 __ SmiSubConstant(r9, rcx, Smi::FromInt(second), exit); 861 __ SmiSubConstant(r9, rcx, Smi::FromInt(second), exit);
861 __ SmiCompare(r9, r8); 862 __ cmpq(r9, r8);
862 __ j(not_equal, exit); 863 __ j(not_equal, exit);
863 864
864 __ incq(rax); // Test 5. 865 __ incq(rax); // Test 5.
865 __ SmiSubConstant(rcx, rcx, Smi::FromInt(second), exit); 866 __ SmiSubConstant(rcx, rcx, Smi::FromInt(second), exit);
866 __ SmiCompare(rcx, r8); 867 __ cmpq(rcx, r8);
867 __ j(not_equal, exit); 868 __ j(not_equal, exit);
868 } 869 }
869 870
870 static void SmiSubOverflowTest(MacroAssembler* masm, 871 static void SmiSubOverflowTest(MacroAssembler* masm,
871 Label* exit, 872 Label* exit,
872 int id, 873 int id,
873 int x) { 874 int x) {
874 // Subtracts a Smi from x so that the subtraction overflows. 875 // Subtracts a Smi from x so that the subtraction overflows.
875 ASSERT(x != -1); // Can't overflow by subtracting a Smi. 876 ASSERT(x != -1); // Can't overflow by subtracting a Smi.
876 int y_max = (x < 0) ? (Smi::kMaxValue + 0) : (Smi::kMinValue + 0); 877 int y_max = (x < 0) ? (Smi::kMaxValue + 0) : (Smi::kMinValue + 0);
877 int y_min = (x < 0) ? (Smi::kMaxValue + x + 2) : (Smi::kMinValue + x); 878 int y_min = (x < 0) ? (Smi::kMaxValue + x + 2) : (Smi::kMinValue + x);
878 879
879 __ movl(rax, Immediate(id)); 880 __ movl(rax, Immediate(id));
880 __ Move(rcx, Smi::FromInt(x)); 881 __ Move(rcx, Smi::FromInt(x));
881 __ movq(r11, rcx); // Store original Smi value of x in r11. 882 __ movq(r11, rcx); // Store original Smi value of x in r11.
882 __ Move(rdx, Smi::FromInt(y_min)); 883 __ Move(rdx, Smi::FromInt(y_min));
883 { 884 {
884 Label overflow_ok; 885 Label overflow_ok;
885 __ SmiSub(r9, rcx, rdx, &overflow_ok); 886 __ SmiSub(r9, rcx, rdx, &overflow_ok);
886 __ jmp(exit); 887 __ jmp(exit);
887 __ bind(&overflow_ok); 888 __ bind(&overflow_ok);
888 __ incq(rax); 889 __ incq(rax);
889 __ SmiCompare(rcx, r11); 890 __ cmpq(rcx, r11);
890 __ j(not_equal, exit); 891 __ j(not_equal, exit);
891 } 892 }
892 893
893 { 894 {
894 Label overflow_ok; 895 Label overflow_ok;
895 __ incq(rax); 896 __ incq(rax);
896 __ SmiSub(rcx, rcx, rdx, &overflow_ok); 897 __ SmiSub(rcx, rcx, rdx, &overflow_ok);
897 __ jmp(exit); 898 __ jmp(exit);
898 __ bind(&overflow_ok); 899 __ bind(&overflow_ok);
899 __ incq(rax); 900 __ incq(rax);
900 __ SmiCompare(rcx, r11); 901 __ cmpq(rcx, r11);
901 __ j(not_equal, exit); 902 __ j(not_equal, exit);
902 } 903 }
903 904
904 __ movq(rcx, r11); 905 __ movq(rcx, r11);
905 { 906 {
906 Label overflow_ok; 907 Label overflow_ok;
907 __ incq(rax); 908 __ incq(rax);
908 __ SmiSubConstant(r9, rcx, Smi::FromInt(y_min), &overflow_ok); 909 __ SmiSubConstant(r9, rcx, Smi::FromInt(y_min), &overflow_ok);
909 __ jmp(exit); 910 __ jmp(exit);
910 __ bind(&overflow_ok); 911 __ bind(&overflow_ok);
911 __ incq(rax); 912 __ incq(rax);
912 __ SmiCompare(rcx, r11); 913 __ cmpq(rcx, r11);
913 __ j(not_equal, exit); 914 __ j(not_equal, exit);
914 } 915 }
915 916
916 { 917 {
917 Label overflow_ok; 918 Label overflow_ok;
918 __ incq(rax); 919 __ incq(rax);
919 __ SmiSubConstant(rcx, rcx, Smi::FromInt(y_min), &overflow_ok); 920 __ SmiSubConstant(rcx, rcx, Smi::FromInt(y_min), &overflow_ok);
920 __ jmp(exit); 921 __ jmp(exit);
921 __ bind(&overflow_ok); 922 __ bind(&overflow_ok);
922 __ incq(rax); 923 __ incq(rax);
923 __ SmiCompare(rcx, r11); 924 __ cmpq(rcx, r11);
924 __ j(not_equal, exit); 925 __ j(not_equal, exit);
925 } 926 }
926 927
927 __ Move(rdx, Smi::FromInt(y_max)); 928 __ Move(rdx, Smi::FromInt(y_max));
928 929
929 { 930 {
930 Label overflow_ok; 931 Label overflow_ok;
931 __ incq(rax); 932 __ incq(rax);
932 __ SmiSub(r9, rcx, rdx, &overflow_ok); 933 __ SmiSub(r9, rcx, rdx, &overflow_ok);
933 __ jmp(exit); 934 __ jmp(exit);
934 __ bind(&overflow_ok); 935 __ bind(&overflow_ok);
935 __ incq(rax); 936 __ incq(rax);
936 __ SmiCompare(rcx, r11); 937 __ cmpq(rcx, r11);
937 __ j(not_equal, exit); 938 __ j(not_equal, exit);
938 } 939 }
939 940
940 { 941 {
941 Label overflow_ok; 942 Label overflow_ok;
942 __ incq(rax); 943 __ incq(rax);
943 __ SmiSub(rcx, rcx, rdx, &overflow_ok); 944 __ SmiSub(rcx, rcx, rdx, &overflow_ok);
944 __ jmp(exit); 945 __ jmp(exit);
945 __ bind(&overflow_ok); 946 __ bind(&overflow_ok);
946 __ incq(rax); 947 __ incq(rax);
947 __ SmiCompare(rcx, r11); 948 __ cmpq(rcx, r11);
948 __ j(not_equal, exit); 949 __ j(not_equal, exit);
949 } 950 }
950 951
951 __ movq(rcx, r11); 952 __ movq(rcx, r11);
952 { 953 {
953 Label overflow_ok; 954 Label overflow_ok;
954 __ incq(rax); 955 __ incq(rax);
955 __ SmiSubConstant(r9, rcx, Smi::FromInt(y_max), &overflow_ok); 956 __ SmiSubConstant(r9, rcx, Smi::FromInt(y_max), &overflow_ok);
956 __ jmp(exit); 957 __ jmp(exit);
957 __ bind(&overflow_ok); 958 __ bind(&overflow_ok);
958 __ incq(rax); 959 __ incq(rax);
959 __ SmiCompare(rcx, r11); 960 __ cmpq(rcx, r11);
960 __ j(not_equal, exit); 961 __ j(not_equal, exit);
961 } 962 }
962 963
963 { 964 {
964 Label overflow_ok; 965 Label overflow_ok;
965 __ incq(rax); 966 __ incq(rax);
966 __ SmiSubConstant(rcx, rcx, Smi::FromInt(y_max), &overflow_ok); 967 __ SmiSubConstant(rcx, rcx, Smi::FromInt(y_max), &overflow_ok);
967 __ jmp(exit); 968 __ jmp(exit);
968 __ bind(&overflow_ok); 969 __ bind(&overflow_ok);
969 __ incq(rax); 970 __ incq(rax);
970 __ SmiCompare(rcx, r11); 971 __ cmpq(rcx, r11);
971 __ j(not_equal, exit); 972 __ j(not_equal, exit);
972 } 973 }
973 } 974 }
974 975
975 976
976 TEST(SmiSub) { 977 TEST(SmiSub) {
977 // Allocate an executable page of memory. 978 // Allocate an executable page of memory.
978 size_t actual_size; 979 size_t actual_size;
979 byte* buffer = 980 byte* buffer =
980 static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize * 2, 981 static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize * 2,
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1025 int64_t result = static_cast<int64_t>(x) * static_cast<int64_t>(y); 1026 int64_t result = static_cast<int64_t>(x) * static_cast<int64_t>(y);
1026 bool negative_zero = (result == 0) && (x < 0 || y < 0); 1027 bool negative_zero = (result == 0) && (x < 0 || y < 0);
1027 __ Move(rcx, Smi::FromInt(x)); 1028 __ Move(rcx, Smi::FromInt(x));
1028 __ movq(r11, rcx); 1029 __ movq(r11, rcx);
1029 __ Move(rdx, Smi::FromInt(y)); 1030 __ Move(rdx, Smi::FromInt(y));
1030 if (Smi::IsValid(result) && !negative_zero) { 1031 if (Smi::IsValid(result) && !negative_zero) {
1031 __ movl(rax, Immediate(id)); 1032 __ movl(rax, Immediate(id));
1032 __ Move(r8, Smi::FromIntptr(result)); 1033 __ Move(r8, Smi::FromIntptr(result));
1033 __ SmiMul(r9, rcx, rdx, exit); 1034 __ SmiMul(r9, rcx, rdx, exit);
1034 __ incq(rax); 1035 __ incq(rax);
1035 __ SmiCompare(r11, rcx); 1036 __ cmpq(r11, rcx);
1036 __ j(not_equal, exit); 1037 __ j(not_equal, exit);
1037 __ incq(rax); 1038 __ incq(rax);
1038 __ SmiCompare(r9, r8); 1039 __ cmpq(r9, r8);
1039 __ j(not_equal, exit); 1040 __ j(not_equal, exit);
1040 1041
1041 __ incq(rax); 1042 __ incq(rax);
1042 __ SmiMul(rcx, rcx, rdx, exit); 1043 __ SmiMul(rcx, rcx, rdx, exit);
1043 __ SmiCompare(rcx, r8); 1044 __ cmpq(rcx, r8);
1044 __ j(not_equal, exit); 1045 __ j(not_equal, exit);
1045 } else { 1046 } else {
1046 __ movl(rax, Immediate(id + 8)); 1047 __ movl(rax, Immediate(id + 8));
1047 Label overflow_ok, overflow_ok2; 1048 Label overflow_ok, overflow_ok2;
1048 __ SmiMul(r9, rcx, rdx, &overflow_ok); 1049 __ SmiMul(r9, rcx, rdx, &overflow_ok);
1049 __ jmp(exit); 1050 __ jmp(exit);
1050 __ bind(&overflow_ok); 1051 __ bind(&overflow_ok);
1051 __ incq(rax); 1052 __ incq(rax);
1052 __ SmiCompare(r11, rcx); 1053 __ cmpq(r11, rcx);
1053 __ j(not_equal, exit); 1054 __ j(not_equal, exit);
1054 __ incq(rax); 1055 __ incq(rax);
1055 __ SmiMul(rcx, rcx, rdx, &overflow_ok2); 1056 __ SmiMul(rcx, rcx, rdx, &overflow_ok2);
1056 __ jmp(exit); 1057 __ jmp(exit);
1057 __ bind(&overflow_ok2); 1058 __ bind(&overflow_ok2);
1058 // 31-bit version doesn't preserve rcx on failure. 1059 // 31-bit version doesn't preserve rcx on failure.
1059 // __ incq(rax); 1060 // __ incq(rax);
1060 // __ SmiCompare(r11, rcx); 1061 // __ cmpq(r11, rcx);
1061 // __ j(not_equal, exit); 1062 // __ j(not_equal, exit);
1062 } 1063 }
1063 } 1064 }
1064 1065
1065 1066
1066 TEST(SmiMul) { 1067 TEST(SmiMul) {
1067 // Allocate an executable page of memory. 1068 // Allocate an executable page of memory.
1068 size_t actual_size; 1069 size_t actual_size;
1069 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, 1070 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize,
1070 &actual_size, 1071 &actual_size,
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1119 __ Move(r14, Smi::FromInt(y)); 1120 __ Move(r14, Smi::FromInt(y));
1120 if (!fraction && !overflow && !negative_zero && !division_by_zero) { 1121 if (!fraction && !overflow && !negative_zero && !division_by_zero) {
1121 // Division succeeds 1122 // Division succeeds
1122 __ movq(rcx, r11); 1123 __ movq(rcx, r11);
1123 __ movq(r15, Immediate(id)); 1124 __ movq(r15, Immediate(id));
1124 int result = x / y; 1125 int result = x / y;
1125 __ Move(r8, Smi::FromInt(result)); 1126 __ Move(r8, Smi::FromInt(result));
1126 __ SmiDiv(r9, rcx, r14, exit); 1127 __ SmiDiv(r9, rcx, r14, exit);
1127 // Might have destroyed rcx and r14. 1128 // Might have destroyed rcx and r14.
1128 __ incq(r15); 1129 __ incq(r15);
1129 __ SmiCompare(r9, r8); 1130 __ cmpq(r9, r8);
1130 __ j(not_equal, exit); 1131 __ j(not_equal, exit);
1131 1132
1132 __ incq(r15); 1133 __ incq(r15);
1133 __ movq(rcx, r11); 1134 __ movq(rcx, r11);
1134 __ Move(r14, Smi::FromInt(y)); 1135 __ Move(r14, Smi::FromInt(y));
1135 __ SmiCompare(rcx, r11); 1136 __ cmpq(rcx, r11);
1136 __ j(not_equal, exit); 1137 __ j(not_equal, exit);
1137 1138
1138 __ incq(r15); 1139 __ incq(r15);
1139 __ SmiDiv(rcx, rcx, r14, exit); 1140 __ SmiDiv(rcx, rcx, r14, exit);
1140 1141
1141 __ incq(r15); 1142 __ incq(r15);
1142 __ SmiCompare(rcx, r8); 1143 __ cmpq(rcx, r8);
1143 __ j(not_equal, exit); 1144 __ j(not_equal, exit);
1144 } else { 1145 } else {
1145 // Division fails. 1146 // Division fails.
1146 __ movq(r15, Immediate(id + 8)); 1147 __ movq(r15, Immediate(id + 8));
1147 1148
1148 Label fail_ok, fail_ok2; 1149 Label fail_ok, fail_ok2;
1149 __ movq(rcx, r11); 1150 __ movq(rcx, r11);
1150 __ SmiDiv(r9, rcx, r14, &fail_ok); 1151 __ SmiDiv(r9, rcx, r14, &fail_ok);
1151 __ jmp(exit); 1152 __ jmp(exit);
1152 __ bind(&fail_ok); 1153 __ bind(&fail_ok);
1153 1154
1154 __ incq(r15); 1155 __ incq(r15);
1155 __ SmiCompare(rcx, r11); 1156 __ cmpq(rcx, r11);
1156 __ j(not_equal, exit); 1157 __ j(not_equal, exit);
1157 1158
1158 __ incq(r15); 1159 __ incq(r15);
1159 __ SmiDiv(rcx, rcx, r14, &fail_ok2); 1160 __ SmiDiv(rcx, rcx, r14, &fail_ok2);
1160 __ jmp(exit); 1161 __ jmp(exit);
1161 __ bind(&fail_ok2); 1162 __ bind(&fail_ok2);
1162 1163
1163 __ incq(r15); 1164 __ incq(r15);
1164 __ SmiCompare(rcx, r11); 1165 __ cmpq(rcx, r11);
1165 __ j(not_equal, exit); 1166 __ j(not_equal, exit);
1166 } 1167 }
1167 } 1168 }
1168 1169
1169 1170
1170 TEST(SmiDiv) { 1171 TEST(SmiDiv) {
1171 // Allocate an executable page of memory. 1172 // Allocate an executable page of memory.
1172 size_t actual_size; 1173 size_t actual_size;
1173 byte* buffer = 1174 byte* buffer =
1174 static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize * 2, 1175 static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize * 2,
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
1231 __ movq(r11, rcx); 1232 __ movq(r11, rcx);
1232 __ Move(r14, Smi::FromInt(y)); 1233 __ Move(r14, Smi::FromInt(y));
1233 if (!division_overflow && !negative_zero && !division_by_zero) { 1234 if (!division_overflow && !negative_zero && !division_by_zero) {
1234 // Modulo succeeds 1235 // Modulo succeeds
1235 __ movq(r15, Immediate(id)); 1236 __ movq(r15, Immediate(id));
1236 int result = x % y; 1237 int result = x % y;
1237 __ Move(r8, Smi::FromInt(result)); 1238 __ Move(r8, Smi::FromInt(result));
1238 __ SmiMod(r9, rcx, r14, exit); 1239 __ SmiMod(r9, rcx, r14, exit);
1239 1240
1240 __ incq(r15); 1241 __ incq(r15);
1241 __ SmiCompare(r9, r8); 1242 __ cmpq(r9, r8);
1242 __ j(not_equal, exit); 1243 __ j(not_equal, exit);
1243 1244
1244 __ incq(r15); 1245 __ incq(r15);
1245 __ SmiCompare(rcx, r11); 1246 __ cmpq(rcx, r11);
1246 __ j(not_equal, exit); 1247 __ j(not_equal, exit);
1247 1248
1248 __ incq(r15); 1249 __ incq(r15);
1249 __ SmiMod(rcx, rcx, r14, exit); 1250 __ SmiMod(rcx, rcx, r14, exit);
1250 1251
1251 __ incq(r15); 1252 __ incq(r15);
1252 __ SmiCompare(rcx, r8); 1253 __ cmpq(rcx, r8);
1253 __ j(not_equal, exit); 1254 __ j(not_equal, exit);
1254 } else { 1255 } else {
1255 // Modulo fails. 1256 // Modulo fails.
1256 __ movq(r15, Immediate(id + 8)); 1257 __ movq(r15, Immediate(id + 8));
1257 1258
1258 Label fail_ok, fail_ok2; 1259 Label fail_ok, fail_ok2;
1259 __ SmiMod(r9, rcx, r14, &fail_ok); 1260 __ SmiMod(r9, rcx, r14, &fail_ok);
1260 __ jmp(exit); 1261 __ jmp(exit);
1261 __ bind(&fail_ok); 1262 __ bind(&fail_ok);
1262 1263
1263 __ incq(r15); 1264 __ incq(r15);
1264 __ SmiCompare(rcx, r11); 1265 __ cmpq(rcx, r11);
1265 __ j(not_equal, exit); 1266 __ j(not_equal, exit);
1266 1267
1267 __ incq(r15); 1268 __ incq(r15);
1268 __ SmiMod(rcx, rcx, r14, &fail_ok2); 1269 __ SmiMod(rcx, rcx, r14, &fail_ok2);
1269 __ jmp(exit); 1270 __ jmp(exit);
1270 __ bind(&fail_ok2); 1271 __ bind(&fail_ok2);
1271 1272
1272 __ incq(r15); 1273 __ incq(r15);
1273 __ SmiCompare(rcx, r11); 1274 __ cmpq(rcx, r11);
1274 __ j(not_equal, exit); 1275 __ j(not_equal, exit);
1275 } 1276 }
1276 } 1277 }
1277 1278
1278 1279
1279 TEST(SmiMod) { 1280 TEST(SmiMod) {
1280 // Allocate an executable page of memory. 1281 // Allocate an executable page of memory.
1281 size_t actual_size; 1282 size_t actual_size;
1282 byte* buffer = 1283 byte* buffer =
1283 static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize * 2, 1284 static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize * 2,
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1333 1334
1334 void TestSmiIndex(MacroAssembler* masm, Label* exit, int id, int x) { 1335 void TestSmiIndex(MacroAssembler* masm, Label* exit, int id, int x) {
1335 __ movl(rax, Immediate(id)); 1336 __ movl(rax, Immediate(id));
1336 1337
1337 for (int i = 0; i < 8; i++) { 1338 for (int i = 0; i < 8; i++) {
1338 __ Move(rcx, Smi::FromInt(x)); 1339 __ Move(rcx, Smi::FromInt(x));
1339 SmiIndex index = masm->SmiToIndex(rdx, rcx, i); 1340 SmiIndex index = masm->SmiToIndex(rdx, rcx, i);
1340 ASSERT(index.reg.is(rcx) || index.reg.is(rdx)); 1341 ASSERT(index.reg.is(rcx) || index.reg.is(rdx));
1341 __ shl(index.reg, Immediate(index.scale)); 1342 __ shl(index.reg, Immediate(index.scale));
1342 __ Set(r8, static_cast<intptr_t>(x) << i); 1343 __ Set(r8, static_cast<intptr_t>(x) << i);
1343 __ SmiCompare(index.reg, r8); 1344 __ cmpq(index.reg, r8);
1344 __ j(not_equal, exit); 1345 __ j(not_equal, exit);
1345 __ incq(rax); 1346 __ incq(rax);
1346 __ Move(rcx, Smi::FromInt(x)); 1347 __ Move(rcx, Smi::FromInt(x));
1347 index = masm->SmiToIndex(rcx, rcx, i); 1348 index = masm->SmiToIndex(rcx, rcx, i);
1348 ASSERT(index.reg.is(rcx)); 1349 ASSERT(index.reg.is(rcx));
1349 __ shl(rcx, Immediate(index.scale)); 1350 __ shl(rcx, Immediate(index.scale));
1350 __ Set(r8, static_cast<intptr_t>(x) << i); 1351 __ Set(r8, static_cast<intptr_t>(x) << i);
1351 __ SmiCompare(rcx, r8); 1352 __ cmpq(rcx, r8);
1352 __ j(not_equal, exit); 1353 __ j(not_equal, exit);
1353 __ incq(rax); 1354 __ incq(rax);
1354 1355
1355 __ Move(rcx, Smi::FromInt(x)); 1356 __ Move(rcx, Smi::FromInt(x));
1356 index = masm->SmiToNegativeIndex(rdx, rcx, i); 1357 index = masm->SmiToNegativeIndex(rdx, rcx, i);
1357 ASSERT(index.reg.is(rcx) || index.reg.is(rdx)); 1358 ASSERT(index.reg.is(rcx) || index.reg.is(rdx));
1358 __ shl(index.reg, Immediate(index.scale)); 1359 __ shl(index.reg, Immediate(index.scale));
1359 __ Set(r8, static_cast<intptr_t>(-x) << i); 1360 __ Set(r8, static_cast<intptr_t>(-x) << i);
1360 __ SmiCompare(index.reg, r8); 1361 __ cmpq(index.reg, r8);
1361 __ j(not_equal, exit); 1362 __ j(not_equal, exit);
1362 __ incq(rax); 1363 __ incq(rax);
1363 __ Move(rcx, Smi::FromInt(x)); 1364 __ Move(rcx, Smi::FromInt(x));
1364 index = masm->SmiToNegativeIndex(rcx, rcx, i); 1365 index = masm->SmiToNegativeIndex(rcx, rcx, i);
1365 ASSERT(index.reg.is(rcx)); 1366 ASSERT(index.reg.is(rcx));
1366 __ shl(rcx, Immediate(index.scale)); 1367 __ shl(rcx, Immediate(index.scale));
1367 __ Set(r8, static_cast<intptr_t>(-x) << i); 1368 __ Set(r8, static_cast<intptr_t>(-x) << i);
1368 __ SmiCompare(rcx, r8); 1369 __ cmpq(rcx, r8);
1369 __ j(not_equal, exit); 1370 __ j(not_equal, exit);
1370 __ incq(rax); 1371 __ incq(rax);
1371 } 1372 }
1372 } 1373 }
1373 1374
1374 TEST(SmiIndex) { 1375 TEST(SmiIndex) {
1375 // Allocate an executable page of memory. 1376 // Allocate an executable page of memory.
1376 size_t actual_size; 1377 size_t actual_size;
1377 byte* buffer = 1378 byte* buffer =
1378 static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize * 3, 1379 static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize * 3,
(...skipping 28 matching lines...) Expand all
1407 1408
1408 1409
1409 void TestSelectNonSmi(MacroAssembler* masm, Label* exit, int id, int x, int y) { 1410 void TestSelectNonSmi(MacroAssembler* masm, Label* exit, int id, int x, int y) {
1410 __ movl(rax, Immediate(id)); 1411 __ movl(rax, Immediate(id));
1411 __ Move(rcx, Smi::FromInt(x)); 1412 __ Move(rcx, Smi::FromInt(x));
1412 __ Move(rdx, Smi::FromInt(y)); 1413 __ Move(rdx, Smi::FromInt(y));
1413 __ xor_(rdx, Immediate(kSmiTagMask)); 1414 __ xor_(rdx, Immediate(kSmiTagMask));
1414 __ SelectNonSmi(r9, rcx, rdx, exit); 1415 __ SelectNonSmi(r9, rcx, rdx, exit);
1415 1416
1416 __ incq(rax); 1417 __ incq(rax);
1417 __ SmiCompare(r9, rdx); 1418 __ cmpq(r9, rdx);
1418 __ j(not_equal, exit); 1419 __ j(not_equal, exit);
1419 1420
1420 __ incq(rax); 1421 __ incq(rax);
1421 __ Move(rcx, Smi::FromInt(x)); 1422 __ Move(rcx, Smi::FromInt(x));
1422 __ Move(rdx, Smi::FromInt(y)); 1423 __ Move(rdx, Smi::FromInt(y));
1423 __ xor_(rcx, Immediate(kSmiTagMask)); 1424 __ xor_(rcx, Immediate(kSmiTagMask));
1424 __ SelectNonSmi(r9, rcx, rdx, exit); 1425 __ SelectNonSmi(r9, rcx, rdx, exit);
1425 1426
1426 __ incq(rax); 1427 __ incq(rax);
1427 __ SmiCompare(r9, rcx); 1428 __ cmpq(r9, rcx);
1428 __ j(not_equal, exit); 1429 __ j(not_equal, exit);
1429 1430
1430 __ incq(rax); 1431 __ incq(rax);
1431 Label fail_ok; 1432 Label fail_ok;
1432 __ Move(rcx, Smi::FromInt(x)); 1433 __ Move(rcx, Smi::FromInt(x));
1433 __ Move(rdx, Smi::FromInt(y)); 1434 __ Move(rdx, Smi::FromInt(y));
1434 __ xor_(rcx, Immediate(kSmiTagMask)); 1435 __ xor_(rcx, Immediate(kSmiTagMask));
1435 __ xor_(rdx, Immediate(kSmiTagMask)); 1436 __ xor_(rdx, Immediate(kSmiTagMask));
1436 __ SelectNonSmi(r9, rcx, rdx, &fail_ok); 1437 __ SelectNonSmi(r9, rcx, rdx, &fail_ok);
1437 __ jmp(exit); 1438 __ jmp(exit);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1481 void TestSmiAnd(MacroAssembler* masm, Label* exit, int id, int x, int y) { 1482 void TestSmiAnd(MacroAssembler* masm, Label* exit, int id, int x, int y) {
1482 int result = x & y; 1483 int result = x & y;
1483 1484
1484 __ movl(rax, Immediate(id)); 1485 __ movl(rax, Immediate(id));
1485 1486
1486 __ Move(rcx, Smi::FromInt(x)); 1487 __ Move(rcx, Smi::FromInt(x));
1487 __ movq(r11, rcx); 1488 __ movq(r11, rcx);
1488 __ Move(rdx, Smi::FromInt(y)); 1489 __ Move(rdx, Smi::FromInt(y));
1489 __ Move(r8, Smi::FromInt(result)); 1490 __ Move(r8, Smi::FromInt(result));
1490 __ SmiAnd(r9, rcx, rdx); 1491 __ SmiAnd(r9, rcx, rdx);
1491 __ SmiCompare(r8, r9); 1492 __ cmpq(r8, r9);
1492 __ j(not_equal, exit); 1493 __ j(not_equal, exit);
1493 1494
1494 __ incq(rax); 1495 __ incq(rax);
1495 __ SmiCompare(r11, rcx); 1496 __ cmpq(r11, rcx);
1496 __ j(not_equal, exit); 1497 __ j(not_equal, exit);
1497 1498
1498 __ incq(rax); 1499 __ incq(rax);
1499 __ SmiAnd(rcx, rcx, rdx); 1500 __ SmiAnd(rcx, rcx, rdx);
1500 __ SmiCompare(r8, rcx); 1501 __ cmpq(r8, rcx);
1501 __ j(not_equal, exit); 1502 __ j(not_equal, exit);
1502 1503
1503 __ movq(rcx, r11); 1504 __ movq(rcx, r11);
1504 __ incq(rax); 1505 __ incq(rax);
1505 __ SmiAndConstant(r9, rcx, Smi::FromInt(y)); 1506 __ SmiAndConstant(r9, rcx, Smi::FromInt(y));
1506 __ SmiCompare(r8, r9); 1507 __ cmpq(r8, r9);
1507 __ j(not_equal, exit); 1508 __ j(not_equal, exit);
1508 1509
1509 __ incq(rax); 1510 __ incq(rax);
1510 __ SmiCompare(r11, rcx); 1511 __ cmpq(r11, rcx);
1511 __ j(not_equal, exit); 1512 __ j(not_equal, exit);
1512 1513
1513 __ incq(rax); 1514 __ incq(rax);
1514 __ SmiAndConstant(rcx, rcx, Smi::FromInt(y)); 1515 __ SmiAndConstant(rcx, rcx, Smi::FromInt(y));
1515 __ SmiCompare(r8, rcx); 1516 __ cmpq(r8, rcx);
1516 __ j(not_equal, exit); 1517 __ j(not_equal, exit);
1517 } 1518 }
1518 1519
1519 1520
1520 TEST(SmiAnd) { 1521 TEST(SmiAnd) {
1521 // Allocate an executable page of memory. 1522 // Allocate an executable page of memory.
1522 size_t actual_size; 1523 size_t actual_size;
1523 byte* buffer = 1524 byte* buffer =
1524 static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, 1525 static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize,
1525 &actual_size, 1526 &actual_size,
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1561 void TestSmiOr(MacroAssembler* masm, Label* exit, int id, int x, int y) { 1562 void TestSmiOr(MacroAssembler* masm, Label* exit, int id, int x, int y) {
1562 int result = x | y; 1563 int result = x | y;
1563 1564
1564 __ movl(rax, Immediate(id)); 1565 __ movl(rax, Immediate(id));
1565 1566
1566 __ Move(rcx, Smi::FromInt(x)); 1567 __ Move(rcx, Smi::FromInt(x));
1567 __ movq(r11, rcx); 1568 __ movq(r11, rcx);
1568 __ Move(rdx, Smi::FromInt(y)); 1569 __ Move(rdx, Smi::FromInt(y));
1569 __ Move(r8, Smi::FromInt(result)); 1570 __ Move(r8, Smi::FromInt(result));
1570 __ SmiOr(r9, rcx, rdx); 1571 __ SmiOr(r9, rcx, rdx);
1571 __ SmiCompare(r8, r9); 1572 __ cmpq(r8, r9);
1572 __ j(not_equal, exit); 1573 __ j(not_equal, exit);
1573 1574
1574 __ incq(rax); 1575 __ incq(rax);
1575 __ SmiCompare(r11, rcx); 1576 __ cmpq(r11, rcx);
1576 __ j(not_equal, exit); 1577 __ j(not_equal, exit);
1577 1578
1578 __ incq(rax); 1579 __ incq(rax);
1579 __ SmiOr(rcx, rcx, rdx); 1580 __ SmiOr(rcx, rcx, rdx);
1580 __ SmiCompare(r8, rcx); 1581 __ cmpq(r8, rcx);
1581 __ j(not_equal, exit); 1582 __ j(not_equal, exit);
1582 1583
1583 __ movq(rcx, r11); 1584 __ movq(rcx, r11);
1584 __ incq(rax); 1585 __ incq(rax);
1585 __ SmiOrConstant(r9, rcx, Smi::FromInt(y)); 1586 __ SmiOrConstant(r9, rcx, Smi::FromInt(y));
1586 __ SmiCompare(r8, r9); 1587 __ cmpq(r8, r9);
1587 __ j(not_equal, exit); 1588 __ j(not_equal, exit);
1588 1589
1589 __ incq(rax); 1590 __ incq(rax);
1590 __ SmiCompare(r11, rcx); 1591 __ cmpq(r11, rcx);
1591 __ j(not_equal, exit); 1592 __ j(not_equal, exit);
1592 1593
1593 __ incq(rax); 1594 __ incq(rax);
1594 __ SmiOrConstant(rcx, rcx, Smi::FromInt(y)); 1595 __ SmiOrConstant(rcx, rcx, Smi::FromInt(y));
1595 __ SmiCompare(r8, rcx); 1596 __ cmpq(r8, rcx);
1596 __ j(not_equal, exit); 1597 __ j(not_equal, exit);
1597 } 1598 }
1598 1599
1599 1600
1600 TEST(SmiOr) { 1601 TEST(SmiOr) {
1601 // Allocate an executable page of memory. 1602 // Allocate an executable page of memory.
1602 size_t actual_size; 1603 size_t actual_size;
1603 byte* buffer = 1604 byte* buffer =
1604 static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, 1605 static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize,
1605 &actual_size, 1606 &actual_size,
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1643 void TestSmiXor(MacroAssembler* masm, Label* exit, int id, int x, int y) { 1644 void TestSmiXor(MacroAssembler* masm, Label* exit, int id, int x, int y) {
1644 int result = x ^ y; 1645 int result = x ^ y;
1645 1646
1646 __ movl(rax, Immediate(id)); 1647 __ movl(rax, Immediate(id));
1647 1648
1648 __ Move(rcx, Smi::FromInt(x)); 1649 __ Move(rcx, Smi::FromInt(x));
1649 __ movq(r11, rcx); 1650 __ movq(r11, rcx);
1650 __ Move(rdx, Smi::FromInt(y)); 1651 __ Move(rdx, Smi::FromInt(y));
1651 __ Move(r8, Smi::FromInt(result)); 1652 __ Move(r8, Smi::FromInt(result));
1652 __ SmiXor(r9, rcx, rdx); 1653 __ SmiXor(r9, rcx, rdx);
1653 __ SmiCompare(r8, r9); 1654 __ cmpq(r8, r9);
1654 __ j(not_equal, exit); 1655 __ j(not_equal, exit);
1655 1656
1656 __ incq(rax); 1657 __ incq(rax);
1657 __ SmiCompare(r11, rcx); 1658 __ cmpq(r11, rcx);
1658 __ j(not_equal, exit); 1659 __ j(not_equal, exit);
1659 1660
1660 __ incq(rax); 1661 __ incq(rax);
1661 __ SmiXor(rcx, rcx, rdx); 1662 __ SmiXor(rcx, rcx, rdx);
1662 __ SmiCompare(r8, rcx); 1663 __ cmpq(r8, rcx);
1663 __ j(not_equal, exit); 1664 __ j(not_equal, exit);
1664 1665
1665 __ movq(rcx, r11); 1666 __ movq(rcx, r11);
1666 __ incq(rax); 1667 __ incq(rax);
1667 __ SmiXorConstant(r9, rcx, Smi::FromInt(y)); 1668 __ SmiXorConstant(r9, rcx, Smi::FromInt(y));
1668 __ SmiCompare(r8, r9); 1669 __ cmpq(r8, r9);
1669 __ j(not_equal, exit); 1670 __ j(not_equal, exit);
1670 1671
1671 __ incq(rax); 1672 __ incq(rax);
1672 __ SmiCompare(r11, rcx); 1673 __ cmpq(r11, rcx);
1673 __ j(not_equal, exit); 1674 __ j(not_equal, exit);
1674 1675
1675 __ incq(rax); 1676 __ incq(rax);
1676 __ SmiXorConstant(rcx, rcx, Smi::FromInt(y)); 1677 __ SmiXorConstant(rcx, rcx, Smi::FromInt(y));
1677 __ SmiCompare(r8, rcx); 1678 __ cmpq(r8, rcx);
1678 __ j(not_equal, exit); 1679 __ j(not_equal, exit);
1679 } 1680 }
1680 1681
1681 1682
1682 TEST(SmiXor) { 1683 TEST(SmiXor) {
1683 // Allocate an executable page of memory. 1684 // Allocate an executable page of memory.
1684 size_t actual_size; 1685 size_t actual_size;
1685 byte* buffer = 1686 byte* buffer =
1686 static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, 1687 static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize,
1687 &actual_size, 1688 &actual_size,
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1724 1725
1725 void TestSmiNot(MacroAssembler* masm, Label* exit, int id, int x) { 1726 void TestSmiNot(MacroAssembler* masm, Label* exit, int id, int x) {
1726 int result = ~x; 1727 int result = ~x;
1727 __ movl(rax, Immediate(id)); 1728 __ movl(rax, Immediate(id));
1728 1729
1729 __ Move(r8, Smi::FromInt(result)); 1730 __ Move(r8, Smi::FromInt(result));
1730 __ Move(rcx, Smi::FromInt(x)); 1731 __ Move(rcx, Smi::FromInt(x));
1731 __ movq(r11, rcx); 1732 __ movq(r11, rcx);
1732 1733
1733 __ SmiNot(r9, rcx); 1734 __ SmiNot(r9, rcx);
1734 __ SmiCompare(r9, r8); 1735 __ cmpq(r9, r8);
1735 __ j(not_equal, exit); 1736 __ j(not_equal, exit);
1736 1737
1737 __ incq(rax); 1738 __ incq(rax);
1738 __ SmiCompare(r11, rcx); 1739 __ cmpq(r11, rcx);
1739 __ j(not_equal, exit); 1740 __ j(not_equal, exit);
1740 1741
1741 __ incq(rax); 1742 __ incq(rax);
1742 __ SmiNot(rcx, rcx); 1743 __ SmiNot(rcx, rcx);
1743 __ SmiCompare(rcx, r8); 1744 __ cmpq(rcx, r8);
1744 __ j(not_equal, exit); 1745 __ j(not_equal, exit);
1745 } 1746 }
1746 1747
1747 1748
1748 TEST(SmiNot) { 1749 TEST(SmiNot) {
1749 // Allocate an executable page of memory. 1750 // Allocate an executable page of memory.
1750 size_t actual_size; 1751 size_t actual_size;
1751 byte* buffer = 1752 byte* buffer =
1752 static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, 1753 static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize,
1753 &actual_size, 1754 &actual_size,
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1790 for (int i = 0; i < kNumShifts; i++) { 1791 for (int i = 0; i < kNumShifts; i++) {
1791 // rax == id + i * 10. 1792 // rax == id + i * 10.
1792 int shift = shifts[i]; 1793 int shift = shifts[i];
1793 int result = x << shift; 1794 int result = x << shift;
1794 CHECK(Smi::IsValid(result)); 1795 CHECK(Smi::IsValid(result));
1795 __ Move(r8, Smi::FromInt(result)); 1796 __ Move(r8, Smi::FromInt(result));
1796 __ Move(rcx, Smi::FromInt(x)); 1797 __ Move(rcx, Smi::FromInt(x));
1797 __ SmiShiftLeftConstant(r9, rcx, shift); 1798 __ SmiShiftLeftConstant(r9, rcx, shift);
1798 1799
1799 __ incq(rax); 1800 __ incq(rax);
1800 __ SmiCompare(r9, r8); 1801 __ cmpq(r9, r8);
1801 __ j(not_equal, exit); 1802 __ j(not_equal, exit);
1802 1803
1803 __ incq(rax); 1804 __ incq(rax);
1804 __ Move(rcx, Smi::FromInt(x)); 1805 __ Move(rcx, Smi::FromInt(x));
1805 __ SmiShiftLeftConstant(rcx, rcx, shift); 1806 __ SmiShiftLeftConstant(rcx, rcx, shift);
1806 1807
1807 __ incq(rax); 1808 __ incq(rax);
1808 __ SmiCompare(rcx, r8); 1809 __ cmpq(rcx, r8);
1809 __ j(not_equal, exit); 1810 __ j(not_equal, exit);
1810 1811
1811 __ incq(rax); 1812 __ incq(rax);
1812 __ Move(rdx, Smi::FromInt(x)); 1813 __ Move(rdx, Smi::FromInt(x));
1813 __ Move(rcx, Smi::FromInt(shift)); 1814 __ Move(rcx, Smi::FromInt(shift));
1814 __ SmiShiftLeft(r9, rdx, rcx); 1815 __ SmiShiftLeft(r9, rdx, rcx);
1815 1816
1816 __ incq(rax); 1817 __ incq(rax);
1817 __ SmiCompare(r9, r8); 1818 __ cmpq(r9, r8);
1818 __ j(not_equal, exit); 1819 __ j(not_equal, exit);
1819 1820
1820 __ incq(rax); 1821 __ incq(rax);
1821 __ Move(rdx, Smi::FromInt(x)); 1822 __ Move(rdx, Smi::FromInt(x));
1822 __ Move(r11, Smi::FromInt(shift)); 1823 __ Move(r11, Smi::FromInt(shift));
1823 __ SmiShiftLeft(r9, rdx, r11); 1824 __ SmiShiftLeft(r9, rdx, r11);
1824 1825
1825 __ incq(rax); 1826 __ incq(rax);
1826 __ SmiCompare(r9, r8); 1827 __ cmpq(r9, r8);
1827 __ j(not_equal, exit); 1828 __ j(not_equal, exit);
1828 1829
1829 __ incq(rax); 1830 __ incq(rax);
1830 __ Move(rdx, Smi::FromInt(x)); 1831 __ Move(rdx, Smi::FromInt(x));
1831 __ Move(r11, Smi::FromInt(shift)); 1832 __ Move(r11, Smi::FromInt(shift));
1832 __ SmiShiftLeft(rdx, rdx, r11); 1833 __ SmiShiftLeft(rdx, rdx, r11);
1833 1834
1834 __ incq(rax); 1835 __ incq(rax);
1835 __ SmiCompare(rdx, r8); 1836 __ cmpq(rdx, r8);
1836 __ j(not_equal, exit); 1837 __ j(not_equal, exit);
1837 1838
1838 __ incq(rax); 1839 __ incq(rax);
1839 } 1840 }
1840 } 1841 }
1841 1842
1842 1843
1843 TEST(SmiShiftLeft) { 1844 TEST(SmiShiftLeft) {
1844 // Allocate an executable page of memory. 1845 // Allocate an executable page of memory.
1845 size_t actual_size; 1846 size_t actual_size;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1886 __ movl(rax, Immediate(id)); 1887 __ movl(rax, Immediate(id));
1887 for (int i = 0; i < kNumShifts; i++) { 1888 for (int i = 0; i < kNumShifts; i++) {
1888 int shift = shifts[i]; 1889 int shift = shifts[i];
1889 intptr_t result = static_cast<unsigned int>(x) >> shift; 1890 intptr_t result = static_cast<unsigned int>(x) >> shift;
1890 if (Smi::IsValid(result)) { 1891 if (Smi::IsValid(result)) {
1891 __ Move(r8, Smi::FromInt(static_cast<int>(result))); 1892 __ Move(r8, Smi::FromInt(static_cast<int>(result)));
1892 __ Move(rcx, Smi::FromInt(x)); 1893 __ Move(rcx, Smi::FromInt(x));
1893 __ SmiShiftLogicalRightConstant(r9, rcx, shift, exit); 1894 __ SmiShiftLogicalRightConstant(r9, rcx, shift, exit);
1894 1895
1895 __ incq(rax); 1896 __ incq(rax);
1896 __ SmiCompare(r9, r8); 1897 __ cmpq(r9, r8);
1897 __ j(not_equal, exit); 1898 __ j(not_equal, exit);
1898 1899
1899 __ incq(rax); 1900 __ incq(rax);
1900 __ Move(rdx, Smi::FromInt(x)); 1901 __ Move(rdx, Smi::FromInt(x));
1901 __ Move(rcx, Smi::FromInt(shift)); 1902 __ Move(rcx, Smi::FromInt(shift));
1902 __ SmiShiftLogicalRight(r9, rdx, rcx, exit); 1903 __ SmiShiftLogicalRight(r9, rdx, rcx, exit);
1903 1904
1904 __ incq(rax); 1905 __ incq(rax);
1905 __ SmiCompare(r9, r8); 1906 __ cmpq(r9, r8);
1906 __ j(not_equal, exit); 1907 __ j(not_equal, exit);
1907 1908
1908 __ incq(rax); 1909 __ incq(rax);
1909 __ Move(rdx, Smi::FromInt(x)); 1910 __ Move(rdx, Smi::FromInt(x));
1910 __ Move(r11, Smi::FromInt(shift)); 1911 __ Move(r11, Smi::FromInt(shift));
1911 __ SmiShiftLogicalRight(r9, rdx, r11, exit); 1912 __ SmiShiftLogicalRight(r9, rdx, r11, exit);
1912 1913
1913 __ incq(rax); 1914 __ incq(rax);
1914 __ SmiCompare(r9, r8); 1915 __ cmpq(r9, r8);
1915 __ j(not_equal, exit); 1916 __ j(not_equal, exit);
1916 1917
1917 __ incq(rax); 1918 __ incq(rax);
1918 } else { 1919 } else {
1919 // Cannot happen with long smis. 1920 // Cannot happen with long smis.
1920 Label fail_ok; 1921 Label fail_ok;
1921 __ Move(rcx, Smi::FromInt(x)); 1922 __ Move(rcx, Smi::FromInt(x));
1922 __ movq(r11, rcx); 1923 __ movq(r11, rcx);
1923 __ SmiShiftLogicalRightConstant(r9, rcx, shift, &fail_ok); 1924 __ SmiShiftLogicalRightConstant(r9, rcx, shift, &fail_ok);
1924 __ jmp(exit); 1925 __ jmp(exit);
1925 __ bind(&fail_ok); 1926 __ bind(&fail_ok);
1926 1927
1927 __ incq(rax); 1928 __ incq(rax);
1928 __ SmiCompare(rcx, r11); 1929 __ cmpq(rcx, r11);
1929 __ j(not_equal, exit); 1930 __ j(not_equal, exit);
1930 1931
1931 __ incq(rax); 1932 __ incq(rax);
1932 __ Move(r8, Smi::FromInt(shift)); 1933 __ Move(r8, Smi::FromInt(shift));
1933 Label fail_ok3; 1934 Label fail_ok3;
1934 __ SmiShiftLogicalRight(r9, rcx, r8, &fail_ok3); 1935 __ SmiShiftLogicalRight(r9, rcx, r8, &fail_ok3);
1935 __ jmp(exit); 1936 __ jmp(exit);
1936 __ bind(&fail_ok3); 1937 __ bind(&fail_ok3);
1937 1938
1938 __ incq(rax); 1939 __ incq(rax);
1939 __ SmiCompare(rcx, r11); 1940 __ cmpq(rcx, r11);
1940 __ j(not_equal, exit); 1941 __ j(not_equal, exit);
1941 1942
1942 __ addq(rax, Immediate(3)); 1943 __ addq(rax, Immediate(3));
1943 } 1944 }
1944 } 1945 }
1945 } 1946 }
1946 1947
1947 1948
1948 TEST(SmiShiftLogicalRight) { 1949 TEST(SmiShiftLogicalRight) {
1949 // Allocate an executable page of memory. 1950 // Allocate an executable page of memory.
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1990 const int kNumShifts = 5; 1991 const int kNumShifts = 5;
1991 __ movl(rax, Immediate(id)); 1992 __ movl(rax, Immediate(id));
1992 for (int i = 0; i < kNumShifts; i++) { 1993 for (int i = 0; i < kNumShifts; i++) {
1993 int shift = shifts[i]; 1994 int shift = shifts[i];
1994 // Guaranteed arithmetic shift. 1995 // Guaranteed arithmetic shift.
1995 int result = (x < 0) ? ~((~x) >> shift) : (x >> shift); 1996 int result = (x < 0) ? ~((~x) >> shift) : (x >> shift);
1996 __ Move(r8, Smi::FromInt(result)); 1997 __ Move(r8, Smi::FromInt(result));
1997 __ Move(rcx, Smi::FromInt(x)); 1998 __ Move(rcx, Smi::FromInt(x));
1998 __ SmiShiftArithmeticRightConstant(rcx, rcx, shift); 1999 __ SmiShiftArithmeticRightConstant(rcx, rcx, shift);
1999 2000
2000 __ SmiCompare(rcx, r8); 2001 __ cmpq(rcx, r8);
2001 __ j(not_equal, exit); 2002 __ j(not_equal, exit);
2002 2003
2003 __ incq(rax); 2004 __ incq(rax);
2004 __ Move(rdx, Smi::FromInt(x)); 2005 __ Move(rdx, Smi::FromInt(x));
2005 __ Move(r11, Smi::FromInt(shift)); 2006 __ Move(r11, Smi::FromInt(shift));
2006 __ SmiShiftArithmeticRight(rdx, rdx, r11); 2007 __ SmiShiftArithmeticRight(rdx, rdx, r11);
2007 2008
2008 __ SmiCompare(rdx, r8); 2009 __ cmpq(rdx, r8);
2009 __ j(not_equal, exit); 2010 __ j(not_equal, exit);
2010 2011
2011 __ incq(rax); 2012 __ incq(rax);
2012 } 2013 }
2013 } 2014 }
2014 2015
2015 2016
2016 TEST(SmiShiftArithmeticRight) { 2017 TEST(SmiShiftArithmeticRight) {
2017 // Allocate an executable page of memory. 2018 // Allocate an executable page of memory.
2018 size_t actual_size; 2019 size_t actual_size;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
2055 int powers[] = { 0, 1, 2, 3, 8, 16, 24, 31 }; 2056 int powers[] = { 0, 1, 2, 3, 8, 16, 24, 31 };
2056 int power_count = 8; 2057 int power_count = 8;
2057 __ movl(rax, Immediate(id)); 2058 __ movl(rax, Immediate(id));
2058 for (int i = 0; i < power_count; i++) { 2059 for (int i = 0; i < power_count; i++) {
2059 int power = powers[i]; 2060 int power = powers[i];
2060 intptr_t result = static_cast<intptr_t>(x) << power; 2061 intptr_t result = static_cast<intptr_t>(x) << power;
2061 __ Set(r8, result); 2062 __ Set(r8, result);
2062 __ Move(rcx, Smi::FromInt(x)); 2063 __ Move(rcx, Smi::FromInt(x));
2063 __ movq(r11, rcx); 2064 __ movq(r11, rcx);
2064 __ PositiveSmiTimesPowerOfTwoToInteger64(rdx, rcx, power); 2065 __ PositiveSmiTimesPowerOfTwoToInteger64(rdx, rcx, power);
2065 __ SmiCompare(rdx, r8); 2066 __ cmpq(rdx, r8);
2066 __ j(not_equal, exit); 2067 __ j(not_equal, exit);
2067 __ incq(rax); 2068 __ incq(rax);
2068 __ SmiCompare(r11, rcx); // rcx unchanged. 2069 __ cmpq(r11, rcx); // rcx unchanged.
2069 __ j(not_equal, exit); 2070 __ j(not_equal, exit);
2070 __ incq(rax); 2071 __ incq(rax);
2071 __ PositiveSmiTimesPowerOfTwoToInteger64(rcx, rcx, power); 2072 __ PositiveSmiTimesPowerOfTwoToInteger64(rcx, rcx, power);
2072 __ SmiCompare(rdx, r8); 2073 __ cmpq(rdx, r8);
2073 __ j(not_equal, exit); 2074 __ j(not_equal, exit);
2074 __ incq(rax); 2075 __ incq(rax);
2075 } 2076 }
2076 } 2077 }
2077 2078
2078 2079
2079 TEST(PositiveSmiTimesPowerOfTwoToInteger64) { 2080 TEST(PositiveSmiTimesPowerOfTwoToInteger64) {
2081 v8::V8::Initialize();
2080 // Allocate an executable page of memory. 2082 // Allocate an executable page of memory.
2081 size_t actual_size; 2083 size_t actual_size;
2082 byte* buffer = 2084 byte* buffer =
2083 static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize * 2, 2085 static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize * 4,
2084 &actual_size, 2086 &actual_size,
2085 true)); 2087 true));
2086 CHECK(buffer); 2088 CHECK(buffer);
2087 HandleScope handles; 2089 HandleScope handles;
2088 MacroAssembler assembler(buffer, static_cast<int>(actual_size)); 2090 MacroAssembler assembler(buffer, static_cast<int>(actual_size));
2089 2091
2090 MacroAssembler* masm = &assembler; 2092 MacroAssembler* masm = &assembler;
2091 masm->set_allow_stub_calls(false); 2093 masm->set_allow_stub_calls(false);
2092 EntryCode(masm); 2094 EntryCode(masm);
2093 Label exit; 2095 Label exit;
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
2465 CodeDesc desc; 2467 CodeDesc desc;
2466 masm->GetCode(&desc); 2468 masm->GetCode(&desc);
2467 // Call the function from C++. 2469 // Call the function from C++.
2468 int result = FUNCTION_CAST<F0>(buffer)(); 2470 int result = FUNCTION_CAST<F0>(buffer)();
2469 CHECK_EQ(0, result); 2471 CHECK_EQ(0, result);
2470 } 2472 }
2471 2473
2472 2474
2473 2475
2474 #undef __ 2476 #undef __
OLDNEW
« src/x64/macro-assembler-x64.cc ('K') | « src/x64/macro-assembler-x64.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698