瀏覽代碼

add word-sized ctz function to atomic.h

strictly speaking this and a few other ops should be factored into
asm.h or the file should just be renamed to asm.h, but whatever. clean
it up someday.
Rich Felker 14 年之前
父節點
當前提交
4bb9b4f3b4
共有 2 個文件被更改,包括 16 次插入4 次删除
  1. 8 2
      arch/i386/atomic.h
  2. 8 2
      arch/x86_64/atomic.h

+ 8 - 2
arch/i386/atomic.h

@@ -1,5 +1,5 @@
-#ifndef _INTERNAA_ATOMIC_H
-#define _INTERNAA_ATOMIC_H
+#ifndef _INTERNAL_ATOMIC_H
+#define _INTERNAL_ATOMIC_H
 
 #include <stdint.h>
 
@@ -11,6 +11,12 @@ static inline int a_ctz_64(uint64_t x)
 	return r;
 }
 
+static inline int a_ctz_l(unsigned long x)
+{
+	long r;
+	__asm__( "bsf %1,%0" : "=r"(r) : "r"(x) );
+	return r;
+}
 
 static inline void a_and_64(volatile uint64_t *p, uint64_t v)
 {

+ 8 - 2
arch/x86_64/atomic.h

@@ -1,5 +1,5 @@
-#ifndef _INTERNAA_ATOMIC_H
-#define _INTERNAA_ATOMIC_H
+#ifndef _INTERNAL_ATOMIC_H
+#define _INTERNAL_ATOMIC_H
 
 #include <stdint.h>
 
@@ -10,6 +10,12 @@ static inline int a_ctz_64(uint64_t x)
 	return r;
 }
 
+static inline int a_ctz_l(unsigned long x)
+{
+	long r;
+	__asm__( "bsf %1,%0" : "=r"(r) : "r"(x) );
+	return r;
+}
 
 static inline void a_and_64(volatile uint64_t *p, uint64_t v)
 {