Skip to content

Commit

Permalink
move black magic to separate file
Browse files Browse the repository at this point in the history
  • Loading branch information
w17 committed Aug 30, 2017
1 parent 5129860 commit e8460c3
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 27 deletions.
4 changes: 4 additions & 0 deletions far/changelog
@@ -1,3 +1,7 @@
w17 30.08.2017 13:19:19 +0300 - build 5016

1. Уточнение 5015

w17 30.08.2017 12:21:12 +0300 - build 5015

1. Plerolad %FARHOME%\legacy\lua51.dll if x86 CPU doesn't support SSE2.
Expand Down
3 changes: 2 additions & 1 deletion far/far.vcxproj
Expand Up @@ -256,6 +256,7 @@ cl /nologo /c /Fo"$(IntDir)%(Filename)_c++.testobj" /TP api_test.c
<ClCompile Include="keyboard.cpp" />
<ClCompile Include="language.cpp" />
<ClCompile Include="lasterror.cpp" />
<ClCompile Include="legacy_cpu_check.cpp" />
<ClCompile Include="locale.cpp" />
<ClCompile Include="lockscrn.cpp" />
<ClCompile Include="macro.cpp" />
Expand Down Expand Up @@ -436,7 +437,7 @@ cl /nologo /c /Fo"$(IntDir)%(Filename)_c++.testobj" /TP api_test.c
<ClInclude Include="keys.hpp" />
<ClInclude Include="KnownGuids.hpp" />
<ClInclude Include="language.hpp" />
<ClInclude Include="lasterror.hpp" />
<ClInclude Include="legacy_cpu_check.hpp" />
<ClInclude Include="locale.hpp" />
<ClInclude Include="lockscrn.hpp" />
<ClInclude Include="macro.hpp" />
Expand Down
6 changes: 6 additions & 0 deletions far/far.vcxproj.filters
Expand Up @@ -221,6 +221,9 @@
<ClCompile Include="lasterror.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="legacy_cpu_check.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="locale.cpp">
<Filter>Source Files</Filter>
</ClCompile>
Expand Down Expand Up @@ -655,6 +658,9 @@
<ClInclude Include="lasterror.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="legacy_cpu_check.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="locale.hpp">
<Filter>Header Files</Filter>
</ClInclude>
Expand Down
28 changes: 28 additions & 0 deletions far/legacy_cpu_check.cpp
@@ -0,0 +1,28 @@
#include "headers.hpp"
#pragma hdrstop

#include "legacy_cpu_check.hpp"

bool IsLegacyCPU()
{
#if defined(_WIN32) && !defined(_WIN64) && (defined(_MSC_VER) || defined(__GNUC__))
bool have_sse2 = false;
int info[4] = { 0, 0, 0, 0 };
#ifdef _MSC_VER
#include <intrin.h>
__cpuidex(info, 0, 0);
if (info[0] >= 1) {
__cpuidex(info, 1, 0);
#else
#include <cpuid.h>
__cpuid_count(0, 0, info[0], info[1], info[2], info[3]);
if (info[0] >= 1) {
__cpuid_count(1, 0, info[0], info[1], info[2], info[3]);
#endif
have_sse2 = (info[3] & ((int)1 << 26)) != 0;
}
return !have_sse2;
#else
return false;
#endif
}
40 changes: 40 additions & 0 deletions far/legacy_cpu_check.hpp
@@ -0,0 +1,40 @@
#ifndef LEGACY_CPU_CHECK_HPP_38B388C1_AF11_4F09_9643_074418E35699
#define LEGACY_CPU_CHECK_HPP_38B388C1_AF11_4F09_9643_074418E35699
#pragma once

/*
legacy_cpu_check.hpp
Ïðîâåðêà ïîääåðæêè SSE2 äëÿ x86
*/
/*
Copyright © 1996 Eugene Roshal
Copyright © 2000 Far Group
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the authors may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

bool IsLegacyCPU();

#endif // LASTERROR_HPP_1C20B3B0_E43C_4DCC_9729_DFD883E99DD3
29 changes: 4 additions & 25 deletions far/main.cpp
Expand Up @@ -70,6 +70,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "cvtname.hpp"
#include "drivemix.hpp"
#include "new_handler.hpp"
#include "legacy_cpu_check.hpp"

global *Global = nullptr;

Expand Down Expand Up @@ -149,33 +150,11 @@ static int MainProcess(
ppanel = Global->Opt->LocalProfilePath;
}

#if defined(_WIN32) && !defined(_WIN64) && (defined(_MSC_VER) || defined(__GNUC__))
// actual lua51.dll uses SSE2 instructions on x86.
// so we have to preload legacy lua51.dll if x86 CPU doesn't support SSE2
if (IsLegacyCPU())
{
bool have_sse2 = false;
int info[4] = { 0, 0, 0, 0 };
#ifdef _MSC_VER
#include <intrin.h>
__cpuidex(info, 0, 0);
if (info[0] >= 1) {
__cpuidex(info, 1, 0);
#else
#include <cpuid.h>
__cpuid_count(0, 0, info[0], info[1], info[2], info[3]);
if (info[0] >= 1) {
__cpuid_count(1, 0, info[0], info[1], info[2], info[3]);
#endif
have_sse2 = (info[3] & ((int)1 << 26)) != 0;
}

if (!have_sse2)
{
auto legay_path = Global->g_strFarPath + L"\\legacy\\lua51.dll"; // %FARHOME%\legacy\lua51.dll
LoadLibraryW(legay_path.data());
}
auto legacy_path = Global->g_strFarPath + L"\\legacy\\lua51.dll"; // %FARHOME%\legacy\lua51.dll
LoadLibraryW(legacy_path.data());
}
#endif

if (!ename.empty() || !vname.empty())
{
Expand Down
1 change: 1 addition & 0 deletions far/makefile_gcc
Expand Up @@ -91,6 +91,7 @@ SRCS = \
keyboard.cpp \
language.cpp \
lasterror.cpp \
legacy_cpu_check.cpp \
locale.cpp \
lockscrn.cpp \
macro.cpp \
Expand Down
1 change: 1 addition & 0 deletions far/makefile_vc
Expand Up @@ -175,6 +175,7 @@ LINK_OBJS = \
"$(INTDIR)\keyboard.obj" \
"$(INTDIR)\language.obj" \
"$(INTDIR)\lasterror.obj" \
"$(INTDIR)\legacy_cpu_check.obj" \
"$(INTDIR)\locale.obj" \
"$(INTDIR)\lockscrn.obj" \
"$(INTDIR)\macro.obj" \
Expand Down
2 changes: 1 addition & 1 deletion far/vbuild.m4
@@ -1 +1 @@
m4_define(BUILD,5015)m4_dnl
m4_define(BUILD,5016)m4_dnl

0 comments on commit e8460c3

Please sign in to comment.