[patch V4 13/31] media: use parity8 in vivid-vbi-gen.c
From: Zhaoxiu ZengSigned-off-by: Zhaoxiu Zeng --- drivers/media/platform/vivid/vivid-vbi-gen.c | 9 ++--- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/drivers/media/platform/vivid/vivid-vbi-gen.c b/drivers/media/platform/vivid/vivid-vbi-gen.c index a2159de..d5ba0fc 100644 --- a/drivers/media/platform/vivid/vivid-vbi-gen.c +++ b/drivers/media/platform/vivid/vivid-vbi-gen.c @@ -175,14 +175,9 @@ static const u8 vivid_cc_sequence2[30] = { 0x14, 0x2f, /* End of Caption */ }; -static u8 calc_parity(u8 val) +static inline u8 calc_parity(u8 val) { - unsigned i; - unsigned tot = 0; - - for (i = 0; i < 7; i++) - tot += (val & (1 << i)) ? 1 : 0; - return val | ((tot & 1) ? 0 : 0x80); + return (!parity8(val) << 7) | val; } static void vivid_vbi_gen_set_time_of_day(u8 *packet) -- 2.7.4 -- To unsubscribe from this list: send the line "unsubscribe linux-media" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[patch V4 14/31] media: use parity functions in saa7115
From: Zhaoxiu ZengSigned-off-by: Zhaoxiu Zeng --- drivers/media/i2c/saa7115.c | 17 ++--- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/drivers/media/i2c/saa7115.c b/drivers/media/i2c/saa7115.c index d2a1ce2..4c22df8 100644 --- a/drivers/media/i2c/saa7115.c +++ b/drivers/media/i2c/saa7115.c @@ -672,15 +672,6 @@ static const unsigned char saa7115_init_misc[] = { 0x00, 0x00 }; -static int saa711x_odd_parity(u8 c) -{ - c ^= (c >> 4); - c ^= (c >> 2); - c ^= (c >> 1); - - return c & 1; -} - static int saa711x_decode_vps(u8 *dst, u8 *p) { static const u8 biphase_tbl[] = { @@ -733,7 +724,6 @@ static int saa711x_decode_wss(u8 *p) static const int wss_bits[8] = { 0, 0, 0, 1, 0, 1, 1, 1 }; - unsigned char parity; int wss = 0; int i; @@ -745,11 +735,8 @@ static int saa711x_decode_wss(u8 *p) return -1; wss |= b2 << i; } - parity = wss & 15; - parity ^= parity >> 2; - parity ^= parity >> 1; - if (!(parity & 1)) + if (!parity4(wss)) return -1; return wss; @@ -1235,7 +1222,7 @@ static int saa711x_decode_vbi_line(struct v4l2_subdev *sd, struct v4l2_decode_vb vbi->type = V4L2_SLICED_TELETEXT_B; break; case 4: - if (!saa711x_odd_parity(p[0]) || !saa711x_odd_parity(p[1])) + if (!parity8(p[0]) || !parity8(p[1])) return 0; vbi->type = V4L2_SLICED_CAPTION_525; break; -- 2.7.4 -- To unsubscribe from this list: send the line "unsubscribe linux-media" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[patch V4 00/31] bitops: add parity functions
From: Zhaoxiu ZengWhen I do "grep parity -r linux", I found many parity calculations distributed in many drivers. This patch series does: 1. provide generic and architecture-specific parity calculations 2. remove drivers' local parity calculations, use bitops' parity functions instead 3. replace "hweightN(x) & 1" with "parityN(x)" to improve readability, and improve performance on some CPUs that without popcount support I did not use GCC's __builtin_parity* functions, based on the following reasons: 1. I don't know where to identify which version of GCC from the beginning supported __builtin_parity for the architecture. 2. For the architecture that doesn't has popcount instruction, GCC instead use "call __paritysi2" (__paritydi2 for 64-bits). So if use __builtin_parity, we must provide __paritysi2 and __paritydi2 functions for these architectures. Additionally, parity4,8,16 might be "__builtin_parity(x & mask)", but the "& mask" operation is totally unnecessary. 3. For the architecture that has popcount instruction, we do the same things as GCC. 4. For powerpc, sparc, and x86, we do runtime patching to use popcount instruction if the CPU support. I have compiled successfully with x86_64_defconfig, i386_defconfig, pseries_defconfig and sparc64_defconfig. Changes to V3: - Remove "odd" and "even" from documents. The function parityN returns whether an odd or even number of bits are on in a N-bit word, does not involve the definition of odd/even parity. Is it an odd or even parity checking, depends on the caller's context. - Replace "hweightN(x) % 2" with "parityN(x)" in crypto/sahara.c and edac/amd64_edac.c - Use PARITY_MAGIC instead of 0x6996 in powerpc's parity_64.S - Use PARITY_MAGIC instead of 0x6996 in sparc's parity.S - Pick up ACKs Changes to v2: - X86, remove custom calling convention, use inline asm - Add constant PARITY_MAGIC (proposals by Sam Ravnborg) - Add include/asm-generic/bitops/popc-parity.h (proposals by Chris Metcalf) - Tile uses popc-parity.h directly - Mips uses popc-parity.h if has usable __builtin_popcount - Add few comments in powerpc's and sparc's parity.S Changes to v1: - Add runtime patching for powerpc, sparc, and x86 - Avr32 use grenric parity too - Fix error in ssfdc's patch, and add commit message - Don't change the original code composition of adxrs450.c - Directly assignement to phy_cap.parity in drivers/scsi/isci/phy.c Regards, === diffstat === Zhaoxiu Zeng (31): bitops: add parity functions bitops: Include generic parity.h in some architectures' bitops.h bitops: Add alpha-specific parity functions bitops: Add blackfin-specific parity functions bitops: Add ia-specific parity functions bitops: Tile and MIPS (if has usable __builtin_popcount) use popcount parity functions bitops: Add powerpc-specific parity functions bitops: Add sparc-specific parity functions bitops: Add x86-specific parity functions sunrpc: use parity8 mips: use parity functions in cerr-sb1.c lib: bch: use parity32 media: use parity8 in vivid-vbi-gen.c media: use parity functions in saa7115 input: use parity32 in grip_mp input: use parity64 in sidewinder input: use parity16 in ams_delta_serio scsi: use parity32 in isci's phy mtd: use parity16 in ssfdc mtd: use parity functions in inftlcore crypto: use parity functions in qat_hal mtd: use parity16 in sm_ftl ethernet: use parity8 in sun/niu.c input: use parity8 in pcips2 input: use parity8 in saps2 iio: use parity32 in adxrs450 serial: use parity32 in max3100 input: use parity8 in elantech ethernet: use parity8 in broadcom/tg3.c crypto: use parity_long is sahara.c edac: use parity8 in amd64_edac.c arch/alpha/include/asm/bitops.h | 27 + arch/arc/include/asm/bitops.h| 1 + arch/arm/include/asm/bitops.h| 1 + arch/arm64/include/asm/bitops.h | 1 + arch/avr32/include/asm/bitops.h | 1 + arch/blackfin/include/asm/bitops.h | 31 ++ arch/c6x/include/asm/bitops.h| 1 + arch/cris/include/asm/bitops.h | 1 + arch/frv/include/asm/bitops.h| 1 + arch/h8300/include/asm/bitops.h | 1 + arch/hexagon/include/asm/bitops.h| 1 + arch/ia64/include/asm/bitops.h | 31 ++ arch/m32r/include/asm/bitops.h | 1 + arch/m68k/include/asm/bitops.h | 1 + arch/metag/include/asm/bitops.h | 1 + arch/mips/include/asm/bitops.h | 7 ++ arch/mips/mm/cerr-sb1.c | 67 - arch/mn10300/include/asm/bitops.h| 1 + arch/openrisc/include/asm/bitops.h | 1 + arch/parisc/include/asm/bitops.h | 1 + arch/powerpc/include/asm/bitops.h| 11 +++ arch/powerpc/lib/Makefile| 2
[PATCH] media: tuner: mt2063: use lib gcd
From: Zhaoxiu ZengThis patch removes the local MT2063_gcd function, uses lib gcd instead Signed-off-by: Zhaoxiu Zeng --- drivers/media/tuners/mt2063.c | 30 +- 1 file changed, 5 insertions(+), 25 deletions(-) diff --git a/drivers/media/tuners/mt2063.c b/drivers/media/tuners/mt2063.c index 6457ac9..7f0b9d5 100644 --- a/drivers/media/tuners/mt2063.c +++ b/drivers/media/tuners/mt2063.c @@ -24,6 +24,7 @@ #include #include #include +#include #include "mt2063.h" @@ -665,27 +666,6 @@ static u32 MT2063_ChooseFirstIF(struct MT2063_AvoidSpursData_t *pAS_Info) } /** - * gcd() - Uses Euclid's algorithm - * - * @u, @v: Unsigned values whose GCD is desired. - * - * Returns THE greatest common divisor of u and v, if either value is 0, - * the other value is returned as the result. - */ -static u32 MT2063_gcd(u32 u, u32 v) -{ - u32 r; - - while (v != 0) { - r = u % v; - u = v; - v = r; - } - - return u; -} - -/** * IsSpurInBand() - Checks to see if a spur will be present within the IF's * bandwidth. (fIFOut +/- fIFBW, -fIFOut +/- fIFBW) * @@ -731,12 +711,12 @@ static u32 IsSpurInBand(struct MT2063_AvoidSpursData_t *pAS_Info, ** of f_LO1, f_LO2 and the edge value. Use the larger of this ** gcd-based scale factor or f_Scale. */ - lo_gcd = MT2063_gcd(f_LO1, f_LO2); - gd_Scale = max((u32) MT2063_gcd(lo_gcd, d), f_Scale); + lo_gcd = gcd(f_LO1, f_LO2); + gd_Scale = max((u32) gcd(lo_gcd, d), f_Scale); hgds = gd_Scale / 2; - gc_Scale = max((u32) MT2063_gcd(lo_gcd, c), f_Scale); + gc_Scale = max((u32) gcd(lo_gcd, c), f_Scale); hgcs = gc_Scale / 2; - gf_Scale = max((u32) MT2063_gcd(lo_gcd, f), f_Scale); + gf_Scale = max((u32) gcd(lo_gcd, f), f_Scale); hgfs = gf_Scale / 2; n0 = DIV_ROUND_UP(f_LO2 - d, f_LO1 - f_LO2); -- 2.5.0 -- To unsubscribe from this list: send the line "unsubscribe linux-media" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH V3 13/29] media: use parity8 in vivid-vbi-gen.c
From: Zhaoxiu ZengSigned-off-by: Zhaoxiu Zeng --- drivers/media/platform/vivid/vivid-vbi-gen.c | 9 ++--- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/drivers/media/platform/vivid/vivid-vbi-gen.c b/drivers/media/platform/vivid/vivid-vbi-gen.c index a2159de..d5ba0fc 100644 --- a/drivers/media/platform/vivid/vivid-vbi-gen.c +++ b/drivers/media/platform/vivid/vivid-vbi-gen.c @@ -175,14 +175,9 @@ static const u8 vivid_cc_sequence2[30] = { 0x14, 0x2f, /* End of Caption */ }; -static u8 calc_parity(u8 val) +static inline u8 calc_parity(u8 val) { - unsigned i; - unsigned tot = 0; - - for (i = 0; i < 7; i++) - tot += (val & (1 << i)) ? 1 : 0; - return val | ((tot & 1) ? 0 : 0x80); + return (!parity8(val) << 7) | val; } static void vivid_vbi_gen_set_time_of_day(u8 *packet) -- 2.5.0 -- To unsubscribe from this list: send the line "unsubscribe linux-media" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH V3 14/29] media: use parity functions in saa7115
From: Zhaoxiu ZengSigned-off-by: Zhaoxiu Zeng --- drivers/media/i2c/saa7115.c | 17 ++--- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/drivers/media/i2c/saa7115.c b/drivers/media/i2c/saa7115.c index d2a1ce2..4c22df8 100644 --- a/drivers/media/i2c/saa7115.c +++ b/drivers/media/i2c/saa7115.c @@ -672,15 +672,6 @@ static const unsigned char saa7115_init_misc[] = { 0x00, 0x00 }; -static int saa711x_odd_parity(u8 c) -{ - c ^= (c >> 4); - c ^= (c >> 2); - c ^= (c >> 1); - - return c & 1; -} - static int saa711x_decode_vps(u8 *dst, u8 *p) { static const u8 biphase_tbl[] = { @@ -733,7 +724,6 @@ static int saa711x_decode_wss(u8 *p) static const int wss_bits[8] = { 0, 0, 0, 1, 0, 1, 1, 1 }; - unsigned char parity; int wss = 0; int i; @@ -745,11 +735,8 @@ static int saa711x_decode_wss(u8 *p) return -1; wss |= b2 << i; } - parity = wss & 15; - parity ^= parity >> 2; - parity ^= parity >> 1; - if (!(parity & 1)) + if (!parity4(wss)) return -1; return wss; @@ -1235,7 +1222,7 @@ static int saa711x_decode_vbi_line(struct v4l2_subdev *sd, struct v4l2_decode_vb vbi->type = V4L2_SLICED_TELETEXT_B; break; case 4: - if (!saa711x_odd_parity(p[0]) || !saa711x_odd_parity(p[1])) + if (!parity8(p[0]) || !parity8(p[1])) return 0; vbi->type = V4L2_SLICED_CAPTION_525; break; -- 2.5.0 -- To unsubscribe from this list: send the line "unsubscribe linux-media" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v2 14/30] media: use parity8 in vivid-vbi-gen.c
From: Zhaoxiu ZengSigned-off-by: Zhaoxiu Zeng --- drivers/media/platform/vivid/vivid-vbi-gen.c | 9 ++--- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/drivers/media/platform/vivid/vivid-vbi-gen.c b/drivers/media/platform/vivid/vivid-vbi-gen.c index a2159de..d5ba0fc 100644 --- a/drivers/media/platform/vivid/vivid-vbi-gen.c +++ b/drivers/media/platform/vivid/vivid-vbi-gen.c @@ -175,14 +175,9 @@ static const u8 vivid_cc_sequence2[30] = { 0x14, 0x2f, /* End of Caption */ }; -static u8 calc_parity(u8 val) +static inline u8 calc_parity(u8 val) { - unsigned i; - unsigned tot = 0; - - for (i = 0; i < 7; i++) - tot += (val & (1 << i)) ? 1 : 0; - return val | ((tot & 1) ? 0 : 0x80); + return (!parity8(val) << 7) | val; } static void vivid_vbi_gen_set_time_of_day(u8 *packet) -- 2.5.0 -- To unsubscribe from this list: send the line "unsubscribe linux-media" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v2 15/30] media: use parity functions in saa7115
From: Zhaoxiu ZengSigned-off-by: Zhaoxiu Zeng --- drivers/media/i2c/saa7115.c | 17 ++--- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/drivers/media/i2c/saa7115.c b/drivers/media/i2c/saa7115.c index d2a1ce2..4c22df8 100644 --- a/drivers/media/i2c/saa7115.c +++ b/drivers/media/i2c/saa7115.c @@ -672,15 +672,6 @@ static const unsigned char saa7115_init_misc[] = { 0x00, 0x00 }; -static int saa711x_odd_parity(u8 c) -{ - c ^= (c >> 4); - c ^= (c >> 2); - c ^= (c >> 1); - - return c & 1; -} - static int saa711x_decode_vps(u8 *dst, u8 *p) { static const u8 biphase_tbl[] = { @@ -733,7 +724,6 @@ static int saa711x_decode_wss(u8 *p) static const int wss_bits[8] = { 0, 0, 0, 1, 0, 1, 1, 1 }; - unsigned char parity; int wss = 0; int i; @@ -745,11 +735,8 @@ static int saa711x_decode_wss(u8 *p) return -1; wss |= b2 << i; } - parity = wss & 15; - parity ^= parity >> 2; - parity ^= parity >> 1; - if (!(parity & 1)) + if (!parity4(wss)) return -1; return wss; @@ -1235,7 +1222,7 @@ static int saa711x_decode_vbi_line(struct v4l2_subdev *sd, struct v4l2_decode_vb vbi->type = V4L2_SLICED_TELETEXT_B; break; case 4: - if (!saa711x_odd_parity(p[0]) || !saa711x_odd_parity(p[1])) + if (!parity8(p[0]) || !parity8(p[1])) return 0; vbi->type = V4L2_SLICED_CAPTION_525; break; -- 2.5.0 -- To unsubscribe from this list: send the line "unsubscribe linux-media" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html