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