00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef _MIPS_SWAP_H_
00019 #define _MIPS_SWAP_H_
00020
00021 #include "general.h"
00022
00026 #ifdef SLM_SWAP_BYTES
00027
00028
00029
00030 #define SWAPFIELD(x) {if (sizeof(*(x))==sizeof(short)) {SWAPHALF((x))} \
00031 else if (sizeof(*(x))==sizeof(int)) {SWAPWORD((x))} \
00032 else if (sizeof(*(x))==sizeof(double)){SWAPDOUBLE((x))}\
00033 }
00034
00035 #define SWAPHALF(x) {char tmp_byte; \
00036 tmp_byte = *((char*)(x)+0); \
00037 *((char*)(x)+0) = *((char*)(x)+1); \
00038 *((char*)(x)+1) = tmp_byte; \
00039 }
00040 #define SWAPWORD(x) {char tmp_byte; \
00041 tmp_byte = *((char*)(x)+0); \
00042 *((char*)(x)+0) = *((char*)(x)+3); \
00043 *((char*)(x)+3) = tmp_byte; \
00044 tmp_byte = *((char*)(x)+1); \
00045 *((char*)(x)+1) = *((char*)(x)+2); \
00046 *((char*)(x)+2) = tmp_byte; \
00047 }
00048
00049 #define SWAPDOUBLE(x) {char tmp_byte; \
00050 tmp_byte = *((char*)(x)+0); \
00051 *((char*)(x)+0) = *((char*)(x)+7); \
00052 *((char*)(x)+7) = tmp_byte; \
00053 tmp_byte = *((char*)(x)+1); \
00054 *((char*)(x)+1) = *((char*)(x)+6); \
00055 *((char*)(x)+6) = tmp_byte; \
00056 tmp_byte = *((char*)(x)+2); \
00057 *((char*)(x)+2) = *((char*)(x)+5); \
00058 *((char*)(x)+5) = tmp_byte; \
00059 tmp_byte = *((char*)(x)+3); \
00060 *((char*)(x)+3) = *((char*)(x)+4); \
00061 *((char*)(x)+4) = tmp_byte; \
00062 }
00063
00064 #if 0
00065 #define SWAPHALF(x) *(short*)(x) = ((0xff & (*(short*)(x)) >> 8) | \
00066 (0xff00 & (*(short*)(x)) << 8))
00067 #define SWAPWORD(x) *(int*) (x) = ((0xff & (*(int*)(x)) >> 24) | \
00068 (0xff00 & (*(int*)(x)) >> 8) | \
00069 (0xff0000 & (*(int*)(x)) << 8) | \
00070 (0xff000000 & (*(int*)(x)) << 24))
00071 #define SWAPDOUBLE(x) { int *low = (int *) (x), \
00072 *high = (int *) (x) + 1, temp;\
00073 SWAPWORD(low); SWAPWORD(high);\
00074 temp = *low; *low = *high; *high = temp;}
00075 #endif
00076 #else
00077
00078 #define SWAPFIELD(x)
00079 #define SWAPHALF(x)
00080 #define SWAPWORD(x)
00081 #define SWAPDOUBLE(x)
00082
00083 #endif
00084
00085
00086 #define ALWAYS_SWAPFIELD(x) {\
00087 if (sizeof(*(x))==sizeof(short)) {SWAPHALF((x))} \
00088 else if (sizeof(*(x))==sizeof(int)) {SWAPWORD((x))} \
00089 else if (sizeof(*(x))==sizeof(double)){SWAPDOUBLE((x))}\
00090 }
00091
00092 #define ALWAYS_SWAPHALF(x) {char tmp_byte; \
00093 tmp_byte = *((char*)(x)+0); \
00094 *((char*)(x)+0) = *((char*)(x)+1); \
00095 *((char*)(x)+1) = tmp_byte; \
00096 }
00097 #define ALWAYS_SWAPWORD(x) {char tmp_byte; \
00098 tmp_byte = *((char*)(x)+0); \
00099 *((char*)(x)+0) = *((char*)(x)+3); \
00100 *((char*)(x)+3) = tmp_byte; \
00101 tmp_byte = *((char*)(x)+1); \
00102 *((char*)(x)+1) = *((char*)(x)+2); \
00103 *((char*)(x)+2) = tmp_byte; \
00104 }
00105
00106 #define ALWAYS_SWAPDOUBLE(x) {char tmp_byte; \
00107 tmp_byte = *((char*)(x)+0); \
00108 *((char*)(x)+0) = *((char*)(x)+7); \
00109 *((char*)(x)+7) = tmp_byte; \
00110 tmp_byte = *((char*)(x)+1); \
00111 *((char*)(x)+1) = *((char*)(x)+6); \
00112 *((char*)(x)+6) = tmp_byte; \
00113 tmp_byte = *((char*)(x)+2); \
00114 *((char*)(x)+2) = *((char*)(x)+5); \
00115 *((char*)(x)+5) = tmp_byte; \
00116 tmp_byte = *((char*)(x)+3); \
00117 *((char*)(x)+3) = *((char*)(x)+4); \
00118 *((char*)(x)+4) = tmp_byte; \
00119 }
00120
00121 #endif
00122