/* Non-restoring dvision algorithm according to http://www.arpnjournals.org/jeas/research_papers/rp_2017/jeas_0517_6036.pdf */ module divi_comb #(parameter NBITS_DEND=8, // number of bits of dividend NBITS_SOR=8, // number of bits of divisor NBITS_Q=8) // number of bits of quotient (input logic [NBITS_DEND-1:0] dend, // dividend input logic [NBITS_SOR -1:0] sor, // divisor output logic [NBITS_Q -1:0] q); // quotient // for vcs (Synopsys simulator) change <= to = in lines 26,27,29 /* verilator lint_off UNOPTFLAT */ // remainders, one for each quotient bit plus one for initialization logic [NBITS_SOR-1:0] rem [NBITS_Q+1:1]; logic [NBITS_SOR:0] rems [NBITS_Q+1:0]; // shifted remainder always_comb // inverted most significant bits of remainders are the quotient for(int i=1; i<=NBITS_Q; i++) q[NBITS_Q-i] <= ~rem[i+1][NBITS_SOR-1]; always_comb begin rems[0] <= 0; // initial shifted remainder for(int i=0; i<=NBITS_Q; i++) begin // calculate all remainders // if remainder is negative, add else subtract divisor if(rems[i][NBITS_SOR]) rem[i+1] <= rems[i] + sor; else rem[i+1] <= rems[i] - sor; // shift in the next didivend bit rems[i+1] <= { rem[i+1], i