generic.inc 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1999-2000 by the Free Pascal development team.
  5. Processor independent implementation for the system unit
  6. (adapted for intel i386.inc file)
  7. See the file COPYING.FPC, included in this distribution,
  8. for details about the copyright.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  12. **********************************************************************}
  13. {****************************************************************************
  14. Primitives
  15. ****************************************************************************}
  16. type
  17. pstring = ^shortstring;
  18. {$ifndef FPC_SYSTEM_HAS_MOVE}
  19. procedure Move(const source;var dest;count:SizeInt);[public, alias: 'FPC_MOVE'];
  20. type
  21. bytearray = array [0..maxlongint-1] of byte;
  22. var
  23. i:longint;
  24. begin
  25. if count <= 0 then exit;
  26. Dec(count);
  27. if @source<@dest then
  28. begin
  29. for i:=count downto 0 do
  30. bytearray(dest)[i]:=bytearray(source)[i];
  31. end
  32. else
  33. begin
  34. for i:=0 to count do
  35. bytearray(dest)[i]:=bytearray(source)[i];
  36. end;
  37. end;
  38. {$endif not FPC_SYSTEM_HAS_MOVE}
  39. {$ifndef FPC_SYSTEM_HAS_FILLCHAR}
  40. Procedure FillChar(var x;count:SizeInt;value:byte);
  41. type
  42. longintarray = array [0..maxlongint div 4] of longint;
  43. bytearray = array [0..maxlongint-1] of byte;
  44. var
  45. i,v : longint;
  46. begin
  47. if count <= 0 then exit;
  48. v := 0;
  49. { aligned? }
  50. if (PtrUInt(@x) mod sizeof(PtrUInt))<>0 then
  51. begin
  52. for i:=0 to count-1 do
  53. bytearray(x)[i]:=value;
  54. end
  55. else
  56. begin
  57. v:=(value shl 8) or (value and $FF);
  58. v:=(v shl 16) or (v and $ffff);
  59. for i:=0 to (count div 4)-1 do
  60. longintarray(x)[i]:=v;
  61. for i:=(count div 4)*4 to count-1 do
  62. bytearray(x)[i]:=value;
  63. end;
  64. end;
  65. {$endif FPC_SYSTEM_HAS_FILLCHAR}
  66. {$ifndef FPC_SYSTEM_HAS_FILLBYTE}
  67. procedure FillByte (var x;count : SizeInt;value : byte );
  68. begin
  69. FillChar (X,Count,CHR(VALUE));
  70. end;
  71. {$endif not FPC_SYSTEM_HAS_FILLBYTE}
  72. {$ifndef FPC_SYSTEM_HAS_FILLWORD}
  73. procedure fillword(var x;count : SizeInt;value : word);
  74. type
  75. longintarray = array [0..maxlongint div 4] of longint;
  76. wordarray = array [0..maxlongint div 2] of word;
  77. var
  78. i,v : longint;
  79. begin
  80. if Count <= 0 then exit;
  81. { aligned? }
  82. if (PtrUInt(@x) mod sizeof(PtrUInt))<>0 then
  83. begin
  84. for i:=0 to count-1 do
  85. wordarray(x)[i]:=value;
  86. end
  87. else
  88. begin
  89. v:=value*$10000+value;
  90. for i:=0 to (count div 2) -1 do
  91. longintarray(x)[i]:=v;
  92. for i:=(count div 2)*2 to count-1 do
  93. wordarray(x)[i]:=value;
  94. end;
  95. end;
  96. {$endif not FPC_SYSTEM_HAS_FILLWORD}
  97. {$ifndef FPC_SYSTEM_HAS_FILLDWORD}
  98. procedure FillDWord(var x;count : SizeInt;value : DWord);
  99. type
  100. longintarray = array [0..maxlongint div 4] of longint;
  101. begin
  102. if count <= 0 then exit;
  103. while Count<>0 do
  104. begin
  105. { range checking must be disabled here }
  106. longintarray(x)[count-1]:=longint(value);
  107. Dec(count);
  108. end;
  109. end;
  110. {$endif FPC_SYSTEM_HAS_FILLDWORD}
  111. {$ifndef FPC_SYSTEM_HAS_INDEXCHAR}
  112. function IndexChar(Const buf;len:SizeInt;b:char):SizeInt;
  113. begin
  114. IndexChar:=IndexByte(Buf,Len,byte(B));
  115. end;
  116. {$endif not FPC_SYSTEM_HAS_INDEXCHAR}
  117. {$ifndef FPC_SYSTEM_HAS_INDEXBYTE}
  118. function IndexByte(Const buf;len:SizeInt;b:byte):SizeInt;
  119. type
  120. bytearray = array [0..maxlongint-1] of byte;
  121. var
  122. I : longint;
  123. begin
  124. I:=0;
  125. { simulate assembler implementations behaviour, which is expected }
  126. { fpc_pchar_to_ansistr in astrings.inc }
  127. if (len < 0) then
  128. len := high(longint);
  129. while (I<Len) and (bytearray(buf)[I]<>b) do
  130. inc(I);
  131. if (i=Len) then
  132. i:=-1; {Can't use 0, since it is a possible value}
  133. IndexByte:=I;
  134. end;
  135. {$endif not FPC_SYSTEM_HAS_INDEXBYTE}
  136. {$ifndef FPC_SYSTEM_HAS_INDEXWORD}
  137. function Indexword(Const buf;len:SizeInt;b:word):SizeInt;
  138. type
  139. wordarray = array [0..maxlongint div 2] of word;
  140. var
  141. I : longint;
  142. begin
  143. I:=0;
  144. if (len < 0) then
  145. len := high(longint);
  146. while (I<Len) and (wordarray(buf)[I]<>b) do
  147. inc(I);
  148. if (i=Len) then
  149. i:=-1; {Can't use 0, since it is a possible value for index}
  150. Indexword:=I;
  151. end;
  152. {$endif not FPC_SYSTEM_HAS_INDEXWORD}
  153. {$ifndef FPC_SYSTEM_HAS_INDEXDWORD}
  154. function IndexDWord(Const buf;len:SizeInt;b:DWord):SizeInt;
  155. type
  156. dwordarray = array [0..maxlongint div 4] of dword;
  157. var
  158. I : longint;
  159. begin
  160. I:=0;
  161. if (len < 0) then
  162. len := high(longint);
  163. while (I<Len) and (dwordarray(buf)[I]<>b) do
  164. inc(I);
  165. if (i=Len) then
  166. i:=-1; {Can't use 0, since it is a possible value for index}
  167. IndexDWord:=I;
  168. end;
  169. {$endif not FPC_SYSTEM_HAS_INDEXDWORD}
  170. {$ifndef FPC_SYSTEM_HAS_COMPARECHAR}
  171. function CompareChar(Const buf1,buf2;len:SizeInt):SizeInt;
  172. begin
  173. CompareChar:=CompareByte(buf1,buf2,len);
  174. end;
  175. {$endif not FPC_SYSTEM_HAS_COMPARECHAR}
  176. {$ifndef FPC_SYSTEM_HAS_COMPAREBYTE}
  177. function CompareByte(Const buf1,buf2;len:SizeInt):SizeInt;
  178. type
  179. bytearray = array [0..maxlongint-1] of byte;
  180. var
  181. I : longint;
  182. begin
  183. I:=0;
  184. if (Len<>0) and (@Buf1<>@Buf2) then
  185. begin
  186. while (bytearray(Buf1)[I]=bytearray(Buf2)[I]) and (I<Len) do
  187. inc(I);
  188. if I=Len then {No difference}
  189. I:=0
  190. else
  191. begin
  192. I:=bytearray(Buf1)[I]-bytearray(Buf2)[I];
  193. if I>0 then
  194. I:=1
  195. else
  196. if I<0 then
  197. I:=-1;
  198. end;
  199. end;
  200. CompareByte:=I;
  201. end;
  202. {$endif not FPC_SYSTEM_HAS_COMPAREBYTE}
  203. {$ifndef FPC_SYSTEM_HAS_COMPAREWORD}
  204. function CompareWord(Const buf1,buf2;len:SizeInt):SizeInt;
  205. type
  206. wordarray = array [0..maxlongint div 2] of word;
  207. var
  208. I : longint;
  209. begin
  210. I:=0;
  211. if (Len<>0) and (@Buf1<>@Buf2) then
  212. begin
  213. while (wordarray(Buf1)[I]=wordarray(Buf2)[I]) and (I<Len) do
  214. inc(I);
  215. if I=Len then {No difference}
  216. I:=0
  217. else
  218. begin
  219. I:=wordarray(Buf1)[I]-wordarray(Buf2)[I];
  220. if I>0 then
  221. I:=1
  222. else
  223. if I<0 then
  224. I:=-1;
  225. end;
  226. end;
  227. CompareWord:=I;
  228. end;
  229. {$endif not FPC_SYSTEM_HAS_COMPAREWORD}
  230. {$ifndef FPC_SYSTEM_HAS_COMPAREDWORD}
  231. function CompareDWord(Const buf1,buf2;len:SizeInt):SizeInt;
  232. type
  233. longintarray = array [0..maxlongint div 4] of longint;
  234. var
  235. I : longint;
  236. begin
  237. I:=0;
  238. if (Len<>0) and (@Buf1<>@Buf2) then
  239. begin
  240. while (longintarray(Buf1)[I]=longintarray(Buf2)[I]) and (I<Len) do
  241. inc(I);
  242. if I=Len then {No difference}
  243. I:=0
  244. else
  245. begin
  246. I:=longintarray(Buf1)[I]-longintarray(Buf2)[I];
  247. if I>0 then
  248. I:=1
  249. else
  250. if I<0 then
  251. I:=-1;
  252. end;
  253. end;
  254. CompareDWord:=I;
  255. end;
  256. {$endif ndef FPC_SYSTEM_HAS_COMPAREDWORD}
  257. {$ifndef FPC_SYSTEM_HAS_MOVECHAR0}
  258. procedure MoveChar0(Const buf1;var buf2;len:SizeInt);
  259. var
  260. I : longint;
  261. begin
  262. if Len = 0 then exit;
  263. I:=IndexByte(Buf1,Len,0);
  264. if I<>-1 then
  265. Move(Buf1,Buf2,I)
  266. else
  267. Move(Buf1,Buf2,len);
  268. end;
  269. {$endif ndef FPC_SYSTEM_HAS_MOVECHAR0}
  270. {$ifndef FPC_SYSTEM_HAS_INDEXCHAR0}
  271. function IndexChar0(Const buf;len:SizeInt;b:Char):SizeInt;
  272. var
  273. I : longint;
  274. begin
  275. if Len<>0 then
  276. begin
  277. I:=IndexByte(Buf,Len,0);
  278. IndexChar0:=IndexByte(Buf,I,0);
  279. end
  280. else
  281. IndexChar0:=0;
  282. end;
  283. {$endif ndef FPC_SYSTEM_HAS_INDEXCHAR0}
  284. {$ifndef FPC_SYSTEM_HAS_COMPARECHAR0}
  285. function CompareChar0(Const buf1,buf2;len:SizeInt):SizeInt;
  286. type
  287. bytearray = array [0..maxlongint-1] of byte;
  288. var
  289. i : longint;
  290. begin
  291. I:=0;
  292. if (Len<>0) and (@Buf1<>@Buf2) then
  293. begin
  294. while (I<Len) And
  295. ((Pbyte(@Buf1)[i]<>0) and (PByte(@buf2)[i]<>0)) and
  296. (pbyte(@Buf1)[I]=pbyte(@Buf2)[I]) do
  297. inc(I);
  298. if (I=Len) or
  299. (PByte(@Buf1)[i]=0) or
  300. (PByte(@buf2)[I]=0) then {No difference or 0 reached }
  301. I:=0
  302. else
  303. begin
  304. I:=bytearray(Buf1)[I]-bytearray(Buf2)[I];
  305. if I>0 then
  306. I:=1
  307. else
  308. if I<0 then
  309. I:=-1;
  310. end;
  311. end;
  312. CompareChar0:=I;
  313. end;
  314. {$endif not FPC_SYSTEM_HAS_COMPARECHAR0}
  315. {****************************************************************************
  316. Object Helpers
  317. ****************************************************************************}
  318. {$ifndef FPC_SYSTEM_HAS_FPC_HELP_CONSTRUCTOR}
  319. { Note: _vmt will be reset to -1 when memory is allocated,
  320. this is needed for fpc_help_fail }
  321. function fpc_help_constructor(_self:pointer;var _vmt:pointer;_vmt_pos:cardinal):pointer;[public,alias:'FPC_HELP_CONSTRUCTOR'];{$ifdef hascompilerproc}compilerproc;{$endif}
  322. type
  323. ppointer = ^pointer;
  324. pvmt = ^tvmt;
  325. tvmt=packed record
  326. size,msize:ptrint;
  327. parent:pointer;
  328. end;
  329. var
  330. vmtcopy : pointer;
  331. begin
  332. { Inherited call? }
  333. if _vmt=nil then
  334. begin
  335. fpc_help_constructor:=_self;
  336. exit;
  337. end;
  338. vmtcopy:=_vmt;
  339. if (_self=nil) and
  340. (pvmt(_vmt)^.size>0) then
  341. begin
  342. getmem(_self,pvmt(_vmt)^.size);
  343. { reset vmt needed for fail }
  344. _vmt:=pointer(-1);
  345. end;
  346. if _self<>nil then
  347. begin
  348. fillchar(_self^,pvmt(vmtcopy)^.size,#0);
  349. ppointer(_self+_vmt_pos)^:=vmtcopy;
  350. end;
  351. fpc_help_constructor:=_self;
  352. end;
  353. {$endif FPC_SYSTEM_HAS_FPC_HELP_CONSTRUCTOR}
  354. {$ifndef FPC_SYSTEM_HAS_FPC_HELP_DESTRUCTOR}
  355. { Note: _self will not be reset, the compiler has to generate the reset }
  356. procedure fpc_help_destructor(_self,_vmt:pointer;vmt_pos:cardinal);[public,alias:'FPC_HELP_DESTRUCTOR']; {$ifdef hascompilerproc} compilerproc; {$endif}
  357. type
  358. ppointer = ^pointer;
  359. pvmt = ^tvmt;
  360. tvmt = packed record
  361. size,msize : ptrint;
  362. parent : pointer;
  363. end;
  364. begin
  365. { already released? }
  366. if (_self=nil) or
  367. (_vmt=nil) or
  368. (ppointer(_self+vmt_pos)^=nil) then
  369. exit;
  370. if (pvmt(ppointer(_self+vmt_pos)^)^.size=0) or
  371. (pvmt(ppointer(_self+vmt_pos)^)^.size+pvmt(ppointer(_self+vmt_pos)^)^.msize<>0) then
  372. RunError(210);
  373. { reset vmt to nil for protection }
  374. ppointer(_self+vmt_pos)^:=nil;
  375. freemem(_self);
  376. end;
  377. {$endif FPC_SYSTEM_HAS_FPC_HELP_DESTRUCTOR}
  378. {$ifndef FPC_SYSTEM_HAS_FPC_HELP_FAIL}
  379. { Note: _self will not be reset, the compiler has to generate the reset }
  380. procedure fpc_help_fail(_self:pointer;var _vmt:pointer;vmt_pos:cardinal);[public,alias:'FPC_HELP_FAIL'];compilerproc;
  381. type
  382. ppointer = ^pointer;
  383. pvmt = ^tvmt;
  384. tvmt = packed record
  385. size,msize : ptrint;
  386. parent : pointer;
  387. end;
  388. begin
  389. if (_self=nil) or (_vmt=nil) then
  390. exit;
  391. { vmt=-1 when memory was allocated }
  392. if ptrint(_vmt)=-1 then
  393. begin
  394. if (_self=nil) or (ppointer(_self+vmt_pos)^=nil) then
  395. HandleError(210)
  396. else
  397. begin
  398. ppointer(_self+vmt_pos)^:=nil;
  399. freemem(_self);
  400. { reset _vmt to nil so it will not be freed a
  401. second time }
  402. _vmt:=nil;
  403. end;
  404. end
  405. else
  406. ppointer(_self+vmt_pos)^:=nil;
  407. end;
  408. {$endif FPC_SYSTEM_HAS_FPC_HELP_FAIL}
  409. {$ifndef NOCLASSHELPERS}
  410. {$ifndef FPC_SYSTEM_HAS_FPC_NEW_CLASS}
  411. function fpc_new_class(_self,_vmt:pointer):pointer;[public,alias:'FPC_NEW_CLASS']; {$ifdef hascompilerproc} compilerproc; {$endif}
  412. begin
  413. { Inherited call? }
  414. if _vmt=nil then
  415. begin
  416. fpc_new_class:=_self;
  417. exit;
  418. end;
  419. fpc_new_class := tclass(_vmt).NewInstance
  420. end;
  421. {$endif FPC_SYSTEM_HAS_FPC_NEW_CLASS}
  422. {$ifndef FPC_SYSTEM_HAS_FPC_DISPOSE_CLASS}
  423. procedure fpc_dispose_class(_self: pointer; flag : longint);[public,alias:'FPC_DISPOSE_CLASS'];compilerproc;
  424. begin
  425. { inherited -> flag = 0 -> no destroy }
  426. { normal -> flag = 1 -> destroy }
  427. if (_self <> nil) and (flag = 1) then
  428. tobject(_self).FreeInstance;
  429. end;
  430. {$endif ndef FPC_SYSTEM_HAS_FPC_DISPOSE_CLASS}
  431. {$endif NOCLASSHELPERS}
  432. {$ifndef FPC_SYSTEM_HAS_FPC_CHECK_OBJECT}
  433. procedure fpc_check_object(_vmt : pointer);saveregisters;[public,alias:'FPC_CHECK_OBJECT']; {$ifdef hascompilerproc} compilerproc; {$endif}
  434. type
  435. pvmt = ^tvmt;
  436. tvmt = packed record
  437. size,msize : ptrint;
  438. parent : pointer;
  439. end;
  440. begin
  441. if (_vmt=nil) or
  442. (pvmt(_vmt)^.size=0) or
  443. (pvmt(_vmt)^.size+pvmt(_vmt)^.msize<>0) then
  444. RunError(210);
  445. end;
  446. {$endif ndef FPC_SYSTEM_HAS_FPC_CHECK_OBJECT}
  447. {$ifndef FPC_SYSTEM_HAS_FPC_CHECK_OBJECT_EXT}
  448. { checks for a correct vmt pointer }
  449. { deeper check to see if the current object is }
  450. { really related to the true }
  451. procedure fpc_check_object_ext(vmt, expvmt : pointer);saveregisters;[public,alias:'FPC_CHECK_OBJECT_EXT']; {$ifdef hascompilerproc} compilerproc; {$endif}
  452. type
  453. pvmt = ^tvmt;
  454. tvmt = packed record
  455. size,msize : ptrint;
  456. parent : pointer;
  457. end;
  458. begin
  459. if (vmt=nil) or
  460. (pvmt(vmt)^.size=0) or
  461. (pvmt(vmt)^.size+pvmt(vmt)^.msize<>0) then
  462. RunError(210);
  463. while assigned(vmt) do
  464. if vmt=expvmt then
  465. exit
  466. else
  467. vmt:=pvmt(vmt)^.parent;
  468. RunError(219);
  469. end;
  470. {$endif not FPC_SYSTEM_HAS_FPC_CHECK_OBJECT_EXT}
  471. {****************************************************************************
  472. String
  473. ****************************************************************************}
  474. {$ifndef FPC_SYSTEM_HAS_FPC_SHORTSTR_ASSIGN}
  475. function fpc_shortstr_to_shortstr(len:longint;const sstr:shortstring): shortstring;[public,alias:'FPC_SHORTSTR_TO_SHORTSTR']; {$ifdef hascompilerproc} compilerproc; {$endif}
  476. var
  477. slen : byte;
  478. begin
  479. slen:=length(sstr);
  480. if slen<len then
  481. len:=slen;
  482. move(sstr[0],result[0],len+1);
  483. if slen>len then
  484. result[0]:=chr(len);
  485. end;
  486. {$ifdef interncopy}
  487. procedure fpc_shortstr_assign(len:longint;sstr,dstr:pointer);[public,alias:'FPC_SHORTSTR_ASSIGN']; {$ifdef HAS_COMPILER_PROC} compilerproc; {$endif}
  488. {$else}
  489. procedure fpc_shortstr_copy(len:longint;sstr,dstr:pointer);[public,alias:'FPC_SHORTSTR_COPY']; {$ifdef HAS_COMPILER_PROC} compilerproc; {$endif}
  490. {$endif}
  491. var
  492. slen : byte;
  493. type
  494. pstring = ^string;
  495. begin
  496. slen:=length(pstring(sstr)^);
  497. if slen<len then
  498. len:=slen;
  499. move(sstr^,dstr^,len+1);
  500. if slen>len then
  501. pchar(dstr)^:=chr(len);
  502. end;
  503. {$endif ndef FPC_SYSTEM_HAS_FPC_SHORTSTR_ASSIGN}
  504. {$ifndef FPC_SYSTEM_HAS_FPC_SHORTSTR_CONCAT}
  505. function fpc_shortstr_concat(const s1,s2:shortstring): shortstring;[public,alias:'FPC_SHORTSTR_CONCAT']; {$ifdef hascompilerproc} compilerproc; {$endif}
  506. var
  507. s1l, s2l : byte;
  508. begin
  509. s1l:=length(s1);
  510. s2l:=length(s2);
  511. if s1l+s2l>255 then
  512. s2l:=255-s1l;
  513. move(s1[1],fpc_shortstr_concat[1],s1l);
  514. move(s2[1],fpc_shortstr_concat[s1l+1],s2l);
  515. fpc_shortstr_concat[0]:=chr(s1l+s2l);
  516. end;
  517. {$endif ndef FPC_SYSTEM_HAS_FPC_SHORTSTR_CONCAT}
  518. {$ifndef FPC_SYSTEM_HAS_FPC_SHORTSTR_APPEND_SHORTSTR}
  519. procedure fpc_shortstr_append_shortstr(var s1:shortstring;const s2:shortstring);{$ifdef hascompilerproc} compilerproc; {$endif}
  520. [public,alias:'FPC_SHORTSTR_APPEND_SHORTSTR'];
  521. var
  522. s1l, s2l : byte;
  523. begin
  524. s1l:=length(s1);
  525. s2l:=length(s2);
  526. if s1l+s2l>high(s1) then
  527. s2l:=high(s1)-s1l;
  528. move(s2[1],s1[s1l+1],s2l);
  529. s1[0]:=chr(s1l+s2l);
  530. end;
  531. {$endif ndef FPC_SYSTEM_HAS_FPC_SHORTSTR_APPEND_SHORTSTR}
  532. {$ifndef FPC_SYSTEM_HAS_FPC_SHORTSTR_COMPARE}
  533. function fpc_shortstr_compare(const left,right:shortstring) : longint;[public,alias:'FPC_SHORTSTR_COMPARE']; {$ifdef hascompilerproc} compilerproc; {$endif}
  534. var
  535. s1,s2,max,i : byte;
  536. d : longint;
  537. begin
  538. s1:=length(left);
  539. s2:=length(right);
  540. if s1<s2 then
  541. max:=s1
  542. else
  543. max:=s2;
  544. for i:=1 to max do
  545. begin
  546. d:=byte(left[i])-byte(right[i]);
  547. if d>0 then
  548. exit(1)
  549. else if d<0 then
  550. exit(-1);
  551. end;
  552. if s1>s2 then
  553. exit(1)
  554. else if s1<s2 then
  555. exit(-1)
  556. else
  557. exit(0);
  558. end;
  559. {$endif ndef FPC_SYSTEM_HAS_FPC_SHORTSTR_COMPARE}
  560. {$ifndef FPC_SYSTEM_HAS_FPC_PCHAR_TO_SHORTSTR}
  561. function fpc_pchar_to_shortstr(p:pchar):shortstring;[public,alias:'FPC_PCHAR_TO_SHORTSTR']; {$ifdef hascompilerproc} compilerproc; {$endif}
  562. var
  563. l : longint;
  564. s: shortstring;
  565. begin
  566. if p=nil then
  567. l:=0
  568. else
  569. l:=strlen(p);
  570. if l>255 then
  571. l:=255;
  572. if l>0 then
  573. move(p^,s[1],l);
  574. s[0]:=chr(l);
  575. fpc_pchar_to_shortstr := s;
  576. end;
  577. {$endif ndef FPC_SYSTEM_HAS_FPC_PCHAR_TO_SHORTSTR}
  578. { also add a strpas alias for internal use in the system unit (JM) }
  579. function strpas(p:pchar):shortstring; [external name 'FPC_PCHAR_TO_SHORTSTR'];
  580. {$ifndef FPC_UNIT_HAS_STRLEN}
  581. { if strlen is not yet defined, we need a forward declaration here }
  582. function strlen(p:pchar):longint; [external name 'FPC_PCHAR_LENGTH'];
  583. {$endif FPC_UNIT_HAS_STRLEN}
  584. {$ifndef FPC_SYSTEM_HAS_FPC_CHARARRAY_TO_SHORTSTR}
  585. {$ifdef hascompilerproc}
  586. function fpc_chararray_to_shortstr(const arr: array of char):shortstring;[public,alias:'FPC_CHARARRAY_TO_SHORTSTR']; compilerproc;
  587. var
  588. l: longint;
  589. {$else hascompilerproc}
  590. function fpc_chararray_to_shortstr(arr:pchar; l : longint):shortstring;[public,alias:'FPC_CHARARRAY_TO_SHORTSTR'];
  591. var
  592. {$endif hascompilerproc}
  593. index: longint;
  594. len: byte;
  595. begin
  596. {$ifdef hascompilerproc}
  597. l := high(arr)+1;
  598. {$endif hascompilerproc}
  599. if l>=256 then
  600. l:=255
  601. else if l<0 then
  602. l:=0;
  603. index:=IndexByte(arr[0],l,0);
  604. if (index < 0) then
  605. len := l
  606. else
  607. len := index;
  608. move(arr[0],fpc_chararray_to_shortstr[1],len);
  609. fpc_chararray_to_shortstr[0]:=chr(len);
  610. end;
  611. {$endif ndef FPC_SYSTEM_HAS_FPC_CHARARRAY_TO_SHORTSTR}
  612. {$ifdef hascompilerproc}
  613. {$ifndef FPC_SYSTEM_HAS_FPC_SHORTSTR_TO_CHARARRAY}
  614. { inside the compiler, the resulttype is modified to that of the actual }
  615. { chararray we're converting to (JM) }
  616. function fpc_shortstr_to_chararray(arraysize: longint; const src: ShortString): fpc_big_chararray;[public,alias: 'FPC_SHORTSTR_TO_CHARARRAY']; compilerproc;
  617. var
  618. len: longint;
  619. begin
  620. len := length(src);
  621. if len > arraysize then
  622. len := arraysize;
  623. { make sure we don't access char 1 if length is 0 (JM) }
  624. if len > 0 then
  625. move(src[1],fpc_shortstr_to_chararray[0],len);
  626. fillchar(fpc_shortstr_to_chararray[len],arraysize-len,0);
  627. end;
  628. {$endif FPC_SYSTEM_HAS_FPC_SHORTSTR_TO_CHARARRAY}
  629. {$else hascompilerproc}
  630. {$ifopt r+}
  631. {$define rangeon}
  632. {$r-}
  633. {$endif}
  634. {$ifndef FPC_SYSTEM_HAS_FPC_STR_TO_CHARARRAY}
  635. procedure fpc_str_to_chararray(strtyp, arraysize: longint; src,dest: pchar);[public,alias:'FPC_STR_TO_CHARARRAY']; {$ifdef hascompilerproc} compilerproc; {$endif}
  636. type
  637. plongint = ^longint;
  638. var
  639. len: longint;
  640. begin
  641. case strtyp of
  642. { shortstring }
  643. 0:
  644. begin
  645. len := byte(src[0]);
  646. inc(src);
  647. end;
  648. {$ifdef SUPPORT_ANSISTRING}
  649. { ansistring}
  650. 1: len := length(ansistring(pointer(src)));
  651. {$endif SUPPORT_ANSISTRING}
  652. { longstring }
  653. 2:;
  654. { widestring }
  655. 3: ;
  656. end;
  657. if len > arraysize then
  658. len := arraysize;
  659. { make sure we don't dereference src if it can be nil (JM) }
  660. if len > 0 then
  661. move(src^,dest^,len);
  662. fillchar(dest[len],arraysize-len,0);
  663. end;
  664. {$endif FPC_SYSTEM_HAS_FPC_STR_TO_CHARARRAY}
  665. {$ifdef rangeon}
  666. {$r+}
  667. {undef rangeon}
  668. {$endif rangeon}
  669. {$endif hascompilerproc}
  670. {$ifndef FPC_SYSTEM_HAS_FPC_PCHAR_LENGTH}
  671. function fpc_pchar_length(p:pchar):longint;[public,alias:'FPC_PCHAR_LENGTH']; {$ifdef hascompilerproc} compilerproc; {$endif}
  672. var i : longint;
  673. begin
  674. i:=0;
  675. while p[i]<>#0 do inc(i);
  676. exit(i);
  677. end;
  678. {$endif ndef FPC_SYSTEM_HAS_FPC_PCHAR_LENGTH}
  679. {$ifdef HASWIDESTRING}
  680. {$ifndef FPC_SYSTEM_HAS_FPC_PWIDECHAR_LENGTH}
  681. function fpc_pwidechar_length(p:pwidechar):longint;[public,alias:'FPC_PWIDECHAR_LENGTH']; {$ifdef hascompilerproc} compilerproc; {$endif}
  682. var i : longint;
  683. begin
  684. i:=0;
  685. while p[i]<>#0 do inc(i);
  686. exit(i);
  687. end;
  688. {$endif ndef FPC_SYSTEM_HAS_FPC_PWIDECHAR_LENGTH}
  689. {$endif HASWIDESTRING}
  690. {****************************************************************************
  691. Caller/StackFrame Helpers
  692. ****************************************************************************}
  693. {$ifndef FPC_SYSTEM_HAS_GET_FRAME}
  694. {_$error Get_frame must be defined for each processor }
  695. {$endif ndef FPC_SYSTEM_HAS_GET_FRAME}
  696. {$ifndef FPC_SYSTEM_HAS_GET_CALLER_ADDR}
  697. {_$error Get_caller_addr must be defined for each processor }
  698. {$endif ndef FPC_SYSTEM_HAS_GET_CALLER_ADDR}
  699. {$ifndef FPC_SYSTEM_HAS_GET_CALLER_FRAME}
  700. {_$error Get_caller_frame must be defined for each processor }
  701. {$endif ndef FPC_SYSTEM_HAS_GET_CALLER_FRAME}
  702. {****************************************************************************
  703. Math
  704. ****************************************************************************}
  705. {****************************************************************************
  706. Software longint/dword division
  707. ****************************************************************************}
  708. {$ifdef FPC_INCLUDE_SOFTWARE_MOD_DIV}
  709. function count_leading_zeros_32bit(l : longint) : longint;
  710. var
  711. i : longint;
  712. begin
  713. for i:=0 to 31 do
  714. begin
  715. if (l and (longint($80000000) shr i))<>0 then
  716. begin
  717. result:=i;
  718. exit;
  719. end;
  720. end;
  721. result:=i;
  722. end;
  723. {$ifndef FPC_SYSTEM_HAS_DIV_DWORD}
  724. function fpc_div_dword(n,z : dword) : dword; [public,alias: 'FPC_DIV_DWORD']; {$ifdef hascompilerproc} compilerproc; {$endif}
  725. var
  726. shift,lzz,lzn : longint;
  727. begin
  728. result:=0;
  729. if n=0 then
  730. HandleErrorFrame(200,get_frame);
  731. lzz:=count_leading_zeros_32bit(z);
  732. lzn:=count_leading_zeros_32bit(n);
  733. { if the denominator contains less zeros
  734. then the numerator
  735. the d is greater than the n }
  736. if lzn<lzz then
  737. exit;
  738. shift:=lzn-lzz;
  739. n:=n shl shift;
  740. repeat
  741. if z>=n then
  742. begin
  743. z:=z-n;
  744. result:=result+dword(1 shl shift);
  745. end;
  746. dec(shift);
  747. n:=n shr 1;
  748. until shift<0;
  749. end;
  750. {$endif FPC_SYSTEM_HAS_DIV_DWORD}
  751. {$ifndef FPC_SYSTEM_HAS_MOD_DWORD}
  752. function fpc_mod_dword(n,z : dword) : dword; [public,alias: 'FPC_MOD_DWORD']; {$ifdef hascompilerproc} compilerproc; {$endif}
  753. var
  754. shift,lzz,lzn : longint;
  755. begin
  756. result:=0;
  757. if n=0 then
  758. HandleErrorFrame(200,get_frame);
  759. lzz:=count_leading_zeros_32bit(z);
  760. lzn:=count_leading_zeros_32bit(n);
  761. { if the denominator contains less zeros
  762. then the numerator
  763. the d is greater than the n }
  764. if lzn<lzz then
  765. begin
  766. result:=z;
  767. exit;
  768. end;
  769. shift:=lzn-lzz;
  770. n:=n shl shift;
  771. repeat
  772. if z>=n then
  773. z:=z-n;
  774. dec(shift);
  775. n:=n shr 1;
  776. until shift<0;
  777. result:=z;
  778. end;
  779. {$endif FPC_SYSTEM_HAS_MOD_DWORD}
  780. {$ifndef FPC_SYSTEM_HAS_DIV_LONGINT}
  781. function fpc_div_longint(n,z : longint) : longint; [public,alias: 'FPC_DIV_LONGINT']; {$ifdef hascompilerproc} compilerproc; {$endif}
  782. var
  783. sign : boolean;
  784. d1,d2 : dword;
  785. begin
  786. if n=0 then
  787. HandleErrorFrame(200,get_frame);
  788. sign:=false;
  789. if z<0 then
  790. begin
  791. sign:=not(sign);
  792. d1:=dword(-z);
  793. end
  794. else
  795. d1:=z;
  796. if n<0 then
  797. begin
  798. sign:=not(sign);
  799. d2:=dword(-n);
  800. end
  801. else
  802. d2:=n;
  803. { the div is coded by the compiler as call to divdword }
  804. if sign then
  805. result:=-(d1 div d2)
  806. else
  807. result:=d1 div d2;
  808. end;
  809. {$endif FPC_SYSTEM_HAS_DIV_LONGINT}
  810. {$ifndef FPC_SYSTEM_HAS_MOD_LONGINT}
  811. function fpc_mod_longint(n,z : longint) : longint; [public,alias: 'FPC_MOD_LONGINT']; {$ifdef hascompilerproc} compilerproc; {$endif}
  812. var
  813. signed : boolean;
  814. r,nq,zq : dword;
  815. begin
  816. if n=0 then
  817. HandleErrorFrame(200,get_frame);
  818. if n<0 then
  819. begin
  820. nq:=-n;
  821. signed:=true;
  822. end
  823. else
  824. begin
  825. signed:=false;
  826. nq:=n;
  827. end;
  828. if z<0 then
  829. begin
  830. zq:=dword(-z);
  831. signed:=not(signed);
  832. end
  833. else
  834. zq:=z;
  835. r:=zq mod nq;
  836. if signed then
  837. result:=-longint(r)
  838. else
  839. result:=r;
  840. end;
  841. {$endif FPC_SYSTEM_HAS_MOD_LONGINT}
  842. {$endif FPC_INCLUDE_SOFTWARE_MOD_DIV}
  843. {****************************************************************************}
  844. {$ifndef FPC_SYSTEM_HAS_ABS_LONGINT}
  845. function abs(l:longint):longint;{$ifdef SYSTEMINLINE}inline;{$endif}[internconst:in_const_abs];
  846. begin
  847. if l<0 then
  848. abs:=-l
  849. else
  850. abs:=l;
  851. end;
  852. {$endif not FPC_SYSTEM_HAS_ABS_LONGINT}
  853. {$ifndef FPC_SYSTEM_HAS_ODD_LONGINT}
  854. function odd(l:longint):boolean;{$ifdef SYSTEMINLINE}inline;{$endif}[internconst:in_const_odd];
  855. begin
  856. odd:=boolean(l and 1);
  857. end;
  858. {$endif ndef FPC_SYSTEM_HAS_ODD_LONGINT}
  859. {$ifndef FPC_SYSTEM_HAS_ODD_LONGWORD}
  860. function odd(l:longword):boolean;{$ifdef SYSTEMINLINE}inline;{$endif}[internconst:in_const_odd];
  861. begin
  862. odd:=boolean(l and 1);
  863. end;
  864. {$endif ndef FPC_SYSTEM_HAS_ODD_LONGWORD}
  865. {$ifndef FPC_SYSTEM_HAS_ODD_INT64}
  866. function odd(l:int64):boolean;{$ifdef SYSTEMINLINE}inline;{$endif}[internconst:in_const_odd];
  867. begin
  868. odd:=boolean(longint(l) and 1);
  869. end;
  870. {$endif ndef FPC_SYSTEM_HAS_ODD_INT64}
  871. {$ifndef FPC_SYSTEM_HAS_ODD_QWORD}
  872. function odd(l:qword):boolean;{$ifdef SYSTEMINLINE}inline;{$endif}[internconst:in_const_odd];
  873. begin
  874. odd:=boolean(longint(l) and 1);
  875. end;
  876. {$endif ndef FPC_SYSTEM_HAS_ODD_QWORD}
  877. {$ifndef FPC_SYSTEM_HAS_SQR_LONGINT}
  878. function sqr(l:longint):longint;{$ifdef SYSTEMINLINE}inline;{$endif}[internconst:in_const_sqr];
  879. begin
  880. sqr:=l*l;
  881. end;
  882. {$endif ndef FPC_SYSTEM_HAS_SQR_LONGINT}
  883. {$ifndef FPC_SYSTEM_HAS_ABS_INT64}
  884. function abs(l: Int64): Int64;{$ifdef SYSTEMINLINE}inline;{$endif}[internconst:in_const_abs];
  885. begin
  886. if l < 0 then
  887. abs := -l
  888. else
  889. abs := l;
  890. end;
  891. {$endif ndef FPC_SYSTEM_HAS_ABS_INT64}
  892. {$ifndef FPC_SYSTEM_HAS_SQR_INT64}
  893. function sqr(l: Int64): Int64;{$ifdef SYSTEMINLINE}inline;{$endif}[internconst:in_const_sqr];
  894. begin
  895. sqr := l*l;
  896. end;
  897. {$endif ndef FPC_SYSTEM_HAS_SQR_INT64}
  898. {$ifndef FPC_SYSTEM_HAS_SQR_QWORD}
  899. function sqr(l: QWord): QWord;{$ifdef SYSTEMINLINE}inline;{$endif}[internconst:in_const_sqr];
  900. begin
  901. sqr := l*l;
  902. end;
  903. {$endif ndef FPC_SYSTEM_HAS_SQR_INT64}
  904. {$ifndef FPC_SYSTEM_HAS_DECLOCKED_LONGINT}
  905. function declocked(var l:longint):boolean;
  906. begin
  907. Dec(l);
  908. declocked:=(l=0);
  909. end;
  910. {$endif FPC_SYSTEM_HAS_DECLOCKED_LONGINT}
  911. {$ifndef FPC_SYSTEM_HAS_DECLOCKED_INT64}
  912. function declocked(var l:int64):boolean;
  913. begin
  914. Dec(l);
  915. declocked:=(l=0);
  916. end;
  917. {$endif FPC_SYSTEM_HAS_DECLOCKED_INT64}
  918. {$ifndef FPC_SYSTEM_HAS_INCLOCKED_LONGINT}
  919. procedure inclocked(var l:longint);
  920. begin
  921. Inc(l);
  922. end;
  923. {$endif FPC_SYSTEM_HAS_INCLOCKED_LONGINT}
  924. {$ifndef FPC_SYSTEM_HAS_INCLOCKED_INT64}
  925. procedure inclocked(var l:int64);
  926. begin
  927. Inc(l);
  928. end;
  929. {$endif FPC_SYSTEM_HAS_INCLOCKED_INT64}
  930. {$ifndef FPC_SYSTEM_HAS_SPTR}
  931. {_$error Sptr must be defined for each processor }
  932. {$endif ndef FPC_SYSTEM_HAS_SPTR}
  933. procedure prefetch(const mem);[internproc:in_prefetch_var];
  934. {****************************************************************************
  935. Str()
  936. ****************************************************************************}
  937. {$ifndef FPC_SYSTEM_HAS_INT_STR_LONGINT}
  938. procedure int_str(l : longint;var s : string);
  939. var
  940. value: longint;
  941. negative: boolean;
  942. begin
  943. negative := false;
  944. s:='';
  945. { Workaround: }
  946. if l=longint($80000000) then
  947. begin
  948. s:='-2147483648';
  949. exit;
  950. end;
  951. { handle case where l = 0 }
  952. if l = 0 then
  953. begin
  954. s:='0';
  955. exit;
  956. end;
  957. If l < 0 then
  958. begin
  959. negative := true;
  960. value:=abs(l);
  961. end
  962. else
  963. value:=l;
  964. { handle non-zero case }
  965. while value>0 do
  966. begin
  967. s:=char((value mod 10)+ord('0'))+s;
  968. value := value div 10;
  969. end;
  970. if negative then
  971. s := '-' + s;
  972. end;
  973. {$endif ndef FPC_SYSTEM_HAS_INT_STR_LONGINT}
  974. {$ifndef FPC_SYSTEM_HAS_INT_STR_LONGWORD}
  975. procedure int_str(l : longword;var s : string);
  976. begin
  977. s:='';
  978. if l = 0 then
  979. begin
  980. s := '0';
  981. exit;
  982. end;
  983. while l>0 do
  984. begin
  985. s:=char(ord('0')+(l mod 10))+s;
  986. l:=l div 10;
  987. end;
  988. end;
  989. {$endif ndef FPC_SYSTEM_HAS_INT_STR_LONGWORD}
  990. {$ifndef FPC_SYSTEM_HAS_INT_STR_INT64}
  991. procedure int_str(l : int64;var s : string);
  992. var
  993. value: int64;
  994. negative: boolean;
  995. begin
  996. negative := false;
  997. s:='';
  998. { Workaround: }
  999. {$ifdef ver1_0}
  1000. if (l shr 32=$80000000) and ((l and $ffffffff)=0) then
  1001. {$else}
  1002. if l=int64($8000000000000000) then
  1003. {$endif}
  1004. begin
  1005. s:='-9223372036854775808';
  1006. exit;
  1007. end;
  1008. { handle case where l = 0 }
  1009. if l = 0 then
  1010. begin
  1011. s:='0';
  1012. exit;
  1013. end;
  1014. If l < 0 then
  1015. begin
  1016. negative := true;
  1017. value:=abs(l);
  1018. end
  1019. else
  1020. value:=l;
  1021. { handle non-zero case }
  1022. while value>0 do
  1023. begin
  1024. s:=char((value mod 10)+ord('0'))+s;
  1025. value := value div 10;
  1026. end;
  1027. if negative then
  1028. s := '-' + s;
  1029. end;
  1030. {$endif ndef FPC_SYSTEM_HAS_INT_STR_INT64}
  1031. {$ifndef FPC_SYSTEM_HAS_INT_STR_QWORD}
  1032. procedure int_str(l : qword;var s : string);
  1033. begin
  1034. s:='';
  1035. if l = 0 then
  1036. begin
  1037. s := '0';
  1038. exit;
  1039. end;
  1040. while l>0 do
  1041. begin
  1042. s:=char(ord('0')+(l mod 10))+s;
  1043. l:=l div 10;
  1044. end;
  1045. end;
  1046. {$endif ndef FPC_SYSTEM_HAS_INT_STR_QWORD}
  1047. {$ifndef FPC_SYSTEM_HAS_SYSRESETFPU}
  1048. procedure SysResetFpu;{$ifdef SYSTEMINLINE}inline;{$endif}
  1049. begin
  1050. { nothing todo }
  1051. end;
  1052. {$endif FPC_SYSTEM_HAS_SYSRESETFPU}
  1053. {
  1054. $Log$
  1055. Revision 1.81 2004-10-09 21:00:46 jonas
  1056. + cgenmath with libc math functions. Faster than the routines in genmath
  1057. and also have full double support (exp() only has support for values in
  1058. the single range in genmath, for example). Used in FPC_USE_LIBC is
  1059. defined
  1060. * several fixes to allow compilation with -dHASINLINE, but internalerrors
  1061. because of missing support for inlining assembler code
  1062. Revision 1.80 2004/07/18 20:21:44 florian
  1063. + several unicode (to/from utf-8 conversion) stuff added
  1064. * some longint -> SizeInt changes
  1065. Revision 1.79 2004/05/31 20:25:04 peter
  1066. * removed warnings
  1067. Revision 1.78 2004/05/02 15:15:45 peter
  1068. * fix arguments for shortstr_compare
  1069. Revision 1.77 2004/05/02 00:31:03 peter
  1070. * fixed compile with 1.0.x
  1071. Revision 1.76 2004/05/01 23:55:18 peter
  1072. * replace strlenint with sizeint
  1073. Revision 1.75 2004/05/01 20:52:50 peter
  1074. * ValSInt fixed for 64 bit
  1075. Revision 1.74 2004/05/01 15:26:33 jonas
  1076. * use some more string routines from libc if FPC_USE_LIBC is used
  1077. Revision 1.73 2004/04/29 19:50:13 peter
  1078. * x86-64 fixes
  1079. Revision 1.72 2004/04/28 21:01:29 florian
  1080. * tvmt fixed (longint -> ptrint)
  1081. Revision 1.71 2004/04/28 20:48:20 peter
  1082. * ordinal-pointer conversions fixed
  1083. Revision 1.70 2004/04/26 15:55:01 peter
  1084. * FPC_MOVE alias
  1085. Revision 1.69 2004/02/02 20:39:27 florian
  1086. + added prefetch(const mem)
  1087. Revision 1.68 2004/01/31 16:14:24 florian
  1088. * alignment handling of generic fillbyte/word fixed
  1089. Revision 1.66 2004/01/21 01:25:02 florian
  1090. * improved generic int. div routines
  1091. Revision 1.65 2004/01/20 23:16:56 florian
  1092. + created generic versions of software dword/longint mod/div
  1093. Revision 1.64 2004/01/10 17:01:29 jonas
  1094. * changed index* to conform to the assembler implementations (interpret
  1095. negative upper bound as maximum)
  1096. Revision 1.63 2003/12/16 09:43:04 daniel
  1097. * Use of 0 instead of nil fixed
  1098. Revision 1.62 2003/12/06 13:25:30 jonas
  1099. * fixed longint/cardinal comparison in int_str
  1100. Revision 1.61 2003/09/03 14:09:37 florian
  1101. * arm fixes to the common rtl code
  1102. * some generic math code fixed
  1103. * ...
  1104. Revision 1.60 2003/06/01 14:50:17 jonas
  1105. * fpc_shortstr_append_shortstr has to use high(s1) instead of 255 as
  1106. maxlen
  1107. + ppc version of fpc_shortstr_append_shortstr
  1108. Revision 1.59 2003/05/26 21:18:13 peter
  1109. * FPC_SHORTSTR_APPEND_SHORTSTR public added
  1110. Revision 1.58 2003/05/26 19:36:46 peter
  1111. * fpc_shortstr_concat is now the same for all targets
  1112. * fpc_shortstr_append_shortstr added for optimized code generation
  1113. Revision 1.57 2003/05/16 22:40:11 florian
  1114. * fixed generic shortstr_compare
  1115. Revision 1.56 2003/05/13 20:52:50 peter
  1116. * extra check for self and empty objects
  1117. Revision 1.55 2003/05/13 19:18:08 peter
  1118. * fpc_help_fail compilerproc
  1119. * fpc_new_class, fpc_dispose_class not needed by latest compiler
  1120. Revision 1.54 2003/04/23 13:10:09 peter
  1121. * remvoe objectsize loading from help_destructor
  1122. * implement fpc_check_object
  1123. * saveregistrers for check_object
  1124. Revision 1.53 2003/04/02 14:05:45 peter
  1125. * undo previous commit
  1126. Revision 1.51 2003/03/26 00:17:34 peter
  1127. * generic constructor/destructor fixes
  1128. Revision 1.50 2003/02/18 17:56:06 jonas
  1129. - removed buggy i386-specific FPC_CHARARRAY_TO_SHORTSTR
  1130. * fixed generic FPC_CHARARRAY_TO_SHORTSTR (web bug 2382)
  1131. * fixed some potential range errors in indexchar/word/dword
  1132. Revision 1.49 2003/01/20 22:21:36 mazen
  1133. * many stuff related to RTL fixed
  1134. Revision 1.48 2003/01/09 20:14:20 florian
  1135. * fixed helper declarations
  1136. Revision 1.47 2003/01/07 22:04:12 mazen
  1137. - space removed
  1138. Revision 1.46 2003/01/06 23:04:21 mazen
  1139. * functions headers modified in generic.inc to make it possible compiling sparc
  1140. RTL based on generic code
  1141. Revision 1.45 2003/01/05 21:32:35 mazen
  1142. * fixing several bugs compiling the RTL
  1143. Revision 1.44 2002/12/23 21:27:13 peter
  1144. * fix wrong var names for shortstr_compare
  1145. Revision 1.43 2002/10/20 11:51:54 carl
  1146. * avoid crashes with negative len counts on fills/moves
  1147. * movechar0 was wrong and did not do the behavior as
  1148. described in docs
  1149. Revision 1.42 2002/10/14 19:39:17 peter
  1150. * threads unit added for thread support
  1151. Revision 1.41 2002/10/12 20:32:41 carl
  1152. * RunError 220 -> RunError 219 to be more consistent with as operator
  1153. Revision 1.40 2002/10/10 16:08:50 florian
  1154. + several widestring/pwidechar related helpers added
  1155. Revision 1.39 2002/10/05 14:20:16 peter
  1156. * fpc_pchar_length compilerproc and strlen alias
  1157. Revision 1.38 2002/10/02 18:21:51 peter
  1158. * Copy() changed to internal function calling compilerprocs
  1159. * FPC_SHORTSTR_COPY renamed to FPC_SHORTSTR_ASSIGN because of the
  1160. new copy functions
  1161. Revision 1.37 2002/09/27 21:10:40 carl
  1162. * fix 2GB limit problem
  1163. Revision 1.36 2002/09/13 19:13:06 carl
  1164. * FPC_HELP_FAIL : reset _self to nil
  1165. Revision 1.35 2002/09/10 21:29:44 jonas
  1166. * added some missing compilerproc directives
  1167. Revision 1.34 2002/09/07 21:08:42 carl
  1168. * cardinal -> longword
  1169. - remove generic boundcheck (does not exist in v1.1)
  1170. Revision 1.33 2002/09/07 15:07:45 peter
  1171. * old logs removed and tabs fixed
  1172. Revision 1.32 2002/08/19 19:34:02 peter
  1173. * SYSTEMINLINE define that will add inline directives for small
  1174. functions and wrappers. This will be defined automaticly when
  1175. the compiler defines the HASINLINE directive
  1176. Revision 1.31 2002/07/29 21:28:16 florian
  1177. * several fixes to get further with linux/ppc system unit compilation
  1178. Revision 1.30 2002/07/29 09:23:11 jonas
  1179. * fixed some datastructures > 2GB
  1180. Revision 1.29 2002/07/28 21:39:28 florian
  1181. * made abs a compiler proc if it is generic
  1182. Revision 1.28 2002/07/28 20:43:47 florian
  1183. * several fixes for linux/powerpc
  1184. * several fixes to MT
  1185. Revision 1.27 2002/06/16 08:19:03 carl
  1186. * bugfix of FPC_NEW_CLASS (was not creating correct instance)
  1187. + FPC_HELP_FAIL_CLASS now tested (no longer required)
  1188. Revision 1.25 2002/05/16 19:58:05 carl
  1189. * generic constructor implemented
  1190. Revision 1.24 2002/03/30 13:08:54 carl
  1191. * memory corruption bugfix in FPC_HELP_CONSTRUCTOR if object cannot be allocated
  1192. Revision 1.23 2002/01/25 17:38:55 peter
  1193. * add internconst for all overloaded types of Odd/Abs/Sqr
  1194. Revision 1.22 2002/01/24 12:33:53 jonas
  1195. * adapted ranges of native types to int64 (e.g. high cardinal is no
  1196. longer longint($ffffffff), but just $fffffff in psystem)
  1197. * small additional fix in 64bit rangecheck code generation for 32 bit
  1198. processors
  1199. * adaption of ranges required the matching talgorithm used for selecting
  1200. which overloaded procedure to call to be adapted. It should now always
  1201. select the closest match for ordinal parameters.
  1202. + inttostr(qword) in sysstr.inc/sysstrh.inc
  1203. + abs(int64), sqr(int64), sqr(qword) in systemh.inc/generic.inc (previous
  1204. fixes were required to be able to add them)
  1205. * is_in_limit() moved from ncal to types unit, should always be used
  1206. instead of direct comparisons of low/high values of orddefs because
  1207. qword is a special case
  1208. }