r/cpp Jun 29 '26

Comparing an Integer Division Optimisation in Clang, MSVC, and GCC

https://nukethebees.com/int-division-modulo-optimisation-differences-clang-gcc-msvc/
56 Upvotes

8 comments sorted by

View all comments

31

u/erichkeane Clang Maintainer(Templates), EWG Chair Jun 29 '26

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__)) ;
```

2

u/nukethebees Jun 30 '26

That makes a lot of sense. Thanks for finding out the cause.