From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1386) id E5CBA3856DDC; Fri, 1 Sep 2023 10:30:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E5CBA3856DDC Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Jan Beulich To: bfd-cvs@sourceware.org Subject: [binutils-gdb] x86: unindent most of set_cpu_arch() X-Act-Checkin: binutils-gdb X-Git-Author: Jan Beulich X-Git-Refname: refs/heads/master X-Git-Oldrev: d54678ebc021d4827b8b00256e37a115f2853884 X-Git-Newrev: dfab07b9ead66f08661325c03175e1df9210ccd7 Message-Id: <20230901103003.E5CBA3856DDC@sourceware.org> Date: Fri, 1 Sep 2023 10:30:03 +0000 (GMT) X-BeenThere: binutils-cvs@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Binutils-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 01 Sep 2023 10:30:04 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Ddfab07b9ead6= 6f08661325c03175e1df9210ccd7 commit dfab07b9ead66f08661325c03175e1df9210ccd7 Author: Jan Beulich Date: Fri Sep 1 12:29:44 2023 +0200 x86: unindent most of set_cpu_arch() =20 Inverting the initial if()'s condition allows to move out the bulk of the function by a level, improving readability at least a bit. While doing that also pull the push/pop handling up first, such that "else if" after "return" isn't needed anymore; the order in which special cases are checked doesn't really matter. Diff: --- gas/config/tc-i386.c | 305 ++++++++++++++++++++++++++---------------------= ---- 1 file changed, 154 insertions(+), 151 deletions(-) diff --git a/gas/config/tc-i386.c b/gas/config/tc-i386.c index 19a5f2d61e5..00abfc78264 100644 --- a/gas/config/tc-i386.c +++ b/gas/config/tc-i386.c @@ -2793,29 +2793,134 @@ set_cpu_arch (int dummy ATTRIBUTE_UNUSED) bool no_cond_jump_promotion; } arch_stack_entry; static const arch_stack_entry *arch_stack_top; + char *s; + int e; + const char *string; + unsigned int j =3D 0; + i386_cpu_flags flags; =20 SKIP_WHITESPACE (); =20 - if (!is_end_of_line[(unsigned char) *input_line_pointer]) + if (is_end_of_line[(unsigned char) *input_line_pointer]) + { + as_bad (_("missing cpu architecture")); + input_line_pointer++; + return; + } + + e =3D get_symbol_name (&s); + string =3D s; + + if (strcmp (string, "push") =3D=3D 0) + { + arch_stack_entry *top =3D XNEW (arch_stack_entry); + + top->name =3D cpu_arch_name; + if (cpu_sub_arch_name) + top->sub_name =3D xstrdup (cpu_sub_arch_name); + else + top->sub_name =3D NULL; + top->flags =3D cpu_arch_flags; + top->isa =3D cpu_arch_isa; + top->isa_flags =3D cpu_arch_isa_flags; + top->flag_code =3D flag_code; + top->stackop_size =3D stackop_size; + top->no_cond_jump_promotion =3D no_cond_jump_promotion; + + top->prev =3D arch_stack_top; + arch_stack_top =3D top; + + (void) restore_line_pointer (e); + demand_empty_rest_of_line (); + return; + } + + if (strcmp (string, "pop") =3D=3D 0) { - char *s; - int e =3D get_symbol_name (&s); - const char *string =3D s; - unsigned int j =3D 0; - i386_cpu_flags flags; + const arch_stack_entry *top =3D arch_stack_top; =20 - if (strcmp (string, "default") =3D=3D 0) + if (!top) + as_bad (_(".arch stack is empty")); + else if (top->flag_code !=3D flag_code + || top->stackop_size !=3D stackop_size) + { + static const unsigned int bits[] =3D { + [CODE_16BIT] =3D 16, + [CODE_32BIT] =3D 32, + [CODE_64BIT] =3D 64, + }; + + as_bad (_("this `.arch pop' requires `.code%u%s' to be in effect"), + bits[top->flag_code], + top->stackop_size =3D=3D LONG_MNEM_SUFFIX ? "gcc" : ""); + } + else + { + arch_stack_top =3D top->prev; + + cpu_arch_name =3D top->name; + free (cpu_sub_arch_name); + cpu_sub_arch_name =3D top->sub_name; + cpu_arch_flags =3D top->flags; + cpu_arch_isa =3D top->isa; + cpu_arch_isa_flags =3D top->isa_flags; + no_cond_jump_promotion =3D top->no_cond_jump_promotion; + + XDELETE (top); + } + + (void) restore_line_pointer (e); + demand_empty_rest_of_line (); + return; + } + + if (strcmp (string, "default") =3D=3D 0) + { + if (strcmp (default_arch, "iamcu") =3D=3D 0) + string =3D default_arch; + else { - if (strcmp (default_arch, "iamcu") =3D=3D 0) - string =3D default_arch; + static const i386_cpu_flags cpu_unknown_flags =3D CPU_UNKNOWN_FLAGS; + + cpu_arch_name =3D NULL; + free (cpu_sub_arch_name); + cpu_sub_arch_name =3D NULL; + cpu_arch_flags =3D cpu_unknown_flags; + if (flag_code =3D=3D CODE_64BIT) + { + cpu_arch_flags.bitfield.cpu64 =3D 1; + cpu_arch_flags.bitfield.cpuno64 =3D 0; + } else { - static const i386_cpu_flags cpu_unknown_flags =3D CPU_UNKNOWN_FLAGS; + cpu_arch_flags.bitfield.cpu64 =3D 0; + cpu_arch_flags.bitfield.cpuno64 =3D 1; + } + cpu_arch_isa =3D PROCESSOR_UNKNOWN; + cpu_arch_isa_flags =3D cpu_arch[flag_code =3D=3D CODE_64BIT].enable; + if (!cpu_arch_tune_set) + { + cpu_arch_tune =3D cpu_arch_isa; + cpu_arch_tune_flags =3D cpu_arch_isa_flags; + } + + j =3D ARRAY_SIZE (cpu_arch) + 1; + } + } + + for (; j < ARRAY_SIZE (cpu_arch); j++) + { + if (strcmp (string + (*string =3D=3D '.'), cpu_arch[j].name) =3D=3D 0 + && (*string =3D=3D '.') =3D=3D (cpu_arch[j].type =3D=3D PROCESSOR_NONE)) + { + if (*string !=3D '.') + { + check_cpu_arch_compatible (string, cpu_arch[j].enable); =20 - cpu_arch_name =3D NULL; + cpu_arch_name =3D cpu_arch[j].name; free (cpu_sub_arch_name); cpu_sub_arch_name =3D NULL; - cpu_arch_flags =3D cpu_unknown_flags; + cpu_arch_flags =3D cpu_arch[j].enable; if (flag_code =3D=3D CODE_64BIT) { cpu_arch_flags.bitfield.cpu64 =3D 1; @@ -2826,173 +2931,71 @@ set_cpu_arch (int dummy ATTRIBUTE_UNUSED) cpu_arch_flags.bitfield.cpu64 =3D 0; cpu_arch_flags.bitfield.cpuno64 =3D 1; } - cpu_arch_isa =3D PROCESSOR_UNKNOWN; - cpu_arch_isa_flags =3D cpu_arch[flag_code =3D=3D CODE_64BIT].enable; + cpu_arch_isa =3D cpu_arch[j].type; + cpu_arch_isa_flags =3D cpu_arch[j].enable; if (!cpu_arch_tune_set) { cpu_arch_tune =3D cpu_arch_isa; cpu_arch_tune_flags =3D cpu_arch_isa_flags; } - - j =3D ARRAY_SIZE (cpu_arch) + 1; + pre_386_16bit_warned =3D false; + break; } - } - else if (strcmp (string, "push") =3D=3D 0) - { - arch_stack_entry *top =3D XNEW (arch_stack_entry); =20 - top->name =3D cpu_arch_name; - if (cpu_sub_arch_name) - top->sub_name =3D xstrdup (cpu_sub_arch_name); - else - top->sub_name =3D NULL; - top->flags =3D cpu_arch_flags; - top->isa =3D cpu_arch_isa; - top->isa_flags =3D cpu_arch_isa_flags; - top->flag_code =3D flag_code; - top->stackop_size =3D stackop_size; - top->no_cond_jump_promotion =3D no_cond_jump_promotion; + if (cpu_flags_all_zero (&cpu_arch[j].enable)) + continue; =20 - top->prev =3D arch_stack_top; - arch_stack_top =3D top; + flags =3D cpu_flags_or (cpu_arch_flags, cpu_arch[j].enable); =20 - (void) restore_line_pointer (e); - demand_empty_rest_of_line (); - return; - } - else if (strcmp (string, "pop") =3D=3D 0) - { - const arch_stack_entry *top =3D arch_stack_top; - - if (!top) - as_bad (_(".arch stack is empty")); - else if (top->flag_code !=3D flag_code - || top->stackop_size !=3D stackop_size) + if (!cpu_flags_equal (&flags, &cpu_arch_flags)) { - static const unsigned int bits[] =3D { - [CODE_16BIT] =3D 16, - [CODE_32BIT] =3D 32, - [CODE_64BIT] =3D 64, - }; - - as_bad (_("this `.arch pop' requires `.code%u%s' to be in effect"), - bits[top->flag_code], - top->stackop_size =3D=3D LONG_MNEM_SUFFIX ? "gcc" : ""); + extend_cpu_sub_arch_name (string + 1); + cpu_arch_flags =3D flags; + cpu_arch_isa_flags =3D flags; } else - { - arch_stack_top =3D top->prev; - - cpu_arch_name =3D top->name; - free (cpu_sub_arch_name); - cpu_sub_arch_name =3D top->sub_name; - cpu_arch_flags =3D top->flags; - cpu_arch_isa =3D top->isa; - cpu_arch_isa_flags =3D top->isa_flags; - no_cond_jump_promotion =3D top->no_cond_jump_promotion; - - XDELETE (top); - } + cpu_arch_isa_flags + =3D cpu_flags_or (cpu_arch_isa_flags, cpu_arch[j].enable); =20 (void) restore_line_pointer (e); demand_empty_rest_of_line (); return; } + } =20 - for (; j < ARRAY_SIZE (cpu_arch); j++) - { - if (strcmp (string + (*string =3D=3D '.'), cpu_arch[j].name) =3D=3D 0 - && (*string =3D=3D '.') =3D=3D (cpu_arch[j].type =3D=3D PROCESSOR_NO= NE)) - { - if (*string !=3D '.') - { - check_cpu_arch_compatible (string, cpu_arch[j].enable); - - cpu_arch_name =3D cpu_arch[j].name; - free (cpu_sub_arch_name); - cpu_sub_arch_name =3D NULL; - cpu_arch_flags =3D cpu_arch[j].enable; - if (flag_code =3D=3D CODE_64BIT) - { - cpu_arch_flags.bitfield.cpu64 =3D 1; - cpu_arch_flags.bitfield.cpuno64 =3D 0; - } - else - { - cpu_arch_flags.bitfield.cpu64 =3D 0; - cpu_arch_flags.bitfield.cpuno64 =3D 1; - } - cpu_arch_isa =3D cpu_arch[j].type; - cpu_arch_isa_flags =3D cpu_arch[j].enable; - if (!cpu_arch_tune_set) - { - cpu_arch_tune =3D cpu_arch_isa; - cpu_arch_tune_flags =3D cpu_arch_isa_flags; - } - pre_386_16bit_warned =3D false; - break; - } - - if (cpu_flags_all_zero (&cpu_arch[j].enable)) - continue; - - flags =3D cpu_flags_or (cpu_arch_flags, - cpu_arch[j].enable); - - if (!cpu_flags_equal (&flags, &cpu_arch_flags)) - { - extend_cpu_sub_arch_name (string + 1); - cpu_arch_flags =3D flags; - cpu_arch_isa_flags =3D flags; - } - else - cpu_arch_isa_flags - =3D cpu_flags_or (cpu_arch_isa_flags, - cpu_arch[j].enable); - (void) restore_line_pointer (e); - demand_empty_rest_of_line (); - return; - } - } - - if (startswith (string, ".no") && j >=3D ARRAY_SIZE (cpu_arch)) - { - /* Disable an ISA extension. */ - for (j =3D 0; j < ARRAY_SIZE (cpu_arch); j++) - if (cpu_arch[j].type =3D=3D PROCESSOR_NONE - && strcmp (string + 3, cpu_arch[j].name) =3D=3D 0) + if (startswith (string, ".no") && j >=3D ARRAY_SIZE (cpu_arch)) + { + /* Disable an ISA extension. */ + for (j =3D 0; j < ARRAY_SIZE (cpu_arch); j++) + if (cpu_arch[j].type =3D=3D PROCESSOR_NONE + && strcmp (string + 3, cpu_arch[j].name) =3D=3D 0) + { + flags =3D cpu_flags_and_not (cpu_arch_flags, cpu_arch[j].disable); + if (!cpu_flags_equal (&flags, &cpu_arch_flags)) { - flags =3D cpu_flags_and_not (cpu_arch_flags, - cpu_arch[j].disable); - if (!cpu_flags_equal (&flags, &cpu_arch_flags)) - { - extend_cpu_sub_arch_name (string + 1); - cpu_arch_flags =3D flags; - cpu_arch_isa_flags =3D flags; - } - (void) restore_line_pointer (e); - demand_empty_rest_of_line (); - return; + extend_cpu_sub_arch_name (string + 1); + cpu_arch_flags =3D flags; + cpu_arch_isa_flags =3D flags; } - } - - if (j =3D=3D ARRAY_SIZE (cpu_arch)) - as_bad (_("no such architecture: `%s'"), string); =20 - *input_line_pointer =3D e; + (void) restore_line_pointer (e); + demand_empty_rest_of_line (); + return; + } } - else - as_bad (_("missing cpu architecture")); + + if (j =3D=3D ARRAY_SIZE (cpu_arch)) + as_bad (_("no such architecture: `%s'"), string); + + *input_line_pointer =3D e; =20 no_cond_jump_promotion =3D 0; if (*input_line_pointer =3D=3D ',' && !is_end_of_line[(unsigned char) input_line_pointer[1]]) { - char *string; - char e; - ++input_line_pointer; - e =3D get_symbol_name (&string); + e =3D get_symbol_name (&s); + string =3D s; =20 if (strcmp (string, "nojumps") =3D=3D 0) no_cond_jump_promotion =3D 1;