summaryrefslogtreecommitdiff
path: root/src/pal/src/arch/amd64/processor.cpp
blob: 298d685c98ddc5249c6169fb0ceb26dd77780069 (plain)
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
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

/*++



Module Name:

    processor.cpp

Abstract:

    Implementation of processor related functions for the Intel x86/x64
    platforms. These functions are processor dependent.



--*/

#include "pal/palinternal.h"

/*++
Function:
YieldProcessor

The YieldProcessor function signals to the processor to give resources
to threads that are waiting for them. This macro is only effective on
processors that support technology allowing multiple threads running
on a single processor, such as Intel's Hyper-Threading technology.

--*/
void
PALAPI
YieldProcessor(
    VOID)
{
    __asm__ __volatile__ (
        "rep\n"
        "nop"
    );
}

/*++
Function:
XmmYmmStateSupport

Check if OS has enabled both XMM and YMM state support

Return value:
1 if XMM and YMM are enabled, 0 otherwise
--*/
extern "C" unsigned int XmmYmmStateSupport()
{
    unsigned int eax;
    __asm("  mov $1, %%eax\n" \
          "  cpuid\n" \
          "  xor %%eax, %%eax\n" \
          "  and $0x18000000, %%ecx\n" /* check for xsave feature set and that it is enabled by the OS */ \
          "  cmp $0x18000000, %%ecx\n" \
          "  jne end\n" \
          "  xor %%ecx, %%ecx\n" \
          "  xgetbv\n" \
          "end:\n" \
        : "=a"(eax) /* output in eax */ \
        : /* no inputs */ \
        : "eax", "ebx", "ecx", "edx" /* registers that are clobbered */
      );
    // Check OS has enabled both XMM and YMM state support
    return ((eax & 0x06) == 0x06) ? 1 : 0;
}