Closed noloader closed 4 years ago
According to the C standard, an enumeration is the implementation-defined smallest type that can represent all values. Hence, I'm doubtful that any 32-bit architecture will turn cpu_feature_t
into a multi-word value. The default is int
.
You can make sure of this by doing the following after the declaration of enum cpu_feature_t
:
enum { BLAKE2_STATIC_ASSERT_1 = 1 / (sizeof(cpu_feature_t) <= sizeof(int)) };
This commit adds a constructor to prime cpu features.
The functions looks safe, except for the write to the
static cpu_feature_t feature
. I think that could have atomicity problems on 32-bit systems if it is a 64-bit value in multi-threaded environments. That is, only half the value gets written and then a thread gets preempted. The partial write could momentarily leave thefeature
in an indeterminate state.If
cpu_feature_t
is not a 64-bit value, then this commit is probably not needed.