From 58b22adaf1e97e4e5397afc229902c0abd103240 Mon Sep 17 00:00:00 2001 From: nickysn Date: Sun, 23 Jun 2013 11:27:00 +0000 Subject: [PATCH] + added function cpubase.segment_regs_equal, which checks whether 2 segment regs are equal in the current memory model git-svn-id: trunk@24949 - --- compiler/x86/cpubase.pas | 47 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/compiler/x86/cpubase.pas b/compiler/x86/cpubase.pas index c3757b4df1..a01e5c66b3 100644 --- a/compiler/x86/cpubase.pas +++ b/compiler/x86/cpubase.pas @@ -35,7 +35,7 @@ interface uses cutils,cclasses, - globtype, + globtype,globals, cgbase ; @@ -286,6 +286,9 @@ uses function inverse_cond(const c: TAsmCond): TAsmCond; {$ifdef USEINLINE}inline;{$endif USEINLINE} function conditions_equal(const c1, c2: TAsmCond): boolean; {$ifdef USEINLINE}inline;{$endif USEINLINE} + { checks whether two segment registers are normally equal in the current memory model } + function segment_regs_equal(r1,r2:tregister):boolean; + {$ifdef i8086} { returns the next virtual register } function GetNextReg(const r : TRegister) : TRegister; @@ -553,6 +556,48 @@ implementation end; + function segment_regs_equal(r1, r2: tregister): boolean; + begin + if not is_segment_reg(r1) or not is_segment_reg(r2) then + internalerror(2013062301); + { every segment register is equal to itself } + if r1=r2 then + exit(true); +{$if defined(i8086)} + case current_settings.x86memorymodel of + mm_tiny: + begin + { CS=DS=SS } + if ((r1=NR_CS) or (r1=NR_DS) or (r1=NR_SS)) and + ((r2=NR_CS) or (r2=NR_DS) or (r2=NR_SS)) then + exit(true); + { the remaining are distinct from each other } + exit(false); + end; + mm_small,mm_medium: + begin + { DS=SS } + if ((r1=NR_DS) or (r1=NR_SS)) and + ((r2=NR_DS) or (r2=NR_SS)) then + exit(true); + { the remaining are distinct from each other } + exit(false); + end; + mm_compact,mm_large,mm_huge: internalerror(2013062303); + else + internalerror(2013062302); + end; +{$elseif defined(i386) or defined(x86_64)} + { DS=SS=ES } + if ((r1=NR_DS) or (r1=NR_SS) or (r1=NR_ES)) and + ((r2=NR_DS) or (r2=NR_SS) or (r2=NR_ES)) then + exit(true); + { the remaining are distinct from each other } + exit(false); +{$endif} + end; + + {$ifdef i8086} function GetNextReg(const r: TRegister): TRegister; begin