arm64cpuid.pl 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. # $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 OPENSSL_cleanse
  71. .type OPENSSL_cleanse,%function
  72. .align 5
  73. OPENSSL_cleanse:
  74. cbz x1,.Lret // len==0?
  75. cmp x1,#15
  76. b.hi .Lot // len>15
  77. nop
  78. .Little:
  79. strb wzr,[x0],#1 // store byte-by-byte
  80. subs x1,x1,#1
  81. b.ne .Little
  82. .Lret: ret
  83. .align 4
  84. .Lot: tst x0,#7
  85. b.eq .Laligned // inp is aligned
  86. strb wzr,[x0],#1 // store byte-by-byte
  87. sub x1,x1,#1
  88. b .Lot
  89. .align 4
  90. .Laligned:
  91. str xzr,[x0],#8 // store word-by-word
  92. sub x1,x1,#8
  93. tst x1,#-8
  94. b.ne .Laligned // len>=8
  95. cbnz x1,.Little // len!=0?
  96. ret
  97. .size OPENSSL_cleanse,.-OPENSSL_cleanse
  98. .globl CRYPTO_memcmp
  99. .type CRYPTO_memcmp,%function
  100. .align 4
  101. CRYPTO_memcmp:
  102. eor w3,w3,w3
  103. cbz x2,.Lno_data // len==0?
  104. cmp x2,#16
  105. b.ne .Loop_cmp
  106. ldp x8,x9,[x0]
  107. ldp x10,x11,[x1]
  108. eor x8,x8,x10
  109. eor x9,x9,x11
  110. orr x8,x8,x9
  111. mov x0,#1
  112. cmp x8,#0
  113. csel x0,xzr,x0,eq
  114. ret
  115. .align 4
  116. .Loop_cmp:
  117. ldrb w4,[x0],#1
  118. ldrb w5,[x1],#1
  119. eor w4,w4,w5
  120. orr w3,w3,w4
  121. subs x2,x2,#1
  122. b.ne .Loop_cmp
  123. .Lno_data:
  124. neg w0,w3
  125. lsr w0,w0,#31
  126. ret
  127. .size CRYPTO_memcmp,.-CRYPTO_memcmp
  128. ___
  129. print $code;
  130. close STDOUT or die "error closing STDOUT";