1 /*
2  *  Copyright (c) 2017 The WebM project authors. All Rights Reserved.
3  *
4  *  Use of this source code is governed by a BSD-style license
5  *  that can be found in the LICENSE file in the root of the source
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10 
11 #ifndef VPX_VPX_DSP_PPC_TRANSPOSE_VSX_H_
12 #define VPX_VPX_DSP_PPC_TRANSPOSE_VSX_H_
13 
14 #include "./vpx_config.h"
15 #include "vpx_dsp/ppc/types_vsx.h"
16 
vpx_transpose_s16_8x8(int16x8_t v[8])17 static INLINE void vpx_transpose_s16_8x8(int16x8_t v[8]) {
18   // d = vec_mergeh(a,b):
19   // The even elements of the result are obtained left-to-right,
20   // from the high elements of a.
21   // The odd elements of the result are obtained left-to-right,
22   // from the high elements of b.
23   //
24   // d = vec_mergel(a,b):
25   // The even elements of the result are obtained left-to-right,
26   // from the low elements of a.
27   // The odd elements of the result are obtained left-to-right,
28   // from the low elements of b.
29 
30   // Example, starting with:
31   // v[0]: 00 01 02 03 04 05 06 07
32   // v[1]: 10 11 12 13 14 15 16 17
33   // v[2]: 20 21 22 23 24 25 26 27
34   // v[3]: 30 31 32 33 34 35 36 37
35   // v[4]: 40 41 42 43 44 45 46 47
36   // v[5]: 50 51 52 53 54 55 56 57
37   // v[6]: 60 61 62 63 64 65 66 67
38   // v[7]: 70 71 72 73 74 75 76 77
39 
40   int16x8_t b0, b1, b2, b3, b4, b5, b6, b7;
41   int16x8_t c0, c1, c2, c3, c4, c5, c6, c7;
42 
43   b0 = vec_mergeh(v[0], v[4]);
44   b1 = vec_mergel(v[0], v[4]);
45   b2 = vec_mergeh(v[1], v[5]);
46   b3 = vec_mergel(v[1], v[5]);
47   b4 = vec_mergeh(v[2], v[6]);
48   b5 = vec_mergel(v[2], v[6]);
49   b6 = vec_mergeh(v[3], v[7]);
50   b7 = vec_mergel(v[3], v[7]);
51 
52   // After first merge operation
53   // b0: 00 40 01 41 02 42 03 43
54   // b1: 04 44 05 45 06 46 07 47
55   // b2: 10 50 11 51 12 52 13 53
56   // b3: 14 54 15 55 16 56 17 57
57   // b4: 20 60 21 61 22 62 23 63
58   // b5: 24 64 25 65 26 66 27 67
59   // b6: 30 70 31 71 32 62 33 73
60   // b7: 34 74 35 75 36 76 37 77
61 
62   c0 = vec_mergeh(b0, b4);
63   c1 = vec_mergel(b0, b4);
64   c2 = vec_mergeh(b1, b5);
65   c3 = vec_mergel(b1, b5);
66   c4 = vec_mergeh(b2, b6);
67   c5 = vec_mergel(b2, b6);
68   c6 = vec_mergeh(b3, b7);
69   c7 = vec_mergel(b3, b7);
70 
71   // After second merge operation
72   // c0: 00 20 40 60 01 21 41 61
73   // c1: 02 22 42 62 03 23 43 63
74   // c2: 04 24 44 64 05 25 45 65
75   // c3: 06 26 46 66 07 27 47 67
76   // c4: 10 30 50 70 11 31 51 71
77   // c5: 12 32 52 72 13 33 53 73
78   // c6: 14 34 54 74 15 35 55 75
79   // c7: 16 36 56 76 17 37 57 77
80 
81   v[0] = vec_mergeh(c0, c4);
82   v[1] = vec_mergel(c0, c4);
83   v[2] = vec_mergeh(c1, c5);
84   v[3] = vec_mergel(c1, c5);
85   v[4] = vec_mergeh(c2, c6);
86   v[5] = vec_mergel(c2, c6);
87   v[6] = vec_mergeh(c3, c7);
88   v[7] = vec_mergel(c3, c7);
89 
90   // After last merge operation
91   // v[0]: 00 10 20 30 40 50 60 70
92   // v[1]: 01 11 21 31 41 51 61 71
93   // v[2]: 02 12 22 32 42 52 62 72
94   // v[3]: 03 13 23 33 43 53 63 73
95   // v[4]: 04 14 24 34 44 54 64 74
96   // v[5]: 05 15 25 35 45 55 65 75
97   // v[6]: 06 16 26 36 46 56 66 76
98   // v[7]: 07 17 27 37 47 57 67 77
99 }
100 
transpose_8x8(const int16x8_t * a,int16x8_t * b)101 static INLINE void transpose_8x8(const int16x8_t *a, int16x8_t *b) {
102   // Stage 1
103   const int16x8_t s1_0 = vec_mergeh(a[0], a[4]);
104   const int16x8_t s1_1 = vec_mergel(a[0], a[4]);
105   const int16x8_t s1_2 = vec_mergeh(a[1], a[5]);
106   const int16x8_t s1_3 = vec_mergel(a[1], a[5]);
107   const int16x8_t s1_4 = vec_mergeh(a[2], a[6]);
108   const int16x8_t s1_5 = vec_mergel(a[2], a[6]);
109   const int16x8_t s1_6 = vec_mergeh(a[3], a[7]);
110   const int16x8_t s1_7 = vec_mergel(a[3], a[7]);
111 
112   // Stage 2
113   const int16x8_t s2_0 = vec_mergeh(s1_0, s1_4);
114   const int16x8_t s2_1 = vec_mergel(s1_0, s1_4);
115   const int16x8_t s2_2 = vec_mergeh(s1_1, s1_5);
116   const int16x8_t s2_3 = vec_mergel(s1_1, s1_5);
117   const int16x8_t s2_4 = vec_mergeh(s1_2, s1_6);
118   const int16x8_t s2_5 = vec_mergel(s1_2, s1_6);
119   const int16x8_t s2_6 = vec_mergeh(s1_3, s1_7);
120   const int16x8_t s2_7 = vec_mergel(s1_3, s1_7);
121 
122   // Stage 2
123   b[0] = vec_mergeh(s2_0, s2_4);
124   b[1] = vec_mergel(s2_0, s2_4);
125   b[2] = vec_mergeh(s2_1, s2_5);
126   b[3] = vec_mergel(s2_1, s2_5);
127   b[4] = vec_mergeh(s2_2, s2_6);
128   b[5] = vec_mergel(s2_2, s2_6);
129   b[6] = vec_mergeh(s2_3, s2_7);
130   b[7] = vec_mergel(s2_3, s2_7);
131 }
132 
133 #endif  // VPX_VPX_DSP_PPC_TRANSPOSE_VSX_H_
134