jdelauney / SIMD-VectorMath-UnitTest

For testing asm SIMD (SSE/SSE 2/SSE 3/SSE 4.x / AVX /AVX 2) vector math library (2f, 4f, matrix, quaternion...) with Lazarus and FreePascal Compiler
Mozilla Public License 2.0
8 stars 0 forks source link

Re Integer Combine2 and Combine3 #16

Closed dicepd closed 6 years ago

dicepd commented 6 years ago

Jerome,

I am proposing the following changes to the pascal Combine2 & 3 for integer vectors.

function TGLZVector4b.Combine2(constref V2: TGLZVector4b; const F1, F2: Single): TGLZVector4b;
//Var
//  va, vb : TGLZVector4b;
//  ws : Byte;
begin
  //ws:=Self.W;               // doing it this way is both inefficient and
  //va := Self * F1;          // inaccurate with 12 calls to clampbyte
  //vb := v2 * F2;            // reducing the precision. Also more conversions
  //result := va + vb;        // from int to float and float to int.
  result.X := ClampByte(Round(Self.X * F1 + V2.X * F2));
  result.Y := ClampByte(Round(Self.Y * F1 + V2.Y * F2));
  result.Z := ClampByte(Round(Self.Z * F1 + V2.Z * F2));
  result.W := Self.W;
end;              

Benefits:

Disadvantage

I am basing this on the presumption that this in its int form is used in areas like scaling and offsetting a scene object at a distance, Hit tests etc.

jdelauney commented 6 years ago

Yes calling "self" for doing calculs with decrease perf and reduce accuracy. You're right. I don't think about about those calls to clampbyte