Re: optimizing simple-arrays
- From: Adam Warner <usenet@xxxxxxxxxxxxxxxxx>
- Date: Wed, 06 Apr 2005 13:33:55 +1200
On Wed, 06 Apr 2005 13:11:53 +1200, Adam Warner wrote:
> The problem is that you are evaluating the initial contents at run time.
> So you would need to build a sequence at run time to pass to
> :INITIAL-CONTENTS. You'd actually build two sequences and would be likely
> to generate more garbage. That's why it's better to just make the array
> and then fill each element in.
Here's another approach where one first builds a sequence of the wrong
type and then coerces it to the correct type:
(coerce (vector (random 1f0) (random 1f0) (random 1f0))
'(simple-array single-float (*)))
While a Sufficiently Smart Compiler could transform this to code that
skips the initial generation of the type T vector, SBCL does not have such
a SSC (they're a mythical construct):
* (lambda ()
(declare (optimize (speed 3) (safety 0) (debug 0)))
(coerce (vector (random 1f0) (random 1f0) (random 1f0))\
'(simple-array single-float (*))))
; in: LAMBDA NIL
; (VECTOR (RANDOM 1.0) (RANDOM 1.0) (RANDOM 1.0))
; --> LET PROGN LET LOCALLY SETF SB-KERNEL:%SVSET SB-KERNEL:%ASET LET*
; --> SB-KERNEL:HAIRY-DATA-VECTOR-SET MULTIPLE-VALUE-BIND MULTIPLE-VALUE-CALL
; --> FUNCTION
; ==>
; (SB-KERNEL:DATA-VECTOR-SET ARRAY SB-INT:INDEX SB-C::NEW-VALUE)
;
; note: doing float to pointer coercion (cost 13), for:
; the second argument of DATA-VECTOR-SET/SIMPLE-VECTOR-C
;
; note: doing float to pointer coercion (cost 13), for:
; the second argument of DATA-VECTOR-SET/SIMPLE-VECTOR-C
;
; note: doing float to pointer coercion (cost 13), for:
; the second argument of DATA-VECTOR-SET/SIMPLE-VECTOR-C
; compilation unit finished
; printed 3 notes
#<FUNCTION (LAMBDA ()) {93062DD}>
The compiler notes indicate that the randomly generated single floats are
first assigned to the vector of type T. A disassembly will also confirm
the call to ALLOCATE-VECTOR.
Regards,
Adam
.
- Follow-Ups:
- Re: optimizing simple-arrays
- From: Duane Rettig
- Re: optimizing simple-arrays
- References:
- optimizing simple-arrays
- From: Dave Watson
- Re: optimizing simple-arrays
- From: Adam Warner
- Re: optimizing simple-arrays
- From: Dave Watson
- Re: optimizing simple-arrays
- From: Adam Warner
- optimizing simple-arrays
- Prev by Date: Re: optimizing simple-arrays
- Next by Date: Any snippets of avionics related Lisp?
- Previous by thread: Re: optimizing simple-arrays
- Next by thread: Re: optimizing simple-arrays
- Index(es):
Relevant Pages
|