PageRenderTime 30ms CodeModel.GetById 13ms app.highlight 15ms RepoModel.GetById 1ms app.codeStats 0ms

/modules/softcam/FFdecsa/parallel_128_4int.h

https://bitbucket.org/cesbo/astra
C Header | 207 lines | 162 code | 26 blank | 19 comment | 1 complexity | 03d7977aecc4edfc070cdadb01005c08 MD5 | raw file
Possible License(s): GPL-3.0, GPL-2.0
  1/* FFdecsa -- fast decsa algorithm
  2 *
  3 * Copyright (C) 2003-2004  fatih89r
  4 *
  5 * This program is free software; you can redistribute it and/or modify
  6 * it under the terms of the GNU General Public License as published by
  7 * the Free Software Foundation; either version 2 of the License, or
  8 * (at your option) any later version.
  9 *
 10 * This program is distributed in the hope that it will be useful,
 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 13 * GNU General Public License for more details.
 14 *
 15 * You should have received a copy of the GNU General Public License
 16 * along with this program; if not, write to the Free Software
 17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 18 */
 19
 20
 21struct group_t{
 22  unsigned int s1,s2,s3,s4;
 23};
 24typedef struct group_t group;
 25
 26#define GROUP_PARALLELISM 128
 27
 28static inline group FF0(void){
 29  group res;
 30  res.s1=0x0;
 31  res.s2=0x0;
 32  res.s3=0x0;
 33  res.s4=0x0;
 34  return res;
 35}
 36
 37static inline group FF1(void){
 38  group res;
 39  res.s1=0xffffffff;
 40  res.s2=0xffffffff;
 41  res.s3=0xffffffff;
 42  res.s4=0xffffffff;
 43  return res;
 44}
 45
 46static inline group FFAND(group a,group b){
 47  group res;
 48  res.s1=a.s1&b.s1;
 49  res.s2=a.s2&b.s2;
 50  res.s3=a.s3&b.s3;
 51  res.s4=a.s4&b.s4;
 52  return res;
 53}
 54
 55static inline group FFOR(group a,group b){
 56  group res;
 57  res.s1=a.s1|b.s1;
 58  res.s2=a.s2|b.s2;
 59  res.s3=a.s3|b.s3;
 60  res.s4=a.s4|b.s4;
 61  return res;
 62}
 63
 64static inline group FFXOR(group a,group b){
 65  group res;
 66  res.s1=a.s1^b.s1;
 67  res.s2=a.s2^b.s2;
 68  res.s3=a.s3^b.s3;
 69  res.s4=a.s4^b.s4;
 70  return res;
 71}
 72
 73static inline group FFNOT(group a){
 74  group res;
 75  res.s1=~a.s1;
 76  res.s2=~a.s2;
 77  res.s3=~a.s3;
 78  res.s4=~a.s4;
 79  return res;
 80}
 81
 82
 83/* 64 rows of 128 bits */
 84
 85static inline void FFTABLEIN(unsigned char *tab, int g, unsigned char *data){
 86  *(((int *)tab)+2*g)=*((int *)data);
 87  *(((int *)tab)+2*g+1)=*(((int *)data)+1);
 88}
 89
 90static inline void FFTABLEOUT(unsigned char *data, unsigned char *tab, int g){
 91  *((int *)data)=*(((int *)tab)+2*g);
 92  *(((int *)data)+1)=*(((int *)tab)+2*g+1);
 93}
 94
 95static inline void FFTABLEOUTXORNBY(int n, unsigned char *data, unsigned char *tab, int g){
 96  int j;
 97  for(j=0;j<n;j++){
 98    *(data+j)^=*(tab+8*g+j);
 99  }
100}
101
102
103struct batch_t{
104  unsigned int s1,s2,s3,s4;
105};
106typedef struct batch_t batch;
107
108#define BYTES_PER_BATCH 16
109
110static inline batch B_FFAND(batch a,batch b){
111  batch res;
112  res.s1=a.s1&b.s1;
113  res.s2=a.s2&b.s2;
114  res.s3=a.s3&b.s3;
115  res.s4=a.s4&b.s4;
116  return res;
117}
118
119static inline batch B_FFOR(batch a,batch b){
120  batch res;
121  res.s1=a.s1|b.s1;
122  res.s2=a.s2|b.s2;
123  res.s3=a.s3|b.s3;
124  res.s4=a.s4|b.s4;
125  return res;
126}
127
128static inline batch B_FFXOR(batch a,batch b){
129  batch res;
130  res.s1=a.s1^b.s1;
131  res.s2=a.s2^b.s2;
132  res.s3=a.s3^b.s3;
133  res.s4=a.s4^b.s4;
134  return res;
135}
136
137
138static inline batch B_FFN_ALL_29(void){
139  batch res;
140  res.s1=0x29292929;
141  res.s2=0x29292929;
142  res.s3=0x29292929;
143  res.s4=0x29292929;
144  return res;
145}
146static inline batch B_FFN_ALL_02(void){
147  batch res;
148  res.s1=0x02020202;
149  res.s2=0x02020202;
150  res.s3=0x02020202;
151  res.s4=0x02020202;
152  return res;
153}
154static inline batch B_FFN_ALL_04(void){
155  batch res;
156  res.s1=0x04040404;
157  res.s2=0x04040404;
158  res.s3=0x04040404;
159  res.s4=0x04040404;
160  return res;
161}
162static inline batch B_FFN_ALL_10(void){
163  batch res;
164  res.s1=0x10101010;
165  res.s2=0x10101010;
166  res.s3=0x10101010;
167  res.s4=0x10101010;
168  return res;
169}
170static inline batch B_FFN_ALL_40(void){
171  batch res;
172  res.s1=0x40404040;
173  res.s2=0x40404040;
174  res.s3=0x40404040;
175  res.s4=0x40404040;
176  return res;
177}
178static inline batch B_FFN_ALL_80(void){
179  batch res;
180  res.s1=0x80808080;
181  res.s2=0x80808080;
182  res.s3=0x80808080;
183  res.s4=0x80808080;
184  return res;
185}
186
187static inline batch B_FFSH8L(batch a,int n){
188  batch res;
189  res.s1=a.s1<<n;
190  res.s2=a.s2<<n;
191  res.s3=a.s3<<n;
192  res.s4=a.s4<<n;
193  return res;
194}
195
196static inline batch B_FFSH8R(batch a,int n){
197  batch res;
198  res.s1=a.s1>>n;
199  res.s2=a.s2>>n;
200  res.s3=a.s3>>n;
201  res.s4=a.s4>>n;
202  return res;
203}
204
205
206static inline void M_EMPTY(void){
207}