<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
Am 11.10.2011 19:49, schrieb Xueming Shen:
<blockquote cite="mid:4E94818D.2020800@oracle.com" type="cite">
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
<title></title>
<br>
I don't know which one is better, I did a run on <br>
<br>
private static boolean op1(int b) {<br>
return (b >> 6) != -2;<br>
}<br>
private static boolean op2(int b) {<br>
return (b & 0xc0) != 0x80;<br>
}<br>
private static boolean op3(byte b) {<br>
return b >= (byte)0xc0;<br>
}<br>
<br>
with 1000000 iteration on my linux machine, and got the scores<br>
<br>
op1=1149<br>
op2=1147<br>
op3=1146<br>
<br>
I would interpret it as they are identical.<br>
</blockquote>
Me too. thanks for your effort.<br>
Maybe the comparison would differ on different architectures.<br>
<br>
So I would prefer opt3, because the others ...<br>
1. in question need 1 more CPU register to save the original value
of b for later usage<br>
2. need 1 more constant to load into CPU<br>
and opt 3 ...<br>
3. is the best readable source code<br>
4. in question seems best to help Hotspot finding best optimization
on arbitrary architectures.<br>
<br>
Additionally I guess using always byte variables would in question
help HotSpot to optimize with 1-byte-operand CPU instructions.<br>
<br>
Don't you like to replace all "(bx & 0xc0) != 0x80" by
"isNotContinuation(bx)" ?<br>
<br>
-Ulf<br>
<br>
</body>
</html>