Initialize static TLS for the benchmarks
[riscv-tests.git] / benchmarks / multiply / multiply_gendata.pl
1 #!/usr/bin/perl -w
2 #==========================================================================
3 # multiply_gendata.pl
4 #
5 # Author : Christopher Batten (cbatten@mit.edu)
6 # Date : May 9, 2005
7 #
8 (our $usageMsg = <<'ENDMSG') =~ s/^\#//gm;
9 #
10 # Simple script which creates an input data set and the reference data
11 # for the multiply benchmark.
12 #
13 ENDMSG
14
15 use strict "vars";
16 use warnings;
17 no warnings("once");
18 use Getopt::Long;
19
20 #--------------------------------------------------------------------------
21 # Command line processing
22 #--------------------------------------------------------------------------
23
24 our %opts;
25
26 sub usage()
27 {
28
29 print "\n";
30 print " Usage: multiply_gendata.pl [options] \n";
31 print "\n";
32 print " Options:\n";
33 print " --help print this message\n";
34 print " --size size of input data [750]\n";
35 print " --seed random seed [1]\n";
36 print "$usageMsg";
37
38 exit();
39 }
40
41 sub processCommandLine()
42 {
43
44 $opts{"help"} = 0;
45 $opts{"size"} = 750;
46 $opts{"seed"} = 1;
47 Getopt::Long::GetOptions( \%opts, 'help|?', 'size:i', 'seed:i' ) or usage();
48 $opts{"help"} and usage();
49
50 }
51
52 #--------------------------------------------------------------------------
53 # Helper Functions
54 #--------------------------------------------------------------------------
55
56 sub printArray
57 {
58 my $arrayName = $_[0];
59 my $arrayRef = $_[1];
60
61 my $numCols = 20;
62 my $arrayLen = scalar(@{$arrayRef});
63
64 print "int ".$arrayName."[DATA_SIZE] = \n";
65 print "{\n";
66
67 if ( $arrayLen <= $numCols ) {
68 print " ";
69 for ( my $i = 0; $i < $arrayLen; $i++ ) {
70 print sprintf("%3d",$arrayRef->[$i]);
71 if ( $i != $arrayLen-1 ) {
72 print ", ";
73 }
74 }
75 print "\n";
76 }
77
78 else {
79 my $numRows = int($arrayLen/$numCols);
80 for ( my $j = 0; $j < $numRows; $j++ ) {
81 print " ";
82 for ( my $i = 0; $i < $numCols; $i++ ) {
83 my $index = $j*$numCols + $i;
84 print sprintf("%3d",$arrayRef->[$index]);
85 if ( $index != $arrayLen-1 ) {
86 print ", ";
87 }
88 }
89 print "\n";
90 }
91
92 if ( $arrayLen > ($numRows*$numCols) ) {
93 print " ";
94 for ( my $i = 0; $i < ($arrayLen-($numRows*$numCols)); $i++ ) {
95 my $index = $numCols*$numRows + $i;
96 print sprintf("%3d",$arrayRef->[$index]);
97 if ( $index != $arrayLen-1 ) {
98 print ", ";
99 }
100 }
101 print "\n";
102 }
103
104 }
105
106 print "};\n\n";
107 }
108
109 #--------------------------------------------------------------------------
110 # Main
111 #--------------------------------------------------------------------------
112
113 sub main()
114 {
115
116 processCommandLine();
117 srand($opts{"seed"});
118
119 my @values1;
120 for ( my $i = 0; $i < $opts{"size"}; $i++ ) {
121 push( @values1, int(rand(999)) );
122 }
123
124 my @values2;
125 for ( my $i = 0; $i < $opts{"size"}; $i++ ) {
126 push( @values2, int(rand(999)) );
127 }
128
129 my @multiply;
130 for ( my $i = 0; $i < $opts{"size"}; $i++ ) {
131 $multiply[$i] = $values1[$i] * $values2[$i];
132 }
133
134 print "\n\#define DATA_SIZE ".$opts{"size"}." \n\n";
135 printArray( "input_data1", \@values1 );
136 printArray( "input_data2", \@values2 );
137 printArray( "verify_data", \@multiply );
138
139 }
140
141 main();
142