RealView Compilation Tools Developer Guide - ARM Information ...
RealView Compilation Tools Developer Guide - ARM Information ...
RealView Compilation Tools Developer Guide - ARM Information ...
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
混 合 使 用 C、 C++ 和 汇 编 语 言<br />
}<br />
disable_IRQ();<br />
enable_IRQ();<br />
标 量 积<br />
示 例 5-3 计 算 两 个 整 型 数 组 的 标 量 积 。 它 说 明 对 于 内 联 汇 编 程 序 不 直 接 支 持 的 C<br />
或 C++ 表 达 式 和 数 据 类 型 , 内 联 汇 编 语 言 如 何 与 其 交 互 。 内 联 函 数 mlal() 被 优<br />
化 为 单 个 SMLAL 指 令 。 使 用 -S -fs 编 译 程 序 选 项 可 以 查 看 编 译 程 序 生 成 的 汇 编 语<br />
言 代 码 。<br />
long long 与 __int64 相 同 。<br />
在 Examples_directory\inline\dotprod.c 中 也 有 此 代 码 。<br />
示 例 5-3 标 量 积<br />
#include <br />
/* change word order if big-endian */<br />
#define lo64(a) (((unsigned*) &a)[0]) /* low 32 bits of a long long */<br />
#define hi64(a) (((int*) &a)[1]) /* high 32 bits of a long long */<br />
__inline __int64 mlal(__int64 sum, int a, int b)<br />
{<br />
#if !defined(__thumb) && defined(__TARGET_FEATURE_MULTIPLY)<br />
__asm<br />
{<br />
SMLAL lo64(sum), hi64(sum), a, b<br />
}<br />
#else<br />
sum += (__int64) a * (__int64) b;<br />
#endif<br />
return sum;<br />
}<br />
__int64 dotprod(int *a, int *b, unsigned n)<br />
{<br />
__int64 sum = 0;<br />
do<br />
sum = mlal(sum, *a++, *b++);<br />
while (--n != 0);<br />
return sum;<br />
}<br />
int a[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };<br />
int b[10] = { 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 };<br />
5-10 © 2002、 2003 <strong>ARM</strong> Limited 版 权 所 有 。 保 留 所 有 权 利 。 <strong>ARM</strong> DUI 0203BSC