simd woes
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
SBCL |
Won't Fix
|
Medium
|
Unassigned |
Bug Description
Send by <email address hidden> to sbcl-bugs:
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_
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_
x[i]=xa[0];
x[i+1]=xa[1];
}
if (len%2) {
xa[0]=x[l1];
_mm_
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-
(:unix (:or "libhimd.so"))
(t (:default "libhimd")))
(cffi:use-
(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",
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.
Changed in sbcl: | |
status: | In Progress → Triaged |
assignee: | Nikodemus Siivola (nikodemus) → nobody |
Is this a 32 or 64 bit SBCL? If the first, I'm guessing that the C-side SIMD code isn't happy with the stack alignment.