00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef INCLUDE_BASE_INTUTILS_H
00017 #define INCLUDE_BASE_INTUTILS_H
00018
00019 #include <string.h>
00020
00021 #ifdef __cplusplus
00022 extern "C" {
00023 #endif
00024
00025 #include "base/inttypes.h"
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 static inline
00044 uint32_t base_subu32(uint32_t a, uint32_t b, uint32_t *cp)
00045 {
00046 #if defined(__GNUG__) && defined(i386)
00047 uint32_t c = *cp;
00048 asm("rcrl %1 # Move borrow to carry flag.\n\t"
00049 "sbbl %2, %0 # Perform subtraction.\n\t"
00050 "rcll %1 # Move borrow from carry flag.\n\t"
00051 : "=r" (a), "=r" (c) : "rm" (b), "0" (a), "1" (c) : "cc");
00052 *cp = c;
00053 return a;
00054 #else
00055 uint32_t c = *cp;
00056 uint32_t v = (b + c);
00057 *cp = ((a < v) || (c > v) ? 1 : 0);
00058 return a - v;
00059 #endif
00060 }
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078 void base_copySmall(void *dst, const void *src, size_t intSize);
00079
00080 static inline
00081 void base_copyLarge(void *dst, const void *src, size_t intSize)
00082 {
00083 #if INTEL_ARCH
00084 memcpy(dst, src, intSize << 2);
00085 #else
00086 base_copySmall(dst, src, intSize);
00087 #endif
00088 }
00089
00090
00091
00092 static inline
00093 void base_copyBest(void *dst, const void *src, size_t intSize)
00094 {
00095 #if INTEL_ARCH
00096 (intSize < 180 ? base_copySmall : base_copyLarge)(dst, src, intSize);
00097 #else
00098 base_copySmall(dst, src, intSize);
00099 #endif
00100 }
00101
00102
00103
00104
00105
00106
00107
00108
00109 void base_fill(void *mem, size_t intSize, uint32_t intValue);
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119 uint32_t base_diff(const void *mem, size_t intSize, uint32_t intValue);
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137 static inline
00138 void base_resetSmall(void *mem, size_t intSize)
00139 {
00140 base_fill(mem, intSize, 0);
00141 }
00142
00143 static inline
00144 void base_resetLarge(void *mem, size_t intSize)
00145 {
00146 #if INTEL_ARCH
00147 memset(mem, 0, intSize << 2);
00148 #else
00149 base_fill(mem, intSize, 0);
00150 #endif
00151 }
00152
00153
00154
00155 static inline
00156 void base_resetBest(void *mem, size_t intSize)
00157 {
00158 #if INTEL_ARCH
00159 (intSize < 200 ? base_resetSmall : base_resetLarge)(mem, intSize);
00160 #else
00161 base_fill(mem, intSize, 0);
00162 #endif
00163 }
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173 BOOL base_areEqual(const void *data1, const void *data2, size_t intSize);
00174
00175
00176
00177
00178
00179 static inline
00180 int32_t base_abs(int32_t x)
00181 {
00182
00183
00184
00185
00186
00187
00188
00189
00190 uint32_t sign = ((uint32_t) x) >> 31;
00191 return (x ^ -sign) + sign;
00192 }
00193
00194
00195
00196
00197
00198 static inline
00199 int32_t base_absNot(int32_t x)
00200 {
00201
00202
00203 uint32_t sign = ((uint32_t) x) >> 31;
00204 return (x ^ -sign);
00205 }
00206
00207
00208
00209
00210
00211
00212
00213 void base_sort(uint32_t *values, size_t n);
00214
00215
00216 #ifdef __cplusplus
00217 }
00218 #endif
00219
00220 #endif