~ubuntu-branches/ubuntu/wily/libzn-poly/wily

« back to all changes in this revision

Viewing changes to mul_fft-profile.c

  • Committer: Bazaar Package Importer
  • Author(s): Tim Abbott
  • Date: 2008-05-27 20:23:43 UTC
  • Revision ID: james.westby@ubuntu.com-20080527202343-ufcb3fwj2as0edoz
Tags: upstream-0.8
ImportĀ upstreamĀ versionĀ 0.8

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
   mul_fft-profile.c:  profiling for mul_fft.c module
 
3
   
 
4
   Copyright (C) 2007, David Harvey
 
5
   
 
6
   This file is part of the zn_poly library (version 0.4.1).
 
7
   
 
8
   This program is free software: you can redistribute it and/or modify
 
9
   it under the terms of the GNU General Public License as published by
 
10
   the Free Software Foundation, either version 2 of the License, or
 
11
   (at your option) version 3 of the License.
 
12
 
 
13
   This program is distributed in the hope that it will be useful,
 
14
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
   GNU General Public License for more details.
 
17
 
 
18
   You should have received a copy of the GNU General Public License
 
19
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
20
 
 
21
*/
 
22
 
 
23
#include <math.h>
 
24
#include "support.h"
 
25
#include "zn_poly_internal.h"
 
26
#include "profiler.h"
 
27
 
 
28
 
 
29
/*
 
30
   Profiles the main mul_fft() routine.
 
31
 
 
32
   arg points to an array of ulongs.
 
33
   First ulong is poly length.
 
34
   Second is modulus n.
 
35
   
 
36
   Returns total cycle count for _count_ calls.
 
37
*/
 
38
double profile_mul_fft(void* arg, unsigned long count)
 
39
{
 
40
   size_t len = ((ulong*) arg)[0];
 
41
   ulong n = ((ulong*) arg)[1];
 
42
   
 
43
   zn_mod_t mod;
 
44
   zn_mod_init(mod, n);
 
45
   
 
46
   ulong* buf1 = (ulong*) malloc(sizeof(ulong) * len);
 
47
   ulong* buf2 = (ulong*) malloc(sizeof(ulong) * len);
 
48
   ulong* buf3 = (ulong*) malloc(sizeof(ulong) * 2 * len);
 
49
   
 
50
   size_t i;
 
51
   for (i = 0; i < len; i++)
 
52
      buf1[i] = random_ulong(n);
 
53
   for (i = 0; i < len; i++)
 
54
      buf2[i] = random_ulong(n);
 
55
 
 
56
   // warm up
 
57
   ulong j;
 
58
   for (j = 0; j < count; j++)
 
59
      zn_array_mul_fft(buf3, buf1, len, buf2, len, mod);
 
60
      
 
61
   cycle_count_t t0 = get_cycle_counter();
 
62
 
 
63
   for (j = 0; j < count; j++)
 
64
      zn_array_mul_fft(buf3, buf1, len, buf2, len, mod);
 
65
 
 
66
   cycle_count_t t1 = get_cycle_counter();
 
67
   
 
68
   free(buf3);
 
69
   free(buf2);
 
70
   free(buf1);
 
71
   
 
72
   zn_mod_clear(mod);
 
73
   
 
74
   return cycle_diff(t0, t1);
 
75
}
 
76
 
 
77
 
 
78
 
 
79
void prof_main(int argc, char* argv[])
 
80
{
 
81
   double result;
 
82
   unsigned long arg[2];
 
83
   unsigned bitsizes[9] = {4, 8, 16, 24, 32, 40, 48, 56, 64};
 
84
 
 
85
   int i, j;
 
86
   size_t len;
 
87
   unsigned bits;
 
88
 
 
89
   // loop over bitsizes in above table
 
90
   for (i = 0; i < sizeof(bitsizes) / sizeof(bitsizes[0]); i++)
 
91
   {
 
92
      bits = bitsizes[i];
 
93
 
 
94
      // loop over lengths, spaced out logarithmically
 
95
      for (j = 0; j < 120; j++)
 
96
      {
 
97
         size_t new_len = (size_t) floor(pow(1.1, (double) j));
 
98
         if (new_len == len)
 
99
            continue;
 
100
         len = new_len;
 
101
 
 
102
         arg[0] = len;
 
103
 
 
104
         // choose an odd modulus exactly _bits_ bits long, and not equal to
 
105
         // a power of two (so that the residues are _bits_ bits long too),
 
106
         ulong n = (1UL << (bits - 1))
 
107
                      + 2 * random_ulong((1UL << (bits - 2))) + 1;
 
108
         arg[1] = n;
 
109
 
 
110
         result = profile(profile_mul_fft, arg);
 
111
         
 
112
         printf("len = %5lu, bits = %2u, mul_fft = %.2le\n",
 
113
                len, bits, result);
 
114
      }
 
115
      printf("-------------------------------------------\n");
 
116
   }
 
117
}
 
118
 
 
119
// end of file ****************************************************************