From 0362d0c9d710c6b541ad7bdf2e6ef6f11b73cec1 Mon Sep 17 00:00:00 2001 From: Matt Turner Date: Sat, 21 Mar 2009 18:26:50 +0000 Subject: Rework slotting struct git-svn-id: svn://mattst88.com/svn/annotator/trunk@2 b9d43f0c-d947-41e4-9d27-581b740e5c48 --- src/determine_slotting.c | 181 ++++++++++++++++++++++++----------------------- 1 file changed, 93 insertions(+), 88 deletions(-) (limited to 'src/determine_slotting.c') diff --git a/src/determine_slotting.c b/src/determine_slotting.c index f366433..32d6927 100644 --- a/src/determine_slotting.c +++ b/src/determine_slotting.c @@ -1,99 +1,104 @@ +#include + #define SLOT_E 'E' #define SLOT_U 'U' #define SLOT_L 'L' +#define CLUSTER_0 0 +#define CLUSTER_1 1 + #if defined DEBUG && DEBUG == 1 #include -#define PRINT_DEBUG printf("%c%c%c%c\n", slot._3, slot._2, slot._1, slot._0) +#define PRINT_DEBUG printf("%c%c%c%c\n", octaword.instr[3].slot, octaword.instr[2].slot, octaword.instr[1].slot, octaword.instr[0].slot) #define RULE1() \ - slot._3 = 'U'; \ - slot._2 = 'U'; \ - slot._1 = 'U'; \ - slot._0 = 'U' + octaword.instr[3].slot = 'U'; \ + octaword.instr[2].slot = 'U'; \ + octaword.instr[1].slot = 'U'; \ + octaword.instr[0].slot = 'U' #define RULE2() \ - slot._3 = 'E'; \ - slot._2 = 'U'; \ - slot._1 = 'U'; \ - slot._0 = 'U' + octaword.instr[3].slot = 'E'; \ + octaword.instr[2].slot = 'U'; \ + octaword.instr[1].slot = 'U'; \ + octaword.instr[0].slot = 'U' #define RULE3() \ - slot._3 = 'U'; \ - slot._2 = 'U'; \ - slot._1 = 'E'; \ - slot._0 = 'L' + octaword.instr[3].slot = 'U'; \ + octaword.instr[2].slot = 'U'; \ + octaword.instr[1].slot = 'E'; \ + octaword.instr[0].slot = 'L' #define RULE3B() \ - slot._3 = 'E'; \ - slot._2 = 'E'; \ - slot._1 = 'L'; \ - slot._0 = 'L' + octaword.instr[3].slot = 'E'; \ + octaword.instr[2].slot = 'E'; \ + octaword.instr[1].slot = 'L'; \ + octaword.instr[0].slot = 'L' #define RULE4C() \ - slot._3 = 'E'; \ - slot._2 = 'E'; \ - slot._1 = 'E'; \ - slot._0 = 'U' + octaword.instr[3].slot = 'E'; \ + octaword.instr[2].slot = 'E'; \ + octaword.instr[1].slot = 'E'; \ + octaword.instr[0].slot = 'U' #define RULE4A() \ - slot._3 = 'E'; \ - slot._2 = 'L'; \ - slot._1 = 'E'; \ - slot._0 = 'U' + octaword.instr[3].slot = 'E'; \ + octaword.instr[2].slot = 'L'; \ + octaword.instr[1].slot = 'E'; \ + octaword.instr[0].slot = 'U' #define RULE4AD() \ - slot._3 = 'U'; \ - slot._2 = 'L'; \ - slot._1 = 'E'; \ - slot._0 = 'E' + octaword.instr[3].slot = 'U'; \ + octaword.instr[2].slot = 'L'; \ + octaword.instr[1].slot = 'E'; \ + octaword.instr[0].slot = 'E' #define RULE4CD() \ - slot._3 = 'E'; \ - slot._2 = 'E'; \ - slot._1 = 'E'; \ - slot._0 = 'E' + octaword.instr[3].slot = 'E'; \ + octaword.instr[2].slot = 'E'; \ + octaword.instr[1].slot = 'E'; \ + octaword.instr[0].slot = 'E' #endif /* DEBUG */ -struct slotting_t +struct octaword_t { - int _3; - int _2; - int _1; - int _0; + struct { + uint8_t slot; + uint8_t cluster; + } instr[4]; }; static inline int -number_slotted(struct slotting_t slot, int which) +number_slotted(struct octaword_t octaword, uint8_t which) { int num = 0; + int i; - if (slot._3 == which) ++num; - if (slot._2 == which) ++num; - if (slot._1 == which) ++num; - if (slot._0 == which) ++num; + for (i = 0; i < 4; i++) { + if (octaword.instr[i].slot == which) ++num; + } return num; } -static inline struct slotting_t -replace_E_with(struct slotting_t slot, int which) +static inline struct octaword_t +replace_E_with(struct octaword_t octaword, uint8_t which) { - if (slot._3 == SLOT_E) slot._3 = which; - if (slot._2 == SLOT_E) slot._2 = which; - if (slot._1 == SLOT_E) slot._1 = which; - if (slot._0 == SLOT_E) slot._0 = which; + if (octaword.instr[3].slot == SLOT_E) octaword.instr[3].slot = which; + if (octaword.instr[2].slot == SLOT_E) octaword.instr[2].slot = which; + if (octaword.instr[1].slot == SLOT_E) octaword.instr[1].slot = which; + if (octaword.instr[0].slot == SLOT_E) octaword.instr[0].slot = which; - return slot; + return octaword; } -struct slotting_t -determine_slotting(struct slotting_t slot) +struct octaword_t +determine_slotting(struct octaword_t octaword) { - int slotted_E = number_slotted(slot, SLOT_E); + int slotted_E = number_slotted(octaword, SLOT_E); /* Ebox slotting rules; Compiler Writer's Guide for the Alpha 21264, pg 69 * A.1 Rule 1 - Four of a Kind @@ -102,7 +107,7 @@ determine_slotting(struct slotting_t slot) */ if (slotted_E == 0) { - return slot; + return octaword; } /* Ebox slotting rules; Compiler Writer's Guide for the Alpha 21264, pg 69-70 @@ -113,10 +118,10 @@ determine_slotting(struct slotting_t slot) * if and only if two instructions are slotted U, * then the classification is honored and the other instructions are slotted L. */ - if ((number_slotted(slot, SLOT_U) == 3) - || (number_slotted(slot, SLOT_U) == 2)) + if ((number_slotted(octaword, SLOT_U) == 3) + || (number_slotted(octaword, SLOT_U) == 2)) { - return replace_E_with(slot, SLOT_L); + return replace_E_with(octaword, SLOT_L); } /* Ebox slotting rules; Compiler Writer's Guide for the Alpha 21264, pg 70 @@ -127,10 +132,10 @@ determine_slotting(struct slotting_t slot) * if and only if two instructions are slotted L, * then the classification is honored and the other instructions are slotted U. */ - if ((number_slotted(slot, SLOT_L) == 3) - || (number_slotted(slot, SLOT_L) == 2)) + if ((number_slotted(octaword, SLOT_L) == 3) + || (number_slotted(octaword, SLOT_L) == 2)) { - return replace_E_with(slot, SLOT_U); + return replace_E_with(octaword, SLOT_U); } /* Ebox slotting rules; Compiler Writer's Guide for the Alpha 21264, pg 70 @@ -138,43 +143,43 @@ determine_slotting(struct slotting_t slot) * if both instructions in the second quadword are slotted E, * then the first is slotted L and the second slotted U. */ - if ((slot._3 == SLOT_E) && (slot._2 == SLOT_E)) + if ((octaword.instr[3].slot == SLOT_E) && (octaword.instr[2].slot == SLOT_E)) { - slot._3 = SLOT_U; - slot._2 = SLOT_L; + octaword.instr[3].slot = SLOT_U; + octaword.instr[2].slot = SLOT_L; slotted_E -= 2; } if (slotted_E == 0) { - return slot; + return octaword; } /* check low quad for single U */ - if ((slot._1 == SLOT_U) != (slot._0 == SLOT_U)) + if ((octaword.instr[1].slot == SLOT_U) != (octaword.instr[0].slot == SLOT_U)) { - if (slot._0 == SLOT_E) + if (octaword.instr[0].slot == SLOT_E) { - slot._0 = SLOT_L; + octaword.instr[0].slot = SLOT_L; } else { - slot._1 = SLOT_L; + octaword.instr[1].slot = SLOT_L; } --slotted_E; } /* check low quad for single L */ - else if ((slot._1 == SLOT_L) != (slot._0 == SLOT_L)) + else if ((octaword.instr[1].slot == SLOT_L) != (octaword.instr[0].slot == SLOT_L)) { - if (slot._0 == SLOT_E) + if (octaword.instr[0].slot == SLOT_E) { - slot._0 = SLOT_U; + octaword.instr[0].slot = SLOT_U; } else { - slot._1 = SLOT_U; + octaword.instr[1].slot = SLOT_U; } --slotted_E; @@ -182,7 +187,7 @@ determine_slotting(struct slotting_t slot) if (slotted_E == 0) { - return slot; + return octaword; } #if defined DEBUG && DEBUG == 1 @@ -190,29 +195,29 @@ determine_slotting(struct slotting_t slot) #endif /* check high quad for single U */ - if ((slot._3 == SLOT_U) != (slot._2 == SLOT_U)) + if ((octaword.instr[3].slot == SLOT_U) != (octaword.instr[2].slot == SLOT_U)) { - if (slot._2 == SLOT_E) + if (octaword.instr[2].slot == SLOT_E) { - slot._2 = SLOT_L; + octaword.instr[2].slot = SLOT_L; } - else if (slot._3 == SLOT_E) + else if (octaword.instr[3].slot == SLOT_E) { - slot._3 = SLOT_L; + octaword.instr[3].slot = SLOT_L; } --slotted_E; } /* check high quad for single L */ - else if ((slot._3 == SLOT_L) != (slot._2 == SLOT_L)) + else if ((octaword.instr[3].slot == SLOT_L) != (octaword.instr[2].slot == SLOT_L)) { - if (slot._2 == SLOT_E) + if (octaword.instr[2].slot == SLOT_E) { - slot._2 = SLOT_U; + octaword.instr[2].slot = SLOT_U; } - else if (slot._3 == SLOT_E) + else if (octaword.instr[3].slot == SLOT_E) { - slot._3 = SLOT_U; + octaword.instr[3].slot = SLOT_U; } --slotted_E; @@ -225,16 +230,16 @@ determine_slotting(struct slotting_t slot) /* if we reach here the only possibility is two Es in the low quad */ if (slotted_E != 0) { - slot._1 = slot._3; - slot._0 = slot._2; + octaword.instr[1].slot = octaword.instr[3].slot; + octaword.instr[0].slot = octaword.instr[2].slot; } - return slot; + return octaword; } #if defined DEBUG && DEBUG == 1 int main() { - struct slotting_t slot; + struct octaword_t octaword; // RULE3(); // RULE3B(); @@ -245,7 +250,7 @@ int main() { PRINT_DEBUG; - slot = determine_slotting(slot); + octaword = determine_slotting(octaword); PRINT_DEBUG; -- cgit v1.2.3