473,396 Members | 1,892 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,396 software developers and data experts.

gcc -O3 variable uninitialization problem


Below is a piece of bit manipulation code. here in function
"eval_output_out" there are some macros.
Say we have to versions of the same code
1. variable "b" in "eval_output_out" is initialized
2. variable "b" in "eval_output_out" is NOT initialized
code expands such that it is independent of past value of variable
"b", i dumped pre processed output of two versions and there was just
one difference of b initialized in one and not in other.

QUERY IS : why version 1 runs faster than 2 with -O3 option of gcc.

if i just dump the assmebly of two versions using "gcc -S" behavior is
expected which is version #1 (with initialization) has one extra
instruction to initialize variable.
But when i dump the assembly of two versions with "gcc -O3 -S"
assembly of version 2 (without initialization) takes 4 extra
instruction.

can somebody please explain me why is this happening.??
ASSEMBLY OF VERSION #1 [ WITH INITIALIZATION]
------------------------------------------------
..globl eval_output_out
.type eval_output_out,@function
eval_output_out:
pushl %ebp
movl width_masks+4, %edx
movl %esp, %ebp
movl 8(%ebp), %eax
movl %edx, %ecx
notl %edx
andl 4(%eax), %edx
andl (%eax), %ecx
movl %edx, 4(%eax)
sall $2, %ecx
andl width_masks+4, %ecx
orl %ecx, %edx
movl %edx, 4(%eax)
leave
ret
ASSEMBLY OF VERSION #2 [ WITH INITIALIZATION]
------------------------------------------------
..globl eval_output_out
.type eval_output_out,@function
eval_output_out:
movl width_masks+4, %edx
pushl %ebp
leal 0(,%edx,4), %eax
movl %esp, %ebp
notl %eax
pushl %ebx
movl 8(%ebp), %ecx
andl %eax, %ebx
movl %edx, %eax
andl (%ecx), %eax
notl %edx
andl 4(%ecx), %edx
sall $2, %eax
movl %edx, 4(%ecx)
orl %eax, %ebx
andl width_masks+4, %ebx
orl %ebx, %edx
movl %edx, 4(%ecx)
movl (%esp), %ebx
leave
ret

SOURCE CODE
------------------------------------

static unsigned int width_masks[32] = {0x1,0x3,0x7,0xF,0x1F,0x3F,0x7F,
0xFF,0x1FF,0x3FF,0x7FF,0xFFF,0x1FFF,0x3FFF,0x7FFF, 0xFFFF,0x1FFFF,
0x3FFFF,0x7FFFF,0xFFFFF,0x1FFFFF,0x3FFFFF,0x7FFFFF ,0xFFFFFF,0x1FFFFFF,
0x3FFFFFF,0x7FFFFFF,0xFFFFFFF,0x1FFFFFFF,0x3FFFFFF F,0x7FFFFFFF,
0xFFFFFFFF};
typedef struct _top_test_model{
unsigned int inputs[1];
unsigned int outputs[1];
}top_test_model;

#define LOGICAL_RIGHT_SHIFT(x,y) (((y) >= 32)?0x0:(x)>>(y))
#define get_arr_var_bits(reg_int, lsb_row, lsb_col, width)
(LOGICAL_RIGHT_SHIFT(((width_masks[width-1] << lsb_col) &
reg_int[lsb_row]),(lsb_col)))
#define reset_arr_var_bits(reg_int, lsb_row, lsb_col, width)
(reg_int[lsb_row] &= ~(width_masks[width-1] << (lsb_col)))
#define set_arr_var_bits(reg_int, lsb_row, lsb_col, width, val)
(reg_int[lsb_row] = reset_arr_var_bits(reg_int, lsb_row, lsb_col,
width) | ((val) << (lsb_col)))
#define get_var_bits(reg_int, lsb_col, width)
(LOGICAL_RIGHT_SHIFT(((width_masks[width-1] << (lsb_col)) &
(reg_int)), (lsb_col)))
#define rst_bits(reg_int, lsb_col, width) ((reg_int) &=
~(width_masks[width-1] << (lsb_col)))
#define set_var_bits(reg_int, lsb_col, width, val) (reg_int =
(rst_bits(reg_int, lsb_col, width)) | ((val) << (lsb_col)))
void eval_output_out(top_test_model *model){
unsigned int b;

/* take 2 bits starting from bit position 0 from variable model-
>inputs[0] and set them in 2 bits in variable "b"
starting from bit position from 2*/
set_var_bits(b,2,2,get_arr_var_bits(model->inputs,0,0,2));

/* take 2 bits starting from bit position 0 from variable b and set
them in 2 bits in model->outputs[0]
starting from bit position 0 */
set_arr_var_bits(model->outputs,0,0,2,get_var_bits(b,0,2));
}
int main (int argc, char *argv){
top_test_model t;
eval_output_out(&t);
}

Aug 1 '08 #1
2 2185
On Aug 1, 3:30*pm, sh.vi...@gmail.com wrote:
QUERY IS : why version 1 runs faster than 2 with -O3 option of gcc.
Your question is GCC-specific, so you should post on a GCC-related
newsgroup. This one deals with the C++ language itself, not particular
compilers. See this FAQ for some ideas of where you might post:

http://www.parashift.com/c++-faq-lit...t.html#faq-5.9

Cheers! --M
Aug 1 '08 #2
On Aug 1, 12:30*pm, sh.vi...@gmail.com wrote:
>[redacted]
As mlimber said, you're OT here.

The group you want is gnu.g++.help
Aug 1 '08 #3

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

Similar topics

1
by: Nick Whitelegg | last post by:
Hello, I'm having an odd problem with combining an authentication session variable with header() redirection. Basically I have an authentication script which checks a username/password. If the...
134
by: James A. Donald | last post by:
I am contemplating getting into Python, which is used by engineers I admire - google and Bram Cohen, but was horrified to read "no variable or argument declarations are necessary." Surely that...
166
by: Graham | last post by:
This has to do with class variables and instances variables. Given the following: <code> class _class: var = 0 #rest of the class
9
by: Pyenos | last post by:
Approach 1: class Class1: class Class2: def __init__(self):self.variable="variable" class Class3: def method():print Class1().Class2().variable #problem Approach 1.1:
0
by: zman77 | last post by:
EDIT: -- forgot to mention... I am using Visual Studio 2005, on Win XP, on an intel machine Hi. This is my first post, though I've "lurked" for a while because I find these forums very helpful....
10
by: Mason Barge | last post by:
I have a standard POST form consisting of two types of input: text input and textarea. The form downloads current settings from a mysql database. The user can update the information by modifying...
1
NeoPa
by: NeoPa | last post by:
Problem Description : In VBA there is an option to enforce declaration of variables in your code. With this set, any reference to a variable that has not been previously declared (Dim; Private;...
20
by: teddysnips | last post by:
Weird. I have taken over responsibility for a legacy application, Access 2k3, split FE/BE. The client has reported a problem and I'm investigating. I didn't write the application. The...
3
Atli
by: Atli | last post by:
Hi everybody. This is not so much a problem, since I have already managed to find a solution, but my solution requires the use of the eval() function, which I just hate to use. The problem is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.