Illegal instruction fix

Torbjörn Granlund tg at
Wed Jan 6 00:26:31 UTC 2021

William Blanke <bill at> writes:

  At Chia, we are using GMP inside Python binary wheels. This means we
  compile GMP on one machine and then run this code on different machines,
  possibly with different CPUs.

  When GMP 6.2 was released, we encountered illegal instruction crashes on
  Intel CPUs older than Haswell. We traced this to the LZCNT instruction
  being run on these older CPUs even though fat binary was chosen on the post
  Haswell compile machine. Unfortunately, this still happens with GMP 6.2.1

  To fix this we have created the patch below. It chooses whether to use the
  LZCNT, MULX, and TZCNT instructions based on CPU support via runtime CPUID
  checks for LZCNT, BMI2, and BMI1 capabilities respectively.

  We would like to submit this for upstream inclusion in future versions of
  GMP. We hope that it helps and we thank you for all your efforts!

We don't do this type of runtime detection for single instructions, as
the choosing takes way more time than any basic old code sequence.

Now, it is somewhat surprising thet rep;bsr fails.  The rep should be
ignored for old processors.  OK, so maybe not.

Then the correct approach is to suppress that variant for fat builds
and fall back to the less-defined plain bsr.

Please encrypt, key id 0xC8601622

More information about the gmp-bugs mailing list