c – Flags. Variables, bits, or bit fields?


From the point of view of performance, on the x86 architecture, which option for creating a set of flags is the most optimal – structure + bit fields, bits of a simple variable, separate variables of 1 byte for each flag. How sensitive is the difference?


The comment limit has been reached. So have to answer @ karmadro4 in the answer.

You are right, timing tables are not missing. Only using them it is very difficult to calculate the execution time of a program fragment. Data delays associated with filling caches and TLBs are not obvious (they depend on the execution of other threads and interrupts in the system).

Also, without knowing the specific values ​​of the data being processed, it is impossible to predict the prefetch of instructions, operands and out-of-order execution of instructions.

The exchange of data between the cache and RAM occurs in cache lines (usually 32 bytes), and between the cache and ALU buffers in words (32 or 64 bits), therefore, "uchars" do not change anything, compared to "ulongs".

I repeat once again, this topic is very interesting, but not obvious.

Scroll to Top