Skip to contentSkip to conversation

fp-bench fixes

PATCH Applied Emilio G. Cota 4 participants 7 messages Dec 21, 2018 – Jan 7, 2019

lore
Share & tools
lore
#1 lore raw

PATCH 1/2 fp-bench: fix update_random_ops

The second test in the branches is wrong; fix while converting to a switch statement, which is easier to get right.

---
 tests/fp/fp-bench.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
tests/fp/fp-bench.c +8 -3
index f5bc5edebf..546bac9c9c 100644
@@ -143,15 +143,20 @@ static void update_random_ops(int n_ops, enum precision prec)
     for (i = 0; i < n_ops; i++) {
         uint64_t r = random_ops[i];
 
-        if (prec == PREC_SINGLE || PREC_FLOAT32) {
+        switch (prec) {
+        case PREC_SINGLE:
+        case PREC_FLOAT32:
             do {
                 r = xorshift64star(r);
             } while (!float32_is_normal(r));
-        } else if (prec == PREC_DOUBLE || PREC_FLOAT64) {
+            break;
+        case PREC_DOUBLE:
+        case PREC_FLOAT64:
             do {
                 r = xorshift64star(r);
             } while (!float64_is_normal(r));
-        } else {
+            break;
+        default:
             g_assert_not_reached();
         }
         random_ops[i] = r;
Signature · 1 line
2.17.1
Reviewed-by on v1 1/2
#3 lore raw

Re: [Qemu-devel] [PATCH 1/2] fp-bench: fix update_random_ops

In reply to Emilio G. Cota
Quoted 13 lines · Emilio G. Cota

The second test in the branches is wrong; fix while converting to a switch statement, which is easier to get right.

---
 tests/fp/fp-bench.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
tests/fp/fp-bench.c +0 -0
index f5bc5edebf..546bac9c9c 100644

tests/fp/fp-bench.c static void update_random_ops(int n_ops, enum precision prec) · line 146

Quoted 4 lines
tests/fp/fp-bench.c +0 -1
@@ -143,15 +143,20 @@ static void update_random_ops(int n_ops, enum precision prec)
     for (i = 0; i < n_ops; i++) {
         uint64_t r = random_ops[i];
 
-        if (prec == PREC_SINGLE || PREC_FLOAT32) {

:)

Quoted 20 lines
tests/fp/fp-bench.c +8 -2
+        switch (prec) {
+        case PREC_SINGLE:
+        case PREC_FLOAT32:
             do {
                 r = xorshift64star(r);
             } while (!float32_is_normal(r));
-        } else if (prec == PREC_DOUBLE || PREC_FLOAT64) {
+            break;
+        case PREC_DOUBLE:
+        case PREC_FLOAT64:
             do {
                 r = xorshift64star(r);
             } while (!float64_is_normal(r));
-        } else {
+            break;
+        default:
             g_assert_not_reached();
         }
         random_ops[i] = r;
#4 lore raw

PATCH 2/2 fp-bench: remove wrong exponent raise in fill_random

In reply to Emilio G. Cota

At this point random_ops[] only contains normals, so there's no need to do anything to them. In fact, raising the exponent here can make the output !normal, which is precisely what the comment says we want to avoid.

---
 tests/fp/fp-bench.c | 4 ----
 1 file changed, 4 deletions(-)
tests/fp/fp-bench.c +0 -4
index 546bac9c9c..4ba5e1d2d4 100644
@@ -176,8 +176,6 @@ static void fill_random(union fp *ops, int n_ops, enum precision prec,
             if (no_neg && float32_is_neg(ops[i].f32)) {
                 ops[i].f32 = float32_chs(ops[i].f32);
             }
-            /* raise the exponent to limit the frequency of denormal results */
-            ops[i].f32 |= 0x40000000;
             break;
         case PREC_DOUBLE:
         case PREC_FLOAT64:
@@ -185,8 +183,6 @@ static void fill_random(union fp *ops, int n_ops, enum precision prec,
             if (no_neg && float64_is_neg(ops[i].f64)) {
                 ops[i].f64 = float64_chs(ops[i].f64);
             }
-            /* raise the exponent to limit the frequency of denormal results */
-            ops[i].f64 |= LIT64(0x4000000000000000);
             break;
         default:
             g_assert_not_reached();
Signature · 1 line
2.17.1
Reviewed-by on v1 2/2
#5 lore raw

Re: [Qemu-devel] [PATCH 2/2] fp-bench: remove wrong exponent raise in fill_random

Quoted 9 lines · Emilio G. Cota

At this point random_ops[] only contains normals, so there's no need to do anything to them. In fact, raising the exponent here can make the output !normal, which is precisely what the comment says we want to avoid.

---
 tests/fp/fp-bench.c | 4 ----
 1 file changed, 4 deletions(-)

r~