From: David Laight <David.Laight@ACULAB.COM>
To: "'15330273260@189.cn'" <15330273260@189.cn>,
Sui Jingfeng <suijingfeng@loongson.cn>, Li Yi <liyi@loongson.cn>
Cc: Thomas Zimmermann <tzimmermann@suse.de>,
Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
Maxime Ripard <mripard@kernel.org>,
David Airlie <airlied@gmail.com>, Daniel Vetter <daniel@ffwll.ch>,
"dri-devel@lists.freedesktop.org"
<dri-devel@lists.freedesktop.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"loongson-kernel@lists.loongnix.cn"
<loongson-kernel@lists.loongnix.cn>
Subject: RE: [PATCH] drm/drm_vblank.c: avoid unsigned int to signed int cast
Date: Wed, 17 May 2023 10:59:14 +0000 [thread overview]
Message-ID: <f6bd362145124f34a1af800dd330f8e9@AcuMS.aculab.com> (raw)
In-Reply-To: <20230516173026.2990705-1-15330273260@189.cn>
From: 15330273260@189.cn
> Sent: 16 May 2023 18:30
>
> From: Sui Jingfeng <suijingfeng@loongson.cn>
>
> Both mode->crtc_htotal and mode->crtc_vtotal are u16 type,
> mode->crtc_htotal * mode->crtc_vtotal will results a unsigned type.
Nope, u16 gets promoted to 'signed int' and the result of the
multiply is also signed.
> Using a u32 is enough to store the result, but considering that the
> result will be casted to u64 soon after. We use a u64 type directly.
> So there no need to cast it to signed type and cast back then.
....
> - int frame_size = mode->crtc_htotal * mode->crtc_vtotal;
> + u64 frame_size = mode->crtc_htotal * mode->crtc_vtotal;
...
> - framedur_ns = div_u64((u64) frame_size * 1000000, dotclock);
> + framedur_ns = div_u64(frame_size * 1000000, dotclock);
The (u64) cast is there to extend the value to 64bits, not
because the original type is signed.
The compiler will detect that the old code is a 32x32 multiply
where a 64bit result is needed, that may not be true for the
changed code (it would need to track back as far as the u16s).
It is not uncommon to force a 64bit result from a multiply
by making the constant 64bit. As in:
div_u64(frame_size * 1000000ULL, dotclock);
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
next prev parent reply other threads:[~2023-05-17 11:00 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-16 17:30 Sui Jingfeng
2023-05-17 10:59 ` David Laight [this message]
2023-05-17 18:08 ` Sui Jingfeng
2023-05-22 11:29 ` Jani Nikula
2023-05-22 11:55 ` Sui Jingfeng
2023-05-22 12:07 ` David Laight
2023-05-22 12:13 ` Jani Nikula
2023-05-22 12:53 ` Sui Jingfeng
2023-05-22 15:01 ` Jani Nikula
2023-05-23 3:55 ` Sui Jingfeng
2023-05-23 4:26 ` Sui Jingfeng
2023-05-23 8:12 ` Sui Jingfeng
2023-05-23 8:50 ` David Laight
2023-05-23 9:55 ` Sui Jingfeng
-- strict thread matches above, loose matches on Subject: below --
2023-05-16 16:59 Sui Jingfeng
2023-05-16 17:06 ` Thomas Zimmermann
2023-05-16 17:13 ` Sui Jingfeng
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=f6bd362145124f34a1af800dd330f8e9@AcuMS.aculab.com \
--to=david.laight@aculab.com \
--cc=15330273260@189.cn \
--cc=airlied@gmail.com \
--cc=daniel@ffwll.ch \
--cc=dri-devel@lists.freedesktop.org \
--cc=linux-kernel@vger.kernel.org \
--cc=liyi@loongson.cn \
--cc=loongson-kernel@lists.loongnix.cn \
--cc=maarten.lankhorst@linux.intel.com \
--cc=mripard@kernel.org \
--cc=suijingfeng@loongson.cn \
--cc=tzimmermann@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®