- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我对 Delphi 10.2 Pascal 编程语言中的特定编程问题有疑问。
StringOfChar 和 FillChar 在 2012 年之前发布的 CPU 上的 Win64 版本构建下无法正常工作。
FillChar 的预期结果只是在给定内存缓冲区中重复 8 位字符的普通序列。
StringOfChar 的预期结果相同,但结果存储在字符串类型中。
但实际上,当我使用 10.2 版本的 Delphi 编译在 10.2 之前的 Delphi 中运行的应用程序时,我们为 Win64 编译的应用程序在 2012 年之前发布的 CPU 上无法正常运行。
StringOfChar 和 FillChar 不能正常工作——它们返回一个由不同字符组成的字符串,尽管是重复的模式——而不是它们应该返回的相同字符的序列。
这是足以说明问题的最少代码。请注意,序列的长度应至少为 16 个字符,且字符不应为 nul (#0)。代码如下:
procedure TestStringOfChar;
var
a: AnsiString;
ac: AnsiChar;
begin
ac := #1;
a := StringOfChar(ac, 43);
if a <> #1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1 then
begin
raise Exception.Create('ANSI StringOfChar Failed!!');
end;
end;
我知道 StackOverflow 上有很多 Delphi 程序员。您遇到同样的问题吗?如果是,你是如何解决的?解决办法是什么?顺便说一下,I have contacted the developers of Delphi but they didn’t confirm nor deny the issue so far .我使用的是 Embarcadero Delphi 10.2 版本 25.0.26309.314。
更新:
如果您的 CPU 是 2012 年或之后生产的,请在调用 StringOfChar 重现问题之前添加以下行:
const
ERMSBBit = 1 shl 9; //$0200
begin
CPUIDTable[7].EBX := CPUIDTable[7].EBX and not ERMSBBit;
关于April 2017 RAD Studio 10.2 Hotfix for Toolchain Issues - 尝试过使用它和不使用它 - 它没有帮助。无论修补程序如何,该问题都存在。
更新#2
Embarcadero 已于 08/Aug/17 下午 6:03 确认并解决了此问题。因此,在 Delphi 10.2 Tokyo Release 1(2017 年 8 月 8 日发布)中修复了此错误。
最佳答案
StringOfChar(A: AnsiChar, count)
在底层使用 FillChar。
您可以使用以下代码来解决问题:
(*******************************************************
System.FastSystem
A fast drop-in addition to speed up function in system.pas
It should compile and run in XE2 and beyond.
Alpha version 0.5, fully tested in Win64
(c) Copyright 2016 J. Bontes
This Source Code Form is subject to the terms of the
Mozilla Public License, v. 2.0.
If a copy of the MPL was not distributed with this file,
You can obtain one at http://mozilla.org/MPL/2.0/.
********************************************************
FillChar code is an altered version FillCharsse2 SynCommons.pas
which is part of Synopse framework by Arnaud Bouchez
********************************************************
Changelog
0.5 Initial version:
********************************************************)
unit FastSystem;
interface
procedure FillChar(var Dest; Count: NativeInt; Value: ansichar); inline; overload;
procedure FillChar(var Dest; Count: NativeInt; Value: Byte); overload;
procedure FillMemory(Destination: Pointer; Length: NativeUInt; Fill: Byte); inline;
{$EXTERNALSYM FillMemory}
procedure ZeroMemory(Destination: Pointer; Length: NativeUInt); inline;
{$EXTERNALSYM ZeroMemory}
implementation
procedure FillChar(var Dest; Count: NativeInt; Value: ansichar); inline; overload;
begin
FillChar(Dest, Count, byte(Value));
end;
procedure FillMemory(Destination: Pointer; Length: NativeUInt; Fill: Byte);
begin
FillChar(Destination^, Length, Fill);
end;
procedure ZeroMemory(Destination: Pointer; Length: NativeUInt); inline;
begin
FillChar(Destination^, Length, 0);
end;
//This code is 3x faster than System.FillChar on x64.
{$ifdef CPUX64}
procedure FillChar(var Dest; Count: NativeInt; Value: Byte);
//rcx = dest
//rdx=count
//r8b=value
asm
.noframe
.align 16
movzx r8,r8b //There's no need to optimize for count <= 3
mov rax,$0101010101010101
mov r9d,edx
imul rax,r8 //fill rax with value.
cmp rdx,59 //Use simple code for small blocks.
jl @Below32
@Above32: mov r11,rcx
mov r8b,7 //code shrink to help alignment.
lea r9,[rcx+rdx] //r9=end of array
sub rdx,8
rep mov [rcx],rax
add rcx,8
and r11,r8 //and 7 See if dest is aligned
jz @tail
@NotAligned: xor rcx,r11 //align dest
lea rdx,[rdx+r11]
@tail: test r9,r8 //and 7 is tail aligned?
jz @alignOK
@tailwrite: mov [r9-8],rax //no, we need to do a tail write
and r9,r8 //and 7
sub rdx,r9 //dec(count, tailcount)
@alignOK: mov r10,rdx
and edx,(32+16+8) //count the partial iterations of the loop
mov r8b,64 //code shrink to help alignment.
mov r9,rdx
jz @Initloop64
@partialloop: shr r9,1 //every instruction is 4 bytes
lea r11,[rip + @partial +(4*7)] //start at the end of the loop
sub r11,r9 //step back as needed
add rcx,rdx //add the partial loop count to dest
cmp r10,r8 //do we need to do more loops?
jmp r11 //do a partial loop
@Initloop64: shr r10,6 //any work left?
jz @done //no, return
mov rdx,r10
shr r10,(19-6) //use non-temporal move for > 512kb
jnz @InitFillHuge
@Doloop64: add rcx,r8
dec edx
mov [rcx-64+00H],rax
mov [rcx-64+08H],rax
mov [rcx-64+10H],rax
mov [rcx-64+18H],rax
mov [rcx-64+20H],rax
mov [rcx-64+28H],rax
mov [rcx-64+30H],rax
mov [rcx-64+38H],rax
jnz @DoLoop64
@done: rep ret
//db $66,$66,$0f,$1f,$44,$00,$00 //nop7
@partial: mov [rcx-64+08H],rax
mov [rcx-64+10H],rax
mov [rcx-64+18H],rax
mov [rcx-64+20H],rax
mov [rcx-64+28H],rax
mov [rcx-64+30H],rax
mov [rcx-64+38H],rax
jge @Initloop64 //are we done with all loops?
rep ret
db $0F,$1F,$40,$00
@InitFillHuge:
@FillHuge: add rcx,r8
dec rdx
db $48,$0F,$C3,$41,$C0 // movnti [rcx-64+00H],rax
db $48,$0F,$C3,$41,$C8 // movnti [rcx-64+08H],rax
db $48,$0F,$C3,$41,$D0 // movnti [rcx-64+10H],rax
db $48,$0F,$C3,$41,$D8 // movnti [rcx-64+18H],rax
db $48,$0F,$C3,$41,$E0 // movnti [rcx-64+20H],rax
db $48,$0F,$C3,$41,$E8 // movnti [rcx-64+28H],rax
db $48,$0F,$C3,$41,$F0 // movnti [rcx-64+30H],rax
db $48,$0F,$C3,$41,$F8 // movnti [rcx-64+38H],rax
jnz @FillHuge
@donefillhuge:mfence
rep ret
db $0F,$1F,$44,$00,$00 //db $0F,$1F,$40,$00
@Below32: and r9d,not(3)
jz @SizeIs3
@FillTail: sub edx,4
lea r10,[rip + @SmallFill + (15*4)]
sub r10,r9
jmp r10
@SmallFill: rep mov [rcx+56], eax
rep mov [rcx+52], eax
rep mov [rcx+48], eax
rep mov [rcx+44], eax
rep mov [rcx+40], eax
rep mov [rcx+36], eax
rep mov [rcx+32], eax
rep mov [rcx+28], eax
rep mov [rcx+24], eax
rep mov [rcx+20], eax
rep mov [rcx+16], eax
rep mov [rcx+12], eax
rep mov [rcx+08], eax
rep mov [rcx+04], eax
mov [rcx],eax
@Fallthough: mov [rcx+rdx],eax //unaligned write to fix up tail
rep ret
@SizeIs3: shl edx,2 //r9 <= 3 r9*4
lea r10,[rip + @do3 + (4*3)]
sub r10,rdx
jmp r10
@do3: rep mov [rcx+2],al
@do2: mov [rcx],ax
ret
@do1: mov [rcx],al
rep ret
@do0: rep ret
end;
{$endif}
解决问题的最简单方法是 Download Mormot并包括 SynCommon.pas进入你的项目。这会将 System.FillChar 修补到上述代码,并包括一些其他性能改进。
请注意,您不需要所有的 Mormot,只需要 SynCommons 本身。
关于windows - Delphi 10.2 for Win64 Release Target 下的 FillChar 和 StringOfChar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43958955/
在项目属性窗口的应用程序选项卡和启动对象组合框中,我无法看到我的 win 表单以将其中一个设置为启动对象。 它出什么问题了? 最佳答案 开通 Program.cs启动项目的文件(在解决方案中选择为启动
我的问题是,当我得到正确的数字时,python 脚本结束,但不打印:你赢了! import random number = random.randint(1,100) # This part work
我使用 Eclipse 开发了一个 Java 应用程序。我使用的电脑操作系统是Win Vista。我在 Win XP 计算机上使用此应用程序时遇到问题。我发现的问题是: 如果在我的代码中我使用以下几行
显然,这将打印出石头/剪刀/布获胜或平局。 实现“石头胜剪刀——计算机胜!”这样的结果的最佳方式是什么?等等? var userChoice = prompt("Do you choose rock,
我正在开发一个使用HttpWebRequest将请求发送到另一台服务器的ASP.NET Web应用程序。它通过HTTPS发送请求,并且远程服务器需要客户端证书。该请求在.NET应用程序中失败,显然无法
我正在 WIn XP 上使用 VC6 开发应用程序。使用 GetKeyBoardLayoutList() 和 GetLocalInfo() API 从系统检索默认输入语言列表。 代码如下。 `UINT
我在 WPF 中创建了一个无边框窗口。我已经编写了一个事件来最大化窗口,但是在最大化时,部分窗口有时会隐藏在任务栏后面,片刻之后会出现在任务栏顶部。 如何确保窗口每次都保持在任务栏的顶部?以下是我实现
我开始制作 3d 游戏。然后我停了一段时间并安装了win7。现在我想继续研究它只是为了发现代码卡住了!在 XP 上,我将 View 渲染到窗体上。并且游戏循环和所有游戏形式都在同一个线程上运行! 这在
main() { int *p; free(p); } 此代码在 Win 2K 中崩溃。但不知何故不会在 Win Xp 中崩溃!知道为什么吗? 编辑:是的。这是一个错误,不应该被写入。更多
我在我的应用程序中使用 libeay32.dll/ssleay32.dll 库来支持 https。库在 Windows 7 上成功加载(不是通过我的应用程序,通过 Qt 库),但是我在 Windows
在源代码下方添加了新的详细信息。 有一个问题是 Delphi,其中 Internet 代码可在 Win 10 上运行,但不能在 Win 7 上运行。我正在尝试将一个小项目连接到 haveibeenpw
我在 Win 7 上为 Perfmon 创建了 xml 模板。我能够导入它并运行它 - 一切正常。现在,当我将此 xml 复制到 Win 2008 R2 计算机并尝试将其导入到 perfmon 中时,
我在使用标准数据驱动的 Winform 应用程序时遇到了一个有趣的问题。 该应用程序最初是在 Windows 7 和 Visual Studio 2010 上开发的。然后我用 Windows 8 和
我有一个在 Windows 7(64 位)上编写的程序,可以在我的计算机上正确编译和运行。 但在其他计算机上(特别是在 Windows 8(64 位)上)该程序无法运行。当我尝试运行它时,它说我的程序
将现有的基于 Vb6.0 win 的应用程序转换为基于 c# win 的应用程序的最快方法是什么? 最佳答案 核心语言如此不同,我不得不说从头开始,只复制复杂的代码位。如果您从头开始,您将不必处理所有
我正在处理 IE 11 在 Windows 8 和 Windows 8.1 上的奇怪行为。我正在固定定位元素内的元素位置。而且它变得很奇怪。当我用开发工具检查它时它在正确的位置,但在视觉上它完全在不同
将使用 Java x32 在 eclipse x32 上创建的项目导入到使用 java x64 的 eclipse x64 上有哪些挑战? 最佳答案 Java 是跨平台的,所以你应该不会有任何问题。
鉴于 l 是一个整数列表并且 win 是一个整数,下面的代码生成一个列表 lpadded: lpadded = win // 2 * [-1] + l + win // 2 * [-1] 在 lpad
我有一个适用于 Windows Phone 8.1 的应用程序及其 UWP 版本。我想在 Windows 中更改应用程序的背景时动态更改它。 用例是: 启动应用,背景主题为深色。 按下手机上的主页按钮
不完全确定我是否已经解决了这个问题,但这是我所看到的以及我认为正在发生的事情。 我有一个主要用 C 编写的 Win32 程序,它加载一个 C++ DLL。该 DLL 通过 COM 对象将数据从 C 程
我是一名优秀的程序员,十分优秀!