Older versions of Clang (before 3.5) and GCC (before 4.1) do not
support the "__attribute__((flatten))" yet. We don't care about
such old versions of GCC anymore, but since Clang 3.4 is still
used in EPEL for RHEL7 / CentOS 7, we should not use this attribute
directly but with a wrapper macro instead.
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
v2: Ignore older versions of GCC since we do not support them anymore
fpu/softfloat.c | 39 +++++++++++++++------------------------
include/qemu/compiler.h | 16 ++++++++++++++++
2 files changed, 31 insertions(+), 24 deletions(-)
diff --git a/fpu/softfloat.c b/fpu/softfloat.c
index 59ca356..8b91cd6 100644
--- a/fpu/softfloat.c
+++ b/fpu/softfloat.c
@@ -726,8 +726,7 @@ static FloatParts addsub_floats(FloatParts a, FloatParts b, bool subtract,
* IEC/IEEE Standard for Binary Floating-Point Arithmetic.
*/
-float16 __attribute__((flatten)) float16_add(float16 a, float16 b,
- float_status *status)
+float16 QEMU_FLATTEN float16_add(float16 a, float16 b, float_status *status)
{
FloatParts pa = float16_unpack_canonical(a, status);
FloatParts pb = float16_unpack_canonical(b, status);
@@ -736,8 +735,7 @@ float16 __attribute__((flatten)) float16_add(float16 a, float16 b,
return float16_round_pack_canonical(pr, status);
}
-float32 __attribute__((flatten)) float32_add(float32 a, float32 b,
- float_status *status)
+float32 QEMU_FLATTEN float32_add(float32 a, float32 b, float_status *status)
{
FloatParts pa = float32_unpack_canonical(a, status);
FloatParts pb = float32_unpack_canonical(b, status);
@@ -746,8 +744,7 @@ float32 __attribute__((flatten)) float32_add(float32 a, float32 b,
return float32_round_pack_canonical(pr, status);
}
-float64 __attribute__((flatten)) float64_add(float64 a, float64 b,
- float_status *status)
+float64 QEMU_FLATTEN float64_add(float64 a, float64 b, float_status *status)
{
FloatParts pa = float64_unpack_canonical(a, status);
FloatParts pb = float64_unpack_canonical(b, status);
@@ -756,8 +753,7 @@ float64 __attribute__((flatten)) float64_add(float64 a, float64 b,
return float64_round_pack_canonical(pr, status);
}
-float16 __attribute__((flatten)) float16_sub(float16 a, float16 b,
- float_status *status)
+float16 QEMU_FLATTEN float16_sub(float16 a, float16 b, float_status *status)
{
FloatParts pa = float16_unpack_canonical(a, status);
FloatParts pb = float16_unpack_canonical(b, status);
@@ -766,8 +762,7 @@ float16 __attribute__((flatten)) float16_sub(float16 a, float16 b,
return float16_round_pack_canonical(pr, status);
}
-float32 __attribute__((flatten)) float32_sub(float32 a, float32 b,
- float_status *status)
+float32 QEMU_FLATTEN float32_sub(float32 a, float32 b, float_status *status)
{
FloatParts pa = float32_unpack_canonical(a, status);
FloatParts pb = float32_unpack_canonical(b, status);
@@ -776,8 +771,7 @@ float32 __attribute__((flatten)) float32_sub(float32 a, float32 b,
return float32_round_pack_canonical(pr, status);
}
-float64 __attribute__((flatten)) float64_sub(float64 a, float64 b,
- float_status *status)
+float64 QEMU_FLATTEN float64_sub(float64 a, float64 b, float_status *status)
{
FloatParts pa = float64_unpack_canonical(a, status);
FloatParts pb = float64_unpack_canonical(b, status);
@@ -835,8 +829,7 @@ static FloatParts mul_floats(FloatParts a, FloatParts b, float_status *s)
g_assert_not_reached();
}
-float16 __attribute__((flatten)) float16_mul(float16 a, float16 b,
- float_status *status)
+float16 QEMU_FLATTEN float16_mul(float16 a, float16 b, float_status *status)
{
FloatParts pa = float16_unpack_canonical(a, status);
FloatParts pb = float16_unpack_canonical(b, status);
@@ -845,8 +838,7 @@ float16 __attribute__((flatten)) float16_mul(float16 a, float16 b,
return float16_round_pack_canonical(pr, status);
}
-float32 __attribute__((flatten)) float32_mul(float32 a, float32 b,
- float_status *status)
+float32 QEMU_FLATTEN float32_mul(float32 a, float32 b, float_status *status)
{
FloatParts pa = float32_unpack_canonical(a, status);
FloatParts pb = float32_unpack_canonical(b, status);
@@ -855,8 +847,7 @@ float32 __attribute__((flatten)) float32_mul(float32 a, float32 b,
return float32_round_pack_canonical(pr, status);
}
-float64 __attribute__((flatten)) float64_mul(float64 a, float64 b,
- float_status *status)
+float64 QEMU_FLATTEN float64_mul(float64 a, float64 b, float_status *status)
{
FloatParts pa = float64_unpack_canonical(a, status);
FloatParts pb = float64_unpack_canonical(b, status);
@@ -1068,7 +1059,7 @@ static FloatParts muladd_floats(FloatParts a, FloatParts b, FloatParts c,
return a;
}
-float16 __attribute__((flatten)) float16_muladd(float16 a, float16 b, float16 c,
+float16 QEMU_FLATTEN float16_muladd(float16 a, float16 b, float16 c,
int flags, float_status *status)
{
FloatParts pa = float16_unpack_canonical(a, status);
@@ -1079,7 +1070,7 @@ float16 __attribute__((flatten)) float16_muladd(float16 a, float16 b, float16 c,
return float16_round_pack_canonical(pr, status);
}
-float32 __attribute__((flatten)) float32_muladd(float32 a, float32 b, float32 c,
+float32 QEMU_FLATTEN float32_muladd(float32 a, float32 b, float32 c,
int flags, float_status *status)
{
FloatParts pa = float32_unpack_canonical(a, status);
@@ -1090,7 +1081,7 @@ float32 __attribute__((flatten)) float32_muladd(float32 a, float32 b, float32 c,
return float32_round_pack_canonical(pr, status);
}
-float64 __attribute__((flatten)) float64_muladd(float64 a, float64 b, float64 c,
+float64 QEMU_FLATTEN float64_muladd(float64 a, float64 b, float64 c,
int flags, float_status *status)
{
FloatParts pa = float64_unpack_canonical(a, status);
@@ -2402,21 +2393,21 @@ static FloatParts sqrt_float(FloatParts a, float_status *s, const FloatFmt *p)
return a;
}
-float16 __attribute__((flatten)) float16_sqrt(float16 a, float_status *status)
+float16 QEMU_FLATTEN float16_sqrt(float16 a, float_status *status)
{
FloatParts pa = float16_unpack_canonical(a, status);
FloatParts pr = sqrt_float(pa, status, &float16_params);
return float16_round_pack_canonical(pr, status);
}
-float32 __attribute__((flatten)) float32_sqrt(float32 a, float_status *status)
+float32 QEMU_FLATTEN float32_sqrt(float32 a, float_status *status)
{
FloatParts pa = float32_unpack_canonical(a, status);
FloatParts pr = sqrt_float(pa, status, &float32_params);
return float32_round_pack_canonical(pr, status);
}
-float64 __attribute__((flatten)) float64_sqrt(float64 a, float_status *status)
+float64 QEMU_FLATTEN float64_sqrt(float64 a, float_status *status)
{
FloatParts pa = float64_unpack_canonical(a, status);
FloatParts pr = sqrt_float(pa, status, &float64_params);
diff --git a/include/qemu/compiler.h b/include/qemu/compiler.h
index 5843812..a4aafa1 100644
--- a/include/qemu/compiler.h
+++ b/include/qemu/compiler.h
@@ -122,6 +122,22 @@
#ifndef __has_feature
#define __has_feature(x) 0 /* compatibility with non-clang compilers */
#endif
+
+#ifndef __has_attribute
+#define __has_attribute(x) 0 /* compatibility with older GCC */
+#endif
+
+/*
+ * GCC doesn't provide __has_attribute() until GCC 5, but we know all the GCC
+ * versions we support have the "flatten" attribute. Clang may not have the
+ * "flatten" attribute but always has __has_attribute() to check for it.
+ */
+#if __has_attribute(flatten) || !defined(__clang__)
+# define QEMU_FLATTEN __attribute__((flatten))
+#else
+# define QEMU_FLATTEN
+#endif
+
/* Implement C11 _Generic via GCC builtins. Example:
*
* QEMU_GENERIC(x, (float, sinf), (long double, sinl), sin) (x)
--
1.8.3.1
Thomas Huth <thuth@redhat.com> writes: > Older versions of Clang (before 3.5) and GCC (before 4.1) do not > support the "__attribute__((flatten))" yet. We don't care about > such old versions of GCC anymore, but since Clang 3.4 is still > used in EPEL for RHEL7 / CentOS 7, we should not use this attribute > directly but with a wrapper macro instead. > > Signed-off-by: Thomas Huth <thuth@redhat.com> > --- > v2: Ignore older versions of GCC since we do not support them anymore > > fpu/softfloat.c | 39 +++++++++++++++------------------------ > include/qemu/compiler.h | 16 ++++++++++++++++ > 2 files changed, 31 insertions(+), 24 deletions(-) > > diff --git a/fpu/softfloat.c b/fpu/softfloat.c > index 59ca356..8b91cd6 100644 > --- a/fpu/softfloat.c > +++ b/fpu/softfloat.c > @@ -726,8 +726,7 @@ static FloatParts addsub_floats(FloatParts a, FloatParts b, bool subtract, > * IEC/IEEE Standard for Binary Floating-Point Arithmetic. > */ > > -float16 __attribute__((flatten)) float16_add(float16 a, float16 b, > - float_status *status) > +float16 QEMU_FLATTEN float16_add(float16 a, float16 b, float_status *status) > { > FloatParts pa = float16_unpack_canonical(a, status); > FloatParts pb = float16_unpack_canonical(b, status); > @@ -736,8 +735,7 @@ float16 __attribute__((flatten)) float16_add(float16 a, float16 b, > return float16_round_pack_canonical(pr, status); > } > > -float32 __attribute__((flatten)) float32_add(float32 a, float32 b, > - float_status *status) > +float32 QEMU_FLATTEN float32_add(float32 a, float32 b, float_status *status) > { > FloatParts pa = float32_unpack_canonical(a, status); > FloatParts pb = float32_unpack_canonical(b, status); > @@ -746,8 +744,7 @@ float32 __attribute__((flatten)) float32_add(float32 a, float32 b, > return float32_round_pack_canonical(pr, status); > } > > -float64 __attribute__((flatten)) float64_add(float64 a, float64 b, > - float_status *status) > +float64 QEMU_FLATTEN float64_add(float64 a, float64 b, float_status *status) > { > FloatParts pa = float64_unpack_canonical(a, status); > FloatParts pb = float64_unpack_canonical(b, status); > @@ -756,8 +753,7 @@ float64 __attribute__((flatten)) float64_add(float64 a, float64 b, > return float64_round_pack_canonical(pr, status); > } > > -float16 __attribute__((flatten)) float16_sub(float16 a, float16 b, > - float_status *status) > +float16 QEMU_FLATTEN float16_sub(float16 a, float16 b, float_status *status) > { > FloatParts pa = float16_unpack_canonical(a, status); > FloatParts pb = float16_unpack_canonical(b, status); > @@ -766,8 +762,7 @@ float16 __attribute__((flatten)) float16_sub(float16 a, float16 b, > return float16_round_pack_canonical(pr, status); > } > > -float32 __attribute__((flatten)) float32_sub(float32 a, float32 b, > - float_status *status) > +float32 QEMU_FLATTEN float32_sub(float32 a, float32 b, float_status *status) > { > FloatParts pa = float32_unpack_canonical(a, status); > FloatParts pb = float32_unpack_canonical(b, status); > @@ -776,8 +771,7 @@ float32 __attribute__((flatten)) float32_sub(float32 a, float32 b, > return float32_round_pack_canonical(pr, status); > } > > -float64 __attribute__((flatten)) float64_sub(float64 a, float64 b, > - float_status *status) > +float64 QEMU_FLATTEN float64_sub(float64 a, float64 b, float_status *status) > { > FloatParts pa = float64_unpack_canonical(a, status); > FloatParts pb = float64_unpack_canonical(b, status); > @@ -835,8 +829,7 @@ static FloatParts mul_floats(FloatParts a, FloatParts b, float_status *s) > g_assert_not_reached(); > } > > -float16 __attribute__((flatten)) float16_mul(float16 a, float16 b, > - float_status *status) > +float16 QEMU_FLATTEN float16_mul(float16 a, float16 b, float_status *status) > { > FloatParts pa = float16_unpack_canonical(a, status); > FloatParts pb = float16_unpack_canonical(b, status); > @@ -845,8 +838,7 @@ float16 __attribute__((flatten)) float16_mul(float16 a, float16 b, > return float16_round_pack_canonical(pr, status); > } > > -float32 __attribute__((flatten)) float32_mul(float32 a, float32 b, > - float_status *status) > +float32 QEMU_FLATTEN float32_mul(float32 a, float32 b, float_status *status) > { > FloatParts pa = float32_unpack_canonical(a, status); > FloatParts pb = float32_unpack_canonical(b, status); > @@ -855,8 +847,7 @@ float32 __attribute__((flatten)) float32_mul(float32 a, float32 b, > return float32_round_pack_canonical(pr, status); > } > > -float64 __attribute__((flatten)) float64_mul(float64 a, float64 b, > - float_status *status) > +float64 QEMU_FLATTEN float64_mul(float64 a, float64 b, float_status *status) > { > FloatParts pa = float64_unpack_canonical(a, status); > FloatParts pb = float64_unpack_canonical(b, status); > @@ -1068,7 +1059,7 @@ static FloatParts muladd_floats(FloatParts a, FloatParts b, FloatParts c, > return a; > } > > -float16 __attribute__((flatten)) float16_muladd(float16 a, float16 b, float16 c, > +float16 QEMU_FLATTEN float16_muladd(float16 a, float16 b, float16 c, > int flags, float_status *status) > { > FloatParts pa = float16_unpack_canonical(a, status); > @@ -1079,7 +1070,7 @@ float16 __attribute__((flatten)) float16_muladd(float16 a, float16 b, float16 c, > return float16_round_pack_canonical(pr, status); > } > > -float32 __attribute__((flatten)) float32_muladd(float32 a, float32 b, float32 c, > +float32 QEMU_FLATTEN float32_muladd(float32 a, float32 b, float32 c, > int flags, float_status *status) > { > FloatParts pa = float32_unpack_canonical(a, status); > @@ -1090,7 +1081,7 @@ float32 __attribute__((flatten)) float32_muladd(float32 a, float32 b, float32 c, > return float32_round_pack_canonical(pr, status); > } > > -float64 __attribute__((flatten)) float64_muladd(float64 a, float64 b, float64 c, > +float64 QEMU_FLATTEN float64_muladd(float64 a, float64 b, float64 c, > int flags, float_status *status) > { > FloatParts pa = float64_unpack_canonical(a, status); > @@ -2402,21 +2393,21 @@ static FloatParts sqrt_float(FloatParts a, float_status *s, const FloatFmt *p) > return a; > } > > -float16 __attribute__((flatten)) float16_sqrt(float16 a, float_status *status) > +float16 QEMU_FLATTEN float16_sqrt(float16 a, float_status *status) > { > FloatParts pa = float16_unpack_canonical(a, status); > FloatParts pr = sqrt_float(pa, status, &float16_params); > return float16_round_pack_canonical(pr, status); > } > > -float32 __attribute__((flatten)) float32_sqrt(float32 a, float_status *status) > +float32 QEMU_FLATTEN float32_sqrt(float32 a, float_status *status) > { > FloatParts pa = float32_unpack_canonical(a, status); > FloatParts pr = sqrt_float(pa, status, &float32_params); > return float32_round_pack_canonical(pr, status); > } > > -float64 __attribute__((flatten)) float64_sqrt(float64 a, float_status *status) > +float64 QEMU_FLATTEN float64_sqrt(float64 a, float_status *status) > { > FloatParts pa = float64_unpack_canonical(a, status); > FloatParts pr = sqrt_float(pa, status, &float64_params); > diff --git a/include/qemu/compiler.h b/include/qemu/compiler.h > index 5843812..a4aafa1 100644 > --- a/include/qemu/compiler.h > +++ b/include/qemu/compiler.h > @@ -122,6 +122,22 @@ > #ifndef __has_feature > #define __has_feature(x) 0 /* compatibility with non-clang compilers */ > #endif > + > +#ifndef __has_attribute > +#define __has_attribute(x) 0 /* compatibility with older GCC */ > +#endif > + > +/* > + * GCC doesn't provide __has_attribute() until GCC 5, but we know all the GCC > + * versions we support have the "flatten" attribute. Clang may not have the > + * "flatten" attribute but always has __has_attribute() to check for it. > + */ > +#if __has_attribute(flatten) || !defined(__clang__) > +# define QEMU_FLATTEN __attribute__((flatten)) > +#else > +# define QEMU_FLATTEN > +#endif > + > /* Implement C11 _Generic via GCC builtins. Example: > * > * QEMU_GENERIC(x, (float, sinf), (long double, sinl), sin) (x) Reviewed-by: Alex Bennée <alex.bennee@linaro.org> -- Alex Bennée
On 9/26/18 11:11 PM, Thomas Huth wrote: > Older versions of Clang (before 3.5) and GCC (before 4.1) do not > support the "__attribute__((flatten))" yet. We don't care about > such old versions of GCC anymore, but since Clang 3.4 is still > used in EPEL for RHEL7 / CentOS 7, we should not use this attribute > directly but with a wrapper macro instead. > > Signed-off-by: Thomas Huth <thuth@redhat.com> > --- > v2: Ignore older versions of GCC since we do not support them anymore Reviewed-by: Richard Henderson <richard.henderson@linaro.org> r~
© 2016 - 2024 Red Hat, Inc.