nth_bit and friends are broken

XMLWordPrintable

    • Type: Bug
    • Resolution: Fixed
    • Priority: P4
    • 9
    • Affects Version/s: 9
    • Component/s: hotspot
    • None
    • gc
    • b115

      The macros lack brackets around n:
      #define nth_bit(n) (n >= BitsPerWord ? 0 : OneBit << (n))
      #define right_n_bits(n) (nth_bit(n) - 1)
      #define left_n_bits(n) (right_n_bits(n) << (n >= BitsPerWord ? 0 : (BitsPerWord - n)))

      So, some esoteric usages produce the wrong result.

      Examples from a 64 bit JVM,
      nth_bit(true ? 32 : 64) returns 0x20 instead of 0x0000000100000000
      nth_bit(1|2) returns 0x0 instead of 0x8

            Assignee:
            Stefan Karlsson
            Reporter:
            Stefan Karlsson
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: