The attached test case contains several continuous bit fields assignment, compile it with options -mthumb -Os, gcc generates
.fnstart .LFB1: ldrb r3, [r0] mov r2, #7 bic r3, r3, r2 strb r3, [r0] ldrb r3, [r0] mov r2, #56 bic r3, r3, r2 mov r2, #8 orr r3, r3, r2 strb r3, [r0] ldrb r3, [r0] mov r2, #64 bic r3, r3, r2 strb r3, [r0] ldrb r2, [r0] mov r3, #127 and r3, r3, r2 strb r3, [r0] @ sp needed for prologue bx lr The 4 fields are contained in one word, for each field assignment the code loads the word, changes the field, then write the word back. A better code sequence should load the word once, change all 4 fields, then write back the changed word. ldrb r3, [r0] mov r2, #255 // bit mask bic r3, r3, r2 mov r2, #8 // the new value of all 4 fields orr r3, r3, r2 strb r3, [r0] @ sp needed for prologue bx lr or more aggressively if the word contains only these four fields mov r3, #8 strb r3, [r0] @ sp needed for prologue bx lr -- Summary: inefficient bit fields assignments Product: gcc Version: 4.5.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: carrot at google dot com GCC build triplet: i686-linux GCC host triplet: i686-linux GCC target triplet: arm-eabi http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42172