From: jonghwa3.lee@samsung.com
To: Venu Byravarasu <vbyravarasu@nvidia.com>
Cc: Alessandro Zummo <a.zummo@towertech.it>,
Andrew Morton <akpm@linux-foundation.org>,
"rtc-linux@googlegroups.com" <rtc-linux@googlegroups.com>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] rtc: Modify leap year test for more simpler way
Date: Wed, 06 Feb 2013 21:53:14 +0900 [thread overview]
Message-ID: <5112523A.10302@samsung.com> (raw)
In-Reply-To: <51124FF2.2070605@samsung.com>
On 2013년 02월 06일 20:42, Venu Byravarasu wrote:
> By definition, leap year is one, which is a divisible by 4 & 400, excluding multiples of 100s.
> Hence I feel this patch is not correct.
No, I think you might misunderstood the it's meaning. The former code checks
whether if it is multiple of 4 or not. Formal mathematical way to verify multiple of 4
is just checks the last two digits are multiple of 4. This '(!year % 4) && (year % 100)'
part does it. But with only that checking, it may miss the case of multiple of 400 which
is also multiple of 4. That's why '!(year % 400)' part was needed.
Then my modification checks in hexadecimal, whether if number has any of 1st and 2nd bit
with value 1. Because any number which has all bits above the 3rd can be divided with 4(2^2).
(e.g. 44(0b101100) = 2^5+2^3+2^2 = 2^2(2^3 + 2 + 1)) So It does same things with
less instructions.
Thanks,
Jonghwa
> Thanks,
> Venu
>
>
>> -----Original Message-----
>> From: linux-kernel-owner@vger.kernel.org [mailto:linux-kernel-
>> owner@vger.kernel.org] On Behalf Of Jonghwa Lee
>> Sent: Wednesday, February 06, 2013 4:53 PM
>> To: linux-kernel@vger.kernel.org
>> Cc: a.zummo@towertech.it; Andrew Morton; rtc-linux@googlegroups.com;
>> Jonghwa Lee
>> Subject: [PATCH] rtc: Modify leap year test for more simpler way
>>
>> Leap year which is multiple of 4, just needed 2 LSB for verifying.
>> A year with zero for all thease two bits means that it is leap year.
>>
>> Signed-off-by: Jonghwa Lee <jonghwa3.lee@samsung.com>
>> ---
>> include/linux/rtc.h | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/include/linux/rtc.h b/include/linux/rtc.h
>> index 9531845..d662b8d 100644
>> --- a/include/linux/rtc.h
>> +++ b/include/linux/rtc.h
>> @@ -181,7 +181,7 @@ void rtc_timer_do_work(struct work_struct *work);
>>
>> static inline bool is_leap_year(unsigned int year)
>> {
>> - return (!(year % 4) && (year % 100)) || !(year % 400);
>> + return !(year & 0x3);
>> }
>>
>> #ifdef CONFIG_RTC_HCTOSYS_DEVICE
>> --
>> 1.7.9.5
>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at http://vger.kernel.org/majordomo-info.html
>> Please read the FAQ at http://www.tux.org/lkml/
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
>
next prev parent reply other threads:[~2013-02-06 12:53 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-02-06 11:22 [PATCH] rtc: Modify leap year test for more simpler way Jonghwa Lee
2013-02-06 11:42 ` Venu Byravarasu
2013-02-06 12:43 ` jonghwa3.lee
2013-02-06 12:53 ` jonghwa3.lee [this message]
2013-02-06 13:00 ` Haojian Zhuang
2013-02-06 18:11 ` Stephen Warren
2013-02-07 1:15 ` jonghwa3.lee
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5112523A.10302@samsung.com \
--to=jonghwa3.lee@samsung.com \
--cc=a.zummo@towertech.it \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rtc-linux@googlegroups.com \
--cc=vbyravarasu@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox