This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Variations of memset()


On 08/04/2017 10:57 PM, Joseph Myers wrote:
> On Fri, 4 Aug 2017, Matthew Wilcox wrote:
> 
>> void *memset16(uint16_t *s, uint16_t v, size_t count);
>> void *memset32(uint32_t *s, uint32_t v, size_t count);
>> void *memset64(uint64_t *s, uint64_t v, size_t count);
> 
> Is your assertion that there are useful optimizations for these that 
> result in code too large for it to make sense for the compiler to inline 
> it, so an out-of-line function call is appropriate instead?  I'd expect 
> the compiler to vectorize memset-like loops where appropriate, inline, 
> without needing such functions.

Small-scale vectorization doesn't work well in practice because most
current Intel CPUs have very high startup costs for using vector
instructions.  To some degree, this applies to AVX2 as well, but it is
allegedly quite visible with AVX512, leading to a reduction in overall
system throughput:

  <https://sourceware.org/ml/libc-alpha/2017-04/msg00325.html>

> Or is the desire to use IFUNCs for such 
> functions so code can be optimized for the processor it is running on, 
> without needing to be compiled for each processor with different vector 
> instructions that should be used?

It's also system-specific.  Whether the more recent vector instructions
help depends a lot on the overall workload on the system.  My current
impression is that auto-vectorization beyond SSE2 is extremely tricky
and probably not worth it for generic/pre-compiled software.

On the other hand, if you deploy on other people's machines, you might
not care that you negatively impact overall system performance, as long
as you squeeze out a few more percent for yourself.  Based on the media
reports I have read (and the patch I referenced above), AVX512 in
particular gives rise to a prisoners' dilemma in this context. 8-(

Thanks,
Florian


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]