18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * arch/alpha/lib/stxncpy.S 48c2ecf20Sopenharmony_ci * Contributed by Richard Henderson (rth@tamu.edu) 58c2ecf20Sopenharmony_ci * 68c2ecf20Sopenharmony_ci * Copy no more than COUNT bytes of the null-terminated string from 78c2ecf20Sopenharmony_ci * SRC to DST. 88c2ecf20Sopenharmony_ci * 98c2ecf20Sopenharmony_ci * This is an internal routine used by strncpy, stpncpy, and strncat. 108c2ecf20Sopenharmony_ci * As such, it uses special linkage conventions to make implementation 118c2ecf20Sopenharmony_ci * of these public functions more efficient. 128c2ecf20Sopenharmony_ci * 138c2ecf20Sopenharmony_ci * On input: 148c2ecf20Sopenharmony_ci * t9 = return address 158c2ecf20Sopenharmony_ci * a0 = DST 168c2ecf20Sopenharmony_ci * a1 = SRC 178c2ecf20Sopenharmony_ci * a2 = COUNT 188c2ecf20Sopenharmony_ci * 198c2ecf20Sopenharmony_ci * Furthermore, COUNT may not be zero. 208c2ecf20Sopenharmony_ci * 218c2ecf20Sopenharmony_ci * On output: 228c2ecf20Sopenharmony_ci * t0 = last word written 238c2ecf20Sopenharmony_ci * t10 = bitmask (with one bit set) indicating the byte position of 248c2ecf20Sopenharmony_ci * the end of the range specified by COUNT 258c2ecf20Sopenharmony_ci * t12 = bitmask (with one bit set) indicating the last byte written 268c2ecf20Sopenharmony_ci * a0 = unaligned address of the last *word* written 278c2ecf20Sopenharmony_ci * a2 = the number of full words left in COUNT 288c2ecf20Sopenharmony_ci * 298c2ecf20Sopenharmony_ci * Furthermore, v0, a3-a5, t11, and $at are untouched. 308c2ecf20Sopenharmony_ci */ 318c2ecf20Sopenharmony_ci 328c2ecf20Sopenharmony_ci#include <asm/regdef.h> 338c2ecf20Sopenharmony_ci 348c2ecf20Sopenharmony_ci .set noat 358c2ecf20Sopenharmony_ci .set noreorder 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_ci .text 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_ci/* There is a problem with either gdb (as of 4.16) or gas (as of 2.7) that 408c2ecf20Sopenharmony_ci doesn't like putting the entry point for a procedure somewhere in the 418c2ecf20Sopenharmony_ci middle of the procedure descriptor. Work around this by putting the 428c2ecf20Sopenharmony_ci aligned copy in its own procedure descriptor */ 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_ci .ent stxncpy_aligned 458c2ecf20Sopenharmony_ci .align 3 468c2ecf20Sopenharmony_cistxncpy_aligned: 478c2ecf20Sopenharmony_ci .frame sp, 0, t9, 0 488c2ecf20Sopenharmony_ci .prologue 0 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_ci /* On entry to this basic block: 518c2ecf20Sopenharmony_ci t0 == the first destination word for masking back in 528c2ecf20Sopenharmony_ci t1 == the first source word. */ 538c2ecf20Sopenharmony_ci 548c2ecf20Sopenharmony_ci /* Create the 1st output word and detect 0's in the 1st input word. */ 558c2ecf20Sopenharmony_ci lda t2, -1 # e1 : build a mask against false zero 568c2ecf20Sopenharmony_ci mskqh t2, a1, t2 # e0 : detection in the src word 578c2ecf20Sopenharmony_ci mskqh t1, a1, t3 # e0 : 588c2ecf20Sopenharmony_ci ornot t1, t2, t2 # .. e1 : 598c2ecf20Sopenharmony_ci mskql t0, a1, t0 # e0 : assemble the first output word 608c2ecf20Sopenharmony_ci cmpbge zero, t2, t8 # .. e1 : bits set iff null found 618c2ecf20Sopenharmony_ci or t0, t3, t0 # e0 : 628c2ecf20Sopenharmony_ci beq a2, $a_eoc # .. e1 : 638c2ecf20Sopenharmony_ci bne t8, $a_eos # .. e1 : 648c2ecf20Sopenharmony_ci 658c2ecf20Sopenharmony_ci /* On entry to this basic block: 668c2ecf20Sopenharmony_ci t0 == a source word not containing a null. */ 678c2ecf20Sopenharmony_ci 688c2ecf20Sopenharmony_ci$a_loop: 698c2ecf20Sopenharmony_ci stq_u t0, 0(a0) # e0 : 708c2ecf20Sopenharmony_ci addq a0, 8, a0 # .. e1 : 718c2ecf20Sopenharmony_ci ldq_u t0, 0(a1) # e0 : 728c2ecf20Sopenharmony_ci addq a1, 8, a1 # .. e1 : 738c2ecf20Sopenharmony_ci subq a2, 1, a2 # e0 : 748c2ecf20Sopenharmony_ci cmpbge zero, t0, t8 # .. e1 (stall) 758c2ecf20Sopenharmony_ci beq a2, $a_eoc # e1 : 768c2ecf20Sopenharmony_ci beq t8, $a_loop # e1 : 778c2ecf20Sopenharmony_ci 788c2ecf20Sopenharmony_ci /* Take care of the final (partial) word store. At this point 798c2ecf20Sopenharmony_ci the end-of-count bit is set in t8 iff it applies. 808c2ecf20Sopenharmony_ci 818c2ecf20Sopenharmony_ci On entry to this basic block we have: 828c2ecf20Sopenharmony_ci t0 == the source word containing the null 838c2ecf20Sopenharmony_ci t8 == the cmpbge mask that found it. */ 848c2ecf20Sopenharmony_ci 858c2ecf20Sopenharmony_ci$a_eos: 868c2ecf20Sopenharmony_ci negq t8, t12 # e0 : find low bit set 878c2ecf20Sopenharmony_ci and t8, t12, t12 # e1 (stall) 888c2ecf20Sopenharmony_ci 898c2ecf20Sopenharmony_ci /* For the sake of the cache, don't read a destination word 908c2ecf20Sopenharmony_ci if we're not going to need it. */ 918c2ecf20Sopenharmony_ci and t12, 0x80, t6 # e0 : 928c2ecf20Sopenharmony_ci bne t6, 1f # .. e1 (zdb) 938c2ecf20Sopenharmony_ci 948c2ecf20Sopenharmony_ci /* We're doing a partial word store and so need to combine 958c2ecf20Sopenharmony_ci our source and original destination words. */ 968c2ecf20Sopenharmony_ci ldq_u t1, 0(a0) # e0 : 978c2ecf20Sopenharmony_ci subq t12, 1, t6 # .. e1 : 988c2ecf20Sopenharmony_ci or t12, t6, t8 # e0 : 998c2ecf20Sopenharmony_ci unop # 1008c2ecf20Sopenharmony_ci zapnot t0, t8, t0 # e0 : clear src bytes > null 1018c2ecf20Sopenharmony_ci zap t1, t8, t1 # .. e1 : clear dst bytes <= null 1028c2ecf20Sopenharmony_ci or t0, t1, t0 # e1 : 1038c2ecf20Sopenharmony_ci 1048c2ecf20Sopenharmony_ci1: stq_u t0, 0(a0) # e0 : 1058c2ecf20Sopenharmony_ci ret (t9) # e1 : 1068c2ecf20Sopenharmony_ci 1078c2ecf20Sopenharmony_ci /* Add the end-of-count bit to the eos detection bitmask. */ 1088c2ecf20Sopenharmony_ci$a_eoc: 1098c2ecf20Sopenharmony_ci or t10, t8, t8 1108c2ecf20Sopenharmony_ci br $a_eos 1118c2ecf20Sopenharmony_ci 1128c2ecf20Sopenharmony_ci .end stxncpy_aligned 1138c2ecf20Sopenharmony_ci 1148c2ecf20Sopenharmony_ci .align 3 1158c2ecf20Sopenharmony_ci .ent __stxncpy 1168c2ecf20Sopenharmony_ci .globl __stxncpy 1178c2ecf20Sopenharmony_ci__stxncpy: 1188c2ecf20Sopenharmony_ci .frame sp, 0, t9, 0 1198c2ecf20Sopenharmony_ci .prologue 0 1208c2ecf20Sopenharmony_ci 1218c2ecf20Sopenharmony_ci /* Are source and destination co-aligned? */ 1228c2ecf20Sopenharmony_ci xor a0, a1, t1 # e0 : 1238c2ecf20Sopenharmony_ci and a0, 7, t0 # .. e1 : find dest misalignment 1248c2ecf20Sopenharmony_ci and t1, 7, t1 # e0 : 1258c2ecf20Sopenharmony_ci addq a2, t0, a2 # .. e1 : bias count by dest misalignment 1268c2ecf20Sopenharmony_ci subq a2, 1, a2 # e0 : 1278c2ecf20Sopenharmony_ci and a2, 7, t2 # e1 : 1288c2ecf20Sopenharmony_ci srl a2, 3, a2 # e0 : a2 = loop counter = (count - 1)/8 1298c2ecf20Sopenharmony_ci addq zero, 1, t10 # .. e1 : 1308c2ecf20Sopenharmony_ci sll t10, t2, t10 # e0 : t10 = bitmask of last count byte 1318c2ecf20Sopenharmony_ci bne t1, $unaligned # .. e1 : 1328c2ecf20Sopenharmony_ci 1338c2ecf20Sopenharmony_ci /* We are co-aligned; take care of a partial first word. */ 1348c2ecf20Sopenharmony_ci 1358c2ecf20Sopenharmony_ci ldq_u t1, 0(a1) # e0 : load first src word 1368c2ecf20Sopenharmony_ci addq a1, 8, a1 # .. e1 : 1378c2ecf20Sopenharmony_ci 1388c2ecf20Sopenharmony_ci beq t0, stxncpy_aligned # avoid loading dest word if not needed 1398c2ecf20Sopenharmony_ci ldq_u t0, 0(a0) # e0 : 1408c2ecf20Sopenharmony_ci br stxncpy_aligned # .. e1 : 1418c2ecf20Sopenharmony_ci 1428c2ecf20Sopenharmony_ci 1438c2ecf20Sopenharmony_ci/* The source and destination are not co-aligned. Align the destination 1448c2ecf20Sopenharmony_ci and cope. We have to be very careful about not reading too much and 1458c2ecf20Sopenharmony_ci causing a SEGV. */ 1468c2ecf20Sopenharmony_ci 1478c2ecf20Sopenharmony_ci .align 3 1488c2ecf20Sopenharmony_ci$u_head: 1498c2ecf20Sopenharmony_ci /* We know just enough now to be able to assemble the first 1508c2ecf20Sopenharmony_ci full source word. We can still find a zero at the end of it 1518c2ecf20Sopenharmony_ci that prevents us from outputting the whole thing. 1528c2ecf20Sopenharmony_ci 1538c2ecf20Sopenharmony_ci On entry to this basic block: 1548c2ecf20Sopenharmony_ci t0 == the first dest word, unmasked 1558c2ecf20Sopenharmony_ci t1 == the shifted low bits of the first source word 1568c2ecf20Sopenharmony_ci t6 == bytemask that is -1 in dest word bytes */ 1578c2ecf20Sopenharmony_ci 1588c2ecf20Sopenharmony_ci ldq_u t2, 8(a1) # e0 : load second src word 1598c2ecf20Sopenharmony_ci addq a1, 8, a1 # .. e1 : 1608c2ecf20Sopenharmony_ci mskql t0, a0, t0 # e0 : mask trailing garbage in dst 1618c2ecf20Sopenharmony_ci extqh t2, a1, t4 # e0 : 1628c2ecf20Sopenharmony_ci or t1, t4, t1 # e1 : first aligned src word complete 1638c2ecf20Sopenharmony_ci mskqh t1, a0, t1 # e0 : mask leading garbage in src 1648c2ecf20Sopenharmony_ci or t0, t1, t0 # e0 : first output word complete 1658c2ecf20Sopenharmony_ci or t0, t6, t6 # e1 : mask original data for zero test 1668c2ecf20Sopenharmony_ci cmpbge zero, t6, t8 # e0 : 1678c2ecf20Sopenharmony_ci beq a2, $u_eocfin # .. e1 : 1688c2ecf20Sopenharmony_ci lda t6, -1 # e0 : 1698c2ecf20Sopenharmony_ci bne t8, $u_final # .. e1 : 1708c2ecf20Sopenharmony_ci 1718c2ecf20Sopenharmony_ci mskql t6, a1, t6 # e0 : mask out bits already seen 1728c2ecf20Sopenharmony_ci nop # .. e1 : 1738c2ecf20Sopenharmony_ci stq_u t0, 0(a0) # e0 : store first output word 1748c2ecf20Sopenharmony_ci or t6, t2, t2 # .. e1 : 1758c2ecf20Sopenharmony_ci cmpbge zero, t2, t8 # e0 : find nulls in second partial 1768c2ecf20Sopenharmony_ci addq a0, 8, a0 # .. e1 : 1778c2ecf20Sopenharmony_ci subq a2, 1, a2 # e0 : 1788c2ecf20Sopenharmony_ci bne t8, $u_late_head_exit # .. e1 : 1798c2ecf20Sopenharmony_ci 1808c2ecf20Sopenharmony_ci /* Finally, we've got all the stupid leading edge cases taken care 1818c2ecf20Sopenharmony_ci of and we can set up to enter the main loop. */ 1828c2ecf20Sopenharmony_ci 1838c2ecf20Sopenharmony_ci extql t2, a1, t1 # e0 : position hi-bits of lo word 1848c2ecf20Sopenharmony_ci beq a2, $u_eoc # .. e1 : 1858c2ecf20Sopenharmony_ci ldq_u t2, 8(a1) # e0 : read next high-order source word 1868c2ecf20Sopenharmony_ci addq a1, 8, a1 # .. e1 : 1878c2ecf20Sopenharmony_ci extqh t2, a1, t0 # e0 : position lo-bits of hi word (stall) 1888c2ecf20Sopenharmony_ci cmpbge zero, t2, t8 # .. e1 : 1898c2ecf20Sopenharmony_ci nop # e0 : 1908c2ecf20Sopenharmony_ci bne t8, $u_eos # .. e1 : 1918c2ecf20Sopenharmony_ci 1928c2ecf20Sopenharmony_ci /* Unaligned copy main loop. In order to avoid reading too much, 1938c2ecf20Sopenharmony_ci the loop is structured to detect zeros in aligned source words. 1948c2ecf20Sopenharmony_ci This has, unfortunately, effectively pulled half of a loop 1958c2ecf20Sopenharmony_ci iteration out into the head and half into the tail, but it does 1968c2ecf20Sopenharmony_ci prevent nastiness from accumulating in the very thing we want 1978c2ecf20Sopenharmony_ci to run as fast as possible. 1988c2ecf20Sopenharmony_ci 1998c2ecf20Sopenharmony_ci On entry to this basic block: 2008c2ecf20Sopenharmony_ci t0 == the shifted low-order bits from the current source word 2018c2ecf20Sopenharmony_ci t1 == the shifted high-order bits from the previous source word 2028c2ecf20Sopenharmony_ci t2 == the unshifted current source word 2038c2ecf20Sopenharmony_ci 2048c2ecf20Sopenharmony_ci We further know that t2 does not contain a null terminator. */ 2058c2ecf20Sopenharmony_ci 2068c2ecf20Sopenharmony_ci .align 3 2078c2ecf20Sopenharmony_ci$u_loop: 2088c2ecf20Sopenharmony_ci or t0, t1, t0 # e0 : current dst word now complete 2098c2ecf20Sopenharmony_ci subq a2, 1, a2 # .. e1 : decrement word count 2108c2ecf20Sopenharmony_ci stq_u t0, 0(a0) # e0 : save the current word 2118c2ecf20Sopenharmony_ci addq a0, 8, a0 # .. e1 : 2128c2ecf20Sopenharmony_ci extql t2, a1, t1 # e0 : extract high bits for next time 2138c2ecf20Sopenharmony_ci beq a2, $u_eoc # .. e1 : 2148c2ecf20Sopenharmony_ci ldq_u t2, 8(a1) # e0 : load high word for next time 2158c2ecf20Sopenharmony_ci addq a1, 8, a1 # .. e1 : 2168c2ecf20Sopenharmony_ci nop # e0 : 2178c2ecf20Sopenharmony_ci cmpbge zero, t2, t8 # e1 : test new word for eos (stall) 2188c2ecf20Sopenharmony_ci extqh t2, a1, t0 # e0 : extract low bits for current word 2198c2ecf20Sopenharmony_ci beq t8, $u_loop # .. e1 : 2208c2ecf20Sopenharmony_ci 2218c2ecf20Sopenharmony_ci /* We've found a zero somewhere in the source word we just read. 2228c2ecf20Sopenharmony_ci If it resides in the lower half, we have one (probably partial) 2238c2ecf20Sopenharmony_ci word to write out, and if it resides in the upper half, we 2248c2ecf20Sopenharmony_ci have one full and one partial word left to write out. 2258c2ecf20Sopenharmony_ci 2268c2ecf20Sopenharmony_ci On entry to this basic block: 2278c2ecf20Sopenharmony_ci t0 == the shifted low-order bits from the current source word 2288c2ecf20Sopenharmony_ci t1 == the shifted high-order bits from the previous source word 2298c2ecf20Sopenharmony_ci t2 == the unshifted current source word. */ 2308c2ecf20Sopenharmony_ci$u_eos: 2318c2ecf20Sopenharmony_ci or t0, t1, t0 # e0 : first (partial) source word complete 2328c2ecf20Sopenharmony_ci nop # .. e1 : 2338c2ecf20Sopenharmony_ci cmpbge zero, t0, t8 # e0 : is the null in this first bit? 2348c2ecf20Sopenharmony_ci bne t8, $u_final # .. e1 (zdb) 2358c2ecf20Sopenharmony_ci 2368c2ecf20Sopenharmony_ci stq_u t0, 0(a0) # e0 : the null was in the high-order bits 2378c2ecf20Sopenharmony_ci addq a0, 8, a0 # .. e1 : 2388c2ecf20Sopenharmony_ci subq a2, 1, a2 # e1 : 2398c2ecf20Sopenharmony_ci 2408c2ecf20Sopenharmony_ci$u_late_head_exit: 2418c2ecf20Sopenharmony_ci extql t2, a1, t0 # .. e0 : 2428c2ecf20Sopenharmony_ci cmpbge zero, t0, t8 # e0 : 2438c2ecf20Sopenharmony_ci or t8, t10, t6 # e1 : 2448c2ecf20Sopenharmony_ci cmoveq a2, t6, t8 # e0 : 2458c2ecf20Sopenharmony_ci nop # .. e1 : 2468c2ecf20Sopenharmony_ci 2478c2ecf20Sopenharmony_ci /* Take care of a final (probably partial) result word. 2488c2ecf20Sopenharmony_ci On entry to this basic block: 2498c2ecf20Sopenharmony_ci t0 == assembled source word 2508c2ecf20Sopenharmony_ci t8 == cmpbge mask that found the null. */ 2518c2ecf20Sopenharmony_ci$u_final: 2528c2ecf20Sopenharmony_ci negq t8, t6 # e0 : isolate low bit set 2538c2ecf20Sopenharmony_ci and t6, t8, t12 # e1 : 2548c2ecf20Sopenharmony_ci 2558c2ecf20Sopenharmony_ci and t12, 0x80, t6 # e0 : avoid dest word load if we can 2568c2ecf20Sopenharmony_ci bne t6, 1f # .. e1 (zdb) 2578c2ecf20Sopenharmony_ci 2588c2ecf20Sopenharmony_ci ldq_u t1, 0(a0) # e0 : 2598c2ecf20Sopenharmony_ci subq t12, 1, t6 # .. e1 : 2608c2ecf20Sopenharmony_ci or t6, t12, t8 # e0 : 2618c2ecf20Sopenharmony_ci zapnot t0, t8, t0 # .. e1 : kill source bytes > null 2628c2ecf20Sopenharmony_ci zap t1, t8, t1 # e0 : kill dest bytes <= null 2638c2ecf20Sopenharmony_ci or t0, t1, t0 # e1 : 2648c2ecf20Sopenharmony_ci 2658c2ecf20Sopenharmony_ci1: stq_u t0, 0(a0) # e0 : 2668c2ecf20Sopenharmony_ci ret (t9) # .. e1 : 2678c2ecf20Sopenharmony_ci 2688c2ecf20Sopenharmony_ci /* Got to end-of-count before end of string. 2698c2ecf20Sopenharmony_ci On entry to this basic block: 2708c2ecf20Sopenharmony_ci t1 == the shifted high-order bits from the previous source word */ 2718c2ecf20Sopenharmony_ci$u_eoc: 2728c2ecf20Sopenharmony_ci and a1, 7, t6 # e1 : 2738c2ecf20Sopenharmony_ci sll t10, t6, t6 # e0 : 2748c2ecf20Sopenharmony_ci and t6, 0xff, t6 # e0 : 2758c2ecf20Sopenharmony_ci bne t6, 1f # .. e1 : 2768c2ecf20Sopenharmony_ci 2778c2ecf20Sopenharmony_ci ldq_u t2, 8(a1) # e0 : load final src word 2788c2ecf20Sopenharmony_ci nop # .. e1 : 2798c2ecf20Sopenharmony_ci extqh t2, a1, t0 # e0 : extract low bits for last word 2808c2ecf20Sopenharmony_ci or t1, t0, t1 # e1 : 2818c2ecf20Sopenharmony_ci 2828c2ecf20Sopenharmony_ci1: cmpbge zero, t1, t8 2838c2ecf20Sopenharmony_ci mov t1, t0 2848c2ecf20Sopenharmony_ci 2858c2ecf20Sopenharmony_ci$u_eocfin: # end-of-count, final word 2868c2ecf20Sopenharmony_ci or t10, t8, t8 2878c2ecf20Sopenharmony_ci br $u_final 2888c2ecf20Sopenharmony_ci 2898c2ecf20Sopenharmony_ci /* Unaligned copy entry point. */ 2908c2ecf20Sopenharmony_ci .align 3 2918c2ecf20Sopenharmony_ci$unaligned: 2928c2ecf20Sopenharmony_ci 2938c2ecf20Sopenharmony_ci ldq_u t1, 0(a1) # e0 : load first source word 2948c2ecf20Sopenharmony_ci 2958c2ecf20Sopenharmony_ci and a0, 7, t4 # .. e1 : find dest misalignment 2968c2ecf20Sopenharmony_ci and a1, 7, t5 # e0 : find src misalignment 2978c2ecf20Sopenharmony_ci 2988c2ecf20Sopenharmony_ci /* Conditionally load the first destination word and a bytemask 2998c2ecf20Sopenharmony_ci with 0xff indicating that the destination byte is sacrosanct. */ 3008c2ecf20Sopenharmony_ci 3018c2ecf20Sopenharmony_ci mov zero, t0 # .. e1 : 3028c2ecf20Sopenharmony_ci mov zero, t6 # e0 : 3038c2ecf20Sopenharmony_ci beq t4, 1f # .. e1 : 3048c2ecf20Sopenharmony_ci ldq_u t0, 0(a0) # e0 : 3058c2ecf20Sopenharmony_ci lda t6, -1 # .. e1 : 3068c2ecf20Sopenharmony_ci mskql t6, a0, t6 # e0 : 3078c2ecf20Sopenharmony_ci subq a1, t4, a1 # .. e1 : sub dest misalignment from src addr 3088c2ecf20Sopenharmony_ci 3098c2ecf20Sopenharmony_ci /* If source misalignment is larger than dest misalignment, we need 3108c2ecf20Sopenharmony_ci extra startup checks to avoid SEGV. */ 3118c2ecf20Sopenharmony_ci 3128c2ecf20Sopenharmony_ci1: cmplt t4, t5, t12 # e1 : 3138c2ecf20Sopenharmony_ci extql t1, a1, t1 # .. e0 : shift src into place 3148c2ecf20Sopenharmony_ci lda t2, -1 # e0 : for creating masks later 3158c2ecf20Sopenharmony_ci beq t12, $u_head # .. e1 : 3168c2ecf20Sopenharmony_ci 3178c2ecf20Sopenharmony_ci extql t2, a1, t2 # e0 : 3188c2ecf20Sopenharmony_ci cmpbge zero, t1, t8 # .. e1 : is there a zero? 3198c2ecf20Sopenharmony_ci andnot t2, t6, t2 # e0 : dest mask for a single word copy 3208c2ecf20Sopenharmony_ci or t8, t10, t5 # .. e1 : test for end-of-count too 3218c2ecf20Sopenharmony_ci cmpbge zero, t2, t3 # e0 : 3228c2ecf20Sopenharmony_ci cmoveq a2, t5, t8 # .. e1 : 3238c2ecf20Sopenharmony_ci andnot t8, t3, t8 # e0 : 3248c2ecf20Sopenharmony_ci beq t8, $u_head # .. e1 (zdb) 3258c2ecf20Sopenharmony_ci 3268c2ecf20Sopenharmony_ci /* At this point we've found a zero in the first partial word of 3278c2ecf20Sopenharmony_ci the source. We need to isolate the valid source data and mask 3288c2ecf20Sopenharmony_ci it into the original destination data. (Incidentally, we know 3298c2ecf20Sopenharmony_ci that we'll need at least one byte of that original dest word.) */ 3308c2ecf20Sopenharmony_ci 3318c2ecf20Sopenharmony_ci ldq_u t0, 0(a0) # e0 : 3328c2ecf20Sopenharmony_ci negq t8, t6 # .. e1 : build bitmask of bytes <= zero 3338c2ecf20Sopenharmony_ci mskqh t1, t4, t1 # e0 : 3348c2ecf20Sopenharmony_ci and t6, t8, t12 # .. e1 : 3358c2ecf20Sopenharmony_ci subq t12, 1, t6 # e0 : 3368c2ecf20Sopenharmony_ci or t6, t12, t8 # e1 : 3378c2ecf20Sopenharmony_ci 3388c2ecf20Sopenharmony_ci zapnot t2, t8, t2 # e0 : prepare source word; mirror changes 3398c2ecf20Sopenharmony_ci zapnot t1, t8, t1 # .. e1 : to source validity mask 3408c2ecf20Sopenharmony_ci 3418c2ecf20Sopenharmony_ci andnot t0, t2, t0 # e0 : zero place for source to reside 3428c2ecf20Sopenharmony_ci or t0, t1, t0 # e1 : and put it there 3438c2ecf20Sopenharmony_ci stq_u t0, 0(a0) # e0 : 3448c2ecf20Sopenharmony_ci ret (t9) # .. e1 : 3458c2ecf20Sopenharmony_ci 3468c2ecf20Sopenharmony_ci .end __stxncpy 347