>From: owner-openssl-...@openssl.org On Behalf Of Yuan Kang
>Sent: Tuesday, 27 August, 2013 00:54
        
>I don't think that it is true that "(signed char)(*p) >= 0" 
>is always true, <snip>

Mr Weimer didn't say it IS always true, he said a compiler 
IS ALLOWED TO ASSUME it is. As I adjusted, the compiler does 
have to document that it does this. Whether a given compiler 
does it depends on the writers of that compiler, and quite 
likely on the target architecture, and quite possibly on 
the optimizations implemented by the compiler and used.

As I added, gcc (at least the versions I have) documents 
that it doesn't do so. What you need to check (or test) is 
all versions of all other compilers used on all platforms 
OpenSSL supports, with all optimization settings. Preferably 
also all versions or replacements that will be released in 
the next several years; people often are seen staying on 
old OpenSSL versions 5 years or more, so that seems a good 
minimum. It's a lot easier to support code that just works.

> I think the optimization that PMHager was thinking about 
> (based on what I see in the x86_64 assembly from gcc) is 
> that the compiler could (but apparently not every compiler 
> does this) use the instruction for checking the sign, like this:
>          9:    84 c9                    test   %cl,%cl
>          b:    78 1b                    js     28 <UTF8_getc+0x28>
        
>This is most likely faster than having to do a logical and instruction
first.
        
It may be faster but that's far from certain, and I'm very 
confident it's not usefully faster; nearly all of the time 
will be in the memory references (which don't change) 
and the branch if mispredicted (which doesn't change).

And not all CPUs work the same as x64, or x86. Where 
speed really matters, like in some of the cipher and 
hash cores, OpenSSL has assembler -- separate for each 
CPU (more or less), and reliably producing the desired 
instructions no matter what the C code generator does.
That's better (though more work) than nonportable C,
which soon needs #ifdef hell to keep working.


______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
Development Mailing List                       openssl-dev@openssl.org
Automated List Manager                           majord...@openssl.org

Reply via email to