Skip to content

Commit

Permalink
feat(vector4): implement vector_set_component variants
Browse files Browse the repository at this point in the history
Fixes #177
  • Loading branch information
nfrechette committed Nov 30, 2023
1 parent f16d3ec commit 864c8f9
Show file tree
Hide file tree
Showing 3 changed files with 152 additions and 0 deletions.
66 changes: 66 additions & 0 deletions includes/rtm/vector4d.h
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,72 @@ namespace rtm
}
#endif

//////////////////////////////////////////////////////////////////////////
// Sets the desired vector4 component and returns the new value.
//////////////////////////////////////////////////////////////////////////
template<component4 component>
RTM_DISABLE_SECURITY_COOKIE_CHECK RTM_FORCE_INLINE vector4d vector_set_component(const vector4d& input, double lane_value) RTM_NO_EXCEPT
{
switch (component)
{
default:
case component4::x: return vector_set_x(input, lane_value);
case component4::y: return vector_set_y(input, lane_value);
case component4::z: return vector_set_z(input, lane_value);
case component4::w: return vector_set_w(input, lane_value);
}
}

#if defined(RTM_SSE2_INTRINSICS)
//////////////////////////////////////////////////////////////////////////
// Sets the desired vector4 component and returns the new value.
//////////////////////////////////////////////////////////////////////////
template<component4 component>
RTM_DISABLE_SECURITY_COOKIE_CHECK RTM_FORCE_INLINE vector4d vector_set_component(const vector4d& input, const scalard& lane_value) RTM_NO_EXCEPT
{
switch (component)
{
default:
case component4::x: return vector_set_x(input, lane_value);
case component4::y: return vector_set_y(input, lane_value);
case component4::z: return vector_set_z(input, lane_value);
case component4::w: return vector_set_w(input, lane_value);
}
}
#endif

//////////////////////////////////////////////////////////////////////////
// Sets the desired vector4 component and returns the new value.
//////////////////////////////////////////////////////////////////////////
RTM_DISABLE_SECURITY_COOKIE_CHECK RTM_FORCE_INLINE vector4d vector_set_component(const vector4d& input, double lane_value, component4 component) RTM_NO_EXCEPT
{
switch (component)
{
default:
case component4::x: return vector_set_x(input, lane_value);
case component4::y: return vector_set_y(input, lane_value);
case component4::z: return vector_set_z(input, lane_value);
case component4::w: return vector_set_w(input, lane_value);
}
}

#if defined(RTM_SSE2_INTRINSICS)
//////////////////////////////////////////////////////////////////////////
// Sets the desired vector4 component and returns the new value.
//////////////////////////////////////////////////////////////////////////
RTM_DISABLE_SECURITY_COOKIE_CHECK RTM_FORCE_INLINE vector4d vector_set_component(const vector4d& input, const scalard& lane_value, component4 component) RTM_NO_EXCEPT
{
switch (component)
{
default:
case component4::x: return vector_set_x(input, lane_value);
case component4::y: return vector_set_y(input, lane_value);
case component4::z: return vector_set_z(input, lane_value);
case component4::w: return vector_set_w(input, lane_value);
}
}
#endif

//////////////////////////////////////////////////////////////////////////
// Returns a floating point pointer to the vector4 data.
//////////////////////////////////////////////////////////////////////////
Expand Down
66 changes: 66 additions & 0 deletions includes/rtm/vector4f.h
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,72 @@ namespace rtm
}
#endif

//////////////////////////////////////////////////////////////////////////
// Sets the desired vector4 component and returns the new value.
//////////////////////////////////////////////////////////////////////////
template<component4 component>
RTM_DISABLE_SECURITY_COOKIE_CHECK RTM_FORCE_INLINE vector4f RTM_SIMD_CALL vector_set_component(vector4f_arg0 input, float lane_value) RTM_NO_EXCEPT
{
switch (component)
{
default:
case component4::x: return vector_set_x(input, lane_value);
case component4::y: return vector_set_y(input, lane_value);
case component4::z: return vector_set_z(input, lane_value);
case component4::w: return vector_set_w(input, lane_value);
}
}

#if defined(RTM_SSE2_INTRINSICS)
//////////////////////////////////////////////////////////////////////////
// Sets the desired vector4 component and returns the new value.
//////////////////////////////////////////////////////////////////////////
template<component4 component>
RTM_DISABLE_SECURITY_COOKIE_CHECK RTM_FORCE_INLINE vector4f RTM_SIMD_CALL vector_set_component(vector4f_arg0 input, scalarf_arg1 lane_value) RTM_NO_EXCEPT
{
switch (component)
{
default:
case component4::x: return vector_set_x(input, lane_value);
case component4::y: return vector_set_y(input, lane_value);
case component4::z: return vector_set_z(input, lane_value);
case component4::w: return vector_set_w(input, lane_value);
}
}
#endif

//////////////////////////////////////////////////////////////////////////
// Sets the desired vector4 component and returns the new value.
//////////////////////////////////////////////////////////////////////////
RTM_DISABLE_SECURITY_COOKIE_CHECK RTM_FORCE_INLINE vector4f RTM_SIMD_CALL vector_set_component(vector4f_arg0 input, float lane_value, component4 component) RTM_NO_EXCEPT
{
switch (component)
{
default:
case component4::x: return vector_set_x(input, lane_value);
case component4::y: return vector_set_y(input, lane_value);
case component4::z: return vector_set_z(input, lane_value);
case component4::w: return vector_set_w(input, lane_value);
}
}

#if defined(RTM_SSE2_INTRINSICS)
//////////////////////////////////////////////////////////////////////////
// Sets the desired vector4 component and returns the new value.
//////////////////////////////////////////////////////////////////////////
RTM_DISABLE_SECURITY_COOKIE_CHECK RTM_FORCE_INLINE vector4f RTM_SIMD_CALL vector_set_component(vector4f_arg0 input, scalarf_arg1 lane_value, component4 component) RTM_NO_EXCEPT
{
switch (component)
{
default:
case component4::x: return vector_set_x(input, lane_value);
case component4::y: return vector_set_y(input, lane_value);
case component4::z: return vector_set_z(input, lane_value);
case component4::w: return vector_set_w(input, lane_value);
}
}
#endif

//////////////////////////////////////////////////////////////////////////
// Returns a floating point pointer to the vector4 data.
//////////////////////////////////////////////////////////////////////////
Expand Down
20 changes: 20 additions & 0 deletions tests/sources/test_vector4_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,26 @@ void test_vector4_getset_impl()
CHECK(vector_all_near_equal(vector_set_z(zero, scalar_set(FloatType(4.0))), vector_set(FloatType(0.0), FloatType(0.0), FloatType(4.0), FloatType(0.0)), FloatType(0.0)));
CHECK(vector_all_near_equal(vector_set_w(zero, scalar_set(FloatType(4.0))), vector_set(FloatType(0.0), FloatType(0.0), FloatType(0.0), FloatType(4.0)), FloatType(0.0)));

CHECK(vector_all_near_equal(vector_set_component<component4::x>(zero, FloatType(4.0)), vector_set(FloatType(4.0), FloatType(0.0), FloatType(0.0), FloatType(0.0)), FloatType(0.0)));
CHECK(vector_all_near_equal(vector_set_component<component4::y>(zero, FloatType(4.0)), vector_set(FloatType(0.0), FloatType(4.0), FloatType(0.0), FloatType(0.0)), FloatType(0.0)));
CHECK(vector_all_near_equal(vector_set_component<component4::z>(zero, FloatType(4.0)), vector_set(FloatType(0.0), FloatType(0.0), FloatType(4.0), FloatType(0.0)), FloatType(0.0)));
CHECK(vector_all_near_equal(vector_set_component<component4::w>(zero, FloatType(4.0)), vector_set(FloatType(0.0), FloatType(0.0), FloatType(0.0), FloatType(4.0)), FloatType(0.0)));

CHECK(vector_all_near_equal(vector_set_component<component4::x>(zero, scalar_set(FloatType(4.0))), vector_set(FloatType(4.0), FloatType(0.0), FloatType(0.0), FloatType(0.0)), FloatType(0.0)));
CHECK(vector_all_near_equal(vector_set_component<component4::y>(zero, scalar_set(FloatType(4.0))), vector_set(FloatType(0.0), FloatType(4.0), FloatType(0.0), FloatType(0.0)), FloatType(0.0)));
CHECK(vector_all_near_equal(vector_set_component<component4::z>(zero, scalar_set(FloatType(4.0))), vector_set(FloatType(0.0), FloatType(0.0), FloatType(4.0), FloatType(0.0)), FloatType(0.0)));
CHECK(vector_all_near_equal(vector_set_component<component4::w>(zero, scalar_set(FloatType(4.0))), vector_set(FloatType(0.0), FloatType(0.0), FloatType(0.0), FloatType(4.0)), FloatType(0.0)));

CHECK(vector_all_near_equal(vector_set_component(zero, FloatType(4.0), component4::x), vector_set(FloatType(4.0), FloatType(0.0), FloatType(0.0), FloatType(0.0)), FloatType(0.0)));
CHECK(vector_all_near_equal(vector_set_component(zero, FloatType(4.0), component4::y), vector_set(FloatType(0.0), FloatType(4.0), FloatType(0.0), FloatType(0.0)), FloatType(0.0)));
CHECK(vector_all_near_equal(vector_set_component(zero, FloatType(4.0), component4::z), vector_set(FloatType(0.0), FloatType(0.0), FloatType(4.0), FloatType(0.0)), FloatType(0.0)));
CHECK(vector_all_near_equal(vector_set_component(zero, FloatType(4.0), component4::w), vector_set(FloatType(0.0), FloatType(0.0), FloatType(0.0), FloatType(4.0)), FloatType(0.0)));

CHECK(vector_all_near_equal(vector_set_component(zero, scalar_set(FloatType(4.0)), component4::x), vector_set(FloatType(4.0), FloatType(0.0), FloatType(0.0), FloatType(0.0)), FloatType(0.0)));
CHECK(vector_all_near_equal(vector_set_component(zero, scalar_set(FloatType(4.0)), component4::y), vector_set(FloatType(0.0), FloatType(4.0), FloatType(0.0), FloatType(0.0)), FloatType(0.0)));
CHECK(vector_all_near_equal(vector_set_component(zero, scalar_set(FloatType(4.0)), component4::z), vector_set(FloatType(0.0), FloatType(0.0), FloatType(4.0), FloatType(0.0)), FloatType(0.0)));
CHECK(vector_all_near_equal(vector_set_component(zero, scalar_set(FloatType(4.0)), component4::w), vector_set(FloatType(0.0), FloatType(0.0), FloatType(0.0), FloatType(4.0)), FloatType(0.0)));

CHECK((FloatType)vector_as_scalar(test_value1) == FloatType(vector_get_x(test_value1)));
CHECK(scalar_equal(vector_as_scalar(test_value1), scalar_set(vector_get_x(test_value1))));
}
Expand Down

0 comments on commit 864c8f9

Please sign in to comment.