Changeset 1539


Ignore:
Timestamp:
Oct 21, 2011, 12:27:38 AM (8 years ago)
Author:
huah
Message:

add idisa.hpp for a generic programming interface and fixed the compilation warning on 64-bit integer

Location:
trunk
Files:
18 added
1 deleted
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/libgen/Configure/configure.py

    r1521 r1539  
    3232Macro_Idisa128_Hpp = r'''
    3333#if defined USE_SSE3
    34 #include "cpp/idisa_sse3.cpp"
     34#include "idisa_cpp/idisa_sse3.cpp"
    3535#elif defined USE_SSSE3
    36 #include "cpp/idisa_ssse3.cpp"
     36#include "idisa_cpp/idisa_ssse3.cpp"
    3737#elif defined USE_SSE4_1
    38 #include "cpp/idisa_sse4_1.cpp"
     38#include "idisa_cpp/idisa_sse4_1.cpp"
    3939#elif defined USE_SSE4_2
    40 #include "cpp/idisa_sse4_2.cpp"
     40#include "idisa_cpp/idisa_sse4_2.cpp"
    4141#else
    42 #include "cpp/idisa_sse2.cpp"
     42#include "idisa_cpp/idisa_sse2.cpp"
    4343#endif
    4444'''
    4545
    4646Macro_Idisa256_Hpp = r'''
    47 #include "cpp/idisa_avx.cpp"
     47#include "idisa_cpp/idisa_avx.cpp"
     48'''
     49
     50Macro_Idisa_Hpp = r'''
     51#ifndef BLOCKSIZE
     52#define BLOCKSIZE 128
     53#endif
     54
     55#if (BLOCKSIZE == 128)
     56#include "idisa128.hpp"
     57#define Bitblock bitblock128_t
     58template <uint32_t fw>
     59class simd: public simd128<fw>
     60{
     61};
     62template <uint32_t fw>
     63class hsimd: public hsimd128<fw>
     64{
     65};
     66template <uint32_t fw>
     67class esimd: public esimd128<fw>
     68{
     69};
     70template <uint32_t fw>
     71class mvmd: public mvmd128<fw>
     72{
     73};
     74class bitblock: public bitblock128
     75{
     76};
     77#endif
     78
     79#if (BLOCKSIZE == 256)
     80#include "idisa256.hpp"
     81#define Bitblock bitblock256_t
     82template <uint32_t fw>
     83class simd: public simd256<fw>
     84{
     85};
     86template <uint32_t fw>
     87class hsimd: public hsimd256<fw>
     88{
     89};
     90template <uint32_t fw>
     91class esimd: public esimd256<fw>
     92{
     93};
     94template <uint32_t fw>
     95class mvmd: public mvmd256<fw>
     96{
     97};
     98class bitblock: public bitblock256
     99{
     100};
     101#endif
    48102'''
    49103
  • trunk/libgen/Library_Generator/CppTranslator.py

    r1535 r1539  
    240240                return {"codes":codes, "returnType":StandardTypes.GetAppropriatePythonType(codes)}
    241241
     242        def CheckNumCodes(self, codes):
     243                if codes[-1] == "L":
     244                        return codes[0:-1] + "UL"
     245                elif int(codes) >= (1<<31):
     246                        return codes + "UL"
     247                return codes
     248       
    242249        binop = {"Add":"+", "Sub":"-", "Mult":"*", "Div":"/", "Mod":"%",\
    243250                        "LShift":"<<", "RShift":">>", "BitOr":"|", "BitXor":"^", "BitAnd":"&",\
     
    254261                try:
    255262                        codes = repr(eval(codes))
     263                        codes = self.CheckNumCodes(codes)
    256264                except:
    257265                        pass
  • trunk/libgen/Library_Generator/LibraryGenerator.py

    r1521 r1539  
    7575       
    7676        if options.use_generator:
     77                Utility.outputOpt = options.body.lower()
    7778                Main(options.arch.upper(), options.lang.upper(), options.idisa_file, options.body.lower())
    7879        else:
  • trunk/libgen/Library_Generator/Operation.py

    r1521 r1539  
    6969                if fw > 0:
    7070                        self.PostParsing(opDescription)
     71               
     72                self.newClassType = self.classType + (str(configure.RegisterSize[arch]) if Utility.outputOpt != configure.Body_All else "")
    7173       
    7274        def PostParsing(self, opDescription):
     
    185187                #print "in args ", args, " self args", self.arguments, " cur op ", self.name, "curlen= ", len(args)
    186188                if len(args) != len(self.arguments):
    187                         print "The operation " + self.classType + "::" + self.name + " doesn't accept this many arguments!"
    188                         sys.exit()
    189                
    190                 cppText = self.classType + "<" + str(fw) + ">" + "::" + self.name
     189                        print "The operation " + self.newClassType + "::" + self.name + " doesn't accept this many arguments!"
     190                        sys.exit()
     191               
     192                cppText = self.newClassType + "<" + str(fw) + ">" + "::" + self.name
    191193                if self.opPattern == 1:
    192194                        #simd<fw>::op<val>(...)
     
    198200                        cppText = self.name
    199201                elif self.opPattern == 3:
    200                         cppText = self.classType + "::" + self.name
     202                        cppText = self.newClassType + "::" + self.name
    201203               
    202204                cppText += "("
  • trunk/libgen/Library_Generator/UI.py

    r1521 r1539  
    9797                       
    9898                        if whichContent == configure.Body_Declaration:
    99                                 codes += configure.Macro_Idisa128_Hpp if "idisa128" in outfile.lower() else configure.Macro_Idisa256_Hpp
     99                                codes += configure.Macro_Idisa128_Hpp if "idisa128" in outfile.lower() else (configure.Macro_Idisa256_Hpp if "idisa256" in outfile.lower() else configure.Macro_Idisa_Hpp)
    100100                        elif whichContent == configure.Body_Implementation:
    101101                                codes += '''#include "''' + configure.InstructionSetLibrary[arch] + '''"\n\n'''
     
    134134               
    135135                for classType in allClasses:
    136                         curClass = Utility.LibClass(classType, [], False if classType=="bitblock" else True)
     136                        if whichContent == configure.Body_All:
     137                                curClass = Utility.LibClass(classType, [], False if classType=="bitblock" else True)
     138                        else:
     139                                curClass = Utility.LibClass(classType, [], False if classType=="bitblock" else True, arch)
    137140                        operationImp[classType] = {}
    138141                        operationDecla[classType] = {}
  • trunk/libgen/Library_Generator/Utility.py

    r1521 r1539  
    3232usedFunctionSupport = {}
    3333
     34outputOpt = configure.Body_All
    3435#This is an interface for returning the calling statements of a function given its all arguments
    3536#e.g. given function name = "foo" and arguments = [arg1, arg2], then it returns "foo(arg1, arg2)"
     
    106107# LibVariable is the class to describe general interfaces of variables(it only has two fields, variable type & name)
    107108class LibClass:
    108         def __init__(self, name, body=[], templatedClass=True):
     109        def __init__(self, name, body=[], templatedClass=True, arch=""):
    109110                self.name = name
    110111                self.type = "class"
    111112                self.body = []
    112113                self.templatedClass = templatedClass
     114                self.regSize = str(configure.RegisterSize[arch]) if outputOpt != configure.Body_All else ""
     115                self.name = self.name + self.regSize
    113116               
    114117        def Append(self, element):
     
    142145                self.cost = cost
    143146                self.body = body
     147                self.regSize = str(configure.RegisterSize[self.arch]) if outputOpt != configure.Body_All else ""
     148                self.classType = self.classType + self.regSize
     149                self.inlineStr = "IDISA_ALWAYS_INLINE" if outputOpt != configure.Body_All else "inline"
    144150       
    145151        #def SetBodyContent(self, body):
     
    155161                text = ""
    156162                if self.opPattern == 0 or self.opPattern == 3:
    157                         text += "static inline " + self.returnType + " " + self.name + "(" + self.ArgumentsToCppText() + ")"
     163                        text += "static " + self.inlineStr + " " + self.returnType + " " + self.name + "(" + self.ArgumentsToCppText() + ")"
    158164                elif self.opPattern == 1:
    159                         text += "template <" + self.templateArg.type + " " + self.templateArg.name + "> " + "static inline " + self.returnType + " " + self.name + "(" + self.ArgumentsToCppText() + ")"
     165                        text += "template <" + self.templateArg.type + " " + self.templateArg.name + "> " + "static " + self.inlineStr + " " + self.returnType + " " + self.name + "(" + self.ArgumentsToCppText() + ")"
    160166                return text# + " __attribute__ ((always_inline))"
    161167       
     
    163169                text = "template <> "
    164170                if self.opPattern == 0:
    165                         text += "inline " + self.returnType + " " + self.classType + "<" + str(self.fieldWidth) + ">" + "::" + self.name + "(" + self.ArgumentsToCppText() + ")"
     171                        text += self.inlineStr + " " + self.returnType + " " + self.classType + "<" + str(self.fieldWidth) + ">" + "::" + self.name + "(" + self.ArgumentsToCppText() + ")"
    166172                elif self.opPattern == 1:
    167                         text += "template <" + self.templateArg.type + " " + self.templateArg.name + ">" + " inline " + self.returnType + " " + self.classType + "<" + str(self.fieldWidth) + ">" + "::" + self.name + "(" + self.ArgumentsToCppText() + ")"
     173                        text += "template <" + self.templateArg.type + " " + self.templateArg.name + ">" + " " + self.inlineStr + " " + self.returnType + " " + self.classType + "<" + str(self.fieldWidth) + ">" + "::" + self.name + "(" + self.ArgumentsToCppText() + ")"
    168174                elif self.opPattern == 2:
    169                         text = "inline " + self.returnType + " " + self.name + "(" + self.ArgumentsToCppText() + ")"
     175                        text = self.inlineStr + " " + self.returnType + " " + self.name + "(" + self.ArgumentsToCppText() + ")"
    170176                elif self.opPattern == 3:
    171                         text = "inline " + self.returnType + " " + self.classType + "::" + self.name + "(" + self.ArgumentsToCppText() + ")"
     177                        text = self.inlineStr + " " + self.returnType + " " + self.classType + "::" + self.name + "(" + self.ArgumentsToCppText() + ")"
    172178                return text
    173179               
  • trunk/libgen/Library_Tester/utility.h

    r1535 r1539  
    1 #include "idisa_avx.h"
    2 #define USE_AVX
    3 typedef __m256 SIMD_type;
     1#include "idisa_sse2.h"
     2#define USE_SSE
     3typedef __m128i SIMD_type;
    44#include <iostream>
    55#include <sstream>
  • trunk/libgen/Makefile

    r1521 r1539  
    33TESTER_DIR = Library_Tester
    44CONFIGURE_DIR = Configure
     5LIB_DIR = ../lib
    56IDISA_LIB_DIR = idisa_lib
    6 IDISA_LIB_CPP_DIR = $(IDISA_LIB_DIR)/cpp
     7IDISA_LIB_CPP_DIR = $(IDISA_LIB_DIR)/idisa_cpp
    78
    89IDISA_GENERATOR = $(GENERATOR_DIR)/LibraryGenerator.py
     
    2526
    2627IDISA256 = idisa256
     28
     29IDISA = idisa
    2730
    2831BODY_DECLARATION = declaration
     
    6871        # copys the idisa128.hpp from generator's directory to idisa_lib/
    6972        python $(IDISA_GENERATOR) -a sse2 -l cpp -f $(IDISA128).hpp -g --body=$(BODY_DECLARATION)
    70         cp $(GENERATOR_DIR)/$(IDISA128).hpp $(IDISA_LIB_DIR)/
     73        mv $(GENERATOR_DIR)/$(IDISA128).hpp $(IDISA_LIB_DIR)/
    7174       
    7275        # produces the idisa_sse2/sse3/ssse3/sse4_1/sse4_2.cpp containing the implementation of idisa operations
    7376        # copys the idisa_sse2/sse3/ssse3/sse4_1/sse4_2.cpp from generator's directory to idisa_lib/cpp/
    7477        python $(IDISA_GENERATOR) -a sse2 -l cpp -f $(IDISA_SSE2_CPP_LIB).cpp -g --body=$(BODY_IMPLEMENTATION)
    75         cp $(GENERATOR_DIR)/$(IDISA_SSE2_CPP_LIB).cpp $(IDISA_LIB_CPP_DIR)/
     78        mv $(GENERATOR_DIR)/$(IDISA_SSE2_CPP_LIB).cpp $(IDISA_LIB_CPP_DIR)/
    7679       
    7780        python $(IDISA_GENERATOR) -a sse3 -l cpp -f $(IDISA_SSE3_CPP_LIB).cpp -g --body=$(BODY_IMPLEMENTATION)
    78         cp $(GENERATOR_DIR)/$(IDISA_SSE3_CPP_LIB).cpp $(IDISA_LIB_CPP_DIR)/
     81        mv $(GENERATOR_DIR)/$(IDISA_SSE3_CPP_LIB).cpp $(IDISA_LIB_CPP_DIR)/
    7982       
    8083        python $(IDISA_GENERATOR) -a ssse3 -l cpp -f $(IDISA_SSSE3_CPP_LIB).cpp -g --body=$(BODY_IMPLEMENTATION)
    81         cp $(GENERATOR_DIR)/$(IDISA_SSSE3_CPP_LIB).cpp $(IDISA_LIB_CPP_DIR)/
     84        mv $(GENERATOR_DIR)/$(IDISA_SSSE3_CPP_LIB).cpp $(IDISA_LIB_CPP_DIR)/
    8285       
    8386        python $(IDISA_GENERATOR) -a sse4_1 -l cpp -f $(IDISA_SSE4_1_CPP_LIB).cpp -g --body=$(BODY_IMPLEMENTATION)
    84         cp $(GENERATOR_DIR)/$(IDISA_SSE4_1_CPP_LIB).cpp $(IDISA_LIB_CPP_DIR)/
     87        mv $(GENERATOR_DIR)/$(IDISA_SSE4_1_CPP_LIB).cpp $(IDISA_LIB_CPP_DIR)/
    8588       
    8689        python $(IDISA_GENERATOR) -a sse4_2 -l cpp -f $(IDISA_SSE4_2_CPP_LIB).cpp -g --body=$(BODY_IMPLEMENTATION)
    87         cp $(GENERATOR_DIR)/$(IDISA_SSE4_2_CPP_LIB).cpp $(IDISA_LIB_CPP_DIR)/
     90        mv $(GENERATOR_DIR)/$(IDISA_SSE4_2_CPP_LIB).cpp $(IDISA_LIB_CPP_DIR)/
    8891
    8992idisa256:
     
    9194        # copys the idisa256.cpp from generator's directory to idisa_lib/
    9295        python $(IDISA_GENERATOR) -a avx -l cpp -f $(IDISA256).hpp -g --body=$(BODY_DECLARATION)
    93         cp $(GENERATOR_DIR)/$(IDISA256).hpp $(IDISA_LIB_DIR)/
     96        mv $(GENERATOR_DIR)/$(IDISA256).hpp $(IDISA_LIB_DIR)/
    9497       
    9598        # produces the idisa_avx.hpp containing the implementation of idisa operations
    9699        # copys the idisa_avx.hpp from generator's directory to idisa_lib/cpp/
    97100        python $(IDISA_GENERATOR) -a avx -l cpp -f $(IDISA_AVX_CPP_LIB).cpp -g --body=$(BODY_IMPLEMENTATION)
    98         cp $(GENERATOR_DIR)/$(IDISA_AVX_CPP_LIB).cpp $(IDISA_LIB_CPP_DIR)/
     101        mv $(GENERATOR_DIR)/$(IDISA_AVX_CPP_LIB).cpp $(IDISA_LIB_CPP_DIR)/
     102
     103idisa:
     104        make idisa128
     105        make idisa256
     106        python $(IDISA_GENERATOR) -a sse2 -l cpp -f $(IDISA).hpp -g --body=$(BODY_DECLARATION)
     107        mv $(GENERATOR_DIR)/$(IDISA).hpp $(IDISA_LIB_DIR)/
     108       
     109        cp -rf $(IDISA_LIB_CPP_DIR)/ $(LIB_DIR)/
     110        cp $(IDISA_LIB_DIR)/$(IDISA128).hpp $(LIB_DIR)/
     111        cp $(IDISA_LIB_DIR)/$(IDISA256).hpp $(LIB_DIR)/
     112        cp $(IDISA_LIB_DIR)/$(IDISA).hpp $(LIB_DIR)/
    99113
    100114clean:
    101115        rm -f $(GENERATOR_DIR)/*.pyc
     116        rm -f $(GENERATOR_DIR)/idisa*.*
    102117        rm -f $(TESTER_DIR)/*.pyc
     118        rm -f $(TESTER_DIR)/*test.cpp
     119        rm -f $(TESTER_DIR)/SS*_test
     120        rm -f $(TESTER_DIR)/AVX*_test
     121        rm -f $(TESTER_DIR)/idisa*.*
     122        rm -f $(TESTER_DIR)/input/*
     123        rm -f $(TESTER_DIR)/output/*
     124        rm -f $(TESTER_DIR)/output_temp/*
    103125        rm -f $(CONFIGURE_DIR)/*.pyc
  • trunk/libgen/idisa_lib/idisa128.hpp

    r1521 r1539  
    33
    44#if defined USE_SSE3
    5 #include "cpp/idisa_sse3.cpp"
     5#include "idisa_cpp/idisa_sse3.cpp"
    66#elif defined USE_SSSE3
    7 #include "cpp/idisa_ssse3.cpp"
     7#include "idisa_cpp/idisa_ssse3.cpp"
    88#elif defined USE_SSE4_1
    9 #include "cpp/idisa_sse4_1.cpp"
     9#include "idisa_cpp/idisa_sse4_1.cpp"
    1010#elif defined USE_SSE4_2
    11 #include "cpp/idisa_sse4_2.cpp"
     11#include "idisa_cpp/idisa_sse4_2.cpp"
    1212#else
    13 #include "cpp/idisa_sse2.cpp"
     13#include "idisa_cpp/idisa_sse2.cpp"
    1414#endif
    1515#endif
  • trunk/libgen/idisa_lib/idisa256.hpp

    r1521 r1539  
    22#define IDISA256_HPP
    33
    4 #include "cpp/idisa_avx.cpp"
     4#include "idisa_cpp/idisa_avx.cpp"
    55#endif
Note: See TracChangeset for help on using the changeset viewer.