Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F157321345
D15369.id55289.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
4 KB
Referenced Files
None
Subscribers
None
D15369.id55289.diff
View Options
Index: lib/libc/powerpc64/string/Makefile.inc
===================================================================
--- /dev/null
+++ lib/libc/powerpc64/string/Makefile.inc
@@ -0,0 +1,4 @@
+# $FreeBSD$
+
+MDSRCS+= \
+ strncpy.S
Index: lib/libc/powerpc64/string/strncpy.S
===================================================================
--- /dev/null
+++ lib/libc/powerpc64/string/strncpy.S
@@ -0,0 +1,165 @@
+/*-
+ * Copyright (c) 2018 Instituto de Pesquisas Eldorado
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the author nor the names of its contributors may
+ * be used to endorse or promote products derived from this software
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <machine/asm.h>
+__FBSDID("$FreeBSD$");
+
+#if 0
+ RCSID("$NetBSD: strncpy.S,v 1.0 2018/05/08 13:00:05 lbianc Exp $")
+#endif
+
+ENTRY(strncpy)
+ std 3,-8(1)
+
+ xor 6,6,6 /* Perare register with zero value. */
+
+ cmpdi cr7,5,0
+ ble cr7,.Lexit
+
+/* Copy by double word. */
+.Lcopy_dw:
+ cmpdi cr7,5,8
+ blt cr7,.Lstd_byte
+ ld 0,0(4)
+ cmpb 7,0,6
+ cmpdi cr7,7,0
+ bne cr7,.Lcheck_zero
+ std 0,0(3)
+ addi 5,5,-8
+ cmpdi cr7,5,0
+ beq cr7,.Lexit
+ cmpdi cr7,5,8
+ blt cr7,.Lstd_byte_fix
+.Lcopy_dw_loop:
+ ldu 0,8(4)
+ cmpb 7,0,6
+ cmpdi cr7,7,0
+ bne cr7,.Lcheck_zero_fix
+ stdu 0,8(3)
+ addi 5,5,-8
+ cmpdi cr7,5,8
+ bge cr7,.Lcopy_dw_loop
+ cmpdi cr7,5,0
+ bne cr7,.Lstd_byte_fix
+ ld 3,-8(1)
+ blr
+
+/* Copy by byte */
+.Lstd_byte_fix:
+ addi 3,3,8 /* Fix addresses from update instructions. */
+ addi 4,4,8
+.Lstd_byte:
+ cmpdi 0,5,0
+ beqlr 0
+ addi 9,5,-1
+ addi 10,3,-1
+ rldicl 9,9,0,32
+ addi 9,9,1
+ mtctr 9
+.Lstd_byte_loop:
+ lbz 9,0(4)
+ addic 8,9,-1
+ stbu 9,1(10)
+ addze 4,4
+ bdnz .Lstd_byte_loop
+ blr
+
+/* Store zeros by byte. */
+.Lstd_byte_z:
+ stb 6,0(3)
+ addi 5,5,-1
+ cmpdi cr7,5,0
+ beq cr7,.Lexit
+ addi 3,3,1
+ b .Lstd_byte_z
+
+/* Fin where the zero is located. */
+.Lcheck_zero_fix:
+ addi 3,3,8
+.Lcheck_zero:
+ addi 5,5,-8
+ rldicr. 7,0,0,7
+ beq .Lfound_on_byte_1
+ rldicr. 7,0,8,7
+ beq .Lfound_on_byte_2
+ rldicr. 7,0,16,7
+ beq .Lfound_on_byte_3
+ rldicr. 7,0,24,7
+ beq .Lfound_on_byte_4
+ andis. 7,0,0xff00
+ beq .Lfound_on_byte_5
+ andis. 7,0,0xff
+ beq .Lfound_on_byte_6
+ andi. 7,0,0xff00
+ beq .Lfound_on_byte_7
+
+/* As zero was found in a double word before r5 be zero, store the entire
+ register with zeros after the end of the string */
+.Lstd_dw:
+ std 0,0(3)
+ addi 3,3,8
+ cmpdi cr7,5,0
+ beq cr7,.Lexit
+ b .Lstd_byte_z
+
+/* Treatment of each byte where the zero my be found. */
+.Lfound_on_byte_7:
+ rldicr 0,0,0,56
+ b .Lstd_dw
+
+.Lfound_on_byte_6:
+ rldicr 0,0,0,48
+ b .Lstd_dw
+
+.Lfound_on_byte_5:
+ rldicr 0,0,0,40
+ b .Lstd_dw
+
+.Lfound_on_byte_4:
+ rldicr 0,0,0,32
+ b .Lstd_dw
+
+.Lfound_on_byte_3:
+ rldicr 0,0,0,24
+ b .Lstd_dw
+
+.Lfound_on_byte_2:
+ rldicr 0,0,0,16
+ b .Lstd_dw
+
+.Lfound_on_byte_1:
+ mr 0,6
+ b .Lstd_dw
+
+.Lexit:
+ ld 3,-8(1)
+ blr
+
+END(strncpy)
+
+ .section .note.GNU-stack,"",%progbits
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, May 21, 7:54 AM (13 h, 26 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
33380484
Default Alt Text
D15369.id55289.diff (4 KB)
Attached To
Mode
D15369: strncpy optimization for PowerPC64
Attached
Detach File
Event Timeline
Log In to Comment