Add CPUID functions for runtime dispatch
This commit is contained in:
@@ -63,6 +63,7 @@ set(RFB_SOURCES
|
|||||||
VNCServerST.cxx
|
VNCServerST.cxx
|
||||||
ZRLEEncoder.cxx
|
ZRLEEncoder.cxx
|
||||||
ZRLEDecoder.cxx
|
ZRLEDecoder.cxx
|
||||||
|
cpuid.cxx
|
||||||
encodings.cxx
|
encodings.cxx
|
||||||
util.cxx
|
util.cxx
|
||||||
xxhash.c)
|
xxhash.c)
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
#include <omp.h>
|
#include <omp.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include <rfb/cpuid.h>
|
||||||
#include <rfb/EncCache.h>
|
#include <rfb/EncCache.h>
|
||||||
#include <rfb/EncodeManager.h>
|
#include <rfb/EncodeManager.h>
|
||||||
#include <rfb/Encoder.h>
|
#include <rfb/Encoder.h>
|
||||||
|
|||||||
@@ -53,6 +53,7 @@
|
|||||||
|
|
||||||
#include <network/GetAPI.h>
|
#include <network/GetAPI.h>
|
||||||
|
|
||||||
|
#include <rfb/cpuid.h>
|
||||||
#include <rfb/ComparingUpdateTracker.h>
|
#include <rfb/ComparingUpdateTracker.h>
|
||||||
#include <rfb/KeyRemapper.h>
|
#include <rfb/KeyRemapper.h>
|
||||||
#include <rfb/ListConnInfo.h>
|
#include <rfb/ListConnInfo.h>
|
||||||
@@ -132,6 +133,9 @@ VNCServerST::VNCServerST(const char* name_, SDesktop* desktop_)
|
|||||||
{
|
{
|
||||||
lastUserInputTime = lastDisconnectTime = time(0);
|
lastUserInputTime = lastDisconnectTime = time(0);
|
||||||
slog.debug("creating single-threaded server %s", name.buf);
|
slog.debug("creating single-threaded server %s", name.buf);
|
||||||
|
slog.info("CPU capability: SSE2 %s, AVX512f %s",
|
||||||
|
supportsSSE2() ? "yes" : "no",
|
||||||
|
supportsAVX512f() ? "yes" : "no");
|
||||||
|
|
||||||
DLPRegion.enabled = DLPRegion.percents = false;
|
DLPRegion.enabled = DLPRegion.percents = false;
|
||||||
|
|
||||||
|
|||||||
70
common/rfb/cpuid.cxx
Normal file
70
common/rfb/cpuid.cxx
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
/* Copyright (C) 2021 Kasm Web
|
||||||
|
*
|
||||||
|
* This is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This software is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this software; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||||
|
* USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
static uint32_t cpuid[4] = { 0 };
|
||||||
|
static uint32_t extcpuid[4] = { 0 };
|
||||||
|
|
||||||
|
static void getcpuid() {
|
||||||
|
if (cpuid[0])
|
||||||
|
return;
|
||||||
|
|
||||||
|
#if defined(__x86_64__) || defined(__i386__)
|
||||||
|
uint32_t eax, ecx = 0;
|
||||||
|
|
||||||
|
eax = 1; // normal feature bits
|
||||||
|
|
||||||
|
__asm__ __volatile__(
|
||||||
|
"cpuid\n\t"
|
||||||
|
: "=a"(cpuid[0]), "=b"(cpuid[1]), "=c"(cpuid[2]), "=d"(cpuid[3])
|
||||||
|
: "0"(eax), "2"(ecx)
|
||||||
|
);
|
||||||
|
|
||||||
|
eax = 7; // ext feature bits
|
||||||
|
ecx = 0;
|
||||||
|
|
||||||
|
__asm__ __volatile__(
|
||||||
|
"cpuid\n\t"
|
||||||
|
: "=a"(extcpuid[0]), "=b"(extcpuid[1]), "=c"(extcpuid[2]), "=d"(extcpuid[3])
|
||||||
|
: "0"(eax), "2"(ecx)
|
||||||
|
);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace rfb {
|
||||||
|
|
||||||
|
bool supportsSSE2() {
|
||||||
|
getcpuid();
|
||||||
|
#if defined(__x86_64__) || defined(__i386__)
|
||||||
|
#define bit_SSE2 (1 << 26)
|
||||||
|
return cpuid[3] & bit_SSE2;
|
||||||
|
#endif
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool supportsAVX512f() {
|
||||||
|
getcpuid();
|
||||||
|
#if defined(__x86_64__) || defined(__i386__)
|
||||||
|
#define bit_AVX512f (1 << 16)
|
||||||
|
return extcpuid[1] & bit_AVX512f;
|
||||||
|
#endif
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}; // namespace rfb
|
||||||
28
common/rfb/cpuid.h
Normal file
28
common/rfb/cpuid.h
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
/* Copyright (C) 2021 Kasm Web
|
||||||
|
*
|
||||||
|
* This is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This software is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this software; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||||
|
* USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __RFB_CPUID_H__
|
||||||
|
#define __RFB_CPUID_H__
|
||||||
|
|
||||||
|
namespace rfb {
|
||||||
|
|
||||||
|
bool supportsSSE2();
|
||||||
|
bool supportsAVX512f();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
Reference in New Issue
Block a user