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

Side by Side Diff: src/compiler/wasm-compiler.cc

Issue 1638283004: [wasm] Backoff implementation for F64Trunc using std::trunc. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@init-root-register
Patch Set: Use math.h trunc instead of std::trunc. Created 4 years, 10 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/compiler/wasm-compiler.h" 5 #include "src/compiler/wasm-compiler.h"
6 6
7 #include "src/isolate-inl.h" 7 #include "src/isolate-inl.h"
8 8
9 #include "src/base/platform/platform.h" 9 #include "src/base/platform/platform.h"
10 10
(...skipping 777 matching lines...) Expand 10 before | Expand all | Expand 10 after
788 case wasm::kExprF64Ceil: { 788 case wasm::kExprF64Ceil: {
789 if (m->Float64RoundUp().IsSupported()) { 789 if (m->Float64RoundUp().IsSupported()) {
790 op = m->Float64RoundUp().op(); 790 op = m->Float64RoundUp().op();
791 break; 791 break;
792 } else { 792 } else {
793 op = UnsupportedOpcode(opcode); 793 op = UnsupportedOpcode(opcode);
794 break; 794 break;
795 } 795 }
796 } 796 }
797 case wasm::kExprF64Trunc: { 797 case wasm::kExprF64Trunc: {
798 if (m->Float64RoundTruncate().IsSupported()) { 798 if (!m->Float64RoundTruncate().IsSupported()) return BuildF64Trunc(input);
799 op = m->Float64RoundTruncate().op(); 799 op = m->Float64RoundTruncate().op();
800 break; 800 break;
801 } else {
802 op = UnsupportedOpcode(opcode);
803 break;
804 }
805 } 801 }
806 case wasm::kExprF64NearestInt: { 802 case wasm::kExprF64NearestInt: {
807 if (m->Float64RoundTiesEven().IsSupported()) { 803 if (m->Float64RoundTiesEven().IsSupported()) {
808 op = m->Float64RoundTiesEven().op(); 804 op = m->Float64RoundTiesEven().op();
809 break; 805 break;
810 } else { 806 } else {
811 op = UnsupportedOpcode(opcode); 807 op = UnsupportedOpcode(opcode);
812 break; 808 break;
813 } 809 }
814 } 810 }
(...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after
1429 Diamond exponent_geq_23(graph(), jsgraph()->common(), 1425 Diamond exponent_geq_23(graph(), jsgraph()->common(),
1430 Binop(wasm::kExprI32GeU, exponent, 1426 Binop(wasm::kExprI32GeU, exponent,
1431 jsgraph()->Int32Constant((23 + 127) << 23))); 1427 jsgraph()->Int32Constant((23 + 127) << 23)));
1432 1428
1433 Node* result = exponent_geq_23.Phi(wasm::kAstI32, result_exponent_geq_23, 1429 Node* result = exponent_geq_23.Phi(wasm::kAstI32, result_exponent_geq_23,
1434 result_within_range); 1430 result_within_range);
1435 1431
1436 return Unop(wasm::kExprF32ReinterpretI32, result); 1432 return Unop(wasm::kExprF32ReinterpretI32, result);
1437 } 1433 }
1438 1434
1435 Node* WasmGraphBuilder::BuildF64Trunc(Node* input) {
1436 // We do truncation by calling a C function which calculates the truncation
1437 // for us. The input is passed to the C function as a double* to avoid double
1438 // parameters. For this we reserve a slot on the stack, store the parameter in
1439 // that slot, pass a pointer to the slot to the C function, and after calling
1440 // the C function we collect the return value from the stack slot.
1441
1442 Node* stack_slot_param = graph()->NewNode(
1443 jsgraph()->machine()->StackSlot(MachineRepresentation::kFloat64));
1444
1445 const Operator* store_op = jsgraph()->machine()->Store(
1446 StoreRepresentation(MachineRepresentation::kFloat64, kNoWriteBarrier));
1447 *effect_ =
1448 graph()->NewNode(store_op, stack_slot_param, jsgraph()->Int32Constant(0),
1449 input, *effect_, *control_);
1450
1451 Signature<MachineType>::Builder sig_builder(jsgraph()->zone(), 0, 1);
1452 sig_builder.AddParam(MachineType::Pointer());
1453 Node* function = graph()->NewNode(jsgraph()->common()->ExternalConstant(
1454 ExternalReference::trunc64_wrapper_function(jsgraph()->isolate())));
1455
1456 Node* args[] = {function, stack_slot_param};
1457
1458 BuildCCall(sig_builder.Build(), args);
1459
1460 const Operator* load_op = jsgraph()->machine()->Load(MachineType::Float64());
1461
1462 Node* load =
1463 graph()->NewNode(load_op, stack_slot_param, jsgraph()->Int32Constant(0),
1464 *effect_, *control_);
1465 *effect_ = load;
1466 return load;
1467 }
1468
1469 Node* WasmGraphBuilder::BuildCCall(MachineSignature* sig, Node** args) {
1470 const size_t params = sig->parameter_count();
1471 const size_t extra = 2; // effect and control inputs.
1472 const size_t count = 1 + params + extra;
1473
1474 // Reallocate the buffer to make space for extra inputs.
1475 args = Realloc(args, count);
1476
1477 // Add effect and control inputs.
1478 args[params + 1] = *effect_;
1479 args[params + 2] = *control_;
1480
1481 CallDescriptor* desc =
1482 Linkage::GetSimplifiedCDescriptor(jsgraph()->zone(), sig);
1483
1484 const Operator* op = jsgraph()->common()->Call(desc);
1485 Node* call = graph()->NewNode(op, static_cast<int>(count), args);
1486 *effect_ = call;
1487 return call;
1488 }
1439 1489
1440 Node* WasmGraphBuilder::BuildWasmCall(wasm::FunctionSig* sig, Node** args) { 1490 Node* WasmGraphBuilder::BuildWasmCall(wasm::FunctionSig* sig, Node** args) {
1441 const size_t params = sig->parameter_count(); 1491 const size_t params = sig->parameter_count();
1442 const size_t extra = 2; // effect and control inputs. 1492 const size_t extra = 2; // effect and control inputs.
1443 const size_t count = 1 + params + extra; 1493 const size_t count = 1 + params + extra;
1444 1494
1445 // Reallocate the buffer to make space for extra inputs. 1495 // Reallocate the buffer to make space for extra inputs.
1446 args = Realloc(args, count); 1496 args = Realloc(args, count);
1447 1497
1448 // Add effect and control inputs. 1498 // Add effect and control inputs.
(...skipping 666 matching lines...) Expand 10 before | Expand all | Expand 10 after
2115 module_env->module->GetName(function.name_offset)); 2165 module_env->module->GetName(function.name_offset));
2116 } 2166 }
2117 2167
2118 return code; 2168 return code;
2119 } 2169 }
2120 2170
2121 2171
2122 } // namespace compiler 2172 } // namespace compiler
2123 } // namespace internal 2173 } // namespace internal
2124 } // namespace v8 2174 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698