| 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 909 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 = args[MA_MULTIPLIER]; |
| 923 // if (x == 0) { | 923 // if (x == 0) { |
| 924 // args[MA_CARRY_OUT] = 0; | 924 // args[MA_CARRY_OUT] = 0; |
| 925 // return; | 925 // return; |
| 926 // } | 926 // } |
| 927 // uint32_t* mip = &m_digits[i >> 1]; // i is Smi. | 927 // uint32_t* mip = &m_digits[i >> 1]; // i is Smi. |
| 928 // uint32_t* ajp = &a_digits[j >> 1]; // j is Smi. | 928 // uint32_t* ajp = &a_digits[j >> 1]; // j is Smi. |
| 929 // uint32_t c = 0; | 929 // uint32_t c = 0; |
| 930 // SmiUntag(n); | 930 // while ((n -= 2) >= 0) { // n is Smi. |
| 931 // while (--n >= 0) { | |
| 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); |
| 937 // } | 936 // } |
| 938 // args[MA_CARRY_OUT] = c; | 937 // args[MA_CARRY_OUT] = c; |
| 939 // } | 938 // } |
| 940 | 939 |
| 940 // TODO(regis): Confirm that it is not required to check arguments (and also |
| 941 // convince invocation_fuzz_test). |
| 942 |
| 941 // EBX = x | 943 // EBX = x |
| 942 Label x_not_zero; | 944 Label x_not_zero; |
| 943 __ movl(ECX, Address(ESP, 6 * kWordSize)); // args | 945 __ movl(ECX, Address(ESP, 6 * kWordSize)); // args |
| 944 __ movl(EBX, FieldAddress(ECX, TypedData::data_offset())); // x | 946 __ movl(EBX, FieldAddress(ECX, TypedData::data_offset())); // x |
| 945 __ cmpl(EBX, Immediate(0)); | 947 __ cmpl(EBX, Immediate(0)); |
| 946 __ j(NOT_EQUAL, &x_not_zero, Assembler::kNearJump); | 948 __ j(NOT_EQUAL, &x_not_zero, Assembler::kNearJump); |
| 947 // Set args[MA_CARRY_OUT] to 0 and return. | 949 // Set args[MA_CARRY_OUT] to 0 and return. |
| 948 __ movl(FieldAddress(ECX, TypedData::data_offset() + kWordSize), EBX); | 950 __ movl(FieldAddress(ECX, TypedData::data_offset() + kWordSize), EBX); |
| 949 // TODO(regis): Confirm that returning Object::null() is not required. | 951 // TODO(regis): Confirm that returning Object::null() is not required. |
| 950 __ ret(); | 952 __ ret(); |
| 951 __ Bind(&x_not_zero); | 953 __ Bind(&x_not_zero); |
| 952 | 954 |
| 953 // Preserve CTX to free ESI. | 955 // Preserve CTX to free ESI. |
| 954 __ pushl(CTX); | 956 __ pushl(CTX); |
| 955 ASSERT(CTX == ESI); | 957 ASSERT(CTX == ESI); |
| 956 | 958 |
| 957 // EDI = mip = &m_digits[i >> 1] | 959 // EDI = mip = &m_digits[i >> 1] |
| 958 __ movl(EDI, Address(ESP, 6 * kWordSize)); // m_digits | 960 __ movl(EDI, Address(ESP, 6 * kWordSize)); // m_digits |
| 959 __ movl(EAX, Address(ESP, 5 * kWordSize)); // i is Smi | 961 __ movl(EAX, Address(ESP, 5 * kWordSize)); // i is Smi |
| 960 __ leal(EDI, FieldAddress(EDI, EAX, TIMES_2, TypedData::data_offset())); | 962 __ leal(EDI, FieldAddress(EDI, EAX, TIMES_2, TypedData::data_offset())); |
| 961 | 963 |
| 962 // ESI = ajp = &a_digits[j >> 1] | 964 // ESI = ajp = &a_digits[j >> 1] |
| 963 __ movl(ESI, Address(ESP, 4 * kWordSize)); // a_digits | 965 __ movl(ESI, Address(ESP, 4 * kWordSize)); // a_digits |
| 964 __ movl(EAX, Address(ESP, 3 * kWordSize)); // j is Smi | 966 __ movl(EAX, Address(ESP, 3 * kWordSize)); // j is Smi |
| 965 __ leal(ESI, FieldAddress(ESI, EAX, TIMES_2, TypedData::data_offset())); | 967 __ leal(ESI, FieldAddress(ESI, EAX, TIMES_2, TypedData::data_offset())); |
| 966 | 968 |
| 967 // ECX = c = 0 | 969 // ECX = c = 0 |
| 968 __ xorl(ECX, ECX); | 970 __ xorl(ECX, ECX); |
| 969 | 971 |
| 970 // SmiUntag(n), 'sar mem32, 1' not implemented | |
| 971 __ movl(EAX, Address(ESP, 2 * kWordSize)); | |
| 972 __ SmiUntag(EAX); | |
| 973 __ pushl(EAX); | |
| 974 Address n_addr = Address(ESP, 0 * kWordSize); | |
| 975 | |
| 976 Label loop, done; | 972 Label loop, done; |
| 977 __ Bind(&loop); | 973 __ Bind(&loop); |
| 978 // x: EBX | 974 // x: EBX |
| 979 // mip: EDI | 975 // mip: EDI |
| 980 // ajp: ESI | 976 // ajp: ESI |
| 981 // c: ECX | 977 // c: ECX |
| 982 // t: EDX:EAX (not live at loop entry) | 978 // t: EDX:EAX (not live at loop entry) |
| 983 // n: ESP[0] | |
| 984 | 979 |
| 985 // while (--n >= 0) | 980 // while ((n -= 2) >= 0), n is on stack, above ret addr and saved CTX. |
| 986 __ decl(n_addr); // --n | 981 __ movl(EAX, Immediate(2)); // 'sub mem32, imm32' not implemented. |
| 982 __ subl(Address(ESP, 2 * kWordSize), EAX); // --n, n is Smi. |
| 987 __ j(NEGATIVE, &done); | 983 __ j(NEGATIVE, &done); |
| 988 | 984 |
| 989 // uint32_t mi = *mip++ | 985 // uint32_t mi = *mip++ |
| 990 __ movl(EAX, Address(EDI, 0)); | 986 __ movl(EAX, Address(EDI, 0)); |
| 991 __ addl(EDI, Immediate(kWordSize)); | 987 __ addl(EDI, Immediate(kWordSize)); |
| 992 | 988 |
| 993 // uint64_t t = x*mi | 989 // uint64_t t = x*mi |
| 994 __ mull(EBX); // t = EDX:EAX = EAX * EBX | 990 __ mull(EBX); // t = EDX:EAX = EAX * EBX |
| 995 __ addl(EAX, ECX); // t += c | 991 __ addl(EAX, ECX); // t += c |
| 996 __ adcl(EDX, Immediate(0)); | 992 __ adcl(EDX, Immediate(0)); |
| 997 | 993 |
| 998 // uint32_t aj = *ajp; t += aj | 994 // uint32_t aj = *ajp; t += aj |
| 999 __ addl(EAX, Address(ESI, 0)); | 995 __ addl(EAX, Address(ESI, 0)); |
| 1000 __ adcl(EDX, Immediate(0)); | 996 __ adcl(EDX, Immediate(0)); |
| 1001 | 997 |
| 1002 // *ajp++ = low32(t) | 998 // *ajp++ = low32(t) |
| 1003 __ movl(Address(ESI, 0), EAX); | 999 __ movl(Address(ESI, 0), EAX); |
| 1004 __ addl(ESI, Immediate(kWordSize)); | 1000 __ addl(ESI, Immediate(kWordSize)); |
| 1005 | 1001 |
| 1006 // c = high32(t) | 1002 // c = high32(t) |
| 1007 __ movl(ECX, EDX); | 1003 __ movl(ECX, EDX); |
| 1008 __ jmp(&loop, Assembler::kNearJump); | 1004 __ jmp(&loop, Assembler::kNearJump); |
| 1009 | 1005 |
| 1010 __ Bind(&done); | 1006 __ Bind(&done); |
| 1011 __ Drop(1); // n | |
| 1012 // Restore CTX, set args[MA_CARRY_OUT] to c and return. | 1007 // Restore CTX, set args[MA_CARRY_OUT] to c and return. |
| 1013 __ popl(CTX); | 1008 __ popl(CTX); |
| 1014 __ movl(EAX, Address(ESP, 6 * kWordSize)); // args | 1009 __ movl(EAX, Address(ESP, 6 * kWordSize)); // args |
| 1015 __ movl(FieldAddress(EAX, TypedData::data_offset() + kWordSize), ECX); | 1010 __ movl(FieldAddress(EAX, TypedData::data_offset() + kWordSize), ECX); |
| 1016 // TODO(regis): Confirm that returning Object::null() is not required. | 1011 // TODO(regis): Confirm that returning Object::null() is not required. |
| 1017 __ ret(); | 1012 __ ret(); |
| 1018 } | 1013 } |
| 1019 | 1014 |
| 1020 | 1015 |
| 1021 // TODO(regis): Once this intrinsic is implemented on all architectures, the | |
| 1022 // corresponding Dart method will be untested. Add a test with --no-intrinsify. | |
| 1023 void Intrinsifier::Bigint_sqrAdd(Assembler* assembler) { | |
| 1024 // Pseudo code: | |
| 1025 // static void _sqrAdd(Uint32List x_digits, int i, | |
| 1026 // Uint32List a_digits, int used) { | |
| 1027 // uint32_t* xip = &x_digits[i >> 1]; // i is Smi. | |
| 1028 // uint32_t x = *xip++; | |
| 1029 // if (x == 0) return; | |
| 1030 // uint32_t* ajp = &a_digits[i]; // j == 2*i, i is Smi. | |
| 1031 // uint32_t aj = *ajp; | |
| 1032 // uint64_t t = x*x + aj; | |
| 1033 // *ajp++ = low32(t); | |
| 1034 // uint64_t c = high32(t); | |
| 1035 // int n = ((used - i) >> 1) - 1; // used and i are Smi. | |
| 1036 // while (--n >= 0) { | |
| 1037 // uint32_t xi = *xip++; | |
| 1038 // uint32_t aj = *ajp; | |
| 1039 // uint96_t t = 2*x*xi + aj + c; // 2-bit * 32-bit * 32-bit -> 65-bit. | |
| 1040 // *ajp++ = low32(t); | |
| 1041 // c = high64(t); // 33-bit. | |
| 1042 // } | |
| 1043 // uint32_t aj = *ajp; | |
| 1044 // uint64_t t = aj + c; // 32-bit + 33-bit -> 34-bit. | |
| 1045 // *ajp++ = low32(t); | |
| 1046 // *ajp = high32(t); | |
| 1047 | |
| 1048 // EDI = xip = &x_digits[i >> 1] | |
| 1049 __ movl(EDI, Address(ESP, 4 * kWordSize)); // m_digits | |
| 1050 __ movl(EAX, Address(ESP, 3 * kWordSize)); // i is Smi | |
| 1051 __ leal(EDI, FieldAddress(EDI, EAX, TIMES_2, TypedData::data_offset())); | |
| 1052 | |
| 1053 // EBX = x = *xip++, return if x == 0 | |
| 1054 Label x_zero; | |
| 1055 __ movl(EBX, Address(EDI, 0)); | |
| 1056 __ cmpl(EBX, Immediate(0)); | |
| 1057 __ j(EQUAL, &x_zero); | |
| 1058 __ addl(EDI, Immediate(kWordSize)); | |
| 1059 | |
| 1060 // Preserve CTX to free ESI. | |
| 1061 __ pushl(CTX); | |
| 1062 ASSERT(CTX == ESI); | |
| 1063 | |
| 1064 // ESI = ajp = &a_digits[i] | |
| 1065 __ movl(ESI, Address(ESP, 3 * kWordSize)); // a_digits | |
| 1066 __ leal(ESI, FieldAddress(ESI, EAX, TIMES_4, TypedData::data_offset())); | |
| 1067 | |
| 1068 // EAX:EDX = t = x*x + *ajp | |
| 1069 __ movl(EAX, EBX); | |
| 1070 __ mull(EBX); | |
| 1071 __ addl(EAX, Address(ESI, 0)); | |
| 1072 __ adcl(EDX, Immediate(0)); | |
| 1073 | |
| 1074 // *ajp++ = low32(t) | |
| 1075 __ movl(Address(ESI, 0), EAX); | |
| 1076 __ addl(ESI, Immediate(kWordSize)); | |
| 1077 | |
| 1078 // int n = used - i - 1; // All Smi. | |
| 1079 __ movl(EAX, Address(ESP, 2 * kWordSize)); // used is Smi | |
| 1080 __ subl(EAX, Address(ESP, 4 * kWordSize)); // i is Smi | |
| 1081 __ SmiUntag(EAX); | |
| 1082 __ decl(EAX); | |
| 1083 __ pushl(EAX); // Save n on stack. | |
| 1084 | |
| 1085 // uint64_t c = high32(t) | |
| 1086 __ pushl(Immediate(0)); // push high32(c) == 0 | |
| 1087 __ pushl(EDX); // push low32(c) == high32(t) | |
| 1088 | |
| 1089 Address n_addr = Address(ESP, 2 * kWordSize); | |
| 1090 Address ch_addr = Address(ESP, 1 * kWordSize); | |
| 1091 Address cl_addr = Address(ESP, 0 * kWordSize); | |
| 1092 | |
| 1093 Label loop, done; | |
| 1094 __ Bind(&loop); | |
| 1095 // x: EBX | |
| 1096 // xip: EDI | |
| 1097 // ajp: ESI | |
| 1098 // c: ESP[1]:ESP[0] | |
| 1099 // t: ECX:EDX:EAX (not live at loop entry) | |
| 1100 // n: ESP[2] | |
| 1101 | |
| 1102 // while (--n >= 0) | |
| 1103 __ decl(Address(ESP, 2 * kWordSize)); // --n | |
| 1104 __ j(NEGATIVE, &done); | |
| 1105 | |
| 1106 // uint32_t xi = *xip++ | |
| 1107 __ movl(EAX, Address(EDI, 0)); | |
| 1108 __ addl(EDI, Immediate(kWordSize)); | |
| 1109 | |
| 1110 // uint96_t t = ECX:EDX:EAX = 2*x*xi + aj + c | |
| 1111 __ mull(EBX); // EDX:EAX = EAX * EBX | |
| 1112 __ xorl(ECX, ECX); // ECX = 0 | |
| 1113 __ shld(ECX, EDX, Immediate(1)); | |
| 1114 __ shld(EDX, EAX, Immediate(1)); | |
| 1115 __ shll(EAX, Immediate(1)); // ECX:EDX:EAX <<= 1 | |
| 1116 __ addl(EAX, Address(ESI, 0)); // t += aj | |
| 1117 __ adcl(EDX, Immediate(0)); | |
| 1118 __ adcl(ECX, Immediate(0)); | |
| 1119 __ addl(EAX, cl_addr); // t += low32(c) | |
| 1120 __ adcl(EDX, ch_addr); // t += high32(c) << 32 | |
| 1121 __ adcl(ECX, Immediate(0)); | |
| 1122 | |
| 1123 // *ajp++ = low32(t) | |
| 1124 __ movl(Address(ESI, 0), EAX); | |
| 1125 __ addl(ESI, Immediate(kWordSize)); | |
| 1126 | |
| 1127 // c = high64(t) | |
| 1128 __ movl(cl_addr, EDX); | |
| 1129 __ movl(ch_addr, ECX); | |
| 1130 | |
| 1131 __ jmp(&loop, Assembler::kNearJump); | |
| 1132 | |
| 1133 __ Bind(&done); | |
| 1134 // uint32_t aj = *ajp; | |
| 1135 __ movl(EAX, Address(ESI, 0)); | |
| 1136 | |
| 1137 // uint64_t t = aj + c; // 32-bit + 33-bit -> 34-bit. | |
| 1138 __ movl(EAX, cl_addr); // t = c | |
| 1139 __ movl(EDX, ch_addr); | |
| 1140 __ addl(EAX, Address(ESI, 0)); // t += aj | |
| 1141 __ adcl(EDX, Immediate(0)); | |
| 1142 | |
| 1143 // *ajp++ = low32(t); | |
| 1144 __ movl(Address(ESI, 0), EAX); | |
| 1145 __ addl(ESI, Immediate(kWordSize)); | |
| 1146 | |
| 1147 // *ajp = high32(t); | |
| 1148 __ movl(Address(ESI, 0), EDX); | |
| 1149 | |
| 1150 // Restore CTX and return. | |
| 1151 __ Drop(3); | |
| 1152 __ popl(CTX); | |
| 1153 __ Bind(&x_zero); | |
| 1154 // TODO(regis): Confirm that returning Object::null() is not required. | |
| 1155 __ ret(); | |
| 1156 } | |
| 1157 | |
| 1158 | |
| 1159 // 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 |
| 1160 // (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', |
| 1161 // Returns the last argument in EAX. | 1018 // Returns the last argument in EAX. |
| 1162 static void TestLastArgumentIsDouble(Assembler* assembler, | 1019 static void TestLastArgumentIsDouble(Assembler* assembler, |
| 1163 Label* is_smi, | 1020 Label* is_smi, |
| 1164 Label* not_double_smi) { | 1021 Label* not_double_smi) { |
| 1165 __ movl(EAX, Address(ESP, + 1 * kWordSize)); | 1022 __ movl(EAX, Address(ESP, + 1 * kWordSize)); |
| 1166 __ testl(EAX, Immediate(kSmiTagMask)); | 1023 __ testl(EAX, Immediate(kSmiTagMask)); |
| 1167 __ j(ZERO, is_smi, Assembler::kNearJump); // Jump if Smi. | 1024 __ j(ZERO, is_smi, Assembler::kNearJump); // Jump if Smi. |
| 1168 __ CompareClassId(EAX, kDoubleCid, EBX); | 1025 __ CompareClassId(EAX, kDoubleCid, EBX); |
| (...skipping 715 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1884 Isolate::current_tag_offset()); | 1741 Isolate::current_tag_offset()); |
| 1885 // Set return value to Isolate::current_tag_. | 1742 // Set return value to Isolate::current_tag_. |
| 1886 __ movl(EAX, current_tag_addr); | 1743 __ movl(EAX, current_tag_addr); |
| 1887 __ ret(); | 1744 __ ret(); |
| 1888 } | 1745 } |
| 1889 | 1746 |
| 1890 #undef __ | 1747 #undef __ |
| 1891 } // namespace dart | 1748 } // namespace dart |
| 1892 | 1749 |
| 1893 #endif // defined TARGET_ARCH_IA32 | 1750 #endif // defined TARGET_ARCH_IA32 |
| OLD | NEW |