On Wed, 18 Jul 2012, Justin Ruggles wrote:
> On 07/18/2012 05:15 AM, Loren Merritt wrote:
>>
>> Aha, a large part of the discrepancy is due to cache aliasing, when the
>> offsets between the 6 output streams are divisible by some large power of
>> 2. This would have to be fixed in whatever piece of code allocates audio
>> buffers, not in the asm.
>>
>> Incidentally, video codecs have the same problem with strides. Do we
>> address that anywhere?
>
> I have to admit that I don't really know much about cache aliasing. If
> avoiding power of 2 offset between plane pointers would fix it, that
> could easily be done in the utility functions for allocating audio
> buffers. Currently we pad plane size to a multiple of 32 samples in
> whatever the sample format is. So, after adding the padding, we could
> do something like:
>
> while (av_popcount(plane_size) == 1 && plane_size >= LARGE_POWER_OF_2)
>     plane_size += size_of_32_samples;

Why 32 samples? Is anything 32x unrolled? And if it is for unrolling, then
the additional padding doesn't need to maintain that alignment, because it
won't cause any extra loop iterations.

This makes conv_flt_to_fltp_6ch(len=1536) 5x faster on bulldozer, 9% on
sandybridge. Haven't benched other audio functions.

---
 libavutil/samplefmt.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/libavutil/samplefmt.c b/libavutil/samplefmt.c
index b6e785c..3b9b17d 100644
--- a/libavutil/samplefmt.c
+++ b/libavutil/samplefmt.c
@@ -136,6 +136,8 @@ int av_samples_get_buffer_size(int *linesize, int 
nb_channels, int nb_samples,

     line_size = planar ? FFALIGN(nb_samples * sample_size,               
align) :
                          FFALIGN(nb_samples * sample_size * nb_channels, 
align);
+    if (planar && !(line_size & 0x3c0))
+        line_size += 64; // avoid cache aliasing
     if (linesize)
         *linesize = line_size;

-- 
1.7.4.1

--Loren Merritt
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to