From patchwork Sat Aug 24 14:46:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Monakov X-Patchwork-Id: 1976393 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=ispras.ru header.i=@ispras.ru header.a=rsa-sha256 header.s=default header.b=UN0/FrOj; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WrfsX14hvz1yfF for ; Sun, 25 Aug 2024 00:46:56 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CCE2A386183C for ; Sat, 24 Aug 2024 14:46:53 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail.ispras.ru (mail.ispras.ru [83.149.199.84]) by sourceware.org (Postfix) with ESMTPS id 76EBD3858408 for ; Sat, 24 Aug 2024 14:46:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 76EBD3858408 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=ispras.ru Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=ispras.ru ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 76EBD3858408 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=83.149.199.84 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1724510793; cv=none; b=t2k26QxwiJRkorfUx04jGgk9o+t1BIYS43POHRMM9Wjs4IGR6HJTTDwURs4/6xxrtL+66V0/9wLbJW3NdJIozZeqkXNtaw6Nle8m1s3zNn4CBghIriypiC0QbH/r9pFXHnY2GbLDvWoqfoWoXzqmo8Fs9LmjSesV9I6kNMBBdF4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1724510793; c=relaxed/simple; bh=GyWKdg1bsH3sX/s4I7r2yzxxHAbPL203m5JSQWFgczo=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=og6FVx3qATphBRFjOKIwCFam1GlxvtRie46eqLSPx01Dtr7h4ZdwpEkiCrehGOEF7MTFEiqyHnWd4K55j2OXyydOoN0ArK8fNILbbMbh93uacVDXA3Ot0a/2K57VIR2gTcNmBDba6+R7Q6DKRRv6ACyp94Zu2zLWGVrkFNNqZcA= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from localhost.intra.ispras.ru (unknown [10.10.3.121]) by mail.ispras.ru (Postfix) with ESMTP id CD26940762D9; Sat, 24 Aug 2024 14:46:29 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 mail.ispras.ru CD26940762D9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ispras.ru; s=default; t=1724510789; bh=mthoPKdoI1UUm4jjtsjtjEyxOtwYUC4sVnHwDkdy6Tk=; h=From:To:Cc:Subject:Date:From; b=UN0/FrOjkyU7Gx1YMhPkfXAzRcmqQvu2Pq0co+Z+mYVVArwwN3oy6v9YMfWiLLdb+ GlKLHGXi7gM/9mypPNPDDCWFpECllXYxMFhwtPlROHSYg3Fd0eqDbUWn6Bv5egra8E 3e0HE7C0rzTsVTCdxAjV21bdCkLeiv6F4vJnML7Y= From: Alexander Monakov To: gcc-patches@gcc.gnu.org Cc: Alexander Monakov Subject: [PATCH] libcpp: deduplicate definition of padding size Date: Sat, 24 Aug 2024 17:46:26 +0300 Message-ID: <20240824144626.6646-1-amonakov@ispras.ru> X-Mailer: git-send-email 2.44.2 MIME-Version: 1.0 X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org Tie together the two functions that ensure tail padding with search_line_ssse3 via CPP_BUFFER_PADDING macro. libcpp/ChangeLog: * internal.h (CPP_BUFFER_PADDING): New macro; use it ... * charset.cc (_cpp_convert_input): ...here, and ... * files.cc (read_file_guts): ...here, and ... * lex.cc (search_line_ssse3): here. --- libcpp/charset.cc | 7 +------ libcpp/files.cc | 6 +----- libcpp/internal.h | 7 +++++++ libcpp/lex.cc | 4 ++-- 4 files changed, 11 insertions(+), 13 deletions(-) diff --git a/libcpp/charset.cc b/libcpp/charset.cc index 79072877cb..fd57f61398 100644 --- a/libcpp/charset.cc +++ b/libcpp/charset.cc @@ -3093,7 +3093,7 @@ _cpp_convert_input (cpp_reader *pfile, const char *input_charset, struct cset_converter input_cset; struct _cpp_strbuf to; unsigned char *buffer; - size_t pad; + size_t pad = CPP_BUFFER_PADDING; input_cset = init_iconv_desc (pfile, SOURCE_CHARSET, input_charset); if (input_cset.func == convert_no_conversion) @@ -3130,11 +3130,6 @@ _cpp_convert_input (cpp_reader *pfile, const char *input_charset, } } -#ifdef HAVE_SSSE3 - pad = 64; -#else - pad = 16; -#endif /* Resize buffer if we allocated substantially too much, or if we don't have enough space for the following padding, which allows search_line_fast to use (possibly misaligned) vector loads. */ diff --git a/libcpp/files.cc b/libcpp/files.cc index 3775091d25..fc66b9c3d7 100644 --- a/libcpp/files.cc +++ b/libcpp/files.cc @@ -732,11 +732,7 @@ read_file_guts (cpp_reader *pfile, _cpp_file *file, location_t loc, the majority of C source files. */ size = 8 * 1024; -#ifdef HAVE_SSSE3 - pad = 64; -#else - pad = 16; -#endif + pad = CPP_BUFFER_PADDING; /* The '+ PAD' here is space for the final '\n' and PAD-1 bytes of padding, allowing search_line_fast to use (possibly misaligned) vector loads. */ buf = XNEWVEC (uchar, size + pad); diff --git a/libcpp/internal.h b/libcpp/internal.h index a20215c570..ad0a5d5d4e 100644 --- a/libcpp/internal.h +++ b/libcpp/internal.h @@ -322,6 +322,13 @@ struct _cpp_line_note unsigned int type; }; +/* Tail padding required by search_line_fast alternatives. */ +#ifdef HAVE_SSSE3 +#define CPP_BUFFER_PADDING 64 +#else +#define CPP_BUFFER_PADDING 16 +#endif + /* Represents the contents of a file cpplib has read in. */ struct cpp_buffer { diff --git a/libcpp/lex.cc b/libcpp/lex.cc index f2d47d112b..7f0f8d0773 100644 --- a/libcpp/lex.cc +++ b/libcpp/lex.cc @@ -359,8 +359,8 @@ search_line_ssse3 (const uchar *s, const uchar *end ATTRIBUTE_UNUSED) "host character encoding is ASCII"); v16qi d1, d2, t1, t2; - /* Unaligned loads. Reading beyond the final newline is safe, - since files.cc:read_file_guts pads the allocation. */ + /* Unaligned loads, potentially using padding after the final newline. */ + static_assert (CPP_BUFFER_PADDING >= 64, ""); d1 = *(const v16qi_u *)s; d2 = *(const v16qi_u *)(s + 16); unsigned m1, m2, found;