• Tolookah@discuss.tchncs.de
    link
    fedilink
    arrow-up
    5
    ·
    1 day ago

    I use bit masks, suck it! (Really though, programming on an embedded CPU might be reasonable to do this, depending on the situation, but on a PC, trying to not waste bits wastes time)

    • jsomae@lemmy.ml
      link
      fedilink
      arrow-up
      2
      ·
      23 hours ago

      Unlikely. Most of the time on modern hardware, you’re going to be cache-limited, not cycle-limited. Checking one bit in a register is insanely fast.

    • Binette@lemmy.ml
      link
      fedilink
      arrow-up
      2
      ·
      1 day ago

      exactly! it is more costly for your pc cpu to check for a bit inside a byte, than just get the byte itself, because adresses only point to bytes

    • mindbleach@sh.itjust.works
      link
      fedilink
      arrow-up
      1
      ·
      1 day ago

      Even on 6502, the BIT command is useless 99% of the time, and AND ~which_bit is the right answer.

      Interestingly the Intel MCS-51 ISA did have several bit-addressable bytes. Like a weird zero page.

      • jsomae@lemmy.ml
        link
        fedilink
        arrow-up
        2
        ·
        23 hours ago

        Only because 6502 has no BIT immediate – only BIT zero page and BIT absolute. But the contemporary z80 and gameboy cpu too have dedicated bit instructions, e.g. BIT c,6 (set z flag to bit 6 of register c).

        • mindbleach@sh.itjust.works
          link
          fedilink
          arrow-up
          3
          ·
          21 hours ago

          I think it’s intended for checking the same bit in multiple bytes. You load the mask instead of the data.

          So much 6502 ASM involves turning your brain inside-out… despite being simple, clever, and friendly. Like how you can’t do a strided array sensibly because there’s no address register(s). There is no “next byte.” Naively, you want separate varied data at the same index is separate arrays. Buuut because each read address is absolute, you can do *(&array+1)[n], for free.

          What I really miss on NES versus Game Boy is SWAP.