Re: [PATCH] libstdc++: More efficient std::chrono::year::leap.

2021-06-24 Thread Cassio Neri via Gcc-patches
Thanks Jonathan. Here are some benchmarks (assembly in [1]): https://quick-bench.com/q/jclBXmi4QLDcRMLuuVpxTUsFmQw Unfortunately, quick-bench times out unless some implementations are commented out. You can copy the code and run it locally (needs google benchmark) to get the full picture. I real

Re: [PATCH] libstdc++: More efficient std::chrono::year::leap.

2021-05-21 Thread Cassio Neri via Gcc-patches
mp; _M_y % 4 == 0; } explicit constexpr On Fri, May 21, 2021 at 7:05 PM Koning, Paul wrote: > > > > > On May 21, 2021, at 1:46 PM, Cassio Neri via Gcc-patches > > wrote: > > > > Simple change to std::chrono::year::is_leap. If a year is multiple of

[PATCH] libstdc++: More efficient std::chrono::year::leap.

2021-05-21 Thread Cassio Neri via Gcc-patches
Simple change to std::chrono::year::is_leap. If a year is multiple of 100, then it's divisible by 400 if and only if it's divisible by 16. The latter allows for better code generation. Tested on x86_64-pc-linux-gnu. libstdc++-v3/ChangeLog: * include/std/chrono: diff --git a/libstdc++-v3/include

Re: [PATCH 1/4] libstdc++: More efficient date from days.

2021-02-25 Thread Cassio Neri via Gcc-patches
Hi Jonathan, The issue is that I didn't cast __dp.count() to uint32_t: - const auto __r0 = __dp.count() + __r2_e3; + const auto __r0 = static_cast(__dp.count()) + __r2_e3; The above would be a better fix. Indeed, __r0 belongs to [0, 2^32[ which allows all arithmetics that follow to be

[PATCH 4/4] libstdc++: More efficient last day of month.

2021-02-23 Thread Cassio Neri via Gcc-patches
This patch reimplements std::chrono::year_month_day_last:day() which yields the last day of a particular month. The current implementation uses a look-up table implemented as an unsigned[12] array. The new implementation instead is based on the fact that a month m in [1, 12], except for m == 2 (F

[PATCH 3/4] libstdc++: More efficient is_leap.

2021-02-23 Thread Cassio Neri via Gcc-patches
This patch reimplements std::chrono::year::is_leap(). Leap year check is ubiquitously implemented (including here) as: y % 4 == 0 && (y % 100 != 0 || y % 400 == 0). The rationale being that testing divisibility by 4 first implies an earlier return for 75% of the cases, therefore, avoiding th

[PATCH 2/4] libstdc++: More efficient days from date.

2021-02-23 Thread Cassio Neri via Gcc-patches
This patch reimplements std::chrono::year_month_day::_M_days_since_epoch() which calculates the number of elapsed days since 1970/01/01. The new implementation is based on Proposition 6.2 of Neri and Schneider, "Euclidean Affine Functions and Applications to Calendar Algorithms" available at https

[PATCH 1/4] libstdc++: More efficient date from days.

2021-02-23 Thread Cassio Neri via Gcc-patches
This patch reimplements std::chrono::year_month_day::_S_from_days() which retrieves a date from the number of elapsed days since 1970/01/01. The new implementation is based on Proposition 6.3 of Neri and Schneider, "Euclidean Affine Functions and Applications to Calendar Algorithms" available at h