Forum Discussion
Altera_Forum
Honored Contributor
10 years agoif you remove the question of bit resolution, it comes down to something as simple as this:
OP = X/C which is the same as OP = X * 1/C 1/C can be calculated prior to implementation, and you have a constant multiplier rather than constant divisor. Lets assume C = 5. obviously, 1/C is now less than 1, and cannot be represented in the same bits that X is represented in. Lets assume X is an 8 bit integer. 1/C requires extra bits on the RHS of the number. Lets assume X is 75 (b00101011) 1/C = 0.2. lets assume we add another 8 bits for fractional bits. We can now generate our numbers by multiplying everything by 256. 75 * 256 = b0010101100000000 (19200 you just shift by 8 bits) 0.2 * 256 = b0000000000110011 (51.2, so we lost the 51) Now we multiply 51x19200 = b0000,0000,0000,1110,1111,0001,0000,0000 (979200) We now have 16 integer bits and 16 fraction bits (8.8 * 8.8 = 16.16) so we can drop the 16 fraction bits to get our answer, 0000000000001110 = 14 (15 if you add extra rounding logic - drop all but the 2^-1 bit and add 1). VHDL 2008 adds the fixed point libraries that mean keeping track of fraction and integer separation in your words is really simple (integer bits have positive index values and fraction are negative, to match the 2^n offset). Otherwise you need to manually keep track of the separation (by using imarginary multiplication offsets etc).