fix cpuid use (apparently it's not appropriate to use in an inlined function)

This commit is contained in:
Arvid Norberg 2015-04-26 18:46:45 +00:00
parent a15bc13392
commit d128d36faa
7 changed files with 18 additions and 53 deletions

View File

@ -19,6 +19,7 @@ set(sources
chained_buffer
choker
close_reason
cpuid
crc32c
create_torrent
disk_buffer_holder

View File

@ -584,6 +584,7 @@ SOURCES =
chained_buffer
choker
close_reason
cpuid
crc32c
create_torrent
disk_buffer_holder

View File

@ -30,7 +30,6 @@ nobase_include_HEADERS = \
config.hpp \
ConvertUTF.h \
copy_ptr.hpp \
cpuid.hpp \
crc32c.hpp \
create_torrent.hpp \
deadline_timer.hpp \
@ -157,15 +156,16 @@ nobase_include_HEADERS = \
tommath_superclass.h \
\
aux_/alert_manager_variadic_emplace.hpp \
aux_/cpuid.hpp \
aux_/disable_warnings_push.hpp \
aux_/disable_warnings_pop.hpp \
aux_/escape_string.hpp \
aux_/merkle.hpp \
aux_/session_call.hpp \
aux_/session_impl.hpp \
aux_/session_settings.hpp \
aux_/session_interface.hpp \
aux_/time.hpp \
aux_/escape_string.hpp \
aux_/disable_warnings_push.hpp \
aux_/disable_warnings_pop.hpp \
aux_/merkle.hpp \
\
extensions/lt_trackers.hpp \
extensions/metadata_transfer.hpp \

View File

@ -34,31 +34,13 @@ POSSIBILITY OF SUCH DAMAGE.
#define TORRENT_CPUID_HPP_INCLUDED
#include "libtorrent/config.hpp"
#include <cstring>
#if defined _MSC_VER && TORRENT_HAS_SSE
#include <intrin.h>
#include <nmmintrin.h>
#endif
namespace libtorrent
namespace libtorrent { namespace aux
{
// internal
inline void cpuid(unsigned int info[4], int type)
{
#if TORRENT_HAS_SSE && defined _MSC_VER
__cpuid((int*)info, type);
#elif TORRENT_HAS_SSE && defined __GNUC__
asm volatile
("cpuid" : "=a" (info[0]), "=b" (info[1]), "=c" (info[2]), "=d" (info[3])
: "a" (type), "c" (0));
#else
// for non-x86 and non-amd64, just return zeroes
std::memset(&info[0], 0, sizeof(unsigned int) * 4);
#endif
}
}
// initialized by static initializers (in cpuid.cpp)
extern bool sse42_support;
extern bool mmx_support;
} }
#endif // TORRENT_CPUID_HPP_INCLUDED

View File

@ -36,7 +36,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/assert.hpp"
#include "libtorrent/config.hpp"
#include "libtorrent/byteswap.hpp"
#include "libtorrent/cpuid.hpp"
#include "libtorrent/aux_/cpuid.hpp"
#include <cstring> // for memset and memcpy
#include <cstdlib> // for malloc, free and realloc
@ -171,9 +171,7 @@ namespace libtorrent
int ret = 0;
const int words = num_words();
#if TORRENT_HAS_SSE
unsigned int cpui[4];
cpuid(cpui, 1);
if (cpui[2] & (1 << 23))
if (aux::mmx_support)
{
for (int i = 0; i < words; ++i)
{

View File

@ -53,6 +53,7 @@ libtorrent_rasterbar_la_SOURCES = \
choker.cpp \
close_reason.cpp \
ConvertUTF.cpp \
cpuid.cpp \
crc32c.cpp \
create_torrent.cpp \
disk_buffer_holder.cpp \

View File

@ -31,8 +31,7 @@ POSSIBILITY OF SUCH DAMAGE.
*/
#include "libtorrent/crc32c.hpp"
#include "libtorrent/cpuid.hpp"
#include "libtorrent/aux_/cpuid.hpp"
#include "libtorrent/aux_/disable_warnings_push.hpp"
#include <boost/crc.hpp>
@ -41,27 +40,10 @@ POSSIBILITY OF SUCH DAMAGE.
namespace libtorrent
{
namespace {
bool supports_sse42()
{
#if TORRENT_HAS_SSE
unsigned int cpui[4];
cpuid(cpui, 1);
return cpui[2] & (1 << 20);
#else
return false;
#endif
}
bool sse42_support = supports_sse42();
} // anonymous namespace
boost::uint32_t crc32c_32(boost::uint32_t v)
{
#if TORRENT_HAS_SSE
if (sse42_support)
if (aux::sse42_support)
{
boost::uint32_t ret = 0xffffffff;
#ifdef __GNUC__
@ -86,7 +68,7 @@ namespace libtorrent
boost::uint32_t crc32c(boost::uint64_t const* buf, int num_words)
{
#if TORRENT_HAS_SSE
if (sse42_support)
if (aux::sse42_support)
{
#if defined _M_AMD64 || defined __x86_64__ \
|| defined __x86_64 || defined _M_X64 || defined __amd64__