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 ( |
Liz Kammer | f610a74 | 2022-02-10 16:56:02 -0500 | [diff] [blame] | 18 | "fmt" |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 19 | "strings" |
| 20 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 21 | "android/soong/android" |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 22 | ) |
| 23 | |
| 24 | var ( |
Colin Cross | 33bac24 | 2021-07-14 17:03:16 -0700 | [diff] [blame] | 25 | x86Cflags = []string{ |
Dan Willemsen | 569b0fa | 2016-05-08 20:04:20 -0700 | [diff] [blame] | 26 | "-msse3", |
| 27 | |
| 28 | // -mstackrealign is needed to realign stack in native code |
| 29 | // that could be called from JNI, so that movaps instruction |
| 30 | // will work on assumed stack aligned local variables. |
| 31 | "-mstackrealign", |
Colin Cross | 33bac24 | 2021-07-14 17:03:16 -0700 | [diff] [blame] | 32 | } |
Dan Willemsen | 569b0fa | 2016-05-08 20:04:20 -0700 | [diff] [blame] | 33 | |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 34 | x86Cppflags = []string{} |
| 35 | |
| 36 | x86Ldflags = []string{ |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 37 | "-Wl,--hash-style=gnu", |
| 38 | } |
| 39 | |
| 40 | x86ArchVariantCflags = map[string][]string{ |
| 41 | "": []string{ |
| 42 | "-march=prescott", |
| 43 | }, |
Dan Willemsen | 8a35405 | 2016-05-10 14:30:51 -0700 | [diff] [blame] | 44 | "x86_64": []string{ |
| 45 | "-march=prescott", |
| 46 | }, |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 47 | "atom": []string{ |
| 48 | "-march=atom", |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 49 | }, |
Shalini Salomi Bodapati | 4a0459d | 2019-01-22 10:00:15 +0530 | [diff] [blame] | 50 | "broadwell": []string{ |
| 51 | "-march=broadwell", |
Shalini Salomi Bodapati | 4a0459d | 2019-01-22 10:00:15 +0530 | [diff] [blame] | 52 | }, |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 53 | "haswell": []string{ |
| 54 | "-march=core-avx2", |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 55 | }, |
| 56 | "ivybridge": []string{ |
| 57 | "-march=core-avx-i", |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 58 | }, |
| 59 | "sandybridge": []string{ |
Dan Willemsen | b77bd79 | 2016-02-29 15:26:26 -0800 | [diff] [blame] | 60 | "-march=corei7", |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 61 | }, |
| 62 | "silvermont": []string{ |
| 63 | "-march=slm", |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 64 | }, |
Shalini Salomi Bodapati | 4a0459d | 2019-01-22 10:00:15 +0530 | [diff] [blame] | 65 | "skylake": []string{ |
| 66 | "-march=skylake", |
Shalini Salomi Bodapati | 4a0459d | 2019-01-22 10:00:15 +0530 | [diff] [blame] | 67 | }, |
Benjamin Gordon | 87e7f2f | 2019-02-14 10:59:48 -0700 | [diff] [blame] | 68 | "stoneyridge": []string{ |
| 69 | "-march=bdver4", |
Benjamin Gordon | 87e7f2f | 2019-02-14 10:59:48 -0700 | [diff] [blame] | 70 | }, |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | x86ArchFeatureCflags = map[string][]string{ |
Elliott Hughes | b22dcfe | 2019-07-12 22:40:45 -0700 | [diff] [blame] | 74 | "ssse3": []string{"-mssse3"}, |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 75 | "sse4": []string{"-msse4"}, |
| 76 | "sse4_1": []string{"-msse4.1"}, |
| 77 | "sse4_2": []string{"-msse4.2"}, |
jaishank | 7e84969 | 2019-06-25 14:55:52 +0530 | [diff] [blame] | 78 | |
| 79 | // Not all cases there is performance gain by enabling -mavx -mavx2 |
| 80 | // flags so these flags are not enabled by default. |
| 81 | // if there is performance gain in individual library components, |
| 82 | // the compiler flags can be set in corresponding bp files. |
| 83 | // "avx": []string{"-mavx"}, |
| 84 | // "avx2": []string{"-mavx2"}, |
| 85 | // "avx512": []string{"-mavx512"} |
| 86 | |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 87 | "aes_ni": []string{"-maes"}, |
| 88 | } |
| 89 | ) |
| 90 | |
Dan Willemsen | 34fc3b1 | 2015-12-07 12:30:44 -0800 | [diff] [blame] | 91 | const ( |
| 92 | x86GccVersion = "4.9" |
| 93 | ) |
| 94 | |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 95 | func init() { |
Dan Willemsen | 34fc3b1 | 2015-12-07 12:30:44 -0800 | [diff] [blame] | 96 | pctx.StaticVariable("x86GccVersion", x86GccVersion) |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 97 | |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 98 | pctx.SourcePathVariable("X86GccRoot", |
Dan Willemsen | 34fc3b1 | 2015-12-07 12:30:44 -0800 | [diff] [blame] | 99 | "prebuilts/gcc/${HostPrebuiltTag}/x86/x86_64-linux-android-${x86GccVersion}") |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 100 | |
Sam Delmerico | 7f88956 | 2022-03-25 14:55:40 +0000 | [diff] [blame^] | 101 | exportedVars.ExportStringListStaticVariable("X86ToolchainCflags", []string{"-m32"}) |
| 102 | exportedVars.ExportStringListStaticVariable("X86ToolchainLdflags", []string{"-m32"}) |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 103 | |
Sam Delmerico | 7f88956 | 2022-03-25 14:55:40 +0000 | [diff] [blame^] | 104 | exportedVars.ExportStringListStaticVariable("X86Ldflags", x86Ldflags) |
| 105 | exportedVars.ExportStringListStaticVariable("X86Lldflags", x86Ldflags) |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 106 | |
| 107 | // Clang cflags |
Sam Delmerico | 7f88956 | 2022-03-25 14:55:40 +0000 | [diff] [blame^] | 108 | exportedVars.ExportStringListStaticVariable("X86Cflags", x86Cflags) |
| 109 | exportedVars.ExportStringListStaticVariable("X86Cppflags", x86Cppflags) |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 110 | |
Colin Cross | 91e9004 | 2016-12-02 17:13:24 -0800 | [diff] [blame] | 111 | // Yasm flags |
Sam Delmerico | 7f88956 | 2022-03-25 14:55:40 +0000 | [diff] [blame^] | 112 | exportedVars.ExportStringListStaticVariable("X86YasmFlags", []string{ |
Liz Kammer | 82ad8cc | 2021-08-02 10:41:48 -0400 | [diff] [blame] | 113 | "-f elf32", |
| 114 | "-m x86", |
| 115 | }) |
Colin Cross | 91e9004 | 2016-12-02 17:13:24 -0800 | [diff] [blame] | 116 | |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 117 | // Extended cflags |
Sam Delmerico | 7f88956 | 2022-03-25 14:55:40 +0000 | [diff] [blame^] | 118 | exportedVars.ExportStringListDict("X86ArchVariantCflags", x86ArchVariantCflags) |
| 119 | exportedVars.ExportStringListDict("X86ArchFeatureCflags", x86ArchFeatureCflags) |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 120 | |
| 121 | // Architecture variant cflags |
| 122 | for variant, cflags := range x86ArchVariantCflags { |
Liz Kammer | 82ad8cc | 2021-08-02 10:41:48 -0400 | [diff] [blame] | 123 | pctx.StaticVariable("X86"+variant+"VariantCflags", strings.Join(cflags, " ")) |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 124 | } |
| 125 | } |
| 126 | |
| 127 | type toolchainX86 struct { |
Colin Cross | e3fee34 | 2021-06-21 17:28:25 -0700 | [diff] [blame] | 128 | toolchainBionic |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 129 | toolchain32Bit |
Colin Cross | 33bac24 | 2021-07-14 17:03:16 -0700 | [diff] [blame] | 130 | toolchainCflags string |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | func (t *toolchainX86) Name() string { |
| 134 | return "x86" |
| 135 | } |
| 136 | |
| 137 | func (t *toolchainX86) GccRoot() string { |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 138 | return "${config.X86GccRoot}" |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | func (t *toolchainX86) GccTriple() string { |
Dan Albert | 84f431f | 2016-07-20 14:44:26 -0700 | [diff] [blame] | 142 | return "x86_64-linux-android" |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | func (t *toolchainX86) GccVersion() string { |
Dan Willemsen | 34fc3b1 | 2015-12-07 12:30:44 -0800 | [diff] [blame] | 146 | return x86GccVersion |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 147 | } |
| 148 | |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 149 | func (t *toolchainX86) IncludeFlags() string { |
Martin Stjernholm | 41ab251 | 2020-04-08 01:06:07 +0100 | [diff] [blame] | 150 | return "" |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | func (t *toolchainX86) ClangTriple() string { |
Dan Willemsen | 569b0fa | 2016-05-08 20:04:20 -0700 | [diff] [blame] | 154 | return "i686-linux-android" |
| 155 | } |
| 156 | |
Colin Cross | 33bac24 | 2021-07-14 17:03:16 -0700 | [diff] [blame] | 157 | func (t *toolchainX86) ToolchainLdflags() string { |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 158 | return "${config.X86ToolchainLdflags}" |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 159 | } |
| 160 | |
Colin Cross | 33bac24 | 2021-07-14 17:03:16 -0700 | [diff] [blame] | 161 | func (t *toolchainX86) ToolchainCflags() string { |
| 162 | return t.toolchainCflags |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 163 | } |
| 164 | |
Colin Cross | 33bac24 | 2021-07-14 17:03:16 -0700 | [diff] [blame] | 165 | func (t *toolchainX86) Cflags() string { |
Colin Cross | 0523ba2 | 2021-07-14 18:45:05 -0700 | [diff] [blame] | 166 | return "${config.X86Cflags}" |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 167 | } |
| 168 | |
Colin Cross | 33bac24 | 2021-07-14 17:03:16 -0700 | [diff] [blame] | 169 | func (t *toolchainX86) Cppflags() string { |
Colin Cross | 0523ba2 | 2021-07-14 18:45:05 -0700 | [diff] [blame] | 170 | return "${config.X86Cppflags}" |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 171 | } |
| 172 | |
Colin Cross | 33bac24 | 2021-07-14 17:03:16 -0700 | [diff] [blame] | 173 | func (t *toolchainX86) Ldflags() string { |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 174 | return "${config.X86Ldflags}" |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 175 | } |
| 176 | |
Colin Cross | 33bac24 | 2021-07-14 17:03:16 -0700 | [diff] [blame] | 177 | func (t *toolchainX86) Lldflags() string { |
Chih-Hung Hsieh | 02b4da5 | 2018-04-03 11:33:34 -0700 | [diff] [blame] | 178 | return "${config.X86Lldflags}" |
| 179 | } |
| 180 | |
Colin Cross | 91e9004 | 2016-12-02 17:13:24 -0800 | [diff] [blame] | 181 | func (t *toolchainX86) YasmFlags() string { |
| 182 | return "${config.X86YasmFlags}" |
| 183 | } |
| 184 | |
Yi Kong | 924adc4 | 2018-08-31 14:27:44 -0700 | [diff] [blame] | 185 | func (toolchainX86) LibclangRuntimeLibraryArch() string { |
Evgenii Stepanov | af36db1 | 2016-08-15 14:18:24 -0700 | [diff] [blame] | 186 | return "i686" |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 187 | } |
| 188 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 189 | func x86ToolchainFactory(arch android.Arch) Toolchain { |
Liz Kammer | f610a74 | 2022-02-10 16:56:02 -0500 | [diff] [blame] | 190 | // Error now rather than having a confusing Ninja error |
| 191 | if _, ok := x86ArchVariantCflags[arch.ArchVariant]; !ok { |
| 192 | panic(fmt.Sprintf("Unknown x86 architecture version: %q", arch.ArchVariant)) |
| 193 | } |
| 194 | |
Colin Cross | 33bac24 | 2021-07-14 17:03:16 -0700 | [diff] [blame] | 195 | toolchainCflags := []string{ |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 196 | "${config.X86ToolchainCflags}", |
Colin Cross | 0523ba2 | 2021-07-14 18:45:05 -0700 | [diff] [blame] | 197 | "${config.X86" + arch.ArchVariant + "VariantCflags}", |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | for _, feature := range arch.ArchFeatures { |
Colin Cross | 33bac24 | 2021-07-14 17:03:16 -0700 | [diff] [blame] | 201 | toolchainCflags = append(toolchainCflags, x86ArchFeatureCflags[feature]...) |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | return &toolchainX86{ |
Colin Cross | 33bac24 | 2021-07-14 17:03:16 -0700 | [diff] [blame] | 205 | toolchainCflags: strings.Join(toolchainCflags, " "), |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 206 | } |
| 207 | } |
| 208 | |
| 209 | func init() { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 210 | registerToolchainFactory(android.Android, android.X86, x86ToolchainFactory) |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 211 | } |