[PATCH 06/25] Add struct scratch_buffer and its internal helper functions

Florian Weimer fweimer@redhat.com
Mon Mar 23 16:14:00 GMT 2015


On 03/20/2015 05:29 PM, Paul Eggert wrote:
> Florian Weimer wrote:
>>>> +#define SCRATCH_BUFFER_ALIGNMENT \
>>>> +  __attribute__ ((aligned (__alignof__ (union {void *p; double d;}))))
>>>
>>> This should use __attribute__ ((aligned (alignof (max_align_t)))), at
>>> least on C11 platforms.
>>
>> Hmm.  Isn't intmax_t enough?
> 
> I don't know about all the platforms, but in theory C11 says one should
> use max_align_t and that types other than intmax_t might have alignments
> stricter than that needed by intmax_t.

Commit 75b4202ab03337edb37536e3d9470a48a04c9341 used __alignof__
(unsigned long long).  I would rather go with intmax_t because it's not
clear to me if __alignof__ (max_align_t) increases to 64 if AVX-512 is
enabled on x86_64.

>> /* Grows *BUFFER so that it can store at least NELEM elements of SIZE
> 
> Grows -> grow

I think you mean “Grow”.  I fixed the other occurrences of the finite
forms as well.

>>     bytes.  The buffer contents is NOT preserved.  Both NELEM and SIZE
> 
> is NOT -> are NOT

Okay.

>> Empirically, I'm pretty certain the division does not matter
>> performance-wise.
> 
> Even on platforms where integer division is a subroutine?  Perhaps glibc
> isn't meant for such platforms, but still....

Even there, because you'll have at least 64K array elements, and the
division will be amortized across all that. :)

Do you think this is ready to commit now?  Does anyone else want to
comment on the new internal interfaces?

	* include/scratch_buffer.h: New file.
	* malloc/scratch_buffer_grow.c: Likewise.
	* malloc/scratch_buffer_grow_preserve.c: Likewise.
	* malloc/scratch_buffer_set_array_size.c: Likewise.
	* malloc/tst-scratch_buffer.c: Likewise.
	* malloc/Makefile (routines): Add scratch_buffer_grow.
	(tests): Add test case.
	* misc/Versions (GLIBC_PRIVATE): Export
	__libc_scratch_buffer_grow, __libc_scratch_buffer_grow_preserve,
	__libc_scratch_buffer_set_array_size.

-- 
Florian Weimer / Red Hat Product Security
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Add-struct-scratch_buffer-and-its-internal-helper-fu.patch
Type: text/x-patch
Size: 18857 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/libc-alpha/attachments/20150323/21528d14/attachment.bin>


More information about the Libc-alpha mailing list