aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntonio de Angelis <antonio.deangelis@arm.com>2019-03-04 16:43:15 +0000
committerAntonio de Angelis <antonio.deangelis@arm.com>2019-07-31 10:09:18 +0000
commitffdcaa8e869ccc7b8f6631726f86cfa6323c4fee (patch)
tree34090dfb7a579e339805b09597139c2325cb6f42
parent457ee3e23421e58c89a2cc2395c252e3a54da1cc (diff)
downloadtrusted-firmware-m-ffdcaa8e869ccc7b8f6631726f86cfa6323c4fee.tar.gz
Core: Optimise bitcount routines
This patch optimises the bitcount routines used in the TF-M core. Change-Id: Ia95424713fc5eeb4ccad03ae4aa2bdd500f396d4 Signed-off-by: Antonio de Angelis <antonio.deangelis@arm.com>
-rw-r--r--secure_fw/core/ipc/tfm_svcalls.c6
-rw-r--r--secure_fw/core/secure_utilities.h3
-rw-r--r--secure_fw/core/tfm_func_api.c6
-rw-r--r--secure_fw/core/tfm_secure_api.c18
4 files changed, 17 insertions, 16 deletions
diff --git a/secure_fw/core/ipc/tfm_svcalls.c b/secure_fw/core/ipc/tfm_svcalls.c
index 447a9f7e43..007fa19fbe 100644
--- a/secure_fw/core/ipc/tfm_svcalls.c
+++ b/secure_fw/core/ipc/tfm_svcalls.c
@@ -1046,7 +1046,7 @@ static void tfm_svcall_psa_eoi(uint32_t *args)
}
/* It is a fatal error if passed signal indicates more than one signals. */
- if (tfm_bitcount(irq_signal) != 1) {
+ if (!tfm_is_one_bit_set(irq_signal)) {
tfm_panic();
}
@@ -1070,7 +1070,7 @@ void tfm_svcall_enable_irq(uint32_t *args)
struct tfm_spm_ipc_partition_t *partition = NULL;
/* It is a fatal error if passed signal indicates more than one signals. */
- if (tfm_bitcount(irq_signal) != 1) {
+ if (!tfm_is_one_bit_set(irq_signal)) {
tfm_panic();
}
@@ -1097,7 +1097,7 @@ void tfm_svcall_disable_irq(uint32_t *args)
struct tfm_spm_ipc_partition_t *partition = NULL;
/* It is a fatal error if passed signal indicates more than one signals. */
- if (tfm_bitcount(irq_signal) != 1) {
+ if (!tfm_is_one_bit_set(irq_signal)) {
tfm_panic();
}
diff --git a/secure_fw/core/secure_utilities.h b/secure_fw/core/secure_utilities.h
index 769d3900e1..0aa0e94549 100644
--- a/secure_fw/core/secure_utilities.h
+++ b/secure_fw/core/secure_utilities.h
@@ -9,6 +9,7 @@
#define __SECURE_UTILITIES_H__
#include <stdio.h>
+#include <stdbool.h>
#include "cmsis_compiler.h"
#include "tfm_svc.h"
@@ -58,4 +59,6 @@ struct tfm_exc_stack_t {
int32_t tfm_bitcount(uint32_t n);
+bool tfm_is_one_bit_set(uint32_t n);
+
#endif /* __SECURE_UTILITIES_H__ */
diff --git a/secure_fw/core/tfm_func_api.c b/secure_fw/core/tfm_func_api.c
index 1c3982023e..6f7ac7d0fd 100644
--- a/secure_fw/core/tfm_func_api.c
+++ b/secure_fw/core/tfm_func_api.c
@@ -1379,7 +1379,7 @@ void tfm_core_enable_irq_handler(uint32_t *svc_args)
int32_t irq_line;
/* Only a single signal is allowed */
- if (tfm_bitcount(irq_signal) != 1) {
+ if (!tfm_is_one_bit_set(irq_signal)) {
/* FixMe: error severity TBD */
tfm_secure_api_error_handler();
}
@@ -1405,7 +1405,7 @@ void tfm_core_disable_irq_handler(uint32_t *svc_args)
int32_t irq_line;
/* Only a single signal is allowed */
- if (tfm_bitcount(irq_signal) != 1) {
+ if (!tfm_is_one_bit_set(irq_signal)) {
/* FixMe: error severity TBD */
tfm_secure_api_error_handler();
}
@@ -1466,7 +1466,7 @@ void tfm_core_psa_eoi(uint32_t *svc_args)
curr_part_data = tfm_spm_partition_get_runtime_data(running_partition_idx);
/* Only a single signal is allowed */
- if (tfm_bitcount(irq_signal) != 1) {
+ if (!tfm_is_one_bit_set(irq_signal)) {
tfm_secure_api_error_handler();
}
diff --git a/secure_fw/core/tfm_secure_api.c b/secure_fw/core/tfm_secure_api.c
index 57e94efd2b..3a262d42f0 100644
--- a/secure_fw/core/tfm_secure_api.c
+++ b/secure_fw/core/tfm_secure_api.c
@@ -39,19 +39,17 @@ int32_t tfm_secure_lock;
int32_t tfm_bitcount(uint32_t n)
{
- int32_t count = 0;
- uint8_t tmp;
-
+ uint8_t count = 0;
while (n) {
- tmp = n & 0xFF;
- while (tmp) {
- count += tmp & 0x1;
- tmp >>= 1;
- }
- n >>= 8;
+ count++;
+ n &= n-1;
}
+ return (int32_t)count;
+}
- return count;
+bool tfm_is_one_bit_set(uint32_t n)
+{
+ return ((n && !(n & (n-1))) ? true : false);
}
/**