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