2N/A * The contents of this file are subject to the terms of the 2N/A * Common Development and Distribution License (the "License"). 2N/A * You may not use this file except in compliance with the License. 2N/A * See the License for the specific language governing permissions 2N/A * and limitations under the License. 2N/A * When distributing Covered Code, include this CDDL HEADER in each 2N/A * If applicable, add the following below this CDDL HEADER, with the 2N/A * fields enclosed by brackets "[]" replaced with your own identifying 2N/A * information: Portions Copyright [yyyy] [name of copyright owner] 2N/A * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 2N/A * Use is subject to license terms. 2N/A * Copy string s2 to s1, truncating or null-padding to always copy n bytes 2N/A * Fast assembler language version of the following C-program for strncpy 2N/A * which represents the `standard' for the C-library. 2N/A * strncpy(char *s1, const char *s2, size_t n) 2N/A * while ((--n != 0) && ((*s1++ = *s2++) != '\0')) 2N/A add %o2, %g4, %g5 ! dst 2N/A or %o4, %lo(0x01010101),%o4! finish loading magic1 2N/A and %g5, 3, %g1 ! dst<1:0> to examine offset 2N/A sllx %o4, 32, %o1 ! spread magic1 2N/A cmp %g1, 1 ! dst offset of 1 or 5 2N/A or %o4, %o1, %o4 ! to all 64 bits 2N/A sub %o2, 8, %o2 ! adjust for dest pre-incr in cpy loops 2N/A be,pn %ncc, .storebyte1241 ! store 1, 2, 4, 1 bytes 2N/A !
we don't get here unless there were >= 16 bytes to pad to begin 2N/A ! with, and we have padded at most 7 bytes suring dst aligning 2N/A add %g4, 7, %o2 ! round up to next dword boundary 2N/A and %o2, -8, %o4 ! pointer to next dword boundary 2N/A and %o2, 8, %o2 ! dword count odd ? 8 : 0 2N/A stx %g0, [%o3] ! store first dword 2N/A addcc %o4, %o2, %o4 ! dword count == 1 ? 2N/A add %g4, %o2, %g4 ! if dword count odd, n -= 8 2N/A bz,pt %ncc, .bytepad ! if dword count == 1, pad leftover bytes 2N/A add %o3, %o2, %o3 ! bump dst if dword count odd 2N/A addcc %o4, 16, %o4 ! count -= 16 2N/A stx %g0, [%o3] ! dst[n] = 0 2N/A stx %g0, [%o3 + 8] ! dst[n+8] = 0 2N/A add %o3, 16, %o3 ! dst += 16 2N/A bcc,pt %ncc, .filldword ! fill dwords until count == 0 2N/A addcc %g4, 16, %g4 ! n -= 16 2N/A bz,pn %ncc, .done ! if n == 0, we are done 2N/A and %g4, 1, %o2 ! byte count odd ? 1 : 0 2N/A stb %g0, [%o3] ! store first byte 2N/A addcc %g4, %o2, %g4 ! byte count == 1 ? 2N/A bz,pt %ncc, .done ! yup, we are done 2N/A add %o3, %o2, %o3 ! bump pointer if odd 2N/A addcc %g4, 2, %g4 ! n -= 2 2N/A stb %g0, [%o3] ! dst[n] = 0 2N/A stb %g0, [%o3 + 1] ! dst[n+1] = 0 2N/A bnz,pt %ncc, .fillbyte ! fill until n == 0 2N/A add %o3, 2, %o3 ! dst += 2 2N/A nop ! pad to align loops below 2N/A nop ! pad to align loops below 2N/A ! this is the last word. It may contain null bytes. store bytes 2N/A ! until n == 0. if null byte encountered, continue 2N/A sub %g4, 8, %g4 ! undo counter pre-increment 2N/A add %o2, 8, %o2 ! adjust dst for counter un-bumping 2N/A srlx %o1, 56, %g1 ! first byte 2N/A stb %g1, [%o2 + %g4] ! store it 2N/A andcc %g1, 0xff, %g0 ! end of src reached ? 2N/A movz %ncc, %g0, %o1 ! if so, start padding with null bytes 2N/A srlx %o1, 40, %g1 ! third byte 2N/A stb %g1, [%o2 + %g4] ! store it 2N/A andcc %g1, 0xff, %g0 ! end of src reached ? 2N/A movz %ncc, %g0, %o1 ! if so, start padding with null bytes 2N/A srlx %o1, 24, %g1 ! fifth byte 2N/A stb %g1, [%o2 + %g4] ! store it 2N/A andcc %g1, 0xff, %g0 ! end of src reached ? 2N/A movz %ncc, %g0, %o1 ! if so, start padding with null bytes 2N/A srlx %o1, 8, %g1 ! seventh byte 2N/A stb %g1, [%o2 + %g4] ! store it 2N/A andcc %
g5, %
g1, %
g0 ! ((x -
0x0101010101010101) & ~x &
0x8080808080808080)
2N/A andcc %
g5, %
g1, %
g0 ! ((x -
0x0101010101010101) & ~x &
0x8080808080808080)
2N/A andcc %
g5, %
g1, %
g0 ! ((x -
0x0101010101010101) & ~x &
0x8080808080808080)
2N/A andcc %
g5, %
g1, %
g0 ! ((x -
0x0101010101010101) & ~x &
0x8080808080808080)