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"