source: proto/s2k/trunk/framework/src/toolchain/b2k/lang/paramBuiltin/idisa/IDISABuiltin.java @ 4109

Last change on this file since 4109 was 4109, checked in by ksherdy, 5 years ago

s2k sk to b2k IDISA translation support.

File size: 18.5 KB
Line 
1/*
2 * IDISA SIMD builtins definitions.
3 *
4 * Unary        r = simd<w>::op(a)
5 * Binary       r = simd<w>::op(a, b)
6 * Ternary  r = simd<w>::op(a, b, c)
7 *
8 * KH: TODO A 'matcher' class to resolve function signatures.
9 *
10 * IDISABuiltins2Lang translates the majority of IDISA builtins.
11 * 'special cases' call out to helpers.
12 *
13 * Note: S2K/B2K IDISA function calls with compile time constants,
14 * e.g. simd.constant<1>(0), treat the first argument(s) as the compile
15 * constant values.
16 *
17 * Note: KH: Additional work needed to validate IDISA function signatures. The current approach
18 * to validation accepts a broader range of signatures than are actually supported at the native
19 * level.
20 *
21 * @author Ken Herdy <ksherdy at sfu dot ca>
22 * @authos Meng
23 */
24
25package toolchain.b2k.lang.paramBuiltin.idisa;
26
27import java.util.ArrayList;
28import java.util.HashMap;
29import java.util.Map;
30
31import toolchain.b2k.lang.paramBuiltin.idisa.AbstractIDISABuiltinGenerator;
32import toolchain.b2k.lang.paramBuiltin.idisa.SIMDBitblockBuiltinsGenerator;
33import toolchain.b2k.lang.paramBuiltin.idisa.SIMDBitblockImmediateBuiltinsGenerator;
34import toolchain.b2k.lang.paramBuiltin.idisa.SIMDBitblockLoadBuiltinsGenerator;
35import toolchain.b2k.lang.paramBuiltin.idisa.SIMDBitblockStoreBuiltinsGenerator;
36import toolchain.b2k.lang.paramBuiltin.idisa.SIMDBuiltinsGenerator;
37import toolchain.b2k.lang.paramBuiltin.idisa.SIMDConstantBuiltinsGenerator;
38import toolchain.b2k.lang.paramBuiltin.idisa.SIMDLogicBuiltinsGenerator;
39import toolchain.b2k.lang.signatures.ParameterizedFunctionSignature;
40import toolchain.b2k.lang.type.Type;
41
42
43import static toolchain.b2k.lang.type.PrimitiveType.BITBLOCK;
44import static toolchain.b2k.lang.type.PrimitiveType.BITBLOCK_POINTER;
45import static toolchain.b2k.lang.type.PrimitiveType.BITBLOCK_SIZE;
46import static toolchain.b2k.lang.type.PrimitiveType.BITFIELD;
47import static toolchain.b2k.lang.type.PrimitiveType.BOOL;
48import static toolchain.b2k.lang.type.PrimitiveType.INTEGER;
49import static toolchain.b2k.lang.type.PrimitiveType.VOID;
50import static toolchain.b2k.lang.paramBuiltin.idisa.IDISABuiltinsTranslator.IDENTITY_TRANSLATION;
51import static toolchain.b2k.lang.paramBuiltin.idisa.IDISABuiltinsTranslator.PACK_TRANSLATION;;
52
53public enum IDISABuiltin {
54    // SIMD operations (opPattern == 0)
55        // C++: class_name<fw>::op(data_type arg, ...)
56        // C:   class_name_op_fw(args...)
57        ESIMD_MERGEH (          "mergeh",               IDENTITY_TRANSLATION, makeRangeOfSimpleSignatures(1,BITBLOCK_SIZE/2, new SIMDBuiltinsGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
58        ESIMD_MERGEL (          "mergel",               IDENTITY_TRANSLATION, makeRangeOfSimpleSignatures(1,BITBLOCK_SIZE/2, new SIMDBuiltinsGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
59        ESIMD_MULTH (           "multh",                IDENTITY_TRANSLATION, makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinsGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
60        ESIMD_MULTL (           "multl",                IDENTITY_TRANSLATION, makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinsGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
61        ESIMD_SIGNEXTENDH (     "signextendh",  IDENTITY_TRANSLATION, makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinsGenerator(),  BITBLOCK,  BITBLOCK)),
62        ESIMD_SIGNEXTENDL (     "signextendl",  IDENTITY_TRANSLATION, makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinsGenerator(),  BITBLOCK,  BITBLOCK)),
63        ESIMD_ZEROEXTENDH (     "zeroextendh",  IDENTITY_TRANSLATION, makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinsGenerator(),  BITBLOCK,  BITBLOCK)),
64        ESIMD_ZEROEXTENDL (     "zeroextendl",  IDENTITY_TRANSLATION, makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinsGenerator(),  BITBLOCK,  BITBLOCK)),
65        HSIMD_ADD_HL (          "add_hl",       IDENTITY_TRANSLATION, makeRangeOfSimpleSignatures(2,BITBLOCK_SIZE, new SIMDBuiltinsGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
66        HSIMD_MIN_HL (          "min_hl",       IDENTITY_TRANSLATION, makeRangeOfSimpleSignatures(2,BITBLOCK_SIZE, new SIMDBuiltinsGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
67        HSIMD_PACKH (           "packh",        PACK_TRANSLATION, makeRangeOfSimpleSignatures(2,BITBLOCK_SIZE, new SIMDBuiltinsGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
68        HSIMD_PACKL (           "packl",        PACK_TRANSLATION, makeRangeOfSimpleSignatures(2,BITBLOCK_SIZE, new SIMDBuiltinsGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
69        HSIMD_PACKSS (          "packss",       IDENTITY_TRANSLATION, makeRangeOfSimpleSignatures(2,BITBLOCK_SIZE, new SIMDBuiltinsGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
70        HSIMD_PACKUS (          "packus",       IDENTITY_TRANSLATION, makeRangeOfSimpleSignatures(2,BITBLOCK_SIZE, new SIMDBuiltinsGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
71        HSIMD_SIGNMASK (        "signmask",     IDENTITY_TRANSLATION, makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinsGenerator(),  BITBLOCK,  BITFIELD)),
72        HSIMD_UMIN_HL (         "umin_hl",      IDENTITY_TRANSLATION, makeRangeOfSimpleSignatures(2,BITBLOCK_SIZE, new SIMDBuiltinsGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
73        MVMD_FILL (                     "fill",         IDENTITY_TRANSLATION, makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinsGenerator(),  BITBLOCK,  BITBLOCK)),
74        MVMD_FILL16 (           "fill16",       IDENTITY_TRANSLATION, makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinsGenerator(),  BITBLOCK, BITBLOCK, BITBLOCK, BITBLOCK, BITBLOCK, BITBLOCK, BITBLOCK, BITBLOCK, BITBLOCK, BITBLOCK, BITBLOCK, BITBLOCK, BITBLOCK, BITBLOCK, BITBLOCK, BITBLOCK,  BITBLOCK)),
75        MVMD_FILL2 (            "fill2",        IDENTITY_TRANSLATION, makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinsGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
76        MVMD_FILL4 (            "fill4",        IDENTITY_TRANSLATION, makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinsGenerator(),  BITBLOCK, BITBLOCK, BITBLOCK, BITBLOCK,  BITBLOCK)),
77        MVMD_FILL8 (            "fill8",        IDENTITY_TRANSLATION, makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinsGenerator(),  BITBLOCK, BITBLOCK, BITBLOCK, BITBLOCK, BITBLOCK, BITBLOCK, BITBLOCK, BITBLOCK,  BITBLOCK)),
78        //KH: shuffle dne ?
79        //MVMD_SHUFFLE (                "shuffle",      makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
80        SIMD_ABS (                      "abs",          IDENTITY_TRANSLATION, makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinsGenerator(),  BITBLOCK,  BITBLOCK)),
81        SIMD_ADD (                      "add",          IDENTITY_TRANSLATION, makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinsGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
82        SIMD_ADD_HL (           "add_hl",       IDENTITY_TRANSLATION, makeRangeOfSimpleSignatures(2,BITBLOCK_SIZE, new SIMDBuiltinsGenerator(),  BITBLOCK,  BITBLOCK)),
83        SIMD_CTZ (                      "ctz",          IDENTITY_TRANSLATION, makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinsGenerator(),  BITBLOCK,  BITBLOCK)),
84        SIMD_EQ (                       "eq",           IDENTITY_TRANSLATION, makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinsGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
85        SIMD_GT (                       "gt",           IDENTITY_TRANSLATION, makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinsGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
86        SIMD_HIMASK (           "himask",       IDENTITY_TRANSLATION, makeRangeOfSimpleSignatures(2,BITBLOCK_SIZE, new SIMDBuiltinsGenerator(),   BITBLOCK)),
87        SIMD_IFH (                      "ifh",          IDENTITY_TRANSLATION, makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinsGenerator(),  BITBLOCK, BITBLOCK, BITBLOCK,  BITBLOCK)),
88        SIMD_LOMASK (           "lomask",       IDENTITY_TRANSLATION, makeRangeOfSimpleSignatures(2,BITBLOCK_SIZE, new SIMDBuiltinsGenerator(),   BITBLOCK)),
89        SIMD_LT (                       "lt",           IDENTITY_TRANSLATION, makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinsGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
90        SIMD_MAX (                      "max",          IDENTITY_TRANSLATION, makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinsGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
91        SIMD_MIN (                      "min",          IDENTITY_TRANSLATION, makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinsGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
92        SIMD_MULT (                     "mult",         IDENTITY_TRANSLATION, makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinsGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
93        SIMD_NEG (                      "neg",          IDENTITY_TRANSLATION, makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinsGenerator(),  BITBLOCK,  BITBLOCK)),
94        SIMD_POPCOUNT (         "popcount",     IDENTITY_TRANSLATION, makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinsGenerator(),  BITBLOCK,  BITBLOCK)),
95        SIMD_SLL (                      "sll",          IDENTITY_TRANSLATION, makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinsGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
96        SIMD_SRA (                      "sra",          IDENTITY_TRANSLATION, makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinsGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
97        SIMD_SRL (                      "srl",          IDENTITY_TRANSLATION, makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinsGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
98        SIMD_SUB (                      "sub",          IDENTITY_TRANSLATION, makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinsGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
99        SIMD_SUB_HL (           "sub_hl",       IDENTITY_TRANSLATION, makeRangeOfSimpleSignatures(2,BITBLOCK_SIZE, new SIMDBuiltinsGenerator(),  BITBLOCK,  BITBLOCK)),
100        SIMD_UGT (                      "ugt",          IDENTITY_TRANSLATION, makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinsGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
101        SIMD_ULT (                      "ult",          IDENTITY_TRANSLATION, makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinsGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
102        SIMD_UMAX (                     "umax",         IDENTITY_TRANSLATION, makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinsGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
103        SIMD_UMIN (                     "umin",         IDENTITY_TRANSLATION, makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinsGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
104        SIMD_UMULT (            "umult",        IDENTITY_TRANSLATION, makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinsGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
105        SIMD_XOR_HL (           "xor_hl",       IDENTITY_TRANSLATION, makeRangeOfSimpleSignatures(2,BITBLOCK_SIZE, new SIMDBuiltinsGenerator(),  BITBLOCK,  BITBLOCK)),
106
107        //  KH: Not sure why we initially omitted any, all, vsrl, vsll
108        SIMD_ANY (              "any",          IDENTITY_TRANSLATION, makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinsGenerator(),  BITBLOCK,  BITBLOCK)),
109        SIMD_ALL (              "all",          IDENTITY_TRANSLATION, makeRangeOfSimpleSignatures(2,BITBLOCK_SIZE, new SIMDBuiltinsGenerator(),  BITBLOCK,  BITBLOCK)),
110        SIMD_VRSL(              "vsrl",         IDENTITY_TRANSLATION, makeRangeOfSimpleSignatures(64,BITBLOCK_SIZE, new SIMDBuiltinsGenerator(),  BITBLOCK,  BITBLOCK, BITBLOCK)),             
111        SIMD_VRLL(              "vsll",         IDENTITY_TRANSLATION, makeRangeOfSimpleSignatures(64,BITBLOCK_SIZE, new SIMDBuiltinsGenerator(),  BITBLOCK,  BITBLOCK, BITBLOCK)),
112       
113        // SIMD (opPatterns == 1)
114        // C++: class_name<fw>::op<x>(data_type arg, ...)
115        // C:   class_name_op_fw(data_type arg, ..., x)
116        MVMD_DSLLI (    "dslli",        IDENTITY_TRANSLATION, makeRangeOfSimpleSignatures(2,BITBLOCK_SIZE, new SIMDConstantBuiltinsGenerator(),  INTEGER,  BITBLOCK,  BITBLOCK,  BITBLOCK)),
117        MVMD_DSRLI (    "dsrli",        IDENTITY_TRANSLATION, makeRangeOfSimpleSignatures(2,BITBLOCK_SIZE, new SIMDConstantBuiltinsGenerator(),  INTEGER,  BITBLOCK,  BITBLOCK,  BITBLOCK)),
118        MVMD_EXTRACT (  "extract",      IDENTITY_TRANSLATION, makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDConstantBuiltinsGenerator(),  INTEGER,  BITBLOCK,  BITFIELD)),
119        MVMD_INSERT (   "insert",       IDENTITY_TRANSLATION, makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDConstantBuiltinsGenerator(),  INTEGER,  BITBLOCK,  BITFIELD, BITBLOCK)),
120        MVMD_SHUFFLEI ( "shufflei",     IDENTITY_TRANSLATION, makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDConstantBuiltinsGenerator(),  INTEGER,   BITBLOCK,   BITBLOCK)),
121        MVMD_SLLI (             "slli",         IDENTITY_TRANSLATION, makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDConstantBuiltinsGenerator(),  INTEGER,   BITBLOCK,  BITBLOCK)),
122        MVMD_SPLAT (    "splat",        IDENTITY_TRANSLATION, makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDConstantBuiltinsGenerator(),  INTEGER, BITBLOCK, BITBLOCK)),
123        MVMD_SRLI (             "srli",         IDENTITY_TRANSLATION, makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDConstantBuiltinsGenerator(),  INTEGER, BITBLOCK,  BITBLOCK)),
124        SIMD_CONSTANT ( "constant",     IDENTITY_TRANSLATION, makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDConstantBuiltinsGenerator(),  INTEGER,   BITBLOCK)),
125        SIMD_SLLI (             "slli",         IDENTITY_TRANSLATION, makeRangeOfSimpleSignatures(2,BITBLOCK_SIZE, new SIMDConstantBuiltinsGenerator(),  INTEGER,   BITBLOCK,   BITBLOCK)),
126        SIMD_SRAI (             "srai",         IDENTITY_TRANSLATION, makeRangeOfSimpleSignatures(2,BITBLOCK_SIZE, new SIMDConstantBuiltinsGenerator(),  INTEGER,   BITBLOCK,   BITBLOCK)),
127        SIMD_SRLI (             "srli",         IDENTITY_TRANSLATION, makeRangeOfSimpleSignatures(2,BITBLOCK_SIZE, new SIMDConstantBuiltinsGenerator(),  INTEGER,   BITBLOCK,   BITBLOCK)),
128               
129        // SIMD logic operations (opPattern == 2)
130        // C++: simd_op(data_type arg, ...)
131        // C:   simd_op(data_type arg, ...)
132        SIMD_NOR (      "nor",  IDENTITY_TRANSLATION, makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDLogicBuiltinsGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
133        SIMD_NOT (      "not",  IDENTITY_TRANSLATION, makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDLogicBuiltinsGenerator(),  BITBLOCK,  BITBLOCK)),
134        SIMD_ANDC (     "andc", IDENTITY_TRANSLATION, makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDLogicBuiltinsGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
135        SIMD_OR (       "or",   IDENTITY_TRANSLATION, makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDLogicBuiltinsGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
136        SIMD_XOR (      "xor",  IDENTITY_TRANSLATION, makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDLogicBuiltinsGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
137        SIMD_AND (      "and",  IDENTITY_TRANSLATION, makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDLogicBuiltinsGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
138       
139        // SIMD (opPattern == 3)
140        // C++: class_name::op(data_type arg, ...)
141        // C:   class_name_op(data_type arg, ...)
142        BITBLOCK_ALL (          "all",                  IDENTITY_TRANSLATION, makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBitblockBuiltinsGenerator(),  BITBLOCK,    BOOL)),
143        BITBLOCK_ANY (          "any",                  IDENTITY_TRANSLATION, makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBitblockBuiltinsGenerator(),  BITBLOCK,    BOOL)),
144        BITBLOCK_POPCOUNT (     "popcount",             IDENTITY_TRANSLATION, makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBitblockBuiltinsGenerator(),  BITBLOCK,    BITFIELD)),
145        BITBLOCK_SLL (          "sll",                  IDENTITY_TRANSLATION, makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBitblockBuiltinsGenerator(),  BITBLOCK,    BITBLOCK,  BITBLOCK)),
146        BITBLOCK_SRL (          "srl",                  IDENTITY_TRANSLATION, makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBitblockBuiltinsGenerator(),  BITBLOCK,    BITBLOCK,  BITBLOCK)),
147       
148        // SIMD (opPattern == 4)
149        // C++: class_name::op<x>(data_type arg, ...)
150        // C:   class_name_op(data_type arg, ..., x)
151        BITBLOCK_SLLI (         "slli"  ,       IDENTITY_TRANSLATION, makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBitblockImmediateBuiltinsGenerator(),  INTEGER,  BITBLOCK,  BITBLOCK)),
152        BITBLOCK_SRLI (         "srli"  ,       IDENTITY_TRANSLATION, makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBitblockImmediateBuiltinsGenerator(),  INTEGER,  BITBLOCK,  BITBLOCK)),
153       
154        // SIMD Stores (with args = (Bitblock, Bitblock*))
155        BITBLOCK_STORE_ALIGNED (        "store_aligned",        IDENTITY_TRANSLATION, makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBitblockStoreBuiltinsGenerator(),  BITBLOCK, BITBLOCK_POINTER,  VOID)),
156        BITBLOCK_STORE_UNALIGNED (      "store_unaligned",      IDENTITY_TRANSLATION, makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBitblockStoreBuiltinsGenerator(),  BITBLOCK, BITBLOCK_POINTER,  VOID)),
157       
158        // SIMD Loads (with args = Bitblock*)
159        BITBLOCK_LOAD_ALIGNED (         "load_aligned",         IDENTITY_TRANSLATION, makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBitblockLoadBuiltinsGenerator(),  BITBLOCK_POINTER,  BITBLOCK)),
160        BITBLOCK_LOAD_UNALIGNED (       "load_unaligned",       IDENTITY_TRANSLATION, makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBitblockLoadBuiltinsGenerator(),  BITBLOCK_POINTER,  BITBLOCK)),
161
162        NULL_BUILTIN("Null", IDENTITY_TRANSLATION );
163       
164        private static final Map<String, IDISABuiltin> builtinForName = new HashMap<String, IDISABuiltin>();
165           
166        static {
167                for(IDISABuiltin idisaBuiltin : values()) {
168                        builtinForName.put(idisaBuiltin.fullyQualifiedName(), idisaBuiltin);
169                }
170    }
171       
172    public static IDISABuiltin forName(String fullyQualifiedName) {
173        if(builtinForName.containsKey(fullyQualifiedName)) {
174                return builtinForName.get(fullyQualifiedName);
175        }
176        return NULL_BUILTIN;
177    }
178   
179    private String name;
180    private IDISABuiltinsTranslator translator;
181        private ParameterizedFunctionSignature [] signatures;
182       
183        private IDISABuiltin(String name, IDISABuiltinsTranslator translator, ParameterizedFunctionSignature ...signatures) {
184                this.name = name;
185                this.translator = translator;
186                this.signatures = signatures; 
187        }
188        //private IDISABuiltin(String className, String opName, IDISAFunctionSignature ...signatures) {
189       
190        /////////////////////////////////////////////////////////////////
191        // queries
192        /////////////////////////////////////////////////////////////////
193        public String fullyQualifiedName() { return packageName() + "." + baseName();   }
194        public String packageName() { return this.name().toLowerCase().split("_")[0];   }
195        public String baseName() { return this.name; }
196    public IDISABuiltinsTranslator getTranslator() { return this.translator; }
197        public boolean hasSignature(int fieldWidth,  int argCount) {
198                return !getSignature(fieldWidth, argCount).isNull();
199        }
200        public ParameterizedFunctionSignature getSignature(int fieldWidth, int argCount) {
201               
202                for(ParameterizedFunctionSignature signature : this.signatures) {
203                        if( (signature.getFieldWidth() == fieldWidth) && (signature.getNumParameters() == argCount) ) {
204                                return signature;
205                        }
206                }
207                return ParameterizedFunctionSignature.nullInstance();
208        }
209
210        // KH:
211        //      public boolean hasCompileTimeConstantArgument() {
212        //      if( (parameterTypes.length > 0) && (parameterTypes[0] == PrimitiveType.INTEGERCONSTANT) ) {
213        //              return true;
214        //      }
215        //      return false;
216        //}
217       
218        /////////////////////////////////////////////////////////////////
219        // generators
220        /////////////////////////////////////////////////////////////////
221        /**
222         * Makes IDISA function signatures from 2^0 to uppoer bound field width and constant arguments.
223         */
224        private static ParameterizedFunctionSignature [] makeAllSimpleSignatures (int upperBound, AbstractIDISABuiltinGenerator idisaBuiltinsGenerator, Type ...types) {
225                return (ParameterizedFunctionSignature []) makeRangeOfSimpleSignatures(1, upperBound, idisaBuiltinsGenerator,types);
226        }
227       
228        /**
229         * Makes IDISA function signatures from power-of-2 lower bound to power-of-2 upper bound field width and constant arguments.
230         */
231        private static ParameterizedFunctionSignature [] makeRangeOfSimpleSignatures (int lowerBound, int upperBound, AbstractIDISABuiltinGenerator idisaBuiltinsGenerator, Type ...types) { 
232               
233                ArrayList<ParameterizedFunctionSignature> signatures = new ArrayList<ParameterizedFunctionSignature>();
234                       
235                for(int fw=lowerBound;fw<=upperBound;fw*=2) {
236                        ParameterizedFunctionSignature signature = new ParameterizedFunctionSignature(idisaBuiltinsGenerator,fw,types);
237                        signatures.add(signature);
238                }
239               
240                return (ParameterizedFunctionSignature []) signatures.toArray(new ParameterizedFunctionSignature[signatures.size()]);
241        }
242
243
244}
Note: See TracBrowser for help on using the repository browser.