1 ;;;; constants and types for assembly
3 ;;;; This software is part of the SBCL system. See the README file for
6 ;;;; This software is derived from the CMU CL system, which was
7 ;;;; written at Carnegie Mellon University and released into the
8 ;;;; public domain. The software is in the public domain and is
9 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
10 ;;;; files for more information.
12 (in-package "SB!ASSEM")
14 ;;; FIXME: It might make sense to use SB!VM:BYTE-FOO values here
15 ;;; instead of the various ASSEMBLY-UNIT-FOO things, and then define a
16 ;;; BYTE type. One problem: BYTE is exported from the CL package, so
17 ;;; ANSI says that we're not supposed to be attaching any new meanings
18 ;;; to it. Perhaps rename SB!VM:BYTE-FOO to SB!VM:VMBYTE-FOO or
19 ;;; SB!VM:VM-BYTE-FOO, and then define the SB!VM:VMBYTE or
20 ;;; SB!VM:VM-BYTE types?
22 ;;; If this was done, some of this file could go away, and the rest
23 ;;; could probably be merged back into assem.lisp. (This file was
24 ;;; created simply in order to move the ASSEMBLY-UNIT-related
25 ;;; definitions before compiler/generic/core.lisp in the build
28 ;;; ASSEMBLY-UNIT-BITS -- the number of bits in the minimum assembly
29 ;;; unit, (also referred to as a ``byte''). Hopefully, different
30 ;;; instruction sets won't require changing this.
31 (defconstant assembly-unit-bits
8)
32 (defconstant assembly-unit-mask
(1- (ash 1 assembly-unit-bits
)))
34 (deftype assembly-unit
()
35 `(unsigned-byte ,assembly-unit-bits
))
37 ;;; Some functions which accept assembly units can meaningfully accept
38 ;;; signed values with the same number of bits and silently munge them
39 ;;; into appropriate unsigned values. (This is handy behavior e.g.
40 ;;; when assembling branch instructions on the X86.)
41 (deftype possibly-signed-assembly-unit
()
43 (signed-byte ,assembly-unit-bits
)))
45 ;;; the maximum alignment we can guarantee given the object format. If
46 ;;; the loader only loads objects 8-byte aligned, we can't do any
47 ;;; better then that ourselves.
48 (defconstant max-alignment sb
!vm
:n-lowtag-bits
)
51 `(integer 0 ,max-alignment
))
53 ;;; common supertype for all the different kinds of annotations
54 (defstruct (annotation (:constructor nil
)
56 ;; Where in the raw output stream was this annotation emitted?
58 ;; What position does that correspond to?
59 (posn nil
:type
(or index null
)))
61 (defstruct (label (:include annotation
)
62 (:constructor gen-label
())
64 ;; (doesn't need any additional information beyond what is in the
65 ;; annotation structure)
67 (defmethod print-object ((label label
) stream
)
68 (if (or *print-escape
* *print-readably
*)
69 (print-unreadable-object (label stream
:type t
)
70 (prin1 (sb!c
:label-id label
) stream
))
71 (format stream
"L~D" (sb!c
:label-id label
))))
73 (defmacro sb
!vm
::define-assembly-routine
(name&options vars
&body code
)
74 (multiple-value-bind (name options
)
75 (if (atom name
&options
)
76 (values name
&options nil
)
77 (values (car name
&options
) (cdr name
&options
)))
78 (let ((regs (mapcar (lambda (var) (apply #'sb
!c
::parse-reg-spec var
))
80 (declare (special sb
!c
::*emit-assembly-code-not-vops-p
*))
81 (if sb
!c
::*emit-assembly-code-not-vops-p
*
82 (sb!c
::emit-assemble name options regs code
)
83 (sb!c
::emit-assemble-vop name options regs
)))))
85 (defun unintern-init-only-stuff ()
86 ;; This macro can't be used in the target.
87 (unintern 'sb
!vm
::define-assembly-routine
"SB-VM"))