IACore v1.2

This commit is contained in:
2026-01-25 22:55:24 +05:30
commit 49340eaa7b
95 changed files with 10182 additions and 0 deletions

View File

@ -0,0 +1,102 @@
// IACore-OSS; The Core Library for All IA Open Source Projects
// Copyright (C) 2026 IAS (ias@iasoft.dev)
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <IACore/IATest.hpp>
#include <IACore/SIMD.hpp>
using namespace IACore;
IAT_BEGIN_BLOCK(Core, FloatVec4)
auto test_float_arithmetic() -> bool {
FloatVec4 v1(10.0f, 20.0f, 30.0f, 40.0f);
FloatVec4 v2(2.0f, 4.0f, 5.0f, 8.0f);
alignas(16) f32 res[4];
(v1 / v2).store(res);
IAT_CHECK_APPROX(res[0], 5.0f);
IAT_CHECK_APPROX(res[3], 5.0f);
(v1 * v2).store(res);
IAT_CHECK_APPROX(res[0], 20.0f);
(v1 + v2).store(res);
IAT_CHECK_APPROX(res[0], 12.0f);
return true;
}
auto test_math_helpers() -> bool {
alignas(16) f32 res[4];
FloatVec4 v_sq(4.0f, 9.0f, 16.0f, 25.0f);
v_sq.sqrt().store(res);
IAT_CHECK_APPROX(res[0], 2.0f);
IAT_CHECK_APPROX(res[3], 5.0f);
FloatVec4 v_neg(-1.0f, -5.0f, 10.0f, -0.0f);
v_neg.abs().store(res);
IAT_CHECK_APPROX(res[0], 1.0f);
IAT_CHECK_APPROX(res[2], 10.0f);
FloatVec4 v_clamp(-100.0f, 0.0f, 50.0f, 200.0f);
v_clamp.clamp(0.0f, 100.0f).store(res);
IAT_CHECK_APPROX(res[0], 0.0f);
IAT_CHECK_APPROX(res[2], 50.0f);
IAT_CHECK_APPROX(res[3], 100.0f);
return true;
}
auto test_approx_math() -> bool {
alignas(16) f32 res[4];
FloatVec4 v(16.0f, 25.0f, 100.0f, 1.0f);
v.rsqrt().store(res);
IAT_CHECK_APPROX(res[0], 0.25f);
IAT_CHECK_APPROX(res[2], 0.1f);
return true;
}
auto test_linear_algebra() -> bool {
FloatVec4 v1(1.0f, 2.0f, 3.0f, 4.0f);
FloatVec4 v2(1.0f, 0.0f, 1.0f, 0.0f);
f32 dot = v1.dot(v2);
IAT_CHECK_APPROX(dot, 4.0f);
FloatVec4 v_norm(10.0f, 0.0f, 0.0f, 0.0f);
alignas(16) f32 res[4];
v_norm.normalize().store(res);
IAT_CHECK_APPROX(res[0], 1.0f);
IAT_CHECK_APPROX(res[1], 0.0f);
return true;
}
IAT_BEGIN_TEST_LIST()
IAT_ADD_TEST(test_float_arithmetic);
IAT_ADD_TEST(test_math_helpers);
IAT_ADD_TEST(test_approx_math);
IAT_ADD_TEST(test_linear_algebra);
IAT_END_TEST_LIST()
IAT_END_BLOCK()
IAT_REGISTER_ENTRY(Core, FloatVec4)

144
Tests/Unit/SIMD/IntVec4.cpp Normal file
View File

@ -0,0 +1,144 @@
// IACore-OSS; The Core Library for All IA Open Source Projects
// Copyright (C) 2026 IAS (ias@iasoft.dev)
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <IACore/IATest.hpp>
#include <IACore/SIMD.hpp>
using namespace IACore;
IAT_BEGIN_BLOCK(Core, IntVec4)
auto test_constructors() -> bool {
IntVec4 v_broadcast(10);
alignas(16) u32 store_buf[4];
v_broadcast.store(store_buf);
IAT_CHECK_EQ(store_buf[0], 10U);
IAT_CHECK_EQ(store_buf[3], 10U);
IntVec4 v_comp(1, 2, 3, 4);
v_comp.store(store_buf);
IAT_CHECK_EQ(store_buf[0], 1U);
IAT_CHECK_EQ(store_buf[3], 4U);
alignas(16) u32 src_buf[4] = {100, 200, 300, 400};
IntVec4 v_load = IntVec4::load(src_buf);
v_load.store(store_buf);
IAT_CHECK_EQ(store_buf[1], 200U);
return true;
}
auto test_arithmetic() -> bool {
const IntVec4 v1(10, 20, 30, 40);
const IntVec4 v2(1, 2, 3, 4);
IntVec4 v_add = v1 + v2;
alignas(16) u32 res[4];
v_add.store(res);
IAT_CHECK_EQ(res[0], 11U);
IAT_CHECK_EQ(res[3], 44U);
IntVec4 v_sub = v1 - v2;
v_sub.store(res);
IAT_CHECK_EQ(res[0], 9U);
IntVec4 v_mul = v1 * v2;
v_mul.store(res);
IAT_CHECK_EQ(res[0], 10U);
IAT_CHECK_EQ(res[2], 90U);
IAT_CHECK_EQ(res[3], 160U);
return true;
}
auto test_bitwise() -> bool {
const IntVec4 v_all_ones(0xFFFFFFFF);
const IntVec4 v_zero((u32)0);
const IntVec4 v_pattern(0xAAAAAAAA);
alignas(16) u32 res[4];
(v_all_ones & v_pattern).store(res);
IAT_CHECK_EQ(res[0], 0xAAAAAAAAU);
(v_zero | v_pattern).store(res);
IAT_CHECK_EQ(res[0], 0xAAAAAAAAU);
(v_all_ones ^ v_pattern).store(res);
IAT_CHECK_EQ(res[0], 0x55555555U);
(~v_pattern).store(res);
IAT_CHECK_EQ(res[0], 0x55555555U);
const IntVec4 v_shift(1);
(v_shift << 1).store(res);
IAT_CHECK_EQ(res[0], 2U);
const IntVec4 v_shift_right(4);
(v_shift_right >> 1).store(res);
IAT_CHECK_EQ(res[0], 2U);
return true;
}
auto test_saturation() -> bool {
const u32 max = 0xFFFFFFFF;
const IntVec4 v_high(max - 10);
const IntVec4 v_add(20);
alignas(16) u32 res[4];
v_high.sat_add(v_add).store(res);
IAT_CHECK_EQ(res[0], max);
const IntVec4 v_low(10);
const IntVec4 v_sub(20);
v_low.sat_sub(v_sub).store(res);
IAT_CHECK_EQ(res[0], 0U);
return true;
}
auto test_advanced_ops() -> bool {
const IntVec4 v(0, 50, 100, 150);
alignas(16) u32 res[4];
v.clamp(40, 110).store(res);
IAT_CHECK_EQ(res[0], 40U);
IAT_CHECK_EQ(res[1], 50U);
IAT_CHECK_EQ(res[2], 100U);
IAT_CHECK_EQ(res[3], 110U);
const IntVec4 a(2);
const IntVec4 b(10);
const IntVec4 c(5);
a.mult_add(b, c).store(res);
IAT_CHECK_EQ(res[0], 25U);
return true;
}
IAT_BEGIN_TEST_LIST()
IAT_ADD_TEST(test_constructors);
IAT_ADD_TEST(test_arithmetic);
IAT_ADD_TEST(test_bitwise);
IAT_ADD_TEST(test_saturation);
IAT_ADD_TEST(test_advanced_ops);
IAT_END_TEST_LIST()
IAT_END_BLOCK()
IAT_REGISTER_ENTRY(Core, IntVec4)