Re: [PATCH 07/15] x86: add xadd helper macro

From: Peter Zijlstra
Date: Tue Aug 23 2011 - 07:00:15 EST




What you could do is something like:

#define CASE_B case 1
#define CASE_W case 2
#define CASE_L case 4
#ifdef CONFIG_64BIT
# define CASE_Q case 8
#else
# define CASE_Q case -1 /* sizeof() won't ever return this */
#endif


> +#define xadd(ptr, inc) \
> + do { \
> + switch (sizeof(*(ptr))) { \
CASE_B: \
> + asm volatile (LOCK_PREFIX "xaddb %b0, %1\n" \
> + : "+r" (inc), "+m" (*(ptr)) \
> + : : "memory", "cc"); \
> + break; \
CASE_W: \
> + asm volatile (LOCK_PREFIX "xaddw %w0, %1\n" \
> + : "+r" (inc), "+m" (*(ptr)) \
> + : : "memory", "cc"); \
> + break; \
CASE_L: \
> + asm volatile (LOCK_PREFIX "xaddl %0, %1\n" \
> + : "+r" (inc), "+m" (*(ptr)) \
> + : : "memory", "cc"); \
> + break; \
CASE_Q: \
> + asm volatile (LOCK_PREFIX "xaddq %q0, %1\n" \
> + : "+r" (inc), "+m" (*(ptr)) \
> + : : "memory", "cc"); \
> + break; \
default: \
__xadd_wrong_size(); \
> + } \
> + } while(0)


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/