M4RI  20140914
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 
39 
45 static inline void _mzd_combine(word *c, word const *t1, wi_t wide_in) {
46  wi_t wide = wide_in;
47 #if __M4RI_HAVE_SSE2
48  /* assuming c, t1 are alligned the same way */
49 
50  if (__M4RI_ALIGNMENT(c,16)==8 && wide) {
51  *c++ ^= *t1++;
52  wide--;
53  }
54 
55  __m128i *__c = (__m128i*)c;
56  __m128i *__t1 = (__m128i*)t1;
57  const __m128i *eof = (__m128i*)((unsigned long)(c + wide) & ~0xFUL);
58  __m128i xmm1;
59 
60 
61  while(__c < eof-1) {
62  xmm1 = _mm_xor_si128(*__c, *__t1++);
63  *__c++ = xmm1;
64  xmm1 = _mm_xor_si128(*__c, *__t1++);
65  *__c++ = xmm1;
66  }
67 
68  if(__c < eof) {
69  xmm1 = _mm_xor_si128(*__c, *__t1++);
70  *__c++ = xmm1;
71  }
72 
73  c = (word*)__c;
74  t1 = (word*)__t1;
75  wide = ((sizeof(word) * wide) % 16) / sizeof(word);
76 
77  if(!wide) {
78  __M4RI_DD_RAWROW(c, wide_in);
79  return;
80  }
81 #endif // __M4RI_HAVE_SSE2
82 
83  wi_t n = (wide + 7) / 8;
84  switch (wide % 8) {
85  case 0: do { *c++ ^= *t1++;
86  case 7: *c++ ^= *t1++;
87  case 6: *c++ ^= *t1++;
88  case 5: *c++ ^= *t1++;
89  case 4: *c++ ^= *t1++;
90  case 3: *c++ ^= *t1++;
91  case 2: *c++ ^= *t1++;
92  case 1: *c++ ^= *t1++;
93  } while (--n > 0);
94  }
95  __M4RI_DD_RAWROW(c, wide_in);
96 }
97 
98 #define N 2
99 #include "xor_template.h"
100 #undef N
101 
102 #define N 3
103 #include "xor_template.h"
104 #undef N
105 
106 #define N 4
107 #include "xor_template.h"
108 #undef N
109 
110 #define N 5
111 #include "xor_template.h"
112 #undef N
113 
114 #define N 6
115 #include "xor_template.h"
116 #undef N
117 
118 #define N 7
119 #include "xor_template.h"
120 #undef N
121 
122 #define N 8
123 #include "xor_template.h"
124 #undef N
125 
126 #endif // M4RI_XOR_H
#define __M4RI_ALIGNMENT(addr, n)
Return alignment of addr w.r.t. n. For example the address 17 would be 1 aligned w.r.t. 16.
Definition: misc.h:421
uint64_t word
A word is the typical packed data structure to represent packed bits.
Definition: misc.h:87
int wi_t
Type of word indexes.
Definition: misc.h:80