Skip to content

Commit 95a590f

Browse files
committed
Optimize divisions and remainders by constants.
Following the techniques described in Hacker's Delight, Chapter 10. Benchmarking suggested that is this generally worth it, except for non-powers of 2 for a) int operations on JS and b) long operations on Wasm. For the long divisions on JS, this yields a 6x speedup, despite the fact that the resulting code needs 16 (!) primitive int multiplications.
1 parent 849495b commit 95a590f

File tree

7 files changed

+1620
-7
lines changed

7 files changed

+1620
-7
lines changed

ir/shared/src/main/scala/org/scalajs/ir/Trees.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,13 @@ object Trees {
125125

126126
override def toString(): String =
127127
stats.mkString("Block(", ",", ")")
128+
129+
override def equals(that: Any): Boolean = that match {
130+
case that: Block => this.stats == that.stats
131+
case _ => false
132+
}
133+
134+
override def hashCode(): Int = stats.##
128135
}
129136

130137
object Block {

0 commit comments

Comments
 (0)