-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implementando simulador sem cache. Iniciando implementacao do simulad…
…or com cache.
- Loading branch information
Italo Valcy
committed
Jun 17, 2008
1 parent
bad30dd
commit cb46948
Showing
5 changed files
with
130 additions
and
110 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,67 @@ | ||
require 'gui' | ||
require 'barramento' | ||
|
||
class Cache | ||
|
||
# Retorna o valor contido em alguns endereços do cache | ||
# address - endereço inicial do cache | ||
# qtd - quantidade de registros que deve ser lidos a | ||
# partir de address | ||
|
||
# Retorna o valor contido em alguns endereços do cache | ||
# address - endereço inicial do cache | ||
# qtd - quantidade de registros que deve ser lidos a | ||
# partir de address | ||
def Cache.get_value(address, qtd) | ||
if(Simulador.get_type_mapping ) | ||
result = '' | ||
if(Simulador.cache_habilitado) | ||
for i in 0..qtd - 1 | ||
value = fetch_value(address.to_i + i) | ||
if (value == nil) | ||
# Cache miss | ||
value = update_cache(address.to_i + i) | ||
end | ||
result = str_concat(result,value) | ||
end | ||
else | ||
result = Barramento.read('mem',address,qtd) | ||
end | ||
return Simulador.get_value_memoria(address) | ||
return result | ||
end | ||
|
||
# Armazena o valor de value no cache no endereco address | ||
def Cache.set_value(address, value) | ||
end | ||
|
||
def get_position(address) | ||
case (Simulador.get_type_mapping) | ||
when 0 #mapeamento direto | ||
return address.to_i.mod Simulador.get_cache_size | ||
return address.to_i.mod(Simulador.get_cache_size) | ||
when 1 #mapeamento fully-set | ||
when 2 #mapeamento 2-set | ||
when 3 #mapeamento 4-set | ||
end | ||
end | ||
|
||
def str_concat(str1, str2) | ||
return (str1.to_i)*256 + str2.to_i | ||
end | ||
|
||
def fetch_value(address) | ||
pos = get_position(address) | ||
vet = Simulador.get_value_cache('cache',pos) | ||
if(vet[0] == address) | ||
#cache hit | ||
return vet[1] | ||
else | ||
#cache miss | ||
if(Simulador.get_type_update_cache == 0) #write back | ||
#levar o que tem no cache para a memoria | ||
#trazer novos dados da memoria para o cache | ||
else #write through | ||
Memoria.get_value(address,4) | ||
#trazer novos dados da memoria para o cache | ||
end | ||
block = Simulador.get_block_cache(pos) | ||
if (block[0] == address + i) | ||
return block[1] | ||
end | ||
return nil | ||
end | ||
|
||
# Armazena o valor de value no cache no endereco address | ||
def Cache.set_value(address, value) | ||
def update_cache(address) | ||
case Simulador.get_type_update_cache | ||
when 0 #write back | ||
pos = get_position(address.to_i) | ||
block1 = Simulador.get_block_cache(pos) | ||
pos = get_position(address.to_i+1) | ||
block2 = Simulador.get_block_cache(pos) | ||
#levar o que tem no cache para a memoria | ||
#trazer novos dados da memoria para o cache | ||
when 1 #write through | ||
Memoria.get_value(address,4) | ||
#trazer novos dados da memoria para o cache | ||
end | ||
end | ||
end |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,25 @@ | ||
require 'gui' | ||
require 'processador' | ||
|
||
class Memoria | ||
# Retorna o valor contido em alguns endereços de memoria | ||
# address - endereço inicial de memoria | ||
# qtd - quantidade de registros que deve ser lidos a | ||
# partir de address | ||
def Memoria.get_value(address, qtd) | ||
Processador.get_clock() | ||
return Simulador.get_value_grid('mem', address,qtd) | ||
def Memoria.get_value(address, qtd) | ||
result = 0 | ||
case qtd | ||
when 1 | ||
result = Simulador.get_value_grid('mem',address) | ||
when 2 | ||
r1 = Simulador.get_value_grid('mem',address).to_i | ||
r2 = Simulador.get_value_grid('mem',address.to_i + 1).to_i | ||
result = r1*256 + r2 | ||
end | ||
return result.to_s | ||
end | ||
|
||
# Armazena o valor de value na memoria no endereco address | ||
def Memoria.set_value(address, value) | ||
Processador.get_clock() | ||
Simulador.set_value_grid('mem',address,value) | ||
end | ||
end |
Oops, something went wrong.