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

Re: Simpe Gwydion question



In article <bruce-A23476.13132313072002@copper.ipg.tsnz.net>,
 Bruce Hoult <bruce@hoult.org> wrote:

> In article <bruce-103AB8.11061913072002@copper.ipg.tsnz.net>,
>  Bruce Hoult <bruce@hoult.org> wrote:
> 
> > Unfortunately, all three of the operations here are going through full 
> > generic function dispatch.  You've done everything right, but we could 
> > do a bit more work on this part of d2c.  We only got support for limited 
> > vectors into the compiler at all a couple of versions ago and at the 
> > moment it works, but is only optimized for some data types.
> 
> I've got some good news for you.  I've just checked some modifications 
> into cvs for the compiler which implement unboxed vectors of doubles.  
> It took five lines of code :-)
> 
> 
> With one simple change your program now runs in 0.02 seconds instead of 
> 1.23 seconds.  After increasing the number of iterations from 100 to 
> 10,000 it takes 0.76 seconds.  So Dylan just got 160 times faster for 
> this type of program.
> 
> 
> Here is the Dylan and generated x86 machine code for vector-foo():
> 
> define function vector-foo(dvec :: <my-double-vector>) => ();
>    let n :: <integer> = dvec.size;
>    for (i :: <integer> from 0 below n)
>      dvec[i] := dvec[i] + 1.64;
>    end for;
> end vector-foo;

Oh, and this is just as fast:

define function vector-foo(dvec :: <my-double-vector>) => ();
   for (i from 0 below dvec.size)
     dvec[i] := dvec[i] + 1.64;
   end for;
end vector-foo;

Once the compiler knows for sure it has a fixed-size vector, it can 
figure out for itself that the size is an integer, and therefore so is 
the loop counter variable.

-- Bruce