From: <hr...@co...> - 2010-03-16 12:21:40
|
Hello! Don't know whether it's SBCL's bug or mine, but still... My first attempt with SIMD is a (silly?) library: #include <emmintrin.h> void himd_sqrt (double* x, int len) { double __attribute__((aligned(16))) *xa=_mm_malloc(2*sizeof(double),16); int i, l1 = len%2 ? len - 1 : len; for (i=0; i<l1; i+=2) { xa[0]=x[i]; xa[1]=x[i+1]; _mm_store_pd(xa, _mm_sqrt_pd(_mm_load_pd(xa))); x[i]=xa[0]; x[i+1]=xa[1]; } if (len%2) { xa[0]=x[l1]; _mm_store_pd(xa, _mm_sqrt_pd(_mm_load_pd(xa))); x[l1]=xa[0]; } _mm_free(xa); } I compile it with gcc -msse2 -shared himd.c -o libhimd.so and then try to use from inside SBCL: (require 'cffi) (cffi:define-foreign-library himd (:unix (:or "libhimd.so")) (t (:default "libhimd"))) (cffi:use-foreign-library himd) (cffi:defcfun "himd_sqrt" :void (p :pointer) (len :int)) (setf x (cffi:foreign-alloc :double :initial-contents '(1.0d0 2.0d0 3.0d0))) (himd-sqrt x 3) It dies with Unhandled memory fault at #x0. According to printf's, it happens at _mm_load_pd At the same time, C test #include <stdio.h> void himd_sqrt (double* x, int len); int main (int argc, char* argv[]) { double x[]={1, 2, 3}; himd_sqrt(x,3); printf("%lf %lf %lf\n",x[0],x[1],x[2]); return 0; } compiled with gcc -lhimd test.c says 1.000000 1.414214 1.732051 What happens? My system is Ubuntu 8.10. Thanks, Dmitri P.S. And if someone could be so kind as to advise me some way to quickly sqrt each element of an array (with GSL, BLAS, etc.), it would be great. |
From: Nikodemus S. <nik...@ra...> - 2010-03-16 15:04:47
|
On 16 March 2010 14:00, <hr...@co...> wrote: > Hello! > > Don't know whether it's SBCL's bug or mine, but still... Logged as https://bugs.launchpad.net/sbcl/+bug/539632 Cheers, -- Nikodemus |