From: Jani Nikula <jani.nikula@linux.intel.com>
To: Muhammad Falak R Wani <falakreyaz@gmail.com>,
Christian Knig <christian.koenig@amd.com>
Cc: "Nils Wallménius" <nils.wallmenius@gmail.com>,
"Jammy Zhou" <Jammy.Zhou@amd.com>,
linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org,
"Alex Deucher" <alexander.deucher@amd.com>,
"Rex Zhu" <Rex.Zhu@amd.com>,
"Dan Carpenter" <dan.carpenter@oracle.com>
Subject: Re: [PATCH] drm/amd/powerplay: use ARRAY_SIZE() for size of array
Date: Thu, 12 May 2016 12:53:48 +0300 [thread overview]
Message-ID: <877feziour.fsf@intel.com> (raw)
In-Reply-To: <1462988936-13486-1-git-send-email-falakreyaz@gmail.com>
On Wed, 11 May 2016, Muhammad Falak R Wani <falakreyaz@gmail.com> wrote:
> Use ARRAY_SIZE() for the size calculation of the array. Also move the
> condition evaulation function out of the for loop.
> Although, any respectable c-compiler would optimize this and evaluate
> the function only once outside the loop, but the optimzation engine
> of gcc is bit brain-dead, and at times needs some hand holding.
This just caught my eye. ARRAY_SIZE is a macro that expands to a compile
time constant. Arguably adding the the local variable here gives GCC
more chances to go wrong than keeping the ARRAY_SIZE in the loop
condition.
BR,
Jani.
>
> Signed-off-by: Muhammad Falak R Wani <falakreyaz@gmail.com>
> ---
> drivers/gpu/drm/amd/powerplay/smumgr/cz_smumgr.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/amd/powerplay/smumgr/cz_smumgr.c b/drivers/gpu/drm/amd/powerplay/smumgr/cz_smumgr.c
> index da18f44..718a551 100644
> --- a/drivers/gpu/drm/amd/powerplay/smumgr/cz_smumgr.c
> +++ b/drivers/gpu/drm/amd/powerplay/smumgr/cz_smumgr.c
> @@ -636,10 +636,11 @@ static int cz_smu_populate_firmware_entries(struct pp_smumgr *smumgr)
> int ret;
> enum cgs_ucode_id ucode_id;
> struct cgs_firmware_info info = {0};
> + int n = ARRAY_SIZE(firmware_list);
>
> cz_smu->driver_buffer_length = 0;
>
> - for (i = 0; i < sizeof(firmware_list)/sizeof(*firmware_list); i++) {
> + for (i = 0; i < n; i++) {
>
> firmware_type = cz_translate_firmware_enum_to_arg(smumgr,
> firmware_list[i]);
--
Jani Nikula, Intel Open Source Technology Center
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
WARNING: multiple messages have this Message-ID (diff)
From: Jani Nikula <jani.nikula@linux.intel.com>
To: Muhammad Falak R Wani <falakreyaz@gmail.com>,
Christian Knig <christian.koenig@amd.com>
Cc: "Nils Wallménius" <nils.wallmenius@gmail.com>,
"Jammy Zhou" <Jammy.Zhou@amd.com>,
linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org,
"Alex Deucher" <alexander.deucher@amd.com>,
"Rex Zhu" <Rex.Zhu@amd.com>,
"Dan Carpenter" <dan.carpenter@oracle.com>
Subject: Re: [PATCH] drm/amd/powerplay: use ARRAY_SIZE() for size of array
Date: Thu, 12 May 2016 12:53:48 +0300 [thread overview]
Message-ID: <877feziour.fsf@intel.com> (raw)
In-Reply-To: <1462988936-13486-1-git-send-email-falakreyaz@gmail.com>
On Wed, 11 May 2016, Muhammad Falak R Wani <falakreyaz@gmail.com> wrote:
> Use ARRAY_SIZE() for the size calculation of the array. Also move the
> condition evaulation function out of the for loop.
> Although, any respectable c-compiler would optimize this and evaluate
> the function only once outside the loop, but the optimzation engine
> of gcc is bit brain-dead, and at times needs some hand holding.
This just caught my eye. ARRAY_SIZE is a macro that expands to a compile
time constant. Arguably adding the the local variable here gives GCC
more chances to go wrong than keeping the ARRAY_SIZE in the loop
condition.
BR,
Jani.
>
> Signed-off-by: Muhammad Falak R Wani <falakreyaz@gmail.com>
> ---
> drivers/gpu/drm/amd/powerplay/smumgr/cz_smumgr.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/amd/powerplay/smumgr/cz_smumgr.c b/drivers/gpu/drm/amd/powerplay/smumgr/cz_smumgr.c
> index da18f44..718a551 100644
> --- a/drivers/gpu/drm/amd/powerplay/smumgr/cz_smumgr.c
> +++ b/drivers/gpu/drm/amd/powerplay/smumgr/cz_smumgr.c
> @@ -636,10 +636,11 @@ static int cz_smu_populate_firmware_entries(struct pp_smumgr *smumgr)
> int ret;
> enum cgs_ucode_id ucode_id;
> struct cgs_firmware_info info = {0};
> + int n = ARRAY_SIZE(firmware_list);
>
> cz_smu->driver_buffer_length = 0;
>
> - for (i = 0; i < sizeof(firmware_list)/sizeof(*firmware_list); i++) {
> + for (i = 0; i < n; i++) {
>
> firmware_type = cz_translate_firmware_enum_to_arg(smumgr,
> firmware_list[i]);
--
Jani Nikula, Intel Open Source Technology Center
next prev parent reply other threads:[~2016-05-12 9:53 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-11 17:48 [PATCH] drm/amd/powerplay: use ARRAY_SIZE() for size of array Muhammad Falak R Wani
2016-05-12 9:49 ` Eric Engestrom
2016-05-12 9:49 ` Eric Engestrom
2016-05-12 9:53 ` Jani Nikula [this message]
2016-05-12 9:53 ` Jani Nikula
2016-05-13 17:17 ` Muhammad Falak R Wani
2016-05-13 17:23 ` Deucher, Alexander
2016-05-13 17:23 ` Deucher, Alexander
2016-05-13 20:21 ` Dan Carpenter
2016-05-13 20:21 ` Dan Carpenter
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=877feziour.fsf@intel.com \
--to=jani.nikula@linux.intel.com \
--cc=Jammy.Zhou@amd.com \
--cc=Rex.Zhu@amd.com \
--cc=alexander.deucher@amd.com \
--cc=christian.koenig@amd.com \
--cc=dan.carpenter@oracle.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=falakreyaz@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=nils.wallmenius@gmail.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.