From d042116b7e74c919a3b8a378a9a5a9961219bc54 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Sat, 11 Jan 2014 19:24:02 +0100 Subject: division with a strange bug in the remainder --- cpu/alu.ml | 51 +++++++++++++++++++-------------------------------- cpu/os.asm | 20 ++++++++++---------- 2 files changed, 29 insertions(+), 42 deletions(-) (limited to 'cpu') diff --git a/cpu/alu.ml b/cpu/alu.ml index b76133f..6757c8a 100644 --- a/cpu/alu.ml +++ b/cpu/alu.ml @@ -185,7 +185,7 @@ let nmulu n a b start_signal = -let rec ndivu n a b start_signal = +let rec ndivu n a b start_signal = let next_busy, set_next_busy = loop 1 in let busy = start_signal ^| (reg 1 next_busy) in @@ -200,39 +200,26 @@ let rec ndivu n a b start_signal = bien que le calcul est terminé quand c vaut 0 *) let c , set_c = loop n in - - - - - (* On définit la concaténée des nouvelles valeurs de dd, q, r, et c *) - - let ddqrc = set_dd ( + let c = set_c ( mux start_signal - (* A chaque nouvelle étape *) - ( - - (* A l'itération i (i = 0 ... n - 1) Le bit de poids fort de [dd] - correspond au bit (n-i-1) du dividande original *) - (shiftl1 n (reg n dd)) ++ - q ++ (* Le quotient reste pour l'instant inchangé *) - ((dd ** (n-1)) ++ ((reg n r) % (0, n-2))) ++ (* On abaisse le bit (n-i-1) du dividande *) - shiftl1 n c (* on décale c *) - ) + (shiftl1 n (reg n c)) + ((const "0") ++ (rep (n-1) (const "1"))) ) in - (* Initialisation *) - ((a) ++ (zeroes n) ++ (zeroes n) ++ (rep n (const "1"))) ) - in + (* Initialisation de q et r *) + let q = mux start_signal (reg n q) (zeroes n) in + let r = mux start_signal (reg n r) (zeroes n) in - let dd = set_dd (ddqrc % (0, n-1)) in - let q' = (ddqrc % (n, 2*n-1)) in - let r' = (ddqrc % (2*n, 3*n-1)) in - let c = set_c (ddqrc % (3*n, 4*n-1)) in + (* A l'itération i (i = 0 ... n - 1) Le bit de poids fort de [dd] + correspond au bit (n-i-1) du dividande original *) + let dd = set_dd (mux start_signal (shiftl1 n (reg n dd)) a) in - + (* On abaisse le bit (n-i-1) du dividande *) + let r = (dd ** (n-1)) ++ (r % (0, n-2)) in + (* Si r >= d alors r := r - d et q(n-i-1) := 1 *) - let rq = mux (ule_n n b r') - (r' ++ (const "0") ++ ((reg n q') % (0, n-2))) - ((nsubber n r' b) ++ (const "1") ++ ((reg n q') % (0, n-2))) in + let rq = mux (ule_n n b r) + (r ++ ((const "0") ++ (q % (0, n-2)))) + ((nsubber n r b) ++ ((const "1") ++ (q % (0, n-2)))) in let r = set_r (rq % (0, n-1)) in let q = set_q (rq % (n, 2*n-1)) in @@ -246,15 +233,15 @@ let rec ndivu n a b start_signal = dd ^. c ^. q, r, finished - + -(* zeroes (n-3) ++ const "110", zeroes (n-3) ++ const "110", +(* zeroes (n-3) ++ const "110", zeroes (n-3) ++ const "110", start_signal *) (* TODO : unsigned division, returns quotient and remainder *) let rec nmul n a b start_signal = - zeroes (n-3) ++ const "101", zeroes (n-3) ++ const "101", start_signal + zeroes (n-3) ++ const "101", zeroes (n-3) ++ const "101", start_signal (* TODO : signed multiplication ; returns low part and high part *) diff --git a/cpu/os.asm b/cpu/os.asm index 1617d6b..58fa83b 100644 --- a/cpu/os.asm +++ b/cpu/os.asm @@ -184,23 +184,23 @@ unit_test_1: # Unsigned multiplication unit_test_2: # Unsigned division li B 1 - li C 60 + li C 64 li D 5 divu C C D move D E sei A C 12 and B B A - se A D Z + sei A D 4 and B B A - li C 14129 - li D 477 - divu C C D - move D E - sei A C 31 - and B B A - sei A D 272 - and B B A + #li C 61 + #li D 5 + #divu C C D + #move D E + #sei A C 12 + #and B B A + #sei A D 1 + #and B B A jr RA unit_test_3: # Signed multiplication/division -- cgit v1.2.3 From 930ca54aa228a340e9139def8c0e67dd5c175331 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Sun, 12 Jan 2014 11:32:48 +0100 Subject: there's a strange bug in the division e Please enter the commit message for your changes. Lines starting --- cpu/alu.ml | 10 +++++----- cpu/os.asm | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'cpu') diff --git a/cpu/alu.ml b/cpu/alu.ml index 6757c8a..87cfc10 100644 --- a/cpu/alu.ml +++ b/cpu/alu.ml @@ -190,7 +190,7 @@ let rec ndivu n a b start_signal = let next_busy, set_next_busy = loop 1 in let busy = start_signal ^| (reg 1 next_busy) in - let dd, set_dd = loop n in (* dividande *) + let dd, set_dd = loop n in (* dividende *) let q , set_q = loop n in (* quotient *) let r , set_r = loop n in (* reste *) @@ -210,15 +210,15 @@ let rec ndivu n a b start_signal = let r = mux start_signal (reg n r) (zeroes n) in (* A l'itération i (i = 0 ... n - 1) Le bit de poids fort de [dd] - correspond au bit (n-i-1) du dividande original *) + correspond au bit (n-i-1) du dividende original *) let dd = set_dd (mux start_signal (shiftl1 n (reg n dd)) a) in - (* On abaisse le bit (n-i-1) du dividande *) + (* On abaisse le bit (n-i-1) du dividende *) let r = (dd ** (n-1)) ++ (r % (0, n-2)) in (* Si r >= d alors r := r - d et q(n-i-1) := 1 *) let rq = mux (ule_n n b r) - (r ++ ((const "0") ++ (q % (0, n-2)))) + (r ++ ((const "0") ++ (q % (0, n-2)))) ((nsubber n r b) ++ ((const "1") ++ (q % (0, n-2)))) in let r = set_r (rq % (0, n-1)) in @@ -230,7 +230,7 @@ let rec ndivu n a b start_signal = set_next_busy (busy ^& work_remains) ^. (not work_remains) ^& busy in - dd ^. c ^. + dd ^. c ^. q, r, finished diff --git a/cpu/os.asm b/cpu/os.asm index 58fa83b..7c271f0 100644 --- a/cpu/os.asm +++ b/cpu/os.asm @@ -184,13 +184,13 @@ unit_test_1: # Unsigned multiplication unit_test_2: # Unsigned division li B 1 - li C 64 + li C 61 li D 5 divu C C D move D E sei A C 12 and B B A - sei A D 4 + sei A D 1 and B B A #li C 61 -- cgit v1.2.3