M4RI 20250128
xor.h
1/*
2 * Functions for adding vectors.
3 *
4 * \author Martin Albrecht <martinralbrecht@googlemail.com>
5 *
6 */
7
8#ifndef M4RI_XOR_H
9#define M4RI_XOR_H
10
11/*******************************************************************
12 *
13 * M4RI: Linear Algebra over GF(2)
14 *
15 * Copyright (C) 2008-2013 Martin Albrecht <martinralbrecht@googlemail.com>
16 *
17 * Distributed under the terms of the GNU General Public License (GPL)
18 * version 2 or higher.
19 *
20 * This code is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 * General Public License for more details.
24 *
25 * The full text of the GPL is available at:
26 *
27 * http://www.gnu.org/licenses/
28 *
29 ********************************************************************/
30
31#include <m4ri/m4ri_config.h>
32
33#if __M4RI_HAVE_SSE2
34#include <emmintrin.h>
35#endif
36
37#include <m4ri/misc.h>
38
43
44static inline void _mzd_combine(word *c, word const *t1, wi_t wide_in) {
45 wi_t wide = wide_in;
46#if __M4RI_HAVE_SSE2
47 /* assuming c, t1 are alligned the same way */
48
49 if (__M4RI_ALIGNMENT(c, 16) == 8 && wide) {
50 *c++ ^= *t1++;
51 wide--;
52 }
53
54 __m128i *__c = (__m128i *)c;
55 __m128i *__t1 = (__m128i *)t1;
56 const __m128i *eof = (__m128i *)((unsigned long)(c + wide) & ~0xFUL);
57 __m128i xmm1;
58
59 while (__c < eof - 1) {
60 xmm1 = _mm_xor_si128(*__c, *__t1++);
61 *__c++ = xmm1;
62 xmm1 = _mm_xor_si128(*__c, *__t1++);
63 *__c++ = xmm1;
64 }
65
66 if (__c < eof) {
67 xmm1 = _mm_xor_si128(*__c, *__t1++);
68 *__c++ = xmm1;
69 }
70
71 c = (word *)__c;
72 t1 = (word *)__t1;
73 wide = ((sizeof(word) * wide) % 16) / sizeof(word);
74
75 if (!wide) {
76 __M4RI_DD_RAWROW(c, wide_in);
77 return;
78 }
79#endif // __M4RI_HAVE_SSE2
80
81 wi_t n = (wide + 7) / 8;
82 switch (wide % 8) {
83 case 0: do { *c++ ^= *t1++;
84 case 7: *c++ ^= *t1++;
85 case 6: *c++ ^= *t1++;
86 case 5: *c++ ^= *t1++;
87 case 4: *c++ ^= *t1++;
88 case 3: *c++ ^= *t1++;
89 case 2: *c++ ^= *t1++;
90 case 1: *c++ ^= *t1++;
91 } while (--n > 0);
92 }
93 __M4RI_DD_RAWROW(c, wide_in);
94}
95
96#define N 2
97#include "xor_template.h"
98#undef N
99
100#define N 3
101#include "xor_template.h"
102#undef N
103
104#define N 4
105#include "xor_template.h"
106#undef N
107
108#define N 5
109#include "xor_template.h"
110#undef N
111
112#define N 6
113#include "xor_template.h"
114#undef N
115
116#define N 7
117#include "xor_template.h"
118#undef N
119
120#define N 8
121#include "xor_template.h"
122#undef N
123
124#endif // M4RI_XOR_H
Helper functions.
#define __M4RI_ALIGNMENT(addr, n)
Return alignment of addr w.r.t. n. For example the address 17 would be 1 aligned w....
Definition misc.h:421
int64_t wi_t
Type of word indexes.
Definition misc.h:81
uint64_t word
A word is the typical packed data structure to represent packed bits.
Definition misc.h:87