Bswapcpy.h

Go to the documentation of this file.
00001 /* @(#)root/base:$Id: Bswapcpy.h 30815 2009-10-20 13:49:22Z rdm $ */
00002 
00003 /*************************************************************************
00004  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
00005  * All rights reserved.                                                  *
00006  *                                                                       *
00007  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00008  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00009  *************************************************************************/
00010 #ifndef ROOT_Bswapcpy
00011 #define ROOT_Bswapcpy
00012 
00013 //////////////////////////////////////////////////////////////////////////
00014 //                                                                      //
00015 // Bswapcpy                                                             //
00016 //                                                                      //
00017 // Initial version: Apr 22, 2000                                        //
00018 //                                                                      //
00019 // A set of inline byte swapping routines for arrays.                   //
00020 //                                                                      //
00021 // The bswapcpy16() and bswapcpy32() routines are used for packing      //
00022 // arrays of basic types into a buffer in a byte swapped order. Use     //
00023 // of asm and the `bswap' opcode (available on i486 and up) reduces     //
00024 // byte swapping overhead on linux.                                     //
00025 //                                                                      //
00026 // Use of routines is similar to that of memcpy.                        //
00027 //                                                                      //
00028 // ATTENTION:                                                           //
00029 //                                                                      //
00030 //    n - is a number of array elements to be copied and byteswapped.   //
00031 //        (It is not the number of bytes!)                              //
00032 //                                                                      //
00033 // For arrays of short type (2 bytes in size) use bswapcpy16().         //
00034 // For arrays of of 4-byte types (int, float) use bswapcpy32().         //
00035 //                                                                      //
00036 //                                                                      //
00037 // Author: Alexandre V. Vaniachine <AVVaniachine@lbl.gov>               //
00038 //                                                                      //
00039 //////////////////////////////////////////////////////////////////////////
00040 
00041 #if !defined(__CINT__)
00042 #include <sys/types.h>
00043 #endif
00044 
00045 extern inline void * bswapcpy16(void * to, const void * from, size_t n)
00046 {
00047 int d0, d1, d2, d3;
00048 __asm__ __volatile__(
00049         "cld\n"
00050         "1:\tlodsw\n\t"
00051         "rorw $8, %%ax\n\t"
00052         "stosw\n\t"
00053         "loop 1b\n\t"
00054         :"=&c" (d0), "=&D" (d1), "=&S" (d2), "=&a" (d3)
00055         :"0" (n), "1" ((long) to),"2" ((long) from)
00056         :"memory");
00057 return (to);
00058 }
00059 
00060 extern inline void * bswapcpy32(void * to, const void * from, size_t n)
00061 {
00062 int d0, d1, d2, d3;
00063 __asm__ __volatile__(
00064         "cld\n"
00065         "1:\tlodsl\n\t"
00066 #if !defined __i486__ && !defined __pentium__ && !defined __pentiumpro__ && \
00067     !defined __pentium4__ && !defined __x86_64__
00068         "rorw $8, %%ax\n\t"
00069         "rorl $16, %%eax\n\t"
00070         "rorw $8, %%ax\n\t"
00071 #else
00072         "bswap %%eax\n\t"
00073 #endif
00074         "stosl\n\t"
00075         "loop 1b\n\t"
00076         :"=&c" (d0), "=&D" (d1), "=&S" (d2), "=&a" (d3)
00077         :"0" (n), "1" ((long) to),"2" ((long) from)
00078         :"memory");
00079 return (to);
00080 }
00081 #endif

Generated on Tue Jul 5 14:10:18 2011 for ROOT_528-00b_version by  doxygen 1.5.1