summaryrefslogtreecommitdiffstats
path: root/private/ntos/rtl/recip.c
diff options
context:
space:
mode:
authorAdam <you@example.com>2020-05-17 05:51:50 +0200
committerAdam <you@example.com>2020-05-17 05:51:50 +0200
commite611b132f9b8abe35b362e5870b74bce94a1e58e (patch)
treea5781d2ec0e085eeca33cf350cf878f2efea6fe5 /private/ntos/rtl/recip.c
downloadNT4.0-e611b132f9b8abe35b362e5870b74bce94a1e58e.tar
NT4.0-e611b132f9b8abe35b362e5870b74bce94a1e58e.tar.gz
NT4.0-e611b132f9b8abe35b362e5870b74bce94a1e58e.tar.bz2
NT4.0-e611b132f9b8abe35b362e5870b74bce94a1e58e.tar.lz
NT4.0-e611b132f9b8abe35b362e5870b74bce94a1e58e.tar.xz
NT4.0-e611b132f9b8abe35b362e5870b74bce94a1e58e.tar.zst
NT4.0-e611b132f9b8abe35b362e5870b74bce94a1e58e.zip
Diffstat (limited to 'private/ntos/rtl/recip.c')
-rw-r--r--private/ntos/rtl/recip.c92
1 files changed, 92 insertions, 0 deletions
diff --git a/private/ntos/rtl/recip.c b/private/ntos/rtl/recip.c
new file mode 100644
index 000000000..603aeea24
--- /dev/null
+++ b/private/ntos/rtl/recip.c
@@ -0,0 +1,92 @@
+/*++
+
+Copyright (c) 1989 Microsoft Corporation
+
+Module Name:
+
+ recip.c
+
+Abstract:
+
+ This module generates reciprocol fractions for implementing integer
+ division by multiplication.
+
+Author:
+
+ David N. Cutler (davec) 13-May-1989
+
+Environment:
+
+ User mode.
+
+Revision History:
+
+--*/
+
+#include <stdio.h>
+
+typedef struct _large_integer {
+ unsigned long LowPart;
+ long HighPart;
+ } large_integer;
+
+//long Divisors[] = {2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 0};
+long Divisors[] = {10, 10000, 10000000, 86400000, 0};
+
+void
+main (argc, argv)
+ int argc;
+ char *argv[];
+{
+
+ large_integer Fraction;
+ long Index;
+ long NumberBits;
+ long Remainder;
+
+ long i;
+
+ //
+ // Compute first few reciprocols.
+ //
+
+ for (Index = Divisors[i = 0]; Index != 0L; Index = Divisors[++i]) {
+ NumberBits = 0L;
+ Remainder = 1L;
+ Fraction.LowPart = 0L;
+ Fraction.HighPart = 0L;
+ while (Fraction.HighPart >= 0L) {
+ NumberBits += 1L;
+ Fraction.HighPart <<= 1L;
+ if ((Fraction.LowPart & 0x80000000) != 0L) {
+ Fraction.HighPart += 1L;
+ }
+ Fraction.LowPart <<= 1L;
+ Remainder <<= 1L;
+ if (Remainder >= Index) {
+ Remainder -= Index;
+ Fraction.LowPart |= 1L;
+ }
+ }
+ if (Remainder) {
+ if ((Fraction.LowPart == -1L) && (Fraction.HighPart == -1L)) {
+ Fraction.LowPart = 0L;
+ Fraction.HighPart = 0x80000000;
+ NumberBits -= 1L;
+ } else {
+ if (Fraction.LowPart == -1L) {
+ Fraction.LowPart = 0L;
+ Fraction.HighPart += 1L;
+ } else {
+ Fraction.LowPart += 1L;
+ }
+ }
+ }
+
+ printf("Divisor %2ld, Fraction %8lx, %8lx Shift %ld\n", Index,
+ Fraction.HighPart, Fraction.LowPart, NumberBits - 64L);
+ }
+
+ return;
+}
+