Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 98820C5AD55 for ; Mon, 10 Aug 2026 22:55:50 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wtYtV-0003DU-PV; Mon, 10 Aug 2026 18:54:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wtYtL-0003Cz-Qm for qemu-devel@nongnu.org; Mon, 10 Aug 2026 18:54:48 -0400 Received: from mx0b-0031df01.pphosted.com ([205.220.180.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wtYtI-0004ii-Q5 for qemu-devel@nongnu.org; Mon, 10 Aug 2026 18:54:47 -0400 Received: from pps.filterd (m0279873.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 67AMqeuK3011239 for ; Mon, 10 Aug 2026 22:54:40 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-type:date:from:in-reply-to:message-id:mime-version :references:subject:to; s=qcppdkim1; bh=fpBdnm7zza3lWROc+mw/QUeR iFeDgqHMiCKbMXrbVdM=; b=DGa4kha2s1t0+SHe8XsNxtln8oe2pNAK4Q9n7hU2 vRuuqPyyZPGl17aCDMjGWepOn/bHCs/9scRmWLqFXY6NXfPnxdxEaBF/G+Bz6McR sceIHRDh2y0VECe+lm5qxrLnKcRLsi6YMAb7dYpl0ik0/0IWu5et1mzTakjlLgag CyFd3YJf22y0UofKefgTfng7fGjxOIVIg/ZKfq+WJXWdZvV32EKUu4Rp9dMZ9tpX UDcWdH7OsusaOqlQx0KA0T9eZo7hzUMHAxAPXCzAPlTW7SvuCtS6TBBIgqSdkRqr /6vs2NA+UID4wS0ogl0oI/aM8/RIFLbnoMMVMpvb4e0Xzg== Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4fyjjthc0v-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Mon, 10 Aug 2026 22:54:40 +0000 (GMT) Received: by mail-qk1-f199.google.com with SMTP id af79cd13be357-930a098ea19so294433485a.1 for ; Mon, 10 Aug 2026 15:54:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1786402480; x=1787007280; darn=nongnu.org; h=in-reply-to:from:content-language:references:cc:to:subject :user-agent:mime-version:date:message-id:content-type:from:to:cc :subject:date:message-id:reply-to:content-type; bh=fpBdnm7zza3lWROc+mw/QUeRiFeDgqHMiCKbMXrbVdM=; b=bPj7kscFAxnZ7Kgb/ew3Ys3YPGL0KOfjdyypfy5QQDB0sS8jzq7Hlsa7VORoIpxFuS DM7OZfuuNCSr4DSamvZKfen8nq3IdixU3pUOP/jppmhwjWYmNRWb8l6wcOXzssC9iriy mslQnYJ4NVc8H83JwiiTC6ACSA1RPmG7yj/Ad0j5549KTVrfWwdfL40N2N1jIWrIcwrh BOdTpb+LAD4jw7rr9zt0US5vcwmNJ0vCkRQQl6VQhMpznZSWziN4KRMuV3AcygkSeqR9 wnWwGAeR8AtX+yQELvACWKzXAVBNvMZekGGdvO05NKGWxorUHAUgWhtsX+pDgLLCE8Yg NBcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786402480; x=1787007280; h=in-reply-to:from:content-language:references:cc:to:subject :user-agent:mime-version:date:message-id:content-type:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=fpBdnm7zza3lWROc+mw/QUeRiFeDgqHMiCKbMXrbVdM=; b=L8XquWhvEt+WVdMcRtd11VlBZXJ6FW3VsYbXSqYZI4j9AqzxLIo7QX5URshPDwbLQf 4Lq6rhm/4xjPrCpvclvuRHY8M50DzMyrJaRexQCZuAMFEGefmkUP/nY7uOKru0x3cgZL 2ASYfjAvBsoeKUvazCPjNtaDx2H+Zk01RLEpwR+jUGwdIgUVYMvVPmPg+JUPVSEK1UmA /H52jzZ7jFR2Xz+uWjPqmVnflU3w3DiS6sm2jlHca8BFaWKFXYQkdrRPucX7IoX+GXHW CPLeADqcySPsnGO7F58JYxiOcQr1N6FAm5WARaEiqc1Ob4CSUm//EiFVqraAmyDeaWy0 XKrQ== X-Gm-Message-State: AOJu0YyG9kaVyqbykYNhyaShtnusZGzyJEH5qr+9qQzWWDFlDvqfyy/i x5leMHnXGtjxDice2hl3JGVP+aLCsGT4fZLy2Werog4lOFi/cUXK1QyfH0gCelRE5grJ71iJUQS 0z4GNfyWbCOtEyOa9Tmqd3qURcgx9wgV4os0HssGPufmge/NloYkzVKWgZA== X-Gm-Gg: AR+sD10nMlBBuUhIpk2xSTxT+0hHmd/9AAXb1bOEaSsiLoIY+KbooAvvEFztBPdlzn0 qKEZhUaBSL22wcp4UH9zuWeKCl2vRQ7C8djiFRn+8lRLlaFWVgyxGkswMTW8Jv7LlN01uVHkPhD mtmoOr8O+CWfKfOtSgFWvb1/bCZPWNZILWZumB20+MFjlMzdgUPTJaBcocHRUSG3oHtRaC55Vie iEEYZjLHLDgVORiOXfsseD7RkKA4/ZdfNA0LdI4syRO1c2+lwXjoQgQJFZ8jrstgSbGHw86/Cxx RyJNq25KcI1zsRHH/OLt4SdX+20/Bb0HIyOe7u6H1QQTb0S0ZeP1Rr7kMTcUJfMWp3g/YVhHDDB BJLvvvCbGZZA2E1LYtgqJeKEKX8vINQtlZsJ5UB0Qt9cF7zz2LRwBmsaSbVOFddglcsuVk5WWZc KpnThR X-Received: by 2002:a05:620a:40ca:b0:936:4955:e5ef with SMTP id af79cd13be357-93671eae246mr2577767985a.22.1786402479766; Mon, 10 Aug 2026 15:54:39 -0700 (PDT) X-Received: by 2002:a05:620a:40ca:b0:936:4955:e5ef with SMTP id af79cd13be357-93671eae246mr2577764685a.22.1786402479285; Mon, 10 Aug 2026 15:54:39 -0700 (PDT) Received: from [192.168.1.199] (104-54-226-75.lightspeed.austtx.sbcglobal.net. [104.54.226.75]) by smtp.gmail.com with ESMTPSA id af79cd13be357-9366e03aeadsm887266185a.3.2026.08.10.15.54.37 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 10 Aug 2026 15:54:38 -0700 (PDT) Content-Type: multipart/alternative; boundary="------------2zZLFmMeMwnzXX0LkZJIbyoe" Message-ID: <9db1ef83-7c05-4327-a6f3-539d1769df9d@oss.qualcomm.com> Date: Mon, 10 Aug 2026 17:54:36 -0500 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] Hexagon (target/hexagon) Clean up disassembly of control and system regs To: Taylor Simpson Cc: qemu-devel@nongnu.org, matheus.bernardino@oss.qualcomm.com, sid.manning@oss.qualcomm.com, marco.liebel@oss.qualcomm.com, richard.henderson@linaro.org, philmd@linaro.org, ale@rev.ng, anjo@rev.ng References: <20260810182804.27310-1-ltaylorsimpson@gmail.com> <57bf1075-cf49-4ccd-8893-94d32d4be313@oss.qualcomm.com> Content-Language: en-US From: Brian Cain In-Reply-To: X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwODEwMDE5NCBTYWx0ZWRfX6S1Sl+LRKJcL 5XPcGScp74DXXwnDG/mPb6Hq4Zz/7DP9H/z748al5YZd6ADHy0GG4azj0fwPQifOaWVCZSIe2BY iKVgMQuOiqE9vwBx4BBrkvNrkYbprtxFoWKDRTv+ga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TQJ7kPSJx9SKPbeHEYW:22 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.134,FMLib:17.12.100.49 definitions=2026-08-10_06,2026-08-10_03,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 clxscore=1015 adultscore=0 spamscore=0 suspectscore=0 priorityscore=1501 malwarescore=0 phishscore=0 impostorscore=0 lowpriorityscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2608100194 Received-SPF: pass client-ip=205.220.180.131; envelope-from=brian.cain@oss.qualcomm.com; helo=mx0b-0031df01.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org This is a multi-part message in MIME format. --------------2zZLFmMeMwnzXX0LkZJIbyoe Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 8/10/2026 4:32 PM, Taylor Simpson wrote: > > > On Mon, Aug 10, 2026 at 3:12 PM Brian Cain > wrote: > > > On 8/10/2026 3:53 PM, Taylor Simpson wrote: >> >> >> On Mon, Aug 10, 2026 at 1:34 PM Brian Cain >> wrote: >> >> >> On 8/10/2026 1:28 PM, Taylor Simpson wrote: >> > Change disassembly of control regs from C{num}/{name} to {name} >> > Change disassembly of system regs from S{num}/r{num} to {name} >> > >> > Signed-off-by: Taylor Simpson >> > --- >> >   target/hexagon/printinsn.c      | 22 ++++++++++++++++++---- >> >   target/hexagon/gen_printinsn.py | 14 ++++++++------ >> >   2 files changed, 26 insertions(+), 10 deletions(-) >> > >> > diff --git a/target/hexagon/printinsn.c >> b/target/hexagon/printinsn.c >> > index a7e46f4bcd..b55d3b0b35 100644 >> > --- a/target/hexagon/printinsn.c >> > +++ b/target/hexagon/printinsn.c >> > @@ -23,18 +23,32 @@ >> >   #include "internal.h" >> >   #include "decode.h" >> > >> > +static char regstr[10]; >> > + >> >   static const char *sreg2str(unsigned int reg) >> >   { >> > -    if (reg < TOTAL_PER_THREAD_REGS) { >> > -        return hexagon_regnames[reg]; >> > +#ifndef CONFIG_USER_ONLY >> > +    if (reg < NUM_SREGS) { >> > +        return hexagon_sregnames[reg]; >> >       } else { >> > -        return "???"; >> > +        snprintf(regstr, sizeof(regstr), "S%d", reg); >> > +        return regstr; >> >       } >> > +#else >> > +    snprintf(regstr, sizeof(regstr), "S%d", reg); >> > +    return regstr; >> > +#endif >> >   } >> > >> >   static const char *creg2str(unsigned int reg) >> >   { >> > -    return sreg2str(reg + HEX_REG_SA0); >> > +    unsigned int gpr = reg + HEX_REG_SA0; >> > +    if (gpr < TOTAL_PER_THREAD_REGS) { >> > +        return hexagon_regnames[gpr]; >> > +    } else { >> > +        snprintf(regstr, sizeof(regstr), "C%d", reg); >> > +        return regstr; >> > +    } >> >   } >> > >> >> >> Seems like this change also depends on some kind of mutex around >> regstr[] so that we know it's not being used concurrently by >> multiple >> threads.  Translation is single-threaded but if we gained >> another caller >> we wouldn't remember to come back and remediate this. >> >> I suppose we could take an input buffer/length. Or maybe we >> just add >> another static _regnames[] array to solve the lifetime/race >> problems? >> >> >> How about putting a regstr field in the Insn struct (and pass >> Insn* to these two functions)? >> > > A character array?  Sure: seems like that should work. > > But if we have a static array for the others why not leverage that > here too?  We can statically fill these values, right? > > > These are for cases where there is some sort of error and the reg > number is larger than NUM_SREGS/TOTAL_PER_THREAD_REGS.  So, we > wouldn't know how to size these without looking at the number of bits > in the encoding of each instruction that has one of these. However, > that could change over time if the architecture adds new instructions. > Ah, okay, right. Okay - any solution that mitigates the race should suffice, then. > The regno field in the Insn struct is a uint8_t, so we could create > static arrays with 256 entries and > > We could revert back to returning "???".  Alternatively, S or > C would be more readable. > > Thoughts? > > > --------------2zZLFmMeMwnzXX0LkZJIbyoe Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit


On 8/10/2026 4:32 PM, Taylor Simpson wrote:


On Mon, Aug 10, 2026 at 3:12 PM Brian Cain <brian.cain@oss.qualcomm.com> wrote:


On 8/10/2026 3:53 PM, Taylor Simpson wrote:


On Mon, Aug 10, 2026 at 1:34 PM Brian Cain <brian.cain@oss.qualcomm.com> wrote:

On 8/10/2026 1:28 PM, Taylor Simpson wrote:
> Change disassembly of control regs from C{num}/{name} to {name}
> Change disassembly of system regs from S{num}/r{num} to {name}
>
> Signed-off-by: Taylor Simpson <ltaylorsimpson@gmail.com>
> ---
>   target/hexagon/printinsn.c      | 22 ++++++++++++++++++----
>   target/hexagon/gen_printinsn.py | 14 ++++++++------
>   2 files changed, 26 insertions(+), 10 deletions(-)
>
> diff --git a/target/hexagon/printinsn.c b/target/hexagon/printinsn.c
> index a7e46f4bcd..b55d3b0b35 100644
> --- a/target/hexagon/printinsn.c
> +++ b/target/hexagon/printinsn.c
> @@ -23,18 +23,32 @@
>   #include "internal.h"
>   #include "decode.h"
>   
> +static char regstr[10];
> +
>   static const char *sreg2str(unsigned int reg)
>   {
> -    if (reg < TOTAL_PER_THREAD_REGS) {
> -        return hexagon_regnames[reg];
> +#ifndef CONFIG_USER_ONLY
> +    if (reg < NUM_SREGS) {
> +        return hexagon_sregnames[reg];
>       } else {
> -        return "???";
> +        snprintf(regstr, sizeof(regstr), "S%d", reg);
> +        return regstr;
>       }
> +#else
> +    snprintf(regstr, sizeof(regstr), "S%d", reg);
> +    return regstr;
> +#endif
>   }
>   
>   static const char *creg2str(unsigned int reg)
>   {
> -    return sreg2str(reg + HEX_REG_SA0);
> +    unsigned int gpr = reg + HEX_REG_SA0;
> +    if (gpr < TOTAL_PER_THREAD_REGS) {
> +        return hexagon_regnames[gpr];
> +    } else {
> +        snprintf(regstr, sizeof(regstr), "C%d", reg);
> +        return regstr;
> +    }
>   }
>   


Seems like this change also depends on some kind of mutex around
regstr[] so that we know it's not being used concurrently by multiple
threads.  Translation is single-threaded but if we gained another caller
we wouldn't remember to come back and remediate this.

I suppose we could take an input buffer/length.  Or maybe we just add
another static _regnames[] array to solve the lifetime/race problems?


How about putting a regstr field in the Insn struct (and pass Insn* to these two functions)?


A character array?  Sure: seems like that should work.  

But if we have a static array for the others why not leverage that here too?  We can statically fill these values, right?


These are for cases where there is some sort of error and the reg number is larger than NUM_SREGS/TOTAL_PER_THREAD_REGS.  So, we wouldn't know how to size these without looking at the number of bits in the encoding of each instruction that has one of these.  However, that could change over time if the architecture adds new instructions.

Ah, okay, right.

Okay - any solution that mitigates the race should suffice, then.


The regno field in the Insn struct is a uint8_t, so we could create static arrays with 256 entries and 

We could revert back to returning "???".  Alternatively, S<unknown> or C<unknown> would be more readable.

Thoughts?



--------------2zZLFmMeMwnzXX0LkZJIbyoe--