Home | History | Annotate | Download | only in config
      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 
     15 package config
     16 
     17 import (
     18 	"strings"
     19 
     20 	"android/soong/android"
     21 )
     22 
     23 var (
     24 	x86Cflags = []string{}
     25 
     26 	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 
     35 	x86Cppflags = []string{}
     36 
     37 	x86Ldflags = []string{
     38 		"-Wl,--hash-style=gnu",
     39 	}
     40 
     41 	x86Lldflags = ClangFilterUnknownLldflags(x86Ldflags)
     42 
     43 	x86ArchVariantCflags = map[string][]string{
     44 		"": []string{
     45 			"-march=prescott",
     46 		},
     47 		"x86_64": []string{
     48 			"-march=prescott",
     49 		},
     50 		"atom": []string{
     51 			"-march=atom",
     52 			"-mfpmath=sse",
     53 		},
     54 		"broadwell": []string{
     55 			"-march=broadwell",
     56 			"-mfpmath=sse",
     57 		},
     58 		"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{
     67 			"-march=corei7",
     68 			"-mfpmath=sse",
     69 		},
     70 		"silvermont": []string{
     71 			"-march=slm",
     72 			"-mfpmath=sse",
     73 		},
     74 		"skylake": []string{
     75 			"-march=skylake",
     76 			"-mfpmath=sse",
     77 		},
     78 		"stoneyridge": []string{
     79 			"-march=bdver4",
     80 			"-mfpmath=sse",
     81 		},
     82 	}
     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"},
     90 		"avx2":   []string{"-mavx2"},
     91 		"aes_ni": []string{"-maes"},
     92 	}
     93 )
     94 
     95 const (
     96 	x86GccVersion = "4.9"
     97 )
     98 
     99 func init() {
    100 	pctx.StaticVariable("x86GccVersion", x86GccVersion)
    101 
    102 	pctx.SourcePathVariable("X86GccRoot",
    103 		"prebuilts/gcc/${HostPrebuiltTag}/x86/x86_64-linux-android-${x86GccVersion}")
    104 
    105 	pctx.StaticVariable("X86ToolchainCflags", "-m32")
    106 	pctx.StaticVariable("X86ToolchainLdflags", "-m32")
    107 
    108 	pctx.StaticVariable("X86Ldflags", strings.Join(x86Ldflags, " "))
    109 	pctx.StaticVariable("X86Lldflags", strings.Join(x86Lldflags, " "))
    110 	pctx.StaticVariable("X86IncludeFlags", bionicHeaders("x86"))
    111 
    112 	// Clang cflags
    113 	pctx.StaticVariable("X86ClangCflags", strings.Join(ClangFilterUnknownCflags(x86ClangCflags), " "))
    114 	pctx.StaticVariable("X86ClangLdflags", strings.Join(ClangFilterUnknownCflags(x86Ldflags), " "))
    115 	pctx.StaticVariable("X86ClangLldflags", strings.Join(ClangFilterUnknownCflags(x86Lldflags), " "))
    116 	pctx.StaticVariable("X86ClangCppflags", strings.Join(ClangFilterUnknownCflags(x86Cppflags), " "))
    117 
    118 	// Yasm flags
    119 	pctx.StaticVariable("X86YasmFlags", "-f elf32 -m x86")
    120 
    121 	// Extended cflags
    122 
    123 	// Architecture variant cflags
    124 	for variant, cflags := range x86ArchVariantCflags {
    125 		pctx.StaticVariable("X86"+variant+"VariantClangCflags",
    126 			strings.Join(ClangFilterUnknownCflags(cflags), " "))
    127 	}
    128 }
    129 
    130 type toolchainX86 struct {
    131 	toolchain32Bit
    132 	toolchainClangCflags string
    133 }
    134 
    135 func (t *toolchainX86) Name() string {
    136 	return "x86"
    137 }
    138 
    139 func (t *toolchainX86) GccRoot() string {
    140 	return "${config.X86GccRoot}"
    141 }
    142 
    143 func (t *toolchainX86) GccTriple() string {
    144 	return "x86_64-linux-android"
    145 }
    146 
    147 func (t *toolchainX86) GccVersion() string {
    148 	return x86GccVersion
    149 }
    150 
    151 func (t *toolchainX86) IncludeFlags() string {
    152 	return "${config.X86IncludeFlags}"
    153 }
    154 
    155 func (t *toolchainX86) ClangTriple() string {
    156 	return "i686-linux-android"
    157 }
    158 
    159 func (t *toolchainX86) ToolchainClangLdflags() string {
    160 	return "${config.X86ToolchainLdflags}"
    161 }
    162 
    163 func (t *toolchainX86) ToolchainClangCflags() string {
    164 	return t.toolchainClangCflags
    165 }
    166 
    167 func (t *toolchainX86) ClangCflags() string {
    168 	return "${config.X86ClangCflags}"
    169 }
    170 
    171 func (t *toolchainX86) ClangCppflags() string {
    172 	return "${config.X86ClangCppflags}"
    173 }
    174 
    175 func (t *toolchainX86) ClangLdflags() string {
    176 	return "${config.X86Ldflags}"
    177 }
    178 
    179 func (t *toolchainX86) ClangLldflags() string {
    180 	return "${config.X86Lldflags}"
    181 }
    182 
    183 func (t *toolchainX86) YasmFlags() string {
    184 	return "${config.X86YasmFlags}"
    185 }
    186 
    187 func (toolchainX86) LibclangRuntimeLibraryArch() string {
    188 	return "i686"
    189 }
    190 
    191 func x86ToolchainFactory(arch android.Arch) Toolchain {
    192 	toolchainClangCflags := []string{
    193 		"${config.X86ToolchainCflags}",
    194 		"${config.X86" + arch.ArchVariant + "VariantClangCflags}",
    195 	}
    196 
    197 	for _, feature := range arch.ArchFeatures {
    198 		toolchainClangCflags = append(toolchainClangCflags, x86ArchFeatureCflags[feature]...)
    199 	}
    200 
    201 	return &toolchainX86{
    202 		toolchainClangCflags: strings.Join(toolchainClangCflags, " "),
    203 	}
    204 }
    205 
    206 func init() {
    207 	registerToolchainFactory(android.Android, android.X86, x86ToolchainFactory)
    208 }
    209