Version 6.1.4.1, tag libreoffice-6.1.4.1
[LibreOffice.git] / tools / source / misc / cpuid.cxx
blobee5093ce18928429c62ef6d74740582c7bdc5ca3
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 */
11 #include <tools/cpuid.hxx>
12 #include <cstdint>
14 namespace tools
16 namespace cpuid
19 namespace
21 #if defined(_MSC_VER)
22 #include <intrin.h>
23 void getCpuId(uint32_t array[4])
25 __cpuid(reinterpret_cast<int*>(array), 1);
27 #else
28 #if (defined(__i386__) || defined(__x86_64__))
29 #include <cpuid.h>
30 void getCpuId(uint32_t array[4])
32 __get_cpuid(1, array + 0, array + 1, array + 2, array + 3);
34 #else
35 void getCpuId(uint32_t array[4])
37 array[0] = array[1] = array[2] = array[3] = 0;
39 #endif
40 #endif
43 #if defined(LO_SSE2_AVAILABLE)
45 bool hasSSE2()
47 uint32_t cpuInfoArray[] = {0, 0, 0, 0};
48 getCpuId(cpuInfoArray);
49 return (cpuInfoArray[3] & (1 << 26)) != 0;
52 #else
54 bool hasSSE2() { return false; }
56 #endif
58 bool hasHyperThreading()
60 uint32_t cpuInfoArray[] = {0, 0, 0, 0};
61 getCpuId(cpuInfoArray);
62 return (cpuInfoArray[3] & (1 << 28)) != 0;
69 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */