Skip to contentSkip to conversation

tests/tcg: add float_madds test to multiarch

PATCH In review Alex Bennée 3 participants 5 messages Sep 13, 2019 – Sep 14, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tests/tcg: add float_madds test to multiarch

This is a generic floating point multiply and accumulate test for single precision floating point values. I've split of the common float functions into a helper library so additional tests can use the same common code.

---
 tests/tcg/multiarch/Makefile.target |   7 +-
 tests/tcg/multiarch/float_helpers.c | 208 ++++++++++++++++++++++++++++
 tests/tcg/multiarch/float_helpers.h |  26 ++++
 tests/tcg/multiarch/float_madds.c   |  78 +++++++++++
 4 files changed, 318 insertions(+), 1 deletion(-)
 create mode 100644 tests/tcg/multiarch/float_helpers.c
 create mode 100644 tests/tcg/multiarch/float_helpers.h
 create mode 100644 tests/tcg/multiarch/float_madds.c
tests/tcg/multiarch/Makefile.target +6 -1
index 657a04f802d..0446b75c456 100644
@@ -10,12 +10,17 @@ MULTIARCH_SRC=$(SRC_PATH)/tests/tcg/multiarch
 # Set search path for all sources
 VPATH 		+= $(MULTIARCH_SRC)
 MULTIARCH_SRCS   =$(notdir $(wildcard $(MULTIARCH_SRC)/*.c))
-MULTIARCH_TESTS  =$(MULTIARCH_SRCS:.c=)
+MULTIARCH_TESTS  =$(filter-out float_helpers, $(MULTIARCH_SRCS:.c=))
 
 #
 # The following are any additional rules needed to build things
 #
 
+
+float_madds: LDFLAGS+=-lm
+float_madds: float_madds.c float_helpers.c
+	$(CC) $(CFLAGS) $(EXTRA_CFLAGS) -O2 $< $(MULTIARCH_SRC)/float_helpers.c -o $@ $(LDFLAGS)
+
 testthread: LDFLAGS+=-lpthread
 
 # We define the runner for test-mmap after the individual
tests/tcg/multiarch/float_helpers.c new file +208 -0

208 lines not on this page · raw message

tests/tcg/multiarch/float_helpers.h new file +26 -0
new file mode 100644
index 00000000000..4a1e2f3853a
@@ -0,0 +1,26 @@
+/*
+ * Common Float Helpers
+ *
+ * Copyright (c) 2019 Linaro
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#include <inttypes.h>
+
+/* Number of constants in each table */
+extern const int num_f16;
+extern const int num_f32;
+extern const int num_f64;
+
+/* Accessor helpers */
+uint16_t get_f16(int i); /* use _Float16 when we can */
+float    get_f32(int i);
+double   get_f64(int i);
+
+/* Return format strings, free after use */
+char * fmt_f16(uint16_t);
+char * fmt_f32(float);
+char * fmt_f64(double);
+/* exception flags */
+char * fmt_flags(void);
tests/tcg/multiarch/float_madds.c new file +78 -0

78 lines not on this page · raw message

Signature · 1 line
2.20.1
#1 lore raw
Quoted 22 lines · Alex Bennée
tests/tcg/multiarch/float_helpers.c new file +22 -0
+static float f32_numbers[] = {
+    -SNANF,
+    -NAN,
+    -INFINITY,
+    -FLT_MAX,
+    -1.111E+31,
+    -1.111E+30,
+    -1.08700982e-12,
+    -1.78051176e-20,
+    -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 */
+    2.0,
+    M_E, M_PI,
+    65503.0,
+    65504.0, /* max FP16 */

tests/tcg/multiarch/float_helpers.c line 112

Quoted 10 lines
tests/tcg/multiarch/float_helpers.c new file +10 -0
+    65505.0,
+    131007.0,
+    131008.0, /* max AFP */
+    131009.0,
+    1.111E+30,
+    FLT_MAX,
+    INFINITY,
+    NAN,
+    SNANF
+};

I've noticed that Glibc prefers to use hex representation for float values, to ensure an accurate representation. If you care to do so, here they are:

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   
};

PC

#2 lore raw
In reply to Alex Bennée

tests/tcg/multiarch/float_madds.c line 69

Quoted 2 lines · Alex Bennée
tests/tcg/multiarch/float_madds.c new file +2 -0
+                    /* must be built with -O2 to generate fused op */
+                    r = a * b + c;

I would prefer to use fmaf() or __builtin_fmaf() here.

Although you'll need to link with -lm just in case the target doesn't support an instruction for fmaf and so the builtin expands to the standard library call.

I also like Paul's suggestion to use hex float constants.

r~

#3 lore raw
Quoted 9 lines · Richard Henderson

tests/tcg/multiarch/float_madds.c line 69

Quoted 2 lines · Alex Bennée
tests/tcg/multiarch/float_madds.c new file +2 -0
+                    /* must be built with -O2 to generate fused op */
+                    r = a * b + c;

I would prefer to use fmaf() or __builtin_fmaf() here.

Although you'll need to link with -lm just in case the target doesn't support an instruction for fmaf and so the builtin expands to the standard library call.

I can do that - we have other tests that link to libm.

I was expecting to see more breakage but the ppc64 tests all passed (or at least against the power8 David ran it on). What am I missing to hit the cases you know are broken?

I've also experimented with reducing the number of iterations because if we want to have golden references we probably don't want to dump several hundred kilobytes of "golden" references into the source tree.

Quoted 1 line

I also like Paul's suggestion to use hex float constants.

Hmm I guess - look a bit weird but I guess that's lack of familiarity. Is is still normalised? I guess the frac shows up (without the implicit bit).

Quoted 3 lines

r~

--
Alex Bennée

#4 lore raw
Quoted 13 lines · Alex Bennée
Quoted 9 lines · Richard Henderson

tests/tcg/multiarch/float_madds.c line 69

Quoted 2 lines · Alex Bennée
tests/tcg/multiarch/float_madds.c new file +2 -0
+                    /* must be built with -O2 to generate fused op */
+                    r = a * b + c;

I would prefer to use fmaf() or __builtin_fmaf() here.

Although you'll need to link with -lm just in case the target doesn't support an instruction for fmaf and so the builtin expands to the standard library call.

Quoted 5 lines

I can do that - we have other tests that link to libm.

I was expecting to see more breakage but the ppc64 tests all passed (or at least against the power8 David ran it on). What am I missing to hit the cases you know are broken?

I would *expect* the test to pass when run natively on power8 hardware. Did it not fail when run via qemu? If not, then we didn't really choose the argument sets that are affected by double rounding.

I would expect the inputs that Paul used in the original report to be candidates. Otherwise, we should grab some from the glibc fma test case(s).

Quoted 9 lines

I've also experimented with reducing the number of iterations because if we want to have golden references we probably don't want to dump several hundred kilobytes of "golden" references into the source tree.

Quoted 1 line

I also like Paul's suggestion to use hex float constants.

Hmm I guess - look a bit weird but I guess that's lack of familiarity. Is is still normalised? I guess the frac shows up (without the implicit bit).

The implicit bit is there: 0x1.xxx. The representation is always normalized; you write denormal numbers by using an exponent that would require denormalization.

r~