Skip to contentSkip to conversation

tests/tcg/aarch64: Fix inline assemblies for clang

PATCH Superseded Akihiko Odaki 3 participants 15 messages Jun 27, 2024 – Jun 29, 2024

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 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 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 (6):
tests/tcg/arm: Fix fcvt result messages 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              |  20 +-
 tests/tcg/aarch64/Makefile.target |  11 +-
 tests/tcg/aarch64/fcvt.ref        | 604 +++++++++++++++++++-------------------
 7 files changed, 330 insertions(+), 321 deletions(-)

---
base-commit: 046a64b9801343e2e89eef10c7a48eec8d8c0d4f
change-id: 20240624-tcg-bf8116e80afa

Best regards,

Signature · 1 line
Akihiko Odaki <[email protected]>
#1 lore raw

PATCH v2 1/6 tests/tcg/arm: Fix fcvt result messages

The test cases for "converting double-precision to single-precision" emits float but the result variable was typed as uint32_t and corrupted the printed values. Propertly type it as float.

Fixes 8ec8a55e3fc9 ("tests/tcg/arm: add fcvt test cases for AArch32/64")
---
 tests/tcg/arm/fcvt.c       |   2 +-
 tests/tcg/aarch64/fcvt.ref | 604 ++++++++++++++++++++++-----------------------
 2 files changed, 303 insertions(+), 303 deletions(-)
tests/tcg/arm/fcvt.c +1 -1
index 7ac47b564e24..05a27b2d0710 100644
@@ -258,7 +258,7 @@ static void convert_double_to_single(void)
 
     for (i = 0; i < ARRAY_SIZE(double_numbers); ++i) {
         double input = double_numbers[i].d;
-        uint32_t output;
+        float output;
 
         feclearexcept(FE_ALL_EXCEPT);
 
tests/tcg/aarch64/fcvt.ref +302 -302

992 lines not on this page · raw message

Signature · 1 line
2.45.2
#2 lore raw

Re: [PATCH v2 1/6] tests/tcg/arm: Fix fcvt result messages

Quoted 10 lines · Akihiko Odaki

The test cases for "converting double-precision to single-precision" emits float but the result variable was typed as uint32_t and corrupted the printed values. Propertly type it as float.

Fixes 8ec8a55e3fc9 ("tests/tcg/arm: add fcvt test cases for AArch32/64")
---
 tests/tcg/arm/fcvt.c       |   2 +-
 tests/tcg/aarch64/fcvt.ref | 604 ++++++++++++++++++++++-----------------------
 2 files changed, 303 insertions(+), 303 deletions(-)

Queued to testing/next, thanks. I'll take the rest of the clang bits when the remaining cases are ironed out.

Signature · 2 lines
Alex Bennée
Virtualisation Tech Lead @ Linaro
Reviewed-by on v2 1/6
#3 lore raw

Re: [PATCH v2 1/6] tests/tcg/arm: Fix fcvt result messages

In reply to Akihiko Odaki
Quoted 10 lines · Akihiko Odaki

The test cases for "converting double-precision to single-precision" emits float but the result variable was typed as uint32_t and corrupted the printed values. Propertly type it as float.

Fixes 8ec8a55e3fc9 ("tests/tcg/arm: add fcvt test cases for AArch32/64")
---
  tests/tcg/arm/fcvt.c       |   2 +-
  tests/tcg/aarch64/fcvt.ref | 604 ++++++++++++++++++++++-----------------------
  2 files changed, 303 insertions(+), 303 deletions(-)

r~

#4 lore raw

PATCH v2 2/6 tests/tcg/aarch64: Fix test architecture specification

In reply to Akihiko Odaki

sme-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 | 11 +++++++++--
 2 files changed, 10 insertions(+), 3 deletions(-)
tests/tcg/aarch64/sme-smopa-2.c +1 -1
index c9f48c3bfca2..2c9707065992 100644
@@ -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 +9 -2
index 70d728ae9af7..ad99e0e3b198 100644
@@ -27,7 +27,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, CROSS_AS_HAS_ARMV9_SME)) 3> config-cc.mak
+	    $(call cc-option,-Wa$(COMMA)-march=armv9-a+sme, CROSS_AS_HAS_ARMV9_SME); \
+	    $(call cc-option,-march=armv9-a+sme-i16i64,     CROSS_AS_HAS_ARMV9_SME_I1664)) 3> config-cc.mak
 -include config-cc.mak
 
 ifneq ($(CROSS_CC_HAS_ARMV8_2),)
@@ -68,7 +69,13 @@ endif
 
 # SME Tests
 ifneq ($(CROSS_AS_HAS_ARMV9_SME),)
-AARCH64_TESTS += sme-outprod1 sme-smopa-1 sme-smopa-2
+AARCH64_TESTS += sme-outprod1 sme-smopa-1
+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
 endif
 
 # System Registers Tests
Signature · 1 line
2.45.2
#5 lore raw

Re: [PATCH v2 2/6] tests/tcg/aarch64: Fix test architecture specification

Quoted 44 lines · Akihiko Odaki

sme-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 | 11 +++++++++--
  2 files changed, 10 insertions(+), 3 deletions(-)
tests/tcg/aarch64/sme-smopa-2.c +1 -1
index c9f48c3bfca2..2c9707065992 100644
@@ -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 +2 -1
index 70d728ae9af7..ad99e0e3b198 100644
@@ -27,7 +27,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, CROSS_AS_HAS_ARMV9_SME)) 3> config-cc.mak
+	    $(call cc-option,-Wa$(COMMA)-march=armv9-a+sme, CROSS_AS_HAS_ARMV9_SME); \
+	    $(call cc-option,-march=armv9-a+sme-i16i64,     CROSS_AS_HAS_ARMV9_SME_I1664)) 3> config-cc.mak
  -include config-cc.mak
 
  ifneq ($(CROSS_CC_HAS_ARMV8_2),)
@@ -68,7 +69,13 @@ endif
 
  # SME Tests

tests/tcg/aarch64/Makefile.target endif · line 79

Quoted 10 lines
tests/tcg/aarch64/Makefile.target +7 -1
  ifneq ($(CROSS_AS_HAS_ARMV9_SME),)
-AARCH64_TESTS += sme-outprod1 sme-smopa-1 sme-smopa-2
+AARCH64_TESTS += sme-outprod1 sme-smopa-1
+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
  endif

How interesting. We were not actually passing -march=armv9-a+sme to the assembler previously. Lack of this is what is causing sme-outprod1 to fail to build, as reported by Alex.

That said, if we use compiler directives we must have gcc-14 or newer to test this, whereas binutils supported sme (and extensions) much earlier. Given that this is all inline assembly, we do not really need compiler support.

I think we should continue to pass assembler options (-Wa,...) and detect and use clang's -no-integrated-as option as well, at least for the SME tests.

r~

#6 lore raw

PATCH v2 3/6 tests/tcg/aarch64: Explicitly specify register width

In reply to Akihiko Odaki

clang 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
index 99a879af23d4..1fada8108d22 100644
@@ -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
index 8c534c09d784..6a3bd037bcd6 100644
@@ -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
Reviewed-by on v2 3/6
#7 lore raw

Re: [PATCH v2 3/6] tests/tcg/aarch64: Explicitly specify register width

Quoted 10 lines · Akihiko Odaki

clang 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(-)

This is true of clang 14 as well, so perhaps remove the version statement entirely.

r~

#8 lore raw

Re: [PATCH v2 3/6] tests/tcg/aarch64: Explicitly specify register width

Quoted 5 lines · Richard Henderson
Quoted 4 lines · Akihiko Odaki

clang 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.

Quoted 8 lines
Quoted 6 lines

---
  tests/tcg/aarch64/bti-1.c | 6 +++---
  tests/tcg/aarch64/bti-3.c | 6 +++---

  2 files changed, 6 insertions(+), 6 deletions(-)

This is true of clang 14 as well, so perhaps remove the version statement entirely.

I noted the version because I think it is totally fine for clang to choose an appropriate register width instead of complaining about it and a future version may do so.

Quoted 2 lines

Thanks for reviewing this series,
Akihiko Odaki

#9 lore raw

PATCH v2 4/6 tests/tcg/aarch64: Fix irg operand type

In reply to Akihiko Odaki

irg 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
index 88dcd617addc..146cad4a0499 100644
@@ -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
#11 lore raw

PATCH v2 5/6 tests/tcg/aarch64: Do not use x constraint

In reply to Akihiko Odaki

clang 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
index 05a27b2d0710..157790e67961 100644
@@ -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
#13 lore raw

PATCH v2 6/6 tests/tcg/arm: Manually bit-cast half-precision numbers

In reply to 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.

---
 tests/tcg/arm/fcvt.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
tests/tcg/arm/fcvt.c +3 -1
index 157790e67961..14c9bb669c91 100644
@@ -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
#14 lore raw
In reply to Akihiko Odaki
Quoted 3 lines · Akihiko Odaki

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.

I guess there are more needed:

ninja: no work to do.
/home/alex/lsrc/qemu.git/builds/all.clang/pyvenv/bin/meson introspect --targets --tests --benchmarks | /home/alex/lsrc/qemu.git/builds/all.clang/pyvenv/bin/python3 -B scripts/mtest2make.py > Makefile.mtest
BUILD aarch64-linux-user guest-tests
tests/tcg/aarch64-linux-user: -march=armv8.1-a+sve detected
tests/tcg/aarch64-linux-user: -march=armv8.1-a+sve2 detected
tests/tcg/aarch64-linux-user: -march=armv8.2-a detected
tests/tcg/aarch64-linux-user: -march=armv8.3-a detected
tests/tcg/aarch64-linux-user: -march=armv8.5-a detected
tests/tcg/aarch64-linux-user: -mbranch-protection=standard detected
tests/tcg/aarch64-linux-user: -march=armv8.5-a+memtag detected
tests/tcg/aarch64-linux-user: -Wa,-march=armv9-a+sme detected
tests/tcg/aarch64-linux-user: -march=armv9-a+sme-i16i64 not detected
<inline asm>:11:2: error: instruction requires: sve or sme

          ptrue p0.s, vl4
          ^
  <inline asm>:12:2: error: instruction requires: sve or sme
          fmov z0.s, #1.0
          ^
  <inline asm>:20:2: error: instruction requires: sve or sme
          st1w {z0.s}, p0, [x0]
          ^
  <inline asm>:22:2: error: instruction requires: sve or sme
          st1w {z1.s}, p0, [x0]
          ^
  <inline asm>:24:2: error: instruction requires: sve or sme
          st1w {z2.s}, p0, [x0]
          ^
  <inline asm>:26:2: error: instruction requires: sve or sme
          st1w {z3.s}, p0, [x0]
          ^

6 errors generated.
make[1]: *** [Makefile:116: sme-outprod1] Error 1
make: *** [/home/alex/lsrc/qemu.git/tests/Makefile.include:50: build-tcg-tests-aarch64-linux-user] Error 2

Quoted 30 lines

---
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 (6):
tests/tcg/arm: Fix fcvt result messages 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              |  20 +-
 tests/tcg/aarch64/Makefile.target |  11 +-
 tests/tcg/aarch64/fcvt.ref        | 604 +++++++++++++++++++-------------------
 7 files changed, 330 insertions(+), 321 deletions(-)

---
base-commit: 046a64b9801343e2e89eef10c7a48eec8d8c0d4f
change-id: 20240624-tcg-bf8116e80afa

Best regards,

Signature · 2 lines
Alex Bennée
Virtualisation Tech Lead @ Linaro