Speed: 151-170 million cycles per frame render.
C Version 1.0 can be downloaded here http://pastebin.com/ET72dQM7
Latest JavaScript version(Acid 8) is @ http://pastebin.com/Y3gYPdVB
Comment/critique/improve/suggest more hacks,features and tricks to improve v1.0
Its not a direct port, but a reimplementation to capitalize on C features.
>>5
god, he is stupid. why don't you write everything in a single line #include <stdio.h>
#include <stdlib.h>
#include <math.h>
#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
#define v0 void inline unsigned long long rdtsc(){__asm{RDTSC}}
#define MAXFRAMES 30
#define DEFHRES 1080
#define DEFWRES 1920
#define SIZE DEFHRES*DEFWRES
#define STDOFFSET 1078
#define FILESIZE SIZE+STDOFFSET
#define PALSIZE 256
#define HEADERINFOSIZE 40
#define BITSPERPIXEL 8
#define FRAMEDIR "frames"
#define MAXCOLOR 0xff
#define magc 6755399441055744*1.6
#define mags 0x7fffffffffffffff
#define scale 0.125
#define offpi (2*M_PI/MAXFRAMES)
const f8 rangepi[]={0,0.4487989505128276,0.8975979010256552,1.3463968515384828,1.7951958020513104,2.243994752564138,2.6927937030769655}; f8 cospi[]={1,0.9009688679024191,0.6234898018587336,0.22252093395631445,-0.22252093395631434,-0.6234898018587335,-0.900968867902419}; f8 sinpi[]={0,0.4338837391175581,0.7818314824680298,0.9749279121818236,0.9749279121818236,0.7818314824680299,0.43388373911755823}; v0 main(s4 argc,s1**argv){ u8 starttime=rdtsc();u8 endtime; u1* bitmap=malloc(1078+SIZE); bitmap[0]='B'; bitmap[1]='M'; u4*crfilesize=bitmap+2; *crfilesize=FILESIZE; u4* bitmapoffset=bitmap+10; *bitmapoffset=STDOFFSET; u4* bhsize=bitmap+14; *bhsize=HEADERINFOSIZE; u4* w=bitmap+18; *w=DEFWRES; u4* h=bitmap+22; *h=DEFHRES; u2* bitplanes=bitmap+26; *bitplanes=1; u2* bitsperpixel=bitmap+28; *bitsperpixel=BITSPERPIXEL; u4* compression=bitmap+30; *compression=0; u4* imagesize=bitmap+34; *imagesize=SIZE; u4* xppm=bitmap+38; u4* yppm=bitmap+42; *xppm=40000; *yppm=40000; u4* numcolors=bitmap+46; *numcolors=256; u4* impcolors=bitmap+50; *impcolors=256; f8 off=0; u4 currframe=0; u4 i,c,m; u4 x,y,height=*h,width=*w; s4* colors=bitmap+54; s4* pixels=bitmap+STDOFFSET; s4 ic,ir,ig,ib,ia;double index,tx,ty,sn,frac; char filename[40];mkdir(FRAMEDIR); for(i=0;i<256;i++){ ic=i; ia=abs(256-(ic&0xf))<<24; ir=(ic)-31;if(ir<3 ){ir=0;} ig=(ic)-81;if(ig<9){ig=0;} ib=(ic)-0; if(ib<0 ){ib=0;} colors[i]=ia<<24|ir<<16|ig<<8|ib ; } f8 s,n2,abstrunc;s4 flt,temp,curx,cury; f8 da[2]; u4* sconv=&s; const f8 halfhscaled=height *0.5 * scale; const f8 halfwscaled=width *0.5 * scale; f8 tempadd,tempsub; f8 frameoffsets[MAXFRAMES]; for(i=0;i<MAXFRAMES;i++)frameoffsets[i]=offpi*i; f8 framecos[MAXFRAMES]; f8 framesin[MAXFRAMES]; for(i=0;i<MAXFRAMES;i++)framecos[i]=cos(frameoffsets[i]); for(i=0;i<MAXFRAMES;i++)framesin[i]=sin(frameoffsets[i]); f8 tysinpi[7]; f8 txarray[DEFWRES]; for(i=0;i<DEFWRES;i++)txarray[i]=(i* scale)-halfwscaled; f8 tyarray[DEFHRES]; for(i=0;i<DEFHRES;i++)tyarray[i]=(i* scale)-halfhscaled; f8 txcos[DEFWRES]; f8 txsin[DEFWRES]; f8 txcospi1[DEFWRES]; f8 txcospi2[DEFWRES]; f8 txcospi3[DEFWRES]; u4 framx=DEFWRES*MAXFRAMES; f8 txcosdiff[framx]; for(i=0;i<DEFWRES;i++)txcos[i]=cos(txarray[i]); for(i=0;i<DEFWRES;i++)txsin[i]=sin(txarray[i]); for(i=0;i<DEFWRES;i++)txcospi1[i]=cos(txarray[i]*cospi[1]); for(i=0;i<DEFWRES;i++)txcospi2[i]=cos(txarray[i]*cospi[2]); for(i=0;i<DEFWRES;i++)txcospi3[i]=cos(txarray[i]*cospi[3]); for(i=0,curx=0,cury=0;i<framx;i++){ txcosdiff[i]=( (txcos[curx]*framecos[cury]-txsin[curx]*framesin[cury])+7)*0.5 ; cury++; cury*=(cury<MAXFRAMES); curx+=(cury<1); } f8 ysin1,ysin2,ysin3,shaf; f8 fcurcos,fcursin; f8 curysin1sin; f8 curysin2sin; f8 curysin3sin; f8 curysin1cos; f8 curysin2cos; f8 curysin3cos; f8 tysin1[DEFHRES]; f8 tysin2[DEFHRES]; f8 tysin3[DEFHRES]; f8 tysin1cos[DEFHRES]; f8 tysin2cos[DEFHRES]; f8 tysin3cos[DEFHRES]; f8 tysin1sin[DEFHRES]; f8 tysin2sin[DEFHRES]; f8 tysin3sin[DEFHRES]; for(i=0;i<DEFHRES;i++)tysin1[i]=sinpi[1] * tyarray[i]; for(i=0;i<DEFHRES;i++)tysin2[i]=sinpi[2] * tyarray[i]; for(i=0;i<DEFHRES;i++)tysin3[i]=sinpi[3] * tyarray[i]; for(i=0;i<DEFHRES;i++)tysin1cos[i]=cos(tysin1[i]); for(i=0;i<DEFHRES;i++)tysin2cos[i]=cos(tysin2[i]); for(i=0;i<DEFHRES;i++)tysin3cos[i]=cos(tysin3[i]); for(i=0;i<DEFHRES;i++)tysin1sin[i]=sin(tysin1[i]); for(i=0;i<DEFHRES;i++)tysin2sin[i]=sin(tysin2[i]); for(i=0;i<DEFHRES;i++)tysin3sin[i]=sin(tysin3[i]); u4 globs,globa; u4 nsize=DEFHRES*DEFWRES; f8* prodadd=malloc(nsize*8); f8* prodsub=malloc(nsize*8); curx=0;cury=0; for(m=0;m<nsize;m++){ prodadd[m]=tysin1cos[cury]*txcospi1[curx]+tysin2cos[cury]*txcospi2[curx]+tysin3cos[cury]*txcospi3[curx]; curx++; curx*=(curx<DEFWRES); cury+=(curx<1); } curx=0;cury=0; for(m=0;m<nsize;m++){ prodsub[m]=tysin1sin[cury]*txcospi1[curx]+tysin2sin[cury]*txcospi2[curx]+tysin3sin[cury]*txcospi3[curx]; curx++; curx*=(curx<DEFWRES); cury+=(curx<1); } endtime=rdtsc(); printf("Precomputation in %llu cycles",endtime-starttime); for(currframe=0;currframe<MAXFRAMES;currframe++){ c=STDOFFSET;cury=0;globs=0;; fcurcos=framecos[currframe]; fcursin=framesin[currframe]; starttime=rdtsc(); for(y=0;y<height;y++){ globa=0; for(x=0;x<width;x++){ s=(prodadd[globs]*fcurcos); s-=(prodsub[globs++]*fcursin); s+=txcosdiff[globa+currframe]; shaf=s+magc; shaf-=magc; s=fabs(s-shaf); s=s>1?2-s:s; s=(s*0xff)+6755399441055744; bitmap[c++]=(u1)(*sconv); globa+=MAXFRAMES; }} endtime=rdtsc(); printf("Created frame:%d in %llu cycles ",currframe,endtime-starttime); sprintf(filename,"%s/frame%d.bmp",FRAMEDIR,currframe); FILE* cfile=fopen(filename,"wb"); if(!cfile){perror("File error");} fwrite(bitmap,1,FILESIZE,cfile);fclose(cfile);}} /* batch file used for this file: ================== @echo off ..\dmc -Jm -v2 -ff -o+all quasi.c quasi copy quasi.c archivedq\%random%%random%%random%quasi.c rem requires imageMagick installed "convert imagename" is the rem which is converting bitmap to gifs(use your own path). rem "C:\Program Files\ImageMagick-6.7.3-Q8\convert.exe" -coalesce -adjoin -delay 25 -compress LZW -quality 10 frames\fr* webanim.gif rem reference frame for correct render(!not exactly acid 8.js since it uses other cos/sin); fc/b frames\Ref.bmp frames\frame0.bmp|more */
Name:
Anonymous2011-11-07 12:19
>>5
Indentation is not even the worst thing, why the hell did you go defining stuff like s1 to signed char and not just use char? That is just retarded and obfuscated.
Name:
FrozenVoid!!mJCwdV5J0Xy2A212011-11-07 12:23
signed char:12 characters to write
char : 5 characters to write and char is not a definite type(it can be both signed and unsigned)
s1 :3 characters to write, completely and unambiguously defined as signed byte.
Who is retarded now?
>>9
... seriously? you can replace everything with letters. define w while
define f for
look, 5 less chars for while and 2 for for loops.
/prog/ I am not a very old /prog/ user. is this one a troll or just plain idiot?
Name:
FrozenVoid!!mJCwdV5J0Xy2A212011-11-07 12:26
for reference to numbers:
#define u1 unsigned char // unsigned bytes 1
#define u2 unsigned short // unsigned bytes 2
#define u4 unsigned int// unsigned bytes 4
#define u8 unsigned long long // unsigned bytes 8
#define s1 signed char// signed bytes 1
#define s2 signed short // signed bytes 2
#define s4 signed int//// signed bytes 4
#define s8 signed long long// signed bytes 8
#define f2 short float// float bytes 2
#define f4 float // float bytes 4
#define f8 double //float bytes 8
#define f10 long double// float bytes 10
#define v0 void //void 0 generic type
Name:
Anonymous2011-11-07 12:28
Who is retarded now?
You, because you have no common sense and are unable to write readable code.
If you spend 100 ms less when writing the type (once for a var, mind you), but a second more deciphering that type when you read it, your time saved is negative.
Also, I have no idea how can s1 be easier to write and remember than char to anyone.
>>10
Both, as well as autistic.
Note that the #define probably used up more chars than the use of these two in code, as well as made it unreadable.
Name:
FrozenVoid!!mJCwdV5J0Xy2A212011-11-07 12:31
>>10
it could clash with one letter variables so you should use
#define wh while
#define fo for
In reality I don't need it, since i don't use 'while' that often and for->fo is only 1 char savings(and i write mostly FOR loops).
Name:
FrozenVoid!!mJCwdV5J0Xy2A212011-11-07 12:34
>>12
Its easier when you read what they mean in >>11
Name:
Anonymous2011-11-07 12:37
>>16
No.
No, it's not.
It can't be easier than the standard int, char, void and such.
Name:
FrozenVoid!!mJCwdV5J0Xy2A212011-11-07 12:40
>>17
Only if your brain was destroyed by learning C that way. My way is shorter,self-descriptive and completely unambiguous.
Next time you type 'unsigned long long' into your editor of choice think about it.
Name:
Anonymous2011-11-07 12:42
>>18 unsigned long long and such might count as exceptions at times, but only if you use them a lot in the code.
Also, what happens when your code with s4 is compiled on a 64-bit platform?
Name:
FrozenVoid!!mJCwdV5J0Xy2A212011-11-07 12:50
>>19
Anytime you like you can change 1 define and its fixed for all code.
>>17
I am pretty sure if you use #define f for you will remove even more letters than using #define u8 unsigned long long. there is no reason not to use it.
Name:
FrozenVoid!!mJCwdV5J0Xy2A212011-11-07 12:52
>>21
define f is
1.not self-descriptive, how many bytes it takes?
2.may clash with one letter variables
3. is only 1 char shorter to type than u8
Name:
Anonymous2011-11-07 12:53
>>20
Or not have to change it at all because you use the normal type names.
>>22 not self-descriptive, how many bytes it takes?
it takes 2 less chars per for loop? what is the question? 2.may clash with one letter variables
then don't use f for any other variables. 3. is only 1 char shorter to type than u8
yeah but you typed u8 twice in your code but there are lots of for loops.
as a c newbie, and coming from other languages, "uint8" and such seems much nicer to me than "unsigned char" etc. although aren't there standard uint8_t types or no?
Name:
Anonymous2011-11-07 13:06
that has got to be the ugliest code i've ever seen.
never heard of intendation, have you, FrozenNigger?
then again, autism
Name:
FrozenVoid!!mJCwdV5J0Xy2A212011-11-07 13:12
>>28
u8 is self-descriptive: u=unsigned 8=8 bytes
f is not, you can easily confuse it with a function or a variable.
Name:
FrozenVoid!!mJCwdV5J0Xy2A212011-11-07 13:15
>>28
chars saved by those 2 u8=32 chars
chars saved by hypothetically shortening all for loops to (fo) in my code =27 chars
see the difference? a measly 2 u8 save as much as 27 fo loops
>>31
Only if your brain was destroyed by learning C that way.
also size of long/int/short is not a standard in C. so u8 might describe your data wrong
Name:
FrozenVoid!!mJCwdV5J0Xy2A212011-11-07 13:22
>>35
If it describes the data wrong you can easily see it and correct to your compiler/arch preference by changing a single line of code(the #define u8)
>>32
it is your fault if you are so stupid and can't define it as "f" because you can't remember if letter "f" is already allocated or not.
Name:
FrozenVoid!!mJCwdV5J0Xy2A212011-11-07 13:24
If you can handle hunting for "standard data types" and changing them one by one in "standard portable C" to port your software,
you can certainly handle the difficulty of replacing one #define
Name:
Anonymous2011-11-07 13:26
>>36
So, you change it into #define u16 (or u4), then you have to change it everywhere else in your code. Or at least use stdint.h types, such as uint64_t.