Example #1
1
/******************************************************************************
*                                                                             *
*   BYTE * _Init_Alloc( BYTE *pRamStart, DWORD dwRamSize )                    *
*                                                                             *
*******************************************************************************
*
*   This function initializes a buffer for the internal memory allocation pool.
*
*   Where:
*       pRamStart - beginning address of the linear buffer memory
*       dwRamTop  - size in bytes of the buffer memory
*
*   Returns:
*       Memory handle to be passed to subsequent mallocHeap() and freeHeap()
*               functions. That is the "heap".
*       This is actually the starting address pRamStart.
*
*       NULL - memory could not be initialized (invalid size/address)
*
******************************************************************************/
static BYTE * _Init_Alloc( BYTE *pRamStart, DWORD dwRamSize )
{
    Tmalloc *pMalloc;
    BYTE * pFree;

    // Some sanity checking

    if( dwRamSize < 32 )
        return( NULL );

    // Set the dummy free structure at the beginning of the free block to
    // easily traverse the linked list (a sentinel)

    pMalloc = TM(pRamStart);            // Get the buffer start
    pFree = (char*)pMalloc;             // Set the free list beginning

    pMalloc->size = 0;                  // No one can request that much!
    pMalloc->next = STM(pMalloc + 1);   // Next structure immediately follows

    pMalloc = TM(pMalloc->next);        // Next free block header
    pMalloc->size = dwRamSize - HEADER_SIZE; // That's how much is really free
    pMalloc->next = NULL;               // Last block in the list

    // Return the address of a heap that is now initialized

    return( pFree );
}
Example #2
0
test_report benchmark_test_with_external_configuration(std::string test_casename, const std::string function_name, int flag){
	std::cout << "test case: " << test_casename << " starts with external configuration" << std::endl;

	general_configuration ext_conf_file("configuration_"+function_name+".txt");

	Overall_Optimisation_Configuration_Settings myConf2(test_casename,
			ext_conf_file,
			"reference_point_"+function_name+".txt",
			"penalty_point_"+function_name+".txt",
			"lower_bound_"+function_name+".txt",
			"upper_bound_"+function_name+".txt",
			"starting_point_"+function_name+".txt",
			"current_step_"+function_name+".txt");

	const unsigned int n_of_variables=myConf2.getExternalConfigurationFile().getVar();
	const unsigned int n_of_objectives=myConf2.getExternalConfigurationFile().getObj();

	objective_function_formulae obj_function(n_of_objectives);

	ObjectiveFunctionBasic<double> TS_ObjFunc(myConf2, obj_function);

	Container2 MTM(n_of_variables, n_of_objectives, "MTM","./memories");
	Container2 IM(n_of_variables, n_of_objectives, "IM","./memories");
	Container2 HISTORY(n_of_variables, n_of_objectives, "HISTORY","./memories");

	STM_Container2 STM(myConf2.getExternalConfigurationFile().getStmSize(), n_of_variables, "STM", "./memories");
	LTM_Container2Basic2<double> LTM( n_of_variables ,  myConf2.getExternalConfigurationFile().getRegions(), myConf2.get_lower_bound(), myConf2.get_upper_bound(),"LTM", "./memories");
	std::cout << "Memories done!" << std::endl;

	TabuSearch TS(myConf2, flag, TS_ObjFunc, MTM, IM, HISTORY, STM, LTM);

	double hyper_volume_indicator=TS.search2();

	return test_report(myConf2.getCaseName(), TS.getDatumPnt(), hyper_volume_indicator) ;
}
void ARMAssembler::epilog(uint32_t touched)
{
    touched &= LSAVED;
    if (touched) {
        // write prolog code
        uint32_t* pc = mPC;
        mPC = mPrologPC;
        STM(AL, FD, SP, 1, touched | LLR);
        mPC = pc;
        // write epilog code
        LDM(AL, FD, SP, 1, touched | LLR);
        BX(AL, LR);
    } else {   // heh, no registers to save!
        // write prolog code
        uint32_t* pc = mPC;
        mPC = mPrologPC;
        MOV(AL, 0, R0, R0); // NOP
        mPC = pc;
        // write epilog code
        BX(AL, LR);
    }
}
void ARMAssembler::prolog()
{
    // write dummy prolog code
    mPrologPC = mPC;
    STM(AL, FD, SP, 1, LSAVED);
}
Example #5
0
test_report benchmark_test_with_internal_configuration(std::string test_casename, const std::string function_name, int flag, int nVar){
	std::ofstream report_file("tests_report_file.txt", std::ios::app);
	time_t start_time; time (&start_time);

	std::cout << "test case: " << test_casename << " starts with internal configuration" << std::endl;


	general_configuration internal_configuration_old("no_filename",
			10, //1 - diversify
			5, //2 - intensify
			15, //3 - reduce
			0.00, //4 - SS
			0.5, //5 - SSRF
			1, //6 - save step
			3, //7 - sampling
			nVar, //8 - nVar
			2, //9 - nObj
			0, //10 loop limit
			3000, //11 evaluations limit
			0, //12 Improvements limit , number of consecutive improvements
			4, //13 - number of regions
			6, //14 - STM size
			"HV", // 15
			"full", //16
			-0.05, //17 - starting point
			200, //18
			300); //19

	general_configuration internal_configuration("configuration.txt");

	ObjFunction2 test_reference_point=ObjFunction2(2, 22.0);
	ObjFunction2 test_penalty_point=ObjFunction2(2,33333.0);

	Point2 test_lower_bound=Point2(nVar,0.0);
	test_lower_bound[0]=5.0;
	test_lower_bound[1]=1.0;
	test_lower_bound[2]=11.0;

	Point2 test_upper_bound=Point2(nVar,1.0);
	test_upper_bound[0]=11.0;
	test_upper_bound[1]=200.0;
	test_upper_bound[2]=29.0;


	Point2 test_starting_point=Point2(nVar,0.5);
	test_starting_point[0]=7.0;
	test_starting_point[1]=100.0;
	test_starting_point[2]=24.5;

	Point2 test_current_step=Point2(nVar,0.05);
	test_current_step[0]=0.1666666;
	test_current_step[1]=0.050251256;
	test_current_step[2]=0.055555556;

	Overall_Optimisation_Configuration_Settings myConf2(test_casename,
			internal_configuration,
			test_reference_point,
			test_penalty_point,
			test_lower_bound,
			test_upper_bound,
			test_starting_point,
			test_current_step);

	const unsigned int n_of_variables=myConf2.getExternalConfigurationFile().getVar();
	const unsigned int n_of_objectives=myConf2.getExternalConfigurationFile().getObj();

	objective_function_formulae obj_function(n_of_objectives);

	ObjectiveFunctionBasic<double> TS_ObjFunc(myConf2, obj_function);

	Container2 MTM(n_of_variables, n_of_objectives, "MTM","./memories");
	Container2 IM(n_of_variables, n_of_objectives, "IM","./memories");
	Container2 HISTORY(n_of_variables, n_of_objectives, "HISTORY","./memories");

	STM_Container2 STM(myConf2.getExternalConfigurationFile().getStmSize(), n_of_variables, "STM", "./memories");
	LTM_Container2Basic2<double> LTM( n_of_variables ,  myConf2.getExternalConfigurationFile().getRegions(), myConf2.get_lower_bound(), myConf2.get_upper_bound(),"LTM", "./memories");
	std::cout << "Memories done!" << std::endl;

	TabuSearch TS(myConf2, flag, TS_ObjFunc, MTM, IM, HISTORY, STM, LTM);

	double hyper_volume_indicator=TS.search2();

	time_t end; time (&end);
	double dif = difftime (end,start_time);
	std::cout << "end in " << dif<< "seconds" << std::endl;
	report_file << test_casename << "\t" << n_of_variables << "\t" << dif << " seconds " << __DATE__ << "\t" << __TIME__  << std::endl;
	report_file.close();

	return test_report(myConf2.getCaseName(), TS.getDatumPnt(), hyper_volume_indicator) ;
}
Example #6
0
/******************************************************************************
*                                                                             *
*   void freeHeap(BYTE *pHeap, void *mPtr )                                   *
*                                                                             *
*******************************************************************************
*
*   Frees the memory that was allocated using mallocHeap() from the internal
*   memory allocation pool (heap).
*
*   The pointer mPtr can be NULL.
*
*   Where:
*       pHeap is the requested heap
*       pMem - pointer to a memory block to be freed
*
******************************************************************************/
void freeHeap(BYTE *pHeap, void *mPtr )
{
    Tmalloc *pLast;
    Tmalloc *pMem;
    Tmalloc *pMalloc;


    // Return if pointer is NULL (should not happen)

    if( mPtr==NULL )
        return;

    // Get the allocation structure

    pMalloc = (Tmalloc*)((int)mPtr - HEADER_SIZE);


    // Check for the magic number to ensure that the right block was passed

    if( (int)pMalloc->next != MALLOC_COOKIE )
    {
        // Should print some error message in the future
        //printf(" *** ERROR - Magic Number Wrong: %08X ***\n",(int)pMalloc->next );

        return;
    }

    // Now we have to return the block to the list of free blocks, so find the
    // place in the list to insert it.  The free list is ordered by the address
    // of the blocks that it holds

    pLast = TM(pHeap);
    pMem  = TM(pLast->next);

    // Traverse the free list and find where the new block should be inserted

    while( (pMem != NULL) && (pMem < pMalloc) )
    {
        pLast = pMem;
        pMem  = TM(pMem->next);
    }


    // If pMem is NULL, the block to be freed lies after the last node in the
    // free list, so link it at the end.

    if( pMem == NULL )
    {
        pLast->next = STM(pMalloc); // Last node in the free list
        pMalloc->next = NULL;       // Terminate it

        // The new, last free block may be merged with the preceeding one

        if( (int)pLast + pLast->size == (int)pMalloc )
        {
            pLast->size += pMalloc->size;
            pLast->next = NULL;
        }

        return;
    }


    // Now pLast points to the last node before pMalloc, and pMem points to
    // the next node.  They just have to be linked now.

    pLast->next = STM(pMalloc);
    pMalloc->next = STM(pMem);


    // If pMem node is immediately after pMalloc, they will be merged.

    if( (int)pMalloc + pMalloc->size == (int)pMem )
    {
        // Merge new node and the successor pointed by pMem

        pMalloc->size += pMem->size;
        pMalloc->next = pMem->next;
    }


    // If the newly freed node is after another free node, merge them

    if( (int)pLast + pLast->size == (int)pMalloc )
    {
        pLast->size += pMalloc->size;
        pLast->next = pMalloc->next;
    }

    return;
}
Example #7
0
/******************************************************************************
*                                                                             *
*   char *mallocHeap(BYTE *pHeap, UINT size)                                  *
*                                                                             *
*******************************************************************************
*
*   Allocates a block of memory within the Linice internal heap.
*
*   Where:
*       pHeap is the requested heap
*       size is the requested size of the memory block
*
*   Returns:
*       Pointer to newly allocated block
*       NULL - memory could not be allocated
*
******************************************************************************/
char *mallocHeap(BYTE *pHeap, UINT size)
{
    Tmalloc *pLast;
    Tmalloc *pNew;

    // This should really be some sort of assert...

    if( pHeap == NULL )
        return(NULL);

    // If the requested size is 0, do nothing.

    if( (size == 0) )
        return NULL;

    // Set the size to be a multiple of 4 to keep the allignemnt
    // Also, add the size of the header to be allocated

    size = ((size+3) & 0xFFFFFFFC) + HEADER_SIZE;

    // Debug allocations:
    //dprinth(1, "malloc(%d)", size);

    // Traverse the free list and find the first block large enough for the
    // block of the requested size

    pLast = TM(pHeap);
    pNew  = TM(pLast->next);

    // This effectively implements the first-fit memory allocation strategy

    while( (pNew != NULL) && (pNew->size < size ))
    {
        pLast = pNew;
        pNew  = TM(pNew->next);
    }


    // Check if we could not find the block large enough and are at the end of
    // the list

    if( pNew==NULL )
        return( NULL );

    // A free memory block that was found is large enough for the request, but
    // maybe too large, so we may want to split it:

    // Two things can happen now: either we will link another free block
    // at the end of the allocated one, or not.  Linking another block will
    // increase fragmentation so we will do it only if the space that remains
    // is larger or equal to 16 bytes (arbitrary value)

    if( pNew->size >= size+16+HEADER_SIZE )
    {
         // Link in another free block

         pLast->next = (struct Tmalloc*)((int)pNew + size);
         pLast = TM(pLast->next);               // Point to the new free block

         pLast->next = pNew->next;              // Link in the next free block
         pLast->size = pNew->size - size;

         pNew->size = size;                     // Set the allocated block size
         pNew->next = STM(MALLOC_COOKIE);       // And the debug cookie

         return (void*)((int)pNew + HEADER_SIZE);
    }
    else
    {
         // There was not enough free space to link in new free node, so just
         // allocate the whole block.

         pLast->next = pNew->next;              // Skip the newly found space

         // pNew->size is all the size of a block. No need to change.

         pNew->next = STM(MALLOC_COOKIE);       // Set the debug cookie

         return (void*)((int)pNew + HEADER_SIZE);
    }
}