• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Nicholas Kong

Regarding CPU cache and RAM and Main memory

14 posts in this topic

Why does cache on CPU require both data and address of program's instruction?

 

Why does loading an instruction from a program sequential require RAM or main memory?

 

It seems every a load instruction takes place it consume main memory but I am not sure why.

 

I know the facts. But I do not know the reasons for why the facts hold.

2

Share this post


Link to post
Share on other sites
1) It needs the data to decode the instruction. It needs the address to figure out which instruction is next.

2) A program is stored in RAM.

3) I have no clue what you mean by a load consuming memory.
1

Share this post


Link to post
Share on other sites

1) It needs the data to decode the instruction. It needs the address to figure out which instruction is next.2) A program is stored in RAM.3) I have no clue what you mean by a load consuming memory.


I mean the load operation the one that has 5 steps: fetch encode execute memory read. The load operation requires RAM in order to operate right?
0

Share this post


Link to post
Share on other sites

I don't know if it speaks directly to your questions, but there seems to be some confusion about the relationship between cache, RAM, and main memory.

 

Conceptually, your program only knows about address space -- that address space might be mapped to the RAM modules installed in your computer, it might be mapped to memory or registers on a peripheral device (like a graphics card), or it might be mapped to virtual memory that's currently swapped out to sectors on your hard disk drive.

 

Cache isn't separate, it just mirrors the contents of the address space in a small amount of fast memory that's closer to the CPU itself (on the CPU silicon, even). Caches aren't magic, all they do is operate on the principle that if you access word 0x0FFFFF04, you're more likely to access 0x0FFFFF08 soon than any other memory. When you read just one byte from the address space, it isn't just one byte that comes back -- to the CPU, you only see the byte you asked for, but the data path between the cache and RAM is an entire cache-line wide (usually 32 bytes or more, IIRC) and it all goes into the cache -- so when you ask for the next byte, you don't walk all the way out to main memory and back, you just walk to the cache and back. Of course, the cache is smaller than the address space, so eventually it gets full and you need to start over-writing what's in the cache. There's different structures and ways a cache can work, but that's the basic principle of it. All of its automatic and you don't usually have to worry about it. All you really need to care about, if memory bandwidth or latency begins to bottleneck your application, is arranging your data structures in such a way that memory that gets used together in next to each other (that oversimplifies a bit, but is the basic idea) so that its all in the cache at the same time.

0

Share this post


Link to post
Share on other sites


It needs the address to figure out which instruction is next.

 

I thought that was the job of PC(Program Counter)

0

Share this post


Link to post
Share on other sites

 

1) It needs the data to decode the instruction. It needs the address to figure out which instruction is next.2) A program is stored in RAM.3) I have no clue what you mean by a load consuming memory.


I mean the load operation the one that has 5 steps: fetch encode execute memory read. The load operation requires RAM in order to operate right?

 

In case the steps of executing an instruction are the part that is confusing you, the steps are based on the most complex instruction's needs and all instructions use the same steps. This is because the CPU is pipelined, so one instruction is executing its fetch while another instruction is executing its encode, etc.

Fetch is just getting the instruction (from cache, or RAM if not in cache, or generating a fault that results in a page load from disk if not in RAM).

Encode (usually referred to as decode) is decoding the instruction so the CPU knows what to do and assigning the registers that will get used.

Execute is where math and such happens, perhaps calculating the full address from an offset for a load operation.

Memory is where reads and writes to memory occur (again, from cache when possible, RAM if not in cache, etc.). This is where the actual loading of data from memory (RAM) into a register happens.

Read I assume is supposed to be write-back. There is no reading that occurs at that point, it's just saving the virtual registers back to the physical register file. I don't think this stage even exists on CPUs that lack register renaming.

 

It's worth noting that loading a constant (when such instructions exist) does not require data loaded from RAM as the constant is encoded in the instruction. So the "memory" stage of the pipeline would be a noop when loading a constant.

0

Share this post


Link to post
Share on other sites


First off, you've asked a lot of hardware questions and mostly they've been for personal learning, but if I find out it is for homework I'll hunt you down. :-)

 

I am not sure if hardware questions are allowed in the programming section. I only post these questions because the knowledge of what goes underneath the hood of a computer might benefit me as a programmer and a self taught game programmer. It is not for homework but more to fill the gaps of what I am not sure of or have doubts about. I am taking a Computer Architecture class and these questions came up when I was typing up the notes for this class.

0

Share this post


Link to post
Share on other sites

I'll just say: Don't get discouraged if you get downvotes for your questions, its okay to ask things.

 

Think of it as trading reputation points for knowledge :D

1

Share this post


Link to post
Share on other sites

I'll just say: Don't get discouraged if you get downvotes for your questions, its okay to ask things.

 

Think of it as trading reputation points for knowledge biggrin.png

 

Its sad but true, I find Gamedev to be a rather hostile forum.

1

Share this post


Link to post
Share on other sites

I'll just say: Don't get discouraged if you get downvotes for your questions, its okay to ask things.
 
Think of it as trading reputation points for knowledge :D


One of the funniest statements I have read on this forum.
0

Share this post


Link to post
Share on other sites


Its sad but true, I find Gamedev to be a rather hostile forum.

 

I don't think its overly hostile unless you ask overtly silly questions, or take a wrong-headed opinion and really stick to your guns. I do think people are unfairly down-voted on occasion, and when I see people in the negative for it I take a look through the thread, and at the post and if they don't seem to be in the wrong I'm happy to upvote even if they're incorrect about something.

 

People can make honest mistakes or be genuinely confused and shouldn't fear being punished for it. And there does seem to be a piling-on effect that's really not helpful or productive.

 

But I think the system mostly works -- Its pretty rare that I downvote anyone. When I do they're objectively wrong and unwilling to admit it, or rude. I also tend to follow an axiom that I don't downvote unless I or someone else has/can correct the information. It seems unfair to downvote without letting its target know why, or how they're wrong.

1

Share this post


Link to post
Share on other sites

It needs the address to figure out which instruction is next.

 
I thought that was the job of PC(Program Counter)

The program counter is the address of the instruction.

1) It needs the data to decode the instruction. It needs the address to figure out which instruction is next.2) A program is stored in RAM.3) I have no clue what you mean by a load consuming memory.


I mean the load operation the one that has 5 steps: fetch encode execute memory read. The load operation requires RAM in order to operate right?

Of course it does; it's job is to load data from memory. Edited by King Mir
0

Share this post


Link to post
Share on other sites


Of course it does; it's job is to load data from memory.

 

Oh I get it now! Thanks for clearing up my doubt with all the questions. Everyone else did a great job too.

0

Share this post


Link to post
Share on other sites

Its sad but true, I find Gamedev to be a rather hostile forum.

 
I don't think its overly hostile unless you ask overtly silly questions, or take a wrong-headed opinion and really stick to your guns. I do think people are unfairly down-voted on occasion, and when I see people in the negative for it I take a look through the thread, and at the post and if they don't seem to be in the wrong I'm happy to upvote even if they're incorrect about something.
 
People can make honest mistakes or be genuinely confused and shouldn't fear being punished for it. And there does seem to be a piling-on effect that's really not helpful or productive.
 
But I think the system mostly works -- Its pretty rare that I downvote anyone. When I do they're objectively wrong and unwilling to admit it, or rude. I also tend to follow an axiom that I don't downvote unless I or someone else has/can correct the information. It seems unfair to downvote without letting its target know why, or how they're wrong.

 
I wish that were true, my experience has been the complete opposite.  For example I got down-voted on this post: http://www.gamedev.net/topic/653308-how-alive-is-oop/#entry5130883.  I didn't insult or denigrate anyone.  Every contentious statement I prepositioned with 'I feel' or 'I personally think'.  No one in subsequent posts even addressed the issues I mentioned.  But just stating the opinion that 'C++ isn't a true OOP language' is enough.  In my university days these are the things I'd have long debates about with my colleagues.  Is encapsulation sufficient for OOP or is inheritance a requirement?  There are legitimate arguments on both sides, and it can be a very interesting discussion.  But that back-n-forth can never happen on GameDev.  Its why I like the TigSource.com forums.  They're certainly less knowledgeable, but far more accommodating to differing opinions and ideas.
 
That's just a minor, albeit recent, example.  There are many more egregious situations that have occurred in the past.  TBH, I don't really care about the ranking.  I've learned long ago to tread cautiously in GameDev, and to never express an opinion.  Its just sad IMHO that that's the way it is.
 
I'll leave it at that, this has become quite tangential to the OP... Edited by Ryan_001
1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0