Merge pull request #878 from tritao/master
authorJoão Matos <ripzonetriton@gmail.com>
Wed, 22 Jan 2014 18:46:45 +0000 (10:46 -0800)
committerJoão Matos <ripzonetriton@gmail.com>
Wed, 22 Jan 2014 18:46:45 +0000 (10:46 -0800)
MSVC build improvements

mono/metadata/sgen-qsort.c
mono/mini/trace.c
mono/utils/atomic.h
mono/utils/mono-compiler.h

index 4b57884b0ff8d19640b3a5cd3939fe53c2b0e42d..1290e0444a92a3d3aec1197052aa20df0d6220c4 100644 (file)
@@ -69,8 +69,13 @@ qsort_rec (void *base, size_t nel, size_t width, int (*compar) (const void*, con
 void
 sgen_qsort (void *base, size_t nel, size_t width, int (*compar) (const void*, const void*))
 {
+#ifndef _MSC_VER
        unsigned char pivot_tmp [width];
        unsigned char swap_tmp [width];
+#else
+       unsigned char* pivot_tmp = (unsigned char*) alloca(width);
+       unsigned char* swap_tmp = (unsigned char*) alloca(width);
+#endif
 
        qsort_rec (base, nel, width, compar, pivot_tmp, swap_tmp);
 }
index 551b2a2fdaf61777910edb599686a6abacf8cfd7..c1d6fcfb4bcafbb8e1072af9b8eec044f506f539 100644 (file)
 #  define fprintf(__ignore, ...) g_log ("mono-gc", G_LOG_LEVEL_MESSAGE, __VA_ARGS__)
 #endif
 
-#define RETURN_ADDRESS(N) (__builtin_extract_return_addr (__builtin_return_address (N)))
+#ifdef __GNUC__
+
+#define RETURN_ADDRESS_N(N) (__builtin_extract_return_addr (__builtin_return_address (N)))
+#define RETURN_ADDRESS() RETURN_ADDRESS_N(0)
+
+#elif defined(_MSC_VER)
+
+#ifdef __cplusplus
+extern "C"
+#endif
+void *_ReturnAddress(void);
+#pragma intrinsic(_ReturnAddress)
+#define RETURN_ADDRESS() _ReturnAddress()
+#define RETURN_ADDRESS_N(N) NULL
+
+#else
+
+#define RETURN_ADDRESS() NULL
+#define RETURN_ADDRESS_N(N) NULL
+
+#endif
 
 static MonoTraceSpec trace_spec;
 
@@ -403,7 +423,7 @@ mono_trace_enter_method (MonoMethod *method, char *ebp)
        g_free (fname);
 
        if (!ebp) {
-               printf (") ip: %p\n", RETURN_ADDRESS (1));
+               printf (") ip: %p\n", RETURN_ADDRESS_N (1));
                return;
        }       
 
@@ -413,7 +433,7 @@ mono_trace_enter_method (MonoMethod *method, char *ebp)
 
        if (method->is_inflated) {
                /* FIXME: Might be better to pass the ji itself */
-               MonoJitInfo *ji = mini_jit_info_table_find (mono_domain_get (), RETURN_ADDRESS (0), NULL);
+               MonoJitInfo *ji = mini_jit_info_table_find (mono_domain_get (), RETURN_ADDRESS (), NULL);
                if (ji) {
                        gsctx = mono_jit_info_get_generic_sharing_context (ji);
                        if (gsctx && (gsctx->var_is_vt || gsctx->mvar_is_vt)) {
@@ -571,7 +591,7 @@ mono_trace_leave_method (MonoMethod *method, ...)
 
        if (method->is_inflated) {
                /* FIXME: Might be better to pass the ji itself */
-               MonoJitInfo *ji = mini_jit_info_table_find (mono_domain_get (), RETURN_ADDRESS (0), NULL);
+               MonoJitInfo *ji = mini_jit_info_table_find (mono_domain_get (), RETURN_ADDRESS (), NULL);
                if (ji) {
                        gsctx = mono_jit_info_get_generic_sharing_context (ji);
                        if (gsctx && (gsctx->var_is_vt || gsctx->mvar_is_vt)) {
@@ -684,7 +704,7 @@ handle_enum:
                printf ("(unknown return type %x)", mono_method_signature (method)->ret->type);
        }
 
-       //printf (" ip: %p\n", RETURN_ADDRESS (1));
+       //printf (" ip: %p\n", RETURN_ADDRESS_N (1));
        printf ("\n");
        fflush (stdout);
 }
index 79455ad9c435c889e9e2fb5289b365324b2ea29a..c8c70007bc751d0a55d612c230a28450c79e968f 100755 (executable)
@@ -79,6 +79,35 @@ static inline gint64 InterlockedAdd64(volatile gint64 *dest, gint64 add)
 }
 #endif
 
+#if defined(_MSC_VER) && !defined(InterlockedAdd)
+/* MSVC before 2013 only defines InterlockedAdd* for the Itanium architecture */
+static inline gint32 InterlockedAdd(volatile gint32 *dest, gint32 add)
+{
+       return InterlockedExchangeAdd (dest, add) + add;
+}
+#endif
+
+#if defined(_MSC_VER) && !defined(InterlockedAdd64)
+#if defined(InterlockedExchangeAdd64)
+/* This may be defined only on amd64 */
+static inline gint64 InterlockedAdd64(volatile gint64 *dest, gint64 add)
+{
+       return InterlockedExchangeAdd64 (dest, add) + add;
+}
+#else
+static inline gint64 InterlockedAdd64(volatile gint64 *dest, gint64 add)
+{
+       gint64 prev_value;
+
+       do {
+               prev_value = *dest;
+       } while (prev_value != InterlockedCompareExchange64(dest, prev_value + add, prev_value));
+
+       return prev_value + add;
+}
+#endif
+#endif
+
 /* And now for some dirty hacks... The Windows API doesn't
  * provide any useful primitives for this (other than getting
  * into architecture-specific madness), so use CAS. */
index 6772dacfd503424548de5370bfb2792b81bb32c6..a533a9f01e33867044ce77558d92992f1bfac588 100644 (file)
 #ifdef _MSC_VER
 
 #include <math.h>
+
+#if _MSC_VER < 1800 /* VS 2013 */
+#define strtoull _strtoui64
+#endif
+
 #include <float.h>
 #define isnan(x)       _isnan(x)
 #define trunc(x)       (((x) < 0) ? ceil((x)) : floor((x)))