From WikiChip
Module:microarchitecture
Revision as of 05:07, 25 May 2017 by David (talk | contribs)

Documentation for this module may be created at Module:microarchitecture/doc

local uarch = {}

function add_header_main(box, str)
      box
        :tag('tr')
          :tag('td')
            :attr('class', 'header-main')
            :attr('colspan', '2')
            :wikitext(str)
end
function add_header(box, str)
      box
        :tag('tr')
          :tag('td')
            :attr('class', 'header')
            :attr('colspan', '2')
            :wikitext(str)
end
function add_entry(box, label, value)
      local tag = box:tag('tr')
      
      tag:tag('td')
        :attr('class', 'label')
        :wikitext(label)
        
      tag:tag('td')
        :attr('class', 'value')
        :wikitext(value)
end

function uarch.uarch(frame)


    local origArgs
    if frame == mw.getCurrentFrame() then
        origArgs = frame:getParent().args
    else
        origArgs = frame
    end

    local infobox = mw.html.create('table')

    infobox
        :attr('class', 'infobox')
        
    -- header
    if string.len(origArgs.name or '') == 0 then return 'ERROR: "name" is missing!' end
	add_header_main(infobox, '[[codename::' .. origArgs.name .. '| ]][[name::' .. origArgs.name .. ']] µarch')

	add_header(infobox, 'General Info')

    -- arch type
    if string.len(origArgs.atype or '') == 0 then return 'ERROR: "atype" is missing!' end
	add_entry(infobox, 'Arch Type', origArgs.atype ..
		'[[microarchitecture type::' .. origArgs.atype .. '| ]]' ..
		'[[Category:' .. string.lower(origArgs.atype) .. ' microarchitectures by ' .. string.lower(origArgs.designer) .. ']]')

	-- designer
    if string.len(origArgs.designer or '') == 0 then return 'ERROR: "designer" is missing!' end
    local devs
    
    devs = '[[designer::' .. string.lower(origArgs.designer) .. '| ]]' .. origArgs.designer
    devs = devs .. '[[Category:microarchitectures by ' .. string.lower(origArgs.designer) .. ']]'
    
    for i = 2, 10 do
    	if string.len(origArgs['designer ' .. i] or '') == 0 then break end
    	devs = devs .. ', [[designer::' .. string.lower(origArgs['designer ' .. i]) .. '| ]]' ..
    			origArgs['designer ' .. i] ..
	    		'[[Category:microarchitectures by ' .. string.lower(origArgs['designer ' .. i]) .. ']]'
	end
	add_entry(infobox, 'Designer', devs)
	
	
	-- manufacturer
    if string.len(origArgs.manufacturer or '') == 0 then return 'ERROR: "manufacturer" is missing!' end
    local devs
    
    devs = '[[manufacturer::' .. string.lower(origArgs.manufacturer) .. '| ]]'
    		.. origArgs.manufacturer
    
    for i = 2, 10 do
    	if string.len(origArgs['manufacturer ' .. i] or '') == 0 then break end
    	devs = devs .. ', [[manufacturer::' .. string.lower(origArgs['manufacturer ' .. i]) .. '| ]]'
    			.. origArgs['manufacturer ' .. i]
	end
	add_entry(infobox, 'Manufacturer', devs)
	
    -- intro
    if string.len(origArgs.introduction or '') > 0 then
		add_entry(infobox, 'Introduction', '[[first launched::' .. origArgs.introduction .. ']]')
	end
	
    -- phase-out
    if string.len(origArgs.phase_out or '') > 0 then
		add_entry(infobox, 'Phase-out', '[[phase-out::' .. origArgs.phase_out .. ']]')
	end
	
	
	
	-- process
    if string.len(origArgs.process or '') > 0 then
	    local proc
	    
	    proc = '[[process::' .. origArgs.process .. '| ]]' ..
	    		'[[' ..  origArgs.process .. ' process|' ..  origArgs.process .. ']]'
	    
	    for i = 2, 10 do
	    	if string.len(origArgs['process_' .. i] or '') == 0 then break end
	    	proc = proc .. ', [[process::' ..origArgs['process_' .. i] .. '| ]]'
	    			.. '[['..  origArgs['process_' .. i] .. ' process|' .. origArgs['process_' .. i] .. ']]'
		end
		add_entry(infobox, 'Process', proc)
	end	
	
	
	-- cores
    if string.len(origArgs.cores or '') > 0 then
	    local core
	    
	    core = '[[core count::' .. origArgs.cores .. '| ]]'
	    	.. '[[' .. origArgs.cores .. ' cores|' .. origArgs.cores .. ']]'
	    
	    for i = 2, 10 do
	    	if string.len(origArgs['cores_' .. i] or '') == 0 then break end
	    	core = core .. ', [[core count::' ..origArgs['cores_' .. i] .. '| ]]'
	    		.. '[[' .. origArgs['cores_' .. i] .. ' cores|' .. origArgs['cores_' .. i] .. ']]'
		end
		add_entry(infobox, 'Core Configs', core)
	end
	
	
	add_header(infobox, 'Pipeline')
	
	-- type
    if string.len(origArgs.ptype or '') > 0 then
	    local ptype
	    
	    ptype = origArgs.ptype
	    for i = 2, 10 do
	    	if string.len(origArgs['ptype_' .. i] or '') == 0 then break end
	    	ptype = ptype .. ', ' .. origArgs['ptype_' .. i]
		end
		add_entry(infobox, 'Type', ptype)
	end
	
    -- oooe
    if string.len(origArgs.oooe or '') > 0 then
		add_entry(infobox, 'OoOE', origArgs.oooe)
	end
	
    -- speculative
    if string.len(origArgs.speculative or '') > 0 then
		add_entry(infobox, 'Speculative', origArgs.speculative)
	end
	
    -- reg_renaming
    if string.len(origArgs.reg_renaming or '') > 0 then
		add_entry(infobox, 'Reg Renaming', origArgs.reg_renaming)
	end
	
    -- pstage
    if string.len(origArgs.pstage or '') > 0 then
		add_entry(infobox, 'Stages', '[[pipeline stages::' .. origArgs.pstage .. ']]')
	end
	
    -- pstage min/max
    if string.len(origArgs.pstages_min or '') > 0 then
		add_entry(infobox, 'Stages',
			'[[pipeline stages (min)::' .. origArgs.pstages_min .. ']]'
			.. '-[[pipeline stages (max)::' .. origArgs.pstages_max .. ']]')
	end
	
    -- decode
    if string.len(origArgs.decode or '') > 0 then
		add_entry(infobox, 'Decode', origArgs.decode)
	end
	
	
	add_header(infobox, 'Instructions')
	
	-- ISA
    if string.len(origArgs.isa or '') > 0 then
	    local isa
	    
	    isa = '[[instruction set architecture::' .. origArgs.isa .. ']]'
	    for i = 2, 10 do
	    	if string.len(origArgs['isa_' .. i] or '') == 0 then break end
	    	isa = isa .. ', ' .. '[[instruction set architecture::' .. origArgs['isa_' .. i] .. ']]'
		end
		add_entry(infobox, 'ISA', isa)
	end
	
	-- features
    if string.len(origArgs.features or '') > 0 then
	    local features
	    
	    features = origArgs.features
	    for i = 2, 10 do
	    	if string.len(origArgs['features_' .. i] or '') == 0 then break end
	    	features = features .. ', ' .. origArgs['features_' .. i]
		end
		add_entry(infobox, 'Features', features)
	end
	
	-- extensions
    if string.len(origArgs.extensions or '') > 0 then
	    local extensions
	    
	    extensions = origArgs.extensions
	    for i = 2, 40 do
	    	if string.len(origArgs['extensions_' .. i] or '') == 0 then break end
	    	extensions = extensions .. ', ' .. origArgs['extensions_' .. i]
		end
		add_entry(infobox, 'Extensions', extensions)
	end
	
	add_header(infobox, 'Cache')
	
    -- L1i
    if string.len(origArgs.l1i or '') > 0 then
    	local li = origArgs.l1i
    	if string.len(origArgs.l1i_per or '') > 0 then
    		li = li .. '/' .. origArgs.l1i_per
		end
    	if string.len(origArgs.l1i_desc or '') > 0 then
    		li = li .. '<br>' .. origArgs.l1i_desc
		end
		add_entry(infobox, 'L1I Cache',  li)
	end
	
    -- L1d
    if string.len(origArgs.l1d or '') > 0 then
    	local li = origArgs.l1d
    	if string.len(origArgs.l1d_per or '') > 0 then
    		li = li .. '/' .. origArgs.l1d_per
		end
    	if string.len(origArgs.l1d_desc or '') > 0 then
    		li = li .. '<br>' .. origArgs.l1d_desc
		end
		add_entry(infobox, 'L1D Cache',  li)
	end
	
    -- L2
    if string.len(origArgs.l2 or '') > 0 then
    	local l2 = origArgs.l2
    	if string.len(origArgs.l2_per or '') > 0 then
    		l2 = l2 .. '/' .. origArgs.l2_per
		end
    	if string.len(origArgs.l2_desc or '') > 0 then
    		l2 = l2 .. '<br>' .. origArgs.l2_desc
		end
		add_entry(infobox, 'L2 Cache',  l2)
	end
	
    -- L3
    if string.len(origArgs.l3 or '') > 0 then
    	local l3 = origArgs.l3
    	if string.len(origArgs.l3_per or '') > 0 then
    		l3 = l3 .. '/' .. origArgs.l3_per
		end
    	if string.len(origArgs.l3_desc or '') > 0 then
    		l3 = l3 .. '<br>' .. origArgs.l3_desc
		end
		add_entry(infobox, 'L3 Cache',  l3)
	end
	
    -- L4
    if string.len(origArgs.l4 or '') > 0 then
    	local l4 = origArgs.l4
    	if string.len(origArgs.l4_per or '') > 0 then
    		l4 = l4 .. '/' .. origArgs.l4_per
		end
    	if string.len(origArgs.l4_desc or '') > 0 then
    		l4 = l4 .. '<br>' .. origArgs.l4_desc
		end
		add_entry(infobox, 'L4 Cache',  l4)
	end
	
    -- Size $
    if string.len(origArgs.sizecache or '') > 0 then
    	local sizecache = origArgs.sizecache
    	if string.len(origArgs.sizecache_per or '') > 0 then
    		sizecache = sizecache .. '/' .. origArgs.sizecache_per
		end
    	if string.len(origArgs.sizecache_desc or '') > 0 then
    		sizecache = sizecache .. '<br>' .. origArgs.sizecache_desc
		end
		add_entry(infobox, 'Size Cache',  sizecache)
	end
	
	
	add_header(infobox, 'Cores')
	
	
	-- cores
    if string.len(origArgs.core_name or '') > 0 then
	    local cores
	    
	    cores = origArgs.core_name
	    for i = 2, 10 do
	    	if string.len(origArgs['core_name_' .. i] or '') == 0 then break end
	    	cores = cores .. ', ' .. origArgs['core_name_' .. i]
		end
		add_entry(infobox, 'Core Names', features)
	end
	
	if string.len(origArgs.successor or '') > 0
	or string.len(origArgs.predecessor or '') > 0 then
		add_header(infobox, 'Succession')
		
		local s = infobox:tag('tr')
		local d1 = s:tag('td'):tag('div'):attr('style', 'display: inline-flex;')
		local d2 = s:tag('td'):tag('div'):attr('style', 'display: inline-flex; float: right;')
		if string.len(origArgs.predecessor or '') > 0 then
			
		    local list
		    if string.len(origArgs.predecessor_link or '') > 0 then
				list = '[[' .. origArgs.predecessor_link .. '|' .. origArgs.predecessor .. ']]'
			else
				list = '[[' .. origArgs.predecessor .. ']]'
			end
		    for i = 2, 10 do
		    	if string.len(origArgs['predecessor_' .. i] or '') == 0 then break end
		    	if string.len(origArgs['predecessor_link_' .. i] or '') > 0 then
		    		list = list .. '<br>[[' .. origArgs['predecessor_link_' .. i] .. '|' ..
		    			origArgs['predecessor_' .. i] .. ']]'
	    		else
		    		list = list .. '<br>[[' .. origArgs['predecessor_' .. i] .. ']]'
    			end
			end
			
			d1:tag('div')
				:attr('style', 'float: left; padding-right: 10px; margin: auto 5px;')
				:wikitext('<i class="fa fa-chevron-left"></i>')
			d1:tag('div')
				:attr('style', 'float: left;')
				:wikitext(list)
		end
		if string.len(origArgs.successor or '') > 0 then
			local list
		    if string.len(origArgs.successor_link or '') > 0 then
				list = '[[' .. origArgs.successor_link .. '|' .. origArgs.successor .. ']]'
			else
				list = '[[' .. origArgs.successor .. ']]'
			end
		    for i = 2, 10 do
		    	if string.len(origArgs['successor_' .. i] or '') == 0 then break end
		    	if string.len(origArgs['successor_link_' .. i] or '') > 0 then
		    		list = list .. '<br>[[' .. origArgs['successor_link_' .. i] .. '|' ..
		    			origArgs['successor_' .. i] .. ']]'
	    		else
		    		list = list .. '<br>[[' .. origArgs['successor_' .. i] .. ']]'
    			end
			end
			
			d2:tag('div')
				:attr('style', 'float: left;')
				:wikitext(list)
			d2:tag('div')
				:attr('style', 'float: right; padding-left: 10px; margin: auto 5px;')
				:wikitext('<i class="fa fa-chevron-right"></i>')
		end
	end
            
    infobox:wikitext('[[Category:all microarchitectures]]')
    infobox:wikitext('[[full page name::{{FULLPAGENAME}}| ]]')
    infobox:wikitext('[[instance of::microarchitecture| ]]')
	
	return infobox
end

return uarch