From: Kemal <kemalinanc8@gmail.com>
To: 9front@9front.org
Subject: Re: [9front] [PATCH] branchless assembly abs() and labs() for amd64
Date: Sat, 26 Dec 2020 01:30:53 +0300 [thread overview]
Message-ID: <CABO6shc211=pPhOTNAT+tyTgihPWSrqwGYSkQyasK=xM69QmRQ@mail.gmail.com> (raw)
In-Reply-To: <3DDE1E483508802CAF9926EE01A0A112@gmail.com>
hello again,
on maintainability issue, we can do it on c with bit shifts like this:
#include <u.h>
#include <libc.h>
int
abs(int a)
{
return (a ^ (a >> 8*sizeof(int)-1)) - (a >> 8*sizeof(int)-1));
}
so that we don't have to maintain more platform specific code.
on size, the assembly one seems to be the clear winner. the original
abs's object file (unlinked) is around 400~ bytes, assembly one is
120-140~, the branchless c one is 300~.
on performance, well i couldn't do much tests on this and i think my
test program doesn't compare these 3 implementations properly. i might
try performance benchmarks if i can setup a better suite.
on if abs is commonly used, well i couldn't find a program that uses
it heavily so having branchless abs is not important.
next prev parent reply other threads:[~2020-12-25 22:32 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-25 16:36 Kemal
2020-12-25 18:13 ` ori
2020-12-25 18:28 ` boehm.igor
2020-12-25 22:30 ` Kemal [this message]
2020-12-26 1:38 ` ori
2020-12-26 14:12 ` Kemal
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='CABO6shc211=pPhOTNAT+tyTgihPWSrqwGYSkQyasK=xM69QmRQ@mail.gmail.com' \
--to=kemalinanc8@gmail.com \
--cc=9front@9front.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 NNTP newsgroup(s).