Damjan Marion | c576622 | 2018-04-16 00:18:34 +0200 | [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 | #ifndef included_vector_avx512_h |
| 17 | #define included_vector_avx512_h |
| 18 | |
| 19 | #include <vppinfra/clib.h> |
| 20 | #include <x86intrin.h> |
| 21 | |
Damjan Marion | a52e166 | 2018-05-19 00:04:23 +0200 | [diff] [blame] | 22 | /* *INDENT-OFF* */ |
Damjan Marion | c576622 | 2018-04-16 00:18:34 +0200 | [diff] [blame] | 23 | #define foreach_avx512_vec512i \ |
| 24 | _(i,8,64,epi8) _(i,16,32,epi16) _(i,32,16,epi32) _(i,64,8,epi64) |
| 25 | #define foreach_avx512_vec512u \ |
| 26 | _(u,8,64,epi8) _(u,16,32,epi16) _(u,32,16,epi32) _(u,64,8,epi64) |
| 27 | #define foreach_avx512_vec512f \ |
| 28 | _(f,32,8,ps) _(f,64,4,pd) |
| 29 | |
Damjan Marion | a52e166 | 2018-05-19 00:04:23 +0200 | [diff] [blame] | 30 | /* splat, load_unaligned, store_unaligned, is_all_zero, is_equal, |
| 31 | is_all_equal */ |
Damjan Marion | c576622 | 2018-04-16 00:18:34 +0200 | [diff] [blame] | 32 | #define _(t, s, c, i) \ |
| 33 | static_always_inline t##s##x##c \ |
| 34 | t##s##x##c##_splat (t##s x) \ |
| 35 | { return (t##s##x##c) _mm512_set1_##i (x); } \ |
| 36 | \ |
| 37 | static_always_inline t##s##x##c \ |
| 38 | t##s##x##c##_load_unaligned (void *p) \ |
| 39 | { return (t##s##x##c) _mm512_loadu_si512 (p); } \ |
| 40 | \ |
| 41 | static_always_inline void \ |
| 42 | t##s##x##c##_store_unaligned (t##s##x##c v, void *p) \ |
| 43 | { _mm512_storeu_si512 ((__m512i *) p, (__m512i) v); } \ |
| 44 | \ |
Damjan Marion | a52e166 | 2018-05-19 00:04:23 +0200 | [diff] [blame] | 45 | static_always_inline int \ |
| 46 | t##s##x##c##_is_all_zero (t##s##x##c v) \ |
| 47 | { return (_mm512_test_epi64_mask ((__m512i) v, (__m512i) v) == 0); } \ |
| 48 | \ |
| 49 | static_always_inline int \ |
| 50 | t##s##x##c##_is_equal (t##s##x##c a, t##s##x##c b) \ |
Damjan Marion | 1486477 | 2018-05-22 14:07:47 +0200 | [diff] [blame] | 51 | { return t##s##x##c##_is_all_zero (a ^ b); } \ |
Damjan Marion | a52e166 | 2018-05-19 00:04:23 +0200 | [diff] [blame] | 52 | \ |
| 53 | static_always_inline int \ |
| 54 | t##s##x##c##_is_all_equal (t##s##x##c v, t##s x) \ |
| 55 | { return t##s##x##c##_is_equal (v, t##s##x##c##_splat (x)); } \ |
Damjan Marion | c576622 | 2018-04-16 00:18:34 +0200 | [diff] [blame] | 56 | |
| 57 | foreach_avx512_vec512i foreach_avx512_vec512u |
| 58 | #undef _ |
Damjan Marion | 8c3f8a2 | 2018-05-17 21:12:13 +0200 | [diff] [blame] | 59 | /* *INDENT-ON* */ |
| 60 | |
| 61 | static_always_inline u32 |
| 62 | u16x32_msb_mask (u16x32 v) |
| 63 | { |
| 64 | return (u32) _mm512_movepi16_mask ((__m512i) v); |
| 65 | } |
| 66 | |
| 67 | #endif /* included_vector_avx512_h */ |
Damjan Marion | c576622 | 2018-04-16 00:18:34 +0200 | [diff] [blame] | 68 | /* |
| 69 | * fd.io coding-style-patch-verification: ON |
| 70 | * |
| 71 | * Local Variables: |
| 72 | * eval: (c-set-style "gnu") |
| 73 | * End: |
| 74 | */ |