Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754788AbcC0G4b (ORCPT ); Sun, 27 Mar 2016 02:56:31 -0400 Received: from mail-pf0-f195.google.com ([209.85.192.195]:34583 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752338AbcC0G4X (ORCPT ); Sun, 27 Mar 2016 02:56:23 -0400 Subject: [PATCH 13/31] mips: use parity functions in cerr-sb1.c To: Ralf Baechle References: <1458788612-4367-1-git-send-email-zhaoxiu.zeng@gmail.com> Cc: linux-kernel@vger.kernel.org, linux-mips@linux-mips.org From: "zhaoxiu.zeng" Message-ID: <56F783FE.6080304@gmail.com> Date: Sun, 27 Mar 2016 14:55:58 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.7.1 MIME-Version: 1.0 In-Reply-To: <1458788612-4367-1-git-send-email-zhaoxiu.zeng@gmail.com> Content-Type: text/plain; charset=gbk Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3419 Lines: 114 From: Zeng Zhaoxiu Signed-off-by: Zeng Zhaoxiu --- arch/mips/mm/cerr-sb1.c | 67 +++++++++++++------------------------------------ 1 file changed, 17 insertions(+), 50 deletions(-) diff --git a/arch/mips/mm/cerr-sb1.c b/arch/mips/mm/cerr-sb1.c index ee5c1ff..2e7d660 100644 --- a/arch/mips/mm/cerr-sb1.c +++ b/arch/mips/mm/cerr-sb1.c @@ -264,27 +264,6 @@ asmlinkage void sb1_cache_error(void) #endif } - -/* Parity lookup table. */ -static const uint8_t parity[256] = { - 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, - 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, - 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, - 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, - 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, - 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, - 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, - 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, - 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, - 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, - 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, - 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, - 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, - 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, - 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, - 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0 -}; - /* Masks to select bits for Hamming parity, mask_72_64[i] for bit[i] */ static const uint64_t mask_72_64[8] = { 0x0738C808099264FFULL, @@ -298,34 +277,28 @@ static const uint64_t mask_72_64[8] = { }; /* Calculate the parity on a range of bits */ -static char range_parity(uint64_t dword, int max, int min) +static inline char range_parity(uint64_t dword, int max, int min) { - char parity = 0; - int i; - dword >>= min; - for (i=max-min; i>=0; i--) { - if (dword & 0x1) - parity = !parity; - dword >>= 1; + int n = max - min + 1; + if (__builtin_constant_p(n)) { + if (n <= 8) + return parity8((unsigned int)(dword >> min) & ((1U << n) - 1)); + if (n <= 16) + return parity16((unsigned int)(dword >> min) & ((1U << n) - 1)); + if (n <= 32) + return parity32((unsigned int)(dword >> min) & ((1U << n) - 1)); } - return parity; + return parity64((dword >> min) & ((1ULL << n) - 1)); } /* Calculate the 4-bit even byte-parity for an instruction */ -static unsigned char inst_parity(uint32_t word) +static inline unsigned char inst_parity(uint32_t word) { - int i, j; - char parity = 0; - for (j=0; j<4; j++) { - char byte_parity = 0; - for (i=0; i<8; i++) { - if (word & 0x80000000) - byte_parity = !byte_parity; - word <<= 1; - } - parity <<= 1; - parity |= byte_parity; - } + char parity; + parity = parity8(word >> 24) << 3; + parity |= parity8(word >> 16) << 2; + parity |= parity8(word >> 8) << 1; + parity |= parity8(word); return parity; } @@ -436,7 +409,6 @@ static uint32_t extract_ic(unsigned short addr, int data) static uint8_t dc_ecc(uint64_t dword) { uint64_t t; - uint32_t w; uint8_t p; int i; @@ -445,12 +417,7 @@ static uint8_t dc_ecc(uint64_t dword) { p <<= 1; t = dword & mask_72_64[i]; - w = (uint32_t)(t >> 32); - p ^= (parity[w>>24] ^ parity[(w>>16) & 0xFF] - ^ parity[(w>>8) & 0xFF] ^ parity[w & 0xFF]); - w = (uint32_t)(t & 0xFFFFFFFF); - p ^= (parity[w>>24] ^ parity[(w>>16) & 0xFF] - ^ parity[(w>>8) & 0xFF] ^ parity[w & 0xFF]); + p |= parity64(t); } return p; } -- 2.5.5