Skip to content

Commit

Permalink
Fix order of operations for float1 / floatN and float1 - floatN opera…
Browse files Browse the repository at this point in the history
…tors

Also changed for addition and multiplication although for consistency even if it doesn't change the result
Add unit tests for these two cases
  • Loading branch information
redorav committed Aug 21, 2022
1 parent 6f72235 commit bf7df71
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
24 changes: 12 additions & 12 deletions include/hlsl++_vector_float.h
Original file line number Diff line number Diff line change
Expand Up @@ -996,9 +996,9 @@ namespace hlslpp
hlslpp_inline float3 operator + (const float3& f1, const float1& f2) { return float3(_hlslpp_add_ps(f1.vec, _hlslpp_perm_xxxx_ps(f2.vec))); }
hlslpp_inline float4 operator + (const float4& f1, const float1& f2) { return float4(_hlslpp_add_ps(f1.vec, _hlslpp_perm_xxxx_ps(f2.vec))); }

hlslpp_inline float2 operator + (const float1& f1, const float2& f2) { return float2(_hlslpp_add_ps(f2.vec, _hlslpp_perm_xxxx_ps(f1.vec))); }
hlslpp_inline float3 operator + (const float1& f1, const float3& f2) { return float3(_hlslpp_add_ps(f2.vec, _hlslpp_perm_xxxx_ps(f1.vec))); }
hlslpp_inline float4 operator + (const float1& f1, const float4& f2) { return float4(_hlslpp_add_ps(f2.vec, _hlslpp_perm_xxxx_ps(f1.vec))); }
hlslpp_inline float2 operator + (const float1& f1, const float2& f2) { return float2(_hlslpp_add_ps(_hlslpp_perm_xxxx_ps(f1.vec), f2.vec)); }
hlslpp_inline float3 operator + (const float1& f1, const float3& f2) { return float3(_hlslpp_add_ps(_hlslpp_perm_xxxx_ps(f1.vec), f2.vec)); }
hlslpp_inline float4 operator + (const float1& f1, const float4& f2) { return float4(_hlslpp_add_ps(_hlslpp_perm_xxxx_ps(f1.vec), f2.vec)); }

hlslpp_inline float1 operator - (const float1& f1, const float1& f2) { return float1(_hlslpp_sub_ps(f1.vec, f2.vec)); }
hlslpp_inline float2 operator - (const float2& f1, const float2& f2) { return float2(_hlslpp_sub_ps(f1.vec, f2.vec)); }
Expand All @@ -1009,9 +1009,9 @@ namespace hlslpp
hlslpp_inline float3 operator - (const float3& f1, const float1& f2) { return float3(_hlslpp_sub_ps(f1.vec, _hlslpp_perm_xxxx_ps(f2.vec))); }
hlslpp_inline float4 operator - (const float4& f1, const float1& f2) { return float4(_hlslpp_sub_ps(f1.vec, _hlslpp_perm_xxxx_ps(f2.vec))); }

hlslpp_inline float2 operator - (const float1& f1, const float2& f2) { return float2(_hlslpp_sub_ps(f2.vec, _hlslpp_perm_xxxx_ps(f1.vec))); }
hlslpp_inline float3 operator - (const float1& f1, const float3& f2) { return float3(_hlslpp_sub_ps(f2.vec, _hlslpp_perm_xxxx_ps(f1.vec))); }
hlslpp_inline float4 operator - (const float1& f1, const float4& f2) { return float4(_hlslpp_sub_ps(f2.vec, _hlslpp_perm_xxxx_ps(f1.vec))); }
hlslpp_inline float2 operator - (const float1& f1, const float2& f2) { return float2(_hlslpp_sub_ps(_hlslpp_perm_xxxx_ps(f1.vec), f2.vec)); }
hlslpp_inline float3 operator - (const float1& f1, const float3& f2) { return float3(_hlslpp_sub_ps(_hlslpp_perm_xxxx_ps(f1.vec), f2.vec)); }
hlslpp_inline float4 operator - (const float1& f1, const float4& f2) { return float4(_hlslpp_sub_ps(_hlslpp_perm_xxxx_ps(f1.vec), f2.vec)); }

hlslpp_inline float1 operator * (const float1& f1, const float1& f2) { return float1(_hlslpp_mul_ps(f1.vec, f2.vec)); }
hlslpp_inline float2 operator * (const float2& f1, const float2& f2) { return float2(_hlslpp_mul_ps(f1.vec, f2.vec)); }
Expand All @@ -1022,9 +1022,9 @@ namespace hlslpp
hlslpp_inline float3 operator * (const float3& f1, const float1& f2) { return float3(_hlslpp_mul_ps(f1.vec, _hlslpp_perm_xxxx_ps(f2.vec))); }
hlslpp_inline float4 operator * (const float4& f1, const float1& f2) { return float4(_hlslpp_mul_ps(f1.vec, _hlslpp_perm_xxxx_ps(f2.vec))); }

hlslpp_inline float2 operator * (const float1& f1, const float2& f2) { return float2(_hlslpp_mul_ps(f2.vec, _hlslpp_perm_xxxx_ps(f1.vec))); }
hlslpp_inline float3 operator * (const float1& f1, const float3& f2) { return float3(_hlslpp_mul_ps(f2.vec, _hlslpp_perm_xxxx_ps(f1.vec))); }
hlslpp_inline float4 operator * (const float1& f1, const float4& f2) { return float4(_hlslpp_mul_ps(f2.vec, _hlslpp_perm_xxxx_ps(f1.vec))); }
hlslpp_inline float2 operator * (const float1& f1, const float2& f2) { return float2(_hlslpp_mul_ps(_hlslpp_perm_xxxx_ps(f1.vec), f2.vec)); }
hlslpp_inline float3 operator * (const float1& f1, const float3& f2) { return float3(_hlslpp_mul_ps(_hlslpp_perm_xxxx_ps(f1.vec), f2.vec)); }
hlslpp_inline float4 operator * (const float1& f1, const float4& f2) { return float4(_hlslpp_mul_ps(_hlslpp_perm_xxxx_ps(f1.vec), f2.vec)); }

hlslpp_inline float1 operator / (const float1& f1, const float1& f2) { return float1(_hlslpp_div_ps(f1.vec, f2.vec)); }
hlslpp_inline float2 operator / (const float2& f1, const float2& f2) { return float2(_hlslpp_div_ps(f1.vec, f2.vec)); }
Expand All @@ -1035,9 +1035,9 @@ namespace hlslpp
hlslpp_inline float3 operator / (const float3& f1, const float1& f2) { return float3(_hlslpp_div_ps(f1.vec, _hlslpp_perm_xxxx_ps(f2.vec))); }
hlslpp_inline float4 operator / (const float4& f1, const float1& f2) { return float4(_hlslpp_div_ps(f1.vec, _hlslpp_perm_xxxx_ps(f2.vec))); }

hlslpp_inline float2 operator / (const float1& f1, const float2& f2) { return float2(_hlslpp_div_ps(f2.vec, _hlslpp_perm_xxxx_ps(f1.vec))); }
hlslpp_inline float3 operator / (const float1& f1, const float3& f2) { return float3(_hlslpp_div_ps(f2.vec, _hlslpp_perm_xxxx_ps(f1.vec))); }
hlslpp_inline float4 operator / (const float1& f1, const float4& f2) { return float4(_hlslpp_div_ps(f2.vec, _hlslpp_perm_xxxx_ps(f1.vec))); }
hlslpp_inline float2 operator / (const float1& f1, const float2& f2) { return float2(_hlslpp_div_ps(_hlslpp_perm_xxxx_ps(f1.vec), f2.vec)); }
hlslpp_inline float3 operator / (const float1& f1, const float3& f2) { return float3(_hlslpp_div_ps(_hlslpp_perm_xxxx_ps(f1.vec), f2.vec)); }
hlslpp_inline float4 operator / (const float1& f1, const float4& f2) { return float4(_hlslpp_div_ps(_hlslpp_perm_xxxx_ps(f1.vec), f2.vec)); }

hlslpp_inline float1 operator - (const float1& f) { return float1(_hlslpp_neg_ps(f.vec)); }
hlslpp_inline float2 operator - (const float2& f) { return float2(_hlslpp_neg_ps(f.vec)); }
Expand Down
8 changes: 8 additions & 0 deletions src/hlsl++_unit_tests_vector_float.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,10 @@ void RunUnitTestsVectorFloat()
vsub_swiz_c_2.xy -= vfoo2;
vsub_swiz_c_2.gr -= vfoo2.rg;

float2 vsub_f1_f2 = vsub1 - vsub2; eq(vsub_f1_f2, (float)vsub1 - (float)vsub2.x, (float)vsub1 - (float)vsub2.y);
float3 vsub_f1_f3 = vsub1 - vsub3; eq(vsub_f1_f3, (float)vsub1 - (float)vsub3.x, (float)vsub1 - (float)vsub3.y, (float)vsub1 - (float)vsub3.z);
float4 vsub_f1_f4 = vsub1 - vsub4; eq(vsub_f1_f4, (float)vsub1 - (float)vsub4.x, (float)vsub1 - (float)vsub4.y, (float)vsub1 - (float)vsub4.z, (float)vsub1 - (float)vsub4.w);

// Multiplication

float1 vmul1 = vfoo1 * vbar1; eq(vmul1, (float)vfoo1.x * (float)vbar1.x);
Expand Down Expand Up @@ -378,6 +382,10 @@ void RunUnitTestsVectorFloat()
vdiv_swiz_c_2.xy /= vfoo2;
vdiv_swiz_c_2.gr /= vfoo2.rg;

float2 vdiv_f1_f2 = vdiv1 / vdiv2; eq(vdiv_f1_f2, (float)vdiv1 / (float)vdiv2.x, (float)vdiv1 / (float)vdiv2.y);
float3 vdiv_f1_f3 = vdiv1 / vdiv3; eq(vdiv_f1_f3, (float)vdiv1 / (float)vdiv3.x, (float)vdiv1 / (float)vdiv3.y, (float)vdiv1 / (float)vdiv3.z);
float4 vdiv_f1_f4 = vdiv1 / vdiv4; eq(vdiv_f1_f4, (float)vdiv1 / (float)vdiv4.x, (float)vdiv1 / (float)vdiv4.y, (float)vdiv1 / (float)vdiv4.z, (float)vdiv1 / (float)vdiv4.w);

// Comparison

float1 vgt1 = vfoo1 > vbar1; eq(vgt1, (float)vfoo1.x > (float)vbar1.x);
Expand Down

0 comments on commit bf7df71

Please sign in to comment.