views:

644

answers:

2

i am converting some Int16's to float and then back again. and some int32 's to float and back again

im just using a straight cast, but doing this quite a few times per second. (44100 any guesses what its for? :) )

is a cast efficient, can it be done any faster?

ps compile for thumb is turned off

+1  A: 

Is a cast efficient? In your case, I'd guess it's efficient enough.

Can it be done faster? Maybe...but would it be worth the effort? Have you benchmarked it and discovered a performance problem due to the cast operations?

If you're doing anything mathematically nontrivial with the floating point sample data, I'd be really surprised if the casts turned out to be a significant bottleneck!

Jim Lewis
its not so much it is a bottleneck, im just up against the wall in terms of performance and looking for every increase of speed i can get, so id still like to know how to do it faster
Aran Mulholland
i have marked this answer as unhelpful as it doesnt answer the question. the forums here promote discussion, this answer does not. whether or not my program needs it this is a question that if answered correctly will be utilized by the iphone community, and an answer like this helps a question like this go unanswered.
Aran Mulholland
after reflection, your answer was good enough, edit your answer and ill upvote it.
Aran Mulholland
+1  A: 

There are only two ways to know.

1) Read the code the compiler generates for promoting ints to floats in your case.

2) Measure the performance of the code the compiler generates vs. other options.

To do the former, set the SDK to Device and the Active Architecture to arm, and choose Build > Show Assembly Code. Then read the compiler-generated code.

If you are smarter than a compiler then you can write your own assembly code and use it instead. Odds are you aren't.

If you are doing an operation many, many times, Instruments will do a good job at showing you how many processor samples it's taking. But Jim's point is valid, and you shouldn't dismiss it as unhelpful: in an operation involving math on floating-point numbers, compiler type promotion is the least of your worries. Chips are built to do that in two or three cycles, and compilers usually manage to make that happen. But the effects processing you're doing will probably take thousands of cycles. The promotion will be lost in the noise.

cdespinosa