blob: 90c026204fcdf4b2833deb08c7ff6709caad6cc3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
|
{
This file is part of the Free Pascal run time library.
Copyright (c) 2004 by Marco van de Voort, member of the
Free Pascal development team
Implements C types for in header conversions
See the file COPYING.FPC, included in this distribution,
for details about the copyright.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
**********************************************************************}
unit ctypes;
{$ifdef FPC}
{$inline on}
{$define dummy}
{$endif}
interface
{$ifdef unix}
uses unixtype;
{$i aliasctp.inc}
{$else}
type
{$ifndef FPC}
qword = int64; // Keep h2pas "uses ctypes" headers working with delphi.
ptruint = cardinal;
pptruint = ^ptruint;
{$endif}
{ the following type definitions are compiler dependant }
{ and system dependant }
cint8 = shortint; pcint8 = ^cint8;
cuint8 = byte; pcuint8 = ^cuint8;
cchar = cint8; pcchar = ^cchar;
cschar = cint8; pcschar = ^cschar;
cuchar = cuint8; pcuchar = ^cuchar;
cint16 = smallint; pcint16 = ^cint16;
cuint16 = word; pcuint16 = ^cuint16;
cshort = cint16; pcshort = ^cshort;
csshort = cint16; pcsshort = ^csshort;
cushort = cuint16; pcushort = ^cushort;
cint32 = longint; pcint32 = ^cint32;
cuint32 = longword; pcuint32 = ^cuint32;
cint64 = int64; pcint64 = ^cint64;
cuint64 = qword; pcuint64 = ^cuint64;
clonglong = cint64; pclonglong = ^clonglong;
cslonglong = cint64; pcslonglong = ^cslonglong;
culonglong = cuint64; pculonglong = ^culonglong;
cbool = longbool; pcbool = ^cbool;
{$if defined(cpu64) and not(defined(win64) and defined(cpux86_64))}
cint = cint32; pcint = ^cint; { minimum range is : 32-bit }
csint = cint32; pcsint = ^csint; { minimum range is : 32-bit }
cuint = cuint32; pcuint = ^cuint; { minimum range is : 32-bit }
clong = int64; pclong = ^clong;
cslong = int64; pcslong = ^cslong;
culong = qword; pculong = ^culong;
{$elseif defined(cpu16)}
{ 16-bit int sizes checked against Borland C++ 3.1 and Open Watcom 1.9 }
cint = cint16; pcint = ^cint;
csint = cint16; pcsint = ^csint;
cuint = cuint16; pcuint = ^cuint;
clong = longint; pclong = ^clong;
cslong = longint; pcslong = ^cslong;
culong = cardinal; pculong = ^culong;
{$else}
cint = cint32; pcint = ^cint; { minimum range is : 32-bit }
csint = cint32; pcsint = ^csint; { minimum range is : 32-bit }
cuint = cuint32; pcuint = ^cuint; { minimum range is : 32-bit }
clong = longint; pclong = ^clong;
cslong = longint; pcslong = ^cslong;
culong = cardinal; pculong = ^culong;
{$ifend}
csigned = cint; pcsigned = ^csigned;
cunsigned = cuint; pcunsigned = ^cunsigned;
csize_t = ptruint; pcsize_t = pptruint;
// Kylix compat types
u_long = culong;
u_short = cushort;
coff_t = clong;
{$ifndef FPUNONE}
cfloat = single; pcfloat = ^cfloat;
cdouble = double; pcdouble = ^cdouble;
{$endif}
{$endif}
{$if defined(win64) or defined(wince) or defined(android)}
{$define longdouble_is_double}
{$endif}
{$if defined(linux) and (defined(cpupowerpc) or defined(cpuarm))}
{$define longdouble_is_double}
{$ifend}
{$if defined(darwin) and defined(cpuaarch64)}
{$define longdouble_is_double}
{$ifend}
{$ifndef FPUNONE}
{$if defined(longdouble_is_double) or not defined(FPC_HAS_CEXTENDED)}
clongdouble=double;
{$else}
{$if defined(cpui8086) or defined(cpui386) or defined(cpux86_64) or defined(cpuavr)}
clongdouble = cextended;
{$else}
{$define longdouble_assignment_overload_real128}
clongdouble = packed array [0..15] of byte;
{$ifend}
{$ifend}
Pclongdouble=^clongdouble;
{$ifdef longdouble_assignment_overload_real128}
{Non-x86 typically doesn't have extended. To be fixed once this changes.}
operator := (const v:clongdouble) r:double;inline;
operator := (const v:double) r:clongdouble;inline;
{$ifdef dummy}
operator +(const e:Double;const c:clongdouble) r:Double;inline;
operator +(const c:clongdouble;const e:Double) r:Double;inline;
operator -(const e:Double;const c:clongdouble) r:Double;inline;
operator -(const c:clongdouble;const e:Double) r:Double;inline;
operator *(const e:Double;const c:clongdouble) r:Double;inline;
operator *(const c:clongdouble;const e:Double) r:Double;inline;
operator /(const e:Double;const c:clongdouble) r:Double;inline;
operator /(const c:clongdouble;const e:Double) r:Double;inline;
operator =(const e:Double;const c:clongdouble) r:boolean;inline;
operator =(const c:clongdouble;const e:Double) r:boolean;inline;
operator <(const e:Double;const c:clongdouble) r:boolean;inline;
operator <(const c:clongdouble;const e:Double) r:boolean;inline;
operator >(const e:Double;const c:clongdouble) r:boolean;inline;
operator >(const c:clongdouble;const e:Double) r:boolean;inline;
operator >=(const e:Double;const c:clongdouble) r:boolean;inline;
operator >=(const c:clongdouble;const e:Double) r:boolean;inline;
operator <=(const e:Double;const c:clongdouble) r:boolean;inline;
operator <=(const c:clongdouble;const e:Double) r:boolean;inline;
{$endif dummy}
{$endif}
{$endif FPUNONE}
implementation
{$ifndef FPUNONE}
{$ifdef longdouble_assignment_overload_real128}
{$ifdef ENDIAN_LITTLE}
const r128_mantissa_ofs=0;
r128_exponent_ofs=14;
{$else}
const r128_mantissa_ofs=2;
r128_exponent_ofs=0;
{$ifdef FPC_REQUIRES_PROPER_ALIGNMENT}
{$define USE_UNALIGNED}
{$endif FPC_REQUIRES_PROPER_ALIGNMENT}
{$endif}
operator := (const v:clongdouble) r:double;
var
exp : word;
mant : qword;
is_neg : boolean;
begin
is_neg:=(pword(@v[r128_exponent_ofs])^and $8000)<>0;
exp:=((Pword(@v[r128_exponent_ofs])^and $7fff)-$4000)+$400;
if is_neg then
exp:=exp+$800;
{$ifdef USE_UNALIGNED}
mant:=unaligned(Pqword(@v[r128_mantissa_ofs])^);
{$else not USE_UNALIGNED}
mant:=Pqword(@v[r128_mantissa_ofs])^;
{$endif not USE_UNALIGNED}
qword(r):=(qword(exp) shl 52) or
(mant shr 12);
end;
operator := (const v:double) r:clongdouble;
var
is_neg : boolean;
exp : word;
begin
is_neg:=(qword(v) shr 63) <> 0;
exp:=$4000 + ((qword(v) shr 52) and $7ff) -$400;
if is_neg then
exp:=exp+$8000;
Pword(@r[r128_exponent_ofs])^:=exp;
{$ifdef USE_UNALIGNED}
unaligned(Pqword(@r[r128_mantissa_ofs])^):=qword(v) shl 12;
Pword(@r[r128_mantissa_ofs+8])^:=0;
Pword(@r[r128_mantissa_ofs+10])^:=0;
{$else not USE_UNALIGNED}
Pqword(@r[r128_mantissa_ofs])^:=qword(v) shl 12;
Pcardinal(@r[r128_mantissa_ofs+8])^:=0;
{$endif not USE_UNALIGNED}
Pword(@r[r128_mantissa_ofs+12])^:=0;
end;
{$ifdef dummy}
// There is no record with a value field in this case
operator +(const e:Double;const c:clongdouble) r:Double;inline;
begin
r:=e+double(c);
end;
operator +(const c:clongdouble;const e:Double) r:Double;inline;
begin
r:=double(c)+e;
end;
operator -(const e:Double;const c:clongdouble) r:Double;inline;
begin
r:=e-double(c);
end;
operator -(const c:clongdouble;const e:Double) r:Double;inline;
begin
r:=double(c)-e;
end;
operator *(const e:Double;const c:clongdouble) r:Double;inline;
begin
r:=e*double(c);
end;
operator *(const c:clongdouble;const e:Double) r:Double;inline;
begin
r:=double(c)*e;
end;
operator /(const e:Double;const c:clongdouble) r:Double;inline;
begin
r:=e/double(c);
end;
operator /(const c:clongdouble;const e:Double) r:Double;inline;
begin
r:=double(c)/e;
end;
operator =(const e:Double;const c:clongdouble) r:boolean;inline;
begin
r:=e=double(c);
end;
operator =(const c:clongdouble;const e:Double) r:boolean;inline;
begin
r:=double(c)=e;
end;
operator <(const e:Double;const c:clongdouble) r:boolean;inline;
begin
r:=e<double(c);
end;
operator <(const c:clongdouble;const e:Double) r:boolean;inline;
begin
r:=double(c)<e;
end;
operator >(const e:Double;const c:clongdouble) r:boolean;inline;
begin
r:=e>double(c);
end;
operator >(const c:clongdouble;const e:Double) r:boolean;inline;
begin
r:=double(c)>e;
end;
operator >=(const e:Double;const c:clongdouble) r:boolean;inline;
begin
r:=e>=double(c);
end;
operator >=(const c:clongdouble;const e:Double) r:boolean;inline;
begin
r:=double(c)>=e;
end;
operator <=(const e:Double;const c:clongdouble) r:boolean;inline;
begin
r:=e<=double(c);
end;
operator <=(const c:clongdouble;const e:Double) r:boolean;inline;
begin
r:=double(c)<=e;
end;
{$endif}
{$endif}
{$endif FPUNONE}
end.
|