blob: 29f05930358a1c4298204971c0f85ce95121452c [file] [log] [blame]
Colin Crossb0cba6a2015-11-20 15:35:26 -08001// 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 Crossb98c8b02016-07-29 13:44:28 -070015package config
Colin Crossb0cba6a2015-11-20 15:35:26 -080016
17import (
18 "strings"
19
Colin Cross635c3b02016-05-18 15:37:25 -070020 "android/soong/android"
Colin Crossb0cba6a2015-11-20 15:35:26 -080021)
22
23var (
Colin Cross33bac242021-07-14 17:03:16 -070024 x86Cflags = []string{
Dan Willemsen569b0fa2016-05-08 20:04:20 -070025 "-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 Cross33bac242021-07-14 17:03:16 -070031 }
Dan Willemsen569b0fa2016-05-08 20:04:20 -070032
Colin Crossb0cba6a2015-11-20 15:35:26 -080033 x86Cppflags = []string{}
34
35 x86Ldflags = []string{
Colin Crossb0cba6a2015-11-20 15:35:26 -080036 "-Wl,--hash-style=gnu",
37 }
38
39 x86ArchVariantCflags = map[string][]string{
40 "": []string{
41 "-march=prescott",
42 },
Dan Willemsen8a354052016-05-10 14:30:51 -070043 "x86_64": []string{
44 "-march=prescott",
45 },
Colin Crossb0cba6a2015-11-20 15:35:26 -080046 "atom": []string{
47 "-march=atom",
Colin Crossb0cba6a2015-11-20 15:35:26 -080048 },
Shalini Salomi Bodapati4a0459d2019-01-22 10:00:15 +053049 "broadwell": []string{
50 "-march=broadwell",
Shalini Salomi Bodapati4a0459d2019-01-22 10:00:15 +053051 },
Colin Crossb0cba6a2015-11-20 15:35:26 -080052 "haswell": []string{
53 "-march=core-avx2",
Colin Crossb0cba6a2015-11-20 15:35:26 -080054 },
55 "ivybridge": []string{
56 "-march=core-avx-i",
Colin Crossb0cba6a2015-11-20 15:35:26 -080057 },
58 "sandybridge": []string{
Dan Willemsenb77bd792016-02-29 15:26:26 -080059 "-march=corei7",
Colin Crossb0cba6a2015-11-20 15:35:26 -080060 },
61 "silvermont": []string{
62 "-march=slm",
Colin Crossb0cba6a2015-11-20 15:35:26 -080063 },
Shalini Salomi Bodapati4a0459d2019-01-22 10:00:15 +053064 "skylake": []string{
65 "-march=skylake",
Shalini Salomi Bodapati4a0459d2019-01-22 10:00:15 +053066 },
Benjamin Gordon87e7f2f2019-02-14 10:59:48 -070067 "stoneyridge": []string{
68 "-march=bdver4",
Benjamin Gordon87e7f2f2019-02-14 10:59:48 -070069 },
Colin Crossb0cba6a2015-11-20 15:35:26 -080070 }
71
72 x86ArchFeatureCflags = map[string][]string{
Elliott Hughesb22dcfe2019-07-12 22:40:45 -070073 "ssse3": []string{"-mssse3"},
Colin Crossb0cba6a2015-11-20 15:35:26 -080074 "sse4": []string{"-msse4"},
75 "sse4_1": []string{"-msse4.1"},
76 "sse4_2": []string{"-msse4.2"},
jaishank7e849692019-06-25 14:55:52 +053077
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 Crossb0cba6a2015-11-20 15:35:26 -080086 "aes_ni": []string{"-maes"},
87 }
88)
89
Dan Willemsen34fc3b12015-12-07 12:30:44 -080090const (
91 x86GccVersion = "4.9"
92)
93
Colin Crossb0cba6a2015-11-20 15:35:26 -080094func init() {
Dan Willemsen34fc3b12015-12-07 12:30:44 -080095 pctx.StaticVariable("x86GccVersion", x86GccVersion)
Colin Crossb0cba6a2015-11-20 15:35:26 -080096
Colin Crossb98c8b02016-07-29 13:44:28 -070097 pctx.SourcePathVariable("X86GccRoot",
Dan Willemsen34fc3b12015-12-07 12:30:44 -080098 "prebuilts/gcc/${HostPrebuiltTag}/x86/x86_64-linux-android-${x86GccVersion}")
Colin Crossb0cba6a2015-11-20 15:35:26 -080099
Liz Kammer82ad8cc2021-08-02 10:41:48 -0400100 exportStringListStaticVariable("X86ToolchainCflags", []string{"-m32"})
101 exportStringListStaticVariable("X86ToolchainLdflags", []string{"-m32"})
Colin Crossb0cba6a2015-11-20 15:35:26 -0800102
Liz Kammer82ad8cc2021-08-02 10:41:48 -0400103 exportStringListStaticVariable("X86Ldflags", x86Ldflags)
104 exportStringListStaticVariable("X86Lldflags", x86Ldflags)
Colin Crossb0cba6a2015-11-20 15:35:26 -0800105
106 // Clang cflags
Liz Kammer82ad8cc2021-08-02 10:41:48 -0400107 exportStringListStaticVariable("X86Cflags", x86Cflags)
108 exportStringListStaticVariable("X86Cppflags", x86Cppflags)
Colin Crossb0cba6a2015-11-20 15:35:26 -0800109
Colin Cross91e90042016-12-02 17:13:24 -0800110 // Yasm flags
Liz Kammer82ad8cc2021-08-02 10:41:48 -0400111 exportStringListStaticVariable("X86YasmFlags", []string{
112 "-f elf32",
113 "-m x86",
114 })
Colin Cross91e90042016-12-02 17:13:24 -0800115
Colin Crossb0cba6a2015-11-20 15:35:26 -0800116 // Extended cflags
Liz Kammer82ad8cc2021-08-02 10:41:48 -0400117 exportedStringListDictVars.Set("X86ArchVariantCflags", x86ArchVariantCflags)
118 exportedStringListDictVars.Set("X86ArchFeatureCflags", x86ArchFeatureCflags)
Colin Crossb0cba6a2015-11-20 15:35:26 -0800119
120 // Architecture variant cflags
121 for variant, cflags := range x86ArchVariantCflags {
Liz Kammer82ad8cc2021-08-02 10:41:48 -0400122 pctx.StaticVariable("X86"+variant+"VariantCflags", strings.Join(cflags, " "))
Colin Crossb0cba6a2015-11-20 15:35:26 -0800123 }
124}
125
126type toolchainX86 struct {
Colin Crosse3fee342021-06-21 17:28:25 -0700127 toolchainBionic
Colin Crossb0cba6a2015-11-20 15:35:26 -0800128 toolchain32Bit
Colin Cross33bac242021-07-14 17:03:16 -0700129 toolchainCflags string
Colin Crossb0cba6a2015-11-20 15:35:26 -0800130}
131
132func (t *toolchainX86) Name() string {
133 return "x86"
134}
135
136func (t *toolchainX86) GccRoot() string {
Colin Crossb98c8b02016-07-29 13:44:28 -0700137 return "${config.X86GccRoot}"
Colin Crossb0cba6a2015-11-20 15:35:26 -0800138}
139
140func (t *toolchainX86) GccTriple() string {
Dan Albert84f431f2016-07-20 14:44:26 -0700141 return "x86_64-linux-android"
Colin Crossb0cba6a2015-11-20 15:35:26 -0800142}
143
144func (t *toolchainX86) GccVersion() string {
Dan Willemsen34fc3b12015-12-07 12:30:44 -0800145 return x86GccVersion
Colin Crossb0cba6a2015-11-20 15:35:26 -0800146}
147
Colin Crossb0cba6a2015-11-20 15:35:26 -0800148func (t *toolchainX86) IncludeFlags() string {
Martin Stjernholm41ab2512020-04-08 01:06:07 +0100149 return ""
Colin Crossb0cba6a2015-11-20 15:35:26 -0800150}
151
152func (t *toolchainX86) ClangTriple() string {
Dan Willemsen569b0fa2016-05-08 20:04:20 -0700153 return "i686-linux-android"
154}
155
Colin Cross33bac242021-07-14 17:03:16 -0700156func (t *toolchainX86) ToolchainLdflags() string {
Colin Crossb98c8b02016-07-29 13:44:28 -0700157 return "${config.X86ToolchainLdflags}"
Colin Crossb0cba6a2015-11-20 15:35:26 -0800158}
159
Colin Cross33bac242021-07-14 17:03:16 -0700160func (t *toolchainX86) ToolchainCflags() string {
161 return t.toolchainCflags
Colin Crossb0cba6a2015-11-20 15:35:26 -0800162}
163
Colin Cross33bac242021-07-14 17:03:16 -0700164func (t *toolchainX86) Cflags() string {
Colin Cross0523ba22021-07-14 18:45:05 -0700165 return "${config.X86Cflags}"
Colin Crossb0cba6a2015-11-20 15:35:26 -0800166}
167
Colin Cross33bac242021-07-14 17:03:16 -0700168func (t *toolchainX86) Cppflags() string {
Colin Cross0523ba22021-07-14 18:45:05 -0700169 return "${config.X86Cppflags}"
Colin Crossb0cba6a2015-11-20 15:35:26 -0800170}
171
Colin Cross33bac242021-07-14 17:03:16 -0700172func (t *toolchainX86) Ldflags() string {
Colin Crossb98c8b02016-07-29 13:44:28 -0700173 return "${config.X86Ldflags}"
Colin Crossb0cba6a2015-11-20 15:35:26 -0800174}
175
Colin Cross33bac242021-07-14 17:03:16 -0700176func (t *toolchainX86) Lldflags() string {
Chih-Hung Hsieh02b4da52018-04-03 11:33:34 -0700177 return "${config.X86Lldflags}"
178}
179
Colin Cross91e90042016-12-02 17:13:24 -0800180func (t *toolchainX86) YasmFlags() string {
181 return "${config.X86YasmFlags}"
182}
183
Yi Kong924adc42018-08-31 14:27:44 -0700184func (toolchainX86) LibclangRuntimeLibraryArch() string {
Evgenii Stepanovaf36db12016-08-15 14:18:24 -0700185 return "i686"
Colin Cross16b23492016-01-06 14:41:07 -0800186}
187
Colin Cross635c3b02016-05-18 15:37:25 -0700188func x86ToolchainFactory(arch android.Arch) Toolchain {
Colin Cross33bac242021-07-14 17:03:16 -0700189 toolchainCflags := []string{
Colin Crossb98c8b02016-07-29 13:44:28 -0700190 "${config.X86ToolchainCflags}",
Colin Cross0523ba22021-07-14 18:45:05 -0700191 "${config.X86" + arch.ArchVariant + "VariantCflags}",
Colin Crossb0cba6a2015-11-20 15:35:26 -0800192 }
193
194 for _, feature := range arch.ArchFeatures {
Colin Cross33bac242021-07-14 17:03:16 -0700195 toolchainCflags = append(toolchainCflags, x86ArchFeatureCflags[feature]...)
Colin Crossb0cba6a2015-11-20 15:35:26 -0800196 }
197
198 return &toolchainX86{
Colin Cross33bac242021-07-14 17:03:16 -0700199 toolchainCflags: strings.Join(toolchainCflags, " "),
Colin Crossb0cba6a2015-11-20 15:35:26 -0800200 }
201}
202
203func init() {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700204 registerToolchainFactory(android.Android, android.X86, x86ToolchainFactory)
Colin Crossb0cba6a2015-11-20 15:35:26 -0800205}