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{ |
| 85 | "ssse3": []string{"-DUSE_SSSE3", "-mssse3"}, |
| 86 | "sse4": []string{"-msse4"}, |
| 87 | "sse4_1": []string{"-msse4.1"}, |
| 88 | "sse4_2": []string{"-msse4.2"}, |
| 89 | "avx": []string{"-mavx"}, |
Benjamin Gordon | 87e7f2f | 2019-02-14 10:59:48 -0700 | [diff] [blame^] | 90 | "avx2": []string{"-mavx2"}, |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 91 | "aes_ni": []string{"-maes"}, |
| 92 | } |
| 93 | ) |
| 94 | |
Dan Willemsen | 34fc3b1 | 2015-12-07 12:30:44 -0800 | [diff] [blame] | 95 | const ( |
| 96 | x86GccVersion = "4.9" |
| 97 | ) |
| 98 | |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 99 | func init() { |
Dan Willemsen | 34fc3b1 | 2015-12-07 12:30:44 -0800 | [diff] [blame] | 100 | pctx.StaticVariable("x86GccVersion", x86GccVersion) |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 101 | |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 102 | pctx.SourcePathVariable("X86GccRoot", |
Dan Willemsen | 34fc3b1 | 2015-12-07 12:30:44 -0800 | [diff] [blame] | 103 | "prebuilts/gcc/${HostPrebuiltTag}/x86/x86_64-linux-android-${x86GccVersion}") |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 104 | |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 105 | pctx.StaticVariable("X86ToolchainCflags", "-m32") |
| 106 | pctx.StaticVariable("X86ToolchainLdflags", "-m32") |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 107 | |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 108 | pctx.StaticVariable("X86Ldflags", strings.Join(x86Ldflags, " ")) |
Chih-Hung Hsieh | 02b4da5 | 2018-04-03 11:33:34 -0700 | [diff] [blame] | 109 | pctx.StaticVariable("X86Lldflags", strings.Join(x86Lldflags, " ")) |
Elliott Hughes | de28deb | 2017-10-12 09:07:53 -0700 | [diff] [blame] | 110 | pctx.StaticVariable("X86IncludeFlags", bionicHeaders("x86")) |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 111 | |
| 112 | // Clang cflags |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 113 | pctx.StaticVariable("X86ClangCflags", strings.Join(ClangFilterUnknownCflags(x86ClangCflags), " ")) |
| 114 | pctx.StaticVariable("X86ClangLdflags", strings.Join(ClangFilterUnknownCflags(x86Ldflags), " ")) |
Chih-Hung Hsieh | 02b4da5 | 2018-04-03 11:33:34 -0700 | [diff] [blame] | 115 | pctx.StaticVariable("X86ClangLldflags", strings.Join(ClangFilterUnknownCflags(x86Lldflags), " ")) |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 116 | pctx.StaticVariable("X86ClangCppflags", strings.Join(ClangFilterUnknownCflags(x86Cppflags), " ")) |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 117 | |
Colin Cross | 91e9004 | 2016-12-02 17:13:24 -0800 | [diff] [blame] | 118 | // Yasm flags |
| 119 | pctx.StaticVariable("X86YasmFlags", "-f elf32 -m x86") |
| 120 | |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 121 | // Extended cflags |
| 122 | |
| 123 | // Architecture variant cflags |
| 124 | for variant, cflags := range x86ArchVariantCflags { |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 125 | pctx.StaticVariable("X86"+variant+"VariantClangCflags", |
| 126 | strings.Join(ClangFilterUnknownCflags(cflags), " ")) |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 127 | } |
| 128 | } |
| 129 | |
| 130 | type toolchainX86 struct { |
| 131 | toolchain32Bit |
Dan Willemsen | bd4abf5 | 2018-10-07 21:06:36 -0700 | [diff] [blame] | 132 | toolchainClangCflags string |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | func (t *toolchainX86) Name() string { |
| 136 | return "x86" |
| 137 | } |
| 138 | |
| 139 | func (t *toolchainX86) GccRoot() string { |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 140 | return "${config.X86GccRoot}" |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | func (t *toolchainX86) GccTriple() string { |
Dan Albert | 84f431f | 2016-07-20 14:44:26 -0700 | [diff] [blame] | 144 | return "x86_64-linux-android" |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | func (t *toolchainX86) GccVersion() string { |
Dan Willemsen | 34fc3b1 | 2015-12-07 12:30:44 -0800 | [diff] [blame] | 148 | return x86GccVersion |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 149 | } |
| 150 | |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 151 | func (t *toolchainX86) IncludeFlags() string { |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 152 | return "${config.X86IncludeFlags}" |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | func (t *toolchainX86) ClangTriple() string { |
Dan Willemsen | 569b0fa | 2016-05-08 20:04:20 -0700 | [diff] [blame] | 156 | return "i686-linux-android" |
| 157 | } |
| 158 | |
| 159 | func (t *toolchainX86) ToolchainClangLdflags() string { |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 160 | return "${config.X86ToolchainLdflags}" |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | func (t *toolchainX86) ToolchainClangCflags() string { |
| 164 | return t.toolchainClangCflags |
| 165 | } |
| 166 | |
| 167 | func (t *toolchainX86) ClangCflags() string { |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 168 | return "${config.X86ClangCflags}" |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | func (t *toolchainX86) ClangCppflags() string { |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 172 | return "${config.X86ClangCppflags}" |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | func (t *toolchainX86) ClangLdflags() string { |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 176 | return "${config.X86Ldflags}" |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 177 | } |
| 178 | |
Chih-Hung Hsieh | 02b4da5 | 2018-04-03 11:33:34 -0700 | [diff] [blame] | 179 | func (t *toolchainX86) ClangLldflags() string { |
| 180 | return "${config.X86Lldflags}" |
| 181 | } |
| 182 | |
Colin Cross | 91e9004 | 2016-12-02 17:13:24 -0800 | [diff] [blame] | 183 | func (t *toolchainX86) YasmFlags() string { |
| 184 | return "${config.X86YasmFlags}" |
| 185 | } |
| 186 | |
Yi Kong | 924adc4 | 2018-08-31 14:27:44 -0700 | [diff] [blame] | 187 | func (toolchainX86) LibclangRuntimeLibraryArch() string { |
Evgenii Stepanov | af36db1 | 2016-08-15 14:18:24 -0700 | [diff] [blame] | 188 | return "i686" |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 189 | } |
| 190 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 191 | func x86ToolchainFactory(arch android.Arch) Toolchain { |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 192 | toolchainClangCflags := []string{ |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 193 | "${config.X86ToolchainCflags}", |
| 194 | "${config.X86" + arch.ArchVariant + "VariantClangCflags}", |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | for _, feature := range arch.ArchFeatures { |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 198 | toolchainClangCflags = append(toolchainClangCflags, x86ArchFeatureCflags[feature]...) |
| 199 | } |
| 200 | |
| 201 | return &toolchainX86{ |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 202 | toolchainClangCflags: strings.Join(toolchainClangCflags, " "), |
| 203 | } |
| 204 | } |
| 205 | |
| 206 | func init() { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 207 | registerToolchainFactory(android.Android, android.X86, x86ToolchainFactory) |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 208 | } |