Created
December 18, 2013 16:16
-
-
Save Luisangonzalez/8025067 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package cache; | |
| public class Cache { | |
| public static void accesoMemoria(){ | |
| int[] array; | |
| array= new int[4194304]; | |
| int contador=0; | |
| for(int j=0;j<=16;j++){ | |
| for (int i=j;i<array.length;i=i+17){ | |
| array[i]=28; | |
| contador++; | |
| } | |
| } | |
| System.out.println(contador); | |
| System.out.println(""); | |
| for (int i=0;i<15;i++){ | |
| System.out.println("Posicion de array "+ i +" Valor del array " + array[i]); | |
| } | |
| System.out.println(""); | |
| } | |
| public static int[][] creadorCaches(int tamañoCache,int tamañoLinea,int vias){ | |
| tamañoCache*=1024; | |
| int palabrasLinea= tamañoLinea/4; | |
| int numeroLineas=tamañoCache/tamañoLinea; | |
| int numeroConjuntos=numeroLineas/vias; | |
| int[][] array; | |
| array= new int[numeroConjuntos][vias]; | |
| int valores=-1; | |
| for(int ii=0;ii<array.length;ii++){ | |
| array[ii][0]=valores; | |
| valores+=palabrasLinea; | |
| } | |
| int diferencia= array[numeroConjuntos-1][0]; | |
| for(int ii=0;ii<array.length;ii++){ | |
| for(int jj=1;jj<array[ii].length;jj++){ | |
| array[ii][jj]=(array[ii][jj-1]+diferencia); | |
| } | |
| } | |
| return array; | |
| } | |
| public static void main(String[] args) { | |
| // TODO Auto-generated method stub | |
| int array[][]; | |
| accesoMemoria(); | |
| /* Te crea un array a ejemplo de cache, le tienes que pasar el tamaño de la cache, | |
| * el tamaño de linea, y las lineas. El tamaño de la cache en kb, y el tamaño de linea en bytes. | |
| * | |
| * Crea un array con tantas filas como conjuntos haya, y en cada linea (conjunto), hay tantas columnas | |
| * como vias (lineas de cada conjunto) | |
| */ | |
| array=creadorCaches(32, 64, 8); | |
| for(int ii=0;ii<array.length;ii++){ | |
| for(int jj=0;jj<array[ii].length;jj++){ | |
| System.out.print(array[ii][jj]+" "); | |
| } | |
| System.out.println(""); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment