[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v4 6/6] qht: Fix threshold rate calculation
From: |
Richard Henderson |
Subject: |
[PATCH v4 6/6] qht: Fix threshold rate calculation |
Date: |
Wed, 17 Jun 2020 13:13:09 -0700 |
tests/qht-bench.c:287:29: error: implicit conversion from 'unsigned long'
to 'double' changes value from 18446744073709551615
to 18446744073709551616 [-Werror,-Wimplicit-int-float-conversion]
*threshold = rate * UINT64_MAX;
~ ^~~~~~~~~~
Fix this by splitting the 64-bit constant into two halves,
each of which is individually perfectly representable, the
sum of which produces the correct arithmetic result.
Cc: Emilio G. Cota <cota@braap.org>
Reported-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
Question: Should we really be scaling by UINT64_MAX?
The comparisons against info->r mean that 1.0 is exceedingly unlikely
to hit. Or if that is supposed to be the point, why is is the test
r >= threshold
not
r > threshold
where, if threshold == UINT64_MAX, there is zero chance of the
test being true for 1.0.
---
tests/qht-bench.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/tests/qht-bench.c b/tests/qht-bench.c
index e3b512f26f..eb88a90137 100644
--- a/tests/qht-bench.c
+++ b/tests/qht-bench.c
@@ -284,7 +284,8 @@ static void do_threshold(double rate, uint64_t *threshold)
if (rate == 1.0) {
*threshold = UINT64_MAX;
} else {
- *threshold = rate * UINT64_MAX;
+ *threshold = (rate * 0xffff000000000000ull)
+ + (rate * 0x0000ffffffffffffull);
}
}
--
2.25.1
- [PATCH v4 0/6] Vs clang-10 and gcc-9 warnings, Richard Henderson, 2020/06/17
- [PATCH v4 1/6] fpu/softfloat: Silence 'bitwise negation of boolean expression' warning, Richard Henderson, 2020/06/17
- [PATCH v4 2/6] migration: fix xbzrle encoding rate calculation, Richard Henderson, 2020/06/17
- [PATCH v4 3/6] configure: Clean up warning flag lists, Richard Henderson, 2020/06/17
- [PATCH v4 4/6] configure: Disable -Wtautological-type-limit-compare, Richard Henderson, 2020/06/17
- [PATCH v4 5/6] configure: Add -Wno-psabi, Richard Henderson, 2020/06/17
- [PATCH v4 6/6] qht: Fix threshold rate calculation,
Richard Henderson <=
- Re: [PATCH v4 0/6] Vs clang-10 and gcc-9 warnings, Peter Maydell, 2020/06/18