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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
|
# sh testcase for cmp/str $rm, $rn -*- Asm -*-
# mach: all
# as: -isa=shcompact
# ld: -m shelf32
.include "compact/testutils.inc"
.macro rot8
rotr r0
rotr r0
rotr r0
rotr r0
rotr r0
rotr r0
rotr r0
rotr r0
.endm
start
# Use multiple "wrong" labels because this program is quite long. It's
# likely that some instructions will be too far away from the branch
# target to use PC-relative branches.
match0:
# No bytes matching.
mov #1, r0
neg r0, r0
xor #170, r0
rot8
xor #170, r0
rot8
xor #170, r0
rot8
xor #170, r0
rot8
mov r0, r1
mov #1, r0
neg r0, r0
xor #85, r0
rot8
xor #85, r0
rot8
xor #85, r0
rot8
xor #85, r0
rot8
cmp/str r0, r1
bt wrong0
bra match1
nop
wrong0:
fail
match1:
# One byte matching.
mov #1, r0
neg r0, r0
xor #170, r0
rot8
xor #170, r0
rot8
xor #170, r0
rot8
mov r0, r1
mov #1, r0
neg r0, r0
xor #85, r0
rot8
xor #85, r0
rot8
xor #85, r0
rot8
cmp/str r0, r1
bf wrong1
bra match2
nop
wrong1:
fail
match2:
# Two bytes matching.
mov #1, r0
neg r0, r0
xor #170, r0
rot8
xor #170, r0
rot8
mov r0, r1
mov #1, r0
neg r0, r0
xor #85, r0
rot8
xor #85, r0
rot8
cmp/str r0, r1
bf wrong2
bra match3
nop
wrong2:
fail
byte0:
match3:
# One byte matching.
# This is also the test for byte 0.
mov #85, r0
mov #85, r1
cmp/str r0, r1
bf wrong3
byte1:
# Match in byte position 1.
mov #85, r0
shll8 r0
mov #85, r1
shll8 r1
cmp/str r0, r1
bf wrong3
byte2:
# Match in byte position 2.
mov #85, r0
shll16 r0
mov #85, r1
shll16 r1
cmp/str r0, r1
bf wrong3
byte3:
# Match in byte position 3.
mov #85, r0
shll16 r0
shll8 r0
mov #85, r1
shll16 r1
shll8 r1
cmp/str r0, r1
bf wrong3
okay:
pass
wrong3:
fail
|