Andres Freund <andres@anarazel.de> writes:
> On 2018-07-09 19:56:25 -0400, Tom Lane wrote:
>> Or, perhaps, use a struct in assert builds and int64 otherwise?
>> You could hide the ensuing notational differences in macros.
> That should be doable. But I'd like to check if it's necessary
> first. Optimizing passing an 8 byte struct shouldn't be hard for
> compilers these days - especially when most things dealing with them are
> inline functions. If we find that it's not a problem on contemporary
> compilers, it might be worthwhile to use a bit more type safety in other
> places too.
I checked your example program on hardware I have laying around:
x86_64, gcc 4.4.7 (RHEL6): identical code, confirms your result
x86_64, LLVM 9.1.0 (macOS High Sierra): also identical
x86, gcc 4.2.1 (old macOS --- dromedary's host): also identical code;
this surprised me a bit. It looks like the ABI convention is that
64-bit values must be passed on the stack but can be returned in a
register pair, and it doesn't matter whether scalar or struct.
PPC, gcc 4.0.1 (ancient macOS --- prairiedog's host): *not* identical.
It looks like 64-bit arguments are passed in registers either way, but
a struct function result is returned in memory not a register.
ARM64, gcc 8.1.1 (Fedora 28): identical code
ARM64, clang 6.0.0 (FreeBSD 12): identical code
ARMv7, gcc 6.3.0 (Raspbian): *not* identical.
Looks like both pass and return conventions are memory-based for structs.
Offhand it would seem that we can get away with struct wrappers
on any platform where performance is really of concern today.
regards, tom lane