From 52fcc0a407da0bc2b0a1a7edc6f90756e790c29c Mon Sep 17 00:00:00 2001 From: nickysn Date: Sat, 28 Sep 2013 11:54:02 +0000 Subject: [PATCH] + added a new x86-specific compiler option 'enablecld', which controls whether the compiler should emit a CLD before using the x86 string instructions. git-svn-id: trunk@25590 - --- compiler/globals.pas | 13 +++++++++++++ compiler/i386/cgcpu.pas | 3 ++- compiler/i8086/cgcpu.pas | 3 ++- compiler/options.pas | 4 ++++ compiler/x86/cgx86.pas | 5 ++--- 5 files changed, 23 insertions(+), 5 deletions(-) diff --git a/compiler/globals.pas b/compiler/globals.pas index 32f4610940..9df087d776 100644 --- a/compiler/globals.pas +++ b/compiler/globals.pas @@ -154,6 +154,12 @@ interface disabledircache : boolean; +{$if defined(x86)} + { setting this to true causes the compiler to emit a CLD instruction + before using the x86 string instructions. } + enablecld : boolean; +{$endif defined(x86)} + {$if defined(i8086)} x86memorymodel : tx86memorymodel; {$endif defined(i8086)} @@ -485,6 +491,13 @@ interface minfpconstprec : s32real; disabledircache : false; +{$if defined(i8086)} + enablecld : true; +{$elseif defined(i386)} + enablecld : true; +{$elseif defined(x86_64)} + enablecld : false; +{$endif} {$if defined(i8086)} x86memorymodel : mm_small; {$endif defined(i8086)} diff --git a/compiler/i386/cgcpu.pas b/compiler/i386/cgcpu.pas index bbda0fbc92..84fe41438f 100644 --- a/compiler/i386/cgcpu.pas +++ b/compiler/i386/cgcpu.pas @@ -485,7 +485,8 @@ unit cgcpu; else list.concat(Taicpu.op_const_reg(A_IMUL,S_L,len,NR_ECX)); end; - list.concat(Taicpu.op_none(A_CLD,S_NO)); + if current_settings.enablecld then + list.concat(Taicpu.op_none(A_CLD,S_NO)); list.concat(Taicpu.op_none(A_REP,S_NO)); case opsize of S_B : list.concat(Taicpu.Op_none(A_MOVSB,S_NO)); diff --git a/compiler/i8086/cgcpu.pas b/compiler/i8086/cgcpu.pas index d97b3dc950..add88cb5f2 100644 --- a/compiler/i8086/cgcpu.pas +++ b/compiler/i8086/cgcpu.pas @@ -1504,7 +1504,8 @@ unit cgcpu; else list.concat(Taicpu.op_const_reg(A_IMUL,S_W,len,NR_CX)); end; - list.concat(Taicpu.op_none(A_CLD,S_NO)); + if current_settings.enablecld then + list.concat(Taicpu.op_none(A_CLD,S_NO)); list.concat(Taicpu.op_none(A_REP,S_NO)); case opsize of S_B : list.concat(Taicpu.Op_none(A_MOVSB,S_NO)); diff --git a/compiler/options.pas b/compiler/options.pas index 5f740bf702..779c971c30 100644 --- a/compiler/options.pas +++ b/compiler/options.pas @@ -3475,6 +3475,10 @@ if (target_info.abi = abi_eabihf) then mm_huge: def_system_macro('FPC_MM_HUGE'); end; {$endif} +{$if defined(x86)} + if current_settings.enablecld then + def_system_macro('FPC_ENABLED_CLD'); +{$endif} { Section smartlinking conflicts with import sections on Windows } diff --git a/compiler/x86/cgx86.pas b/compiler/x86/cgx86.pas index e3f428f17a..5bfe9ae93e 100644 --- a/compiler/x86/cgx86.pas +++ b/compiler/x86/cgx86.pas @@ -2233,9 +2233,8 @@ unit cgx86; end; getcpuregister(list,REGCX); -{$if defined(i8086) or defined(i386)} - list.concat(Taicpu.op_none(A_CLD,S_NO)); -{$endif i8086 or i386} + if current_settings.enablecld then + list.concat(Taicpu.op_none(A_CLD,S_NO)); if (cs_opt_size in current_settings.optimizerswitches) and (len>sizeof(aint)+(sizeof(aint) div 2)) then begin