Re: [PATCH] Add timegm POSIX call

Freddie Chopin <[email protected]>
Newsgroups gmane.comp.lib.newlib
Message-ID <[email protected]>
On Wed, 2018-08-15 at 21:18 +0200, Freddie Chopin wrote:
> On Wed, 2018-08-15 at 11:01 -0400, Craig Howland wrote:
> > > +/* returns either 0 or 1 */
> > > +static
> > > +int
> > > +__is_leap_year (int year)
> > > +{
> > > +  return (year % 4) == 0 && ((year % 100) != 0 || (((year / 100)
> > > &
> > > 3)
> > > == (-(YEAR_BASE / 100)  & 3)));
> > 
> > How about "(year & 3) == 0" instead of the % to save time? (Should
> > not matter 
> > with a good optimizer, but it is not necessarily on.)
> 
> On the other hand % is exactly 1:1 with the intent, while binary
> operations are not.
> 
> godbolt suggests that for x86-64 "(x % 4) == 0" and "(x & 3) == 0"
> give
> exactly the same code (binary operations) when optimization is
> explicitly _disabled_ (-O0).

Same for arm-none-eabi (previously I could not find the right subpage
where arm-none-eabi) was available.

https://godbolt.org/g/MYFCkb

Regards,
FCh
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.