Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

pcc and uldiv for V7 PDP11

2 views
Skip to first unread message

david@sri-unix

unread,
Nov 18, 1982, 5:14:53 AM11/18/82
to
We run a PDP11/70 with 2.8BSD. When compiling some programs with pcc
(as distributed in V7), I occasionally get uldiv and ulrem (unsigned
long division and remainder?) undefined. The references are generated
by pcc and those routines are not in the v7 clib, though they are in
System III clib. Has anyone else run up against this? What sort
of statements in your source program cause pcc to generate references
to these routines? Does anyone have versions of uldiv.s and ulrem.s
for v7 (we have source license)? My alternative is to change the
System III version to run under V7 - it looks to me like the calling
sequence may be different - the System III versions have calls to
different csav and cret routines.

Any information would be appreciated - thanks in advance.

David Brown
Varian Instruments
2700 Mitchell DR
Walnut Creek Ca 94598
(415) 939-2400 x288
...decvax!sytek!zehntel!varian!david

Brl@sri-unix

unread,
Nov 21, 1982, 11:43:45 PM11/21/82
to
From: Doug Gwyn <gwyn@Brl>
Date: 19 Nov 82 14:04:57-EST (Fri)
uldiv & ulrem implement run-time support for unsigned long division & mod.
All of the run-time arithmetic modules were bug-fixed for System III,
and a few were added (uldiv,ulrem,udiv,urem).

The stack frame is the same on PDP-11 System III as on V7, as is cret.
However,
jsr r0,csav
is generated instead of the V7
jsr r5,csv
in order to solve a problem with interrupting csv (the new one is also
slightly faster). Support for both is in the System III library, and
both old-compiled and new-compiled object modules can be mixed in one
executable image.


Mit-Mc@sri-unix

unread,
Nov 21, 1982, 11:49:42 PM11/21/82
to
Date: 19 Nov 1982 16:12:41-EST
uldiv and ulrem are generated by the PCC when it compiles something involving
unsigned longs. They are analogous to ldiv and lrem. If you have floating
point, I long ago wrote the routines to do what uldiv and ulrem are to do.

/**** uldiv.c, by John Woods, October 9, 1982 ****/

unsigned long uldiv(a,b) unsigned long a,b; {
return((unsigned long)((double)a / (double)b));
}
unsigned long auldiv(a,b) unsigned long *a,b; {
return(*a = ((unsigned long)((double)*a / (double)b)));
}
unsigned long ulmul(a,b) unsigned long a,b; {
return((unsigned long)((double)a * (double)b));
}
unsigned long aulmul(a,b) unsigned long *a,b; {
return(*a = ((unsigned long)((double)*a * (double)b)));
}
/****************/

The following is a massaged assembly language version which avoids some of the
overhead of C procedure discipline: (It was compiled -S by PCC and -O'd by me).

/**** uldiv.s, by John Woods, October 9, 1982 ****/
.text
.globl uldiv
uldiv:
/ line 2, file "uldiv.c"
setl
movif 2.(sp),fr0
cfcc
bpl 1f
addf $050200,fr0
1:
movif 6.(sp),fr1
cfcc
bpl 1f
addf $050200,fr1
1:
divf fr1,fr0
movfi fr0,-(sp)
seti
mov (sp)+,r0
mov (sp)+,r1
rts pc
.globl fltused
.globl auldiv
auldiv:
/ line 5, file "uldiv.c"
mov 2.(sp),r1
mov (r1)+,r0
mov (r1),r1
mov r1,-(sp)
mov r0,-(sp)
setl
movif (sp)+,fr0
cfcc
bpl 1f
addf $050200,fr0
1:
movif 4.(sp),fr1
cfcc
bpl 1f
addf $050200,fr1
1:
divf fr1,fr0
movfi fr0,-(sp)
seti
mov (sp)+,r0
mov (sp)+,r1
mov 2.(sp),r2
mov r0,(r2)+
mov r1,(r2)
rts pc
.globl fltused
.globl ulmul
ulmul:
/ line 8, file "uldiv.c"
setl
movif 2.(sp),fr0
seti
cfcc
bpl 1f
addf $050200,fr0
1:
setl
movif 6.(sp),fr1
cfcc
bpl 1f
addf $050200,fr1
1:
mulf fr1,fr0
movfi fr0,-(sp)
seti
mov (sp)+,r0
mov (sp)+,r1
rts pc
.globl fltused
.globl aulmul
aulmul:
/ line 11, file "uldiv.c"
mov 2.(sp),r1
mov (r1)+,r0
mov (r1),r1
mov r1,-(sp)
mov r0,-(sp)
setl
movif (sp)+,fr0
cfcc
bpl 1f
addf $050200,fr0
1:
setl
movif 4.(sp),fr1
cfcc
bpl 1f
addf $050200,fr1
1:
mulf fr1,fr0
movfi fr0,-(sp)
seti
mov (sp)+,r0
mov (sp)+,r1
mov 2.(sp),r2
mov r0,(r2)+
mov r1,(r2)
rts pc
.globl fltused
.data

adec23!eric

unread,
Nov 22, 1982, 11:56:15 PM11/22/82
to
I take exception to the statement "All of the run-time arithmetic modules
were bug-fixed for System III ..." in sri-unix.4288.
The System III we are running arrived with the same old bug in the long
division and remainder routines. The following routine should print:
20000000000 1 20000000000
On an 11/23 the result is 20000000000 1 0.
On an 11/40 the result is 20000000000 1 37777700001.
Admittedly these are not typical UNIX machines, but the Processor Handbooks all
say that the values left in R and Rv1 are unpredictable if overflow occurs.
I would be interested in finding out if there are ANY machines on which the
'vanilla' ldiv and lrem routines work properly.
I will post our fixup if interest warrants.
Eric Norum
(...!decvax!harpo!utah-cs!sask!hssg40!adec23!eric)

/*
* Check for bug in PDP-11 long division routines
*/
long int i, j, k;
main ()
{
i = 020000000000;
j = 1;
k = i / j;
printf ("%lo %lo %lo\n", i, j, k);
}

0 new messages