Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(366)

Side by Side Diff: runtime/vm/intrinsifier_ia32.cc

Issue 600533002: Refactor bigint _sqrTo in preparation of intrinsification. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/intrinsifier_arm64.cc ('k') | runtime/vm/intrinsifier_mips.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
srdjan 2014/09/24 00:19:28 You could define: Address n_addr = Address(ESP, 2
regis 2014/09/24 01:50:49 Done. And it may not be such a good idea to untag
970 // SmiUntag(n), 'sar mem32, 1' not implemented
971 __ movl(EAX, Address(ESP, 2 * kWordSize));
972 __ SmiUntag(EAX);
973 __ movl(Address(ESP, 2 * kWordSize), EAX);
974
972 Label loop, done; 975 Label loop, done;
973 __ Bind(&loop); 976 __ Bind(&loop);
974 // x: EBX 977 // x: EBX
975 // mip: EDI 978 // mip: EDI
976 // ajp: ESI 979 // ajp: ESI
977 // c: ECX 980 // c: ECX
978 // t: EDX:EAX (not live at loop entry) 981 // t: EDX:EAX (not live at loop entry)
982 // n: ESP[2]
979 983
980 // while ((n -= 2) >= 0), n is on stack, above ret addr and saved CTX. 984 // while (--n >= 0)
981 __ movl(EAX, Immediate(2)); // 'sub mem32, imm32' not implemented. 985 __ decl(Address(ESP, 2 * kWordSize)); // --n
982 __ subl(Address(ESP, 2 * kWordSize), EAX); // --n, n is Smi.
983 __ j(NEGATIVE, &done); 986 __ j(NEGATIVE, &done);
984 987
985 // uint32_t mi = *mip++ 988 // uint32_t mi = *mip++
986 __ movl(EAX, Address(EDI, 0)); 989 __ movl(EAX, Address(EDI, 0));
987 __ addl(EDI, Immediate(kWordSize)); 990 __ addl(EDI, Immediate(kWordSize));
988 991
989 // uint64_t t = x*mi 992 // uint64_t t = x*mi
990 __ mull(EBX); // t = EDX:EAX = EAX * EBX 993 __ mull(EBX); // t = EDX:EAX = EAX * EBX
991 __ addl(EAX, ECX); // t += c 994 __ addl(EAX, ECX); // t += c
992 __ adcl(EDX, Immediate(0)); 995 __ adcl(EDX, Immediate(0));
(...skipping 13 matching lines...) Expand all
1006 __ Bind(&done); 1009 __ Bind(&done);
1007 // Restore CTX, set args[MA_CARRY_OUT] to c and return. 1010 // Restore CTX, set args[MA_CARRY_OUT] to c and return.
1008 __ popl(CTX); 1011 __ popl(CTX);
1009 __ movl(EAX, Address(ESP, 6 * kWordSize)); // args 1012 __ movl(EAX, Address(ESP, 6 * kWordSize)); // args
1010 __ movl(FieldAddress(EAX, TypedData::data_offset() + kWordSize), ECX); 1013 __ movl(FieldAddress(EAX, TypedData::data_offset() + kWordSize), ECX);
1011 // TODO(regis): Confirm that returning Object::null() is not required. 1014 // TODO(regis): Confirm that returning Object::null() is not required.
1012 __ ret(); 1015 __ ret();
1013 } 1016 }
1014 1017
1015 1018
1019 // TODO(regis): Once this intrinsic is implemented on all architectures, the
1020 // corresponding Dart method will be untested. Add a test with --no-intrinsify.
1021 void Intrinsifier::Bigint_sqrAdd(Assembler* assembler) {
1022 // Pseudo code:
1023 // static void _sqrAdd(Uint32List x_digits, int i,
1024 // Uint32List a_digits, int used) {
1025 // uint32_t* xip = &x_digits[i >> 1]; // i is Smi.
1026 // uint32_t x = *xip++;
1027 // if (x == 0) return;
1028 // uint32_t* ajp = &a_digits[i]; // j == 2*i, i is Smi.
1029 // uint32_t aj = *ajp;
1030 // uint64_t t = x*x + aj;
1031 // *ajp++ = low32(t);
1032 // uint64_t c = high32(t);
1033 // int n = ((used - i) >> 1) - 1; // used and i are Smi.
1034 // while (--n >= 0) {
1035 // uint32_t xi = *xip++;
1036 // uint32_t aj = *ajp;
1037 // uint96_t t = 2*x*xi + aj + c; // 2-bit * 32-bit * 32-bit -> 65-bit.
1038 // *ajp++ = low32(t);
1039 // c = high64(t); // 33-bit.
1040 // }
1041 // uint32_t aj = *ajp;
1042 // uint64_t t = aj + c; // 32-bit + 33-bit -> 34-bit.
1043 // *ajp++ = low32(t);
1044 // *ajp = high32(t);
1045
1046 // EDI = xip = &x_digits[i >> 1]
1047 __ movl(EDI, Address(ESP, 4 * kWordSize)); // m_digits
1048 __ movl(EAX, Address(ESP, 3 * kWordSize)); // i is Smi
1049 __ leal(EDI, FieldAddress(EDI, EAX, TIMES_2, TypedData::data_offset()));
1050
1051 // EBX = x = *xip++, return if x == 0
1052 Label x_not_zero;
1053 __ movl(EBX, Address(EDI, 0));
1054 __ cmpl(EBX, Immediate(0));
1055 __ j(NOT_EQUAL, &x_not_zero, Assembler::kNearJump);
srdjan 2014/09/24 00:19:28 You could jump if equal 0 to a label just before t
regis 2014/09/24 01:50:49 Done.
1056 // TODO(regis): Confirm that returning Object::null() is not required.
1057 __ ret();
1058 __ Bind(&x_not_zero);
1059 __ addl(EDI, Immediate(kWordSize));
1060
1061 // Preserve CTX to free ESI.
1062 __ pushl(CTX);
1063 ASSERT(CTX == ESI);
1064
1065 // ESI = ajp = &a_digits[i]
1066 __ movl(ESI, Address(ESP, 3 * kWordSize)); // a_digits
1067 __ leal(ESI, FieldAddress(ESI, EAX, TIMES_4, TypedData::data_offset()));
1068
1069 // EAX:EDX = t = x*x + *ajp
1070 __ movl(EAX, EBX);
1071 __ mull(EBX);
1072 __ addl(EAX, Address(ESI, 0));
1073 __ adcl(EDX, Immediate(0));
1074
1075 // *ajp++ = low32(t)
1076 __ movl(Address(ESI, 0), EAX);
1077 __ addl(ESI, Immediate(kWordSize));
1078
1079 // int n = used - i - 1; // All Smi.
1080 __ movl(EAX, Address(ESP, 2 * kWordSize)); // used is Smi
1081 __ subl(EAX, Address(ESP, 4 * kWordSize)); // i is Smi
1082 __ SmiUntag(EAX);
1083 __ decl(EAX);
1084 __ pushl(EAX); // Save n on stack.
1085
1086 // uint64_t c = high32(t)
1087 __ pushl(Immediate(0)); // push high32(c) == 0
1088 __ pushl(EDX); // push low32(c) == high32(t)
1089
1090 Label loop, done;
1091 __ Bind(&loop);
1092 // x: EBX
1093 // xip: EDI
1094 // ajp: ESI
1095 // c: ESP[1]:ESP[0]
1096 // t: ECX:EDX:EAX (not live at loop entry)
1097 // n: ESP[2]
1098
1099 // while (--n >= 0)
1100 __ decl(Address(ESP, 2 * kWordSize)); // --n
1101 __ j(NEGATIVE, &done);
1102
1103 // uint32_t xi = *xip++
1104 __ movl(EAX, Address(EDI, 0));
1105 __ addl(EDI, Immediate(kWordSize));
1106
1107 // uint96_t t = ECX:EDX:EAX = 2*x*xi + aj + c
1108 __ mull(EBX); // EDX:EAX = EAX * EBX
1109 __ xorl(ECX, ECX); // ECX = 0
1110 __ shld(ECX, EDX, Immediate(1));
1111 __ shld(EDX, EAX, Immediate(1));
1112 __ shll(EAX, Immediate(1)); // ECX:EDX:EAX <<= 1
1113 __ addl(EAX, Address(ESI, 0)); // t += aj
1114 __ adcl(EDX, Immediate(0));
1115 __ adcl(ECX, Immediate(0));
1116 __ addl(EAX, Address(ESP, 0 * kWordSize)); // t += low32(c)
1117 __ adcl(EDX, Address(ESP, 1 * kWordSize)); // t += high32(c) << 32
1118 __ adcl(ECX, Immediate(0));
1119
1120 // *ajp++ = low32(t)
1121 __ movl(Address(ESI, 0), EAX);
1122 __ addl(ESI, Immediate(kWordSize));
1123
1124 // c = high64(t)
1125 __ movl(Address(ESP, 0 * kWordSize), EDX);
1126 __ movl(Address(ESP, 1 * kWordSize), ECX);
1127
1128 __ jmp(&loop, Assembler::kNearJump);
1129
1130 __ Bind(&done);
1131 // uint32_t aj = *ajp;
1132 __ movl(EAX, Address(ESI, 0));
1133
1134 // uint64_t t = aj + c; // 32-bit + 33-bit -> 34-bit.
1135 __ movl(EAX, Address(ESP, 0 * kWordSize)); // t = c
1136 __ movl(EDX, Address(ESP, 1 * kWordSize));
1137 __ addl(EAX, Address(ESI, 0)); // t += aj
1138 __ adcl(EDX, Immediate(0));
1139
1140 // *ajp++ = low32(t);
1141 __ movl(Address(ESI, 0), EAX);
1142 __ addl(ESI, Immediate(kWordSize));
1143
1144 // *ajp = high32(t);
1145 __ movl(Address(ESI, 0), EDX);
1146
1147 // Restore CTX and return.
1148 __ Drop(3);
1149 __ popl(CTX);
1150 // TODO(regis): Confirm that returning Object::null() is not required.
1151 __ ret();
1152 }
1153
1154
1016 // Check if the last argument is a double, jump to label 'is_smi' if smi 1155 // 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', 1156 // (easy to convert to double), otherwise jump to label 'not_double_smi',
1018 // Returns the last argument in EAX. 1157 // Returns the last argument in EAX.
1019 static void TestLastArgumentIsDouble(Assembler* assembler, 1158 static void TestLastArgumentIsDouble(Assembler* assembler,
1020 Label* is_smi, 1159 Label* is_smi,
1021 Label* not_double_smi) { 1160 Label* not_double_smi) {
1022 __ movl(EAX, Address(ESP, + 1 * kWordSize)); 1161 __ movl(EAX, Address(ESP, + 1 * kWordSize));
1023 __ testl(EAX, Immediate(kSmiTagMask)); 1162 __ testl(EAX, Immediate(kSmiTagMask));
1024 __ j(ZERO, is_smi, Assembler::kNearJump); // Jump if Smi. 1163 __ j(ZERO, is_smi, Assembler::kNearJump); // Jump if Smi.
1025 __ CompareClassId(EAX, kDoubleCid, EBX); 1164 __ CompareClassId(EAX, kDoubleCid, EBX);
(...skipping 715 matching lines...) Expand 10 before | Expand all | Expand 10 after
1741 Isolate::current_tag_offset()); 1880 Isolate::current_tag_offset());
1742 // Set return value to Isolate::current_tag_. 1881 // Set return value to Isolate::current_tag_.
1743 __ movl(EAX, current_tag_addr); 1882 __ movl(EAX, current_tag_addr);
1744 __ ret(); 1883 __ ret();
1745 } 1884 }
1746 1885
1747 #undef __ 1886 #undef __
1748 } // namespace dart 1887 } // namespace dart
1749 1888
1750 #endif // defined TARGET_ARCH_IA32 1889 #endif // defined TARGET_ARCH_IA32
OLDNEW
« no previous file with comments | « runtime/vm/intrinsifier_arm64.cc ('k') | runtime/vm/intrinsifier_mips.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698