Google's style guide gives Linux a disadvantage

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Post Reply
Message
Author
User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

Google's style guide gives Linux a disadvantage

#1 Post by technosaurus »

Google's style guide states:
When defining a function, parameter order is: inputs, then outputs.

Parameters to C/C++ functions are either input to the function, output from the function, or both. Input parameters are usually values or const references, while output and input/output parameters will be non-const pointers. When ordering function parameters, put all input-only parameters before any output parameters
This is bad, because in UNIX/Linux the calling convention uses the following registers:
  • RDI, RSI, RDX, RCX, R8, and R9
while Windows uses:
  • RCX, RDX, R8, R9
Note that the DI in RDI stands for _D_estination _I_ndex while the SI in RSI stands for _S_ource _I_ndex.

On Windows that would mean just MOVing parameters to RSI and RDI, but on other UNIX-like platforms it requires an extra temp register whereas if the recommendation was reversed, Windows should perform the same and other platforms could potentially shave 3 operations (both MOVs and the temp) off of every function that moves data.

Not to mention it would match the rest of the world:
void *memmove(void *dest, const void *src, size_t n);
void *memcpy(void *dest, const void *src, size_t n);
char *strcpy(char *dest, const char *src);
... and practically every other standard function

Further reading:
https://en.wikipedia.org/wiki/X86_calli ... _AMD64_ABI - shows differences in various calling conventions
https://google-styleguide.googlecode.co ... r_Ordering - google's C++ style guide
http://stackoverflow.com/a/4438515/1162141 - discusses reasons behind the calling convention
http://www.swansontec.com/sregisters.html - tells what function each register is designed for
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

User avatar
Flash
Official Dog Handler
Posts: 13071
Joined: Wed 04 May 2005, 16:04
Location: Arizona USA

#2 Post by Flash »

Have you tried to tell Google about this?

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#3 Post by technosaurus »

I doubt it is something google would "fix". Once a large corporate entity has a code base as vast a theirs, you only get "bolt-on" fixes. It just goes to show that the old project management adage that "an hour spent in planning phase saves 10 in production" is applicable to software as well.

Most of the people at google who would have known better, were busy working on the Go language, which has its own design problems (I thought they had already figured out that register based calling conventions were superior to stack based calling conventions).
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

Post Reply