Skip to content

Commit

Permalink
Merge branch 'fix-stack-alignment'
Browse files Browse the repository at this point in the history
  • Loading branch information
CuppoJava committed Dec 7, 2022
2 parents ac1a17b + 51b16e2 commit 311502c
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion compiler/jit-encoder.stanza
Original file line number Diff line number Diff line change
Expand Up @@ -1286,6 +1286,7 @@ defn AsmGen (code:CodeHolder,
; before the CALL instruction.
;2) Therefore we need to push an odd number of items onto the stack to
; ensure that our own CALL instructions are 16-byte aligned.
; In the body of JIT generated code, RSP will be 0x???????0.
defn make-jit-launch-stub () :
;Save incoming arguments
push(a, reg(Tmp1)) ;Save Dummy for 16-byte stack alignment.
Expand Down Expand Up @@ -1445,9 +1446,13 @@ defn AsmGen (code:CodeHolder,
;Call directly using the C-calling convention.
defn emit-fast-callc (f:VMImm, xs:Tuple<Local|VMType>, ys:Tuple<VMImm>) :
;This is added to CRSP before the call.
;In the body of JIT generated code, launcher ensures that RSP will be 0x???????0.
;The System-V convention requires that RSP by 0x???????0 before the CALL instruction.
;Therefore we ensure that the number of slots is even.
defn crsp-offset (records:CallCRecords) -> Int :
val num-slots = num-mem-args(records) + c-num-spill-slots(backend)
(8 * num-slots + 7) & -8
;Ensure that the number of slots is even so that the new C RSP is 16-byte aligned.
8 * ((num-slots + 1) & -2)

;Compute all the SetCArg to implement the given calling records.
defn compute-set-c-args (records:CallCRecords) -> Tuple<SetCArg> :
Expand Down

0 comments on commit 311502c

Please sign in to comment.