I'm trying to get more speed out of a little quadratic solver by using optimizations and fixnums. Here's my code:
1: (defun solve-x (d)
2: (declare (optimize (speed 3))
3: (type fixnum d))
4: (let ((x 1) (y 1))
5: (declare (type fixnum x y))
6: (loop while (/= (- (* x x) (* d y y)) 1) do
7: (if (> (- (* x x) (* d y y)) 1)
8: (incf y)
9: (incf x)))
10: (list x y)))
The SBCL compiler seems to have trouble optimizing lines 6 and 7 correctly. I'm getting lots of warnings like this one:
forced to do GENERIC-- (cost 10)
unable to do inline fixnum arithmetic (cost 2) because:
The first argument is a (INTEGER 1 21267647932558653957237540927630737409), not a FIXNUM.
The second argument is a (INTEGER
-98079714615416886892398913872502479823289163909206900736
98079714615416886871131265939943825866051622981576163327), not a FIXNUM.
The result is a (VALUES
(INTEGER
-98079714615416886871131265939943825866051622981576163326
98079714615416886913666561805061133780526704836837638145)
&OPTIONAL), not a (VALUES FIXNUM &REST T).
unable to do inline (signed-byte 64) arithmetic (cost 5) because:
The first argument is a (INTEGER 1 21267647932558653957237540927630737409), not a (SIGNED-BYTE
64).
The second argument is a (INTEGER
-98079714615416886892398913872502479823289163909206900736
98079714615416886871131265939943825866051622981576163327), not a (SIGNED-BYTE
64).
The result is a (VALUES
(INTEGER
-98079714615416886871131265939943825866051622981576163326
98079714615416886913666561805061133780526704836837638145)
&OPTIONAL), not a (VALUES (SIGNED-BYTE 64) &REST T).
etc.
Don't know, where to continue. I already tried to insert 'the fixnum' around multiplications, divisions and subtractions, but it only got worse.
Any ideas, how to make this fast?