19#if ETISS_USE_BYTESWAP_H
33 return static_cast<char *
>(
static_cast<void *
>(
d_));
45#if ETISS_USE_BYTESWAP_H
46 if (
sizeof(
I) == alignment)
54 d_[i] = __bswap_32(
d_[i]);
72 if (
sizeof(
I) == alignment)
78 for (
unsigned j = 0; j < (
sizeof(
I) >> 1); j++)
82 ((
int8_t *)&(
d_[i]))[
sizeof(
I) - 1 - j] = tmp;
98 unsigned mod = size() % (8);
99 unsigned ret = (size() - mod) / (8);
106 unsigned mod = size() % (
sizeof(
I) * 8);
107 unsigned ret = (size() - mod) / (
sizeof(
I) * 8);
115 std::vector<BitArray> results{ input };
117 for (
const auto &i : indexes)
119 for (
int j = 0; j < (1 << count); j++)
121 results.push_back(results[j]);
123 results.push_back(results[j]);
125 results.erase(results.begin(), results.begin() + (1 << count));
147 ret.resize(end - start + 1);
153 auto len = end - start + 1;
156 (*
this)[i + start] = range[i];
162 boost::to_string(*
this,
s);
167 : startpos(startindex_included), endpos(endindex_included)
173 assert(ba.size() >= (
endpos - startpos + 1) &&
"BitArrayRange outside of BitArray");
175 return range.to_ulong();
180 assert(ba.size() >= (
endpos - startpos + 1) &&
"BitArrayRange outside of BitArray");
199 throw std::runtime_error(
"etiss::instr::OPCode constructed with code and mask of different widths");
202 if (!((code & mask) == code))
223 if ((o1 == 0) || (o2 == 0))
231 return (*o1) < (*o2);
240 : builtinGroups_(0), printer_(printASMSimple), width(opc.code_.size()), opc_(opc), name_(name)
245 std::stringstream ss;
246 ss << instr.
name_ <<
" # 0x" << ba <<
" [UNKNOWN PARAMETERS]";
252 std::stringstream ss;
254 ss << indent <<
"@0x" << std::hex << std::setw(pfillwidth) << pos << std::dec <<
" Instruction: " <<
name_ <<
"\n";
258 uint32_t builtinGroups,
const std::set<uint32_t> &groups)
267 for (
auto iter = groups.begin(); iter != groups.end(); iter++)
283 for (
auto iter = groups.begin(); iter != groups.end(); iter++)
289 std::set<uint32_t>>(callback, builtinGroups, groups));
298 ok = ok & std::get<0>(*iter)(ba, cs, context);
325 : parent_(parent), name_(name), width_(width), chunk_size(c_size), root_(nullptr), invalid(width, -1, -1,
"INVALID")
376 if (
instrmap_.insert(std::pair<const OPCode *, Instruction *>(&ret->
opc_, ret)).second ==
false)
378 etiss::log(
ERROR,
"Failed to add instruction to instrmap_.", name, *
this);
393 std::vector<size_type> indexes;
397 BitArray code = op2instr.first->code_;
398 BitArray mask = op2instr.first->mask_;
407 for (
size_type j = 0; j < chunk_bits_mask.size(); ++j)
408 if (!chunk_bits_mask[j])
409 indexes.push_back(j);
417 for (
const auto &permutated_chunk : permutated_chunk_codes)
419 auto val = permutated_chunk.to_ulong();
420 root_[i][val].insert(inst);
429 std::set<Instruction *> results;
434 auto val = chunk_bits_code.to_ulong();
436 auto instrs_in_node =
root_[i][val];
439 results = instrs_in_node;
442 std::set<Instruction *> results_o;
443 std::set_intersection(
444 results.begin(), results.end(),
445 instrs_in_node.begin(), instrs_in_node.end(),
446 std::inserter(results_o, results_o.begin()));
453 else if (results.size() == 1)
454 return *(results.begin());
463 { return lhs->opc_.mask_.count() < rhs->opc_.mask_.count(); });
470 if (
root_ !=
nullptr)
472 std::stringstream ss;
492 if (iter->second !=
nullptr)
511VariableInstructionSet::VariableInstructionSet(
ModedInstructionSet &parent,
unsigned width,
const std::string &archname)
512 : parent_(parent), width_(width), archname_(archname)
516 con.is_not_default_width_ =
false;
517 con.instr_width_ =
width_;
523 for (
auto iter =
ismap_.begin(); iter !=
ismap_.end(); iter++)
534 if (iter->second->size() <= 0)
541 ok = ok & iter->second->compile();
578 for (
auto iter =
ismap_.begin(); iter !=
ismap_.end(); iter++)
580 if (iter->second !=
nullptr)
582 call(*(iter->second));
593 std::stringstream ss;
600ModedInstructionSet::ModedInstructionSet(
const std::string &name) : archname_(name) {}
622 if (f->second->width_ != width)
647 return *
create(mode, width, name);
655 "variable instruction set mode cannot be found since this moded instruction set is not its parent");
663 if (iter->second !=
nullptr)
665 call(*(iter->second));
684 std::stringstream ss;
690 ss << vis.
print(prefix +
"\t");
702 klass.
addTo(vis, ok);
722 if (instr ==
nullptr)
725 etiss::log(
ERROR,
"failed to add InstructionDefinition to Instruction set.",
id, set);
728 id.addTo(*instr, ok);
741 etiss::log(
VERBOSE,
"Added instruction definition to instruction.", *
this, instr);
749#if __cplusplus >= 201103L
757 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())
etiss_del_como(ModedInstructionSet) ModedInstructionSet(const std ~ModedInstructionSet()
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_
BitArray::size_type size_type
std::set< Instruction * > Node
Holding unique instruction sets code chunks after permutation.
uint32_t parse_i32(const char *s)
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