Skip to content

Instantly share code, notes, and snippets.

@jvkersch
Last active March 29, 2020 10:05
Show Gist options
  • Save jvkersch/cb65d3c2ba6deca287d6 to your computer and use it in GitHub Desktop.
Save jvkersch/cb65d3c2ba6deca287d6 to your computer and use it in GitHub Desktop.
Bug in Apple's vecLib (OS X < 10.10)
/* proof-of-concept incorrect */
@jwpeterson
Copy link

I just tried this on El Capitan (10.11.1) and the bug is still there.

@matcross
Copy link

matcross commented Mar 27, 2020

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

@jvkersch
Copy link
Author

jvkersch commented Mar 27, 2020

@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.

@matcross
Copy link

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...

@jvkersch
Copy link
Author

I've checked my notes from that time, and I was trying to debug a similar issue (with NumPy indirectly calling into vecLib).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment