only use 48-bit lba when necessary
Quoted 7 lines · Juan Quintela
Reason is that:
if (expr)
var = true;
else
var = false;
Quoted 5 lines
is always a bad construct.
var = expr;
is a better construct to express that meaning.
Yes, but:
if (expr1 && expr2)
var = true;
else
var = false;is usually better turned into something that avoids jumps when it's safe to evaluate both parts unconditionally:
var = (expr1 != 0) & (expr2 != 0);
or (if you can stand it):
var = !!expr1 & !!expr2;
--
Chuck
Quoted 24 lines · Chuck Ebbert
Quoted 7 lines · Juan Quintela
Reason is that:
if (expr)
var = true;
else
var = false;Quoted 5 lines
is always a bad construct.
var = expr;
is a better construct to express that meaning.
Yes, but:
if (expr1 && expr2) var = true; else var = false;
Quoted 8 lines
is usually better turned into something that avoids jumps when it's safe to evaluate both parts unconditionally:
var = (expr1 != 0) & (expr2 != 0);or (if you can stand it):
var = !!expr1 & !!expr2;
Such ugly transformations are a job for compiler writers and may occassionally be acceptable in some critical paths. The IO path, which is literally dozens of function calls deep from read()/write() to driver methods, does not qualify.
FYI, GCC as of 3.2.3 doesn't yet reduce the if(...) form to branchless code but the & and && versions come out the same with -O2.
Signature · 1 line
Matt Mackall : http://www.selenic.com : of or relating to the moon
Quoted 16 lines · Matt Mackall
Quoted 16 lines
Yes, but:
if (expr1 && expr2) var = true; else var = false;is usually better turned into something that avoids jumps when it's safe to evaluate both parts unconditionally:
var = (expr1 != 0) & (expr2 != 0);or (if you can stand it):
Quoted 9 lines
Quoted 3 lines
var = !!expr1 & !!expr2;Such ugly transformations are a job for compiler writers and may occassionally be acceptable in some critical paths. The IO path, which is literally dozens of function calls deep from read()/write() to driver methods, does not qualify.
What's ugly about them? If I were a compiler developer, I would look for "!!" (which I'm sure many compilers do) and deal with it properly. I have seen, however, that gcc produces the same machine code for { if (x) {} } as for { if (x != 0) {} }. Additionally, I would put "!!" in C programming books so that people understand what it means when they come across it. In my mind, it's the "make-it-a-bool" operator.
I certainly don't advocate optimizations that completely obfuscate the meaning of the code, but for ones which are relatively innocuous and make sense, why not? When not to do that is when you know what the compiler is going to do with it. If you can add more characters so that it makes it more understandable without impacting what the compiler produces, then by all means, do it. Another way to "add more characters to make it readable without impacting code size" is to add comments. :) Not to say that I'm any saint in that area.
But I do appreciate it when people take the time to write good, explanatory comments. I'm not saying that you should comment every line (do you comment your comments? :), but putting something before the function which explans it is always a good thing, IMHO. Even when faced with the most readable code, I have some sort of mental block. I like it when I get to read long english textual descriptions of the POINT behind a function before I read the code so I have an abstract framework into which I fit the details. I have a love-hate relationship with details.
Also, It seems that not all compilers perform these "obvious" optimizations. But if any of the gcc contributors are watching some of the recent lkml discussions, I have faith that they'll add some of those optimizations.
Anyhow, I have no emotional attachment to my opinions about comments. I do it my way, you do it yours. I see the merit in all sides of it. The only problem is that if I have trouble reading your code, I will feel less inclined to read it. Oh well.
Quoted 15 lines · Timothy Miller
Quoted 15 lines
Quoted 15 lines
Yes, but:
if (expr1 && expr2)
var = true; else var = false;is usually better turned into something that avoids jumps when it's safe to evaluate both parts unconditionally:
var = (expr1 != 0) & (expr2 != 0);
or (if you can stand it):
Quoted 8 lines
Quoted 6 lines
Quoted 1 line
var = !!expr1 & !!expr2;
Such ugly transformations are a job for compiler writers and may occassionally be acceptable in some critical paths. The IO path, which is literally dozens of function calls deep from read()/write() to driver methods, does not qualify.
What's ugly about them?
It doesn't pass the test of "would I use it if I didn't think it was faster?"
As I pointed out, your variant is not faster with a reasonable compiler, only less obvious. And none of this sort of optimization will ever be measurably better in the IO path anyway. But every one of these false optimizations is a barrier to the understanding that will allow real cleanups to make fundamental improvements.
Signature · 1 line
Matt Mackall : http://www.selenic.com : of or relating to the moon
Quoted 8 lines · Matt Mackall
Quoted 7 lines
Quoted 4 lines
What's ugly about them?
Quoted 11 lines
It doesn't pass the test of "would I use it if I didn't think it was faster?"
As I pointed out, your variant is not faster with a reasonable compiler, only less obvious. And none of this sort of optimization will ever be measurably better in the IO path anyway. But every one of these false optimizations is a barrier to the understanding that will allow real cleanups to make fundamental improvements.
Agreed, but in this case, it's simply a matter of culture. If some of these things were more common, then they would pass the test, like the use of "!!".
One thing for your side of the argument is that if something works, don't mess with it and risk breaking it, especially if it has no practical impact on performance.
If we really wanted to improve readability, we could start doing something like Windows developers are so fond of doing and use Hungarian Notation. I know it's ugly, and we eschew anything to do with Microsoft, but once you get used to it, it can be very helpful in keeping things straight.