From WikiChip
Difference between revisions of "Module:frequency table"

Line 52: Line 52:
 
     if has_arg('freq_avx512_' .. i) then avx512N = i; avx512 = true end
 
     if has_arg('freq_avx512_' .. i) then avx512N = i; avx512 = true end
 
end
 
end
 +
local maxN = math.max(normN, avx2N, avx512N)
 
 
 
 
Line 61: Line 62:
 
          
 
          
 
     local tr = tbl:tag('tr')
 
     local tr = tbl:tag('tr')
    tr:tag('th'):attr('colspan', '2')
+
tr:tag('th'):attr('rowspan', '2'):wikitext('Mode')
     tr:tag('th'):attr('colspan', i):wikitext('Frequency/Active Cores')
+
tr:tag('th'):attr('rowspan', '2'):wikitext('Base')
 +
     tr:tag('th'):attr('colspan', maxN):wikitext('Frequency/Active Cores')
 
    
 
    
 
tr = tbl:tag('tr')
 
tr = tbl:tag('tr')
tr:tag('th'):wikitext('Mode')
+
for i = 1, maxN do
tr:tag('th'):wikitext('Base')
 
for i = 1, math.max(normN, avx2N, avx512N) do
 
 
tr:tag('th'):wikitext(i)
 
tr:tag('th'):wikitext(i)
 
end
 
end

Revision as of 20:27, 16 July 2017

To add this template, simple add
{{frequency table}}
to the page and save. The chip infobox will have a small [Modify Frequency Info] button at the top-right corner which can be used to add values using a form.
local p = {}
local origArgs

function p.add_file_prefix(str)
  if string.match(string.lower(str), '^file:') then
    return str
  else
    return 'File:' .. str
  end
end

function p.add_separator(box, title)
  box:tag('tr')
           :tag('td')
           :attr('class', 'header')
           :attr('colspan', '2')
           :wikitext(title)
end

function p.add_entry(value, right)
  local e = mw.html.create('tr')
  e:tag('td')
    :attr('class', 'label')
    :wikitext(value)
  e:node(right)
  return e   
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 p.frequency_table(frame)
	
    if frame == mw.getCurrentFrame() then
        origArgs = frame:getParent().args
    else
        origArgs = frame.args
    end
    
    local norm, avx2, avx512 = false, false, false
    
    local normN, avx2N, avx512N = 0, 0, 0
    for i = 1, 50 do
    	if	has_arg('freq_' .. i) then normN = i; norm = true end
    	if	has_arg('freq_avx2_' .. i) then avx2N = i; avx2 = true end
    	if	has_arg('freq_avx512_' .. i) then avx512N = i; avx512 = true end
	end
	local maxN = math.max(normN, avx2N, avx512N)
	
	
    local tbl = mw.html.create('table')

    tbl
        :attr('class', 'wikitable')
        :attr('style', 'margin-left: 10px;')
        
    local tr = tbl:tag('tr')
		tr:tag('th'):attr('rowspan', '2'):wikitext('Mode')
		tr:tag('th'):attr('rowspan', '2'):wikitext('Base')
    	tr:tag('th'):attr('colspan', maxN):wikitext('Frequency/Active Cores')
    	
	tr = tbl:tag('tr')
		for i = 1, maxN do
			tr:tag('th'):wikitext(i)	
		end
	
	if norm or has_arg('freq_base') then
		tr = tbl:tag('tr')
		tr:tag('th'):wikitext('Normal')
		tr:tag('th'):wikitext(arg('freq_base'))
		for i = 1, normN do
			if has_arg('freq_' .. i) then
				tr:tag('td'):wikitext(arg('freq_' .. i))
			else
				tr:tag('td'):wikitext(' ')
			end
		end
	end
	
	if avx2 or has_arg('freq_avx2_base') then
		tr = tbl:tag('tr')
		tr:tag('th'):wikitext('AVX2')
		tr:tag('th'):wikitext(arg('freq_avx2_base'))
		for i = 1, avx2N do
			if has_arg('freq_avx2_' .. i) then
				tr:tag('td'):wikitext(arg('freq_avx2_' .. i))
			else
				tr:tag('td'):wikitext(' ')
			end
		end
	end
	
	if avx512 or has_arg('freq_avx512_base') then
		tr = tbl:tag('tr')
		tr:tag('th'):wikitext('AVX512')
		tr:tag('th'):wikitext(arg('freq_avx512_base'))
		for i = 1, avx512N do
			if has_arg('freq_avx512_' .. i) then
				tr:tag('td'):wikitext(arg('freq_avx512_' .. i))
			else
				tr:tag('td'):wikitext(' ')
			end
		end
	end
	
    return tbl
end

return p