diff --git a/algo/axiom.c b/algo/axiom.c index 8c429cf6d..fd469e92e 100644 --- a/algo/axiom.c +++ b/algo/axiom.c @@ -3,46 +3,11 @@ #include #include -#include "sha3/sph_shabal.h" #include "crypto/mshabal.h" -static __thread uint32_t _ALIGN(128) M[65536][8]; - -void axiomhash(void *output, const void *input) -{ - sph_shabal256_context ctx; - const int N = 65536; - - sph_shabal256_init(&ctx); - sph_shabal256(&ctx, input, 80); - sph_shabal256_close(&ctx, M[0]); - - for(int i = 1; i < N; i++) { - //sph_shabal256_init(&ctx); - sph_shabal256(&ctx, M[i-1], 32); - sph_shabal256_close(&ctx, M[i]); - } - - for(int b = 0; b < N; b++) - { - const int p = b > 0 ? b - 1 : 0xFFFF; - const int q = M[p][0] % 0xFFFF; - const int j = (b + q) % N; - - //sph_shabal256_init(&ctx); -#if 0 - sph_shabal256(&ctx, M[p], 32); - sph_shabal256(&ctx, M[j], 32); -#else - uint8_t _ALIGN(128) hash[64]; - memcpy(hash, M[p], 32); - memcpy(&hash[32], M[j], 32); - sph_shabal256(&ctx, hash, 64); +#ifdef __AVX2__ +#define __8WAY__ #endif - sph_shabal256_close(&ctx, M[b]); - } - memcpy(output, M[N-1], 32); -} typedef uint32_t hash_t[8]; @@ -117,7 +82,7 @@ void axiomhash4way(mshabal_context* ctx_org, void* memspace, const void *input1, memcpy(result4, hash4[0xffff], 32); } -#ifdef __AVX__ +#ifdef __8WAY__ void axiomhash8way(mshabal8_context* ctx_org, void* memspace, const void *input1, void *result1, const void *input2, void *result2, @@ -229,78 +194,31 @@ void axiomhash8way(mshabal8_context* ctx_org, void* memspace, int scanhash_axiom(int thr_id, uint32_t *pdata, const uint32_t *ptarget, - uint32_t max_nonce, uint64_t *hashes_done) + uint32_t max_nonce, uint64_t *hashes_done, uint32_t *nonces, int *nonces_len) { -#ifndef __AVX__ - uint32_t _ALIGN(128) hash64_1[8], hash64_2[8], hash64_3[8], hash64_4[8]; - uint32_t _ALIGN(128) endiandata_1[20], endiandata_2[20], endiandata_3[20], endiandata_4[20]; - mshabal_context ctx_org; - void* memspace; - - const uint32_t Htarg = ptarget[7]; - const uint32_t first_nonce = pdata[19]; - - uint32_t n = first_nonce; - - // to avoid small chance of generating duplicate shares - max_nonce = (max_nonce / 4) * 4; - - for (int i=0; i < 19; i++) { - be32enc(&endiandata_1[i], pdata[i]); - } - - memcpy(endiandata_2, endiandata_1, sizeof(endiandata_1)); - memcpy(endiandata_3, endiandata_1, sizeof(endiandata_1)); - memcpy(endiandata_4, endiandata_1, sizeof(endiandata_1)); - - mshabal_init(&ctx_org, 256); - memspace = malloc(65536 * 32 * 4); +#ifdef __8WAY__ +#define HASHES 8 +#else +#define HASHES 4 +#endif - do { - be32enc(&endiandata_1[19], n); - be32enc(&endiandata_2[19], n + 1); - be32enc(&endiandata_3[19], n + 2); - be32enc(&endiandata_4[19], n + 3); - //axiomhash(hash64_1, endiandata_1); - axiomhash4way(&ctx_org, memspace, endiandata_1, hash64_1, endiandata_2, hash64_2, endiandata_3, hash64_3, endiandata_4, hash64_4); - if (hash64_1[7] < Htarg && fulltest(hash64_1, ptarget)) { - *hashes_done = n - first_nonce + 4; - pdata[19] = n; - free(memspace); - return true; - } - if (hash64_2[7] < Htarg && fulltest(hash64_2, ptarget)) { - *hashes_done = n - first_nonce + 4; - pdata[19] = n + 1; - free(memspace); - return true; - } - if (hash64_3[7] < Htarg && fulltest(hash64_3, ptarget)) { - *hashes_done = n - first_nonce + 4; - pdata[19] = n + 2; - free(memspace); - return true; - } - if (hash64_4[7] < Htarg && fulltest(hash64_4, ptarget)) { - *hashes_done = n - first_nonce + 4; - pdata[19] = n + 3; - free(memspace); - return true; - } - - n += 4; - //n++; + uint32_t _ALIGN(128) hash64_1[8], hash64_2[8], hash64_3[8], hash64_4[8] +#ifdef __8WAY__ + , hash64_5[8], hash64_6[8], hash64_7[8], hash64_8[8] +#endif + ; - } while (n < max_nonce && !work_restart[thr_id].restart); + uint32_t _ALIGN(128) endiandata_1[20], endiandata_2[20], endiandata_3[20], endiandata_4[20] +#ifdef __8WAY__ + , endiandata_5[20], endiandata_6[20], endiandata_7[20], endiandata_8[20] +#endif + ; - *hashes_done = n - first_nonce; - pdata[19] = n; - free(memspace); - return 0; +#ifdef __8WAY__ + mshabal8_context ctx_org; #else - uint32_t _ALIGN(128) hash64_1[8], hash64_2[8], hash64_3[8], hash64_4[8], hash64_5[8], hash64_6[8], hash64_7[8], hash64_8[8]; - uint32_t _ALIGN(128) endiandata_1[20], endiandata_2[20], endiandata_3[20], endiandata_4[20], endiandata_5[20], endiandata_6[20], endiandata_7[20], endiandata_8[20]; - mshabal8_context ctx_org8; + mshabal_context ctx_org; +#endif void* memspace; const uint32_t Htarg = ptarget[7]; @@ -308,8 +226,10 @@ int scanhash_axiom(int thr_id, uint32_t *pdata, const uint32_t *ptarget, uint32_t n = first_nonce; + *nonces_len = 0; + // to avoid small chance of generating duplicate shares - max_nonce = (max_nonce / 8) * 8; + max_nonce = (max_nonce / HASHES) * HASHES; for (int i = 0; i < 19; i++) { be32enc(&endiandata_1[i], pdata[i]); @@ -318,84 +238,81 @@ int scanhash_axiom(int thr_id, uint32_t *pdata, const uint32_t *ptarget, memcpy(endiandata_2, endiandata_1, sizeof(endiandata_1)); memcpy(endiandata_3, endiandata_1, sizeof(endiandata_1)); memcpy(endiandata_4, endiandata_1, sizeof(endiandata_1)); +#ifdef __8WAY__ memcpy(endiandata_5, endiandata_1, sizeof(endiandata_1)); memcpy(endiandata_6, endiandata_1, sizeof(endiandata_1)); memcpy(endiandata_7, endiandata_1, sizeof(endiandata_1)); memcpy(endiandata_8, endiandata_1, sizeof(endiandata_1)); +#endif - mshabal8_init(&ctx_org8, 256); - memspace = malloc(65536 * 32 * 8); +#ifdef __8WAY__ + mshabal8_init(&ctx_org, 256); +#else + mshabal_init(&ctx_org, 256); +#endif + memspace = malloc(65536 * 32 * HASHES); do { be32enc(&endiandata_1[19], n); be32enc(&endiandata_2[19], n + 1); be32enc(&endiandata_3[19], n + 2); be32enc(&endiandata_4[19], n + 3); +#ifdef __8WAY__ be32enc(&endiandata_5[19], n + 4); be32enc(&endiandata_6[19], n + 5); be32enc(&endiandata_7[19], n + 6); be32enc(&endiandata_8[19], n + 7); +#endif - axiomhash8way(&ctx_org8, memspace, endiandata_1, hash64_1, endiandata_2, hash64_2, endiandata_3, hash64_3, endiandata_4, hash64_4, +#ifdef __8WAY__ + axiomhash8way(&ctx_org, memspace, endiandata_1, hash64_1, endiandata_2, hash64_2, endiandata_3, hash64_3, endiandata_4, hash64_4, endiandata_5, hash64_5, endiandata_6, hash64_6, endiandata_7, hash64_7, endiandata_8, hash64_8); +#else + axiomhash4way(&ctx_org, memspace, endiandata_1, hash64_1, endiandata_2, hash64_2, endiandata_3, hash64_3, endiandata_4, hash64_4); +#endif if (hash64_1[7] < Htarg && fulltest(hash64_1, ptarget)) { - *hashes_done = n - first_nonce + 8; - pdata[19] = n; - free(memspace); - return true; + nonces[(*nonces_len)++] = n; } if (hash64_2[7] < Htarg && fulltest(hash64_2, ptarget)) { - *hashes_done = n - first_nonce + 8; - pdata[19] = n + 1; - free(memspace); - return true; + nonces[(*nonces_len)++] = n + 1; } if (hash64_3[7] < Htarg && fulltest(hash64_3, ptarget)) { - *hashes_done = n - first_nonce + 8; - pdata[19] = n + 2; - free(memspace); - return true; + nonces[(*nonces_len)++] = n + 2; } if (hash64_4[7] < Htarg && fulltest(hash64_4, ptarget)) { - *hashes_done = n - first_nonce + 8; - pdata[19] = n + 3; - free(memspace); - return true; + nonces[(*nonces_len)++] = n + 3; } +#ifdef __8WAY__ if (hash64_5[7] < Htarg && fulltest(hash64_5, ptarget)) { - *hashes_done = n - first_nonce + 8; - pdata[19] = n + 4; - free(memspace); - return true; + nonces[(*nonces_len)++] = n + 4; } if (hash64_6[7] < Htarg && fulltest(hash64_6, ptarget)) { - *hashes_done = n - first_nonce + 8; - pdata[19] = n + 5; - free(memspace); - return true; + nonces[(*nonces_len)++] = n + 5; } if (hash64_7[7] < Htarg && fulltest(hash64_7, ptarget)) { - *hashes_done = n - first_nonce + 8; - pdata[19] = n + 6; - free(memspace); - return true; + nonces[(*nonces_len)++] = n + 6; } if (hash64_8[7] < Htarg && fulltest(hash64_8, ptarget)) { - *hashes_done = n - first_nonce + 8; - pdata[19] = n + 7; + nonces[(*nonces_len)++] = n + 7; + } +#endif + + n += HASHES; + + if ((*nonces_len) > 0) + { + *hashes_done = n - first_nonce; + pdata[19] = n; free(memspace); return true; } - n += 8; - } while (n < max_nonce && !work_restart[thr_id].restart); *hashes_done = n - first_nonce; pdata[19] = n; free(memspace); return 0; -#endif } diff --git a/cpu-miner.c b/cpu-miner.c index b2816e1ba..57d768851 100644 --- a/cpu-miner.c +++ b/cpu-miner.c @@ -1714,6 +1714,9 @@ static void *miner_thread(void *userdata) int wkcmp_sz = nonce_oft; int rc = 0; + uint32_t axiom_nonces[8]; + int axiom_nonces_len; + if (opt_algo == ALGO_DROP || opt_algo == ALGO_ZR5) { // Duplicates: ignore pok in data[0] wkcmp_sz -= sizeof(uint32_t); @@ -1920,7 +1923,7 @@ static void *miner_thread(void *userdata) &hashes_done); break; case ALGO_AXIOM: - rc = scanhash_axiom(thr_id, work.data, work.target, max_nonce, &hashes_done); + rc = scanhash_axiom(thr_id, work.data, work.target, max_nonce, &hashes_done, axiom_nonces, &axiom_nonces_len); break; case ALGO_BLAKE: rc = scanhash_blake(thr_id, work.data, work.target, max_nonce, @@ -2068,8 +2071,28 @@ static void *miner_thread(void *userdata) /* if nonce found, submit work */ if (rc && !opt_benchmark) { - if (!submit_work(mythr, &work)) - break; + if (opt_algo == ALGO_AXIOM) + { + uint32_t oldnonce = work.data[19]; + + if (axiom_nonces_len > 1) + printf("Found multiple shares in single loop: %d\n", axiom_nonces_len); + + /* axiom may find multiple nonces, submit all shares */ + for (i = 0; i < axiom_nonces_len; i++) + { + work.data[19] = axiom_nonces[i]; + if (!submit_work(mythr, &work)) + break; + } + + work.data[19] = oldnonce; + } + else + { + if (!submit_work(mythr, &work)) + break; + } // prevent stale work in solo // we can't submit twice a block! if (!have_stratum && !have_longpoll) { diff --git a/launcher/Config.cs b/launcher/Config.cs index f6ca7bf98..541d91580 100644 --- a/launcher/Config.cs +++ b/launcher/Config.cs @@ -14,7 +14,7 @@ class Config public string WorkerName; public int Location; public int Threads; - public bool UseAVX; + public int Extension; #pragma warning restore 649 public static Config ConfigData; @@ -27,7 +27,7 @@ static Config() ConfigData.WorkerName = "worker1"; ConfigData.Location = 0; ConfigData.Threads = Environment.ProcessorCount; - ConfigData.UseAVX = true; + ConfigData.Extension = 0; try { ConfigData = JsonConvert.DeserializeObject(File.ReadAllText("config.json")); } catch { } diff --git a/launcher/Form1.Designer.cs b/launcher/Form1.Designer.cs index dea47eb83..eb1d7ed14 100644 --- a/launcher/Form1.Designer.cs +++ b/launcher/Form1.Designer.cs @@ -33,7 +33,6 @@ private void InitializeComponent() this.label1 = new System.Windows.Forms.Label(); this.comboBox1 = new System.Windows.Forms.ComboBox(); this.label2 = new System.Windows.Forms.Label(); - this.checkBox1 = new System.Windows.Forms.CheckBox(); this.numericUpDown1 = new System.Windows.Forms.NumericUpDown(); this.label3 = new System.Windows.Forms.Label(); this.statusStrip1 = new System.Windows.Forms.StatusStrip(); @@ -48,6 +47,8 @@ private void InitializeComponent() this.label4 = new System.Windows.Forms.Label(); this.textBox2 = new System.Windows.Forms.TextBox(); this.linkLabel2 = new System.Windows.Forms.LinkLabel(); + this.comboBox2 = new System.Windows.Forms.ComboBox(); + this.label5 = new System.Windows.Forms.Label(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit(); this.statusStrip1.SuspendLayout(); this.SuspendLayout(); @@ -101,18 +102,6 @@ private void InitializeComponent() this.label2.TabIndex = 4; this.label2.Text = "Bitcoin address:"; // - // checkBox1 - // - this.checkBox1.AutoSize = true; - this.checkBox1.Checked = true; - this.checkBox1.CheckState = System.Windows.Forms.CheckState.Checked; - this.checkBox1.Location = new System.Drawing.Point(193, 92); - this.checkBox1.Name = "checkBox1"; - this.checkBox1.Size = new System.Drawing.Size(150, 17); - this.checkBox1.TabIndex = 6; - this.checkBox1.Text = "Use AVX CPU extensions."; - this.checkBox1.UseVisualStyleBackColor = true; - // // numericUpDown1 // this.numericUpDown1.Location = new System.Drawing.Point(104, 91); @@ -228,11 +217,35 @@ private void InitializeComponent() this.linkLabel2.Text = "Visit us @ www.nicehash.com"; this.linkLabel2.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.linkLabel2_LinkClicked); // + // comboBox2 + // + this.comboBox2.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.comboBox2.FormattingEnabled = true; + this.comboBox2.Items.AddRange(new object[] { + "SSE2 (4-way)", + "AVX (4-way)", + "AVX2 (8-way)"}); + this.comboBox2.Location = new System.Drawing.Point(236, 90); + this.comboBox2.Name = "comboBox2"; + this.comboBox2.Size = new System.Drawing.Size(107, 21); + this.comboBox2.TabIndex = 12; + // + // label5 + // + this.label5.AutoSize = true; + this.label5.Location = new System.Drawing.Point(169, 93); + this.label5.Name = "label5"; + this.label5.Size = new System.Drawing.Size(56, 13); + this.label5.TabIndex = 13; + this.label5.Text = "Extension:"; + // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(521, 144); + this.Controls.Add(this.label5); + this.Controls.Add(this.comboBox2); this.Controls.Add(this.linkLabel2); this.Controls.Add(this.label4); this.Controls.Add(this.textBox2); @@ -240,7 +253,6 @@ private void InitializeComponent() this.Controls.Add(this.statusStrip1); this.Controls.Add(this.label3); this.Controls.Add(this.numericUpDown1); - this.Controls.Add(this.checkBox1); this.Controls.Add(this.label2); this.Controls.Add(this.comboBox1); this.Controls.Add(this.label1); @@ -265,7 +277,6 @@ private void InitializeComponent() private System.Windows.Forms.Label label1; private System.Windows.Forms.ComboBox comboBox1; private System.Windows.Forms.Label label2; - private System.Windows.Forms.CheckBox checkBox1; private System.Windows.Forms.NumericUpDown numericUpDown1; private System.Windows.Forms.Label label3; private System.Windows.Forms.StatusStrip statusStrip1; @@ -280,6 +291,8 @@ private void InitializeComponent() private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel6; private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel7; private System.Windows.Forms.LinkLabel linkLabel2; + private System.Windows.Forms.ComboBox comboBox2; + private System.Windows.Forms.Label label5; } } diff --git a/launcher/Form1.cs b/launcher/Form1.cs index 802427a4d..8581b9e86 100644 --- a/launcher/Form1.cs +++ b/launcher/Form1.cs @@ -14,6 +14,8 @@ public partial class Form1 : Form private static string[] MiningURL = { "axiom.eu.nicehash.com", "axiom.usa.nicehash.com", "axiom.hk.nicehash.com", "axiom.jp.nicehash.com" }; + private static string[] Executables = { "cpuminer_x64_SSE2_4way.exe", "cpuminer_x64_AVX_4way.exe", "cpuminer_x64_AVX2_8way.exe" }; + private static Process CPUMiner; private static Timer T; private static Boolean FirstTime; @@ -34,7 +36,7 @@ public Form1() comboBox1.SelectedIndex = Config.ConfigData.Location; textBox1.Text = Config.ConfigData.BitcoinAddress; textBox2.Text = Config.ConfigData.WorkerName; - checkBox1.Checked = Config.ConfigData.UseAVX; + comboBox2.SelectedIndex = Config.ConfigData.Extension; numericUpDown1.Value = Config.ConfigData.Threads; } @@ -104,11 +106,7 @@ private void button1_Click(object sender, EventArgs e) else Worker = textBox1.Text.Trim(); - string FileName; - if (checkBox1.Checked) - FileName = "bin\\cpuminer_x64_AVX.exe"; - else - FileName = "bin\\cpuminer_x64.exe"; + string FileName = "bin\\" + Executables[comboBox2.SelectedIndex]; string CommandLine = "--algo=axiom --url=stratum+tcp://" + MiningURL[comboBox1.SelectedIndex] + ":3346 --userpass=" + Worker + ":d=0.0000008 --threads=" + numericUpDown1.Value.ToString(); @@ -127,7 +125,7 @@ private void button1_Click(object sender, EventArgs e) Config.ConfigData.WorkerName = textBox2.Text.Trim(); Config.ConfigData.Location = comboBox1.SelectedIndex; Config.ConfigData.Threads = decimal.ToInt32(numericUpDown1.Value); - Config.ConfigData.UseAVX = checkBox1.Checked; + Config.ConfigData.Extension = comboBox2.SelectedIndex; Config.Commit(); button1.Text = "Stop"; diff --git a/launcher/Properties/AssemblyInfo.cs b/launcher/Properties/AssemblyInfo.cs index 6978dfb59..39ea4d652 100644 --- a/launcher/Properties/AssemblyInfo.cs +++ b/launcher/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] +[assembly: AssemblyVersion("1.0.1.0")] +[assembly: AssemblyFileVersion("1.0.1.0")] diff --git a/miner.h b/miner.h index 9466397ed..98fd8c3ba 100644 --- a/miner.h +++ b/miner.h @@ -192,7 +192,7 @@ int scanhash_anime(int thr_id, uint32_t *pdata, const uint32_t *ptarget, uint32_t max_nonce, uint64_t *hashes_done); int scanhash_axiom(int thr_id, uint32_t *pdata, const uint32_t *ptarget, - uint32_t max_nonce, uint64_t *hashes_done); + uint32_t max_nonce, uint64_t *hashes_done, uint32_t *nonces, int *nonces_len); int scanhash_blake(int thr_id, uint32_t *pdata, const uint32_t *ptarget, uint32_t max_nonce, uint64_t *hashes_done); @@ -508,7 +508,7 @@ void print_hash_tests(void); void sha256d(unsigned char *hash, const unsigned char *data, int len); void animehash(void *state, const void *input); -void axiomhash(void *state, const void *input); +//void axiomhash(void *state, const void *input); void blakehash(void *state, const void *input); void blakecoinhash(void *state, const void *input); void blake2s_hash(void *output, const void *input); diff --git a/util.c b/util.c index 2aee3ce64..0b3ecc81c 100644 --- a/util.c +++ b/util.c @@ -2002,8 +2002,8 @@ void print_hash_tests(void) animehash(&hash[0], &buf[0]); printpfx("anime", hash); - axiomhash(&hash[0], &buf[0]); - printpfx("axiom", hash); + //axiomhash(&hash[0], &buf[0]); + //printpfx("axiom", hash); blakehash(&hash[0], &buf[0]); printpfx("blake", hash);