ARMv7-M汇编:寄存器中的未对齐字节替换?

时间:2017-05-23 17:43:52

标签: assembly arm cortex-m

假设我们有三个目标寄存器r5,r6和r7,并认为它们是一个12字节的数组:

r5={a, b, c, d} r6={e, f, g, h} r7={i, j, k, l}

我想要做的是从给定的内存位置读取8个字节{0, 1, 2, 3, 4, 5, 6, 7},并将它们复制到三个目标寄存器中以提供

r5={a, 0, 1, 2} r6={3, 4, 5, 6} r7={7, j, k, l}

换句话说,我想将r5-r7中数组的1-8位替换为从ROM读取的8个字节。

我可以在六条指令中执行此操作:

ldrd    r0, r1, [r3]
bfi     r5, r0, #8, #24
ubfx    r6, r0, #24, #8
bfi     r6, r1, #8, #24
bfc     r7, #0, #8
orr     r7, r7, r1, lsr #24

可以少花钱吗?假设没有浮点单位。

(背景:这是blitting例程的一部分,从内存中读取几个像素模式并合成一组寄存器,然后将这些寄存器写入stmia的显示缓冲区。)

1 个答案:

答案 0 :(得分:0)

我对发布以下内容犹豫不决,因为它没有解决问题 - 它在内存而不是在寄存器中组合输出。

但是它值得:

HTTP/1.1 500 Internal Server Error 
Cache-Control: public 
Content-Type: image/jpeg; charset=utf-8 Server: Microsoft-IIS/10.0 
X-AspNet-Version: 4.0.30319 
X-Powered-By: ASP.NET 
Content-Length: 7472

[ArgumentException]: Parameter is not valid.
   at System.Drawing.Bitmap..ctor(Stream stream, Boolean useIcm)
   at ImageResizer.ImageBuilder.DecodeStream(Stream s, ResizeSettings settings, String optionalPath)
   at ImageResizer.ImageBuilder.LoadImage(Object source, ResizeSettings settings, Boolean restoreStreamPos)
[ImageCorruptedException]: File may be corrupted, empty, or may contain a PNG image with a single dimension greater than 65,535 pixels.
   at ImageResizer.ImageBuilder.LoadImage(Object source, ResizeSettings settings, Boolean restoreStreamPos)
   at ImageResizer.ImageBuilder.BuildJob(ImageJob job)
   at ImageResizer.ImageBuilder.Build(ImageJob job)
   at ImageResizer.ImageBuilder.Build(Object source, Object dest, ResizeSettings settings, Boolean disposeSource, Boolean addFileExtension)
   at ImageResizer.ImageBuilder.Build(Object source, Object dest, ResizeSettings settings, Boolean disposeSource)
   at ImageResizer.ImageBuilder.Build(Object source, Object dest, ResizeSettings settings)
   at ImageResizer.InterceptModule.<>c__DisplayClass5_0.<HandleRequest>b__1(Stream stream)
   at ImageResizer.Plugins.DiskCache.CustomDiskCache.<>c__DisplayClass29_0.<TryWriteFile>b__0()
   at ImageResizer.Plugins.DiskCache.LockProvider.TryExecute(String key, Int32 timeoutMs, LockCallback success)
   at ImageResizer.Plugins.DiskCache.CustomDiskCache.TryWriteFile(CacheResult result, String physicalPath, String relativePath, ResizeImageDelegate writeCallback, Int32 timeoutMs, Boolean recheckFS)
   at ImageResizer.Plugins.DiskCache.CustomDiskCache.GetCachedFile(String keyBasis, String extension, ResizeImageDelegate writeCallback, Int32 timeoutMs, Boolean asynchronous)
   at ImageResizer.Plugins.DiskCache.DiskCache.Process(IResponseArgs e)
   at ImageResizer.Plugins.DiskCache.DiskCache.Process(HttpContext context, IResponseArgs e)
   at ImageResizer.InterceptModule.HandleRequest(HttpContext context, HttpModuleRequestAssistant ra, IVirtualFile vf)
   at ImageResizer.InterceptModule.CheckRequest_PostAuthorizeRequest(Object sender, EventArgs e)
   at System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

请注意:

  • 三个输出字汇编成四次写入内存,其中两个未对齐。
  • 两条r5,r6,r7 - abcdefghijkl (as per the question) r3 - input array ptr (as per the question) r2 - output array ptr r5 r6 r7 [r3] r0 r1 [r2] abcd efgh ijkl 01234567 ldrd r0, r1, [r3] 0123 4567 ------------ str r5, [r2, #0] abcd-------- str r7, [r2, #8] abcd----ijkl str.w r0, [r2, #1] a0123---ijkl str.w r1, [r2, #5] a01234567jkl 指令是16位编码。