#------------------------------------------------------------------ # Copyright Unpublished, Motorola, Inc. All Rights Reserved. This # software contains proprietary and confidential information of # Motorola, Inc. Use, disclosure or reproduction is prohibited # without the prior express written consent of Motorola, Inc. #------------------------------------------------------------------ #------------------------------------------------------------------ # int strcmp(const unsigned char* source1, # const unsigned char* source2); # Returns: # value < 0 if source1 < source2 # value = 0 if source1 = source2 # value > 0 if source1 > source2 #------------------------------------------------------------------ .set _eq,2 .set _cr0,0 .set _cr1,1 #aix# .toc #aix#T..strcmp: #aix# .tc ..strcmp[tc], strcmp[ds] #aix# .align 2 #aix# .globl strcmp[ds] #aix# .csect strcmp[ds] #aix# .long .strcmp[pr],TOC[tc0],0 #aix# .globl .strcmp[pr] #aix# .csect .strcmp[pr] #aix#.strcmp: .sect .text .align 2 .extern strcmp strcmp: #nt# .reldata #nt# .globl strcmp #nt#strcmp: #nt# .long ..strcmp,.toc #nt# .text #nt# .globl ..strcmp #nt#..strcmp: # r0 = temporary # r3 = source1 pointer, result, mask for first words # r4 = source2 pointer # r5 = 0x80808080 # r6 = 0x01010101 # r7 = source2 word # r8 = source1 word # r9 = temporary # r10 = source1 pointer # r11 = temporary # r12 = index # See if the two pointers are both word aligned. xor r0,r3,r4 rlwinm. r0,r0,0,30,31 addis r6,r0,0x0101 mr r10,r3 bne Byte_By_Byte # Generate an initial index so the word containing the first byte # will be loaded. Compute a mask to set all bits in the bytes # prior to the first in the words that are loaded. rlwinm r11,r3,3,27,28 li r3,-1 rlwinm r12,r10,0,30,31 subfic r11,r11,32 neg r12,r12 slw r3,r3,r11 # Complete the setup for the word aligned loop. ori r6,r6,0x0101 lwzx r8,r12,r10 #le# lwbrx r8,r12,r10 or r8,r8,r3 # Mask off unused bytes. slwi r5,r6,7 subfc r0,r6,r8 andc r9,r5,r8 lwzx r7,r12,r4 #le# lwbrx r7,r12,r4 and. r11,r0,r9 addi r4,r4,-4 addi r12,r12,4 or r7,r7,r3 # Mask off unused bytes. bne Source1_Has_Null Word_Loop: subfc. r3,r8,r7 bne Words_Differ lwzx r8,r12,r10 #le# lwbrx r8,r12,r10 subfc r0,r6,r8 andc r9,r5,r8 and. r11,r0,r9 addi r12,r12,4 lwzx r7,r12,r4 #le# lwbrx r7,r12,r4 beq Word_Loop Source1_Has_Null: # We terminated the loop because r8 has a null byte. # Shift both words right so the null byte is the LSB. # Can't do this with cntlzw because of a borrow if the byte # preceeding the null has the value one. rlwinm. r10,r8,0,0,7 li r9,24 beq shift rlwinm. r10,r8,0,8,15 li r9,16 beq shift rlwinm. r10,r8,0,16,23 li r9,8 beq shift li r9,0 shift: srw r7,r7,r9 srw r8,r8,r9 subfc r3,r7,r8 blr Words_Differ: # We terminated the loop because the words differ but # r8 does not have a null byte. Return 1 or -1 based # on the unsigned comparison. subfe r3,r3,r3 nand r3,r3,r3 ori r3,r3,1 blr Byte_By_Byte: # Do strcmp a byte at a time. lbz r9,0(r3) lbz r0,0(r4) subfc. r3,r0,r9 bnelr Byte_Loop: cmpi _cr1,0,r9,0 beq _cr1,Null_Byte lbzu r9,1(r10) lbzu r0,1(r4) subfc. r3,r0,r9 beq Byte_Loop blr Null_Byte: mr r3,r0 blr