>>64
I only have a small prototype which is limited to 1 function
and its very very slow. You can have it since i'm not interested in this anymore:
//====Headers
//the code is of bit of mess, this is unchunked, single file at onc e version which takes alot of time to search
#define VERSION "Infinity Compressor 1.01 by FrozenVoid\n"
//..\gcc -O2 main.c -lmpfr -lgmp -o a.exe
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <float.h>
#include <time.h>
#include <gmp.h> //using libgmp.a
#include <mpfr.h>
//======Types
#define u1 unsigned char
#define u2 unsigned short
#define u4 unsigned int
#define u8 unsigned long long
#define s1 signed char
#define s2 signed short
#define s4 signed int
#define s8 signed long long
#define f2 short float
#define f4 float
#define f8 double
#define f10 long double
//====Bithacks
#define setb(o,p) (o|=(1<<p)) //byte| 1<< pos
#define clrb(o,p) (o&=(~(1<<p))) // byte | 11101111
#define togb(o,p) (o^=(1<<p))
#define chkb(o,p) ((o>>p)&1)
#define bitchar(bitchar_bit) (48|bitchar_bit) // 48|0 or 1
//====Func GCC
static __inline__ u8 rdtsc(void){u8 x;
__asm__ volatile (".byte 0x0f, 0x31" : "=A" (x)); return x;}
u8 fsize(u1* filename){
FILE* tfile=fopen(filename,"rb");
if(!tfile){perror(filename);return 0;}
fseek(tfile,0,SEEK_END);
u8 sz=(u8)(ftell(tfile));fclose(tfile);return sz;}
u1* getcontent(u1*filename){//file to buffer
u8 size=fsize(filename);//
if(!size){perror("Zero length content"); return NULL;}
u1* res=malloc(size);
if(!res){perror("Malloc failure");return NULL;}
FILE* inpfile=fopen(filename,"rb");
if(!inpfile){perror("File cannot be read");return NULL;}
u8 findex=(u8)fread(res,1,size,inpfile);fclose(inpfile);
if(findex!=size){perror("size mismatch");return NULL;}
return res;}
void readcontent(u1* filename,u1* storage){
if(!filename){perror("Invalid filename"); return;}
u8 inpsize=fsize(filename);
if(!inpsize){perror("File empty");return;}
FILE* in=fopen(filename,"rb");
if(!in){perror(filename);return;}
storage=realloc(storage,inpsize);
if(!storage){perror("Malloc failure");return;}
u8 findex=(u8)fread(storage,1,inpsize,in);
fclose(in);
if(findex!=inpsize){perror("Read size mismatch");return;}}
void writecontent(u1* filename,u1* content,u8 size){
FILE* out=fopen(filename,"wb");
if(!out){perror(filename);return;}
u8 findex=(u8)fwrite(content,1,size,out);fclose(out);
if(findex!=size) perror("Write size mismatch");}
void buf2mpz(u1* string,mpz_t num,u8 size){
if(!string){perror("NULL string");return;}
if(!num){perror("Invalid mpz_t");return;}
if(!size){perror("Zero-length string");return;}
mpz_import(num,size, 1,1, -1, 0,string);
}
#define loop(loopx,loopy) for(loopx=0;loopx<loopy;loopx++)
#define fextension(string) strrchr(string,'.')?:".???"
#define isbit(xint,ypos) ((xint)&(1<<ypos))
#define frop(x,filename) FILE* x=fopen(filename,"rb")
#define fwop(x,filename) FILE* x=fopen(filename,"wb")
#define outx(x,fil) fwrite(&x,1,sizeof(x),fil);
#define mpz(x) mpz_t x;mpz_init(x);
#define mpf(x) mpfr_t x;mpfr_init(x);
//static array
#define mpfr(x) MPFR_DECL_INIT(x, 53) //returns float
#define DEBUG 1 //debug
#define DEBUG2 0 //symbolics
#define DEBUG3 0 //verbose
#define POWERPREC 512 //more=slower, more precise
#define fdisp(x) puts("");mpf_out_str(stdout,10, 0,x);
//===========MAIN======================
#define setch(o,ch,pos) (o|=ch<<(pos<<1)) // pos 0-3,ch=0-3
#define getbb(o,pos) ((o>>(pos<<1))&3) //get 001100
>>2 &3
#define getb0(b) (b&3)
#define getb1(b) ((b
>>2)&3)
#define getb2(b) ((b
>>4)&3)
#define getb3(b) ((b
>>6)&3)
//(1<<(pos<<1))
//========MAIN===
//code is from another compressor i wrote
void main(int argc,char**argv){
if(!argv[1]){printf("Syntax:cmp inputfile [-d=decode]");exit(1);}
//-----DECODE--TODO-----
if(argv[2] && !strcmp(argv[2],"-d")){//decode Data
}
//------INPUT--------
#define PR0 MPFR_RNDN
printf(VERSION);
/*
>> MPFR_RNDN: round to nearest (roundTiesToEven in IEEE 754-2008),
MPFR_RNDZ: round toward zero (roundTowardZero in IEEE 754-2008),
MPFR_RNDU: round toward plus infinity (roundTowardPositive in IEEE 754-2008),
MPFR_RNDD: round toward minus infinity (roundTowardNegative in IEEE 754-2008),
MPFR_RNDA: round away from zero.
*/
FILE* output=fopen("Result.cmp","wb");
u8 inpsize=fsize(argv[1]);
fwrite(&inpsize,8,1,output);//write inpsize to avoid misdecoding;
u8 bitlen=inpsize*8;
s8 Kmod=0; //window modifier
s4 check,checklow,checkhi,checkold;
if(!inpsize){perror("input size invalid");return;};
u1* input=getcontent(argv[1]);
//convert to mpz
mpfr_set_default_prec( bitlen);
mpz(Z);buf2mpz(input,Z,inpsize);
mpf(median);//Z->median
mpfr_set_z(median,Z,PR0);
mpf(scalemodmax);//window bounds(1/2 filesize to be safe)
mpfr_set_ui(scalemodmax,1,PR0);
mpfr_mul_2ui(scalemodmax,scalemodmax,inpsize*4,PR0);//scalemods max=half filelength in bits
mpf(K);//window base multiplier=2^inpsize8: 4 times;
mpfr_set_ui(K,1,PR0);//4 times muls
mpfr_mul_2ui(K,K, bitlen,PR0);
mpfr_mul_2ui(K,K, bitlen,PR0);
mpfr_mul_2ui(K,K, bitlen,PR0);
mpfr_mul_2ui(K,K, bitlen,PR0);
//base =1+ 1e-100
mpfr_t base;mpfr_init2(base,POWERPREC);
mpfr_set_str(base,"1e-100",10,PR0);
mpfr_add_ui(base,base,1,PR0);
check=mpfr_cmp_ui (base,1);
//create initial bounds
mpf(Zlow);mpfr_sub(Zlow,median,scalemodmax,PR0);
mpf(Zhi);mpfr_add(Zhi,median,scalemodmax,PR0);
//multiply bounds to get initial,non-kmod window
mpf(Low);mpfr_mul(Low,Zlow,K,PR0);
mpf(Hi);mpfr_mul(Hi,Zhi,K,PR0);
//search for closest base match to window
mpf(Result);//Power is 512 bits;result stores Base^Power
mpfr_t Power;mpfr_init2(Power,POWERPREC);
mpfr_t Powermin;mpfr_init2(Powermin,POWERPREC);
mpfr_t Powermax;mpfr_init2(Powermax,POWERPREC);
mpfr_t Powerold;mpfr_init2(Powerold,POWERPREC);
mpfr_set_str(Power,"2",10,PR0);
mpfr_set_str(Powermin,"1",10,PR0);
mpfr_set_str(Powerold,"0",10,PR0);
//genrate match above Hi
if(DEBUG)puts("\nCalculating initial bounds");
preloop://
mpfr_pow(Result,base,Power,PR0);
check=mpfr_cmp(Result,Hi);
if(check<1){if(DEBUG2)printf("*");
mpfr_mul_ui(Power,Power,1024,PR0);
goto preloop;};//if max found set powermax
mpfr_set (Powermax,Power,PR0);
if(DEBUG)puts("\nCalculating closest match to window");
mainloop:;//search for closest match
//power=avg(Powermax,Powermin)
mpfr_add (Power,Powermax,Powermin,PR0);
mpfr_div_2ui(Power,Power,1,PR0);
mpfr_pow(Result,base,Power,PR0);
checkold=mpfr_cmp(Power,Powerold);
checkhi=mpfr_cmp(Result,Hi);
checklow=mpfr_cmp(Result,Low);
if(checkold==0){if(DEBUG2)printf("=");
if(DEBUG)printf("\nInitiating window search: Result is %s window",checkhi>0?"above":"below");
mpfr_out_str(output,16,0,Power,PR0);
goto windowsearch;//power stall:search window to Result
}
if(checkhi>0){if(DEBUG2)printf("+");
mpfr_set(Powerold,Power,PR0);
mpfr_swap(Powermax,Power);
goto mainloop;}
if(checklow<0){if(DEBUG2)printf("-");
mpfr_set(Powerold,Power,PR0);
mpfr_swap(Powermin,Power);
goto mainloop;}
//inside initial window
if(DEBUG)printf("Found match inside initial window");
mpfr_out_str(output,16,0,Power,PR0);//write power(hex)
goto ex1;//success :Inside initial window?
//implement correct window shifting code
windowsearch://to get Result into window, shift window
//search direction: simple add+-1
checkhi=mpfr_cmp(Result,Hi);
checklow=mpfr_cmp(Result,Low);
if(checkhi>0){//Result is up, shift window up
Kmod++;//Kmod Up, Hi/Low+=Scalemodmax
if(DEBUG2){printf("+");}
mpfr_add(Hi,Hi,scalemodmax,PR0);
mpfr_add(Low,Low,scalemodmax,PR0);
goto windowsearch;
}
if(checklow<0){//Result is down ,shift window down
Kmod--;//Kmod down
if(DEBUG2){printf("-");}
mpfr_sub(Hi,Hi,scalemodmax,PR0);
mpfr_sub(Low,Low,scalemodmax,PR0);
goto windowsearch;
}
//found Kmod: apply Kmod to
if(DEBUG)printf("Found Kmod for window");
ex1:;//output result :Scalemod & exit
if(DEBUG)printf("Calculating final scalemod");
mpf(newK);mpfr_set_si(newK,Kmod,PR0);
mpfr_add(newK,K,newK,PR0);//newK=K-+Kmod
fwrite(&Kmod,8,1,output);//write Kmod
mpfr_div(Result,Result,newK,PR0);//get into initial window
check=mpfr_cmp(Result,median);//if R>M scalemod neg
mpf(scalemod);mpfr_sub(scalemod,median,Result,PR0);
mpfr_out_str(output,16,0,scalemod,PR0);//write scaledmod(hex)
//====================================
; }