flat assembler
Message board for the users of flat assembler.

 Index > Windows > Parse mathematically c++ example to asm sse code.
Author
Roman

Joined: 21 Apr 2012
Posts: 545
Roman
My idea write parser c++ math formuls.
This gives easy copy c++ code and read code.

For example(very simple example).
Code:
float A = 2.1;
float B = 3;
vec3 C = A*B;


Parser understood float\int\vec2\vec3\vec4 and matrix3(3x3) and matrix4(4x4)
Parser get asm sse text code in output file(and we easy include this file in fasm source):
Code:
movss xmm0,[pA]
mulss xmm0,[pB]
pinsrd xmm1, xmm0, 0
pinsrd xmm1, xmm0, 1
pinsrd xmm1, xmm0, 2
;now in xmm1 we have vec3


In future very useful\handful for this:
Code:
  Vec3 v0v1 = (v1- v0);
Vec3 v0v2 = (v2- v0);

Vec3 pvec = cross (r->dir, v0v2);

float det = dot (v0v1, pvec);
if (det < 0.000001) return -INFINITY;

float invDet = 1.0 / det;

Vec3 tvec = sub (r->orig, v0);

float u = dot (tvec, pvec) * invDet;

if (u < -0.0001 || u > 1.0001) return -INFINITY;

Vec3 qvec = cross (tvec, v0v1);

float v = dot (r->dir, qvec) * invDet;

if (v < -0.0001 || u + v > 1.0001) return -INFINITY;

return dot (v0v2, qvec) * invDet;

19 Jan 2019, 11:40
DimonSoft

Joined: 03 Mar 2010
Posts: 632
Location: Belarus
DimonSoft
Shaders have this stuff and are often written in something similar to C/C++ syntax. D3DX library already has certain formula like these implemented as well. Note also that SSE is not very useful for calculations applied to a few values, it is supposed to be used for large arrays of data (for certain definitions of “large”) to be useful.
19 Jan 2019, 14:05
Roman

Joined: 21 Apr 2012
Posts: 545
Roman
But sometimes need do function on CPU.
20 Jan 2019, 09:11
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

 Jump to: Select a forum Official----------------AssemblyPeripheria General----------------MainDOSWindowsLinuxUnixMenuetOS Specific----------------MacroinstructionsCompiler InternalsIDE DevelopmentOS ConstructionNon-x86 architecturesHigh Level LanguagesProgramming Language DesignProjects and IdeasExamples and Tutorials Other----------------FeedbackHeapTest Area

Forum Rules:
 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot vote in polls in this forumYou cannot attach files in this forumYou can download files in this forum