70 |
/* Before trying to level the exponents, minimize the mantisses. |
/* Before trying to level the exponents, minimize the mantisses. |
71 |
This will hopefully minimize the risk of overflow. */ |
This will hopefully minimize the risk of overflow. */ |
72 |
while (time1->period.m && !(time1->period.m & 1)) |
while (time1->period.m && !(time1->period.m & 1)) |
73 |
time1->period.e++, time1->period.m /= 2; |
{ |
74 |
|
time1->period.e++; |
75 |
|
time1->period.m /= 2; |
76 |
|
} |
77 |
|
|
78 |
while (time2->period.m && !(time2->period.m & 1)) |
while (time2->period.m && !(time2->period.m & 1)) |
79 |
time2->period.e ++, time2->period.m /= 2; |
{ |
80 |
|
time2->period.e++; |
81 |
|
time2->period.m /= 2; |
82 |
|
} |
83 |
|
|
84 |
if (time1->period.e < time2->period.e) |
if (time1->period.e < time2->period.e) |
85 |
{ |
{ |
86 |
__L4_time_t *time_tmp = time1; |
__L4_time_t *time_tmp = time1; |
87 |
time1 = time2, time2 = time_tmp; |
time1 = time2; |
88 |
|
time2 = time_tmp; |
89 |
} |
} |
90 |
|
|
91 |
while (time1->period.e != time2->period.e) |
while (time1->period.e != time2->period.e) |
92 |
{ |
{ |
93 |
time1->period.m *= 2; |
time1->period.m *= 2; |
94 |
time1->period.e --; |
time1->period.e--; |
95 |
} |
} |
96 |
} |
} |
97 |
|
|
100 |
_L4_attribute_always_inline |
_L4_attribute_always_inline |
101 |
_L4_time_make (_L4_word_t val) |
_L4_time_make (_L4_word_t val) |
102 |
{ |
{ |
103 |
__L4_time_t t = { 0, }; |
__L4_time_t t = { .raw = 0 }; |
104 |
|
|
105 |
if (val != 0) |
if (val != 0) |
106 |
{ |
{ |
133 |
res = _time1.period.m + _time2.period.m; |
res = _time1.period.m + _time2.period.m; |
134 |
|
|
135 |
if (res > _L4_TIME_PERIOD_M_MAX) |
if (res > _L4_TIME_PERIOD_M_MAX) |
|
/* Overflow in the mantisse, try to see if it is possible to shift |
|
|
down the result, and increase the exponent. */ |
|
136 |
{ |
{ |
137 |
|
/* Overflow in the mantisse, try to see if it is possible to |
138 |
|
shift down the result, and increase the exponent. */ |
139 |
|
|
140 |
while (!(res & 1)) |
while (!(res & 1)) |
141 |
{ |
{ |
142 |
res >>= 1; |
res >>= 1; |
143 |
_time1.period.e ++; |
_time1.period.e++; |
144 |
} |
} |
145 |
} |
} |
146 |
|
|
166 |
|
|
167 |
_L4_time_alter_exps (&_time1, &_time2); |
_L4_time_alter_exps (&_time1, &_time2); |
168 |
|
|
169 |
/* If this underflows (b's mantisse is greater than a's) there is |
/* If this underflows (time2's mantisse is greater than time1's) there |
170 |
really nothing to do, since negative time is not supported. */ |
is really nothing to do, since negative time is not supported. */ |
171 |
_time1.period.m = _time1.period.m - _time2.period.m; |
_time1.period.m = _time1.period.m - _time2.period.m; |
172 |
return _time1.raw; |
return _time1.raw; |
173 |
} |
} |