[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Minios-devel] [UNIKRAFT PATCH v2 1/9] include/uk/arch: Add ukarch_ffs, ukarch_fls, ukarch_flsl functions for x86_64



From: Costin Lupu <costin.lupu@xxxxxxxxx>

Signed-off-by: Costin Lupu <costin.lupu@xxxxxxxxx>
Reviewed-by: Yuri Volchkov <yuri.volchkov@xxxxxxxxx>
---
 include/uk/arch/x86_64/atomic.h | 46 +++++++++++++++++++++++++++++++--
 1 file changed, 44 insertions(+), 2 deletions(-)

diff --git a/include/uk/arch/x86_64/atomic.h b/include/uk/arch/x86_64/atomic.h
index c5f30cc..c48d5bd 100644
--- a/include/uk/arch/x86_64/atomic.h
+++ b/include/uk/arch/x86_64/atomic.h
@@ -30,6 +30,34 @@
 #error Do not include this header directly
 #endif
 
+/**
+ * ukarch_ffs - find first (lowest) set bit in word.
+ * @word: The word to search
+ *
+ * Undefined if no bit exists, so code should check against 0 first.
+ */
+static inline unsigned int ukarch_ffs(unsigned int word)
+{
+       __asm__("bsfl %1,%0"
+               : "=r" (word)
+               : "rm" (word));
+       return word;
+}
+
+/**
+ * ukarch_fls - find last (highest) set bit in word.
+ * @word: The word to search
+ *
+ * Undefined if no bit exists, so code should check against 0 first.
+ */
+static inline unsigned int ukarch_fls(unsigned int word)
+{
+       __asm__("bsrl %1,%0"
+               : "=r" (word)
+               : "rm" (word));
+       return word;
+}
+
 /**
  * ukarch_ffsl - find first (lowest) set bit in word.
  * @word: The word to search
@@ -39,7 +67,21 @@
 static inline unsigned long ukarch_ffsl(unsigned long word)
 {
        __asm__("bsfq %1,%0"
-               :"=r" (word)
-               :"rm" (word));
+               : "=r" (word)
+               : "rm" (word));
+       return word;
+}
+
+/**
+ * ukarch_flsl - find last (highest) set bit in word.
+ * @word: The word to search
+ *
+ * Undefined if no bit exists, so code should check against 0 first.
+ */
+static inline unsigned long ukarch_flsl(unsigned long word)
+{
+       __asm__("bsrq %1,%0"
+               : "=r" (word)
+               : "rm" (word));
        return word;
 }
-- 
2.18.0


_______________________________________________
Minios-devel mailing list
Minios-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/minios-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.