[PATCH 07/19] riscv: Optimize riscv_cpu_isa_extension_(un)likely()

Conor Dooley conor at kernel.org
Fri Apr 12 13:33:20 PDT 2024


On Fri, Apr 12, 2024 at 10:34:28AM -0700, Charlie Jenkins wrote:
> On Fri, Apr 12, 2024 at 11:40:38AM +0100, Conor Dooley wrote:
> > On Thu, Apr 11, 2024 at 09:11:13PM -0700, Charlie Jenkins wrote:
> > > When alternatives are disabled, riscv_cpu_isa_extension_(un)likely()
> > > checks if the current cpu supports the selected extension if not all
> > > cpus support the extension. It is sufficient to only check if the
> > > current cpu supports the extension.
> > > 
> > > The alternatives code to handle if all cpus support an extension is
> > > factored out into a new function to support this.
> > > 
> > > Signed-off-by: Charlie Jenkins <charlie at rivosinc.com>
> > > ---
> > 
> > >  static __always_inline bool riscv_cpu_has_extension_unlikely(int cpu, const unsigned long ext)
> > >  {
> > > -	if (IS_ENABLED(CONFIG_RISCV_ALTERNATIVE) && riscv_has_extension_unlikely(ext))
> > > -		return true;
> > > +	compiletime_assert(ext < RISCV_ISA_EXT_MAX,
> > > +			   "ext must be < RISCV_ISA_EXT_MAX");
> > >  
> > > -	return __riscv_isa_extension_available(hart_isa[cpu].isa, ext);
> > > +	if (IS_ENABLED(CONFIG_RISCV_ALTERNATIVE) && __riscv_has_extension_unlikely_alternatives(ext))
> > > +		return true;
> > > +	else
> > > +		return __riscv_isa_extension_available(hart_isa[cpu].isa, ext);
> > >  }
> > 
> > static __always_inline bool riscv_cpu_has_extension_likely(int cpu, const unsigned long ext)
> > {
> > 	if (IS_ENABLED(CONFIG_RISCV_ALTERNATIVE) && riscv_has_extension_likely(ext))
> > 		return true;
> > 
> > 	return __riscv_isa_extension_available(hart_isa[cpu].isa, ext);
> > }
> > 
> > This is the code as things stand. If alternatives are disabled, the if
> > statement becomes if (0 && foo) which will lead to the function call
> > getting constant folded away and all you end up with is the call to
> > __riscv_isa_extension_available(). Unless I am missing something, I don't
> > think this patch has any affect?
> 
> Yeah I fumbled this one it appears. I got thrown off by the nested
> IS_ENABLED(CONFIG_RISCV_ALTERNATIVE). This patch eliminates the need for
> this and maybe can avoid avoid confusion in the future.

I think it just creates unneeded functions and can/should be dropped.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 228 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20240412/d0fe35e3/attachment.sig>


More information about the linux-arm-kernel mailing list