1. Remind me - mem_set()?

If I allocate(2000) and want to initialise that to 500 identical (non-null) dwords, in this specific case an #AARRGGBB colour, what's the best way?

I'm thinking mem_set() is missing a size=1 parameter, which (with atom v instead of integer byte_value) can also be 2/4/8, and maybe -4/-8 to poke float32/64...
I realise that mem_copy() would work, but would perform 499 unnecessary reads, or would modern cpus make that completely irrelevant?
I also realise that poke4(addr,repeat(v,500)) would also work, but clearly suboptimal, maybe it is poke4() that is missing a times=1 parameter?

It seems to be one of those rare things I find easier in assembly than Eu/Phix...

new topic     » topic index » view message » categorize

2. Re: Remind me - mem_set()?

petelomax said...

If I allocate(2000) and want to initialise that to 500 identical (non-null) dwords, in this specific case an #AARRGGBB colour, what's the best way?

I'm thinking mem_set() is missing a size=1 parameter, which (with atom v instead of integer byte_value) can also be 2/4/8, and maybe -4/-8 to poke float32/64...
I realise that mem_copy() would work, but would perform 499 unnecessary reads, or would modern cpus make that completely irrelevant?
I also realise that poke4(addr,repeat(v,500)) would also work, but clearly suboptimal, maybe it is poke4() that is missing a times=1 parameter?

It seems to be one of those rare things I find easier in assembly than Eu/Phix...

To be fair, C's own memset works the same as Euphoria:

cplusplus.com said...

value
Value to be set. The value is passed as an int, but the function fills the block of memory using the unsigned char conversion of this value.

So yes currently the "best" method in Euphoria would be poke4(addr, repeat(value, count)). I suspect there's a better method that doesn't first create such a large sequence in memory. Searching around the Google it seems like a simple for loop in C is best and is often optimized by the compiler whenever you possible. Optimizing this in Euphoria would mean lifting the for loop up to the backend which I'd likely implement as you've suggested: by adding a count parameter to poke4(), etc. or conversely adding a size parameter to mem_set().

-Greg

new topic     » goto parent     » topic index » view message » categorize

3. Re: Remind me - mem_set()?

petelomax said...

If I allocate(2000) and want to initialise that to 500 identical (non-null) dwords, in this specific case an #AARRGGBB colour, what's the best way?

I'm thinking mem_set() is missing a size=1 parameter, which (with atom v instead of integer byte_value) can also be 2/4/8, and maybe -4/-8 to poke float32/64...
I realise that mem_copy() would work, but would perform 499 unnecessary reads, or would modern cpus make that completely irrelevant?
I also realise that poke4(addr,repeat(v,500)) would also work, but clearly suboptimal, maybe it is poke4() that is missing a times=1 parameter?

It seems to be one of those rare things I find easier in assembly than Eu/Phix...

I believe a series of 10 mem_copy() calls, with each subsequent call being twice the size of the previous one, could be quite a fast way to do it. You would have to trim the last one.

Spock

new topic     » goto parent     » topic index » view message » categorize

4. Re: Remind me - mem_set()?

Spock said...

I believe a series of 10 mem_copy() calls, with each subsequent call being twice the size of the previous one, could be quite a fast way to do it. You would have to trim the last one.

(sorry for the tardy reply, been busy) Nice try, but I doubt that would be as fast as mem_copy(mem,mem+4,1996)... and I still suspect the unnecessary reads might halve performance.

Don't get me wrong: I'm perfectly happy to slap down a little inline assembler, it just strikes me as a little bit odd there isn't a properly efficient hll way to do it.

PS obviously no-one should really care about 2K, but since even my bargain basement £80 phone takes 50MP photos, then someone might.

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu