linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: luke.starrett@broadcom.com (Luke Starrett)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 1/1] arm64: Add ARM64 optimized IP checksum routine
Date: Tue, 10 May 2016 14:27:27 -0400	[thread overview]
Message-ID: <1462904847-28369-1-git-send-email-luke.starrett@broadcom.com> (raw)

This change implements an optimized checksum for arm64, based loosely on
the original arch/arm implementation.  Load-pair is used for the initial
16B load, reducing the overall number of loads to two for packets without
IP options.  Instruction count is reduced by ~3x compared to generic C
implementation.  Changes were tested against LE and BE operation and for
all possible mis-alignments.

Signed-off-by: Luke Starrett <luke.starrett@broadcom.com>
---
 arch/arm64/include/asm/checksum.h | 57 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 57 insertions(+)
 create mode 100644 arch/arm64/include/asm/checksum.h

diff --git a/arch/arm64/include/asm/checksum.h b/arch/arm64/include/asm/checksum.h
new file mode 100644
index 0000000..15629d7
--- /dev/null
+++ b/arch/arm64/include/asm/checksum.h
@@ -0,0 +1,57 @@
+/*
+ * Copyright 2016 Broadcom
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation (the "GPL").
+ *
+ * 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 version 2 (GPLv2) for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * version 2 (GPLv2) along with this source code.
+ *
+ * ip_fast_csum() loosely derived from original arch/arm implementation
+ */
+
+#ifndef __ASM_ARM64_CHECKSUM_H
+#define __ASM_ARM64_CHECKSUM_H
+
+/*
+ * This is a version of ip_compute_csum() optimized for IP headers,
+ * which always checksum on 4 octet boundaries.
+ */
+static inline __sum16
+ip_fast_csum(const void *iph, unsigned int ihl)
+{
+	u64 tmp, sum;
+
+	__asm__ __volatile__ (
+"	ldp	%0, %3, [%1], #16\n"
+"	sub	%2, %2, #4\n"
+"	adds	%0, %0, %3\n"
+"1:	ldr	%w3, [%1], #4\n"
+"	sub	%2, %2, #1\n"
+"	adcs	%0, %0, %3\n"
+"	tst	%2, #15\n"
+"	bne	1b\n"
+"	adc	%0, %0, xzr\n"
+"	ror	%3, %0, #32\n"
+"	add     %0, %0, %3\n"
+"	lsr	%0, %0, #32\n"
+"	ror	%w3, %w0, #16\n"
+"	add     %w0, %w0, %w3\n"
+"	lsr	%0, %0, #16\n"
+	: "=r" (sum), "=r" (iph), "=r" (ihl), "=r" (tmp)
+	: "1" (iph), "2" (ihl)
+	: "cc", "memory");
+
+	return (__force __sum16)(~sum);
+}
+
+#define ip_fast_csum ip_fast_csum
+#include <asm-generic/checksum.h>
+
+#endif	/* __ASM_ARM64_CHECKSUM_H */
-- 
2.1.0

             reply	other threads:[~2016-05-10 18:27 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-10 18:27 Luke Starrett [this message]
2016-05-11 12:55 ` [PATCH 1/1] arm64: Add ARM64 optimized IP checksum routine Robin Murphy
2016-05-11 18:36   ` Luke Starrett

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1462904847-28369-1-git-send-email-luke.starrett@broadcom.com \
    --to=luke.starrett@broadcom.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).