Skip to content

Commit 0e501b8

Browse files
committed
add: madhyasthal: INC implementation + codegen path
1 parent 8e131c1 commit 0e501b8

4 files changed

Lines changed: 31 additions & 1 deletion

File tree

benchmarks/script/patch.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ function expensiveLoop()
99
var i = 0;
1010
while (i < 65536)
1111
{
12-
i = 65536;
12+
i++;
1313
}
1414

1515
return i;

src/bali/runtime/compiler/amd64/midtier.nim

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,26 @@ proc compileLowered(
352352
cgen.patchConditionalJmps &=
353353
ConditionalJump(label: cgen.s.label(), op: i + 2, condition: condNotBelow)
354354
cgen.s.jcc(condNotBelow, BackwardsLabel(EnsureNoInt8Align))
355+
of InstKind.Increment:
356+
alignStack 8:
357+
cgen.s.mov(regRdi, cast[int64](cgen.vm))
358+
cgen.s.mov(regRsi, int64(inst.args[0].vreg))
359+
cgen.s.call(cgen.callbacks.getAtom)
360+
361+
cgen.s.mov(regRdi.reg, regRax)
362+
cgen.s.call(getRawFloat)
363+
364+
cgen.s.mov(regR9, 0x3FF0000000000000)
365+
cgen.s.movq(regXmm1, regR9.reg)
366+
cgen.s.addsd(regXmm0, regXmm1.reg)
367+
368+
cgen.s.mov(regRdi, cast[int64](cgen.vm))
369+
cgen.s.call(cgen.callbacks.allocFloat)
370+
371+
cgen.s.mov(regRdi, cast[int64](cgen.vm))
372+
cgen.s.mov(regRsi.reg, regRax)
373+
cgen.s.mov(regRdx, int64(inst.args[0].vreg))
374+
cgen.s.call(cgen.callbacks.addAtom)
355375
else:
356376
debug "jit/amd64: midtier cannot lower op into x64 code: " & $inst.kind
357377
return

src/bali/runtime/compiler/madhyasthal/ir.nim

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ type
2626
Jump
2727
Equate
2828
LesserThanInt
29+
Increment
2930

3031
Register* {.size: sizeof(uint8), pure.} = enum
3132
ReturnValue = 0
@@ -177,4 +178,9 @@ func lesserThanI*(a, b: uint32): Inst =
177178
kind: InstKind.LesserThanInt,
178179
args: [ArgVariant(kind: avkPos, vreg: a), ArgVariant(kind: avkPos, vreg: b)],
179180
)
181+
182+
func increment*(a: uint32): Inst =
183+
Inst(
184+
kind: InstKind.Increment, args: [ArgVariant(kind: avkPos, vreg: a), ArgVariant()]
185+
)
180186
{.pop.}

src/bali/runtime/compiler/madhyasthal/lowering.nim

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,10 @@ proc lowerStream*(fn: var Function, stream: var OpStream): bool =
258258
lesserThanI(
259259
uint32(&op.arguments[0].getInt()), uint32(&op.arguments[1].getInt())
260260
)
261+
of Increment:
262+
let op = stream.consume()
263+
264+
fn.insts &= increment(uint32(&op.arguments[0].getInt()))
261265
else:
262266
bailout "cannot find predictable pattern for op: " & $stream.peekKind()
263267

0 commit comments

Comments
 (0)