57 #if ETISS_USE_BYTESWAP_H
71 return static_cast<char *
>(
static_cast<void *
>(
d_));
83 #if ETISS_USE_BYTESWAP_H
84 if (
sizeof(
I) == alignment)
92 d_[i] = __bswap_32(
d_[i]);
110 if (
sizeof(
I) == alignment)
116 for (
unsigned j = 0; j < (
sizeof(
I) >> 1); j++)
120 ((
int8_t *)&(
d_[i]))[
sizeof(
I) - 1 - j] = tmp;
135 unsigned mod = size() % (8);
136 unsigned ret = (size() - mod) / (8);
141 unsigned mod = size() % (
sizeof(
I) * 8);
142 unsigned ret = (size() - mod) / (
sizeof(
I) * 8);
149 std::vector<BitArray>
results{input};
151 for(
const auto& i : indexes){
152 for(
int j=0; j<(1<<count); j++){
177 ret.resize(end-start+1);
182 auto len = end - start + 1;
185 (*
this)[i+start] = range[i];
191 boost::to_string(*
this,
s);
196 : startpos(startindex_included), endpos(endindex_included) {}
200 assert(ba.size() >= (
endpos - startpos + 1) &&
"BitArrayRange outside of BitArray");
202 return range.to_ulong();
207 assert(ba.size() >= (
endpos - startpos + 1) &&
"BitArrayRange outside of BitArray");
226 throw std::runtime_error(
"etiss::instr::OPCode constructed with code and mask of different widths");
229 if (!((code & mask) == code))
250 if ((o1 == 0) || (o2 == 0))
258 return (*o1) < (*o2);
267 : builtinGroups_(0), printer_(printASMSimple), width(opc.code_.size()), opc_(opc), name_(name)
272 std::stringstream ss;
273 ss << instr.
name_ <<
" # 0x" << ba <<
" [UNKNOWN PARAMETERS]";
279 std::stringstream ss;
281 ss << indent <<
"@0x" << std::hex << std::setw(pfillwidth) << pos << std::dec <<
" Instruction: " <<
name_ <<
"\n";
285 uint32_t builtinGroups,
const std::set<uint32_t> &groups)
294 for (
auto iter = groups.begin(); iter != groups.end(); iter++)
310 for (
auto iter = groups.begin(); iter != groups.end(); iter++)
316 std::set<uint32_t>>(callback, builtinGroups, groups));
325 ok = ok & std::get<0>(*iter)(ba, cs, context);
352 : parent_(parent), name_(name), width_(width), chunk_size(c_size), root_(nullptr), invalid(width, -1, -1,
"INVALID")
404 if (
instrmap_.insert(std::pair<const OPCode *, Instruction *>(&ret->
opc_, ret)).second ==
false)
406 etiss::log(
ERROR,
"Failed to add instruction to instrmap_.", name, *
this);
421 std::vector<size_type> indexes;
424 BitArray code = op2instr.first->code_;
425 BitArray mask = op2instr.first->mask_;
433 for (
size_type j = 0; j < chunk_bits_mask.size(); ++j)
434 if (!chunk_bits_mask[j]) indexes.push_back(j);
442 for(
const auto& permutated_chunk : permutated_chunk_codes){
443 auto val = permutated_chunk.to_ulong();
444 root_[i][val].insert(inst);
453 std::set<Instruction*>
results;
457 auto val = chunk_bits_code.to_ulong();
459 auto instrs_in_node =
root_[i][val];
461 if(i==0)
results = instrs_in_node;
463 std::set<Instruction*> results_o;
465 instrs_in_node.begin(), instrs_in_node.end(),
466 std::inserter(results_o, results_o.begin()));
471 if(
results.empty())
return nullptr;
479 [](
const Instruction* lhs,
const Instruction* rhs) { return lhs->opc_.mask_.count() < rhs->opc_.mask_.count();});
486 if (
root_ !=
nullptr)
488 std::stringstream ss;
508 if (iter->second !=
nullptr)
527 VariableInstructionSet::VariableInstructionSet(
ModedInstructionSet &parent,
unsigned width,
const std::string &archname)
528 : parent_(parent), width_(width), archname_(archname)
531 con.is_not_default_width_ =
false;
532 con.instr_width_ =
width_;
538 for (
auto iter =
ismap_.begin(); iter !=
ismap_.end(); iter++)
549 if (iter->second->size() <= 0)
556 ok = ok & iter->second->compile();
593 for (
auto iter =
ismap_.begin(); iter !=
ismap_.end(); iter++)
595 if (iter->second !=
nullptr)
597 call(*(iter->second));
608 std::stringstream ss;
615 ModedInstructionSet::ModedInstructionSet(
const std::string &name) : archname_(name) {}
616 ModedInstructionSet::~ModedInstructionSet()
637 if (f->second->width_ != width)
670 "variable instruction set mode cannot be found since this moded instruction set is not its parent");
678 if (iter->second !=
nullptr)
680 call(*(iter->second));
699 std::stringstream ss;
703 ss << vis.
print(prefix +
"\t");
713 klass.
addTo(vis, ok);
729 if (instr ==
nullptr)
732 etiss::log(
ERROR,
"failed to add InstructionDefinition to Instruction set.",
id, set);
735 id.addTo(*instr, ok);
748 etiss::log(
VERBOSE,
"Added instruction definition to instruction.", *
this, instr);
756 #if __cplusplus >= 201103L
764 return parse_i<uint32_t>(
s);
contains container classes to store instruction definitions + translation functions and build a trans...
#define etiss_log(LEVEL, MSG)
__device__ __2f16 float bool s
static __inline__ uint32_t
BitArray::size_type end()
lowest bit of the range (included).
BitArray::size_type start()
highest bit of the range (included)
etiss_del_como(BitArrayRange) private BitArray::size_type endpos
void write(BitArray &ba, I val)
write the bit from the passed value starting at the lsb to the range.
I read(const BitArray &ba)
reads bits from the range to the return value starting at the lsb.
BitArrayRange(unsigned endindex_included, unsigned startindex_included)
static std::vector< BitArray > permutate(const BitArray &input, std::vector< size_type > indexes)
permutates the given input at the specified indexes.
void set_value(size_type width, unsigned long value)
change the value the object is holding
BitArray get_range(size_type end, size_type start) const
get the interval [end, start]
unsigned byteCount() const
std::string to_string() const
string representation of the BitArray
unsigned intCount() const
void set_range(unsigned long val, size_type end, size_type start)
set the value to the interval [end, start]
unsigned internalBufferSize()
char * internalBuffer()
get the internal buffer
void recoverFromEndianness(unsigned alignment, endian_t endianness)
changes byte positions as needed to resove endiannes incompabilities after using the internal buffer ...
maps to VariableInstructionSet
void addTo(VariableInstructionSet &set, bool &ok)
void addTo(ModedInstructionSet &set, bool &ok)
this class contains parameters that persist in between instruction lookpus/translation within a trans...
std::map< std::string, unsigned > ufields_
additional fields that can be used by any plugin/architecture.
unsigned & ufield(std::string name)
void addTo(Instruction &set, bool &ok)
const std::function< bool(BitArray &, etiss::CodeSet &, InstructionContext &)> callback_
const std::function< std::string(BitArray &, Instruction &)> ASMprinter_
const uint32_t builtinGroups_
void addTo(InstructionSet &set, bool &ok)
holds etiss::instr::Instruction instances and handles automatic instruction tree creation.
Instruction & getInvalid()
std::map< const OPCode *, Instruction *, etiss::instr::less > instrmap_
Instruction * get(const OPCode &key)
std::string print(std::string prefix, bool printunused=false)
Instruction * resolve(BitArray &instr)
void foreach(std::function< void(Instruction &)> func)
Instruction * create(const OPCode &key, const std::string &name)
Instruction & open(const OPCode &key, const std::string &name)
InstructionSet(VariableInstructionSet &parent, unsigned width, const std::string &name, unsigned c_size=4)
const unsigned chunk_size
holds information and translation callbacks for an instruction.
bool addCallback(std::function< bool(BitArray &, etiss::CodeSet &, InstructionContext &)> callback, uint32_t builtinGroups, const std::set< uint32_t > &groups=std::set< uint32_t >())
std::set< uint32_t > & presentGroups()
bool translate(BitArray &, CodeSet &cs, InstructionContext &context)
uint32_t & presentBuiltinGroups()
void setASMPrinter(std::function< std::string(BitArray &, Instruction &)> printer)
std::function< std::string(BitArray &, Instruction &)> printer_
static std::string printASMSimple(BitArray &ba, Instruction &instr)
Instruction(const OPCode &opc, const std::string &name)
virtual std::string print(std::string indent, I pos, unsigned pfillwidth, bool printunused=false)
std::string printASM(BitArray &)
std::set< uint32_t > groups_
std::list< std::tuple< std::function< bool(BitArray &, etiss::CodeSet &, InstructionContext &)>, uint32_t, std::set< uint32_t > > > callbacks_
holds etiss::instr::VariableInstructionSet instances for different modes.
std::string print(std::string prefix=std::string())
VariableInstructionSet * create(uint32_t mode, unsigned width, const std::string &name=std::string())
std::map< VariableInstructionSet *, uint32_t > invvismap_
VariableInstructionSet & open(uint32_t mode, unsigned width, const std::string &name=std::string())
const std::string archname_
uint32_t getMode(VariableInstructionSet *vis)
VariableInstructionSet * get(uint32_t mode)
std::map< uint32_t, VariableInstructionSet * > vismap_
void foreach(std::function< void(VariableInstructionSet &)> call)
defines the relevant bits and their value to identify an instruction.
OPCode(unsigned width, const T code, const T mask)
ctor that uses integral values for mask and code
bool operator<(const OPCode &o) const
comparison operator for map/sets.
holds etiss::instr::InstructionSet instances with different bit widths.
void foreach(std::function< void(InstructionSet &)> func)
~VariableInstructionSet()
InstructionSet & open(unsigned width, const std::string &name=std::string())
std::string print(std::string prefix=std::string())
InstructionSet * get(unsigned width)
const std::string archname_
std::map< unsigned, InstructionSet * > ismap_
InstructionSet * create(unsigned width, const std::string &name=std::string())
ModedInstructionSet & parent_
std::set< Instruction * > Node
Holding unique instruction sets code chunks after permutation.
BitArray::size_type size_type
uint32_t parse_i32(const char *s)
Page Table Entry (PTE) defines the composition of Page Frame Number (PFN) and relavant flags.
endian_t
Enumeration type for the endianness.
endian_t getEndianness()
evaluates the endianness of the current build as a constexpr.
void log(Verbosity level, std::string msg)
write log message at the given level.
bool operator()(const OPCode *const &o1, const OPCode *const &o2) const