예제 #1
0
파일: Matrix.C 프로젝트: Roy-lab/mrtle
//Multiply this with b
Matrix* 
Matrix::multiplyMatrix(Matrix* b)
{
	if(col!=b->getRowCnt())
	{
		return NULL;
	}
	Matrix* res=new Matrix(row,b->getColCnt());
	gsl_matrix_set_zero (res->matrix);

	gsl_matrix_float* resmatrix=gsl_matrix_float_alloc(row,b->getColCnt());
	convertToFloat(resmatrix,res->matrix,row,b->getColCnt());

	gsl_matrix_float* cmatrix=gsl_matrix_float_alloc(row,col);
	convertToFloat(cmatrix,matrix,row,col);

	gsl_matrix_float* bmatrix=gsl_matrix_float_alloc(b->getRowCnt(),b->getColCnt());
	convertToFloat(bmatrix,b->matrix,b->getRowCnt(),b->getColCnt());
	
	gsl_blas_sgemm (CblasNoTrans, CblasNoTrans, 1, cmatrix, bmatrix, 0, resmatrix);
	convertFromFloat(resmatrix,res->matrix,row,b->getColCnt());
	gsl_matrix_float_free(resmatrix);
	gsl_matrix_float_free(cmatrix);
	gsl_matrix_float_free(bmatrix);
	return res;	
}
예제 #2
0
파일: Matrix.C 프로젝트: Roy-lab/mrtle
int 
Matrix::multiplyWithMatrix(Matrix* b)
{
	if(col!=b->getRowCnt())
	{
		return -1;
	}
	
	gsl_matrix* res=gsl_matrix_alloc(row,b->getColCnt());
	gsl_matrix_set_zero(res);
	
	gsl_matrix_float* resmatrix=gsl_matrix_float_alloc(row,b->getColCnt());
	convertToFloat(resmatrix,res,row,b->getColCnt());

	gsl_matrix_float* cmatrix=gsl_matrix_float_alloc(row,col);
	convertToFloat(cmatrix,matrix,row,col);

	gsl_matrix_float* bmatrix=gsl_matrix_float_alloc(b->getRowCnt(),b->getColCnt());
	convertToFloat(bmatrix,b->matrix,b->getRowCnt(),b->getColCnt());
	
	gsl_blas_sgemm(CblasNoTrans, CblasNoTrans, 1, cmatrix, bmatrix, 0, resmatrix);
	convertFromFloat(resmatrix,res,row,b->getColCnt());

	gsl_matrix_float_free(resmatrix);
	gsl_matrix_float_free(cmatrix);
	gsl_matrix_float_free(bmatrix);
	
	gsl_matrix_memcpy(matrix, res);
	gsl_matrix_free(res);
	return 0;
}
예제 #3
0
int main(int argc, char *argv[])
{
  char *instruction = *(argv + 2);
  char *input = *(argv + 1);

switch(*instruction)
    {
    case '1':
     convertToInt(input);
      break;
    case '2':
        convertToFloat(input);
      break;
    case '3':
        convertToUpperCase(input);
      break;
    case '4':
        revString(input);
      break;
    case '5':
        palindrome(input);
      break;
    default:
      printf("Error: \"%s\" was an invalid input.\n", argv[2]);
    }

  return 0;
}
예제 #4
0
double pushBackBuffer::readNumber (void)
{
  int i;
  char ch;

  i = readInt();
  if ((ch = getPB()) == '.') {
    return convertToFloat(i, readInt());
  }
  putPB(ch);
  return (double)i;
}
예제 #5
0
static void
updateHeight
(
byte_t * p,
float new_val,
PHY_ScalarType type
)
{
	float old_val = convertToFloat(p, type);
	if (!old_val) {
		convertFromFloat(p, new_val, type);
	}
}
예제 #6
0
float requestData(const byte cmd_buffer[], const byte write_pipe[]) {
  if( !radio_hw_available ) {
    debugPrint("Radio is NOT available");
    return -1.0;
  }
    
  debugPrint("Request data from Radio ... ");
  
  radio.openWritingPipe(write_pipe);       // Open different pipes when writing. Write on pipe 0, address 0
  radio.openReadingPipe(1,pipes[1]);       // Read on pipe 1, as address 1
  
  byte rec_buffer[8];
  
  /*
  if( !radio.testRPD() || !radio.isValid() ) {
    debugPrint("Radio is not available");
    return false;
  }
  */
  if( !sendRadioCommand(cmd_buffer) ) {
    debugPrint("Send Radio command failed");
    return false;
  }
  
  unsigned long started_waiting_at = millis();               // Set up a timeout period, get the current milliseconds
  boolean timeout = false;                                   // Set up a variable to indicate if a response was received or not    
  while ( ! radio.available() ){                             // While nothing is received
    if (millis() - started_waiting_at > 200 ) {              // If waited longer than 200ms, indicate timeout and exit while loop
      timeout = true;
      break;
    }      
  }
  
        
  if ( timeout ) {
    debugPrint("Failed, response timed out.\n\r");
  } else {
    radio.read( &rec_buffer, 8 );

    byte fbytes[4];
    for(int i=0,j=4;i<4;i++,j++)
      fbytes[i] = rec_buffer[j];
    
    return convertToFloat(fbytes);
  }
  
  
  return -99.99;
}
static void dumpGrid(const byte_t * grid,int bytesPerElement,PHY_ScalarType type,int max){
	//std::cerr << "Grid:\n";

	char buffer[32];

	for (int j = 0; j < max; ++j) {
		for (int i = 0; i < max; ++i) {
			long offset = j * s_gridSize + i;
			float z = convertToFloat(grid + offset * bytesPerElement, type);
			sprintf(buffer, "%6.2f", z);
			//std::cerr << "  " << buffer;
		}
		//std::cerr << "\n";
	}
}
static float getGridHeight(byte_t * grid, int i, int j, PHY_ScalarType type){
	btAssert(grid);
	btAssert(i >= 0 && i < s_gridSize);
	btAssert(j >= 0 && j < s_gridSize);

	int bpe = sizeof(float);
	btAssert(bpe > 0 && "bad bytes per element");

	int idx = (j * s_gridSize) + i;
	long offset = ((long) bpe) * idx;

	byte_t * p = grid + offset;

	return convertToFloat(p, type);
}
예제 #9
0
/*
 * Set the provided value in the datapoint identified by the provided id
 * Return true if successful or false otherwise
 */
boolean setDatapointValue(Datapoint datapoints[], int datapointId, byte buffer[]) {
  Datapoint dp = getDatapointById(datapoints, datapointId);
  
  if( &dp && dp.getId() >= 0) {
    /**
     * The setFunc must be set for the datapoint by using the "datapoints[0].setValueHandler(setHandler);"
     * setHandler is a function defined as: boolean setHandler(byte value[], int length) {
     *
     */
    float value = convertToFloat(buffer);    
    
    return dp.setData(value);
  }
  
  return false;
}
예제 #10
0
void
JackLayer::write(AudioBuffer &buffer, std::vector<float> &floatBuffer)
{
    for (unsigned i = 0; i < out_ringbuffers_.size(); ++i) {
        const unsigned inChannel = std::min(i, buffer.channels() - 1);
        convertToFloat(*buffer.getChannel(inChannel), floatBuffer);

        // write to output
        const size_t to_ringbuffer = jack_ringbuffer_write_space(out_ringbuffers_[i]);
        const size_t write_bytes = std::min(buffer.frames() * sizeof(floatBuffer[0]), to_ringbuffer);
        // FIXME: while we have samples to write AND while we have space to write them
        const size_t written_bytes = jack_ringbuffer_write(out_ringbuffers_[i],
                (const char *) floatBuffer.data(), write_bytes);
        if (written_bytes < write_bytes)
            RING_WARN("Dropped %zu bytes for channel %u", write_bytes - written_bytes, i);
    }
}
예제 #11
0
/*
 *  Raw file                                          DCT output
 *   -----                                              -----
 *  |     |  read+chop                         write   |     |
 *  |     |    ---->   DCT ---->  Quantization  ---->  |     |
 *  |     |                                            |     |
 *   -----                                              -----
 *  DCT output                                           IDCT result
 *   -----                                                  -----
 *  |     |  read+chop                             write   |     |
 *  |     |    ---->  Dequantization  ---->  IDCT   ---->  |     |
 *  |     |                                                |     |
 *   -----                                                  -----
 */
void test_release2(){
  CEXCEPTION_T error;
  Stream *inStream = NULL;
  Stream *outStream = NULL;
  float inputMatrix[8][8];
  int size = 8, count = 0;
  
  Try{
    inStream = openStream("test/Data/Water lilies.7z.010", "rb");
    outStream = openStream("test/Data/Water lilies_RE2.7z.010", "wb");
  }Catch(error){
    TEST_ASSERT_EQUAL(ERR_END_OF_FILE, error);
  }
  Try{
  while(1){
    readBlock(inStream, size, inputMatrix);
    //printf("%.3f", inputMatrix[0][0]);
    normalizeMatrix(size, inputMatrix);
    // dumpMatrix(size, inputMatrix);
    twoD_DCT(size, inputMatrix);
    // printf("%.3f", inputMatrix[0][0]);
    // dumpMatrix(size, inputMatrix);
    quantizationFunction50(size, inputMatrix);
    // dumpMatrix(size, inputMatrix);
    writeBlock11Bit(outStream, size, inputMatrix);
    
    if( feof(inStream->file) )
      { 
          break ;
      }
  }
  }Catch(error){
  TEST_ASSERT_EQUAL(ERR_END_OF_FILE, error);
  }
  closeStream(inStream);
  closeStream(outStream);
  // printf("\n");
  Stream *inStream2 = NULL;
  Stream *outStream2 = NULL;
  count = 0;
  short int inputMatrixIDCT[8][8];
  
  Try{
    inStream2 = openStream("test/Data/Water lilies_RE2.7z.010", "rb");
    outStream2 = openStream("test/Data/Water lilies_RE2Out.7z.010", "wb");
  }Catch(error){
    TEST_ASSERT_EQUAL(ERR_END_OF_FILE, error);
  }
  Try{
  while(1){
    readBlock11Bit(inStream2, size, inputMatrixIDCT);
    // dumpMatrixInt(size, inputMatrixIDCT);
    convertToFloat(inputMatrixIDCT, inputMatrix);
    dequantizationFunction50(size, inputMatrix);
    //dumpMatrix(size, inputMatrix);
    twoD_IDCT(size, inputMatrix);
    denormalizeMatrix(size, inputMatrix);
    // dumpMatrix(size, inputMatrix);
    
    writeBlock(outStream2, size, inputMatrix);
    
   if( feof(inStream2->file) )
      { 
          break ;
      }
  }
  }Catch(error){
  TEST_ASSERT_EQUAL(ERR_END_OF_FILE, error);
  }
  closeStream(inStream2);
  closeStream(outStream2);
}
예제 #12
0
void FinalMachineCodeGen::convert_IC_MC(InterCode *interCode, ostream &os) {
    string  dst_regName ;
    string  src1_regName;
    string  src2_regName;
    ExprNode **opndsList = (ExprNode **)interCode->get3Operands();
    switch(interCode->getOPNType()) {
        case CALL   :   {
                            string func_name = ((InvocationNode*)opndsList[0])->symTabEntry()->name();
                            string retAddrReg;

                            if (int_reg_used_cnt || fl_reg_used_cnt) {
                                retAddrReg = LabelClass::assignLabel()->getLabel();
                            } else {
                                retAddrReg = opndsList[0]->next()->getLabel();
                            }

                            push_registers(retAddrReg, os); 
                            os << "JMP  " << func_name << endl;

                            if ((int_reg_used_cnt-1) || fl_reg_used_cnt || opndsList[1]) {
                                os << retAddrReg << ": ";
                                pop_registers(os);

                                if (opndsList[1]) {
                                    ExprNode *src1    = opndsList[1];
                                    string retValueReg = src1->getRegisterName();
                                    if(IS_FLOAT(src1->type()))
                                        os<<"MOVF "<<RRV_F<<" ";
                                    else
                                        os<<"MOVI "<<RRV_I<<" ";
                                    os<<retValueReg<<endl;
                                    //int_reg_used_cnt--; 
                                }
                            }
                            reg_list.resize(0);

                            break;
                        }
        case FPARAM:    {
                            ExprNode *src1       = opndsList[0];
                            dst_regName = src1->getRegisterName();

                            os << "ADD "<<RSP<<" 4 "<<RSP << endl;
                            if (IS_FLOAT(src1->type()))
                                os << "LDF "<<RSP<<" "<<dst_regName;
                            else 
                                os << "LDI "<<RSP<<" "<<dst_regName;
                            os << C_FPARAM << endl;
                            break; 
                        } 
        case APARAM:    {
                            ExprNode *param       = opndsList[0];
                            Type     *ret_type = (param) ? (param->coercedType() ? (Type*)param ->coercedType() : param->type()): NULL ;
                            string    str;
                            string regName;
                            if(param)
                            {
                                if(param->exprNodeType() == ExprNode::ExprNodeType::VALUE_NODE)
                                {
                                    if(IS_FLOAT(ret_type))
                                     {
                                         regName = allocateNewRegName(true);
                                         str = "STF "+regName+" "+RSP;
                                         //fl_reg_used_cnt--;
                                     }
                                    else
                                        str = "STI "+param->getRefName()+" "+RSP;
                                }
                                else
                                {
                                    if(IS_FLOAT(ret_type))
                                       {
                                           string temp;
                                           regName = param->getRegisterName();
                                           if(regName.at(0) == 'R')
                                              {
                                                  temp =  convertToFloat(param, os);
                                                  str = "STF "+temp+" "+RSP;
                                              }
                                            else
                                                  str = "STF "+param->getRegisterName()+" "+RSP;
                                        }
                                    else
                                        str = "STI "+param->getRegisterName()+" "+RSP;

                                }
                                reg_list.push_back(str + C_APARAM);
                            }
                            break;
                        }
        case RETURN:    {
                            if (opndsList[0]) {
                                ExprNode *ret_val  = opndsList[0];
                                Type     *ret_type = (ret_val) ? (ret_val ->coercedType() ? (Type*)ret_val ->coercedType() : ret_val ->type()): NULL ;

                                if (IS_FLOAT(ret_type)) {
                                    dst_regName = ret_val->getRegisterName();
                                    os<<"MOVF "<<dst_regName<<" "<<RRV_F;
                                } else {
                                    dst_regName = ret_val->getRegisterName();
                                    os<<"MOVI "<<dst_regName<<" "<<RRV_I;
                                }
                                os<<endl;
                            }
                            os<<"ADD " << RSP << " 4 " << RSP << endl;
                            os<<"LDI " << RSP << " " << RRET_ADD << C_POP_RET << endl;
                            os << "JMPI " << RRET_ADD << endl;
                            break;
                        }
        case EXPR:      {
                            ExprNode *dst = opndsList[0];
                            Type   *type_dst  = dst ->coercedType() ? (Type*)dst ->coercedType() : dst ->type();
                            if (opndsList[0] && opndsList[1] && opndsList[2]) {
                                ExprNode *src1 = opndsList[1];
                                ExprNode *src2 = opndsList[2];

                                Type *type_src1 = src1->coercedType() ? (Type*)src1->coercedType() : src1->type();
                                Type *type_src2 = src2->coercedType() ? (Type*)src2->coercedType() : src2->type();
                                if (IS_FLOAT(type_dst)) {
                                    if (src1) {
                                        src1_regName = src1->getRegisterName();
                                        if (!IS_FLOAT(type_src1))
                                            src1_regName = convertToFloat(src1, os);
                                    }
                                    if (src2) {
                                        src2_regName = src2->getRegisterName();
                                        if(!IS_FLOAT(type_src2))
                                            src2_regName= convertToFloat(src2, os);
                                    }
                                    if (dst)
                                        dst_regName = dst->getRegisterName();

                                    switch(interCode->getsubCode()) {
                                        case OpNode::OpCode::PLUS  :   {   os<<"FADD ";    PRT_REG;    break; } 
                                        case OpNode::OpCode::MINUS :   {   os<<"FSUB ";    PRT_REG;    break; }
                                        case OpNode::OpCode::MULT  :   {   os<<"FMUL ";    PRT_REG;    break; }     
                                        case OpNode::OpCode::DIV   :   {   os<<"FDIV ";    PRT_REG;    break; }
                                        case OpNode::OpCode::GT    :   {   os<<"FGT " ;    PRT_REG;    break; }
                                        case OpNode::OpCode::GE    :   {   os<<"FGE " ;    PRT_REG;    break; }
                                        case OpNode::OpCode::LT    :   {   os<<"FLT " ;    PRT_REG;    break; }
                                        case OpNode::OpCode::LE    :   {   os<<"FLE " ;    PRT_REG;    break; }
                                        case OpNode::OpCode::EQ    :   {   os<<"FEQ " ;    PRT_REG;    break; }
                                        case OpNode::OpCode::NE    :   {   os<<"FEQ " ;    PRT_REG;    break; }
                                        default                    :                  break;    
                                    }
                                } else {
                                    if (src1) {
                                        src1_regName = src1->getRegisterName();
                                        if(IS_FLOAT(type_src1)) 
                                            src1_regName = convertToInt(src1, os);
                                    }
                                    if (src2) {
                                        src2_regName = src2->getRegisterName();
                                        if(IS_FLOAT(type_src2))
                                            src2_regName= convertToInt(src2, os);
                                    }
                                    if (dst)
                                        dst_regName = dst->getRegisterName();
                                    
                                    switch(interCode->getsubCode()) {
                                        case OpNode::OpCode::PLUS  :   {  os<<"ADD ";    PRT_REG;          break; }
                                        case OpNode::OpCode::MINUS :   {  os<<"SUB ";    PRT_REG;          break; }
                                        case OpNode::OpCode::MULT  :   {  os<<"MUL ";    PRT_REG;          break; }    
                                        case OpNode::OpCode::MOD   :   {  os<<"MOD ";    PRT_REG;          break; }    
                                        case OpNode::OpCode::DIV   :   {  os<<"DIV ";    PRT_REG;          break; }
                                        case OpNode::OpCode::BITAND:   {  os<<"AND ";    PRT_REG;          break; }
                                        case OpNode::OpCode::BITOR :   {  os<<"OR " ;    PRT_REG;          break; }
                                        case OpNode::OpCode::BITXOR:   {  os<<"XOR ";    PRT_REG;          break; }
                                        case OpNode::OpCode::GT    :   {  os<<"JMPC GT " <<src1_regName<<" "<<src2_regName<<" ";    relational( dst_regName, os);    break; }
                                        case OpNode::OpCode::GE    :   {  os<<"JMPC GE " <<src1_regName<<" "<<src2_regName<<" ";    relational( dst_regName, os);    break; }
                                        case OpNode::OpCode::LT    :   {  os<<"JMPC LT " <<src1_regName<<" "<<src2_regName<<" ";    relational( dst_regName, os);    break; }
                                        case OpNode::OpCode::LE    :   {  os<<"JMPC LE " <<src1_regName<<" "<<src2_regName<<" ";    relational( dst_regName, os);    break; }
                                        case OpNode::OpCode::EQ    :   {  os<<"JMPC EQ " <<src1_regName<<" "<<src2_regName<<" ";    relational( dst_regName, os);    break; }
                                        case OpNode::OpCode::NE    :   {  os<<"JMPC NE " <<src1_regName<<" "<<src2_regName<<" ";    relational( dst_regName, os);    break; }
                                        case OpNode::OpCode::SHL   :   {  ShiftLogic(true, src1_regName, src2_regName, dst_regName, os);    break; } 
                                        case OpNode::OpCode::SHR   :   {  ShiftLogic(false, src1_regName, src2_regName, dst_regName, os);           break; }
                                        case OpNode::OpCode::AND   :   {  ANDLogic  (src1_regName, src2_regName, dst_regName, os);    break; } 
                                        case OpNode::OpCode::OR    :   {  ORLogic   (src1_regName, src2_regName, dst_regName, os);           break; }
                                        default                    :                  break;    
                                    }
                                }
                            } else if(opndsList[0] && opndsList[1]) {
                                ExprNode *src1 = opndsList[1];
                                Type   *type_src1 = src1->coercedType() ? (Type*)src1->coercedType() : src1->type();
                                bool IsEndlNeeded = true;

                                src1_regName = src1->getRegisterName();
                                if(dst)
                                    dst_regName = dst->getRegisterName();

                                if (IS_FLOAT(type_dst)) {
                                    if (interCode->getsubCode() == OpNode::OpCode::ASSIGN) {
                                        if (!IS_FLOAT(type_src1))
                                            src1_regName = convertToFloat(src1, os);
                                        os<<"MOVF "<<src1_regName<<" "<<dst_regName;

                                    } else if (interCode->getsubCode() == OpNode::OpCode::UMINUS) {
                                        if (!IS_FLOAT(type_src1)) 
                                            src1_regName = convertToFloat(src1, os);
                                        os<<"FNEG "<<src1_regName<<" "<<dst_regName;
                                    }
                                } else {
                                    if (interCode->getsubCode() == OpNode::OpCode::ASSIGN) {
                                        if (IS_STRING(type_src1)) {
                                            os<<"MOVS "<<src1_regName<<" "<<dst_regName;
                                        } else {
                                            if (IS_FLOAT(type_src1)) 
                                                src1_regName = convertToInt(src1, os);
                                            os<<"MOVI "<<src1_regName<<" "<<dst_regName;
                                        }
                                    } else if (interCode->getsubCode() == OpNode::OpCode::UMINUS) {
                                        if (IS_FLOAT(type_src1)) 
                                            src1_regName = convertToInt(src1, os);
                                        os<<"NEG "<<src1_regName<<" "<<dst_regName;
                                    } else if (interCode->getsubCode() ==  OpNode::OpCode::NOT) {
                                        NOTLogic(src1_regName, dst_regName, os);
                                        IsEndlNeeded = false;
                                    } else if (interCode->getsubCode() ==  OpNode::OpCode::BITNOT) {
                                        os << "BNOT " << src1_regName << " " << dst_regName;
                                    }

                                }
                                if (IsEndlNeeded) os<<endl;
                            }
                            break;
                        }
          case LABEL  : {
                            os<<interCode->getLabel()<<endl;
                            break; 
                        }
          case GOTO   : { 
                            InterCode* goto_lab = (InterCode*) opndsList[0];

                            os<<"JMP "<<goto_lab->getLabel() <<endl;
                            break; 
                        }
          case IFREL  : { 
                            ExprNode* cond        = (ExprNode*) opndsList[0];
                            InterCode* true_lab   = cond->OnTrue();
                            InterCode* false_lab  = cond->OnFalse();
                            ExprNode* expr1       = (ExprNode*) opndsList[1];
                            ExprNode* expr2       = (ExprNode*) opndsList[2];
                            bool if_cond_int      = false;

                            Type   *type_src1 = (expr1) ?  (expr1->coercedType() ? (Type*)expr1->coercedType() : expr1->type()): NULL ;
                            Type   *type_src2 = (expr2) ?  (expr2->coercedType() ? (Type*)expr2->coercedType() : expr2->type()): NULL ;

                            if (opndsList[2] && opndsList[1]) 
                            {

                                src1_regName = expr1->getRegisterName();
                                src2_regName = expr2->getRegisterName();

                                if(!IS_FLOAT(type_src1) && !IS_FLOAT(type_src2))
                                    if_cond_int  = true;
                                else
                                {
                                    if(!IS_FLOAT(type_src1)) 
                                        src1_regName = convertToFloat(expr1, os);
                                    if(!IS_FLOAT(type_src2))
                                        src2_regName= convertToFloat(expr2, os);
                                    if_cond_int = false;
                                }

                                os<<"JMPC ";
                                switch(interCode->getsubCode())
                                {
                                    case OpNode::OpCode::EQ   : (if_cond_int) ? os<<"EQ " : os<<"FEQ "; break; 
                                    case OpNode::OpCode::NE   : (if_cond_int) ? os<<"NE " : os<<"FNE "; break;
                                    case OpNode::OpCode::GT   : (if_cond_int) ? os<<"GT " : os<<"FGT "; break; 
                                    case OpNode::OpCode::GE   : (if_cond_int) ? os<<"GE " : os<<"FGE "; break;
                                    case OpNode::OpCode::LT   : (if_cond_int) ? os<<"LT " : os<<"FLT "; break; 
                                    case OpNode::OpCode::LE   : (if_cond_int) ? os<<"LE " : os<<"FLE "; break;
                                    default                   :  break ;    
                                }
                                os<<src1_regName<<" "<<src2_regName<<" "<<(true_lab->getLabel())<<endl;
                                if(false_lab)
                                    os<<"JMP "<<(false_lab->getLabel())<<endl;
                            }
                            else if(opndsList[1])
                            {
                                if(cond->exprNodeType() == ExprNode::ExprNodeType::VALUE_NODE)
                                        src1_regName = expr1->getRefName(); 
                                else
                                        src1_regName = expr1->getRegisterName();
                                
                                if(Type::isBool(type_src1->tag()))
                                {
                                    if(interCode->getsubCode() == OpNode::OpCode::NOT)
                                        os<<"JMPC EQ ";
                                    os<<src1_regName<<" 0 "<<(true_lab->getLabel())<<endl;
                                    if(false_lab)
                                        os<<"JMP "<<(false_lab->getLabel())<<endl;
                                }
                            }
                            else
                            {
                                if(cond->exprNodeType() == ExprNode::ExprNodeType::VALUE_NODE)
                                        src1_regName = cond->getRefName(); 
                                else
                                        src1_regName = cond->getRegisterName();
                                os<<"JMPC NE ";
                                os<<src1_regName<<" 0 "<<(true_lab->getLabel())<<endl;
                                if(false_lab)
                                    os<<"JMP "<<(false_lab->getLabel())<<endl;
                            }
                            break;
                        }
         case ENTER  :  { 
                            IsLastBlockEmpty = true;
                            fl_reg_used_cnt  = 0 ;
                            int_reg_used_cnt = 0 ;
                            break;
                        }
         case LEAVE  :  { 
                            os<<"ADD "<<RSP<<" 4 "<<RSP << endl;
                            os<<"LDI "<<RSP <<" "<<RRET_ADD << C_POP_RET << endl;
                            os << "JMPI " << RRET_ADD << endl;
                            break;
                        }
         case PRINT  :  {
                            ExprNode *param        = opndsList[0];
                            Type   *type_dst     = (param ) ?  (param ->coercedType() ? (Type*)param ->coercedType() : param ->type()): NULL ;

                            if (IS_FLOAT(type_dst))         os<<"PRTF ";
                            else if (IS_STRING(type_dst))   os<<"PRTS ";
                            else                            os<<"PRTI ";

                            if (param->exprNodeType() == ExprNode::ExprNodeType::VALUE_NODE)
                                os << opndsList[0]->getRefName();
                            else 
                                os << opndsList[0]->getRegisterName();
                            os << endl;
                            break;
                        }
                     
         default:       {
                            assert(0 && "Invalid 3 address Opcode");
                        }
    }
}
예제 #13
0
// creates a random, fractal heightfield
static void
setFractal
(
byte_t * grid,
int bytesPerElement,
PHY_ScalarType type,
int step
)
{
	btAssert(grid);
	btAssert(bytesPerElement > 0);
	btAssert(step > 0);
	btAssert(step < s_gridSize);

	int newStep = step / 2;
//	std::cerr << "Computing grid with step = " << step << ": before\n";
//	dumpGrid(grid, bytesPerElement, type, step + 1);

	// special case: starting (must set four corners)
	if (s_gridSize - 1 == step) {
		// pick a non-zero (possibly negative) base elevation for testing
		float base = randomHeight(step / 2);

		convertFromFloat(grid, base, type);
		convertFromFloat(grid + step * bytesPerElement, base, type);
		convertFromFloat(grid + step * s_gridSize * bytesPerElement, base, type);
		convertFromFloat(grid + (step * s_gridSize + step) * bytesPerElement, base, type);
	}

	// determine elevation of each corner
	float c00 = convertToFloat(grid, type);
	float c01 = convertToFloat(grid + step * bytesPerElement, type);
	float c10 = convertToFloat(grid + (step * s_gridSize) * bytesPerElement, type);
	float c11 = convertToFloat(grid + (step * s_gridSize + step) * bytesPerElement, type);

	// set top middle
	updateHeight(grid + newStep * bytesPerElement, 0.5 * (c00 + c01) + randomHeight(step), type);

	// set left middle
	updateHeight(grid + (newStep * s_gridSize) * bytesPerElement, 0.5 * (c00 + c10) + randomHeight(step), type);

	// set right middle
	updateHeight(grid + (newStep * s_gridSize + step) * bytesPerElement, 0.5 * (c01 + c11) + randomHeight(step), type);

	// set bottom middle
	updateHeight(grid + (step * s_gridSize + newStep) * bytesPerElement, 0.5 * (c10 + c11) + randomHeight(step), type);

	// set middle
	updateHeight(grid + (newStep * s_gridSize + newStep) * bytesPerElement, 0.25 * (c00 + c01 + c10 + c11) + randomHeight(step), type);

//	std::cerr << "Computing grid with step = " << step << ": after\n";
//	dumpGrid(grid, bytesPerElement, type, step + 1);

	// terminate?
	if (newStep < 2) {
		return;
	}

	// recurse
	setFractal(grid, bytesPerElement, type, newStep);
	setFractal(grid + newStep * bytesPerElement, bytesPerElement, type, newStep);
	setFractal(grid + (newStep * s_gridSize) * bytesPerElement, bytesPerElement, type, newStep);
	setFractal(grid + ((newStep * s_gridSize) + newStep) * bytesPerElement, bytesPerElement, type, newStep);
}
예제 #14
0
bool pyrDownImage(MImage * image)
{
	if(! isImageValid(image))
		return false;
	
	M_TYPES type = image->getDataType();
	
	if(type == M_FLOAT)
	{
		int width = (int)image->getWidth();
		int height = (int)image->getHeight();
		int halfWidth = (width+1)/2;
		int halfHeight = (height+1)/2;
		unsigned int components = image->getComponents();
	
		MImage copy(*image);
		image->create(type, halfWidth, halfHeight, components);
		
		float * copyData = (float *)copy.getData();
		float * destData = (float *)image->getData();
		
		#pragma omp parallel for schedule(dynamic, 8)
		for(int y=0; y<halfHeight; y++)
		{
			float * color;
			float * pixel = destData + halfWidth*y*components;
		
			int i;
			int y2 = y*2;
			int y2p = MIN(y2+1, height-1);
			
			for(int x=0; x<halfWidth; x++)
			{
				int x2 = x*2;
				int x2p = MIN(x2+1, width-1);
			
				color = copyData + (y2*width + x2)*components;
				for(i=0; i<components; i++)
					pixel[i] = color[i];
				
				color = copyData + (y2p*width + x2)*components;
				for(i=0; i<components; i++)
					pixel[i] += color[i];
				
				color = copyData + (y2*width + x2p)*components;
				for(i=0; i<components; i++)
					pixel[i] += color[i];
				
				color = copyData + (y2p*width + x2p)*components;
				for(i=0; i<components; i++)
					pixel[i] += color[i];
				
				for(i=0; i<components; i++)
					pixel[i] *= 0.25f;
				
				pixel+=components;
			}
		}
	
		return true;
	}
	else if(type == M_UBYTE)
	{
		convertToFloat(image);
		pyrDownImage(image);
		convertToUbyte(image);
		return true;
	}
	
	return false;
}
예제 #15
0
bool resizeImage(MImage * image, unsigned int destWidth, unsigned int destHeight, float filter)
{
	if(! isImageValid(image))
		return false;
		
	M_TYPES type = image->getDataType();
	
	if(type == M_FLOAT)
	{
		MImage copy(*image);
		
		unsigned int components = image->getComponents();
		unsigned int srcWidth = image->getWidth();
		unsigned int srcHeight = image->getHeight();

		float xFilter = filter;
		float yFilter = filter;
		
		MVector2 scale(srcWidth/(float)destWidth, srcHeight/(float)destHeight);

		image->create(type, destWidth, destHeight, components);
		float * destData = (float *)image->getData();
		
		if(filter > 0)
		{
			#pragma omp parallel for schedule(dynamic, 8)
			for(unsigned int y=0; y<destHeight; y++)
			{
				float color[4];
				float totalColor[4];
				float * pixel = destData + destWidth*y*components;
			
				for(unsigned int x=0; x<destWidth; x++)
				{
					unsigned int i;
					MVector2 srcPos, destPos = MVector2((float)x, (float)y);
				
					float score = 0;
					memset(totalColor, 0, components*sizeof(float));
		
					float dx, dy;
					for(dy=-yFilter; dy<=yFilter; dy+=yFilter)
					for(dx=-xFilter; dx<=xFilter; dx+=xFilter)
					{
						srcPos = (destPos + MVector2(dx, dy))*scale;
						getImageSubPixel_float(&copy, srcPos.x-0.5f, srcPos.y-0.5f, color);
						for(i=0; i<components; i++)
							totalColor[i] += color[i];
						score++;
					}
					
					for(i=0; i<components; i++)
						pixel[i] = (totalColor[i] / score);
			
					pixel += components;
				}
			}
		}
		else if(filter == 0)
		{
			#pragma omp parallel for schedule(dynamic, 8)
			for(unsigned int y=0; y<destHeight; y++)
			{
				float * pixel = destData + destWidth*y*components;
				for(unsigned int x=0; x<destWidth; x++)
				{
					MVector2 srcPos = MVector2((float)x, (float)y)*scale;
					getImageSubPixel_float(&copy, srcPos.x-0.5f, srcPos.y-0.5f, pixel);
					pixel += components;
				}
			}
		}
		else
		{
			for(unsigned int y=0; y<destHeight; y++)
			{
				float * pixel = destData + destWidth*y*components;
				for(unsigned int x=0; x<destWidth; x++)
				{
					MVector2 srcPos = MVector2((float)x, (float)y)*scale;
					copy.readPixel(srcPos.x, srcPos.y, pixel);
					pixel += components;
				}
			}
		}
	}
	else if(type == M_UBYTE)
	{
		convertToFloat(image);
		resizeImage(image, destWidth, destHeight, filter);
		convertToUbyte(image);
		return true;
	}
	
	return true;
}
예제 #16
0
파일: tdata.c 프로젝트: amic3r/Terra
float TDataToFloat(const TData *context)
{
	if (context) return convertToFloat(context->data, context->type);
	return 0;
}