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

Subversion Repositories hf-risc

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

powered by: WebSVN 2.1.0

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