lkml.org 
[lkml]   [1997]   [Dec]   [11]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: 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

\
 
 \ /
  Last update: 2005-03-22 13:40    [W:0.069 / U:0.732 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site