Skip to content

Commit fcfe18f

Browse files
d4ddi0gregkh
authored andcommitted
fpga-manager: altera-ps-spi: use bitrev8x4
Speed up bit reversal by using hardware bit reversal Add extra code to handle less than 4byte remnants, if any Signed-off-by: Joshua Clayton <stillcompiling@gmail.com> Signed-off-by: Alan Tull <atull@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 3b88da4 commit fcfe18f

1 file changed

Lines changed: 15 additions & 4 deletions

File tree

‎drivers/fpga/altera-ps-spi.c‎

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,23 @@ static int altera_ps_write_init(struct fpga_manager *mgr,
149149

150150
static void rev_buf(char *buf, size_t len)
151151
{
152-
const char *fw_end = (buf + len);
152+
u32 *fw32 = (u32 *)buf;
153+
size_t extra_bytes = (len & 0x03);
154+
const u32 *fw_end = (u32 *)(buf + len - extra_bytes);
153155

154156
/* set buffer to lsb first */
155-
while (buf < fw_end) {
156-
*buf = bitrev8(*buf);
157-
buf++;
157+
while (fw32 < fw_end) {
158+
*fw32 = bitrev8x4(*fw32);
159+
fw32++;
160+
}
161+
162+
if (extra_bytes) {
163+
buf = (char *)fw_end;
164+
while (extra_bytes) {
165+
*buf = bitrev8(*buf);
166+
buf++;
167+
extra_bytes--;
168+
}
158169
}
159170
}
160171

0 commit comments

Comments
 (0)