OK, what I want is pretty straight forward :
This is my code so far (in the form of 2 macros) :
#define SETBIT(X,Y) X|=(1ULL<<(Y))
#define UNSETBIT(X,Y) X&=(~(1ULL<<(Y)))
They are both working fine. The thing is :
(Both operations are supposed to be performed some millions of times per second, so performance is more than crucial).
You can marginally speed up compilation time by getting rid of the macros, but that's about it. Bit twiddling is fast enough so it shouldn't be an issue.
This is the idiomatic way of doing it, I wouldn't change a thing.
This is the standard way of setting and clearing a bit in C.
If you want to potentially speed up these macros you can have a look at Linux assembly implementations of these operations.
For example, for x86
:
http://lxr.linux.no/linux/arch/x86/include/asm/bitops.h
Look for __clear_bit
and __set_bit
inline functions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With