aboutsummaryrefslogtreecommitdiff
path: root/tests/qht-bench.c
diff options
context:
space:
mode:
authorRichard Henderson <richard.henderson@linaro.org>2020-06-26 13:09:50 -0700
committerAlex Bennée <alex.bennee@linaro.org>2020-07-11 15:53:00 +0100
commit78441c04ca4356e40620bbd24dffffdee3978a22 (patch)
tree19f776f50ff859bf6e521b28278e1088d09606b1 /tests/qht-bench.c
parentd11f824991749c4b28c3c08ca737e82d0d9d01e6 (diff)
downloadqemu-78441c04ca4356e40620bbd24dffffdee3978a22.zip
qemu-78441c04ca4356e40620bbd24dffffdee3978a22.tar.gz
qemu-78441c04ca4356e40620bbd24dffffdee3978a22.tar.bz2
tests/qht-bench: Adjust threshold computation
In 06c4cc3660b3, we split the multiplication in two parts to avoid a clang warning. But because double still rounds to 53 bits, this does not provide additional precision beyond multiplication by nextafter(0x1p64, 0), the largest representable value smaller than 2**64. However, since we have eliminated 1.0, mutiplying by 2**64 produces a better distribution of input values to the output values. Signed-off-by: Richard Henderson <richard.henderson@linaro.org> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> Signed-off-by: Alex Bennée <alex.bennee@linaro.org> Message-Id: <20200626200950.1015121-3-richard.henderson@linaro.org>
Diffstat (limited to 'tests/qht-bench.c')
-rw-r--r--tests/qht-bench.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/tests/qht-bench.c b/tests/qht-bench.c
index ad885d8..362f03c 100644
--- a/tests/qht-bench.c
+++ b/tests/qht-bench.c
@@ -289,11 +289,25 @@ static void pr_params(void)
static void do_threshold(double rate, uint64_t *threshold)
{
+ /*
+ * For 0 <= rate <= 1, scale to fit in a uint64_t.
+ *
+ * Scale by 2**64, with a special case for 1.0.
+ * The remainder of the possible values are scattered between 0
+ * and 0xfffffffffffff800 (nextafter(0x1p64, 0)).
+ *
+ * Note that we cannot simply scale by UINT64_MAX, because that
+ * value is not representable as an IEEE double value.
+ *
+ * If we scale by the next largest value, nextafter(0x1p64, 0),
+ * then the remainder of the possible values are scattered between
+ * 0 and 0xfffffffffffff000. Which leaves us with a gap between
+ * the final two inputs that is twice as large as any other.
+ */
if (rate == 1.0) {
*threshold = UINT64_MAX;
} else {
- *threshold = (rate * 0xffff000000000000ull)
- + (rate * 0x0000ffffffffffffull);
+ *threshold = rate * 0x1p64;
}
}