home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / pcl / src-16f.lha / compiler / mips / memory.lisp < prev    next >
Encoding:
Text File  |  1991-11-06  |  5.5 KB  |  171 lines

  1. ;;; -*- Package: C; Log: C.Log -*-
  2. ;;;
  3. ;;; **********************************************************************
  4. ;;; This code was written as part of the CMU Common Lisp project at
  5. ;;; Carnegie Mellon University, and has been placed in the public domain.
  6. ;;; If you want to use this code or any part of CMU Common Lisp, please contact
  7. ;;; Scott Fahlman or slisp-group@cs.cmu.edu.
  8. ;;;
  9. (ext:file-comment
  10.   "$Header: memory.lisp,v 1.12 91/02/20 15:14:39 ram Exp $")
  11. ;;;
  12. ;;; **********************************************************************
  13. ;;;
  14. ;;; $Header: memory.lisp,v 1.12 91/02/20 15:14:39 ram Exp $
  15. ;;;
  16. ;;;    This file contains the MIPS definitions of some general purpose memory
  17. ;;; reference VOPs inherited by basic memory reference operations.
  18. ;;;
  19. ;;; Written by Rob MacLachlan
  20. ;;;
  21. ;;; Converted by William Lott.
  22. ;;; 
  23.  
  24. (in-package "MIPS")
  25.  
  26.  
  27. ;;; Cell-Ref and Cell-Set are used to define VOPs like CAR, where the offset to
  28. ;;; be read or written is a property of the VOP used.  Cell-Setf is similar to
  29. ;;; Cell-Set, but delivers the new value as the result.  Cell-Setf-Function
  30. ;;; takes its arguments as if it were a setf function (new value first, as
  31. ;;; apposed to a setf macro, which takes the new value last).
  32. ;;;
  33. (define-vop (cell-ref)
  34.   (:args (object :scs (descriptor-reg)))
  35.   (:results (value :scs (descriptor-reg any-reg)))
  36.   (:variant-vars offset lowtag)
  37.   (:policy :fast-safe)
  38.   (:generator 4
  39.     (loadw value object offset lowtag)))
  40. ;;;
  41. (define-vop (cell-set)
  42.   (:args (object :scs (descriptor-reg))
  43.          (value :scs (descriptor-reg any-reg)))
  44.   (:variant-vars offset lowtag)
  45.   (:policy :fast-safe)
  46.   (:generator 4
  47.     (storew value object offset lowtag)))
  48. ;;;
  49. (define-vop (cell-setf)
  50.   (:args (object :scs (descriptor-reg))
  51.      (value :scs (descriptor-reg any-reg)
  52.         :target result))
  53.   (:results (result :scs (descriptor-reg any-reg)))
  54.   (:variant-vars offset lowtag)
  55.   (:policy :fast-safe)
  56.   (:generator 4
  57.     (storew value object offset lowtag)
  58.     (move result value)))
  59. ;;;
  60. (define-vop (cell-setf-function)
  61.   (:args (value :scs (descriptor-reg any-reg)
  62.         :target result)
  63.      (object :scs (descriptor-reg)))
  64.   (:results (result :scs (descriptor-reg any-reg)))
  65.   (:variant-vars offset lowtag)
  66.   (:policy :fast-safe)
  67.   (:generator 4
  68.     (storew value object offset lowtag)
  69.     (move result value)))
  70.  
  71. ;;; Define-Cell-Accessors  --  Interface
  72. ;;;
  73. ;;;    Define accessor VOPs for some cells in an object.  If the operation name
  74. ;;; is NIL, then that operation isn't defined.  If the translate function is
  75. ;;; null, then we don't define a translation.
  76. ;;;
  77. (defmacro define-cell-accessors (offset lowtag
  78.                     ref-op ref-trans set-op set-trans)
  79.   `(progn
  80.      ,@(when ref-op
  81.      `((define-vop (,ref-op cell-ref)
  82.          (:variant ,offset ,lowtag)
  83.          ,@(when ref-trans
  84.          `((:translate ,ref-trans))))))
  85.      ,@(when set-op
  86.      `((define-vop (,set-op cell-setf)
  87.          (:variant ,offset ,lowtag)
  88.          ,@(when set-trans
  89.          `((:translate ,set-trans))))))))
  90.  
  91.  
  92. ;;; Slot-Ref and Slot-Set are used to define VOPs like Closure-Ref, where the
  93. ;;; offset is constant at compile time, but varies for different uses.  We add
  94. ;;; in the stardard g-vector overhead.
  95. ;;;
  96. (define-vop (slot-ref)
  97.   (:args (object :scs (descriptor-reg)))
  98.   (:results (value :scs (descriptor-reg any-reg)))
  99.   (:variant-vars base lowtag)
  100.   (:info offset)
  101.   (:generator 4
  102.     (loadw value object (+ base offset) lowtag)))
  103. ;;;
  104. (define-vop (slot-set)
  105.   (:args (object :scs (descriptor-reg))
  106.      (value :scs (descriptor-reg any-reg)))
  107.   (:variant-vars base lowtag)
  108.   (:info offset)
  109.   (:generator 4
  110.     (storew value object (+ base offset) lowtag)))
  111.  
  112.  
  113.  
  114. ;;;; Indexed references:
  115.  
  116. ;;; Define-Indexer  --  Internal
  117. ;;;
  118. ;;;    Define some VOPs for indexed memory reference.  Unless the index is
  119. ;;; constant, we must compute an intermediate result in a boxed temporary,
  120. ;;; since the RT doesn't have any indexed addressing modes.  This means that GC
  121. ;;; has to adjust the "raw" pointer in Index-Temp by observing that Index-Temp
  122. ;;; points within Object-Temp.  After we are done, we clear Index-Temp so that
  123. ;;; we don't raw pointers lying around.
  124. ;;;
  125. (defmacro define-indexer (name write-p op shift)
  126.   `(define-vop (,name)
  127.      (:args (object :scs (descriptor-reg))
  128.         (index :scs (any-reg zero immediate negative-immediate))
  129.         ,@(when write-p
  130.         '((value :scs (any-reg descriptor-reg) :target result))))
  131.      (:arg-types * tagged-num ,@(when write-p '(*)))
  132.      (:temporary (:scs (interior-reg) :type interior) lip)
  133.      ,@(unless (zerop shift)
  134.      `((:temporary (:scs (non-descriptor-reg) :type random) temp)))
  135.      (:results (,(if write-p 'result 'value)
  136.         :scs (any-reg descriptor-reg)))
  137.      (:result-types *)
  138.      (:variant-vars offset lowtag)
  139.      (:policy :fast-safe)
  140.      (:generator 5
  141.        (sc-case index
  142.      ((immediate zero negative-immediate)
  143.       (inst ,op value object
  144.         (- (+ (if (sc-is index zero)
  145.               0
  146.               (ash (tn-value index) (- word-shift ,shift)))
  147.               (ash offset word-shift))
  148.            lowtag))
  149.       ,(if write-p
  150.            '(move result value)
  151.            '(inst nop)))
  152.      (t
  153.       ,@(if (zerop shift)
  154.         `((inst addu lip object index))
  155.         `((inst srl temp index ,shift)
  156.           (inst addu lip temp object)))
  157.       (inst ,op value lip (- (ash offset word-shift) lowtag))
  158.       ,(if write-p
  159.            '(move result value)
  160.            '(inst nop)))))))
  161.  
  162. (define-indexer word-index-ref nil lw 0)
  163. (define-indexer word-index-set t sw 0)
  164. (define-indexer halfword-index-ref nil lhu 1)
  165. (define-indexer signed-halfword-index-ref nil lh 1)
  166. (define-indexer halfword-index-set t sh 1)
  167. (define-indexer byte-index-ref nil lbu 2)
  168. (define-indexer signed-byte-index-ref nil lb 2)
  169. (define-indexer byte-index-set t sb 2)
  170.  
  171.