In the version I built 4 months ago, that particular division in print() also generated a DIV instruction.
We are possibly talking at cross-purposes here.
Are you saying that one or other of the patches either is no longer needed, or just plain doesn’t make sense?
I have the latest GCC sources (from the git mirror) now checked out, so I’m able to fairly quickly test things.
It seems only the second patch (to pdp11.md) is needed for the spigot test case to run.
Here’s my test case for the first patch:
#include "tube.h"
void outhex(uint8_t i);
void outhex32(uint32_t i);
void outnl();
int program() {
uint32_t a = 0x12345678;
uint32_t *ap = &a;
outhex32(*ap);
outnl();
}
void outhex(uint8_t i) {
i &= 15;
if (i > 9) {
outc(i + ('A' - 10));
} else {
outc(i + '0');
}
}
void outhex32(uint32_t i) {
int d;
for (d = 0; d < 8; d++) {
// Note: this uses ASHC which is a signed shift
outhex((uint8_t)(i >> 28));
i <<= 4;
}
}
void outnl() {
outc(10);
outc(13);
}
This fails with the latest GCC, which generates the following code:
00000128 <_program>:
128: 1166 mov r5, -(sp)
12a: 1185 mov sp, r5
12c: 65c6 fffa add $-6, sp
130: 15f5 1234 fffa mov $11064, -6(r5)
136: 15f5 5678 fffc mov $53170, -4(r5)
13c: 15c0 fffa mov $-6, r0
140: 6140 add r5, r0
142: 1035 fffe mov r0, -2(r5)
146: 1d40 fffe mov -2(r5), r0
14a: 1200 mov (r0), r0 <<<<< clobbers r0
14c: 1c01 0002 mov 2(r0), r1
150: 1066 mov r1, -(sp)
152: 1026 mov r0, -(sp)
154: 09f7 004e jsr pc, 1a6 <_outhex32>
158: 65c6 0004 add $4, sp
15c: 09f7 009c jsr pc, 1fc <_outnl>
160: 00a0 nop
162: 1146 mov r5, sp
164: 1585 mov (sp)+, r5
166: 0087 rts pc
With the patch (to pdp11.cc), the code is:
00000128 <_program>:
128: 1166 mov r5, -(sp)
12a: 1185 mov sp, r5
12c: 65c6 fffa add $-6, sp
130: 15f5 1234 fffa mov $11064, -6(r5)
136: 15f5 5678 fffc mov $53170, -4(r5)
13c: 15c0 fffa mov $-6, r0
140: 6140 add r5, r0
142: 1035 fffe mov r0, -2(r5)
146: 1d40 fffe mov -2(r5), r0
14a: 1c01 0002 mov 2(r0), r1 <<<< swapped
14e: 1200 mov (r0), r0 <<<< swapped
150: 1066 mov r1, -(sp)
152: 1026 mov r0, -(sp)
154: 09f7 004e jsr pc, 1a6 <_outhex32>
158: 65c6 0004 add $4, sp
15c: 09f7 009c jsr pc, 1fc <_outnl>
160: 00a0 nop
162: 1146 mov r5, sp
164: 1585 mov (sp)+, r5
166: 0087 rts pc
This is all with -O0