Initial commit of vpp code.
[vpp.git] / vppinfra / vppinfra / vector_iwmmxt.h
1 /*
2  * Copyright (c) 2015 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 /*
16   Copyright (c) 2008 Eliot Dresselhaus
17
18   Permission is hereby granted, free of charge, to any person obtaining
19   a copy of this software and associated documentation files (the
20   "Software"), to deal in the Software without restriction, including
21   without limitation the rights to use, copy, modify, merge, publish,
22   distribute, sublicense, and/or sell copies of the Software, and to
23   permit persons to whom the Software is furnished to do so, subject to
24   the following conditions:
25
26   The above copyright notice and this permission notice shall be
27   included in all copies or substantial portions of the Software.
28
29   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
30   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
31   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
32   NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
33   LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
34   OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
35   WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
36 */
37
38 #ifndef included_vector_iwmmxt_h
39 #define included_vector_iwmmxt_h
40
41 #include <vppinfra/error.h>             /* for ASSERT */
42
43 /* 64 bit interleaves. */
44 always_inline u8x8 u8x8_interleave_hi (u8x8 a, u8x8 b)
45 { return __builtin_arm_wunpckihb (a, b); }
46
47 always_inline u8x8 u8x8_interleave_lo (u8x8 a, u8x8 b)
48 { return __builtin_arm_wunpckilb (a, b); }
49
50 always_inline u16x4 u16x4_interleave_hi (u16x4 a, u16x4 b)
51 { return __builtin_arm_wunpckihh (a, b); }
52
53 always_inline u16x4 u16x4_interleave_lo (u16x4 a, u16x4 b)
54 { return __builtin_arm_wunpckilh (a, b); }
55
56 always_inline u32x2 u32x2_interleave_hi (u32x2 a, u32x2 b)
57 { return __builtin_arm_wunpckihw (a, b); }
58
59 always_inline u32x2 u32x2_interleave_lo (u32x2 a, u32x2 b)
60 { return __builtin_arm_wunpckilw (a, b); }
61
62 always_inline u32x2 u32x2_splat (u32 a)
63 {
64   u32x2 x = {a};
65   x = u32x2_interleave_lo (x, x);
66   return x;
67  }
68
69 always_inline u16x4 u16x4_splat (u16 a)
70 {
71   u32 t = (u32) a | ((u32) a << 16);
72   return u32x2_splat (t);
73 }
74
75 always_inline u8x8 u8x8_splat (u8 a)
76 {
77   u32 t = (u32) a | ((u32) a << 8);
78   t |= t << 16;
79   return u32x2_splat (t);
80 }
81
82 #define i32x2_splat u32x2_splat
83 #define i16x4_splat u16x4_splat
84 #define i8x8_splat u8x8_splat
85
86 /* 64 bit shifts. */
87
88 /* As of July 2008 the __builtin_arm shifts cause gcc-4.3.1 to crash
89    so we use asm versions. */
90 #define _(t,u,lr,f)                             \
91   always_inline t                               \
92   t##_##lr (t x, int i)                         \
93   {                                             \
94     i16x4 y;                                    \
95     asm (#f " %[y], %[x], %[shift]"             \
96          : [y] "=y" (y)                         \
97          : [x] "y" (x), [shift] "i" (i * u));   \
98     return y;                                   \
99   }
100
101 _ (u16x4, 1, shift_left, wsllhi)
102 _ (u32x2, 1, shift_left, wsllwi)
103 _ (u16x4, 1, shift_right, wsrlhi)
104 _ (u32x2, 1, shift_right, wsrlwi)
105 _ (i16x4, 1, shift_left, wsllhi)
106 _ (i32x2, 1, shift_left, wsllwi)
107 _ (i16x4, 1, shift_right, wsrahi)
108 _ (i32x2, 1, shift_right, wsrawi)
109
110 /* Word shifts. */
111 _ (u8x8, 8, word_shift_left, wslldi)
112 _ (u16x4, 16, word_shift_left, wslldi)
113 _ (u32x2, 32, word_shift_left, wslldi)
114 _ (u8x8, 8, word_shift_right, wsrldi)
115 _ (u16x4, 16, word_shift_right, wsrldi)
116 _ (u32x2, 32, word_shift_right, wsrldi)
117 _ (i8x8, 8, word_shift_left, wslldi)
118 _ (i16x4, 16, word_shift_left, wslldi)
119 _ (i32x2, 32, word_shift_left, wslldi)
120 _ (i8x8, 8, word_shift_right, wsrldi)
121 _ (i16x4, 16, word_shift_right, wsrldi)
122 _ (i32x2, 32, word_shift_right, wsrldi)
123
124 #undef _
125
126
127 #endif /* included_vector_iwmmxt_h */