diff options
author | Ley Foon Tan <lftan@altera.com> | 2014-11-06 02:20:00 -0500 |
---|---|---|
committer | Ley Foon Tan <lftan@altera.com> | 2014-12-07 23:56:00 -0500 |
commit | eea9507a69d637d52705de8703b168bf6bfe5643 (patch) | |
tree | 7a75b11289b9d4b040468fbccbfbee65280adeba /arch/nios2/include | |
parent | b53e906d255d7bc3539c2729afb8a18c309cd41e (diff) |
nios2: Library functions
Add optimised library functions for nios2.
Signed-off-by: Ley Foon Tan <lftan@altera.com>
Diffstat (limited to 'arch/nios2/include')
-rw-r--r-- | arch/nios2/include/asm/checksum.h | 78 | ||||
-rw-r--r-- | arch/nios2/include/asm/string.h | 24 |
2 files changed, 102 insertions, 0 deletions
diff --git a/arch/nios2/include/asm/checksum.h b/arch/nios2/include/asm/checksum.h new file mode 100644 index 000000000000..6bc1f0d5df7b --- /dev/null +++ b/arch/nios2/include/asm/checksum.h | |||
@@ -0,0 +1,78 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2010 Tobias Klauser <tklauser@distanz.ch> | ||
3 | * Copyright (C) 2004 Microtronix Datacom Ltd. | ||
4 | * | ||
5 | * This file is subject to the terms and conditions of the GNU General Public | ||
6 | * License. See the file "COPYING" in the main directory of this archive | ||
7 | * for more details. | ||
8 | */ | ||
9 | |||
10 | #ifndef _ASM_NIOS_CHECKSUM_H | ||
11 | #define _ASM_NIOS_CHECKSUM_H | ||
12 | |||
13 | /* Take these from lib/checksum.c */ | ||
14 | extern __wsum csum_partial(const void *buff, int len, __wsum sum); | ||
15 | extern __wsum csum_partial_copy(const void *src, void *dst, int len, | ||
16 | __wsum sum); | ||
17 | extern __wsum csum_partial_copy_from_user(const void __user *src, void *dst, | ||
18 | int len, __wsum sum, int *csum_err); | ||
19 | #define csum_partial_copy_nocheck(src, dst, len, sum) \ | ||
20 | csum_partial_copy((src), (dst), (len), (sum)) | ||
21 | |||
22 | extern __sum16 ip_fast_csum(const void *iph, unsigned int ihl); | ||
23 | extern __sum16 ip_compute_csum(const void *buff, int len); | ||
24 | |||
25 | /* | ||
26 | * Fold a partial checksum | ||
27 | */ | ||
28 | static inline __sum16 csum_fold(__wsum sum) | ||
29 | { | ||
30 | __asm__ __volatile__( | ||
31 | "add %0, %1, %0\n" | ||
32 | "cmpltu r8, %0, %1\n" | ||
33 | "srli %0, %0, 16\n" | ||
34 | "add %0, %0, r8\n" | ||
35 | "nor %0, %0, %0\n" | ||
36 | : "=r" (sum) | ||
37 | : "r" (sum << 16), "0" (sum) | ||
38 | : "r8"); | ||
39 | return (__force __sum16) sum; | ||
40 | } | ||
41 | |||
42 | /* | ||
43 | * computes the checksum of the TCP/UDP pseudo-header | ||
44 | * returns a 16-bit checksum, already complemented | ||
45 | */ | ||
46 | #define csum_tcpudp_nofold csum_tcpudp_nofold | ||
47 | static inline __wsum csum_tcpudp_nofold(__be32 saddr, __be32 daddr, | ||
48 | unsigned short len, | ||
49 | unsigned short proto, | ||
50 | __wsum sum) | ||
51 | { | ||
52 | __asm__ __volatile__( | ||
53 | "add %0, %1, %0\n" | ||
54 | "cmpltu r8, %0, %1\n" | ||
55 | "add %0, %0, r8\n" /* add carry */ | ||
56 | "add %0, %2, %0\n" | ||
57 | "cmpltu r8, %0, %2\n" | ||
58 | "add %0, %0, r8\n" /* add carry */ | ||
59 | "add %0, %3, %0\n" | ||
60 | "cmpltu r8, %0, %3\n" | ||
61 | "add %0, %0, r8\n" /* add carry */ | ||
62 | : "=r" (sum), "=r" (saddr) | ||
63 | : "r" (daddr), "r" ((ntohs(len) << 16) + (proto * 256)), | ||
64 | "0" (sum), | ||
65 | "1" (saddr) | ||
66 | : "r8"); | ||
67 | |||
68 | return sum; | ||
69 | } | ||
70 | |||
71 | static inline __sum16 csum_tcpudp_magic(__be32 saddr, __be32 daddr, | ||
72 | unsigned short len, | ||
73 | unsigned short proto, __wsum sum) | ||
74 | { | ||
75 | return csum_fold(csum_tcpudp_nofold(saddr, daddr, len, proto, sum)); | ||
76 | } | ||
77 | |||
78 | #endif /* _ASM_NIOS_CHECKSUM_H */ | ||
diff --git a/arch/nios2/include/asm/string.h b/arch/nios2/include/asm/string.h new file mode 100644 index 000000000000..14dd570d64f7 --- /dev/null +++ b/arch/nios2/include/asm/string.h | |||
@@ -0,0 +1,24 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2004 Microtronix Datacom Ltd | ||
3 | * | ||
4 | * This file is subject to the terms and conditions of the GNU General Public | ||
5 | * License. See the file "COPYING" in the main directory of this archive | ||
6 | * for more details. | ||
7 | */ | ||
8 | |||
9 | #ifndef _ASM_NIOS2_STRING_H | ||
10 | #define _ASM_NIOS2_STRING_H | ||
11 | |||
12 | #ifdef __KERNEL__ | ||
13 | |||
14 | #define __HAVE_ARCH_MEMSET | ||
15 | #define __HAVE_ARCH_MEMCPY | ||
16 | #define __HAVE_ARCH_MEMMOVE | ||
17 | |||
18 | extern void *memset(void *s, int c, size_t count); | ||
19 | extern void *memcpy(void *d, const void *s, size_t count); | ||
20 | extern void *memmove(void *d, const void *s, size_t count); | ||
21 | |||
22 | #endif /* __KERNEL__ */ | ||
23 | |||
24 | #endif /* _ASM_NIOS2_STRING_H */ | ||