swr: fix build with mingw

Reviewed-by: Jan Zielinski <jan.zielinski@intel.com>
Tested-by: Prodea Alexandru-Liviu <liviuprodea@yahoo.com>
Cc: mesa-stable

closes #3454

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6532>
diff --git a/src/gallium/auxiliary/tessellator/tessellator.cpp b/src/gallium/auxiliary/tessellator/tessellator.cpp
index ac16aab..7452ec6 100644
--- a/src/gallium/auxiliary/tessellator/tessellator.cpp
+++ b/src/gallium/auxiliary/tessellator/tessellator.cpp
@@ -18,9 +18,7 @@
 */
 
 #include "tessellator.hpp"
-#if defined(__MINGW32__) || defined(__MINGW64__)
-#include <cmath>
-#elif defined(_WIN32) || defined(_WIN64)
+#if defined(_MSC_VER)
 #include <math.h> // ceil
 #else
 #include <cmath>
@@ -195,7 +193,7 @@
         if (iShift >= 0)
         {
 //            assert( iShift < 32 );
-#if defined(_WIN32) || defined(_WIN64)
+#if defined(_MSC_VER)
 #pragma warning( suppress : 4293 )
 #endif
             _fxpMaxPosValueFloat -= INT32( 1 ) << iShift;
@@ -217,7 +215,7 @@
         if (iShift >= 0)
         {
 //            assert( iShift < 32 );
-#if defined(_WIN32) || defined(_WIN64)
+#if defined(_MSC_VER)
 #pragma warning( suppress : 4293 )
 #endif
             _fxpMaxPosValueFloat -= INT32( 1 ) << iShift;
diff --git a/src/gallium/drivers/swr/meson.build b/src/gallium/drivers/swr/meson.build
index f8c4ba9..0e6f921 100644
--- a/src/gallium/drivers/swr/meson.build
+++ b/src/gallium/drivers/swr/meson.build
@@ -239,6 +239,7 @@
       version : '0.0.0',
       soversion : host_machine.system() == 'windows' ? '' : '0',
       install : true,
+      name_prefix : host_machine.system() == 'windows' ? '' : 'lib',
     )
   else
     swr_arch_libs += static_library(
@@ -280,6 +281,7 @@
       version : '0.0.0',
       soversion : host_machine.system() == 'windows' ? '' : '0',
       install : true,
+      name_prefix : host_machine.system() == 'windows' ? '' : 'lib',
     )
   else
     swr_arch_libs += static_library(
@@ -326,6 +328,7 @@
       version : '0.0.0',
       soversion : host_machine.system() == 'windows' ? '' : '0',
       install : true,
+      name_prefix : host_machine.system() == 'windows' ? '' : 'lib',
     )
   else
     swr_arch_libs += static_library(
@@ -360,6 +363,7 @@
       version : '0.0.0',
       soversion : host_machine.system() == 'windows' ? '' : '0',
       install : true,
+      name_prefix : host_machine.system() == 'windows' ? '' : 'lib',
     )
   else
     swr_arch_libs += static_library(
diff --git a/src/gallium/drivers/swr/rasterizer/archrast/archrast.cpp b/src/gallium/drivers/swr/rasterizer/archrast/archrast.cpp
index c1d3f2d..bcdc6d0 100644
--- a/src/gallium/drivers/swr/rasterizer/archrast/archrast.cpp
+++ b/src/gallium/drivers/swr/rasterizer/archrast/archrast.cpp
@@ -25,6 +25,8 @@
  * @brief Implementation for archrast.
  *
  ******************************************************************************/
+#include <sys/stat.h>
+
 #include <atomic>
 #include <map>
 
diff --git a/src/gallium/drivers/swr/rasterizer/common/os.cpp b/src/gallium/drivers/swr/rasterizer/common/os.cpp
index aa817d4..a40745f 100644
--- a/src/gallium/drivers/swr/rasterizer/common/os.cpp
+++ b/src/gallium/drivers/swr/rasterizer/common/os.cpp
@@ -34,7 +34,7 @@
 #include <pthread.h>
 #endif // Linux
 
-#if defined(_WIN32)
+#if defined(_MSC_VER)
 static const DWORD MS_VC_EXCEPTION = 0x406D1388;
 
 #pragma pack(push, 8)
@@ -76,7 +76,7 @@
 
 void SWR_API SetCurrentThreadName(const char* pThreadName)
 {
-#if defined(_WIN32)
+#if defined(_MSC_VER)
     // The SetThreadDescription API was brought in version 1607 of Windows 10.
     typedef HRESULT(WINAPI * PFNSetThreadDescription)(HANDLE hThread, PCWSTR lpThreadDescription);
     // The SetThreadDescription API works even if no debugger is attached.
diff --git a/src/gallium/drivers/swr/rasterizer/common/os.h b/src/gallium/drivers/swr/rasterizer/common/os.h
index bda114d..f48ed64 100644
--- a/src/gallium/drivers/swr/rasterizer/common/os.h
+++ b/src/gallium/drivers/swr/rasterizer/common/os.h
@@ -49,7 +49,11 @@
 #undef MemoryFence
 #endif
 
+#if defined(_MSC_VER)
 #define OSALIGN(RWORD, WIDTH) __declspec(align(WIDTH)) RWORD
+#elif defined(__GNUC__)
+#define OSALIGN(RWORD, WIDTH) RWORD __attribute__((aligned(WIDTH)))
+#endif
 
 #if defined(_DEBUG)
 // We compile Debug builds with inline function expansion enabled.  This allows
diff --git a/src/gallium/drivers/swr/rasterizer/common/swr_assert.cpp b/src/gallium/drivers/swr/rasterizer/common/swr_assert.cpp
index 8e874fb..0f53820 100644
--- a/src/gallium/drivers/swr/rasterizer/common/swr_assert.cpp
+++ b/src/gallium/drivers/swr/rasterizer/common/swr_assert.cpp
@@ -30,7 +30,7 @@
 
 #if SWR_ENABLE_ASSERTS || SWR_ENABLE_REL_ASSERTS
 
-#if defined(_WIN32)
+#if defined(_MSC_VER)
 #pragma comment(lib, "user32.lib")
 #endif // _WIN32
 
diff --git a/src/gallium/drivers/swr/rasterizer/common/swr_assert.h b/src/gallium/drivers/swr/rasterizer/common/swr_assert.h
index f6bf83e..cd9854f 100644
--- a/src/gallium/drivers/swr/rasterizer/common/swr_assert.h
+++ b/src/gallium/drivers/swr/rasterizer/common/swr_assert.h
@@ -71,7 +71,7 @@
     while (0)          \
     _SWR_WARN_RESTORE
 
-#if defined(_WIN32)
+#if defined(_MSC_VER)
 #define SWR_ASSUME(e, ...)        \
     _SWR_MACRO_START __assume(e); \
     _SWR_MACRO_END
diff --git a/src/gallium/drivers/swr/rasterizer/core/tessellator.cpp b/src/gallium/drivers/swr/rasterizer/core/tessellator.cpp
index 05a598b..d9f4ddb 100644
--- a/src/gallium/drivers/swr/rasterizer/core/tessellator.cpp
+++ b/src/gallium/drivers/swr/rasterizer/core/tessellator.cpp
@@ -18,7 +18,7 @@
 */
 
 #include "tessellator.hpp"
-#if defined(_WIN32) || defined(_WIN64)
+#if defined(_MSC_VER)
 #include <math.h> // ceil
 #else
 #include <cmath>
@@ -179,7 +179,7 @@
         if (iShift >= 0)
         {
 //            assert( iShift < 32 );
-#if defined(_WIN32) || defined(_WIN64)
+#if defined(_MSC_VER)
 #pragma warning( suppress : 4293 )
 #endif
             _fxpMaxPosValueFloat -= INT32( 1 ) << iShift;
@@ -201,7 +201,7 @@
         if (iShift >= 0)
         {
 //            assert( iShift < 32 );
-#if defined(_WIN32) || defined(_WIN64)
+#if defined(_MSC_VER)
 #pragma warning( suppress : 4293 )
 #endif
             _fxpMaxPosValueFloat -= INT32( 1 ) << iShift;
diff --git a/src/gallium/drivers/swr/rasterizer/core/threads.cpp b/src/gallium/drivers/swr/rasterizer/core/threads.cpp
index 556e02e..1338f92 100644
--- a/src/gallium/drivers/swr/rasterizer/core/threads.cpp
+++ b/src/gallium/drivers/swr/rasterizer/core/threads.cpp
@@ -105,8 +105,6 @@
 
             Core* pCore = nullptr;
 
-            uint32_t numThreads = (uint32_t)_mm_popcount_sizeT(gmask.Mask);
-
             while (BitScanForwardSizeT((unsigned long*)&threadId, gmask.Mask))
             {
                 // clear mask
@@ -148,8 +146,6 @@
                 auto& numaNode  = out_nodes[numaId];
                 numaNode.numaId = numaId;
 
-                uint32_t coreId = 0;
-
                 if (nullptr == pCore)
                 {
                     numaNode.cores.push_back(Core());
@@ -980,14 +976,14 @@
 template <bool IsFEThread, bool IsBEThread>
 DWORD workerThreadInit(LPVOID pData)
 {
-#if defined(_WIN32)
+#if defined(_MSC_VER)
     __try
 #endif // _WIN32
     {
         return workerThreadMain<IsFEThread, IsBEThread>(pData);
     }
 
-#if defined(_WIN32)
+#if defined(_MSC_VER)
     __except (EXCEPTION_CONTINUE_SEARCH)
     {
     }
diff --git a/src/gallium/drivers/swr/rasterizer/jitter/JitManager.cpp b/src/gallium/drivers/swr/rasterizer/jitter/JitManager.cpp
index 96224a7..7b86899 100644
--- a/src/gallium/drivers/swr/rasterizer/jitter/JitManager.cpp
+++ b/src/gallium/drivers/swr/rasterizer/jitter/JitManager.cpp
@@ -159,7 +159,7 @@
 
     mFetchShaderTy = FunctionType::get(Type::getVoidTy(mContext), fsArgs, false);
 
-#if defined(_WIN32)
+#if defined(_MSC_VER)
     // explicitly instantiate used symbols from potentially staticly linked libs
     sys::DynamicLibrary::AddSymbol("exp2f", &exp2f);
     sys::DynamicLibrary::AddSymbol("log2f", &log2f);
diff --git a/src/gallium/drivers/swr/rasterizer/jitter/jit_pch.hpp b/src/gallium/drivers/swr/rasterizer/jitter/jit_pch.hpp
index a5c5b1f..3e7bc8b 100644
--- a/src/gallium/drivers/swr/rasterizer/jitter/jit_pch.hpp
+++ b/src/gallium/drivers/swr/rasterizer/jitter/jit_pch.hpp
@@ -30,7 +30,7 @@
 
 #pragma once
 
-#if defined(_WIN32)
+#if defined(_MSC_VER)
 #pragma warning(disable : 4146 4244 4267 4800 4996)
 #endif
 
diff --git a/src/gallium/drivers/swr/rasterizer/memory/Convert.h b/src/gallium/drivers/swr/rasterizer/memory/Convert.h
index de4986c..c8c6b30 100644
--- a/src/gallium/drivers/swr/rasterizer/memory/Convert.h
+++ b/src/gallium/drivers/swr/rasterizer/memory/Convert.h
@@ -27,7 +27,7 @@
 ******************************************************************************/
 #pragma once
 
-#if defined(_WIN32)
+#if defined(_MSC_VER)
 // disable "potential divide by 0"
 #pragma warning(disable: 4723)
 #endif