------- Additional Comments From dann at godzilla dot ics dot uci dot edu  
2005-06-24 17:41 -------
(In reply to comment #21)

> The slow routine appears to be the buffer cleaning routine,
> though I haven't verified this with oprofile yet.
> Here's its loop:
> static char cleanse_ctr;
> ...
>     while (len--) {
>         *(ptr++) = cleanse_ctr;
>         cleanse_ctr += (17 + (unsigned char) ((int) ptr & 0xF));
>     }

[Not entirely related, but..] There's one obvious way to improve this loop. 
The compiler cannot prove that the write *(ptr++) does not alias the global
variable cleanse_ptr, so it will read it from memory in each iteration.
To avoid the extra memory read just do something like:

void OPENSSL_cleanse(unsigned char *ptr, unsigned int len)
{
  unsigned char local_cleanse_ctr = cleanse_ctr;
  while (len--) {
        *(ptr++) = local_cleanse_ctr;
        local_cleanse_ctr += (17 + (unsigned char) ((int) ptr & 0xF));
    }
  local_cleanse_ctr += 63;
  cleanse_ctr = local_cleanse_ctr;  
}


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19923

Reply via email to