ffs.S 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #include <linux/linkage.h>
  2. .register %g2,#scratch
  3. .text
  4. .align 32
  5. ENTRY(ffs)
  6. brnz,pt %o0, 1f
  7. mov 1, %o1
  8. retl
  9. clr %o0
  10. nop
  11. nop
  12. ENTRY(__ffs)
  13. sllx %o0, 32, %g1 /* 1 */
  14. srlx %o0, 32, %g2
  15. clr %o1 /* 2 */
  16. movrz %g1, %g2, %o0
  17. movrz %g1, 32, %o1 /* 3 */
  18. 1: clr %o2
  19. sllx %o0, (64 - 16), %g1 /* 4 */
  20. srlx %o0, 16, %g2
  21. movrz %g1, %g2, %o0 /* 5 */
  22. clr %o3
  23. movrz %g1, 16, %o2 /* 6 */
  24. clr %o4
  25. and %o0, 0xff, %g1 /* 7 */
  26. srlx %o0, 8, %g2
  27. movrz %g1, %g2, %o0 /* 8 */
  28. clr %o5
  29. movrz %g1, 8, %o3 /* 9 */
  30. add %o2, %o1, %o2
  31. and %o0, 0xf, %g1 /* 10 */
  32. srlx %o0, 4, %g2
  33. movrz %g1, %g2, %o0 /* 11 */
  34. add %o2, %o3, %o2
  35. movrz %g1, 4, %o4 /* 12 */
  36. and %o0, 0x3, %g1 /* 13 */
  37. srlx %o0, 2, %g2
  38. movrz %g1, %g2, %o0 /* 14 */
  39. add %o2, %o4, %o2
  40. movrz %g1, 2, %o5 /* 15 */
  41. and %o0, 0x1, %g1 /* 16 */
  42. add %o2, %o5, %o2 /* 17 */
  43. xor %g1, 0x1, %g1
  44. retl /* 18 */
  45. add %o2, %g1, %o0
  46. ENDPROC(ffs)
  47. ENDPROC(__ffs)
  48. .section .popc_6insn_patch, "ax"
  49. .word ffs
  50. brz,pn %o0, 98f
  51. neg %o0, %g1
  52. xnor %o0, %g1, %o1
  53. popc %o1, %o0
  54. 98: retl
  55. nop
  56. .word __ffs
  57. neg %o0, %g1
  58. xnor %o0, %g1, %o1
  59. popc %o1, %o0
  60. retl
  61. sub %o0, 1, %o0
  62. nop
  63. .previous