blob: 209785d94e4a7a6c8ac1128787ebe10d35daba3e [file] [log] [blame]
Gian Marco58c57942017-11-28 09:10:03 +00001/*
George Wort2d7e6832019-02-22 16:37:41 +00002 * Copyright (c) 2017-2019 ARM Limited.
Gian Marco58c57942017-11-28 09:10:03 +00003 *
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
George Wort2d7e6832019-02-22 16:37:41 +000034inline int32_t rounding_divide_by_pow2(int32_t x, int exponent)
35{
36 const int32_t mask = (1 << exponent) - 1;
37 const int32_t threshold = (mask >> 1) + (x < 0 ? 1 : 0);
38 return (x >> exponent) + ((x & mask) > threshold ? 1 : 0);
39}
40
Michel Iwaniec5dfeae62017-11-29 10:48:23 +000041inline qasymm8x16_t vmlaq_qasymm8(qasymm8x16_t vd, float32x4_t vs, float32x4_t vo)
42{
43 // Convert uint8 vectors to uint16 vectors
44 const uint8x8_t vd_low = vget_low_u8(vd);
45 const uint8x8_t vd_high = vget_high_u8(vd);
46 uint16x8_t vd_low_u16x8 = vmovl_u8(vd_low);
47 uint16x8_t vd_high_u16x8 = vmovl_u8(vd_high);
48 // Convert uint16 vectors to uint32 vectors
49 uint32x4_t A_u32x4 = vmovl_u16(vget_low_u16(vd_low_u16x8));
50 uint32x4_t B_u32x4 = vmovl_u16(vget_high_u16(vd_low_u16x8));
51 uint32x4_t C_u32x4 = vmovl_u16(vget_low_u16(vd_high_u16x8));
52 uint32x4_t D_u32x4 = vmovl_u16(vget_high_u16(vd_high_u16x8));
53 // Convert uint32 vectors to float32 vectors
54 float32x4_t A_f32x4 = vcvtq_f32_u32(A_u32x4);
55 float32x4_t B_f32x4 = vcvtq_f32_u32(B_u32x4);
56 float32x4_t C_f32x4 = vcvtq_f32_u32(C_u32x4);
57 float32x4_t D_f32x4 = vcvtq_f32_u32(D_u32x4);
58 // vd = vd*vs + vo
59 A_f32x4 = vmlaq_f32(vo, A_f32x4, vs);
60 B_f32x4 = vmlaq_f32(vo, B_f32x4, vs);
61 C_f32x4 = vmlaq_f32(vo, C_f32x4, vs);
62 D_f32x4 = vmlaq_f32(vo, D_f32x4, vs);
63 // Convert float32 vectors to uint32 vectors
64 A_u32x4 = vcvtq_u32_f32(A_f32x4);
65 B_u32x4 = vcvtq_u32_f32(B_f32x4);
66 C_u32x4 = vcvtq_u32_f32(C_f32x4);
67 D_u32x4 = vcvtq_u32_f32(D_f32x4);
68 // Convert uint32 vectors to uint16 vectors (with saturation)
69 vd_low_u16x8 = vcombine_u16(vqmovn_u32(A_u32x4), vqmovn_u32(B_u32x4));
70 vd_high_u16x8 = vcombine_u16(vqmovn_u32(C_u32x4), vqmovn_u32(D_u32x4));
71 // convert uint16 vectors to uint8 vectors (with saturation)
72 return vcombine_u8(vqmovn_u16(vd_low_u16x8), vqmovn_u16(vd_high_u16x8));
73}
74} // namespace arm_compute