MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / flip

Function flip

dnn/src/fallback/flip/opr_impl.cpp:15–43  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

13
14template <typename T, size_t ch>
15void flip(
16 const T* __restrict src, T* __restrict dst, const size_t rows,
17 const size_t cols, const size_t src_step, const size_t dst_step, bool vertical,
18 bool horizontal) {
19 for (size_t sr = 0; sr < rows; ++sr) {
20 const T* sptr = src + sr * src_step;
21 size_t dr = (vertical ? rows - sr - 1 : sr);
22 T* dptr = dst + dr * dst_step;
23 if (!horizontal) {
24 memcpy(dptr, sptr, sizeof(T) * cols * ch);
25 } else {
26 size_t sc = 0;
27 size_t dc = cols * ch;
28 for (; sc + 8 * ch <= cols * ch; sc += 8 * ch, dc -= 8 * ch) {
29 rep(c, ch) dptr[dc - 1 * ch + c] = sptr[sc + 0 * ch + c];
30 rep(c, ch) dptr[dc - 2 * ch + c] = sptr[sc + 1 * ch + c];
31 rep(c, ch) dptr[dc - 3 * ch + c] = sptr[sc + 2 * ch + c];
32 rep(c, ch) dptr[dc - 4 * ch + c] = sptr[sc + 3 * ch + c];
33 rep(c, ch) dptr[dc - 5 * ch + c] = sptr[sc + 4 * ch + c];
34 rep(c, ch) dptr[dc - 6 * ch + c] = sptr[sc + 5 * ch + c];
35 rep(c, ch) dptr[dc - 7 * ch + c] = sptr[sc + 6 * ch + c];
36 rep(c, ch) dptr[dc - 8 * ch + c] = sptr[sc + 7 * ch + c];
37 }
38 for (; sc < cols * ch; sc += ch, dc -= ch) {
39 rep(c, ch) dptr[dc - ch + c] = sptr[sc + c];
40 }
41 }
42 }
43}
44
45} // namespace flip_internal
46

Callers 3

forwardMethod · 0.90
forwardMethod · 0.90
forwardMethod · 0.90

Calls 1

repFunction · 0.50

Tested by

no test coverage detected