Message ID | 1505745774-29303-2-git-send-email-adhemerval.zanella@linaro.org |
---|---|
State | Dropped |
Headers |
Received: (qmail 26646 invoked by alias); 18 Sep 2017 14:43:08 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: <libc-alpha.sourceware.org> List-Unsubscribe: <mailto:libc-alpha-unsubscribe-##L=##H@sourceware.org> List-Subscribe: <mailto:libc-alpha-subscribe@sourceware.org> List-Archive: <http://sourceware.org/ml/libc-alpha/> List-Post: <mailto:libc-alpha@sourceware.org> List-Help: <mailto:libc-alpha-help@sourceware.org>, <http://sourceware.org/ml/#faqs> Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 25309 invoked by uid 89); 18 Sep 2017 14:43:07 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-27.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_LOW, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-qt0-f181.google.com X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=xX5XtwVwSQxL89L5UfdtATIw2jrxOLknUzTWLh+A7G4=; b=iRy4P0WFSjwP2ivBABJSrSd52OZUEgvw1u/YPhQiD+7m0S4O6bK5FQ2WuRl/Gasbrm Zwafbg1J6LusA64Axy/2X/AL3xho8XNEwqqKAcx7MiO39rkyy7Y7PXP9fGZ6Cc5DKYdj +mLgF2CXAa+kOGBbl6pKdJa4HaViYFtDbDkzh/bx6a2ZigcFgeTJp1rLTAz10R56gET7 lliH2ANht2i7cGM31A7FhhjT+vmNbb9gq/ZGbMaH1YwlhsnSAXvVR9jmGwMp5LrJ9TGr EKjRBQ8flxXMReGFPCri2cr/rk8GucwERiQsd6r5hV+NjyM9lnBHDMFGJLrHdFpILGkO jAzg== X-Gm-Message-State: AHPjjUiDxQaJ5/1XmtBYi3/mNqP/PZRO6bEUWHowggN5IgLux3ofgG1h QwGEAEYBp+KiaZjvJrhLEQ== X-Google-Smtp-Source: AOwi7QDhUepFLnPyxdF9BYQeSBrM/tgcF8pj448Lg3D6t1InwuAPhwhtpEgYQjfof0WbZnaYXLkVXg== X-Received: by 10.200.4.16 with SMTP id v16mr53093882qtg.265.1505745783621; Mon, 18 Sep 2017 07:43:03 -0700 (PDT) From: Adhemerval Zanella <adhemerval.zanella@linaro.org> To: libc-alpha@sourceware.org Subject: [PATCH 2/2] Use C11 _Alignas on scratch_buffer internal buffer Date: Mon, 18 Sep 2017 11:42:54 -0300 Message-Id: <1505745774-29303-2-git-send-email-adhemerval.zanella@linaro.org> In-Reply-To: <1505745774-29303-1-git-send-email-adhemerval.zanella@linaro.org> References: <1505745774-29303-1-git-send-email-adhemerval.zanella@linaro.org> |
Commit Message
Adhemerval Zanella
Sept. 18, 2017, 2:42 p.m. UTC
Checked on x86_64-linux-gnu. * include/scratch_buffer.h (scratch_buffer): Use C11 _Alignas on __space field definition if compiler supports it. --- ChangeLog | 3 +++ include/scratch_buffer.h | 5 +++++ 2 files changed, 8 insertions(+)
Comments
On 09/18/2017 04:42 PM, Adhemerval Zanella wrote: > Checked on x86_64-linux-gnu. > > * include/scratch_buffer.h (scratch_buffer): Use C11 _Alignas on > __space field definition if compiler supports it. > --- > ChangeLog | 3 +++ > include/scratch_buffer.h | 5 +++++ > 2 files changed, 8 insertions(+) > > diff --git a/include/scratch_buffer.h b/include/scratch_buffer.h > index bb04662..2e0c8b5 100644 > --- a/include/scratch_buffer.h > +++ b/include/scratch_buffer.h > @@ -60,13 +60,18 @@ > #include <stdbool.h> > #include <stddef.h> > #include <stdlib.h> > +#include <stdalign.h> > > /* Scratch buffer. Must be initialized with scratch_buffer_init > before its use. */ > struct scratch_buffer { > void *data; /* Pointer to the beginning of the scratch area. */ > size_t length; /* Allocated space at the data pointer, in bytes. */ > +#if __alignas_is_defined > + _Alignas (max_align_t) char __space[1024]; > +#else > max_align_t __space[(1023 + sizeof (max_align_t)) / sizeof (max_align_t)]; > +#endif Okay, I think. (Richard has spoken: The code with max_align_t is okay as well as far as GCC is concerned. But I think it's useful to keep the initial buffer size in sync on all architectures to reduce variance, so please push this change.) Thanks, Florian.
This patch could cause problems on non-GCC platforms. According to the Gnulib documentation <https://www.gnu.org/software/gnulib/manual/html_node/stdalign_002eh.html>, Sun C 5.11 supports _Alignas but not on auto variables. In practice, the unpatched scratch_buffer.h uses 1024-byte buffers everywhere, so the initial buffer size will be in sync on all platforms even without the patch. Since the patch adds complexity, seems to have no technical advantage, and has potential downsides, I suggest leaving that part of scratch_buffer.h alone.
On 09/18/2017 06:10 PM, Paul Eggert wrote: > This patch could cause problems on non-GCC platforms. According to the > Gnulib documentation > <https://www.gnu.org/software/gnulib/manual/html_node/stdalign_002eh.html>, > Sun C 5.11 supports _Alignas but not on auto variables. In practice, the > unpatched scratch_buffer.h uses 1024-byte buffers everywhere, Are you sure? sizeof (max_align_t) is 48 on i386, after all. Thanks, Florian
Florian Weimer wrote:
> Are you sure? sizeof (max_align_t) is 48 on i386, after all.
Sorry, didn't know that. We could use 1056-byte buffers instead; would that be
the same on all glibc platforms? I'm not sure how important it is that the byte
count be the same everywhere.
On Sep 18 2017, Adhemerval Zanella <adhemerval.zanella@linaro.org> wrote: > diff --git a/include/scratch_buffer.h b/include/scratch_buffer.h > index bb04662..2e0c8b5 100644 > --- a/include/scratch_buffer.h > +++ b/include/scratch_buffer.h > @@ -60,13 +60,18 @@ > #include <stdbool.h> > #include <stddef.h> > #include <stdlib.h> > +#include <stdalign.h> > > /* Scratch buffer. Must be initialized with scratch_buffer_init > before its use. */ > struct scratch_buffer { > void *data; /* Pointer to the beginning of the scratch area. */ > size_t length; /* Allocated space at the data pointer, in bytes. */ > +#if __alignas_is_defined > + _Alignas (max_align_t) char __space[1024]; > +#else > max_align_t __space[(1023 + sizeof (max_align_t)) / sizeof (max_align_t)]; > +#endif You could use a union instead. Andreas.
On 09/18/2017 06:57 PM, Paul Eggert wrote: > Florian Weimer wrote: >> Are you sure? sizeof (max_align_t) is 48 on i386, after all. > > Sorry, didn't know that. We could use 1056-byte buffers instead; would > that be the same on all glibc platforms? I'm not sure how important it > is that the byte count be the same everywhere. I've chased ghosts due to such buffer size differences. I'd like to reduce it to the 32/64 difference if possible. Thanks, Florian
Florian Weimer wrote: >> Sorry, didn't know that. We could use 1056-byte buffers instead; would that be >> the same on all glibc platforms? I'm not sure how important it is that the >> byte count be the same everywhere. > > I've chased ghosts due to such buffer size differences. I'd like to reduce it > to the 32/64 difference if possible. Then Andreas's suggestion is a good way to go. A member like this in struct scratch_buffer: union { max_align_t __a; char __c[1024]; } __space; and then use __space.__c everywhere the code currently uses __space. This will make the buffer size 1024 on all platforms where sizeof (max_align_t) <= 1024, which should be a safe assumption for all glibc platforms now.
diff --git a/include/scratch_buffer.h b/include/scratch_buffer.h index bb04662..2e0c8b5 100644 --- a/include/scratch_buffer.h +++ b/include/scratch_buffer.h @@ -60,13 +60,18 @@ #include <stdbool.h> #include <stddef.h> #include <stdlib.h> +#include <stdalign.h> /* Scratch buffer. Must be initialized with scratch_buffer_init before its use. */ struct scratch_buffer { void *data; /* Pointer to the beginning of the scratch area. */ size_t length; /* Allocated space at the data pointer, in bytes. */ +#if __alignas_is_defined + _Alignas (max_align_t) char __space[1024]; +#else max_align_t __space[(1023 + sizeof (max_align_t)) / sizeof (max_align_t)]; +#endif }; /* Initializes *BUFFER so that BUFFER->data points to BUFFER->__space