Hacker News new | past | comments | ask | show | jobs | submit login
Swift 2: SIMD (russbishop.net)
51 points by tambourine_man on June 24, 2015 | hide | past | favorite | 15 comments



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

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.


"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


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.


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)


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.


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


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

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.


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.


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.


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.


Reminds me of the Accelerate framework and Altivec for Mac OS X from 10 years ago...

http://www.unix.com/man-page/OSX/7/Altivec/


I guess you didn't pay attention to this years WWDC. Apple pushed Swift harder than they have ever pushed anything else. 7 session mentioned Swift in their title , only one did Obj-C and Swift was also mentioned in that sessions title. Almost all of the examples were in Swift.

The message is clear: learn Swift or be left behind.


You obviously didn't pay attention to what I wrote.

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


Although the language itself is clearly superior, Cocoa was written for objective c, so coding with this language still is a quite pleasant experience. I don't feel an urge to move to swift right now, but i'll certainly start learning it during the course of the year, and probably switch to it at the end of the year.

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.


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.




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: