2
0

loongarch64cpuid.pl 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #! /usr/bin/env perl
  2. # Copyright 2022 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. ($zero,$ra,$tp,$sp)=map("\$r$_",(0..3));
  11. ($a0,$a1,$a2,$a3,$a4,$a5,$a6,$a7)=map("\$r$_",(4..11));
  12. ($t0,$t1,$t2,$t3,$t4,$t5,$t6,$t7,$t8,$t9)=map("\$r$_",(12..21));
  13. ($s0,$s1,$s2,$s3,$s4,$s5,$s6,$s7)=map("\$r$_",(23..30));
  14. ($vr0,$vr1,$vr2,$vr3,$vr4,$vr5,$vr6,$vr7,$vr8,$vr9,$vr10,$vr11,$vr12,$vr13,$vr14,$vr15,$vr16,$vr17,$vr18,$vr19)=map("\$vr$_",(0..19));
  15. ($fp)=map("\$r$_",(22));
  16. for (@ARGV) { $output=$_ if (/\w[\w\-]*\.\w+$/); }
  17. open STDOUT,">$output";
  18. while (($output=shift) && ($output!~/\w[\w\-]*\.\w+$/)) {}
  19. open STDOUT,">$output";
  20. {
  21. my ($in_a,$in_b,$len,$m,$temp1,$temp2) = ($a0,$a1,$a2,$t0,$t1,$t2);
  22. $code.=<<___;
  23. ################################################################################
  24. # int CRYPTO_memcmp(const void * in_a, const void * in_b, size_t len)
  25. ################################################################################
  26. .text
  27. .balign 16
  28. .globl CRYPTO_memcmp
  29. .type CRYPTO_memcmp,\@function
  30. CRYPTO_memcmp:
  31. li.d $m,0
  32. beqz $len,2f # len == 0
  33. 1:
  34. ld.bu $temp1,$in_a,0
  35. ld.bu $temp2,$in_b,0
  36. addi.d $in_a,$in_a,1
  37. addi.d $in_b,$in_b,1
  38. addi.d $len,$len,-1
  39. xor $temp1,$temp1,$temp2
  40. or $m,$m,$temp1
  41. blt $zero,$len,1b
  42. 2:
  43. move $a0,$m
  44. jr $ra
  45. ___
  46. }
  47. {
  48. my ($ptr,$len,$temp1,$temp2) = ($a0,$a1,$t0,$t1);
  49. $code.=<<___;
  50. ################################################################################
  51. # void OPENSSL_cleanse(void *ptr, size_t len)
  52. ################################################################################
  53. .text
  54. .balign 16
  55. .globl OPENSSL_cleanse
  56. .type OPENSSL_cleanse,\@function
  57. OPENSSL_cleanse:
  58. beqz $len,2f # len == 0, return
  59. srli.d $temp1,$len,4
  60. bnez $temp1,3f # len > 15
  61. 1: # Store <= 15 individual bytes
  62. st.b $zero,$ptr,0
  63. addi.d $ptr,$ptr,1
  64. addi.d $len,$len,-1
  65. bnez $len,1b
  66. 2:
  67. jr $ra
  68. 3: # Store individual bytes until we are aligned
  69. andi $temp1,$ptr,0x7
  70. beqz $temp1,4f
  71. st.b $zero,$ptr,0
  72. addi.d $ptr,$ptr,1
  73. addi.d $len,$len,-1
  74. b 3b
  75. 4: # Store aligned dwords
  76. li.d $temp2,8
  77. 4:
  78. st.d $zero,$ptr,0
  79. addi.d $ptr,$ptr,8
  80. addi.d $len,$len,-8
  81. bge $len,$temp2,4b # if len>=8 loop
  82. bnez $len,1b # if len<8 and len != 0, store remaining bytes
  83. jr $ra
  84. ___
  85. }
  86. {
  87. $code.=<<___;
  88. ################################################################################
  89. # uint32_t OPENSSL_rdtsc(void)
  90. ################################################################################
  91. .text
  92. .balign 16
  93. .globl OPENSSL_rdtsc
  94. .type OPENSSL_rdtsc,\@function
  95. OPENSSL_rdtsc:
  96. move $a0,$zero
  97. jr $ra
  98. ___
  99. }
  100. $code =~ s/\`([^\`]*)\`/eval($1)/gem;
  101. print $code;
  102. close STDOUT or die "error closing STDOUT: $!";