[PATCH] D52697: Bug 39129: Speeding up partition_point/lower_bound/upper_bound/ by using unsigned division by 2 when possible.

Denis Yaroshevskiy via Phabricator reviews at reviews.llvm.org
Mon Oct 1 11:34:17 PDT 2018


dyaroshev added inline comments.


================
Comment at: include/algorithm:3213
+            _Integral
+        >::type __size_t_if_safe;
+
----------------
mclow.lists wrote:
> mclow.lists wrote:
> > dyaroshev wrote:
> > > mclow.lists wrote:
> > > > Does `make_unsigned` do what you want here?
> > > I don't think so. Seems like size_t if faster than unsigned: http://quick-bench.com/hATsToKHx8UP3legquGgvT-4qpU
> > > (this is not only this benchmark, I've seen other cases when it happens.
> > I think we may be talking about different things.
> > 
> > I was talking about the template metafunction `std::make_unsigned`, which gives you an unsigned type with the same size as the parameter.
> > 
> > From your comment, I get the feeling you are talking about the literal type `unsigned`.
> > 
> If I change line 9 in your quickbench example to:
> 
>        using len_type = std::make_unsigned_t<typename std::iterator_traits<I>::difference_type>;
> 
> then the two chunks of code run at the same speed.
Sorry, wasn't clear enough.

Not all unsigned types are created equal: for int - unsigned type would unsigned(32 bit) not size_t - 64 bit. If you use size_t - it's faster, so if we would get int difference type - I'd still like to use size_t.

Realistically, the only difference_type we care about is std::ptrdiff_t, which is 64 bit, so either way the important case works. But, if this is really the only case we care about, we can just specialise for it.


https://reviews.llvm.org/D52697





More information about the libcxx-commits mailing list