strchr.S 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * arch/alpha/lib/strchr.S
  3. * Contributed by Richard Henderson ([email protected])
  4. *
  5. * Return the address of a given character within a null-terminated
  6. * string, or null if it is not found.
  7. */
  8. #include <asm/export.h>
  9. #include <asm/regdef.h>
  10. .set noreorder
  11. .set noat
  12. .align 3
  13. .globl strchr
  14. .ent strchr
  15. strchr:
  16. .frame sp, 0, ra
  17. .prologue 0
  18. zapnot a1, 1, a1 # e0 : zero extend the search character
  19. ldq_u t0, 0(a0) # .. e1 : load first quadword
  20. sll a1, 8, t5 # e0 : replicate the search character
  21. andnot a0, 7, v0 # .. e1 : align our loop pointer
  22. or t5, a1, a1 # e0 :
  23. lda t4, -1 # .. e1 : build garbage mask
  24. sll a1, 16, t5 # e0 :
  25. cmpbge zero, t0, t2 # .. e1 : bits set iff byte == zero
  26. mskqh t4, a0, t4 # e0 :
  27. or t5, a1, a1 # .. e1 :
  28. sll a1, 32, t5 # e0 :
  29. cmpbge zero, t4, t4 # .. e1 : bits set iff byte is garbage
  30. or t5, a1, a1 # e0 :
  31. xor t0, a1, t1 # .. e1 : make bytes == c zero
  32. cmpbge zero, t1, t3 # e0 : bits set iff byte == c
  33. or t2, t3, t0 # e1 : bits set iff char match or zero match
  34. andnot t0, t4, t0 # e0 : clear garbage bits
  35. bne t0, $found # .. e1 (zdb)
  36. $loop: ldq t0, 8(v0) # e0 :
  37. addq v0, 8, v0 # .. e1 :
  38. nop # e0 :
  39. xor t0, a1, t1 # .. e1 (ev5 data stall)
  40. cmpbge zero, t0, t2 # e0 : bits set iff byte == 0
  41. cmpbge zero, t1, t3 # .. e1 : bits set iff byte == c
  42. or t2, t3, t0 # e0 :
  43. beq t0, $loop # .. e1 (zdb)
  44. $found: negq t0, t1 # e0 : clear all but least set bit
  45. and t0, t1, t0 # e1 (stall)
  46. and t0, t3, t1 # e0 : bit set iff byte was the char
  47. beq t1, $retnull # .. e1 (zdb)
  48. and t0, 0xf0, t2 # e0 : binary search for that set bit
  49. and t0, 0xcc, t3 # .. e1 :
  50. and t0, 0xaa, t4 # e0 :
  51. cmovne t2, 4, t2 # .. e1 :
  52. cmovne t3, 2, t3 # e0 :
  53. cmovne t4, 1, t4 # .. e1 :
  54. addq t2, t3, t2 # e0 :
  55. addq v0, t4, v0 # .. e1 :
  56. addq v0, t2, v0 # e0 :
  57. ret # .. e1 :
  58. $retnull:
  59. mov zero, v0 # e0 :
  60. ret # .. e1 :
  61. .end strchr
  62. EXPORT_SYMBOL(strchr)