4coder/code/4ed_mem.cpp

78 lines
1.8 KiB
C++
Raw Normal View History

/*
* Mr. 4th Dimention - Allen Webster
*
* 30.08.2016
*
* Replacements for common memory block managing functions.
*/
// TOP
// TODO(allen): Make these as fast as possible
2019-06-01 23:58:28 +00:00
#if 0
internal void
block_zero(void *a, u64 size){
2019-06-01 23:58:28 +00:00
for (u8 *ptr = (u8*)a, *e = ptr + size; ptr < e; ptr += 1){
*ptr = 0;
}
}
internal void
block_fill_ones(void *a, u64 size){
2019-06-01 23:58:28 +00:00
for (u8 *ptr = (u8*)a, *e = ptr + size; ptr < e; ptr += 1){
*ptr = 0xFF;
}
}
internal void
block_copy(void *dst, void *src, u64 size){
2019-06-01 23:58:28 +00:00
for (u8 *d = (u8*)dst, *s = (u8*)src, *e = s + size; s < e; d += 1, s += 1){
*d = *s;
}
}
2019-06-01 23:58:28 +00:00
internal i32
block_compare(void *a, void *b, u64 size){
2019-06-01 23:58:28 +00:00
for (u8 *aptr = (u8*)a, *bptr = (u8*)b, *e = bptr + size; bptr < e; aptr += 1, bptr += 1){
i32 dif = (i32)*aptr - (i32)*bptr;
if (dif != 0){
return(dif > 0?1:-1);
}
}
return(0);
}
internal void
block_fill_u8(void *a, u64 size, u8 val){
2019-06-01 23:58:28 +00:00
for (u8 *ptr = (u8*)a, *e = ptr + size; ptr < e; ptr += 1){
*ptr = val;
}
}
internal void
block_fill_u16(void *a, u64 size, u16 val){
2019-06-01 23:58:28 +00:00
Assert(size%sizeof(u16) == 0);
u64 count = size/sizeof(u16);
2019-06-01 23:58:28 +00:00
for (u16 *ptr = (u16*)a, *e = ptr + count; ptr < e; ptr += 1){
*ptr = val;
}
}
internal void
block_fill_u32(void *a, u64 size, u32 val){
2019-06-01 23:58:28 +00:00
Assert(size%sizeof(u32) == 0);
u64 count = size/sizeof(u32);
2019-06-01 23:58:28 +00:00
for (u32 *ptr = (u32*)a, *e = ptr + count; ptr < e; ptr += 1){
*ptr = val;
}
}
internal void
block_fill_u64(void *a, u64 size, u64 val){
2019-06-01 23:58:28 +00:00
Assert(size%sizeof(u64) == 0);
u64 count = size/sizeof(u64);
2019-06-01 23:58:28 +00:00
for (u64 *ptr = (u64*)a, *e = ptr + count; ptr < e; ptr += 1){
*ptr = val;
}
}
2019-06-01 23:58:28 +00:00
#define block_zero_struct(s) block_zero((s), sizeof(*(s)))
#endif
// BOTTOM