From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by mail.toke.dk (Postfix) with ESMTPS id A4396982F63 for ; Tue, 28 Jun 2022 21:50:06 +0200 (CEST) Authentication-Results: mail.toke.dk; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=SLz+/dzg DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1656445806; x=1687981806; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=kf6pyiBAKh8PfjaMPwYDzTHelnIuBG2itheZfTrrJ9k=; b=SLz+/dzgfKJrjXCB3SFvnAYdICqhp/CLWfRpmFFf5pxgNyrk3DKlElQz Op68VJIGJor+gI+YyOQJTmy9z5aZ+dBi7hSBJYu/4amREgeYrBRPkbYPd Qt2sd4AsHtx3Su4w9ackmZ7iv3xMyNU3DwmMT3eZLJ7nibmfVIAlnJf4l lQuGkShslwpQyN/wkQhULJUiotIQjIsKjfU8SOYKJ7kMCAA5vZzRU0WL5 cT0czbDbSVxzjiQ4YO25yawNx1InbrwDgTH4pUAgLuo0Y9zHgP+LIJS9b c+weIIyzkPrep8SCKfSpudftt3h1ZYpEZztHEEi+olyflZ7Zvcj2iaHlX A==; X-IronPort-AV: E=McAfee;i="6400,9594,10392"; a="280596072" X-IronPort-AV: E=Sophos;i="5.92,229,1650956400"; d="scan'208";a="280596072" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Jun 2022 12:50:04 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.92,229,1650956400"; d="scan'208";a="623054245" Received: from irvmail001.ir.intel.com ([10.43.11.63]) by orsmga001.jf.intel.com with ESMTP; 28 Jun 2022 12:49:59 -0700 Received: from newjersey.igk.intel.com (newjersey.igk.intel.com [10.102.20.203]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id 25SJmr9m022013; Tue, 28 Jun 2022 20:49:57 +0100 From: Alexander Lobakin To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Date: Tue, 28 Jun 2022 21:48:08 +0200 Message-Id: <20220628194812.1453059-49-alexandr.lobakin@intel.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220628194812.1453059-1-alexandr.lobakin@intel.com> References: <20220628194812.1453059-1-alexandr.lobakin@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: GYQSMN7V2YFYK626DGIJZDI45OAQIFIZ X-Message-ID-Hash: GYQSMN7V2YFYK626DGIJZDI45OAQIFIZ X-MailFrom: alexandr.lobakin@intel.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Alexander Lobakin , Larysa Zaremba , Michal Swiatkowski , Jesper Dangaard Brouer , =?UTF-8?q?Bj=C3=B6rn=20T=C3=B6pel?= , Magnus Karlsson , Maciej Fijalkowski , Jonathan Lemon , Toke Hoiland-Jorgensen , Lorenzo Bianconi , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jesse Brandeburg , John Fastabend , Yajun Deng , Willem de Bruijn , bpf@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, xdp-hints@xdp-project.net X-Mailman-Version: 3.3.5 Precedence: list Subject: [xdp-hints] [PATCH RFC bpf-next 48/52] libbpf: compress Endianness ops with a macro List-Id: XDP hardware hints design discussion Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: All of the Endianness helpers for BPF programs have the same pattern and can be defined using a compression macro, which will also protect against typos and copy-paste mistakes. Not speaking of saving locs, of course. Ahh, if we only could define macros inside other macros. Signed-off-by: Alexander Lobakin --- tools/lib/bpf/bpf_endian.h | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/tools/lib/bpf/bpf_endian.h b/tools/lib/bpf/bpf_endian.h index ec9db4feca9f..b03db6aa3f14 100644 --- a/tools/lib/bpf/bpf_endian.h +++ b/tools/lib/bpf/bpf_endian.h @@ -77,23 +77,15 @@ # error "Fix your compiler's __BYTE_ORDER__?!" #endif -#define bpf_htons(x) \ +#define __bpf_endop(op, x) \ (__builtin_constant_p(x) ? \ - __bpf_constant_htons(x) : __bpf_htons(x)) -#define bpf_ntohs(x) \ - (__builtin_constant_p(x) ? \ - __bpf_constant_ntohs(x) : __bpf_ntohs(x)) -#define bpf_htonl(x) \ - (__builtin_constant_p(x) ? \ - __bpf_constant_htonl(x) : __bpf_htonl(x)) -#define bpf_ntohl(x) \ - (__builtin_constant_p(x) ? \ - __bpf_constant_ntohl(x) : __bpf_ntohl(x)) -#define bpf_cpu_to_be64(x) \ - (__builtin_constant_p(x) ? \ - __bpf_constant_cpu_to_be64(x) : __bpf_cpu_to_be64(x)) -#define bpf_be64_to_cpu(x) \ - (__builtin_constant_p(x) ? \ - __bpf_constant_be64_to_cpu(x) : __bpf_be64_to_cpu(x)) + __bpf_constant_##op(x) : __bpf_##op(x)) + +#define bpf_htons(x) __bpf_endop(htons, x) +#define bpf_ntohs(x) __bpf_endop(ntohs, x) +#define bpf_htonl(x) __bpf_endop(htonl, x) +#define bpf_ntohl(x) __bpf_endop(ntohl, x) +#define bpf_cpu_to_be64(x) __bpf_endop(cpu_to_be64, x) +#define bpf_be64_to_cpu(x) __bpf_endop(be64_to_cpu, x) #endif /* __BPF_ENDIAN__ */ -- 2.36.1