phash.ph: yet another attempt at getting Perl to behave, arithmetically
[nasm/avx512.git] / perllib / gensv.pl
blob2790b0ea218be815670bab230844f02a02b38941
1 #!/usr/bin/perl
3 # Generate a list of rotation vectors so we always use the same set.
4 # This needs to be run on a platform with /dev/urandom.
7 ($n) = @ARGV;
9 sysopen(UR, '/dev/urandom', O_RDONLY) or die;
11 $maxlen = 78;
13 print "\@random_sv_vectors = (\n";
14 $outl = ' ';
16 for ($i = 0; $i < $n; $i++) {
18 do {
19 die if (sysread(UR, $x4, 4) != 4);
20 @n = unpack("C*", $x4);
22 $n[0] &= 31;
23 $n[1] &= 31;
24 $n[2] &= 31;
25 $n[3] &= 31;
26 } while ($n[0] == 0 || $n[1] == 0 || $n[2] == 0 || $n[3] == 0 ||
27 $n[0] == $n[3] || $n[1] == $n[2]);
29 $xl = sprintf(" [%d,%d,%d,%d]%s",
30 $n[0], $n[1], $n[2], $n[3],
31 ($i == $n-1) ? '' : ',');
32 if (length($outl.$xl) > $maxlen) {
33 print $outl, "\n";
34 $outl = ' ';
36 $outl .= $xl;
38 close(UR);
40 print $outl, "\n";
41 print ");\n";
42 print "1;\n";