close Warning: Can't use blame annotator:
No changeset 1586 in the repository

source: branches/acode-rewrite/source/compiler/PPC/PPC32/ppc32-arch.lisp

Last change on this file was 16055, checked in by Gary Byers, 11 years ago

Catch up (mostly) on PPC. (ppc2-elide-pushes doesn't elide anything, but that's a perfomance issue.)
Note that complex floats are just consecutive register pairs; the first (realpart) may be even or odd.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 34.7 KB
RevLine 
1;;;-*- Mode: Lisp; Package: (PPC32 :use CL) -*-
2;;;
3;;; Copyright (C) 2009 Clozure Associates
4;;; Copyright (C) 1994-2001 Digitool, Inc
5;;; This file is part of Clozure CL.
6;;;
7;;; Clozure CL is licensed under the terms of the Lisp Lesser GNU Public
8;;; License , known as the LLGPL and distributed with Clozure CL as the
9;;; file "LICENSE". The LLGPL consists of a preamble and the LGPL,
10;;; which is distributed with Clozure CL as the file "LGPL". Where these
11;;; conflict, the preamble takes precedence.
12;;;
13;;; Clozure CL is referenced in the preamble as the "LIBRARY."
14;;;
15;;; The LLGPL is also available online at
16;;; http://opensource.franz.com/preamble.html
17
18
19;; This file matches "ccl:pmcl;constants.h" & "ccl:pmcl;constants.s"
20
21(defpackage "PPC32"
22 (:use "CL")
23 #+ppc32-target
24 (:nicknames "TARGET"))
25
26(in-package "PPC32")
27
28(eval-when (:compile-toplevel :load-toplevel :execute)
29 (require "PPC-ARCH")
30
31
32(defmacro define-storage-layout (name origin &rest cells)
33 `(progn
34 (ccl::defenum (:start ,origin :step 4)
35 ,@(mapcar #'(lambda (cell) (ccl::form-symbol name "." cell)) cells))
36 (defconstant ,(ccl::form-symbol name ".SIZE") ,(* (length cells) 4))))
37
38(defmacro define-lisp-object (name tagname &rest cells)
39 `(define-storage-layout ,name ,(- (symbol-value tagname)) ,@cells))
40
41(defmacro define-subtag (name tag subtag)
42 `(defconstant ,(ccl::form-symbol "SUBTAG-" name) (logior ,tag (ash ,subtag ntagbits))))
43
44
45(defmacro define-imm-subtag (name subtag)
46 `(define-subtag ,name fulltag-immheader ,subtag))
47
48(defmacro define-node-subtag (name subtag)
49 `(define-subtag ,name fulltag-nodeheader ,subtag))
50
51(defmacro define-fixedsized-object (name &rest non-header-cells)
52 `(progn
53 (define-lisp-object ,name fulltag-misc header ,@non-header-cells)
54 (ccl::defenum ()
55 ,@(mapcar #'(lambda (cell) (ccl::form-symbol name "." cell "-CELL")) non-header-cells))
56 (defconstant ,(ccl::form-symbol name ".ELEMENT-COUNT") ,(length non-header-cells))))
57
58
59)
60
61(eval-when (:compile-toplevel :load-toplevel :execute)
62(defconstant rcontext 13)
63(defconstant nbits-in-word 32)
64(defconstant least-significant-bit 31)
65(defconstant nbits-in-byte 8)
66(defconstant ntagbits 3) ; But non-header objects only use 2
67(defconstant nlisptagbits 2)
68(defconstant nfixnumtagbits 2) ; See ?
69(defconstant num-subtag-bits 8) ; tag part of header is 8 bits wide
70(defconstant fixnumshift nfixnumtagbits)
71(defconstant fixnum-shift fixnumshift) ; A pet name for it.
72(defconstant fulltagmask (1- (ash 1 ntagbits))) ; Only needed by GC/very low-level code
73(defconstant full-tag-mask fulltagmask)
74(defconstant tagmask (1- (ash 1 nlisptagbits)))
75(defconstant tag-mask tagmask)
76(defconstant fixnummask (1- (ash 1 nfixnumtagbits)))
77(defconstant fixnum-mask fixnummask)
78(defconstant subtag-mask (1- (ash 1 num-subtag-bits)))
79(defconstant ncharcodebits 24) ; only the low 8 bits are used, currently
80(defconstant charcode-shift (- nbits-in-word ncharcodebits))
81(defconstant word-shift 2)
82(defconstant word-size-in-bytes 4)
83(defconstant node-size 4)
84(defconstant dnode-size 8)
85(defconstant dnode-align-bits 3)
86(defconstant dnode-shift dnode-align-bits)
87(defconstant bitmap-shift 5)
88
89(defconstant target-most-negative-fixnum (ash -1 (1- (- nbits-in-word nfixnumtagbits))))
90(defconstant target-most-positive-fixnum (1- (ash 1 (1- (- nbits-in-word nfixnumtagbits)))))
91
92;; PPC-32 stuff and tags.
93
94;; Tags.
95;; There are two-bit tags and three-bit tags.
96;; A FULLTAG is the value of the low three bits of a tagged object.
97;; A TAG is the value of the low two bits of a tagged object.
98;; A TYPECODE is either a TAG or the value of a "tag-misc" object's header-byte.
99
100;; There are 4 primary TAG values. Any object which lisp can "see" can be classified
101;; by its TAG. (Some headers have FULLTAGS that are congruent modulo 4 with the
102;; TAGS of other objects, but lisp can't "see" headers.)
103(ccl::defenum ()
104 tag-fixnum ; All fixnums, whether odd or even
105 tag-list ; Conses and NIL
106 tag-misc ; Heap-consed objects other than lists: vectors, symbols, functions, floats ...
107 tag-imm ; Immediate-objects: characters, UNBOUND, other markers.
108)
109
110;;; And there are 8 FULLTAG values. Note that NIL has its own FULLTAG (congruent mod 4 to tag-list),
111;;; that FULLTAG-MISC is > 4 (so that code-vector entry-points can be branched to, since the low
112;;; two bits of the PC are ignored) and that both FULLTAG-MISC and FULLTAG-IMM have header fulltags
113;;; that share the same TAG.
114;;; Things that walk memory (and the stack) have to be careful to look at the FULLTAG of each
115;;; object that they see.
116(ccl::defenum ()
117 fulltag-even-fixnum ; I suppose EVENP/ODDP might care; nothing else does.
118 fulltag-cons ; a real (non-null) cons. Shares TAG with fulltag-nil.
119 fulltag-nodeheader ; Header of heap-allocated object that contains lisp-object pointers
120 fulltag-imm ; a "real" immediate object. Shares TAG with fulltag-immheader.
121 fulltag-odd-fixnum ;
122 fulltag-nil ; NIL and nothing but. (Note that there's still a hidden NILSYM.)
123 fulltag-misc ; Pointer "real" tag-misc object. Shares TAG with fulltag-nodeheader.
124 fulltag-immheader ; Header of heap-allocated object that contains unboxed data.
125)
126
127(defconstant misc-header-offset (- fulltag-misc))
128(defconstant misc-subtag-offset (+ misc-header-offset 3))
129(defconstant misc-data-offset (+ misc-header-offset 4))
130(defconstant misc-dfloat-offset (+ misc-header-offset 8))
131
132
133
134
135
136
137(defconstant canonical-nil-value #x00003015)
138;;; T is almost adjacent to NIL: since NIL is a misaligned CONS, it spans
139;;; two doublewords. The arithmetic difference between T and NIL is
140;;; such that the least-significant bit and exactly one other bit is
141;;; set in the result.
142
143(defconstant t-offset (+ 8 (- 8 fulltag-nil) fulltag-misc))
144(assert (and (logbitp 0 t-offset) (= (logcount t-offset) 2)))
145
146;;; The order in which various header values are defined is significant in several ways:
147;;; 1) Numeric subtags precede non-numeric ones; there are further orderings among numeric subtags.
148;;; 2) All subtags which denote CL arrays are preceded by those that don't,
149;;; with a further ordering which requires that (< header-arrayH header-vectorH ,@all-other-CL-vector-types)
150;;; 3) The element-size of ivectors is determined by the ordering of ivector subtags.
151;;; 4) All subtags are >= fulltag-immheader .
152
153
154;;; Numeric subtags.
155(define-imm-subtag bignum 0)
156(defconstant min-numeric-subtag subtag-bignum)
157(define-node-subtag ratio 1)
158(defconstant max-rational-subtag subtag-ratio)
159
160(define-imm-subtag single-float 1) ; "SINGLE" float, aka short-float in the new order.
161(define-imm-subtag double-float 2)
162(defconstant min-float-subtag subtag-single-float)
163(defconstant max-float-subtag subtag-double-float)
164(defconstant max-real-subtag subtag-double-float)
165
166(define-node-subtag complex 3)
167(defconstant max-numeric-subtag subtag-complex)
168
169;;; CL array types. There are more immediate types than node types; all CL array subtags must be > than
170;;; all non-CL-array subtags. So we start by defining the immediate subtags in decreasing order, starting
171;;; with that subtag whose element size isn't an integral number of bits and ending with those whose
172;;; element size - like all non-CL-array fulltag-immheader types - is 32 bits.
173(define-imm-subtag bit-vector 31)
174(define-imm-subtag complex-double-float-vector 30)
175(define-imm-subtag complex-single-float-vector 29)
176(define-imm-subtag double-float-vector 28)
177(define-imm-subtag s16-vector 27)
178(define-imm-subtag u16-vector 26)
179(defconstant min-16-bit-ivector-subtag subtag-u16-vector)
180(defconstant max-16-bit-ivector-subtag subtag-s16-vector)
181
182(define-imm-subtag s8-vector 25)
183(define-imm-subtag u8-vector 24)
184(defconstant min-8-bit-ivector-subtag subtag-u8-vector)
185(defconstant max-8-bit-ivector-subtag subtag-s8-vector)
186
187(define-imm-subtag simple-base-string 23)
188(define-imm-subtag fixnum-vector 22)
189(define-imm-subtag s32-vector 21)
190(define-imm-subtag u32-vector 20)
191(define-imm-subtag single-float-vector 19)
192(defconstant max-32-bit-ivector-subtag subtag-simple-base-string)
193(defconstant min-cl-ivector-subtag subtag-single-float-vector)
194
195(define-node-subtag vectorH 30)
196(define-node-subtag arrayH 29)
197(define-node-subtag simple-vector 31) ; Only one such subtag
198(assert (< subtag-arrayH subtag-vectorH subtag-simple-vector))
199
200
201;;; So, we get the remaining subtags (n: (n > max-numeric-subtag) & (n < min-array-subtag))
202;;; for various immediate/node object types.
203
204(define-imm-subtag macptr 3)
205(defconstant min-non-numeric-imm-subtag subtag-macptr)
206(assert (> min-non-numeric-imm-subtag max-numeric-subtag))
207(define-imm-subtag dead-macptr 4)
208(define-imm-subtag code-vector 5)
209(define-imm-subtag creole-object 6)
210(define-imm-subtag xcode-vector 7) ; code-vector for cross-development
211(define-imm-subtag complex-single-float 8)
212(define-imm-subtag complex-double-float 9)
213
214
215(defconstant max-non-array-imm-subtag (logior (ash 19 ntagbits) fulltag-immheader))
216
217(define-node-subtag catch-frame 4)
218(defconstant min-non-numeric-node-subtag subtag-catch-frame)
219(assert (> min-non-numeric-node-subtag max-numeric-subtag))
220(define-node-subtag function 5)
221(define-node-subtag basic-stream 6)
222(define-node-subtag symbol 7)
223(define-node-subtag lock 8)
224(define-node-subtag hash-vector 9)
225(define-node-subtag pool 10)
226(define-node-subtag weak 11)
227(define-node-subtag package 12)
228(define-node-subtag slot-vector 13)
229(define-node-subtag instance 14)
230(define-node-subtag struct 15)
231(define-node-subtag istruct 16)
232(define-node-subtag value-cell 17)
233(define-node-subtag xfunction 18) ; Function for cross-development
234(defconstant max-non-array-node-subtag (logior (ash 18 ntagbits) fulltag-nodeheader))
235
236(define-subtag character fulltag-imm 9)
237(define-subtag vsp-protect fulltag-imm 7)
238(define-subtag slot-unbound fulltag-imm 10)
239(defconstant slot-unbound-marker subtag-slot-unbound)
240(define-subtag illegal fulltag-imm 11)
241(defconstant illegal-marker subtag-illegal)
242(define-subtag go-tag fulltag-imm 12)
243(define-subtag block-tag fulltag-imm 24)
244(define-subtag no-thread-local-binding fulltag-imm 30)
245(define-subtag unbound fulltag-imm 6)
246(defconstant unbound-marker subtag-unbound)
247(defconstant undefined unbound-marker)
248
249
250(defconstant max-64-bit-constant-index (ash (+ #x7fff ppc32::misc-dfloat-offset) -3))
251(defconstant max-32-bit-constant-index (ash (+ #x7fff ppc32::misc-data-offset) -2))
252(defconstant max-16-bit-constant-index (ash (+ #x7fff ppc32::misc-data-offset) -1))
253(defconstant max-8-bit-constant-index (+ #x7fff ppc32::misc-data-offset))
254(defconstant max-1-bit-constant-index (ash (+ #x7fff ppc32::misc-data-offset) 5))
255
256
257;;; The objects themselves look something like this:
258
259;;; Order of CAR and CDR doesn't seem to matter much - there aren't
260;;; too many tricks to be played with predecrement/preincrement addressing.
261;;; Keep them in the confusing MCL 3.0 order, to avoid confusion.
262(define-lisp-object cons tag-list
263 cdr
264 car)
265
266
267(define-fixedsized-object ratio
268 numer
269 denom)
270
271(define-fixedsized-object single-float
272 value)
273
274(define-fixedsized-object double-float
275 pad
276 value
277 val-low)
278
279(define-fixedsized-object complex-single-float
280 pad
281 realpart
282 imagpart)
283
284(define-fixedsized-object complex-double-float
285 pad
286 realpart-high
287 realpart-low
288 imagpart-high
289 imagpart-low)
290
291(defconstant complex-double-float.realpart complex-double-float.realpart-high)
292(defconstant complex-double-float.imagpart complex-double-float.imagpart-high)
293
294(define-fixedsized-object complex
295 realpart
296 imagpart
297)
298
299
300;;; There are two kinds of macptr; use the length field of the header if you
301;;; need to distinguish between them
302(define-fixedsized-object macptr
303 address
304 domain
305 type
306)
307
308(define-fixedsized-object xmacptr
309 address
310 domain
311 type
312 flags
313 link
314)
315
316;;; Catch frames go on the tstack; they point to a minimal lisp-frame
317;;; on the cstack. (The catch/unwind-protect PC is on the cstack, where
318;;; the GC expects to find it.)
319(define-fixedsized-object catch-frame
320 catch-tag ; #<unbound> -> unwind-protect, else catch
321 link ; tagged pointer to next older catch frame
322 mvflag ; 0 if single-value, 1 if uwp or multiple-value
323 csp ; pointer to control stack
324 db-link ; value of dynamic-binding link on thread entry.
325 save-save7 ; saved registers
326 save-save6
327 save-save5
328 save-save4
329 save-save3
330 save-save2
331 save-save1
332 save-save0
333 xframe ; exception-frame link
334 nfp
335)
336
337(define-fixedsized-object lock
338 _value ;finalizable pointer to kernel object
339 kind ; '0 = recursive-lock, '1 = rwlock
340 writer ;tcr of owning thread or 0
341 name
342 whostate
343 whostate-2
344 )
345
346
347
348(define-fixedsized-object symbol
349 pname
350 vcell
351 fcell
352 package-predicate
353 flags
354 plist
355 binding-index
356)
357
358
359
360(defconstant nilsym-offset (+ t-offset symbol.size))
361
362
363(define-fixedsized-object vectorH
364 logsize ; fillpointer if it has one, physsize otherwise
365 physsize ; total size of (possibly displaced) data vector
366 data-vector ; object this header describes
367 displacement ; true displacement or 0
368 flags ; has-fill-pointer,displaced-to,adjustable bits; subtype of underlying simple vector.
369)
370
371(define-lisp-object arrayH fulltag-misc
372 header ; subtag = subtag-arrayH
373 rank ; NEVER 1
374 physsize ; total size of (possibly displaced) data vector
375 data-vector ; object this header describes
376 displacement ; true displacement or 0
377 flags ; has-fill-pointer,displaced-to,adjustable bits; subtype of underlying simple vector.
378 ;; Dimensions follow
379)
380
381(defconstant arrayH.rank-cell 0)
382(defconstant arrayH.physsize-cell 1)
383(defconstant arrayH.data-vector-cell 2)
384(defconstant arrayH.displacement-cell 3)
385(defconstant arrayH.flags-cell 4)
386(defconstant arrayH.dim0-cell 5)
387
388(defconstant arrayH.flags-cell-bits-byte (byte 8 0))
389(defconstant arrayH.flags-cell-subtag-byte (byte 8 8))
390
391
392(define-fixedsized-object value-cell
393 value)
394
395;;; The kernel uses these (rather generically named) structures
396;;; to keep track of various memory regions it (or the lisp) is
397;;; interested in.
398;;; The gc-area record definition in "ccl:interfaces;mcl-records.lisp"
399;;; matches this.
400
401(define-storage-layout area 0
402 pred ; pointer to preceding area in DLL
403 succ ; pointer to next area in DLL
404 low ; low bound on area addresses
405 high ; high bound on area addresses.
406 active ; low limit on stacks, high limit on heaps
407 softlimit ; overflow bound
408 hardlimit ; another one
409 code ; an area-code; see below
410 markbits ; bit vector for GC
411 ndnodes ; "active" size of dynamic area or stack
412 older ; in EGC sense
413 younger ; also for EGC
414 h ; Handle or null pointer
415 softprot ; protected_area structure pointer
416 hardprot ; another one.
417 owner ; fragment (library) which "owns" the area
418 refbits ; bitvector for intergenerational refernces
419 threshold ; for egc
420 gc-count ; generational gc count.
421 static-dnodes ; for honsing, etc.
422 static-used ; bitvector
423)
424
425
426(define-storage-layout protected-area 0
427 next
428 start ; first byte (page-aligned) that might be protected
429 end ; last byte (page-aligned) that could be protected
430 nprot ; Might be 0
431 protsize ; number of bytes to protect
432 why)
433
434(defconstant tcr-bias 0)
435
436(define-storage-layout tcr (- tcr-bias)
437 prev ; in doubly-linked list
438 next ; in doubly-linked list
439 lisp-fpscr-high
440 lisp-fpscr-low
441 db-link ; special binding chain head
442 catch-top ; top catch frame
443 save-vsp ; VSP when in foreign code
444 save-tsp ; TSP when in foreign code
445 cs-area ; cstack area pointer
446 vs-area ; vstack area pointer
447 ts-area ; tstack area pointer
448 cs-limit ; cstack overflow limit
449 total-bytes-allocated-high
450 total-bytes-allocated-low
451 log2-allocation-quantum ; unboxed
452 interrupt-pending ; fixnum
453 xframe ; exception frame linked list
454 errno-loc ; thread-private, maybe
455 ffi-exception ; fpscr bits from ff-call.
456 osid ; OS thread id
457 valence ; odd when in foreign code
458 foreign-exception-status
459 native-thread-info
460 native-thread-id
461 last-allocptr
462 save-allocptr
463 save-allocbase
464 reset-completion
465 activate
466 suspend-count
467 suspend-context
468 pending-exception-context
469 suspend ; semaphore for suspension notify
470 resume ; sempahore for resumption notify
471 flags ; foreign, being reset, ...
472 gc-context
473 termination-semaphore
474 unwinding
475 tlb-limit
476 tlb-pointer
477 shutdown-count
478 safe-ref-address
479 nfp
480)
481
482(defconstant interrupt-level-binding-index (ash 1 fixnumshift))
483
484(define-storage-layout lockptr 0
485 avail
486 owner
487 count
488 signal
489 waiting
490 malloced-ptr
491 spinlock)
492
493(define-storage-layout rwlock 0
494 spin
495 state
496 blocked-writers
497 blocked-readers
498 writer
499 reader-signal
500 writer-signal
501 malloced-ptr
502 )
503
504;;; For the eabi port: mark this stack frame as Lisp's (since EABI
505;;; foreign frames can be the same size as a lisp frame.)
506
507
508(ppc32::define-storage-layout lisp-frame 0
509 backlink
510 savefn
511 savelr
512 savevsp
513)
514
515(ppc32::define-storage-layout c-frame 0
516 backlink
517 crsave
518 savelr
519 unused-1
520 unused-2
521 savetoc
522 param0
523 param1
524 param2
525 param3
526 param4
527 param5
528 param6
529 param7
530)
531
532(defconstant c-frame.minsize c-frame.size)
533
534;;; .SPeabi-ff-call "shrinks" this frame after loading the GPRs.
535(ppc32::define-storage-layout eabi-c-frame 0
536 backlink
537 savelr
538 param0
539 param1
540 param2
541 param3
542 param4
543 param5
544 param6
545 param7
546)
547
548(defconstant eabi-c-frame.minsize eabi-c-frame.size)
549
550(defmacro define-header (name element-count subtag)
551 `(defconstant ,name (logior (ash ,element-count num-subtag-bits) ,subtag)))
552
553(define-header single-float-header single-float.element-count subtag-single-float)
554(define-header double-float-header double-float.element-count subtag-double-float)
555(define-header one-digit-bignum-header 1 subtag-bignum)
556(define-header two-digit-bignum-header 2 subtag-bignum)
557(define-header three-digit-bignum-header 3 subtag-bignum)
558(define-header symbol-header symbol.element-count subtag-symbol)
559(define-header value-cell-header value-cell.element-count subtag-value-cell)
560(define-header macptr-header macptr.element-count subtag-macptr)
561
562
563
564)
565
566
567
568
569(defun %kernel-global (sym)
570 (let* ((pos (position sym ppc::*ppc-kernel-globals* :test #'string=)))
571 (if pos
572 (- (+ fulltag-nil (* (1+ pos) 4)))
573 (error "Unknown kernel global : ~s ." sym))))
574
575(defmacro kernel-global (sym)
576 (let* ((pos (position sym ppc::*ppc-kernel-globals* :test #'string=)))
577 (if pos
578 (- (+ fulltag-nil (* (1+ pos) 4)))
579 (error "Unknown kernel global : ~s ." sym))))
580
581;;; The kernel imports things that are defined in various other
582;;; libraries for us. The objects in question are generally
583;;; fixnum-tagged; the entries in the "kernel-imports" vector are 4
584;;; bytes apart.
585(ccl::defenum (:prefix "KERNEL-IMPORT-" :start 0 :step 4)
586 fd-setsize-bytes
587 do-fd-set
588 do-fd-clr
589 do-fd-is-set
590 do-fd-zero
591 MakeDataExecutable
592 GetSharedLibrary
593 FindSymbol
594 malloc
595 free
596 wait-for-signal
597 tcr-frame-ptr
598 register-xmacptr-dispose-function
599 open-debug-output
600 get-r-debug
601 restore-soft-stack-limit
602 egc-control
603 lisp-bug
604 NewThread
605 YieldToThread
606 DisposeThread
607 ThreadCurrentStackSpace
608 usage-exit
609 save-fp-context
610 restore-fp-context
611 put-altivec-registers
612 get-altivec-registers
613 new-semaphore
614 wait-on-semaphore
615 signal-semaphore
616 destroy-semaphore
617 new-recursive-lock
618 lock-recursive-lock
619 unlock-recursive-lock
620 destroy-recursive-lock
621 suspend-other-threads
622 resume-other-threads
623 suspend-tcr
624 resume-tcr
625 rwlock-new
626 rwlock-destroy
627 rwlock-rlock
628 rwlock-wlock
629 rwlock-unlock
630 recursive-lock-trylock
631 foreign-name-and-offset
632 lisp-read
633 lisp-write
634 lisp-open
635 lisp-fchmod
636 lisp-lseek
637 lisp-close
638 lisp-ftruncate
639 lisp-stat
640 lisp-fstat
641 lisp-futex
642 lisp-opendir
643 lisp-readdir
644 lisp-closedir
645 lisp-pipe
646 lisp-gettimeofday
647 lisp-sigexit
648 jvm-init
649)
650
651(defmacro nrs-offset (name)
652 (let* ((pos (position name ppc::*ppc-nilreg-relative-symbols* :test #'eq)))
653 (if pos (+ t-offset (* pos symbol.size)))))
654
655
656(defconstant reservation-discharge #x2004)
657
658
659
660(defmacro with-stack-short-floats (specs &body body)
661 (ccl::collect ((binds)
662 (inits)
663 (names))
664 (dolist (spec specs)
665 (let ((name (first spec)))
666 (binds `(,name (ccl::%make-sfloat)))
667 (names name)
668 (let ((init (second spec)))
669 (when init
670 (inits `(ccl::%short-float ,init ,name))))))
671 `(let* ,(binds)
672 (declare (dynamic-extent ,@(names))
673 (short-float ,@(names)))
674 ,@(inits)
675 ,@body)))
676
677(defparameter *ppc32-target-uvector-subtags*
678 `((:bignum . ,subtag-bignum)
679 (:ratio . ,subtag-ratio)
680 (:single-float . ,subtag-single-float)
681 (:double-float . ,subtag-double-float)
682 (:complex . ,subtag-complex )
683 (:complex-single-float . ,subtag-complex-single-float)
684 (:complex-double-float . ,subtag-complex-double-float)
685 (:symbol . ,subtag-symbol)
686 (:function . ,subtag-function )
687 (:code-vector . ,subtag-code-vector)
688 (:xcode-vector . ,subtag-xcode-vector)
689 (:macptr . ,subtag-macptr )
690 (:catch-frame . ,subtag-catch-frame)
691 (:struct . ,subtag-struct )
692 (:istruct . ,subtag-istruct )
693 (:pool . ,subtag-pool )
694 (:population . ,subtag-weak )
695 (:hash-vector . ,subtag-hash-vector )
696 (:package . ,subtag-package )
697 (:value-cell . ,subtag-value-cell)
698 (:instance . ,subtag-instance )
699 (:lock . ,subtag-lock )
700 (:slot-vector . ,subtag-slot-vector)
701 (:basic-stream . ,subtag-basic-stream)
702 (:simple-string . ,subtag-simple-base-string )
703 (:bit-vector . ,subtag-bit-vector )
704 (:signed-8-bit-vector . ,subtag-s8-vector )
705 (:unsigned-8-bit-vector . ,subtag-u8-vector )
706 (:signed-16-bit-vector . ,subtag-s16-vector )
707 (:unsigned-16-bit-vector . ,subtag-u16-vector )
708 (:signed-32-bit-vector . ,subtag-s32-vector )
709 (:fixnum-vector . ,subtag-fixnum-vector)
710 (:unsigned-32-bit-vector . ,subtag-u32-vector )
711 (:single-float-vector . ,subtag-single-float-vector)
712 (:double-float-vector . ,subtag-double-float-vector )
713 (:complex-single-float-vector . ,subtag-complex-single-float-vector)
714 (:complex-double-float-vector . ,subtag-complex-double-float-vector)
715 (:simple-vector . ,subtag-simple-vector )
716 (:vector-header . ,subtag-vectorH)
717 (:array-header . ,subtag-arrayH)
718 (:min-cl-ivector-subtag ,.min-cl-ivector-subtag)))
719
720
721;;; This should return NIL unless it's sure of how the indicated
722;;; type would be represented (in particular, it should return
723;;; NIL if the element type is unknown or unspecified at compile-time.
724(defun ppc32-array-type-name-from-ctype (ctype)
725 (when (typep ctype 'ccl::array-ctype)
726 (let* ((element-type (ccl::array-ctype-element-type ctype)))
727 (typecase element-type
728 (ccl::class-ctype
729 (let* ((class (ccl::class-ctype-class element-type)))
730 (if (or (eq class ccl::*character-class*)
731 (eq class ccl::*base-char-class*)
732 (eq class ccl::*standard-char-class*))
733 :simple-string
734 :simple-vector)))
735 (ccl::numeric-ctype
736 (if (eq (ccl::numeric-ctype-complexp element-type) :complex)
737 (case (ccl::numeric-ctype-format element-type)
738 (single-float :complex-single-float-vector)
739 (double-float :complex-double-float-vector)
740 (t :simple-vector))
741 (case (ccl::numeric-ctype-class element-type)
742 (integer
743 (let* ((low (ccl::numeric-ctype-low element-type))
744 (high (ccl::numeric-ctype-high element-type)))
745 (cond ((or (null low) (null high)) :simple-vector)
746 ((and (>= low 0) (<= high 1) :bit-vector))
747 ((and (>= low 0) (<= high 255)) :unsigned-8-bit-vector)
748 ((and (>= low 0) (<= high 65535)) :unsigned-16-bit-vector)
749 ((and (>= low 0) (<= high #xffffffff) :unsigned-32-bit-vector))
750 ((and (>= low -128) (<= high 127)) :signed-8-bit-vector)
751 ((and (>= low -32768) (<= high 32767) :signed-16-bit-vector))
752 ((and (>= low target-most-negative-fixnum)
753 (<= high target-most-positive-fixnum))
754 :fixnum-vector)
755 ((and (>= low (ash -1 31)) (<= high (1- (ash 1 31))))
756 :signed-32-bit-vector)
757 (t :simple-vector))))
758 (float
759 (case (ccl::numeric-ctype-format element-type)
760 ((double-float long-float) :double-float-vector)
761 ((single-float short-float) :single-float-vector)
762 (t :simple-vector)))
763 (t :simple-vector))))
764 (ccl::unknown-ctype)
765 (ccl::named-ctype
766 (if (eq element-type ccl::*universal-type*)
767 :simple-vector))
768 (t nil)))))
769
770(defun ppc32-misc-byte-count (subtag element-count)
771 (declare (fixnum subtag))
772 (if (or (= fulltag-nodeheader (logand subtag fulltagmask))
773 (<= subtag max-32-bit-ivector-subtag))
774 (ash element-count 2)
775 (if (<= subtag max-8-bit-ivector-subtag)
776 element-count
777 (if (<= subtag max-16-bit-ivector-subtag)
778 (ash element-count 1)
779 (if (= subtag subtag-bit-vector)
780 (ash (+ element-count 7) -3)
781 (if (= subtag subtag-complex-double-float-vector)
782 (+ 4 (ash element-count 4))
783 (+ 4 (ash element-count 3))))))))
784
785(defparameter *ppc32-target-arch*
786 (arch::make-target-arch :name :ppc32
787 :lisp-node-size 4
788 :nil-value canonical-nil-value
789 :fixnum-shift fixnumshift
790 :most-positive-fixnum (1- (ash 1 (1- (- 32 fixnumshift))))
791 :most-negative-fixnum (- (ash 1 (1- (- 32 fixnumshift))))
792 :misc-data-offset misc-data-offset
793 :misc-dfloat-offset misc-dfloat-offset
794 :nbits-in-word 32
795 :ntagbits 3
796 :nlisptagbits 2
797 :uvector-subtags *ppc32-target-uvector-subtags*
798 :max-64-bit-constant-index max-64-bit-constant-index
799 :max-32-bit-constant-index max-32-bit-constant-index
800 :max-16-bit-constant-index max-16-bit-constant-index
801 :max-8-bit-constant-index max-8-bit-constant-index
802 :max-1-bit-constant-index max-1-bit-constant-index
803 :word-shift 2
804 :code-vector-prefix ()
805 :gvector-types '(:ratio :complex :symbol :function
806 :catch-frame :struct :istruct
807 :pool :population :hash-vector
808 :package :value-cell :instance
809 :lock :slot-vector
810 :simple-vector)
811 :1-bit-ivector-types '(:bit-vector)
812 :8-bit-ivector-types '(:signed-8-bit-vector
813 :unsigned-8-bit-vector)
814 :16-bit-ivector-types '(:signed-16-bit-vector
815 :unsigned-16-bit-vector)
816 :32-bit-ivector-types '(:signed-32-bit-vector
817 :unsigned-32-bit-vector
818 :single-float-vector
819 :fixnum-vector
820 :single-float
821 :double-float
822 :bignum
823 :simple-string)
824 :64-bit-ivector-types '(:double-float-vector
825 :complex-single-float-vector)
826 :array-type-name-from-ctype-function
827 #'ppc32-array-type-name-from-ctype
828 :package-name "PPC32"
829 :t-offset t-offset
830 :array-data-size-function #'ppc32-misc-byte-count
831 :fpr-mask-function 'ppc::fpr-mask
832 :subprims-base ppc::*ppc-subprims-base*
833 :subprims-shift ppc::*ppc-subprims-shift*
834 :subprims-table ppc::*ppc-subprims*
835 :primitive->subprims `(((0 . 23) . ,(ccl::%subprim-name->offset '.SPbuiltin-plus ppc::*ppc-subprims*)))
836 :unbound-marker-value unbound-marker
837 :slot-unbound-marker-value slot-unbound-marker
838 :fixnum-tag tag-fixnum
839 :single-float-tag subtag-single-float
840 :single-float-tag-is-subtag t
841 :double-float-tag subtag-double-float
842 :cons-tag fulltag-cons
843 :null-tag fulltag-nil
844 :symbol-tag subtag-symbol
845 :symbol-tag-is-subtag t
846 :function-tag subtag-function
847 :function-tag-is-subtag t
848 :big-endian t
849 :misc-subtag-offset misc-subtag-offset
850 :car-offset cons.car
851 :cdr-offset cons.cdr
852 :subtag-char subtag-character
853 :charcode-shift charcode-shift
854 :fulltagmask fulltagmask
855 :fulltag-misc fulltag-misc
856 :char-code-limit #x110000
857 ))
858
859;;; arch macros
860(defmacro defppc32archmacro (name lambda-list &body body)
861 `(arch::defarchmacro :ppc32 ,name ,lambda-list ,@body))
862
863(defppc32archmacro ccl::%make-sfloat ()
864 `(ccl::%alloc-misc ppc32::single-float.element-count ppc32::subtag-single-float))
865
866(defppc32archmacro ccl::%make-dfloat ()
867 `(ccl::%alloc-misc ppc32::double-float.element-count ppc32::subtag-double-float))
868
869(defppc32archmacro ccl::%numerator (x)
870 `(ccl::%svref ,x ppc32::ratio.numer-cell))
871
872(defppc32archmacro ccl::%denominator (x)
873 `(ccl::%svref ,x ppc32::ratio.denom-cell))
874
875(defppc32archmacro ccl::%realpart (x)
876 (let* ((thing (gensym)))
877 `(let* ((,thing ,x))
878 (case (ccl::typecode ,thing)
879 (#.ppc32::subtag-complex-single-float (ccl::%complex-single-float-realpart ,thing))
880 (#.ppc32::subtag-complex-double-float (ccl::%complex-double-float-realpart ,thing))
881 (t (ccl::%svref ,thing ppc32::complex.realpart-cell))))))
882
883(defppc32archmacro ccl::%imagpart (x)
884 (let* ((thing (gensym)))
885 `(let* ((,thing ,x))
886 (case (ccl::typecode ,thing)
887 (#.ppc32::subtag-complex-single-float (ccl::%complex-single-float-imagpart ,thing))
888 (#.ppc32::subtag-complex-double-float (ccl::%complex-double-float-imagpart ,thing))
889 (t (ccl::%svref ,thing ppc32::complex.realpart-cell))))))
890
891;;;
892(defppc32archmacro ccl::%get-single-float-from-double-ptr (ptr offset)
893 `(ccl::%double-float->short-float (ccl::%get-double-float ,ptr ,offset)
894 (ccl::%alloc-misc 1 ppc32::subtag-single-float)))
895
896(defppc32archmacro ccl::codevec-header-p (word)
897 `(eql ppc32::subtag-code-vector
898 (logand ,word ppc32::subtag-mask)))
899
900(defppc32archmacro ccl::immediate-p-macro (thing)
901 (let* ((tag (gensym)))
902 `(let* ((,tag (ccl::lisptag ,thing)))
903 (declare (fixnum ,tag))
904 (or (= ,tag ppc32::tag-fixnum)
905 (= ,tag ppc32::tag-imm)))))
906
907(defppc32archmacro ccl::hashed-by-identity (thing)
908 (let* ((typecode (gensym)))
909 `(let* ((,typecode (ccl::typecode ,thing)))
910 (declare (fixnum ,typecode))
911 (or
912 (= ,typecode ppc32::tag-fixnum)
913 (= ,typecode ppc32::tag-imm)
914 (= ,typecode ppc32::subtag-symbol)
915 (= ,typecode ppc32::subtag-instance)))))
916
917;;;
918(defppc32archmacro ccl::%get-kernel-global (name)
919 `(ccl::%fixnum-ref 0 (+ ,(ccl::target-nil-value)
920 ,(%kernel-global
921 (if (ccl::quoted-form-p name)
922 (cadr name)
923 name)))))
924
925(defppc32archmacro ccl::%get-kernel-global-ptr (name dest)
926 `(ccl::%setf-macptr
927 ,dest
928 (ccl::%fixnum-ref-macptr 0 (+ ,(ccl::target-nil-value)
929 ,(%kernel-global
930 (if (ccl::quoted-form-p name)
931 (cadr name)
932 name))))))
933
934(defppc32archmacro ccl::%target-kernel-global (name)
935 `(ppc32::%kernel-global ,name))
936
937(defppc32archmacro ccl::lfun-vector (fn)
938 fn)
939
940(defppc32archmacro ccl::lfun-vector-lfun (lfv)
941 lfv)
942
943(defppc32archmacro ccl::area-code ()
944 area.code)
945
946(defppc32archmacro ccl::area-succ ()
947 area.succ)
948
949(defppc32archmacro ccl::nth-immediate (f i)
950 `(ccl::%svref ,f ,i))
951
952(defppc32archmacro ccl::set-nth-immediate (f i new)
953 `(setf (ccl::%svref ,f ,i) ,new))
954
955(defppc32archmacro ccl::symptr->symvector (s)
956 s)
957
958(defppc32archmacro ccl::symvector->symptr (s)
959 s)
960
961(defppc32archmacro ccl::function-to-function-vector (f)
962 f)
963
964(defppc32archmacro ccl::function-vector-to-function (v)
965 v)
966
967(defppc32archmacro ccl::with-ffcall-results ((buf) &body body)
968 (let* ((size (+ (* 8 4) (* 31 8))))
969 `(%stack-block ((,buf ,size))
970 ,@body)))
971
972(defconstant arg-check-trap-pc-limit 8)
973;;
974(defconstant fasl-version #x60)
975(defconstant fasl-max-version #x60)
976(defconstant fasl-min-version #x60)
977(defparameter *image-abi-version* 1040)
978
979(provide "PPC32-ARCH")
Note: See TracBrowser for help on using the repository browser.