]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
ChangeLog, Makefile.in, bitops.h, tst_byteswap.c:
authorTheodore Ts'o <tytso@mit.edu>
Tue, 20 Feb 2001 16:28:40 +0000 (16:28 +0000)
committerTheodore Ts'o <tytso@mit.edu>
Tue, 20 Feb 2001 16:28:40 +0000 (16:28 +0000)
  bitops.h (ext2fs_swab16, ext2fs_swab32): Add i386 assembly inline
   functions.
  tst_byteswap.c: New function to test the byteswap functions.  Add to
   regression test suite.

lib/ext2fs/ChangeLog
lib/ext2fs/Makefile.in
lib/ext2fs/bitops.h
lib/ext2fs/tst_byteswap.c [new file with mode: 0644]

index ee128cace96474a8b225429ccb6bc70995f002eb..3a46a1d3b204557917de69d0b412ddbd820ddc3e 100644 (file)
@@ -1,3 +1,11 @@
+2001-02-20  Theodore Tso  <tytso@valinux.com>
+
+       * bitops.h (ext2fs_swab16, ext2fs_swab32): Add i386 assembly
+               inline functions.
+
+       * tst_byteswap.c: New function to test the byteswap functions.
+               Add to regression test suite.
+
 2001-02-08  Theodore Tso  <tytso@valinux.com>
 
        * e2image.h (struct ext2_image_hdr): Fix type for fs_hostname
index 49102a7adb6966d9623ef61ecf565c58be6f0461..dc0590f6d010a25460c8b71dec025e97d27c3269 100644 (file)
@@ -177,12 +177,17 @@ tst_getsize: tst_getsize.o getsize.o $(STATIC_LIBEXT2FS)
        $(CC) -o tst_getsize tst_getsize.o getsize.o $(STATIC_LIBEXT2FS) \
                $(LIBCOM_ERR)
 
+tst_byteswap: tst_byteswap.o bitops.o $(STATIC_LIBEXT2FS)
+       $(CC) -o tst_byteswap tst_byteswap.o bitops.o $(STATIC_LIBEXT2FS) \
+               $(LIBCOM_ERR)
+
 mkjournal: mkjournal.c $(STATIC_LIBEXT2FS)
        $(CC) -o mkjournal $(srcdir)/mkjournal.c -DDEBUG $(STATIC_LIBEXT2FS) $(LIBCOM_ERR) $(ALL_CFLAGS)
 
-check:: tst_badblocks tst_iscan
+check:: tst_badblocks tst_iscan tst_byteswap
        ./tst_badblocks
        ./tst_iscan
+       ./tst_byteswap
 
 installdirs::
        $(top_srcdir)/mkinstalldirs $(DESTDIR)$(libdir) \
index 6ab778198278b85d25260746b2d9f28ec1805562..f91f5645d853716bb2902488ab57186f80052935 100644 (file)
@@ -109,7 +109,8 @@ extern void ext2fs_set_bitmap_padding(ext2fs_generic_bitmap map);
                            defined(__i586__)))
 
 #define _EXT2_HAVE_ASM_BITOPS_
-       
+#define _EXT2_HAVE_ASM_SWAB_
+
 /*
  * These are done by inline assembly for speed reasons.....
  *
@@ -155,6 +156,28 @@ _INLINE_ int ext2fs_test_bit(int nr, const void * addr)
        return oldbit;
 }
 
+_INLINE_ __u32 ext2fs_swab32(__u32 val)
+{
+#ifdef EXT2FS_REQUIRE_486
+       __asm__("bswap %0" : "=r" (val) : "0" (val));
+#else
+       __asm__("xchgb %b0,%h0\n\t"     /* swap lower bytes     */
+               "rorl $16,%0\n\t"       /* swap words           */
+               "xchgb %b0,%h0"         /* swap higher bytes    */
+               :"=q" (val)
+               : "0" (val));
+#endif
+       return val;
+}
+
+_INLINE_ __u16 ext2fs_swab16(__u16 val)
+{
+       __asm__("xchgb %b0,%h0"         /* swap bytes           */ \
+               : "=q" (val) \
+               :  "0" (val)); \
+               return val;
+}
+
 #undef EXT2FS_ADDR
 
 #endif /* i386 */
@@ -314,7 +337,7 @@ _INLINE_ int ext2fs_test_bit(int nr, const void *addr)
 
 #endif /* __sparc__ */
 
-#ifndef _EXT2_HAVE_ASM_SWAB
+#ifndef _EXT2_HAVE_ASM_SWAB_
 
 _INLINE_ __u16 ext2fs_swab16(__u16 val)
 {
diff --git a/lib/ext2fs/tst_byteswap.c b/lib/ext2fs/tst_byteswap.c
new file mode 100644 (file)
index 0000000..96e44ec
--- /dev/null
@@ -0,0 +1,97 @@
+/*
+ * This testing program makes sure the byteswap functions work
+ *
+ * Copyright (C) 2000 by Theodore Ts'o.
+ * 
+ * %Begin-Header%
+ * This file may be redistributed under the terms of the GNU Public
+ * License.
+ * %End-Header%
+ */
+
+#include <stdio.h>
+#include <string.h>
+#if HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+#include <fcntl.h>
+#include <time.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#if HAVE_ERRNO_H
+#include <errno.h>
+#endif
+
+#if EXT2_FLAT_INCLUDES
+#include "ext2_fs.h"
+#else
+#include <linux/ext2_fs.h>
+#endif
+
+#include "ext2fs.h"
+
+__u16 test1[] = {
+       0x0001, 0x0100,
+       0x1234, 0x3412,
+       0xff00, 0x00ff,
+       0x4000, 0x0040,
+       0xfeff, 0xfffe,
+       0x0000, 0x0000
+       };
+
+__u32 test2[] = {
+       0x00000001, 0x01000000,
+       0x80000000, 0x00000080,
+       0x12345678, 0x78563412,
+       0xffff0000, 0x0000ffff,
+       0x00ff0000, 0x0000ff00,
+       0xff000000, 0x000000ff,
+       0x00000000, 0x00000000
+       };
+
+int main(int argc, char *argv)
+{
+       int     i;
+       int     errors = 0;
+
+       printf("Testing ext2fs_swab16\n");
+       i=0;
+       do {
+               printf("swab16(0x%04x) = 0x%04x\n", test1[i],
+                      ext2fs_swab16(test1[i]));
+               if (ext2fs_swab16(test1[i]) != test1[i+1]) {
+                       printf("Error!!!   %04x != %04x\n",
+                              ext2fs_swab16(test1[i]), test1[i+1]);
+                       errors++;
+               }
+               if (ext2fs_swab16(test1[i+1]) != test1[i]) {
+                       printf("Error!!!   %04x != %04x\n",
+                              ext2fs_swab16(test1[i+1]), test1[i]);
+                       errors++;
+               }
+               i += 2;
+       } while (test1[i] != 0);
+       
+       printf("Testing ext2fs_swab32\n");
+       i = 0;
+       do {
+               printf("swab32(0x%08x) = 0x%08x\n", test2[i],
+                      ext2fs_swab32(test2[i]));
+               if (ext2fs_swab32(test2[i]) != test2[i+1]) {
+                       printf("Error!!!   %04x != %04x\n",
+                              ext2fs_swab32(test2[i]), test2[i+1]);
+                       errors++;
+               }
+               if (ext2fs_swab32(test2[i+1]) != test2[i]) {
+                       printf("Error!!!   %04x != %04x\n",
+                              ext2fs_swab32(test2[i+1]), test2[i]);
+                       errors++;
+               }
+               i += 2;
+       } while (test2[i] != 0);
+
+       if (!errors)
+               printf("No errors found in the byteswap implementation!\n");
+       
+       return errors;
+}