From f735fd577c01137f2e6705b5146fa50b9ec8122f Mon Sep 17 00:00:00 2001 From: Stas Boukarev Date: Sun, 26 Apr 2026 19:16:19 +0300 Subject: [PATCH] x86-64, struct callbacks: leave registers if a struct doesn't fit Which was copied from arm64. --- src/compiler/x86-64/c-call.lisp | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/compiler/x86-64/c-call.lisp b/src/compiler/x86-64/c-call.lisp index d6f9c09f8..362df5a9d 100644 --- a/src/compiler/x86-64/c-call.lisp +++ b/src/compiler/x86-64/c-call.lisp @@ -951,12 +951,10 @@ Floats are passed in integer registers." (struct-size (sb-alien::struct-classification-size classification)) (slots (sb-alien::struct-classification-register-slots classification)) (n-int (count :integer slots)) - (n-fp (count :double slots))) - (when (or (> n-int (length gprs)) - (> n-fp (length fprs))) - ;; Don't mix stack/registers - (setf gprs nil - fprs nil)) + (n-fp (count :double slots)) + ;; Don't mix stack/registers + (use-registers (and (<= n-int (length gprs)) + (<= n-fp (length fprs))))) #+win32 (cond ;; Large struct: pointer passed in register @@ -976,12 +974,14 @@ Floats are passed in integer registers." (inst mov (ea dst-off rsp) r11))))) ;; Small struct: single integer register (t - (let ((gpr (pop gprs))) - (pop fprs) - (unless gpr - (incf stack-argument-count) - (setf gpr rax) - (inst mov gpr stack-arg-tn)) + (let ((gpr (and use-registers + (pop gprs)))) + (cond (gpr + (pop fprs)) + (t + (incf stack-argument-count) + (setf gpr rax) + (inst mov gpr stack-arg-tn))) (inst mov (ea arg-offset rsp) gpr)))) #-win32 (cond @@ -1003,14 +1003,16 @@ Floats are passed in integer registers." for slot-offset from arg-offset by n-word-bytes do (ecase class (:integer - (let ((gpr (pop gprs))) + (let ((gpr (and use-registers + (pop gprs)))) (unless gpr (incf stack-argument-count) (setf gpr rax) (inst mov gpr (ea (- stack-args-offset n-word-bytes) rsp))) (inst mov (ea slot-offset rsp) gpr))) (:double - (let ((fpr (pop fprs))) + (let ((fpr (and use-registers + (pop fprs)))) (cond (fpr (inst movq (ea slot-offset rsp) fpr)) (t