OLD | NEW |
1 // Copyright 2009 the V8 project authors. All rights reserved. | 1 // Copyright 2009 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 1170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1181 #ifdef OBJECT_PRINT | 1181 #ifdef OBJECT_PRINT |
1182 OFStream os(stdout); | 1182 OFStream os(stdout); |
1183 code->Print(os); | 1183 code->Print(os); |
1184 #endif | 1184 #endif |
1185 | 1185 |
1186 F8 f = FUNCTION_CAST<F8>(code->entry()); | 1186 F8 f = FUNCTION_CAST<F8>(code->entry()); |
1187 CHECK_EQ(0, f(9.26621069e-05f, -2.4607749f, -1.09587872f)); | 1187 CHECK_EQ(0, f(9.26621069e-05f, -2.4607749f, -1.09587872f)); |
1188 } | 1188 } |
1189 | 1189 |
1190 | 1190 |
| 1191 TEST(AssemblerX64SSE_ss) { |
| 1192 CcTest::InitializeVM(); |
| 1193 |
| 1194 Isolate* isolate = reinterpret_cast<Isolate*>(CcTest::isolate()); |
| 1195 HandleScope scope(isolate); |
| 1196 v8::internal::byte buffer[1024]; |
| 1197 Assembler assm(isolate, buffer, sizeof(buffer)); |
| 1198 { |
| 1199 Label exit; |
| 1200 // arguments in xmm0, xmm1 and xmm2 |
| 1201 __ movl(rax, Immediate(0)); |
| 1202 |
| 1203 __ movaps(xmm3, xmm0); |
| 1204 __ maxss(xmm3, xmm1); |
| 1205 __ ucomiss(xmm3, xmm1); |
| 1206 __ j(parity_even, &exit); |
| 1207 __ j(not_equal, &exit); |
| 1208 __ movl(rax, Immediate(1)); |
| 1209 |
| 1210 __ movaps(xmm3, xmm1); |
| 1211 __ minss(xmm3, xmm2); |
| 1212 __ ucomiss(xmm3, xmm1); |
| 1213 __ j(parity_even, &exit); |
| 1214 __ j(not_equal, &exit); |
| 1215 __ movl(rax, Immediate(2)); |
| 1216 |
| 1217 __ movaps(xmm3, xmm2); |
| 1218 __ subss(xmm3, xmm1); |
| 1219 __ ucomiss(xmm3, xmm0); |
| 1220 __ j(parity_even, &exit); |
| 1221 __ j(not_equal, &exit); |
| 1222 __ movl(rax, Immediate(3)); |
| 1223 |
| 1224 __ movaps(xmm3, xmm0); |
| 1225 __ addss(xmm3, xmm1); |
| 1226 __ ucomiss(xmm3, xmm2); |
| 1227 __ j(parity_even, &exit); |
| 1228 __ j(not_equal, &exit); |
| 1229 __ movl(rax, Immediate(4)); |
| 1230 |
| 1231 __ movaps(xmm3, xmm0); |
| 1232 __ mulss(xmm3, xmm1); |
| 1233 __ ucomiss(xmm3, xmm1); |
| 1234 __ j(parity_even, &exit); |
| 1235 __ j(not_equal, &exit); |
| 1236 __ movl(rax, Immediate(5)); |
| 1237 |
| 1238 __ movaps(xmm3, xmm0); |
| 1239 __ divss(xmm3, xmm1); |
| 1240 __ mulss(xmm3, xmm2); |
| 1241 __ mulss(xmm3, xmm1); |
| 1242 __ ucomiss(xmm3, xmm2); |
| 1243 __ j(parity_even, &exit); |
| 1244 __ j(not_equal, &exit); |
| 1245 __ movl(rax, Immediate(6)); |
| 1246 |
| 1247 // result in eax |
| 1248 __ bind(&exit); |
| 1249 __ ret(0); |
| 1250 } |
| 1251 |
| 1252 CodeDesc desc; |
| 1253 assm.GetCode(&desc); |
| 1254 Handle<Code> code = isolate->factory()->NewCode( |
| 1255 desc, Code::ComputeFlags(Code::STUB), Handle<Code>()); |
| 1256 #ifdef OBJECT_PRINT |
| 1257 OFStream os(stdout); |
| 1258 code->Print(os); |
| 1259 #endif |
| 1260 |
| 1261 F8 f = FUNCTION_CAST<F8>(code->entry()); |
| 1262 int res = f(1.0f, 2.0f, 3.0f); |
| 1263 PrintF("f(1,2,3) = %d\n", res); |
| 1264 CHECK_EQ(6, res); |
| 1265 } |
| 1266 |
| 1267 |
| 1268 TEST(AssemblerX64AVX_ss) { |
| 1269 CcTest::InitializeVM(); |
| 1270 if (!CpuFeatures::IsSupported(AVX)) return; |
| 1271 |
| 1272 Isolate* isolate = reinterpret_cast<Isolate*>(CcTest::isolate()); |
| 1273 HandleScope scope(isolate); |
| 1274 v8::internal::byte buffer[1024]; |
| 1275 Assembler assm(isolate, buffer, sizeof(buffer)); |
| 1276 { |
| 1277 CpuFeatureScope avx_scope(&assm, AVX); |
| 1278 Label exit; |
| 1279 // arguments in xmm0, xmm1 and xmm2 |
| 1280 __ movl(rax, Immediate(0)); |
| 1281 |
| 1282 __ vmaxss(xmm3, xmm0, xmm1); |
| 1283 __ vucomiss(xmm3, xmm1); |
| 1284 __ j(parity_even, &exit); |
| 1285 __ j(not_equal, &exit); |
| 1286 __ movl(rax, Immediate(1)); |
| 1287 |
| 1288 __ vminss(xmm3, xmm1, xmm2); |
| 1289 __ vucomiss(xmm3, xmm1); |
| 1290 __ j(parity_even, &exit); |
| 1291 __ j(not_equal, &exit); |
| 1292 __ movl(rax, Immediate(2)); |
| 1293 |
| 1294 __ vsubss(xmm3, xmm2, xmm1); |
| 1295 __ vucomiss(xmm3, xmm0); |
| 1296 __ j(parity_even, &exit); |
| 1297 __ j(not_equal, &exit); |
| 1298 __ movl(rax, Immediate(3)); |
| 1299 |
| 1300 __ vaddss(xmm3, xmm0, xmm1); |
| 1301 __ vucomiss(xmm3, xmm2); |
| 1302 __ j(parity_even, &exit); |
| 1303 __ j(not_equal, &exit); |
| 1304 __ movl(rax, Immediate(4)); |
| 1305 |
| 1306 __ vmulss(xmm3, xmm0, xmm1); |
| 1307 __ vucomiss(xmm3, xmm1); |
| 1308 __ j(parity_even, &exit); |
| 1309 __ j(not_equal, &exit); |
| 1310 __ movl(rax, Immediate(5)); |
| 1311 |
| 1312 __ vdivss(xmm3, xmm0, xmm1); |
| 1313 __ vmulss(xmm3, xmm3, xmm2); |
| 1314 __ vmulss(xmm3, xmm3, xmm1); |
| 1315 __ vucomiss(xmm3, xmm2); |
| 1316 __ j(parity_even, &exit); |
| 1317 __ j(not_equal, &exit); |
| 1318 __ movl(rax, Immediate(6)); |
| 1319 |
| 1320 // result in eax |
| 1321 __ bind(&exit); |
| 1322 __ ret(0); |
| 1323 } |
| 1324 |
| 1325 CodeDesc desc; |
| 1326 assm.GetCode(&desc); |
| 1327 Handle<Code> code = isolate->factory()->NewCode( |
| 1328 desc, Code::ComputeFlags(Code::STUB), Handle<Code>()); |
| 1329 #ifdef OBJECT_PRINT |
| 1330 OFStream os(stdout); |
| 1331 code->Print(os); |
| 1332 #endif |
| 1333 |
| 1334 F8 f = FUNCTION_CAST<F8>(code->entry()); |
| 1335 int res = f(1.0f, 2.0f, 3.0f); |
| 1336 PrintF("f(1,2,3) = %d\n", res); |
| 1337 CHECK_EQ(6, res); |
| 1338 } |
| 1339 |
| 1340 |
| 1341 TEST(AssemblerX64AVX_sd) { |
| 1342 CcTest::InitializeVM(); |
| 1343 if (!CpuFeatures::IsSupported(AVX)) return; |
| 1344 |
| 1345 Isolate* isolate = reinterpret_cast<Isolate*>(CcTest::isolate()); |
| 1346 HandleScope scope(isolate); |
| 1347 v8::internal::byte buffer[1024]; |
| 1348 Assembler assm(isolate, buffer, sizeof(buffer)); |
| 1349 { |
| 1350 CpuFeatureScope avx_scope(&assm, AVX); |
| 1351 Label exit; |
| 1352 // arguments in xmm0, xmm1 and xmm2 |
| 1353 __ movl(rax, Immediate(0)); |
| 1354 |
| 1355 __ vmaxsd(xmm3, xmm0, xmm1); |
| 1356 __ vucomisd(xmm3, xmm1); |
| 1357 __ j(parity_even, &exit); |
| 1358 __ j(not_equal, &exit); |
| 1359 __ movl(rax, Immediate(1)); |
| 1360 |
| 1361 __ vminsd(xmm3, xmm1, xmm2); |
| 1362 __ vucomisd(xmm3, xmm1); |
| 1363 __ j(parity_even, &exit); |
| 1364 __ j(not_equal, &exit); |
| 1365 __ movl(rax, Immediate(2)); |
| 1366 |
| 1367 __ vsubsd(xmm3, xmm2, xmm1); |
| 1368 __ vucomisd(xmm3, xmm0); |
| 1369 __ j(parity_even, &exit); |
| 1370 __ j(not_equal, &exit); |
| 1371 __ movl(rax, Immediate(3)); |
| 1372 |
| 1373 __ vaddsd(xmm3, xmm0, xmm1); |
| 1374 __ vucomisd(xmm3, xmm2); |
| 1375 __ j(parity_even, &exit); |
| 1376 __ j(not_equal, &exit); |
| 1377 __ movl(rax, Immediate(4)); |
| 1378 |
| 1379 __ vmulsd(xmm3, xmm0, xmm1); |
| 1380 __ vucomisd(xmm3, xmm1); |
| 1381 __ j(parity_even, &exit); |
| 1382 __ j(not_equal, &exit); |
| 1383 __ movl(rax, Immediate(5)); |
| 1384 |
| 1385 __ vdivsd(xmm3, xmm0, xmm1); |
| 1386 __ vmulsd(xmm3, xmm3, xmm2); |
| 1387 __ vmulsd(xmm3, xmm3, xmm1); |
| 1388 __ vucomisd(xmm3, xmm2); |
| 1389 __ j(parity_even, &exit); |
| 1390 __ j(not_equal, &exit); |
| 1391 __ movl(rax, Immediate(6)); |
| 1392 |
| 1393 // result in eax |
| 1394 __ bind(&exit); |
| 1395 __ ret(0); |
| 1396 } |
| 1397 |
| 1398 CodeDesc desc; |
| 1399 assm.GetCode(&desc); |
| 1400 Handle<Code> code = isolate->factory()->NewCode( |
| 1401 desc, Code::ComputeFlags(Code::STUB), Handle<Code>()); |
| 1402 #ifdef OBJECT_PRINT |
| 1403 OFStream os(stdout); |
| 1404 code->Print(os); |
| 1405 #endif |
| 1406 |
| 1407 F7 f = FUNCTION_CAST<F7>(code->entry()); |
| 1408 int res = f(1.0, 2.0, 3.0); |
| 1409 PrintF("f(1,2,3) = %d\n", res); |
| 1410 CHECK_EQ(6, res); |
| 1411 } |
| 1412 |
| 1413 |
1191 TEST(AssemblerX64JumpTables1) { | 1414 TEST(AssemblerX64JumpTables1) { |
1192 // Test jump tables with forward jumps. | 1415 // Test jump tables with forward jumps. |
1193 CcTest::InitializeVM(); | 1416 CcTest::InitializeVM(); |
1194 Isolate* isolate = reinterpret_cast<Isolate*>(CcTest::isolate()); | 1417 Isolate* isolate = reinterpret_cast<Isolate*>(CcTest::isolate()); |
1195 HandleScope scope(isolate); | 1418 HandleScope scope(isolate); |
1196 MacroAssembler assm(isolate, nullptr, 0); | 1419 MacroAssembler assm(isolate, nullptr, 0); |
1197 | 1420 |
1198 const int kNumCases = 512; | 1421 const int kNumCases = 512; |
1199 int values[kNumCases]; | 1422 int values[kNumCases]; |
1200 isolate->random_number_generator()->NextBytes(values, sizeof(values)); | 1423 isolate->random_number_generator()->NextBytes(values, sizeof(values)); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1276 | 1499 |
1277 F1 f = FUNCTION_CAST<F1>(code->entry()); | 1500 F1 f = FUNCTION_CAST<F1>(code->entry()); |
1278 for (int i = 0; i < kNumCases; ++i) { | 1501 for (int i = 0; i < kNumCases; ++i) { |
1279 int res = f(i); | 1502 int res = f(i); |
1280 PrintF("f(%d) = %d\n", i, res); | 1503 PrintF("f(%d) = %d\n", i, res); |
1281 CHECK_EQ(values[i], res); | 1504 CHECK_EQ(values[i], res); |
1282 } | 1505 } |
1283 } | 1506 } |
1284 | 1507 |
1285 #undef __ | 1508 #undef __ |
OLD | NEW |