blob: ce999a5413052cd9043a1d269afb10b1481a2bf3 [file] [log] [blame]
Gian Marco58c57942017-11-28 09:10:03 +00001/*
2 * Copyright (c) 2017 ARM Limited.
3 *
4 * SPDX-License-Identifier: MIT
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24namespace arm_compute
25{
26inline int32x4_t rounding_divide_by_pow2(int32x4_t x, int exponent)
27{
28 const int32x4_t shift_vec = vdupq_n_s32(-exponent);
29 const int32x4_t fixup = vshrq_n_s32(vandq_s32(x, shift_vec), 31);
30 const int32x4_t fixed_up_x = vqaddq_s32(x, fixup);
31 return vrshlq_s32(fixed_up_x, shift_vec);
32}
Michel Iwaniec5dfeae62017-11-29 10:48:23 +000033
34inline qasymm8x16_t vmlaq_qasymm8(qasymm8x16_t vd, float32x4_t vs, float32x4_t vo)
35{
36 // Convert uint8 vectors to uint16 vectors
37 const uint8x8_t vd_low = vget_low_u8(vd);
38 const uint8x8_t vd_high = vget_high_u8(vd);
39 uint16x8_t vd_low_u16x8 = vmovl_u8(vd_low);
40 uint16x8_t vd_high_u16x8 = vmovl_u8(vd_high);
41 // Convert uint16 vectors to uint32 vectors
42 uint32x4_t A_u32x4 = vmovl_u16(vget_low_u16(vd_low_u16x8));
43 uint32x4_t B_u32x4 = vmovl_u16(vget_high_u16(vd_low_u16x8));
44 uint32x4_t C_u32x4 = vmovl_u16(vget_low_u16(vd_high_u16x8));
45 uint32x4_t D_u32x4 = vmovl_u16(vget_high_u16(vd_high_u16x8));
46 // Convert uint32 vectors to float32 vectors
47 float32x4_t A_f32x4 = vcvtq_f32_u32(A_u32x4);
48 float32x4_t B_f32x4 = vcvtq_f32_u32(B_u32x4);
49 float32x4_t C_f32x4 = vcvtq_f32_u32(C_u32x4);
50 float32x4_t D_f32x4 = vcvtq_f32_u32(D_u32x4);
51 // vd = vd*vs + vo
52 A_f32x4 = vmlaq_f32(vo, A_f32x4, vs);
53 B_f32x4 = vmlaq_f32(vo, B_f32x4, vs);
54 C_f32x4 = vmlaq_f32(vo, C_f32x4, vs);
55 D_f32x4 = vmlaq_f32(vo, D_f32x4, vs);
56 // Convert float32 vectors to uint32 vectors
57 A_u32x4 = vcvtq_u32_f32(A_f32x4);
58 B_u32x4 = vcvtq_u32_f32(B_f32x4);
59 C_u32x4 = vcvtq_u32_f32(C_f32x4);
60 D_u32x4 = vcvtq_u32_f32(D_f32x4);
61 // Convert uint32 vectors to uint16 vectors (with saturation)
62 vd_low_u16x8 = vcombine_u16(vqmovn_u32(A_u32x4), vqmovn_u32(B_u32x4));
63 vd_high_u16x8 = vcombine_u16(vqmovn_u32(C_u32x4), vqmovn_u32(D_u32x4));
64 // convert uint16 vectors to uint8 vectors (with saturation)
65 return vcombine_u8(vqmovn_u16(vd_low_u16x8), vqmovn_u16(vd_high_u16x8));
66}
67} // namespace arm_compute