From patchwork Tue Dec 1 04:00:14 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Pfaff X-Patchwork-Id: 550621 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 6D1CD140273 for ; Tue, 1 Dec 2015 15:00:27 +1100 (AEDT) Received: from archives.nicira.com (localhost [127.0.0.1]) by archives.nicira.com (Postfix) with ESMTP id C719A10575; Mon, 30 Nov 2015 20:00:26 -0800 (PST) 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 1191910574 for ; Mon, 30 Nov 2015 20:00:26 -0800 (PST) Received: from bar5.cudamail.com (unknown [192.168.21.12]) by mx1e4.cudamail.com (Postfix) with ESMTPS id 5B6C31E041F for ; Mon, 30 Nov 2015 21:00:24 -0700 (MST) X-ASG-Debug-ID: 1448942422-09eadd4a32bb710001-byXFYA Received: from mx1-pf1.cudamail.com ([192.168.24.1]) by bar5.cudamail.com with ESMTP id K1xfomReEgN9YKDs (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Mon, 30 Nov 2015 21:00:22 -0700 (MST) X-Barracuda-Envelope-From: blp@ovn.org X-Barracuda-RBL-Trusted-Forwarder: 192.168.24.1 Received: from unknown (HELO relay5-d.mail.gandi.net) (217.70.183.197) by mx1-pf1.cudamail.com with ESMTPS (DHE-RSA-AES256-SHA encrypted); 1 Dec 2015 04:00:22 -0000 Received-SPF: pass (mx1-pf1.cudamail.com: SPF record at ovn.org designates 217.70.183.197 as permitted sender) X-Barracuda-Apparent-Source-IP: 217.70.183.197 X-Barracuda-RBL-IP: 217.70.183.197 Received: from mfilter10-d.gandi.net (mfilter10-d.gandi.net [217.70.178.139]) by relay5-d.mail.gandi.net (Postfix) with ESMTP id C194C41C076; Tue, 1 Dec 2015 05:00:20 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at mfilter10-d.gandi.net Received: from relay5-d.mail.gandi.net ([IPv6:::ffff:217.70.183.197]) by mfilter10-d.gandi.net (mfilter10-d.gandi.net [::ffff:10.0.15.180]) (amavisd-new, port 10024) with ESMTP id 3Udtxe5P8Oxz; Tue, 1 Dec 2015 05:00:19 +0100 (CET) X-Originating-IP: 173.228.112.189 Received: from sigabrt.gateway.sonic.net (173-228-112-189.dsl.dynamic.fusionbroadband.com [173.228.112.189]) (Authenticated sender: blp@ovn.org) by relay5-d.mail.gandi.net (Postfix) with ESMTPSA id AE74F41C074; Tue, 1 Dec 2015 05:00:18 +0100 (CET) X-CudaMail-Envelope-Sender: blp@ovn.org From: Ben Pfaff To: dev@openvswitch.org X-CudaMail-Whitelist-To: dev@openvswitch.org X-CudaMail-MID: CM-E1-1129124132 X-CudaMail-DTE: 113015 X-CudaMail-Originating-IP: 217.70.183.197 Date: Mon, 30 Nov 2015 20:00:14 -0800 X-ASG-Orig-Subj: [##CM-E1-1129124132##][PATCH] csum: Inline csum_add16(), csum_add32(). Message-Id: <1448942414-26194-1-git-send-email-blp@ovn.org> X-Mailer: git-send-email 2.1.3 X-Barracuda-Connect: UNKNOWN[192.168.24.1] X-Barracuda-Start-Time: 1448942422 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 Subject: [ovs-dev] [PATCH] csum: Inline csum_add16(), csum_add32(). 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 two functions are really simple, to the point that inlining them yields less code than calling them: with GCC 4.9 on i386, this change reduces the code generated for packet_csum_pseudoheader() from 112 bytes to 100 bytes. Signed-off-by: Ben Pfaff Acked-by: Thadeu Lima de Souza Cascardo --- lib/csum.c | 22 +--------------------- lib/csum.h | 27 ++++++++++++++++++++++++--- 2 files changed, 25 insertions(+), 24 deletions(-) diff --git a/lib/csum.c b/lib/csum.c index c87c8dd..a0e9967 100644 --- a/lib/csum.c +++ b/lib/csum.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2009, 2010, 2011, 2013 Nicira, Inc. + * Copyright (c) 2008, 2009, 2010, 2011, 2013, 2015 Nicira, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,7 +19,6 @@ #include "unaligned.h" #ifndef __CHECKER__ - /* Returns the IP checksum of the 'n' bytes in 'data'. * * The return value has the same endianness as the data. That is, if 'data' @@ -32,25 +31,6 @@ csum(const void *data, size_t n) return csum_finish(csum_continue(0, data, n)); } -/* Adds the 16 bits in 'new' to the partial IP checksum 'partial' and returns - * the updated checksum. (To start a new checksum, pass 0 for 'partial'. To - * obtain the finished checksum, pass the return value to csum_finish().) */ -uint32_t -csum_add16(uint32_t partial, ovs_be16 new) -{ - return partial + new; -} - -/* Adds the 32 bits in 'new' to the partial IP checksum 'partial' and returns - * the updated checksum. (To start a new checksum, pass 0 for 'partial'. To - * obtain the finished checksum, pass the return value to csum_finish().) */ -uint32_t -csum_add32(uint32_t partial, ovs_be32 new) -{ - return partial + (new >> 16) + (new & 0xffff); -} - - /* Adds the 'n' bytes in 'data' to the partial IP checksum 'partial' and * returns the updated checksum. (To start a new checksum, pass 0 for * 'partial'. To obtain the finished checksum, pass the return value to diff --git a/lib/csum.h b/lib/csum.h index 293339d..fc52086 100644 --- a/lib/csum.h +++ b/lib/csum.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2011 Nicira, Inc. + * Copyright (c) 2008, 2011, 2015 Nicira, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,8 +22,6 @@ #include "openvswitch/types.h" ovs_be16 csum(const void *, size_t); -uint32_t csum_add16(uint32_t partial, ovs_be16); -uint32_t csum_add32(uint32_t partial, ovs_be32); uint32_t csum_continue(uint32_t partial, const void *, size_t); ovs_be16 csum_finish(uint32_t partial); ovs_be16 recalc_csum16(ovs_be16 old_csum, ovs_be16 old_u16, ovs_be16 new_u16); @@ -33,4 +31,27 @@ ovs_be16 recalc_csum48(ovs_be16 old_csum, const struct eth_addr old_mac, ovs_be16 recalc_csum128(ovs_be16 old_csum, ovs_16aligned_be32 old_u32[4], const ovs_be32 new_u32[4]); +#ifndef __CHECKER__ +/* Adds the 16 bits in 'new' to the partial IP checksum 'partial' and returns + * the updated checksum. (To start a new checksum, pass 0 for 'partial'. To + * obtain the finished checksum, pass the return value to csum_finish().) */ +static inline uint32_t +csum_add16(uint32_t partial, ovs_be16 new) +{ + return partial + new; +} + +/* Adds the 32 bits in 'new' to the partial IP checksum 'partial' and returns + * the updated checksum. (To start a new checksum, pass 0 for 'partial'. To + * obtain the finished checksum, pass the return value to csum_finish().) */ +static inline uint32_t +csum_add32(uint32_t partial, ovs_be32 new) +{ + return partial + (new >> 16) + (new & 0xffff); +} +#else +uint32_t csum_add16(uint32_t partial, ovs_be16); +uint32_t csum_add32(uint32_t partial, ovs_be32); +#endif + #endif /* csum.h */