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

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

Issue 1386133002: [Interpreter] Add bitwise operators (Or, Xor, And) to interpreter (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: 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 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 343
344 InterpreterTester tester(handles.main_isolate(), bytecode_array); 344 InterpreterTester tester(handles.main_isolate(), bytecode_array);
345 auto callable = tester.GetCallable<>(); 345 auto callable = tester.GetCallable<>();
346 Handle<Object> return_val = callable().ToHandleChecked(); 346 Handle<Object> return_val = callable().ToHandleChecked();
347 CHECK(return_val.is_identical_to(true_value)); 347 CHECK(return_val.is_identical_to(true_value));
348 } 348 }
349 } 349 }
350 350
351 351
352 static const Token::Value kArithmeticOperators[] = { 352 static const Token::Value kArithmeticOperators[] = {
353 Token::Value::ADD, Token::Value::SUB, Token::Value::MUL, Token::Value::DIV, 353 Token::Value::BIT_OR, Token::Value::BIT_XOR, Token::Value::BIT_AND,
354 Token::Value::MOD}; 354 Token::Value::ADD, Token::Value::SUB, Token::Value::MUL,
355 Token::Value::DIV, Token::Value::MOD};
355 356
356 357
357 static double BinaryOpC(Token::Value op, double lhs, double rhs) { 358 static double BinaryOpC(Token::Value op, double lhs, double rhs) {
358 switch (op) { 359 switch (op) {
360 case Token::Value::BIT_OR:
361 return (v8::internal::DoubleToInt32(lhs) |
362 v8::internal::DoubleToInt32(rhs));
363 case Token::Value::BIT_XOR:
364 return (v8::internal::DoubleToInt32(lhs) ^
365 v8::internal::DoubleToInt32(rhs));
366 case Token::Value::BIT_AND:
367 return (v8::internal::DoubleToInt32(lhs) &
368 v8::internal::DoubleToInt32(rhs));
359 case Token::Value::ADD: 369 case Token::Value::ADD:
360 return lhs + rhs; 370 return lhs + rhs;
361 case Token::Value::SUB: 371 case Token::Value::SUB:
362 return lhs - rhs; 372 return lhs - rhs;
363 case Token::Value::MUL: 373 case Token::Value::MUL:
364 return lhs * rhs; 374 return lhs * rhs;
365 case Token::Value::DIV: 375 case Token::Value::DIV:
366 return lhs / rhs; 376 return lhs / rhs;
367 case Token::Value::MOD: 377 case Token::Value::MOD:
368 return std::fmod(lhs, rhs); 378 return std::fmod(lhs, rhs);
(...skipping 11 matching lines...) Expand all
380 for (size_t r = 0; r < arraysize(rhs_inputs); r++) { 390 for (size_t r = 0; r < arraysize(rhs_inputs); r++) {
381 for (size_t o = 0; o < arraysize(kArithmeticOperators); o++) { 391 for (size_t o = 0; o < arraysize(kArithmeticOperators); o++) {
382 HandleAndZoneScope handles; 392 HandleAndZoneScope handles;
383 i::Factory* factory = handles.main_isolate()->factory(); 393 i::Factory* factory = handles.main_isolate()->factory();
384 BytecodeArrayBuilder builder(handles.main_isolate(), 394 BytecodeArrayBuilder builder(handles.main_isolate(),
385 handles.main_zone()); 395 handles.main_zone());
386 builder.set_locals_count(1); 396 builder.set_locals_count(1);
387 builder.set_parameter_count(1); 397 builder.set_parameter_count(1);
388 Register reg(0); 398 Register reg(0);
389 int lhs = lhs_inputs[l]; 399 int lhs = lhs_inputs[l];
390 int rhs = rhs_inputs[l]; 400 int rhs = rhs_inputs[r];
391 builder.LoadLiteral(Smi::FromInt(lhs)) 401 builder.LoadLiteral(Smi::FromInt(lhs))
392 .StoreAccumulatorInRegister(reg) 402 .StoreAccumulatorInRegister(reg)
393 .LoadLiteral(Smi::FromInt(rhs)) 403 .LoadLiteral(Smi::FromInt(rhs))
394 .BinaryOperation(kArithmeticOperators[o], reg) 404 .BinaryOperation(kArithmeticOperators[o], reg)
395 .Return(); 405 .Return();
396 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); 406 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray();
397 407
398 InterpreterTester tester(handles.main_isolate(), bytecode_array); 408 InterpreterTester tester(handles.main_isolate(), bytecode_array);
399 auto callable = tester.GetCallable<>(); 409 auto callable = tester.GetCallable<>();
400 Handle<Object> return_value = callable().ToHandleChecked(); 410 Handle<Object> return_value = callable().ToHandleChecked();
(...skipping 14 matching lines...) Expand all
415 for (size_t r = 0; r < arraysize(rhs_inputs); r++) { 425 for (size_t r = 0; r < arraysize(rhs_inputs); r++) {
416 for (size_t o = 0; o < arraysize(kArithmeticOperators); o++) { 426 for (size_t o = 0; o < arraysize(kArithmeticOperators); o++) {
417 HandleAndZoneScope handles; 427 HandleAndZoneScope handles;
418 i::Factory* factory = handles.main_isolate()->factory(); 428 i::Factory* factory = handles.main_isolate()->factory();
419 BytecodeArrayBuilder builder(handles.main_isolate(), 429 BytecodeArrayBuilder builder(handles.main_isolate(),
420 handles.main_zone()); 430 handles.main_zone());
421 builder.set_locals_count(1); 431 builder.set_locals_count(1);
422 builder.set_parameter_count(1); 432 builder.set_parameter_count(1);
423 Register reg(0); 433 Register reg(0);
424 double lhs = lhs_inputs[l]; 434 double lhs = lhs_inputs[l];
425 double rhs = rhs_inputs[l]; 435 double rhs = rhs_inputs[r];
426 builder.LoadLiteral(factory->NewNumber(lhs)) 436 builder.LoadLiteral(factory->NewNumber(lhs))
427 .StoreAccumulatorInRegister(reg) 437 .StoreAccumulatorInRegister(reg)
428 .LoadLiteral(factory->NewNumber(rhs)) 438 .LoadLiteral(factory->NewNumber(rhs))
429 .BinaryOperation(kArithmeticOperators[o], reg) 439 .BinaryOperation(kArithmeticOperators[o], reg)
430 .Return(); 440 .Return();
431 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); 441 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray();
432 442
433 InterpreterTester tester(handles.main_isolate(), bytecode_array); 443 InterpreterTester tester(handles.main_isolate(), bytecode_array);
434 auto callable = tester.GetCallable<>(); 444 auto callable = tester.GetCallable<>();
435 Handle<Object> return_value = callable().ToHandleChecked(); 445 Handle<Object> return_value = callable().ToHandleChecked();
(...skipping 868 matching lines...) Expand 10 before | Expand all | Expand 10 after
1304 .CallRuntime(Runtime::kAdd, Register(0), 2) 1314 .CallRuntime(Runtime::kAdd, Register(0), 2)
1305 .Return(); 1315 .Return();
1306 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); 1316 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray();
1307 1317
1308 InterpreterTester tester(handles.main_isolate(), bytecode_array); 1318 InterpreterTester tester(handles.main_isolate(), bytecode_array);
1309 auto callable = tester.GetCallable<>(); 1319 auto callable = tester.GetCallable<>();
1310 1320
1311 Handle<Object> return_val = callable().ToHandleChecked(); 1321 Handle<Object> return_val = callable().ToHandleChecked();
1312 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(55)); 1322 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(55));
1313 } 1323 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698