view test/test_align.h @ 23:e26874655738

*: huge refactor, new major release (hahaha) I keep finding things that are broken... The problem NOW was that vec would unintentionally build some functions with extended instruction sets, which is Bad and would mean that for all intents and purposes the CPU detection was completely broken. Now vec is no longer header only either. Boohoo. However this gives a lot more flexibility to vec since we no longer want or need to care about C++ crap. The NEON and Altivec implementations have not been updated which means they won't compile hence why they're commented out in the cmake build file.
author Paper <paper@tflc.us>
date Sun, 24 Nov 2024 02:52:40 -0500
parents 41dd962abdd1
children
line wrap: on
line source

static int test_align(void)
{
	int ret = 0;

#define RUN_TEST(sign, csign, bits, size) \
	do { \
		/* allocate the aligned array */ \
		V##csign##INT##bits##x##size##_ALIGNED_ARRAY(vec_arr); \
	\
		/* fill the values */ \
		for (int i = 0; i < size; i++) \
			vec_arr[i] = i; \
	\
		/* try to load it */ \
		v##sign##int##bits##x##size vec = v##sign##int##bits##x##size##_load_aligned(vec_arr); \
	\
		/* now allocate an output array */ \
		V##csign##INT##bits##x##size##_ALIGNED_ARRAY(vec_arr_out); \
	\
		/* try storing it */ \
		v##sign##int##bits##x##size##_store_aligned(vec, vec_arr_out); \
	\
		/* mark success or failure */ \
		ret |= !!memcmp(vec_arr, vec_arr_out, size * sizeof(*vec_arr)); \
	\
		ret |= !V##csign##INT##bits##x##size##_PTR_ALIGNED(vec_arr); \
		ret |= !V##csign##INT##bits##x##size##_PTR_ALIGNED(vec_arr_out); \
	} while (0);

#define RUN_TESTS(bits, size) \
	RUN_TEST( ,  , bits, size) \
	RUN_TEST(u, U, bits, size)

	RUN_TESTS(8, 2)

	RUN_TESTS(8, 4)
	RUN_TESTS(16, 2)

	RUN_TESTS(8, 8)
	RUN_TESTS(16, 4)
	RUN_TESTS(32, 2)

	RUN_TESTS(8, 16)
	RUN_TESTS(16, 8)
	RUN_TESTS(32, 4)
	RUN_TESTS(64, 2)

	RUN_TESTS(8, 32)
	RUN_TESTS(16, 16)
	RUN_TESTS(32, 8)
	RUN_TESTS(64, 4)

	RUN_TESTS(8, 64)
	RUN_TESTS(16, 32)
	RUN_TESTS(32, 16)
	RUN_TESTS(64, 8)

#undef RUN_TESTS
#undef RUN_TEST

	return ret;
}