File tree 3 files changed +153
-69
lines changed
test/standalone/ez80_builtin/src
3 files changed +153
-69
lines changed Original file line number Diff line number Diff line change
1
+ assume adl=1
2
+
3
+ section .text
4
+ public __bcttz
5
+ __bcttz:
6
+ tst a, 0Fh
7
+ jr z, .high4
8
+ tst a, 3
9
+ jr z, .high6
10
+ cpl
11
+ and a, 1
12
+ ret
13
+ .high6:
14
+ dec a
15
+ and a, 6
16
+ ret po
17
+ rrca
18
+ ret
19
+ .high4:
20
+ tst a, 030h
21
+ jr z, .high2
22
+ dec a
23
+ and a, 014h
24
+ ret po
25
+ ld a, 5
26
+ ret
27
+ .high2:
28
+ add a, a
29
+ sbc a, -8
30
+ ret p
31
+ ld a, 6
32
+ ret
33
+
34
+ section .text
35
+ public __scttz
36
+ __scttz:
37
+ ld a, l
38
+ or a, a
39
+ jr nz, __bcttz
40
+ ld a, h
41
+ require __scttz.hijack
42
+
43
+ section .text
44
+ private __scttz.hijack
45
+ __scttz.hijack:
46
+ call __bcttz
47
+ add a, 8
48
+ ret
49
+
50
+ section .text
51
+ public __icttz
52
+ __icttz:
53
+ xor a, a
54
+ require __icttz.hijack
55
+
56
+ section .text
57
+ private __icttz.hijack
58
+ __icttz.hijack:
59
+ or a, l
60
+ jr nz, __bcttz
61
+ or a, h
62
+ jr nz, __scttz.hijack
63
+ dec sp
64
+ push hl
65
+ inc sp
66
+ pop af
67
+ call __bcttz
68
+ add a, 16
69
+ ret
70
+
71
+ section .text
72
+ public __lcttz
73
+ __lcttz:
74
+ add hl, de
75
+ xor a, a
76
+ sbc hl, de
77
+ jr nz, __icttz.hijack
78
+ ld a, e
79
+ call __bcttz
80
+ add a, 24
81
+ ret
82
+
83
+ section .text
84
+ public __llcttz
85
+ __llcttz:
86
+ add hl, de
87
+ xor a, a
88
+ sbc hl, de
89
+ jr nz, __icttz.hijack
90
+ ex de, hl
91
+ sbc hl, de
92
+ jr nz, __i48cttz.hijack
93
+ or a, c
94
+ jr z, .high
95
+ call __bcttz
96
+ add a, 48
97
+ ret
98
+ .high:
99
+ ld a, b
100
+ call __bcttz
101
+ add a, 56
102
+ ret
103
+
104
+ section .text
105
+ public __i48cttz
106
+ __i48cttz:
107
+ add hl, de
108
+ xor a, a
109
+ sbc hl, de
110
+ jr nz, __icttz.hijack
111
+ ex de, hl
112
+ require __i48cttz.hijack
113
+
114
+ section .text
115
+ private __i48cttz.hijack
116
+ __i48cttz.hijack:
117
+ call __icttz.hijack
118
+ ex de, hl
119
+ add a, 24
120
+ ret
Original file line number Diff line number Diff line change 6
6
7
7
public ___ez80_ctzc
8
8
___ez80_ctzc:
9
- ; unoptimized
10
9
ld hl, 3
11
10
add hl, sp
12
- ld l, (hl)
13
- xor a, a
14
- sub a, l
15
- and a, l
16
- call __bctlz
17
- bit 3, a
18
- ret nz
19
- xor a, 7
20
- ret
11
+ ld a, (hl)
12
+ jp __bcttz
21
13
22
14
;-------------------------------------------------------------------------------
23
15
24
16
section .text
25
17
26
18
public ___ez80_ctzi48
27
19
___ez80_ctzi48:
28
- ; unoptimized
29
- ld hl, 3
20
+ ld hl, 6
30
21
add hl, sp
31
- ld bc, (hl)
32
- inc hl
33
- inc hl
34
- inc hl
35
- ld iy, (hl)
36
- sbc hl, hl
37
- add hl, bc
38
- lea de, iy
39
- call __i48neg
40
- call __i48and
41
- call __i48ctlz
42
- cpl
43
- add a, 48
44
- ret p
45
- ld a, 48
46
- ret
22
+ ld de, (hl)
23
+ dec hl
24
+ dec hl
25
+ dec hl
26
+ ld hl, (hl)
27
+ jp __i48cttz
47
28
48
29
;-------------------------------------------------------------------------------
49
30
50
31
section .text
51
32
52
33
public ___ez80_ffsc
53
34
___ez80_ffsc:
54
- ; unoptimized
55
35
ld hl, 3
56
36
add hl, sp
57
- ld l, (hl)
58
- xor a, a
59
- sub a, l
60
- and a, l
61
- call __bctlz
62
- cpl
63
- add a, 9
37
+ ld a, (hl)
38
+ or a, a
39
+ rla
40
+ jp nz, __bcttz
64
41
ret
65
42
66
43
;-------------------------------------------------------------------------------
@@ -69,24 +46,13 @@ ___ez80_ffsc:
69
46
70
47
public ___ez80_ffss
71
48
___ez80_ffss:
72
- ; unoptimized
73
49
ld hl, 3
74
50
add hl, sp
75
51
ld hl, (hl)
76
- ; HL & -HL
77
- ld b, h
78
- ld c, l
79
- sbc hl, hl
80
- sbc hl, bc
81
52
ld a, h
82
- and a, b
83
- ld h, a
84
- ld a, l
85
- and a, c
86
- ld l, a
87
- call __sctlz
88
- cpl
89
- add a, 17
53
+ or a, l
54
+ add hl, hl
55
+ jp nz, __scttz
90
56
ret
91
57
92
58
;-------------------------------------------------------------------------------
@@ -95,22 +61,18 @@ ___ez80_ffss:
95
61
96
62
public ___ez80_ffsi48
97
63
___ez80_ffsi48:
98
- ; unoptimized
99
- ld hl, 3
64
+ ld hl, 6
100
65
add hl, sp
101
- ld bc, (hl)
102
- inc hl
103
- inc hl
104
- inc hl
105
- ld iy, (hl)
106
- sbc hl, hl
107
- add hl, bc
108
- lea de, iy
109
- call __i48neg
110
- call __i48and
111
- call __i48ctlz
112
- cpl
113
- add a, 49
66
+ ld de, (hl)
67
+ dec hl
68
+ dec hl
69
+ dec hl
70
+ ld hl, (hl)
71
+ call __i48cttz
72
+ inc a
73
+ cp a, 49
74
+ ret nz
75
+ xor a, a
114
76
ret
115
77
116
78
;-------------------------------------------------------------------------------
@@ -406,13 +368,15 @@ ___ez80_rotateright48:
406
368
407
369
extern __snot
408
370
extern __i48not
409
- extern __i48and
410
- extern __i48neg
411
371
412
372
extern __bctlz
413
373
extern __sctlz
414
374
extern __i48ctlz
415
375
376
+ extern __bcttz
377
+ extern __scttz
378
+ extern __i48cttz
379
+
416
380
extern __bpopcnt
417
381
extern __spopcnt
418
382
extern __i48popcnt
Original file line number Diff line number Diff line change @@ -121,7 +121,7 @@ static int test_ctzc(void) {
121
121
unsigned char input ;
122
122
for (int i = 0 ; i < 256 ; i ++ ) {
123
123
input = (unsigned char )i ;
124
- truth = (input == 0 ) ? 8 : __builtin_ctz ((unsigned int )input );
124
+ truth = (input == 0 ) ? 8 : __builtin_ctz ((unsigned int )input | INT_MIN );
125
125
guess = __ez80_ctzc (input );
126
126
CMP ("%d" , input , truth , guess );
127
127
}
@@ -271,7 +271,7 @@ static int test_ctzi48(void) {
271
271
CMP ("%012llX" , (uint64_t )UINT48_MAX , 0 , __ez80_ctzi48 (UINT48_MAX ));
272
272
for (int i = 0 ; i < RANDOM_TEST_COUNT ; i ++ ) {
273
273
input = rand48 ();
274
- truth = (input == 0 ) ? 48 : __builtin_ctzll ((unsigned long long )input );
274
+ truth = (input == 0 ) ? 48 : __builtin_ctzll ((unsigned long long )input | INT64_MIN );
275
275
guess = __ez80_ctzi48 (input );
276
276
CMP ("%012llX" , (uint64_t )input , truth , guess );
277
277
}
You can’t perform that action at this time.
0 commit comments