tests/tcg/aarch64: Fix inline assemblies for clang
v3 cover tests/tcg/aarch64: Fix inline assemblies for clang
Unlike GCC, clang checks if the operands in assembly matches with the type in C. It also does not support "x" constraint for AArch64 and complains about them.
---
Changes in v3:
- Added patch "tests/tcg/aarch64: Use -fno-integrated-as".
- Added patch "tests/tcg/aarch64: Specify -Wa,-march=armv9-a+sme".
- Dropped patch "tests/docker: Specify --userns keep-id for Podman" as it is already queued.
- Link to v2: https://lore.kernel.org/r/[email protected]
Changes in v2:
- Removed spurious a compiler flag change for normal SME tests.
- Fixed sme-i16i64 detection.
- Link to v1: https://lore.kernel.org/r/[email protected]
---
Akihiko Odaki (7):
tests/tcg/aarch64: Use -fno-integrated-as tests/tcg/aarch64: Specify -Wa,-march=armv9-a+sme tests/tcg/aarch64: Fix test architecture specification tests/tcg/aarch64: Explicitly specify register width tests/tcg/aarch64: Fix irg operand type tests/tcg/aarch64: Do not use x constraint tests/tcg/arm: Manually bit-cast half-precision numbers
tests/tcg/aarch64/bti-1.c | 6 +++--- tests/tcg/aarch64/bti-3.c | 6 +++--- tests/tcg/aarch64/mte-1.c | 2 +- tests/tcg/aarch64/sme-smopa-2.c | 2 +- tests/tcg/arm/fcvt.c | 18 ++++++++++-------- tests/tcg/aarch64/Makefile.target | 21 +++++++++++++++++++-- 6 files changed, 37 insertions(+), 18 deletions(-)
---
base-commit: 046a64b9801343e2e89eef10c7a48eec8d8c0d4f
change-id: 20240624-tcg-bf8116e80afa
Best regards,
Signature · 1 line
Akihiko Odaki <[email protected]>
PATCH v3 1/7 tests/tcg/aarch64: Use -fno-integrated-as
clang version 18.1.6 does not respect -Wa,-march=armv9-a+sme without -fno-integrated-as. Use it when available.
--- tests/tcg/aarch64/Makefile.target | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
tests/tcg/aarch64/Makefile.target +7 -1
@@ -20,6 +20,9 @@ run-fcvt: fcvt config-cc.mak: Makefile $(quiet-@)( \ + if $(call cc-test, -fno-integrated-as); then fno_integrated_as=-fno-integrated-as; else \ + fno_integrated_as=; fi; \ + $(call cc-option,-fno-integrated-as, CROSS_CC_HAS_FNO_INTEGRATED_AS); \ $(call cc-option,-march=armv8.1-a+sve, CROSS_CC_HAS_SVE); \ $(call cc-option,-march=armv8.1-a+sve2, CROSS_CC_HAS_SVE2); \ $(call cc-option,-march=armv8.2-a, CROSS_CC_HAS_ARMV8_2); \
@@ -27,7 +30,7 @@ config-cc.mak: Makefile $(call cc-option,-march=armv8.5-a, CROSS_CC_HAS_ARMV8_5); \ $(call cc-option,-mbranch-protection=standard, CROSS_CC_HAS_ARMV8_BTI); \ $(call cc-option,-march=armv8.5-a+memtag, CROSS_CC_HAS_ARMV8_MTE); \ - $(call cc-option,-Wa$(COMMA)-march=armv9-a+sme, CROSS_AS_HAS_ARMV9_SME)) 3> config-cc.mak + $(call cc-option,-Wa$(COMMA)-march=armv9-a+sme $$fno_integrated_as, CROSS_AS_HAS_ARMV9_SME)) 3> config-cc.mak -include config-cc.mak ifneq ($(CROSS_CC_HAS_ARMV8_2),)
@@ -69,6 +72,9 @@ endif # SME Tests ifneq ($(CROSS_AS_HAS_ARMV9_SME),) AARCH64_TESTS += sme-outprod1 sme-smopa-1 sme-smopa-2 +ifneq ($(CROSS_CC_HAS_FNO_INTEGRATED_AS),) +sme-%: CFLAGS += -fno-integrated-as +endif endif # System Registers Tests
Signature · 1 line
2.45.2
PATCH v3 2/7 tests/tcg/aarch64: Specify -Wa,-march=armv9-a+sme
In reply to Akihiko OdakiThe availability of -Wa,-march=armv9-a+sme was checked but it was never used. Use it for SME tests.
--- tests/tcg/aarch64/Makefile.target | 1 + 1 file changed, 1 insertion(+)
tests/tcg/aarch64/Makefile.target +1 -0
@@ -72,6 +72,7 @@ endif # SME Tests ifneq ($(CROSS_AS_HAS_ARMV9_SME),) AARCH64_TESTS += sme-outprod1 sme-smopa-1 sme-smopa-2 +sme-%: CFLAGS += -Wa,-march=armv9-a+sme ifneq ($(CROSS_CC_HAS_FNO_INTEGRATED_AS),) sme-%: CFLAGS += -fno-integrated-as endif
Signature · 1 line
2.45.2
PATCH v3 3/7 tests/tcg/aarch64: Fix test architecture specification
In reply to Akihiko Odakisme-smopa-2.c requires sme-i16i64 but the compiler option used not to specify it. Instead, the extension was specified with the inline assembly, resulting in mixing assembly code targeting sme-i1664 and C code that does not target sme-i1664.
clang version 18.1.6 does not support such mixing so properly specify the extension with the compiler option instead.
--- tests/tcg/aarch64/sme-smopa-2.c | 2 +- tests/tcg/aarch64/Makefile.target | 18 ++++++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-)
tests/tcg/aarch64/sme-smopa-2.c +1 -1
@@ -14,7 +14,7 @@ int main()long svl;/* Validate that we have a wide enough vector for 4 elements. */ - asm(".arch armv8-r+sme-i64\n\trdsvl %0, #1" :"=r" (svl)); + asm("rdsvl %0, #1" :"=r" (svl));if (svl <32 ) {return 0 ; }
tests/tcg/aarch64/Makefile.target +14 -4
@@ -30,7 +30,8 @@ config-cc.mak: Makefile $(call cc-option,-march=armv8.5-a, CROSS_CC_HAS_ARMV8_5); \ $(call cc-option,-mbranch-protection=standard, CROSS_CC_HAS_ARMV8_BTI); \ $(call cc-option,-march=armv8.5-a+memtag, CROSS_CC_HAS_ARMV8_MTE); \ - $(call cc-option,-Wa$(COMMA)-march=armv9-a+sme $$fno_integrated_as, CROSS_AS_HAS_ARMV9_SME)) 3> config-cc.mak + $(call cc-option,-Wa$(COMMA)-march=armv9-a+sme $$fno_integrated_as, CROSS_AS_HAS_ARMV9_SME); \ + $(call cc-option,-march=armv9-a+sme-i16i64 $$fno_integrated_as, CROSS_AS_HAS_ARMV9_SME_I1664)) 3> config-cc.mak -include config-cc.mak ifneq ($(CROSS_CC_HAS_ARMV8_2),)
@@ -71,10 +72,19 @@ endif # SME Tests ifneq ($(CROSS_AS_HAS_ARMV9_SME),) -AARCH64_TESTS += sme-outprod1 sme-smopa-1 sme-smopa-2 -sme-%: CFLAGS += -Wa,-march=armv9-a+sme +AARCH64_TESTS += sme-outprod1 sme-smopa-1 +sme-outprod1 sme-smopa-1: CFLAGS += -Wa,-march=armv9-a+sme ifneq ($(CROSS_CC_HAS_FNO_INTEGRATED_AS),) -sme-%: CFLAGS += -fno-integrated-as +sme-outprod1 sme-smopa-1: CFLAGS += -fno-integrated-as +endif +endif + +# SME I16I64 Tests +ifneq ($(CROSS_AS_HAS_ARMV9_SME_I1664),) +AARCH64_TESTS += sme-smopa-2 +sme-smopa-2: CFLAGS += -march=armv9-a+sme-i16i64 +ifneq ($(CROSS_CC_HAS_FNO_INTEGRATED_AS),) +sme-smopa-2: CFLAGS += -fno-integrated-as endif endif
Signature · 1 line
2.45.2
PATCH v3 4/7 tests/tcg/aarch64: Explicitly specify register width
In reply to Akihiko Odakiclang version 18.1.6 assumes a register is 64-bit by default and complains if a 32-bit value is given. Explicitly specify register width when passing a 32-bit value.
--- tests/tcg/aarch64/bti-1.c | 6 +++--- tests/tcg/aarch64/bti-3.c | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-)
tests/tcg/aarch64/bti-1.c +3 -3
@@ -17,15 +17,15 @@ static void skip2_sigill(int sig, siginfo_t *info, ucontext_t *uc)#define BTI_JC "hint #38"#define BTYPE_1 (DEST ) \ - asm("mov %0,#1; adr x16, 1f; br x16; 1: " DEST "; mov %0,#0" \ + asm("mov %w0,#1; adr x16, 1f; br x16; 1: " DEST "; mov %w0,#0" \ : "=r"(skipped) : : "x16")#define BTYPE_2 (DEST ) \ - asm("mov %0,#1; adr x16, 1f; blr x16; 1: " DEST "; mov %0,#0" \ + asm("mov %w0,#1; adr x16, 1f; blr x16; 1: " DEST "; mov %w0,#0" \ : "=r"(skipped) : : "x16", "x30")#define BTYPE_3 (DEST ) \ - asm("mov %0,#1; adr x15, 1f; br x15; 1: " DEST "; mov %0,#0" \ + asm("mov %w0,#1; adr x15, 1f; br x15; 1: " DEST "; mov %w0,#0" \ : "=r"(skipped) : : "x15")#define TEST (WHICH ,DEST ,EXPECT ) \
tests/tcg/aarch64/bti-3.c +3 -3
@@ -11,15 +11,15 @@ static void skip2_sigill(int sig, siginfo_t *info, ucontext_t *uc) }#define BTYPE_1 () \ - asm("mov %0,#1; adr x16, 1f; br x16; 1: hint #25; mov %0,#0" \ + asm("mov %w0,#1; adr x16, 1f; br x16; 1: hint #25; mov %w0,#0" \ : "=r"(skipped) : : "x16", "x30")#define BTYPE_2 () \ - asm("mov %0,#1; adr x16, 1f; blr x16; 1: hint #25; mov %0,#0" \ + asm("mov %w0,#1; adr x16, 1f; blr x16; 1: hint #25; mov %w0,#0" \ : "=r"(skipped) : : "x16", "x30")#define BTYPE_3 () \ - asm("mov %0,#1; adr x15, 1f; br x15; 1: hint #25; mov %0,#0" \ + asm("mov %w0,#1; adr x15, 1f; br x15; 1: hint #25; mov %w0,#0" \ : "=r"(skipped) : : "x15", "x30")#define TEST (WHICH ,EXPECT ) \
Signature · 1 line
2.45.2
PATCH v3 5/7 tests/tcg/aarch64: Fix irg operand type
In reply to Akihiko Odakiirg expects 64-bit integers. Passing a 32-bit integer results in compilation failure with clang version 18.1.6.
--- tests/tcg/aarch64/mte-1.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tests/tcg/aarch64/mte-1.c +1 -1
@@ -15,7 +15,7 @@ int main(int ac, char **av)enable_mte (PR_MTE_TCF_NONE ); p0 =alloc_mte_mem (sizeof (*p0)); - asm("irg %0,%1,%2" :"=r" (p1) :"r" (p0),"r" (1 )); + asm("irg %0,%1,%2" :"=r" (p1) :"r" (p0),"r" (1l ));assert (p1 != p0); asm("subp %0,%1,%2" :"=r" (c) :"r" (p0),"r" (p1));assert (c ==0 );
Signature · 1 line
2.45.2
PATCH v3 6/7 tests/tcg/aarch64: Do not use x constraint
In reply to Akihiko Odakiclang version 18.1.6 does not support x constraint for AArch64. Use w instead.
--- tests/tcg/arm/fcvt.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
tests/tcg/arm/fcvt.c +7 -7
@@ -126,7 +126,7 @@ static void convert_single_to_half(void) asm("vcvtb.f16.f32 %0, %1" :"=t" (output) :"x" (input));#else uint16_t output; - asm("fcvt %h0, %s1" :"=w" (output) :"x" (input)); + asm("fcvt %h0, %s1" :"=w" (output) :"w" (input));#endif print_half_number (i, output); }
@@ -149,7 +149,7 @@ static void convert_single_to_double(void)#if defined(__arm__) asm("vcvt.f64.f32 %P0, %1" :"=w" (output) :"t" (input));#else - asm("fcvt %d0, %s1" :"=w" (output) :"x" (input)); + asm("fcvt %d0, %s1" :"=w" (output) :"w" (input));#endif print_double_number (i, output); }
@@ -244,7 +244,7 @@ static void convert_double_to_half(void)/* asm("vcvtb.f16.f64 %0, %P1" : "=t" (output) : "x" (input)); */ output = input;#else - asm("fcvt %h0, %d1" :"=w" (output) :"x" (input)); + asm("fcvt %h0, %d1" :"=w" (output) :"w" (input));#endif print_half_number (i, output); }
@@ -267,7 +267,7 @@ static void convert_double_to_single(void)#if defined(__arm__) asm("vcvt.f32.f64 %0, %P1" :"=w" (output) :"x" (input));#else - asm("fcvt %s0, %d1" :"=w" (output) :"x" (input)); + asm("fcvt %s0, %d1" :"=w" (output) :"w" (input));#endif print_single_number (i, output);
@@ -335,7 +335,7 @@ static void convert_half_to_double(void)/* asm("vcvtb.f64.f16 %P0, %1" : "=w" (output) : "t" (input)); */ output = input;#else - asm("fcvt %d0, %h1" :"=w" (output) :"x" (input)); + asm("fcvt %d0, %h1" :"=w" (output) :"w" (input));#endif print_double_number (i, output); }
@@ -357,7 +357,7 @@ static void convert_half_to_single(void)#if defined(__arm__) asm("vcvtb.f32.f16 %0, %1" :"=w" (output) :"x" ((uint32_t )input));#else - asm("fcvt %s0, %h1" :"=w" (output) :"x" (input)); + asm("fcvt %s0, %h1" :"=w" (output) :"w" (input));#endif print_single_number (i, output); }
@@ -380,7 +380,7 @@ static void convert_half_to_integer(void)/* asm("vcvt.s32.f16 %0, %1" : "=t" (output) : "t" (input)); v8.2*/ output = input;#else - asm("fcvt %s0, %h1" :"=w" (output) :"x" (input)); + asm("fcvt %s0, %h1" :"=w" (output) :"w" (input));#endif print_int64 (i, output); }
Signature · 1 line
2.45.2
PATCH v3 7/7 tests/tcg/arm: Manually bit-cast half-precision numbers
In reply to Akihiko Odakiclang version 18.1.6 does not allow specifying an integer as the value of a single-precision register. Manually bit-cast into float with vmov first.
--- tests/tcg/arm/fcvt.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
tests/tcg/arm/fcvt.c +3 -1
@@ -355,7 +355,9 @@ static void convert_half_to_single(void)print_half_number (i, input);#if defined(__arm__) - asm("vcvtb.f32.f16 %0, %1" :"=w" (output) :"x" ((uint32_t )input)); +float tmp; + asm("vmov %0, %1" :"=w" (tmp) :"r" (input)); + asm("vcvtb.f32.f16 %0, %1" :"=w" (output) :"x" (tmp));#else asm("fcvt %s0, %h1" :"=w" (output) :"w" (input));#endif
Signature · 1 line
2.45.2
Re: [PATCH v3 7/7] tests/tcg/arm: Manually bit-cast half-precision numbers
Quoted 14 lines · Akihiko Odaki
clang version 18.1.6 does not allow specifying an integer as the value of a single-precision register. Manually bit-cast into float with vmov first.
Signed-off-by Akihiko Odaki <[email protected]>--- tests/tcg/arm/fcvt.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)tests/tcg/arm/fcvt.c +0
-0
tests/tcg/arm/fcvt.c static void convert_half_to_single(void) · line 363
Quoted 10 lines
tests/tcg/arm/fcvt.c +3
-1@@ -355,7 +355,9 @@ static void convert_half_to_single(void)print_half_number (i, input);#if defined(__arm__) - asm("vcvtb.f32.f16 %0, %1" :"=w" (output) :"x" ((uint32_t )input)); +float tmp; + asm("vmov %0, %1" :"=w" (tmp) :"r" (input)); + asm("vcvtb.f32.f16 %0, %1" :"=w" (output) :"x" (tmp));#else asm("fcvt %s0, %h1" :"=w" (output) :"w" (input));#endif
Better as
#if defined(__arm__)
- asm("vcvtb.f32.f16 %0, %1" : "=w" (output) : "x" ((uint32_t)input));
+ /*
+ * Clang refuses to allocate an integer to a fp register. + * Perform the move from a general register by hand. + */
+ asm("vmov %0, %1\n\t"
+ "vcvtb.f32.f16 %0, %0" : "=w" (output) : "r" (input));
#else
without the C temporary. With that,
r~