From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by sourceware.org (Postfix) with ESMTPS id 6082B3858D39 for ; Thu, 30 Jun 2022 23:16:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6082B3858D39 Received: by mail-pl1-x62a.google.com with SMTP id m14so728669plg.5 for ; Thu, 30 Jun 2022 16:16:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=YQVZSWqbW33fQGW8xQmaNR3OU9lkT6PegWt8cj5wduk=; b=G6sKrTC+iOimeoTWM3bOJ0oMdj68Q6gQ2gPueRPGMmBq+80QSIWAKjf/q1beQ86Svk jUE+GRJZLEM+UU7XtO2zmjJuQtNybcg6GrkEUhO11g0wIuiHzqXFupc+U4hpaJisIBj6 +6QpjJ3kuMC/nKHXczx97QVod33zewtGxvYSXJ2OYUJpUV0gRPdx+yZeX+PmRjMIWCgJ FUo0xyqxYRepAebbdw3GttsRlOLuR+HKhJ1Ge9M1GDDTDe3ohNb4L6hrb8yDMP9q8nNw lFYvc5paceoel0PlK3ko8hgT6kHYqlInXbZ0FHmpfMd94wrV2bg+mY3L6t9LyEKfyksu TmOw== X-Gm-Message-State: AJIora9yeWKPwGr/69a12rAKBKes4SPfYW0V0X4eVBq7meqwRHpc2QNx f9ny2IRwUy1C6wC+UNhBLchjaoApe5zrpGdgcj4= X-Google-Smtp-Source: AGRyM1tOQsyEseW/ZwObf8Wl3UeljBbnZFJ9WFd+oVv/GUpEUVcMs5BFEPufMbL+aUFuqehaDFGpfl6JGyuW6fW/wPA= X-Received: by 2002:a17:90b:895:b0:1ec:827c:ef0f with SMTP id bj21-20020a17090b089500b001ec827cef0fmr14509097pjb.10.1656630977342; Thu, 30 Jun 2022 16:16:17 -0700 (PDT) MIME-Version: 1.0 References: <01f502ff-5b51-86d3-ed54-646df7d22037@suse.com> <53e719d3-482e-e1bc-663c-367fe0de7277@suse.com> In-Reply-To: <53e719d3-482e-e1bc-663c-367fe0de7277@suse.com> From: "H.J. Lu" Date: Thu, 30 Jun 2022 16:15:41 -0700 Message-ID: Subject: Re: [PATCH 7/7] x86: introduce a state stack for .arch To: Jan Beulich Cc: Binutils Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-3018.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 30 Jun 2022 23:16:20 -0000 On Thu, Jun 30, 2022 at 5:55 AM Jan Beulich wrote: > > When using just slightly non-trivial combinations of .arch, it can be > quite useful to be able to go back to prior state without needing to > re-invoke perhaps many earlier directives and without needing to invoke > perhaps many "negative" ones. Like some other architectures allow > saving (pushing) and restoring (popping) present/prior state. > > For now require the same .code to be in effect for ".arch pop" that > was in effect for the corresponding ".arch push". > > Also change the global "no_cond_jump_promotion" to be bool, to match the > new struct field. > > --- a/gas/config/tc-i386.c > +++ b/gas/config/tc-i386.c > @@ -788,7 +788,7 @@ i386_cpu_flags cpu_arch_isa_flags; > > /* If set, conditional jumps are not automatically promoted to handle > larger than a byte offset. */ > -static unsigned int no_cond_jump_promotion = 0; > +static bool no_cond_jump_promotion = false; > > /* Encode SSE instructions with VEX prefix. */ > static unsigned int sse2avx; > @@ -2663,6 +2663,20 @@ extend_cpu_sub_arch_name (const char *na > static void > set_cpu_arch (int dummy ATTRIBUTE_UNUSED) > { > + typedef struct arch_stack_entry > + { > + const struct arch_stack_entry *prev; > + const char *name; > + char *sub_name; > + i386_cpu_flags flags; > + i386_cpu_flags isa_flags; > + enum processor_type isa; > + enum flag_code flag_code; > + char stackop_size; > + bool no_cond_jump_promotion; > + } arch_stack_entry; > + static const arch_stack_entry *arch_stack_top; > + > SKIP_WHITESPACE (); > > if (!is_end_of_line[(unsigned char) *input_line_pointer]) > @@ -2706,6 +2720,67 @@ set_cpu_arch (int dummy ATTRIBUTE_UNUSED > j = ARRAY_SIZE (cpu_arch) + 1; > } > } > + else if (strcmp (string, "push") == 0) > + { > + arch_stack_entry *top = XNEW (arch_stack_entry); > + > + top->name = cpu_arch_name; > + if (cpu_sub_arch_name) > + top->sub_name = xstrdup (cpu_sub_arch_name); > + else > + top->sub_name = NULL; > + top->flags = cpu_arch_flags; > + top->isa = cpu_arch_isa; > + top->isa_flags = cpu_arch_isa_flags; > + top->flag_code = flag_code; > + top->stackop_size = stackop_size; > + top->no_cond_jump_promotion = no_cond_jump_promotion; > + > + top->prev = arch_stack_top; > + arch_stack_top = top; > + > + (void) restore_line_pointer (e); > + demand_empty_rest_of_line (); > + return; > + } > + else if (strcmp (string, "pop") == 0) > + { > + const arch_stack_entry *top = arch_stack_top; > + > + if (!top) > + as_bad (_(".arch stack is empty")); > + else if (top->flag_code != flag_code > + || top->stackop_size != stackop_size) > + { > + static const unsigned int bits[] = { > + [CODE_16BIT] = 16, > + [CODE_32BIT] = 32, > + [CODE_64BIT] = 64, > + }; > + > + as_bad (_("this `.arch pop' requires `.code%u%s' to be in effect"), > + bits[top->flag_code], > + top->stackop_size == LONG_MNEM_SUFFIX ? "gcc" : ""); > + } > + else > + { > + arch_stack_top = top->prev; > + > + cpu_arch_name = top->name; > + xfree (cpu_sub_arch_name); Can we just use free? > + cpu_sub_arch_name = top->sub_name; > + cpu_arch_flags = top->flags; > + cpu_arch_isa = top->isa; > + cpu_arch_isa_flags = top->isa_flags; > + no_cond_jump_promotion = top->no_cond_jump_promotion; > + > + XDELETE (top); > + } > + > + (void) restore_line_pointer (e); > + demand_empty_rest_of_line (); > + return; > + } > > for (; j < ARRAY_SIZE (cpu_arch); j++) > { > @@ -13685,6 +13760,10 @@ show_arch (FILE *stream, int ext, int ch > { > p = output_message (stream, p, message, start, &left, > STRING_COMMA_LEN ("default")); > + p = output_message (stream, p, message, start, &left, > + STRING_COMMA_LEN ("push")); > + p = output_message (stream, p, message, start, &left, > + STRING_COMMA_LEN ("pop")); > } > > for (j = 0; j < ARRAY_SIZE (cpu_arch); j++) > --- a/gas/doc/c-i386.texi > +++ b/gas/doc/c-i386.texi > @@ -1504,7 +1504,7 @@ directive enables a warning when gas det > supported on the CPU specified. The choices for @var{cpu_type} are: > > @multitable @columnfractions .20 .20 .20 .20 > -@item @samp{default} > +@item @samp{default} @tab @samp{push} @tab @samp{pop} > @item @samp{i8086} @tab @samp{i186} @tab @samp{i286} @tab @samp{i386} > @item @samp{i486} @tab @samp{i586} @tab @samp{i686} @tab @samp{pentium} > @item @samp{pentiumpro} @tab @samp{pentiumii} @tab @samp{pentiumiii} @tab @samp{pentium4} > --- /dev/null > +++ b/gas/testsuite/gas/i386/arch-stk.l > @@ -0,0 +1,43 @@ > +.*: Assembler messages: > +.*:3: Error:.*`cmovl'.* > +.*:10: Error:.*`cmovg'.* > +.*:17: Error:.*`cmovz'.* > +.*:21: Error:.*`\.arch pop'.*`\.code32'.* > +.*:28: Error:.*`\.arch pop'.*`\.code16gcc'.* > +.*:32: Error:.*\.arch.*empty.* > +GAS LISTING .* > + > + > +[ ]*[0-9]*[ ]+\.text > +[ ]*[0-9]*[ ]+start: > +[ ]*[0-9]*[ ]+cmovl %eax, %ecx > +[ ]*[0-9]*[ ]* > +[ ]*[0-9]*[ ]+\.arch push > +[ ]*[0-9]*[ ]+\.arch default > +[ ]*[0-9]*[ ]+\?\?\?\? 0F4DC8[ ]+cmovnl %eax, %ecx > +[ ]*[0-9]*[ ]* > +[ ]*[0-9]*[ ]+\.arch pop > +[ ]*[0-9]*[ ]+cmovg %eax, %ecx > +[ ]*[0-9]*[ ]* > +[ ]*[0-9]*[ ]+\.arch push > +[ ]*[0-9]*[ ]+\.arch \.cmov > +[ ]*[0-9]*[ ]+\?\?\?\? 0F4EC8[ ]+cmovng %eax, %ecx > +[ ]*[0-9]*[ ]* > +[ ]*[0-9]*[ ]+\.arch pop > +[ ]*[0-9]*[ ]+cmovz %eax, %ecx > +[ ]*[0-9]*[ ]* > +[ ]*[0-9]*[ ]+\.arch push > +[ ]*[0-9]*[ ]+\.code16 > +[ ]*[0-9]*[ ]+\.arch pop > +[ ]*[0-9]*[ ]+\.code32 > +[ ]*[0-9]*[ ]+\.arch pop > +[ ]*[0-9]*[ ]* > +[ ]*[0-9]*[ ]+\.code16gcc > +[ ]*[0-9]*[ ]+\.arch push > +[ ]*[0-9]*[ ]+\.code32 > +[ ]*[0-9]*[ ]+\.arch pop > +[ ]*[0-9]*[ ]+\.code16gcc > +[ ]*[0-9]*[ ]+\.arch pop > +[ ]*[0-9]*[ ]* > +[ ]*[0-9]*[ ]+\.arch pop > +#pass > --- /dev/null > +++ b/gas/testsuite/gas/i386/arch-stk.s > @@ -0,0 +1,34 @@ > + .text > +start: > + cmovl %eax, %ecx > + > + .arch push > + .arch default > + cmovnl %eax, %ecx > + > + .arch pop > + cmovg %eax, %ecx > + > + .arch push > + .arch .cmov > + cmovng %eax, %ecx > + > + .arch pop > + cmovz %eax, %ecx > + > + .arch push > + .code16 > + .arch pop > + .code32 > + .arch pop > + > + .code16gcc > + .arch push > + .code32 > + .arch pop > + .code16gcc > + .arch pop > + > + .arch pop > + > + .end > --- a/gas/testsuite/gas/i386/i386.exp > +++ b/gas/testsuite/gas/i386/i386.exp > @@ -206,6 +206,7 @@ if [gas_32_check] then { > run_dump_test "arch-13" > run_dump_test "arch-14" > run_list_test "arch-dflt" "-march=generic32 -al" > + run_list_test "arch-stk" "-march=generic32 -al" > run_dump_test "8087" > run_dump_test "287" > run_dump_test "387" > -- H.J.