linux-arch.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Using __int128 on 64-bit architectures
@ 2013-03-17 23:04 H. Peter Anvin
  2013-04-21  4:29 ` Maciej W. Rozycki
  0 siblings, 1 reply; 5+ messages in thread
From: H. Peter Anvin @ 2013-03-17 23:04 UTC (permalink / raw)
  To: Linux Arch Mailing List, Linux Kernel Mailing List

Hi all,

How desirable/portable is it to use __int128 on non-x86 64-bit
architectures to get a 64*64 -> 128 bit multiply?  On x86-64 this works
extremely well, but I'm worried about that needlessly breaking on other
architectures.

In particular, it looks opportune to use a scaling-by-multiply instead
of a multiply-divide on lines 253 and 269 of kernel/time.c:

   243  unsigned int jiffies_to_msecs(const unsigned long j)
   244  {
   245  #if HZ <= MSEC_PER_SEC && !(MSEC_PER_SEC % HZ)
   246          return (MSEC_PER_SEC / HZ) * j;
   247  #elif HZ > MSEC_PER_SEC && !(HZ % MSEC_PER_SEC)
   248          return (j + (HZ / MSEC_PER_SEC) - 1)/(HZ / MSEC_PER_SEC);
   249  #else
   250  # if BITS_PER_LONG == 32
   251          return (HZ_TO_MSEC_MUL32 * j) >> HZ_TO_MSEC_SHR32;
   252  # else
   253          return (j * HZ_TO_MSEC_NUM) / HZ_TO_MSEC_DEN;
   254  # endif
   255  #endif
   256  }
   257  EXPORT_SYMBOL(jiffies_to_msecs);
   258
   259  unsigned int jiffies_to_usecs(const unsigned long j)
   260  {
   261  #if HZ <= USEC_PER_SEC && !(USEC_PER_SEC % HZ)
   262          return (USEC_PER_SEC / HZ) * j;
   263  #elif HZ > USEC_PER_SEC && !(HZ % USEC_PER_SEC)
   264          return (j + (HZ / USEC_PER_SEC) - 1)/(HZ / USEC_PER_SEC);
   265  #else
   266  # if BITS_PER_LONG == 32
   267          return (HZ_TO_USEC_MUL32 * j) >> HZ_TO_USEC_SHR32;
   268  # else
   269          return (j * HZ_TO_USEC_NUM) / HZ_TO_USEC_DEN;
   270  # endif
   271  #endif
   272  }


	-hpa

-- 
H. Peter Anvin, Intel Open Source Technology Center
I work for Intel.  I don't speak on their behalf.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2013-04-21 11:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-03-17 23:04 Using __int128 on 64-bit architectures H. Peter Anvin
2013-04-21  4:29 ` Maciej W. Rozycki
2013-04-21  9:35   ` Stephen Rothwell
2013-04-21  9:51     ` Michael Cree
2013-04-21  9:51       ` Michael Cree

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).