Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
7597 | akron1 | 1 | (* |
2 | BSD 2-Clause License |
||
3 | |||
4 | Copyright (c) 2018, 2019, Anton Krotov |
||
5 | All rights reserved. |
||
6 | *) |
||
7 | |||
8 | MODULE MACHINE; |
||
9 | |||
10 | IMPORT UTILS; |
||
11 | |||
12 | |||
13 | CONST |
||
14 | |||
15 | min32* = -2147483647-1; |
||
16 | max32* = 2147483647; |
||
17 | |||
18 | |||
19 | VAR |
||
20 | |||
21 | target*: |
||
22 | |||
23 | RECORD |
||
24 | |||
25 | bit_depth*, |
||
26 | maxInt*, |
||
27 | minInt*, |
||
28 | maxSet*, |
||
29 | maxHex*: INTEGER; |
||
30 | |||
31 | maxReal*: REAL |
||
32 | |||
33 | END; |
||
34 | |||
35 | _64to32*: BOOLEAN; |
||
36 | |||
37 | |||
38 | PROCEDURE SetBitDepth* (pBitDepth: INTEGER); |
||
39 | BEGIN |
||
40 | ASSERT(pBitDepth <= UTILS.bit_depth); |
||
41 | ASSERT((pBitDepth = 32) OR (pBitDepth = 64)); |
||
42 | |||
43 | _64to32 := (UTILS.bit_depth = 64) & (pBitDepth = 32); |
||
44 | |||
45 | target.bit_depth := pBitDepth; |
||
46 | target.maxSet := pBitDepth - 1; |
||
47 | target.maxHex := pBitDepth DIV 4; |
||
48 | target.minInt := ASR(UTILS.minint, UTILS.bit_depth - pBitDepth); |
||
49 | target.maxInt := ASR(UTILS.maxint, UTILS.bit_depth - pBitDepth); |
||
50 | target.maxReal := 1.9; |
||
51 | PACK(target.maxReal, 1023); |
||
52 | END SetBitDepth; |
||
53 | |||
54 | |||
55 | PROCEDURE Byte* (n: INTEGER; idx: INTEGER): BYTE; |
||
56 | BEGIN |
||
57 | WHILE idx > 0 DO |
||
58 | n := ASR(n, 8); |
||
59 | DEC(idx) |
||
60 | END |
||
61 | |||
62 | RETURN ORD(BITS(n) * {0..7}) |
||
63 | END Byte; |
||
64 | |||
65 | |||
66 | PROCEDURE Align* (VAR bytes: INTEGER; align: INTEGER): BOOLEAN; |
||
67 | VAR |
||
68 | res: BOOLEAN; |
||
69 | |||
70 | BEGIN |
||
71 | IF bytes MOD align # 0 THEN |
||
72 | res := UTILS.maxint - bytes >= align - (bytes MOD align); |
||
73 | IF res THEN |
||
74 | bytes := bytes + align - (bytes MOD align) |
||
75 | END |
||
76 | ELSE |
||
77 | res := TRUE |
||
78 | END |
||
79 | |||
80 | RETURN res |
||
81 | END Align; |
||
82 | |||
83 | |||
84 | PROCEDURE Int32To64* (value: INTEGER): INTEGER; |
||
85 | BEGIN |
||
86 | IF UTILS.bit_depth = 64 THEN |
||
87 | value := LSL(value, 16); |
||
88 | value := LSL(value, 16); |
||
89 | value := ASR(value, 16); |
||
90 | value := ASR(value, 16) |
||
91 | END |
||
92 | |||
93 | RETURN value |
||
94 | END Int32To64; |
||
95 | |||
96 | |||
97 | PROCEDURE Int64To32* (value: INTEGER): INTEGER; |
||
98 | BEGIN |
||
99 | IF UTILS.bit_depth = 64 THEN |
||
100 | value := LSL(value, 16); |
||
101 | value := LSL(value, 16); |
||
102 | value := LSR(value, 16); |
||
103 | value := LSR(value, 16) |
||
104 | END |
||
105 | |||
106 | RETURN value |
||
107 | END Int64To32; |
||
108 | |||
109 | |||
110 | END MACHINE.=> |