1// Copyright 2015 Google Inc. All rights reserved. 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// http://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15package config 16 17import ( 18 "strings" 19 20 "android/soong/android" 21) 22 23var ( 24 x86Cflags = []string{} 25 26 x86ClangCflags = append(x86Cflags, []string{ 27 "-msse3", 28 29 // -mstackrealign is needed to realign stack in native code 30 // that could be called from JNI, so that movaps instruction 31 // will work on assumed stack aligned local variables. 32 "-mstackrealign", 33 }...) 34 35 x86Cppflags = []string{} 36 37 x86Ldflags = []string{ 38 "-Wl,--hash-style=gnu", 39 } 40 41 x86Lldflags = ClangFilterUnknownLldflags(x86Ldflags) 42 43 x86ArchVariantCflags = map[string][]string{ 44 "": []string{ 45 "-march=prescott", 46 }, 47 "x86_64": []string{ 48 "-march=prescott", 49 }, 50 "atom": []string{ 51 "-march=atom", 52 "-mfpmath=sse", 53 }, 54 "broadwell": []string{ 55 "-march=broadwell", 56 "-mfpmath=sse", 57 }, 58 "haswell": []string{ 59 "-march=core-avx2", 60 "-mfpmath=sse", 61 }, 62 "ivybridge": []string{ 63 "-march=core-avx-i", 64 "-mfpmath=sse", 65 }, 66 "sandybridge": []string{ 67 "-march=corei7", 68 "-mfpmath=sse", 69 }, 70 "silvermont": []string{ 71 "-march=slm", 72 "-mfpmath=sse", 73 }, 74 "skylake": []string{ 75 "-march=skylake", 76 "-mfpmath=sse", 77 }, 78 "stoneyridge": []string{ 79 "-march=bdver4", 80 "-mfpmath=sse", 81 }, 82 } 83 84 x86ArchFeatureCflags = map[string][]string{ 85 "ssse3": []string{"-mssse3"}, 86 "sse4": []string{"-msse4"}, 87 "sse4_1": []string{"-msse4.1"}, 88 "sse4_2": []string{"-msse4.2"}, 89 90 // Not all cases there is performance gain by enabling -mavx -mavx2 91 // flags so these flags are not enabled by default. 92 // if there is performance gain in individual library components, 93 // the compiler flags can be set in corresponding bp files. 94 // "avx": []string{"-mavx"}, 95 // "avx2": []string{"-mavx2"}, 96 // "avx512": []string{"-mavx512"} 97 98 "aes_ni": []string{"-maes"}, 99 } 100) 101 102const ( 103 x86GccVersion = "4.9" 104) 105 106func init() { 107 pctx.StaticVariable("x86GccVersion", x86GccVersion) 108 109 pctx.SourcePathVariable("X86GccRoot", 110 "prebuilts/gcc/${HostPrebuiltTag}/x86/x86_64-linux-android-${x86GccVersion}") 111 112 pctx.StaticVariable("X86ToolchainCflags", "-m32") 113 pctx.StaticVariable("X86ToolchainLdflags", "-m32") 114 115 pctx.StaticVariable("X86Ldflags", strings.Join(x86Ldflags, " ")) 116 pctx.StaticVariable("X86Lldflags", strings.Join(x86Lldflags, " ")) 117 118 // Clang cflags 119 pctx.StaticVariable("X86ClangCflags", strings.Join(ClangFilterUnknownCflags(x86ClangCflags), " ")) 120 pctx.StaticVariable("X86ClangLdflags", strings.Join(ClangFilterUnknownCflags(x86Ldflags), " ")) 121 pctx.StaticVariable("X86ClangLldflags", strings.Join(ClangFilterUnknownCflags(x86Lldflags), " ")) 122 pctx.StaticVariable("X86ClangCppflags", strings.Join(ClangFilterUnknownCflags(x86Cppflags), " ")) 123 124 // Yasm flags 125 pctx.StaticVariable("X86YasmFlags", "-f elf32 -m x86") 126 127 // Extended cflags 128 129 // Architecture variant cflags 130 for variant, cflags := range x86ArchVariantCflags { 131 pctx.StaticVariable("X86"+variant+"VariantClangCflags", 132 strings.Join(ClangFilterUnknownCflags(cflags), " ")) 133 } 134} 135 136type toolchainX86 struct { 137 toolchain32Bit 138 toolchainClangCflags string 139} 140 141func (t *toolchainX86) Name() string { 142 return "x86" 143} 144 145func (t *toolchainX86) GccRoot() string { 146 return "${config.X86GccRoot}" 147} 148 149func (t *toolchainX86) GccTriple() string { 150 return "x86_64-linux-android" 151} 152 153func (t *toolchainX86) GccVersion() string { 154 return x86GccVersion 155} 156 157func (t *toolchainX86) IncludeFlags() string { 158 return "" 159} 160 161func (t *toolchainX86) ClangTriple() string { 162 return "i686-linux-android" 163} 164 165func (t *toolchainX86) ToolchainClangLdflags() string { 166 return "${config.X86ToolchainLdflags}" 167} 168 169func (t *toolchainX86) ToolchainClangCflags() string { 170 return t.toolchainClangCflags 171} 172 173func (t *toolchainX86) ClangCflags() string { 174 return "${config.X86ClangCflags}" 175} 176 177func (t *toolchainX86) ClangCppflags() string { 178 return "${config.X86ClangCppflags}" 179} 180 181func (t *toolchainX86) ClangLdflags() string { 182 return "${config.X86Ldflags}" 183} 184 185func (t *toolchainX86) ClangLldflags() string { 186 return "${config.X86Lldflags}" 187} 188 189func (t *toolchainX86) YasmFlags() string { 190 return "${config.X86YasmFlags}" 191} 192 193func (toolchainX86) LibclangRuntimeLibraryArch() string { 194 return "i686" 195} 196 197func x86ToolchainFactory(arch android.Arch) Toolchain { 198 toolchainClangCflags := []string{ 199 "${config.X86ToolchainCflags}", 200 "${config.X86" + arch.ArchVariant + "VariantClangCflags}", 201 } 202 203 for _, feature := range arch.ArchFeatures { 204 toolchainClangCflags = append(toolchainClangCflags, x86ArchFeatureCflags[feature]...) 205 } 206 207 return &toolchainX86{ 208 toolchainClangCflags: strings.Join(toolchainClangCflags, " "), 209 } 210} 211 212func init() { 213 registerToolchainFactory(android.Android, android.X86, x86ToolchainFactory) 214} 215