OpenCores
URL https://opencores.org/ocsvn/hf-risc/hf-risc/trunk

Subversion Repositories hf-risc

[/] [hf-risc/] [trunk/] [tools/] [riscv-gnu-toolchain-master/] [newlib/] [newlib/] [libc/] [machine/] [riscv/] [strcmp.S] - Blame information for rev 13

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 13 serginhofr
# Artisanally coded in California by A. Shell Waterman
2
 
3
#include 
4
 
5
#if BYTE_ORDER != LITTLE_ENDIAN
6
# error
7
#endif
8
 
9
.text
10
.globl strcmp
11
strcmp:
12
  or    a4, a0, a1
13
  li    t2, -1
14
  and   a4, a4, SZREG-1
15
  bnez  a4, .Lmisaligned
16
 
17
#if SZREG == 4
18
  li t3, 0x7f7f7f7f
19
#else
20
  ld t3, mask
21
#endif
22
 
23
  .macro check_one_word i n
24
    REG_L a2, \i*SZREG(a0)
25
    REG_L a3, \i*SZREG(a1)
26
 
27
    and   t0, a2, t3
28
    or    t1, a2, t3
29
    add   t0, t0, t3
30
    or    t0, t0, t1
31
 
32
    bne   t0, t2, .Lnull\i
33
    .if \i+1-\n
34
      bne   a2, a3, .Lmismatch
35
    .else
36
      add   a0, a0, \n*SZREG
37
      add   a1, a1, \n*SZREG
38
      beq   a2, a3, .Lloop
39
      # fall through to .Lmismatch
40
    .endif
41
  .endm
42
 
43
  .macro foundnull i n
44
    .ifne \i
45
      .Lnull\i:
46
      add   a0, a0, \i*SZREG
47
      add   a1, a1, \i*SZREG
48
      .ifeq \i-1
49
        .Lnull0:
50
      .endif
51
      bne   a2, a3, .Lmisaligned
52
      li    a0, 0
53
      ret
54
    .endif
55
  .endm
56
 
57
.Lloop:
58
  # examine full words
59
  check_one_word 0 3
60
  check_one_word 1 3
61
  check_one_word 2 3
62
  # backwards branch to .Lloop contained above
63
 
64
.Lmismatch:
65
  # words don't match, but a2 has no null byte.
66
#ifdef __riscv64
67
  sll   a4, a2, 48
68
  sll   a5, a3, 48
69
  bne   a4, a5, .Lmismatch_upper
70
  sll   a4, a2, 32
71
  sll   a5, a3, 32
72
  bne   a4, a5, .Lmismatch_upper
73
#endif
74
  sll   a4, a2, 16
75
  sll   a5, a3, 16
76
  bne   a4, a5, .Lmismatch_upper
77
 
78
  srl   a4, a2, 8*SZREG-16
79
  srl   a5, a3, 8*SZREG-16
80
  sub   a0, a4, a5
81
  and   a1, a0, 0xff
82
  bnez  a1, 1f
83
  ret
84
 
85
.Lmismatch_upper:
86
  srl   a4, a4, 8*SZREG-16
87
  srl   a5, a5, 8*SZREG-16
88
  sub   a0, a4, a5
89
  and   a1, a0, 0xff
90
  bnez  a1, 1f
91
  ret
92
 
93
1:and   a4, a4, 0xff
94
  and   a5, a5, 0xff
95
  sub   a0, a4, a5
96
  ret
97
 
98
.Lmisaligned:
99
  # misaligned
100
  lbu   a2, 0(a0)
101
  lbu   a3, 0(a1)
102
  add   a0, a0, 1
103
  add   a1, a1, 1
104
  bne   a2, a3, 1f
105
  bnez  a2, .Lmisaligned
106
 
107
1:
108
  sub   a0, a2, a3
109
  ret
110
 
111
  # cases in which a null byte was detected
112
  foundnull 0, 3
113
  foundnull 1, 3
114
  foundnull 2, 3
115
 
116
#if SZREG == 8
117
.section .srodata.cst8,"aM",@progbits,8
118
.align 3
119
mask:
120
.dword 0x7f7f7f7f7f7f7f7f
121
#endif

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.