Welcome to mirror list, hosted at ThFree Co, Russian Federation.

strlen.c « mips « machine « libc « newlib - cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 158fb9f3fb58ef5cd26570e39e2b6c39ef4cf844 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
 * strlen.c -- strlen function.  On at least some MIPS chips, a simple
 * strlen is faster than the 'optimized' C version.
 *
 * Copyright (c) 2001, 2002 Red Hat, Inc.
 *
 * The authors hereby grant permission to use, copy, modify, distribute,
 * and license this software and its documentation for any purpose, provided
 * that existing copyright notices are retained in all copies and that this
 * notice is included verbatim in any distributions. No written agreement,
 * license, or royalty fee is required for any of the authorized uses.
 * Modifications to this software may be copyrighted by their authors
 * and need not follow the licensing terms described here, provided that
 * the new terms are clearly indicated on the first page of each file where
 * they apply.
 */

#include <stddef.h>
#include <string.h>

/* MIPS16 needs to come first.  */

#if defined(__mips16)
size_t
strlen (const char *str)
{
  const char *start = str;

  while (*str++ != '\0')
    ;

  return str - start - 1;
}
#elif defined(__mips64)
__asm__(""			/* 64-bit MIPS targets */
	"	.set	noreorder\n"
	"	.set	nomacro\n"
	"	.globl	strlen\n"
	"	.ent	strlen\n"
	"strlen:\n"
	"	daddiu	$2,$4,1\n"
	"\n"
	"1:	lbu	$3,0($4)\n"
	"	bnez	$3,1b\n"
	"	daddiu	$4,$4,1\n"
	"\n"
	"	jr	$31\n"
	"	dsubu	$2,$4,$2\n"
	"	.end	strlen\n"
	"	.set	macro\n"
	"	.set	reorder\n");

#else
__asm__(""			/* 32-bit MIPS targets */
	"	.set	noreorder\n"
	"	.set	nomacro\n"
	"	.globl	strlen\n"
	"	.ent	strlen\n"
	"strlen:\n"
	"	addiu	$2,$4,1\n"
	"\n"
	"1:	lbu	$3,0($4)\n"
	"	bnez	$3,1b\n"
	"	addiu	$4,$4,1\n"
	"\n"
	"	jr	$31\n"
	"	subu	$2,$4,$2\n"
	"	.end	strlen\n"
	"	.set	macro\n"
	"	.set	reorder\n");
#endif