Display access numbers and reset cache state between accesses.
This commit is contained in:
parent
3c0f5d34bf
commit
e6c7638324
|
@ -2,15 +2,21 @@ module CacheSim.AccessView exposing (..)
|
|||
import CacheSim.Cache exposing (..)
|
||||
import CacheSim.Hierarchy exposing (..)
|
||||
|
||||
type AccessPosition = Down Int | Up Int | Done
|
||||
type alias AccessView = (List (AccessEffect Cache), AccessPosition)
|
||||
type AccessPosition = Down Int | Up Int | Preview | End
|
||||
type alias AccessView =
|
||||
{ initialState : CacheHierarchy
|
||||
, blockAddr : BlockAddr
|
||||
, accessEffects : List (AccessEffect Cache)
|
||||
, position : AccessPosition
|
||||
}
|
||||
|
||||
accessPositionForward : Int -> AccessPosition -> AccessPosition
|
||||
accessPositionForward depth av =
|
||||
case av of
|
||||
Down n -> if n == depth - 1 then Up n else Down (n + 1)
|
||||
Up n -> if n == 0 then Done else Up (n - 1)
|
||||
Done -> Done
|
||||
Up n -> if n == 0 then Preview else Up (n - 1)
|
||||
Preview -> End
|
||||
End -> End
|
||||
|
||||
accessPositionBack : Int -> AccessPosition -> AccessPosition
|
||||
accessPositionBack depth av =
|
||||
|
@ -18,41 +24,43 @@ accessPositionBack depth av =
|
|||
Down 0 -> Down 0
|
||||
Down n -> Down (n-1)
|
||||
Up n -> if n == (depth - 1) then Down n else Up (n + 1)
|
||||
Done -> Up 0
|
||||
Preview -> Up 0
|
||||
End -> Preview
|
||||
|
||||
accessPositionDone : AccessPosition -> Bool
|
||||
accessPositionDone av =
|
||||
case av of
|
||||
Done -> True
|
||||
End -> True
|
||||
_ -> False
|
||||
|
||||
accessViewForward : AccessView -> AccessView
|
||||
accessViewForward (l, ap) = (l, accessPositionForward (List.length l) ap)
|
||||
accessViewForward av = { av | position = accessPositionForward (List.length av.accessEffects) av.position }
|
||||
|
||||
accessViewBack : AccessView -> AccessView
|
||||
accessViewBack (l, ap) = (l, accessPositionBack (List.length l) ap)
|
||||
accessViewBack av = { av | position = accessPositionBack (List.length av.accessEffects) av.position }
|
||||
|
||||
accessViewDone : AccessView -> Bool
|
||||
accessViewDone (_, ap) = accessPositionDone ap
|
||||
accessViewDone av = accessPositionDone av.position
|
||||
|
||||
finalCacheHierarchy : CacheHierarchy -> AccessView -> CacheHierarchy
|
||||
finalCacheHierarchy ch (l, ap) =
|
||||
List.map .output l ++ List.drop (List.length l) ch
|
||||
finalCacheHierarchy : AccessView -> CacheHierarchy
|
||||
finalCacheHierarchy av =
|
||||
List.map .output av.accessEffects ++ List.drop (List.length av.accessEffects) av.initialState
|
||||
|
||||
|
||||
effectiveCacheHierarchy : CacheHierarchy -> AccessView -> CacheHierarchy
|
||||
effectiveCacheHierarchy c (l, ap) =
|
||||
effectiveCacheHierarchy : AccessView -> CacheHierarchy
|
||||
effectiveCacheHierarchy av =
|
||||
let
|
||||
finalContents = List.map .output l
|
||||
unaccessed = List.drop (List.length l) c
|
||||
finalContents = List.map .output av.accessEffects
|
||||
unaccessed = List.drop (List.length av.accessEffects) av.initialState
|
||||
notDone =
|
||||
case ap of
|
||||
Done -> []
|
||||
Down _ -> List.take (List.length l) c
|
||||
Up n -> List.take n c
|
||||
case av.position of
|
||||
Preview -> []
|
||||
End -> []
|
||||
Down _ -> List.take (List.length av.accessEffects) av.initialState
|
||||
Up n -> List.take n av.initialState
|
||||
done =
|
||||
case ap of
|
||||
Done -> finalContents
|
||||
case av.position of
|
||||
Preview -> finalContents
|
||||
End -> finalContents
|
||||
Down _ -> []
|
||||
Up n -> List.drop n finalContents
|
||||
in
|
||||
|
|
|
@ -46,7 +46,7 @@ updateAccess li m =
|
|||
[] -> Ok []
|
||||
(i::t) ->
|
||||
case accessCacheHierarchy i c of
|
||||
Ok av -> Result.map ((::) (av, Down 0)) <| process (finalCacheHierarchy c (av, Done)) t
|
||||
Ok av -> Result.map ((::) (i, av, Down 0)) <| process (finalCacheHierarchy c (i, av, Done)) t
|
||||
Err s -> Err s
|
||||
|
||||
accessResult = Maybe.andThen (\h -> Result.toMaybe <| process h li) m.hierarchy
|
||||
|
@ -61,8 +61,8 @@ updateAccessViewForward m =
|
|||
afterStep = Maybe.map (intMapUpdate 0 accessViewForward) m.accessView
|
||||
(newHierarchy, newAccessView) =
|
||||
case afterStep of
|
||||
Just ((avs, Done)::[]) -> (Maybe.map (\h -> finalCacheHierarchy h (avs, Done)) m.hierarchy, Nothing)
|
||||
Just ((avs, Done)::xs) -> (Maybe.map (\h -> finalCacheHierarchy h (avs, Done)) m.hierarchy, Just xs)
|
||||
Just ((i, avs, Done)::[]) -> (Maybe.map (\h -> finalCacheHierarchy h (i, avs, Done)) m.hierarchy, Nothing)
|
||||
Just ((i, avs, Done)::xs) -> (Maybe.map (\h -> finalCacheHierarchy h (i, avs, Done)) m.hierarchy, Just xs)
|
||||
as_ -> (m.hierarchy, as_)
|
||||
newModel = { m | accessView = newAccessView, hierarchy = newHierarchy }
|
||||
cmd = Cmd.none
|
||||
|
|
|
@ -164,10 +164,12 @@ viewCacheHierarchy ch =
|
|||
viewAccessView : Model -> AccessView -> Html Msg
|
||||
viewAccessView m av =
|
||||
let
|
||||
(i, _, _) = av
|
||||
currentCache = Maybe.withDefault [] m.hierarchy
|
||||
in
|
||||
div []
|
||||
[ h2 [] [ text "Access Simulation" ]
|
||||
, p [] [ text ("Simulating access of address " ++ String.fromInt i) ]
|
||||
, buttonWrapper
|
||||
[ primaryButton "Back" AccessViewBack
|
||||
, primaryButton "Forward" AccessViewForward
|
||||
|
@ -179,7 +181,7 @@ viewAccessView m av =
|
|||
]
|
||||
|
||||
viewAccessLog : AccessView -> Html Msg
|
||||
viewAccessLog (aes, ap) =
|
||||
viewAccessLog (i, aes, ap) =
|
||||
let
|
||||
resultSpan r =
|
||||
span [ classList [ ("badge", True), ("badge-success", r == Hit), ("badge-danger", r == Miss) ] ]
|
||||
|
|
Loading…
Reference in New Issue
Block a user