Trig in PropellerForth
Among many other nice features, the Parallax Propeller microcontroller has a single-quadrant sine table in ROM. This makes implementing sine and cosine fast and simple, for medium-precision (13-bit) work.
Here's a simple port of Parallax's routines to PropellerForth.
With PropellerForth v8.05 this gives a runtime of 1088-1152 cycles for
It can be made slightly faster by (1) replacing the numbers with CONSTANTs and (2) inlining 2*, which is not a primitive, as "1 lshift", for a runtime of 993-1056 cycles -- 28x slower than native, at the cost of a 22 more bytes of space.
Update: Huh. Through some optimizations to the kernel, I can shave off another 100 cycles -- for a runtime of 896-926 cycles. However, it costs 248 bytes in the kernel, and eliminates a hook I was hoping to use for single-step and breakpoints. I'll have to weigh this.
Here's a simple port of Parallax's routines to PropellerForth.
hex
\ Address of table in ROM
E000 constant sin-base
\ Computes the sign of an angle.
\ The angle is a 13-bit number (0x1FFF = almost 360 degrees).
\ The result is a 16.16 fixed-point signed integer.
: sin ( angle13 -- n16_16 )
dup 1000 and >R \ Stash a flag for Quadr.3/4 onto the rstack
dup 0800 and if negate then \ Invert angle for Quadr.2/4
2* sin-base or H@ \ Compute word address and fetch
R> if negate then ; \ Negate result for Quadr.3/4
: cos ( angle13 -- n16_16 ) 0800 + sin ;
With PropellerForth v8.05 this gives a runtime of 1088-1152 cycles for
sin
, and an additional 240 cycles for cos
-- 31x slower than a native implementation. (v8.02 will be slower.) It can be made slightly faster by (1) replacing the numbers with CONSTANTs and (2) inlining 2*, which is not a primitive, as "1 lshift", for a runtime of 993-1056 cycles -- 28x slower than native, at the cost of a 22 more bytes of space.
Update: Huh. Through some optimizations to the kernel, I can shave off another 100 cycles -- for a runtime of 896-926 cycles. However, it costs 248 bytes in the kernel, and eliminates a hook I was hoping to use for single-step and breakpoints. I'll have to weigh this.
Labels: propellerforth
6 Comments:
Cliff,
How about releasing the 8.05 version?
Ron
By HighJump, at 12:55 PM
Ron,
Hoping to! :-) Been awfully busy with the day job lately, I've only got back to working on PropellerForth in the past couple weeks.
Most users won't notice much difference in 8.05; there are a few fixes and several primitives are faster, but that's about it.
By Cliff L. Biffle, at 7:50 PM
This article is very helpfull. I was looking for this info and it will help me on my business. thanks a lot
Hadoop Training Institute in Noida
By ciitnoida, at 12:26 AM
Hello! What an interesting post with lots of useful information. By the way, if you need some writing help then you can apply to the essay writing service and find there even world food problems essay help and many other options.
By Ciana Langham, at 12:27 AM
I'm sharing this to all Real Cash Rummy Game Lovers.
Experience the fun & excitement of playing classical Indian rummy online & win cash prizes. Download the rummy app and Start playing real rummy cash games on your mobile anywhere any time. India's No.1 Rummy Site. Please check the website for more real-time promotions & best offers. how to play rummy, also know about the different variants of the Game.
By Anonymous, at 4:44 AM
Casino Resort, Las Vegas - Mapyro
Casino Resort in Las Vegas is 충청북도 출장마사지 an 서귀포 출장마사지 MGM Resorts Luxury Destination with 경상남도 출장마사지 2,527 guest rooms and 서울특별 출장샵 suites, making it the perfect choice for 인천광역 출장마사지 travelers seeking an
By vardhamantabron, at 4:01 PM
Post a Comment
<< Home