arm64cpuid.pl 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. #! /usr/bin/env perl
  2. # Copyright 2015-2020 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. # $output is the last argument if it looks like a file (it has an extension)
  9. # $flavour is the first argument if it doesn't look like a file
  10. $output = $#ARGV >= 0 && $ARGV[$#ARGV] =~ m|\.\w+$| ? pop : undef;
  11. $flavour = $#ARGV >= 0 && $ARGV[0] !~ m|\.| ? shift : undef;
  12. $0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
  13. ( $xlate="${dir}arm-xlate.pl" and -f $xlate ) or
  14. ( $xlate="${dir}perlasm/arm-xlate.pl" and -f $xlate) or
  15. die "can't locate arm-xlate.pl";
  16. open OUT,"| \"$^X\" $xlate $flavour \"$output\""
  17. or die "can't call $xlate: $!";
  18. *STDOUT=*OUT;
  19. $code.=<<___;
  20. #include "arm_arch.h"
  21. .text
  22. .arch armv8-a+crypto
  23. .align 5
  24. .globl _armv7_neon_probe
  25. .type _armv7_neon_probe,%function
  26. _armv7_neon_probe:
  27. orr v15.16b, v15.16b, v15.16b
  28. ret
  29. .size _armv7_neon_probe,.-_armv7_neon_probe
  30. .globl _armv7_tick
  31. .type _armv7_tick,%function
  32. _armv7_tick:
  33. #ifdef __APPLE__
  34. mrs x0, CNTPCT_EL0
  35. #else
  36. mrs x0, CNTVCT_EL0
  37. #endif
  38. ret
  39. .size _armv7_tick,.-_armv7_tick
  40. .globl _armv8_aes_probe
  41. .type _armv8_aes_probe,%function
  42. _armv8_aes_probe:
  43. aese v0.16b, v0.16b
  44. ret
  45. .size _armv8_aes_probe,.-_armv8_aes_probe
  46. .globl _armv8_sha1_probe
  47. .type _armv8_sha1_probe,%function
  48. _armv8_sha1_probe:
  49. sha1h s0, s0
  50. ret
  51. .size _armv8_sha1_probe,.-_armv8_sha1_probe
  52. .globl _armv8_sha256_probe
  53. .type _armv8_sha256_probe,%function
  54. _armv8_sha256_probe:
  55. sha256su0 v0.4s, v0.4s
  56. ret
  57. .size _armv8_sha256_probe,.-_armv8_sha256_probe
  58. .globl _armv8_pmull_probe
  59. .type _armv8_pmull_probe,%function
  60. _armv8_pmull_probe:
  61. pmull v0.1q, v0.1d, v0.1d
  62. ret
  63. .size _armv8_pmull_probe,.-_armv8_pmull_probe
  64. .globl _armv8_sha512_probe
  65. .type _armv8_sha512_probe,%function
  66. _armv8_sha512_probe:
  67. .long 0xcec08000 // sha512su0 v0.2d,v0.2d
  68. ret
  69. .size _armv8_sha512_probe,.-_armv8_sha512_probe
  70. .globl _armv8_cpuid_probe
  71. .type _armv8_cpuid_probe,%function
  72. _armv8_cpuid_probe:
  73. mrs x0, midr_el1
  74. ret
  75. .size _armv8_cpuid_probe,.-_armv8_cpuid_probe
  76. .globl OPENSSL_cleanse
  77. .type OPENSSL_cleanse,%function
  78. .align 5
  79. OPENSSL_cleanse:
  80. cbz x1,.Lret // len==0?
  81. cmp x1,#15
  82. b.hi .Lot // len>15
  83. nop
  84. .Little:
  85. strb wzr,[x0],#1 // store byte-by-byte
  86. subs x1,x1,#1
  87. b.ne .Little
  88. .Lret: ret
  89. .align 4
  90. .Lot: tst x0,#7
  91. b.eq .Laligned // inp is aligned
  92. strb wzr,[x0],#1 // store byte-by-byte
  93. sub x1,x1,#1
  94. b .Lot
  95. .align 4
  96. .Laligned:
  97. str xzr,[x0],#8 // store word-by-word
  98. sub x1,x1,#8
  99. tst x1,#-8
  100. b.ne .Laligned // len>=8
  101. cbnz x1,.Little // len!=0?
  102. ret
  103. .size OPENSSL_cleanse,.-OPENSSL_cleanse
  104. .globl CRYPTO_memcmp
  105. .type CRYPTO_memcmp,%function
  106. .align 4
  107. CRYPTO_memcmp:
  108. eor w3,w3,w3
  109. cbz x2,.Lno_data // len==0?
  110. cmp x2,#16
  111. b.ne .Loop_cmp
  112. ldp x8,x9,[x0]
  113. ldp x10,x11,[x1]
  114. eor x8,x8,x10
  115. eor x9,x9,x11
  116. orr x8,x8,x9
  117. mov x0,#1
  118. cmp x8,#0
  119. csel x0,xzr,x0,eq
  120. ret
  121. .align 4
  122. .Loop_cmp:
  123. ldrb w4,[x0],#1
  124. ldrb w5,[x1],#1
  125. eor w4,w4,w5
  126. orr w3,w3,w4
  127. subs x2,x2,#1
  128. b.ne .Loop_cmp
  129. .Lno_data:
  130. neg w0,w3
  131. lsr w0,w0,#31
  132. ret
  133. .size CRYPTO_memcmp,.-CRYPTO_memcmp
  134. ___
  135. print $code;
  136. close STDOUT or die "error closing STDOUT: $!";