Skip to content

Commit 7861a25

Browse files
authored
Merge emsdk_cflags helper function. NFC (#20710)
The name of this is function and the fact the it a separate are purely legacy. Prior to this change we were skipping the SIMD defined such as -D__SSE2__ when `-nostdinc` was specified.
1 parent b86cf40 commit 7861a25

File tree

1 file changed

+37
-44
lines changed

1 file changed

+37
-44
lines changed

emcc.py

Lines changed: 37 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -924,47 +924,6 @@ def parse_s_args(args):
924924
return (settings_changes, newargs)
925925

926926

927-
def emsdk_cflags(user_args):
928-
cflags = ['--sysroot=' + cache.get_sysroot(absolute=True)]
929-
930-
def array_contains_any_of(hay, needles):
931-
for n in needles:
932-
if n in hay:
933-
return True
934-
935-
if array_contains_any_of(user_args, SIMD_INTEL_FEATURE_TOWER) or array_contains_any_of(user_args, SIMD_NEON_FLAGS):
936-
if '-msimd128' not in user_args and '-mrelaxed-simd' not in user_args:
937-
exit_with_error('Passing any of ' + ', '.join(SIMD_INTEL_FEATURE_TOWER + SIMD_NEON_FLAGS) + ' flags also requires passing -msimd128 (or -mrelaxed-simd)!')
938-
cflags += ['-D__SSE__=1']
939-
940-
if array_contains_any_of(user_args, SIMD_INTEL_FEATURE_TOWER[1:]):
941-
cflags += ['-D__SSE2__=1']
942-
943-
if array_contains_any_of(user_args, SIMD_INTEL_FEATURE_TOWER[2:]):
944-
cflags += ['-D__SSE3__=1']
945-
946-
if array_contains_any_of(user_args, SIMD_INTEL_FEATURE_TOWER[3:]):
947-
cflags += ['-D__SSSE3__=1']
948-
949-
if array_contains_any_of(user_args, SIMD_INTEL_FEATURE_TOWER[4:]):
950-
cflags += ['-D__SSE4_1__=1']
951-
952-
# Handle both -msse4.2 and its alias -msse4.
953-
if array_contains_any_of(user_args, SIMD_INTEL_FEATURE_TOWER[5:]):
954-
cflags += ['-D__SSE4_2__=1']
955-
956-
if array_contains_any_of(user_args, SIMD_INTEL_FEATURE_TOWER[7:]):
957-
cflags += ['-D__AVX__=1']
958-
959-
if array_contains_any_of(user_args, SIMD_NEON_FLAGS):
960-
cflags += ['-D__ARM_NEON__=1']
961-
962-
if not settings.USE_SDL:
963-
cflags += ['-Xclang', '-iwithsysroot' + os.path.join('/include', 'fakesdl')]
964-
965-
return cflags + ['-Xclang', '-iwithsysroot' + os.path.join('/include', 'compat')]
966-
967-
968927
def get_target_flags():
969928
return ['-target', shared.get_llvm_target()]
970929

@@ -1020,6 +979,7 @@ def get_cflags(user_args, is_cxx):
1020979
# Flags we pass to the compiler when building C/C++ code
1021980
# We add these to the user's flags (newargs), but not when building .s or .S assembly files
1022981
cflags = get_clang_flags(user_args)
982+
cflags.append('--sysroot=' + cache.get_sysroot(absolute=True))
1023983

1024984
if settings.EMSCRIPTEN_TRACING:
1025985
cflags.append('-D__EMSCRIPTEN_TRACING__=1')
@@ -1048,10 +1008,43 @@ def get_cflags(user_args, is_cxx):
10481008

10491009
ports.add_cflags(cflags, settings)
10501010

1051-
if '-nostdinc' in user_args:
1052-
return cflags
1011+
def array_contains_any_of(hay, needles):
1012+
for n in needles:
1013+
if n in hay:
1014+
return True
1015+
1016+
if array_contains_any_of(user_args, SIMD_INTEL_FEATURE_TOWER) or array_contains_any_of(user_args, SIMD_NEON_FLAGS):
1017+
if '-msimd128' not in user_args and '-mrelaxed-simd' not in user_args:
1018+
exit_with_error('Passing any of ' + ', '.join(SIMD_INTEL_FEATURE_TOWER + SIMD_NEON_FLAGS) + ' flags also requires passing -msimd128 (or -mrelaxed-simd)!')
1019+
cflags += ['-D__SSE__=1']
1020+
1021+
if array_contains_any_of(user_args, SIMD_INTEL_FEATURE_TOWER[1:]):
1022+
cflags += ['-D__SSE2__=1']
1023+
1024+
if array_contains_any_of(user_args, SIMD_INTEL_FEATURE_TOWER[2:]):
1025+
cflags += ['-D__SSE3__=1']
1026+
1027+
if array_contains_any_of(user_args, SIMD_INTEL_FEATURE_TOWER[3:]):
1028+
cflags += ['-D__SSSE3__=1']
1029+
1030+
if array_contains_any_of(user_args, SIMD_INTEL_FEATURE_TOWER[4:]):
1031+
cflags += ['-D__SSE4_1__=1']
1032+
1033+
# Handle both -msse4.2 and its alias -msse4.
1034+
if array_contains_any_of(user_args, SIMD_INTEL_FEATURE_TOWER[5:]):
1035+
cflags += ['-D__SSE4_2__=1']
1036+
1037+
if array_contains_any_of(user_args, SIMD_INTEL_FEATURE_TOWER[7:]):
1038+
cflags += ['-D__AVX__=1']
1039+
1040+
if array_contains_any_of(user_args, SIMD_NEON_FLAGS):
1041+
cflags += ['-D__ARM_NEON__=1']
1042+
1043+
if '-nostdinc' not in user_args:
1044+
if not settings.USE_SDL:
1045+
cflags += ['-Xclang', '-iwithsysroot' + os.path.join('/include', 'fakesdl')]
1046+
cflags += ['-Xclang', '-iwithsysroot' + os.path.join('/include', 'compat')]
10531047

1054-
cflags += emsdk_cflags(user_args)
10551048
return cflags
10561049

10571050

0 commit comments

Comments
 (0)