* time.c: rename small integer specialization related identifiers.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27073 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2010-03-28 00:54:29 +00:00
parent 86aa8f3f0f
commit c08277c62d
2 changed files with 164 additions and 160 deletions

View File

@ -1,3 +1,7 @@
Sun Mar 28 09:53:02 2010 Tanaka Akira <akr@fsij.org>
* time.c: rename small integer specialization related identifiers.
Sun Mar 28 08:20:37 2010 Tanaka Akira <akr@fsij.org> Sun Mar 28 08:20:37 2010 Tanaka Akira <akr@fsij.org>
* time.c (weq): specialize for small integer. * time.c (weq): specialize for small integer.
@ -17,7 +21,7 @@ Sun Mar 28 07:12:41 2010 Tanaka Akira <akr@fsij.org>
Sun Mar 28 02:14:13 2010 Tanaka Akira <akr@fsij.org> Sun Mar 28 02:14:13 2010 Tanaka Akira <akr@fsij.org>
* time.c: fix previos commit. * time.c: fix previous commit.
Sat Mar 27 23:17:52 2010 Tanaka Akira <akr@fsij.org> Sat Mar 27 23:17:52 2010 Tanaka Akira <akr@fsij.org>
@ -101,7 +105,7 @@ Thu Mar 25 12:37:37 2010 Kazuhiro NISHIYAMA <zn@mbf.nifty.com>
Thu Mar 25 11:34:00 2010 Kenta Murata <mrkn@mrkn.jp> Thu Mar 25 11:34:00 2010 Kenta Murata <mrkn@mrkn.jp>
* bignum.c, node.h, strftime.c, enc/trans/utf8_mac.trans: * bignum.c, node.h, strftime.c, enc/trans/utf8_mac.trans:
added explicit casts for supplessing warnings. added explicit casts for suppressing warnings.
Thu Mar 25 11:34:00 2010 Kenta Murata <mrkn@mrkn.jp> Thu Mar 25 11:34:00 2010 Kenta Murata <mrkn@mrkn.jp>

316
time.c
View File

@ -57,73 +57,73 @@ typedef unsigned LONG_LONG unsigned_time_t;
#define TIMET_MIN (~(time_t)0 <= 0 ? (time_t)(((unsigned_time_t)1) << (sizeof(time_t) * CHAR_BIT - 1)) : (time_t)0) #define TIMET_MIN (~(time_t)0 <= 0 ? (time_t)(((unsigned_time_t)1) << (sizeof(time_t) * CHAR_BIT - 1)) : (time_t)0)
#if defined(HAVE_UINT64_T) && SIZEOF_VALUE < SIZEOF_UINT64_T #if defined(HAVE_UINT64_T) && SIZEOF_VALUE < SIZEOF_UINT64_T
#define TIMEVALUE_IS_UINT64 1 #define WIDEINT_IS_UINT64 1
#define FIXTV_P(tv) ((tv) & 1) #define FIXWV_P(tv) ((tv) & 1)
#define FIXTVtoINT64(tv) RSHIFT((SIGNED_TIMEVALUE)(tv), 1) #define FIXWVtoINT64(tv) RSHIFT((SIGNED_WIDEINT)(tv), 1)
#define INT64toFIXTV(i64) ((TIMEVALUE)((SIGNED_TIMEVALUE)(i64) << 1 | FIXNUM_FLAG)) #define INT64toFIXWV(i64) ((WIDEINT)((SIGNED_WIDEINT)(i64) << 1 | FIXNUM_FLAG))
#define FIXTV_MAX (((int64_t)1 << 62) - 1) #define FIXWV_MAX (((int64_t)1 << 62) - 1)
#define FIXTV_MIN (-((int64_t)1 << 62)) #define FIXWV_MIN (-((int64_t)1 << 62))
#define POSFIXTVABLE(i64) ((i64) < FIXTV_MAX+1) #define POSFIXWVABLE(i64) ((i64) < FIXWV_MAX+1)
#define NEGFIXTVABLE(i64) ((i64) >= FIXTV_MIN) #define NEGFIXWVABLE(i64) ((i64) >= FIXWV_MIN)
#define FIXTVABLE(i64) (POSFIXTVABLE(i64) && NEGFIXTVABLE(i64)) #define FIXWVABLE(i64) (POSFIXWVABLE(i64) && NEGFIXWVABLE(i64))
typedef uint64_t TIMEVALUE; typedef uint64_t WIDEINT;
typedef int64_t SIGNED_TIMEVALUE; typedef int64_t SIGNED_WIDEINT;
#else #else
#define TIMEVALUE_IS_UINT64 0 #define WIDEINT_IS_UINT64 0
#define FIXTV_P(tv) FIXNUM_P(tv) #define FIXWV_P(tv) FIXNUM_P(tv)
typedef VALUE TIMEVALUE; typedef VALUE WIDEINT;
typedef SIGNED_VALUE SIGNED_TIMEVALUE; typedef SIGNED_VALUE SIGNED_WIDEINT;
#endif #endif
/* #define STRUCT_TIMEW */ /* #define STRUCT_WIDEVAL */
#ifdef STRUCT_TIMEW #ifdef STRUCT_WIDEVAL
/* for type checking */ /* for type checking */
typedef struct { typedef struct {
TIMEVALUE value; WIDEINT value;
} timew_t; } wideval_t;
#define TIMEW_GETVAL(w) ((w).value) #define WIDEVAL_GET(w) ((w).value)
#define TIMEW_SETVAL(w, v) ((w).value = (v)) #define WIDEVAL_SET(w, v) ((w).value = (v))
#else #else
typedef TIMEVALUE timew_t; typedef WIDEINT wideval_t;
#define TIMEW_GETVAL(w) (w) #define WIDEVAL_GET(w) (w)
#define TIMEW_SETVAL(w, v) ((w) = (v)) #define WIDEVAL_SET(w, v) ((w) = (v))
#endif #endif
static inline VALUE static inline VALUE
w2xv(timew_t w) w2xv(wideval_t w)
{ {
#if TIMEVALUE_IS_UINT64 #if WIDEINT_IS_UINT64
if (FIXTV_P(TIMEW_GETVAL(w))) if (FIXWV_P(WIDEVAL_GET(w)))
return INT64toNUM(FIXTVtoINT64(TIMEW_GETVAL(w))); return INT64toNUM(FIXWVtoINT64(WIDEVAL_GET(w)));
return (VALUE)TIMEW_GETVAL(w); return (VALUE)WIDEVAL_GET(w);
#else #else
return TIMEW_GETVAL(w); return WIDEVAL_GET(w);
#endif #endif
} }
static inline timew_t static inline wideval_t
xv2w(VALUE xv) { xv2w(VALUE xv) {
timew_t w; wideval_t w;
#if TIMEVALUE_IS_UINT64 #if WIDEINT_IS_UINT64
# if SIZEOF_UINT64_T % SIZEOF_BDIGITS != 0 # if SIZEOF_UINT64_T % SIZEOF_BDIGITS != 0
# error SIZEOF_UINT64 is not multiple of SIZEOF_BDIGITS # error SIZEOF_UINT64 is not multiple of SIZEOF_BDIGITS
# endif # endif
long len; long len;
BDIGIT *ds; BDIGIT *ds;
if (FIXNUM_P(xv)) { if (FIXNUM_P(xv)) {
TIMEW_SETVAL(w, (TIMEVALUE)(SIGNED_TIMEVALUE)(SIGNED_VALUE)xv); WIDEVAL_SET(w, (WIDEINT)(SIGNED_WIDEINT)(SIGNED_VALUE)xv);
return w; return w;
} }
else if (TYPE(xv) == T_BIGNUM && else if (TYPE(xv) == T_BIGNUM &&
(len = RBIGNUM_LEN(xv)) * sizeof(BDIGIT) <= sizeof(TIMEVALUE)) { (len = RBIGNUM_LEN(xv)) * sizeof(BDIGIT) <= sizeof(WIDEINT)) {
ds = RBIGNUM_DIGITS(xv); ds = RBIGNUM_DIGITS(xv);
TIMEW_SETVAL(w, xv); WIDEVAL_SET(w, xv);
if (RBIGNUM_POSITIVE_P(xv)) { if (RBIGNUM_POSITIVE_P(xv)) {
if (ds[len-1] < ((BDIGIT)1 << (sizeof(BDIGIT)*CHAR_BIT-2))) { if (ds[len-1] < ((BDIGIT)1 << (sizeof(BDIGIT)*CHAR_BIT-2))) {
int64_t i = 0; int64_t i = 0;
while (len) while (len)
i = (i << sizeof(BDIGIT)*CHAR_BIT) | ds[--len]; i = (i << sizeof(BDIGIT)*CHAR_BIT) | ds[--len];
if (FIXTVABLE(i)) if (FIXWVABLE(i))
TIMEW_SETVAL(w, INT64toFIXTV(i)); WIDEVAL_SET(w, INT64toFIXWV(i));
} }
} }
else { else {
@ -131,31 +131,31 @@ xv2w(VALUE xv) {
int64_t i = 0; int64_t i = 0;
while (len) while (len)
i = (i << sizeof(BDIGIT)*CHAR_BIT) | ds[--len]; i = (i << sizeof(BDIGIT)*CHAR_BIT) | ds[--len];
TIMEW_SETVAL(w, INT64toFIXTV(-i)); WIDEVAL_SET(w, INT64toFIXWV(-i));
} }
} }
return w; return w;
} }
#endif #endif
TIMEW_SETVAL(w, xv); WIDEVAL_SET(w, xv);
return w; return w;
} }
static timew_t rb_time_magnify(VALUE v); static wideval_t rb_time_magnify(VALUE v);
static timew_t static wideval_t
timet2timew(time_t t) timet2wideval(time_t t)
{ {
#if TIMEVALUE_IS_UINT64 #if WIDEINT_IS_UINT64
int64_t i64 = t; int64_t i64 = t;
timew_t w; wideval_t w;
if (-((-FIXTV_MIN)/TIME_SCALE) <= i64 && i64 <= FIXTV_MAX/TIME_SCALE) { if (-((-FIXWV_MIN)/TIME_SCALE) <= i64 && i64 <= FIXWV_MAX/TIME_SCALE) {
TIMEW_SETVAL(w, INT64toFIXTV(i64 * TIME_SCALE)); WIDEVAL_SET(w, INT64toFIXWV(i64 * TIME_SCALE));
return w; return w;
} }
#endif #endif
return rb_time_magnify(TIMET2NUM(t)); return rb_time_magnify(TIMET2NUM(t));
} }
#define TIMET2TIMEW(t) timet2timew(t) #define TIMET2WIDEVAL(t) timet2wideval(t)
VALUE rb_cTime; VALUE rb_cTime;
static VALUE time_utc_offset _((VALUE)); static VALUE time_utc_offset _((VALUE));
@ -175,7 +175,7 @@ static int tmcmp(struct tm *a, struct tm *b);
static int vtmcmp(struct vtm *a, struct vtm *b); static int vtmcmp(struct vtm *a, struct vtm *b);
static const char *find_time_t(struct tm *tptr, int utc_p, time_t *tp); static const char *find_time_t(struct tm *tptr, int utc_p, time_t *tp);
static struct vtm *localtimew(timew_t timew, struct vtm *result); static struct vtm *localtimew(wideval_t timew, struct vtm *result);
static int leap_year_p(long y); static int leap_year_p(long y);
#define leap_year_v_p(y) leap_year_p(NUM2LONG(mod(v, INT2FIX(400)))) #define leap_year_v_p(y) leap_year_p(NUM2LONG(mod(v, INT2FIX(400))))
@ -326,22 +326,22 @@ divmodv(VALUE n, VALUE d, VALUE *q, VALUE *r)
} }
static int static int
weq(timew_t wx, timew_t wy) weq(wideval_t wx, wideval_t wy)
{ {
#if TIMEVALUE_IS_UINT64 #if WIDEINT_IS_UINT64
if (FIXTV_P(TIMEW_GETVAL(wx)) && FIXTV_P(TIMEW_GETVAL(wy))) { if (FIXWV_P(WIDEVAL_GET(wx)) && FIXWV_P(WIDEVAL_GET(wy))) {
return FIXTVtoINT64(TIMEW_GETVAL(wx)) == FIXTVtoINT64(TIMEW_GETVAL(wy)); return FIXWVtoINT64(WIDEVAL_GET(wx)) == FIXWVtoINT64(WIDEVAL_GET(wy));
} }
#endif #endif
return RTEST(rb_funcall(w2xv(wx), id_eq, 1, w2xv(wy))); return RTEST(rb_funcall(w2xv(wx), id_eq, 1, w2xv(wy)));
} }
static int static int
wlt(timew_t wx, timew_t wy) wlt(wideval_t wx, wideval_t wy)
{ {
#if TIMEVALUE_IS_UINT64 #if WIDEINT_IS_UINT64
if (FIXTV_P(TIMEW_GETVAL(wx)) && FIXTV_P(TIMEW_GETVAL(wy))) { if (FIXWV_P(WIDEVAL_GET(wx)) && FIXWV_P(WIDEVAL_GET(wy))) {
return FIXTVtoINT64(TIMEW_GETVAL(wx)) < FIXTVtoINT64(TIMEW_GETVAL(wy)); return FIXWVtoINT64(WIDEVAL_GET(wx)) < FIXWVtoINT64(WIDEVAL_GET(wy));
} }
#endif #endif
return RTEST(rb_funcall(w2xv(wx), '<', 1, w2xv(wy))); return RTEST(rb_funcall(w2xv(wx), '<', 1, w2xv(wy)));
@ -352,16 +352,16 @@ wlt(timew_t wx, timew_t wy)
#define wle(x,y) (!wgt(x,y)) #define wle(x,y) (!wgt(x,y))
#define wge(x,y) (!wlt(x,y)) #define wge(x,y) (!wlt(x,y))
static timew_t static wideval_t
wadd(timew_t wx, timew_t wy) wadd(wideval_t wx, wideval_t wy)
{ {
VALUE x; VALUE x;
#if TIMEVALUE_IS_UINT64 #if WIDEINT_IS_UINT64
if (FIXTV_P(TIMEW_GETVAL(wx)) && FIXTV_P(TIMEW_GETVAL(wy))) { if (FIXWV_P(WIDEVAL_GET(wx)) && FIXWV_P(WIDEVAL_GET(wy))) {
int64_t r = FIXTVtoINT64(TIMEW_GETVAL(wx)) + FIXTVtoINT64(TIMEW_GETVAL(wy)); int64_t r = FIXWVtoINT64(WIDEVAL_GET(wx)) + FIXWVtoINT64(WIDEVAL_GET(wy));
if (FIXTVABLE(r)) { if (FIXWVABLE(r)) {
timew_t z; wideval_t z;
TIMEW_SETVAL(z, INT64toFIXTV(r)); WIDEVAL_SET(z, INT64toFIXWV(r));
return z; return z;
} }
return xv2w(INT64toNUM(r)); return xv2w(INT64toNUM(r));
@ -373,16 +373,16 @@ wadd(timew_t wx, timew_t wy)
return xv2w(rb_funcall(x, '+', 1, w2xv(wy))); return xv2w(rb_funcall(x, '+', 1, w2xv(wy)));
} }
static timew_t static wideval_t
wsub(timew_t wx, timew_t wy) wsub(wideval_t wx, wideval_t wy)
{ {
VALUE x; VALUE x;
#if TIMEVALUE_IS_UINT64 #if WIDEINT_IS_UINT64
if (FIXTV_P(TIMEW_GETVAL(wx)) && FIXTV_P(TIMEW_GETVAL(wy))) { if (FIXWV_P(WIDEVAL_GET(wx)) && FIXWV_P(WIDEVAL_GET(wy))) {
int64_t r = FIXTVtoINT64(TIMEW_GETVAL(wx)) - FIXTVtoINT64(TIMEW_GETVAL(wy)); int64_t r = FIXWVtoINT64(WIDEVAL_GET(wx)) - FIXWVtoINT64(WIDEVAL_GET(wy));
if (FIXTVABLE(r)) { if (FIXWVABLE(r)) {
timew_t z; wideval_t z;
TIMEW_SETVAL(z, INT64toFIXTV(r)); WIDEVAL_SET(z, INT64toFIXWV(r));
return z; return z;
} }
return xv2w(INT64toNUM(r)); return xv2w(INT64toNUM(r));
@ -395,20 +395,20 @@ wsub(timew_t wx, timew_t wy)
return xv2w(rb_funcall(x, '-', 1, w2xv(wy))); return xv2w(rb_funcall(x, '-', 1, w2xv(wy)));
} }
static timew_t static wideval_t
wmul(timew_t wx, timew_t wy) wmul(wideval_t wx, wideval_t wy)
{ {
VALUE x; VALUE x;
#if TIMEVALUE_IS_UINT64 #if WIDEINT_IS_UINT64
if (FIXTV_P(TIMEW_GETVAL(wx)) && FIXTV_P(TIMEW_GETVAL(wy))) { if (FIXWV_P(WIDEVAL_GET(wx)) && FIXWV_P(WIDEVAL_GET(wy))) {
int64_t a, b, c; int64_t a, b, c;
a = FIXTVtoINT64(TIMEW_GETVAL(wx)); a = FIXWVtoINT64(WIDEVAL_GET(wx));
if (a == 0) return wx; if (a == 0) return wx;
b = FIXTVtoINT64(TIMEW_GETVAL(wy)); b = FIXWVtoINT64(WIDEVAL_GET(wy));
c = a * b; c = a * b;
if (c / a == b && FIXTVABLE(c)) { if (c / a == b && FIXWVABLE(c)) {
timew_t z; wideval_t z;
TIMEW_SETVAL(z, INT64toFIXTV(c)); WIDEVAL_SET(z, INT64toFIXWV(c));
return z; return z;
} }
} }
@ -419,14 +419,14 @@ wmul(timew_t wx, timew_t wy)
} }
static int static int
wcmp(timew_t wx, timew_t wy) wcmp(wideval_t wx, wideval_t wy)
{ {
VALUE x, y; VALUE x, y;
#if TIMEVALUE_IS_UINT64 #if WIDEINT_IS_UINT64
if (FIXTV_P(TIMEW_GETVAL(wx)) && FIXTV_P(TIMEW_GETVAL(wy))) { if (FIXWV_P(WIDEVAL_GET(wx)) && FIXWV_P(WIDEVAL_GET(wy))) {
int64_t a, b; int64_t a, b;
a = FIXTVtoINT64(TIMEW_GETVAL(wx)); a = FIXWVtoINT64(WIDEVAL_GET(wx));
b = FIXTVtoINT64(TIMEW_GETVAL(wy)); b = FIXWVtoINT64(WIDEVAL_GET(wy));
if (a < b) if (a < b)
return -1; return -1;
if (a > b) if (a > b)
@ -439,23 +439,23 @@ wcmp(timew_t wx, timew_t wy)
return rb_cmpint(rb_funcall(x, id_cmp, 1, y), x, y); return rb_cmpint(rb_funcall(x, id_cmp, 1, y), x, y);
} }
static timew_t static wideval_t
wquo(timew_t wx, timew_t wy) wquo(wideval_t wx, wideval_t wy)
{ {
VALUE x, y, ret; VALUE x, y, ret;
#if TIMEVALUE_IS_UINT64 #if WIDEINT_IS_UINT64
if (FIXTV_P(TIMEW_GETVAL(wx)) && FIXTV_P(TIMEW_GETVAL(wy))) { if (FIXWV_P(WIDEVAL_GET(wx)) && FIXWV_P(WIDEVAL_GET(wy))) {
int64_t a, b, c; int64_t a, b, c;
a = FIXTVtoINT64(TIMEW_GETVAL(wx)); a = FIXWVtoINT64(WIDEVAL_GET(wx));
b = FIXTVtoINT64(TIMEW_GETVAL(wy)); b = FIXWVtoINT64(WIDEVAL_GET(wy));
if (b == 0) rb_num_zerodiv(); if (b == 0) rb_num_zerodiv();
c = a / b; c = a / b;
if (c * b == a) { if (c * b == a) {
timew_t z; wideval_t z;
if (FIXTVABLE(c)) if (FIXWVABLE(c))
TIMEW_SETVAL(z, INT64toFIXTV(c)); WIDEVAL_SET(z, INT64toFIXWV(c));
else else
TIMEW_SETVAL(z, INT64toNUM(c)); WIDEVAL_SET(z, INT64toNUM(c));
return z; return z;
} }
} }
@ -470,36 +470,36 @@ wquo(timew_t wx, timew_t wy)
return xv2w(ret); return xv2w(ret);
} }
#define wmulquo(x,y,z) ((TIMEW_GETVAL(y) == TIMEW_GETVAL(z)) ? (x) : wquo(wmul((x),(y)),(z))) #define wmulquo(x,y,z) ((WIDEVAL_GET(y) == WIDEVAL_GET(z)) ? (x) : wquo(wmul((x),(y)),(z)))
#define wmulquoll(x,y,z) (((y) == (z)) ? (x) : wquo(wmul((x),xv2w(LONG2FIX(y))),xv2w(LONG2FIX(z)))) #define wmulquoll(x,y,z) (((y) == (z)) ? (x) : wquo(wmul((x),xv2w(LONG2FIX(y))),xv2w(LONG2FIX(z))))
static void static void
wdivmodv(timew_t wn, timew_t wd, timew_t *wq, timew_t *wr) wdivmodv(wideval_t wn, wideval_t wd, wideval_t *wq, wideval_t *wr)
{ {
VALUE tmp, ary; VALUE tmp, ary;
#if TIMEVALUE_IS_UINT64 #if WIDEINT_IS_UINT64
if (FIXTV_P(TIMEW_GETVAL(wn)) && FIXTV_P(TIMEW_GETVAL(wd))) { if (FIXWV_P(WIDEVAL_GET(wn)) && FIXWV_P(WIDEVAL_GET(wd))) {
int64_t n, d, q, r; int64_t n, d, q, r;
d = FIXTVtoINT64(TIMEW_GETVAL(wd)); d = FIXWVtoINT64(WIDEVAL_GET(wd));
if (d == 0) rb_num_zerodiv(); if (d == 0) rb_num_zerodiv();
if (d == 1) { if (d == 1) {
*wq = wn; *wq = wn;
TIMEW_SETVAL(*wr, INT64toFIXTV(0)); WIDEVAL_SET(*wr, INT64toFIXWV(0));
return; return;
} }
if (d == -1) { if (d == -1) {
int64_t xneg = -FIXTVtoINT64(TIMEW_GETVAL(wn)); int64_t xneg = -FIXWVtoINT64(WIDEVAL_GET(wn));
if (FIXTVABLE(xneg)) if (FIXWVABLE(xneg))
TIMEW_SETVAL(*wq, INT64toFIXTV(xneg)); WIDEVAL_SET(*wq, INT64toFIXWV(xneg));
else else
TIMEW_SETVAL(*wq, INT64toNUM(xneg)); WIDEVAL_SET(*wq, INT64toNUM(xneg));
TIMEW_SETVAL(*wr, INT64toFIXTV(0)); WIDEVAL_SET(*wr, INT64toFIXWV(0));
return; return;
} }
n = FIXTVtoINT64(TIMEW_GETVAL(wn)); n = FIXWVtoINT64(WIDEVAL_GET(wn));
if (n == 0) { if (n == 0) {
TIMEW_SETVAL(*wq, INT64toFIXTV(0)); WIDEVAL_SET(*wq, INT64toFIXWV(0));
TIMEW_SETVAL(*wr, INT64toFIXTV(0)); WIDEVAL_SET(*wr, INT64toFIXWV(0));
return; return;
} }
if (d < 0) { if (d < 0) {
@ -522,8 +522,8 @@ wdivmodv(timew_t wn, timew_t wd, timew_t *wq, timew_t *wr)
r = n % d; r = n % d;
} }
} }
TIMEW_SETVAL(*wq, INT64toFIXTV(q)); WIDEVAL_SET(*wq, INT64toFIXWV(q));
TIMEW_SETVAL(*wr, INT64toFIXTV(r)); WIDEVAL_SET(*wr, INT64toFIXWV(r));
return; return;
} }
#endif #endif
@ -538,9 +538,9 @@ wdivmodv(timew_t wn, timew_t wd, timew_t *wq, timew_t *wr)
} }
static void static void
split_second(timew_t timew, VALUE *timev_p, VALUE *subsecx_p) split_second(wideval_t timew, VALUE *timev_p, VALUE *subsecx_p)
{ {
timew_t q, r; wideval_t q, r;
wdivmodv(timew, xv2w(INT2FIX(TIME_SCALE)), &q, &r); wdivmodv(timew, xv2w(INT2FIX(TIME_SCALE)), &q, &r);
*timev_p = w2xv(q); *timev_p = w2xv(q);
*subsecx_p = w2xv(r); *subsecx_p = w2xv(r);
@ -582,14 +582,14 @@ num_exact(VALUE v)
return v; return v;
} }
static timew_t static wideval_t
rb_time_magnify(VALUE v) rb_time_magnify(VALUE v)
{ {
timew_t ret; wideval_t ret;
if (FIXNUM_P(v)) { if (FIXNUM_P(v)) {
#if TIMEVALUE_IS_UINT64 && SIZEOF_LONG * 2 <= SIZEOF_INT64_T #if WIDEINT_IS_UINT64 && SIZEOF_LONG * 2 <= SIZEOF_INT64_T
int64_t i64 = (int64_t)FIX2LONG(v) * TIME_SCALE; int64_t i64 = (int64_t)FIX2LONG(v) * TIME_SCALE;
TIMEW_SETVAL(ret, INT64toFIXTV(i64)); WIDEVAL_SET(ret, INT64toFIXWV(i64));
return ret; return ret;
#else #else
long a, b, c; long a, b, c;
@ -599,7 +599,7 @@ rb_time_magnify(VALUE v)
b = TIME_SCALE; b = TIME_SCALE;
c = a * b; c = a * b;
if (c / a == b) { if (c / a == b) {
TIMEW_SETVAL(ret, INT64toFIXTV(c)); WIDEVAL_SET(ret, INT64toFIXWV(c));
return ret; return ret;
} }
#endif #endif
@ -608,13 +608,13 @@ rb_time_magnify(VALUE v)
} }
static VALUE static VALUE
rb_time_unmagnify(timew_t w) rb_time_unmagnify(wideval_t w)
{ {
VALUE v; VALUE v;
#if TIMEVALUE_IS_UINT64 #if WIDEINT_IS_UINT64
if (FIXTV_P(TIMEW_GETVAL(w))) { if (FIXWV_P(WIDEVAL_GET(w))) {
int64_t a, b, c; int64_t a, b, c;
a = FIXTVtoINT64(TIMEW_GETVAL(w)); a = FIXWVtoINT64(WIDEVAL_GET(w));
b = TIME_SCALE; b = TIME_SCALE;
c = a / b; c = a / b;
if (c * b == a) { if (c * b == a) {
@ -627,19 +627,19 @@ rb_time_unmagnify(timew_t w)
} }
static VALUE static VALUE
rb_time_unmagnify_to_float(timew_t w) rb_time_unmagnify_to_float(wideval_t w)
{ {
VALUE v; VALUE v;
#if TIMEVALUE_IS_UINT64 #if WIDEINT_IS_UINT64
if (FIXTV_P(TIMEW_GETVAL(w))) { if (FIXWV_P(WIDEVAL_GET(w))) {
int64_t a, b, c; int64_t a, b, c;
a = FIXTVtoINT64(TIMEW_GETVAL(w)); a = FIXWVtoINT64(WIDEVAL_GET(w));
b = TIME_SCALE; b = TIME_SCALE;
c = a / b; c = a / b;
if (c * b == a) { if (c * b == a) {
return DBL2NUM((double)c); return DBL2NUM((double)c);
} }
v = DBL2NUM(FIXTVtoINT64(TIMEW_GETVAL(w))); v = DBL2NUM(FIXWVtoINT64(WIDEVAL_GET(w)));
return quo(v, DBL2NUM(TIME_SCALE)); return quo(v, DBL2NUM(TIME_SCALE));
} }
#endif #endif
@ -685,7 +685,7 @@ static const int leap_year_days_in_month[] = {
31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
}; };
static timew_t static wideval_t
timegmw_noleapsecond(struct vtm *vtm) timegmw_noleapsecond(struct vtm *vtm)
{ {
VALUE year1900; VALUE year1900;
@ -694,7 +694,7 @@ timegmw_noleapsecond(struct vtm *vtm)
int yday = vtm->mday; int yday = vtm->mday;
long days_in400; long days_in400;
VALUE vdays, ret; VALUE vdays, ret;
timew_t wret; wideval_t wret;
year1900 = sub(vtm->year, INT2FIX(1900)); year1900 = sub(vtm->year, INT2FIX(1900));
@ -751,7 +751,7 @@ zone_str(const char *s)
} }
static void static void
gmtimew_noleapsecond(timew_t timew, struct vtm *vtm) gmtimew_noleapsecond(wideval_t timew, struct vtm *vtm)
{ {
VALUE v; VALUE v;
int i, n, x, y; int i, n, x, y;
@ -992,7 +992,7 @@ init_leap_second_info()
time_t now; time_t now;
struct tm *tm, result; struct tm *tm, result;
struct vtm vtm; struct vtm vtm;
timew_t timew; wideval_t timew;
now = time(NULL); now = time(NULL);
gmtime(&now); gmtime(&now);
tm = gmtime_with_leapsecond(&now, &result); tm = gmtime_with_leapsecond(&now, &result);
@ -1021,10 +1021,10 @@ init_leap_second_info()
} }
} }
static timew_t static wideval_t
timegmw(struct vtm *vtm) timegmw(struct vtm *vtm)
{ {
timew_t timew; wideval_t timew;
struct tm tm; struct tm tm;
time_t t; time_t t;
const char *errmsg; const char *errmsg;
@ -1038,7 +1038,7 @@ timegmw(struct vtm *vtm)
timew = timegmw_noleapsecond(vtm); timew = timegmw_noleapsecond(vtm);
if (wlt(TIMET2TIMEW(known_leap_seconds_limit), timew)) { if (wlt(TIMET2WIDEVAL(known_leap_seconds_limit), timew)) {
return wadd(timew, rb_time_magnify(INT2NUM(number_of_leap_seconds_known))); return wadd(timew, rb_time_magnify(INT2NUM(number_of_leap_seconds_known)));
} }
@ -1053,11 +1053,11 @@ timegmw(struct vtm *vtm)
errmsg = find_time_t(&tm, 1, &t); errmsg = find_time_t(&tm, 1, &t);
if (errmsg) if (errmsg)
rb_raise(rb_eArgError, "%s", errmsg); rb_raise(rb_eArgError, "%s", errmsg);
return wadd(TIMET2TIMEW(t), xv2w(vtm->subsecx)); return wadd(TIMET2WIDEVAL(t), xv2w(vtm->subsecx));
} }
static struct vtm * static struct vtm *
gmtimew(timew_t timew, struct vtm *result) gmtimew(wideval_t timew, struct vtm *result)
{ {
time_t t; time_t t;
struct tm tm; struct tm tm;
@ -1071,7 +1071,7 @@ gmtimew(timew_t timew, struct vtm *result)
init_leap_second_info(); init_leap_second_info();
if (wlt(TIMET2TIMEW(known_leap_seconds_limit), timew)) { if (wlt(TIMET2WIDEVAL(known_leap_seconds_limit), timew)) {
timew = wsub(timew, rb_time_magnify(INT2NUM(number_of_leap_seconds_known))); timew = wsub(timew, rb_time_magnify(INT2NUM(number_of_leap_seconds_known)));
gmtimew_noleapsecond(timew, result); gmtimew_noleapsecond(timew, result);
return result; return result;
@ -1267,13 +1267,13 @@ small_vtm_sub(struct vtm *vtm1, struct vtm *vtm2)
return INT2FIX(off); return INT2FIX(off);
} }
static timew_t static wideval_t
timelocalw(struct vtm *vtm) timelocalw(struct vtm *vtm)
{ {
time_t t; time_t t;
struct tm tm; struct tm tm;
VALUE v; VALUE v;
timew_t timew1, timew2; wideval_t timew1, timew2;
struct vtm vtm1, vtm2; struct vtm vtm1, vtm2;
int n; int n;
@ -1299,7 +1299,7 @@ timelocalw(struct vtm *vtm)
if (find_time_t(&tm, 0, &t)) if (find_time_t(&tm, 0, &t))
goto no_localtime; goto no_localtime;
return wadd(TIMET2TIMEW(t), xv2w(vtm->subsecx)); return wadd(TIMET2WIDEVAL(t), xv2w(vtm->subsecx));
no_localtime: no_localtime:
timew1 = timegmw(vtm); timew1 = timegmw(vtm);
@ -1385,12 +1385,12 @@ localtime_with_gmtoff(const time_t *t, struct tm *result, long *gmtoff)
} }
static int static int
timew_out_of_timet_range(timew_t timew) timew_out_of_timet_range(wideval_t timew)
{ {
VALUE timexv; VALUE timexv;
#if TIMEVALUE_IS_UINT64 && SIZEOF_TIME_T < SIZEOF_INT64_T #if WIDEINT_IS_UINT64 && SIZEOF_TIME_T < SIZEOF_INT64_T
if (FIXTV_P(TIMEW_GETVAL(timew))) { if (FIXWV_P(WIDEVAL_GET(timew))) {
int64_t t = FIXTVtoINT64(TIMEW_GETVAL(timew)); int64_t t = FIXWVtoINT64(WIDEVAL_GET(timew));
if (t < TIME_SCALE * (int64_t)TIMET_MIN || if (t < TIME_SCALE * (int64_t)TIMET_MIN ||
TIME_SCALE * (1 + (int64_t)TIMET_MAX) <= t) TIME_SCALE * (1 + (int64_t)TIMET_MAX) <= t)
return 1; return 1;
@ -1405,7 +1405,7 @@ timew_out_of_timet_range(timew_t timew)
} }
static struct vtm * static struct vtm *
localtimew(timew_t timew, struct vtm *result) localtimew(wideval_t timew, struct vtm *result)
{ {
VALUE timev, subsecx, offset; VALUE timev, subsecx, offset;
@ -1461,7 +1461,7 @@ localtimew(timew_t timew, struct vtm *result)
} }
struct time_object { struct time_object {
timew_t timew; /* time_t value * TIME_SCALE. possibly Rational. */ wideval_t timew; /* time_t value * TIME_SCALE. possibly Rational. */
struct vtm vtm; struct vtm vtm;
int gmt; int gmt;
int tm_got; int tm_got;
@ -1499,7 +1499,7 @@ time_mark(void *ptr)
{ {
struct time_object *tobj = ptr; struct time_object *tobj = ptr;
if (!tobj) return; if (!tobj) return;
if (!FIXTV_P(TIMEW_GETVAL(tobj->timew))) if (!FIXWV_P(WIDEVAL_GET(tobj->timew)))
rb_gc_mark(w2xv(tobj->timew)); rb_gc_mark(w2xv(tobj->timew));
rb_gc_mark(tobj->vtm.year); rb_gc_mark(tobj->vtm.year);
rb_gc_mark(tobj->vtm.subsecx); rb_gc_mark(tobj->vtm.subsecx);
@ -1544,19 +1544,19 @@ time_modify(VALUE time)
rb_raise(rb_eSecurityError, "Insecure: can't modify Time"); rb_raise(rb_eSecurityError, "Insecure: can't modify Time");
} }
static timew_t static wideval_t
timespec2timew(struct timespec *ts) timespec2timew(struct timespec *ts)
{ {
timew_t timew; wideval_t timew;
timew = TIMET2TIMEW(ts->tv_sec); timew = TIMET2WIDEVAL(ts->tv_sec);
if (ts->tv_nsec) if (ts->tv_nsec)
timew = wadd(timew, wmulquoll(xv2w(LONG2NUM(ts->tv_nsec)), TIME_SCALE, 1000000000)); timew = wadd(timew, wmulquoll(xv2w(LONG2NUM(ts->tv_nsec)), TIME_SCALE, 1000000000));
return timew; return timew;
} }
static struct timespec static struct timespec
timew2timespec(timew_t timew) timew2timespec(wideval_t timew)
{ {
VALUE timev, subsecx; VALUE timev, subsecx;
struct timespec ts; struct timespec ts;
@ -1930,7 +1930,7 @@ time_overflow_p(time_t *secp, long *nsecp)
*nsecp = nsec; *nsecp = nsec;
} }
static timew_t static wideval_t
nsec2timew(time_t sec, long nsec) nsec2timew(time_t sec, long nsec)
{ {
struct timespec ts; struct timespec ts;
@ -1941,7 +1941,7 @@ nsec2timew(time_t sec, long nsec)
} }
static VALUE static VALUE
time_new_timew(VALUE klass, timew_t timew) time_new_timew(VALUE klass, wideval_t timew)
{ {
VALUE time = time_s_alloc(klass); VALUE time = time_s_alloc(klass);
struct time_object *tobj; struct time_object *tobj;
@ -2140,7 +2140,7 @@ static VALUE
time_s_at(int argc, VALUE *argv, VALUE klass) time_s_at(int argc, VALUE *argv, VALUE klass)
{ {
VALUE time, t; VALUE time, t;
timew_t timew; wideval_t timew;
if (rb_scan_args(argc, argv, "11", &time, &t) == 2) { if (rb_scan_args(argc, argv, "11", &time, &t) == 2) {
time = num_exact(time); time = num_exact(time);
@ -4194,7 +4194,7 @@ time_mload(VALUE time, VALUE str)
int i, gmt; int i, gmt;
long nsec; long nsec;
VALUE submicro, nano_num, nano_den, offset; VALUE submicro, nano_num, nano_den, offset;
timew_t timew; wideval_t timew;
time_modify(time); time_modify(time);
@ -4237,7 +4237,7 @@ time_mload(VALUE time, VALUE str)
sec = p; sec = p;
usec = s; usec = s;
nsec = usec * 1000; nsec = usec * 1000;
timew = wadd(TIMET2TIMEW(sec), wmulquoll(xv2w(LONG2FIX(usec)), TIME_SCALE, 1000000)); timew = wadd(TIMET2WIDEVAL(sec), wmulquoll(xv2w(LONG2FIX(usec)), TIME_SCALE, 1000000));
} }
else { else {
p &= ~(1UL<<31); p &= ~(1UL<<31);