Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 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) 2009 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_altivec_h |
| 39 | #define included_vector_altivec_h |
| 40 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 41 | /* 128 bit shifts. */ |
| 42 | #define _(t,ti,lr,f) \ |
| 43 | always_inline t t##_##lr (t x, t y) \ |
| 44 | { return (t) __builtin_altivec_##f ((ti) x, (ti) y); } \ |
| 45 | \ |
| 46 | always_inline t t##_i##lr (t x, int i) \ |
| 47 | { \ |
| 48 | t j = {i,i,i,i}; \ |
| 49 | return t##_##lr (x, j); \ |
| 50 | } |
| 51 | |
Dave Barach | c379999 | 2016-08-15 11:12:27 -0400 | [diff] [blame] | 52 | _(u16x8, i16x8, shift_left, vslh); |
| 53 | _(u32x4, i32x4, shift_left, vslw); |
| 54 | _(u16x8, i16x8, shift_right, vsrh); |
| 55 | _(u32x4, i32x4, shift_right, vsrw); |
| 56 | _(i16x8, i16x8, shift_right, vsrah); |
| 57 | _(i32x4, i32x4, shift_right, vsraw); |
| 58 | _(u16x8, i16x8, rotate_left, vrlh); |
| 59 | _(i16x8, i16x8, rotate_left, vrlh); |
| 60 | _(u32x4, i32x4, rotate_left, vrlw); |
| 61 | _(i32x4, i32x4, rotate_left, vrlw); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 62 | |
| 63 | #undef _ |
| 64 | |
| 65 | #define _(t,it,lr,f) \ |
| 66 | always_inline t t##_word_shift_##lr (t x, int n_words) \ |
| 67 | { \ |
| 68 | i32x4 n_bits = {0,0,0,n_words * BITS (it)}; \ |
| 69 | return (t) __builtin_altivec_##f ((i32x4) x, n_bits); \ |
| 70 | } |
| 71 | |
Dave Barach | c379999 | 2016-08-15 11:12:27 -0400 | [diff] [blame] | 72 | _(u32x4, u32, left, vslo) |
| 73 | _(i32x4, i32, left, vslo) |
| 74 | _(u32x4, u32, right, vsro) |
| 75 | _(i32x4, i32, right, vsro) |
| 76 | _(u16x8, u16, left, vslo) |
| 77 | _(i16x8, i16, left, vslo) |
| 78 | _(u16x8, u16, right, vsro) _(i16x8, i16, right, vsro) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 79 | #undef _ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 80 | |
| 81 | /* Interleave. */ |
| 82 | #define _(t,it,lh,f) \ |
| 83 | always_inline t t##_interleave_##lh (t x, t y) \ |
| 84 | { return (t) __builtin_altivec_##f ((it) x, (it) y); } |
| 85 | |
Dave Barach | c379999 | 2016-08-15 11:12:27 -0400 | [diff] [blame] | 86 | _(u32x4, i32x4, lo, vmrglw) |
| 87 | _(i32x4, i32x4, lo, vmrglw) |
| 88 | _(u16x8, i16x8, lo, vmrglh) |
| 89 | _(i16x8, i16x8, lo, vmrglh) |
| 90 | _(u32x4, i32x4, hi, vmrghw) |
| 91 | _(i32x4, i32x4, hi, vmrghw) |
| 92 | _(u16x8, i16x8, hi, vmrghh) _(i16x8, i16x8, hi, vmrghh) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 93 | #undef _ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 94 | /* Unaligned loads/stores. */ |
| 95 | #ifndef __cplusplus |
| 96 | #define _(t) \ |
| 97 | always_inline void t##_store_unaligned (t x, t * a) \ |
| 98 | { clib_mem_unaligned (a, t) = x; } \ |
| 99 | always_inline t t##_load_unaligned (t * a) \ |
| 100 | { return clib_mem_unaligned (a, t); } |
Dave Barach | c379999 | 2016-08-15 11:12:27 -0400 | [diff] [blame] | 101 | _(u8x16) _(u16x8) _(u32x4) _(u64x2) _(i8x16) _(i16x8) _(i32x4) _(i64x2) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 102 | #undef _ |
| 103 | #endif |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 104 | #define _signed_binop(n,m,f,g) \ |
| 105 | /* Unsigned */ \ |
| 106 | always_inline u##n##x##m \ |
| 107 | u##n##x##m##_##f (u##n##x##m x, u##n##x##m y) \ |
| 108 | { return (u##n##x##m) __builtin_altivec_##g ((i##n##x##m) x, (i##n##x##m) y); } \ |
| 109 | \ |
| 110 | /* Signed */ \ |
| 111 | always_inline i##n##x##m \ |
| 112 | i##n##x##m##_##f (i##n##x##m x, i##n##x##m y) \ |
| 113 | { return (i##n##x##m) __builtin_altivec_##g ((i##n##x##m) x, (i##n##x##m) y); } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 114 | /* Compare operations. */ |
Dave Barach | c379999 | 2016-08-15 11:12:27 -0400 | [diff] [blame] | 115 | _signed_binop (16, 8, is_equal, vcmpequh) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 116 | _signed_binop (32, 4, is_equal, vcmpequw) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 117 | #undef _signed_binop |
Dave Barach | c379999 | 2016-08-15 11:12:27 -0400 | [diff] [blame] | 118 | always_inline u16x8 u16x8_is_zero (u16x8 x) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 119 | { |
Dave Barach | c379999 | 2016-08-15 11:12:27 -0400 | [diff] [blame] | 120 | u16x8 zero = { 0 }; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 121 | return u16x8_is_equal (x, zero); |
| 122 | } |
| 123 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 124 | #endif /* included_vector_altivec_h */ |
Dave Barach | c379999 | 2016-08-15 11:12:27 -0400 | [diff] [blame] | 125 | |
| 126 | /* |
| 127 | * fd.io coding-style-patch-verification: ON |
| 128 | * |
| 129 | * Local Variables: |
| 130 | * eval: (c-set-style "gnu") |
| 131 | * End: |
| 132 | */ |