]>
git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - fs/btrfs/crc32c.h
2 * Copyright (C) 2008 Oracle. All rights reserved.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public
6 * License v2 as published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public
14 * License along with this program; if not, write to the
15 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
16 * Boston, MA 021110-1307, USA.
19 #ifndef __BTRFS_CRC32C__
20 #define __BTRFS_CRC32C__
21 #include <asm/byteorder.h>
22 #include <linux/crc32c.h>
23 #include <linux/version.h>
25 /* #define CONFIG_BTRFS_HW_SUM 1 */
27 #ifdef CONFIG_BTRFS_HW_SUM
30 * Using hardware provided CRC32 instruction to accelerate the CRC32 disposal.
31 * CRC32C polynomial:0x1EDC6F41(BE)/0x82F63B78(LE)
32 * CRC32 is a new instruction in Intel SSE4.2, the reference can be found at:
33 * http://www.intel.com/products/processor/manuals/
34 * Intel(R) 64 and IA-32 Architectures Software Developer's Manual
35 * Volume 2A: Instruction Set Reference, A-M
38 #include <asm/cpufeature.h>
39 #include <asm/processor.h>
41 #define X86_FEATURE_XMM4_2 (4*32+20) /* Streaming SIMD Extensions-4.2 */
42 #define cpu_has_xmm4_2 boot_cpu_has(X86_FEATURE_XMM4_2)
45 #define REX_PRE "0x48, "
52 static inline u32
btrfs_crc32c_le_hw_byte(u32 crc
, unsigned char const *data
,
57 ".byte 0xf2, 0xf, 0x38, 0xf0, 0xf1"
67 static inline u32 __pure
btrfs_crc32c_le_hw(u32 crc
, unsigned char const *p
,
70 unsigned int iquotient
= len
/ SCALE_F
;
71 unsigned int iremainder
= len
% SCALE_F
;
80 ".byte 0xf2, " REX_PRE
"0xf, 0x38, 0xf1, 0xf1;"
88 crc
= btrfs_crc32c_le_hw_byte(crc
, (unsigned char *)ptmp
,
93 #endif /* CONFIG_BTRFS_HW_SUM */
95 static inline u32
__btrfs_crc32c(u32 crc
, unsigned char const *address
,
98 #ifdef CONFIG_BTRFS_HW_SUM
100 return btrfs_crc32c_le_hw(crc
, address
, len
);
102 return crc32c_le(crc
, address
, len
);
107 #define __btrfs_crc32c(seed, data, length) crc32c(seed, data, length)
109 #endif /* CONFIG_X86 */
112 * implementation of crc32c_le() changed in linux-2.6.23,
113 * has of v0.13 btrfs-progs is using the latest version.
114 * We must workaround older implementations of crc32c_le()
115 * found on older kernel versions.
117 #define btrfs_crc32c(seed, data, length) \
118 __btrfs_crc32c(seed, (unsigned char const *)data, length)