File: tune.c

package info (click to toggle)
libzn-poly 0.9.2-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 904 kB
  • sloc: ansic: 10,736; python: 124; makefile: 12; sh: 6
file content (183 lines) | stat: -rw-r--r-- 5,767 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/*
   tune_main.c:  main() routine for tuning program
   
   Copyright (C) 2007, 2008, David Harvey
   
   This file is part of the zn_poly library (version 0.9).
   
   This program is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation, either version 2 of the License, or
   (at your option) version 3 of the License.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.

*/

#include <string.h>
#include "support.h"
#include "zn_poly_internal.h"
#include "profiler.h"


char* header = 
"/*\n"
"   NOTE: do not edit this file! It is auto-generated by the \"tune\" program.\n"
"   (Run \"make tune\" and then \"./tune > tuning.c\" to regenerate it.)\n"
"*/\n"
"\n"
"/*\n"
"   tuning.c:  global tuning values\n"
"\n"
"   Copyright (C) 2007, 2008, David Harvey\n"
"\n"
"   This file is part of the zn_poly library (version 0.9).\n"
"\n"
"   This program is free software: you can redistribute it and/or modify\n"
"   it under the terms of the GNU General Public License as published by\n"
"   the Free Software Foundation, either version 2 of the License, or\n"
"   (at your option) version 3 of the License.\n"
"\n"
"   This program is distributed in the hope that it will be useful,\n"
"   but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
"   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n"
"   GNU General Public License for more details.\n"
"\n"
"   You should have received a copy of the GNU General Public License\n"
"   along with this program.  If not, see <http://www.gnu.org/licenses/>.\n"
"\n"
"*/\n"
"\n"
"#include \"zn_poly_internal.h\"\n"
"\n";


char* footer =
"};\n"
"\n"
"// end of file ****************************************************************\n";


int
main (int argc, char* argv[])
{
   fprintf (stderr, "zn_poly tuning program\n");
   fprintf (stderr, "(use -v flag for verbose output)\n\n");

   gmp_randinit_default (randstate);

#if ZNP_HAVE_CYCLE_COUNTER

   calibrate_cycle_scale_factor ();

   int verbose = 0;

   if (argc == 2 && !strcmp (argv[1], "-v"))
      verbose = 1;

   // call various routines to generate tuning data
   tune_mpn_smp_kara (stderr, verbose);
   tune_mpn_mulmid_fallback (stderr, verbose);
   tune_mul_KS (stderr, 0, verbose);
   tune_mul_KS (stderr, 1, verbose);
   tune_mulmid_KS (stderr, verbose);
   tune_nuss (stderr, 0, verbose);
   tune_nuss (stderr, 1, verbose);
   tune_mul (stderr, 0, verbose);
   tune_mul (stderr, 1, verbose);
   tune_mulmid (stderr, verbose);

#else

   fprintf (stderr, "\n"
            "Warning: no cycle counting code available on this system,\n"
            "using default tuning values.\n\n");

#endif
   
   unsigned bits;
   size_t x;

   // generate tuning.c file
   printf ("%s", header);

   x = ZNP_mpn_smp_kara_thresh;
   printf ("size_t ZNP_mpn_smp_kara_thresh = ");
   printf (x == SIZE_MAX ? "SIZE_MAX;\n" : "%lu;\n", x);

   x = ZNP_mpn_mulmid_fallback_thresh;
   printf ("size_t ZNP_mpn_mulmid_fallback_thresh = ");
   printf (x == SIZE_MAX ? "SIZE_MAX;\n" : "%lu;\n", x);

   printf ("\n");

   printf ("tuning_info_t tuning_info[] = \n");
   printf ("{\n");
   printf ("   {  // bits = 0\n");
   printf ("   },\n");
   printf ("   {  // bits = 1\n");
   printf ("   },\n");
   
   for (bits = 2; bits <= ULONG_BITS; bits++)
   {
      printf ("   {  // bits = %u\n", bits);
      
      x = tuning_info[bits].mul_KS2_thresh;
      printf (x == SIZE_MAX ? "   SIZE_MAX," : "      %5lu,", x);
      printf ("   // KS1 -> KS2 multiplication threshold\n");

      x = tuning_info[bits].mul_KS4_thresh;
      printf (x == SIZE_MAX ? "   SIZE_MAX," : "      %5lu,", x);
      printf ("   // KS2 -> KS4 multiplication threshold\n");

      x = tuning_info[bits].mul_fft_thresh;
      printf (x == SIZE_MAX ? "   SIZE_MAX," : "      %5lu,", x);
      printf ("   // KS4 -> FFT multiplication threshold\n");
      
      x = tuning_info[bits].sqr_KS2_thresh;
      printf (x == SIZE_MAX ? "   SIZE_MAX," : "      %5lu,", x);
      printf ("   // KS1 -> KS2 squaring threshold\n");

      x = tuning_info[bits].sqr_KS4_thresh;
      printf (x == SIZE_MAX ? "   SIZE_MAX," : "      %5lu,", x);
      printf ("   // KS2 -> KS4 squaring threshold\n");

      x = tuning_info[bits].sqr_fft_thresh;
      printf (x == SIZE_MAX ? "   SIZE_MAX," : "      %5lu,", x);
      printf ("   // KS4 -> FFT squaring threshold\n");
      
      x = tuning_info[bits].mulmid_KS2_thresh;
      printf (x == SIZE_MAX ? "   SIZE_MAX," : "      %5lu,", x);
      printf ("   // KS1 -> KS2 middle product threshold\n");

      x = tuning_info[bits].mulmid_KS4_thresh;
      printf (x == SIZE_MAX ? "   SIZE_MAX," : "      %5lu,", x);
      printf ("   // KS2 -> KS4 middle product threshold\n");

      x = tuning_info[bits].mulmid_fft_thresh;
      printf (x == SIZE_MAX ? "   SIZE_MAX," : "      %5lu,", x);
      printf ("   // KS4 -> FFT middle product threshold\n");
      
      printf ("      %5lu,   // nussbaumer multiplication threshold\n",
              tuning_info[bits].nuss_mul_thresh);
      printf ("      %5lu    // nussbaumer squaring threshold\n",
              tuning_info[bits].nuss_sqr_thresh);

      printf ("   },\n");
   }
   
   printf ("%s", footer);
   
   gmp_randclear (randstate);
   
   return 0;
}


// end of file ****************************************************************