3

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 ?

Jay D
  • 3,263
  • 4
  • 32
  • 48
  • 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 Jul 05 '12 at 22:13
  • i am using FNV-1a which a good CRC. i wanted to optimize it further to squeeze out CPU cycles. – Jay D Jul 05 '12 at 22:15
  • 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 Jul 05 '12 at 22:22
  • i am using FNV as a CRC and it solves my purpose. – Jay D Jul 05 '12 at 23:06

1 Answers1

3

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.

houbysoft
  • 32,532
  • 24
  • 103
  • 156
  • 3
    Perhaps setting the call convention to `fastcall` can get you covered in case the compiler do not inline the function. – Gigi Jul 05 '12 at 23:15
  • 1
    This is not strictly true. Inline is a compiler suggestion. Per the standard, the compiler has no responsibility to actually inline the function. Thus, an inline'd function still requires a calling convention. – 8bitwide Sep 20 '13 at 20:02