Add inlining (or compiler intrinsics if you prefer) for AND and XOR

This commit is contained in:
John Lorentzson 2025-07-31 16:06:41 +02:00
parent 70fb3a9500
commit 0f80ba10ef
2 changed files with 51 additions and 1 deletions

View file

@ -280,6 +280,24 @@ is the responsibility of the pre-assembly compilation step."
;; BCS to true path ;; BCS to true path
(emit-branch-test-code (inputs inst) (output inst) '((#xB0)))) (emit-branch-test-code (inputs inst) (output inst) '((#xB0))))
;;; Inline snippets
(define-normal-emitter emit-and #x29 #x25 #x2D)
(defmethod compile-ir ((inst ir-inline-bitand))
(emit-load-data (first (inputs inst)))
(emit-and (data-reference (second (inputs inst))))
(emit-store-data (output inst)))
(define-normal-emitter emit-xor #x49 #x45 #x4D)
(defmethod compile-ir ((inst ir-inline-bitxor))
(emit-load-data (first (inputs inst)))
(emit-xor (data-reference (second (inputs inst))))
(emit-store-data (output inst)))
;;; Functions for the performing the compilation process
(defmacro do-asm-objects ((asm-obj start-asm-obj) &body body) (defmacro do-asm-objects ((asm-obj start-asm-obj) &body body)
`(loop :for ,asm-obj := ,start-asm-obj :then (next ,asm-obj) `(loop :for ,asm-obj := ,start-asm-obj :then (next ,asm-obj)
:until (null ,asm-obj) :until (null ,asm-obj)

View file

@ -1,5 +1,35 @@
(in-package #:user-side-compiler) (in-package #:user-side-compiler)
(defclass ir-inline (ir-inst) ())
(defclass ir-inline-bitand (ir-inline ir-operation) ())
(defclass ir-inline-bitxor (ir-inline ir-operation) ())
(defparameter *inline-functions*
'(("bitand" . ir-inline-bitand)
("bitxor" . ir-inline-bitxor)))
(defun optim-inline (start-iblock)
(do-iblocks (iblock start-iblock)
(do-instructions (inst iblock)
(when (typep inst 'ir-call)
(let ((inline-equivalent (cdr (assoc (name (callee inst))
*inline-functions*
:test #'string-equal))))
(unless (null inline-equivalent)
(let* ((inputs (inputs inst))
(output (output inst)))
(setf (inputs inst) '()
(output inst) nil)
(let ((new (make-instance inline-equivalent
:source (source inst)
:inputs inputs
:output output)))
(insert-instruction-above new inst)
(delete-instruction inst)
(setf inst new))))))))
(print-iblocks start-iblock))
(defun optim-reuse-temporary-slots (start-iblock allocations) (defun optim-reuse-temporary-slots (start-iblock allocations)
(let ((free '())) (let ((free '()))
(do-iblocks (iblock start-iblock) (do-iblocks (iblock start-iblock)
@ -58,7 +88,9 @@
(defun pre-assembly (iblock) (defun pre-assembly (iblock)
(pre-assembly-software-operations iblock) (pre-assembly-software-operations iblock)
(optim-prepare-direct-instructions iblock) (optim-inline iblock)
(do-iblocks (ib iblock)
(optim-prepare-direct-instructions ib))
(let ((allocs (allocate-values iblock))) (let ((allocs (allocate-values iblock)))
(optim-reuse-temporary-slots iblock allocs) (optim-reuse-temporary-slots iblock allocs)
allocs)) allocs))