From be47aebc2435cf7a95a39e48e0c42f3a2c3b5613 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Fri, 26 Aug 2016 20:38:45 -0700 Subject: [PATCH] Avoid float to double promotions --- include/shared.h | 2 +- src/hashcat.c | 44 ++++++++++++++++++++++---------------------- src/shared.c | 6 +++--- 3 files changed, 26 insertions(+), 26 deletions(-) diff --git a/include/shared.h b/include/shared.h index aab622e0f..2bf830364 100644 --- a/include/shared.h +++ b/include/shared.h @@ -1413,7 +1413,7 @@ u64 mydivc64 (const u64 dividend, const u64 divisor); void ascii_digest (char *out_buf, uint salt_pos, uint digest_pos); void to_hccap_t (hccap_t *hccap, uint salt_pos, uint digest_pos); -void format_speed_display (float val, char *buf, size_t len); +void format_speed_display (double val, char *buf, size_t len); void format_timer_display (struct tm *tm, char *buf, size_t len); void lowercase (u8 *buf, int len); void uppercase (u8 *buf, int len); diff --git a/src/hashcat.c b/src/hashcat.c index 75e26ba44..9e0bb741a 100644 --- a/src/hashcat.c +++ b/src/hashcat.c @@ -1032,7 +1032,7 @@ void status_display () if (data.maskcnt > 1) { - float mask_percentage = (float) data.maskpos / (float) data.maskcnt; + double mask_percentage = (double) data.maskpos / (double) data.maskcnt; tmp_len += snprintf (tmp_buf + tmp_len, sizeof (tmp_buf) - tmp_len, " (%.02f%%)", mask_percentage * 100); } @@ -1525,8 +1525,8 @@ void status_display () if (data.devices_active > 1) log_info ("Speed.Dev.#*...: %9sH/s", display_all_cur); - const float digests_percent = (float) data.digests_done / data.digests_cnt; - const float salts_percent = (float) data.salts_done / data.salts_cnt; + const double digests_percent = (double) data.digests_done / data.digests_cnt; + const double salts_percent = (double) data.salts_done / data.salts_cnt; log_info ("Recovered......: %u/%u (%.2f%%) Digests, %u/%u (%.2f%%) Salts", data.digests_done, data.digests_cnt, digests_percent * 100, data.salts_done, data.salts_cnt, salts_percent * 100); @@ -1563,9 +1563,9 @@ void status_display () double ms_real = ms_running - ms_paused; - float cpt_avg_min = (float) data.cpt_total / ((ms_real / 1000) / 60); - float cpt_avg_hour = (float) data.cpt_total / ((ms_real / 1000) / 3600); - float cpt_avg_day = (float) data.cpt_total / ((ms_real / 1000) / 86400); + double cpt_avg_min = (double) data.cpt_total / ((ms_real / 1000) / 60); + double cpt_avg_hour = (double) data.cpt_total / ((ms_real / 1000) / 3600); + double cpt_avg_day = (double) data.cpt_total / ((ms_real / 1000) / 86400); if ((data.cpt_start + 86400) < now) { @@ -1609,20 +1609,20 @@ void status_display () u64 restore_total = data.words_base; - float percent_restore = 0; + double percent_restore = 0; - if (restore_total != 0) percent_restore = (float) restore_point / (float) restore_total; + if (restore_total != 0) percent_restore = (double) restore_point / (double) restore_total; if (progress_end_relative_skip) { if ((data.wordlist_mode == WL_MODE_FILE) || (data.wordlist_mode == WL_MODE_MASK)) { - float percent_finished = (float) progress_cur_relative_skip / (float) progress_end_relative_skip; - float percent_rejected = 0.0; + double percent_finished = (double) progress_cur_relative_skip / (double) progress_end_relative_skip; + double percent_rejected = 0.0; if (progress_cur) { - percent_rejected = (float) (all_rejected) / (float) progress_cur; + percent_rejected = (double) (all_rejected) / (double) progress_cur; } log_info ("Progress.......: %llu/%llu (%.02f%%)", (unsigned long long int) progress_cur_relative_skip, (unsigned long long int) progress_end_relative_skip, percent_finished * 100); @@ -1641,12 +1641,12 @@ void status_display () { if ((data.wordlist_mode == WL_MODE_FILE) || (data.wordlist_mode == WL_MODE_MASK)) { - log_info ("Progress.......: %llu/%llu (%.02f%%)", (u64) 0, (u64) 0, (float) 100); - log_info ("Rejected.......: %llu/%llu (%.02f%%)", (u64) 0, (u64) 0, (float) 100); + log_info ("Progress.......: %llu/%llu (%.02f%%)", 0ull, 0ull, 100); + log_info ("Rejected.......: %llu/%llu (%.02f%%)", 0ull, 0ull, 100); if (data.restore_disable == 0) { - log_info ("Restore.Point..: %llu/%llu (%.02f%%)", (u64) 0, (u64) 0, (float) 100); + log_info ("Restore.Point..: %llu/%llu (%.02f%%)", 0ull, 0ull, 100); } } else @@ -4517,7 +4517,7 @@ static u64 count_words (wl_data_t *wl_data, FILE *fd, char *dictfile, dictstat_t if ((now - prev) == 0) continue; - float percent = (float) comp / (float) d.stat.st_size; + double percent = (double) comp / (double) d.stat.st_size; if (data.quiet == 0) log_info_nn ("Generating dictionary stats for %s: %llu bytes (%.2f%%), %llu words, %llu keyspace", dictfile, (unsigned long long int) comp, percent * 100, (unsigned long long int) cnt2, (unsigned long long int) cnt); @@ -4720,8 +4720,8 @@ static void *thread_monitor (void *p) last_temp_check_time = temp_check_time; - float Kp = 1.8; - float Ki = 0.005; + float Kp = 1.8f; + float Ki = 0.005f; float Kd = 6; // PID controller (3-term controller: proportional - Kp, integral - Ki, derivative - Kd) @@ -12848,7 +12848,7 @@ int main (int argc, char **argv) hash_t *lm_hash_right = &hashes_buf[hashes_cnt]; - if (data.quiet == 0) if ((hashes_cnt % 0x20000) == 0) log_info_nn ("Parsed Hashes: %u/%u (%0.2f%%)", hashes_cnt, hashes_avail, ((float) hashes_cnt / hashes_avail) * 100); + if (data.quiet == 0) if ((hashes_cnt % 0x20000) == 0) log_info_nn ("Parsed Hashes: %u/%u (%0.2f%%)", hashes_cnt, hashes_avail, ((double) hashes_cnt / hashes_avail) * 100); hashes_cnt++; @@ -12868,7 +12868,7 @@ int main (int argc, char **argv) continue; } - if (data.quiet == 0) if ((hashes_cnt % 0x20000) == 0) log_info_nn ("Parsed Hashes: %u/%u (%0.2f%%)", hashes_cnt, hashes_avail, ((float) hashes_cnt / hashes_avail) * 100); + if (data.quiet == 0) if ((hashes_cnt % 0x20000) == 0) log_info_nn ("Parsed Hashes: %u/%u (%0.2f%%)", hashes_cnt, hashes_avail, ((double) hashes_cnt / hashes_avail) * 100); if (show == 1) handle_show_request (pot, pot_cnt, line_buf, line_len, &hashes_buf[hashes_cnt], sort_by_pot, out_fp); if (left == 1) handle_left_request (pot, pot_cnt, line_buf, line_len, &hashes_buf[hashes_cnt], sort_by_pot, out_fp); @@ -12887,7 +12887,7 @@ int main (int argc, char **argv) continue; } - if (data.quiet == 0) if ((hashes_cnt % 0x20000) == 0) log_info_nn ("Parsed Hashes: %u/%u (%0.2f%%)", hashes_cnt, hashes_avail, ((float) hashes_cnt / hashes_avail) * 100); + if (data.quiet == 0) if ((hashes_cnt % 0x20000) == 0) log_info_nn ("Parsed Hashes: %u/%u (%0.2f%%)", hashes_cnt, hashes_avail, ((double) hashes_cnt / hashes_avail) * 100); if (show == 1) handle_show_request (pot, pot_cnt, line_buf, line_len, &hashes_buf[hashes_cnt], sort_by_pot, out_fp); if (left == 1) handle_left_request (pot, pot_cnt, line_buf, line_len, &hashes_buf[hashes_cnt], sort_by_pot, out_fp); @@ -15691,8 +15691,8 @@ int main (int argc, char **argv) int engine_clock_max = caps.sEngineClockRange.iMax * 0.6666; int memory_clock_max = caps.sMemoryClockRange.iMax * 0.6250; - int warning_trigger_engine = (int) (0.25 * (float) engine_clock_max); - int warning_trigger_memory = (int) (0.25 * (float) memory_clock_max); + int warning_trigger_engine = (int) (0.25 * (double) engine_clock_max); + int warning_trigger_memory = (int) (0.25 * (double) memory_clock_max); int engine_clock_profile_max = od_clock_mem_status[device_id].state.aLevels[1].iEngineClock; int memory_clock_profile_max = od_clock_mem_status[device_id].state.aLevels[1].iMemoryClock; diff --git a/src/shared.c b/src/shared.c index f52d76251..eb5ca3acb 100644 --- a/src/shared.c +++ b/src/shared.c @@ -473,7 +473,7 @@ int base32_encode (u8 (*f) (const u8), const u8 *in_buf, int in_len, u8 *out_buf out_ptr += 8; } - int out_len = (int) (((0.5 + (float) in_len) * 8) / 5); // ceil (in_len * 8 / 5) + int out_len = (int) (((0.5 + (double) in_len) * 8) / 5); // ceil (in_len * 8 / 5) while (out_len % 8) { @@ -540,7 +540,7 @@ int base64_encode (u8 (*f) (const u8), const u8 *in_buf, int in_len, u8 *out_buf out_ptr += 4; } - int out_len = (int) (((0.5 + (float) in_len) * 8) / 6); // ceil (in_len * 8 / 6) + int out_len = (int) (((0.5 + (double) in_len) * 8) / 6); // ceil (in_len * 8 / 6) while (out_len % 4) { @@ -5661,7 +5661,7 @@ void format_timer_display (struct tm *tm, char *buf, size_t len) } } -void format_speed_display (float val, char *buf, size_t len) +void format_speed_display (double val, char *buf, size_t len) { if (val <= 0) {