From 1e5fe1b836beca724b977f39d3b83cf1f8e38748 Mon Sep 17 00:00:00 2001 From: Astro Date: Fri, 31 Jan 2020 20:47:16 +0100 Subject: [PATCH] regs: add more #[inline] annotations reduces .text size by 740 bytes --- libcortex_a9/src/regs.rs | 9 +++++++-- libregister/src/lib.rs | 15 +++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/libcortex_a9/src/regs.rs b/libcortex_a9/src/regs.rs index 8f89241..c8aab19 100644 --- a/libcortex_a9/src/regs.rs +++ b/libcortex_a9/src/regs.rs @@ -8,7 +8,7 @@ macro_rules! def_reg_r { impl RegisterR for $name { type R = $type; - #[inline(always)] + #[inline] fn read(&self) -> Self::R { let mut value: u32; unsafe { asm!($asm_instr : "=r" (value) ::: "volatile") } @@ -23,12 +23,13 @@ macro_rules! def_reg_w { impl RegisterW for $name { type W = $type; - #[inline(always)] + #[inline] fn write(&mut self, value: Self::W) { let value: u32 = value.into(); unsafe { asm!($asm_instr :: "r" (value) :: "volatile") } } + #[inline] fn zeroed() -> Self::W { 0u32.into() } @@ -43,6 +44,7 @@ macro_rules! wrap_reg { pub inner: u32, } impl From for Read { + #[inline] fn from(value: u32) -> Self { Read { inner: value } } @@ -52,11 +54,13 @@ macro_rules! wrap_reg { pub inner: u32, } impl From for Write { + #[inline] fn from(value: u32) -> Self { Write { inner: value } } } impl Into for Write { + #[inline] fn into(self) -> u32 { self.inner } @@ -133,6 +137,7 @@ register_bit!(actlr, l1_prefetch_enable, 2); register_bit!(actlr, fw, 0); impl RegisterRW for ACTLR { + #[inline] fn modify Self::W>(&mut self, f: F) { let r = self.read(); let w = actlr::Write { inner: r.inner }; diff --git a/libregister/src/lib.rs b/libregister/src/lib.rs index e4ef1e7..603507b 100644 --- a/libregister/src/lib.rs +++ b/libregister/src/lib.rs @@ -55,6 +55,7 @@ macro_rules! register_r { impl libregister::RegisterR for $struct_name { type R = $mod_name::Read; + #[inline] fn read(&self) -> Self::R { let inner = self.inner.read(); $mod_name::Read { inner } @@ -69,10 +70,12 @@ macro_rules! register_w { impl libregister::RegisterW for $struct_name { type W = $mod_name::Write; + #[inline] fn zeroed() -> $mod_name::Write { $mod_name::Write { inner: 0 } } + #[inline] fn write(&mut self, w: Self::W) { unsafe { self.inner.write(w.inner); @@ -86,6 +89,7 @@ macro_rules! register_w { macro_rules! register_rw { ($mod_name: ident, $struct_name: ident) => ( impl libregister::RegisterRW for $struct_name { + #[inline] fn modify Self::W>(&mut self, f: F) { unsafe { self.inner.modify(|inner| { @@ -105,6 +109,7 @@ macro_rules! register_vcell { impl libregister::RegisterR for $struct_name { type R = $mod_name::Read; + #[inline] fn read(&self) -> Self::R { let inner = self.inner.get(); $mod_name::Read { inner } @@ -113,15 +118,18 @@ macro_rules! register_vcell { impl libregister::RegisterW for $struct_name { type W = $mod_name::Write; + #[inline] fn zeroed() -> $mod_name::Write { $mod_name::Write { inner: 0 } } + #[inline] fn write(&mut self, w: Self::W) { self.inner.set(w.inner); } } impl libregister::RegisterRW for $struct_name { + #[inline] fn modify Self::W>(&mut self, f: F) { let r = self.read(); let w = $mod_name::Write { inner: r.inner }; @@ -169,6 +177,7 @@ macro_rules! register_bit { $(#[$outer])* impl $mod_name::Read { #[allow(unused)] + #[inline] pub fn $name(&self) -> bool { use bit_field::BitField; @@ -179,6 +188,7 @@ macro_rules! register_bit { $(#[$outer])* impl $mod_name::Write { #[allow(unused)] + #[inline] pub fn $name(mut self, value: bool) -> Self { use bit_field::BitField; @@ -195,6 +205,7 @@ macro_rules! register_bits { ($mod_name: ident, $(#[$outer:meta])* $name: ident, $type: ty, $bit_begin: expr, $bit_end: expr) => ( impl $mod_name::Read { #[allow(unused)] + #[inline] $(#[$outer])* pub fn $name(&self) -> $type { use bit_field::BitField; @@ -207,6 +218,7 @@ macro_rules! register_bits { $(#[$outer])* impl $mod_name::Write { #[allow(unused)] + #[inline] pub fn $name(mut self, value: $type) -> Self { use bit_field::BitField; @@ -226,6 +238,7 @@ macro_rules! register_bits_typed { ($mod_name: ident, $(#[$outer:meta])* $name: ident, $bit_type: ty, $type: ty, $bit_begin: expr, $bit_end: expr) => ( impl $mod_name::Read { #[allow(unused)] + #[inline] $(#[$outer])* pub fn $name(&self) -> $type { use bit_field::BitField; @@ -237,6 +250,7 @@ macro_rules! register_bits_typed { impl $mod_name::Write { #[allow(unused)] + #[inline] $(#[$outer])* pub fn $name(mut self, value: $type) -> Self { use bit_field::BitField; @@ -254,6 +268,7 @@ macro_rules! register_at { ($name: ident, $addr: expr, $ctor: ident) => ( impl $name { #[allow(unused)] + #[inline] pub fn $ctor() -> &'static mut Self { let addr = $addr as *mut Self; unsafe { &mut *addr }