svn commit: trunk/uClibc/libc/string/cris

pkj at uclibc.org pkj at uclibc.org
Wed Nov 21 12:34:42 UTC 2007


Author: pkj
Date: 2007-11-21 04:34:41 -0800 (Wed, 21 Nov 2007)
New Revision: 20461

Log:
Added optimized versions of strcpy() and strncpy() for CRIS/CRISv32.


Added:
   trunk/uClibc/libc/string/cris/strcpy.c
   trunk/uClibc/libc/string/cris/strncpy.c


Changeset:
Added: trunk/uClibc/libc/string/cris/strcpy.c
===================================================================
--- trunk/uClibc/libc/string/cris/strcpy.c	                        (rev 0)
+++ trunk/uClibc/libc/string/cris/strcpy.c	2007-11-21 12:34:41 UTC (rev 20461)
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2006-2007 Axis Communications AB
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ */
+
+#include <string.h>
+
+libc_hidden_proto(strcpy)
+char *strcpy(char *dest, const char *src)
+{
+  char *ret = dest;
+  unsigned long himagic = 0x80808080L;
+  unsigned long lomagic = 0x01010101L;
+
+  while ((unsigned long)src & (sizeof src - 1))
+  {
+    if (!(*dest++ = *src++))
+    {
+      return ret;
+    }
+  }
+
+  while (1)
+  {
+    unsigned long value = *(unsigned long*)src;
+    unsigned long magic;
+
+    src += sizeof (unsigned long);
+
+    if ((magic = (value - lomagic) & himagic))
+    {
+      if (magic & ~value)
+      {
+        break;
+      }
+    }
+
+    *(unsigned long*)dest = value;
+    dest += sizeof (unsigned long);
+  }
+
+  src -= sizeof (unsigned long);
+
+  while ((*dest++ = *src++))
+  {
+  }
+
+  return ret;
+}
+libc_hidden_def(strcpy)

Added: trunk/uClibc/libc/string/cris/strncpy.c
===================================================================
--- trunk/uClibc/libc/string/cris/strncpy.c	                        (rev 0)
+++ trunk/uClibc/libc/string/cris/strncpy.c	2007-11-21 12:34:41 UTC (rev 20461)
@@ -0,0 +1,61 @@
+/*
+ * Copyright (C) 2006-2007 Axis Communications AB
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ */
+
+#include <string.h>
+
+libc_hidden_proto(memset)
+
+libc_hidden_proto(strncpy)
+char *strncpy(char *dest, const char *src, size_t count)
+{
+  char *ret = dest;
+  unsigned long himagic = 0x80808080L;
+  unsigned long lomagic = 0x01010101L;
+
+  while (count && (unsigned long)src & (sizeof src - 1))
+  {
+    count--;
+    if (!(*dest++ = *src++))
+    {
+      goto finalize;
+    }
+  }
+
+  while (count >= sizeof (unsigned long))
+  {
+    unsigned long value = *(unsigned long*)src;
+    unsigned long magic;
+
+    if ((magic = (value - lomagic) & himagic))
+    {
+      if (magic & ~value)
+      {
+        break;
+      }
+    }
+
+    *(unsigned long*)dest = value;
+    dest += sizeof (unsigned long);
+    src += sizeof (unsigned long);
+    count -= sizeof (unsigned long);
+  }
+
+  while (count)
+  {
+    count--;
+    if (!(*dest++ = *src++))
+      break;
+  }
+
+finalize:
+  if (count)
+  {
+    memset(dest, '\0', count);
+  }
+
+  return ret;
+}
+libc_hidden_def(strncpy)




More information about the uClibc-cvs mailing list