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

Side by Side Diff: test/cctest/test-assembler-ia32.cc

Issue 1069683002: [ia32] Introduce BMI instructions. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Align with gdb disassembler Created 5 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
« no previous file with comments | « src/ia32/macro-assembler-ia32.cc ('k') | test/cctest/test-disasm-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 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 1026 matching lines...) Expand 10 before | Expand all | Expand 10 after
1037 #ifdef OBJECT_PRINT 1037 #ifdef OBJECT_PRINT
1038 OFStream os(stdout); 1038 OFStream os(stdout);
1039 code->Print(os); 1039 code->Print(os);
1040 #endif 1040 #endif
1041 1041
1042 F10 f = FUNCTION_CAST<F10>(code->entry()); 1042 F10 f = FUNCTION_CAST<F10>(code->entry());
1043 CHECK_EQ(0, f(9.26621069e-05f, -2.4607749f, -1.09587872f)); 1043 CHECK_EQ(0, f(9.26621069e-05f, -2.4607749f, -1.09587872f));
1044 } 1044 }
1045 1045
1046 1046
1047 TEST(AssemblerIa32BMI1) {
1048 CcTest::InitializeVM();
1049 if (!CpuFeatures::IsSupported(BMI1)) return;
1050
1051 Isolate* isolate = reinterpret_cast<Isolate*>(CcTest::isolate());
1052 HandleScope scope(isolate);
1053 v8::internal::byte buffer[1024];
1054 MacroAssembler assm(isolate, buffer, sizeof buffer);
1055 {
1056 CpuFeatureScope fscope(&assm, BMI1);
1057 Label exit;
1058
1059 __ push(ebx); // save ebx
1060 __ mov(ecx, Immediate(0x55667788u)); // source operand
1061 __ push(ecx); // For memory operand
1062
1063 // andn
1064 __ mov(edx, Immediate(0x20000000u));
1065
1066 __ mov(eax, Immediate(1)); // Test number
1067 __ andn(ebx, edx, ecx);
1068 __ cmp(ebx, Immediate(0x55667788u)); // expected result
1069 __ j(not_equal, &exit);
1070
1071 __ inc(eax);
1072 __ andn(ebx, edx, Operand(esp, 0));
1073 __ cmp(ebx, Immediate(0x55667788u)); // expected result
1074 __ j(not_equal, &exit);
1075
1076 // bextr
1077 __ mov(edx, Immediate(0x00002808u));
1078
1079 __ inc(eax);
1080 __ bextr(ebx, ecx, edx);
1081 __ cmp(ebx, Immediate(0x00556677u)); // expected result
1082 __ j(not_equal, &exit);
1083
1084 __ inc(eax);
1085 __ bextr(ebx, Operand(esp, 0), edx);
1086 __ cmp(ebx, Immediate(0x00556677u)); // expected result
1087 __ j(not_equal, &exit);
1088
1089 // blsi
1090 __ inc(eax);
1091 __ blsi(ebx, ecx);
1092 __ cmp(ebx, Immediate(0x00000008u)); // expected result
1093 __ j(not_equal, &exit);
1094
1095 __ inc(eax);
1096 __ blsi(ebx, Operand(esp, 0));
1097 __ cmp(ebx, Immediate(0x00000008u)); // expected result
1098 __ j(not_equal, &exit);
1099
1100 // blsmsk
1101 __ inc(eax);
1102 __ blsmsk(ebx, ecx);
1103 __ cmp(ebx, Immediate(0x0000000fu)); // expected result
1104 __ j(not_equal, &exit);
1105
1106 __ inc(eax);
1107 __ blsmsk(ebx, Operand(esp, 0));
1108 __ cmp(ebx, Immediate(0x0000000fu)); // expected result
1109 __ j(not_equal, &exit);
1110
1111 // blsr
1112 __ inc(eax);
1113 __ blsr(ebx, ecx);
1114 __ cmp(ebx, Immediate(0x55667780u)); // expected result
1115 __ j(not_equal, &exit);
1116
1117 __ inc(eax);
1118 __ blsr(ebx, Operand(esp, 0));
1119 __ cmp(ebx, Immediate(0x55667780u)); // expected result
1120 __ j(not_equal, &exit);
1121
1122 // tzcnt
1123 __ inc(eax);
1124 __ tzcnt(ebx, ecx);
1125 __ cmp(ebx, Immediate(3)); // expected result
1126 __ j(not_equal, &exit);
1127
1128 __ inc(eax);
1129 __ tzcnt(ebx, Operand(esp, 0));
1130 __ cmp(ebx, Immediate(3)); // expected result
1131 __ j(not_equal, &exit);
1132
1133 __ xor_(eax, eax);
1134 __ bind(&exit);
1135 __ pop(ecx);
1136 __ pop(ebx);
1137 __ ret(0);
1138 }
1139
1140 CodeDesc desc;
1141 assm.GetCode(&desc);
1142 Handle<Code> code = isolate->factory()->NewCode(
1143 desc, Code::ComputeFlags(Code::STUB), Handle<Code>());
1144 #ifdef OBJECT_PRINT
1145 OFStream os(stdout);
1146 code->Print(os);
1147 #endif
1148
1149 F0 f = FUNCTION_CAST<F0>(code->entry());
1150 CHECK_EQ(0, f());
1151 }
1152
1153
1154 TEST(AssemblerIa32LZCNT) {
1155 CcTest::InitializeVM();
1156 if (!CpuFeatures::IsSupported(LZCNT)) return;
1157
1158 Isolate* isolate = reinterpret_cast<Isolate*>(CcTest::isolate());
1159 HandleScope scope(isolate);
1160 v8::internal::byte buffer[256];
1161 MacroAssembler assm(isolate, buffer, sizeof buffer);
1162 {
1163 CpuFeatureScope fscope(&assm, LZCNT);
1164 Label exit;
1165
1166 __ push(ebx); // save ebx
1167 __ mov(ecx, Immediate(0x55667788u)); // source operand
1168 __ push(ecx); // For memory operand
1169
1170 __ mov(eax, Immediate(1)); // Test number
1171 __ lzcnt(ebx, ecx);
1172 __ cmp(ebx, Immediate(1)); // expected result
1173 __ j(not_equal, &exit);
1174
1175 __ inc(eax);
1176 __ lzcnt(ebx, Operand(esp, 0));
1177 __ cmp(ebx, Immediate(1)); // expected result
1178 __ j(not_equal, &exit);
1179
1180 __ xor_(eax, eax);
1181 __ bind(&exit);
1182 __ pop(ecx);
1183 __ pop(ebx);
1184 __ ret(0);
1185 }
1186
1187 CodeDesc desc;
1188 assm.GetCode(&desc);
1189 Handle<Code> code = isolate->factory()->NewCode(
1190 desc, Code::ComputeFlags(Code::STUB), Handle<Code>());
1191 #ifdef OBJECT_PRINT
1192 OFStream os(stdout);
1193 code->Print(os);
1194 #endif
1195
1196 F0 f = FUNCTION_CAST<F0>(code->entry());
1197 CHECK_EQ(0, f());
1198 }
1199
1200
1201 TEST(AssemblerIa32POPCNT) {
1202 CcTest::InitializeVM();
1203 if (!CpuFeatures::IsSupported(POPCNT)) return;
1204
1205 Isolate* isolate = reinterpret_cast<Isolate*>(CcTest::isolate());
1206 HandleScope scope(isolate);
1207 v8::internal::byte buffer[256];
1208 MacroAssembler assm(isolate, buffer, sizeof buffer);
1209 {
1210 CpuFeatureScope fscope(&assm, POPCNT);
1211 Label exit;
1212
1213 __ push(ebx); // save ebx
1214 __ mov(ecx, Immediate(0x11111100u)); // source operand
1215 __ push(ecx); // For memory operand
1216
1217 __ mov(eax, Immediate(1)); // Test number
1218 __ popcnt(ebx, ecx);
1219 __ cmp(ebx, Immediate(6)); // expected result
1220 __ j(not_equal, &exit);
1221
1222 __ inc(eax);
1223 __ popcnt(ebx, Operand(esp, 0));
1224 __ cmp(ebx, Immediate(6)); // expected result
1225 __ j(not_equal, &exit);
1226
1227 __ xor_(eax, eax);
1228 __ bind(&exit);
1229 __ pop(ecx);
1230 __ pop(ebx);
1231 __ ret(0);
1232 }
1233
1234 CodeDesc desc;
1235 assm.GetCode(&desc);
1236 Handle<Code> code = isolate->factory()->NewCode(
1237 desc, Code::ComputeFlags(Code::STUB), Handle<Code>());
1238 #ifdef OBJECT_PRINT
1239 OFStream os(stdout);
1240 code->Print(os);
1241 #endif
1242
1243 F0 f = FUNCTION_CAST<F0>(code->entry());
1244 CHECK_EQ(0, f());
1245 }
1246
1247
1248 TEST(AssemblerIa32BMI2) {
1249 CcTest::InitializeVM();
1250 if (!CpuFeatures::IsSupported(BMI2)) return;
1251
1252 Isolate* isolate = reinterpret_cast<Isolate*>(CcTest::isolate());
1253 HandleScope scope(isolate);
1254 v8::internal::byte buffer[2048];
1255 MacroAssembler assm(isolate, buffer, sizeof buffer);
1256 {
1257 CpuFeatureScope fscope(&assm, BMI2);
1258 Label exit;
1259
1260 __ push(ebx); // save ebx
1261 __ push(esi); // save esi
1262 __ mov(ecx, Immediate(0x55667788u)); // source operand
1263 __ push(ecx); // For memory operand
1264
1265 // bzhi
1266 __ mov(edx, Immediate(9));
1267
1268 __ mov(eax, Immediate(1)); // Test number
1269 __ bzhi(ebx, ecx, edx);
1270 __ cmp(ebx, Immediate(0x00000188u)); // expected result
1271 __ j(not_equal, &exit);
1272
1273 __ inc(eax);
1274 __ bzhi(ebx, Operand(esp, 0), edx);
1275 __ cmp(ebx, Immediate(0x00000188u)); // expected result
1276 __ j(not_equal, &exit);
1277
1278 // mulx
1279 __ mov(edx, Immediate(0x00001000u));
1280
1281 __ inc(eax);
1282 __ mulx(ebx, esi, ecx);
1283 __ cmp(ebx, Immediate(0x00000556u)); // expected result
1284 __ j(not_equal, &exit);
1285 __ cmp(esi, Immediate(0x67788000u)); // expected result
1286 __ j(not_equal, &exit);
1287
1288 __ inc(eax);
1289 __ mulx(ebx, esi, Operand(esp, 0));
1290 __ cmp(ebx, Immediate(0x00000556u)); // expected result
1291 __ j(not_equal, &exit);
1292 __ cmp(esi, Immediate(0x67788000u)); // expected result
1293 __ j(not_equal, &exit);
1294
1295 // pdep
1296 __ mov(edx, Immediate(0xfffffff0u));
1297
1298 __ inc(eax);
1299 __ pdep(ebx, edx, ecx);
1300 __ cmp(ebx, Immediate(0x55667400u)); // expected result
1301 __ j(not_equal, &exit);
1302
1303 __ inc(eax);
1304 __ pdep(ebx, edx, Operand(esp, 0));
1305 __ cmp(ebx, Immediate(0x55667400u)); // expected result
1306 __ j(not_equal, &exit);
1307
1308 // pext
1309 __ mov(edx, Immediate(0xfffffff0u));
1310
1311 __ inc(eax);
1312 __ pext(ebx, edx, ecx);
1313 __ cmp(ebx, Immediate(0x0000fffeu)); // expected result
1314 __ j(not_equal, &exit);
1315
1316 __ inc(eax);
1317 __ pext(ebx, edx, Operand(esp, 0));
1318 __ cmp(ebx, Immediate(0x0000fffeu)); // expected result
1319 __ j(not_equal, &exit);
1320
1321 // sarx
1322 __ mov(edx, Immediate(4));
1323
1324 __ inc(eax);
1325 __ sarx(ebx, ecx, edx);
1326 __ cmp(ebx, Immediate(0x05566778u)); // expected result
1327 __ j(not_equal, &exit);
1328
1329 __ inc(eax);
1330 __ sarx(ebx, Operand(esp, 0), edx);
1331 __ cmp(ebx, Immediate(0x05566778u)); // expected result
1332 __ j(not_equal, &exit);
1333
1334 // shlx
1335 __ mov(edx, Immediate(4));
1336
1337 __ inc(eax);
1338 __ shlx(ebx, ecx, edx);
1339 __ cmp(ebx, Immediate(0x56677880u)); // expected result
1340 __ j(not_equal, &exit);
1341
1342 __ inc(eax);
1343 __ shlx(ebx, Operand(esp, 0), edx);
1344 __ cmp(ebx, Immediate(0x56677880u)); // expected result
1345 __ j(not_equal, &exit);
1346
1347 // shrx
1348 __ mov(edx, Immediate(4));
1349
1350 __ inc(eax);
1351 __ shrx(ebx, ecx, edx);
1352 __ cmp(ebx, Immediate(0x05566778u)); // expected result
1353 __ j(not_equal, &exit);
1354
1355 __ inc(eax);
1356 __ shrx(ebx, Operand(esp, 0), edx);
1357 __ cmp(ebx, Immediate(0x05566778u)); // expected result
1358 __ j(not_equal, &exit);
1359
1360 // rorx
1361 __ inc(eax);
1362 __ rorx(ebx, ecx, 0x4);
1363 __ cmp(ebx, Immediate(0x85566778u)); // expected result
1364 __ j(not_equal, &exit);
1365
1366 __ inc(eax);
1367 __ rorx(ebx, Operand(esp, 0), 0x4);
1368 __ cmp(ebx, Immediate(0x85566778u)); // expected result
1369 __ j(not_equal, &exit);
1370
1371 __ xor_(eax, eax);
1372 __ bind(&exit);
1373 __ pop(ecx);
1374 __ pop(esi);
1375 __ pop(ebx);
1376 __ ret(0);
1377 }
1378
1379 CodeDesc desc;
1380 assm.GetCode(&desc);
1381 Handle<Code> code = isolate->factory()->NewCode(
1382 desc, Code::ComputeFlags(Code::STUB), Handle<Code>());
1383 #ifdef OBJECT_PRINT
1384 OFStream os(stdout);
1385 code->Print(os);
1386 #endif
1387
1388 F0 f = FUNCTION_CAST<F0>(code->entry());
1389 CHECK_EQ(0, f());
1390 }
1391
1392
1047 TEST(AssemblerIa32JumpTables1) { 1393 TEST(AssemblerIa32JumpTables1) {
1048 // Test jump tables with forward jumps. 1394 // Test jump tables with forward jumps.
1049 CcTest::InitializeVM(); 1395 CcTest::InitializeVM();
1050 Isolate* isolate = reinterpret_cast<Isolate*>(CcTest::isolate()); 1396 Isolate* isolate = reinterpret_cast<Isolate*>(CcTest::isolate());
1051 HandleScope scope(isolate); 1397 HandleScope scope(isolate);
1052 Assembler assm(isolate, nullptr, 0); 1398 Assembler assm(isolate, nullptr, 0);
1053 1399
1054 const int kNumCases = 512; 1400 const int kNumCases = 512;
1055 int values[kNumCases]; 1401 int values[kNumCases];
1056 isolate->random_number_generator()->NextBytes(values, sizeof(values)); 1402 isolate->random_number_generator()->NextBytes(values, sizeof(values));
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
1132 #endif 1478 #endif
1133 F1 f = FUNCTION_CAST<F1>(code->entry()); 1479 F1 f = FUNCTION_CAST<F1>(code->entry());
1134 for (int i = 0; i < kNumCases; ++i) { 1480 for (int i = 0; i < kNumCases; ++i) {
1135 int res = f(i); 1481 int res = f(i);
1136 ::printf("f(%d) = %d\n", i, res); 1482 ::printf("f(%d) = %d\n", i, res);
1137 CHECK_EQ(values[i], res); 1483 CHECK_EQ(values[i], res);
1138 } 1484 }
1139 } 1485 }
1140 1486
1141 #undef __ 1487 #undef __
OLDNEW
« no previous file with comments | « src/ia32/macro-assembler-ia32.cc ('k') | test/cctest/test-disasm-ia32.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698