Debian Codegraph @

crt/aws-c-common/source/arch/intel/asm/cpuid.c

raw symbols SCIP
1 /**
2 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 * SPDX-License-Identifier: Apache-2.0.
4 */
5
6 #include <aws/common/cpuid.h>
7
8 void aws_run_cpuid(uint32_t eax, uint32_t ecx, uint32_t *abcd) {
9 uint32_t ebx = 0;
10 uint32_t edx = 0;
11
12 #if defined(__i386__) && defined(__PIC__)
13 /* in case of PIC under 32-bit EBX cannot be clobbered */
14 __asm__ __volatile__("movl %%ebx, %%edi \n\t "
15 "cpuid \n\t "
16 "xchgl %%ebx, %%edi"
17 : "=D"(ebx),
18 #else
19 __asm__ __volatile__("cpuid"
20 : "+b"(ebx),
21 #endif
22 "+a"(eax),
23 "+c"(ecx),
24 "=d"(edx));
25 abcd[0] = eax;
26 abcd[1] = ebx;
27 abcd[2] = ecx;
28 abcd[3] = edx;
29 }
30
31 uint64_t aws_run_xgetbv(uint32_t xcr) {
32 /* NOTE: we could have used the _xgetbv() intrinsic in <immintrin.h>, but it's missing from GCC < 9.0:
33 * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71659 */
34
35 /* xgetbv writes high and low of 64bit value to EDX:EAX */
36 uint32_t xcrhigh;
37 uint32_t xcrlow;
38 __asm__ __volatile__("xgetbv" : "=a"(xcrlow), "=d"(xcrhigh) : "c"(xcr));
39 return (((uint64_t)xcrhigh) << 32) | xcrlow;
40 }