lua-users home
lua-l archive

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


KR wrote:
> For some reason there is a very minor difference (even with bounds checking
> disabled) between the vector class and the C-style equivalent which is not
> present in the matrix case. It's very minor but I am curious about it, maybe I
> made a stupid mistake :)

The offset calculation and the multiplication with the stride
cannot be hoisted. And they are performed as FP calculations and
need to be converted back to integers. That's rather expensive.

I question the wisdom in adding this overhead to a standard vector
class. I suggest to create a separate class for these use cases.
Similarly, you can remove the dispatch overhead related to the
bounds-checks by creating a subclass. Yes, the dispatch check can
be hoisted in this case, but separation of concerns is valuable
nonetheless.

> At the moment, the only issue is that I cannot enable bound checks on the column
> index in
> m[row][col]
> as this would require having
> m[i]
> be defined (for numeric types) as
> m:row(i)
> At the moment the (temporary) vector view that is created is not optimized away. 
> It is my understanding that there is a plan to implement this kind of
> optimizations in LuaJIT in the future. Or is the struct object vecview_t too
> complex to be optimized away in any case?

Maybe it will be eliminated, maybe not. Depends on the exact
usage. You could selectively enable the views only for the
bounds-checking subclass.

--Mike