0

I'm reading a book bottom up and it have instruction to get exponent of float on c compiled via GCC:

asm ("getf.exp %0=%1" : "=r"(exp) : "f"(d));

saying it works on Itanium. On my Core i7 GCC says Error: no such instruction: 'getf.exp %rax=%st'.

I've tried web search but could not find similar instruction for Core iX processors. Is there such?

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Marisha
  • 816
  • 9
  • 14
  • 1
    I might start with [this](https://stackoverflow.com/a/19608878/2189500). There are all sorts of [reasons](https://gcc.gnu.org/wiki/DontUseInlineAsm) not to use inline asm. This is #3. – David Wohlferd Sep 25 '19 at 06:28
  • 1
    No, x86 does not have such an instruction. Use the `ilogb` function from `math.h` instead. That said, the instructions of every architecture are different and assembly code written for one architecture generally does not work on any other. – fuz Sep 25 '19 at 09:21
  • @fuz: AVX512 has a similar instruction that gets the exponent *as a float*: https://www.felixcloutier.com/x86/vgetexpps. Floats will be in XMM registers so you can do integer bit-shifts and masking on them with SSE2 instructions instead of extracting the bit-pattern to integer. But yeah, there's no reason to expect to find equivalents for IA-64 instructions on x86, except for the obvious stuff like `add`. – Peter Cordes Sep 25 '19 at 10:28
  • @PeterCordes OP says he has a Core i7 CPU and as far as I'm concerned, there are no Core i7 CPUs with AVX 512 on the market yet; only CPUs branded Xeon have AVX 512. But yeah, you are technically correct. – fuz Sep 25 '19 at 11:05
  • @fuz: There are SKX i9 and i7 CPUs in the (expensive) HEDT series: https://www.anandtech.com/show/14463/intel-plans-to-phase-out-2017-skylake-x-processors. But yeah, I wasn't suggesting the OP could use it on their CPU, just that x86 has it. (In an extension that will be widespread in a few years, starting with IceLake for the mainstream.) – Peter Cordes Sep 25 '19 at 11:13
  • @PeterCordes Ah cool, that's new to me. – fuz Sep 25 '19 at 11:14

0 Answers0