From patchwork Fri Jun 26 20:09:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 191917 Delivered-To: patch@linaro.org Received: by 2002:a92:d244:0:0:0:0:0 with SMTP id v4csp802701ilg; Fri, 26 Jun 2020 13:10:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyWyu8pODia8YQw5wfTSpyE4V1Nzi5uawp1UjwkQV4jKVfIfokgXVcnQPq2+m7cdiiDvwTG X-Received: by 2002:a25:5d04:: with SMTP id r4mr7303661ybb.290.1593202236739; Fri, 26 Jun 2020 13:10:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593202236; cv=none; d=google.com; s=arc-20160816; b=U5mRudSzeHu0EaZLHg3d2+QqQbOLKh5VcV1FrVmwRc418QoQyolyTkPof4Fk3brqew vFgJhdDhpEW2qqUXvPh0h1txJtvUYKIQpcQllnGEtDzrcqWTXfiVY2nIgU6hefXJC/1L QfjwUBBOxzVFJcdEk09iQTGBmw4YduKnlKHDXBqpceyRG5c8CltS3rxeqAkdbjol7Ua4 ER9RKa7o8XQbVWKI+xw8upLDiE0mmEx2O9mjSH7rd2NaBd5KhjxPmM84Nntq+z06yTfS 2F24hurmnX6UqPEB1MGI1Z5/DmAcDXiOO30p8LtijdscvELzCPqaIXAQCWELuOlsRJMe hLcQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=hxw6BjVwQMIa1uoPxedqx8XGWOQD0NGxS2kvL4q3yy8=; b=E03LkfYURYfc7KmmAgc7d4pv/V4HhfIkSTK5UKI1xCRZhexWjB0DeoAftP2oEWeP40 Ckh0HsA93MkjlQ8S95DyOGWrFRmY/b/NuyN3VB0JyxOeRSqSQ4Y+PEeJqLK4pPSBZ7IU TxQ8VbMhtds2NzztwFIqBRKImrHeu84Xcr7VHBLsQwv8ldvoOgtgFOdzmBgi1t5W0Ril dfbjP53XsJc9EsEfvdiydOul7MA0h3pCA2L/6g1lfrdXv8BW000X5F7aIQlgM9HJAdMR aGd1u6z+VqWjXpGW+tz7g6rF0Ig5Ds0xv7H1o6h5/CMjRcFA1mWZ8I8EOcAuFPHu7+8M z4kg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=p+RuJNwr; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id v7si24653671ybe.190.2020.06.26.13.10.36 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 26 Jun 2020 13:10:36 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=p+RuJNwr; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:42570 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jougG-0004MX-50 for patch@linaro.org; Fri, 26 Jun 2020 16:10:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54578) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1joufe-0004M4-Rk for qemu-devel@nongnu.org; Fri, 26 Jun 2020 16:09:58 -0400 Received: from mail-pf1-x443.google.com ([2607:f8b0:4864:20::443]:37713) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1joufd-00042T-4n for qemu-devel@nongnu.org; Fri, 26 Jun 2020 16:09:58 -0400 Received: by mail-pf1-x443.google.com with SMTP id j1so5086375pfe.4 for ; Fri, 26 Jun 2020 13:09:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=hxw6BjVwQMIa1uoPxedqx8XGWOQD0NGxS2kvL4q3yy8=; b=p+RuJNwrhJwZzEjMil2KSK43gxw9c+9Cn27jYyvT7FTHmrnzki4Un4F4HvfliyZTfh zXg3MOoJ+ONJRbRqBL+3x/DlskkOFR5Pv03YSLmatXGGMw3clTstv9gJr4m/vWUkDZEF CBH7TvujTskzBLKxmyLPmM7vz5Oo9h3Poeiv71ZablgVXZIPmYqo777WsK6qOPK50nde SmUXWbP9JsnlKn74DgQeHsaZ5mjwr+9R1fj4cXkmHMS+cuZzUWSTM2wt4vIHVpHZN8o8 ul4nASLcZ7/qGz/SGDT5xixR7NfFPCAHQfBDw6F46jXdXo7vBfac0kn3xXk3fqVLna0w Cvqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=hxw6BjVwQMIa1uoPxedqx8XGWOQD0NGxS2kvL4q3yy8=; b=U4AINskNL5PbOouh5ucX2DuQVaz2cEFcoCqfXrjmlt7nYwPyuYtAfzDMSJ7Ls3fdKr NkMjMpJ2Vx6hsjTJI5TX2+hIo7FQ3E1NJemGbDYC78ncZfxZhG54YiL/gBd0A1FWdOPC Y+fLHKbvgUR46sUN5S8VnCv8wI5oo75mKcmBSdlmRtBCbAgVSlaXJfwrDeyPcChcTvn7 htOGF44Ri0Ui1cwQcFfWO+xqmHTbUD1J6oMdhJpqD49riuna0f/65IeUMs24D6Qax9JZ jM2CDi9qWa6hQHftN5dcjvichU+zK7Zf2vWjEOUebczGkChcWXlAoTbivZMW3GXgkcMJ tXQg== X-Gm-Message-State: AOAM531P8h4NmKeIhb/PyiCJwL2EPtv0rDn4wSzMLtBzeTuNIoVN0GoC msVvXXTvu40HANHN+uau1vPkIzy2YW0= X-Received: by 2002:a62:ea14:: with SMTP id t20mr813019pfh.264.1593202195174; Fri, 26 Jun 2020 13:09:55 -0700 (PDT) Received: from localhost.localdomain (174-21-143-238.tukw.qwest.net. [174.21.143.238]) by smtp.gmail.com with ESMTPSA id n8sm23879405pgi.18.2020.06.26.13.09.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jun 2020 13:09:54 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 1/2] tests/qht-bench: Adjust testing rate by -1 Date: Fri, 26 Jun 2020 13:09:49 -0700 Message-Id: <20200626200950.1015121-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200626200950.1015121-1-richard.henderson@linaro.org> References: <20200626200950.1015121-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::443; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x443.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: cota@braap.org, alex.bennee@linaro.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Since the seed must be non-zero, subtracting 1 means puts the rate in 0..UINT64_MAX-1, which allows the 0 and UINT64_MAX thresholds to corrspond to 0% (never) and 100% (always). Suggested-by: Emilio G. Cota Signed-off-by: Richard Henderson --- tests/qht-bench.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) -- 2.25.1 Reviewed-by: Philippe Mathieu-Daudé diff --git a/tests/qht-bench.c b/tests/qht-bench.c index eb88a90137..ad885d89d0 100644 --- a/tests/qht-bench.c +++ b/tests/qht-bench.c @@ -25,7 +25,13 @@ struct thread_stats { struct thread_info { void (*func)(struct thread_info *); struct thread_stats stats; - uint64_t r; + /* + * Seed is in the range [1..UINT64_MAX], because the RNG requires + * a non-zero seed. To use, subtract 1 and compare against the + * threshold with =. This lets threshold = 0 never match (0% hit), + * and threshold = UINT64_MAX always match (100% hit). + */ + uint64_t seed; bool write_op; /* writes alternate between insertions and removals */ bool resize_down; } QEMU_ALIGNED(64); /* avoid false sharing among threads */ @@ -131,8 +137,9 @@ static uint64_t xorshift64star(uint64_t x) static void do_rz(struct thread_info *info) { struct thread_stats *stats = &info->stats; + uint64_t r = info->seed - 1; - if (info->r < resize_threshold) { + if (r < resize_threshold) { size_t size = info->resize_down ? resize_min : resize_max; bool resized; @@ -151,13 +158,14 @@ static void do_rz(struct thread_info *info) static void do_rw(struct thread_info *info) { struct thread_stats *stats = &info->stats; + uint64_t r = info->seed - 1; uint32_t hash; long *p; - if (info->r >= update_threshold) { + if (r >= update_threshold) { bool read; - p = &keys[info->r & (lookup_range - 1)]; + p = &keys[r & (lookup_range - 1)]; hash = hfunc(*p); read = qht_lookup(&ht, p, hash); if (read) { @@ -166,7 +174,7 @@ static void do_rw(struct thread_info *info) stats->not_rd++; } } else { - p = &keys[info->r & (update_range - 1)]; + p = &keys[r & (update_range - 1)]; hash = hfunc(*p); if (info->write_op) { bool written = false; @@ -208,7 +216,7 @@ static void *thread_func(void *p) rcu_read_lock(); while (!atomic_read(&test_stop)) { - info->r = xorshift64star(info->r); + info->seed = xorshift64star(info->seed); info->func(info); } rcu_read_unlock(); @@ -221,7 +229,7 @@ static void *thread_func(void *p) static void prepare_thread_info(struct thread_info *info, int i) { /* seed for the RNG; each thread should have a different one */ - info->r = (i + 1) ^ time(NULL); + info->seed = (i + 1) ^ time(NULL); /* the first update will be a write */ info->write_op = true; /* the first resize will be down */ From patchwork Fri Jun 26 20:09:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 191916 Delivered-To: patch@linaro.org Received: by 2002:a92:d244:0:0:0:0:0 with SMTP id v4csp802412ilg; Fri, 26 Jun 2020 13:10:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw0m28o53ZKvHIXh/bBTidv1fQAAzXczZ/xDr6Xr84b557wqEAbu2rbrR8xFtn9ufMGQ/a6 X-Received: by 2002:a5b:342:: with SMTP id q2mr7297285ybp.64.1593202213784; Fri, 26 Jun 2020 13:10:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593202213; cv=none; d=google.com; s=arc-20160816; b=qOa8Jq4otK/gTBJRjvMtPN/gpcTOde+XVBQjYGKh3Q0JEIMeeLM94knqGV1fS+BLOz DY+5lMkEbvAdE8ZU52Dm5XwHo+Vf89egyogS4I1/iO1lhjwLapMvNHQRElsx4/pdeQNz m5wBHltHQe9HMx7gHt/pezqiMSvKHsTFzifHCt0+/HhHCEigCAQB1GD6i5uDJNJ7Gfvu wcotLfl4MEhDe6r9lwN3tzRMMapW8hyK64wgC0BNQebtQgBeJ20Uvvf3nbKz7nmbCLJp Ag+K7KkG0E9hBr8w+Uhf0V/arMWD4dVQQ5j5oEPUnlFFyI0o4mWkj+4qeaYTlAlteXBe 0B2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=SW802rsBjyjH3nSM8zwvWR8Kt24bL/tDHyeHn/2Y6L4=; b=GjYe564tRQuJBc/RZrYjvKHogC0okT0QzmBJWSfUv3YDpFP6f/gXw1Dd2BhwAIBRlZ JwJfunYmK1Y7C4eG8Xq+aL/szKS0CLaBa1gkJ8bDMly0DRs1FGFrN5R5uPTdBu0pio7B nsV+LcAlR7DGA6wpEfhsyzE6gaSwrUTvkMs9ViSo85CcI2prVx3q5+tjTsK4Vcn16tqy 0GtWrA6H009iOGrgpVqeY806NrwDsK9/k6fWnoANaKTMDP9mVRbTZ0PX/iwB8Vq+ALvk 7J9vR3pYFSsibSbbFfKCx1B+TCNtsUOApLupKCBpl1DIod2/aqBaV6gCkiUuDS5lT4P7 txAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=N7qHoavy; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id u15si2104052ybj.145.2020.06.26.13.10.13 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 26 Jun 2020 13:10:13 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=N7qHoavy; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:42636 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jouft-0004Oj-7G for patch@linaro.org; Fri, 26 Jun 2020 16:10:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54592) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jouff-0004MH-P0 for qemu-devel@nongnu.org; Fri, 26 Jun 2020 16:09:59 -0400 Received: from mail-pf1-x442.google.com ([2607:f8b0:4864:20::442]:46722) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1joufe-000443-5Q for qemu-devel@nongnu.org; Fri, 26 Jun 2020 16:09:59 -0400 Received: by mail-pf1-x442.google.com with SMTP id b16so5060093pfi.13 for ; Fri, 26 Jun 2020 13:09:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=SW802rsBjyjH3nSM8zwvWR8Kt24bL/tDHyeHn/2Y6L4=; b=N7qHoavy76cIFRRnP7H8p2TP83RVrVKT4yO7yN3Hg85MvuXYyNU91RAGg4g6RJMjUq 9UiS/9BG5IO2nfY4OA6Gq+5Gc9667D1p+DCxWjtCBD6Bc59Q5r+G1JU1SRjJiyZ95TW0 HWgIRYzhpCchKvuT/69134fepgDiQSsf8I7XkePCga8MJAMtSf/TWY5fknSG7hM1m71Q Q+4PaBB6ZiWSDCBZZCeBz2/L4Axzv2pixXMqkLxyVoXbiH6WE56ZM7Ihfru49fCrIhOa 1XWhH5enJkSd9NoW/AZuhQLg5TDJnNN2SvDK5k7tfsIip4+Dhd1z/wK0dGCFZQDJUzWE 7TfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=SW802rsBjyjH3nSM8zwvWR8Kt24bL/tDHyeHn/2Y6L4=; b=Mk/2Q2Nm6oS5bQBwQAvxxJyg2LGXMBMkUHjaRbP29h9DiQs/wcaUTp9fFweI2r+k45 vMmyHHrulbif0LBpzLoznQmOJiCU/jJmhTGB+NzL6b6THTRxtxQIEEPNM1ee9uuXLYY3 Yrl9GQI5CKdh+tOlnQyQzA7ZswIfc3JZrcSjX3WuhzzAwKAWRNfrKDMhWFKE6arkivkR ZOHeozVJrmxm3jzevHwTHcEZyJ8MjubVOWhNp/rTSNvjza0U5VEtValXty69YjBOsoGn WxbLmW3Q3d/w0PHX8cmf07InbUbasbp7ZMeYr4IecMUEVyQ9N4D+yu7mMP5Fxa44Dz6f xGOA== X-Gm-Message-State: AOAM531cxfLkjzSxJvrlzK5lxOwICR3NO00J9m+7rLtKYwXn49eGG/Go +BOCDJSQqsFWjuQycDADzU4jlUTES0k= X-Received: by 2002:aa7:9289:: with SMTP id j9mr4573050pfa.124.1593202196355; Fri, 26 Jun 2020 13:09:56 -0700 (PDT) Received: from localhost.localdomain (174-21-143-238.tukw.qwest.net. [174.21.143.238]) by smtp.gmail.com with ESMTPSA id n8sm23879405pgi.18.2020.06.26.13.09.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jun 2020 13:09:55 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 2/2] tests/qht-bench: Adjust threshold computation Date: Fri, 26 Jun 2020 13:09:50 -0700 Message-Id: <20200626200950.1015121-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200626200950.1015121-1-richard.henderson@linaro.org> References: <20200626200950.1015121-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::442; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x442.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: cota@braap.org, alex.bennee@linaro.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" 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 --- tests/qht-bench.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) -- 2.25.1 Reviewed-by: Philippe Mathieu-Daudé 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; } }