OLD | NEW |
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 868 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
879 __ SmiSubConstant(r9, rcx, Smi::FromInt(second), exit); | 879 __ SmiSubConstant(r9, rcx, Smi::FromInt(second), exit); |
880 __ cmpq(r9, r8); | 880 __ cmpq(r9, r8); |
881 __ j(not_equal, exit); | 881 __ j(not_equal, exit); |
882 | 882 |
883 __ incq(rax); // Test 5. | 883 __ incq(rax); // Test 5. |
884 __ SmiSubConstant(rcx, rcx, Smi::FromInt(second), exit); | 884 __ SmiSubConstant(rcx, rcx, Smi::FromInt(second), exit); |
885 __ cmpq(rcx, r8); | 885 __ cmpq(rcx, r8); |
886 __ j(not_equal, exit); | 886 __ j(not_equal, exit); |
887 } | 887 } |
888 | 888 |
| 889 |
889 static void SmiSubOverflowTest(MacroAssembler* masm, | 890 static void SmiSubOverflowTest(MacroAssembler* masm, |
890 Label* exit, | 891 Label* exit, |
891 int id, | 892 int id, |
892 int x) { | 893 int x) { |
893 // Subtracts a Smi from x so that the subtraction overflows. | 894 // Subtracts a Smi from x so that the subtraction overflows. |
894 ASSERT(x != -1); // Can't overflow by subtracting a Smi. | 895 ASSERT(x != -1); // Can't overflow by subtracting a Smi. |
895 int y_max = (x < 0) ? (Smi::kMaxValue + 0) : (Smi::kMinValue + 0); | 896 int y_max = (x < 0) ? (Smi::kMaxValue + 0) : (Smi::kMinValue + 0); |
896 int y_min = (x < 0) ? (Smi::kMaxValue + x + 2) : (Smi::kMinValue + x); | 897 int y_min = (x < 0) ? (Smi::kMaxValue + x + 2) : (Smi::kMinValue + x); |
897 | 898 |
898 __ movl(rax, Immediate(id)); | 899 __ movl(rax, Immediate(id)); |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1034 __ ret(0); | 1035 __ ret(0); |
1035 | 1036 |
1036 CodeDesc desc; | 1037 CodeDesc desc; |
1037 masm->GetCode(&desc); | 1038 masm->GetCode(&desc); |
1038 // Call the function from C++. | 1039 // Call the function from C++. |
1039 int result = FUNCTION_CAST<F0>(buffer)(); | 1040 int result = FUNCTION_CAST<F0>(buffer)(); |
1040 CHECK_EQ(0, result); | 1041 CHECK_EQ(0, result); |
1041 } | 1042 } |
1042 | 1043 |
1043 | 1044 |
1044 | |
1045 void TestSmiMul(MacroAssembler* masm, Label* exit, int id, int x, int y) { | 1045 void TestSmiMul(MacroAssembler* masm, Label* exit, int id, int x, int y) { |
1046 int64_t result = static_cast<int64_t>(x) * static_cast<int64_t>(y); | 1046 int64_t result = static_cast<int64_t>(x) * static_cast<int64_t>(y); |
1047 bool negative_zero = (result == 0) && (x < 0 || y < 0); | 1047 bool negative_zero = (result == 0) && (x < 0 || y < 0); |
1048 __ Move(rcx, Smi::FromInt(x)); | 1048 __ Move(rcx, Smi::FromInt(x)); |
1049 __ movq(r11, rcx); | 1049 __ movq(r11, rcx); |
1050 __ Move(rdx, Smi::FromInt(y)); | 1050 __ Move(rdx, Smi::FromInt(y)); |
1051 if (Smi::IsValid(result) && !negative_zero) { | 1051 if (Smi::IsValid(result) && !negative_zero) { |
1052 __ movl(rax, Immediate(id)); | 1052 __ movl(rax, Immediate(id)); |
1053 __ Move(r8, Smi::FromIntptr(result)); | 1053 __ Move(r8, Smi::FromIntptr(result)); |
1054 __ SmiMul(r9, rcx, rdx, exit); | 1054 __ SmiMul(r9, rcx, rdx, exit); |
(...skipping 769 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1824 | 1824 |
1825 | 1825 |
1826 void TestSmiShiftLeft(MacroAssembler* masm, Label* exit, int id, int x) { | 1826 void TestSmiShiftLeft(MacroAssembler* masm, Label* exit, int id, int x) { |
1827 const int shifts[] = { 0, 1, 7, 24, kSmiValueSize - 1}; | 1827 const int shifts[] = { 0, 1, 7, 24, kSmiValueSize - 1}; |
1828 const int kNumShifts = 5; | 1828 const int kNumShifts = 5; |
1829 __ movl(rax, Immediate(id)); | 1829 __ movl(rax, Immediate(id)); |
1830 for (int i = 0; i < kNumShifts; i++) { | 1830 for (int i = 0; i < kNumShifts; i++) { |
1831 // rax == id + i * 10. | 1831 // rax == id + i * 10. |
1832 int shift = shifts[i]; | 1832 int shift = shifts[i]; |
1833 int result = x << shift; | 1833 int result = x << shift; |
1834 CHECK(Smi::IsValid(result)); | 1834 if (Smi::IsValid(result)) { |
1835 __ Move(r8, Smi::FromInt(result)); | 1835 __ Move(r8, Smi::FromInt(result)); |
1836 __ Move(rcx, Smi::FromInt(x)); | 1836 __ Move(rcx, Smi::FromInt(x)); |
1837 __ SmiShiftLeftConstant(r9, rcx, shift); | 1837 __ SmiShiftLeftConstant(r9, rcx, shift, exit); |
1838 | 1838 |
1839 __ incq(rax); | 1839 __ incq(rax); |
1840 __ cmpq(r9, r8); | 1840 __ cmpq(r9, r8); |
1841 __ j(not_equal, exit); | 1841 __ j(not_equal, exit); |
1842 | 1842 |
1843 __ incq(rax); | 1843 __ incq(rax); |
1844 __ Move(rcx, Smi::FromInt(x)); | 1844 __ Move(rcx, Smi::FromInt(x)); |
1845 __ SmiShiftLeftConstant(rcx, rcx, shift); | 1845 __ SmiShiftLeftConstant(rcx, rcx, shift, exit); |
1846 | 1846 |
1847 __ incq(rax); | 1847 __ incq(rax); |
1848 __ cmpq(rcx, r8); | 1848 __ cmpq(rcx, r8); |
1849 __ j(not_equal, exit); | 1849 __ j(not_equal, exit); |
1850 | 1850 |
1851 __ incq(rax); | 1851 __ incq(rax); |
1852 __ Move(rdx, Smi::FromInt(x)); | 1852 __ Move(rdx, Smi::FromInt(x)); |
1853 __ Move(rcx, Smi::FromInt(shift)); | 1853 __ Move(rcx, Smi::FromInt(shift)); |
1854 __ SmiShiftLeft(r9, rdx, rcx); | 1854 __ SmiShiftLeft(r9, rdx, rcx, exit); |
1855 | 1855 |
1856 __ incq(rax); | 1856 __ incq(rax); |
1857 __ cmpq(r9, r8); | 1857 __ cmpq(r9, r8); |
1858 __ j(not_equal, exit); | 1858 __ j(not_equal, exit); |
1859 | 1859 |
1860 __ incq(rax); | 1860 __ incq(rax); |
1861 __ Move(rdx, Smi::FromInt(x)); | 1861 __ Move(rdx, Smi::FromInt(x)); |
1862 __ Move(r11, Smi::FromInt(shift)); | 1862 __ Move(r11, Smi::FromInt(shift)); |
1863 __ SmiShiftLeft(r9, rdx, r11); | 1863 __ SmiShiftLeft(r9, rdx, r11, exit); |
1864 | 1864 |
1865 __ incq(rax); | 1865 __ incq(rax); |
1866 __ cmpq(r9, r8); | 1866 __ cmpq(r9, r8); |
1867 __ j(not_equal, exit); | 1867 __ j(not_equal, exit); |
1868 | 1868 |
1869 __ incq(rax); | 1869 __ incq(rax); |
1870 __ Move(rdx, Smi::FromInt(x)); | 1870 __ Move(rdx, Smi::FromInt(x)); |
1871 __ Move(r11, Smi::FromInt(shift)); | 1871 __ Move(r11, Smi::FromInt(shift)); |
1872 __ SmiShiftLeft(rdx, rdx, r11); | 1872 __ SmiShiftLeft(rdx, rdx, r11, exit); |
1873 | 1873 |
1874 __ incq(rax); | 1874 __ incq(rax); |
1875 __ cmpq(rdx, r8); | 1875 __ cmpq(rdx, r8); |
1876 __ j(not_equal, exit); | 1876 __ j(not_equal, exit); |
1877 | 1877 |
1878 __ incq(rax); | 1878 __ incq(rax); |
| 1879 } else { |
| 1880 __ Move(rdx, Smi::FromInt(x)); |
| 1881 __ Move(rcx, Smi::FromInt(shift)); |
| 1882 __ movq(r11, rcx); |
| 1883 Label fail_ok1; |
| 1884 __ SmiShiftLeft(r9, rdx, rcx, &fail_ok1); |
| 1885 __ jmp(exit); |
| 1886 __ bind(&fail_ok1); |
| 1887 |
| 1888 __ incq(rax); |
| 1889 __ cmpq(rcx, r11); |
| 1890 __ j(not_equal, exit); |
| 1891 |
| 1892 __ incq(rax); |
| 1893 __ Move(rcx, Smi::FromInt(x)); |
| 1894 __ Move(rdx, Smi::FromInt(shift)); |
| 1895 __ movq(r11, rcx); |
| 1896 Label fail_ok2; |
| 1897 __ SmiShiftLeft(r9, rcx, rdx, &fail_ok2); |
| 1898 __ jmp(exit); |
| 1899 __ bind(&fail_ok2); |
| 1900 |
| 1901 __ incq(rax); |
| 1902 __ cmpq(rcx, r11); |
| 1903 __ j(not_equal, exit); |
| 1904 |
| 1905 __ addq(rax, Immediate(7)); |
| 1906 } |
1879 } | 1907 } |
1880 } | 1908 } |
1881 | 1909 |
1882 | 1910 |
1883 TEST(SmiShiftLeft) { | 1911 TEST(SmiShiftLeft) { |
1884 v8::internal::V8::Initialize(NULL); | 1912 v8::internal::V8::Initialize(NULL); |
1885 // Allocate an executable page of memory. | 1913 // Allocate an executable page of memory. |
1886 size_t actual_size; | 1914 size_t actual_size; |
1887 byte* buffer = | 1915 byte* buffer = |
1888 static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize * 4, | 1916 static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize * 4, |
(...skipping 626 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2515 CodeDesc desc; | 2543 CodeDesc desc; |
2516 masm->GetCode(&desc); | 2544 masm->GetCode(&desc); |
2517 // Call the function from C++. | 2545 // Call the function from C++. |
2518 int result = FUNCTION_CAST<F0>(buffer)(); | 2546 int result = FUNCTION_CAST<F0>(buffer)(); |
2519 CHECK_EQ(0, result); | 2547 CHECK_EQ(0, result); |
2520 } | 2548 } |
2521 | 2549 |
2522 | 2550 |
2523 | 2551 |
2524 #undef __ | 2552 #undef __ |
OLD | NEW |