From 263522db97b5b16d2408fa11c5c158f88539bc8c Mon Sep 17 00:00:00 2001 From: Paul Kocialkowski Date: Tue, 22 Sep 2015 22:16:33 +0200 Subject: armv7: Word-sized/half-word-sized memory operations for 32/16 bit read/write As a follow up to Change-Id: I1fb3fc139e0a813acf9d70f14386a9603c9f9ede, use as builtin compiler hint instead of inline assembly to allow the compiler to generate more efficient code. Change-Id: I690514ac6d8988a6494ad3a77690709d932802b0 Signed-off-by: Paul Kocialkowski Signed-off-by: Patrick Georgi Reviewed-on: https://review.coreboot.org/12083 Tested-by: build bot (Jenkins) Reviewed-by: Alexandru Gagniuc Reviewed-by: Julius Werner Reviewed-by: Stefan Reinauer --- src/arch/arm/include/armv7/arch/io.h | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/src/arch/arm/include/armv7/arch/io.h b/src/arch/arm/include/armv7/arch/io.h index 87797bd0eb..1772659fec 100644 --- a/src/arch/arm/include/armv7/arch/io.h +++ b/src/arch/arm/include/armv7/arch/io.h @@ -34,49 +34,40 @@ static inline uint8_t read8(const void *addr) { - uint8_t val; - dmb(); - asm volatile ("ldrb %0, [%1]" : "=r" (val) : "r" (addr) : "memory"); - return val; + return *(volatile uint8_t *)__builtin_assume_aligned(addr, sizeof(uint8_t)); } static inline uint16_t read16(const void *addr) { - uint16_t val; - dmb(); - asm volatile ("ldrh %0, [%1]" : "=r" (val) : "r" (addr) : "memory"); - return val; + return *(volatile uint16_t *)__builtin_assume_aligned(addr, sizeof(uint16_t)); } static inline uint32_t read32(const void *addr) { - uint32_t val; - dmb(); - asm volatile ("ldr %0, [%1]" : "=r" (val) : "r" (addr) : "memory"); - return val; + return *(volatile uint32_t *)__builtin_assume_aligned(addr, sizeof(uint32_t)); } static inline void write8(void *addr, uint8_t val) { dmb(); - asm volatile ("strb %0, [%1]" : : "r" (val), "r" (addr) : "memory"); + *(volatile uint8_t *)__builtin_assume_aligned(addr, sizeof(uint8_t)) = val; dmb(); } static inline void write16(void *addr, uint16_t val) { dmb(); - asm volatile ("strh %0, [%1]" : : "r" (val), "r" (addr) : "memory"); + *(volatile uint16_t *)__builtin_assume_aligned(addr, sizeof(uint16_t)) = val; dmb(); } static inline void write32(void *addr, uint32_t val) { dmb(); - asm volatile ("str %0, [%1]" : : "r" (val), "r" (addr) : "memory"); + *(volatile uint32_t *)__builtin_assume_aligned(addr, sizeof(uint32_t)) = val; dmb(); } -- cgit v1.2.3