<div style="white-space:pre-wrap">I feel like inline assembly is a very niche idea. Inline assembly is supported by c and by extension objective-c.<br><br>//file.h<br>void aCFunction();<br>//file.m<br> void aCFunction() {<br> int a=10, b;<br> asm ("movl %1, %%eax; <br> movl %%eax, %0;"<br> :"=r"(b) /* output */<br> :"r"(a) /* input */<br> :"%eax" /* clobbered register */<br> ); <br>}<br><br>I found the assembly code here: <a href="http://www.ibiblio.org/gferg/ldp/GCC-Inline-Assembly-HOWTO.html">http://www.ibiblio.org/gferg/ldp/GCC-Inline-Assembly-HOWTO.html</a><br><br>But theoretically you should be able to call this assembly code via aCFunction() in swift.<br><br>I understand that it might be fun to do assembly in swift but I feel like low level code should stay in its territory; if you want to do low level programming write c code, if you want to go lower than that, leverage inline assembly within the boundaries of c.</div><br><div class="gmail_quote"><div dir="ltr">On Sat, Dec 3, 2016 at 7:23 PM Chris Lattner via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br class="gmail_msg">
> On Dec 3, 2016, at 3:12 PM, Ethin Probst via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="gmail_msg" target="_blank">swift-evolution@swift.org</a>> wrote:<br class="gmail_msg">
><br class="gmail_msg">
> Hello all,<br class="gmail_msg">
> My name is Ethin and I am new to this community. However, I certainly<br class="gmail_msg">
> am no newbie when it comes to software development, and have emailed<br class="gmail_msg">
> all of you to file a proposal of inline assembly in Swift. The<br class="gmail_msg">
> assembly language would be within an asm {...} block.<br class="gmail_msg">
<br class="gmail_msg">
Hi Ethin,<br class="gmail_msg">
<br class="gmail_msg">
While it isn’t a pressing short term priority, I would like to see something to address the needs served by inline assembly in Swift at some point. We have a lot of experience from the Clang/C space to draw on here, and there are three general approaches supported by Clang:<br class="gmail_msg">
<br class="gmail_msg">
1) “Processor Intrinsics" for instructions. Compilers for some architectures provide this as the only option (Itanium in MSVC IIRC).<br class="gmail_msg">
2) “Microsoft” or “CodeWarrior” style inline assembly, like you show. This doesn’t require the developer to write register constraints, and sometimes allows direct use of local variables in the asm block.<br class="gmail_msg">
3) “GCC” style inline assembly, which requires the user to write register constraints like “rmi”.<br class="gmail_msg">
<br class="gmail_msg">
I’m significantly opposed to ever supporting GCC-style assembly, since it is very very common for developers to get the constraints wrong, and the compiler knows the instruction set anyway.<br class="gmail_msg">
<br class="gmail_msg">
When it comes to #1 vs #2, there are tradeoffs:<br class="gmail_msg">
<br class="gmail_msg">
#1 is simpler, doesn’t require language extensions (and can be done today by a sufficiently motivated person), and composes better with processor-independent intrinsics (like cross platform prefetch operations).<br class="gmail_msg">
<br class="gmail_msg">
#2 is better for folks who “think in assembly”, because it has a more obvious and direct mapping to it. It has the additional downside of having to deal with multiple dialects of assembly, e.g. AT&T vs Intel syntax.<br class="gmail_msg">
<br class="gmail_msg">
-Chris<br class="gmail_msg">
<br class="gmail_msg">
_______________________________________________<br class="gmail_msg">
swift-evolution mailing list<br class="gmail_msg">
<a href="mailto:swift-evolution@swift.org" class="gmail_msg" target="_blank">swift-evolution@swift.org</a><br class="gmail_msg">
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" class="gmail_msg" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class="gmail_msg">
</blockquote></div>