Work-around buggy Intel chips erroneously reporting BMI1/BMI2 support #1249
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Apparently on some chips,
cpuid
is not to be fully trusted. According to http://www.intel.com/content/dam/www/public/us/en/documents/specification-updates/desktop-6th-gen-core-family-spec-update.pdf, some Skylake chips (notably Celerons) will report support for BMI1 and BMI2 without actual support for those operations.Quoting that document's Errata section:
IIUC, the problematic chips are fairly widespread1, and searches online do seem to bring up people hitting this crash in the real world... so it would be nice if a better workaround existed than "ask the user to update their BIOS" (I think the OS could work around it too — if nothing else, by performing a similar hack to what's in this patch).
That said, one seems to exist2. From what I was able to tell3, all current Intel chips with working support for either BMI instruction set also have AVX, and the chips impacted by this bug here do not, so we can just assume any Intel chip without AVX also has no BMI1/BMI2. If this is correct, we can work around this with no downside to any current chip, so even if a more ideal place for a hack like this would be in the OS4, it's worth doing.
This is what's implemented in this patch, which also contains a big comment describing the issue, since it's pretty WTF.
Footnotes
I am pretty sure I know someone with one. This would be great because it would allow me to verify the issue/fix, but the Intel documentation is pretty clear either way. ↩
It's not surprising that Intel wouldn't include this as the suggested workaround, since they might want to keep the ability to ship chips with BMI and not AVX in the future. ↩
Unfortunately, this isn't definitive, since I'm not sure where to find such information concretely, and just went by what I could find on Wikipedia and Agner. That said, it makes sense that this would be the case both now and in the future, and it's safe even if I'm wrong or things change in the future. ↩
And ofc we can't rely on the user's OS or BIOS being up to date, beyond what libstd supports. ↩