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

Side by Side Diff: test/cctest/interpreter/test-interpreter.cc

Issue 1392913002: [Interpreter] Adds shift operators to interpreter (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fixed a test for shift operators and comments Created 5 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
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/execution.h" 7 #include "src/execution.h"
8 #include "src/handles.h" 8 #include "src/handles.h"
9 #include "src/interpreter/bytecode-array-builder.h" 9 #include "src/interpreter/bytecode-array-builder.h"
10 #include "src/interpreter/interpreter.h" 10 #include "src/interpreter/interpreter.h"
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 345
346 InterpreterTester tester(handles.main_isolate(), bytecode_array); 346 InterpreterTester tester(handles.main_isolate(), bytecode_array);
347 auto callable = tester.GetCallable<>(); 347 auto callable = tester.GetCallable<>();
348 Handle<Object> return_val = callable().ToHandleChecked(); 348 Handle<Object> return_val = callable().ToHandleChecked();
349 CHECK(return_val.is_identical_to(true_value)); 349 CHECK(return_val.is_identical_to(true_value));
350 } 350 }
351 } 351 }
352 352
353 353
354 static const Token::Value kArithmeticOperators[] = { 354 static const Token::Value kArithmeticOperators[] = {
355 Token::Value::ADD, Token::Value::SUB, Token::Value::MUL, Token::Value::DIV, 355 Token::Value::SHL, Token::Value::SAR, Token::Value::SHR, Token::Value::ADD,
356 Token::Value::MOD}; 356 Token::Value::SUB, Token::Value::MUL, Token::Value::DIV, Token::Value::MOD};
357
358
359 static const Token::Value kShiftOperators[] = {
360 Token::Value::SHL, Token::Value::SAR, Token::Value::SHR};
357 361
358 362
359 static double BinaryOpC(Token::Value op, double lhs, double rhs) { 363 static double BinaryOpC(Token::Value op, double lhs, double rhs) {
360 switch (op) { 364 switch (op) {
361 case Token::Value::ADD: 365 case Token::Value::ADD:
362 return lhs + rhs; 366 return lhs + rhs;
363 case Token::Value::SUB: 367 case Token::Value::SUB:
364 return lhs - rhs; 368 return lhs - rhs;
365 case Token::Value::MUL: 369 case Token::Value::MUL:
366 return lhs * rhs; 370 return lhs * rhs;
367 case Token::Value::DIV: 371 case Token::Value::DIV:
368 return lhs / rhs; 372 return lhs / rhs;
369 case Token::Value::MOD: 373 case Token::Value::MOD:
370 return std::fmod(lhs, rhs); 374 return std::fmod(lhs, rhs);
375 case Token::Value::SHL: {
376 int32_t val = v8::internal::DoubleToInt32(lhs);
377 uint32_t count = v8::internal::DoubleToUint32(rhs) & 0x1F;
378 int32_t result = val << count;
379 return result;
380 }
381 case Token::Value::SAR: {
382 int32_t val = v8::internal::DoubleToInt32(lhs);
383 uint32_t count = v8::internal::DoubleToUint32(rhs) & 0x1F;
384 int32_t result = val >> count;
385 return result;
386 }
387 case Token::Value::SHR: {
388 uint32_t val = v8::internal::DoubleToUint32(lhs);
389 uint32_t count = v8::internal::DoubleToUint32(rhs) & 0x1F;
390 uint32_t result = val >> count;
391 return result;
392 }
371 default: 393 default:
372 UNREACHABLE(); 394 UNREACHABLE();
373 return std::numeric_limits<double>::min(); 395 return std::numeric_limits<double>::min();
374 } 396 }
375 } 397 }
376 398
377 399
400 TEST(InterpreterShiftOpsSmi) {
401 int lhs_inputs[] = {0, -17, -182, 1073741823, -1};
402 int rhs_inputs[] = {5, 2, 1, -1, -2, 0, 31, 32, -32, 64, 37};
403 for (size_t l = 0; l < arraysize(lhs_inputs); l++) {
404 for (size_t r = 0; r < arraysize(rhs_inputs); r++) {
405 for (size_t o = 0; o < arraysize(kShiftOperators); o++) {
406 HandleAndZoneScope handles;
407 i::Factory* factory = handles.main_isolate()->factory();
408 BytecodeArrayBuilder builder(handles.main_isolate(),
409 handles.main_zone());
410 builder.set_locals_count(1);
411 builder.set_parameter_count(1);
412 Register reg(0);
413 int lhs = lhs_inputs[l];
414 int rhs = rhs_inputs[r];
415 builder.LoadLiteral(Smi::FromInt(lhs))
416 .StoreAccumulatorInRegister(reg)
417 .LoadLiteral(Smi::FromInt(rhs))
418 .BinaryOperation(kArithmeticOperators[o], reg, Strength::WEAK)
419 .Return();
420 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray();
421
422 InterpreterTester tester(handles.main_isolate(), bytecode_array);
423 auto callable = tester.GetCallable<>();
424 Handle<Object> return_value = callable().ToHandleChecked();
425 Handle<Object> expected_value =
426 factory->NewNumber(BinaryOpC(kShiftOperators[o], lhs, rhs));
427 CHECK(return_value->SameValue(*expected_value));
428 }
429 }
430 }
431 }
432
433
378 TEST(InterpreterBinaryOpsSmi) { 434 TEST(InterpreterBinaryOpsSmi) {
379 int lhs_inputs[] = {3266, 1024, 0, -17, -18000}; 435 int lhs_inputs[] = {3266, 1024, 0, -17, -18000};
380 int rhs_inputs[] = {3266, 5, 4, 3, 2, 1, -1, -2}; 436 int rhs_inputs[] = {3266, 5, 4, 3, 2, 1, -1, -2};
381 for (size_t l = 0; l < arraysize(lhs_inputs); l++) { 437 for (size_t l = 0; l < arraysize(lhs_inputs); l++) {
382 for (size_t r = 0; r < arraysize(rhs_inputs); r++) { 438 for (size_t r = 0; r < arraysize(rhs_inputs); r++) {
383 for (size_t o = 0; o < arraysize(kArithmeticOperators); o++) { 439 for (size_t o = 0; o < arraysize(kArithmeticOperators); o++) {
384 HandleAndZoneScope handles; 440 HandleAndZoneScope handles;
385 i::Factory* factory = handles.main_isolate()->factory(); 441 i::Factory* factory = handles.main_isolate()->factory();
386 BytecodeArrayBuilder builder(handles.main_isolate(), 442 BytecodeArrayBuilder builder(handles.main_isolate(),
387 handles.main_zone()); 443 handles.main_zone());
(...skipping 1076 matching lines...) Expand 10 before | Expand all | Expand 10 after
1464 .CallRuntime(Runtime::kAdd, Register(0), 2) 1520 .CallRuntime(Runtime::kAdd, Register(0), 2)
1465 .Return(); 1521 .Return();
1466 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); 1522 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray();
1467 1523
1468 InterpreterTester tester(handles.main_isolate(), bytecode_array); 1524 InterpreterTester tester(handles.main_isolate(), bytecode_array);
1469 auto callable = tester.GetCallable<>(); 1525 auto callable = tester.GetCallable<>();
1470 1526
1471 Handle<Object> return_val = callable().ToHandleChecked(); 1527 Handle<Object> return_val = callable().ToHandleChecked();
1472 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(55)); 1528 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(55));
1473 } 1529 }
OLDNEW
« no previous file with comments | « test/cctest/interpreter/test-bytecode-generator.cc ('k') | test/unittests/interpreter/bytecode-array-builder-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698