RFC: [MIPS] Add an option to disable ldc1/sdc1

Andrew Pinski pinskia@gmail.com
Wed Feb 13 23:09:00 GMT 2013


On Wed, Feb 13, 2013 at 2:14 PM, Chao-Ying Fu <Chao-Ying.Fu@imgtec.com> wrote:
> Hello All,
>
>   Once in a while we got reports about programs (ex: WebKit, FireFox)
> crash due to ldc1/sdc1 unaligned accesses on MIPS targets.  The root cause is that programmers
> neglect the alignment issue and cast arbitrary pointers to point to double variables.


And the code is undefined C/C++ anyways and should really be fixed
rather this workaround.  If the upstream vendor is not willing to fix
undefined code then it is their fault the code does not work rather
than the compiler's.

Thanks,
Andrew Pinski

>
>   Although the correct solution is to fix application source code to fulfill alignment requirements,
> we want to add a GCC option to disable ldc1 and sdc1 (for the testing purpose or for workaround).
> On 32-bit MIPS targets, GCC generates lwc1 and swc1 when -mno-ldc1-sdc1 is used,
> so that the memory address can be just 4-byte aligned to avoid ldc1/sdc1 address exceptions.
>
> Ex:  (The proposed patch)
> Index: mips.opt
> ===================================================================
> --- mips.opt    (revision 196026)
> +++ mips.opt    (working copy)
> @@ -233,6 +233,10 @@
>  Target Report RejectNegative Mask(MIPS3D)
>  Use MIPS-3D instructions
>
> +mldc1-sdc1
> +Target Report Var(TARGET_LDC1_SDC1) Init(1)
> +Use ldc1 and sdc1 instruction
> +
>  mllsc
>  Target Report Mask(LLSC)
>  Use ll, sc and sync instructions
> Index: mips.h
> ===================================================================
> --- mips.h      (revision 196026)
> +++ mips.h      (working copy)
> @@ -840,8 +840,9 @@
>     ST Loongson 2E/2F.  */
>  #define ISA_HAS_CONDMOVE        (ISA_HAS_FP_CONDMOVE || TARGET_LOONGSON_2EF)
>
> -/* ISA has LDC1 and SDC1.  */
> -#define ISA_HAS_LDC1_SDC1      (!ISA_MIPS1 && !TARGET_MIPS16)
> +/* ISA has LDC1 and SDC1 and they are enabled.  */
> +#define ISA_HAS_LDC1_SDC1 \
> +  (!ISA_MIPS1 && !TARGET_MIPS16 && TARGET_LDC1_SDC1)
>
>  /* ISA has the mips4 FP condition code instructions: FP-compare to CC,
>     branch on CC, and move (both FP and non-FP) on CC.  */
>
>   Any feedback?  Thanks a lot!
>
> Regards,
> Chao-ying



More information about the Gcc-patches mailing list