Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Minyong Li
Can
Commits
b803be17
Verified
Commit
b803be17
authored
Jun 26, 2021
by
Minyong Li
💬
Browse files
core.{Add,Xor}er{,Test}: impl
These are trivial modules, but add convenience when wiring up the processor.
parent
1b6286a3
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/main/scala/uk/ac/soton/ecs/can/core/Adder.scala
0 → 100644
View file @
b803be17
package
uk.ac.soton.ecs.can.core
import
chisel3._
class
Adder
extends
MultiIOModule
{
val
lhs
=
IO
(
Input
(
Vec
(
16
,
UInt
(
32.
W
))))
val
rhs
=
IO
(
Input
(
Vec
(
16
,
UInt
(
32.
W
))))
val
out
=
IO
(
Output
(
Vec
(
16
,
UInt
(
32.
W
))))
out
:=
lhs
.
zip
(
rhs
).
map
{
case
(
lhs
,
rhs
)
=>
lhs
+
rhs
}
}
src/main/scala/uk/ac/soton/ecs/can/core/Xorer.scala
0 → 100644
View file @
b803be17
package
uk.ac.soton.ecs.can.core
import
chisel3._
class
Xorer
extends
MultiIOModule
{
val
lhs
=
IO
(
Input
(
Vec
(
16
,
UInt
(
32.
W
))))
val
rhs
=
IO
(
Input
(
Vec
(
16
,
UInt
(
32.
W
))))
val
out
=
IO
(
Output
(
Vec
(
16
,
UInt
(
32.
W
))))
out
:=
lhs
.
zip
(
rhs
).
map
{
case
(
lhs
,
rhs
)
=>
lhs
^
rhs
}
}
src/test/scala/uk/ac/soton/ecs/can/core/AdderTest.scala
0 → 100644
View file @
b803be17
package
uk.ac.soton.ecs.can.core
import
org.scalatest._
import
chiseltest._
import
chisel3._
import
scala.util.Random
import
scala.math.abs
class
AdderTest
extends
FlatSpec
with
ChiselScalatestTester
{
private
val
maxUInt
=
(
Int
.
MaxValue
.
toLong
<<
1
)
|
1
behavior
of
"The Adder"
it
should
"sum the 16 32b unsigned integers"
in
{
test
(
new
Adder
)
{
c
=>
val
randomLhs
=
c
.
lhs
.
map
(
_
=>
abs
(
Random
.
nextInt
))
val
randomRhs
=
c
.
rhs
.
map
(
_
=>
abs
(
Random
.
nextInt
))
val
randomRes
=
randomLhs
.
zip
(
randomRhs
).
map
{
case
(
l
,
r
)
=>
(
l
.
toLong
+
r
.
toLong
)
%
maxUInt
}
c
.
lhs
.
zip
(
randomLhs
).
foreach
{
case
(
p
,
r
)
=>
p
.
poke
(
r
.
U
)
}
c
.
rhs
.
zip
(
randomRhs
).
foreach
{
case
(
p
,
r
)
=>
p
.
poke
(
r
.
U
)
}
c
.
out
.
zip
(
randomRes
).
foreach
{
case
(
p
,
r
)
=>
p
.
expect
(
r
.
U
)
}
}
}
}
src/test/scala/uk/ac/soton/ecs/can/core/XorerTest.scala
0 → 100644
View file @
b803be17
package
uk.ac.soton.ecs.can.core
import
org.scalatest._
import
chiseltest._
import
chisel3._
import
scala.util.Random
import
scala.math.abs
class
XorerTest
extends
FlatSpec
with
ChiselScalatestTester
{
behavior
of
"The Xorer"
it
should
"exclusive-or the 16 32b unsigned integers"
in
{
test
(
new
Xorer
)
{
c
=>
val
randomLhs
=
c
.
lhs
.
map
(
_
=>
abs
(
Random
.
nextInt
))
val
randomRhs
=
c
.
rhs
.
map
(
_
=>
abs
(
Random
.
nextInt
))
val
randomRes
=
randomLhs
.
zip
(
randomRhs
).
map
{
case
(
l
,
r
)
=>
l
^
r
}
c
.
lhs
.
zip
(
randomLhs
).
foreach
{
case
(
p
,
r
)
=>
p
.
poke
(
r
.
U
)
}
c
.
rhs
.
zip
(
randomRhs
).
foreach
{
case
(
p
,
r
)
=>
p
.
poke
(
r
.
U
)
}
c
.
out
.
zip
(
randomRes
).
foreach
{
case
(
p
,
r
)
=>
p
.
expect
(
r
.
U
)
}
}
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment