[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Array Register Analog in MCL?



At 7:05 PM 5/14/95, Steve Hain wrote:
>I looked a little further into how to best optimize string references.
>The following macro:
>
>(defmacro fast-schar (string index)
>  `(locally
>     (declare (optimize (speed 3) (safety 0)))
>     (schar ,string ,index)))
>
>will result in a call to the $SP-%SCHAR subprimitive, which does know
>about fat (16-bit character) strings, but doesn't do bounds checking.
>I think that's as fast as you can get without using LAP code. There is
>also a $SP-%SET-SCHAR subprimitive, which you can get using the form:
>
>(defmacro fast-set-schar (string index char)
>  `(locally
>     (declare (optimize (speed 3) (safety 0)))
>     (setf (schar ,string ,index) ,char)))
>
>Hope these help; it would be interesting to see timing test results
>from them.

Steve is using MCL 3.0, which has 2-byte characters. You are likely
using MCL 2.0.1, which has only 1-byte characters. The following
generates in-inline code in MCL 2.0:

(in-package :ccl)

(export faster-schar)

(declaim (inline faster-schar (setf faster-schar)))

(defun faster-schar (string index)
  (declare (type simple-base-string string)
           (optimize (speed 3) (safety 0)))
  (schar string index))

(defun (setf faster-schar) (value string index)
  (declare (type simple-base-string string)
           (optimize (speed 3) (safety 0)))
  (setf (%schar string index) value))

In MCL 3.0, the code above for (setf faster-schar) goes out of line
(a bug?). Instead, you need to say:

(defun (setf faster-schar) (value string index)
  (declare (type simple-base-string string)
           (optimize (speed 3) (safety 0)))
  (setf (schar string index) value))