hi. I'm trying to force inline with codegenDec but couldn't get it to work. I have below code. Key is used as Table key.
proc `==`*(a, b: Key): bool {.codegenDecl: "__attribute__((always_inline)) $# $#$#".} =
cast[int64](a) == cast[int64](b)
When I compile and run it I'm getting error:
/home/vagrant/.cache/nim/fibonacci_r/@m..@s..@s..@shome@[email protected]@[email protected]@slib@spure@[email protected]:343:41: error: inlining failed in call to always_inline ‘eqeq___OOZgeneZtypes_u597’: function body not available
__attribute__((always_inline)) NIM_BOOL eqeq___OOZgeneZtypes_u597(NI64 a_p0, NI64 b_p1);
$ gcc -v
...
gcc version 7.5.0 (Ubuntu 7.5.0-3ubuntu1~18.04)
It seems the generated code doesn't include the function body. What am I miss here?template `==`*(a, b: Key): bool =
cast[int64](a) == cast[int64](b)
Nim's operators are just function calls and they resolve just like everything else by types. Nim templates always force things inline, unlike the C compiler which can decide to inline or not even after all of the markings you've added. This gives you full control, but it can also make your code slower by excessively templating things.
Thanks for the input. My fibonacci implementation is not Nim proc. It's in my pet language and interpreted by a Nim VM. Inline won't be a problem I think.
I am using recursive Fibonacci to benchmark my code. However, I don't know which other language I can compare with. Even Ruby implementation is much faster than mine, probably because it's caching intermediate results. So it's not an apple to apple comparison.