Skip to content

Commit 26751de

Browse files
rmurphy-armbroonie
authored andcommitted
spi: bcm2835: Micro-optimise FIFO loops
The blind and counted loops are always called with nonzero count, so convert them to do-while loops that lead to slightly more efficient code generation. With GCC 8.3 this shaves off 1-2 instructions per iteration in each case. Signed-off-by: Robin Murphy <[email protected]> Link: https://lore.kernel.org/r/9242863077acf9a64e4b3720e479855b88d19e82.1592261248.git.robin.murphy@arm.com Signed-off-by: Mark Brown <[email protected]>
1 parent afe7e36 commit 26751de

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

drivers/spi/spi-bcm2835.c

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -245,13 +245,13 @@ static inline void bcm2835_rd_fifo_count(struct bcm2835_spi *bs, int count)
245245

246246
bs->rx_len -= count;
247247

248-
while (count > 0) {
248+
do {
249249
val = bcm2835_rd(bs, BCM2835_SPI_FIFO);
250250
len = min(count, 4);
251251
memcpy(bs->rx_buf, &val, len);
252252
bs->rx_buf += len;
253253
count -= 4;
254-
}
254+
} while (count > 0);
255255
}
256256

257257
/**
@@ -271,7 +271,7 @@ static inline void bcm2835_wr_fifo_count(struct bcm2835_spi *bs, int count)
271271

272272
bs->tx_len -= count;
273273

274-
while (count > 0) {
274+
do {
275275
if (bs->tx_buf) {
276276
len = min(count, 4);
277277
memcpy(&val, bs->tx_buf, len);
@@ -281,7 +281,7 @@ static inline void bcm2835_wr_fifo_count(struct bcm2835_spi *bs, int count)
281281
}
282282
bcm2835_wr(bs, BCM2835_SPI_FIFO, val);
283283
count -= 4;
284-
}
284+
} while (count > 0);
285285
}
286286

287287
/**
@@ -310,12 +310,11 @@ static inline void bcm2835_rd_fifo_blind(struct bcm2835_spi *bs, int count)
310310
count = min(count, bs->rx_len);
311311
bs->rx_len -= count;
312312

313-
while (count) {
313+
do {
314314
val = bcm2835_rd(bs, BCM2835_SPI_FIFO);
315315
if (bs->rx_buf)
316316
*bs->rx_buf++ = val;
317-
count--;
318-
}
317+
} while (--count);
319318
}
320319

321320
/**
@@ -330,11 +329,10 @@ static inline void bcm2835_wr_fifo_blind(struct bcm2835_spi *bs, int count)
330329
count = min(count, bs->tx_len);
331330
bs->tx_len -= count;
332331

333-
while (count) {
332+
do {
334333
val = bs->tx_buf ? *bs->tx_buf++ : 0;
335334
bcm2835_wr(bs, BCM2835_SPI_FIFO, val);
336-
count--;
337-
}
335+
} while (--count);
338336
}
339337

340338
static void bcm2835_spi_reset_hw(struct bcm2835_spi *bs)

0 commit comments

Comments
 (0)