-
-
Save jvkersch/cb65d3c2ba6deca287d6 to your computer and use it in GitHub Desktop.
/* proof-of-concept incorrect */ |
Your prototype for SDOT is incorrect. The Fortran parts of Apple vecLib use the g77 calling convention, see e.g. -ff2c
at GCC 9.3.0 Code-Gen-Options
So under this ABI the return type for SDOT is double
.
/* bad.c */
#include <stdio.h>
extern double SDOT(
const int *, const float *, const int *, const float *, const int *);
int main()
{
int len = 2;
int stride = 1;
float A[] = {1.0, 1.0};
double res;
res = SDOT(&len, A, &stride, A, &stride);
printf("%f\n", (float)res);
return 0;
}
> sw_vers
ProductName: Mac OS X
ProductVersion: 10.11.6
BuildVersion: 15G31
> gcc -framework Accelerate bad.c -o bad && ./bad
2.000000
@matcross Thanks for the clarification, you're right. Out of curiosity, what led you to this gist? In any case, I will edit the gist to indicate that the code is incorrect.
Out of curiosity, what led you to this gist?
Hi, it was through Google. I was looking into some problems at NAG building our numerical libraries against vecLib. I think the search might have been 'Apple vecLib sdot' - I'd forgotten that the g77 convention did this to float-valued functions...
I've checked my notes from that time, and I was trying to debug a similar issue (with NumPy indirectly calling into vecLib).
I just tried this on El Capitan (10.11.1) and the bug is still there.