PageRenderTime 37ms CodeModel.GetById 21ms app.highlight 15ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/softcam/FFdecsa/parallel_032_4char.h

https://bitbucket.org/cesbo/astra
C Header | 206 lines | 162 code | 25 blank | 19 comment | 1 complexity | 0cf75a6129d36bd2486147ab3c95f203 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 char s1,s2,s3,s4;
 23};
 24typedef struct group_t group;
 25
 26#define GROUP_PARALLELISM 32
 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=0xff;
 40  res.s2=0xff;
 41  res.s3=0xff;
 42  res.s4=0xff;
 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 32 bits */
 84
 85static inline void FFTABLEIN(unsigned char *tab, int g, unsigned char *data){
 86  *(((int *)tab)+g)=*((int *)data);
 87  *(((int *)tab)+32+g)=*(((int *)data)+1);
 88}
 89
 90static inline void FFTABLEOUT(unsigned char *data, unsigned char *tab, int g){
 91  *((int *)data)=*(((int *)tab)+g);
 92  *(((int *)data)+1)=*(((int *)tab)+32+g);
 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+4*(g+(j>=4?32-1:0))+j);
 99  }
100}
101
102struct batch_t{
103  unsigned char s1,s2,s3,s4;
104};
105typedef struct batch_t batch;
106
107#define BYTES_PER_BATCH 4
108
109static inline batch B_FFAND(batch a,batch b){
110  batch res;
111  res.s1=a.s1&b.s1;
112  res.s2=a.s2&b.s2;
113  res.s3=a.s3&b.s3;
114  res.s4=a.s4&b.s4;
115  return res;
116}
117
118static inline batch B_FFOR(batch a,batch b){
119  batch res;
120  res.s1=a.s1|b.s1;
121  res.s2=a.s2|b.s2;
122  res.s3=a.s3|b.s3;
123  res.s4=a.s4|b.s4;
124  return res;
125}
126
127static inline batch B_FFXOR(batch a,batch b){
128  batch res;
129  res.s1=a.s1^b.s1;
130  res.s2=a.s2^b.s2;
131  res.s3=a.s3^b.s3;
132  res.s4=a.s4^b.s4;
133  return res;
134}
135
136
137static inline batch B_FFN_ALL_29(void){
138  batch res;
139  res.s1=0x29;
140  res.s2=0x29;
141  res.s3=0x29;
142  res.s4=0x29;
143  return res;
144}
145static inline batch B_FFN_ALL_02(void){
146  batch res;
147  res.s1=0x02;
148  res.s2=0x02;
149  res.s3=0x02;
150  res.s4=0x02;
151  return res;
152}
153static inline batch B_FFN_ALL_04(void){
154  batch res;
155  res.s1=0x04;
156  res.s2=0x04;
157  res.s3=0x04;
158  res.s4=0x04;
159  return res;
160}
161static inline batch B_FFN_ALL_10(void){
162  batch res;
163  res.s1=0x10;
164  res.s2=0x10;
165  res.s3=0x10;
166  res.s4=0x10;
167  return res;
168}
169static inline batch B_FFN_ALL_40(void){
170  batch res;
171  res.s1=0x40;
172  res.s2=0x40;
173  res.s3=0x40;
174  res.s4=0x40;
175  return res;
176}
177static inline batch B_FFN_ALL_80(void){
178  batch res;
179  res.s1=0x80;
180  res.s2=0x80;
181  res.s3=0x80;
182  res.s4=0x80;
183  return res;
184}
185
186static inline batch B_FFSH8L(batch a,int n){
187  batch res;
188  res.s1=a.s1<<n;
189  res.s2=a.s2<<n;
190  res.s3=a.s3<<n;
191  res.s4=a.s4<<n;
192  return res;
193}
194
195static inline batch B_FFSH8R(batch a,int n){
196  batch res;
197  res.s1=a.s1>>n;
198  res.s2=a.s2>>n;
199  res.s3=a.s3>>n;
200  res.s4=a.s4>>n;
201  return res;
202}
203
204
205static inline void M_EMPTY(void){
206}