Skip to content

Commit 8f16ca0

Browse files
authored
Merge pull request #28 from r-a-sattarov/master
E2K: added initial support of MCST Elbrus 2000 CPU architecture
2 parents 6180b3c + 4ab5ddf commit 8f16ca0

File tree

23 files changed

+336
-60
lines changed

23 files changed

+336
-60
lines changed

CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@ add_subdirectory(vgui2/vgui_controls)
4040
add_subdirectory(vgui2/vgui_surfacelib)
4141
add_subdirectory(soundsystem/lowlevel)
4242
add_subdirectory(thirdparty/quickhull)
43-
add_subdirectory(thirdparty/gperftools-2.8.1) #We include this version instead of distro-pkg because there is a false positive in ASAN
43+
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "e2k")
44+
# We use sustem gperftools-2.5 on OS Elbrus
45+
else()
46+
add_subdirectory(thirdparty/gperftools-2.8.1) #We include this version instead of distro-pkg because there is a false positive in ASAN
47+
endif()
4448
add_subdirectory(thirdparty/protobuf-2.5.0/cmake)
4549
add_subdirectory(utils/bzip2)
4650
add_subdirectory(utils/jpeglib)

cmake/source_exe_posix_base.cmake

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@ if( LINUXALL AND NOT DEDICATED )
4242
if( LINUX64 )
4343
#target_link_libraries(${OUTBINNAME} "${SRCDIR}/thirdparty/gperftools-2.0/.libs/x86_64/libtcmalloc_minimal.so")# [$LINUX64]
4444
#SWITCH BACK to a new version in /thirdparty. Unfortunately ASAN detects a false positive in this library and we need to edit the source.
45-
target_link_libraries(${OUTBINNAME} tcmalloc_minimal)
45+
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "e2k")
46+
target_link_libraries(${OUTBINNAME} "/usr/lib/libtcmalloc_minimal.so.4.3.0") # use sustem gperftools-2.5 on OS Elbrus
47+
else()
48+
target_link_libraries(${OUTBINNAME} tcmalloc_minimal)
49+
endif()
4650
else()
4751
#$ImpLibExternal "$SRCDIR/thirdparty/gperftools-2.0/.libs/tcmalloc_minimal" [$LINUX32]
4852
message(FATAL_ERROR "linux32 not supported in cmake")

cmake/source_posix_base.cmake

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,12 @@ else()
4343
message("^^ Not Setting -O for Target")
4444
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${LINUX_DEBUG_FLAGS} ${LINUX_FLAGS_COMMON}")
4545
else()
46-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 ${LINUX_DEBUG_FLAGS} ${LINUX_FLAGS_COMMON}")
46+
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "e2k")
47+
# O3 on mcst-lcc approximately equal to O2 at gcc X86/ARM
48+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 ${LINUX_FLAGS_COMMON}")
49+
else()
50+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 ${LINUX_DEBUG_FLAGS} ${LINUX_FLAGS_COMMON}")
51+
endif()
4752
endif()
4853
endif()
4954
endif()

engine/engine_inc.cmake

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,11 @@ if( LINUXALL AND (NOT DEDICATED) )
5050
target_link_libraries(${OUTBINNAME} SDL2 rt openal)
5151
endif()
5252
if( LINUXALL )
53-
target_link_options(${OUTBINNAME} PRIVATE -L/usr/lib32 -L/usr/lib)
53+
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "e2k")
54+
target_link_options(${OUTBINNAME} PRIVATE -L/usr/lib)
55+
else()
56+
target_link_options(${OUTBINNAME} PRIVATE -L/usr/lib32 -L/usr/lib)
57+
endif()
5458
target_compile_options(${OUTBINNAME} PRIVATE -Wno-narrowing -fpermissive) #downgrade some errors to fix build
5559
endif()
5660

ivp/ivp_collision/ivp_compact_ledge.hxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ const IVP_Compact_Triangle *IVP_Compact_Edge::get_triangle() const
255255
//lwss - x64 fixes ( original is x86 )
256256
#if defined(__i386__)
257257
return (IVP_Compact_Triangle *)(((unsigned int)this) & 0xfffffff0);
258-
#elif defined( __x86_64__ )
258+
#elif defined(__x86_64__) || defined(__e2k__)
259259
return (IVP_Compact_Triangle *)(((unsigned long int)this) & 0xFFFFFFFFFFFFFFF0);
260260
#else
261261
#error fix this for your platform

materialsystem/shadersystem.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,14 +315,14 @@ void CShaderSystem::LoadAllShaderDLLs( )
315315
#if defined( _PS3 ) || defined( _OSX )
316316
LoadShaderDLL( "stdshader_dx9" DLL_EXT_STRING );
317317
#else // _PS3 || _OSX
318-
318+
#ifndef __e2k__ // Don't load stdshader_dbg module on Elbrus (prevent "Module stdshader_dbg failed to load! Error: ((null))" message)
319319
// 360 has the the debug shaders in its dx9 dll
320320
if ( IsPC() || !IsX360() )
321321
{
322322
// Always need the debug shaders
323323
LoadShaderDLL( "stdshader_dbg" );
324324
}
325-
325+
#endif
326326
// Load up standard shader DLLs...
327327
int dxSupportLevel = HardwareConfig()->GetMaxDXSupportLevel();
328328
Assert( dxSupportLevel >= 60 );

mathlib/sse.cpp

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,54 @@ void __cdecl _SSE_VectorMA( const float *start, float scale, const float *direc
8080
// SSE implementations of optimized routines:
8181
//-----------------------------------------------------------------------------
8282

83+
#ifdef POSIX
84+
const __m128 f3 = _mm_set_ss(3.0f); // 3 as SSE value
85+
const __m128 f05 = _mm_set_ss(0.5f); // 0.5 as SSE value
86+
#endif
87+
88+
float _SSE_RSqrtAccurate(float a)
89+
{
90+
91+
#ifdef _WIN32
92+
float x;
93+
float half = 0.5f;
94+
float three = 3.f;
95+
96+
__asm
97+
{
98+
movss xmm3, a;
99+
movss xmm1, half;
100+
movss xmm2, three;
101+
rsqrtss xmm0, xmm3;
102+
103+
mulss xmm3, xmm0;
104+
mulss xmm1, xmm0;
105+
mulss xmm3, xmm0;
106+
subss xmm2, xmm3;
107+
mulss xmm1, xmm2;
108+
109+
movss x, xmm1;
110+
}
83111

112+
return x;
113+
#elif POSIX
114+
__m128 xx = _mm_load_ss( &a );
115+
__m128 xr = _mm_rsqrt_ss( xx );
116+
__m128 xt;
117+
118+
xt = _mm_mul_ss( xr, xr );
119+
xt = _mm_mul_ss( xt, xx );
120+
xt = _mm_sub_ss( f3, xt );
121+
xt = _mm_mul_ss( xt, f05 );
122+
xr = _mm_mul_ss( xr, xt );
123+
124+
_mm_store_ss( &a, xr );
125+
return a;
126+
#else
127+
#error "Not Implemented"
128+
#endif
129+
130+
}
84131

85132
float FASTCALL _SSE_VectorNormalize (Vector& vec)
86133
{
@@ -91,7 +138,7 @@ float FASTCALL _SSE_VectorNormalize (Vector& vec)
91138
#ifdef _WIN32
92139
__declspec(align(16)) float result[4];
93140
#elif POSIX
94-
float result[4] __attribute__((aligned(16)));
141+
float result[4] __attribute__((aligned(16)));
95142
#endif
96143

97144
float *v = &vec[0];
@@ -133,7 +180,11 @@ float FASTCALL _SSE_VectorNormalize (Vector& vec)
133180
r[ 0 ] = vec.x * recipSqrt;
134181
r[ 1 ] = vec.y * recipSqrt;
135182
r[ 2 ] = vec.z * recipSqrt;
136-
183+
#elif defined __e2k__
184+
float rsqrt = _SSE_RSqrtAccurate( v[0] * v[0] + v[1] * v[1] + v[2] * v[2] );
185+
r[0] = v[0] * rsqrt;
186+
r[1] = v[1] * rsqrt;
187+
r[2] = v[2] * rsqrt;
137188
#elif POSIX
138189
__asm__ __volatile__(
139190
#ifdef ALIGNED_VECTOR
@@ -451,7 +502,7 @@ float FastCos( float x )
451502
movss x, xmm0
452503

453504
}
454-
#elif defined( _WIN64 )
505+
#elif defined( _WIN64 ) || defined( __e2k__ )
455506
return cosf( x );
456507
#elif POSIX
457508

public/glmgr/glmgrbasics.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,11 +178,13 @@ float GLMKnobToggle( char *knobname );
178178
#if GLMDEBUG
179179
inline void GLMDebugger( void )
180180
{
181+
#ifndef __e2k__
181182
if (GLMDebugChannelMask() & (1<<eDebugger))
182183
{
183184
asm ( "int $3" );
184185
}
185-
186+
#endif // ifndef __e2k__
187+
186188
if (GLMDebugChannelMask() & (1<<eGLProfiler))
187189
{
188190
// we call an obscure GL function which we know has been breakpointed in the OGLP function list

public/localize/ilocalize.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
// unicode character type
1919
// for more unicode manipulation functions #include <wchar.h>
20-
#if !defined( _WCHAR_T_DEFINED ) && !defined( _PS3 ) && !defined(__clang__)
20+
#if !defined( _WCHAR_T_DEFINED ) && !defined( _PS3 ) && !defined(__clang__) && !defined(__e2k__)
2121
typedef unsigned short wchar_t;
2222
#define _WCHAR_T_DEFINED
2323
#endif

public/materialsystem/imesh.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1324,7 +1324,7 @@ inline void CVertexBuilder::FastVertexSSE( const ModelVertexDX8_t &vertex )
13241324
movntps [edi + 16], xmm1
13251325
movntps [edi + 32], xmm2
13261326
}
1327-
#elif defined(GNUC)
1327+
#elif defined(GNUC) && !defined(__e2k__)
13281328
const void *pRead = &vertex;
13291329
void *pCurrPos = m_pCurrPosition;
13301330
__asm__ __volatile__ (
@@ -1335,7 +1335,7 @@ inline void CVertexBuilder::FastVertexSSE( const ModelVertexDX8_t &vertex )
13351335
"movntps %%xmm0, (%1)\n"
13361336
"movntps %%xmm1, 16(%1)\n"
13371337
"movntps %%xmm2, 32(%1)\n"
1338-
"movntps %%xmm3, 48(%1)\n"
1338+
"movntps %%xmm3, 48(%1)\n"
13391339
:: "r" (pRead), "r" (pCurrPos) : "memory");
13401340
#else
13411341
Error( "Implement CMeshBuilder::FastVertexSSE((dx8)" );

public/mathlib/mathlib.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ void inline SinCos( float radians, float * RESTRICT sine, float * RESTRICT cosin
532532
fstp DWORD PTR [edx]
533533
fstp DWORD PTR [eax]
534534
}
535-
#elif defined( GNUC )
535+
#elif defined( GNUC ) && !defined( __e2k__ )
536536
//lwss - remove 'register' keyword
537537
//register double __cosr, __sinr;
538538
double __cosr, __sinr;
@@ -1682,7 +1682,7 @@ FORCEINLINE int RoundFloatToInt(float f)
16821682
fld f
16831683
fistp nResult
16841684
}
1685-
#elif GNUC
1685+
#elif defined( GNUC ) && !defined( __e2k__ )
16861686
__asm __volatile__ (
16871687
"fistpl %0;": "=m" (nResult): "t" (f) : "st"
16881688
);
@@ -1729,7 +1729,7 @@ FORCEINLINE unsigned char RoundFloatToByte(float f)
17291729
fld f
17301730
fistp nResult
17311731
}
1732-
#elif GNUC
1732+
#elif defined( GNUC ) && !defined( __e2k__ )
17331733
__asm __volatile__ (
17341734
"fistpl %0;": "=m" (nResult): "t" (f) : "st"
17351735
);
@@ -1767,7 +1767,7 @@ FORCEINLINE unsigned long RoundFloatToUnsignedLong(float f)
17671767
return __fctiw( f );
17681768
#endif
17691769
#else // !X360
1770-
1770+
17711771
#if defined( COMPILER_MSVC32 )
17721772
unsigned char nResult[8];
17731773
__asm
@@ -1776,7 +1776,7 @@ FORCEINLINE unsigned long RoundFloatToUnsignedLong(float f)
17761776
fistp qword ptr nResult
17771777
}
17781778
return *((unsigned long*)nResult);
1779-
#elif defined( COMPILER_GCC )
1779+
#elif defined( COMPILER_GCC ) && !defined( __e2k__ )
17801780
unsigned char nResult[8];
17811781
__asm __volatile__ (
17821782
"fistpl %0;": "=m" (nResult): "t" (f) : "st"

public/saverestoretypes.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class CSaveRestoreSegment
6464
const char *StringFromSymbol( int token );
6565

6666
private:
67-
#ifndef _WIN32
67+
#if !defined _WIN32 && !defined __e2k__
6868
unsigned _rotr ( unsigned val, int shift);
6969
#endif
7070
unsigned int HashString( const char *pszToken );
@@ -521,7 +521,7 @@ inline const char *CSaveRestoreSegment::StringFromSymbol( int token )
521521
return "<<illegal>>";
522522
}
523523

524-
#ifndef _WIN32
524+
#if !defined _WIN32 && !defined __e2k__
525525
inline unsigned CSaveRestoreSegment::_rotr ( unsigned val, int shift)
526526
{
527527
register unsigned lobit; /* non-zero means lo bit set */

public/steam/steamtypes.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ typedef unsigned char uint8;
2424
#define POSIX 1
2525
#endif
2626

27-
#if defined(__x86_64__) || defined(_WIN64)
27+
#if defined(__x86_64__) || defined(_WIN64) || defined(__e2k__)
2828
#define X64BITS
2929
#endif
3030

public/tier0/hardware_clock_fast.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
#include "tier0/platform.h"
66

7-
#ifdef GNUC
7+
#if defined GNUC && !defined __e2k__
88
inline int GetHardwareClockFast( void )
99
{
1010
unsigned long long int nRet;
@@ -35,15 +35,18 @@ inline int GetHardwareClockFast()
3535
}
3636
#else
3737

38+
#ifdef __e2k__
39+
#include <x86intrin.h>
40+
#else
3841
#include <intrin.h>
39-
42+
#endif // ifdef __e2k__
4043

4144
inline int GetHardwareClockFast()
4245
{
4346
return __rdtsc();
4447
}
45-
#endif
48+
#endif // ifdef _X360
4649

47-
#endif
50+
#endif // defined GNUC && !defined __e2k__
4851

49-
#endif
52+
#endif // ifndef TIER0_HARDWARE_TIMER

public/tier0/microprofiler.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,11 @@ PLATFORM_INTERFACE int64 GetHardwareClockReliably();
2626
#include <intrin.h> // get __rdtsc
2727
#endif
2828

29+
#ifdef __e2k__
30+
#include <x86intrin.h>
31+
#endif
2932

30-
#if defined(_LINUX) || defined( OSX )
33+
#if (defined(_LINUX) || defined( OSX )) && !defined(__e2k__)
3134
inline unsigned long long GetTimebaseRegister( void )
3235
{
3336
#ifdef PLATFORM_64BITS

public/tier0/platform.h

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@
99
#ifndef PLATFORM_H
1010
#define PLATFORM_H
1111

12-
#if defined(__x86_64__) || defined(_WIN64)
12+
#if defined(__x86_64__) || defined(_WIN64) || defined(__e2k__)
1313
#define PLATFORM_64BITS 1
1414
#endif
1515

16+
#if defined(__e2k__)
17+
#define PLATFORM_E2K 1
18+
#endif
19+
1620
#if defined( LINUX ) && ((__GNUC__ * 100) + __GNUC_MINOR__) >= 406
1721
// based on some Jonathan Wakely macros on the net...
1822
#define GCC_DIAG_STR(s) #s
@@ -1154,7 +1158,7 @@ typedef void * HINSTANCE;
11541158
#endif
11551159
#elif defined( OSX )
11561160
#define DebuggerBreak() if ( Plat_IsInDebugSession() ) asm( "int3" ); else { raise(SIGTRAP); }
1157-
#elif defined( PLATFORM_CYGWIN ) || defined( PLATFORM_POSIX )
1161+
#elif ( defined( PLATFORM_CYGWIN ) || defined( PLATFORM_POSIX ) ) && !defined( __e2k__ )
11581162
#define DebuggerBreak() __asm__( "int $0x3;")
11591163
#else
11601164
#define DebuggerBreak() raise(SIGTRAP)
@@ -1386,7 +1390,7 @@ typedef int socklen_t;
13861390
// Works for PS3
13871391
inline void SetupFPUControlWord()
13881392
{
1389-
#ifdef _PS3
1393+
#if defined ( _PS3 ) || defined ( __e2k__ )
13901394
// TODO: PS3 compiler spits out the following errors:
13911395
// C:/tmp/ccIN0aaa.s: Assembler messages:
13921396
// C:/tmp/ccIN0aaa.s(80): Error: Unrecognized opcode: `fnstcw'
@@ -1829,6 +1833,10 @@ extern "C" unsigned __int64 __rdtsc();
18291833
#pragma intrinsic(__rdtsc)
18301834
#endif
18311835

1836+
#if defined( __e2k__ )
1837+
#include <x86intrin.h> // get __rdtsc
1838+
#endif
1839+
18321840
inline uint64 Plat_Rdtsc()
18331841
{
18341842
#if defined( _X360 )
@@ -1850,6 +1858,8 @@ inline uint64 Plat_Rdtsc()
18501858
uint32 lo, hi;
18511859
__asm__ __volatile__ ( "rdtsc" : "=a" (lo), "=d" (hi));
18521860
return ( ( ( uint64 )hi ) << 32 ) | lo;
1861+
#elif defined( __e2k__ )
1862+
return ( uint64 )__rdtsc();
18531863
#else
18541864
#error
18551865
#endif

0 commit comments

Comments
 (0)