[PATCH-for-10.2 3/3] target/arm/tcg: Undefine Solaris FSCALE definition as a kludge

Philippe Mathieu-Daudé posted 3 patches 2 days, 15 hours ago
Maintainers: Paolo Bonzini <pbonzini@redhat.com>, "Marc-André Lureau" <marcandre.lureau@redhat.com>, "Daniel P. Berrangé" <berrange@redhat.com>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, Li Zhijian <lizhijian@fujitsu.com>, Peter Xu <peterx@redhat.com>, Michael Roth <michael.roth@amd.com>, Kostiantyn Kostiuk <kkostiuk@redhat.com>, Peter Maydell <peter.maydell@linaro.org>
[PATCH-for-10.2 3/3] target/arm/tcg: Undefine Solaris FSCALE definition as a kludge
Posted by Philippe Mathieu-Daudé 2 days, 15 hours ago
 CONFIG_SOLARIS_FSCALE

Solaris defines FSCALE in <sys/param.h>:

  301 /*
  302  * Scale factor for scaled integers used to count
  303  * %cpu time and load averages.
  304  */
  305 #define FSHIFT  8               /* bits to right of fixed binary point */
  306 #define FSCALE  (1<<FSHIFT)

When emulating the SVE FSCALE instruction, we defines the same name
in decodetree format in target/arm/tcg/sve.decode:

  1129:FSCALE          01100101 .. 00 1001 100 ... ..... .....    @rdn_pg_rm

This leads to a definition clash:

  In file included from ../target/arm/tcg/translate-sve.c:21:
  ../target/arm/tcg/translate.h:875:17: error: pasting "trans_" and "(" does not give a valid preprocessing token
    875 |     static bool trans_##NAME(DisasContext *s, arg_##NAME *a) \
        |                 ^~~~~~
  ../target/arm/tcg/translate-sve.c:4205:5: note: in expansion of macro 'TRANS_FEAT'
   4205 |     TRANS_FEAT(NAME, FEAT, gen_gvec_fpst_arg_zpzz, name##_zpzz_fns[a->esz], a)
        |     ^~~~~~~~~~
  ../target/arm/tcg/translate-sve.c:4249:1: note: in expansion of macro 'DO_ZPZZ_FP'
   4249 | DO_ZPZZ_FP(FSCALE, aa64_sve, sve_fscalbn)
        | ^~~~~~~~~~
  ../target/arm/tcg/translate-sve.c:4249:12: error: expected declaration specifiers or '...' before numeric constant
   4249 | DO_ZPZZ_FP(FSCALE, aa64_sve, sve_fscalbn)
        |            ^~~~~~
  ../target/arm/tcg/translate.h:875:25: note: in definition of macro 'TRANS_FEAT'
    875 |     static bool trans_##NAME(DisasContext *s, arg_##NAME *a) \
        |                         ^~~~
  ../target/arm/tcg/translate-sve.c:4249:1: note: in expansion of macro 'DO_ZPZZ_FP'
   4249 | DO_ZPZZ_FP(FSCALE, aa64_sve, sve_fscalbn)
        | ^~~~~~~~~~
  ../target/arm/tcg/translate.h:875:47: error: pasting "arg_" and "(" does not give a valid preprocessing token
    875 |     static bool trans_##NAME(DisasContext *s, arg_##NAME *a) \
        |                                               ^~~~
  ../target/arm/tcg/translate-sve.c:4205:5: note: in expansion of macro 'TRANS_FEAT'
   4205 |     TRANS_FEAT(NAME, FEAT, gen_gvec_fpst_arg_zpzz, name##_zpzz_fns[a->esz], a)
        |     ^~~~~~~~~~
  ../target/arm/tcg/translate-sve.c:4249:1: note: in expansion of macro 'DO_ZPZZ_FP'
   4249 | DO_ZPZZ_FP(FSCALE, aa64_sve, sve_fscalbn)
        | ^~~~~~~~~~
  In file included from ../target/arm/tcg/translate-sve.c:100:
  libqemu-aarch64-softmmu.a.p/decode-sve.c.inc:1227:13: warning: 'trans_FSCALE' used but never defined
   1227 | static bool trans_FSCALE(DisasContext *ctx, arg_FSCALE *a);
        |             ^~~~~~~~~~~~
  ../target/arm/tcg/translate-sve.c:4249:30: warning: 'sve_fscalbn_zpzz_fns' defined but not used [-Wunused-const-variable=]
   4249 | DO_ZPZZ_FP(FSCALE, aa64_sve, sve_fscalbn)
        |                              ^~~~~~~~~~~
  ../target/arm/tcg/translate-sve.c:4201:42: note: in definition of macro 'DO_ZPZZ_FP'
   4201 |     static gen_helper_gvec_4_ptr * const name##_zpzz_fns[4] = { \
        |                                          ^~~~

As a kludge, check the definition existence with meson, then undefine
it locally in target/arm/tcg/translate-sve.c file.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 meson.build                    | 3 +++
 target/arm/tcg/translate-sve.c | 3 +++
 2 files changed, 6 insertions(+)

diff --git a/meson.build b/meson.build
index 72edd6097a4..65dd2bc6873 100644
--- a/meson.build
+++ b/meson.build
@@ -2779,6 +2779,9 @@ config_host_data.set('HAVE_TCP_KEEPINTVL',
                      #endif
                      int main(void) { return 0; }''',
                      name: 'Win32 TCP_KEEPINTVL'))
+if host_os == 'sunos'
+  config_host_data.set('CONFIG_SOLARIS_FSCALE', cc.has_header_symbol('sys/param.h', 'FSCALE'))
+endif
 
 # has_member
 config_host_data.set('HAVE_SIGEV_NOTIFY_THREAD_ID',
diff --git a/target/arm/tcg/translate-sve.c b/target/arm/tcg/translate-sve.c
index 07b827fa8e8..b6fd069aa0c 100644
--- a/target/arm/tcg/translate-sve.c
+++ b/target/arm/tcg/translate-sve.c
@@ -4246,6 +4246,9 @@ DO_ZPZZ_AH_FP_B16(FMAX_zpzz, aa64_sve, sve_fmax, sve_ah_fmax)
 DO_ZPZZ_FP_B16(FMINNM_zpzz, aa64_sve, sve_fminnum)
 DO_ZPZZ_FP_B16(FMAXNM_zpzz, aa64_sve, sve_fmaxnum)
 DO_ZPZZ_AH_FP(FABD, aa64_sve, sve_fabd, sve_ah_fabd)
+#ifdef CONFIG_SOLARIS_FSCALE
+#undef FSCALE /* Kludge for Solaris which defines FSCALE in <sys/param.h> */
+#endif
 DO_ZPZZ_FP(FSCALE, aa64_sve, sve_fscalbn)
 DO_ZPZZ_FP(FDIV, aa64_sve, sve_fdiv)
 DO_ZPZZ_FP(FMULX, aa64_sve, sve_fmulx)
-- 
2.51.0


Re: [PATCH-for-10.2 3/3] target/arm/tcg: Undefine Solaris FSCALE definition as a kludge
Posted by Richard Henderson 2 days, 3 hours ago
On 11/17/25 21:38, Philippe Mathieu-Daudé wrote:
>   CONFIG_SOLARIS_FSCALE
> 
> Solaris defines FSCALE in <sys/param.h>:
> 
>    301 /*
>    302  * Scale factor for scaled integers used to count
>    303  * %cpu time and load averages.
>    304  */
>    305 #define FSHIFT  8               /* bits to right of fixed binary point */
>    306 #define FSCALE  (1<<FSHIFT)
> 
> When emulating the SVE FSCALE instruction, we defines the same name
> in decodetree format in target/arm/tcg/sve.decode:
> 
>    1129:FSCALE          01100101 .. 00 1001 100 ... ..... .....    @rdn_pg_rm
> 
> This leads to a definition clash:
> 
>    In file included from ../target/arm/tcg/translate-sve.c:21:
>    ../target/arm/tcg/translate.h:875:17: error: pasting "trans_" and "(" does not give a valid preprocessing token
>      875 |     static bool trans_##NAME(DisasContext *s, arg_##NAME *a) \
>          |                 ^~~~~~
>    ../target/arm/tcg/translate-sve.c:4205:5: note: in expansion of macro 'TRANS_FEAT'
>     4205 |     TRANS_FEAT(NAME, FEAT, gen_gvec_fpst_arg_zpzz, name##_zpzz_fns[a->esz], a)
>          |     ^~~~~~~~~~
>    ../target/arm/tcg/translate-sve.c:4249:1: note: in expansion of macro 'DO_ZPZZ_FP'
>     4249 | DO_ZPZZ_FP(FSCALE, aa64_sve, sve_fscalbn)
>          | ^~~~~~~~~~
>    ../target/arm/tcg/translate-sve.c:4249:12: error: expected declaration specifiers or '...' before numeric constant
>     4249 | DO_ZPZZ_FP(FSCALE, aa64_sve, sve_fscalbn)
>          |            ^~~~~~
>    ../target/arm/tcg/translate.h:875:25: note: in definition of macro 'TRANS_FEAT'
>      875 |     static bool trans_##NAME(DisasContext *s, arg_##NAME *a) \
>          |                         ^~~~
>    ../target/arm/tcg/translate-sve.c:4249:1: note: in expansion of macro 'DO_ZPZZ_FP'
>     4249 | DO_ZPZZ_FP(FSCALE, aa64_sve, sve_fscalbn)
>          | ^~~~~~~~~~
>    ../target/arm/tcg/translate.h:875:47: error: pasting "arg_" and "(" does not give a valid preprocessing token
>      875 |     static bool trans_##NAME(DisasContext *s, arg_##NAME *a) \
>          |                                               ^~~~
>    ../target/arm/tcg/translate-sve.c:4205:5: note: in expansion of macro 'TRANS_FEAT'
>     4205 |     TRANS_FEAT(NAME, FEAT, gen_gvec_fpst_arg_zpzz, name##_zpzz_fns[a->esz], a)
>          |     ^~~~~~~~~~
>    ../target/arm/tcg/translate-sve.c:4249:1: note: in expansion of macro 'DO_ZPZZ_FP'
>     4249 | DO_ZPZZ_FP(FSCALE, aa64_sve, sve_fscalbn)
>          | ^~~~~~~~~~
>    In file included from ../target/arm/tcg/translate-sve.c:100:
>    libqemu-aarch64-softmmu.a.p/decode-sve.c.inc:1227:13: warning: 'trans_FSCALE' used but never defined
>     1227 | static bool trans_FSCALE(DisasContext *ctx, arg_FSCALE *a);
>          |             ^~~~~~~~~~~~
>    ../target/arm/tcg/translate-sve.c:4249:30: warning: 'sve_fscalbn_zpzz_fns' defined but not used [-Wunused-const-variable=]
>     4249 | DO_ZPZZ_FP(FSCALE, aa64_sve, sve_fscalbn)
>          |                              ^~~~~~~~~~~
>    ../target/arm/tcg/translate-sve.c:4201:42: note: in definition of macro 'DO_ZPZZ_FP'
>     4201 |     static gen_helper_gvec_4_ptr * const name##_zpzz_fns[4] = { \
>          |                                          ^~~~
> 
> As a kludge, check the definition existence with meson, then undefine
> it locally in target/arm/tcg/translate-sve.c file.
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>   meson.build                    | 3 +++
>   target/arm/tcg/translate-sve.c | 3 +++
>   2 files changed, 6 insertions(+)
> 
> diff --git a/meson.build b/meson.build
> index 72edd6097a4..65dd2bc6873 100644
> --- a/meson.build
> +++ b/meson.build
> @@ -2779,6 +2779,9 @@ config_host_data.set('HAVE_TCP_KEEPINTVL',
>                        #endif
>                        int main(void) { return 0; }''',
>                        name: 'Win32 TCP_KEEPINTVL'))
> +if host_os == 'sunos'
> +  config_host_data.set('CONFIG_SOLARIS_FSCALE', cc.has_header_symbol('sys/param.h', 'FSCALE'))
> +endif
>   
>   # has_member
>   config_host_data.set('HAVE_SIGEV_NOTIFY_THREAD_ID',
> diff --git a/target/arm/tcg/translate-sve.c b/target/arm/tcg/translate-sve.c
> index 07b827fa8e8..b6fd069aa0c 100644
> --- a/target/arm/tcg/translate-sve.c
> +++ b/target/arm/tcg/translate-sve.c
> @@ -4246,6 +4246,9 @@ DO_ZPZZ_AH_FP_B16(FMAX_zpzz, aa64_sve, sve_fmax, sve_ah_fmax)
>   DO_ZPZZ_FP_B16(FMINNM_zpzz, aa64_sve, sve_fminnum)
>   DO_ZPZZ_FP_B16(FMAXNM_zpzz, aa64_sve, sve_fmaxnum)
>   DO_ZPZZ_AH_FP(FABD, aa64_sve, sve_fabd, sve_ah_fabd)
> +#ifdef CONFIG_SOLARIS_FSCALE
> +#undef FSCALE /* Kludge for Solaris which defines FSCALE in <sys/param.h> */
> +#endif
>   DO_ZPZZ_FP(FSCALE, aa64_sve, sve_fscalbn)
>   DO_ZPZZ_FP(FDIV, aa64_sve, sve_fdiv)
>   DO_ZPZZ_FP(FMULX, aa64_sve, sve_fmulx)

You don't need an ifdef for undef, just undef it.


r~