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

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

Issue 638983002: Implement bigint mulAdd and sqrAdd intrinsics on ARM. (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/disassembler_arm.cc ('k') | runtime/vm/intrinsifier_ia32.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 #include "vm/globals.h" // Needed here to get TARGET_ARCH_ARM. 5 #include "vm/globals.h" // Needed here to get TARGET_ARCH_ARM.
6 #if defined(TARGET_ARCH_ARM) 6 #if defined(TARGET_ARCH_ARM)
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 895 matching lines...) Expand 10 before | Expand all | Expand 10 after
906 // TODO(regis): Implement. 906 // TODO(regis): Implement.
907 } 907 }
908 908
909 909
910 void Intrinsifier::Bigint_absSub(Assembler* assembler) { 910 void Intrinsifier::Bigint_absSub(Assembler* assembler) {
911 // TODO(regis): Implement. 911 // TODO(regis): Implement.
912 } 912 }
913 913
914 914
915 void Intrinsifier::Bigint_mulAdd(Assembler* assembler) { 915 void Intrinsifier::Bigint_mulAdd(Assembler* assembler) {
916 // TODO(regis): Implement. 916 if (TargetCPUFeatures::arm_version() != ARMv7) {
917 return;
918 }
919 // Pseudo code:
920 // static void _mulAdd(Uint32List x_digits, int xi,
921 // Uint32List m_digits, int i,
922 // Uint32List a_digits, int j, int n) {
923 // uint32_t x = x_digits[xi >> 1]; // xi is Smi.
924 // if (x == 0 || n == 0) {
925 // return;
926 // }
927 // uint32_t* mip = &m_digits[i >> 1]; // i is Smi.
928 // uint32_t* ajp = &a_digits[j >> 1]; // j is Smi.
929 // uint32_t c = 0;
930 // SmiUntag(n);
931 // do {
932 // uint32_t mi = *mip++;
933 // uint32_t aj = *ajp;
934 // uint64_t t = x*mi + aj + c; // 32-bit * 32-bit -> 64-bit.
935 // *ajp++ = low32(t);
936 // c = high32(t);
937 // } while (--n > 0);
938 // while (c != 0) {
939 // uint64_t t = *ajp + c;
940 // *ajp++ = low32(t);
941 // c = high32(t); // c == 0 or 1.
942 // }
943 // }
944
945 Label done;
946 // R3 = x, no_op if x == 0
947 __ ldr(R1, Address(SP, 6 * kWordSize)); // x_digits
948 __ ldr(R0, Address(SP, 5 * kWordSize)); // xi is Smi
949 __ add(R1, R1, Operand(R0, LSL, 1));
950 __ ldr(R3, FieldAddress(R1, TypedData::data_offset()));
951 __ tst(R3, Operand(R3));
952 __ b(&done, EQ);
953
954 // R6 = SmiUntag(n), no_op if n == 0
955 __ ldr(R6, Address(SP, 0 * kWordSize));
956 __ Asrs(R6, R6, Operand(kSmiTagSize));
957 __ b(&done, EQ);
958
959 // R4 = mip = &m_digits[i >> 1]
960 __ ldr(R1, Address(SP, 4 * kWordSize)); // m_digits
961 __ ldr(R0, Address(SP, 3 * kWordSize)); // i is Smi
962 __ add(R1, R1, Operand(R0, LSL, 1));
963 __ add(R4, R1, Operand(TypedData::data_offset() - kHeapObjectTag));
964
965 // R5 = ajp = &a_digits[j >> 1]
966 __ ldr(R1, Address(SP, 2 * kWordSize)); // a_digits
967 __ ldr(R0, Address(SP, 1 * kWordSize)); // j is Smi
968 __ add(R1, R1, Operand(R0, LSL, 1));
969 __ add(R5, R1, Operand(TypedData::data_offset() - kHeapObjectTag));
970
971 // R1 = c = 0
972 __ mov(R1, Operand(0));
973
974 Label muladd_loop;
975 __ Bind(&muladd_loop);
976 // x: R3
977 // mip: R4
978 // ajp: R5
979 // c: R1
980 // n: R6
981
982 // uint32_t mi = *mip++
983 __ ldr(R2, Address(R4, kWordSize, Address::PostIndex));
984
985 // uint32_t aj = *ajp
986 __ ldr(R0, Address(R5, 0));
987
988 // uint64_t t = x*mi + aj + c
989 __ umaal(R0, R1, R2, R3); // R1:R0 = R2*R3 + R1 + R0.
990
991 // *ajp++ = low32(t) = R0
992 __ str(R0, Address(R5, kWordSize, Address::PostIndex));
993
994 // c = high32(t) = R1
995
996 // while (--n > 0)
997 __ subs(R6, R6, Operand(1)); // --n
998 __ b(&muladd_loop, NE);
999
1000 __ tst(R1, Operand(R1));
1001 __ b(&done, EQ);
1002
1003 // *ajp++ += c
1004 __ ldr(R0, Address(R5, 0));
1005 __ adds(R0, R0, Operand(R1));
1006 __ str(R0, Address(R5, kWordSize, Address::PostIndex));
1007 __ b(&done, CC);
1008
1009 Label propagate_carry_loop;
1010 __ Bind(&propagate_carry_loop);
1011 __ ldr(R0, Address(R5, 0));
1012 __ adds(R0, R0, Operand(1));
1013 __ str(R0, Address(R5, kWordSize, Address::PostIndex));
1014 __ b(&propagate_carry_loop, CS);
1015
1016 __ Bind(&done);
1017 __ Ret();
917 } 1018 }
918 1019
919 1020
920 void Intrinsifier::Bigint_sqrAdd(Assembler* assembler) { 1021 void Intrinsifier::Bigint_sqrAdd(Assembler* assembler) {
921 // TODO(regis): Implement. 1022 if (TargetCPUFeatures::arm_version() != ARMv7) {
1023 return;
1024 }
1025 // Pseudo code:
1026 // static void _sqrAdd(Uint32List x_digits, int i,
1027 // Uint32List a_digits, int used) {
1028 // uint32_t* xip = &x_digits[i >> 1]; // i is Smi.
1029 // uint32_t x = *xip++;
1030 // if (x == 0) return;
1031 // uint32_t* ajp = &a_digits[i]; // j == 2*i, i is Smi.
1032 // uint32_t aj = *ajp;
1033 // uint64_t t = x*x + aj;
1034 // *ajp++ = low32(t);
1035 // uint64_t c = high32(t);
1036 // int n = ((used - i) >> 1) - 1; // used and i are Smi.
1037 // while (--n >= 0) {
1038 // uint32_t xi = *xip++;
1039 // uint32_t aj = *ajp;
1040 // uint96_t t = 2*x*xi + aj + c; // 2-bit * 32-bit * 32-bit -> 65-bit.
1041 // *ajp++ = low32(t);
1042 // c = high64(t); // 33-bit.
1043 // }
1044 // uint32_t aj = *ajp;
1045 // uint64_t t = aj + c; // 32-bit + 33-bit -> 34-bit.
1046 // *ajp++ = low32(t);
1047 // *ajp = high32(t);
1048 // }
1049
1050 // R4 = xip = &x_digits[i >> 1]
1051 __ ldr(R1, Address(SP, 3 * kWordSize)); // x_digits
1052 __ ldr(R6, Address(SP, 2 * kWordSize)); // i is Smi
1053 __ add(R1, R1, Operand(R6, LSL, 1));
1054 __ add(R4, R1, Operand(TypedData::data_offset() - kHeapObjectTag));
1055
1056 // R3 = x = *xip++, return if x == 0
1057 Label x_zero;
1058 __ ldr(R3, Address(R4, kWordSize, Address::PostIndex));
1059 __ tst(R3, Operand(R3));
1060 __ b(&x_zero, EQ);
1061
1062 // R5 = ajp = &a_digits[i]
1063 __ ldr(R1, Address(SP, 1 * kWordSize)); // a_digits
1064 __ add(R1, R1, Operand(R6, LSL, 2)); // j == 2*i, i is Smi.
1065 __ add(R5, R1, Operand(TypedData::data_offset() - kHeapObjectTag));
1066
1067 // R7:R0 = t = x*x + *ajp
1068 __ ldr(R0, Address(R5, 0));
1069 __ mov(R7, Operand(0));
1070 __ umaal(R0, R7, R3, R3); // R7:R0 = R3*R3 + R7 + R0.
1071
1072 // *ajp++ = low32(t) = R0
1073 __ str(R0, Address(R5, kWordSize, Address::PostIndex));
1074
1075 // R7 = low32(c) = high32(t)
1076 // R8 = high32(c) = 0
1077 __ mov(R8, Operand(0));
1078
1079 // int n = used - i - 1
1080 __ ldr(R0, Address(SP, 0 * kWordSize)); // used is Smi
1081 __ sub(R6, R0, Operand(R6));
1082 __ mov(R0, Operand(2)); // while (--n >= 0)
1083 __ rsbs(R6, R0, Operand(R6, ASR, kSmiTagSize));
1084
1085 Label loop, done;
1086 __ b(&done, MI);
1087
1088 __ Bind(&loop);
1089 // x: R3
1090 // xip: R4
1091 // ajp: R5
1092 // c: R8:R7
1093 // t: R2:R1:R0 (not live at loop entry)
1094 // n: R6
1095
1096 // uint32_t xi = *xip++
1097 __ ldr(R2, Address(R4, kWordSize, Address::PostIndex));
1098
1099 // uint32_t aj = *ajp
1100 __ ldr(R1, Address(R5, 0));
1101
1102 // uint96_t t = R2:R1:R0 = 2*x*xi + aj + c
1103 __ mov(R0, Operand(0));
1104 __ umaal(R0, R1, R2, R3); // R1:R0 = R3*R2 + R1 + R0 = x*xi + aj + 0.
1105 __ umlal(R7, R8, R2, R3); // R8:R7 += R3*R2; c += x*xi.
1106 __ adds(R0, R0, Operand(R7));
1107 __ adcs(R7, R1, Operand(R8));
1108 __ mov(R8, Operand(0));
1109 __ adc(R8, R8, Operand(0)); // R8:R7:R0 = R1:R0 + R8:R7 = 2*x*xi + aj + c.
1110
1111 // *ajp++ = low32(t) = R0
1112 __ str(R0, Address(R5, kWordSize, Address::PostIndex));
1113
1114 // while (--n >= 0)
1115 __ subs(R6, R6, Operand(1)); // --n
1116 __ b(&loop, PL);
1117
1118 __ Bind(&done);
1119 // uint32_t aj = *ajp
1120 __ ldr(R0, Address(R5, 0));
1121
1122 // uint64_t t = aj + c
1123 __ adds(R7, R7, Operand(R0));
1124 __ adc(R8, R8, Operand(0));
1125
1126 // *ajp++ = low32(t)
1127 // *ajp = high32(t)
1128 __ str(R7, Address(R5, 0));
1129 __ str(R8, Address(R5, kWordSize));
1130
1131 __ Bind(&x_zero);
1132 __ Ret();
922 } 1133 }
923 1134
924 1135
925 void Intrinsifier::Bigint_estQuotientDigit(Assembler* assembler) { 1136 void Intrinsifier::Bigint_estQuotientDigit(Assembler* assembler) {
926 // TODO(regis): Implement. 1137 // TODO(regis): Implement.
927 } 1138 }
928 1139
929 1140
930 void Intrinsifier::Montgomery_mulMod(Assembler* assembler) { 1141 void Intrinsifier::Montgomery_mulMod(Assembler* assembler) {
931 // TODO(regis): Implement. 1142 // TODO(regis): Implement.
(...skipping 737 matching lines...) Expand 10 before | Expand all | Expand 10 after
1669 Isolate* isolate = Isolate::Current(); 1880 Isolate* isolate = Isolate::Current();
1670 __ LoadImmediate(R1, reinterpret_cast<uword>(isolate)); 1881 __ LoadImmediate(R1, reinterpret_cast<uword>(isolate));
1671 // Set return value to Isolate::current_tag_. 1882 // Set return value to Isolate::current_tag_.
1672 __ ldr(R0, Address(R1, Isolate::current_tag_offset())); 1883 __ ldr(R0, Address(R1, Isolate::current_tag_offset()));
1673 __ Ret(); 1884 __ Ret();
1674 } 1885 }
1675 1886
1676 } // namespace dart 1887 } // namespace dart
1677 1888
1678 #endif // defined TARGET_ARCH_ARM 1889 #endif // defined TARGET_ARCH_ARM
OLDNEW
« no previous file with comments | « runtime/vm/disassembler_arm.cc ('k') | runtime/vm/intrinsifier_ia32.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698