00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00036 #if !defined(_TIFA_MESSAGES_H_)
00037
00041 #define _TIFA_MESSAGES_H_
00042
00043 #ifdef __cplusplus
00044 extern "C" {
00045 #endif
00046
00047 #include "timer.h"
00048 #include "tifa_config.h"
00049
00050
00051
00052
00053
00054 #if !defined(__VERBOSE__)
00055 #error "__VERBOSE__ must be defined before including this header."
00056 #endif
00057 #if !defined(__TIMING__)
00058 #error "__TIMING__ must be defined before including this header."
00059 #endif
00060 #if !defined(__PREFIX__)
00061 #error "__PREFIX__ must be defined before including this header."
00062 #endif
00063
00064 #if __VERBOSE__ || __TIMING__
00065 #include <stdio.h>
00066 #include "exit_codes.h"
00067 #endif
00068
00069 #define __EXTRA_TIMING__ TIFA_EXTRA_TIMING
00070
00071
00072
00073
00074 #define INIT_STRING "computing start up data..."
00075 #define UPDATE_STRING "updating context... "
00076 #define UPDATE_GIVEUP_STRING "updating context... give up"
00077 #define CLEAN_STRING "cleaning..."
00078 #define FUNC_SUCCEEDED_STRING "completed"
00079 #define FUNC_FAILED_STRING "failed"
00080
00081
00082
00083 #define COLLECT_RELS_STRING "collecting (X^2 = Y mod N) relations..."
00084 #define COLLECT_RELS_DONE_STRING "collection of (X^2 = Y mod N) relations"
00085 #define FACTOR_RES_STRING "factoring residues on the factor base..."
00086 #define LIN_ALG_STRING "solving linear algebra system..."
00087 #define DED_FACTORS_STRING "deducing factors..."
00088 #define UPDATE_MORE_RELS_STRING "updating context to find more relations... "
00089 #define UPDATE_NEW_MULT_STRING "updating context to change multiplier... "
00090
00091
00092
00093 #define FERMAT_FACT_STRING "performing Fermat's factorization..."
00094 #define FERMAT_FACT_DONE_STRING "Fermat's factorization..."
00095 #define UPDATE_MULTIPREC_STRING "updating context to use multi-precision..."
00096
00097
00098
00099 #define PERFORMING_ECM_STRING "performing elliptic curve factorization..."
00100 #define PERFORMING_P2_PRECOMP_STRING "performing phase 2 precomputations..."
00101 #define CHOOSED_CURVES_IN_STRING "choosing curves..."
00102 #define PHASE_1_IN_STRING "phase 1 (accumulated)..."
00103 #define PHASE_2_IN_STRING "phase 2 (accumulated)..."
00104 #define UPDATE_MORE_CURVES_STRING "updating context to try more curves... "
00105 #define UPDATE_LARGER_BOUNDS_STRING "updating context to use larger bounds... "
00106
00107
00108
00109 #define FWD_CYCL_STRING "forward cycling to find a proper form..."
00110 #define INV_SQRT_STRING "computing inverse square root of form..."
00111 #define REV_CYCL_STRING "reverse cycling to find a factor..."
00112 #define FR_REV_CYCL_STRING "reverse cycling to find a factor (fast ret)..."
00113 #define UPDATE_RACE_STRING "updating context to perform a race... "
00114
00115
00116
00117 #define NEXT_A_HACK_STRING "WARNING: running out of polynomials soon..."
00118
00119
00120
00121 #define DIVIDING_STRING_FORMAT "trial dividing by %lu primes..."
00122
00123
00124
00125
00126 #define TAB " "
00127 #define SEPARATION_LINE "-----------------------------------" \
00128 "------------------------------------"
00129
00130
00131
00132 #if __VERBOSE__ || __TIMING__
00133 #define PRINTF(...) printf(__VA_ARGS__); fflush(stdout)
00134 #define PRFX_PRINTF(...) printf(__PREFIX__ __VA_ARGS__); fflush(stdout)
00135 #else
00136 #define PRINTF(...)
00137 #define PRFX_PRINTF(...)
00138 #endif
00139
00140
00141
00142
00143 #define PRINT_LINE(STRING) PRFX_PRINTF("%s\n", STRING)
00144 #define PADDED_PRINTF(STRING) PRFX_PRINTF("%-47s", STRING)
00145
00146
00147
00148
00149
00150 #if !__TIMING__
00151 #define PRINT_MSG(STRING) PRINT_LINE(STRING)
00152 #else
00153 #define PRINT_MSG(STRING) PADDED_PRINTF(STRING)
00154 #endif
00155
00156 #if __VERBOSE__ || __TIMING__
00157 #define PRINT_SEPARATION_LINE PRINT_LINE(SEPARATION_LINE)
00158 #else
00159 #define PRINT_SEPARATION_LINE
00160 #endif
00161
00162
00163
00164
00165 #define PRINT_FAILURE_NL PRINTF("failure!\n")
00166 #define PRINT_INIT_MSG PRINT_MSG(INIT_STRING)
00167 #define PRINT_UPDATE_MSG PRINT_MSG(UPDATE_STRING)
00168 #define PRINT_UPDATE_GIVEUP_MSG PRINT_MSG(UPDATE_GIVEUP_STRING)
00169 #define PRINT_CLEAN_MSG PRINT_MSG(CLEAN_STRING)
00170
00171 #define PRINT_SUCCESS_MSG(ECODE) do { \
00172 char __tmp_str__[64]; \
00173 (void)sprintf(__tmp_str__, FUNC_SUCCEEDED_STRING " (%s)", \
00174 ecode_to_str[ECODE]); \
00175 PRINT_MSG(__tmp_str__); \
00176 } while (0)
00177
00178 #define PRINT_FAILURE_MSG(ECODE) do { \
00179 char __tmp_str__[64]; \
00180 (void)sprintf(__tmp_str__, FUNC_FAILED_STRING " (%s)", \
00181 ecode_to_str[ECODE]); \
00182 PRINT_MSG(__tmp_str__); \
00183 } while (0)
00184
00185 #if __VERBOSE__ || __TIMING__
00186
00187
00188
00189 #define PRINT_INTRO_MSG(NAME) \
00190 do { \
00191 PRINTF(__PREFIX__ "attempting %s factorization\n", NAME); \
00192 PRINT_SEPARATION_LINE; \
00193 } while (0)
00194
00195
00196
00197 #define PRINT_STATUS(SUCCESS, ECODE) \
00198 do { \
00199 PRINT_SEPARATION_LINE; \
00200 if (SUCCESS) { \
00201 PRINT_SUCCESS_MSG(ECODE); \
00202 } else { \
00203 PRINT_FAILURE_MSG(ECODE); \
00204 } \
00205 PRINT_TOTAL; \
00206 } while (0)
00207 #else
00208 #define PRINT_STATUS(SUCCESS, ECODE_STR)
00209 #define PRINT_INTRO_MSG(NAME)
00210 #endif
00211
00212
00213
00214 #define PRINT_UPDATE_MORE_RELS_MSG PRINT_MSG(UPDATE_MORE_RELS_STRING)
00215 #define PRINT_UPDATE_NEW_MULT_MSG PRINT_MSG(UPDATE_NEW_MULT_STRING)
00216
00217 #define PRINT_FACTOR_RES_MSG PRINT_MSG(FACTOR_RES_STRING)
00218 #define PRINT_LIN_ALG_MSG PRINT_MSG(LIN_ALG_STRING)
00219 #define PRINT_DED_FACTORS_MSG PRINT_MSG(DED_FACTORS_STRING)
00220
00221 #if __VERBOSE__
00222 #define PRINT_COLLECT_RELS_MSG PRINT_LINE(COLLECT_RELS_STRING)
00223 #else
00224 #define PRINT_COLLECT_RELS_MSG PADDED_PRINTF(COLLECT_RELS_STRING)
00225 #endif
00226
00227 #if (__VERBOSE__ && __TIMING__) || (__TIMING__ && __EXTRA_TIMING__)
00228 #define PRINT_COLLECT_RELS_DONE_MSG PRINT_MSG(COLLECT_RELS_DONE_STRING)
00229 #else
00230 #define PRINT_COLLECT_RELS_DONE_MSG
00231 #endif
00232
00233 #if __VERBOSE__
00234 #define PRINT_NRELS_FOUND(FOUND, TO_FIND) \
00235 PRFX_PRINTF(TAB TAB "(%"PRIu32"/%"PRIu32") relations found\n", \
00236 FOUND, TO_FIND);
00237 #else
00238 #define PRINT_NRELS_FOUND(FOUND, TO_FIND)
00239 #endif
00240
00241 #if __VERBOSE__ && __TIMING__
00242 #define PRINT_RES_GENERATED_MSG(TIMING) \
00243 PRFX_PRINTF(TAB "(relations generated in "TIMING_FORMAT" seconds)\n", \
00244 TIMING);
00245 #define PRINT_RES_SELECTED_MSG(TIMING) \
00246 PRFX_PRINTF(TAB "(relations selected in "TIMING_FORMAT" seconds)\n", \
00247 TIMING);
00248 #else
00249 #define PRINT_RES_GENERATED_MSG(TIMING)
00250 #define PRINT_RES_SELECTED_MSG(TIMING)
00251 #endif
00252
00253
00254
00255
00256 #define PRINT_UPDATE_MULTIPREC_MSG PRINT_MSG(UPDATE_MULTIPREC_STRING)
00257
00258 #if __VERBOSE__
00259 #define PRINT_FERMAT_FACT_MSG PRINT_LINE(FERMAT_FACT_STRING)
00260 #else
00261 #define PRINT_FERMAT_FACT_MSG PADDED_PRINTF(FERMAT_FACT_STRING)
00262 #endif
00263
00264 #if __VERBOSE__ && __TIMING__
00265 #define PRINT_FERMAT_FACT_DONE_MSG PRINT_MSG(FERMAT_FACT_DONE_STRING)
00266 #define PRINT_NEXTPRIME_MSG(TIMING) \
00267 PRFX_PRINTF(TAB "primes computed in "TIMING_FORMAT" seconds\n", \
00268 TIMING);
00269 #define PRINT_SQRTM_MSG(TIMING) \
00270 PRFX_PRINTF(TAB "sqrtm computed in "TIMING_FORMAT" seconds\n", \
00271 TIMING);
00272 #define PRINT_GREEDY_MSG(TIMING) \
00273 PRFX_PRINTF(TAB "greedy phase done in "TIMING_FORMAT" seconds\n", \
00274 TIMING);
00275 #else
00276 #define PRINT_NEXTPRIME_MSG(TIMING)
00277 #define PRINT_SQRTM_MSG(TIMING)
00278 #define PRINT_GREEDY_MSG(TIMING)
00279 #define PRINT_FERMAT_FACT_DONE_MSG
00280 #endif
00281
00282
00283
00284
00285 #define PRINT_PERFORMING_ECM PRINT_MSG(PERFORMING_ECM_STRING)
00286 #define PRINT_PERFORMING_P2_PRECOMP PRINT_MSG(PERFORMING_P2_PRECOMP_STRING)
00287 #if __TIMING__
00288 #define PRINT_CHOOSED_CURVES_IN PRINT_MSG(CHOOSED_CURVES_IN_STRING)
00289 #define PRINT_PHASE_1_IN PRINT_MSG(PHASE_1_IN_STRING)
00290 #define PRINT_PHASE_2_IN PRINT_MSG(PHASE_2_IN_STRING)
00291 #else
00292 #define PRINT_CHOOSED_CURVES_IN
00293 #define PRINT_PHASE_1_IN
00294 #define PRINT_PHASE_2_IN
00295 #endif
00296
00297 #define PRINT_NCURVES_USED(NCURVES) \
00298 PRFX_PRINTF("used %"PRIu32" curve(s)\n", (uint32_t)NCURVES)
00299
00300 #define PRINT_UPDATE_MORE_CURVES_MSG PRINT_MSG(UPDATE_MORE_CURVES_STRING)
00301 #define PRINT_UPDATE_LARGER_BOUNDS_MSG PRINT_MSG(UPDATE_LARGER_BOUNDS_STRING)
00302
00303
00304
00305 #define PRINT_UPDATE_RACE_MSG PRINT_MSG(UPDATE_RACE_STRING)
00306 #define PRINT_FWD_CYCL_MSG PRINT_MSG(FWD_CYCL_STRING)
00307 #define PRINT_INV_SQRT_MSG PRINT_MSG(INV_SQRT_STRING)
00308 #define PRINT_REV_CYCL_MSG PRINT_MSG(REV_CYCL_STRING)
00309 #define PRINT_FR_REV_CYCL_MSG PRINT_MSG(FR_REV_CYCL_STRING)
00310
00311
00312
00313 #if __EXTRA_TIMING__
00314 #if __VERBOSE__
00315 #define PRINT_FILL_TIMING_MSG \
00316 printf(__PREFIX__ " Fill sieve: done in %7.4f seconds\n", \
00317 GET_EXTRA_TIMING(fill));
00318 #else
00319 #define PRINT_FILL_TIMING_MSG \
00320 printf("\n" __PREFIX__ \
00321 " Fill sieve: done in %7.4f seconds\n", \
00322 GET_EXTRA_TIMING(fill));
00323 #endif
00324
00325 #define PRINT_SCAN_TIMING_MSG \
00326 printf(__PREFIX__ " Scan sieve: done in %7.4f seconds\n", \
00327 GET_EXTRA_TIMING(scan));
00328
00329 #define PRINT_INIT_POLY_TIMING_MSG \
00330 printf(__PREFIX__ " Init poly: done in %7.4f seconds\n", \
00331 GET_EXTRA_TIMING(init_poly));
00332 #else
00333 #define PRINT_FILL_TIMING_MSG
00334 #define PRINT_SCAN_TIMING_MSG
00335 #define PRINT_INIT_POLY_TIMING_MSG
00336 #define PRINT_BATCH_TIMING_MSG
00337 #endif
00338
00339
00340
00341
00342 #if __TIMING__ || __VERBOSE__
00343 #define PRINT_DIVIDING_MSG(X) \
00344 do { \
00345 char __tmp_str__[64]; \
00346 (void)sprintf(__tmp_str__, DIVIDING_STRING_FORMAT, \
00347 (unsigned long int)X); \
00348 PRINT_MSG(__tmp_str__); \
00349 } while (0)
00350 #else
00351 #define PRINT_DIVIDING_MSG(X)
00352 #endif
00353
00354
00355
00356 #if __TIMING__
00357 #define PRINT_NAMED_TIMING(NAME) \
00358 PRINTF("done in " TIMING_FORMAT " seconds\n", \
00359 GET_NAMED_TIMING(NAME));
00360 #define PRINT_NAMED_TOTAL(NAME) \
00361 PRINTF("total " TIMING_FORMAT " seconds\n", \
00362 GET_NAMED_TIMING(NAME));
00363 #else
00364 #define PRINT_NAMED_TIMING(NAME)
00365 #define PRINT_NAMED_TOTAL(NAME)
00366 #endif
00367 #define PRINT_TIMING PRINT_NAMED_TIMING()
00368 #define PRINT_TOTAL PRINT_NAMED_TOTAL()
00369
00370 #ifdef __cplusplus
00371 }
00372 #endif
00373
00374 #endif