Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Martin Pepin
sysdig
Commits
7542f7ed
Commit
7542f7ed
authored
Jan 14, 2017
by
Martin Pépin
Browse files
Merge branch 'master' of git.eleves.ens.fr:mpepin/sysdig
parents
af5bb09a
6d44b0d7
Changes
2
Hide whitespace changes
Inline
Side-by-side
cpu/src/alu/utils.mj
View file @
7542f7ed
...
...
@@ -32,6 +32,31 @@ extand_const_n<n, offset>(c:[n]) = (o:[n + offset]) where
end where
(* logical shifts *)
shift_by_const_n<n, m, shift_val>(input:[n], const:[m], is_right, keep_sign) =
(out:[n]) where
aux = mux(const[m-1],
mux(is_right,
extand_right_n<n - shift_val, shift_val>
(input[..(n-1) - shift_val], mux(keep_sign, input[0])),
extand_left_n<n - shift_val, shift_val>
(input[shift_val..])),
input);
if 2 * shift_val > n then
out = shift_by_const_n<n, m-1, n>(aux, const[..m-2], is_right, keep_sign);
else
out = shift_by_const_n<n, m-1, 2*shift_val>
(aux, const[..m-2], is_right, keep_sign);
end where
(* shift by shamt, either to the right or to the left. Arithmetic or not.*)
shift_by_shamt_ALU(input:[32], shamt:[5], is_right, keep_sign) = (out:[32]) where
out = shift_by_const_n<32, 5, 1>(input, shamt, is_right, keep_sign)
end where
(* shift by value stored in reg, to the right or left, arithmetic or not *)
shift_by_reg_ALU(input:[32], const:[32], is_right, keep_sign) = (out:[32]) where
out = shift_by_const_n<32, 32, 1>(input, const, is_right, keep_sign)
(* ------------------------------------------------------------------------- *)
(* Opérations booléennes *)
...
...
@@ -96,7 +121,9 @@ not_n<n>(a:[n]) = (o:[n]) where
end if
end where
nor_ALU(a:[32], b:[32]) = (o:[32]) where
o = not_n<32>(or_ALU(a, b));
end where
(* ------------------------------------------------------------------------- *)
(*Opérations arithmétiques *)
...
...
@@ -126,14 +153,12 @@ end where
(* Fonction d'addition, qui fait la soustraction si le drapeau vaut 1 *)
(* flag est le drapeau d'overflow, sub le drapeau de soustraction *)
add_ALU(a:[32], b:[32], sub) = (o:[32]
, flag
) where
add_ALU(a:[32], b:[32], sub) = (o:[32]) where
(o, flag) = adder_n<32>(a, mux(sub, change_sign_n<32>(b), b), 0);
zero = equal_zero_n<32>(o);
end where
addi_ALU(a:[32], c:[16], sub) = (o:[32]
, flag
) where
addi_ALU(a:[32], c:[16], sub) = (o:[32]) where
(o, flag) = add_ALU(a, extand_const_n<16,16>(c), sub);
zero = equal_zero_n<32>(o);
end where
(* Une fonction multiplication absolument peu pratique *)
...
...
cpu/src/control.mj
View file @
7542f7ed
require utils
(* Bloc de control du micro-processeur
Entrée : les 6 premiers bits d'une instruction
Sortie : les drapeaux de contrôle utilisés pour contrôler différents
blocs en fonction de l'instruction courante
...
...
@@ -10,7 +10,7 @@ require utils
control(instruction:[6]) = (reg_dst, jump, branch, mem_read, mem_to_reg,
alu_op:[3], mem_write, alu_src, reg_write,
write_pc) where
(* Variable interne égale à 1 s'il s'agit d'une instruction de branchement,
beq ou bne *)
is_branch = equal_n<5>(instruction[0..4], 0.0.0.1.0);
...
...
@@ -35,20 +35,25 @@ control(instruction:[6]) = (reg_dst, jump, branch, mem_read, mem_to_reg,
Uniquement utilisé par les trois instructions de lecture mémoire *)
mem_to_reg = mem_read;
(* alu_op à 00 => lecture/écriture mémoire nécéssitant une addition
(pour calculer l'adresse)
alu_op à 01 => branchement en cas d'(in)égalité nécéssitant
une soustraction
alu_op à 10 => choix d'instruction laissé au bloc de contrôle de l'ALU
(selon funct) *)
alu_op = not instruction[0] . is_branch . 1; (* TODO *)
(* Cas 11 supposé ignoré par alu_control *)
(* alu_op => cf google doc pour savoir quelles valeurs sont associées avec
quelles instructions
Remarque : la gestion actuelle fait que 000 est attribué aux R-format*)
alu_op =
mux(instruction[0], 1,
mux(instruction[2] & (not instruction[3])), 1, 0) .
mux((instruction[2] & instruction[3]) & (instruction[4] xor instruction[5]),
1, 0) .
mux((instruction[2] xor instruction[5]) &
not(instruction[0]) &
instruction[3] or instruction[4],
1, 0);
(* mem_write à 1 => mémoire RAM accédée en écriture
Uniquement utilisé par les trois instructions d'écriture mémoire *)
mem_write = instruction[0] and instruction[2];
(* alu_src à 1 => seconde entré de l'ALU = valeur immédiate
(* alu_src à 1 => seconde entré de l'ALU = valeur immédiate
Ce cas est vrai pour tout format I, sauf pour les branchements
Ces instructions sont caractérisées par un des trois premiers bits à 1 *)
alu_src = instruction[0] or instruction[1] or instruction[2];
...
...
@@ -104,7 +109,7 @@ ALU_control(funct:[6], op:[3]) = (alu_op:[4], use_shamt) where
or (op[1] and op[2]); (* xori *)
(* Bit 4 à 1 si => TODO *)
alu_op_4 = 0
;
alu_op_4 = 0
(* or use_shamt *); (* si modif, bouger use_shamt avant*)
alu_op = alu_op_1 . alu_op_2 . alu_op_3 . alu_op_4;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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