From: Wim Taymans Date: Fri, 28 Aug 2009 10:33:37 +0000 (+0200) Subject: utils: factor out the leading zero count code X-Git-Tag: RELEASE-0.10.25~75 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0ef7a5af5277935e4459389a8cce4af2de01a115;p=platform%2Fupstream%2Fgstreamer.git utils: factor out the leading zero count code --- diff --git a/gst/gstutils.c b/gst/gstutils.c index 505b7f5dc6..fddf871dc1 100644 --- a/gst/gstutils.c +++ b/gst/gstutils.c @@ -247,19 +247,13 @@ gst_util_uint64_mul_uint64 (GstUInt64 * c1, GstUInt64 * c0, guint64 arg1, c1->ll = (guint64) v.l.high * n.l.high + c1->l.high + a1.l.high + b0.l.high; } -/* based on Hacker's Delight p152 */ -static guint64 -gst_util_div128_64 (GstUInt64 c1, GstUInt64 c0, guint64 denom) +/* count leading zeros */ +static guint +gst_util_clz (guint32 val) { - GstUInt64 q1, q0, rhat; - GstUInt64 v, cmp1, cmp2; guint s; - v.ll = denom; - - /* count number of leading zeroes, we know they must be in the high - * part of denom since denom > G_MAXUINT32. */ - s = v.l.high | (v.l.high >> 1); + s = val | (val >> 1); s |= (s >> 2); s |= (s >> 4); s |= (s >> 8); @@ -270,6 +264,23 @@ gst_util_div128_64 (GstUInt64 c1, GstUInt64 c0, guint64 denom) s += (s >> 8); s = (s + (s >> 16)) & 0x3f; + return s; +} + +/* based on Hacker's Delight p152 */ +static guint64 +gst_util_div128_64 (GstUInt64 c1, GstUInt64 c0, guint64 denom) +{ + GstUInt64 q1, q0, rhat; + GstUInt64 v, cmp1, cmp2; + guint s; + + v.ll = denom; + + /* count number of leading zeroes, we know they must be in the high + * part of denom since denom > G_MAXUINT32. */ + s = gst_util_clz (v.l.high); + if (s > 0) { /* normalize divisor and dividend */ v.ll <<= s;