qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@redhat.com>
To: Richard Henderson <richard.henderson@linaro.org>, qemu-devel@nongnu.org
Cc: cota@braap.org, alex.bennee@linaro.org
Subject: Re: [PATCH v2 2/2] tests/qht-bench: Adjust threshold computation
Date: Fri, 26 Jun 2020 22:38:26 +0200	[thread overview]
Message-ID: <6f38dcac-131c-b831-47db-813713d90c64@redhat.com> (raw)
In-Reply-To: <20200626200950.1015121-3-richard.henderson@linaro.org>

On 6/26/20 10:09 PM, Richard Henderson wrote:
> 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>
> ---
>  tests/qht-bench.c | 18 ++++++++++++++++--
>  1 file changed, 16 insertions(+), 2 deletions(-)
> 
> diff --git a/tests/qht-bench.c b/tests/qht-bench.c
> index ad885d89d0..362f03cb03 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;
>      }
>  }
>  
> 

Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>



  reply	other threads:[~2020-06-26 20:39 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-26 20:09 [PATCH v2 0/2] tests/qht-bench: Adjust rate/threshold computation Richard Henderson
2020-06-26 20:09 ` [PATCH v2 1/2] tests/qht-bench: Adjust testing rate by -1 Richard Henderson
2020-06-26 20:39   ` Philippe Mathieu-Daudé
2020-06-26 20:09 ` [PATCH v2 2/2] tests/qht-bench: Adjust threshold computation Richard Henderson
2020-06-26 20:38   ` Philippe Mathieu-Daudé [this message]
2020-06-26 20:21 ` [PATCH v2 0/2] tests/qht-bench: Adjust rate/threshold computation no-reply
2020-06-27 21:57 ` Emilio G. Cota
2020-07-02 19:51 ` Alex Bennée

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6f38dcac-131c-b831-47db-813713d90c64@redhat.com \
    --to=philmd@redhat.com \
    --cc=alex.bennee@linaro.org \
    --cc=cota@braap.org \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).