|
From: | Volker Rümelin |
Subject: | Re: [PATCH v2 01/15] audio: replace open-coded buffer arithmetic |
Date: | Tue, 1 Mar 2022 19:59:39 +0100 |
User-agent: | Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.6.1 |
Am 26.01.22 um 09:48 schrieb Gerd Hoffmann:
Hi,--- a/audio/audio_int.h +++ b/audio/audio_int.h @@ -266,6 +266,12 @@ static inline size_t audio_ring_dist(size_t dst, size_t src, size_t len) return (dst >= src) ? (dst - src) : (len - src + dst); }You haven't touched this function, but while I am looking at it, all function arguments are unsigned. So probably modulo operator might be used to get rid of a branch here.That would be "return (len - dist + pos) % len;" but on my x86_64 system I always prefer a conditional move instruction to a 64 bit integer division instruction.Why? Performance? Don't underestimate the optimizer of a modern compiler. In many cases it simply isn't worth the effort. Better optimize the code for humans, i.e. make it easy to read and understand.
I know this micro optimization is useless. I will not try to defend it because there are no good reasons for it. But I can't see that "return (len - dist + pos) % len;" is more readable than "return pos >= dist ? pos - dist : len - dist + pos;".
With best regards Volker
take care, Gerd
[Prev in Thread] | Current Thread | [Next in Thread] |