projects
/
experiments
/
inline-assembly.git
/ commitdiff
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
c7e67bc
)
Add an inline asm implementation of sum() for x86 CPUs
author
Antonio Ospite <ospite@studenti.unina.it>
Tue, 5 Nov 2013 16:57:56 +0000
(17:57 +0100)
committer
Antonio Ospite <ospite@studenti.unina.it>
Tue, 5 Nov 2013 22:03:47 +0000
(23:03 +0100)
inline-asm-sum.c
patch
|
blob
|
history
diff --git
a/inline-asm-sum.c
b/inline-asm-sum.c
index
4f9c2f0
..
a578ee7
100644
(file)
--- a/
inline-asm-sum.c
+++ b/
inline-asm-sum.c
@@
-21,7
+21,16
@@
static int sum(int a, int b)
{
static int sum(int a, int b)
{
+#if defined(__i386__) || defined(__x86_64__)
+ int ret;
+ __asm__("addl %2, %1\n\t"
+ : "=a"(ret) /* %0 bound to %eax */
+ : "a"(a), "r"(b) /* %1 is 'a' bound to %eax, %2 is 'b' */
+ );
+ return ret;
+#else
return a + b;
return a + b;
+#endif
}
int main(void)
}
int main(void)