Tags:
view all tags
%DASHBOARD{ section="dashboard_start" }% %DASHBOARD{ section="banner" image="%PUBURLPATH%/Cosmac/ForthSTM32WB/nucleo-header.jpg" title="Floating Point Unit (FPU)" titlestyle="color:#F00000;" }% %DASHBOARD{ section="box_start" title="Intro" width="485" height="300"}% ---+ Why Floating Point? Forth systems traditionally make use of cooperative multitasking. It is very simple and clever. But it has its limits. If you write all your software by yourself, each software part can be cooperative. But if you want to benefit from middleware written by somebody else (and most probably not written in Forth), you can be sure that software is not cooperative (in the context of multitasking). Forth wants to rule your system. I would like to have a Forth system that is cooperative. It should extend the system, to make it interactive and easy to use. The Forth interpreter (called terminal task in Forth jargon) itself is only a thread and can be used as some sort of CLI for testing purposes or could be the main part of the application. %DASHBOARD{ section="box_end" }% %DASHBOARD{ section="box_start" title="Contents" width="460" height="300"}% %TOC% %DASHBOARD{ section="box_end" }% %DASHBOARD{ section="box_start" width="992" height="800" }% ---+ Forth Multitasking Andrew Haley wrote "Forth has been multi-tasking for almost 50 years. It's time to standardize it" and he is right. I will implement his proposed API for Mecrisp-Cube described in [[http://www.complang.tuwien.ac.at/anton/euroforth/ef17/papers/haley-slides.pdf][A multi-tasking wordset for Standard Forth]]. The multitasker wordset is very similar to the one in !SwiftForth / !PolyForth. I use the term task here because it is well known in the Forth world, although Mecrisp-Cube make use of threads. Mecrisp-Cube tasks are CMSIS-RTOS threads with user variables. The Mecrisp-Cube (CMSIS-RTOS / !FreeRTOS) scheduler is pre-emptive and not round robin (cooperative). Mecrisp-Cube is always multi tasked, you can not switch off the scheduler and therefore there is no =MULTI=, =SINGLE=, or =INIT-MULTI=. ---+ Floating Point Unit * [[https://mecrisp-stellaris-folkdoc.sourceforge.io/fixed-point.html][Fixed Point]] * https://www.complang.tuwien.ac.at/forth/gforth/Docs-html/Number-Conversion.html#Number-Conversion * https://www.complang.tuwien.ac.at/forth/gforth/Docs-html/Floating-Point.html#Floating-Point * https://forth-standard.org/standard/float * https://forth-standard.org/proposals/recognizer#contribution-142 * https://de.wikipedia.org/wiki/IEEE_754 * https://interrupt.memfault.com/blog/cortex-m-rtos-context-switching ARM Cortex-M RTOS Context Switching * printf("%f", myFloat) f. fe. fs. * atof() oder strtof() benutzen? * nur single-precision? (7..8 Dezimalstellen, H7 hat double precision FPU) * kein eigener Stack * >float wo? * float register mit mutex absichern? * float.fs in source integrieren? * auf float in ISR verzichten * _FPU_USED * AN4044 Application note, Foating point unit demonstration on STM32 microcontrollers * math.h e.g. float cosf (float) =>float= in Gforth engine/support.c verwendet =strtod()= (=strtof()= for single precision) <verbatim> Cell to_float(Char *c_addr, UCell u, Float *rp) { /* convertible string := <significand>[<exponent>] <significand> := [<sign>]{<digits>[.<digits0>] | .<digits> } <exponent> := <marker><digits0> <marker> := {<e-form> | <sign-form>} <e-form> := <e-char>[<sign-form>] <sign-form> := { + | - } <e-char> := { D | d | E | e } */ Char *s = c_addr; Char c; Char *send = c_addr+u; UCell ndigits = 0; UCell ndots = 0; UCell edigits = 0; char cnum[u+3]; /* append at most "e0\0" */ char *t=cnum; char *endconv; Float r; if (s >= send) /* treat empty string as 0e */ goto return0; switch ((c=*s)) { case ' ': /* "A string of blanks should be treated as a special case representing zero."*/ for (s++; s<send; ) if (*s++ != ' ') goto error; goto return0; case '-': case '+': *t++ = c; s++; goto aftersign; } aftersign: if (s >= send) goto exponent; switch (c=*s) { case '0' ... '9': *t++ = c; ndigits++; s++; goto aftersign; case '.': *t++ = c; ndots++; s++; goto aftersign; default: goto exponent; } exponent: if (ndigits < 1 || ndots > 1) goto error; *t++ = 'E'; if (s >= send) goto done; switch (c=*s) { case 'D': case 'd': case 'E': case 'e': s++; break; } if (s >= send) goto done; switch (c=*s) { case '+': case '-': *t++ = c; s++; break; } edigits0: if (s >= send) goto done; switch (c=*s) { case '0' ... '9': *t++ = c; s++; edigits++; goto edigits0; default: goto error; } done: if (edigits == 0) *t++ = '0'; *t++ = '\0'; assert(t-cnum <= u+3); r = strtod(cnum, &endconv); assert(*endconv == '\0'); *rp = r; return -1; return0: *rp = 0.0; return -1; error: *rp = 0.0; return 0; } #endif </verbatim> %DASHBOARD{ section="box_end" }% %DASHBOARD{ section="box_start" width="992" height="600" }% ---+ Floating Point Words <pre> f+ ( r1 r2 -- r3 ) Add r1 to r2 giving the sum r3. f- ( r1 r2 -- r3 ) Subtract r2 from r1, giving r3. f* ( r1 r2 -- r3 ) Multiply r1 by r2 giving r3. f/ ( r1 r2 -- r3 ) Divide r1 by r2, giving the quotient r3. fsqrt ( r1 -- r2 ) r2 is the square root of r1. fabs ( r1 -- r2 ) r2 is the absolute value of r1. fnegate ( r1 -- r2 ) r2 is the negation of r1. f>s ( r -- n ) n is the single-cell signed-integer equivalent of the integer portion of r. s>f ( n -- r ) r is the floating-point equivalent of the single-cell value n. f>fx ( r -- d ) d is the fixed-point equivalent of the floating-point r fx>f ( d -- r ) r is the floating-point equivalent of the fixed-point d. f. ( r -- ) Display, with a trailing space, the top number using fixed-point notation: </pre> ---++ C Math Library %DASHBOARD{ section="box_end" }% %DASHBOARD{ section="dashboard_end" }% -- %USERSIG{PeterSchmid - 2022-11-01}% <a rel="license" href="http://creativecommons.org/licenses/by-sa/4.0/"><img alt="Creative Commons License" style="border-width:0" src="https://i.creativecommons.org/l/by-sa/4.0/88x31.png" /></a><br />This work by <a xmlns:cc="http://creativecommons.org/ns#" href="http://spyr.ch" property="cc:attributionName" rel="cc:attributionURL">Peter Schmid</a> is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-sa/4.0/">Creative Commons Attribution-ShareAlike 4.0 International License</a>.
Edit
|
Attach
|
Watch
|
P
rint version
|
H
istory
:
r44
|
r12
<
r11
<
r10
<
r9
|
B
acklinks
|
V
iew topic
|
Raw edit
|
More topic actions...
Topic revision: r10 - 2022-11-01
-
PeterSchmid
Home
Site map
Cosmac web
MRR web
MecrispCube web
SuperRandonnee web
TWiki web
Ursula web
Velo web
MecrispCube Web
Create New Topic
Index
Search
Changes
Notifications
RSS Feed
Statistics
Preferences
View
Raw View
Print version
Find backlinks
History
More topic actions
Edit
Raw edit
Attach file or image
Edit topic preference settings
Set new parent
More topic actions
Account
Log In
Edit
Attach
Copyright © 2008-2025 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki?
Send feedback