Remove NOPs from conditionals by adding a branch-tensioner hack to
authorGuillermo J. Rozas <edu/mit/csail/zurich/gjr>
Sat, 13 Feb 1993 05:37:27 +0000 (05:37 +0000)
committerGuillermo J. Rozas <edu/mit/csail/zurich/gjr>
Sat, 13 Feb 1993 05:37:27 +0000 (05:37 +0000)
accomodate the sign of the displacement.

v7/src/compiler/machines/spectrum/instr1.scm
v7/src/compiler/machines/spectrum/instr2.scm
v7/src/compiler/machines/spectrum/lapgen.scm

index a6fb847463019b8154821b86f29b2cffc9329dfe..2b98e0c6c93271964cc40e1b506c429fefcbdfb4 100644 (file)
@@ -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))
 \f
@@ -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)))
index db0b52a063260c4bbcce9205e9048dccb95aac02..d5e0493e6dd71ff9f2ad72939e4d0825a34cf27f 100644 (file)
@@ -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))
 \f
@@ -560,6 +561,106 @@ branch-extend-nullify in instr1.
   (defpseudo COMIB #X21 (immed-5 right-signed))
   (defpseudo ADDIB #x29 (immed-5 right-signed)))
 \f
+;;;; 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.
+|#
+\f
+(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)))
+\f
 ;;;; Miscellaneous control
 
 (let-syntax
index 81d9d106737707ee5f7dcbf505d66bfaddec5229..7e812e9bbcf3c7ec28674975bebf83e36c40e3f1 100644 (file)
@@ -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)))
 \f
-;; 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))
 \f
 ;;;; 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 ())))