#"C" users read Pascal?
5 messages in this thread
Tom, here is a sample from the VAX. I had to make this a subroutine that works
on data in common or the VAX compiler optimized out *all* the code. here goes:
subroutine swert
real a1(100),a2(100),a3(100)
common /zork/a1,a2,a3
do 10 i= 1, 100
a1(i) = a2(i) + a3(i)
10 continue
return
end
.PSECT $CODE
SWERT::
.WORD ^M<IV>
MOVZBL #100, R0
MOVL #1, R1
MOVAF A1, R12
L$1:
ADDF3 800(R12), 400(R12), (R12)+
AOBLEQ R0, R1, L$1
RET
Notice that the compiler only needs one address for three arrays, as it knows
where the other two are in reference to the first. The VAX also has an indexed
addressing mode.
Jhon– I already have code for VAX Fortran and ePascal.The Fortran is the
only compiler so far to get 100% for both total and loop code. The Pascal gets
100% for the loop but only 150% for total because it uses 3 pointers rather
than 1 with offsets to the other arrays. I use write statements after the loop
to keep the compiler from deleting the entire code. If only all compilers were
as devoted to code optimization as this one there would be very little assembly
code written by hand. Do you have access to the VAX C, or PL/1 compilers?
To read all messages non stop without making the option permanent use without
the quotes: "OP;SM N;S;RN". This is what I use to read all messages into my
log file. Thanks to Arley Dealey for coming up with this.
Tom
Tom,
It looks like Turbo Pascal could use some real improvement in the code it
generates. I compiled this on a Z80 version of Turbo. To tell you the truth,
I'm not impressed. I used to think that Turbo did a good job of optimization.
; program test; type
anarray = array [1..100] of integer; var
i, n : integer;
array1, array2, array3 : anarray; begin
n := 100;
for i := 1 to n do
array1[i] := array2[i] + array3[i]; end. ; ; the loopset routine is
called by every for loop before the first ; iteration. it returns the
number of iterations in de and the initial ; value of the loop index
variable in hl. ; loopset:
or a
sbc hl,de
ex de,hl
inc de
jp pe,.ls1
ret p
jr .ls2
ls1: ret m
ls2: ld de,0
ret start: ld hl,100
ld (n),hl ;n=100
ld hl,1
push hl
ld hl,(n)
pop de
call loopset ;loop setup returns hl=start,de=#iterations
loop: ld a,d
or e
jp z,done ;if de=0, we're done
push de ;save loop counter
ld (i),hl ;
ld hl,array1 ;array1 base
push hl
ld hl,(i) ;loop index
dec hl
add hl,hl ;hl=array offset
pop de ;de=base address
add hl,de
push hl ;save destination
ld hl,array2 ;array2 base
push hl
ld hl,(i) ;loop index
dec hl
add hl,hl ;hl=offset
pop de ;de=base
add hl,de ;points to operand
ld e,(hl)
inc hl
ld d,(hl) ;operand in de
ex de,hl
push hl ;first operand on stack
ld hl,array3 ;array3 base
push hl
ld hl,(i)
dec hl
add hl,hl
pop de
add hl,de ;points to operand
ld e,(hl)
inc hl
ld d,(hl) ;operand in de
ex de,hl ;to hl
pop de ;restore first operand
add hl,de ;hl = array[2] + array[3]
ex de,hl ;de = " "
pop hl ;hl = destination address
ld (hl),e
inc hl
ld (hl),d ;and it's saved
ld hl,(i)
inc hl ;i = i+1
pop de
dec de ;decrement loop counter
jp loop ;and go again done:
<continued in next message>
<continued from previous message>
I pulled out my copy of Pascal MT+ and tried it. The loop code has 1
instruction less than the Turbo Pascal code, but the processing is exactly the
same. MT+ re-arranges things a little, but doesn't really change them. The
loop setup code is much different, but is nearly the same number of
instructions. I'll upload it if you like.
JIM
Yes, I do. I have not done that yet, but I will. I also have access to the
Ultrix fortran and C, but not right now. I tried last night to get there, but
our network was down at work and the only way into the Ultrix machine is
through the 8650. If it is up, I will try tonight.
jhon