From WikiChip
Module:microarchitecture
Documentation for this module may be created at Module:microarchitecture/doc
local uarch = {}
local origArgs
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 has_arg(name)
-- The argument can exist and be empty or not exist at all
return string.len(origArgs[name] or '') > 0
end
function arg(name)
return origArgs[name]
end
function uarch.set_val(prop, val)
uarch.frame:preprocess('{{#set: ' .. prop .. '=' .. val .. '}}')
end
function uarch.uarch(frame)
uarch.frame = frame
if frame == mw.getCurrentFrame() then
origArgs = frame:getParent().args
else
origArgs = frame
end
local infobox = mw.html.create('table')
infobox
:attr('class', 'infobox')
infobox
:tag('tr')
:tag('td'):attr('colspan', '2')
:tag('small'):attr('style', 'float: right; font-weight: bold;')
:wikitext('[[Special:FormEdit/microarchitecture/' .. frame:preprocess('{{FULLPAGENAME}}') .. '|<i class="fa fa-edit"></i>Edit Values]]')
-- header
if not has_arg('name') then return tostring(infobox) .. '[[Category:Articles with invalid parameter in template]]<strong>* ERROR: "name" is missing!</strong>' end
uarch.set_val('name', arg('name'))
uarch.set_val('codename', arg('name'))
add_header_main(infobox, arg('name') .. ' µarch')
add_header(infobox, 'General Info')
if not has_arg('atype') then return tostring(infobox) .. '[[Category:Articles with invalid parameter in template]]<strong>ERROR: "atype" is missing!</strong>' end
if not has_arg('designer') then return tostring(infobox) .. '[[Category:Articles with invalid parameter in template]]<strong>ERROR: "designer" is missing!</strong>' end
-- arch type
add_entry(infobox, 'Arch Type', arg('atype') ..
'[[Category:' .. string.lower(arg('atype')) .. ' microarchitectures by ' .. string.lower(arg('designer')) .. ']]')
uarch.set_val('microarchitecture type', arg('atype'))
-- designer
local devs
uarch.set_val('designer', arg('designer'))
devs = arg('designer') .. '[[Category:microarchitectures by ' .. string.lower(arg('designer')) .. ']]'
for i = 2, 10 do
if not has_arg('designer ' .. i) then break end
uarch.set_val('designer', arg('designer ' .. i))
devs = devs .. ', ' .. arg('designer ' .. i) ..
'[[Category:microarchitectures by ' .. string.lower(arg('designer ' .. i)) .. ']]'
devs = devs ..
'[[Category:' .. string.lower(arg('atype')) .. ' microarchitectures by ' .. string.lower(arg('designer ' .. i)) .. ']]'
end
add_entry(infobox, 'Designer', devs)
-- manufacturer
if not has_arg('manufacturer') then return '[[Category:Articles with invalid parameter in template]]ERROR: "manufacturer" is missing!' end
uarch.set_val('manufacturer', arg('manufacturer'))
local devs = '[[manufacturer::' .. arg('manufacturer') .. ']]'
for i = 2, 10 do
if not has_arg('manufacturer ' .. i) then break end
uarch.set_val('manufacturer', arg('manufacturer ' .. i))
devs = devs .. ', [[manufacturer::' .. arg('manufacturer ' .. i) .. ']]'
end
add_entry(infobox, 'Manufacturer', devs)
-- intro
if has_arg('introduction') then
uarch.set_val('first launched', arg('introduction'))
add_entry(infobox, 'Introduction', arg('introduction'))
end
-- phase-out
if has_arg('phase-out') then
uarch.set_val('phase-out', arg('phase-out'))
add_entry(infobox, 'Phase-out', arg('phase-out'))
end
-- process
if has_arg('process') then
local proc
uarch.set_val('process', arg('process'))
proc = '[[' .. arg('process') .. ' process|' .. arg('process') .. ']]'
for i = 2, 10 do
if string.len(origArgs['process ' .. i] or '') == 0 then break end
uarch.set_val('process', arg('process ' .. i))
proc = proc .. ', [['.. arg('process ' .. i) .. ' process|' .. arg('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, 20 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
-- processing elements
if has_arg('processing elements') then
local pe
pe = '[[processing element count::' .. arg('processing elements') .. '| ]]'
.. arg('processing elements')
for i = 2, 20 do
if not has_arg('processing elements ' .. i) then break end
pe = pe .. ', [[processing element count::' .. arg('processing elements ' .. i) .. '| ]]'
.. arg('processing elements ' .. i)
end
add_entry(infobox, 'PE Configs', pe)
end
if has_arg('type') or has_arg('oooe') or has_arg('speculative')
or has_arg('renaming') or has_arg('stages') or has_arg('stages min')
or has_arg('decode') 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 has_arg('isa') or has_arg('features') or has_arg('extension') 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
if has_arg('l1') or has_arg('l1i') or has_arg('l1d') or
has_arg('l2') or has_arg('l3') or has_arg('l3') or
has_arg('side cache') then
add_header(infobox, 'Cache')
end
-- 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
-- L1, Unified
if string.len(origArgs.l1 or '') > 0 then
local li = origArgs.l1
if string.len(origArgs['l1 per'] or '') > 0 then
li = li .. '/' .. origArgs['l1 per']
end
if string.len(origArgs['l1 desc'] or '') > 0 then
li = li .. '<br>' .. origArgs['l1 desc']
end
add_entry(infobox, 'L1 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
-- Side $
if has_arg('side cache') then
local sidecache = arg('side cache')
if has_arg('side cache per') then
sidecache = sidecache .. '/' .. arg('side cache per')
end
if has_arg('side cache desc') then
sidecache = sidecache .. '<br>' .. arg('side cache desc')
end
add_entry(infobox, 'Side Cache', sidecache)
end
-- cores
if has_arg('core name') then
add_header(infobox, 'Cores')
local cores = arg('core name')
for i = 2, 10 do
if not has_arg('core name ' .. i) then break end
cores = cores .. ',<br>' .. arg('core name ' .. i)
end
add_entry(infobox, 'Core Names', cores)
end
if has_arg('successor') or has_arg('predecessor') then
add_header(infobox, 'Succession')
local s = infobox:tag('tr')
local td = s:tag('td'):attr('colspan', '2')
local d1 = td:tag('div'):attr('style', 'display: inline-flex;')
local d2 = td:tag('div'):attr('style', 'display: inline-flex; float: right;')
if has_arg('predecessor') then
local list
if has_arg('predecessor link') then
list = '[[' .. arg('predecessor link') .. '|' .. arg('predecessor') .. ']]'
else
list = '[[' .. arg('predecessor') .. ']]'
end
for i = 2, 10 do
if not has_arg('predecessor ' .. i) then break end
if has_arg('predecessor ' .. i .. ' link') then
list = list .. '<br>[[' .. arg('predecessor ' .. i .. ' link') .. '|' .. arg('predecessor ' .. i) .. ']]'
else
list = list .. '<br>[[' .. arg('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 has_arg('successor') then
local list
if has_arg('successor link') then
list = '[[' .. arg('successor link') .. '|' .. arg('successor') .. ']]'
else
list = '[[' .. arg('successor') .. ']]'
end
for i = 2, 10 do
if not has_arg('successor ' .. i) then break end
if has_arg('successor ' .. i .. ' link') then
list = list .. '<br>[[' .. arg('successor ' .. i .. ' link') .. '|' ..
arg('successor ' .. i) .. ']]'
else
list = list .. '<br>[[' .. arg('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
-- Contemporary
if has_arg('contemporary') then
add_header(infobox, 'Contemporary')
local s = infobox:tag('tr')
local td = s:tag('td'):attr('colspan', '2')
td:attr('style', 'text-align: center;')
local list
if has_arg('contemporary link') then
list = '[[' .. arg('contemporary link') .. '|' .. arg('contemporary') .. ']]'
else
list = '[[' .. arg('contemporary') .. ']]'
end
for i = 2, 10 do
if not has_arg('contemporary ' .. i) then break end
if has_arg('contemporary ' .. i .. ' link') then
list = list .. '<br>[[' .. arg('contemporary ' .. i .. ' link') .. '|' .. arg('contemporary ' .. i) .. ']]'
else
list = list .. '<br>[[' .. arg('contemporary ' .. i) .. ']]'
end
end
td:wikitext(list)
end
infobox:wikitext('[[Category:all microarchitectures]]')
infobox:wikitext('[[full page name::' .. frame:preprocess('{{FULLPAGENAME}}') .. '| ]]')
infobox:wikitext('[[instance of::microarchitecture| ]]')
return infobox
end
return uarch