3
votes

I have a CRC calculation function which gets called with extremely high frequency. I have already declared as inline i tried making it a __attribute((hot))__ but i am not sure if that buys anything. I am thinking about making it a fastcall.

According to gcc docs ,

fastcall On the Intel 386, the fastcall attribute causes the compiler to pass the first argument (if of integral type) in the register ECX and the second argument (if of integral type) in the register EDX. Subsequent and other typed arguments are passed on the stack. The called function will pop the arguments off the stack. If the number of arguments is variable all arguments are pushed on the stack.

fastcall would make it essentially faster because input params would be sent through registers instead of pushing them on to the stack. with inline, compiler would replace the function call with the body of the function .

So question is does fastcall when used with inline even make sense ?

1
For doing CRCs, I would expect the function call overhead to be extremely small compared to the actual work inside the function to do the CRC (unless you are calculating over extremely short buffers on the order of a few bytes). I would assume you're using a table lookup algorithm. Optimizing the insides of the loop would pay off much more than inlining. - TJD
i am using FNV-1a which a good CRC. i wanted to optimize it further to squeeze out CPU cycles. - Jay D
FNV is not a CRC, rather a hash that can be used for similar purposes. FNV is fast and simple, but I'd still guess that you will get negligible speedup from inlining unless your average buffer length is extremely small. - TJD
i am using FNV as a CRC and it solves my purpose. - Jay D

1 Answers

3
votes

If you make your function inline, the compiler will simply "paste" it wherever you write it, as you've said.

Therefore, nothing will get called, and so using fastcall would be pointless.