|
knighty
Fractal Iambus
Posts: 819
|
|
« Reply #16 on: April 07, 2015, 09:22:40 PM » |
|
Ah yes haven't tested that. sorry! One needs to set -ffast-math in order to have gcc compile to native cpu floating point operations. Here are my experiments: The source. It is just like visual's OP but used x and y instead: #include <math.h> __attribute__((packed)) struct TIteration3Dext { double Cw,Rold,RStopD,x,y,z,w; // use with neg indizes before C1. w is also used for 3d ifs and abox analytic DE double Px, Py, Pz; // actual position, never change these! Can be used as input. double Cx, Cy, Cz; //+24 these are the constants for adding. Pxyz or the julia seed. Cw is @-56 (begin of struct) void* PVar; //+48 the actual formulas adress of constants and vars, constants at offset 0 increasing, user vars below -8 float SmoothItD; //+52 double Rout; //+56 the square of the vector length, can be used as input int ItResultI; //+64 int maxIt; //+68 float RStop; //+72 int nHybrid[6]; //+76 all formulas iteration counts or single weights in interpol-hybrid void* fHPVar[6]; //+100 all formulas pointer to constants+vars, PVars-8=0.5, use PVar for the actual formula void* fHybrid[6]; //+124 the formulas adresses int CalcSIT; //+148 int DoJulia; //+152 float LNRStop; //+156 int DEoption; //+160 float fHln[6]; //+164 for SmoothIts int iRepeatFrom; //+188 double OTrap; //+192 double VaryScale; //+200 to use in vary by its int bFirstIt; //+208 used also as iteration count, is set to 0 on it-start int bTmp; //+212 tmpBuf, free of use. double Dfree1; //+216 double Dfree2; //+224 double Deriv1; //+232 for 4D first deriv or as full derivs double Deriv2; //+240 double Deriv3; //+248 float SMatrix4[4][4]; //+256 for 4d rotation, used like most other values only by the programs iteration loop procedure };
// fastcall is not quite delphi fastcall. // first two args are ok, third is in ecx in delphi, on stack here. void __attribute__((fastcall)) formula( double* x, // [eax] double* y, // [edx] double* arg, // [ebp+8], points to TIteration3Dext.C1 void* dummy // so we end w/ ret 8 as delphi expects ) { // Compute ptr to proper start of TIteration3Dext struct. struct TIteration3Dext* cfg = (struct TIteration3Dext*)(arg-7);
// Read / write some fields as demonstration.. not a real formula ;-) double tmp=cfg->x; cfg->x=cos(sin(cfg->y)); cfg->y=tmp; } Compile with gcc -c -m32 -O3 -mfpmath=387 -ffast-math sineswap.c Otput assembly juste to see if there are no library calls and no data sections: sineswap.o: file format pe-i386
Disassembly of section .text:
00000000 <@formula@16>: 0: 55 push %ebp 1: 89 e5 mov %esp,%ebp 3: 8b 45 08 mov 0x8(%ebp),%eax 6: 83 e8 38 sub $0x38,%eax 9: 8b 50 18 mov 0x18(%eax),%edx c: 8b 48 1c mov 0x1c(%eax),%ecx f: dd 40 20 fldl 0x20(%eax) 12: d9 fe fsin 14: d9 ff fcos 16: dd 58 18 fstpl 0x18(%eax) 19: 89 50 20 mov %edx,0x20(%eax) 1c: 89 48 24 mov %ecx,0x24(%eax) 1f: c9 leave 20: c2 08 00 ret $0x8 23: 90 nop Then take only the machine code: objcopy -Obinary -j .text sineswap.o sineswap.bin Then convert the binary file to hexadecimal values in text file: bin2hex sineswap.bin sineswap.txt then add MB3D stuff and save as sineswap.m3f : [OPTIONS] .Version = 2 .DEoption = -1 [CODE] 5589E58B450883E8388B50188B481CDD4020D9FED9FFDD5818895020894824C9C2080090 [END]
Description:
Test of compiling a formula with GCC. Now the parameters: Mandelbulb3Dv18{ b.....Y/...g2...w....26...U2xSE.FEG1.TLyGzcFHn2Ezkskg1RPYyvTB4OmJcqszipiyP.9Q4zj ................................3CcamACAtz1.......EO./..................y.2...wD ...Uz.....UR..../wU0/......q/...W/....E3.....2LNaiUt1joD/w.........m/dkpXm1..... z.UaNadD12..0..........wz..................................u1....y1...sD...../.. .z1...kDmxchI3E6bxnNtGvRevNwy6EccKb8ZDlDyOAa4uMzGwvZyxtOCCPKzUDDlGyIvAqD7f84AINX xvfDDzwW9qnMz8kgNCnrmapD......Ia2...g7........sD.6....sD..E..................... .............oAnAt1...sD....z.Lv15.2iDQ.kuyk/.pv15.wjDQ.E0zk/.Hw15......Q....k1. ..................kz.wzzz1EM.c6.P....61...EK....Q/...c3...UD....5/...I1.....SF52 ...U.ydelyjeYFnzTeOgzf8No.6.2c..zzzz............4............0........k.8.kXWF1. .sM93P58iz9.MmnWK2zwz0........../EU0.wzzz1...........s/...................E.2c.. zzzz.............0...................2./8.kzzzD............8.................... /EU0.wzzz1....................................uBZ.U7EgU7tj/eVv1.oQm2oElCnueM.YXB bYX7Ot6Ul/.8Gsm0Drb3jC4.a.l0aUWTUSH7.M029MmWy/uBZ.U7EgU7hv5crI0.a.l0aIoTUSH7.M02 9Mmfz/uBZ.U7EgU7...crIGJzzFoTuIdyzngi8qdxzZX.4rU................................ E....6....E.....I.........kQdtKNnRLMk/.......................................... ...................6./.......................................................... ................................................................................ .....................2..........0....YYPoJqNZ756ExqRZ75......................... 8............................./E........kz9..................................... ................................................................................ ................................}
The picture [/code]
|
|
|
|
knighty
Fractal Iambus
Posts: 819
|
|
« Reply #17 on: April 07, 2015, 09:29:08 PM » |
|
Still, there's the problem you can't deal with constants and user input...
In the TIteration3Dext structure there is: void* PVar; //+48 the actual formulas adress of constants and vars, constants at offset 0 increasing, user vars below -8 That's something I'll try to see how to use it. Marius, any tip?
|
|
|
Logged
|
|
|
|
DarkBeam
Global Moderator
Fractal Senior
Posts: 2512
Fragments of the fractal -like the tip of it
|
|
« Reply #18 on: April 07, 2015, 09:54:19 PM » |
|
Uhm. As for the constants they sit in EDI, EDI+8h, EDI+(8h*N) and so on if they are doubles! User data. In case of doubles first one is EDI-10h, -18h, -20h etc, integers have a size of 4... so correct addresses accordingly angles are stored in matrix form, I always paste the whole Jesse code everytime but manually correcting offsets. Be careful with nonstandard data like boxscale, reciprocal... ESI contains Cx Cy and Cz, don't remember offsets but see any escapetime formula. Pay attention, some ABox formulas swap ESI / EDI... We are doing a mosaic of sorts!
|
|
« Last Edit: April 07, 2015, 10:00:23 PM by DarkBeam »
|
Logged
|
No sweat, guardian of wisdom!
|
|
|
knighty
Fractal Iambus
Posts: 819
|
|
« Reply #19 on: April 07, 2015, 10:46:50 PM » |
|
There are a lot of things that I don't understand. What are boxscale and reciprocal? What do .DEoption mean? How does MB3D know that a formula is a dIFS a 3D or 4D ...? It should be possible to make structs for constants and variables. Something like: struct constants{ double const1; double const2; ...etc. }; struct variables{ ...etc. //they should be inserted in reverse order? float var4;//[edi-20h] longint var3;//[edi-1ch] double var2;//[edi-18h] double var1;//[edi-10h] double dummy; //corrsponding to [edi-08h] because the "1st" accessible variable is at -0x10 } ... //In formula struct constants *pconst=(struct constants *) cfg->pVar; struct variables *pvar=(struct variables *)(((char *)pconst)-sizeof(struct variables));//not sure about the syntax or even if this is correct. ...
|
|
|
Logged
|
|
|
|
DarkBeam
Global Moderator
Fractal Senior
Posts: 2512
Fragments of the fractal -like the tip of it
|
|
« Reply #20 on: April 08, 2015, 12:07:45 AM » |
|
Dear friend I am in bad phisical conditions and I cannot be of big help just now. Boxscale is used in Amazing box in conjunction with minr, but don't remember well how. However there should be two doubles for a boxscale. Reciprocal is a type that loads in memory 1./the user input, there are also others like .singleangle and the aforementioned .3singleangle ones, also stuff for 4d but my memory doesn't help me now. Those types are less frequent but you may want to use them.
|
|
|
Logged
|
No sweat, guardian of wisdom!
|
|
|
DarkBeam
Global Moderator
Fractal Senior
Posts: 2512
Fragments of the fractal -like the tip of it
|
|
« Reply #21 on: April 08, 2015, 12:10:24 AM » |
|
The deoption tells mb3d if a formula is ads, escapetime, ifs etc menger3 has a different option than ruckerbulb
|
|
|
Logged
|
No sweat, guardian of wisdom!
|
|
|
thargor6
Fractal Molossus
Posts: 789
|
|
« Reply #22 on: April 08, 2015, 12:13:52 AM » |
|
int nHybrid[6]; //+76 all formulas iteration counts or single weights in interpol-hybrid void* fHPVar[6]; //+100 all formulas pointer to constants+vars, PVars-8=0.5, use PVar for the actual formula void* fHybrid[6]; //+124 the formulas adresses
Especially this has to change when we extend the number of possible formulas. Extending those arrays did not work for me, as it causes a lot of changes in ASM-code, some really tricky, because all offsets after this arrays will shift. My current idea is to create new offsets for those arrays, rather than extending them, so all offsets after those structures remain the same, but the three arrays will shift. Hopefully they are not used from within external formulas, but this currently is just a guess as I did not test a lot yet.
|
|
|
Logged
|
|
|
|
thargor6
Fractal Molossus
Posts: 789
|
|
« Reply #23 on: April 08, 2015, 12:27:46 AM » |
|
Maybe MB3D-v2 will feature a formula compiler. I also thought about something like your described, i. e. using some external compiler for this (in the first way). It is rather cheap, but of great use, I think. Even if it is not optimized for death, it could be really great fun to be able to just enter some C-style code (or whatever compiler to use).
|
|
|
Logged
|
|
|
|
knighty
Fractal Iambus
Posts: 819
|
|
« Reply #24 on: April 08, 2015, 10:03:36 PM » |
|
Thank you very much DarkBeam for the infos. I remember you already gave me the full explanation about the variables types. Thank you again and get well soon. @thargor6: I don't think those tables are used by any formula but the only way to be sure it to verify all of them. This could be done automatically I gess: disassemble them then look which parameters are used/modified. I also thought about something like your described, i. e. using some external compiler for this (in the first way). It is rather cheap, but of great use, I think. Even if it is not optimized for death, it could be really great fun to be able to just enter some C-style code (or whatever compiler to use).
Maybe it would be better to use dlls loaded at runtime (like gnofract4d) in order to avoid all the complications of integrating the machine code from the object file. For even better execution speed one can generate the source for the whole parameter (including all the used formulas) -> no overhead due to calls and more opportunities for the compiler to optimize. But the best of all (and the most difficult to do) is a specialized compiler with jit using LLVM. but LLVM is a monster. Both approaches would need to rewrite all the existing formulas for backward compatibility. Good news! the code I posted for accessing the constants and variables is correct! see attachement.
|
|
|
|
thargor6
Fractal Molossus
Posts: 789
|
|
« Reply #25 on: April 08, 2015, 10:32:15 PM » |
|
This could be done automatically I gess: disassemble them then look which parameters are used/modified. Right, good idea, I will have to do that! Maybe it would be better to use dlls loaded at runtime (like gnofract4d) in order to avoid all the complications of integrating the machine code from the object file.
Reminds me a little bit on the dll-hell from Apo :-), but is also a good idea, compared to the current approach. I think, we should just try out some things to actually decide, rewriting all the formulas is a nightmare ;-) Good news! the code I posted for accessing the constants and variables is correct!
Nice! Best regards, Andreas
|
|
|
Logged
|
|
|
|
DarkBeam
Global Moderator
Fractal Senior
Posts: 2512
Fragments of the fractal -like the tip of it
|
|
« Reply #26 on: April 08, 2015, 11:34:43 PM » |
|
Rewriting all the formulas?! Andreas you are trying to kill me by heart attack
|
|
|
Logged
|
No sweat, guardian of wisdom!
|
|
|
thargor6
Fractal Molossus
Posts: 789
|
|
« Reply #27 on: April 09, 2015, 12:38:32 AM » |
|
Rewriting all the formulas?! Andreas you are trying to kill me by heart attack At least you are awake now ;-)
|
|
|
Logged
|
|
|
|
DarkBeam
Global Moderator
Fractal Senior
Posts: 2512
Fragments of the fractal -like the tip of it
|
|
« Reply #28 on: April 10, 2015, 07:10:41 PM » |
|
Published a resource about how to program DIFS shapes, including some examples. I hope everyone finds it interesting. http://fav.me/d8p65ye
|
|
|
Logged
|
No sweat, guardian of wisdom!
|
|
|
knighty
Fractal Iambus
Posts: 819
|
|
« Reply #29 on: April 10, 2015, 08:32:16 PM » |
|
Thank you very much DarkBeam. Reminds me a little bit on the dll-hell from Apo :-)
Nooo! It's not a good idea to have a dll for each formula because most formulas are very small in size. What I was meaning is to take the whole fractal "parameter" that is the formulas sequence, generate the source from it then a dll by invoking the compiler/tools and finally loading and executing it. Maybe this would not be a good approache for small "parameters".
|
|
|
Logged
|
|
|
|
|