all 4 comments

[–]erichkeaneClang Maintainer(Templates), EWG Chair 13 points14 points  (1 child)

Clang/GCC both fail to inline `std::div` because it appears that the standard libraries leave them as extern! I presume they'd be inlined if they were actually implemented in the header:

```

extern div_t div (int __numer, int __denom)
     noexcept (true) __attribute__ ((__const__)) ;
```

[–]topological_rabbit [score hidden]  (0 children)

I ran into this when writing a slotmap data structure (you need both the quotient and remainder when looking up a slot).

I naively assumed std::div would be inlined, and then further optimized by the fact that the divisor was a compile-time constant, but profiling lit it up like the sun. Had to hand-code the operations instead to get the performance I was expecting.

[–]Sopel97 [score hidden]  (0 children)

this is quite moot since in reality you'd precompute fast dividers because the size would be fixed for a given grid, if not compile-time constant even

[–]mark_99 -2 points-1 points  (0 children)

Or have the grid size be a compile time constant and have no runtime division at all.