On Thursday, 14 March 2024 at 01:58:46 UTC, Richard (Rikki) Andrew Cattermole wrote:
The cost of an add + increment then a bitwise and is only 2-4 cycles on a Haswell cpu. Depending upon if its working solely in registers (via inlining) or its operating on ram.

Whereas if you need to do branching (if statement, loops), this is an unpredictable cost and loops where a simple bitwise operation can be done is out right non-optimized.

As for exceptions, totally not required. You can solve this by simply making your state private so nobody else can mutate it. Bounds checking will ensure if the state is corrupted it'll error out if you use the lookup method I suggested above.

I tried to rework the functions to use bitwise operations, but it was difficult to figure out the correct logic. I decided that it's not worth the hassle, so I just changed the value storage from `bool[3]` to `ubyte`. Now it works much more like your version.
https://github.com/LiamM32/Open_Emblem/blob/c2014ab3f77e89c0cedcd6dbf7f8362ebfac33a9/source/common.d

I did a little reading, so now I understand what it means when you have `&= 7`. But I want to ask, is this faster than `%= 8`? If not, I would like to change it to the latter for readability.
  • Challenge: Make ... Liam McGillivray via Digitalmars-d-learn
    • Re: Challen... Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
      • Re: Cha... Liam McGillivray via Digitalmars-d-learn
        • Re:... Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
      • Re: Cha... Liam McGillivray via Digitalmars-d-learn
        • Re:... Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
          • ... Liam McGillivray via Digitalmars-d-learn
            • ... Basile B. via Digitalmars-d-learn
              • ... Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
                • ... Basile B. via Digitalmars-d-learn
            • ... H. S. Teoh via Digitalmars-d-learn
            • ... Liam McGillivray via Digitalmars-d-learn
              • ... H. S. Teoh via Digitalmars-d-learn
    • Re: Challen... Salih Dincer via Digitalmars-d-learn
    • Re: Challen... Basile B. via Digitalmars-d-learn
    • Re: Challen... Daniel N via Digitalmars-d-learn

Reply via email to