aboutsummaryrefslogtreecommitdiffstats
path: root/tools/libfsimage/ext2fs
diff options
context:
space:
mode:
authorkaf24@localhost.localdomain <kaf24@localhost.localdomain>2006-11-11 01:25:00 +0000
committerkaf24@localhost.localdomain <kaf24@localhost.localdomain>2006-11-11 01:25:00 +0000
commit6ab4f311ed263ae99c13d22da11bf5ea14f9b137 (patch)
tree8174f3c7a58e491466bf6a7b1a9ff17deb1a41b1 /tools/libfsimage/ext2fs
parent22ed12a0f3266df4714057f9bdf2dfc9577bf80e (diff)
downloadxen-6ab4f311ed263ae99c13d22da11bf5ea14f9b137.tar.gz
xen-6ab4f311ed263ae99c13d22da11bf5ea14f9b137.tar.bz2
xen-6ab4f311ed263ae99c13d22da11bf5ea14f9b137.zip
[LIBFS] IA64 & PPC aren't making use of this right now, but it's silly to
have the build fail for some trivial x86 specific assembly. I snagged the appropriate bitops for ia64 and ppc (untested) and tossed in an unoptimized option as well in case we want to make use of it. Signed-off-by: Alex Williamson <alex.williamson@hp.com>
Diffstat (limited to 'tools/libfsimage/ext2fs')
-rw-r--r--tools/libfsimage/ext2fs/fsys_ext2fs.c61
1 files changed, 61 insertions, 0 deletions
diff --git a/tools/libfsimage/ext2fs/fsys_ext2fs.c b/tools/libfsimage/ext2fs/fsys_ext2fs.c
index d6c305238e..c4e4c863bd 100644
--- a/tools/libfsimage/ext2fs/fsys_ext2fs.c
+++ b/tools/libfsimage/ext2fs/fsys_ext2fs.c
@@ -232,6 +232,7 @@ struct ext2_dir_entry
#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
+#if defined(__i386__) || defined(__x86_64__)
/* include/asm-i386/bitops.h */
/*
* ffz = Find First Zero in word. Undefined if no zero exists,
@@ -251,6 +252,66 @@ ffz (unsigned long word)
return word;
}
+#elif defined(__ia64__)
+
+typedef unsigned long __u64;
+
+#if __GNUC__ >= 4 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
+# define ia64_popcnt(x) __builtin_popcountl(x)
+#else
+# define ia64_popcnt(x) \
+ ({ \
+ __u64 ia64_intri_res; \
+ asm ("popcnt %0=%1" : "=r" (ia64_intri_res) : "r" (x)); \
+ ia64_intri_res; \
+ })
+#endif
+
+static __inline__ unsigned long
+ffz (unsigned long word)
+{
+ unsigned long result;
+
+ result = ia64_popcnt(word & (~word - 1));
+ return result;
+}
+
+#elif defined(__powerpc__)
+
+static __inline__ int
+__ilog2(unsigned long x)
+{
+ int lz;
+
+ asm (PPC_CNTLZL "%0,%1" : "=r" (lz) : "r" (x));
+ return BITS_PER_LONG - 1 - lz;
+}
+
+static __inline__ unsigned long
+ffz (unsigned long word)
+{
+ if ((word = ~word) == 0)
+ return BITS_PER_LONG;
+ return __ilog2(word & -word);
+}
+
+#else /* Unoptimized */
+
+static __inline__ unsigned long
+ffz (unsigned long word)
+{
+ unsigned long result;
+
+ result = 0;
+ while(word & 1)
+ {
+ result++;
+ word >>= 1;
+ }
+ return result;
+}
+#endif
+
/* check filesystem types and read superblock into memory buffer */
int
ext2fs_mount (fsi_file_t *ffi)