Registered Member #4266
Joined: Fri Dec 16 2011, 03:15AM
Location:
Posts: 874
|
Hi I was hopeing to start a thread for a community project that uses Parallel logic, that people can use, the idea was to have a C libary that is highly portable. Anyone can take the code from older posts and update them, and the group works out if it should stay.
Starting it off
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
unsigned char output[256*8+16];
unsigned char input1[256*8+16];
unsigned char input2[256*8+16];
unsigned char hex[257][8];
add256(unsigned char input1[256], unsigned char input2[256]) {
unsigned char a[256*8+16],b[256*8+16],,sum[256*8+16],c;
unsigned int i;
for(i=0,t=0;t<(256*8);t=t+8) {
a[t+0] = hex[input1[i]][0];
a[t+1] = hex[input1[i]][1];
a[t+2] = hex[input1[i]][2];
a[t+3] = hex[input1[i]][3];
a[t+4] = hex[input1[i]][4];
a[t+5] = hex[input1[i]][5];
a[t+6] = hex[input1[i]][6];
a[t+7] = hex[input1[i]][7];
b[t+0] = hex[input2[i]][0];
b[t+1] = hex[input2[i]][1];
b[t+2] = hex[input2[i]][2];
b[t+3] = hex[input2[i]][3];
b[t+4] = hex[input2[i]][4];
b[t+5] = hex[input2[i]][5];
b[t+6] = hex[input2[i]][6];
b[t+7] = hex[input2[i]][7];
}
for(i = 0; i < 256*8 ;i++){
sum[i] = ((a[i] ^ b[i]) ^ c); // c is carry
c = ((a[i] & b[i]) | (a[i] & c)) | (b[i] & c);
}
for(t=0;t<256*8;t=t+8) {
for(i=0;i<=0xff;i++) {
count=0;
if(sum[0+t] == hex[i][0]) count++;
if(sum[1+t] == hex[i][1]) count++;
if(sum[2+t] == hex[i][2]) count++;
if(sum[3+t] == hex[i][3]) count++;
if(sum[4+t] == hex[i][4]) count++;
if(sum[5+t] == hex[i][5]) count++;
if(sum[6+t] == hex[i][6]) count++;
if(sum[7+t] == hex[i][7]) count++;
if(count > 7) goto out;
}
out:
if(t < 8) output[0] = i;
if(t >= 8) output[t/8] = i;
}
}
main() {
unsigned int c;
unsigned char init[257] = {0x7f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},init1[257];
memset(init1,0x00,sizeof(init1));
unsigned char val[257] = {0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x41};
c=0;
for(i=0;i<=0xff;i++) {
c=i;
hex[i][0] = c&0x01;
c=c>>1;
hex[i][1] = c&0x01;
c=c>>1;
hex[i][2] = c&0x01;
c=c>>1;
hex[i][3] = c&0x01;
c=c>>1;
hex[i][4] = c&0x01;
c=c>>1;
hex[i][5] = c&0x01;
c=c>>1;
hex[i][6] = c&0x01;
c=c>>1;
hex[i][7] = c&0x01;
}
add256(init,init1);
add256(output,val);
}
|