blob: 500014e9fcaf0dfd4838c4f80c7143832d830632 [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 Crossb37620f2017-11-06 14:05:51 -080024 x86Cflags = []string{}
Colin Crossb0cba6a2015-11-20 15:35:26 -080025
Dan Willemsen569b0fa2016-05-08 20:04:20 -070026 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 Crossb0cba6a2015-11-20 15:35:26 -080035 x86Cppflags = []string{}
36
37 x86Ldflags = []string{
Colin Crossb0cba6a2015-11-20 15:35:26 -080038 "-Wl,--hash-style=gnu",
39 }
40
Chih-Hung Hsieh02b4da52018-04-03 11:33:34 -070041 x86Lldflags = ClangFilterUnknownLldflags(x86Ldflags)
42
Colin Crossb0cba6a2015-11-20 15:35:26 -080043 x86ArchVariantCflags = map[string][]string{
44 "": []string{
45 "-march=prescott",
46 },
Dan Willemsen8a354052016-05-10 14:30:51 -070047 "x86_64": []string{
48 "-march=prescott",
49 },
Colin Crossb0cba6a2015-11-20 15:35:26 -080050 "atom": []string{
51 "-march=atom",
52 "-mfpmath=sse",
53 },
Shalini Salomi Bodapati4a0459d2019-01-22 10:00:15 +053054 "broadwell": []string{
55 "-march=broadwell",
56 "-mfpmath=sse",
57 },
Colin Crossb0cba6a2015-11-20 15:35:26 -080058 "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 Willemsenb77bd792016-02-29 15:26:26 -080067 "-march=corei7",
Colin Crossb0cba6a2015-11-20 15:35:26 -080068 "-mfpmath=sse",
69 },
70 "silvermont": []string{
71 "-march=slm",
72 "-mfpmath=sse",
73 },
Shalini Salomi Bodapati4a0459d2019-01-22 10:00:15 +053074 "skylake": []string{
75 "-march=skylake",
76 "-mfpmath=sse",
77 },
Benjamin Gordon87e7f2f2019-02-14 10:59:48 -070078 "stoneyridge": []string{
79 "-march=bdver4",
80 "-mfpmath=sse",
81 },
Colin Crossb0cba6a2015-11-20 15:35:26 -080082 }
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 Gordon87e7f2f2019-02-14 10:59:48 -070090 "avx2": []string{"-mavx2"},
Colin Crossb0cba6a2015-11-20 15:35:26 -080091 "aes_ni": []string{"-maes"},
92 }
93)
94
Dan Willemsen34fc3b12015-12-07 12:30:44 -080095const (
96 x86GccVersion = "4.9"
97)
98
Colin Crossb0cba6a2015-11-20 15:35:26 -080099func init() {
Dan Willemsen34fc3b12015-12-07 12:30:44 -0800100 pctx.StaticVariable("x86GccVersion", x86GccVersion)
Colin Crossb0cba6a2015-11-20 15:35:26 -0800101
Colin Crossb98c8b02016-07-29 13:44:28 -0700102 pctx.SourcePathVariable("X86GccRoot",
Dan Willemsen34fc3b12015-12-07 12:30:44 -0800103 "prebuilts/gcc/${HostPrebuiltTag}/x86/x86_64-linux-android-${x86GccVersion}")
Colin Crossb0cba6a2015-11-20 15:35:26 -0800104
Colin Crossb98c8b02016-07-29 13:44:28 -0700105 pctx.StaticVariable("X86ToolchainCflags", "-m32")
106 pctx.StaticVariable("X86ToolchainLdflags", "-m32")
Colin Crossb0cba6a2015-11-20 15:35:26 -0800107
Colin Crossb98c8b02016-07-29 13:44:28 -0700108 pctx.StaticVariable("X86Ldflags", strings.Join(x86Ldflags, " "))
Chih-Hung Hsieh02b4da52018-04-03 11:33:34 -0700109 pctx.StaticVariable("X86Lldflags", strings.Join(x86Lldflags, " "))
Elliott Hughesde28deb2017-10-12 09:07:53 -0700110 pctx.StaticVariable("X86IncludeFlags", bionicHeaders("x86"))
Colin Crossb0cba6a2015-11-20 15:35:26 -0800111
112 // Clang cflags
Colin Crossb98c8b02016-07-29 13:44:28 -0700113 pctx.StaticVariable("X86ClangCflags", strings.Join(ClangFilterUnknownCflags(x86ClangCflags), " "))
114 pctx.StaticVariable("X86ClangLdflags", strings.Join(ClangFilterUnknownCflags(x86Ldflags), " "))
Chih-Hung Hsieh02b4da52018-04-03 11:33:34 -0700115 pctx.StaticVariable("X86ClangLldflags", strings.Join(ClangFilterUnknownCflags(x86Lldflags), " "))
Colin Crossb98c8b02016-07-29 13:44:28 -0700116 pctx.StaticVariable("X86ClangCppflags", strings.Join(ClangFilterUnknownCflags(x86Cppflags), " "))
Colin Crossb0cba6a2015-11-20 15:35:26 -0800117
Colin Cross91e90042016-12-02 17:13:24 -0800118 // Yasm flags
119 pctx.StaticVariable("X86YasmFlags", "-f elf32 -m x86")
120
Colin Crossb0cba6a2015-11-20 15:35:26 -0800121 // Extended cflags
122
123 // Architecture variant cflags
124 for variant, cflags := range x86ArchVariantCflags {
Colin Crossb98c8b02016-07-29 13:44:28 -0700125 pctx.StaticVariable("X86"+variant+"VariantClangCflags",
126 strings.Join(ClangFilterUnknownCflags(cflags), " "))
Colin Crossb0cba6a2015-11-20 15:35:26 -0800127 }
128}
129
130type toolchainX86 struct {
131 toolchain32Bit
Dan Willemsenbd4abf52018-10-07 21:06:36 -0700132 toolchainClangCflags string
Colin Crossb0cba6a2015-11-20 15:35:26 -0800133}
134
135func (t *toolchainX86) Name() string {
136 return "x86"
137}
138
139func (t *toolchainX86) GccRoot() string {
Colin Crossb98c8b02016-07-29 13:44:28 -0700140 return "${config.X86GccRoot}"
Colin Crossb0cba6a2015-11-20 15:35:26 -0800141}
142
143func (t *toolchainX86) GccTriple() string {
Dan Albert84f431f2016-07-20 14:44:26 -0700144 return "x86_64-linux-android"
Colin Crossb0cba6a2015-11-20 15:35:26 -0800145}
146
147func (t *toolchainX86) GccVersion() string {
Dan Willemsen34fc3b12015-12-07 12:30:44 -0800148 return x86GccVersion
Colin Crossb0cba6a2015-11-20 15:35:26 -0800149}
150
Colin Crossb0cba6a2015-11-20 15:35:26 -0800151func (t *toolchainX86) IncludeFlags() string {
Colin Crossb98c8b02016-07-29 13:44:28 -0700152 return "${config.X86IncludeFlags}"
Colin Crossb0cba6a2015-11-20 15:35:26 -0800153}
154
155func (t *toolchainX86) ClangTriple() string {
Dan Willemsen569b0fa2016-05-08 20:04:20 -0700156 return "i686-linux-android"
157}
158
159func (t *toolchainX86) ToolchainClangLdflags() string {
Colin Crossb98c8b02016-07-29 13:44:28 -0700160 return "${config.X86ToolchainLdflags}"
Colin Crossb0cba6a2015-11-20 15:35:26 -0800161}
162
163func (t *toolchainX86) ToolchainClangCflags() string {
164 return t.toolchainClangCflags
165}
166
167func (t *toolchainX86) ClangCflags() string {
Colin Crossb98c8b02016-07-29 13:44:28 -0700168 return "${config.X86ClangCflags}"
Colin Crossb0cba6a2015-11-20 15:35:26 -0800169}
170
171func (t *toolchainX86) ClangCppflags() string {
Colin Crossb98c8b02016-07-29 13:44:28 -0700172 return "${config.X86ClangCppflags}"
Colin Crossb0cba6a2015-11-20 15:35:26 -0800173}
174
175func (t *toolchainX86) ClangLdflags() string {
Colin Crossb98c8b02016-07-29 13:44:28 -0700176 return "${config.X86Ldflags}"
Colin Crossb0cba6a2015-11-20 15:35:26 -0800177}
178
Chih-Hung Hsieh02b4da52018-04-03 11:33:34 -0700179func (t *toolchainX86) ClangLldflags() string {
180 return "${config.X86Lldflags}"
181}
182
Colin Cross91e90042016-12-02 17:13:24 -0800183func (t *toolchainX86) YasmFlags() string {
184 return "${config.X86YasmFlags}"
185}
186
Yi Kong924adc42018-08-31 14:27:44 -0700187func (toolchainX86) LibclangRuntimeLibraryArch() string {
Evgenii Stepanovaf36db12016-08-15 14:18:24 -0700188 return "i686"
Colin Cross16b23492016-01-06 14:41:07 -0800189}
190
Colin Cross635c3b02016-05-18 15:37:25 -0700191func x86ToolchainFactory(arch android.Arch) Toolchain {
Colin Crossb0cba6a2015-11-20 15:35:26 -0800192 toolchainClangCflags := []string{
Colin Crossb98c8b02016-07-29 13:44:28 -0700193 "${config.X86ToolchainCflags}",
194 "${config.X86" + arch.ArchVariant + "VariantClangCflags}",
Colin Crossb0cba6a2015-11-20 15:35:26 -0800195 }
196
197 for _, feature := range arch.ArchFeatures {
Colin Crossb0cba6a2015-11-20 15:35:26 -0800198 toolchainClangCflags = append(toolchainClangCflags, x86ArchFeatureCflags[feature]...)
199 }
200
201 return &toolchainX86{
Colin Crossb0cba6a2015-11-20 15:35:26 -0800202 toolchainClangCflags: strings.Join(toolchainClangCflags, " "),
203 }
204}
205
206func init() {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700207 registerToolchainFactory(android.Android, android.X86, x86ToolchainFactory)
Colin Crossb0cba6a2015-11-20 15:35:26 -0800208}