Skip to content

Commit

Permalink
xtensa: fix __delay for small loop count
Browse files Browse the repository at this point in the history
Avoid __delay counter underflow for loop counts < 2.

Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
Signed-off-by: Chris Zankel <chris@zankel.net>
  • Loading branch information
Max Filippov authored and Chris Zankel committed Jan 14, 2014
1 parent 5515daa commit 01e3b3c
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions arch/xtensa/include/asm/delay.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@ extern unsigned long loops_per_jiffy;

static inline void __delay(unsigned long loops)
{
/* 2 cycles per loop. */
__asm__ __volatile__ ("1: addi %0, %0, -2; bgeui %0, 2, 1b"
: "=r" (loops) : "0" (loops));
if (__builtin_constant_p(loops) && loops < 2)
__asm__ __volatile__ ("nop");
else if (loops >= 2)
/* 2 cycles per loop. */
__asm__ __volatile__ ("1: addi %0, %0, -2; bgeui %0, 2, 1b"
: "+r" (loops));
}

/* For SMP/NUMA systems, change boot_cpu_data to something like
Expand Down

0 comments on commit 01e3b3c

Please sign in to comment.