blob: da24f113975a02206393f9cb72a58319ad4596da [file] [log] [blame]
Andrew Geissler10fa1492020-12-11 16:25:29 -06001From cb67b2e64c0d5bd32d36cb32def5f889122fc37a Mon Sep 17 00:00:00 2001
Brad Bishop286d45c2018-10-02 15:21:57 -04002From: Mahesh Bodapati <mbodapat@xilinx.com>
Brad Bishop26bdd442019-08-16 17:08:17 -04003Date: Wed, 18 Jan 2017 12:42:10 +0530
Andrew Geissler10fa1492020-12-11 16:25:29 -06004Subject: [PATCH 25/54] [Patch, microblaze]: Fix bug in MB version calculation
5 This patch fixes the bug in microblaze_version_to_int function. Earlier the
6 conversion of vXX.YY.Z to int has a bug which is fixed now.
Brad Bishop286d45c2018-10-02 15:21:57 -04007
Brad Bishop26bdd442019-08-16 17:08:17 -04008Signed-off-by : Mahesh Bodapati <mbodapat@xilinx.com>
9 Nagaraju Mekala <nmekala@xilix.com>
Brad Bishop286d45c2018-10-02 15:21:57 -040010---
Andrew Geissler10fa1492020-12-11 16:25:29 -060011 gcc/config/microblaze/microblaze.c | 147 ++++++++++++++---------------
12 1 file changed, 70 insertions(+), 77 deletions(-)
Brad Bishop286d45c2018-10-02 15:21:57 -040013
14diff --git a/gcc/config/microblaze/microblaze.c b/gcc/config/microblaze/microblaze.c
Andrew Geissler10fa1492020-12-11 16:25:29 -060015index 14c652325a8..451db9c79b0 100644
Brad Bishop286d45c2018-10-02 15:21:57 -040016--- a/gcc/config/microblaze/microblaze.c
17+++ b/gcc/config/microblaze/microblaze.c
Andrew Geisslera9ff2b32020-10-16 10:11:54 -050018@@ -242,6 +242,63 @@ section *sdata2_section;
Brad Bishop286d45c2018-10-02 15:21:57 -040019 #define TARGET_HAVE_TLS true
20 #endif
21
22+/* Convert a version number of the form "vX.YY.Z" to an integer encoding
23+ for easier range comparison. */
24+static int
25+microblaze_version_to_int (const char *version)
26+{
27+ const char *p, *v;
28+ const char *tmpl = "vXX.YY.Z";
29+ int iver1 =0, iver2 =0, iver3 =0;
30+
31+ p = version;
32+ v = tmpl;
33+
34+ while (*p)
35+ {
36+ if (*v == 'X')
37+ { /* Looking for major */
38+ if (*p == '.')
39+ {
40+ *v++;
41+ }
42+ else
43+ {
44+ if (!(*p >= '0' && *p <= '9'))
45+ return -1;
46+ iver1 += (int) (*p - '0');
47+ iver1 *= 1000;
48+ }
49+ }
50+ else if (*v == 'Y')
51+ { /* Looking for minor */
52+ if (!(*p >= '0' && *p <= '9'))
53+ return -1;
54+ iver2 += (int) (*p - '0');
55+ iver2 *= 10;
56+ }
57+ else if (*v == 'Z')
58+ { /* Looking for compat */
59+ if (!(*p >= 'a' && *p <= 'z'))
60+ return -1;
61+ iver3 = ((int) (*p)) - 96;
62+ }
63+ else
64+ {
65+ if (*p != *v)
66+ return -1;
67+ }
68+
69+ v++;
70+ p++;
71+ }
72+
73+ if (*p)
74+ return -1;
75+
76+ return iver1 + iver2 + iver3;
77+}
78+
79 /* Return truth value if a CONST_DOUBLE is ok to be a legitimate constant. */
80 static bool
81 microblaze_const_double_ok (rtx op, machine_mode mode)
Andrew Geisslera9ff2b32020-10-16 10:11:54 -050082@@ -1341,8 +1398,7 @@ microblaze_rtx_costs (rtx x, machine_mode mode, int outer_code ATTRIBUTE_UNUSED,
Brad Bishop286d45c2018-10-02 15:21:57 -040083 {
84 if (TARGET_BARREL_SHIFT)
85 {
86- if (MICROBLAZE_VERSION_COMPARE (microblaze_select_cpu, "v5.00.a")
87- >= 0)
88+ if (microblaze_version_to_int(microblaze_select_cpu) >= microblaze_version_to_int("v5.00.a"))
89 *total = COSTS_N_INSNS (1);
90 else
91 *total = COSTS_N_INSNS (2);
Andrew Geisslera9ff2b32020-10-16 10:11:54 -050092@@ -1403,8 +1459,7 @@ microblaze_rtx_costs (rtx x, machine_mode mode, int outer_code ATTRIBUTE_UNUSED,
Brad Bishop286d45c2018-10-02 15:21:57 -040093 }
94 else if (!TARGET_SOFT_MUL)
95 {
96- if (MICROBLAZE_VERSION_COMPARE (microblaze_select_cpu, "v5.00.a")
97- >= 0)
98+ if (microblaze_version_to_int(microblaze_select_cpu) >= microblaze_version_to_int("v5.00.a"))
99 *total = COSTS_N_INSNS (1);
100 else
101 *total = COSTS_N_INSNS (3);
Andrew Geissler10fa1492020-12-11 16:25:29 -0600102@@ -1677,72 +1732,13 @@ function_arg_partial_bytes (cumulative_args_t cum_v,
Brad Bishop286d45c2018-10-02 15:21:57 -0400103 return 0;
104 }
105
106-/* Convert a version number of the form "vX.YY.Z" to an integer encoding
107- for easier range comparison. */
108-static int
109-microblaze_version_to_int (const char *version)
110-{
111- const char *p, *v;
112- const char *tmpl = "vXX.YY.Z";
113- int iver = 0;
114-
115- p = version;
116- v = tmpl;
117-
118- while (*p)
119- {
120- if (*v == 'X')
121- { /* Looking for major */
122- if (*p == '.')
123- {
124- v++;
125- }
126- else
127- {
128- if (!(*p >= '0' && *p <= '9'))
129- return -1;
130- iver += (int) (*p - '0');
131- iver *= 10;
132- }
133- }
134- else if (*v == 'Y')
135- { /* Looking for minor */
136- if (!(*p >= '0' && *p <= '9'))
137- return -1;
138- iver += (int) (*p - '0');
139- iver *= 10;
140- }
141- else if (*v == 'Z')
142- { /* Looking for compat */
143- if (!(*p >= 'a' && *p <= 'z'))
144- return -1;
145- iver *= 10;
146- iver += (int) (*p - 'a');
147- }
148- else
149- {
150- if (*p != *v)
151- return -1;
152- }
153-
154- v++;
155- p++;
156- }
157-
158- if (*p)
159- return -1;
160-
161- return iver;
162-}
163-
164-
165 static void
166 microblaze_option_override (void)
167 {
Andrew Geissler10fa1492020-12-11 16:25:29 -0600168 register int i, start;
169 register int regno;
170 register machine_mode mode;
171- int ver;
172+ int ver,ver_int;
173
174 microblaze_section_threshold = (global_options_set.x_g_switch_value
175 ? g_switch_value
Andrew Geisslera9ff2b32020-10-16 10:11:54 -0500176@@ -1763,13 +1759,13 @@ microblaze_option_override (void)
Brad Bishop286d45c2018-10-02 15:21:57 -0400177 /* Check the MicroBlaze CPU version for any special action to be done. */
178 if (microblaze_select_cpu == NULL)
179 microblaze_select_cpu = MICROBLAZE_DEFAULT_CPU;
180- ver = microblaze_version_to_int (microblaze_select_cpu);
181- if (ver == -1)
182+ ver_int = microblaze_version_to_int (microblaze_select_cpu);
183+ if (ver_int == -1)
184 {
Andrew Geissler84ad7c52020-06-27 00:00:16 -0500185 error ("%qs is an invalid argument to %<-mcpu=%>", microblaze_select_cpu);
Brad Bishop286d45c2018-10-02 15:21:57 -0400186 }
187
188- ver = MICROBLAZE_VERSION_COMPARE (microblaze_select_cpu, "v3.00.a");
189+ ver = ver_int - microblaze_version_to_int("v3.00.a");
190 if (ver < 0)
191 {
192 /* No hardware exceptions in earlier versions. So no worries. */
Andrew Geisslera9ff2b32020-10-16 10:11:54 -0500193@@ -1780,8 +1776,7 @@ microblaze_option_override (void)
Brad Bishop286d45c2018-10-02 15:21:57 -0400194 microblaze_pipe = MICROBLAZE_PIPE_3;
195 }
196 else if (ver == 0
197- || (MICROBLAZE_VERSION_COMPARE (microblaze_select_cpu, "v4.00.b")
198- == 0))
199+ || (ver_int == microblaze_version_to_int("v4.00.b")))
200 {
201 #if 0
202 microblaze_select_flags |= (MICROBLAZE_MASK_NO_UNSAFE_DELAY);
Andrew Geisslera9ff2b32020-10-16 10:11:54 -0500203@@ -1798,11 +1793,9 @@ microblaze_option_override (void)
Brad Bishop286d45c2018-10-02 15:21:57 -0400204 #endif
205 microblaze_no_unsafe_delay = 0;
206 microblaze_pipe = MICROBLAZE_PIPE_5;
207- if (MICROBLAZE_VERSION_COMPARE (microblaze_select_cpu, "v5.00.a") == 0
208- || MICROBLAZE_VERSION_COMPARE (microblaze_select_cpu,
209- "v5.00.b") == 0
210- || MICROBLAZE_VERSION_COMPARE (microblaze_select_cpu,
211- "v5.00.c") == 0)
212+ if ((ver_int == microblaze_version_to_int("v5.00.a"))
213+ || (ver_int == microblaze_version_to_int("v5.00.b"))
214+ || (ver_int == microblaze_version_to_int("v5.00.c")))
215 {
216 /* Pattern compares are to be turned on by default only when
217 compiling for MB v5.00.'z'. */
Andrew Geisslera9ff2b32020-10-16 10:11:54 -0500218@@ -1810,7 +1803,7 @@ microblaze_option_override (void)
Brad Bishop286d45c2018-10-02 15:21:57 -0400219 }
220 }
221
222- ver = MICROBLAZE_VERSION_COMPARE (microblaze_select_cpu, "v6.00.a");
223+ ver = ver_int - microblaze_version_to_int("v6.00.a");
224 if (ver < 0)
225 {
226 if (TARGET_MULTIPLY_HIGH)
Andrew Geisslera9ff2b32020-10-16 10:11:54 -0500227@@ -1819,7 +1812,7 @@ microblaze_option_override (void)
Andrew Geissler84ad7c52020-06-27 00:00:16 -0500228 "%<-mcpu=v6.00.a%> or greater");
Brad Bishop286d45c2018-10-02 15:21:57 -0400229 }
230
231- ver = MICROBLAZE_VERSION_COMPARE (microblaze_select_cpu, "v8.10.a");
232+ ver = ver_int - microblaze_version_to_int("v8.10.a");
233 microblaze_has_clz = 1;
234 if (ver < 0)
235 {
Andrew Geisslera9ff2b32020-10-16 10:11:54 -0500236@@ -1828,7 +1821,7 @@ microblaze_option_override (void)
Brad Bishop286d45c2018-10-02 15:21:57 -0400237 }
238
239 /* TARGET_REORDER defaults to 2 if -mxl-reorder not specified. */
240- ver = MICROBLAZE_VERSION_COMPARE (microblaze_select_cpu, "v8.30.a");
241+ ver = ver_int - microblaze_version_to_int("v8.30.a");
242 if (ver < 0)
243 {
244 if (TARGET_REORDER == 1)
245--
Andrew Geisslera9ff2b32020-10-16 10:11:54 -05002462.17.1
Brad Bishop286d45c2018-10-02 15:21:57 -0400247