| 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 894 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 905 | 905 |
| 906 void Intrinsifier::Bigint_setDigits(Assembler* assembler) { | 906 void Intrinsifier::Bigint_setDigits(Assembler* assembler) { |
| 907 __ movl(EAX, Address(ESP, + 1 * kWordSize)); | 907 __ movl(EAX, Address(ESP, + 1 * kWordSize)); |
| 908 __ movl(ECX, Address(ESP, + 2 * kWordSize)); | 908 __ movl(ECX, Address(ESP, + 2 * kWordSize)); |
| 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 |
| 916 // corresponding Dart method will be untested. Add a test with --no-intrinsify. |
| 917 void Intrinsifier::Bigint_mulAdd(Assembler* assembler) { |
| 918 // Pseudo code: |
| 919 // static void _mulAdd(Uint32List args, |
| 920 // Uint32List m_digits, int i, |
| 921 // Uint32List a_digits, int j, int n) { |
| 922 // uint32_t x = args[MA_MULTIPLIER]; |
| 923 // if (x == 0) { |
| 924 // args[MA_CARRY_OUT] = 0; |
| 925 // return; |
| 926 // } |
| 927 // uint32_t* mip = &m_digits[i >> 1]; // i is Smi. |
| 928 // uint32_t* ajp = &a_digits[j >> 1]; // j is Smi. |
| 929 // uint32_t c = 0; |
| 930 // while ((n -= 2) >= 0) { // n is Smi. |
| 931 // uint32_t mi = *mip++; |
| 932 // uint32_t aj = *ajp; |
| 933 // uint64_t t = x*mi + aj + c; // 32-bit * 32-bit -> 64-bit. |
| 934 // *ajp++ = low32(t); |
| 935 // c = high32(t); |
| 936 // } |
| 937 // args[MA_CARRY_OUT] = c; |
| 938 // } |
| 939 |
| 940 // TODO(regis): Confirm that it is not required to check arguments (and also |
| 941 // convince invocation_fuzz_test). |
| 942 |
| 943 // EBX = x |
| 944 Label x_not_zero; |
| 945 __ movl(ECX, Address(ESP, 6 * kWordSize)); // args |
| 946 __ movl(EBX, FieldAddress(ECX, TypedData::data_offset())); // x |
| 947 __ cmpl(EBX, Immediate(0)); |
| 948 __ j(NOT_EQUAL, &x_not_zero, Assembler::kNearJump); |
| 949 // Set args[MA_CARRY_OUT] to 0 and return. |
| 950 __ movl(FieldAddress(ECX, TypedData::data_offset() + kWordSize), EBX); |
| 951 // TODO(regis): Confirm that returning Object::null() is not required. |
| 952 __ ret(); |
| 953 __ Bind(&x_not_zero); |
| 954 |
| 955 // Preserve CTX to free ESI. |
| 956 __ pushl(CTX); |
| 957 ASSERT(CTX == ESI); |
| 958 |
| 959 // EDI = mip = &m_digits[i >> 1] |
| 960 __ movl(EDI, Address(ESP, 6 * kWordSize)); // m_digits |
| 961 __ movl(EAX, Address(ESP, 5 * kWordSize)); // i is Smi |
| 962 __ leal(EDI, FieldAddress(EDI, EAX, TIMES_2, TypedData::data_offset())); |
| 963 |
| 964 // ESI = ajp = &a_digits[j >> 1] |
| 965 __ movl(ESI, Address(ESP, 4 * kWordSize)); // a_digits |
| 966 __ movl(EAX, Address(ESP, 3 * kWordSize)); // j is Smi |
| 967 __ leal(ESI, FieldAddress(ESI, EAX, TIMES_2, TypedData::data_offset())); |
| 968 |
| 969 // ECX = c = 0 |
| 970 __ xorl(ECX, ECX); |
| 971 |
| 972 Label loop, done; |
| 973 __ Bind(&loop); |
| 974 // x: EBX |
| 975 // mip: EDI |
| 976 // ajp: ESI |
| 977 // c: ECX |
| 978 // t: EDX:EAX (not live at loop entry) |
| 979 |
| 980 // while ((n -= 2) >= 0), n is on stack, above ret addr and saved CTX. |
| 981 __ movl(EAX, Immediate(2)); // 'sub mem32, imm32' not implemented. |
| 982 __ subl(Address(ESP, 2 * kWordSize), EAX); // --n, n is Smi. |
| 983 __ j(NEGATIVE, &done); |
| 984 |
| 985 // uint32_t mi = *mip++ |
| 986 __ movl(EAX, Address(EDI, 0)); |
| 987 __ addl(EDI, Immediate(kWordSize)); |
| 988 |
| 989 // uint64_t t = x*mi |
| 990 __ mull(EBX); // t = EDX:EAX = EAX * EBX |
| 991 __ addl(EAX, ECX); // t += c |
| 992 __ adcl(EDX, Immediate(0)); |
| 993 |
| 994 // uint32_t aj = *ajp; t += aj |
| 995 __ addl(EAX, Address(ESI, 0)); |
| 996 __ adcl(EDX, Immediate(0)); |
| 997 |
| 998 // *ajp++ = low32(t) |
| 999 __ movl(Address(ESI, 0), EAX); |
| 1000 __ addl(ESI, Immediate(kWordSize)); |
| 1001 |
| 1002 // c = high32(t) |
| 1003 __ movl(ECX, EDX); |
| 1004 __ jmp(&loop, Assembler::kNearJump); |
| 1005 |
| 1006 __ Bind(&done); |
| 1007 // Restore CTX, set args[MA_CARRY_OUT] to c and return. |
| 1008 __ popl(CTX); |
| 1009 __ movl(EAX, Address(ESP, 6 * kWordSize)); // args |
| 1010 __ movl(FieldAddress(EAX, TypedData::data_offset() + kWordSize), ECX); |
| 1011 // TODO(regis): Confirm that returning Object::null() is not required. |
| 1012 __ ret(); |
| 1013 } |
| 1014 |
| 1015 |
| 915 // Check if the last argument is a double, jump to label 'is_smi' if smi | 1016 // Check if the last argument is a double, jump to label 'is_smi' if smi |
| 916 // (easy to convert to double), otherwise jump to label 'not_double_smi', | 1017 // (easy to convert to double), otherwise jump to label 'not_double_smi', |
| 917 // Returns the last argument in EAX. | 1018 // Returns the last argument in EAX. |
| 918 static void TestLastArgumentIsDouble(Assembler* assembler, | 1019 static void TestLastArgumentIsDouble(Assembler* assembler, |
| 919 Label* is_smi, | 1020 Label* is_smi, |
| 920 Label* not_double_smi) { | 1021 Label* not_double_smi) { |
| 921 __ movl(EAX, Address(ESP, + 1 * kWordSize)); | 1022 __ movl(EAX, Address(ESP, + 1 * kWordSize)); |
| 922 __ testl(EAX, Immediate(kSmiTagMask)); | 1023 __ testl(EAX, Immediate(kSmiTagMask)); |
| 923 __ j(ZERO, is_smi, Assembler::kNearJump); // Jump if Smi. | 1024 __ j(ZERO, is_smi, Assembler::kNearJump); // Jump if Smi. |
| 924 __ CompareClassId(EAX, kDoubleCid, EBX); | 1025 __ CompareClassId(EAX, kDoubleCid, EBX); |
| (...skipping 717 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1642 Isolate::current_tag_offset()); | 1743 Isolate::current_tag_offset()); |
| 1643 // Set return value to Isolate::current_tag_. | 1744 // Set return value to Isolate::current_tag_. |
| 1644 __ movl(EAX, current_tag_addr); | 1745 __ movl(EAX, current_tag_addr); |
| 1645 __ ret(); | 1746 __ ret(); |
| 1646 } | 1747 } |
| 1647 | 1748 |
| 1648 #undef __ | 1749 #undef __ |
| 1649 } // namespace dart | 1750 } // namespace dart |
| 1650 | 1751 |
| 1651 #endif // defined TARGET_ARCH_IA32 | 1752 #endif // defined TARGET_ARCH_IA32 |
| OLD | NEW |