From e62ad2bf13aa05cb19c2bd72e0d9f59117a6ec84 Mon Sep 17 00:00:00 2001 From: "Brad Payne (Vir Linden)" Date: Thu, 15 Dec 2011 19:26:03 -0500 Subject: SH-2789 WIP - tests for alignment --- indra/llmath/CMakeLists.txt | 1 + indra/llmath/tests/alignment_test.cpp | 127 ++++++++++++++++++++++++++++++++++ 2 files changed, 128 insertions(+) mode change 100644 => 100755 indra/llmath/CMakeLists.txt create mode 100755 indra/llmath/tests/alignment_test.cpp (limited to 'indra/llmath') diff --git a/indra/llmath/CMakeLists.txt b/indra/llmath/CMakeLists.txt old mode 100644 new mode 100755 index b5e59c1ca3..5865ae030c --- a/indra/llmath/CMakeLists.txt +++ b/indra/llmath/CMakeLists.txt @@ -117,6 +117,7 @@ if (LL_TESTS) # INTEGRATION TESTS set(test_libs llmath llcommon ${LLCOMMON_LIBRARIES} ${WINDOWS_LIBRARIES}) # TODO: Some of these need refactoring to be proper Unit tests rather than Integration tests. + LL_ADD_INTEGRATION_TEST(alignment "" "${test_libs}") LL_ADD_INTEGRATION_TEST(llbbox llbbox.cpp "${test_libs}") LL_ADD_INTEGRATION_TEST(llquaternion llquaternion.cpp "${test_libs}") LL_ADD_INTEGRATION_TEST(mathmisc "" "${test_libs}") diff --git a/indra/llmath/tests/alignment_test.cpp b/indra/llmath/tests/alignment_test.cpp new file mode 100755 index 0000000000..6b4a454fd2 --- /dev/null +++ b/indra/llmath/tests/alignment_test.cpp @@ -0,0 +1,127 @@ +/** + * @file v3dmath_test.cpp + * @author Vir + * @date 2011-12 + * @brief v3dmath test cases. + * + * $LicenseInfo:firstyear=2011&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2011, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * 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 + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +// Tests related to allocating objects with alignment constraints, particularly for SSE support. + +#include "linden_common.h" +#include "../test/lltut.h" +#include "../llmath.h" +#include "../llsimdmath.h" +#include "../llvector4a.h" + +namespace tut +{ + +#define is_aligned(ptr,alignment) ((reinterpret_cast(ptr))%(alignment)==0) + +struct alignment_test {}; + +typedef test_group alignment_test_t; +typedef alignment_test_t::object alignment_test_object_t; +tut::alignment_test_t tut_alignment_test("LLAlignment"); + +LL_ALIGN_PREFIX(16) +class MyVector4a +{ + LLQuad mQ; +} LL_ALIGN_POSTFIX(16); + +LL_ALIGN_PREFIX(64) +class MyBigBlob +{ +public: + ~MyBigBlob() {} +private: + LLQuad mQ[4]; +} LL_ALIGN_POSTFIX(64); + +// In-place allocation of objects and arrays. +template<> template<> +void alignment_test_object_t::test<1>() +{ + ensure("LLAlignment reality is broken: ", (1==1)); + + MyVector4a vec1; + ensure("LLAlignment vec1 unaligned", is_aligned(&vec1,16)); + + MyBigBlob bb1; + ensure("LLAlignment bb1 unaligned", is_aligned(&bb1,64)); + + + MyVector4a veca[12]; + ensure("LLAlignment veca unaligned", is_aligned(veca,16)); + + MyBigBlob bba[12]; + ensure("LLAlignment bba unaligned", is_aligned(bba,64)); +} + +// Heap allocation of objects and arrays. +template<> template<> +void alignment_test_object_t::test<2>() +{ + const int ARR_SIZE = 7; + for(int i=0; i~MyBigBlob(); + _aligned_free(aligned_addr); + } + + ensure("LLAlignment big blob size",sizeof(MyBigBlob)==64); + void *aligned_addr = _aligned_malloc(ARR_SIZE*sizeof(MyBigBlob),64); + MyBigBlob *bba = new(aligned_addr) MyBigBlob[ARR_SIZE]; + std::cout << "aligned_addr " << aligned_addr << std::endl; + std::cout << "bba " << bba << std::endl; + for(int i=0; i