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_TYPES_VSX_H_
12 #define VPX_VPX_DSP_PPC_TYPES_VSX_H_
13
14 #include <altivec.h>
15
16 typedef vector signed char int8x16_t;
17 typedef vector unsigned char uint8x16_t;
18 typedef vector signed short int16x8_t;
19 typedef vector unsigned short uint16x8_t;
20 typedef vector signed int int32x4_t;
21 typedef vector unsigned int uint32x4_t;
22 typedef vector bool char bool8x16_t;
23 typedef vector bool short bool16x8_t;
24 typedef vector bool int bool32x4_t;
25
26 #if defined(__clang__) && __clang_major__ < 6
27 static const uint8x16_t xxpermdi0_perm = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05,
28 0x06, 0x07, 0x10, 0x11, 0x12, 0x13,
29 0x14, 0x15, 0x16, 0x17 };
30 static const uint8x16_t xxpermdi1_perm = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05,
31 0x06, 0x07, 0x18, 0x19, 0x1A, 0x1B,
32 0x1C, 0x1D, 0x1E, 0x1F };
33 static const uint8x16_t xxpermdi2_perm = { 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D,
34 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13,
35 0x14, 0x15, 0x16, 0x17 };
36 static const uint8x16_t xxpermdi3_perm = { 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D,
37 0x0E, 0x0F, 0x18, 0x19, 0x1A, 0x1B,
38 0x1C, 0x1D, 0x1E, 0x1F };
39 #define xxpermdi(a, b, c) vec_perm(a, b, xxpermdi##c##_perm)
40 #elif defined(__GNUC__) && \
41 (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 3))
42 #define xxpermdi(a, b, c) vec_xxpermdi(a, b, c)
43 #endif
44
45 #ifdef WORDS_BIGENDIAN
46 #define unpack_to_u16_h(v) \
47 (uint16x8_t) vec_mergeh(vec_splat_u8(0), (uint8x16_t)v)
48 #define unpack_to_u16_l(v) \
49 (uint16x8_t) vec_mergel(vec_splat_u8(0), (uint8x16_t)v)
50 #define unpack_to_s16_h(v) \
51 (int16x8_t) vec_mergeh(vec_splat_u8(0), (uint8x16_t)v)
52 #define unpack_to_s16_l(v) \
53 (int16x8_t) vec_mergel(vec_splat_u8(0), (uint8x16_t)v)
54 #ifndef xxpermdi
55 #define xxpermdi(a, b, c) vec_xxpermdi(a, b, c)
56 #endif
57 #else
58 #define unpack_to_u16_h(v) \
59 (uint16x8_t) vec_mergeh((uint8x16_t)v, vec_splat_u8(0))
60 #define unpack_to_u16_l(v) \
61 (uint16x8_t) vec_mergel((uint8x16_t)v, vec_splat_u8(0))
62 #define unpack_to_s16_h(v) \
63 (int16x8_t) vec_mergeh((uint8x16_t)v, vec_splat_u8(0))
64 #define unpack_to_s16_l(v) \
65 (int16x8_t) vec_mergel((uint8x16_t)v, vec_splat_u8(0))
66 #ifndef xxpermdi
67 #define xxpermdi(a, b, c) vec_xxpermdi(b, a, (((c) >> 1) | ((c)&1) << 1) ^ 3)
68 #endif
69 #endif
70
read4x2(const uint8_t * a,int stride)71 static INLINE uint8x16_t read4x2(const uint8_t *a, int stride) {
72 const uint32x4_t a0 = (uint32x4_t)vec_vsx_ld(0, a);
73 const uint32x4_t a1 = (uint32x4_t)vec_vsx_ld(0, a + stride);
74
75 return (uint8x16_t)vec_mergeh(a0, a1);
76 }
77
78 #ifndef __POWER9_VECTOR__
79 #define vec_absd(a, b) vec_sub(vec_max(a, b), vec_min(a, b))
80 #endif
81
82 static const uint8x16_t vec_zeros_u8 = { 0, 0, 0, 0, 0, 0, 0, 0,
83 0, 0, 0, 0, 0, 0, 0, 0 };
84 static const int16x8_t vec_zeros_s16 = { 0, 0, 0, 0, 0, 0, 0, 0 };
85 static const int16x8_t vec_ones_s16 = { 1, 1, 1, 1, 1, 1, 1, 1 };
86 static const int16x8_t vec_twos_s16 = { 2, 2, 2, 2, 2, 2, 2, 2 };
87 static const uint16x8_t vec_ones_u16 = { 1, 1, 1, 1, 1, 1, 1, 1 };
88 static const uint32x4_t vec_ones_u32 = { 1, 1, 1, 1 };
89 static const int32x4_t vec_zeros_s32 = { 0, 0, 0, 0 };
90 static const uint32x4_t vec_zeros_u32 = { 0, 0, 0, 0 };
91 static const uint16x8_t vec_shift_sign_s16 = { 15, 15, 15, 15, 15, 15, 15, 15 };
92 static const uint32x4_t vec_shift_sign_s32 = { 31, 31, 31, 31 };
93 static const uint8x16_t vec_perm64 = { 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D,
94 0x0E, 0x0F, 0x00, 0x01, 0x02, 0x03,
95 0x04, 0x05, 0x06, 0x07 };
96 static const uint8x16_t vec_perm32 = { 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,
97 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
98 0x00, 0x01, 0x02, 0x03 };
99 static const uint8x16_t vec_perm16 = { 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
100 0x08, 0x09, 0x0A, 0x0B, 0x0E, 0x0D,
101 0x0E, 0x0F, 0x00, 0x01 };
102
103 static const uint8x16_t vec_perm_odd_even_pack = { 0x00, 0x01, 0x10, 0x11,
104 0x04, 0x05, 0x14, 0x15,
105 0x08, 0x09, 0x18, 0x19,
106 0x0C, 0x0D, 0x1C, 0x1D };
107
108 #endif // VPX_VPX_DSP_PPC_TYPES_VSX_H_
109