set.inc 11 KB

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