-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: delete tanker style: gw name feat: add base and third-party examples feat: add vector addition feat: add simd example refactor: boost perfomance via type narrow down fix: delete reduntant movs feat: add simd slice contains style: add comments refactor: add slice header fix: header refactor: add comments fix: comment feat: add some new asm code feat: add lection_1 examples feat: add lection 3 examples feat: add lection_7 examples refactor: delete generated data
- Loading branch information
1 parent
054c2c1
commit 9f4fa21
Showing
78 changed files
with
102,453 additions
and
279 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
.idea | ||
*.prof | ||
*bin | ||
*bin | ||
*.DS_STORE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ loop: | |
|
||
CMPQ R11, CX | ||
|
||
// TODO: open_lesson | ||
CMOVQLE R10, R8 | ||
CMOVQGT R10, R9 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.PHONY: prof | ||
prof: | ||
go test -bench=. -benchmem -cpuprofile=cpu.prof -memprofile=mem.prof |
66 changes: 66 additions & 0 deletions
66
lections/lection_1/cache_contention/cache_contention_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package cache_contention | ||
|
||
import ( | ||
"golang.org/x/sys/cpu" | ||
"math/rand/v2" | ||
"runtime" | ||
"sync" | ||
"sync/atomic" | ||
"testing" | ||
"unsafe" | ||
) | ||
|
||
const cacheLineSize = unsafe.Sizeof(cpu.CacheLinePad{}) | ||
|
||
func BenchmarkCacheContentionWithoutPadding(b *testing.B) { | ||
type WorkerStatistics struct { | ||
Value atomic.Int64 | ||
_ [cacheLineSize - 8]byte | ||
} | ||
|
||
workers := runtime.NumCPU() | ||
statistics := make([]WorkerStatistics, workers) | ||
|
||
wg := new(sync.WaitGroup) | ||
|
||
for workerID := 0; workerID < workers; workerID++ { | ||
wg.Add(1) | ||
go func() { | ||
defer wg.Done() | ||
|
||
for j := 0; j < b.N; j++ { | ||
statistics[workerID].Value.Add(externalStatisticSourceByID(int64(workerID))) | ||
} | ||
}() | ||
} | ||
|
||
wg.Wait() | ||
} | ||
|
||
func BenchmarkCacheContentionWithPadding(b *testing.B) { | ||
type WorkerStatistics struct { | ||
Value atomic.Int64 | ||
} | ||
|
||
workers := runtime.NumCPU() | ||
statistics := make([]WorkerStatistics, workers) | ||
wg := new(sync.WaitGroup) | ||
|
||
for workerID := 0; workerID < workers; workerID++ { | ||
wg.Add(1) | ||
|
||
go func() { | ||
defer wg.Done() | ||
|
||
for j := 0; j < b.N; j++ { | ||
statistics[workerID].Value.Add(externalStatisticSourceByID(int64(workerID))) | ||
} | ||
}() | ||
} | ||
|
||
wg.Wait() | ||
} | ||
|
||
func externalStatisticSourceByID(id int64) int64 { | ||
return rand.N[int64](42*id%10 + 1) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module lection_1 | ||
|
||
go 1.22.1 | ||
|
||
require golang.org/x/sys v0.24.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg= | ||
golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"golang.org/x/sys/cpu" | ||
"unsafe" | ||
) | ||
|
||
const cacheLineSize = unsafe.Sizeof(cpu.CacheLinePad{}) | ||
|
||
func main() { | ||
a := 42 | ||
fmt.Println(fmt.Sprintf("%064b", &a)) | ||
fmt.Println(cacheLineSize) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module lection_1 | ||
|
||
go 1.22.1 | ||
|
||
require golang.org/x/sys v0.24.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg= | ||
golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
.PHONY: test | ||
test: | ||
iverilog -g2001 cpu_test.v | ||
./a.out | ||
|
||
|
||
.PHONY: view | ||
view: | ||
gtkwave dump.vcd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
## Структура процессора | ||
1) Память команд и данных, модуль [memory.v](./cpu-template/memory.v) | ||
2) Регистровый файл, модуль [register_file.v](./cpu-template/register_file.v) | ||
3) Модуль для одиночного 32-битного регистра PC в [d_flop.v](./cpu-template/d_flop.v) | ||
4) Модуль [util.v](./cpu-template/util.v) содержит вспомогательные модули, которые могут быть полезны | ||
при реализации процессора. | ||
|
||
|
||
| Команда | opcode | rs | rt | imm | | ||
|---------|--------|-------|-------|------------------| | ||
| lw | 100011 | xxxxx | xxxxx | xxxxxxxxxxxxxxxx | | ||
| sw | 101011 | xxxxx | xxxxx | xxxxxxxxxxxxxxxx | | ||
| beq | 000100 | xxxxx | xxxxx | xxxxxxxxxxxxxxxx | | ||
|
||
| Команда | opcode | rs | rt | rd | shamt | funct | | ||
|---------|--------|-------|-------|-------|-------|--------| | ||
| add | 000000 | xxxxx | xxxxx | xxxxx | 00000 | 100000 | | ||
| sub | 000000 | xxxxx | xxxxx | xxxxx | 00000 | 100010 | | ||
| and | 000000 | xxxxx | xxxxx | xxxxx | 00000 | 100100 | | ||
| or | 000000 | xxxxx | xxxxx | xxxxx | 00000 | 100101 | | ||
| slt | 000000 | xxxxx | xxxxx | xxxxx | 00000 | 101010 | | ||
|
||
| Команда | opcode | rs | rt | imm | | ||
|---------|--------|-------|-------|------------------| | ||
| addi* | 001000 | xxxxx | xxxxx | xxxxxxxxxxxxxxxx | | ||
| andi* | 001100 | xxxxx | xxxxx | xxxxxxxxxxxxxxxx | | ||
| bne | 000101 | xxxxx | xxxxx | xxxxxxxxxxxxxxxx | | ||
|
||
| Команда | opcode | addr | | ||
|---------|--------|----------------------------| | ||
| j | 000010 | xxxxxxxxxxxxxxxxxxxxxxxxxx | | ||
| jal | 000011 | xxxxxxxxxxxxxxxxxxxxxxxxxx | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
`include "mips_cpu.v" | ||
`include "memory.v" | ||
`include "register_file.v" | ||
`include "d_flop.v" | ||
|
||
module cpu_test(); | ||
reg clk; | ||
|
||
initial begin | ||
$dumpfile("./dump.vcd"); | ||
$dumpvars; | ||
end | ||
|
||
// Инициализируем процессор | ||
wire[31:0] instruction_memory_a, instruction_memory_rd; | ||
|
||
instruction_memory cpu_instruction_memory(.a(instruction_memory_a), .rd(instruction_memory_rd)); | ||
|
||
wire data_memory_we; | ||
wire[31:0] data_memory_a, data_memory_rd, data_memory_wd; | ||
wire[31:0] pc, pc_new; | ||
|
||
d_flop program_counter(.d(pc_new), .clk(clk), .q(pc)); | ||
|
||
data_memory cpu_data_memory(.a(data_memory_a), .we(data_memory_we), .clk(clk), .wd(data_memory_wd), .rd(data_memory_rd)); | ||
|
||
wire register_we3; | ||
wire[4:0] register_a1, register_a2, register_a3; | ||
wire[31:0] register_rd1, register_rd2, register_wd3; | ||
|
||
register_file cpu_register(.clk(clk), | ||
.we3(register_we3), | ||
.a1(register_a1), | ||
.a2(register_a2), | ||
.a3(register_a3), | ||
.wd3(register_wd3), | ||
.rd1(register_rd1), | ||
.rd2(register_rd2)); | ||
|
||
mips_cpu cpu(.clk(clk), | ||
.pc(pc), | ||
.pc_new(pc_new), | ||
.instruction_memory_a(instruction_memory_a), | ||
.instruction_memory_rd(instruction_memory_rd), | ||
.data_memory_a(data_memory_a), | ||
.data_memory_rd(data_memory_rd), | ||
.data_memory_we(data_memory_we), | ||
.data_memory_wd(data_memory_wd), | ||
.register_a1(register_a1), | ||
.register_a2(register_a2), | ||
.register_a3(register_a3), | ||
.register_we3(register_we3), | ||
.register_wd3(register_wd3), | ||
.register_rd1(register_rd1), | ||
.register_rd2(register_rd2)); | ||
|
||
// Testbench | ||
reg[31:0] i_counter, reg_counter, mem_counter; | ||
initial begin | ||
// Выполняем 2023 тактов | ||
for (i_counter = 0; i_counter < 2023; i_counter = i_counter+1) begin | ||
#5 | ||
clk = 1; | ||
#5 | ||
clk = 0; | ||
end | ||
// Дампим регистры | ||
for (reg_counter = 0; reg_counter < 32; reg_counter = reg_counter+1) begin | ||
$display("Register: %d, value: %d", reg_counter, cpu_register.mem[reg_counter]); | ||
end | ||
// Дампим память данных | ||
for (mem_counter = 0; mem_counter < 64; mem_counter = mem_counter+1) begin | ||
$display("Addr: %d, value: %d", mem_counter*4, cpu_data_memory.ram[mem_counter]); | ||
end | ||
end | ||
endmodule |
Oops, something went wrong.