7 static inline int clip2(int v, int mn, int mx) {
8 if( v > mx ) return mx;
9 if( v < mn ) return mn;
13 static inline uint8_t clip(int32_t v) {
14 return ((uint8_t)v) == v ? v : clip2(v,0,255);
17 #define m_(v) (*(mmx_t*)(((long long *)(v))))
19 int main(int ac, char **av)
22 unsigned char dat0[8] = { 0x01, 0xf2, 0x03, 0x04, 0x05, 0x06, 0xf7, 0x08 };
23 long long *datp = (long long *)&dat0;
24 int16_t dat1[8] = { 0x10, 0x20, -0x130, -0x140, 0x50, -0x160, -0x170, 0x80 };
25 volatile uint8_t *rfp = dat0;
26 volatile int16_t *bp = dat1;
27 unsigned char ans1[8], ans2[8];
30 for( i=-32768; i<32768; ++i ) {
33 for( k=0; k<8; ++k ) {
37 movq_m2r(m_(&rfp[0]),mm1); /* rfp[0..7] */
40 movq_m2r(m_(&bp[0]),mm5); /* bp[0..3] */
42 movq_m2r(m_(&bp[4]),mm6); /* bp[4..7] */
43 punpcklbw_r2r(mm3,mm1); /* rfp[0,2,4,6] */
44 punpckhbw_r2r(mm3,mm2); /* rfp[1,3,5,7] */
45 paddsw_r2r(mm5,mm1); /* bp[0..3] */
46 paddsw_r2r(mm6,mm2); /* bp[4..7] */
51 packuswb_r2r(mm4,mm3);
52 movq_r2m(mm3,m_(&ans1[0]));
55 ans2[0] = clip(bp[0] + rfp[0]);
56 ans2[1] = clip(bp[1] + rfp[1]);
57 ans2[2] = clip(bp[2] + rfp[2]);
58 ans2[3] = clip(bp[3] + rfp[3]);
59 ans2[4] = clip(bp[4] + rfp[4]);
60 ans2[5] = clip(bp[5] + rfp[5]);
61 ans2[6] = clip(bp[6] + rfp[6]);
62 ans2[7] = clip(bp[7] + rfp[7]);
64 if( *(uint64_t *)&ans1[0] != *(uint64_t *)&ans2[0] )
66 printf(" i=%5d %02x %02x %02x %02x %02x %02x %02x %02x\n", i,
67 ans1[0], ans1[1], ans1[2], ans1[3], ans1[4], ans1[5], ans1[6], ans1[7]);
68 printf(" j=%5d %02x %02x %02x %02x %02x %02x %02x %02x\n", j,
69 ans2[0], ans2[1], ans2[2], ans2[3], ans2[4], ans2[5], ans2[6], ans2[7]);