2 * memcmp routine for Z8000
3 * Copyright (C) 2004 Christian Groessler <chris@groessler.org>
5 * Permission to use, copy, modify, and distribute this file
6 * for any purpose is hereby granted without fee, provided that
7 * the above copyright notice and this notice appears in all
10 * This file is distributed WITHOUT ANY WARRANTY; without even the implied
11 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 /* int memcmp(const void *b1, const void *b2, size_t length);
34 /* rr2 - length (high word ignored)
39 clr r1 /* initialize return value */
43 bitb rl7,#0 /* odd b1? */
45 bitb rl5,#0 /* odd b2? */
46 jr nz,odd_cmp /* b1 even, b2 odd */
51 jr z,odd_cmp /* b2 even, b1 odd */
54 jr z,beq /* bytes are the same */
57 beq: jr ov,finish /* jump if r3 is zero now */
61 ld r2,r3 /* remember length */
69 dec r5,#2 /* point to different bytes */
74 bitb rl2,#0 /* odd length? */
78 jr z,finish /* last bytes are the same */
83 cpsirb @rr6,@rr4,r3,ne
88 dec r5,#1 /* point to different bytes */
95 finish: /* set return value */
103 #else /* above Z8001, below Z8002 */
119 clr r1 /* initialize return value */
123 bitb rl7,#0 /* odd destination address? */
125 bitb rl6,#0 /* odd source address? */
126 jr nz,odd_cmp /* b1 even, b2 odd */
131 jr z,odd_cmp /* b2 even, b1 odd */
134 jr z,beq /* bytes are the same */
137 beq: jr ov,finish /* jump if r3 is zero now */
141 ld r4,r5 /* remember length */
149 dec r6,#2 /* point to different bytes */
154 bitb rl4,#0 /* odd length? */
158 jr z,finish /* last bytes are the same */
168 dec r6,#1 /* point to different bytes */