Skip to content

Commit d03bd04

Browse files
author
Martin Schwidefsky
committed
s390/timex: micro optimization for tod_to_ns
The conversion of a TOD value to nano-seconds currently uses a 32/32 bit split with the calculation for "nsecs = (TOD * 125) >> 9". Using a 55/9 bit split saves an instruction. Signed-off-by: Martin Schwidefsky <[email protected]>
1 parent e53051e commit d03bd04

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

arch/s390/include/asm/timex.h

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -206,20 +206,16 @@ static inline unsigned long long get_tod_clock_monotonic(void)
206206
* ns = (todval * 125) >> 9;
207207
*
208208
* In order to avoid an overflow with the multiplication we can rewrite this.
209-
* With a split todval == 2^32 * th + tl (th upper 32 bits, tl lower 32 bits)
209+
* With a split todval == 2^9 * th + tl (th upper 55 bits, tl lower 9 bits)
210210
* we end up with
211211
*
212-
* ns = ((2^32 * th + tl) * 125 ) >> 9;
213-
* -> ns = (2^23 * th * 125) + ((tl * 125) >> 9);
212+
* ns = ((2^9 * th + tl) * 125 ) >> 9;
213+
* -> ns = (th * 125) + ((tl * 125) >> 9);
214214
*
215215
*/
216216
static inline unsigned long long tod_to_ns(unsigned long long todval)
217217
{
218-
unsigned long long ns;
219-
220-
ns = ((todval >> 32) << 23) * 125;
221-
ns += ((todval & 0xffffffff) * 125) >> 9;
222-
return ns;
218+
return ((todval >> 9) * 125) + (((todval & 0x1ff) * 125) >> 9);
223219
}
224220

225221
#endif

0 commit comments

Comments
 (0)