1#define Bxx BE 2 3 TEXT memcmp(SB), $0 4 5/* 6 * performance: 7 * (tba) 8 */ 9 10MOVW R7, 0(FP) 11 MOVW n+8(FP), R9 /* R9 is count */ 12 MOVW s1+0(FP), R10 /* R10 is pointer1 */ 13 MOVW s2+4(FP), R11 /* R11 is pointer2 */ 14 ADD R9,R10, R12 /* R12 is end pointer1 */ 15 16/* 17 * if not at least 4 chars, 18 * dont even mess around. 19 * 3 chars to guarantee any 20 * rounding up to a word 21 * boundary and 4 characters 22 * to get at least maybe one 23 * full word cmp. 24 */ 25 SUBCC $4,R9, R0 26 BL out 27 28/* 29 * test if both pointers 30 * are similarly word alligned 31 */ 32 XOR R10,R11, R7 33 ANDCC $3,R7, R0 34 BNE out 35 36/* 37 * byte at a time to word allign 38 */ 39l1: 40 ANDCC $3,R10, R0 41 BE l2 42 MOVB 0(R10), R16 43 MOVB 0(R11), R17 44 ADD $1, R10 45 SUBCC R16,R17, R0 46 BNE ne 47 ADD $1, R11 48 JMP l1 49 50/* 51 * turn R9 into end pointer1-15 52 * cmp 16 at a time while theres room 53 */ 54l2: 55 SUB $15,R12, R9 56l3: 57 SUBCC R10,R9, R0 58 BLEU l4 59 MOVW 0(R10), R16 60 MOVW 0(R11), R17 61 MOVW 4(R10), R18 62 SUBCC R16,R17, R0 63 BNE ne 64 MOVW 4(R11), R19 65 MOVW 8(R10), R16 66 SUBCC R18,R19, R0 67 BNE ne 68 MOVW 8(R11), R17 69 MOVW 12(R10), R18 70 SUBCC R16,R17, R0 71 BNE ne 72 MOVW 12(R11), R19 73 ADD $16, R10 74 SUBCC R18,R19, R0 75 BNE ne 76 SUBCC R16,R17, R0 77 BNE ne 78 ADD $16, R11 79 JMP l3 80 81/* 82 * turn R9 into end pointer1-3 83 * cmp 4 at a time while theres room 84 */ 85l4: 86 SUB $3,R12, R9 87l5: 88 SUBCC R10,R9, R0 89 BLEU out 90 MOVW 0(R10), R16 91 MOVW 0(R11), R17 92 ADD $4, R10 93 SUBCC R16,R17, R0 /* only works because big endian */ 94 BNE ne 95 ADD $4, R11 96 JMP l5 97 98/* 99 * last loop, cmp byte at a time 100 */ 101out: 102 SUBCC R10,R12, R0 103 BE zero 104 MOVB 0(R10), R16 105 MOVB 0(R11), R17 106 ADD $1, R10 107 SUBCC R16,R17, R0 108 BNE ne 109 ADD $1, R11 110 JMP out 111 112ne: 113 BG plus 114 MOVW $1, R7 115 RETURN 116plus: 117 MOVW $-1, R7 118 RETURN 119 120zero: 121 MOVW R0, R7 122 RETURN 123