patch, libfortran: Make spread more efficient

Thomas Koenig tkoenig@netcologne.de
Thu Mar 27 22:31:00 GMT 2008


Hello world,

here is another patch to make array intrinsics more efficient,
this time the spread intrinsic.  It is a straightforward
application of the principles of the earlier patche, with one
exception:  I wanted to get rid of the nested switch statements
for type and size, both for code clarity and execution speed
reasons, so I introduced macros to do the size and type decoding
for the relevant types with a single mask operation.  Once this
patch is in, I'll convert that handling in the other places
I touched previously.

Obviously, this patch doesn't use the ideas in PR 32512 (using
array descriptors to make things more efficient), but since
it touches spread, I thought I'd mention it in the ChangeLog
entry anyway.

Currently regtesting on i686-pc-linux-gnu.  I'll once again
ask Dominique crosscheck this on his system; he's found a few
problems with my earlier patches.

OK once the checks have passed?

	Thomas

Here's the speed gain for my system (for large arrays,
where this makes a bigger difference):

$ cat spread-speed.f90
program main
  real, dimension(1000) :: source
  real, dimension(1000,1000) :: target
  call random_number (source)
  do i=1,100
     target = spread(source,1,1000)
  end do
end program main
$ gfortran -static spread-speed.f90 && time ./a.out

real 0m0.774s
user 0m0.768s
sys 0m0.000s
$ gfortran-4.3 -static spread-speed.f90 && time ./a.out

real 0m1.946s
user 0m1.928s
sys 0m0.004s

2008-03-27  Thomas Koenig  <tkoenig@gcc.gnu.org>

PR libfortran/32972
PR libfortran/32512
* Makefile.am:  Add new variable, i_spread_c, containing
pack_i1.c, pack_i2.c, pack_i4.c, pack_i8.c, spread_i16.c,
spread_r4.c, spread_r8.c, spread_r10.c, spread_r16.c,
spread_c4.c, spread_c8.c, spread_c10.c, spread_c16.c.
* Makefile.in:  Regenerated.
* libgfortran.h:  Add prototypes for spread_i1, spread_i2,
spread_i4, spread_i8, spread_i16, spread_r4, spread_r8,
spread_c4, spread_c8, spread_c10, spread_c16,
spread_scalar_i1, spread_scalar_i2, spread_scalar_i4,
spread_scalar_i8, spread_scalar_i16, spread_scalar_r4
spread_scalar_r8, spread_scalar_c4, spread_scalar_c8,
spread_scalar_c10 and spread_scalar_c16.
Add macros to isolate both type and size information
from array descriptors with a single mask operation.
* intrinsics/spread_generic.c:  Add calls to specific
spread functions.
* m4/spread.m4:  New file.
* generated/spread_i1.c:  New file.
* generated/spread_i2.c:  New file.
* generated/spread_i4.c:  New file.
* generated/spread_i8.c:  New file.
* generated/spread_i16.c:  New file.
* generated/spread_r4.c:  New file.
* generated/spread_r8.c:  New file.
* generated/spread_r10.c:  New file.
* generated/spread_r16.c:  New file.
* generated/spread_c4.c:  New file.
* generated/spread_c8.c:  New file.
* generated/spread_c10.c:  New file.
* generated/spread_c16.c:  New file.

2008-03-27  Thomas Koenig  <tkoenig@gcc.gnu.org>

PR libfortran/32972
PR libfortran/32512
* intrinsic_spread_1.f90:  New file.
* intrinsic_spread_2.f90:  New file.
* intrinsic_spread_3.f90:  New file.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: intrinsic_spread_1.f90
Type: text/x-fortran
Size: 4142 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20080327/04476a34/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: intrinsic_spread_2.f90
Type: text/x-fortran
Size: 906 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20080327/04476a34/attachment-0001.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: intrinsic_spread_3.f90
Type: text/x-fortran
Size: 907 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20080327/04476a34/attachment-0002.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: spread-diff
Type: text/x-patch
Size: 23040 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20080327/04476a34/attachment-0003.bin>


More information about the Gcc-patches mailing list