|
| 1 | +/*************************************************************************** |
| 2 | + * Copyright (c) Johan Mabille, Sylvain Corlay, Wolf Vollprecht and * |
| 3 | + * Martin Renou * |
| 4 | + * Copyright (c) QuantStack * |
| 5 | + * Copyright (c) Serge Guelton * |
| 6 | + * * |
| 7 | + * Distributed under the terms of the BSD 3-Clause License. * |
| 8 | + * * |
| 9 | + * The full license is in the file LICENSE, distributed with this software. * |
| 10 | + ***************************************************************************/ |
| 11 | + |
| 12 | +#ifndef XSIMD_CPU_FEATURES_PPC_HPP |
| 13 | +#define XSIMD_CPU_FEATURES_PPC_HPP |
| 14 | + |
| 15 | +#include "./xsimd_config.hpp" |
| 16 | +#include "./xsimd_getauxval.hpp" |
| 17 | + |
| 18 | +#if XSIMD_TARGET_PPC && XSIMD_HAVE_LINUX_GETAUXVAL |
| 19 | +// HWCAP_XXX masks to use on getauxval results. |
| 20 | +// Header does not exists on all architectures and masks are architecture |
| 21 | +// specific. |
| 22 | +#include <asm/hwcap.h> |
| 23 | +#endif // XSIMD_TARGET_PPC && XSIMD_HAVE_LINUX_GETAUXVAL |
| 24 | + |
| 25 | +namespace xsimd |
| 26 | +{ |
| 27 | + /** |
| 28 | + * An opinionated CPU feature detection utility for PowerPC. |
| 29 | + * |
| 30 | + * On Linux, runtime detection uses getauxval to query the auxiliary vector. |
| 31 | + * On other platforms, only compile-time information is used. |
| 32 | + * |
| 33 | + * This is well defined on all architectures. |
| 34 | + * It will always return false on non-PowerPC architectures. |
| 35 | + */ |
| 36 | + class ppc_cpu_features : private linux_hwcap_backend_default |
| 37 | + { |
| 38 | + public: |
| 39 | + inline bool vsx() const noexcept; |
| 40 | + }; |
| 41 | + |
| 42 | + /******************** |
| 43 | + * Implementation * |
| 44 | + ********************/ |
| 45 | + |
| 46 | + inline bool ppc_cpu_features::vsx() const noexcept |
| 47 | + { |
| 48 | +#if XSIMD_TARGET_PPC && XSIMD_HAVE_LINUX_GETAUXVAL |
| 49 | +#ifdef PPC_FEATURE_HAS_VSX |
| 50 | + return hwcap().has_feature(PPC_FEATURE_HAS_VSX); |
| 51 | +#else |
| 52 | + // Possibly missing on older Linux distributions |
| 53 | + return hwcap().has_feature(0x00000080); |
| 54 | +#endif |
| 55 | +#else |
| 56 | + return XSIMD_WITH_VSX; |
| 57 | +#endif |
| 58 | + } |
| 59 | +} |
| 60 | + |
| 61 | +#endif |
0 commit comments