diff mbox series

[v3,7/7] tests/tcg/arm: Manually bit-cast half-precision numbers

Message ID 20240629-tcg-v3-7-fa57918bdf09@daynix.com (mailing list archive)
State New, archived
Headers show
Series tests/tcg/aarch64: Fix inline assemblies for clang | expand

Commit Message

Akihiko Odaki June 29, 2024, 8:56 a.m. UTC
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 <akihiko.odaki@daynix.com>
---
 tests/tcg/arm/fcvt.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Richard Henderson June 29, 2024, 4:21 p.m. UTC | #1
On 6/29/24 01:56, Akihiko Odaki wrote:
> 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 <akihiko.odaki@daynix.com>
> ---
>   tests/tcg/arm/fcvt.c | 4 +++-
>   1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/tests/tcg/arm/fcvt.c b/tests/tcg/arm/fcvt.c
> index f631197287a1..5263f607b59c 100644
> --- a/tests/tcg/arm/fcvt.c
> +++ b/tests/tcg/arm/fcvt.c
> @@ -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,

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>


r~
diff mbox series

Patch

diff --git a/tests/tcg/arm/fcvt.c b/tests/tcg/arm/fcvt.c
index f631197287a1..5263f607b59c 100644
--- a/tests/tcg/arm/fcvt.c
+++ b/tests/tcg/arm/fcvt.c
@@ -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