Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
quantize.cpp File Reference
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "xbyak/xbyak.h"
Include dependency graph for quantize.cpp:

Go to the source code of this file.

Classes

class  Quantize
 

Macros

#define XBYAK_NO_OP_NAMES
 

Typedefs

typedef Xbyak::uint64 uint64
 
typedef Xbyak::uint32 uint32
 

Functions

void quantize (uint32 dest[64], const uint32 src[64], const uint32 qTbl[64])
 
int main (int argc, char *argv[])
 

Variables

const int N = 64
 

Macro Definition Documentation

◆ XBYAK_NO_OP_NAMES

#define XBYAK_NO_OP_NAMES

Definition at line 45 of file quantize.cpp.

Typedef Documentation

◆ uint32

Definition at line 52 of file quantize.cpp.

◆ uint64

Definition at line 51 of file quantize.cpp.

Function Documentation

◆ main()

int main ( int argc,
char * argv[] )

Definition at line 160 of file quantize.cpp.

161{
162 int q;
163 if (argc > 1) {
164 q = atoi(argv[1]);
165 } else {
166 printf("input quantize=");
167 if (scanf("%d", &q) != 1) {
168 fprintf(stderr, "bad number\n");
169 return 1;
170 }
171 }
172 printf("q=%d\n", q);
173 uint32 qTbl[] = {
174 16, 11, 10, 16, 24, 40, 51, 61,
175 12, 12, 14, 19, 26, 58, 60, 55,
176 14, 13, 16, 24, 40, 57, 69, 56,
177 14, 17, 22, 29, 51, 87, 80, 62,
178 18, 22, 37, 56, 68, 109, 103, 77,
179 24, 35, 55, 64, 81, 104, 113, 92,
180 49, 64, 78, 87, 103, 121, 120, 101,
181 72, 92, 95, 98, 112, 100, 103, 99
182 };
183
184 for (int i = 0; i < N; i++) {
185 qTbl[i] /= q;
186 if (qTbl[i] == 0) qTbl[i] = 1;
187 }
188
189 try {
190 uint32 src[N];
191 uint32 dest[N];
192 uint32 dest2[N];
193 for (int i = 0; i < N; i++) {
194 src[i] = rand() % 2048;
195 }
196
197 Quantize jit(qTbl);
198//printf("jit size=%d, ptr=%p\n", jit.getSize(), jit.getCode());
199 void (*quantize2)(uint32*, const uint32*, const uint32 *) = jit.getCode<void (*)(uint32*, const uint32*, const uint32 *)>();
200
201 quantize(dest, src, qTbl);
202 quantize2(dest2, src, qTbl);
203 for (int i = 0; i < N; i++) {
204 if (dest[i] != dest2[i]) {
205 printf("err[%d] %d %d\n", i, dest[i], dest2[i]);
206 }
207 }
208
209 const int count = 10000000;
210 int begin;
211
212 begin = clock();
213 for (int i = 0; i < count; i++) {
214 quantize(dest, src, qTbl);
215 }
216 printf("time=%.1fsec\n", (clock() - begin) / double(CLOCKS_PER_SEC));
217
218 begin = clock();
219 for (int i = 0; i < count; i++) {
220 quantize2(dest, src, qTbl);
221 }
222 printf("time=%.1fsec\n", (clock() - begin) / double(CLOCKS_PER_SEC));
223 } catch (std::exception& e) {
224 printf("ERR:%s\n", e.what());
225 } catch (...) {
226 printf("unknown error\n");
227 }
228}
int * count
char ** argv
LOGGING_API void printf(Category category, const char *format,...)
Definition Logging.cpp:30
void quantize(uint32 dest[64], const uint32 src[64], const uint32 qTbl[64])
Definition quantize.cpp:146
const int N
Definition quantize.cpp:54
Xbyak::uint32 uint32
Definition quantize.cpp:52
Here is the call graph for this function:

◆ quantize()

void quantize ( uint32 dest[64],
const uint32 src[64],
const uint32 qTbl[64] )

Definition at line 146 of file quantize.cpp.

147{
148 for (int i = 0; i < N; i++) {
149 dest[i] = src[i] / qTbl[i];
150 }
151}
Here is the caller graph for this function:

Variable Documentation

◆ N

const int N = 64

Definition at line 54 of file quantize.cpp.