Lisp HUG Maillist Archive

fast doubles -- please forgive me if I sent this already

Sorry if you got this already -- I accidentally unsubscribed today, and
figure that when I sent this it likely got dropped. 


Dear LispWorks users, 

I have a very specific performance problem. I am wondering if anybody else
has already run into this or not, and what the best solution is, given
LispWork's implementation (for NT).

I have a foreign routine that fills a buffer with lots of doubles (say 1-10K
elements).

I need to process these doubles in lisp, without boxing, as quickly as
possible. 
From what I know, the best is to get them into an array, as aref works
without boxing (when suitably optimized).

E.g. suppose I want something like this (here is the C++ version).
....
double *pBufer = GetBuffer();
for(int x= 0; x < NUM_SCENS; x++)
{
	for(y = 0; y < NUM_UNDERLYINGS; y++){
		z[y] = z[y] * (1 + *pBuffer);
		pBuffer++;
	}
}
....


I know in LispWorks I start with a fli:pointer to a double array.

I can see two methods to process the data:

1. Use fli:dereference and fli:increment on the double array.
2. Copy the native array into a lisp array, and then use aref. 

I suspect that if the LW implementation has been done so as to optimize #1,
#1 is the best way to go.

But if not, then #2 could be the best way to go (I know that aref
optimizations work) -- the one time copying cost may be less than paying
some penalty for repeatedly calling fli:dereference.

Does anyone know if technique #1 or #2 is best, or if there is some 3rd
version that works even better?

Rather than doing some experiments, I'd like to get a definitive answer, if
someone has one.

Thanks,

Heath


Updated at: 2020-12-10 09:01 UTC