iDevGames Forums
memset16 - Printable Version

+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: iPhone, iPad & iPod Game Development (/forum-11.html)
+--- Thread: memset16 (/thread-8118.html)



memset16 - captainfreedom - Sep 19, 2010 06:35 AM

I see android have arm optimised versions of memset: http://code.google.com/p/skia/source/browse/trunk/src/opts/memset.arm.S?r=594

Are the equivilant functions available for the iPhone?


RE: memset16 - OneSadCookie - Sep 19, 2010 06:59 AM

memset and memset_pattern* do 1, 4, 8, and 16-byte patterns between them. I don't see one that directly does 2-byte patterns, though obviously you can use memset_pattern4 for the purpose.

Code:
man memset_pattern



RE: memset16 - captainfreedom - Sep 20, 2010 01:41 AM

Ok. Maybe I'll just try using the android code


RE: memset16 - OneSadCookie - Sep 20, 2010 07:07 AM

"yes, here:"
"OK, I guess not, thanks anyway"


RE: memset16 - Skorche - Sep 20, 2010 09:10 AM

I think he was disappointed that you didn't point him to "optimized" versions. You just pointed out the stdlib versions which clearly must be inferior or why would a custom optimized version exist.

* Skorche shrugs


RE: memset16 - captainfreedom - Sep 20, 2010 10:19 AM

Amm. There is no stdlib version for memset16. And what's wrong with trying out the optimised version? You prefer stuff to be slower?


RE: memset16 - skyhawk - Sep 20, 2010 10:26 AM

(Sep 20, 2010 10:19 AM)captainfreedom Wrote:  Amm. There is no stdlib version for memset16. And what's wrong with trying out the optimised version? You prefer stuff to be slower?

Mad


RE: memset16 - Skorche - Sep 20, 2010 11:19 AM

Uh. The first reply to your post stated that in fact there was a 16 bit version. Also, do you have any reason to believe that these "optimized" versions really are any faster? have you actually tested them or are you just assuming that they are because they exist?


RE: memset16 - ThemsAllTook - Sep 20, 2010 11:21 AM

(Sep 20, 2010 10:19 AM)captainfreedom Wrote:  Amm. There is no stdlib version for memset16.

The man page OneSadCookie pointed to in his first post says otherwise, so I'm nor sure what you mean here:

man memset_pattern Wrote:void
memset_pattern16(void *b, const void *pattern16, size_t len);

(Sep 20, 2010 10:19 AM)captainfreedom Wrote:  And what's wrong with trying out the optimised version? You prefer stuff to be slower?

Skorche's post was tongue-in-cheek, presumably meant to point out that unless you have the profiler measurements to prove it, it's a relatively safe assumption that the stdlib implementation of a function will be optimal. If this is used in a crucial part of your code, and you've profiled it and shown it to be a bottleneck when you implement it with memset_pattern16, then you have a good reason to try out the optimized version. Otherwise, it's premature optimization, which is wasted effort if it doesn't end up being faster than the easy way. Since the only real way to measure that is to implement it both ways and profile your code with both methods, and since there's a perfectly good chance that the easy way will be fast enough in your case (and a chance the hard way is no faster than the easy way), it's logical to only try the hard way if you've already implemented it the easy way and proven it to be a bottleneck.

To the earlier sarcastic posters, the above is not necessarily self-evident. If you assume that every poster here has an intuitive understanding of these things that matches yours, it gives the forum an elitist and unwelcoming tone. Taking the time to explain things unpresumingly not only gives the person asking the question a better chance to learn, but also fosters mutual respect and a more positive forum environment.


RE: memset16 - OneSadCookie - Sep 20, 2010 11:23 AM

that's 16 bytes, not 16 bits. IDK why he wants 16 bits, but he seems to.

Yes, memset and memset_pattern* are highly optimized.


RE: memset16 - Skorche - Sep 20, 2010 05:51 PM

Ah, I did misread the bit/byte distinction. (I thought it odd that they would bother with < 1 byte patterns, now I know why.) Presumably he wants a 16 bit version for clearing a framebuffer or some such.

I wasn't however being sarcastic in my second reply. I was quite seriously asking if he had tried the stdlib versions and found them to be inefficient for what he wanted. He asked if there were optimized versions and seemed disappointed when the stdlib versions were mentioned.

If the confusion was that there wasn't a 2 byte/16 bit version, then you can just memset_pattern4(buff, pattern | (pattern << 16), length) The assembly code linked does the exact same thing. The 16 bit version just calls the 32 bit version.