Path: blob/main/lib/libc/powerpc64/string/strcpy_arch_2_05.S
39530 views
/*-1* Copyright (c) 2018 Instituto de Pesquisas Eldorado2* All rights reserved.3*4* Redistribution and use in source and binary forms, with or without5* modification, are permitted provided that the following conditions6* are met:7* 1. Redistributions of source code must retain the above copyright8* notice, this list of conditions and the following disclaimer.9* 2. Redistributions in binary form must reproduce the above copyright10* notice, this list of conditions and the following disclaimer in the11* documentation and/or other materials provided with the distribution.12* 3. Neither the name of the author nor the names of its contributors may13* be used to endorse or promote products derived from this software14*15* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND16* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE17* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE18* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE19* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL20* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS21* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)22* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT23* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY24* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF25* SUCH DAMAGE.26*/272829#include <machine/asm.h>30#if 031RCSID("$NetBSD: strcpy.S,v 1.0 2018/05/08 13:00:49 lbianc Exp $")32#endif3334ENTRY(__strcpy_arch_2_05)35mr %r8, %r33637/*38* Aligning the reading address, even if it is already aligned to avoid39* performance degradation with strings with 8 bytes or less.40*/41.Lalignment:42lbz %r0,0(%r4)43cmpdi cr7,%r0,044stb %r0,0(%r8)45beq cr7,.Lexit46addi %r4,%r4,147addi %r8,%r8,148andi. %r0,%r4,0x749bne .Lalignment5051/* Copy by double word with aligned address. */52.Lcopy_dw:53ld %r0,0(%r4)54xor %r6,%r6,%r655cmpb %r5,%r0,%r656cmpdi cr7,%r5,057bne cr7,.Lcheck_zero58/* Backward r8 to use stdu instruction in Lcopy_dw_loop */59addi %r8,%r8,-860.Lcopy_dw_loop:61stdu %r0,8(%r8)62ldu %r0,8(%r4)63cmpb %r5,%r0,%r664cmpdi cr7,%r5,065beq cr7,.Lcopy_dw_loop6667addi %r8,%r8,8 /* Forward r8 to use std instruction. */68#if defined(__BIG_ENDIAN__)69/* Find where the zero is located. */70.Lcheck_zero:71rldicr. %r5,%r0,0,772beq .Lfound_on_byte_073rldicr. %r7,%r0,8,774beq .Lfound_on_byte_175rldicr. %r7,%r0,16,776beq .Lfound_on_byte_277rldicr. %r7,%r0,24,778beq .Lfound_on_byte_379andis. %r7,%r0,0xff0080beq .Lfound_on_byte_481andis. %r7,%r0,0xff82beq .Lfound_on_byte_583andi. %r7,%r0,0xff0084beq .Lfound_on_byte_68586/* Copy the last string bytes according to the string end position. */87.Lfound_on_byte_7:88std %r0,0(%r8)89b .Lexit9091.Lfound_on_byte_6:92srdi %r6,%r0,3293stw %r6,0(%r8)94srdi %r6,%r0,1695sth %r6,4(%r8)96srdi %r6,%r0,897stb %r6,6(%r8)98b .Lexit99100.Lfound_on_byte_5:101srdi %r6,%r0,32102stw %r6,0(%r8)103srdi %r6,%r0,16104sth %r6,4(%r8)105b .Lexit106107.Lfound_on_byte_4:108srdi %r6,%r0,32109stw %r6,0(%r8)110srdi %r6,%r0,24111stb %r6,4(%r8)112b .Lexit113114.Lfound_on_byte_3:115srdi %r6,%r0,32116stw %r6,0(%r8)117b .Lexit118119.Lfound_on_byte_2:120srdi %r6,%r0,48121sth %r6,0(%r8)122srdi %r6,%r0,40123stb %r6,2(%r8)124b .Lexit125126.Lfound_on_byte_1:127srdi %r6,%r0,48128sth %r6,0(%r8)129b .Lexit130131.Lfound_on_byte_0:132srdi %r6,%r0,56133stb %r6,0(%r8)134#elif defined(__LITTLE_ENDIAN__)135/* Find where the zero is located. */136.Lcheck_zero:137andi. %r7,%r0,0xff138beq .Lfound_on_byte_0139andi. %r7,%r0,0xff00140beq .Lfound_on_byte_1141andis. %r7,%r0,0xff142beq .Lfound_on_byte_2143andis. %r7,%r0,0xff00144beq .Lfound_on_byte_3145rldicr. %r7,%r0,24,7146beq .Lfound_on_byte_4147rldicr. %r7,%r0,16,7148beq .Lfound_on_byte_5149rldicr. %r7,%r0,8,7150beq .Lfound_on_byte_6151152/* Copy the last string bytes according to the string end position. */153.Lfound_on_byte_7:154std %r0,0(%r8)155b .Lexit156157.Lfound_on_byte_6:158stw %r0,0(%r8)159srdi %r6,%r0,32160sth %r6,4(%r8)161srdi %r6,%r0,48162stb %r6,6(%r8)163b .Lexit164165.Lfound_on_byte_5:166stw %r0,0(%r8)167srdi %r6,%r0,32168sth %r6,4(%r8)169b .Lexit170171.Lfound_on_byte_4:172stw %r0,0(%r8)173srdi %r6,%r0,32174stb %r6,4(%r8)175b .Lexit176177.Lfound_on_byte_3:178stw %r0,0(%r8)179b .Lexit180181.Lfound_on_byte_2:182sth %r0,0(%r8)183srdi %r6,%r0,16184stb %r6,2(%r8)185b .Lexit186187.Lfound_on_byte_1:188sth %r0,0(%r8)189b .Lexit190191.Lfound_on_byte_0:192stb %r0,0(%r8)193#else194#error "Unable to determine Endianness"195#endif196.Lexit:197blr198199END(__strcpy_arch_2_05)200201.section .note.GNU-stack,"",%progbits202203204