Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d6359fd7 authored by Roman Zippel's avatar Roman Zippel Committed by Linus Torvalds
Browse files

[PATCH] m68k: cleanup string functions



- cleanup asm of string functions
- deinline strncat()/strncmp()
- provide non-inlined strcpy()

Signed-off-by: default avatarRoman Zippel <zippel@linux-m68k.org>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 7236e978
Loading
Loading
Loading
Loading
+0 −4
Original line number Original line Diff line number Diff line
#include <linux/module.h>
#include <linux/module.h>
#include <linux/linkage.h>
#include <linux/linkage.h>
#include <linux/sched.h>
#include <linux/sched.h>
#include <linux/string.h>
#include <linux/mm.h>
#include <linux/mm.h>
#include <linux/user.h>
#include <linux/user.h>
#include <linux/elfcore.h>
#include <linux/elfcore.h>
@@ -53,9 +52,6 @@ EXPORT_SYMBOL(mach_beep);
#endif
#endif
EXPORT_SYMBOL(dump_fpu);
EXPORT_SYMBOL(dump_fpu);
EXPORT_SYMBOL(dump_thread);
EXPORT_SYMBOL(dump_thread);
EXPORT_SYMBOL(strnlen);
EXPORT_SYMBOL(strrchr);
EXPORT_SYMBOL(strstr);
EXPORT_SYMBOL(kernel_thread);
EXPORT_SYMBOL(kernel_thread);
#ifdef CONFIG_VME
#ifdef CONFIG_VME
EXPORT_SYMBOL(vme_brdtype);
EXPORT_SYMBOL(vme_brdtype);
+14 −1
Original line number Original line Diff line number Diff line
/*
 * This file is subject to the terms and conditions of the GNU General Public
 * License.  See the file COPYING in the main directory of this archive
 * for more details.
 */

#define __IN_STRING_C


#include <linux/types.h>
#include <linux/module.h>
#include <linux/module.h>
#include <linux/string.h>

char *strcpy(char *dest, const char *src)
{
	return __kernel_strcpy(dest, src);
}
EXPORT_SYMBOL(strcpy);


void *memset(void *s, int c, size_t count)
void *memset(void *s, int c, size_t count)
{
{
+88 −110
Original line number Original line Diff line number Diff line
#ifndef _M68K_STRING_H_
#ifndef _M68K_STRING_H_
#define _M68K_STRING_H_
#define _M68K_STRING_H_


#include <asm/setup.h>
#include <linux/types.h>
#include <asm/page.h>
#include <linux/compiler.h>


#define __HAVE_ARCH_STRCPY
static inline size_t __kernel_strlen(const char *s)
static inline char * strcpy(char * dest,const char *src)
{
{
  char *xdest = dest;
	const char *sc;


  __asm__ __volatile__
	for (sc = s; *sc++; )
       ("1:\tmoveb %1@+,%0@+\n\t"
		;
        "jne 1b"
	return sc - s - 1;
	: "=a" (dest), "=a" (src)
        : "0" (dest), "1" (src) : "memory");
  return xdest;
}
}


#define __HAVE_ARCH_STRNCPY
static inline char *__kernel_strcpy(char *dest, const char *src)
static inline char * strncpy(char *dest, const char *src, size_t n)
{
{
	char *xdest = dest;
	char *xdest = dest;


  if (n == 0)
	asm volatile ("\n"
    return xdest;
		"1:	move.b	(%1)+,(%0)+\n"

		"	jne	1b"
  __asm__ __volatile__
		: "+a" (dest), "+a" (src)
       ("1:\tmoveb %1@+,%0@+\n\t"
		: : "memory");
	"jeq 2f\n\t"
        "subql #1,%2\n\t"
        "jne 1b\n\t"
        "2:"
        : "=a" (dest), "=a" (src), "=d" (n)
        : "0" (dest), "1" (src), "2" (n)
        : "memory");
	return xdest;
	return xdest;
}
}


#define __HAVE_ARCH_STRCAT
#ifndef __IN_STRING_C
static inline char * strcat(char * dest, const char * src)
{
	char *tmp = dest;


	while (*dest)
#define __HAVE_ARCH_STRLEN
		dest++;
#define strlen(s)	(__builtin_constant_p(s) ?	\
	while ((*dest++ = *src++))
			 __builtin_strlen(s) :		\
		;
			 __kernel_strlen(s))


	return tmp;
#define __HAVE_ARCH_STRNLEN
static inline size_t strnlen(const char *s, size_t count)
{
	const char *sc = s;

	asm volatile ("\n"
		"1:     subq.l  #1,%1\n"
		"       jcs     2f\n"
		"       tst.b   (%0)+\n"
		"       jne     1b\n"
		"       subq.l  #1,%0\n"
		"2:"
		: "+a" (sc), "+d" (count));
	return sc - s;
}
}


#define __HAVE_ARCH_STRNCAT
#define __HAVE_ARCH_STRCPY
static inline char * strncat(char *dest, const char *src, size_t count)
#if __GNUC__ >= 4
#define strcpy(d, s)	(__builtin_constant_p(s) &&	\
			 __builtin_strlen(s) <= 32 ?	\
			 __builtin_strcpy(d, s) :	\
			 __kernel_strcpy(d, s))
#else
#define strcpy(d, s)	__kernel_strcpy(d, s)
#endif

#define __HAVE_ARCH_STRNCPY
static inline char *strncpy(char *dest, const char *src, size_t n)
{
{
	char *tmp = dest;
	char *xdest = dest;

	if (count) {
		while (*dest)
			dest++;
		while ((*dest++ = *src++)) {
			if (--count == 0) {
				*dest++='\0';
				break;
			}
		}
	}


	return tmp;
	asm volatile ("\n"
		"	jra	2f\n"
		"1:	move.b	(%1),(%0)+\n"
		"	jeq	2f\n"
		"	addq.l	#1,%1\n"
		"2:	subq.l	#1,%2\n"
		"	jcc	1b\n"
		: "+a" (dest), "+a" (src), "+d" (n)
		: : "memory");
	return xdest;
}
}


#define __HAVE_ARCH_STRCAT
#define strcat(d, s)	({			\
	char *__d = (d);			\
	strcpy(__d + strlen(__d), (s));		\
})

#define __HAVE_ARCH_STRCHR
#define __HAVE_ARCH_STRCHR
static inline char *strchr(const char *s, int c)
static inline char *strchr(const char *s, int c)
{
{
  const char ch = c;
	char sc, ch = c;


  for(; *s != ch; ++s)
	for (; (sc = *s++) != ch; ) {
    if (*s == '\0')
		if (!sc)
      return( NULL );
			return NULL;
  return( (char *) s);
	}
	}

	return (char *)s - 1;
/* strstr !! */

#define __HAVE_ARCH_STRLEN
static inline size_t strlen(const char * s)
{
  const char *sc;
  for (sc = s; *sc != '\0'; ++sc) ;
  return(sc - s);
}
}


/* strnlen !! */

#define __HAVE_ARCH_STRCMP
#define __HAVE_ARCH_STRCMP
static inline int strcmp(const char *cs, const char *ct)
static inline int strcmp(const char *cs, const char *ct)
{
{
  char __res;
	char res;


  __asm__
	asm ("\n"
       ("1:\tmoveb %0@+,%2\n\t" /* get *cs */
		"1:	move.b	(%0)+,%2\n"	/* get *cs */
        "cmpb %1@+,%2\n\t"      /* compare a byte */
		"	cmp.b	(%1)+,%2\n"	/* compare a byte */
        "jne  2f\n\t"           /* not equal, break out */
		"	jne	2f\n"		/* not equal, break out */
        "tstb %2\n\t"           /* at end of cs? */
		"	tst.b	%2\n"		/* at end of cs? */
        "jne  1b\n\t"           /* no, keep going */
		"	jne	1b\n"		/* no, keep going */
        "jra  3f\n\t"		/* strings are equal */
		"	jra	3f\n"		/* strings are equal */
        "2:\tsubb %1@-,%2\n\t"  /* *cs - *ct */
		"2:	sub.b	-(%1),%2\n"	/* *cs - *ct */
		"3:"
		"3:"
        : "=a" (cs), "=a" (ct), "=d" (__res)
		: "+a" (cs), "+a" (ct), "=d" (res));
        : "0" (cs), "1" (ct));
	return res;
  return __res;
}

#define __HAVE_ARCH_STRNCMP
static inline int strncmp(const char * cs,const char * ct,size_t count)
{
  char __res;

  if (!count)
    return 0;
  __asm__
       ("1:\tmovb %0@+,%3\n\t"          /* get *cs */
        "cmpb   %1@+,%3\n\t"            /* compare a byte */
        "jne    3f\n\t"                 /* not equal, break out */
        "tstb   %3\n\t"                 /* at end of cs? */
        "jeq    4f\n\t"                 /* yes, all done */
        "subql  #1,%2\n\t"              /* no, adjust count */
        "jne    1b\n\t"                 /* more to do, keep going */
        "2:\tmoveq #0,%3\n\t"           /* strings are equal */
        "jra    4f\n\t"
        "3:\tsubb %1@-,%3\n\t"          /* *cs - *ct */
        "4:"
        : "=a" (cs), "=a" (ct), "=d" (count), "=d" (__res)
        : "0" (cs), "1" (ct), "2" (count));
  return __res;
}
}


#define __HAVE_ARCH_MEMSET
#define __HAVE_ARCH_MEMSET
@@ -150,4 +126,6 @@ extern void *memmove(void *, const void *, __kernel_size_t);
extern int memcmp(const void *, const void *, __kernel_size_t);
extern int memcmp(const void *, const void *, __kernel_size_t);
#define memcmp(d, s, n) __builtin_memcmp(d, s, n)
#define memcmp(d, s, n) __builtin_memcmp(d, s, n)


#endif

#endif /* _M68K_STRING_H_ */
#endif /* _M68K_STRING_H_ */