Skip to content

Commit 62e2d0c

Browse files
committed
more standard definitions
1 parent 750e4ad commit 62e2d0c

File tree

2 files changed

+91
-0
lines changed

2 files changed

+91
-0
lines changed

std/channel.act

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -860,6 +860,83 @@ export defchan bdbool <: chan(bool) (bool?! d; bool?! r; bool!? a)
860860
}
861861

862862

863+
864+
/*
865+
* Bundled-data channel for standard memory interface
866+
* Encoding: bottom two bits are control
867+
* 0 = write, 1 = read, 2 = read-modify-write
868+
*/
869+
export
870+
template<pint M>
871+
defchan bd_memaddr <: chan(int<M+2>) (bool?! d[M]; bool?! r, w, rw; bool!? a)
872+
{
873+
spec {
874+
/* timing forks */
875+
timing a- : d* < r*+
876+
timing a- : d* < rw*+
877+
timing a- : d* < w*+
878+
}
879+
880+
methods {
881+
/*-- initialize channel, sender end --*/
882+
send_init {
883+
(,i:M: d[i]-),r-,w-,rw-
884+
}
885+
886+
/*-- set output data --*/
887+
set {
888+
(,i:M: [((self >> (i+2)) & 1) = 0 -> d[i]- [] else -> d[i]+ ]);
889+
[self{1..0} = 0 -> w+
890+
[]self{1..0} = 1 -> r+
891+
[]self{1..0} = 2 -> rw+
892+
]
893+
}
894+
895+
/*-- finish synchronization --*/
896+
send_up {
897+
[a]
898+
}
899+
900+
/*-- reset part of the protocol --*/
901+
send_rest {
902+
r-,w-,rw-;[~a]
903+
}
904+
905+
/*-- initialize channel, receiver end --*/
906+
recv_init {
907+
a-
908+
}
909+
910+
/*-- get value --*/
911+
get {
912+
[r|w|rw];
913+
self := 0;
914+
(;i:M: self := self | (int(d[i]) << (i+2)));
915+
[r -> self := self | 1
916+
[]rw -> self := self | 2
917+
[] else -> skip
918+
]
919+
}
920+
921+
/*-- finish synchronization action --*/
922+
recv_up {
923+
a+
924+
}
925+
926+
/*-- reset part of the protocol --*/
927+
recv_rest {
928+
[~r&~w&~rw];a-
929+
}
930+
931+
/*-- probe expression on receiver --*/
932+
recv_probe = (r|w|rw);
933+
934+
// no sender probe
935+
}
936+
}
937+
938+
939+
863940
template<pbool reset; pint V; pint M>
864941
defchan gen_pMbd <: chan(int<M>) (bool?! d[M]; bool!? r; bool?! a)
865942
{

std/func.act

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,20 @@ function ror(int<W> x) : int<W>
120120
}
121121
}
122122

123+
/**
124+
* WARNING: This only works if x is non-zero.
125+
* The function returns the bit-position of the leading one in "x"
126+
*/
127+
export
128+
template<pint W>
129+
function find_msb_pos(int<W> x) : int<std::ceil_log2(W)>
130+
{
131+
chp {
132+
self := 0;
133+
(; i : W : [ x{i} = 1 -> self := i [] else -> skip ])
134+
}
135+
}
136+
123137
}
124138

125139

0 commit comments

Comments
 (0)