From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-0.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 25460 invoked from network); 25 Dec 2020 22:32:03 -0000 Received: from ewsd.inri.net (107.191.116.128) by inbox.vuxu.org with ESMTPUTF8; 25 Dec 2020 22:32:03 -0000 Received: from mail-vk1-f172.google.com ([209.85.221.172]) by ewsd; Fri Dec 25 17:31:14 -0500 2020 Received: by mail-vk1-f172.google.com with SMTP id t16so1143447vkl.10 for <9front@9front.org>; Fri, 25 Dec 2020 14:31:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=AI6jyVoOLgm6WiE+nV1pAw+ppZ5Ohsf2gQmvdpzKVD4=; b=Duhl/pDrUy1LN/360roS7d80V319dMtPZ/+SRvrnkAvgy6posVAmMQQ30w0be2+T4d In5HFA1vnAHupp6twrPIXoVAoXBBOHIaAuBfSFglrHbyxlcXFDGxeba2t2LEvKNcDKgR wRUGIKm/EKCsErWO5cZYObpAxq2OSdjPIqmjGxvtXSrynEdAcXp4TE3bPTQclE8hLj9u Z/LDi6dFI2pE70UxIDD9stvufMr1GG+OuHRJJYFw81t/HVta/q4dZFdz8k40m9w76Z2I 93L/bZXk0qNaXUYyOC5kLxkBR28mAlmhWEoei7F6TiNXLEY8eEmgrzEEZwMGde+knUkh 1m6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=AI6jyVoOLgm6WiE+nV1pAw+ppZ5Ohsf2gQmvdpzKVD4=; b=njNlKcOmSu47wWI19Kj7DXiBGxnxbwkCxA1a2sN8DhODAS5eskqubVG6s7zPGvexgM bBDez4SpYveqvv4mzvn/AkqE1sc1ZNdSo76S2syfrPe4pf8nE1y9yiVT0qws2H9KyGjO LXare6MWlpPvRsogPHNocLqq5tCaVJB/3wfDrLgDhvXJqckBCTa4j5meOALSaS41rdhn 3uJnXc+5xeMAOqBTU8pKA01E2Q3qD/d7k642kkCLZjNBafx9i3Z499mlljA67MD2dSGp mwyRww7DxKRNtQ2eSUec/ugclfSJFVQ9BrZHEVXkkHXrgssiampAgj+zgtprNAO7Lop+ 7Gew== X-Gm-Message-State: AOAM53116A3fi7Fund+wrPu7XzbYJVJXUaft/4SFML6bXv4ZwkNa/AJw utP7E+RHhA8nz2NjhVcm0dXJh5NXdp0EPVoMgEFNqHf7 X-Google-Smtp-Source: ABdhPJw1R+QR4kKCpNi5SDPvcvLAa+vrQUztYaM6FuQdVSovDOWhwXTQ3/VcN4+xxRmgQG3t5g6K+00+hVAoZjpQbRA= X-Received: by 2002:a1f:1105:: with SMTP id 5mr24831475vkr.17.1608935469335; Fri, 25 Dec 2020 14:31:09 -0800 (PST) MIME-Version: 1.0 References: <3DDE1E483508802CAF9926EE01A0A112@gmail.com> In-Reply-To: <3DDE1E483508802CAF9926EE01A0A112@gmail.com> From: Kemal Date: Sat, 26 Dec 2020 01:30:53 +0300 Message-ID: To: 9front@9front.org Content-Type: text/plain; charset="UTF-8" List-ID: <9front.9front.org> List-Help: X-Glyph: ➈ X-Bullshit: scale-out dependency replication descriptor database Subject: Re: [9front] [PATCH] branchless assembly abs() and labs() for amd64 Reply-To: 9front@9front.org Precedence: bulk hello again, on maintainability issue, we can do it on c with bit shifts like this: #include #include 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.