4ff2127cc6a95456efdf64746d922a4f4e153c80
[sbcl.git] / src / compiler / sparc / subprim.lisp
1 ;;;; linkage information for standard static functions, and random vops
2
3 ;;;; This software is part of the SBCL system. See the README file for
4 ;;;; more information.
5 ;;;;
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.
11
12 (in-package "SB!VM")
13 \f
14 ;;;; LENGTH
15 (define-vop (length/list)
16   (:translate length)
17   (:args (object :scs (descriptor-reg) :target ptr))
18   (:arg-types list)
19   (:temporary (:scs (descriptor-reg) :from (:argument 0)) ptr)
20   (:temporary (:scs (non-descriptor-reg)) temp)
21   (:temporary (:scs (any-reg) :type fixnum :to (:result 0) :target result)
22               count)
23   (:results (result :scs (any-reg descriptor-reg)))
24   (:policy :fast-safe)
25   (:vop-var vop)
26   (:save-p :compute-only)
27   (:generator 50
28     (let ((done (gen-label))
29           (loop (gen-label))
30           (not-list (generate-cerror-code vop object-not-list-error object)))
31       (move ptr object)
32       (move count zero-tn)
33
34       (emit-label loop)
35
36       (inst cmp ptr null-tn)
37       (inst b :eq done)
38       (inst nop)
39
40       (test-type ptr temp not-list t list-pointer-lowtag)
41
42       (loadw ptr ptr cons-cdr-slot list-pointer-lowtag)
43       (inst add count count (fixnumize 1))
44       (test-type ptr temp loop nil list-pointer-lowtag)
45
46       (cerror-call vop done object-not-list-error ptr)
47
48       (emit-label done)
49       (move result count))))
50        
51
52 (define-static-fun length (object) :translate length)
53