^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * arch/alpha/lib/stxncpy.S
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Contributed by Richard Henderson (rth@tamu.edu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copy no more than COUNT bytes of the null-terminated string from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * SRC to DST.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * This is an internal routine used by strncpy, stpncpy, and strncat.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * As such, it uses special linkage conventions to make implementation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * of these public functions more efficient.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * On input:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * t9 = return address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * a0 = DST
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * a1 = SRC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) * a2 = COUNT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) * Furthermore, COUNT may not be zero.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * On output:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) * t0 = last word written
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * t10 = bitmask (with one bit set) indicating the byte position of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * the end of the range specified by COUNT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) * t12 = bitmask (with one bit set) indicating the last byte written
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * a0 = unaligned address of the last *word* written
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) * a2 = the number of full words left in COUNT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) * Furthermore, v0, a3-a5, t11, and $at are untouched.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #include <asm/regdef.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) .set noat
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) .set noreorder
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) .text
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) /* There is a problem with either gdb (as of 4.16) or gas (as of 2.7) that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) doesn't like putting the entry point for a procedure somewhere in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) middle of the procedure descriptor. Work around this by putting the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) aligned copy in its own procedure descriptor */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) .ent stxncpy_aligned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) .align 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) stxncpy_aligned:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) .frame sp, 0, t9, 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) .prologue 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) /* On entry to this basic block:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) t0 == the first destination word for masking back in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) t1 == the first source word. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) /* Create the 1st output word and detect 0's in the 1st input word. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) lda t2, -1 # e1 : build a mask against false zero
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) mskqh t2, a1, t2 # e0 : detection in the src word
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) mskqh t1, a1, t3 # e0 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) ornot t1, t2, t2 # .. e1 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) mskql t0, a1, t0 # e0 : assemble the first output word
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) cmpbge zero, t2, t8 # .. e1 : bits set iff null found
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) or t0, t3, t0 # e0 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) beq a2, $a_eoc # .. e1 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) bne t8, $a_eos # .. e1 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) /* On entry to this basic block:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) t0 == a source word not containing a null. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) $a_loop:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) stq_u t0, 0(a0) # e0 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) addq a0, 8, a0 # .. e1 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) ldq_u t0, 0(a1) # e0 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) addq a1, 8, a1 # .. e1 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) subq a2, 1, a2 # e0 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) cmpbge zero, t0, t8 # .. e1 (stall)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) beq a2, $a_eoc # e1 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) beq t8, $a_loop # e1 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) /* Take care of the final (partial) word store. At this point
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) the end-of-count bit is set in t8 iff it applies.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) On entry to this basic block we have:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) t0 == the source word containing the null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) t8 == the cmpbge mask that found it. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) $a_eos:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) negq t8, t12 # e0 : find low bit set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) and t8, t12, t12 # e1 (stall)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) /* For the sake of the cache, don't read a destination word
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) if we're not going to need it. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) and t12, 0x80, t6 # e0 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) bne t6, 1f # .. e1 (zdb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) /* We're doing a partial word store and so need to combine
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) our source and original destination words. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) ldq_u t1, 0(a0) # e0 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) subq t12, 1, t6 # .. e1 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) or t12, t6, t8 # e0 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) unop #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) zapnot t0, t8, t0 # e0 : clear src bytes > null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) zap t1, t8, t1 # .. e1 : clear dst bytes <= null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) or t0, t1, t0 # e1 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 1: stq_u t0, 0(a0) # e0 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) ret (t9) # e1 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) /* Add the end-of-count bit to the eos detection bitmask. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) $a_eoc:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) or t10, t8, t8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) br $a_eos
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) .end stxncpy_aligned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) .align 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) .ent __stxncpy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) .globl __stxncpy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) __stxncpy:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) .frame sp, 0, t9, 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) .prologue 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) /* Are source and destination co-aligned? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) xor a0, a1, t1 # e0 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) and a0, 7, t0 # .. e1 : find dest misalignment
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) and t1, 7, t1 # e0 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) addq a2, t0, a2 # .. e1 : bias count by dest misalignment
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) subq a2, 1, a2 # e0 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) and a2, 7, t2 # e1 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) srl a2, 3, a2 # e0 : a2 = loop counter = (count - 1)/8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) addq zero, 1, t10 # .. e1 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) sll t10, t2, t10 # e0 : t10 = bitmask of last count byte
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) bne t1, $unaligned # .. e1 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) /* We are co-aligned; take care of a partial first word. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) ldq_u t1, 0(a1) # e0 : load first src word
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) addq a1, 8, a1 # .. e1 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) beq t0, stxncpy_aligned # avoid loading dest word if not needed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) ldq_u t0, 0(a0) # e0 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) br stxncpy_aligned # .. e1 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) /* The source and destination are not co-aligned. Align the destination
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) and cope. We have to be very careful about not reading too much and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) causing a SEGV. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) .align 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) $u_head:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) /* We know just enough now to be able to assemble the first
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) full source word. We can still find a zero at the end of it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) that prevents us from outputting the whole thing.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) On entry to this basic block:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) t0 == the first dest word, unmasked
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) t1 == the shifted low bits of the first source word
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) t6 == bytemask that is -1 in dest word bytes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) ldq_u t2, 8(a1) # e0 : load second src word
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) addq a1, 8, a1 # .. e1 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) mskql t0, a0, t0 # e0 : mask trailing garbage in dst
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) extqh t2, a1, t4 # e0 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) or t1, t4, t1 # e1 : first aligned src word complete
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) mskqh t1, a0, t1 # e0 : mask leading garbage in src
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) or t0, t1, t0 # e0 : first output word complete
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) or t0, t6, t6 # e1 : mask original data for zero test
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) cmpbge zero, t6, t8 # e0 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) beq a2, $u_eocfin # .. e1 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) lda t6, -1 # e0 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) bne t8, $u_final # .. e1 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) mskql t6, a1, t6 # e0 : mask out bits already seen
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) nop # .. e1 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) stq_u t0, 0(a0) # e0 : store first output word
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) or t6, t2, t2 # .. e1 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) cmpbge zero, t2, t8 # e0 : find nulls in second partial
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) addq a0, 8, a0 # .. e1 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) subq a2, 1, a2 # e0 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) bne t8, $u_late_head_exit # .. e1 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) /* Finally, we've got all the stupid leading edge cases taken care
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) of and we can set up to enter the main loop. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) extql t2, a1, t1 # e0 : position hi-bits of lo word
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) beq a2, $u_eoc # .. e1 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) ldq_u t2, 8(a1) # e0 : read next high-order source word
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) addq a1, 8, a1 # .. e1 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) extqh t2, a1, t0 # e0 : position lo-bits of hi word (stall)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) cmpbge zero, t2, t8 # .. e1 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) nop # e0 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) bne t8, $u_eos # .. e1 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) /* Unaligned copy main loop. In order to avoid reading too much,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) the loop is structured to detect zeros in aligned source words.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) This has, unfortunately, effectively pulled half of a loop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) iteration out into the head and half into the tail, but it does
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) prevent nastiness from accumulating in the very thing we want
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) to run as fast as possible.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) On entry to this basic block:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) t0 == the shifted low-order bits from the current source word
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) t1 == the shifted high-order bits from the previous source word
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) t2 == the unshifted current source word
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) We further know that t2 does not contain a null terminator. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) .align 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) $u_loop:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) or t0, t1, t0 # e0 : current dst word now complete
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) subq a2, 1, a2 # .. e1 : decrement word count
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) stq_u t0, 0(a0) # e0 : save the current word
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) addq a0, 8, a0 # .. e1 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) extql t2, a1, t1 # e0 : extract high bits for next time
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) beq a2, $u_eoc # .. e1 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) ldq_u t2, 8(a1) # e0 : load high word for next time
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) addq a1, 8, a1 # .. e1 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) nop # e0 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) cmpbge zero, t2, t8 # e1 : test new word for eos (stall)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) extqh t2, a1, t0 # e0 : extract low bits for current word
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) beq t8, $u_loop # .. e1 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) /* We've found a zero somewhere in the source word we just read.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) If it resides in the lower half, we have one (probably partial)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) word to write out, and if it resides in the upper half, we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) have one full and one partial word left to write out.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) On entry to this basic block:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) t0 == the shifted low-order bits from the current source word
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) t1 == the shifted high-order bits from the previous source word
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) t2 == the unshifted current source word. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) $u_eos:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) or t0, t1, t0 # e0 : first (partial) source word complete
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) nop # .. e1 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) cmpbge zero, t0, t8 # e0 : is the null in this first bit?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) bne t8, $u_final # .. e1 (zdb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) stq_u t0, 0(a0) # e0 : the null was in the high-order bits
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) addq a0, 8, a0 # .. e1 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) subq a2, 1, a2 # e1 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) $u_late_head_exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) extql t2, a1, t0 # .. e0 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) cmpbge zero, t0, t8 # e0 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) or t8, t10, t6 # e1 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) cmoveq a2, t6, t8 # e0 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) nop # .. e1 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) /* Take care of a final (probably partial) result word.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) On entry to this basic block:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) t0 == assembled source word
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) t8 == cmpbge mask that found the null. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) $u_final:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) negq t8, t6 # e0 : isolate low bit set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) and t6, t8, t12 # e1 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) and t12, 0x80, t6 # e0 : avoid dest word load if we can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) bne t6, 1f # .. e1 (zdb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) ldq_u t1, 0(a0) # e0 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) subq t12, 1, t6 # .. e1 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) or t6, t12, t8 # e0 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) zapnot t0, t8, t0 # .. e1 : kill source bytes > null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) zap t1, t8, t1 # e0 : kill dest bytes <= null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) or t0, t1, t0 # e1 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 1: stq_u t0, 0(a0) # e0 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) ret (t9) # .. e1 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) /* Got to end-of-count before end of string.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) On entry to this basic block:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) t1 == the shifted high-order bits from the previous source word */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) $u_eoc:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) and a1, 7, t6 # e1 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) sll t10, t6, t6 # e0 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) and t6, 0xff, t6 # e0 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) bne t6, 1f # .. e1 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) ldq_u t2, 8(a1) # e0 : load final src word
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) nop # .. e1 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) extqh t2, a1, t0 # e0 : extract low bits for last word
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) or t1, t0, t1 # e1 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 1: cmpbge zero, t1, t8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) mov t1, t0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) $u_eocfin: # end-of-count, final word
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) or t10, t8, t8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) br $u_final
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) /* Unaligned copy entry point. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) .align 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) $unaligned:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) ldq_u t1, 0(a1) # e0 : load first source word
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) and a0, 7, t4 # .. e1 : find dest misalignment
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) and a1, 7, t5 # e0 : find src misalignment
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) /* Conditionally load the first destination word and a bytemask
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) with 0xff indicating that the destination byte is sacrosanct. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) mov zero, t0 # .. e1 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) mov zero, t6 # e0 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) beq t4, 1f # .. e1 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) ldq_u t0, 0(a0) # e0 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) lda t6, -1 # .. e1 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) mskql t6, a0, t6 # e0 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) subq a1, t4, a1 # .. e1 : sub dest misalignment from src addr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) /* If source misalignment is larger than dest misalignment, we need
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) extra startup checks to avoid SEGV. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 1: cmplt t4, t5, t12 # e1 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) extql t1, a1, t1 # .. e0 : shift src into place
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) lda t2, -1 # e0 : for creating masks later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) beq t12, $u_head # .. e1 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) extql t2, a1, t2 # e0 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) cmpbge zero, t1, t8 # .. e1 : is there a zero?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) andnot t2, t6, t2 # e0 : dest mask for a single word copy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) or t8, t10, t5 # .. e1 : test for end-of-count too
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) cmpbge zero, t2, t3 # e0 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) cmoveq a2, t5, t8 # .. e1 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) andnot t8, t3, t8 # e0 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) beq t8, $u_head # .. e1 (zdb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) /* At this point we've found a zero in the first partial word of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) the source. We need to isolate the valid source data and mask
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) it into the original destination data. (Incidentally, we know
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) that we'll need at least one byte of that original dest word.) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) ldq_u t0, 0(a0) # e0 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) negq t8, t6 # .. e1 : build bitmask of bytes <= zero
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) mskqh t1, t4, t1 # e0 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) and t6, t8, t12 # .. e1 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) subq t12, 1, t6 # e0 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) or t6, t12, t8 # e1 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) zapnot t2, t8, t2 # e0 : prepare source word; mirror changes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) zapnot t1, t8, t1 # .. e1 : to source validity mask
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) andnot t0, t2, t0 # e0 : zero place for source to reside
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) or t0, t1, t0 # e1 : and put it there
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) stq_u t0, 0(a0) # e0 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) ret (t9) # .. e1 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) .end __stxncpy