| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 // | 4 // |
| 5 // The intrinsic code below is executed before a method has built its frame. | 5 // The intrinsic code below is executed before a method has built its frame. |
| 6 // The return address is on the stack and the arguments below it. | 6 // The return address is on the stack and the arguments below it. |
| 7 // Registers EDX (arguments descriptor) and ECX (function) must be preserved. | 7 // Registers EDX (arguments descriptor) and ECX (function) must be preserved. |
| 8 // Each intrinsification method returns true if the corresponding | 8 // Each intrinsification method returns true if the corresponding |
| 9 // Dart method was intrinsified. | 9 // Dart method was intrinsified. |
| 10 | 10 |
| (...skipping 898 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 909 __ StoreIntoObject(ECX, | 909 __ StoreIntoObject(ECX, |
| 910 FieldAddress(ECX, Bigint::digits_offset()), EAX, false); | 910 FieldAddress(ECX, Bigint::digits_offset()), EAX, false); |
| 911 __ ret(); | 911 __ ret(); |
| 912 } | 912 } |
| 913 | 913 |
| 914 | 914 |
| 915 // TODO(regis): Once this intrinsic is implemented on all architectures, the | 915 // TODO(regis): Once this intrinsic is implemented on all architectures, the |
| 916 // corresponding Dart method will be untested. Add a test with --no-intrinsify. | 916 // corresponding Dart method will be untested. Add a test with --no-intrinsify. |
| 917 void Intrinsifier::Bigint_mulAdd(Assembler* assembler) { | 917 void Intrinsifier::Bigint_mulAdd(Assembler* assembler) { |
| 918 // Pseudo code: | 918 // Pseudo code: |
| 919 // static void _mulAdd(Uint32List args, | 919 // static void _mulAdd(Uint32List x_digits, int xi, |
| 920 // Uint32List m_digits, int i, | 920 // Uint32List m_digits, int i, |
| 921 // Uint32List a_digits, int j, int n) { | 921 // Uint32List a_digits, int j, int n) { |
| 922 // uint32_t x = args[MA_MULTIPLIER]; | 922 // uint32_t x = x_digits[xi]; |
| 923 // if (x == 0) { | 923 // if (x == 0 || n == 0) { |
| 924 // args[MA_CARRY_OUT] = 0; | |
| 925 // return; | 924 // return; |
| 926 // } | 925 // } |
| 927 // uint32_t* mip = &m_digits[i >> 1]; // i is Smi. | 926 // uint32_t* mip = &m_digits[i >> 1]; // i is Smi. |
| 928 // uint32_t* ajp = &a_digits[j >> 1]; // j is Smi. | 927 // uint32_t* ajp = &a_digits[j >> 1]; // j is Smi. |
| 929 // uint32_t c = 0; | 928 // uint32_t c = 0; |
| 930 // SmiUntag(n); | 929 // SmiUntag(n); |
| 931 // while (--n >= 0) { | 930 // do { |
| 932 // uint32_t mi = *mip++; | 931 // uint32_t mi = *mip++; |
| 933 // uint32_t aj = *ajp; | 932 // uint32_t aj = *ajp; |
| 934 // uint64_t t = x*mi + aj + c; // 32-bit * 32-bit -> 64-bit. | 933 // uint64_t t = x*mi + aj + c; // 32-bit * 32-bit -> 64-bit. |
| 935 // *ajp++ = low32(t); | 934 // *ajp++ = low32(t); |
| 936 // c = high32(t); | 935 // c = high32(t); |
| 936 // } while (--n > 0); |
| 937 // while (c != 0) { |
| 938 // uint64_t t = *ajp + c; |
| 939 // *ajp++ = low32(t); |
| 940 // c = high32(t); // c == 0 or 1. |
| 937 // } | 941 // } |
| 938 // args[MA_CARRY_OUT] = c; | |
| 939 // } | 942 // } |
| 940 | 943 |
| 941 // EBX = x | 944 Label no_op; |
| 942 Label x_not_zero; | 945 // EBX = x, no_op if x == 0 |
| 943 __ movl(ECX, Address(ESP, 6 * kWordSize)); // args | 946 __ movl(ECX, Address(ESP, 7 * kWordSize)); // x_digits |
| 944 __ movl(EBX, FieldAddress(ECX, TypedData::data_offset())); // x | 947 __ movl(EAX, Address(ESP, 6 * kWordSize)); // xi is Smi |
| 945 __ cmpl(EBX, Immediate(0)); | 948 __ movl(EBX, FieldAddress(ECX, EAX, TIMES_2, TypedData::data_offset())); |
| 946 __ j(NOT_EQUAL, &x_not_zero, Assembler::kNearJump); | 949 __ testl(EBX, EBX); |
| 947 // Set args[MA_CARRY_OUT] to 0 and return. | 950 __ j(ZERO, &no_op, Assembler::kNearJump); |
| 948 __ movl(FieldAddress(ECX, TypedData::data_offset() + kWordSize), EBX); | 951 |
| 949 // TODO(regis): Confirm that returning Object::null() is not required. | 952 // EDX = SmiUntag(n), no_op if n == 0 |
| 950 __ ret(); | 953 __ movl(EDX, Address(ESP, 1 * kWordSize)); |
| 951 __ Bind(&x_not_zero); | 954 __ SmiUntag(EDX); |
| 955 __ j(ZERO, &no_op, Assembler::kNearJump); |
| 952 | 956 |
| 953 // Preserve CTX to free ESI. | 957 // Preserve CTX to free ESI. |
| 954 __ pushl(CTX); | 958 __ pushl(CTX); |
| 955 ASSERT(CTX == ESI); | 959 ASSERT(CTX == ESI); |
| 956 | 960 |
| 957 // EDI = mip = &m_digits[i >> 1] | 961 // EDI = mip = &m_digits[i >> 1] |
| 958 __ movl(EDI, Address(ESP, 6 * kWordSize)); // m_digits | 962 __ movl(EDI, Address(ESP, 6 * kWordSize)); // m_digits |
| 959 __ movl(EAX, Address(ESP, 5 * kWordSize)); // i is Smi | 963 __ movl(EAX, Address(ESP, 5 * kWordSize)); // i is Smi |
| 960 __ leal(EDI, FieldAddress(EDI, EAX, TIMES_2, TypedData::data_offset())); | 964 __ leal(EDI, FieldAddress(EDI, EAX, TIMES_2, TypedData::data_offset())); |
| 961 | 965 |
| 962 // ESI = ajp = &a_digits[j >> 1] | 966 // ESI = ajp = &a_digits[j >> 1] |
| 963 __ movl(ESI, Address(ESP, 4 * kWordSize)); // a_digits | 967 __ movl(ESI, Address(ESP, 4 * kWordSize)); // a_digits |
| 964 __ movl(EAX, Address(ESP, 3 * kWordSize)); // j is Smi | 968 __ movl(EAX, Address(ESP, 3 * kWordSize)); // j is Smi |
| 965 __ leal(ESI, FieldAddress(ESI, EAX, TIMES_2, TypedData::data_offset())); | 969 __ leal(ESI, FieldAddress(ESI, EAX, TIMES_2, TypedData::data_offset())); |
| 966 | 970 |
| 971 // Save n |
| 972 __ pushl(EDX); |
| 973 Address n_addr = Address(ESP, 0 * kWordSize); |
| 974 |
| 967 // ECX = c = 0 | 975 // ECX = c = 0 |
| 968 __ xorl(ECX, ECX); | 976 __ xorl(ECX, ECX); |
| 969 | 977 |
| 970 // SmiUntag(n), 'sar mem32, 1' not implemented | 978 Label muladd_loop; |
| 971 __ movl(EAX, Address(ESP, 2 * kWordSize)); | 979 __ Bind(&muladd_loop); |
| 972 __ SmiUntag(EAX); | |
| 973 __ pushl(EAX); | |
| 974 Address n_addr = Address(ESP, 0 * kWordSize); | |
| 975 | |
| 976 Label loop, done; | |
| 977 __ Bind(&loop); | |
| 978 // x: EBX | 980 // x: EBX |
| 979 // mip: EDI | 981 // mip: EDI |
| 980 // ajp: ESI | 982 // ajp: ESI |
| 981 // c: ECX | 983 // c: ECX |
| 982 // t: EDX:EAX (not live at loop entry) | 984 // t: EDX:EAX (not live at loop entry) |
| 983 // n: ESP[0] | 985 // n: ESP[0] |
| 984 | 986 |
| 985 // while (--n >= 0) | |
| 986 __ decl(n_addr); // --n | |
| 987 __ j(NEGATIVE, &done); | |
| 988 | |
| 989 // uint32_t mi = *mip++ | 987 // uint32_t mi = *mip++ |
| 990 __ movl(EAX, Address(EDI, 0)); | 988 __ movl(EAX, Address(EDI, 0)); |
| 991 __ addl(EDI, Immediate(kWordSize)); | 989 __ addl(EDI, Immediate(kWordSize)); |
| 992 | 990 |
| 993 // uint64_t t = x*mi | 991 // uint64_t t = x*mi |
| 994 __ mull(EBX); // t = EDX:EAX = EAX * EBX | 992 __ mull(EBX); // t = EDX:EAX = EAX * EBX |
| 995 __ addl(EAX, ECX); // t += c | 993 __ addl(EAX, ECX); // t += c |
| 996 __ adcl(EDX, Immediate(0)); | 994 __ adcl(EDX, Immediate(0)); |
| 997 | 995 |
| 998 // uint32_t aj = *ajp; t += aj | 996 // uint32_t aj = *ajp; t += aj |
| 999 __ addl(EAX, Address(ESI, 0)); | 997 __ addl(EAX, Address(ESI, 0)); |
| 1000 __ adcl(EDX, Immediate(0)); | 998 __ adcl(EDX, Immediate(0)); |
| 1001 | 999 |
| 1002 // *ajp++ = low32(t) | 1000 // *ajp++ = low32(t) |
| 1003 __ movl(Address(ESI, 0), EAX); | 1001 __ movl(Address(ESI, 0), EAX); |
| 1004 __ addl(ESI, Immediate(kWordSize)); | 1002 __ addl(ESI, Immediate(kWordSize)); |
| 1005 | 1003 |
| 1006 // c = high32(t) | 1004 // c = high32(t) |
| 1007 __ movl(ECX, EDX); | 1005 __ movl(ECX, EDX); |
| 1008 __ jmp(&loop, Assembler::kNearJump); | 1006 |
| 1007 // while (--n > 0) |
| 1008 __ decl(n_addr); // --n |
| 1009 __ j(NOT_ZERO, &muladd_loop, Assembler::kNearJump); |
| 1010 |
| 1011 Label done; |
| 1012 __ testl(ECX, ECX); |
| 1013 __ j(ZERO, &done); |
| 1014 |
| 1015 // *ajp += c |
| 1016 __ addl(Address(ESI, 0), ECX); |
| 1017 __ j(NOT_CARRY, &done, Assembler::kNearJump); |
| 1018 |
| 1019 Label propagate_carry_loop; |
| 1020 __ Bind(&propagate_carry_loop); |
| 1021 __ addl(ESI, Immediate(kWordSize)); |
| 1022 __ incl(Address(ESI, 0)); // c == 0 or 1 |
| 1023 __ j(CARRY, &propagate_carry_loop, Assembler::kNearJump); |
| 1009 | 1024 |
| 1010 __ Bind(&done); | 1025 __ Bind(&done); |
| 1011 __ Drop(1); // n | 1026 __ Drop(1); // n |
| 1012 // Restore CTX, set args[MA_CARRY_OUT] to c and return. | 1027 // Restore CTX and return. |
| 1013 __ popl(CTX); | 1028 __ popl(CTX); |
| 1014 __ movl(EAX, Address(ESP, 6 * kWordSize)); // args | 1029 |
| 1015 __ movl(FieldAddress(EAX, TypedData::data_offset() + kWordSize), ECX); | 1030 __ Bind(&no_op); |
| 1016 // TODO(regis): Confirm that returning Object::null() is not required. | 1031 // TODO(regis): Confirm that returning Object::null() is not required. |
| 1017 __ ret(); | 1032 __ ret(); |
| 1018 } | 1033 } |
| 1019 | 1034 |
| 1020 | 1035 |
| 1021 // TODO(regis): Once this intrinsic is implemented on all architectures, the | 1036 // TODO(regis): Once this intrinsic is implemented on all architectures, the |
| 1022 // corresponding Dart method will be untested. Add a test with --no-intrinsify. | 1037 // corresponding Dart method will be untested. Add a test with --no-intrinsify. |
| 1023 void Intrinsifier::Bigint_sqrAdd(Assembler* assembler) { | 1038 void Intrinsifier::Bigint_sqrAdd(Assembler* assembler) { |
| 1024 // Pseudo code: | 1039 // Pseudo code: |
| 1025 // static void _sqrAdd(Uint32List x_digits, int i, | 1040 // static void _sqrAdd(Uint32List x_digits, int i, |
| (...skipping 858 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1884 Isolate::current_tag_offset()); | 1899 Isolate::current_tag_offset()); |
| 1885 // Set return value to Isolate::current_tag_. | 1900 // Set return value to Isolate::current_tag_. |
| 1886 __ movl(EAX, current_tag_addr); | 1901 __ movl(EAX, current_tag_addr); |
| 1887 __ ret(); | 1902 __ ret(); |
| 1888 } | 1903 } |
| 1889 | 1904 |
| 1890 #undef __ | 1905 #undef __ |
| 1891 } // namespace dart | 1906 } // namespace dart |
| 1892 | 1907 |
| 1893 #endif // defined TARGET_ARCH_IA32 | 1908 #endif // defined TARGET_ARCH_IA32 |
| OLD | NEW |