inslist.pl 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #!/usr/bin/perl
  2. ## --------------------------------------------------------------------------
  3. ##
  4. ## Copyright 1996-2017 The NASM Authors - All Rights Reserved
  5. ## See the file AUTHORS included with the NASM distribution for
  6. ## the specific copyright holders.
  7. ##
  8. ## Redistribution and use in source and binary forms, with or without
  9. ## modification, are permitted provided that the following
  10. ## conditions are met:
  11. ##
  12. ## * Redistributions of source code must retain the above copyright
  13. ## notice, this list of conditions and the following disclaimer.
  14. ## * Redistributions in binary form must reproduce the above
  15. ## copyright notice, this list of conditions and the following
  16. ## disclaimer in the documentation and/or other materials provided
  17. ## with the distribution.
  18. ##
  19. ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  20. ## CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  21. ## INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  22. ## MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  23. ## DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  24. ## CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  25. ## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  26. ## NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  27. ## LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  28. ## HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  29. ## CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  30. ## OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  31. ## EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. ##
  33. ## --------------------------------------------------------------------------
  34. #
  35. # inslist.pl produce inslist.src
  36. #
  37. print STDERR "Reading insns.dat...\n";
  38. @args = ();
  39. undef $output;
  40. foreach $arg ( @ARGV ) {
  41. if ( $arg =~ /^\-/ ) {
  42. if ( $arg =~ /^\-([adins])$/ ) {
  43. $output = $1;
  44. } else {
  45. die "$0: Unknown option: ${arg}\n";
  46. }
  47. } else {
  48. push (@args, $arg);
  49. }
  50. }
  51. $fname = "../insns.dat" unless $fname = $args[0];
  52. open (F, '<', $fname) || die "unable to open $fname";
  53. print STDERR "Writing inslist.src...\n";
  54. open S, '>', 'inslist.src';
  55. $line = 0;
  56. $insns = 0;
  57. while (<F>) {
  58. $line++;
  59. next if (/^\s*$/); # blank lines
  60. if ( /^\s*;/ ) # comments
  61. {
  62. if ( /^\s*;\#\s*(.+)/ ) # section subheader
  63. {
  64. print S "\n\\S{} $1\n\n";
  65. }
  66. next;
  67. }
  68. chomp;
  69. unless (/^\s*(\S+)\s+(\S+)\s+(\S+|\[.*\])\s+(\S+)\s*$/) {
  70. warn "line $line does not contain four fields\n";
  71. next;
  72. }
  73. my @entry = ($1, $2, $3, $4);
  74. $entry[1] =~ s/ignore//;
  75. $entry[1] =~ s/void//;
  76. my @flags = split(/,/, $entry[3]);
  77. my @nflags;
  78. undef $isavx512;
  79. undef @avx512fl;
  80. for my $fl (@flags) {
  81. next if ($fl =~ /^(ignore|SB|SM|SM2|SQ|AR2|FUTURE)$/);
  82. if ($fl =~ /^AVX512(.*)$/) {
  83. $isavx512 = 1;
  84. push(@avx512fl, $1) unless ($1 eq '');
  85. } else {
  86. push(@nflags,$fl);
  87. }
  88. }
  89. if ($isavx512) {
  90. unshift(@nflags, "AVX512".join('/', @avx512fl));
  91. }
  92. printf S "\\c %-16s %-24s %s\n",$entry[0],$entry[1], join(',', @nflags);
  93. $insns++;
  94. }
  95. print S "\n";
  96. close S;
  97. close F;
  98. printf STDERR "Done: %d instructions\n", $insns;