Uses specific architecture defines.

This commit is contained in:
Andrea Mazzoleni 2013-12-30 21:12:29 +01:00
parent 535beee053
commit 8a904cbe7a
19 changed files with 65 additions and 107 deletions

View file

@ -31,6 +31,19 @@
#include <windows.h>
#endif
/**
* Architecture.
*/
#if defined(__i386__)
#define CONFIG_X86 1
#define CONFIG_X86_32 1
#endif
#if defined(__x86_64__)
#define CONFIG_X86 1
#define CONFIG_X86_64 1
#endif
/**
* Includes some platform specific headers.
*/

View file

@ -10,13 +10,10 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __COMBO_H
#define __COMBO_H
#ifndef __RAID_COMBO_H
#define __RAID_COMBO_H
#include <assert.h>

View file

@ -10,17 +10,14 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __RAID_CPU_H
#define __RAID_CPU_H
#if defined(__i386__) || defined(__x86_64__)
#ifdef CONFIG_X86
static __always_inline void raid_cpuid(uint32_t func_eax, uint32_t sub_ecx, uint32_t *reg)
static inline void raid_cpuid(uint32_t func_eax, uint32_t sub_ecx, uint32_t *reg)
{
asm volatile(
#if defined(__i386__) && defined(__PIC__)
@ -40,7 +37,7 @@ static __always_inline void raid_cpuid(uint32_t func_eax, uint32_t sub_ecx, uint
#define CPU_VENDOR_MAX 13
static __always_inline void raid_cpu_info(char *vendor, unsigned *family, unsigned *model)
static inline void raid_cpu_info(char *vendor, unsigned *family, unsigned *model)
{
uint32_t reg[4];
unsigned f, ef, m, em;
@ -73,7 +70,7 @@ static __always_inline void raid_cpu_info(char *vendor, unsigned *family, unsign
}
}
static __always_inline int raid_cpu_has_mmx(void)
static inline int raid_cpu_has_mmx(void)
{
uint32_t reg[4];
@ -82,7 +79,7 @@ static __always_inline int raid_cpu_has_mmx(void)
return (reg[3] >> 23) & 1;
}
static __always_inline int raid_cpu_has_sse2(void)
static inline int raid_cpu_has_sse2(void)
{
uint32_t reg[4];
@ -91,7 +88,7 @@ static __always_inline int raid_cpu_has_sse2(void)
return (reg[3] >> 26) & 1;
}
static __always_inline int raid_cpu_has_ssse3(void)
static inline int raid_cpu_has_ssse3(void)
{
uint32_t reg[4];
@ -100,7 +97,7 @@ static __always_inline int raid_cpu_has_ssse3(void)
return (reg[2] >> 9) & 1;
}
static __always_inline int raid_cpu_has_sse42(void)
static inline int raid_cpu_has_sse42(void)
{
uint32_t reg[4];
@ -109,7 +106,7 @@ static __always_inline int raid_cpu_has_sse42(void)
return (reg[2] >> 20) & 1;
}
static __always_inline int raid_cpu_has_avx(void)
static inline int raid_cpu_has_avx(void)
{
uint32_t reg[4];
@ -118,7 +115,7 @@ static __always_inline int raid_cpu_has_avx(void)
return (reg[2] >> 28) & 1;
}
static __always_inline int raid_cpu_has_avx2(void)
static inline int raid_cpu_has_avx2(void)
{
uint32_t reg[4];
@ -131,7 +128,7 @@ static __always_inline int raid_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 __always_inline int raid_cpu_has_slowmult(void)
static inline int raid_cpu_has_slowmult(void)
{
char vendor[CPU_VENDOR_MAX];
unsigned family;
@ -169,7 +166,7 @@ static __always_inline int raid_cpu_has_slowmult(void)
* Check if the processor has a slow PSHUFB implementation.
* If yes, it's better to not use it.
*/
static __always_inline int raid_cpu_has_slowpshufb(void)
static inline int raid_cpu_has_slowpshufb(void)
{
char vendor[CPU_VENDOR_MAX];
unsigned family;
@ -233,7 +230,7 @@ static __always_inline int raid_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 __always_inline int raid_cpu_has_slowextendedreg(void)
static inline int raid_cpu_has_slowextendedreg(void)
{
char vendor[CPU_VENDOR_MAX];
unsigned family;

View file

@ -10,9 +10,6 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __RAID_GF_H

View file

@ -10,9 +10,6 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "internal.h"

View file

@ -10,9 +10,6 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __RAID_INTERNAL_H

View file

@ -10,9 +10,6 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "internal.h"

View file

@ -10,9 +10,6 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "internal.h"

View file

@ -10,9 +10,6 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __RAID_MEMORY_H

View file

@ -10,9 +10,6 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
@ -192,9 +189,6 @@ int main(void)
printf(" * but WITHOUT ANY WARRANTY; without even the implied warranty of\n");
printf(" * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n");
printf(" * GNU General Public License for more details.\n");
printf(" *\n");
printf(" * You should have received a copy of the GNU General Public License\n");
printf(" * along with this program. If not, see <http://www.gnu.org/licenses/>.\n");
printf(" */\n");
printf("\n");
@ -319,7 +313,7 @@ int main(void)
}
printf("};\n\n");
printf("#if defined(__i386__) || defined(__x86_64__)\n");
printf("#ifdef CONFIG_X86\n");
printf("/**\n");
printf(" * PSHUFB tables for the Cauchy matrix.\n");
printf(" *\n");
@ -351,7 +345,7 @@ int main(void)
printf("};\n");
printf("#endif\n\n");
printf("#if defined(__i386__) || defined(__x86_64__)\n");
printf("#ifdef CONFIG_X86\n");
printf("/**\n");
printf(" * PSHUFB tables for generic multiplication.\n");
printf(" *\n");

View file

@ -10,9 +10,6 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "internal.h"
@ -42,10 +39,10 @@ void raid_init(void)
raid_rec_ptr[4] = raid_recX_int8;
raid_rec_ptr[5] = raid_recX_int8;
#if defined(__i386__) || defined(__x86_64__)
#ifdef CONFIG_X86
if (raid_cpu_has_sse2()) {
raid_par_ptr[0] = raid_par1_sse2;
#if defined(__x86_64__)
#ifdef CONFIG_X86_64
if (raid_cpu_has_slowextendedreg()) {
raid_par_ptr[1] = raid_par2_sse2;
raid_parz_ptr = raid_parz_sse2;
@ -60,7 +57,7 @@ void raid_init(void)
}
if (raid_cpu_has_ssse3()) {
#if defined(__x86_64__)
#ifdef CONFIG_X86_64
raid_par3_ptr = raid_par3_ssse3ext;
raid_par_ptr[3] = raid_par4_ssse3ext;
raid_par_ptr[4] = raid_par5_ssse3ext;
@ -102,7 +99,7 @@ static struct raid_func {
{ "int8", raid_rec2_int8 },
{ "int8", raid_recX_int8 },
#if defined(__i386__) || defined(__x86_64__)
#ifdef CONFIG_X86
{ "sse2", raid_par1_sse2 },
{ "sse2", raid_par2_sse2 },
{ "sse2", raid_parz_sse2 },
@ -115,7 +112,7 @@ static struct raid_func {
{ "ssse3", raid_recX_ssse3 },
#endif
#if defined(__x86_64__)
#ifdef CONFIG_X86_64
{ "sse2e", raid_par2_sse2ext },
{ "sse2e", raid_parz_sse2ext },
{ "ssse3e", raid_par3_ssse3ext },

View file

@ -10,9 +10,6 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "internal.h"

View file

@ -10,9 +10,6 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __RAID_H

View file

@ -10,9 +10,6 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "internal.h"

View file

@ -10,9 +10,6 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "internal.h"
@ -9131,7 +9128,7 @@ const uint8_t __aligned(256) raid_gfcauchy[6][256] =
},
};
#if defined(__i386__) || defined(__x86_64__)
#ifdef CONFIG_X86
/**
* PSHUFB tables for the Cauchy matrix.
*
@ -13661,7 +13658,7 @@ const uint8_t __aligned(256) raid_gfcauchypshufb[251][4][2][16] =
};
#endif
#if defined(__i386__) || defined(__x86_64__)
#ifdef CONFIG_X86
/**
* PSHUFB tables for generic multiplication.
*

View file

@ -10,9 +10,6 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "internal.h"
@ -160,19 +157,19 @@ int raid_test_rec(int mode, int nd, size_t size)
mac[i] = 0;
if (i == 0) {
map[i][mac[i]++] = raid_rec1_int8;
#if defined(__i386__) || defined(__x86_64__)
#ifdef CONFIG_X86
if (raid_cpu_has_ssse3())
map[i][mac[i]++] = raid_rec1_ssse3;
#endif
} else if (i == 1) {
map[i][mac[i]++] = raid_rec2_int8;
#if defined(__i386__) || defined(__x86_64__)
#ifdef CONFIG_X86
if (raid_cpu_has_ssse3())
map[i][mac[i]++] = raid_rec2_ssse3;
#endif
} else {
map[i][mac[i]++] = raid_recX_int8;
#if defined(__i386__) || defined(__x86_64__)
#ifdef CONFIG_X86
if (raid_cpu_has_ssse3())
map[i][mac[i]++] = raid_recX_ssse3;
#endif
@ -271,11 +268,11 @@ int raid_test_par(int mode, int nd, size_t size)
map[mac++] = raid_par2_int32;
map[mac++] = raid_par2_int64;
#if defined(__i386__) || defined(__x86_64__)
#ifdef CONFIG_X86
if (raid_cpu_has_sse2()) {
map[mac++] = raid_par1_sse2;
map[mac++] = raid_par2_sse2;
#if defined(__x86_64__)
#ifdef CONFIG_X86_64
map[mac++] = raid_par2_sse2ext;
#endif
}
@ -287,13 +284,13 @@ int raid_test_par(int mode, int nd, size_t size)
map[mac++] = raid_par5_int8;
map[mac++] = raid_par6_int8;
#if defined(__i386__) || defined(__x86_64__)
#ifdef CONFIG_X86
if (raid_cpu_has_ssse3()) {
map[mac++] = raid_par3_ssse3;
map[mac++] = raid_par4_ssse3;
map[mac++] = raid_par5_ssse3;
map[mac++] = raid_par6_ssse3;
#if defined(__x86_64__)
#ifdef CONFIG_X86_64
map[mac++] = raid_par3_ssse3ext;
map[mac++] = raid_par4_ssse3ext;
map[mac++] = raid_par5_ssse3ext;
@ -305,10 +302,10 @@ int raid_test_par(int mode, int nd, size_t size)
map[mac++] = raid_parz_int32;
map[mac++] = raid_parz_int64;
#if defined(__i386__) || defined(__x86_64__)
#ifdef CONFIG_X86
if (raid_cpu_has_sse2()) {
map[mac++] = raid_parz_sse2;
#if defined(__x86_64__)
#ifdef CONFIG_X86_64
map[mac++] = raid_parz_sse2ext;
#endif
}

View file

@ -10,9 +10,6 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __RAID_TEST_H
@ -28,7 +25,7 @@
int raid_test_sort(void);
/**
* Tests combinations functions.
* Tests combination functions.
*
* Tests combination_first() and combination_next() for all the parity levels.
*

View file

@ -10,15 +10,12 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "internal.h"
#include "gf.h"
#if defined(__i386__) || defined(__x86_64__)
#ifdef CONFIG_X86
/*
* PAR1 (RAID5 with xor) SSE2 implementation
*
@ -66,7 +63,7 @@ void raid_par1_sse2(int nd, size_t size, void **vv)
}
#endif
#if defined(__i386__) || defined(__x86_64__)
#ifdef CONFIG_X86
static const struct gfconst16 {
uint8_t poly[16];
uint8_t low4[16];
@ -76,7 +73,7 @@ static const struct gfconst16 {
};
#endif
#if defined(__i386__) || defined(__x86_64__)
#ifdef CONFIG_X86
/*
* PAR2 (RAID6 with powers of 2) SSE2 implementation
*/
@ -130,7 +127,7 @@ void raid_par2_sse2(int nd, size_t size, void **vv)
}
#endif
#if defined(__x86_64__)
#ifdef CONFIG_X86_64
/*
* PAR2 (RAID6 with powers of 2) SSE2 implementation
*
@ -210,7 +207,7 @@ void raid_par2_sse2ext(int nd, size_t size, void **vv)
}
#endif
#if defined(__i386__) || defined(__x86_64__)
#ifdef CONFIG_X86
/*
* PAR3 (triple parity with Cauchy matrix) SSSE3 implementation
*/
@ -307,7 +304,7 @@ void raid_par3_ssse3(int nd, size_t size, void **vv)
}
#endif
#if defined(__x86_64__)
#ifdef CONFIG_X86_64
/*
* PAR3 (triple parity with Cauchy matrix) SSSE3 implementation
*
@ -448,7 +445,7 @@ void raid_par3_ssse3ext(int nd, size_t size, void **vv)
}
#endif
#if defined(__i386__) || defined(__x86_64__)
#ifdef CONFIG_X86
/*
* PAR4 (quad parity with Cauchy matrix) SSSE3 implementation
*/
@ -564,7 +561,7 @@ void raid_par4_ssse3(int nd, size_t size, void **vv)
}
#endif
#if defined(__x86_64__)
#ifdef CONFIG_X86_64
/*
* PAR4 (quad parity with Cauchy matrix) SSSE3 implementation
*
@ -737,7 +734,7 @@ void raid_par4_ssse3ext(int nd, size_t size, void **vv)
}
#endif
#if defined(__i386__) || defined(__x86_64__)
#ifdef CONFIG_X86
/*
* PAR5 (penta parity with Cauchy matrix) SSSE3 implementation
*/
@ -878,7 +875,7 @@ void raid_par5_ssse3(int nd, size_t size, void **vv)
}
#endif
#if defined(__x86_64__)
#ifdef CONFIG_X86_64
/*
* PAR5 (penta parity with Cauchy matrix) SSSE3 implementation
*
@ -1011,7 +1008,7 @@ void raid_par5_ssse3ext(int nd, size_t size, void **vv)
}
#endif
#if defined(__i386__) || defined(__x86_64__)
#ifdef CONFIG_X86
/*
* PAR6 (hexa parity with Cauchy matrix) SSSE3 implementation
*/
@ -1173,7 +1170,7 @@ void raid_par6_ssse3(int nd, size_t size, void **vv)
}
#endif
#if defined(__x86_64__)
#ifdef CONFIG_X86_64
/*
* PAR6 (hexa parity with Cauchy matrix) SSSE3 implementation
*
@ -1323,7 +1320,7 @@ void raid_par6_ssse3ext(int nd, size_t size, void **vv)
}
#endif
#if defined(__i386__) || defined(__x86_64__)
#ifdef CONFIG_X86
/*
* RAID recovering for one disk SSSE3 implementation
*/
@ -1382,7 +1379,7 @@ void raid_rec1_ssse3(int nr, const int *id, const int *ip, int nd, size_t size,
}
#endif
#if defined(__i386__) || defined(__x86_64__)
#ifdef CONFIG_X86
/*
* RAID recovering for two disks SSSE3 implementation
*/
@ -1488,7 +1485,7 @@ void raid_rec2_ssse3(int nr, const int *id, const int *ip, int nd, size_t size,
}
#endif
#if defined(__i386__) || defined(__x86_64__)
#ifdef CONFIG_X86
/*
* RAID recovering SSSE3 implementation
*/

View file

@ -10,14 +10,11 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "internal.h"
#if defined(__i386__) || defined(__x86_64__)
#ifdef CONFIG_X86
static const struct gfzconst16 {
uint8_t poly[16];
uint8_t half[16];
@ -27,7 +24,9 @@ static const struct gfzconst16 {
{ 0x8e, 0x8e, 0x8e, 0x8e, 0x8e, 0x8e, 0x8e, 0x8e, 0x8e, 0x8e, 0x8e, 0x8e, 0x8e, 0x8e, 0x8e, 0x8e },
{ 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f }
};
#endif
#ifdef CONFIG_X86
/*
* PARz (triple parity with powers of 2^-1) SSE2 implementation
*/
@ -85,7 +84,7 @@ void raid_parz_sse2(int nd, size_t size, void **vv)
}
#endif
#if defined(__x86_64__)
#ifdef CONFIG_X86_64
/*
* PARz (triple parity with powers of 2^-1) SSE2 implementation
*