> On 08 Jun 2015, at 4:41 , Matthieu Lacaton <matthieu.laca...@gmail.com> wrote: > > Hello everyone, > > I have a small question about NativeBoost : How does the "+" operator when > applied to a pointer translates into NativeBoost code ? > > To give a bit of context, what I want to do is to reallocate some > non-contiguous bytes in memory to a buffer. Basically, I have an array of > integers in a buffer and I want to copy some chunks of it in another buffer. > The chunks are always the same size and the offset between each chunk is > always the same too. > > Because a bit of actual code is easier to understand here is what I'd like to > do in Pharo : > > ... > > int i, j; > int *data = malloc(1000*sizeof(int)); > int *newData = malloc(50*sizeof(int)); > > // Allocate initial data > for (i = 0 ; i < 1000, i++) { > data[i] = i; > } > > //Copy desired chunks into new buffer > for (i = 0; i < 5; i++ ) { > memcpy( newData + j*10, data + 200 + j*30, 10*sizeof(int)); > j++; > } > > free(data);
You can do relative addressing like this: (destReg ptr: dataSize) + offsetReg + constant So with offSetRegs containing j* 10 and j* 30, you might end up with an unrolled inner loop (barring using any fancier longer-than-int moves) like: 0 to: 9 do: [:constantOffset | asm mov: (destReg ptr: currentPlatform sizeOfInt) + dstOffsetReg + constantOffset with: (srcReg ptr: currentPlatform sizeOfInt) + 200 + srcOffsetReg + constantOffset] If the range of j is constant, you can just as easily unroll the whole thing in a similarly compact fashion, space and sensibilites permitting: 0 to: 4 do: [ :j | 0 to: 9 do: [ :consOffset | asm mov: (destReg ptr: currentPlatform sizeOfInt) + (j* 10) + constOffset with: (srcReg ptr: currentPlatform sizeOfInt) + 200 + (j * 30) + constOffset] Cheers, Henry