[Pixman] [PATCH v2 2/3] build: use '-mloongson-mmi' for Loongson MMI.

Shiyou Yin yinshiyou-hf at loongson.cn
Wed Feb 26 09:45:45 UTC 2020

>-----Original Message-----
>From: YunQiang Su [mailto:wzssyqa at gmail.com]
>Sent: Saturday, February 22, 2020 10:20 PM
>To: Shiyou Yin
>Cc: pixman at lists.freedesktop.org
>Subject: Re: [Pixman] [PATCH v2 2/3] build: use '-mloongson-mmi' for Loongson MMI.
>Shiyou Yin <yinshiyou-hf at loongson.cn> 于2020年2月22日周六 下午9:19写道:
>> First let's clarify what exactly compatibility mean, or what specific goals we want to achieve.
>> If it's just ensure the features of new code consistent with old compilation and hardware
>> environment, then this patch will works well.
>Of course that is not enough. If it is the only your goal, why sent this patch?
>> If it is going to make sure MMI can be enabled and works well on each cases, it may be not easy.
>> Guess compiler? Compiler check can only ensure the compile option is supported or not
>yq at ls3b1500:~$ gcc -march=loongson3a -dM -E - < /dev/null | grep mmi
>#define __mips_loongson_mmi 1
>So, you can try to compile (-c) the bellow code to test whether the
>compiler has MMI enabled
>#ifndef __mips_loongson_mmi
># error "Loongson MMI is not supported"
>For example, mipsel-linux-gnu-gcc is a generic mips compiler and
>target mips32r2;
>and the user set CC="mipsel-linux-gnu-gcc -march=loongson3",
>Your test can still pass.
>> and then MMI instruction can be compiled. We can't ensure the binary can works well on
>> each hardware, especially in the case of cross-compilation.
>Sure, that why you need to obey users configure, by LS_CFLAGS or CC or
>the default configure of compiler.
>> Almost all latest gcc support "-march=loongson2f" and "-march=loongson3a"
>> and "-mloongson-mmi". So which kind of compiler we will set LS_CFLAGS as -mloongson-mmi?
>due to history reason, the default value of LS_CFLAGS should be keep as 2f, and
>user can set it by
>LS_CFLAGS="-mloongson-mmi" ./configure -- blabla
>> Guess CPU is always used in runtime check, it should be added in the optimization code but not in
>> configure. The configure just need to ensure the compile process can finished successfully,
>> So it may check compiler support some options or not and then enable/disable the features.
>Generally, we don't need to guess the BUILD_MACHINE's cpu in buildtime.

If this is what you mean, I will agree and update the patch.
It should be noted that we still need to manually specify appropriate option to enable MMI correctly.
The only change is now we have two new ways(2 & 3) to specify this option:
2) CC
3)compiler's default cflags, such as COLLECT_GCC_OPTIONS of gcc.

Diff is as follows:

diff --git a/configure.ac b/configure.ac
index 1ca3974..be9212d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -78,7 +78,7 @@ AC_C_BIGENDIAN
 dnl PIXMAN_LINK_WITH_ENV(env-setup, program, true-action, false-action)
 dnl Compiles and links the given program in the environment setup by env-setup
 dnl and executes true-action on success and false-action on failure.
@@ -273,7 +273,27 @@ dnl ===========================================================================
 dnl Check for Loongson Multimedia Instructions
 if test "x$LS_CFLAGS" = "x" ; then
-    LS_CFLAGS="-march=loongson2f"
+  # check default cflags to set LS_CFLAGS
+  # Has -mloongson-mmi or -march=loongson3a : LS_CFLAGS="-mloongson-mmi"
+  # else : LS_CFLAGS="-march=loongson2f"
+  xserver_save_CFLAGS=$CFLAGS
+int main () {
+  /* check default cflags */
+  #ifndef __mips_loongson_mmi
+  /* No -mloongson-mmi,-march=loongson3a and -march=loongson2f */
+  return 0;
+  #else
+    /* Has -march=loongson2f */
+    return 0;
+    #else
+    /* Has -mloongson-mmi or -march=loongson3a */
+    return 1;
+    #endif
+  #endif
+}]])], LS_CFLAGS="-mloongson-mmi", LS_CFLAGS="-march=loongson2f")

More information about the Pixman mailing list