hweight_64.S 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. *
  4. * Copyright (C) IBM Corporation, 2010
  5. *
  6. * Author: Anton Blanchard <[email protected]>
  7. */
  8. #include <asm/processor.h>
  9. #include <asm/ppc_asm.h>
  10. #include <asm/export.h>
  11. #include <asm/feature-fixups.h>
  12. /* Note: This code relies on -mminimal-toc */
  13. _GLOBAL(__arch_hweight8)
  14. BEGIN_FTR_SECTION
  15. b __sw_hweight8
  16. nop
  17. nop
  18. FTR_SECTION_ELSE
  19. PPC_POPCNTB(R3,R3)
  20. clrldi r3,r3,64-8
  21. blr
  22. ALT_FTR_SECTION_END_IFCLR(CPU_FTR_POPCNTB)
  23. EXPORT_SYMBOL(__arch_hweight8)
  24. _GLOBAL(__arch_hweight16)
  25. BEGIN_FTR_SECTION
  26. b __sw_hweight16
  27. nop
  28. nop
  29. nop
  30. nop
  31. FTR_SECTION_ELSE
  32. BEGIN_FTR_SECTION_NESTED(50)
  33. PPC_POPCNTB(R3,R3)
  34. srdi r4,r3,8
  35. add r3,r4,r3
  36. clrldi r3,r3,64-8
  37. blr
  38. FTR_SECTION_ELSE_NESTED(50)
  39. clrlwi r3,r3,16
  40. PPC_POPCNTW(R3,R3)
  41. clrldi r3,r3,64-8
  42. blr
  43. ALT_FTR_SECTION_END_NESTED_IFCLR(CPU_FTR_POPCNTD, 50)
  44. ALT_FTR_SECTION_END_IFCLR(CPU_FTR_POPCNTB)
  45. EXPORT_SYMBOL(__arch_hweight16)
  46. _GLOBAL(__arch_hweight32)
  47. BEGIN_FTR_SECTION
  48. b __sw_hweight32
  49. nop
  50. nop
  51. nop
  52. nop
  53. nop
  54. nop
  55. FTR_SECTION_ELSE
  56. BEGIN_FTR_SECTION_NESTED(51)
  57. PPC_POPCNTB(R3,R3)
  58. srdi r4,r3,16
  59. add r3,r4,r3
  60. srdi r4,r3,8
  61. add r3,r4,r3
  62. clrldi r3,r3,64-8
  63. blr
  64. FTR_SECTION_ELSE_NESTED(51)
  65. PPC_POPCNTW(R3,R3)
  66. clrldi r3,r3,64-8
  67. blr
  68. ALT_FTR_SECTION_END_NESTED_IFCLR(CPU_FTR_POPCNTD, 51)
  69. ALT_FTR_SECTION_END_IFCLR(CPU_FTR_POPCNTB)
  70. EXPORT_SYMBOL(__arch_hweight32)
  71. _GLOBAL(__arch_hweight64)
  72. BEGIN_FTR_SECTION
  73. b __sw_hweight64
  74. nop
  75. nop
  76. nop
  77. nop
  78. nop
  79. nop
  80. nop
  81. nop
  82. FTR_SECTION_ELSE
  83. BEGIN_FTR_SECTION_NESTED(52)
  84. PPC_POPCNTB(R3,R3)
  85. srdi r4,r3,32
  86. add r3,r4,r3
  87. srdi r4,r3,16
  88. add r3,r4,r3
  89. srdi r4,r3,8
  90. add r3,r4,r3
  91. clrldi r3,r3,64-8
  92. blr
  93. FTR_SECTION_ELSE_NESTED(52)
  94. PPC_POPCNTD(R3,R3)
  95. clrldi r3,r3,64-8
  96. blr
  97. ALT_FTR_SECTION_END_NESTED_IFCLR(CPU_FTR_POPCNTD, 52)
  98. ALT_FTR_SECTION_END_IFCLR(CPU_FTR_POPCNTB)
  99. EXPORT_SYMBOL(__arch_hweight64)