Home | History | Annotate | Download | only in memset_mips
      1 /* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
      2    This file is part of the GNU C Library.
      3    Contributed by Hartvig Ekner <hartvige (at) mips.com>, 2002.
      4 
      5    The GNU C Library is free software; you can redistribute it and/or
      6    modify it under the terms of the GNU Lesser General Public
      7    License as published by the Free Software Foundation; either
      8    version 2.1 of the License, or (at your option) any later version.
      9 
     10    The GNU C Library is distributed in the hope that it will be useful,
     11    but WITHOUT ANY WARRANTY; without even the implied warranty of
     12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     13    Lesser General Public License for more details.
     14 
     15    You should have received a copy of the GNU Lesser General Public
     16    License along with the GNU C Library; if not, write to the Free
     17    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
     18    02111-1307 USA.  */
     19 
     20 /* void *memset_omips(void *s, int c, size_t n).  */
     21 
     22 #include "machine/asm.h"
     23 
     24 #ifdef __mips64
     25 #error mips32 code being compiled for mips64!
     26 #endif
     27 
     28 #if defined(__MIPSEB__)
     29 #error big-endian is not supported in Broadcom MIPS Android platform
     30 # define SWHI	swl		/* high part is left in big-endian	*/
     31 #else
     32 # define SWHI	swr		/* high part is right in little-endian	*/
     33 #endif
     34 
     35 LEAF (memset_omips,0)
     36 	.set	noreorder
     37 
     38 	slti	t1, a2, 8		# Less than 8?
     39 	bne	t1, zero, .Llast8
     40 	move	v0, a0			# Setup exit value before too late
     41 
     42 	beq	a1, zero, .Lueven	# If zero pattern, no need to extend
     43 	andi	a1, 0xff		# Avoid problems with bogus arguments
     44 	sll	t0, a1, 8
     45 	or	a1, t0
     46 	sll	t0, a1, 16
     47 	or	a1, t0			# a1 is now pattern in full word
     48 
     49 .Lueven:
     50 	subu	t0, zero, a0		# Unaligned address?
     51 	andi	t0, 0x3
     52 	beq	t0, zero, .Lchkw
     53 	subu	a2, t0
     54 	SWHI	a1, 0(a0)		# Yes, handle first unaligned part
     55 	addu	a0, t0			# Now both a0 and a2 are updated
     56 
     57 .Lchkw:
     58 	andi	t0, a2, 0x7		# Enough left for one loop iteration?
     59 	beq	t0, a2, .Lchkl
     60 	subu	a3, a2, t0
     61 	addu	a3, a0			# a3 is last loop address +1
     62 	move	a2, t0			# a2 is now # of bytes left after loop
     63 .Lloopw:
     64 	addiu	a0, 8			# Handle 2 words pr. iteration
     65 	sw	a1, -8(a0)
     66 	bne	a0, a3, .Lloopw
     67 	sw	a1, -4(a0)
     68 
     69 .Lchkl:
     70 	andi	t0, a2, 0x4		# Check if there is at least a full
     71 	beq	t0, zero, .Llast8	#  word remaining after the loop
     72 	subu	a2, t0
     73 	sw	a1, 0(a0)		# Yes...
     74 	addiu	a0, 4
     75 
     76 .Llast8:
     77 	blez	a2, .Lexit		# Handle last 8 bytes (if cnt>0)
     78 	addu	a3, a2, a0		# a3 is last address +1
     79 .Llst8l:
     80 	addiu	a0, 1
     81 	bne	a0, a3, .Llst8l
     82 	sb	a1, -1(a0)
     83 .Lexit:
     84 	j	ra			# Bye, bye
     85 	nop
     86 
     87 	.set	reorder
     88 END (memset_omips)
     89 
     90 
     91