/** Flip all the bits, in-place, in a single write op! */
void optimizedFlip(int* p) {
    // Step 1. Create bit-wise integer mask (second operand) with all bits set to 1 (e.g. one's complement of the zero constant)
    // Step 2. Read value located at address p (first operand)
    // Step 3. Use XOR (exclusive-or) operator to flip all the bits
    // Step 4. Write the result back at address p
    // Pseudo-code: for(bit in bits) bit = XOR(bit, NOT(0))
    // TODO: use ASM machine code optimizations depending on ABI architecture
    // !!!!! bug-fix after 3 debugging days: make sure we wanna invert all (and ONLY) sizeof(int) bits, so force a cast to match 0's data type to int in case it defaults to something larger or smaller than a f&$**** integer
    *p ^= ~ (int) 0;
}

// FIXME: 64-bit function overload?! Oh wait, sizeof(int) is not always 32... I guess templates are useless for this use-case?
// FIXME: add integration and unit tests with all applicable test vectors for misc. device hardware executor units and OS-es (does it work on quantum bits, x = 1 - x? Is there a way to observe-and-flip a quantum bit without affecting the read value, due to Heisenberg's Uncertainty Principle?)
// FIXME: ask for code review after fixing and remove all FIXMEs (this should probably be a TODO, but whatever, this is my first task here...)

© ️2023