summaryrefslogtreecommitdiff
path: root/libc/string/powerpc/memset.c
diff options
context:
space:
mode:
authorPeter S. Mazinger <ps.m@gmx.net>2005-11-11 22:24:53 +0000
committerPeter S. Mazinger <ps.m@gmx.net>2005-11-11 22:24:53 +0000
commitd0c2fc99e181270291f0f09da87d29609ce6d328 (patch)
tree085c270f1013331d790d3933a8bcd5ddb1103684 /libc/string/powerpc/memset.c
parent5ab11964a80debf091ff65ad15938b628ab9f597 (diff)
Split up MSRC file, bzero left out
Diffstat (limited to 'libc/string/powerpc/memset.c')
-rw-r--r--libc/string/powerpc/memset.c81
1 files changed, 81 insertions, 0 deletions
diff --git a/libc/string/powerpc/memset.c b/libc/string/powerpc/memset.c
new file mode 100644
index 000000000..c5903afa6
--- /dev/null
+++ b/libc/string/powerpc/memset.c
@@ -0,0 +1,81 @@
+/*
+ * Copyright (C) 2004 Joakim Tjernlund
+ * Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ */
+
+/* These are carefully optimized mem*() functions for PPC written in C.
+ * Don't muck around with these function without checking the generated
+ * assmbler code.
+ * It is possible to optimize these significantly more by using specific
+ * data cache instructions(mainly dcbz). However that requires knownledge
+ * about the CPU's cache line size.
+ *
+ * BUG ALERT!
+ * The cache instructions on MPC8xx CPU's are buggy(they don't update
+ * the DAR register when causing a DTLB Miss/Error) and cannot be
+ * used on 8xx CPU's without a kernel patch to work around this
+ * problem.
+ */
+
+#include <string.h>
+
+static inline int expand_byte_word(int c){
+ /* this does:
+ c = c << 8 | c;
+ c = c << 16 | c ;
+ */
+ asm("rlwimi %0,%0,8,16,23\n"
+ "\trlwimi %0,%0,16,0,15\n"
+ : "=r" (c) : "0" (c));
+ return c;
+}
+void attribute_hidden *__memset(void *to, int c, size_t n)
+{
+ unsigned long rem, chunks;
+ unsigned char *tmp_to;
+
+ chunks = n / 8;
+ tmp_to = to - 4;
+ c = expand_byte_word(c);
+ if (!chunks)
+ goto lessthan8;
+ rem = (unsigned long )tmp_to % 4;
+ if (rem)
+ goto align;
+ copy_chunks:
+ do {
+ *(unsigned long *)(tmp_to+4) = c;
+ tmp_to += 4;
+ *(unsigned long *)(tmp_to+4) = c;
+ tmp_to += 4;
+ } while (--chunks);
+ lessthan8:
+ n = n % 8;
+ if (n >= 4) {
+ *(unsigned long *)(tmp_to+4) = c;
+ tmp_to += 4;
+ n = n-4;
+ }
+ if (!n ) return to;
+ tmp_to += 3;
+ do {
+ *++tmp_to = c;
+ } while (--n);
+
+ return to;
+ align:
+ rem = 4 - rem;
+ n = n-rem;
+ do {
+ *(tmp_to+4) = c;
+ ++tmp_to;
+ } while (--rem);
+ chunks = n / 8;
+ if (chunks)
+ goto copy_chunks;
+ goto lessthan8;
+}
+
+strong_alias(__memset, memset)