diff options
| author | Jedidiah Barber <contact@jedbarber.id.au> | 2026-01-05 22:10:47 +1300 |
|---|---|---|
| committer | Jedidiah Barber <contact@jedbarber.id.au> | 2026-01-05 22:10:47 +1300 |
| commit | a0d71be199c82b78815f64e151a0f208ef87cb05 (patch) | |
| tree | 0deda198199fb238bfdbc9b498286d71d0782772 /src/kompsos-math.adb | |
| parent | 259f5df4d96a958e6cf567725466f92d2e245807 (diff) | |
Small speed improvement to division
Diffstat (limited to 'src/kompsos-math.adb')
| -rw-r--r-- | src/kompsos-math.adb | 54 |
1 files changed, 28 insertions, 26 deletions
diff --git a/src/kompsos-math.adb b/src/kompsos-math.adb index 91743c3..e74ff60 100644 --- a/src/kompsos-math.adb +++ b/src/kompsos-math.adb @@ -793,15 +793,6 @@ package body Kompsos.Math is Remainder_Term : Term renames Inputs (4); One, Two, Three : Goal := This; - - N_Low : constant Term := Three.Fresh; - N_High : constant Term := Three.Fresh; - Quot_Low : constant Term := Three.Fresh; - Quot_High : constant Term := Three.Fresh; - Quot_Low_M : constant Term := Three.Fresh; - Quot_Low_M_Remain : constant Term := Three.Fresh; - Remain_Remain : constant Term := Three.Fresh; - Remain_High : constant Term := Three.Fresh; begin One.Unify (N_Term, Remainder_Term); One.Unify (Quotient_Term, Zero_Term); @@ -815,25 +806,36 @@ package body Kompsos.Math is LT_Length (Three, M_Term & N_Term); LT (Three, Remainder_Term & M_Term); GT_Zero (Three, Quotient_Term); - Three.Conjunct (Split_Access, N_Term & Remainder_Term & N_Low & N_High); - Three.Conjunct (Split_Access, Quotient_Term & Remainder_Term & Quot_Low & Quot_High); declare - Three_A, Three_B : Goal := Three; + N_Low : constant Term := Three.Fresh; + N_High : constant Term := Three.Fresh; + Quot_Low : constant Term := Three.Fresh; + Quot_High : constant Term := Three.Fresh; + Quot_Low_M : constant Term := Three.Fresh; + Quot_Low_M_Remain : constant Term := Three.Fresh; + Remain_Remain : constant Term := Three.Fresh; + Remain_High : constant Term := Three.Fresh; begin - Three_A.Unify (N_High, Zero_Term); - Three_A.Unify (Quot_High, Zero_Term); - Subtract (Three_A, N_Low & Remainder_Term & Quot_Low_M); - Multiply (Three_A, Quot_Low & M_Term & Quot_Low_M); - - GT_Zero (Three_B, N_High); - Multiply (Three_B, Quot_Low & M_Term & Quot_Low_M); - Add (Three_B, Quot_Low_M & Remainder_Term & Quot_Low_M_Remain); - Subtract (Three_B, Quot_Low_M_Remain & N_Low & Remain_Remain); - Three_B.Conjunct (Split_Access, - Remain_Remain & Remainder_Term & Zero_Term & Remain_High); - Three_B.Conjunct (Divide_Access, N_High & M_Term & Quot_High & Remain_High); - - return Disjunct (One & Two & Three_A & Three_B); + Three.Conjunct (Split_Access, N_Term & Remainder_Term & N_Low & N_High); + Three.Conjunct (Split_Access, Quotient_Term & Remainder_Term & Quot_Low & Quot_High); + declare + Three_A, Three_B : Goal := Three; + begin + Three_A.Unify (N_High, Zero_Term); + Three_A.Unify (Quot_High, Zero_Term); + Subtract (Three_A, N_Low & Remainder_Term & Quot_Low_M); + Multiply (Three_A, Quot_Low & M_Term & Quot_Low_M); + + GT_Zero (Three_B, N_High); + Multiply (Three_B, Quot_Low & M_Term & Quot_Low_M); + Add (Three_B, Quot_Low_M & Remainder_Term & Quot_Low_M_Remain); + Subtract (Three_B, Quot_Low_M_Remain & N_Low & Remain_Remain); + Three_B.Conjunct (Split_Access, + Remain_Remain & Remainder_Term & Zero_Term & Remain_High); + Three_B.Conjunct (Divide_Access, N_High & M_Term & Quot_High & Remain_High); + + return Disjunct (One & Two & Three_A & Three_B); + end; end; end Divide; |
