0

Is there a single assembly instruction that gets the fractional part of a double or float (or packed double or float)?

(x87 x64 SSE)

  • 1
    You have asked *at least* 3 different questions in this very short text. How to get the fractional part, how to implement `modf`, and whether there exists a *single instruction* to get the fractional part. Also both x87 and SSE are involved somehow in a way that is not quite clear. What is your actual question? – harold Oct 02 '17 at 19:10
  • No I don't want to implement modf. I also don't want to round/truncate (FRNDINT) than subtract. – TemporalStructure Oct 02 '17 at 19:12
  • 4
    If the main question is "is there a *single instruction* that gets the fractional part", the answer is no there isn't. Not even FPREM. – harold Oct 02 '17 at 19:19
  • 1
    AVX512F has `vgetmantpd/ps` to get the mantissa (as a `double` / `float` normalized to your choice of ranges), but that's not the same thing as the fractional part. https://hjlebbink.github.io/x86doc/html/VGETMANTPD.html https://hjlebbink.github.io/x86doc/html/VGETMANTPS.html. There's a `vgetexppd` as well. They're useful for implementing log2(). – Peter Cordes Oct 02 '17 at 19:34
  • Oh, (off topic) log2() is important to me , do you have a link to this algorithm/ implementation ? – TemporalStructure Oct 02 '17 at 20:47
  • 1
    https://stackoverflow.com/questions/45770089/efficient-implementation-of-log2-m256d-in-avx2. – Peter Cordes Oct 02 '17 at 22:29
  • 1
    @harold `vfrcz(s/p)(s/d)` in XOP and `vreduce(s/p)(s/d)` in AVX512-DQ will do it in a single instruction. Neither of these are readily available though. – Mysticial Oct 03 '17 at 19:42
  • ^^ /cc @PeterCordes – Mysticial Oct 03 '17 at 19:42
  • Oh yeah, forgot about [`vreducepd`](https://hjlebbink.github.io/x86doc/html/VREDUCEPD.html). Thanks, @Mysticial. I didn't know about the XOP instruction. I think you can at least test AVX512DQ instructions using Intel's SDE emulator, if you don't have a Skylake-avx512 CPU. – Peter Cordes Oct 03 '17 at 19:46

0 Answers0