arm64cpuid.pl 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. #! /usr/bin/env perl
  2. # Copyright 2015-2018 The OpenSSL Project Authors. All Rights Reserved.
  3. #
  4. # Licensed under the Apache License 2.0 (the "License"). You may not use
  5. # this file except in compliance with the License. You can obtain a copy
  6. # in the file LICENSE in the source distribution or at
  7. # https://www.openssl.org/source/license.html
  8. $flavour = shift;
  9. $output = shift;
  10. $0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
  11. ( $xlate="${dir}arm-xlate.pl" and -f $xlate ) or
  12. ( $xlate="${dir}perlasm/arm-xlate.pl" and -f $xlate) or
  13. die "can't locate arm-xlate.pl";
  14. open OUT,"| \"$^X\" $xlate $flavour $output";
  15. *STDOUT=*OUT;
  16. $code.=<<___;
  17. #include "arm_arch.h"
  18. .text
  19. .arch armv8-a+crypto
  20. .align 5
  21. .globl _armv7_neon_probe
  22. .type _armv7_neon_probe,%function
  23. _armv7_neon_probe:
  24. orr v15.16b, v15.16b, v15.16b
  25. ret
  26. .size _armv7_neon_probe,.-_armv7_neon_probe
  27. .globl _armv7_tick
  28. .type _armv7_tick,%function
  29. _armv7_tick:
  30. #ifdef __APPLE__
  31. mrs x0, CNTPCT_EL0
  32. #else
  33. mrs x0, CNTVCT_EL0
  34. #endif
  35. ret
  36. .size _armv7_tick,.-_armv7_tick
  37. .globl _armv8_aes_probe
  38. .type _armv8_aes_probe,%function
  39. _armv8_aes_probe:
  40. aese v0.16b, v0.16b
  41. ret
  42. .size _armv8_aes_probe,.-_armv8_aes_probe
  43. .globl _armv8_sha1_probe
  44. .type _armv8_sha1_probe,%function
  45. _armv8_sha1_probe:
  46. sha1h s0, s0
  47. ret
  48. .size _armv8_sha1_probe,.-_armv8_sha1_probe
  49. .globl _armv8_sha256_probe
  50. .type _armv8_sha256_probe,%function
  51. _armv8_sha256_probe:
  52. sha256su0 v0.4s, v0.4s
  53. ret
  54. .size _armv8_sha256_probe,.-_armv8_sha256_probe
  55. .globl _armv8_pmull_probe
  56. .type _armv8_pmull_probe,%function
  57. _armv8_pmull_probe:
  58. pmull v0.1q, v0.1d, v0.1d
  59. ret
  60. .size _armv8_pmull_probe,.-_armv8_pmull_probe
  61. .globl _armv8_sha512_probe
  62. .type _armv8_sha512_probe,%function
  63. _armv8_sha512_probe:
  64. .long 0xcec08000 // sha512su0 v0.2d,v0.2d
  65. ret
  66. .size _armv8_sha512_probe,.-_armv8_sha512_probe
  67. .globl OPENSSL_cleanse
  68. .type OPENSSL_cleanse,%function
  69. .align 5
  70. OPENSSL_cleanse:
  71. cbz x1,.Lret // len==0?
  72. cmp x1,#15
  73. b.hi .Lot // len>15
  74. nop
  75. .Little:
  76. strb wzr,[x0],#1 // store byte-by-byte
  77. subs x1,x1,#1
  78. b.ne .Little
  79. .Lret: ret
  80. .align 4
  81. .Lot: tst x0,#7
  82. b.eq .Laligned // inp is aligned
  83. strb wzr,[x0],#1 // store byte-by-byte
  84. sub x1,x1,#1
  85. b .Lot
  86. .align 4
  87. .Laligned:
  88. str xzr,[x0],#8 // store word-by-word
  89. sub x1,x1,#8
  90. tst x1,#-8
  91. b.ne .Laligned // len>=8
  92. cbnz x1,.Little // len!=0?
  93. ret
  94. .size OPENSSL_cleanse,.-OPENSSL_cleanse
  95. .globl CRYPTO_memcmp
  96. .type CRYPTO_memcmp,%function
  97. .align 4
  98. CRYPTO_memcmp:
  99. eor w3,w3,w3
  100. cbz x2,.Lno_data // len==0?
  101. cmp x2,#16
  102. b.ne .Loop_cmp
  103. ldp x8,x9,[x0]
  104. ldp x10,x11,[x1]
  105. eor x8,x8,x10
  106. eor x9,x9,x11
  107. orr x8,x8,x9
  108. mov x0,#1
  109. cmp x8,#0
  110. csel x0,xzr,x0,eq
  111. ret
  112. .align 4
  113. .Loop_cmp:
  114. ldrb w4,[x0],#1
  115. ldrb w5,[x1],#1
  116. eor w4,w4,w5
  117. orr w3,w3,w4
  118. subs x2,x2,#1
  119. b.ne .Loop_cmp
  120. .Lno_data:
  121. neg w0,w3
  122. lsr w0,w0,#31
  123. ret
  124. .size CRYPTO_memcmp,.-CRYPTO_memcmp
  125. ___
  126. print $code;
  127. close STDOUT;