From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6930 invoked by alias); 12 Sep 2017 17:09:24 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Received: (qmail 6921 invoked by uid 89); 12 Sep 2017 17:09:24 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=Hx-languages-length:1656 X-HELO: mx1.redhat.com DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 281B5356F5 Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=fweimer@redhat.com Subject: Re: [PATCH] powerpc: Use aligned stores in memset To: Zack Weinberg Cc: Rajalakshmi Srinivasaraghavan , GNU C Library References: <1503033107-20047-1-git-send-email-raji@linux.vnet.ibm.com> From: Florian Weimer Message-ID: <2d36f499-1602-18ab-9ea2-94e5bc8c7c50@redhat.com> Date: Tue, 12 Sep 2017 17:09:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-SW-Source: 2017-09/txt/msg00521.txt.bz2 On 09/12/2017 02:18 PM, Zack Weinberg wrote: > On Tue, Sep 12, 2017 at 6:30 AM, Florian Weimer wrote: >> >> I could not find the manual which has the requirement that the mem* >> functions do not use unaligned accesses. Unless they are worded in a >> very peculiar way, right now, the GCC/glibc combination does not comply >> with a requirement that memset & Co. can be used for device memory access. > > mem* are required to behave as-if they access memory as an array of > unsigned char. Therefore it is valid to give them arbitrarily > (un)aligned pointers. The C abstract machine doesn't specifically > contemplate the possibility of a CPU that can do unaligned word reads > but maybe not to all memory addresses, but I would argue that if there > is such a CPU, then mem* are obliged to cope with it. I disagree. On most architectures, including x86-64, you can tell, with certain hardware devices, that our mem* functions do not perform byte-wise read or write access. On many architectures, just a hardware watchpoint installed using ptrace (a supported API) is sufficient. But this theoretical possibility does not mean that we cannot or should not optimize the mem* functions. If you need specific memory access patterns, you need to use inline assembly. In many cases, volatile loads and stores are sufficient, too. >> ...the current glibc >> implementation accesses locations which are outside the specified object >> boundaries. > > I think that's technically a defect. Nothing in the C standard > licenses it to do that; It's permitted under the as-if rule. Florian