From 33f18f6b85d5298d9f65f252bb3abc11f3e4e0c1 Mon Sep 17 00:00:00 2001 From: Taylor R Campbell Date: Sun, 26 Jun 2011 19:45:40 +0000 Subject: [PATCH] Move interrupt branch from start to end of block, on x86-64. --- src/compiler/machines/x86-64/rules3.scm | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/compiler/machines/x86-64/rules3.scm b/src/compiler/machines/x86-64/rules3.scm index 08b13f0ec..1f83d0b1c 100644 --- a/src/compiler/machines/x86-64/rules3.scm +++ b/src/compiler/machines/x86-64/rules3.scm @@ -380,14 +380,23 @@ USA. (define (interrupt-check interrupt-label checks) ;; This always does interrupt checks in line. - (LAP ,@(if (or (memq 'INTERRUPT checks) (memq 'HEAP checks)) - (LAP (CMP Q (R ,regnum:free-pointer) ,reg:compiled-memtop) - (JGE (@PCR ,interrupt-label))) - (LAP)) - ,@(if (memq 'STACK checks) - (LAP (CMP Q (R ,regnum:stack-pointer) ,reg:stack-guard) - (JL (@PCR ,interrupt-label))) - (LAP)))) + (let ((branch-target (generate-label 'INTERRUPT))) + ;; Put the interrupt check branch target after the branch so that + ;; it is a forward branch, which Intel and AMD CPUs will predict + ;; not taken by default, in the absence of dynamic branch + ;; prediction profile data. + (add-end-of-block-code! + (lambda () + (LAP (LABEL ,branch-target) + (JMP (@PCR ,interrupt-label))))) + (LAP ,@(if (or (memq 'INTERRUPT checks) (memq 'HEAP checks)) + (LAP (CMP Q (R ,regnum:free-pointer) ,reg:compiled-memtop) + (JGE (@PCR ,branch-target))) + (LAP)) + ,@(if (memq 'STACK checks) + (LAP (CMP Q (R ,regnum:stack-pointer) ,reg:stack-guard) + (JL (@PCR ,branch-target))) + (LAP))))) (define (simple-procedure-header code-word label entry) (let ((checks (get-entry-interrupt-checks))) -- 2.25.1