Re: [PATCH RFC v3 6/7] gpu: nova-core: add basic timer device

From: Daniel Brooks
Date: Thu Mar 20 2025 - 11:55:13 EST


Alexandre Courbot <acourbot@xxxxxxxxxx> writes:

> +impl Add<Duration> for Timestamp {
> + type Output = Self;
> +
> + fn add(mut self, rhs: Duration) -> Self::Output {
> + let mut nanos = rhs.as_nanos();
> + while nanos > u64::MAX as u128 {
> + self.0 = self.0.wrapping_add(nanos as u64);
> + nanos -= u64::MAX as u128;
> + }
> +
> + Timestamp(self.0.wrapping_add(nanos as u64))
> + }
> +}

Perhaps I missed something, but couldn’t you simplify this method like
this:

fn add(mut self, rhs: Duration) -> Self::Output {
let stamp = self.0 as u128;
Timestamp(stamp.wrapping_add(rhs.as_nanos()) as u64)
}

db48x