Messages in this thread | | | Date | Wed, 10 Dec 1997 11:13:06 -0500 | From | "Theodore Y. Ts'o" <> | Subject | Re: copy-bit macro |
| |
It appears to me that people are not understanding the problem which the copy-bit macro is trying to solve. The basic idea here is that there are often cases where you need to set bit number x if bit number y is set.
For example,
if (input & 1 << IN_FLAG_NUMBER) output |= 1 << OUT_FLAG_NUMBER
... where IN_FLAG_NUMBER and OUT_FLAG_NUMBER are not the same.
An example of where this might be done is where if the PARODD bit in the termios structure is set, set the appropriate bit in the UART's MCR register.
The naive implementation, either involving an if statement or the C conditional operator (i.e., "output |= (input & 1 << IN_FLAG_NUMBER) ? (1 << OUT_FLAG_NUMBER) : 0") both involve an assembly language conditional jump instruction, which is expensive, because it involves pipeline stalls, etc.
Colin has proposed a macro which plays shifting and masking games which is much faster.
- Ted
| |