搜索
bottom↓
回复: 19

纠正错误,AVR-GCC 浮点数(float 和 double) 一律处理为单精度(4 bytes),并不是所说的

[复制链接]

出0入0汤圆

发表于 2006-7-15 14:55:00 | 显示全部楼层 |阅读模式
网上流传的“GCC还有一个很严重的缺陷就是,不支持float数据类型,实际上GCC在所有环境中都把float直接定义为double,这样,对8bit环境来说,就显得负担过重了”是不正确的说法。

    准确的说是,GCC是将double定义成了float类型的了。

    今天在看反汇编时偶然发现。

阿莫论坛20周年了!感谢大家的支持与爱护!!

月入3000的是反美的。收入3万是亲美的。收入30万是移民美国的。收入300万是取得绿卡后回国,教唆那些3000来反美的!

出0入0汤圆

 楼主| 发表于 2006-7-15 17:42:06 | 显示全部楼层
到目前 所有的GCC-AVR都是这样子的. 不过GCC在做浮点运算的时候还是比较优化的, 比ICC好.

如下代码  float f; f=1.0; f/=3.0; f=sin(f);

除法运算,GCC中执行大概500个周期, 而ICC需要700个周期;

SIN运算, GCC需要大概5500个周期, 而ICC需要7100个周期;

这就是优势.所以选择GCC没错. 牛人做的东西就是牛.

出0入0汤圆

发表于 2006-7-15 18:36:36 | 显示全部楼层
楼主老大,那个“网上流传的‘GCC还有一个很严重的缺陷就是,不支持float数据类型,实际上GCC在所有环境中都把float直接定义为double,这样,对8bit环境来说,就显得负担过重了’”很不幸是鄙人在下我说的,更不幸的是说这话的时候刚2003年(还是2002年来着?记不大清楚了,太久远了……)





3、4年了也,生个小孩都会打酱油了,您以为以高效率著称的开源团队GNU会一直放着这么大一个疏漏不管么?
-----此内容被watercat于2006-07-15,18:38:26编辑过

出0入0汤圆

 楼主| 发表于 2006-7-16 00:43:33 | 显示全部楼层
再WINAVR的下载地 找了个最老的版本2002年11月11日发布的, 发现也是这样(float和double一律处理为4bytes)

出0入0汤圆

发表于 2006-7-16 00:49:42 | 显示全部楼层
很好,那么那时候我测试的8byte便是幽灵版本咯

出0入0汤圆

 楼主| 发表于 2006-7-16 01:10:08 | 显示全部楼层
能把你所说的版本发上来看看吗?

出0入0汤圆

发表于 2006-7-16 01:10:19 | 显示全部楼层
在WINAVR的手册里就已经明确地说明了数据的类型:(贴上来大家参考)

“What registers are used by the C compiler?

• Data types:

char is 8 bits, int is 16 bits, long is 32 bits, long long is 64 bits, float and

double are 32 bits (this is the only supported floating point format), pointers

are 16 bits (function pointers are word addresses, to allow addressing the whole 128K program memory space on the ATmega devices with > 64 KB of flash

ROM). There is a -mint8 option (see Options for the C compiler avr-gcc) to

make int 8 bits, but that is not supported by avr-libc and violates C standards

(int must be at least 16 bits). It may be removed in a future release.



• Call-used registers (r18-r27, r30-r31):

May be allocated by gcc for local data. You may use them freely in assembler

subroutines. Calling C subroutines can clobber any of them - the caller is responsible for saving and restoring.



• Call-saved registers (r2-r17, r28-r29):

May be allocated by gcc for local data. Calling C subroutines leaves them unchanged. Assembler subroutines are responsible for saving and restoring these

registers, if changed. r29:r28 (Y pointer) is used as a frame pointer (points to

local data on stack) if necessary.



• Fixed registers (r0, r1):

Never allocated by gcc for local data, but often used for fixed purposes:

r0 - temporary register, can be clobbered by any C code (except interrupt handlers

which save it), may be used to remember something for a while within one piece of

assembler code r1 - assumed to be always zero in any C code, may be used to remember something for a while within one piece of assembler code, but must then be cleared after use (clr r1). This includes any use of the [f]mul[s] instructions, which return their result in r1:r0. Interrupt handlers save and clear r1 on entry, and restore r1 on exit (in case it was non-zero).



• Function call conventions:

Arguments - allocated left to right, r25 to r8. All arguments are aligned to start in even-numbered registers (odd-sized arguments, including char, have one free

register above them). This allows making better use of the movw instruction on

the enhanced core. If too many, those that don’t fit are passed on the stack.

Return values: 8-bit in r24 (not r25!), 16-bit in r25:r24, up to 32 bits in r22-r25, up to 64 bits in r18-r25. 8-bit return values are zero/sign-extended to 16 bits by the caller (unsigned char is more efficient than signed char - just clr r25). Arguments to functions with variable argument lists (printf etc.) are all passed on stack, and char is extended to int.



Warning:

There was no such alignment before 2000-07-01, including the old patches for

gcc-2.95.2. Check your old assembler subroutines, and adjust them accordingly.

出0入71汤圆

发表于 2006-10-8 09:00:36 | 显示全部楼层
顶GCC个肺,把我害惨了,独生子女float 和 二胎 double是一样

出0入0汤圆

发表于 2006-10-8 14:15:19 | 显示全部楼层
确实是4字节

出0入0汤圆

发表于 2006-10-8 14:15:42 | 显示全部楼层
确实是4字节

出0入0汤圆

发表于 2006-10-8 20:27:01 | 显示全部楼层
我也觉得怪怪,GCC本就是把float与double 都是按float处理的啊!Winavr也就那几个版本啊!!!

出0入0汤圆

发表于 2009-8-21 00:57:41 | 显示全部楼层
The following table lists all the data types supported by the CodeVisionAVR C compiler, their range of possible values and their size:

Type Size (Bits) Range
bit 1 0 , 1
char 8 -128 to 127
unsigned char 8 0 to 255
signed char 8 -128 to 127
int 16 -32768 to 32767
short int 16 -32768 to 32767
unsigned int 16 0 to 65535
signed int 16 -32768 to 32767
long int 32 -2147483648 to 2147483647
unsigned long int 32 0 to 4294967295
signed long int 32 -2147483648 to 2147483647
float 32 +- 1.175e-38 to +- 3.402e38
double 32 +- 1.175e-38 to +- 3.402e38

The bit data type is supported only for global variables.

If the Project|Configure|C Compiler|Code Generation|char is unsigned option is checked or #pragma uchar+ is used, then char has by default the range 0..255.

========================================
在CVAVR的使用说明中给出了 float 和 double 的范围,他们是一样的,如同int 和 short int  

在icc里也是一样。

也就是说avr好几款编译器都是将float和double定义成了4字节。而且精度也一样。所以gcc和winavr也许是最好的。

出0入0汤圆

发表于 2009-8-21 08:27:17 | 显示全部楼层
IAR double可选64位。

出0入0汤圆

发表于 2009-8-29 11:44:55 | 显示全部楼层
哦,double,不知道一个片子能经得起double几下。

出0入0汤圆

发表于 2010-3-2 17:05:23 | 显示全部楼层
mark

出0入0汤圆

发表于 2013-3-24 11:53:18 | 显示全部楼层
mark  doubel 类似运算还是换成 32位的吧

出0入0汤圆

发表于 2013-6-2 23:09:09 | 显示全部楼层
数据宽度不过是一个定义罢了,再多位数对单片机的大多数应用来说只能造成性能下降。如果某应用有需要更宽的位数,只要单片机够快,可以写一个函数解决。

出0入0汤圆

发表于 2019-7-15 16:36:49 | 显示全部楼层
看看,我也碰到此问题了
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-4-26 08:07

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表