Skip to content

Commit 3f29eb1

Browse files
committed
Alternative scheme for resHi as an Int32Array of size 1.
Sadly, that doesn't fix the GCC issue. It may have performance, especially in multi-module outputs, as we don't need to mutate a foreign var.
1 parent ce1d915 commit 3f29eb1

File tree

4 files changed

+32
-17
lines changed

4 files changed

+32
-17
lines changed

linker/shared/src/main/scala/org/scalajs/linker/backend/emitter/CoreJSLib.scala

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,13 @@ private[emitter] object CoreJSLib {
520520

521521
private def defineResHi(): List[Tree] = {
522522
condDefs(!allowBigIntsForLongs)(
523-
extractWithGlobals(globallyMutableVarDef(VarField.resHi, VarField.setResHi, CoreVar, int(0)))
523+
extractWithGlobals(globallyMutableVarDef(VarField.resHi, VarField.setResHi, CoreVar, {
524+
if (esVersion >= ESVersion.ES2015) {
525+
New(globalRef("Int32Array"), List(int(1)))
526+
} else {
527+
ArrayConstr(List(int(0)))
528+
}
529+
}))
524530
)
525531
}
526532

@@ -1504,12 +1510,12 @@ private[emitter] object CoreJSLib {
15041510
} else {
15051511
If(v === Null(), {
15061512
Block(
1507-
globalVar(VarField.resHi, CoreVar) := 0,
1513+
genResHi() := 0,
15081514
0
15091515
)
15101516
}, {
15111517
Block(
1512-
globalVar(VarField.resHi, CoreVar) := v DOT cpn.hi,
1518+
genResHi() := v DOT cpn.hi,
15131519
v DOT cpn.lo
15141520
)
15151521
})
@@ -1536,12 +1542,12 @@ private[emitter] object CoreJSLib {
15361542
} else {
15371543
If(v === Null(), {
15381544
Block(
1539-
globalVar(VarField.resHi, CoreVar) := 0,
1545+
genResHi() := 0,
15401546
Return(0)
15411547
)
15421548
}, {
15431549
Block(
1544-
globalVar(VarField.resHi, CoreVar) := v DOT cpn.hi,
1550+
genResHi() := v DOT cpn.hi,
15451551
Return(v DOT cpn.lo)
15461552
)
15471553
})
@@ -1596,7 +1602,7 @@ private[emitter] object CoreJSLib {
15961602
Block(
15971603
boundsCheck,
15981604
i := (i << 1),
1599-
globalVar(VarField.resHi, CoreVar) := BracketSelect(This().u, (i + 1) | 0),
1605+
genResHi() := BracketSelect(This().u, (i + 1) | 0),
16001606
Return(BracketSelect(This().u, i))
16011607
)
16021608
}),

linker/shared/src/main/scala/org/scalajs/linker/backend/emitter/FunctionEmitter.scala

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1742,22 +1742,16 @@ private[emitter] class FunctionEmitter(sjsGen: SJSGen) {
17421742
js.Block(transformStat(rhs, tailPosLabels = Set.empty), js.Return(js.Undefined()))
17431743
case LongType if !useBigIntForLongs =>
17441744
val (lo, hi) = transformLongExpr(rhs)
1745-
val resHi = globalVar(VarField.resHi, CoreVar)
1746-
if (hi == resHi) {
1745+
if (isResHi(hi)) {
17471746
/* No need to assign resHi to itself.
17481747
* This happens for all tail calls of Long-returning functions.
17491748
*/
17501749
js.Return(lo)
17511750
} else {
17521751
val tempLo = newSyntheticVar()
1753-
val resHiAssign = if (needToUseGloballyMutableVarSetter(CoreVar)) {
1754-
js.Apply(globalVar(VarField.setResHi, CoreVar), hi :: Nil)
1755-
} else {
1756-
js.Assign(resHi, hi)
1757-
}
17581752
js.Block(
17591753
genConst(tempLo, lo),
1760-
resHiAssign,
1754+
js.Assign(genResHi(), hi),
17611755
js.Return(js.VarRef(tempLo))
17621756
)
17631757
}
@@ -3230,7 +3224,7 @@ private[emitter] class FunctionEmitter(sjsGen: SJSGen) {
32303224
}
32313225

32323226
def withResHi(jsTree: js.Tree): (js.Tree, js.Tree) =
3233-
(jsTree, globalVar(VarField.resHi, CoreVar))
3227+
(jsTree, genResHi())
32343228

32353229
tree match {
32363230
// Control flow constructs

linker/shared/src/main/scala/org/scalajs/linker/backend/emitter/SJSGen.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,21 @@ private[emitter] final class SJSGen(
186186
else Nil
187187
}
188188

189+
def genResHi()(
190+
implicit moduleContext: ModuleContext, globalKnowledge: GlobalKnowledge,
191+
pos: Position): Tree = {
192+
BracketSelect(globalVar(VarField.resHi, CoreVar), IntLiteral(0))
193+
}
194+
195+
def isResHi(tree: Tree)(
196+
implicit moduleContext: ModuleContext, globalKnowledge: GlobalKnowledge,
197+
pos: Position): Boolean = {
198+
tree match {
199+
case BracketSelect(qual, IntLiteral(0)) => qual == globalVar(VarField.resHi, CoreVar)
200+
case _ => false
201+
}
202+
}
203+
189204
def genZeroOf(tpe: Type)(
190205
implicit moduleContext: ModuleContext, globalKnowledge: GlobalKnowledge,
191206
pos: Position): Tree = {

project/Build.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2080,7 +2080,7 @@ object Build {
20802080
} else {
20812081
Some(ExpectedSizes(
20822082
fastLink = 424000 to 425000,
2083-
fullLink = 282000 to 283000,
2083+
fullLink = 283000 to 284000,
20842084
fastLinkGz = 61000 to 62000,
20852085
fullLinkGz = 44000 to 45000,
20862086
))
@@ -2097,7 +2097,7 @@ object Build {
20972097
} else {
20982098
Some(ExpectedSizes(
20992099
fastLink = 300000 to 301000,
2100-
fullLink = 259000 to 260000,
2100+
fullLink = 260000 to 261000,
21012101
fastLinkGz = 47000 to 48000,
21022102
fullLinkGz = 43000 to 44000,
21032103
))

0 commit comments

Comments
 (0)