From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.devel Subject: Re: HAVE_FAST_UNALIGNED_ACCESS Date: Thu, 30 Mar 2023 13:26:58 +0300 Message-ID: <83a5zu5ybx.fsf@gnu.org> References: <87sfdmlgzx.fsf@gmail.com> Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="6499"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org, luangruo@yahoo.com To: Robert Pluim Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Thu Mar 30 12:27:45 2023 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1phpVQ-0001X6-JY for ged-emacs-devel@m.gmane-mx.org; Thu, 30 Mar 2023 12:27:44 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1phpUd-00022e-VK; Thu, 30 Mar 2023 06:26:55 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1phpUX-00022U-Tc for emacs-devel@gnu.org; Thu, 30 Mar 2023 06:26:49 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1phpUX-0002vB-6i; Thu, 30 Mar 2023 06:26:49 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=Zo364wHsRfJ7tcUMuGimCxF7bplq1nHP044dO31JneM=; b=AHqL0tdIDsBv 9dcONUtBbHgeqTNUZUDiHiNxtaZiiqxorkg3OpjbwexAy3UEhmX5Hxj8/XVbbVAI2dwEMuOfr9d4M /Bza2Ud8aT7wFnFvXHcj2HnxTaRuIUdYkHoTGJFurkAVIBWKSwTcncdeNI8PtFEAvgU1lOYO5KyBq HGk7KCuR7mijxD+du0mmxXArG05YCKKk6V5VhJMFSJ7RFIuz3DdmAi1EbmQ2SHsdKUFmqeogjyxY/ PenLYzVWl3AcIcQAlq10K8I1VQ6McdAqJItbH2HaHBZlYT4AfLsNeIT7O1WCF9+osv7DaaUfuYVi/ TDeN9SabAVis9CW0MI3THQ==; Original-Received: from [87.69.77.57] (helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1phpUW-0001lk-Gq; Thu, 30 Mar 2023 06:26:48 -0400 In-Reply-To: <87sfdmlgzx.fsf@gmail.com> (message from Robert Pluim on Thu, 30 Mar 2023 11:34:42 +0200) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:304853 Archived-At: > From: Robert Pluim > Cc: Po Lu > Date: Thu, 30 Mar 2023 11:34:42 +0200 > > Fstring_lessp has: > > /* Check whether the platform allows access to unaligned addresses for > size_t integers without trapping or undue penalty (a few cycles is OK). > > This whitelist is incomplete but since it is only used to improve > performance, omitting cases is safe. */ > #if defined __x86_64__|| defined __amd64__ \ > || defined __i386__ || defined __i386 \ > || defined __arm64__ || defined __aarch64__ \ > || defined __powerpc__ || defined __powerpc \ > || defined __ppc__ || defined __ppc \ > || defined __s390__ || defined __s390x__ > #define HAVE_FAST_UNALIGNED_ACCESS 1 > #else > #define HAVE_FAST_UNALIGNED_ACCESS 0 > #endif > > but even if unaligned access is normally permitted by a machine, it is > still undefined behavior to dereference an unaligned pointer. This is incorrect. There's nothing undefined about x86 unaligned accesses. C standards can regard this as UB, but we are using machine-specific knowledge here (and Emacs cannot be built with a strict adherence to C standards anyway). > Instead, HAVE_FAST_UNALIGNED_ACCESS and UNALIGNED_LOAD_SIZE should be > removed and memcpy used instead: > > word_t a, c; > > memcpy (&a, w1 + b / ws, sizeof a); > memcpy (&c, w2 + b / ws, sizeof c); > > doing so will make the compiler itself generate the right sequence of > instructions for performing unaligned accesses, normally with only a few > cycles penalty. We don't want that penalty here, that's all. > I would like to install such a change on emacs-29. No, please don't. > Emacs currently crashes when built with various compilers performing > pointer alignment checks. Details, please. Which compilers, on what platforms, for what target architectures, etc. Unconditionally removing the fast copy there is a non-starter.