Logo by Sockratease - 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. February 21, 2019, 01:53:33 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: Writing formula using gcc (Re: Blobby)  (Read 5057 times)
Description: Learining how to use gcc for writing MB3D formulas
0 Members and 1 Guest are viewing this topic.
DarkBeam
Global Moderator
Fractal Senior
******
Posts: 2512


Fragments of the fractal -like the tip of it


« Reply #30 on: August 21, 2016, 07:17:54 PM »

Next build?! Yayyy cheesy
Logged

No sweat, guardian of wisdom!
M Benesi
Fractal Schemer
****
Posts: 1075



WWW
« Reply #31 on: August 30, 2016, 07:21:43 AM »

I think it would be easy to just dump it, but I'm not sure that the result has the quality you really want to optimize.
But, I can include such an option in the next build, and you may have a look by yourself :-)

  Thanks!

  I've looked at some other code made by gcc (to write a formula) and... yeah.. it might not be easy to optimize.  cheesy 

   
Logged

DarkBeam
Global Moderator
Fractal Senior
******
Posts: 2512


Fragments of the fractal -like the tip of it


« Reply #32 on: December 09, 2016, 12:49:57 PM »

grin

I am trying a superlame no-overhead DIFS implement. Uses macro-like statements with hardcoded horrible stuff, and it surprisingly works:

Code:
#include <math.h>
        
/*
struct TIteration3Dext {
double something; // -0x88 ; used in sphereheightmap.m3f
double dum0; // -0x80 ; unknown
double x; // -0x78
double y; // -0x70
double z; // -0x68
double dum1[8]; //unknown
double DE2T; // -0x20 ; Output: distance estimate to current object
double dum2[17]; //unknown
double accumulatedScale; // +0x70
double dum3; // +0x78; unknown
double OTforCol; // +0x80
double dum4[16]; //unknown
//void * sphericalMap; // +0x108; pointer to function
} MB3D_PACK;
*/

__CRT_INLINE double __cdecl Hypot(double x,double y) ;
__CRT_INLINE double __cdecl length2(double x,double y,double z);
__CRT_INLINE double __cdecl length(double x,double y,double z);
__CRT_INLINE double __cdecl recip (double _x);
__CRT_INLINE double __cdecl max (double _a, double _b);
__CRT_INLINE double __cdecl min (double _a, double _b);

__CRT_INLINE double __cdecl loadzero (void) // uses constants, assembly required :o)
{
  double res;
  __asm__ ("fldz": "=t" (res));
  return res;
}

__CRT_INLINE double __cdecl load1 (void) // uses constants, assembly required :o)
{
  double res;
  __asm__ ("fld1": "=t" (res));
  return res;
}

__CRT_INLINE double __cdecl loadX (void)
{
  double res;
  __asm__ ("fldl -104(%%esi)" // esi-0x068
        : "=t" (res)
:   // nothing in (well except the memory located into esi+stuff but we won't say that - it's okayish)
        :"%esi"    // using esi (clobbered));
        );
  return res;
}

__CRT_INLINE double __cdecl loadY (void)
{
  double res;
  __asm__ ("fldl -112(%%esi)" // esi-0x070
        : "=t" (res)
:   // nothing in (well except the memory located into esi+stuff but we won't say that - it's okayish)
        :"%esi"    // using esi (clobbered));
        );
  return res;
}

__CRT_INLINE double __cdecl loadZ (void)
{
  double res;
  __asm__ ("fldl -120(%%esi)" // esi-0x078
        : "=t" (res)
:   // nothing in (well except the memory located into esi+stuff but we won't say that - it's okayish)
        :"%esi"    // using esi (clobbered));
        );
  return res;
}

// WARNING don't do this normally except if you really have changed actual coords,
// AND you scaled them by a value... works even in nonlinear changes like Tglad's sphere inv
// If you changed coords, scaling them you must also change this (at the end of your fmla)
__CRT_INLINE void __cdecl multScaleFactorBy (double _ScaleF)
{
  __asm__ ("fldl %0
"
   "fmull +112(%%esi)" // esi+0x070
   "fstpl +112(%%esi)" // esi+0x070
        : // no out (well except the memory located into esi+stuff but we won't say that - it's okayish)
        :"m"(_ScaleF)   // in
        :"%esi"    // using esi (clobbered));
        );
  return;
}

// WARNING don't do this normally except if you really want to change actual coords
__CRT_INLINE void __cdecl saveInX (double _x)
{
  __asm__ ("fldl %0
"
   "fstpl -104(%%esi)" // esi-0x068
        : // no out (well except the memory located into esi+stuff but we won't say that - it's okayish)
        :"m"(_x)   // in
        :"%esi"    // using esi (clobbered));
        );
  return;
}

// WARNING don't do this normally except if you really want to change actual coords
__CRT_INLINE void __cdecl saveInY (double _y)
{
  __asm__ ("fldl %0
"
   "fstpl -112(%%esi)" // esi-0x070
        : // no out (well except the memory located into esi+stuff but we won't say that - it's okayish)
        :"m"(_y)   // in
        :"%esi"    // using esi (clobbered));
        );
  return;
}

// WARNING don't do this normally except if you really want to change actual coords
__CRT_INLINE void __cdecl saveInZ (double _z)
{
  __asm__ ("fldl %0
"
   "fstpl -120(%%esi)" // esi-0x078
        : // no out (well except the memory located into esi+stuff but we won't say that - it's okayish)
        :"m"(_z)   // in
        :"%esi"    // using esi (clobbered));
        );
  return;
}

__CRT_INLINE void __cdecl saveDE (double _DE)
{
  __asm__ ("fldl %0
"
   "fstpl -32(%%esi)
" // esi-0x020
        : // no out (well except the memory located into esi+stuff but we won't say that - it's okayish)
        :"m"(_DE)   // in
        :"%esi"    // using esi (clobbered));
        );
  return;
}

__CRT_INLINE double __cdecl Hypot(double x,double y) { return sqrt(x*x+y*y); }

__CRT_INLINE double __cdecl length2(double x,double y,double z) { return (x*x+y*y+z*z); }

__CRT_INLINE double __cdecl length(double x,double y,double z) { return sqrt(length2(x,y,z)); }

__CRT_INLINE double __cdecl recip (double _x) // uses constants, assembly required :o)
{
  double res;
  __asm__ ("fld1
"
   "fdivp": "=t" (res) : "0" (_x));
  return res;
}

__CRT_INLINE double __cdecl max (double _a, double _b)
{
  return (_a>_b)?_a:_b;
}

__CRT_INLINE double __cdecl max3 (double _a, double _b, double _c)
{
  return max(max(_a,_b),_c);
}

__CRT_INLINE double __cdecl min (double _a, double _b)
{
  return (_a<_b)?_a:_b;
}

__CRT_INLINE double __cdecl min3 (double _a, double _b, double _c)
{
  return min(min(_a,_b),_c);
}

// ULTRASLIM since Jessie said Mb3D prepares everything for us already
// We just use those lame macros it should be fine I hope? duh
void __attribute__((fastcall)) Formula(void) {
  // lamest cube on earth
  double x=fabs(loadX()), y=fabs(loadY()), z=fabs(loadZ());
  saveDE (max3(x,y,z)-load1());
}

Resulting m3f:
Code:
[OPTIONS]
.Version = 6
.DEoption = 20
[CONSTANTS]
Double = 1
[CO DE] space to fool forum tags
56DD4698D9E1DD4690D9E1DD4688D9E1D9CA83EC10DDE1DFE0F6C4457404DDD8
EB02DDD9DDE1DFE0F6C4457404DDD8EB02DDD9D9E8DEE9DD5C2408DD442408DD
5EE083C4105EC3
[END]

Just a lame test

Except idk how to access at user vars, and consts - now I will try to! Heheh
Logged

No sweat, guardian of wisdom!
knighty
Fractal Iambus
***
Posts: 819


« Reply #33 on: December 09, 2016, 04:12:02 PM »

 Repeating Zooming Self-Silimilar Thumb Up, by Craig
Logged
DarkBeam
Global Moderator
Fractal Senior
******
Posts: 2512


Fragments of the fractal -like the tip of it


« Reply #34 on: December 10, 2016, 12:10:05 PM »

 grin Thanks again, but now I confirmed my age old suspect, vars are in reverse order so I modified macros accordingly snore. Plus lame macros for user vars, that must be manually tweaked if you use mixed types, like one int for applyscale+add and all other doubles grin ... noes! Using offsets (I always waste at least 2 hours everytime)


Code:
#include <math.h>
       
/*
struct TIteration3Dext {
double something; // -0x88 ; used in sphereheightmap.m3f
double dum0; // -0x80 ; unknown
double x; // -0x78
double y; // -0x70
double z; // -0x68
double dum1[8]; //unknown
double DE2T; // -0x20 ; Output: distance estimate to current object
double dum2[17]; //unknown
double accumulatedScale; // +0x70
double dum3; // +0x78; unknown
double OTforCol; // +0x80
double dum4[16]; //unknown
//void * sphericalMap; // +0x108; pointer to function
} MB3D_PACK;
*/

const int szof1int = 4; // helps to find out offsets
const int szof1dbl = 8; // helps to find out offsets

__CRT_INLINE double __cdecl Hypot(double x,double y) ;
__CRT_INLINE double __cdecl length2(double x,double y,double z);
__CRT_INLINE double __cdecl length(double x,double y,double z);
__CRT_INLINE double __cdecl recip (double _x);
__CRT_INLINE double __cdecl max (double _a, double _b);
__CRT_INLINE double __cdecl min (double _a, double _b);

__CRT_INLINE double __cdecl loadzero (void) // uses constants, assembly required :o)
{
  double res;
  __asm__ ("fldz": "=t" (res));
  return res;
}

__CRT_INLINE double __cdecl load1 (void) // uses constants, assembly required :o)
{
  double res;
  __asm__ ("fld1": "=t" (res));
  return res;
}

__CRT_INLINE double __cdecl loadZ (void)
{
  double res;
  __asm__ ("fldl -104(%%esi)" // esi-0x068
        : "=t" (res)
:   // nothing in (well except the memory located into esi+stuff but we won't say that - it's okayish)
        :"%esi"    // using esi (clobbered));
        );
  return res;
}

__CRT_INLINE double __cdecl loadY (void)
{
  double res;
  __asm__ ("fldl -112(%%esi)" // esi-0x070
        : "=t" (res)
:   // nothing in (well except the memory located into esi+stuff but we won't say that - it's okayish)
        :"%esi"    // using esi (clobbered));
        );
  return res;
}

__CRT_INLINE double __cdecl loadX (void)
{
  double res;
  __asm__ ("fldl -120(%%esi)" // esi-0x078
        : "=t" (res)
:   // nothing in (well except the memory located into esi+stuff but we won't say that - it's okayish)
        :"%esi"    // using esi (clobbered));
        );
  return res;
}

__CRT_INLINE double __cdecl loadNthDoubleVar (int _nVar, int OFFSET) // 0 for the 1st ... use only double vars
// ELSE use offset, idk how I go by attempts normally ;(
{
  register int N = -(_nVar*szof1dbl)- 0x010-OFFSET; // EAX
  double res;
  __asm__ ("fldl (%%edi,%1)" // nothing else seems to work
        : "=t" (res)
        :"r"(N)   // in
        :"%edi"    // using edi (clobbered));
        );
  return res;
}

__CRT_INLINE int __cdecl loadNthIntVar (int _nVar, int OFFSET) // 0 for the 1st ... use only int vars
// ELSE use offset, idk how I go by attempts normally ;(
// untested! untested! untested!
{
  int N = -(_nVar*szof1int)- 0x0C-OFFSET;
  int res;
  __asm__ ( "add %%edi,%1
" // omg?!?? nothing else seems to work
  "movl %1,%%eax
" // omg?!?? nothing else seems to work
        "movl %%eax,%0
"// omg?!?? nothing else seems to work
        : "=m" (res)
        :"m"(N)   // in
        :"%edi","%eax"    // using edi and eax (clobbered));
        );
  return res;
}

__CRT_INLINE double __cdecl loadNthDoubleCns (int _nVar, int OFFSET) // 0 for the 1st ... use only double vars
// ELSE use offset, idk how I go by attempts normally ;(
// untested! untested! untested!
{
  register int N = +(_nVar*szof1dbl)+ 0x000+OFFSET; // EAX
  double res;
  __asm__ ("fldl (%%edi,%1)" // nothing else seems to work
        : "=t" (res)
        :"r"(N)   // in
        :"%edi"    // using edi (clobbered));
        );
  return res;
}

__CRT_INLINE double __cdecl loadNthIntCns (int _nVar, int OFFSET) // 0 for the 1st ... use only double vars
// ELSE use offset, idk how I go by attempts normally ;(
// untested! untested! untested!
{
  register int N = +(_nVar*szof1int)+ 0x000+OFFSET; // EAX
  double res;
  __asm__ ( "add %%edi,%1
" // omg?!?? nothing else seems to work
  "movl %1,%%eax
" // omg?!?? nothing else seems to work
        "movl %%eax,%0
"// omg?!?? nothing else seems to work
        : "=m" (res)
        :"m"(N)   // in
        :"%edi","%eax"    // using edi and eax (clobbered));
        );
  return res;
}


// WARNING don't do this normally except if you really have changed actual coords,
// AND you scaled them by a value... works even in nonlinear changes like Tglad's sphere inv
// If you changed coords, scaling them you must also change this (at the end of your fmla)
__CRT_INLINE void __cdecl multScaleFactorBy (double _ScaleF)
{
  __asm__ ("fldl %0
"
  "fmull +112(%%esi)" // esi+0x070
  "fstpl +112(%%esi)" // esi+0x070
        : // no out (well except the memory located into esi+stuff but we won't say that - it's okayish)
        :"m"(_ScaleF)   // in
        :"%esi"    // using esi (clobbered));
        );
  return;
}

// WARNING don't do this normally except if you really want to change actual coords
__CRT_INLINE void __cdecl saveInZ (double _z)
{
  __asm__ ("fldl %0
"
  "fstpl -104(%%esi)" // esi-0x068
        : // no out (well except the memory located into esi+stuff but we won't say that - it's okayish)
        :"m"(_z)   // in
        :"%esi"    // using esi (clobbered));
        );
  return;
}

// WARNING don't do this normally except if you really want to change actual coords
__CRT_INLINE void __cdecl saveInY (double _y)
{
  __asm__ ("fldl %0
"
  "fstpl -112(%%esi)" // esi-0x070
        : // no out (well except the memory located into esi+stuff but we won't say that - it's okayish)
        :"m"(_y)   // in
        :"%esi"    // using esi (clobbered));
        );
  return;
}

// WARNING don't do this normally except if you really want to change actual coords
__CRT_INLINE void __cdecl saveInX (double _x)
{
  __asm__ ("fldl %0
"
  "fstpl -120(%%esi)" // esi-0x078
        : // no out (well except the memory located into esi+stuff but we won't say that - it's okayish)
        :"m"(_x)   // in
        :"%esi"    // using esi (clobbered));
        );
  return;
}

__CRT_INLINE void __cdecl saveDE (double _DE)
{
  __asm__ ("fldl %0
"
  "fstpl -32(%%esi)
" // esi-0x020
        : // no out (well except the memory located into esi+stuff but we won't say that - it's okayish)
        :"m"(_DE)   // in
        :"%esi"    // using esi (clobbered));
        );
  return;
}

__CRT_INLINE double __cdecl Hypot(double x,double y) { return sqrt(x*x+y*y); }

__CRT_INLINE double __cdecl length2(double x,double y,double z) { return (x*x+y*y+z*z); }

__CRT_INLINE double __cdecl length(double x,double y,double z) { return sqrt(length2(x,y,z)); }

__CRT_INLINE double __cdecl recip (double _x) // uses constants, assembly required :o)
{
  double res;
  __asm__ ("fld1
"
    "fdivp": "=t" (res) : "0" (_x));
  return res;
}

__CRT_INLINE double __cdecl max (double _a, double _b)
{
  return (_a>_b)?_a:_b;
}

__CRT_INLINE double __cdecl max3 (double _a, double _b, double _c)
{
  return max(max(_a,_b),_c);
}

__CRT_INLINE double __cdecl min (double _a, double _b)
{
  return (_a<_b)?_a:_b;
}

__CRT_INLINE double __cdecl min3 (double _a, double _b, double _c)
{
  return min(min(_a,_b),_c);
}

// ULTRASLIM since Jessie said Mb3D prepares everything for us already
// We just use those lame macros it should be fine I hope? duh
void __attribute__((fastcall)) Formula(void) {
  // should we tell the compiler to NOT touch edi nor esi?! I strongly think so...
  double x=fabs(loadX()), y=fabs(loadY()), z=fabs(loadZ());
  double V0=loadNthDoubleVar(0,0),V1=loadNthDoubleVar(1,0),V2=loadNthDoubleVar(2,0);
  saveDE (max3(x-V0,y-V1,z-V2+h));
}

Resulting M3F: afro

Code:
[OPTIONS]
.Version = 6
.DEoption = 20
.Double Size X = 1.
.Double Size Y = 1.
.Double Size Z = 1.
[CONSTANTS]
Double = 1
[CO DE] DELETE the space!
B8F0FFFFFF5756DD4688DD4690DD4698DD0407B0E883EC14DD0407B0E0DD0407
D9CBD9E1DEE3D9CBD9E1DEE3D9CBD9E1DEE3D9CADDE1DFE0F6C4457404DDD8EB
02DDD9DDE1DFE0F6C4457404DDD8EB02DDD9DD5C2408DD442408DD5EE083C414
5E5FC3
[END]

Just a lame test, but prettier :P
Logged

No sweat, guardian of wisdom!
M Benesi
Fractal Schemer
****
Posts: 1075



WWW
« Reply #35 on: December 10, 2016, 10:41:49 PM »

awesome!@#!@#   cheesy
Logged

DarkBeam
Global Moderator
Fractal Senior
******
Posts: 2512


Fragments of the fractal -like the tip of it


« Reply #36 on: December 10, 2016, 11:22:22 PM »

Ehehe thanks Matthew I am a bit scared of this code but I will soon test it for some crazyyy stuff like weird terrains or whatever wink plenty of those into Shadertoy. Or some cool 3d models. I am unable to code them in asm cheesy
You are invited to try too smiley
Logged

No sweat, guardian of wisdom!
Pages: 1 2 [3]   Go Down
  Print  
 
Jump to:  

Related Topics
Subject Started by Replies Views Last post
Inner Writing I FractalForums.com Banner Logos Pauldelbrot 0 723 Last post January 02, 2012, 04:57:34 AM
by Pauldelbrot
Inner Writing II FractalForums.com Banner Logos Pauldelbrot 0 723 Last post January 02, 2012, 04:59:09 AM
by Pauldelbrot
Inner Writing III FractalForums.com Banner Logos Pauldelbrot 1 887 Last post January 02, 2012, 02:21:09 PM
by cKleinhuis
Blobby (How to write simple m3f) Tutorials « 1 2 3 » visual.bermarte 39 3878 Last post April 20, 2015, 09:18:23 PM
by knighty
writing a mb3d formula (*directly* in Assembly) Tutorials « 1 2 » M Benesi 15 1804 Last post October 21, 2015, 11:34:49 PM
by M Benesi

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.098 seconds with 29 queries. (Pretty URLs adds 0.007s, 2q)