Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to write inline assembly in Swift?

Tags:

I was wondering if you can write inline assembly in Swift.

I know that in Objective-C you could use something like this:

inline void assemblyFunc() {
    __asm__(/*Assembly*/);
}

But in Swift it seems that you can't use __asm__(/*Assembly*/).

Does anyone know how to use __asm__() if its even possible. I haven't found anything about it, so I thought it would be a good question to ask.

like image 513
Bas Avatar asked Jun 16 '14 14:06

Bas


People also ask

Does GCC support inline assembly?

GCC provides two forms of inline asm statements. A basic asm statement is one with no operands (see Basic Asm), while an extended asm statement (see Extended Asm) includes one or more operands.

Is inline assembly useful?

Inline Assembly is useful for in-place optimizations, and access to CPU features not exposed by any libraries or the operating system. For example, some applications need strict tracking of timing.

What is inline assembly code?

In computer programming, an inline assembler is a feature of some compilers that allows low-level code written in assembly language to be embedded within a program, among code that otherwise has been compiled from a higher-level language such as C or Ada.

How is inline assembly different from mixing assembly language with C?

Microsoft Specific Because the inline assembler doesn't require separate assembly and link steps, it is more convenient than a separate assembler. Inline assembly code can use any C variable or function name that is in scope, so it is easy to integrate it with your program's C code.


1 Answers

There isn't a way in Swift itself. If you need this, probably a good opportunity to take advantage of Swift-ObjC interop.

like image 73
Robert Levy Avatar answered Oct 05 '22 02:10

Robert Levy