[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] RISCV/bitops: Use Zbb to provide arch-optimised bitops


  • To: Oleksii Kurochko <oleksii.kurochko@xxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Wed, 26 Mar 2025 11:15:33 +0100
  • Autocrypt: addr=jbeulich@xxxxxxxx; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJkiwGPXbWtPxl2xCdSoeepS07jW8UgcHNurfHvUzogEq5xk hu507c3BarVjyWCJOylMNR98Yd8VqD9UfmX0Hb8/BrA+Hl6/DB/eqGptrf4BSRwcZQM32aZK 7Pj2XbGWIUrZrd70x1eAP9QE3P79Y2oLrsCgbZJfEwCgvz9JjGmQqQkRiTVzlZVCJYcyGGsD /0tbFCzD2h20ahe8rC1gbb3K3qk+LpBtvjBu1RY9drYk0NymiGbJWZgab6t1jM7sk2vuf0Py O9Hf9XBmK0uE9IgMaiCpc32XV9oASz6UJebwkX+zF2jG5I1BfnO9g7KlotcA/v5ClMjgo6Gl MDY4HxoSRu3i1cqqSDtVlt+AOVBJBACrZcnHAUSuCXBPy0jOlBhxPqRWv6ND4c9PH1xjQ3NP nxJuMBS8rnNg22uyfAgmBKNLpLgAGVRMZGaGoJObGf72s6TeIqKJo/LtggAS9qAUiuKVnygo 3wjfkS9A3DRO+SpU7JqWdsveeIQyeyEJ/8PTowmSQLakF+3fote9ybzd880fSmFuIEJldWxp Y2ggPGpiZXVsaWNoQHN1c2UuY29tPsJgBBMRAgAgBQJZN5xEAhsDBgsJCAcDAgQVAggDBBYC AwECHgECF4AACgkQoDSui/t3IH4J+wCfQ5jHdEjCRHj23O/5ttg9r9OIruwAn3103WUITZee e7Sbg12UgcQ5lv7SzsFNBFk3nEQQCACCuTjCjFOUdi5Nm244F+78kLghRcin/awv+IrTcIWF hUpSs1Y91iQQ7KItirz5uwCPlwejSJDQJLIS+QtJHaXDXeV6NI0Uef1hP20+y8qydDiVkv6l IreXjTb7DvksRgJNvCkWtYnlS3mYvQ9NzS9PhyALWbXnH6sIJd2O9lKS1Mrfq+y0IXCP10eS FFGg+Av3IQeFatkJAyju0PPthyTqxSI4lZYuJVPknzgaeuJv/2NccrPvmeDg6Coe7ZIeQ8Yj t0ARxu2xytAkkLCel1Lz1WLmwLstV30g80nkgZf/wr+/BXJW/oIvRlonUkxv+IbBM3dX2OV8 AmRv1ySWPTP7AAMFB/9PQK/VtlNUJvg8GXj9ootzrteGfVZVVT4XBJkfwBcpC/XcPzldjv+3 HYudvpdNK3lLujXeA5fLOH+Z/G9WBc5pFVSMocI71I8bT8lIAzreg0WvkWg5V2WZsUMlnDL9 mpwIGFhlbM3gfDMs7MPMu8YQRFVdUvtSpaAs8OFfGQ0ia3LGZcjA6Ik2+xcqscEJzNH+qh8V m5jjp28yZgaqTaRbg3M/+MTbMpicpZuqF4rnB0AQD12/3BNWDR6bmh+EkYSMcEIpQmBM51qM EKYTQGybRCjpnKHGOxG0rfFY1085mBDZCH5Kx0cl0HVJuQKC+dV2ZY5AqjcKwAxpE75MLFkr wkkEGBECAAkFAlk3nEQCGwwACgkQoDSui/t3IH7nnwCfcJWUDUFKdCsBH/E5d+0ZnMQi+G0A nAuWpQkjM1ASeQwSHEeAWPgskBQL
  • Cc: Xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
  • Delivery-date: Wed, 26 Mar 2025 10:15:39 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 25.03.2025 18:04, Oleksii Kurochko wrote:
> 
> On 3/25/25 5:46 PM, Jan Beulich wrote:
>> On 25.03.2025 17:35, Oleksii Kurochko wrote:
>>> On 3/7/25 1:12 PM, Andrew Cooper wrote:
>>>> On 07/03/2025 12:01 pm, Jan Beulich wrote:
>>>>> On 07.03.2025 12:50, Oleksii Kurochko wrote:
>>>>>> On 3/6/25 9:19 PM, Andrew Cooper wrote:
>>>>>>> On 05/03/2025 7:34 am, Jan Beulich wrote:
>>>>>>>> I was actually hoping to eliminate BITS_PER_LONG at some point, in 
>>>>>>>> favor
>>>>>>>> of using sizeof(long) * BITS_PER_BYTE. (Surely in common code we could
>>>>>>>> retain a shorthand of that name, if so desired, but I see no reason why
>>>>>>>> each arch would need to provide all three BITS_PER_{BYTE,INT,LONG}.)
>>>>>>> The concern is legibility and clarity.
>>>>>>>
>>>>>>> This:
>>>>>>>
>>>>>>>        ((x) ? 32 - __builtin_clz(x) : 0)
>>>>>>>
>>>>>>> is a clear expression in a way that this:
>>>>>>>
>>>>>>>        ((x) ? (sizeof(int) * BITS_PER_BYTE) - __builtin_clz(x) : 0)
>>>>>>>
>>>>>>> is not.  The problem is the extra binary expression, and this:
>>>>>>>
>>>>>>>        ((x) ? BITS_PER_INT - __builtin_clz(x) : 0)
>>>>>>>
>>>>>>> is still clear, because the reader doesn't have to perform a multiply to
>>>>>>> just to figure out what's going on.
>>>>>>>
>>>>>>>
>>>>>>> It is definitely stupid to have each architecture provide their own
>>>>>>> BITS_PER_*.  The compiler is in a superior position to provide those
>>>>>>> details, and it should be in a common location.
>>>>>>>
>>>>>>> I don't particularly mind how those constants are derived, but one key
>>>>>>> thing that BITS_PER_* can do which sizeof() can't is be used in 
>>>>>>> #ifdef/etc.
>>>>>> What about moving them to xen/config.h? (if it isn't the best one place, 
>>>>>> any suggestion which is better?)
>>>>>>
>>>>>> #define BYTES_PER_INT  (1 << INT_BYTEORDER)
>>>>>> #define BITS_PER_INT  (BYTES_PER_INT << 3)
>>>>>>
>>>>>> #define BYTES_PER_LONG (1 << LONG_BYTEORDER)
>>>>>> #define BITS_PER_LONG (BYTES_PER_LONG << 3)
>>>>>> #define BITS_PER_BYTE 8
>>>> The *_BYTEORDER's are useless indirection.  BITS_PER_* should be defined
>>>> straight up, and this will simplify quite a lot of preprocessing.
>>> Could we really drop *_BYTEORDER?
>>>
>>> For example, LONG_BYTEORDER for Arm could be either 2 or 3 depends on Arm32 
>>> or Arm64 is used.
>> The can still #define BITS_PER_LONG to 32 or 64 respectively, can't they?
> 
> Yes, but then if we want to move it to xen/config.h then it will be needed to:
> in Arm's asm/config.h to have something like:
>    #ifdef CONFIG_ARM_32
>        #define BITS_PER_LONG 32
>    #endif
> 
> and then in xen/config.h
>    #ifndef BITS_PER_LONG
>        #define BITS_PER_LONG 64
>    #endif
> 
> But I wanted to not have #ifndef BITS_PER_LONG in xen/config.h. (or using 
> CONFIG_ARM_32 in xen/config.h)

Whatever the fundamental definitions that can vary per arch - those should
imo live in asm/config.h. For the case here, if we deem *_BYTEORDER as
fundamental, they go there (and BITS_PER_* go into xen/config.h). If we deem
BITS_PER_* fundamental, they go into asm/config.h.

Stuff that we expect to remain uniform across ports (BITS_PER_BYTE, possibly
also BITS_PER_INT BITS_PER_LLONG) may also go into xen/config.h, as long as
we're okay with the possible future churn if a port appeared that has
different needs.

I agree that there better wouldn't be #ifndef for such in xen/config.h.

Jan



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.