From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.cs.ucla.edu (mail.cs.ucla.edu [131.179.128.66]) by sourceware.org (Postfix) with ESMTPS id 41DB63858D20 for ; Wed, 12 Jul 2023 21:04:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 41DB63858D20 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=cs.ucla.edu Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=cs.ucla.edu Received: from localhost (localhost [127.0.0.1]) by mail.cs.ucla.edu (Postfix) with ESMTP id D97303C011BD4; Wed, 12 Jul 2023 14:04:02 -0700 (PDT) Received: from mail.cs.ucla.edu ([127.0.0.1]) by localhost (mail.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id oTuUpSnhl98Z; Wed, 12 Jul 2023 14:04:02 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by mail.cs.ucla.edu (Postfix) with ESMTP id 791BF3C011BDA; Wed, 12 Jul 2023 14:04:02 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.10.3 mail.cs.ucla.edu 791BF3C011BDA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cs.ucla.edu; s=9D0B346E-2AEB-11ED-9476-E14B719DCE6C; t=1689195842; bh=AQAesj/DOiMIuoBScbm+H4LjZQ332lV3cW3st306E48=; h=Message-ID:Date:MIME-Version:To:From; b=ojeuuZnuRAfaR3vEgKOrGgQbAIS8TDWhnSkFmDP/WiYtCb14u4rTYCxIlJR7ylZZj CaZYn5z7O8UG2N+aOlKJZz28Og6ktka3jrMM548tbyrPs3OoE8TdKfEHJkb3EsTTDC 2X0JLBFRc+eCddUjkA4+1yNbH/jeslIWszCgYJcUaDkEHZ8kaGWndjlGQVX1l6HK3X vcF4AGxt1hQZNic+Oc8OjPjHqd7gHJqDyxPqqSH7sO1QXcS/btB1t86du0DINO8N28 mh/DMi5nmqbH2kVeH88FW0JbnI2BLPtlbOYGeXz1mhkqPXynSKcaFUnj1QaXc5/sQV PEjEAg/IarO+g== X-Virus-Scanned: amavisd-new at mail.cs.ucla.edu Received: from mail.cs.ucla.edu ([127.0.0.1]) by localhost (mail.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id ZIAnooxykByZ; Wed, 12 Jul 2023 14:04:02 -0700 (PDT) Received: from [192.168.1.9] (cpe-172-91-119-151.socal.res.rr.com [172.91.119.151]) by mail.cs.ucla.edu (Postfix) with ESMTPSA id 560BE3C011BD4; Wed, 12 Jul 2023 14:04:02 -0700 (PDT) Message-ID: <01eee84c-d5e6-a5a0-79be-e5b58ca6e541@cs.ucla.edu> Date: Wed, 12 Jul 2023 14:04:02 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Content-Language: en-US To: Adhemerval Zanella References: <20230711190722.4028821-1-adhemerval.zanella@linaro.org> <20230711190722.4028821-2-adhemerval.zanella@linaro.org> Cc: libc-alpha@sourceware.org From: Paul Eggert Organization: UCLA Computer Science Department Subject: Re: [PATCH v4 1/6] stdlib: Optimization qsort{_r} swap implementation (BZ 19305) In-Reply-To: <20230711190722.4028821-2-adhemerval.zanella@linaro.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3.0 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 2023-07-11 12:07, Adhemerval Zanella via Libc-alpha wrote: > +/* Returns true if elements can be copied using word loads and stores. > + The SIZE and BASE must be a multiple of the ALIGN. */ > +__attribute_const__ __always_inline > +static bool > +is_aligned (const void *base, size_t size, unsigned char align) > +{ > + unsigned char lsbits = (unsigned char) size; > + > + lsbits |= (unsigned char)(uintptr_t) base; > + return (lsbits & (align - 1)) == 0; > +} Doesn't the following source code generate better machine code? It does for me, anyway (x86-64). Even if the code were the same, the simplicity would be a win. static bool is_aligned (const void *base, size_t size, size_t align) { return (((uintptr_t) base | size) & (align - 1)) == 0; } > + if (is_aligned (pbase, size, sizeof (uint64_t))) > + swap_func = SWAP_WORDS_64; alignof not sizeof, in contexts like these that are talking about alignment not size.