1 /*
2 * Copyright (c) 2019-2020 Kevin Townsend (KTOWN)
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 /**
8 * @file
9 * @brief Optimised vector functions for zscilib using ARM Thumb or ARM Thumb2.
10 *
11 * This file contains optimised vector functions for ARM Thumb or ARM Thumb2.
12 */
13
14 #include <zsl/zsl.h>
15 #include <zsl/asm/arm/asm_arm.h>
16
17 #ifndef ZEPHYR_INCLUDE_ZSL_ASM_ARM_VECTORS_H_
18 #define ZEPHYR_INCLUDE_ZSL_ASM_ARM_VECTORS_H_
19
20 #if !asm_vec_add
21 #if CONFIG_ZSL_PLATFORM_OPT == 2
zsl_vec_add(struct zsl_vec * v,struct zsl_vec * w,struct zsl_vec * x)22 int zsl_vec_add(struct zsl_vec *v, struct zsl_vec *w, struct zsl_vec *x)
23 {
24 #if CONFIG_ZSL_BOUNDS_CHECKS
25 /* Make sure v and w are equal length. */
26 if ((v->sz != w->sz) || (v->sz != x->sz)) {
27 return -EINVAL;
28 }
29 #endif
30
31 for (size_t i = 0; i < v->sz; i++) {
32 x->data[i] = v->data[i] + w->data[i];
33 }
34
35 return 0;
36 }
37 #define asm_vec_add 1
38 #endif
39 #endif
40
41 #if !asm_vec_scalar_add
42 #if CONFIG_ZSL_PLATFORM_OPT == 2
43 /* TODO: ARM Thumb2 GNU implementation. */
zsl_vec_scalar_add(struct zsl_vec * v,zsl_real_t s)44 int zsl_vec_scalar_add(struct zsl_vec *v, zsl_real_t s)
45 {
46 for (size_t i = 0; i < v->sz; i++) {
47 v->data[i] += s;
48 }
49
50 return 0;
51 }
52 #define asm_vec_scalar_add 1
53 #endif
54 #endif
55
56 #if !asm_vec_scalar_mult
57 #if CONFIG_ZSL_PLATFORM_OPT == 2
58 /* TODO: ARM Thumb2 GNU implementation. */
zsl_vec_scalar_mult(struct zsl_vec * v,zsl_real_t s)59 int zsl_vec_scalar_mult(struct zsl_vec *v, zsl_real_t s)
60 {
61 for (size_t i = 0; i < v->sz; i++) {
62 v->data[i] *= s;
63 }
64
65 return 0;
66 }
67 #define asm_vec_scalar_mult 1
68 #endif /* CONFIG_ZSL_PLATFORM_OPT == 2 */
69 #endif
70
71 #if !asm_vec_scalar_div
72 #if CONFIG_ZSL_PLATFORM_OPT == 2
73 /* TODO: ARM Thumb2 GNU implementation. */
zsl_vec_scalar_div(struct zsl_vec * v,zsl_real_t s)74 int zsl_vec_scalar_div(struct zsl_vec *v, zsl_real_t s)
75 {
76 /* Avoid divide by zero errors. */
77 if (s == 0) {
78 return -EINVAL;
79 }
80
81 for (size_t i = 0; i < v->sz; i++) {
82 v->data[i] /= s;
83 }
84
85 return 0;
86 }
87 #define asm_vec_scalar_div 1
88 #endif /* CONFIG_ZSL_PLATFORM_OPT == 2 */
89 #endif
90
91 #endif /* ZEPHYR_INCLUDE_ZSL_ASM_ARM_VECTORS_H_ */
92