| 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 // while ((n -= 2) >= 0) { // n is Smi. | 930 // SmiUntag(n); |
| 931 // while (--n >= 0) { |
| 931 // uint32_t mi = *mip++; | 932 // uint32_t mi = *mip++; |
| 932 // uint32_t aj = *ajp; | 933 // uint32_t aj = *ajp; |
| 933 // uint64_t t = x*mi + aj + c; // 32-bit * 32-bit -> 64-bit. | 934 // uint64_t t = x*mi + aj + c; // 32-bit * 32-bit -> 64-bit. |
| 934 // *ajp++ = low32(t); | 935 // *ajp++ = low32(t); |
| 935 // c = high32(t); | 936 // c = high32(t); |
| 936 // } | 937 // } |
| 937 // args[MA_CARRY_OUT] = c; | 938 // args[MA_CARRY_OUT] = c; |
| 938 // } | 939 // } |
| 939 | 940 |
| 940 // TODO(regis): Confirm that it is not required to check arguments (and also | |
| 941 // convince invocation_fuzz_test). | |
| 942 | |
| 943 // EBX = x | 941 // EBX = x |
| 944 Label x_not_zero; | 942 Label x_not_zero; |
| 945 __ movl(ECX, Address(ESP, 6 * kWordSize)); // args | 943 __ movl(ECX, Address(ESP, 6 * kWordSize)); // args |
| 946 __ movl(EBX, FieldAddress(ECX, TypedData::data_offset())); // x | 944 __ movl(EBX, FieldAddress(ECX, TypedData::data_offset())); // x |
| 947 __ cmpl(EBX, Immediate(0)); | 945 __ cmpl(EBX, Immediate(0)); |
| 948 __ j(NOT_EQUAL, &x_not_zero, Assembler::kNearJump); | 946 __ j(NOT_EQUAL, &x_not_zero, Assembler::kNearJump); |
| 949 // Set args[MA_CARRY_OUT] to 0 and return. | 947 // Set args[MA_CARRY_OUT] to 0 and return. |
| 950 __ movl(FieldAddress(ECX, TypedData::data_offset() + kWordSize), EBX); | 948 __ movl(FieldAddress(ECX, TypedData::data_offset() + kWordSize), EBX); |
| 951 // TODO(regis): Confirm that returning Object::null() is not required. | 949 // TODO(regis): Confirm that returning Object::null() is not required. |
| 952 __ ret(); | 950 __ ret(); |
| 953 __ Bind(&x_not_zero); | 951 __ Bind(&x_not_zero); |
| 954 | 952 |
| 955 // Preserve CTX to free ESI. | 953 // Preserve CTX to free ESI. |
| 956 __ pushl(CTX); | 954 __ pushl(CTX); |
| 957 ASSERT(CTX == ESI); | 955 ASSERT(CTX == ESI); |
| 958 | 956 |
| 959 // EDI = mip = &m_digits[i >> 1] | 957 // EDI = mip = &m_digits[i >> 1] |
| 960 __ movl(EDI, Address(ESP, 6 * kWordSize)); // m_digits | 958 __ movl(EDI, Address(ESP, 6 * kWordSize)); // m_digits |
| 961 __ movl(EAX, Address(ESP, 5 * kWordSize)); // i is Smi | 959 __ movl(EAX, Address(ESP, 5 * kWordSize)); // i is Smi |
| 962 __ leal(EDI, FieldAddress(EDI, EAX, TIMES_2, TypedData::data_offset())); | 960 __ leal(EDI, FieldAddress(EDI, EAX, TIMES_2, TypedData::data_offset())); |
| 963 | 961 |
| 964 // ESI = ajp = &a_digits[j >> 1] | 962 // ESI = ajp = &a_digits[j >> 1] |
| 965 __ movl(ESI, Address(ESP, 4 * kWordSize)); // a_digits | 963 __ movl(ESI, Address(ESP, 4 * kWordSize)); // a_digits |
| 966 __ movl(EAX, Address(ESP, 3 * kWordSize)); // j is Smi | 964 __ movl(EAX, Address(ESP, 3 * kWordSize)); // j is Smi |
| 967 __ leal(ESI, FieldAddress(ESI, EAX, TIMES_2, TypedData::data_offset())); | 965 __ leal(ESI, FieldAddress(ESI, EAX, TIMES_2, TypedData::data_offset())); |
| 968 | 966 |
| 969 // ECX = c = 0 | 967 // ECX = c = 0 |
| 970 __ xorl(ECX, ECX); | 968 __ xorl(ECX, ECX); |
| 971 | 969 |
| 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 |
| 972 Label loop, done; | 976 Label loop, done; |
| 973 __ Bind(&loop); | 977 __ Bind(&loop); |
| 974 // x: EBX | 978 // x: EBX |
| 975 // mip: EDI | 979 // mip: EDI |
| 976 // ajp: ESI | 980 // ajp: ESI |
| 977 // c: ECX | 981 // c: ECX |
| 978 // t: EDX:EAX (not live at loop entry) | 982 // t: EDX:EAX (not live at loop entry) |
| 983 // n: ESP[0] |
| 979 | 984 |
| 980 // while ((n -= 2) >= 0), n is on stack, above ret addr and saved CTX. | 985 // while (--n >= 0) |
| 981 __ movl(EAX, Immediate(2)); // 'sub mem32, imm32' not implemented. | 986 __ decl(n_addr); // --n |
| 982 __ subl(Address(ESP, 2 * kWordSize), EAX); // --n, n is Smi. | |
| 983 __ j(NEGATIVE, &done); | 987 __ j(NEGATIVE, &done); |
| 984 | 988 |
| 985 // uint32_t mi = *mip++ | 989 // uint32_t mi = *mip++ |
| 986 __ movl(EAX, Address(EDI, 0)); | 990 __ movl(EAX, Address(EDI, 0)); |
| 987 __ addl(EDI, Immediate(kWordSize)); | 991 __ addl(EDI, Immediate(kWordSize)); |
| 988 | 992 |
| 989 // uint64_t t = x*mi | 993 // uint64_t t = x*mi |
| 990 __ mull(EBX); // t = EDX:EAX = EAX * EBX | 994 __ mull(EBX); // t = EDX:EAX = EAX * EBX |
| 991 __ addl(EAX, ECX); // t += c | 995 __ addl(EAX, ECX); // t += c |
| 992 __ adcl(EDX, Immediate(0)); | 996 __ adcl(EDX, Immediate(0)); |
| 993 | 997 |
| 994 // uint32_t aj = *ajp; t += aj | 998 // uint32_t aj = *ajp; t += aj |
| 995 __ addl(EAX, Address(ESI, 0)); | 999 __ addl(EAX, Address(ESI, 0)); |
| 996 __ adcl(EDX, Immediate(0)); | 1000 __ adcl(EDX, Immediate(0)); |
| 997 | 1001 |
| 998 // *ajp++ = low32(t) | 1002 // *ajp++ = low32(t) |
| 999 __ movl(Address(ESI, 0), EAX); | 1003 __ movl(Address(ESI, 0), EAX); |
| 1000 __ addl(ESI, Immediate(kWordSize)); | 1004 __ addl(ESI, Immediate(kWordSize)); |
| 1001 | 1005 |
| 1002 // c = high32(t) | 1006 // c = high32(t) |
| 1003 __ movl(ECX, EDX); | 1007 __ movl(ECX, EDX); |
| 1004 __ jmp(&loop, Assembler::kNearJump); | 1008 __ jmp(&loop, Assembler::kNearJump); |
| 1005 | 1009 |
| 1006 __ Bind(&done); | 1010 __ Bind(&done); |
| 1011 __ Drop(1); // n |
| 1007 // Restore CTX, set args[MA_CARRY_OUT] to c and return. | 1012 // Restore CTX, set args[MA_CARRY_OUT] to c and return. |
| 1008 __ popl(CTX); | 1013 __ popl(CTX); |
| 1009 __ movl(EAX, Address(ESP, 6 * kWordSize)); // args | 1014 __ movl(EAX, Address(ESP, 6 * kWordSize)); // args |
| 1010 __ movl(FieldAddress(EAX, TypedData::data_offset() + kWordSize), ECX); | 1015 __ movl(FieldAddress(EAX, TypedData::data_offset() + kWordSize), ECX); |
| 1011 // TODO(regis): Confirm that returning Object::null() is not required. | 1016 // TODO(regis): Confirm that returning Object::null() is not required. |
| 1012 __ ret(); | 1017 __ ret(); |
| 1013 } | 1018 } |
| 1014 | 1019 |
| 1015 | 1020 |
| 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 |
| 1016 // Check if the last argument is a double, jump to label 'is_smi' if smi | 1159 // Check if the last argument is a double, jump to label 'is_smi' if smi |
| 1017 // (easy to convert to double), otherwise jump to label 'not_double_smi', | 1160 // (easy to convert to double), otherwise jump to label 'not_double_smi', |
| 1018 // Returns the last argument in EAX. | 1161 // Returns the last argument in EAX. |
| 1019 static void TestLastArgumentIsDouble(Assembler* assembler, | 1162 static void TestLastArgumentIsDouble(Assembler* assembler, |
| 1020 Label* is_smi, | 1163 Label* is_smi, |
| 1021 Label* not_double_smi) { | 1164 Label* not_double_smi) { |
| 1022 __ movl(EAX, Address(ESP, + 1 * kWordSize)); | 1165 __ movl(EAX, Address(ESP, + 1 * kWordSize)); |
| 1023 __ testl(EAX, Immediate(kSmiTagMask)); | 1166 __ testl(EAX, Immediate(kSmiTagMask)); |
| 1024 __ j(ZERO, is_smi, Assembler::kNearJump); // Jump if Smi. | 1167 __ j(ZERO, is_smi, Assembler::kNearJump); // Jump if Smi. |
| 1025 __ CompareClassId(EAX, kDoubleCid, EBX); | 1168 __ CompareClassId(EAX, kDoubleCid, EBX); |
| (...skipping 715 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1741 Isolate::current_tag_offset()); | 1884 Isolate::current_tag_offset()); |
| 1742 // Set return value to Isolate::current_tag_. | 1885 // Set return value to Isolate::current_tag_. |
| 1743 __ movl(EAX, current_tag_addr); | 1886 __ movl(EAX, current_tag_addr); |
| 1744 __ ret(); | 1887 __ ret(); |
| 1745 } | 1888 } |
| 1746 | 1889 |
| 1747 #undef __ | 1890 #undef __ |
| 1748 } // namespace dart | 1891 } // namespace dart |
| 1749 | 1892 |
| 1750 #endif // defined TARGET_ARCH_IA32 | 1893 #endif // defined TARGET_ARCH_IA32 |
| OLD | NEW |