| ▲ | Charon77 2 days ago | |||||||
> Like addition I'm perplexed to the claim that addition is cheaper than XOR, especially since addition is built upon XOR, am I missing anything? Is it javascript specific? | ||||||||
| ▲ | purplesyringa 2 days ago | parent | next [-] | |||||||
I work on the machine code level, so the only characteristic I'm interested in is how many ticks it takes to compute the result, not how many transistors it requires or anything like that. All modern CPUs take 1 tick to compute both XOR, addition, and many other simple arithmetic operations, so even though addition is technically more complicated in CPU designs, it never surfaces in software. In the context of this post, I preferred addition instead of XOR to reduce cancel-out and propagate entropy between bits. | ||||||||
| ▲ | pjscott 2 days ago | parent | prev | next [-] | |||||||
The wording was a bit unclear. The previous paragraph mentions wanting something cheaper than "those pesky XORs and multiplications". The multiplication is the expensive part; the (very cheap) XORs are just mildly annoying because you have to think about what they're doing. | ||||||||
| ▲ | 4k0hz 2 days ago | parent | prev [-] | |||||||
At least on x86, multiple additions and multiplications can be done with a single `lea` instruction so it's preferable to XOR. Though I have no idea about other architectures, compiler implementations, any interpreters... | ||||||||
| ||||||||