From: Paul Eggert <eggert@cs.ucla.edu>
To: Daniel Gutson <daniel.gutson@tallertechnologies.com>,
Adhemerval Zanella <adhemerval.zanella@linaro.org>
Cc: GNU C Library <libc-alpha@sourceware.org>
Subject: Re: question regarding div / std::div implementation
Date: Wed, 20 Apr 2016 21:38:00 -0000 [thread overview]
Message-ID: <5717F6BD.90705@cs.ucla.edu> (raw)
In-Reply-To: <CAF5HaEVWnU9_8Ae3gCR9Ns8sD_B8QoD794sp59XQNrqEw034EQ@mail.gmail.com>
On 04/20/2016 02:15 PM, Daniel Gutson wrote:
> OK with no inline asm, but a libcall might be expensive specially in a
> tight loop and messes with predictions;
> a builtin is nonportable as well.
In practice, C programs that need integer quotient and remainder
typically don't call 'div'. They just use % and /, and compilers are now
smart enough to do just one machine-level operation to get both quotient
and remainder. For example, time/offtime.c has this macro:
#define DIV(a, b) ((a) / (b) - ((a) % (b) < 0))
which should work just fine as-is. In theory one could change this to
use div/ldiv/lldiv, but why bother making the code way more complicated?
As the 'div' function family was designed back when C compilers were not
that smart and is largely obsolete now, simplicity would appear to be
more important than performance here. Perhaps someone someday will work
up the energy to get 'div' removed from the C standard.
next prev parent reply other threads:[~2016-04-20 21:38 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-04-20 19:44 Daniel Gutson
2016-04-20 20:27 ` Mike Frysinger
[not found] ` <5717DF65.5060606@linaro.org>
[not found] ` <CAF5HaEWdpAGiXtCO36u3F0QGAXfVHL+qkY+RLsszpv7paPVdMg@mail.gmail.com>
2016-04-20 20:29 ` Adhemerval Zanella
2016-04-20 20:36 ` Daniel Gutson
2016-04-20 20:49 ` Adhemerval Zanella
2016-04-20 21:16 ` Daniel Gutson
2016-04-20 21:38 ` Paul Eggert [this message]
2016-04-20 21:55 ` Daniel Gutson
2016-04-20 22:10 ` Paul Eggert
2016-04-20 22:18 ` Daniel Gutson
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=5717F6BD.90705@cs.ucla.edu \
--to=eggert@cs.ucla.edu \
--cc=adhemerval.zanella@linaro.org \
--cc=daniel.gutson@tallertechnologies.com \
--cc=libc-alpha@sourceware.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 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 read-only IMAP folder(s) and NNTP newsgroup(s).