Changeset 3809


Ignore:
Timestamp:
Apr 11, 2014, 1:55:50 AM (3 years ago)
Author:
ksherdy
Message:

Fixed IDISA builtin signatures. Added initial support for type checking signatures. Refactored IDISA signatures as parameterized signatures.

Location:
proto/s2k/trunk/framework/src/toolchain/b2k/lang
Files:
6 added
3 deleted
2 edited

Legend:

Unmodified
Added
Removed
  • proto/s2k/trunk/framework/src/toolchain/b2k/lang/B2KBuiltin.java

    r3798 r3809  
    1616      public enum CarryType{One, N, None};   
    1717     
     18      private final String name;
    1819      private final CarryType type;
    19       private final String name;
    2020      private final int argCount;
    2121     
  • proto/s2k/trunk/framework/src/toolchain/b2k/lang/idisa/IDISABuiltin.java

    r3705 r3809  
    11/*
    2   * IDISA SIMD builtins.
     2 * IDISA SIMD builtins definitions.
    33 *
    44 * Unary        r = simd<w>::op(a)
     
    66 * Ternary  r = simd<w>::op(a, b, c)
    77 *
     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 *
    821 * @author Ken Herdy <ksherdy at sfu dot ca>
     22 * @authos Meng
    923 */
    1024
     
    1226
    1327import java.util.ArrayList;
     28import java.util.Arrays;
    1429import java.util.HashMap;
     30import java.util.List;
    1531import java.util.Map;
    1632
     
    2339import toolchain.b2k.codeGenerator.idisa.SIMDConstantBuiltinGenerator;
    2440import toolchain.b2k.codeGenerator.idisa.SIMDLogicBuiltinGenerator;
    25 import toolchain.b2k.lang.types.Type;
    26 
    27 
    28 import static toolchain.b2k.lang.types.PrimitiveType.BITBLOCK;
    29 import static toolchain.b2k.lang.types.PrimitiveType.BITBLOCK_POINTER;
    30 import static toolchain.b2k.lang.types.PrimitiveType.BITBLOCK_SIZE;
    31 import static toolchain.b2k.lang.types.PrimitiveType.BITFIELD;
    32 import static toolchain.b2k.lang.types.PrimitiveType.BOOL;
    33 import static toolchain.b2k.lang.types.PrimitiveType.INTEGERCONSTANT;
    34 import static toolchain.b2k.lang.types.PrimitiveType.VOID;
     41import toolchain.b2k.lang.signatures.ParameterizedFunctionSignature;
     42import toolchain.b2k.lang.type.Type;
     43
     44
     45import static toolchain.b2k.lang.type.PrimitiveType.BITBLOCK;
     46import static toolchain.b2k.lang.type.PrimitiveType.BITBLOCK_POINTER;
     47import static toolchain.b2k.lang.type.PrimitiveType.BITBLOCK_SIZE;
     48import static toolchain.b2k.lang.type.PrimitiveType.BITFIELD;
     49import static toolchain.b2k.lang.type.PrimitiveType.BOOL;
     50import static toolchain.b2k.lang.type.PrimitiveType.INTEGERCONSTANT;
     51import static toolchain.b2k.lang.type.PrimitiveType.VOID;
    3552
    3653public enum IDISABuiltin {
    37    
    38 
    39    
    40                
    41         // SIMD operations (opPattern == 0)
     54    // SIMD operations (opPattern == 0)
    4255        // C++: class_name<fw>::op(data_type arg, ...)
    4356        // C:   class_name_op_fw(args...)
    44         ESIMD_MERGEH (makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
    45         ESIMD_MERGEL (makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
    46         ESIMD_MULTH (makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
    47         ESIMD_MULTL (makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
    48         ESIMD_SIGNEXTENDH (makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinGenerator(),  BITBLOCK,  BITBLOCK)),
    49         ESIMD_SIGNEXTENDL (makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinGenerator(),  BITBLOCK,  BITBLOCK)),
    50         ESIMD_ZEROEXTENDH (makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinGenerator(),  BITBLOCK,  BITBLOCK)),
    51         ESIMD_ZEROEXTENDL (makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinGenerator(),  BITBLOCK,  BITBLOCK)),
    52         HSIMD_ADD_HL (makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
    53         HSIMD_MIN_HL (makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
    54         HSIMD_PACKH (makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
    55         HSIMD_PACKL (makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
    56         HSIMD_PACKSS (makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
    57         HSIMD_PACKUS (makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
    58         HSIMD_SIGNMASK (makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinGenerator(),  BITBLOCK,  BITFIELD)),
    59         HSIMD_UMIN_HL (makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
    60         MVMD_FILL (makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinGenerator(),  BITBLOCK,  BITBLOCK)),
    61         MVMD_FILL16 (makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinGenerator(),  BITBLOCK, BITBLOCK, BITBLOCK, BITBLOCK, BITBLOCK, BITBLOCK, BITBLOCK, BITBLOCK, BITBLOCK, BITBLOCK, BITBLOCK, BITBLOCK, BITBLOCK, BITBLOCK, BITBLOCK, BITBLOCK,  BITBLOCK)),
    62         MVMD_FILL2 (makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
    63         MVMD_FILL4 (makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinGenerator(),  BITBLOCK, BITBLOCK, BITBLOCK, BITBLOCK,  BITBLOCK)),
    64         MVMD_FILL8 (makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinGenerator(),  BITBLOCK, BITBLOCK, BITBLOCK, BITBLOCK, BITBLOCK, BITBLOCK, BITBLOCK, BITBLOCK,  BITBLOCK)),
    65         MVMD_SHUFFLE (makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
    66         SIMD_ABS (makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinGenerator(),  BITBLOCK,  BITBLOCK)),
    67         SIMD_ADD (makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
    68         SIMD_ADD_HL (makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinGenerator(),  BITBLOCK,  BITBLOCK)),
    69         SIMD_CTZ (makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinGenerator(),  BITBLOCK,  BITBLOCK)),
    70         SIMD_EQ (makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
    71         SIMD_GT (makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
    72         SIMD_HIMASK (makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinGenerator(),   BITBLOCK)),
    73         SIMD_IFH (makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinGenerator(),  BITBLOCK, BITBLOCK, BITBLOCK,  BITBLOCK)),
    74         SIMD_LOMASK (makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinGenerator(),   BITBLOCK)),
    75         SIMD_LT (makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
    76         SIMD_MAX (makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
    77         SIMD_MIN (makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
    78         SIMD_MULT (makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
    79         SIMD_NEG (makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinGenerator(),  BITBLOCK,  BITBLOCK)),
    80         SIMD_POPCOUNT (makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinGenerator(),  BITBLOCK,  BITBLOCK)),
    81         SIMD_SLL (makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
    82         SIMD_SRA (makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
    83         SIMD_SRL (makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
    84         SIMD_SUB (makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
    85         SIMD_SUB_HL (makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinGenerator(),  BITBLOCK,  BITBLOCK)),
    86         SIMD_UGT (makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
    87         SIMD_ULT (makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
    88         SIMD_UMAX (makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
    89         SIMD_UMIN (makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
    90         SIMD_UMULT (makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
    91         SIMD_XOR_HL (makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinGenerator(),  BITBLOCK,  BITBLOCK)),
     57        ESIMD_MERGEH (          "mergeh",               makeRangeOfSimpleSignatures(1,BITBLOCK_SIZE/2, new SIMDBuiltinGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
     58        ESIMD_MERGEL (          "mergel",               makeRangeOfSimpleSignatures(1,BITBLOCK_SIZE/2, new SIMDBuiltinGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
     59        ESIMD_MULTH (           "multh",                makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
     60        ESIMD_MULTL (           "multl",                makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
     61        ESIMD_SIGNEXTENDH (     "signextendh",  makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinGenerator(),  BITBLOCK,  BITBLOCK)),
     62        ESIMD_SIGNEXTENDL (     "signextendl",  makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinGenerator(),  BITBLOCK,  BITBLOCK)),
     63        ESIMD_ZEROEXTENDH (     "zeroextendh",  makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinGenerator(),  BITBLOCK,  BITBLOCK)),
     64        ESIMD_ZEROEXTENDL (     "zeroextendl",  makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinGenerator(),  BITBLOCK,  BITBLOCK)),
     65        HSIMD_ADD_HL (          "add_hl",       makeRangeOfSimpleSignatures(2,BITBLOCK_SIZE, new SIMDBuiltinGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
     66        HSIMD_MIN_HL (          "min_hl",       makeRangeOfSimpleSignatures(2,BITBLOCK_SIZE, new SIMDBuiltinGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
     67        HSIMD_PACKH (           "packh",        makeRangeOfSimpleSignatures(2,BITBLOCK_SIZE, new SIMDBuiltinGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
     68        HSIMD_PACKL (           "packl",        makeRangeOfSimpleSignatures(2,BITBLOCK_SIZE, new SIMDBuiltinGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
     69        HSIMD_PACKSS (          "packss",       makeRangeOfSimpleSignatures(2,BITBLOCK_SIZE, new SIMDBuiltinGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
     70        HSIMD_PACKUS (          "packus",       makeRangeOfSimpleSignatures(2,BITBLOCK_SIZE, new SIMDBuiltinGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
     71        HSIMD_SIGNMASK (        "signmask",     makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinGenerator(),  BITBLOCK,  BITFIELD)),
     72        HSIMD_UMIN_HL (         "umin_hl",      makeRangeOfSimpleSignatures(2,BITBLOCK_SIZE, new SIMDBuiltinGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
     73        MVMD_FILL (                     "fill",         makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinGenerator(),  BITBLOCK,  BITBLOCK)),
     74        MVMD_FILL16 (           "fill16",       makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinGenerator(),  BITBLOCK, BITBLOCK, BITBLOCK, BITBLOCK, BITBLOCK, BITBLOCK, BITBLOCK, BITBLOCK, BITBLOCK, BITBLOCK, BITBLOCK, BITBLOCK, BITBLOCK, BITBLOCK, BITBLOCK, BITBLOCK,  BITBLOCK)),
     75        MVMD_FILL2 (            "fill2",        makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
     76        MVMD_FILL4 (            "fill4",        makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinGenerator(),  BITBLOCK, BITBLOCK, BITBLOCK, BITBLOCK,  BITBLOCK)),
     77        MVMD_FILL8 (            "fill8",        makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinGenerator(),  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",          makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinGenerator(),  BITBLOCK,  BITBLOCK)),
     81        SIMD_ADD (                      "add",          makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
     82        SIMD_ADD_HL (           "add_hl",       makeRangeOfSimpleSignatures(2,BITBLOCK_SIZE, new SIMDBuiltinGenerator(),  BITBLOCK,  BITBLOCK)),
     83        SIMD_CTZ (                      "ctz",          makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinGenerator(),  BITBLOCK,  BITBLOCK)),
     84        SIMD_EQ (                       "eq",           makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
     85        SIMD_GT (                       "gt",           makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
     86        SIMD_HIMASK (           "himask",       makeRangeOfSimpleSignatures(2,BITBLOCK_SIZE, new SIMDBuiltinGenerator(),   BITBLOCK)),
     87        SIMD_IFH (                      "ifh",          makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinGenerator(),  BITBLOCK, BITBLOCK, BITBLOCK,  BITBLOCK)),
     88        SIMD_LOMASK (           "lomask",       makeRangeOfSimpleSignatures(2,BITBLOCK_SIZE, new SIMDBuiltinGenerator(),   BITBLOCK)),
     89        SIMD_LT (                       "lt",           makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
     90        SIMD_MAX (                      "max",          makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
     91        SIMD_MIN (                      "min",          makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
     92        SIMD_MULT (                     "mult",         makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
     93        SIMD_NEG (                      "neg",          makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinGenerator(),  BITBLOCK,  BITBLOCK)),
     94        SIMD_POPCOUNT (         "popcount",     makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinGenerator(),  BITBLOCK,  BITBLOCK)),
     95        SIMD_SLL (                      "sll",          makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
     96        SIMD_SRA (                      "sra",          makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
     97        SIMD_SRL (                      "srl",          makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
     98        SIMD_SUB (                      "sub",          makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
     99        SIMD_SUB_HL (           "sub_hl",       makeRangeOfSimpleSignatures(2,BITBLOCK_SIZE, new SIMDBuiltinGenerator(),  BITBLOCK,  BITBLOCK)),
     100        SIMD_UGT (                      "ugt",          makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
     101        SIMD_ULT (                      "ult",          makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
     102        SIMD_UMAX (                     "umax",         makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
     103        SIMD_UMIN (                     "umin",         makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
     104        SIMD_UMULT (            "umult",        makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
     105        SIMD_XOR_HL (           "xor_hl",       makeRangeOfSimpleSignatures(2,BITBLOCK_SIZE, new SIMDBuiltinGenerator(),  BITBLOCK,  BITBLOCK)),
     106
     107        //  KH: Not sure why we initially omitted any, all, vsrl, vsll
     108        SIMD_ANY (              "any",          makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBuiltinGenerator(),  BITBLOCK,  BITBLOCK)),
     109        SIMD_ALL (              "all",          makeRangeOfSimpleSignatures(2,BITBLOCK_SIZE, new SIMDBuiltinGenerator(),  BITBLOCK,  BITBLOCK)),
     110        SIMD_VRSL(              "vsrl",         makeRangeOfSimpleSignatures(64,BITBLOCK_SIZE, new SIMDBuiltinGenerator(),  BITBLOCK,  BITBLOCK, BITBLOCK)),             
     111        SIMD_VRLL(              "vsll",         makeRangeOfSimpleSignatures(64,BITBLOCK_SIZE, new SIMDBuiltinGenerator(),  BITBLOCK,  BITBLOCK, BITBLOCK)),
    92112       
    93113        // SIMD (opPatterns == 1)
    94114        // C++: class_name<fw>::op<x>(data_type arg, ...)
    95115        // C:   class_name_op_fw(data_type arg, ..., x)
    96         MVMD_DSLLI (makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDConstantBuiltinGenerator(),  INTEGERCONSTANT,  BITBLOCK,  BITBLOCK)),
    97         MVMD_DSRLI (makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDConstantBuiltinGenerator(),  INTEGERCONSTANT,  BITBLOCK,  BITBLOCK)),
    98         MVMD_EXTRACT (makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDConstantBuiltinGenerator(),  INTEGERCONSTANT,   BITFIELD)),
    99         MVMD_SHUFFLEI (makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDConstantBuiltinGenerator(),  INTEGERCONSTANT,   BITBLOCK)),
    100         MVMD_SLLI (makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDConstantBuiltinGenerator(),  INTEGERCONSTANT,   BITBLOCK)),
    101         MVMD_SPLAT (makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDConstantBuiltinGenerator(),  INTEGERCONSTANT,   BITBLOCK)),
    102         MVMD_SRLI (makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDConstantBuiltinGenerator(),  INTEGERCONSTANT,   BITBLOCK)),
    103         SIMD_CONSTANT (makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDConstantBuiltinGenerator(),  INTEGERCONSTANT,   BITBLOCK)),
    104         SIMD_SLLI (makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDConstantBuiltinGenerator(),  INTEGERCONSTANT,   BITBLOCK)),
    105         SIMD_SRAI (makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDConstantBuiltinGenerator(),  INTEGERCONSTANT,   BITBLOCK)),
    106         SIMD_SRLI (makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDConstantBuiltinGenerator(),  INTEGERCONSTANT,   BITBLOCK)),
    107        
     116        MVMD_DSLLI (    "dslli",        makeRangeOfSimpleSignatures(2,BITBLOCK_SIZE, new SIMDConstantBuiltinGenerator(),  INTEGERCONSTANT,  BITBLOCK,  BITBLOCK,  BITBLOCK)),
     117        MVMD_DSRLI (    "dsrli",        makeRangeOfSimpleSignatures(2,BITBLOCK_SIZE, new SIMDConstantBuiltinGenerator(),  INTEGERCONSTANT,  BITBLOCK,  BITBLOCK,  BITBLOCK)),
     118        MVMD_EXTRACT (  "extract",      makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDConstantBuiltinGenerator(),  INTEGERCONSTANT,  BITBLOCK,  BITFIELD)),
     119        MVMD_INSERT (   "insert",       makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDConstantBuiltinGenerator(),  INTEGERCONSTANT,  BITBLOCK,  BITFIELD, BITBLOCK)),
     120        MVMD_SHUFFLEI ( "shufflei",     makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDConstantBuiltinGenerator(),  INTEGERCONSTANT,   BITBLOCK,   BITBLOCK)),
     121        MVMD_SLLI (             "slli",         makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDConstantBuiltinGenerator(),  INTEGERCONSTANT,   BITBLOCK,  BITBLOCK)),
     122        MVMD_SPLAT (    "splat",        makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDConstantBuiltinGenerator(),  INTEGERCONSTANT, BITBLOCK, BITBLOCK)),
     123        MVMD_SRLI (             "srli",         makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDConstantBuiltinGenerator(),  INTEGERCONSTANT, BITBLOCK,  BITBLOCK)),
     124        SIMD_CONSTANT ( "constant",     makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDConstantBuiltinGenerator(),  INTEGERCONSTANT,   BITBLOCK)),
     125        SIMD_SLLI (             "slli",         makeRangeOfSimpleSignatures(2,BITBLOCK_SIZE, new SIMDConstantBuiltinGenerator(),  INTEGERCONSTANT,   BITBLOCK,   BITBLOCK)),
     126        SIMD_SRAI (             "srai",         makeRangeOfSimpleSignatures(2,BITBLOCK_SIZE, new SIMDConstantBuiltinGenerator(),  INTEGERCONSTANT,   BITBLOCK,   BITBLOCK)),
     127        SIMD_SRLI (             "srli",         makeRangeOfSimpleSignatures(2,BITBLOCK_SIZE, new SIMDConstantBuiltinGenerator(),  INTEGERCONSTANT,   BITBLOCK,   BITBLOCK)),
     128               
    108129        // SIMD logic operations (opPattern == 2)
    109130        // C++: simd_op(data_type arg, ...)
    110131        // C:   simd_op(data_type arg, ...)
    111         SIMD_NOR (makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDLogicBuiltinGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
    112         SIMD_NOT (makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDLogicBuiltinGenerator(),  BITBLOCK,  BITBLOCK)),
    113         SIMD_ANDC (makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDLogicBuiltinGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
    114         SIMD_OR (makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDLogicBuiltinGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
    115         SIMD_XOR (makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDLogicBuiltinGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
    116         SIMD_AND (makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDLogicBuiltinGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
     132        SIMD_NOR (      "nor",  makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDLogicBuiltinGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
     133        SIMD_NOT (      "not",  makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDLogicBuiltinGenerator(),  BITBLOCK,  BITBLOCK)),
     134        SIMD_ANDC (     "andc", makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDLogicBuiltinGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
     135        SIMD_OR (       "or",   makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDLogicBuiltinGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
     136        SIMD_XOR (      "xor",  makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDLogicBuiltinGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
     137        SIMD_AND (      "and",  makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDLogicBuiltinGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
    117138       
    118139        // SIMD (opPattern == 3)
    119140        // C++: class_name::op(data_type arg, ...)
    120141        // C:   class_name_op(data_type arg, ...)
    121         BITBLOCK_ALL (makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBitblockBuiltinGenerator(),  BITBLOCK,  BOOL)),
    122         BITBLOCK_ANY (makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBitblockBuiltinGenerator(),  BITBLOCK,  BOOL)),
    123         BITBLOCK_POPCOUNT (makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBitblockBuiltinGenerator(),  BITBLOCK,  BITFIELD)),
    124         BITBLOCK_SLL (makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBitblockBuiltinGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
    125         BITBLOCK_SRL (makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBitblockBuiltinGenerator(),  BITBLOCK, BITBLOCK,  BITBLOCK)),
     142        BITBLOCK_ALL (          "all",                  makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBitblockBuiltinGenerator(),  BITBLOCK,   BOOL)),
     143        BITBLOCK_ANY (          "any",                  makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBitblockBuiltinGenerator(),  BITBLOCK,   BOOL)),
     144        BITBLOCK_POPCOUNT (     "popcount",             makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBitblockBuiltinGenerator(),  BITBLOCK,   BITFIELD)),
     145        BITBLOCK_SLL (          "sll",                  makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBitblockBuiltinGenerator(),  BITBLOCK,   BITBLOCK,  BITBLOCK)),
     146        BITBLOCK_SRL (          "srl",                  makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBitblockBuiltinGenerator(),  BITBLOCK,   BITBLOCK,  BITBLOCK)),
    126147       
    127148        // SIMD (opPattern == 4)
    128149        // C++: class_name::op<x>(data_type arg, ...)
    129150        // C:   class_name_op(data_type arg, ..., x)
    130         BITBLOCK_SLLI (makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBitblockImmediateBuiltinGenerator(),  INTEGERCONSTANT,  BITBLOCK)),
    131         BITBLOCK_SRLI (makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBitblockImmediateBuiltinGenerator(),  INTEGERCONSTANT,  BITBLOCK)),
     151        BITBLOCK_SLLI (         "slli"  ,       makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBitblockImmediateBuiltinGenerator(),  INTEGERCONSTANT,  BITBLOCK,  BITBLOCK)),
     152        BITBLOCK_SRLI (         "srli"  ,       makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBitblockImmediateBuiltinGenerator(),  INTEGERCONSTANT,  BITBLOCK,  BITBLOCK)),
    132153       
    133154        // SIMD Stores (with args = (Bitblock, Bitblock*))
    134         BITBLOCK_STORE_ALIGNED (makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBitblockStoreBuiltinGenerator(),  BITBLOCK, BITBLOCK_POINTER,  VOID)),
    135         BITBLOCK_STORE_UNALIGNED (makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBitblockStoreBuiltinGenerator(),  BITBLOCK, BITBLOCK_POINTER,  VOID)),
     155        BITBLOCK_STORE_ALIGNED (        "store_aligned",        makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBitblockStoreBuiltinGenerator(),  BITBLOCK, BITBLOCK_POINTER,  VOID)),
     156        BITBLOCK_STORE_UNALIGNED (      "store_unaligned",      makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBitblockStoreBuiltinGenerator(),  BITBLOCK, BITBLOCK_POINTER,  VOID)),
    136157       
    137158        // SIMD Loads (with args = Bitblock*)
    138         BITBLOCK_LOAD_ALIGNED (makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBitblockLoadBuiltinGenerator(),  BITBLOCK_POINTER,  BITBLOCK)),
    139         BITBLOCK_LOAD_UNALIGNED (makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBitblockLoadBuiltinGenerator(),  BITBLOCK_POINTER,  BITBLOCK));
    140 
    141         private static final Map<String, IDISABuiltin> operationName2IDISABuilinMap = new HashMap<String, IDISABuiltin>();
     159        BITBLOCK_LOAD_ALIGNED (         "load_aligned",         makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBitblockLoadBuiltinGenerator(),  BITBLOCK_POINTER,  BITBLOCK)),
     160        BITBLOCK_LOAD_UNALIGNED (       "load_unaligned",       makeAllSimpleSignatures(BITBLOCK_SIZE, new SIMDBitblockLoadBuiltinGenerator(),  BITBLOCK_POINTER,  BITBLOCK)),
     161
     162        NULL_BUILTIN("Null");
     163       
     164        private static final Map<String, IDISABuiltin> builtinForName = new HashMap<String, IDISABuiltin>();
    142165           
    143166        static {
    144167                for(IDISABuiltin idisaBuiltin : values()) {
    145                         operationName2IDISABuilinMap.put(idisaBuiltin.toString(), idisaBuiltin);
     168                        builtinForName.put(idisaBuiltin.fullyQualifiedName(), idisaBuiltin);
    146169                }
    147170    }
    148171       
    149     public static IDISABuiltin fromString(String operationName) {
    150         return operationName2IDISABuilinMap.get(operationName);
     172    public static IDISABuiltin forName(String fullyQualifiedName) {
     173        if(builtinForName.containsKey(fullyQualifiedName)) {
     174                return builtinForName.get(fullyQualifiedName);
     175        }
     176        return NULL_BUILTIN;
    151177    }
    152178   
    153         private IDISAFunctionSignature [] signatures;
    154        
     179    private String name;
     180        private ParameterizedFunctionSignature [] signatures;
     181       
     182        private IDISABuiltin(String name, ParameterizedFunctionSignature ...signatures) {
     183                this.name = name;
     184                this.signatures = signatures;
     185        }
    155186        //private IDISABuiltin(String className, String opName, IDISAFunctionSignature ...signatures) {
    156         private IDISABuiltin(IDISAFunctionSignature ...signatures) {
    157                 this.signatures    = signatures;
    158         }
    159        
    160         public String packageName() {
    161             return this.name().toLowerCase().split("_")[0];
    162         }
    163        
    164         public String baseName() {
    165             return this.name().toLowerCase().split("_")[1];
    166         }
    167        
    168         @Override
    169         public String toString() {
    170                 return this.name().toLowerCase().replaceFirst("_", ".");
    171         }
    172        
    173         public boolean hasCompileTimeConstantArgument() {
    174                 return false;
    175         }
    176 
    177         public boolean hasSignature(int fieldWidth) {
    178                 return !getSignature(fieldWidth).isNull();
    179         }
    180        
    181         public IDISAFunctionSignature getSignature(int fieldWidth) {
    182 
    183                 for(IDISAFunctionSignature signature : this.signatures) {
    184                         if(signature.matches(fieldWidth)) {
     187       
     188        /////////////////////////////////////////////////////////////////
     189        // queries
     190        /////////////////////////////////////////////////////////////////
     191        public String fullyQualifiedName() { return packageName() + "." + baseName();   }
     192        public String packageName() { return this.name().toLowerCase().split("_")[0];   }
     193        public String baseName() { return this.name; }
     194        public boolean hasSignature(int fieldWidth,  int argCount) {
     195                return !getSignature(fieldWidth, argCount).isNull();
     196        }
     197        public ParameterizedFunctionSignature getSignature(int fieldWidth, int argCount) {
     198               
     199                for(ParameterizedFunctionSignature signature : this.signatures) {
     200                        if( (signature.getFieldWidth() == fieldWidth) && (signature.getNumParameters() == argCount) ) {
    185201                                return signature;
    186202                        }
    187203                }
    188                
    189                 return IDISAFunctionSignature.nullInstance();
    190         }
    191        
    192         public boolean hasSignature(int fieldWidth, Type ... types) {
    193                 return getSignature(fieldWidth,types).isNull();
    194         }
    195        
    196         public IDISAFunctionSignature getSignature(int fieldWidth, Type ... types) {
    197 
    198                 for(IDISAFunctionSignature signature : this.signatures) {
    199                         if(signature.matches(fieldWidth,types)) {
    200                                 return signature;
    201                         }
    202                 }
    203                
    204                 return IDISAFunctionSignature.nullInstance();
    205         }
    206        
    207        
     204                return ParameterizedFunctionSignature.nullInstance();
     205        }
     206
     207        // KH:
     208        //      public boolean hasCompileTimeConstantArgument() {
     209        //      if( (parameterTypes.length > 0) && (parameterTypes[0] == PrimitiveType.INTEGERCONSTANT) ) {
     210        //              return true;
     211        //      }
     212        //      return false;
     213        //}
     214       
     215        /////////////////////////////////////////////////////////////////
     216        // generators
     217        /////////////////////////////////////////////////////////////////
    208218        /**
    209          * Makes IDISA function signatures from 2^0 to power-of-2 upper bound field width and constant arguments.
     219         * Makes IDISA function signatures from 2^0 to uppoer bound field width and constant arguments.
    210220         */
    211         private static IDISAFunctionSignature [] makeAllSimpleSignatures (int upperBound, AbstractIDISABuiltinGenerator idisaBuiltinsGenerator, Type ...types) {
    212                 return (IDISAFunctionSignature []) makeRangeOfSimpleSignatures(1, upperBound, idisaBuiltinsGenerator,types);
     221        private static ParameterizedFunctionSignature [] makeAllSimpleSignatures (int upperBound, AbstractIDISABuiltinGenerator idisaBuiltinsGenerator, Type ...types) {
     222                return (ParameterizedFunctionSignature []) makeRangeOfSimpleSignatures(1, upperBound, idisaBuiltinsGenerator,types);
    213223        }
    214224       
     
    216226         * Makes IDISA function signatures from power-of-2 lower bound to power-of-2 upper bound field width and constant arguments.
    217227         */
    218         private static IDISAFunctionSignature [] makeRangeOfSimpleSignatures (int lowerBound, int upperBound, AbstractIDISABuiltinGenerator idisaBuiltinsGenerator, Type ...types) {
    219                
    220                 ArrayList<IDISAFunctionSignature> signatures = new ArrayList<IDISAFunctionSignature>();
     228        private static ParameterizedFunctionSignature [] makeRangeOfSimpleSignatures (int lowerBound, int upperBound, AbstractIDISABuiltinGenerator idisaBuiltinsGenerator, Type ...types) {
     229               
     230                ArrayList<ParameterizedFunctionSignature> signatures = new ArrayList<ParameterizedFunctionSignature>();
    221231                       
    222232                for(int fw=lowerBound;fw<=upperBound;fw*=2) {
    223                         IDISAFunctionSignature signature = new IDISAFunctionSignature(idisaBuiltinsGenerator,fw,types);
     233                        ParameterizedFunctionSignature signature = new ParameterizedFunctionSignature(idisaBuiltinsGenerator,fw,types);
    224234                        signatures.add(signature);
    225235                }
    226236               
    227                
    228                 return (IDISAFunctionSignature []) signatures.toArray(new IDISAFunctionSignature[signatures.size()]);
    229                
    230         }
    231        
     237                return (ParameterizedFunctionSignature []) signatures.toArray(new ParameterizedFunctionSignature[signatures.size()]);
     238        }
    232239}
    233 
    234 /*
    235 
    236 1. Define IDISA builtins.
    237 2. Define FunctionSignature as an interface. 'getSignature' returns a new signature, this signature can be used to build the
    238 function signatures hash for recognition of calls.
    239 3. A 'matcher' object will serve to match function signatures.
    240 4. IDISABuiltins2Lang will translate the majority of IDISA builtins but 'special cases' will call out to helpers based on type.
    241  
    242 So, S2K creates an simd.constant<1>(0) IDISA function call with compound id, fw, arg_list. In this case the first argument is
    243 a constant integer (a primitive).
    244 
    245 IDISA Function Call looks up the function call.
    246 
    247 It finds the type 'CONSTANT1',
    248 It
    249 (1) calls the IDISA2CPP generator with the value 'CONSTANT1' and the node to make the string or
    250 (2) 
    251  
    252 */
Note: See TracChangeset for help on using the changeset viewer.