[PATCH 5/5] drm/i915: Tidy up fixed16_16

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Tidy up fixed16_16 code before promoting it to the include/linux.

Signed-off-by: Michal Wajdeczko <michal.wajdeczko@xxxxxxxxx>
Cc: Chris Wilson <chris@xxxxxxxxxxxxxxxxxx>
Cc: Rodrigo Vivi <rodrigo.vivi@xxxxxxxxx>
Cc: Joonas Lahtinen <joonas.lahtinen@xxxxxxxxxxxxxxx>
---
 drivers/gpu/drm/i915/fixed16_16.h | 96 ++++++++++++++++++---------------------
 1 file changed, 43 insertions(+), 53 deletions(-)

diff --git a/drivers/gpu/drm/i915/fixed16_16.h b/drivers/gpu/drm/i915/fixed16_16.h
index 43fe0037..a2f8736 100644
--- a/drivers/gpu/drm/i915/fixed16_16.h
+++ b/drivers/gpu/drm/i915/fixed16_16.h
@@ -46,21 +46,19 @@
 	fp; \
 })
 
-static inline bool is_fixed16_zero(fixed16_16_t val)
+static inline bool is_fixed16_zero(fixed16_16_t fp)
 {
-	if (val.val == 0)
-		return true;
-	return false;
+	return fp.val == 0;
 }
 
-static inline fixed16_16_t u32_to_fixed16(u32 val)
+static inline fixed16_16_t u32_to_fixed16(u32 value)
 {
 	fixed16_16_t fp;
 
-	if (WARN_ON(val > U16_MAX))
-		val = U16_MAX;
+	if (WARN_ON(value > U16_MAX))
+		value = U16_MAX;
 
-	fp.val = val << 16;
+	fp.val = value << 16;
 	return fp;
 }
 
@@ -76,99 +74,91 @@ static inline u32 fixed16_to_u32(fixed16_16_t fp)
 
 static inline fixed16_16_t min_fixed16(fixed16_16_t min1, fixed16_16_t min2)
 {
-	fixed16_16_t min;
-
-	min.val = min(min1.val, min2.val);
-	return min;
+	if (min1.val <= min2.val)
+		return min1;
+	return min2;
 }
 
 static inline fixed16_16_t max_fixed16(fixed16_16_t max1, fixed16_16_t max2)
 {
-	fixed16_16_t max;
-
-	max.val = max(max1.val, max2.val);
-	return max;
+	if (max1.val >= max2.val)
+		return max1;
+	return max2;
 }
 
-static inline fixed16_16_t clamp_u64_to_fixed16(u64 val)
+static inline fixed16_16_t clamp_u64_to_fixed16(u64 value)
 {
 	fixed16_16_t fp;
 
-	if (WARN_ON(val > U32_MAX))
-		val = U32_MAX;
+	if (WARN_ON(value > U32_MAX))
+		value = U32_MAX;
 
-	fp.val = (u32) val;
+	fp.val = value;
 	return fp;
 }
 
-static inline u32 div_round_up_fixed16(fixed16_16_t val, fixed16_16_t d)
+static inline u32 div_round_up_fixed16(fixed16_16_t fp, fixed16_16_t d)
 {
-	return DIV_ROUND_UP(val.val, d.val);
+	return DIV_ROUND_UP(fp.val, d.val);
 }
 
 static inline u32 mul_round_up_u32_fixed16(u32 val, fixed16_16_t mul)
 {
-	u64 intermediate_val;
+	u64 tmp;
 
-	intermediate_val = (u64) val * mul.val;
-	intermediate_val = DIV_ROUND_UP_ULL(intermediate_val, 1 << 16);
-	if (WARN_ON(intermediate_val > U32_MAX))
-		intermediate_val = U32_MAX;
-	return (u32) intermediate_val;
+	tmp = (u64) val * mul.val;
+	tmp = DIV_ROUND_UP_ULL(tmp, 1 << 16);
+	if (WARN_ON(tmp > U32_MAX))
+		tmp = U32_MAX;
+	return tmp;
 }
 
 static inline fixed16_16_t mul_fixed16(fixed16_16_t val, fixed16_16_t mul)
 {
-	u64 intermediate_val;
+	u64 tmp;
 
-	intermediate_val = (u64) val.val * mul.val;
-	intermediate_val = intermediate_val >> 16;
-	return clamp_u64_to_fixed16(intermediate_val);
+	tmp = (u64) val.val * mul.val;
+	tmp = tmp >> 16;
+	return clamp_u64_to_fixed16(tmp);
 }
 
 static inline fixed16_16_t div_fixed16(u32 val, u32 d)
 {
-	u64 interm_val;
+	u64 tmp;
 
-	interm_val = (u64)val << 16;
-	interm_val = DIV_ROUND_UP_ULL(interm_val, d);
-	return clamp_u64_to_fixed16(interm_val);
+	tmp = (u64)val << 16;
+	tmp = DIV_ROUND_UP_ULL(tmp, d);
+	return clamp_u64_to_fixed16(tmp);
 }
 
 static inline u32 div_round_up_u32_fixed16(u32 val, fixed16_16_t d)
 {
-	u64 interm_val;
+	u64 tmp;
 
-	interm_val = (u64)val << 16;
-	interm_val = DIV_ROUND_UP_ULL(interm_val, d.val);
-	if (WARN_ON(interm_val > U32_MAX))
-		interm_val = U32_MAX;
-	return (u32) interm_val;
+	tmp = (u64)val << 16;
+	tmp = DIV_ROUND_UP_ULL(tmp, d.val);
+	if (WARN_ON(tmp > U32_MAX))
+		tmp = U32_MAX;
+	return tmp;
 }
 
 static inline fixed16_16_t mul_u32_fixed16(u32 val, fixed16_16_t mul)
 {
-	u64 intermediate_val;
+	u64 tmp = (u64) val * mul.val;
 
-	intermediate_val = (u64) val * mul.val;
-	return clamp_u64_to_fixed16(intermediate_val);
+	return clamp_u64_to_fixed16(tmp);
 }
 
 static inline fixed16_16_t add_fixed16(fixed16_16_t add1, fixed16_16_t add2)
 {
-	u64 interm_sum;
+	u64 tmp = (u64) add1.val + add2.val;
 
-	interm_sum = (u64) add1.val + add2.val;
-	return clamp_u64_to_fixed16(interm_sum);
+	return clamp_u64_to_fixed16(tmp);
 }
 
 static inline fixed16_16_t add_fixed16_u32(fixed16_16_t add1, u32 add2)
 {
-	u64 interm_sum;
-	fixed16_16_t interm_add2 = u32_to_fixed16(add2);
-
-	interm_sum = (u64)add1.val + interm_add2.val;
-	return clamp_u64_to_fixed16(interm_sum);
+	return add_fixed16(add1, u32_to_fixed16(add2));
 }
 
 #endif
-- 
1.9.1

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




[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]
  Powered by Linux