All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Jan Beulich <JBeulich@suse.com>,
	xen-devel <xen-devel@lists.xenproject.org>
Cc: Keir Fraser <keir@xen.org>
Subject: Re: [PATCH] x86: simplify a few macros / inline functions
Date: Fri, 8 May 2015 09:25:23 +0100	[thread overview]
Message-ID: <554C72F3.8060501@citrix.com> (raw)
In-Reply-To: <554C76FE0200007800077F45@mail.emea.novell.com>

On 08/05/15 07:42, Jan Beulich wrote:
> Drop pointless casts and write_atomic()'s bogus and unused "return
> value".
>
> Signed-off-by: Jan Beulich <jbeulich@suse.com>

Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>, given
confirmation of one query...

>
> --- a/xen/include/asm-x86/atomic.h
> +++ b/xen/include/asm-x86/atomic.h
> @@ -17,12 +17,11 @@ static inline void name(volatile type *a
>  build_read_atomic(read_u8_atomic, "b", uint8_t, "=q", )
>  build_read_atomic(read_u16_atomic, "w", uint16_t, "=r", )
>  build_read_atomic(read_u32_atomic, "l", uint32_t, "=r", )
> +build_read_atomic(read_u64_atomic, "q", uint64_t, "=r", )
>  
>  build_write_atomic(write_u8_atomic, "b", uint8_t, "q", )
>  build_write_atomic(write_u16_atomic, "w", uint16_t, "r", )
>  build_write_atomic(write_u32_atomic, "l", uint32_t, "r", )
> -
> -build_read_atomic(read_u64_atomic, "q", uint64_t, "=r", )
>  build_write_atomic(write_u64_atomic, "q", uint64_t, "r", )
>  
>  #undef build_read_atomic
> @@ -30,29 +29,28 @@ build_write_atomic(write_u64_atomic, "q"
>  
>  void __bad_atomic_size(void);
>  
> -#define read_atomic(p) ({                                               \
> -    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;                        \
> -    }                                                                   \
> -    (typeof(*(p)))x_;                                                   \
> +#define read_atomic(p) ({                                 \
> +    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;          \
> +    }                                                     \
> +    (typeof(*(p)))x_;                                     \
>  })

I cant spot a change in read_atomic(), other than the alignment of the
\'s.  I just want to double check that I haven't missed something.

~Andrew

>  
> -#define write_atomic(p, x) ({                                           \
> -    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;                                                                \
> +#define write_atomic(p, x) ({                             \
> +    typeof(*(p)) __x = (x);                               \
> +    unsigned long x_ = (unsigned long)__x;                \
> +    switch ( sizeof(*(p)) ) {                             \
> +    case 1: write_u8_atomic((uint8_t *)(p), x_); break;   \
> +    case 2: write_u16_atomic((uint16_t *)(p), x_); break; \
> +    case 4: write_u32_atomic((uint32_t *)(p), x_); break; \
> +    case 8: write_u64_atomic((uint64_t *)(p), x_); break; \
> +    default: __bad_atomic_size(); break;                  \
> +    }                                                     \
>  })
>  
>  /*
> --- a/xen/include/asm-x86/system.h
> +++ b/xen/include/asm-x86/system.h
> @@ -41,25 +41,25 @@ static always_inline unsigned long __xch
>      case 1:
>          asm volatile ( "xchgb %b0,%1"
>                         : "=q" (x)
> -                       : "m" (*__xg((volatile void *)ptr)), "0" (x)
> +                       : "m" (*__xg(ptr)), "0" (x)
>                         : "memory" );
>          break;
>      case 2:
>          asm volatile ( "xchgw %w0,%1"
>                         : "=r" (x)
> -                       : "m" (*__xg((volatile void *)ptr)), "0" (x)
> +                       : "m" (*__xg(ptr)), "0" (x)
>                         : "memory" );
>          break;
>      case 4:
>          asm volatile ( "xchgl %k0,%1"
>                         : "=r" (x)
> -                       : "m" (*__xg((volatile void *)ptr)), "0" (x)
> +                       : "m" (*__xg(ptr)), "0" (x)
>                         : "memory" );
>          break;
>      case 8:
>          asm volatile ( "xchgq %0,%1"
>                         : "=r" (x)
> -                       : "m" (*__xg((volatile void *)ptr)), "0" (x)
> +                       : "m" (*__xg(ptr)), "0" (x)
>                         : "memory" );
>          break;
>      }
> @@ -81,28 +81,28 @@ static always_inline unsigned long __cmp
>      case 1:
>          asm volatile ( "lock; cmpxchgb %b1,%2"
>                         : "=a" (prev)
> -                       : "q" (new), "m" (*__xg((volatile void *)ptr)),
> +                       : "q" (new), "m" (*__xg(ptr)),
>                         "0" (old)
>                         : "memory" );
>          return prev;
>      case 2:
>          asm volatile ( "lock; cmpxchgw %w1,%2"
>                         : "=a" (prev)
> -                       : "r" (new), "m" (*__xg((volatile void *)ptr)),
> +                       : "r" (new), "m" (*__xg(ptr)),
>                         "0" (old)
>                         : "memory" );
>          return prev;
>      case 4:
>          asm volatile ( "lock; cmpxchgl %k1,%2"
>                         : "=a" (prev)
> -                       : "r" (new), "m" (*__xg((volatile void *)ptr)),
> +                       : "r" (new), "m" (*__xg(ptr)),
>                         "0" (old)
>                         : "memory" );
>          return prev;
>      case 8:
>          asm volatile ( "lock; cmpxchgq %1,%2"
>                         : "=a" (prev)
> -                       : "r" (new), "m" (*__xg((volatile void *)ptr)),
> +                       : "r" (new), "m" (*__xg(ptr)),
>                         "0" (old)
>                         : "memory" );
>          return prev;
>
>

  reply	other threads:[~2015-05-08  8:25 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-08  6:42 [PATCH] x86: simplify a few macros / inline functions Jan Beulich
2015-05-08  8:25 ` Andrew Cooper [this message]
2015-05-08  8:29   ` Jan Beulich

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=554C72F3.8060501@citrix.com \
    --to=andrew.cooper3@citrix.com \
    --cc=JBeulich@suse.com \
    --cc=keir@xen.org \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.