On Thu, 8 Oct 2020 at 13:27, Peter Maydell <peter.mayd...@linaro.org> wrote:
>
> On Thu, 8 Oct 2020 at 11:21, Maxim Uvarov <maxim.uva...@linaro.org> wrote:
> >
> > On Thu, 8 Oct 2020 at 05:43, Shashi Mallela <shashi.mall...@linaro.org> 
> > wrote:
> > > +static void sbsa_gwdt_update_timer(SBSA_GWDTState *s)
> > > +{
> > > +    uint64_t timeout = 0;
> > > +
> > > +    if (s->enabled) {
> > > +        /*
> > > +         * Extract the upper 16 bits from woru & 32 bits from worl
> > > +         * registers to construct the 48 bit offset value
> > > +         */
> > > +        timeout = s->woru & SBSA_GWDT_WOR_MASK;
> > > +        timeout <<= 32;
> > > +        timeout |= s->worl;
> > > +        timeout = muldiv64(timeout, NANOSECONDS_PER_SECOND, 
> > > SBSA_TIMER_FREQ);
> >
> > static inline uint64_t muldiv64(uint64_t a, uint32_t b, uint32_t c)
> > {
> >     return (__int128_t)a * b / c;
> > }
> >
> > #define NANOSECONDS_PER_SECOND 1000000000LL
> >
> > Interesting why gcc does not warn on  64bit signed to 32bit unsigned
> > truncation here. Looks like it's too smart to understand
> > that value fits in 32 bits.
>
> What truncation? 1000000000 in decimal is 0x3B9ACA00 in hex:
> the number fits in an 32 bit integer without truncation.
>
> (ns = muldiv64(ticks, NANOSECONDS_PER_SECOND, frequency) is a pretty
> common pattern in our timer devices for converting a number of
> ticks to a duration in nanoseconds, as is the reverse
> conversion of ticks = muldiv64(ns, NANOSECONDS_PER_SECOND, frequency).)
>
> thanks
> -- PMM

I meant that LL is an long long int which is 64 bit size type. And
then you pass it to uint32_t.

Reply via email to