Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 1 | /* |
Robin Getz | 96f1050 | 2009-09-24 14:11:24 +0000 | [diff] [blame] | 2 | * Copyright 2005-2009 Analog Devices Inc. |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 3 | * |
Sonic Zhang | de45083 | 2012-05-17 14:45:27 +0800 | [diff] [blame] | 4 | * Licensed under the Clear BSD license or the GPL-2 (or later) |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <linux/linkage.h> |
| 8 | |
| 9 | /* void *memchr(const void *s, int c, size_t n); |
| 10 | * R0 = address (s) |
| 11 | * R1 = sought byte (c) |
| 12 | * R2 = count (n) |
| 13 | * |
| 14 | * Returns pointer to located character. |
| 15 | */ |
| 16 | |
| 17 | .text |
| 18 | |
| 19 | .align 2 |
| 20 | |
| 21 | ENTRY(_memchr) |
| 22 | P0 = R0; /* P0 = address */ |
| 23 | P2 = R2; /* P2 = count */ |
| 24 | R1 = R1.B(Z); |
| 25 | CC = R2 == 0; |
| 26 | IF CC JUMP .Lfailed; |
| 27 | |
| 28 | .Lbytes: |
| 29 | LSETUP (.Lbyte_loop_s, .Lbyte_loop_e) LC0=P2; |
| 30 | |
| 31 | .Lbyte_loop_s: |
| 32 | R3 = B[P0++](Z); |
| 33 | CC = R3 == R1; |
| 34 | IF CC JUMP .Lfound; |
| 35 | .Lbyte_loop_e: |
| 36 | NOP; |
| 37 | |
| 38 | .Lfailed: |
| 39 | R0=0; |
| 40 | RTS; |
| 41 | |
| 42 | .Lfound: |
| 43 | R0 = P0; |
| 44 | R0 += -1; |
| 45 | RTS; |
| 46 | |
Mike Frysinger | 51be24c | 2007-06-11 15:31:30 +0800 | [diff] [blame] | 47 | ENDPROC(_memchr) |