On Sat, 10 Feb 2018, Fredrik Noring wrote: > The short loop bug under certain conditions causes loops to execute > only once or twice. GCC 2.95 that shipped with Sony PS2 Linux had a > patch with the following note: > > On the R5900, we must ensure that the compiler never generates > loops that satisfy all of the following conditions: > > - a loop consists of less than equal to six instructions > (including the branch delay slot); > - a loop contains only one conditional branch instruction at > the end of the loop; > - a loop does not contain any other branch or jump instructions; > - a branch delay slot of the loop is not NOP (EE 2.9 or later). > > We need to do this because of a bug in the chip. > > Signed-off-by: Fredrik Noring <noring@xxxxxxxxxx> > --- > The exact NOP placements in this patch are provisional. Request for comment > on the method to use. I believe there are at least three alternatives: > > 1. Add #ifdefs or macros in the source code (similar to this patch). > 2. Modify the assembler to automatically insert NOPs as required. > 3. Avoid assembly and use C versions of memcpy etc. instead. > > This change has been ported from v2.6 patches. I can't tell if this is a porting artefact or whether the reason is different, but many of these loops contain more than 6 instructions already, or need fewer than 3 NOPs. Please review accordingly. Also can't this be handled automagically by GAS instead? We have similar workarounds already implemented, see e.g. `-mfix-vr4130'. Otherwise this is looking to me like a candidate for a maintenance nightmare (which the problem with getting loop instruction counts wrong in your patch is a sign of). Maciej