diff options
author | Ilia Mirkin <imirkin@alum.mit.edu> | 2014-02-09 15:51:24 -0500 |
---|---|---|
committer | Ben Skeggs <bskeggs@redhat.com> | 2014-02-18 10:40:21 +1000 |
commit | 9b858054c857a1dc00175774c340d984f747fcee (patch) | |
tree | a3fdbd42d1528f46d1dafdca3bf89028196b3e50 | |
parent | f0708f490375f25c36f95d94b0090a709679f220 (diff) |
drm: replace ffsll with __ffs64
The ffsll function is a lot slower than the __ffs64 built-in which
compiles to a single instruction on 64-bit. It's also nice to avoid
custom versions of standard functions. Note that __ffs == ffs - 1.
Signed-off-by: Ilia Mirkin <imirkin@alum.mit.edu>
Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
-rw-r--r-- | drm/core/os.h | 11 | ||||
-rw-r--r-- | drm/nouveau_abi16.c | 4 | ||||
-rw-r--r-- | lib/core/os.h | 3 | ||||
-rw-r--r-- | nvkm/core/parent.c | 2 |
4 files changed, 5 insertions, 15 deletions
diff --git a/drm/core/os.h b/drm/core/os.h index 191e739f..3cd6120d 100644 --- a/drm/core/os.h +++ b/drm/core/os.h @@ -23,17 +23,6 @@ #include <asm/unaligned.h> -static inline int -ffsll(u64 mask) -{ - int i; - for (i = 0; i < 64; i++) { - if (mask & (1ULL << i)) - return i + 1; - } - return 0; -} - #ifndef ioread32_native #ifdef __BIG_ENDIAN #define ioread16_native ioread16be diff --git a/drm/nouveau_abi16.c b/drm/nouveau_abi16.c index 900fae01..b7011171 100644 --- a/drm/nouveau_abi16.c +++ b/drm/nouveau_abi16.c @@ -270,8 +270,8 @@ nouveau_abi16_ioctl_channel_alloc(ABI16_IOCTL_ARGS) return nouveau_abi16_put(abi16, -EINVAL); /* allocate "abi16 channel" data and make up a handle for it */ - init->channel = ffsll(~abi16->handles); - if (!init->channel--) + init->channel = __ffs64(~abi16->handles); + if (~abi16->handles == 0) return nouveau_abi16_put(abi16, -ENOSPC); chan = kzalloc(sizeof(*chan), GFP_KERNEL); diff --git a/lib/core/os.h b/lib/core/os.h index 14661e5d..282104ce 100644 --- a/lib/core/os.h +++ b/lib/core/os.h @@ -140,7 +140,8 @@ put_unaligned_le32(u32 val, void *ptr) /****************************************************************************** * bitops *****************************************************************************/ -#define ffsll(a) __builtin_ffsll(a) +#define __ffs64(a) (__builtin_ffsll(a) - 1) +#define __ffs(a) (__builtin_ffs(a) - 1) static inline int hweight8(u32 v) { diff --git a/nvkm/core/parent.c b/nvkm/core/parent.c index 313380ce..dee5d123 100644 --- a/nvkm/core/parent.c +++ b/nvkm/core/parent.c @@ -49,7 +49,7 @@ nouveau_parent_sclass(struct nouveau_object *parent, u16 handle, mask = nv_parent(parent)->engine; while (mask) { - int i = ffsll(mask) - 1; + int i = __ffs64(mask); if (nv_iclass(parent, NV_CLIENT_CLASS)) engine = nv_engine(nv_client(parent)->device); |