Skip to content

Commit 3d101f9

Browse files
committed
Basically revert #141 and mark methods #[inline(always)] again
Turns out this @therealprof dude was wrong in blindly following general consensus that #[inline(always)] was a bad idea. Revisiting the topic showed that just #[inline] is not enough to get even very trivial functions inlined in dev mode which causes a ton of bloat and a lot of debugging fun due to many emitted extra functions without any value for the developer. Usual binary reductions by this change are in the area of 10-15% which is a lot given that even a simply blinky on Cortex-M0 is several kB already. E.g. before: 0.5% 100.0% 4.0KiB .text section size, the file size is 734.1KiB after: 0.5% 100.0% 3.7KiB .text section size, the file size is 714.5KiB Signed-off-by: Daniel Egger <[email protected]>
1 parent c70c814 commit 3d101f9

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

src/generate/register.rs

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pub fn render(
4242
if access == Access::ReadWrite {
4343
reg_impl_items.push(quote! {
4444
/// Modifies the contents of the register
45-
#[inline]
45+
#[inline(always)]
4646
pub fn modify<F>(&self, f: F)
4747
where
4848
for<'w> F: FnOnce(&R, &'w mut W) -> &'w mut W
@@ -56,7 +56,7 @@ pub fn render(
5656
if access == Access::ReadOnly || access == Access::ReadWrite {
5757
reg_impl_items.push(quote! {
5858
/// Reads the contents of the register
59-
#[inline]
59+
#[inline(always)]
6060
pub fn read(&self) -> R {
6161
R { bits: self.register.get() }
6262
}
@@ -71,7 +71,7 @@ pub fn render(
7171

7272
r_impl_items.push(quote! {
7373
/// Value of the register as raw bits
74-
#[inline]
74+
#[inline(always)]
7575
pub fn bits(&self) -> #rty {
7676
self.bits
7777
}
@@ -81,7 +81,7 @@ pub fn render(
8181
if access == Access::WriteOnly || access == Access::ReadWrite {
8282
reg_impl_items.push(quote! {
8383
/// Writes to the register
84-
#[inline]
84+
#[inline(always)]
8585
pub fn write<F>(&self, f: F)
8686
where
8787
F: FnOnce(&mut W) -> &mut W
@@ -105,20 +105,20 @@ pub fn render(
105105

106106
reg_impl_items.push(quote! {
107107
/// Reset value of the register
108-
#[inline]
108+
#[inline(always)]
109109
pub const fn reset_value() -> #rty {
110110
#rv
111111
}
112112
/// Writes the reset value to the register
113-
#[inline]
113+
#[inline(always)]
114114
pub fn reset(&self) {
115115
self.register.set(Self::reset_value())
116116
}
117117
});
118118

119119
w_impl_items.push(quote! {
120120
/// Writes raw bits to the register
121-
#[inline]
121+
#[inline(always)]
122122
pub #unsafety fn bits(&mut self, bits: #rty) -> &mut Self {
123123
self.bits = bits;
124124
self
@@ -365,7 +365,7 @@ pub fn fields(
365365
let sc = &f.sc;
366366
r_impl_items.push(quote! {
367367
#[doc = #description]
368-
#[inline]
368+
#[inline(always)]
369369
pub fn #sc(&self) -> #pc_r {
370370
#pc_r::_from( #value )
371371
}
@@ -421,13 +421,13 @@ pub fn fields(
421421
if f.width == 1 {
422422
enum_items.push(quote! {
423423
/// Returns `true` if the bit is clear (0)
424-
#[inline]
424+
#[inline(always)]
425425
pub fn bit_is_clear(&self) -> bool {
426426
!self.#bits()
427427
}
428428

429429
/// Returns `true` if the bit is set (1)
430-
#[inline]
430+
#[inline(always)]
431431
pub fn bit_is_set(&self) -> bool {
432432
self.#bits()
433433
}
@@ -436,7 +436,7 @@ pub fn fields(
436436

437437
enum_items.push(quote! {
438438
/// Value of the field as raw bits
439-
#[inline]
439+
#[inline(always)]
440440
pub fn #bits(&self) -> #fty {
441441
match *self {
442442
#(#arms),*
@@ -469,7 +469,7 @@ pub fn fields(
469469
enum_items.push(quote! {
470470
#[allow(missing_docs)]
471471
#[doc(hidden)]
472-
#[inline]
472+
#[inline(always)]
473473
pub fn _from(value: #fty) -> #pc_r {
474474
match value {
475475
#(#arms),*,
@@ -490,7 +490,7 @@ pub fn fields(
490490
let doc = format!("Checks if the value of the field is `{}`", pc);
491491
enum_items.push(quote! {
492492
#[doc = #doc]
493-
#[inline]
493+
#[inline(always)]
494494
pub fn #is_variant(&self) -> bool {
495495
*self == #pc_r::#pc
496496
}
@@ -509,7 +509,7 @@ pub fn fields(
509509
let sc = &f.sc;
510510
r_impl_items.push(quote! {
511511
#[doc = #description]
512-
#[inline]
512+
#[inline(always)]
513513
pub fn #sc(&self) -> #pc_r {
514514
let bits = #value;
515515
#pc_r { bits }
@@ -519,7 +519,7 @@ pub fn fields(
519519
let mut pc_r_impl_items = vec![
520520
quote! {
521521
/// Value of the field as raw bits
522-
#[inline]
522+
#[inline(always)]
523523
pub fn #bits(&self) -> #fty {
524524
self.bits
525525
}
@@ -529,13 +529,13 @@ pub fn fields(
529529
if f.width == 1 {
530530
pc_r_impl_items.push(quote! {
531531
/// Returns `true` if the bit is clear (0)
532-
#[inline]
532+
#[inline(always)]
533533
pub fn bit_is_clear(&self) -> bool {
534534
!self.#bits()
535535
}
536536

537537
/// Returns `true` if the bit is set (1)
538-
#[inline]
538+
#[inline(always)]
539539
pub fn bit_is_set(&self) -> bool {
540540
self.#bits()
541541
}
@@ -690,7 +690,7 @@ pub fn fields(
690690
impl #pc_w {
691691
#[allow(missing_docs)]
692692
#[doc(hidden)]
693-
#[inline]
693+
#[inline(always)]
694694
pub fn _bits(&self) -> #fty {
695695
match *self {
696696
#(#arms),*
@@ -702,7 +702,7 @@ pub fn fields(
702702

703703
proxy_items.push(quote! {
704704
/// Writes `variant` to the field
705-
#[inline]
705+
#[inline(always)]
706706
pub fn variant(self, variant: #pc_w) -> &'a mut W {
707707
#unsafety {
708708
self.#bits(variant._bits())
@@ -718,15 +718,15 @@ pub fn fields(
718718
if let Some(enum_) = base_pc_w.as_ref() {
719719
proxy_items.push(quote! {
720720
#[doc = #doc]
721-
#[inline]
721+
#[inline(always)]
722722
pub fn #sc(self) -> &'a mut W {
723723
self.variant(#enum_::#pc)
724724
}
725725
});
726726
} else {
727727
proxy_items.push(quote! {
728728
#[doc = #doc]
729-
#[inline]
729+
#[inline(always)]
730730
pub fn #sc(self) -> &'a mut W {
731731
self.variant(#pc_w::#pc)
732732
}
@@ -751,7 +751,7 @@ pub fn fields(
751751

752752
proxy_items.push(quote! {
753753
/// Writes raw bits to the field
754-
#[inline]
754+
#[inline(always)]
755755
pub #unsafety fn #bits(self, value: #fty) -> &'a mut W {
756756
self.w.bits &= !(#mask << #offset);
757757
self.w.bits |= ((value as #rty) & #mask) << #offset;
@@ -775,7 +775,7 @@ pub fn fields(
775775
let sc = &f.sc;
776776
w_impl_items.push(quote! {
777777
#[doc = #description]
778-
#[inline]
778+
#[inline(always)]
779779
pub fn #sc(&mut self) -> #_pc_w {
780780
#_pc_w { w: self }
781781
}

0 commit comments

Comments
 (0)