Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for GCC legacy __sync_XXX builtins #22

Open
lambdageek opened this issue Feb 14, 2017 · 1 comment
Open

Add support for GCC legacy __sync_XXX builtins #22

lambdageek opened this issue Feb 14, 2017 · 1 comment

Comments

@lambdageek
Copy link

From https://gcc.gnu.org/onlinedocs/gcc/_005f_005fsync-Builtins.html:

The following built-in functions are intended to be compatible with those described in the Intel Itanium Processor-specific Application Binary Interface, section 7.4. As such, they depart from normal GCC practice by not using the ‘__builtin_’ prefix and also by being overloaded so that they work on multiple types.

The definition given in the Intel documentation allows only for the use of the types int, long, long long or their unsigned counterparts. GCC allows any scalar type that is 1, 2, 4 or 8 bytes in size other than the C type _Bool or the C++ type bool. Operations on pointer arguments are performed as if the operands were of the uintptr_t type. That is, they are not scaled by the size of the type to which the pointer points.

They have about a dozen of these things, they look more or less like this one:

type __sync_fetch_and_add (type *ptr, type value, ...)

@lambdageek
Copy link
Author

lambdageek commented Feb 17, 2017

I've had some luck just #define-ing these things away in a header that I pass with a IncludeFile CppOption.

#define __sync_fetch_and_add(ptr,value,...)  ({ typeof((ptr)) __hack_ptr = (ptr);  typeof (*__hack_ptr) __hack_tmp = *__hack_ptr; *__hack_ptr += (value); __hack_tmp; })

Of course this forgets about the atomicity, but it at least gets the file parsed (if you use GNU extensions).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant