Created
December 17, 2023 22:17
-
-
Save altmind/ee2c0ecfe51149d234000fc8ad432330 to your computer and use it in GitHub Desktop.
gcc march compile options
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import re | |
import subprocess | |
def get_supported_marches(): | |
# gcc -c -Q -march=native --help=target | |
res = subprocess.getoutput("gcc -c -Q -march=native --help=target") | |
match = re.search(r" valid arguments for -march= option:\W*([^\r\n]+)", res, re.DOTALL) | |
if match: | |
return re.split(r"\s+", match.group(1), 0) | |
else: | |
return None | |
def get_opts(march): | |
res = subprocess.getoutput(f"gcc -c -Q -march={march} --help=target") | |
# res = subprocess.getoutput(f"gcc -march={march} -E -v - </dev/null 2>&1 | grep cc1") | |
opts = {} | |
match = re.search(" target specific:[\r\n]*(.*?)[\r\n] *Known ", res, re.DOTALL) | |
excpt = ["-march=", "-masm=", "-mtune="] # "-malign-functions=", "-malign-jumps=", "-malign-loops=", | |
if match: | |
for match in re.finditer(r"^\s+([\S]+)[ \t]*(\S*)$", match.group(1), re.MULTILINE): | |
if (match.group(1) not in excpt): | |
opts[match.group(1)] = match.group(2) | |
return opts | |
else: | |
return None | |
def get_version(): | |
res = subprocess.getoutput("gcc -v 2>&1| grep \"gcc version\"") | |
if len(res) < 10: | |
raise Exception("gcc not found") | |
else: | |
return res | |
if __name__ == '__main__': | |
ver = get_version() | |
marches = get_supported_marches() | |
# print(marches) | |
all_opts = [] | |
all_march_opts = {} | |
for march in marches: | |
# print(march) | |
mopts = get_opts(march) | |
all_march_opts[march] = mopts | |
# print(mopts) | |
for (k, v) in mopts.items(): | |
if k not in all_opts: | |
all_opts.append(k) | |
print( | |
"<script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.slim.min.js'></script>" | |
f"<b>{ver}</b>" | |
"""<input type="checkbox" id="tblhidesame"/><label for="tblhidesame">Hide Same</label><br>""" | |
"""<script> | |
$('#tblhidesame').change(function () { | |
var show = !$(this).is(":checked"); | |
var $table = $('.gcctbl'); | |
$table.find('thead td').each(function (index) { | |
var vals = new Set(); | |
$table.find('tbody tr td:nth-child(' + index + ')').each(function () { | |
vals.add($(this).text()); | |
}); | |
console.log($(this).text(), vals, vals.size > 1 || show) | |
$table.find('tr td:nth-child(' + index + ')').each(function () { | |
if (vals.size > 1 || show) | |
$(this).show(); | |
else | |
$(this).hide(); | |
}); | |
}); | |
}) | |
</script>""") | |
print( | |
"<style>" | |
".gcctbl {padding:2px 4px; border-collapse:collapse; position: relative} " | |
".gcctbl td {border:1px solid gray; white-space: nowrap} " | |
".gcctbl thead td {font-weight:bold; text-align:center; white-space:nowrap; position: sticky; top: 0; background-color: rgba(200, 200, 200, 0.8);} " | |
".gcctbl .green {background-color:lime} " | |
".gcctbl .red {background-color:pink} " | |
".archname {text-align: right; font-weight:bold; position:sticky; left: 0; background-color: rgba(200, 200, 200, 0.8); } " | |
".valempty {background-color:gray;}" | |
"</style>") | |
print("<table class='gcctbl'><thead><tr><td>Arch</td>") | |
for x in all_opts: | |
print(f"<td>{x}</td>") | |
print("</tr></thead>\n<tbody>") | |
for (k, v) in all_march_opts.items(): | |
print(f"<tr><td class='archname'>{k}</td>") | |
for opt in all_opts: | |
val = "---" | |
if (opt in v): | |
val = v[opt] | |
if val == "[enabled]": | |
print(f"<td class='green'>{v[opt]}</td>") | |
elif val == "[disabled]": | |
print(f"<td class='red'>{v[opt]}</td>") | |
else: | |
print("<td>" + v[opt] + "</td>") | |
else: | |
print("<td class='valempty'></td>") | |
print("</tr>\n") | |
print("</tbody></table>") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment