stateVector->cols = ret.cols;
}
-
void qansel_toffoli(cpx_mtx_t* stateVector, unsigned char qubitCount, unsigned char bitA, unsigned char bitB, unsigned char bitC)
{
if (bitA >= qubitCount || bitB >= qubitCount) return;
return 0;
}
+int qansel_get_barrier(int** q, int qubitCount, int bitCount, unsigned char* binary, int pos)
+{
+
+ unsigned char instr = binary[pos];
+ switch (instr)
+ {
+ case QANSEL_INSTRUCTION_SAMPLE:
+ case QANSEL_INSTRUCTION_RAND:
+ case QANSEL_INSTRUCTION_HVAR:
+ case QANSEL_INSTRUCTION_EXIT:
+ case QANSEL_INSTRUCTION_IF_E:
+ case QANSEL_INSTRUCTION_IF_NE:
+ case QANSEL_INSTRUCTION_IF_G:
+ case QANSEL_INSTRUCTION_IF_GE:
+ case QANSEL_INSTRUCTION_IF_L:
+ case QANSEL_INSTRUCTION_IF_LE:
+ *q = NULL;
+ return 0;
+ case QANSEL_INSTRUCTION_X:
+ case QANSEL_INSTRUCTION_Y:
+ case QANSEL_INSTRUCTION_Z:
+ case QANSEL_INSTRUCTION_H:
+ case QANSEL_INSTRUCTION_S:
+ case QANSEL_INSTRUCTION_T:
+ case QANSEL_INSTRUCTION_RX:
+ case QANSEL_INSTRUCTION_RY:
+ case QANSEL_INSTRUCTION_RZ:
+ case QANSEL_INSTRUCTION_U1:
+ case QANSEL_INSTRUCTION_U2:
+ case QANSEL_INSTRUCTION_U3:
+ //only barrier single-qubit instructions if
+ // they are nexted in an if statement
+ if (pos >= (1 + sizeof(unsigned short)))
+ {
+ switch (binary[pos - (1 + sizeof(unsigned short))])
+ {
+ case QANSEL_INSTRUCTION_IF_E:
+ case QANSEL_INSTRUCTION_IF_NE:
+ case QANSEL_INSTRUCTION_IF_G:
+ case QANSEL_INSTRUCTION_IF_GE:
+ case QANSEL_INSTRUCTION_IF_L:
+ case QANSEL_INSTRUCTION_IF_LE:
+ *q = malloc(1);
+ (*q)[0] = binary[pos + 1] + QANSEL_QBOUND_LOWER;
+ return 1;
+ }
+ }
+ *q = NULL;
+ return 0;
+ case QANSEL_INSTRUCTION_MEASURE:
+ case QANSEL_INSTRUCTION_DENSITY:
+ *q = malloc(2);
+ (*q)[0] = binary[pos + 1] + QANSEL_QBOUND_LOWER;
+ (*q)[1] = binary[pos + 2] + QANSEL_CBOUND_LOWER;
+ return 1;
+ case QANSEL_INSTRUCTION_BORN:
+ case QANSEL_INSTRUCTION_BARRIER:
+ case QANSEL_INSTRUCTION_PRINT:
+ case QANSEL_INSTRUCTION_RESET:
+ switch (binary[pos + 1])
+ {
+ case QANSEL_ALL:
+ *q = malloc(sizeof(int) * (qubitCount + bitCount));
+ for (int i = 0; i < qubitCount; i++)
+ {
+ (*q)[i] = i + QANSEL_QBOUND_LOWER;
+ }
+ for (int i = 0; i < bitCount; i++)
+ {
+ (*q)[i] = i + QANSEL_CBOUND_LOWER;
+ }
+ return qubitCount + bitCount;
+ case QANSEL_ALL_QUANTUM:
+ *q = malloc(sizeof(int) * qubitCount);
+ for (int i = 0; i < qubitCount; i++)
+ {
+ (*q)[i] = i + QANSEL_QBOUND_LOWER;
+ }
+ return qubitCount;
+ case QANSEL_ALL_CLASSIC:
+ *q = malloc(sizeof(int) * bitCount);
+ for (int i = 0; i < bitCount; i++)
+ {
+ (*q)[i] = i + QANSEL_CBOUND_LOWER;
+ }
+ return bitCount;
+ default:
+ *q = malloc(1);
+ (*q)[0] = binary[pos + 1];
+ return 1;
+ }
+ case QANSEL_INSTRUCTION_CX:
+ case QANSEL_INSTRUCTION_SWAP:
+ *q = malloc(2);
+ (*q)[0] = binary[pos + 1] + QANSEL_QBOUND_LOWER;
+ (*q)[1] = binary[pos + 2] + QANSEL_QBOUND_LOWER;
+ return 2;
+ case QANSEL_INSTRUCTION_CCX:
+ case QANSEL_INSTRUCTION_CSWAP:
+ *q = malloc(3);
+ (*q)[0] = binary[pos + 1] + QANSEL_QBOUND_LOWER;
+ (*q)[1] = binary[pos + 2] + QANSEL_QBOUND_LOWER;
+ (*q)[2] = binary[pos + 3] + QANSEL_QBOUND_LOWER;
+ return 3;
+ }
+ fprintf(stderr, "QAnsel (%04X): Unknown error in barrier analysis.\n", pos);
+}
+
int qansel_get_instruction_size(unsigned char instr)
{
switch (instr)
case QANSEL_INSTRUCTION_U3:
queueFlushed = 0;
break;
+ case QANSEL_INSTRUCTION_IF_E:
+ case QANSEL_INSTRUCTION_IF_NE:
+ case QANSEL_INSTRUCTION_IF_G:
+ case QANSEL_INSTRUCTION_IF_GE:
+ case QANSEL_INSTRUCTION_IF_L:
+ case QANSEL_INSTRUCTION_IF_LE:
+ case QANSEL_INSTRUCTION_SAMPLE:
+ case QANSEL_INSTRUCTION_HVAR:
+ case QANSEL_INSTRUCTION_RAND:
+ break;
default:
qansel_instruction(&stateVector, qubitCount, instr, 0, 0, 0, 0, &queueVector);
for (int i = 0; i < qubitCount; i++)
+++ /dev/null
-#include <stdio.h>
-#include <time.h>
-#if defined(_WIN32) || defined(_WIN64)
-#include <windows.h>
-#elif defined(__linux__)
-#include <unistd.h>
-#include <sys/time.h>
-#elif defined(__APPLE__)
-#include <sys/sysctl.h>
-#endif
-
-int ___get_core_count()
-{
- #if defined(_WIN32) || defined(_WIN64)
- SYSTEM_INFO sysinfo;
- GetSystemInfo(&sysinfo);
- return sysinfo.dwNumberOfProcessors;
- #elif defined(__linux__)
- return sysconf(_SC_NPROCESSORS_ONLN);
- #elif defined(__APPLE__)
- int nm[2];
- size_t len = 4;
- uint32_t count;
-
- nm[0] = CTL_HW;
- nm[1] = HW_AVAILCPU;
- sysctl(nm, 2, &count, &len, NULL, 0);
-
- if(count < 1) {
- nm[1] = HW_NCPU;
- sysctl(nm, 2, &count, &len, NULL, 0);
- if(count < 1) {
- count = 1;
- }
- }
- return count;
- #else
- return -1; // Unknown platform
- #endif
-}
-
-int get_core_count()
-{
- static int coreCount = -1;
- if (coreCount == -1)
- {
- coreCount = ___get_core_count();
- if (coreCount == -1)
- {
- coreCount = 1;
- }
- }
- return coreCount;
-}
-
-unsigned long int get_time()
-{
- struct timeval tv;
- gettimeofday(&tv,NULL);
- unsigned long int timestamp = 1000000 * tv.tv_sec + tv.tv_usec;
- return timestamp;
-}
\ No newline at end of file
--- /dev/null
+#include <stdio.h>
+#include <time.h>
+#if defined(_WIN32) || defined(_WIN64)
+#include <windows.h>
+#elif defined(__linux__)
+#include <unistd.h>
+#include <sys/time.h>
+#elif defined(__APPLE__)
+#include <sys/sysctl.h>
+#endif
+
+int ___get_core_count()
+{
+ #if defined(_WIN32) || defined(_WIN64)
+ SYSTEM_INFO sysinfo;
+ GetSystemInfo(&sysinfo);
+ return sysinfo.dwNumberOfProcessors;
+ #elif defined(__linux__)
+ return sysconf(_SC_NPROCESSORS_ONLN);
+ #elif defined(__APPLE__)
+ int nm[2];
+ size_t len = 4;
+ uint32_t count;
+
+ nm[0] = CTL_HW;
+ nm[1] = HW_AVAILCPU;
+ sysctl(nm, 2, &count, &len, NULL, 0);
+
+ if(count < 1) {
+ nm[1] = HW_NCPU;
+ sysctl(nm, 2, &count, &len, NULL, 0);
+ if(count < 1) {
+ count = 1;
+ }
+ }
+ return count;
+ #else
+ return -1; // Unknown platform
+ #endif
+}
+
+int get_core_count()
+{
+ static int coreCount = -1;
+ if (coreCount == -1)
+ {
+ coreCount = ___get_core_count();
+ if (coreCount == -1)
+ {
+ coreCount = 1;
+ }
+ }
+ return coreCount;
+}
+
+unsigned long int get_time()
+{
+ struct timeval tv;
+ gettimeofday(&tv,NULL);
+ unsigned long int timestamp = 1000000 * tv.tv_sec + tv.tv_usec;
+ return timestamp;
+}
+
+int qansel_hardware_rand_supported()
+{
+ #if defined(__x86_64__) || defined(__i386__)
+ int result = 0;
+
+ // Execute CPUID instruction with feature request
+ __asm__ volatile
+ (
+ "mov $7, %%eax;mov $0, %%ecx;cpuid;mov %%ebx, %0;"
+ : "=r" (result)
+ :
+ : "eax", "ebx", "ecx", "edx"
+ );
+ return (result >> 18) & 1;
+ #else
+ return 0;
+ #endif
+}
+int qansel_hardware_rand()
+{
+
+}