Commits

Manu Evans committed e7ac32d Draft

Improved Android floating point support, added 'floatabi' setting.

Comments (0)

Files changed (3)

src/actions/vstudio/vs2010_vcxproj.lua

 			_p(3,'<EnableEnhancedInstructionSet>StreamingSIMDExtensions</EnableEnhancedInstructionSet>')
 		end
 
+		if cfg.toolset == "vsandroid" then
+			vstudio.vsandroid.additionalOptions(cfg)
+		end
 		if #cfg.buildoptions > 0 then
 			local options = table.concat(cfg.buildoptions, " ")
 			_x(3,'<AdditionalOptions>%s %%(AdditionalOptions)</AdditionalOptions>', options)

src/actions/vstudio/vsandroid.lua

 
 			-- TODO-ANDROID: we need a way to select the GCC toolchain version...
 
-			if cfg.architecture == "armv7" then
+			if cfg.architecture == "armv7" or cfg.architecture == "armv6" then
 				_p(2,'<PlatformToolset>arm-linux-androideabi-4.6</PlatformToolset>')
 				_p(2,'<AndroidArch>armv7-a</AndroidArch>')
 			elseif cfg.architecture == "armv5" then
 		if cfg.flags.SoftwareFloat then
 			_p(3,'<SoftFloat>true</SoftFloat>')
 		end
-		if cfg.flags.HardwareFloat then
-			_p(3,'<SoftFloat>false</SoftFloat>')
-		end
 
 		if cfg.flags.EnableThumb then
 			_p(3,'<ThumbMode>true</ThumbMode>')
 		end
 
 		-- TODO: NEON, hardware float settings, endian selection
-		-- VS-Android does not support these settings yet...
+		-- VS-Android does not support these settings yet... we'll add them manually to <AdvancedOptions> below.
 
 	end
 
 
 --
+-- Add options unsupported by VS-Android UI to <AdvancedOptions>.
+--
+	function vsandroid.additionalOptions(cfg)
+
+		local function alreadyHas(t, key)
+			for _, k in ipairs(t) do
+				if string.find(k, key) then
+					return true
+				end
+			end
+			return false
+		end
+
+
+		-- Flags that are not supported by the VS-Android UI may be added manually here...
+
+		-- we might want to define the arch to generate better code
+		if not alreadyHas(cfg.buildoptions, "-march=") then
+			if cfg.architecture == "armv6" then
+				table.insert(cfg.buildoptions, "-march=armv6")
+			elseif cfg.architecture == "armv7" then
+				table.insert(cfg.buildoptions, "-march=armv7")
+			end
+		end
+
+		-- Android has a comprehensive set of floating point options
+		if not cfg.flags.SoftwareFloat and cfg.floatabi ~= "soft" then
+
+			if cfg.architecture == "armv7" then
+
+				-- armv7 always has VFP, may not have NEON
+
+				if not alreadyHas(cfg.buildoptions, "-mfpu=") then
+					if cfg.flags.EnableNEON then
+						table.insert(cfg.buildoptions, "-mfpu=neon")
+					elseif cfg.flags.HardwareFloat or cfg.floatabi == "softfp" or cfg.floatabi == "hard" then
+						table.insert(cfg.buildoptions, "-mfpu=vfpv3-d16") -- d16 is the lowest common denominator
+					end
+				end
+
+				if not alreadyHas(cfg.buildoptions, "-mfloat-abi=") then
+					if cfg.floatabi == "hard" then
+						table.insert(cfg.buildoptions, "-mfloat-abi=hard")
+					else
+						-- Android should probably use softfp by default for compatibility
+						table.insert(cfg.buildoptions, "-mfloat-abi=softfp")
+					end
+				end
+
+			else
+
+				-- armv5/6 may not have VFP
+
+				if not alreadyHas(cfg.buildoptions, "-mfpu=") then
+					if cfg.flags.HardwareFloat or cfg.floatabi == "softfp" or cfg.floatabi == "hard" then
+						table.insert(cfg.buildoptions, "-mfpu=vfp")
+					end
+				end
+
+				if not alreadyHas(cfg.buildoptions, "-mfloat-abi=") then
+					if cfg.floatabi == "softfp" then
+						table.insert(cfg.buildoptions, "-mfloat-abi=softfp")
+					elseif cfg.floatabi == "hard" then
+						table.insert(cfg.buildoptions, "-mfloat-abi=hard")
+					end
+				end
+
+			end
+
+		elseif cfg.floatabi == "soft" then
+
+			table.insert(cfg.buildoptions, "-mfloat-abi=soft")
+
+		end
+
+		if cfg.flags.LittleEndian then
+			table.insert(cfg.buildoptions, "-mlittle-endian")
+		elseif cfg.flags.BigEndian then
+			table.insert(cfg.buildoptions, "-mbig-endian")
+		end
+
+	end
+
+
+--
 -- Write the VS-Android <AntBuild> settings.
 --
 
 			"x32",
 			"x64",
 			"armv5",
+			"armv6",
 			"armv7",
 			"mips",
 		},
 	}
 
 	api.register {
+		name = "floatabi",
+		scope = "config",
+		kind = "string",
+		allowed = {
+			"soft",
+			"softfp",
+			"hard",
+		},
+	}
+
+	api.register {
 		name = "flags",
 		scope = "config",
 		kind  = "string-list",
 			"DisableStrictAliasing",
 			"EnableThumb",
 			"EnableNEON",
+			"SoftwareFloat",
 			"HardwareFloat",
-			"SoftwareFloat",
-			"SoftFloatFP", -- I don't like this term.. better flag name? (hardware float with soft ABI)
 			"LittleEndian",
 			"BigEndian",
 		},