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

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

Issue 786933009: Process two 32-bit digits as one 64-bit digit in all bigint intrinsics on x64. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 5 years, 11 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
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 #include "vm/globals.h" // Needed here to get TARGET_ARCH_X64. 5 #include "vm/globals.h" // Needed here to get TARGET_ARCH_X64.
6 #if defined(TARGET_ARCH_X64) 6 #if defined(TARGET_ARCH_X64)
7 7
8 #include "vm/intrinsifier.h" 8 #include "vm/intrinsifier.h"
9 9
10 #include "vm/assembler.h" 10 #include "vm/assembler.h"
(...skipping 914 matching lines...) Expand 10 before | Expand all | Expand 10 after
925 // Returning Object::null() is not required, since this method is private. 925 // Returning Object::null() is not required, since this method is private.
926 __ ret(); 926 __ ret();
927 } 927 }
928 928
929 929
930 void Intrinsifier::Bigint_mulAdd(Assembler* assembler) { 930 void Intrinsifier::Bigint_mulAdd(Assembler* assembler) {
931 // Pseudo code: 931 // Pseudo code:
932 // static int _mulAdd(Uint32List x_digits, int xi, 932 // static int _mulAdd(Uint32List x_digits, int xi,
933 // Uint32List m_digits, int i, 933 // Uint32List m_digits, int i,
934 // Uint32List a_digits, int j, int n) { 934 // Uint32List a_digits, int j, int n) {
935 // uint32_t x = x_digits[xi >> 1]; // xi is Smi. 935 // uint64_t x = x_digits[xi >> 1 .. (xi >> 1) + 1]; // xi is Smi and even.
936 // if (x == 0 || n == 0) { 936 // if (x == 0 || n == 0) {
937 // return 1; 937 // return 2;
938 // } 938 // }
939 // uint32_t* mip = &m_digits[i >> 1]; // i is Smi. 939 // uint64_t* mip = &m_digits[i >> 1]; // i is Smi and even.
940 // uint32_t* ajp = &a_digits[j >> 1]; // j is Smi. 940 // uint64_t* ajp = &a_digits[j >> 1]; // j is Smi and even.
941 // uint32_t c = 0; 941 // uint64_t c = 0;
942 // SmiUntag(n); 942 // SmiUntag(n); // n is Smi and even.
943 // n = (n + 1)/2; // Number of pairs to process.
943 // do { 944 // do {
944 // uint32_t mi = *mip++; 945 // uint64_t mi = *mip++;
945 // uint32_t aj = *ajp; 946 // uint364_t aj = *ajp;
zra 2015/01/05 16:39:22 uint64_t?
regis 2017/01/13 02:34:46 Done.
946 // uint64_t t = x*mi + aj + c; // 32-bit * 32-bit -> 64-bit. 947 // uint128_t t = x*mi + aj + c; // 64-bit * 64-bit -> 128-bit.
947 // *ajp++ = low32(t); 948 // *ajp++ = low64(t);
948 // c = high32(t); 949 // c = high64(t);
949 // } while (--n > 0); 950 // } while (--n > 0);
950 // while (c != 0) { 951 // while (c != 0) {
951 // uint64_t t = *ajp + c; 952 // uint128_t t = *ajp + c;
952 // *ajp++ = low32(t); 953 // *ajp++ = low64(t);
953 // c = high32(t); // c == 0 or 1. 954 // c = high64(t); // c == 0 or 1.
954 // } 955 // }
955 // return 1; 956 // return 2;
956 // } 957 // }
957 958
958 Label done; 959 Label done;
959 // RBX = x, done if x == 0 960 // RBX = x, done if x == 0
960 __ movq(RCX, Address(RSP, 7 * kWordSize)); // x_digits 961 __ movq(RCX, Address(RSP, 7 * kWordSize)); // x_digits
961 __ movq(RAX, Address(RSP, 6 * kWordSize)); // xi is Smi 962 __ movq(RAX, Address(RSP, 6 * kWordSize)); // xi is Smi
962 __ movl(RBX, FieldAddress(RCX, RAX, TIMES_2, TypedData::data_offset())); 963 __ movq(RBX, FieldAddress(RCX, RAX, TIMES_2, TypedData::data_offset()));
963 __ testl(RBX, RBX); 964 __ testq(RBX, RBX);
964 __ j(ZERO, &done, Assembler::kNearJump); 965 __ j(ZERO, &done, Assembler::kNearJump);
965 966
966 // R8 = SmiUntag(n), no_op if n == 0 967 // R8 = (SmiUntag(n) + 1)/2, no_op if n == 0
967 __ movq(R8, Address(RSP, 1 * kWordSize)); 968 __ movq(R8, Address(RSP, 1 * kWordSize));
968 __ SmiUntag(R8); 969 __ addq(R8, Immediate(2));
970 __ sarq(R8, Immediate(2)); // R8 = number of digit pairs to process.
969 __ j(ZERO, &done, Assembler::kNearJump); 971 __ j(ZERO, &done, Assembler::kNearJump);
970 972
971 // RDI = mip = &m_digits[i >> 1] 973 // RDI = mip = &m_digits[i >> 1]
972 __ movq(RDI, Address(RSP, 5 * kWordSize)); // m_digits 974 __ movq(RDI, Address(RSP, 5 * kWordSize)); // m_digits
973 __ movq(RAX, Address(RSP, 4 * kWordSize)); // i is Smi 975 __ movq(RAX, Address(RSP, 4 * kWordSize)); // i is Smi
974 __ leaq(RDI, FieldAddress(RDI, RAX, TIMES_2, TypedData::data_offset())); 976 __ leaq(RDI, FieldAddress(RDI, RAX, TIMES_2, TypedData::data_offset()));
975 977
976 // RSI = ajp = &a_digits[j >> 1] 978 // RSI = ajp = &a_digits[j >> 1]
977 __ movq(RSI, Address(RSP, 3 * kWordSize)); // a_digits 979 __ movq(RSI, Address(RSP, 3 * kWordSize)); // a_digits
978 __ movq(RAX, Address(RSP, 2 * kWordSize)); // j is Smi 980 __ movq(RAX, Address(RSP, 2 * kWordSize)); // j is Smi
979 __ leaq(RSI, FieldAddress(RSI, RAX, TIMES_2, TypedData::data_offset())); 981 __ leaq(RSI, FieldAddress(RSI, RAX, TIMES_2, TypedData::data_offset()));
980 982
981 // RCX = c = 0 983 // RCX = c = 0
982 __ xorq(RCX, RCX); 984 __ xorq(RCX, RCX);
983 985
984 Label muladd_loop; 986 Label muladd_loop;
985 __ Bind(&muladd_loop); 987 __ Bind(&muladd_loop);
986 // x: RBX 988 // x: RBX
987 // mip: RDI 989 // mip: RDI
988 // ajp: RSI 990 // ajp: RSI
989 // c: RCX 991 // c: RCX
990 // t: RDX:RAX (not live at loop entry) 992 // t: RDX:RAX (not live at loop entry)
991 // n: R8 993 // n: R8
992 994
993 // uint32_t mi = *mip++ 995 // uint64_t mi = *mip++
994 __ movl(RAX, Address(RDI, 0)); 996 __ movq(RAX, Address(RDI, 0));
995 __ addq(RDI, Immediate(Bigint::kBytesPerDigit)); 997 __ addq(RDI, Immediate(2*Bigint::kBytesPerDigit));
996 998
997 // uint64_t t = x*mi 999 // uint128_t t = x*mi
998 __ mull(RBX); // t = RDX:RAX = RAX * RBX, 32-bit * 32-bit -> 64-bit 1000 __ mulq(RBX); // t = RDX:RAX = RAX * RBX, 64-bit * 64-bit -> 64-bit
999 __ addl(RAX, RCX); // t += c 1001 __ addq(RAX, RCX); // t += c
1000 __ adcl(RDX, Immediate(0)); 1002 __ adcq(RDX, Immediate(0));
1001 1003
1002 // uint32_t aj = *ajp; t += aj 1004 // uint64_t aj = *ajp; t += aj
1003 __ addl(RAX, Address(RSI, 0)); 1005 __ addq(RAX, Address(RSI, 0));
1004 __ adcl(RDX, Immediate(0)); 1006 __ adcq(RDX, Immediate(0));
1005 1007
1006 // *ajp++ = low32(t) 1008 // *ajp++ = low64(t)
1007 __ movl(Address(RSI, 0), RAX); 1009 __ movq(Address(RSI, 0), RAX);
1008 __ addq(RSI, Immediate(Bigint::kBytesPerDigit)); 1010 __ addq(RSI, Immediate(2*Bigint::kBytesPerDigit));
1009 1011
1010 // c = high32(t) 1012 // c = high64(t)
1011 __ movl(RCX, RDX); 1013 __ movq(RCX, RDX);
1012 1014
1013 // while (--n > 0) 1015 // while (--n > 0)
1014 __ decq(R8); // --n 1016 __ decq(R8); // --n
1015 __ j(NOT_ZERO, &muladd_loop, Assembler::kNearJump); 1017 __ j(NOT_ZERO, &muladd_loop, Assembler::kNearJump);
1016 1018
1017 __ testl(RCX, RCX); 1019 __ testq(RCX, RCX);
1018 __ j(ZERO, &done, Assembler::kNearJump); 1020 __ j(ZERO, &done, Assembler::kNearJump);
1019 1021
1020 // *ajp += c 1022 // *ajp += c
1021 __ addl(Address(RSI, 0), RCX); 1023 __ addq(Address(RSI, 0), RCX);
1022 __ j(NOT_CARRY, &done, Assembler::kNearJump); 1024 __ j(NOT_CARRY, &done, Assembler::kNearJump);
1023 1025
1024 Label propagate_carry_loop; 1026 Label propagate_carry_loop;
1025 __ Bind(&propagate_carry_loop); 1027 __ Bind(&propagate_carry_loop);
1026 __ addq(RSI, Immediate(Bigint::kBytesPerDigit)); 1028 __ addq(RSI, Immediate(2*Bigint::kBytesPerDigit));
1027 __ incl(Address(RSI, 0)); // c == 0 or 1 1029 __ incq(Address(RSI, 0)); // c == 0 or 1
1028 __ j(CARRY, &propagate_carry_loop, Assembler::kNearJump); 1030 __ j(CARRY, &propagate_carry_loop, Assembler::kNearJump);
1029 1031
1030 __ Bind(&done); 1032 __ Bind(&done);
1031 __ movq(RAX, Immediate(Smi::RawValue(1))); // One digit processed. 1033 __ movq(RAX, Immediate(Smi::RawValue(2))); // Two digits processed.
1032 __ ret(); 1034 __ ret();
1033 } 1035 }
1034 1036
1035 1037
1036 void Intrinsifier::Bigint_sqrAdd(Assembler* assembler) { 1038 void Intrinsifier::Bigint_sqrAdd(Assembler* assembler) {
1037 // Pseudo code: 1039 // Pseudo code:
1038 // static int _sqrAdd(Uint32List x_digits, int i, 1040 // static int _sqrAdd(Uint32List x_digits, int i,
1039 // Uint32List a_digits, int used) { 1041 // Uint32List a_digits, int used) {
1040 // uint32_t* xip = &x_digits[i >> 1]; // i is Smi. 1042 // uint64_t* xip = &x_digits[i >> 1]; // i is Smi and even.
1041 // uint32_t x = *xip++; 1043 // uint64_t x = *xip++;
1042 // if (x == 0) return 1; 1044 // if (x == 0) return 2;
1043 // uint32_t* ajp = &a_digits[i]; // j == 2*i, i is Smi. 1045 // uint64_t* ajp = &a_digits[i]; // j == 2*i, i is Smi.
1044 // uint32_t aj = *ajp; 1046 // uint64_t aj = *ajp;
1045 // uint64_t t = x*x + aj; 1047 // uint128_t t = x*x + aj;
1046 // *ajp++ = low32(t); 1048 // *ajp++ = low64(t);
1047 // uint64_t c = high32(t); 1049 // uint128_t c = high64(t);
1048 // int n = ((used - i) >> 1) - 1; // used and i are Smi. 1050 // int n = ((used - i + 2) >> 2) - 1; // used and i are Smi. n: num pairs.
1049 // while (--n >= 0) { 1051 // while (--n >= 0) {
1050 // uint32_t xi = *xip++; 1052 // uint64_t xi = *xip++;
1051 // uint32_t aj = *ajp; 1053 // uint64_t aj = *ajp;
1052 // uint96_t t = 2*x*xi + aj + c; // 2-bit * 32-bit * 32-bit -> 65-bit. 1054 // uint192_t t = 2*x*xi + aj + c; // 2-bit * 64-bit * 64-bit -> 129-bit.
1053 // *ajp++ = low32(t); 1055 // *ajp++ = low64(t);
1054 // c = high64(t); // 33-bit. 1056 // c = high128(t); // 65-bit.
1055 // } 1057 // }
1056 // uint32_t aj = *ajp; 1058 // uint64_t aj = *ajp;
1057 // uint64_t t = aj + c; // 32-bit + 33-bit -> 34-bit. 1059 // uint128_t t = aj + c; // 64-bit + 65-bit -> 66-bit.
1058 // *ajp++ = low32(t); 1060 // *ajp++ = low64(t);
1059 // *ajp = high32(t); 1061 // *ajp = high64(t);
1060 // return 1; 1062 // return 2;
1061 // } 1063 // }
1062 1064
1063 // RDI = xip = &x_digits[i >> 1] 1065 // RDI = xip = &x_digits[i >> 1]
1064 __ movq(RDI, Address(RSP, 4 * kWordSize)); // x_digits 1066 __ movq(RDI, Address(RSP, 4 * kWordSize)); // x_digits
1065 __ movq(RAX, Address(RSP, 3 * kWordSize)); // i is Smi 1067 __ movq(RAX, Address(RSP, 3 * kWordSize)); // i is Smi
1066 __ leaq(RDI, FieldAddress(RDI, RAX, TIMES_2, TypedData::data_offset())); 1068 __ leaq(RDI, FieldAddress(RDI, RAX, TIMES_2, TypedData::data_offset()));
1067 1069
1068 // RBX = x = *xip++, return if x == 0 1070 // RBX = x = *xip++, return if x == 0
1069 Label x_zero; 1071 Label x_zero;
1070 __ movl(RBX, Address(RDI, 0)); 1072 __ movq(RBX, Address(RDI, 0));
1071 __ cmpl(RBX, Immediate(0)); 1073 __ cmpq(RBX, Immediate(0));
1072 __ j(EQUAL, &x_zero, Assembler::kNearJump); 1074 __ j(EQUAL, &x_zero);
1073 __ addq(RDI, Immediate(Bigint::kBytesPerDigit)); 1075 __ addq(RDI, Immediate(2*Bigint::kBytesPerDigit));
1074 1076
1075 // RSI = ajp = &a_digits[i] 1077 // RSI = ajp = &a_digits[i]
1076 __ movq(RSI, Address(RSP, 2 * kWordSize)); // a_digits 1078 __ movq(RSI, Address(RSP, 2 * kWordSize)); // a_digits
1077 __ leaq(RSI, FieldAddress(RSI, RAX, TIMES_4, TypedData::data_offset())); 1079 __ leaq(RSI, FieldAddress(RSI, RAX, TIMES_4, TypedData::data_offset()));
1078 1080
1079 // RDX:RAX = t = x*x + *ajp 1081 // RDX:RAX = t = x*x + *ajp
1080 __ movl(RAX, RBX); 1082 __ movq(RAX, RBX);
1081 __ mull(RBX); 1083 __ mulq(RBX);
1082 __ addl(RAX, Address(RSI, 0)); 1084 __ addq(RAX, Address(RSI, 0));
1083 __ adcl(RDX, Immediate(0)); 1085 __ adcq(RDX, Immediate(0));
1084 1086
1085 // *ajp++ = low32(t) 1087 // *ajp++ = low64(t)
1086 __ movl(Address(RSI, 0), RAX); 1088 __ movq(Address(RSI, 0), RAX);
1087 __ addq(RSI, Immediate(Bigint::kBytesPerDigit)); 1089 __ addq(RSI, Immediate(2*Bigint::kBytesPerDigit));
1088 1090
1089 // int n = used - i - 1 1091 // int n = (used - i + 1)/2 - 1
1090 __ movq(R8, Address(RSP, 1 * kWordSize)); // used is Smi 1092 __ movq(R8, Address(RSP, 1 * kWordSize)); // used is Smi
1091 __ subq(R8, Address(RSP, 3 * kWordSize)); // i is Smi 1093 __ subq(R8, Address(RSP, 3 * kWordSize)); // i is Smi
1092 __ SmiUntag(R8); 1094 __ addq(R8, Immediate(2));
1093 __ decq(R8); 1095 __ sarq(R8, Immediate(2));
1096 __ decq(R8); // R8 = number of digit pairs to process.
1094 1097
1095 // uint64_t c = high32(t) 1098 // uint128_t c = high64(t)
1096 __ xorl(R13, R13); // R13 = high32(c) == 0 1099 __ xorq(R13, R13); // R13 = high64(c) == 0
1097 __ movl(R12, RDX); // R12 = low32(c) == high32(t) 1100 __ movq(R12, RDX); // R12 = low64(c) == high64(t)
1098 1101
1099 Label loop, done; 1102 Label loop, done;
1100 __ Bind(&loop); 1103 __ Bind(&loop);
1101 // x: RBX 1104 // x: RBX
1102 // xip: RDI 1105 // xip: RDI
1103 // ajp: RSI 1106 // ajp: RSI
1104 // c: R13:R12 1107 // c: R13:R12
1105 // t: RCX:RDX:RAX (not live at loop entry) 1108 // t: RCX:RDX:RAX (not live at loop entry)
1106 // n: R8 1109 // n: R8
1107 1110
1108 // while (--n >= 0) 1111 // while (--n >= 0)
1109 __ decq(R8); // --n 1112 __ decq(R8); // --n
1110 __ j(NEGATIVE, &done, Assembler::kNearJump); 1113 __ j(NEGATIVE, &done, Assembler::kNearJump);
1111 1114
1112 // uint32_t xi = *xip++ 1115 // uint64_t xi = *xip++
1113 __ movl(RAX, Address(RDI, 0)); 1116 __ movq(RAX, Address(RDI, 0));
1114 __ addq(RDI, Immediate(Bigint::kBytesPerDigit)); 1117 __ addq(RDI, Immediate(2*Bigint::kBytesPerDigit));
1115 1118
1116 // uint96_t t = RCX:RDX:RAX = 2*x*xi + aj + c 1119 // uint192_t t = RCX:RDX:RAX = 2*x*xi + aj + c
1117 __ mull(RBX); // RDX:RAX = RAX * RBX 1120 __ mulq(RBX); // RDX:RAX = RAX * RBX
1118 __ xorl(RCX, RCX); // RCX = 0 1121 __ xorq(RCX, RCX); // RCX = 0
1119 __ shldl(RCX, RDX, Immediate(1)); 1122 __ shldq(RCX, RDX, Immediate(1));
1120 __ shldl(RDX, RAX, Immediate(1)); 1123 __ shldq(RDX, RAX, Immediate(1));
1121 __ shll(RAX, Immediate(1)); // RCX:RDX:RAX <<= 1 1124 __ shlq(RAX, Immediate(1)); // RCX:RDX:RAX <<= 1
1122 __ addl(RAX, Address(RSI, 0)); // t += aj 1125 __ addq(RAX, Address(RSI, 0)); // t += aj
1123 __ adcl(RDX, Immediate(0)); 1126 __ adcq(RDX, Immediate(0));
1124 __ adcl(RCX, Immediate(0)); 1127 __ adcq(RCX, Immediate(0));
1125 __ addl(RAX, R12); // t += low32(c) 1128 __ addq(RAX, R12); // t += low64(c)
1126 __ adcl(RDX, R13); // t += high32(c) << 32 1129 __ adcq(RDX, R13); // t += high64(c) << 64
1127 __ adcl(RCX, Immediate(0)); 1130 __ adcq(RCX, Immediate(0));
1128 1131
1129 // *ajp++ = low32(t) 1132 // *ajp++ = low64(t)
1130 __ movl(Address(RSI, 0), RAX); 1133 __ movq(Address(RSI, 0), RAX);
1131 __ addq(RSI, Immediate(Bigint::kBytesPerDigit)); 1134 __ addq(RSI, Immediate(2*Bigint::kBytesPerDigit));
1132 1135
1133 // c = high64(t) 1136 // c = high64(t)
1134 __ movl(R12, RDX); 1137 __ movq(R12, RDX);
1135 __ movl(R13, RCX); 1138 __ movq(R13, RCX);
1136 1139
1137 __ jmp(&loop, Assembler::kNearJump); 1140 __ jmp(&loop, Assembler::kNearJump);
1138 1141
1139 __ Bind(&done); 1142 __ Bind(&done);
1140 // uint64_t t = aj + c 1143 // uint128_t t = aj + c
1141 __ addl(R12, Address(RSI, 0)); // t = c, t += *ajp 1144 __ addq(R12, Address(RSI, 0)); // t = c, t += *ajp
1142 __ adcl(R13, Immediate(0)); 1145 __ adcq(R13, Immediate(0));
1143 1146
1144 // *ajp++ = low32(t) 1147 // *ajp++ = low64(t)
1145 // *ajp = high32(t) 1148 // *ajp = high64(t)
1146 __ movl(Address(RSI, 0), R12); 1149 __ movq(Address(RSI, 0), R12);
1147 __ movl(Address(RSI, Bigint::kBytesPerDigit), R13); 1150 __ movq(Address(RSI, 2*Bigint::kBytesPerDigit), R13);
1148 1151
1149 __ Bind(&x_zero); 1152 __ Bind(&x_zero);
1150 __ movq(RAX, Immediate(Smi::RawValue(1))); // One digit processed. 1153 __ movq(RAX, Immediate(Smi::RawValue(2))); // Two digits processed.
1151 __ ret(); 1154 __ ret();
1152 } 1155 }
1153 1156
1154 1157
1155 void Intrinsifier::Bigint_estQuotientDigit(Assembler* assembler) { 1158 void Intrinsifier::Bigint_estQuotientDigit(Assembler* assembler) {
1156 // Pseudo code: 1159 // Pseudo code:
1157 // static int _estQuotientDigit(Uint32List args, Uint32List digits, int i) { 1160 // static int _estQuotientDigit(Uint32List args, Uint32List digits, int i) {
1158 // uint32_t yt = args[_YT]; // _YT == 1. 1161 // uint64_t yt = args[_YT_LO .. _YT]; // _YT_LO == 0, _YT == 1.
1159 // uint32_t* dp = &digits[i >> 1]; // i is Smi. 1162 // uint64_t* dp = &digits[(i >> 1) - 1]; // i is Smi.
1160 // uint32_t dh = dp[0]; // dh == digits[i >> 1]. 1163 // uint64_t dh = dp[0]; // dh == digits[(i >> 1) - 1 .. i >> 1].
1161 // uint32_t qd; 1164 // uint64_t qd;
1162 // if (dh == yt) { 1165 // if (dh == yt) {
1163 // qd = DIGIT_MASK; 1166 // qd = (DIGIT_MASK << 32) | DIGIT_MASK;
1164 // } else { 1167 // } else {
1165 // dl = dp[-1]; // dl == digits[(i - 1) >> 1]. 1168 // dl = dp[-1]; // dl == digits[(i >> 1) - 3 .. (i >> 1) - 2].
1166 // qd = dh:dl / yt; // No overflow possible, because dh < yt. 1169 // qd = dh:dl / yt; // No overflow possible, because dh < yt.
1167 // } 1170 // }
1168 // args[_QD] = qd; // _QD == 2. 1171 // args[_QD .. _QD_HI] = qd; // _QD == 2, _QD_HI == 3.
1169 // return 1; 1172 // return 2;
1170 // } 1173 // }
1171 1174
1172 // RDI = args 1175 // RDI = args
1173 __ movq(RDI, Address(RSP, 3 * kWordSize)); // args 1176 __ movq(RDI, Address(RSP, 3 * kWordSize)); // args
1174 1177
1175 // RCX = yt = args[1] 1178 // RCX = yt = args[0..1]
1176 __ movl(RCX, 1179 __ movq(RCX, FieldAddress(RDI, TypedData::data_offset()));
1177 FieldAddress(RDI, TypedData::data_offset() + Bigint::kBytesPerDigit));
1178 1180
1179 // RBX = dp = &digits[i >> 1] 1181 // RBX = dp = &digits[(i >> 1) - 1]
1180 __ movq(RBX, Address(RSP, 2 * kWordSize)); // digits 1182 __ movq(RBX, Address(RSP, 2 * kWordSize)); // digits
1181 __ movq(RAX, Address(RSP, 1 * kWordSize)); // i is Smi 1183 __ movq(RAX, Address(RSP, 1 * kWordSize)); // i is Smi and odd.
1182 __ leaq(RBX, FieldAddress(RBX, RAX, TIMES_2, TypedData::data_offset())); 1184 __ leaq(RBX, FieldAddress(RBX, RAX, TIMES_2,
1185 TypedData::data_offset() - Bigint::kBytesPerDigit));
1183 1186
1184 // RDX = dh = dp[0] 1187 // RDX = dh = dp[0]
1185 __ movl(RDX, Address(RBX, 0)); 1188 __ movq(RDX, Address(RBX, 0));
1186 1189
1187 // RAX = qd = DIGIT_MASK = -1 1190 // RAX = qd = (DIGIT_MASK << 32) | DIGIT_MASK = -1
1188 __ movl(RAX, Immediate(-1)); 1191 __ movq(RAX, Immediate(-1));
1189 1192
1190 // Return qd if dh == yt 1193 // Return qd if dh == yt
1191 Label return_qd; 1194 Label return_qd;
1192 __ cmpl(RDX, RCX); 1195 __ cmpq(RDX, RCX);
1193 __ j(EQUAL, &return_qd, Assembler::kNearJump); 1196 __ j(EQUAL, &return_qd, Assembler::kNearJump);
1194 1197
1195 // RAX = dl = dp[-1] 1198 // RAX = dl = dp[-1]
1196 __ movl(RAX, Address(RBX, -Bigint::kBytesPerDigit)); 1199 __ movq(RAX, Address(RBX, -2*Bigint::kBytesPerDigit));
1197 1200
1198 // RAX = qd = dh:dl / yt = RDX:RAX / RCX 1201 // RAX = qd = dh:dl / yt = RDX:RAX / RCX
1199 __ divl(RCX); 1202 __ divq(RCX);
1200 1203
1201 __ Bind(&return_qd); 1204 __ Bind(&return_qd);
1202 // args[2] = qd 1205 // args[2..3] = qd
1203 __ movl(FieldAddress(RDI, 1206 __ movq(FieldAddress(RDI,
1204 TypedData::data_offset() + 2*Bigint::kBytesPerDigit), 1207 TypedData::data_offset() + 2*Bigint::kBytesPerDigit),
1205 RAX); 1208 RAX);
1206 1209
1207 __ movq(RAX, Immediate(Smi::RawValue(1))); // One digit processed. 1210 __ movq(RAX, Immediate(Smi::RawValue(2))); // Two digits processed.
1208 __ ret(); 1211 __ ret();
1209 } 1212 }
1210 1213
1211 1214
1212 void Intrinsifier::Montgomery_mulMod(Assembler* assembler) { 1215 void Intrinsifier::Montgomery_mulMod(Assembler* assembler) {
1213 // Pseudo code: 1216 // Pseudo code:
1214 // static int _mulMod(Uint32List args, Uint32List digits, int i) { 1217 // static int _mulMod(Uint32List args, Uint32List digits, int i) {
1215 // uint32_t rho = args[_RHO]; // _RHO == 2. 1218 // uint64_t rho = args[_RHO .. _RHO_HI]; // _RHO == 2, _RHO_HI == 3.
1216 // uint32_t d = digits[i >> 1]; // i is Smi. 1219 // uint64_t d = digits[i >> 1 .. (i >> 1) + 1]; // i is Smi and even.
1217 // uint64_t t = rho*d; 1220 // uint128_t t = rho*d;
1218 // args[_MU] = t mod DIGIT_BASE; // _MU == 4. 1221 // args[_MU .. _MU_HI] = t mod DIGIT_BASE^2; // _MU == 4, _MU_HI == 5.
1219 // return 1; 1222 // return 2;
1220 // } 1223 // }
1221 1224
1222 // RDI = args 1225 // RDI = args
1223 __ movq(RDI, Address(RSP, 3 * kWordSize)); // args 1226 __ movq(RDI, Address(RSP, 3 * kWordSize)); // args
1224 1227
1225 // RCX = rho = args[2] 1228 // RCX = rho = args[2 .. 3]
1226 __ movl(RCX, 1229 __ movq(RCX,
1227 FieldAddress(RDI, 1230 FieldAddress(RDI,
1228 TypedData::data_offset() + 2*Bigint::kBytesPerDigit)); 1231 TypedData::data_offset() + 2*Bigint::kBytesPerDigit));
1229 1232
1230 // RAX = digits[i >> 1] 1233 // RAX = digits[i >> 1 .. (i >> 1) + 1]
1231 __ movq(RBX, Address(RSP, 2 * kWordSize)); // digits 1234 __ movq(RBX, Address(RSP, 2 * kWordSize)); // digits
1232 __ movq(RAX, Address(RSP, 1 * kWordSize)); // i is Smi 1235 __ movq(RAX, Address(RSP, 1 * kWordSize)); // i is Smi
1233 __ movl(RAX, FieldAddress(RBX, RAX, TIMES_2, TypedData::data_offset())); 1236 __ movq(RAX, FieldAddress(RBX, RAX, TIMES_2, TypedData::data_offset()));
1234 1237
1235 // RDX:RAX = t = rho*d 1238 // RDX:RAX = t = rho*d
1236 __ mull(RCX); 1239 __ mulq(RCX);
1237 1240
1238 // args[4] = t mod DIGIT_BASE = low32(t) 1241 // args[4 .. 5] = t mod DIGIT_BASE^2 = low64(t)
1239 __ movl(FieldAddress(RDI, 1242 __ movq(FieldAddress(RDI,
1240 TypedData::data_offset() + 4*Bigint::kBytesPerDigit), 1243 TypedData::data_offset() + 4*Bigint::kBytesPerDigit),
1241 RAX); 1244 RAX);
1242 1245
1243 __ movq(RAX, Immediate(Smi::RawValue(1))); // One digit processed. 1246 __ movq(RAX, Immediate(Smi::RawValue(2))); // Two digits processed.
1244 __ ret(); 1247 __ ret();
1245 } 1248 }
1246 1249
1247 1250
1248 // Check if the last argument is a double, jump to label 'is_smi' if smi 1251 // Check if the last argument is a double, jump to label 'is_smi' if smi
1249 // (easy to convert to double), otherwise jump to label 'not_double_smi', 1252 // (easy to convert to double), otherwise jump to label 'not_double_smi',
1250 // Returns the last argument in RAX. 1253 // Returns the last argument in RAX.
1251 static void TestLastArgumentIsDouble(Assembler* assembler, 1254 static void TestLastArgumentIsDouble(Assembler* assembler,
1252 Label* is_smi, 1255 Label* is_smi,
1253 Label* not_double_smi) { 1256 Label* not_double_smi) {
(...skipping 752 matching lines...) Expand 10 before | Expand all | Expand 10 after
2006 // Set return value to Isolate::current_tag_. 2009 // Set return value to Isolate::current_tag_.
2007 __ movq(RAX, Address(RBX, Isolate::current_tag_offset())); 2010 __ movq(RAX, Address(RBX, Isolate::current_tag_offset()));
2008 __ ret(); 2011 __ ret();
2009 } 2012 }
2010 2013
2011 #undef __ 2014 #undef __
2012 2015
2013 } // namespace dart 2016 } // namespace dart
2014 2017
2015 #endif // defined TARGET_ARCH_X64 2018 #endif // defined TARGET_ARCH_X64
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698