set.inc 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1993,97 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. { set.inc }
  14. { Converted by Carl Eric Codere }
  15. {*************************************************************************}
  16. { This inc. implements low-level set operations for the motorola }
  17. { 68000 familiy of processors. }
  18. {*************************************************************************}
  19. { Based on original code bt Florian Kl„mpfl for the 80x86. }
  20. { }
  21. { 22nd november 1997 }
  22. { * bugfix of btst with long sizes. (CEC) }
  23. {*************************************************************************}
  24. { f�gt das Element b der Menge zu, auf die p zeigt }
  25. procedure do_set(p : pointer;b : byte);[public,alias: 'SET_SET_BYTE'];
  26. begin
  27. asm
  28. move.l 8(a6),a0
  29. move.b 12(a6),d6
  30. andi.l #$f8,d6
  31. lsl.l #3,d6
  32. adda.l d6,a0
  33. move.b 12(a6),d6
  34. andi.l #7,d6
  35. move.l (a0),d0 { we must put bits into register }
  36. btst.l d6,d0 { otherwise btst will be a byte }
  37. { put result in carry flag } { operation. }
  38. bne @LDOSET1
  39. clr.b d0
  40. { andi.b #$fe,ccr } { clear carry flag }
  41. bra @LDOSET2
  42. @LDOSET1:
  43. move.b #1,d0
  44. { ori.b #$01,ccr } { set carry flag }
  45. @LDOSET2:
  46. end ['d0','a0','d6'];
  47. end;
  48. { testet, ob das Element b in der Menge p vorhanden ist }
  49. { und setzt das Carryflag entsprechend }
  50. procedure do_in(p : pointer;b : byte);[public,alias: 'SET_IN_BYTE'];
  51. { Returns Carry set then = in set , otherwise carry is cleared }
  52. { (D0) }
  53. begin
  54. asm
  55. move.l 8(a6),a0
  56. move.b 12(a6),d6
  57. andi.l #$f8,d6
  58. lsl.l #3,d6
  59. adda.l d6,a0 { correct offset from start address of set }
  60. move.b 12(a6),d6
  61. andi.l #7,d6
  62. move.l (a0),d0 { we must put bits into register }
  63. btst.l d6,d0 { otherwise btst will be a byte }
  64. { put result in carry flag } { operation. }
  65. bne @LDOIN1
  66. clr.b d0
  67. { this does not work, because of how the stack is restored }
  68. { by the routine. }
  69. { andi.b #$fe,ccr } { clear carry flag }
  70. bra @LDOIN2
  71. @LDOIN1:
  72. move.b #1,d0
  73. { ori.b #$01,ccr } { set carry flag }
  74. @LDOIN2:
  75. end ['d0','a0','d6'];
  76. end;
  77. { vereinigt set1 und set2 und speichert das Ergebnis in dest }
  78. procedure add_sets(set1,set2,dest : pointer);[public,alias: 'SET_ADD_SETS'];
  79. { PSEUDO-CODE:
  80. type
  81. destination = array[1..8] of longint;
  82. for i:=1 to 8 do
  83. destination(dest^)[i] := destination(set1^)[i] OR destination(set2^)[i];
  84. }
  85. begin
  86. asm
  87. { saved used register }
  88. move.l a2,-(sp)
  89. move.l 8(a6),a0
  90. move.l 12(a6),a1
  91. move.l 16(a6),a2
  92. move.l #8,d6
  93. @LMADDSETS1:
  94. move.l (a0)+,d0
  95. or.l (a1)+,d0
  96. move.l d0,(a2)+
  97. subq.l #4,d6
  98. bne @LMADDSETS1
  99. { restore register }
  100. move.l a2,(sp)+
  101. end ['d0','d6','a0','a1'];
  102. end;
  103. { bildet den Durchschnitt von set1 und set2 }
  104. { und speichert das Ergebnis in dest }
  105. procedure mul_sets(set1,set2,dest : pointer);[public,alias: 'SET_MUL_SETS'];
  106. { type
  107. larray = array[0..7] of longint;
  108. for i:=0 to 7 do
  109. larray(dest^)[i] := larray(set1^)[i] AND larray(set2^)[i];
  110. }
  111. begin
  112. asm
  113. { saved used register }
  114. move.l a2,-(sp)
  115. move.l 8(a6),a0
  116. move.l 12(a6),a1
  117. move.l 16(a6),a2
  118. move.l #8,d6
  119. @LMMULSETS1:
  120. move.l (a0)+,d0
  121. and.l (a1)+,d0
  122. move.l d0,(a2)+
  123. subq.l #4,d6
  124. bne @LMMULSETS1
  125. { restore register }
  126. move.l a2,(sp)+
  127. end ['d0','d6','a0','a1'];
  128. end;
  129. { bildet die Differenz von set1 und set2 }
  130. { und speichert das Ergebnis in dest }
  131. procedure sub_sets(set1,set2,dest : pointer);[public,alias: 'SET_SUB_SETS'];
  132. { type
  133. larray = array[0..7] of longint;
  134. begin
  135. for i:=0 to 7 do
  136. larray(dest^)[i] := larray(set1^)[i] AND NOT (larray(set2^)[i]);
  137. end;
  138. }
  139. begin
  140. asm
  141. { saved used register }
  142. move.l a2,-(sp)
  143. move.l 8(a6),a0
  144. move.l 12(a6),a1
  145. move.l 16(a6),a2
  146. move.l #8,d6
  147. @LSUBSETS1:
  148. move.l (a0)+,d0
  149. not.l d0
  150. and.l (a1)+,d0
  151. move.l d0,(a2)+
  152. subq.l #4,d6
  153. bne @LSUBSETS1
  154. { restore register }
  155. move.l a2,(sp)+
  156. end ['d0','d6','a0','a1'];
  157. end;
  158. { vergleicht Mengen und setzt die Flags entsprechend }
  159. procedure comp_sets(set1,set2 : pointer);[public,alias: 'SET_COMP_SETS'];
  160. begin
  161. asm
  162. move.l 8(a6),a0 { set1 - esi}
  163. move.l 12(a6),a1 { set2 - edi }
  164. move.l #8,d6
  165. @LMCOMPSETS1:
  166. move.l (a0)+,d0
  167. move.l (a1),d1
  168. cmp.l d1,d0
  169. bne @LMCOMPSETEND
  170. add.l #4,a1
  171. subq.l #1,d6
  172. bne @LMCOMPSETS1
  173. { we are here only if the two sets are equal }
  174. { we have zero flag set, and that what is expected }
  175. cmp.l d0,d0
  176. @LMCOMPSETEND:
  177. end;
  178. end;
  179. procedure do_set(p : pointer;b : word);[public,alias: 'SET_SET_WORD'];
  180. begin
  181. asm
  182. move.l 8(a6),a0
  183. move.w 12(a6),d6
  184. andi.l #$fff8,d6
  185. lsl.l #3,d6
  186. adda.l d6,a0
  187. move.b 12(a6),d6
  188. andi.l #7,d6
  189. move.l (a0),d0 { we must put bits into register }
  190. btst.l d6,d0 { otherwise btst will be a byte }
  191. { put result in carry flag } { operation. }
  192. bne @LBIGDOSET1
  193. andi.b #$fe,ccr { clear carry flag }
  194. bra @LBIGDOSET2
  195. @LBIGDOSET1:
  196. ori.b #$01,ccr { set carry flag }
  197. @LBIGDOSET2:
  198. end ['d0','a0','d6'];
  199. end;
  200. { testet, ob das Element b in der Menge p vorhanden ist }
  201. { und setzt das Carryflag entsprechend }
  202. procedure do_in(p : pointer;b : word);[public,alias: 'SET_IN_WORD'];
  203. begin
  204. asm
  205. move.l 8(a6),a0
  206. move.w 12(a6),d6
  207. andi.l #$fff8,d6
  208. lsl.l #3,d6
  209. adda.l d6,a0 { correct offset from start address of set }
  210. move.b 12(a6),d6
  211. andi.l #7,d6
  212. move.l (a0),d0 { we must put bits into register }
  213. btst.l d6,d0 { otherwise btst will be a byte }
  214. { put result in carry flag } { operation. }
  215. bne @LBIGDOIN1
  216. andi.b #$fe,ccr { clear carry flag }
  217. bra @LBIGDOIN2
  218. @LBIGDOIN1:
  219. ori.b #$01,ccr { set carry flag }
  220. @LBIGDOIN2:
  221. end ['d0','a0','d6'];
  222. end;
  223. { vereinigt set1 und set2 und speichert das Ergebnis in dest }
  224. { size is the number of bytes in the set }
  225. procedure add_sets(set1,set2,dest : pointer;size : longint);[public,alias: 'SET_ADD_SETS_SIZE'];
  226. begin
  227. asm
  228. { saved used register }
  229. move.l a2,-(sp)
  230. move.l 8(a6),a0
  231. move.l 12(a6),a1
  232. move.l 16(a6),a2
  233. move.l 20(a6),d6
  234. @LBIGMADDSETS1:
  235. move.l (a0)+,d0
  236. or.l (a1)+,d0
  237. move.l d0,(a2)+
  238. subq.l #4,d6
  239. bne @LBIGMADDSETS1
  240. { restore register }
  241. move.l a2,(sp)+
  242. end ['d0','d6','a0','a1'];
  243. end;
  244. procedure mul_sets(set1,set2,dest : pointer;size : longint);[public,alias: 'SET_MUL_SETS_SIZE'];
  245. { bildet den Durchschnitt von set1 und set2 }
  246. { und speichert das Ergebnis in dest }
  247. { size is the number of bytes in the set }
  248. begin
  249. asm
  250. { saved used register }
  251. move.l a2,-(sp)
  252. move.l 8(a6),a0
  253. move.l 12(a6),a1
  254. move.l 16(a6),a2
  255. move.l 20(a6),d6
  256. @LBIGMMULSETS1:
  257. move.l (a0)+,d0
  258. and.l (a1)+,d0
  259. move.l d0,(a2)+
  260. subq.l #4,d6
  261. bne @LBIGMMULSETS1
  262. { restore register }
  263. move.l a2,(sp)+
  264. end ['d0','d6','a0','a1'];
  265. end;
  266. { bildet die Differenz von set1 und set2 }
  267. { und speichert das Ergebnis in dest }
  268. { size is the number of bytes in the set }
  269. procedure sub_sets(set1,set2,dest : pointer;size : longint);[public,alias: 'SET_SUB_SETS_SIZE'];
  270. begin
  271. asm
  272. { saved used register }
  273. move.l a2,-(sp)
  274. move.l 8(a6),a0
  275. move.l 12(a6),a1
  276. move.l 16(a6),a2
  277. move.l 20(a6),d6
  278. @BIGSUBSETS1:
  279. move.l (a0)+,d0
  280. not.l d0
  281. and.l (a1)+,d0
  282. move.l d0,(a2)+
  283. subq.l #4,d6
  284. bne @BIGSUBSETS1
  285. { restore register }
  286. move.l a2,(sp)+
  287. end ['d0','d6','a0','a1'];
  288. end;
  289. { vergleicht Mengen und setzt die Flags entsprechend }
  290. procedure comp_sets(set1,set2 : pointer;size : longint);[public,alias: 'SET_COMP_SETS_SIZE'];
  291. begin
  292. asm
  293. move.l 8(a6),a0 { set1 - esi}
  294. move.l 12(a6),a1 { set2 - edi }
  295. move.l 16(a6),d6
  296. @MCOMPSETS1:
  297. move.l (a0)+,d0
  298. move.l (a1),d1
  299. cmp.l d1,d0
  300. bne @BIGMCOMPSETEND
  301. add.l #4,a1
  302. subq.l #1,d6
  303. bne @MCOMPSETS1
  304. { we are here only if the two sets are equal }
  305. { we have zero flag set, and that what is expected }
  306. cmp.l d0,d0
  307. @BIGMCOMPSETEND:
  308. end;
  309. end;
  310. {
  311. $Log$
  312. Revision 1.2 1998-03-27 23:47:35 carl
  313. * bugfix of FLAGS as return values for SET_IN_BYTE and SET_SET_BYTE
  314. Revision 1.4 1998/01/26 12:01:42 michael
  315. + Added log at the end
  316. Working file: rtl/m68k/set.inc
  317. description:
  318. ----------------------------
  319. revision 1.3
  320. date: 1998/01/05 00:34:50; author: carl; state: Exp; lines: +349 -350
  321. * Silly syntax errors fixed.
  322. ----------------------------
  323. revision 1.2
  324. date: 1997/12/01 12:37:22; author: michael; state: Exp; lines: +14 -0
  325. + added copyright reference in header.
  326. ----------------------------
  327. revision 1.1
  328. date: 1997/11/28 16:51:20; author: carl; state: Exp;
  329. + set routines for m68k.
  330. =============================================================================
  331. }