Re: floating point code without consing?
Unable to parse email body. Email id is 200
Unable to parse email body. Email id is 200
Am Son, 2002-03-17 um 19.40 schrieb Barry Wilkes: > > Just to be clear, the following syntax 'works' (ie, is accepted by the LW > compiler) : > <snip> > (loop for alpha fixnum from 0 to conf > sum (the short-float (* (aref m1 i alpha) (aref m2 alpha j))) > into acc of-type short-float finally (return (the short-float acc))) > <snip> > > - note the use of the 'of-type' keyword. However, this still doesn't get rid of the > consing. LW has a optimize declaration which is named "float". Setting it to 0 can lead to dramatic speedups with floating point code. Another declaration many do not know is "fixnum-safety" (be careful with that!) ciao, Jochen
Jochen Schmidt <jsc@dataheaven.de> writes: > > LW has a optimize declaration which is named "float". Setting it to 0 > can lead to dramatic speedups with floating point code. I did discover this by searching on Google groups : http://groups.google.com/groups?hl=en&ie=ISO-8859-1&oe=ISO-8859-1&threadm=357c3188.3987049031%40newshost&rnum=1&prev=/groups%3Fq%3DLispworks%2B%252B%2Bfloating%2Bpoint%2B%2Bgroup:comp.lang.lisp%26hl%3Den%26ie%3DISO-8859-1%26oe%3DISO-8859-1%26selm%3D357c3188.3987049031%2540newshost%26rnum%3D1 Sadly, I think that the problem I am seeing is that the 'future PC release with floating point optimization' never happened. Hopefully, someone from Xanalys will give the definitive answer. I cannot even stop the following from consing : (defun testing (a b c) (declare (type short-float a b c) (optimize (speed 3) (safety 0) (float 0) (debug 0))) (setf a (the short-float (+ b c )))) It seems as though *all* arithmetic operations (+ * /) cons when used with floating point types on both the Linux and Windows versions of LispWorks 4.2. I specifically tried short-float as the type based on the following which I also Googled up : http://groups.google.com/groups?q=Lispworks+%2B+short-float+%2B+unboxed+group:comp.lang.lisp&hl=en&ie=ISO-8859-1&oe=ISO-8859-1&selm=LGM.94Mar9091703%40polaris.flw.att.com&rnum=1 This seemed to suggest that LispWorks supported 'unboxed' short-floats. Unfortunatly, I think the first message suggests that this applies to the 'UNIX' version, as distinct to the x86 (Linux and Windows) versions. Regards, Barry. -- If in the last few years you haven't discarded a major opinion or acquired a new one, check your pulse. You may be dead. -- Gelett Burgess (1866-1951)
Unable to parse email body. Email id is 206
I'd just like to thank everyone who responded to my question - this was the first time I have attempted to do any real floating point optimisation of my code (well, that much must have been obvious), and I have learned a lot from you all. Thanks, Barry Wilkes. -- If in the last few years you haven't discarded a major opinion or acquired a new one, check your pulse. You may be dead. -- Gelett Burgess (1866-1951)
* Barry Wilkes wrote: > (defun testing (a b c) > (declare (type short-float a b c) > (optimize (speed 3) (safety 0) (float 0) (debug 0))) > (setf a (the short-float (+ b c )))) > It seems as though *all* arithmetic operations (+ * /) cons when > used with floating point types on both the Linux and Windows > versions of LispWorks 4.2. No, this isn't so. This does not cons: (defun float-mult (a b c) (declare (optimize speed (debug 0) (safety 0) (space 0) float) (type (simple-array short-float (*)) a b c)) (loop for i of-type fixnum from 0 below (length a) do (setf (aref c i) (* (aref a i) (aref b i))) finally (return c))) Anything that returns a float will almost certainly have to box at least the float it is returning I think, so in general you want to do float operations as array -> array operations so you can keep the floats unboxed inside the array, and pass in the result array (this is sort-of as if you are passing in a box which the function then modifies...). The only Lisp implementation I know which can, I think, avoid result consing is CMUCL if you block-compile things. I guess the equivalent case for LW would be if the function is completely local, when it might be able to know enough to not box. I don't really know anything about LW's compiler though and how seriously it tries to do this kind of thing (I couldn't get it to do SQRT without consing for instance, though I didn't try hard). --tim