mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Markus Wichmann <nullplan@gmx.net>
To: Rich Felker <dalias@libc.org>
Cc: musl@lists.openwall.com
Subject: Re: [musl] [PATCH] fix return value of wcs{,n}cmp for near-limits signed wchar_t values
Date: Fri, 6 Jan 2023 17:57:08 +0100	[thread overview]
Message-ID: <20230106165708.GC2032@voyager> (raw)
In-Reply-To: <20230106111724.GA4163@brightrain.aerifal.cx>

Hi all,

I thought a bit more about it. It would be possible to compress the
information we need somewhat like this:

int64_t d = (int64_t)*l - *r;
return (d >> 1) | (d & INT_MAX);

The idea is that I need bit 31 of the output to equal bit 32 of the
difference, and bits 0-30 of the output need to be nonzero exactly if
bits 0-31 of the difference were nonzero. So it's one big disjunction.

So I managed to find a branchless function. Not sure if it is actually
worth it to implement it. The branching version is easier to understand
and apparently gives better machine code on i386 and x86_64 (from just
eyeballing it). It is not even implemented with branches on those
architectures. And it is a micro-optimization, anyway.

Ciao,
Markus

  reply	other threads:[~2023-01-06 16:57 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-04 15:07 Gabriel Ravier
2023-01-06  9:20 ` Markus Wichmann
2023-01-06  9:31   ` Markus Wichmann
2023-01-06 11:17   ` Rich Felker
2023-01-06 16:57     ` Markus Wichmann [this message]
2023-01-07  1:51       ` Gabriel Ravier

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=20230106165708.GC2032@voyager \
    --to=nullplan@gmx.net \
    --cc=dalias@libc.org \
    --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).