1 #ifndef __BTRFS_CRC32C__
2 #define __BTRFS_CRC32C__
3 #include <asm/byteorder.h>
4 #include <linux/crc32c.h>
5 #include <linux/version.h>
7 /* #define CONFIG_BTRFS_HW_SUM 1 */
9 #ifdef CONFIG_BTRFS_HW_SUM
12 * Using hardware provided CRC32 instruction to accelerate the CRC32 disposal.
13 * CRC32C polynomial:0x1EDC6F41(BE)/0x82F63B78(LE)
14 * CRC32 is a new instruction in Intel SSE4.2, the reference can be found at:
15 * http://www.intel.com/products/processor/manuals/
16 * Intel(R) 64 and IA-32 Architectures Software Developer's Manual
17 * Volume 2A: Instruction Set Reference, A-M
20 #include <asm/cpufeature.h>
21 #include <asm/processor.h>
23 #define X86_FEATURE_XMM4_2 (4*32+20) /* Streaming SIMD Extensions-4.2 */
24 #define cpu_has_xmm4_2 boot_cpu_has(X86_FEATURE_XMM4_2)
27 #define REX_PRE "0x48, "
34 static inline u32
btrfs_crc32c_le_hw_byte(u32 crc
, unsigned char const *data
,
39 ".byte 0xf2, 0xf, 0x38, 0xf0, 0xf1"
49 static inline u32 __pure
btrfs_crc32c_le_hw(u32 crc
, unsigned char const *p
,
52 unsigned int iquotient
= len
/ SCALE_F
;
53 unsigned int iremainder
= len
% SCALE_F
;
62 ".byte 0xf2, " REX_PRE
"0xf, 0x38, 0xf1, 0xf1;"
70 crc
= btrfs_crc32c_le_hw_byte(crc
, (unsigned char *)ptmp
,
75 #endif /* CONFIG_BTRFS_HW_SUM */
77 static inline u32
__btrfs_crc32c(u32 crc
, unsigned char const *address
,
80 #ifdef CONFIG_BTRFS_HW_SUM
82 return btrfs_crc32c_le_hw(crc
, address
, len
);
84 return crc32c_le(crc
, address
, len
);
89 #define __btrfs_crc32c(seed, data, length) crc32c(seed, data, length)
91 #endif /* CONFIG_X86 */
94 * implementation of crc32c_le() changed in linux-2.6.23,
95 * has of v0.13 btrfs-progs is using the latest version.
96 * We must workaround older implementations of crc32c_le()
97 * found on older kernel versions.
99 #define btrfs_crc32c(seed, data, length) \
100 __btrfs_crc32c(seed, (unsigned char const *)data, length)
This page took 0.077486 seconds and 5 git commands to generate.