Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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_ARM64. | 5 #include "vm/globals.h" // Needed here to get TARGET_ARCH_ARM64. |
| 6 #if defined(TARGET_ARCH_ARM64) | 6 #if defined(TARGET_ARCH_ARM64) |
| 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 913 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 924 // Returning Object::null() is not required, since this method is private. | 924 // Returning Object::null() is not required, since this method is private. |
| 925 __ ret(); | 925 __ ret(); |
| 926 } | 926 } |
| 927 | 927 |
| 928 | 928 |
| 929 void Intrinsifier::Bigint_mulAdd(Assembler* assembler) { | 929 void Intrinsifier::Bigint_mulAdd(Assembler* assembler) { |
| 930 // Pseudo code: | 930 // Pseudo code: |
| 931 // static int _mulAdd(Uint32List x_digits, int xi, | 931 // static int _mulAdd(Uint32List x_digits, int xi, |
| 932 // Uint32List m_digits, int i, | 932 // Uint32List m_digits, int i, |
| 933 // Uint32List a_digits, int j, int n) { | 933 // Uint32List a_digits, int j, int n) { |
| 934 // uint32_t x = x_digits[xi >> 1]; // xi is Smi. | 934 // uint64_t x = x_digits[xi >> 1 .. (xi >> 1) + 1]; // xi is Smi and even. |
| 935 // if (x == 0 || n == 0) { | 935 // if (x == 0 || n == 0) { |
| 936 // return 1; | 936 // return 2; |
| 937 // } | 937 // } |
| 938 // uint32_t* mip = &m_digits[i >> 1]; // i is Smi. | 938 // uint64_t* mip = &m_digits[i >> 1]; // i is Smi and even. |
| 939 // uint32_t* ajp = &a_digits[j >> 1]; // j is Smi. | 939 // uint64_t* ajp = &a_digits[j >> 1]; // j is Smi and even. |
| 940 // uint32_t c = 0; | 940 // uint64_t c = 0; |
| 941 // SmiUntag(n); | 941 // SmiUntag(n); // n is Smi and even. |
| 942 // n = (n + 1)/2; // Number of pairs to process. | |
| 942 // do { | 943 // do { |
| 943 // uint32_t mi = *mip++; | 944 // uint64_t mi = *mip++; |
| 944 // uint32_t aj = *ajp; | 945 // uint364_t aj = *ajp; |
| 945 // uint64_t t = x*mi + aj + c; // 32-bit * 32-bit -> 64-bit. | 946 // uint128_t t = x*mi + aj + c; // 64-bit * 64-bit -> 128-bit. |
| 946 // *ajp++ = low32(t); | 947 // *ajp++ = low64(t); |
| 947 // c = high32(t); | 948 // c = high64(t); |
| 948 // } while (--n > 0); | 949 // } while (--n > 0); |
| 949 // while (c != 0) { | 950 // while (c != 0) { |
| 950 // uint64_t t = *ajp + c; | 951 // uint128_t t = *ajp + c; |
| 951 // *ajp++ = low32(t); | 952 // *ajp++ = low64(t); |
| 952 // c = high32(t); // c == 0 or 1. | 953 // c = high64(t); // c == 0 or 1. |
| 953 // } | 954 // } |
| 954 // return 1; | 955 // return 2; |
| 955 // } | 956 // } |
| 956 | 957 |
| 957 Label done; | 958 Label done; |
| 958 // R3 = x, no_op if x == 0 | 959 // R3 = x, no_op if x == 0 |
| 959 // R0 = xi as Smi, R1 = x_digits. | 960 // R0 = xi as Smi, R1 = x_digits. |
| 960 __ ldp(R0, R1, Address(SP, 5 * kWordSize, Address::PairOffset)); | 961 __ ldp(R0, R1, Address(SP, 5 * kWordSize, Address::PairOffset)); |
| 961 __ add(R1, R1, Operand(R0, LSL, 1)); | 962 __ add(R1, R1, Operand(R0, LSL, 1)); |
| 962 __ ldr(R3, FieldAddress(R1, TypedData::data_offset()), kUnsignedWord); | 963 __ ldr(R3, FieldAddress(R1, TypedData::data_offset())); |
| 963 __ tst(R3, Operand(R3)); | 964 __ tst(R3, Operand(R3)); |
| 964 __ b(&done, EQ); | 965 __ b(&done, EQ); |
| 965 | 966 |
| 966 // R6 = SmiUntag(n), no_op if n == 0 | 967 // R6 = (SmiUntag(n) + 1)/2, no_op if n == 0 |
| 967 __ ldr(R6, Address(SP, 0 * kWordSize)); | 968 __ ldr(R6, Address(SP, 0 * kWordSize)); |
| 968 __ adds(R6, ZR, Operand(R6, ASR, kSmiTagSize)); // SmiUntag(R6) and set cc. | 969 __ add(R6, R6, Operand(2)); |
| 970 __ adds(R6, ZR, Operand(R6, ASR, 2)); // SmiUntag(R6) and set cc. | |
| 969 __ b(&done, EQ); | 971 __ b(&done, EQ); |
| 970 | 972 |
| 971 // R4 = mip = &m_digits[i >> 1] | 973 // R4 = mip = &m_digits[i >> 1] |
| 972 // R0 = i as Smi, R1 = m_digits. | 974 // R0 = i as Smi, R1 = m_digits. |
| 973 __ ldp(R0, R1, Address(SP, 3 * kWordSize, Address::PairOffset)); | 975 __ ldp(R0, R1, Address(SP, 3 * kWordSize, Address::PairOffset)); |
| 974 __ add(R1, R1, Operand(R0, LSL, 1)); | 976 __ add(R1, R1, Operand(R0, LSL, 1)); |
| 975 __ add(R4, R1, Operand(TypedData::data_offset() - kHeapObjectTag)); | 977 __ add(R4, R1, Operand(TypedData::data_offset() - kHeapObjectTag)); |
| 976 | 978 |
| 977 // R5 = ajp = &a_digits[j >> 1] | 979 // R5 = ajp = &a_digits[j >> 1] |
| 978 // R0 = j as Smi, R1 = a_digits. | 980 // R0 = j as Smi, R1 = a_digits. |
| 979 __ ldp(R0, R1, Address(SP, 1 * kWordSize, Address::PairOffset)); | 981 __ ldp(R0, R1, Address(SP, 1 * kWordSize, Address::PairOffset)); |
| 980 __ add(R1, R1, Operand(R0, LSL, 1)); | 982 __ add(R1, R1, Operand(R0, LSL, 1)); |
| 981 __ add(R5, R1, Operand(TypedData::data_offset() - kHeapObjectTag)); | 983 __ add(R5, R1, Operand(TypedData::data_offset() - kHeapObjectTag)); |
| 982 | 984 |
| 983 // R1 = c = 0 | 985 // R1 = c = 0 |
| 984 __ mov(R1, ZR); | 986 __ mov(R1, ZR); |
| 985 | 987 |
| 986 Label muladd_loop; | 988 Label muladd_loop; |
| 987 __ Bind(&muladd_loop); | 989 __ Bind(&muladd_loop); |
| 988 // x: R3 | 990 // x: R3 |
| 989 // mip: R4 | 991 // mip: R4 |
| 990 // ajp: R5 | 992 // ajp: R5 |
| 991 // c: R1 | 993 // c: R1 |
| 992 // n: R6 | 994 // n: R6 |
| 995 // t: R7:R8 (not live at loop entry) | |
| 993 | 996 |
| 994 // uint32_t mi = *mip++ | 997 // uint64_t mi = *mip++ |
| 995 __ ldr(R2, Address(R4, Bigint::kBytesPerDigit, Address::PostIndex), | 998 __ ldr(R2, Address(R4, 2*Bigint::kBytesPerDigit, Address::PostIndex)); |
| 996 kUnsignedWord); | |
| 997 | 999 |
| 998 // uint32_t aj = *ajp | 1000 // uint64_t aj = *ajp |
| 999 __ ldr(R0, Address(R5, 0), kUnsignedWord); | 1001 __ ldr(R0, Address(R5, 0)); |
| 1000 | 1002 |
| 1001 // uint64_t t = x*mi + aj + c | 1003 // uint128_t t = x*mi + aj + c |
| 1002 __ umaddl(R0, R2, R3, R0); // X0 = W2*W3 + X0. | 1004 __ mul(R7, R2, R3); // R7 = low64(R2*R3). |
| 1003 __ add(R0, R0, Operand(R1)); // R0 += c. | 1005 __ umulh(R8, R2, R3); // R8 = high64(R2*R3), t = R8:R7 = x*mi. |
| 1006 __ adds(R7, R7, Operand(R0)); | |
| 1007 __ adc(R8, R8, ZR); // t += aj. | |
| 1008 __ adds(R0, R7, Operand(R1)); // t += c, R0 = low64(t). | |
| 1009 __ adc(R1, R8, ZR); // c = R1 = high64(t). | |
| 1004 | 1010 |
| 1005 // *ajp++ = low32(t) = R0 | 1011 // *ajp++ = low64(t) = R0 |
| 1006 __ str(R0, Address(R5, Bigint::kBytesPerDigit, Address::PostIndex), | 1012 __ str(R0, Address(R5, 2*Bigint::kBytesPerDigit, Address::PostIndex)); |
| 1007 kUnsignedWord); | |
| 1008 | |
| 1009 // c = R1 = high32(t) = R0 >> 32. | |
| 1010 __ LsrImmediate(R1, R0, 32); | |
| 1011 | 1013 |
| 1012 // while (--n > 0) | 1014 // while (--n > 0) |
| 1013 __ subs(R6, R6, Operand(1)); // --n | 1015 __ subs(R6, R6, Operand(1)); // --n |
| 1014 __ b(&muladd_loop, NE); | 1016 __ b(&muladd_loop, NE); |
| 1015 | 1017 |
| 1016 __ tst(R1, Operand(R1)); | 1018 __ tst(R1, Operand(R1)); |
| 1017 __ b(&done, EQ); | 1019 __ b(&done, EQ); |
| 1018 | 1020 |
| 1019 // *ajp++ += c | 1021 // *ajp++ += c |
| 1020 __ ldr(R0, Address(R5, 0), kUnsignedWord); | 1022 __ ldr(R0, Address(R5, 0)); |
| 1021 __ addsw(R0, R0, Operand(R1)); | 1023 __ adds(R0, R0, Operand(R1)); |
| 1022 __ str(R0, Address(R5, Bigint::kBytesPerDigit, Address::PostIndex), | 1024 __ str(R0, Address(R5, 2*Bigint::kBytesPerDigit, Address::PostIndex)); |
| 1023 kUnsignedWord); | |
| 1024 __ b(&done, CC); | 1025 __ b(&done, CC); |
| 1025 | 1026 |
| 1026 Label propagate_carry_loop; | 1027 Label propagate_carry_loop; |
| 1027 __ Bind(&propagate_carry_loop); | 1028 __ Bind(&propagate_carry_loop); |
| 1028 __ ldr(R0, Address(R5, 0), kUnsignedWord); | 1029 __ ldr(R0, Address(R5, 0)); |
| 1029 __ addsw(R0, R0, Operand(1)); | 1030 __ adds(R0, R0, Operand(1)); |
| 1030 __ str(R0, Address(R5, Bigint::kBytesPerDigit, Address::PostIndex), | 1031 __ str(R0, Address(R5, 2*Bigint::kBytesPerDigit, Address::PostIndex)); |
| 1031 kUnsignedWord); | |
| 1032 __ b(&propagate_carry_loop, CS); | 1032 __ b(&propagate_carry_loop, CS); |
| 1033 | 1033 |
| 1034 __ Bind(&done); | 1034 __ Bind(&done); |
| 1035 __ LoadImmediate(R0, Smi::RawValue(1), kNoPP); // One digit processed. | 1035 __ LoadImmediate(R0, Smi::RawValue(2), kNoPP); // Two digits processed. |
| 1036 __ ret(); | 1036 __ ret(); |
| 1037 } | 1037 } |
| 1038 | 1038 |
| 1039 | 1039 |
| 1040 void Intrinsifier::Bigint_sqrAdd(Assembler* assembler) { | 1040 void Intrinsifier::Bigint_sqrAdd(Assembler* assembler) { |
| 1041 // Pseudo code: | 1041 // Pseudo code: |
| 1042 // static int _sqrAdd(Uint32List x_digits, int i, | 1042 // static int _sqrAdd(Uint32List x_digits, int i, |
| 1043 // Uint32List a_digits, int used) { | 1043 // Uint32List a_digits, int used) { |
| 1044 // uint32_t* xip = &x_digits[i >> 1]; // i is Smi. | 1044 // uint64_t* xip = &x_digits[i >> 1]; // i is Smi and even. |
| 1045 // uint32_t x = *xip++; | 1045 // uint64_t x = *xip++; |
| 1046 // if (x == 0) return 1; | 1046 // if (x == 0) return 2; |
| 1047 // uint32_t* ajp = &a_digits[i]; // j == 2*i, i is Smi. | 1047 // uint64_t* ajp = &a_digits[i]; // j == 2*i, i is Smi. |
| 1048 // uint32_t aj = *ajp; | 1048 // uint64_t aj = *ajp; |
| 1049 // uint64_t t = x*x + aj; | 1049 // uint128_t t = x*x + aj; |
| 1050 // *ajp++ = low32(t); | 1050 // *ajp++ = low64(t); |
| 1051 // uint64_t c = high32(t); | 1051 // uint128_t c = high64(t); |
| 1052 // int n = ((used - i) >> 1) - 1; // used and i are Smi. | 1052 // int n = ((used - i + 2) >> 2) - 1; // used and i are Smi. n: num pairs. |
| 1053 // while (--n >= 0) { | 1053 // while (--n >= 0) { |
| 1054 // uint32_t xi = *xip++; | 1054 // uint64_t xi = *xip++; |
| 1055 // uint32_t aj = *ajp; | 1055 // uint64_t aj = *ajp; |
| 1056 // uint96_t t = 2*x*xi + aj + c; // 2-bit * 32-bit * 32-bit -> 65-bit. | 1056 // uint192_t t = 2*x*xi + aj + c; // 2-bit * 64-bit * 64-bit -> 129-bit. |
| 1057 // *ajp++ = low32(t); | 1057 // *ajp++ = low64(t); |
| 1058 // c = high64(t); // 33-bit. | 1058 // c = high128(t); // 65-bit. |
| 1059 // } | 1059 // } |
| 1060 // uint32_t aj = *ajp; | 1060 // uint64_t aj = *ajp; |
| 1061 // uint64_t t = aj + c; // 32-bit + 33-bit -> 34-bit. | 1061 // uint128_t t = aj + c; // 64-bit + 65-bit -> 66-bit. |
| 1062 // *ajp++ = low32(t); | 1062 // *ajp++ = low64(t); |
| 1063 // *ajp = high32(t); | 1063 // *ajp = high64(t); |
| 1064 // return 1; | 1064 // return 2; |
| 1065 // } | 1065 // } |
| 1066 | 1066 |
| 1067 // R4 = xip = &x_digits[i >> 1] | 1067 // R4 = xip = &x_digits[i >> 1] |
| 1068 // R2 = i as Smi, R3 = x_digits | 1068 // R2 = i as Smi, R3 = x_digits |
| 1069 __ ldp(R2, R3, Address(SP, 2 * kWordSize, Address::PairOffset)); | 1069 __ ldp(R2, R3, Address(SP, 2 * kWordSize, Address::PairOffset)); |
| 1070 __ add(R3, R3, Operand(R2, LSL, 1)); | 1070 __ add(R3, R3, Operand(R2, LSL, 1)); |
| 1071 __ add(R4, R3, Operand(TypedData::data_offset() - kHeapObjectTag)); | 1071 __ add(R4, R3, Operand(TypedData::data_offset() - kHeapObjectTag)); |
| 1072 | 1072 |
| 1073 // R3 = x = *xip++, return if x == 0 | 1073 // R3 = x = *xip++, return if x == 0 |
| 1074 Label x_zero; | 1074 Label x_zero; |
| 1075 __ ldr(R3, Address(R4, Bigint::kBytesPerDigit, Address::PostIndex), | 1075 __ ldr(R3, Address(R4, 2*Bigint::kBytesPerDigit, Address::PostIndex)); |
| 1076 kUnsignedWord); | |
| 1077 __ tst(R3, Operand(R3)); | 1076 __ tst(R3, Operand(R3)); |
| 1078 __ b(&x_zero, EQ); | 1077 __ b(&x_zero, EQ); |
| 1079 | 1078 |
| 1080 // R5 = ajp = &a_digits[i] | 1079 // R5 = ajp = &a_digits[i] |
| 1081 __ ldr(R1, Address(SP, 1 * kWordSize)); // a_digits | 1080 __ ldr(R1, Address(SP, 1 * kWordSize)); // a_digits |
| 1082 __ add(R1, R1, Operand(R2, LSL, 2)); // j == 2*i, i is Smi. | 1081 __ add(R1, R1, Operand(R2, LSL, 2)); // j == 2*i, i is Smi. |
| 1083 __ add(R5, R1, Operand(TypedData::data_offset() - kHeapObjectTag)); | 1082 __ add(R5, R1, Operand(TypedData::data_offset() - kHeapObjectTag)); |
| 1084 | 1083 |
| 1085 // X0 = t = x*x + *ajp | 1084 // R6:R1 = t = x*x + *ajp |
| 1086 __ ldr(R0, Address(R5, 0), kUnsignedWord); | 1085 __ ldr(R0, Address(R5, 0)); |
| 1087 __ umaddl(R0, R3, R3, R0); // X0 = W3*W3 + X0. | 1086 __ mul(R1, R3, R3); // R1 = low64(R3*R3). |
| 1087 __ umulh(R6, R3, R3); // R6 = high64(R3*R3). | |
| 1088 __ adds(R1, R1, Operand(R0)); // R6:R1 += *ajp. | |
| 1089 __ adc(R6, R6, ZR); // R6 = low64(c) = high64(t). | |
| 1090 __ mov(R7, ZR); // R7 = high64(c) = 0. | |
| 1088 | 1091 |
| 1089 // *ajp++ = low32(t) = R0 | 1092 // *ajp++ = low64(t) = R1 |
| 1090 __ str(R0, Address(R5, Bigint::kBytesPerDigit, Address::PostIndex), | 1093 __ str(R1, Address(R5, 2*Bigint::kBytesPerDigit, Address::PostIndex)); |
| 1091 kUnsignedWord); | |
| 1092 | 1094 |
| 1093 // c = R6 = high32(t) = R0 >> 32. | 1095 // int n = (used - i + 1)/2 - 1 |
| 1094 __ LsrImmediate(R6, R0, 32); | |
| 1095 | |
| 1096 // int n = used - i - 1 | |
| 1097 __ ldr(R0, Address(SP, 0 * kWordSize)); // used is Smi | 1096 __ ldr(R0, Address(SP, 0 * kWordSize)); // used is Smi |
| 1098 __ sub(R8, R0, Operand(R2)); | 1097 __ sub(R8, R0, Operand(R2)); |
| 1098 __ add(R8, R8, Operand(2)); | |
| 1099 __ movn(R0, Immediate(1), 0); // R0 = ~1 = -2. | 1099 __ movn(R0, Immediate(1), 0); // R0 = ~1 = -2. |
| 1100 __ adds(R8, R0, Operand(R8, ASR, kSmiTagSize)); // while (--n >= 0) | 1100 __ adds(R8, R0, Operand(R8, ASR, 2)); // while (--n >= 0) |
| 1101 | 1101 |
| 1102 Label loop, done; | 1102 Label loop, done; |
| 1103 __ b(&done, MI); | 1103 __ b(&done, MI); |
| 1104 | 1104 |
| 1105 __ Bind(&loop); | 1105 __ Bind(&loop); |
| 1106 // x: R3 | 1106 // x: R3 |
| 1107 // xip: R4 | 1107 // xip: R4 |
| 1108 // ajp: R5 | 1108 // ajp: R5 |
| 1109 // c: R6 | 1109 // c: R7:R6 |
| 1110 // t: R1:R0 (not live at loop entry) | 1110 // t: R2:R1:R0 (not live at loop entry) |
| 1111 // n: R8 | 1111 // n: R8 |
| 1112 | 1112 |
| 1113 // uint32_t xi = *xip++ | 1113 // uint64_t xi = *xip++ |
| 1114 __ ldr(R2, Address(R4, Bigint::kBytesPerDigit, Address::PostIndex), | 1114 __ ldr(R2, Address(R4, 2*Bigint::kBytesPerDigit, Address::PostIndex)); |
| 1115 kUnsignedWord); | |
| 1116 | 1115 |
| 1117 // uint32_t aj = *ajp | 1116 // uint192_t t = R2:R1:R0 = 2*x*xi + aj + c |
| 1118 __ ldr(R1, Address(R5, 0), kUnsignedWord); | 1117 __ mul(R0, R2, R3); // R0 = low64(R2*R3) = low64(x*xi). |
| 1118 __ umulh(R1, R2, R3); // R1 = high64(R2*R3) = high64(x*xi). | |
| 1119 __ adds(R0, R0, Operand(R0)); | |
| 1120 __ adcs(R1, R1, R1); | |
| 1121 __ adc(R2, ZR, ZR); // R2:R1:R0 = R1:R0 + R1:R0 = 2*x*xi. | |
| 1122 __ adds(R0, R0, Operand(R6)); | |
| 1123 __ adcs(R1, R1, R7); | |
| 1124 __ adc(R2, R2, ZR); // R2:R1:R0 += c. | |
| 1125 __ ldr(R7, Address(R5, 0)); // R7 = aj = *ajp. | |
| 1126 __ adds(R0, R0, Operand(R7)); | |
| 1127 __ adcs(R6, R1, ZR); | |
| 1128 __ adc(R7, R2, ZR); // R7:R6:R0 = 2*x*xi + aj + c. | |
| 1119 | 1129 |
| 1120 // uint96_t t = R1:R0 = 2*x*xi + aj + c | 1130 // *ajp++ = low64(t) = R0 |
| 1121 __ umaddl(R0, R2, R3, ZR); // X0 = W2*W3 + 0 = x*xi. | 1131 __ str(R0, Address(R5, 2*Bigint::kBytesPerDigit, Address::PostIndex)); |
| 1122 __ add(R1, R0, Operand(R1)); // R1 = x*xi + aj. | |
| 1123 __ adds(R0, R0, Operand(R1)); | |
| 1124 __ adc(R1, ZR, ZR); // R1:R0 = 2*R0 + R1 = 2*x*xi + aj. | |
| 1125 __ adds(R0, R0, Operand(R6)); | |
| 1126 __ adc(R1, R1, ZR); // R1:R0 = R1:R0 + R6 = 2*x*xi + aj + c. | |
| 1127 | |
| 1128 // *ajp++ = low32(t) = R0 | |
| 1129 __ str(R0, Address(R5, Bigint::kBytesPerDigit, Address::PostIndex), | |
| 1130 kUnsignedWord); | |
| 1131 | |
| 1132 // R6 = c = t >> 32. | |
| 1133 __ LslImmediate(R6, R1, 32); | |
| 1134 __ orr(R6, R6, Operand(R0, LSR, 32)); | |
| 1135 | 1132 |
| 1136 // while (--n >= 0) | 1133 // while (--n >= 0) |
| 1137 __ subs(R8, R8, Operand(1)); // --n | 1134 __ subs(R8, R8, Operand(1)); // --n |
| 1138 __ b(&loop, PL); | 1135 __ b(&loop, PL); |
| 1139 | 1136 |
| 1140 __ Bind(&done); | 1137 __ Bind(&done); |
| 1141 // uint32_t aj = *ajp | 1138 // uint64_t aj = *ajp |
| 1142 __ ldr(R0, Address(R5, 0), kUnsignedWord); | 1139 __ ldr(R0, Address(R5, 0)); |
| 1143 | 1140 |
| 1144 // uint64_t t = aj + c | 1141 // uint128_t t = aj + c |
| 1145 __ add(R6, R6, Operand(R0)); | 1142 __ adds(R6, R6, Operand(R0)); |
| 1143 __ adc(R7, R7, ZR); | |
| 1146 | 1144 |
| 1147 // R7 = R6 >> 32. | 1145 // *ajp = low64(t) = R6 |
| 1148 __ LsrImmediate(R7, R6, 32); | 1146 // *(ajp + 1) = high64(t) = R7 |
| 1149 | 1147 __ stp(R6, R7, Address(R5, 0, Address::PairOffset)); |
| 1150 // *ajp = low32(t) = low32(R6) | |
| 1151 // *(ajp + 1) = high32(t) = low32(R7) | |
| 1152 __ stp(R6, R7, Address(R5, 0, Address::PairOffset), kUnsignedWord); | |
| 1153 | 1148 |
| 1154 __ Bind(&x_zero); | 1149 __ Bind(&x_zero); |
| 1155 __ LoadImmediate(R0, Smi::RawValue(1), kNoPP); // One digit processed. | 1150 __ LoadImmediate(R0, Smi::RawValue(2), kNoPP); // Two digits processed. |
| 1156 __ ret(); | 1151 __ ret(); |
| 1157 } | 1152 } |
| 1158 | 1153 |
| 1159 | 1154 |
| 1160 void Intrinsifier::Bigint_estQuotientDigit(Assembler* assembler) { | 1155 void Intrinsifier::Bigint_estQuotientDigit(Assembler* assembler) { |
|
zra
2015/01/05 17:00:28
There are a lot more instruction here. I think I s
| |
| 1156 // There is no 128-bit by 64-bit division instruction on arm64, so we use two | |
| 1157 // 64-bit by 32-bit divisions and two 64-bit by 64-bit multiplications to | |
| 1158 // adjust the two 32-bit digits of the estimated quotient. | |
| 1159 // | |
| 1161 // Pseudo code: | 1160 // Pseudo code: |
| 1162 // static int _estQuotientDigit(Uint32List args, Uint32List digits, int i) { | 1161 // static int _estQuotientDigit(Uint32List args, Uint32List digits, int i) { |
| 1163 // uint32_t yt = args[_YT]; // _YT == 1. | 1162 // uint64_t yt = args[_YT_LO .. _YT]; // _YT_LO == 0, _YT == 1. |
| 1164 // uint32_t* dp = &digits[i >> 1]; // i is Smi. | 1163 // uint64_t* dp = &digits[(i >> 1) - 1]; // i is Smi. |
| 1165 // uint32_t dh = dp[0]; // dh == digits[i >> 1]. | 1164 // uint64_t dh = dp[0]; // dh == digits[(i >> 1) - 1 .. i >> 1]. |
| 1166 // uint32_t qd; | 1165 // uint64_t qd; |
| 1167 // if (dh == yt) { | 1166 // if (dh == yt) { |
| 1168 // qd = DIGIT_MASK; | 1167 // qd = (DIGIT_MASK << 32) | DIGIT_MASK; |
| 1169 // } else { | 1168 // } else { |
| 1170 // dl = dp[-1]; // dl == digits[(i - 1) >> 1]. | 1169 // dl = dp[-1]; // dl == digits[(i >> 1) - 3 .. (i >> 1) - 2]. |
| 1171 // qd = dh:dl / yt; // No overflow possible, because dh < yt. | 1170 // // We cannot calculate qd = dh:dl / yt, so ... |
| 1171 // uint64_t yth = yt >> 32; | |
| 1172 // uint64_t qh = dh / yth; | |
| 1173 // uint128_t ph:pl = yt*qh; | |
| 1174 // uint64_t tl = (dh << 32)|(dl >> 32); | |
| 1175 // uint64_t th = dh >> 32; | |
| 1176 // while ((ph > th) || ((ph == th) && (pl > tl))) { | |
| 1177 // if (pl < yt) --ph; | |
| 1178 // pl -= yt; | |
| 1179 // --qh; | |
| 1180 // } | |
| 1181 // qd = qh << 32; | |
| 1182 // tl = (pl << 32); | |
| 1183 // th = (ph << 32)|(pl >> 32); | |
| 1184 // if (tl > dl) ++th; | |
| 1185 // dl -= tl; | |
| 1186 // dh -= th; | |
| 1187 // uint64_t ql = ((dh << 32)|(dl >> 32)) / yth; | |
| 1188 // ph:pl = yt*ql; | |
| 1189 // while ((ph > dh) || ((ph == dh) && (pl > dl))) { | |
| 1190 // if (pl < yt) --ph; | |
| 1191 // pl -= yt; | |
| 1192 // --ql; | |
| 1193 // } | |
| 1194 // qd |= ql; | |
| 1172 // } | 1195 // } |
| 1173 // args[_QD] = qd; // _QD == 2. | 1196 // args[_QD .. _QD_HI] = qd; // _QD == 2, _QD_HI == 3. |
| 1174 // return 1; | 1197 // return 2; |
| 1175 // } | 1198 // } |
| 1176 | 1199 |
| 1177 // R4 = args | 1200 // R4 = args |
| 1178 __ ldr(R4, Address(SP, 2 * kWordSize)); // args | 1201 __ ldr(R4, Address(SP, 2 * kWordSize)); // args |
| 1179 | 1202 |
| 1180 // R3 = yt = args[1] | 1203 // R3 = yt = args[0..1] |
| 1181 __ ldr(R3, FieldAddress(R4, | 1204 __ ldr(R3, FieldAddress(R4, TypedData::data_offset())); |
| 1182 TypedData::data_offset() + Bigint::kBytesPerDigit), | |
| 1183 kUnsignedWord); | |
| 1184 | 1205 |
| 1185 // R2 = dh = digits[i >> 1] | 1206 // R2 = dh = digits[(i >> 1) - 1 .. i >> 1] |
| 1186 // R0 = i as Smi, R1 = digits | 1207 // R0 = i as Smi, R1 = digits |
| 1187 __ ldp(R0, R1, Address(SP, 0 * kWordSize, Address::PairOffset)); | 1208 __ ldp(R0, R1, Address(SP, 0 * kWordSize, Address::PairOffset)); |
| 1188 __ add(R1, R1, Operand(R0, LSL, 1)); | 1209 __ add(R1, R1, Operand(R0, LSL, 1)); |
| 1189 __ ldr(R2, FieldAddress(R1, TypedData::data_offset()), kUnsignedWord); | 1210 __ ldr(R2, |
| 1211 FieldAddress(R1, TypedData::data_offset() - Bigint::kBytesPerDigit)); | |
| 1190 | 1212 |
| 1191 // R0 = qd = DIGIT_MASK = -1 | 1213 // R0 = qd = (DIGIT_MASK << 32) | DIGIT_MASK = -1 |
| 1192 __ movn(R0, Immediate(0), 0); | 1214 __ movn(R0, Immediate(0), 0); |
| 1193 | 1215 |
| 1194 // Return qd if dh == yt | 1216 // Return qd if dh == yt |
| 1195 Label return_qd; | 1217 Label return_qd; |
| 1196 __ cmp(R2, Operand(R3)); | 1218 __ cmp(R2, Operand(R3)); |
| 1197 __ b(&return_qd, EQ); | 1219 __ b(&return_qd, EQ); |
| 1198 | 1220 |
| 1199 // R1 = dl = digits[(i - 1) >> 1] | 1221 // R1 = dl = digits[(i >> 1) - 3 .. (i >> 1) - 2] |
| 1200 __ ldr(R1, | 1222 __ ldr(R1, |
| 1201 FieldAddress(R1, TypedData::data_offset() - Bigint::kBytesPerDigit), | 1223 FieldAddress(R1, TypedData::data_offset() - 3*Bigint::kBytesPerDigit)); |
| 1202 kUnsignedWord); | |
| 1203 | 1224 |
| 1204 // R1 = dh:dl | 1225 // R5 = yth = yt >> 32 |
| 1205 __ orr(R1, R1, Operand(R2, LSL, 32)); | 1226 __ orr(R5, ZR, Operand(R3, LSR, 32)); |
| 1206 | 1227 |
| 1207 // R0 = qd = dh:dl / yt = R1 / R3 | 1228 // R6 = qh = dh / yth |
| 1208 __ udiv(R0, R1, R3); | 1229 __ udiv(R6, R2, R5); |
| 1230 | |
| 1231 // R8:R7 = ph:pl = yt*qh | |
| 1232 __ mul(R7, R3, R6); | |
| 1233 __ umulh(R8, R3, R6); | |
| 1234 | |
| 1235 // R9 = tl = (dh << 32)|(dl >> 32) | |
| 1236 __ orr(R9, ZR, Operand(R2, LSL, 32)); | |
| 1237 __ orr(R9, R9, Operand(R1, LSR, 32)); | |
| 1238 | |
| 1239 // R10 = th = dh >> 32 | |
| 1240 __ orr(R10, ZR, Operand(R2, LSR, 32)); | |
| 1241 | |
| 1242 // while ((ph > th) || ((ph == th) && (pl > tl))) | |
| 1243 Label qh_adj_loop, qh_adj, qh_ok; | |
| 1244 __ Bind(&qh_adj_loop); | |
| 1245 __ cmp(R8, Operand(R10)); | |
| 1246 __ b(&qh_adj, HI); | |
| 1247 __ b(&qh_ok, NE); | |
| 1248 __ cmp(R7, Operand(R9)); | |
| 1249 __ b(&qh_ok, LS); | |
| 1250 | |
| 1251 __ Bind(&qh_adj); | |
| 1252 // if (pl < yt) --ph | |
| 1253 __ sub(TMP, R8, Operand(1)); // TMP = ph - 1 | |
| 1254 __ cmp(R7, Operand(R3)); | |
| 1255 __ csel(R8, TMP, R8, CC); // R8 = R7 < R3 ? TMP : R8 | |
| 1256 | |
| 1257 // pl -= yt | |
| 1258 __ sub(R7, R7, Operand(R3)); | |
| 1259 | |
| 1260 // --qh | |
| 1261 __ sub(R6, R6, Operand(1)); | |
| 1262 | |
| 1263 __ Bind(&qh_ok); | |
| 1264 // R0 = qd = qh << 32 | |
| 1265 __ orr(R0, ZR, Operand(R6, LSL, 32)); | |
| 1266 | |
| 1267 // tl = (pl << 32) | |
| 1268 __ orr(R9, ZR, Operand(R7, LSL, 32)); | |
| 1269 | |
| 1270 // th = (ph << 32)|(pl >> 32); | |
| 1271 __ orr(R10, ZR, Operand(R8, LSL, 32)); | |
| 1272 __ orr(R10, R10, Operand(R7, LSR, 32)); | |
| 1273 | |
| 1274 // if (tl > dl) ++th | |
| 1275 __ add(TMP, R10, Operand(1)); // TMP = th + 1 | |
| 1276 __ cmp(R9, Operand(R1)); | |
| 1277 __ csel(R10, TMP, R10, HI); // R10 = R9 > R1 ? TMP : R10 | |
| 1278 | |
| 1279 // dl -= tl | |
| 1280 __ sub(R1, R1, Operand(R9)); | |
| 1281 | |
| 1282 // dh -= th | |
| 1283 __ sub(R2, R2, Operand(R10)); | |
| 1284 | |
| 1285 // R6 = ql = ((dh << 32)|(dl >> 32)) / yth | |
| 1286 __ orr(R6, ZR, Operand(R2, LSL, 32)); | |
| 1287 __ orr(R6, R6, Operand(R1, LSR, 32)); | |
| 1288 __ udiv(R6, R6, R5); | |
| 1289 | |
| 1290 // R8:R7 = ph:pl = yt*ql | |
| 1291 __ mul(R7, R3, R6); | |
| 1292 __ umulh(R8, R3, R6); | |
| 1293 | |
| 1294 // while ((ph > dh) || ((ph == dh) && (pl > dl))) { | |
| 1295 Label ql_adj_loop, ql_adj, ql_ok; | |
| 1296 __ Bind(&ql_adj_loop); | |
| 1297 __ cmp(R8, Operand(R2)); | |
| 1298 __ b(&ql_adj, HI); | |
| 1299 __ b(&ql_ok, NE); | |
| 1300 __ cmp(R7, Operand(R1)); | |
| 1301 __ b(&ql_ok, LS); | |
| 1302 | |
| 1303 __ Bind(&ql_adj); | |
| 1304 // if (pl < yt) --ph | |
| 1305 __ sub(TMP, R8, Operand(1)); // TMP = ph - 1 | |
| 1306 __ cmp(R7, Operand(R3)); | |
| 1307 __ csel(R8, TMP, R8, CC); // R8 = R7 < R3 ? TMP : R8 | |
| 1308 | |
| 1309 // pl -= yt | |
| 1310 __ sub(R7, R7, Operand(R3)); | |
| 1311 | |
| 1312 // --ql | |
| 1313 __ sub(R6, R6, Operand(1)); | |
| 1314 | |
| 1315 __ Bind(&ql_ok); | |
| 1316 // qd |= ql; | |
| 1317 __ orr(R0, R0, Operand(R6)); | |
| 1209 | 1318 |
| 1210 __ Bind(&return_qd); | 1319 __ Bind(&return_qd); |
| 1211 // args[2] = qd | 1320 // args[2..3] = qd |
| 1212 __ str(R0, | 1321 __ str(R0, |
| 1213 FieldAddress(R4, TypedData::data_offset() + 2*Bigint::kBytesPerDigit), | 1322 FieldAddress(R4, TypedData::data_offset() + 2*Bigint::kBytesPerDigit)); |
| 1214 kUnsignedWord); | |
| 1215 | 1323 |
| 1216 __ LoadImmediate(R0, Smi::RawValue(1), kNoPP); // One digit processed. | 1324 __ LoadImmediate(R0, Smi::RawValue(2), kNoPP); // Two digits processed. |
| 1217 __ ret(); | 1325 __ ret(); |
| 1218 } | 1326 } |
| 1219 | 1327 |
| 1220 | 1328 |
| 1221 void Intrinsifier::Montgomery_mulMod(Assembler* assembler) { | 1329 void Intrinsifier::Montgomery_mulMod(Assembler* assembler) { |
| 1222 // Pseudo code: | 1330 // Pseudo code: |
| 1223 // static int _mulMod(Uint32List args, Uint32List digits, int i) { | 1331 // static int _mulMod(Uint32List args, Uint32List digits, int i) { |
| 1224 // uint32_t rho = args[_RHO]; // _RHO == 2. | 1332 // uint64_t rho = args[_RHO .. _RHO_HI]; // _RHO == 2, _RHO_HI == 3. |
| 1225 // uint32_t d = digits[i >> 1]; // i is Smi. | 1333 // uint64_t d = digits[i >> 1 .. (i >> 1) + 1]; // i is Smi and even. |
| 1226 // uint64_t t = rho*d; | 1334 // uint128_t t = rho*d; |
| 1227 // args[_MU] = t mod DIGIT_BASE; // _MU == 4. | 1335 // args[_MU .. _MU_HI] = t mod DIGIT_BASE^2; // _MU == 4, _MU_HI == 5. |
| 1228 // args[_MU_HI] = 0; // _MU_HI == 3. | 1336 // return 2; |
| 1229 // return 1; | |
| 1230 // } | 1337 // } |
| 1231 | 1338 |
| 1232 // R4 = args | 1339 // R4 = args |
| 1233 __ ldr(R4, Address(SP, 2 * kWordSize)); // args | 1340 __ ldr(R4, Address(SP, 2 * kWordSize)); // args |
| 1234 | 1341 |
| 1235 // R3 = rho = args[2] | 1342 // R3 = rho = args[2..3] |
| 1236 __ ldr(R3, | 1343 __ ldr(R3, |
| 1237 FieldAddress(R4, TypedData::data_offset() + 2*Bigint::kBytesPerDigit), | 1344 FieldAddress(R4, TypedData::data_offset() + 2*Bigint::kBytesPerDigit)); |
| 1238 kUnsignedWord); | |
| 1239 | 1345 |
| 1240 // R2 = digits[i >> 1] | 1346 // R2 = digits[i >> 1 .. (i >> 1) + 1] |
| 1241 // R0 = i as Smi, R1 = digits | 1347 // R0 = i as Smi, R1 = digits |
| 1242 __ ldp(R0, R1, Address(SP, 0 * kWordSize, Address::PairOffset)); | 1348 __ ldp(R0, R1, Address(SP, 0 * kWordSize, Address::PairOffset)); |
| 1243 __ add(R1, R1, Operand(R0, LSL, 1)); | 1349 __ add(R1, R1, Operand(R0, LSL, 1)); |
| 1244 __ ldr(R2, FieldAddress(R1, TypedData::data_offset()), kUnsignedWord); | 1350 __ ldr(R2, FieldAddress(R1, TypedData::data_offset())); |
| 1245 | 1351 |
| 1246 // X0 = t = rho*d | 1352 // R0 = rho*d mod DIGIT_BASE |
| 1247 __ umaddl(R0, R2, R3, ZR); // X0 = W2*W3 + 0. | 1353 __ mul(R0, R2, R3); // R0 = low64(R2*R3). |
| 1248 | 1354 |
| 1249 // args[4] = t mod DIGIT_BASE = low32(t) | 1355 // args[4 .. 5] = R0 |
| 1250 __ str(R0, | 1356 __ str(R0, |
| 1251 FieldAddress(R4, TypedData::data_offset() + 4*Bigint::kBytesPerDigit), | 1357 FieldAddress(R4, TypedData::data_offset() + 4*Bigint::kBytesPerDigit)); |
| 1252 kUnsignedWord); | |
| 1253 | 1358 |
| 1254 __ LoadImmediate(R0, Smi::RawValue(1), kNoPP); // One digit processed. | 1359 __ LoadImmediate(R0, Smi::RawValue(2), kNoPP); // Two digits processed. |
| 1255 __ ret(); | 1360 __ ret(); |
| 1256 } | 1361 } |
| 1257 | 1362 |
| 1258 | 1363 |
| 1259 // Check if the last argument is a double, jump to label 'is_smi' if smi | 1364 // Check if the last argument is a double, jump to label 'is_smi' if smi |
| 1260 // (easy to convert to double), otherwise jump to label 'not_double_smi', | 1365 // (easy to convert to double), otherwise jump to label 'not_double_smi', |
| 1261 // Returns the last argument in R0. | 1366 // Returns the last argument in R0. |
| 1262 static void TestLastArgumentIsDouble(Assembler* assembler, | 1367 static void TestLastArgumentIsDouble(Assembler* assembler, |
| 1263 Label* is_smi, | 1368 Label* is_smi, |
| 1264 Label* not_double_smi) { | 1369 Label* not_double_smi) { |
| (...skipping 747 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2012 Isolate* isolate = Isolate::Current(); | 2117 Isolate* isolate = Isolate::Current(); |
| 2013 __ LoadImmediate(R1, reinterpret_cast<uword>(isolate), kNoPP); | 2118 __ LoadImmediate(R1, reinterpret_cast<uword>(isolate), kNoPP); |
| 2014 // Set return value to Isolate::current_tag_. | 2119 // Set return value to Isolate::current_tag_. |
| 2015 __ ldr(R0, Address(R1, Isolate::current_tag_offset())); | 2120 __ ldr(R0, Address(R1, Isolate::current_tag_offset())); |
| 2016 __ ret(); | 2121 __ ret(); |
| 2017 } | 2122 } |
| 2018 | 2123 |
| 2019 } // namespace dart | 2124 } // namespace dart |
| 2020 | 2125 |
| 2021 #endif // defined TARGET_ARCH_ARM64 | 2126 #endif // defined TARGET_ARCH_ARM64 |
| OLD | NEW |