diff --git a/client/src/cmdanalyse.c b/client/src/cmdanalyse.c index 3f860c4e6..02ad3fcd0 100644 --- a/client/src/cmdanalyse.c +++ b/client/src/cmdanalyse.c @@ -242,7 +242,7 @@ static int CmdAnalyseLCR(const char *Cmd) { uint8_t data[100] = {0x00}; int res = CLIParamHexToBuf(arg_get_str(ctx, 1), data, sizeof(data), &dlen); CLIParserFree(ctx); - + if (res) { PrintAndLogEx(FAILED, "Error parsing bytes"); return PM3_EINVARG; @@ -272,7 +272,7 @@ static int CmdAnalyseCRC(const char *Cmd) { uint8_t data[1024] = {0x00}; int res = CLIParamHexToBuf(arg_get_str(ctx, 1), data, sizeof(data), &dlen); CLIParserFree(ctx); - + if (res) { PrintAndLogEx(FAILED, "Error parsing bytes"); return PM3_EINVARG; @@ -386,14 +386,14 @@ static int CmdAnalyseCHKSUM(const char *Cmd) { const char *s = arg_get_str(ctx, 2)->sval[0]; bool verbose = arg_get_lit(ctx, 3); CLIParserFree(ctx); - + uint32_t mlen = 0; - if (s) + if (s) mlen = strlen(s); if (mlen > 8) { PrintAndLogEx(FAILED, "Mask value is max 4 hex bytes"); - return PM3_EINVARG; + return PM3_EINVARG; } uint32_t mask = 0; @@ -487,7 +487,7 @@ static int CmdAnalyseTEASelfTest(const char *Cmd) { uint8_t v_le[8]; memset(v_le, 0x00, sizeof(v_le)); uint8_t *v_ptr = v_le; - + SwapEndian64ex(data, 8, 4, v_ptr); // ENCRYPTION KEY: @@ -856,7 +856,7 @@ static int CmdAnalyseNuid(const char *Cmd) { int res = CLIParamHexToBuf(arg_get_str(ctx, 1), uid, sizeof(uid), &uidlen); bool selftest = arg_get_lit(ctx, 2); CLIParserFree(ctx); - + if (res) { PrintAndLogEx(FAILED, "Error parsing bytes"); return PM3_EINVARG; @@ -878,19 +878,19 @@ static int CmdAnalyseNuid(const char *Cmd) { PrintAndLogEx(INFO, "Self tests"); bool test1 = (0 == memcmp(nuid, nuid_test1, sizeof(nuid))); PrintAndLogEx((test1) ? SUCCESS : FAILED, "1. %s -> %s ( %s )" - , sprint_hex_inrow(uid_test1, sizeof(uid_test1)) - , sprint_hex(nuid, sizeof(nuid)) - , test1 ? _GREEN_("ok") : _RED_("fail") - ); + , sprint_hex_inrow(uid_test1, sizeof(uid_test1)) + , sprint_hex(nuid, sizeof(nuid)) + , test1 ? _GREEN_("ok") : _RED_("fail") + ); memcpy(uid, uid_test2, sizeof(uid)); mfc_generate4b_nuid(uid, nuid); bool test2 = (0 == memcmp(nuid, nuid_test2, sizeof(nuid))); PrintAndLogEx((test2) ? SUCCESS : FAILED, "2. %s -> %s ( %s )\n" - , sprint_hex_inrow(uid_test2, sizeof(uid_test2)) - , sprint_hex(nuid, sizeof(nuid)) - , test2 ? _GREEN_("ok") : _RED_("fail") - ); + , sprint_hex_inrow(uid_test2, sizeof(uid_test2)) + , sprint_hex(nuid, sizeof(nuid)) + , test2 ? _GREEN_("ok") : _RED_("fail") + ); return PM3_SUCCESS; } @@ -922,7 +922,7 @@ static int CmdAnalyseDemodBuffer(const char *Cmd) { CLIExecWithReturn(ctx, Cmd, argtable, true); const char *s = arg_get_str(ctx, 1)->sval[0]; CLIParserFree(ctx); - + if (s == NULL) { PrintAndLogEx(FAILED, "Must provide a binary string"); return PM3_EINVARG; @@ -987,7 +987,7 @@ static int CmdAnalyseFoo(const char *Cmd) { CLIParserInit(&ctx, "analyze foo", "experiments of cliparse", "analyse foo -r a0000000a0002021" - ); + ); void *argtable[] = { arg_param_begin, @@ -1001,8 +1001,8 @@ static int CmdAnalyseFoo(const char *Cmd) { uint8_t data[256]; CLIGetHexWithReturn(ctx, 1, data, &datalen); - int data3len = 512; - uint8_t data3[512]; + int data3len = 512; + uint8_t data3[512]; CLIGetStrWithReturn(ctx, 1, data3, &data3len); CLIParserFree(ctx); @@ -1010,7 +1010,7 @@ static int CmdAnalyseFoo(const char *Cmd) { PrintAndLogEx(INFO, "-r"); PrintAndLogEx(INFO, "Got: %s", sprint_hex_inrow(data, datalen)); PrintAndLogEx(INFO, "Got: %s", data3); - + ClearGraph(false); GraphTraceLen = 15000; diff --git a/client/src/cmdhfmfu.c b/client/src/cmdhfmfu.c index 9c0534c75..4d5106437 100644 --- a/client/src/cmdhfmfu.c +++ b/client/src/cmdhfmfu.c @@ -2746,7 +2746,7 @@ static int CmdHF14AMfUPwdGen(const char *Cmd) { bool selftest = arg_get_lit(ctx, 3); CLIParserFree(ctx); - if (selftest) + if (selftest) return generator_selftest(); if (u_len != 7) { @@ -2873,9 +2873,9 @@ static int CmdHF14AMfuOtpTearoff(const char *Cmd) { return PM3_EINVARG; } - uint8_t teardata[8] = {0x00}; - memcpy(teardata, data, sizeof(data)); - memcpy(teardata + sizeof(data), test, sizeof(test)); + uint8_t teardata[8] = {0x00}; + memcpy(teardata, data, sizeof(data)); + memcpy(teardata + sizeof(data), test, sizeof(test)); PrintAndLogEx(INFO, "----------------- " _CYAN_("MFU Tear off") " ---------------------"); PrintAndLogEx(INFO, "Starting Tear-off test"); diff --git a/client/src/cmdhw.c b/client/src/cmdhw.c index 45281637c..b97a4f773 100644 --- a/client/src/cmdhw.c +++ b/client/src/cmdhw.c @@ -347,9 +347,9 @@ static int CmdDbg(const char *Cmd) { else if (lv1) dbg = 1; else if (lv2) - dbg = 2; + dbg = 2; else if (lv3) - dbg = 3; + dbg = 3; else if (lv4) dbg = 4; @@ -817,7 +817,7 @@ static int CmdConnect(const char *Cmd) { int p_len = FILE_PATH_SIZE; char port[FILE_PATH_SIZE] = {0}; - CLIGetStrWithReturn(ctx, 1, (uint8_t*)port, &p_len); + CLIGetStrWithReturn(ctx, 1, (uint8_t *)port, &p_len); uint32_t baudrate = arg_get_u32_def(ctx, 2, USART_BAUD_RATE); CLIParserFree(ctx); diff --git a/client/src/cmdlft55xx.c b/client/src/cmdlft55xx.c index fe2ba09ca..a3e6bc176 100644 --- a/client/src/cmdlft55xx.c +++ b/client/src/cmdlft55xx.c @@ -80,11 +80,11 @@ static void print_usage_t55xx_downloadlink(uint8_t ShowAll, uint8_t dl_mode_defa } static void arg_add_t55xx_downloadlink(void *at[], uint8_t *idx, uint8_t show, uint8_t dl_mode_def) { - - char *r0 = (char*)calloc(56, sizeof(uint8_t)); - char *r1 = (char*)calloc(56, sizeof(uint8_t)); - char *r2 = (char*)calloc(56, sizeof(uint8_t)); - char *r3 = (char*)calloc(56, sizeof(uint8_t)); + + char *r0 = (char *)calloc(56, sizeof(uint8_t)); + char *r1 = (char *)calloc(56, sizeof(uint8_t)); + char *r2 = (char *)calloc(56, sizeof(uint8_t)); + char *r3 = (char *)calloc(56, sizeof(uint8_t)); sprintf(r0, "downlink - fixed bit length %s", (dl_mode_def == 0) ? "(detected def)" : ""); sprintf(r1, "downlink - long leading reference %s", (dl_mode_def == 1) ? "(detected def)" : ""); @@ -98,12 +98,12 @@ static void arg_add_t55xx_downloadlink(void *at[], uint8_t *idx, uint8_t show, u at[n++] = arg_lit0(NULL, "r3", r3); if (show == T55XX_DLMODE_ALL) { - char *r4 = (char*)calloc(50, sizeof(uint8_t)); + char *r4 = (char *)calloc(50, sizeof(uint8_t)); sprintf(r4, "try all downlink modes %s", (dl_mode_def == 4) ? "(def)" : ""); at[n++] = arg_lit0(NULL, "all", r4); } at[n++] = arg_param_end; - *idx = n; + *idx = n; } @@ -2876,7 +2876,7 @@ static int CmdT55xxWipe(const char *Cmd) { ); // 4 + (5 or 6) - void *argtable[9] = { + void *argtable[9] = { arg_param_begin, arg_str0("c", "cfg", "", "configuration block0 (4 hex bytes)"), arg_str0("p", "pwd", "", "password (4 hex bytes)"), @@ -2887,7 +2887,7 @@ static int CmdT55xxWipe(const char *Cmd) { CLIExecWithReturn(ctx, Cmd, argtable, true); bool usepwd = false, gotconf = false; - uint32_t block0 = 0; + uint32_t block0 = 0; int res = arg_get_u32_hexstr_def(ctx, 1, 0, &block0); if (res == 1) { gotconf = true; @@ -2907,7 +2907,7 @@ static int CmdT55xxWipe(const char *Cmd) { PrintAndLogEx(WARNING, "Password should be 4 bytes, using default pwd"); } - bool Q5 = arg_get_lit(ctx, 3); + bool Q5 = arg_get_lit(ctx, 3); CLIParserFree(ctx); PrintAndLogEx(INFO, "Target " _YELLOW_("%s")" tag", (Q5) ? "Q5/T5555" : "T55x7"); @@ -3181,7 +3181,7 @@ static int CmdT55xxBruteForce(const char *Cmd) { "lf t55xx bruteforce --r2 -s aaaaaa77 -e aaaaaa99\n" ); - void *argtable[3 + 6] = { + void *argtable[3 + 6] = { arg_param_begin, arg_str1("s", "start", "", "search start password (4 hex bytes)"), arg_str1("e", "end", "", "search end password (4 hex bytes)"), @@ -3243,7 +3243,7 @@ static int CmdT55xxBruteForce(const char *Cmd) { curr = start_password; while (found == 0) { - + PrintAndLogEx(NORMAL, "." NOLF); if (IsCancelled()) { @@ -3308,7 +3308,7 @@ static int CmdT55xxRecoverPW(const char *Cmd) { ); // 2 + (5 or 6) - void *argtable[8] = { + void *argtable[8] = { arg_param_begin, arg_str1("p", "pwd", "", "password (4 hex bytes)"), }; @@ -3548,7 +3548,7 @@ static int CmdT55xxDetectPage1(const char *Cmd) { ); // 2 + (5 or 6) - void *argtable[7] = { + void *argtable[7] = { arg_param_begin, arg_lit0("1", NULL, "extract using data from graphbuffer"), arg_str0("p", "pwd", "", "password (4 hex bytes)"), @@ -3565,7 +3565,7 @@ static int CmdT55xxDetectPage1(const char *Cmd) { if (res == 2) { PrintAndLogEx(INFO, "Password should be 4 hex bytes"); return PM3_EINVARG; - } else if ( res == 1) { + } else if (res == 1) { usepwd = true; } @@ -3606,7 +3606,7 @@ static int CmdT55xxDetectPage1(const char *Cmd) { if (use_graphbuf == false) { for (uint8_t dl_mode = downlink_mode; dl_mode < 4; dl_mode++) { - + if (AcquireData(T55x7_PAGE1, T55x7_TRACE_BLOCK1, usepwd, password, dl_mode) == false) continue; @@ -3644,7 +3644,7 @@ static int CmdT55xxSetDeviceConfig(const char *Cmd) { "lf t55xx deviceconfig -a 55 -b 14 -c 21 -d 30 -> default EM4305" ); - void *argtable[10 + 5] = { + void *argtable[10 + 5] = { arg_param_begin, arg_int0("a", NULL, "<8..255>", "Set start gap"), arg_int0("b", NULL, "<8..255>", "Set write gap"), @@ -3677,7 +3677,7 @@ static int CmdT55xxSetDeviceConfig(const char *Cmd) { if ((r0 + r1 + r2 + r3) > 1) { PrintAndLogEx(FAILED, "Error multiple downlink encoding"); - return PM3_EINVARG; + return PM3_EINVARG; } uint8_t downlink_mode = 0; @@ -3755,7 +3755,7 @@ static int CmdT55xxProtect(const char *Cmd) { ); // 4 + (5 or 6) - void *argtable[4 + 5] = { + void *argtable[4 + 5] = { arg_param_begin, arg_lit0("o", "override", "override safety check"), arg_str1("p", "pwd", "", "password (4 hex bytes)"), @@ -3766,17 +3766,17 @@ static int CmdT55xxProtect(const char *Cmd) { CLIExecWithReturn(ctx, Cmd, argtable, true); uint8_t override = 0; - if (arg_get_lit(ctx, 1)) + if (arg_get_lit(ctx, 1)) override = 2; uint32_t password = 0; - bool usepwd = false; + bool usepwd = false; int res = arg_get_u32_hexstr_def(ctx, 2, 0, &password); if (res == 2) { CLIParserFree(ctx); PrintAndLogEx(FAILED, "Error parsing password bytes"); return PM3_EINVARG; - } else if ( res == 1) { + } else if (res == 1) { usepwd = true; override = 1; } @@ -3942,7 +3942,7 @@ static int CmdT55xxSniff(const char *Cmd) { char dataText [100]; int pulseBuffer[80] = { 0 }; // max should be 73 +/- - Holds Pulse widths char data[80]; // linked to pulseBuffer. - Holds 0/1 from pulse widths - + // setup and sample data from Proxmark // if not directed to existing sample/graphbuffer if (use_graphbuf == false) { @@ -4159,7 +4159,7 @@ static int CmdT55xxSniff(const char *Cmd) { } // Print results - if (have_data) { + if (have_data) { if (blockAddr == 7) PrintAndLogEx(SUCCESS, "%-20s | "_GREEN_("%8s")" | "_YELLOW_("%8s")" | "_YELLOW_("%d")" | "_GREEN_("%d")" | %3d | %3d | %s", modeText, pwdText, dataText, blockAddr, page, minWidth, maxWidth, data); else diff --git a/client/src/cmdsmartcard.c b/client/src/cmdsmartcard.c index 0b5bc4507..247090dd0 100644 --- a/client/src/cmdsmartcard.c +++ b/client/src/cmdsmartcard.c @@ -614,7 +614,7 @@ static int CmdSmartInfo(const char *Cmd) { arg_param_end }; CLIExecWithReturn(ctx, Cmd, argtable, true); - bool verbose = arg_get_lit(ctx, 1); + bool verbose = arg_get_lit(ctx, 1); CLIParserFree(ctx); clearCommandBuffer(); @@ -628,7 +628,7 @@ static int CmdSmartInfo(const char *Cmd) { } if (resp.status != PM3_SUCCESS) { - if (verbose) { + if (verbose) { PrintAndLogEx(WARNING, "smart card select failed"); } return PM3_ESOFT; @@ -685,7 +685,7 @@ static int CmdSmartReader(const char *Cmd) { arg_param_end }; CLIExecWithReturn(ctx, Cmd, argtable, true); - bool verbose = arg_get_lit(ctx, 1); + bool verbose = arg_get_lit(ctx, 1); CLIParserFree(ctx); clearCommandBuffer(); @@ -700,7 +700,7 @@ static int CmdSmartReader(const char *Cmd) { if (resp.status != PM3_SUCCESS) { if (verbose) { - PrintAndLogEx(WARNING, "smart card select failed"); + PrintAndLogEx(WARNING, "smart card select failed"); } return PM3_ESOFT; } @@ -733,7 +733,7 @@ static int CmdSmartSetClock(const char *Cmd) { bool c4 = arg_get_lit(ctx, 3); CLIParserFree(ctx); - if ((c16 + c8 + c4) > 1 ) { + if ((c16 + c8 + c4) > 1) { PrintAndLogEx(WARNING, "Only one clock speed can be used at a time"); return PM3_EINVARG; } diff --git a/client/src/cmdusart.c b/client/src/cmdusart.c index 6be9ed743..92991be4c 100644 --- a/client/src/cmdusart.c +++ b/client/src/cmdusart.c @@ -14,7 +14,7 @@ #include #include #include "cmdparser.h" // command_t -#include "cliparser.h" // +#include "cliparser.h" // #include "commonutil.h" // ARRAYLEN #include "comms.h" #include "util_posix.h" @@ -119,7 +119,7 @@ static int CmdUsartConfig(const char *Cmd) { bool po = arg_get_lit(ctx, 4); CLIParserFree(ctx); - if ((pn + pe + po) > 1 ) { + if ((pn + pe + po) > 1) { PrintAndLogEx(WARNING, "Only one parity can be used at a time"); return PM3_EINVARG; } @@ -160,7 +160,7 @@ static int usart_bt_testcomm(uint32_t baudrate, uint8_t parity) { static int CmdUsartBtFactory(const char *Cmd) { CLIParserContext *ctx; CLIParserInit(&ctx, "usart btfactory", - "Reset BT add-on to factory settings\n" + "Reset BT add-on to factory settings\n" "This requires\n" " 1) BTpower to be turned ON\n" " 2) BT add-on to NOT be connected\n" @@ -361,22 +361,22 @@ static int CmdUsartBtPin(const char *Cmd) { }; CLIExecWithReturn(ctx, Cmd, argtable, true); int plen = 4; - char pin[5] = { 0, 0 ,0, 0, 0 }; + char pin[5] = { 0, 0, 0, 0, 0 }; CLIParamStrToBuf(arg_get_str(ctx, 1), (uint8_t *)pin, sizeof(pin), &plen); CLIParserFree(ctx); if (plen != 4) { PrintAndLogEx(FAILED, "PIN must be 4 digits"); - return PM3_EINVARG; + return PM3_EINVARG; } for (uint8_t i = 0; i < plen; i++) { if (isdigit(pin[i]) == false) { PrintAndLogEx(FAILED, "PIN must be 4 digits"); - return PM3_EINVARG; + return PM3_EINVARG; } } - + char string[6 + sizeof(pin)] = {0}; sprintf(string, "AT+PIN%s", pin); uint8_t data[PM3_CMD_DATA_SIZE] = {0x00}; @@ -425,7 +425,7 @@ static int CmdUsartTX(const char *Cmd) { size_t i2 = 0; size_t n = strlen(s); - // strip / replace + // strip / replace for (size_t i = 0; i < n; i++) { if ((i < n - 1) && (s[i] == '\\') && (s[i + 1] == '\\')) { i++; @@ -469,7 +469,7 @@ static int CmdUsartRX(const char *Cmd) { arg_param_end }; CLIExecWithReturn(ctx, Cmd, argtable, true); - uint32_t waittime = arg_get_u32_def(ctx, 1, 0); + uint32_t waittime = arg_get_u32_def(ctx, 1, 0); CLIParserFree(ctx); uint8_t data[PM3_CMD_DATA_SIZE] = {0x00}; @@ -501,7 +501,7 @@ static int CmdUsartTXRX(const char *Cmd) { arg_param_end }; CLIExecWithReturn(ctx, Cmd, argtable, true); - uint32_t waittime = arg_get_u32_def(ctx, 1, 1000); + uint32_t waittime = arg_get_u32_def(ctx, 1, 1000); int slen = 0; char s[PM3_CMD_DATA_SIZE] = {0}; CLIParamStrToBuf(arg_get_str(ctx, 2), (uint8_t *)s, sizeof(s), &slen); @@ -568,7 +568,7 @@ static int CmdUsartTXhex(const char *Cmd) { uint8_t data[PM3_CMD_DATA_SIZE] = {0x00}; int res = CLIParamHexToBuf(arg_get_str(ctx, 1), data, sizeof(data), &dlen); CLIParserFree(ctx); - + if (res) { PrintAndLogEx(FAILED, "Error parsing bytes"); return PM3_EINVARG; @@ -591,7 +591,7 @@ static int CmdUsartRXhex(const char *Cmd) { arg_param_end }; CLIExecWithReturn(ctx, Cmd, argtable, true); - uint32_t waittime = arg_get_u32_def(ctx, 1, 0); + uint32_t waittime = arg_get_u32_def(ctx, 1, 0); CLIParserFree(ctx); uint8_t data[PM3_CMD_DATA_SIZE] = {0x00}; diff --git a/client/src/fileutils.c b/client/src/fileutils.c index 23444d62b..d68c95563 100644 --- a/client/src/fileutils.c +++ b/client/src/fileutils.c @@ -196,11 +196,11 @@ bool create_path(const char *dirname) { } */ -bool setDefaultPath (savePaths_t pathIndex, const char *Path) { +bool setDefaultPath(savePaths_t pathIndex, const char *Path) { if (pathIndex < spItemCount) { if ((Path == NULL) && (session.defaultPaths[pathIndex] != NULL)) { - free (session.defaultPaths[pathIndex]); + free(session.defaultPaths[pathIndex]); session.defaultPaths[pathIndex] = NULL; } diff --git a/client/src/fileutils.h b/client/src/fileutils.h index 587e48ec6..480cb013b 100644 --- a/client/src/fileutils.h +++ b/client/src/fileutils.h @@ -78,7 +78,7 @@ typedef enum { int fileExists(const char *filename); //bool create_path(const char *dirname); -bool setDefaultPath (savePaths_t pathIndex,const char *Path); // set a path in the path list session.defaultPaths +bool setDefaultPath(savePaths_t pathIndex, const char *Path); // set a path in the path list session.defaultPaths char *newfilenamemcopy(const char *preferredName, const char *suffix); diff --git a/client/src/preferences.c b/client/src/preferences.c index 6a3207cd4..b133dd428 100644 --- a/client/src/preferences.c +++ b/client/src/preferences.c @@ -55,27 +55,27 @@ int preferences_load(void) { session.show_hints = true; session.bar_mode = STYLE_VALUE; - setDefaultPath (spDefault, ""); - setDefaultPath (spDump, ""); - setDefaultPath (spTrace, ""); + setDefaultPath(spDefault, ""); + setDefaultPath(spDump, ""); + setDefaultPath(spTrace, ""); // default save path if (get_my_user_directory() != NULL) // should return path to .proxmark3 folder - setDefaultPath (spDefault, get_my_user_directory()); + setDefaultPath(spDefault, get_my_user_directory()); else - setDefaultPath (spDefault, "."); + setDefaultPath(spDefault, "."); // default dump path if (get_my_user_directory() != NULL) // should return path to .proxmark3 folder - setDefaultPath (spDump, get_my_user_directory()); + setDefaultPath(spDump, get_my_user_directory()); else - setDefaultPath (spDump, "."); + setDefaultPath(spDump, "."); // default dump path if (get_my_user_directory() != NULL) // should return path to .proxmark3 folder - setDefaultPath (spTrace, get_my_user_directory()); + setDefaultPath(spTrace, get_my_user_directory()); else - setDefaultPath (spTrace, "."); + setDefaultPath(spTrace, "."); if (session.incognito) { PrintAndLogEx(INFO, "No preferences file will be loaded"); @@ -177,9 +177,9 @@ void preferences_save_callback(json_t *root) { JsonSaveBoolean(root, "os.supports.colors", session.supports_colors); - JsonSaveStr(root, "file.default.savepath", session.defaultPaths[spDefault]); - JsonSaveStr(root, "file.default.dumppath", session.defaultPaths[spDump]); - JsonSaveStr(root, "file.default.tracepath", session.defaultPaths[spTrace]); + JsonSaveStr(root, "file.default.savepath", session.defaultPaths[spDefault]); + JsonSaveStr(root, "file.default.dumppath", session.defaultPaths[spDump]); + JsonSaveStr(root, "file.default.tracepath", session.defaultPaths[spTrace]); // Plot window JsonSaveInt(root, "window.plot.xpos", session.plot.x); @@ -262,15 +262,15 @@ void preferences_load_callback(json_t *root) { // default save path if (json_unpack_ex(root, &up_error, 0, "{s:s}", "file.default.savepath", &s1) == 0) - setDefaultPath (spDefault, s1); + setDefaultPath(spDefault, s1); // default dump path if (json_unpack_ex(root, &up_error, 0, "{s:s}", "file.default.dumppath", &s1) == 0) - setDefaultPath (spDump, s1); + setDefaultPath(spDump, s1); // default trace path if (json_unpack_ex(root, &up_error, 0, "{s:s}", "file.default.tracepath", &s1) == 0) - setDefaultPath (spTrace, s1); + setDefaultPath(spTrace, s1); // window plot if (json_unpack_ex(root, &up_error, 0, "{s:i}", "window.plot.xpos", &i1) == 0) @@ -424,49 +424,49 @@ static void showSavePathState(savePaths_t path_index, prefShowOpt_t opt) { char s[50]; switch (path_index) { case spDefault: - strcpy (s, "default save path......"); + strcpy(s, "default save path......"); break; case spDump: - strcpy (s, "dump save path........."); + strcpy(s, "dump save path........."); break; case spTrace: - strcpy (s, "trace save path........"); + strcpy(s, "trace save path........"); break; case spItemCount: default: - strcpy (s, _RED_("unknown")" save path......"); + strcpy(s, _RED_("unknown")" save path......"); } if ((session.defaultPaths[path_index] == NULL) || (strcmp(session.defaultPaths[path_index], "") == 0)) { PrintAndLogEx(INFO, " %s %s "_WHITE_("not set"), - prefShowMsg(opt), - s - ); + prefShowMsg(opt), + s + ); } else { PrintAndLogEx(INFO, " %s %s "_GREEN_("%s"), - prefShowMsg(opt), - s, - session.defaultPaths[path_index] - ); + prefShowMsg(opt), + s, + session.defaultPaths[path_index] + ); } } static void showPlotPosState(void) { PrintAndLogEx(INFO, " Plot window............ X "_GREEN_("%4d")" Y "_GREEN_("%4d")" H "_GREEN_("%4d")" W "_GREEN_("%4d"), - session.plot.x, - session.plot.y, - session.plot.h, - session.plot.w - ); + session.plot.x, + session.plot.y, + session.plot.h, + session.plot.w + ); } static void showOverlayPosState(void) { PrintAndLogEx(INFO, " Slider/Overlay window.. X "_GREEN_("%4d")" Y "_GREEN_("%4d")" H "_GREEN_("%4d")" W "_GREEN_("%4d"), - session.overlay.x, - session.overlay.y, - session.overlay.h, - session.overlay.w - ); + session.overlay.x, + session.overlay.y, + session.overlay.h, + session.overlay.w + ); } static void showHintsState(prefShowOpt_t opt) { @@ -521,8 +521,8 @@ static int setCmdEmoji(const char *Cmd) { bool show_alt = arg_get_lit(ctx, 3); bool show_none = arg_get_lit(ctx, 4); CLIParserFree(ctx); - - if ( (show_a + show_e + show_alt + show_none) > 1) { + + if ((show_a + show_e + show_alt + show_none) > 1) { PrintAndLogEx(FAILED, "Can only set one option"); return PM3_EINVARG; } @@ -572,7 +572,7 @@ static int setCmdColor(const char *Cmd) { bool use_n = arg_get_lit(ctx, 2); CLIParserFree(ctx); - if ( (use_c + use_n) > 1) { + if ((use_c + use_n) > 1) { PrintAndLogEx(FAILED, "Can only set one option"); return PM3_EINVARG; } @@ -618,7 +618,7 @@ static int setCmdDebug(const char *Cmd) { bool use_full = arg_get_lit(ctx, 3); CLIParserFree(ctx); - if ( (use_off + use_simple + use_full) > 1) { + if ((use_off + use_simple + use_full) > 1) { PrintAndLogEx(FAILED, "Can only set one option"); return PM3_EINVARG; } @@ -662,7 +662,7 @@ static int setCmdDeviceDebug (const char *Cmd) arg_lit0(NULL, "error", "error messages"), arg_lit0(NULL, "info", "info messages"), arg_lit0(NULL, "dbg", "debug messages"), - arg_lit0(NULL, "ext", "extended debug messages"), + arg_lit0(NULL, "ext", "extended debug messages"), arg_param_end }; CLIExecWithReturn(ctx, Cmd, argtable, true); @@ -734,12 +734,12 @@ static int setCmdHint(const char *Cmd) { bool use_on = arg_get_lit(ctx, 2); CLIParserFree(ctx); - if ( (use_off + use_on) > 1) { + if ((use_off + use_on) > 1) { PrintAndLogEx(FAILED, "Can only set one option"); return PM3_EINVARG; } - - bool new_value = session.show_hints; + + bool new_value = session.show_hints; if (use_off) { new_value = false; } @@ -777,11 +777,11 @@ static int setCmdPlotSliders(const char *Cmd) { bool use_on = arg_get_lit(ctx, 2); CLIParserFree(ctx); - if ( (use_off + use_on) > 1) { + if ((use_off + use_on) > 1) { PrintAndLogEx(FAILED, "Can only set one option"); return PM3_EINVARG; } - + bool new_value = session.overlay_sliders; if (use_off) { new_value = false; @@ -801,7 +801,7 @@ static int setCmdPlotSliders(const char *Cmd) { return PM3_SUCCESS; } -static int setCmdSavePaths (const char *Cmd) { +static int setCmdSavePaths(const char *Cmd) { CLIParserContext *ctx; CLIParserInit(&ctx, "pref set savepath", "Set presistent preference of file paths in the client", @@ -861,8 +861,8 @@ static int setCmdSavePaths (const char *Cmd) { // Check path if (fileExists(path) == false && create_dir == false) { - PrintAndLogEx(ERR,"path does not exist... "_RED_("%s"), path); - } + PrintAndLogEx(ERR, "path does not exist... "_RED_("%s"), path); + } // do we need to create it // if (!fileExists(newValue)) @@ -871,7 +871,7 @@ static int setCmdSavePaths (const char *Cmd) { if (path_item < spItemCount) { if (strcmp(path, session.defaultPaths[path_item]) != 0) { showSavePathState(path_item, prefShowOLD); - setDefaultPath (path_item, path); + setDefaultPath(path_item, path); showSavePathState(path_item, prefShowNEW); preferences_save(); } else { @@ -902,7 +902,7 @@ static int setCmdBarMode(const char *Cmd) { bool show_val = arg_get_lit(ctx, 3); CLIParserFree(ctx); - if ( (show_bar + show_mix + show_val) > 1) { + if ((show_bar + show_mix + show_val) > 1) { PrintAndLogEx(FAILED, "Can only set one option"); return PM3_EINVARG; } diff --git a/doc/commands.md b/doc/commands.md index 347fdaaa8..33b47f975 100644 --- a/doc/commands.md +++ b/doc/commands.md @@ -506,7 +506,7 @@ Check column "offline" for their availability. |command |offline |description |------- |------- |----------- |`hw help `|Y |`This help` -|`hw connect `|Y |`connect Proxmark3 to serial port` +|`hw connect `|Y |`Connect Proxmark3 to serial port` |`hw dbg `|N |`Set Proxmark3 debug level` |`hw detectreader `|N |`Detect external reader field` |`hw fpgaoff `|N |`Set FPGA off` @@ -515,7 +515,7 @@ Check column "offline" for their availability. |`hw ping `|N |`Test if the Proxmark3 is responsive` |`hw readmem `|N |`Read memory at decimal address from flash` |`hw reset `|N |`Reset the Proxmark3` -|`hw setlfdivisor `|N |`Drive LF antenna at 12 MHz / (divisor + 1)` +|`hw setlfdivisor `|N |`Drive LF antenna at 12MHz / (divisor + 1)` |`hw setmux `|N |`Set the ADC mux to a specific value` |`hw standalone `|N |`Jump to the standalone mode` |`hw status `|N |`Show runtime status information about the connected Proxmark3` diff --git a/tools/hitag2crack/common/OpenCL-Headers/CL/cl.h b/tools/hitag2crack/common/OpenCL-Headers/CL/cl.h index 3a5aae486..4e6103e49 100644 --- a/tools/hitag2crack/common/OpenCL-Headers/CL/cl.h +++ b/tools/hitag2crack/common/OpenCL-Headers/CL/cl.h @@ -26,15 +26,15 @@ extern "C" { /******************************************************************************/ -typedef struct _cl_platform_id * cl_platform_id; -typedef struct _cl_device_id * cl_device_id; -typedef struct _cl_context * cl_context; -typedef struct _cl_command_queue * cl_command_queue; -typedef struct _cl_mem * cl_mem; -typedef struct _cl_program * cl_program; -typedef struct _cl_kernel * cl_kernel; -typedef struct _cl_event * cl_event; -typedef struct _cl_sampler * cl_sampler; +typedef struct _cl_platform_id *cl_platform_id; +typedef struct _cl_device_id *cl_device_id; +typedef struct _cl_context *cl_context; +typedef struct _cl_command_queue *cl_command_queue; +typedef struct _cl_mem *cl_mem; +typedef struct _cl_program *cl_program; +typedef struct _cl_kernel *cl_kernel; +typedef struct _cl_event *cl_event; +typedef struct _cl_sampler *cl_sampler; typedef cl_uint cl_bool; /* WARNING! Unlike cl_ types in cl_platform.h, cl_bool is not guaranteed to be the same size as the bool in kernels. */ typedef cl_ulong cl_bitfield; @@ -147,13 +147,13 @@ typedef struct _cl_image_desc { union { #endif #endif - cl_mem buffer; + cl_mem buffer; #ifdef CL_VERSION_2_0 #if defined(_MSC_VER) && defined(__STDC__) /* Anonymous unions are not supported in /Za builds */ #else - cl_mem mem_object; - }; + cl_mem mem_object; +}; #endif #if defined(_MSC_VER) && !defined(__STDC__) #pragma warning( pop ) @@ -945,39 +945,39 @@ typedef struct _cl_name_version { /* Platform API */ extern CL_API_ENTRY cl_int CL_API_CALL clGetPlatformIDs(cl_uint num_entries, - cl_platform_id * platforms, - cl_uint * num_platforms) CL_API_SUFFIX__VERSION_1_0; + cl_platform_id *platforms, + cl_uint *num_platforms) CL_API_SUFFIX__VERSION_1_0; extern CL_API_ENTRY cl_int CL_API_CALL clGetPlatformInfo(cl_platform_id platform, cl_platform_info param_name, size_t param_value_size, - void * param_value, - size_t * param_value_size_ret) CL_API_SUFFIX__VERSION_1_0; + void *param_value, + size_t *param_value_size_ret) CL_API_SUFFIX__VERSION_1_0; /* Device APIs */ extern CL_API_ENTRY cl_int CL_API_CALL clGetDeviceIDs(cl_platform_id platform, cl_device_type device_type, cl_uint num_entries, - cl_device_id * devices, - cl_uint * num_devices) CL_API_SUFFIX__VERSION_1_0; + cl_device_id *devices, + cl_uint *num_devices) CL_API_SUFFIX__VERSION_1_0; extern CL_API_ENTRY cl_int CL_API_CALL clGetDeviceInfo(cl_device_id device, cl_device_info param_name, size_t param_value_size, - void * param_value, - size_t * param_value_size_ret) CL_API_SUFFIX__VERSION_1_0; + void *param_value, + size_t *param_value_size_ret) CL_API_SUFFIX__VERSION_1_0; #ifdef CL_VERSION_1_2 extern CL_API_ENTRY cl_int CL_API_CALL clCreateSubDevices(cl_device_id in_device, - const cl_device_partition_property * properties, + const cl_device_partition_property *properties, cl_uint num_devices, - cl_device_id * out_devices, - cl_uint * num_devices_ret) CL_API_SUFFIX__VERSION_1_2; + cl_device_id *out_devices, + cl_uint *num_devices_ret) CL_API_SUFFIX__VERSION_1_2; extern CL_API_ENTRY cl_int CL_API_CALL clRetainDevice(cl_device_id device) CL_API_SUFFIX__VERSION_1_2; @@ -996,36 +996,36 @@ clSetDefaultDeviceCommandQueue(cl_context context, extern CL_API_ENTRY cl_int CL_API_CALL clGetDeviceAndHostTimer(cl_device_id device, - cl_ulong* device_timestamp, - cl_ulong* host_timestamp) CL_API_SUFFIX__VERSION_2_1; + cl_ulong *device_timestamp, + cl_ulong *host_timestamp) CL_API_SUFFIX__VERSION_2_1; extern CL_API_ENTRY cl_int CL_API_CALL clGetHostTimer(cl_device_id device, - cl_ulong * host_timestamp) CL_API_SUFFIX__VERSION_2_1; + cl_ulong *host_timestamp) CL_API_SUFFIX__VERSION_2_1; #endif /* Context APIs */ extern CL_API_ENTRY cl_context CL_API_CALL -clCreateContext(const cl_context_properties * properties, +clCreateContext(const cl_context_properties *properties, cl_uint num_devices, - const cl_device_id * devices, - void (CL_CALLBACK * pfn_notify)(const char * errinfo, - const void * private_info, - size_t cb, - void * user_data), - void * user_data, - cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0; + const cl_device_id *devices, + void (CL_CALLBACK *pfn_notify)(const char *errinfo, + const void *private_info, + size_t cb, + void *user_data), + void *user_data, + cl_int *errcode_ret) CL_API_SUFFIX__VERSION_1_0; extern CL_API_ENTRY cl_context CL_API_CALL -clCreateContextFromType(const cl_context_properties * properties, +clCreateContextFromType(const cl_context_properties *properties, cl_device_type device_type, - void (CL_CALLBACK * pfn_notify)(const char * errinfo, - const void * private_info, - size_t cb, - void * user_data), - void * user_data, - cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0; + void (CL_CALLBACK *pfn_notify)(const char *errinfo, + const void *private_info, + size_t cb, + void *user_data), + void *user_data, + cl_int *errcode_ret) CL_API_SUFFIX__VERSION_1_0; extern CL_API_ENTRY cl_int CL_API_CALL clRetainContext(cl_context context) CL_API_SUFFIX__VERSION_1_0; @@ -1037,16 +1037,16 @@ extern CL_API_ENTRY cl_int CL_API_CALL clGetContextInfo(cl_context context, cl_context_info param_name, size_t param_value_size, - void * param_value, - size_t * param_value_size_ret) CL_API_SUFFIX__VERSION_1_0; + void *param_value, + size_t *param_value_size_ret) CL_API_SUFFIX__VERSION_1_0; #ifdef CL_VERSION_3_0 extern CL_API_ENTRY cl_int CL_API_CALL clSetContextDestructorCallback(cl_context context, - void (CL_CALLBACK* pfn_notify)(cl_context context, - void* user_data), - void* user_data) CL_API_SUFFIX__VERSION_3_0; + void (CL_CALLBACK *pfn_notify)(cl_context context, + void *user_data), + void *user_data) CL_API_SUFFIX__VERSION_3_0; #endif @@ -1057,8 +1057,8 @@ clSetContextDestructorCallback(cl_context context, extern CL_API_ENTRY cl_command_queue CL_API_CALL clCreateCommandQueueWithProperties(cl_context context, cl_device_id device, - const cl_queue_properties * properties, - cl_int * errcode_ret) CL_API_SUFFIX__VERSION_2_0; + const cl_queue_properties *properties, + cl_int *errcode_ret) CL_API_SUFFIX__VERSION_2_0; #endif @@ -1072,16 +1072,16 @@ extern CL_API_ENTRY cl_int CL_API_CALL clGetCommandQueueInfo(cl_command_queue command_queue, cl_command_queue_info param_name, size_t param_value_size, - void * param_value, - size_t * param_value_size_ret) CL_API_SUFFIX__VERSION_1_0; + void *param_value, + size_t *param_value_size_ret) CL_API_SUFFIX__VERSION_1_0; /* Memory Object APIs */ extern CL_API_ENTRY cl_mem CL_API_CALL clCreateBuffer(cl_context context, cl_mem_flags flags, size_t size, - void * host_ptr, - cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0; + void *host_ptr, + cl_int *errcode_ret) CL_API_SUFFIX__VERSION_1_0; #ifdef CL_VERSION_1_1 @@ -1089,8 +1089,8 @@ extern CL_API_ENTRY cl_mem CL_API_CALL clCreateSubBuffer(cl_mem buffer, cl_mem_flags flags, cl_buffer_create_type buffer_create_type, - const void * buffer_create_info, - cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_1; + const void *buffer_create_info, + cl_int *errcode_ret) CL_API_SUFFIX__VERSION_1_1; #endif @@ -1099,10 +1099,10 @@ clCreateSubBuffer(cl_mem buffer, extern CL_API_ENTRY cl_mem CL_API_CALL clCreateImage(cl_context context, cl_mem_flags flags, - const cl_image_format * image_format, - const cl_image_desc * image_desc, - void * host_ptr, - cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_2; + const cl_image_format *image_format, + const cl_image_desc *image_desc, + void *host_ptr, + cl_int *errcode_ret) CL_API_SUFFIX__VERSION_1_2; #endif @@ -1113,8 +1113,8 @@ clCreatePipe(cl_context context, cl_mem_flags flags, cl_uint pipe_packet_size, cl_uint pipe_max_packets, - const cl_pipe_properties * properties, - cl_int * errcode_ret) CL_API_SUFFIX__VERSION_2_0; + const cl_pipe_properties *properties, + cl_int *errcode_ret) CL_API_SUFFIX__VERSION_2_0; #endif @@ -1122,20 +1122,20 @@ clCreatePipe(cl_context context, extern CL_API_ENTRY cl_mem CL_API_CALL clCreateBufferWithProperties(cl_context context, - const cl_mem_properties * properties, + const cl_mem_properties *properties, cl_mem_flags flags, size_t size, - void * host_ptr, - cl_int * errcode_ret) CL_API_SUFFIX__VERSION_3_0; + void *host_ptr, + cl_int *errcode_ret) CL_API_SUFFIX__VERSION_3_0; extern CL_API_ENTRY cl_mem CL_API_CALL clCreateImageWithProperties(cl_context context, - const cl_mem_properties * properties, + const cl_mem_properties *properties, cl_mem_flags flags, - const cl_image_format * image_format, - const cl_image_desc * image_desc, - void * host_ptr, - cl_int * errcode_ret) CL_API_SUFFIX__VERSION_3_0; + const cl_image_format *image_format, + const cl_image_desc *image_desc, + void *host_ptr, + cl_int *errcode_ret) CL_API_SUFFIX__VERSION_3_0; #endif @@ -1150,22 +1150,22 @@ clGetSupportedImageFormats(cl_context context, cl_mem_flags flags, cl_mem_object_type image_type, cl_uint num_entries, - cl_image_format * image_formats, - cl_uint * num_image_formats) CL_API_SUFFIX__VERSION_1_0; + cl_image_format *image_formats, + cl_uint *num_image_formats) CL_API_SUFFIX__VERSION_1_0; extern CL_API_ENTRY cl_int CL_API_CALL clGetMemObjectInfo(cl_mem memobj, cl_mem_info param_name, size_t param_value_size, - void * param_value, - size_t * param_value_size_ret) CL_API_SUFFIX__VERSION_1_0; + void *param_value, + size_t *param_value_size_ret) CL_API_SUFFIX__VERSION_1_0; extern CL_API_ENTRY cl_int CL_API_CALL clGetImageInfo(cl_mem image, cl_image_info param_name, size_t param_value_size, - void * param_value, - size_t * param_value_size_ret) CL_API_SUFFIX__VERSION_1_0; + void *param_value, + size_t *param_value_size_ret) CL_API_SUFFIX__VERSION_1_0; #ifdef CL_VERSION_2_0 @@ -1173,8 +1173,8 @@ extern CL_API_ENTRY cl_int CL_API_CALL clGetPipeInfo(cl_mem pipe, cl_pipe_info param_name, size_t param_value_size, - void * param_value, - size_t * param_value_size_ret) CL_API_SUFFIX__VERSION_2_0; + void *param_value, + size_t *param_value_size_ret) CL_API_SUFFIX__VERSION_2_0; #endif @@ -1182,9 +1182,9 @@ clGetPipeInfo(cl_mem pipe, extern CL_API_ENTRY cl_int CL_API_CALL clSetMemObjectDestructorCallback(cl_mem memobj, - void (CL_CALLBACK * pfn_notify)(cl_mem memobj, - void * user_data), - void * user_data) CL_API_SUFFIX__VERSION_1_1; + void (CL_CALLBACK *pfn_notify)(cl_mem memobj, + void *user_data), + void *user_data) CL_API_SUFFIX__VERSION_1_1; #endif @@ -1192,7 +1192,7 @@ clSetMemObjectDestructorCallback(cl_mem memobj, #ifdef CL_VERSION_2_0 -extern CL_API_ENTRY void * CL_API_CALL +extern CL_API_ENTRY void *CL_API_CALL clSVMAlloc(cl_context context, cl_svm_mem_flags flags, size_t size, @@ -1200,7 +1200,7 @@ clSVMAlloc(cl_context context, extern CL_API_ENTRY void CL_API_CALL clSVMFree(cl_context context, - void * svm_pointer) CL_API_SUFFIX__VERSION_2_0; + void *svm_pointer) CL_API_SUFFIX__VERSION_2_0; #endif @@ -1210,8 +1210,8 @@ clSVMFree(cl_context context, extern CL_API_ENTRY cl_sampler CL_API_CALL clCreateSamplerWithProperties(cl_context context, - const cl_sampler_properties * sampler_properties, - cl_int * errcode_ret) CL_API_SUFFIX__VERSION_2_0; + const cl_sampler_properties *sampler_properties, + cl_int *errcode_ret) CL_API_SUFFIX__VERSION_2_0; #endif @@ -1225,34 +1225,34 @@ extern CL_API_ENTRY cl_int CL_API_CALL clGetSamplerInfo(cl_sampler sampler, cl_sampler_info param_name, size_t param_value_size, - void * param_value, - size_t * param_value_size_ret) CL_API_SUFFIX__VERSION_1_0; + void *param_value, + size_t *param_value_size_ret) CL_API_SUFFIX__VERSION_1_0; /* Program Object APIs */ extern CL_API_ENTRY cl_program CL_API_CALL clCreateProgramWithSource(cl_context context, cl_uint count, - const char ** strings, - const size_t * lengths, - cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0; + const char **strings, + const size_t *lengths, + cl_int *errcode_ret) CL_API_SUFFIX__VERSION_1_0; extern CL_API_ENTRY cl_program CL_API_CALL clCreateProgramWithBinary(cl_context context, cl_uint num_devices, - const cl_device_id * device_list, - const size_t * lengths, - const unsigned char ** binaries, - cl_int * binary_status, - cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0; + const cl_device_id *device_list, + const size_t *lengths, + const unsigned char **binaries, + cl_int *binary_status, + cl_int *errcode_ret) CL_API_SUFFIX__VERSION_1_0; #ifdef CL_VERSION_1_2 extern CL_API_ENTRY cl_program CL_API_CALL clCreateProgramWithBuiltInKernels(cl_context context, cl_uint num_devices, - const cl_device_id * device_list, - const char * kernel_names, - cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_2; + const cl_device_id *device_list, + const char *kernel_names, + cl_int *errcode_ret) CL_API_SUFFIX__VERSION_1_2; #endif @@ -1260,9 +1260,9 @@ clCreateProgramWithBuiltInKernels(cl_context context, extern CL_API_ENTRY cl_program CL_API_CALL clCreateProgramWithIL(cl_context context, - const void* il, - size_t length, - cl_int* errcode_ret) CL_API_SUFFIX__VERSION_2_1; + const void *il, + size_t length, + cl_int *errcode_ret) CL_API_SUFFIX__VERSION_2_1; #endif @@ -1275,37 +1275,37 @@ clReleaseProgram(cl_program program) CL_API_SUFFIX__VERSION_1_0; extern CL_API_ENTRY cl_int CL_API_CALL clBuildProgram(cl_program program, cl_uint num_devices, - const cl_device_id * device_list, - const char * options, - void (CL_CALLBACK * pfn_notify)(cl_program program, - void * user_data), - void * user_data) CL_API_SUFFIX__VERSION_1_0; + const cl_device_id *device_list, + const char *options, + void (CL_CALLBACK *pfn_notify)(cl_program program, + void *user_data), + void *user_data) CL_API_SUFFIX__VERSION_1_0; #ifdef CL_VERSION_1_2 extern CL_API_ENTRY cl_int CL_API_CALL clCompileProgram(cl_program program, cl_uint num_devices, - const cl_device_id * device_list, - const char * options, + const cl_device_id *device_list, + const char *options, cl_uint num_input_headers, - const cl_program * input_headers, - const char ** header_include_names, - void (CL_CALLBACK * pfn_notify)(cl_program program, - void * user_data), - void * user_data) CL_API_SUFFIX__VERSION_1_2; + const cl_program *input_headers, + const char **header_include_names, + void (CL_CALLBACK *pfn_notify)(cl_program program, + void *user_data), + void *user_data) CL_API_SUFFIX__VERSION_1_2; extern CL_API_ENTRY cl_program CL_API_CALL clLinkProgram(cl_context context, cl_uint num_devices, - const cl_device_id * device_list, - const char * options, + const cl_device_id *device_list, + const char *options, cl_uint num_input_programs, - const cl_program * input_programs, - void (CL_CALLBACK * pfn_notify)(cl_program program, - void * user_data), - void * user_data, - cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_2; + const cl_program *input_programs, + void (CL_CALLBACK *pfn_notify)(cl_program program, + void *user_data), + void *user_data, + cl_int *errcode_ret) CL_API_SUFFIX__VERSION_1_2; #endif @@ -1313,15 +1313,15 @@ clLinkProgram(cl_context context, extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_2_2_DEPRECATED cl_int CL_API_CALL clSetProgramReleaseCallback(cl_program program, - void (CL_CALLBACK * pfn_notify)(cl_program program, - void * user_data), - void * user_data) CL_EXT_SUFFIX__VERSION_2_2_DEPRECATED; + void (CL_CALLBACK *pfn_notify)(cl_program program, + void *user_data), + void *user_data) CL_EXT_SUFFIX__VERSION_2_2_DEPRECATED; extern CL_API_ENTRY cl_int CL_API_CALL clSetProgramSpecializationConstant(cl_program program, cl_uint spec_id, size_t spec_size, - const void* spec_value) CL_API_SUFFIX__VERSION_2_2; + const void *spec_value) CL_API_SUFFIX__VERSION_2_2; #endif @@ -1336,34 +1336,34 @@ extern CL_API_ENTRY cl_int CL_API_CALL clGetProgramInfo(cl_program program, cl_program_info param_name, size_t param_value_size, - void * param_value, - size_t * param_value_size_ret) CL_API_SUFFIX__VERSION_1_0; + void *param_value, + size_t *param_value_size_ret) CL_API_SUFFIX__VERSION_1_0; extern CL_API_ENTRY cl_int CL_API_CALL clGetProgramBuildInfo(cl_program program, cl_device_id device, cl_program_build_info param_name, size_t param_value_size, - void * param_value, - size_t * param_value_size_ret) CL_API_SUFFIX__VERSION_1_0; + void *param_value, + size_t *param_value_size_ret) CL_API_SUFFIX__VERSION_1_0; /* Kernel Object APIs */ extern CL_API_ENTRY cl_kernel CL_API_CALL clCreateKernel(cl_program program, - const char * kernel_name, - cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0; + const char *kernel_name, + cl_int *errcode_ret) CL_API_SUFFIX__VERSION_1_0; extern CL_API_ENTRY cl_int CL_API_CALL clCreateKernelsInProgram(cl_program program, cl_uint num_kernels, - cl_kernel * kernels, - cl_uint * num_kernels_ret) CL_API_SUFFIX__VERSION_1_0; + cl_kernel *kernels, + cl_uint *num_kernels_ret) CL_API_SUFFIX__VERSION_1_0; #ifdef CL_VERSION_2_1 extern CL_API_ENTRY cl_kernel CL_API_CALL clCloneKernel(cl_kernel source_kernel, - cl_int* errcode_ret) CL_API_SUFFIX__VERSION_2_1; + cl_int *errcode_ret) CL_API_SUFFIX__VERSION_2_1; #endif @@ -1377,20 +1377,20 @@ extern CL_API_ENTRY cl_int CL_API_CALL clSetKernelArg(cl_kernel kernel, cl_uint arg_index, size_t arg_size, - const void * arg_value) CL_API_SUFFIX__VERSION_1_0; + const void *arg_value) CL_API_SUFFIX__VERSION_1_0; #ifdef CL_VERSION_2_0 extern CL_API_ENTRY cl_int CL_API_CALL clSetKernelArgSVMPointer(cl_kernel kernel, cl_uint arg_index, - const void * arg_value) CL_API_SUFFIX__VERSION_2_0; + const void *arg_value) CL_API_SUFFIX__VERSION_2_0; extern CL_API_ENTRY cl_int CL_API_CALL clSetKernelExecInfo(cl_kernel kernel, cl_kernel_exec_info param_name, size_t param_value_size, - const void * param_value) CL_API_SUFFIX__VERSION_2_0; + const void *param_value) CL_API_SUFFIX__VERSION_2_0; #endif @@ -1398,8 +1398,8 @@ extern CL_API_ENTRY cl_int CL_API_CALL clGetKernelInfo(cl_kernel kernel, cl_kernel_info param_name, size_t param_value_size, - void * param_value, - size_t * param_value_size_ret) CL_API_SUFFIX__VERSION_1_0; + void *param_value, + size_t *param_value_size_ret) CL_API_SUFFIX__VERSION_1_0; #ifdef CL_VERSION_1_2 @@ -1408,8 +1408,8 @@ clGetKernelArgInfo(cl_kernel kernel, cl_uint arg_indx, cl_kernel_arg_info param_name, size_t param_value_size, - void * param_value, - size_t * param_value_size_ret) CL_API_SUFFIX__VERSION_1_2; + void *param_value, + size_t *param_value_size_ret) CL_API_SUFFIX__VERSION_1_2; #endif @@ -1418,8 +1418,8 @@ clGetKernelWorkGroupInfo(cl_kernel kernel, cl_device_id device, cl_kernel_work_group_info param_name, size_t param_value_size, - void * param_value, - size_t * param_value_size_ret) CL_API_SUFFIX__VERSION_1_0; + void *param_value, + size_t *param_value_size_ret) CL_API_SUFFIX__VERSION_1_0; #ifdef CL_VERSION_2_1 @@ -1428,30 +1428,30 @@ clGetKernelSubGroupInfo(cl_kernel kernel, cl_device_id device, cl_kernel_sub_group_info param_name, size_t input_value_size, - const void* input_value, + const void *input_value, size_t param_value_size, - void* param_value, - size_t* param_value_size_ret) CL_API_SUFFIX__VERSION_2_1; + void *param_value, + size_t *param_value_size_ret) CL_API_SUFFIX__VERSION_2_1; #endif /* Event Object APIs */ extern CL_API_ENTRY cl_int CL_API_CALL clWaitForEvents(cl_uint num_events, - const cl_event * event_list) CL_API_SUFFIX__VERSION_1_0; + const cl_event *event_list) CL_API_SUFFIX__VERSION_1_0; extern CL_API_ENTRY cl_int CL_API_CALL clGetEventInfo(cl_event event, cl_event_info param_name, size_t param_value_size, - void * param_value, - size_t * param_value_size_ret) CL_API_SUFFIX__VERSION_1_0; + void *param_value, + size_t *param_value_size_ret) CL_API_SUFFIX__VERSION_1_0; #ifdef CL_VERSION_1_1 extern CL_API_ENTRY cl_event CL_API_CALL clCreateUserEvent(cl_context context, - cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_1; + cl_int *errcode_ret) CL_API_SUFFIX__VERSION_1_1; #endif @@ -1470,10 +1470,10 @@ clSetUserEventStatus(cl_event event, extern CL_API_ENTRY cl_int CL_API_CALL clSetEventCallback(cl_event event, cl_int command_exec_callback_type, - void (CL_CALLBACK * pfn_notify)(cl_event event, - cl_int event_command_status, - void * user_data), - void * user_data) CL_API_SUFFIX__VERSION_1_1; + void (CL_CALLBACK *pfn_notify)(cl_event event, + cl_int event_command_status, + void *user_data), + void *user_data) CL_API_SUFFIX__VERSION_1_1; #endif @@ -1482,8 +1482,8 @@ extern CL_API_ENTRY cl_int CL_API_CALL clGetEventProfilingInfo(cl_event event, cl_profiling_info param_name, size_t param_value_size, - void * param_value, - size_t * param_value_size_ret) CL_API_SUFFIX__VERSION_1_0; + void *param_value, + size_t *param_value_size_ret) CL_API_SUFFIX__VERSION_1_0; /* Flush and Finish APIs */ extern CL_API_ENTRY cl_int CL_API_CALL @@ -1499,10 +1499,10 @@ clEnqueueReadBuffer(cl_command_queue command_queue, cl_bool blocking_read, size_t offset, size_t size, - void * ptr, + void *ptr, cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event) CL_API_SUFFIX__VERSION_1_0; + const cl_event *event_wait_list, + cl_event *event) CL_API_SUFFIX__VERSION_1_0; #ifdef CL_VERSION_1_1 @@ -1510,17 +1510,17 @@ extern CL_API_ENTRY cl_int CL_API_CALL clEnqueueReadBufferRect(cl_command_queue command_queue, cl_mem buffer, cl_bool blocking_read, - const size_t * buffer_origin, - const size_t * host_origin, - const size_t * region, + const size_t *buffer_origin, + const size_t *host_origin, + const size_t *region, size_t buffer_row_pitch, size_t buffer_slice_pitch, size_t host_row_pitch, size_t host_slice_pitch, - void * ptr, + void *ptr, cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event) CL_API_SUFFIX__VERSION_1_1; + const cl_event *event_wait_list, + cl_event *event) CL_API_SUFFIX__VERSION_1_1; #endif @@ -1530,10 +1530,10 @@ clEnqueueWriteBuffer(cl_command_queue command_queue, cl_bool blocking_write, size_t offset, size_t size, - const void * ptr, + const void *ptr, cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event) CL_API_SUFFIX__VERSION_1_0; + const cl_event *event_wait_list, + cl_event *event) CL_API_SUFFIX__VERSION_1_0; #ifdef CL_VERSION_1_1 @@ -1541,17 +1541,17 @@ extern CL_API_ENTRY cl_int CL_API_CALL clEnqueueWriteBufferRect(cl_command_queue command_queue, cl_mem buffer, cl_bool blocking_write, - const size_t * buffer_origin, - const size_t * host_origin, - const size_t * region, + const size_t *buffer_origin, + const size_t *host_origin, + const size_t *region, size_t buffer_row_pitch, size_t buffer_slice_pitch, size_t host_row_pitch, size_t host_slice_pitch, - const void * ptr, + const void *ptr, cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event) CL_API_SUFFIX__VERSION_1_1; + const cl_event *event_wait_list, + cl_event *event) CL_API_SUFFIX__VERSION_1_1; #endif @@ -1560,13 +1560,13 @@ clEnqueueWriteBufferRect(cl_command_queue command_queue, extern CL_API_ENTRY cl_int CL_API_CALL clEnqueueFillBuffer(cl_command_queue command_queue, cl_mem buffer, - const void * pattern, + const void *pattern, size_t pattern_size, size_t offset, size_t size, cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event) CL_API_SUFFIX__VERSION_1_2; + const cl_event *event_wait_list, + cl_event *event) CL_API_SUFFIX__VERSION_1_2; #endif @@ -1578,8 +1578,8 @@ clEnqueueCopyBuffer(cl_command_queue command_queue, size_t dst_offset, size_t size, cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event) CL_API_SUFFIX__VERSION_1_0; + const cl_event *event_wait_list, + cl_event *event) CL_API_SUFFIX__VERSION_1_0; #ifdef CL_VERSION_1_1 @@ -1587,16 +1587,16 @@ extern CL_API_ENTRY cl_int CL_API_CALL clEnqueueCopyBufferRect(cl_command_queue command_queue, cl_mem src_buffer, cl_mem dst_buffer, - const size_t * src_origin, - const size_t * dst_origin, - const size_t * region, + const size_t *src_origin, + const size_t *dst_origin, + const size_t *region, size_t src_row_pitch, size_t src_slice_pitch, size_t dst_row_pitch, size_t dst_slice_pitch, cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event) CL_API_SUFFIX__VERSION_1_1; + const cl_event *event_wait_list, + cl_event *event) CL_API_SUFFIX__VERSION_1_1; #endif @@ -1604,39 +1604,39 @@ extern CL_API_ENTRY cl_int CL_API_CALL clEnqueueReadImage(cl_command_queue command_queue, cl_mem image, cl_bool blocking_read, - const size_t * origin, - const size_t * region, + const size_t *origin, + const size_t *region, size_t row_pitch, size_t slice_pitch, - void * ptr, + void *ptr, cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event) CL_API_SUFFIX__VERSION_1_0; + const cl_event *event_wait_list, + cl_event *event) CL_API_SUFFIX__VERSION_1_0; extern CL_API_ENTRY cl_int CL_API_CALL clEnqueueWriteImage(cl_command_queue command_queue, cl_mem image, cl_bool blocking_write, - const size_t * origin, - const size_t * region, + const size_t *origin, + const size_t *region, size_t input_row_pitch, size_t input_slice_pitch, - const void * ptr, + const void *ptr, cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event) CL_API_SUFFIX__VERSION_1_0; + const cl_event *event_wait_list, + cl_event *event) CL_API_SUFFIX__VERSION_1_0; #ifdef CL_VERSION_1_2 extern CL_API_ENTRY cl_int CL_API_CALL clEnqueueFillImage(cl_command_queue command_queue, cl_mem image, - const void * fill_color, - const size_t * origin, - const size_t * region, + const void *fill_color, + const size_t *origin, + const size_t *region, cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event) CL_API_SUFFIX__VERSION_1_2; + const cl_event *event_wait_list, + cl_event *event) CL_API_SUFFIX__VERSION_1_2; #endif @@ -1644,36 +1644,36 @@ extern CL_API_ENTRY cl_int CL_API_CALL clEnqueueCopyImage(cl_command_queue command_queue, cl_mem src_image, cl_mem dst_image, - const size_t * src_origin, - const size_t * dst_origin, - const size_t * region, + const size_t *src_origin, + const size_t *dst_origin, + const size_t *region, cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event) CL_API_SUFFIX__VERSION_1_0; + const cl_event *event_wait_list, + cl_event *event) CL_API_SUFFIX__VERSION_1_0; extern CL_API_ENTRY cl_int CL_API_CALL clEnqueueCopyImageToBuffer(cl_command_queue command_queue, cl_mem src_image, cl_mem dst_buffer, - const size_t * src_origin, - const size_t * region, + const size_t *src_origin, + const size_t *region, size_t dst_offset, cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event) CL_API_SUFFIX__VERSION_1_0; + const cl_event *event_wait_list, + cl_event *event) CL_API_SUFFIX__VERSION_1_0; extern CL_API_ENTRY cl_int CL_API_CALL clEnqueueCopyBufferToImage(cl_command_queue command_queue, cl_mem src_buffer, cl_mem dst_image, size_t src_offset, - const size_t * dst_origin, - const size_t * region, + const size_t *dst_origin, + const size_t *region, cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event) CL_API_SUFFIX__VERSION_1_0; + const cl_event *event_wait_list, + cl_event *event) CL_API_SUFFIX__VERSION_1_0; -extern CL_API_ENTRY void * CL_API_CALL +extern CL_API_ENTRY void *CL_API_CALL clEnqueueMapBuffer(cl_command_queue command_queue, cl_mem buffer, cl_bool blocking_map, @@ -1681,42 +1681,42 @@ clEnqueueMapBuffer(cl_command_queue command_queue, size_t offset, size_t size, cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event, - cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0; + const cl_event *event_wait_list, + cl_event *event, + cl_int *errcode_ret) CL_API_SUFFIX__VERSION_1_0; -extern CL_API_ENTRY void * CL_API_CALL +extern CL_API_ENTRY void *CL_API_CALL clEnqueueMapImage(cl_command_queue command_queue, cl_mem image, cl_bool blocking_map, cl_map_flags map_flags, - const size_t * origin, - const size_t * region, - size_t * image_row_pitch, - size_t * image_slice_pitch, + const size_t *origin, + const size_t *region, + size_t *image_row_pitch, + size_t *image_slice_pitch, cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event, - cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0; + const cl_event *event_wait_list, + cl_event *event, + cl_int *errcode_ret) CL_API_SUFFIX__VERSION_1_0; extern CL_API_ENTRY cl_int CL_API_CALL clEnqueueUnmapMemObject(cl_command_queue command_queue, cl_mem memobj, - void * mapped_ptr, + void *mapped_ptr, cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event) CL_API_SUFFIX__VERSION_1_0; + const cl_event *event_wait_list, + cl_event *event) CL_API_SUFFIX__VERSION_1_0; #ifdef CL_VERSION_1_2 extern CL_API_ENTRY cl_int CL_API_CALL clEnqueueMigrateMemObjects(cl_command_queue command_queue, cl_uint num_mem_objects, - const cl_mem * mem_objects, + const cl_mem *mem_objects, cl_mem_migration_flags flags, cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event) CL_API_SUFFIX__VERSION_1_2; + const cl_event *event_wait_list, + cl_event *event) CL_API_SUFFIX__VERSION_1_2; #endif @@ -1724,38 +1724,38 @@ extern CL_API_ENTRY cl_int CL_API_CALL clEnqueueNDRangeKernel(cl_command_queue command_queue, cl_kernel kernel, cl_uint work_dim, - const size_t * global_work_offset, - const size_t * global_work_size, - const size_t * local_work_size, + const size_t *global_work_offset, + const size_t *global_work_size, + const size_t *local_work_size, cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event) CL_API_SUFFIX__VERSION_1_0; + const cl_event *event_wait_list, + cl_event *event) CL_API_SUFFIX__VERSION_1_0; extern CL_API_ENTRY cl_int CL_API_CALL clEnqueueNativeKernel(cl_command_queue command_queue, - void (CL_CALLBACK * user_func)(void *), - void * args, + void (CL_CALLBACK *user_func)(void *), + void *args, size_t cb_args, cl_uint num_mem_objects, - const cl_mem * mem_list, - const void ** args_mem_loc, + const cl_mem *mem_list, + const void **args_mem_loc, cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event) CL_API_SUFFIX__VERSION_1_0; + const cl_event *event_wait_list, + cl_event *event) CL_API_SUFFIX__VERSION_1_0; #ifdef CL_VERSION_1_2 extern CL_API_ENTRY cl_int CL_API_CALL clEnqueueMarkerWithWaitList(cl_command_queue command_queue, cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event) CL_API_SUFFIX__VERSION_1_2; + const cl_event *event_wait_list, + cl_event *event) CL_API_SUFFIX__VERSION_1_2; extern CL_API_ENTRY cl_int CL_API_CALL clEnqueueBarrierWithWaitList(cl_command_queue command_queue, cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event) CL_API_SUFFIX__VERSION_1_2; + const cl_event *event_wait_list, + cl_event *event) CL_API_SUFFIX__VERSION_1_2; #endif @@ -1764,52 +1764,52 @@ clEnqueueBarrierWithWaitList(cl_command_queue command_queue, extern CL_API_ENTRY cl_int CL_API_CALL clEnqueueSVMFree(cl_command_queue command_queue, cl_uint num_svm_pointers, - void * svm_pointers[], - void (CL_CALLBACK * pfn_free_func)(cl_command_queue queue, - cl_uint num_svm_pointers, - void * svm_pointers[], - void * user_data), - void * user_data, + void *svm_pointers[], + void (CL_CALLBACK *pfn_free_func)(cl_command_queue queue, + cl_uint num_svm_pointers, + void *svm_pointers[], + void *user_data), + void *user_data, cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event) CL_API_SUFFIX__VERSION_2_0; + const cl_event *event_wait_list, + cl_event *event) CL_API_SUFFIX__VERSION_2_0; extern CL_API_ENTRY cl_int CL_API_CALL clEnqueueSVMMemcpy(cl_command_queue command_queue, cl_bool blocking_copy, - void * dst_ptr, - const void * src_ptr, + void *dst_ptr, + const void *src_ptr, size_t size, cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event) CL_API_SUFFIX__VERSION_2_0; + const cl_event *event_wait_list, + cl_event *event) CL_API_SUFFIX__VERSION_2_0; extern CL_API_ENTRY cl_int CL_API_CALL clEnqueueSVMMemFill(cl_command_queue command_queue, - void * svm_ptr, - const void * pattern, + void *svm_ptr, + const void *pattern, size_t pattern_size, size_t size, cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event) CL_API_SUFFIX__VERSION_2_0; + const cl_event *event_wait_list, + cl_event *event) CL_API_SUFFIX__VERSION_2_0; extern CL_API_ENTRY cl_int CL_API_CALL clEnqueueSVMMap(cl_command_queue command_queue, cl_bool blocking_map, cl_map_flags flags, - void * svm_ptr, + void *svm_ptr, size_t size, cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event) CL_API_SUFFIX__VERSION_2_0; + const cl_event *event_wait_list, + cl_event *event) CL_API_SUFFIX__VERSION_2_0; extern CL_API_ENTRY cl_int CL_API_CALL clEnqueueSVMUnmap(cl_command_queue command_queue, - void * svm_ptr, + void *svm_ptr, cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event) CL_API_SUFFIX__VERSION_2_0; + const cl_event *event_wait_list, + cl_event *event) CL_API_SUFFIX__VERSION_2_0; #endif @@ -1818,12 +1818,12 @@ clEnqueueSVMUnmap(cl_command_queue command_queue, extern CL_API_ENTRY cl_int CL_API_CALL clEnqueueSVMMigrateMem(cl_command_queue command_queue, cl_uint num_svm_pointers, - const void ** svm_pointers, - const size_t * sizes, + const void **svm_pointers, + const size_t *sizes, cl_mem_migration_flags flags, cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event) CL_API_SUFFIX__VERSION_2_1; + const cl_event *event_wait_list, + cl_event *event) CL_API_SUFFIX__VERSION_2_1; #endif @@ -1836,61 +1836,61 @@ clEnqueueSVMMigrateMem(cl_command_queue command_queue, * check to make sure the address is not NULL, before using or * calling the returned function address. */ -extern CL_API_ENTRY void * CL_API_CALL +extern CL_API_ENTRY void *CL_API_CALL clGetExtensionFunctionAddressForPlatform(cl_platform_id platform, - const char * func_name) CL_API_SUFFIX__VERSION_1_2; + const char *func_name) CL_API_SUFFIX__VERSION_1_2; #endif #ifdef CL_USE_DEPRECATED_OPENCL_1_0_APIS - /* - * WARNING: - * This API introduces mutable state into the OpenCL implementation. It has been REMOVED - * to better facilitate thread safety. The 1.0 API is not thread safe. It is not tested by the - * OpenCL 1.1 conformance test, and consequently may not work or may not work dependably. - * It is likely to be non-performant. Use of this API is not advised. Use at your own risk. - * - * Software developers previously relying on this API are instructed to set the command queue - * properties when creating the queue, instead. - */ - extern CL_API_ENTRY cl_int CL_API_CALL - clSetCommandQueueProperty(cl_command_queue command_queue, - cl_command_queue_properties properties, - cl_bool enable, - cl_command_queue_properties * old_properties) CL_EXT_SUFFIX__VERSION_1_0_DEPRECATED; +/* + * WARNING: + * This API introduces mutable state into the OpenCL implementation. It has been REMOVED + * to better facilitate thread safety. The 1.0 API is not thread safe. It is not tested by the + * OpenCL 1.1 conformance test, and consequently may not work or may not work dependably. + * It is likely to be non-performant. Use of this API is not advised. Use at your own risk. + * + * Software developers previously relying on this API are instructed to set the command queue + * properties when creating the queue, instead. + */ +extern CL_API_ENTRY cl_int CL_API_CALL +clSetCommandQueueProperty(cl_command_queue command_queue, + cl_command_queue_properties properties, + cl_bool enable, + cl_command_queue_properties *old_properties) CL_EXT_SUFFIX__VERSION_1_0_DEPRECATED; #endif /* CL_USE_DEPRECATED_OPENCL_1_0_APIS */ /* Deprecated OpenCL 1.1 APIs */ extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_mem CL_API_CALL clCreateImage2D(cl_context context, cl_mem_flags flags, - const cl_image_format * image_format, + const cl_image_format *image_format, size_t image_width, size_t image_height, size_t image_row_pitch, - void * host_ptr, - cl_int * errcode_ret) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; + void *host_ptr, + cl_int *errcode_ret) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_mem CL_API_CALL clCreateImage3D(cl_context context, cl_mem_flags flags, - const cl_image_format * image_format, + const cl_image_format *image_format, size_t image_width, size_t image_height, size_t image_depth, size_t image_row_pitch, size_t image_slice_pitch, - void * host_ptr, - cl_int * errcode_ret) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; + void *host_ptr, + cl_int *errcode_ret) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_int CL_API_CALL clEnqueueMarker(cl_command_queue command_queue, - cl_event * event) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; + cl_event *event) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_int CL_API_CALL clEnqueueWaitForEvents(cl_command_queue command_queue, - cl_uint num_events, - const cl_event * event_list) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; + cl_uint num_events, + const cl_event *event_list) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_int CL_API_CALL clEnqueueBarrier(cl_command_queue command_queue) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; @@ -1898,29 +1898,29 @@ clEnqueueBarrier(cl_command_queue command_queue) CL_EXT_SUFFIX__VERSION_1_1_DEPR extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_int CL_API_CALL clUnloadCompiler(void) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; -extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED void * CL_API_CALL -clGetExtensionFunctionAddress(const char * func_name) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; +extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED void *CL_API_CALL +clGetExtensionFunctionAddress(const char *func_name) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; /* Deprecated OpenCL 2.0 APIs */ extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_2_DEPRECATED cl_command_queue CL_API_CALL clCreateCommandQueue(cl_context context, cl_device_id device, cl_command_queue_properties properties, - cl_int * errcode_ret) CL_EXT_SUFFIX__VERSION_1_2_DEPRECATED; + cl_int *errcode_ret) CL_EXT_SUFFIX__VERSION_1_2_DEPRECATED; extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_2_DEPRECATED cl_sampler CL_API_CALL clCreateSampler(cl_context context, cl_bool normalized_coords, cl_addressing_mode addressing_mode, cl_filter_mode filter_mode, - cl_int * errcode_ret) CL_EXT_SUFFIX__VERSION_1_2_DEPRECATED; + cl_int *errcode_ret) CL_EXT_SUFFIX__VERSION_1_2_DEPRECATED; extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_2_DEPRECATED cl_int CL_API_CALL clEnqueueTask(cl_command_queue command_queue, cl_kernel kernel, cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event) CL_EXT_SUFFIX__VERSION_1_2_DEPRECATED; + const cl_event *event_wait_list, + cl_event *event) CL_EXT_SUFFIX__VERSION_1_2_DEPRECATED; #ifdef __cplusplus } diff --git a/tools/hitag2crack/common/OpenCL-Headers/CL/cl_d3d10.h b/tools/hitag2crack/common/OpenCL-Headers/CL/cl_d3d10.h index 2b80d90cb..c355e4b42 100644 --- a/tools/hitag2crack/common/OpenCL-Headers/CL/cl_d3d10.h +++ b/tools/hitag2crack/common/OpenCL-Headers/CL/cl_d3d10.h @@ -75,50 +75,50 @@ typedef cl_uint cl_d3d10_device_set_khr; /******************************************************************************/ -typedef CL_API_ENTRY cl_int (CL_API_CALL *clGetDeviceIDsFromD3D10KHR_fn)( +typedef CL_API_ENTRY cl_int(CL_API_CALL *clGetDeviceIDsFromD3D10KHR_fn)( cl_platform_id platform, cl_d3d10_device_source_khr d3d_device_source, - void * d3d_object, + void *d3d_object, cl_d3d10_device_set_khr d3d_device_set, cl_uint num_entries, - cl_device_id * devices, - cl_uint * num_devices) CL_API_SUFFIX__VERSION_1_0; + cl_device_id *devices, + cl_uint *num_devices) CL_API_SUFFIX__VERSION_1_0; -typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromD3D10BufferKHR_fn)( +typedef CL_API_ENTRY cl_mem(CL_API_CALL *clCreateFromD3D10BufferKHR_fn)( cl_context context, cl_mem_flags flags, - ID3D10Buffer * resource, - cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0; + ID3D10Buffer *resource, + cl_int *errcode_ret) CL_API_SUFFIX__VERSION_1_0; -typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromD3D10Texture2DKHR_fn)( +typedef CL_API_ENTRY cl_mem(CL_API_CALL *clCreateFromD3D10Texture2DKHR_fn)( cl_context context, cl_mem_flags flags, - ID3D10Texture2D * resource, + ID3D10Texture2D *resource, UINT subresource, - cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0; + cl_int *errcode_ret) CL_API_SUFFIX__VERSION_1_0; -typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromD3D10Texture3DKHR_fn)( +typedef CL_API_ENTRY cl_mem(CL_API_CALL *clCreateFromD3D10Texture3DKHR_fn)( cl_context context, cl_mem_flags flags, - ID3D10Texture3D * resource, + ID3D10Texture3D *resource, UINT subresource, - cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0; + cl_int *errcode_ret) CL_API_SUFFIX__VERSION_1_0; -typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueAcquireD3D10ObjectsKHR_fn)( +typedef CL_API_ENTRY cl_int(CL_API_CALL *clEnqueueAcquireD3D10ObjectsKHR_fn)( cl_command_queue command_queue, cl_uint num_objects, - const cl_mem * mem_objects, + const cl_mem *mem_objects, cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event) CL_API_SUFFIX__VERSION_1_0; + const cl_event *event_wait_list, + cl_event *event) CL_API_SUFFIX__VERSION_1_0; -typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueReleaseD3D10ObjectsKHR_fn)( +typedef CL_API_ENTRY cl_int(CL_API_CALL *clEnqueueReleaseD3D10ObjectsKHR_fn)( cl_command_queue command_queue, cl_uint num_objects, - const cl_mem * mem_objects, + const cl_mem *mem_objects, cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event) CL_API_SUFFIX__VERSION_1_0; + const cl_event *event_wait_list, + cl_event *event) CL_API_SUFFIX__VERSION_1_0; #ifdef __cplusplus } diff --git a/tools/hitag2crack/common/OpenCL-Headers/CL/cl_d3d11.h b/tools/hitag2crack/common/OpenCL-Headers/CL/cl_d3d11.h index 10023dde0..f9aac7180 100644 --- a/tools/hitag2crack/common/OpenCL-Headers/CL/cl_d3d11.h +++ b/tools/hitag2crack/common/OpenCL-Headers/CL/cl_d3d11.h @@ -75,50 +75,50 @@ typedef cl_uint cl_d3d11_device_set_khr; /******************************************************************************/ -typedef CL_API_ENTRY cl_int (CL_API_CALL *clGetDeviceIDsFromD3D11KHR_fn)( +typedef CL_API_ENTRY cl_int(CL_API_CALL *clGetDeviceIDsFromD3D11KHR_fn)( cl_platform_id platform, cl_d3d11_device_source_khr d3d_device_source, - void * d3d_object, + void *d3d_object, cl_d3d11_device_set_khr d3d_device_set, cl_uint num_entries, - cl_device_id * devices, - cl_uint * num_devices) CL_API_SUFFIX__VERSION_1_2; + cl_device_id *devices, + cl_uint *num_devices) CL_API_SUFFIX__VERSION_1_2; -typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromD3D11BufferKHR_fn)( +typedef CL_API_ENTRY cl_mem(CL_API_CALL *clCreateFromD3D11BufferKHR_fn)( cl_context context, cl_mem_flags flags, - ID3D11Buffer * resource, - cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_2; + ID3D11Buffer *resource, + cl_int *errcode_ret) CL_API_SUFFIX__VERSION_1_2; -typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromD3D11Texture2DKHR_fn)( +typedef CL_API_ENTRY cl_mem(CL_API_CALL *clCreateFromD3D11Texture2DKHR_fn)( cl_context context, cl_mem_flags flags, - ID3D11Texture2D * resource, + ID3D11Texture2D *resource, UINT subresource, - cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_2; + cl_int *errcode_ret) CL_API_SUFFIX__VERSION_1_2; -typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromD3D11Texture3DKHR_fn)( +typedef CL_API_ENTRY cl_mem(CL_API_CALL *clCreateFromD3D11Texture3DKHR_fn)( cl_context context, cl_mem_flags flags, - ID3D11Texture3D * resource, + ID3D11Texture3D *resource, UINT subresource, - cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_2; + cl_int *errcode_ret) CL_API_SUFFIX__VERSION_1_2; -typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueAcquireD3D11ObjectsKHR_fn)( +typedef CL_API_ENTRY cl_int(CL_API_CALL *clEnqueueAcquireD3D11ObjectsKHR_fn)( cl_command_queue command_queue, cl_uint num_objects, - const cl_mem * mem_objects, + const cl_mem *mem_objects, cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event) CL_API_SUFFIX__VERSION_1_2; + const cl_event *event_wait_list, + cl_event *event) CL_API_SUFFIX__VERSION_1_2; -typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueReleaseD3D11ObjectsKHR_fn)( +typedef CL_API_ENTRY cl_int(CL_API_CALL *clEnqueueReleaseD3D11ObjectsKHR_fn)( cl_command_queue command_queue, cl_uint num_objects, - const cl_mem * mem_objects, + const cl_mem *mem_objects, cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event) CL_API_SUFFIX__VERSION_1_2; + const cl_event *event_wait_list, + cl_event *event) CL_API_SUFFIX__VERSION_1_2; #ifdef __cplusplus } diff --git a/tools/hitag2crack/common/OpenCL-Headers/CL/cl_dx9_media_sharing.h b/tools/hitag2crack/common/OpenCL-Headers/CL/cl_dx9_media_sharing.h index 048937005..162836d28 100644 --- a/tools/hitag2crack/common/OpenCL-Headers/CL/cl_dx9_media_sharing.h +++ b/tools/hitag2crack/common/OpenCL-Headers/CL/cl_dx9_media_sharing.h @@ -30,11 +30,10 @@ extern "C" { typedef cl_uint cl_dx9_media_adapter_type_khr; typedef cl_uint cl_dx9_media_adapter_set_khr; - + #if defined(_WIN32) #include -typedef struct _cl_dx9_surface_info_khr -{ +typedef struct _cl_dx9_surface_info_khr { IDirect3DSurface9 *resource; HANDLE shared_handle; } cl_dx9_surface_info_khr; @@ -76,39 +75,39 @@ typedef struct _cl_dx9_surface_info_khr /******************************************************************************/ -typedef CL_API_ENTRY cl_int (CL_API_CALL *clGetDeviceIDsFromDX9MediaAdapterKHR_fn)( +typedef CL_API_ENTRY cl_int(CL_API_CALL *clGetDeviceIDsFromDX9MediaAdapterKHR_fn)( cl_platform_id platform, cl_uint num_media_adapters, - cl_dx9_media_adapter_type_khr * media_adapter_type, - void * media_adapters, + cl_dx9_media_adapter_type_khr *media_adapter_type, + void *media_adapters, cl_dx9_media_adapter_set_khr media_adapter_set, cl_uint num_entries, - cl_device_id * devices, - cl_uint * num_devices) CL_API_SUFFIX__VERSION_1_2; + cl_device_id *devices, + cl_uint *num_devices) CL_API_SUFFIX__VERSION_1_2; -typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromDX9MediaSurfaceKHR_fn)( +typedef CL_API_ENTRY cl_mem(CL_API_CALL *clCreateFromDX9MediaSurfaceKHR_fn)( cl_context context, cl_mem_flags flags, cl_dx9_media_adapter_type_khr adapter_type, - void * surface_info, - cl_uint plane, - cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_2; + void *surface_info, + cl_uint plane, + cl_int *errcode_ret) CL_API_SUFFIX__VERSION_1_2; -typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueAcquireDX9MediaSurfacesKHR_fn)( +typedef CL_API_ENTRY cl_int(CL_API_CALL *clEnqueueAcquireDX9MediaSurfacesKHR_fn)( cl_command_queue command_queue, cl_uint num_objects, - const cl_mem * mem_objects, + const cl_mem *mem_objects, cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event) CL_API_SUFFIX__VERSION_1_2; + const cl_event *event_wait_list, + cl_event *event) CL_API_SUFFIX__VERSION_1_2; -typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueReleaseDX9MediaSurfacesKHR_fn)( +typedef CL_API_ENTRY cl_int(CL_API_CALL *clEnqueueReleaseDX9MediaSurfacesKHR_fn)( cl_command_queue command_queue, cl_uint num_objects, - const cl_mem * mem_objects, + const cl_mem *mem_objects, cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event) CL_API_SUFFIX__VERSION_1_2; + const cl_event *event_wait_list, + cl_event *event) CL_API_SUFFIX__VERSION_1_2; #ifdef __cplusplus } diff --git a/tools/hitag2crack/common/OpenCL-Headers/CL/cl_dx9_media_sharing_intel.h b/tools/hitag2crack/common/OpenCL-Headers/CL/cl_dx9_media_sharing_intel.h index 4525a175e..fb9994588 100644 --- a/tools/hitag2crack/common/OpenCL-Headers/CL/cl_dx9_media_sharing_intel.h +++ b/tools/hitag2crack/common/OpenCL-Headers/CL/cl_dx9_media_sharing_intel.h @@ -96,71 +96,71 @@ extern CL_API_ENTRY cl_int CL_API_CALL clGetDeviceIDsFromDX9INTEL( cl_platform_id platform, cl_dx9_device_source_intel dx9_device_source, - void* dx9_object, + void *dx9_object, cl_dx9_device_set_intel dx9_device_set, cl_uint num_entries, - cl_device_id* devices, - cl_uint* num_devices) CL_EXT_SUFFIX__VERSION_1_1; + cl_device_id *devices, + cl_uint *num_devices) CL_EXT_SUFFIX__VERSION_1_1; -typedef CL_API_ENTRY cl_int (CL_API_CALL* clGetDeviceIDsFromDX9INTEL_fn)( +typedef CL_API_ENTRY cl_int(CL_API_CALL *clGetDeviceIDsFromDX9INTEL_fn)( cl_platform_id platform, cl_dx9_device_source_intel dx9_device_source, - void* dx9_object, + void *dx9_object, cl_dx9_device_set_intel dx9_device_set, cl_uint num_entries, - cl_device_id* devices, - cl_uint* num_devices) CL_EXT_SUFFIX__VERSION_1_1; + cl_device_id *devices, + cl_uint *num_devices) CL_EXT_SUFFIX__VERSION_1_1; extern CL_API_ENTRY cl_mem CL_API_CALL clCreateFromDX9MediaSurfaceINTEL( cl_context context, cl_mem_flags flags, - IDirect3DSurface9* resource, + IDirect3DSurface9 *resource, HANDLE sharedHandle, UINT plane, - cl_int* errcode_ret) CL_EXT_SUFFIX__VERSION_1_1; + cl_int *errcode_ret) CL_EXT_SUFFIX__VERSION_1_1; -typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromDX9MediaSurfaceINTEL_fn)( +typedef CL_API_ENTRY cl_mem(CL_API_CALL *clCreateFromDX9MediaSurfaceINTEL_fn)( cl_context context, cl_mem_flags flags, - IDirect3DSurface9* resource, + IDirect3DSurface9 *resource, HANDLE sharedHandle, UINT plane, - cl_int* errcode_ret) CL_EXT_SUFFIX__VERSION_1_1; + cl_int *errcode_ret) CL_EXT_SUFFIX__VERSION_1_1; extern CL_API_ENTRY cl_int CL_API_CALL clEnqueueAcquireDX9ObjectsINTEL( cl_command_queue command_queue, cl_uint num_objects, - const cl_mem* mem_objects, + const cl_mem *mem_objects, cl_uint num_events_in_wait_list, - const cl_event* event_wait_list, - cl_event* event) CL_EXT_SUFFIX__VERSION_1_1; + const cl_event *event_wait_list, + cl_event *event) CL_EXT_SUFFIX__VERSION_1_1; -typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueAcquireDX9ObjectsINTEL_fn)( +typedef CL_API_ENTRY cl_int(CL_API_CALL *clEnqueueAcquireDX9ObjectsINTEL_fn)( cl_command_queue command_queue, cl_uint num_objects, - const cl_mem* mem_objects, + const cl_mem *mem_objects, cl_uint num_events_in_wait_list, - const cl_event* event_wait_list, - cl_event* event) CL_EXT_SUFFIX__VERSION_1_1; + const cl_event *event_wait_list, + cl_event *event) CL_EXT_SUFFIX__VERSION_1_1; extern CL_API_ENTRY cl_int CL_API_CALL clEnqueueReleaseDX9ObjectsINTEL( cl_command_queue command_queue, cl_uint num_objects, - cl_mem* mem_objects, + cl_mem *mem_objects, cl_uint num_events_in_wait_list, - const cl_event* event_wait_list, - cl_event* event) CL_EXT_SUFFIX__VERSION_1_1; + const cl_event *event_wait_list, + cl_event *event) CL_EXT_SUFFIX__VERSION_1_1; -typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueReleaseDX9ObjectsINTEL_fn)( +typedef CL_API_ENTRY cl_int(CL_API_CALL *clEnqueueReleaseDX9ObjectsINTEL_fn)( cl_command_queue command_queue, cl_uint num_objects, - cl_mem* mem_objects, + cl_mem *mem_objects, cl_uint num_events_in_wait_list, - const cl_event* event_wait_list, - cl_event* event) CL_EXT_SUFFIX__VERSION_1_1; + const cl_event *event_wait_list, + cl_event *event) CL_EXT_SUFFIX__VERSION_1_1; #ifdef __cplusplus } diff --git a/tools/hitag2crack/common/OpenCL-Headers/CL/cl_egl.h b/tools/hitag2crack/common/OpenCL-Headers/CL/cl_egl.h index c8bde80e1..b1670c6bb 100644 --- a/tools/hitag2crack/common/OpenCL-Headers/CL/cl_egl.h +++ b/tools/hitag2crack/common/OpenCL-Headers/CL/cl_egl.h @@ -34,13 +34,13 @@ extern "C" { #define CL_EGL_RESOURCE_NOT_ACQUIRED_KHR -1092 /* CLeglImageKHR is an opaque handle to an EGLImage */ -typedef void* CLeglImageKHR; +typedef void *CLeglImageKHR; /* CLeglDisplayKHR is an opaque handle to an EGLDisplay */ -typedef void* CLeglDisplayKHR; +typedef void *CLeglDisplayKHR; /* CLeglSyncKHR is an opaque handle to an EGLSync object */ -typedef void* CLeglSyncKHR; +typedef void *CLeglSyncKHR; /* properties passed to clCreateFromEGLImageKHR */ typedef intptr_t cl_egl_image_properties_khr; @@ -53,50 +53,50 @@ clCreateFromEGLImageKHR(cl_context context, CLeglDisplayKHR egldisplay, CLeglImageKHR eglimage, cl_mem_flags flags, - const cl_egl_image_properties_khr * properties, - cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0; + const cl_egl_image_properties_khr *properties, + cl_int *errcode_ret) CL_API_SUFFIX__VERSION_1_0; -typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromEGLImageKHR_fn)( +typedef CL_API_ENTRY cl_mem(CL_API_CALL *clCreateFromEGLImageKHR_fn)( cl_context context, CLeglDisplayKHR egldisplay, CLeglImageKHR eglimage, cl_mem_flags flags, - const cl_egl_image_properties_khr * properties, - cl_int * errcode_ret); + const cl_egl_image_properties_khr *properties, + cl_int *errcode_ret); extern CL_API_ENTRY cl_int CL_API_CALL clEnqueueAcquireEGLObjectsKHR(cl_command_queue command_queue, cl_uint num_objects, - const cl_mem * mem_objects, + const cl_mem *mem_objects, cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event) CL_API_SUFFIX__VERSION_1_0; + const cl_event *event_wait_list, + cl_event *event) CL_API_SUFFIX__VERSION_1_0; -typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueAcquireEGLObjectsKHR_fn)( +typedef CL_API_ENTRY cl_int(CL_API_CALL *clEnqueueAcquireEGLObjectsKHR_fn)( cl_command_queue command_queue, cl_uint num_objects, - const cl_mem * mem_objects, + const cl_mem *mem_objects, cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event); + const cl_event *event_wait_list, + cl_event *event); extern CL_API_ENTRY cl_int CL_API_CALL clEnqueueReleaseEGLObjectsKHR(cl_command_queue command_queue, cl_uint num_objects, - const cl_mem * mem_objects, + const cl_mem *mem_objects, cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event) CL_API_SUFFIX__VERSION_1_0; + const cl_event *event_wait_list, + cl_event *event) CL_API_SUFFIX__VERSION_1_0; -typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueReleaseEGLObjectsKHR_fn)( +typedef CL_API_ENTRY cl_int(CL_API_CALL *clEnqueueReleaseEGLObjectsKHR_fn)( cl_command_queue command_queue, cl_uint num_objects, - const cl_mem * mem_objects, + const cl_mem *mem_objects, cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event); + const cl_event *event_wait_list, + cl_event *event); #define cl_khr_egl_event 1 @@ -105,13 +105,13 @@ extern CL_API_ENTRY cl_event CL_API_CALL clCreateEventFromEGLSyncKHR(cl_context context, CLeglSyncKHR sync, CLeglDisplayKHR display, - cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0; + cl_int *errcode_ret) CL_API_SUFFIX__VERSION_1_0; -typedef CL_API_ENTRY cl_event (CL_API_CALL *clCreateEventFromEGLSyncKHR_fn)( +typedef CL_API_ENTRY cl_event(CL_API_CALL *clCreateEventFromEGLSyncKHR_fn)( cl_context context, CLeglSyncKHR sync, CLeglDisplayKHR display, - cl_int * errcode_ret); + cl_int *errcode_ret); #ifdef __cplusplus } diff --git a/tools/hitag2crack/common/OpenCL-Headers/CL/cl_ext.h b/tools/hitag2crack/common/OpenCL-Headers/CL/cl_ext.h index 0239b6413..6ba1e9bbd 100644 --- a/tools/hitag2crack/common/OpenCL-Headers/CL/cl_ext.h +++ b/tools/hitag2crack/common/OpenCL-Headers/CL/cl_ext.h @@ -54,9 +54,9 @@ extern "C" { * before using. */ #define cl_APPLE_SetMemObjectDestructor 1 -cl_int CL_API_ENTRY clSetMemObjectDestructorAPPLE( cl_mem memobj, - void (* pfn_notify)(cl_mem memobj, void * user_data), - void * user_data) CL_EXT_SUFFIX__VERSION_1_0; +cl_int CL_API_ENTRY clSetMemObjectDestructorAPPLE(cl_mem memobj, + void (* pfn_notify)(cl_mem memobj, void *user_data), + void *user_data) CL_EXT_SUFFIX__VERSION_1_0; /* Context Logging Functions @@ -68,22 +68,22 @@ cl_int CL_API_ENTRY clSetMemObjectDestructorAPPLE( cl_mem memobj, * clLogMessagesToSystemLog forwards on all log messages to the Apple System Logger */ #define cl_APPLE_ContextLoggingFunctions 1 -extern void CL_API_ENTRY clLogMessagesToSystemLogAPPLE( const char * errstr, - const void * private_info, - size_t cb, - void * user_data) CL_EXT_SUFFIX__VERSION_1_0; +extern void CL_API_ENTRY clLogMessagesToSystemLogAPPLE(const char *errstr, + const void *private_info, + size_t cb, + void *user_data) CL_EXT_SUFFIX__VERSION_1_0; /* clLogMessagesToStdout sends all log messages to the file descriptor stdout */ -extern void CL_API_ENTRY clLogMessagesToStdoutAPPLE( const char * errstr, - const void * private_info, - size_t cb, - void * user_data) CL_EXT_SUFFIX__VERSION_1_0; +extern void CL_API_ENTRY clLogMessagesToStdoutAPPLE(const char *errstr, + const void *private_info, + size_t cb, + void *user_data) CL_EXT_SUFFIX__VERSION_1_0; /* clLogMessagesToStderr sends all log messages to the file descriptor stderr */ -extern void CL_API_ENTRY clLogMessagesToStderrAPPLE( const char * errstr, - const void * private_info, - size_t cb, - void * user_data) CL_EXT_SUFFIX__VERSION_1_0; +extern void CL_API_ENTRY clLogMessagesToStderrAPPLE(const char *errstr, + const void *private_info, + size_t cb, + void *user_data) CL_EXT_SUFFIX__VERSION_1_0; /************************ @@ -99,13 +99,13 @@ extern void CL_API_ENTRY clLogMessagesToStderrAPPLE( const char * errstr, extern CL_API_ENTRY cl_int CL_API_CALL clIcdGetPlatformIDsKHR(cl_uint num_entries, - cl_platform_id * platforms, - cl_uint * num_platforms); + cl_platform_id *platforms, + cl_uint *num_platforms); typedef CL_API_ENTRY cl_int (CL_API_CALL *clIcdGetPlatformIDsKHR_fn)(cl_uint num_entries, - cl_platform_id * platforms, - cl_uint * num_platforms); + cl_platform_id *platforms, + cl_uint *num_platforms); /******************************* @@ -125,15 +125,15 @@ typedef CL_API_ENTRY cl_int extern CL_API_ENTRY cl_program CL_API_CALL clCreateProgramWithILKHR(cl_context context, - const void * il, + const void *il, size_t length, - cl_int * errcode_ret); + cl_int *errcode_ret); typedef CL_API_ENTRY cl_program (CL_API_CALL *clCreateProgramWithILKHR_fn)(cl_context context, - const void * il, + const void *il, size_t length, - cl_int * errcode_ret) CL_EXT_SUFFIX__VERSION_1_2; + cl_int *errcode_ret) CL_EXT_SUFFIX__VERSION_1_2; /* Extension: cl_khr_image2d_from_buffer * @@ -203,14 +203,14 @@ typedef cl_properties cl_queue_properties_khr; extern CL_API_ENTRY cl_command_queue CL_API_CALL clCreateCommandQueueWithPropertiesKHR(cl_context context, cl_device_id device, - const cl_queue_properties_khr* properties, - cl_int* errcode_ret) CL_EXT_SUFFIX__VERSION_1_2; + const cl_queue_properties_khr *properties, + cl_int *errcode_ret) CL_EXT_SUFFIX__VERSION_1_2; typedef CL_API_ENTRY cl_command_queue (CL_API_CALL *clCreateCommandQueueWithPropertiesKHR_fn)(cl_context context, cl_device_id device, - const cl_queue_properties_khr* properties, - cl_int* errcode_ret) CL_EXT_SUFFIX__VERSION_1_2; + const cl_queue_properties_khr *properties, + cl_int *errcode_ret) CL_EXT_SUFFIX__VERSION_1_2; /****************************************** @@ -282,17 +282,17 @@ typedef CL_API_ENTRY cl_int typedef cl_ulong cl_device_partition_property_ext; extern CL_API_ENTRY cl_int CL_API_CALL clCreateSubDevicesEXT(cl_device_id in_device, - const cl_device_partition_property_ext * properties, + const cl_device_partition_property_ext *properties, cl_uint num_entries, - cl_device_id * out_devices, - cl_uint * num_devices) CL_EXT_SUFFIX__VERSION_1_1; + cl_device_id *out_devices, + cl_uint *num_devices) CL_EXT_SUFFIX__VERSION_1_1; typedef CL_API_ENTRY cl_int -(CL_API_CALL * clCreateSubDevicesEXT_fn)(cl_device_id in_device, - const cl_device_partition_property_ext * properties, - cl_uint num_entries, - cl_device_id * out_devices, - cl_uint * num_devices) CL_EXT_SUFFIX__VERSION_1_1; +(CL_API_CALL *clCreateSubDevicesEXT_fn)(cl_device_id in_device, + const cl_device_partition_property_ext *properties, + cl_uint num_entries, + cl_device_id *out_devices, + cl_uint *num_devices) CL_EXT_SUFFIX__VERSION_1_1; /* cl_device_partition_property_ext */ #define CL_DEVICE_PARTITION_EQUALLY_EXT 0x4050 @@ -340,20 +340,20 @@ typedef cl_bitfield cl_mem_migration_flags_ext; extern CL_API_ENTRY cl_int CL_API_CALL clEnqueueMigrateMemObjectEXT(cl_command_queue command_queue, cl_uint num_mem_objects, - const cl_mem * mem_objects, + const cl_mem *mem_objects, cl_mem_migration_flags_ext flags, cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event); + const cl_event *event_wait_list, + cl_event *event); typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueMigrateMemObjectEXT_fn)(cl_command_queue command_queue, cl_uint num_mem_objects, - const cl_mem * mem_objects, + const cl_mem *mem_objects, cl_mem_migration_flags_ext flags, cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event); + const cl_event *event_wait_list, + cl_event *event); /********************************* @@ -391,8 +391,7 @@ clGetDeviceImageInfoQCOM(cl_device_id device, void *param_value, size_t *param_value_size_ret); -typedef struct _cl_mem_ext_host_ptr -{ +typedef struct _cl_mem_ext_host_ptr { /* Type of external memory allocation. */ /* Legal values will be defined in layered extensions. */ cl_uint allocation_type; @@ -417,8 +416,7 @@ typedef struct _cl_mem_ext_host_ptr #define CL_MEM_ION_HOST_PTR_QCOM 0x40A8 -typedef struct _cl_mem_ion_host_ptr -{ +typedef struct _cl_mem_ion_host_ptr { /* Type of external memory allocation. */ /* Must be CL_MEM_ION_HOST_PTR_QCOM for ION allocations. */ cl_mem_ext_host_ptr ext_host_ptr; @@ -427,7 +425,7 @@ typedef struct _cl_mem_ion_host_ptr int ion_filedesc; /* Host pointer to the ION allocated memory */ - void* ion_hostptr; + void *ion_hostptr; } cl_mem_ion_host_ptr; @@ -438,14 +436,13 @@ typedef struct _cl_mem_ion_host_ptr #define CL_MEM_ANDROID_NATIVE_BUFFER_HOST_PTR_QCOM 0x40C6 -typedef struct _cl_mem_android_native_buffer_host_ptr -{ +typedef struct _cl_mem_android_native_buffer_host_ptr { /* Type of external memory allocation. */ /* Must be CL_MEM_ANDROID_NATIVE_BUFFER_HOST_PTR_QCOM for Android native buffers. */ cl_mem_ext_host_ptr ext_host_ptr; /* Virtual pointer to the android native buffer */ - void* anb_ptr; + void *anb_ptr; } cl_mem_android_native_buffer_host_ptr; @@ -487,18 +484,18 @@ typedef struct _cl_mem_android_native_buffer_host_ptr extern CL_API_ENTRY cl_int CL_API_CALL clEnqueueAcquireGrallocObjectsIMG(cl_command_queue command_queue, cl_uint num_objects, - const cl_mem * mem_objects, + const cl_mem *mem_objects, cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event) CL_EXT_SUFFIX__VERSION_1_2; + const cl_event *event_wait_list, + cl_event *event) CL_EXT_SUFFIX__VERSION_1_2; extern CL_API_ENTRY cl_int CL_API_CALL clEnqueueReleaseGrallocObjectsIMG(cl_command_queue command_queue, cl_uint num_objects, - const cl_mem * mem_objects, + const cl_mem *mem_objects, cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event) CL_EXT_SUFFIX__VERSION_1_2; + const cl_event *event_wait_list, + cl_event *event) CL_EXT_SUFFIX__VERSION_1_2; /****************************************** * cl_img_generate_mipmap extension * @@ -524,7 +521,7 @@ clEnqueueGenerateMipmapIMG(cl_command_queue command_queue, cl_uint num_events_in_wait_list, const cl_event *event_wait_list, cl_event *event) CL_EXT_SUFFIX__VERSION_1_2; - + /****************************************** * cl_img_mem_properties extension * ******************************************/ @@ -561,20 +558,20 @@ clGetKernelSubGroupInfoKHR(cl_kernel in_kernel, cl_device_id in_device, cl_kernel_sub_group_info param_name, size_t input_value_size, - const void * input_value, + const void *input_value, size_t param_value_size, - void * param_value, - size_t * param_value_size_ret) CL_EXT_SUFFIX__VERSION_2_0_DEPRECATED; + void *param_value, + size_t *param_value_size_ret) CL_EXT_SUFFIX__VERSION_2_0_DEPRECATED; typedef CL_API_ENTRY cl_int -(CL_API_CALL * clGetKernelSubGroupInfoKHR_fn)(cl_kernel in_kernel, - cl_device_id in_device, - cl_kernel_sub_group_info param_name, - size_t input_value_size, - const void * input_value, - size_t param_value_size, - void * param_value, - size_t * param_value_size_ret) CL_EXT_SUFFIX__VERSION_2_0_DEPRECATED; +(CL_API_CALL *clGetKernelSubGroupInfoKHR_fn)(cl_kernel in_kernel, + cl_device_id in_device, + cl_kernel_sub_group_info param_name, + size_t input_value_size, + const void *input_value, + size_t param_value_size, + void *param_value, + size_t *param_value_size_ret) CL_EXT_SUFFIX__VERSION_2_0_DEPRECATED; /********************************* @@ -661,8 +658,7 @@ typedef cl_uint cl_version_khr; #define CL_NAME_VERSION_MAX_NAME_SIZE_KHR 64 -typedef struct _cl_name_version_khr -{ +typedef struct _cl_name_version_khr { cl_version_khr version; char name[CL_NAME_VERSION_MAX_NAME_SIZE_KHR]; } cl_name_version_khr; @@ -739,12 +735,12 @@ typedef intptr_t cl_import_properties_arm; * function clCreateBuffer. */ extern CL_API_ENTRY cl_mem CL_API_CALL -clImportMemoryARM( cl_context context, - cl_mem_flags flags, - const cl_import_properties_arm *properties, - void *memory, - size_t size, - cl_int *errcode_ret) CL_EXT_SUFFIX__VERSION_1_0; +clImportMemoryARM(cl_context context, + cl_mem_flags flags, + const cl_import_properties_arm *properties, + void *memory, + size_t size, + cl_int *errcode_ret) CL_EXT_SUFFIX__VERSION_1_0; /****************************************** @@ -783,7 +779,7 @@ typedef cl_bitfield cl_svm_mem_flags_arm; typedef cl_uint cl_kernel_exec_info_arm; typedef cl_bitfield cl_device_svm_capabilities_arm; -extern CL_API_ENTRY void * CL_API_CALL +extern CL_API_ENTRY void *CL_API_CALL clSVMAllocARM(cl_context context, cl_svm_mem_flags_arm flags, size_t size, @@ -791,68 +787,68 @@ clSVMAllocARM(cl_context context, extern CL_API_ENTRY void CL_API_CALL clSVMFreeARM(cl_context context, - void * svm_pointer) CL_EXT_SUFFIX__VERSION_1_2; + void *svm_pointer) CL_EXT_SUFFIX__VERSION_1_2; extern CL_API_ENTRY cl_int CL_API_CALL clEnqueueSVMFreeARM(cl_command_queue command_queue, cl_uint num_svm_pointers, - void * svm_pointers[], - void (CL_CALLBACK * pfn_free_func)(cl_command_queue queue, - cl_uint num_svm_pointers, - void * svm_pointers[], - void * user_data), - void * user_data, + void *svm_pointers[], + void (CL_CALLBACK *pfn_free_func)(cl_command_queue queue, + cl_uint num_svm_pointers, + void *svm_pointers[], + void *user_data), + void *user_data, cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event) CL_EXT_SUFFIX__VERSION_1_2; + const cl_event *event_wait_list, + cl_event *event) CL_EXT_SUFFIX__VERSION_1_2; extern CL_API_ENTRY cl_int CL_API_CALL clEnqueueSVMMemcpyARM(cl_command_queue command_queue, cl_bool blocking_copy, - void * dst_ptr, - const void * src_ptr, + void *dst_ptr, + const void *src_ptr, size_t size, cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event) CL_EXT_SUFFIX__VERSION_1_2; + const cl_event *event_wait_list, + cl_event *event) CL_EXT_SUFFIX__VERSION_1_2; extern CL_API_ENTRY cl_int CL_API_CALL clEnqueueSVMMemFillARM(cl_command_queue command_queue, - void * svm_ptr, - const void * pattern, + void *svm_ptr, + const void *pattern, size_t pattern_size, size_t size, cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event) CL_EXT_SUFFIX__VERSION_1_2; + const cl_event *event_wait_list, + cl_event *event) CL_EXT_SUFFIX__VERSION_1_2; extern CL_API_ENTRY cl_int CL_API_CALL clEnqueueSVMMapARM(cl_command_queue command_queue, cl_bool blocking_map, cl_map_flags flags, - void * svm_ptr, + void *svm_ptr, size_t size, cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event) CL_EXT_SUFFIX__VERSION_1_2; + const cl_event *event_wait_list, + cl_event *event) CL_EXT_SUFFIX__VERSION_1_2; extern CL_API_ENTRY cl_int CL_API_CALL clEnqueueSVMUnmapARM(cl_command_queue command_queue, - void * svm_ptr, + void *svm_ptr, cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event) CL_EXT_SUFFIX__VERSION_1_2; + const cl_event *event_wait_list, + cl_event *event) CL_EXT_SUFFIX__VERSION_1_2; extern CL_API_ENTRY cl_int CL_API_CALL clSetKernelArgSVMPointerARM(cl_kernel kernel, cl_uint arg_index, - const void * arg_value) CL_EXT_SUFFIX__VERSION_1_2; + const void *arg_value) CL_EXT_SUFFIX__VERSION_1_2; extern CL_API_ENTRY cl_int CL_API_CALL clSetKernelExecInfoARM(cl_kernel kernel, cl_kernel_exec_info_arm param_name, size_t param_value_size, - const void * param_value) CL_EXT_SUFFIX__VERSION_1_2; + const void *param_value) CL_EXT_SUFFIX__VERSION_1_2; /******************************** * cl_arm_get_core_id extension * diff --git a/tools/hitag2crack/common/OpenCL-Headers/CL/cl_ext_intel.h b/tools/hitag2crack/common/OpenCL-Headers/CL/cl_ext_intel.h index aab82284c..55bdc515d 100644 --- a/tools/hitag2crack/common/OpenCL-Headers/CL/cl_ext_intel.h +++ b/tools/hitag2crack/common/OpenCL-Headers/CL/cl_ext_intel.h @@ -75,7 +75,7 @@ extern "C" { #define cl_intel_motion_estimation 1 #define cl_intel_advanced_motion_estimation 1 -typedef struct _cl_accelerator_intel* cl_accelerator_intel; +typedef struct _cl_accelerator_intel *cl_accelerator_intel; typedef cl_uint cl_accelerator_type_intel; typedef cl_uint cl_accelerator_info_intel; @@ -171,43 +171,43 @@ clCreateAcceleratorINTEL( cl_context context, cl_accelerator_type_intel accelerator_type, size_t descriptor_size, - const void* descriptor, - cl_int* errcode_ret) CL_EXT_SUFFIX__VERSION_1_2; + const void *descriptor, + cl_int *errcode_ret) CL_EXT_SUFFIX__VERSION_1_2; -typedef CL_API_ENTRY cl_accelerator_intel (CL_API_CALL *clCreateAcceleratorINTEL_fn)( +typedef CL_API_ENTRY cl_accelerator_intel(CL_API_CALL *clCreateAcceleratorINTEL_fn)( cl_context context, cl_accelerator_type_intel accelerator_type, size_t descriptor_size, - const void* descriptor, - cl_int* errcode_ret) CL_EXT_SUFFIX__VERSION_1_2; + const void *descriptor, + cl_int *errcode_ret) CL_EXT_SUFFIX__VERSION_1_2; extern CL_API_ENTRY cl_int CL_API_CALL clGetAcceleratorInfoINTEL( cl_accelerator_intel accelerator, cl_accelerator_info_intel param_name, size_t param_value_size, - void* param_value, - size_t* param_value_size_ret) CL_EXT_SUFFIX__VERSION_1_2; + void *param_value, + size_t *param_value_size_ret) CL_EXT_SUFFIX__VERSION_1_2; -typedef CL_API_ENTRY cl_int (CL_API_CALL *clGetAcceleratorInfoINTEL_fn)( +typedef CL_API_ENTRY cl_int(CL_API_CALL *clGetAcceleratorInfoINTEL_fn)( cl_accelerator_intel accelerator, cl_accelerator_info_intel param_name, size_t param_value_size, - void* param_value, - size_t* param_value_size_ret) CL_EXT_SUFFIX__VERSION_1_2; + void *param_value, + size_t *param_value_size_ret) CL_EXT_SUFFIX__VERSION_1_2; extern CL_API_ENTRY cl_int CL_API_CALL clRetainAcceleratorINTEL( cl_accelerator_intel accelerator) CL_EXT_SUFFIX__VERSION_1_2; -typedef CL_API_ENTRY cl_int (CL_API_CALL *clRetainAcceleratorINTEL_fn)( +typedef CL_API_ENTRY cl_int(CL_API_CALL *clRetainAcceleratorINTEL_fn)( cl_accelerator_intel accelerator) CL_EXT_SUFFIX__VERSION_1_2; extern CL_API_ENTRY cl_int CL_API_CALL clReleaseAcceleratorINTEL( cl_accelerator_intel accelerator) CL_EXT_SUFFIX__VERSION_1_2; -typedef CL_API_ENTRY cl_int (CL_API_CALL *clReleaseAcceleratorINTEL_fn)( +typedef CL_API_ENTRY cl_int(CL_API_CALL *clReleaseAcceleratorINTEL_fn)( cl_accelerator_intel accelerator) CL_EXT_SUFFIX__VERSION_1_2; /****************************************** @@ -472,171 +472,171 @@ typedef cl_uint cl_mem_advice_intel; #define CL_COMMAND_MIGRATEMEM_INTEL 0x4206 #define CL_COMMAND_MEMADVISE_INTEL 0x4207 -extern CL_API_ENTRY void* CL_API_CALL +extern CL_API_ENTRY void *CL_API_CALL clHostMemAllocINTEL( - cl_context context, - const cl_mem_properties_intel* properties, - size_t size, - cl_uint alignment, - cl_int* errcode_ret); + cl_context context, + const cl_mem_properties_intel *properties, + size_t size, + cl_uint alignment, + cl_int *errcode_ret); -typedef CL_API_ENTRY void* (CL_API_CALL * -clHostMemAllocINTEL_fn)( - cl_context context, - const cl_mem_properties_intel* properties, - size_t size, - cl_uint alignment, - cl_int* errcode_ret); +typedef CL_API_ENTRY void *(CL_API_CALL * + clHostMemAllocINTEL_fn)( + cl_context context, + const cl_mem_properties_intel *properties, + size_t size, + cl_uint alignment, + cl_int *errcode_ret); -extern CL_API_ENTRY void* CL_API_CALL +extern CL_API_ENTRY void *CL_API_CALL clDeviceMemAllocINTEL( - cl_context context, - cl_device_id device, - const cl_mem_properties_intel* properties, - size_t size, - cl_uint alignment, - cl_int* errcode_ret); + cl_context context, + cl_device_id device, + const cl_mem_properties_intel *properties, + size_t size, + cl_uint alignment, + cl_int *errcode_ret); -typedef CL_API_ENTRY void* (CL_API_CALL * -clDeviceMemAllocINTEL_fn)( - cl_context context, - cl_device_id device, - const cl_mem_properties_intel* properties, - size_t size, - cl_uint alignment, - cl_int* errcode_ret); +typedef CL_API_ENTRY void *(CL_API_CALL * + clDeviceMemAllocINTEL_fn)( + cl_context context, + cl_device_id device, + const cl_mem_properties_intel *properties, + size_t size, + cl_uint alignment, + cl_int *errcode_ret); -extern CL_API_ENTRY void* CL_API_CALL +extern CL_API_ENTRY void *CL_API_CALL clSharedMemAllocINTEL( - cl_context context, - cl_device_id device, - const cl_mem_properties_intel* properties, - size_t size, - cl_uint alignment, - cl_int* errcode_ret); + cl_context context, + cl_device_id device, + const cl_mem_properties_intel *properties, + size_t size, + cl_uint alignment, + cl_int *errcode_ret); -typedef CL_API_ENTRY void* (CL_API_CALL * -clSharedMemAllocINTEL_fn)( - cl_context context, - cl_device_id device, - const cl_mem_properties_intel* properties, - size_t size, - cl_uint alignment, - cl_int* errcode_ret); +typedef CL_API_ENTRY void *(CL_API_CALL * + clSharedMemAllocINTEL_fn)( + cl_context context, + cl_device_id device, + const cl_mem_properties_intel *properties, + size_t size, + cl_uint alignment, + cl_int *errcode_ret); extern CL_API_ENTRY cl_int CL_API_CALL clMemFreeINTEL( - cl_context context, - void* ptr); + cl_context context, + void *ptr); -typedef CL_API_ENTRY cl_int (CL_API_CALL * -clMemFreeINTEL_fn)( - cl_context context, - void* ptr); +typedef CL_API_ENTRY cl_int(CL_API_CALL * + clMemFreeINTEL_fn)( + cl_context context, + void *ptr); extern CL_API_ENTRY cl_int CL_API_CALL clMemBlockingFreeINTEL( - cl_context context, - void* ptr); + cl_context context, + void *ptr); -typedef CL_API_ENTRY cl_int (CL_API_CALL * -clMemBlockingFreeINTEL_fn)( - cl_context context, - void* ptr); +typedef CL_API_ENTRY cl_int(CL_API_CALL * + clMemBlockingFreeINTEL_fn)( + cl_context context, + void *ptr); extern CL_API_ENTRY cl_int CL_API_CALL clGetMemAllocInfoINTEL( - cl_context context, - const void* ptr, - cl_mem_info_intel param_name, - size_t param_value_size, - void* param_value, - size_t* param_value_size_ret); + cl_context context, + const void *ptr, + cl_mem_info_intel param_name, + size_t param_value_size, + void *param_value, + size_t *param_value_size_ret); -typedef CL_API_ENTRY cl_int (CL_API_CALL * -clGetMemAllocInfoINTEL_fn)( - cl_context context, - const void* ptr, - cl_mem_info_intel param_name, - size_t param_value_size, - void* param_value, - size_t* param_value_size_ret); +typedef CL_API_ENTRY cl_int(CL_API_CALL * + clGetMemAllocInfoINTEL_fn)( + cl_context context, + const void *ptr, + cl_mem_info_intel param_name, + size_t param_value_size, + void *param_value, + size_t *param_value_size_ret); extern CL_API_ENTRY cl_int CL_API_CALL clSetKernelArgMemPointerINTEL( - cl_kernel kernel, - cl_uint arg_index, - const void* arg_value); + cl_kernel kernel, + cl_uint arg_index, + const void *arg_value); -typedef CL_API_ENTRY cl_int (CL_API_CALL * -clSetKernelArgMemPointerINTEL_fn)( - cl_kernel kernel, - cl_uint arg_index, - const void* arg_value); +typedef CL_API_ENTRY cl_int(CL_API_CALL * + clSetKernelArgMemPointerINTEL_fn)( + cl_kernel kernel, + cl_uint arg_index, + const void *arg_value); extern CL_API_ENTRY cl_int CL_API_CALL clEnqueueMemsetINTEL( /* Deprecated */ - cl_command_queue command_queue, - void* dst_ptr, - cl_int value, - size_t size, - cl_uint num_events_in_wait_list, - const cl_event* event_wait_list, - cl_event* event); + cl_command_queue command_queue, + void *dst_ptr, + cl_int value, + size_t size, + cl_uint num_events_in_wait_list, + const cl_event *event_wait_list, + cl_event *event); -typedef CL_API_ENTRY cl_int (CL_API_CALL * -clEnqueueMemsetINTEL_fn)( /* Deprecated */ - cl_command_queue command_queue, - void* dst_ptr, - cl_int value, - size_t size, - cl_uint num_events_in_wait_list, - const cl_event* event_wait_list, - cl_event* event); +typedef CL_API_ENTRY cl_int(CL_API_CALL * + clEnqueueMemsetINTEL_fn)( /* Deprecated */ + cl_command_queue command_queue, + void *dst_ptr, + cl_int value, + size_t size, + cl_uint num_events_in_wait_list, + const cl_event *event_wait_list, + cl_event *event); extern CL_API_ENTRY cl_int CL_API_CALL clEnqueueMemFillINTEL( - cl_command_queue command_queue, - void* dst_ptr, - const void* pattern, - size_t pattern_size, - size_t size, - cl_uint num_events_in_wait_list, - const cl_event* event_wait_list, - cl_event* event); + cl_command_queue command_queue, + void *dst_ptr, + const void *pattern, + size_t pattern_size, + size_t size, + cl_uint num_events_in_wait_list, + const cl_event *event_wait_list, + cl_event *event); -typedef CL_API_ENTRY cl_int (CL_API_CALL * -clEnqueueMemFillINTEL_fn)( - cl_command_queue command_queue, - void* dst_ptr, - const void* pattern, - size_t pattern_size, - size_t size, - cl_uint num_events_in_wait_list, - const cl_event* event_wait_list, - cl_event* event); +typedef CL_API_ENTRY cl_int(CL_API_CALL * + clEnqueueMemFillINTEL_fn)( + cl_command_queue command_queue, + void *dst_ptr, + const void *pattern, + size_t pattern_size, + size_t size, + cl_uint num_events_in_wait_list, + const cl_event *event_wait_list, + cl_event *event); extern CL_API_ENTRY cl_int CL_API_CALL clEnqueueMemcpyINTEL( - cl_command_queue command_queue, - cl_bool blocking, - void* dst_ptr, - const void* src_ptr, - size_t size, - cl_uint num_events_in_wait_list, - const cl_event* event_wait_list, - cl_event* event); + cl_command_queue command_queue, + cl_bool blocking, + void *dst_ptr, + const void *src_ptr, + size_t size, + cl_uint num_events_in_wait_list, + const cl_event *event_wait_list, + cl_event *event); -typedef CL_API_ENTRY cl_int (CL_API_CALL * -clEnqueueMemcpyINTEL_fn)( - cl_command_queue command_queue, - cl_bool blocking, - void* dst_ptr, - const void* src_ptr, - size_t size, - cl_uint num_events_in_wait_list, - const cl_event* event_wait_list, - cl_event* event); +typedef CL_API_ENTRY cl_int(CL_API_CALL * + clEnqueueMemcpyINTEL_fn)( + cl_command_queue command_queue, + cl_bool blocking, + void *dst_ptr, + const void *src_ptr, + size_t size, + cl_uint num_events_in_wait_list, + const cl_event *event_wait_list, + cl_event *event); #ifdef CL_VERSION_1_2 @@ -645,45 +645,45 @@ clEnqueueMemcpyINTEL_fn)( extern CL_API_ENTRY cl_int CL_API_CALL clEnqueueMigrateMemINTEL( - cl_command_queue command_queue, - const void* ptr, - size_t size, - cl_mem_migration_flags flags, - cl_uint num_events_in_wait_list, - const cl_event* event_wait_list, - cl_event* event); + cl_command_queue command_queue, + const void *ptr, + size_t size, + cl_mem_migration_flags flags, + cl_uint num_events_in_wait_list, + const cl_event *event_wait_list, + cl_event *event); -typedef CL_API_ENTRY cl_int (CL_API_CALL * -clEnqueueMigrateMemINTEL_fn)( - cl_command_queue command_queue, - const void* ptr, - size_t size, - cl_mem_migration_flags flags, - cl_uint num_events_in_wait_list, - const cl_event* event_wait_list, - cl_event* event); +typedef CL_API_ENTRY cl_int(CL_API_CALL * + clEnqueueMigrateMemINTEL_fn)( + cl_command_queue command_queue, + const void *ptr, + size_t size, + cl_mem_migration_flags flags, + cl_uint num_events_in_wait_list, + const cl_event *event_wait_list, + cl_event *event); #endif extern CL_API_ENTRY cl_int CL_API_CALL clEnqueueMemAdviseINTEL( - cl_command_queue command_queue, - const void* ptr, - size_t size, - cl_mem_advice_intel advice, - cl_uint num_events_in_wait_list, - const cl_event* event_wait_list, - cl_event* event); + cl_command_queue command_queue, + const void *ptr, + size_t size, + cl_mem_advice_intel advice, + cl_uint num_events_in_wait_list, + const cl_event *event_wait_list, + cl_event *event); -typedef CL_API_ENTRY cl_int (CL_API_CALL * -clEnqueueMemAdviseINTEL_fn)( - cl_command_queue command_queue, - const void* ptr, - size_t size, - cl_mem_advice_intel advice, - cl_uint num_events_in_wait_list, - const cl_event* event_wait_list, - cl_event* event); +typedef CL_API_ENTRY cl_int(CL_API_CALL * + clEnqueueMemAdviseINTEL_fn)( + cl_command_queue command_queue, + const void *ptr, + size_t size, + cl_mem_advice_intel advice, + cl_uint num_events_in_wait_list, + const cl_event *event_wait_list, + cl_event *event); /*************************************************** * cl_intel_create_buffer_with_properties extension * @@ -694,20 +694,20 @@ clEnqueueMemAdviseINTEL_fn)( extern CL_API_ENTRY cl_mem CL_API_CALL clCreateBufferWithPropertiesINTEL( cl_context context, - const cl_mem_properties_intel* properties, + const cl_mem_properties_intel *properties, cl_mem_flags flags, size_t size, - void * host_ptr, - cl_int * errcode_ret) CL_EXT_SUFFIX__VERSION_1_0; + void *host_ptr, + cl_int *errcode_ret) CL_EXT_SUFFIX__VERSION_1_0; -typedef CL_API_ENTRY cl_mem (CL_API_CALL * -clCreateBufferWithPropertiesINTEL_fn)( - cl_context context, - const cl_mem_properties_intel* properties, - cl_mem_flags flags, - size_t size, - void * host_ptr, - cl_int * errcode_ret) CL_EXT_SUFFIX__VERSION_1_0; +typedef CL_API_ENTRY cl_mem(CL_API_CALL * + clCreateBufferWithPropertiesINTEL_fn)( + cl_context context, + const cl_mem_properties_intel *properties, + cl_mem_flags flags, + size_t size, + void *host_ptr, + cl_int *errcode_ret) CL_EXT_SUFFIX__VERSION_1_0; /****************************************** * cl_intel_mem_channel_property extension * diff --git a/tools/hitag2crack/common/OpenCL-Headers/CL/cl_gl.h b/tools/hitag2crack/common/OpenCL-Headers/CL/cl_gl.h index b587f02a9..10ca62875 100644 --- a/tools/hitag2crack/common/OpenCL-Headers/CL/cl_gl.h +++ b/tools/hitag2crack/common/OpenCL-Headers/CL/cl_gl.h @@ -52,7 +52,7 @@ extern CL_API_ENTRY cl_mem CL_API_CALL clCreateFromGLBuffer(cl_context context, cl_mem_flags flags, cl_GLuint bufobj, - cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0; + cl_int *errcode_ret) CL_API_SUFFIX__VERSION_1_0; #ifdef CL_VERSION_1_2 @@ -62,7 +62,7 @@ clCreateFromGLTexture(cl_context context, cl_GLenum target, cl_GLint miplevel, cl_GLuint texture, - cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_2; + cl_int *errcode_ret) CL_API_SUFFIX__VERSION_1_2; #endif @@ -70,35 +70,35 @@ extern CL_API_ENTRY cl_mem CL_API_CALL clCreateFromGLRenderbuffer(cl_context context, cl_mem_flags flags, cl_GLuint renderbuffer, - cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0; + cl_int *errcode_ret) CL_API_SUFFIX__VERSION_1_0; extern CL_API_ENTRY cl_int CL_API_CALL clGetGLObjectInfo(cl_mem memobj, - cl_gl_object_type * gl_object_type, - cl_GLuint * gl_object_name) CL_API_SUFFIX__VERSION_1_0; + cl_gl_object_type *gl_object_type, + cl_GLuint *gl_object_name) CL_API_SUFFIX__VERSION_1_0; extern CL_API_ENTRY cl_int CL_API_CALL clGetGLTextureInfo(cl_mem memobj, cl_gl_texture_info param_name, size_t param_value_size, - void * param_value, - size_t * param_value_size_ret) CL_API_SUFFIX__VERSION_1_0; + void *param_value, + size_t *param_value_size_ret) CL_API_SUFFIX__VERSION_1_0; extern CL_API_ENTRY cl_int CL_API_CALL clEnqueueAcquireGLObjects(cl_command_queue command_queue, cl_uint num_objects, - const cl_mem * mem_objects, + const cl_mem *mem_objects, cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event) CL_API_SUFFIX__VERSION_1_0; + const cl_event *event_wait_list, + cl_event *event) CL_API_SUFFIX__VERSION_1_0; extern CL_API_ENTRY cl_int CL_API_CALL clEnqueueReleaseGLObjects(cl_command_queue command_queue, cl_uint num_objects, - const cl_mem * mem_objects, + const cl_mem *mem_objects, cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event) CL_API_SUFFIX__VERSION_1_0; + const cl_event *event_wait_list, + cl_event *event) CL_API_SUFFIX__VERSION_1_0; /* Deprecated OpenCL 1.1 APIs */ @@ -108,7 +108,7 @@ clCreateFromGLTexture2D(cl_context context, cl_GLenum target, cl_GLint miplevel, cl_GLuint texture, - cl_int * errcode_ret) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; + cl_int *errcode_ret) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_mem CL_API_CALL clCreateFromGLTexture3D(cl_context context, @@ -116,7 +116,7 @@ clCreateFromGLTexture3D(cl_context context, cl_GLenum target, cl_GLint miplevel, cl_GLuint texture, - cl_int * errcode_ret) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; + cl_int *errcode_ret) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; /* cl_khr_gl_sharing extension */ @@ -139,18 +139,18 @@ typedef cl_uint cl_gl_context_info; #define CL_CGL_SHAREGROUP_KHR 0x200C extern CL_API_ENTRY cl_int CL_API_CALL -clGetGLContextInfoKHR(const cl_context_properties * properties, +clGetGLContextInfoKHR(const cl_context_properties *properties, cl_gl_context_info param_name, size_t param_value_size, - void * param_value, - size_t * param_value_size_ret) CL_API_SUFFIX__VERSION_1_0; + void *param_value, + size_t *param_value_size_ret) CL_API_SUFFIX__VERSION_1_0; -typedef CL_API_ENTRY cl_int (CL_API_CALL *clGetGLContextInfoKHR_fn)( - const cl_context_properties * properties, +typedef CL_API_ENTRY cl_int(CL_API_CALL *clGetGLContextInfoKHR_fn)( + const cl_context_properties *properties, cl_gl_context_info param_name, size_t param_value_size, - void * param_value, - size_t * param_value_size_ret); + void *param_value, + size_t *param_value_size_ret); #ifdef __cplusplus } diff --git a/tools/hitag2crack/common/OpenCL-Headers/CL/cl_gl_ext.h b/tools/hitag2crack/common/OpenCL-Headers/CL/cl_gl_ext.h index 52107b111..916c5189b 100644 --- a/tools/hitag2crack/common/OpenCL-Headers/CL/cl_gl_ext.h +++ b/tools/hitag2crack/common/OpenCL-Headers/CL/cl_gl_ext.h @@ -23,7 +23,7 @@ extern "C" { #include -/* +/* * cl_khr_gl_event extension */ #define CL_COMMAND_GL_FENCE_SYNC_OBJECT_KHR 0x200D @@ -31,7 +31,7 @@ extern "C" { extern CL_API_ENTRY cl_event CL_API_CALL clCreateEventFromGLsyncKHR(cl_context context, cl_GLsync sync, - cl_int * errcode_ret) CL_EXT_SUFFIX__VERSION_1_1; + cl_int *errcode_ret) CL_EXT_SUFFIX__VERSION_1_1; #ifdef __cplusplus } diff --git a/tools/hitag2crack/common/OpenCL-Headers/CL/cl_half.h b/tools/hitag2crack/common/OpenCL-Headers/CL/cl_half.h index ecc422332..f394042a5 100644 --- a/tools/hitag2crack/common/OpenCL-Headers/CL/cl_half.h +++ b/tools/hitag2crack/common/OpenCL-Headers/CL/cl_half.h @@ -41,12 +41,11 @@ extern "C" { /** * Rounding mode used when converting to cl_half. */ -typedef enum -{ - CL_HALF_RTE, // round to nearest even - CL_HALF_RTZ, // round towards zero - CL_HALF_RTP, // round towards positive infinity - CL_HALF_RTN, // round towards negative infinity +typedef enum { + CL_HALF_RTE, // round to nearest even + CL_HALF_RTZ, // round towards zero + CL_HALF_RTP, // round towards positive infinity + CL_HALF_RTN, // round towards negative infinity } cl_half_rounding_mode; @@ -59,372 +58,317 @@ typedef enum * Utility to deal with values that overflow when converting to half precision. */ static inline cl_half cl_half_handle_overflow(cl_half_rounding_mode rounding_mode, - uint16_t sign) -{ - if (rounding_mode == CL_HALF_RTZ) - { - // Round overflow towards zero -> largest finite number (preserving sign) - return (sign << 15) | CL_HALF_MAX_FINITE_MAG; - } - else if (rounding_mode == CL_HALF_RTP && sign) - { - // Round negative overflow towards positive infinity -> most negative finite number - return (1 << 15) | CL_HALF_MAX_FINITE_MAG; - } - else if (rounding_mode == CL_HALF_RTN && !sign) - { - // Round positive overflow towards negative infinity -> largest finite number - return CL_HALF_MAX_FINITE_MAG; - } + uint16_t sign) { + if (rounding_mode == CL_HALF_RTZ) { + // Round overflow towards zero -> largest finite number (preserving sign) + return (sign << 15) | CL_HALF_MAX_FINITE_MAG; + } else if (rounding_mode == CL_HALF_RTP && sign) { + // Round negative overflow towards positive infinity -> most negative finite number + return (1 << 15) | CL_HALF_MAX_FINITE_MAG; + } else if (rounding_mode == CL_HALF_RTN && !sign) { + // Round positive overflow towards negative infinity -> largest finite number + return CL_HALF_MAX_FINITE_MAG; + } - // Overflow to infinity - return (sign << 15) | CL_HALF_EXP_MASK; + // Overflow to infinity + return (sign << 15) | CL_HALF_EXP_MASK; } /* * Utility to deal with values that underflow when converting to half precision. */ static inline cl_half cl_half_handle_underflow(cl_half_rounding_mode rounding_mode, - uint16_t sign) -{ - if (rounding_mode == CL_HALF_RTP && !sign) - { - // Round underflow towards positive infinity -> smallest positive value - return (sign << 15) | 1; - } - else if (rounding_mode == CL_HALF_RTN && sign) - { - // Round underflow towards negative infinity -> largest negative value - return (sign << 15) | 1; - } + uint16_t sign) { + if (rounding_mode == CL_HALF_RTP && !sign) { + // Round underflow towards positive infinity -> smallest positive value + return (sign << 15) | 1; + } else if (rounding_mode == CL_HALF_RTN && sign) { + // Round underflow towards negative infinity -> largest negative value + return (sign << 15) | 1; + } - // Flush to zero - return (sign << 15); + // Flush to zero + return (sign << 15); } /** * Convert a cl_float to a cl_half. */ -static inline cl_half cl_half_from_float(cl_float f, cl_half_rounding_mode rounding_mode) -{ - // Type-punning to get direct access to underlying bits - union - { - cl_float f; - uint32_t i; - } f32; - f32.f = f; +static inline cl_half cl_half_from_float(cl_float f, cl_half_rounding_mode rounding_mode) { + // Type-punning to get direct access to underlying bits + union { + cl_float f; + uint32_t i; + } f32; + f32.f = f; - // Extract sign bit - uint16_t sign = f32.i >> 31; + // Extract sign bit + uint16_t sign = f32.i >> 31; - // Extract FP32 exponent and mantissa - uint32_t f_exp = (f32.i >> (CL_FLT_MANT_DIG - 1)) & 0xFF; - uint32_t f_mant = f32.i & ((1 << (CL_FLT_MANT_DIG - 1)) - 1); + // Extract FP32 exponent and mantissa + uint32_t f_exp = (f32.i >> (CL_FLT_MANT_DIG - 1)) & 0xFF; + uint32_t f_mant = f32.i & ((1 << (CL_FLT_MANT_DIG - 1)) - 1); - // Remove FP32 exponent bias - int32_t exp = f_exp - CL_FLT_MAX_EXP + 1; + // Remove FP32 exponent bias + int32_t exp = f_exp - CL_FLT_MAX_EXP + 1; - // Add FP16 exponent bias - uint16_t h_exp = (uint16_t)(exp + CL_HALF_MAX_EXP - 1); + // Add FP16 exponent bias + uint16_t h_exp = (uint16_t)(exp + CL_HALF_MAX_EXP - 1); - // Position of the bit that will become the FP16 mantissa LSB - uint32_t lsb_pos = CL_FLT_MANT_DIG - CL_HALF_MANT_DIG; + // Position of the bit that will become the FP16 mantissa LSB + uint32_t lsb_pos = CL_FLT_MANT_DIG - CL_HALF_MANT_DIG; - // Check for NaN / infinity - if (f_exp == 0xFF) - { - if (f_mant) - { - // NaN -> propagate mantissa and silence it - uint16_t h_mant = (uint16_t)(f_mant >> lsb_pos); - h_mant |= 0x200; - return (sign << 15) | CL_HALF_EXP_MASK | h_mant; + // Check for NaN / infinity + if (f_exp == 0xFF) { + if (f_mant) { + // NaN -> propagate mantissa and silence it + uint16_t h_mant = (uint16_t)(f_mant >> lsb_pos); + h_mant |= 0x200; + return (sign << 15) | CL_HALF_EXP_MASK | h_mant; + } else { + // Infinity -> zero mantissa + return (sign << 15) | CL_HALF_EXP_MASK; + } } - else - { - // Infinity -> zero mantissa - return (sign << 15) | CL_HALF_EXP_MASK; + + // Check for zero + if (!f_exp && !f_mant) { + return (sign << 15); } - } - // Check for zero - if (!f_exp && !f_mant) - { - return (sign << 15); - } + // Check for overflow + if (exp >= CL_HALF_MAX_EXP) { + return cl_half_handle_overflow(rounding_mode, sign); + } - // Check for overflow - if (exp >= CL_HALF_MAX_EXP) - { - return cl_half_handle_overflow(rounding_mode, sign); - } + // Check for underflow + if (exp < (CL_HALF_MIN_EXP - CL_HALF_MANT_DIG - 1)) { + return cl_half_handle_underflow(rounding_mode, sign); + } - // Check for underflow - if (exp < (CL_HALF_MIN_EXP - CL_HALF_MANT_DIG - 1)) - { - return cl_half_handle_underflow(rounding_mode, sign); - } + // Check for value that will become denormal + if (exp < -14) { + // Denormal -> include the implicit 1 from the FP32 mantissa + h_exp = 0; + f_mant |= 1 << (CL_FLT_MANT_DIG - 1); - // Check for value that will become denormal - if (exp < -14) - { - // Denormal -> include the implicit 1 from the FP32 mantissa - h_exp = 0; - f_mant |= 1 << (CL_FLT_MANT_DIG - 1); + // Mantissa shift amount depends on exponent + lsb_pos = -exp + (CL_FLT_MANT_DIG - 25); + } - // Mantissa shift amount depends on exponent - lsb_pos = -exp + (CL_FLT_MANT_DIG - 25); - } + // Generate FP16 mantissa by shifting FP32 mantissa + uint16_t h_mant = (uint16_t)(f_mant >> lsb_pos); - // Generate FP16 mantissa by shifting FP32 mantissa - uint16_t h_mant = (uint16_t)(f_mant >> lsb_pos); + // Check whether we need to round + uint32_t halfway = 1 << (lsb_pos - 1); + uint32_t mask = (halfway << 1) - 1; + switch (rounding_mode) { + case CL_HALF_RTE: + if ((f_mant & mask) > halfway) { + // More than halfway -> round up + h_mant += 1; + } else if ((f_mant & mask) == halfway) { + // Exactly halfway -> round to nearest even + if (h_mant & 0x1) + h_mant += 1; + } + break; + case CL_HALF_RTZ: + // Mantissa has already been truncated -> do nothing + break; + case CL_HALF_RTP: + if ((f_mant & mask) && !sign) { + // Round positive numbers up + h_mant += 1; + } + break; + case CL_HALF_RTN: + if ((f_mant & mask) && sign) { + // Round negative numbers down + h_mant += 1; + } + break; + } - // Check whether we need to round - uint32_t halfway = 1 << (lsb_pos - 1); - uint32_t mask = (halfway << 1) - 1; - switch (rounding_mode) - { - case CL_HALF_RTE: - if ((f_mant & mask) > halfway) - { - // More than halfway -> round up - h_mant += 1; - } - else if ((f_mant & mask) == halfway) - { - // Exactly halfway -> round to nearest even - if (h_mant & 0x1) - h_mant += 1; - } - break; - case CL_HALF_RTZ: - // Mantissa has already been truncated -> do nothing - break; - case CL_HALF_RTP: - if ((f_mant & mask) && !sign) - { - // Round positive numbers up - h_mant += 1; - } - break; - case CL_HALF_RTN: - if ((f_mant & mask) && sign) - { - // Round negative numbers down - h_mant += 1; - } - break; - } + // Check for mantissa overflow + if (h_mant & 0x400) { + h_exp += 1; + h_mant = 0; + } - // Check for mantissa overflow - if (h_mant & 0x400) - { - h_exp += 1; - h_mant = 0; - } - - return (sign << 15) | (h_exp << 10) | h_mant; + return (sign << 15) | (h_exp << 10) | h_mant; } /** * Convert a cl_double to a cl_half. */ -static inline cl_half cl_half_from_double(cl_double d, cl_half_rounding_mode rounding_mode) -{ - // Type-punning to get direct access to underlying bits - union - { - cl_double d; - uint64_t i; - } f64; - f64.d = d; +static inline cl_half cl_half_from_double(cl_double d, cl_half_rounding_mode rounding_mode) { + // Type-punning to get direct access to underlying bits + union { + cl_double d; + uint64_t i; + } f64; + f64.d = d; - // Extract sign bit - uint16_t sign = f64.i >> 63; + // Extract sign bit + uint16_t sign = f64.i >> 63; - // Extract FP64 exponent and mantissa - uint64_t d_exp = (f64.i >> (CL_DBL_MANT_DIG - 1)) & 0x7FF; - uint64_t d_mant = f64.i & (((uint64_t)1 << (CL_DBL_MANT_DIG - 1)) - 1); + // Extract FP64 exponent and mantissa + uint64_t d_exp = (f64.i >> (CL_DBL_MANT_DIG - 1)) & 0x7FF; + uint64_t d_mant = f64.i & (((uint64_t)1 << (CL_DBL_MANT_DIG - 1)) - 1); - // Remove FP64 exponent bias - int64_t exp = d_exp - CL_DBL_MAX_EXP + 1; + // Remove FP64 exponent bias + int64_t exp = d_exp - CL_DBL_MAX_EXP + 1; - // Add FP16 exponent bias - uint16_t h_exp = (uint16_t)(exp + CL_HALF_MAX_EXP - 1); + // Add FP16 exponent bias + uint16_t h_exp = (uint16_t)(exp + CL_HALF_MAX_EXP - 1); - // Position of the bit that will become the FP16 mantissa LSB - uint32_t lsb_pos = CL_DBL_MANT_DIG - CL_HALF_MANT_DIG; + // Position of the bit that will become the FP16 mantissa LSB + uint32_t lsb_pos = CL_DBL_MANT_DIG - CL_HALF_MANT_DIG; - // Check for NaN / infinity - if (d_exp == 0x7FF) - { - if (d_mant) - { - // NaN -> propagate mantissa and silence it - uint16_t h_mant = (uint16_t)(d_mant >> lsb_pos); - h_mant |= 0x200; - return (sign << 15) | CL_HALF_EXP_MASK | h_mant; + // Check for NaN / infinity + if (d_exp == 0x7FF) { + if (d_mant) { + // NaN -> propagate mantissa and silence it + uint16_t h_mant = (uint16_t)(d_mant >> lsb_pos); + h_mant |= 0x200; + return (sign << 15) | CL_HALF_EXP_MASK | h_mant; + } else { + // Infinity -> zero mantissa + return (sign << 15) | CL_HALF_EXP_MASK; + } } - else - { - // Infinity -> zero mantissa - return (sign << 15) | CL_HALF_EXP_MASK; + + // Check for zero + if (!d_exp && !d_mant) { + return (sign << 15); } - } - // Check for zero - if (!d_exp && !d_mant) - { - return (sign << 15); - } + // Check for overflow + if (exp >= CL_HALF_MAX_EXP) { + return cl_half_handle_overflow(rounding_mode, sign); + } - // Check for overflow - if (exp >= CL_HALF_MAX_EXP) - { - return cl_half_handle_overflow(rounding_mode, sign); - } + // Check for underflow + if (exp < (CL_HALF_MIN_EXP - CL_HALF_MANT_DIG - 1)) { + return cl_half_handle_underflow(rounding_mode, sign); + } - // Check for underflow - if (exp < (CL_HALF_MIN_EXP - CL_HALF_MANT_DIG - 1)) - { - return cl_half_handle_underflow(rounding_mode, sign); - } + // Check for value that will become denormal + if (exp < -14) { + // Include the implicit 1 from the FP64 mantissa + h_exp = 0; + d_mant |= (uint64_t)1 << (CL_DBL_MANT_DIG - 1); - // Check for value that will become denormal - if (exp < -14) - { - // Include the implicit 1 from the FP64 mantissa - h_exp = 0; - d_mant |= (uint64_t)1 << (CL_DBL_MANT_DIG - 1); + // Mantissa shift amount depends on exponent + lsb_pos = (uint32_t)(-exp + (CL_DBL_MANT_DIG - 25)); + } - // Mantissa shift amount depends on exponent - lsb_pos = (uint32_t)(-exp + (CL_DBL_MANT_DIG - 25)); - } + // Generate FP16 mantissa by shifting FP64 mantissa + uint16_t h_mant = (uint16_t)(d_mant >> lsb_pos); - // Generate FP16 mantissa by shifting FP64 mantissa - uint16_t h_mant = (uint16_t)(d_mant >> lsb_pos); + // Check whether we need to round + uint64_t halfway = (uint64_t)1 << (lsb_pos - 1); + uint64_t mask = (halfway << 1) - 1; + switch (rounding_mode) { + case CL_HALF_RTE: + if ((d_mant & mask) > halfway) { + // More than halfway -> round up + h_mant += 1; + } else if ((d_mant & mask) == halfway) { + // Exactly halfway -> round to nearest even + if (h_mant & 0x1) + h_mant += 1; + } + break; + case CL_HALF_RTZ: + // Mantissa has already been truncated -> do nothing + break; + case CL_HALF_RTP: + if ((d_mant & mask) && !sign) { + // Round positive numbers up + h_mant += 1; + } + break; + case CL_HALF_RTN: + if ((d_mant & mask) && sign) { + // Round negative numbers down + h_mant += 1; + } + break; + } - // Check whether we need to round - uint64_t halfway = (uint64_t)1 << (lsb_pos - 1); - uint64_t mask = (halfway << 1) - 1; - switch (rounding_mode) - { - case CL_HALF_RTE: - if ((d_mant & mask) > halfway) - { - // More than halfway -> round up - h_mant += 1; - } - else if ((d_mant & mask) == halfway) - { - // Exactly halfway -> round to nearest even - if (h_mant & 0x1) - h_mant += 1; - } - break; - case CL_HALF_RTZ: - // Mantissa has already been truncated -> do nothing - break; - case CL_HALF_RTP: - if ((d_mant & mask) && !sign) - { - // Round positive numbers up - h_mant += 1; - } - break; - case CL_HALF_RTN: - if ((d_mant & mask) && sign) - { - // Round negative numbers down - h_mant += 1; - } - break; - } + // Check for mantissa overflow + if (h_mant & 0x400) { + h_exp += 1; + h_mant = 0; + } - // Check for mantissa overflow - if (h_mant & 0x400) - { - h_exp += 1; - h_mant = 0; - } - - return (sign << 15) | (h_exp << 10) | h_mant; + return (sign << 15) | (h_exp << 10) | h_mant; } /** * Convert a cl_half to a cl_float. */ -static inline cl_float cl_half_to_float(cl_half h) -{ - // Type-punning to get direct access to underlying bits - union - { - cl_float f; - uint32_t i; - } f32; +static inline cl_float cl_half_to_float(cl_half h) { + // Type-punning to get direct access to underlying bits + union { + cl_float f; + uint32_t i; + } f32; - // Extract sign bit - uint16_t sign = h >> 15; + // Extract sign bit + uint16_t sign = h >> 15; - // Extract FP16 exponent and mantissa - uint16_t h_exp = (h >> (CL_HALF_MANT_DIG - 1)) & 0x1F; - uint16_t h_mant = h & 0x3FF; + // Extract FP16 exponent and mantissa + uint16_t h_exp = (h >> (CL_HALF_MANT_DIG - 1)) & 0x1F; + uint16_t h_mant = h & 0x3FF; - // Remove FP16 exponent bias - int32_t exp = h_exp - CL_HALF_MAX_EXP + 1; + // Remove FP16 exponent bias + int32_t exp = h_exp - CL_HALF_MAX_EXP + 1; - // Add FP32 exponent bias - uint32_t f_exp = exp + CL_FLT_MAX_EXP - 1; + // Add FP32 exponent bias + uint32_t f_exp = exp + CL_FLT_MAX_EXP - 1; - // Check for NaN / infinity - if (h_exp == 0x1F) - { - if (h_mant) - { - // NaN -> propagate mantissa and silence it - uint32_t f_mant = h_mant << (CL_FLT_MANT_DIG - CL_HALF_MANT_DIG); - f_mant |= 0x400000; - f32.i = (sign << 31) | 0x7F800000 | f_mant; - return f32.f; + // Check for NaN / infinity + if (h_exp == 0x1F) { + if (h_mant) { + // NaN -> propagate mantissa and silence it + uint32_t f_mant = h_mant << (CL_FLT_MANT_DIG - CL_HALF_MANT_DIG); + f_mant |= 0x400000; + f32.i = (sign << 31) | 0x7F800000 | f_mant; + return f32.f; + } else { + // Infinity -> zero mantissa + f32.i = (sign << 31) | 0x7F800000; + return f32.f; + } } - else - { - // Infinity -> zero mantissa - f32.i = (sign << 31) | 0x7F800000; - return f32.f; - } - } - // Check for zero / denormal - if (h_exp == 0) - { - if (h_mant == 0) - { - // Zero -> zero exponent - f_exp = 0; + // Check for zero / denormal + if (h_exp == 0) { + if (h_mant == 0) { + // Zero -> zero exponent + f_exp = 0; + } else { + // Denormal -> normalize it + // - Shift mantissa to make most-significant 1 implicit + // - Adjust exponent accordingly + uint32_t shift = 0; + while ((h_mant & 0x400) == 0) { + h_mant <<= 1; + shift++; + } + h_mant &= 0x3FF; + f_exp -= shift - 1; + } } - else - { - // Denormal -> normalize it - // - Shift mantissa to make most-significant 1 implicit - // - Adjust exponent accordingly - uint32_t shift = 0; - while ((h_mant & 0x400) == 0) - { - h_mant <<= 1; - shift++; - } - h_mant &= 0x3FF; - f_exp -= shift - 1; - } - } - f32.i = (sign << 31) | (f_exp << 23) | (h_mant << 13); - return f32.f; + f32.i = (sign << 31) | (f_exp << 23) | (h_mant << 13); + return f32.f; } diff --git a/tools/hitag2crack/common/OpenCL-Headers/CL/cl_icd.h b/tools/hitag2crack/common/OpenCL-Headers/CL/cl_icd.h index 8ff8b94f9..1c9fb3b8a 100644 --- a/tools/hitag2crack/common/OpenCL-Headers/CL/cl_icd.h +++ b/tools/hitag2crack/common/OpenCL-Headers/CL/cl_icd.h @@ -163,10 +163,10 @@ typedef CL_API_ENTRY cl_mem(CL_API_CALL *cl_api_clCreateImageWithProperties)( const cl_image_format *image_format, const cl_image_desc *image_desc, void *host_ptr, cl_int *errcode_ret) CL_API_SUFFIX__VERSION_3_0; -typedef CL_API_ENTRY cl_int(CL_API_CALL* cl_api_clSetContextDestructorCallback)( +typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_clSetContextDestructorCallback)( cl_context context, - void(CL_CALLBACK* pfn_notify)(cl_context context, void* user_data), - void* user_data) CL_API_SUFFIX__VERSION_3_0; + void(CL_CALLBACK *pfn_notify)(cl_context context, void *user_data), + void *user_data) CL_API_SUFFIX__VERSION_3_0; #else @@ -428,10 +428,10 @@ typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_clGetEventInfo)( void *param_value, size_t *param_value_size_ret) CL_API_SUFFIX__VERSION_1_0; typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_clRetainEvent)(cl_event event) - CL_API_SUFFIX__VERSION_1_0; +CL_API_SUFFIX__VERSION_1_0; typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_clReleaseEvent)(cl_event event) - CL_API_SUFFIX__VERSION_1_0; +CL_API_SUFFIX__VERSION_1_0; // Profiling APIs typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_clGetEventProfilingInfo)( @@ -637,8 +637,8 @@ typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_clEnqueueBarrierWithWaitList)( typedef CL_API_ENTRY void *( CL_API_CALL *cl_api_clGetExtensionFunctionAddressForPlatform)( - cl_platform_id platform, - const char *function_name)CL_API_SUFFIX__VERSION_1_2; + cl_platform_id platform, + const char *function_name)CL_API_SUFFIX__VERSION_1_2; #else @@ -704,7 +704,7 @@ typedef void *cl_api_clEnqueueSVMUnmap; typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_clSetCommandQueueProperty)( cl_command_queue command_queue, cl_command_queue_properties properties, cl_bool enable, cl_command_queue_properties *old_properties) - CL_EXT_SUFFIX__VERSION_1_0_DEPRECATED; +CL_EXT_SUFFIX__VERSION_1_0_DEPRECATED; typedef CL_API_ENTRY cl_mem(CL_API_CALL *cl_api_clCreateImage2D)( cl_context context, cl_mem_flags flags, const cl_image_format *image_format, @@ -718,7 +718,7 @@ typedef CL_API_ENTRY cl_mem(CL_API_CALL *cl_api_clCreateImage3D)( cl_int *errcode_ret) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_clUnloadCompiler)(void) - CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; +CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; typedef CL_API_ENTRY cl_int(CL_API_CALL *cl_api_clEnqueueMarker)( cl_command_queue command_queue, @@ -1102,188 +1102,188 @@ typedef void *cl_api_clGetHostTimer; /* Vendor dispatch table struture */ typedef struct _cl_icd_dispatch { - /* OpenCL 1.0 */ - cl_api_clGetPlatformIDs clGetPlatformIDs; - cl_api_clGetPlatformInfo clGetPlatformInfo; - cl_api_clGetDeviceIDs clGetDeviceIDs; - cl_api_clGetDeviceInfo clGetDeviceInfo; - cl_api_clCreateContext clCreateContext; - cl_api_clCreateContextFromType clCreateContextFromType; - cl_api_clRetainContext clRetainContext; - cl_api_clReleaseContext clReleaseContext; - cl_api_clGetContextInfo clGetContextInfo; - cl_api_clCreateCommandQueue clCreateCommandQueue; - cl_api_clRetainCommandQueue clRetainCommandQueue; - cl_api_clReleaseCommandQueue clReleaseCommandQueue; - cl_api_clGetCommandQueueInfo clGetCommandQueueInfo; - cl_api_clSetCommandQueueProperty clSetCommandQueueProperty; - cl_api_clCreateBuffer clCreateBuffer; - cl_api_clCreateImage2D clCreateImage2D; - cl_api_clCreateImage3D clCreateImage3D; - cl_api_clRetainMemObject clRetainMemObject; - cl_api_clReleaseMemObject clReleaseMemObject; - cl_api_clGetSupportedImageFormats clGetSupportedImageFormats; - cl_api_clGetMemObjectInfo clGetMemObjectInfo; - cl_api_clGetImageInfo clGetImageInfo; - cl_api_clCreateSampler clCreateSampler; - cl_api_clRetainSampler clRetainSampler; - cl_api_clReleaseSampler clReleaseSampler; - cl_api_clGetSamplerInfo clGetSamplerInfo; - cl_api_clCreateProgramWithSource clCreateProgramWithSource; - cl_api_clCreateProgramWithBinary clCreateProgramWithBinary; - cl_api_clRetainProgram clRetainProgram; - cl_api_clReleaseProgram clReleaseProgram; - cl_api_clBuildProgram clBuildProgram; - cl_api_clUnloadCompiler clUnloadCompiler; - cl_api_clGetProgramInfo clGetProgramInfo; - cl_api_clGetProgramBuildInfo clGetProgramBuildInfo; - cl_api_clCreateKernel clCreateKernel; - cl_api_clCreateKernelsInProgram clCreateKernelsInProgram; - cl_api_clRetainKernel clRetainKernel; - cl_api_clReleaseKernel clReleaseKernel; - cl_api_clSetKernelArg clSetKernelArg; - cl_api_clGetKernelInfo clGetKernelInfo; - cl_api_clGetKernelWorkGroupInfo clGetKernelWorkGroupInfo; - cl_api_clWaitForEvents clWaitForEvents; - cl_api_clGetEventInfo clGetEventInfo; - cl_api_clRetainEvent clRetainEvent; - cl_api_clReleaseEvent clReleaseEvent; - cl_api_clGetEventProfilingInfo clGetEventProfilingInfo; - cl_api_clFlush clFlush; - cl_api_clFinish clFinish; - cl_api_clEnqueueReadBuffer clEnqueueReadBuffer; - cl_api_clEnqueueWriteBuffer clEnqueueWriteBuffer; - cl_api_clEnqueueCopyBuffer clEnqueueCopyBuffer; - cl_api_clEnqueueReadImage clEnqueueReadImage; - cl_api_clEnqueueWriteImage clEnqueueWriteImage; - cl_api_clEnqueueCopyImage clEnqueueCopyImage; - cl_api_clEnqueueCopyImageToBuffer clEnqueueCopyImageToBuffer; - cl_api_clEnqueueCopyBufferToImage clEnqueueCopyBufferToImage; - cl_api_clEnqueueMapBuffer clEnqueueMapBuffer; - cl_api_clEnqueueMapImage clEnqueueMapImage; - cl_api_clEnqueueUnmapMemObject clEnqueueUnmapMemObject; - cl_api_clEnqueueNDRangeKernel clEnqueueNDRangeKernel; - cl_api_clEnqueueTask clEnqueueTask; - cl_api_clEnqueueNativeKernel clEnqueueNativeKernel; - cl_api_clEnqueueMarker clEnqueueMarker; - cl_api_clEnqueueWaitForEvents clEnqueueWaitForEvents; - cl_api_clEnqueueBarrier clEnqueueBarrier; - cl_api_clGetExtensionFunctionAddress clGetExtensionFunctionAddress; - cl_api_clCreateFromGLBuffer clCreateFromGLBuffer; - cl_api_clCreateFromGLTexture2D clCreateFromGLTexture2D; - cl_api_clCreateFromGLTexture3D clCreateFromGLTexture3D; - cl_api_clCreateFromGLRenderbuffer clCreateFromGLRenderbuffer; - cl_api_clGetGLObjectInfo clGetGLObjectInfo; - cl_api_clGetGLTextureInfo clGetGLTextureInfo; - cl_api_clEnqueueAcquireGLObjects clEnqueueAcquireGLObjects; - cl_api_clEnqueueReleaseGLObjects clEnqueueReleaseGLObjects; - cl_api_clGetGLContextInfoKHR clGetGLContextInfoKHR; + /* OpenCL 1.0 */ + cl_api_clGetPlatformIDs clGetPlatformIDs; + cl_api_clGetPlatformInfo clGetPlatformInfo; + cl_api_clGetDeviceIDs clGetDeviceIDs; + cl_api_clGetDeviceInfo clGetDeviceInfo; + cl_api_clCreateContext clCreateContext; + cl_api_clCreateContextFromType clCreateContextFromType; + cl_api_clRetainContext clRetainContext; + cl_api_clReleaseContext clReleaseContext; + cl_api_clGetContextInfo clGetContextInfo; + cl_api_clCreateCommandQueue clCreateCommandQueue; + cl_api_clRetainCommandQueue clRetainCommandQueue; + cl_api_clReleaseCommandQueue clReleaseCommandQueue; + cl_api_clGetCommandQueueInfo clGetCommandQueueInfo; + cl_api_clSetCommandQueueProperty clSetCommandQueueProperty; + cl_api_clCreateBuffer clCreateBuffer; + cl_api_clCreateImage2D clCreateImage2D; + cl_api_clCreateImage3D clCreateImage3D; + cl_api_clRetainMemObject clRetainMemObject; + cl_api_clReleaseMemObject clReleaseMemObject; + cl_api_clGetSupportedImageFormats clGetSupportedImageFormats; + cl_api_clGetMemObjectInfo clGetMemObjectInfo; + cl_api_clGetImageInfo clGetImageInfo; + cl_api_clCreateSampler clCreateSampler; + cl_api_clRetainSampler clRetainSampler; + cl_api_clReleaseSampler clReleaseSampler; + cl_api_clGetSamplerInfo clGetSamplerInfo; + cl_api_clCreateProgramWithSource clCreateProgramWithSource; + cl_api_clCreateProgramWithBinary clCreateProgramWithBinary; + cl_api_clRetainProgram clRetainProgram; + cl_api_clReleaseProgram clReleaseProgram; + cl_api_clBuildProgram clBuildProgram; + cl_api_clUnloadCompiler clUnloadCompiler; + cl_api_clGetProgramInfo clGetProgramInfo; + cl_api_clGetProgramBuildInfo clGetProgramBuildInfo; + cl_api_clCreateKernel clCreateKernel; + cl_api_clCreateKernelsInProgram clCreateKernelsInProgram; + cl_api_clRetainKernel clRetainKernel; + cl_api_clReleaseKernel clReleaseKernel; + cl_api_clSetKernelArg clSetKernelArg; + cl_api_clGetKernelInfo clGetKernelInfo; + cl_api_clGetKernelWorkGroupInfo clGetKernelWorkGroupInfo; + cl_api_clWaitForEvents clWaitForEvents; + cl_api_clGetEventInfo clGetEventInfo; + cl_api_clRetainEvent clRetainEvent; + cl_api_clReleaseEvent clReleaseEvent; + cl_api_clGetEventProfilingInfo clGetEventProfilingInfo; + cl_api_clFlush clFlush; + cl_api_clFinish clFinish; + cl_api_clEnqueueReadBuffer clEnqueueReadBuffer; + cl_api_clEnqueueWriteBuffer clEnqueueWriteBuffer; + cl_api_clEnqueueCopyBuffer clEnqueueCopyBuffer; + cl_api_clEnqueueReadImage clEnqueueReadImage; + cl_api_clEnqueueWriteImage clEnqueueWriteImage; + cl_api_clEnqueueCopyImage clEnqueueCopyImage; + cl_api_clEnqueueCopyImageToBuffer clEnqueueCopyImageToBuffer; + cl_api_clEnqueueCopyBufferToImage clEnqueueCopyBufferToImage; + cl_api_clEnqueueMapBuffer clEnqueueMapBuffer; + cl_api_clEnqueueMapImage clEnqueueMapImage; + cl_api_clEnqueueUnmapMemObject clEnqueueUnmapMemObject; + cl_api_clEnqueueNDRangeKernel clEnqueueNDRangeKernel; + cl_api_clEnqueueTask clEnqueueTask; + cl_api_clEnqueueNativeKernel clEnqueueNativeKernel; + cl_api_clEnqueueMarker clEnqueueMarker; + cl_api_clEnqueueWaitForEvents clEnqueueWaitForEvents; + cl_api_clEnqueueBarrier clEnqueueBarrier; + cl_api_clGetExtensionFunctionAddress clGetExtensionFunctionAddress; + cl_api_clCreateFromGLBuffer clCreateFromGLBuffer; + cl_api_clCreateFromGLTexture2D clCreateFromGLTexture2D; + cl_api_clCreateFromGLTexture3D clCreateFromGLTexture3D; + cl_api_clCreateFromGLRenderbuffer clCreateFromGLRenderbuffer; + cl_api_clGetGLObjectInfo clGetGLObjectInfo; + cl_api_clGetGLTextureInfo clGetGLTextureInfo; + cl_api_clEnqueueAcquireGLObjects clEnqueueAcquireGLObjects; + cl_api_clEnqueueReleaseGLObjects clEnqueueReleaseGLObjects; + cl_api_clGetGLContextInfoKHR clGetGLContextInfoKHR; - /* cl_khr_d3d10_sharing */ - cl_api_clGetDeviceIDsFromD3D10KHR clGetDeviceIDsFromD3D10KHR; - cl_api_clCreateFromD3D10BufferKHR clCreateFromD3D10BufferKHR; - cl_api_clCreateFromD3D10Texture2DKHR clCreateFromD3D10Texture2DKHR; - cl_api_clCreateFromD3D10Texture3DKHR clCreateFromD3D10Texture3DKHR; - cl_api_clEnqueueAcquireD3D10ObjectsKHR clEnqueueAcquireD3D10ObjectsKHR; - cl_api_clEnqueueReleaseD3D10ObjectsKHR clEnqueueReleaseD3D10ObjectsKHR; + /* cl_khr_d3d10_sharing */ + cl_api_clGetDeviceIDsFromD3D10KHR clGetDeviceIDsFromD3D10KHR; + cl_api_clCreateFromD3D10BufferKHR clCreateFromD3D10BufferKHR; + cl_api_clCreateFromD3D10Texture2DKHR clCreateFromD3D10Texture2DKHR; + cl_api_clCreateFromD3D10Texture3DKHR clCreateFromD3D10Texture3DKHR; + cl_api_clEnqueueAcquireD3D10ObjectsKHR clEnqueueAcquireD3D10ObjectsKHR; + cl_api_clEnqueueReleaseD3D10ObjectsKHR clEnqueueReleaseD3D10ObjectsKHR; - /* OpenCL 1.1 */ - cl_api_clSetEventCallback clSetEventCallback; - cl_api_clCreateSubBuffer clCreateSubBuffer; - cl_api_clSetMemObjectDestructorCallback clSetMemObjectDestructorCallback; - cl_api_clCreateUserEvent clCreateUserEvent; - cl_api_clSetUserEventStatus clSetUserEventStatus; - cl_api_clEnqueueReadBufferRect clEnqueueReadBufferRect; - cl_api_clEnqueueWriteBufferRect clEnqueueWriteBufferRect; - cl_api_clEnqueueCopyBufferRect clEnqueueCopyBufferRect; + /* OpenCL 1.1 */ + cl_api_clSetEventCallback clSetEventCallback; + cl_api_clCreateSubBuffer clCreateSubBuffer; + cl_api_clSetMemObjectDestructorCallback clSetMemObjectDestructorCallback; + cl_api_clCreateUserEvent clCreateUserEvent; + cl_api_clSetUserEventStatus clSetUserEventStatus; + cl_api_clEnqueueReadBufferRect clEnqueueReadBufferRect; + cl_api_clEnqueueWriteBufferRect clEnqueueWriteBufferRect; + cl_api_clEnqueueCopyBufferRect clEnqueueCopyBufferRect; - /* cl_ext_device_fission */ - cl_api_clCreateSubDevicesEXT clCreateSubDevicesEXT; - cl_api_clRetainDeviceEXT clRetainDeviceEXT; - cl_api_clReleaseDeviceEXT clReleaseDeviceEXT; + /* cl_ext_device_fission */ + cl_api_clCreateSubDevicesEXT clCreateSubDevicesEXT; + cl_api_clRetainDeviceEXT clRetainDeviceEXT; + cl_api_clReleaseDeviceEXT clReleaseDeviceEXT; - /* cl_khr_gl_event */ - cl_api_clCreateEventFromGLsyncKHR clCreateEventFromGLsyncKHR; + /* cl_khr_gl_event */ + cl_api_clCreateEventFromGLsyncKHR clCreateEventFromGLsyncKHR; - /* OpenCL 1.2 */ - cl_api_clCreateSubDevices clCreateSubDevices; - cl_api_clRetainDevice clRetainDevice; - cl_api_clReleaseDevice clReleaseDevice; - cl_api_clCreateImage clCreateImage; - cl_api_clCreateProgramWithBuiltInKernels clCreateProgramWithBuiltInKernels; - cl_api_clCompileProgram clCompileProgram; - cl_api_clLinkProgram clLinkProgram; - cl_api_clUnloadPlatformCompiler clUnloadPlatformCompiler; - cl_api_clGetKernelArgInfo clGetKernelArgInfo; - cl_api_clEnqueueFillBuffer clEnqueueFillBuffer; - cl_api_clEnqueueFillImage clEnqueueFillImage; - cl_api_clEnqueueMigrateMemObjects clEnqueueMigrateMemObjects; - cl_api_clEnqueueMarkerWithWaitList clEnqueueMarkerWithWaitList; - cl_api_clEnqueueBarrierWithWaitList clEnqueueBarrierWithWaitList; - cl_api_clGetExtensionFunctionAddressForPlatform - clGetExtensionFunctionAddressForPlatform; - cl_api_clCreateFromGLTexture clCreateFromGLTexture; + /* OpenCL 1.2 */ + cl_api_clCreateSubDevices clCreateSubDevices; + cl_api_clRetainDevice clRetainDevice; + cl_api_clReleaseDevice clReleaseDevice; + cl_api_clCreateImage clCreateImage; + cl_api_clCreateProgramWithBuiltInKernels clCreateProgramWithBuiltInKernels; + cl_api_clCompileProgram clCompileProgram; + cl_api_clLinkProgram clLinkProgram; + cl_api_clUnloadPlatformCompiler clUnloadPlatformCompiler; + cl_api_clGetKernelArgInfo clGetKernelArgInfo; + cl_api_clEnqueueFillBuffer clEnqueueFillBuffer; + cl_api_clEnqueueFillImage clEnqueueFillImage; + cl_api_clEnqueueMigrateMemObjects clEnqueueMigrateMemObjects; + cl_api_clEnqueueMarkerWithWaitList clEnqueueMarkerWithWaitList; + cl_api_clEnqueueBarrierWithWaitList clEnqueueBarrierWithWaitList; + cl_api_clGetExtensionFunctionAddressForPlatform + clGetExtensionFunctionAddressForPlatform; + cl_api_clCreateFromGLTexture clCreateFromGLTexture; - /* cl_khr_d3d11_sharing */ - cl_api_clGetDeviceIDsFromD3D11KHR clGetDeviceIDsFromD3D11KHR; - cl_api_clCreateFromD3D11BufferKHR clCreateFromD3D11BufferKHR; - cl_api_clCreateFromD3D11Texture2DKHR clCreateFromD3D11Texture2DKHR; - cl_api_clCreateFromD3D11Texture3DKHR clCreateFromD3D11Texture3DKHR; - cl_api_clCreateFromDX9MediaSurfaceKHR clCreateFromDX9MediaSurfaceKHR; - cl_api_clEnqueueAcquireD3D11ObjectsKHR clEnqueueAcquireD3D11ObjectsKHR; - cl_api_clEnqueueReleaseD3D11ObjectsKHR clEnqueueReleaseD3D11ObjectsKHR; + /* cl_khr_d3d11_sharing */ + cl_api_clGetDeviceIDsFromD3D11KHR clGetDeviceIDsFromD3D11KHR; + cl_api_clCreateFromD3D11BufferKHR clCreateFromD3D11BufferKHR; + cl_api_clCreateFromD3D11Texture2DKHR clCreateFromD3D11Texture2DKHR; + cl_api_clCreateFromD3D11Texture3DKHR clCreateFromD3D11Texture3DKHR; + cl_api_clCreateFromDX9MediaSurfaceKHR clCreateFromDX9MediaSurfaceKHR; + cl_api_clEnqueueAcquireD3D11ObjectsKHR clEnqueueAcquireD3D11ObjectsKHR; + cl_api_clEnqueueReleaseD3D11ObjectsKHR clEnqueueReleaseD3D11ObjectsKHR; - /* cl_khr_dx9_media_sharing */ - cl_api_clGetDeviceIDsFromDX9MediaAdapterKHR - clGetDeviceIDsFromDX9MediaAdapterKHR; - cl_api_clEnqueueAcquireDX9MediaSurfacesKHR - clEnqueueAcquireDX9MediaSurfacesKHR; - cl_api_clEnqueueReleaseDX9MediaSurfacesKHR - clEnqueueReleaseDX9MediaSurfacesKHR; + /* cl_khr_dx9_media_sharing */ + cl_api_clGetDeviceIDsFromDX9MediaAdapterKHR + clGetDeviceIDsFromDX9MediaAdapterKHR; + cl_api_clEnqueueAcquireDX9MediaSurfacesKHR + clEnqueueAcquireDX9MediaSurfacesKHR; + cl_api_clEnqueueReleaseDX9MediaSurfacesKHR + clEnqueueReleaseDX9MediaSurfacesKHR; - /* cl_khr_egl_image */ - cl_api_clCreateFromEGLImageKHR clCreateFromEGLImageKHR; - cl_api_clEnqueueAcquireEGLObjectsKHR clEnqueueAcquireEGLObjectsKHR; - cl_api_clEnqueueReleaseEGLObjectsKHR clEnqueueReleaseEGLObjectsKHR; + /* cl_khr_egl_image */ + cl_api_clCreateFromEGLImageKHR clCreateFromEGLImageKHR; + cl_api_clEnqueueAcquireEGLObjectsKHR clEnqueueAcquireEGLObjectsKHR; + cl_api_clEnqueueReleaseEGLObjectsKHR clEnqueueReleaseEGLObjectsKHR; - /* cl_khr_egl_event */ - cl_api_clCreateEventFromEGLSyncKHR clCreateEventFromEGLSyncKHR; + /* cl_khr_egl_event */ + cl_api_clCreateEventFromEGLSyncKHR clCreateEventFromEGLSyncKHR; - /* OpenCL 2.0 */ - cl_api_clCreateCommandQueueWithProperties clCreateCommandQueueWithProperties; - cl_api_clCreatePipe clCreatePipe; - cl_api_clGetPipeInfo clGetPipeInfo; - cl_api_clSVMAlloc clSVMAlloc; - cl_api_clSVMFree clSVMFree; - cl_api_clEnqueueSVMFree clEnqueueSVMFree; - cl_api_clEnqueueSVMMemcpy clEnqueueSVMMemcpy; - cl_api_clEnqueueSVMMemFill clEnqueueSVMMemFill; - cl_api_clEnqueueSVMMap clEnqueueSVMMap; - cl_api_clEnqueueSVMUnmap clEnqueueSVMUnmap; - cl_api_clCreateSamplerWithProperties clCreateSamplerWithProperties; - cl_api_clSetKernelArgSVMPointer clSetKernelArgSVMPointer; - cl_api_clSetKernelExecInfo clSetKernelExecInfo; + /* OpenCL 2.0 */ + cl_api_clCreateCommandQueueWithProperties clCreateCommandQueueWithProperties; + cl_api_clCreatePipe clCreatePipe; + cl_api_clGetPipeInfo clGetPipeInfo; + cl_api_clSVMAlloc clSVMAlloc; + cl_api_clSVMFree clSVMFree; + cl_api_clEnqueueSVMFree clEnqueueSVMFree; + cl_api_clEnqueueSVMMemcpy clEnqueueSVMMemcpy; + cl_api_clEnqueueSVMMemFill clEnqueueSVMMemFill; + cl_api_clEnqueueSVMMap clEnqueueSVMMap; + cl_api_clEnqueueSVMUnmap clEnqueueSVMUnmap; + cl_api_clCreateSamplerWithProperties clCreateSamplerWithProperties; + cl_api_clSetKernelArgSVMPointer clSetKernelArgSVMPointer; + cl_api_clSetKernelExecInfo clSetKernelExecInfo; - /* cl_khr_sub_groups */ - cl_api_clGetKernelSubGroupInfoKHR clGetKernelSubGroupInfoKHR; + /* cl_khr_sub_groups */ + cl_api_clGetKernelSubGroupInfoKHR clGetKernelSubGroupInfoKHR; - /* OpenCL 2.1 */ - cl_api_clCloneKernel clCloneKernel; - cl_api_clCreateProgramWithIL clCreateProgramWithIL; - cl_api_clEnqueueSVMMigrateMem clEnqueueSVMMigrateMem; - cl_api_clGetDeviceAndHostTimer clGetDeviceAndHostTimer; - cl_api_clGetHostTimer clGetHostTimer; - cl_api_clGetKernelSubGroupInfo clGetKernelSubGroupInfo; - cl_api_clSetDefaultDeviceCommandQueue clSetDefaultDeviceCommandQueue; + /* OpenCL 2.1 */ + cl_api_clCloneKernel clCloneKernel; + cl_api_clCreateProgramWithIL clCreateProgramWithIL; + cl_api_clEnqueueSVMMigrateMem clEnqueueSVMMigrateMem; + cl_api_clGetDeviceAndHostTimer clGetDeviceAndHostTimer; + cl_api_clGetHostTimer clGetHostTimer; + cl_api_clGetKernelSubGroupInfo clGetKernelSubGroupInfo; + cl_api_clSetDefaultDeviceCommandQueue clSetDefaultDeviceCommandQueue; - /* OpenCL 2.2 */ - cl_api_clSetProgramReleaseCallback clSetProgramReleaseCallback; - cl_api_clSetProgramSpecializationConstant clSetProgramSpecializationConstant; + /* OpenCL 2.2 */ + cl_api_clSetProgramReleaseCallback clSetProgramReleaseCallback; + cl_api_clSetProgramSpecializationConstant clSetProgramSpecializationConstant; - /* OpenCL 3.0 */ - cl_api_clCreateBufferWithProperties clCreateBufferWithProperties; - cl_api_clCreateImageWithProperties clCreateImageWithProperties; - cl_api_clSetContextDestructorCallback clSetContextDestructorCallback; + /* OpenCL 3.0 */ + cl_api_clCreateBufferWithProperties clCreateBufferWithProperties; + cl_api_clCreateImageWithProperties clCreateImageWithProperties; + cl_api_clSetContextDestructorCallback clSetContextDestructorCallback; } cl_icd_dispatch; diff --git a/tools/hitag2crack/common/OpenCL-Headers/CL/cl_platform.h b/tools/hitag2crack/common/OpenCL-Headers/CL/cl_platform.h index 2d69cc4e5..884e49e3e 100644 --- a/tools/hitag2crack/common/OpenCL-Headers/CL/cl_platform.h +++ b/tools/hitag2crack/common/OpenCL-Headers/CL/cl_platform.h @@ -24,13 +24,13 @@ extern "C" { #endif #if defined(_WIN32) - #define CL_API_ENTRY - #define CL_API_CALL __stdcall - #define CL_CALLBACK __stdcall +#define CL_API_ENTRY +#define CL_API_CALL __stdcall +#define CL_CALLBACK __stdcall #else - #define CL_API_ENTRY - #define CL_API_CALL - #define CL_CALLBACK +#define CL_API_ENTRY +#define CL_API_CALL +#define CL_CALLBACK #endif /* @@ -61,62 +61,62 @@ extern "C" { #ifdef __GNUC__ - #define CL_EXT_SUFFIX_DEPRECATED __attribute__((deprecated)) - #define CL_EXT_PREFIX_DEPRECATED +#define CL_EXT_SUFFIX_DEPRECATED __attribute__((deprecated)) +#define CL_EXT_PREFIX_DEPRECATED #elif defined(_WIN32) - #define CL_EXT_SUFFIX_DEPRECATED - #define CL_EXT_PREFIX_DEPRECATED __declspec(deprecated) +#define CL_EXT_SUFFIX_DEPRECATED +#define CL_EXT_PREFIX_DEPRECATED __declspec(deprecated) #else - #define CL_EXT_SUFFIX_DEPRECATED - #define CL_EXT_PREFIX_DEPRECATED +#define CL_EXT_SUFFIX_DEPRECATED +#define CL_EXT_PREFIX_DEPRECATED #endif #ifdef CL_USE_DEPRECATED_OPENCL_1_0_APIS - #define CL_EXT_SUFFIX__VERSION_1_0_DEPRECATED - #define CL_EXT_PREFIX__VERSION_1_0_DEPRECATED +#define CL_EXT_SUFFIX__VERSION_1_0_DEPRECATED +#define CL_EXT_PREFIX__VERSION_1_0_DEPRECATED #else - #define CL_EXT_SUFFIX__VERSION_1_0_DEPRECATED CL_EXT_SUFFIX_DEPRECATED - #define CL_EXT_PREFIX__VERSION_1_0_DEPRECATED CL_EXT_PREFIX_DEPRECATED +#define CL_EXT_SUFFIX__VERSION_1_0_DEPRECATED CL_EXT_SUFFIX_DEPRECATED +#define CL_EXT_PREFIX__VERSION_1_0_DEPRECATED CL_EXT_PREFIX_DEPRECATED #endif #ifdef CL_USE_DEPRECATED_OPENCL_1_1_APIS - #define CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED - #define CL_EXT_PREFIX__VERSION_1_1_DEPRECATED +#define CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED +#define CL_EXT_PREFIX__VERSION_1_1_DEPRECATED #else - #define CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED CL_EXT_SUFFIX_DEPRECATED - #define CL_EXT_PREFIX__VERSION_1_1_DEPRECATED CL_EXT_PREFIX_DEPRECATED +#define CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED CL_EXT_SUFFIX_DEPRECATED +#define CL_EXT_PREFIX__VERSION_1_1_DEPRECATED CL_EXT_PREFIX_DEPRECATED #endif #ifdef CL_USE_DEPRECATED_OPENCL_1_2_APIS - #define CL_EXT_SUFFIX__VERSION_1_2_DEPRECATED - #define CL_EXT_PREFIX__VERSION_1_2_DEPRECATED +#define CL_EXT_SUFFIX__VERSION_1_2_DEPRECATED +#define CL_EXT_PREFIX__VERSION_1_2_DEPRECATED #else - #define CL_EXT_SUFFIX__VERSION_1_2_DEPRECATED CL_EXT_SUFFIX_DEPRECATED - #define CL_EXT_PREFIX__VERSION_1_2_DEPRECATED CL_EXT_PREFIX_DEPRECATED - #endif +#define CL_EXT_SUFFIX__VERSION_1_2_DEPRECATED CL_EXT_SUFFIX_DEPRECATED +#define CL_EXT_PREFIX__VERSION_1_2_DEPRECATED CL_EXT_PREFIX_DEPRECATED +#endif #ifdef CL_USE_DEPRECATED_OPENCL_2_0_APIS - #define CL_EXT_SUFFIX__VERSION_2_0_DEPRECATED - #define CL_EXT_PREFIX__VERSION_2_0_DEPRECATED +#define CL_EXT_SUFFIX__VERSION_2_0_DEPRECATED +#define CL_EXT_PREFIX__VERSION_2_0_DEPRECATED #else - #define CL_EXT_SUFFIX__VERSION_2_0_DEPRECATED CL_EXT_SUFFIX_DEPRECATED - #define CL_EXT_PREFIX__VERSION_2_0_DEPRECATED CL_EXT_PREFIX_DEPRECATED +#define CL_EXT_SUFFIX__VERSION_2_0_DEPRECATED CL_EXT_SUFFIX_DEPRECATED +#define CL_EXT_PREFIX__VERSION_2_0_DEPRECATED CL_EXT_PREFIX_DEPRECATED #endif #ifdef CL_USE_DEPRECATED_OPENCL_2_1_APIS - #define CL_EXT_SUFFIX__VERSION_2_1_DEPRECATED - #define CL_EXT_PREFIX__VERSION_2_1_DEPRECATED +#define CL_EXT_SUFFIX__VERSION_2_1_DEPRECATED +#define CL_EXT_PREFIX__VERSION_2_1_DEPRECATED #else - #define CL_EXT_SUFFIX__VERSION_2_1_DEPRECATED CL_EXT_SUFFIX_DEPRECATED - #define CL_EXT_PREFIX__VERSION_2_1_DEPRECATED CL_EXT_PREFIX_DEPRECATED +#define CL_EXT_SUFFIX__VERSION_2_1_DEPRECATED CL_EXT_SUFFIX_DEPRECATED +#define CL_EXT_PREFIX__VERSION_2_1_DEPRECATED CL_EXT_PREFIX_DEPRECATED #endif #ifdef CL_USE_DEPRECATED_OPENCL_2_2_APIS - #define CL_EXT_SUFFIX__VERSION_2_2_DEPRECATED - #define CL_EXT_PREFIX__VERSION_2_2_DEPRECATED +#define CL_EXT_SUFFIX__VERSION_2_2_DEPRECATED +#define CL_EXT_PREFIX__VERSION_2_2_DEPRECATED #else - #define CL_EXT_SUFFIX__VERSION_2_2_DEPRECATED CL_EXT_SUFFIX_DEPRECATED - #define CL_EXT_PREFIX__VERSION_2_2_DEPRECATED CL_EXT_PREFIX_DEPRECATED +#define CL_EXT_SUFFIX__VERSION_2_2_DEPRECATED CL_EXT_SUFFIX_DEPRECATED +#define CL_EXT_PREFIX__VERSION_2_2_DEPRECATED CL_EXT_PREFIX_DEPRECATED #endif #if (defined (_WIN32) && defined(_MSC_VER)) @@ -316,14 +316,14 @@ typedef double cl_double; #define CL_M_SQRT1_2_F 0.707106781f #if defined( __GNUC__ ) - #define CL_HUGE_VALF __builtin_huge_valf() - #define CL_HUGE_VAL __builtin_huge_val() - #define CL_NAN __builtin_nanf( "" ) +#define CL_HUGE_VALF __builtin_huge_valf() +#define CL_HUGE_VAL __builtin_huge_val() +#define CL_NAN __builtin_nanf( "" ) #else - #define CL_HUGE_VALF ((cl_float) 1e50) - #define CL_HUGE_VAL ((cl_double) 1e500) - float nanf( const char * ); - #define CL_NAN nanf( "" ) +#define CL_HUGE_VALF ((cl_float) 1e50) +#define CL_HUGE_VAL ((cl_double) 1e500) +float nanf(const char *); +#define CL_NAN nanf( "" ) #endif #define CL_MAXFLOAT CL_FLT_MAX #define CL_INFINITY CL_HUGE_VALF @@ -355,126 +355,126 @@ typedef unsigned int cl_GLenum; /* Define basic vector types */ #if defined( __VEC__ ) - #if !defined(__clang__) - #include /* may be omitted depending on compiler. AltiVec spec provides no way to detect whether the header is required. */ - #endif - typedef __vector unsigned char __cl_uchar16; - typedef __vector signed char __cl_char16; - typedef __vector unsigned short __cl_ushort8; - typedef __vector signed short __cl_short8; - typedef __vector unsigned int __cl_uint4; - typedef __vector signed int __cl_int4; - typedef __vector float __cl_float4; - #define __CL_UCHAR16__ 1 - #define __CL_CHAR16__ 1 - #define __CL_USHORT8__ 1 - #define __CL_SHORT8__ 1 - #define __CL_UINT4__ 1 - #define __CL_INT4__ 1 - #define __CL_FLOAT4__ 1 +#if !defined(__clang__) +#include /* may be omitted depending on compiler. AltiVec spec provides no way to detect whether the header is required. */ +#endif +typedef __vector unsigned char __cl_uchar16; +typedef __vector signed char __cl_char16; +typedef __vector unsigned short __cl_ushort8; +typedef __vector signed short __cl_short8; +typedef __vector unsigned int __cl_uint4; +typedef __vector signed int __cl_int4; +typedef __vector float __cl_float4; +#define __CL_UCHAR16__ 1 +#define __CL_CHAR16__ 1 +#define __CL_USHORT8__ 1 +#define __CL_SHORT8__ 1 +#define __CL_UINT4__ 1 +#define __CL_INT4__ 1 +#define __CL_FLOAT4__ 1 #endif #if defined( __SSE__ ) - #if defined( __MINGW64__ ) - #include - #else - #include - #endif - #if defined( __GNUC__ ) - typedef float __cl_float4 __attribute__((vector_size(16))); - #else - typedef __m128 __cl_float4; - #endif - #define __CL_FLOAT4__ 1 +#if defined( __MINGW64__ ) +#include +#else +#include +#endif +#if defined( __GNUC__ ) +typedef float __cl_float4 __attribute__((vector_size(16))); +#else +typedef __m128 __cl_float4; +#endif +#define __CL_FLOAT4__ 1 #endif #if defined( __SSE2__ ) - #if defined( __MINGW64__ ) - #include - #else - #include - #endif - #if defined( __GNUC__ ) - typedef cl_uchar __cl_uchar16 __attribute__((vector_size(16))); - typedef cl_char __cl_char16 __attribute__((vector_size(16))); - typedef cl_ushort __cl_ushort8 __attribute__((vector_size(16))); - typedef cl_short __cl_short8 __attribute__((vector_size(16))); - typedef cl_uint __cl_uint4 __attribute__((vector_size(16))); - typedef cl_int __cl_int4 __attribute__((vector_size(16))); - typedef cl_ulong __cl_ulong2 __attribute__((vector_size(16))); - typedef cl_long __cl_long2 __attribute__((vector_size(16))); - typedef cl_double __cl_double2 __attribute__((vector_size(16))); - #else - typedef __m128i __cl_uchar16; - typedef __m128i __cl_char16; - typedef __m128i __cl_ushort8; - typedef __m128i __cl_short8; - typedef __m128i __cl_uint4; - typedef __m128i __cl_int4; - typedef __m128i __cl_ulong2; - typedef __m128i __cl_long2; - typedef __m128d __cl_double2; - #endif - #define __CL_UCHAR16__ 1 - #define __CL_CHAR16__ 1 - #define __CL_USHORT8__ 1 - #define __CL_SHORT8__ 1 - #define __CL_INT4__ 1 - #define __CL_UINT4__ 1 - #define __CL_ULONG2__ 1 - #define __CL_LONG2__ 1 - #define __CL_DOUBLE2__ 1 +#if defined( __MINGW64__ ) +#include +#else +#include +#endif +#if defined( __GNUC__ ) +typedef cl_uchar __cl_uchar16 __attribute__((vector_size(16))); +typedef cl_char __cl_char16 __attribute__((vector_size(16))); +typedef cl_ushort __cl_ushort8 __attribute__((vector_size(16))); +typedef cl_short __cl_short8 __attribute__((vector_size(16))); +typedef cl_uint __cl_uint4 __attribute__((vector_size(16))); +typedef cl_int __cl_int4 __attribute__((vector_size(16))); +typedef cl_ulong __cl_ulong2 __attribute__((vector_size(16))); +typedef cl_long __cl_long2 __attribute__((vector_size(16))); +typedef cl_double __cl_double2 __attribute__((vector_size(16))); +#else +typedef __m128i __cl_uchar16; +typedef __m128i __cl_char16; +typedef __m128i __cl_ushort8; +typedef __m128i __cl_short8; +typedef __m128i __cl_uint4; +typedef __m128i __cl_int4; +typedef __m128i __cl_ulong2; +typedef __m128i __cl_long2; +typedef __m128d __cl_double2; +#endif +#define __CL_UCHAR16__ 1 +#define __CL_CHAR16__ 1 +#define __CL_USHORT8__ 1 +#define __CL_SHORT8__ 1 +#define __CL_INT4__ 1 +#define __CL_UINT4__ 1 +#define __CL_ULONG2__ 1 +#define __CL_LONG2__ 1 +#define __CL_DOUBLE2__ 1 #endif #if defined( __MMX__ ) - #include - #if defined( __GNUC__ ) - typedef cl_uchar __cl_uchar8 __attribute__((vector_size(8))); - typedef cl_char __cl_char8 __attribute__((vector_size(8))); - typedef cl_ushort __cl_ushort4 __attribute__((vector_size(8))); - typedef cl_short __cl_short4 __attribute__((vector_size(8))); - typedef cl_uint __cl_uint2 __attribute__((vector_size(8))); - typedef cl_int __cl_int2 __attribute__((vector_size(8))); - typedef cl_ulong __cl_ulong1 __attribute__((vector_size(8))); - typedef cl_long __cl_long1 __attribute__((vector_size(8))); - typedef cl_float __cl_float2 __attribute__((vector_size(8))); - #else - typedef __m64 __cl_uchar8; - typedef __m64 __cl_char8; - typedef __m64 __cl_ushort4; - typedef __m64 __cl_short4; - typedef __m64 __cl_uint2; - typedef __m64 __cl_int2; - typedef __m64 __cl_ulong1; - typedef __m64 __cl_long1; - typedef __m64 __cl_float2; - #endif - #define __CL_UCHAR8__ 1 - #define __CL_CHAR8__ 1 - #define __CL_USHORT4__ 1 - #define __CL_SHORT4__ 1 - #define __CL_INT2__ 1 - #define __CL_UINT2__ 1 - #define __CL_ULONG1__ 1 - #define __CL_LONG1__ 1 - #define __CL_FLOAT2__ 1 +#include +#if defined( __GNUC__ ) +typedef cl_uchar __cl_uchar8 __attribute__((vector_size(8))); +typedef cl_char __cl_char8 __attribute__((vector_size(8))); +typedef cl_ushort __cl_ushort4 __attribute__((vector_size(8))); +typedef cl_short __cl_short4 __attribute__((vector_size(8))); +typedef cl_uint __cl_uint2 __attribute__((vector_size(8))); +typedef cl_int __cl_int2 __attribute__((vector_size(8))); +typedef cl_ulong __cl_ulong1 __attribute__((vector_size(8))); +typedef cl_long __cl_long1 __attribute__((vector_size(8))); +typedef cl_float __cl_float2 __attribute__((vector_size(8))); +#else +typedef __m64 __cl_uchar8; +typedef __m64 __cl_char8; +typedef __m64 __cl_ushort4; +typedef __m64 __cl_short4; +typedef __m64 __cl_uint2; +typedef __m64 __cl_int2; +typedef __m64 __cl_ulong1; +typedef __m64 __cl_long1; +typedef __m64 __cl_float2; +#endif +#define __CL_UCHAR8__ 1 +#define __CL_CHAR8__ 1 +#define __CL_USHORT4__ 1 +#define __CL_SHORT4__ 1 +#define __CL_INT2__ 1 +#define __CL_UINT2__ 1 +#define __CL_ULONG1__ 1 +#define __CL_LONG1__ 1 +#define __CL_FLOAT2__ 1 #endif #if defined( __AVX__ ) - #if defined( __MINGW64__ ) - #include - #else - #include - #endif - #if defined( __GNUC__ ) - typedef cl_float __cl_float8 __attribute__((vector_size(32))); - typedef cl_double __cl_double4 __attribute__((vector_size(32))); - #else - typedef __m256 __cl_float8; - typedef __m256d __cl_double4; - #endif - #define __CL_FLOAT8__ 1 - #define __CL_DOUBLE4__ 1 +#if defined( __MINGW64__ ) +#include +#else +#include +#endif +#if defined( __GNUC__ ) +typedef cl_float __cl_float8 __attribute__((vector_size(32))); +typedef cl_double __cl_double4 __attribute__((vector_size(32))); +#else +typedef __m256 __cl_float8; +typedef __m256d __cl_double4; +#endif +#define __CL_FLOAT8__ 1 +#define __CL_DOUBLE4__ 1 #endif /* Define capabilities for anonymous struct members. */ @@ -485,16 +485,16 @@ typedef unsigned int cl_GLenum; #define __CL_HAS_ANON_STRUCT__ 1 #define __CL_ANON_STRUCT__ __extension__ #elif defined( _WIN32) && defined(_MSC_VER) && ! defined(__STDC__) - #if _MSC_VER >= 1500 - /* Microsoft Developer Studio 2008 supports anonymous structs, but - * complains by default. */ - #define __CL_HAS_ANON_STRUCT__ 1 - #define __CL_ANON_STRUCT__ - /* Disable warning C4201: nonstandard extension used : nameless - * struct/union */ - #pragma warning( push ) - #pragma warning( disable : 4201 ) - #endif +#if _MSC_VER >= 1500 +/* Microsoft Developer Studio 2008 supports anonymous structs, but + * complains by default. */ +#define __CL_HAS_ANON_STRUCT__ 1 +#define __CL_ANON_STRUCT__ +/* Disable warning C4201: nonstandard extension used : nameless + * struct/union */ +#pragma warning( push ) +#pragma warning( disable : 4201 ) +#endif #else #define __CL_HAS_ANON_STRUCT__ 0 #define __CL_ANON_STRUCT__ @@ -502,49 +502,47 @@ typedef unsigned int cl_GLenum; /* Define alignment keys */ #if defined( __GNUC__ ) || defined(__INTEGRITY) - #define CL_ALIGNED(_x) __attribute__ ((aligned(_x))) +#define CL_ALIGNED(_x) __attribute__ ((aligned(_x))) #elif defined( _WIN32) && (_MSC_VER) - /* Alignment keys neutered on windows because MSVC can't swallow function arguments with alignment requirements */ - /* http://msdn.microsoft.com/en-us/library/373ak2y1%28VS.71%29.aspx */ - /* #include */ - /* #define CL_ALIGNED(_x) _CRT_ALIGN(_x) */ - #define CL_ALIGNED(_x) +/* Alignment keys neutered on windows because MSVC can't swallow function arguments with alignment requirements */ +/* http://msdn.microsoft.com/en-us/library/373ak2y1%28VS.71%29.aspx */ +/* #include */ +/* #define CL_ALIGNED(_x) _CRT_ALIGN(_x) */ +#define CL_ALIGNED(_x) #else - #warning Need to implement some method to align data here - #define CL_ALIGNED(_x) +#warning Need to implement some method to align data here +#define CL_ALIGNED(_x) #endif /* Indicate whether .xyzw, .s0123 and .hi.lo are supported */ #if __CL_HAS_ANON_STRUCT__ - /* .xyzw and .s0123...{f|F} are supported */ - #define CL_HAS_NAMED_VECTOR_FIELDS 1 - /* .hi and .lo are supported */ - #define CL_HAS_HI_LO_VECTOR_FIELDS 1 +/* .xyzw and .s0123...{f|F} are supported */ +#define CL_HAS_NAMED_VECTOR_FIELDS 1 +/* .hi and .lo are supported */ +#define CL_HAS_HI_LO_VECTOR_FIELDS 1 #endif /* Define cl_vector types */ /* ---- cl_charn ---- */ -typedef union -{ +typedef union { cl_char CL_ALIGNED(2) s[2]; #if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_char x, y; }; - __CL_ANON_STRUCT__ struct{ cl_char s0, s1; }; - __CL_ANON_STRUCT__ struct{ cl_char lo, hi; }; + __CL_ANON_STRUCT__ struct { cl_char x, y; }; + __CL_ANON_STRUCT__ struct { cl_char s0, s1; }; + __CL_ANON_STRUCT__ struct { cl_char lo, hi; }; #endif #if defined( __CL_CHAR2__) __cl_char2 v2; #endif -}cl_char2; +} cl_char2; -typedef union -{ +typedef union { cl_char CL_ALIGNED(4) s[4]; #if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_char x, y, z, w; }; - __CL_ANON_STRUCT__ struct{ cl_char s0, s1, s2, s3; }; - __CL_ANON_STRUCT__ struct{ cl_char2 lo, hi; }; + __CL_ANON_STRUCT__ struct { cl_char x, y, z, w; }; + __CL_ANON_STRUCT__ struct { cl_char s0, s1, s2, s3; }; + __CL_ANON_STRUCT__ struct { cl_char2 lo, hi; }; #endif #if defined( __CL_CHAR2__) __cl_char2 v2[2]; @@ -552,18 +550,17 @@ typedef union #if defined( __CL_CHAR4__) __cl_char4 v4; #endif -}cl_char4; +} cl_char4; /* cl_char3 is identical in size, alignment and behavior to cl_char4. See section 6.1.5. */ typedef cl_char4 cl_char3; -typedef union -{ +typedef union { cl_char CL_ALIGNED(8) s[8]; #if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_char x, y, z, w; }; - __CL_ANON_STRUCT__ struct{ cl_char s0, s1, s2, s3, s4, s5, s6, s7; }; - __CL_ANON_STRUCT__ struct{ cl_char4 lo, hi; }; + __CL_ANON_STRUCT__ struct { cl_char x, y, z, w; }; + __CL_ANON_STRUCT__ struct { cl_char s0, s1, s2, s3, s4, s5, s6, s7; }; + __CL_ANON_STRUCT__ struct { cl_char4 lo, hi; }; #endif #if defined( __CL_CHAR2__) __cl_char2 v2[4]; @@ -574,15 +571,14 @@ typedef union #if defined( __CL_CHAR8__ ) __cl_char8 v8; #endif -}cl_char8; +} cl_char8; -typedef union -{ +typedef union { cl_char CL_ALIGNED(16) s[16]; #if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_char x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; - __CL_ANON_STRUCT__ struct{ cl_char s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; - __CL_ANON_STRUCT__ struct{ cl_char8 lo, hi; }; + __CL_ANON_STRUCT__ struct { cl_char x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; + __CL_ANON_STRUCT__ struct { cl_char s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; + __CL_ANON_STRUCT__ struct { cl_char8 lo, hi; }; #endif #if defined( __CL_CHAR2__) __cl_char2 v2[8]; @@ -596,30 +592,28 @@ typedef union #if defined( __CL_CHAR16__ ) __cl_char16 v16; #endif -}cl_char16; +} cl_char16; /* ---- cl_ucharn ---- */ -typedef union -{ +typedef union { cl_uchar CL_ALIGNED(2) s[2]; #if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_uchar x, y; }; - __CL_ANON_STRUCT__ struct{ cl_uchar s0, s1; }; - __CL_ANON_STRUCT__ struct{ cl_uchar lo, hi; }; + __CL_ANON_STRUCT__ struct { cl_uchar x, y; }; + __CL_ANON_STRUCT__ struct { cl_uchar s0, s1; }; + __CL_ANON_STRUCT__ struct { cl_uchar lo, hi; }; #endif #if defined( __cl_uchar2__) __cl_uchar2 v2; #endif -}cl_uchar2; +} cl_uchar2; -typedef union -{ +typedef union { cl_uchar CL_ALIGNED(4) s[4]; #if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_uchar x, y, z, w; }; - __CL_ANON_STRUCT__ struct{ cl_uchar s0, s1, s2, s3; }; - __CL_ANON_STRUCT__ struct{ cl_uchar2 lo, hi; }; + __CL_ANON_STRUCT__ struct { cl_uchar x, y, z, w; }; + __CL_ANON_STRUCT__ struct { cl_uchar s0, s1, s2, s3; }; + __CL_ANON_STRUCT__ struct { cl_uchar2 lo, hi; }; #endif #if defined( __CL_UCHAR2__) __cl_uchar2 v2[2]; @@ -627,18 +621,17 @@ typedef union #if defined( __CL_UCHAR4__) __cl_uchar4 v4; #endif -}cl_uchar4; +} cl_uchar4; /* cl_uchar3 is identical in size, alignment and behavior to cl_uchar4. See section 6.1.5. */ typedef cl_uchar4 cl_uchar3; -typedef union -{ +typedef union { cl_uchar CL_ALIGNED(8) s[8]; #if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_uchar x, y, z, w; }; - __CL_ANON_STRUCT__ struct{ cl_uchar s0, s1, s2, s3, s4, s5, s6, s7; }; - __CL_ANON_STRUCT__ struct{ cl_uchar4 lo, hi; }; + __CL_ANON_STRUCT__ struct { cl_uchar x, y, z, w; }; + __CL_ANON_STRUCT__ struct { cl_uchar s0, s1, s2, s3, s4, s5, s6, s7; }; + __CL_ANON_STRUCT__ struct { cl_uchar4 lo, hi; }; #endif #if defined( __CL_UCHAR2__) __cl_uchar2 v2[4]; @@ -649,15 +642,14 @@ typedef union #if defined( __CL_UCHAR8__ ) __cl_uchar8 v8; #endif -}cl_uchar8; +} cl_uchar8; -typedef union -{ +typedef union { cl_uchar CL_ALIGNED(16) s[16]; #if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_uchar x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; - __CL_ANON_STRUCT__ struct{ cl_uchar s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; - __CL_ANON_STRUCT__ struct{ cl_uchar8 lo, hi; }; + __CL_ANON_STRUCT__ struct { cl_uchar x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; + __CL_ANON_STRUCT__ struct { cl_uchar s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; + __CL_ANON_STRUCT__ struct { cl_uchar8 lo, hi; }; #endif #if defined( __CL_UCHAR2__) __cl_uchar2 v2[8]; @@ -671,30 +663,28 @@ typedef union #if defined( __CL_UCHAR16__ ) __cl_uchar16 v16; #endif -}cl_uchar16; +} cl_uchar16; /* ---- cl_shortn ---- */ -typedef union -{ +typedef union { cl_short CL_ALIGNED(4) s[2]; #if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_short x, y; }; - __CL_ANON_STRUCT__ struct{ cl_short s0, s1; }; - __CL_ANON_STRUCT__ struct{ cl_short lo, hi; }; + __CL_ANON_STRUCT__ struct { cl_short x, y; }; + __CL_ANON_STRUCT__ struct { cl_short s0, s1; }; + __CL_ANON_STRUCT__ struct { cl_short lo, hi; }; #endif #if defined( __CL_SHORT2__) __cl_short2 v2; #endif -}cl_short2; +} cl_short2; -typedef union -{ +typedef union { cl_short CL_ALIGNED(8) s[4]; #if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_short x, y, z, w; }; - __CL_ANON_STRUCT__ struct{ cl_short s0, s1, s2, s3; }; - __CL_ANON_STRUCT__ struct{ cl_short2 lo, hi; }; + __CL_ANON_STRUCT__ struct { cl_short x, y, z, w; }; + __CL_ANON_STRUCT__ struct { cl_short s0, s1, s2, s3; }; + __CL_ANON_STRUCT__ struct { cl_short2 lo, hi; }; #endif #if defined( __CL_SHORT2__) __cl_short2 v2[2]; @@ -702,18 +692,17 @@ typedef union #if defined( __CL_SHORT4__) __cl_short4 v4; #endif -}cl_short4; +} cl_short4; /* cl_short3 is identical in size, alignment and behavior to cl_short4. See section 6.1.5. */ typedef cl_short4 cl_short3; -typedef union -{ +typedef union { cl_short CL_ALIGNED(16) s[8]; #if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_short x, y, z, w; }; - __CL_ANON_STRUCT__ struct{ cl_short s0, s1, s2, s3, s4, s5, s6, s7; }; - __CL_ANON_STRUCT__ struct{ cl_short4 lo, hi; }; + __CL_ANON_STRUCT__ struct { cl_short x, y, z, w; }; + __CL_ANON_STRUCT__ struct { cl_short s0, s1, s2, s3, s4, s5, s6, s7; }; + __CL_ANON_STRUCT__ struct { cl_short4 lo, hi; }; #endif #if defined( __CL_SHORT2__) __cl_short2 v2[4]; @@ -724,15 +713,14 @@ typedef union #if defined( __CL_SHORT8__ ) __cl_short8 v8; #endif -}cl_short8; +} cl_short8; -typedef union -{ +typedef union { cl_short CL_ALIGNED(32) s[16]; #if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_short x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; - __CL_ANON_STRUCT__ struct{ cl_short s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; - __CL_ANON_STRUCT__ struct{ cl_short8 lo, hi; }; + __CL_ANON_STRUCT__ struct { cl_short x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; + __CL_ANON_STRUCT__ struct { cl_short s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; + __CL_ANON_STRUCT__ struct { cl_short8 lo, hi; }; #endif #if defined( __CL_SHORT2__) __cl_short2 v2[8]; @@ -746,30 +734,28 @@ typedef union #if defined( __CL_SHORT16__ ) __cl_short16 v16; #endif -}cl_short16; +} cl_short16; /* ---- cl_ushortn ---- */ -typedef union -{ +typedef union { cl_ushort CL_ALIGNED(4) s[2]; #if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_ushort x, y; }; - __CL_ANON_STRUCT__ struct{ cl_ushort s0, s1; }; - __CL_ANON_STRUCT__ struct{ cl_ushort lo, hi; }; + __CL_ANON_STRUCT__ struct { cl_ushort x, y; }; + __CL_ANON_STRUCT__ struct { cl_ushort s0, s1; }; + __CL_ANON_STRUCT__ struct { cl_ushort lo, hi; }; #endif #if defined( __CL_USHORT2__) __cl_ushort2 v2; #endif -}cl_ushort2; +} cl_ushort2; -typedef union -{ +typedef union { cl_ushort CL_ALIGNED(8) s[4]; #if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_ushort x, y, z, w; }; - __CL_ANON_STRUCT__ struct{ cl_ushort s0, s1, s2, s3; }; - __CL_ANON_STRUCT__ struct{ cl_ushort2 lo, hi; }; + __CL_ANON_STRUCT__ struct { cl_ushort x, y, z, w; }; + __CL_ANON_STRUCT__ struct { cl_ushort s0, s1, s2, s3; }; + __CL_ANON_STRUCT__ struct { cl_ushort2 lo, hi; }; #endif #if defined( __CL_USHORT2__) __cl_ushort2 v2[2]; @@ -777,18 +763,17 @@ typedef union #if defined( __CL_USHORT4__) __cl_ushort4 v4; #endif -}cl_ushort4; +} cl_ushort4; /* cl_ushort3 is identical in size, alignment and behavior to cl_ushort4. See section 6.1.5. */ typedef cl_ushort4 cl_ushort3; -typedef union -{ +typedef union { cl_ushort CL_ALIGNED(16) s[8]; #if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_ushort x, y, z, w; }; - __CL_ANON_STRUCT__ struct{ cl_ushort s0, s1, s2, s3, s4, s5, s6, s7; }; - __CL_ANON_STRUCT__ struct{ cl_ushort4 lo, hi; }; + __CL_ANON_STRUCT__ struct { cl_ushort x, y, z, w; }; + __CL_ANON_STRUCT__ struct { cl_ushort s0, s1, s2, s3, s4, s5, s6, s7; }; + __CL_ANON_STRUCT__ struct { cl_ushort4 lo, hi; }; #endif #if defined( __CL_USHORT2__) __cl_ushort2 v2[4]; @@ -799,15 +784,14 @@ typedef union #if defined( __CL_USHORT8__ ) __cl_ushort8 v8; #endif -}cl_ushort8; +} cl_ushort8; -typedef union -{ +typedef union { cl_ushort CL_ALIGNED(32) s[16]; #if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_ushort x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; - __CL_ANON_STRUCT__ struct{ cl_ushort s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; - __CL_ANON_STRUCT__ struct{ cl_ushort8 lo, hi; }; + __CL_ANON_STRUCT__ struct { cl_ushort x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; + __CL_ANON_STRUCT__ struct { cl_ushort s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; + __CL_ANON_STRUCT__ struct { cl_ushort8 lo, hi; }; #endif #if defined( __CL_USHORT2__) __cl_ushort2 v2[8]; @@ -821,30 +805,28 @@ typedef union #if defined( __CL_USHORT16__ ) __cl_ushort16 v16; #endif -}cl_ushort16; +} cl_ushort16; /* ---- cl_halfn ---- */ -typedef union -{ +typedef union { cl_half CL_ALIGNED(4) s[2]; #if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_half x, y; }; - __CL_ANON_STRUCT__ struct{ cl_half s0, s1; }; - __CL_ANON_STRUCT__ struct{ cl_half lo, hi; }; + __CL_ANON_STRUCT__ struct { cl_half x, y; }; + __CL_ANON_STRUCT__ struct { cl_half s0, s1; }; + __CL_ANON_STRUCT__ struct { cl_half lo, hi; }; #endif #if defined( __CL_HALF2__) __cl_half2 v2; #endif -}cl_half2; +} cl_half2; -typedef union -{ +typedef union { cl_half CL_ALIGNED(8) s[4]; #if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_half x, y, z, w; }; - __CL_ANON_STRUCT__ struct{ cl_half s0, s1, s2, s3; }; - __CL_ANON_STRUCT__ struct{ cl_half2 lo, hi; }; + __CL_ANON_STRUCT__ struct { cl_half x, y, z, w; }; + __CL_ANON_STRUCT__ struct { cl_half s0, s1, s2, s3; }; + __CL_ANON_STRUCT__ struct { cl_half2 lo, hi; }; #endif #if defined( __CL_HALF2__) __cl_half2 v2[2]; @@ -852,18 +834,17 @@ typedef union #if defined( __CL_HALF4__) __cl_half4 v4; #endif -}cl_half4; +} cl_half4; /* cl_half3 is identical in size, alignment and behavior to cl_half4. See section 6.1.5. */ typedef cl_half4 cl_half3; -typedef union -{ +typedef union { cl_half CL_ALIGNED(16) s[8]; #if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_half x, y, z, w; }; - __CL_ANON_STRUCT__ struct{ cl_half s0, s1, s2, s3, s4, s5, s6, s7; }; - __CL_ANON_STRUCT__ struct{ cl_half4 lo, hi; }; + __CL_ANON_STRUCT__ struct { cl_half x, y, z, w; }; + __CL_ANON_STRUCT__ struct { cl_half s0, s1, s2, s3, s4, s5, s6, s7; }; + __CL_ANON_STRUCT__ struct { cl_half4 lo, hi; }; #endif #if defined( __CL_HALF2__) __cl_half2 v2[4]; @@ -874,15 +855,14 @@ typedef union #if defined( __CL_HALF8__ ) __cl_half8 v8; #endif -}cl_half8; +} cl_half8; -typedef union -{ +typedef union { cl_half CL_ALIGNED(32) s[16]; #if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_half x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; - __CL_ANON_STRUCT__ struct{ cl_half s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; - __CL_ANON_STRUCT__ struct{ cl_half8 lo, hi; }; + __CL_ANON_STRUCT__ struct { cl_half x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; + __CL_ANON_STRUCT__ struct { cl_half s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; + __CL_ANON_STRUCT__ struct { cl_half8 lo, hi; }; #endif #if defined( __CL_HALF2__) __cl_half2 v2[8]; @@ -896,29 +876,27 @@ typedef union #if defined( __CL_HALF16__ ) __cl_half16 v16; #endif -}cl_half16; +} cl_half16; /* ---- cl_intn ---- */ -typedef union -{ +typedef union { cl_int CL_ALIGNED(8) s[2]; #if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_int x, y; }; - __CL_ANON_STRUCT__ struct{ cl_int s0, s1; }; - __CL_ANON_STRUCT__ struct{ cl_int lo, hi; }; + __CL_ANON_STRUCT__ struct { cl_int x, y; }; + __CL_ANON_STRUCT__ struct { cl_int s0, s1; }; + __CL_ANON_STRUCT__ struct { cl_int lo, hi; }; #endif #if defined( __CL_INT2__) __cl_int2 v2; #endif -}cl_int2; +} cl_int2; -typedef union -{ +typedef union { cl_int CL_ALIGNED(16) s[4]; #if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_int x, y, z, w; }; - __CL_ANON_STRUCT__ struct{ cl_int s0, s1, s2, s3; }; - __CL_ANON_STRUCT__ struct{ cl_int2 lo, hi; }; + __CL_ANON_STRUCT__ struct { cl_int x, y, z, w; }; + __CL_ANON_STRUCT__ struct { cl_int s0, s1, s2, s3; }; + __CL_ANON_STRUCT__ struct { cl_int2 lo, hi; }; #endif #if defined( __CL_INT2__) __cl_int2 v2[2]; @@ -926,18 +904,17 @@ typedef union #if defined( __CL_INT4__) __cl_int4 v4; #endif -}cl_int4; +} cl_int4; /* cl_int3 is identical in size, alignment and behavior to cl_int4. See section 6.1.5. */ typedef cl_int4 cl_int3; -typedef union -{ +typedef union { cl_int CL_ALIGNED(32) s[8]; #if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_int x, y, z, w; }; - __CL_ANON_STRUCT__ struct{ cl_int s0, s1, s2, s3, s4, s5, s6, s7; }; - __CL_ANON_STRUCT__ struct{ cl_int4 lo, hi; }; + __CL_ANON_STRUCT__ struct { cl_int x, y, z, w; }; + __CL_ANON_STRUCT__ struct { cl_int s0, s1, s2, s3, s4, s5, s6, s7; }; + __CL_ANON_STRUCT__ struct { cl_int4 lo, hi; }; #endif #if defined( __CL_INT2__) __cl_int2 v2[4]; @@ -948,15 +925,14 @@ typedef union #if defined( __CL_INT8__ ) __cl_int8 v8; #endif -}cl_int8; +} cl_int8; -typedef union -{ +typedef union { cl_int CL_ALIGNED(64) s[16]; #if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_int x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; - __CL_ANON_STRUCT__ struct{ cl_int s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; - __CL_ANON_STRUCT__ struct{ cl_int8 lo, hi; }; + __CL_ANON_STRUCT__ struct { cl_int x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; + __CL_ANON_STRUCT__ struct { cl_int s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; + __CL_ANON_STRUCT__ struct { cl_int8 lo, hi; }; #endif #if defined( __CL_INT2__) __cl_int2 v2[8]; @@ -970,30 +946,28 @@ typedef union #if defined( __CL_INT16__ ) __cl_int16 v16; #endif -}cl_int16; +} cl_int16; /* ---- cl_uintn ---- */ -typedef union -{ +typedef union { cl_uint CL_ALIGNED(8) s[2]; #if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_uint x, y; }; - __CL_ANON_STRUCT__ struct{ cl_uint s0, s1; }; - __CL_ANON_STRUCT__ struct{ cl_uint lo, hi; }; + __CL_ANON_STRUCT__ struct { cl_uint x, y; }; + __CL_ANON_STRUCT__ struct { cl_uint s0, s1; }; + __CL_ANON_STRUCT__ struct { cl_uint lo, hi; }; #endif #if defined( __CL_UINT2__) __cl_uint2 v2; #endif -}cl_uint2; +} cl_uint2; -typedef union -{ +typedef union { cl_uint CL_ALIGNED(16) s[4]; #if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_uint x, y, z, w; }; - __CL_ANON_STRUCT__ struct{ cl_uint s0, s1, s2, s3; }; - __CL_ANON_STRUCT__ struct{ cl_uint2 lo, hi; }; + __CL_ANON_STRUCT__ struct { cl_uint x, y, z, w; }; + __CL_ANON_STRUCT__ struct { cl_uint s0, s1, s2, s3; }; + __CL_ANON_STRUCT__ struct { cl_uint2 lo, hi; }; #endif #if defined( __CL_UINT2__) __cl_uint2 v2[2]; @@ -1001,18 +975,17 @@ typedef union #if defined( __CL_UINT4__) __cl_uint4 v4; #endif -}cl_uint4; +} cl_uint4; /* cl_uint3 is identical in size, alignment and behavior to cl_uint4. See section 6.1.5. */ typedef cl_uint4 cl_uint3; -typedef union -{ +typedef union { cl_uint CL_ALIGNED(32) s[8]; #if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_uint x, y, z, w; }; - __CL_ANON_STRUCT__ struct{ cl_uint s0, s1, s2, s3, s4, s5, s6, s7; }; - __CL_ANON_STRUCT__ struct{ cl_uint4 lo, hi; }; + __CL_ANON_STRUCT__ struct { cl_uint x, y, z, w; }; + __CL_ANON_STRUCT__ struct { cl_uint s0, s1, s2, s3, s4, s5, s6, s7; }; + __CL_ANON_STRUCT__ struct { cl_uint4 lo, hi; }; #endif #if defined( __CL_UINT2__) __cl_uint2 v2[4]; @@ -1023,15 +996,14 @@ typedef union #if defined( __CL_UINT8__ ) __cl_uint8 v8; #endif -}cl_uint8; +} cl_uint8; -typedef union -{ +typedef union { cl_uint CL_ALIGNED(64) s[16]; #if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_uint x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; - __CL_ANON_STRUCT__ struct{ cl_uint s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; - __CL_ANON_STRUCT__ struct{ cl_uint8 lo, hi; }; + __CL_ANON_STRUCT__ struct { cl_uint x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; + __CL_ANON_STRUCT__ struct { cl_uint s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; + __CL_ANON_STRUCT__ struct { cl_uint8 lo, hi; }; #endif #if defined( __CL_UINT2__) __cl_uint2 v2[8]; @@ -1045,29 +1017,27 @@ typedef union #if defined( __CL_UINT16__ ) __cl_uint16 v16; #endif -}cl_uint16; +} cl_uint16; /* ---- cl_longn ---- */ -typedef union -{ +typedef union { cl_long CL_ALIGNED(16) s[2]; #if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_long x, y; }; - __CL_ANON_STRUCT__ struct{ cl_long s0, s1; }; - __CL_ANON_STRUCT__ struct{ cl_long lo, hi; }; + __CL_ANON_STRUCT__ struct { cl_long x, y; }; + __CL_ANON_STRUCT__ struct { cl_long s0, s1; }; + __CL_ANON_STRUCT__ struct { cl_long lo, hi; }; #endif #if defined( __CL_LONG2__) __cl_long2 v2; #endif -}cl_long2; +} cl_long2; -typedef union -{ +typedef union { cl_long CL_ALIGNED(32) s[4]; #if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_long x, y, z, w; }; - __CL_ANON_STRUCT__ struct{ cl_long s0, s1, s2, s3; }; - __CL_ANON_STRUCT__ struct{ cl_long2 lo, hi; }; + __CL_ANON_STRUCT__ struct { cl_long x, y, z, w; }; + __CL_ANON_STRUCT__ struct { cl_long s0, s1, s2, s3; }; + __CL_ANON_STRUCT__ struct { cl_long2 lo, hi; }; #endif #if defined( __CL_LONG2__) __cl_long2 v2[2]; @@ -1075,18 +1045,17 @@ typedef union #if defined( __CL_LONG4__) __cl_long4 v4; #endif -}cl_long4; +} cl_long4; /* cl_long3 is identical in size, alignment and behavior to cl_long4. See section 6.1.5. */ typedef cl_long4 cl_long3; -typedef union -{ +typedef union { cl_long CL_ALIGNED(64) s[8]; #if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_long x, y, z, w; }; - __CL_ANON_STRUCT__ struct{ cl_long s0, s1, s2, s3, s4, s5, s6, s7; }; - __CL_ANON_STRUCT__ struct{ cl_long4 lo, hi; }; + __CL_ANON_STRUCT__ struct { cl_long x, y, z, w; }; + __CL_ANON_STRUCT__ struct { cl_long s0, s1, s2, s3, s4, s5, s6, s7; }; + __CL_ANON_STRUCT__ struct { cl_long4 lo, hi; }; #endif #if defined( __CL_LONG2__) __cl_long2 v2[4]; @@ -1097,15 +1066,14 @@ typedef union #if defined( __CL_LONG8__ ) __cl_long8 v8; #endif -}cl_long8; +} cl_long8; -typedef union -{ +typedef union { cl_long CL_ALIGNED(128) s[16]; #if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_long x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; - __CL_ANON_STRUCT__ struct{ cl_long s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; - __CL_ANON_STRUCT__ struct{ cl_long8 lo, hi; }; + __CL_ANON_STRUCT__ struct { cl_long x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; + __CL_ANON_STRUCT__ struct { cl_long s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; + __CL_ANON_STRUCT__ struct { cl_long8 lo, hi; }; #endif #if defined( __CL_LONG2__) __cl_long2 v2[8]; @@ -1119,30 +1087,28 @@ typedef union #if defined( __CL_LONG16__ ) __cl_long16 v16; #endif -}cl_long16; +} cl_long16; /* ---- cl_ulongn ---- */ -typedef union -{ +typedef union { cl_ulong CL_ALIGNED(16) s[2]; #if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_ulong x, y; }; - __CL_ANON_STRUCT__ struct{ cl_ulong s0, s1; }; - __CL_ANON_STRUCT__ struct{ cl_ulong lo, hi; }; + __CL_ANON_STRUCT__ struct { cl_ulong x, y; }; + __CL_ANON_STRUCT__ struct { cl_ulong s0, s1; }; + __CL_ANON_STRUCT__ struct { cl_ulong lo, hi; }; #endif #if defined( __CL_ULONG2__) __cl_ulong2 v2; #endif -}cl_ulong2; +} cl_ulong2; -typedef union -{ +typedef union { cl_ulong CL_ALIGNED(32) s[4]; #if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_ulong x, y, z, w; }; - __CL_ANON_STRUCT__ struct{ cl_ulong s0, s1, s2, s3; }; - __CL_ANON_STRUCT__ struct{ cl_ulong2 lo, hi; }; + __CL_ANON_STRUCT__ struct { cl_ulong x, y, z, w; }; + __CL_ANON_STRUCT__ struct { cl_ulong s0, s1, s2, s3; }; + __CL_ANON_STRUCT__ struct { cl_ulong2 lo, hi; }; #endif #if defined( __CL_ULONG2__) __cl_ulong2 v2[2]; @@ -1150,18 +1116,17 @@ typedef union #if defined( __CL_ULONG4__) __cl_ulong4 v4; #endif -}cl_ulong4; +} cl_ulong4; /* cl_ulong3 is identical in size, alignment and behavior to cl_ulong4. See section 6.1.5. */ typedef cl_ulong4 cl_ulong3; -typedef union -{ +typedef union { cl_ulong CL_ALIGNED(64) s[8]; #if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_ulong x, y, z, w; }; - __CL_ANON_STRUCT__ struct{ cl_ulong s0, s1, s2, s3, s4, s5, s6, s7; }; - __CL_ANON_STRUCT__ struct{ cl_ulong4 lo, hi; }; + __CL_ANON_STRUCT__ struct { cl_ulong x, y, z, w; }; + __CL_ANON_STRUCT__ struct { cl_ulong s0, s1, s2, s3, s4, s5, s6, s7; }; + __CL_ANON_STRUCT__ struct { cl_ulong4 lo, hi; }; #endif #if defined( __CL_ULONG2__) __cl_ulong2 v2[4]; @@ -1172,15 +1137,14 @@ typedef union #if defined( __CL_ULONG8__ ) __cl_ulong8 v8; #endif -}cl_ulong8; +} cl_ulong8; -typedef union -{ +typedef union { cl_ulong CL_ALIGNED(128) s[16]; #if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_ulong x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; - __CL_ANON_STRUCT__ struct{ cl_ulong s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; - __CL_ANON_STRUCT__ struct{ cl_ulong8 lo, hi; }; + __CL_ANON_STRUCT__ struct { cl_ulong x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; + __CL_ANON_STRUCT__ struct { cl_ulong s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; + __CL_ANON_STRUCT__ struct { cl_ulong8 lo, hi; }; #endif #if defined( __CL_ULONG2__) __cl_ulong2 v2[8]; @@ -1194,31 +1158,29 @@ typedef union #if defined( __CL_ULONG16__ ) __cl_ulong16 v16; #endif -}cl_ulong16; +} cl_ulong16; /* --- cl_floatn ---- */ -typedef union -{ +typedef union { cl_float CL_ALIGNED(8) s[2]; #if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_float x, y; }; - __CL_ANON_STRUCT__ struct{ cl_float s0, s1; }; - __CL_ANON_STRUCT__ struct{ cl_float lo, hi; }; + __CL_ANON_STRUCT__ struct { cl_float x, y; }; + __CL_ANON_STRUCT__ struct { cl_float s0, s1; }; + __CL_ANON_STRUCT__ struct { cl_float lo, hi; }; #endif #if defined( __CL_FLOAT2__) __cl_float2 v2; #endif -}cl_float2; +} cl_float2; -typedef union -{ +typedef union { cl_float CL_ALIGNED(16) s[4]; #if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_float x, y, z, w; }; - __CL_ANON_STRUCT__ struct{ cl_float s0, s1, s2, s3; }; - __CL_ANON_STRUCT__ struct{ cl_float2 lo, hi; }; + __CL_ANON_STRUCT__ struct { cl_float x, y, z, w; }; + __CL_ANON_STRUCT__ struct { cl_float s0, s1, s2, s3; }; + __CL_ANON_STRUCT__ struct { cl_float2 lo, hi; }; #endif #if defined( __CL_FLOAT2__) __cl_float2 v2[2]; @@ -1226,18 +1188,17 @@ typedef union #if defined( __CL_FLOAT4__) __cl_float4 v4; #endif -}cl_float4; +} cl_float4; /* cl_float3 is identical in size, alignment and behavior to cl_float4. See section 6.1.5. */ typedef cl_float4 cl_float3; -typedef union -{ +typedef union { cl_float CL_ALIGNED(32) s[8]; #if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_float x, y, z, w; }; - __CL_ANON_STRUCT__ struct{ cl_float s0, s1, s2, s3, s4, s5, s6, s7; }; - __CL_ANON_STRUCT__ struct{ cl_float4 lo, hi; }; + __CL_ANON_STRUCT__ struct { cl_float x, y, z, w; }; + __CL_ANON_STRUCT__ struct { cl_float s0, s1, s2, s3, s4, s5, s6, s7; }; + __CL_ANON_STRUCT__ struct { cl_float4 lo, hi; }; #endif #if defined( __CL_FLOAT2__) __cl_float2 v2[4]; @@ -1248,15 +1209,14 @@ typedef union #if defined( __CL_FLOAT8__ ) __cl_float8 v8; #endif -}cl_float8; +} cl_float8; -typedef union -{ +typedef union { cl_float CL_ALIGNED(64) s[16]; #if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_float x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; - __CL_ANON_STRUCT__ struct{ cl_float s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; - __CL_ANON_STRUCT__ struct{ cl_float8 lo, hi; }; + __CL_ANON_STRUCT__ struct { cl_float x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; + __CL_ANON_STRUCT__ struct { cl_float s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; + __CL_ANON_STRUCT__ struct { cl_float8 lo, hi; }; #endif #if defined( __CL_FLOAT2__) __cl_float2 v2[8]; @@ -1270,30 +1230,28 @@ typedef union #if defined( __CL_FLOAT16__ ) __cl_float16 v16; #endif -}cl_float16; +} cl_float16; /* --- cl_doublen ---- */ -typedef union -{ +typedef union { cl_double CL_ALIGNED(16) s[2]; #if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_double x, y; }; - __CL_ANON_STRUCT__ struct{ cl_double s0, s1; }; - __CL_ANON_STRUCT__ struct{ cl_double lo, hi; }; + __CL_ANON_STRUCT__ struct { cl_double x, y; }; + __CL_ANON_STRUCT__ struct { cl_double s0, s1; }; + __CL_ANON_STRUCT__ struct { cl_double lo, hi; }; #endif #if defined( __CL_DOUBLE2__) __cl_double2 v2; #endif -}cl_double2; +} cl_double2; -typedef union -{ +typedef union { cl_double CL_ALIGNED(32) s[4]; #if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_double x, y, z, w; }; - __CL_ANON_STRUCT__ struct{ cl_double s0, s1, s2, s3; }; - __CL_ANON_STRUCT__ struct{ cl_double2 lo, hi; }; + __CL_ANON_STRUCT__ struct { cl_double x, y, z, w; }; + __CL_ANON_STRUCT__ struct { cl_double s0, s1, s2, s3; }; + __CL_ANON_STRUCT__ struct { cl_double2 lo, hi; }; #endif #if defined( __CL_DOUBLE2__) __cl_double2 v2[2]; @@ -1301,18 +1259,17 @@ typedef union #if defined( __CL_DOUBLE4__) __cl_double4 v4; #endif -}cl_double4; +} cl_double4; /* cl_double3 is identical in size, alignment and behavior to cl_double4. See section 6.1.5. */ typedef cl_double4 cl_double3; -typedef union -{ +typedef union { cl_double CL_ALIGNED(64) s[8]; #if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_double x, y, z, w; }; - __CL_ANON_STRUCT__ struct{ cl_double s0, s1, s2, s3, s4, s5, s6, s7; }; - __CL_ANON_STRUCT__ struct{ cl_double4 lo, hi; }; + __CL_ANON_STRUCT__ struct { cl_double x, y, z, w; }; + __CL_ANON_STRUCT__ struct { cl_double s0, s1, s2, s3, s4, s5, s6, s7; }; + __CL_ANON_STRUCT__ struct { cl_double4 lo, hi; }; #endif #if defined( __CL_DOUBLE2__) __cl_double2 v2[4]; @@ -1323,15 +1280,14 @@ typedef union #if defined( __CL_DOUBLE8__ ) __cl_double8 v8; #endif -}cl_double8; +} cl_double8; -typedef union -{ +typedef union { cl_double CL_ALIGNED(128) s[16]; #if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_double x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; - __CL_ANON_STRUCT__ struct{ cl_double s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; - __CL_ANON_STRUCT__ struct{ cl_double8 lo, hi; }; + __CL_ANON_STRUCT__ struct { cl_double x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; + __CL_ANON_STRUCT__ struct { cl_double s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; + __CL_ANON_STRUCT__ struct { cl_double8 lo, hi; }; #endif #if defined( __CL_DOUBLE2__) __cl_double2 v2[8]; @@ -1345,7 +1301,7 @@ typedef union #if defined( __CL_DOUBLE16__ ) __cl_double16 v16; #endif -}cl_double16; +} cl_double16; /* Macro to facilitate debugging * Usage: @@ -1376,9 +1332,9 @@ typedef union #endif #if defined( _WIN32) && defined(_MSC_VER) && ! defined(__STDC__) - #if _MSC_VER >=1500 - #pragma warning( pop ) - #endif +#if _MSC_VER >=1500 +#pragma warning( pop ) +#endif #endif #endif /* __CL_PLATFORM_H */ diff --git a/tools/hitag2crack/common/OpenCL-Headers/CL/cl_va_api_media_sharing_intel.h b/tools/hitag2crack/common/OpenCL-Headers/CL/cl_va_api_media_sharing_intel.h index 0e7cd4d6f..e9a1c6388 100644 --- a/tools/hitag2crack/common/OpenCL-Headers/CL/cl_va_api_media_sharing_intel.h +++ b/tools/hitag2crack/common/OpenCL-Headers/CL/cl_va_api_media_sharing_intel.h @@ -88,69 +88,69 @@ extern CL_API_ENTRY cl_int CL_API_CALL clGetDeviceIDsFromVA_APIMediaAdapterINTEL( cl_platform_id platform, cl_va_api_device_source_intel media_adapter_type, - void* media_adapter, + void *media_adapter, cl_va_api_device_set_intel media_adapter_set, cl_uint num_entries, - cl_device_id* devices, - cl_uint* num_devices) CL_EXT_SUFFIX__VERSION_1_2; + cl_device_id *devices, + cl_uint *num_devices) CL_EXT_SUFFIX__VERSION_1_2; -typedef CL_API_ENTRY cl_int (CL_API_CALL * clGetDeviceIDsFromVA_APIMediaAdapterINTEL_fn)( +typedef CL_API_ENTRY cl_int(CL_API_CALL *clGetDeviceIDsFromVA_APIMediaAdapterINTEL_fn)( cl_platform_id platform, cl_va_api_device_source_intel media_adapter_type, - void* media_adapter, + void *media_adapter, cl_va_api_device_set_intel media_adapter_set, cl_uint num_entries, - cl_device_id* devices, - cl_uint* num_devices) CL_EXT_SUFFIX__VERSION_1_2; + cl_device_id *devices, + cl_uint *num_devices) CL_EXT_SUFFIX__VERSION_1_2; extern CL_API_ENTRY cl_mem CL_API_CALL clCreateFromVA_APIMediaSurfaceINTEL( cl_context context, cl_mem_flags flags, - VASurfaceID* surface, + VASurfaceID *surface, cl_uint plane, - cl_int* errcode_ret) CL_EXT_SUFFIX__VERSION_1_2; + cl_int *errcode_ret) CL_EXT_SUFFIX__VERSION_1_2; -typedef CL_API_ENTRY cl_mem (CL_API_CALL * clCreateFromVA_APIMediaSurfaceINTEL_fn)( +typedef CL_API_ENTRY cl_mem(CL_API_CALL *clCreateFromVA_APIMediaSurfaceINTEL_fn)( cl_context context, cl_mem_flags flags, - VASurfaceID* surface, + VASurfaceID *surface, cl_uint plane, - cl_int* errcode_ret) CL_EXT_SUFFIX__VERSION_1_2; + cl_int *errcode_ret) CL_EXT_SUFFIX__VERSION_1_2; extern CL_API_ENTRY cl_int CL_API_CALL clEnqueueAcquireVA_APIMediaSurfacesINTEL( cl_command_queue command_queue, cl_uint num_objects, - const cl_mem* mem_objects, + const cl_mem *mem_objects, cl_uint num_events_in_wait_list, - const cl_event* event_wait_list, - cl_event* event) CL_EXT_SUFFIX__VERSION_1_2; + const cl_event *event_wait_list, + cl_event *event) CL_EXT_SUFFIX__VERSION_1_2; -typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueAcquireVA_APIMediaSurfacesINTEL_fn)( +typedef CL_API_ENTRY cl_int(CL_API_CALL *clEnqueueAcquireVA_APIMediaSurfacesINTEL_fn)( cl_command_queue command_queue, cl_uint num_objects, - const cl_mem* mem_objects, + const cl_mem *mem_objects, cl_uint num_events_in_wait_list, - const cl_event* event_wait_list, - cl_event* event) CL_EXT_SUFFIX__VERSION_1_2; + const cl_event *event_wait_list, + cl_event *event) CL_EXT_SUFFIX__VERSION_1_2; extern CL_API_ENTRY cl_int CL_API_CALL clEnqueueReleaseVA_APIMediaSurfacesINTEL( cl_command_queue command_queue, cl_uint num_objects, - const cl_mem* mem_objects, + const cl_mem *mem_objects, cl_uint num_events_in_wait_list, - const cl_event* event_wait_list, - cl_event* event) CL_EXT_SUFFIX__VERSION_1_2; + const cl_event *event_wait_list, + cl_event *event) CL_EXT_SUFFIX__VERSION_1_2; -typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueReleaseVA_APIMediaSurfacesINTEL_fn)( +typedef CL_API_ENTRY cl_int(CL_API_CALL *clEnqueueReleaseVA_APIMediaSurfacesINTEL_fn)( cl_command_queue command_queue, cl_uint num_objects, - const cl_mem* mem_objects, + const cl_mem *mem_objects, cl_uint num_events_in_wait_list, - const cl_event* event_wait_list, - cl_event* event) CL_EXT_SUFFIX__VERSION_1_2; + const cl_event *event_wait_list, + cl_event *event) CL_EXT_SUFFIX__VERSION_1_2; #ifdef __cplusplus } diff --git a/tools/hitag2crack/crack5opencl/hitag2.c b/tools/hitag2crack/crack5opencl/hitag2.c index a23093347..181f029ac 100644 --- a/tools/hitag2crack/crack5opencl/hitag2.c +++ b/tools/hitag2crack/crack5opencl/hitag2.c @@ -4,65 +4,62 @@ //#if FORCE_HITAG2_FULL == 0 // return a single bit from a value -int bitn (uint64_t x, int bit) -{ - const uint64_t bitmask = (uint64_t)(1) << bit; +int bitn(uint64_t x, int bit) { + const uint64_t bitmask = (uint64_t)(1) << bit; - return (x & bitmask) ? 1 : 0; + return (x & bitmask) ? 1 : 0; } // the sub-function R that rollback depends upon -int fnR (uint64_t x) -{ - // renumbered bits because my state is 0-47, not 1-48 - return (bitn(x, 1) ^ bitn(x, 2) ^ bitn(x, 5) ^ - bitn(x, 6) ^ bitn(x, 7) ^ bitn(x, 15) ^ - bitn(x, 21) ^ bitn(x, 22) ^ bitn(x, 25) ^ - bitn(x, 29) ^ bitn(x, 40) ^ bitn(x, 41) ^ - bitn(x, 42) ^ bitn(x, 45) ^ bitn(x, 46) ^ bitn(x, 47)); +int fnR(uint64_t x) { + // renumbered bits because my state is 0-47, not 1-48 + return (bitn(x, 1) ^ bitn(x, 2) ^ bitn(x, 5) ^ + bitn(x, 6) ^ bitn(x, 7) ^ bitn(x, 15) ^ + bitn(x, 21) ^ bitn(x, 22) ^ bitn(x, 25) ^ + bitn(x, 29) ^ bitn(x, 40) ^ bitn(x, 41) ^ + bitn(x, 42) ^ bitn(x, 45) ^ bitn(x, 46) ^ bitn(x, 47)); } // the three filter sub-functions that feed fnf int fa(unsigned int i) { - return bitn(0x2C79, (int)i); + return bitn(0x2C79, (int)i); } int fb(unsigned int i) { - return bitn(0x6671, (int)i); + return bitn(0x6671, (int)i); } // the filter function that generates a bit of output from the prng state -int fnf (uint64_t s) -{ - const unsigned int x1 = (unsigned int)((bitn(s, 2) << 0) | (bitn(s, 3) << 1) | (bitn(s, 5) << 2) | (bitn(s, 6) << 3)); - const unsigned int x2 = (unsigned int)((bitn(s, 8) << 0) | (bitn(s, 12) << 1) | (bitn(s, 14) << 2) | (bitn(s, 15) << 3)); - const unsigned int x3 = (unsigned int)((bitn(s, 17) << 0) | (bitn(s, 21) << 1) | (bitn(s, 23) << 2) | (bitn(s, 26) << 3)); - const unsigned int x4 = (unsigned int)((bitn(s, 28) << 0) | (bitn(s, 29) << 1) | (bitn(s, 31) << 2) | (bitn(s, 33) << 3)); - const unsigned int x5 = (unsigned int)((bitn(s, 34) << 0) | (bitn(s, 43) << 1) | (bitn(s, 44) << 2) | (bitn(s, 46) << 3)); +int fnf(uint64_t s) { + const unsigned int x1 = (unsigned int)((bitn(s, 2) << 0) | (bitn(s, 3) << 1) | (bitn(s, 5) << 2) | (bitn(s, 6) << 3)); + const unsigned int x2 = (unsigned int)((bitn(s, 8) << 0) | (bitn(s, 12) << 1) | (bitn(s, 14) << 2) | (bitn(s, 15) << 3)); + const unsigned int x3 = (unsigned int)((bitn(s, 17) << 0) | (bitn(s, 21) << 1) | (bitn(s, 23) << 2) | (bitn(s, 26) << 3)); + const unsigned int x4 = (unsigned int)((bitn(s, 28) << 0) | (bitn(s, 29) << 1) | (bitn(s, 31) << 2) | (bitn(s, 33) << 3)); + const unsigned int x5 = (unsigned int)((bitn(s, 34) << 0) | (bitn(s, 43) << 1) | (bitn(s, 44) << 2) | (bitn(s, 46) << 3)); - const unsigned int x6 = (unsigned int)((fa(x1) << 0) | (fb(x2) << 1) | (fb(x3) << 2) | (fb(x4) << 3) | (fa(x5) << 4)); + const unsigned int x6 = (unsigned int)((fa(x1) << 0) | (fb(x2) << 1) | (fb(x3) << 2) | (fb(x4) << 3) | (fa(x5) << 4)); - return bitn (0x7907287B, (int) x6); + return bitn(0x7907287B, (int) x6); } -uint32_t hitag2_crypt (uint64_t x) { - const uint32_t ht2_function4a = 0x2C79; // 0010 1100 0111 1001 - const uint32_t ht2_function4b = 0x6671; // 0110 0110 0111 0001 - const uint32_t ht2_function5c = 0x7907287B; // 0111 1001 0000 0111 0010 1000 0111 1011 +uint32_t hitag2_crypt(uint64_t x) { + const uint32_t ht2_function4a = 0x2C79; // 0010 1100 0111 1001 + const uint32_t ht2_function4b = 0x6671; // 0110 0110 0111 0001 + const uint32_t ht2_function5c = 0x7907287B; // 0111 1001 0000 0111 0010 1000 0111 1011 - uint32_t bitindex; + uint32_t bitindex; - bitindex = (ht2_function4a >> pickbits2_2(x, 1, 4)) & 1; - bitindex |= ((ht2_function4b << 1) >> pickbits1_1_2(x, 7, 11, 13)) & 0x02; - bitindex |= ((ht2_function4b << 2) >> pickbits1x4(x, 16, 20, 22, 25)) & 0x04; - bitindex |= ((ht2_function4b << 3) >> pickbits2_1_1(x, 27, 30, 32)) & 0x08; - bitindex |= ((ht2_function4a << 4) >> pickbits1_2_1(x, 33, 42, 45)) & 0x10; + bitindex = (ht2_function4a >> pickbits2_2(x, 1, 4)) & 1; + bitindex |= ((ht2_function4b << 1) >> pickbits1_1_2(x, 7, 11, 13)) & 0x02; + bitindex |= ((ht2_function4b << 2) >> pickbits1x4(x, 16, 20, 22, 25)) & 0x04; + bitindex |= ((ht2_function4b << 3) >> pickbits2_1_1(x, 27, 30, 32)) & 0x08; + bitindex |= ((ht2_function4a << 4) >> pickbits1_2_1(x, 33, 42, 45)) & 0x10; - #if defined(DEBUG_HITAG2) && DEBUG_HITAG2 == 1 - printf ("hitag2_crypt bitindex = %02x\n", bitindex); - #endif +#if defined(DEBUG_HITAG2) && DEBUG_HITAG2 == 1 + printf("hitag2_crypt bitindex = %02x\n", bitindex); +#endif - return (ht2_function5c >> bitindex) & 1; + return (ht2_function5c >> bitindex) & 1; } /* @@ -77,39 +74,39 @@ uint32_t hitag2_crypt (uint64_t x) { * uint32_t steps - number of bits requested, (capped at 32) */ uint32_t hitag2_nstep(Hitag_State *pstate, uint32_t steps) { - uint64_t cur_state = pstate->shiftreg; - uint32_t result = 0; - uint64_t lfsr = pstate->lfsr; + uint64_t cur_state = pstate->shiftreg; + uint32_t result = 0; + uint64_t lfsr = pstate->lfsr; - if (steps == 0) return 0; + if (steps == 0) return 0; - do { - // update shift registers - if (lfsr & 1) { - cur_state = (cur_state >> 1) | 0x800000000000; - lfsr = (lfsr >> 1) ^ 0xB38083220073; + do { + // update shift registers + if (lfsr & 1) { + cur_state = (cur_state >> 1) | 0x800000000000; + lfsr = (lfsr >> 1) ^ 0xB38083220073; - // accumulate next bit of crypto - result = (result << 1) | hitag2_crypt(cur_state); - } else { - cur_state >>= 1; - lfsr >>= 1; + // accumulate next bit of crypto + result = (result << 1) | hitag2_crypt(cur_state); + } else { + cur_state >>= 1; + lfsr >>= 1; - result = (result << 1) | hitag2_crypt(cur_state); - } - } while (--steps); + result = (result << 1) | hitag2_crypt(cur_state); + } + } while (--steps); - #if defined(DEBUG_HITAG2) && DEBUG_HITAG2 == 1 - #ifdef _ISOC99_SOURCE - printf ("hitag2_nstep cur_state = %012I64x, result %02x\n", cur_state, result); - #else - printf ("hitag2_nstep cur_state = %012" STR(OFF_FORMAT_X) ", result %02x\n", cur_state, result); - #endif - #endif // DEBUG_HITAG2 +#if defined(DEBUG_HITAG2) && DEBUG_HITAG2 == 1 +#ifdef _ISOC99_SOURCE + printf("hitag2_nstep cur_state = %012I64x, result %02x\n", cur_state, result); +#else + printf("hitag2_nstep cur_state = %012" STR(OFF_FORMAT_X) ", result %02x\n", cur_state, result); +#endif +#endif // DEBUG_HITAG2 - pstate->shiftreg = cur_state; - pstate->lfsr = lfsr; - return result; + pstate->shiftreg = cur_state; + pstate->lfsr = lfsr; + return result; } /* @@ -119,140 +116,136 @@ uint32_t hitag2_nstep(Hitag_State *pstate, uint32_t steps) { * uint32_t serialnum - 32 bit tag serial number * uint32_t initvector - 32 bit random IV from reader, part of tag authentication */ -void hitag2_init (Hitag_State *pstate, uint64_t sharedkey, uint32_t serialnum, uint32_t initvector) -{ - // init state, from serial number and lowest 16 bits of shared key - uint64_t cur_state = ((sharedkey & 0xFFFF) << 32) | serialnum; +void hitag2_init(Hitag_State *pstate, uint64_t sharedkey, uint32_t serialnum, uint32_t initvector) { + // init state, from serial number and lowest 16 bits of shared key + uint64_t cur_state = ((sharedkey & 0xFFFF) << 32) | serialnum; - // mix the initialisation vector and highest 32 bits of the shared key - initvector ^= (uint32_t) (sharedkey >> 16); + // mix the initialisation vector and highest 32 bits of the shared key + initvector ^= (uint32_t)(sharedkey >> 16); - // move 16 bits from (IV xor Shared Key) to top of uint64_t state - // these will be XORed in turn with output of the crypto function - cur_state |= (uint64_t) initvector << 48; - initvector >>= 16; + // move 16 bits from (IV xor Shared Key) to top of uint64_t state + // these will be XORed in turn with output of the crypto function + cur_state |= (uint64_t) initvector << 48; + initvector >>= 16; - // unrolled loop is faster on PIC32 (MIPS), do 32 times - // shift register, then calc new bit - cur_state >>= 1; + // unrolled loop is faster on PIC32 (MIPS), do 32 times + // shift register, then calc new bit + cur_state >>= 1; - int i; + int i; - for (i = 0; i < 16; i++) cur_state = (cur_state >> 1) ^ (uint64_t) hitag2_crypt(cur_state) << 46; + for (i = 0; i < 16; i++) cur_state = (cur_state >> 1) ^ (uint64_t) hitag2_crypt(cur_state) << 46; - // highest 16 bits of IV XOR Shared Key - cur_state |= (uint64_t) initvector << 47; + // highest 16 bits of IV XOR Shared Key + cur_state |= (uint64_t) initvector << 47; - for (i = 0; i < 15; i++) cur_state = (cur_state >> 1) ^ (uint64_t) hitag2_crypt(cur_state) << 46; + for (i = 0; i < 15; i++) cur_state = (cur_state >> 1) ^ (uint64_t) hitag2_crypt(cur_state) << 46; - cur_state ^= (uint64_t) hitag2_crypt (cur_state) << 47; + cur_state ^= (uint64_t) hitag2_crypt(cur_state) << 47; - pstate->shiftreg = cur_state; - #if defined(DEBUG_HITAG2) && DEBUG_HITAG2 == 1 - #ifdef _ISOC99_SOURCE - printf ("hitag2_init shiftreg = %012I64x\n", pstate->shiftreg); - #else - printf ("hitag2_init shiftreg = %012" STR(OFF_FORMAT_X) "\n", pstate->shiftreg); - #endif - #endif // DEBUG_HITAG2 + pstate->shiftreg = cur_state; +#if defined(DEBUG_HITAG2) && DEBUG_HITAG2 == 1 +#ifdef _ISOC99_SOURCE + printf("hitag2_init shiftreg = %012I64x\n", pstate->shiftreg); +#else + printf("hitag2_init shiftreg = %012" STR(OFF_FORMAT_X) "\n", pstate->shiftreg); +#endif +#endif // DEBUG_HITAG2 - /* naive version for reference, LFSR has 16 taps - pstate->lfsr = state ^ (state >> 2) ^ (state >> 3) ^ (state >> 6) - ^ (state >> 7) ^ (state >> 8) ^ (state >> 16) ^ (state >> 22) - ^ (state >> 23) ^ (state >> 26) ^ (state >> 30) ^ (state >> 41) - ^ (state >> 42) ^ (state >> 43) ^ (state >> 46) ^ (state >> 47); - */ + /* naive version for reference, LFSR has 16 taps + pstate->lfsr = state ^ (state >> 2) ^ (state >> 3) ^ (state >> 6) + ^ (state >> 7) ^ (state >> 8) ^ (state >> 16) ^ (state >> 22) + ^ (state >> 23) ^ (state >> 26) ^ (state >> 30) ^ (state >> 41) + ^ (state >> 42) ^ (state >> 43) ^ (state >> 46) ^ (state >> 47); + */ - // optimise with one 64-bit intermediate - uint64_t temp = cur_state ^ (cur_state >> 1); + // optimise with one 64-bit intermediate + uint64_t temp = cur_state ^ (cur_state >> 1); - pstate->lfsr = cur_state ^ (cur_state >> 6) ^ (cur_state >> 16) ^ + pstate->lfsr = cur_state ^ (cur_state >> 6) ^ (cur_state >> 16) ^ (cur_state >> 26) ^ (cur_state >> 30) ^ (cur_state >> 41) ^ (temp >> 2) ^ (temp >> 7) ^ (temp >> 22) ^ (temp >> 42) ^ (temp >> 46); - #if defined(DEBUG_HITAG2) && DEBUG_HITAG2 == 1 - #ifdef _ISOC99_SOURCE - printf ("hitag2_init lfsr = %012I64x\n", pstate->lfsr); - #else - printf ("hitag2_init lfsr = %012" STR(OFF_FORMAT_X) "\n", pstate->lfsr); - #endif - #endif // DEBUG_HITAG2 +#if defined(DEBUG_HITAG2) && DEBUG_HITAG2 == 1 +#ifdef _ISOC99_SOURCE + printf("hitag2_init lfsr = %012I64x\n", pstate->lfsr); +#else + printf("hitag2_init lfsr = %012" STR(OFF_FORMAT_X) "\n", pstate->lfsr); +#endif +#endif // DEBUG_HITAG2 } // try state // todo, changes arguments, only what is needed -bool try_state (uint64_t s, uint32_t uid, uint32_t aR2, uint32_t nR1, uint32_t nR2, uint64_t *key) -{ - #if defined(DEBUG_HITAG2) && DEBUG_HITAG2 == 1 - printf ("s : %lu, uid: %u, aR2: %u, nR1: %u, nR2: %u\n", s, uid, aR2, nR1, nR2); - fflush (stdout); - #endif +bool try_state(uint64_t s, uint32_t uid, uint32_t aR2, uint32_t nR1, uint32_t nR2, uint64_t *key) { +#if defined(DEBUG_HITAG2) && DEBUG_HITAG2 == 1 + printf("s : %lu, uid: %u, aR2: %u, nR1: %u, nR2: %u\n", s, uid, aR2, nR1, nR2); + fflush(stdout); +#endif - Hitag_State hstate; - uint64_t keyrev, nR1xk; - uint32_t b = 0; + Hitag_State hstate; + uint64_t keyrev, nR1xk; + uint32_t b = 0; - hstate.shiftreg = s; + hstate.shiftreg = s; - //rollback(&hstate, 2); - hstate.shiftreg = (uint64_t)(((hstate.shiftreg << 1) & 0xffffffffffff) | (uint64_t)fnR(hstate.shiftreg)); - hstate.shiftreg = (uint64_t)(((hstate.shiftreg << 1) & 0xffffffffffff) | (uint64_t)fnR(hstate.shiftreg)); + //rollback(&hstate, 2); + hstate.shiftreg = (uint64_t)(((hstate.shiftreg << 1) & 0xffffffffffff) | (uint64_t)fnR(hstate.shiftreg)); + hstate.shiftreg = (uint64_t)(((hstate.shiftreg << 1) & 0xffffffffffff) | (uint64_t)fnR(hstate.shiftreg)); - #if defined(DEBUG_HITAG2) && DEBUG_HITAG2 == 1 - printf ("shiftreg : %lu\n", hstate.shiftreg); - fflush (stdout); - #endif +#if defined(DEBUG_HITAG2) && DEBUG_HITAG2 == 1 + printf("shiftreg : %lu\n", hstate.shiftreg); + fflush(stdout); +#endif - // recover key - keyrev = hstate.shiftreg & 0xffff; - nR1xk = (hstate.shiftreg >> 16) & 0xffffffff; + // recover key + keyrev = hstate.shiftreg & 0xffff; + nR1xk = (hstate.shiftreg >> 16) & 0xffffffff; - #if defined(DEBUG_HITAG2) && DEBUG_HITAG2 == 1 - printf ("keyrev: %lu, nR1xk: %lu\n", keyrev, nR1xk); - fflush (stdout); - #endif +#if defined(DEBUG_HITAG2) && DEBUG_HITAG2 == 1 + printf("keyrev: %lu, nR1xk: %lu\n", keyrev, nR1xk); + fflush(stdout); +#endif - for (int i = 0; i < 32; i++) - { - hstate.shiftreg = ((hstate.shiftreg) << 1) | ((uid >> (31 - i)) & 0x1); - b = (b << 1) | (unsigned int) fnf(hstate.shiftreg); - } + for (int i = 0; i < 32; i++) { + hstate.shiftreg = ((hstate.shiftreg) << 1) | ((uid >> (31 - i)) & 0x1); + b = (b << 1) | (unsigned int) fnf(hstate.shiftreg); + } - #if defined(DEBUG_HITAG2) && DEBUG_HITAG2 == 1 - printf ("shiftreg: %lu\n", hstate.shiftreg); - fflush (stdout); - #endif +#if defined(DEBUG_HITAG2) && DEBUG_HITAG2 == 1 + printf("shiftreg: %lu\n", hstate.shiftreg); + fflush(stdout); +#endif - keyrev |= (nR1xk ^ nR1 ^ b) << 16; + keyrev |= (nR1xk ^ nR1 ^ b) << 16; - #if defined(DEBUG_HITAG2) && DEBUG_HITAG2 == 1 - printf ("keyrev: %lu\n", keyrev); - fflush (stdout); - #endif +#if defined(DEBUG_HITAG2) && DEBUG_HITAG2 == 1 + printf("keyrev: %lu\n", keyrev); + fflush(stdout); +#endif - // test key - hitag2_init (&hstate, keyrev, uid, nR2); - if ((aR2 ^ hitag2_nstep (&hstate, 32)) == 0xffffffff) - { - *key = rev64 (keyrev); + // test key + hitag2_init(&hstate, keyrev, uid, nR2); + if ((aR2 ^ hitag2_nstep(&hstate, 32)) == 0xffffffff) { + *key = rev64(keyrev); - #if DEBUGME >= 2 - #if ENABLE_EMOJ == 1 - printf ("\nKey found ╭☞ "); - #else - printf ("\nKey found: "); - #endif - for (int i = 0; i < 6; i++) { - printf ("%02X", (uint8_t)(*key & 0xff)); - *key = *key >> 8; - } - printf ("\n"); - #endif - return true; - } +#if DEBUGME >= 2 +#if ENABLE_EMOJ == 1 + printf("\nKey found ╭☞ "); +#else + printf("\nKey found: "); +#endif + for (int i = 0; i < 6; i++) { + printf("%02X", (uint8_t)(*key & 0xff)); + *key = *key >> 8; + } + printf("\n"); +#endif + return true; + } - return false; + return false; } //#endif // FORCE_HITAG2_FULL = 0 diff --git a/tools/hitag2crack/crack5opencl/hitag2.h b/tools/hitag2crack/crack5opencl/hitag2.h index cc28e9464..964482c58 100644 --- a/tools/hitag2crack/crack5opencl/hitag2.h +++ b/tools/hitag2crack/crack5opencl/hitag2.h @@ -27,17 +27,16 @@ #define rev32(X) (rev16(X) + (rev16(X >> 16) << 16)) #define rev64(X) (rev32(X) + (rev32(X >> 32) << 32)) -typedef struct -{ - uint64_t shiftreg; // naive shift register, required for nonlinear fn input - uint64_t lfsr; // fast lfsr, used to make software faster +typedef struct { + uint64_t shiftreg; // naive shift register, required for nonlinear fn input + uint64_t lfsr; // fast lfsr, used to make software faster } Hitag_State; // return a single bit from a value -int bitn (uint64_t x, int bit); +int bitn(uint64_t x, int bit); // the sub-function R that rollback depends upon -int fnR (uint64_t x); +int fnR(uint64_t x); // the three filter sub-functions that feed fnf int fa(unsigned int i); @@ -45,7 +44,7 @@ int fa(unsigned int i); int fb(unsigned int i); // the filter function that generates a bit of output from the prng state -int fnf (uint64_t s); +int fnf(uint64_t s); // macros to pick out 4 bits in various patterns of 1s & 2s & make a new number #define pickbits2_2(S, A, B) ( ((S >> A) & 3) | ((S >> (B - 2)) & 0xC) ) @@ -54,7 +53,7 @@ int fnf (uint64_t s); #define pickbits2_1_1(S, A, B, C) ( ((S >> A) & 3) | ((S >> (B - 2)) & 4) | ((S >> (C - 3)) & 8) ) #define pickbits1_2_1(S, A, B, C) ( ((S >> A) & 1) | ((S >> (B - 1)) & 6) | ((S >> (C - 3)) & 8) ) -uint32_t hitag2_crypt (uint64_t x); +uint32_t hitag2_crypt(uint64_t x); /* * Return up to 32 crypto bits. @@ -76,9 +75,9 @@ uint32_t hitag2_nstep(Hitag_State *pstate, uint32_t steps); * uint32_t serialnum - 32 bit tag serial number * uint32_t initvector - 32 bit random IV from reader, part of tag authentication */ -void hitag2_init (Hitag_State *pstate, uint64_t sharedkey, uint32_t serialnum, uint32_t initvector); +void hitag2_init(Hitag_State *pstate, uint64_t sharedkey, uint32_t serialnum, uint32_t initvector); // try_state -bool try_state (uint64_t s, uint32_t uid, uint32_t aR2, uint32_t nR1, uint32_t nR2, uint64_t *key); +bool try_state(uint64_t s, uint32_t uid, uint32_t aR2, uint32_t nR1, uint32_t nR2, uint64_t *key); #endif // HITAG2_H diff --git a/tools/hitag2crack/crack5opencl/ht2crack5opencl.c b/tools/hitag2crack/crack5opencl/ht2crack5opencl.c index 4347e8eef..c1994c153 100644 --- a/tools/hitag2crack/crack5opencl/ht2crack5opencl.c +++ b/tools/hitag2crack/crack5opencl/ht2crack5opencl.c @@ -40,8 +40,8 @@ typedef unsigned int __attribute__((aligned(VECTOR_SIZE))) __attribute__((vector_size(VECTOR_SIZE))) bitslice_value_t; typedef union { - bitslice_value_t value; - uint8_t bytes[MAX_BITSLICES / 8]; + bitslice_value_t value; + uint8_t bytes[MAX_BITSLICES / 8]; } bitslice_t; static bitslice_t keystream[32]; @@ -51,1986 +51,1776 @@ static bitslice_t keystream[32]; static uint16_t candidates[(1 << 20) * 3]; // compute profile constants, from low to high workloads -static unsigned int profiles[11][2] = -{ - { 16384, 5 }, // 0, best for Intel GPU's with Neo - { 8192, 6 }, // 1, only for Intel NEO - { 4096, 7 }, // 2 (old 0) seems the best for all others (also NVIDIA) :D Apple/Intel GPU's stable here - { 2048, 8 }, // 3 (old 1) usefull for any kind of CPU's - { 1024, 9 }, - { 512, 10 }, - { 256, 11 }, - { 128, 12 }, // 7, (old 5) the last good value with NVIDIA GPU's - { 64, 13 }, - { 32, 14 }, - { 16, 15 }, +static unsigned int profiles[11][2] = { + { 16384, 5 }, // 0, best for Intel GPU's with Neo + { 8192, 6 }, // 1, only for Intel NEO + { 4096, 7 }, // 2 (old 0) seems the best for all others (also NVIDIA) :D Apple/Intel GPU's stable here + { 2048, 8 }, // 3 (old 1) usefull for any kind of CPU's + { 1024, 9 }, + { 512, 10 }, + { 256, 11 }, + { 128, 12 }, // 7, (old 5) the last good value with NVIDIA GPU's + { 64, 13 }, + { 32, 14 }, + { 16, 15 }, }; -static uint64_t expand (uint64_t mask, uint64_t value) -{ - uint64_t fill = 0; +static uint64_t expand(uint64_t mask, uint64_t value) { + uint64_t fill = 0; - for (uint64_t bit_index = 0; bit_index < 48; bit_index++) - { - if (mask & 1) - { - fill |= (value & 1) << bit_index; - value >>= 1; - } - mask >>= 1; - } + for (uint64_t bit_index = 0; bit_index < 48; bit_index++) { + if (mask & 1) { + fill |= (value & 1) << bit_index; + value >>= 1; + } + mask >>= 1; + } - return fill; + return fill; } -static void bitslice (const uint64_t value, bitslice_t *restrict bitsliced_value) -{ - // set constants - bitslice_t bs_zeroes, bs_ones; - memset (bs_ones.bytes, 0xff, VECTOR_SIZE); - memset (bs_zeroes.bytes, 0x00, VECTOR_SIZE); +static void bitslice(const uint64_t value, bitslice_t *restrict bitsliced_value) { + // set constants + bitslice_t bs_zeroes, bs_ones; + memset(bs_ones.bytes, 0xff, VECTOR_SIZE); + memset(bs_zeroes.bytes, 0x00, VECTOR_SIZE); - for (size_t bit_idx = 0; bit_idx < 32; bit_idx++) - { - const bool bit = get_bit(32 - 1 - bit_idx, value); - bitsliced_value[bit_idx].value = (bit) ? bs_ones.value : bs_zeroes.value; - } + for (size_t bit_idx = 0; bit_idx < 32; bit_idx++) { + const bool bit = get_bit(32 - 1 - bit_idx, value); + bitsliced_value[bit_idx].value = (bit) ? bs_ones.value : bs_zeroes.value; + } } // convert byte-reversed 8 digit hex to unsigned long -static unsigned long hexreversetoulong (char *hex) { - unsigned long ret = 0L; - unsigned int x; - char i; +static unsigned long hexreversetoulong(char *hex) { + unsigned long ret = 0L; + unsigned int x; + char i; - if (strlen(hex) != 8) - return 0L; + if (strlen(hex) != 8) + return 0L; - for (i = 0 ; i < 4 ; ++i) { - if (sscanf(hex, "%2X", &x) != 1) - return 0L; - ret += ((unsigned long) x) << i * 8; - hex += 2; - } - return ret; + for (i = 0 ; i < 4 ; ++i) { + if (sscanf(hex, "%2X", &x) != 1) + return 0L; + ret += ((unsigned long) x) << i * 8; + hex += 2; + } + return ret; } #if ENABLE_EMOJ == 1 -static const char *emoj[3][2] = { {"∩","つ"}, {"つ","⊃"}, {"⊃","੭ " } }; +static const char *emoj[3][2] = { {"∩", "つ"}, {"つ", "⊃"}, {"⊃", "੭ " } }; #endif __attribute__((noreturn)) -static void usage (char *name) -{ - printf ("%s [options] {UID} {nR1} {aR1} {nR2} {aR2}\n\n" \ - "Options:\n" - "-p : select OpenCL Platform(s). Multiple allowed (1,2,3,etc.). [Default: all]\n" - "-d : select OpenCL Device(s). Multiple allowed (1,2,3,etc.). [Default: all]\n" - "-D : select OpenCL Device Type. 0: GPU, 1: CPU, 2: all. [Default: GPU]\n" - "-S : select the thread scheduler type. 0: sequential, 1: asynchronous. [Default 1]\n" - "-P : select the Profile, from 0 to 10. [Default: auto-tuning]\n" - "-F : force verify key with OpenCL instead of CPU. [Default: disabled]\n" - "-Q : select queue engine. 0: forward, 1: reverse, 2: random. [Default: 0]\n" - "-s : show the list of OpenCL platforms/devices, then exit\n" - "-V : enable debug messages\n" - "-v : show the version\n" - "-h : show this help\n\n", name); +static void usage(char *name) { + printf("%s [options] {UID} {nR1} {aR1} {nR2} {aR2}\n\n" \ + "Options:\n" + "-p : select OpenCL Platform(s). Multiple allowed (1,2,3,etc.). [Default: all]\n" + "-d : select OpenCL Device(s). Multiple allowed (1,2,3,etc.). [Default: all]\n" + "-D : select OpenCL Device Type. 0: GPU, 1: CPU, 2: all. [Default: GPU]\n" + "-S : select the thread scheduler type. 0: sequential, 1: asynchronous. [Default 1]\n" + "-P : select the Profile, from 0 to 10. [Default: auto-tuning]\n" + "-F : force verify key with OpenCL instead of CPU. [Default: disabled]\n" + "-Q : select queue engine. 0: forward, 1: reverse, 2: random. [Default: 0]\n" + "-s : show the list of OpenCL platforms/devices, then exit\n" + "-V : enable debug messages\n" + "-v : show the version\n" + "-h : show this help\n\n", name); - printf ("Example, select devices 1, 2 and 3 using platform 1 and 2, with random queue engine:\n\n" - "%s -D 2 -Q 2 -p 1,2 -d 1,2,3 2ab12bf2 4B71E49D 6A606453 D79BD94B 16A2255B\n\n", name); + printf("Example, select devices 1, 2 and 3 using platform 1 and 2, with random queue engine:\n\n" + "%s -D 2 -Q 2 -p 1,2 -d 1,2,3 2ab12bf2 4B71E49D 6A606453 D79BD94B 16A2255B\n\n", name); - exit (8); + exit(8); } -static bool parse_arg (char * restrict in, unsigned int *out, unsigned int *out_cnt, const int opt_type) -{ - unsigned int cnt = 0; +static bool parse_arg(char *restrict in, unsigned int *out, unsigned int *out_cnt, const int opt_type) { + unsigned int cnt = 0; - if (in == NULL) - { - out[cnt++] = 0xff; - *out_cnt = cnt; - } - else - { - if (strchr (in, ',')) - { - // multiple values - char *saveptr = NULL; - char *next = strtok_r (in, ",", &saveptr); + if (in == NULL) { + out[cnt++] = 0xff; + *out_cnt = cnt; + } else { + if (strchr(in, ',')) { + // multiple values + char *saveptr = NULL; + char *next = strtok_r(in, ",", &saveptr); - do - { - unsigned int tmp_sel = (unsigned int) strtoul (next, NULL, 10); - if (errno == EINVAL || errno == ERANGE || - (tmp_sel < 1 || tmp_sel > 16)) - { - printf ("! Invalid %s argument\n", (opt_type == 0) ? "'platform'" : "'device'"); - return false; - } + do { + unsigned int tmp_sel = (unsigned int) strtoul(next, NULL, 10); + if (errno == EINVAL || errno == ERANGE || + (tmp_sel < 1 || tmp_sel > 16)) { + printf("! Invalid %s argument\n", (opt_type == 0) ? "'platform'" : "'device'"); + return false; + } - out[cnt++] = tmp_sel; + out[cnt++] = tmp_sel; - } while ((next = strtok_r (NULL, ",", &saveptr)) != NULL); + } while ((next = strtok_r(NULL, ",", &saveptr)) != NULL); - *out_cnt = cnt; + *out_cnt = cnt; - // todo: sort, uniq - } - else - { - out[0] = (unsigned int) strtoul (in, NULL, 10); - if (errno == EINVAL || errno == ERANGE) - { - printf ("! Invalid %s argument\n", (opt_type == 0) ? "'platform'" : "'device'"); - return false; - } - *out_cnt = 1; - } - } + // todo: sort, uniq + } else { + out[0] = (unsigned int) strtoul(in, NULL, 10); + if (errno == EINVAL || errno == ERANGE) { + printf("! Invalid %s argument\n", (opt_type == 0) ? "'platform'" : "'device'"); + return false; + } + *out_cnt = 1; + } + } - return true; + return true; } -int main (int argc, char **argv) -{ - opencl_ctx_t ctx; - - uint32_t uid = 0, nR1 = 0, aR1 = 0, nR2 = 0, aR2 = 0; - bool opencl_profiling = 0; - bool force_hitag2_opencl = false; - bool verbose = false; - bool show = false; - - char *platforms_selected = NULL; - char *devices_selected = NULL; - unsigned int device_types_selected = 0; - unsigned int thread_scheduler_type_selected = THREAD_TYPE_ASYNC; - unsigned int profile_selected = 2; - unsigned int queue_type = 0; - - uint32_t target = 0; - uint32_t **matches_found = NULL; - uint64_t **matches = NULL; - - int opt; - - while ((opt = getopt (argc, argv, "p:d:D:S:P:F:Q:svVh")) != -1) - { - switch (opt) - { - case 'p': - // 1, 2, 3, etc .. - platforms_selected = strdup (optarg); - break; - case 'd': - // 1, 2, 3, etc ... - devices_selected = strdup (optarg); - break; - case 'D': - // 0: gpu, 1: cpu, 2: all - device_types_selected = (unsigned int) strtoul (optarg, NULL, 10); - if (device_types_selected > 2) - { - printf ("! Invalid DEVICE TYPE argument (accepted values: from 0 to 2)\n"); - usage (argv[0]); - } - break; - case 'S': - // 0: sequential, 1: async - thread_scheduler_type_selected = (unsigned int) strtoul (optarg, NULL, 10); - break; - case 'P': - profile_selected = (unsigned int) strtoul (optarg, NULL, 10); - if (profile_selected > 10) - { - printf ("! Invalid PROFILE argument (accepted valuee: from 0 to 10)\n"); - usage (argv[0]); - } - break; - case 'F': - force_hitag2_opencl = true; - break; - case 'Q': - // 0: forward, 1: reverse, 2: random - queue_type = (unsigned int) strtoul (optarg, NULL, 10); - if (queue_type != QUEUE_TYPE_FORWARD && queue_type != QUEUE_TYPE_REVERSE && queue_type != QUEUE_TYPE_RANDOM) - { - printf ("! Invalid QUEUE TYPE argument (accepted values: 0, 1 or 2)\n"); - usage (argv[0]); - } - break; - case 's': - show = true; - break; - case 'V': - verbose = true; - break; - case 'v': - printf ("Version: %s\n", VERSION); - exit (0); - case 'h': - default: - usage (argv[0]); - } - } - - unsigned int plat_sel[16] = { 0 }; - unsigned int plat_cnt = 0; - unsigned int dev_sel[16] = { 0 }; - unsigned int dev_cnt = 0; - - if (!parse_arg (platforms_selected, plat_sel, &plat_cnt, 0)) - { - free (platforms_selected); - usage (argv[0]); - } - - if (!parse_arg (devices_selected, dev_sel, &dev_cnt, 1)) - { - free (platforms_selected); - free (devices_selected); - usage (argv[0]); - } - - free (platforms_selected); - free (devices_selected); - - if (device_types_selected == 0) device_types_selected = CL_DEVICE_TYPE_GPU; - else if (device_types_selected == 1) device_types_selected = CL_DEVICE_TYPE_CPU; - else device_types_selected = CL_DEVICE_TYPE_ALL; - - if (show) - { - plat_sel[0] = 0xff; - dev_sel[0] = 0xff; - device_types_selected = CL_DEVICE_TYPE_ALL; - } - - if (verbose) - { - if (plat_sel[0] == 0xff) printf ("Platforms selected : ALL\n"); - else - { - printf ("Platforms selected : %u", plat_sel[0]); - for (unsigned int i = 1; i < plat_cnt; i++) printf (", %u", plat_sel[i]); - printf ("\n"); - } - - if (dev_sel[0] == 0xff) printf ("Devices selected : ALL\n"); - else - { - printf ("Devices selected : %u", dev_sel[0]); - for (unsigned int i = 1; i < dev_cnt; i++) printf (", %u", dev_sel[i]); - printf ("\n"); - } - - printf ("Device types selected : %s\n", (device_types_selected == CL_DEVICE_TYPE_GPU) ? "GPU" : (device_types_selected == CL_DEVICE_TYPE_CPU) ? "CPU" : "ALL"); - printf ("Scheduler selected : %s\n", (thread_scheduler_type_selected == 0) ? "sequential" : "async"); - printf ("Profile selected : %d\n", profile_selected); - } - - if (!show) - { - if ((argc - optind) < 5) - { - #if DEBUGME > 0 - printf ("! Invalid extra arguments\n"); - #endif - usage (argv[0]); - } - - for (int e = 0; e < 5; optind++, e++) - { - switch (e) - { - case 0: // UID - if (!strncmp (argv[optind], "0x", 2) || !strncmp (argv[optind], "0X", 2)) - { - if (strlen(argv[optind]) != 2+8) { printf ("! Invalid UID length\n"); usage (argv[0]); } - uid = (uint32_t) rev32 (hexreversetoulong(argv[optind] + 2)); - } - else - { - if (strlen(argv[optind]) != 8) { printf ("! Invalid UID length\n"); usage (argv[0]); } - uid = (uint32_t) rev32 (hexreversetoulong(argv[optind])); - } - break; - - case 1: // nR1 - if (!strncmp (argv[optind], "0x", 2) || !strncmp (argv[optind], "0X", 2)) - { - if (strlen(argv[optind]) != 2+8) { printf ("! Invalid nR1 length\n"); usage (argv[0]); } - nR1 = (uint32_t) rev32 (hexreversetoulong(argv[optind] + 2)); - } - else - { - if (strlen(argv[optind]) != 8) { printf ("! Invalid nR1 length\n"); usage (argv[0]); } - nR1 = (uint32_t) rev32 (hexreversetoulong(argv[optind])); - } - break; - - case 2: // aR1 - if (strlen(argv[optind]) != 8) { printf ("! Invalid aR1 length\n"); usage (argv[0]); } - aR1 = (uint32_t) strtoul (argv[optind], NULL, 16); - break; - - case 3: // nR2 - if (!strncmp (argv[optind], "0x", 2) || !strncmp (argv[optind], "0X", 2)) - { - if (strlen(argv[optind]) != 2+8) { printf ("! Invalid nR2 length\n"); usage (argv[0]); } - nR2 = (uint32_t) rev32 (hexreversetoulong(argv[optind] + 2)); - } - else - { - if (strlen(argv[optind]) != 8) { printf ("! Invalid nR2 length\n"); usage (argv[0]); } - nR2 = (uint32_t) rev32 (hexreversetoulong(argv[optind])); - } - break; - - case 4: // aR2 - if (strlen(argv[optind]) != 8) { printf ("! Invalid aR2 length\n"); usage (argv[0]); } - aR2 = (uint32_t) strtoul (argv[optind], NULL, 16); - break; - - default: // skip invalid instead of show usage and exit - optind = argc; - break; - } - } - } - - memset (&ctx, 0, sizeof (opencl_ctx_t)); - memset (keystream, 0, sizeof (keystream)); - memset (candidates, 0, sizeof (candidates)); - - ctx.profiling = opencl_profiling; - ctx.thread_sched_type = (short) thread_scheduler_type_selected; - ctx.force_hitag2_opencl = force_hitag2_opencl; - - uint32_t checks[4] = { uid, aR2, nR1, nR2 }; - - if (!show) - { - if (verbose) printf ("uid: %u, aR2: %u, nR1: %u, nR2: %u\n", checks[0], checks[1], checks[2], checks[3]); - - target = ~aR1; - // bitslice inverse target bits - bitslice (~target, keystream); - - size_t layer_0_found = 0; - - // compute layer 0 output - for (size_t i0 = 0; i0 < 1 << 20; i0++) - { - uint64_t state0 = expand (0x5806b4a2d16c, i0); - - if (f(state0) == target >> 31) - { - // using uint64_t - // candidates[layer_0_found++] = state0; - // or - // cf kernel, state is now split in 3 shorts >> 2 - candidates[(layer_0_found * 3) + 0] = (uint16_t)((state0 >> (32 + 2)) & 0xffff); - candidates[(layer_0_found * 3) + 1] = (uint16_t)((state0 >> (16 + 2)) & 0xffff); - candidates[(layer_0_found * 3) + 2] = (uint16_t)((state0 >> (0 + 2)) & 0xffff); - layer_0_found++; - } - } - - #if DEBUGME >= 1 - printf ("[debug] layer_0_found: %zu\n", layer_0_found); - #endif - } - - // powered by dolphin's macros :) - int freeListIdx = 0; - - // todo, calculate the max number of allocations to remove 0x40 - void **freeList = (void **) malloc (0x40 * sizeof(void *)); - if (!freeList) - { - printf ("Error: malloc (freeList) failed (%d): %s\n", errno, strerror (errno)); - exit (3); - } - - if (!show) - { - // load OpenCL kernel source - struct stat st; - const char *opencl_kernel = "ht2crack5opencl_kernel.cl"; - - int fd = open (opencl_kernel, O_RDONLY); - if (fd <= 0) { - printf ("Error: open (%s) failed (%d): %s\n", opencl_kernel, errno, strerror (errno)); - exit (3); - } - - if (fstat (fd, &st)) { - printf ("Error: stat (%s) failed (%d): %s\n", opencl_kernel, errno, strerror (errno)); - close (fd); - exit (3); - } - - ctx.kernelSource_len = (size_t) st.st_size; - ctx.kernelSource[0] = (char *) calloc (ctx.kernelSource_len + 1, sizeof (char)); // size + \0 - if (!ctx.kernelSource[0]) { - printf ("Error: calloc (ctx.kernelSource[0]) failed (%d): %s\n", errno, strerror (errno)); - exit (3); - } - - MEMORY_FREE_ADD(ctx.kernelSource[0]) - - if (read (fd, ctx.kernelSource[0], ctx.kernelSource_len) < (ssize_t) ctx.kernelSource_len) - { - printf ("Error: read (%s) failed (%d): %s\n", opencl_kernel, errno, strerror (errno)); - close (fd); - MEMORY_FREE_ALL - exit (3); - } - - ctx.kernelSource[0][ctx.kernelSource_len] = '\0'; - - close (fd); - } - - // now discover and set up compute device(s) - int err = 0; - cl_uint ocl_platform_cnt = 0; - unsigned int ocl_platform_max = MAX_OPENCL_DEVICES; // 16 - - cl_platform_id *ocl_platforms = (cl_platform_id *) calloc (ocl_platform_max, sizeof (cl_platform_id)); - if (!ocl_platforms) - { - printf ("Error: calloc (ocl_platforms) failed (%d): %s\n", errno, strerror (errno)); - MEMORY_FREE_ALL - exit (2); - } - - MEMORY_FREE_ADD(ocl_platforms) - - // enum platforms - err = clGetPlatformIDs (ocl_platform_max, ocl_platforms, &ocl_platform_cnt); - if (err != CL_SUCCESS) { - printf ("Error: clGetPlatformIDs() failed (%d)\n", err); - MEMORY_FREE_ALL - exit (2); - } - - if (ocl_platform_cnt == 0) { - printf ("No platforms found, exit\n"); - MEMORY_FREE_ALL - exit (2); - } - - // allocate memory to hold info about platforms/devices - compute_platform_ctx_t *cd_ctx = (compute_platform_ctx_t *) calloc (ocl_platform_cnt, sizeof (compute_platform_ctx_t)); - if (!cd_ctx) { - printf ("Error: calloc (compute_platform_ctx_t) failed (%d): %s\n", errno, strerror (errno)); - MEMORY_FREE_ALL - exit (err); - } - - MEMORY_FREE_ADD(cd_ctx) - - cl_platform_info ocl_platforms_info[3] = { CL_PLATFORM_NAME, CL_PLATFORM_VENDOR, CL_PLATFORM_VERSION }; - unsigned int ocl_platforms_info_cnt = sizeof (ocl_platforms_info) / sizeof (cl_platform_info); - - cl_device_info ocl_devices_info[8] = { CL_DEVICE_TYPE, CL_DEVICE_NAME, CL_DEVICE_VERSION, CL_DRIVER_VERSION, CL_DEVICE_VENDOR, CL_DEVICE_LOCAL_MEM_TYPE, CL_DEVICE_MAX_WORK_ITEM_SIZES, CL_DEVICE_MAX_COMPUTE_UNITS }; - unsigned int ocl_devices_info_cnt = sizeof (ocl_devices_info) / sizeof (cl_device_info); - - unsigned int info_idx = 0; - size_t tmp_len = 0; - char *tmp_buf = NULL; - - unsigned int global_device_id = 0; - size_t selected_platforms_cnt = 0; - size_t selected_devices_cnt = 0; - - if (show) verbose = true; - - if (verbose) printf ("- Found %u OpenCL Platform(s)\n", ocl_platform_cnt); - - for (cl_uint platform_idx = 0; platform_idx < ocl_platform_cnt; platform_idx++) - { - cd_ctx[platform_idx].platform_id = ocl_platforms[platform_idx]; - cd_ctx[platform_idx].selected = plat_dev_enabled (platform_idx, plat_sel, plat_cnt, 0, 0); - - if (cd_ctx[platform_idx].selected) selected_platforms_cnt++; - - if (verbose) printf ("\n-- Platform ID: %d\n", platform_idx+1); - - for (info_idx = 0; info_idx < ocl_platforms_info_cnt; info_idx++) - { - cl_platform_info ocl_info = ocl_platforms_info[info_idx]; - - err = clGetPlatformInfo (cd_ctx[platform_idx].platform_id, ocl_info, 0, NULL, &tmp_len); - if (err != CL_SUCCESS) { - printf ("Error: clGetPlatformInfo(param size) failed (%d)\n", err); - MEMORY_FREE_ALL - exit (2); - } - - if (tmp_len > 0) - { - if (!(tmp_buf = (char *) calloc (tmp_len, sizeof (char)))) - { - printf ("Error: calloc (ocl_info %u) failed (%d): %s\n", info_idx, errno, strerror (errno)); - MEMORY_FREE_ALL - exit (2); - } - - MEMORY_FREE_ADD(tmp_buf) - - err = clGetPlatformInfo (cd_ctx[platform_idx].platform_id, ocl_info, tmp_len, tmp_buf, 0); - if (err != CL_SUCCESS) { - printf ("Error: clGetPlatformInfo(param) failed (%d)\n", err); - MEMORY_FREE_ALL - exit (2); - } - } - else - { - tmp_len = 4; - if (!(tmp_buf = (char *) calloc (tmp_len, sizeof (char)))) - { - printf ("Error: calloc (ocl_info %u) failed (%d): %s\n", info_idx, errno, strerror (errno)); - MEMORY_FREE_ALL - exit (2); - } - - MEMORY_FREE_ADD(tmp_buf) - - strncpy (tmp_buf, "N/A\0", tmp_len); - } - - if (verbose) - { - const char *tmp_info_desc = (info_idx == 0) ? "Name" : (info_idx == 1) ? "Vendor" : "Version"; - - printf ("%14s: %s\n", tmp_info_desc, tmp_buf); - } - - switch (info_idx) - { - case 0: - strncpy(cd_ctx[platform_idx].name, tmp_buf, tmp_len < 0xff ? tmp_len : 0xff-1); - break; - case 1: - strncpy(cd_ctx[platform_idx].vendor, tmp_buf, tmp_len < 0x40 ? tmp_len : 0x40-1); - break; - case 2: - strncpy(cd_ctx[platform_idx].version, tmp_buf, tmp_len < 0x40 ? tmp_len : 0x40-1); - break; - } - - if (info_idx == 1) - { - // todo: do the same this devices - if (!strncmp (tmp_buf, "NVIDIA", 6)) cd_ctx[platform_idx].is_nv = true; - else if (!strncmp (tmp_buf, "Apple", 5)) { cd_ctx[platform_idx].is_apple = true; cd_ctx[platform_idx].warning = true; } - else if (!strncmp (tmp_buf, "Intel", 5)) cd_ctx[platform_idx].is_intel = true; - } - - MEMORY_FREE_DEL(tmp_buf) - } - - if (!show && verbose) - { - printf ("%14s: %s\n", "Selected", (cd_ctx[platform_idx].selected) ? "yes" : "no"); - if (cd_ctx[platform_idx].warning) printf ("\n%14s: performance will not be optimal using this platform\n\n", "=====> Warning"); - } - - // enum devices with this platform - unsigned int ocl_device_cnt = 0; - unsigned int ocl_device_max = MAX_OPENCL_DEVICES; - - cl_device_id *ocl_devices = (cl_device_id *) calloc (ocl_device_max, sizeof (cl_device_id)); - if (!ocl_devices) { - printf ("Error: calloc (ocl_devices) failed (%d): %s\n", errno, strerror (errno)); - MEMORY_FREE_ALL - exit (2); - } - - MEMORY_FREE_ADD(ocl_devices) - - err = clGetDeviceIDs (cd_ctx[platform_idx].platform_id, CL_DEVICE_TYPE_ALL, ocl_device_max, ocl_devices, &ocl_device_cnt); - if (ocl_device_cnt == 0) - { - if (device_types_selected == CL_DEVICE_TYPE_ALL) printf ("No device(s) available with platform id %d\n", platform_idx); - cd_ctx[platform_idx].device_cnt = 0; - continue; - } - - if (err != CL_SUCCESS) { - printf ("Error: clGetDeviceIDs(cnt) failed (%d)\n", err); - MEMORY_FREE_ALL - exit (2); - } - - if (verbose) printf ("%14s: %u\n", "Device(s)", ocl_device_cnt); - - cd_ctx[platform_idx].device_cnt = ocl_device_cnt; - - for (unsigned int device_idx = 0; device_idx < ocl_device_cnt; device_idx++) - { - memset (&cd_ctx[platform_idx].device[device_idx], 0, sizeof (compute_device_ctx_t)); - cl_device_id ocl_device = ocl_devices[device_idx]; - cd_ctx[platform_idx].device[device_idx].platform_id = cd_ctx[platform_idx].platform_id; - - if (verbose) printf ("---- * ID: %u\n", global_device_id+1); - - for (info_idx = 0; info_idx < ocl_devices_info_cnt; info_idx++) - { - cl_device_info ocl_dev_info = ocl_devices_info[info_idx]; - - if (info_idx == 0) - { - cl_device_type device_type; - - err = clGetDeviceInfo (ocl_device, ocl_dev_info, sizeof (cl_device_type), &device_type, 0); - if (err != CL_SUCCESS) { - printf ("Error: clGetDeviceInfo(device_type) failed (%d)\n", err); - MEMORY_FREE_ALL - exit (2); - } - - if (device_type & CL_DEVICE_TYPE_GPU) cd_ctx[platform_idx].device[device_idx].is_gpu = 1; - - if (verbose) printf ("%14s: %s\n", "Device Type", (device_type & CL_DEVICE_TYPE_GPU) ? "GPU" : (device_type & CL_DEVICE_TYPE_CPU ) ? "CPU" : "Other"); - - cd_ctx[platform_idx].device[device_idx].selected = plat_dev_enabled (global_device_id, dev_sel, dev_cnt, (unsigned int) device_type, device_types_selected); - global_device_id++; - if (cd_ctx[platform_idx].device[device_idx].selected) selected_devices_cnt++; - continue; - } - else if (info_idx == 5) - { - cl_device_local_mem_type local_mem_type; - - err = clGetDeviceInfo (ocl_device, ocl_dev_info, sizeof (cl_device_local_mem_type), &local_mem_type, 0); - if (err != CL_SUCCESS) { - printf ("Error: clGetDeviceInfo(local_mem_type) failed (%d)\n", err); - MEMORY_FREE_ALL - exit (2); - } - - if (local_mem_type == CL_LOCAL || local_mem_type == CL_GLOBAL) - { - if (verbose) printf ("%14s: %s\n", "Local Mem Type", (local_mem_type == CL_LOCAL) ? "Local" : "Global"); - - if (cd_ctx[platform_idx].is_apple) - { - if (strncmp (cd_ctx[platform_idx].device[device_idx].vendor, "Intel", 5) != 0) cd_ctx[platform_idx].device[device_idx].have_local_memory = true; - } - else if (cd_ctx[platform_idx].is_nv) cd_ctx[platform_idx].device[device_idx].have_local_memory = true; -/* - // swap the 'if' comment for enable local memory with apple gpu's (my Iris crash, abort 6) - // if (!(!strncmp (cd_ctx[platform_idx].device[device_idx].vendor, "Intel", 5) && cd_ctx[platform_idx].is_apple && !cd_ctx[platform_idx].device[device_idx].is_gpu)) - if (!(!strncmp (cd_ctx[platform_idx].device[device_idx].vendor, "Intel", 5) && cd_ctx[platform_idx].is_apple)) - { - cd_ctx[platform_idx].device[device_idx].have_local_memory = true; - } -*/ - } - else - { - if (verbose) printf ("%14s: None\n", "Local Mem Type"); - } - - if (verbose) printf ("%14s: %s\n", "Local Mem Opt", (cd_ctx[platform_idx].device[device_idx].have_local_memory) ? "yes" : "no"); - - continue; - } - else if (info_idx == 6) - { - size_t wis[3] = { 0 }; - err = clGetDeviceInfo (ocl_device, ocl_dev_info, sizeof (size_t) * 3, wis, 0); - if (err != CL_SUCCESS) { - printf ("Error: clGetDeviceInfo(work_items_size) failed (%d)\n", err); - MEMORY_FREE_ALL - exit (2); - } - - if (verbose) printf ("%14s: (%zu,%zu,%zu)\n", "Max Work-Items", wis[0], wis[1], wis[2]); - - #if APPLE_GPU_BROKEN == 1 - if (wis[1] < GLOBAL_WS_1 && cd_ctx[platform_idx].device[device_idx].is_apple_gpu) - { - cd_ctx[platform_idx].device[device_idx].unsupported = true; - } - #endif - continue; - } - else if (info_idx == 7) - { - cl_uint cores = 0; - err = clGetDeviceInfo (ocl_device, ocl_dev_info, sizeof (cl_uint), &cores, 0); - if (err != CL_SUCCESS) { - printf ("Error: clGetDeviceInfo(compute_units) failed (%d)\n", err); - MEMORY_FREE_ALL - exit (2); - } - - if (verbose) printf ("%14s: %u\n", "Compute Units", cores); - - cd_ctx[platform_idx].device[device_idx].compute_units = cores; - continue; - } - - tmp_len = 0; - tmp_buf = NULL; - - err = clGetDeviceInfo (ocl_device, ocl_dev_info, 0, NULL, &tmp_len); - if (err != CL_SUCCESS) { - printf ("Error: clGetDeviceInfo(param size) failed (%d)\n", err); - MEMORY_FREE_ALL - exit (2); - } - - if (tmp_len > 0) - { - if (!(tmp_buf = (char *) calloc (tmp_len, sizeof (char)))) - { - printf ("Error: calloc (ocl_dev_info %u) failed (%d): %s\n", info_idx, errno, strerror (errno)); - MEMORY_FREE_ALL - exit (2); - } - - MEMORY_FREE_ADD(tmp_buf) - - err = clGetDeviceInfo (ocl_device, ocl_dev_info, tmp_len, tmp_buf, 0); - if (err != CL_SUCCESS) { - printf ("Error: clGetDeviceInfo(param) failed (%d)\n", err); - MEMORY_FREE_ALL - exit (2); - } - } - else - { - tmp_len = 4; - if (!(tmp_buf = (char *) calloc (tmp_len, sizeof (char)))) - { - printf ("Error: calloc (ocl_dev_info %u) failed (%d): %s\n", info_idx, errno, strerror (errno)); - MEMORY_FREE_ALL - exit (2); - } - - MEMORY_FREE_ADD(tmp_buf) - - strncpy (tmp_buf, "N/A\0", tmp_len); - } - - if (verbose) - { - const char *tmp_dev_info_desc = (info_idx == 1) ? "Name" : (info_idx == 2) ? "Version" : (info_idx == 3) ? "Driver Version" : "Vendor"; - - printf ("%14s: %s\n", tmp_dev_info_desc, tmp_buf); - } - - switch (info_idx) - { - case 1: - strncpy (cd_ctx[platform_idx].device[device_idx].name, tmp_buf, tmp_len < 0xff ? tmp_len : 0xff-1); - break; - case 2: - strncpy (cd_ctx[platform_idx].device[device_idx].version, tmp_buf, tmp_len < 0x40 ? tmp_len : 0x40-1); - break; - case 3: - strncpy (cd_ctx[platform_idx].device[device_idx].driver_version, tmp_buf, tmp_len < 0x40 ? tmp_len : 0x40-1); - break; - case 4: - strncpy (cd_ctx[platform_idx].device[device_idx].vendor, tmp_buf, tmp_len < 0x40 ? tmp_len : 0x40-1); - break; - } - - if (info_idx == 4) - { - if (!strncmp (tmp_buf, "Intel", 5) && cd_ctx[platform_idx].is_apple) - { - // disable hitag2 with apple platform and not apple device vendor (< Apple M1) - ctx.force_hitag2_opencl = false; - - cd_ctx[platform_idx].device[device_idx].is_apple_gpu = cd_ctx[platform_idx].device[device_idx].is_gpu; - } - - if (!strncmp (tmp_buf, "NVIDIA", 6) && cd_ctx[platform_idx].is_nv) - { - unsigned int sm_maj = 0, sm_min = 0; - - err = clGetDeviceInfo (ocl_device, 0x4000, sizeof (unsigned int), &sm_maj, 0); - err |= clGetDeviceInfo (ocl_device, 0x4001, sizeof (unsigned int), &sm_min, 0); - - if (err != CL_SUCCESS) { - printf ("Error: clGetDeviceInfo(sm_maj/sm_min) failed (%d)\n", err); - MEMORY_FREE_ALL - exit (2); - } - - cd_ctx[platform_idx].device[device_idx].sm_maj = sm_maj; - cd_ctx[platform_idx].device[device_idx].sm_min = sm_min; - - if (verbose) printf ("%14s: %u%u\n", "SM", sm_maj, sm_min); - - if (sm_maj >= 5) // >= Maxwell - { - // https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#logic-and-shift-instructions-lop3 - // Requires sm_50 or higher. - cd_ctx[platform_idx].device[device_idx].have_lop3 = true; - } - else - { - cd_ctx[platform_idx].device[device_idx].warning = true; - } - - cd_ctx[platform_idx].device[device_idx].is_nv = true; - } - else - { - cd_ctx[platform_idx].device[device_idx].warning = true; - } - } - - MEMORY_FREE_DEL(tmp_buf) - } - - if (!show && verbose) printf ("%14s: %s\n", "Selected", (cd_ctx[platform_idx].device[device_idx].selected) ? "yes" : "no"); - - if (cd_ctx[platform_idx].device[device_idx].unsupported) - { - printf ("\n%14s: this device was not supported, beacuse of missing resources\n\n", "=====> Warning"); - continue; - } - - if (cd_ctx[platform_idx].device[device_idx].warning) - { - if (!show && verbose) printf ("\n%14s: performance will not be optimal using this device\n\n", "=====> Warning"); - } - - cd_ctx[platform_idx].device[device_idx].device_id = ocl_device; - } - MEMORY_FREE_DEL(ocl_devices) - } - MEMORY_FREE_DEL(ocl_platforms) - - // new selection engine, need to support multi-gpu system (with the same platform) - - if (verbose) printf ("\n"); - - if (show) - { - MEMORY_FREE_ALL - exit (2); - } - - if (selected_platforms_cnt == 0) - { - printf ("! No platform was selected ...\n"); - MEMORY_FREE_ALL - exit (2); - } - - if (selected_devices_cnt == 0) - { - printf ("! No device(s) was selected ...\n"); - MEMORY_FREE_ALL - exit (2); - } - - size_t w = 0, q = 0, g = 0; - - size_t z = 0; // z is a dolphin's friend - - // show selected devices - - printf ("Selected %zu OpenCL Device(s)\n\n", selected_devices_cnt); - - for (w = 0; w < ocl_platform_cnt; w++) - { - if (!cd_ctx[w].selected) continue; - - for (q = 0; q < cd_ctx[w].device_cnt; q++) - { - if (!cd_ctx[w].device[q].selected) continue; - - printf ("%2zu - %s", z, cd_ctx[w].device[q].name); - if (verbose) - { - printf (" (Lop3 %s, ", (cd_ctx[w].device[q].have_lop3) ? "yes" : "no"); - printf ("Local Memory %s)", (cd_ctx[w].device[q].have_local_memory) ? "yes" : "no"); - } - printf ("\n"); - - z++; - } - } - printf ("\n"); - - if (selected_devices_cnt != z) - { - printf ("BUG: z and selected_devices_cnt are not equal\n"); - MEMORY_FREE_ALL - exit (2); - } - - // time to eat some memory :P - - if (!(ctx.device_ids = (cl_device_id *) calloc (selected_devices_cnt, sizeof (cl_device_id)))) - { - printf ("Error: calloc (ctx.device_ids) failed (%d): %s\n", errno, strerror (errno)); - MEMORY_FREE_ALL - exit (2); - } - - MEMORY_FREE_ADD(ctx.device_ids) - - if (!(ctx.contexts = (cl_context *) calloc (selected_devices_cnt, sizeof (cl_context)))) - { - printf ("Error: calloc (ctx.contexts) failed (%d): %s\n", errno, strerror (errno)); - MEMORY_FREE_ALL - exit (2); - } - - MEMORY_FREE_ADD(ctx.contexts) - - if (!(ctx.commands = (cl_command_queue *) calloc (selected_devices_cnt, sizeof (cl_command_queue)))) - { - printf ("Error: calloc (ctx.commands) failed (%d): %s\n", errno, strerror (errno)); - MEMORY_FREE_ALL - exit (2); - } - - MEMORY_FREE_ADD(ctx.commands) - - if (!(ctx.programs = (cl_program *) calloc (selected_devices_cnt, sizeof (cl_program)))) - { - printf ("Error: calloc (ctx.programs) failed (%d): %s\n", errno, strerror (errno)); - MEMORY_FREE_ALL - exit (2); - } - - MEMORY_FREE_ADD(ctx.programs) - - if (!(ctx.kernels = (cl_kernel *) calloc (selected_devices_cnt, sizeof (cl_kernel)))) - { - printf ("Error: calloc (ctx.kernels) failed (%d): %s\n", errno, strerror (errno)); - MEMORY_FREE_ALL - exit (2); - } - - MEMORY_FREE_ADD(ctx.kernels) - - if (!(matches = (uint64_t **) calloc (selected_devices_cnt, sizeof (uint64_t *)))) - { - printf ("Error: calloc (**matches) failed (%d): %s\n", errno, strerror (errno)); - MEMORY_FREE_ALL - exit (2); - } - - MEMORY_FREE_ADD(matches) - - if (!(matches_found = (uint32_t **) calloc (selected_devices_cnt, sizeof (uint32_t *)))) - { - printf ("Error: calloc (**matches_found) failed (%d): %s\n", errno, strerror (errno)); - MEMORY_FREE_ALL - exit (2); - } - - MEMORY_FREE_ADD(matches_found) - - if (!(ctx.keystreams = (cl_mem *) calloc (selected_devices_cnt, sizeof (cl_mem)))) - { - printf ("Error: calloc (ctx.keystreams) failed (%d): %s\n", errno, strerror (errno)); - MEMORY_FREE_ALL - exit (2); - } - - MEMORY_FREE_ADD(ctx.keystreams) - - if (!(ctx.candidates = (cl_mem *) calloc (selected_devices_cnt, sizeof (cl_mem)))) - { - printf ("Error: calloc (ctx.candidates) failed (%d): %s\n", errno, strerror (errno)); - MEMORY_FREE_ALL - exit (2); - } - - MEMORY_FREE_ADD(ctx.candidates) - - if (!(ctx.matches = (cl_mem *) calloc (selected_devices_cnt, sizeof (cl_mem)))) - { - printf ("Error: calloc (ctx.matches) failed (%d): %s\n", errno, strerror (errno)); - MEMORY_FREE_ALL - exit (2); - } - - MEMORY_FREE_ADD(ctx.matches) - - if (!(ctx.matches_found = (cl_mem *) calloc (selected_devices_cnt, sizeof (cl_mem)))) - { - printf ("Error: calloc (ctx.matches_found) failed (%d): %s\n", errno, strerror (errno)); - MEMORY_FREE_ALL - exit (2); - } - - MEMORY_FREE_ADD(ctx.matches_found) - - if (ctx.force_hitag2_opencl) - { - if (!(ctx.checks = (cl_mem *) calloc (selected_devices_cnt, sizeof (cl_mem)))) - { - printf ("Error: calloc (ctx.checks) failed (%d): %s\n", errno, strerror (errno)); - MEMORY_FREE_ALL - exit (2); - } - - MEMORY_FREE_ADD(ctx.checks) - } - - if (!(ctx.global_ws = (size_t *) calloc (selected_devices_cnt, sizeof (size_t)))) - { - printf ("Error: calloc (ctx.global_ws) failed (%d): %s\n", errno, strerror (errno)); - MEMORY_FREE_ALL - exit (2); - } - - MEMORY_FREE_ADD(ctx.global_ws) - - if (!(ctx.local_ws = (size_t *) calloc (selected_devices_cnt, sizeof (size_t)))) - { - printf ("Error: calloc (ctx.local_ws) failed (%d): %s\n", errno, strerror (errno)); - MEMORY_FREE_ALL - exit (2); - } - - MEMORY_FREE_ADD(ctx.local_ws) - - if (!(ctx.profiles = (int *) calloc (selected_devices_cnt, sizeof (int)))) - { - printf ("Error: calloc (ctx.profiles) failed (%d): %s\n", errno, strerror (errno)); - MEMORY_FREE_ALL - exit (2); - } - - MEMORY_FREE_ADD(ctx.profiles) - - // show buidlog in case of error - // todo: only for device models - unsigned int build_errors = 0; - unsigned int build_logs = 0; - - cl_command_queue_properties queue_properties = 0; - - if (opencl_profiling) queue_properties = CL_QUEUE_PROFILING_ENABLE; - - // setup, phase 1 - - z = 0; // dolphin - - for (w = 0; w < ocl_platform_cnt; w++) - { - if (!cd_ctx[w].selected) continue; - - for (q = 0; q < cd_ctx[w].device_cnt; q++) - { - if (!cd_ctx[w].device[q].selected) continue; - - ctx.device_ids[z] = cd_ctx[w].device[q].device_id; - - // create the opencl context with the array - ctx.contexts[z] = clCreateContext (NULL, 1, &ctx.device_ids[z], NULL, NULL, &err); - if (!ctx.contexts[z] || err != CL_SUCCESS) { - printf ("[%zu] Error: clCreateContext() failed (%d)\n", z, err); - MEMORY_FREE_OPENCL(ctx, z) - MEMORY_FREE_LIST(matches,z) - MEMORY_FREE_LIST(matches_found, z) - MEMORY_FREE_ALL - exit (2); - } - - // create comman queues for each selected devices - ctx.commands[z] = clCreateCommandQueue(ctx.contexts[z], ctx.device_ids[z], queue_properties, &err); - if (!ctx.commands[z] || err != CL_SUCCESS) - { - printf ("[%zu] Error: clCreateCommandQueue() failed (%d)\n", z, err); - MEMORY_FREE_OPENCL(ctx, z) - MEMORY_FREE_LIST(matches,z) - MEMORY_FREE_LIST(matches_found, z) - MEMORY_FREE_ALL - exit (2); - } - - // from clang: - // warning: cast from 'char *(*)[1]' to 'const char **' increases required alignment from 1 to 8 - const char *a = (const char *)ctx.kernelSource[0]; - const char **ks = &a; - - // create the compute program from the source buffer - //ctx.programs[z] = clCreateProgramWithSource(ctx.contexts[z], 1, (const char **) &ctx.kernelSource, &ctx.kernelSource_len, &err); - ctx.programs[z] = clCreateProgramWithSource(ctx.contexts[z], 1, ks, &ctx.kernelSource_len, &err); - if (!ctx.programs[z] || err != CL_SUCCESS) - { - printf ("[%zu] Error: clCreateProgramWithSource() failed (%d)\n", z, err); - MEMORY_FREE_OPENCL(ctx, z) - MEMORY_FREE_LIST(matches,z) - MEMORY_FREE_LIST(matches_found, z) - MEMORY_FREE_ALL - exit (2); - } - - // build the program executable - bool have_local_memory = false; - size_t blen = 0; - char build_options[0x100]; - - memset (build_options, 0, sizeof (build_options)); - - strncpy (build_options, "-Werror", 8); - blen += 7; - - if (cd_ctx[w].device[q].have_lop3) // enable lop3 - { - strncpy (build_options+blen, " -D HAVE_LOP3", 14); - blen += 13; - } - - if (ctx.force_hitag2_opencl) - { - // force using hitag2 key validation with OpenCL - strncpy (build_options+blen, " -D WITH_HITAG2_FULL", 21); - blen += 20; - } - - // Intel's gpu are worst than Apple - #if APPLE_GPU_BROKEN == 0 - if (cd_ctx[w].device[q].is_gpu && !strncmp (cd_ctx[w].device[q].vendor, "Intel", 5)) - { - if (cd_ctx[w].is_apple || cd_ctx[w].is_intel) - { - strncpy (build_options+blen, " -D LOWPERF", 13); - blen += 12; - } - } - #endif - - #if DEBUGME >= 1 - printf ("[debug] Device %zu have local mem ? %d\n", z, cd_ctx[w].device[q].have_local_memory); - #endif - - if (cd_ctx[w].device[q].have_local_memory) // kernel keystream memory optimization - { - have_local_memory = true; - strncpy (build_options+blen, " -D HAVE_LOCAL_MEMORY", 22); - blen += 21; - } - - if (verbose) printf ("[%zu] Building OpenCL program with options (len %zu): %s\n", z, blen, build_options); - - err = clBuildProgram(ctx.programs[z], 1, &ctx.device_ids[z], build_options, NULL, NULL); - - #if DEBUGME == 0 - if (err != CL_SUCCESS) - #endif - { - #if DEBUGME > 0 - if (err != CL_SUCCESS) - #endif - { - printf ("[%zu] Error: clBuildProgram() failed (%d)\n", z, err); - build_errors++; - } - - // todo: if same device model of other and build_logs > 0, continue - - size_t len = 0; - err = clGetProgramBuildInfo(ctx.programs[z], cd_ctx[w].device[q].device_id, CL_PROGRAM_BUILD_LOG, 0, NULL, &len); - if (err != CL_SUCCESS) { - printf ("[%zu] Error: clGetProgramBuildInfo failed (%d)\n", z, err); - continue; +int main(int argc, char **argv) { + opencl_ctx_t ctx; + + uint32_t uid = 0, nR1 = 0, aR1 = 0, nR2 = 0, aR2 = 0; + bool opencl_profiling = 0; + bool force_hitag2_opencl = false; + bool verbose = false; + bool show = false; + + char *platforms_selected = NULL; + char *devices_selected = NULL; + unsigned int device_types_selected = 0; + unsigned int thread_scheduler_type_selected = THREAD_TYPE_ASYNC; + unsigned int profile_selected = 2; + unsigned int queue_type = 0; + + uint32_t target = 0; + uint32_t **matches_found = NULL; + uint64_t **matches = NULL; + + int opt; + + while ((opt = getopt(argc, argv, "p:d:D:S:P:F:Q:svVh")) != -1) { + switch (opt) { + case 'p': + // 1, 2, 3, etc .. + platforms_selected = strdup(optarg); + break; + case 'd': + // 1, 2, 3, etc ... + devices_selected = strdup(optarg); + break; + case 'D': + // 0: gpu, 1: cpu, 2: all + device_types_selected = (unsigned int) strtoul(optarg, NULL, 10); + if (device_types_selected > 2) { + printf("! Invalid DEVICE TYPE argument (accepted values: from 0 to 2)\n"); + usage(argv[0]); + } + break; + case 'S': + // 0: sequential, 1: async + thread_scheduler_type_selected = (unsigned int) strtoul(optarg, NULL, 10); + break; + case 'P': + profile_selected = (unsigned int) strtoul(optarg, NULL, 10); + if (profile_selected > 10) { + printf("! Invalid PROFILE argument (accepted valuee: from 0 to 10)\n"); + usage(argv[0]); + } + break; + case 'F': + force_hitag2_opencl = true; + break; + case 'Q': + // 0: forward, 1: reverse, 2: random + queue_type = (unsigned int) strtoul(optarg, NULL, 10); + if (queue_type != QUEUE_TYPE_FORWARD && queue_type != QUEUE_TYPE_REVERSE && queue_type != QUEUE_TYPE_RANDOM) { + printf("! Invalid QUEUE TYPE argument (accepted values: 0, 1 or 2)\n"); + usage(argv[0]); + } + break; + case 's': + show = true; + break; + case 'V': + verbose = true; + break; + case 'v': + printf("Version: %s\n", VERSION); + exit(0); + case 'h': + default: + usage(argv[0]); + } + } + + unsigned int plat_sel[16] = { 0 }; + unsigned int plat_cnt = 0; + unsigned int dev_sel[16] = { 0 }; + unsigned int dev_cnt = 0; + + if (!parse_arg(platforms_selected, plat_sel, &plat_cnt, 0)) { + free(platforms_selected); + usage(argv[0]); + } + + if (!parse_arg(devices_selected, dev_sel, &dev_cnt, 1)) { + free(platforms_selected); + free(devices_selected); + usage(argv[0]); + } + + free(platforms_selected); + free(devices_selected); + + if (device_types_selected == 0) device_types_selected = CL_DEVICE_TYPE_GPU; + else if (device_types_selected == 1) device_types_selected = CL_DEVICE_TYPE_CPU; + else device_types_selected = CL_DEVICE_TYPE_ALL; + + if (show) { + plat_sel[0] = 0xff; + dev_sel[0] = 0xff; + device_types_selected = CL_DEVICE_TYPE_ALL; + } + + if (verbose) { + if (plat_sel[0] == 0xff) printf("Platforms selected : ALL\n"); + else { + printf("Platforms selected : %u", plat_sel[0]); + for (unsigned int i = 1; i < plat_cnt; i++) printf(", %u", plat_sel[i]); + printf("\n"); + } + + if (dev_sel[0] == 0xff) printf("Devices selected : ALL\n"); + else { + printf("Devices selected : %u", dev_sel[0]); + for (unsigned int i = 1; i < dev_cnt; i++) printf(", %u", dev_sel[i]); + printf("\n"); + } + + printf("Device types selected : %s\n", (device_types_selected == CL_DEVICE_TYPE_GPU) ? "GPU" : (device_types_selected == CL_DEVICE_TYPE_CPU) ? "CPU" : "ALL"); + printf("Scheduler selected : %s\n", (thread_scheduler_type_selected == 0) ? "sequential" : "async"); + printf("Profile selected : %d\n", profile_selected); + } + + if (!show) { + if ((argc - optind) < 5) { +#if DEBUGME > 0 + printf("! Invalid extra arguments\n"); +#endif + usage(argv[0]); + } + + for (int e = 0; e < 5; optind++, e++) { + switch (e) { + case 0: // UID + if (!strncmp(argv[optind], "0x", 2) || !strncmp(argv[optind], "0X", 2)) { + if (strlen(argv[optind]) != 2 + 8) { printf("! Invalid UID length\n"); usage(argv[0]); } + uid = (uint32_t) rev32(hexreversetoulong(argv[optind] + 2)); + } else { + if (strlen(argv[optind]) != 8) { printf("! Invalid UID length\n"); usage(argv[0]); } + uid = (uint32_t) rev32(hexreversetoulong(argv[optind])); + } + break; + + case 1: // nR1 + if (!strncmp(argv[optind], "0x", 2) || !strncmp(argv[optind], "0X", 2)) { + if (strlen(argv[optind]) != 2 + 8) { printf("! Invalid nR1 length\n"); usage(argv[0]); } + nR1 = (uint32_t) rev32(hexreversetoulong(argv[optind] + 2)); + } else { + if (strlen(argv[optind]) != 8) { printf("! Invalid nR1 length\n"); usage(argv[0]); } + nR1 = (uint32_t) rev32(hexreversetoulong(argv[optind])); + } + break; + + case 2: // aR1 + if (strlen(argv[optind]) != 8) { printf("! Invalid aR1 length\n"); usage(argv[0]); } + aR1 = (uint32_t) strtoul(argv[optind], NULL, 16); + break; + + case 3: // nR2 + if (!strncmp(argv[optind], "0x", 2) || !strncmp(argv[optind], "0X", 2)) { + if (strlen(argv[optind]) != 2 + 8) { printf("! Invalid nR2 length\n"); usage(argv[0]); } + nR2 = (uint32_t) rev32(hexreversetoulong(argv[optind] + 2)); + } else { + if (strlen(argv[optind]) != 8) { printf("! Invalid nR2 length\n"); usage(argv[0]); } + nR2 = (uint32_t) rev32(hexreversetoulong(argv[optind])); + } + break; + + case 4: // aR2 + if (strlen(argv[optind]) != 8) { printf("! Invalid aR2 length\n"); usage(argv[0]); } + aR2 = (uint32_t) strtoul(argv[optind], NULL, 16); + break; + + default: // skip invalid instead of show usage and exit + optind = argc; + break; + } + } + } + + memset(&ctx, 0, sizeof(opencl_ctx_t)); + memset(keystream, 0, sizeof(keystream)); + memset(candidates, 0, sizeof(candidates)); + + ctx.profiling = opencl_profiling; + ctx.thread_sched_type = (short) thread_scheduler_type_selected; + ctx.force_hitag2_opencl = force_hitag2_opencl; + + uint32_t checks[4] = { uid, aR2, nR1, nR2 }; + + if (!show) { + if (verbose) printf("uid: %u, aR2: %u, nR1: %u, nR2: %u\n", checks[0], checks[1], checks[2], checks[3]); + + target = ~aR1; + // bitslice inverse target bits + bitslice(~target, keystream); + + size_t layer_0_found = 0; + + // compute layer 0 output + for (size_t i0 = 0; i0 < 1 << 20; i0++) { + uint64_t state0 = expand(0x5806b4a2d16c, i0); + + if (f(state0) == target >> 31) { + // using uint64_t + // candidates[layer_0_found++] = state0; + // or + // cf kernel, state is now split in 3 shorts >> 2 + candidates[(layer_0_found * 3) + 0] = (uint16_t)((state0 >> (32 + 2)) & 0xffff); + candidates[(layer_0_found * 3) + 1] = (uint16_t)((state0 >> (16 + 2)) & 0xffff); + candidates[(layer_0_found * 3) + 2] = (uint16_t)((state0 >> (0 + 2)) & 0xffff); + layer_0_found++; + } + } + +#if DEBUGME >= 1 + printf("[debug] layer_0_found: %zu\n", layer_0_found); +#endif + } + + // powered by dolphin's macros :) + int freeListIdx = 0; + + // todo, calculate the max number of allocations to remove 0x40 + void **freeList = (void **) malloc(0x40 * sizeof(void *)); + if (!freeList) { + printf("Error: malloc (freeList) failed (%d): %s\n", errno, strerror(errno)); + exit(3); + } + + if (!show) { + // load OpenCL kernel source + struct stat st; + const char *opencl_kernel = "ht2crack5opencl_kernel.cl"; + + int fd = open(opencl_kernel, O_RDONLY); + if (fd <= 0) { + printf("Error: open (%s) failed (%d): %s\n", opencl_kernel, errno, strerror(errno)); + exit(3); + } + + if (fstat(fd, &st)) { + printf("Error: stat (%s) failed (%d): %s\n", opencl_kernel, errno, strerror(errno)); + close(fd); + exit(3); + } + + ctx.kernelSource_len = (size_t) st.st_size; + ctx.kernelSource[0] = (char *) calloc(ctx.kernelSource_len + 1, sizeof(char)); // size + \0 + if (!ctx.kernelSource[0]) { + printf("Error: calloc (ctx.kernelSource[0]) failed (%d): %s\n", errno, strerror(errno)); + exit(3); + } + + MEMORY_FREE_ADD(ctx.kernelSource[0]) + + if (read(fd, ctx.kernelSource[0], ctx.kernelSource_len) < (ssize_t) ctx.kernelSource_len) { + printf("Error: read (%s) failed (%d): %s\n", opencl_kernel, errno, strerror(errno)); + close(fd); + MEMORY_FREE_ALL + exit(3); + } + + ctx.kernelSource[0][ctx.kernelSource_len] = '\0'; + + close(fd); + } + + // now discover and set up compute device(s) + int err = 0; + cl_uint ocl_platform_cnt = 0; + unsigned int ocl_platform_max = MAX_OPENCL_DEVICES; // 16 + + cl_platform_id *ocl_platforms = (cl_platform_id *) calloc(ocl_platform_max, sizeof(cl_platform_id)); + if (!ocl_platforms) { + printf("Error: calloc (ocl_platforms) failed (%d): %s\n", errno, strerror(errno)); + MEMORY_FREE_ALL + exit(2); + } + + MEMORY_FREE_ADD(ocl_platforms) + + // enum platforms + err = clGetPlatformIDs(ocl_platform_max, ocl_platforms, &ocl_platform_cnt); + if (err != CL_SUCCESS) { + printf("Error: clGetPlatformIDs() failed (%d)\n", err); + MEMORY_FREE_ALL + exit(2); + } + + if (ocl_platform_cnt == 0) { + printf("No platforms found, exit\n"); + MEMORY_FREE_ALL + exit(2); + } + + // allocate memory to hold info about platforms/devices + compute_platform_ctx_t *cd_ctx = (compute_platform_ctx_t *) calloc(ocl_platform_cnt, sizeof(compute_platform_ctx_t)); + if (!cd_ctx) { + printf("Error: calloc (compute_platform_ctx_t) failed (%d): %s\n", errno, strerror(errno)); + MEMORY_FREE_ALL + exit(err); + } + + MEMORY_FREE_ADD(cd_ctx) + + cl_platform_info ocl_platforms_info[3] = { CL_PLATFORM_NAME, CL_PLATFORM_VENDOR, CL_PLATFORM_VERSION }; + unsigned int ocl_platforms_info_cnt = sizeof(ocl_platforms_info) / sizeof(cl_platform_info); + + cl_device_info ocl_devices_info[8] = { CL_DEVICE_TYPE, CL_DEVICE_NAME, CL_DEVICE_VERSION, CL_DRIVER_VERSION, CL_DEVICE_VENDOR, CL_DEVICE_LOCAL_MEM_TYPE, CL_DEVICE_MAX_WORK_ITEM_SIZES, CL_DEVICE_MAX_COMPUTE_UNITS }; + unsigned int ocl_devices_info_cnt = sizeof(ocl_devices_info) / sizeof(cl_device_info); + + unsigned int info_idx = 0; + size_t tmp_len = 0; + char *tmp_buf = NULL; + + unsigned int global_device_id = 0; + size_t selected_platforms_cnt = 0; + size_t selected_devices_cnt = 0; + + if (show) verbose = true; + + if (verbose) printf("- Found %u OpenCL Platform(s)\n", ocl_platform_cnt); + + for (cl_uint platform_idx = 0; platform_idx < ocl_platform_cnt; platform_idx++) { + cd_ctx[platform_idx].platform_id = ocl_platforms[platform_idx]; + cd_ctx[platform_idx].selected = plat_dev_enabled(platform_idx, plat_sel, plat_cnt, 0, 0); + + if (cd_ctx[platform_idx].selected) selected_platforms_cnt++; + + if (verbose) printf("\n-- Platform ID: %d\n", platform_idx + 1); + + for (info_idx = 0; info_idx < ocl_platforms_info_cnt; info_idx++) { + cl_platform_info ocl_info = ocl_platforms_info[info_idx]; + + err = clGetPlatformInfo(cd_ctx[platform_idx].platform_id, ocl_info, 0, NULL, &tmp_len); + if (err != CL_SUCCESS) { + printf("Error: clGetPlatformInfo(param size) failed (%d)\n", err); + MEMORY_FREE_ALL + exit(2); + } + + if (tmp_len > 0) { + if (!(tmp_buf = (char *) calloc(tmp_len, sizeof(char)))) { + printf("Error: calloc (ocl_info %u) failed (%d): %s\n", info_idx, errno, strerror(errno)); + MEMORY_FREE_ALL + exit(2); + } + + MEMORY_FREE_ADD(tmp_buf) + + err = clGetPlatformInfo(cd_ctx[platform_idx].platform_id, ocl_info, tmp_len, tmp_buf, 0); + if (err != CL_SUCCESS) { + printf("Error: clGetPlatformInfo(param) failed (%d)\n", err); + MEMORY_FREE_ALL + exit(2); + } + } else { + tmp_len = 4; + if (!(tmp_buf = (char *) calloc(tmp_len, sizeof(char)))) { + printf("Error: calloc (ocl_info %u) failed (%d): %s\n", info_idx, errno, strerror(errno)); + MEMORY_FREE_ALL + exit(2); + } + + MEMORY_FREE_ADD(tmp_buf) + + strncpy(tmp_buf, "N/A\0", tmp_len); + } + + if (verbose) { + const char *tmp_info_desc = (info_idx == 0) ? "Name" : (info_idx == 1) ? "Vendor" : "Version"; + + printf("%14s: %s\n", tmp_info_desc, tmp_buf); + } + + switch (info_idx) { + case 0: + strncpy(cd_ctx[platform_idx].name, tmp_buf, tmp_len < 0xff ? tmp_len : 0xff - 1); + break; + case 1: + strncpy(cd_ctx[platform_idx].vendor, tmp_buf, tmp_len < 0x40 ? tmp_len : 0x40 - 1); + break; + case 2: + strncpy(cd_ctx[platform_idx].version, tmp_buf, tmp_len < 0x40 ? tmp_len : 0x40 - 1); + break; + } + + if (info_idx == 1) { + // todo: do the same this devices + if (!strncmp(tmp_buf, "NVIDIA", 6)) cd_ctx[platform_idx].is_nv = true; + else if (!strncmp(tmp_buf, "Apple", 5)) { cd_ctx[platform_idx].is_apple = true; cd_ctx[platform_idx].warning = true; } + else if (!strncmp(tmp_buf, "Intel", 5)) cd_ctx[platform_idx].is_intel = true; + } + + MEMORY_FREE_DEL(tmp_buf) + } + + if (!show && verbose) { + printf("%14s: %s\n", "Selected", (cd_ctx[platform_idx].selected) ? "yes" : "no"); + if (cd_ctx[platform_idx].warning) printf("\n%14s: performance will not be optimal using this platform\n\n", "=====> Warning"); + } + + // enum devices with this platform + unsigned int ocl_device_cnt = 0; + unsigned int ocl_device_max = MAX_OPENCL_DEVICES; + + cl_device_id *ocl_devices = (cl_device_id *) calloc(ocl_device_max, sizeof(cl_device_id)); + if (!ocl_devices) { + printf("Error: calloc (ocl_devices) failed (%d): %s\n", errno, strerror(errno)); + MEMORY_FREE_ALL + exit(2); + } + + MEMORY_FREE_ADD(ocl_devices) + + err = clGetDeviceIDs(cd_ctx[platform_idx].platform_id, CL_DEVICE_TYPE_ALL, ocl_device_max, ocl_devices, &ocl_device_cnt); + if (ocl_device_cnt == 0) { + if (device_types_selected == CL_DEVICE_TYPE_ALL) printf("No device(s) available with platform id %d\n", platform_idx); + cd_ctx[platform_idx].device_cnt = 0; + continue; + } + + if (err != CL_SUCCESS) { + printf("Error: clGetDeviceIDs(cnt) failed (%d)\n", err); + MEMORY_FREE_ALL + exit(2); + } + + if (verbose) printf("%14s: %u\n", "Device(s)", ocl_device_cnt); + + cd_ctx[platform_idx].device_cnt = ocl_device_cnt; + + for (unsigned int device_idx = 0; device_idx < ocl_device_cnt; device_idx++) { + memset(&cd_ctx[platform_idx].device[device_idx], 0, sizeof(compute_device_ctx_t)); + cl_device_id ocl_device = ocl_devices[device_idx]; + cd_ctx[platform_idx].device[device_idx].platform_id = cd_ctx[platform_idx].platform_id; + + if (verbose) printf("---- * ID: %u\n", global_device_id + 1); + + for (info_idx = 0; info_idx < ocl_devices_info_cnt; info_idx++) { + cl_device_info ocl_dev_info = ocl_devices_info[info_idx]; + + if (info_idx == 0) { + cl_device_type device_type; + + err = clGetDeviceInfo(ocl_device, ocl_dev_info, sizeof(cl_device_type), &device_type, 0); + if (err != CL_SUCCESS) { + printf("Error: clGetDeviceInfo(device_type) failed (%d)\n", err); + MEMORY_FREE_ALL + exit(2); + } + + if (device_type & CL_DEVICE_TYPE_GPU) cd_ctx[platform_idx].device[device_idx].is_gpu = 1; + + if (verbose) printf("%14s: %s\n", "Device Type", (device_type & CL_DEVICE_TYPE_GPU) ? "GPU" : (device_type & CL_DEVICE_TYPE_CPU) ? "CPU" : "Other"); + + cd_ctx[platform_idx].device[device_idx].selected = plat_dev_enabled(global_device_id, dev_sel, dev_cnt, (unsigned int) device_type, device_types_selected); + global_device_id++; + if (cd_ctx[platform_idx].device[device_idx].selected) selected_devices_cnt++; + continue; + } else if (info_idx == 5) { + cl_device_local_mem_type local_mem_type; + + err = clGetDeviceInfo(ocl_device, ocl_dev_info, sizeof(cl_device_local_mem_type), &local_mem_type, 0); + if (err != CL_SUCCESS) { + printf("Error: clGetDeviceInfo(local_mem_type) failed (%d)\n", err); + MEMORY_FREE_ALL + exit(2); + } + + if (local_mem_type == CL_LOCAL || local_mem_type == CL_GLOBAL) { + if (verbose) printf("%14s: %s\n", "Local Mem Type", (local_mem_type == CL_LOCAL) ? "Local" : "Global"); + + if (cd_ctx[platform_idx].is_apple) { + if (strncmp(cd_ctx[platform_idx].device[device_idx].vendor, "Intel", 5) != 0) cd_ctx[platform_idx].device[device_idx].have_local_memory = true; + } else if (cd_ctx[platform_idx].is_nv) cd_ctx[platform_idx].device[device_idx].have_local_memory = true; + /* + // swap the 'if' comment for enable local memory with apple gpu's (my Iris crash, abort 6) + // if (!(!strncmp (cd_ctx[platform_idx].device[device_idx].vendor, "Intel", 5) && cd_ctx[platform_idx].is_apple && !cd_ctx[platform_idx].device[device_idx].is_gpu)) + if (!(!strncmp (cd_ctx[platform_idx].device[device_idx].vendor, "Intel", 5) && cd_ctx[platform_idx].is_apple)) + { + cd_ctx[platform_idx].device[device_idx].have_local_memory = true; + } + */ + } else { + if (verbose) printf("%14s: None\n", "Local Mem Type"); + } + + if (verbose) printf("%14s: %s\n", "Local Mem Opt", (cd_ctx[platform_idx].device[device_idx].have_local_memory) ? "yes" : "no"); + + continue; + } else if (info_idx == 6) { + size_t wis[3] = { 0 }; + err = clGetDeviceInfo(ocl_device, ocl_dev_info, sizeof(size_t) * 3, wis, 0); + if (err != CL_SUCCESS) { + printf("Error: clGetDeviceInfo(work_items_size) failed (%d)\n", err); + MEMORY_FREE_ALL + exit(2); + } + + if (verbose) printf("%14s: (%zu,%zu,%zu)\n", "Max Work-Items", wis[0], wis[1], wis[2]); + +#if APPLE_GPU_BROKEN == 1 + if (wis[1] < GLOBAL_WS_1 && cd_ctx[platform_idx].device[device_idx].is_apple_gpu) { + cd_ctx[platform_idx].device[device_idx].unsupported = true; + } +#endif + continue; + } else if (info_idx == 7) { + cl_uint cores = 0; + err = clGetDeviceInfo(ocl_device, ocl_dev_info, sizeof(cl_uint), &cores, 0); + if (err != CL_SUCCESS) { + printf("Error: clGetDeviceInfo(compute_units) failed (%d)\n", err); + MEMORY_FREE_ALL + exit(2); + } + + if (verbose) printf("%14s: %u\n", "Compute Units", cores); + + cd_ctx[platform_idx].device[device_idx].compute_units = cores; + continue; + } + + tmp_len = 0; + tmp_buf = NULL; + + err = clGetDeviceInfo(ocl_device, ocl_dev_info, 0, NULL, &tmp_len); + if (err != CL_SUCCESS) { + printf("Error: clGetDeviceInfo(param size) failed (%d)\n", err); + MEMORY_FREE_ALL + exit(2); + } + + if (tmp_len > 0) { + if (!(tmp_buf = (char *) calloc(tmp_len, sizeof(char)))) { + printf("Error: calloc (ocl_dev_info %u) failed (%d): %s\n", info_idx, errno, strerror(errno)); + MEMORY_FREE_ALL + exit(2); + } + + MEMORY_FREE_ADD(tmp_buf) + + err = clGetDeviceInfo(ocl_device, ocl_dev_info, tmp_len, tmp_buf, 0); + if (err != CL_SUCCESS) { + printf("Error: clGetDeviceInfo(param) failed (%d)\n", err); + MEMORY_FREE_ALL + exit(2); + } + } else { + tmp_len = 4; + if (!(tmp_buf = (char *) calloc(tmp_len, sizeof(char)))) { + printf("Error: calloc (ocl_dev_info %u) failed (%d): %s\n", info_idx, errno, strerror(errno)); + MEMORY_FREE_ALL + exit(2); + } + + MEMORY_FREE_ADD(tmp_buf) + + strncpy(tmp_buf, "N/A\0", tmp_len); + } + + if (verbose) { + const char *tmp_dev_info_desc = (info_idx == 1) ? "Name" : (info_idx == 2) ? "Version" : (info_idx == 3) ? "Driver Version" : "Vendor"; + + printf("%14s: %s\n", tmp_dev_info_desc, tmp_buf); + } + + switch (info_idx) { + case 1: + strncpy(cd_ctx[platform_idx].device[device_idx].name, tmp_buf, tmp_len < 0xff ? tmp_len : 0xff - 1); + break; + case 2: + strncpy(cd_ctx[platform_idx].device[device_idx].version, tmp_buf, tmp_len < 0x40 ? tmp_len : 0x40 - 1); + break; + case 3: + strncpy(cd_ctx[platform_idx].device[device_idx].driver_version, tmp_buf, tmp_len < 0x40 ? tmp_len : 0x40 - 1); + break; + case 4: + strncpy(cd_ctx[platform_idx].device[device_idx].vendor, tmp_buf, tmp_len < 0x40 ? tmp_len : 0x40 - 1); + break; + } + + if (info_idx == 4) { + if (!strncmp(tmp_buf, "Intel", 5) && cd_ctx[platform_idx].is_apple) { + // disable hitag2 with apple platform and not apple device vendor (< Apple M1) + ctx.force_hitag2_opencl = false; + + cd_ctx[platform_idx].device[device_idx].is_apple_gpu = cd_ctx[platform_idx].device[device_idx].is_gpu; + } + + if (!strncmp(tmp_buf, "NVIDIA", 6) && cd_ctx[platform_idx].is_nv) { + unsigned int sm_maj = 0, sm_min = 0; + + err = clGetDeviceInfo(ocl_device, 0x4000, sizeof(unsigned int), &sm_maj, 0); + err |= clGetDeviceInfo(ocl_device, 0x4001, sizeof(unsigned int), &sm_min, 0); + + if (err != CL_SUCCESS) { + printf("Error: clGetDeviceInfo(sm_maj/sm_min) failed (%d)\n", err); + MEMORY_FREE_ALL + exit(2); + } + + cd_ctx[platform_idx].device[device_idx].sm_maj = sm_maj; + cd_ctx[platform_idx].device[device_idx].sm_min = sm_min; + + if (verbose) printf("%14s: %u%u\n", "SM", sm_maj, sm_min); + + if (sm_maj >= 5) { // >= Maxwell + // https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#logic-and-shift-instructions-lop3 + // Requires sm_50 or higher. + cd_ctx[platform_idx].device[device_idx].have_lop3 = true; + } else { + cd_ctx[platform_idx].device[device_idx].warning = true; + } + + cd_ctx[platform_idx].device[device_idx].is_nv = true; + } else { + cd_ctx[platform_idx].device[device_idx].warning = true; + } + } + + MEMORY_FREE_DEL(tmp_buf) + } + + if (!show && verbose) printf("%14s: %s\n", "Selected", (cd_ctx[platform_idx].device[device_idx].selected) ? "yes" : "no"); + + if (cd_ctx[platform_idx].device[device_idx].unsupported) { + printf("\n%14s: this device was not supported, beacuse of missing resources\n\n", "=====> Warning"); + continue; + } + + if (cd_ctx[platform_idx].device[device_idx].warning) { + if (!show && verbose) printf("\n%14s: performance will not be optimal using this device\n\n", "=====> Warning"); + } + + cd_ctx[platform_idx].device[device_idx].device_id = ocl_device; + } + MEMORY_FREE_DEL(ocl_devices) + } + MEMORY_FREE_DEL(ocl_platforms) + + // new selection engine, need to support multi-gpu system (with the same platform) + + if (verbose) printf("\n"); + + if (show) { + MEMORY_FREE_ALL + exit(2); + } + + if (selected_platforms_cnt == 0) { + printf("! No platform was selected ...\n"); + MEMORY_FREE_ALL + exit(2); + } + + if (selected_devices_cnt == 0) { + printf("! No device(s) was selected ...\n"); + MEMORY_FREE_ALL + exit(2); + } + + size_t w = 0, q = 0, g = 0; + + size_t z = 0; // z is a dolphin's friend + + // show selected devices + + printf("Selected %zu OpenCL Device(s)\n\n", selected_devices_cnt); + + for (w = 0; w < ocl_platform_cnt; w++) { + if (!cd_ctx[w].selected) continue; + + for (q = 0; q < cd_ctx[w].device_cnt; q++) { + if (!cd_ctx[w].device[q].selected) continue; + + printf("%2zu - %s", z, cd_ctx[w].device[q].name); + if (verbose) { + printf(" (Lop3 %s, ", (cd_ctx[w].device[q].have_lop3) ? "yes" : "no"); + printf("Local Memory %s)", (cd_ctx[w].device[q].have_local_memory) ? "yes" : "no"); + } + printf("\n"); + + z++; + } + } + printf("\n"); + + if (selected_devices_cnt != z) { + printf("BUG: z and selected_devices_cnt are not equal\n"); + MEMORY_FREE_ALL + exit(2); + } + + // time to eat some memory :P + + if (!(ctx.device_ids = (cl_device_id *) calloc(selected_devices_cnt, sizeof(cl_device_id)))) { + printf("Error: calloc (ctx.device_ids) failed (%d): %s\n", errno, strerror(errno)); + MEMORY_FREE_ALL + exit(2); + } + + MEMORY_FREE_ADD(ctx.device_ids) + + if (!(ctx.contexts = (cl_context *) calloc(selected_devices_cnt, sizeof(cl_context)))) { + printf("Error: calloc (ctx.contexts) failed (%d): %s\n", errno, strerror(errno)); + MEMORY_FREE_ALL + exit(2); + } + + MEMORY_FREE_ADD(ctx.contexts) + + if (!(ctx.commands = (cl_command_queue *) calloc(selected_devices_cnt, sizeof(cl_command_queue)))) { + printf("Error: calloc (ctx.commands) failed (%d): %s\n", errno, strerror(errno)); + MEMORY_FREE_ALL + exit(2); + } + + MEMORY_FREE_ADD(ctx.commands) + + if (!(ctx.programs = (cl_program *) calloc(selected_devices_cnt, sizeof(cl_program)))) { + printf("Error: calloc (ctx.programs) failed (%d): %s\n", errno, strerror(errno)); + MEMORY_FREE_ALL + exit(2); + } + + MEMORY_FREE_ADD(ctx.programs) + + if (!(ctx.kernels = (cl_kernel *) calloc(selected_devices_cnt, sizeof(cl_kernel)))) { + printf("Error: calloc (ctx.kernels) failed (%d): %s\n", errno, strerror(errno)); + MEMORY_FREE_ALL + exit(2); + } + + MEMORY_FREE_ADD(ctx.kernels) + + if (!(matches = (uint64_t **) calloc(selected_devices_cnt, sizeof(uint64_t *)))) { + printf("Error: calloc (**matches) failed (%d): %s\n", errno, strerror(errno)); + MEMORY_FREE_ALL + exit(2); + } + + MEMORY_FREE_ADD(matches) + + if (!(matches_found = (uint32_t **) calloc(selected_devices_cnt, sizeof(uint32_t *)))) { + printf("Error: calloc (**matches_found) failed (%d): %s\n", errno, strerror(errno)); + MEMORY_FREE_ALL + exit(2); + } + + MEMORY_FREE_ADD(matches_found) + + if (!(ctx.keystreams = (cl_mem *) calloc(selected_devices_cnt, sizeof(cl_mem)))) { + printf("Error: calloc (ctx.keystreams) failed (%d): %s\n", errno, strerror(errno)); + MEMORY_FREE_ALL + exit(2); + } + + MEMORY_FREE_ADD(ctx.keystreams) + + if (!(ctx.candidates = (cl_mem *) calloc(selected_devices_cnt, sizeof(cl_mem)))) { + printf("Error: calloc (ctx.candidates) failed (%d): %s\n", errno, strerror(errno)); + MEMORY_FREE_ALL + exit(2); + } + + MEMORY_FREE_ADD(ctx.candidates) + + if (!(ctx.matches = (cl_mem *) calloc(selected_devices_cnt, sizeof(cl_mem)))) { + printf("Error: calloc (ctx.matches) failed (%d): %s\n", errno, strerror(errno)); + MEMORY_FREE_ALL + exit(2); + } + + MEMORY_FREE_ADD(ctx.matches) + + if (!(ctx.matches_found = (cl_mem *) calloc(selected_devices_cnt, sizeof(cl_mem)))) { + printf("Error: calloc (ctx.matches_found) failed (%d): %s\n", errno, strerror(errno)); + MEMORY_FREE_ALL + exit(2); + } + + MEMORY_FREE_ADD(ctx.matches_found) + + if (ctx.force_hitag2_opencl) { + if (!(ctx.checks = (cl_mem *) calloc(selected_devices_cnt, sizeof(cl_mem)))) { + printf("Error: calloc (ctx.checks) failed (%d): %s\n", errno, strerror(errno)); + MEMORY_FREE_ALL + exit(2); + } + + MEMORY_FREE_ADD(ctx.checks) + } + + if (!(ctx.global_ws = (size_t *) calloc(selected_devices_cnt, sizeof(size_t)))) { + printf("Error: calloc (ctx.global_ws) failed (%d): %s\n", errno, strerror(errno)); + MEMORY_FREE_ALL + exit(2); + } + + MEMORY_FREE_ADD(ctx.global_ws) + + if (!(ctx.local_ws = (size_t *) calloc(selected_devices_cnt, sizeof(size_t)))) { + printf("Error: calloc (ctx.local_ws) failed (%d): %s\n", errno, strerror(errno)); + MEMORY_FREE_ALL + exit(2); + } + + MEMORY_FREE_ADD(ctx.local_ws) + + if (!(ctx.profiles = (int *) calloc(selected_devices_cnt, sizeof(int)))) { + printf("Error: calloc (ctx.profiles) failed (%d): %s\n", errno, strerror(errno)); + MEMORY_FREE_ALL + exit(2); + } + + MEMORY_FREE_ADD(ctx.profiles) + + // show buidlog in case of error + // todo: only for device models + unsigned int build_errors = 0; + unsigned int build_logs = 0; + + cl_command_queue_properties queue_properties = 0; + + if (opencl_profiling) queue_properties = CL_QUEUE_PROFILING_ENABLE; + + // setup, phase 1 + + z = 0; // dolphin + + for (w = 0; w < ocl_platform_cnt; w++) { + if (!cd_ctx[w].selected) continue; + + for (q = 0; q < cd_ctx[w].device_cnt; q++) { + if (!cd_ctx[w].device[q].selected) continue; + + ctx.device_ids[z] = cd_ctx[w].device[q].device_id; + + // create the opencl context with the array + ctx.contexts[z] = clCreateContext(NULL, 1, &ctx.device_ids[z], NULL, NULL, &err); + if (!ctx.contexts[z] || err != CL_SUCCESS) { + printf("[%zu] Error: clCreateContext() failed (%d)\n", z, err); + MEMORY_FREE_OPENCL(ctx, z) + MEMORY_FREE_LIST(matches, z) + MEMORY_FREE_LIST(matches_found, z) + MEMORY_FREE_ALL + exit(2); + } + + // create comman queues for each selected devices + ctx.commands[z] = clCreateCommandQueue(ctx.contexts[z], ctx.device_ids[z], queue_properties, &err); + if (!ctx.commands[z] || err != CL_SUCCESS) { + printf("[%zu] Error: clCreateCommandQueue() failed (%d)\n", z, err); + MEMORY_FREE_OPENCL(ctx, z) + MEMORY_FREE_LIST(matches, z) + MEMORY_FREE_LIST(matches_found, z) + MEMORY_FREE_ALL + exit(2); + } + + // from clang: + // warning: cast from 'char *(*)[1]' to 'const char **' increases required alignment from 1 to 8 + const char *a = (const char *)ctx.kernelSource[0]; + const char **ks = &a; + + // create the compute program from the source buffer + //ctx.programs[z] = clCreateProgramWithSource(ctx.contexts[z], 1, (const char **) &ctx.kernelSource, &ctx.kernelSource_len, &err); + ctx.programs[z] = clCreateProgramWithSource(ctx.contexts[z], 1, ks, &ctx.kernelSource_len, &err); + if (!ctx.programs[z] || err != CL_SUCCESS) { + printf("[%zu] Error: clCreateProgramWithSource() failed (%d)\n", z, err); + MEMORY_FREE_OPENCL(ctx, z) + MEMORY_FREE_LIST(matches, z) + MEMORY_FREE_LIST(matches_found, z) + MEMORY_FREE_ALL + exit(2); + } + + // build the program executable + bool have_local_memory = false; + size_t blen = 0; + char build_options[0x100]; + + memset(build_options, 0, sizeof(build_options)); + + strncpy(build_options, "-Werror", 8); + blen += 7; + + if (cd_ctx[w].device[q].have_lop3) { // enable lop3 + strncpy(build_options + blen, " -D HAVE_LOP3", 14); + blen += 13; + } + + if (ctx.force_hitag2_opencl) { + // force using hitag2 key validation with OpenCL + strncpy(build_options + blen, " -D WITH_HITAG2_FULL", 21); + blen += 20; + } + + // Intel's gpu are worst than Apple +#if APPLE_GPU_BROKEN == 0 + if (cd_ctx[w].device[q].is_gpu && !strncmp(cd_ctx[w].device[q].vendor, "Intel", 5)) { + if (cd_ctx[w].is_apple || cd_ctx[w].is_intel) { + strncpy(build_options + blen, " -D LOWPERF", 13); + blen += 12; + } + } +#endif + +#if DEBUGME >= 1 + printf("[debug] Device %zu have local mem ? %d\n", z, cd_ctx[w].device[q].have_local_memory); +#endif + + if (cd_ctx[w].device[q].have_local_memory) { // kernel keystream memory optimization + have_local_memory = true; + strncpy(build_options + blen, " -D HAVE_LOCAL_MEMORY", 22); + blen += 21; + } + + if (verbose) printf("[%zu] Building OpenCL program with options (len %zu): %s\n", z, blen, build_options); + + err = clBuildProgram(ctx.programs[z], 1, &ctx.device_ids[z], build_options, NULL, NULL); + +#if DEBUGME == 0 + if (err != CL_SUCCESS) +#endif + { +#if DEBUGME > 0 + if (err != CL_SUCCESS) +#endif + { + printf("[%zu] Error: clBuildProgram() failed (%d)\n", z, err); + build_errors++; + } + + // todo: if same device model of other and build_logs > 0, continue + + size_t len = 0; + err = clGetProgramBuildInfo(ctx.programs[z], cd_ctx[w].device[q].device_id, CL_PROGRAM_BUILD_LOG, 0, NULL, &len); + if (err != CL_SUCCESS) { + printf("[%zu] Error: clGetProgramBuildInfo failed (%d)\n", z, err); + continue; // exit (2); - } + } - if (len == 0) continue; + if (len == 0) continue; - if (len > 0xdeadbe) len = 0xdeadbe; // limit build_log size + if (len > 0xdeadbe) len = 0xdeadbe; // limit build_log size - char *buffer = (char *) calloc (len, sizeof(char)); - if (!buffer) - { - printf ("[%zu] Error: calloc (CL_PROGRAM_BUILD_LOG) failed (%d): %s\n", z, errno, strerror (errno)); - continue; + char *buffer = (char *) calloc(len, sizeof(char)); + if (!buffer) { + printf("[%zu] Error: calloc (CL_PROGRAM_BUILD_LOG) failed (%d): %s\n", z, errno, strerror(errno)); + continue; // exit (2); - } + } - MEMORY_FREE_ADD(buffer) + MEMORY_FREE_ADD(buffer) - err = clGetProgramBuildInfo(ctx.programs[z], cd_ctx[w].device[q].device_id, CL_PROGRAM_BUILD_LOG, len, buffer, 0); - if (err != CL_SUCCESS) { - printf ("[%zu] clGetProgramBuildInfo() failed (%d)\n", z, err); - MEMORY_FREE_DEL(buffer) - continue; + err = clGetProgramBuildInfo(ctx.programs[z], cd_ctx[w].device[q].device_id, CL_PROGRAM_BUILD_LOG, len, buffer, 0); + if (err != CL_SUCCESS) { + printf("[%zu] clGetProgramBuildInfo() failed (%d)\n", z, err); + MEMORY_FREE_DEL(buffer) + continue; // exit (2); - } + } - #if DEBUGME > 0 - if (len > 2) - #endif - { - printf ("[%zu] Build log (len %zu):\n--------\n%s\n--------\n", z, len, buffer); - } +#if DEBUGME > 0 + if (len > 2) +#endif + { + printf("[%zu] Build log (len %zu):\n--------\n%s\n--------\n", z, len, buffer); + } - MEMORY_FREE_DEL(buffer) + MEMORY_FREE_DEL(buffer) - build_logs++; - #if DEBUGME == 0 - continue; // todo: evaluate this, one or more can be broken, so continue - #endif - } + build_logs++; +#if DEBUGME == 0 + continue; // todo: evaluate this, one or more can be broken, so continue +#endif + } - // todo, continue if build_errors + // todo, continue if build_errors - // Create the compute kernel in the program we wish to run - ctx.kernels[z] = clCreateKernel(ctx.programs[z], "find_state", &err); - if (!ctx.kernels[z] || err != CL_SUCCESS) { - printf ("[%zu] Error: clCreateKernel() failed (%d)\n", z, err); - MEMORY_FREE_OPENCL(ctx, z) - MEMORY_FREE_LIST(matches,z) - MEMORY_FREE_LIST(matches_found, z) - MEMORY_FREE_ALL - exit (3); - } + // Create the compute kernel in the program we wish to run + ctx.kernels[z] = clCreateKernel(ctx.programs[z], "find_state", &err); + if (!ctx.kernels[z] || err != CL_SUCCESS) { + printf("[%zu] Error: clCreateKernel() failed (%d)\n", z, err); + MEMORY_FREE_OPENCL(ctx, z) + MEMORY_FREE_LIST(matches, z) + MEMORY_FREE_LIST(matches_found, z) + MEMORY_FREE_ALL + exit(3); + } - size_t wgs = 0; - err = clGetKernelWorkGroupInfo (ctx.kernels[z], cd_ctx[w].device[q].device_id, CL_KERNEL_WORK_GROUP_SIZE, sizeof (size_t), &wgs, NULL); - if (err != CL_SUCCESS) { - printf ("[%zu] Error: clGetKernelWorkGroupInfo(CL_KERNEL_WORK_GROUP_SIZE) failed (%d)\n", z, err); - MEMORY_FREE_OPENCL(ctx, z) - // if macros work, next 2 macro are not needed - MEMORY_FREE_LIST(matches,z) - MEMORY_FREE_LIST(matches_found, z) - MEMORY_FREE_ALL - exit (3); - } + size_t wgs = 0; + err = clGetKernelWorkGroupInfo(ctx.kernels[z], cd_ctx[w].device[q].device_id, CL_KERNEL_WORK_GROUP_SIZE, sizeof(size_t), &wgs, NULL); + if (err != CL_SUCCESS) { + printf("[%zu] Error: clGetKernelWorkGroupInfo(CL_KERNEL_WORK_GROUP_SIZE) failed (%d)\n", z, err); + MEMORY_FREE_OPENCL(ctx, z) + // if macros work, next 2 macro are not needed + MEMORY_FREE_LIST(matches, z) + MEMORY_FREE_LIST(matches_found, z) + MEMORY_FREE_ALL + exit(3); + } - ctx.local_ws[z] = wgs; + ctx.local_ws[z] = wgs; - // never got it - if (ctx.local_ws[z] < 32 && have_local_memory) - { - printf ("Warning: local work-item size is less than the length of the keystream, and local memory optimization is enabled. An unexpected result could arise.\n"); - } + // never got it + if (ctx.local_ws[z] < 32 && have_local_memory) { + printf("Warning: local work-item size is less than the length of the keystream, and local memory optimization is enabled. An unexpected result could arise.\n"); + } - z++; - } - } + z++; + } + } - // z is device counter, dolphin counter as well + // z is device counter, dolphin counter as well - // setup, phase 2 (select lower profile) + // setup, phase 2 (select lower profile) - int profile = 0xff; + int profile = 0xff; - g = 0; + g = 0; - for (w = 0; w < ocl_platform_cnt; w++) - { - if (!cd_ctx[w].selected) continue; + for (w = 0; w < ocl_platform_cnt; w++) { + if (!cd_ctx[w].selected) continue; - for (q = 0; q < cd_ctx[w].device_cnt; q++) - { - if (!cd_ctx[w].device[q].selected) continue; + for (q = 0; q < cd_ctx[w].device_cnt; q++) { + if (!cd_ctx[w].device[q].selected) continue; - ctx.profiles[g] = (int) profile_selected; // start with default + ctx.profiles[g] = (int) profile_selected; // start with default - #if DEBUGME > 1 - printf ("[debug] Initial profile for device %zu: %d\n", z, ctx.profiles[g]); - #endif +#if DEBUGME > 1 + printf("[debug] Initial profile for device %zu: %d\n", z, ctx.profiles[g]); +#endif - // force profile to 0 with Apple GPU's to get it stable, and 1 for CPU - if (cd_ctx[w].is_apple && !strncmp (cd_ctx[w].device[q].vendor, "Intel", 5)) - { - if (cd_ctx[w].device[q].is_gpu) - { - if (profile_selected > 2) ctx.profiles[g] = PROFILE_DEFAULT; // Apple-Intel GPU's, 2 is the old 0 - } - else - { - if (profile_selected > 3) ctx.profiles[g] = PROFILE_DEFAULT; // Apple-Intel CPU's, 3 is the old 1 - } - } + // force profile to 0 with Apple GPU's to get it stable, and 1 for CPU + if (cd_ctx[w].is_apple && !strncmp(cd_ctx[w].device[q].vendor, "Intel", 5)) { + if (cd_ctx[w].device[q].is_gpu) { + if (profile_selected > 2) ctx.profiles[g] = PROFILE_DEFAULT; // Apple-Intel GPU's, 2 is the old 0 + } else { + if (profile_selected > 3) ctx.profiles[g] = PROFILE_DEFAULT; // Apple-Intel CPU's, 3 is the old 1 + } + } - // force profile to 0 with Intel GPU and 2 wih Intel CPU's - if (cd_ctx[w].is_intel && !strncmp (cd_ctx[w].device[q].vendor, "Intel", 5)) - { - if (cd_ctx[w].device[q].is_gpu) - { - ctx.profiles[g] = 0; // Intel GPU, work better with a very slow profile - } - else - { - if (profile_selected > 2) ctx.profiles[g] = PROFILE_DEFAULT; // Intel CPU (2 is the old 0) - } - } + // force profile to 0 with Intel GPU and 2 wih Intel CPU's + if (cd_ctx[w].is_intel && !strncmp(cd_ctx[w].device[q].vendor, "Intel", 5)) { + if (cd_ctx[w].device[q].is_gpu) { + ctx.profiles[g] = 0; // Intel GPU, work better with a very slow profile + } else { + if (profile_selected > 2) ctx.profiles[g] = PROFILE_DEFAULT; // Intel CPU (2 is the old 0) + } + } - // force profile to 2 with NVIDIA GPU's with NVIDIA platform - if (cd_ctx[w].is_nv && cd_ctx[w].device[q].is_gpu && !strncmp (cd_ctx[w].device[q].vendor, "NVIDIA", 6)) - { - if (profile_selected > 10) - { - // NVIDIA RTX 3090 perform better with 5 - ctx.profiles[g] = (cd_ctx[w].device[q].sm_maj >= 8) ? 5 : PROFILE_DEFAULT; - } - } + // force profile to 2 with NVIDIA GPU's with NVIDIA platform + if (cd_ctx[w].is_nv && cd_ctx[w].device[q].is_gpu && !strncmp(cd_ctx[w].device[q].vendor, "NVIDIA", 6)) { + if (profile_selected > 10) { + // NVIDIA RTX 3090 perform better with 5 + ctx.profiles[g] = (cd_ctx[w].device[q].sm_maj >= 8) ? 5 : PROFILE_DEFAULT; + } + } - // probably unstested hw, set profile to 0 - if (profile_selected == 0xff) - { - profile_selected = 0; - ctx.profiles[g] = 0; - } + // probably unstested hw, set profile to 0 + if (profile_selected == 0xff) { + profile_selected = 0; + ctx.profiles[g] = 0; + } - // with same devices will be selected the best - // but for different devices in the same platform we need the worst for now (todo) - if (ctx.profiles[q] < profile) profile = ctx.profiles[q]; - } - } + // with same devices will be selected the best + // but for different devices in the same platform we need the worst for now (todo) + if (ctx.profiles[q] < profile) profile = ctx.profiles[q]; + } + } - // profile consistency check - if (profile < 0 || profile > 10) - { - printf ("! Error: the selected profile is not allowed (%d)\n", profile); - MEMORY_FREE_OPENCL(ctx, z) - MEMORY_FREE_LIST_Z(matches, z) - MEMORY_FREE_LIST_Z(matches_found, z) - MEMORY_FREE_ALL - exit(2); - } + // profile consistency check + if (profile < 0 || profile > 10) { + printf("! Error: the selected profile is not allowed (%d)\n", profile); + MEMORY_FREE_OPENCL(ctx, z) + MEMORY_FREE_LIST_Z(matches, z) + MEMORY_FREE_LIST_Z(matches_found, z) + MEMORY_FREE_ALL + exit(2); + } - // setup, phase 3 (finis him) + // setup, phase 3 (finis him) - z = 0; + z = 0; - for (w = 0; w < ocl_platform_cnt; w++) - { - if (!cd_ctx[w].selected) continue; + for (w = 0; w < ocl_platform_cnt; w++) { + if (!cd_ctx[w].selected) continue; - for (q = 0; q < cd_ctx[w].device_cnt; q++) - { - if (!cd_ctx[w].device[q].selected) continue; + for (q = 0; q < cd_ctx[w].device_cnt; q++) { + if (!cd_ctx[w].device[q].selected) continue; - ctx.global_ws[z] = (1 << profiles[profile][1]); + ctx.global_ws[z] = (1 << profiles[profile][1]); - // the following happens with cpu devices or Apple GPU - if (ctx.local_ws[z] > 256) - { - if (cd_ctx[w].is_apple) ctx.local_ws[z] = 256; - else if (!cd_ctx[w].device[q].is_gpu) ctx.local_ws[z] = 256; - } + // the following happens with cpu devices or Apple GPU + if (ctx.local_ws[z] > 256) { + if (cd_ctx[w].is_apple) ctx.local_ws[z] = 256; + else if (!cd_ctx[w].device[q].is_gpu) ctx.local_ws[z] = 256; + } - // dow't allow gws < lws - if (ctx.global_ws[z] < ctx.local_ws[z]) ctx.local_ws[z] = ctx.global_ws[z]; + // dow't allow gws < lws + if (ctx.global_ws[z] < ctx.local_ws[z]) ctx.local_ws[z] = ctx.global_ws[z]; - if (opencl_profiling) printf ("[%zu] global_ws %zu, local_ws %zu\n", g, ctx.global_ws[z], ctx.local_ws[z]); + if (opencl_profiling) printf("[%zu] global_ws %zu, local_ws %zu\n", g, ctx.global_ws[z], ctx.local_ws[z]); - if (!ctx.force_hitag2_opencl) - { - if (!(matches[z] = (uint64_t *) calloc ((uint32_t)(ctx.global_ws[z] * WGS_MATCHES_FACTOR), sizeof (uint64_t)))) - { - printf ("[%zu] Error: calloc (matches) failed (%d): %s\n", g, errno, strerror (errno)); - MEMORY_FREE_OPENCL(ctx, z) - MEMORY_FREE_LIST(matches, z) - MEMORY_FREE_LIST(matches_found, z) - MEMORY_FREE_ALL - exit (2); - } - } - else - { - // one - if (!(matches[z] = (uint64_t *) calloc (1, sizeof (uint64_t)))) - { - printf ("[%zu] Error: calloc (matches) failed (%d): %s\n", z, errno, strerror (errno)); - MEMORY_FREE_OPENCL(ctx, z) - MEMORY_FREE_LIST(matches, z) - MEMORY_FREE_LIST(matches_found, z) - MEMORY_FREE_ALL - exit (2); - } - } + if (!ctx.force_hitag2_opencl) { + if (!(matches[z] = (uint64_t *) calloc((uint32_t)(ctx.global_ws[z] * WGS_MATCHES_FACTOR), sizeof(uint64_t)))) { + printf("[%zu] Error: calloc (matches) failed (%d): %s\n", g, errno, strerror(errno)); + MEMORY_FREE_OPENCL(ctx, z) + MEMORY_FREE_LIST(matches, z) + MEMORY_FREE_LIST(matches_found, z) + MEMORY_FREE_ALL + exit(2); + } + } else { + // one + if (!(matches[z] = (uint64_t *) calloc(1, sizeof(uint64_t)))) { + printf("[%zu] Error: calloc (matches) failed (%d): %s\n", z, errno, strerror(errno)); + MEMORY_FREE_OPENCL(ctx, z) + MEMORY_FREE_LIST(matches, z) + MEMORY_FREE_LIST(matches_found, z) + MEMORY_FREE_ALL + exit(2); + } + } - if (!(matches_found[z] = (uint32_t *) calloc (1, sizeof (uint32_t)))) - { - printf ("[%zu] Error: calloc (matches_found) failed (%d): %s\n", z, errno, strerror (errno)); - MEMORY_FREE_OPENCL(ctx, z) - MEMORY_FREE_LIST_Z(matches, z) - MEMORY_FREE_LIST(matches_found, z) - MEMORY_FREE_ALL - exit (2); - } + if (!(matches_found[z] = (uint32_t *) calloc(1, sizeof(uint32_t)))) { + printf("[%zu] Error: calloc (matches_found) failed (%d): %s\n", z, errno, strerror(errno)); + MEMORY_FREE_OPENCL(ctx, z) + MEMORY_FREE_LIST_Z(matches, z) + MEMORY_FREE_LIST(matches_found, z) + MEMORY_FREE_ALL + exit(2); + } - ctx.candidates[z] = clCreateBuffer(ctx.contexts[z], CL_MEM_READ_ONLY, sizeof(uint16_t) * ((1 << 20) * 3), NULL, NULL); - //ctx.candidates = clCreateBuffer(ctx.contexts[z], CL_MEM_READ_ONLY, sizeof(uint64_t) * ((1 << 20)), NULL, NULL); - ctx.keystreams[z] = clCreateBuffer(ctx.contexts[z], CL_MEM_READ_ONLY, VECTOR_SIZE * 32, NULL, NULL); + ctx.candidates[z] = clCreateBuffer(ctx.contexts[z], CL_MEM_READ_ONLY, sizeof(uint16_t) * ((1 << 20) * 3), NULL, NULL); + //ctx.candidates = clCreateBuffer(ctx.contexts[z], CL_MEM_READ_ONLY, sizeof(uint64_t) * ((1 << 20)), NULL, NULL); + ctx.keystreams[z] = clCreateBuffer(ctx.contexts[z], CL_MEM_READ_ONLY, VECTOR_SIZE * 32, NULL, NULL); - if (!ctx.force_hitag2_opencl) - { - ctx.matches[z] = clCreateBuffer(ctx.contexts[z], CL_MEM_WRITE_ONLY, sizeof(uint64_t) * (uint32_t)(ctx.global_ws[z]*WGS_MATCHES_FACTOR), NULL, NULL); - } - else // one - { - ctx.matches[z] = clCreateBuffer(ctx.contexts[z], CL_MEM_WRITE_ONLY, sizeof(uint64_t), NULL, NULL); - } + if (!ctx.force_hitag2_opencl) { + ctx.matches[z] = clCreateBuffer(ctx.contexts[z], CL_MEM_WRITE_ONLY, sizeof(uint64_t) * (uint32_t)(ctx.global_ws[z] * WGS_MATCHES_FACTOR), NULL, NULL); + } else { // one + ctx.matches[z] = clCreateBuffer(ctx.contexts[z], CL_MEM_WRITE_ONLY, sizeof(uint64_t), NULL, NULL); + } - ctx.matches_found[z] = clCreateBuffer(ctx.contexts[z], CL_MEM_READ_WRITE, sizeof(uint32_t), NULL, NULL); + ctx.matches_found[z] = clCreateBuffer(ctx.contexts[z], CL_MEM_READ_WRITE, sizeof(uint32_t), NULL, NULL); - if (ctx.force_hitag2_opencl) - { - ctx.checks[z] = clCreateBuffer(ctx.contexts[z], CL_MEM_READ_ONLY, sizeof(uint32_t) * 4, NULL, NULL); - if (!ctx.checks[z]) - { - printf ("[%zu] Error: invalid shared cl_mem (ctx.candidates|ctx.keystream|ctx.checks)\n", z); - MEMORY_FREE_OPENCL(ctx, z) - MEMORY_FREE_LIST_Z(matches, z) - MEMORY_FREE_LIST_Z(matches_found, z) - MEMORY_FREE_ALL - exit (3); - } - } + if (ctx.force_hitag2_opencl) { + ctx.checks[z] = clCreateBuffer(ctx.contexts[z], CL_MEM_READ_ONLY, sizeof(uint32_t) * 4, NULL, NULL); + if (!ctx.checks[z]) { + printf("[%zu] Error: invalid shared cl_mem (ctx.candidates|ctx.keystream|ctx.checks)\n", z); + MEMORY_FREE_OPENCL(ctx, z) + MEMORY_FREE_LIST_Z(matches, z) + MEMORY_FREE_LIST_Z(matches_found, z) + MEMORY_FREE_ALL + exit(3); + } + } - if (!ctx.candidates[z] || !ctx.keystreams[z]) - { - printf ("[%zu] Error: invalid shared cl_mem (ctx.candidates|ctx.keystream)\n", z); - MEMORY_FREE_OPENCL(ctx, z) - MEMORY_FREE_LIST_Z(matches, z) - MEMORY_FREE_LIST_Z(matches_found, z) - MEMORY_FREE_ALL - exit (3); - } + if (!ctx.candidates[z] || !ctx.keystreams[z]) { + printf("[%zu] Error: invalid shared cl_mem (ctx.candidates|ctx.keystream)\n", z); + MEMORY_FREE_OPENCL(ctx, z) + MEMORY_FREE_LIST_Z(matches, z) + MEMORY_FREE_LIST_Z(matches_found, z) + MEMORY_FREE_ALL + exit(3); + } - if (!ctx.matches[z] || !ctx.matches_found[z]) - { - printf ("[%zu] Error: invalid per-device cl_mem (ctx.matches or ctx.matches_found)\n", z); - MEMORY_FREE_OPENCL(ctx, z) - MEMORY_FREE_LIST_Z(matches, z) - MEMORY_FREE_LIST_Z(matches_found, z) - MEMORY_FREE_ALL - exit (3); - } + if (!ctx.matches[z] || !ctx.matches_found[z]) { + printf("[%zu] Error: invalid per-device cl_mem (ctx.matches or ctx.matches_found)\n", z); + MEMORY_FREE_OPENCL(ctx, z) + MEMORY_FREE_LIST_Z(matches, z) + MEMORY_FREE_LIST_Z(matches_found, z) + MEMORY_FREE_ALL + exit(3); + } - // Write our data set into the input array in device memory - // todo - // if z is last set CL_TRUE (blocking) else CL_FALSE (non-blocking) - // using this way, setup time can be reduced - err = clEnqueueWriteBuffer(ctx.commands[z], ctx.keystreams[z], CL_TRUE, 0, VECTOR_SIZE * 32, keystream, 0, NULL, NULL); - if (err != CL_SUCCESS) - { - printf ("[%zu] Error: clEnqueueWriteBuffer(ctx.keystream) failed (%d)\n", z, err); - MEMORY_FREE_OPENCL(ctx, z) - MEMORY_FREE_LIST_Z(matches, z) - MEMORY_FREE_LIST_Z(matches_found, z) - MEMORY_FREE_ALL - exit (3); - } + // Write our data set into the input array in device memory + // todo + // if z is last set CL_TRUE (blocking) else CL_FALSE (non-blocking) + // using this way, setup time can be reduced + err = clEnqueueWriteBuffer(ctx.commands[z], ctx.keystreams[z], CL_TRUE, 0, VECTOR_SIZE * 32, keystream, 0, NULL, NULL); + if (err != CL_SUCCESS) { + printf("[%zu] Error: clEnqueueWriteBuffer(ctx.keystream) failed (%d)\n", z, err); + MEMORY_FREE_OPENCL(ctx, z) + MEMORY_FREE_LIST_Z(matches, z) + MEMORY_FREE_LIST_Z(matches_found, z) + MEMORY_FREE_ALL + exit(3); + } - err = clEnqueueWriteBuffer(ctx.commands[z], ctx.candidates[z], CL_TRUE, 0, sizeof(uint16_t) * ((1 << 20) * 3), candidates, 0, NULL, NULL); + err = clEnqueueWriteBuffer(ctx.commands[z], ctx.candidates[z], CL_TRUE, 0, sizeof(uint16_t) * ((1 << 20) * 3), candidates, 0, NULL, NULL); // err = clEnqueueWriteBuffer(ctx.commands[z], ctx.candidates, CL_TRUE, 0, sizeof(uint64_t) * ((1 << 20)), candidates, 0, NULL, NULL); - if (err != CL_SUCCESS) - { - printf ("[%zu] Error: clEnqueueWriteBuffer(ctx.candidates) failed (%d)\n", z, err); - MEMORY_FREE_OPENCL(ctx, z) - MEMORY_FREE_LIST_Z(matches, z) - MEMORY_FREE_LIST_Z(matches_found, z) - MEMORY_FREE_ALL - exit (3); - } - - if (ctx.force_hitag2_opencl) - { - err = clEnqueueWriteBuffer(ctx.commands[z], ctx.checks[z], CL_TRUE, 0, sizeof(uint32_t) * 4, checks, 0, NULL, NULL); - if (err != CL_SUCCESS) { - printf ("[%zu] Error: clEnqueueWriteBuffer(ctx.checks) failed (%d)\n", z, err); - MEMORY_FREE_OPENCL(ctx, z) - MEMORY_FREE_LIST_Z(matches, z) - MEMORY_FREE_LIST_Z(matches_found, z) - MEMORY_FREE_ALL - exit (3); - } - } - - // Set the arguments to our compute kernel - err = clSetKernelArg (ctx.kernels[z], 1, sizeof(cl_mem), &ctx.candidates[z]); - err |= clSetKernelArg (ctx.kernels[z], 2, sizeof(cl_mem), &ctx.keystreams[z]); - err |= clSetKernelArg (ctx.kernels[z], 3, sizeof(cl_mem), &ctx.matches[z]); - if (ctx.force_hitag2_opencl) err |= clSetKernelArg (ctx.kernels[z], 5, sizeof(cl_mem), &ctx.checks[z]); - - if (err != CL_SUCCESS) { - printf ("[%zu] Error: clSetKernelArg(ctx.candidates|ctx.keystream|ctx.matches|ctx.checks) failed (%d)\n", z, err); - MEMORY_FREE_OPENCL(ctx, z) - MEMORY_FREE_LIST_Z(matches, z) - MEMORY_FREE_LIST_Z(matches_found, z) - MEMORY_FREE_ALL - exit (3); - } - - z++; - } - } - - if (build_errors > 0) - { - #if DEBUGME >= 2 - printf ("[debug] Detected build errors with %u device(s).\n", build_errors); - #endif - MEMORY_FREE_OPENCL(ctx, z) - MEMORY_FREE_LIST_Z(matches, z) - MEMORY_FREE_LIST_Z(matches_found, z) - MEMORY_FREE_ALL - exit (3); - } - - // at this point z is the max value, still usefull for free's - - #if DEBUGME > 0 - printf ("[debug] Lower profile between %u device(s) is: %d\n", selected_devices_cnt, profile); - #endif - - uint32_t max_step = profiles[profile][0]; - uint32_t chunk = profiles[profile][1]; - - #if DEBUGME > 0 - printf ("[debug] Init queue\n"); - #endif - - int ret = 0; - if ((ret = wu_queue_init (&ctx.queue_ctx, queue_type)) != 0) - { - printf ("! Error: wu_queue_init(%s) failed (%d): %s\n", wu_queue_strdesc (queue_type), ret, wu_queue_strerror (ret)); - MEMORY_FREE_OPENCL(ctx, z) - MEMORY_FREE_LIST_Z(matches, z) - MEMORY_FREE_LIST_Z(matches_found, z) - MEMORY_FREE_ALL - exit(2); - } - - #if DEBUGME > 0 - printf ("[queue] Fill queue with pre-calculated offset using profile (%d): ", profile); - #endif - - for (size_t step = 0; step < max_step; step++) wu_queue_push (&ctx.queue_ctx, step, step << chunk, max_step); - - #if DEBUGME > 0 - printf ("done\n"); - #endif - - // save selected_devices_cnt - size_t thread_count = selected_devices_cnt; - - thread_ctx_t th_ctx; - memset (&th_ctx, 0, sizeof (thread_ctx_t)); - - thread_args_t *t_arg = (thread_args_t *) calloc (thread_count, sizeof (thread_args_t)); - if (!t_arg) - { - printf ("Error: calloc (thread_args_t) failed (%d): %s\n", errno, strerror (errno)); - MEMORY_FREE_OPENCL(ctx, z) - MEMORY_FREE_LIST_Z(matches, z) - MEMORY_FREE_LIST_Z(matches_found, z) - MEMORY_FREE_ALL - exit (3); - } - - MEMORY_FREE_ADD(t_arg) - - if ((ret = thread_init (&th_ctx, ctx.thread_sched_type, thread_count)) != 0) - { - printf ("Error: thread_init(%zu) failed (%d)\n", thread_count, ret); - MEMORY_FREE_OPENCL(ctx, z) - MEMORY_FREE_LIST_Z(matches, z) - MEMORY_FREE_LIST_Z(matches_found, z) - MEMORY_FREE_ALL - exit (3); - } - - // preload constant values in threads memory, and start threads - for (z = 0; z < thread_count; z++) - { - t_arg[z].uid = uid; - t_arg[z].aR2 = aR2; - t_arg[z].nR1 = nR1; - t_arg[z].nR2 = nR2; - t_arg[z].max_step = max_step; - t_arg[z].ocl_ctx = &ctx; - t_arg[z].device_id = z; - t_arg[z].async = (ctx.thread_sched_type == THREAD_TYPE_ASYNC); - t_arg[z].thread_ctx = &th_ctx; - - if (ctx.thread_sched_type == THREAD_TYPE_ASYNC) - { - t_arg[z].matches = matches[z]; - t_arg[z].matches_found = matches_found[z]; - t_arg[z].status = TH_START; - } - } - - if (ctx.thread_sched_type == THREAD_TYPE_ASYNC) - { - if ((ret = thread_start (&th_ctx, t_arg)) != 0) - { - printf ("Error: thread_start() failed (%d): %s\n", ret, thread_strerror (ret)); - thread_destroy (&th_ctx); - MEMORY_FREE_OPENCL(ctx, z) - MEMORY_FREE_LIST_Z(matches, z) - MEMORY_FREE_LIST_Z(matches_found, z) - MEMORY_FREE_ALL - exit (3); - } - } - - #if DEBUGME >= 1 - // they now are all in TH_WAIT locked by a cond_wait - // try the normal routine - if (ctx.thread_sched_type == THREAD_TYPE_ASYNC) - { - size_t th_status_err = 0; - for (z = 0; z < thread_count; z++) - { - pthread_mutex_lock (&thread_mutexs[z]); - thread_status_t tmp = t_arg[z].status; - pthread_mutex_unlock (&thread_mutexs[z]); - - if (tmp != TH_START) - { - printf ("! Warning: Thread %zu is not in TH_START, found in %s\n", z, thread_status_strdesc (tmp)); - th_status_err++; - } - } - - if (th_status_err != 0) - { - printf ("! Warning: %zu thread(s) found in wrong initial state ...\n", th_status_err); - } - else - { - printf ("# %zu thread(s) ready\n", thread_count); - } - } - #endif // DEBUGME >= 1 - - bool found = false; - bool error = false; - bool show_overall_time = true; - - struct timeval cpu_t_start, cpu_t_end, cpu_t_result; - - fprintf (stderr, "Attack 5 - opencl - start (Max Slices %u, %s order", max_step, wu_queue_strdesc (ctx.queue_ctx.queue_type)); - - if (!verbose) fprintf (stderr, ")\n\n"); - else fprintf (stderr, ", Profile %d, Async Threads %s, HiTag2 key verify on device %s)\n\n", profile, (ctx.thread_sched_type == THREAD_TYPE_ASYNC) ? "yes" : "no", (force_hitag2_opencl) ? "yes" : "no"); - - if (gettimeofday (&cpu_t_start, NULL) == -1) - { - printf ("! gettimeofday(start) failed (%d): %s\n", errno, strerror (errno)); - show_overall_time = false; - } - - if (ctx.thread_sched_type == THREAD_TYPE_ASYNC) - { - // crack hitag key or die tryin' - unsigned int th_cnt; - - bool done = false; - - do // master - { - th_cnt = 0; - - for (z = 0; z < thread_count; z++) - { - #if TDEBUG >= 1 && DEBUGME == 1 - if (thread_count == 1) { printf ("[%zu] get status from slave ...\n", z); fflush (stdout); } - #endif - - pthread_mutex_lock (&th_ctx.thread_mutexs[z]); - thread_status_t cur_status = t_arg[z].status; - pthread_mutex_unlock (&th_ctx.thread_mutexs[z]); - - #if TDEBUG >= 1 && DEBUGME == 1 - if (thread_count == 1) { printf ("[%zu] slave status: %s\n", z, thread_status_strdesc (cur_status)); fflush (stdout); } - #endif - - if (found) - { - #if TDEBUG >= 3 - printf ("[%zu] Processing exit logic\n", z); - fflush (stdout); - #endif - - if (cur_status < TH_FOUND_KEY) - { - #if TDEBUG >= 1 - printf ("[%zu] key found from another thread, set quit\n", z); - fflush (stdout); - #endif - pthread_mutex_lock (&th_ctx.thread_mutexs[z]); - t_arg[z].status = TH_END; - t_arg[z].quit = true; - if (cur_status == TH_WAIT) pthread_cond_signal (&th_ctx.thread_conds[z]); - pthread_mutex_unlock (&th_ctx.thread_mutexs[z]); - } - else - { - if (thread_count == 1) - { - th_cnt++; - #if TDEBUG >= 1 - printf ("[%zu] Increment th_cnt: %u/%zu\n", z, th_cnt, thread_count); - fflush (stdout); - #endif - } - } - continue; - } - - if (cur_status == TH_WAIT) - { - pthread_mutex_lock (&th_ctx.thread_mutexs[z]); - - if (found) - { - #if TDEBUG >= 1 - printf ("[%zu] key is found in another thread 1\n", z); - fflush (stdout); - #endif - t_arg[z].status = TH_END; - t_arg[z].quit = true; - pthread_mutex_unlock (&th_ctx.thread_mutexs[z]); - continue; - } - - if (wu_queue_done (&ctx.queue_ctx) != QUEUE_EMPTY) - { - t_arg[z].status = TH_PROCESSING; - - #if TDEBUG >= 1 - printf ("[master] slave [%zu], I give you another try (%s)\n", z, thread_status_strdesc (t_arg[z].status)); - fflush (stdout); - #endif - - pthread_cond_signal (&th_ctx.thread_conds[z]); - pthread_mutex_unlock (&th_ctx.thread_mutexs[z]); - continue; - } - else - { - #if TDEBUG >= 1 - printf ("[master] slave [%zu], max step reached. Quit.\n", z); - fflush (stdout); - #endif - - cur_status = t_arg[z].status = TH_END; - t_arg[z].quit = true; - - pthread_cond_signal (&th_ctx.thread_conds[z]); - pthread_mutex_unlock (&th_ctx.thread_mutexs[z]); - } - } - - if (cur_status == TH_PROCESSING) - { - if (th_ctx.enable_condusleep) - { - #if TDEBUG >= 1 - printf ("[master] before pthread_cond_wait, TH_PROCESSING\n"); - #endif - pthread_mutex_lock (&th_ctx.thread_mutex_usleep); - #if TDEBUG >= 1 - printf ("[master] slave [%zu], I'm waiting you end of task, I'm in %s give me a signal.\n", z, thread_status_strdesc (t_arg[z].status)); - fflush (stdout); - #endif - pthread_cond_wait (&th_ctx.thread_cond_usleep, &th_ctx.thread_mutex_usleep); - #if TDEBUG >= 1 - printf ("[master] slave [%zu], got the signal with new state: %s.\n", z, thread_status_strdesc (t_arg[z].status)); - fflush (stdout); - #endif - - if (t_arg[z].status == TH_FOUND_KEY) found = true; - - pthread_mutex_unlock (&th_ctx.thread_mutex_usleep); - #if TDEBUG >= 1 - printf ("[master] after pthread_cond_wait, TH_PROCESSING\n"); - #endif - continue; - } - - if (found) - { - #if TDEBUG >= 1 - printf ("[master] slave [%zu], the key is found. set TH_END from TH_PROCESSING\n", z); - fflush (stdout); - #endif - - pthread_mutex_lock (&th_ctx.thread_mutexs[z]); - t_arg[z].status = TH_END; - t_arg[z].quit = true; - pthread_mutex_unlock (&th_ctx.thread_mutexs[z]); - continue; - } - } - - if (cur_status == TH_ERROR) - { - // something went wrong - pthread_mutex_lock (&th_ctx.thread_mutexs[z]); - t_arg[z].status = TH_END; - t_arg[z].quit = true; - pthread_mutex_unlock (&th_ctx.thread_mutexs[z]); - continue; - } - - // todo, do more clean exit logic - if (cur_status >= TH_FOUND_KEY) - { - th_cnt++; - - if (cur_status == TH_FOUND_KEY) - { - thread_setEnd (&th_ctx, t_arg); - found = true; - done = true; - } - } - } - - if (th_cnt == thread_count) done = true; - - } while (!done); - - // end of async engine - } - else if (ctx.thread_sched_type == THREAD_TYPE_SEQ) - { - uint32_t step = 0; - bool quit = false; - - for (step = 0; step < max_step; step += thread_count) - { - for (z = 0; z < thread_count; z++) - { - t_arg[z].r = found; - t_arg[z].matches = matches[z]; - t_arg[z].matches_found = matches_found[z]; - } - - if ((ret = thread_start (&th_ctx, t_arg)) != 0) - { - printf ("Error: thread_start() failed (%d): %s\n", ret, thread_strerror (ret)); - thread_destroy (&th_ctx); - MEMORY_FREE_OPENCL(ctx, z) - MEMORY_FREE_LIST_Z(matches, z) - MEMORY_FREE_LIST_Z(matches_found, z) - MEMORY_FREE_ALL - exit (3); - } - - // waiting threads return - thread_stop (&th_ctx); - - for (z = 0; z < th_ctx.thread_count; z++) - { - if (t_arg[z].r) found = true; - - if (t_arg[z].err) - { - error = true; - quit = true; - } - } - - if (found || quit) break; - } - } - - // if found, show the key here - for (size_t y = 0; y < thread_count; y++) - { - if (t_arg[y].r) - { - if (verbose) printf ("\n"); - - if (thread_count > 1) printf ("[%zu] ", y); - - printf ("Key found @ slice %lu/%lu: ", t_arg[y].slice, t_arg[y].max_step); - for (int i = 0; i < 6; i++) { - printf ("%02X", (uint8_t)(t_arg[y].key & 0xff)); - t_arg[y].key = t_arg[y].key >> 8; - } - printf ("\n"); - fflush (stdout); - break; - } - } - - if (show_overall_time) - { - if (gettimeofday (&cpu_t_end, NULL) == 0) - { - timersub (&cpu_t_end, &cpu_t_start, &cpu_t_result); - } - else - { - printf ("! gettimeofday(end) failed (%d): %s\n", errno, strerror (errno)); - show_overall_time = false; - } - } - - if (!found) - { - printf ("\nError. %s\n", (error) ? "something went wrong :(" : "Key not found :|"); - if (error) exit(-1); - } - - printf ("\nAttack 5 - opencl - end"); - - if (show_overall_time) printf (" in %ld.%06ld second(s).\n\n", (long int)cpu_t_result.tv_sec, (long int)cpu_t_result.tv_usec); - else printf ("\n"); - - fflush(stdout); - - #if DEBUGME > 1 - printf ("stop threads\n"); - fflush (stdout); - #endif - - thread_stop (&th_ctx); - - #if DEBUGME > 1 - printf ("destroy threads\n"); - fflush (stdout); - #endif - - if ((ret = thread_destroy (&th_ctx)) != 0) - { - #if DEBUGME > 0 - printf ("Warning: thread_destroy() failed (%d): %s\n", ret, thread_strerror (ret)); - #endif - } - - #if DEBUGME > 1 - printf ("wu_queue_destroy\n"); - fflush (stdout); - #endif - - if ((ret = wu_queue_destroy (&ctx.queue_ctx)) != 0) - { - #if DEBUGME > 0 - printf ("Warning: wu_queue_destroy() failed (%d): %s\n", ret, wu_queue_strerror (ret)); - #endif - } - - z = selected_devices_cnt - 1; - MEMORY_FREE_OPENCL(ctx, z) - MEMORY_FREE_LIST_Z(matches, z) - MEMORY_FREE_LIST_Z(matches_found, z) - MEMORY_FREE_ALL - - return (found) ? 0 : 1; + if (err != CL_SUCCESS) { + printf("[%zu] Error: clEnqueueWriteBuffer(ctx.candidates) failed (%d)\n", z, err); + MEMORY_FREE_OPENCL(ctx, z) + MEMORY_FREE_LIST_Z(matches, z) + MEMORY_FREE_LIST_Z(matches_found, z) + MEMORY_FREE_ALL + exit(3); + } + + if (ctx.force_hitag2_opencl) { + err = clEnqueueWriteBuffer(ctx.commands[z], ctx.checks[z], CL_TRUE, 0, sizeof(uint32_t) * 4, checks, 0, NULL, NULL); + if (err != CL_SUCCESS) { + printf("[%zu] Error: clEnqueueWriteBuffer(ctx.checks) failed (%d)\n", z, err); + MEMORY_FREE_OPENCL(ctx, z) + MEMORY_FREE_LIST_Z(matches, z) + MEMORY_FREE_LIST_Z(matches_found, z) + MEMORY_FREE_ALL + exit(3); + } + } + + // Set the arguments to our compute kernel + err = clSetKernelArg(ctx.kernels[z], 1, sizeof(cl_mem), &ctx.candidates[z]); + err |= clSetKernelArg(ctx.kernels[z], 2, sizeof(cl_mem), &ctx.keystreams[z]); + err |= clSetKernelArg(ctx.kernels[z], 3, sizeof(cl_mem), &ctx.matches[z]); + if (ctx.force_hitag2_opencl) err |= clSetKernelArg(ctx.kernels[z], 5, sizeof(cl_mem), &ctx.checks[z]); + + if (err != CL_SUCCESS) { + printf("[%zu] Error: clSetKernelArg(ctx.candidates|ctx.keystream|ctx.matches|ctx.checks) failed (%d)\n", z, err); + MEMORY_FREE_OPENCL(ctx, z) + MEMORY_FREE_LIST_Z(matches, z) + MEMORY_FREE_LIST_Z(matches_found, z) + MEMORY_FREE_ALL + exit(3); + } + + z++; + } + } + + if (build_errors > 0) { +#if DEBUGME >= 2 + printf("[debug] Detected build errors with %u device(s).\n", build_errors); +#endif + MEMORY_FREE_OPENCL(ctx, z) + MEMORY_FREE_LIST_Z(matches, z) + MEMORY_FREE_LIST_Z(matches_found, z) + MEMORY_FREE_ALL + exit(3); + } + + // at this point z is the max value, still usefull for free's + +#if DEBUGME > 0 + printf("[debug] Lower profile between %u device(s) is: %d\n", selected_devices_cnt, profile); +#endif + + uint32_t max_step = profiles[profile][0]; + uint32_t chunk = profiles[profile][1]; + +#if DEBUGME > 0 + printf("[debug] Init queue\n"); +#endif + + int ret = 0; + if ((ret = wu_queue_init(&ctx.queue_ctx, queue_type)) != 0) { + printf("! Error: wu_queue_init(%s) failed (%d): %s\n", wu_queue_strdesc(queue_type), ret, wu_queue_strerror(ret)); + MEMORY_FREE_OPENCL(ctx, z) + MEMORY_FREE_LIST_Z(matches, z) + MEMORY_FREE_LIST_Z(matches_found, z) + MEMORY_FREE_ALL + exit(2); + } + +#if DEBUGME > 0 + printf("[queue] Fill queue with pre-calculated offset using profile (%d): ", profile); +#endif + + for (size_t step = 0; step < max_step; step++) wu_queue_push(&ctx.queue_ctx, step, step << chunk, max_step); + +#if DEBUGME > 0 + printf("done\n"); +#endif + + // save selected_devices_cnt + size_t thread_count = selected_devices_cnt; + + thread_ctx_t th_ctx; + memset(&th_ctx, 0, sizeof(thread_ctx_t)); + + thread_args_t *t_arg = (thread_args_t *) calloc(thread_count, sizeof(thread_args_t)); + if (!t_arg) { + printf("Error: calloc (thread_args_t) failed (%d): %s\n", errno, strerror(errno)); + MEMORY_FREE_OPENCL(ctx, z) + MEMORY_FREE_LIST_Z(matches, z) + MEMORY_FREE_LIST_Z(matches_found, z) + MEMORY_FREE_ALL + exit(3); + } + + MEMORY_FREE_ADD(t_arg) + + if ((ret = thread_init(&th_ctx, ctx.thread_sched_type, thread_count)) != 0) { + printf("Error: thread_init(%zu) failed (%d)\n", thread_count, ret); + MEMORY_FREE_OPENCL(ctx, z) + MEMORY_FREE_LIST_Z(matches, z) + MEMORY_FREE_LIST_Z(matches_found, z) + MEMORY_FREE_ALL + exit(3); + } + + // preload constant values in threads memory, and start threads + for (z = 0; z < thread_count; z++) { + t_arg[z].uid = uid; + t_arg[z].aR2 = aR2; + t_arg[z].nR1 = nR1; + t_arg[z].nR2 = nR2; + t_arg[z].max_step = max_step; + t_arg[z].ocl_ctx = &ctx; + t_arg[z].device_id = z; + t_arg[z].async = (ctx.thread_sched_type == THREAD_TYPE_ASYNC); + t_arg[z].thread_ctx = &th_ctx; + + if (ctx.thread_sched_type == THREAD_TYPE_ASYNC) { + t_arg[z].matches = matches[z]; + t_arg[z].matches_found = matches_found[z]; + t_arg[z].status = TH_START; + } + } + + if (ctx.thread_sched_type == THREAD_TYPE_ASYNC) { + if ((ret = thread_start(&th_ctx, t_arg)) != 0) { + printf("Error: thread_start() failed (%d): %s\n", ret, thread_strerror(ret)); + thread_destroy(&th_ctx); + MEMORY_FREE_OPENCL(ctx, z) + MEMORY_FREE_LIST_Z(matches, z) + MEMORY_FREE_LIST_Z(matches_found, z) + MEMORY_FREE_ALL + exit(3); + } + } + +#if DEBUGME >= 1 + // they now are all in TH_WAIT locked by a cond_wait + // try the normal routine + if (ctx.thread_sched_type == THREAD_TYPE_ASYNC) { + size_t th_status_err = 0; + for (z = 0; z < thread_count; z++) { + pthread_mutex_lock(&thread_mutexs[z]); + thread_status_t tmp = t_arg[z].status; + pthread_mutex_unlock(&thread_mutexs[z]); + + if (tmp != TH_START) { + printf("! Warning: Thread %zu is not in TH_START, found in %s\n", z, thread_status_strdesc(tmp)); + th_status_err++; + } + } + + if (th_status_err != 0) { + printf("! Warning: %zu thread(s) found in wrong initial state ...\n", th_status_err); + } else { + printf("# %zu thread(s) ready\n", thread_count); + } + } +#endif // DEBUGME >= 1 + + bool found = false; + bool error = false; + bool show_overall_time = true; + + struct timeval cpu_t_start, cpu_t_end, cpu_t_result; + + fprintf(stderr, "Attack 5 - opencl - start (Max Slices %u, %s order", max_step, wu_queue_strdesc(ctx.queue_ctx.queue_type)); + + if (!verbose) fprintf(stderr, ")\n\n"); + else fprintf(stderr, ", Profile %d, Async Threads %s, HiTag2 key verify on device %s)\n\n", profile, (ctx.thread_sched_type == THREAD_TYPE_ASYNC) ? "yes" : "no", (force_hitag2_opencl) ? "yes" : "no"); + + if (gettimeofday(&cpu_t_start, NULL) == -1) { + printf("! gettimeofday(start) failed (%d): %s\n", errno, strerror(errno)); + show_overall_time = false; + } + + if (ctx.thread_sched_type == THREAD_TYPE_ASYNC) { + // crack hitag key or die tryin' + unsigned int th_cnt; + + bool done = false; + + do { // master + th_cnt = 0; + + for (z = 0; z < thread_count; z++) { +#if TDEBUG >= 1 && DEBUGME == 1 + if (thread_count == 1) { printf("[%zu] get status from slave ...\n", z); fflush(stdout); } +#endif + + pthread_mutex_lock(&th_ctx.thread_mutexs[z]); + thread_status_t cur_status = t_arg[z].status; + pthread_mutex_unlock(&th_ctx.thread_mutexs[z]); + +#if TDEBUG >= 1 && DEBUGME == 1 + if (thread_count == 1) { printf("[%zu] slave status: %s\n", z, thread_status_strdesc(cur_status)); fflush(stdout); } +#endif + + if (found) { +#if TDEBUG >= 3 + printf("[%zu] Processing exit logic\n", z); + fflush(stdout); +#endif + + if (cur_status < TH_FOUND_KEY) { +#if TDEBUG >= 1 + printf("[%zu] key found from another thread, set quit\n", z); + fflush(stdout); +#endif + pthread_mutex_lock(&th_ctx.thread_mutexs[z]); + t_arg[z].status = TH_END; + t_arg[z].quit = true; + if (cur_status == TH_WAIT) pthread_cond_signal(&th_ctx.thread_conds[z]); + pthread_mutex_unlock(&th_ctx.thread_mutexs[z]); + } else { + if (thread_count == 1) { + th_cnt++; +#if TDEBUG >= 1 + printf("[%zu] Increment th_cnt: %u/%zu\n", z, th_cnt, thread_count); + fflush(stdout); +#endif + } + } + continue; + } + + if (cur_status == TH_WAIT) { + pthread_mutex_lock(&th_ctx.thread_mutexs[z]); + + if (found) { +#if TDEBUG >= 1 + printf("[%zu] key is found in another thread 1\n", z); + fflush(stdout); +#endif + t_arg[z].status = TH_END; + t_arg[z].quit = true; + pthread_mutex_unlock(&th_ctx.thread_mutexs[z]); + continue; + } + + if (wu_queue_done(&ctx.queue_ctx) != QUEUE_EMPTY) { + t_arg[z].status = TH_PROCESSING; + +#if TDEBUG >= 1 + printf("[master] slave [%zu], I give you another try (%s)\n", z, thread_status_strdesc(t_arg[z].status)); + fflush(stdout); +#endif + + pthread_cond_signal(&th_ctx.thread_conds[z]); + pthread_mutex_unlock(&th_ctx.thread_mutexs[z]); + continue; + } else { +#if TDEBUG >= 1 + printf("[master] slave [%zu], max step reached. Quit.\n", z); + fflush(stdout); +#endif + + cur_status = t_arg[z].status = TH_END; + t_arg[z].quit = true; + + pthread_cond_signal(&th_ctx.thread_conds[z]); + pthread_mutex_unlock(&th_ctx.thread_mutexs[z]); + } + } + + if (cur_status == TH_PROCESSING) { + if (th_ctx.enable_condusleep) { +#if TDEBUG >= 1 + printf("[master] before pthread_cond_wait, TH_PROCESSING\n"); +#endif + pthread_mutex_lock(&th_ctx.thread_mutex_usleep); +#if TDEBUG >= 1 + printf("[master] slave [%zu], I'm waiting you end of task, I'm in %s give me a signal.\n", z, thread_status_strdesc(t_arg[z].status)); + fflush(stdout); +#endif + pthread_cond_wait(&th_ctx.thread_cond_usleep, &th_ctx.thread_mutex_usleep); +#if TDEBUG >= 1 + printf("[master] slave [%zu], got the signal with new state: %s.\n", z, thread_status_strdesc(t_arg[z].status)); + fflush(stdout); +#endif + + if (t_arg[z].status == TH_FOUND_KEY) found = true; + + pthread_mutex_unlock(&th_ctx.thread_mutex_usleep); +#if TDEBUG >= 1 + printf("[master] after pthread_cond_wait, TH_PROCESSING\n"); +#endif + continue; + } + + if (found) { +#if TDEBUG >= 1 + printf("[master] slave [%zu], the key is found. set TH_END from TH_PROCESSING\n", z); + fflush(stdout); +#endif + + pthread_mutex_lock(&th_ctx.thread_mutexs[z]); + t_arg[z].status = TH_END; + t_arg[z].quit = true; + pthread_mutex_unlock(&th_ctx.thread_mutexs[z]); + continue; + } + } + + if (cur_status == TH_ERROR) { + // something went wrong + pthread_mutex_lock(&th_ctx.thread_mutexs[z]); + t_arg[z].status = TH_END; + t_arg[z].quit = true; + pthread_mutex_unlock(&th_ctx.thread_mutexs[z]); + continue; + } + + // todo, do more clean exit logic + if (cur_status >= TH_FOUND_KEY) { + th_cnt++; + + if (cur_status == TH_FOUND_KEY) { + thread_setEnd(&th_ctx, t_arg); + found = true; + done = true; + } + } + } + + if (th_cnt == thread_count) done = true; + + } while (!done); + + // end of async engine + } else if (ctx.thread_sched_type == THREAD_TYPE_SEQ) { + uint32_t step = 0; + bool quit = false; + + for (step = 0; step < max_step; step += thread_count) { + for (z = 0; z < thread_count; z++) { + t_arg[z].r = found; + t_arg[z].matches = matches[z]; + t_arg[z].matches_found = matches_found[z]; + } + + if ((ret = thread_start(&th_ctx, t_arg)) != 0) { + printf("Error: thread_start() failed (%d): %s\n", ret, thread_strerror(ret)); + thread_destroy(&th_ctx); + MEMORY_FREE_OPENCL(ctx, z) + MEMORY_FREE_LIST_Z(matches, z) + MEMORY_FREE_LIST_Z(matches_found, z) + MEMORY_FREE_ALL + exit(3); + } + + // waiting threads return + thread_stop(&th_ctx); + + for (z = 0; z < th_ctx.thread_count; z++) { + if (t_arg[z].r) found = true; + + if (t_arg[z].err) { + error = true; + quit = true; + } + } + + if (found || quit) break; + } + } + + // if found, show the key here + for (size_t y = 0; y < thread_count; y++) { + if (t_arg[y].r) { + if (verbose) printf("\n"); + + if (thread_count > 1) printf("[%zu] ", y); + + printf("Key found @ slice %lu/%lu: ", t_arg[y].slice, t_arg[y].max_step); + for (int i = 0; i < 6; i++) { + printf("%02X", (uint8_t)(t_arg[y].key & 0xff)); + t_arg[y].key = t_arg[y].key >> 8; + } + printf("\n"); + fflush(stdout); + break; + } + } + + if (show_overall_time) { + if (gettimeofday(&cpu_t_end, NULL) == 0) { + timersub(&cpu_t_end, &cpu_t_start, &cpu_t_result); + } else { + printf("! gettimeofday(end) failed (%d): %s\n", errno, strerror(errno)); + show_overall_time = false; + } + } + + if (!found) { + printf("\nError. %s\n", (error) ? "something went wrong :(" : "Key not found :|"); + if (error) exit(-1); + } + + printf("\nAttack 5 - opencl - end"); + + if (show_overall_time) printf(" in %ld.%06ld second(s).\n\n", (long int)cpu_t_result.tv_sec, (long int)cpu_t_result.tv_usec); + else printf("\n"); + + fflush(stdout); + +#if DEBUGME > 1 + printf("stop threads\n"); + fflush(stdout); +#endif + + thread_stop(&th_ctx); + +#if DEBUGME > 1 + printf("destroy threads\n"); + fflush(stdout); +#endif + + if ((ret = thread_destroy(&th_ctx)) != 0) { +#if DEBUGME > 0 + printf("Warning: thread_destroy() failed (%d): %s\n", ret, thread_strerror(ret)); +#endif + } + +#if DEBUGME > 1 + printf("wu_queue_destroy\n"); + fflush(stdout); +#endif + + if ((ret = wu_queue_destroy(&ctx.queue_ctx)) != 0) { +#if DEBUGME > 0 + printf("Warning: wu_queue_destroy() failed (%d): %s\n", ret, wu_queue_strerror(ret)); +#endif + } + + z = selected_devices_cnt - 1; + MEMORY_FREE_OPENCL(ctx, z) + MEMORY_FREE_LIST_Z(matches, z) + MEMORY_FREE_LIST_Z(matches_found, z) + MEMORY_FREE_ALL + + return (found) ? 0 : 1; } diff --git a/tools/hitag2crack/crack5opencl/opencl.c b/tools/hitag2crack/crack5opencl/opencl.c index 161155b6c..a16ce0f94 100644 --- a/tools/hitag2crack/crack5opencl/opencl.c +++ b/tools/hitag2crack/crack5opencl/opencl.c @@ -24,140 +24,128 @@ License: GNU General Public License v3 or any later version (see LICENSE.txt) #include "opencl.h" -bool plat_dev_enabled (unsigned int id, unsigned int *sel, unsigned int cnt, unsigned int cur_type, unsigned int allow_type) -{ - // usefull only with devices - if (allow_type != CL_DEVICE_TYPE_ALL) - { - if (cur_type != allow_type) return false; - } +bool plat_dev_enabled(unsigned int id, unsigned int *sel, unsigned int cnt, unsigned int cur_type, unsigned int allow_type) { + // usefull only with devices + if (allow_type != CL_DEVICE_TYPE_ALL) { + if (cur_type != allow_type) return false; + } - if (sel[0] == 0xff) return true; // all - else - { - for (unsigned int i = 0; i < cnt; i++) - { - if (sel[i] == (id+1)) return true; - } - } + if (sel[0] == 0xff) return true; // all + else { + for (unsigned int i = 0; i < cnt; i++) { + if (sel[i] == (id + 1)) return true; + } + } - return false; + return false; } -int runKernel (opencl_ctx_t *ctx, uint32_t cand_base, uint64_t *matches, uint32_t *matches_found, size_t id) -{ - int err = 0; +int runKernel(opencl_ctx_t *ctx, uint32_t cand_base, uint64_t *matches, uint32_t *matches_found, size_t id) { + int err = 0; - size_t global_ws[3] = { ctx->global_ws[id], GLOBAL_WS_1, GLOBAL_WS_2 }; - size_t local_ws[3] = { ctx->local_ws[id], 1, 1 }; + size_t global_ws[3] = { ctx->global_ws[id], GLOBAL_WS_1, GLOBAL_WS_2 }; + size_t local_ws[3] = { ctx->local_ws[id], 1, 1 }; - if (ctx->profiling) - { - printf ("[%zu] global_ws %zu, ctx->local_ws: %zu\n", id, global_ws[0], local_ws[0]); - fflush (stdout); - } + if (ctx->profiling) { + printf("[%zu] global_ws %zu, ctx->local_ws: %zu\n", id, global_ws[0], local_ws[0]); + fflush(stdout); + } - *matches_found = 0; + *matches_found = 0; - // Write our data set into the input array in device memory - err = clEnqueueWriteBuffer (ctx->commands[id], ctx->matches_found[id], CL_TRUE, 0, sizeof(uint32_t), matches_found, 0, NULL, NULL); - if (err != CL_SUCCESS) { - printf ("[%zu] Error: clEnqueueWriteBuffer (matches_found) failed (%d)\n", id, err); - return -1; - } + // Write our data set into the input array in device memory + err = clEnqueueWriteBuffer(ctx->commands[id], ctx->matches_found[id], CL_TRUE, 0, sizeof(uint32_t), matches_found, 0, NULL, NULL); + if (err != CL_SUCCESS) { + printf("[%zu] Error: clEnqueueWriteBuffer (matches_found) failed (%d)\n", id, err); + return -1; + } - // Set the arguments to our compute kernel - err = clSetKernelArg (ctx->kernels[id], 0, sizeof(uint32_t), &cand_base); - err |= clSetKernelArg (ctx->kernels[id], 4, sizeof(cl_mem), &ctx->matches_found[id]); + // Set the arguments to our compute kernel + err = clSetKernelArg(ctx->kernels[id], 0, sizeof(uint32_t), &cand_base); + err |= clSetKernelArg(ctx->kernels[id], 4, sizeof(cl_mem), &ctx->matches_found[id]); - if (err != CL_SUCCESS) { - printf ("[%zu] Error: clSetKernelArg (cand_base|ctx->matches_found) failed (%d)\n", id, err); - return -1; - } + if (err != CL_SUCCESS) { + printf("[%zu] Error: clSetKernelArg (cand_base|ctx->matches_found) failed (%d)\n", id, err); + return -1; + } - cl_event event; + cl_event event; - err = clEnqueueNDRangeKernel (ctx->commands[id], ctx->kernels[id], 2, NULL, global_ws, local_ws, 0, NULL, &event); - if (err != CL_SUCCESS) { - printf ("[%zu] Error: clEnqueueNDRangeKernel() failed (%d)\n", id, err); - return -1; - } + err = clEnqueueNDRangeKernel(ctx->commands[id], ctx->kernels[id], 2, NULL, global_ws, local_ws, 0, NULL, &event); + if (err != CL_SUCCESS) { + printf("[%zu] Error: clEnqueueNDRangeKernel() failed (%d)\n", id, err); + return -1; + } - // todo, check if is possible remove - err = clFlush (ctx->commands[id]); - if (err != CL_SUCCESS) { - printf ("[%zu] Error: clFlush() failed (%d)\n", id, err); - return -1; - } + // todo, check if is possible remove + err = clFlush(ctx->commands[id]); + if (err != CL_SUCCESS) { + printf("[%zu] Error: clFlush() failed (%d)\n", id, err); + return -1; + } - if (ctx->profiling) - { - err = clWaitForEvents (1, &event); - if (err != CL_SUCCESS) { - printf ("[%zu] Error: clWaitForEvents() failed (%d)\n", id, err); - return -1; - } + if (ctx->profiling) { + err = clWaitForEvents(1, &event); + if (err != CL_SUCCESS) { + printf("[%zu] Error: clWaitForEvents() failed (%d)\n", id, err); + return -1; + } - cl_ulong gpu_t_start = 0, gpu_t_end = 0; + cl_ulong gpu_t_start = 0, gpu_t_end = 0; - err = clGetEventProfilingInfo (event, CL_PROFILING_COMMAND_START, sizeof (cl_ulong), &gpu_t_start, NULL); - err |= clGetEventProfilingInfo (event, CL_PROFILING_COMMAND_END, sizeof (cl_ulong), &gpu_t_end, NULL); - if (err != CL_SUCCESS) { - printf ("[%zu] Error: clGetEventOPENCL_PROFILINGInfo() failed (%d)\n", id, err); - return -1; - } + err = clGetEventProfilingInfo(event, CL_PROFILING_COMMAND_START, sizeof(cl_ulong), &gpu_t_start, NULL); + err |= clGetEventProfilingInfo(event, CL_PROFILING_COMMAND_END, sizeof(cl_ulong), &gpu_t_end, NULL); + if (err != CL_SUCCESS) { + printf("[%zu] Error: clGetEventOPENCL_PROFILINGInfo() failed (%d)\n", id, err); + return -1; + } - const double time_ms = (double) (gpu_t_end - gpu_t_start) / 1000000; + const double time_ms = (double)(gpu_t_end - gpu_t_start) / 1000000; - printf ("[%zu] kernel exec time (ms): %.2f]\n", id, time_ms); - fflush (stdout); - } + printf("[%zu] kernel exec time (ms): %.2f]\n", id, time_ms); + fflush(stdout); + } - err = clReleaseEvent (event); - if (err != CL_SUCCESS) { - printf ("[%zu] Error: clReleaseEvent() failed (%d)\n", id, err); - return -1; - } + err = clReleaseEvent(event); + if (err != CL_SUCCESS) { + printf("[%zu] Error: clReleaseEvent() failed (%d)\n", id, err); + return -1; + } - // Wait for the command commands to get serviced before reading back results - // todo, check if is possible remove, because of blocking clEnqueueReadBuffer (CL_TRUE) - err = clFinish (ctx->commands[id]); - if (err != CL_SUCCESS) { - printf ("[%zu] Error: clFinish() failed (%d)\n", id, err); - return -1; - } + // Wait for the command commands to get serviced before reading back results + // todo, check if is possible remove, because of blocking clEnqueueReadBuffer (CL_TRUE) + err = clFinish(ctx->commands[id]); + if (err != CL_SUCCESS) { + printf("[%zu] Error: clFinish() failed (%d)\n", id, err); + return -1; + } - // read back the matches counter first - err = clEnqueueReadBuffer (ctx->commands[id], ctx->matches_found[id], CL_TRUE, 0, sizeof(uint32_t), matches_found, 0, NULL, NULL); - if (err != CL_SUCCESS) { - printf ("[%zu] Error: clEnqueueReadBuffer(matches_found) failed (%d)\n", id, err); - return -1; - } + // read back the matches counter first + err = clEnqueueReadBuffer(ctx->commands[id], ctx->matches_found[id], CL_TRUE, 0, sizeof(uint32_t), matches_found, 0, NULL, NULL); + if (err != CL_SUCCESS) { + printf("[%zu] Error: clEnqueueReadBuffer(matches_found) failed (%d)\n", id, err); + return -1; + } - if (matches_found[0] > 0) - { - if (ctx->force_hitag2_opencl) - { - if (matches_found[0] != 1) printf ("[%zu] BUG: if match the counter must be 1. Here %u are founds\n", id, matches_found[0]); - } - else - { - if (matches_found[0] > (uint32_t)(ctx->global_ws[id]*WGS_MATCHES_FACTOR)) - { - printf ("[%zu] BUG: the next clEnqueueReadBuffer will crash. 'matches' buffer (%u) is lower than requested (%u)\n", id, (uint32_t)(ctx->global_ws[id]*WGS_MATCHES_FACTOR), matches_found[0]); - } - } + if (matches_found[0] > 0) { + if (ctx->force_hitag2_opencl) { + if (matches_found[0] != 1) printf("[%zu] BUG: if match the counter must be 1. Here %u are founds\n", id, matches_found[0]); + } else { + if (matches_found[0] > (uint32_t)(ctx->global_ws[id]*WGS_MATCHES_FACTOR)) { + printf("[%zu] BUG: the next clEnqueueReadBuffer will crash. 'matches' buffer (%u) is lower than requested (%u)\n", id, (uint32_t)(ctx->global_ws[id]*WGS_MATCHES_FACTOR), matches_found[0]); + } + } - err = clEnqueueReadBuffer(ctx->commands[id], ctx->matches[id], CL_TRUE, 0, sizeof(uint64_t) * matches_found[0], matches, 0, NULL, NULL); - if (err != CL_SUCCESS) { - printf ("[%zu] Error: clEnqueueReadBuffer(matches) failed (%d)\n", id, err); - return -1; - } + err = clEnqueueReadBuffer(ctx->commands[id], ctx->matches[id], CL_TRUE, 0, sizeof(uint64_t) * matches_found[0], matches, 0, NULL, NULL); + if (err != CL_SUCCESS) { + printf("[%zu] Error: clEnqueueReadBuffer(matches) failed (%d)\n", id, err); + return -1; + } - // key found - return 1; - } + // key found + return 1; + } - // nada - return 0; + // nada + return 0; } diff --git a/tools/hitag2crack/crack5opencl/opencl.h b/tools/hitag2crack/crack5opencl/opencl.h index e91ace290..410a7cb5a 100644 --- a/tools/hitag2crack/crack5opencl/opencl.h +++ b/tools/hitag2crack/crack5opencl/opencl.h @@ -43,87 +43,84 @@ License: GNU General Public License v3 or any later version (see LICENSE.txt) #define MAX_OPENCL_DEVICES 16 // defines structures -typedef struct compute_device_ctx -{ - char name[0xff]; - char vendor[0x40]; - char version[0x40]; - char driver_version[0x40]; +typedef struct compute_device_ctx { + char name[0xff]; + char vendor[0x40]; + char version[0x40]; + char driver_version[0x40]; - bool is_gpu, is_apple_gpu, is_nv; - bool have_lop3, have_local_memory; - bool warning, unsupported; + bool is_gpu, is_apple_gpu, is_nv; + bool have_lop3, have_local_memory; + bool warning, unsupported; - bool selected; - bool enabled; + bool selected; + bool enabled; - unsigned char pad1[4]; - unsigned int sm_maj; - unsigned int sm_min; - unsigned int compute_units; + unsigned char pad1[4]; + unsigned int sm_maj; + unsigned int sm_min; + unsigned int compute_units; - cl_device_id device_id; - cl_platform_id platform_id; + cl_device_id device_id; + cl_platform_id platform_id; } compute_device_ctx_t; -typedef struct compute_platform_ctx -{ - unsigned int device_cnt; - unsigned int compute_units_max; +typedef struct compute_platform_ctx { + unsigned int device_cnt; + unsigned int compute_units_max; - bool is_nv, is_apple, is_intel; - bool warning; - bool selected; + bool is_nv, is_apple, is_intel; + bool warning; + bool selected; - unsigned char pad1[3]; - compute_device_ctx_t device[0x10]; + unsigned char pad1[3]; + compute_device_ctx_t device[0x10]; - char name[0xff]; - char vendor[0x40]; - char version[0x40]; + char name[0xff]; + char vendor[0x40]; + char version[0x40]; - unsigned char pad2[1]; - cl_platform_id platform_id; - cl_context context; - cl_program program; + unsigned char pad2[1]; + cl_platform_id platform_id; + cl_context context; + cl_program program; } compute_platform_ctx_t; -typedef struct opencl_ctx -{ - char *kernelSource[1]; - size_t kernelSource_len; +typedef struct opencl_ctx { + char *kernelSource[1]; + size_t kernelSource_len; - size_t *global_ws; - size_t *local_ws; - int *profiles; + size_t *global_ws; + size_t *local_ws; + int *profiles; - cl_device_id *device_ids; // compute device id's array - cl_context *contexts; // compute contexts - cl_command_queue *commands; // compute command queue (for each device) - cl_program *programs; // compute program's - cl_kernel *kernels; // compute kernel's + cl_device_id *device_ids; // compute device id's array + cl_context *contexts; // compute contexts + cl_command_queue *commands; // compute command queue (for each device) + cl_program *programs; // compute program's + cl_kernel *kernels; // compute kernel's // cl_mem cand_base; // device memory used for the candidate base - cl_mem *keystreams; // device memory used for the keystream array - cl_mem *candidates; // device memory used for the candidates array - cl_mem *matches; // device memory used for the matches array - cl_mem *matches_found; // device memory used for the matches_found array - cl_mem *checks; // device memory used for uid, aR2, nR1, nR2 + cl_mem *keystreams; // device memory used for the keystream array + cl_mem *candidates; // device memory used for the candidates array + cl_mem *matches; // device memory used for the matches array + cl_mem *matches_found; // device memory used for the matches_found array + cl_mem *checks; // device memory used for uid, aR2, nR1, nR2 - wu_queue_ctx_t queue_ctx; - bool profiling; - unsigned char pad2[1]; - short thread_sched_type; - bool force_hitag2_opencl; + wu_queue_ctx_t queue_ctx; + bool profiling; + unsigned char pad2[1]; + short thread_sched_type; + bool force_hitag2_opencl; - unsigned char pad3[3]; + unsigned char pad3[3]; } opencl_ctx_t; -bool plat_dev_enabled (unsigned int id, unsigned int *sel, unsigned int cnt, unsigned int cur_type, unsigned int allow_type); +bool plat_dev_enabled(unsigned int id, unsigned int *sel, unsigned int cnt, unsigned int cur_type, unsigned int allow_type); -int runKernel (opencl_ctx_t *ctx, uint32_t cand_base, uint64_t *matches, uint32_t *matches_found, size_t id); +int runKernel(opencl_ctx_t *ctx, uint32_t cand_base, uint64_t *matches, uint32_t *matches_found, size_t id); #endif // OPENCL_H diff --git a/tools/hitag2crack/crack5opencl/queue.c b/tools/hitag2crack/crack5opencl/queue.c index c32f1dbba..ee289f552 100644 --- a/tools/hitag2crack/crack5opencl/queue.c +++ b/tools/hitag2crack/crack5opencl/queue.c @@ -25,527 +25,493 @@ License: GNU General Public License v3 or any later version (see LICENSE.txt) #include "queue.h" #if TEST_UNIT == 1 -int wu_queue_print (wu_queue_ctx_t *ctx) -{ - wu_queue_item_t *ptr = 0; //NULL; - size_t sum = 0; - int ret = -1; +int wu_queue_print(wu_queue_ctx_t *ctx) { + wu_queue_item_t *ptr = 0; //NULL; + size_t sum = 0; + int ret = -1; - if (!ctx) return -1; - if (!ctx->init) return ERROR_CTX_IS_NOT_INIT; + if (!ctx) return -1; + if (!ctx->init) return ERROR_CTX_IS_NOT_INIT; - pthread_mutex_lock (&ctx->queue_mutex); + pthread_mutex_lock(&ctx->queue_mutex); - if ((ret = wu_queue_done (ctx)) != 0) - { - pthread_mutex_unlock (&ctx->queue_mutex); - return ret; - } + if ((ret = wu_queue_done(ctx)) != 0) { + pthread_mutex_unlock(&ctx->queue_mutex); + return ret; + } - switch (ctx->queue_type) - { - case QUEUE_TYPE_FORWARD: - ptr = ctx->queue_head; - printf ("> show queue contents in FORWARD mode, from head\n"); - break; - case QUEUE_TYPE_REVERSE: - ptr = ctx->queue_tail; - printf ("> show queue contents in REVERSE mode, from tail\n"); - break; - case QUEUE_TYPE_RANDOM: - ptr = ctx->queue_head; - printf ("> show queue contents in RANDOM mode, from head\n"); - default: - pthread_mutex_unlock (&ctx->queue_mutex); - return ERROR_QUEUE_TYPE_INVALID; - } + switch (ctx->queue_type) { + case QUEUE_TYPE_FORWARD: + ptr = ctx->queue_head; + printf("> show queue contents in FORWARD mode, from head\n"); + break; + case QUEUE_TYPE_REVERSE: + ptr = ctx->queue_tail; + printf("> show queue contents in REVERSE mode, from tail\n"); + break; + case QUEUE_TYPE_RANDOM: + ptr = ctx->queue_head; + printf("> show queue contents in RANDOM mode, from head\n"); + default: + pthread_mutex_unlock(&ctx->queue_mutex); + return ERROR_QUEUE_TYPE_INVALID; + } - int cnt = 0; + int cnt = 0; - printf ("# Queue size: %zu\n", ctx->queue_size); + printf("# Queue size: %zu\n", ctx->queue_size); - do - { - sum += ptr->data.id; + do { + sum += ptr->data.id; - if (cnt++ < 4) printf ("# ID %zu, OFF %zu, MAX %zu\n", ptr->data.id, ptr->data.off, ptr->data.max); + if (cnt++ < 4) printf("# ID %zu, OFF %zu, MAX %zu\n", ptr->data.id, ptr->data.off, ptr->data.max); - if (ctx->queue_type == QUEUE_TYPE_FORWARD || ctx->queue_type == QUEUE_TYPE_RANDOM) - { - if (!ptr->next) break; - ptr = ptr->next; - } - else if (ctx->queue_type == QUEUE_TYPE_REVERSE) - { - if (!ptr->prev) break; - ptr = ptr->prev; - } + if (ctx->queue_type == QUEUE_TYPE_FORWARD || ctx->queue_type == QUEUE_TYPE_RANDOM) { + if (!ptr->next) break; + ptr = ptr->next; + } else if (ctx->queue_type == QUEUE_TYPE_REVERSE) { + if (!ptr->prev) break; + ptr = ptr->prev; + } - } while (ptr); + } while (ptr); - if (!ptr) - { - printf ("! Fail: ptr must be not null here\n"); - pthread_mutex_unlock (&ctx->queue_mutex); - return -1; - } + if (!ptr) { + printf("! Fail: ptr must be not null here\n"); + pthread_mutex_unlock(&ctx->queue_mutex); + return -1; + } - switch (ctx->queue_type) - { - case QUEUE_TYPE_RANDOM: - printf ("> show queue contents in RANDOM mode, from end to head\n"); - break; - case QUEUE_TYPE_FORWARD: - printf ("> show queue contents in FORWARD mode, from end to head\n"); - break; - case QUEUE_TYPE_REVERSE: - printf ("> show queue contents in REVERSE mode, from start to tail\n"); - break; - } + switch (ctx->queue_type) { + case QUEUE_TYPE_RANDOM: + printf("> show queue contents in RANDOM mode, from end to head\n"); + break; + case QUEUE_TYPE_FORWARD: + printf("> show queue contents in FORWARD mode, from end to head\n"); + break; + case QUEUE_TYPE_REVERSE: + printf("> show queue contents in REVERSE mode, from start to tail\n"); + break; + } - cnt = 0; + cnt = 0; - do - { - sum -= ptr->data.id; - if (cnt++ < 4) printf ("# ID %zu, OFF %zu, MAX %zu\n", ptr->data.id, ptr->data.off, ptr->data.max); + do { + sum -= ptr->data.id; + if (cnt++ < 4) printf("# ID %zu, OFF %zu, MAX %zu\n", ptr->data.id, ptr->data.off, ptr->data.max); - if (ctx->queue_type == QUEUE_TYPE_FORWARD || ctx->queue_type == QUEUE_TYPE_RANDOM) - { - if (!ptr->prev) break; - ptr = ptr->prev; - } - else if (ctx->queue_type == QUEUE_TYPE_REVERSE) - { - if (!ptr->next) break; - ptr = ptr->next; - } + if (ctx->queue_type == QUEUE_TYPE_FORWARD || ctx->queue_type == QUEUE_TYPE_RANDOM) { + if (!ptr->prev) break; + ptr = ptr->prev; + } else if (ctx->queue_type == QUEUE_TYPE_REVERSE) { + if (!ptr->next) break; + ptr = ptr->next; + } - } while (ptr); + } while (ptr); - if (sum != 0) - { - printf ("! Fail: sum is not zero\n"); - pthread_mutex_unlock (&ctx->queue_mutex); - return -1; - } + if (sum != 0) { + printf("! Fail: sum is not zero\n"); + pthread_mutex_unlock(&ctx->queue_mutex); + return -1; + } - pthread_mutex_unlock (&ctx->queue_mutex); - return 0; + pthread_mutex_unlock(&ctx->queue_mutex); + return 0; } #endif -const char *wu_queue_strerror (int error) -{ - switch (error) - { - case QUEUE_EMPTY: return (const char *) "QUERY_EMPTY"; - case NO_ERROR: return (const char *) "NO_ERROR"; - case ERROR_GENERIC: return (const char *) "ERROR_GENERIC"; - case ERROR_QUEUE_TYPE_INVALID: return (const char *) "ERROR_QUEUE_TYPE_INVALID"; - case ERROR_CTX_NULL: return (const char *) "ERROR_CTX_NULL"; - case ERROR_CTX_IS_INIT: return (const char *) "ERROR_CTX_IS_INIT"; - case ERROR_CTX_IS_NOT_INIT: return (const char *) "ERROR_CTX_IS_NOT_INIT"; - case ERROR_MUTEXATTR_INIT: return (const char *) "ERROR_MUTEXATTR_INIT"; - case ERROR_MUTEXATTR_SETTYPE: return (const char *) "ERROR_MUTEXATTR_SETTYPE"; - case ERROR_MUTEX_INIT: return (const char *) "ERROR_MUTEX_INIT"; - case ERROR_ALLOC: return (const char *) "ERROR_ALLOC"; - case ERROR_UNDEFINED: - default: - return (const char *) "ERROR_UNDEFINED"; - } +const char *wu_queue_strerror(int error) { + switch (error) { + case QUEUE_EMPTY: + return (const char *) "QUERY_EMPTY"; + case NO_ERROR: + return (const char *) "NO_ERROR"; + case ERROR_GENERIC: + return (const char *) "ERROR_GENERIC"; + case ERROR_QUEUE_TYPE_INVALID: + return (const char *) "ERROR_QUEUE_TYPE_INVALID"; + case ERROR_CTX_NULL: + return (const char *) "ERROR_CTX_NULL"; + case ERROR_CTX_IS_INIT: + return (const char *) "ERROR_CTX_IS_INIT"; + case ERROR_CTX_IS_NOT_INIT: + return (const char *) "ERROR_CTX_IS_NOT_INIT"; + case ERROR_MUTEXATTR_INIT: + return (const char *) "ERROR_MUTEXATTR_INIT"; + case ERROR_MUTEXATTR_SETTYPE: + return (const char *) "ERROR_MUTEXATTR_SETTYPE"; + case ERROR_MUTEX_INIT: + return (const char *) "ERROR_MUTEX_INIT"; + case ERROR_ALLOC: + return (const char *) "ERROR_ALLOC"; + case ERROR_UNDEFINED: + default: + return (const char *) "ERROR_UNDEFINED"; + } } -const char *wu_queue_strdesc (wu_queue_type_t type) -{ - switch (type) - { - case QUEUE_TYPE_FORWARD: return (const char *) "FORWARD"; - case QUEUE_TYPE_REVERSE: return (const char *) "REVERSE"; - case QUEUE_TYPE_RANDOM: return (const char *) "RANDOM"; - } +const char *wu_queue_strdesc(wu_queue_type_t type) { + switch (type) { + case QUEUE_TYPE_FORWARD: + return (const char *) "FORWARD"; + case QUEUE_TYPE_REVERSE: + return (const char *) "REVERSE"; + case QUEUE_TYPE_RANDOM: + return (const char *) "RANDOM"; + } - return (const char *) "UNKNOWN"; + return (const char *) "UNKNOWN"; } -int wu_queue_init (wu_queue_ctx_t *ctx, wu_queue_type_t queue_type) -{ - #if TEST_UNIT == 1 - fprintf (stdout, "[%s] enter\n", __func__); - fflush (stdout); - #endif +int wu_queue_init(wu_queue_ctx_t *ctx, wu_queue_type_t queue_type) { +#if TEST_UNIT == 1 + fprintf(stdout, "[%s] enter\n", __func__); + fflush(stdout); +#endif - if (!ctx) return ERROR_CTX_NULL; + if (!ctx) return ERROR_CTX_NULL; - // Conditional jump or move depends on uninitialised value(s). It's good as it - if (ctx->init) return ERROR_CTX_IS_INIT; + // Conditional jump or move depends on uninitialised value(s). It's good as it + if (ctx->init) return ERROR_CTX_IS_INIT; - if (queue_type == QUEUE_TYPE_RANDOM) srand ((unsigned int) time(0)); - else if (queue_type != QUEUE_TYPE_FORWARD && queue_type != QUEUE_TYPE_REVERSE) - { - #if TEST_UNIT == 1 - fprintf (stderr, "! Error, invalid 'queue_type'.\n"); - #endif - return ERROR_QUEUE_TYPE_INVALID; - } + if (queue_type == QUEUE_TYPE_RANDOM) srand((unsigned int) time(0)); + else if (queue_type != QUEUE_TYPE_FORWARD && queue_type != QUEUE_TYPE_REVERSE) { +#if TEST_UNIT == 1 + fprintf(stderr, "! Error, invalid 'queue_type'.\n"); +#endif + return ERROR_QUEUE_TYPE_INVALID; + } - memset (ctx, 0, sizeof (wu_queue_ctx_t)); - ctx->queue_type = queue_type; - ctx->queue_head = 0; //NULL; - ctx->queue_tail = 0; //NULL; + memset(ctx, 0, sizeof(wu_queue_ctx_t)); + ctx->queue_type = queue_type; + ctx->queue_head = 0; //NULL; + ctx->queue_tail = 0; //NULL; - int ret = 0; + int ret = 0; - if ((ret = pthread_mutexattr_init (&ctx->queue_mutex_attr)) != 0) - { - #if TEST_UNIT == 1 - fprintf (stderr, "! Error, pthread_mutexattr_init() failed (%d): %s\n", ret, strerror (ret)); - #endif - memset (ctx, 0, sizeof (wu_queue_ctx_t)); - return ERROR_MUTEXATTR_INIT; - } + if ((ret = pthread_mutexattr_init(&ctx->queue_mutex_attr)) != 0) { +#if TEST_UNIT == 1 + fprintf(stderr, "! Error, pthread_mutexattr_init() failed (%d): %s\n", ret, strerror(ret)); +#endif + memset(ctx, 0, sizeof(wu_queue_ctx_t)); + return ERROR_MUTEXATTR_INIT; + } - if ((ret = pthread_mutexattr_settype (&ctx->queue_mutex_attr, PTHREAD_MUTEX_ERRORCHECK)) != 0) - { - #if TEST_UNIT == 1 - fprintf (stderr, "! Error, pthread_mutexattr_settype(PTHREAD_MUTEX_ERRORCHECK) failed (%d): %s\n", ret, strerror (ret)); - #endif - pthread_mutexattr_destroy (&ctx->queue_mutex_attr); - memset (ctx, 0, sizeof (wu_queue_ctx_t)); - return ERROR_MUTEXATTR_SETTYPE; - } + if ((ret = pthread_mutexattr_settype(&ctx->queue_mutex_attr, PTHREAD_MUTEX_ERRORCHECK)) != 0) { +#if TEST_UNIT == 1 + fprintf(stderr, "! Error, pthread_mutexattr_settype(PTHREAD_MUTEX_ERRORCHECK) failed (%d): %s\n", ret, strerror(ret)); +#endif + pthread_mutexattr_destroy(&ctx->queue_mutex_attr); + memset(ctx, 0, sizeof(wu_queue_ctx_t)); + return ERROR_MUTEXATTR_SETTYPE; + } - if ((ret = pthread_mutex_init (&ctx->queue_mutex, &ctx->queue_mutex_attr)) != 0) - { - #if TEST_UNIT == 1 - fprintf (stderr, "! Error, pthread_mutex_init() failed (%d): %s\n", ret, strerror (ret)); - #endif - pthread_mutexattr_destroy (&ctx->queue_mutex_attr); - memset (ctx, 0, sizeof (wu_queue_ctx_t)); - return ERROR_MUTEX_INIT; - } + if ((ret = pthread_mutex_init(&ctx->queue_mutex, &ctx->queue_mutex_attr)) != 0) { +#if TEST_UNIT == 1 + fprintf(stderr, "! Error, pthread_mutex_init() failed (%d): %s\n", ret, strerror(ret)); +#endif + pthread_mutexattr_destroy(&ctx->queue_mutex_attr); + memset(ctx, 0, sizeof(wu_queue_ctx_t)); + return ERROR_MUTEX_INIT; + } - ctx->init = 1; - return NO_ERROR; + ctx->init = 1; + return NO_ERROR; } -int wu_queue_done (wu_queue_ctx_t *ctx) -{ - if (!ctx) return ERROR_CTX_NULL; - if (!ctx->init) return ERROR_CTX_IS_NOT_INIT; +int wu_queue_done(wu_queue_ctx_t *ctx) { + if (!ctx) return ERROR_CTX_NULL; + if (!ctx->init) return ERROR_CTX_IS_NOT_INIT; - switch (ctx->queue_type) - { - case QUEUE_TYPE_RANDOM: return (ctx->queue_head == NULL); - case QUEUE_TYPE_FORWARD: return (ctx->queue_head == NULL); - case QUEUE_TYPE_REVERSE: return (ctx->queue_tail == NULL); - } + switch (ctx->queue_type) { + case QUEUE_TYPE_RANDOM: + return (ctx->queue_head == NULL); + case QUEUE_TYPE_FORWARD: + return (ctx->queue_head == NULL); + case QUEUE_TYPE_REVERSE: + return (ctx->queue_tail == NULL); + } - return ERROR_QUEUE_TYPE_INVALID; + return ERROR_QUEUE_TYPE_INVALID; } -int wu_queue_push (wu_queue_ctx_t *ctx, size_t id, size_t off, size_t max) -{ - if (!ctx) return ERROR_CTX_NULL; - if (!ctx->init) return ERROR_CTX_IS_NOT_INIT; +int wu_queue_push(wu_queue_ctx_t *ctx, size_t id, size_t off, size_t max) { + if (!ctx) return ERROR_CTX_NULL; + if (!ctx->init) return ERROR_CTX_IS_NOT_INIT; - pthread_mutex_lock (&ctx->queue_mutex); + pthread_mutex_lock(&ctx->queue_mutex); - wu_queue_item_t *ptr = 0; //NULL; + wu_queue_item_t *ptr = 0; //NULL; - short first = 0; + short first = 0; - if (ctx->queue_head == 0) first = 1; + if (ctx->queue_head == 0) first = 1; - if (!(ptr = (wu_queue_item_t *) malloc (sizeof (wu_queue_item_t)))) - { - #if TEST_UNIT == 1 - fprintf (stderr, "! Error: malloc() failed (%d): %s\n", errno, strerror (errno)); - #endif - pthread_mutex_unlock (&ctx->queue_mutex); - return ERROR_ALLOC; - } + if (!(ptr = (wu_queue_item_t *) malloc(sizeof(wu_queue_item_t)))) { +#if TEST_UNIT == 1 + fprintf(stderr, "! Error: malloc() failed (%d): %s\n", errno, strerror(errno)); +#endif + pthread_mutex_unlock(&ctx->queue_mutex); + return ERROR_ALLOC; + } - ptr->data.id = id; - ptr->data.off = off; - ptr->data.max = max; - ptr->next = 0; //NULL; - ptr->prev = 0; //NULL; + ptr->data.id = id; + ptr->data.off = off; + ptr->data.max = max; + ptr->next = 0; //NULL; + ptr->prev = 0; //NULL; - if (first) { - ctx->queue_head = ptr; - ctx->queue_tail = ptr; - ctx->queue_size++; - pthread_mutex_unlock (&ctx->queue_mutex); - return NO_ERROR; - } + if (first) { + ctx->queue_head = ptr; + ctx->queue_tail = ptr; + ctx->queue_size++; + pthread_mutex_unlock(&ctx->queue_mutex); + return NO_ERROR; + } - // set tail - ptr->prev = ctx->queue_tail; - ctx->queue_tail = ptr; + // set tail + ptr->prev = ctx->queue_tail; + ctx->queue_tail = ptr; - // set head - wu_queue_item_t *last = ctx->queue_head; - while (last->next != 0) last = last->next; - last->next = ptr; + // set head + wu_queue_item_t *last = ctx->queue_head; + while (last->next != 0) last = last->next; + last->next = ptr; - ctx->queue_size++; - pthread_mutex_unlock (&ctx->queue_mutex); - return NO_ERROR; + ctx->queue_size++; + pthread_mutex_unlock(&ctx->queue_mutex); + return NO_ERROR; } -int wu_queue_pop (wu_queue_ctx_t *ctx, wu_queue_data_t *wu, short remove) -{ - if (!ctx) return ERROR_CTX_NULL; - if (!ctx->init) return ERROR_CTX_IS_NOT_INIT; +int wu_queue_pop(wu_queue_ctx_t *ctx, wu_queue_data_t *wu, short remove) { + if (!ctx) return ERROR_CTX_NULL; + if (!ctx->init) return ERROR_CTX_IS_NOT_INIT; - int ret = -1; - int rnd = 0; - wu_queue_item_t *ptr = 0, *ptrPrev = 0; + int ret = -1; + int rnd = 0; + wu_queue_item_t *ptr = 0, *ptrPrev = 0; - pthread_mutex_lock (&ctx->queue_mutex); + pthread_mutex_lock(&ctx->queue_mutex); - if ((ret = wu_queue_done (ctx)) != 0) - { - #if TEST_UNIT == 1 - fprintf (stderr, "ret from wu_queue_done() (%d): %s\n", ret, wu_queue_strerror (ret)); - #endif - pthread_mutex_unlock (&ctx->queue_mutex); - return ret; - } + if ((ret = wu_queue_done(ctx)) != 0) { +#if TEST_UNIT == 1 + fprintf(stderr, "ret from wu_queue_done() (%d): %s\n", ret, wu_queue_strerror(ret)); +#endif + pthread_mutex_unlock(&ctx->queue_mutex); + return ret; + } - switch (ctx->queue_type) - { - case QUEUE_TYPE_FORWARD: - ptr = ctx->queue_head; - break; - case QUEUE_TYPE_REVERSE: - ptr = ctx->queue_tail; - break; - case QUEUE_TYPE_RANDOM: - ptr = ctx->queue_head; - rnd = rand() % (int) ctx->queue_size; - for (int r = 0; r < rnd; r++) - { - ptrPrev = ptr; - ptr = ptr->next; - } - break; - } + switch (ctx->queue_type) { + case QUEUE_TYPE_FORWARD: + ptr = ctx->queue_head; + break; + case QUEUE_TYPE_REVERSE: + ptr = ctx->queue_tail; + break; + case QUEUE_TYPE_RANDOM: + ptr = ctx->queue_head; + rnd = rand() % (int) ctx->queue_size; + for (int r = 0; r < rnd; r++) { + ptrPrev = ptr; + ptr = ptr->next; + } + break; + } - if (!ptr) - { - pthread_mutex_unlock (&ctx->queue_mutex); - return ERROR_GENERIC; - } + if (!ptr) { + pthread_mutex_unlock(&ctx->queue_mutex); + return ERROR_GENERIC; + } - if (!remove) - { - wu->id = ptr->data.id; - wu->off = ptr->data.off; - wu->max = ptr->data.max; - } + if (!remove) { + wu->id = ptr->data.id; + wu->off = ptr->data.off; + wu->max = ptr->data.max; + } - switch (ctx->queue_type) - { - case QUEUE_TYPE_FORWARD: - ctx->queue_head = (ctx->queue_head)->next; - break; - case QUEUE_TYPE_REVERSE: - ctx->queue_tail = (ctx->queue_tail)->prev; - break; - case QUEUE_TYPE_RANDOM: // from the head - #if TEST_UNIT == 1 - fprintf (stdout, "pop id %ld\n", wu->id); - fflush (stdout); - #endif - if (ptrPrev == NULL) - { - ctx->queue_head = (ctx->queue_head)->next; - } - else - { - ptrPrev->next = ptr->next; - } - break; - } + switch (ctx->queue_type) { + case QUEUE_TYPE_FORWARD: + ctx->queue_head = (ctx->queue_head)->next; + break; + case QUEUE_TYPE_REVERSE: + ctx->queue_tail = (ctx->queue_tail)->prev; + break; + case QUEUE_TYPE_RANDOM: // from the head +#if TEST_UNIT == 1 + fprintf(stdout, "pop id %ld\n", wu->id); + fflush(stdout); +#endif + if (ptrPrev == NULL) { + ctx->queue_head = (ctx->queue_head)->next; + } else { + ptrPrev->next = ptr->next; + } + break; + } - memset (ptr, 0, sizeof (wu_queue_item_t)); - free (ptr); - ptr = 0; //NULL; + memset(ptr, 0, sizeof(wu_queue_item_t)); + free(ptr); + ptr = 0; //NULL; - ctx->queue_size--; + ctx->queue_size--; - if (!remove) wu->rem = ctx->queue_size; + if (!remove) wu->rem = ctx->queue_size; - pthread_mutex_unlock (&ctx->queue_mutex); - return NO_ERROR; + pthread_mutex_unlock(&ctx->queue_mutex); + return NO_ERROR; } -int wu_queue_destroy (wu_queue_ctx_t *ctx) -{ - #if TEST_UNIT == 1 - fprintf (stdout, "[%s] enter\n", __func__); - fflush (stdout); - #endif +int wu_queue_destroy(wu_queue_ctx_t *ctx) { +#if TEST_UNIT == 1 + fprintf(stdout, "[%s] enter\n", __func__); + fflush(stdout); +#endif - if (!ctx) return ERROR_CTX_NULL; - if (!ctx->init) return ERROR_CTX_IS_NOT_INIT; + if (!ctx) return ERROR_CTX_NULL; + if (!ctx->init) return ERROR_CTX_IS_NOT_INIT; - pthread_mutex_lock (&ctx->queue_mutex); + pthread_mutex_lock(&ctx->queue_mutex); - int ret = -1; + int ret = -1; - // unload the queue - while ((ret = wu_queue_pop (ctx, 0, 1)) == 0) {}; + // unload the queue + while ((ret = wu_queue_pop(ctx, 0, 1)) == 0) {}; - if (ret != QUEUE_EMPTY) - { - #if TEST_UNIT - fprintf (stderr, "! Error, wu_queue_pop() failed (%d): %s\n", ret, wu_queue_strerror (ret)); - #endif - return ret; - } + if (ret != QUEUE_EMPTY) { +#if TEST_UNIT + fprintf(stderr, "! Error, wu_queue_pop() failed (%d): %s\n", ret, wu_queue_strerror(ret)); +#endif + return ret; + } - #if TEST_UNIT == 1 - printf ("ret from wu_queue_pop() (%d): %s\n", ret, wu_queue_strerror (ret)); - #endif +#if TEST_UNIT == 1 + printf("ret from wu_queue_pop() (%d): %s\n", ret, wu_queue_strerror(ret)); +#endif - #if TEST_UNIT == 1 - if (ctx->queue_head != 0) fprintf (stderr, "queue_head not null\n"); - if (ctx->queue_tail != 0) fprintf (stderr, "queue_tail not null\n"); - #endif +#if TEST_UNIT == 1 + if (ctx->queue_head != 0) fprintf(stderr, "queue_head not null\n"); + if (ctx->queue_tail != 0) fprintf(stderr, "queue_tail not null\n"); +#endif - ctx->queue_head = 0; //NULL; - ctx->queue_tail = 0; //NULL; - ctx->init = 0; + ctx->queue_head = 0; //NULL; + ctx->queue_tail = 0; //NULL; + ctx->init = 0; - pthread_mutex_unlock (&ctx->queue_mutex); + pthread_mutex_unlock(&ctx->queue_mutex); - pthread_mutex_destroy (&ctx->queue_mutex); - pthread_mutexattr_destroy (&ctx->queue_mutex_attr); + pthread_mutex_destroy(&ctx->queue_mutex); + pthread_mutexattr_destroy(&ctx->queue_mutex_attr); - memset (ctx, 0, sizeof (wu_queue_ctx_t)); - //ctx = 0; //NULL; + memset(ctx, 0, sizeof(wu_queue_ctx_t)); + //ctx = 0; //NULL; - return (ret == 1) ? NO_ERROR : ERROR_GENERIC; + return (ret == 1) ? NO_ERROR : ERROR_GENERIC; } #if TEST_UNIT == 1 -int main (void) -{ - unsigned int profiles[11][2] = - { - { 16384, 5 }, // 0, best for Intel GPU's with Neo - { 8192, 6 }, // 1, only for Intel NEO - { 4096, 7 }, // 2 (old 0) seems the best for all others (also NVIDIA) :D Apple/Intel GPU's stable here - { 2048, 8 }, // 3 (old 1) usefull for any kind of CPU's - { 1024, 9 }, - { 512, 10 }, - { 256, 11 }, - { 128, 12 }, // 7, (old 5) the last good value with NVIDIA GPU's - { 64, 13 }, - { 32, 14 }, - { 16, 15 }, - }; +int main(void) { + unsigned int profiles[11][2] = { + { 16384, 5 }, // 0, best for Intel GPU's with Neo + { 8192, 6 }, // 1, only for Intel NEO + { 4096, 7 }, // 2 (old 0) seems the best for all others (also NVIDIA) :D Apple/Intel GPU's stable here + { 2048, 8 }, // 3 (old 1) usefull for any kind of CPU's + { 1024, 9 }, + { 512, 10 }, + { 256, 11 }, + { 128, 12 }, // 7, (old 5) the last good value with NVIDIA GPU's + { 64, 13 }, + { 32, 14 }, + { 16, 15 }, + }; - size_t err = 0, err_max = 1; - size_t id = 0; - size_t max = profiles[0][0]; - size_t chunk = profiles[0][1]; - size_t sum = 0; - int i = 0; + size_t err = 0, err_max = 1; + size_t id = 0; + size_t max = profiles[0][0]; + size_t chunk = profiles[0][1]; + size_t sum = 0; + int i = 0; - wu_queue_ctx_t ctx; - memset (&ctx, 0, sizeof (wu_queue_ctx_t)); + wu_queue_ctx_t ctx; + memset(&ctx, 0, sizeof(wu_queue_ctx_t)); - printf("Selected the following config: max %zu, chunk %zu\n", max, chunk); - fflush (stdout); + printf("Selected the following config: max %zu, chunk %zu\n", max, chunk); + fflush(stdout); - wu_queue_type_t types[4] = { QUEUE_TYPE_FORWARD, QUEUE_TYPE_REVERSE, QUEUE_TYPE_RANDOM, 1234 }; - int types_max = (int) (sizeof (types) / sizeof (wu_queue_type_t)); - int ret = 0; + wu_queue_type_t types[4] = { QUEUE_TYPE_FORWARD, QUEUE_TYPE_REVERSE, QUEUE_TYPE_RANDOM, 1234 }; + int types_max = (int)(sizeof(types) / sizeof(wu_queue_type_t)); + int ret = 0; - for (i = 0; i < types_max; i++) - { - printf ("[%d] trying wu_queue_init() in %s mode\n", i, wu_queue_strdesc (types[i])); + for (i = 0; i < types_max; i++) { + printf("[%d] trying wu_queue_init() in %s mode\n", i, wu_queue_strdesc(types[i])); - if ((ret = wu_queue_init (&ctx, types[i])) != 0) - { - fprintf (stderr, "[%d] Error: wu_queue_init(%s) failed (%d): %s\n", i, wu_queue_strdesc (types[i]), ret, wu_queue_strerror (ret)); - err++; - continue; - } + if ((ret = wu_queue_init(&ctx, types[i])) != 0) { + fprintf(stderr, "[%d] Error: wu_queue_init(%s) failed (%d): %s\n", i, wu_queue_strdesc(types[i]), ret, wu_queue_strerror(ret)); + err++; + continue; + } - printf ("[%d] trying wu_queue_push()\n", i); + printf("[%d] trying wu_queue_push()\n", i); - for (id = 0; id < max; id++) - { - sum += id; - ret = wu_queue_push (&ctx, id, id << chunk, max); - if (ret != 0) - { - fprintf (stderr, "[%d] Error: wu_queue_push(%zu) failed (%d): %s\n", i, id, ret, wu_queue_strerror (ret)); - err++; - continue; - } - } + for (id = 0; id < max; id++) { + sum += id; + ret = wu_queue_push(&ctx, id, id << chunk, max); + if (ret != 0) { + fprintf(stderr, "[%d] Error: wu_queue_push(%zu) failed (%d): %s\n", i, id, ret, wu_queue_strerror(ret)); + err++; + continue; + } + } - printf("[%d] push sum: %zu\n", i, sum); + printf("[%d] push sum: %zu\n", i, sum); - if (wu_queue_print (&ctx) == -1) - { - fprintf (stderr, "[%d] wu_queue_print() error\n", i); - err++; - continue; - } + if (wu_queue_print(&ctx) == -1) { + fprintf(stderr, "[%d] wu_queue_print() error\n", i); + err++; + continue; + } - wu_queue_data_t wu; + wu_queue_data_t wu; - while ((ret = wu_queue_pop (&ctx, &wu, 0)) == 0) sum -= wu.id; + while ((ret = wu_queue_pop(&ctx, &wu, 0)) == 0) sum -= wu.id; - if (ret != QUEUE_EMPTY) - { - fprintf (stderr, "[%d] Error: wu_queue_pop() failed (%d): %s\n", i, ret, wu_queue_strerror (ret)); - err++; - continue; - } + if (ret != QUEUE_EMPTY) { + fprintf(stderr, "[%d] Error: wu_queue_pop() failed (%d): %s\n", i, ret, wu_queue_strerror(ret)); + err++; + continue; + } - printf("[%d] pop sum: %zu\n", i, sum); + printf("[%d] pop sum: %zu\n", i, sum); - if (sum != 0) - { - fprintf (stderr, "[%d] Fail: sum is not zero (%zu)\n", i, sum); - err++; - continue; - } + if (sum != 0) { + fprintf(stderr, "[%d] Fail: sum is not zero (%zu)\n", i, sum); + err++; + continue; + } - if (wu_queue_print (&ctx) == -1) - { - fprintf (stderr, "[%d] wu_queue_print() error\n", i); - err++; - continue; - } + if (wu_queue_print(&ctx) == -1) { + fprintf(stderr, "[%d] wu_queue_print() error\n", i); + err++; + continue; + } - printf ("[%d] trying wu_queue_destroy()\n", i); - if ((ret = wu_queue_destroy (&ctx)) != 0) - { - fprintf (stderr, "! Error: wu_queue_destroy() failed (%d): %s\n", ret, wu_queue_strerror (ret)); - err++; - continue; - } - } + printf("[%d] trying wu_queue_destroy()\n", i); + if ((ret = wu_queue_destroy(&ctx)) != 0) { + fprintf(stderr, "! Error: wu_queue_destroy() failed (%d): %s\n", ret, wu_queue_strerror(ret)); + err++; + continue; + } + } - printf ("Catched %zu/%zu error(s).\n", err, err_max); + printf("Catched %zu/%zu error(s).\n", err, err_max); - if (err == err_max) - { - printf ("Self-Test pass\n"); - return 0; - } + if (err == err_max) { + printf("Self-Test pass\n"); + return 0; + } - printf ("Self-Test fail\n"); - return -1; + printf("Self-Test fail\n"); + return -1; } #endif // TEST_UNIT diff --git a/tools/hitag2crack/crack5opencl/queue.h b/tools/hitag2crack/crack5opencl/queue.h index 415b4aa8c..80304b0d3 100644 --- a/tools/hitag2crack/crack5opencl/queue.h +++ b/tools/hitag2crack/crack5opencl/queue.h @@ -42,81 +42,76 @@ License: GNU General Public License v3 or any later version (see LICENSE.txt) #include // enum errors -typedef enum wu_queue_error -{ - QUEUE_EMPTY = 1, - NO_ERROR = 0, - ERROR_GENERIC = -1, - ERROR_QUEUE_TYPE_INVALID = -2, - ERROR_CTX_NULL = -3, - ERROR_CTX_IS_INIT = -4, - ERROR_CTX_IS_NOT_INIT = -5, - ERROR_MUTEXATTR_INIT = -6, - ERROR_MUTEXATTR_SETTYPE = -7, - ERROR_MUTEX_INIT = -8, - ERROR_ALLOC = -9, - ERROR_UNDEFINED = -10 +typedef enum wu_queue_error { + QUEUE_EMPTY = 1, + NO_ERROR = 0, + ERROR_GENERIC = -1, + ERROR_QUEUE_TYPE_INVALID = -2, + ERROR_CTX_NULL = -3, + ERROR_CTX_IS_INIT = -4, + ERROR_CTX_IS_NOT_INIT = -5, + ERROR_MUTEXATTR_INIT = -6, + ERROR_MUTEXATTR_SETTYPE = -7, + ERROR_MUTEX_INIT = -8, + ERROR_ALLOC = -9, + ERROR_UNDEFINED = -10 } wu_queue_error_t; // enum queue types -typedef enum wu_queue_type -{ - QUEUE_TYPE_FORWARD = 0, - QUEUE_TYPE_REVERSE, - QUEUE_TYPE_RANDOM +typedef enum wu_queue_type { + QUEUE_TYPE_FORWARD = 0, + QUEUE_TYPE_REVERSE, + QUEUE_TYPE_RANDOM } wu_queue_type_t; // hold wu data -typedef struct wu_queue_data -{ - size_t id; - size_t off; - size_t max; - size_t rem; +typedef struct wu_queue_data { + size_t id; + size_t off; + size_t max; + size_t rem; } wu_queue_data_t; // lists typedef struct wu_queue_item wu_queue_item_t; -struct wu_queue_item -{ - wu_queue_data_t data; - wu_queue_item_t *next; - wu_queue_item_t *prev; +struct wu_queue_item { + wu_queue_data_t data; + wu_queue_item_t *next; + wu_queue_item_t *prev; }; // main ctx -typedef struct wu_queue_ctx -{ - unsigned int init; +typedef struct wu_queue_ctx { + unsigned int init; - wu_queue_type_t queue_type; - wu_queue_item_t *queue_head; - wu_queue_item_t *queue_tail; + wu_queue_type_t queue_type; + wu_queue_item_t *queue_head; + wu_queue_item_t *queue_tail; - size_t queue_size; + size_t queue_size; - // mutex - pthread_mutexattr_t queue_mutex_attr; + // mutex + pthread_mutexattr_t queue_mutex_attr; // unsigned char pad1[4]; - pthread_mutex_t queue_mutex; + pthread_mutex_t queue_mutex; } wu_queue_ctx_t; // exports -int wu_queue_init (wu_queue_ctx_t *ctx, wu_queue_type_t queue_type); -int wu_queue_done (wu_queue_ctx_t *ctx); -int wu_queue_push (wu_queue_ctx_t *ctx, size_t id, size_t off, size_t max); -int wu_queue_pop (wu_queue_ctx_t *ctx, wu_queue_data_t *wu, short remove); -int wu_queue_destroy (wu_queue_ctx_t *ctx); +int wu_queue_init(wu_queue_ctx_t *ctx, wu_queue_type_t queue_type); +int wu_queue_done(wu_queue_ctx_t *ctx); +int wu_queue_push(wu_queue_ctx_t *ctx, size_t id, size_t off, size_t max); +int wu_queue_pop(wu_queue_ctx_t *ctx, wu_queue_data_t *wu, short remove); +int wu_queue_destroy(wu_queue_ctx_t *ctx); -const char *wu_queue_strdesc (wu_queue_type_t type); -const char *wu_queue_strerror (int error); +const char *wu_queue_strdesc(wu_queue_type_t type); +const char *wu_queue_strerror(int error); #if TEST_UNIT == 1 -int wu_queue_print (wu_queue_ctx_t *ctx); +int wu_queue_print(wu_queue_ctx_t *ctx); #endif #endif // QUEUE_H diff --git a/tools/hitag2crack/crack5opencl/threads.c b/tools/hitag2crack/crack5opencl/threads.c index 2c1e4c84f..5cb5a2b87 100644 --- a/tools/hitag2crack/crack5opencl/threads.c +++ b/tools/hitag2crack/crack5opencl/threads.c @@ -24,721 +24,664 @@ License: GNU General Public License v3 or any later version (see LICENSE.txt) #include "threads.h" -const char *thread_strerror (int error) -{ - switch (error) - { - case THREAD_NOERROR: return (const char *) "No error"; - case THREAD_ERROR_CTX_IS_NULL: return (const char *) "CTX IS NULL"; - case THREAD_ERROR_CTX_IS_INIT: return (const char *) "CTX IS INIT"; - case THREAD_ERROR_TYPE_INVALID: return (const char *) "INVALID TYPE"; - case THREAD_ERROR_COUNT_INVALID: return (const char *) "INVALID THREAD COUNT"; - case THREAD_ERROR_ATTR_SETDETACH: return (const char *) "SETDETACHSTATE FAILED"; - case THREAD_ERROR_ATTR: return (const char *) "INIT ATTR FAILED"; - case THREAD_ERROR_MUTEXATTR: return (const char *) "INIT MUTEXATTR FAILED"; - case THREAD_ERROR_CREATE: return (const char *) "PTHREAD CREATE FAILED"; - case THREAD_ERROR_MUTEX: return (const char *) "INIT MUTEXFAILED"; - case THREAD_ERROR_COND: return (const char *) "INIT COND FAILED"; - case THREAD_ERROR_MUTEX_USLEEP: return (const char *) "INIT MUTEX USLEEP FAILED"; - case THREAD_ERROR_COND_USLEEP: return (const char *) "INIT COND USLEEP FAILED"; - case THREAD_ERROR_GENERIC: return (const char *) "GENERIC ERROR"; - case THREAD_ERROR_ALLOC: return (const char *) "ALLOC FAILED"; - } +const char *thread_strerror(int error) { + switch (error) { + case THREAD_NOERROR: + return (const char *) "No error"; + case THREAD_ERROR_CTX_IS_NULL: + return (const char *) "CTX IS NULL"; + case THREAD_ERROR_CTX_IS_INIT: + return (const char *) "CTX IS INIT"; + case THREAD_ERROR_TYPE_INVALID: + return (const char *) "INVALID TYPE"; + case THREAD_ERROR_COUNT_INVALID: + return (const char *) "INVALID THREAD COUNT"; + case THREAD_ERROR_ATTR_SETDETACH: + return (const char *) "SETDETACHSTATE FAILED"; + case THREAD_ERROR_ATTR: + return (const char *) "INIT ATTR FAILED"; + case THREAD_ERROR_MUTEXATTR: + return (const char *) "INIT MUTEXATTR FAILED"; + case THREAD_ERROR_CREATE: + return (const char *) "PTHREAD CREATE FAILED"; + case THREAD_ERROR_MUTEX: + return (const char *) "INIT MUTEXFAILED"; + case THREAD_ERROR_COND: + return (const char *) "INIT COND FAILED"; + case THREAD_ERROR_MUTEX_USLEEP: + return (const char *) "INIT MUTEX USLEEP FAILED"; + case THREAD_ERROR_COND_USLEEP: + return (const char *) "INIT COND USLEEP FAILED"; + case THREAD_ERROR_GENERIC: + return (const char *) "GENERIC ERROR"; + case THREAD_ERROR_ALLOC: + return (const char *) "ALLOC FAILED"; + } - return (const char *) "GENERIC"; + return (const char *) "GENERIC"; } -int thread_init (thread_ctx_t *ctx, short type, size_t thread_count) -{ - if (!ctx) return THREAD_ERROR_CTX_IS_NULL; - if (ctx->init) return THREAD_ERROR_CTX_IS_INIT; - if (type != THREAD_TYPE_ASYNC && type != THREAD_TYPE_SEQ) return THREAD_ERROR_TYPE_INVALID; - if (thread_count == 0) return THREAD_ERROR_COUNT_INVALID; +int thread_init(thread_ctx_t *ctx, short type, size_t thread_count) { + if (!ctx) return THREAD_ERROR_CTX_IS_NULL; + if (ctx->init) return THREAD_ERROR_CTX_IS_INIT; + if (type != THREAD_TYPE_ASYNC && type != THREAD_TYPE_SEQ) return THREAD_ERROR_TYPE_INVALID; + if (thread_count == 0) return THREAD_ERROR_COUNT_INVALID; - memset (ctx, 0, sizeof (thread_ctx_t)); + memset(ctx, 0, sizeof(thread_ctx_t)); - ctx->thread_count = thread_count; - ctx->type = type; - ctx->enable_condusleep = (type == THREAD_TYPE_ASYNC && thread_count == 1); + ctx->thread_count = thread_count; + ctx->type = type; + ctx->enable_condusleep = (type == THREAD_TYPE_ASYNC && thread_count == 1); - ctx->thread_handles = (pthread_t *) calloc (thread_count, sizeof (pthread_t)); - if (!ctx->thread_handles) - { - return THREAD_ERROR_ALLOC; - } + ctx->thread_handles = (pthread_t *) calloc(thread_count, sizeof(pthread_t)); + if (!ctx->thread_handles) { + return THREAD_ERROR_ALLOC; + } - ctx->thread_mutexs = (pthread_mutex_t *) calloc (thread_count, sizeof (pthread_mutex_t)); - if (!ctx->thread_mutexs) - { - free (ctx->thread_handles); - return THREAD_ERROR_ALLOC; - } + ctx->thread_mutexs = (pthread_mutex_t *) calloc(thread_count, sizeof(pthread_mutex_t)); + if (!ctx->thread_mutexs) { + free(ctx->thread_handles); + return THREAD_ERROR_ALLOC; + } - ctx->thread_conds = (pthread_cond_t *) calloc (thread_count, sizeof (pthread_cond_t)); - if (!ctx->thread_conds) - { - free (ctx->thread_handles); - free (ctx->thread_mutexs); - return THREAD_ERROR_ALLOC; - } + ctx->thread_conds = (pthread_cond_t *) calloc(thread_count, sizeof(pthread_cond_t)); + if (!ctx->thread_conds) { + free(ctx->thread_handles); + free(ctx->thread_mutexs); + return THREAD_ERROR_ALLOC; + } - if (pthread_attr_init (&ctx->attr) != 0) - { - free (ctx->thread_handles); - free (ctx->thread_mutexs); - free (ctx->thread_conds); - return THREAD_ERROR_ATTR; - } + if (pthread_attr_init(&ctx->attr) != 0) { + free(ctx->thread_handles); + free(ctx->thread_mutexs); + free(ctx->thread_conds); + return THREAD_ERROR_ATTR; + } - pthread_attr_setdetachstate (&ctx->attr, PTHREAD_CREATE_JOINABLE); + pthread_attr_setdetachstate(&ctx->attr, PTHREAD_CREATE_JOINABLE); - if (pthread_mutexattr_init (&ctx->mutex_attr) != 0) - { - free (ctx->thread_handles); - free (ctx->thread_mutexs); - free (ctx->thread_conds); - pthread_attr_destroy (&ctx->attr); - return THREAD_ERROR_MUTEXATTR; - } + if (pthread_mutexattr_init(&ctx->mutex_attr) != 0) { + free(ctx->thread_handles); + free(ctx->thread_mutexs); + free(ctx->thread_conds); + pthread_attr_destroy(&ctx->attr); + return THREAD_ERROR_MUTEXATTR; + } - pthread_mutexattr_settype (&ctx->mutex_attr, PTHREAD_MUTEX_ERRORCHECK); + pthread_mutexattr_settype(&ctx->mutex_attr, PTHREAD_MUTEX_ERRORCHECK); - if (ctx->enable_condusleep) - { - if (pthread_mutex_init (&ctx->thread_mutex_usleep, NULL) != 0) - { - free (ctx->thread_handles); - free (ctx->thread_mutexs); - free (ctx->thread_conds); - pthread_attr_destroy (&ctx->attr); - pthread_mutexattr_destroy (&ctx->mutex_attr); - return THREAD_ERROR_MUTEX_USLEEP; - } + if (ctx->enable_condusleep) { + if (pthread_mutex_init(&ctx->thread_mutex_usleep, NULL) != 0) { + free(ctx->thread_handles); + free(ctx->thread_mutexs); + free(ctx->thread_conds); + pthread_attr_destroy(&ctx->attr); + pthread_mutexattr_destroy(&ctx->mutex_attr); + return THREAD_ERROR_MUTEX_USLEEP; + } - if (pthread_cond_init (&ctx->thread_cond_usleep, NULL) != 0) - { - free (ctx->thread_handles); - free (ctx->thread_mutexs); - free (ctx->thread_conds); - pthread_mutex_destroy (&ctx->thread_mutex_usleep); - pthread_attr_destroy (&ctx->attr); - pthread_mutexattr_destroy (&ctx->mutex_attr); - return THREAD_ERROR_COND_USLEEP; - } - } + if (pthread_cond_init(&ctx->thread_cond_usleep, NULL) != 0) { + free(ctx->thread_handles); + free(ctx->thread_mutexs); + free(ctx->thread_conds); + pthread_mutex_destroy(&ctx->thread_mutex_usleep); + pthread_attr_destroy(&ctx->attr); + pthread_mutexattr_destroy(&ctx->mutex_attr); + return THREAD_ERROR_COND_USLEEP; + } + } - int err = 0; - int z = 0; + int err = 0; + int z = 0; - for (z = 0; z < (int) ctx->thread_count; z++) - { - if (ctx->type == THREAD_TYPE_ASYNC) - { - if (pthread_mutex_init (&ctx->thread_mutexs[z], NULL) != 0) - { - err = THREAD_ERROR_MUTEX; - break; - } + for (z = 0; z < (int) ctx->thread_count; z++) { + if (ctx->type == THREAD_TYPE_ASYNC) { + if (pthread_mutex_init(&ctx->thread_mutexs[z], NULL) != 0) { + err = THREAD_ERROR_MUTEX; + break; + } - if (pthread_cond_init (&ctx->thread_conds[z], NULL) != 0) - { - pthread_mutex_destroy (&ctx->thread_mutexs[z]); - err = THREAD_ERROR_COND; - break; - } - } - } + if (pthread_cond_init(&ctx->thread_conds[z], NULL) != 0) { + pthread_mutex_destroy(&ctx->thread_mutexs[z]); + err = THREAD_ERROR_COND; + break; + } + } + } - if (err != 0) - { - z--; // step back + if (err != 0) { + z--; // step back - for (; z >= 0; z--) - { - pthread_cond_destroy (&ctx->thread_conds[z]); - pthread_mutex_destroy (&ctx->thread_mutexs[z]); - } + for (; z >= 0; z--) { + pthread_cond_destroy(&ctx->thread_conds[z]); + pthread_mutex_destroy(&ctx->thread_mutexs[z]); + } - if (ctx->enable_condusleep) - { - pthread_mutex_destroy (&ctx->thread_mutex_usleep); - pthread_cond_destroy (&ctx->thread_cond_usleep); - } + if (ctx->enable_condusleep) { + pthread_mutex_destroy(&ctx->thread_mutex_usleep); + pthread_cond_destroy(&ctx->thread_cond_usleep); + } - free (ctx->thread_handles); - free (ctx->thread_mutexs); - free (ctx->thread_conds); - pthread_attr_destroy (&ctx->attr); - pthread_mutexattr_destroy (&ctx->mutex_attr); - return err; - } + free(ctx->thread_handles); + free(ctx->thread_mutexs); + free(ctx->thread_conds); + pthread_attr_destroy(&ctx->attr); + pthread_mutexattr_destroy(&ctx->mutex_attr); + return err; + } - ctx->init = 1; - return 0; + ctx->init = 1; + return 0; } -int thread_destroy (thread_ctx_t *ctx) -{ - if (!ctx) return -1; - if (!ctx->init) return -2; +int thread_destroy(thread_ctx_t *ctx) { + if (!ctx) return -1; + if (!ctx->init) return -2; - if (ctx->enable_condusleep) - { - pthread_cond_destroy (&ctx->thread_cond_usleep); - pthread_mutex_destroy (&ctx->thread_mutex_usleep); - } + if (ctx->enable_condusleep) { + pthread_cond_destroy(&ctx->thread_cond_usleep); + pthread_mutex_destroy(&ctx->thread_mutex_usleep); + } - for (size_t z = 0; z < ctx->thread_count; z++) - { - pthread_cond_destroy (&ctx->thread_conds[z]); - pthread_mutex_destroy (&ctx->thread_mutexs[z]); - } + for (size_t z = 0; z < ctx->thread_count; z++) { + pthread_cond_destroy(&ctx->thread_conds[z]); + pthread_mutex_destroy(&ctx->thread_mutexs[z]); + } - pthread_mutexattr_destroy (&ctx->mutex_attr); - pthread_attr_init (&ctx->attr); + pthread_mutexattr_destroy(&ctx->mutex_attr); + pthread_attr_init(&ctx->attr); - free (ctx->thread_conds); - free (ctx->thread_mutexs); - free (ctx->thread_handles); + free(ctx->thread_conds); + free(ctx->thread_mutexs); + free(ctx->thread_handles); - memset (ctx, 0, sizeof (thread_ctx_t)); - ctx->init = 0; - return 0; + memset(ctx, 0, sizeof(thread_ctx_t)); + ctx->init = 0; + return 0; } -int thread_start (thread_ctx_t *ctx, thread_args_t *t_arg) -{ - int err = 0; - int z = 0; +int thread_start(thread_ctx_t *ctx, thread_args_t *t_arg) { + int err = 0; + int z = 0; - for (z = 0; z < (int) ctx->thread_count; z++) - { - if (pthread_create (&ctx->thread_handles[z], &ctx->attr, (ctx->type == THREAD_TYPE_ASYNC) ? computing_process_async : computing_process, (void *) &t_arg[z]) != 0) - { - err = THREAD_ERROR_CREATE; - break; - } - } + for (z = 0; z < (int) ctx->thread_count; z++) { + if (pthread_create(&ctx->thread_handles[z], &ctx->attr, (ctx->type == THREAD_TYPE_ASYNC) ? computing_process_async : computing_process, (void *) &t_arg[z]) != 0) { + err = THREAD_ERROR_CREATE; + break; + } + } - if (err != 0) - { - z--; // step back + if (err != 0) { + z--; // step back - for (; z >= 0; z++) - { - pthread_cancel (ctx->thread_handles[z]); - pthread_join (ctx->thread_handles[z], NULL); - } + for (; z >= 0; z++) { + pthread_cancel(ctx->thread_handles[z]); + pthread_join(ctx->thread_handles[z], NULL); + } - return err; - } + return err; + } - return 0; + return 0; } -int thread_stop (thread_ctx_t *ctx) -{ - for (size_t z = 0; z < ctx->thread_count; z++) - { - if (ctx->type == THREAD_TYPE_ASYNC) pthread_cancel (ctx->thread_handles[z]); - pthread_join (ctx->thread_handles[z], NULL); - } +int thread_stop(thread_ctx_t *ctx) { + for (size_t z = 0; z < ctx->thread_count; z++) { + if (ctx->type == THREAD_TYPE_ASYNC) pthread_cancel(ctx->thread_handles[z]); + pthread_join(ctx->thread_handles[z], NULL); + } - return 0; + return 0; } -__attribute__ ((format (printf, 1, 2))) -void tprintf (const char * restrict format, ...) -{ - flockfile (stdout); +__attribute__((format(printf, 1, 2))) +void tprintf(const char *restrict format, ...) { + flockfile(stdout); - va_list va_args; - va_start (va_args, format); - vprintf (format, va_args); - va_end (va_args); + va_list va_args; + va_start(va_args, format); + vprintf(format, va_args); + va_end(va_args); - funlockfile (stdout); + funlockfile(stdout); - fflush (stdout); + fflush(stdout); } -const char *thread_status_strdesc (thread_status_t s) -{ - switch (s) - { - case TH_START: return (const char *) "START"; - case TH_WAIT: return (const char *) "WAIT"; - case TH_PROCESSING: return (const char *) "PROCESSING"; - case TH_ERROR: return (const char *) "ERROR"; - case TH_STOP: return (const char *) "STOP"; - case TH_FOUND_KEY: return (const char *) "FOUND_KEY"; - case TH_END: return (const char *) "END"; - } +const char *thread_status_strdesc(thread_status_t s) { + switch (s) { + case TH_START: + return (const char *) "START"; + case TH_WAIT: + return (const char *) "WAIT"; + case TH_PROCESSING: + return (const char *) "PROCESSING"; + case TH_ERROR: + return (const char *) "ERROR"; + case TH_STOP: + return (const char *) "STOP"; + case TH_FOUND_KEY: + return (const char *) "FOUND_KEY"; + case TH_END: + return (const char *) "END"; + } - return (const char *) "... or die tryin'"; + return (const char *) "... or die tryin'"; } -bool thread_setEnd (thread_ctx_t *ctx, thread_args_t *t_arg) -{ - bool found = false; +bool thread_setEnd(thread_ctx_t *ctx, thread_args_t *t_arg) { + bool found = false; - size_t z; + size_t z; - int m_ret = 0; - int c_ret = 0; + int m_ret = 0; + int c_ret = 0; - for (z = 0; z < ctx->thread_count; z++) - { - m_ret = pthread_mutex_lock (&ctx->thread_mutexs[z]); - if (m_ret != 0) - { - tprintf ("[%zu] [%s] Error: pthread_mutex_lock() failed (%d): %s\n", z, __func__, m_ret, strerror (m_ret)); - } + for (z = 0; z < ctx->thread_count; z++) { + m_ret = pthread_mutex_lock(&ctx->thread_mutexs[z]); + if (m_ret != 0) { + tprintf("[%zu] [%s] Error: pthread_mutex_lock() failed (%d): %s\n", z, __func__, m_ret, strerror(m_ret)); + } - thread_status_t tmp = t_arg[z].status; + thread_status_t tmp = t_arg[z].status; - #if DEBUGME > 0 - tprintf ("[%zu] [%s] Thread status: %s\n", z, __func__, thread_status_strdesc(t_arg[z].status)); - #endif +#if DEBUGME > 0 + tprintf("[%zu] [%s] Thread status: %s\n", z, __func__, thread_status_strdesc(t_arg[z].status)); +#endif - if (tmp == TH_FOUND_KEY || tmp == TH_END || tmp == TH_ERROR) - { - if (tmp == TH_FOUND_KEY) found = true; - pthread_mutex_unlock (&ctx->thread_mutexs[z]); - continue; - } + if (tmp == TH_FOUND_KEY || tmp == TH_END || tmp == TH_ERROR) { + if (tmp == TH_FOUND_KEY) found = true; + pthread_mutex_unlock(&ctx->thread_mutexs[z]); + continue; + } - #if DEBUGME > 0 - tprintf ("[%zu] [%s] Set thread status to TH_STOP\n", z, __func__); - #endif +#if DEBUGME > 0 + tprintf("[%zu] [%s] Set thread status to TH_STOP\n", z, __func__); +#endif - t_arg[z].status = TH_STOP; + t_arg[z].status = TH_STOP; - if (tmp == TH_WAIT) - { - #if DEBUGME > 0 - tprintf ("[%zu] [%s] Send cond_signal to thread\n", z, __func__); - #endif + if (tmp == TH_WAIT) { +#if DEBUGME > 0 + tprintf("[%zu] [%s] Send cond_signal to thread\n", z, __func__); +#endif - c_ret = pthread_cond_signal (&ctx->thread_conds[z]); - if (c_ret != 0) - { - tprintf ("[%zu] [%s] Error: pthread_cond_signal() failed (%d): %s\n", z, __func__, c_ret, strerror (c_ret)); - } - } + c_ret = pthread_cond_signal(&ctx->thread_conds[z]); + if (c_ret != 0) { + tprintf("[%zu] [%s] Error: pthread_cond_signal() failed (%d): %s\n", z, __func__, c_ret, strerror(c_ret)); + } + } - pthread_mutex_unlock (&ctx->thread_mutexs[z]); - } + pthread_mutex_unlock(&ctx->thread_mutexs[z]); + } - return found; + return found; } -void *computing_process (void *arg) -{ - thread_args_t *a = (thread_args_t *) arg; +void *computing_process(void *arg) { + thread_args_t *a = (thread_args_t *) arg; - uint64_t off = 0; + uint64_t off = 0; - size_t z = a->device_id; - uint64_t *matches = a->matches; - uint32_t *matches_found = a->matches_found; + size_t z = a->device_id; + uint64_t *matches = a->matches; + uint32_t *matches_found = a->matches_found; - uint32_t uid = a->uid; - uint32_t aR2 = a->aR2; - uint32_t nR1 = a->nR1; - uint32_t nR2 = a->nR2; + uint32_t uid = a->uid; + uint32_t aR2 = a->aR2; + uint32_t nR1 = a->nR1; + uint32_t nR2 = a->nR2; - opencl_ctx_t *ctx = a->ocl_ctx; + opencl_ctx_t *ctx = a->ocl_ctx; - wu_queue_data_t wu; - wu_queue_pop (&ctx->queue_ctx, &wu, false); - off = wu.off; - a->slice = wu.id+1; + wu_queue_data_t wu; + wu_queue_pop(&ctx->queue_ctx, &wu, false); + off = wu.off; + a->slice = wu.id + 1; - if (ctx->queue_ctx.queue_type == QUEUE_TYPE_RANDOM) - { - #if DEBUGME > 0 - printf ("[%zu] Slice %zu (off %zu), max %zu, remain %zu slice(s)\n", z, wu.id+1, wu.off, wu.max, wu.rem); - #else - printf ("[%zu] Slice %zu/%zu (%zu remain)\n", z, wu.id+1, wu.max, wu.rem); - #endif // DEBUGME - } - else - { - #if DEBUGME > 0 - printf ("[%zu] Slice %zu/%zu, off %zu\n", z, wu.id+1, wu.max, wu.off); - #else - printf ("[%zu] Slice %zu/%zu\n", z, wu.id+1, wu.max); - #endif // DEBUGME - } - fflush (stdout); + if (ctx->queue_ctx.queue_type == QUEUE_TYPE_RANDOM) { +#if DEBUGME > 0 + printf("[%zu] Slice %zu (off %zu), max %zu, remain %zu slice(s)\n", z, wu.id + 1, wu.off, wu.max, wu.rem); +#else + printf("[%zu] Slice %zu/%zu (%zu remain)\n", z, wu.id + 1, wu.max, wu.rem); +#endif // DEBUGME + } else { +#if DEBUGME > 0 + printf("[%zu] Slice %zu/%zu, off %zu\n", z, wu.id + 1, wu.max, wu.off); +#else + printf("[%zu] Slice %zu/%zu\n", z, wu.id + 1, wu.max); +#endif // DEBUGME + } + fflush(stdout); - int ret = runKernel (ctx, (uint32_t) off, matches, matches_found, z); + int ret = runKernel(ctx, (uint32_t) off, matches, matches_found, z); - a->r = false; - a->err = false; + a->r = false; + a->err = false; - if (ret < 1) // error or nada - { - if (ret == -1) a->err = true; - pthread_exit (NULL); - } + if (ret < 1) { // error or nada + if (ret == -1) a->err = true; + pthread_exit(NULL); + } - if (!ctx->force_hitag2_opencl) - { - #if DEBUGME >= 2 - printf ("[slave][%zu] master, I found %5u candidates @ slice %zu\n", z, matches_found[0], a->slice+1); - fflush (stdout); - #endif + if (!ctx->force_hitag2_opencl) { +#if DEBUGME >= 2 + printf("[slave][%zu] master, I found %5u candidates @ slice %zu\n", z, matches_found[0], a->slice + 1); + fflush(stdout); +#endif - for (uint32_t match = 0; match < matches_found[0]; match++) - { - a->r = try_state (matches[match], uid, aR2, nR1, nR2, &a->key); - if (a->r) break; - } - } - else - { - // the OpenCL kernel return only one key if found, else nothing + for (uint32_t match = 0; match < matches_found[0]; match++) { + a->r = try_state(matches[match], uid, aR2, nR1, nR2, &a->key); + if (a->r) break; + } + } else { + // the OpenCL kernel return only one key if found, else nothing - #if TDEBUG >= 1 - printf ("[slave][%zu] master, I found the key @ slice %zu\n", z, a->slice+1); - fflush (stdout); - #endif +#if TDEBUG >= 1 + printf("[slave][%zu] master, I found the key @ slice %zu\n", z, a->slice + 1); + fflush(stdout); +#endif - a->r = true; - a->key = matches[0]; - } + a->r = true; + a->key = matches[0]; + } - pthread_exit (NULL); + pthread_exit(NULL); } -void *computing_process_async (void *arg) -{ - thread_args_t *a = (thread_args_t *) arg; +void *computing_process_async(void *arg) { + thread_args_t *a = (thread_args_t *) arg; - size_t z = a->device_id; + size_t z = a->device_id; - // TH_START, not really needed lock with mutex here - pthread_mutex_lock (&a->thread_ctx->thread_mutexs[z]); + // TH_START, not really needed lock with mutex here + pthread_mutex_lock(&a->thread_ctx->thread_mutexs[z]); - // fetching data from thread struct, I hope they are good - thread_status_t status = a->status; + // fetching data from thread struct, I hope they are good + thread_status_t status = a->status; - uint32_t uid = a->uid; - uint32_t aR2 = a->aR2; - uint32_t nR1 = a->nR1; - uint32_t nR2 = a->nR2; + uint32_t uid = a->uid; + uint32_t aR2 = a->aR2; + uint32_t nR1 = a->nR1; + uint32_t nR2 = a->nR2; - uint64_t *matches = a->matches; - uint32_t *matches_found = a->matches_found; - size_t max_step = a->max_step; + uint64_t *matches = a->matches; + uint32_t *matches_found = a->matches_found; + size_t max_step = a->max_step; - opencl_ctx_t *ctx = a->ocl_ctx; + opencl_ctx_t *ctx = a->ocl_ctx; - pthread_mutex_unlock (&a->thread_ctx->thread_mutexs[z]); + pthread_mutex_unlock(&a->thread_ctx->thread_mutexs[z]); - uint64_t off = 0; + uint64_t off = 0; // size_t slice = 0; - int ret = 0; + int ret = 0; - if (status == TH_START) - { - #if TDEBUG >= 1 - printf ("[slave][%zu] plat id %d, uid %u, aR2 %u, nR1 %u, nR2 %u, Initial status: %s\n", z, ctx->id_platform, uid, aR2, nR1, nR2, thread_status_strdesc (status)); - #endif - status = TH_WAIT; - // proceed to next - } + if (status == TH_START) { +#if TDEBUG >= 1 + printf("[slave][%zu] plat id %d, uid %u, aR2 %u, nR1 %u, nR2 %u, Initial status: %s\n", z, ctx->id_platform, uid, aR2, nR1, nR2, thread_status_strdesc(status)); +#endif + status = TH_WAIT; + // proceed to next + } - do // slave - { - if (status == TH_WAIT) - { - pthread_mutex_lock (&a->thread_ctx->thread_mutexs[z]); + do { // slave + if (status == TH_WAIT) { + pthread_mutex_lock(&a->thread_ctx->thread_mutexs[z]); - // update thread status to WAIT, todo: check with multiple devices + // update thread status to WAIT, todo: check with multiple devices - if (a->status == TH_END) // other threads found the key - { - fflush(stdout); - status = TH_END; - a->quit = true; - pthread_mutex_unlock (&a->thread_ctx->thread_mutexs[z]); - pthread_exit (NULL); - } - else - { - a->status = TH_WAIT; + if (a->status == TH_END) { // other threads found the key + fflush(stdout); + status = TH_END; + a->quit = true; + pthread_mutex_unlock(&a->thread_ctx->thread_mutexs[z]); + pthread_exit(NULL); + } else { + a->status = TH_WAIT; - if (a->thread_ctx->enable_condusleep) - { - pthread_mutex_lock (&a->thread_ctx->thread_mutex_usleep); - pthread_cond_signal (&a->thread_ctx->thread_cond_usleep); // unlock master/TH_PROCESSING cond - #if TDEBUG >= 1 - printf ("[slate][%zu] after pthread_cond_signal TH_WAIT\n", z); - fflush (stdout); - #endif - pthread_mutex_unlock (&a->thread_ctx->thread_mutex_usleep); - } - } + if (a->thread_ctx->enable_condusleep) { + pthread_mutex_lock(&a->thread_ctx->thread_mutex_usleep); + pthread_cond_signal(&a->thread_ctx->thread_cond_usleep); // unlock master/TH_PROCESSING cond +#if TDEBUG >= 1 + printf("[slate][%zu] after pthread_cond_signal TH_WAIT\n", z); + fflush(stdout); +#endif + pthread_mutex_unlock(&a->thread_ctx->thread_mutex_usleep); + } + } - #if TDEBUG >= 1 - printf ("[slave][%zu] master, i'm here to serve you. I'm in %s give me a signal.\n", z, thread_status_strdesc (status)); - fflush (stdout); - #endif +#if TDEBUG >= 1 + printf("[slave][%zu] master, i'm here to serve you. I'm in %s give me a signal.\n", z, thread_status_strdesc(status)); + fflush(stdout); +#endif - pthread_cond_wait (&a->thread_ctx->thread_conds[z], &a->thread_ctx->thread_mutexs[z]); + pthread_cond_wait(&a->thread_ctx->thread_conds[z], &a->thread_ctx->thread_mutexs[z]); - status = a->status; // read new status from master + status = a->status; // read new status from master - #if TDEBUG >= 2 - printf ("[slave][%zu] master, got the signal with new state: %s.\n", z, thread_status_strdesc (status)); - fflush (stdout); - #endif +#if TDEBUG >= 2 + printf("[slave][%zu] master, got the signal with new state: %s.\n", z, thread_status_strdesc(status)); + fflush(stdout); +#endif - pthread_mutex_unlock (&a->thread_ctx->thread_mutexs[z]); + pthread_mutex_unlock(&a->thread_ctx->thread_mutexs[z]); - if (status == TH_WAIT) - { - #if TDEBUG >=1 - printf ("[slave] ! Error: need to be TH_PROCESSING or TH_END, not TH_WAIT ... exit\n"); - fflush (stdout); - #endif - break; - } - } + if (status == TH_WAIT) { +#if TDEBUG >=1 + printf("[slave] ! Error: need to be TH_PROCESSING or TH_END, not TH_WAIT ... exit\n"); + fflush(stdout); +#endif + break; + } + } - if (status == TH_ERROR) - { - #if TDEBUG >= 1 - printf ("[slave][%zu] master, got error signal, proceed with exit\n", z); - fflush (stdout); - #endif - pthread_exit (NULL); - } + if (status == TH_ERROR) { +#if TDEBUG >= 1 + printf("[slave][%zu] master, got error signal, proceed with exit\n", z); + fflush(stdout); +#endif + pthread_exit(NULL); + } - if (status == TH_PROCESSING) - { - #if TDEBUG >= 2 - printf ("[slave][%zu] master, got a work-unit, processing ...\n", z); - fflush (stdout); - #endif + if (status == TH_PROCESSING) { +#if TDEBUG >= 2 + printf("[slave][%zu] master, got a work-unit, processing ...\n", z); + fflush(stdout); +#endif - wu_queue_data_t wu; - wu_queue_pop (&ctx->queue_ctx, &wu, false); - off = wu.off; - a->slice = wu.id+1; + wu_queue_data_t wu; + wu_queue_pop(&ctx->queue_ctx, &wu, false); + off = wu.off; + a->slice = wu.id + 1; - if (ctx->queue_ctx.queue_type == QUEUE_TYPE_RANDOM) - { - #if DEBUGME > 0 - printf ("[%zu] Slice %zu (off %zu), max %zu, remain %zu slice(s)\n", z, wu.id+1, wu.off, wu.max, wu.rem); - #else - printf ("[%zu] Slice %zu/%zu (%zu remain)\n", z, wu.id+1, wu.max, wu.rem); - #endif // DEBUGME - } - else - { - #if DEBUGME > 0 - printf ("[%zu] Slice %zu/%zu, off %zu\n", z, wu.id+1, wu.max, wu.off); - #else - printf ("[%zu] Slice %zu/%zu\n", z, wu.id+1, wu.max); - #endif // DEBUGME - } + if (ctx->queue_ctx.queue_type == QUEUE_TYPE_RANDOM) { +#if DEBUGME > 0 + printf("[%zu] Slice %zu (off %zu), max %zu, remain %zu slice(s)\n", z, wu.id + 1, wu.off, wu.max, wu.rem); +#else + printf("[%zu] Slice %zu/%zu (%zu remain)\n", z, wu.id + 1, wu.max, wu.rem); +#endif // DEBUGME + } else { +#if DEBUGME > 0 + printf("[%zu] Slice %zu/%zu, off %zu\n", z, wu.id + 1, wu.max, wu.off); +#else + printf("[%zu] Slice %zu/%zu\n", z, wu.id + 1, wu.max); +#endif // DEBUGME + } - fflush (stdout); + fflush(stdout); - ret = runKernel (ctx, (uint32_t) off, matches, matches_found, z); + ret = runKernel(ctx, (uint32_t) off, matches, matches_found, z); - if (ret < 1) // error or nada - { - if (ret == -1) - { - // untested code - pthread_mutex_lock (&a->thread_ctx->thread_mutexs[z]); - a->err = true; - a->status = TH_ERROR; - pthread_mutex_unlock (&a->thread_ctx->thread_mutexs[z]); - #if TDEBUG >= 1 - printf ("[slave][%zu] master, something is broken, exit\n", z); - fflush (stdout); - #endif + if (ret < 1) { // error or nada + if (ret == -1) { + // untested code + pthread_mutex_lock(&a->thread_ctx->thread_mutexs[z]); + a->err = true; + a->status = TH_ERROR; + pthread_mutex_unlock(&a->thread_ctx->thread_mutexs[z]); +#if TDEBUG >= 1 + printf("[slave][%zu] master, something is broken, exit\n", z); + fflush(stdout); +#endif - if (a->thread_ctx->enable_condusleep) - { - pthread_mutex_lock (&a->thread_ctx->thread_mutex_usleep); - pthread_cond_signal (&a->thread_ctx->thread_cond_usleep); // unlock master/TH_PROCESSING cond - #if TDEBUG >= 1 - printf ("[slave][%zu] after pthread_cond_signal TH_ERROR\n", z); - #endif - pthread_mutex_unlock (&a->thread_ctx->thread_mutex_usleep); - } + if (a->thread_ctx->enable_condusleep) { + pthread_mutex_lock(&a->thread_ctx->thread_mutex_usleep); + pthread_cond_signal(&a->thread_ctx->thread_cond_usleep); // unlock master/TH_PROCESSING cond +#if TDEBUG >= 1 + printf("[slave][%zu] after pthread_cond_signal TH_ERROR\n", z); +#endif + pthread_mutex_unlock(&a->thread_ctx->thread_mutex_usleep); + } - pthread_exit (NULL); - // end of unstested code - } + pthread_exit(NULL); + // end of unstested code + } - #if TDEBUG >= 1 - printf ("[slave][%zu] master, process is done but no candidates found\n", z); - fflush (stdout); - #endif - pthread_mutex_lock (&a->thread_ctx->thread_mutexs[z]); +#if TDEBUG >= 1 + printf("[slave][%zu] master, process is done but no candidates found\n", z); + fflush(stdout); +#endif + pthread_mutex_lock(&a->thread_ctx->thread_mutexs[z]); - if (a->slice >= max_step) a->status = TH_END; - else a->status = TH_WAIT; + if (a->slice >= max_step) a->status = TH_END; + else a->status = TH_WAIT; - status = a->status; + status = a->status; - pthread_mutex_unlock (&a->thread_ctx->thread_mutexs[z]); + pthread_mutex_unlock(&a->thread_ctx->thread_mutexs[z]); - if (a->thread_ctx->enable_condusleep) - { - pthread_mutex_lock (&a->thread_ctx->thread_mutex_usleep); - pthread_cond_signal (&a->thread_ctx->thread_cond_usleep); // unlock master/TH_PROCESSING cond - #if TDEBUG >= 1 - printf ("[slave][%zu] after pthread_cond_signal TH_WAIT\n", z); - fflush (stdout); - #endif - pthread_mutex_unlock (&a->thread_ctx->thread_mutex_usleep); - } + if (a->thread_ctx->enable_condusleep) { + pthread_mutex_lock(&a->thread_ctx->thread_mutex_usleep); + pthread_cond_signal(&a->thread_ctx->thread_cond_usleep); // unlock master/TH_PROCESSING cond +#if TDEBUG >= 1 + printf("[slave][%zu] after pthread_cond_signal TH_WAIT\n", z); + fflush(stdout); +#endif + pthread_mutex_unlock(&a->thread_ctx->thread_mutex_usleep); + } - continue; - } + continue; + } - if (!ctx->force_hitag2_opencl) - { - #if TDEBUG >= 1 - printf ("[slave][%zu] master, we got %5u candidates. Proceed to validation\n", z, matches_found[0]); - fflush (stdout); - #endif + if (!ctx->force_hitag2_opencl) { +#if TDEBUG >= 1 + printf("[slave][%zu] master, we got %5u candidates. Proceed to validation\n", z, matches_found[0]); + fflush(stdout); +#endif - for (uint32_t match = 0; match < matches_found[0]; match++) - { - if (a->quit) - { - pthread_mutex_lock (&a->thread_ctx->thread_mutexs[z]); - a->status = TH_END; - pthread_mutex_unlock (&a->thread_ctx->thread_mutexs[z]); - #if TDEBUG >= 1 - printf ("[slave][%zu] master, Another thread found the key, quit 2 \n", z); - fflush (stdout); - #endif + for (uint32_t match = 0; match < matches_found[0]; match++) { + if (a->quit) { + pthread_mutex_lock(&a->thread_ctx->thread_mutexs[z]); + a->status = TH_END; + pthread_mutex_unlock(&a->thread_ctx->thread_mutexs[z]); +#if TDEBUG >= 1 + printf("[slave][%zu] master, Another thread found the key, quit 2 \n", z); + fflush(stdout); +#endif - if (a->thread_ctx->enable_condusleep) - { - pthread_mutex_lock (&a->thread_ctx->thread_mutex_usleep); - pthread_cond_signal (&a->thread_ctx->thread_cond_usleep); // unlock master/TH_PROCESSING cond - #if TDEBUG >= 1 - printf ("[slave][%zu] after pthread_cond_signal TH_END\n", z); - #endif - pthread_mutex_unlock (&a->thread_ctx->thread_mutex_usleep); - } + if (a->thread_ctx->enable_condusleep) { + pthread_mutex_lock(&a->thread_ctx->thread_mutex_usleep); + pthread_cond_signal(&a->thread_ctx->thread_cond_usleep); // unlock master/TH_PROCESSING cond +#if TDEBUG >= 1 + printf("[slave][%zu] after pthread_cond_signal TH_END\n", z); +#endif + pthread_mutex_unlock(&a->thread_ctx->thread_mutex_usleep); + } - pthread_exit (NULL); - } + pthread_exit(NULL); + } - a->r = try_state (matches[match], uid, aR2, nR1, nR2, &a->key); - if (a->r) - { - pthread_mutex_lock (&a->thread_ctx->thread_mutexs[z]); - a->s = matches[match]; - status = a->status = TH_FOUND_KEY; - a->quit = true; - pthread_mutex_unlock (&a->thread_ctx->thread_mutexs[z]); - #if TDEBUG >= 1 - printf ("[slave][%zu] master, I found the key ! state %" STR(OFF_FORMAT_U) ", slice %zu\n", z, a->s, a->slice+1); - fflush (stdout); - #endif + a->r = try_state(matches[match], uid, aR2, nR1, nR2, &a->key); + if (a->r) { + pthread_mutex_lock(&a->thread_ctx->thread_mutexs[z]); + a->s = matches[match]; + status = a->status = TH_FOUND_KEY; + a->quit = true; + pthread_mutex_unlock(&a->thread_ctx->thread_mutexs[z]); +#if TDEBUG >= 1 + printf("[slave][%zu] master, I found the key ! state %" STR(OFF_FORMAT_U) ", slice %zu\n", z, a->s, a->slice + 1); + fflush(stdout); +#endif - if (a->thread_ctx->enable_condusleep) - { - pthread_mutex_lock (&a->thread_ctx->thread_mutex_usleep); - pthread_cond_signal (&a->thread_ctx->thread_cond_usleep); // unlock master/TH_PROCESSING cond - #if TDEBUG >= 1 - printf ("[slave][%zu] after pthread_cond_signal TH_FOUND_KEY\n", z); - #endif - pthread_mutex_unlock (&a->thread_ctx->thread_mutex_usleep); - } + if (a->thread_ctx->enable_condusleep) { + pthread_mutex_lock(&a->thread_ctx->thread_mutex_usleep); + pthread_cond_signal(&a->thread_ctx->thread_cond_usleep); // unlock master/TH_PROCESSING cond +#if TDEBUG >= 1 + printf("[slave][%zu] after pthread_cond_signal TH_FOUND_KEY\n", z); +#endif + pthread_mutex_unlock(&a->thread_ctx->thread_mutex_usleep); + } - pthread_exit (NULL); - } - } + pthread_exit(NULL); + } + } - if (a->quit) - { - pthread_mutex_lock (&a->thread_ctx->thread_mutexs[z]); - a->status = TH_END; - pthread_mutex_unlock (&a->thread_ctx->thread_mutexs[z]); - #if TDEBUG >= 1 - printf ("[slave][%zu] master, Another thread found the key, quit 1 \n", z); - fflush (stdout); - #endif + if (a->quit) { + pthread_mutex_lock(&a->thread_ctx->thread_mutexs[z]); + a->status = TH_END; + pthread_mutex_unlock(&a->thread_ctx->thread_mutexs[z]); +#if TDEBUG >= 1 + printf("[slave][%zu] master, Another thread found the key, quit 1 \n", z); + fflush(stdout); +#endif - if (a->thread_ctx->enable_condusleep) - { - pthread_mutex_lock (&a->thread_ctx->thread_mutex_usleep); - pthread_cond_signal (&a->thread_ctx->thread_cond_usleep); // unlock master/TH_PROCESSING cond - #if TDEBUG >= 1 - printf ("[slave][%zu] after pthread_cond_signal TH_END\n", z); - #endif - pthread_mutex_unlock (&a->thread_ctx->thread_mutex_usleep); - } + if (a->thread_ctx->enable_condusleep) { + pthread_mutex_lock(&a->thread_ctx->thread_mutex_usleep); + pthread_cond_signal(&a->thread_ctx->thread_cond_usleep); // unlock master/TH_PROCESSING cond +#if TDEBUG >= 1 + printf("[slave][%zu] after pthread_cond_signal TH_END\n", z); +#endif + pthread_mutex_unlock(&a->thread_ctx->thread_mutex_usleep); + } - pthread_exit (NULL); - } + pthread_exit(NULL); + } - // setting internal status to wait - status = TH_WAIT; - continue; - } - else - { - // the OpenCL kernel return only one key if found, else nothing + // setting internal status to wait + status = TH_WAIT; + continue; + } else { + // the OpenCL kernel return only one key if found, else nothing - pthread_mutex_lock (&a->thread_ctx->thread_mutexs[z]); - a->r = true; - a->key = matches[0]; - status = a->status = TH_FOUND_KEY; - a->quit = true; - pthread_mutex_unlock (&a->thread_ctx->thread_mutexs[z]); - #if TDEBUG >= 1 - printf ("[slave][%zu] master, I found the key at slice %zu\n", z, a->slice+1); - fflush (stdout); - #endif + pthread_mutex_lock(&a->thread_ctx->thread_mutexs[z]); + a->r = true; + a->key = matches[0]; + status = a->status = TH_FOUND_KEY; + a->quit = true; + pthread_mutex_unlock(&a->thread_ctx->thread_mutexs[z]); +#if TDEBUG >= 1 + printf("[slave][%zu] master, I found the key at slice %zu\n", z, a->slice + 1); + fflush(stdout); +#endif - if (a->thread_ctx->enable_condusleep) - { - pthread_mutex_lock (&a->thread_ctx->thread_mutex_usleep); - pthread_cond_signal (&a->thread_ctx->thread_cond_usleep); // unlock master/TH_PROCESSING cond - #if TDEBUG >= 1 - printf ("[slave][%zu] after pthread_cond_signal TH_FOUND_KEY\n", z); - #endif - pthread_mutex_unlock (&a->thread_ctx->thread_mutex_usleep); - } + if (a->thread_ctx->enable_condusleep) { + pthread_mutex_lock(&a->thread_ctx->thread_mutex_usleep); + pthread_cond_signal(&a->thread_ctx->thread_cond_usleep); // unlock master/TH_PROCESSING cond +#if TDEBUG >= 1 + printf("[slave][%zu] after pthread_cond_signal TH_FOUND_KEY\n", z); +#endif + pthread_mutex_unlock(&a->thread_ctx->thread_mutex_usleep); + } - pthread_exit (NULL); - } - } + pthread_exit(NULL); + } + } - if (status >= TH_FOUND_KEY) - { - #if TDEBUG >= 1 - if (status == TH_FOUND_KEY) - { - printf ("[slave][%zu] master, TH_FOUND_KEY, if you see this message, something is wrong\n", z); - fflush (stdout); - } - else if (status == TH_END) - { - printf ("[slave][%zu] master, TH_END reached\n", z); - fflush (stdout); - } - #endif - pthread_exit (NULL); - } + if (status >= TH_FOUND_KEY) { +#if TDEBUG >= 1 + if (status == TH_FOUND_KEY) { + printf("[slave][%zu] master, TH_FOUND_KEY, if you see this message, something is wrong\n", z); + fflush(stdout); + } else if (status == TH_END) { + printf("[slave][%zu] master, TH_END reached\n", z); + fflush(stdout); + } +#endif + pthread_exit(NULL); + } - } while (status < TH_FOUND_KEY); + } while (status < TH_FOUND_KEY); - pthread_exit (NULL); + pthread_exit(NULL); } diff --git a/tools/hitag2crack/crack5opencl/threads.h b/tools/hitag2crack/crack5opencl/threads.h index 10f07f04b..d60c16cfc 100644 --- a/tools/hitag2crack/crack5opencl/threads.h +++ b/tools/hitag2crack/crack5opencl/threads.h @@ -34,110 +34,105 @@ License: GNU General Public License v3 or any later version (see LICENSE.txt) #include "opencl.h" #include "hitag2.h" -typedef enum thread_status -{ - TH_START = 0, - TH_WAIT, - TH_PROCESSING, - TH_STOP, - TH_ERROR, - TH_FOUND_KEY, - TH_END +typedef enum thread_status { + TH_START = 0, + TH_WAIT, + TH_PROCESSING, + TH_STOP, + TH_ERROR, + TH_FOUND_KEY, + TH_END } thread_status_t; -typedef enum thread_type -{ - THREAD_TYPE_SEQ = 0, - THREAD_TYPE_ASYNC +typedef enum thread_type { + THREAD_TYPE_SEQ = 0, + THREAD_TYPE_ASYNC } thread_type_t; -typedef enum thread_error -{ - THREAD_NOERROR = 0, - THREAD_ERROR_CTX_IS_NULL = -1, - THREAD_ERROR_CTX_IS_INIT = -2, - THREAD_ERROR_TYPE_INVALID = -3, - THREAD_ERROR_COUNT_INVALID = -4, - THREAD_ERROR_ATTR_SETDETACH = -5, - THREAD_ERROR_ATTR = -6, - THREAD_ERROR_MUTEXATTR = -7, - THREAD_ERROR_CREATE = -8, - THREAD_ERROR_MUTEX = -9, - THREAD_ERROR_COND = -10, - THREAD_ERROR_MUTEX_USLEEP = -11, - THREAD_ERROR_COND_USLEEP = -12, - THREAD_ERROR_GENERIC = -13, - THREAD_ERROR_ALLOC = -14 +typedef enum thread_error { + THREAD_NOERROR = 0, + THREAD_ERROR_CTX_IS_NULL = -1, + THREAD_ERROR_CTX_IS_INIT = -2, + THREAD_ERROR_TYPE_INVALID = -3, + THREAD_ERROR_COUNT_INVALID = -4, + THREAD_ERROR_ATTR_SETDETACH = -5, + THREAD_ERROR_ATTR = -6, + THREAD_ERROR_MUTEXATTR = -7, + THREAD_ERROR_CREATE = -8, + THREAD_ERROR_MUTEX = -9, + THREAD_ERROR_COND = -10, + THREAD_ERROR_MUTEX_USLEEP = -11, + THREAD_ERROR_COND_USLEEP = -12, + THREAD_ERROR_GENERIC = -13, + THREAD_ERROR_ALLOC = -14 } thread_error_t; -typedef struct threads_ctx -{ - short init; - short type; +typedef struct threads_ctx { + short init; + short type; - unsigned char pad1[4]; - size_t thread_count; + unsigned char pad1[4]; + size_t thread_count; - pthread_t *thread_handles; + pthread_t *thread_handles; - pthread_mutex_t *thread_mutexs; - pthread_cond_t *thread_conds; + pthread_mutex_t *thread_mutexs; + pthread_cond_t *thread_conds; - short enable_condusleep; + short enable_condusleep; - // get rid of sleep/usleep call to synchronize threads - unsigned char pad2[6]; - pthread_mutex_t thread_mutex_usleep; - pthread_cond_t thread_cond_usleep; + // get rid of sleep/usleep call to synchronize threads + unsigned char pad2[6]; + pthread_mutex_t thread_mutex_usleep; + pthread_cond_t thread_cond_usleep; - pthread_attr_t attr; - pthread_mutexattr_t mutex_attr; + pthread_attr_t attr; + pthread_mutexattr_t mutex_attr; } thread_ctx_t; // used by threads engine -typedef struct thread_arg -{ - thread_status_t status; - unsigned char pad1[4]; - size_t max_threads; +typedef struct thread_arg { + thread_status_t status; + unsigned char pad1[4]; + size_t max_threads; - uint64_t s; - uint32_t uid, nR1, aR1, nR2, aR2; - bool r; - bool err; - bool quit; - bool async; + uint64_t s; + uint32_t uid, nR1, aR1, nR2, aR2; + bool r; + bool err; + bool quit; + bool async; - uint64_t off; - uint64_t *matches; - uint32_t *matches_found; - size_t slice; - size_t max_step; - size_t device_id; + uint64_t off; + uint64_t *matches; + uint32_t *matches_found; + size_t slice; + size_t max_step; + size_t device_id; - uint64_t key; + uint64_t key; - opencl_ctx_t *ocl_ctx; - thread_ctx_t *thread_ctx; + opencl_ctx_t *ocl_ctx; + thread_ctx_t *thread_ctx; } thread_args_t; -int thread_init (thread_ctx_t *ctx, short type, size_t thread_count); -int thread_start (thread_ctx_t *ctx, thread_args_t *args); -int thread_stop (thread_ctx_t *ctx); +int thread_init(thread_ctx_t *ctx, short type, size_t thread_count); +int thread_start(thread_ctx_t *ctx, thread_args_t *args); +int thread_stop(thread_ctx_t *ctx); -void tprintf (const char * restrict format, ...); -const char *thread_strerror (int error); -const char *thread_status_strdesc (thread_status_t s); -bool thread_setEnd (thread_ctx_t *ctx, thread_args_t *t_arg); +void tprintf(const char *restrict format, ...); +const char *thread_strerror(int error); +const char *thread_status_strdesc(thread_status_t s); +bool thread_setEnd(thread_ctx_t *ctx, thread_args_t *t_arg); -void *computing_process (void *arg); -void *computing_process_async (void *arg); +void *computing_process(void *arg); +void *computing_process_async(void *arg); -int thread_destroy (thread_ctx_t *ctx); +int thread_destroy(thread_ctx_t *ctx); #endif // THREADS_H