cn/r part 1 of 2.

This commit is contained in:
XMRig 2019-09-03 14:36:27 +07:00
parent 9b6ab55936
commit b9e15389ca
16 changed files with 1484 additions and 734 deletions

View file

@ -4,15 +4,12 @@
const fs = require('fs');
const path = require('path');
const { text2h, addIncludes } = require('./js/opencl');
const cwd = process.cwd();
const { text2h, text2h_bundle, addIncludes } = require('./js/opencl');
// const cwd = process.cwd();
function cn()
{
process.chdir(cwd);
process.chdir(path.resolve('src/backend/opencl/cl/cn'));
const cn = addIncludes('cryptonight.cl', [
'algorithm.cl',
'wolf-aes.cl',
@ -30,4 +27,22 @@ function cn()
}
cn();
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');
// for (let key in items) {
// fs.writeFileSync(key + '_gen.cl', items[key]);
// }
fs.writeFileSync('cryptonight_r_cl.h', text2h_bundle('xmrig', items));
}
process.chdir(path.resolve('src/backend/opencl/cl/cn'));
cn();
cn_r();

View file

@ -24,11 +24,11 @@ function bin2h(buf, namespace, name)
}
function text2h(text, namespace, name)
function text2h_internal(text, name)
{
const buf = Buffer.from(text);
const size = buf.byteLength;
let out = `#pragma once\n\nnamespace ${namespace} {\n\nstatic char ${name}[${size + 1}] = {\n `;
let out = `\nstatic char ${name}[${size + 1}] = {\n `;
let b = 32;
for (let i = 0; i < size; i++) {
@ -42,12 +42,30 @@ function text2h(text, namespace, name)
out += '0x00';
out += `\n};\n\n} // namespace ${namespace}\n`;
out += '\n};\n';
return out;
}
function text2h(text, namespace, name)
{
return `#pragma once\n\nnamespace ${namespace} {\n` + text2h_internal(text, name) + `\n} // namespace ${namespace}\n`;
}
function text2h_bundle(namespace, items)
{
let out = `#pragma once\n\nnamespace ${namespace} {\n`;
for (let key in items) {
out += text2h_internal(items[key], key);
}
return out + `\n} // namespace ${namespace}\n`;
}
function addInclude(input, name)
{
return input.replace(`#include "${name}"`, fs.readFileSync(name, 'utf8'));
@ -66,7 +84,8 @@ function addIncludes(inputFileName, names)
}
module.exports.bin2h = bin2h;
module.exports.text2h = text2h;
module.exports.addInclude = addInclude;
module.exports.addIncludes = addIncludes;
module.exports.bin2h = bin2h;
module.exports.text2h = text2h;
module.exports.text2h_bundle = text2h_bundle;
module.exports.addInclude = addInclude;
module.exports.addIncludes = addIncludes;