Thread: mulmod failing
View Single Post
Old 2017-06-08, 20:03   #2
danaj
 
"Dana Jacobsen"
Feb 2011
Bangkok, TH

90910 Posts
Default

In my code I have this comment:

Code:
  /* GCC on a 64-bit Intel x86, help from WraithX and Wojciech Izykowski */
  /* Beware: if (a*b)/c > 2^64, there will be an FP exception */
  static inline uint64_t _mulmod(uint64_t a, uint64_t b, uint64_t n) {
    uint64_t d, dummy;                    /* d will get a*b mod c */
    asm ("mulq %3\n\t"              /* mul a*b -> rdx:rax */
         "divq %4\n\t"              /* (a*b)/c -> quot in rax remainder in rdx */
         :"=a"(dummy), "=&d"(d)     /* output */
         :"a"(a), "rm"(b), "rm"(n)  /* input */
         :"cc"                      /* mulq and divq can set conditions */
        );
    return d;
  }
It seems the exact behavior varies -- my Mac hangs, while some other machines I have exit with an FP exception.
danaj is offline   Reply With Quote