set.inc 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1999-2000 by Carl-Eric Codere,
  5. member of the Free Pascal development team.
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. {*************************************************************************}
  13. { Converted by Carl Eric Codere }
  14. {*************************************************************************}
  15. { This inc. implements low-level set operations for the motorola }
  16. { 68000 familiy of processors. }
  17. { Based on original code bt Florian Kl„mpfl for the 80x86. }
  18. {*************************************************************************}
  19. { add the element b to the set pointed by p }
  20. { On entry }
  21. { a0 = pointer to set }
  22. { d0.b = element to add to the set }
  23. { Registers destroyed: d0,a1,d6 }
  24. procedure do_set;assembler;
  25. asm
  26. XDEF SET_SET_BYTE
  27. move.l d0,d6
  28. { correct long position: }
  29. { -> (value div 32)*4 = longint }
  30. { (value shr 5)*shl 2 }
  31. lsr.l #5,d6
  32. lsl.l #2,d6
  33. adda.l d6,a0 { correct offset from start address of set }
  34. move.l d0,d6 { bit is now in here }
  35. andi.l #31,d0 { bit number is = value mod 32 }
  36. { now bit set the value }
  37. move.l (a0),d0 { we must put bits into register }
  38. bset.l d6,d0 { otherwise btst will be a byte }
  39. { put result in carry flag } { operation. }
  40. bne @LDOSET1
  41. andi.b #$fe,ccr { clear carry flag }
  42. bra @LDOSET2
  43. @LDOSET1:
  44. ori.b #$01,ccr { set carry flag }
  45. @LDOSET2:
  46. move.l d0,(a0) { restore the value at that location }
  47. { of the set. }
  48. end;
  49. { Finds an element in a set }
  50. { a0 = address of set }
  51. { d0.b = value to compare with }
  52. { CARRY SET IF FOUND ON EXIT }
  53. { Registers destroyed: d0,a0,d6 }
  54. procedure do_in; assembler;
  55. { Returns Carry set then = in set , otherwise carry is cleared }
  56. { (D0) }
  57. asm
  58. XDEF SET_IN_BYTE
  59. move.l d0,d6
  60. { correct long position: }
  61. { -> (value div 32)*4 = longint }
  62. { (value shr 5)*shl 2 }
  63. lsr.l #5,d6
  64. lsl.l #2,d6
  65. adda.l d6,a0 { correct offset from start address of set }
  66. move.l d0,d6 { bit is now in here }
  67. andi.l #31,d0 { bit number is = value mod 32 }
  68. move.l (a0),d0 { we must put bits into register }
  69. btst.l d6,d0 { otherwise btst will be a byte }
  70. { put result in carry flag } { operation. }
  71. bne @LDOIN1
  72. andi.b #$fe,ccr { clear carry flag }
  73. bra @LDOIN2
  74. @LDOIN1:
  75. ori.b #$01,ccr { set carry flag }
  76. @LDOIN2:
  77. end;
  78. { vereinigt set1 und set2 und speichert das Ergebnis in dest }
  79. procedure add_sets(set1,set2,dest : pointer);[public,alias: 'SET_ADD_SETS'];
  80. { PSEUDO-CODE:
  81. type
  82. destination = array[1..8] of longint;
  83. for i:=1 to 8 do
  84. destination(dest^)[i] := destination(set1^)[i] OR destination(set2^)[i];
  85. }
  86. begin
  87. asm
  88. { saved used register }
  89. move.l a2,-(sp)
  90. move.l 8(a6),a0
  91. move.l 12(a6),a1
  92. move.l 16(a6),a2
  93. move.l #32,d6
  94. @LMADDSETS1:
  95. move.b (a0)+,d0
  96. or.b (a1)+,d0
  97. move.b d0,(a2)+
  98. subq.b #1,d6
  99. bne @LMADDSETS1
  100. { restore register }
  101. move.l a2,(sp)+
  102. end ['d0','d6','a0','a1'];
  103. end;
  104. { computes the symetric diff from set1 to set2 }
  105. { result in dest }
  106. procedure sym_sub_sets(set1,set2,dest : pointer);[public,alias: 'SET_SYMDIF_SETS'];
  107. begin
  108. asm
  109. { saved used register }
  110. move.l a2,-(sp)
  111. move.l 8(a6),a0
  112. move.l 12(a6),a1
  113. move.l 16(a6),a2
  114. move.l #32,d6
  115. @LMADDSETS1:
  116. move.b (a0)+,d0
  117. move.b (a1)+,d1
  118. eor.b d1,d0
  119. move.b d0,(a2)+
  120. subq.b #1,d6
  121. bne @LMADDSETS1
  122. { restore register }
  123. move.l a2,(sp)+
  124. end;
  125. end;
  126. { bad implementation, but it's very seldom used }
  127. procedure do_set(p : pointer;l,h : byte);[public,alias: 'SET_SET_RANGE'];
  128. begin
  129. asm
  130. move.b h,d0
  131. @LSetRLoop:
  132. cmp.b l,d0
  133. blt @Lend
  134. move.w d0,-(sp)
  135. { adjust value to correct endian }
  136. lsl.w #8,d0
  137. pea p
  138. jsr SET_SET_BYTE
  139. sub.b #1,d0
  140. bra @LSetRLoop
  141. @Lend:
  142. end;
  143. end;
  144. { bildet den Durchschnitt von set1 und set2 }
  145. { und speichert das Ergebnis in dest }
  146. procedure mul_sets(set1,set2,dest : pointer);[public,alias: 'SET_MUL_SETS'];
  147. { type
  148. larray = array[0..7] of longint;
  149. for i:=0 to 7 do
  150. larray(dest^)[i] := larray(set1^)[i] AND larray(set2^)[i];
  151. }
  152. begin
  153. asm
  154. { saved used register }
  155. move.l a2,-(sp)
  156. move.l 8(a6),a0
  157. move.l 12(a6),a1
  158. move.l 16(a6),a2
  159. move.l #32,d6
  160. @LMMULSETS1:
  161. move.b (a0)+,d0
  162. and.b (a1)+,d0
  163. move.b d0,(a2)+
  164. subq.b #1,d6
  165. bne @LMMULSETS1
  166. { restore register }
  167. move.l a2,(sp)+
  168. end ['d0','d6','a0','a1'];
  169. end;
  170. { bildet die Differenz von set1 und set2 }
  171. { und speichert das Ergebnis in dest }
  172. procedure sub_sets(set1,set2,dest : pointer);[public,alias: 'SET_SUB_SETS'];
  173. { type
  174. larray = array[0..7] of longint;
  175. begin
  176. for i:=0 to 7 do
  177. larray(dest^)[i] := larray(set1^)[i] AND NOT (larray(set2^)[i]);
  178. end;
  179. }
  180. begin
  181. asm
  182. { saved used register }
  183. move.l a2,-(sp)
  184. move.l 8(a6),a0
  185. move.l 12(a6),a1
  186. move.l 16(a6),a2
  187. move.l #32,d6
  188. @LSUBSETS1:
  189. move.b (a0)+,d0
  190. move.b (a1)+,d1
  191. not.b d1
  192. and.b d1,d0
  193. move.b d0,(a2)+
  194. sub.b #1,d6
  195. bne @LSUBSETS1
  196. { restore register }
  197. move.l a2,(sp)+
  198. end ['d0','d1','d6','a0','a1'];
  199. end;
  200. { compare both sets }
  201. { compares set1 and set2 }
  202. { zeroflag is set if they are equal }
  203. { on entry : a0 = pointer to first set }
  204. { : a1 = pointer to second set }
  205. procedure comp_sets; assembler;
  206. asm
  207. XDEF SET_COMP_SETS
  208. move.l #32,d6
  209. @LMCOMPSETS1:
  210. move.b (a0)+,d0
  211. move.b (a1),d1
  212. cmp.b d1,d0
  213. bne @LMCOMPSETEND
  214. adda.l #1,a1
  215. sub.b #1,d6
  216. bne @LMCOMPSETS1
  217. { we are here only if the two sets are equal }
  218. { we have zero flag set, and that what is expected }
  219. cmp.b d0,d0
  220. @LMCOMPSETEND:
  221. end;
  222. procedure do_set(p : pointer;b : word);[public,alias: 'SET_SET_WORD'];
  223. begin
  224. asm
  225. move.l 8(a6),a0
  226. move.w 12(a6),d6
  227. andi.l #$fff8,d6
  228. lsl.l #3,d6
  229. adda.l d6,a0
  230. move.b 12(a6),d6
  231. andi.l #7,d6
  232. move.l (a0),d0 { we must put bits into register }
  233. btst.l d6,d0 { otherwise btst will be a byte }
  234. { put result in carry flag } { operation. }
  235. bne @LBIGDOSET1
  236. andi.b #$fe,ccr { clear carry flag }
  237. bra @LBIGDOSET2
  238. @LBIGDOSET1:
  239. ori.b #$01,ccr { set carry flag }
  240. @LBIGDOSET2:
  241. end ['d0','a0','d6'];
  242. end;
  243. { testet, ob das Element b in der Menge p vorhanden ist }
  244. { und setzt das Carryflag entsprechend }
  245. procedure do_in(p : pointer;b : word);[public,alias: 'SET_IN_WORD'];
  246. begin
  247. asm
  248. move.l 8(a6),a0
  249. move.w 12(a6),d6
  250. andi.l #$fff8,d6
  251. lsl.l #3,d6
  252. adda.l d6,a0 { correct offset from start address of set }
  253. move.b 12(a6),d6
  254. andi.l #7,d6
  255. move.l (a0),d0 { we must put bits into register }
  256. btst.l d6,d0 { otherwise btst will be a byte }
  257. { put result in carry flag } { operation. }
  258. bne @LBIGDOIN1
  259. andi.b #$fe,ccr { clear carry flag }
  260. bra @LBIGDOIN2
  261. @LBIGDOIN1:
  262. ori.b #$01,ccr { set carry flag }
  263. @LBIGDOIN2:
  264. end ['d0','a0','d6'];
  265. end;
  266. { vereinigt set1 und set2 und speichert das Ergebnis in dest }
  267. { size is the number of bytes in the set }
  268. procedure add_sets(set1,set2,dest : pointer;size : longint);[public,alias: 'SET_ADD_SETS_SIZE'];
  269. begin
  270. asm
  271. { saved used register }
  272. move.l a2,-(sp)
  273. move.l 8(a6),a0
  274. move.l 12(a6),a1
  275. move.l 16(a6),a2
  276. move.l 20(a6),d6
  277. @LBIGMADDSETS1:
  278. move.l (a0)+,d0
  279. or.l (a1)+,d0
  280. move.l d0,(a2)+
  281. subq.l #4,d6
  282. bne @LBIGMADDSETS1
  283. { restore register }
  284. move.l a2,(sp)+
  285. end ['d0','d6','a0','a1'];
  286. end;
  287. procedure mul_sets(set1,set2,dest : pointer;size : longint);[public,alias: 'SET_MUL_SETS_SIZE'];
  288. { bildet den Durchschnitt von set1 und set2 }
  289. { und speichert das Ergebnis in dest }
  290. { size is the number of bytes in the set }
  291. begin
  292. asm
  293. { saved used register }
  294. move.l a2,-(sp)
  295. move.l 8(a6),a0
  296. move.l 12(a6),a1
  297. move.l 16(a6),a2
  298. move.l 20(a6),d6
  299. @LBIGMMULSETS1:
  300. move.l (a0)+,d0
  301. and.l (a1)+,d0
  302. move.l d0,(a2)+
  303. subq.l #4,d6
  304. bne @LBIGMMULSETS1
  305. { restore register }
  306. move.l a2,(sp)+
  307. end ['d0','d6','a0','a1'];
  308. end;
  309. { bildet die Differenz von set1 und set2 }
  310. { und speichert das Ergebnis in dest }
  311. { size is the number of bytes in the set }
  312. procedure sub_sets(set1,set2,dest : pointer;size : longint);[public,alias: 'SET_SUB_SETS_SIZE'];
  313. begin
  314. asm
  315. { saved used register }
  316. move.l a2,-(sp)
  317. move.l 8(a6),a0
  318. move.l 12(a6),a1
  319. move.l 16(a6),a2
  320. move.l 20(a6),d6
  321. @BIGSUBSETS1:
  322. move.l (a0)+,d0
  323. not.l d0
  324. and.l (a1)+,d0
  325. move.l d0,(a2)+
  326. subq.l #4,d6
  327. bne @BIGSUBSETS1
  328. { restore register }
  329. move.l a2,(sp)+
  330. end ['d0','d6','a0','a1'];
  331. end;
  332. { vergleicht Mengen und setzt die Flags entsprechend }
  333. procedure comp_sets(set1,set2 : pointer;size : longint);[public,alias: 'SET_COMP_SETS_SIZE'];
  334. begin
  335. asm
  336. move.l 8(a6),a0 { set1 - esi}
  337. move.l 12(a6),a1 { set2 - edi }
  338. move.l 16(a6),d6
  339. @MCOMPSETS1:
  340. move.l (a0)+,d0
  341. move.l (a1),d1
  342. cmp.l d1,d0
  343. bne @BIGMCOMPSETEND
  344. add.l #4,a1
  345. subq.l #1,d6
  346. bne @MCOMPSETS1
  347. { we are here only if the two sets are equal }
  348. { we have zero flag set, and that what is expected }
  349. cmp.l d0,d0
  350. @BIGMCOMPSETEND:
  351. end;
  352. end;
  353. {
  354. $Log$
  355. Revision 1.3 2002-09-07 16:01:20 peter
  356. * old logs removed and tabs fixed
  357. }