How to check when a division by zero happends (x86)

This piece of code was gold for me (thanks to Harry !)  :

    uint32_t mxcsr;
    uint32_t mask = 0;
    //mask |= 1 << 12; // precision mask
    mask |= 1 << 11;   // under flow mask 
    mask |= 1 << 10;   // over flow mask
    mask |= 1 << 9;    // division by zero mask
    mask |= 1 << 7;    // invalid operator mask
    mask = ~mask;
    asm volatile ("stmxcsr %0" : "=m"(mxcsr));
    mxcsr &= mask;
    asm volatile ("ldmxcsr %0" : : "m"(mxcsr));

When you add it, then any division by zero (or other type of error you had to the mask) will trigger an floating point exception. This can save you a day (or two)…