lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <a5d078a5-2995-4fcd-bdfa-096e544db07a@nvidia.com>
Date: Thu, 1 May 2025 17:52:24 -0400
From: Joel Fernandes <joelagnelf@...dia.com>
To: Alexandre Courbot <acourbot@...dia.com>, Timur Tabi <ttabi@...dia.com>,
 "dakr@...nel.org" <dakr@...nel.org>,
 "a.hindborg@...nel.org" <a.hindborg@...nel.org>,
 "ojeda@...nel.org" <ojeda@...nel.org>,
 "boqun.feng@...il.com" <boqun.feng@...il.com>,
 "simona@...ll.ch" <simona@...ll.ch>, "tmgross@...ch.edu"
 <tmgross@...ch.edu>, "alex.gaynor@...il.com" <alex.gaynor@...il.com>,
 "tzimmermann@...e.de" <tzimmermann@...e.de>, "corbet@....net"
 <corbet@....net>, "mripard@...nel.org" <mripard@...nel.org>,
 "maarten.lankhorst@...ux.intel.com" <maarten.lankhorst@...ux.intel.com>,
 "benno.lossin@...ton.me" <benno.lossin@...ton.me>,
 "bjorn3_gh@...tonmail.com" <bjorn3_gh@...tonmail.com>,
 "airlied@...il.com" <airlied@...il.com>,
 "aliceryhl@...gle.com" <aliceryhl@...gle.com>,
 "gary@...yguo.net" <gary@...yguo.net>
Cc: Alistair Popple <apopple@...dia.com>, John Hubbard <jhubbard@...dia.com>,
 "rust-for-linux@...r.kernel.org" <rust-for-linux@...r.kernel.org>,
 "dri-devel@...ts.freedesktop.org" <dri-devel@...ts.freedesktop.org>,
 "nouveau@...ts.freedesktop.org" <nouveau@...ts.freedesktop.org>,
 "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
 Ben Skeggs <bskeggs@...dia.com>
Subject: Re: [PATCH v2 17/21] rust: num: Add an upward alignment helper for
 usize



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


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ