Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
12/12/02 00:36
Read: times


 
#34292 - Checking 1 bit in a byte Faster than Dan
Dan suggested:
#define BIT4 (1 << 4)

unsigned char byte;
unsigned char old_byte;

byte = reg; /* Only read register once per check */

But if you're going to copy the byte anyway, why not copy it into a bit-addressable byte, so that the required bit can then be tested directly - without all that tedious messing about with masking, etc?!

You could then also look at Keil's _testbit_() intrinsic fucntion - which gives some advantage in some situations.

As Dennis said, you'll need to experiment & examine the resulting assembler to determine which is actually the fastest for you.

List of 13 messages in thread
TopicAuthorDate
Checking one bit, in a byte Fast            01/01/70 00:00      
RE: Checking one bit, in a byte Fast            01/01/70 00:00      
RE: Checking one bit, in a byte Fast            01/01/70 00:00      
RE: Checking one bit, in a byte Fast            01/01/70 00:00      
RE: Checking one bit, in a byte Fast            01/01/70 00:00      
RE: Checking one bit, in a byte Fast            01/01/70 00:00      
RE: Checking one bit, in a byte Fast            01/01/70 00:00      
Checking 1 bit in a byte Faster than Dan            01/01/70 00:00      
RE: Checking 1 bit in a byte Faster than Dan            01/01/70 00:00      
RE: assembler faster than C            01/01/70 00:00      
RE: Checking 1 bit in a byte Faster than Dan            01/01/70 00:00      
RE: Checking 1 bit in a byte ... Erik            01/01/70 00:00      
RE: Checking one bit, in a byte Fast            01/01/70 00:00      

Back to Subject List