
Swift 2: SIMD - tambourine_man
http://www.russbishop.net/swift-2-simd
======
SloopJon
The chart in the results section is interesting. I don't remember reading
Raymond Chen's post on branch prediction before, so thanks for that:

[http://blogs.msdn.com/b/oldnewthing/archive/2014/06/13/10533...](http://blogs.msdn.com/b/oldnewthing/archive/2014/06/13/10533875.aspx)

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.

------
Someone
_" The logic in the inner loop is a silly way to count whether something is
below the boundary but it matches what we have to do on the SIMD side"_

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 integer

~~~
xenadu02
Author here; the non-vector loop still has a branch with a less than check if
you do it the straightforward way.

The whole benchmark is artificial, hence my warning.

~~~
Someone
Thanks. I do not see that when I use what I would think to be the
straightforward way to count (using integers), though:

    
    
      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)

------
justonepost
Swift is really starting to show it's superiority to ObjC. I think we'll see a
very significant inflection point in iOS development when Swift is open
sourced.

~~~
Tloewald
Since this all relates to simd.h it seems like it's taking advantage of C APIs
which are equally available to Obj-C coders.

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).

~~~
melling
People are already blogging mostly in Swift rather than Objective C, which was
created in the mid 1980's.

[http://www.h4labs.com/dev/ios/swift.html](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...](http://ericasadun.com/2015/04/14/swift-in-case-you-didnt-think-that-
swift-was-the-future/)

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.

~~~
Tloewald
Oh, no argument there -- and I wouldn't call the messages subtle, either. That
said, Apple would be insane to orphan its Obj-C codebase (but it may start
deprecating...)

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.

~~~
xenadu02
Author here; that's not correct. Swift 2 introduced compiler support for the
SIMD intrinsics that make this possible. It's listed directly as one of the
new features of Swift 2.

~~~
Tloewald
Thanks for the correction.

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.

------
_rs
I remember opening a bug report for this quite a few months back. No reply
(nor marked as dupe), but glad to see it getting implemented.

