
* Update to QEMU v9.0.0 --------- Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Fabiano Rosas <farosas@suse.de> Signed-off-by: Peter Xu <peterx@redhat.com> Signed-off-by: Thomas Huth <thuth@redhat.com> Signed-off-by: Cédric Le Goater <clg@redhat.com> Signed-off-by: Zheyu Ma <zheyuma97@gmail.com> Signed-off-by: Ido Plat <ido.plat@ibm.com> Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com> Signed-off-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru> Signed-off-by: David Hildenbrand <david@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com> Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com> Signed-off-by: Fiona Ebner <f.ebner@proxmox.com> Signed-off-by: Gregory Price <gregory.price@memverge.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> Signed-off-by: Lorenz Brun <lorenz@brun.one> Signed-off-by: Yao Xingtao <yaoxt.fnst@fujitsu.com> Signed-off-by: Arnaud Minier <arnaud.minier@telecom-paris.fr> Signed-off-by: Inès Varhol <ines.varhol@telecom-paris.fr> Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu> Signed-off-by: Igor Mammedov <imammedo@redhat.com> Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com> Signed-off-by: Richard Henderson <richard.henderson@linaro.org> Signed-off-by: Sven Schnelle <svens@stackframe.org> Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> Signed-off-by: Christian Schoenebeck <qemu_oss@crudebyte.com> Signed-off-by: Jason Wang <jasowang@redhat.com> Signed-off-by: Helge Deller <deller@gmx.de> Signed-off-by: Nicholas Piggin <npiggin@gmail.com> Signed-off-by: Benjamin Gray <bgray@linux.ibm.com> Signed-off-by: Avihai Horon <avihaih@nvidia.com> Signed-off-by: Michael Tokarev <mjt@tls.msk.ru> Signed-off-by: Joonas Kankaala <joonas.a.kankaala@gmail.com> Signed-off-by: Marcin Juszkiewicz <marcin.juszkiewicz@linaro.org> Signed-off-by: Stefan Weil <sw@weilnetz.de> Signed-off-by: Zhao Liu <zhao1.liu@intel.com> Signed-off-by: Glenn Miles <milesg@linux.ibm.com> Signed-off-by: Oleg Sviridov <oleg.sviridov@red-soft.ru> Signed-off-by: Artem Chernyshev <artem.chernyshev@red-soft.ru> Signed-off-by: Yajun Wu <yajunw@nvidia.com> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk> Signed-off-by: Pierre-Clément Tosi <ptosi@google.com> Signed-off-by: Lei Wang <lei4.wang@intel.com> Signed-off-by: Wei Wang <wei.w.wang@intel.com> Signed-off-by: Martin Hundebøll <martin@geanix.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org> Signed-off-by: Wafer <wafer@jaguarmicro.com> Signed-off-by: Yuxue Liu <yuxue.liu@jaguarmicro.com> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> Signed-off-by: Nguyen Dinh Phi <phind.uet@gmail.com> Signed-off-by: Zack Buhman <zack@buhman.org> Signed-off-by: Keith Packard <keithp@keithp.com> Signed-off-by: Yuquan Wang wangyuquan1236@phytium.com.cn Signed-off-by: Matheus Tavares Bernardino <quic_mathbern@quicinc.com> Signed-off-by: Cindy Lu <lulu@redhat.com> Co-authored-by: Peter Maydell <peter.maydell@linaro.org> Co-authored-by: Fabiano Rosas <farosas@suse.de> Co-authored-by: Peter Xu <peterx@redhat.com> Co-authored-by: Thomas Huth <thuth@redhat.com> Co-authored-by: Cédric Le Goater <clg@redhat.com> Co-authored-by: Zheyu Ma <zheyuma97@gmail.com> Co-authored-by: Ido Plat <ido.plat@ibm.com> Co-authored-by: Ilya Leoshkevich <iii@linux.ibm.com> Co-authored-by: Markus Armbruster <armbru@redhat.com> Co-authored-by: Marc-André Lureau <marcandre.lureau@redhat.com> Co-authored-by: Paolo Bonzini <pbonzini@redhat.com> Co-authored-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru> Co-authored-by: David Hildenbrand <david@redhat.com> Co-authored-by: Kevin Wolf <kwolf@redhat.com> Co-authored-by: Stefan Reiter <s.reiter@proxmox.com> Co-authored-by: Fiona Ebner <f.ebner@proxmox.com> Co-authored-by: Gregory Price <gregory.price@memverge.com> Co-authored-by: Lorenz Brun <lorenz@brun.one> Co-authored-by: Yao Xingtao <yaoxt.fnst@fujitsu.com> Co-authored-by: Philippe Mathieu-Daudé <philmd@linaro.org> Co-authored-by: Arnaud Minier <arnaud.minier@telecom-paris.fr> Co-authored-by: BALATON Zoltan <balaton@eik.bme.hu> Co-authored-by: Igor Mammedov <imammedo@redhat.com> Co-authored-by: Akihiko Odaki <akihiko.odaki@daynix.com> Co-authored-by: Richard Henderson <richard.henderson@linaro.org> Co-authored-by: Sven Schnelle <svens@stackframe.org> Co-authored-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> Co-authored-by: Helge Deller <deller@kernel.org> Co-authored-by: Harsh Prateek Bora <harshpb@linux.ibm.com> Co-authored-by: Benjamin Gray <bgray@linux.ibm.com> Co-authored-by: Nicholas Piggin <npiggin@gmail.com> Co-authored-by: Avihai Horon <avihaih@nvidia.com> Co-authored-by: Michael Tokarev <mjt@tls.msk.ru> Co-authored-by: Joonas Kankaala <joonas.a.kankaala@gmail.com> Co-authored-by: Marcin Juszkiewicz <marcin.juszkiewicz@linaro.org> Co-authored-by: Stefan Weil <sw@weilnetz.de> Co-authored-by: Dayu Liu <liu.dayu@zte.com.cn> Co-authored-by: Zhao Liu <zhao1.liu@intel.com> Co-authored-by: Glenn Miles <milesg@linux.vnet.ibm.com> Co-authored-by: Artem Chernyshev <artem.chernyshev@red-soft.ru> Co-authored-by: Yajun Wu <yajunw@nvidia.com> Co-authored-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk> Co-authored-by: Pierre-Clément Tosi <ptosi@google.com> Co-authored-by: Wei Wang <wei.w.wang@intel.com> Co-authored-by: Martin Hundebøll <martin@geanix.com> Co-authored-by: Michael S. Tsirkin <mst@redhat.com> Co-authored-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org> Co-authored-by: Wafer <wafer@jaguarmicro.com> Co-authored-by: lyx634449800 <yuxue.liu@jaguarmicro.com> Co-authored-by: Gerd Hoffmann <kraxel@redhat.com> Co-authored-by: Nguyen Dinh Phi <phind.uet@gmail.com> Co-authored-by: Zack Buhman <zack@buhman.org> Co-authored-by: Keith Packard <keithp@keithp.com> Co-authored-by: Yuquan Wang <wangyuquan1236@phytium.com.cn> Co-authored-by: Matheus Tavares Bernardino <quic_mathbern@quicinc.com> Co-authored-by: Cindy Lu <lulu@redhat.com>
229 lines
4.6 KiB
C
229 lines
4.6 KiB
C
/*
|
|
* Common Float Helpers
|
|
*
|
|
* This contains a series of useful utility routines and a set of
|
|
* floating point constants useful for exercising the edge cases in
|
|
* floating point tests.
|
|
*
|
|
* Copyright (c) 2019, 2024 Linaro
|
|
*
|
|
* SPDX-License-Identifier: GPL-2.0-or-later
|
|
*/
|
|
|
|
/* we want additional float type definitions */
|
|
#define __STDC_WANT_IEC_60559_BFP_EXT__
|
|
#define __STDC_WANT_IEC_60559_TYPES_EXT__
|
|
|
|
#define _GNU_SOURCE
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <inttypes.h>
|
|
#include <math.h>
|
|
#include <float.h>
|
|
#include <fenv.h>
|
|
|
|
#include "../float_helpers.h"
|
|
|
|
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
|
|
|
|
/*
|
|
* Half Precision Numbers
|
|
*
|
|
* Not yet well standardised so we return a plain uint16_t for now.
|
|
*/
|
|
|
|
/* no handy defines for these numbers */
|
|
static uint16_t f16_numbers[] = {
|
|
0xffff, /* -NaN / AHP -Max */
|
|
0xfcff, /* -NaN / AHP */
|
|
0xfc01, /* -NaN / AHP */
|
|
0xfc00, /* -Inf */
|
|
0xfbff, /* -Max */
|
|
0xc000, /* -2 */
|
|
0xbc00, /* -1 */
|
|
0x8001, /* -MIN subnormal */
|
|
0x8000, /* -0 */
|
|
0x0000, /* +0 */
|
|
0x0001, /* MIN subnormal */
|
|
0x3c00, /* 1 */
|
|
0x7bff, /* Max */
|
|
0x7c00, /* Inf */
|
|
0x7c01, /* NaN / AHP */
|
|
0x7cff, /* NaN / AHP */
|
|
0x7fff, /* NaN / AHP +Max*/
|
|
};
|
|
|
|
static const int num_f16 = ARRAY_SIZE(f16_numbers);
|
|
|
|
int get_num_f16(void)
|
|
{
|
|
return num_f16;
|
|
}
|
|
|
|
uint16_t get_f16(int i)
|
|
{
|
|
return f16_numbers[i % num_f16];
|
|
}
|
|
|
|
/* only display as hex */
|
|
char *fmt_16(uint16_t num)
|
|
{
|
|
char *fmt;
|
|
asprintf(&fmt, "f16(%#04x)", num);
|
|
return fmt;
|
|
}
|
|
|
|
/*
|
|
* Single Precision Numbers
|
|
*/
|
|
|
|
#ifndef SNANF
|
|
/* Signaling NaN macros, if supported. */
|
|
# define SNANF (__builtin_nansf (""))
|
|
# define SNAN (__builtin_nans (""))
|
|
# define SNANL (__builtin_nansl (""))
|
|
#endif
|
|
|
|
static float f32_numbers[] = {
|
|
-SNANF,
|
|
-NAN,
|
|
-INFINITY,
|
|
-FLT_MAX,
|
|
-0x1.1874b2p+103,
|
|
-0x1.c0bab6p+99,
|
|
-0x1.31f75p-40,
|
|
-0x1.505444p-66,
|
|
-FLT_MIN,
|
|
0.0,
|
|
FLT_MIN,
|
|
0x1p-25,
|
|
0x1.ffffe6p-25, /* min positive FP16 subnormal */
|
|
0x1.ff801ap-15, /* max subnormal FP16 */
|
|
0x1.00000cp-14, /* min positive normal FP16 */
|
|
1.0,
|
|
0x1.004p+0, /* smallest float after 1.0 FP16 */
|
|
2.0,
|
|
M_E, M_PI,
|
|
0x1.ffbep+15,
|
|
0x1.ffcp+15, /* max FP16 */
|
|
0x1.ffc2p+15,
|
|
0x1.ffbfp+16,
|
|
0x1.ffcp+16, /* max AFP */
|
|
0x1.ffc1p+16,
|
|
0x1.c0bab6p+99,
|
|
FLT_MAX,
|
|
INFINITY,
|
|
NAN,
|
|
SNANF
|
|
};
|
|
|
|
static const int num_f32 = ARRAY_SIZE(f32_numbers);
|
|
|
|
int get_num_f32(void)
|
|
{
|
|
return num_f32;
|
|
}
|
|
|
|
float get_f32(int i)
|
|
{
|
|
return f32_numbers[i % num_f32];
|
|
}
|
|
|
|
char *fmt_f32(float num)
|
|
{
|
|
uint32_t single_as_hex = *(uint32_t *) #
|
|
char *fmt;
|
|
asprintf(&fmt, "f32(%02.20a:%#010x)", num, single_as_hex);
|
|
return fmt;
|
|
}
|
|
|
|
|
|
/* This allows us to initialise some doubles as pure hex */
|
|
typedef union {
|
|
double d;
|
|
uint64_t h;
|
|
} test_doubles;
|
|
|
|
static test_doubles f64_numbers[] = {
|
|
{SNAN},
|
|
{-NAN},
|
|
{-INFINITY},
|
|
{-DBL_MAX},
|
|
{-FLT_MAX-1.0},
|
|
{-FLT_MAX},
|
|
{-1.111E+31},
|
|
{-1.111E+30}, /* half prec */
|
|
{-2.0}, {-1.0},
|
|
{-DBL_MIN},
|
|
{-FLT_MIN},
|
|
{0.0},
|
|
{FLT_MIN},
|
|
{2.98023224e-08},
|
|
{5.96046E-8}, /* min positive FP16 subnormal */
|
|
{6.09756E-5}, /* max subnormal FP16 */
|
|
{6.10352E-5}, /* min positive normal FP16 */
|
|
{1.0},
|
|
{1.0009765625}, /* smallest float after 1.0 FP16 */
|
|
{DBL_MIN},
|
|
{1.3789972848607228e-308},
|
|
{1.4914738736681624e-308},
|
|
{1.0}, {2.0},
|
|
{M_E}, {M_PI},
|
|
{65503.0},
|
|
{65504.0}, /* max FP16 */
|
|
{65505.0},
|
|
{131007.0},
|
|
{131008.0}, /* max AFP */
|
|
{131009.0},
|
|
{.h = 0x41dfffffffc00000 }, /* to int = 0x7fffffff */
|
|
{FLT_MAX},
|
|
{FLT_MAX + 1.0},
|
|
{DBL_MAX},
|
|
{INFINITY},
|
|
{NAN},
|
|
{.h = 0x7ff0000000000001}, /* SNAN */
|
|
{SNAN},
|
|
};
|
|
|
|
static const int num_f64 = ARRAY_SIZE(f64_numbers);
|
|
|
|
int get_num_f64(void)
|
|
{
|
|
return num_f64;
|
|
}
|
|
|
|
double get_f64(int i)
|
|
{
|
|
return f64_numbers[i % num_f64].d;
|
|
}
|
|
|
|
char *fmt_f64(double num)
|
|
{
|
|
uint64_t double_as_hex = *(uint64_t *) #
|
|
char *fmt;
|
|
asprintf(&fmt, "f64(%02.20a:%#020" PRIx64 ")", num, double_as_hex);
|
|
return fmt;
|
|
}
|
|
|
|
/*
|
|
* Float flags
|
|
*/
|
|
char *fmt_flags(void)
|
|
{
|
|
int flags = fetestexcept(FE_ALL_EXCEPT);
|
|
char *fmt;
|
|
|
|
if (flags) {
|
|
asprintf(&fmt, "%s%s%s%s%s",
|
|
flags & FE_OVERFLOW ? "OVERFLOW " : "",
|
|
flags & FE_UNDERFLOW ? "UNDERFLOW " : "",
|
|
flags & FE_DIVBYZERO ? "DIV0 " : "",
|
|
flags & FE_INEXACT ? "INEXACT " : "",
|
|
flags & FE_INVALID ? "INVALID" : "");
|
|
} else {
|
|
asprintf(&fmt, "OK");
|
|
}
|
|
|
|
return fmt;
|
|
}
|