Added Agner's asmlib (#87)

This commit is contained in:
theAsmodai 2016-12-24 15:09:50 +03:00 committed by s1lentq
parent 14fb7f7756
commit e0ee615183
9 changed files with 231 additions and 17 deletions

View File

@ -130,6 +130,8 @@ void setupToolchain(NativeBinarySpec b)
cfg.linkerOptions.randomizedBaseAddress = false
cfg.linkerOptions.baseAddress = '0x4970000'
}
cfg.projectLibpath(project, '/lib')
cfg.extraLibs 'libacof32.lib'
}
else if (cfg instanceof GccToolchainConfig)
{
@ -153,7 +155,8 @@ void setupToolchain(NativeBinarySpec b)
cfg.linkerOptions.args '-no-opt-class-analysis'
cfg.compilerOptions.args '-Qoption,cpp,--treat_func_as_string_literal_cpp', '-g0', '-fno-rtti'
cfg.extraLibs 'dl', 'm', 'stdc++'
cfg.projectLibpath(project, '/lib/linux32')
cfg.extraLibs 'dl', 'm', 'stdc++', 'aelf32'
}
if (mpLib && GradleCppUtils.windows && !unitTestExecutable) {

View File

@ -106,24 +106,61 @@ inline T& operator&= (T& a, T b) { return (T&)((type&)a &= (type)b); }
template<class T, class type=typename std::underlying_type<T>::type>
inline T& operator^= (T& a, T b) { return (T&)((type&)a ^= (type)b); }
inline double M_sqrt(int value) {
return sqrt(value);
}
inline float M_sqrt(float value) {
return _mm_cvtss_f32(_mm_sqrt_ss(_mm_load_ss(&value)));
}
inline double M_sqrt(double value) {
double ret;
auto v = _mm_load_sd(&value);
_mm_store_sd(&ret, _mm_sqrt_sd(v, v));
return ret;
return _mm_cvtsd_f64(_mm_sqrt_sd(v, v));
}
template<typename T>
inline double M_sqrt(T value) {
return sqrt(value);
}
inline float M_min(float a, float b) {
return _mm_cvtss_f32(_mm_min_ss(_mm_load_ss(&a), _mm_load_ss(&b)));
}
inline double M_min(double a, double b) {
return _mm_cvtsd_f64(_mm_min_sd(_mm_load_sd(&a), _mm_load_sd(&b)));
}
template<typename T>
inline T M_min(T a, T b) {
return min(a, b);
}
inline float M_max(float a, float b) {
return _mm_cvtss_f32(_mm_max_ss(_mm_load_ss(&a), _mm_load_ss(&b)));
}
inline double M_max(double a, double b) {
return _mm_cvtsd_f64(_mm_max_sd(_mm_load_sd(&a), _mm_load_sd(&b)));
}
template<typename T>
inline T M_max(T a, T b) {
return max(a, b);
}
inline float M_clamp(float a, float min, float max) {
return _mm_cvtss_f32(_mm_min_ss(_mm_max_ss(_mm_load_ss(&a), _mm_load_ss(&min)), _mm_load_ss(&max)));
}
inline double M_clamp(double a, double min, double max) {
return _mm_cvtsd_f64(_mm_min_sd(_mm_max_sd(_mm_load_sd(&a), _mm_load_sd(&min)), _mm_load_sd(&max)));
}
template<typename T>
inline T M_clamp(T a, T min, T max) {
return clamp(a, min, max);
}
template<class T>
inline void SWAP(T &first, T &second)
{
inline void SWAP(T &first, T &second) {
T temp = first;
first = second;
second = temp;

BIN
regamedll/lib/libacof32.lib Normal file

Binary file not shown.

Binary file not shown.

View File

@ -1075,6 +1075,7 @@
<ClInclude Include="..\pm_shared\pm_movevars.h" />
<ClInclude Include="..\pm_shared\pm_shared.h" />
<ClInclude Include="..\public\archtypes.h" />
<ClInclude Include="..\public\asmlib.h" />
<ClInclude Include="..\public\basetypes.h" />
<ClInclude Include="..\public\commonmacros.h" />
<ClInclude Include="..\public\FileSystem.h" />

View File

@ -1127,6 +1127,9 @@
<ClInclude Include="..\dlls\mapinfo.h">
<Filter>dlls</Filter>
</ClInclude>
<ClInclude Include="..\public\asmlib.h">
<Filter>public</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="..\linux\appversion.sh">

123
regamedll/public/asmlib.h Normal file
View File

@ -0,0 +1,123 @@
/*************************** asmlib.h ***************************************
* Author: Agner Fog
* Date created: 2003-12-12
* Last modified: 2013-10-04
* Project: asmlib.zip
* Source URL: www.agner.org/optimize
*
* Description:
* Header file for the asmlib function library.
* This library is available in many versions for different platforms.
* See asmlib-instructions.pdf for details.
*
* (c) Copyright 2003 - 2013 by Agner Fog.
* GNU General Public License http://www.gnu.org/licenses/gpl.html
*****************************************************************************/
#ifndef ASMLIB_H
#define ASMLIB_H
/***********************************************************************
Define compiler-specific types and directives
***********************************************************************/
// Define type size_t
#ifndef _SIZE_T_DEFINED
#include "stddef.h"
#endif
// Define integer types with known size: int32_t, uint32_t, int64_t, uint64_t.
// If this doesn't work then insert compiler-specific definitions here:
#if defined(__GNUC__) || (defined(_MSC_VER) && _MSC_VER >= 1600)
// Compilers supporting C99 or C++0x have stdint.h defining these integer types
#include <stdint.h>
#define INT64_SUPPORTED // Remove this if the compiler doesn't support 64-bit integers
#elif defined(_MSC_VER)
// Older Microsoft compilers have their own definition
typedef signed __int16 int16_t;
typedef unsigned __int16 uint16_t;
typedef signed __int32 int32_t;
typedef unsigned __int32 uint32_t;
typedef signed __int64 int64_t;
typedef unsigned __int64 uint64_t;
#define INT64_SUPPORTED // Remove this if the compiler doesn't support 64-bit integers
#else
// This works with most compilers
typedef signed short int int16_t;
typedef unsigned short int uint16_t;
typedef signed int int32_t;
typedef unsigned int uint32_t;
typedef long long int64_t;
typedef unsigned long long uint64_t;
#define INT64_SUPPORTED // Remove this if the compiler doesn't support 64-bit integers
#endif
// Turn off name mangling
#ifdef __cplusplus
extern "C" {
#endif
/***********************************************************************
Function prototypes, memory and string functions
***********************************************************************/
void * A_memcpy (void * dest, const void * src, size_t count); // Copy count bytes from src to dest
void * A_memmove(void * dest, const void * src, size_t count); // Same as memcpy, allows overlap between src and dest
void * A_memset (void * dest, int c, size_t count); // Set count bytes in dest to (char)c
int A_memcmp (const void * buf1, const void * buf2, size_t num); // Compares two blocks of memory
size_t GetMemcpyCacheLimit(void); // Data blocks bigger than this will be copied uncached by memcpy and memmove
void SetMemcpyCacheLimit(size_t); // Change limit in GetMemcpyCacheLimit
size_t GetMemsetCacheLimit(void); // Data blocks bigger than this will be stored uncached by memset
void SetMemsetCacheLimit(size_t); // Change limit in GetMemsetCacheLimit
char * A_strcat (char * dest, const char * src); // Concatenate strings dest and src. Store result in dest
char * A_strcpy (char * dest, const char * src); // Copy string src to dest
size_t A_strlen (const char * str); // Get length of zero-terminated string
int A_strcmp (const char * a, const char * b); // Compare strings. Case sensitive
int A_stricmp (const char *string1, const char *string2); // Compare strings. Case insensitive for A-Z only
char * A_strstr (char * haystack, const char * needle); // Search for substring in string
void A_strtolower(char * string); // Convert string to lower case for A-Z only
void A_strtoupper(char * string); // Convert string to upper case for a-z only
size_t A_substring(char * dest, const char * source, size_t pos, size_t len); // Copy a substring for source into dest
size_t A_strspn (const char * str, const char * set); // Find span of characters that belong to set
size_t A_strcspn(const char * str, const char * set); // Find span of characters that don't belong to set
size_t strCountInSet(const char * str, const char * set); // Count characters that belong to set
size_t strcount_UTF8(const char * str); // Counts the number of characters in a UTF-8 encoded string
/***********************************************************************
Function prototypes, miscellaneous functions
***********************************************************************/
uint32_t A_popcount(uint32_t x); // Count 1-bits in 32-bit integer
int RoundD (double x); // Round to nearest or even
int RoundF (float x); // Round to nearest or even
int InstructionSet(void); // Tell which instruction set is supported
char * ProcessorName(void); // ASCIIZ text describing microprocessor
void CpuType(int * vendor, int * family, int * model); // Get CPU vendor, family and model
size_t DataCacheSize(int level); // Get size of data cache
void A_DebugBreak(void); // Makes a debug breakpoint
#ifdef INT64_SUPPORTED
uint64_t ReadTSC(void); // Read microprocessor internal clock (64 bits)
#else
uint32_t ReadTSC(void); // Read microprocessor internal clock (only 32 bits supported by compiler)
#endif
void cpuid_ex (int abcd[4], int eax, int ecx); // call CPUID instruction
static inline void cpuid_abcd (int abcd[4], int eax) {
cpuid_ex(abcd, eax, 0);}
#ifdef __cplusplus
} // end of extern "C"
// Define overloaded versions if compiling as C++
static inline int Round (double x) { // Overload name Round
return RoundD(x);}
static inline int Round (float x) { // Overload name Round
return RoundF(x);}
static inline const char * A_strstr(const char * haystack, const char * needle) {
return A_strstr((char*)haystack, needle);} // Overload A_strstr with const char * version
#endif // __cplusplus
#endif // ASMLIB_H

View File

@ -41,6 +41,57 @@
#define Q_alloca alloca
#define Q_free free
#ifdef REGAMEDLL_FIXES
#define Q_sqrt M_sqrt
#define Q_min M_min
#define Q_max M_max
#define Q_clamp M_clamp
#define Q_access _access
#define Q_close _close
#define Q_write _write
#define Q_memset A_memset
#define Q_memcpy A_memcpy
#define Q_memcmp A_memcmp
#define Q_memmove A_memmove
#define Q_strlen A_strlen
#define Q_strcpy A_strcpy
#define Q_strncpy strncpy
#define Q_strrchr A_strrchr
#define Q_strcat A_strcat
#define Q_strncat strncat
#define Q_strcmp A_strcmp
#define Q_strncmp strncmp
#define Q_sscanf sscanf
#define Q_strdup _strdup
#define Q_stricmp _stricmp
#define Q_strnicmp _strnicmp
#define Q_strstr A_strstr
#define Q_strchr strchr
#define Q_strrchr A_strrchr
#define Q_strlwr A_strtolower
#define Q_sprintf sprintf
#define Q_snprintf _snprintf
#define Q_atoi atoi
#define Q_atof atof
#define Q_toupper toupper
#define Q_vsnprintf _vsnprintf
#define Q_vsnwprintf _vsnwprintf
#define Q_abs abs
#define Q_fabs fabs
#define Q_tan tan
#define Q_atan atan
#define Q_atan2 atan2
#define Q_acos acos
#define Q_cos cos
#define Q_sin sin
#define Q_pow pow
#define Q_fmod fmod
#define Q_fopen fopen
#define Q_fwrite fwrite
#define Q_fprintf fprintf
#define Q_fclose fclose
#else
#define Q_sqrt sqrt
#define Q_min min
#define Q_max max
#define Q_clamp clamp
@ -49,8 +100,9 @@
#define Q_write _write
#define Q_memset memset
#define Q_memcpy memcpy
#define Q_strlen strlen
#define Q_memcmp memcmp
#define Q_memmove memmove
#define Q_strlen strlen
#define Q_strcpy strcpy
#define Q_strncpy strncpy
#define Q_strrchr strrchr
@ -71,7 +123,6 @@
#define Q_atoi atoi
#define Q_atof atof
#define Q_toupper toupper
#define Q_memmove memmove
#define Q_vsnprintf _vsnprintf
#define Q_vsnwprintf _vsnwprintf
#define Q_abs abs
@ -88,9 +139,4 @@
#define Q_fwrite fwrite
#define Q_fprintf fprintf
#define Q_fclose fclose
#ifdef REGAMEDLL_FIXES
#define Q_sqrt M_sqrt
#else
#define Q_sqrt sqrt
#endif

View File

@ -6,6 +6,7 @@
#include "basetypes.h"
#include "archtypes.h"
#include "sse_mathfun.h"
#include "asmlib.h"
#include "MemPool.h"
#include "engine.h"