From 654cd570b4348f788ce83c50fce9986afdcbea30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Drwi=C4=99ga?= Date: Fri, 1 Jul 2016 12:35:14 +0200 Subject: [PATCH] Optimizing shr --- util/bigint/src/uint.rs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/util/bigint/src/uint.rs b/util/bigint/src/uint.rs index 2b9863135..2bc8e9810 100644 --- a/util/bigint/src/uint.rs +++ b/util/bigint/src/uint.rs @@ -1031,7 +1031,7 @@ macro_rules! construct_uint { // shift for i in word_shift..$n_words { - ret[i] += original[i - word_shift] << bit_shift; + ret[i] = original[i - word_shift] << bit_shift; } // carry if bit_shift > 0 { @@ -1052,14 +1052,18 @@ macro_rules! construct_uint { let word_shift = shift / 64; let bit_shift = shift % 64; + // shift for i in word_shift..$n_words { - // Shift - ret[i - word_shift] += original[i] >> bit_shift; - // Carry - if bit_shift > 0 && i < $n_words - 1 { - ret[i - word_shift] += original[i + 1] << (64 - bit_shift); + ret[i - word_shift] = original[i] >> bit_shift; + } + + // Carry + if bit_shift > 0 { + for i in word_shift+1..$n_words { + ret[i - word_shift - 1] += original[i] << (64 - bit_shift); } } + $name(ret) } }