Re: [eigen] Eigen containers cannot be vectorized

[ Thread Index | Date Index | More Archives ]

2016-12-08 9:27 GMT-05:00 Francois Fayard <fayard@xxxxxxxxxxxxx>:

On 2016-12-08 15:03, Francois Fayard wrote:
I was also surprised to see that in debug mode, bounds checking is done with: assert(i >=0 && i < n). This can be optimized into assert(static_cast<std::size_t>(i) < static_cast<std::size_t>(n)).

I would be surprised if any reasonably good compiler fails to see that optimization. I did not check though, and I guess it should not matter, since one should have disabled assertions if one really needs the last bit of performance (of course, only after making sure that everything works)

No compiler cannot do that as the optimization from the first _expression_ to the second one is only valid when n is nonnegative.

The point of these range checks is to be safe and readable. They will be very high-overhead anyway. When the overhead matters, the way is to avoid doing range-checks, not micro-optimizing them. Eigen does that by having internal coefficient accessors that bypass range checks, so that most accesses performed internally by Eigen are free of any such overhead (except in unit tests, where range checks are enabled also for these internal accessors).

François Fayard
Founder & Consultant - Inside Loop
Applied Mathematics & High Performance Computing
Tel: +33 (0)6 01 44 06 93

Mail converted by MHonArc 2.6.19+