Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/media/libtheora/lib/x86/mmxfrag.c
Line
Count
Source (jump to first uncovered line)
1
/********************************************************************
2
 *                                                                  *
3
 * THIS FILE IS PART OF THE OggTheora SOFTWARE CODEC SOURCE CODE.   *
4
 * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS     *
5
 * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
6
 * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING.       *
7
 *                                                                  *
8
 * THE Theora SOURCE CODE IS COPYRIGHT (C) 2002-2009                *
9
 * by the Xiph.Org Foundation and contributors http://www.xiph.org/ *
10
 *                                                                  *
11
 ********************************************************************
12
13
  function:
14
    last mod: $Id: mmxfrag.c 17410 2010-09-21 21:53:48Z tterribe $
15
16
 ********************************************************************/
17
18
/*MMX acceleration of fragment reconstruction for motion compensation.
19
  Originally written by Rudolf Marek.
20
  Additional optimization by Nils Pipenbrinck.
21
  Note: Loops are unrolled for best performance.
22
  The iteration each instruction belongs to is marked in the comments as #i.*/
23
#include <stddef.h>
24
#include "x86int.h"
25
26
#if defined(OC_X86_ASM)
27
28
/*Copies an 8x8 block of pixels from _src to _dst, assuming _ystride bytes
29
   between rows.*/
30
# define OC_FRAG_COPY_MMX(_dst,_src,_ystride) \
31
0
  do{ \
32
0
    const unsigned char *src; \
33
0
    unsigned char       *dst; \
34
0
    ptrdiff_t            ystride3; \
35
0
    src=(_src); \
36
0
    dst=(_dst); \
37
0
    __asm__ __volatile__( \
38
0
      /*src+0*ystride*/ \
39
0
      "movq (%[src]),%%mm0\n\t" \
40
0
      /*src+1*ystride*/ \
41
0
      "movq (%[src],%[ystride]),%%mm1\n\t" \
42
0
      /*ystride3=ystride*3*/ \
43
0
      "lea (%[ystride],%[ystride],2),%[ystride3]\n\t" \
44
0
      /*src+2*ystride*/ \
45
0
      "movq (%[src],%[ystride],2),%%mm2\n\t" \
46
0
      /*src+3*ystride*/ \
47
0
      "movq (%[src],%[ystride3]),%%mm3\n\t" \
48
0
      /*dst+0*ystride*/ \
49
0
      "movq %%mm0,(%[dst])\n\t" \
50
0
      /*dst+1*ystride*/ \
51
0
      "movq %%mm1,(%[dst],%[ystride])\n\t" \
52
0
      /*Pointer to next 4.*/ \
53
0
      "lea (%[src],%[ystride],4),%[src]\n\t" \
54
0
      /*dst+2*ystride*/ \
55
0
      "movq %%mm2,(%[dst],%[ystride],2)\n\t" \
56
0
      /*dst+3*ystride*/ \
57
0
      "movq %%mm3,(%[dst],%[ystride3])\n\t" \
58
0
      /*Pointer to next 4.*/ \
59
0
      "lea (%[dst],%[ystride],4),%[dst]\n\t" \
60
0
      /*src+0*ystride*/ \
61
0
      "movq (%[src]),%%mm0\n\t" \
62
0
      /*src+1*ystride*/ \
63
0
      "movq (%[src],%[ystride]),%%mm1\n\t" \
64
0
      /*src+2*ystride*/ \
65
0
      "movq (%[src],%[ystride],2),%%mm2\n\t" \
66
0
      /*src+3*ystride*/ \
67
0
      "movq (%[src],%[ystride3]),%%mm3\n\t" \
68
0
      /*dst+0*ystride*/ \
69
0
      "movq %%mm0,(%[dst])\n\t" \
70
0
      /*dst+1*ystride*/ \
71
0
      "movq %%mm1,(%[dst],%[ystride])\n\t" \
72
0
      /*dst+2*ystride*/ \
73
0
      "movq %%mm2,(%[dst],%[ystride],2)\n\t" \
74
0
      /*dst+3*ystride*/ \
75
0
      "movq %%mm3,(%[dst],%[ystride3])\n\t" \
76
0
      :[dst]"+r"(dst),[src]"+r"(src),[ystride3]"=&r"(ystride3) \
77
0
      :[ystride]"r"((ptrdiff_t)(_ystride)) \
78
0
      :"memory" \
79
0
    ); \
80
0
  } \
81
0
  while(0)
82
83
/*Copies an 8x8 block of pixels from _src to _dst, assuming _ystride bytes
84
   between rows.*/
85
void oc_frag_copy_mmx(unsigned char *_dst,
86
0
 const unsigned char *_src,int _ystride){
87
0
  OC_FRAG_COPY_MMX(_dst,_src,_ystride);
88
0
}
89
90
/*Copies the fragments specified by the lists of fragment indices from one
91
   frame to another.
92
  _dst_frame:     The reference frame to copy to.
93
  _src_frame:     The reference frame to copy from.
94
  _ystride:       The row stride of the reference frames.
95
  _fragis:        A pointer to a list of fragment indices.
96
  _nfragis:       The number of fragment indices to copy.
97
  _frag_buf_offs: The offsets of fragments in the reference frames.*/
98
void oc_frag_copy_list_mmx(unsigned char *_dst_frame,
99
 const unsigned char *_src_frame,int _ystride,
100
0
 const ptrdiff_t *_fragis,ptrdiff_t _nfragis,const ptrdiff_t *_frag_buf_offs){
101
0
  ptrdiff_t fragii;
102
0
  for(fragii=0;fragii<_nfragis;fragii++){
103
0
    ptrdiff_t frag_buf_off;
104
0
    frag_buf_off=_frag_buf_offs[_fragis[fragii]];
105
0
    OC_FRAG_COPY_MMX(_dst_frame+frag_buf_off,
106
0
     _src_frame+frag_buf_off,_ystride);
107
0
  }
108
0
}
109
110
111
void oc_frag_recon_intra_mmx(unsigned char *_dst,int _ystride,
112
0
 const ogg_int16_t *_residue){
113
0
  __asm__ __volatile__(
114
0
    /*Set mm0 to 0xFFFFFFFFFFFFFFFF.*/
115
0
    "pcmpeqw %%mm0,%%mm0\n\t"
116
0
    /*#0 Load low residue.*/
117
0
    "movq 0*8(%[residue]),%%mm1\n\t"
118
0
    /*#0 Load high residue.*/
119
0
    "movq 1*8(%[residue]),%%mm2\n\t"
120
0
    /*Set mm0 to 0x8000800080008000.*/
121
0
    "psllw $15,%%mm0\n\t"
122
0
    /*#1 Load low residue.*/
123
0
    "movq 2*8(%[residue]),%%mm3\n\t"
124
0
    /*#1 Load high residue.*/
125
0
    "movq 3*8(%[residue]),%%mm4\n\t"
126
0
    /*Set mm0 to 0x0080008000800080.*/
127
0
    "psrlw $8,%%mm0\n\t"
128
0
    /*#2 Load low residue.*/
129
0
    "movq 4*8(%[residue]),%%mm5\n\t"
130
0
    /*#2 Load high residue.*/
131
0
    "movq 5*8(%[residue]),%%mm6\n\t"
132
0
    /*#0 Bias low  residue.*/
133
0
    "paddsw %%mm0,%%mm1\n\t"
134
0
    /*#0 Bias high residue.*/
135
0
    "paddsw %%mm0,%%mm2\n\t"
136
0
    /*#0 Pack to byte.*/
137
0
    "packuswb %%mm2,%%mm1\n\t"
138
0
    /*#1 Bias low  residue.*/
139
0
    "paddsw %%mm0,%%mm3\n\t"
140
0
    /*#1 Bias high residue.*/
141
0
    "paddsw %%mm0,%%mm4\n\t"
142
0
    /*#1 Pack to byte.*/
143
0
    "packuswb %%mm4,%%mm3\n\t"
144
0
    /*#2 Bias low  residue.*/
145
0
    "paddsw %%mm0,%%mm5\n\t"
146
0
    /*#2 Bias high residue.*/
147
0
    "paddsw %%mm0,%%mm6\n\t"
148
0
    /*#2 Pack to byte.*/
149
0
    "packuswb %%mm6,%%mm5\n\t"
150
0
    /*#0 Write row.*/
151
0
    "movq %%mm1,(%[dst])\n\t"
152
0
    /*#1 Write row.*/
153
0
    "movq %%mm3,(%[dst],%[ystride])\n\t"
154
0
    /*#2 Write row.*/
155
0
    "movq %%mm5,(%[dst],%[ystride],2)\n\t"
156
0
    /*#3 Load low residue.*/
157
0
    "movq 6*8(%[residue]),%%mm1\n\t"
158
0
    /*#3 Load high residue.*/
159
0
    "movq 7*8(%[residue]),%%mm2\n\t"
160
0
    /*#4 Load high residue.*/
161
0
    "movq 8*8(%[residue]),%%mm3\n\t"
162
0
    /*#4 Load high residue.*/
163
0
    "movq 9*8(%[residue]),%%mm4\n\t"
164
0
    /*#5 Load high residue.*/
165
0
    "movq 10*8(%[residue]),%%mm5\n\t"
166
0
    /*#5 Load high residue.*/
167
0
    "movq 11*8(%[residue]),%%mm6\n\t"
168
0
    /*#3 Bias low  residue.*/
169
0
    "paddsw %%mm0,%%mm1\n\t"
170
0
    /*#3 Bias high residue.*/
171
0
    "paddsw %%mm0,%%mm2\n\t"
172
0
    /*#3 Pack to byte.*/
173
0
    "packuswb %%mm2,%%mm1\n\t"
174
0
    /*#4 Bias low  residue.*/
175
0
    "paddsw %%mm0,%%mm3\n\t"
176
0
    /*#4 Bias high residue.*/
177
0
    "paddsw %%mm0,%%mm4\n\t"
178
0
    /*#4 Pack to byte.*/
179
0
    "packuswb %%mm4,%%mm3\n\t"
180
0
    /*#5 Bias low  residue.*/
181
0
    "paddsw %%mm0,%%mm5\n\t"
182
0
    /*#5 Bias high residue.*/
183
0
    "paddsw %%mm0,%%mm6\n\t"
184
0
    /*#5 Pack to byte.*/
185
0
    "packuswb %%mm6,%%mm5\n\t"
186
0
    /*#3 Write row.*/
187
0
    "movq %%mm1,(%[dst],%[ystride3])\n\t"
188
0
    /*#4 Write row.*/
189
0
    "movq %%mm3,(%[dst4])\n\t"
190
0
    /*#5 Write row.*/
191
0
    "movq %%mm5,(%[dst4],%[ystride])\n\t"
192
0
    /*#6 Load low residue.*/
193
0
    "movq 12*8(%[residue]),%%mm1\n\t"
194
0
    /*#6 Load high residue.*/
195
0
    "movq 13*8(%[residue]),%%mm2\n\t"
196
0
    /*#7 Load low residue.*/
197
0
    "movq 14*8(%[residue]),%%mm3\n\t"
198
0
    /*#7 Load high residue.*/
199
0
    "movq 15*8(%[residue]),%%mm4\n\t"
200
0
    /*#6 Bias low  residue.*/
201
0
    "paddsw %%mm0,%%mm1\n\t"
202
0
    /*#6 Bias high residue.*/
203
0
    "paddsw %%mm0,%%mm2\n\t"
204
0
    /*#6 Pack to byte.*/
205
0
    "packuswb %%mm2,%%mm1\n\t"
206
0
    /*#7 Bias low  residue.*/
207
0
    "paddsw %%mm0,%%mm3\n\t"
208
0
    /*#7 Bias high residue.*/
209
0
    "paddsw %%mm0,%%mm4\n\t"
210
0
    /*#7 Pack to byte.*/
211
0
    "packuswb %%mm4,%%mm3\n\t"
212
0
    /*#6 Write row.*/
213
0
    "movq %%mm1,(%[dst4],%[ystride],2)\n\t"
214
0
    /*#7 Write row.*/
215
0
    "movq %%mm3,(%[dst4],%[ystride3])\n\t"
216
0
    :
217
0
    :[residue]"r"(_residue),
218
0
     [dst]"r"(_dst),
219
0
     [dst4]"r"(_dst+(_ystride<<2)),
220
0
     [ystride]"r"((ptrdiff_t)_ystride),
221
0
     [ystride3]"r"((ptrdiff_t)_ystride*3)
222
0
    :"memory"
223
0
  );
224
0
}
225
226
void oc_frag_recon_inter_mmx(unsigned char *_dst,const unsigned char *_src,
227
0
 int _ystride,const ogg_int16_t *_residue){
228
0
  int i;
229
0
  /*Zero mm0.*/
230
0
  __asm__ __volatile__("pxor %%mm0,%%mm0\n\t"::);
231
0
  for(i=4;i-->0;){
232
0
    __asm__ __volatile__(
233
0
      /*#0 Load source.*/
234
0
      "movq (%[src]),%%mm3\n\t"
235
0
      /*#1 Load source.*/
236
0
      "movq (%[src],%[ystride]),%%mm7\n\t"
237
0
      /*#0 Get copy of src.*/
238
0
      "movq %%mm3,%%mm4\n\t"
239
0
      /*#0 Expand high source.*/
240
0
      "punpckhbw %%mm0,%%mm4\n\t"
241
0
      /*#0 Expand low  source.*/
242
0
      "punpcklbw %%mm0,%%mm3\n\t"
243
0
      /*#0 Add residue high.*/
244
0
      "paddsw 8(%[residue]),%%mm4\n\t"
245
0
      /*#1 Get copy of src.*/
246
0
      "movq %%mm7,%%mm2\n\t"
247
0
      /*#0 Add residue low.*/
248
0
      "paddsw (%[residue]), %%mm3\n\t"
249
0
      /*#1 Expand high source.*/
250
0
      "punpckhbw %%mm0,%%mm2\n\t"
251
0
      /*#0 Pack final row pixels.*/
252
0
      "packuswb %%mm4,%%mm3\n\t"
253
0
      /*#1 Expand low  source.*/
254
0
      "punpcklbw %%mm0,%%mm7\n\t"
255
0
      /*#1 Add residue low.*/
256
0
      "paddsw 16(%[residue]),%%mm7\n\t"
257
0
      /*#1 Add residue high.*/
258
0
      "paddsw 24(%[residue]),%%mm2\n\t"
259
0
      /*Advance residue.*/
260
0
      "lea 32(%[residue]),%[residue]\n\t"
261
0
      /*#1 Pack final row pixels.*/
262
0
      "packuswb %%mm2,%%mm7\n\t"
263
0
      /*Advance src.*/
264
0
      "lea (%[src],%[ystride],2),%[src]\n\t"
265
0
      /*#0 Write row.*/
266
0
      "movq %%mm3,(%[dst])\n\t"
267
0
      /*#1 Write row.*/
268
0
      "movq %%mm7,(%[dst],%[ystride])\n\t"
269
0
      /*Advance dst.*/
270
0
      "lea (%[dst],%[ystride],2),%[dst]\n\t"
271
0
      :[residue]"+r"(_residue),[dst]"+r"(_dst),[src]"+r"(_src)
272
0
      :[ystride]"r"((ptrdiff_t)_ystride)
273
0
      :"memory"
274
0
    );
275
0
  }
276
0
}
277
278
void oc_frag_recon_inter2_mmx(unsigned char *_dst,const unsigned char *_src1,
279
0
 const unsigned char *_src2,int _ystride,const ogg_int16_t *_residue){
280
0
  int i;
281
0
  /*Zero mm7.*/
282
0
  __asm__ __volatile__("pxor %%mm7,%%mm7\n\t"::);
283
0
  for(i=4;i-->0;){
284
0
    __asm__ __volatile__(
285
0
      /*#0 Load src1.*/
286
0
      "movq (%[src1]),%%mm0\n\t"
287
0
      /*#0 Load src2.*/
288
0
      "movq (%[src2]),%%mm2\n\t"
289
0
      /*#0 Copy src1.*/
290
0
      "movq %%mm0,%%mm1\n\t"
291
0
      /*#0 Copy src2.*/
292
0
      "movq %%mm2,%%mm3\n\t"
293
0
      /*#1 Load src1.*/
294
0
      "movq (%[src1],%[ystride]),%%mm4\n\t"
295
0
      /*#0 Unpack lower src1.*/
296
0
      "punpcklbw %%mm7,%%mm0\n\t"
297
0
      /*#1 Load src2.*/
298
0
      "movq (%[src2],%[ystride]),%%mm5\n\t"
299
0
      /*#0 Unpack higher src1.*/
300
0
      "punpckhbw %%mm7,%%mm1\n\t"
301
0
      /*#0 Unpack lower src2.*/
302
0
      "punpcklbw %%mm7,%%mm2\n\t"
303
0
      /*#0 Unpack higher src2.*/
304
0
      "punpckhbw %%mm7,%%mm3\n\t"
305
0
      /*Advance src1 ptr.*/
306
0
      "lea (%[src1],%[ystride],2),%[src1]\n\t"
307
0
      /*Advance src2 ptr.*/
308
0
      "lea (%[src2],%[ystride],2),%[src2]\n\t"
309
0
      /*#0 Lower src1+src2.*/
310
0
      "paddsw %%mm2,%%mm0\n\t"
311
0
      /*#0 Higher src1+src2.*/
312
0
      "paddsw %%mm3,%%mm1\n\t"
313
0
      /*#1 Copy src1.*/
314
0
      "movq %%mm4,%%mm2\n\t"
315
0
      /*#0 Build lo average.*/
316
0
      "psraw $1,%%mm0\n\t"
317
0
      /*#1 Copy src2.*/
318
0
      "movq %%mm5,%%mm3\n\t"
319
0
      /*#1 Unpack lower src1.*/
320
0
      "punpcklbw %%mm7,%%mm4\n\t"
321
0
      /*#0 Build hi average.*/
322
0
      "psraw $1,%%mm1\n\t"
323
0
      /*#1 Unpack higher src1.*/
324
0
      "punpckhbw %%mm7,%%mm2\n\t"
325
0
      /*#0 low+=residue.*/
326
0
      "paddsw (%[residue]),%%mm0\n\t"
327
0
      /*#1 Unpack lower src2.*/
328
0
      "punpcklbw %%mm7,%%mm5\n\t"
329
0
      /*#0 high+=residue.*/
330
0
      "paddsw 8(%[residue]),%%mm1\n\t"
331
0
      /*#1 Unpack higher src2.*/
332
0
      "punpckhbw %%mm7,%%mm3\n\t"
333
0
      /*#1 Lower src1+src2.*/
334
0
      "paddsw %%mm4,%%mm5\n\t"
335
0
      /*#0 Pack and saturate.*/
336
0
      "packuswb %%mm1,%%mm0\n\t"
337
0
      /*#1 Higher src1+src2.*/
338
0
      "paddsw %%mm2,%%mm3\n\t"
339
0
      /*#0 Write row.*/
340
0
      "movq %%mm0,(%[dst])\n\t"
341
0
      /*#1 Build lo average.*/
342
0
      "psraw $1,%%mm5\n\t"
343
0
      /*#1 Build hi average.*/
344
0
      "psraw $1,%%mm3\n\t"
345
0
      /*#1 low+=residue.*/
346
0
      "paddsw 16(%[residue]),%%mm5\n\t"
347
0
      /*#1 high+=residue.*/
348
0
      "paddsw 24(%[residue]),%%mm3\n\t"
349
0
      /*#1 Pack and saturate.*/
350
0
      "packuswb  %%mm3,%%mm5\n\t"
351
0
      /*#1 Write row ptr.*/
352
0
      "movq %%mm5,(%[dst],%[ystride])\n\t"
353
0
      /*Advance residue ptr.*/
354
0
      "add $32,%[residue]\n\t"
355
0
      /*Advance dest ptr.*/
356
0
      "lea (%[dst],%[ystride],2),%[dst]\n\t"
357
0
     :[dst]"+r"(_dst),[residue]"+r"(_residue),
358
0
      [src1]"+%r"(_src1),[src2]"+r"(_src2)
359
0
     :[ystride]"r"((ptrdiff_t)_ystride)
360
0
     :"memory"
361
0
    );
362
0
  }
363
0
}
364
365
0
void oc_restore_fpu_mmx(void){
366
0
  __asm__ __volatile__("emms\n\t");
367
0
}
368
#endif