title: memset slow on 32-bit embedded platform
body: <p>I am developing on an embedded device (STM32, ARM-Cortex M4) and expected <code>memset</code> and similar functions to be optimized for speed.  However, I noticed much slower behavior than expected.  I'm using GNU ARM embedded compiler/linker (<code>arm-none-eabi-gcc</code>, etc) with the <code>-O3</code> optimization flag.</p>
  
  <p>I looked into the disassembly and the <code>memset</code> function is writing one byte at a time and rechecking bounds at each iteration.</p>
  
  <pre><code>0x802e2c4 &lt;memset&gt;: add r2, r0
  0x802e2c6 &lt;memset+2&gt;:   mov r3, r0
  0x802e2c8 &lt;memset+4&gt;:   cmp r3, r2
  0x802e2ca &lt;memset+6&gt;:   bne.n   0x802e2ce &lt;memset+10&gt;
  0x802e2cc &lt;memset+8&gt;:   bx  lr
  0x802e2ce &lt;memset+10&gt;:  strb.w  r1, [r3], #1
  0x802e2d2 &lt;memset+14&gt;:  b.n 0x802e2c8
  </code></pre>
  
  <p></p>
  
  <p>Naturally, this code could be sped up by using 32-bit writes and/or loop unrolling at the expense of code size.  It is possible the implementers chose not to optimize this for speed in order to keep code size down.</p>
  
  <p>The <code>memset</code> header and library are being included from:</p>
  
  <pre><code>C:\Program Files (x86)\GNU Tools Arm Embedded\7 2018-q2-update\arm-none-eabi\include\string.h
  C:\Program Files (x86)\GNU Tools Arm Embedded\7 2018-q2-update\arm-none-eabi\include\c++\7.3.1\cmath
  </code></pre>
  
  <p>This question is similar to existing questions but is different in that it targets an embedded platform.</p>
  
  <p><strong>Is there an optimized memset readily available within the GNU ARM embedded package?  If so how can I access it?</strong></p>