145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#!/usr/bin/env python
245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgdef emit(opcode,suffix,width,order,optype):
445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    d = {}
545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    d['opcode']=opcode
645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    d['suffix']=suffix
745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    d['order']=order
845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    if width == 128:
945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        d['op1']= 'xmm1'
1045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        d['op2']= 'xmm2'
1145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        d['op3']= 'xmm3'
1245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        if optype == 'rrr':
1345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org            d['op3']= 'xmm3'
1445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        elif suffix == 'pd':
1545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org            d['op3']= 'dqword [rax]'
1645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        elif suffix == 'sd':
1745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org            d['op3']= 'qword [rax]'
1845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        elif suffix == 'ss':
1945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org            d['op3']= 'dword [rax]'
2045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    else:
2145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        d['op1']= 'ymm1'
2245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        d['op2']= 'ymm2'
2345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        if optype == 'rrr':
2445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org            d['op3']= 'ymm3'
2545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        else:
2645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org            d['op3']= 'yword [rax]'
2745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
2845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
2945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    print "v%(opcode)s%(order)s%(suffix)s %(op1)s, %(op2)s, %(op3)s" % (d)
3045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    if optype == 'rrm':
3145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        d['op3']= '[rax]'
3245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        print "v%(opcode)s%(order)s%(suffix)s %(op1)s, %(op2)s, %(op3)s" % (d)
3345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
3445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgdef gen(opcodes, combos, optypes, orders):
3545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    for opcode in opcodes:
3645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        for (suffix,width) in combos:
3745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org            for order in orders:
3845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org                for optype in optypes:
3945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org                    emit(opcode,suffix,width,order,optype)
4045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
4145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
4245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgif __name__ == '__main__':
4345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    orders = ['132', '231', '213']
4445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
4545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    all_combos = [('ss',128),
4645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org                  ('sd',128),
4745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org                  ('ps',128),
4845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org                  ('ps',256),
4945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org                  ('pd',128),
5045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org                  ('pd',256) ]
5145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    packed_combos = [ ('ps',128),
5245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org                      ('ps',256),
5345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org                      ('pd',128),
5445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org                      ('pd',256) ]
5545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
5645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    opcodes1 = ['fmadd', 'fmsub', 'fnmadd', 'fnmsub']
5745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    opcodes2 = ['fmaddsub', 'fmsubadd']
5845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
5945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    optypes = ['rrr','rrm']
6045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
6145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    print "[bits 64]"
6245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    gen(opcodes1,    all_combos,optypes, orders)
6345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    gen(opcodes2, packed_combos,optypes, orders)
64