[v4,02/14] eal: use rtm and xtest intrinsics

Message ID 1681247548-18590-3-git-send-email-roretzla@linux.microsoft.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series msvc integration changes |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Tyler Retzlaff April 11, 2023, 9:12 p.m. UTC
  Inline assembly is not supported for MSVC x64. Convert code to use
_xend, _xabort and _xtest intrinsics.

Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
---
 config/x86/meson.build        |  6 ++++++
 lib/eal/x86/include/rte_rtm.h | 18 +++++-------------
 2 files changed, 11 insertions(+), 13 deletions(-)
  

Comments

Bruce Richardson April 12, 2023, 8:54 a.m. UTC | #1
On Tue, Apr 11, 2023 at 02:12:16PM -0700, Tyler Retzlaff wrote:
> Inline assembly is not supported for MSVC x64. Convert code to use
> _xend, _xabort and _xtest intrinsics.
> 
> Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
> ---

Subject to the CI not reporting any errors:

Acked-by: Bruce Richardson <bruce.richardson@intel.com>

>  config/x86/meson.build        |  6 ++++++
>  lib/eal/x86/include/rte_rtm.h | 18 +++++-------------
>  2 files changed, 11 insertions(+), 13 deletions(-)
> 
> diff --git a/config/x86/meson.build b/config/x86/meson.build
> index 54345c4..4c0b06c 100644
> --- a/config/x86/meson.build
> +++ b/config/x86/meson.build
> @@ -30,6 +30,12 @@ if cc.get_define('__SSE4_2__', args: machine_args) == ''
>      machine_args += '-msse4'
>  endif
>  
> +# enable restricted transactional memory intrinsics
> +# https://gcc.gnu.org/onlinedocs/gcc/x86-transactional-memory-intrinsics.html
> +if cc.get_id() != 'msvc'
> +    machine_args += '-mrtm'
> +endif
> +
>  base_flags = ['SSE', 'SSE2', 'SSE3','SSSE3', 'SSE4_1', 'SSE4_2']
>  foreach f:base_flags
>      compile_time_cpuflags += ['RTE_CPUFLAG_' + f]
> diff --git a/lib/eal/x86/include/rte_rtm.h b/lib/eal/x86/include/rte_rtm.h
> index 36bf498..b84e58e 100644
> --- a/lib/eal/x86/include/rte_rtm.h
> +++ b/lib/eal/x86/include/rte_rtm.h
> @@ -5,6 +5,7 @@
>  #ifndef _RTE_RTM_H_
>  #define _RTE_RTM_H_ 1
>  
> +#include <immintrin.h>
>  
>  /* Official RTM intrinsics interface matching gcc/icc, but works
>     on older gcc compatible compilers and binutils. */
> @@ -28,31 +29,22 @@
>  static __rte_always_inline
>  unsigned int rte_xbegin(void)
>  {
> -	unsigned int ret = RTE_XBEGIN_STARTED;
> -
> -	asm volatile(".byte 0xc7,0xf8 ; .long 0" : "+a" (ret) :: "memory");
> -	return ret;
> +	return _xbegin();
>  }
>  
>  static __rte_always_inline
>  void rte_xend(void)
>  {
> -	 asm volatile(".byte 0x0f,0x01,0xd5" ::: "memory");
> +	_xend();
>  }
>  
>  /* not an inline function to workaround a clang bug with -O0 */
> -#define rte_xabort(status) do { \
> -	asm volatile(".byte 0xc6,0xf8,%P0" :: "i" (status) : "memory"); \
> -} while (0)
> +#define rte_xabort(status) _xabort(status)
>  
>  static __rte_always_inline
>  int rte_xtest(void)
>  {
> -	unsigned char out;
> -
> -	asm volatile(".byte 0x0f,0x01,0xd6 ; setnz %0" :
> -		"=r" (out) :: "memory");
> -	return out;
> +	return _xtest();
>  }
>  
>  #ifdef __cplusplus
> -- 
> 1.8.3.1
>
  
Konstantin Ananyev April 12, 2023, 10:27 a.m. UTC | #2
> Inline assembly is not supported for MSVC x64. Convert code to use
> _xend, _xabort and _xtest intrinsics.
> 
> Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
> ---
>  config/x86/meson.build        |  6 ++++++
>  lib/eal/x86/include/rte_rtm.h | 18 +++++-------------
>  2 files changed, 11 insertions(+), 13 deletions(-)
> 
> diff --git a/config/x86/meson.build b/config/x86/meson.build
> index 54345c4..4c0b06c 100644
> --- a/config/x86/meson.build
> +++ b/config/x86/meson.build
> @@ -30,6 +30,12 @@ if cc.get_define('__SSE4_2__', args: machine_args) == ''
>      machine_args += '-msse4'
>  endif
> 
> +# enable restricted transactional memory intrinsics
> +# https://gcc.gnu.org/onlinedocs/gcc/x86-transactional-memory-intrinsics.html
> +if cc.get_id() != 'msvc'
> +    machine_args += '-mrtm'
> +endif
> +
>  base_flags = ['SSE', 'SSE2', 'SSE3','SSSE3', 'SSE4_1', 'SSE4_2']
>  foreach f:base_flags
>      compile_time_cpuflags += ['RTE_CPUFLAG_' + f]
> diff --git a/lib/eal/x86/include/rte_rtm.h b/lib/eal/x86/include/rte_rtm.h
> index 36bf498..b84e58e 100644
> --- a/lib/eal/x86/include/rte_rtm.h
> +++ b/lib/eal/x86/include/rte_rtm.h
> @@ -5,6 +5,7 @@
>  #ifndef _RTE_RTM_H_
>  #define _RTE_RTM_H_ 1
> 
> +#include <immintrin.h>
> 
>  /* Official RTM intrinsics interface matching gcc/icc, but works
>     on older gcc compatible compilers and binutils. */
> @@ -28,31 +29,22 @@
>  static __rte_always_inline
>  unsigned int rte_xbegin(void)
>  {
> -	unsigned int ret = RTE_XBEGIN_STARTED;
> -
> -	asm volatile(".byte 0xc7,0xf8 ; .long 0" : "+a" (ret) :: "memory");
> -	return ret;
> +	return _xbegin();
>  }
> 
>  static __rte_always_inline
>  void rte_xend(void)
>  {
> -	 asm volatile(".byte 0x0f,0x01,0xd5" ::: "memory");
> +	_xend();
>  }
> 
>  /* not an inline function to workaround a clang bug with -O0 */
> -#define rte_xabort(status) do { \
> -	asm volatile(".byte 0xc6,0xf8,%P0" :: "i" (status) : "memory"); \
> -} while (0)
> +#define rte_xabort(status) _xabort(status)
> 
>  static __rte_always_inline
>  int rte_xtest(void)
>  {
> -	unsigned char out;
> -
> -	asm volatile(".byte 0x0f,0x01,0xd6 ; setnz %0" :
> -		"=r" (out) :: "memory");
> -	return out;
> +	return _xtest();
>  }
> 
>  #ifdef __cplusplus
> --

Acked-by: Konstantin Ananyev <konstantin.ananyev@huawei.com>
 

> 1.8.3.1
  

Patch

diff --git a/config/x86/meson.build b/config/x86/meson.build
index 54345c4..4c0b06c 100644
--- a/config/x86/meson.build
+++ b/config/x86/meson.build
@@ -30,6 +30,12 @@  if cc.get_define('__SSE4_2__', args: machine_args) == ''
     machine_args += '-msse4'
 endif
 
+# enable restricted transactional memory intrinsics
+# https://gcc.gnu.org/onlinedocs/gcc/x86-transactional-memory-intrinsics.html
+if cc.get_id() != 'msvc'
+    machine_args += '-mrtm'
+endif
+
 base_flags = ['SSE', 'SSE2', 'SSE3','SSSE3', 'SSE4_1', 'SSE4_2']
 foreach f:base_flags
     compile_time_cpuflags += ['RTE_CPUFLAG_' + f]
diff --git a/lib/eal/x86/include/rte_rtm.h b/lib/eal/x86/include/rte_rtm.h
index 36bf498..b84e58e 100644
--- a/lib/eal/x86/include/rte_rtm.h
+++ b/lib/eal/x86/include/rte_rtm.h
@@ -5,6 +5,7 @@ 
 #ifndef _RTE_RTM_H_
 #define _RTE_RTM_H_ 1
 
+#include <immintrin.h>
 
 /* Official RTM intrinsics interface matching gcc/icc, but works
    on older gcc compatible compilers and binutils. */
@@ -28,31 +29,22 @@ 
 static __rte_always_inline
 unsigned int rte_xbegin(void)
 {
-	unsigned int ret = RTE_XBEGIN_STARTED;
-
-	asm volatile(".byte 0xc7,0xf8 ; .long 0" : "+a" (ret) :: "memory");
-	return ret;
+	return _xbegin();
 }
 
 static __rte_always_inline
 void rte_xend(void)
 {
-	 asm volatile(".byte 0x0f,0x01,0xd5" ::: "memory");
+	_xend();
 }
 
 /* not an inline function to workaround a clang bug with -O0 */
-#define rte_xabort(status) do { \
-	asm volatile(".byte 0xc6,0xf8,%P0" :: "i" (status) : "memory"); \
-} while (0)
+#define rte_xabort(status) _xabort(status)
 
 static __rte_always_inline
 int rte_xtest(void)
 {
-	unsigned char out;
-
-	asm volatile(".byte 0x0f,0x01,0xd6 ; setnz %0" :
-		"=r" (out) :: "memory");
-	return out;
+	return _xtest();
 }
 
 #ifdef __cplusplus