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

--- Comment #17 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
(In reply to Liu Hao from comment #15)
> 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 ));

That would certainly need : "xmm5" in clobbers (etc.).
And isn't really portable anyway, the compiler can choose to put
anything into %xmm6 in between that and the asm before printf.
But, loading the value from memory into some double temporary (with "=x" for
many of them)
in an asm and then e.g. just "+x" them in empty asms and then comparing values
will likely reproduce it too.

>     __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`

You mean 6.123456 ?  And in any case, I'd suggest whatever.625 or other
constants which won't suffer from rounding etc.

Reply via email to