On Wed, Sep 25, 2024 at 12:11:52PM +0200, Jonas Oberhauser wrote: > > > Am 9/25/2024 um 12:02 PM schrieb Boqun Feng: > > Hi Jonas, > > > > Of > > course, if we are really worried about compilers being too "smart" > > Ah, I see you know me better and better... > > > we can always do the comparison in asm code, then compilers don't know > > anything of the equality between 'ptr' and 'head - head_offset'. > Yes, but then a simple compiler barrier between the comparison and returning > ptr would also do the trick, right? And maybe easier on the eyes. > The thing about putting a compiler barrier is that it will prevent all compiler reorderings, and some of the reordering may contribute to better codegen. (I know in this case, we have a smp_mb(), but still compilers can move unrelated code upto the second load for optimization purpose). Asm comparison is cheaper in this way. But TBH, compilers should provide a way to compare pointer values without using the result for pointer equality proof, if "convert to unsigned long" doesn't work, some other ways should work. Regards, Boqun > > Have fun, > jonas >