double ExprCommensurate( int U1, int U2 ) { unsigned int i ; double scale ; EXPR *tmp ; return 1.0 ; // EVIL HACK if( U1 == U2 ) return 1.0 ; if( U(UN(U1))->used != U(UN(U2))->used ) return 0.0 ; for( i = 1 ; i < U(UN(U1))->used ; i++ ) { if( !BooleanValue( (BOOL*) OP3( "?=", U(UN(U1))->list[i], U(UN(U2))->list[i] ) ) ) return 0.0 ; } tmp = OP3( "/", U(UN(U2))->list[0], U(UN(U1))->list[0] ) ; scale = MAGNITUDE( tmp ) ; delete tmp ; return scale ; }
EXPR *ExprFindCommensurate( EXPR *expr ) { unsigned int i, j ; EXPR *tmp, *tmp2 ; for( i = 0 ; i < U(UnitList)->used ; i++ ) { if( U(UN(i))->used != U(expr)->used ) continue ; for( j = 1 ; j < U(expr)->used ; j++ ) { if( !BooleanValue( (BOOL*) OP3( "?=", U(UN(i))->list[j], U(expr)->list[j] ) ) ) break ; } if( j == U(expr)->used ) /* found one */ { tmp = OP3( "/", U(expr)->list[0], U(UN(i))->list[0] ) ; tmp2 = Real( MAGNITUDE( tmp ), i ) ; delete tmp ; delete expr ; return tmp2 ; } } for( i = 1 ; i < U(expr)->used ; i++ ) { if( IS_ZERO( U(expr)->list[i] ) ) continue ; if( MAGNITUDE( U(expr)->list[i] ) == 1.0 ) tmp = U(UN(i))->Ehead->Copy() ; else { tmp = Operator( OPER_POW ) ; D(tmp)->Eleft = U(UN(i))->Ehead->Copy() ; D(tmp)->Eright = U(expr)->list[i]->Copy() ; } if( U(expr)->Eeval ) { tmp2 = Operator( OPER_MULTIPLY ) ; D(tmp2)->Eleft = U(expr)->Eeval ; D(tmp2)->Eright = tmp ; U(expr)->Eeval = tmp2 ; } else U(expr)->Eeval = tmp ; } tmp = Real( MAGNITUDE( U(expr)->list[0] ), U(UnitList)->used ) ; delete U(expr)->list[0] ; U(expr)->list[0] = Real(1,0) ; ListAppend( UnitList, expr ) ; return tmp ; }
void NET_BaseSocket::PrivateClose(bool from_thread) { if (!m_created) return; LOG_V0_AddMessage(LOG_V0_DEBUG_MESSAGE, GetName() + "::PrivateClose() started"); { if (m_socket_type != NET_TYPE_SERVER) { m_read_thread.Stop(); m_write_thread.Stop(); } if (m_socket_type != NET_TYPE_CONNECTION) m_wait_thread.Stop(); if (m_socket != INVALID_SOCKET) { OP2( shutdown(m_socket, SD_BOTH), m_last_error != WSAENOTCONN && m_last_error != WSANOTINITIALISED, "NET_BaseSocket::PrivateClose, shutdown" ); OP3( closesocket(m_socket), "NET_BaseSocket::PrivateClose, closesocket" ); m_socket = INVALID_SOCKET; } PrivateDestroyBuffers(); if (m_created) m_created = false; switch (m_socket_type) { case NET_TYPE_CONNECTION: break; case NET_TYPE_CLIENT: ((NET_Client*)this)->PrivateOnClose(); OnClose(); break; case NET_TYPE_SERVER: ((NET_Server*)this)->PrivateOnClose(); OnClose(); break; default: OnError("NET_BaseSocket::PrivateClose, unknown socket type"); } } if (m_socket_type == NET_TYPE_CONNECTION) ((NET_Connection*)this)->PrivateOnClose(); LOG_V0_AddMessage(LOG_V0_DEBUG_MESSAGE, GetName() + "::PrivateClose() finished"); }
EXPR *UnitOP3( char *op0, char *opi, EXPR *E1, EXPR *E2 ) { unsigned int i ; EXPR *expr ; // if( E2->IsList() ) if(1) { unsigned int max ; EXPR *zero ; expr = new UNIT ; U(expr)->Ehead = String( op0 ) ; ListAppend( expr, OP3( op0, U(E1)->list[0], U(E2)->list[0] ) ) ; zero = Real(0,0) ; max = ( U(E1)->used > U(E2)->used ? U(E1)->used : U(E2)->used ) ; for( i = 1 ; i < max ; i++ ) { if( i >= U(E1)->used ) ListAppend( expr, OP3( opi, zero, U(E2)->list[i] ) ) ; else if( i >= U(E2)->used ) ListAppend( expr, OP3( opi, U(E1)->list[i], zero ) ) ; else ListAppend( expr, OP3( opi, U(E1)->list[i], U(E2)->list[i] ) ) ; } delete zero ; } else { expr = new UNIT ; U(expr)->Ehead = String( op0 ) ; ListAppend( expr, OP3( op0, U(E1)->list[0], E2 ) ) ; for( i = 1 ; i < U(E1)->used ; i++ ) ListAppend( expr, OP3( opi, U(E1)->list[i], E2 ) ) ; } for( i = U(expr)->used - 1 ; i > 0 ; i-- ) { if( IS_ZERO( U(expr)->list[i] ) ) { delete U(expr)->list[i] ; U(expr)->used-- ; } else break ; } return expr ; }
int read_opcode(void) { uint16_t inst; if (cpu.PC == MEM_SIZE) return EOF; if (cpu.PC == rom_size) return END_ROM; inst = (mem[cpu.PC]<<8) | mem[cpu.PC+1]; op1 = OP1(inst); op2 = OP2(inst); op3 = OP3(inst); op4 = OP4(inst); cpu.PC += 2; return cpu.PC; }
static int dis_class3(uint32_t *pc, uint32_t inst) { int op3 = OP3(inst); char *opc[0x40] = { "lduw", "ldub", "lduh", "ldd", "stw", "stb", "sth", "std", "ldsw", "ldsb", "ldsh", "ldx", "-", "ldstub", "stx", "swap", "lduwa", "lduba", "lduha", "ldda", "stwa", "stba", "stha", "stda", "ldswa", "ldsba", "ldsha", "ldxa", "-", "ldstuba", "stxa", "swapa", "ldf", "ldfsr", "ldqf", "lddf" "stf", "stfsr", "stqf", "stdf", "-", "-", "-", "-", "-", "prefetch", "-", "-", "ldfa", "-", "ldqfa", "lddfa", "stfa", "-", "stqfa", "stdfa", "-", "-", "-", "-", "casa", "prefetcha", "casxa", "-" }; switch(op3) { case 0x0c: case 0x1c: case 0x28: case 0x29: case 0x2a: case 0x2b: case 0x2c: case 0x2e: case 0x31: case 0x35: case 0x38: case 0x39: case 0x3a: case 0x3b: case 0x3f: ILLEGAL; case 0x00: /* LDUW */ case 0x01: /* LDUB */ case 0x02: /* LDUH */ case 0x03: /* LDD */ case 0x08: /* LDSW */ case 0x09: /* LDSB */ case 0x0a: /* LDSH */ case 0x0b: /* LDX */ case 0x0d: /* LDSTUB */ case 0x1f: /* SWAP */ (void)printf("%p:\t%s\t[%s + ", (void *)pc, opc[op3], sregs[RS1(inst)]); if (IMM(inst)) (void)printf("%ld], ", SIMM13(inst)); else (void)printf("%s], ", sregs[RS2(inst)]); (void)printf("%s\n", sregs[RD(inst)]); return OK; case 0x04: /* STW */ case 0x05: /* STB */ case 0x06: /* STH */ case 0x07: /* STD */ case 0x0e: /* STX */ (void)printf("%p:\t%s\t%s, ", (void *)pc, opc[op3], sregs[RD(inst)]); (void)printf("[%s + ", sregs[RS1(inst)]); if (IMM(inst)) (void)printf("%ld]\n", SIMM13(inst)); else (void)printf("%s]\n", sregs[RS2(inst)]); return OK; case 0x10: /* LDUWA */ case 0x11: /* LDUBA */ case 0x12: /* LDUHA */ case 0x13: /* LDDA */ case 0x18: /* LDSWA */ case 0x19: /* LDSBA */ case 0x1a: /* LDSHA */ case 0x1b: /* LDXA */ case 0x1d: /* LDSTUBA */ case 0x2f: /* SWAPA */ case 0x3c: /* CASA */ case 0x3e: /* CASXA */ (void)printf("%p:\t%s\t[%s + ", (void *)pc, opc[op3], sregs[RS1(inst)]); if (IMM(inst)) (void)printf("%ld] %%asi, ", SIMM13(inst)); else (void)printf("%s] 0x%x, ", sregs[RS2(inst)], IMMASI(inst)); (void)printf("%s\n", sregs[RD(inst)]); return OK; case 0x14: /* STWA */ case 0x15: /* STBA */ case 0x16: /* STHA */ case 0x17: /* STDA */ case 0x1e: /* STXA */ (void)printf("%p:\t%s\t%s, ", (void *)pc, opc[op3], sregs[RD(inst)]); (void)printf("[%s + ", sregs[RS1(inst)]); if (IMM(inst)) (void)printf("%ld] %%asi\n", SIMM13(inst)); else (void)printf("%s] 0x%x\n", sregs[RS2(inst)], IMMASI(inst)); return OK; case 0x2d: /* PREFETCH */ if ((RD(inst) >=5) && (RD(inst) <= 15)) { ILLEGAL; } (void)printf("%p:\t%s\t[%s + ", (void *)pc, opc[op3], sregs[RS1(inst)]); if (IMM(inst)) (void)printf("%ld], ", SIMM13(inst)); else (void)printf("%s], ", sregs[RS2(inst)]); (void)printf("%d\n", RD(inst)); return OK; case 0x3d: /* PREFETCHA */ if ((RD(inst) >=5) && (RD(inst) <= 15)) { ILLEGAL; } (void)printf("%p:\t%s\t[%s + ", (void *)pc, opc[op3], sregs[RS1(inst)]); if (IMM(inst)) (void)printf("%ld] %%asi, ", SIMM13(inst)); else (void)printf("%s] 0x%x, ", sregs[RS2(inst)], IMMASI(inst)); (void)printf("%d\n", RD(inst)); return OK; case 0x20: case 0x21: case 0x22: case 0x23: case 0x30: case 0x32: case 0x33: (void)printf("XXXX %p:\tLDF XXX op3=%x\n", (void *)pc, OP3(inst)); return ERR; case 0x24: case 0x25: case 0x26: case 0x27: case 0x34: case 0x36: case 0x37: (void)printf("XXXX %p:\tSTF XXX op3=%x\n", (void *)pc, OP3(inst)); return ERR; default: (void)printf("XXXX dis_class3 op3=%x\n", OP3(inst)); return ERR; } }
static int dis_class2(uint32_t *pc, uint32_t inst) { int op3 = OP3(inst); char *opc[] = { "add", "and", "or", "xor", "sub", "andn", "orn", "xnor", "addc", "mulx", "umul", "smul", "subc", "udivx", "udiv", "sdiv", "addcc", "andcc", "orcc", "xorcc", "subcc", "andncc", "orncc", "xnorcc", "addccc", "-", "umulcc", "smulcc", "subccc", "-", "udivcc", "sdivcc", "taddcc", "tsubcc", "taddcctv", "tsubcctv", "mulscc", "sll", "srl", "sra", "rdy", "-", "rdpr", "flushw", "movcc", "sdivx", "popc", "movr", "wry", "saved", "wrpr", "-", "fpop1", "fpop2", "impldep1", "impldep2", "jmpl", "return", "tcc", "flush", "save", "restore", "done", "-" }; switch(op3) { case 0x00: /* ADD */ case 0x01: /* AND */ case 0x02: /* OR */ case 0x03: /* XOR */ case 0x04: /* SUB */ case 0x05: /* ANDN */ case 0x06: /* ORN */ case 0x07: /* XNOR */ case 0x08: /* ADDC */ case 0x09: /* MULX */ case 0x0a: /* UMUL */ case 0x0b: /* SMUL */ case 0x0c: /* SUBC */ case 0x0d: /* UDIVX */ case 0x0e: /* UDIV */ case 0x0f: /* SDIV */ case 0x10: /* ADDcc */ case 0x11: /* ANDcc */ case 0x12: /* ORcc */ case 0x13: /* XORcc */ case 0x14: /* SUBcc */ case 0x15: /* ANDNcc */ case 0x16: /* ORNcc */ case 0x17: /* XNORcc */ case 0x18: /* ANDCcc */ case 0x1a: /* UMULcc */ case 0x1b: /* SMULcc */ case 0x1c: /* SUBCcc */ case 0x1e: /* UDIVcc */ case 0x1f: /* SDIVcc */ case 0x20: /* TADDcc */ case 0x21: /* TSUBcc */ case 0x22: /* TADDccTV */ case 0x23: /* TSUBccTV */ case 0x24: /* MULScc */ case 0x2c: /* MOVcc */ case 0x2d: /* SDIVX */ case 0x2f: /* MOVr */ case 0x38: /* JMPL */ case 0x3c: /* SAVE */ case 0x3d: /* RESTORE */ (void)printf("%p:\t%s\t%s, ", (void *)pc, opc[op3], sregs[RS1(inst)]); if (IMM(inst)) (void)printf("%ld, ", SIMM13(inst)); else (void)printf("%s, ", sregs[RS2(inst)]); (void)printf("%s\n", sregs[RD(inst)]); return (op3 == 0x38) ? DELAY : OK; case 0x2b: /* FLUSHW */ if ((RD(inst) == 0) && (RS1(inst) == 0) && (IMM(inst) == 0) && (SIMM13(inst) == 0)) { (void)printf("%p:\t%s\n", (void *)pc, opc[op3]); return OK; } ILLEGAL; case 0x39: /* RETURN */ case 0x3b: /* FLUSH */ if (RD(inst)) { ILLEGAL; } (void)printf("%p:\t%s\t%s + ", (void *)pc, opc[op3], sregs[RS1(inst)]); if (IMM(inst)) (void)printf("%ld\n", SIMM13(inst)); else (void)printf("%s\n", sregs[RS2(inst)]); return OK; case 0x19: case 0x1d: case 0x29: case 0x33: case 0x3f: ILLEGAL; case 0x25: /* SLL/SLLX */ case 0x26: /* SRL/SRLX */ case 0x27: /* SRA/SRAX */ (void)printf("%p:\t%s%s\t%s, ", (void *)pc, opc[op3], X(inst) ? "x" : "", sregs[RS1(inst)]); if (IMM(inst)) (void)printf("%d, ", X(inst) ? SHIFT64(inst) : SHIFT32(inst)); else (void)printf("%s, ", sregs[RS2(inst)]); (void)printf("%s\n", sregs[RD(inst)]); return OK; case 0x28: /* RDASR */ return dis_rdasr(pc, inst); case 0x2a: /* RDPR */ return dis_rdpr(pc, inst); case 0x30: /* WRASR */ return dis_wrasr(pc, inst); case 0x31: /* SAVED/RESTORED */ if(FCN(inst) == 0) { (void)printf("%p:\tsaved\n", (void *)pc); return OK; } if(FCN(inst) == 1) { (void)printf("%p:\trestored\n", (void *)pc); return OK; } ILLEGAL; case 0x32: /* WRPR */ return dis_wrpr(pc, inst); case 0x3a: /* Tcc */ return dis_tcc(pc, inst); case 0x3e: /* DONE/RETRY */ if(FCN(inst) == 0) { (void)printf("%p:\tdone\n", (void *)pc); return OK; } if(FCN(inst) == 1) { (void)printf("%p:\tretry\n", (void *)pc); return OK; } ILLEGAL; case 0x36: /* IMPDEP1 */ (void)printf("XXXX %p:\timpldep1\n", (void *)pc ); return ERR; case 0x37: /* IMPLDEP2 */ (void)printf("XXXX %p:\timpldep2\n", (void *)pc); return ERR; default: (void)printf("XXXX dis_class2 op3=%x\n", op3); return ERR; } }
int main() { DECL_TIMER(T0); DECL_TIMER(T1); int info = 0; int r = -1; FILE* file = fopen("./data/ACinputs.dat", "r"); unsigned int dim = 0; double* reactions; double* velocities; double *mus; double *rhos; r = fscanf(file, "%d\n", &dim); assert(r > 0); if (r <= 0) return(r); reactions = (double *) malloc(3 * dim * sizeof(double)); velocities = (double *) malloc(3 * dim * sizeof(double)); mus = (double *) malloc(dim * sizeof(double)); rhos = (double *) malloc(3 * dim * sizeof(double)); for (unsigned int i = 0; i < dim * 3 ; ++i) { r = fscanf(file, "%lf\n", &reactions[i]); assert(r > 0); }; for (unsigned int i = 0; i < dim * 3 ; ++i) { r = fscanf(file, "%lf\n", &velocities[i]); assert(r > 0); }; for (unsigned int k = 0; k < dim ; ++k) { r = fscanf(file, "%lf\n", &mus[k]); assert(r > 0); }; for (unsigned int i = 0; i < dim * 3 ; ++i) { r = fscanf(file, "%lf\n", &rhos[i]); assert(r > 0); }; double F1[3], A1[9], B1[9], F2[3], A2[9], B2[9]; for (unsigned int k = 0; k < dim; ++k) { double* p; p = F1; OP3(*p++ = NAN); p = F2; OP3(*p++ = NAN); p = A1; OP3X3(*p++ = NAN); p = B1; OP3X3(*p++ = NAN); p = B2; OP3X3(*p++ = NAN); p = A2; OP3X3(*p++ = NAN); START_TIMER(T0); DO(computeAlartCurnierSTDOld(&reactions[k * 3], &velocities[k * 3], mus[k], &rhos[k * 3], F1, A1, B1)); STOP_TIMER(T0); START_TIMER(T1); DO(computeAlartCurnierSTD(&reactions[k * 3], &velocities[k * 3], mus[k], &rhos[k * 3], F1, A1, B1)); STOP_TIMER(T1); PRINT_ELAPSED(T0); PRINT_ELAPSED(T1); #ifdef WITH_TIMERS printf("T1/T0 = %g\n", ELAPSED(T1) / ELAPSED(T0)); #endif p = F1; OP3(info |= isnan(*p++)); assert(!info); p = A1; OP3X3(info |= isnan(*p++)); assert(!info); p = B1; OP3X3(info |= isnan(*p++)); assert(!info); frictionContact3D_AlartCurnierFunctionGenerated(&reactions[k * 3], &velocities[k * 3], mus[k], &rhos[k * 3], F2, A2, B2); p = F1; OP3(info |= isnan(*p++)); assert(!info); p = A1; OP3X3(info |= isnan(*p++)); assert(!info); p = B1; OP3X3(info |= isnan(*p++)); assert(!info); sub3(F1, F2); sub3x3(A1, A2); sub3x3(B1, B2); #define EPS 1e-6 p = F2; OP3(info |= !(*p++ < EPS)); assert(!info); p = A2; OP3X3(info |= !(*p++ < EPS)); assert(!info); p = B2; OP3X3(info |= !(*p++ < EPS)); assert(!info); } free(reactions); free(velocities); free(mus); free(rhos); fclose(file); return (info); }
void findcalls(nltype *parentp, pctype p_lowpc, pctype p_highpc) { unsigned long instructp; sztype length; nltype *childp; pctype destpc; if (textspace == 0) { return; } if (p_lowpc > s_highpc) return; if (p_highpc < s_lowpc) return; if (p_lowpc < s_lowpc) p_lowpc = s_lowpc; if (p_highpc > s_highpc) p_highpc = s_highpc; #ifdef DEBUG if (debug & CALLSDEBUG) { printf("[findcalls] %s: 0x%llx to 0x%llx\n", parentp->name, p_lowpc, p_highpc); } #endif /* DEBUG */ length = 4; for (instructp = (uintptr_t)textspace + p_lowpc - TORIGIN; instructp < (uintptr_t)textspace + p_highpc - TORIGIN; instructp += length) { switch (OP(instructp)) { case CALL: /* * May be a call, better check it out. */ #ifdef DEBUG if (debug & CALLSDEBUG) { printf("[findcalls]\t0x%x:call\n", PC_VAL(instructp)); } #endif /* DEBUG */ destpc = (DISP30(instructp) << 2) + PC_VAL(instructp); break; case FMT3_0x10: if (OP3(instructp) != JMPL) continue; #ifdef DEBUG if (debug & CALLSDEBUG) printf("[findcalls]\t0x%x:jmpl", PC_VAL(instructp)); #endif /* DEBUG */ if (RD(instructp) == R_G0) { #ifdef DEBUG if (debug & CALLSDEBUG) { switch (RS1(instructp)) { case R_O7: printf("\tprobably a RETL\n"); break; case R_I7: printf("\tprobably a RET\n"); break; default: printf(", but not a call: " "linked to g0\n"); } } #endif /* DEBUG */ continue; } #ifdef DEBUG if (debug & CALLSDEBUG) { printf("\toperands are DST = R%d,\tSRC = R%d", RD(instructp), RS1(instructp)); } #endif /* DEBUG */ if (IMMED(instructp)) { #ifdef DEBUG if (debug & CALLSDEBUG) { if (SIMM13(instructp) < 0) { printf(" - 0x%x\n", -(SIMM13(instructp))); } else { printf(" + 0x%x\n", SIMM13(instructp)); } } #endif /* DEBUG */ switch (RS1(instructp)) { case R_G0: /* * absolute address, simm 13 */ destpc = SIMM13(instructp); break; default: /* * indirect call */ addarc(parentp, &indirectchild, 0); continue; } } else { /* * two register sources, all cases are indirect */ #ifdef DEBUG if (debug & CALLSDEBUG) { printf(" + R%d\n", RS2(instructp)); } #endif /* DEBUG */ addarc(parentp, &indirectchild, 0); continue; } break; default: continue; } /* * Check that the destination is the address of * a function; this allows us to differentiate * real calls from someone trying to get the PC, * e.g. position independent switches. */ if (destpc >= s_lowpc && destpc <= s_highpc) { childp = nllookup(&modules, destpc, NULL); #ifdef DEBUG if (debug & CALLSDEBUG) { printf("[findcalls]\tdestpc 0x%llx", destpc); printf(" childp->name %s", childp->name); printf(" childp->value 0x%llx\n", childp->value); } #endif /* DEBUG */ if (childp->value == destpc) { /* * a hit */ addarc(parentp, childp, 0); continue; } } /* * else: * it looked like a call, * but it wasn't to anywhere. */ #ifdef DEBUG if (debug & CALLSDEBUG) { printf("[findcalls]\tbut it's a switch or a botch\n"); } #endif /* DEBUG */ continue; } }
EXPR *FindBasic( EXPR *def ) { unsigned int i ; EXPR *expr, *E1, *E2 ; if( IsReal(def) ) { expr = new UNIT ; U(expr)->Ehead = String( "Ordinate" ) ; ListAppend( expr, def->Copy() ) ; return expr ; } if( IsLabel( def ) ) { for( i = 0 ; i < U(UnitList)->used ; i++ ) { if( U(UN(i))->Ehead == def ) { expr = UN(i)->Copy() ; delete U(expr)->Eeval ; U(expr)->Eeval = NULL_EXPR ; return expr ; } } IOerror( IO_ERR, "FindBasic", "%s is an undefined unit", LabelValue(def) ) ; return garbageunit() ; } if( !IsOper(def) ) { IOerror( IO_FATAL, "FindBasic", "unexpected in units definition" ) ; return garbageunit() ; } if( D(def)->oper == OPER_MINUS ) { expr = FindBasic( D(def)->Eleft ) ; if( U(expr)->used > 1 ) { IOerror( IO_ERR, "FindBasic", "illegal negation of unit" ) ; return garbageunit() ; } E1 = OP3( "u-", U(expr)->list[0], NULL_EXPR ) ; delete U(expr)->list[0] ; U(expr)->list[0] = E1 ; return expr ; } E1 = FindBasic( D(def)->Eleft ) ; E2 = FindBasic( D(def)->Eright ) ; switch( D(def)->oper ) { case OPER_MULTIPLY: expr = UnitOP3( "*", "+", E1, E2 ) ; break ; case OPER_DIVIDE: expr = UnitOP3( "/", "-", E1, E2 ) ; break ; case OPER_POW: expr = UnitOP3( "^", "*", E1, E2 ) ; break ; default: IOerror( IO_ERR, "FindBasic", "unexpected operator in unit" ) ; expr = garbageunit() ; break ; } delete E1 ; delete E2 ; return expr ; }