/*1* Returns 0 if exception before NUL or reaching the supplied limit (N),2* a value greater than N if the string is longer than the limit, else3* strlen.4*5* Inputs:6* in0: address of buffer7* in1: string length limit N8* Outputs:9* r8: 0 in case of fault, strlen(buffer)+1 otherwise10*11* Copyright (C) 1999, 2001 David Mosberger-Tang <[email protected]>12*/1314#include <asm/asmmacro.h>1516GLOBAL_ENTRY(__strnlen_user)17.prologue18alloc r2=ar.pfs,2,0,0,019.save ar.lc, r1620mov r16=ar.lc // preserve ar.lc2122.body2324add r3=-1,in125;;26mov ar.lc=r327mov r9=028;;29// XXX braindead strlen loop---this needs to be optimized30.Loop1:31EXCLR(.Lexit, ld1 r8=[in0],1)32add r9=1,r933;;34cmp.eq p6,p0=r8,r035(p6) br.cond.dpnt .Lexit36br.cloop.dptk.few .Loop13738add r9=1,in1 // NUL not found---return N+139;;40.Lexit:41mov r8=r942mov ar.lc=r16 // restore ar.lc43br.ret.sptk.many rp44END(__strnlen_user)454647