3 (declare (simple-string s))
4 (declare (optimize (speed 3) (safety 0) (debug 0)))
7 (dotimes (i (length s))
8 (when (eql (aref s i) #\1)
12 * On X86 I is represented as a tagged integer.
15 3: SLOT S!11[EDX] {SB-C::VECTOR-LENGTH 1 7} => t23[EAX]
16 4: MOVE t23[EAX] => t24[EBX]
18 --------------------------------------------------------------------------------
21 (declare (optimize (speed 3) (safety 0) (space 2) (debug 0)))
22 (declare (type (simple-array double-float 1) v))
24 (declare (type double-float s))
25 (dotimes (i (length v))
26 (setq s (+ s (aref v i))))
29 * Python does not combine + with AREF, so generates extra move and
32 * On X86 Python thinks that all FP registers are directly accessible
33 and emits costy MOVE ... => FR1.
35 --------------------------------------------------------------------------------
38 (declare (optimize (speed 3) (safety 0) (space 2))
40 (let ((v (make-list n)))
41 (setq v (make-array n))
44 * IR1 does not optimize away (MAKE-LIST N).
45 --------------------------------------------------------------------------------
48 (declare (optimize (speed 3) (safety 0) (space 2))
49 (type (simple-array base-char 1) v1 v2))
50 (dotimes (i (length v1))
51 (setf (aref v2 i) (aref v1 i))))
53 VOP DATA-VECTOR-SET/SIMPLE-STRING V2!14[EDI] t32[EAX] t30[S2]>t33[CL]
55 MOV #<TN t33[CL]>, #<TN t30[S2]>
56 MOV BYTE PTR [EDI+EAX+1], #<TN t33[CL]>
57 MOV #<TN t35[AL]>, #<TN t33[CL]>
58 MOV #<TN t34[S2]>, #<TN t35[AL]>
60 * The value of DATA-VECTOR-SET is not used, so there is no need in the
64 --------------------------------------------------------------------------------
66 09:49:05 <jtra> I have found a case in those where suboptimal code is
67 generate with nested loops, it might be moderately easy to fix that
69 http://www.bagley.org/~doug/shootout/bench/nestedloop/nestedloop.cmucl
70 09:50:30 <jtra> if you add declarations to dotimes, generated code is
71 almost optimal, but most inner loops run out of registers and use
72 memory location for iteration variable
74 ;;; -*- mode: lisp -*-
75 ;;; http://www.bagley.org/~doug/shootout/
76 ;;; from Friedrich Dominicus
79 (let ((n (parse-integer (or (car (last extensions:*command-line-strings*)) "1")))
83 (optimize (speed 3) (debug 0) (safety 0)))
92 --------------------------------------------------------------------------------
95 (declare (optimize (speed 3) (safety 0) (debug 0)))
96 (declare (type (double-float 0d0 1d0) d))
97 (loop for i fixnum from 1 to 5
98 for x1 double-float = (sin d) ;;; !!!
99 do (loop for j fixnum from 1 to 4
100 sum x1 double-float)))
102 Without the marked declaration Python will use boxed representation for X1.
104 This is equivalent to
108 ;; use of X as DOUBLE-FLOAT
111 The initial binding is effectless, and without it X is of type
112 DOUBLE-FLOAT. Unhopefully, IR1 does not optimize away effectless
113 SETs/bindings, and IR2 does not perform type inference.
114 --------------------------------------------------------------------------------
115 #9 "Multi-path constant folding"
117 (if (= (cond ((irgh x) 0)
124 This code could be optimized to
127 (cond ((irgh x) :yes)
130 --------------------------------------------------------------------------------
132 (inverted variant of #9)
135 (let ((y (sap-alien x c-string)))
139 It could be optimized to
141 (lambda (x) (list x x))
143 (if Y were used only once, the current compiler would optimize it)
144 --------------------------------------------------------------------------------
146 (typep (truly-the (simple-array * (*)) x) 'simple-vector)
149 --------------------------------------------------------------------------------
151 FAST-+/FIXNUM and similar should accept unboxed arguments in interests
152 of representation selection. Problem: inter-TN dependencies.
153 --------------------------------------------------------------------------------
155 The derived type of (/ (THE (DOUBLE-FLOAT (0D0)) X) (THE (DOUBLE-FLOAT
156 1D0) Y)) is (DOUBLE-FLOAT 0.0d0). While it might be reasonable, it is
157 better to derive (OR (MEMBER 0.0d0) (DOUBLE-FLOAT (0.0d0))).
158 --------------------------------------------------------------------------------
160 On the alpha, the system is reluctant to refer directly to a constant bignum,
161 preferring to load a large constant through a slow sequence of instructions,
162 then cons up a bignum for it:
165 (DECLARE (OPTIMIZE (SAFETY 1) (SPEED 3) (DEBUG 1))
166 (TYPE (INTEGER -10000 10000) A)
169 ((89 125 16) (ASH A (MIN 18 -706)))
170 (T (DPB -3 (BYTE 30 30) -1))))
171 --------------------------------------------------------------------------------
174 ((= i (the (integer 0 100) n)))
177 It is commonly expected for Python to derive (FIXNUMP I). (If ``='' is
178 replaced with ``>='', Python will do.)
179 --------------------------------------------------------------------------------