aboutsummaryrefslogtreecommitdiff
path: root/libvpx/vpx_dsp/x86/convolve.h
blob: e69d6c6176333791d926767aad0cc8a157881690 (plain)
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
/*
 *  Copyright (c) 2015 The WebM project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */
#ifndef VPX_DSP_X86_CONVOLVE_H_
#define VPX_DSP_X86_CONVOLVE_H_

#include <assert.h>

#include "./vpx_config.h"
#include "vpx/vpx_integer.h"
#include "vpx_ports/mem.h"

typedef void filter8_1dfunction(const uint8_t *src_ptr, ptrdiff_t src_pitch,
                                uint8_t *output_ptr, ptrdiff_t out_pitch,
                                uint32_t output_height, const int16_t *filter);

#define FUN_CONV_1D(name, step_q4, filter, dir, src_start, avg, opt)         \
  void vpx_convolve8_##name##_##opt(                                         \
      const uint8_t *src, ptrdiff_t src_stride, uint8_t *dst,                \
      ptrdiff_t dst_stride, const int16_t *filter_x, int x_step_q4,          \
      const int16_t *filter_y, int y_step_q4, int w, int h) {                \
    (void)filter_x;                                                          \
    (void)x_step_q4;                                                         \
    (void)filter_y;                                                          \
    (void)y_step_q4;                                                         \
    assert(filter[3] != 128);                                                \
    assert(step_q4 == 16);                                                   \
    if (filter[0] | filter[1] | filter[2]) {                                 \
      while (w >= 16) {                                                      \
        vpx_filter_block1d16_##dir##8_##avg##opt(src_start, src_stride, dst, \
                                                 dst_stride, h, filter);     \
        src += 16;                                                           \
        dst += 16;                                                           \
        w -= 16;                                                             \
      }                                                                      \
      if (w == 8) {                                                          \
        vpx_filter_block1d8_##dir##8_##avg##opt(src_start, src_stride, dst,  \
                                                dst_stride, h, filter);      \
      } else if (w == 4) {                                                   \
        vpx_filter_block1d4_##dir##8_##avg##opt(src_start, src_stride, dst,  \
                                                dst_stride, h, filter);      \
      }                                                                      \
    } else {                                                                 \
      while (w >= 16) {                                                      \
        vpx_filter_block1d16_##dir##2_##avg##opt(src, src_stride, dst,       \
                                                 dst_stride, h, filter);     \
        src += 16;                                                           \
        dst += 16;                                                           \
        w -= 16;                                                             \
      }                                                                      \
      if (w == 8) {                                                          \
        vpx_filter_block1d8_##dir##2_##avg##opt(src, src_stride, dst,        \
                                                dst_stride, h, filter);      \
      } else if (w == 4) {                                                   \
        vpx_filter_block1d4_##dir##2_##avg##opt(src, src_stride, dst,        \
                                                dst_stride, h, filter);      \
      }                                                                      \
    }                                                                        \
  }

#define FUN_CONV_2D(avg, opt)                                                 \
  void vpx_convolve8_##avg##opt(                                              \
      const uint8_t *src, ptrdiff_t src_stride, uint8_t *dst,                 \
      ptrdiff_t dst_stride, const int16_t *filter_x, int x_step_q4,           \
      const int16_t *filter_y, int y_step_q4, int w, int h) {                 \
    assert(filter_x[3] != 128);                                               \
    assert(filter_y[3] != 128);                                               \
    assert(w <= 64);                                                          \
    assert(h <= 64);                                                          \
    assert(x_step_q4 == 16);                                                  \
    assert(y_step_q4 == 16);                                                  \
    if (filter_x[0] | filter_x[1] | filter_x[2]) {                            \
      DECLARE_ALIGNED(16, uint8_t, fdata2[64 * 71]);                          \
      vpx_convolve8_horiz_##opt(src - 3 * src_stride, src_stride, fdata2, 64, \
                                filter_x, x_step_q4, filter_y, y_step_q4, w,  \
                                h + 7);                                       \
      vpx_convolve8_##avg##vert_##opt(fdata2 + 3 * 64, 64, dst, dst_stride,   \
                                      filter_x, x_step_q4, filter_y,          \
                                      y_step_q4, w, h);                       \
    } else {                                                                  \
      DECLARE_ALIGNED(16, uint8_t, fdata2[64 * 65]);                          \
      vpx_convolve8_horiz_##opt(src, src_stride, fdata2, 64, filter_x,        \
                                x_step_q4, filter_y, y_step_q4, w, h + 1);    \
      vpx_convolve8_##avg##vert_##opt(fdata2, 64, dst, dst_stride, filter_x,  \
                                      x_step_q4, filter_y, y_step_q4, w, h);  \
    }                                                                         \
  }

#if CONFIG_VP9_HIGHBITDEPTH

typedef void highbd_filter8_1dfunction(const uint16_t *src_ptr,
                                       const ptrdiff_t src_pitch,
                                       uint16_t *output_ptr,
                                       ptrdiff_t out_pitch,
                                       unsigned int output_height,
                                       const int16_t *filter, int bd);

#define HIGH_FUN_CONV_1D(name, step_q4, filter, dir, src_start, avg, opt) \
  void vpx_highbd_convolve8_##name##_##opt(                               \
      const uint16_t *src, ptrdiff_t src_stride, uint16_t *dst,           \
      ptrdiff_t dst_stride, const int16_t *filter_x, int x_step_q4,       \
      const int16_t *filter_y, int y_step_q4, int w, int h, int bd) {     \
    if (step_q4 == 16 && filter[3] != 128) {                              \
      if (filter[0] | filter[1] | filter[2]) {                            \
        while (w >= 16) {                                                 \
          vpx_highbd_filter_block1d16_##dir##8_##avg##opt(                \
              src_start, src_stride, dst, dst_stride, h, filter, bd);     \
          src += 16;                                                      \
          dst += 16;                                                      \
          w -= 16;                                                        \
        }                                                                 \
        while (w >= 8) {                                                  \
          vpx_highbd_filter_block1d8_##dir##8_##avg##opt(                 \
              src_start, src_stride, dst, dst_stride, h, filter, bd);     \
          src += 8;                                                       \
          dst += 8;                                                       \
          w -= 8;                                                         \
        }                                                                 \
        while (w >= 4) {                                                  \
          vpx_highbd_filter_block1d4_##dir##8_##avg##opt(                 \
              src_start, src_stride, dst, dst_stride, h, filter, bd);     \
          src += 4;                                                       \
          dst += 4;                                                       \
          w -= 4;                                                         \
        }                                                                 \
      } else {                                                            \
        while (w >= 16) {                                                 \
          vpx_highbd_filter_block1d16_##dir##2_##avg##opt(                \
              src, src_stride, dst, dst_stride, h, filter, bd);           \
          src += 16;                                                      \
          dst += 16;                                                      \
          w -= 16;                                                        \
        }                                                                 \
        while (w >= 8) {                                                  \
          vpx_highbd_filter_block1d8_##dir##2_##avg##opt(                 \
              src, src_stride, dst, dst_stride, h, filter, bd);           \
          src += 8;                                                       \
          dst += 8;                                                       \
          w -= 8;                                                         \
        }                                                                 \
        while (w >= 4) {                                                  \
          vpx_highbd_filter_block1d4_##dir##2_##avg##opt(                 \
              src, src_stride, dst, dst_stride, h, filter, bd);           \
          src += 4;                                                       \
          dst += 4;                                                       \
          w -= 4;                                                         \
        }                                                                 \
      }                                                                   \
    }                                                                     \
    if (w) {                                                              \
      vpx_highbd_convolve8_##name##_c(src, src_stride, dst, dst_stride,   \
                                      filter_x, x_step_q4, filter_y,      \
                                      y_step_q4, w, h, bd);               \
    }                                                                     \
  }

#define HIGH_FUN_CONV_2D(avg, opt)                                            \
  void vpx_highbd_convolve8_##avg##opt(                                       \
      const uint16_t *src, ptrdiff_t src_stride, uint16_t *dst,               \
      ptrdiff_t dst_stride, const int16_t *filter_x, int x_step_q4,           \
      const int16_t *filter_y, int y_step_q4, int w, int h, int bd) {         \
    assert(w <= 64);                                                          \
    assert(h <= 64);                                                          \
    if (x_step_q4 == 16 && y_step_q4 == 16) {                                 \
      if ((filter_x[0] | filter_x[1] | filter_x[2]) || filter_x[3] == 128) {  \
        DECLARE_ALIGNED(16, uint16_t, fdata2[64 * 71]);                       \
        vpx_highbd_convolve8_horiz_##opt(src - 3 * src_stride, src_stride,    \
                                         fdata2, 64, filter_x, x_step_q4,     \
                                         filter_y, y_step_q4, w, h + 7, bd);  \
        vpx_highbd_convolve8_##avg##vert_##opt(                               \
            fdata2 + 192, 64, dst, dst_stride, filter_x, x_step_q4, filter_y, \
            y_step_q4, w, h, bd);                                             \
      } else {                                                                \
        DECLARE_ALIGNED(16, uint16_t, fdata2[64 * 65]);                       \
        vpx_highbd_convolve8_horiz_##opt(src, src_stride, fdata2, 64,         \
                                         filter_x, x_step_q4, filter_y,       \
                                         y_step_q4, w, h + 1, bd);            \
        vpx_highbd_convolve8_##avg##vert_##opt(fdata2, 64, dst, dst_stride,   \
                                               filter_x, x_step_q4, filter_y, \
                                               y_step_q4, w, h, bd);          \
      }                                                                       \
    } else {                                                                  \
      vpx_highbd_convolve8_##avg##c(src, src_stride, dst, dst_stride,         \
                                    filter_x, x_step_q4, filter_y, y_step_q4, \
                                    w, h, bd);                                \
    }                                                                         \
  }
#endif  // CONFIG_VP9_HIGHBITDEPTH

#endif  // VPX_DSP_X86_CONVOLVE_H_