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

Side by Side Diff: src/wasm/asm-wasm-builder.cc

Issue 1968943002: [wasm] Introduce custom asm.js bytecodes for loads and stores. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@wasm_asmjs_convert
Patch Set: Created 4 years, 7 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 // Required to get M_E etc. in MSVC. 7 // Required to get M_E etc. in MSVC.
8 #if defined(_WIN32) 8 #if defined(_WIN32)
9 #define _USE_MATH_DEFINES 9 #define _USE_MATH_DEFINES
10 #endif 10 #endif
(...skipping 719 matching lines...) Expand 10 before | Expand all | Expand 10 after
730 if (target_var != nullptr && effective_value_var != nullptr && 730 if (target_var != nullptr && effective_value_var != nullptr &&
731 target_var->var() == effective_value_var->var()) { 731 target_var->var() == effective_value_var->var()) {
732 *is_nop = true; 732 *is_nop = true;
733 return; 733 return;
734 } 734 }
735 } 735 }
736 } 736 }
737 RECURSE(Visit(value)); 737 RECURSE(Visit(value));
738 } 738 }
739 739
740 void EmitAssignment(Assignment* expr, MachineType mtype) { 740 void EmitAssignment(Assignment* expr, MachineType type) {
741 // Match the left hand side of the assignment. 741 // Match the left hand side of the assignment.
742 VariableProxy* target_var = expr->target()->AsVariableProxy(); 742 VariableProxy* target_var = expr->target()->AsVariableProxy();
743 if (target_var != nullptr) { 743 if (target_var != nullptr) {
744 // Left hand side is a local or a global variable. 744 // Left hand side is a local or a global variable.
745 Variable* var = target_var->var(); 745 Variable* var = target_var->var();
746 LocalType var_type = TypeOf(expr); 746 LocalType var_type = TypeOf(expr);
747 DCHECK_NE(kAstStmt, var_type); 747 DCHECK_NE(kAstStmt, var_type);
748 if (var->IsContextSlot()) { 748 if (var->IsContextSlot()) {
749 current_function_builder_->EmitWithVarInt( 749 current_function_builder_->EmitWithVarInt(
750 kExprStoreGlobal, LookupOrInsertGlobal(var, var_type)); 750 kExprStoreGlobal, LookupOrInsertGlobal(var, var_type));
751 } else { 751 } else {
752 current_function_builder_->EmitSetLocal( 752 current_function_builder_->EmitSetLocal(
753 LookupOrInsertLocal(var, var_type)); 753 LookupOrInsertLocal(var, var_type));
754 } 754 }
755 } 755 }
756 756
757 Property* target_prop = expr->target()->AsProperty(); 757 Property* target_prop = expr->target()->AsProperty();
758 if (target_prop != nullptr) { 758 if (target_prop != nullptr) {
759 // Left hand side is a property access, i.e. the asm.js heap. 759 // Left hand side is a property access, i.e. the asm.js heap.
760 if (TypeOf(expr->value()) == kAstF64 && expr->target()->IsProperty() && 760 if (TypeOf(expr->value()) == kAstF64 && expr->target()->IsProperty() &&
761 expr->target()->AsProperty()->obj()->bounds().lower->Is( 761 expr->target()->AsProperty()->obj()->bounds().lower->Is(
762 cache_.kFloat32Array)) { 762 cache_.kFloat32Array)) {
763 current_function_builder_->Emit(kExprF32ConvertF64); 763 current_function_builder_->Emit(kExprF32ConvertF64);
764 } 764 }
765 current_function_builder_->EmitWithU8U8( 765 WasmOpcode opcode;
766 WasmOpcodes::LoadStoreOpcodeOf(mtype, true), 0, 0); 766 if (type == MachineType::Int8()) {
767 opcode = kExprI32AsmjsStoreMem8;
768 } else if (type == MachineType::Uint8()) {
769 opcode = kExprI32AsmjsStoreMem8;
770 } else if (type == MachineType::Int16()) {
771 opcode = kExprI32AsmjsStoreMem16;
772 } else if (type == MachineType::Uint16()) {
773 opcode = kExprI32AsmjsStoreMem16;
774 } else if (type == MachineType::Int32()) {
775 opcode = kExprI32AsmjsStoreMem;
776 } else if (type == MachineType::Uint32()) {
777 opcode = kExprI32AsmjsStoreMem;
778 } else if (type == MachineType::Float32()) {
779 opcode = kExprF32AsmjsStoreMem;
780 } else if (type == MachineType::Float64()) {
781 opcode = kExprF64AsmjsStoreMem;
782 } else {
783 UNREACHABLE();
784 }
785 current_function_builder_->Emit(opcode);
767 } 786 }
768 787
769 if (target_var == nullptr && target_prop == nullptr) { 788 if (target_var == nullptr && target_prop == nullptr) {
770 UNREACHABLE(); // invalid assignment. 789 UNREACHABLE(); // invalid assignment.
771 } 790 }
772 } 791 }
773 792
774 void VisitAssignment(Assignment* expr) { 793 void VisitAssignment(Assignment* expr) {
775 bool as_init = false; 794 bool as_init = false;
776 if (scope_ == kModuleScope) { 795 if (scope_ == kModuleScope) {
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
934 byte mask = static_cast<byte>(~(size - 1)); 953 byte mask = static_cast<byte>(~(size - 1));
935 RECURSE(Visit(binop->left())); 954 RECURSE(Visit(binop->left()));
936 current_function_builder_->EmitWithU8(kExprI8Const, mask); 955 current_function_builder_->EmitWithU8(kExprI8Const, mask);
937 current_function_builder_->Emit(kExprI32And); 956 current_function_builder_->Emit(kExprI32And);
938 return; 957 return;
939 } 958 }
940 UNREACHABLE(); 959 UNREACHABLE();
941 } 960 }
942 961
943 void VisitProperty(Property* expr) { 962 void VisitProperty(Property* expr) {
944 MachineType mtype; 963 MachineType type;
945 VisitPropertyAndEmitIndex(expr, &mtype); 964 VisitPropertyAndEmitIndex(expr, &type);
946 current_function_builder_->EmitWithU8U8( 965 WasmOpcode opcode;
947 WasmOpcodes::LoadStoreOpcodeOf(mtype, false), 0, 0); 966 if (type == MachineType::Int8()) {
967 opcode = kExprI32AsmjsLoadMem8S;
968 } else if (type == MachineType::Uint8()) {
969 opcode = kExprI32AsmjsLoadMem8U;
970 } else if (type == MachineType::Int16()) {
971 opcode = kExprI32AsmjsLoadMem16S;
972 } else if (type == MachineType::Uint16()) {
973 opcode = kExprI32AsmjsLoadMem16U;
974 } else if (type == MachineType::Int32()) {
975 opcode = kExprI32AsmjsLoadMem;
976 } else if (type == MachineType::Uint32()) {
977 opcode = kExprI32AsmjsLoadMem;
978 } else if (type == MachineType::Float32()) {
979 opcode = kExprF32AsmjsLoadMem;
980 } else if (type == MachineType::Float64()) {
981 opcode = kExprF64AsmjsLoadMem;
982 } else {
983 UNREACHABLE();
984 }
985
986 current_function_builder_->Emit(opcode);
948 } 987 }
949 988
950 bool VisitStdlibFunction(Call* call, VariableProxy* expr) { 989 bool VisitStdlibFunction(Call* call, VariableProxy* expr) {
951 Variable* var = expr->var(); 990 Variable* var = expr->var();
952 AsmTyper::StandardMember standard_object = 991 AsmTyper::StandardMember standard_object =
953 typer_->VariableAsStandardMember(var); 992 typer_->VariableAsStandardMember(var);
954 ZoneList<Expression*>* args = call->arguments(); 993 ZoneList<Expression*>* args = call->arguments();
955 LocalType call_type = TypeOf(call); 994 LocalType call_type = TypeOf(call);
956 995
957 switch (standard_object) { 996 switch (standard_object) {
(...skipping 746 matching lines...) Expand 10 before | Expand all | Expand 10 after
1704 // that zone in constructor may be thrown away once wasm module is written. 1743 // that zone in constructor may be thrown away once wasm module is written.
1705 WasmModuleIndex* AsmWasmBuilder::Run() { 1744 WasmModuleIndex* AsmWasmBuilder::Run() {
1706 AsmWasmBuilderImpl impl(isolate_, zone_, literal_, foreign_, typer_); 1745 AsmWasmBuilderImpl impl(isolate_, zone_, literal_, foreign_, typer_);
1707 impl.Compile(); 1746 impl.Compile();
1708 WasmModuleWriter* writer = impl.builder_->Build(zone_); 1747 WasmModuleWriter* writer = impl.builder_->Build(zone_);
1709 return writer->WriteTo(zone_); 1748 return writer->WriteTo(zone_);
1710 } 1749 }
1711 } // namespace wasm 1750 } // namespace wasm
1712 } // namespace internal 1751 } // namespace internal
1713 } // namespace v8 1752 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698