From mboxrd@z Thu Jan 1 00:00:00 1970 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 35F61CD98C5 for ; Thu, 11 Jun 2026 01:06:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=0U6CbeRrnsz8NrfNLzHbC8hohuSXmIh4bczEjb1Rd9g=; b=Q0Hl+OEIMxD5Om UQ65NJfzHtiiO+KNIzVbkewNvNreS9pGBnLycOLTn5Nd6wBKPhsdIDT6Pphl7oMD1uhoFjBIzZLqQ JBQRVZnLF0r4bdRW5re+KjLzRrGGXSkF6j7XOFPQeCm9hPZRKA16N5SCey/s+50SveAzDDac1yLyS WTzhQARY40Cnun61f7EPLOqid3JS2CYE6bN/xnr6bbJPywMPUhHYauybbvDejQW/QMDUE+SmBolm+ nPCmkFmreIlx0tGwcPEN6D4TkfuEwMpGY7wGhJA2W6TJEQ5cAEEEh3f7EkX9qPocT4NXBH8fuz2IT EaavTAT8ThnuWWWbwTBA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1wXTs7-00000008WBQ-3bZm; Thu, 11 Jun 2026 01:06:15 +0000 Received: from mail-dy1-x1333.google.com ([2607:f8b0:4864:20::1333]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1wXTs4-00000008WAh-3MQm for kvm-riscv@lists.infradead.org; Thu, 11 Jun 2026 01:06:14 +0000 Received: by mail-dy1-x1333.google.com with SMTP id 5a478bee46e88-304d7f31215so6677825eec.1 for ; Wed, 10 Jun 2026 18:06:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1781139971; x=1781744771; darn=lists.infradead.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=VboLQNAR8iiox5vG6qq6qNpSq+23FwPh2uptUxiLAaw=; b=LdgjRiLtfpvIFoGtn9J08Ry+vFo/Hb7Q9IVBg9iSvoKCjfCRoKxV2fZW8RPRMtmw7s n7I7iJO8J4YHtcTYJ3Z4nSpScWdnKODre+QLiiK4Lsb3vpURqtMCpVXEZMm1Lkc6E8xG euggwm7dKzX5e4DiR1HguRZbsFGFsEsQCVZYit7Bh9BcrLfe6VoyqvO9+vX9hf7+ByZl D59uypuvrnDcvhRaFmZmqfgCVs9cAwEsQVU4LdR0b8Pw02DEcta9TOOzElt+wPH7Ns3x 7U+OZulRoKouXE5FZXRubrlbsTgygs4JfzwBdDq14s+CLuH19y14d6kGejdmSFQVQ87m 9XtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781139971; x=1781744771; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VboLQNAR8iiox5vG6qq6qNpSq+23FwPh2uptUxiLAaw=; b=QmpZpY9srZdZ+2pb61wi7ffb9+L5rK+9bIcR1oXqVpJplQvDfUtPE5O+018lS0AGxW gbV2g+HUzYMKh14vj972ArPGSZpWd03XviI+jkPrmm1TR2tJygvy3bQ4NIY2z2HK7q7t t3S2hJ7mrvnCETvUN7rb/jXhDY82JJHFkGQ0DaCPsCVHt34S0J1hayQ8or9ompKas1dH AlX/C/wI+jcFpPtLtjjTvlaVhilF31XBKnrm+Zwjm/zZUCTHDrsDPTDhE3bNrUhHFm3N o7ZqLoJAlRhkDgJ9VlJkmsZjuT1XCbcqHUwS5QDFh/mUA9IK0JayeLcFnbsmBToVO688 VQbw== X-Forwarded-Encrypted: i=1; AFNElJ/U5UHcjIM6juoNVfCW85XQOR1ZxhDubGCDy6CJnnOBOs0J63HOWdn0MfzzdeKFZQtsnKweoSOeROY=@lists.infradead.org X-Gm-Message-State: AOJu0YxX+TYCyOXv10Z28F/pG5KHw1U9mIdanbYTry6KoybXt5xQ293o JzOyT6h6tXAb1Qf4ISZ7JRwhuhhnBJFPgljm8+vhgI+3VH4IuCf/YOLw X-Gm-Gg: Acq92OGYK89g/hWwiP8xSt3BPaOVH6QTlG/xgKnbLq2CCpINZ6oH2E31HeLuZpg2hXk S+FKFajr8Ho6vlXMyvUVni4oZSCieGuuNRNsJhshUeeGWXe9Q+NsLGgk3x3mf92177k9HxmDZFe zkad5c7w9J94WqwtaIfLvptAx+YQdCLS0VhdcdAq3NfUyD4Hk+daArz3mpxWuubZbEtvzxjDNjs qcAKiZCO/DfkE19ZlHK1xqFiRHZ6pHcSHRE8O0cq/ZXzaxU5gl0AzJmtGBY9VQq47+ETmErzejL cZmbg4gC30PN0U85RDwbnDRr/umjLSMlaySjrHiZHcInjLy3ip9QUkIMn+xSZrP/I/2Dx1/xq6X M2dMEhG/xsCohLoz5p2KOZgqY7waHUCKLU7QFGsn4YrlFA9MnNKiNC6Z1duRylCNEJXtJeMh0yk KyNLMd/P9pXqmOFPivbtmxZQ== X-Received: by 2002:a05:7300:510:b0:2f3:986d:2d01 with SMTP id 5a478bee46e88-30804bbdd85mr548716eec.19.1781139971040; Wed, 10 Jun 2026 18:06:11 -0700 (PDT) Received: from blinky ([2601:647:6700:64d0::92d1]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-30806ebb79bsm71245eec.25.2026.06.10.18.06.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jun 2026 18:06:10 -0700 (PDT) Date: Wed, 10 Jun 2026 18:06:07 -0700 From: Charlie Jenkins To: Nam Cao Cc: Charlie Jenkins via B4 Relay , Paul Walmsley , Palmer Dabbelt , Alexandre Ghiti , Anup Patel , Atish Patra , Conor Dooley , Paolo Bonzini , Andrew Morton , Shuah Khan , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-kselftest@vger.kernel.org Subject: Re: [PATCH 01/16] riscv: Introduce instruction table generation Message-ID: References: <20260407-riscv_insn_table-v1-0-54b4736a1e77@gmail.com> <20260407-riscv_insn_table-v1-1-54b4736a1e77@gmail.com> <878q8m1j9y.fsf@yellow.woof> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <878q8m1j9y.fsf@yellow.woof> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260610_180612_850825_08BFA894 X-CRM114-Status: GOOD ( 26.21 ) X-BeenThere: kvm-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "kvm-riscv" Errors-To: kvm-riscv-bounces+kvm-riscv=archiver.kernel.org@lists.infradead.org On Wed, Jun 10, 2026 at 05:56:25PM +0200, Nam Cao wrote: > Charlie Jenkins via B4 Relay > writes: > > From: Charlie Jenkins > > > > Eliminate the need to hand-write riscv instructions by using a shell > > script to autogenerate a header from an instruction table. This is modeled > > after the syscall table infrastructure. > > > > The table is generated externally by riscv-unified-db [1], but is > > in a simple format to make it possible to use other tools or modify > > manually. > > > > [1] https://github.com/riscv-software-src/riscv-unified-db > > > > Signed-off-by: Charlie Jenkins > > Thanks for the work, I really like the idea. This will make it much > easier to maintain the instruction stuffs. > > > +c.ld common,32 011<13|00<0 imm<3=6-5|12-10 xd!1!3!5!7=4-2 xs1=9-7 > > +c.ld common,64 011<13|00<0 imm<3=6-5|12-10 xd=4-2 xs1=9-7 > > Not sure if I confuse something, but the spec says "C.LD is an > RV64C-only instruction". Why do we have 32 here? This is a weird one. The Ziclsd extension introduces it for RV32[1]. All of the data is generated from the riscv-unified-db and because it is in the Ziclsd extension, c.ld is included for 32-bit in the c.ld description [2]. [1] https://docs.riscv.org/reference/isa/extensions/zilsd/_attachments/riscv-zilsd.pdf [2] https://github.com/riscv/riscv-unified-db/blob/main/spec/std/isa/inst/C/c.ld.yaml > > > +echo "#define COMMA ," >> $outfile > > +echo "#define SEMICOLON ;" >> $outfile > > +echo "#define SINGLE_ARG(...) __VA_ARGS__" >> $outfile > > Aren't these macro unused? Yes thanks, I had them for an earlier version and never removed them. > > > +echo >> $outfile > > + > > +grep -E "^[a-z\.0-9]+[[:space:]]+" "$infile" | { > > + while read name base fixed variables; do > > + echo "/* $name */" > > + > > + compressed_name=${name##c.*} > ^^^^^^^^^^^^^^^ > this name is misleading That's fair, I can rename it to be something like "compressed_inst"? > > > + invalid_inst_functions="" > > + variable_params="" > > + constraints="" > > + match="" > > + mask="" > > + make="" > > + > > + # All compressed instructions start with "c." > > + size=${compressed_name:+32}; > > + size=${size:-16}; > > + > > + # Replace all . with _ > > + formatted_inst_name=$name > > + while [ ! ${formatted_inst_name##*.*} ]; do > > + prefix=${formatted_inst_name%.*} > > + suffix=${formatted_inst_name##*.} > > + contains_dot=${formatted_inst_name##*.*} > > + formatted_inst_name=${contains_dot:-${prefix}_${suffix}} > > + done > > Does the simplier > formatted_inst_name=$(echo $name | tr '.' '_') > work? That does work, but it dramatically slows down the time. I was trying to avoid using external programs because this is called on every compilation and there are a lot of instructions to parse. On my system, it's about 10x slower to use echo/tr. Taking the time from about 150us to 1.5ms for each iteration and the total time from around 0.8s to around 3.5s. > > > + echo "static __always_inline ${type}${size} riscv_insn_${formatted_inst_name}_extract_${variable_name}(u${size} ${insn})" > > + echo "{" > > + echo "\treturn ${extract};" > > + echo "}" > > + echo "static __always_inline void riscv_insn_${formatted_inst_name}_insert_${variable_name}(u${size} *${insn}, ${type}32 ${var})" > > + echo "{" > > + echo "\t*_insn &= ${insert_mask# & };" > > Why is this required? Isn't this part always zero at this point? > > > + echo "\t*_insn |= ${insert# | };" > > + echo "}" > > + > > + if [ "${only_base}" ]; then > > + invalid_inst_functions="${invalid_inst_functions}static __always_inline ${type}${size} riscv_insn_${formatted_inst_name}_extract_${variable_name}(u${size} ${insn}) {\n\tpanic(\"${name} is not supported on non ${only_base}-bit systems.\");\n}\n" > > Instead of panic(), can we do BUILD_BUG() instead? That's a better solution :) - Charlie > > Nam -- kvm-riscv mailing list kvm-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/kvm-riscv From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-dy1-f174.google.com (mail-dy1-f174.google.com [74.125.82.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2139A1DC198 for ; Thu, 11 Jun 2026 01:06:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.174 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781139973; cv=none; b=ujmsqe7Y9HIA+sHXaRDzXagqNQaoaH3mpsisl/haAmVNf9e+2mCeo7QjfEkXLB5G9nhILHm6wjvNR54KoIwz6nx8PovBzql66o/XdEN46Tn0Q5cZ2VnLRQWCeqYqtqb4JPv0V4xe+HXUuMt+TlzT2kqo2XugVzJdGU39eDyWVnc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781139973; c=relaxed/simple; bh=tlYJdwjt2jvaFbKtXeL1njWq773Cas3GWF5HwbmzqD4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=I+NkuImjfOhkCyxijvPXOfpelTXni07aIZW0neGmiPvP9PXTRM4LQ7D4cx0FPUouA5Ysfw0wsa5eNMUCDdkB7bdTrbgnUYmL7O3Ozn3mbm62rr2wXbkh+t/F/6CGEOGEzRYe16YTJi4tD3yA1Eosmlv5Trda5f3Y0VALbDyy60o= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=FvWWnYEm; arc=none smtp.client-ip=74.125.82.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="FvWWnYEm" Received: by mail-dy1-f174.google.com with SMTP id 5a478bee46e88-304e83724bfso9453178eec.0 for ; Wed, 10 Jun 2026 18:06:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1781139971; x=1781744771; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=VboLQNAR8iiox5vG6qq6qNpSq+23FwPh2uptUxiLAaw=; b=FvWWnYEmq470Eysdd1SKG1uDMRxao45PEzCSOo8EULrYfZQUCHdM7kQmoyaoEbSduM 6qSsdIJEmKebx4cb8rBjAF4kuxWnqWFyjGiRWgC9tGQjo+aTGbgnroCE3P9ZJWE6GEDA u1fwRpm+VhCY1Clfb5vh1sfdIsZ91iVd6mYjIHuJEl+unbxhFRrwktegfqFnweFeho/1 G7MFG3yPRbbbWTBkXKHuroc6cffuGismDTOyp7lLiDIF3Fq1FogNtIRt77vgt6FKH+pk mZLn3RHACK2p63Iv//anLvD5cNCnoioDCXxUvorKyZ4De4E2ADzGki7w3mGhRBM9BC2w 1cuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781139971; x=1781744771; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VboLQNAR8iiox5vG6qq6qNpSq+23FwPh2uptUxiLAaw=; b=KVrKLa9CopPmDKHSqGmyHsnHEN+5ljanGt75uuxwqNE3lDLXKQmPjBzI8dG5TPr11l 8KeuM7H3YgVMt26Wop03xCBG5kdcUYr/xqzmUSTAXtkWtDpbfJ68KZ/eEhvX9CqY6ZWI 60X32+RnSIFSAqNZzAkgeMRmKL4gH59fpBoDdkSyNMj7OxuI82WCpPfyvQ3DyFe6MeVo E/qvTvcctKW4uU+LACSLSU2ScuLziipi9nuvxBHs/8ZBqug0Yh8fWhwyVdqS+sLTHQPZ xpaa/POskurMF0Y9VL+ZgS2+azrwSzqTjHpXHmqmNuNDmlUQ/2u5eKF68kAgDOaz45wt lc0Q== X-Forwarded-Encrypted: i=1; AFNElJ/1JtKUQtpQxqx+OmfzDa1duMrz2kNXG3WPaPErNe6pvhYZjttbMxBNdtaebeAFOdwlSsoHWd1xq8KzFm00u38=@vger.kernel.org X-Gm-Message-State: AOJu0YzHSMZd7VYoT+fxIXKFPMvZluGAIMpXmS21vzodSLObn9lJwS+K 2+kxGQCfUC2k5izMs9v9HRxFsVfKa7SFyocrbs39dE0u+G4FCxtfVPsh X-Gm-Gg: Acq92OGNnLTY4ejLCcUxHHi8UFg2TJSS6u/hhDRHXMQeIdTDU1YrQ7seWFFjfWN0T8P YP0YQg/gG9AY5onnUoay+OwGBNDnSUBSYE80viwYfPBEfK5fvXhYtcp+zDpKSli9UcpaUwCiPCN XOD6Lvp5gCTtFH1YaHY3M9Cp+5HO3o7CNCDO6mfxeILj1bm88wEoPM529TSoPk66f1DXO4MD3Ja crYXtdf75n4D5o0oRoYM4VT3oXSnri4AaovZPCHnIZRod+bCpPBXVb1pNK3RutdeE87QSsVyCdx PPY/OS/v32NHNrABRg9TVzhLTgdBAxT/E22NohoktaA+/KSZpNiY7R5XWyGHE4o77cvKXXLOOBc W9513QpIhZRy45IBKDPy1xYcootTK+ZraoCXAVsxBLGt4uQvOc7QFKP2KRxND6JNs2HkpAghl6r fqMD9gkZzzFjaqKbgrHT/hDA== X-Received: by 2002:a05:7300:510:b0:2f3:986d:2d01 with SMTP id 5a478bee46e88-30804bbdd85mr548716eec.19.1781139971040; Wed, 10 Jun 2026 18:06:11 -0700 (PDT) Received: from blinky ([2601:647:6700:64d0::92d1]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-30806ebb79bsm71245eec.25.2026.06.10.18.06.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jun 2026 18:06:10 -0700 (PDT) Date: Wed, 10 Jun 2026 18:06:07 -0700 From: Charlie Jenkins To: Nam Cao Cc: Charlie Jenkins via B4 Relay , Paul Walmsley , Palmer Dabbelt , Alexandre Ghiti , Anup Patel , Atish Patra , Conor Dooley , Paolo Bonzini , Andrew Morton , Shuah Khan , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-kselftest@vger.kernel.org Subject: Re: [PATCH 01/16] riscv: Introduce instruction table generation Message-ID: References: <20260407-riscv_insn_table-v1-0-54b4736a1e77@gmail.com> <20260407-riscv_insn_table-v1-1-54b4736a1e77@gmail.com> <878q8m1j9y.fsf@yellow.woof> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <878q8m1j9y.fsf@yellow.woof> On Wed, Jun 10, 2026 at 05:56:25PM +0200, Nam Cao wrote: > Charlie Jenkins via B4 Relay > writes: > > From: Charlie Jenkins > > > > Eliminate the need to hand-write riscv instructions by using a shell > > script to autogenerate a header from an instruction table. This is modeled > > after the syscall table infrastructure. > > > > The table is generated externally by riscv-unified-db [1], but is > > in a simple format to make it possible to use other tools or modify > > manually. > > > > [1] https://github.com/riscv-software-src/riscv-unified-db > > > > Signed-off-by: Charlie Jenkins > > Thanks for the work, I really like the idea. This will make it much > easier to maintain the instruction stuffs. > > > +c.ld common,32 011<13|00<0 imm<3=6-5|12-10 xd!1!3!5!7=4-2 xs1=9-7 > > +c.ld common,64 011<13|00<0 imm<3=6-5|12-10 xd=4-2 xs1=9-7 > > Not sure if I confuse something, but the spec says "C.LD is an > RV64C-only instruction". Why do we have 32 here? This is a weird one. The Ziclsd extension introduces it for RV32[1]. All of the data is generated from the riscv-unified-db and because it is in the Ziclsd extension, c.ld is included for 32-bit in the c.ld description [2]. [1] https://docs.riscv.org/reference/isa/extensions/zilsd/_attachments/riscv-zilsd.pdf [2] https://github.com/riscv/riscv-unified-db/blob/main/spec/std/isa/inst/C/c.ld.yaml > > > +echo "#define COMMA ," >> $outfile > > +echo "#define SEMICOLON ;" >> $outfile > > +echo "#define SINGLE_ARG(...) __VA_ARGS__" >> $outfile > > Aren't these macro unused? Yes thanks, I had them for an earlier version and never removed them. > > > +echo >> $outfile > > + > > +grep -E "^[a-z\.0-9]+[[:space:]]+" "$infile" | { > > + while read name base fixed variables; do > > + echo "/* $name */" > > + > > + compressed_name=${name##c.*} > ^^^^^^^^^^^^^^^ > this name is misleading That's fair, I can rename it to be something like "compressed_inst"? > > > + invalid_inst_functions="" > > + variable_params="" > > + constraints="" > > + match="" > > + mask="" > > + make="" > > + > > + # All compressed instructions start with "c." > > + size=${compressed_name:+32}; > > + size=${size:-16}; > > + > > + # Replace all . with _ > > + formatted_inst_name=$name > > + while [ ! ${formatted_inst_name##*.*} ]; do > > + prefix=${formatted_inst_name%.*} > > + suffix=${formatted_inst_name##*.} > > + contains_dot=${formatted_inst_name##*.*} > > + formatted_inst_name=${contains_dot:-${prefix}_${suffix}} > > + done > > Does the simplier > formatted_inst_name=$(echo $name | tr '.' '_') > work? That does work, but it dramatically slows down the time. I was trying to avoid using external programs because this is called on every compilation and there are a lot of instructions to parse. On my system, it's about 10x slower to use echo/tr. Taking the time from about 150us to 1.5ms for each iteration and the total time from around 0.8s to around 3.5s. > > > + echo "static __always_inline ${type}${size} riscv_insn_${formatted_inst_name}_extract_${variable_name}(u${size} ${insn})" > > + echo "{" > > + echo "\treturn ${extract};" > > + echo "}" > > + echo "static __always_inline void riscv_insn_${formatted_inst_name}_insert_${variable_name}(u${size} *${insn}, ${type}32 ${var})" > > + echo "{" > > + echo "\t*_insn &= ${insert_mask# & };" > > Why is this required? Isn't this part always zero at this point? > > > + echo "\t*_insn |= ${insert# | };" > > + echo "}" > > + > > + if [ "${only_base}" ]; then > > + invalid_inst_functions="${invalid_inst_functions}static __always_inline ${type}${size} riscv_insn_${formatted_inst_name}_extract_${variable_name}(u${size} ${insn}) {\n\tpanic(\"${name} is not supported on non ${only_base}-bit systems.\");\n}\n" > > Instead of panic(), can we do BUILD_BUG() instead? That's a better solution :) - Charlie > > Nam From mboxrd@z Thu Jan 1 00:00:00 1970 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 2ACA3CD98C6 for ; Thu, 11 Jun 2026 01:06:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=PGJVbtkUN+6hR1wJHnfzW9WoV4AeFpsSpKlEdKgdodw=; b=Y6Ux3kKrL0C6IG QHuLUNuzYU56qFuuN0qzdalQvfLzJFRgCggMHSoD+87jqbsU8ieyQzmbaUxeLmZjs8ZRVd3zc9605 tEUUWLz1FnevVXwL9chMY5s8Mub/SDY10hESp2HxiIEpJZGfVgt3/PzH0Ew0RA7rcogO0QtPdfMWN 4TrJxLQnw3XEcqJ4RVrDN5rC393TfNT4XPzOehu718/pW7eBPPyeEnlONahxyA0uxT3+4NemSRsxN DQmPElGFkY8WJWZGxKqQZIZ1/eF3Ej4LYswPPwCUfWIWWqYSg034cDITwSJT0rhfogZ8xakYKDQA5 /3a5Oac+Iz+bD0YRWSaw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1wXTs7-00000008WBM-3I7C; Thu, 11 Jun 2026 01:06:15 +0000 Received: from mail-dy1-x1334.google.com ([2607:f8b0:4864:20::1334]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1wXTs4-00000008WAi-3xtb for linux-riscv@lists.infradead.org; Thu, 11 Jun 2026 01:06:14 +0000 Received: by mail-dy1-x1334.google.com with SMTP id 5a478bee46e88-304d7f31215so6677827eec.1 for ; Wed, 10 Jun 2026 18:06:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1781139971; x=1781744771; darn=lists.infradead.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=VboLQNAR8iiox5vG6qq6qNpSq+23FwPh2uptUxiLAaw=; b=LdgjRiLtfpvIFoGtn9J08Ry+vFo/Hb7Q9IVBg9iSvoKCjfCRoKxV2fZW8RPRMtmw7s n7I7iJO8J4YHtcTYJ3Z4nSpScWdnKODre+QLiiK4Lsb3vpURqtMCpVXEZMm1Lkc6E8xG euggwm7dKzX5e4DiR1HguRZbsFGFsEsQCVZYit7Bh9BcrLfe6VoyqvO9+vX9hf7+ByZl D59uypuvrnDcvhRaFmZmqfgCVs9cAwEsQVU4LdR0b8Pw02DEcta9TOOzElt+wPH7Ns3x 7U+OZulRoKouXE5FZXRubrlbsTgygs4JfzwBdDq14s+CLuH19y14d6kGejdmSFQVQ87m 9XtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781139971; x=1781744771; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VboLQNAR8iiox5vG6qq6qNpSq+23FwPh2uptUxiLAaw=; b=OqzyC2nMRzRkSKC3UC4D8mS3q1wEaCfLBjSRbtWfrY+DUPbWQFbg65Ml+/HXTcYbjX B5vxmXOloppmTdiqRP4DxrWAWTCUq/PY/z/ZOyc2f9aMgJhXxmwO8yGm58fK6a7ReVZe hFqT7xn0wGM5/P39TuJt+CAMjr+U2PR7B2oHQctR5qJALNiAyQBiZp2daApzZR1HzmYU N7UiC4XSRVL1f9FE++EvKkFLP8zFczhuasQE7puGWXYmmNTyLaqfhMMr3EPfyEEePXeL F8JxU21E3hEBoUfQP3d83y2th+OwcFe7jSUprgNuyr2sBLKfcN1DkpeXXNqUkpCiGVn0 b33g== X-Forwarded-Encrypted: i=1; AFNElJ/1VReBKur+NY/cYBx1VCwrMwv89EmFJh2UudHi/KanAwISO2AJyHdfn0y7s/vnCXCMZ6MMFdeE4Xo+/Q==@lists.infradead.org X-Gm-Message-State: AOJu0Yx9IC7jSSGGEx7oU4Ose4227tsi3zhWcjXW06kRucEZNSOGDe+U kL4KXgUiTgAhW4LfaORQvnlgU2uN+JQxgIxNC6aEeLN1TTI9bDu5/wmN X-Gm-Gg: Acq92OErh9BXR3IpfVzFR3yoztu6EARglW+obVg+hDRdO1ZFYH/Bq6QydOp92cQzUxS NOvFhJm1cMSbyI1SwXgztfKapot+rBg6gIq03kC/dU/b/lFszO4AUa0/y3UfGJ5DRwLHwzoAt+F 0H3jHQDGDVgyzxLmMCKt0MV90m+pAxVxZko23ChW/GXQV8VI5bTG9uVJqPvJvsSpXfMOOXao4CD MlDFk2evUujiW7Cq7qKMzuM6tNB6xkGdpAjKzFzpqhO0Ro+Ioh5wDZpOsLXxvrcFxtptQcrOs5Z U0bL7QuyqQDKA6ssGIAEYAuwivrg5RpARzFGzGeifsonxPTL/h5FQ0eyteELP27wPJ2M1Qbm+ak 3fnj0Nx9+GCdBsG0X/uqqHpoRf6ZsaMSoYi8CBNJFtwjrl1DvTlqIIWFYV2PGrEDRa5XT8+AP+J tJZfNIx1VCBMbFnze8JpvTLw== X-Received: by 2002:a05:7300:510:b0:2f3:986d:2d01 with SMTP id 5a478bee46e88-30804bbdd85mr548716eec.19.1781139971040; Wed, 10 Jun 2026 18:06:11 -0700 (PDT) Received: from blinky ([2601:647:6700:64d0::92d1]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-30806ebb79bsm71245eec.25.2026.06.10.18.06.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jun 2026 18:06:10 -0700 (PDT) Date: Wed, 10 Jun 2026 18:06:07 -0700 From: Charlie Jenkins To: Nam Cao Cc: Charlie Jenkins via B4 Relay , Paul Walmsley , Palmer Dabbelt , Alexandre Ghiti , Anup Patel , Atish Patra , Conor Dooley , Paolo Bonzini , Andrew Morton , Shuah Khan , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-kselftest@vger.kernel.org Subject: Re: [PATCH 01/16] riscv: Introduce instruction table generation Message-ID: References: <20260407-riscv_insn_table-v1-0-54b4736a1e77@gmail.com> <20260407-riscv_insn_table-v1-1-54b4736a1e77@gmail.com> <878q8m1j9y.fsf@yellow.woof> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <878q8m1j9y.fsf@yellow.woof> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260610_180612_980143_BE96F3E0 X-CRM114-Status: GOOD ( 26.22 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org On Wed, Jun 10, 2026 at 05:56:25PM +0200, Nam Cao wrote: > Charlie Jenkins via B4 Relay > writes: > > From: Charlie Jenkins > > > > Eliminate the need to hand-write riscv instructions by using a shell > > script to autogenerate a header from an instruction table. This is modeled > > after the syscall table infrastructure. > > > > The table is generated externally by riscv-unified-db [1], but is > > in a simple format to make it possible to use other tools or modify > > manually. > > > > [1] https://github.com/riscv-software-src/riscv-unified-db > > > > Signed-off-by: Charlie Jenkins > > Thanks for the work, I really like the idea. This will make it much > easier to maintain the instruction stuffs. > > > +c.ld common,32 011<13|00<0 imm<3=6-5|12-10 xd!1!3!5!7=4-2 xs1=9-7 > > +c.ld common,64 011<13|00<0 imm<3=6-5|12-10 xd=4-2 xs1=9-7 > > Not sure if I confuse something, but the spec says "C.LD is an > RV64C-only instruction". Why do we have 32 here? This is a weird one. The Ziclsd extension introduces it for RV32[1]. All of the data is generated from the riscv-unified-db and because it is in the Ziclsd extension, c.ld is included for 32-bit in the c.ld description [2]. [1] https://docs.riscv.org/reference/isa/extensions/zilsd/_attachments/riscv-zilsd.pdf [2] https://github.com/riscv/riscv-unified-db/blob/main/spec/std/isa/inst/C/c.ld.yaml > > > +echo "#define COMMA ," >> $outfile > > +echo "#define SEMICOLON ;" >> $outfile > > +echo "#define SINGLE_ARG(...) __VA_ARGS__" >> $outfile > > Aren't these macro unused? Yes thanks, I had them for an earlier version and never removed them. > > > +echo >> $outfile > > + > > +grep -E "^[a-z\.0-9]+[[:space:]]+" "$infile" | { > > + while read name base fixed variables; do > > + echo "/* $name */" > > + > > + compressed_name=${name##c.*} > ^^^^^^^^^^^^^^^ > this name is misleading That's fair, I can rename it to be something like "compressed_inst"? > > > + invalid_inst_functions="" > > + variable_params="" > > + constraints="" > > + match="" > > + mask="" > > + make="" > > + > > + # All compressed instructions start with "c." > > + size=${compressed_name:+32}; > > + size=${size:-16}; > > + > > + # Replace all . with _ > > + formatted_inst_name=$name > > + while [ ! ${formatted_inst_name##*.*} ]; do > > + prefix=${formatted_inst_name%.*} > > + suffix=${formatted_inst_name##*.} > > + contains_dot=${formatted_inst_name##*.*} > > + formatted_inst_name=${contains_dot:-${prefix}_${suffix}} > > + done > > Does the simplier > formatted_inst_name=$(echo $name | tr '.' '_') > work? That does work, but it dramatically slows down the time. I was trying to avoid using external programs because this is called on every compilation and there are a lot of instructions to parse. On my system, it's about 10x slower to use echo/tr. Taking the time from about 150us to 1.5ms for each iteration and the total time from around 0.8s to around 3.5s. > > > + echo "static __always_inline ${type}${size} riscv_insn_${formatted_inst_name}_extract_${variable_name}(u${size} ${insn})" > > + echo "{" > > + echo "\treturn ${extract};" > > + echo "}" > > + echo "static __always_inline void riscv_insn_${formatted_inst_name}_insert_${variable_name}(u${size} *${insn}, ${type}32 ${var})" > > + echo "{" > > + echo "\t*_insn &= ${insert_mask# & };" > > Why is this required? Isn't this part always zero at this point? > > > + echo "\t*_insn |= ${insert# | };" > > + echo "}" > > + > > + if [ "${only_base}" ]; then > > + invalid_inst_functions="${invalid_inst_functions}static __always_inline ${type}${size} riscv_insn_${formatted_inst_name}_extract_${variable_name}(u${size} ${insn}) {\n\tpanic(\"${name} is not supported on non ${only_base}-bit systems.\");\n}\n" > > Instead of panic(), can we do BUILD_BUG() instead? That's a better solution :) - Charlie > > Nam _______________________________________________ linux-riscv mailing list linux-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-riscv