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

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

Issue 2280063002: [asm.js] (Re)use temporaries in asm->wasm conversion. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: [asm.js] (Re)use temporaries in asm->wasm conversion. Created 4 years, 3 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
« no previous file with comments | « no previous file | src/wasm/encoder.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 1081 matching lines...) Expand 10 before | Expand all | Expand 10 after
1092 break; 1092 break;
1093 } 1093 }
1094 case AsmTyper::kMathClz32: { 1094 case AsmTyper::kMathClz32: {
1095 VisitCallArgs(call); 1095 VisitCallArgs(call);
1096 DCHECK(call_type == kAstI32); 1096 DCHECK(call_type == kAstI32);
1097 current_function_builder_->Emit(kExprI32Clz); 1097 current_function_builder_->Emit(kExprI32Clz);
1098 break; 1098 break;
1099 } 1099 }
1100 case AsmTyper::kMathAbs: { 1100 case AsmTyper::kMathAbs: {
1101 if (call_type == kAstI32) { 1101 if (call_type == kAstI32) {
1102 uint32_t tmp = current_function_builder_->AddLocal(kAstI32); 1102 WasmTemporary tmp(current_function_builder_, kAstI32);
1103 1103
1104 // if set_local(tmp, x) < 0 1104 // if set_local(tmp, x) < 0
1105 Visit(call->arguments()->at(0)); 1105 Visit(call->arguments()->at(0));
1106 current_function_builder_->EmitSetLocal(tmp); 1106 current_function_builder_->EmitSetLocal(tmp.index());
1107 byte code[] = {WASM_I8(0)}; 1107 byte code[] = {WASM_I8(0)};
1108 current_function_builder_->EmitCode(code, sizeof(code)); 1108 current_function_builder_->EmitCode(code, sizeof(code));
1109 current_function_builder_->Emit(kExprI32LtS); 1109 current_function_builder_->Emit(kExprI32LtS);
1110 current_function_builder_->Emit(kExprIf); 1110 current_function_builder_->Emit(kExprIf);
1111 1111
1112 // then (0 - tmp) 1112 // then (0 - tmp)
1113 current_function_builder_->EmitCode(code, sizeof(code)); 1113 current_function_builder_->EmitCode(code, sizeof(code));
1114 current_function_builder_->EmitGetLocal(tmp); 1114 current_function_builder_->EmitGetLocal(tmp.index());
1115 current_function_builder_->Emit(kExprI32Sub); 1115 current_function_builder_->Emit(kExprI32Sub);
1116 1116
1117 // else tmp 1117 // else tmp
1118 current_function_builder_->Emit(kExprElse); 1118 current_function_builder_->Emit(kExprElse);
1119 current_function_builder_->EmitGetLocal(tmp); 1119 current_function_builder_->EmitGetLocal(tmp.index());
1120 // end 1120 // end
1121 current_function_builder_->Emit(kExprEnd); 1121 current_function_builder_->Emit(kExprEnd);
1122 1122
1123 } else if (call_type == kAstF32) { 1123 } else if (call_type == kAstF32) {
1124 VisitCallArgs(call); 1124 VisitCallArgs(call);
1125 current_function_builder_->Emit(kExprF32Abs); 1125 current_function_builder_->Emit(kExprF32Abs);
1126 } else if (call_type == kAstF64) { 1126 } else if (call_type == kAstF64) {
1127 VisitCallArgs(call); 1127 VisitCallArgs(call);
1128 current_function_builder_->Emit(kExprF64Abs); 1128 current_function_builder_->Emit(kExprF64Abs);
1129 } else { 1129 } else {
1130 UNREACHABLE(); 1130 UNREACHABLE();
1131 } 1131 }
1132 break; 1132 break;
1133 } 1133 }
1134 case AsmTyper::kMathMin: { 1134 case AsmTyper::kMathMin: {
1135 // TODO(bradnelson): Change wasm to match Math.min in asm.js mode. 1135 // TODO(bradnelson): Change wasm to match Math.min in asm.js mode.
1136 if (call_type == kAstI32) { 1136 if (call_type == kAstI32) {
1137 uint32_t tmp_x = current_function_builder_->AddLocal(kAstI32); 1137 WasmTemporary tmp_x(current_function_builder_, kAstI32);
1138 uint32_t tmp_y = current_function_builder_->AddLocal(kAstI32); 1138 WasmTemporary tmp_y(current_function_builder_, kAstI32);
1139 1139
1140 // if set_local(tmp_x, x) < set_local(tmp_y, y) 1140 // if set_local(tmp_x, x) < set_local(tmp_y, y)
1141 Visit(call->arguments()->at(0)); 1141 Visit(call->arguments()->at(0));
1142 current_function_builder_->EmitSetLocal(tmp_x); 1142 current_function_builder_->EmitSetLocal(tmp_x.index());
1143 1143
1144 Visit(call->arguments()->at(1)); 1144 Visit(call->arguments()->at(1));
1145 current_function_builder_->EmitSetLocal(tmp_y); 1145 current_function_builder_->EmitSetLocal(tmp_y.index());
1146 1146
1147 current_function_builder_->Emit(kExprI32LeS); 1147 current_function_builder_->Emit(kExprI32LeS);
1148 current_function_builder_->Emit(kExprIf); 1148 current_function_builder_->Emit(kExprIf);
1149 1149
1150 // then tmp_x 1150 // then tmp_x
1151 current_function_builder_->EmitGetLocal(tmp_x); 1151 current_function_builder_->EmitGetLocal(tmp_x.index());
1152 1152
1153 // else tmp_y 1153 // else tmp_y
1154 current_function_builder_->Emit(kExprElse); 1154 current_function_builder_->Emit(kExprElse);
1155 current_function_builder_->EmitGetLocal(tmp_y); 1155 current_function_builder_->EmitGetLocal(tmp_y.index());
1156 current_function_builder_->Emit(kExprEnd); 1156 current_function_builder_->Emit(kExprEnd);
1157 1157
1158 } else if (call_type == kAstF32) { 1158 } else if (call_type == kAstF32) {
1159 VisitCallArgs(call); 1159 VisitCallArgs(call);
1160 current_function_builder_->Emit(kExprF32Min); 1160 current_function_builder_->Emit(kExprF32Min);
1161 } else if (call_type == kAstF64) { 1161 } else if (call_type == kAstF64) {
1162 VisitCallArgs(call); 1162 VisitCallArgs(call);
1163 current_function_builder_->Emit(kExprF64Min); 1163 current_function_builder_->Emit(kExprF64Min);
1164 } else { 1164 } else {
1165 UNREACHABLE(); 1165 UNREACHABLE();
1166 } 1166 }
1167 break; 1167 break;
1168 } 1168 }
1169 case AsmTyper::kMathMax: { 1169 case AsmTyper::kMathMax: {
1170 // TODO(bradnelson): Change wasm to match Math.max in asm.js mode. 1170 // TODO(bradnelson): Change wasm to match Math.max in asm.js mode.
1171 if (call_type == kAstI32) { 1171 if (call_type == kAstI32) {
1172 uint32_t tmp_x = current_function_builder_->AddLocal(kAstI32); 1172 WasmTemporary tmp_x(current_function_builder_, kAstI32);
1173 uint32_t tmp_y = current_function_builder_->AddLocal(kAstI32); 1173 WasmTemporary tmp_y(current_function_builder_, kAstI32);
1174 1174
1175 // if set_local(tmp_x, x) < set_local(tmp_y, y) 1175 // if set_local(tmp_x, x) < set_local(tmp_y, y)
1176 Visit(call->arguments()->at(0)); 1176 Visit(call->arguments()->at(0));
1177 1177
1178 current_function_builder_->EmitSetLocal(tmp_x); 1178 current_function_builder_->EmitSetLocal(tmp_x.index());
1179 1179
1180 Visit(call->arguments()->at(1)); 1180 Visit(call->arguments()->at(1));
1181 current_function_builder_->EmitSetLocal(tmp_y); 1181 current_function_builder_->EmitSetLocal(tmp_y.index());
1182 1182
1183 current_function_builder_->Emit(kExprI32LeS); 1183 current_function_builder_->Emit(kExprI32LeS);
1184 current_function_builder_->Emit(kExprIf); 1184 current_function_builder_->Emit(kExprIf);
1185 1185
1186 // then tmp_y 1186 // then tmp_y
1187 current_function_builder_->EmitGetLocal(tmp_y); 1187 current_function_builder_->EmitGetLocal(tmp_y.index());
1188 1188
1189 // else tmp_x 1189 // else tmp_x
1190 current_function_builder_->Emit(kExprElse); 1190 current_function_builder_->Emit(kExprElse);
1191 current_function_builder_->EmitGetLocal(tmp_x); 1191 current_function_builder_->EmitGetLocal(tmp_x.index());
1192 current_function_builder_->Emit(kExprEnd); 1192 current_function_builder_->Emit(kExprEnd);
1193 1193
1194 } else if (call_type == kAstF32) { 1194 } else if (call_type == kAstF32) {
1195 VisitCallArgs(call); 1195 VisitCallArgs(call);
1196 current_function_builder_->Emit(kExprF32Max); 1196 current_function_builder_->Emit(kExprF32Max);
1197 } else if (call_type == kAstF64) { 1197 } else if (call_type == kAstF64) {
1198 VisitCallArgs(call); 1198 VisitCallArgs(call);
1199 current_function_builder_->Emit(kExprF64Max); 1199 current_function_builder_->Emit(kExprF64Max);
1200 } else { 1200 } else {
1201 UNREACHABLE(); 1201 UNREACHABLE();
(...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after
1788 AsmWasmBuilderImpl impl(isolate_, zone_, literal_, typer_); 1788 AsmWasmBuilderImpl impl(isolate_, zone_, literal_, typer_);
1789 impl.Build(); 1789 impl.Build();
1790 *foreign_args = impl.GetForeignArgs(); 1790 *foreign_args = impl.GetForeignArgs();
1791 ZoneBuffer* buffer = new (zone_) ZoneBuffer(zone_); 1791 ZoneBuffer* buffer = new (zone_) ZoneBuffer(zone_);
1792 impl.builder_->WriteTo(*buffer); 1792 impl.builder_->WriteTo(*buffer);
1793 return buffer; 1793 return buffer;
1794 } 1794 }
1795 } // namespace wasm 1795 } // namespace wasm
1796 } // namespace internal 1796 } // namespace internal
1797 } // namespace v8 1797 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | src/wasm/encoder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698