+ if(bigint_length_b(a) + 3 > bigint_length_b(r)){
+ if((r->length_W*sizeof(bigint_word_t)<=4) && (a->length_W*sizeof(bigint_word_t)<=4)){
+ uint32_t p=0, q=0;
+ memcpy(&p, a->wordv, a->length_W*sizeof(bigint_word_t));
+ memcpy(&q, r->wordv, r->length_W*sizeof(bigint_word_t));
+ p %= q;
+ memcpy(a->wordv, &p, a->length_W*sizeof(bigint_word_t));
+ bigint_adjust(a);
+ // cli_putstr("\r\nDBG: (0) = "); bigint_print_hex(a);
+ return;
+ }
+ uint16_t shift;
+ while(a->length_W > r->length_W){
+ shift = (a->length_W - r->length_W) * 8 * sizeof(bigint_word_t) + GET_FBS(a) - rfbs - 1;
+ /*
+ if((a->wordv[a->length_W-1] & ((1LL<<GET_FBS(a)) - 1)) > r->wordv[r->length_W-1]){
+ // cli_putc('~');
+ cli_putstr("\r\n ~ [a] = ");
+ cli_hexdump_rev(&a->wordv[a->length_W-1], 4);
+ cli_putstr(" [r] = ");
+ cli_hexdump_rev(&r->wordv[r->length_W-1], 4);
+ shift += 1;
+ }
+ */
+ // cli_putstr("\r\nDBG: (p) shift = "); cli_hexdump_rev(&shift, 2);
+ // cli_putstr(" a_len = "); cli_hexdump_rev(&a->length_W, 2);
+ // cli_putstr(" r_len = "); cli_hexdump_rev(&r->length_W, 2);
+ // uart_flush(0);
+ bigint_sub_u_bitscale(a, r, shift);
+ // cli_putstr("\r\nDBG: (1) = "); bigint_print_hex(a);
+ }
+ while((GET_FBS(a) > rfbs) && (a->length_W == r->length_W)){
+ shift = GET_FBS(a)-rfbs-1;
+ // cli_putstr("\r\nDBG: (q) shift = "); cli_hexdump_rev(&shift, 2);
+ bigint_sub_u_bitscale(a, r, shift);
+ // cli_putstr("\r\nDBG: (2) = "); bigint_print_hex(a);
+ }