[PATCH 05/15] Add hle.h base header
Andreas Jaeger
aj@suse.com
Fri Dec 28 12:19:00 GMT 2012
On 12/23/2012 04:02 AM, Andi Kleen wrote:
> From: Andi Kleen <ak@linux.intel.com>
>
> Add a header to use the RTM _x* intrinsics to start/stop transactions.
>
> Newer compilers / assembler implement those directly, but do it ourselves
> here to be more compatible with older toolchains.
>
> 2012-12-22 Andi Kleen <ak@linux.intel.com>
>
> * nptl/sysdeps/unix/sysv/linux/x86/hle.h New file.
> ---
> nptl/sysdeps/unix/sysv/linux/x86/hle.h | 71 ++++++++++++++++++++++++++++++++
> 1 files changed, 71 insertions(+), 0 deletions(-)
> create mode 100644 nptl/sysdeps/unix/sysv/linux/x86/hle.h
>
> diff --git a/nptl/sysdeps/unix/sysv/linux/x86/hle.h b/nptl/sysdeps/unix/sysv/linux/x86/hle.h
> new file mode 100644
> index 0000000..866a6ee
> --- /dev/null
> +++ b/nptl/sysdeps/unix/sysv/linux/x86/hle.h
> @@ -0,0 +1,71 @@
this header needs the usual copyright and license information.
> +/* Shared RTM header. Emulate TSX intrinsics for compilers and assemblers
> + that do not support the intrinsics and instructions yet. */
> +#ifndef _HLE_H
> +#define _HLE_H 1
> +
> +#ifdef __ASSEMBLER__
And this needs an extra space to show the intendation:
# ifdef ...
> +
> +.macro XBEGIN target
> + .byte 0xc7,0xf8
> + .long \target-1f
> +1:
> +.endm
> +
> +.macro XEND
> + .byte 0x0f,0x01,0xd5
> +.endm
> +
> +.macro XABORT code
> + .byte 0xc6,0xf8,\code
> +.endm
> +
> +.macro XTEST
> + .byte 0x0f,0x01,0xd6
> +.endm
> +
> +#endif
> +
> +/* Official RTM intrinsics interface matching gcc/icc, but works
> + on older gcc compatible compilers and binutils.
> + We should somehow detect if the compiler supports it, because
> + it may be able to generate slightly better code. */
> +
> +#define _XBEGIN_STARTED (~0u)
> +#define _XABORT_EXPLICIT (1 << 0)
> +#define _XABORT_RETRY (1 << 1)
> +#define _XABORT_CONFLICT (1 << 2)
> +#define _XABORT_CAPACITY (1 << 3)
> +#define _XABORT_DEBUG (1 << 4)
> +#define _XABORT_NESTED (1 << 5)
> +#define _XABORT_CODE(x) (((x) >> 24) & 0xff)
> +
> +#ifndef __ASSEMBLER__
> +
> +#define __force_inline __attribute__((__always_inline__)) inline
We have nowhere such a definition - and I wonder whether we should add
it either globally - or not at all. Just locally here looks wrong to me,
please follow the conventions elsewhere to not use a macro for this.
> +
> +static __force_inline int _xbegin(void)
> +{
> + int ret = _XBEGIN_STARTED;
> + asm volatile (".byte 0xc7,0xf8 ; .long 0" : "+a" (ret) :: "memory");
> + return ret;
> +}
> +
> +static __force_inline void _xend(void)
> +{
> + asm volatile (".byte 0x0f,0x01,0xd5" ::: "memory");
> +}
> +
> +static __force_inline void _xabort(const unsigned int status)
> +{
> + asm volatile (".byte 0xc6,0xf8,%P0" :: "i" (status) : "memory");
> +}
> +
> +static __force_inline int _xtest(void)
A space for each opening paren.
I'd also like to see brief comments for all these macros/functions.
Thanks,
Andreas
> +{
> + unsigned char out;
> + asm volatile (".byte 0x0f,0x01,0xd6 ; setnz %0" : "=r" (out) :: "memory");
> + return out;
> +}
> +
> +#endif
> +#endif
>
--
Andreas Jaeger aj@{suse.com,opensuse.org} Twitter/Identica: jaegerandi
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn,Jennifer Guild,Felix Imendörffer,HRB16746 (AG Nürnberg)
GPG fingerprint = 93A3 365E CE47 B889 DF7F FED1 389A 563C C272 A126
More information about the Libc-alpha
mailing list