473,326 Members | 2,113 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Bad enough to be a bug

PLS
I'm amazed at the following generated code.

The environment is:
VS2005 SP1
Debug mode

Declarations
bool different;
fileVersion and MSGFILEVERSION are unsigned int

different = different || header.fileVersion != MSGFILEVERSION;
00672244 movzx eax,byte ptr [different]
0067224B test eax,eax
0067224D jne 00672264
0067224F cmp dword ptr [header],67h
00672256 jne 00672264
00672258 mov dword ptr [ebp-89Ch],0
00672262 jmp 0067226E
00672264 mov dword ptr [ebp-89Ch],1
0067226E mov ecx,dword ptr [ebp-89Ch]
00672274 call @ILT+11940(@_RTC_Check_4_to_1@4) (560EA9h)
00672279 mov byte ptr [different],al

The generated code developes a one byte bool value by storing into a 32
bit int temporary. The value can only be 0 or 1. It then goes through a
truncation check before storing the one byte value into a one byte
boolean variable. Awful.

++PLS
May 11 '07 #1
4 1101
In article <MP************************@msnews.microsoft.com >,
PLS <no****@nowhere.comwrote:
>I'm amazed at the following generated code.
Debug or optimized? If it's debug, the codegen is usually "awful,"
but that's in order to make it easier to debug it. What optimization
settings are you at?

Nathan Mates
--
<*Nathan Mates - personal webpage http://www.visi.com/~nathan/
# Programmer at Pandemic Studios -- http://www.pandemicstudios.com/
# NOT speaking for Pandemic Studios. "Care not what the neighbors
# think. What are the facts, and to how many decimal places?" -R.A. Heinlein
May 11 '07 #2
Nathan Mates wrote:
In article <MP************************@msnews.microsoft.com >,
PLS <no****@nowhere.comwrote:
>I'm amazed at the following generated code.

Debug or optimized? If it's debug, the codegen is usually "awful,"
but that's in order to make it easier to debug it. What optimization
settings are you at?
The OP indicated that this was a debug build. For a debug build, the code
is not optimized at all but is, as you point out, intended to be easy for
the debugger to understand. Another consideration is the penalty that you
pay on modern CPUs for doing byte-sized operations - it can be 4x (or more)
slower to do a byte operation than an entire 32-bit word, so the code isn't
as awful as the OP suggests.

-cd
May 11 '07 #3
"Carl Daniel [VC++ MVP]" <cp*****************************@mvps.org.nospam >
wrote in message news:%2****************@TK2MSFTNGP03.phx.gbl...
>In article <MP************************@msnews.microsoft.com >,
PLS <no****@nowhere.comwrote:
>>I'm amazed at the following generated code.

For a debug build, the code is not optimized at all but is, as you point
out, intended to be easy for the debugger to understand. Another
consideration is the penalty that you pay on modern CPUs for doing
byte-sized operations - it can be 4x (or more) slower to do a byte
operation than an entire 32-bit word, so the code isn't as awful as the OP
suggests.
And what's the penalty for the part that the OP said he/she was amazed by?
00672274 call @ILT+11940(@_RTC_Check_4_to_1@4) (560EA9h)

Even in a debug build, the compiler knew that the possible values 0 or 1
don't need a subroutine call to figure out if they fit in a byte.

May 14 '07 #4
Norman Diamond wrote:
"Carl Daniel [VC++ MVP]"
<cp*****************************@mvps.org.nospamwr ote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
>>In article <MP************************@msnews.microsoft.com >,
PLS <no****@nowhere.comwrote:
I'm amazed at the following generated code.

For a debug build, the code is not optimized at all but is, as you
point out, intended to be easy for the debugger to understand. Another
consideration is the penalty that you pay on modern CPUs for
doing byte-sized operations - it can be 4x (or more) slower to do a
byte operation than an entire 32-bit word, so the code isn't as
awful as the OP suggests.

And what's the penalty for the part that the OP said he/she was
amazed by? 00672274 call @ILT+11940(@_RTC_Check_4_to_1@4)
(560EA9h)
Even in a debug build, the compiler knew that the possible values 0
or 1 don't need a subroutine call to figure out if they fit in a byte.
Compile time. A tiny amount. Really tiny. Granted, it does seem like
something the compiler could have easily omitted even in a debug build.

-cd
May 14 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: opt_inf_env | last post by:
Hello, I have a page such that each user can see only a corresponding (personal) part of the page. In the beginning I wanted to perform initialization of users (by asking there names and...
12
by: GraphicsMark | last post by:
Opinions needed - is VB.net good enough to create a proper vector drawing program with some bitmap processing, i.e. does it have a rich enough feature set, and do the compiled programs run fast...
123
by: C# Learner | last post by:
I've had enough of C#. I've had enough of using parentheses for every 'if' statement. I've had enough of having to mix assignment of return value of methods with flow control, making writing code...
0
by: Simon | last post by:
I've had enough of C# Learner. I've had enough of his complaining about using parentheses for every 'if' statement. I've had enough of his complaining about having to mix assignment of return...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.