Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace asm statements by C code to increase portability #205

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 21 additions & 9 deletions include/jellyfish/rectangular_binary_matrix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,13 +296,20 @@ namespace jellyfish {
// #pragma GCC diagnostic pop

// i is the lower 2 bits of x, and an index into the smear array. Compute res ^= smear[i] & p[j].
#ifdef __x86_64__
#define AND_XOR(off) \
asm("movdqa (%[s],%[i]), %[load]\n\t" \
"pand " off "(%[p]),%[load]\n\t" \
"pand " #off "(%[p]),%[load]\n\t" \
"pxor %[load],%[acc]\n\t" \
: [acc]"=&x"(acc) \
: "[acc]"(acc), [i]"r"(i), [p]"r"(p), [s]"r"(smear), [load]"x"(load))

#else
#define AND_XOR(off) do { \
xmm_t a = { smear[i / 8], smear[i / 8 + 1] }; \
xmm_t b = { p[(off) / 8], p[(off) / 8 + 1] }; \
acc ^= a & b; \
} while (0)
#endif

uint64_t i, j = 0, x = 0;
for(unsigned int w = 0; w < nb_words(); ++w) {
Expand All @@ -314,16 +321,16 @@ namespace jellyfish {
}
for( ; j > 7; j -= 8, p -= 8) {
i = (x & (uint64_t)0x3) << 4;
AND_XOR("0x30");
AND_XOR(0x30);
x >>= 2;
i = (x & (uint64_t)0x3) << 4;
AND_XOR("0x20");
AND_XOR(0x20);
x >>= 2;
i = (x & (uint64_t)0x3) << 4;
AND_XOR("0x10");
AND_XOR(0x10);
x >>= 2;
i = (x & (uint64_t)0x3) << 4;
AND_XOR("");
AND_XOR(0);
x >>= 2;
}
}
Expand All @@ -333,25 +340,30 @@ namespace jellyfish {
switch(j) {
case 6:
i = (x & (uint64_t)0x3) << 4;
AND_XOR("0x20");
AND_XOR(0x20);
x >>= 2;
case 4:
i = (x & (uint64_t)0x3) << 4;
AND_XOR("0x10");
AND_XOR(0x10);
x >>= 2;
case 2:
i = (x & (uint64_t)0x3) << 4;
AND_XOR("");
AND_XOR(0);
}

// Get result out
#ifdef __x86_64__
uint64_t res1, res2;
asm("movd %[acc], %[res1]\n\t"
"psrldq $8, %[acc]\n\t"
"movd %[acc], %[res2]\n\t"
: [res1]"=r"(res1), [res2]"=r"(res2)
: [acc]"x"(acc));
return res1 ^ res2;
#else
return acc[0] ^ acc[1];
#endif

}
#endif // HAVE_SSE

Expand Down
Loading