Re: [Q] svref vs. aref for fixnum arrays
Steve Haflich <[email protected]> Wed, 05 Apr 2006 11:42:49 -0700
| Newsgroups | gmane.lisp.allegro |
|---|---|
| Message-ID | <22579.1144262569@bach> |
From: Didier Verna <[email protected]> I notice an important performance difference between these two fixnum array implementations: 1/ simple-vector / svref 2/ simple-array / aref Note that in my test cases, the arrays don't contain anything else than fixnums, and the compiler is aware of that (no number comsing at all). Yet, the simple-vector method is faster. Your assertion that the compiler is aware of something is presented without any evidence. But you seem not to understand something about CL types: The type simple-vector is equivalent to (simple-array t (*)) The type simple-array is equivalent to (simple-array * *), and assuming that the compiler can infer the rank of the array from the nu8mber of arguments to aref, it is equivalent to (simple-array * (*)) The first of these specifies a particular array type with a known representational structure. In particular, the element-type is t. The second of these specifies all possible rank 1 arrays, including unspecialized arrays, various specialized byte arrays, complex-number arrays, strings, and even bit-vectors. (Each element of a bit-vector will necessarily be of type fixnum.) Is there an implementation difference between the two ? For instance, would fixnums be shifted in the simple-array version by any chance ? his is thw wrong question,. If you want compiled code not to have to determine the representational type iof an array at run time, you generally have to tell it the specific representational type at compile time. That declaration is implicit in the use of svref (because svref requires that the array argument be a simple-vector, which is a simple-array of rank 1 specialized to element-type t) but a mere simple-array declaration doesn't say anything about the specialization of element-type. See http://www.franz.com/support/documentation/8.0/doc/implementation.htm#data-types-1