| OLD | NEW |
| 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 1044 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1055 Handle<Name> name = | 1055 Handle<Name> name = |
| 1056 Object::ToName(isolate_, key_literal->value()).ToHandleChecked(); | 1056 Object::ToName(isolate_, key_literal->value()).ToHandleChecked(); |
| 1057 ValueType type = is_float ? kWasmF64 : kWasmI32; | 1057 ValueType type = is_float ? kWasmF64 : kWasmI32; |
| 1058 foreign_variables_.push_back({name, var, type}); | 1058 foreign_variables_.push_back({name, var, type}); |
| 1059 } | 1059 } |
| 1060 } | 1060 } |
| 1061 | 1061 |
| 1062 void VisitPropertyAndEmitIndex(Property* expr, AsmType** atype) { | 1062 void VisitPropertyAndEmitIndex(Property* expr, AsmType** atype) { |
| 1063 Expression* obj = expr->obj(); | 1063 Expression* obj = expr->obj(); |
| 1064 *atype = typer_->TypeOf(obj); | 1064 *atype = typer_->TypeOf(obj); |
| 1065 int size = (*atype)->ElementSizeInBytes(); | 1065 int32_t size = (*atype)->ElementSizeInBytes(); |
| 1066 if (size == 1) { | 1066 if (size == 1) { |
| 1067 // Allow more general expression in byte arrays than the spec | 1067 // Allow more general expression in byte arrays than the spec |
| 1068 // strictly permits. | 1068 // strictly permits. |
| 1069 // Early versions of Emscripten emit HEAP8[HEAP32[..]|0] in | 1069 // Early versions of Emscripten emit HEAP8[HEAP32[..]|0] in |
| 1070 // places that strictly should be HEAP8[HEAP32[..]>>0]. | 1070 // places that strictly should be HEAP8[HEAP32[..]>>0]. |
| 1071 RECURSE(Visit(expr->key())); | 1071 RECURSE(Visit(expr->key())); |
| 1072 return; | 1072 return; |
| 1073 } | 1073 } |
| 1074 | 1074 |
| 1075 Literal* value = expr->key()->AsLiteral(); | 1075 Literal* value = expr->key()->AsLiteral(); |
| 1076 if (value) { | 1076 if (value) { |
| 1077 DCHECK(value->raw_value()->IsNumber()); | 1077 DCHECK(value->raw_value()->IsNumber()); |
| 1078 DCHECK_EQ(kWasmI32, TypeOf(value)); | 1078 DCHECK_EQ(kWasmI32, TypeOf(value)); |
| 1079 int32_t val = static_cast<int32_t>(value->raw_value()->AsNumber()); | 1079 int32_t val = static_cast<int32_t>(value->raw_value()->AsNumber()); |
| 1080 // TODO(titzer): handle overflow here. | 1080 // TODO(titzer): handle overflow here. |
| 1081 current_function_builder_->EmitI32Const(val * size); | 1081 current_function_builder_->EmitI32Const(val * size); |
| 1082 return; | 1082 return; |
| 1083 } | 1083 } |
| 1084 BinaryOperation* binop = expr->key()->AsBinaryOperation(); | 1084 BinaryOperation* binop = expr->key()->AsBinaryOperation(); |
| 1085 if (binop) { | 1085 if (binop) { |
| 1086 DCHECK_EQ(Token::SAR, binop->op()); | 1086 DCHECK_EQ(Token::SAR, binop->op()); |
| 1087 DCHECK(binop->right()->AsLiteral()->raw_value()->IsNumber()); | 1087 DCHECK(binop->right()->AsLiteral()->raw_value()->IsNumber()); |
| 1088 DCHECK(kWasmI32 == TypeOf(binop->right()->AsLiteral())); | 1088 DCHECK(kWasmI32 == TypeOf(binop->right()->AsLiteral())); |
| 1089 DCHECK_EQ(size, | 1089 DCHECK_EQ(size, |
| 1090 1 << static_cast<int>( | 1090 1 << static_cast<int>( |
| 1091 binop->right()->AsLiteral()->raw_value()->AsNumber())); | 1091 binop->right()->AsLiteral()->raw_value()->AsNumber())); |
| 1092 // Mask bottom bits to match asm.js behavior. | 1092 // Mask bottom bits to match asm.js behavior. |
| 1093 byte mask = static_cast<byte>(~(size - 1)); | |
| 1094 RECURSE(Visit(binop->left())); | 1093 RECURSE(Visit(binop->left())); |
| 1095 current_function_builder_->EmitWithU8(kExprI8Const, mask); | 1094 current_function_builder_->EmitI32Const(~(size - 1)); |
| 1096 current_function_builder_->Emit(kExprI32And); | 1095 current_function_builder_->Emit(kExprI32And); |
| 1097 return; | 1096 return; |
| 1098 } | 1097 } |
| 1099 UNREACHABLE(); | 1098 UNREACHABLE(); |
| 1100 } | 1099 } |
| 1101 | 1100 |
| 1102 void VisitProperty(Property* expr) { | 1101 void VisitProperty(Property* expr) { |
| 1103 AsmType* type = AsmType::None(); | 1102 AsmType* type = AsmType::None(); |
| 1104 VisitPropertyAndEmitIndex(expr, &type); | 1103 VisitPropertyAndEmitIndex(expr, &type); |
| 1105 WasmOpcode opcode; | 1104 WasmOpcode opcode; |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1224 current_function_builder_->Emit(kExprI32Clz); | 1223 current_function_builder_->Emit(kExprI32Clz); |
| 1225 break; | 1224 break; |
| 1226 } | 1225 } |
| 1227 case AsmTyper::kMathAbs: { | 1226 case AsmTyper::kMathAbs: { |
| 1228 if (call_type == kWasmI32) { | 1227 if (call_type == kWasmI32) { |
| 1229 WasmTemporary tmp(current_function_builder_, kWasmI32); | 1228 WasmTemporary tmp(current_function_builder_, kWasmI32); |
| 1230 | 1229 |
| 1231 // if set_local(tmp, x) < 0 | 1230 // if set_local(tmp, x) < 0 |
| 1232 Visit(call->arguments()->at(0)); | 1231 Visit(call->arguments()->at(0)); |
| 1233 current_function_builder_->EmitTeeLocal(tmp.index()); | 1232 current_function_builder_->EmitTeeLocal(tmp.index()); |
| 1234 byte code[] = {WASM_I8(0)}; | 1233 byte code[] = {WASM_ZERO}; |
| 1235 current_function_builder_->EmitCode(code, sizeof(code)); | 1234 current_function_builder_->EmitCode(code, sizeof(code)); |
| 1236 current_function_builder_->Emit(kExprI32LtS); | 1235 current_function_builder_->Emit(kExprI32LtS); |
| 1237 current_function_builder_->EmitWithU8(kExprIf, kLocalI32); | 1236 current_function_builder_->EmitWithU8(kExprIf, kLocalI32); |
| 1238 | 1237 |
| 1239 // then (0 - tmp) | 1238 // then (0 - tmp) |
| 1240 current_function_builder_->EmitCode(code, sizeof(code)); | 1239 current_function_builder_->EmitCode(code, sizeof(code)); |
| 1241 current_function_builder_->EmitGetLocal(tmp.index()); | 1240 current_function_builder_->EmitGetLocal(tmp.index()); |
| 1242 current_function_builder_->Emit(kExprI32Sub); | 1241 current_function_builder_->Emit(kExprI32Sub); |
| 1243 | 1242 |
| 1244 // else tmp | 1243 // else tmp |
| (...skipping 734 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1979 impl.builder_->WriteAsmJsOffsetTable(*asm_offsets_buffer); | 1978 impl.builder_->WriteAsmJsOffsetTable(*asm_offsets_buffer); |
| 1980 return {module_buffer, asm_offsets_buffer, success}; | 1979 return {module_buffer, asm_offsets_buffer, success}; |
| 1981 } | 1980 } |
| 1982 | 1981 |
| 1983 const char* AsmWasmBuilder::foreign_init_name = "__foreign_init__"; | 1982 const char* AsmWasmBuilder::foreign_init_name = "__foreign_init__"; |
| 1984 const char* AsmWasmBuilder::single_function_name = "__single_function__"; | 1983 const char* AsmWasmBuilder::single_function_name = "__single_function__"; |
| 1985 | 1984 |
| 1986 } // namespace wasm | 1985 } // namespace wasm |
| 1987 } // namespace internal | 1986 } // namespace internal |
| 1988 } // namespace v8 | 1987 } // namespace v8 |
| OLD | NEW |