From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by sourceware.org (Postfix) with ESMTPS id A09A9398E468 for ; Fri, 9 Apr 2021 15:15:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org A09A9398E468 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tdevries@suse.de X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id BD685B029; Fri, 9 Apr 2021 15:15:39 +0000 (UTC) Date: Fri, 9 Apr 2021 17:15:38 +0200 From: Tom de Vries To: dwz@sourceware.org, jakub@redhat.com, mark@klomp.org Subject: [committed] Add util.h Message-ID: <20210409151536.GA21626@delia> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: dwz@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Dwz mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 09 Apr 2021 15:15:42 -0000 Hi, Factor out utility macros into new file util.h. Committed to trunk. Thanks, - Tom Add util.h 2021-04-09 Tom de Vries * args.c (IMPLIES): Remove. * dwz.c (pool_alloc): Use ALIGNOF_STRUCT. (USE_GNUC, likely, unlikely, FORCE_INLINE, UNUSED, USED, IMPLIES): (MAX, MIN, ALIGN_STRUCT): Move ... * util.h: ... here. New file. Add ALIGNOF_STRUCT. --- args.c | 2 +- dwz.c | 46 +++------------------------------------------- util.h | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 44 deletions(-) diff --git a/args.c b/args.c index 23bf1d4..cb11f25 100644 --- a/args.c +++ b/args.c @@ -31,7 +31,7 @@ #include "args.h" -#define IMPLIES(A, B) (!((A) && !(B))) +#include "util.h" #if DEVEL int tracing; diff --git a/dwz.c b/dwz.c index dfae64f..07c576e 100644 --- a/dwz.c +++ b/dwz.c @@ -43,14 +43,7 @@ #include "hashtab.h" #include "sha1.h" #include "args.h" - -#ifndef USE_GNUC -#ifdef __GNUC__ -#define USE_GNUC 1 -#else -#define USE_GNUC 0 -#endif -#endif +#include "util.h" #ifndef SHF_COMPRESSED /* Glibc elf.h contains SHF_COMPRESSED starting v2.22. Libelf libelf.h has @@ -118,29 +111,6 @@ # define NT_GNU_BUILD_ID 3 #endif -#if USE_GNUC && __GNUC__ >= 3 -# define likely(x) __builtin_expect (!!(x), 1) -# define unlikely(x) __builtin_expect (!!(x), 0) -#else -# define likely(x) (x) -# define unlikely(x) (x) -#endif - -#if USE_GNUC -# define FORCE_INLINE __attribute__((always_inline)) -# define UNUSED __attribute__((unused)) -# define USED __attribute__((used)) -#else -# define FORCE_INLINE -# define UNUSED -# define USED -#endif - -/* Utility macro. */ -#define IMPLIES(A, B) (!((A) && !(B))) -#define MAX(A, B) ((A) > (B) ? (A) : (B)) -#define MIN(A, B) ((A) < (B) ? (A) : (B)) - /* Print memory amount M (in kb) in both exact and human readable, like so: 1382508 (1.3G). */ static void @@ -1129,11 +1099,6 @@ die_cu (dw_die_ref die) #define die_safe_nextdup(die) \ ((die)->die_toplevel ? (die)->die_nextdup : (dw_die_ref) NULL) -#if USE_GNUC -# define ALIGN_STRUCT(name) -#else -# define ALIGN_STRUCT(name) struct align_##name { char c; struct name s; }; -#endif ALIGN_STRUCT (abbrev_tag) ALIGN_STRUCT (dw_file) ALIGN_STRUCT (dw_cu) @@ -1194,13 +1159,8 @@ pool_destroy (void) } } -#if USE_GNUC -# define pool_alloc(name, size) \ - (struct name *) pool_alloc_1 (__alignof__ (struct name), size) -#else -# define pool_alloc(name, size) \ - (struct name *) pool_alloc_1 (offsetof (struct align_##name, s), size) -#endif +#define pool_alloc(name, size) \ + (struct name *) pool_alloc_1 (ALIGNOF_STRUCT (name), size) static struct abbrev_tag * pool_clone_abbrev (struct abbrev_tag *t) diff --git a/util.h b/util.h new file mode 100644 index 0000000..7caac06 --- /dev/null +++ b/util.h @@ -0,0 +1,60 @@ +/* Copyright (C) 2001-2021 Red Hat, Inc. + Copyright (C) 2003 Free Software Foundation, Inc. + Copyright (C) 2019-2021 SUSE LLC. + Written by Jakub Jelinek , 2012. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; see the file COPYING. If not, write to + the Free Software Foundation, 51 Franklin Street - Fifth Floor, + Boston, MA 02110-1301, USA. */ + +/* Utility macros. */ + +#define IMPLIES(A, B) (!((A) && !(B))) + +#define MAX(A, B) ((A) > (B) ? (A) : (B)) +#define MIN(A, B) ((A) < (B) ? (A) : (B)) + +#ifndef USE_GNUC +#ifdef __GNUC__ +#define USE_GNUC 1 +#else +#define USE_GNUC 0 +#endif +#endif + +#if USE_GNUC && __GNUC__ >= 3 +# define likely(x) __builtin_expect (!!(x), 1) +# define unlikely(x) __builtin_expect (!!(x), 0) +#else +# define likely(x) (x) +# define unlikely(x) (x) +#endif + +#if USE_GNUC +# define FORCE_INLINE __attribute__((always_inline)) +# define UNUSED __attribute__((unused)) +# define USED __attribute__((used)) +#else +# define FORCE_INLINE +# define UNUSED +# define USED +#endif + +#if USE_GNUC +# define ALIGN_STRUCT(name) +# define ALIGNOF_STRUCT(name) __alignof__ (struct name) +#else +# define ALIGN_STRUCT(name) struct align_##name { char c; struct name s; }; +# define ALIGNOF_STRUCT(name) offsetof (struct align_##name, s) +#endif