Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 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 | |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 15 | package config |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 16 | |
| 17 | import ( |
| 18 | "strings" |
| 19 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 20 | "android/soong/android" |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 21 | ) |
| 22 | |
| 23 | var ( |
Colin Cross | b37620f | 2017-11-06 14:05:51 -0800 | [diff] [blame] | 24 | x86Cflags = []string{} |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 25 | |
Dan Willemsen | 569b0fa | 2016-05-08 20:04:20 -0700 | [diff] [blame] | 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 | |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 35 | x86Cppflags = []string{} |
| 36 | |
| 37 | x86Ldflags = []string{ |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 38 | "-Wl,--hash-style=gnu", |
| 39 | } |
| 40 | |
Chih-Hung Hsieh | 02b4da5 | 2018-04-03 11:33:34 -0700 | [diff] [blame] | 41 | x86Lldflags = ClangFilterUnknownLldflags(x86Ldflags) |
| 42 | |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 43 | x86ArchVariantCflags = map[string][]string{ |
| 44 | "": []string{ |
| 45 | "-march=prescott", |
| 46 | }, |
Dan Willemsen | 8a35405 | 2016-05-10 14:30:51 -0700 | [diff] [blame] | 47 | "x86_64": []string{ |
| 48 | "-march=prescott", |
| 49 | }, |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 50 | "atom": []string{ |
| 51 | "-march=atom", |
| 52 | "-mfpmath=sse", |
| 53 | }, |
Shalini Salomi Bodapati | 4a0459d | 2019-01-22 10:00:15 +0530 | [diff] [blame] | 54 | "broadwell": []string{ |
| 55 | "-march=broadwell", |
| 56 | "-mfpmath=sse", |
| 57 | }, |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 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{ |
Dan Willemsen | b77bd79 | 2016-02-29 15:26:26 -0800 | [diff] [blame] | 67 | "-march=corei7", |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 68 | "-mfpmath=sse", |
| 69 | }, |
| 70 | "silvermont": []string{ |
| 71 | "-march=slm", |
| 72 | "-mfpmath=sse", |
| 73 | }, |
Shalini Salomi Bodapati | 4a0459d | 2019-01-22 10:00:15 +0530 | [diff] [blame] | 74 | "skylake": []string{ |
| 75 | "-march=skylake", |
| 76 | "-mfpmath=sse", |
| 77 | }, |
Benjamin Gordon | 87e7f2f | 2019-02-14 10:59:48 -0700 | [diff] [blame] | 78 | "stoneyridge": []string{ |
| 79 | "-march=bdver4", |
| 80 | "-mfpmath=sse", |
| 81 | }, |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | x86ArchFeatureCflags = map[string][]string{ |
Elliott Hughes | b22dcfe | 2019-07-12 22:40:45 -0700 | [diff] [blame] | 85 | "ssse3": []string{"-mssse3"}, |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 86 | "sse4": []string{"-msse4"}, |
| 87 | "sse4_1": []string{"-msse4.1"}, |
| 88 | "sse4_2": []string{"-msse4.2"}, |
jaishank | 7e84969 | 2019-06-25 14:55:52 +0530 | [diff] [blame] | 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 | |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 98 | "aes_ni": []string{"-maes"}, |
| 99 | } |
| 100 | ) |
| 101 | |
Dan Willemsen | 34fc3b1 | 2015-12-07 12:30:44 -0800 | [diff] [blame] | 102 | const ( |
| 103 | x86GccVersion = "4.9" |
| 104 | ) |
| 105 | |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 106 | func init() { |
Dan Willemsen | 34fc3b1 | 2015-12-07 12:30:44 -0800 | [diff] [blame] | 107 | pctx.StaticVariable("x86GccVersion", x86GccVersion) |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 108 | |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 109 | pctx.SourcePathVariable("X86GccRoot", |
Dan Willemsen | 34fc3b1 | 2015-12-07 12:30:44 -0800 | [diff] [blame] | 110 | "prebuilts/gcc/${HostPrebuiltTag}/x86/x86_64-linux-android-${x86GccVersion}") |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 111 | |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 112 | pctx.StaticVariable("X86ToolchainCflags", "-m32") |
| 113 | pctx.StaticVariable("X86ToolchainLdflags", "-m32") |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 114 | |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 115 | pctx.StaticVariable("X86Ldflags", strings.Join(x86Ldflags, " ")) |
Chih-Hung Hsieh | 02b4da5 | 2018-04-03 11:33:34 -0700 | [diff] [blame] | 116 | pctx.StaticVariable("X86Lldflags", strings.Join(x86Lldflags, " ")) |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 117 | |
| 118 | // Clang cflags |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 119 | pctx.StaticVariable("X86ClangCflags", strings.Join(ClangFilterUnknownCflags(x86ClangCflags), " ")) |
| 120 | pctx.StaticVariable("X86ClangLdflags", strings.Join(ClangFilterUnknownCflags(x86Ldflags), " ")) |
Chih-Hung Hsieh | 02b4da5 | 2018-04-03 11:33:34 -0700 | [diff] [blame] | 121 | pctx.StaticVariable("X86ClangLldflags", strings.Join(ClangFilterUnknownCflags(x86Lldflags), " ")) |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 122 | pctx.StaticVariable("X86ClangCppflags", strings.Join(ClangFilterUnknownCflags(x86Cppflags), " ")) |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 123 | |
Colin Cross | 91e9004 | 2016-12-02 17:13:24 -0800 | [diff] [blame] | 124 | // Yasm flags |
| 125 | pctx.StaticVariable("X86YasmFlags", "-f elf32 -m x86") |
| 126 | |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 127 | // Extended cflags |
| 128 | |
| 129 | // Architecture variant cflags |
| 130 | for variant, cflags := range x86ArchVariantCflags { |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 131 | pctx.StaticVariable("X86"+variant+"VariantClangCflags", |
| 132 | strings.Join(ClangFilterUnknownCflags(cflags), " ")) |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 133 | } |
| 134 | } |
| 135 | |
| 136 | type toolchainX86 struct { |
| 137 | toolchain32Bit |
Dan Willemsen | bd4abf5 | 2018-10-07 21:06:36 -0700 | [diff] [blame] | 138 | toolchainClangCflags string |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | func (t *toolchainX86) Name() string { |
| 142 | return "x86" |
| 143 | } |
| 144 | |
| 145 | func (t *toolchainX86) GccRoot() string { |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 146 | return "${config.X86GccRoot}" |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | func (t *toolchainX86) GccTriple() string { |
Dan Albert | 84f431f | 2016-07-20 14:44:26 -0700 | [diff] [blame] | 150 | return "x86_64-linux-android" |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | func (t *toolchainX86) GccVersion() string { |
Dan Willemsen | 34fc3b1 | 2015-12-07 12:30:44 -0800 | [diff] [blame] | 154 | return x86GccVersion |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 155 | } |
| 156 | |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 157 | func (t *toolchainX86) IncludeFlags() string { |
Martin Stjernholm | 41ab251 | 2020-04-08 01:06:07 +0100 | [diff] [blame^] | 158 | return "" |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | func (t *toolchainX86) ClangTriple() string { |
Dan Willemsen | 569b0fa | 2016-05-08 20:04:20 -0700 | [diff] [blame] | 162 | return "i686-linux-android" |
| 163 | } |
| 164 | |
| 165 | func (t *toolchainX86) ToolchainClangLdflags() string { |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 166 | return "${config.X86ToolchainLdflags}" |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | func (t *toolchainX86) ToolchainClangCflags() string { |
| 170 | return t.toolchainClangCflags |
| 171 | } |
| 172 | |
| 173 | func (t *toolchainX86) ClangCflags() string { |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 174 | return "${config.X86ClangCflags}" |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | func (t *toolchainX86) ClangCppflags() string { |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 178 | return "${config.X86ClangCppflags}" |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | func (t *toolchainX86) ClangLdflags() string { |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 182 | return "${config.X86Ldflags}" |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 183 | } |
| 184 | |
Chih-Hung Hsieh | 02b4da5 | 2018-04-03 11:33:34 -0700 | [diff] [blame] | 185 | func (t *toolchainX86) ClangLldflags() string { |
| 186 | return "${config.X86Lldflags}" |
| 187 | } |
| 188 | |
Colin Cross | 91e9004 | 2016-12-02 17:13:24 -0800 | [diff] [blame] | 189 | func (t *toolchainX86) YasmFlags() string { |
| 190 | return "${config.X86YasmFlags}" |
| 191 | } |
| 192 | |
Yi Kong | 924adc4 | 2018-08-31 14:27:44 -0700 | [diff] [blame] | 193 | func (toolchainX86) LibclangRuntimeLibraryArch() string { |
Evgenii Stepanov | af36db1 | 2016-08-15 14:18:24 -0700 | [diff] [blame] | 194 | return "i686" |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 195 | } |
| 196 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 197 | func x86ToolchainFactory(arch android.Arch) Toolchain { |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 198 | toolchainClangCflags := []string{ |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 199 | "${config.X86ToolchainCflags}", |
| 200 | "${config.X86" + arch.ArchVariant + "VariantClangCflags}", |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | for _, feature := range arch.ArchFeatures { |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 204 | toolchainClangCflags = append(toolchainClangCflags, x86ArchFeatureCflags[feature]...) |
| 205 | } |
| 206 | |
| 207 | return &toolchainX86{ |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 208 | toolchainClangCflags: strings.Join(toolchainClangCflags, " "), |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | func init() { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 213 | registerToolchainFactory(android.Android, android.X86, x86ToolchainFactory) |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 214 | } |