1#
2#             Copyright Andrey Semashev 2020.
3# Distributed under the Boost Software License, Version 1.0.
4#    (See accompanying file LICENSE_1_0.txt or copy at
5#          http://www.boost.org/LICENSE_1_0.txt)
6#
7# This jamfile contains utility rules to select architecture-specific compiler flags
8
9import common ;
10import feature ;
11import configure ;
12
13rule deduce-architecture ( properties * )
14{
15    local architecture = [ feature.get-values "architecture" : $(properties) ] ;
16    if $(architecture)
17    {
18        return $(architecture) ;
19    }
20    else
21    {
22        if [ configure.builds /boost/architecture//x86 : $(properties) : "x86" ]
23        {
24            return x86 ;
25        }
26        else if [ configure.builds /boost/architecture//arm : $(properties) : "arm" ]
27        {
28            return arm ;
29        }
30        else if [ configure.builds /boost/architecture//mips1 : $(properties) : "mips1" ]
31        {
32            return mips1 ;
33        }
34        else if [ configure.builds /boost/architecture//power : $(properties) : "power" ]
35        {
36            return power ;
37        }
38        else if [ configure.builds /boost/architecture//sparc : $(properties) : "sparc" ]
39        {
40            return sparc ;
41        }
42    }
43}
44
45rule deduce-address-model ( properties * )
46{
47    local address_model = [ feature.get-values "address-model" : $(properties) ] ;
48    if $(address_model)
49    {
50        return $(address_model) ;
51    }
52    else
53    {
54        if [ configure.builds /boost/architecture//32 : $(properties) : "32-bit" ]
55        {
56            return 32 ;
57        }
58        else if [ configure.builds /boost/architecture//64 : $(properties) : "64-bit" ]
59        {
60            return 64 ;
61        }
62    }
63}
64
65rule sse2-flags ( properties * )
66{
67    local result ;
68
69    if <toolset>intel in $(properties)
70    {
71        if <toolset-intel:platform>win in $(properties)
72        {
73            result = <cxxflags>"/QxSSE2" ;
74        }
75        else
76        {
77            result = <cxxflags>"-xSSE2" ;
78        }
79    }
80    else if <toolset>msvc in $(properties)
81    {
82        # MSVC doesn't really care about these switches, all SSE intrinsics are always available, but still...
83        # Also 64 bit MSVC doesn't have the /arch:SSE2 switch as it is the default.
84        if 32 in [ deduce-address-model $(properties) ]
85        {
86            result = <cxxflags>"/arch:SSE2" ;
87        }
88    }
89    else
90    {
91        result = <cxxflags>"-msse -msse2" ;
92    }
93
94    return $(result) ;
95}
96
97rule sse41-flags ( properties * )
98{
99    local result ;
100
101    if <toolset>intel in $(properties)
102    {
103        if <toolset-intel:platform>win in $(properties)
104        {
105            result = <cxxflags>"/QxSSE4.1" ;
106        }
107        else
108        {
109            result = <cxxflags>"-xSSE4.1" ;
110        }
111    }
112    else if <toolset>msvc in $(properties)
113    {
114        # MSVC doesn't really care about these switches, all SSE intrinsics are always available, but still...
115        # Also 64 bit MSVC doesn't have the /arch:SSE2 switch as it is the default.
116        if 32 in [ deduce-address-model $(properties) ]
117        {
118            result = <cxxflags>"/arch:SSE2" ;
119        }
120    }
121    else
122    {
123        result = <cxxflags>"-msse -msse2 -msse3 -mssse3 -msse4.1" ;
124    }
125
126    return $(result) ;
127}
128