473,569 Members | 2,526 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

register

hi everyone, i'm wondering if there is a way to have sure that a
variable is allocated in the cache, after its declaration with
"register"? Tks!

Nov 15 '05 #1
29 2449
>hi everyone, i'm wondering if there is a way to have sure that a
variable is allocated in the cache, after its declaration with
"register"? Tks!


On all processors I have ever heard of with a cache, actual CPU
registers are never part of the cache. Actual CPU registers
are normally much faster than the cache.

You can never be sure that the keyword 'register' will affect
the code at all. And if you use it enough, you *WILL* run out
of actual CPU registers. If you could force a variable into a
CPU register, it might slow down the code because the register
might be better used as an invisible temporary. The compiler
is often smarter than you are.

Gordon L. Burditt
Nov 15 '05 #2
On 2005-11-09, Gordon Burditt <go***********@ burditt.org> wrote:
hi everyone, i'm wondering if there is a way to have sure that a
variable is allocated in the cache, after its declaration with
"register"? Tks!


On all processors I have ever heard of with a cache, actual CPU
registers are never part of the cache. Actual CPU registers
are normally much faster than the cache.

You can never be sure that the keyword 'register' will affect
the code at all. And if you use it enough, you *WILL* run out
of actual CPU registers. If you could force a variable into a
CPU register, it might slow down the code because the register
might be better used as an invisible temporary. The compiler
is often smarter than you are.


The compiler also isn't required to listen to you. All "register" means
is that the compiler is free to not give the variable an address. This
could otherwise be determined by code analysis, i'm sure, but a keyword
is simpler.
Nov 15 '05 #3
In article <11************ *********@z14g2 000cwz.googlegr oups.com>,
<or*****@gmail. com> wrote:
hi everyone, i'm wondering if there is a way to have sure that a
variable is allocated in the cache, after its declaration with
"register"? Tks!


The answers you will get will all boil down to "You can't know and you
shouldn't want to know."

However, the bottom line is: Invoke the compiler with an option that causes
it to output assembly (e.g., "gcc -S") and then look at the generated
assembly. You should be able to figure out what it did with your
"register" directive.

Nov 15 '05 #4
On Wed, 09 Nov 2005 20:10:12 GMT, in comp.lang.c ,
ga*****@yin.int eraccess.com (Kenny McCormack) wrote:
In article <11************ *********@z14g2 000cwz.googlegr oups.com>,
<or*****@gmail. com> wrote:
hi everyone, i'm wondering if there is a way to have sure that a
variable is allocated in the cache, after its declaration with
"register"? Tks!
The answers you will get will all boil down to "You can't know and you
shouldn't want to know."

However, the bottom line is: Invoke the compiler with an option that causes
it to output assembly (e.g., "gcc -S") and then look at the generated
assembly. You should be able to figure out what it did with your
"register" directive.


This won't tell you a thing about how the CPU will use the cache at
runtime. Never mind that if its in a register, it cannot be in a
cache...

In fact, this is a classic example of why answering offtopic questions
here is a bad idea.
--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt >

----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Nov 15 '05 #5
"Jordan Abel" <jm****@purdue. edu> wrote in message
news:sl******** ***********@ran dom.yi.org...
[snip]
The compiler also isn't required to listen to you. All "register" means
is that the compiler is free to not give the variable an address.
I would say all it means is that you cannot take the address of the object.
What you wrote follows from that fact.
This could otherwise be determined by code analysis, i'm sure, but a
keyword is simpler.


These days, such analysis (and then some) is certainly practical, but
presumably it wasn't always that way, and that is why the keyword exists.

Alex
Nov 15 '05 #6
Jordan Abel <jm****@purdue. edu> writes:
On 2005-11-09, Gordon Burditt <go***********@ burditt.org> wrote:
hi everyone, i'm wondering if there is a way to have sure that a
variable is allocated in the cache, after its declaration with
"register" ? Tks!


On all processors I have ever heard of with a cache, actual CPU
registers are never part of the cache. Actual CPU registers
are normally much faster than the cache.

You can never be sure that the keyword 'register' will affect
the code at all. And if you use it enough, you *WILL* run out
of actual CPU registers. If you could force a variable into a
CPU register, it might slow down the code because the register
might be better used as an invisible temporary. The compiler
is often smarter than you are.


The compiler also isn't required to listen to you. All "register" means
is that the compiler is free to not give the variable an address. This
could otherwise be determined by code analysis, i'm sure, but a keyword
is simpler.


Here's what the standard says, C99 6.7.1p4:

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.

with a footnote:

The implementation may treat any register declaration simply as an
auto declaration. However, whether or not addressable storage is
actually used, the address of any part of an object declared with
storage-class specifier register cannot be computed, either
explicitly (by use of the unary & operator as discussed in
6.5.3.2) or implicitly (by converting an array name to a pointer
as discussed in 6.3.2.1). Thus, the only operator that can be
applied to an array declared with storage-class specifier register
is sizeof.

6.5.4.2 says you can't apply unary "&" to a register-qualified object.
6.3.2.1 says that the implicit conversion of an array expression to a
pointer to its first element invokes undefined behavior if the
designated array object has register storage class. (I'm not sure why
it's undefined behavior rather than a constraint violation.)n

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 15 '05 #7
In article <mb************ *************** *****@4ax.com>,
Mark McIntyre <ma**********@s pamcop.net> wrote:
....
This won't tell you a thing about how the CPU will use the cache at
runtime. Never mind that if its in a register, it cannot be in a
cache...
You're being needlessly pedantic - and, might I add, definitely not PC.
I think we can assume that the OP meant "CPU register" when he said
"cache". Remember, these dorks use terminology very loosely and generally
just repeat words they've overheard.
In fact, this is a classic example of why answering offtopic questions
here is a bad idea.


Sez you.

Nov 15 '05 #8
ga*****@yin.int eraccess.com (Kenny McCormack) writes:
In article <mb************ *************** *****@4ax.com>,
Mark McIntyre <ma**********@s pamcop.net> wrote:
...
This won't tell you a thing about how the CPU will use the cache at
runtime. Never mind that if its in a register, it cannot be in a
cache...


You're being needlessly pedantic - and, might I add, definitely not PC.
I think we can assume that the OP meant "CPU register" when he said
"cache".


Perhaps, but I don't think we *need* to assume any such thing. It's
likely that the OP didn't understand what registers and cache really
are. If he's been following this thread, he should now have a much
better understanding of the terms.

(The term "cache" as a generic term is applicable to registers, but in
this context it more commonly refers to something else.)

I suppose we could have guessed what he meant by the term "cache" and
pretended his usage was correct. Then we could have fooled him into
thinking that he was getting a real answer to his question, something
like "Just use the register keyword, it guarantees that the variable
will be stored in cache."

But most of us are more interested in passing on knowledge than in
playing stupid games like that.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 15 '05 #9
Keith Thompson wrote:

ga*****@yin.int eraccess.com (Kenny McCormack) writes: But most of us are more interested in passing on knowledge than in
playing stupid games like that.


But Kenny isn't.

http://www.codecomments.com/Unix_Pro...age665290.html

<OT>
Poor Kenny. The people in comp.lang.c aren't amenable to redefining
the purpose of the newsgroup to suit him. One wonders why he continues
to hang around there ;-)
</OT>
I stick around, read, and post, for the same reasons I do in
any other joke newsgroup - because it is so much fun.

--
pete
Nov 15 '05 #10

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

Similar topics

1
14131
by: G Kannan | last post by:
Hey all! I have written a perl script to retrieve information from a HTML Form and insert the data into an Oracle database table. I am gettting the the following error message: "Use of uninitialized value in concatenation (.) at register.pl line 38, <STDIN> line 10." The PERL code is as follows:
12
2222
by: Ioannis Vranos | last post by:
Just some thought on it, wanting to see any explanations. It was advised in this newsgroups that we should avoid the use of keyword register. However it is a language feature, and if it offers no help to an implementation, it is free to ignore it. And this happens widely, all my C++ compilers in my platform ignore this keyword.
3
2246
by: Alex | last post by:
I apoligise in advance if this is an os or platform based question, I don't know. I was wondering how register integers (and other types of register variables) are managed by c++. For example, on a pentium 4, there are 8 register integers in the cpu. If you define more than 8, or if there are other programs using this space, how are the...
14
7895
by: aruna | last post by:
What is the disadvantage of using register storage class specifier?
9
8595
by: Jackie | last post by:
Hi everyone, Does anyone know when "register" declarations should be used and when "register" must not be used? If possible please give examples for both cases. Thanks
33
3251
by: Snis Pilbor | last post by:
With the "as if" rule in play, doesn't that effectively render the "register" keyword completely useless? Example: I make a silly compiler which creates code that goes out of its way to take a full 10 minutes every time a "register" declared variable is read from or written to. Besides this lag, everything else runs as expected. Then my...
5
1886
by: prouleau001 | last post by:
Hi all! Since that the decorator syntax is upon us, I think it would be good if atexit.register() was returning the function passed as argument. This simple change to the library would solve a problem with the use of atexit.register as a decorator (and I can't think of any use case where this change would break any code). I describe the...
26
2197
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 a register variable and this will make it much faster to access. Now the question is: obviously there are only a fixed number of registers in our...
21
6312
by: JOYCE | last post by:
Look the subject,that's my problem! I hope someone can help me, thanks
0
7614
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8125
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7676
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7974
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6284
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5513
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3642
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2114
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
938
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.