* [PATCH] drm/amd/powerplay: use ARRAY_SIZE() for size of array @ 2016-05-11 17:48 Muhammad Falak R Wani 2016-05-12 9:49 ` Eric Engestrom 2016-05-12 9:53 ` Jani Nikula 0 siblings, 2 replies; 6+ messages in thread From: Muhammad Falak R Wani @ 2016-05-11 17:48 UTC (permalink / raw) To: Christian Knig Cc: Alex Deucher, David Airlie, Rex Zhu, Nils Wallménius, Dan Carpenter, Jammy Zhou, dri-devel, linux-kernel 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. 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]); -- 1.9.1 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] drm/amd/powerplay: use ARRAY_SIZE() for size of array 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:53 ` Jani Nikula 1 sibling, 0 replies; 6+ messages in thread From: Eric Engestrom @ 2016-05-12 9:49 UTC (permalink / raw) To: Muhammad Falak R Wani Cc: Christian Knig, Nils Wallménius, Jammy Zhou, linux-kernel, dri-devel, Alex Deucher, Rex Zhu, Dan Carpenter On Wed, May 11, 2016 at 11:18:43PM +0530, Muhammad Falak R Wani 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. `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) > > 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]); > -- > 1.9.1 > > _______________________________________________ > dri-devel mailing list > dri-devel@lists.freedesktop.org > https://lists.freedesktop.org/mailman/listinfo/dri-devel ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] drm/amd/powerplay: use ARRAY_SIZE() for size of array 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:53 ` Jani Nikula 2016-05-13 17:17 ` Muhammad Falak R Wani 1 sibling, 1 reply; 6+ messages in thread From: Jani Nikula @ 2016-05-12 9:53 UTC (permalink / raw) To: Muhammad Falak R Wani, Christian Knig Cc: Nils Wallménius, Jammy Zhou, linux-kernel, dri-devel, Alex Deucher, Rex Zhu, Dan Carpenter 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 ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] drm/amd/powerplay: use ARRAY_SIZE() for size of array 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 20:21 ` Dan Carpenter 0 siblings, 2 replies; 6+ messages in thread From: Muhammad Falak R Wani @ 2016-05-13 17:17 UTC (permalink / raw) To: Jani Nikula Cc: Christian Knig, Nils Wallménius, Jammy Zhou, linux-kernel, dri-devel, Alex Deucher, Rex Zhu, Dan Carpenter On Thu, May 12, 2016 at 12:53:48PM +0300, Jani Nikula wrote: > 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 Should i send a new patch, with these modifications. Sorry for my childish mistake, i got a little too carried away. ^ permalink raw reply [flat|nested] 6+ messages in thread
* RE: [PATCH] drm/amd/powerplay: use ARRAY_SIZE() for size of array 2016-05-13 17:17 ` Muhammad Falak R Wani @ 2016-05-13 17:23 ` Deucher, Alexander 2016-05-13 20:21 ` Dan Carpenter 1 sibling, 0 replies; 6+ messages in thread From: Deucher, Alexander @ 2016-05-13 17:23 UTC (permalink / raw) To: 'Muhammad Falak R Wani', Jani Nikula Cc: Koenig, Christian, Nils Wallménius, Zhou, Jammy, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Zhu, Rex, Dan Carpenter > -----Original Message----- > From: Muhammad Falak R Wani [mailto:falakreyaz@gmail.com] > Sent: Friday, May 13, 2016 1:17 PM > To: Jani Nikula > Cc: Koenig, Christian; Nils Wallménius; Zhou, Jammy; linux- > kernel@vger.kernel.org; dri-devel@lists.freedesktop.org; Deucher, > Alexander; Zhu, Rex; Dan Carpenter > Subject: Re: [PATCH] drm/amd/powerplay: use ARRAY_SIZE() for size of > array > > On Thu, May 12, 2016 at 12:53:48PM +0300, Jani Nikula wrote: > > 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 > Should 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 ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] drm/amd/powerplay: use ARRAY_SIZE() for size of array 2016-05-13 17:17 ` Muhammad Falak R Wani 2016-05-13 17:23 ` Deucher, Alexander @ 2016-05-13 20:21 ` Dan Carpenter 1 sibling, 0 replies; 6+ messages in thread From: Dan Carpenter @ 2016-05-13 20:21 UTC (permalink / raw) To: Muhammad Falak R Wani Cc: Jani Nikula, Christian Knig, Nils Wallménius, Jammy Zhou, linux-kernel, dri-devel, Alex Deucher, Rex Zhu On Fri, May 13, 2016 at 10:47:05PM +0530, Muhammad Falak R Wani wrote: > 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 ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2016-05-13 20:21 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 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:53 ` Jani Nikula 2016-05-13 17:17 ` Muhammad Falak R Wani 2016-05-13 17:23 ` Deucher, Alexander 2016-05-13 20:21 ` Dan Carpenter
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox