Method of performing hardware efficient unbiased rounding of a number
A method and hardware for performing hardware efficient unbiased rounding of a number includes receiving the number in a binary format having a first portion and a second portion. The first portion comprises bits of the number above a rounding point and the second portion comprises bits of the number after the rounding point. The method includes adding a first amount to the number to obtain a first value. Further the method comprises determining if the bit above the rounding point for a controlling value is ‘0’ bit or a ‘1’ bit. The controlling value is either the received number in the binary format or the first value. The method further includes adding a second amount to ‘b+1’ LSBs of the first value to obtain a second value if the bit above the rounding point for the controlling value is a ‘0’ bit and rounding the number by truncating the last b bits of the second value or the last b bits of the first value based on the determination.
1 . A method of processing an input value to a processing system, said input value comprising a number representing data, the method comprising:
receiving, at a first adder implemented in hardware logic, the number in a binary format with a bit length of m bits, having a first portion with bit length of ‘a’ bits and second portion with bit-length of ‘b’ bits, wherein the first portion comprises bits of the number above a rounding point and the second portion comprises bits of the number after the rounding point;
performing a hardware efficient unbiased rounding of the number by:
adding, by the first adder, a first amount to the number to obtain a first value;
determining if the bit above the rounding point for a controlling value is ‘0’ bit or a ‘1’ bit, wherein the controlling value is either the received number in the binary format or the first value;
if the bit above the rounding point for the controlling value is a ‘0’ bit, adding, by a second adder implemented in hardware logic, a second amount to ‘b+1’ LSBs of the first value to obtain a second value and truncating the last b bits of the second value by a shifter implemented in hardware logic; or
if the bit above the rounding point for the controlling value is a ‘1’ bit, truncating the last b bits of the first value by said shifter;
wherein the first amount and the second amount to be added are determined based on the number of ‘b’ bits of the second portion and wherein the first value and the second value are represented in the same binary format as the received number; and
outputting the truncated value from the shifter to the processing system to facilitate processing of said number by the processing system.
2 . The method according to claim 1 , wherein the value of the second amount is the value of the LSB of the second portion.
3 . The method according to claim 1 , wherein adding the second amount comprises adding a ‘1’ to the LSB of the first value.
4 . The method according to claim 1 , wherein the first amount is the difference between the value of position of MSB of the second portion and the second amount, such that when b=1, the first amount is zero.
5 . The method according to claim 1 , wherein adding the second adder is a ‘b+1’ bit adder.
6 . The method according to claim 1 , wherein the first value and the second value are having the same ‘a−1’ MSBs.
7 . The method according to claim 1 , wherein adding a second amount to ‘b+1’ LSBs of the first value generates an intermediate value having a bit length of ‘b+1’ bits.
8 . The method according to claim 6 , wherein the second value is obtained by combining ‘a−1’ MSBs of the first value and ‘b+1’ bits of the intermediate value.
9 . The method according to claim 1 , wherein the received number has an integer part and a fractional part.
10 . The method according to claim 9 , wherein the first portion of ‘a’ bits comprises bits of the integer part and none, one or more MSBs of the fractional part to which the number needs to be rounded.
11 . The method according to claim 1 , wherein the first adder is a ‘m’ bit adder.
12 . A non-transitory computer readable storage medium having stored thereon computer readable code configured to cause the method of claim 1 to be performed when the code is run on at least one processor.
13 . An efficient hardware implementation for processing an input value to a processing system, said input value comprising a number representing data, the hardware implementation performing unbiased rounding and comprising:
a first adder implemented in hardware logic configured to:
receive said number in binary format with a bit length of m bits, having a first portion with bit length of ‘a’ bits and a second portion with bit-length of ‘b’ bits, the first portion comprises bits of the number before a rounding point and the second portion comprises bits of the number after the rounding point, and
add a first amount to the number N to obtain a first value;
a second adder implemented in hardware logic configured to add a second amount to ‘b+1’ LSBs of the first value to obtain a second value, wherein the second amount is added if the bit above the rounding point for the first value is a ‘0’ bit;
wherein the first amount and the second amount to be added is determined based on the bit length ‘b’ bits of the second portion;
a shifter implemented in hardware logic configured to:
shift the second value by ‘b’ bit to the LSB side if the bit above the rounding point for the first value is a ‘0’ bit, or
shift the first value by ‘b’ bit to the LSB side if the bit above the rounding point for the first value is a ‘1’ bit; and
said shifter being further configured to output the shifted value to the processing system to facilitate processing of said number by the processing system.
14 . The hardware implementation according to claim 13 , wherein the first adder is an m-bit adder.
15 . The hardware implementation according to claim 13 , wherein the second adder is a ‘b+1’ bit adder.
16 . The hardware implementation according to claim 13 , wherein the shifter is implemented by hard wiring the wires from the second adder or the first adder.
17 . The hardware implementation according to claim 13 , wherein the first adder is integrated with an in-built adder in a logic in the hardware producing the number to be rounded, and optionally wherein the logic is a Finite Impulse Response (FIR) filter used in image processing.
18 . The hardware implementation according to claim 13 , wherein the second adder adds the second amount by adding ‘1’ to the LSB of the first value.
19 . The hardware implementation according to claim 13 , wherein the first adder adds the first amount which is the difference between the value of the MSB of the second portion and the second amount.
20 . A non-transitory computer readable storage medium having stored thereon an integrated circuit dataset description that when processed by an integrated circuit manufacturing system causes the integrated circuit manufacturing system to manufacture the hardware implementation as set forth in claim 13 .