Various methods for performing rounding operations in a computer processor
are described. A machine instruction sets the rounding mode, which is automatically
applied to subsequent machine instructions. Using machine instructions to round
results according to the selected rounding mode has several advantages over software-implemented
rounding techniques, such as faster execution and concise code. A variety of rounding
modes can be specified. Depending in part on the specified rounding mode and on
the sign of the value to be rounded, a rounding term is added to the value to be
rounded. Adding this rounding term ensures that the desired result is obtained.
The value thus obtained is then right-shifted.