^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/ev6-stxncpy.S
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * 21264 version contributed by Rick Gorton <rick.gorton@api-networks.com>
^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) * Much of the information about 21264 scheduling/coding comes from:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) * Compiler Writer's Guide for the Alpha 21264
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) * abbreviated as 'CWG' in other comments here
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) * ftp.digital.com/pub/Digital/info/semiconductor/literature/dsc-library.html
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) * Scheduling notation:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) * E - either cluster
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) * U - upper subcluster; U0 - subcluster U0; U1 - subcluster U1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) * L - lower subcluster; L0 - subcluster L0; L1 - subcluster L1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) * Try not to change the actual algorithm if possible for consistency.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) #include <asm/regdef.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) .set noat
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) .set noreorder
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) .text
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) /* 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 50) doesn't like putting the entry point for a procedure somewhere in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) middle of the procedure descriptor. Work around this by putting the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) aligned copy in its own procedure descriptor */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) .ent stxncpy_aligned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) .align 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) stxncpy_aligned:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) .frame sp, 0, t9, 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) .prologue 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) /* On entry to this basic block:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) t0 == the first destination word for masking back in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) t1 == the first source word. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) /* Create the 1st output word and detect 0's in the 1st input word. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) lda t2, -1 # E : build a mask against false zero
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) mskqh t2, a1, t2 # U : detection in the src word (stall)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) mskqh t1, a1, t3 # U :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) ornot t1, t2, t2 # E : (stall)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) mskql t0, a1, t0 # U : assemble the first output word
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) cmpbge zero, t2, t8 # E : bits set iff null found
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) or t0, t3, t0 # E : (stall)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) beq a2, $a_eoc # U :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) bne t8, $a_eos # U :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) nop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) nop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) nop
^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:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) t0 == a source word not containing a null. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) * nops here to:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) * separate store quads from load quads
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) * limit of 1 bcond/quad to permit training
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) $a_loop:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) stq_u t0, 0(a0) # L :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) addq a0, 8, a0 # E :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) subq a2, 1, a2 # E :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) nop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) ldq_u t0, 0(a1) # L :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) addq a1, 8, a1 # E :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) cmpbge zero, t0, t8 # E :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) beq a2, $a_eoc # U :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) beq t8, $a_loop # U :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) nop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) nop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) nop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) /* Take care of the final (partial) word store. At this point
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) the end-of-count bit is set in t8 iff it applies.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) On entry to this basic block we have:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) t0 == the source word containing the null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) t8 == the cmpbge mask that found it. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) $a_eos:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) negq t8, t12 # E : find low bit set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) and t8, t12, t12 # E : (stall)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) /* For the sake of the cache, don't read a destination word
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) if we're not going to need it. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) and t12, 0x80, t6 # E : (stall)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) bne t6, 1f # U : (stall)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) /* We're doing a partial word store and so need to combine
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) our source and original destination words. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) ldq_u t1, 0(a0) # L :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) subq t12, 1, t6 # E :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) or t12, t6, t8 # E : (stall)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) zapnot t0, t8, t0 # U : clear src bytes > null (stall)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) zap t1, t8, t1 # .. e1 : clear dst bytes <= null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) or t0, t1, t0 # e1 : (stall)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) nop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) nop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 1: stq_u t0, 0(a0) # L :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) ret (t9) # L0 : Latency=3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) nop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) nop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) /* Add the end-of-count bit to the eos detection bitmask. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) $a_eoc:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) or t10, t8, t8 # E :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) br $a_eos # L0 : Latency=3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) nop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) nop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) .end stxncpy_aligned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) .align 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) .ent __stxncpy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) .globl __stxncpy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) __stxncpy:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) .frame sp, 0, t9, 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) .prologue 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) /* Are source and destination co-aligned? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) xor a0, a1, t1 # E :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) and a0, 7, t0 # E : find dest misalignment
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) and t1, 7, t1 # E : (stall)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) addq a2, t0, a2 # E : bias count by dest misalignment (stall)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) subq a2, 1, a2 # E :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) and a2, 7, t2 # E : (stall)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) srl a2, 3, a2 # U : a2 = loop counter = (count - 1)/8 (stall)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) addq zero, 1, t10 # E :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) sll t10, t2, t10 # U : t10 = bitmask of last count byte
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) bne t1, $unaligned # U :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) /* We are co-aligned; take care of a partial first word. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) ldq_u t1, 0(a1) # L : load first src word
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) addq a1, 8, a1 # E :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) beq t0, stxncpy_aligned # U : avoid loading dest word if not needed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) ldq_u t0, 0(a0) # L :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) nop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) nop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) br stxncpy_aligned # .. e1 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) nop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) nop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) nop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) /* The source and destination are not co-aligned. Align the destination
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) and cope. We have to be very careful about not reading too much and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) causing a SEGV. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) .align 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) $u_head:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) /* We know just enough now to be able to assemble the first
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) full source word. We can still find a zero at the end of it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) that prevents us from outputting the whole thing.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) On entry to this basic block:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) t0 == the first dest word, unmasked
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) t1 == the shifted low bits of the first source word
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) t6 == bytemask that is -1 in dest word bytes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) ldq_u t2, 8(a1) # L : Latency=3 load second src word
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) addq a1, 8, a1 # E :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) mskql t0, a0, t0 # U : mask trailing garbage in dst
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) extqh t2, a1, t4 # U : (3 cycle stall on t2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) or t1, t4, t1 # E : first aligned src word complete (stall)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) mskqh t1, a0, t1 # U : mask leading garbage in src (stall)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) or t0, t1, t0 # E : first output word complete (stall)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) or t0, t6, t6 # E : mask original data for zero test (stall)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) cmpbge zero, t6, t8 # E :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) beq a2, $u_eocfin # U :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) lda t6, -1 # E :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) nop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) bne t8, $u_final # U :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) mskql t6, a1, t6 # U : mask out bits already seen
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) stq_u t0, 0(a0) # L : store first output word
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) or t6, t2, t2 # E : (stall)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) cmpbge zero, t2, t8 # E : find nulls in second partial
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) addq a0, 8, a0 # E :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) subq a2, 1, a2 # E :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) bne t8, $u_late_head_exit # U :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) /* Finally, we've got all the stupid leading edge cases taken care
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) of and we can set up to enter the main loop. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) extql t2, a1, t1 # U : position hi-bits of lo word
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) beq a2, $u_eoc # U :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) ldq_u t2, 8(a1) # L : read next high-order source word
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) addq a1, 8, a1 # E :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) extqh t2, a1, t0 # U : position lo-bits of hi word (stall)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) cmpbge zero, t2, t8 # E :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) nop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) bne t8, $u_eos # U :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) /* Unaligned copy main loop. In order to avoid reading too much,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) the loop is structured to detect zeros in aligned source words.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) This has, unfortunately, effectively pulled half of a loop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) iteration out into the head and half into the tail, but it does
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) prevent nastiness from accumulating in the very thing we want
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) to run as fast as possible.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) On entry to this basic block:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) t0 == the shifted low-order bits from the current source word
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) t1 == the shifted high-order bits from the previous source word
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) t2 == the unshifted current source word
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) We further know that t2 does not contain a null terminator. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) .align 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) $u_loop:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) or t0, t1, t0 # E : current dst word now complete
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) subq a2, 1, a2 # E : decrement word count
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) extql t2, a1, t1 # U : extract low bits for next time
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) addq a0, 8, a0 # E :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) stq_u t0, -8(a0) # U : save the current word
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) beq a2, $u_eoc # U :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) ldq_u t2, 8(a1) # U : Latency=3 load high word for next time
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) addq a1, 8, a1 # E :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) extqh t2, a1, t0 # U : extract low bits (2 cycle stall)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) cmpbge zero, t2, t8 # E : test new word for eos
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) nop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) beq t8, $u_loop # U :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) /* We've found a zero somewhere in the source word we just read.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) If it resides in the lower half, we have one (probably partial)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) word to write out, and if it resides in the upper half, we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) have one full and one partial word left to write out.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) On entry to this basic block:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) t0 == the shifted low-order bits from the current source word
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) t1 == the shifted high-order bits from the previous source word
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) t2 == the unshifted current source word. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) $u_eos:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) or t0, t1, t0 # E : first (partial) source word complete
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) nop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) cmpbge zero, t0, t8 # E : is the null in this first bit? (stall)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) bne t8, $u_final # U : (stall)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) stq_u t0, 0(a0) # L : the null was in the high-order bits
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) addq a0, 8, a0 # E :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) subq a2, 1, a2 # E :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) nop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) $u_late_head_exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) extql t2, a1, t0 # U :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) cmpbge zero, t0, t8 # E :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) or t8, t10, t6 # E : (stall)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) cmoveq a2, t6, t8 # E : Latency=2, extra map slot (stall)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) /* Take care of a final (probably partial) result word.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) On entry to this basic block:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) t0 == assembled source word
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) t8 == cmpbge mask that found the null. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) $u_final:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) negq t8, t6 # E : isolate low bit set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) and t6, t8, t12 # E : (stall)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) and t12, 0x80, t6 # E : avoid dest word load if we can (stall)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) bne t6, 1f # U : (stall)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) ldq_u t1, 0(a0) # L :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) subq t12, 1, t6 # E :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) or t6, t12, t8 # E : (stall)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) zapnot t0, t8, t0 # U : kill source bytes > null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) zap t1, t8, t1 # U : kill dest bytes <= null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) or t0, t1, t0 # E : (stall)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) nop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) nop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 1: stq_u t0, 0(a0) # L :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) ret (t9) # L0 : Latency=3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) /* Got to end-of-count before end of string.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) On entry to this basic block:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) t1 == the shifted high-order bits from the previous source word */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) $u_eoc:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) and a1, 7, t6 # E : avoid final load if possible
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) sll t10, t6, t6 # U : (stall)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) and t6, 0xff, t6 # E : (stall)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) bne t6, 1f # U : (stall)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) ldq_u t2, 8(a1) # L : load final src word
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) nop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) extqh t2, a1, t0 # U : extract low bits for last word (stall)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) or t1, t0, t1 # E : (stall)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 1: cmpbge zero, t1, t8 # E :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) mov t1, t0 # E :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) $u_eocfin: # end-of-count, final word
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) or t10, t8, t8 # E :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) br $u_final # L0 : Latency=3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) /* Unaligned copy entry point. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) .align 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) $unaligned:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) ldq_u t1, 0(a1) # L : load first source word
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) and a0, 7, t4 # E : find dest misalignment
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) and a1, 7, t5 # E : find src misalignment
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) /* Conditionally load the first destination word and a bytemask
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) with 0xff indicating that the destination byte is sacrosanct. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) mov zero, t0 # E :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) mov zero, t6 # E :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) beq t4, 1f # U :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) ldq_u t0, 0(a0) # L :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) lda t6, -1 # E :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) mskql t6, a0, t6 # U :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) nop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) nop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) subq a1, t4, a1 # E : sub dest misalignment from src addr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) /* If source misalignment is larger than dest misalignment, we need
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) extra startup checks to avoid SEGV. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 1: cmplt t4, t5, t12 # E :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) extql t1, a1, t1 # U : shift src into place
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) lda t2, -1 # E : for creating masks later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) beq t12, $u_head # U : (stall)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) extql t2, a1, t2 # U :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) cmpbge zero, t1, t8 # E : is there a zero?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) andnot t2, t6, t2 # E : dest mask for a single word copy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) or t8, t10, t5 # E : test for end-of-count too
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) cmpbge zero, t2, t3 # E :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) cmoveq a2, t5, t8 # E : Latency=2, extra map slot
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) nop # E : keep with cmoveq
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) andnot t8, t3, t8 # E : (stall)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) beq t8, $u_head # U :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) /* At this point we've found a zero in the first partial word of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) the source. We need to isolate the valid source data and mask
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) it into the original destination data. (Incidentally, we know
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) that we'll need at least one byte of that original dest word.) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) ldq_u t0, 0(a0) # L :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) negq t8, t6 # E : build bitmask of bytes <= zero
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) mskqh t1, t4, t1 # U :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) and t6, t8, t12 # E :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) subq t12, 1, t6 # E : (stall)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) or t6, t12, t8 # E : (stall)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) zapnot t2, t8, t2 # U : prepare source word; mirror changes (stall)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) zapnot t1, t8, t1 # U : to source validity mask
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) andnot t0, t2, t0 # E : zero place for source to reside
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) or t0, t1, t0 # E : and put it there (stall both t0, t1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) stq_u t0, 0(a0) # L : (stall)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) ret (t9) # L0 : Latency=3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) nop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) nop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) nop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) .end __stxncpy