blob: fe830982f4c10bd5a57644d183720b6fbfd467f3 [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{
Elliott Hughesb22dcfe2019-07-12 22:40:45 -070085 "ssse3": []string{"-mssse3"},
Colin Crossb0cba6a2015-11-20 15:35:26 -080086 "sse4": []string{"-msse4"},
87 "sse4_1": []string{"-msse4.1"},
88 "sse4_2": []string{"-msse4.2"},
jaishank7e849692019-06-25 14:55:52 +053089
90 // Not all cases there is performance gain by enabling -mavx -mavx2
91 // flags so these flags are not enabled by default.
92 // if there is performance gain in individual library components,
93 // the compiler flags can be set in corresponding bp files.
94 // "avx": []string{"-mavx"},
95 // "avx2": []string{"-mavx2"},
96 // "avx512": []string{"-mavx512"}
97
Colin Crossb0cba6a2015-11-20 15:35:26 -080098 "aes_ni": []string{"-maes"},
99 }
100)
101
Dan Willemsen34fc3b12015-12-07 12:30:44 -0800102const (
103 x86GccVersion = "4.9"
104)
105
Colin Crossb0cba6a2015-11-20 15:35:26 -0800106func init() {
Dan Willemsen34fc3b12015-12-07 12:30:44 -0800107 pctx.StaticVariable("x86GccVersion", x86GccVersion)
Colin Crossb0cba6a2015-11-20 15:35:26 -0800108
Colin Crossb98c8b02016-07-29 13:44:28 -0700109 pctx.SourcePathVariable("X86GccRoot",
Dan Willemsen34fc3b12015-12-07 12:30:44 -0800110 "prebuilts/gcc/${HostPrebuiltTag}/x86/x86_64-linux-android-${x86GccVersion}")
Colin Crossb0cba6a2015-11-20 15:35:26 -0800111
Colin Crossb98c8b02016-07-29 13:44:28 -0700112 pctx.StaticVariable("X86ToolchainCflags", "-m32")
113 pctx.StaticVariable("X86ToolchainLdflags", "-m32")
Colin Crossb0cba6a2015-11-20 15:35:26 -0800114
Colin Crossb98c8b02016-07-29 13:44:28 -0700115 pctx.StaticVariable("X86Ldflags", strings.Join(x86Ldflags, " "))
Chih-Hung Hsieh02b4da52018-04-03 11:33:34 -0700116 pctx.StaticVariable("X86Lldflags", strings.Join(x86Lldflags, " "))
Colin Crossb0cba6a2015-11-20 15:35:26 -0800117
118 // Clang cflags
Colin Crossb98c8b02016-07-29 13:44:28 -0700119 pctx.StaticVariable("X86ClangCflags", strings.Join(ClangFilterUnknownCflags(x86ClangCflags), " "))
120 pctx.StaticVariable("X86ClangLdflags", strings.Join(ClangFilterUnknownCflags(x86Ldflags), " "))
Chih-Hung Hsieh02b4da52018-04-03 11:33:34 -0700121 pctx.StaticVariable("X86ClangLldflags", strings.Join(ClangFilterUnknownCflags(x86Lldflags), " "))
Colin Crossb98c8b02016-07-29 13:44:28 -0700122 pctx.StaticVariable("X86ClangCppflags", strings.Join(ClangFilterUnknownCflags(x86Cppflags), " "))
Colin Crossb0cba6a2015-11-20 15:35:26 -0800123
Colin Cross91e90042016-12-02 17:13:24 -0800124 // Yasm flags
125 pctx.StaticVariable("X86YasmFlags", "-f elf32 -m x86")
126
Colin Crossb0cba6a2015-11-20 15:35:26 -0800127 // Extended cflags
128
129 // Architecture variant cflags
130 for variant, cflags := range x86ArchVariantCflags {
Colin Crossb98c8b02016-07-29 13:44:28 -0700131 pctx.StaticVariable("X86"+variant+"VariantClangCflags",
132 strings.Join(ClangFilterUnknownCflags(cflags), " "))
Colin Crossb0cba6a2015-11-20 15:35:26 -0800133 }
134}
135
136type toolchainX86 struct {
137 toolchain32Bit
Dan Willemsenbd4abf52018-10-07 21:06:36 -0700138 toolchainClangCflags string
Colin Crossb0cba6a2015-11-20 15:35:26 -0800139}
140
141func (t *toolchainX86) Name() string {
142 return "x86"
143}
144
145func (t *toolchainX86) GccRoot() string {
Colin Crossb98c8b02016-07-29 13:44:28 -0700146 return "${config.X86GccRoot}"
Colin Crossb0cba6a2015-11-20 15:35:26 -0800147}
148
149func (t *toolchainX86) GccTriple() string {
Dan Albert84f431f2016-07-20 14:44:26 -0700150 return "x86_64-linux-android"
Colin Crossb0cba6a2015-11-20 15:35:26 -0800151}
152
153func (t *toolchainX86) GccVersion() string {
Dan Willemsen34fc3b12015-12-07 12:30:44 -0800154 return x86GccVersion
Colin Crossb0cba6a2015-11-20 15:35:26 -0800155}
156
Colin Crossb0cba6a2015-11-20 15:35:26 -0800157func (t *toolchainX86) IncludeFlags() string {
Martin Stjernholm41ab2512020-04-08 01:06:07 +0100158 return ""
Colin Crossb0cba6a2015-11-20 15:35:26 -0800159}
160
161func (t *toolchainX86) ClangTriple() string {
Dan Willemsen569b0fa2016-05-08 20:04:20 -0700162 return "i686-linux-android"
163}
164
165func (t *toolchainX86) ToolchainClangLdflags() string {
Colin Crossb98c8b02016-07-29 13:44:28 -0700166 return "${config.X86ToolchainLdflags}"
Colin Crossb0cba6a2015-11-20 15:35:26 -0800167}
168
169func (t *toolchainX86) ToolchainClangCflags() string {
170 return t.toolchainClangCflags
171}
172
173func (t *toolchainX86) ClangCflags() string {
Colin Crossb98c8b02016-07-29 13:44:28 -0700174 return "${config.X86ClangCflags}"
Colin Crossb0cba6a2015-11-20 15:35:26 -0800175}
176
177func (t *toolchainX86) ClangCppflags() string {
Colin Crossb98c8b02016-07-29 13:44:28 -0700178 return "${config.X86ClangCppflags}"
Colin Crossb0cba6a2015-11-20 15:35:26 -0800179}
180
181func (t *toolchainX86) ClangLdflags() string {
Colin Crossb98c8b02016-07-29 13:44:28 -0700182 return "${config.X86Ldflags}"
Colin Crossb0cba6a2015-11-20 15:35:26 -0800183}
184
Chih-Hung Hsieh02b4da52018-04-03 11:33:34 -0700185func (t *toolchainX86) ClangLldflags() string {
186 return "${config.X86Lldflags}"
187}
188
Colin Cross91e90042016-12-02 17:13:24 -0800189func (t *toolchainX86) YasmFlags() string {
190 return "${config.X86YasmFlags}"
191}
192
Yi Kong924adc42018-08-31 14:27:44 -0700193func (toolchainX86) LibclangRuntimeLibraryArch() string {
Evgenii Stepanovaf36db12016-08-15 14:18:24 -0700194 return "i686"
Colin Cross16b23492016-01-06 14:41:07 -0800195}
196
Colin Cross635c3b02016-05-18 15:37:25 -0700197func x86ToolchainFactory(arch android.Arch) Toolchain {
Colin Crossb0cba6a2015-11-20 15:35:26 -0800198 toolchainClangCflags := []string{
Colin Crossb98c8b02016-07-29 13:44:28 -0700199 "${config.X86ToolchainCflags}",
200 "${config.X86" + arch.ArchVariant + "VariantClangCflags}",
Colin Crossb0cba6a2015-11-20 15:35:26 -0800201 }
202
203 for _, feature := range arch.ArchFeatures {
Colin Crossb0cba6a2015-11-20 15:35:26 -0800204 toolchainClangCflags = append(toolchainClangCflags, x86ArchFeatureCflags[feature]...)
205 }
206
207 return &toolchainX86{
Colin Crossb0cba6a2015-11-20 15:35:26 -0800208 toolchainClangCflags: strings.Join(toolchainClangCflags, " "),
209 }
210}
211
212func init() {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700213 registerToolchainFactory(android.Android, android.X86, x86ToolchainFactory)
Colin Crossb0cba6a2015-11-20 15:35:26 -0800214}