| 1 |
/* SPDX-License-Identifier: MIT |
| 2 |
* |
| 3 |
* Permission is hereby granted, free of charge, to any person |
| 4 |
* obtaining a copy of this software and associated documentation |
| 5 |
* files (the "Software"), to deal in the Software without |
| 6 |
* restriction, including without limitation the rights to use, copy, |
| 7 |
* modify, merge, publish, distribute, sublicense, and/or sell copies |
| 8 |
* of the Software, and to permit persons to whom the Software is |
| 9 |
* furnished to do so, subject to the following conditions: |
| 10 |
* |
| 11 |
* The above copyright notice and this permission notice shall be |
| 12 |
* included in all copies or substantial portions of the Software. |
| 13 |
* |
| 14 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 15 |
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 16 |
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 17 |
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| 18 |
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| 19 |
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 20 |
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 21 |
* SOFTWARE. |
| 22 |
* |
| 23 |
* Copyright: |
| 24 |
* 2021 Evan Nemerson <[email protected]> |
| 25 |
*/ |
| 26 |
|
| 27 |
#if !defined(SIMDE_ARM_SVE_PTEST_H) |
| 28 |
#define SIMDE_ARM_SVE_PTEST_H |
| 29 |
|
| 30 |
#include "types.h" |
| 31 |
|
| 32 |
HEDLEY_DIAGNOSTIC_PUSH |
| 33 |
SIMDE_DISABLE_UNWANTED_DIAGNOSTICS |
| 34 |
|
| 35 |
SIMDE_FUNCTION_ATTRIBUTES |
| 36 |
simde_bool |
| 37 |
simde_svptest_first(simde_svbool_t pg, simde_svbool_t op) { |
| 38 |
#if defined(SIMDE_ARM_SVE_NATIVE) |
| 39 |
return svptest_first(pg, op); |
| 40 |
#elif defined(SIMDE_X86_AVX512BW_NATIVE) |
| 41 |
if (HEDLEY_LIKELY(pg.value & 1)) |
| 42 |
return op.value & 1; |
| 43 |
|
| 44 |
if (pg.value == 0 || op.value == 0) |
| 45 |
return 0; |
| 46 |
|
| 47 |
#if defined(_MSC_VER) |
| 48 |
unsigned long r = 0; |
| 49 |
_BitScanForward64(&r, HEDLEY_STATIC_CAST(uint64_t, pg.value)); |
| 50 |
return (op.value >> r) & 1; |
| 51 |
#else |
| 52 |
return (op.value >> __builtin_ctzll(HEDLEY_STATIC_CAST(unsigned long long, pg.value))) & 1; |
| 53 |
#endif |
| 54 |
#else |
| 55 |
for (int i = 0 ; i < HEDLEY_STATIC_CAST(int, simde_svcntb()) ; i++) { |
| 56 |
if (pg.values_i8[i]) { |
| 57 |
return !!op.values_i8[i]; |
| 58 |
} |
| 59 |
} |
| 60 |
|
| 61 |
return 0; |
| 62 |
#endif |
| 63 |
} |
| 64 |
#if defined(SIMDE_ARM_SVE_ENABLE_NATIVE_ALIASES) |
| 65 |
#undef simde_svptest_first |
| 66 |
#define svptest_first(pg, op) simde_svptest_first(pg, op) |
| 67 |
#endif |
| 68 |
|
| 69 |
HEDLEY_DIAGNOSTIC_POP |
| 70 |
|
| 71 |
#endif /* SIMDE_ARM_SVE_PTEST_H */ |