10Sstevel@tonic-gate/* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7298SMark.J.Nelson@Sun.COM * Common Development and Distribution License (the "License"). 6*7298SMark.J.Nelson@Sun.COM * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate/* 220Sstevel@tonic-gate * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 26*7298SMark.J.Nelson@Sun.COM .file "strrchr.s" 270Sstevel@tonic-gate 280Sstevel@tonic-gate/ 290Sstevel@tonic-gate/ strrchr(sp, c) 300Sstevel@tonic-gate/ 310Sstevel@tonic-gate/ Returns the pointer in sp at which the character c last 320Sstevel@tonic-gate/ appears; NULL if no found 330Sstevel@tonic-gate/ 340Sstevel@tonic-gate/ Fast assembly language version of the following C-program strrchr 350Sstevel@tonic-gate/ which represents the `standard' for the C-library. 360Sstevel@tonic-gate/ 370Sstevel@tonic-gate/ char * 380Sstevel@tonic-gate/ strrchr(const char *sp, int c) 390Sstevel@tonic-gate/ { 400Sstevel@tonic-gate/ char *r = NULL; 410Sstevel@tonic-gate/ 420Sstevel@tonic-gate/ do { 430Sstevel@tonic-gate/ if (*sp == (char)c) 440Sstevel@tonic-gate/ r = (char *)sp; 450Sstevel@tonic-gate/ } while (*sp++); 460Sstevel@tonic-gate/ 470Sstevel@tonic-gate/ return (r); 480Sstevel@tonic-gate/ } 490Sstevel@tonic-gate/ 500Sstevel@tonic-gate 510Sstevel@tonic-gate#include "SYS.h" 520Sstevel@tonic-gate 530Sstevel@tonic-gate ENTRY(strrchr) 540Sstevel@tonic-gate pushl %edi / save register variable 550Sstevel@tonic-gate movl 8(%esp), %eax / %eax = string address 560Sstevel@tonic-gate movb 12(%esp), %cl / %cl = char sought 570Sstevel@tonic-gate movl $0, %edi / %edi = NULL (current occurrence) 580Sstevel@tonic-gate 590Sstevel@tonic-gate testl $3, %eax / if %eax not word aligned 600Sstevel@tonic-gate jnz .L1 / goto .L1 610Sstevel@tonic-gate .align 4 620Sstevel@tonic-gate.L3: 630Sstevel@tonic-gate movl (%eax), %edx / move 1 word from (%eax) to %edx 640Sstevel@tonic-gate cmpb %cl, %dl / if the fist byte is not %cl 650Sstevel@tonic-gate jne .L4 / goto .L4 660Sstevel@tonic-gate movl %eax, %edi / save this address to %edi 670Sstevel@tonic-gate.L4: 680Sstevel@tonic-gate cmpb $0, %dl / if a null termination 690Sstevel@tonic-gate je .L8 / goto .L8 700Sstevel@tonic-gate 710Sstevel@tonic-gate cmpb %cl, %dh / if the second byte is not %cl 720Sstevel@tonic-gate jne .L5 / goto .L5 730Sstevel@tonic-gate leal 1(%eax), %edi / save this address to %edi 740Sstevel@tonic-gate.L5: 750Sstevel@tonic-gate cmpb $0, %dh / if a null termination 760Sstevel@tonic-gate je .L8 / goto .L8 770Sstevel@tonic-gate 780Sstevel@tonic-gate shrl $16, %edx / right shift 16-bit 790Sstevel@tonic-gate cmpb %cl, %dl / if the third byte is not %cl 800Sstevel@tonic-gate jne .L6 / goto .L6 810Sstevel@tonic-gate leal 2(%eax), %edi / save this address to %edi 820Sstevel@tonic-gate.L6: 830Sstevel@tonic-gate cmpb $0, %dl / if a null termination 840Sstevel@tonic-gate je .L8 / goto .L8 850Sstevel@tonic-gate 860Sstevel@tonic-gate cmpb %cl, %dh / if the fourth byte is not %cl 870Sstevel@tonic-gate jne .L7 / goto .L7 880Sstevel@tonic-gate leal 3(%eax), %edi / save this address to %edi 890Sstevel@tonic-gate.L7: 900Sstevel@tonic-gate cmpb $0, %dh / if a null termination 910Sstevel@tonic-gate je .L8 / goto .L8 920Sstevel@tonic-gate 930Sstevel@tonic-gate addl $4, %eax / next word 940Sstevel@tonic-gate jmp .L3 / goto .L3 950Sstevel@tonic-gate .align 4 960Sstevel@tonic-gate.L1: 970Sstevel@tonic-gate movb (%eax), %dl / move 1 byte from (%eax) to %dl 980Sstevel@tonic-gate cmpb %cl, %dl / if %dl is not %cl 990Sstevel@tonic-gate jne .L2 / goto .L2 1000Sstevel@tonic-gate movl %eax, %edi / save this address to %edi 1010Sstevel@tonic-gate.L2: 1020Sstevel@tonic-gate cmpb $0, %dl / if a null termination 1030Sstevel@tonic-gate je .L8 / goto .L8 1040Sstevel@tonic-gate 1050Sstevel@tonic-gate incl %eax / next byte 1060Sstevel@tonic-gate testl $3, %eax / if %eax not word aligned 1070Sstevel@tonic-gate jnz .L1 / goto .L1 1080Sstevel@tonic-gate jmp .L3 / goto .L3 (word aligned) 1090Sstevel@tonic-gate .align 4 1100Sstevel@tonic-gate.L8: 1110Sstevel@tonic-gate movl %edi, %eax / %edi points to the last occurrence or NULL 1120Sstevel@tonic-gate popl %edi / restore register variable 1130Sstevel@tonic-gate ret 1140Sstevel@tonic-gate SET_SIZE(strrchr) 115