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

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

Issue 236173002: Adds more arithmetic ops to arm64. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 8 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_arm64.cc ('k') | no next file » | 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) 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 <math.h> // for isnan. 5 #include <math.h> // for isnan.
6 #include <setjmp.h> 6 #include <setjmp.h>
7 #include <stdlib.h> 7 #include <stdlib.h>
8 8
9 #include "vm/globals.h" 9 #include "vm/globals.h"
10 #if defined(TARGET_ARCH_ARM64) 10 #if defined(TARGET_ARCH_ARM64)
(...skipping 1057 matching lines...) Expand 10 before | Expand all | Expand 10 after
1068 } 1068 }
1069 1069
1070 if (instr->SFField() == 1) { 1070 if (instr->SFField() == 1) {
1071 set_register(rd, alu_out, instr->RdMode()); 1071 set_register(rd, alu_out, instr->RdMode());
1072 } else { 1072 } else {
1073 set_wregister(rd, alu_out & kWRegMask, instr->RdMode()); 1073 set_wregister(rd, alu_out & kWRegMask, instr->RdMode());
1074 } 1074 }
1075 } 1075 }
1076 1076
1077 1077
1078 static int64_t divide64(int64_t top, int64_t bottom, bool signd) {
1079 // ARM64 does not trap on integer division by zero. The destination register
1080 // is instead set to 0.
1081 if (bottom == 0) {
1082 return 0;
1083 }
1084
1085 if (signd) {
1086 // INT_MIN / -1 = INT_MIN.
1087 if ((top == static_cast<int64_t>(0x8000000000000000LL)) &&
1088 (bottom == static_cast<int64_t>(0xffffffffffffffffLL))) {
1089 return static_cast<int64_t>(0x8000000000000000LL);
1090 } else {
1091 return top / bottom;
1092 }
1093 } else {
1094 const uint64_t utop = static_cast<uint64_t>(top);
1095 const uint64_t ubottom = static_cast<uint64_t>(bottom);
1096 return static_cast<int64_t>(utop / ubottom);
1097 }
1098 }
1099
1100
1101 static int32_t divide32(int32_t top, int32_t bottom, bool signd) {
1102 // ARM64 does not trap on integer division by zero. The destination register
1103 // is instead set to 0.
1104 if (bottom == 0) {
1105 return 0;
1106 }
1107
1108 if (signd) {
1109 // INT_MIN / -1 = INT_MIN.
1110 if ((top == static_cast<int32_t>(0x80000000)) &&
1111 (bottom == static_cast<int32_t>(0xffffffff))) {
1112 return static_cast<int32_t>(0x80000000);
1113 } else {
1114 return top / bottom;
1115 }
1116 } else {
1117 const uint32_t utop = static_cast<uint32_t>(top);
1118 const uint32_t ubottom = static_cast<uint32_t>(bottom);
1119 return static_cast<int32_t>(utop / ubottom);
1120 }
1121 }
1122
1123
1124 void Simulator::DecodeMiscDP2Source(Instr* instr) {
1125 if (instr->Bit(29) != 0) {
1126 UnimplementedInstruction(instr);
1127 }
1128
1129 const Register rd = instr->RdField();
1130 const Register rn = instr->RnField();
1131 const Register rm = instr->RmField();
1132 const int op = instr->Bits(10, 6);
1133 const int64_t rn_val64 = get_register(rn, R31IsZR);
1134 const int64_t rm_val64 = get_register(rm, R31IsZR);
1135 const int32_t rn_val32 = get_wregister(rn, R31IsZR);
1136 const int32_t rm_val32 = get_wregister(rm, R31IsZR);
1137 switch (op) {
1138 case 2:
1139 case 3: {
1140 // Format(instr, "udiv'sf 'rd, 'rn, 'rm");
1141 // Format(instr, "sdiv'sf 'rd, 'rn, 'rm");
1142 const bool signd = instr->Bit(10) == 1;
1143 if (instr->SFField() == 1) {
1144 set_register(rd, divide64(rn_val64, rm_val64, signd), R31IsZR);
1145 } else {
1146 set_wregister(rd, divide32(rn_val32, rm_val32, signd), R31IsZR);
1147 }
1148 break;
1149 }
1150 case 8: {
1151 // Format(instr, "lsl'sf 'rd, 'rn, 'rm");
1152 if (instr->SFField() == 1) {
1153 const int64_t alu_out = rn_val64 << (rm_val64 & (kXRegSizeInBits - 1));
1154 set_register(rd, alu_out, R31IsZR);
1155 } else {
1156 const int32_t alu_out = rn_val32 << (rm_val32 & (kXRegSizeInBits - 1));
1157 set_wregister(rd, alu_out, R31IsZR);
1158 }
1159 break;
1160 }
1161 case 9: {
1162 // Format(instr, "lsr'sf 'rd, 'rn, 'rm");
1163 if (instr->SFField() == 1) {
1164 const uint64_t rn_u64 = static_cast<uint64_t>(rn_val64);
1165 const int64_t alu_out = rn_u64 >> (rm_val64 & (kXRegSizeInBits - 1));
1166 set_register(rd, alu_out, R31IsZR);
1167 } else {
1168 const uint32_t rn_u32 = static_cast<uint32_t>(rn_val32);
1169 const int32_t alu_out = rn_u32 >> (rm_val32 & (kXRegSizeInBits - 1));
1170 set_wregister(rd, alu_out, R31IsZR);
1171 }
1172 break;
1173 }
1174 case 10: {
1175 // Format(instr, "asr'sf 'rd, 'rn, 'rm");
1176 if (instr->SFField() == 1) {
1177 const int64_t alu_out = rn_val64 >> (rm_val64 & (kXRegSizeInBits - 1));
1178 set_register(rd, alu_out, R31IsZR);
1179 } else {
1180 const int32_t alu_out = rn_val32 >> (rm_val32 & (kXRegSizeInBits - 1));
1181 set_wregister(rd, alu_out, R31IsZR);
1182 }
1183 break;
1184 }
1185 default:
1186 UnimplementedInstruction(instr);
1187 break;
1188 }
1189 }
1190
1191
1192 void Simulator::DecodeMiscDP3Source(Instr* instr) {
1193 if ((instr->Bits(29, 2) == 0) && (instr->Bits(21, 3) == 0) &&
1194 (instr->Bit(15) == 0)) {
1195 // Format(instr, "madd'sf 'rd, 'rn, 'rm, 'ra");
1196 const Register rd = instr->RdField();
1197 const Register rn = instr->RnField();
1198 const Register rm = instr->RmField();
1199 const Register ra = instr->RaField();
1200 if (instr->SFField() == 1) {
1201 const int64_t rn_val = get_register(rn, R31IsZR);
1202 const int64_t rm_val = get_register(rm, R31IsZR);
1203 const int64_t ra_val = get_register(ra, R31IsZR);
1204 const int64_t alu_out = ra_val + (rn_val * rm_val);
1205 set_register(rd, alu_out, R31IsZR);
1206 } else {
1207 const int32_t rn_val = get_wregister(rn, R31IsZR);
1208 const int32_t rm_val = get_wregister(rm, R31IsZR);
1209 const int32_t ra_val = get_wregister(ra, R31IsZR);
1210 const int32_t alu_out = ra_val + (rn_val * rm_val);
1211 set_wregister(rd, alu_out, R31IsZR);
1212 }
1213 } else {
1214 UnimplementedInstruction(instr);
1215 }
1216 }
1217
1218
1078 void Simulator::DecodeDPRegister(Instr* instr) { 1219 void Simulator::DecodeDPRegister(Instr* instr) {
1079 if (instr->IsAddSubShiftExtOp()) { 1220 if (instr->IsAddSubShiftExtOp()) {
1080 DecodeAddSubShiftExt(instr); 1221 DecodeAddSubShiftExt(instr);
1081 } else if (instr->IsLogicalShiftOp()) { 1222 } else if (instr->IsLogicalShiftOp()) {
1082 DecodeLogicalShift(instr); 1223 DecodeLogicalShift(instr);
1224 } else if (instr->IsMiscDP2SourceOp()) {
1225 DecodeMiscDP2Source(instr);
1226 } else if (instr->IsMiscDP3SourceOp()) {
1227 DecodeMiscDP3Source(instr);
1083 } else { 1228 } else {
1084 UnimplementedInstruction(instr); 1229 UnimplementedInstruction(instr);
1085 } 1230 }
1086 } 1231 }
1087 1232
1088 1233
1089 void Simulator::DecodeDPSimd1(Instr* instr) { 1234 void Simulator::DecodeDPSimd1(Instr* instr) {
1090 UnimplementedInstruction(instr); 1235 UnimplementedInstruction(instr);
1091 } 1236 }
1092 1237
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
1255 int64_t return_value; 1400 int64_t return_value;
1256 return_value = get_register(R0); 1401 return_value = get_register(R0);
1257 return return_value; 1402 return return_value;
1258 } 1403 }
1259 1404
1260 } // namespace dart 1405 } // namespace dart
1261 1406
1262 #endif // !defined(HOST_ARCH_ARM64) 1407 #endif // !defined(HOST_ARCH_ARM64)
1263 1408
1264 #endif // defined TARGET_ARCH_ARM64 1409 #endif // defined TARGET_ARCH_ARM64
OLDNEW
« no previous file with comments | « runtime/vm/disassembler_arm64.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698