English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Asm / Hardware

 
 
Thread Tools
Old 18 February 2024, 00:06   #1
earok
Registered User
 
Join Date: Dec 2013
Location: Auckland
Posts: 3,543
Efficient way of converting longword -> string

Mostly interested to see what opinions are about converting longwords to strings, I'll need to roll my own implementation for Scorpion sooner or later but I haven't decided on the exact approach.


JOTD shared code here that converts a long word to a string using DIVU #10 (including handling for longwords that have a number too large to fit into a word even after a divide by 10).

https://stackoverflow.com/questions/...umber-to-ascii

The code that's part of Amiblitz approaches the issue a different way that doesn't use DIVU at all - rather it uses a lookup table that contains values of a power of 10, and subtracts until the base value is smaller than the number in that row of the lookup table.

https://github.com/AmiBlitz/AmiBlitz...ntlib.ab3#L969




Edit: I wonder if the second approach could be improved to use a pre-rolled loop for each power of 10 value rather than a lookup table

Last edited by earok; 18 February 2024 at 00:45.
earok is offline  
Old 18 February 2024, 03:18   #2
a/b
Registered User
 
Join Date: Jun 2016
Location: europe
Posts: 1,043
I typically use a simple 10^n table approch with extra options like variable length output, leading space/zero/no padding. Getting rid of divs is fast enough, and then size takes priority (short and simple all-in-one).
If your main concern is speed, might as well consider binary subdivision (e.g. 5x, 2/3x, unrolled 1x until a match) and multiple tables. Maybe also first check if the number is 16-bit and skip to 10000 units if so.
a/b is offline  
Old 18 February 2024, 06:36   #3
earok
Registered User
 
Join Date: Dec 2013
Location: Auckland
Posts: 3,543
Cheeers

I ended up something like this for now, no divs, no lookup tables. It seems pretty good but I'll think about optimising it further over time.

From digits 9-5, use a loop to subtract the base value. (for example, for digit 9, subtract 100000000 until the base value is less than that).

Then copy the long word into a word, and repeat the above for digits 4-2

Finally, since the value on the last digit is guaranteed to be less than 10, just copy that value directly.
earok is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
Arexx > Converting files > Multiple steps > Geordie-Jedi Coders. Scripting 0 06 December 2023 23:26
Arexx > Converting files > Multiple steps > Geordie-Jedi support.Other 3 25 November 2023 17:07
Stretch bit in word into longword KONEY Coders. Asm / Hardware 18 09 December 2019 14:51
Vbcc on Win: Flag <-o> needs string guy lateur Coders. C/C++ 15 19 July 2017 20:31
Questions re: Efficient blitting earok Coders. Blitz Basic 11 01 January 2017 06:41

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 05:39.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.06580 seconds with 15 queries