Fixed bug in calculation of use/def classes. Still not tested.
[jitcs.git] / include / jitcs_x86_xx_insids.lh
blob45d91f3aa44db37df1b4c27fe611b671b087331d
1 #/bin/emblua LUAPREFIX=/*|
2 /*| --VARDELIM=%
3 /*| --CMTDELIM=//
4 /*| --*/
5 /*| local N = $$$
6 /*| function pred_ipairs(t, pred)
7 /*|   return function(t,k)
8 /*|       local v
9 /*|       repeat
10 /*|         k = k + 1 
11 /*|         v = t[k]
12 /*|       until not v or pred(k, v)
13 /*|       return v and k, v
14 /*|     end, t, 0
15 /*| end
16 /*| function isa(v) return not v[N==32 and "x64" or "x32only"] end
17 //===-- jitcs_x86_%(N)_regs.h C++ -----------------------------------------*-===//
19 // Instruction and instruction class ids (+ condition codes) for %(N)bit x86 code.
21 //===----------------------------------------------------------------------===//
23 #ifndef _JITCS_X86_%(N)_INSIDS_H_
24 #define _JITCS_X86_%(N)_INSIDS_H_
26 #include "jitcs_base.h"
27 #include "jitcs_ids.h"
28 #include "jitcs_x86_common_insids.h"
30 /*| local data= runfile("../src/data/x86_inslist.dat")
31 /*|  --*/
33 namespace jitcs {
34 namespace x86_%(N) {
36 using x86_common::CondCodeId;
37 enum {
38   ICL_SubBits = 5,
39   ICL_SubMask = (1 << ICL_SubBits) - 1,
40   ICL_AuxBits = 8,
41   ICL_NonMainBits = ICL_SubBits + ICL_AuxBits,
42   ICL_NonMainMask = (1 << ICL_NonMainBits) - 1,
44 enum InsClassId {
45   ICL_First = (I_CoreMax + ICL_NonMainMask) >> ICL_NonMainBits,
46 /*| local function ps(n,s) return n .. (#n < s and string.rep(" ",s-#n) or "") end
47 /*| local first = true
48 /*| for k,cl in pred_ipairs(data.opclasses, function(k,cl) return isa(cl.isa) end) do
49   ICL_%(cl.id)%(first and " = ICL_First" or ""), // ? members
50 /*|   first = false
51 /*| end
52 /*| --*/
53   ICL_Last,
55 enum { ICL_Count = ICL_Last - ICL_First };
57 template <InsId ID> struct ToInsClassCT {
58   static const InsClassId Value = static_cast<InsClassId>(ID >> ICL_NonMainBits);
60 inline InsClassId ToInsClass(InsId id) { return static_cast<InsClassId>(id >> ICL_NonMainBits); }
61 template <InsClassId ICL> struct IsValidInsClassCT {
62   static const bool Value = (ICL >= ICL_First && ICL < ICL_Last);
64 inline bool IsValid(InsClassId icl) { return icl >= ICL_First && icl < ICL_Last; }
66 template <typename T>
67 inline T ReadFromInsClassArray(T arr[ICL_Count] , InsClassId icl) {
68   assert(IsValid(icl));
69   return arr[icl - x86_%(N)::ICL_First];
72 #define INSID(CID,SUB,AUX) static_cast<InsId>(((CID) << ICL_NonMainBits) + ((AUX) << ICL_SubBits) + (SUB))
73 /*| for k,op in pred_ipairs(data.ops, function(k,op) return isa(op.opclass.isa) end) do
74 static const InsId I_%(ps(op.name, 20)) = INSID(ICL_%(op.opclass.id), %(op.sub or 0), %(op.sub2 or 0));
75 /*| end
76 /*| --*/
77 #undef INSID
79 /*| local al= runfile("../src/data/x86_insalias.dat")
80 // here come aliases
81 /*| for k,v in ipairs{{0,al.aliases}, {N,al["aliases"..N]}} do
82 /*|   for kk,vv in ipairs(v[2]) do
83 static const InsId I_%(ps(vv[1],20)) = I_%(vv[2]);
84 /*|   end
85 /*| end
87 } // end of namespace jitcs::x86_%(N)
88 } // end of namespace jitcs
89 #endif
90 // _JITCS_X86_%(N)_INSIDS_H_