Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/root/Bswapcpy.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /* @(#)root/base:$Id$ */
0002 
0003 /*************************************************************************
0004  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
0005  * All rights reserved.                                                  *
0006  *                                                                       *
0007  * For the licensing terms see $ROOTSYS/LICENSE.                         *
0008  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
0009  *************************************************************************/
0010 #ifndef ROOT_Bswapcpy
0011 #define ROOT_Bswapcpy
0012 
0013 //////////////////////////////////////////////////////////////////////////
0014 //                                                                      //
0015 // Bswapcpy                                                             //
0016 //                                                                      //
0017 // Initial version: Apr 22, 2000                                        //
0018 //                                                                      //
0019 // A set of inline byte swapping routines for arrays.                   //
0020 //                                                                      //
0021 // The bswapcpy16() and bswapcpy32() routines are used for packing      //
0022 // arrays of basic types into a buffer in a byte swapped order. Use     //
0023 // of asm and the `bswap' opcode (available on i486 and up) reduces     //
0024 // byte swapping overhead on linux.                                     //
0025 //                                                                      //
0026 // Use of routines is similar to that of memcpy.                        //
0027 //                                                                      //
0028 // ATTENTION:                                                           //
0029 //                                                                      //
0030 //    n - is a number of array elements to be copied and byteswapped.   //
0031 //        (It is not the number of bytes!)                              //
0032 //                                                                      //
0033 // Note: It is note safe to call these routines with n == 0.            //
0034 //                                                                      //
0035 // For arrays of short type (2 bytes in size) use bswapcpy16().         //
0036 // For arrays of of 4-byte types (int, float) use bswapcpy32().         //
0037 //                                                                      //
0038 //                                                                      //
0039 // Author: Alexandre V. Vaniachine <AVVaniachine@lbl.gov>               //
0040 //                                                                      //
0041 //////////////////////////////////////////////////////////////////////////
0042 
0043 #include <sys/types.h>
0044 
0045 extern inline void * bswapcpy16(void * to, const void * from, size_t n)
0046 {
0047 int d0, d1, d2, d3;
0048 __asm__ __volatile__(
0049         "cld\n"
0050         "1:\tlodsw\n\t"
0051         "rorw $8, %%ax\n\t"
0052         "stosw\n\t"
0053         "loop 1b\n\t"
0054         :"=&c" (d0), "=&D" (d1), "=&S" (d2), "=&a" (d3)
0055         :"0" (n), "1" ((long) to),"2" ((long) from)
0056         :"memory");
0057 return (to);
0058 }
0059 
0060 extern inline void * bswapcpy32(void * to, const void * from, size_t n)
0061 {
0062 int d0, d1, d2, d3;
0063 __asm__ __volatile__(
0064         "cld\n"
0065         "1:\tlodsl\n\t"
0066 #if !defined __i486__ && !defined __pentium__ && !defined __pentiumpro__ && \
0067     !defined __pentium4__ && !defined __x86_64__
0068         "rorw $8, %%ax\n\t"
0069         "rorl $16, %%eax\n\t"
0070         "rorw $8, %%ax\n\t"
0071 #else
0072         "bswap %%eax\n\t"
0073 #endif
0074         "stosl\n\t"
0075         "loop 1b\n\t"
0076         :"=&c" (d0), "=&D" (d1), "=&S" (d2), "=&a" (d3)
0077         :"0" (n), "1" ((long) to),"2" ((long) from)
0078         :"memory");
0079 return (to);
0080 }
0081 #endif