lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

Petri Häkkinen wrote:
> > Assuming 3d vectors throughout this would give an allocation size
> > of 8+3*sizeof(double) = 32 bytes for the FFI cdata.
> How about using 32-bit floats instead with FFI? Float precision is enough
> for games and most game engines use them for better cache utilization.

Maybe for permanent storage. But I doubt this is a win for
temporaries: they really ought to be kept in registers by the
JIT compiler.

> Question: how would vector component indexing work with FFI? If I have a
> C-type "struct { float x, y, z; }" will "v.x" work in Lua?

That's the exact syntax.

> I guess that would automatically convert from float to double?

Yes, and that's the downside: the conversion ops add 2 or 4 cycles
of latency. It would be quite difficult to force pure float/float
ops everywhere (would imply boxing/unboxing even float scalars).

But I'd suggest to benchmark it when everything is ready. I'm not
sure about the tradeoff between conversion overhead vs. memory
bandwidth in this case.