title: Is there a standard macro to detect architectures requiring aligned memory access?
body: <p>Assuming something like:</p>
  
  <pre><code>void mask_bytes(unsigned char* dest, unsigned char* src, unsigned char* mask, unsigned int len)
  {
    unsigned int i;
    for(i=0; i&lt;len; i++)
    {
       dest[i] = src[i] &amp; mask[i];
    }
  }
  </code></pre>
  
  <p>I can go faster on a non-aligned access machine (e.g. x86) by writing something like:</p>
  
  <pre><code>void mask_bytes(unsigned char* dest, unsigned char* src, unsigned char* mask, unsigned int len)
  {
    unsigned int i;
    unsigned int wordlen = len &gt;&gt; 2;
    for(i=0; i&lt;wordlen; i++)
    {
      ((uint32_t*)dest)[i] = ((uint32_t*)src)[i] &amp; ((uint32_t*)mask)[i]; // this raises SIGBUS on SPARC and other archs that require aligned access.
    }
    for(i=wordlen&lt;&lt;2; i&lt;len; i++){
      dest[i] = src[i] &amp; mask[i];
    }
  }
  </code></pre>
  
  <p>However it needs to build on several architectures so I would like to do something like:</p>
  
  <pre><code>void mask_bytes(unsigned char* dest, unsigned char* src, unsigned char* mask, unsigned int len)
  {
    unsigned int i;
    unsigned int wordlen = len &gt;&gt; 2;
  
  #if defined(__ALIGNED2__) || defined(__ALIGNED4__) || defined(__ALIGNED8__)
    // go slow
    for(i=0; i&lt;len; i++)
    {
       dest[i] = src[i] &amp; mask[i];
    }
  #else
    // go fast
    for(i=0; i&lt;wordlen; i++)
    {
      // the following line will raise SIGBUS on SPARC and other archs that require aligned access.
      ((uint32_t*)dest)[i] = ((uint32_t*)src)[i] &amp; ((uint32_t*)mask)[i]; 
    }
    for(i=wordlen&lt;&lt;2; i&lt;len; i++){
      dest[i] = src[i] &amp; mask[i];
    }
  #endif
  }
  </code></pre>
  
  <p>But I cannot find any good information on compiler defined macros (like my hypothetical <code>__ALIGNED4__</code> above) that specify alignment or any clever ways of using the pre-processor to determine target architecture alignment. I could just test <code>defined (__SVR4) &amp;&amp; defined (__sun)</code>, but I would prefer something that will Just Work<sup><sup><sub>TM</sub></sup></sup> on other architectures requiring aligned memory accesses.</p>