2
This file is part of the Free Pascal simulator environment
3
Copyright (c) 1999-2000 by Florian Klaempfl
5
This unit implemements routines for data types which aren't
6
support by commonly used compilers
8
See the file COPYING.FPC, included in this distribution,
9
for details about the copyright.
11
This program is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15
**********************************************************************}
17
{ we do some strange things here }
27
procedure byte_zap(q : qword;b : byte;var r : qword);
29
{ shifts q b bytes left }
30
procedure shift_left_q(q : qword;b : byte;var r : qword);
32
{ shifts q b bytes right }
33
procedure shift_right_q(q : qword;b : byte;var r : qword);
35
{ returns true if i1<i2 assuming that c1 and c2 are unsigned !}
36
function ltu(c1,c2 : qword) : boolean;
38
{ returns true if i1=<i2 assuming that c1 and c2 are unsigned !}
39
function leu(c1,c2 : qword) : boolean;
41
{ adds to owords, returns true if an overflow occurs }
42
function addoword(o1,o2 : oword;var r : oword) : boolean;
44
{ adds two words, returns true if an overflow occurs }
45
function addword(w1,w2 : word;var r : word) : boolean;
47
{ sets an oword to zero }
48
procedure zerooword(var o : oword);
50
{ multiplies two qwords into a full oword }
51
procedure mulqword(q1,q2 : qword;var r : oword);
55
procedure byte_zap(q : qword;b : byte;var r : qword);
62
if ((1 shl i) and b)=0 then
63
tqwordrec(r).bytes[i]:=tqwordrec(q).bytes[i]
65
tqwordrec(r).bytes[i]:=0;
68
{ shifts q b bytes left }
69
procedure shift_left_q(q : qword;b : byte;var r : qword);
78
tqwordrec(r).high32:=tqwordrec(q).low32 shl (b-32)
81
{ bad solution! A qword shift would be nice! }
85
tqwordrec(r).high32:=tqwordrec(r).high32 shl 1;
86
if (tqwordrec(r).low32 and $80000000)<>0 then
87
tqwordrec(r).high32:=tqwordrec(r).high32 or 1;
88
tqwordrec(r).low32:=tqwordrec(r).low32 shl 1;
93
{ shifts q b bytes right }
94
procedure shift_right_q(q : qword;b : byte;var r : qword);
103
tqwordrec(r).low32:=tqwordrec(q).high32 shr (b-32)
106
{ bad solution! A qword shift would be nice! }
110
tqwordrec(r).low32:=tqwordrec(r).low32 shr 1;
111
if (tqwordrec(r).high32 and 1)<>0 then
112
tqwordrec(r).low32:=tqwordrec(r).low32 or
114
tqwordrec(r).high32:=tqwordrec(r).high32 shr 1;
119
{ returns true if i1<i2 assuming that c1 and c2 are unsigned !}
120
function ltu(c1,c2 : qword) : boolean;
123
if (c1>=0) and (c2>=0) then
125
else if (c1<0) and (c2>=0) then
127
else if (c1>=0) and (c2<0) then
133
{ returns true if i1=<i2 assuming that c1 and c2 are unsigned !}
134
function leu(c1,c2 : qword) : boolean;
137
if (c1>=0) and (c2>=0) then
139
else if (c1<0) and (c2>=0) then
141
else if (c1>=0) and (c2<0) then
147
{ "ands" two qwords }
148
procedure andqword(w1,w2 : qword;var r : qword);
151
tqwordrec(r).low32:=tqwordrec(w1).low32 and tqwordrec(w2).low32;
152
tqwordrec(r).high32:=tqwordrec(w1).high32 and tqwordrec(w2).high32;
155
{ adds two words, returns true if an overflow occurs }
156
function addword(w1,w2 : word;var r : word) : boolean;
163
addword:=(l and $10000)<>0;
167
{ adds two owords, returns true if an overflow occurs }
168
function addoword(o1,o2 : oword;var r : oword) : boolean;
178
r[i]:=o1[i]+o2[i]+carry;
179
{ an overflow has occured, if the r is less
180
than one of the summands
182
if (r[i]<o1[i]) or (r[i]<o2[i]) then
190
{ sets an oword to zero }
191
procedure zerooword(var o : oword);
194
fillchar(o,sizeof(o),0);
197
{ multiplies two qwords into a full oword }
198
procedure mulqword(q1,q2 : qword;var r : oword);
209
towordrec(ho1).low64:=q1;
215
andqword(q2,bitpos,h);
220
addoword(ho1,ho1,ho1);
221
shift_left_q(bitpos,1,bitpos);