Swift 2: SIMD
russbishop.net
russbishop.net
http://blogs.msdn.com/b/oldnewthing/archive/2014/06/13/10533...
I especially liked Raymond's comment: "Compiler optimizations may have been carefully selected for expository purposes." Counterintuitive, and interesting that the Swift program demonstrates the effect as clearly as the C program.
That's something I wouldn't have done; it may be the sole reason the non-SIMD code has a branch in the inner loop.
The SIMD code would still be faster, of course.
It also is a bit unfortunate to have types:
int4 : vector of 4 integers
Int32: 32-bit integerThe whole benchmark is artificial, hence my warning.
var count = Int()
for var i in array
{
i += negBoundary
let delta = (i > 0.0) ? 1 : 0
count += delta
}
(timed using mach_absolute_time(), on my system, that code also seems about twice as fast as the SIMD code)I did not check whether that trigraph gets compiled to a branch (I tried, but I had trouble reading the disassembly that otool gave me; I’m not used to x86, and I found the code surprisingly long)
Swift seems great, but I wouldn't expect any huge technical advantages over Obj-C until Apple stops caring about Obj-C (which I suspect huge chunks of Cocoa are written in for starters).
http://www.h4labs.com/dev/ios/swift.html
Apple is doing a good job of updating ObjC but Swift already has the momentum. Apple has made it clear that they want Swift:
http://ericasadun.com/2015/04/14/swift-in-case-you-didnt-thi...
You can choose to ignore their subtle messages (e.g. use Autolayout, Size Classes) but at some point in the not too distant future, you'll likely regret not starting with Swift earlier.
I was just pointing out that the original linked article isn't really about Swift, just an Apple framework that can be used with Swift.
So -- going back to the original point -- in fact this was Swift catching up with Obj-C, so it does pertain to Swift but is not evidence of Swift getting ahead of Obj-C.
The message is clear: learn Swift or be left behind.
I paid great attention to both WWDCs. In fact I read the Swift book immediately after the announcement. However, the point I am making remains true: Obj-C isn't going away soon and the linked article is not about Swift pulling away from Obj-C (indeed, it's about Swift catching up to Obj-C -- see author's comment elsewhere in thread).
In fact, here's a link to an article explaining how to bridge from Swift to Obj-C to make use of simd.h.
https://www.safaribooksonline.com/library/view/learning-swif...
The big change will occure once we start to see apple framework designed for swift, using swift specific patterns, and then adapted to objective-c for compatibility purpose. But for now, it's still a wrapper on top.