ref: 531272addf291dc18b1b02a53e2fe8eea8774f64
parent: 96cd94f4d8de6ab57ff45382f12c740b062d8a21
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Tue Dec 19 03:27:42 EST 2017
[as] Keep relative order of instruction with same verb The order is important, because there are several ways to implement an instruction, but not always they have the same performance, so the table has to be built with an order that ensure the correct seletion of instructions. The order in sort of lines that are equal is unspecified, so we have to add a workaround to ensure that the order is not modified. This workaround basically insert a new field that is the Number of record which can be used later to enure the correct order.
--- a/as/target/amd64/target.mk
+++ b/as/target/amd64/target.mk
@@ -7,7 +7,8 @@
set -e ;\
rm -f $@;\
trap "rm -f $$$$.c" 0 2 3; \
- sort -k1 target/x86/x86.dat | \
+ awk '!/^$$/ {print $$1,NR,$$2,$$3,$$4,$$5,$$6}' target/x86/x86.dat | \
+ sort -k1 -k2n | \
awk -v cpu=BITS64 -v family=x86 \
-f target/gen.awk > $$$$.c && mv $$$$.c $@
--- a/as/target/gen.awk
+++ b/as/target/gen.awk
@@ -1,6 +1,5 @@
BEGIN {
- FS = "\t"
printf "#include \"../../../inc/scc.h\"\n"\
"#include \"../../as.h\"\n"\
"#include \"../" family "/proc.h\"\n"
@@ -11,11 +10,11 @@
regex[++nregs] = $1
value[nregs] = $2
}
- close "target/rules.awk"
+ close("target/rules.awk")
}
{sub(/#.*/,"")}
-$6 !~ cpu {next}
+$7 !~ cpu {next}
/^$/ {next}
@@ -25,11 +24,11 @@
opnames[nop++] = $1
}
opcount[$1]++
- opargs[nvar] = $2
- opsize[nvar] = $3
- opbytes[nvar] = ($4 == "none") ? "" : $4
- opformat[nvar++] = $5
- formats[$5] = 1
+ opargs[nvar] = $3
+ opsize[nvar] = $4
+ opbytes[nvar] = ($5 == "none") ? "" : $5
+ opformat[nvar++] = $6
+ formats[$6] = 1
}
END {
--- a/as/target/i386/target.mk
+++ b/as/target/i386/target.mk
@@ -7,7 +7,8 @@
set -e ;\
rm -f $@;\
trap "rm -f $$$$.c" 0 2 3; \
- sort -k1 target/x86/x86.dat | \
+ awk '!/^$$/ {print $$1,NR,$$2,$$3,$$4,$$5,$$6}' target/x86/x86.dat | \
+ sort -k1 -k2n | \
awk -v cpu=BITS32 -v family=x86 \
-f target/gen.awk > $$$$.c && mv $$$$.c $@
--- a/as/target/z80/target.mk
+++ b/as/target/z80/target.mk
@@ -7,7 +7,8 @@
set -e ;\
rm -f $@;\
trap "rm -f $$$$.c" 0 2 3; \
- sort -k1 target/x80/x80.dat | \
+ awk '!/^$$/ {print $$1,NR,$$2,$$3,$$4,$$5,$$6}' target/x80/x80.dat | \
+ sort -k1 -k2n | \
awk -v cpu=Z80 -v family=x80 \
-f target/gen.awk > $$$$.c && mv $$$$.c $@