summaryrefslogtreecommitdiff
path: root/jmemmgr.c
diff options
context:
space:
mode:
authorJonathan Wright <jonathan.wright@arm.com>2019-05-20 15:13:57 +0100
committerJonathan Wright <jonathan.wright@arm.com>2019-05-20 15:57:11 +0100
commitfdcaeede1eae1dc9898212fdb963b0ae98ec43c8 (patch)
tree17ed58ab7070de403d5363f9bf995b89c07e4e71 /jmemmgr.c
parent2de84a43e683c2c3c8ff4922da16b9053f024144 (diff)
Add memory alignment size check in jmemmgr.c
SIMD architectures have different memory alignment requirements which must be complied with to prevent performance - and more importantly - security issues. This patch introduces an explicit compile-time check to make sure that ALIGN_SIZE is a multiple of 32 bytes for AVX2 and a multiple of 16 bytes for all other architectures. Future Arm NEON performance patches will rely on this behaviour in the memory manager for correctness. Bug: 922430 Change-Id: I8cf0503fba301baa6505459e3308ba89e670cc26
Diffstat (limited to 'jmemmgr.c')
-rw-r--r--jmemmgr.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/jmemmgr.c b/jmemmgr.c
index 508ca74..8765bb4 100644
--- a/jmemmgr.c
+++ b/jmemmgr.c
@@ -95,6 +95,15 @@ round_up_pow2(size_t a, size_t b)
#endif
#endif
+#ifdef WITH_SIMD
+#if (ALIGN_SIZE % 16)
+ #error "ALIGN_SIZE is not a multiple of 16 bytes - required for SIMD instructions."
+#endif
+#if defined(__AVX2__) && (ALIGN_SIZE % 32)
+ #error "AVX2 requires 32-byte alignment. ALIGN_SIZE is not a multiple of 32 bytes."
+#endif
+#endif
+
/*
* We allocate objects from "pools", where each pool is gotten with a single
* request to jpeg_get_small() or jpeg_get_large(). There is no per-object