public inbox for intel-gfx@lists.freedesktop.org
 help / color / mirror / Atom feed
* [PATCH i-g-t] benchmarks/gem_wsim: Tidy manual sizeof VLA calculations
@ 2019-05-27  9:46 Chris Wilson
  2019-06-03 12:53 ` [igt-dev] " Tvrtko Ursulin
  0 siblings, 1 reply; 2+ messages in thread
From: Chris Wilson @ 2019-05-27  9:46 UTC (permalink / raw)
  To: intel-gfx; +Cc: igt-dev

We can use offsetof for the same effect, much tidier with no dummy
locals.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
---
 benchmarks/gem_wsim.c | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)

diff --git a/benchmarks/gem_wsim.c b/benchmarks/gem_wsim.c
index db19925b1..a76fdbfe2 100644
--- a/benchmarks/gem_wsim.c
+++ b/benchmarks/gem_wsim.c
@@ -1443,23 +1443,20 @@ set_ctx_sseu(struct ctx *ctx, uint64_t slice_mask)
 
 static size_t sizeof_load_balance(int count)
 {
-	struct i915_context_engines_load_balance *ptr;
-
-	return sizeof(*ptr) + count * sizeof(ptr->engines[0]);
+	return offsetof(struct i915_context_engines_load_balance,
+			engines[count]);
 }
 
 static size_t sizeof_param_engines(int count)
 {
-	struct i915_context_param_engines *ptr;
-
-	return sizeof(*ptr) + count * sizeof(ptr->engines[0]);
+	return offsetof(struct i915_context_param_engines,
+			engines[count]);
 }
 
 static size_t sizeof_engines_bond(int count)
 {
-	struct i915_context_engines_bond *ptr;
-
-	return sizeof(*ptr) + count * sizeof(ptr->engines[0]);
+	return offsetof(struct i915_context_engines_bond,
+			engines[count]);
 }
 
 #define alloca0(sz) ({ size_t sz__ = (sz); memset(alloca(sz__), 0, sz__); })
-- 
2.20.1

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [igt-dev] [PATCH i-g-t] benchmarks/gem_wsim: Tidy manual sizeof VLA calculations
  2019-05-27  9:46 [PATCH i-g-t] benchmarks/gem_wsim: Tidy manual sizeof VLA calculations Chris Wilson
@ 2019-06-03 12:53 ` Tvrtko Ursulin
  0 siblings, 0 replies; 2+ messages in thread
From: Tvrtko Ursulin @ 2019-06-03 12:53 UTC (permalink / raw)
  To: Chris Wilson, intel-gfx; +Cc: igt-dev


On 27/05/2019 10:46, Chris Wilson wrote:
> We can use offsetof for the same effect, much tidier with no dummy
> locals.
> 
> Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
> Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
> ---
>   benchmarks/gem_wsim.c | 15 ++++++---------
>   1 file changed, 6 insertions(+), 9 deletions(-)
> 
> diff --git a/benchmarks/gem_wsim.c b/benchmarks/gem_wsim.c
> index db19925b1..a76fdbfe2 100644
> --- a/benchmarks/gem_wsim.c
> +++ b/benchmarks/gem_wsim.c
> @@ -1443,23 +1443,20 @@ set_ctx_sseu(struct ctx *ctx, uint64_t slice_mask)
>   
>   static size_t sizeof_load_balance(int count)
>   {
> -	struct i915_context_engines_load_balance *ptr;
> -
> -	return sizeof(*ptr) + count * sizeof(ptr->engines[0]);
> +	return offsetof(struct i915_context_engines_load_balance,
> +			engines[count]);
>   }
>   
>   static size_t sizeof_param_engines(int count)
>   {
> -	struct i915_context_param_engines *ptr;
> -
> -	return sizeof(*ptr) + count * sizeof(ptr->engines[0]);
> +	return offsetof(struct i915_context_param_engines,
> +			engines[count]);
>   }
>   
>   static size_t sizeof_engines_bond(int count)
>   {
> -	struct i915_context_engines_bond *ptr;
> -
> -	return sizeof(*ptr) + count * sizeof(ptr->engines[0]);
> +	return offsetof(struct i915_context_engines_bond,
> +			engines[count]);
>   }
>   
>   #define alloca0(sz) ({ size_t sz__ = (sz); memset(alloca(sz__), 0, sz__); })
> 

Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>

Regards,

Tvrtko
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-06-03 12:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-05-27  9:46 [PATCH i-g-t] benchmarks/gem_wsim: Tidy manual sizeof VLA calculations Chris Wilson
2019-06-03 12:53 ` [igt-dev] " Tvrtko Ursulin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox