21 #ifndef _XBOOST_HAAR_FEATURE_JIT_H
22 #define _XBOOST_HAAR_FEATURE_JIT_H
39 typedef int (* callback)(
const unsigned int *) __attribute__((fastcall));
43 std::vector<unsigned char *> m_pages;
45 unsigned char *m_proc;
49 void push_back(
unsigned char c)
53 std::cerr <<
"Exceed " << pagesize <<
" bytes" << std::endl;
54 throw std::runtime_error(
"too large application");
60 int is_8bit(
int offset)
62 return (offset<128) && (offset>-129);
67 if(posix_memalign((
void**) &m_proc, pagesize,pagesize)!=0)
68 throw std::runtime_error(
"posix_memalign failed");
69 memset(m_proc, 0x90, pagesize);
70 if(mprotect(m_proc, pagesize, PROT_EXEC|PROT_READ|PROT_WRITE)!=0)
71 throw std::runtime_error(
"mprotect failed");
72 m_pages.push_back(m_proc);
79 pagesize = sysconf(_SC_PAGE_SIZE)*4;
85 for(std::vector<unsigned char *>::const_iterator i = m_pages.begin(); i!= m_pages.end(); ++i)
91 for(std::vector<unsigned char *>::const_iterator i = m_pages.begin(); i!= m_pages.end(); ++i)
104 return reinterpret_cast<callback
>(&m_proc[index]);
116 push_back(offset & 0xff);
123 push_back(offset & 0xff);
124 push_back((offset & 0xff00)>>8);
125 push_back((offset & 0xff0000)>>16);
126 push_back((offset & 0xff000000)>>24);
139 push_back(offset & 0xff);
146 push_back(offset & 0xff);
147 push_back((offset & 0xff00)>>8);
148 push_back((offset & 0xff0000)>>16);
149 push_back((offset & 0xff000000)>>24);
163 push_back(offset&0xff);
170 push_back(offset & 0xff);
171 push_back((offset & 0xff00)>>8);
172 push_back((offset & 0xff0000)>>16);
173 push_back((offset & 0xff000000)>>24);
211 index = (index+15)&(~0xF);
232 for(std::vector<HaarNode>::const_iterator i=src.begin();i!=src.end();++i)
233 mul[ std::abs(i->sign) - 1] = 1;
246 if((mul[1]+mul[2]+mul[3])>1)
251 for(std::vector<HaarNode>::const_iterator i=src.begin();i!=src.end();++i)
254 int __offset = (offset + i->x + i->y * stride)*4;
263 for(
int j=0;j<i->sign;++j)
268 for(std::vector<HaarNode>::const_iterator i=src.begin();i!=src.end();++i)
271 int __offset = (offset + i->x + i->y * stride)*4;
272 for(
int j=0;j<std::abs(i->sign);++j)
281 for(std::vector<HaarNode>::const_iterator i=src.begin();i!=src.end();++i)
282 if( i->sign == factor)
284 int __offset = (offset + i->x + i->y * stride)*4;
294 for(std::vector<HaarNode>::const_iterator i=src.begin();i!=src.end();++i)
295 if( i->sign == -factor)
297 int __offset = (offset + i->x + i->y * stride)*4;
305 for(std::vector<HaarNode>::const_iterator i=src.begin();i!=src.end();++i)
307 int __offset = (offset + i->x + i->y * stride)*4;
319 for(std::vector<HaarNode>::const_iterator i=src.begin();i!=src.end();++i)
322 int __offset = (offset + i->x + i->y * stride)*4;
332 for(std::vector<HaarNode>::const_iterator i=src.begin();i!=src.end();++i)
335 int __offset = (offset + i->x + i->y * stride)*4;
345 inline int response(
const unsigned int *pIntImage)
const
352 return proc(pIntImage);
355 inline int operator() (
const unsigned int *pIntImage)
const
Definition: JITHaarFeature.h:37
int response(const unsigned int *pIntImage) const
compute the response
Definition: JITHaarFeature.h:345
void retq()
complete and return the procedure
Definition: JITHaarFeature.h:205
an optimized HaarFeature
Definition: CollapsedHaarFeature.h:50
An haar Feature: a collection of weighted HaarNode.
Definition: HaarFeature.h:63
Definition: JITHaarFeature.h:218
callback GetProcAddr() const
Return the current procedure addres.
Definition: JITHaarFeature.h:102
void add(int offset)
Definition: JITHaarFeature.h:132
void mul(int f)
NOTE: offset in bytes and not in uint32_t!!!
Definition: JITHaarFeature.h:178
void move(int offset)
Definition: JITHaarFeature.h:109
void sub(int offset)
Definition: JITHaarFeature.h:156