Skip to content

Commit

Permalink
E2K: added initial support of MCST Elbrus 2000 CPU architecture
Browse files Browse the repository at this point in the history
  • Loading branch information
r-a-sattarov committed Oct 14, 2023
1 parent 5a4d0b7 commit ac078e2
Show file tree
Hide file tree
Showing 16 changed files with 69 additions and 51 deletions.
2 changes: 2 additions & 0 deletions engine/baseclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -706,11 +706,13 @@ bool CBaseClient::SendServerInfo( void )

serverinfo.WriteToBuffer( msg );

#ifndef SWDS
if ( IsX360() && serverinfo.m_nMaxClients > 1 )
{
Msg( "Telling clients to connect" );
g_pMatchmaking->TellClientsToConnect();
}
#endif

// send first tick
m_nSignonTick = m_Server->m_nTickCount;
Expand Down
4 changes: 4 additions & 0 deletions engine/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,13 @@ COM_ExplainDisconnection
*/
void COM_ExplainDisconnection( bool bPrint, const char *fmt, ... )
{
#ifndef SWDS
if ( IsX360() )
{
g_pMatchmaking->SessionNotification( SESSION_NOTIFY_LOST_SERVER );
}
else
#endif
{
va_list argptr;
char string[1024];
Expand Down Expand Up @@ -146,11 +148,13 @@ COM_ExtendedExplainDisconnection
*/
void COM_ExtendedExplainDisconnection( bool bPrint, const char *fmt, ... )
{
#ifndef SWDS
if ( IsX360() )
{
g_pMatchmaking->SessionNotification( SESSION_NOTIFY_LOST_SERVER );
}
else
#endif
{
va_list argptr;
char string[1024];
Expand Down
13 changes: 7 additions & 6 deletions engine/l_studio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4360,13 +4360,14 @@ ModelInstanceHandle_t CModelRender::CreateInstance( IClientRenderable *pRenderab
// builds out color meshes or loads disk colors, now at load/create time
RecomputeStaticLighting( handle );
}
else
if ( r_decalstaticprops.GetBool() && instance.m_LightCacheHandle )
{
instance.m_AmbientLightingState = *(LightcacheGetStatic( *pCache, NULL, LIGHTCACHEFLAGS_STATIC ));
}
#ifndef SWDS
else if ( r_decalstaticprops.GetBool() && instance.m_LightCacheHandle )
{
instance.m_AmbientLightingState = *(LightcacheGetStatic( *pCache, NULL, LIGHTCACHEFLAGS_STATIC ));
}
#endif
}

return handle;
}

Expand Down
2 changes: 1 addition & 1 deletion mathlib/mathlib_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3281,7 +3281,7 @@ void MathLib_Init( float gamma, float texGamma, float brightness, int overbright
{
s_bSSEEnabled = true;

#ifndef PLATFORM_WINDOWS_PC64
#if !defined(PLATFORM_WINDOWS_PC64) && (defined(__i386__) || defined(__amd64__))
// These are not yet available.
// Select the SSE specific routines if available
pfVectorNormalize = _VectorNormalize;
Expand Down
7 changes: 4 additions & 3 deletions mathlib/sse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@
#include "tier0/dbg.h"
#include "mathlib/mathlib.h"
#include "mathlib/vector.h"
#if defined(__arm__) || defined(__aarch64__)
#include "sse2neon.h"
#endif

#if !defined(__arm__) && !defined(__aarch64__) && !defined(__e2k__)

#include "sse.h"

Expand Down Expand Up @@ -1127,3 +1126,5 @@ vec_t DotProduct (const vec_t *a, const vec_t *c)
*/

#endif // COMPILER_MSVC64

#endif
4 changes: 2 additions & 2 deletions public/materialsystem/imesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -1152,7 +1152,7 @@ inline void CVertexBuilder::FastAdvanceNVertices( int n )
//-----------------------------------------------------------------------------
inline void CVertexBuilder::FastVertex( const ModelVertexDX7_t &vertex )
{
#if defined(__arm__) || defined(__aarch64__) || defined(PLATFORM_WINDOWS_PC64)
#if defined(__arm__) || defined(__aarch64__) || defined(__e2k__) || defined(PLATFORM_WINDOWS_PC64)
FastVertexSSE( vertex );
#else
Assert( m_CompressionType == VERTEX_COMPRESSION_NONE ); // FIXME: support compressed verts if needed
Expand Down Expand Up @@ -1354,7 +1354,7 @@ inline void CVertexBuilder::Fast4VerticesSSE(

inline void CVertexBuilder::FastVertex( const ModelVertexDX8_t &vertex )
{
#if defined(__arm__) || defined(__aarch64__) || defined(PLATFORM_WINDOWS_PC64)
#if defined(__arm__) || defined(__aarch64__) || defined(__e2k__) || defined(PLATFORM_WINDOWS_PC64)
FastVertexSSE( vertex );
#else
Assert( m_CompressionType == VERTEX_COMPRESSION_NONE ); // FIXME: support compressed verts if needed
Expand Down
8 changes: 4 additions & 4 deletions public/mathlib/mathlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -1201,8 +1201,8 @@ FORCEINLINE int RoundFloatToInt(float f)
};
flResult = __fctiw( f );
return pResult[1];
#elif defined (__arm__) || defined (__aarch64__)
return (int)(f + 0.5f);
#elif defined(__arm__) || defined(__aarch64__) || defined(__e2k__)
return (int)(f + 0.5f);
#else
#error Unknown architecture
#endif
Expand Down Expand Up @@ -1233,8 +1233,8 @@ FORCEINLINE unsigned long RoundFloatToUnsignedLong(float f)
Assert( pIntResult[1] >= 0 );
return pResult[1];
#else // !X360
#if defined(__arm__) || defined(__aarch64__)
return (unsigned long)(f + 0.5f);
#if defined(__arm__) || defined(__aarch64__) || defined(__e2k__)
return (unsigned long)(f + 0.5f);
#elif defined( PLATFORM_WINDOWS_PC64 )
uint nRet = ( uint ) f;
if ( nRet & 1 )
Expand Down
8 changes: 2 additions & 6 deletions public/steam/steamtypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ typedef unsigned char uint8;
#define POSIX 1
#endif

#if defined(__x86_64__) || defined(_WIN64) || defined(__aarch64__)
#define X64BITS
#endif

// Make sure VALVE_BIG_ENDIAN gets set on PS3, may already be set previously in Valve internal code.
#if !defined(VALVE_BIG_ENDIAN) && defined(_PS3)
#define VALVE_BIG_ENDIAN
Expand All @@ -48,7 +44,7 @@ typedef unsigned __int64 uint64;
typedef int64 lint64;
typedef uint64 ulint64;

#ifdef X64BITS
#ifdef PLATFORM_64BITS
typedef __int64 intp; // intp is an integer that can accomodate a pointer
typedef unsigned __int64 uintp; // (ie, sizeof(intp) >= sizeof(int) && sizeof(intp) >= sizeof(void *)
#else
Expand All @@ -74,7 +70,7 @@ typedef unsigned long long uint64;
typedef long int lint64;
typedef unsigned long int ulint64;

#ifdef X64BITS
#ifdef PLATFORM_64BITS
typedef long long intp;
typedef unsigned long long uintp;
#else
Expand Down
13 changes: 9 additions & 4 deletions public/tier0/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,19 @@
#ifndef PLATFORM_H
#define PLATFORM_H

#if defined(__x86_64__) || defined(_WIN64) || defined(__aarch64__)
#if defined(__x86_64__) || defined(_WIN64) || defined(__aarch64__) || defined(__e2k__)
#define PLATFORM_64BITS 1
#endif

#if defined(__GCC__) || defined(__GNUC__)
#define COMPILER_GCC 1
#endif

#if defined(__LCC__) && defined(__MCST__)
// MCST LCC (eLbrus Compiler Collection)
#define COMPILER_MCST_LCC 1
#endif

#ifdef __GLIBC__
#define PLATFORM_GLIBC 1
#endif
Expand Down Expand Up @@ -898,7 +903,7 @@ static FORCEINLINE double fsel(double fComparand, double fValGE, double fLT)

#endif
#endif
#elif defined (__arm__) || defined (__aarch64__)
#elif defined(__arm__) || defined(__aarch64__) || defined(__e2k__)
inline void SetupFPUControlWord() {}
#else
inline void SetupFPUControlWord()
Expand Down Expand Up @@ -1069,7 +1074,7 @@ inline T QWordSwapC( T dw )
// The typically used methods.
//-------------------------------------

#if (defined(__i386__) || defined(__amd64__) || defined(__arm__) || defined(__aarch64__)) && !defined(VALVE_LITTLE_ENDIAN)
#if (defined(__i386__) || defined(__amd64__) || defined(__arm__) || defined(__aarch64__) || defined(__e2k__)) && !defined(VALVE_LITTLE_ENDIAN)
#define VALVE_LITTLE_ENDIAN 1
#endif

Expand Down Expand Up @@ -1235,7 +1240,7 @@ PLATFORM_INTERFACE struct tm * Plat_localtime( const time_t *timep, struct tm *

inline uint64 Plat_Rdtsc()
{
#if (defined( __arm__ ) || defined( __aarch64__ )) && defined (POSIX)
#if (defined( __arm__ ) || defined( __aarch64__ ) || defined(__e2k__)) && defined (POSIX)
struct timespec t;
clock_gettime( CLOCK_REALTIME, &t);
return t.tv_sec * 1000000000ULL + t.tv_nsec;
Expand Down
8 changes: 7 additions & 1 deletion scripts/waifulib/compiler_optimizations.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
}
'''

VALID_BUILD_TYPES = ['fastnative', 'fast', 'release', 'debug', 'nooptimize', 'sanitize', 'none']
VALID_BUILD_TYPES = ['native','fastnative', 'fast', 'release', 'debug', 'nooptimize', 'sanitize', 'none']

LINKFLAGS = {
'common': {
Expand Down Expand Up @@ -65,6 +65,12 @@
'clang': ['-O2', '-march=native'],
'default': ['-O3']
},
'native': {
'msvc': ['/O2', '/Oy', '/MT'],
'gcc': ['-O2', '-march=native'],
'clang': ['-O2', '-march=native'],
'default': ['-O3']
},
'release': {
'msvc': ['/O2', '/MT'],
'owcc': ['-O3', '-fomit-leaf-frame-pointer', '-fomit-frame-pointer', '-finline-functions', '-finline-limit=512'],
Expand Down
22 changes: 17 additions & 5 deletions tier0/cpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const tchar* GetProcessorVendorId();

static bool cpuid(uint32 function, uint32& out_eax, uint32& out_ebx, uint32& out_ecx, uint32& out_edx)
{
#if defined (__arm__) || defined (__aarch64__) || defined( _X360 )
#if defined(__arm__) || defined(__aarch64__) || defined(__e2k__) || defined(_X360)
return false;
#elif defined(GNUC)

Expand Down Expand Up @@ -337,6 +337,8 @@ const tchar* GetProcessorVendorId()
return "PPC";
#elif defined ( __arm__ )
return "ARM";
#elif defined (__e2k__)
return "MCST";
#else
uint32 unused, VendorIDRegisters[3];

Expand Down Expand Up @@ -372,10 +374,12 @@ const tchar* GetProcessorArchName()
return "amd64";
#elif defined(__i386__) || defined(_X86_) || defined(_M_IX86)
return "i386";
#elif defined __aarch64__
return "aarch64";
#elif defined __arm__ || defined _M_ARM
return "arm";
#elif defined(__aarch64__)
return "aarch64";
#elif defined(__arm__) || defined(_M_ARM)
return "arm";
#elif defined(__e2k__)
return "e2k";
#else
#error "Unknown architecture"
#endif
Expand Down Expand Up @@ -528,6 +532,13 @@ const CPUInformation* GetCPUInformation()
pi.m_nPhysicalProcessors = 3;
pi.m_nLogicalProcessors = 6;
#elif defined(_LINUX)
#if defined(__e2k__) // MCST Elbrus 2000
// e2k CPU don't have "core id" and "physical id" in "/proc/cpuinfo" (but have "processor")
// and don't have Hyper-Threading (HT) technology
// used sysconf() to count CPU cores
pi.m_nLogicalProcessors = sysconf( _SC_NPROCESSORS_CONF ); // _SC_NPROCESSORS_ONLN may not be reliable on ARM/Android
pi.m_nPhysicalProcessors = pi.m_nLogicalProcessors; // hack for CPU without Hyper-Threading (HT) technology
#else
// TODO: poll /dev/cpuinfo when we have some benefits from multithreading
FILE *fpCpuInfo = fopen( "/proc/cpuinfo", "r" );
if ( fpCpuInfo )
Expand Down Expand Up @@ -584,6 +595,7 @@ const CPUInformation* GetCPUInformation()
pi.m_nLogicalProcessors = 1;
Assert( !"couldn't read cpu information from /proc/cpuinfo" );
}
#endif // if e2k
#elif defined(OSX) || defined(PLATFORM_BSD)
int mib[2], num_cpu = 1;
size_t len;
Expand Down
5 changes: 2 additions & 3 deletions tier0/cpu_posix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ uint64 CalculateCPUFreq()
}
}

#if !defined(__arm__) && !defined(__aarch64__)
#if defined(__i386__) || defined(_M_IX86)
// fallback mechanism to calculate when failed
// Compute the period. Loop until we get 3 consecutive periods that
// are the same to within a small error. The error is chosen
Expand Down Expand Up @@ -178,7 +178,6 @@ uint64 CalculateCPUFreq()
#else
// ARM hard-coded frequency
return (uint64)2000000000;
#endif // if !ARM
#endif // if i386
#endif // if APPLE
}

2 changes: 1 addition & 1 deletion tier1/processor_detect_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ bool CheckMMXTechnology(void) { return false; }
bool CheckSSETechnology(void) { return false; }
bool CheckSSE2Technology(void) { return false; }
bool Check3DNowTechnology(void) { return false; }
#elif defined (__arm__) || defined (__aarch64__)
#elif defined(__arm__) || defined(__aarch64__) || defined(__e2k__)
bool CheckMMXTechnology(void) { return false; }
bool CheckSSETechnology(void) { return false; }
bool CheckSSE2Technology(void) { return false; }
Expand Down
15 changes: 1 addition & 14 deletions tier1/reliabletimer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,20 +82,7 @@ int64 CReliableTimer::GetPerformanceCountNow()
CycleCount.Sample();
return CycleCount.GetLongCycles();
}
#elif defined( _PS3 )
// use handy macro to grab tb
uint64 ulNow;
SYS_TIMEBASE_GET( ulNow );
return ulNow;
#elif (defined( __arm__ ) || defined( __aarch64__ )) && defined (POSIX)
struct timespec ts;
clock_gettime(CLOCK_REALTIME, &ts);
return ts.tv_sec * 1000000000ULL + ts.tv_nsec;
#else
uint64 un64;
__asm__ __volatile__ (
"rdtsc\n\t"
: "=A" (un64) );
return (int64)un64;
return (int64)Plat_Rdtsc();
#endif
}
4 changes: 3 additions & 1 deletion vtf/vtf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -951,7 +951,8 @@ static bool ReadHeaderFromBufferPastBaseHeader( CUtlBuffer &buf, VTFFileHeader_t

bool CVTFTexture::ReadHeader( CUtlBuffer &buf, VTFFileHeader_t &header )
{
if ( IsX360() && SetupByteSwap( buf ) )
#ifdef _X360
if ( SetupByteSwap( buf ) )
{
VTFFileBaseHeader_t baseHeader;
m_Swap.SwapFieldsToTargetEndian( &baseHeader, (VTFFileBaseHeader_t*)buf.PeekGet() );
Expand Down Expand Up @@ -979,6 +980,7 @@ bool CVTFTexture::ReadHeader( CUtlBuffer &buf, VTFFileHeader_t &header )
}
}
}
#endif

memset( &header, 0, sizeof(VTFFileHeader_t) );
buf.Get( &header, sizeof(VTFFileBaseHeader_t) );
Expand Down
3 changes: 3 additions & 0 deletions wscript
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,9 @@ def configure(conf):
if conf.env.DEST_OS == 'freebsd':
linkflags += ['-lexecinfo']

if conf.env.DEST_OS != 'darwin':
linkflags += ['-latomic']

if conf.env.DEST_OS != 'win32':
cflags += flags
linkflags += flags
Expand Down

0 comments on commit ac078e2

Please sign in to comment.