Improved autovectorization with pointers, 64 bit linux, gcc 8.20

Linux specific questions.
greenink
Posts: 200
Joined: Jan 28, 2016 15:45

Improved autovectorization with pointers, 64 bit linux, gcc 8.20

Postby greenink » Feb 23, 2019 12:11

By using pointers for array operations you may get up to a 4 times speed improvement with Linux 64bit PC and GCC 8.2.0
You may have to experiment with reordering the code to get gcc to autovectorize.
You must use the -O 3 compiler command line option:Eg fbc -O 3 test.bas

Code: Select all

sub multiply(result() as single,x() as single,y() as single)
   for i as ulongint=0 to ubound(result)
      result(i)=x(i)*y(i)
   next
end sub

sub multiplyPointer(result() as single,x() as single,y() as single)
    dim as single ptr rptr=@result(0),xptr=@x(0),yptr=@y(0)
   for i as ulongint=0 to ubound(result)
      rptr[i]=xptr[i]*yptr[i]
   next
end sub

dim as single r(100000),x(100000),y(100000)
var t1=Timer
for i as ulongint=0 to 1000
   multiply(r(),x(),y())
next
var t2=Timer
print 1000.0/(t2-t1),"multiply function calls per second"

t1=Timer
for i as ulongint=0 to 1000
   multiplyPointer(r(),x(),y())
next
t2=Timer
print 1000.0/(t2-t1),"multiplyPointer function calls per second"


8400/s vs 14000/s in this case
fxm
Posts: 8805
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Improved autovectorization with pointers, 64 bit linux, gcc 8.20

Postby fxm » Feb 23, 2019 12:34

The 3 arrays occupy more than 1 MB in the stack.
So (for Windows), it is better to:
- compile by setting a stack size of 2MB for example: -t 2048
- or put the 3 arrays data in the heap: dim shared as single r(100000), x(100000), y(100000)

Return to “Linux”

Who is online

Users browsing this forum: No registered users and 0 guests