C++ :: Bit Shifting - Cache Simulator

Apr 18, 2013

I'm attempting to make a cache simulator in C++. But I need to access individual bits in an integer to figure out where in my "cache" the writing actually gets done. I'm pretty new to bit shifting. Say I'm trying to access the the bits of the int 5, which are its "address". I'm simulating a direct mapped cache. I need to find its tag, the set it goes into, and which line. How do I use bit shifting to access the bits to acquire the tag, the index bits, offset bits, block number...all these pieces in order to actually find where I store it in the cache.

View 6 Replies


ADVERTISEMENT

C :: Cache Simulator - Bit Shifting

Apr 21, 2013

I'm attempting to make a cache simulator in C++. But I need to access individual bits in an integer to figure out where in my "cache" the writing actually gets done. I'm pretty new to bit shifting. Say I'm trying to access the the bits of the int 5, which are its "address". I'm simulating a direct mapped cache. I need to find its tag, the set it goes into, and which line. How do I use bit shifting to access the bits to aquire the tag, the index bits, offset bits, block number...all these pieces in order to actually find where I store it in the cache. I need to break the bits up into 3 sections: tag, set index, and block index. I think I can figure out the set and block index sizes based on the values passed in. The tag bits are just the remaining ones. And I'm hard coding values such as cache size (C) - 1024, number of physical address bits (m) - 32, block size (B) - 2, number of lines per set (E) - 1 (again, directly mapped cache). How would this look? I'll be using unsigned longs, so it can handle up to 64 bits.

View 3 Replies View Related

C++ :: Using Vectors For A Clip / Cache

Apr 19, 2013

I'm trying to make it like a game. You would fire your gun, then have the option of reloading. If you run out of ammo and try to fire...it will automatically come out of your cache. Anyone who played a 3rd or first person shooter knows what I mean. I thought vectors would be the best course of actions since they can remove and add elements with ease. One of the many problems I have is subtracting the Hand Guns current ammo (size) from its maximum (capacity) to see how much to A. push_back into the clip and B. pop_back out of the cache. Can size() and capacity even be subtracted? Here's the code with what I believe to be all the possibilities.

#include<iostream>
#include<vector>
using namespace std;
int main(int argc,char** argv) {
vector<int> HG_cache (36,1);
vector<int> HG_clip (12,1);
char user_input;

[code]....

View 1 Replies View Related

C :: Cache Optimizations / Make Multiplication And Calculations Faster?

Jan 30, 2014

I have a 125X125 array, each element is 55 bits. The cache line for the CPU ( Cortex A9) is 32 bits. Is there anyway to do optimizations, like loop tiling that would make multiplication and calculations faster?

View 5 Replies View Related

C++ :: Shifting Bits Away And Back

Mar 25, 2014

Value x is a 32-bit unsigned integer 3:

00000000000000000000000000000011

If we use bitwise-shift to shift all bits to the right by 2, x is 0:

00000000000000000000000000000000

If we then do a bitwise leftshift on x by 30, do we end up with:

11000000000000000000000000000000
or
00000000000000000000000000000000

In other words, when we perform right shift which clips away the least most significant bits, and then do a left shift, is it possible for those bits to reappear?

View 2 Replies View Related

C/C++ :: Shifting Elements In Array?

Jan 2, 2015

Let's say I have an array of 10 elements. I want user to enter 9 numbers so that they fill arrays 0 to 8 (9 numbers). Now I shift the arrays +1. so array[0] is now array[1] and so on. Now I ask user to enter 10th number (fills array 0).

Here's my code(it doesn't shift arrays and doesn't ask for 10th num)

#include <stdio.h>
int main() {
int a[10];
int i;

[code]....

View 4 Replies View Related

C :: Shifting Elements In 2 Dimensional Array

Feb 28, 2013

I am inserting elements from two files into 2-D arrays.Suppose I have generated this kind of code to create 2-D array:

Code:

main() {
int counter;
int divide=5, m1=0, l1=20, window=20;
for(counter=0;counter<divide;counter++){
for(i=m1,j=0;i<l1;i++,j++){
}

[code]....

Now after generating 2D array, if I want to shift last 2 elements from windata[counter] or winquery[counter] where counter=0 to the beginning of counter 1 and subsequently last two from counter 1 to counter 2 in this fashion, how can I do that.

View 4 Replies View Related

C++ :: Pointers / Binary Data And Shifting

Sep 15, 2014

unsigned short foo = 1337;
//since unsigned short is 2 bytes, a char x[2]should be enough to hold the binary data
char foo2[2];

How do I have foo2, contain the binary equivalent of foo? (how can I point foo2 to = &foo)

View 4 Replies View Related

C++ :: Signal Or Array Or Vector Shifting?

Dec 6, 2013

This can be done very easy, but I assume there is a better way to do it.

assume that I have a vector or a signal like

x=[1 1 1 1 1]

want to shift it by one unit to the right I have

x[n+1] gives

xn=[0 1 1 1 1 1]

and x[n-1] vies

xn=[1 1 1 1 0]

as you can see the length of the original vector or array does not change.

How can I solve this problem without specify the length of the output vector. The size of the output array should be the same as the input array, but I couldn't find a way to do it without adjusting the size.

View 2 Replies View Related

C++ :: Gravity Simulator Implementation

Jul 9, 2013

I've been working on creating a simulator to crash two galaxies together as part of a project to stress test a CUDA super computer. I've got a long way to go and am currently just working on correctly simulating n-body gravity functions. First I will use this to simulate the cores of the galaxies (the black holes) and eventually the stars.

So long story short I'm working on the beginnings of a gravity simulator. At this point I found some basic code that works well but doesn't quite give the effect I'm looking for.

The code below only pulls each object towards each other like a spring faster and faster until they shoot off into infinity. I try to give one of my bodies an initial velocity to get it to orbit another, but it always just shoots straight at the other body. I'm thinking I need to factor in inertia so that the initial velocity doesn't just get calculated away really fast by the other calculations.

I'm really looking for a bit of direction to get a real gravity simulator with orbits and such working right so eventually I can scale it up to a galaxy, throw in 100B stars and let the CUDA run for a month..

Code:
void update_galaxies(GLdouble elapsedTime) {
//Calculate gravity simulations
GLdouble r1, r2, r3;
r1 = r2 = r3 = 0.0;

for(unsigned int i = 0; i < galaxies.size(); i++)

[Code] ....

As you can see, I'm calculating all the bodies in a vector called "galaxies" with each other, and doing a basic gravity calculation to it. The update_position function simply takes the calculated acceleration and uses it to calculate the velocity and position based on the "elapsedTime".

I think I need to use the Varlet or Runge-Kutta integration methods, after doing a bit more research.

View 9 Replies View Related

C/C++ :: Shifting Characters - How To Make Letters Loop Back To The Start

Feb 9, 2015

I have to make a function that i'll later be able to use for a ceasar cypher. The letters should shift a user inputted number. This is what I have so far:

char shiftChar(char c, int s) {
char ch = c;
int shift = s;
int newC;
newC = int(ch) + shift;
return newC;
}

The problem with this, is that it doesn't loop back to the start of the alphabet once i get past z.

View 2 Replies View Related

C :: Secure Entry Keypad Simulator

Feb 15, 2015

We've been tasked write a code which would mimic a secure entry keypad.. Only recognising the digits 0-9 for the passcode, and non-numerics S (start again) C (clear last digit) and E (enter) for the control. All other key strokes are to be ignored.

The passcode has to be <10 digits and represented on the screen by "****", with any keystrokes >10 ignored.
The valid passcode being 4 digits (1234).

With 3 attempts to get the correct pass code, after each fail attempt as please try again message show, where after the 3rd attempt a specific message is displayed and an alarm sounds..

View 13 Replies View Related

C++ :: Dice Simulator - Floats Rounding Up

Oct 28, 2013

I made this dice simulator which basically throws the dice 1 million times and outputs the frequency and percentage average for each side (1 to 6).

Everything is working fine, except my averages (floats) seem to be rounding up, causing 4% being "unassigned" at the end of the million rolls. I'm outputting with a setprecision of 2, but I only get 0's and no fractional numbers.

View 5 Replies View Related

C++ :: Creating Space Simulator Program For University

Aug 5, 2014

I'm creating a space simulator program for uni and I've got 3 errors that I just can't seem to fix.

View 10 Replies View Related

C/C++ :: Simulator To Implement Populations For Given Number Of Months?

May 18, 2013

How can i implement a simulator that computes the populations for a given number of months for all sectors.

View 1 Replies View Related

C++ :: Error Handling - Enigma Cipher Simulator

Jan 4, 2014

I finished my Enigma cipher simulator...how should I write the error handling code? Should I throw an exception in main, or in the Enigma ctor and Encrypt() fn when the user enters a non-alphanumeric character?

Rotor.hpp

Code:
#ifndef ROTOR_HPP
#define ROTOR_HPP
class Rotor {
public:
Rotor(char pos='A');
Rotor(const Rotor & rhs);
Rotor& operator=(const Rotor& rhs);

[Code] ....

Output

Code:
Enter rotor settings:
ABCDEFGHIJ
Enter cleartext:
HELLO WORLD
Ciphertext:
0O258 SGY5V

View 3 Replies View Related

C++ :: Airline Reservation Simulator - Binary File Errors

Aug 11, 2014

For a big project for school I have to make an airline reservation simulator but I have run into a problem. I want to save the the flight code and its location in a binary file so that I can obtain a code according to the location but this happens:

[URL] ... (link to current output and expected output)

Here is the source class

class file {
private:
char code[8];
char from[20];
public:
void input();

[Code] ....

View 4 Replies View Related

C++ :: Battle Simulator - Save / Load Functions Not Working

Oct 16, 2013

I've been working on a battle simulator, and using it as a learning experience. So far, I've been able to debug the program, and learn some stuff, and it's been running smoothly. It's still runnable, but I've been trying to make it so the player can save his character, and continue the game later. However, I'm not sure whether it's the save or load function that's not working, because even if i save to a txt file, it's just a bunch of random characters. I don't know if that means it's not saving correctly, or if it's just supposed to be like that. Anyway, here are the two functions I'm speaking of:

Code:
void Game::saveGame(Character &player) {
std::ofstream saveFile("save.bin", ios::binary);
saveFile.write((char *)&player, sizeof(player));
saveFile.close();

[Code] .....

My program is in multiple files, so I can't really post the whole code easily, but I can upload or something if I really need to.

View 14 Replies View Related

C++ :: Highway Simulator - Cars Move From Start Point To Quit At End

Jun 12, 2013

i want to draw a highway, this simulator must not be graphical (must draw by "|" and "-" and...) . this highway include 3 type of car,

1- heavy
2-light heavy
3-light, t

These cars move from start point to quit at end of highway, highway must be object (programmed by class), and have 200 columns and 4 raw, it must be horizontal... . the cars speed are different,

speed =1,2,3; length=1,2,3;

View 3 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved