From patchwork Fri Sep 18 22:26:28 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Pfaff X-Patchwork-Id: 519602 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from archives.nicira.com (li376-54.members.linode.com [96.126.127.54]) by ozlabs.org (Postfix) with ESMTP id E43EB140785 for ; Sat, 19 Sep 2015 08:26:34 +1000 (AEST) Received: from archives.nicira.com (localhost [127.0.0.1]) by archives.nicira.com (Postfix) with ESMTP id CF38210D32; Fri, 18 Sep 2015 15:26:33 -0700 (PDT) X-Original-To: dev@openvswitch.org Delivered-To: dev@openvswitch.org Received: from mx1e4.cudamail.com (mx1.cudamail.com [69.90.118.67]) by archives.nicira.com (Postfix) with ESMTPS id 56C2110C2B for ; Fri, 18 Sep 2015 15:26:32 -0700 (PDT) Received: from bar5.cudamail.com (unknown [192.168.21.12]) by mx1e4.cudamail.com (Postfix) with ESMTPS id D0AB41E084A for ; Fri, 18 Sep 2015 16:26:31 -0600 (MDT) X-ASG-Debug-ID: 1442615191-09eadd11e0812e0001-byXFYA Received: from mx1-pf1.cudamail.com ([192.168.24.1]) by bar5.cudamail.com with ESMTP id NYC2q7vpGqiRSoOw (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Fri, 18 Sep 2015 16:26:31 -0600 (MDT) X-Barracuda-Envelope-From: blp@nicira.com X-Barracuda-RBL-Trusted-Forwarder: 192.168.24.1 Received: from unknown (HELO mail-pa0-f53.google.com) (209.85.220.53) by mx1-pf1.cudamail.com with ESMTPS (RC4-SHA encrypted); 18 Sep 2015 22:26:31 -0000 Received-SPF: unknown (mx1-pf1.cudamail.com: Multiple SPF records returned) X-Barracuda-RBL-Trusted-Forwarder: 209.85.220.53 Received: by padhk3 with SMTP id hk3so61481111pad.3 for ; Fri, 18 Sep 2015 15:26:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=93nkQisyMukkskUJ1A/iNdnC1Qq4CLLrrE1LMEDsz5U=; b=I/m4+jxpQflSNlYBGkteKbXLBoDQw+4zKEUVRDOY2BqKdC/khOWCtRgd67emEtgkBe qIe9gEQZoR6udT3NOVmm2tGFllnOv3Xng08zfaDKrVmcEOl64Can4l7U9OCT2vhUfZLz smddixIEJDLnFv4KciQbbX6tfBQhW4wy3iBuDAigsHmJgSeeuZn9hRtvukixjA7gWc6d B5NJoFQWie0YlsB0uGv6cNnGEPJshCGSkAmLoU2a7UFF/GB5+v0bhAaSCGiLrmjel0Ti +oqmoolVIbZQr6XQ2NzN31W1nXfKGLFSZj1kfeI6CZvQIhxy8uAiz0aJ1dM6IXwxjkyV 6dsQ== X-Gm-Message-State: ALoCoQnK3KjlE8OPSH9UAfSnRlRpOrrGNswlORBIBTkQaB4ABPsQR4WBtkmXzd1/HBW9UBr+uVri X-Received: by 10.68.220.226 with SMTP id pz2mr9792226pbc.115.1442615190221; Fri, 18 Sep 2015 15:26:30 -0700 (PDT) Received: from sigabrt.benpfaff.org (173-228-112-165.dsl.dynamic.fusionbroadband.com. [173.228.112.165]) by smtp.gmail.com with ESMTPSA id zk9sm10889060pac.7.2015.09.18.15.26.27 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 18 Sep 2015 15:26:28 -0700 (PDT) X-CudaMail-Envelope-Sender: blp@nicira.com X-Barracuda-Apparent-Source-IP: 173.228.112.165 From: Ben Pfaff To: dev@openvswitch.org X-CudaMail-Whitelist-To: dev@openvswitch.org X-CudaMail-MID: CM-E1-917082330 X-CudaMail-DTE: 091815 X-CudaMail-Originating-IP: 209.85.220.53 Date: Fri, 18 Sep 2015 15:26:28 -0700 X-ASG-Orig-Subj: [##CM-E1-917082330##][PATCH] util: Generalize rightmost_1bit_idx(), leftmost_1bit_idx(). Message-Id: <1442615188-23637-1-git-send-email-blp@nicira.com> X-Mailer: git-send-email 2.1.3 X-Barracuda-Connect: UNKNOWN[192.168.24.1] X-Barracuda-Start-Time: 1442615191 X-Barracuda-Encrypted: DHE-RSA-AES256-SHA X-Barracuda-URL: https://web.cudamail.com:443/cgi-mod/mark.cgi X-ASG-Whitelist: Header =?UTF-8?B?eFwtY3VkYW1haWxcLXdoaXRlbGlzdFwtdG8=?= X-Virus-Scanned: by bsmtpd at cudamail.com X-Barracuda-BRTS-Status: 1 Cc: Ben Pfaff , Kyle Upton Subject: [ovs-dev] [PATCH] util: Generalize rightmost_1bit_idx(), leftmost_1bit_idx(). X-BeenThere: dev@openvswitch.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dev-bounces@openvswitch.org Sender: "dev" These functions could only work with 32-bit integers because of their special cases for an argument of value 0. However, none of the existing users depended on this special case, and some of the users did try to use these functions with 64-bit integer arguments. Thus, this commit changes them to support 64-bit integer arguments and drops the special cases for zero. This fixes a latent bug that applied rightmost_1bit_idx() to an ofpact bitmap, which only becomes visible when an OFPACT_* with value greater than 32 is included in the bitmap. Reported-by: Kyle Upton Reported-at: http://openvswitch.org/pipermail/dev/2015-September/060128.html Signed-off-by: Ben Pfaff --- lib/util.h | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/lib/util.h b/lib/util.h index 7080a0c..4186d49 100644 --- a/lib/util.h +++ b/lib/util.h @@ -506,25 +506,20 @@ zero_rightmost_1bit(uintmax_t x) return x & (x - 1); } -/* Returns the index of the rightmost 1-bit in 'x' (e.g. 01011000 => 3), or 32 - * if 'x' is 0. - * - * Unlike the other functions for rightmost 1-bits, this function only works - * with 32-bit integers. */ +/* Returns the index of the rightmost 1-bit in 'x' (e.g. 01011000 => 3), or an + * undefined value if 'x' is 0. */ static inline int -rightmost_1bit_idx(uint32_t x) +rightmost_1bit_idx(uint64_t x) { - return ctz32(x); + return ctz64(x); } -/* Returns the index of the leftmost 1-bit in 'x' (e.g. 01011000 => 6), or 32 - * if 'x' is 0. - * - * This function only works with 32-bit integers. */ +/* Returns the index of the leftmost 1-bit in 'x' (e.g. 01011000 => 6), or an + * undefined value if 'x' is 0. */ static inline uint32_t -leftmost_1bit_idx(uint32_t x) +leftmost_1bit_idx(uint64_t x) { - return x ? log_2_floor(x) : 32; + return log_2_floor(x); } /* Return a ovs_be32 prefix in network byte order with 'plen' highest bits set.