flat assembler
Message board for the users of flat assembler.

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

Author
Thread Post new topic Reply to topic
Roman



Joined: 21 Apr 2012
Posts: 1847
Roman 19 Jan 2019, 11:40
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;
    
Post 19 Jan 2019, 11:40
View user's profile Send private message Reply with quote
DimonSoft



Joined: 03 Mar 2010
Posts: 1228
Location: Belarus
DimonSoft 19 Jan 2019, 14:05
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.
Post 19 Jan 2019, 14:05
View user's profile Send private message Visit poster's website Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1847
Roman 20 Jan 2019, 09:11
Shaders cool.
But sometimes need do function on CPU.
Post 20 Jan 2019, 09:11
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.