drm/amd/powerplay: use ARRAY_SIZE() for size of array
Subsystems (2)
PATCH 1/1 drm/amd/powerplay: use ARRAY_SIZE() for size of array
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.
--- drivers/gpu/drm/amd/powerplay/smumgr/cz_smumgr.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/powerplay/smumgr/cz_smumgr.c +2 -1
@@ -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]);
Signature · 1 line
1.9.1
Quoted 5 lines · Muhammad Falak R Wani
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.
sizeof is actually a compile-time thing, so at worst, if no optimisation is made, the runtime result is a division of two literals, eg. for (i = 0; i < 64/8; i++) (which I doubt any compiler would leave as is anyway)
So, +1 on using ARRAY_SIZE, -1 on creating a new variable (which is not even const btw)
Quoted 30 lines
Signed-off-by Muhammad Falak R Wani <[email protected]>--- drivers/gpu/drm/amd/powerplay/smumgr/cz_smumgr.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/powerplay/smumgr/cz_smumgr.c +2
-1@@ -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]);Signature · 6 lines
1.9.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 5 lines · Muhammad Falak R Wani
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.
Quoted 23 lines
Signed-off-by Muhammad Falak R Wani <[email protected]>--- drivers/gpu/drm/amd/powerplay/smumgr/cz_smumgr.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/powerplay/smumgr/cz_smumgr.c +2
-1@@ -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]);
Signature · 5 lines
Jani Nikula, Intel Open Source Technology Center _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 31 lines · Jani Nikula
Quoted 5 lines · Muhammad Falak R Wani
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_SIZEis 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 theARRAY_SIZEin the loop condition.BR,
Jani.Quoted 16 lines
Signed-off-by Muhammad Falak R Wani <[email protected]>--- drivers/gpu/drm/amd/powerplay/smumgr/cz_smumgr.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/powerplay/smumgr/cz_smumgr.c +1
-0@@ -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);
Quoted 10 lines
Quoted 7 lines
drivers/gpu/drm/amd/powerplay/smumgr/cz_smumgr.c +1
-1cz_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]);Signature · 1 line
Jani Nikula, Intel Open Source Technology Center
Should i send a new patch, with these modifications. Sorry for my childish mistake, i got a little too carried away.
Deucher, Alexander
maintainerQuoted 50 lines
-----Original Message-----
From: Muhammad Falak R Wani [mailto:[email protected]]
Sent: Friday, May 13, 2016 1:17 PM
To: Jani Nikula
Cc: Koenig, Christian; Nils Wallménius; Zhou, Jammy; linux- [email protected]; [email protected]; Deucher, Alexander; Zhu, Rex; Dan Carpenter
Subject: Re: [PATCH] drm/amd/powerplay: useARRAY_SIZE()for size of arrayQuoted 1 line · Jani Nikula
On Wed, 11 May 2016, Muhammad Falak R Wani <[email protected]>
Quoted 15 lines · wrote:
Quoted 5 lines
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_SIZEis 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 theARRAY_SIZEin the loop condition.BR,
Jani.Quoted 1 line
Quoted 6 lines
Review
Quoted 6 lines
Signed-off-by Muhammad Falak R Wani <[email protected]>--- drivers/gpu/drm/amd/powerplay/smumgr/cz_smumgr.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)(quoted diff) +0
-0
b/drivers/gpu/drm/amd/powerplay/smumgr/cz_smumgr.cQuoted 4 lines
drivers/gpu/drm/amd/powerplay/smumgr/cz_smumgr.c static int
Quoted 4 lines
index da18f44..718a551 100644
drivers/gpu/drm/amd/powerplay/smumgr/cz_smumgr.c +0
-0@@ -636,10 +636,11 @@ static int
cz_smu_populate_firmware_entries(struct pp_smumgr *smumgr)Quoted 10 lines
Quoted 10 lines
drivers/gpu/drm/amd/powerplay/smumgr/cz_smumgr.c +2
-1int 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++) {
Quoted 8 lines
Quoted 1 line
drivers/gpu/drm/amd/powerplay/smumgr/cz_smumgr.c static int · line 645
Quoted 1 line
drivers/gpu/drm/amd/powerplay/smumgr/cz_smumgr.c +0
-0firmware_type =cz_translate_firmware_enum_to_arg(smumgr,
Quoted 4 lines
drivers/gpu/drm/amd/powerplay/smumgr/cz_smumgr.c static int cz_smu_populate_firmware_entries(struct pp_smumgr *smumgr) · line 646
Quoted 1 line
drivers/gpu/drm/amd/powerplay/smumgr/cz_smumgr.c +0
-0firmware_list[i]);--
Jani Nikula, Intel Open Source Technology CenterShould i send a new patch, with these modifications. Sorry for my childish mistake, i got a little too carried away.
Yes, please send an updated patch.
Thanks,
Alex
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 1 line · Muhammad Falak R Wani
Sorry for my childish mistake, i got a little too carried away.
No need to appologize, it's just a disagreement about style issues.
regards,
dan carpenter
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel