All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH libdrm 1/2] include: Factor out log2_int() function.
@ 2020-10-28 10:06 Paul Gofman
  2020-10-28 10:06 ` [PATCH libdrm 2/2] include: Avoid potentially infinite loop in log2_int() Paul Gofman
  0 siblings, 1 reply; 4+ messages in thread
From: Paul Gofman @ 2020-10-28 10:06 UTC (permalink / raw)
  To: dri-devel; +Cc: Paul Gofman

Signed-off-by: Paul Gofman <pgofman@codeweavers.com>
---
 radeon/radeon_surface.c | 20 +-------------------
 util_math.h             | 14 ++++++++++++++
 xf86drm.c               | 16 ----------------
 3 files changed, 15 insertions(+), 35 deletions(-)

diff --git a/radeon/radeon_surface.c b/radeon/radeon_surface.c
index ea0a27a9..c59dcc83 100644
--- a/radeon/radeon_surface.c
+++ b/radeon/radeon_surface.c
@@ -38,6 +38,7 @@
 #include "xf86drm.h"
 #include "radeon_drm.h"
 #include "radeon_surface.h"
+#include "util_math.h"
 
 #define CIK_TILE_MODE_COLOR_2D			14
 #define CIK_TILE_MODE_COLOR_2D_SCANOUT		10
@@ -47,10 +48,6 @@
 #define CIK_TILE_MODE_DEPTH_STENCIL_2D_TILESPLIT_512      3
 #define CIK_TILE_MODE_DEPTH_STENCIL_2D_TILESPLIT_ROW_SIZE 4
 
-#define ALIGN(value, alignment) (((value) + alignment - 1) & ~(alignment - 1))
-#define MAX2(A, B)              ((A) > (B) ? (A) : (B))
-#define MIN2(A, B)              ((A) < (B) ? (A) : (B))
-
 /* keep this private */
 enum radeon_family {
     CHIP_UNKNOWN,
@@ -887,21 +884,6 @@ static int eg_surface_init(struct radeon_surface_manager *surf_man,
     return r;
 }
 
-static unsigned log2_int(unsigned x)
-{
-    unsigned l;
-
-    if (x < 2) {
-        return 0;
-    }
-    for (l = 2; ; l++) {
-        if ((unsigned)(1 << l) > x) {
-            return l - 1;
-        }
-    }
-    return 0;
-}
-
 /* compute best tile_split, bankw, bankh, mtilea
  * depending on surface
  */
diff --git a/util_math.h b/util_math.h
index 35bf4512..e2fa95f5 100644
--- a/util_math.h
+++ b/util_math.h
@@ -31,4 +31,18 @@
 #define __align_mask(value, mask)  (((value) + (mask)) & ~(mask))
 #define ALIGN(value, alignment)    __align_mask(value, (__typeof__(value))((alignment) - 1))
 
+static inline unsigned log2_int(unsigned x)
+{
+    unsigned l;
+
+    if (x < 2) {
+        return 0;
+    }
+    for (l = 2; ; l++) {
+        if ((unsigned)(1 << l) > x) {
+            return l - 1;
+        }
+    }
+    return 0;
+}
 #endif /*_UTIL_MATH_H_*/
diff --git a/xf86drm.c b/xf86drm.c
index dbb7c14b..ca4738e1 100644
--- a/xf86drm.c
+++ b/xf86drm.c
@@ -124,22 +124,6 @@ static drmServerInfoPtr drm_server_info;
 static bool drmNodeIsDRM(int maj, int min);
 static char *drmGetMinorNameForFD(int fd, int type);
 
-static unsigned log2_int(unsigned x)
-{
-    unsigned l;
-
-    if (x < 2) {
-        return 0;
-    }
-    for (l = 2; ; l++) {
-        if ((unsigned)(1 << l) > x) {
-            return l - 1;
-        }
-    }
-    return 0;
-}
-
-
 drm_public void drmSetServerInfo(drmServerInfoPtr info)
 {
     drm_server_info = info;
-- 
2.28.0

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

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

* [PATCH libdrm 2/2] include: Avoid potentially infinite loop in log2_int().
  2020-10-28 10:06 [PATCH libdrm 1/2] include: Factor out log2_int() function Paul Gofman
@ 2020-10-28 10:06 ` Paul Gofman
  2020-10-30 11:07   ` Pekka Paalanen
  0 siblings, 1 reply; 4+ messages in thread
From: Paul Gofman @ 2020-10-28 10:06 UTC (permalink / raw)
  To: dri-devel; +Cc: Paul Gofman

Signed-off-by: Paul Gofman <pgofman@codeweavers.com>
---
 util_math.h | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/util_math.h b/util_math.h
index e2fa95f5..f6bbe192 100644
--- a/util_math.h
+++ b/util_math.h
@@ -38,6 +38,9 @@ static inline unsigned log2_int(unsigned x)
     if (x < 2) {
         return 0;
     }
+    if (x & 0x80000000) {
+        return 31;
+    }
     for (l = 2; ; l++) {
         if ((unsigned)(1 << l) > x) {
             return l - 1;
-- 
2.28.0

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

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

* Re: [PATCH libdrm 2/2] include: Avoid potentially infinite loop in log2_int().
  2020-10-28 10:06 ` [PATCH libdrm 2/2] include: Avoid potentially infinite loop in log2_int() Paul Gofman
@ 2020-10-30 11:07   ` Pekka Paalanen
  2020-10-30 13:07     ` Paul Gofman
  0 siblings, 1 reply; 4+ messages in thread
From: Pekka Paalanen @ 2020-10-30 11:07 UTC (permalink / raw)
  To: Paul Gofman; +Cc: dri-devel


[-- Attachment #1.1: Type: text/plain, Size: 793 bytes --]

On Wed, 28 Oct 2020 13:06:02 +0300
Paul Gofman <pgofman@codeweavers.com> wrote:

> Signed-off-by: Paul Gofman <pgofman@codeweavers.com>
> ---
>  util_math.h | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/util_math.h b/util_math.h
> index e2fa95f5..f6bbe192 100644
> --- a/util_math.h
> +++ b/util_math.h
> @@ -38,6 +38,9 @@ static inline unsigned log2_int(unsigned x)
>      if (x < 2) {
>          return 0;
>      }
> +    if (x & 0x80000000) {
> +        return 31;
> +    }
>      for (l = 2; ; l++) {
>          if ((unsigned)(1 << l) > x) {
>              return l - 1;

Hi,

I guess that does it, but it seems quite a lot of code that could be
a two-liner:
http://graphics.stanford.edu/~seander/bithacks.html#IntegerLogObvious


Thanks,
pq

[-- Attachment #1.2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

[-- Attachment #2: Type: text/plain, Size: 160 bytes --]

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

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

* Re: [PATCH libdrm 2/2] include: Avoid potentially infinite loop in log2_int().
  2020-10-30 11:07   ` Pekka Paalanen
@ 2020-10-30 13:07     ` Paul Gofman
  0 siblings, 0 replies; 4+ messages in thread
From: Paul Gofman @ 2020-10-30 13:07 UTC (permalink / raw)
  To: Pekka Paalanen; +Cc: dri-devel

On 10/30/20 14:07, Pekka Paalanen wrote:
> On Wed, 28 Oct 2020 13:06:02 +0300
> Paul Gofman <pgofman@codeweavers.com> wrote:
>
>> Signed-off-by: Paul Gofman <pgofman@codeweavers.com>
>> ---
>>  util_math.h | 3 +++
>>  1 file changed, 3 insertions(+)
>>
>> diff --git a/util_math.h b/util_math.h
>> index e2fa95f5..f6bbe192 100644
>> --- a/util_math.h
>> +++ b/util_math.h
>> @@ -38,6 +38,9 @@ static inline unsigned log2_int(unsigned x)
>>      if (x < 2) {
>>          return 0;
>>      }
>> +    if (x & 0x80000000) {
>> +        return 31;
>> +    }
>>      for (l = 2; ; l++) {
>>          if ((unsigned)(1 << l) > x) {
>>              return l - 1;
> Hi,
>
> I guess that does it, but it seems quite a lot of code that could be
> a two-liner:
> http://graphics.stanford.edu/~seander/bithacks.html#IntegerLogObvious
>
>
> Thanks,
> pq

Hello,

    thanks, I've sent the updated patches with simplified implementation.

Regards,

    Paul.

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

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

end of thread, other threads:[~2020-10-30 13:08 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-28 10:06 [PATCH libdrm 1/2] include: Factor out log2_int() function Paul Gofman
2020-10-28 10:06 ` [PATCH libdrm 2/2] include: Avoid potentially infinite loop in log2_int() Paul Gofman
2020-10-30 11:07   ` Pekka Paalanen
2020-10-30 13:07     ` Paul Gofman

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.