/* Crafter® Build Copyright (C) 2026 Catcrafts® Catcrafts.net This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License version 3.0 as published by the Free Software Foundation; This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include import Crafter.Math; import std; using namespace Crafter; template std::string* TestLoadStore() { _Float16 floats[Len * Packing]; for (std::uint32_t i = 0; i < Len * Packing; i++) { floats[i] = static_cast<_Float16>(i); } VectorF16 vec(floats); auto stored = vec.Store(); for (std::uint32_t i = 0; i < Len * Packing; i++) { if (stored.v[i] != floats[i]) { return new std::string(std::format("Load/Store mismatch at Len={} Packing={}, Expected: {}, Got: {}", Len, Packing, (float)(floats[i]), (float)stored.v[i])); } } return nullptr; } template std::string* TestAdd() { _Float16 floats[Len * Packing]; for (std::uint32_t i = 0; i < Len * Packing; i++) { floats[i] = static_cast<_Float16>(i); } VectorF16 vec(floats); vec = vec + vec; auto stored = vec.Store(); for (std::uint32_t i = 0; i < Len * Packing; i++) { if (stored.v[i] != floats[i] + floats[i]) { return new std::string(std::format("Add mismatch at Len={} Packing={}, Expected: {}, Got: {}", Len, Packing, (float)(floats[i] + floats[i]), (float)stored.v[i])); } } return nullptr; } template std::string* TestAllCombinations() { if constexpr (Len > MaxSize) { return nullptr; } else if constexpr (Len * Packing > MaxSize) { return TestAllCombinations(); } else { std::string* result = TestLoadStore(); if (result) return result; result = TestAdd(); if (result) return result; return TestAllCombinations(); } } extern "C" { std::string* RunTest() { std::string* err = TestAllCombinations::MaxSize>(); if (err) { return err; } return nullptr; } }