aboutsummaryrefslogtreecommitdiffstats
path: root/testing/ponyc/disable-avx512f-for-x86-only.patch
blob: e14ff874789adc5c0fdc4e24be3f937d23046dd7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
Patch-Source: https://github.com/ponylang/ponyc/pull/2665

--- a/Makefile
+++ b/Makefile
@@ -41,6 +41,7 @@
 config ?= release
 arch ?= native
 tune ?= generic
+cpu ?= $(arch)
 bits ?= $(shell getconf LONG_BIT)
 
 ifndef verbose
@@ -102,7 +103,7 @@
   -DPONY_VERSION_STR=\"$(version_str)\" \
   -D_FILE_OFFSET_BITS=64
 ALL_CXXFLAGS = -std=gnu++11 -fno-rtti
-LL_FLAGS = -mcpu=$(arch)
+LL_FLAGS = -mcpu=$(cpu)
 
 # Determine pointer size in bits.
 BITS := $(bits)
--- a/src/libponyc/codegen/codegen.c
+++ b/src/libponyc/codegen/codegen.c
@@ -976,48 +976,53 @@
 
 bool codegen_pass_init(pass_opt_t* opt)
 {
+  char *triple;
+
+  // Default triple, cpu and features.
+  if(opt->triple != NULL)
+  {
+    triple = LLVMCreateMessage(opt->triple);
+  } else {
+#ifdef PLATFORM_IS_MACOSX
+    // This is to prevent XCode 7+ from claiming OSX 14.5 is required.
+    triple = LLVMCreateMessage("x86_64-apple-macosx");
+#else
+    triple = LLVMGetDefaultTargetTriple();
+#endif
+  }
+
   if(opt->features != NULL)
   {
 #if PONY_LLVM < 500
-    // Disable -avx512f on LLVM < 5.0.0 to avoid bug https://bugs.llvm.org/show_bug.cgi?id=30542
-    size_t temp_len = strlen(opt->features) + 9;
-    char* temp_str = (char*)ponyint_pool_alloc_size(temp_len);
-    snprintf(temp_str, temp_len, "%s,-avx512f", opt->features);
+    if(target_is_x86(triple))
+    {
+      // Disable -avx512f on LLVM < 5.0.0 to avoid bug https://bugs.llvm.org/show_bug.cgi?id=30542
+      size_t temp_len = strlen(opt->features) + 10;
+      char* temp_str = (char*)ponyint_pool_alloc_size(temp_len);
+      snprintf(temp_str, temp_len, "%s,-avx512f", opt->features);
 
-    opt->features = temp_str;
-#endif
+      opt->features = LLVMCreateMessage(temp_str);
 
+      ponyint_pool_free_size(temp_len, temp_str);
+    } else {
+      opt->features = LLVMCreateMessage(opt->features);
+    }
+#else
     opt->features = LLVMCreateMessage(opt->features);
-
-
-#if PONY_LLVM < 500
-    // free memory for temp_str
-    ponyint_pool_free_size(temp_len, temp_str);
 #endif
   } else {
     if((opt->cpu == NULL) && (opt->triple == NULL))
       opt->features = LLVMGetHostCPUFeatures();
     else
 #if PONY_LLVM < 500
-      opt->features = LLVMCreateMessage("-avx512f");
+      opt->features = LLVMCreateMessage(target_is_x86(triple) ? "-avx512f" : "");
 #else
       opt->features = LLVMCreateMessage("");
 #endif
   }
 
-  // Default triple, cpu and features.
-  if(opt->triple != NULL)
-  {
-    opt->triple = LLVMCreateMessage(opt->triple);
-  } else {
-#ifdef PLATFORM_IS_MACOSX
-    // This is to prevent XCode 7+ from claiming OSX 14.5 is required.
-    opt->triple = LLVMCreateMessage("x86_64-apple-macosx");
-#else
-    opt->triple = LLVMGetDefaultTargetTriple();
-#endif
-  }
-
+  opt->triple = triple;
+  
   if(opt->cpu != NULL)
     opt->cpu = LLVMCreateMessage(opt->cpu);
   else
--- a/src/libponyc/codegen/host.cc
+++ b/src/libponyc/codegen/host.cc
@@ -46,7 +46,7 @@
   for(auto it = features.begin(); it != features.end(); it++)
     buf_size += (*it).getKey().str().length() + 2; // plus +/- char and ,/null
 
-#if PONY_LLVM < 500
+#if PONY_LLVM < 500 and defined(PLATFORM_IS_X86)
   // Add extra buffer space for llvm bug workaround
   buf_size += 9;
 #endif
@@ -69,7 +69,7 @@
       strcat(buf, ",");
   }
 
-#if PONY_LLVM < 500
+#if PONY_LLVM < 500 and defined(PLATFORM_IS_X86)
   // Disable -avx512f on LLVM < 5.0.0 to avoid bug https://bugs.llvm.org/show_bug.cgi?id=30542
   strcat(buf, ",-avx512f");
 #endif