From patchwork Mon Mar 21 18:58:16 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: ben@skyportsystems.com X-Patchwork-Id: 600271 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from archives.nicira.com (archives.nicira.com [96.126.127.54]) by ozlabs.org (Postfix) with ESMTP id 3qTQB21xqgz9ryW for ; Tue, 22 Mar 2016 05:59:54 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=skyportsystems.com header.i=@skyportsystems.com header.b=lFJRZlvZ; dkim-atps=neutral Received: from archives.nicira.com (localhost [127.0.0.1]) by archives.nicira.com (Postfix) with ESMTP id C961210527; Mon, 21 Mar 2016 11:58:56 -0700 (PDT) X-Original-To: dev@openvswitch.org Delivered-To: dev@openvswitch.org Received: from mx3v3.cudamail.com (mx3.cudamail.com [64.34.241.5]) by archives.nicira.com (Postfix) with ESMTPS id 0054210308 for ; Mon, 21 Mar 2016 11:58:50 -0700 (PDT) Received: from bar6.cudamail.com (localhost [127.0.0.1]) by mx3v3.cudamail.com (Postfix) with ESMTPS id 816231624FD for ; Mon, 21 Mar 2016 12:58:49 -0600 (MDT) X-ASG-Debug-ID: 1458586728-0b323727626b4bb0001-byXFYA Received: from mx1-pf2.cudamail.com ([192.168.24.2]) by bar6.cudamail.com with ESMTP id 4DHGmWb0wGc9ai2f (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Mon, 21 Mar 2016 12:58:48 -0600 (MDT) X-Barracuda-Envelope-From: ben@skyportsystems.com X-Barracuda-RBL-Trusted-Forwarder: 192.168.24.2 Received: from unknown (HELO mail-pf0-f177.google.com) (209.85.192.177) by mx1-pf2.cudamail.com with ESMTPS (RC4-SHA encrypted); 21 Mar 2016 18:58:48 -0000 Received-SPF: pass (mx1-pf2.cudamail.com: SPF record at _netblocks.google.com designates 209.85.192.177 as permitted sender) X-Barracuda-RBL-Trusted-Forwarder: 209.85.192.177 Received: by mail-pf0-f177.google.com with SMTP id 4so144245590pfd.0 for ; Mon, 21 Mar 2016 11:58:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=skyportsystems.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=4Rni790A+8PL5wgro5SoBdkC9q6C/dzlbX9Wkbkj1ME=; b=lFJRZlvZ2briZKuOulUnw1SGbpt+RDM0IjiKAh6U8C5W2a70bm99ykqVGmblgKJJCA ayqEzt4930omgfPId/I+5o//4n1QVTfEuUU6TYivhDvHYV2bEgEPWtWnEst9heyan2h1 zRS+hBGWxOErmW7P96xRDMoarJlzKmjwkgG5s= 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:in-reply-to :references:in-reply-to:references; bh=4Rni790A+8PL5wgro5SoBdkC9q6C/dzlbX9Wkbkj1ME=; b=NpztmgmcOIuNBuqNm+cQQ9BuZV2xnckhllF/b4Nz9qNTWLfmRriKqgW+HIdd3hg+zP oMrw1sf6slIto0dJR6eTodYdrRNHFWBhq+9aJy4D65l8Lgrng7XG3nKYmzQjBdnZPdUm uSeZI0R7Z1HxkB53n6/dPEl+EFWHfJFHrBRB0NGM1TLjCWzjTGsKOrUkTubevBLN2NCy aH+iJtt9NL7heyeNMZ6fhm7+xoUqWFFQk7ycjcqe0xOpaQfbYdzxs4EwmPIAnJRN2lmH 9q2DfCtqIoPhgJxCGa6L0tmB3W1u1QVzxuYBdfOznRTO8r2A81xknE/8SEQGp1A6Is++ Vjdg== X-Gm-Message-State: AD7BkJIAKyZGuRYwV+g7Fm8vuLWmUV4AX53zMIoFJOPtRH3aSTyRCAvqmmsEOlfZy/JHByv6 X-Received: by 10.98.86.28 with SMTP id k28mr47737946pfb.43.1458586727531; Mon, 21 Mar 2016 11:58:47 -0700 (PDT) Received: from Arrow.corp.skyportsystems.com (67-207-112-138.static.wiline.com. [67.207.112.138]) by smtp.gmail.com with ESMTPSA id a22sm42472831pfj.2.2016.03.21.11.58.46 (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 21 Mar 2016 11:58:46 -0700 (PDT) X-CudaMail-Envelope-Sender: ben@skyportsystems.com X-Barracuda-Apparent-Source-IP: 67.207.112.138 From: ben@skyportsystems.com To: dev@openvswitch.org X-CudaMail-MID: CM-E2-320059252 X-CudaMail-DTE: 032116 X-CudaMail-Originating-IP: 209.85.192.177 Date: Mon, 21 Mar 2016 11:58:16 -0700 X-ASG-Orig-Subj: [##CM-E2-320059252##][PATCH v3 08/21] Misc cleanup with "util.h" header files Message-Id: X-Mailer: git-send-email 2.5.4 (Apple Git-61) In-Reply-To: References: In-Reply-To: References: X-GBUdb-Analysis: 0, 209.85.192.177, Ugly c=0.437809 p=-0.314286 Source Normal X-MessageSniffer-Rules: 0-0-0-14609-c X-Barracuda-Connect: UNKNOWN[192.168.24.2] X-Barracuda-Start-Time: 1458586728 X-Barracuda-Encrypted: DHE-RSA-AES256-SHA X-Barracuda-URL: https://web.cudamail.com:443/cgi-mod/mark.cgi X-Virus-Scanned: by bsmtpd at cudamail.com X-Barracuda-BRTS-Status: 1 X-Barracuda-Spam-Score: 0.60 X-Barracuda-Spam-Status: No, SCORE=0.60 using per-user scores of TAG_LEVEL=3.5 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=4.0 tests=BSF_SC5_MJ1963, DKIM_SIGNED, NO_REAL_NAME, RDNS_NONE X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.28028 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- 0.00 NO_REAL_NAME From: does not include a real name 0.00 DKIM_SIGNED Domain Keys Identified Mail: message has a signature 0.10 RDNS_NONE Delivered to trusted network by a host with no rDNS 0.50 BSF_SC5_MJ1963 Custom Rule MJ1963 Cc: Ben Warren Subject: [ovs-dev] [PATCH v3 08/21] Misc cleanup with "util.h" header files 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" From: Ben Warren Removed from redundant #includes and moved some macros to different file scope Signed-off-by: Ben Warren Acked-by: Ryan Moats --- include/openvswitch/compiler.h | 3 +++ include/openvswitch/util.h | 50 ++++++++++++++++++++++++++++++++++++++++- lib/util.h | 51 ------------------------------------------ 3 files changed, 52 insertions(+), 52 deletions(-) diff --git a/include/openvswitch/compiler.h b/include/openvswitch/compiler.h index 1d3af9f..0e402c0 100644 --- a/include/openvswitch/compiler.h +++ b/include/openvswitch/compiler.h @@ -17,6 +17,9 @@ #ifndef OPENVSWITCH_COMPILER_H #define OPENVSWITCH_COMPILER_H 1 +#include +#include + #ifndef __has_feature #define __has_feature(x) 0 #endif diff --git a/include/openvswitch/util.h b/include/openvswitch/util.h index 63c8a45..cfafc36 100644 --- a/include/openvswitch/util.h +++ b/include/openvswitch/util.h @@ -17,8 +17,9 @@ #ifndef OPENVSWITCH_UTIL_H #define OPENVSWITCH_UTIL_H 1 -#include #include +#include +#include #ifdef __cplusplus extern "C" { @@ -147,6 +148,53 @@ OVS_NO_RETURN void ovs_assert_failure(const char *, const char *, const char *); #define INIT_CONTAINER(OBJECT, POINTER, MEMBER) \ ((OBJECT) = NULL, ASSIGN_CONTAINER(OBJECT, POINTER, MEMBER)) +/* Returns the number of elements in ARRAY. */ +#define ARRAY_SIZE(ARRAY) __ARRAY_SIZE(ARRAY) + +/* Returns X / Y, rounding up. X must be nonnegative to round correctly. */ +#define DIV_ROUND_UP(X, Y) (((X) + ((Y) - 1)) / (Y)) + +/* Returns X rounded up to the nearest multiple of Y. */ +#define ROUND_UP(X, Y) (DIV_ROUND_UP(X, Y) * (Y)) + +/* Returns the least number that, when added to X, yields a multiple of Y. */ +#define PAD_SIZE(X, Y) (ROUND_UP(X, Y) - (X)) + +/* Returns X rounded down to the nearest multiple of Y. */ +#define ROUND_DOWN(X, Y) ((X) / (Y) * (Y)) + +/* Returns true if X is a power of 2, otherwise false. */ +#define IS_POW2(X) ((X) && !((X) & ((X) - 1))) + +static inline bool +is_pow2(uintmax_t x) +{ + return IS_POW2(x); +} + +/* Returns X rounded up to a power of 2. X must be a constant expression. */ +#define ROUND_UP_POW2(X) RUP2__(X) +#define RUP2__(X) (RUP2_1(X) + 1) +#define RUP2_1(X) (RUP2_2(X) | (RUP2_2(X) >> 16)) +#define RUP2_2(X) (RUP2_3(X) | (RUP2_3(X) >> 8)) +#define RUP2_3(X) (RUP2_4(X) | (RUP2_4(X) >> 4)) +#define RUP2_4(X) (RUP2_5(X) | (RUP2_5(X) >> 2)) +#define RUP2_5(X) (RUP2_6(X) | (RUP2_6(X) >> 1)) +#define RUP2_6(X) ((X) - 1) + +/* Returns X rounded down to a power of 2. X must be a constant expression. */ +#define ROUND_DOWN_POW2(X) RDP2__(X) +#define RDP2__(X) (RDP2_1(X) - (RDP2_1(X) >> 1)) +#define RDP2_1(X) (RDP2_2(X) | (RDP2_2(X) >> 16)) +#define RDP2_2(X) (RDP2_3(X) | (RDP2_3(X) >> 8)) +#define RDP2_3(X) (RDP2_4(X) | (RDP2_4(X) >> 4)) +#define RDP2_4(X) (RDP2_5(X) | (RDP2_5(X) >> 2)) +#define RDP2_5(X) ( (X) | ( (X) >> 1)) + +/* Given ATTR, and TYPE, cast the ATTR to TYPE by first casting ATTR to + * (void *). This is to suppress the alignment warning issued by clang. */ +#define ALIGNED_CAST(TYPE, ATTR) ((TYPE) (void *) (ATTR)) + #ifdef __cplusplus } #endif diff --git a/lib/util.h b/lib/util.h index 41c5ea6..5dcb5df 100644 --- a/lib/util.h +++ b/lib/util.h @@ -20,15 +20,10 @@ #include #include #include -#include -#include -#include -#include #include #include #include #include "compiler.h" -#include "openvswitch/types.h" #include "openvswitch/util.h" #ifndef va_copy @@ -56,48 +51,6 @@ extern char *program_name; #define __ARRAY_SIZE(ARRAY) __ARRAY_SIZE_NOCHECK(ARRAY) #endif -/* Returns the number of elements in ARRAY. */ -#define ARRAY_SIZE(ARRAY) __ARRAY_SIZE(ARRAY) - -/* Returns X / Y, rounding up. X must be nonnegative to round correctly. */ -#define DIV_ROUND_UP(X, Y) (((X) + ((Y) - 1)) / (Y)) - -/* Returns X rounded up to the nearest multiple of Y. */ -#define ROUND_UP(X, Y) (DIV_ROUND_UP(X, Y) * (Y)) - -/* Returns the least number that, when added to X, yields a multiple of Y. */ -#define PAD_SIZE(X, Y) (ROUND_UP(X, Y) - (X)) - -/* Returns X rounded down to the nearest multiple of Y. */ -#define ROUND_DOWN(X, Y) ((X) / (Y) * (Y)) - -/* Returns true if X is a power of 2, otherwise false. */ -#define IS_POW2(X) ((X) && !((X) & ((X) - 1))) - -static inline bool -is_pow2(uintmax_t x) -{ - return IS_POW2(x); -} - -/* Returns X rounded up to a power of 2. X must be a constant expression. */ -#define ROUND_UP_POW2(X) RUP2__(X) -#define RUP2__(X) (RUP2_1(X) + 1) -#define RUP2_1(X) (RUP2_2(X) | (RUP2_2(X) >> 16)) -#define RUP2_2(X) (RUP2_3(X) | (RUP2_3(X) >> 8)) -#define RUP2_3(X) (RUP2_4(X) | (RUP2_4(X) >> 4)) -#define RUP2_4(X) (RUP2_5(X) | (RUP2_5(X) >> 2)) -#define RUP2_5(X) (RUP2_6(X) | (RUP2_6(X) >> 1)) -#define RUP2_6(X) ((X) - 1) - -/* Returns X rounded down to a power of 2. X must be a constant expression. */ -#define ROUND_DOWN_POW2(X) RDP2__(X) -#define RDP2__(X) (RDP2_1(X) - (RDP2_1(X) >> 1)) -#define RDP2_1(X) (RDP2_2(X) | (RDP2_2(X) >> 16)) -#define RDP2_2(X) (RDP2_3(X) | (RDP2_3(X) >> 8)) -#define RDP2_3(X) (RDP2_4(X) | (RDP2_4(X) >> 4)) -#define RDP2_4(X) (RDP2_5(X) | (RDP2_5(X) >> 2)) -#define RDP2_5(X) ( (X) | ( (X) >> 1)) /* This system's cache line size, in bytes. * Being wrong hurts performance but not correctness. */ @@ -125,10 +78,6 @@ ovs_prefetch_range(const void *start, size_t size) #define OVS_NOT_REACHED() abort() -/* Given ATTR, and TYPE, cast the ATTR to TYPE by first casting ATTR to - * (void *). This is to suppress the alignment warning issued by clang. */ -#define ALIGNED_CAST(TYPE, ATTR) ((TYPE) (void *) (ATTR)) - /* Use "%"PRIuSIZE to format size_t with printf(). */ #ifdef _WIN32 #define PRIdSIZE "Id"