Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / arch / intel.c
1 /*
2  * Ceph - scalable distributed file system
3  *
4  * Copyright (C) 2013,2014 Inktank Storage, Inc.
5  * Copyright (C) 2014 Cloudwatt <libre.licensing@cloudwatt.com>
6  *
7  * Author: Loic Dachary <loic@dachary.org>
8  *
9  *  This library is free software; you can redistribute it and/or
10  *  modify it under the terms of the GNU Lesser General Public
11  *  License as published by the Free Software Foundation; either
12  *  version 2.1 of the License, or (at your option) any later version.
13  * 
14  */
15 #include <stdio.h>
16 #include "arch/probe.h"
17
18 /* flags we export */
19 int ceph_arch_intel_pclmul = 0;
20 int ceph_arch_intel_sse42 = 0;
21 int ceph_arch_intel_sse41 = 0;
22 int ceph_arch_intel_ssse3 = 0;
23 int ceph_arch_intel_sse3 = 0;
24 int ceph_arch_intel_sse2 = 0;
25 int ceph_arch_intel_aesni = 0;
26
27 #ifdef __x86_64__
28 #include <cpuid.h>
29
30 /* http://en.wikipedia.org/wiki/CPUID#EAX.3D1:_Processor_Info_and_Feature_Bits */
31
32 #define CPUID_PCLMUL    (1 << 1)
33 #define CPUID_SSE42     (1 << 20)
34 #define CPUID_SSE41     (1 << 19)
35 #define CPUID_SSSE3     (1 << 9)
36 #define CPUID_SSE3      (1)
37 #define CPUID_SSE2      (1 << 26)
38 #define CPUID_AESNI (1 << 25)
39
40 int ceph_arch_intel_probe(void)
41 {
42         /* i know how to check this on x86_64... */
43         unsigned int eax, ebx, ecx = 0, edx = 0;
44         if (!__get_cpuid(1, &eax, &ebx, &ecx, &edx)) {
45           return 1;
46         }
47         if ((ecx & CPUID_PCLMUL) != 0) {
48                 ceph_arch_intel_pclmul = 1;
49         }
50         if ((ecx & CPUID_SSE42) != 0) {
51                 ceph_arch_intel_sse42 = 1;
52         }
53         if ((ecx & CPUID_SSE41) != 0) {
54                 ceph_arch_intel_sse41 = 1;
55         }
56         if ((ecx & CPUID_SSSE3) != 0) {
57                 ceph_arch_intel_ssse3 = 1;
58         }
59         if ((ecx & CPUID_SSE3) != 0) {
60                 ceph_arch_intel_sse3 = 1;
61         }
62         if ((edx & CPUID_SSE2) != 0) {
63                 ceph_arch_intel_sse2 = 1;
64         }
65   if ((ecx & CPUID_AESNI) != 0) {
66           ceph_arch_intel_aesni = 1;
67   }
68
69         return 0;
70 }
71
72 #else // __x86_64__
73
74 int ceph_arch_intel_probe(void)
75 {
76         /* no features */
77         return 0;
78 }
79
80 #endif // __x86_64__