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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • timmu

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


    If I have set a macro such like:

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

    will something like
    *(u64*)REGISTER 1 |= 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.

  • pete

    #2
    Re: 64 bit register manipuate using 1ULL &lt;&lt; (a) macro?

    timmu wrote:[color=blue]
    >
    > If I have set a macro such like:
    >
    > #define BIT(a) (1ULL << (a))
    >
    > will something like
    > *(u64*)REGISTER 1 |= 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.[/color]

    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)))

    --
    pete

    Comment

    • Dave Thompson

      #3
      Re: 64 bit register manipuate using 1ULL &lt;&lt; (a) macro?

      On 25 Apr 2006 03:06:11 -0700, "timmu" <tim119@gmail.c om> wrote:
      [color=blue]
      >
      > If I have set a macro such like:
      >
      > #define BIT(a) (1ULL << (a))
      >
      > will something like
      > *(u64*)REGISTER 1 |= BIT(53)
      > work if i wanna set bit[53] as 1 ?
      >[/color]
      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.
      [color=blue]
      > I'm running on MIPS which have several 64bit registers,
      > just don't know if the syntax will work.
      >[/color]
      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.ne t

      Comment

      Working...