Allow FPU flag override (#471)
authorSinan Kaya <41809318+franksinankaya@users.noreply.github.com>
Wed, 4 Dec 2019 18:20:00 +0000 (13:20 -0500)
committerJan Kotas <jkotas@microsoft.com>
Wed, 4 Dec 2019 18:20:00 +0000 (10:20 -0800)
Command line to build for vfpv3-d16 ARM Cortex-5:

./build.sh -cross -arm -cmakeargs -DCLR_ARM_FPU_CAPABILITY=0x3 -cmakeargs -DCLR_ARM_FPU_TYPE=vfpv3-d16

Fixes https://github.com/dotnet/coreclr/issues/17043

eng/common/cross/toolchain.cmake
src/coreclr/configurecompiler.cmake
src/coreclr/src/pal/src/arch/arm/context2.S
src/libraries/Native/Unix/CMakeLists.txt

index 0eea7d1..b48ae28 100644 (file)
@@ -71,8 +71,17 @@ endif()
 
 if(TARGET_ARCH_NAME MATCHES "^(arm|armel)$")
   add_compile_options(-mthumb)
-  add_compile_options(-mfpu=vfpv3)
-  if(TARGET_ARCH_NAME STREQUAL "armel")
+  if (NOT DEFINED CLR_ARM_FPU_TYPE)
+    set(CLR_ARM_FPU_TYPE vfpv3)
+  endif(NOT DEFINED CLR_ARM_FPU_TYPE)
+
+  add_compile_options(-mfpu=${CLR_ARM_FPU_TYPE})
+  if (NOT DEFINED CLR_ARM_FPU_CAPABILITY)
+    set(CLR_ARM_FPU_CAPABILITY 0x7)
+  endif(NOT DEFINED CLR_ARM_FPU_CAPABILITY)
+  add_definitions(-DCLR_ARM_FPU_CAPABILITY=${CLR_ARM_FPU_CAPABILITY})
+
+ if(TARGET_ARCH_NAME STREQUAL "armel")
     add_compile_options(-mfloat-abi=softfp)
     if(DEFINED TIZEN_TOOLCHAIN)
       add_compile_options(-Wno-deprecated-declarations) # compile-time option
index 522b4bf..588aff2 100644 (file)
@@ -537,10 +537,18 @@ if (CLR_CMAKE_PLATFORM_UNIX)
 endif(CLR_CMAKE_PLATFORM_UNIX)
 
 if(CLR_CMAKE_PLATFORM_UNIX_ARM)
+   if (NOT DEFINED CLR_ARM_FPU_TYPE)
+     set(CLR_ARM_FPU_TYPE vfpv3)
+   endif(NOT DEFINED CLR_ARM_FPU_TYPE)
+
    # Because we don't use CMAKE_C_COMPILER/CMAKE_CXX_COMPILER to use clang
    # we have to set the triple by adding a compiler argument
    add_compile_options(-mthumb)
-   add_compile_options(-mfpu=vfpv3)
+   add_compile_options(-mfpu=${CLR_ARM_FPU_TYPE})
+   if (NOT DEFINED CLR_ARM_FPU_CAPABILITY)
+     set(CLR_ARM_FPU_CAPABILITY 0x7)
+   endif(NOT DEFINED CLR_ARM_FPU_CAPABILITY)
+   add_definitions(-DCLR_ARM_FPU_CAPABILITY=${CLR_ARM_FPU_CAPABILITY})
    add_compile_options(-march=armv7-a)
    if(ARM_SOFTFP)
      add_definitions(-DARM_SOFTFP)
index 88efc4b..6ea8aba 100644 (file)
@@ -80,7 +80,11 @@ LEAF_ENTRY CONTEXT_CaptureContext, _TEXT
     itttt ne
     addne r0, CONTEXT_D0
     vstmiane r0!, {d0-d15}
+#if CLR_ARM_FPU_CAPABILITY & 0x4
     vstmiane r0!, {d16-d31}
+#else
+    addne r0, r0, #128
+#endif
     subne r0, CONTEXT_D31
 
     // Make sure sp is restored
@@ -130,7 +134,11 @@ LOCAL_LABEL(Restore_CONTEXT_FLOATING_POINT):
     itttt ne
     addne r0, CONTEXT_D0
     vldmiane r0!, {d0-d15}
+#if CLR_ARM_FPU_CAPABILITY & 0x4
     vldmiane r0, {d16-d31}
+#else
+    nopne
+#endif
     subne r0, CONTEXT_D16
 
     itt ne
index 9d4db06..c19f10c 100644 (file)
@@ -59,7 +59,16 @@ elseif (CMAKE_SYSTEM_PROCESSOR STREQUAL armv7l)
     add_compile_options(-mfloat-abi=softfp)
   endif ()
     add_compile_options(-mthumb)
-    add_compile_options(-mfpu=vfpv3)
+  if (NOT DEFINED CLR_ARM_FPU_TYPE)
+    set(CLR_ARM_FPU_TYPE vfpv3)
+  endif(NOT DEFINED CLR_ARM_FPU_TYPE)
+
+    add_compile_options(-mfpu=${CLR_ARM_FPU_TYPE})
+  if (NOT DEFINED CLR_ARM_FPU_CAPABILITY)
+    set(CLR_ARM_FPU_CAPABILITY 0x7)
+  endif(NOT DEFINED CLR_ARM_FPU_CAPABILITY)
+    add_definitions(-DCLR_ARM_FPU_CAPABILITY=${CLR_ARM_FPU_CAPABILITY})
+
     add_compile_options(-march=armv7-a)
 elseif (CMAKE_SYSTEM_PROCESSOR STREQUAL arm)
     add_definitions(-DBIT32=1)