[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-id: <51124FF2.2070605@samsung.com>
Date: Wed, 06 Feb 2013 21:43:30 +0900
From: jonghwa3.lee@...sung.com
To: Venu Byravarasu <vbyravarasu@...dia.com>
Cc: Jonghwa Lee <jonghwa3.lee@...sung.com>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
"a.zummo@...ertech.it" <a.zummo@...ertech.it>,
Andrew Morton <akpm@...ux-foundation.org>,
"rtc-linux@...glegroups.com" <rtc-linux@...glegroups.com>
Subject: Re: [PATCH] rtc: Modify leap year test for more simpler way
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. 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,
> Venu
>
>
>> -----Original Message-----
>> From: linux-kernel-owner@...r.kernel.org [mailto:linux-kernel-
>> owner@...r.kernel.org] On Behalf Of Jonghwa Lee
>> Sent: Wednesday, February 06, 2013 4:53 PM
>> To: linux-kernel@...r.kernel.org
>> Cc: a.zummo@...ertech.it; Andrew Morton; rtc-linux@...glegroups.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@...sung.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@...r.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@...r.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@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists