From: Harry Wentland <harry.wentland@amd.com>
To: dri-devel@lists.freedesktop.org
Subject: [PATCH 1/5] drm: Add drm_fixp_from_fraction and drm_fixp2int_ceil
Date: Fri, 22 Jan 2016 17:07:25 -0500 [thread overview]
Message-ID: <1453500449-9224-2-git-send-email-harry.wentland@amd.com> (raw)
In-Reply-To: <1453500449-9224-1-git-send-email-harry.wentland@amd.com>
drm_fixp_from_fraction allows us to create a fixed point directly
from a fraction, rather than creating fixed point values and dividing
later. This avoids overflow of our 64 bit value for large numbers.
drm_fixp2int_ceil allows us to return the ceiling of our fixed point
value.
Signed-off-by: Harry Wentland <harry.wentland@amd.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
---
include/drm/drm_fixed.h | 54 +++++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 52 insertions(+), 2 deletions(-)
diff --git a/include/drm/drm_fixed.h b/include/drm/drm_fixed.h
index d639049a613d..16e725c42422 100644
--- a/include/drm/drm_fixed.h
+++ b/include/drm/drm_fixed.h
@@ -73,18 +73,28 @@ static inline u32 dfixed_div(fixed20_12 A, fixed20_12 B)
#define DRM_FIXED_ONE (1ULL << DRM_FIXED_POINT)
#define DRM_FIXED_DECIMAL_MASK (DRM_FIXED_ONE - 1)
#define DRM_FIXED_DIGITS_MASK (~DRM_FIXED_DECIMAL_MASK)
+#define DRM_FIXED_EPSILON 1LL
+#define DRM_FIXED_ALMOST_ONE (DRM_FIXED_ONE - DRM_FIXED_EPSILON)
static inline s64 drm_int2fixp(int a)
{
return ((s64)a) << DRM_FIXED_POINT;
}
-static inline int drm_fixp2int(int64_t a)
+static inline int drm_fixp2int(s64 a)
{
return ((s64)a) >> DRM_FIXED_POINT;
}
-static inline unsigned drm_fixp_msbset(int64_t a)
+static inline int drm_fixp2int_ceil(s64 a)
+{
+ if (a > 0)
+ return drm_fixp2int(a + DRM_FIXED_ALMOST_ONE);
+ else
+ return drm_fixp2int(a - DRM_FIXED_ALMOST_ONE);
+}
+
+static inline unsigned drm_fixp_msbset(s64 a)
{
unsigned shift, sign = (a >> 63) & 1;
@@ -136,6 +146,46 @@ static inline s64 drm_fixp_div(s64 a, s64 b)
return result;
}
+static inline s64 drm_fixp_from_fraction(s64 a, s64 b)
+{
+ s64 res;
+ bool a_neg = a < 0;
+ bool b_neg = b < 0;
+ u64 a_abs = a_neg ? -a : a;
+ u64 b_abs = b_neg ? -b : b;
+ u64 rem;
+
+ /* determine integer part */
+ u64 res_abs = a_abs / b_abs;
+ rem = a_abs % b_abs;
+
+ /* determine fractional part */
+ {
+ u32 i = DRM_FIXED_POINT;
+
+ do {
+ rem <<= 1;
+ res_abs <<= 1;
+ if (rem >= b_abs) {
+ res_abs |= 1;
+ rem -= b_abs;
+ }
+ } while (--i != 0);
+ }
+
+ /* round up LSB */
+ {
+ u64 summand = (rem << 1) >= b_abs;
+
+ res_abs += summand;
+ }
+
+ res = (s64) res_abs;
+ if (a_neg ^ b_neg)
+ res = -res;
+ return res;
+}
+
static inline s64 drm_fixp_exp(s64 x)
{
s64 tolerance = div64_s64(DRM_FIXED_ONE, 1000000);
--
2.1.4
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel
next prev parent reply other threads:[~2016-01-22 22:23 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-01-22 22:07 [PATCH 0/5] Fixes for MST (daisy-chain and 4k tiles) Harry Wentland
2016-01-22 22:07 ` Harry Wentland [this message]
2016-01-22 22:07 ` [PATCH 2/5] drm/dp/mst: Calculate MST PBN with 31.32 fixed point Harry Wentland
2016-01-22 22:07 ` [PATCH 3/5] drm/dp/mst: change MST detection scheme Harry Wentland
2016-02-17 5:45 ` Dave Airlie
2016-02-18 4:53 ` Lysenko, Mykola
2016-02-23 3:09 ` Lysenko, Mykola
2016-05-12 22:41 ` Grodzovsky, Andrey
2016-06-15 3:49 ` Dave Airlie
2016-06-15 4:14 ` Dave Airlie
2017-01-25 17:16 ` Krzysztof Nowicki
2017-01-25 17:24 ` Alex Deucher
2017-01-25 18:32 ` Harry Wentland
2017-01-25 22:46 ` Alex Deucher
2017-01-25 23:07 ` Harry Wentland
2017-01-27 18:21 ` Krzysztof Nowicki
2016-01-22 22:07 ` [PATCH 4/5] drm/dp/mst: move GUID storage from mgr, port to only mst branch Harry Wentland
2016-01-22 22:07 ` [PATCH 5/5] drm/dp/mst: Reverse order of MST enable and clearing VC payload table Harry Wentland
2016-01-25 4:53 ` [PATCH 0/5] Fixes for MST (daisy-chain and 4k tiles) Dave Airlie
2016-01-25 18:55 ` Wentland, Harry
2016-02-02 21:20 ` Alex Deucher
2016-02-04 0:35 ` Dave Airlie
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1453500449-9224-2-git-send-email-harry.wentland@amd.com \
--to=harry.wentland@amd.com \
--cc=dri-devel@lists.freedesktop.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox