From: "H. Peter Anvin" <hpa@zytor.com>
To: Linux Arch Mailing List <linux-arch@vger.kernel.org>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Using __int128 on 64-bit architectures
Date: Sun, 17 Mar 2013 16:04:32 -0700 [thread overview]
Message-ID: <51464C00.5090107@zytor.com> (raw)
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.
next reply other threads:[~2013-03-17 23:04 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-03-17 23:04 H. Peter Anvin [this message]
2013-04-21 4:29 ` Using __int128 on 64-bit architectures Maciej W. Rozycki
2013-04-21 9:35 ` Stephen Rothwell
2013-04-21 9:51 ` Michael Cree
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=51464C00.5090107@zytor.com \
--to=hpa@zytor.com \
--cc=linux-arch@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.