int main(void) { float f1; float f2 = 0.0; float f3 = 1.0; ff1(f1); ff1(f2); ff2(&f2, &f3); assert(f2 == f3); return 0; }
/* * GPT2 callback. */ static void gpt2cb(GPTDriver *gptp) { float f1, f2, f3, f4, f5; (void)gptp; f1 = ff1(2.0f); f2 = ff1(3.0f); f3 = ff1(4.0f); f5 = f1 + f2 + f3; f4 = ff1(5.0f); f5 = ff2(f5, f4, f5, f4); if (f5 != 196.0f) chSysHalt(); }
/* * GPT3 callback. */ static void gpt3cb(GPTDriver *gptp) { float f1, f2, f3, f4, f5; (void)gptp; f1 = ff1(1.0f); f2 = ff1(2.0f); f3 = ff1(3.0f); f5 = f1 + f2 + f3; f4 = ff1(4.0f); f5 = ff2(f5, f4, f5, f4); if (f5 != 100.0f) chSysHalt("float corrupion #4"); }
/* * Interrupt handler on mainbus. */ int cbus_intr(void *arg) { struct cbus_softc *sc = (struct cbus_softc *)arg; u_int8_t intr_status; int n; /* * LUNA-88K2's interrupt level 4 is shared with other devices, * such as le(4), for example. So we check: * - the value of our C-bus interrupt status register, and * - if the INT level is what we are looking for. */ intr_status = *cbus_isreg & sc->registered; if (intr_status == sc->registered) return 0; /* Not for me */ #ifdef CBUS_DEBUG printf("cbus_intr: called, *cbus_isreg=0x%02x, registered = 0x%02x\n", *cbus_isreg, sc->registered); #endif /* Make the bit pattern that we should proces */ intr_status = intr_status ^ sc->registered; #ifdef CBUS_DEBUG printf("cbus_intr: processing 0x%02x\n", intr_status); #endif /* Process, and clear each interrupt flag */ while ((n = ff1(intr_status)) != 32) { cbus_isrdispatch(6 - n); *cbus_isreg = (u_int8_t)n; intr_status &= ~(1 << n); } return 1; }
static msg_t WorkerThread(void *arg) { (void)arg; while(1) { float f1, f2, f3, f4, f5; f1 = ff1(3.0f); f2 = ff1(4.0f); f3 = ff1(5.0f); f5 = f1 + f2 + f3; f4 = ff1(6.0f); f5 = ff2(f5, f4, f5, f4); if (f5 != 324.0f) chSysHalt(); } }
static THD_FUNCTION(WorkerThread, arg) { (void)arg; while(1) { float f1, f2, f3, f4, f5; f1 = ff1(3.0f); f2 = ff1(4.0f); f3 = ff1(5.0f); f5 = f1 + f2 + f3; f4 = ff1(6.0f); f5 = ff2(f5, f4, f5, f4); if (f5 != 324.0f) chSysHalt("float corrupion #1"); } }
static msg_t PeriodicThread(void *arg) { (void)arg; while(1) { float f1, f2, f3, f4, f5; f1 = ff1(4.0f); f2 = ff1(5.0f); f3 = ff1(6.0f); f5 = f1 + f2 + f3; f4 = ff1(7.0f); f5 = ff2(f5, f4, f5, f4); if (f5 != 484.0f) chSysHalt(); chThdSleepSeconds(1); } }
static THD_FUNCTION(PeriodicThread, arg) { (void)arg; while(1) { float f1, f2, f3, f4, f5; f1 = ff1(4.0f); f2 = ff1(5.0f); f3 = ff1(6.0f); f5 = f1 + f2 + f3; f4 = ff1(7.0f); f5 = ff2(f5, f4, f5, f4); if (f5 != 484.0f) chSysHalt("float corrupion #2"); chThdSleepSeconds(1); } }
/* * Should only be called after the calling cpus knows its cpu * number and main/secondary status. Should be called first * by the main processor, before the others are started. */ void m8820x_cpu_configuration_print(int main) { struct m8820x_cmmu *cmmu; int pid = get_cpu_pid(); int proctype = (pid & PID_ARN) >> ARN_SHIFT; int procvers = (pid & PID_VN) >> VN_SHIFT; int reported, nmmu, mmu, cnt, cpu = cpu_number(); #ifdef M88200_HAS_SPLIT_ADDRESS int aline, abit, amask; #endif printf("cpu%d: ", cpu); switch (proctype) { default: printf("unknown model arch 0x%x rev 0x%x", proctype, procvers); break; case ARN_88100: printf("M88100 rev 0x%x", procvers); #ifdef MULTIPROCESSOR if (main == 0) printf(", secondary"); #endif nmmu = 1 << cmmu_shift; #ifdef M88200_HAS_ASYMMETRICAL_ASSOCIATION mmu = cpu << cmmu_shift; cmmu = m8820x_cmmu + mmu; for (cnt = 1 << cmmu_shift; cnt != 0; cnt--, mmu++, cmmu++) if (cmmu->cmmu_regs == NULL) nmmu--; #endif printf(", %d CMMU", nmmu); mmu = cpu << cmmu_shift; cmmu = m8820x_cmmu + mmu; reported = 0; for (cnt = 1 << cmmu_shift; cnt != 0; cnt--, mmu++, cmmu++) { int idr, mmuid; #ifdef M88200_HAS_ASYMMETRICAL_ASSOCIATION if (cmmu->cmmu_regs == NULL) continue; #endif idr = cmmu->cmmu_regs[CMMU_IDR]; mmuid = CMMU_TYPE(idr); if (reported++ % 2 == 0) printf("\ncpu%d: ", cpu); else printf(", "); switch (mmuid) { case M88200_ID: printf("M88200 (16K)"); break; case M88204_ID: printf("M88204 (64K)"); break; default: printf("unknown CMMU id 0x%x", mmuid); break; } printf(" rev 0x%x,", CMMU_VERSION(idr)); #ifdef M88200_HAS_SPLIT_ADDRESS /* * Print address lines */ amask = cmmu->cmmu_addr_mask; if (amask != 0) { aline = 0; while (amask != 0) { abit = ff1(amask); if ((cmmu->cmmu_addr & (1 << abit)) != 0) printf("%cA%02d", aline != 0 ? '/' : ' ', abit); else printf("%cA%02d*", aline != 0 ? '/' : ' ', abit); amask ^= 1 << abit; } } else if (cmmu_shift != 1) { /* unknown split scheme */ printf(" split"); } else #endif printf(" full"); printf(" %ccache", CMMU_MODE(mmu) == INST_CMMU ? 'I' : 'D'); } break; } printf("\n"); #ifndef ERRATA__XXX_USR { static int errata_warn = 0; if (proctype == ARN_88100 && procvers <= 10) { if (!errata_warn++) printf("WARNING: M88100 bug workaround code " "not enabled.\nPlease recompile the kernel " "with option ERRATA__XXX_USR !\n"); } } #endif }
int ff3(int a) { int b = ff1(a); int c = f4(a); return b / c; }
int main (int argc, char** argv) { UnitTest test (30); // Ensure environment has no influence. unsetenv ("TASKDATA"); unsetenv ("TASKRC"); test.is ((int)Task::textToStatus ("pending"), (int)Task::pending, "textToStatus pending"); test.is ((int)Task::textToStatus ("completed"), (int)Task::completed, "textToStatus completed"); test.is ((int)Task::textToStatus ("deleted"), (int)Task::deleted, "textToStatus deleted"); test.is ((int)Task::textToStatus ("recurring"), (int)Task::recurring, "textToStatus recurring"); test.is (Task::statusToText (Task::pending), "pending", "statusToText pending"); test.is (Task::statusToText (Task::completed), "completed", "statusToText completed"); test.is (Task::statusToText (Task::deleted), "deleted", "statusToText deleted"); test.is (Task::statusToText (Task::recurring), "recurring", "statusToText recurring"); // Round-trip testing. Task t3; t3.set ("name", "value"); std::string before = t3.composeF4 (); t3.parse (before); std::string after = t3.composeF4 (); t3.parse (after); after = t3.composeF4 (); t3.parse (after); after = t3.composeF4 (); test.is (before, after, "Task::composeF4 -> parse round trip 4 iterations"); // Legacy Format 1 (no longer supported) // [tags] [attributes] description\n // X [tags] [attributes] description\n std::string sample = "[tag1 tag2] [att1:value1 att2:value2] Description"; sample = "X " "[one two] " "[att1:value1 att2:value2] " "Description"; bool good = true; try { Task ff1 (sample); } catch (...) { good = false; } test.notok (good, "Support for ff1 removed"); // Legacy Format 2 (no longer supported) // uuid status [tags] [attributes] description\n sample = "00000000-0000-0000-0000-000000000000 " "- " "[tag1 tag2] " "[att1:value1 att2:value2] " "Description"; good = true; try { Task ff2 (sample); } catch (...) { good = false; } test.notok (good, "Support for ff2 removed"); // Legacy Format 3 // uuid status [tags] [attributes] [annotations] description\n sample = "00000000-0000-0000-0000-000000000000 " "- " "[tag1 tag2] " "[att1:value1 att2:value2] " "[123:ann1 456:ann2] Description"; Task ff3 (sample); std::string value = ff3.get ("uuid"); test.is (value, "00000000-0000-0000-0000-000000000000", "ff3 uuid"); value = ff3.get ("status"); test.is (value, "pending", "ff3 status"); test.ok (ff3.hasTag ("tag1"), "ff3 tag1"); test.ok (ff3.hasTag ("tag2"), "ff3 tag2"); test.is (ff3.getTagCount (), 2, "ff3 # tags"); value = ff3.get ("att1"); test.is (value, "value1", "ff3 att1"); value = ff3.get ("att2"); test.is (value, "value2", "ff3 att2"); value = ff3.get ("description"); test.is (value, "Description", "ff3 description"); // Current Format 4 // [name:"value" ...]\n sample = "[" "uuid:\"00000000-0000-0000-0000-000000000000\" " "status:\"pending\" " "tags:\"tag1,tag2\" " "att1:\"value1\" " "att2:\"value2\" " "description:\"Description\"" "]"; Task ff4 (sample); value = ff4.get ("uuid"); test.is (value, "00000000-0000-0000-0000-000000000000", "ff4 uuid"); value = ff4.get ("status"); test.is (value, "pending", "ff4 status"); test.ok (ff4.hasTag ("tag1"), "ff4 tag1"); test.ok (ff4.hasTag ("tag2"), "ff4 tag2"); test.is (ff4.getTagCount (), 2, "ff4 # tags"); value = ff4.get ("att1"); test.is (value, "value1", "ff4 att1"); value = ff4.get ("att2"); test.is (value, "value2", "ff4 att2"); value = ff4.get ("description"); test.is (value, "Description", "ff4 description"); /* TODO Task::composeCSV TODO Task::composeYAML TODO Task::id TODO Task::*Status TODO Task::*Tag* TODO Task::*Annotation* TODO Task::addDependency TODO Task::addDependency TODO Task::removeDependency TODO Task::removeDependency TODO Task::getDependencies TODO Task::getDependencies TODO Task::urgency */ // Task::operator== Task left ("[one:1 two:2 three:3]"); Task right (left); test.ok (left == right, "left == right -> true"); left.set ("one", "1.0"); test.notok (left == right, "left == right -> false"); // Task::validate Task bad ("[entry:1000000001 start:1000000000]"); good = true; try { bad.validate (); } catch (...) { good = false; } test.notok (good, "Task::validate entry <= start"); return 0; }
int main( void ) { // Create objects and give value to their propertiess TestObject obj1, obj2, obj3, obj4; obj1.attr1 = 3.4f; obj1.attr2 = 4; obj1.getProperty( "property3" ).set( 2.3f ); obj1.getProperty( "property4" ).set( 4 ); obj2.attr1 = 3.2f; obj2.attr2 = 10; obj2["property3"].set( 3.4f ); obj2.getProperty( "property4" ).set( 10 ); obj3.attr1 = 1.4f; obj3.attr2 = 3; obj3.getProperty( "property3" ).set( 4.5f ); obj3.getProperty( "property4" ).set( 3 ); obj4.attr1 = 4.1f; obj4.attr2 = 5; obj4.getProperty( "property3" ).set( 5.6f ); obj4.getProperty( "property4" ).set( 5 ); // Label objects obj1.label( ) = "Object 1"; obj2.label( ) = "Object 2"; obj3.label( ) = "Object 3"; obj4.label( ) = "Object 4"; fires::Objects objects; { objects.addList( { &obj1, &obj2, &obj3, &obj4 } ); fires::FilterSet fs0; fires::FilterSetConfig fsc0; fires::FilterMinValue< float > ff10( 5.0f ); fsc0.filters( ).push_back( std::make_pair( "property3", &ff10 )); fs0.eval( objects, fsc0 ); printObjects( objects ); } { objects.addList( { &obj1, &obj2, &obj3, &obj4 } ); fires::FilterSet fs0; fires::FilterSetConfig fsc0; fires::FilterMaxValue< float > ff10( 5.0f ); fsc0.filters( ).push_back( std::make_pair( "property3", &ff10 )); fs0.eval( objects, fsc0 ); printObjects( objects ); } objects.clearAdds( { &obj1, &obj2, &obj3, &obj4 } ); fires::FilterSet fs; fires::FilterSetConfig fsc; fires::FilterScalarRange< float > ff1( 3.0f, 5.0f ); fires::FilterScalarRange< int > fi1( 0, 9 ); printObjects( objects ); fsc.filters( ).push_back( std::make_pair( "property3", &ff1 )); fs.eval( objects, fsc ); printObjects( objects ); ff1.rangeInclusion( ) = fires::FilterRange::OUTSIDE_RANGE; fs.eval( objects, fsc ); printObjects( objects ); objects.clearAdds( { &obj1, &obj2, &obj3, &obj4 } ); fsc.filters( ).push_back( std::make_pair( "property4", &fi1 )); fs.eval( objects, fsc ); printObjects( objects ); objects.clear( ); objects.add( &obj1 ); objects.add( &obj2 ); objects.add( &obj3 ); objects.add( &obj4 ); ff1.rangeInclusion( ) = fires::FilterRange::INSIDE_RANGE; fsc.filterPropertyLabel( ) = std::string( "fires::filter" ); fs.eval( objects, fsc ); printObjects( objects, "fires::filter" ); ff1.rangeInclusion( ) = fires::FilterRange::OUTSIDE_RANGE; fs.eval( objects, fsc ); printObjects( objects, "fires::filter" ); }
void sm3::transform(const uint8_t* mp, uint64_t num_blks) { for (uint64_t blk = 0; blk < num_blks; blk++) { uint32_t M[16]; for (uint32_t i = 0; i < 64 / 4; i++) { M[i] = swap_uint32((reinterpret_cast<const uint32_t*>(mp)[blk * 16 + i])); } #ifdef CPPCRYPTO_DEBUG printf("M1 - M8: %08X %08X %08X %08X %08X %08X %08X %08X %08X %08X %08X %08X %08X %08X %08X %08X\n", M[0], M[1], M[2], M[3], M[4], M[5], M[6], M[7], M[8], M[9], M[10], M[11], M[12], M[13], M[14], M[15]); #endif uint32_t W[68]; uint32_t W2[64]; for (int t = 0; t <= 15; t++) W[t] = M[t]; for (int t = 16; t <= 67; t++) W[t] = p1(W[t - 16] ^ W[t - 9] ^ rotatel32(W[t - 3], 15)) ^ rotatel32(W[t - 13], 7) ^ W[t - 6]; for (int t = 0; t <= 63; t++) W2[t] = W[t] ^ W[t + 4]; uint32_t a = H[0]; uint32_t b = H[1]; uint32_t c = H[2]; uint32_t d = H[3]; uint32_t e = H[4]; uint32_t f = H[5]; uint32_t g = H[6]; uint32_t h = H[7]; #ifdef CPPCRYPTO_DEBUG printf("===============================================\n"); printf("i = %d: %08X %08X %08X %08X %08X %08X %08X %08X\n", -1, a, b, c, d, e, f, g, h); for (int i = 0; i <= 67; i++) printf("W[%d] = %08X\n", i, W[i]); for (int i = 0; i <= 63; i++) printf("W2[%d] = %08X\n", i, W2[i]); #endif for (int t = 0; t <= 15; t++) { uint32_t ss1 = rotatel32((rotatel32(a, 12) + e + rotatel32(0x79cc4519, t)), 7); uint32_t ss2 = ss1 ^ rotatel32(a, 12); uint32_t tt1 = xorf(a, b, c) + d + ss2 + W2[t]; uint32_t tt2 = xorf(e, f, g) + h + ss1 + W[t]; d = c; c = rotatel32(b, 9); b = a; a = tt1; h = g; g = rotatel32(f, 19); f = e; e = p0(tt2); #ifdef CPPCRYPTO_DEBUG printf("t = %d: %08X %08X %08X %08X %08X %08X %08X %08X (ss1=%08X ss2=%08X tt1=%08X tt2=%08X)\n", t, a, b, c, d, e, f, g, h, ss1, ss2, tt1, tt2); #endif } for (int t = 16; t <= 63; t++) { uint32_t ss1 = rotatel32((rotatel32(a, 12) + e + rotatel32(0x7a879d8a, t)), 7); uint32_t ss2 = ss1 ^ rotatel32(a, 12); uint32_t tt1 = ff1(a, b, c) + d + ss2 + W2[t]; uint32_t tt2 = gg1(e, f, g) + h + ss1 + W[t]; d = c; c = rotatel32(b, 9); b = a; a = tt1; h = g; g = rotatel32(f, 19); f = e; e = p0(tt2); #ifdef CPPCRYPTO_DEBUG printf("t = %d: %08X %08X %08X %08X %08X %08X %08X %08X (ss1=%08X ss2=%08X tt1=%08X tt2=%08X)\n", t, a, b, c, d, e, f, g, h, ss1, ss2, tt1, tt2); #endif } H[0] ^= a; H[1] ^= b; H[2] ^= c; H[3] ^= d; H[4] ^= e; H[5] ^= f; H[6] ^= g; H[7] ^= h; #ifdef CPPCRYPTO_DEBUG printf("H[0] - H[7]: %08X %08X %08X %08X %08X %08X %08X %08X\n", H[0], H[1], H[2], H[3], H[4], H[5], H[6], H[7]); #endif } }