* [PATCH] x86: properly parenthesize {read, write}_atomic()
@ 2015-03-20 14:54 Jan Beulich
2015-03-25 17:29 ` Andrew Cooper
0 siblings, 1 reply; 2+ messages in thread
From: Jan Beulich @ 2015-03-20 14:54 UTC (permalink / raw)
To: xen-devel; +Cc: Andrew Cooper, Keir Fraser
[-- Attachment #1: Type: text/plain, Size: 3031 bytes --]
... at once eliminating some redundancy from the read variant (the cast
to the destination type can be done once outside the switch).
Signed-off-by: Jan Beulich <jbeulich@suse.com>
--- a/xen/include/asm-x86/atomic.h
+++ b/xen/include/asm-x86/atomic.h
@@ -31,24 +31,25 @@ build_write_atomic(write_u64_atomic, "q"
void __bad_atomic_size(void);
#define read_atomic(p) ({ \
- typeof(*p) __x; \
- switch ( sizeof(*p) ) { \
- case 1: __x = (typeof(*p))read_u8_atomic((uint8_t *)p); break; \
- case 2: __x = (typeof(*p))read_u16_atomic((uint16_t *)p); break; \
- case 4: __x = (typeof(*p))read_u32_atomic((uint32_t *)p); break; \
- case 8: __x = (typeof(*p))read_u64_atomic((uint64_t *)p); break; \
- default: __x = 0; __bad_atomic_size(); break; \
+ unsigned long x_; \
+ switch ( sizeof(*(p)) ) { \
+ case 1: x_ = read_u8_atomic((uint8_t *)(p)); break; \
+ case 2: x_ = read_u16_atomic((uint16_t *)(p)); break; \
+ case 4: x_ = read_u32_atomic((uint32_t *)(p)); break; \
+ case 8: x_ = read_u64_atomic((uint64_t *)(p)); break; \
+ default: x_ = 0; __bad_atomic_size(); break; \
} \
- __x; \
+ (typeof(*(p)))x_; \
})
#define write_atomic(p, x) ({ \
- typeof(*p) __x = (x); \
- switch ( sizeof(*p) ) { \
- case 1: write_u8_atomic((uint8_t *)p, (uint8_t)__x); break; \
- case 2: write_u16_atomic((uint16_t *)p, (uint16_t)__x); break; \
- case 4: write_u32_atomic((uint32_t *)p, (uint32_t)__x); break; \
- case 8: write_u64_atomic((uint64_t *)p, (uint64_t)__x); break; \
+ typeof(*(p)) __x = (x); \
+ unsigned long x_ = (unsigned long)__x; \
+ switch ( sizeof(*(p)) ) { \
+ case 1: write_u8_atomic((uint8_t *)(p), (uint8_t)x_); break; \
+ case 2: write_u16_atomic((uint16_t *)(p), (uint16_t)x_); break; \
+ case 4: write_u32_atomic((uint32_t *)(p), (uint32_t)x_); break; \
+ case 8: write_u64_atomic((uint64_t *)(p), (uint64_t)x_); break; \
default: __bad_atomic_size(); break; \
} \
__x; \
[-- Attachment #2: x86-rw-atomic-parens.patch --]
[-- Type: text/plain, Size: 3078 bytes --]
x86: properly parenthesize {read,write}_atomic()
... at once eliminating some redundancy from the read variant (the cast
to the destination type can be done once outside the switch).
Signed-off-by: Jan Beulich <jbeulich@suse.com>
--- a/xen/include/asm-x86/atomic.h
+++ b/xen/include/asm-x86/atomic.h
@@ -31,24 +31,25 @@ build_write_atomic(write_u64_atomic, "q"
void __bad_atomic_size(void);
#define read_atomic(p) ({ \
- typeof(*p) __x; \
- switch ( sizeof(*p) ) { \
- case 1: __x = (typeof(*p))read_u8_atomic((uint8_t *)p); break; \
- case 2: __x = (typeof(*p))read_u16_atomic((uint16_t *)p); break; \
- case 4: __x = (typeof(*p))read_u32_atomic((uint32_t *)p); break; \
- case 8: __x = (typeof(*p))read_u64_atomic((uint64_t *)p); break; \
- default: __x = 0; __bad_atomic_size(); break; \
+ unsigned long x_; \
+ switch ( sizeof(*(p)) ) { \
+ case 1: x_ = read_u8_atomic((uint8_t *)(p)); break; \
+ case 2: x_ = read_u16_atomic((uint16_t *)(p)); break; \
+ case 4: x_ = read_u32_atomic((uint32_t *)(p)); break; \
+ case 8: x_ = read_u64_atomic((uint64_t *)(p)); break; \
+ default: x_ = 0; __bad_atomic_size(); break; \
} \
- __x; \
+ (typeof(*(p)))x_; \
})
#define write_atomic(p, x) ({ \
- typeof(*p) __x = (x); \
- switch ( sizeof(*p) ) { \
- case 1: write_u8_atomic((uint8_t *)p, (uint8_t)__x); break; \
- case 2: write_u16_atomic((uint16_t *)p, (uint16_t)__x); break; \
- case 4: write_u32_atomic((uint32_t *)p, (uint32_t)__x); break; \
- case 8: write_u64_atomic((uint64_t *)p, (uint64_t)__x); break; \
+ typeof(*(p)) __x = (x); \
+ unsigned long x_ = (unsigned long)__x; \
+ switch ( sizeof(*(p)) ) { \
+ case 1: write_u8_atomic((uint8_t *)(p), (uint8_t)x_); break; \
+ case 2: write_u16_atomic((uint16_t *)(p), (uint16_t)x_); break; \
+ case 4: write_u32_atomic((uint32_t *)(p), (uint32_t)x_); break; \
+ case 8: write_u64_atomic((uint64_t *)(p), (uint64_t)x_); break; \
default: __bad_atomic_size(); break; \
} \
__x; \
[-- Attachment #3: Type: text/plain, Size: 126 bytes --]
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] x86: properly parenthesize {read, write}_atomic()
2015-03-20 14:54 [PATCH] x86: properly parenthesize {read, write}_atomic() Jan Beulich
@ 2015-03-25 17:29 ` Andrew Cooper
0 siblings, 0 replies; 2+ messages in thread
From: Andrew Cooper @ 2015-03-25 17:29 UTC (permalink / raw)
To: Jan Beulich, xen-devel; +Cc: Keir Fraser
On 20/03/15 15:54, Jan Beulich wrote:
> ... at once eliminating some redundancy from the read variant (the cast
> to the destination type can be done once outside the switch).
>
> Signed-off-by: Jan Beulich<jbeulich@suse.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-03-25 17:29 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-03-20 14:54 [PATCH] x86: properly parenthesize {read, write}_atomic() Jan Beulich
2015-03-25 17:29 ` Andrew Cooper
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.