| Index: src/wasm/asm-wasm-builder.cc
|
| diff --git a/src/wasm/asm-wasm-builder.cc b/src/wasm/asm-wasm-builder.cc
|
| index 91c3a8ee16ddb658e4431b47a120137c080f30a0..0bca2cfdaa50c562827c2d1d20201f0ed2d265ae 100644
|
| --- a/src/wasm/asm-wasm-builder.cc
|
| +++ b/src/wasm/asm-wasm-builder.cc
|
| @@ -846,36 +846,44 @@ class AsmWasmBuilderImpl : public AstVisitor {
|
| return false;
|
| }
|
| case AsmTyper::kMathAcos: {
|
| - UNREACHABLE();
|
| - break; // TODO(bradnelson): Implement as external.
|
| + DCHECK_EQ(kAstF64, call_type);
|
| + current_function_builder_->Emit(kExprF64Acos);
|
| + break;
|
| }
|
| case AsmTyper::kMathAsin: {
|
| - UNREACHABLE();
|
| - break; // TODO(bradnelson): Implement as external.
|
| + DCHECK_EQ(kAstF64, call_type);
|
| + current_function_builder_->Emit(kExprF64Asin);
|
| + break;
|
| }
|
| case AsmTyper::kMathAtan: {
|
| - UNREACHABLE();
|
| - break; // TODO(bradnelson): Implement as external.
|
| + DCHECK_EQ(kAstF64, call_type);
|
| + current_function_builder_->Emit(kExprF64Atan);
|
| + break;
|
| }
|
| case AsmTyper::kMathCos: {
|
| - UNREACHABLE();
|
| - break; // TODO(bradnelson): Implement as external.
|
| + DCHECK_EQ(kAstF64, call_type);
|
| + current_function_builder_->Emit(kExprF64Cos);
|
| + break;
|
| }
|
| case AsmTyper::kMathSin: {
|
| - UNREACHABLE();
|
| - break; // TODO(bradnelson): Implement as external.
|
| + DCHECK_EQ(kAstF64, call_type);
|
| + current_function_builder_->Emit(kExprF64Sin);
|
| + break;
|
| }
|
| case AsmTyper::kMathTan: {
|
| - UNREACHABLE();
|
| - break; // TODO(bradnelson): Implement as external.
|
| + DCHECK_EQ(kAstF64, call_type);
|
| + current_function_builder_->Emit(kExprF64Tan);
|
| + break;
|
| }
|
| case AsmTyper::kMathExp: {
|
| - UNREACHABLE();
|
| - break; // TODO(bradnelson): Implement as external.
|
| + DCHECK_EQ(kAstF64, call_type);
|
| + current_function_builder_->Emit(kExprF64Exp);
|
| + break;
|
| }
|
| case AsmTyper::kMathLog: {
|
| - UNREACHABLE();
|
| - break; // TODO(bradnelson): Implement as external.
|
| + DCHECK_EQ(kAstF64, call_type);
|
| + current_function_builder_->Emit(kExprF64Log);
|
| + break;
|
| }
|
| case AsmTyper::kMathCeil: {
|
| if (call_type == kAstF32) {
|
| @@ -908,8 +916,17 @@ class AsmWasmBuilderImpl : public AstVisitor {
|
| break;
|
| }
|
| case AsmTyper::kMathAbs: {
|
| - // TODO(bradnelson): Handle signed.
|
| - if (call_type == kAstF32) {
|
| + // TODO(bradnelson): Should this be cast to float?
|
| + if (call_type == kAstI32) {
|
| + current_function_builder_->Emit(kExprIfElse);
|
| + current_function_builder_->Emit(kExprI32LtS);
|
| + Visit(args->at(0));
|
| + byte code[] = {WASM_I8(0)};
|
| + current_function_builder_->EmitCode(code, sizeof(code));
|
| + current_function_builder_->Emit(kExprI32Sub);
|
| + current_function_builder_->EmitCode(code, sizeof(code));
|
| + Visit(args->at(0));
|
| + } else if (call_type == kAstF32) {
|
| current_function_builder_->Emit(kExprF32Abs);
|
| } else if (call_type == kAstF64) {
|
| current_function_builder_->Emit(kExprF64Abs);
|
| @@ -919,9 +936,13 @@ class AsmWasmBuilderImpl : public AstVisitor {
|
| break;
|
| }
|
| case AsmTyper::kMathMin: {
|
| - // TODO(bradnelson): Handle signed.
|
| // TODO(bradnelson): Change wasm to match Math.min in asm.js mode.
|
| - if (call_type == kAstF32) {
|
| + if (call_type == kAstI32) {
|
| + current_function_builder_->Emit(kExprIfElse);
|
| + current_function_builder_->Emit(kExprI32LeS);
|
| + Visit(args->at(0));
|
| + Visit(args->at(1));
|
| + } else if (call_type == kAstF32) {
|
| current_function_builder_->Emit(kExprF32Min);
|
| } else if (call_type == kAstF64) {
|
| current_function_builder_->Emit(kExprF64Min);
|
| @@ -931,9 +952,13 @@ class AsmWasmBuilderImpl : public AstVisitor {
|
| break;
|
| }
|
| case AsmTyper::kMathMax: {
|
| - // TODO(bradnelson): Handle signed.
|
| // TODO(bradnelson): Change wasm to match Math.max in asm.js mode.
|
| - if (call_type == kAstF32) {
|
| + if (call_type == kAstI32) {
|
| + current_function_builder_->Emit(kExprIfElse);
|
| + current_function_builder_->Emit(kExprI32GtS);
|
| + Visit(args->at(0));
|
| + Visit(args->at(1));
|
| + } else if (call_type == kAstF32) {
|
| current_function_builder_->Emit(kExprF32Max);
|
| } else if (call_type == kAstF64) {
|
| current_function_builder_->Emit(kExprF64Max);
|
| @@ -943,12 +968,14 @@ class AsmWasmBuilderImpl : public AstVisitor {
|
| break;
|
| }
|
| case AsmTyper::kMathAtan2: {
|
| - UNREACHABLE();
|
| - break; // TODO(bradnelson): Implement as external.
|
| + DCHECK_EQ(kAstF64, call_type);
|
| + current_function_builder_->Emit(kExprF64Atan2);
|
| + break;
|
| }
|
| case AsmTyper::kMathPow: {
|
| - UNREACHABLE();
|
| - break; // TODO(bradnelson): Implement as external.
|
| + DCHECK_EQ(kAstF64, call_type);
|
| + current_function_builder_->Emit(kExprF64Pow);
|
| + break;
|
| }
|
| case AsmTyper::kMathImul: {
|
| current_function_builder_->Emit(kExprI32Mul);
|
| @@ -1243,7 +1270,7 @@ class AsmWasmBuilderImpl : public AstVisitor {
|
| } else if (type == kUint32) {
|
| current_function_builder_->Emit(kExprI32RemU);
|
| } else if (type == kFloat64) {
|
| - ModF64(expr);
|
| + current_function_builder_->Emit(kExprF64Mod);
|
| return;
|
| } else {
|
| UNREACHABLE();
|
| @@ -1262,32 +1289,6 @@ class AsmWasmBuilderImpl : public AstVisitor {
|
| }
|
| }
|
|
|
| - void ModF64(BinaryOperation* expr) {
|
| - current_function_builder_->EmitWithU8(kExprBlock, 3);
|
| - uint16_t index_0 = current_function_builder_->AddLocal(kAstF64);
|
| - uint16_t index_1 = current_function_builder_->AddLocal(kAstF64);
|
| - current_function_builder_->Emit(kExprSetLocal);
|
| - AddLeb128(index_0, true);
|
| - RECURSE(Visit(expr->left()));
|
| - current_function_builder_->Emit(kExprSetLocal);
|
| - AddLeb128(index_1, true);
|
| - RECURSE(Visit(expr->right()));
|
| - current_function_builder_->Emit(kExprF64Sub);
|
| - current_function_builder_->Emit(kExprGetLocal);
|
| - AddLeb128(index_0, true);
|
| - current_function_builder_->Emit(kExprF64Mul);
|
| - current_function_builder_->Emit(kExprGetLocal);
|
| - AddLeb128(index_1, true);
|
| - // Use trunc instead of two casts
|
| - current_function_builder_->Emit(kExprF64SConvertI32);
|
| - current_function_builder_->Emit(kExprI32SConvertF64);
|
| - current_function_builder_->Emit(kExprF64Div);
|
| - current_function_builder_->Emit(kExprGetLocal);
|
| - AddLeb128(index_0, true);
|
| - current_function_builder_->Emit(kExprGetLocal);
|
| - AddLeb128(index_1, true);
|
| - }
|
| -
|
| void AddLeb128(uint32_t index, bool is_local) {
|
| std::vector<uint8_t> index_vec = UnsignedLEB128From(index);
|
| if (is_local) {
|
|
|