15129044dSC.J. Collier/*-
25129044dSC.J. Collier *   BSD LICENSE
35129044dSC.J. Collier *
45129044dSC.J. Collier *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
55129044dSC.J. Collier *   All rights reserved.
65129044dSC.J. Collier *
75129044dSC.J. Collier *   Redistribution and use in source and binary forms, with or without
85129044dSC.J. Collier *   modification, are permitted provided that the following conditions
95129044dSC.J. Collier *   are met:
105129044dSC.J. Collier *
115129044dSC.J. Collier *     * Redistributions of source code must retain the above copyright
125129044dSC.J. Collier *       notice, this list of conditions and the following disclaimer.
135129044dSC.J. Collier *     * Redistributions in binary form must reproduce the above copyright
145129044dSC.J. Collier *       notice, this list of conditions and the following disclaimer in
155129044dSC.J. Collier *       the documentation and/or other materials provided with the
165129044dSC.J. Collier *       distribution.
175129044dSC.J. Collier *     * Neither the name of Intel Corporation nor the names of its
185129044dSC.J. Collier *       contributors may be used to endorse or promote products derived
195129044dSC.J. Collier *       from this software without specific prior written permission.
205129044dSC.J. Collier *
215129044dSC.J. Collier *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
225129044dSC.J. Collier *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
235129044dSC.J. Collier *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
245129044dSC.J. Collier *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
255129044dSC.J. Collier *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
265129044dSC.J. Collier *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
275129044dSC.J. Collier *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
285129044dSC.J. Collier *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
295129044dSC.J. Collier *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
305129044dSC.J. Collier *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
315129044dSC.J. Collier *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
325129044dSC.J. Collier */
335129044dSC.J. Collier
345129044dSC.J. Collier#include <stdio.h>
355129044dSC.J. Collier
365129044dSC.J. Collier#include <errno.h>
375129044dSC.J. Collier#include <stdint.h>
385129044dSC.J. Collier#include <rte_cpuflags.h>
395129044dSC.J. Collier#include <rte_debug.h>
405129044dSC.J. Collier
415129044dSC.J. Collier#include "test.h"
425129044dSC.J. Collier
435129044dSC.J. Collier
445129044dSC.J. Collier/* convenience define */
455129044dSC.J. Collier#define CHECK_FOR_FLAG(x) \
465129044dSC.J. Collier			result = rte_cpu_get_flag_enabled(x);    \
475129044dSC.J. Collier			printf("%s\n", cpu_flag_result(result)); \
485129044dSC.J. Collier			if (result == -ENOENT)                   \
495129044dSC.J. Collier				return -1;
505129044dSC.J. Collier
515129044dSC.J. Collier/*
525129044dSC.J. Collier * Helper function to display result
535129044dSC.J. Collier */
545129044dSC.J. Collierstatic inline const char *
555129044dSC.J. Colliercpu_flag_result(int result)
565129044dSC.J. Collier{
575129044dSC.J. Collier	switch (result) {
585129044dSC.J. Collier	case 0:
595129044dSC.J. Collier		return "NOT PRESENT";
605129044dSC.J. Collier	case 1:
615129044dSC.J. Collier		return "OK";
625129044dSC.J. Collier	default:
635129044dSC.J. Collier		return "ERROR";
645129044dSC.J. Collier	}
655129044dSC.J. Collier}
665129044dSC.J. Collier
675129044dSC.J. Collier
685129044dSC.J. Collier
695129044dSC.J. Collier/*
705129044dSC.J. Collier * CPUID test
715129044dSC.J. Collier * ===========
725129044dSC.J. Collier *
735129044dSC.J. Collier * - Check flags from different registers with rte_cpu_get_flag_enabled()
745129044dSC.J. Collier * - Check if register and CPUID functions fail properly
755129044dSC.J. Collier */
765129044dSC.J. Collier
775129044dSC.J. Collierstatic int
785129044dSC.J. Colliertest_cpuflags(void)
795129044dSC.J. Collier{
805129044dSC.J. Collier	int result;
815129044dSC.J. Collier	printf("\nChecking for flags from different registers...\n");
825129044dSC.J. Collier
835129044dSC.J. Collier#ifdef RTE_ARCH_PPC_64
845129044dSC.J. Collier	printf("Check for PPC64:\t\t");
855129044dSC.J. Collier	CHECK_FOR_FLAG(RTE_CPUFLAG_PPC64);
865129044dSC.J. Collier
875129044dSC.J. Collier	printf("Check for PPC32:\t\t");
885129044dSC.J. Collier	CHECK_FOR_FLAG(RTE_CPUFLAG_PPC32);
895129044dSC.J. Collier
905129044dSC.J. Collier	printf("Check for VSX:\t\t");
915129044dSC.J. Collier	CHECK_FOR_FLAG(RTE_CPUFLAG_VSX);
925129044dSC.J. Collier
935129044dSC.J. Collier	printf("Check for DFP:\t\t");
945129044dSC.J. Collier	CHECK_FOR_FLAG(RTE_CPUFLAG_DFP);
955129044dSC.J. Collier
965129044dSC.J. Collier	printf("Check for FPU:\t\t");
975129044dSC.J. Collier	CHECK_FOR_FLAG(RTE_CPUFLAG_FPU);
985129044dSC.J. Collier
995129044dSC.J. Collier	printf("Check for SMT:\t\t");
1005129044dSC.J. Collier	CHECK_FOR_FLAG(RTE_CPUFLAG_SMT);
1015129044dSC.J. Collier
1025129044dSC.J. Collier	printf("Check for MMU:\t\t");
1035129044dSC.J. Collier	CHECK_FOR_FLAG(RTE_CPUFLAG_MMU);
1045129044dSC.J. Collier
1055129044dSC.J. Collier	printf("Check for ALTIVEC:\t\t");
1065129044dSC.J. Collier	CHECK_FOR_FLAG(RTE_CPUFLAG_ALTIVEC);
1075129044dSC.J. Collier
1085129044dSC.J. Collier	printf("Check for ARCH_2_06:\t\t");
1095129044dSC.J. Collier	CHECK_FOR_FLAG(RTE_CPUFLAG_ARCH_2_06);
1105129044dSC.J. Collier
1115129044dSC.J. Collier	printf("Check for ARCH_2_07:\t\t");
1125129044dSC.J. Collier	CHECK_FOR_FLAG(RTE_CPUFLAG_ARCH_2_07);
1135129044dSC.J. Collier
1145129044dSC.J. Collier	printf("Check for ICACHE_SNOOP:\t\t");
1155129044dSC.J. Collier	CHECK_FOR_FLAG(RTE_CPUFLAG_ICACHE_SNOOP);
1165129044dSC.J. Collier#endif
1175129044dSC.J. Collier
1185129044dSC.J. Collier#if defined(RTE_ARCH_ARM)
1195129044dSC.J. Collier	printf("Check for NEON:\t\t");
1205129044dSC.J. Collier	CHECK_FOR_FLAG(RTE_CPUFLAG_NEON);
1215129044dSC.J. Collier#endif
1225129044dSC.J. Collier
1235129044dSC.J. Collier#if defined(RTE_ARCH_ARM64)
1245129044dSC.J. Collier	printf("Check for FP:\t\t");
1255129044dSC.J. Collier	CHECK_FOR_FLAG(RTE_CPUFLAG_FP);
1265129044dSC.J. Collier
1275129044dSC.J. Collier	printf("Check for ASIMD:\t");
1285129044dSC.J. Collier	CHECK_FOR_FLAG(RTE_CPUFLAG_NEON);
1295129044dSC.J. Collier
1305129044dSC.J. Collier	printf("Check for EVTSTRM:\t");
1315129044dSC.J. Collier	CHECK_FOR_FLAG(RTE_CPUFLAG_EVTSTRM);
1325129044dSC.J. Collier
1335129044dSC.J. Collier	printf("Check for AES:\t\t");
1345129044dSC.J. Collier	CHECK_FOR_FLAG(RTE_CPUFLAG_AES);
1355129044dSC.J. Collier
1365129044dSC.J. Collier	printf("Check for PMULL:\t");
1375129044dSC.J. Collier	CHECK_FOR_FLAG(RTE_CPUFLAG_PMULL);
1385129044dSC.J. Collier
1395129044dSC.J. Collier	printf("Check for SHA1:\t\t");
1405129044dSC.J. Collier	CHECK_FOR_FLAG(RTE_CPUFLAG_SHA1);
1415129044dSC.J. Collier
1425129044dSC.J. Collier	printf("Check for SHA2:\t\t");
1435129044dSC.J. Collier	CHECK_FOR_FLAG(RTE_CPUFLAG_SHA2);
1445129044dSC.J. Collier
1455129044dSC.J. Collier	printf("Check for CRC32:\t");
1465129044dSC.J. Collier	CHECK_FOR_FLAG(RTE_CPUFLAG_CRC32);
1475129044dSC.J. Collier
1485129044dSC.J. Collier	printf("Check for ATOMICS:\t");
1495129044dSC.J. Collier	CHECK_FOR_FLAG(RTE_CPUFLAG_ATOMICS);
1505129044dSC.J. Collier#endif
1515129044dSC.J. Collier
1525129044dSC.J. Collier#if defined(RTE_ARCH_X86_64) || defined(RTE_ARCH_I686)
1535129044dSC.J. Collier	printf("Check for SSE:\t\t");
1545129044dSC.J. Collier	CHECK_FOR_FLAG(RTE_CPUFLAG_SSE);
1555129044dSC.J. Collier
1565129044dSC.J. Collier	printf("Check for SSE2:\t\t");
1575129044dSC.J. Collier	CHECK_FOR_FLAG(RTE_CPUFLAG_SSE2);
1585129044dSC.J. Collier
1595129044dSC.J. Collier	printf("Check for SSE3:\t\t");
1605129044dSC.J. Collier	CHECK_FOR_FLAG(RTE_CPUFLAG_SSE3);
1615129044dSC.J. Collier
1625129044dSC.J. Collier	printf("Check for SSE4.1:\t");
1635129044dSC.J. Collier	CHECK_FOR_FLAG(RTE_CPUFLAG_SSE4_1);
1645129044dSC.J. Collier
1655129044dSC.J. Collier	printf("Check for SSE4.2:\t");
1665129044dSC.J. Collier	CHECK_FOR_FLAG(RTE_CPUFLAG_SSE4_2);
1675129044dSC.J. Collier
1685129044dSC.J. Collier	printf("Check for AVX:\t\t");
1695129044dSC.J. Collier	CHECK_FOR_FLAG(RTE_CPUFLAG_AVX);
1705129044dSC.J. Collier
1715129044dSC.J. Collier	printf("Check for AVX2:\t\t");
1725129044dSC.J. Collier	CHECK_FOR_FLAG(RTE_CPUFLAG_AVX2);
1735129044dSC.J. Collier
1745129044dSC.J. Collier	printf("Check for TRBOBST:\t");
1755129044dSC.J. Collier	CHECK_FOR_FLAG(RTE_CPUFLAG_TRBOBST);
1765129044dSC.J. Collier
1775129044dSC.J. Collier	printf("Check for ENERGY_EFF:\t");
1785129044dSC.J. Collier	CHECK_FOR_FLAG(RTE_CPUFLAG_ENERGY_EFF);
1795129044dSC.J. Collier
1805129044dSC.J. Collier	printf("Check for LAHF_SAHF:\t");
1815129044dSC.J. Collier	CHECK_FOR_FLAG(RTE_CPUFLAG_LAHF_SAHF);
1825129044dSC.J. Collier
1835129044dSC.J. Collier	printf("Check for 1GB_PG:\t");
1845129044dSC.J. Collier	CHECK_FOR_FLAG(RTE_CPUFLAG_1GB_PG);
1855129044dSC.J. Collier
1865129044dSC.J. Collier	printf("Check for INVTSC:\t");
1875129044dSC.J. Collier	CHECK_FOR_FLAG(RTE_CPUFLAG_INVTSC);
1885129044dSC.J. Collier#endif
1895129044dSC.J. Collier
1905129044dSC.J. Collier	/*
1915129044dSC.J. Collier	 * Check if invalid data is handled properly
1925129044dSC.J. Collier	 */
1935129044dSC.J. Collier	printf("\nCheck for invalid flag:\t");
1945129044dSC.J. Collier	result = rte_cpu_get_flag_enabled(RTE_CPUFLAG_NUMFLAGS);
1955129044dSC.J. Collier	printf("%s\n", cpu_flag_result(result));
1965129044dSC.J. Collier	if (result != -ENOENT)
1975129044dSC.J. Collier		return -1;
1985129044dSC.J. Collier
1995129044dSC.J. Collier	return 0;
2005129044dSC.J. Collier}
2015129044dSC.J. Collier
2029ecc306dSRicardo SalvetiREGISTER_TEST_COMMAND(cpuflags_autotest, test_cpuflags);
203