Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751439AbdFETH1 (ORCPT ); Mon, 5 Jun 2017 15:07:27 -0400 Received: from mail.kernel.org ([198.145.29.99]:44772 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751395AbdFETHY (ORCPT ); Mon, 5 Jun 2017 15:07:24 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5B9D323A4F Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=atull@kernel.org From: Alan Tull To: Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org, linux-fpga@vger.kernel.org, Moritz Fischer , delicious.quinoa@gmail.com, Joshua Clayton , Alan Tull Subject: [PATCH 09/10] fpga-manager: altera-ps-spi: use bitrev8x4 Date: Mon, 5 Jun 2017 14:07:40 -0500 Message-Id: <20170605190741.10508-10-atull@kernel.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170605190741.10508-1-atull@kernel.org> References: <20170605190741.10508-1-atull@kernel.org> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1157 Lines: 45 From: Joshua Clayton 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 Signed-off-by: Alan Tull --- drivers/fpga/altera-ps-spi.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/drivers/fpga/altera-ps-spi.c b/drivers/fpga/altera-ps-spi.c index 0db8def668ed..14f14efdf0d5 100644 --- a/drivers/fpga/altera-ps-spi.c +++ b/drivers/fpga/altera-ps-spi.c @@ -149,12 +149,23 @@ static int altera_ps_write_init(struct fpga_manager *mgr, static void rev_buf(char *buf, size_t len) { - const char *fw_end = (buf + len); + u32 *fw32 = (u32 *)buf; + size_t extra_bytes = (len & 0x03); + const u32 *fw_end = (u32 *)(buf + len - extra_bytes); /* set buffer to lsb first */ - while (buf < fw_end) { - *buf = bitrev8(*buf); - buf++; + while (fw32 < fw_end) { + *fw32 = bitrev8x4(*fw32); + fw32++; + } + + if (extra_bytes) { + buf = (char *)fw_end; + while (extra_bytes) { + *buf = bitrev8(*buf); + buf++; + extra_bytes--; + } } } -- 2.11.0