Logo by S Nelson - Contribute your own Logo!

END OF AN ERA, FRACTALFORUMS.COM IS CONTINUED ON FRACTALFORUMS.ORG

it was a great time but no longer maintainable by c.Kleinhuis contact him for any data retrieval,
thanks and see you perhaps in 10 years again

this forum will stay online for reference
News: Follow us on Twitter
 
*
Welcome, Guest. Please login or register. March 29, 2024, 01:23:48 PM


Login with username, password and session length


The All New FractalForums is now in Public Beta Testing! Visit FractalForums.org and check it out!


Pages: [1] 2 3   Go Down
  Print  
Share this topic on DiggShare this topic on FacebookShare this topic on GoogleShare this topic on RedditShare this topic on StumbleUponShare this topic on Twitter
Author Topic: Blobby (How to write simple m3f)  (Read 10115 times)
0 Members and 1 Guest are viewing this topic.
visual.bermarte
Fractal Fertilizer
*****
Posts: 355



« 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 grin
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
Fractal Fertilizer
*****
Posts: 355



« 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.  tease
« 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 »

 Repeating Zooming Self-Silimilar Thumb Up, by Craig
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! wink wink
Logged

No sweat, guardian of wisdom!
3dickulus
Global Moderator
Fractal Senior
******
Posts: 1558



WWW
« Reply #4 on: April 04, 2015, 10:31:12 PM »

https://gcc.gnu.org/onlinedocs/
gcc option -mfpmath=sse
Quote
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

Resistance is fertile...
You will be illuminated!

                            #B^] https://en.wikibooks.org/wiki/Fractals/fragmentarium
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? smiley
Logged

No sweat, guardian of wisdom!
3dickulus
Global Moderator
Fractal Senior
******
Posts: 1558



WWW
« Reply #6 on: April 04, 2015, 11:00:47 PM »

Code:
> /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...
Code:
414178452070203d0a31614773756973
6e6141413d20742075720a656523646e
727073657465000a

edit:can add to a make file/script like...
Code:
...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

Resistance is fertile...
You will be illuminated!

                            #B^] https://en.wikibooks.org/wiki/Fractals/fragmentarium
marius
Fractal Lover
**
Posts: 206


« Reply #7 on: April 05, 2015, 01:36:47 AM »

It wokrs here!  horsie riding
I used this example posted here a looong time ago by jesse:
Code:
__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 grin Wow, been over 3.5 years already.. I hope you're not the first to actually try it  huh?
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. grin

@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:
Code:
[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.  :smiley
That needs some work but it is not impossible.
Logged
3dickulus
Global Moderator
Fractal Senior
******
Posts: 1558



WWW
« 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 smiley
you may find that the GCC optimizations are hard to improve wink
« Last Edit: April 05, 2015, 06:48:03 PM by 3dickulus, Reason: typo » Logged

Resistance is fertile...
You will be illuminated!

                            #B^] https://en.wikibooks.org/wiki/Fractals/fragmentarium
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 hurt. 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? smiley
using:
Code:
objcopy -Obinary -j .text MB3D-formula-ex.o out.bin
extracts the binary machine code then:
Code:
bin2hex out.bin out.txt
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.  evil
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 smiley so that pain will end? cheesy
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
Fractal Fertilizer
*****
Posts: 355



« Reply #14 on: April 07, 2015, 10:33:33 AM »

 smiley How can one write a trigonometric function using this c example? for example sin(x).
Logged
Pages: [1] 2 3   Go Down
  Print  
 
Jump to:  

Related Topics
Subject Started by Replies Views Last post
How to write a formula in ChaosPro General Discussion Krumel 1 3214 Last post September 08, 2010, 09:29:06 PM
by quaternion
Write your own formulas? Mandelbulb 3d s31415 5 6009 Last post June 06, 2012, 08:58:11 PM
by stringbean5
How to write a book about the Mandelbrot set Mandelbrot & Julia Set claude 6 2983 Last post April 25, 2014, 05:21:52 PM
by claude
Writing formula using gcc (Re: Blobby) Tutorials « 1 2 3 » knighty 36 14545 Last post December 10, 2016, 11:22:22 PM
by DarkBeam
fastest way to write to the screen with a GPU Programming 0xbeefc0ffee 9 5131 Last post August 07, 2017, 06:41:10 PM
by 3dickulus

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines

Valid XHTML 1.0! Valid CSS! Dilber MC Theme by HarzeM
Page created in 0.21 seconds with 29 queries. (Pretty URLs adds 0.011s, 2q)