Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Fri, 6 Jan 2023 17:57:08 +0100
From: Markus Wichmann <nullplan@....net>
To: Rich Felker <dalias@...c.org>
Cc: musl@...ts.openwall.com
Subject: Re: [PATCH] fix return value of wcs{,n}cmp for near-limits
 signed wchar_t values

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

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.