crc32.S 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * Accelerated CRC32(C) using AArch64 CRC instructions
  3. *
  4. * Copyright (C) 2016 - 2018 Linaro Ltd <ard.biesheuvel@linaro.org>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. */
  10. #include <linux/linkage.h>
  11. #include <asm/alternative.h>
  12. #include <asm/assembler.h>
  13. .cpu generic+crc
  14. .macro __crc32, c
  15. 0: subs x2, x2, #16
  16. b.mi 8f
  17. ldp x3, x4, [x1], #16
  18. CPU_BE( rev x3, x3 )
  19. CPU_BE( rev x4, x4 )
  20. crc32\c\()x w0, w0, x3
  21. crc32\c\()x w0, w0, x4
  22. b.ne 0b
  23. ret
  24. 8: tbz x2, #3, 4f
  25. ldr x3, [x1], #8
  26. CPU_BE( rev x3, x3 )
  27. crc32\c\()x w0, w0, x3
  28. 4: tbz x2, #2, 2f
  29. ldr w3, [x1], #4
  30. CPU_BE( rev w3, w3 )
  31. crc32\c\()w w0, w0, w3
  32. 2: tbz x2, #1, 1f
  33. ldrh w3, [x1], #2
  34. CPU_BE( rev16 w3, w3 )
  35. crc32\c\()h w0, w0, w3
  36. 1: tbz x2, #0, 0f
  37. ldrb w3, [x1]
  38. crc32\c\()b w0, w0, w3
  39. 0: ret
  40. .endm
  41. .align 5
  42. ENTRY(crc32_le)
  43. alternative_if_not ARM64_HAS_CRC32
  44. b crc32_le_base
  45. alternative_else_nop_endif
  46. __crc32
  47. ENDPROC(crc32_le)
  48. .align 5
  49. ENTRY(__crc32c_le)
  50. alternative_if_not ARM64_HAS_CRC32
  51. b __crc32c_le_base
  52. alternative_else_nop_endif
  53. __crc32 c
  54. ENDPROC(__crc32c_le)