Truly independent web browser
LibJS/JIT: Round doubles in Math functions without boxing them first
Andreas Klingef9371bde314
diff --git a/Libraries/LibJS/JIT/Rust/src/builder/intrinsics.rs b/Libraries/LibJS/JIT/Rust/src/builder/intrinsics.rsindex ce0d1a1ae4e..b4a1c8dc1e2 100644--- a/Libraries/LibJS/JIT/Rust/src/builder/intrinsics.rs+++ b/Libraries/LibJS/JIT/Rust/src/builder/intrinsics.rs@@ -83,6 +83,9 @@ impl GraphBuilder<'_> {}let result = if let Some(integer) = self.int32_value_of(argument) {self.build_int32_math_function(&mut slow_paths, op, integer)+ } else if let Some(double) = self.float64_value_of(argument) {+ let result = self.emit(Op::Float64Unary { op }, vec![double], Some(Repr::Float64));+ self.emit(Op::BoxFloat64, vec![result], Some(Repr::Tagged))} else {// NB: Int32 arguments, then doubles.let (int32, other) = self.branch_both_ways(BranchCondition::Int32Value, vec![argument]);@@ -171,6 +174,17 @@ impl GraphBuilder<'_> {}}+ /// The `Repr::Float64` value of `value`, if it is known to be a double:+ /// itself, or what it boxes.+ pub(super) fn float64_value_of(&self, value: NodeId) -> Option<NodeId> {+ let node = self.graph.node(value);+ match (node.repr, &node.op) {+ (Some(Repr::Float64), _) => Some(value),+ (_, Op::BoxFloat64) => Some(node.inputs[0]),+ _ => None,+ }+ }+/// The `Repr::Float64` of the `Repr::Int32` `integer`.pub(super) fn int32_to_float64(&mut self, integer: NodeId) -> NodeId {match self.graph.constant_value(integer) {diff --git a/Libraries/LibJS/JIT/Rust/src/builder/speculation.rs b/Libraries/LibJS/JIT/Rust/src/builder/speculation.rsindex 53485f7b468..6ca0fd09918 100644--- a/Libraries/LibJS/JIT/Rust/src/builder/speculation.rs+++ b/Libraries/LibJS/JIT/Rust/src/builder/speculation.rs@@ -407,8 +407,8 @@ impl GraphBuilder<'_> {/// The number `value` is, as an unboxed double, checked where needed.pub(super) fn number(&mut self, value: NodeId) -> NodeId {- if self.graph.node(value).repr == Some(Repr::Float64) {- return value;+ if let Some(double) = self.float64_value_of(value) {+ return double;}if let Some(integer) = self.int32_value_of(value) {return self.int32_to_float64(integer);@@ -854,8 +854,8 @@ impl GraphBuilder<'_> {value: NodeId,otherwise: impl FnOnce(&mut Self, BranchCondition, Vec<NodeId>) -> NodeId,) -> NodeId {- if self.graph.node(value).repr == Some(Repr::Float64) {- return value;+ if let Some(double) = self.float64_value_of(value) {+ return double;}if let Some(integer) = self.int32_value_of(value) {return self.int32_to_float64(integer);