[ovs-dev] [PATCH 1/1] include/openvswitch/compiler.h: check existence of __builtin_prefetch using __has_builtin
Ben Pfaff
blp at ovn.org
Thu Aug 12 17:11:40 UTC 2021
On Tue, Aug 10, 2021 at 05:17:56PM -0700, Sergey Madaminov wrote:
> Checking if '__has_builtin' is defined and then defining OVS_PREFETCH to
> be '__builtin_prefetch' if it is available. To preserve backwards
> compatibility, the previous way to define OVS_PREFETCH macro is also
> there.
Thanks for working on OVS!
> +#if defined __has_builtin
> +# if __has_builtin (__builtin_prefetch)
> +# define OVS_PREFETCH(addr) __builtin_prefetch((addr))
> +# define OVS_PREFETCH_WRITE(addr) __builtin_prefetch((addr), 1)
> +# endif
> +#elif __GNUC__
> +# define OVS_PREFETCH(addr) __builtin_prefetch((addr))
> +# define OVS_PREFETCH_WRITE(addr) __builtin_prefetch((addr), 1)
> #else
> -#define OVS_PREFETCH(addr)
> -#define OVS_PREFETCH_WRITE(addr)
> +# define OVS_PREFETCH(addr)
> +# define OVS_PREFETCH_WRITE(addr)
> #endif
The above has some redundancy: two of the forks of the definitions are
identical.
I think a common way to deal with this is something like:
#ifndef __has_builtin
#define __has_builtin(X) 0
#endif
#if __has_builtin (__builtin_prefetch) || __GNUC__
/* definition 1 */
#else
/* definition 2 */
#endif
> /* Since Visual Studio 2015 there has been an effort to make offsetof a
> @@ -244,11 +253,13 @@
> * the C compiler.
> * e.g.: https://bit.ly/2UvWwti
> */
> + /*
> #if _MSC_VER >= 1900
> #undef offsetof
> #define offsetof(type, member) \
> ((size_t)((char *)&(((type *)0)->member) - (char *)0))
> #endif
> +*/
The above seems unrelated. If it's needed, I'd put it in a separate
patch. I'd also remove the code rather than commenting it out.
More information about the dev
mailing list