1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
| #pragma once
| #ifndef _FUNCTIONS_HPP_
| #define _FUNCTIONS_HPP_
|
| static int AnsiToW(CStringA & Src, CStringW & Dest)
| {
| int j,l;
| l=Src.GetLength();
| j=MultiByteToWideChar(CP_ACP,0,Src,l,Dest.GetBuffer(l),l);
| Dest.ReleaseBuffer(j);
| return 0;
| }
| static int WToAnsi(CStringW & Src, CStringA & Dest)
| {
| int j,l;
| l=Src.GetLength();
| j=WideCharToMultiByte(CP_ACP,0,Src,l,Dest.GetBuffer(l*2),l*2,NULL,0);
| Dest.ReleaseBuffer(j);
| return 0;
| }
| inline int AnsiToT(CStringA & Src, CString & Dest)
| {
| #ifdef UNICODE
| AnsiToW(Src,Dest);
| #else
| Dest=Src;
| #endif
| return 0;
| }
| static int TToAnsi(CString & Src, CStringA & Dest)
| {
| #ifdef UNICODE
| WToAnsi(Src,Dest);
| #else
| Dest=Src;
| #endif
| return 0;
| }
| static int TToW(CString & Src, CStringW & Dest)
| {
| #ifdef UNICODE
| Dest=Src;
| #else
| AnsiToW(Src,Dest);
| #endif
| return 0;
| }
| static int WToT(CStringW & Src, CString & Dest)
| {
| #ifdef UNICODE
| Dest=Src;
| #else
| WToAnsi(Src,Dest);
| #endif
| return 0;
| }
|
| inline double GetTickCountmS()
| {
| LARGE_INTEGER perfreq;
| LARGE_INTEGER percounter1; //,percounter2;
| double time1; //,time2,timeinter1;
| QueryPerformanceFrequency(&perfreq);
| QueryPerformanceCounter(&percounter1);
| // percounter1.QuadPart=rdtsc();
| /* _asm {
| RDTSC;
| mov percounter1.LowPart,eax;
| mov percounter1.HighPart,edx;
| }
| */
| time1=(double)percounter1.QuadPart/perfreq.QuadPart ;
| // time2=(double)percounter2.QuadPart/perfreq.QuadPart ;
| // timeinter1=time2-time1;
| return (time1*1000);
| };
| /*
| template <class ST>
| int Split(ST s1,ST divider, ST resultstr[])
| {
| int i,j,k,l;
| // CString s2;
| k=0;
| i=0;
| l=s1.GetLength();
| for (i=0;k<l&&i<1024;i++)
| {
| j=s1.Find(divider,k);
| if (j==-1)
| {
| resultstr[i]=s1.Mid(k);
| i++;
| break;
| }
| resultstr[i]=s1.Mid(k,j-k);
| // s2.Format(_T("%d %d %d \r\n"),i,j,k);
| // ::SysLog(s2);
| k=j+divider.GetLength();
| }
| return i;
| }
| */
| //template int Split<CStringA>(CStringA a,CStringA b,CStringA c[]);
| ///*
| static inline int Xtoi(const char * hexstr)
| {
| int i,j,k;
| unsigned char ch;
| k=0;j=0;
| int len=(int)strlen(hexstr);
| for (i=0;i<len;i++)
| {
| ch=hexstr[i];
| if (ch>='0'&&ch<='9')
| {
| k=ch-'0';
| j=j*16+k;
| continue;
| }
| if (ch>='A'&&ch<='F')
| {
| k=ch-'A'+10;
| j=j*16+k;
| continue;
| }
| if (ch>='a'&&ch<='f')
| {
| k=ch-'a'+10;
| j=j*16+k;
| continue;
| }
| if (ch==' '||ch==' ')
| {
| continue;
| }
| break;
| }
| return j;
| }
| static inline int Xtoi(CString hexstr)
| {
| int i,j,k;
| TCHAR ch;
| k=0;j=0;
| int len=hexstr.GetLength();
| for (i=0;i<len;i++)
| {
| ch=hexstr[i];
| if (ch>=_T('0')&&ch<=_T('9'))
| {
| k=ch-_T('0');
| j=j*16+k;
| continue;
| }
| if (ch>=_T('A')&&ch<=_T('F'))
| {
| k=ch-_T('A')+10;
| j=j*16+k;
| continue;
| }
| if (ch>=_T('a')&&ch<=_T('f'))
| {
| k=ch-_T('a')+10;
| j=j*16+k;
| continue;
| }
| if (ch==_T(' ')||ch==_T(' '))
| {
| continue;
| }
| break;
| }
| return j;
| }
| inline int Split(CString s1,CString divider,CString resultstr[])
| {
| int i,j,k,l;
| // CString s2;
| k=0;
| i=0;
| l=s1.GetLength();
| for (i=0;k<l&&i<1024;i++)
| {
| j=s1.Find(divider,k);
| if (j==-1)
| {
| resultstr[i]=s1.Mid(k);
| i++;
| break;
| }
| resultstr[i]=s1.Mid(k,j-k);
| // s2.Format(_T("%d %d %d \r\n"),i,j,k);
| // ::SysLog(s2);
| k=j+divider.GetLength();
| }
| return i;
| }
|
| inline int Split(CStringA s1,CStringA divider,CStringA resultstr[])
| {
| int i,j,k,l;
| // CString s2;
| k=0;
| i=0;
| l=s1.GetLength();
| for (i=0;k<l&&i<2048;i++)
| {
| j=s1.Find(divider,k);
| if (j==-1)
| {
| resultstr[i]=s1.Mid(k);
| i++;
| break;
| }
| resultstr[i]=s1.Mid(k,j-k);
| // s2.Format(_T("%d %d %d \r\n"),i,j,k);
| // ::SysLog(s2);
| k=j+divider.GetLength();
| }
| return i;
| }
| //*/
| inline WCHAR* ToWChar(char * str)
| {
| //ÔÚGDI£«ÖУ¬ÓйØ×Ö·ûµÄ²ÎÊýÀàÐÍÈ«²¿¶¼ÊÇWCHARÀàÐ͵Ä
| //¸Ãº¯ÊýÊǽ«´«Í³×Ö·û´®½øÐÐת»»
|
| static WCHAR buffer[1024];
| wmemset(buffer,0,1024);
| //_wcsset(buffer,0);
| MultiByteToWideChar(CP_ACP,0,str,(int)strlen(str),buffer,1024);
| //LPCSTR
| //WideCharToMultiByte(
| return buffer;
| }
|
|
| inline void X_aligned_memcpy_sse2(void* dest, const void* src, const unsigned long size_t)
| {
| /*
| __asm
| {
| mov esi, src; //src pointer
| mov edi, dest; //dest pointer
|
| mov ebx, size_t; //ebx is our counter
| shr ebx, 7; //divide by 128 (8 * 128bit registers)
|
| loop_copy:
| prefetchnta 128[ESI]; //SSE2 prefetch
| prefetchnta 160[ESI];
| prefetchnta 192[ESI];
| prefetchnta 224[ESI];
|
| movdqa xmm0, 0[ESI]; //move data from src to registers
| movdqa xmm1, 16[ESI];
| movdqa xmm2, 32[ESI];
| movdqa xmm3, 48[ESI];
| movdqa xmm4, 64[ESI];
| movdqa xmm5, 80[ESI];
| movdqa xmm6, 96[ESI];
| movdqa xmm7, 112[ESI];
|
| movntdq 0[EDI], xmm0; //move data from registers to dest
| movntdq 16[EDI], xmm1;
| movntdq 32[EDI], xmm2;
| movntdq 48[EDI], xmm3;
| movntdq 64[EDI], xmm4;
| movntdq 80[EDI], xmm5;
| movntdq 96[EDI], xmm6;
| movntdq 112[EDI], xmm7;
|
| add esi, 128;
| add edi, 128;
| dec ebx;
|
| jnz loop_copy; //loop please
| sfence
| //loop_copy_end:
| }
| */
| }
| //*/
| #endif //_FUNCTIONS_HPP_
|
|