[llvm-commits] CVS: reopt/lib/TraceCache/InstrUtils.cpp
Brian Gaeke
gaeke at cs.uiuc.edu
Mon Oct 20 12:38:01 PDT 2003
Changes in directory reopt/lib/TraceCache:
InstrUtils.cpp updated: 1.13 -> 1.14
---
Log message:
Get rid of some commented-out code and extra whitespace.
Get rid of the #ifdef __sparc__ all around the whole file; it's only needed for
doFlush().
Decorate hex constants with U, UL, ULL as necessary to avoid ambiguity.
Fix up some single-bit constants to use (1 << N) instead (more yet to do here).
Prefer hex constants to decimal constants (more yet to do here, too).
---
Diffs of the changes: (+22 -43)
Index: reopt/lib/TraceCache/InstrUtils.cpp
diff -u reopt/lib/TraceCache/InstrUtils.cpp:1.13 reopt/lib/TraceCache/InstrUtils.cpp:1.14
--- reopt/lib/TraceCache/InstrUtils.cpp:1.13 Fri Aug 22 12:43:42 2003
+++ reopt/lib/TraceCache/InstrUtils.cpp Mon Oct 20 12:36:55 2003
@@ -5,10 +5,6 @@
//
//===----------------------------------------------------------------------===//
-// This file can only be compiled for a Sparc V9 architecture.
-//
-#ifdef __sparc
-
#include "reopt/InstrUtils.h"
#include <cassert>
#include <iostream>
@@ -41,26 +37,26 @@
}
}
-
bool isNonDepJump(unsigned int y){//int + floating point
return ((y & 0xc1c00000) == 4194304 || (y & 0xc1c00000) == 20971520);
- // return ((y & 0x01c00000) == 4194304);
}
bool isDepJump(unsigned int y){ //integer+floatingpoint
return ((y & 0xc1c00000) == 8388608 || (y & 0xc1c00000) == 25165824);
- //return ((y & 0x01c00000) == 8388608);
}
uint64_t getNonDepJmpTarget(unsigned int y, uint64_t oldAdd){
- return (oldAdd+4*(((y&262144)==262144) ? ((y&0x0007ffff)|0xfffffffffff80000) : (y&0x0007ffff)));
+ return oldAdd + 4 * (((y&0x00040000)==0x00040000)
+ ? ((y&0x0007ffff)|0xfffffffffff80000ULL)
+ : (y&0x0007ffff));
}
uint64_t getDepJmpTarget(unsigned int y, uint64_t oldAdd){
- return (oldAdd+4*(((y&2097152)==2097152) ? ((y&0x003fffff)|0xffffffffffc00000) : (y&0x003fffff)));
+ return oldAdd + 4 * (((y&0x00200000U)==0x00200000U)
+ ? ((y&0x003fffff)|0xffffffffffc00000ULL)
+ : (y&0x003fffff));
}
-
unsigned int getUndepJumpInstr(unsigned int a, uint64_t to, uint64_t pc){
if(to>pc)
assert((to-pc)/4<262144 && "Can't fit target!");
@@ -68,69 +64,54 @@
assert((pc-to)/4<262144 && "Can't fit target!");
unsigned int diff = (((to-pc)/4)&0x3ffff);
- unsigned int sgn=0;
- if(to<pc)
- sgn = 262144;
- return ((a&0xfff80000)|diff|sgn);
+ unsigned int sgn = ((to < pc) ? (1 << 21) : 0);
+ return ((a&0xfff80000U)|diff|sgn);
}
-
-
unsigned int getDepJumpInstr(unsigned int a, uint64_t to, uint64_t pc){
- //assert((((to-pc)/4)&(2097151) < 2097152) && "Can't fit target!");
if(to>pc)
assert((to-pc)/4<2097152 && "Can't fit target!");
else
assert((pc-to)/4<2097152 && "Can't fit target!");
unsigned int diff = (((to-pc)/4)&0x1fffff);
- unsigned int sgn=0;
- if(to<pc)
- sgn = 2097152;
+ unsigned int sgn = ((to < pc) ? (1 << 21) : 0);
return ((a&0xffc00000)|diff|sgn);
}
-
uint64_t getBPRTarget(unsigned int b, uint64_t oldAdd){
- return (oldAdd+4*(((b&2097152)==2097152)?(0xffffffffffff0000|((b&3145728)>>6)|(b&16383)):(((b&3145728)>>6)|(b&16383))));
+ return (oldAdd+4*(((b&2097152)==2097152)?(0xffffffffffff0000ULL|((b&3145728)>>6)|(b&16383)):(((b&3145728)>>6)|(b&16383))));
}
unsigned int getBPRInstr(unsigned int b, uint64_t to, uint64_t frm){
-
if(to>frm)
assert((to-frm)/4 < 32768 && "Target out of range!");
else
assert((frm-to)/4 < 32768 && "Target out of range!");
//frame = 2^32-1-(2^21+2^20+2^14-1)
- unsigned int frame = b&4291805184;
+ unsigned int frame = b & 0xffcfc000U;
uint64_t target = (to-frm)/4;
- unsigned int hi = ((target & (2147483648))>>10)|((target&(16384))<<6);
- unsigned lo = target&(16383);
+ unsigned int hi = ((target & 0x80000000ULL)>>10) | ((target&(0x4000ULL))<<6);
+ unsigned int lo = (unsigned int) (target & 0x3FFFULL);
return (frame|hi|lo);
}
//TODO: put assert to check branch destinations!
//TODO: Take out sign bit in branch instr
-//unsigned int getDepJumpInstr(unsigned int a, uint64_t to, uint64_t pc){
-//return ((a&0xffc00000)|(((to-pc)/4)&0x003fffff));
-//}
-
-//unsigned int getUndepJumpInstr(unsigned int a, uint64_t to, uint64_t pc){
-//return ((a&0xfff80000)|(((to-pc)/4)&0x0007ffff));
-//}
bool isCallInstr(unsigned int a){
return ((a & 0xc0000000) == 0x40000000);
}
uint64_t getCallTarget(unsigned int y, uint64_t oldAdd){
- uint64_t toRet = (oldAdd + 4*(((y&536870912)==536870912)?(0xffffffffc0000000|(y&0x3fffffff)):(y&0x3fffffff)));
- //std::cerr<<"\t\t\tCall Target:"<<(void *)toRet<<"\n";
- return toRet;
+ return oldAdd + 4 * (((y&0x20000000) == 0x20000000)
+ ? (0xffffffffc0000000ULL | (y & 0x3fffffff))
+ : (y & 0x3fffffff));
}
+// pc is the "from" address
unsigned int getCallInstr(uint64_t to , uint64_t pc){
//check to-pc < 2^29
if(to>pc)
@@ -144,9 +125,6 @@
if(to<pc)
sgn = 536870912; //2^29
unsigned int inst = (0x40000000|diff|sgn);
- //std::cerr<<"to: "<<(void *)to<<"\t frm: "<<(void *)pc
- // <<"\t inst"<<(void *)inst<<"\n";
-
return inst;
}
@@ -168,16 +146,18 @@
}
void doFlush(uint64_t st_addr, uint64_t end_addr){
+#ifdef __sparc__
if(st_addr%8 != 0)
st_addr -=4;
for(uint64_t i = st_addr; i<=end_addr; i+=8){
asm("flush %0"::"r" (i));
}
+#else
+ assert (0 && "Sorry, doFlush is not implemented for this architecture");
+#endif // __sparc__
}
-
-unsigned int getInvertedBranch(unsigned int br1){
-
+unsigned int getInvertedBranch(unsigned int br1) {
assert(isBranchInstr(br1) && "Not a branch!");
unsigned int cond = 0;
@@ -222,4 +202,3 @@
((inst & 0xffffffff) == 0x81c7e008) ||
((inst & 0xffffffff) == 0x81c3e008));
}
-#endif
More information about the llvm-commits
mailing list