Skip to contentSkip to conversation

cmpxchg: Discard unnecessary cast to volatile

PATCH In review Pranith Kumar 3 participants 5 messages Oct 1, 2014 – Oct 21, 2014 x86

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cmpxchg: Discard unnecessary cast to volatile

Generating a volatile pointer is really not necessary here. This is the only location where a volatile pointer is being generated for use in asm.

This commit removes the unnecessary volatile pointer being created.

---
 arch/x86/include/asm/cmpxchg.h | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)
arch/x86/include/asm/cmpxchg.h +4 -8
index 99c105d7..f0baea8 100644
@@ -90,36 +90,32 @@ extern void __add_wrong_size(void)
 	switch (size) {							\
 	case __X86_CASE_B:						\
 	{								\
-		volatile u8 *__ptr = (volatile u8 *)(ptr);		\
 		asm volatile(lock "cmpxchgb %2,%1"			\
-			     : "=a" (__ret), "+m" (*__ptr)		\
+			     : "=a" (__ret), "+m" (*ptr)		\
 			     : "q" (__new), "0" (__old)			\
 			     : "memory");				\
 		break;							\
 	}								\
 	case __X86_CASE_W:						\
 	{								\
-		volatile u16 *__ptr = (volatile u16 *)(ptr);		\
 		asm volatile(lock "cmpxchgw %2,%1"			\
-			     : "=a" (__ret), "+m" (*__ptr)		\
+			     : "=a" (__ret), "+m" (*ptr)		\
 			     : "r" (__new), "0" (__old)			\
 			     : "memory");				\
 		break;							\
 	}								\
 	case __X86_CASE_L:						\
 	{								\
-		volatile u32 *__ptr = (volatile u32 *)(ptr);		\
 		asm volatile(lock "cmpxchgl %2,%1"			\
-			     : "=a" (__ret), "+m" (*__ptr)		\
+			     : "=a" (__ret), "+m" (*ptr)		\
 			     : "r" (__new), "0" (__old)			\
 			     : "memory");				\
 		break;							\
 	}								\
 	case __X86_CASE_Q:						\
 	{								\
-		volatile u64 *__ptr = (volatile u64 *)(ptr);		\
 		asm volatile(lock "cmpxchgq %2,%1"			\
-			     : "=a" (__ret), "+m" (*__ptr)		\
+			     : "=a" (__ret), "+m" (*ptr)		\
 			     : "r" (__new), "0" (__old)			\
 			     : "memory");				\
 		break;							\
Signature · 1 line
1.9.1
#1 lore raw

ping.

Quoted 58 lines · Pranith Kumar

Generating a volatile pointer is really not necessary here. This is the only location where a volatile pointer is being generated for use in asm.

This commit removes the unnecessary volatile pointer being created.

---
 arch/x86/include/asm/cmpxchg.h | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)
arch/x86/include/asm/cmpxchg.h +4 -9
index 99c105d7..f0baea8 100644
@@ -90,36 +90,32 @@ extern void __add_wrong_size(void)
        switch (size) {                                                 \
        case __X86_CASE_B:                                              \
        {                                                               \
-               volatile u8 *__ptr = (volatile u8 *)(ptr);              \
                asm volatile(lock "cmpxchgb %2,%1"                      \
-                            : "=a" (__ret), "+m" (*__ptr)              \
+                            : "=a" (__ret), "+m" (*ptr)                \
                             : "q" (__new), "0" (__old)                 \
                             : "memory");                               \
                break;                                                  \
        }                                                               \
        case __X86_CASE_W:                                              \
        {                                                               \
-               volatile u16 *__ptr = (volatile u16 *)(ptr);            \
                asm volatile(lock "cmpxchgw %2,%1"                      \
-                            : "=a" (__ret), "+m" (*__ptr)              \
+                            : "=a" (__ret), "+m" (*ptr)                \
                             : "r" (__new), "0" (__old)                 \
                             : "memory");                               \
                break;                                                  \
        }                                                               \
        case __X86_CASE_L:                                              \
        {                                                               \
-               volatile u32 *__ptr = (volatile u32 *)(ptr);            \
                asm volatile(lock "cmpxchgl %2,%1"                      \
-                            : "=a" (__ret), "+m" (*__ptr)              \
+                            : "=a" (__ret), "+m" (*ptr)                \
                             : "r" (__new), "0" (__old)                 \
                             : "memory");                               \
                break;                                                  \
        }                                                               \
        case __X86_CASE_Q:                                              \
        {                                                               \
-               volatile u64 *__ptr = (volatile u64 *)(ptr);            \
                asm volatile(lock "cmpxchgq %2,%1"                      \
-                            : "=a" (__ret), "+m" (*__ptr)              \
+                            : "=a" (__ret), "+m" (*ptr)                \
                             : "r" (__new), "0" (__old)                 \
                             : "memory");                               \
                break;                                                  \
--

1.9.1

Signature · 1 line
Pranith
#2 lore raw
Quoted 6 lines · Pranith Kumar
Quoted 6 lines

Generating a volatile pointer is really not necessary here. This is the only location where a volatile pointer is being generated for use in asm.

This commit removes the unnecessary volatile pointer being created.

Seems sane enough to me.

#3 lore raw
Quoted 10 lines · Peter Zijlstra
Quoted 6 lines · Pranith Kumar
Quoted 6 lines

Generating a volatile pointer is really not necessary here. This is the only location where a volatile pointer is being generated for use in asm.

This commit removes the unnecessary volatile pointer being created.

Seems sane enough to me.

However, it seems like unnecessary churn. Does the volatile hurt in any way?

-hpa

#4 lore raw
Quoted 7 lines · H. Peter Anvin
Quoted 6 lines · Peter Zijlstra
Quoted 5 lines · Pranith Kumar
Quoted 5 lines

Generating a volatile pointer is really not necessary here. This is the only location where a volatile pointer is being generated for use in asm.

This commit removes the unnecessary volatile pointer being created.

Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Quoted 1 line

Seems sane enough to me.

However, it seems like unnecessary churn. Does the volatile hurt in any way?

Removing 4 lines of unnecessary code seems to be worthwhile to me. Also, we reduce the unnecessary use of 'volatile' data types which IMHO makes this a good little clean up.

I am not sure if the use of volatile actually causes any loss of chances of optimization. I've tried to come up with cases where this happens and was unsuccessful.

Signature · 1 line
Pranith