elem_t array_search(const array_t* a, const elem_t key, compfunc_t cf) { size_t num_elems; elem_t elem0, center; int lo, hi, mid; assert(SMRZR_TRUE == a->is_array && 0 != a->elem_sz); elem0 = PTR_ADD(elem_t, a, sizeof(array_t)); num_elems = PTR_DIFF(a->curr, elem0) / a->elem_sz; lo = 0; hi = num_elems-1; while(lo <= hi) { mid = (lo + hi)/2; center = PTR_ADD(elem_t, elem0, mid * a->elem_sz); switch(cf(center, key)) { case SMRZR_EQ: return(center); case SMRZR_GT: hi = mid - 1; break; case SMRZR_LT: lo = mid + 1; break; default: assert(SMRZR_FALSE); } } return(NULL); }
func_error_t core_iobase_init ( unsigned sz, const char *name, const char *description, core_iobase_t **iobase) { DBG_ASSERT (iobase != NULL); // compute the additional size for texts unsigned sz_name = (name == NULL ? 0 : strlen (name)); unsigned sz_descr = (name == NULL ? 0 : strlen (description)); // compute full size and allocate unsigned full_size = sz + sz_name + 1 + sz_descr + 1; core_iobase_t * ret = (core_iobase_t*)malloc (full_size); if (ret == NULL) { return FUNC_MEMORY_ERROR; } // clear the structure memset (ret, 0, sz); ret->enabled = 1; // compute name/description and copy ret->name = PTR_ADD(ret, sz); ret->description = PTR_ADD(ret->name, sz_name+1); if (name != NULL) memcpy((char*)ret->name, name, sz_name); *(char*)PTR_ADD(ret->name, sz_name) = 0; if (description != NULL) memcpy((char*)ret->description, description, sz_descr); *(char*)PTR_ADD(ret->description, sz_descr) = 0; // and that's that *iobase = ret; return FUNC_OK; }
static void s390_elf_corehdr_create(char **elfcorebuf, size_t *elfcorebuf_sz) { Elf64_Phdr *phdr_notes, *phdr_loads; int mem_chunk_cnt; void *ptr, *hdr; u32 alloc_size; u64 hdr_off; mem_chunk_cnt = get_mem_chunk_cnt(); alloc_size = 0x1000 + get_cpu_cnt() * 0x300 + mem_chunk_cnt * sizeof(Elf64_Phdr); hdr = kzalloc_panic(alloc_size); /* */ ptr = ehdr_init(hdr, mem_chunk_cnt); /* */ phdr_notes = ptr; ptr = PTR_ADD(ptr, sizeof(Elf64_Phdr)); phdr_loads = ptr; ptr = PTR_ADD(ptr, sizeof(Elf64_Phdr) * mem_chunk_cnt); /* */ hdr_off = PTR_DIFF(ptr, hdr); ptr = notes_init(phdr_notes, ptr, ((unsigned long) hdr) + hdr_off); /* */ hdr_off = PTR_DIFF(ptr, hdr); loads_init(phdr_loads, ((unsigned long) hdr) + hdr_off); *elfcorebuf_sz = hdr_off; *elfcorebuf = (void *) relocate((unsigned long) hdr); BUG_ON(*elfcorebuf_sz > alloc_size); }
void replace_word(array_t** stack, string_t word, string_t rule) { string_t from; size_t word_len = strlen(word), to_len, offset; from = strsep(&rule, RULE_SEPARATOR_STR); assert(0 != *rule); /* something to replace must be there */ /*fprintf(stdout, "%s %s\n", word, from);*/ if(0 != strcasecmp(word, from)) return; to_len = strlen(rule); if(to_len > word_len) { /* need to extend 'word' memory */ if(ARR_FULL(*stack, to_len - word_len)) { /* re-alloc, adjust word */ offset = PTR_DIFF(word, *stack); assert(NULL != (*stack = array_new(SMRZR_FALSE, 0, 0, *stack))); word = PTR_ADD(string_t, *stack, offset); } } strcpy(word, rule); /* replace */ (*stack)->curr = PTR_ADD(elem_t, word, to_len + 1); /* adjust curr */ }
/* * grow(delta,FreeList). * Allocate one or more pages (at least delta bytes) and add chunk to FreeList. */ chunk *grow (int delta, chunk *l) // pre: delta > H_MINCHUNK // post: space is allocated, encapsulated by a chunk, added to freelist l // HWM is updated to reflect extent of new allocation { init(); delta = delta + 4*H_IS; //bring payload size up to chunk size from hmalloc delta = (delta + PAGE_SIZE-1)/PAGE_SIZE*PAGE_SIZE; chunk *c = sbrk(delta); //c now points to prev program break HWM = sbrk(0); //returns end of the allocated space; new program break *(info*)c = 0; //thing c points to (dereferenced info pointer) is 0 - initialize top segment boundary info* end = (info*)PTR_ADD(HWM, -H_IS); //subtract size of an info from HWM *end = 0; //initialize bottom segment boundary c = (chunk*)PTR_ADD(c, H_IS); //increment c to point at where the chunk will start int size = PTR_DIFF(end, c); ck_setInfo(c, size|H_FREE);//set free bit fl_insert(l, c); return c; }
/* * ck_footerAddr(c). * Generate a pointer to the footer info field at the end of chunk c. */ info *ck_footerAddr(chunk *c) // pre: c is a pointer to a valid chunk // post: returns a pointer to footer { int size = c->header & H_SIZEMASK; // clear non-size flags return (info*)PTR_ADD(c,size-H_IS); }
func_error_t aitown_dstorage_data_new ( aitown_dstorage_data_t **data_ptr, unsigned size) { func_error_t ret = FUNC_OK; aitown_dstorage_data_t *data = NULL; for (;;) { // allocate unsigned sz = aitown_dstorage_data_buffer_size (size); data = (aitown_dstorage_data_t *) malloc(sz+1); if (data == NULL) { ret = FUNC_MEMORY_ERROR; break; } // support null-terminated strings char * p_end = PTR_ADD(data, sz); *p_end = 0; // set size data->size = size; break; } *data_ptr = data; return ret; }
/* * hmalloc(size). * Allocate and return memory to hold size bytes. */ void *hmalloc(int size) { /* Look through free list to see if there's a chunk big enough to suit your needs (size). If no, grows by at least size. Returns the pointer to the beginning of the whole payload area, not the header; to preserve header info */ init(); if (size < H_MINPAYLOAD) { size = H_MINPAYLOAD; } chunk *found = fl_findBestFit(FreeList, size); if (found->header == 0) { //if dummy found = grow(size, FreeList); //we know if we got to this point nothing in freelist fit //chunk we allocate in grow is the one we want to grab } else { ck_split(found, size); } ck_setInfo(found, ck_size(found)); fl_remove(found); return (chunk*)PTR_ADD(found, H_IS); //return pointer to the payload }
elem_t array_search_or_alloc(array_t** array, const elem_t key, compfunc_t cf, bool_t* is_new) { size_t num_elems; elem_t elem0, center, elem; int lo, hi, mid; array_t * a = *array; assert(SMRZR_TRUE == a->is_array && 0 != a->elem_sz); elem0 = PTR_ADD(elem_t, a, sizeof(array_t)); num_elems = PTR_DIFF(a->curr, elem0) / a->elem_sz; if(!num_elems) { a->curr = PTR_ADD(elem_t, elem0, a->elem_sz); *is_new = SMRZR_TRUE; return(elem0); } lo = 0; hi = num_elems-1; while(lo <= hi) { mid = (lo + hi)/2; center = PTR_ADD(elem_t, elem0, mid * a->elem_sz); switch(cf(center, key)) { case SMRZR_EQ: *is_new = SMRZR_FALSE; return(center); case SMRZR_GT: hi = mid - 1; break; case SMRZR_LT: lo = mid + 1; break; default: assert(SMRZR_FALSE); } } /* insert just before lo */ if(SMRZR_TRUE == ARR_FULL(a, a->elem_sz)) { if(NULL == (*array = array_new(a->is_array, a->elem_sz, 2 * a->num_elems, a))) return(NULL); a = *array; elem0 = PTR_ADD(elem_t, a, sizeof(array_t)); } elem = PTR_ADD(elem_t, elem0, lo * a->elem_sz); memmove(PTR_ADD(elem_t, elem, a->elem_sz), elem, PTR_DIFF(a->curr, elem)); a->curr = PTR_ADD(elem_t, a->curr, a->elem_sz); *is_new = SMRZR_TRUE; return(elem); }
/* }}} */ static XC_SHM_TO_READONLY(xc_mmap_to_readonly) /* {{{ */ { assert(xc_mmap_is_readwrite(shm, p)); if (shm->diff) { p = PTR_ADD(p, shm->diff); assert(xc_mmap_is_readonly(shm, p)); } return p; }
static XC_SHM_MEMINIT(xc_mmap_meminit) /* {{{ */ { void *mem; if (shm->memoffset + size > shm->size) { zend_error(E_ERROR, "XCache: internal error at %s#%d", __FILE__, __LINE__); return NULL; } mem = PTR_ADD(shm->ptr, shm->memoffset); shm->memoffset += size; return mem; }
/* * hprint() * Print out the segment(s) between BASE and HWM. * All allocated and free chunks are described as encountered. */ void hprint(void) // post: prints the chunks in the heap between BASE and HWM { init(); void *p = BASE; while (p < HWM) { // loop across segments info i = *(info*)p; if (i == 0) { // i should be a dummy (0) info field printf("%p: base dummy\n",p); p = PTR_ADD(p,H_IS); while ((i = ck_size(p))) { // p is a non-dummy info printf("%p: ",p); ck_print(p); p = PTR_ADD(p,i); } printf("%p: top dummy\n",p); p = PTR_ADD(p,H_IS); } } }
// Creates a new Node and initializes the data fields Node *CreateNode( unsigned data_size ) { Node *newNode = (Node *)malloc( sizeof( Node ) + data_size ); newNode->next = NULL; newNode->prev = NULL; // Make data point to end of the allocated Node where the data's space is newNode->data = PTR_ADD( newNode, sizeof( Node ) ); return newNode; }
void array_remove(array_t* a, const elem_t key, compfunc_t cf) { elem_t elem, from; elem = array_search(a, key, cf); if(NULL == elem) return; from = PTR_ADD(elem_t, elem, a->elem_sz); assert(PTR_DIFF(a->curr, from) >= 0); if(from != a->curr) { memmove(elem, from, PTR_DIFF(a->curr, from)); } a->curr = PTR_ADD(elem_t, a->curr, -(a->elem_sz)); return; }
string_t get_word_stem(array_t** stack, lang_t* lang, const string_t word, bool_t is_core) { string_t changed, copy, *r; array_t* a; if(SMRZR_TRUE == is_core) { changed = word; } else { if(NULL == (changed = get_word_core(stack, lang, word))) return(NULL); } if(isupper(changed[0]) && strlen(changed) > 1) return(changed); copy = array_push_alloc(stack, strlen(changed)+1); strcpy(copy, changed); a = lang->manual; if(NULL!=(r=(string_t*)array_search(a, changed, comp_string_with_rule))){ replace_word(stack, changed, *r); } a = lang->pre; for(r = (string_t*)ARR_FIRST(a); !ARR_END(a); r = (string_t*)ARR_NEXT(a)) { if(SMRZR_TRUE == replace_word_head(changed, *r)) break; } a = lang->post; for(r = (string_t*)ARR_FIRST(a); !ARR_END(a); r = (string_t*)ARR_NEXT(a)) { if(SMRZR_TRUE == replace_word_tail(changed, *r)) break; } a = lang->synonyms; if(NULL!=(r=(string_t*)array_search(a, changed, comp_string_with_rule))){ replace_word(stack, changed, *r); } /* quality check */ if(strlen(changed) < 3) { memmove(changed, copy, strlen(copy)+1); (*stack)->curr = PTR_ADD(elem_t, changed, strlen(changed)+1); } else { array_pop_free(*stack, copy); } return(changed); }
/* * hrealloc(p,size) * Re-allocate memory pointed to by p to be at least size. * No guarantees about optimality. */ void *hrealloc(void *p, int size) { init(); chunk *c = (chunk*)PTR_ADD(p,-H_IS); if (ck_payloadSize(c) < size) { void *q = hmalloc(size); memcpy(q,p,size); hfree(p); return q; } else { return p; } }
void ADD_SUFF(Index12GrayToIntArgbConvert)(BLIT_PARAMS) { jint *pixLut = pSrcInfo->lutBase; mlib_s32 dstScan = pDstInfo->scanStride; mlib_s32 srcScan = pSrcInfo->scanStride; mlib_s32 i, i0, j; if (srcScan == width && dstScan == 4*width) { width *= height; height = 1; } for (j = 0; j < height; j++) { mlib_u16 *src = srcBase; mlib_s32 *dst = dstBase; i = i0 = 0; if ((mlib_s32)dst & 7) { dst[i] = pixLut[src[i]]; i0 = 1; } #pragma pipeloop(0) for (i = i0; i <= (mlib_s32)width - 2; i += 2) { *(mlib_d64*)(dst + i) = LOAD_2F32(pixLut, src[i], src[i + 1]); } for (; i < width; i++) { dst[i] = pixLut[src[i]]; } PTR_ADD(dstBase, dstScan); PTR_ADD(srcBase, srcScan); } }
/* * hfree(m). * Return/recycle heap-allocated memory, m. */ void hfree(void *m) //return a chunk or some memory to the free list. reset free bits to free { init(); chunk *theChunk = (chunk*)PTR_ADD(m, -H_IS); if (!(theChunk->header)&H_FREE) { //use bit mask of 0001; if 1, chunk is free ck_print(theChunk); //this is the chunk being freed int size = ck_size(theChunk); //size of the entire chunk; saved in header info ck_setInfo(theChunk, size|H_FREE); //reset the flag bits to free fl_insert(FreeList, theChunk); } else { printf("Cannot free a chunk that's already free\n"); } }
array_t* array_new(uint32_t is_array, size_t elem_sz, size_t num_elems, array_t* orig) { array_t* array; size_t curr_offset; size_t array_sz; assert(0 != elem_sz || SMRZR_FALSE == is_array); if(SMRZR_TRUE == is_array) { array_sz = elem_sz * num_elems + sizeof(array_t); array_sz = (1 + (array_sz / PAGESIZE)) * PAGESIZE; num_elems = (array_sz - sizeof(array_t)) / elem_sz; } else { if(NULL == orig) array_sz = ARRAY_DEFAULT_SZ; else array_sz = 2 * orig->array_sz; } if(NULL == orig) curr_offset = sizeof(array_t); else curr_offset = PTR_DIFF(orig->curr, orig); if(NULL == orig) { if(NULL == (array = (array_t*)malloc(array_sz))) { return(NULL); } } else { if(NULL == (array = (array_t*)realloc(orig, array_sz))) { return(NULL); } } array->is_array = is_array; array->elem_sz = ((SMRZR_TRUE == is_array) ? elem_sz : 0); array->num_elems = num_elems; array->array_sz = array_sz; array->curr = PTR_ADD(elem_t, array, curr_offset); return(array); }
elem_t array_push_alloc(array_t** array, size_t sz) { elem_t elem; array_t* a = *array; assert(SMRZR_FALSE == a->is_array); if(ARR_FULL(a, sz)) { if(NULL == (*array = array_new(SMRZR_FALSE, 0, 0, a))) return(NULL); a = *array; } elem = a->curr; a->curr = PTR_ADD(elem_t, a->curr, sz); return(elem); }
static void *nt_init(void *buf, Elf64_Word type, void *desc, int d_len, const char *name) { Elf64_Nhdr *note; u64 len; note = (Elf64_Nhdr *)buf; note->n_namesz = strlen(name) + 1; note->n_descsz = d_len; note->n_type = type; len = sizeof(Elf64_Nhdr); memcpy(buf + len, name, note->n_namesz); len = roundup(len + note->n_namesz, 4); memcpy(buf + len, desc, note->n_descsz); len = roundup(len + note->n_descsz, 4); return PTR_ADD(buf, len); }
elem_t array_alloc(array_t** array) { elem_t elem; array_t* a = *array; assert(SMRZR_TRUE == a->is_array); if(ARR_FULL(a, a->elem_sz)) { if(NULL == (*array = array_new(a->is_array, a->elem_sz, 2 * a->num_elems, a))) return(NULL); a = *array; } elem = a->curr; a->curr = PTR_ADD(elem_t, a->curr, a->elem_sz); return(elem); }
status_t array_add_elemptr(array_t** array, elem_t elem) { array_t* a = *array; assert(SMRZR_TRUE == a->is_array && sizeof(elem_t) == a->elem_sz); if(ARR_FULL(a, sizeof(elem_t))) { if(NULL == (*array = array_new(a->is_array, a->elem_sz, 2 * a->num_elems, a))) ERROR_RET; a = *array; } ptr_t ptr_val = (ptr_t)elem; *((ptr_t*)a->curr) = ptr_val; a->curr = PTR_ADD(elem_t, a->curr, a->elem_sz); return(SMRZR_OK); }
/* * ck_split(c,paySize) * Split a chunk, c, into two pieces: c and the return value, rest. */ chunk *ck_split(chunk *c, int paysize) // pre: c is a chunk (not marked free), paysize is the desired payload size // post: c is trimmed appropriately and the remainder is returned as another chunk // if chunk can't be split, 0 is returned. { printf("ck_split entered!\n"); //chunk can only be split if paysize big enough; this is an extra check even though hmalloc already takes care of this if (paysize >= H_MINPAYLOAD) { int CHUNK_SIZE = ck_size(c); //we'll need this later paysize = (paysize + H_PS-1)/H_PS*H_PS; //round paysize up to multiple of 8 info size_c = paysize + 2*H_IS; //reset c's payload size info size_d = CHUNK_SIZE - size_c; //make sure remainder would be a big enough chunk if (size_d < H_MINCHUNK) { return 0; } //trim c's payload by creating one chunk of size paysize + header and footer ck_setInfo(c, size_c); //find where c ends info *end_c = ck_footerAddr(c); chunk *d = (chunk*)PTR_ADD(end_c, H_IS); //new chunk d starts where c ended ck_setInfo(d, size_d|H_FREE); //insert it into the free list fl_insert(FreeList, d); return d; } else { //chunk can't be split; return 0 return 0; } }
int sniff_udp_fromwire(const byte *packet, size_t length) { const struct udphdr *header = (struct udphdr *)packet; uint16_t sport = ntohs(header->uh_sport); uint16_t dport = ntohs(header->uh_dport); LOG_PRINTF(UDP, "-- UDP (%lu bytes)\n", length); LOG_PRINTF_INDENT(UDP, 2, "\tsport: %u\n", sport); // source port LOG_PRINTF_INDENT(UDP, 2, "\tdport: %u\n", dport); // destination port LOG_PRINTF_INDENT(UDP, 2, "\tulen : %u\n", ntohs(header->uh_ulen)); // udp length LOG_PRINTF_INDENT(UDP, 2, "\tsum : %u\n", header->uh_sum); // udp checksum packet = (byte *)PTR_ADD(packet, UDP_HDR_LEN); length = ntohs(header->uh_ulen) - UDP_HDR_LEN; if (sport == 53 || dport == 53) { sniff_dns_fromwire(packet, length); } #if LOG_ENABLED(UDP_DATA) LOG_PRINTF(UDP_DATA, "showing %lu bytes:\n", length); dump_hex(stdout, packet, length, 0); #endif return 0; }
void ADD_SUFF(ByteIndexedToIntArgbScaleConvert)(SCALE_PARAMS) { jint *pixLut = pSrcInfo->lutBase; mlib_s32 dstScan = pDstInfo->scanStride; mlib_s32 srcScan = pSrcInfo->scanStride; mlib_s32 j; for (j = 0; j < height; j++) { mlib_u8 *src = srcBase; mlib_s32 *dst = dstBase; mlib_s32 *dst_end = dst + width; mlib_s32 tmpsxloc = sxloc; PTR_ADD(src, (syloc >> shift) * srcScan); if ((mlib_s32)dst & 7) { *dst++ = pixLut[src[tmpsxloc >> shift]]; tmpsxloc += sxinc; } #pragma pipeloop(0) for (; dst <= dst_end - 2; dst += 2) { *(mlib_d64*)dst = LOAD_2F32(pixLut, src[tmpsxloc >> shift], src[(tmpsxloc + sxinc) >> shift]); tmpsxloc += 2*sxinc; } for (; dst < dst_end; dst++) { *dst = pixLut[src[tmpsxloc >> shift]]; tmpsxloc += sxinc; } PTR_ADD(dstBase, dstScan); syloc += syinc; }
void ADD_SUFF(UshortGrayToByteGrayConvert)(BLIT_PARAMS) { mlib_s32 dstScan = pDstInfo->scanStride; mlib_s32 srcScan = pSrcInfo->scanStride; mlib_u8 *dst_end; mlib_d64 s0, s1, ss; mlib_s32 i, j; if (width <= 8) { for (j = 0; j < height; j++) { mlib_u8 *src = srcBase; mlib_u8 *dst = dstBase; for (i = 0; i < width; i++) { dst[i] = src[2*i]; } PTR_ADD(dstBase, dstScan); PTR_ADD(srcBase, srcScan); } return; } if (srcScan == 2*width && dstScan == width) { width *= height; height = 1; } for (j = 0; j < height; j++) { mlib_u8 *src = srcBase; mlib_u8 *dst = dstBase; mlib_d64 *sp; dst_end = dst + width; while (((mlib_s32)dst & 3) && dst < dst_end) { *dst++ = *src; src += 2; } if ((mlib_s32)src & 7) { sp = vis_alignaddr(src, 0); s1 = *sp++; #pragma pipeloop(0) for (; dst <= (dst_end - 4); dst += 4) { s0 = s1; s1 = *sp++; ss = vis_faligndata(s0, s1); ss = vis_fpmerge(vis_read_hi(ss), vis_read_lo(ss)); ss = vis_fpmerge(vis_read_hi(ss), vis_read_lo(ss)); *(mlib_f32*)dst = vis_read_hi(ss); src += 2*4; } } else { #pragma pipeloop(0) for (; dst <= (dst_end - 4); dst += 4) { ss = *(mlib_d64*)src; ss = vis_fpmerge(vis_read_hi(ss), vis_read_lo(ss)); ss = vis_fpmerge(vis_read_hi(ss), vis_read_lo(ss)); *(mlib_f32*)dst = vis_read_hi(ss); src += 2*4; } } while (dst < dst_end) { *dst++ = *src; src += 2; } PTR_ADD(dstBase, dstScan); PTR_ADD(srcBase, srcScan); } }
void ADD_SUFF(ByteGrayToIntArgbScaleConvert)(SCALE_PARAMS) { mlib_s32 dstScan = pDstInfo->scanStride; mlib_s32 srcScan = pSrcInfo->scanStride; mlib_d64 d0, d1, d2, d3, dd; mlib_f32 ff, aa = vis_fones(); mlib_s32 i, j, x; if (width < 16) { for (j = 0; j < height; j++) { mlib_u8 *src = srcBase; mlib_s32 *dst = dstBase; mlib_s32 tmpsxloc = sxloc; PTR_ADD(src, (syloc >> shift) * srcScan); for (i = 0; i < width; i++) { x = src[tmpsxloc >> shift]; tmpsxloc += sxinc; dst[i] = Gray2Argb(x); } PTR_ADD(dstBase, dstScan); syloc += syinc; } return; } vis_alignaddr(NULL, 7); for (j = 0; j < height; j++) { mlib_u8 *src = srcBase; mlib_s32 *dst = dstBase; mlib_s32 *dst_end; mlib_s32 tmpsxloc = sxloc; PTR_ADD(src, (syloc >> shift) * srcScan); dst_end = dst + width; #pragma pipeloop(0) for (; dst <= (dst_end - 4); dst += 4) { LOAD_NEXT_U8(dd, src + ((tmpsxloc + 3*sxinc) >> shift)); LOAD_NEXT_U8(dd, src + ((tmpsxloc + 2*sxinc) >> shift)); LOAD_NEXT_U8(dd, src + ((tmpsxloc + sxinc) >> shift)); LOAD_NEXT_U8(dd, src + ((tmpsxloc ) >> shift)); tmpsxloc += 4*sxinc; ff = vis_read_hi(dd); d0 = vis_fpmerge(aa, ff); d1 = vis_fpmerge(ff, ff); d2 = vis_fpmerge(vis_read_hi(d0), vis_read_hi(d1)); d3 = vis_fpmerge(vis_read_lo(d0), vis_read_lo(d1)); ((mlib_f32*)dst)[0] = vis_read_hi(d2); ((mlib_f32*)dst)[1] = vis_read_lo(d2); ((mlib_f32*)dst)[2] = vis_read_hi(d3); ((mlib_f32*)dst)[3] = vis_read_lo(d3); } while (dst < dst_end) { x = src[tmpsxloc >> shift]; tmpsxloc += sxinc; *dst++ = Gray2Argb(x); } PTR_ADD(dstBase, dstScan); syloc += syinc; } }
void ADD_SUFF(ByteGrayToIntArgbConvert)(BLIT_PARAMS) { mlib_s32 dstScan = pDstInfo->scanStride; mlib_s32 srcScan = pSrcInfo->scanStride; mlib_d64 d0, d1, d2, d3; mlib_f32 ff, aa = vis_fones(); mlib_s32 i, j, x; if (width < 8) { for (j = 0; j < height; j++) { mlib_u8 *src = srcBase; mlib_s32 *dst = dstBase; for (i = 0; i < width; i++) { x = src[i]; dst[i] = Gray2Argb(x); } PTR_ADD(dstBase, dstScan); PTR_ADD(srcBase, srcScan); } return; } if (srcScan == width && dstScan == 4*width) { width *= height; height = 1; } for (j = 0; j < height; j++) { mlib_u8 *src = srcBase; mlib_s32 *dst = dstBase; mlib_s32 *dst_end; dst_end = dst + width; while (((mlib_s32)src & 3) && dst < dst_end) { x = *src++; *dst++ = Gray2Argb(x); } #pragma pipeloop(0) for (; dst <= (dst_end - 4); dst += 4) { ff = *(mlib_f32*)src; d0 = vis_fpmerge(aa, ff); d1 = vis_fpmerge(ff, ff); d2 = vis_fpmerge(vis_read_hi(d0), vis_read_hi(d1)); d3 = vis_fpmerge(vis_read_lo(d0), vis_read_lo(d1)); ((mlib_f32*)dst)[0] = vis_read_hi(d2); ((mlib_f32*)dst)[1] = vis_read_lo(d2); ((mlib_f32*)dst)[2] = vis_read_hi(d3); ((mlib_f32*)dst)[3] = vis_read_lo(d3); src += 4; } while (dst < dst_end) { x = *src++; *dst++ = Gray2Argb(x); } PTR_ADD(dstBase, dstScan); PTR_ADD(srcBase, srcScan); } }
void ADD_SUFF(ThreeByteBgrToIntArgbConvert)(BLIT_PARAMS) { mlib_s32 dstScan = pDstInfo->scanStride; mlib_s32 srcScan = pSrcInfo->scanStride; mlib_d64 *sp; mlib_d64 s_0; mlib_d64 s0, s1, s2, s3, sd0, sd1, sd2, dd0, dd1, dd2, dd3; mlib_s32 i, i0, j; if (width < 16) { for (j = 0; j < height; j++) { mlib_u8 *src = srcBase; mlib_s32 *dst = dstBase; for (i = 0; i < width; i++) { dst[i] = GBR_PIXEL(i); } PTR_ADD(dstBase, dstScan); PTR_ADD(srcBase, srcScan); } return; } if (srcScan == 3*width && dstScan == 4*width) { width *= height; height = 1; } s_0 = vis_fone(); for (j = 0; j < height; j++) { mlib_u8 *src = srcBase; mlib_f32 *dst = dstBase; i = i0 = 0; if ((mlib_s32)dst & 7) { ((mlib_s32*)dst)[i] = GBR_PIXEL(i); i0 = 1; } sp = vis_alignaddr(src, 3*i0); s3 = *sp++; #pragma pipeloop(0) for (i = i0; i <= (mlib_s32)width - 8; i += 8) { s0 = s3; s1 = *sp++; s2 = *sp++; s3 = *sp++; sd0 = vis_faligndata(s0, s1); sd1 = vis_faligndata(s1, s2); sd2 = vis_faligndata(s2, s3); BGR_TO_ARGB *(mlib_d64*)(dst + i ) = dd0; *(mlib_d64*)(dst + i + 2) = dd1; *(mlib_d64*)(dst + i + 4) = dd2; *(mlib_d64*)(dst + i + 6) = dd3; } for (; i < width; i++) { ((mlib_s32*)dst)[i] = GBR_PIXEL(i); } PTR_ADD(dstBase, dstScan); PTR_ADD(srcBase, srcScan); } }