Hello
I noticed that compiling fails (Nim 1.06) with `{.passC: "-Werror -pedantic".}`
i.e. when I follow my C habit to be stringent with code and ask gcc to treat
warnings as errors also in the Nim generated code. It seems the culprit is
stdlib_system.nim.c.
Error 1 `error: ISO C forbids conversion of object pointer to function pointer
type [-Werror=pedantic] ((Finalizer) ((*t).finalizer))(T5_);`
Error 2 `In function ‘sysFatal__... error: ‘noreturn’ function does return`
Error 3 same as 2 but another `sysFatal__...` where '...' stands for what looks
like a hash
The other problem (mine) is about wrapping some C code.
Situation: I've written a Nim wrapper for (yet another) fast but good quality
(non-cs) random generator. When running the C test version I achieve
(-march=x86-64 -mtune=nehalem on a Zen1 Ryzen) a bit above 3 GB of random bytes
per second. When running test nim (using my wrapper) it's about 1 GB/s slower.
Losing about 30% performance is of course not something that makes me happy.
My suspicion is that it's my mistake and that NIM copies the state object
and/or the result array on each call.
Explanation: I have to pass in a state object which is but two uint32 arrays.
type PState* = ref object
x: array[8, uint32]
y: array[4, uint32]
Run
in my prng_wrap.nim along with type `PResult* = array[32, uint8]` and `proc
prand(s: PState) : ptr byte {.importc.} ## The C core proc` Note: My wrapper
calling this proc `prand` casts the result to PResult (`return
cast[PResult](s.x)`)
Which I create in test.nim `var ps = new(PState)` and (var) `pr: PResult` and
then call `pr = prand(ps)` 32 million times (exactly as I do in the C version)
it works fine but is about 30% slower.
Now a) I'm confident that Nim's overhead is far less than 30% and b) I have
been forced to work in C and Ada for some months and certainly forgot some of
the finer points in dealing with and passing pointers (and refs), so I guess
it's _my_ fault. Any idea _where_ my mistake is and how to bring the Nim
version to something like 95+% of the C version speed?
Thanks in advance (oh, and congrats and thanks a ton and another ton for Nim
1.x! I'm immensely pleased by that)