Make more constexpr

This commit is contained in:
apio 2022-12-05 16:43:52 +01:00
parent 2eaa458555
commit 762131a425
Signed by: apio
GPG Key ID: B8A7D06E42258954

View File

@ -6,23 +6,22 @@
static u64 timer_ticks = 0;
static u64 boot_timestamp;
static int isleap(int year)
static inline constexpr int isleap(int year)
{
return year % 4 == 0 && (year % 100 != 0 || year % 400 == 0);
}
static int make_yday(int year, int month)
static constexpr int make_yday(int year, int month)
{
static const short int upto[12] = {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334};
int yd;
constexpr short int upto[12] = {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334};
yd = upto[month - 1];
int yd = upto[month - 1];
if (month > 2 && isleap(year)) yd++;
return yd;
}
// https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html#tag_04_16
static u64 broken_down_to_unix(u64 year, u64 yday, u64 hour, u64 min, u64 sec)
static constexpr u64 broken_down_to_unix(u64 year, u64 yday, u64 hour, u64 min, u64 sec)
{
return sec + min * 60 + hour * 3600 + yday * 86400 + (year - 70) * 31536000 + ((year - 69) / 4) * 86400 -
((year - 1) / 100) * 86400 + ((year + 299) / 400) * 86400;