blob: dce1bc58b73cbed1c5b6f223895057c3c063b708 [file] [log] [blame]
Brad Bishop26bdd442019-08-16 17:08:17 -04001From 3db8f0c3124d3001d3c10e6d400943f3ec57616b 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
4Subject: [PATCH 32/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---
11 gcc/config/microblaze/microblaze.c | 147 ++++++++++++++++++-------------------
12 1 file changed, 70 insertions(+), 77 deletions(-)
13
14diff --git a/gcc/config/microblaze/microblaze.c b/gcc/config/microblaze/microblaze.c
Brad Bishop26bdd442019-08-16 17:08:17 -040015index 70d8d03..30a0fcf 100644
Brad Bishop286d45c2018-10-02 15:21:57 -040016--- a/gcc/config/microblaze/microblaze.c
17+++ b/gcc/config/microblaze/microblaze.c
Brad Bishop26bdd442019-08-16 17:08:17 -040018@@ -238,6 +238,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)
Brad Bishop26bdd442019-08-16 17:08:17 -040082@@ -1266,8 +1323,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);
Brad Bishop26bdd442019-08-16 17:08:17 -040092@@ -1328,8 +1384,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);
Brad Bishop26bdd442019-08-16 17:08:17 -0400102@@ -1609,72 +1664,13 @@ function_arg_partial_bytes (cumulative_args_t cum_v, machine_mode mode,
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 {
168 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
Brad Bishop26bdd442019-08-16 17:08:17 -0400176@@ -1695,13 +1691,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 {
185 error ("%qs is an invalid argument to -mcpu=", microblaze_select_cpu);
186 }
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. */
Brad Bishop26bdd442019-08-16 17:08:17 -0400193@@ -1712,8 +1708,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);
Brad Bishop26bdd442019-08-16 17:08:17 -0400203@@ -1730,11 +1725,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'. */
Brad Bishop26bdd442019-08-16 17:08:17 -0400218@@ -1742,7 +1735,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)
Brad Bishop26bdd442019-08-16 17:08:17 -0400227@@ -1750,7 +1743,7 @@ microblaze_option_override (void)
Brad Bishop286d45c2018-10-02 15:21:57 -0400228 "-mxl-multiply-high can be used only with -mcpu=v6.00.a or greater");
229 }
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 {
Brad Bishop26bdd442019-08-16 17:08:17 -0400236@@ -1759,7 +1752,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--
Brad Bishop26bdd442019-08-16 17:08:17 -04002462.7.4
Brad Bishop286d45c2018-10-02 15:21:57 -0400247