Re: RFR: 8319423: Improve Year.isLeap by checking divisibility by 16

2023-11-09 Thread Claes Redestad
On Wed, 8 Nov 2023 16:51:48 GMT, Lothar Kimmeringer wrote: > return (year & 3) == 0 && (year & 15 == 0 || year % 100 != 0); I tried this and many other variants but the one in this PR came out on top - and it even seemed the additional redundancy helped the JIT. This might be due a deficiency

Re: RFR: 8319423: Improve Year.isLeap by checking divisibility by 16 [v2]

2023-11-06 Thread Roger Riggs
On Mon, 6 Nov 2023 00:50:22 GMT, Claes Redestad wrote: > I suggest we go ahead and integrate this, file an RFE to re-examine the > division-by-constant in C2, then re-evaluate these `isLeapYear` micros in > that new environment. These are good improvements and are beneficial with or without ot

Re: RFR: 8319423: Improve Year.isLeap by checking divisibility by 16 [v2]

2023-11-06 Thread Roger Riggs
On Fri, 3 Nov 2023 23:22:27 GMT, Claes Redestad wrote: >> https://github.com/cassioneri/eaf suggest this code for leap year >> calculation: >> >> public static boolean isLeap(long year) { >> int d = year % 100 != 0 ? 4 : 16; >> return (year & (d - 1)) == 0; >> } >> >> .

Re: RFR: 8319423: Improve Year.isLeap by checking divisibility by 16 [v2]

2023-11-06 Thread Claes Redestad
On Fri, 3 Nov 2023 23:22:27 GMT, Claes Redestad wrote: >> https://github.com/cassioneri/eaf suggest this code for leap year >> calculation: >> >> public static boolean isLeap(long year) { >> int d = year % 100 != 0 ? 4 : 16; >> return (year & (d - 1)) == 0; >> } >> >> .

Re: RFR: 8319423: Improve Year.isLeap by checking divisibility by 16 [v2]

2023-11-06 Thread Claes Redestad
On Mon, 6 Nov 2023 02:34:21 GMT, Quan Anh Mai wrote: > > > > I have filed > [JDK-8319451](https://bugs.openjdk.org/projects/JDK/issues/JDK-8319451). I > would suggest waiting for this bug to be resolved before proceeding with this > PR. Nice analysis! While I'm sure we need to re-evaluate

Re: RFR: 8319423: Improve Year.isLeap by checking divisibility by 16 [v2]

2023-11-05 Thread Quan Anh Mai
On Fri, 3 Nov 2023 23:22:27 GMT, Claes Redestad wrote: >> https://github.com/cassioneri/eaf suggest this code for leap year >> calculation: >> >> public static boolean isLeap(long year) { >> int d = year % 100 != 0 ? 4 : 16; >> return (year & (d - 1)) == 0; >> } >> >> .

Re: RFR: 8319423: Improve Year.isLeap by checking divisibility by 16 [v2]

2023-11-05 Thread Claes Redestad
On Fri, 3 Nov 2023 23:22:27 GMT, Claes Redestad wrote: >> https://github.com/cassioneri/eaf suggest this code for leap year >> calculation: >> >> public static boolean isLeap(long year) { >> int d = year % 100 != 0 ? 4 : 16; >> return (year & (d - 1)) == 0; >> } >> >> .

Re: RFR: 8319423: Improve Year.isLeap by checking divisibility by 16 [v2]

2023-11-05 Thread Cassio Neri
On Sun, 5 Nov 2023 22:14:50 GMT, Claes Redestad wrote: >> Thanks for your interest in my work. I'd love to assist porting our >> algorithms to Java. Notice, however, that I'm not a Java programmer and I >> don't have the complete picture of what goes on in the JVM. What follows is >> based on

Re: RFR: 8319423: Improve Year.isLeap by checking divisibility by 16 [v2]

2023-11-05 Thread Claes Redestad
On Sat, 4 Nov 2023 20:12:58 GMT, Cassio Neri wrote: >> Claes Redestad has updated the pull request incrementally with one >> additional commit since the last revision: >> >> Apply similar optimization to GregorianCalendar, sun.util.calendar > > Thanks for your interest in my work. I'd love to

Re: RFR: 8319423: Improve Year.isLeap by checking divisibility by 16 [v2]

2023-11-04 Thread Cassio Neri
On Fri, 3 Nov 2023 23:22:27 GMT, Claes Redestad wrote: >> https://github.com/cassioneri/eaf suggest this code for leap year >> calculation: >> >> public static boolean isLeap(long year) { >> int d = year % 100 != 0 ? 4 : 16; >> return (year & (d - 1)) == 0; >> } >> >> .

Re: RFR: 8319423: Improve Year.isLeap by checking divisibility by 16 [v2]

2023-11-04 Thread Cassio Neri
On Sat, 4 Nov 2023 16:01:44 GMT, Claes Redestad wrote: >> src/java.base/share/classes/java/time/Year.java line 321: >> >>> 319: // So for a year that's divisible by 4, checking that it's >>> also divisible by 16 >>> 320: // is sufficient to determine it must be a leap year. >>>

Re: RFR: 8319423: Improve Year.isLeap by checking divisibility by 16 [v2]

2023-11-04 Thread Cassio Neri
On Fri, 3 Nov 2023 23:22:27 GMT, Claes Redestad wrote: >> https://github.com/cassioneri/eaf suggest this code for leap year >> calculation: >> >> public static boolean isLeap(long year) { >> int d = year % 100 != 0 ? 4 : 16; >> return (year & (d - 1)) == 0; >> } >> >> .

Re: RFR: 8319423: Improve Year.isLeap by checking divisibility by 16 [v2]

2023-11-04 Thread Claes Redestad
On Sat, 4 Nov 2023 04:57:11 GMT, Quan Anh Mai wrote: >> Claes Redestad has updated the pull request incrementally with one >> additional commit since the last revision: >> >> Apply similar optimization to GregorianCalendar, sun.util.calendar > > src/java.base/share/classes/java/time/Year.java

Re: RFR: 8319423: Improve Year.isLeap by checking divisibility by 16 [v2]

2023-11-03 Thread Quan Anh Mai
On Fri, 3 Nov 2023 23:22:27 GMT, Claes Redestad wrote: >> https://github.com/cassioneri/eaf suggest this code for leap year >> calculation: >> >> public static boolean isLeap(long year) { >> int d = year % 100 != 0 ? 4 : 16; >> return (year & (d - 1)) == 0; >> } >> >> .

Re: RFR: 8319423: Improve Year.isLeap by checking divisibility by 16 [v2]

2023-11-03 Thread Quan Anh Mai
On Fri, 3 Nov 2023 23:22:27 GMT, Claes Redestad wrote: >> https://github.com/cassioneri/eaf suggest this code for leap year >> calculation: >> >> public static boolean isLeap(long year) { >> int d = year % 100 != 0 ? 4 : 16; >> return (year & (d - 1)) == 0; >> } >> >> .

Re: RFR: 8319423: Improve Year.isLeap by checking divisibility by 16

2023-11-03 Thread Andriy Plokhotnyuk
On Fri, 3 Nov 2023 23:34:49 GMT, Claes Redestad wrote: > > @cl4es Could you please test > > [this](https://github.com/plokhotnyuk/jsoniter-scala/blob/ba6f4f80deaf0e7a1a95787321de3cc2a232d66d/jsoniter-scala-core/jvm/src/main/scala/com/github/plokhotnyuk/jsoniter_scala/core/JsonReader.scala#L3687)

Re: RFR: 8319423: Improve Year.isLeap by checking divisibility by 16

2023-11-03 Thread Claes Redestad
On Fri, 3 Nov 2023 22:37:40 GMT, Andriy Plokhotnyuk wrote: > @cl4es Could you please test > [this](https://github.com/plokhotnyuk/jsoniter-scala/blob/ba6f4f80deaf0e7a1a95787321de3cc2a232d66d/jsoniter-scala-core/jvm/src/main/scala/com/github/plokhotnyuk/jsoniter_scala/core/JsonReader.scala#L3687)

Re: RFR: 8319423: Improve Year.isLeap by checking divisibility by 16 [v2]

2023-11-03 Thread Claes Redestad
> https://github.com/cassioneri/eaf suggest this code for leap year calculation: > > public static boolean isLeap(long year) { > int d = year % 100 != 0 ? 4 : 16; > return (year & (d - 1)) == 0; > } > > .. with a claim this would compile down to branchless, easily pipeline

Re: RFR: 8319423: Improve Year.isLeap by checking divisibility by 16

2023-11-03 Thread Andriy Plokhotnyuk
On Fri, 3 Nov 2023 12:03:24 GMT, Claes Redestad wrote: > https://github.com/cassioneri/eaf suggest this code for leap year calculation: > > public static boolean isLeap(long year) { > int d = year % 100 != 0 ? 4 : 16; > return (year & (d - 1)) == 0; > } > > .. with a cla

Re: RFR: 8319423: Improve Year.isLeap by checking divisibility by 16

2023-11-03 Thread Naoto Sato
On Fri, 3 Nov 2023 12:03:24 GMT, Claes Redestad wrote: > https://github.com/cassioneri/eaf suggest this code for leap year calculation: > > public static boolean isLeap(long year) { > int d = year % 100 != 0 ? 4 : 16; > return (year & (d - 1)) == 0; > } > > .. with a cla

Re: RFR: 8319423: Improve Year.isLeap by checking divisibility by 16

2023-11-03 Thread Roger Riggs
On Fri, 3 Nov 2023 12:03:24 GMT, Claes Redestad wrote: > https://github.com/cassioneri/eaf suggest this code for leap year calculation: > > public static boolean isLeap(long year) { > int d = year % 100 != 0 ? 4 : 16; > return (year & (d - 1)) == 0; > } > > .. with a cla