@@ -72,6 +72,38 @@ static inline void bc_fast_mul(bc_num n1, size_t n1len, bc_num n2, size_t n2len,
72
72
}
73
73
}
74
74
75
+ static inline void bc_standard_vector_mul (
76
+ BC_VECTOR * n1_vector , size_t n1_arr_size , BC_VECTOR * n2_vector , size_t n2_arr_size , BC_VECTOR * prod_vector , size_t prod_arr_size )
77
+ {
78
+ for (size_t i = 0 ; i < prod_arr_size ; i ++ ) {
79
+ prod_vector [i ] = 0 ;
80
+ }
81
+
82
+ /* Multiplication and addition */
83
+ size_t count = 0 ;
84
+ for (size_t i = 0 ; i < n1_arr_size ; i ++ ) {
85
+ /*
86
+ * This calculation adds the result multiple times to the array entries.
87
+ * When multiplying large numbers of digits, there is a possibility of
88
+ * overflow, so digit adjustment is performed beforehand.
89
+ */
90
+ if (UNEXPECTED (count >= BC_VECTOR_NO_OVERFLOW_ADD_COUNT )) {
91
+ bc_mul_carry_calc (prod_vector , prod_arr_size );
92
+ count = 0 ;
93
+ }
94
+ count ++ ;
95
+ for (size_t j = 0 ; j < n2_arr_size ; j ++ ) {
96
+ prod_vector [i + j ] += n1_vector [i ] * n2_vector [j ];
97
+ }
98
+ }
99
+
100
+ /*
101
+ * Move a value exceeding 4/8 digits by carrying to the next digit.
102
+ * However, the last digit does nothing.
103
+ */
104
+ bc_mul_carry_calc (prod_vector , prod_arr_size );
105
+ }
106
+
75
107
/*
76
108
* Converts the BCD of bc_num by 4 (32 bits) or 8 (64 bits) digits to an array of BC_VECTOR.
77
109
* The array is generated starting with the smaller digits.
@@ -82,7 +114,6 @@ static inline void bc_fast_mul(bc_num n1, size_t n1len, bc_num n2, size_t n2len,
82
114
*/
83
115
static void bc_standard_mul (bc_num n1 , size_t n1len , bc_num n2 , size_t n2len , bc_num * prod )
84
116
{
85
- size_t i ;
86
117
const char * n1end = n1 -> n_value + n1len - 1 ;
87
118
const char * n2end = n2 -> n_value + n2len - 1 ;
88
119
size_t prodlen = n1len + n2len ;
@@ -108,37 +139,12 @@ static void bc_standard_mul(bc_num n1, size_t n1len, bc_num n2, size_t n2len, bc
108
139
BC_VECTOR * n2_vector = n1_vector + n1_arr_size ;
109
140
BC_VECTOR * prod_vector = n2_vector + n2_arr_size ;
110
141
111
- for (i = 0 ; i < prod_arr_size ; i ++ ) {
112
- prod_vector [i ] = 0 ;
113
- }
114
-
115
142
/* Convert to BC_VECTOR[] */
116
143
bc_convert_to_vector (n1_vector , n1end , n1len );
117
144
bc_convert_to_vector (n2_vector , n2end , n2len );
118
145
119
- /* Multiplication and addition */
120
- size_t count = 0 ;
121
- for (i = 0 ; i < n1_arr_size ; i ++ ) {
122
- /*
123
- * This calculation adds the result multiple times to the array entries.
124
- * When multiplying large numbers of digits, there is a possibility of
125
- * overflow, so digit adjustment is performed beforehand.
126
- */
127
- if (UNEXPECTED (count >= BC_VECTOR_NO_OVERFLOW_ADD_COUNT )) {
128
- bc_mul_carry_calc (prod_vector , prod_arr_size );
129
- count = 0 ;
130
- }
131
- count ++ ;
132
- for (size_t j = 0 ; j < n2_arr_size ; j ++ ) {
133
- prod_vector [i + j ] += n1_vector [i ] * n2_vector [j ];
134
- }
135
- }
136
-
137
- /*
138
- * Move a value exceeding 4/8 digits by carrying to the next digit.
139
- * However, the last digit does nothing.
140
- */
141
- bc_mul_carry_calc (prod_vector , prod_arr_size );
146
+ /* Do multiply */
147
+ bc_standard_vector_mul (n1_vector , n1_arr_size , n2_vector , n2_arr_size , prod_vector , prod_arr_size );
142
148
143
149
/* Convert to bc_num */
144
150
* prod = bc_new_num_nonzeroed (prodlen , 0 );
0 commit comments