64 bit register manipuate using 1ULL << (a) macro?

T

timmu

If I have set a macro such like:

#define BIT(a) (1ULL << (a))

will something like
*(u64*)REGISTER1 |= BIT(53)
work if i wanna set bit[53] as 1 ?

I'm running on MIPS which have several 64bit registers,
just don't know if the syntax will work.

thanks for any idea.
 
P

pete

timmu said:
If I have set a macro such like:

#define BIT(a) (1ULL << (a))

will something like
*(u64*)REGISTER1 |= BIT(53)
work if i wanna set bit[53] as 1 ?

I'm running on MIPS which have several 64bit registers,
just don't know if the syntax will work.

thanks for any idea.

Looks OK to me.

#define BIT(a) (1ULL << (a))

#define READ_BIT(U, N) ((U) >> (N) & 1ULL)
#define SET_BIT(U, N) ((void)((U) |= BIT(N)))
#define CLEAR_BIT(U, N) ((void)((U) &= ~BIT(N)))
#define FLIP_BIT(U, N) ((void)((U) ^= BIT(N)))
 
D

Dave Thompson

If I have set a macro such like:

#define BIT(a) (1ULL << (a))

will something like
*(u64*)REGISTER1 |= BIT(53)
work if i wanna set bit[53] as 1 ?
Assuming you want little-endian bit numbering, u64 is a typedef for a
sufficiently large (presumably 64-bit) unsigned type, and REGISTER1 is
(or evalutes to) a pointer to something that is large enough and
correctly aligned to hold a u64, yes.
I'm running on MIPS which have several 64bit registers,
just don't know if the syntax will work.
If you mean processor registers, it is extremely rare to be able to
have a pointer to one of those. (There are some odd architectures
which do this, but MIPS is not one of them.) On modern compilers it's
rarely possible to assign a variable to a particular or known
register, or even to any register, but if you can and do for a
variable of type u64 then just x |= BIT(53).

- David.Thompson1 at worldnet.att.net
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top