[Development] Passing QSize, QPoint, QTime and other small structs by value

Thiago Macieira thiago.macieira at intel.com
Fri Apr 7 22:24:44 CEST 2017


Em sexta-feira, 7 de abril de 2017, às 12:38:37 PDT, Shawn Rutledge escreveu:
> > Passing float or double by value means they get passed in the x87
> > registers.
>
> SIMD registers you mean, or are those the same?  At some point I read that
> the 387-era FPU instructions are way too slow by comparison nowadays, but I
> thought if that’s the case then probably the compilers are doing whatever
> is fastest by now...

No, I really mean the x87 registers. We're talking about the x86 ABI here, not 
the x86-64 or x32 ABI. Yes, they are mighty slow. But they are still used 
because that's what ABIs are for: retain compatibility.

GCC and Clang, when generating code for generic x86, will use x87 instructions 
anyway. So you may say that the data is already in the x87 coprocessor. Might 
as well leave it there.

But when compiling with -msse2 -mfpmath=sse (like we do QtCore and QtGui), the 
math itself is made with SSE instead, even if we have to pass arguments via 
x87 registers. To change that, we'd need -msseregparm, but that's an ABI-
changing option.

> > Passing float inside a struct means it's passed in the x86 stack instead.
> 
> No difference whether by value or by reference?  The compiler couldn’t break
> up the struct and put different members in different registers?

The difference between passing by value and by reference is whether the 
reference is included in the stack or not. See https://godbolt.org/g/cq643O.

It could break up, but doesn't because the ABI doesn't allow for that. Modern 
ABIs (except for MS Windows) allow for that.

-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center




More information about the Development mailing list