https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99234

--- Comment #15 from Liu Hao <lh_mouse at 126 dot com> ---
Thanks. The 'Final fix' looks good to me.

I applied it locally and built GCC. With a debugger, I verified that after the
try-catch statement, all non-volatile XMM registers (6-15) had been restored
properly.



```
// x86_64-w64-mingw32-g++ -O2 -fno-omit-frame-pointer test.cc

__attribute__((__noinline__)) void clobber_xmm6()
  {
    __asm__ volatile ("xorpd %%xmm6, %%xmm6" ::: "xmm6");
    throw 42;   // remove this to get expected result
  }

int main()
  {
    static const double xmm5  =  5.123456;
    static const double xmm6  =  6.123456;
    static const double xmm7  =  7.123456;
    static const double xmm8  =  8.123456;
    static const double xmm9  =  9.123456;
    static const double xmm10 = 10.123456;
    static const double xmm11 = 11.123456;
    static const double xmm12 = 12.123456;
    static const double xmm13 = 13.123456;
    static const double xmm14 = 14.123456;
    static const double xmm15 = 15.123456;
    __asm__ volatile ("movsd %0, %%xmm5 " :: "m"(xmm5 ));
    __asm__ volatile ("movsd %0, %%xmm6 " :: "m"(xmm6 ));
    __asm__ volatile ("movsd %0, %%xmm7 " :: "m"(xmm7 ));
    __asm__ volatile ("movsd %0, %%xmm8 " :: "m"(xmm8 ));
    __asm__ volatile ("movsd %0, %%xmm9 " :: "m"(xmm9 ));
    __asm__ volatile ("movsd %0, %%xmm10" :: "m"(xmm10));
    __asm__ volatile ("movsd %0, %%xmm11" :: "m"(xmm11));
    __asm__ volatile ("movsd %0, %%xmm12" :: "m"(xmm12));
    __asm__ volatile ("movsd %0, %%xmm13" :: "m"(xmm13));
    __asm__ volatile ("movsd %0, %%xmm14" :: "m"(xmm14));
    __asm__ volatile ("movsd %0, %%xmm15" :: "m"(xmm15));

    try {
      clobber_xmm6();
    }
    catch(...) { }

    double value;
    __asm__ volatile ("movsd %%xmm6, %0" : "=x"(value));
    __builtin_printf("value = %g\n", value);      // expect `123.456`
  }


```

Reply via email to