blob: 8e662045655d1a12e7ee131898b6ef1c72fde8ae [file] [log] [blame]
Ed Warnickecb9cada2015-12-08 15:45:58 -07001/*
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
Dave Barachc3799992016-08-15 11:12:27 -040041#include <vppinfra/error.h> /* for ASSERT */
Ed Warnickecb9cada2015-12-08 15:45:58 -070042
43/* 64 bit interleaves. */
Dave Barachc3799992016-08-15 11:12:27 -040044always_inline u8x8
45u8x8_interleave_hi (u8x8 a, u8x8 b)
Ed Warnickecb9cada2015-12-08 15:45:58 -070046{
Dave Barachc3799992016-08-15 11:12:27 -040047 return __builtin_arm_wunpckihb (a, b);
48}
49
50always_inline u8x8
51u8x8_interleave_lo (u8x8 a, u8x8 b)
52{
53 return __builtin_arm_wunpckilb (a, b);
54}
55
56always_inline u16x4
57u16x4_interleave_hi (u16x4 a, u16x4 b)
58{
59 return __builtin_arm_wunpckihh (a, b);
60}
61
62always_inline u16x4
63u16x4_interleave_lo (u16x4 a, u16x4 b)
64{
65 return __builtin_arm_wunpckilh (a, b);
66}
67
68always_inline u32x2
69u32x2_interleave_hi (u32x2 a, u32x2 b)
70{
71 return __builtin_arm_wunpckihw (a, b);
72}
73
74always_inline u32x2
75u32x2_interleave_lo (u32x2 a, u32x2 b)
76{
77 return __builtin_arm_wunpckilw (a, b);
78}
79
80always_inline u32x2
81u32x2_splat (u32 a)
82{
83 u32x2 x = { a };
Ed Warnickecb9cada2015-12-08 15:45:58 -070084 x = u32x2_interleave_lo (x, x);
85 return x;
Dave Barachc3799992016-08-15 11:12:27 -040086}
Ed Warnickecb9cada2015-12-08 15:45:58 -070087
Dave Barachc3799992016-08-15 11:12:27 -040088always_inline u16x4
89u16x4_splat (u16 a)
Ed Warnickecb9cada2015-12-08 15:45:58 -070090{
91 u32 t = (u32) a | ((u32) a << 16);
92 return u32x2_splat (t);
93}
94
Dave Barachc3799992016-08-15 11:12:27 -040095always_inline u8x8
96u8x8_splat (u8 a)
Ed Warnickecb9cada2015-12-08 15:45:58 -070097{
98 u32 t = (u32) a | ((u32) a << 8);
99 t |= t << 16;
100 return u32x2_splat (t);
101}
102
103#define i32x2_splat u32x2_splat
104#define i16x4_splat u16x4_splat
105#define i8x8_splat u8x8_splat
106
107/* 64 bit shifts. */
108
109/* As of July 2008 the __builtin_arm shifts cause gcc-4.3.1 to crash
110 so we use asm versions. */
111#define _(t,u,lr,f) \
112 always_inline t \
113 t##_##lr (t x, int i) \
114 { \
115 i16x4 y; \
116 asm (#f " %[y], %[x], %[shift]" \
117 : [y] "=y" (y) \
118 : [x] "y" (x), [shift] "i" (i * u)); \
119 return y; \
120 }
121
Dave Barachc3799992016-08-15 11:12:27 -0400122_(u16x4, 1, shift_left, wsllhi)
123_(u32x2, 1, shift_left, wsllwi)
124_(u16x4, 1, shift_right, wsrlhi)
125_(u32x2, 1, shift_right, wsrlwi)
126_(i16x4, 1, shift_left, wsllhi)
127_(i32x2, 1, shift_left, wsllwi)
128_(i16x4, 1, shift_right, wsrahi) _(i32x2, 1, shift_right, wsrawi)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700129/* Word shifts. */
Dave Barachc3799992016-08-15 11:12:27 -0400130 _(u8x8, 8, word_shift_left, wslldi)
131_(u16x4, 16, word_shift_left, wslldi)
132_(u32x2, 32, word_shift_left, wslldi)
133_(u8x8, 8, word_shift_right, wsrldi)
134_(u16x4, 16, word_shift_right, wsrldi)
135_(u32x2, 32, word_shift_right, wsrldi)
136_(i8x8, 8, word_shift_left, wslldi)
137_(i16x4, 16, word_shift_left, wslldi)
138_(i32x2, 32, word_shift_left, wslldi)
139_(i8x8, 8, word_shift_right, wsrldi)
140_(i16x4, 16, word_shift_right, wsrldi) _(i32x2, 32, word_shift_right, wsrldi)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700141#undef _
Ed Warnickecb9cada2015-12-08 15:45:58 -0700142#endif /* included_vector_iwmmxt_h */
Dave Barachc3799992016-08-15 11:12:27 -0400143/*
144 * fd.io coding-style-patch-verification: ON
145 *
146 * Local Variables:
147 * eval: (c-set-style "gnu")
148 * End:
149 */