17c478bd9Sstevel@tonic-gate/* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*9a70fc3bSMark J. Nelson * Common Development and Distribution License (the "License"). 6*9a70fc3bSMark J. Nelson * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate/* 227c478bd9Sstevel@tonic-gate * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 26*9a70fc3bSMark J. Nelson .file "strrchr.s" 277c478bd9Sstevel@tonic-gate 287c478bd9Sstevel@tonic-gate/ 297c478bd9Sstevel@tonic-gate/ strrchr(sp, c) 307c478bd9Sstevel@tonic-gate/ 317c478bd9Sstevel@tonic-gate/ Returns the pointer in sp at which the character c last 327c478bd9Sstevel@tonic-gate/ appears; NULL if no found 337c478bd9Sstevel@tonic-gate/ 347c478bd9Sstevel@tonic-gate/ Fast assembly language version of the following C-program strrchr 357c478bd9Sstevel@tonic-gate/ which represents the `standard' for the C-library. 367c478bd9Sstevel@tonic-gate/ 377c478bd9Sstevel@tonic-gate/ char * 387c478bd9Sstevel@tonic-gate/ strrchr(const char *sp, int c) 397c478bd9Sstevel@tonic-gate/ { 407c478bd9Sstevel@tonic-gate/ char *r = NULL; 417c478bd9Sstevel@tonic-gate/ 427c478bd9Sstevel@tonic-gate/ do { 437c478bd9Sstevel@tonic-gate/ if (*sp == (char)c) 447c478bd9Sstevel@tonic-gate/ r = (char *)sp; 457c478bd9Sstevel@tonic-gate/ } while (*sp++); 467c478bd9Sstevel@tonic-gate/ 477c478bd9Sstevel@tonic-gate/ return (r); 487c478bd9Sstevel@tonic-gate/ } 497c478bd9Sstevel@tonic-gate/ 507c478bd9Sstevel@tonic-gate 517c478bd9Sstevel@tonic-gate#include "SYS.h" 527c478bd9Sstevel@tonic-gate 537c478bd9Sstevel@tonic-gate ENTRY(strrchr) 547c478bd9Sstevel@tonic-gate pushl %edi / save register variable 557c478bd9Sstevel@tonic-gate movl 8(%esp), %eax / %eax = string address 567c478bd9Sstevel@tonic-gate movb 12(%esp), %cl / %cl = char sought 577c478bd9Sstevel@tonic-gate movl $0, %edi / %edi = NULL (current occurrence) 587c478bd9Sstevel@tonic-gate 597c478bd9Sstevel@tonic-gate testl $3, %eax / if %eax not word aligned 607c478bd9Sstevel@tonic-gate jnz .L1 / goto .L1 617c478bd9Sstevel@tonic-gate .align 4 627c478bd9Sstevel@tonic-gate.L3: 637c478bd9Sstevel@tonic-gate movl (%eax), %edx / move 1 word from (%eax) to %edx 647c478bd9Sstevel@tonic-gate cmpb %cl, %dl / if the fist byte is not %cl 657c478bd9Sstevel@tonic-gate jne .L4 / goto .L4 667c478bd9Sstevel@tonic-gate movl %eax, %edi / save this address to %edi 677c478bd9Sstevel@tonic-gate.L4: 687c478bd9Sstevel@tonic-gate cmpb $0, %dl / if a null termination 697c478bd9Sstevel@tonic-gate je .L8 / goto .L8 707c478bd9Sstevel@tonic-gate 717c478bd9Sstevel@tonic-gate cmpb %cl, %dh / if the second byte is not %cl 727c478bd9Sstevel@tonic-gate jne .L5 / goto .L5 737c478bd9Sstevel@tonic-gate leal 1(%eax), %edi / save this address to %edi 747c478bd9Sstevel@tonic-gate.L5: 757c478bd9Sstevel@tonic-gate cmpb $0, %dh / if a null termination 767c478bd9Sstevel@tonic-gate je .L8 / goto .L8 777c478bd9Sstevel@tonic-gate 787c478bd9Sstevel@tonic-gate shrl $16, %edx / right shift 16-bit 797c478bd9Sstevel@tonic-gate cmpb %cl, %dl / if the third byte is not %cl 807c478bd9Sstevel@tonic-gate jne .L6 / goto .L6 817c478bd9Sstevel@tonic-gate leal 2(%eax), %edi / save this address to %edi 827c478bd9Sstevel@tonic-gate.L6: 837c478bd9Sstevel@tonic-gate cmpb $0, %dl / if a null termination 847c478bd9Sstevel@tonic-gate je .L8 / goto .L8 857c478bd9Sstevel@tonic-gate 867c478bd9Sstevel@tonic-gate cmpb %cl, %dh / if the fourth byte is not %cl 877c478bd9Sstevel@tonic-gate jne .L7 / goto .L7 887c478bd9Sstevel@tonic-gate leal 3(%eax), %edi / save this address to %edi 897c478bd9Sstevel@tonic-gate.L7: 907c478bd9Sstevel@tonic-gate cmpb $0, %dh / if a null termination 917c478bd9Sstevel@tonic-gate je .L8 / goto .L8 927c478bd9Sstevel@tonic-gate 937c478bd9Sstevel@tonic-gate addl $4, %eax / next word 947c478bd9Sstevel@tonic-gate jmp .L3 / goto .L3 957c478bd9Sstevel@tonic-gate .align 4 967c478bd9Sstevel@tonic-gate.L1: 977c478bd9Sstevel@tonic-gate movb (%eax), %dl / move 1 byte from (%eax) to %dl 987c478bd9Sstevel@tonic-gate cmpb %cl, %dl / if %dl is not %cl 997c478bd9Sstevel@tonic-gate jne .L2 / goto .L2 1007c478bd9Sstevel@tonic-gate movl %eax, %edi / save this address to %edi 1017c478bd9Sstevel@tonic-gate.L2: 1027c478bd9Sstevel@tonic-gate cmpb $0, %dl / if a null termination 1037c478bd9Sstevel@tonic-gate je .L8 / goto .L8 1047c478bd9Sstevel@tonic-gate 1057c478bd9Sstevel@tonic-gate incl %eax / next byte 1067c478bd9Sstevel@tonic-gate testl $3, %eax / if %eax not word aligned 1077c478bd9Sstevel@tonic-gate jnz .L1 / goto .L1 1087c478bd9Sstevel@tonic-gate jmp .L3 / goto .L3 (word aligned) 1097c478bd9Sstevel@tonic-gate .align 4 1107c478bd9Sstevel@tonic-gate.L8: 1117c478bd9Sstevel@tonic-gate movl %edi, %eax / %edi points to the last occurrence or NULL 1127c478bd9Sstevel@tonic-gate popl %edi / restore register variable 1137c478bd9Sstevel@tonic-gate ret 1147c478bd9Sstevel@tonic-gate SET_SIZE(strrchr) 115