mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Jon Chesterfield <jonathanchesterfield@gmail.com>
To: musl@lists.openwall.com, "Mattias Andrée" <maandree@kth.se>
Subject: Re: [musl] [PATCH v2 2/2] Use modulo instead of mul+sub in __secs_to_tm
Date: Sun, 28 Feb 2021 19:58:27 +0000	[thread overview]
Message-ID: <CAOUYtQCiOiM69sq1QWsNEGMspedGFY7_VBYxef9-hXENeTCnKQ@mail.gmail.com> (raw)
In-Reply-To: <20210228193733.GF354034@port70.net>

[-- Attachment #1: Type: text/plain, Size: 800 bytes --]

On Sun, 28 Feb 2021, 19:37 Szabolcs Nagy, <nsz@port70.net> wrote:

> * Mattias Andrée <maandree@kth.se> [2021-02-28 20:22:10 +0100]:
> > On x86 modulo is free when doing division, so this removes
>
> there should be no division.
>
> div by const is transformed to mul and shift at -O1 and
> that's what we should be using instead of manual hacks.


Right. Divide by constant is cheap because compilers have a bunch of
transforms to get rid of the divide in favour of one of more cheaper
instructions.

Note that module coming for free with division doesn't make it cheap.
Integer division is far more expensive that integer multiply on ~ every
architecture. Several architectures implement division in software. It's
not cheap on x86, despite the dedicated instruction.

Cheers

[-- Attachment #2: Type: text/html, Size: 1315 bytes --]

  parent reply	other threads:[~2021-02-28 19:58 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-28 15:09 [musl] [PATCH] Remove unnecessary if " Mattias Andrée
2021-02-28 17:06 ` Rich Felker
2021-02-28 17:24   ` Mattias Andrée
2021-02-28 17:34     ` Rich Felker
2021-02-28 19:22 ` [musl] [PATCH v2 1/2] " Mattias Andrée
2021-02-28 19:22   ` [musl] [PATCH v2 2/2] Use modulo instead of mul+sub " Mattias Andrée
2021-02-28 19:37     ` Szabolcs Nagy
2021-02-28 19:52       ` Mattias Andrée
2021-02-28 19:58       ` Jon Chesterfield [this message]
2021-03-01 19:26         ` Markus Wichmann
2021-02-28 19:27 ` [musl] [PATCH v3 1/2] Remove unnecessary if " Mattias Andrée
2021-02-28 19:27   ` [musl] [PATCH v3 2/2] Use modulo instead of mul+sub " Mattias Andrée

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=CAOUYtQCiOiM69sq1QWsNEGMspedGFY7_VBYxef9-hXENeTCnKQ@mail.gmail.com \
    --to=jonathanchesterfield@gmail.com \
    --cc=maandree@kth.se \
    --cc=musl@lists.openwall.com \
    /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.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

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).