File: arm_arch_queries.c

package info (click to toggle)
putty 0.78-2%2Bdeb12u2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 13,964 kB
  • sloc: ansic: 137,777; python: 7,775; perl: 1,798; makefile: 133; sh: 111
file content (105 lines) | stat: -rw-r--r-- 2,926 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*
 * Unix implementation of the OS query functions that detect Arm
 * architecture extensions.
 */

#include "putty.h"
#include "ssh.h"

#include "utils/arm_arch_queries.h"

#if defined __arm__ || defined __aarch64__

bool platform_aes_neon_available(void)
{
#if defined HWCAP_AES
    return getauxval(AT_HWCAP) & HWCAP_AES;
#elif defined HWCAP2_AES
    return getauxval(AT_HWCAP2) & HWCAP2_AES;
#elif defined __APPLE__
    SysctlResult res = test_sysctl_flag("hw.optional.arm.FEAT_AES");
    /* Older M1 macOS didn't provide this flag, but as far as I know
     * implemented the crypto extension anyway, so treat 'feature
     * missing' as 'implemented' */
    return res != SYSCTL_OFF;
#else
    return false;
#endif
}

bool platform_pmull_neon_available(void)
{
#if defined HWCAP_PMULL
    return getauxval(AT_HWCAP) & HWCAP_PMULL;
#elif defined HWCAP2_PMULL
    return getauxval(AT_HWCAP2) & HWCAP2_PMULL;
#elif defined __APPLE__
    SysctlResult res = test_sysctl_flag("hw.optional.arm.FEAT_PMULL");
    /* As above, treat 'missing' as enabled */
    return res != SYSCTL_OFF;
#else
    return false;
#endif
}

bool platform_sha256_neon_available(void)
{
#if defined HWCAP_SHA2
    return getauxval(AT_HWCAP) & HWCAP_SHA2;
#elif defined HWCAP2_SHA2
    return getauxval(AT_HWCAP2) & HWCAP2_SHA2;
#elif defined __APPLE__
    SysctlResult res = test_sysctl_flag("hw.optional.arm.FEAT_SHA256");
    /* As above, treat 'missing' as enabled */
    return res != SYSCTL_OFF;
#else
    return false;
#endif
}

bool platform_sha1_neon_available(void)
{
#if defined HWCAP_SHA1
    return getauxval(AT_HWCAP) & HWCAP_SHA1;
#elif defined HWCAP2_SHA1
    return getauxval(AT_HWCAP2) & HWCAP2_SHA1;
#elif defined __APPLE__
    SysctlResult res = test_sysctl_flag("hw.optional.arm.FEAT_SHA1");
    /* As above, treat 'missing' as enabled */
    return res != SYSCTL_OFF;
#else
    return false;
#endif
}

bool platform_sha512_neon_available(void)
{
#if defined HWCAP_SHA512
    return getauxval(AT_HWCAP) & HWCAP_SHA512;
#elif defined HWCAP2_SHA512
    return getauxval(AT_HWCAP2) & HWCAP2_SHA512;
#elif defined __APPLE__
    /* There are two sysctl flags for this, apparently invented at
     * different times. Try both, falling back to the older one. */
    SysctlResult res = test_sysctl_flag("hw.optional.arm.FEAT_SHA512");
    if (res != SYSCTL_MISSING)
        return res == SYSCTL_ON;

    res = test_sysctl_flag("hw.optional.armv8_2_sha512");
    return res == SYSCTL_ON;
#else
    return false;
#endif
}

#else /* defined __arm__ || defined __aarch64__ */

/*
 * Include _something_ in this file to prevent an annoying compiler
 * warning, and to avoid having to condition out this file in
 * CMakeLists. It's in a library, so this variable shouldn't end up in
 * any actual program, because nothing will refer to it.
 */
const int arm_arch_queries_dummy_variable = 0;

#endif /* defined __arm__ || defined __aarch64__ */