예제 #1
0
bool put_word(Segment s, uint32_t ID, uint32_t address, uint32_t word)
{
	TRY
	        assert(s);
	        UArray_T inner = Seq_get(s, ID);
	        
	        assert(inner);

		if (ID >= (unsigned) Seq_length(s)) {
			/* ID does not exist */
			return false;
		}

		if (address >= (unsigned) UArray_length(inner)) {
			/* offset does not exist */
			return false;
		}

	        assert(inner);

	        uint32_t *wordptr = UArray_at(inner, address);

	        *wordptr = word;

	EXCEPT(Mem_Failed)
		return false;
	END_TRY;

        return true;

}
예제 #2
0
/* this function takes in the UArray_T of the pixels, and outputs the 
   Y, Pb, Pr representation
*/
CVC *rgb_pixels_to_CVC(UArray_T block, int denominator)
{

        int num_pixels = UArray_length(block);
        float avg_Pb = 0.0;
        float avg_Pr = 0.0;

        Pnm_rgb cur_pix;
        Pnm_rgb_float cur_pix_float;

        CVC *YPbPr = malloc(sizeof(struct CVC));
        assert(YPbPr);

        YPbPr->Y = malloc(sizeof(Lum_vals) * num_pixels);
        assert(YPbPr->Y);

        YPbPr->num_vals = num_pixels;

        for (int i = 0; i < num_pixels; i++) {

                cur_pix = (Pnm_rgb)UArray_at(block, i);
                cur_pix_float = normalize_pixel(cur_pix, denominator);

                YPbPr->Y[i] = get_Y(cur_pix_float);

                avg_Pb += get_Pb(cur_pix_float);
                avg_Pr += get_Pr(cur_pix_float);
                free(cur_pix_float);
        }

        YPbPr->avg_Pb = avg_Pb / (float)num_pixels;
        YPbPr->avg_Pr = avg_Pr / (float)num_pixels;

        return YPbPr;
}
예제 #3
0
static void copy_segment_to_m0(UM_machine machine, UM_segment_ID segment_ID)
{
        Seq_T mapped_segments = machine->address_space->mapped_segments;
        UM_segment temp = Seq_get(mapped_segments, segment_ID);
        int temp_length = UArray_length(temp->words);

        UM_segment duplicate = get_new_segment_of_size(temp_length);

        /* copy words into the new segment */
        for(int i=0; i<temp_length; i++){
                UM_word *word_i_p = UArray_at(temp->words, i);
                UM_word *duplicate_word_i_p = UArray_at(duplicate->words, i);
                *duplicate_word_i_p = *word_i_p;
        }

        duplicate->ID = 0;

        /* free the old program segment */
        UM_segment program = Seq_get(mapped_segments, 0);
        free_segment_memory(&program);

        /* put the duplicate segment in the place of the old program segment */
        Seq_put(mapped_segments, 0, duplicate);

        /* update num_instructions */
        machine->num_instructions = temp_length;
}
예제 #4
0
파일: unitTests.c 프로젝트: rlew/um
void verifyMapped(Seq_T memorySegments, Seq_T unmappedSegments) {
    assert(Seq_length(memorySegments) == Seq_length(unmappedSegments));
    for(int i = 0; i < Seq_length(memorySegments); i++){
        if(Seq_get(memorySegments, i) == Seq_get(unmappedSegments, i)){
            fprintf(stderr, "Cannot be both mapped and unmapped: %d\n", i);
         /*   if(Seq_get(unmappedSegments, i) == NULL) {
                fprintf(stderr, "Both NULL\n");
            }*/
            exit(1);
        }
        if(Seq_get(memorySegments, i) != NULL) {
            if(Seq_get(unmappedSegments, i) != NULL){
                fprintf(stderr, "Failed to unmap index: %d\n", i);
                exit(1);
            }
            UArray_T temp = Seq_get(memorySegments, i);
            for(UM_Word j = 0; j < (UM_Word)UArray_length(temp); j++) {
                UM_Word value = *(UM_Word*)UArray_at(temp, j); 
                if(value != 0){
                    printf("Segmented load at %d with value of %u\n", i, value);
                }
            }
        }
    }
    printf("Verified\n");
}
예제 #5
0
/*
 * Copies and inserts the segment at the given ID into the Segment_Table
 * Parameters: sm - Segment manager struct
 * 	       id - ID of segment to copy
 * Return value: The id of the newly inserted segment
 */
unsigned copy_Segment(Segment_Manager sm, unsigned id)
{
	Segment original = Seq_get(sm->Segment_Table, id);
	unsigned length = UArray_length(original);
	Segment copy = UArray_copy(original, length);
	return insert_Segment(sm, copy);
}
예제 #6
0
파일: unitTests.c 프로젝트: jsanch/umasm
void verifyMapped(Seq_T memorySegments, Seq_T unmappedSegments) {
    // Verifies that the available unmapped segments is updated upon mapping
    for(int i = 0; i < Seq_length(unmappedSegments); i++){
        UM_Word index = *(UM_Word*)Seq_get(unmappedSegments, i);
        if((UArray_T)Seq_get(memorySegments, index) != NULL){
            fprintf(stderr, 
                    "Unmapped segments not updated correctly for: %u\n", 
                    index);
            exit(1);
        }
    }

    for(int i = 0; i < MEM_SEG_LEN; i++) {
        UArray_T segments = (UArray_T)Seq_get(memorySegments, i);
        if (segments != NULL) {
            for(int j = 0; j < UArray_length(segments); j++) {
                // Each 32-bit word must be initialized to 0
                printf("memseg: %u\n", *(UM_Word*)UArray_at(segments, j));
                if(*(UM_Word*)UArray_at(segments, j) != 0) {
                    fprintf(stderr, "segment incorrectly initialized\n");
                    exit(1);
                }
            }
        }
    }
    printf("Verified bitch.\n");
}
예제 #7
0
파일: IoMP3Encoder.c 프로젝트: Akiyah/io
IoObject *IoMP3Encoder_encode(IoMP3Encoder *self, IoObject *locals, IoMessage *m)
{
    UArray *inBa = IoBuffer_rawUArray(IoMessage_locals_bufferArgAt_(m, locals, 0));
    /*UArray *outBa = IoBuffer_rawUArray(DATA(self)->outBuffer);*/
    
    int start = 0;
    int end = UArray_length(inBa);
    
    if (IoMessage_argCount(m) > 1) start = IoMessage_locals_intArgAt_(m, locals, 1);
    if (IoMessage_argCount(m) > 2) end = IoMessage_locals_intArgAt_(m, locals, 2);
    if (start > end)
    { IoState_error_description_(IOSTATE, m, "MP3Encoder", "range error: start > end"); }
    if (end > UArray_length(inBa))
    { IoState_error_description_(IOSTATE, m, "MP3Encoder", "range error: end > length of input buffer"); }
    
    MP3Encoder_encode(DATA(self)->encoder, UArray_bytes(inBa) + start, end);
    
    return IoMP3Encoder_checkError(self, locals, m);
}
예제 #8
0
/*-----------------------------------------------------------------------------*
| UArray2_map_col_major
|       Purpose:   maps the given function onto every element of the given 
|                  UArray2 in col major order
|       Arguments: a pointer to the 2D array, a pointer to a void apply 
|                  function, the closure as a void *
|       Returns:   -
|       Fail cases:
|               - the pointer to the 2D array is null
|               - the pointer to the apply function is null
*-----------------------------------------------------------------------------*/
void UArray2_map_col_major(UArray2_T uarray2, void apply(int i, int j, 
                           UArray2_T uarray2, void *value, void *cl), 
                           void *cl) {
        assert(uarray2 != NULL);
        assert(apply != NULL);
        int index;
        int i;
        int j;
        for (index = 0; index < UArray_length(uarray2->uarray); index ++) {
                i = get_i(index, UArray2_height(uarray2));
                j = get_j(index, UArray2_height(uarray2));
                apply(i, j, uarray2, UArray2_at(uarray2, i, j), cl);
        };
}
예제 #9
0
void check_map_large(){

//These variable created for compiling sake
	Seq_T SEG_MEMORY = Seq_new(100);
	Seq_T UNMAP_SEQ = Seq_new(10);

	Umsegment_Id one = map_segment(6);
	Umsegment_Id two = map_segment(6);
	Umsegment_Id three = map_segment(8000);
	Umsegment_Id four = map_segment(6);
	int size = UArray_length(Seq_get(SEG_MEMORY, three));
	if (size != 8000)
		fprintf(stderr, "Big segment is incorrect size %d.\n", size);
	unmap_segment(one);
	unmap_segment(two);
	unmap_segment(three);
	unmap_segment(four);

	Seq_free(&SEG_MEMORY);
	Seq_free(&UNMAP_SEQ);
}
예제 #10
0
/* returns how many words are stored in the segment ID */
int get_words_in_seg(Segment s, uint32_t ID)
{
	assert(s);

	return UArray_length(Seq_get(s,ID));	
}