Skip to content

Commit 0d72db1

Browse files
mkustermannCommit Queue
authored andcommitted
[dart2wasm] Use f64.sqrt instead of Math.sqrt import
Issue https://g-issues.chromium.org/issues/383373316 Change-Id: I319df732ecfce5811fc46934919962c94cdb12b0 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/400281 Commit-Queue: Martin Kustermann <[email protected]> Reviewed-by: Slava Egorov <[email protected]>
1 parent 684018e commit 0d72db1

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

pkg/dart2wasm/lib/intrinsics.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,10 @@ class Intrinsifier {
420420
codeGen.translateExpression(receiver, w.NumType.f64);
421421
b.i64_trunc_sat_f64_s();
422422
return w.NumType.i64;
423+
case "sqrt":
424+
codeGen.translateExpression(receiver, w.NumType.f64);
425+
b.f64_sqrt();
426+
return w.NumType.f64;
423427
case "copysign":
424428
codeGen.translateExpression(receiver, w.NumType.f64);
425429
codeGen.translateExpression(

sdk/lib/_internal/wasm/lib/math_patch.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import "dart:_internal" show mix64, patch;
66
import "dart:_js_types" show JSUint8ArrayImpl;
77
import "dart:js_interop";
8+
import "dart:_wasm";
89

910
/// There are no parts of this patch library.
1011
@@ -113,7 +114,7 @@ double asin(num x) => _asin(x.toDouble());
113114
@patch
114115
double atan(num x) => _atan(x.toDouble());
115116
@patch
116-
double sqrt(num x) => _sqrt(x.toDouble());
117+
double sqrt(num x) => x.toDouble().sqrt();
117118
@patch
118119
double exp(num x) => _exp(x.toDouble());
119120
@patch
@@ -133,8 +134,6 @@ external double _acos(double x);
133134
external double _asin(double x);
134135
@pragma("wasm:import", "Math.atan")
135136
external double _atan(double x);
136-
@pragma("wasm:import", "Math.sqrt")
137-
external double _sqrt(double x);
138137
@pragma("wasm:import", "Math.exp")
139138
external double _exp(double x);
140139
@pragma("wasm:import", "Math.log")

sdk/lib/_wasm/wasm_types.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,9 @@ class WasmF64 extends _WasmBase {
221221
/// Wasm `i64.trunc_sat_f64_s` instruction.
222222
external WasmI64 truncSatS();
223223

224+
/// Wasm `f64.sqrt` instruction.
225+
external WasmF64 sqrt();
226+
224227
/// Wasm `f64.copysign` instruction.
225228
external WasmF64 copysign(WasmF64 other);
226229
}
@@ -437,6 +440,10 @@ extension DoubleWasmInstructions on double {
437440
@pragma("wasm:prefer-inline")
438441
double copysign(double other) =>
439442
this.toWasmF64().copysign(other.toWasmF64()).toDouble();
443+
444+
/// Wasm `f64.sqrt` instruction.
445+
@pragma("wasm:prefer-inline")
446+
double sqrt() => this.toWasmF64().sqrt().toDouble();
440447
}
441448

442449
extension WasmExternRefToJSAny on WasmExternRef {

0 commit comments

Comments
 (0)