PageRenderTime 34ms CodeModel.GetById 21ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

/FFdecsa/parallel_064_2int.h

https://bitbucket.org/a84/gs_public/
C++ Header | 175 lines | 130 code | 26 blank | 19 comment | 1 complexity | af145c77912ba77df34c3b72eaf63a89 MD5 | raw file
  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;
 23  unsigned int s2;
 24};
 25typedef struct group_t group;
 26
 27#define GROUP_PARALLELISM 64
 28
 29group static inline FF0(){
 30  group res;
 31  res.s1=0x0;
 32  res.s2=0x0;
 33  return res;
 34}
 35
 36group static inline FF1(){
 37  group res;
 38  res.s1=0xffffffff;
 39  res.s2=0xffffffff;
 40  return res;
 41}
 42
 43group static inline FFAND(group a,group b){
 44  group res;
 45  res.s1=a.s1&b.s1;
 46  res.s2=a.s2&b.s2;
 47  return res;
 48}
 49
 50group static inline FFOR(group a,group b){
 51  group res;
 52  res.s1=a.s1|b.s1;
 53  res.s2=a.s2|b.s2;
 54  return res;
 55}
 56
 57group static inline FFXOR(group a,group b){
 58  group res;
 59  res.s1=a.s1^b.s1;
 60  res.s2=a.s2^b.s2;
 61  return res;
 62}
 63
 64group static inline FFNOT(group a){
 65  group res;
 66  res.s1=~a.s1;
 67  res.s2=~a.s2;
 68  return res;
 69}
 70
 71
 72/* 64 rows of 64 bits */
 73
 74void static inline FFTABLEIN(unsigned char *tab, int g, unsigned char *data){
 75  *(((int *)tab)+2*g)=*((int *)data);
 76  *(((int *)tab)+2*g+1)=*(((int *)data)+1);
 77}
 78
 79void static inline FFTABLEOUT(unsigned char *data, unsigned char *tab, int g){
 80  *((int *)data)=*(((int *)tab)+2*g);
 81  *(((int *)data)+1)=*(((int *)tab)+2*g+1);
 82}
 83
 84void static inline FFTABLEOUTXORNBY(int n, unsigned char *data, unsigned char *tab, int g){
 85  int j;
 86  for(j=0;j<n;j++){
 87    *(data+j)^=*(tab+8*g+j);
 88  }
 89}
 90
 91struct batch_t{
 92  unsigned int s1;
 93  unsigned int s2;
 94};
 95typedef struct batch_t batch;
 96
 97#define BYTES_PER_BATCH 8
 98
 99batch static inline B_FFAND(batch a,batch b){
100  batch res;
101  res.s1=a.s1&b.s1;
102  res.s2=a.s2&b.s2;
103  return res;
104}
105
106batch static inline B_FFOR(batch a,batch b){
107  batch res;
108  res.s1=a.s1|b.s1;
109  res.s2=a.s2|b.s2;
110  return res;
111}
112
113batch static inline B_FFXOR(batch a,batch b){
114  batch res;
115  res.s1=a.s1^b.s1;
116  res.s2=a.s2^b.s2;
117  return res;
118}
119
120
121batch static inline B_FFN_ALL_29(){
122  batch res;
123  res.s1=0x29292929;
124  res.s2=0x29292929;
125  return res;
126}
127batch static inline B_FFN_ALL_02(){
128  batch res;
129  res.s1=0x02020202;
130  res.s2=0x02020202;
131  return res;
132}
133batch static inline B_FFN_ALL_04(){
134  batch res;
135  res.s1=0x04040404;
136  res.s2=0x04040404;
137  return res;
138}
139batch static inline B_FFN_ALL_10(){
140  batch res;
141  res.s1=0x10101010;
142  res.s2=0x10101010;
143  return res;
144}
145batch static inline B_FFN_ALL_40(){
146  batch res;
147  res.s1=0x40404040;
148  res.s2=0x40404040;
149  return res;
150}
151batch static inline B_FFN_ALL_80(){
152  batch res;
153  res.s1=0x80808080;
154  res.s2=0x80808080;
155  return res;
156}
157
158
159batch static inline B_FFSH8L(batch a,int n){
160  batch res;
161  res.s1=a.s1<<n;
162  res.s2=a.s2<<n;
163  return res;
164}
165
166batch static inline B_FFSH8R(batch a,int n){
167  batch res;
168  res.s1=a.s1>>n;
169  res.s2=a.s2>>n;
170  return res;
171}
172
173
174void static inline M_EMPTY(void){
175}