visual.bermarte
|
|
« on: April 02, 2015, 02:53:25 PM » |
|
This is my test using mandelbulb3d, I was curious about the method used to create formulas in assembly What was interesting to me was the method and not the formula itself (it's rather meaningless). I took a formula and I have used http://www2.onlinedisassembler.com/odaweb/ to disassemble the hex code. Then I have modified the most basic _FlipXY.m3f formula like that (it's just a test, just trying out things): push ebp mov ebp,esp fld QWORD PTR [ecx] fld QWORD PTR [eax] fsin fcos fstp QWORD PTR [ecx] fstp QWORD PTR [eax] pop ebp ret 0x8 Latest step was using https://defuse.ca/online-x86-assembler.htm#disassembly to assemble back in Hex code (for x86) the assembly code, to obtain 5589E5DD01DD00D9FED9FFDD19DD185DC20800 For my image first I have used the modifier I did and then I have added a formula called 'Integer Power' (here is 4).
|
|
« Last Edit: April 07, 2015, 10:24:34 AM by visual.bermarte »
|
Logged
|
|
|
|
visual.bermarte
|
|
« Reply #1 on: April 02, 2015, 05:48:16 PM » |
|
I have to write again that just throwing two functions one after the other (sinus and cosinus) like I did in the example, does not make sense at all.
|
|
« Last Edit: April 02, 2015, 05:51:31 PM by visual.bermarte »
|
Logged
|
|
|
|
knighty
Fractal Iambus
Posts: 819
|
|
« Reply #2 on: April 02, 2015, 06:59:10 PM » |
|
Also, thank you for the links. They use GCC for the assembler. Maybe it is possible to automate the process. C/C++ to assembly code to MB3D formula? Anyone?
|
|
|
Logged
|
|
|
|
DarkBeam
Global Moderator
Fractal Senior
Posts: 2512
Fragments of the fractal -like the tip of it
|
|
« Reply #3 on: April 02, 2015, 07:04:04 PM » |
|
Never worked here!
|
|
|
Logged
|
No sweat, guardian of wisdom!
|
|
|
3dickulus
|
|
« Reply #4 on: April 04, 2015, 10:31:12 PM » |
|
https://gcc.gnu.org/onlinedocs/gcc option -mfpmath=sse For the i386 compiler, you need to use -march=cpu-type, -msse or -msse2 switches to enable SSE extensions and make this option effective.
|
|
|
Logged
|
|
|
|
DarkBeam
Global Moderator
Fractal Senior
Posts: 2512
Fragments of the fractal -like the tip of it
|
|
« Reply #5 on: April 04, 2015, 10:38:10 PM » |
|
Knighty do you know an instant method to get just the mb3d code, without spaces, without copypaste it everytime?
|
|
|
Logged
|
No sweat, guardian of wisdom!
|
|
|
3dickulus
|
|
« Reply #6 on: April 04, 2015, 11:00:47 PM » |
|
> /usr/bin/hexdump obj.o | sed -ne '/^0000...\ /s/^0000...\ //g;p' | sed -ne '/\ /s/\ //g;p' will output only hex values. (tail end of a random file) looks like... 414178452070203d0a31614773756973 6e6141413d20742075720a656523646e 727073657465000a
edit:can add to a make file/script like... ...make cmds... cat obj.o | hexdump | sed -ne '/^0000...\ /s/^0000...\ //g;p' | sed -ne '/\ /s/\ //g;p' > hexfile.txt ...creates file named hexfile.txt
|
|
« Last Edit: April 04, 2015, 11:26:10 PM by 3dickulus, Reason: mk cmd »
|
Logged
|
|
|
|
marius
Fractal Lover
Posts: 206
|
|
« Reply #7 on: April 05, 2015, 01:36:47 AM » |
|
It wokrs here! I used this example posted here a looong time ago by jesse: __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 r = cfg->x + cfg->y - cfg->z * cfg->w; cfg->Deriv1 = r; }
compile with 'gcc -c -Os -m32'.
Objdump -D can be used to show the generated code. Heh, that code looks familiar Wow, been over 3.5 years already.. I hope you're not the first to actually try it Too bad m3d is not 64 bit, eh?
|
|
|
Logged
|
|
|
|
knighty
Fractal Iambus
Posts: 819
|
|
« Reply #8 on: April 05, 2015, 03:58:32 PM » |
|
@Marius: It was this post. It must be your code. @3Dickulus: Thank you. I'll try them ASAP. @Darkbeam: I think 3Dickulus partially answers your question. The idea is to write a script (sh, bat or so) that given the source will: - call the compiler to generate the object file. - extract the machine code from the object file. Also verify that no external function is used. objdump have a lot of options to explore. - construct the m3f file using the extracted machine code and some informations from the source (for example: user defined variables and constants). This requires using existing (if any, otherwise write them) programs to parse the source and object files and extract the informations. The best IMHO is to have a system where the formula is written this way: [OPTIONS] .Version = 2 .DEoption = -1 [constants and variables] [SOURCE] cfg->x=fabs(cfg->x); cfg->y=fabs(cfg->y); cfg->z=fabs(cfg->z); [END]
Description:
Test of compiling a formula with GCC. It simply set (x,y,z)=abs(x,y,z) and then generates the c file automagicaly. : That needs some work but it is not impossible.
|
|
|
Logged
|
|
|
|
3dickulus
|
|
« Reply #9 on: April 05, 2015, 06:39:23 PM » |
|
compile with GCC debug options turned on so objdump can insert the C source as comments in the assembly language output you may find that the GCC optimizations are hard to improve
|
|
« Last Edit: April 05, 2015, 06:48:03 PM by 3dickulus, Reason: typo »
|
Logged
|
|
|
|
knighty
Fractal Iambus
Posts: 819
|
|
« Reply #10 on: April 05, 2015, 09:35:29 PM » |
|
Yes! it is very good at optimizing. I've tried to use sse but for fabs, it needs a constant (0x7fffffffffffffff) that is stored in .rdata section . Hopefully it didn't freez the computer. So it is better not to use sse (or perhaps as intrinsic/inlined asm?) Knighty do you know an instant method to get just the mb3d code, without spaces, without copypaste it everytime? using: objcopy -Obinary -j .text MB3D-formula-ex.o out.bin extracts the binary machine code then: converts it to hexadecimal. bin2hex can be found here. I forgot to say that I use mingw and msys.
|
|
|
Logged
|
|
|
|
DarkBeam
Global Moderator
Fractal Senior
Posts: 2512
Fragments of the fractal -like the tip of it
|
|
« Reply #11 on: April 05, 2015, 10:00:48 PM » |
|
Ouch, that was the reason why I avoided the c compiler! Those issues are irritating to me. There are even worse ones sometimes
|
|
|
Logged
|
No sweat, guardian of wisdom!
|
|
|
knighty
Fractal Iambus
Posts: 819
|
|
« Reply #12 on: April 05, 2015, 10:09:33 PM » |
|
Maybe MB3D-v2 will feature a formula compiler.
|
|
|
Logged
|
|
|
|
DarkBeam
Global Moderator
Fractal Senior
Posts: 2512
Fragments of the fractal -like the tip of it
|
|
« Reply #13 on: April 05, 2015, 10:45:14 PM » |
|
Yes! Andreas will try to do that so that pain will end? Some of my formulas need serious work. Also I would like to see a serious ifs general work like the one you did, together with many otger things I am unable to do. I still wonder how a data section can be replicated in a plain assembly code...
|
|
|
Logged
|
No sweat, guardian of wisdom!
|
|
|
visual.bermarte
|
|
« Reply #14 on: April 07, 2015, 10:33:33 AM » |
|
How can one write a trigonometric function using this c example? for example sin(x).
|
|
|
Logged
|
|
|
|
|