blob: 421b08354399cf4cc26f771a18434dc0278ffd7f [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 (
Liz Kammerf610a742022-02-10 16:56:02 -050018 "fmt"
Colin Crossb0cba6a2015-11-20 15:35:26 -080019 "strings"
20
Colin Cross635c3b02016-05-18 15:37:25 -070021 "android/soong/android"
Colin Crossb0cba6a2015-11-20 15:35:26 -080022)
23
24var (
Colin Cross33bac242021-07-14 17:03:16 -070025 x86Cflags = []string{
Dan Willemsen569b0fa2016-05-08 20:04:20 -070026 "-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 Cross33bac242021-07-14 17:03:16 -070032 }
Dan Willemsen569b0fa2016-05-08 20:04:20 -070033
Colin Crossb0cba6a2015-11-20 15:35:26 -080034 x86Cppflags = []string{}
35
36 x86Ldflags = []string{
Colin Crossb0cba6a2015-11-20 15:35:26 -080037 "-Wl,--hash-style=gnu",
38 }
39
40 x86ArchVariantCflags = map[string][]string{
41 "": []string{
42 "-march=prescott",
43 },
Dan Willemsen8a354052016-05-10 14:30:51 -070044 "x86_64": []string{
45 "-march=prescott",
46 },
Colin Crossb0cba6a2015-11-20 15:35:26 -080047 "atom": []string{
48 "-march=atom",
Colin Crossb0cba6a2015-11-20 15:35:26 -080049 },
Shalini Salomi Bodapati4a0459d2019-01-22 10:00:15 +053050 "broadwell": []string{
51 "-march=broadwell",
Shalini Salomi Bodapati4a0459d2019-01-22 10:00:15 +053052 },
Colin Crossb0cba6a2015-11-20 15:35:26 -080053 "haswell": []string{
54 "-march=core-avx2",
Colin Crossb0cba6a2015-11-20 15:35:26 -080055 },
56 "ivybridge": []string{
57 "-march=core-avx-i",
Colin Crossb0cba6a2015-11-20 15:35:26 -080058 },
59 "sandybridge": []string{
Dan Willemsenb77bd792016-02-29 15:26:26 -080060 "-march=corei7",
Colin Crossb0cba6a2015-11-20 15:35:26 -080061 },
62 "silvermont": []string{
63 "-march=slm",
Colin Crossb0cba6a2015-11-20 15:35:26 -080064 },
Shalini Salomi Bodapati4a0459d2019-01-22 10:00:15 +053065 "skylake": []string{
66 "-march=skylake",
Shalini Salomi Bodapati4a0459d2019-01-22 10:00:15 +053067 },
Benjamin Gordon87e7f2f2019-02-14 10:59:48 -070068 "stoneyridge": []string{
69 "-march=bdver4",
Benjamin Gordon87e7f2f2019-02-14 10:59:48 -070070 },
Colin Crossb0cba6a2015-11-20 15:35:26 -080071 }
72
73 x86ArchFeatureCflags = map[string][]string{
Elliott Hughesb22dcfe2019-07-12 22:40:45 -070074 "ssse3": []string{"-mssse3"},
Colin Crossb0cba6a2015-11-20 15:35:26 -080075 "sse4": []string{"-msse4"},
76 "sse4_1": []string{"-msse4.1"},
77 "sse4_2": []string{"-msse4.2"},
jaishank7e849692019-06-25 14:55:52 +053078
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 Crossb0cba6a2015-11-20 15:35:26 -080087 "aes_ni": []string{"-maes"},
88 }
89)
90
Dan Willemsen34fc3b12015-12-07 12:30:44 -080091const (
92 x86GccVersion = "4.9"
93)
94
Colin Crossb0cba6a2015-11-20 15:35:26 -080095func init() {
Dan Willemsen34fc3b12015-12-07 12:30:44 -080096 pctx.StaticVariable("x86GccVersion", x86GccVersion)
Colin Crossb0cba6a2015-11-20 15:35:26 -080097
Colin Crossb98c8b02016-07-29 13:44:28 -070098 pctx.SourcePathVariable("X86GccRoot",
Dan Willemsen34fc3b12015-12-07 12:30:44 -080099 "prebuilts/gcc/${HostPrebuiltTag}/x86/x86_64-linux-android-${x86GccVersion}")
Colin Crossb0cba6a2015-11-20 15:35:26 -0800100
Sam Delmerico7f889562022-03-25 14:55:40 +0000101 exportedVars.ExportStringListStaticVariable("X86ToolchainCflags", []string{"-m32"})
102 exportedVars.ExportStringListStaticVariable("X86ToolchainLdflags", []string{"-m32"})
Colin Crossb0cba6a2015-11-20 15:35:26 -0800103
Sam Delmerico7f889562022-03-25 14:55:40 +0000104 exportedVars.ExportStringListStaticVariable("X86Ldflags", x86Ldflags)
105 exportedVars.ExportStringListStaticVariable("X86Lldflags", x86Ldflags)
Colin Crossb0cba6a2015-11-20 15:35:26 -0800106
107 // Clang cflags
Sam Delmerico7f889562022-03-25 14:55:40 +0000108 exportedVars.ExportStringListStaticVariable("X86Cflags", x86Cflags)
109 exportedVars.ExportStringListStaticVariable("X86Cppflags", x86Cppflags)
Colin Crossb0cba6a2015-11-20 15:35:26 -0800110
Colin Cross91e90042016-12-02 17:13:24 -0800111 // Yasm flags
Sam Delmerico7f889562022-03-25 14:55:40 +0000112 exportedVars.ExportStringListStaticVariable("X86YasmFlags", []string{
Liz Kammer82ad8cc2021-08-02 10:41:48 -0400113 "-f elf32",
114 "-m x86",
115 })
Colin Cross91e90042016-12-02 17:13:24 -0800116
Colin Crossb0cba6a2015-11-20 15:35:26 -0800117 // Extended cflags
Sam Delmerico7f889562022-03-25 14:55:40 +0000118 exportedVars.ExportStringListDict("X86ArchVariantCflags", x86ArchVariantCflags)
119 exportedVars.ExportStringListDict("X86ArchFeatureCflags", x86ArchFeatureCflags)
Colin Crossb0cba6a2015-11-20 15:35:26 -0800120
121 // Architecture variant cflags
122 for variant, cflags := range x86ArchVariantCflags {
Liz Kammer82ad8cc2021-08-02 10:41:48 -0400123 pctx.StaticVariable("X86"+variant+"VariantCflags", strings.Join(cflags, " "))
Colin Crossb0cba6a2015-11-20 15:35:26 -0800124 }
125}
126
127type toolchainX86 struct {
Colin Crosse3fee342021-06-21 17:28:25 -0700128 toolchainBionic
Colin Crossb0cba6a2015-11-20 15:35:26 -0800129 toolchain32Bit
Colin Cross33bac242021-07-14 17:03:16 -0700130 toolchainCflags string
Colin Crossb0cba6a2015-11-20 15:35:26 -0800131}
132
133func (t *toolchainX86) Name() string {
134 return "x86"
135}
136
137func (t *toolchainX86) GccRoot() string {
Colin Crossb98c8b02016-07-29 13:44:28 -0700138 return "${config.X86GccRoot}"
Colin Crossb0cba6a2015-11-20 15:35:26 -0800139}
140
141func (t *toolchainX86) GccTriple() string {
Dan Albert84f431f2016-07-20 14:44:26 -0700142 return "x86_64-linux-android"
Colin Crossb0cba6a2015-11-20 15:35:26 -0800143}
144
145func (t *toolchainX86) GccVersion() string {
Dan Willemsen34fc3b12015-12-07 12:30:44 -0800146 return x86GccVersion
Colin Crossb0cba6a2015-11-20 15:35:26 -0800147}
148
Colin Crossb0cba6a2015-11-20 15:35:26 -0800149func (t *toolchainX86) IncludeFlags() string {
Martin Stjernholm41ab2512020-04-08 01:06:07 +0100150 return ""
Colin Crossb0cba6a2015-11-20 15:35:26 -0800151}
152
153func (t *toolchainX86) ClangTriple() string {
Dan Willemsen569b0fa2016-05-08 20:04:20 -0700154 return "i686-linux-android"
155}
156
Colin Cross33bac242021-07-14 17:03:16 -0700157func (t *toolchainX86) ToolchainLdflags() string {
Colin Crossb98c8b02016-07-29 13:44:28 -0700158 return "${config.X86ToolchainLdflags}"
Colin Crossb0cba6a2015-11-20 15:35:26 -0800159}
160
Colin Cross33bac242021-07-14 17:03:16 -0700161func (t *toolchainX86) ToolchainCflags() string {
162 return t.toolchainCflags
Colin Crossb0cba6a2015-11-20 15:35:26 -0800163}
164
Colin Cross33bac242021-07-14 17:03:16 -0700165func (t *toolchainX86) Cflags() string {
Colin Cross0523ba22021-07-14 18:45:05 -0700166 return "${config.X86Cflags}"
Colin Crossb0cba6a2015-11-20 15:35:26 -0800167}
168
Colin Cross33bac242021-07-14 17:03:16 -0700169func (t *toolchainX86) Cppflags() string {
Colin Cross0523ba22021-07-14 18:45:05 -0700170 return "${config.X86Cppflags}"
Colin Crossb0cba6a2015-11-20 15:35:26 -0800171}
172
Colin Cross33bac242021-07-14 17:03:16 -0700173func (t *toolchainX86) Ldflags() string {
Colin Crossb98c8b02016-07-29 13:44:28 -0700174 return "${config.X86Ldflags}"
Colin Crossb0cba6a2015-11-20 15:35:26 -0800175}
176
Colin Cross33bac242021-07-14 17:03:16 -0700177func (t *toolchainX86) Lldflags() string {
Chih-Hung Hsieh02b4da52018-04-03 11:33:34 -0700178 return "${config.X86Lldflags}"
179}
180
Colin Cross91e90042016-12-02 17:13:24 -0800181func (t *toolchainX86) YasmFlags() string {
182 return "${config.X86YasmFlags}"
183}
184
Yi Kong924adc42018-08-31 14:27:44 -0700185func (toolchainX86) LibclangRuntimeLibraryArch() string {
Evgenii Stepanovaf36db12016-08-15 14:18:24 -0700186 return "i686"
Colin Cross16b23492016-01-06 14:41:07 -0800187}
188
Colin Cross635c3b02016-05-18 15:37:25 -0700189func x86ToolchainFactory(arch android.Arch) Toolchain {
Liz Kammerf610a742022-02-10 16:56:02 -0500190 // 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 Cross33bac242021-07-14 17:03:16 -0700195 toolchainCflags := []string{
Colin Crossb98c8b02016-07-29 13:44:28 -0700196 "${config.X86ToolchainCflags}",
Colin Cross0523ba22021-07-14 18:45:05 -0700197 "${config.X86" + arch.ArchVariant + "VariantCflags}",
Colin Crossb0cba6a2015-11-20 15:35:26 -0800198 }
199
200 for _, feature := range arch.ArchFeatures {
Colin Cross33bac242021-07-14 17:03:16 -0700201 toolchainCflags = append(toolchainCflags, x86ArchFeatureCflags[feature]...)
Colin Crossb0cba6a2015-11-20 15:35:26 -0800202 }
203
204 return &toolchainX86{
Colin Cross33bac242021-07-14 17:03:16 -0700205 toolchainCflags: strings.Join(toolchainCflags, " "),
Colin Crossb0cba6a2015-11-20 15:35:26 -0800206 }
207}
208
209func init() {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700210 registerToolchainFactory(android.Android, android.X86, x86ToolchainFactory)
Colin Crossb0cba6a2015-11-20 15:35:26 -0800211}