Browse Source

[crypto] Profile the various stages of modular multiplication

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 4 years ago
parent
commit
0cc12f053c
1 changed files with 29 additions and 0 deletions
  1. 29
    0
      src/crypto/bigint.c

+ 29
- 0
src/crypto/bigint.c View File

26
 #include <stdint.h>
26
 #include <stdint.h>
27
 #include <string.h>
27
 #include <string.h>
28
 #include <assert.h>
28
 #include <assert.h>
29
+#include <ipxe/profile.h>
29
 #include <ipxe/bigint.h>
30
 #include <ipxe/bigint.h>
30
 
31
 
31
 /** @file
32
 /** @file
33
  * Big integer support
34
  * Big integer support
34
  */
35
  */
35
 
36
 
37
+/** Modular multiplication overall profiler */
38
+static struct profiler bigint_mod_multiply_profiler __profiler =
39
+	{ .name = "bigint_mod_multiply" };
40
+
41
+/** Modular multiplication multiply step profiler */
42
+static struct profiler bigint_mod_multiply_multiply_profiler __profiler =
43
+	{ .name = "bigint_mod_multiply.multiply" };
44
+
45
+/** Modular multiplication rescale step profiler */
46
+static struct profiler bigint_mod_multiply_rescale_profiler __profiler =
47
+	{ .name = "bigint_mod_multiply.rescale" };
48
+
49
+/** Modular multiplication subtract step profiler */
50
+static struct profiler bigint_mod_multiply_subtract_profiler __profiler =
51
+	{ .name = "bigint_mod_multiply.subtract" };
52
+
36
 /**
53
 /**
37
  * Perform modular multiplication of big integers
54
  * Perform modular multiplication of big integers
38
  *
55
  *
63
 	int rotation;
80
 	int rotation;
64
 	int i;
81
 	int i;
65
 
82
 
83
+	/* Start profiling */
84
+	profile_start ( &bigint_mod_multiply_profiler );
85
+
66
 	/* Sanity check */
86
 	/* Sanity check */
67
 	assert ( sizeof ( *temp ) == bigint_mod_multiply_tmp_len ( modulus ) );
87
 	assert ( sizeof ( *temp ) == bigint_mod_multiply_tmp_len ( modulus ) );
68
 
88
 
69
 	/* Perform multiplication */
89
 	/* Perform multiplication */
90
+	profile_start ( &bigint_mod_multiply_multiply_profiler );
70
 	bigint_multiply ( multiplicand, multiplier, &temp->result );
91
 	bigint_multiply ( multiplicand, multiplier, &temp->result );
92
+	profile_stop ( &bigint_mod_multiply_multiply_profiler );
71
 
93
 
72
 	/* Rescale modulus to match result */
94
 	/* Rescale modulus to match result */
95
+	profile_start ( &bigint_mod_multiply_rescale_profiler );
73
 	bigint_grow ( modulus, &temp->modulus );
96
 	bigint_grow ( modulus, &temp->modulus );
74
 	rotation = ( bigint_max_set_bit ( &temp->result ) -
97
 	rotation = ( bigint_max_set_bit ( &temp->result ) -
75
 		     bigint_max_set_bit ( &temp->modulus ) );
98
 		     bigint_max_set_bit ( &temp->modulus ) );
76
 	for ( i = 0 ; i < rotation ; i++ )
99
 	for ( i = 0 ; i < rotation ; i++ )
77
 		bigint_rol ( &temp->modulus );
100
 		bigint_rol ( &temp->modulus );
101
+	profile_stop ( &bigint_mod_multiply_rescale_profiler );
78
 
102
 
79
 	/* Subtract multiples of modulus */
103
 	/* Subtract multiples of modulus */
104
+	profile_start ( &bigint_mod_multiply_subtract_profiler );
80
 	for ( i = 0 ; i <= rotation ; i++ ) {
105
 	for ( i = 0 ; i <= rotation ; i++ ) {
81
 		if ( bigint_is_geq ( &temp->result, &temp->modulus ) )
106
 		if ( bigint_is_geq ( &temp->result, &temp->modulus ) )
82
 			bigint_subtract ( &temp->modulus, &temp->result );
107
 			bigint_subtract ( &temp->modulus, &temp->result );
83
 		bigint_ror ( &temp->modulus );
108
 		bigint_ror ( &temp->modulus );
84
 	}
109
 	}
110
+	profile_stop ( &bigint_mod_multiply_subtract_profiler );
85
 
111
 
86
 	/* Resize result */
112
 	/* Resize result */
87
 	bigint_shrink ( &temp->result, result );
113
 	bigint_shrink ( &temp->result, result );
88
 
114
 
89
 	/* Sanity check */
115
 	/* Sanity check */
90
 	assert ( bigint_is_geq ( modulus, result ) );
116
 	assert ( bigint_is_geq ( modulus, result ) );
117
+
118
+	/* Stop profiling */
119
+	profile_stop ( &bigint_mod_multiply_profiler );
91
 }
120
 }
92
 
121
 
93
 /**
122
 /**

Loading…
Cancel
Save