Added OpenCL code minification .

This commit is contained in:
XMRig 2019-09-12 18:50:35 +07:00
parent 046eb4d9fd
commit bd1ffa56dc
6 changed files with 6782 additions and 9383 deletions

View file

@ -5,12 +5,13 @@
const fs = require('fs');
const path = require('path');
const { text2h, text2h_bundle, addIncludes } = require('./js/opencl');
const { opencl_minify } = require('./js/opencl_minify');
const cwd = process.cwd();
function cn()
{
const cn = addIncludes('cryptonight.cl', [
const cn = opencl_minify(addIncludes('cryptonight.cl', [
'algorithm.cl',
'wolf-aes.cl',
'wolf-skein.cl',
@ -20,9 +21,9 @@ function cn()
'fast_int_math_v2.cl',
'fast_div_heavy.cl',
'keccak.cl'
]);
]));
//fs.writeFileSync('cryptonight_gen.cl', cn);
// fs.writeFileSync('cryptonight_gen.cl', cn);
fs.writeFileSync('cryptonight_cl.h', text2h(cn, 'xmrig', 'cryptonight_cl'));
}
@ -31,11 +32,11 @@ function cn_r()
{
const items = {};
items.cryptonight_r_defines_cl = addIncludes('cryptonight_r_defines.cl', [ 'wolf-aes.cl' ]);
items.cryptonight_r_cl = fs.readFileSync('cryptonight_r.cl', 'utf8');
items.cryptonight_r_defines_cl = opencl_minify(addIncludes('cryptonight_r_defines.cl', [ 'wolf-aes.cl' ]));
items.cryptonight_r_cl = opencl_minify(fs.readFileSync('cryptonight_r.cl', 'utf8'));
// for (let key in items) {
// fs.writeFileSync(key + '_gen.cl', items[key]);
// fs.writeFileSync(key + '_gen.cl', items[key]);
// }
fs.writeFileSync('cryptonight_r_cl.h', text2h_bundle('xmrig', items));
@ -44,9 +45,9 @@ function cn_r()
function cn_gpu()
{
const cn_gpu = addIncludes('cryptonight_gpu.cl', [ 'wolf-aes.cl', 'keccak.cl' ]);
const cn_gpu = opencl_minify(addIncludes('cryptonight_gpu.cl', [ 'wolf-aes.cl', 'keccak.cl' ]));
//fs.writeFileSync('cryptonight_gpu_gen.cl', cn_gpu);
// fs.writeFileSync('cryptonight_gpu_gen.cl', cn_gpu);
fs.writeFileSync('cryptonight_gpu_cl.h', text2h(cn_gpu, 'xmrig', 'cryptonight_gpu_cl'));
}
@ -66,6 +67,7 @@ function rx()
rx = rx.replace(/(\t| )*#include "fillAes1Rx4.cl"/g, fs.readFileSync('fillAes1Rx4.cl', 'utf8'));
rx = rx.replace(/(\t| )*#include "blake2b_double_block.cl"/g, fs.readFileSync('blake2b_double_block.cl', 'utf8'));
rx = opencl_minify(rx);
//fs.writeFileSync('randomx_gen.cl', rx);
fs.writeFileSync('randomx_cl.h', text2h(rx, 'xmrig', 'randomx_cl'));

View file

@ -0,0 +1,50 @@
'use strict';
function opencl_minify(input)
{
let out = input.replace(/\/\*[\s\S]*?\*\/|\/\/.*$/gm, ''); // comments
out = out.replace(/^#\s+/gm, '#'); // macros with spaces
out = out.replace(/\n{2,}/g, '\n'); // empty lines
out = out.replace(/^\s+/gm, ''); // leading whitespace
out = out.replace(/ {2,}/g, ' '); // extra whitespace
let array = out.split('\n').map(line => {
if (line[0] === '#') {
return line
}
line = line.replace(/, /g, ',');
line = line.replace(/ \? /g, '?');
line = line.replace(/ : /g, ':');
line = line.replace(/ = /g, '=');
line = line.replace(/ != /g, '!=');
line = line.replace(/ >= /g, '>=');
line = line.replace(/ <= /g, '<=');
line = line.replace(/ == /g, '==');
line = line.replace(/ \+= /g, '+=');
line = line.replace(/ -= /g, '-=');
line = line.replace(/ \|= /g, '|=');
line = line.replace(/ \| /g, '|');
line = line.replace(/ \|\| /g, '||');
line = line.replace(/ & /g, '&');
line = line.replace(/ && /g, '&&');
line = line.replace(/ > /g, '>');
line = line.replace(/ < /g, '<');
line = line.replace(/ \+ /g, '+');
line = line.replace(/ - /g, '-');
line = line.replace(/ \* /g, '*');
line = line.replace(/ \^ /g, '^');
line = line.replace(/ & /g, '&');
line = line.replace(/ \/ /g, '/');
line = line.replace(/ << /g, '<<');
line = line.replace(/ >> /g, '>>');
line = line.replace(/if \(/g, 'if(');
return line;
});
return array.join('\n');
}
module.exports.opencl_minify = opencl_minify;