-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGlobals.bsv
83 lines (67 loc) · 2.3 KB
/
Globals.bsv
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// SPDX-License-Identifier: BSD-2-Clause
package Globals;
import Util :: *;
// Core-local thread id
typedef Bit#(`LogThreadsPerCore) ThreadId;
// Board-local core id
typedef Bit#(`LogCoresPerBoard) CoreId;
// Board id
typedef struct {
Bit#(`MeshYBits) y;
Bit#(`MeshXBits) x;
} BoardId deriving (Eq, Bits, FShow);
// Network address
// Note: If 'host' bit is valid, then once the message reaches the
// destination board, it is routed either left or right depending
// the contents of the host bit. This is to support bridge boards
// connected at the east/west rims of the FPGA mesh.
// The 'isKey' bit means that the destination is a routing key, held
// in the botom 32 bits of the 'NetAddr'.
// The 'acc' bit means message is routed to a custom accelerator rather
// than a mailbox.
typedef struct {
Bool acc;
Bool isKey;
Option#(Bit#(1)) host;
BoardId board;
MailboxId mbox;
} MailboxNetAddr deriving (Bits, FShow);
typedef struct {
MailboxNetAddr addr;
Bit#(`ThreadsPerMailbox) threads;
} NetAddr deriving (Bits, FShow);
// Mailbox id
typedef struct {
Bit#(`MailboxMeshYBits) y;
Bit#(`MailboxMeshXBits) x;
} MailboxId deriving (Bits, Eq, FShow);
function MailboxId getMailboxId(NetAddr addr) = addr.addr.mbox;
// Extract routing key from network address
function Bit#(32) getRoutingKeyRaw(NetAddr addr) = truncate(pack(addr));
// ============================================================================
// Messages
// ============================================================================
// Message length in flits
// (A length of N corresponds to N+1 flits)
typedef Bit#(`LogMaxFlitsPerMsg) MsgLen;
// Flit payload
typedef Bit#(TMul#(`WordsPerFlit, 32)) FlitPayload;
// Flit type
typedef struct {
// Destination address
NetAddr dest;
// Payload
FlitPayload payload;
// Is this the final flit in the message?
Bool notFinalFlit;
// Is this a special packet for idle-detection?
Bool isIdleToken;
} Flit deriving (Bits, FShow);
// A padded flit is a multiple of 64 bits
// (i.e. the data width of the 10G MAC interface)
typedef TMul#(TDiv#(SizeOf#(Flit), 64), 64) PaddedFlitNumBits;
typedef Bit#(PaddedFlitNumBits) PaddedFlit;
// Padding functions
function PaddedFlit padFlit(Flit flit) = {?, pack(flit)};
function Flit unpadFlit(PaddedFlit flit) = unpack(truncate(pack(flit)));
endpackage