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

Register Variables

some say floats can't be stored in register.
size of int and float are same ( on some machine am i Wrong?)
so if int can be delcared as register than why not float(where in and
float are of same size) ?

tx
Ajay
Nov 13 '05 #1
10 15622
dis
"ajay" <aj*************@yahoo.com> wrote in message
news:2a**************************@posting.google.c om...
some say floats can't be stored in register.
You have been misinformed. Some implementations allow for a float object to
be stored in a register.
size of int and float are same ( on some machine am i Wrong?)
sizeof(int) == sizeof(float) can yield either a value of 0 or a value of 1
for a given implementation.
so if int can be delcared as register than why not float(where in and
float are of same size) ?


You have been misinformed. The following is a compliant program:

int main(void)
{
register float pi = 3.0;
return 0;
}

Nov 13 '05 #2
ajay writes:
some say floats can't be stored in register.
size of int and float are same ( on some machine am i Wrong?)
so if int can be delcared as register than why not float(where in and
float are of same size) ?


Since the register keyword is only advice, and not a mandate, to the
compiler there is no need for a register to actually be able to contain the
relevant datum. If a float won't fit, the compiler can simply ignore the
suggestion.
Nov 13 '05 #3
aj*************@yahoo.com (ajay) wrote:
some say floats can't be stored in register.
This is immaterial to C. They certainly can be declared using the
register keyword, but whether that actually results in them being stored
in a register is something the Standard cannot possibly require.
size of int and float are same ( on some machine am i Wrong?)
On some machine, sure. On others they're not.
so if int can be delcared as register than why not float(where in and
float are of same size) ?


_If_ it were true that there is a machine on which int and float are the
same size, and _if_ it were true that on that machine ints could be
stored in registers, and floats couldn't, _then_ a reason could be that
this machine has specialised integer and floating point registers, and
the FP unit only works on doubles.
On the other hand, _if_ there were a machine on which int and float are
widely different sizes, and _if_ on that machine both floats and ints
could be stored in registers, _then_ the reason could be that this
machine, too, has specialised integer and floating point registers, but
its FPU can handle both floats and doubles.

The important thing, though, is that the C language requires neither of
these machines to exist. All it requires is that all objects can be
declared with the register storage class, and (quote from n869.txt):

# [#4] A declaration of an identifier for an object with
# storage-class specifier register suggests that access to the
# object be as fast as possible. The extent to which such
# suggestions are effective is implementation-defined.

IOW, the register keyword is _supposed_ to make the object faster, and
this is _usually_ achieved by putting it in a hardware register, but the
Standard can demand nothing in this respect. Hey, some machines might
not even _have_ registers!

Richard
Nov 13 '05 #4
On Fri, 26 Sep 2003, ajay wrote:
some say floats can't be stored in register.
size of int and float are same ( on some machine am i Wrong?)
so if int can be delcared as register than why not float(where in and
float are of same size) ?


First, when you declare any variable as a register variable it does not
guarantee the variable will be placed in a register. The C standard
indicates:

A declaration of an identifier for an object with
storage-class specifier register suggests that access
to the object be as fast as possible. The extent to
which such suggestions are effective is implementation-
defined.

So there is nothing stopping you from declaring a float as register. The
compiler will take this as a suggestion. If for any reason the float
cannot be placed in a register than the compiler is free to ignore your
suggestion and make it a regular auto variable.

As to the point that float and int are the same size on your machine so
why not put a float in a register. Size is not the only consideration for
putting data in registers. Some operations may not be possible on
variables in registers. If opcodes relating to floating point values only
work on variables in memory then a float will not be placed in a register.
This relates to the microprocessor architecture and not the C standard so
I will not elaborate further. I will suggest you look into microprocessor
design if you want to understand more about this.

--
Send e-mail to: darrell at cs dot toronto dot edu
Don't send e-mail to vi************@whitehouse.gov
Nov 13 '05 #5
Darrell Grainger wrote:
On Fri, 26 Sep 2003, ajay wrote:
some say floats can't be stored in register.
size of int and float are same ( on some machine am i Wrong?)
so if int can be delcared as register than why not float (where
in and float are of same size) ?


First, when you declare any variable as a register variable it
does not guarantee the variable will be placed in a register. The
C standard indicates:

A declaration of an identifier for an object with
storage-class specifier register suggests that access
to the object be as fast as possible. The extent to
which such suggestions are effective is implementation-
defined.

So there is nothing stopping you from declaring a float as
register. The compiler will take this as a suggestion. If for
any reason the float cannot be placed in a register than the
compiler is free to ignore your suggestion and make it a regular
auto variable.


However, once you have declared it as "register" you can no longer
take its address, regardless of what the compiler does with that
suggestion.

--
Chuck F (cb********@yahoo.com) (cb********@worldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!
Nov 13 '05 #6

"ajay" <aj*************@yahoo.com> wrote in message

some say floats can't be stored in register.
That could well be true on your platform. "register" will have no effect on
a float variable.
size of int and float are same ( on some machine am i Wrong?)
Yes. On an old DOS machine int is typically 16 bits, float 32 bits.
so if int can be delcared as register than why not float(where in and
float are of same size) ?

You could physically store the bit pattern of the float in an integer
register, but there might be no "floating-point multiply" or similar
instructions to use with the integer register, so putting a float there
won't speed things up.
Nov 13 '05 #7
"Malcolm" <ma*****@55bank.freeserve.co.uk> writes:
"ajay" <aj*************@yahoo.com> wrote in message

some say floats can't be stored in register.

That could well be true on your platform. "register" will have no effect on
a float variable.

[...]

That may be true on a specific platform, but it's not true in general.
On the hardware level, almost all platforms that have data registers
at all are able to store floats in registers (possibly in specialized
floating-point registers). A compiler may or may not take advantage
of this; for example, if there are only enough floating-point
registers for expression evaluation, it may not make sense to dedicate
one of them to hold a particular variable.

Others have correctly pointed out that "register" may or may not be
honored by the compiler, even for int variables.

But one thing that's not optional is that you can't take the address
of a "register" variable. A compiler may be able to take advantage of
that guarantee to perform some extra optimizations, even if the
variable is stored in memory.

--
Keith Thompson (The_Other_Keith) ks*@cts.com <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://www.sdsc.edu/~kst>
Schroedinger does Shakespeare: "To be *and* not to be"
Nov 13 '05 #8
Keith Thompson wrote:

"Malcolm" <ma*****@55bank.freeserve.co.uk> writes:
"ajay" <aj*************@yahoo.com> wrote in message

some say floats can't be stored in register.

That could well be true on your platform. "register" will have no effect on
a float variable.

[...]

That may be true on a specific platform, but it's not true in general.
On the hardware level, almost all platforms that have data registers
at all are able to store floats in registers (possibly in specialized
floating-point registers). A compiler may or may not take advantage
of this; for example, if there are only enough floating-point
registers for expression evaluation, it may not make sense to dedicate
one of them to hold a particular variable.

Others have correctly pointed out that "register" may or may not be
honored by the compiler, even for int variables.


My experience has been that with high levels of optimization, is that
'register' is either ignored or my use of it trips up the optimizer.
So I've stopped using it for general coding, only trying it when I'm
trying to get better performance out of a piece of code. But even
then, the optimizer either usually out does me (or outsmarts me).

My experience is weak in the x86 arena, so some folks may have seen
different. On the SUN I'm currently using, there's so many f.p.
registers that you don't have to worry about it.
Nov 13 '05 #9
My experience has been that with high levels of optimization, is that
'register' is either ignored or my use of it trips up the optimizer.
So I've stopped using it for general coding, only trying it when I'm
trying to get better performance out of a piece of code. But even
then, the optimizer either usually out does me (or outsmarts me).

My experience is weak in the x86 arena, so some folks may have seen
different. On the SUN I'm currently using, there's so many f.p.
registers that you don't have to worry about it.


So you're using SPARC then. Scott McNealy's toy.

Bill

-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Nov 13 '05 #10
On Mon, 29 Sep 2003 18:36:49 -0400, in comp.lang.c you
wrote:
My experience has been that with high levels of optimization, is that
'register' is either ignored or my use of it trips up the optimizer.
So I've stopped using it for general coding, only trying it when I'm
trying to get better performance out of a piece of code. But even
then, the optimizer either usually out does me (or outsmarts me).

My experience is weak in the x86 arena, so some folks may have seen
different. On the SUN I'm currently using, there's so many f.p.
registers that you don't have to worry about it.


So you're using SPARC then. Scott McNealy's toy.


What sort of a troll are you?



Nov 13 '05 #11

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

Similar topics

16
by: junky_fellow | last post by:
what is the purpose of declaring a register variable ? why can't we find the address of register variable ?
7
by: int main(void) | last post by:
Hi all, I know that register variables work fine at block scope. I tried putting a register variable in file scope, like this, #include <stdio.h> register int a = 2; int main(void) {...
28
by: sowmiyakc18 | last post by:
Please clear my doubt. When do we declare a variable to be a register variable? What is its significance? What are the conditions to be adhered to when register variables are passed between...
26
by: Vashna | last post by:
Hi Group, I have a doubt about register variables. I know that if we have a variable used very frequently in a function, then provided we never apply the & function to it, we can define it as...
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.