mirror of
https://github.com/amadvance/snapraid.git
synced 2026-11-22 16:06:30 -05:00
Refactors the RAID engine for a potential independent release.
This commit is contained in:
parent
b81e4a0141
commit
de0c8db8d7
15 changed files with 964 additions and 882 deletions
48
cpu.h
48
cpu.h
|
|
@ -15,12 +15,12 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __CPU_H
|
||||
#define __CPU_H
|
||||
#ifndef __RAID_CPU_H
|
||||
#define __RAID_CPU_H
|
||||
|
||||
#if defined(__i386__) || defined(__x86_64__)
|
||||
|
||||
static inline void cpuid(uint32_t func_eax, uint32_t sub_ecx, uint32_t* reg)
|
||||
static __always_inline void raid_cpuid(uint32_t func_eax, uint32_t sub_ecx, uint32_t* reg)
|
||||
{
|
||||
asm volatile(
|
||||
#if defined(__i386__) && defined(__PIC__)
|
||||
|
|
@ -40,19 +40,19 @@ static inline void cpuid(uint32_t func_eax, uint32_t sub_ecx, uint32_t* reg)
|
|||
|
||||
#define CPU_VENDOR_MAX 13
|
||||
|
||||
static inline void cpu_info(char* vendor, unsigned* family, unsigned* model)
|
||||
static __always_inline void raid_cpu_info(char* vendor, unsigned* family, unsigned* model)
|
||||
{
|
||||
uint32_t reg[4];
|
||||
unsigned f, ef, m, em;
|
||||
|
||||
cpuid(0, 0, reg);
|
||||
raid_cpuid(0, 0, reg);
|
||||
|
||||
((uint32_t*)vendor)[0] = reg[1];
|
||||
((uint32_t*)vendor)[1] = reg[3];
|
||||
((uint32_t*)vendor)[2] = reg[2];
|
||||
vendor[12] = 0;
|
||||
|
||||
cpuid(1, 0, reg);
|
||||
raid_cpuid(1, 0, reg);
|
||||
|
||||
f = (reg[0] >> 8) & 0xF;
|
||||
ef = (reg[0] >> 20) & 0xFF;
|
||||
|
|
@ -73,56 +73,56 @@ static inline void cpu_info(char* vendor, unsigned* family, unsigned* model)
|
|||
}
|
||||
}
|
||||
|
||||
static inline int cpu_has_mmx(void)
|
||||
static __always_inline int raid_cpu_has_mmx(void)
|
||||
{
|
||||
uint32_t reg[4];
|
||||
|
||||
cpuid(1, 0, reg);
|
||||
raid_cpuid(1, 0, reg);
|
||||
|
||||
return (reg[3] >> 23) & 1;
|
||||
}
|
||||
|
||||
static inline int cpu_has_sse2(void)
|
||||
static __always_inline int raid_cpu_has_sse2(void)
|
||||
{
|
||||
uint32_t reg[4];
|
||||
|
||||
cpuid(1, 0, reg);
|
||||
raid_cpuid(1, 0, reg);
|
||||
|
||||
return (reg[3] >> 26) & 1;
|
||||
}
|
||||
|
||||
static inline int cpu_has_ssse3(void)
|
||||
static __always_inline int raid_cpu_has_ssse3(void)
|
||||
{
|
||||
uint32_t reg[4];
|
||||
|
||||
cpuid(1, 0, reg);
|
||||
raid_cpuid(1, 0, reg);
|
||||
|
||||
return (reg[2] >> 9) & 1;
|
||||
}
|
||||
|
||||
static inline int cpu_has_sse42(void)
|
||||
static __always_inline int raid_cpu_has_sse42(void)
|
||||
{
|
||||
uint32_t reg[4];
|
||||
|
||||
cpuid(1, 0, reg);
|
||||
raid_cpuid(1, 0, reg);
|
||||
|
||||
return (reg[2] >> 20) & 1;
|
||||
}
|
||||
|
||||
static inline int cpu_has_avx(void)
|
||||
static __always_inline int raid_cpu_has_avx(void)
|
||||
{
|
||||
uint32_t reg[4];
|
||||
|
||||
cpuid(1, 0, reg);
|
||||
raid_cpuid(1, 0, reg);
|
||||
|
||||
return (reg[2] >> 28) & 1;
|
||||
}
|
||||
|
||||
static inline int cpu_has_avx2(void)
|
||||
static __always_inline int raid_cpu_has_avx2(void)
|
||||
{
|
||||
uint32_t reg[4];
|
||||
|
||||
cpuid(7, 0, reg);
|
||||
raid_cpuid(7, 0, reg);
|
||||
|
||||
return (reg[1] >> 5) & 1;
|
||||
}
|
||||
|
|
@ -131,13 +131,13 @@ static inline int cpu_has_avx2(void)
|
|||
* Check if the processor has a slow MULT implementation.
|
||||
* If yes, it's better to use a hash not based on multiplication.
|
||||
*/
|
||||
static inline int cpu_has_slowmult(void)
|
||||
static __always_inline int raid_cpu_has_slowmult(void)
|
||||
{
|
||||
char vendor[CPU_VENDOR_MAX];
|
||||
unsigned family;
|
||||
unsigned model;
|
||||
|
||||
cpu_info(vendor, &family, &model);
|
||||
raid_cpu_info(vendor, &family, &model);
|
||||
|
||||
if (strcmp(vendor, "GenuineIntel") == 0) {
|
||||
/* Intel(R) Atom(TM) CPU D525 @ 1.80GHz (info from user)
|
||||
|
|
@ -169,13 +169,13 @@ static inline int cpu_has_slowmult(void)
|
|||
* Check if the processor has a slow PSHUFB implementation.
|
||||
* If yes, it's better to not use it.
|
||||
*/
|
||||
static inline int cpu_has_slowpshufb(void)
|
||||
static __always_inline int raid_cpu_has_slowpshufb(void)
|
||||
{
|
||||
char vendor[CPU_VENDOR_MAX];
|
||||
unsigned family;
|
||||
unsigned model;
|
||||
|
||||
cpu_info(vendor, &family, &model);
|
||||
raid_cpu_info(vendor, &family, &model);
|
||||
|
||||
if (strcmp(vendor, "GenuineIntel") == 0) {
|
||||
/* Intel ATOM (info from x264 -> full family/model 6/28) */
|
||||
|
|
@ -233,13 +233,13 @@ static inline int cpu_has_slowpshufb(void)
|
|||
* Check if the processor has a slow extended set of SSE registers.
|
||||
* If yes, it's better to unroll without using the second part of registers.
|
||||
*/
|
||||
static inline int cpu_has_slowextendedreg(void)
|
||||
static __always_inline int raid_cpu_has_slowextendedreg(void)
|
||||
{
|
||||
char vendor[CPU_VENDOR_MAX];
|
||||
unsigned family;
|
||||
unsigned model;
|
||||
|
||||
cpu_info(vendor, &family, &model);
|
||||
raid_cpu_info(vendor, &family, &model);
|
||||
|
||||
if (strcmp(vendor, "AuthenticAMD") == 0) {
|
||||
/* AMD Bulldozer (from user)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue