Hi,
What is the status as far as using optimization is concerned? Is it supposed to be usable? If so I have a problem...
I'm on a Solaris 2.6 Ultra 1 using GPC 2.1 (based on GCC 2.95.2). Source code showing the problem is below.
When I build and run with the commands:-
gpc -c opt.pas gpc -c -DMYMODULE opt.pas -o lichkp1.o gpc opt.o lichkp1.o a.out
I see "ok" but if I use -O i.e.
gpc -c opt.pas gpc -c -DMYMODULE opt.pas -o lichkp1.o -O gpc opt.o lichkp1.o a.out
I see "failed". Can anyone help?
Cheers, Martin G C Davies.
#if defined MYMODULE module opt; #else program opt(output); #endif
const lmpages = 24576 ; lcpgsize = 4096 ; lcpgctrl = 28 ; lmalloc = lcpgsize - lcpgctrl - 4 ;
type mylupage = record number : packed 0..lmpages ; datadisp : packed 0..lmalloc end ; mylopage = ^mylupage;
function lichkp1( mypage : mylopage ) : boolean ; external ;
#if defined MYMODULE function lichkp1( mypage : mylopage ) : boolean ; begin if mypage^.number <> 1 then lichkp1 := false else if ( mypage^.datadisp < lcpgctrl ) or ( mypage^.datadisp > ( lmalloc div 8 ) ) then lichkp1 := false else lichkp1 := true ; end ; #else var mypage : mylupage ; begin mypage.number := 1 ; mypage.datadisp := lcpgctrl ;
if lichkp1(addr(mypage)) then writeln('ok') else writeln('failed'); #endif end.
Yesterday I posted:-
-----Original Message----- From: gpc-owner@gnu.de [mailto:gpc-owner@gnu.de]On Behalf Of Martin G C Davies Sent: 07 August 2002 19:20 To: gpc@gnu.de Subject: GPC 2.1 (GCC 2.95.2) optimization.
Hi,
What is the status as far as using optimization is concerned? Is it supposed to be usable? If so I have a problem...
I reported that problem on Solaris but I now have an even simpler source that shows a problem on Win2000 (I was trying to check if my problems are with Solaris or gpc in general). The source is:-
module opt;
type mylupage = record datadisp : packed 0..31 end ; mylopage = ^mylupage;
function lichkp1( mypage : mylopage ) : integer ; begin if ( mypage^.datadisp < 21 ) or ( mypage^.datadisp > 25 ) then lichkp1 := 100 else lichkp1 := 200 ; end ;
end.
and gpc -v shows
Reading specs from c:/dev_gpc/lib/gcc-lib/mingw32/2.95.3-6/specs gpc version 2.1 (20020510), based on 2.95.3-6 (mingw special)
and when I compile with
gpc -O opt4.pas -S
the contents of opt4.s is:-
.file "opt4.pas" gcc2_compiled.: ___gnu_compiled_pascal: .text .align 4 .def _Lichkp1; .scl 3; .type 32; .ende _Lichkp1: pushl %ebp movl %esp,%ebp movl $100,%eax leave ret .data _ctor_run_condition_0.4: .byte 1 .def __p_atexit; .scl 2; .type 32; .ende .text .align 4 .globl _init_Opt .def _init_Opt; .scl 2; .type 32; .ende _init_Opt: pushl %ebp movl %esp,%ebp subl $8,%esp cmpb $0,_ctor_run_condition_0.4 je L6 movb $0,_ctor_run_condition_0.4 addl $-12,%esp pushl $_fini_Opt call __p_atexit L6: leave ret .align 4 .def _fini_Opt; .scl 3; .type 32; .ende _fini_Opt: pushl %ebp movl %esp,%ebp leave ret
So, as you can see, lichp1 will return 100 whatever the input. Should I just give up with trying to use optimization?
Cheers, Martin G C Davies
Martin G C Davies wrote:
Yesterday I posted:-
What is the status as far as using optimization is concerned? Is it supposed to be usable? If so I have a problem...
Optimization yes, bit-fiddling not always (in particular the packed subranges which are a nonstandard extension, and were apparently not too well debugged yet; a regular subrange in a packed record (the standard way) seems to work better in this case).
module opt;
type mylupage = record datadisp : packed 0..31 end ; mylopage = ^mylupage;
function lichkp1( mypage : mylopage ) : integer ; begin if ( mypage^.datadisp < 21 ) or ( mypage^.datadisp > 25 ) then lichkp1 := 100 else lichkp1 := 200 ; end ;
end.
and when I compile with
gpc -O opt4.pas -S
[...]
So, as you can see, lichp1 will return 100 whatever the input.
The following patch should fix it, thanks for the report. (martin4*.pas)
Frank