On 5/1/2025 5:02 PM, Alexandre Courbot wrote:
> On Fri May 2, 2025 at 12:19 AM JST, Timur Tabi wrote:
>> On Thu, 2025-05-01 at 21:58 +0900, Alexandre Courbot wrote:
>>
>>
>>> +impl UsizeAlign for usize {
>>> + fn align_up(mut self, align: usize) -> usize {
>>> + self = (self + align - 1) & !(align - 1);
>>> + self
>>> + }
>>> +}
>>> +
>>> +/// Aligns `val` upwards to the nearest multiple of `align`.
>>> +pub const fn usize_align_up(val: usize, align: usize) -> usize {
>>> + (val + align - 1) & !(align - 1)
>>> +}
>>
>> Why not have usize_align_up() just return "val.align_up(align)"?
>>
>> But why why two versions at all? Is there any context where you could use
>> one
>> and not the other?
>
> The second version can be used in const context to create values at
> compile-time, something the first one cannot do. If we want to factorize
> things out we can probably make the first version call the second one
> though.
True. By the way, Timur suggested me to factor it out in a chat so I already did
that in my tree. thanks,
- Joel
- [PATCH v2 12/21] gpu: nova-core: add DMA object struct Alexandre Courbot
- [PATCH v2 13/21] gpu: nova-core: register sysmem flush p... Alexandre Courbot
- [PATCH v2 14/21] gpu: nova-core: add helper function to ... Alexandre Courbot
- [PATCH v2 07/21] gpu: nova-core: fix layout of NV_PMC_BO... Alexandre Courbot
- [PATCH v2 19/21] gpu: nova-core: compute layout of the F... Alexandre Courbot
- [PATCH v2 18/21] nova-core: Add support for VBIOS ucode ... Alexandre Courbot
- [PATCH v2 20/21] gpu: nova-core: extract FWSEC from BIOS... Alexandre Courbot
- [PATCH v2 17/21] rust: num: Add an upward alignment help... Alexandre Courbot
- Re: [PATCH v2 17/21] rust: num: Add an upward align... Timur Tabi
- Re: [PATCH v2 17/21] rust: num: Add an upward a... Alexandre Courbot
- Re: [PATCH v2 17/21] rust: num: Add an upwa... Joel Fernandes
- Re: [PATCH v2 17/21] rust: num: Add an upward a... Joel Fernandes
- Re: [PATCH v2 17/21] rust: num: Add an upwa... Timur Tabi
- Re: [PATCH v2 17/21] rust: num: Add an ... Joel Fernandes
- Re: [PATCH v2 17/21] rust: num: Add an upward align... Alexandre Courbot
- Re: [PATCH v2 17/21] rust: num: Add an upward a... Joel Fernandes
- Re: [PATCH v2 17/21] rust: num: Add an upwa... Alexandre Courbot
- Re: [PATCH v2 17/21] rust: num: Add an ... Joel Fernandes
- Re: [PATCH v2 17/21] rust: num: Ad... Alexandre Courbot
- Re: [PATCH v2 17/21] rust: num... Joel Fernandes
- Re: [PATCH v2 17/21] rust: num... Alexandre Courbot
