Lack of a very important instruction in modern CPUs: "Test and Reset"

Lack of a very important instruction in modern CPUs: "Test and Reset"

I am not sure if it already exists, but during my benchmarks, I felt a lot lack of a "Test Limit and reset" instruction for counter implementation on CPUs.

if (++Counter == N)
Counter=0;
has a very high cost due to jmp instruction cost

The modulus operation has a higher cost than jmp. It is not an option either.

Briefly, this instruction will take two parameters:

Memory or register
Value

and

will set [Memory Or Register] to 0 if [Memory Or Register] == Value

Using & operation as in the example below, is the best solution. But it requires to work with numbers which are power of 2.

Counter = ++Counter;
Counter &= 255;

I thought such an important and simple operand existed but I surprisingly couldn't find it during my researches.
I believe this simple instruction will speed up a lot of softwares.

Yorumlar

Bu blogdaki popüler yayınlar

Visual proofs of Hohha Dynamic XOR Encryption Algorithm