/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

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