Skip to content

Commit

Permalink
ustcpetergu: Added COD code
Browse files Browse the repository at this point in the history
  • Loading branch information
petergu committed Jan 18, 2021
1 parent f3532b2 commit 64bd1fd
Show file tree
Hide file tree
Showing 146 changed files with 15,316 additions and 0 deletions.
16 changes: 16 additions & 0 deletions 计算机组成原理/codes/ustcpetergu/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
### 2020 年春季学期 COD 实验报告 & 代码

原项目/历史记录请见 https://github.com/ustcpetergu/USTC-COD-Labs/

- Lab1: ALU & sort
- Lab2: Regfile & RAM & FIFO
- Lab3: Single cycle CPU
- Lab4: Multiple cycle CPU
- Lab5: 5-stage pipeline CPU
- Lab6: CPU & UART on ebaz4205 (testing video in report.md)

Rebuild projects from TCL(for example):

```
vivado -mode batch -source lab6.tcl -tclargs --project_name lab6
```
276 changes: 276 additions & 0 deletions 计算机组成原理/codes/ustcpetergu/ip/alu/component.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,276 @@
<?xml version="1.0" encoding="UTF-8"?>
<spirit:component xmlns:xilinx="http://www.xilinx.com" xmlns:spirit="http://www.spiritconsortium.org/XMLSchema/SPIRIT/1685-2009" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<spirit:vendor>ustcpetergu.com</spirit:vendor>
<spirit:library>user</spirit:library>
<spirit:name>alu</spirit:name>
<spirit:version>1.0</spirit:version>
<spirit:model>
<spirit:views>
<spirit:view>
<spirit:name>xilinx_anylanguagesynthesis</spirit:name>
<spirit:displayName>Synthesis</spirit:displayName>
<spirit:envIdentifier>:vivado.xilinx.com:synthesis</spirit:envIdentifier>
<spirit:language>Verilog</spirit:language>
<spirit:modelName>alu</spirit:modelName>
<spirit:fileSetRef>
<spirit:localName>xilinx_anylanguagesynthesis_view_fileset</spirit:localName>
</spirit:fileSetRef>
<spirit:parameters>
<spirit:parameter>
<spirit:name>viewChecksum</spirit:name>
<spirit:value>7bf5aeae</spirit:value>
</spirit:parameter>
</spirit:parameters>
</spirit:view>
<spirit:view>
<spirit:name>xilinx_anylanguagebehavioralsimulation</spirit:name>
<spirit:displayName>Simulation</spirit:displayName>
<spirit:envIdentifier>:vivado.xilinx.com:simulation</spirit:envIdentifier>
<spirit:language>Verilog</spirit:language>
<spirit:modelName>alu</spirit:modelName>
<spirit:fileSetRef>
<spirit:localName>xilinx_anylanguagebehavioralsimulation_view_fileset</spirit:localName>
</spirit:fileSetRef>
<spirit:parameters>
<spirit:parameter>
<spirit:name>viewChecksum</spirit:name>
<spirit:value>7bf5aeae</spirit:value>
</spirit:parameter>
</spirit:parameters>
</spirit:view>
<spirit:view>
<spirit:name>xilinx_testbench</spirit:name>
<spirit:displayName>Test Bench</spirit:displayName>
<spirit:envIdentifier>:vivado.xilinx.com:simulation.testbench</spirit:envIdentifier>
<spirit:modelName>sort_simu</spirit:modelName>
<spirit:fileSetRef>
<spirit:localName>xilinx_testbench_view_fileset</spirit:localName>
</spirit:fileSetRef>
<spirit:parameters>
<spirit:parameter>
<spirit:name>viewChecksum</spirit:name>
<spirit:value>079ef021</spirit:value>
</spirit:parameter>
</spirit:parameters>
</spirit:view>
<spirit:view>
<spirit:name>xilinx_xpgui</spirit:name>
<spirit:displayName>UI Layout</spirit:displayName>
<spirit:envIdentifier>:vivado.xilinx.com:xgui.ui</spirit:envIdentifier>
<spirit:fileSetRef>
<spirit:localName>xilinx_xpgui_view_fileset</spirit:localName>
</spirit:fileSetRef>
<spirit:parameters>
<spirit:parameter>
<spirit:name>viewChecksum</spirit:name>
<spirit:value>b030f5a2</spirit:value>
</spirit:parameter>
</spirit:parameters>
</spirit:view>
</spirit:views>
<spirit:ports>
<spirit:port>
<spirit:name>m</spirit:name>
<spirit:wire>
<spirit:direction>in</spirit:direction>
<spirit:vector>
<spirit:left spirit:format="long">2</spirit:left>
<spirit:right spirit:format="long">0</spirit:right>
</spirit:vector>
<spirit:wireTypeDefs>
<spirit:wireTypeDef>
<spirit:typeName>std_logic_vector</spirit:typeName>
<spirit:viewNameRef>xilinx_anylanguagesynthesis</spirit:viewNameRef>
<spirit:viewNameRef>xilinx_anylanguagebehavioralsimulation</spirit:viewNameRef>
</spirit:wireTypeDef>
</spirit:wireTypeDefs>
</spirit:wire>
</spirit:port>
<spirit:port>
<spirit:name>a</spirit:name>
<spirit:wire>
<spirit:direction>in</spirit:direction>
<spirit:vector>
<spirit:left spirit:format="long" spirit:resolve="dependent" spirit:dependency="(spirit:decode(id(&apos;MODELPARAM_VALUE.WIDTH&apos;)) - 1)">31</spirit:left>
<spirit:right spirit:format="long">0</spirit:right>
</spirit:vector>
<spirit:wireTypeDefs>
<spirit:wireTypeDef>
<spirit:typeName>std_logic_vector</spirit:typeName>
<spirit:viewNameRef>xilinx_anylanguagesynthesis</spirit:viewNameRef>
<spirit:viewNameRef>xilinx_anylanguagebehavioralsimulation</spirit:viewNameRef>
</spirit:wireTypeDef>
</spirit:wireTypeDefs>
</spirit:wire>
</spirit:port>
<spirit:port>
<spirit:name>b</spirit:name>
<spirit:wire>
<spirit:direction>in</spirit:direction>
<spirit:vector>
<spirit:left spirit:format="long" spirit:resolve="dependent" spirit:dependency="(spirit:decode(id(&apos;MODELPARAM_VALUE.WIDTH&apos;)) - 1)">31</spirit:left>
<spirit:right spirit:format="long">0</spirit:right>
</spirit:vector>
<spirit:wireTypeDefs>
<spirit:wireTypeDef>
<spirit:typeName>std_logic_vector</spirit:typeName>
<spirit:viewNameRef>xilinx_anylanguagesynthesis</spirit:viewNameRef>
<spirit:viewNameRef>xilinx_anylanguagebehavioralsimulation</spirit:viewNameRef>
</spirit:wireTypeDef>
</spirit:wireTypeDefs>
</spirit:wire>
</spirit:port>
<spirit:port>
<spirit:name>y</spirit:name>
<spirit:wire>
<spirit:direction>out</spirit:direction>
<spirit:vector>
<spirit:left spirit:format="long" spirit:resolve="dependent" spirit:dependency="(spirit:decode(id(&apos;MODELPARAM_VALUE.WIDTH&apos;)) - 1)">31</spirit:left>
<spirit:right spirit:format="long">0</spirit:right>
</spirit:vector>
<spirit:wireTypeDefs>
<spirit:wireTypeDef>
<spirit:typeName>std_logic_vector</spirit:typeName>
<spirit:viewNameRef>xilinx_anylanguagesynthesis</spirit:viewNameRef>
<spirit:viewNameRef>xilinx_anylanguagebehavioralsimulation</spirit:viewNameRef>
</spirit:wireTypeDef>
</spirit:wireTypeDefs>
</spirit:wire>
</spirit:port>
<spirit:port>
<spirit:name>zf</spirit:name>
<spirit:wire>
<spirit:direction>out</spirit:direction>
<spirit:wireTypeDefs>
<spirit:wireTypeDef>
<spirit:typeName>std_logic</spirit:typeName>
<spirit:viewNameRef>xilinx_anylanguagesynthesis</spirit:viewNameRef>
<spirit:viewNameRef>xilinx_anylanguagebehavioralsimulation</spirit:viewNameRef>
</spirit:wireTypeDef>
</spirit:wireTypeDefs>
</spirit:wire>
</spirit:port>
<spirit:port>
<spirit:name>cf</spirit:name>
<spirit:wire>
<spirit:direction>out</spirit:direction>
<spirit:wireTypeDefs>
<spirit:wireTypeDef>
<spirit:typeName>std_logic</spirit:typeName>
<spirit:viewNameRef>xilinx_anylanguagesynthesis</spirit:viewNameRef>
<spirit:viewNameRef>xilinx_anylanguagebehavioralsimulation</spirit:viewNameRef>
</spirit:wireTypeDef>
</spirit:wireTypeDefs>
</spirit:wire>
</spirit:port>
<spirit:port>
<spirit:name>of</spirit:name>
<spirit:wire>
<spirit:direction>out</spirit:direction>
<spirit:wireTypeDefs>
<spirit:wireTypeDef>
<spirit:typeName>std_logic</spirit:typeName>
<spirit:viewNameRef>xilinx_anylanguagesynthesis</spirit:viewNameRef>
<spirit:viewNameRef>xilinx_anylanguagebehavioralsimulation</spirit:viewNameRef>
</spirit:wireTypeDef>
</spirit:wireTypeDefs>
</spirit:wire>
</spirit:port>
</spirit:ports>
<spirit:modelParameters>
<spirit:modelParameter xsi:type="spirit:nameValueTypeType" spirit:dataType="integer">
<spirit:name>WIDTH</spirit:name>
<spirit:displayName>Width</spirit:displayName>
<spirit:value spirit:format="long" spirit:resolve="generated" spirit:id="MODELPARAM_VALUE.WIDTH">32</spirit:value>
</spirit:modelParameter>
</spirit:modelParameters>
</spirit:model>
<spirit:fileSets>
<spirit:fileSet>
<spirit:name>xilinx_anylanguagesynthesis_view_fileset</spirit:name>
<spirit:file>
<spirit:name>src/alu.v</spirit:name>
<spirit:fileType>verilogSource</spirit:fileType>
<spirit:userFileType>CHECKSUM_7bf5aeae</spirit:userFileType>
<spirit:userFileType>IMPORTED_FILE</spirit:userFileType>
</spirit:file>
</spirit:fileSet>
<spirit:fileSet>
<spirit:name>xilinx_anylanguagebehavioralsimulation_view_fileset</spirit:name>
<spirit:file>
<spirit:name>src/alu.v</spirit:name>
<spirit:fileType>verilogSource</spirit:fileType>
<spirit:userFileType>IMPORTED_FILE</spirit:userFileType>
</spirit:file>
</spirit:fileSet>
<spirit:fileSet>
<spirit:name>xilinx_testbench_view_fileset</spirit:name>
<spirit:file>
<spirit:name>src/sort_simu.v</spirit:name>
<spirit:fileType>verilogSource</spirit:fileType>
<spirit:userFileType>IMPORTED_FILE</spirit:userFileType>
<spirit:userFileType>USED_IN_implementation</spirit:userFileType>
<spirit:userFileType>USED_IN_simulation</spirit:userFileType>
<spirit:userFileType>USED_IN_synthesis</spirit:userFileType>
</spirit:file>
</spirit:fileSet>
<spirit:fileSet>
<spirit:name>xilinx_xpgui_view_fileset</spirit:name>
<spirit:file>
<spirit:name>xgui/alu_v1_0.tcl</spirit:name>
<spirit:fileType>tclSource</spirit:fileType>
<spirit:userFileType>CHECKSUM_b030f5a2</spirit:userFileType>
<spirit:userFileType>XGUI_VERSION_2</spirit:userFileType>
</spirit:file>
</spirit:fileSet>
</spirit:fileSets>
<spirit:description>alu_v1_0</spirit:description>
<spirit:parameters>
<spirit:parameter>
<spirit:name>WIDTH</spirit:name>
<spirit:displayName>Width</spirit:displayName>
<spirit:value spirit:format="long" spirit:resolve="user" spirit:id="PARAM_VALUE.WIDTH">32</spirit:value>
</spirit:parameter>
<spirit:parameter>
<spirit:name>Component_Name</spirit:name>
<spirit:value spirit:resolve="user" spirit:id="PARAM_VALUE.Component_Name" spirit:order="1">alu_v1_0</spirit:value>
</spirit:parameter>
</spirit:parameters>
<spirit:vendorExtensions>
<xilinx:coreExtensions>
<xilinx:supportedFamilies>
<xilinx:family xilinx:lifeCycle="Production">artix7</xilinx:family>
<xilinx:family xilinx:lifeCycle="Production">artix7l</xilinx:family>
<xilinx:family xilinx:lifeCycle="Production">aartix7</xilinx:family>
<xilinx:family xilinx:lifeCycle="Production">zynq</xilinx:family>
<xilinx:family xilinx:lifeCycle="Production">azynq</xilinx:family>
</xilinx:supportedFamilies>
<xilinx:taxonomies>
<xilinx:taxonomy>/UserIP</xilinx:taxonomy>
</xilinx:taxonomies>
<xilinx:displayName>alu_v1_0</xilinx:displayName>
<xilinx:definitionSource>package_project</xilinx:definitionSource>
<xilinx:coreRevision>1</xilinx:coreRevision>
<xilinx:upgrades>
<xilinx:canUpgradeFrom>user.org:user:alu:1.0</xilinx:canUpgradeFrom>
</xilinx:upgrades>
<xilinx:coreCreationDateTime>2020-05-06T13:03:33Z</xilinx:coreCreationDateTime>
<xilinx:tags>
<xilinx:tag xilinx:name="ui.data.coregen.dd@35733fc2_ARCHIVE_LOCATION">/home/petergu/MyHome/COD/ip</xilinx:tag>
<xilinx:tag xilinx:name="ui.data.coregen.dd@699b901e_ARCHIVE_LOCATION">/home/petergu/MyHome/COD/ip</xilinx:tag>
<xilinx:tag xilinx:name="ui.data.coregen.dd@d1e0736_ARCHIVE_LOCATION">/home/petergu/MyHome/COD/ip</xilinx:tag>
<xilinx:tag xilinx:name="ui.data.coregen.dd@701722a9_ARCHIVE_LOCATION">/home/petergu/MyHome/COD/ip</xilinx:tag>
<xilinx:tag xilinx:name="ui.data.coregen.dd@7b42f9b0_ARCHIVE_LOCATION">/home/petergu/MyHome/COD/ip</xilinx:tag>
<xilinx:tag xilinx:name="ui.data.coregen.dd@1788dc30_ARCHIVE_LOCATION">/home/petergu/MyHome/COD/ip</xilinx:tag>
<xilinx:tag xilinx:name="ui.data.coregen.dd@281ccfa0_ARCHIVE_LOCATION">/home/petergu/MyHome/COD/ip</xilinx:tag>
</xilinx:tags>
</xilinx:coreExtensions>
<xilinx:packagingInfo>
<xilinx:xilinxVersion>2019.1</xilinx:xilinxVersion>
<xilinx:checksum xilinx:scope="fileGroups" xilinx:value="bf9b2c8e"/>
<xilinx:checksum xilinx:scope="ports" xilinx:value="c400300f"/>
<xilinx:checksum xilinx:scope="hdlParameters" xilinx:value="6d1236b8"/>
<xilinx:checksum xilinx:scope="parameters" xilinx:value="f46a4aa8"/>
</xilinx:packagingInfo>
</spirit:vendorExtensions>
</spirit:component>
67 changes: 67 additions & 0 deletions 计算机组成原理/codes/ustcpetergu/ip/alu/src/alu.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
`timescale 1ns / 1ps
// ALU
// 2020 COD Lab1
// ustcpetergu

module alu
#(parameter WIDTH = 32)
(
input [2:0]m, // selection
input [WIDTH-1:0]a, b, // input
output [WIDTH-1:0]y, // result
output zf, // zero flag
output cf, // carry out flag: WIDTH bit
output of // overflow flag: WIDTH-1 sign bit
);

reg [WIDTH-1:0]regy;
reg regcf;
reg regof;
reg regzf;
assign y = regy;
assign cf = regcf;
assign of = regof;
assign zf = regzf;
// assign zf = (regy == 0);

always @ (a, b, m) begin
case(m)
3'b000: begin // add
{regcf, regy} = a + b;
regof = (!a[WIDTH-1] & !b[WIDTH-1] & regy[WIDTH-1]) |
(a[WIDTH-1] & b[WIDTH-1] & !regy[WIDTH-1]);
regzf = (regy == 0);
end
3'b001: begin // sub
{regcf, regy} = a - b;
regof = (!a[WIDTH-1] & b[WIDTH-1] & regy[WIDTH-1]) |
(a[WIDTH-1] & !b[WIDTH-1] & !regy[WIDTH-1]);
regzf = (regy == 0);
end
3'b010: begin // and
regy = a & b;
regzf = (regy == 0);
regcf = 0;
regof = 0;
end
3'b011: begin // or
regy = a | b;
regzf = (regy == 0);
regcf = 0;
regof = 0;
end
3'b100: begin // xor
regy = a ^ b;
regzf = (regy == 0);
regcf = 0;
regof = 0;
end
default: begin // error
regy = 0;
regzf = 0;
regcf = 0;
regof = 0;
end
endcase
end
endmodule
Loading

0 comments on commit 64bd1fd

Please sign in to comment.