applied patch: strcmp for sh64

Joern Rennecke joern.rennecke@superh.com
Sun Jul 7 07:59:00 GMT 2002


-- 
--------------------------
SuperH
2430 Aztec West / Almondsbury / BRISTOL / BS32 4AQ
T:+44 1454 462330
-------------- next part --------------
Sun Jul  7 01:23:45 2002  J"orn Rennecke <joern.rennecke@superh.com>

	* libc/machine/sh/Makefile.am (lib_a_SOURCES):
	Make strcmp.S unconditional.
	* libc/machine/sh/Makefile.in: Regenerate.
	* libc/machine/sh/asm.h (DELAYED_BRANCHES, SL): Also for __SH5__ .
	* strcmp.S (strcmp): Add SHmedia variant.  Use different registers
	for SHcompact.

Index: libc/machine/sh/Makefile.am
===================================================================
RCS file: /cvs/src/src/newlib/libc/machine/sh/Makefile.am,v
retrieving revision 1.4
diff -p -r1.4 Makefile.am
*** libc/machine/sh/Makefile.am	24 Jun 2002 20:30:08 -0000	1.4
--- libc/machine/sh/Makefile.am	7 Jul 2002 00:10:52 -0000
*************** INCLUDES = $(NEWLIB_CFLAGS) $(CROSS_CFLA
*** 6,16 ****
  
  noinst_LIBRARIES = lib.a
  
- if SH64
- lib_a_SOURCES = memcpy.S memset.S setjmp.S strcpy.S strlen.S
- else
  lib_a_SOURCES = memcpy.S memset.S setjmp.S strcpy.S strlen.S strcmp.S
- endif
  
  memcpy.o: asm.h
  memset.o: asm.h
--- 6,12 ----
Index: libc/machine/sh/asm.h
===================================================================
RCS file: /cvs/src/src/newlib/libc/machine/sh/asm.h,v
retrieving revision 1.3
diff -p -r1.3 asm.h
*** libc/machine/sh/asm.h	6 Mar 2002 10:43:18 -0000	1.3
--- libc/machine/sh/asm.h	7 Jul 2002 00:10:52 -0000
***************
*** 23,29 ****
  	_ENTRY(_C_LABEL(name))
  
  #if (defined (__sh2__) || defined (__sh3__) || defined (__SH3E__) \
!      || defined (__SH4_SINGLE__) || defined (__SH4__)) || defined(__SH4_SINGLE_ONLY__)
  #define DELAYED_BRANCHES
  #define SL(branch, dest, in_slot, in_slot_arg2) \
  	branch##.s dest; in_slot, in_slot_arg2
--- 23,30 ----
  	_ENTRY(_C_LABEL(name))
  
  #if (defined (__sh2__) || defined (__sh3__) || defined (__SH3E__) \
!      || defined (__SH4_SINGLE__) || defined (__SH4__)) \
!      || defined (__SH4_SINGLE_ONLY__) || defined (__SH5__)
  #define DELAYED_BRANCHES
  #define SL(branch, dest, in_slot, in_slot_arg2) \
  	branch##.s dest; in_slot, in_slot_arg2
Index: libc/machine/sh/strcmp.S
===================================================================
RCS file: /cvs/src/src/newlib/libc/machine/sh/strcmp.S,v
retrieving revision 1.1.1.1
diff -p -r1.1.1.1 strcmp.S
*** libc/machine/sh/strcmp.S	17 Feb 2000 19:39:47 -0000	1.1.1.1
--- libc/machine/sh/strcmp.S	7 Jul 2002 00:10:52 -0000
***************
*** 1,42 ****
! ! Entry: r4: destination
! !        r5: source
! ! Exit:  r0: result
! !        r1-r2,r4-r5: clobbered
  
  #include "asm.h"
  
  ENTRY(strcmp)
! 	mov     r4,r0
! 	or      r5,r0
  	tst	#3,r0
  	bf	L_setup_char_loop
  	mov	#0,r0
  #ifdef DELAYED_BRANCHES
! 	mov.l	@r4+,r1
  	.align  2
  Longword_loop:
! 	mov.l	@r5+,r2
  	cmp/str	r0,r1
  	bt	Longword_loop_end
! 	cmp/eq	r1,r2
  	bt.s	Longword_loop
! 	mov.l	@r4+,r1
! 	add #-4, r4
  Longword_loop_end:
! 	add #-4, r4
! 	add #-4, r5
  L_setup_char_loop:
! 	mov.b	@r4+,r0
  	.align  2
  L_char_loop:
! 	mov.b	@r5+,r1
  	tst	r0,r0
  	bt	L_return
  	cmp/eq	r0,r1
  	bt.s L_char_loop
! 	mov.b	@r4+,r0
! 	add	#-2,r4
! 	mov.b	@r4,r0
  #else /* ! DELAYED_BRANCHES */
  	.align  2
  Longword_loop:
--- 1,198 ----
! ! SH5 code Copyright 2002 SuperH Ltd.
  
  #include "asm.h"
  
  ENTRY(strcmp)
! 
! #if __SHMEDIA__
! 	ld.ub	r2,0,r4
! 	pt/l	quickret0,tr0
! 	ld.ub	r3,0,r5
! 	ptabs	r18,tr2
! 	beqi/u	r4,0,tr0
! 	ld.ub	r2,1,r6
! 	bne/u	r4,r5,tr0
! 	pt/l	quickret1,tr1
! 	ld.ub	r3,1,r7
! 	beqi/u	r6,0,tr1
! 	ld.ub	r2,2,r4
! 	bne/u	r6,r7,tr1
! 	ld.ub	r3,2,r5
! 	beqi/u	r4,0,tr0
! 	ld.ub	r2,3,r6
! 	bne/u	r4,r5,tr0
! 	ld.ub	r3,3,r7
! 	beqi/u	r6,0,tr1
! 	ld.ub	r2,4,r4
! 	bne/u	r6,r7,tr1
! 	ld.ub	r3,4,r5
! 	beqi/u	r4,0,tr0
! 	ld.ub	r2,5,r6
! 	bne/u	r4,r5,tr0
! 	ld.ub	r3,5,r7
! 	beqi/u	r6,0,tr1
! 	ld.ub	r2,6,r4
! 	bne/u	r6,r7,tr1
! 	ld.ub	r3,6,r5
! 	beqi/u	r4,0,tr0
! 	ld.ub	r2,7,r6
! 	bne/u	r4,r5,tr0
! 	ld.ub	r3,7,r7
! 	beqi/u	r6,0,tr1
! 	sub	r3,r2,r3
! 	bne/u	r6,r7,tr1
! 
! 	andi	r2,-8,r2
! 	add	r3,r2,r3
! 	ldlo.q	r3,8,r23
! 	pt	r23_zero,tr0
! 	shlli	r3,3,r22
! 	sub	r63,r22,r20
! 	movi	0x101,r6
! 	mperm.w	r6,r63,r6
! 	SHLO	r6,r22,r7
! 	msubs.ub r7,r23,r8
! 	pt	loop,tr1
! 	bnei/u	r8,0,tr0 // r23_zero
! 	pt	found_zero,tr0
! 	ori	r3,7,r3
! 	addi	r3,9,r3
! 	sub	r3,r2,r3
! 	bne/l	r7,r6,tr1 // loop
! 	/* The strings are aligned to each other.  */
! 	pt	al_loop,tr1
! 	pt	al_found_zero,tr0
! 	addi	r3,-8,r3
! al_loop:
! 	ld.q	r2,8,r4
! 	ldx.q	r2,r3,r5
! 	addi	r2,8,r2
! 	mcmpeq.b r63,r4,r8
! 	pt	cmp_quad,tr3
! 	bnei/u	r8,0,tr0  // al_found_zero
! 	beq/l	r4,r5,tr1 // al_loop
! 	blink	tr3,r63   // cmp_quad
! 
! 	.balign 8
! quickret0:
! 	sub	r4,r5,r2
! 	blink	tr2,r63
! quickret1:
! 	sub	r6,r7,r2
! 	blink	tr2,r63
! 
! loop:
! 	ld.q	r2,8,r4
! 	ldx.q	r2,r3,r19
! 	addi	r2,8,r2
! 	msubs.ub r6,r4,r8
! 	mcmpeq.b r63,r19,r9
! 	SHHI	r19,r20,r21
! 	or	r21,r23,r5
! 	SHLO	r19,r22,r23
! 	bne/u	r8,r9,tr0 // found_zero
! 	beq/l	r4,r5,tr1 // loop
! cmp_quad:
! #ifdef __LITTLE_ENDIAN__
! 	byterev r4,r4
! 	byterev r5,r5
! #endif
! 	cmpgtu	r4,r5,r6
! 	cmpgtu	r5,r4,r7
! 	sub	r6,r7,r2
! 	blink tr2,r63
! found_zero:
! 	pt	zero_now,tr0
! 	mcmpeq.b r63,r5,r7
! 	pt	cmp_quad,tr1
! 	bne/u	r8,r7,tr0 // zero_now
! 	bne/u	r4,r5,tr1 // cmp_quad
! 	SHLO	r9,r22,r8
! r23_zero:
! 	ld.q	r2,8,r4
! 	add	r23,r63,r5
! zero_now:
! al_found_zero:
! /* We konw that one of the values has at lest one zero, and r8 holds
!    an 0x01 or 0xff mask for every zero found in one of the operands.
!    If both operands have the first zero in the same place, this mask
!    allows us to truncate the comparison to the valid bytes in the
!    strings.  If the first zero is in different places, it doesn't
!    matter if some invalid bytes are included, since the comparison
!    of the zero with the non-zero will determine the outcome.  */
! #ifdef __LITTLE_ENDIAN__
! 	shlli	r8,8,r8
! 	addi	r8,-1,r9
! 	andc	r9,r8,r8
! 	and	r8,r4,r4
! 	and	r8,r5,r5
! #else
! 	shlri r8,1,r8
! 	nsb	r8,r8
! 	addi	r8,8,r8
! 	andi	r8,56,r8
! 	sub	r63,r8,r8
! 	shlrd	r4,r8,r4
! 	shlrd	r5,r8,r5
! #endif
! #ifdef __LITTLE_ENDIAN__
! 	byterev r4,r4
! 	byterev r5,r5
! #endif
! 	cmpgtu	r4,r5,r6
! 	cmpgtu	r5,r4,r7
! 	sub	r6,r7,r2
! 	blink tr2,r63
! 
! #else /* ! __SHMEDIA__, i.e. SH 1..4 / SHcompact */
! 
! #ifdef __SH5__
! #define STR1 r2
! #define STR2 r3
! #define RESULT r2
! #define TMP r4
! #else
! ! Entry: r4: string1
! !        r5: string2
! ! Exit:  r0: result
! !        r1-r2,r4-r5: clobbered
! #define STR1 r4
! #define STR2 r5
! #define RESULT r0
! #define TMP r2
! #endif /* __SH5__ */
! 
! 	mov     STR1,r0
! 	or      STR2,r0
  	tst	#3,r0
  	bf	L_setup_char_loop
  	mov	#0,r0
  #ifdef DELAYED_BRANCHES
! 	mov.l	@STR1+,r1
  	.align  2
  Longword_loop:
! 	mov.l	@STR2+,TMP
  	cmp/str	r0,r1
  	bt	Longword_loop_end
! 	cmp/eq	r1,TMP
  	bt.s	Longword_loop
! 	mov.l	@STR1+,r1
! 	add #-4, STR1
  Longword_loop_end:
! 	add #-4, STR1
! 	add #-4, STR2
  L_setup_char_loop:
! 	mov.b	@STR1+,r0
  	.align  2
  L_char_loop:
! 	mov.b	@STR2+,r1
  	tst	r0,r0
  	bt	L_return
  	cmp/eq	r0,r1
  	bt.s L_char_loop
! 	mov.b	@STR1+,r0
! 	add	#-2,STR1
! 	mov.b	@STR1,r0
  #else /* ! DELAYED_BRANCHES */
  	.align  2
  Longword_loop:
*************** L_char_loop:
*** 60,66 ****
  	bt L_char_loop
  #endif
  L_return:
! 	extu.b	r0,r0
  	extu.b	r1,r1
  	rts
! 	sub	r1,r0
--- 216,223 ----
  	bt L_char_loop
  #endif
  L_return:
! 	extu.b	r0,RESULT
  	extu.b	r1,r1
  	rts
! 	sub	r1,RESULT
! #endif /* ! __SHMEDIA__ */
Index: libc/machine/sh/Makefile.in
===================================================================
RCS file: /cvs/src/src/newlib/libc/machine/sh/Makefile.in,v
retrieving revision 1.9
diff -p -r1.9 Makefile.in
*** libc/machine/sh/Makefile.in	4 Jul 2002 19:57:39 -0000	1.9
--- libc/machine/sh/Makefile.in	7 Jul 2002 00:24:37 -0000
***************
*** 1,6 ****
! # Makefile.in generated automatically by automake 1.4 from Makefile.am
  
! # Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc.
  # This Makefile.in is free software; the Free Software Foundation
  # gives unlimited permission to copy and/or distribute it,
  # with or without modifications, as long as this notice is preserved.
--- 1,6 ----
! # Makefile.in generated automatically by automake 1.4-p5 from Makefile.am
  
! # Copyright (C) 1994, 1995-8, 1999, 2001 Free Software Foundation, Inc.
  # This Makefile.in is free software; the Free Software Foundation
  # gives unlimited permission to copy and/or distribute it,
  # with or without modifications, as long as this notice is preserved.
*************** AUTOMAKE_OPTIONS = cygnus
*** 88,95 ****
  INCLUDES = $(NEWLIB_CFLAGS) $(CROSS_CFLAGS) $(TARGET_CFLAGS)
  
  noinst_LIBRARIES = lib.a
! @SH64_TRUE@lib_a_SOURCES = @SH64_TRUE@memcpy.S memset.S setjmp.S strcpy.S strlen.S
! @SH64_FALSE@lib_a_SOURCES = @SH64_FALSE@memcpy.S memset.S setjmp.S strcpy.S strlen.S strcmp.S
  
  ACLOCAL_AMFLAGS = -I ../../..
  CONFIG_STATUS_DEPENDENCIES = $(newlib_basedir)/configure.host
--- 88,95 ----
  INCLUDES = $(NEWLIB_CFLAGS) $(CROSS_CFLAGS) $(TARGET_CFLAGS)
  
  noinst_LIBRARIES = lib.a
! 
! lib_a_SOURCES = memcpy.S memset.S setjmp.S strcpy.S strlen.S strcmp.S
  
  ACLOCAL_AMFLAGS = -I ../../..
  CONFIG_STATUS_DEPENDENCIES = $(newlib_basedir)/configure.host
*************** DEFS = @DEFS@ -I. -I$(srcdir) 
*** 103,111 ****
  CPPFLAGS = @CPPFLAGS@
  LIBS = @LIBS@
  lib_a_LIBADD = 
! @SH64_TRUE@lib_a_OBJECTS =  memcpy.o memset.o setjmp.o strcpy.o strlen.o
! @SH64_FALSE@lib_a_OBJECTS =  memcpy.o memset.o setjmp.o strcpy.o \
! @SH64_FALSE@strlen.o strcmp.o
  CFLAGS = @CFLAGS@
  COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
  CCLD = $(CC)
--- 103,109 ----
  CPPFLAGS = @CPPFLAGS@
  LIBS = @LIBS@
  lib_a_LIBADD = 
! lib_a_OBJECTS =  memcpy.o memset.o setjmp.o strcpy.o strlen.o strcmp.o
  CFLAGS = @CFLAGS@
  COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
  CCLD = $(CC)


More information about the Newlib mailing list