detecter_defaut_cache_LRU(adresse @) : booleen
variables :
index : entier
ensemble_courant : t_ensemble





DEBUT

index := conv_bin2dec(@(2 .. 4))
ensemble_courant := mc[index]

Pour i := 0 à 15 Faire
	Si ensemble_courant[i].bit_validite = '1' Alors
		Si ensemble_courant[i].etiquette = @(5..10) Alors
			// MAJ du tag
			ensemble_courant[i].tag_LRU := 0
			// MAJ des tags
			Pour i := 0 à 15 Faire
				Si ensemble_courant[i].bit_validite = '1' Alors
					ensemble_courant[i].tag_LRU := ensemble_courant[i].tag_LRU + 1
				FinSi
			FinPour
			retourner FAUX
		FinSi
	FinSi
FinPour

retourner vrai

	
FIN




detecter_defaut_cache_LFU(adresse @) : booleen
variables :
index : entier
ensemble_courant : t_ensemble

DEBUT

index := conv_bin2dec(@(2 .. 4))
ensemble_courant := mc[index]

Pour i := 0 à 15 Faire
	Si ensemble_courant[i].bit_validite = '1' Alors
		Si ensemble_courant[i].etiquette = @(5..10) Alors
			// MAJ du tag
			ensemble_courant[i].tag_LRU := ensemble_courant[i].tag_LRU + 1
			
			retourner FAUX
		FinSi
	FinSi
FinPour

retourner vrai

	
FIN




charger_en_memoire_cache_LRU(adresse @ , t_bloc b) : 
variables : 
index : entier
ensemble_courant : t_ensemble

DEBUT

	index := conv_bin2dec(@(2..4))
	ensemble_courant := mc[index]

pos_LRU := 0
Pour i := 0 à 15 Faire
	// Cas ou la ligne n'est pas affectée
	Si ensemble_courant[i].bit_validite = '0' Alors
		ensemble_courant[i].bloc := b
		ensemble_courant[i].etiquette := @(5..10)
		ensemble_courant[i].tag_LRU := 0
		ensemble_courant[i].bit_validite := '1'
		pos_LRU := -1
		BREAK // SORT DE LA LOOP POUR
	Sinon
		Si( ensemble_courant[i].tag_LRU > ensemble_courant[pos_LRU].tag_LRU)Alors
			pos_LRU := i
		FinSi
	FinSi
FinPour

Si pos_LRU <> -1 Alors
		// Si on a modifié le contenu du bloc, on le recharge en mm avant de l'écraser
		Si ensemble_courant[pos_LRU].maj = '1' Alors
			@2 := concat( ensemble_courant[pos_LRU].etiquette , @(2 .. 4)  )
			pos_mm := conv_bin2dec( @2 )
			mm(pos_mm) := ensemble_courant[pos_LRU].bloc
		FinSi
		// Ensuite on charge la nouvelle donnée
		ensemble_courant[pos_LRU].bloc := b
		ensemble_courant[pos_LRU].etiquette := @(5..10)
		ensemble_courant[pos_LRU].tag_LRU := 0
FinSi

// MAJ des tags
		Pour i := 0 à 15 Faire
			Si ensemble_courant[i].bit_validite = '1' Alors
				ensemble_courant[i].tag_LRU := ensemble_courant[i].tag_LRU + 1
			FinSi
		FinPour

FIN






charger_en_memoire_cache_LFU(adresse @ , t_bloc b) : 
variables : 
index : entier
ensemble_courant : t_ensemble

DEBUT

	index := conv_bin2dec(@(2..4))
	ensemble_courant := mc[index]

pos_LFU := 0
Pour i := 0 à 15 Faire
	// Cas ou la ligne n'est pas affectée
	Si ensemble_courant[i].bit_validite = '0' Alors
		ensemble_courant[i].bloc := b
		ensemble_courant[i].etiquette := @(5..10)
		ensemble_courant[i].tag_LFU := 1
		ensemble_courant[i].bit_validite := '1'
		pos_LFU := -1
		BREAK // SORT DE LA LOOP POUR
	Sinon
		Si( ensemble_courant[i].tag_LFU < ensemble_courant[pos_old].tag_LFU)Alors
			pos_LFU := i
		FinSi
	FinSi
FinPour

Si pos_LFU <> -1 Alors
		// Si on a modifié le contenu du bloc, on le recharge en mm avant de l'écraser
		Si ensemble_courant[pos_LFU].maj = '1' Alors
			@2 := concat( ensemble_courant[pos_LFU].etiquette , @(2 .. 4)  )
			pos_mm := conv_dec2bin( @2 )
			mm(pos_mm) := ensemble_courant[pos_LFU].bloc
		FinSi
		// Ensuite on charge la nouvelle donnée
		ensemble_courant[pos_LFU].bloc := b
		ensemble_courant[pos_LFU].etiquette := @(5..10)
		ensemble_courant[pos_LFU].tag_LFU := 1
FinSi


FIN