Floating point operation of arm chip

Publisher:乐基儿vosLatest update time:2016-08-13 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
微软MSDN上关于ARM芯片浮点运算的资料
        勿使用浮点运算
        ARM 处理器并不支持浮点运算 (Floating Point Math)。所有的浮点运算都是在浮点运算模拟器上进行,因此特别缓慢。需要浮点运算的函式,常要耗费数千个循环才能执行完毕。这就是为何游戏开发时,通常都使用定点 (Fixed Point) 格式的运算。定点运算实际上是使用整数,但指定固定数目的位元做為数值的分数部份。就好像是指定某一数字,其千位数以下為分数。若要表示 0.500,只要乘以 1000,便得到 500 这个数值。
       比较困难的部份,是开发人员必须随时想像这个隐形的小数点。加法与减法比较没有问题:
               500 + 500 = 1000 (可视為:0.500 + 0.500 = 1.000)。
       乘法与除法则较為困难:
               500 * 500 = 250000 (但若视為:0.500 * 0.500 = 250.000) 结果会不正确。
       两个定点数值相乘后,必须以除法调整有效位数。若将结果除以 1000,则得到正确值 (250.000 / 1000 = 0.250 為正确的结果)。因此,进行乘法运算时,先做一般的乘法运算,再以除法调整结果的有效位数。
       上述方法会引出一项有趣的问题。相乘后但尚未调整位数前,此居中数值的范围為何?
       在上例中,执行乘法后,数值可能会超过允许的位元数。亦即可能会造成溢位,而得不到您想要的结果。解决方法是為居中数值指定合适的资料格式,确保能储存可能的最大值。当您将两个 32 位元数值相乘时,居中数值必须是 64 位元。调整位数后 (以及截断数值),结果会恢復為 32 位元。
   int Multiply16_16_by_16_16( int a16_16, int b16_16 )
{
     __int64 tmp32_32;
     int result16_16;
     tmp32_32 = a16_16;
     tmp32_32 *= b16_16;     // 目前结果為 32:32
     tmp32_32 >>= 16; // 截断 16 个低位元
     result16_16 = ( int ) tmp32_32; // 截断 16 个高位元
     // 目前结果回到 16:16
     return result16_16;
}
        若要除法运算,则执行相反的程序:先以乘法调整,再进行相除。
        常用的定点格式為 16:16,亦即前 16 位元代表整数部份,后 16 位元代表分数部份。        以此游戏专案而言,使用了各种不同的格式,以便应用在游戏引擎中各种范围的数值。简而言之,共使用了 2:30、8:24、16:16、24:8、28:4、2:14、8:8、11:5、2:8 以及4:4。其中大多数是 32 位元数值,但有些是 16 位元、10 位元或 8 位元。
Reference address:Floating point operation of arm chip

Previous article:atmega fuse configuration details
Next article:Connection between ARM and SDRAM chip

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号