1 /****************************************************************************** 2 * 3 * Copyright 2022 Google LLC 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at: 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 ******************************************************************************/ 18 19 #if __ARM_FEATURE_SIMD32 20 21 #include <arm_acle.h> 22 23 static inline int16x2_t __pkhbt(int16x2_t a, int16x2_t b) 24 { 25 int16x2_t r; 26 __asm("pkhbt %0, %1, %2" : "=r" (r) : "r" (a), "r" (b)); 27 return r; 28 } 29 30 #else 31 32 #include <stdint.h> 33 34 typedef int32_t int16x2_t; 35 36 __attribute__((unused)) 37 static int16x2_t __pkhbt(int16x2_t a, int16x2_t b) 38 { 39 uint32_t a_bot = (uint32_t)a & 0x0000ffffu; 40 uint32_t b_top = (uint32_t)b & 0xffff0000u; 41 42 return (int16x2_t)(a_bot | b_top); 43 } 44 45 __attribute__((unused)) 46 static int32_t __smlad(int16x2_t a, int16x2_t b, int32_t u) 47 { 48 int16_t a_hi = a >> 16, a_lo = a & 0xffff; 49 int16_t b_hi = b >> 16, b_lo = b & 0xffff; 50 51 return u + (a_hi * b_hi) + (a_lo * b_lo); 52 } 53 54 __attribute__((unused)) 55 static int64_t __smlald(int16x2_t a, int16x2_t b, int64_t u) 56 { 57 int16_t a_hi = a >> 16, a_lo = a & 0xffff; 58 int16_t b_hi = b >> 16, b_lo = b & 0xffff; 59 return u + (a_hi * b_hi) + (a_lo * b_lo); 60 } 61 62 __attribute__((unused)) 63 static int64_t __smlaldx(int16x2_t a, int16x2_t b, int64_t u) 64 { 65 int16_t a_hi = a >> 16, a_lo = a & 0xffff; 66 int16_t b_hi = b >> 16, b_lo = b & 0xffff; 67 return u + (a_hi * b_lo) + (a_lo * b_hi); 68 } 69 70 #endif /* __ARM_FEATURE_SIMD32 */ 71