root/core/blatant_old_msvc_compiler_hacks.hpp

/* [<][>][^][v][top][bottom][index][help] */

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. max
  2. max
  3. min
  4. min

   1 #ifndef LIBJMMCG_CORE_BLATANT_OLD_MSVC_COMPILER_HACKS_HPP
   2 #define LIBJMMCG_CORE_BLATANT_OLD_MSVC_COMPILER_HACKS_HPP
   3 
   4 /******************************************************************************
   5 ** $Header: svn+ssh://jmmcg@svn.code.sf.net/p/libjmmcg/code/trunk/libjmmcg/core/blatant_old_msvc_compiler_hacks.hpp 2314 2018-08-30 22:09:01Z jmmcg $
   6 **
   7 ** Copyright (C) 2002 by J.M.McGuiness, coder@hussar.me.uk
   8 **
   9 ** This library is free software; you can redistribute it and/or
  10 ** modify it under the terms of the GNU Lesser General Public
  11 ** License as published by the Free Software Foundation; either
  12 ** version 2.1 of the License, or (at your option) any later version.
  13 **
  14 ** This library is distributed in the hope that it will be useful,
  15 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  16 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17 ** Lesser General Public License for more details.
  18 **
  19 ** You should have received a copy of the GNU Lesser General Public
  20 ** License along with this library; if not, write to the Free Software
  21 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  22 */
  23 
  24 #include "config.h"
  25 
  26 #include <new>
  27 
  28 /**
  29         \mainpage
  30         \section Overview
  31         See <a href="http://libjmmcg.sf.net/">the web site</a> for an overview and previously-given presentations regarding the library.
  32 */
  33 
  34 /** \file
  35         This file contains some of the more blatant, nasty, evil hacks that need
  36         to be done to work-around the venerable MSVC++ v6.0 sp5 compiler's "features".
  37         Note that this compiler should really be referred to as "cl.exe" v12.00.8168.
  38 */
  39 
  40 /// Work arounds for the older MSVC++ compilers being very broken regarding the use of various keywords.
  41 #define JMMCG_MSVC_STDCALL_HACK __stdcall
  42 #define JMMCG_MSVC_FASTCALL_HACK __fastcall
  43 
  44 #ifndef _CRT_SECURE_NO_WARNINGS
  45 #       define _CRT_SECURE_NO_WARNINGS
  46 #endif
  47 #ifndef _WIN32_WINNT
  48 #       define _WIN32_WINNT 0x0501
  49 #endif
  50 #ifndef WINVER
  51 #       define WINVER _WIN32_WINNT
  52 #endif
  53 
  54 #if defined(_MSC_VER) && (_MSC_VER < 1300)
  55 #       define __FUNCTION__ _T("Message to M$: you should have defined __FUNCTION__!")
  56 /// Hacks to get round MS macros in "windef.h" that conflict with the STL definitions of min() and max().
  57 #       undef min
  58 #       undef max
  59 #       ifndef JMMCG_MS_MINMAX_HACK
  60 #               define JMMCG_MS_MINMAX_HACK
  61 #               define NOMINMAX
  62                 namespace std {
  63                         template<class _Ty> inline const _Ty& __fastcall
  64                         max(const _Ty& _X, const _Ty& _Y) {
  65                                 return _cpp_max(_X, _Y);
  66                         }
  67                         template<class _Ty, class _Pr> inline const _Ty& __fastcall
  68                         max(const _Ty& _X, const _Ty& _Y, _Pr _P) {
  69                                 return _cpp_max(_X, _Y, _P);
  70                         }
  71 
  72                         template<class _Ty> inline const _Ty& __fastcall
  73                         min(const _Ty& _X, const _Ty& _Y) {
  74                                 return _cpp_min(_X, _Y);
  75                         }
  76                         template<class _Ty, class _Pr> inline const _Ty& __fastcall
  77                         min(const _Ty& _X, const _Ty& _Y, _Pr _P) {
  78                                 return _cpp_min(_X, _Y, _P);
  79                         }
  80                 }
  81 #       endif
  82 #       if (_MSC_VER < 1300)
  83 #               undef JMMCG_MSVC_FASTCALL_HACK
  84 #               define JMMCG_MSVC_FASTCALL_HACK
  85 #               undef JMMCG_MSVC_STDCALL_HACK
  86 #               define JMMCG_MSVC_STDCALL_HACK
  87 #       endif
  88 #endif
  89 
  90 #ifdef _MSC_VER
  91 /// Get rid of stupid MSVC warnings.
  92 #       pragma warning(disable:4033)    ///< Conversion from OMF to COFF warning.
  93 #       pragma warning(disable:4256)    ///< constructor for class with virtual bases has '...'; calls may not be compatible with older versions of Visual C++
  94 #       pragma warning(disable:4290)    ///< C++ Exception Specification ignored.
  95 #       pragma warning(disable:4503)    ///< Decorated name length exceeded, name was truncated.
  96 #       pragma warning(disable:4710)    ///< function '...' not inlined
  97 #       pragma warning(disable:4711)    ///< function '...' selected for automatic inline expansion
  98 #       pragma warning(disable:4725)    ///< Pentium fdiv warning.
  99 #       pragma warning(disable:4786)    ///< "identifier was truncated to '255' characters in the debug information", (from MSVC++ v5.0 help).
 100 #       pragma warning(disable:4800)    ///< forcing value to bool 'true' or 'false' (performance warning).
 101 
 102 #       define _CRT_SECURE_NO_WARNINGS  ///< This function or variable may be unsafe.
 103 #       define _SCL_SECURE_NO_WARNINGS  ///< Function call with parameters that may be unsafe.
 104 
 105 #       define __PRETTY_FUNCTION__ __FUNCSIG__
 106 
 107         typedef __int16 int16_t;
 108 
 109 #       if defined(_MT) && !defined(_REENTRANT)
 110 #               define _REETRANT
 111 #       endif
 112         
 113 #       define LIKELY(x) (x)
 114 #       define UNLIKELY(x) (x)
 115 #       define FORCE_INLINE
 116 #       define NEVER_INLINE
 117 
 118 #       define POPCOUNTLL(x) __popcnt64(x)
 119 
 120         /**
 121                 Include "intrin.h" for this intrinsic. See <a href="https://msdn.microsoft.com/en-us/library/hh977023.aspx">MSDN Intrinsics</a> for more information.
 122 
 123                 \param addr     Prefetch a cache line from the address addr for reading.
 124                 \param locality Not used.
 125         */
 126 #       define PREFETCH_READ(addr, locality) _m_prefetch(reinterpret_cast<void *>(addr))
 127 
 128         /**
 129                 Include "intrin.h" for this intrinsic. See <a href="https://msdn.microsoft.com/en-us/library/hh977023.aspx">MSDN Intrinsics</a> for more information.
 130 
 131                 \param addr     Prefetch a cache line from the address addr for writing.
 132                 \param locality Not used.
 133         */
 134 #       define PREFETCH_WRITE(addr, locality) _m_prefetchw(reinterpret_cast<void *>(addr))
 135 
 136 #else
 137 // Ensure that other 32-bit compilers can safely ignore unnecessary requirement in MSVC++-world for declaring functions with efficient calling conventions.
 138 
 139 /// This is the general calling convention: use it anywhere.
 140 #       ifndef __fastcall
 141 #               define __fastcall __attribute__((regparm(3)))
 142 #       endif
 143 
 144 /// Calling convention necessary for constructors/destructors in MSVC.
 145 #       ifndef __stdcall
 146 #               define __stdcall __attribute__((regparm(3)))
 147 #       endif
 148 
 149 /// In MSVC++, the standard, slowest calling convention, used only for "main()" and other required places, e.g. var-arg functions.
 150 #       ifndef __cdecl
 151 #               define __cdecl __attribute__((cdecl))
 152 #       endif
 153 
 154 #       define __CLR_OR_THIS_CALL __attribute__((regparm(3)))
 155 
 156 #       define __declspec(dllexport)
 157 
 158 /**
 159         GCC has "quirks" in it's static branch-prediction: <a href="https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66573">Branch prediction in gcc</a>. Use these to ensure that if-statements are generated reliably.
 160 */
 161 #       define LIKELY(x) __builtin_expect(!!(x), 1)
 162 #       define UNLIKELY(x) __builtin_expect(!!(x), 0)
 163 // Note that this can cause the compiler to take 100x longer...! BEWARE!
 164 #       define REALLY_FORCE_INLINE  __attribute__((always_inline))
 165 #       define FORCE_INLINE
 166 #       define NEVER_INLINE __attribute__((noinline))
 167 
 168 /// Yup: MSVC++ doesn't support "long long" properly.... Better use the MSVC++-special types.
 169         typedef long long __int64;
 170         typedef unsigned long long __uint64;
 171 
 172 #       define POPCOUNTLL(x) __builtin_popcountll(x)
 173 
 174         /**
 175                 See <a href="https://gcc.gnu.org/onlinedocs/gcc-3.3.6/gcc/Other-Builtins.html">GCC Intrinsics</a> and <a href="http://tomoyo.osdn.jp/cgi-bin/lxr/source/include/linux/prefetch.h">Prefetching strides</a> for more information.
 176 
 177                 \param addr     Prefetch a cache line from the address addr for reading. See the kernel marco L1_CACHE_BYTES for an approximation.
 178                 \param locality A compile-time integer constant in [1 .. 3], default 3. 1 means low locality, 3 highest.
 179         */
 180 #       define PREFETCH_READ(addr, locality) __builtin_prefetch(reinterpret_cast<void const *>(addr), 0, (locality))
 181 
 182         /**
 183                 See <a href="https://gcc.gnu.org/onlinedocs/gcc-3.3.6/gcc/Other-Builtins.html">GCC Intrinsics</a> and <a href="http://tomoyo.osdn.jp/cgi-bin/lxr/source/include/linux/prefetch.h">Prefetching strides</a> for more information.
 184 
 185                 \param addr     Prefetch a cache line from the address addr for writing. See the kernel marco L1_CACHE_BYTES for an approximation.
 186                 \param locality A compile-time integer constant in [1 .. 3], default 3. 1 means low locality, 3 highest.
 187         */
 188 #       define PREFETCH_WRITE(addr, locality) __builtin_prefetch(reinterpret_cast<void const *>(addr), 1, (locality))
 189 
 190 #endif
 191 
 192 #define ALIGN_TO_L1_CACHE alignas(64 /* TODO std::hardware_constructive_interference_size */)
 193 
 194 #endif

/* [<][>][^][v][top][bottom][index][help] */