From WikiChip
Module:microarchitecture
Revision as of 07:19, 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
	
	if string.len(origArgs.pipeline or '') > 0 then
		add_header(infobox, 'Pipeline')
	end
	
	-- type
    if string.len(origArgs['type'] or '') > 0 then
	    local ptype
	    
	    ptype = origArgs['type']
	    for i = 2, 10 do
	    	if string.len(origArgs['type ' .. i] or '') == 0 then break end
	    	ptype = ptype .. ', ' .. origArgs['type ' .. 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
	
    -- renaming
    if string.len(origArgs.renaming or '') > 0 then
		add_entry(infobox, 'Reg Renaming', origArgs.renaming)
	end
	
    -- stages
    if string.len(origArgs.stages or '') > 0 then
		add_entry(infobox, 'Stages', '[[pipeline stages::' .. origArgs.stages .. ']]')
	end
	
    -- stages min/max
    if string.len(origArgs['stages min'] or '') > 0 then
		add_entry(infobox, 'Stages',
			'[[pipeline stages (min)::' .. origArgs['stages min'] .. ']]'
			.. '-[[pipeline stages (max)::' .. origArgs['stages max'] .. ']]')
	end
	
    -- decode
    if string.len(origArgs.decode or '') > 0 then
		add_entry(infobox, 'Decode', origArgs.decode)
	end
	
	
    if string.len(origArgs.isa or '') > 0 then
		add_header(infobox, 'Instructions')
	end
	
	-- 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.extension or '') > 0 then
	    local extension
	    
	    extension = origArgs.extension
	    for i = 2, 40 do
	    	if string.len(origArgs['extension ' .. i] or '') == 0 then break end
	    	extension = extension .. ', ' .. origArgs['extension ' .. i]
		end
		add_entry(infobox, 'Extensions', extension)
	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', cores)
	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