From: Guillermo J. Rozas Date: Sat, 13 Feb 1993 05:37:27 +0000 (+0000) Subject: Remove NOPs from conditionals by adding a branch-tensioner hack to X-Git-Tag: 20090517-FFI~8526 X-Git-Url: https://birchwood-abbey.net/git?a=commitdiff_plain;h=8d1994da1fecb9de3359f6ed3204d436ffdd2fb3;p=mit-scheme.git Remove NOPs from conditionals by adding a branch-tensioner hack to accomodate the sign of the displacement. --- diff --git a/v7/src/compiler/machines/spectrum/instr1.scm b/v7/src/compiler/machines/spectrum/instr1.scm index a6fb84746..2b98e0c6c 100644 --- a/v7/src/compiler/machines/spectrum/instr1.scm +++ b/v7/src/compiler/machines/spectrum/instr1.scm @@ -1,8 +1,8 @@ #| -*-Scheme-*- -$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/compiler/machines/spectrum/instr1.scm,v 1.2 1990/07/19 04:03:55 jinx Rel $ +$Id: instr1.scm,v 1.3 1993/02/13 05:37:22 gjr Exp $ -Copyright (c) 1987, 1989, 1990 Massachusetts Institute of Technology +Copyright (c) 1987-1993 Massachusetts Institute of Technology This material was developed by the Scheme project at the Massachusetts Institute of Technology, Department of Electrical Engineering and @@ -34,6 +34,7 @@ MIT in each case. |# ;;;; HP Spectrum instruction utilities ;;; Originally from Walt Hill, who did the hard part. +;;; package: (compiler lap-syntaxer) (declare (usual-integrations)) @@ -75,6 +76,13 @@ MIT in each case. |# (lambda (completer) (arith-log-condition completer))) +(define-transformer complaltf + (lambda (completer) + (let ((val (arith-log-condition completer))) + (if (not (zero? (cadr val))) + (error "complaltf: Bad completer" completer) + val)))) + (define-transformer fpformat (lambda (completer) (encode-fpformat completer))) diff --git a/v7/src/compiler/machines/spectrum/instr2.scm b/v7/src/compiler/machines/spectrum/instr2.scm index db0b52a06..d5e0493e6 100644 --- a/v7/src/compiler/machines/spectrum/instr2.scm +++ b/v7/src/compiler/machines/spectrum/instr2.scm @@ -1,8 +1,8 @@ #| -*-Scheme-*- -$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/compiler/machines/spectrum/instr2.scm,v 1.3 1990/08/05 05:41:27 jinx Rel $ +$Id: instr2.scm,v 1.4 1993/02/13 05:37:27 gjr Exp $ -Copyright (c) 1987, 1989, 1990 Massachusetts Institute of Technology +Copyright (c) 1987-1993 Massachusetts Institute of Technology This material was developed by the Scheme project at the Massachusetts Institute of Technology, Department of Electrical Engineering and @@ -34,6 +34,7 @@ MIT in each case. |# ;;;; HP Spectrum Instruction Set Description ;;; Originally from Walt Hill, who did the hard part. +;;; package: (compiler lap-syntaxer) (declare (usual-integrations)) @@ -560,6 +561,106 @@ branch-extend-nullify in instr1. (defpseudo COMIB #X21 (immed-5 right-signed)) (defpseudo ADDIB #x29 (immed-5 right-signed))) +;;;; Pseudo branch instructions. + +#| + +These nullify the following instruction when the branch is taken. +irrelevant of the sign of the displacement (unlike the real instructions). +If the displacement is positive, they use the nullify bit. +If the displacement is negative, they use a NOP. + + combn,cc r1,r2,label + +becomes either + + comb,cc,n r1,r2,label + +if label is downstream (forward branch) + +or + + comb,cc r1,r2,label + nop + +if label is upstream (backward branch) + +If the displacement is too large, it becomes + + comb,!cc,n r1,r2,tlabel ; pco = 0 + b,n label +tlabel + +Note: Only those currently used by the code generator are implemented. +|# + +(let-syntax + ((defccbranch + (macro (keyword completer opcode1 opcode2 opr1) + `(define-instruction ,keyword + ;; No @PCO form. It is a pseudo-instruction generated by the assembler + + (((? compl ,completer) (? ,(car opr1)) (? reg-2) (@PCR (? l))) + (VARIABLE-WIDTH + (disp `(- ,l (+ *PC* 8))) + ((#x-2000 -1) + ;; Backward branch. No nullification, insert NOP. + (LONG (6 ,opcode1) ; COMB,cc + (5 reg-2) + (5 ,@opr1) + (3 (car compl)) + (11 disp ASSEMBLE12:X) + (1 0) + (1 disp ASSEMBLE12:Y) + + (6 #x02) ; NOP (OR 0 0 0) + (10 #b0000000000) + (3 0) + (1 0) + (7 #x12) + (5 #b00000))) + + ((0 #x1FFF) + ;; Forward branch. Nullify. + (LONG (6 ,opcode1) ; COMB,cc,n + (5 reg-2) + (5 ,@opr1) + (3 (car compl)) + (11 disp ASSEMBLE12:X) + (1 1) + (1 disp ASSEMBLE12:Y))) + + ((() ()) + (LONG (6 ,opcode2) ; COMB!,n + (5 reg-2) + (5 ,@opr1) + (3 (car compl)) + (11 0 ASSEMBLE12:X) + (1 1) + (1 0 ASSEMBLE12:Y) + + (6 #x3a) ; B,n + (5 0) + (5 (branch-extend-disp disp) ASSEMBLE17:X) + (3 0) + (11 (branch-extend-disp disp) ASSEMBLE17:Y) + (1 1) + (1 (branch-extend-disp disp) ASSEMBLE17:Z))))))))) + + (define-macro (defcond name opcode1 opcode2 opr1) + `(defccbranch ,name complaltf ,opcode1 ,opcode2 ,opr1)) + + (define-macro (defpseudo name opcode opr1) + `(defccbranch ,name complal + (TF-adjust ,opcode compl) + (TF-adjust-inverted ,opcode compl) + ,opr1)) + + (defcond COMIBTN #X21 #x23 (immed-5 right-signed)) + (defcond COMIBFN #X23 #x21 (immed-5 right-signed)) + + (defpseudo COMBN #X20 (reg-1))) + ;;;; Miscellaneous control (let-syntax diff --git a/v7/src/compiler/machines/spectrum/lapgen.scm b/v7/src/compiler/machines/spectrum/lapgen.scm index 81d9d1067..7e812e9bb 100644 --- a/v7/src/compiler/machines/spectrum/lapgen.scm +++ b/v7/src/compiler/machines/spectrum/lapgen.scm @@ -1,8 +1,8 @@ #| -*-Scheme-*- -$Id: lapgen.scm,v 4.40 1992/09/11 22:34:34 cph Exp $ +$Id: lapgen.scm,v 4.41 1993/02/13 05:37:15 gjr Exp $ -Copyright (c) 1988-92 Massachusetts Institute of Technology +Copyright (c) 1988-1993 Massachusetts Institute of Technology This material was developed by the Scheme project at the Massachusetts Institute of Technology, Department of Electrical Engineering and @@ -279,11 +279,10 @@ MIT in each case. |# (DEP () 0 31 2 ,regnum:addil-result) (LDO () (OFFSET (- ,label *PC*) 0 ,regnum:addil-result) ,target))) -;; NOPs are inserted since conditional nullification only nullifies -;; depending on the sign of the branch offset, which is unknown at -;; this point. Linearizer can be changed, fairly easily, to tell us -;; which direction the branch goes so we can decide whether the NOP is -;; needed. +;; COMIBTN, COMIBFN, and COMBN are pseudo-instructions that nullify +;; the following instruction when the branch is taken. Since COMIBT, +;; etc. nullify according to the sign of the displacement, the branch +;; tensioner inserts NOPs as necessary (backward branches). (define (compare-immediate cc i r2) (cond ((zero? i) @@ -300,11 +299,9 @@ MIT in each case. |# (set-branches! (lambda (label) - (LAP (COMIBT (,cc) ,i ,r2 (@PCR ,label)) - (NOP ()))) + (LAP (COMIBTN (,cc) ,i ,r2 (@PCR ,label)))) (lambda (label) - (LAP (COMIBF (,cc) ,i ,r2 (@PCR ,label)) - (NOP ())))) + (LAP (COMIBFN (,cc) ,i ,r2 (@PCR ,label))))) (LAP))) ((fits-in-11-bits-signed? i) (set-current-branches! @@ -323,11 +320,9 @@ MIT in each case. |# (define (compare condition r1 r2) (set-current-branches! (lambda (label) - (LAP (COMB (,condition) ,r1 ,r2 (@PCR ,label)) - (NOP ()))) + (LAP (COMBN (,condition) ,r1 ,r2 (@PCR ,label)))) (lambda (label) - (LAP (COMB (,(invert-condition condition)) ,r1 ,r2 (@PCR ,label)) - (NOP ())))) + (LAP (COMBN (,(invert-condition condition)) ,r1 ,r2 (@PCR ,label))))) (LAP)) ;;;; Conditions @@ -590,6 +585,9 @@ MIT in each case. |# shortcircuit-apply-8 stack-and-interrupt-check)) +;; Why is this NOP here? We could use BLE,N, and adjust +;; the return address within the hook. + (define (invoke-hook hook) (LAP (BLE () (OFFSET ,hook 4 ,regnum:scheme-to-interface-ble)) (NOP ())))