Recent

Author Topic: Real types  (Read 597 times)

julkas

  • Hero Member
  • *****
  • Posts: 525
  • KISS principle / Lazarus 2.0.6 / FPC 3.0.4
Real types
« on: January 15, 2020, 10:25:49 am »
Any plans to implement real types for AVR target?
procedure mulu64(a, b: QWORD; out clo, chi: QWORD); assembler;
asm
  mov rax, a
  mov rdx, b
  mul rdx
  mov [clo], rax
  mov [chi], rdx
end;

ccrause

  • Full Member
  • ***
  • Posts: 226
Re: Real types
« Reply #1 on: January 15, 2020, 01:18:25 pm »
Any plans to implement real types for AVR target?
I guess it is not a high priority.  To check what is/isn't working try to compile softfpu.pp for AVR.

Dimitrios Chr. Ioannidis

  • Jr. Member
  • **
  • Posts: 90
    • Nephelae
Re: Real types
« Reply #2 on: January 15, 2020, 01:35:43 pm »
Hi,

Any plans to implement real types for AVR target?

You can read the responses I got at the devel list with the same question back at 2018 ...

"Problem is: the compiler throws internal errors on the softfpu unit. The code is really complex (a lot of 64 bit operations) and the register allocator cannot cope with this."

 One can hope that some day will have real types for avr also ...

regards,
 
« Last Edit: January 15, 2020, 01:40:24 pm by Dimitrios Chr. Ioannidis »
Dimitrios Chr. Ioannidis
http://www.nephelae.eu

Thaddy

  • Hero Member
  • *****
  • Posts: 9449
Re: Real types
« Reply #3 on: January 15, 2020, 01:36:26 pm »
Any plans to implement real types for AVR target?
You mean float types?
Real is a distinct Pascal type, unlike C. Do not confuse the two.
The code that ccrause mentions works depending on bitness (e.g. comment out anything above the bitness of your particular AVR)
also related to equus asinus.

Thaddy

  • Hero Member
  • *****
  • Posts: 9449
Re: Real types
« Reply #4 on: January 15, 2020, 01:38:31 pm »
"Problem is: the compiler throws internal errors on the softfpu unit. The code is really complex (a lot of 64 bit operations) and the register allocator cannot cope with this."
No, the problem is over-asking. 8 bit always works. Takes some commenting, not programming.
also related to equus asinus.

Dimitrios Chr. Ioannidis

  • Jr. Member
  • **
  • Posts: 90
    • Nephelae
Re: Real types
« Reply #5 on: January 15, 2020, 01:41:38 pm »
"Problem is: the compiler throws internal errors on the softfpu unit. The code is really complex (a lot of 64 bit operations) and the register allocator cannot cope with this."
No, the problem is over-asking. 8 bit always works. Takes some commenting, not programming.

This was Florian's response Thaddy, not mine.
Dimitrios Chr. Ioannidis
http://www.nephelae.eu

Thaddy

  • Hero Member
  • *****
  • Posts: 9449
Re: Real types
« Reply #6 on: January 15, 2020, 01:49:38 pm »
Simply rip out anything over 32 bit and create your own unit (rename it).
also related to equus asinus.

Laksen

  • Hero Member
  • *****
  • Posts: 637
    • J-Software
Re: Real types
« Reply #7 on: January 15, 2020, 02:45:17 pm »
I can assure you that noone is planning not to support floating point on AVR  :P

Really just comes down to understanding exactly why the register allocator behaves as it does

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 7863
Re: Real types
« Reply #8 on: January 15, 2020, 02:55:34 pm »
Hi,

Any plans to implement real types for AVR target?

You can read the responses I got at the devel list with the same question back at 2018 ...

"Problem is: the compiler throws internal errors on the softfpu unit. The code is really complex (a lot of 64 bit operations) and the register allocator cannot cope with this."

Hmm, to start I'd go for single, not double :-)


avra

  • Hero Member
  • *****
  • Posts: 1759
    • Additional info
Re: Real types
« Reply #9 on: January 15, 2020, 03:06:20 pm »
In case you can't wait then you can try fixed point numbers.
https://forum.lazarus.freepascal.org/index.php/topic,15895.0.html
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

julkas

  • Hero Member
  • *****
  • Posts: 525
  • KISS principle / Lazarus 2.0.6 / FPC 3.0.4
Re: Real types
« Reply #10 on: January 15, 2020, 03:36:23 pm »
procedure mulu64(a, b: QWORD; out clo, chi: QWORD); assembler;
asm
  mov rax, a
  mov rdx, b
  mul rdx
  mov [clo], rax
  mov [chi], rdx
end;

julkas

  • Hero Member
  • *****
  • Posts: 525
  • KISS principle / Lazarus 2.0.6 / FPC 3.0.4
Re: Real types
« Reply #11 on: January 15, 2020, 08:29:55 pm »
Any plans to implement real types for AVR target?
I guess it is not a high priority.  To check what is/isn't working try to compile softfpu.pp for AVR.
Ok what is a high priority for embedded target?
procedure mulu64(a, b: QWORD; out clo, chi: QWORD); assembler;
asm
  mov rax, a
  mov rdx, b
  mul rdx
  mov [clo], rax
  mov [chi], rdx
end;

Thaddy

  • Hero Member
  • *****
  • Posts: 9449
Re: Real types
« Reply #12 on: January 15, 2020, 08:39:06 pm »
Floats will be very, very slow on the real hardware starved embedded systems like the 3 cents chips mentioned here and fixed point arithmetic would suffice.
Some seem to have expectations that anything can be ported to any system. While this is true - they are after all Turing complete - the result would be unworkable.
« Last Edit: January 15, 2020, 08:41:10 pm by Thaddy »
also related to equus asinus.

Dimitrios Chr. Ioannidis

  • Jr. Member
  • **
  • Posts: 90
    • Nephelae
Re: Real types
« Reply #13 on: January 15, 2020, 09:03:05 pm »
Hi,

Floats will be very, very slow on the real hardware starved embedded systems like the 3 cents chips mentioned here and fixed point arithmetic would suffice.

  I don't think so . Look at the results of those relative recent tests ( 2018 ) using the "old" atmega328p with avr-gcc :

Code: Text  [Select]
  1.  
  2.  
  3. 250ns  Null
  4.   310ns  add((uint8_t)123, (uint8_t)222)
  5.   500ns  add( 12345, 5678)
  6.  1000ns  add(13456L, 7891011L)
  7.  9300ns  add((float)123456.0, (float)7891011.0)
  8.  
  9.   500ns  mult((uint8_t)123, (uint8_t)222)
  10.  1060ns  mult( 12345, 5678)
  11.  5300ns  mult(13456L, 7891011L)
  12.  8300ns  mult((float)123456.0, (float)7891011.0)
  13.  
  14.  5200ns  divi((uint8_t)123, (uint8_t)222)
  15. 13800ns  divi( 12345, 5678)
  16. 37200ns  divi(13456L, 7891011L)
  17. 29200ns  divi((float)123456.0, (float)7891011.0)

Some seem to have expectations that anything can be ported to any system. While this is true - they are after all Turing complete - the result would be unworkable.

OTOH, if anyone here advocate for something like Linux on an 8-bit micro? then I totally and fully agree with you .... ( fun fact: in this site the author writes: " ....  It takes about 2 hours to boot to bash prompt ("init=/bin/bash" kernel command line). Then 4 more hours to boot up the entire Ubuntu ("exec init" and then login). ... " ...  %) :o )

regards,
Dimitrios Chr. Ioannidis
http://www.nephelae.eu

Thaddy

  • Hero Member
  • *****
  • Posts: 9449
Re: Real types
« Reply #14 on: January 15, 2020, 09:11:34 pm »
That were the points I actually made.... :P
also related to equus asinus.