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

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: rebased the patch 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 357
358 358
359 static double BinaryOpC(Token::Value op, double lhs, double rhs) { 359 static double BinaryOpC(Token::Value op, double lhs, double rhs) {
360 switch (op) { 360 switch (op) {
361 case Token::Value::ADD: 361 case Token::Value::ADD:
362 return lhs + rhs; 362 return lhs + rhs;
363 case Token::Value::SUB: 363 case Token::Value::SUB:
364 return lhs - rhs; 364 return lhs - rhs;
365 case Token::Value::MUL: 365 case Token::Value::MUL:
366 return lhs * rhs; 366 return lhs * rhs;
367 case Token::Value::DIV: 367 case Token::Value::DIV:
368 return lhs / rhs; 368 return lhs / rhs;
369 case Token::Value::MOD: 369 case Token::Value::MOD:
370 return std::fmod(lhs, rhs); 370 return std::fmod(lhs, rhs);
371 case Token::Value::SHL: {
372 int32_t val = v8::internal::DoubleToInt32(lhs);
373 uint32_t count = v8::internal::DoubleToUint32(rhs) & 0x1F;
374 return val << count;
375 }
376 case Token::Value::SAR: {
377 int32_t val = v8::internal::DoubleToInt32(lhs);
378 uint32_t count = v8::internal::DoubleToUint32(rhs) & 0x1F;
379 return val >> count;
380 }
381 case Token::Value::SHR: {
382 uint32_t val = v8::internal::DoubleToUint32(lhs);
383 uint32_t count = v8::internal::DoubleToUint32(rhs) & 0x1F;
384 return val >> count;
oth 2015/10/07 13:53:17 Can we have a separate test for the shift operator
mythria 2015/10/08 14:33:44 Done.
385 }
371 default: 386 default:
372 UNREACHABLE(); 387 UNREACHABLE();
373 return std::numeric_limits<double>::min(); 388 return std::numeric_limits<double>::min();
374 } 389 }
375 } 390 }
376 391
377 392
378 TEST(InterpreterBinaryOpsSmi) { 393 TEST(InterpreterBinaryOpsSmi) {
379 int lhs_inputs[] = {3266, 1024, 0, -17, -18000}; 394 int lhs_inputs[] = {3266, 1024, 0, -17, -18000};
380 int rhs_inputs[] = {3266, 5, 4, 3, 2, 1, -1, -2}; 395 int rhs_inputs[] = {3266, 5, 4, 3, 2, 1, -1, -2};
(...skipping 1083 matching lines...) Expand 10 before | Expand all | Expand 10 after
1464 .CallRuntime(Runtime::kAdd, Register(0), 2) 1479 .CallRuntime(Runtime::kAdd, Register(0), 2)
1465 .Return(); 1480 .Return();
1466 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); 1481 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray();
1467 1482
1468 InterpreterTester tester(handles.main_isolate(), bytecode_array); 1483 InterpreterTester tester(handles.main_isolate(), bytecode_array);
1469 auto callable = tester.GetCallable<>(); 1484 auto callable = tester.GetCallable<>();
1470 1485
1471 Handle<Object> return_val = callable().ToHandleChecked(); 1486 Handle<Object> return_val = callable().ToHandleChecked();
1472 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(55)); 1487 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(55));
1473 } 1488 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698