mirror of
https://github.com/kdave/btrfs-progs
synced 2025-02-09 06:06:58 +00:00
btrfs-progs: crypto: use common CPU feature detection for crc32c
The crc32c selection has been already using the pointer-based approach so drop the cpuid detection and use our common code for that. Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
979fe686d2
commit
8a60fde969
@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include "crypto/crc32c.h"
|
#include "crypto/crc32c.h"
|
||||||
|
#include "common/cpu-utils.h"
|
||||||
|
|
||||||
uint32_t __crc32c_le(uint32_t crc, unsigned char const *data, uint32_t length);
|
uint32_t __crc32c_le(uint32_t crc, unsigned char const *data, uint32_t length);
|
||||||
static uint32_t (*crc_function)(uint32_t crc, unsigned char const *data, uint32_t length) = __crc32c_le;
|
static uint32_t (*crc_function)(uint32_t crc, unsigned char const *data, uint32_t length) = __crc32c_le;
|
||||||
@ -34,9 +35,6 @@ static uint32_t (*crc_function)(uint32_t crc, unsigned char const *data, uint32_
|
|||||||
#define SCALE_F 4
|
#define SCALE_F 4
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static int crc32c_probed = 0;
|
|
||||||
static int crc32c_intel_available = 0;
|
|
||||||
|
|
||||||
static uint32_t crc32c_intel_le_hw_byte(uint32_t crc, unsigned char const *data,
|
static uint32_t crc32c_intel_le_hw_byte(uint32_t crc, unsigned char const *data,
|
||||||
uint32_t length)
|
uint32_t length)
|
||||||
{
|
{
|
||||||
@ -78,45 +76,20 @@ static uint32_t crc32c_intel(uint32_t crc, unsigned char const *data, uint32_t l
|
|||||||
return crc;
|
return crc;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void do_cpuid(unsigned int *eax, unsigned int *ebx, unsigned int *ecx,
|
void crc32c_init_accel(void)
|
||||||
unsigned int *edx)
|
|
||||||
{
|
{
|
||||||
int id = *eax;
|
/* CRC32 is in SSE4.2 */
|
||||||
|
if (cpu_has_feature(CPU_FLAG_SSE42))
|
||||||
asm("movl %4, %%eax;"
|
|
||||||
"cpuid;"
|
|
||||||
"movl %%eax, %0;"
|
|
||||||
"movl %%ebx, %1;"
|
|
||||||
"movl %%ecx, %2;"
|
|
||||||
"movl %%edx, %3;"
|
|
||||||
: "=r" (*eax), "=r" (*ebx), "=r" (*ecx), "=r" (*edx)
|
|
||||||
: "r" (id)
|
|
||||||
: "eax", "ebx", "ecx", "edx");
|
|
||||||
}
|
|
||||||
|
|
||||||
static void crc32c_intel_probe(void)
|
|
||||||
{
|
|
||||||
if (!crc32c_probed) {
|
|
||||||
unsigned int eax, ebx, ecx, edx;
|
|
||||||
|
|
||||||
eax = 1;
|
|
||||||
|
|
||||||
do_cpuid(&eax, &ebx, &ecx, &edx);
|
|
||||||
crc32c_intel_available = (ecx & (1 << 20)) != 0;
|
|
||||||
crc32c_probed = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void crc32c_optimization_init(void)
|
|
||||||
{
|
|
||||||
crc32c_intel_probe();
|
|
||||||
if (crc32c_intel_available)
|
|
||||||
crc_function = crc32c_intel;
|
crc_function = crc32c_intel;
|
||||||
|
else
|
||||||
|
crc_function = __crc32c_le;
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
void crc32c_optimization_init(void)
|
void crc32c_init_accel(void)
|
||||||
{
|
{
|
||||||
|
crc_function = __crc32c_le;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* __x86_64__ */
|
#endif /* __x86_64__ */
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
|
|
||||||
uint32_t crc32c_le(uint32_t seed, unsigned char const *data, uint32_t length);
|
uint32_t crc32c_le(uint32_t seed, unsigned char const *data, uint32_t length);
|
||||||
void crc32c_optimization_init(void);
|
void crc32c_init_accel(void);
|
||||||
|
|
||||||
#define crc32c(seed, data, length) crc32c_le(seed, (unsigned char const *)data, length)
|
#define crc32c(seed, data, length) crc32c_le(seed, (unsigned char const *)data, length)
|
||||||
|
|
||||||
|
@ -22,11 +22,16 @@
|
|||||||
|
|
||||||
void hash_init_accel(void)
|
void hash_init_accel(void)
|
||||||
{
|
{
|
||||||
crc32c_optimization_init();
|
crc32c_init_accel();
|
||||||
blake2_init_accel();
|
blake2_init_accel();
|
||||||
sha256_init_accel();
|
sha256_init_accel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void hash_init_crc32c(void)
|
||||||
|
{
|
||||||
|
crc32c_init_accel();
|
||||||
|
}
|
||||||
|
|
||||||
void hash_init_blake2(void)
|
void hash_init_blake2(void)
|
||||||
{
|
{
|
||||||
blake2_init_accel();
|
blake2_init_accel();
|
||||||
|
@ -27,6 +27,7 @@ int hash_sha256(const u8 *buf, size_t length, u8 *out);
|
|||||||
int hash_blake2b(const u8 *buf, size_t length, u8 *out);
|
int hash_blake2b(const u8 *buf, size_t length, u8 *out);
|
||||||
|
|
||||||
void hash_init_accel(void);
|
void hash_init_accel(void);
|
||||||
|
void hash_init_crc32c(void);
|
||||||
void hash_init_blake2(void);
|
void hash_init_blake2(void);
|
||||||
void hash_init_sha256(void);
|
void hash_init_sha256(void);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user