From patchwork Tue May 23 23:02:14 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Stringer X-Patchwork-Id: 766259 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3wXWLN0VF9z9sNp for ; Wed, 24 May 2017 09:04:12 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id A731FBDF; Tue, 23 May 2017 23:02:31 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id 8A98BB5F for ; Tue, 23 May 2017 23:02:28 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id DB7AF1D2 for ; Tue, 23 May 2017 23:02:27 +0000 (UTC) Received: from mfilter11-d.gandi.net (mfilter11-d.gandi.net [217.70.178.131]) by relay5-d.mail.gandi.net (Postfix) with ESMTP id BF52341C07C for ; Wed, 24 May 2017 01:02:26 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at mfilter11-d.gandi.net Received: from relay5-d.mail.gandi.net ([IPv6:::ffff:217.70.183.197]) by mfilter11-d.gandi.net (mfilter11-d.gandi.net [::ffff:10.0.15.180]) (amavisd-new, port 10024) with ESMTP id hlCXF7T15JRG for ; Wed, 24 May 2017 01:02:25 +0200 (CEST) X-Originating-IP: 64.134.227.17 Received: from archer.hil-sfofhhh02.sfo.wayport.net (ip-64-134-227-17.public.wayport.net [64.134.227.17]) (Authenticated sender: joe@ovn.org) by relay5-d.mail.gandi.net (Postfix) with ESMTPSA id C0C1141C074 for ; Wed, 24 May 2017 01:02:24 +0200 (CEST) From: Joe Stringer To: dev@openvswitch.org Date: Tue, 23 May 2017 16:02:14 -0700 Message-Id: <20170523230216.29696-4-joe@ovn.org> X-Mailer: git-send-email 2.12.2 In-Reply-To: <20170523230216.29696-1-joe@ovn.org> References: <20170523230216.29696-1-joe@ovn.org> X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Subject: [ovs-dev] [PATCH 3/5] test-hash: Don't check bit 2048. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org When running 256B hash check, we currently iterate from 0 up to and including bit 2048, which is beyond the range of bits that 256B holds. For bit 2048, set_bit128() doesn't set a bit due to the range check. Simplify the code by dropping the handling of bit 2048. Signed-off-by: Joe Stringer --- tests/test-hash.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/tests/test-hash.c b/tests/test-hash.c index d1beead36ed5..a20c87fad6a0 100644 --- a/tests/test-hash.c +++ b/tests/test-hash.c @@ -39,16 +39,15 @@ set_bit(uint32_t array[3], int bit) static void set_bit128(ovs_u128 *values, int bit, int n_bits) { - assert(bit >= 0 && bit <= 2048); + int b = bit % 128; + + assert(bit >= 0 && bit < 2048); memset(values, 0, n_bits/8); - if (bit < n_bits) { - int b = bit % 128; - if (b < 64) { - values[bit / 128].u64.lo = UINT64_C(1) << (b % 64); - } else { - values[bit / 128].u64.hi = UINT64_C(1) << (b % 64); - } + if (b < 64) { + values[bit / 128].u64.lo = UINT64_C(1) << (b % 64); + } else { + values[bit / 128].u64.hi = UINT64_C(1) << (b % 64); } } @@ -149,7 +148,7 @@ check_hash_bytes128(void (*hash)(const void *, size_t, uint32_t, ovs_u128 *), const int n_bits = sizeof(ovs_u128) * 8; int i, j; - for (i = 0; i <= n_bits; i++) { + for (i = 0; i < n_bits; i++) { OVS_PACKED(struct offset_ovs_u128 { uint32_t a; ovs_u128 b; @@ -168,7 +167,7 @@ check_hash_bytes128(void (*hash)(const void *, size_t, uint32_t, ovs_u128 *), name, out0.u64.lo, out0.u64.hi, out1.u64.lo, out1.u64.hi); } - for (j = i + 1; j <= n_bits; j++) { + for (j = i + 1; j < n_bits; j++) { ovs_u128 in2; ovs_u128 out2; int ofs; @@ -201,7 +200,7 @@ check_256byte_hash(void (*hash)(const void *, size_t, uint32_t, ovs_u128 *), const int n_bits = sizeof(ovs_u128) * 8 * 16; int i, j; - for (i = 0; i <= n_bits; i++) { + for (i = 0; i < n_bits; i++) { OVS_PACKED(struct offset_ovs_u128 { uint32_t a; ovs_u128 b[16]; @@ -220,7 +219,7 @@ check_256byte_hash(void (*hash)(const void *, size_t, uint32_t, ovs_u128 *), name, out0.u64.lo, out0.u64.hi, out1.u64.lo, out1.u64.hi); } - for (j = i + 1; j <= n_bits; j++) { + for (j = i + 1; j < n_bits; j++) { ovs_u128 in2[16]; ovs_u128 out2;