aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Monakov <amonakov@ispras.ru>2024-08-24 17:37:13 +0300
committerAlexander Monakov <amonakov@ispras.ru>2024-08-26 16:05:48 +0300
commita8260ebeae0f817bc7adf99cf62b604b1e2d3895 (patch)
treed54443ac051ac7ba4f1e457709b90aba1995a51d
parent0ceeb9926d69dbb382622a8eae9eef7ed8ac3e97 (diff)
downloadgcc-a8260ebeae0f817bc7adf99cf62b604b1e2d3895.zip
gcc-a8260ebeae0f817bc7adf99cf62b604b1e2d3895.tar.gz
gcc-a8260ebeae0f817bc7adf99cf62b604b1e2d3895.tar.bz2
libcpp: deduplicate definition of padding size
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.
-rw-r--r--libcpp/charset.cc7
-rw-r--r--libcpp/files.cc6
-rw-r--r--libcpp/internal.h7
-rw-r--r--libcpp/lex.cc4
4 files changed, 11 insertions, 13 deletions
diff --git a/libcpp/charset.cc b/libcpp/charset.cc
index 7907287..fd57f61 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 3775091..fc66b9c 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 a20215c..ad0a5d5 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 f2d47d1..7f0f8d0 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;