drm/i915/selftests: Use mul_u32_u32() for 32b x 32b -> 64b result
authorChris Wilson <chris@chris-wilson.co.uk>
Wed, 13 Sep 2017 10:51:54 +0000 (11:51 +0100)
committerChris Wilson <chris@chris-wilson.co.uk>
Wed, 13 Sep 2017 12:27:20 +0000 (13:27 +0100)
As realised by commit 9e3d6223d209 ("math64, timers: Fix 32bit
mul_u64_u32_shr() and friends"), GCC does not always generate ideal code
for performing a 32b x 32b multiply returning a 64b result (i.e. where
we idiomatically use u64 result = (u64)x * (u32)x).

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Link: https://patchwork.freedesktop.org/patch/msgid/20170913105154.2910-2-chris@chris-wilson.co.uk
Reviewed-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
drivers/gpu/drm/i915/selftests/i915_gem_timeline.c
drivers/gpu/drm/i915/selftests/i915_random.c
drivers/gpu/drm/i915/selftests/i915_random.h

index 7a44dab631b8ece99c8b7d4d50b19dfbdb982bff..4795877abe5611876c7a3fe0f4401cd10b0e4bfe 100644 (file)
@@ -121,7 +121,7 @@ out:
 
 static unsigned int random_engine(struct rnd_state *rnd)
 {
-       return ((u64)prandom_u32_state(rnd) * I915_NUM_ENGINES) >> 32;
+       return i915_prandom_u32_max_state(I915_NUM_ENGINES, rnd);
 }
 
 static int bench_sync(void *arg)
index d044bf9a6feb37e6036b44e83a0a70dc1b7f03cb..ea0f5dbc0eb7d22e90ed5ba10962270ba9cfebb6 100644 (file)
@@ -41,11 +41,6 @@ u64 i915_prandom_u64_state(struct rnd_state *rnd)
        return x;
 }
 
-static inline u32 i915_prandom_u32_max_state(u32 ep_ro, struct rnd_state *state)
-{
-       return upper_32_bits((u64)prandom_u32_state(state) * ep_ro);
-}
-
 void i915_random_reorder(unsigned int *order, unsigned int count,
                         struct rnd_state *state)
 {
index 6c9379871384949f603216359ec511cbd2685b31..7dffedc501cadaf1294dbe1ca4515a5db62c1cdb 100644 (file)
 
 u64 i915_prandom_u64_state(struct rnd_state *rnd);
 
+static inline u32 i915_prandom_u32_max_state(u32 ep_ro, struct rnd_state *state)
+{
+       return upper_32_bits(mul_u32_u32(prandom_u32_state(state), ep_ro));
+}
+
 unsigned int *i915_random_order(unsigned int count,
                                struct rnd_state *state);
 void i915_random_reorder(unsigned int *order,