Welcome, Guest. Please login or register.
Amiga Kit Amiga Store Iridium Banner AMIStore App Store A1200/A600 4xIDE Interface

AuthorTopic: 64 bit integers in SAS/C  (Read 5141 times)

0 Members and 1 Guest are viewing this topic.

Offline nOw2

64 bit integers in SAS/C
« on: July 21, 2013, 01:46:35 PM »
What's the best way to handle large numbers in SAS/C?

I want to calculate disk space for >4GB partitions. 64 bit would be ideal, but 48bit would work for now. Possibly also need to pass the numbers through library calls too, but that's a secondary issue.
 

Offline Thomas

Re: 64 bit integers in SAS/C
« Reply #1 on: July 21, 2013, 02:55:20 PM »
To get the size in megabytes you can divide the number of blocks on the disk by the number of blocks per megabyte. This way all numbers fit into 32 bits.

Offline nicholas

Re: 64 bit integers in SAS/C
« Reply #2 on: July 21, 2013, 04:50:06 PM »
I'm not 100% certain but I've got a vague recollection that the update from 6.58 to 7.01 introduced better large number handling.  I could be wrong though as it's been a long time since I used it.

http://aminet.net/package/biz/patch/expsascxx

I've just read the readme and it doesn't mention it so I must have remembered wrongly.

Can't hurt to try though. ;)
“Een rezhim-i eshghalgar-i Quds bayad az sahneh-i ruzgar mahv shaved.” - Imam Ayatollah Sayyed  Ruhollah Khomeini
 

Offline pjhutch

  • Sr. Member
  • ****
  • Join Date: Mar 2002
  • Posts: 452
  • Country: england
  • Total likes: 1
  • Gender: Male
  • Amiga user and developer
    • http://www.pjhutchison.org
Re: 64 bit integers in SAS/C
« Reply #3 on: July 21, 2013, 06:33:11 PM »
The Amiga utility.library for AmigaOS 3.9 comes with 64 bit functions:
SMult64, UMult64

I have not seen anything in the SAS/C about 64 bit functions.
 

Offline Thorham

Re: 64 bit integers in SAS/C
« Reply #4 on: July 21, 2013, 07:05:22 PM »
Why bother? Thomas' solution works fine.
 

Offline psxphill

Re: 64 bit integers in SAS/C
« Reply #5 on: July 21, 2013, 08:11:06 PM »
Quote from: nicholas;741476
I'm not 100% certain but I've got a vague recollection that the update from 6.58 to 7.01 introduced better large number handling. I could be wrong though as it's been a long time since I used it.
 
http://aminet.net/package/biz/patch/expsascxx
 
I've just read the readme and it doesn't mention it so I must have remembered wrongly.
 
Can't hurt to try though. ;)

http://support.sas.com/documentation/onlinedoc/sasc/doc750/html/changes/zgenid-5.htm
 
long long
 

Offline nOw2

Re: 64 bit integers in SAS/C
« Reply #6 on: July 21, 2013, 08:53:36 PM »
The value needs to be passed around in bytes (to support existing code and also importantly maintain resolution), it's not just the issue of reading the size from disk. Though that does the question of doing that - I'd want to maintain accuracy so would need the true size of disks/files rather than the more granular block sizes.

I'm not confident of patching the compiler with experimental code. SAS/C 6.5x is a restriction at the moment.

I'm thinking of using two longs to hold the data, even if that makes calculations interesting. UtilityBase functions may be suitable for that, otherwise I'll roll my own. This way existing code will continue to work as it does today (little-endian style) and new code can be adapted to see the higher bytes.

Then I need to work out how to write that as human readable - converting to display in MB/GB/TB I think should be okay as by that point the calculation will leave a single long suitable for sprintf, but starting to worry myself about how to get the large >2^32 byte values out in ASCII.
 

Offline itix

Re: 64 bit integers in SAS/C
« Reply #7 on: July 21, 2013, 09:11:49 PM »
Quote from: nOw2;741497

I'm thinking of using two longs to hold the data, even if that makes calculations interesting. UtilityBase functions may be suitable for that, otherwise I'll roll my own. This way existing code will continue to work as it does today (little-endian style) and new code can be adapted to see the higher bytes.


Create small structure with two longs and develop small framework around it to do 64-bit math and ToString() function to convert numbers to ASCII.
My Amigas: A500, Mac Mini and PowerBook
 

Offline nicholas

Re: 64 bit integers in SAS/C
« Reply #8 on: July 21, 2013, 09:30:44 PM »
Quote from: psxphill;741490
http://support.sas.com/documentation/onlinedoc/sasc/doc750/html/changes/zgenid-5.htm
 
long long


My memory isn't failing me as much as I thought then. :)
“Een rezhim-i eshghalgar-i Quds bayad az sahneh-i ruzgar mahv shaved.” - Imam Ayatollah Sayyed  Ruhollah Khomeini
 

Offline matthey

Re: 64 bit integers in SAS/C
« Reply #9 on: July 21, 2013, 10:06:55 PM »
Quote from: nOw2;741497

I'm not confident of patching the compiler with experimental code. SAS/C 6.5x is a restriction at the moment.


If you roll your own 64-bit int math functionality then it will also be experimental. If you don't want experimental then consider another compiler. I've found bugs in the 64-bit integer math of some versions of GCC 3.x. The latest version of vbcc has been accurate and is reasonably fast from what I've seen with 64-bit int. The next version out soon will have much faster 64x64=64 for the 68060 ;).

What does SAS/C support that you need?

Quote from: nOw2;741497

I'm thinking of using two longs to hold the data, even if that makes calculations interesting. UtilityBase functions may be suitable for that, otherwise I'll roll my own. This way existing code will continue to work as it does today (little-endian style) and new code can be adapted to see the higher bytes.


The utility.library only has partial 64-bit integer functions. A true 64x64=64 bit multiplication becomes easy with 32x32=64 help but there is not much help for 64/64=64 which is dead slow as there is no hardware help on any 68k processor. Addition and subtraction of full 64-bit numbers are easy enough but faster with hardware help that C does not provide. Logic operations are no problem and fast even with C.

Itix's suggestion can be done but you will be reinventing the wheel for a stoneage compiler. New compilers already have well oiled and nicely rounded 64-bit wheels.
 

Offline ChaosLord

Re: 64 bit integers in SAS/C
« Reply #10 on: July 22, 2013, 01:32:27 AM »
Quote from: nOw2;741497

I'm not confident of patching the compiler with experimental code. SAS/C 6.5x is a restriction at the moment.

The patch was created by the ppl who wrote SASC.  It isn't like some random haxx0r made it. :)

Also, once you realize that all C compilers are experimental and have weird rare bugs then you realize that everything is ok.

There are at least 2 bugs in SASC 6.58.  Perhaps these have been fixed in v7.x?  Who knows?


Quote

I'm thinking of using two longs to hold the data, even if that makes calculations interesting. UtilityBase functions may be suitable for that, otherwise I'll roll my own.



Yep you are always allowed to create your own new datatypes.  You can code them in C or asm since SASC interfaces to asm routines easily.
Wanna try a wonderfull strategy game with lots of handdrawn anims,
Magic Spells and Monsters, Incredible playability and lastability,
English speech, etc. Total Chaos AGA
 

Offline nicholas

Re: 64 bit integers in SAS/C
« Reply #11 on: July 22, 2013, 01:50:01 AM »
Quote from: nOw2;741497
I'm not confident of patching the compiler with experimental code. SAS/C 6.5x is a restriction at the moment.


Well if it makes you feel more comfortable, it's more stable than 6.58 was as I remember it. :)
“Een rezhim-i eshghalgar-i Quds bayad az sahneh-i ruzgar mahv shaved.” - Imam Ayatollah Sayyed  Ruhollah Khomeini
 

Offline olsen

Re: 64 bit integers in SAS/C
« Reply #12 on: July 22, 2013, 08:07:25 AM »
Quote from: nOw2;741465
What's the best way to handle large numbers in SAS/C?

I want to calculate disk space for >4GB partitions. 64 bit would be ideal, but 48bit would work for now. Possibly also need to pass the numbers through library calls too, but that's a secondary issue.


Have a look at the http://aminet.net/comm/tcp/SendRawDisk.lha utility which I wrote a while ago (full source code included). It includes both 64 bit arithmetic code written in portable 'C', as well a complete set of functions for accessing "large disks" (covering both NSD/TD64, with auto-detection of some sort which handles both sets transparently).

The purpose of this utility was to make it easier to transfer disk images from my Amiga to UAE. But if you're after the arithmetic functions, please by my guest :)

Multiplication and addition are rather straightforward. The division algorithm is a tricky one, though. Would you believe that there are several different division algorithms, some more readable than others?

If you're in dire need of arithmetic algorithms, I would hesitate to recommend Knuth's "The Art of Computer Programming: Seminumerical algorithms" (chapter 4). You have to master both the language in which the implementations are written, and make something useful out of the copious notes which accompany them. Many programmers work extra hard on solving problems on their own, rather than looking them up in the Knuth ;)
 

Offline ChaosLord

Re: 64 bit integers in SAS/C
« Reply #13 on: July 22, 2013, 08:33:13 AM »
Quote from: olsen;741551
Have a look at the http://aminet.net/comm/tcp/SendRawDisk.lha utility which I wrote a while ago (full source code included). It includes both 64 bit arithmetic code written in portable 'C', as well a complete set of functions for accessing "large disks" (covering both NSD/TD64, with auto-detection of some sort which handles both sets transparently).

Yeah!!!!!!!!!!!!!!!!!!!!!!  Olsen saves the day!!!!!!  :banana:


Quote

The purpose of this utility was to make it easier to transfer disk images from my Amiga to UAE. But if you're after the arithmetic functions, please by my guest :)

Multiplication and addition are rather straightforward. The division algorithm is a tricky one, though. Would you believe that there are several different division algorithms, some more readable than others?

If you're in dire need of arithmetic algorithms, I would hesitate to recommend Knuth's "The Art of Computer Programming: Seminumerical algorithms" (chapter 4). You have to master both the language in which the implementations are written, and make something useful out of the copious notes which accompany them. Many programmers work extra hard on solving problems on their own, rather than looking them up in the Knuth ;)


I have the 2nd edition of that book from 1981.  Is that good enough?
Have any new algorithms been invented since 1981?




@nOw2

I have not tested SASC v7.x yet.  I plan to test it sometime in a couple of weeks and I will compile giant piles of source codes thru it to see if it works or not.

I predict that 64-bit integers (long long) will work perfectly in SASC v7.x

I predict that any bugs will be in a few random routines in the C library where they forgot to add 64-bit support or somehow messed it up.  These library functions will be functions I have never used and never will use or I use them but will never use them with 64-bit integers.  For what you are trying to accomplish I think you will be safe and it would take you years to find a bug.

It took me something like 6 years to find a bug in SASC 6.58.  And I was using the compiler every single day and night and compiling giant programs with it.   Its not like I was just compiling a tiny 2000 line program on the weekends or something.  I was really banging SASC hard.  The bug I found can only be triggered by linking asm code (which gets inlined) that takes floating point parameters.  Although I have been doing some hardcore studying of Advanced C books lately and I have found that C wants to always promote all types to either into or double when calling functions.  So maybe I could have worked around the problem by using Doubles instead of Floats?  (The forced promotion is not supposed to happen when you use a concrete datatype.)


p.s. Feel free to post any discoveries or problems that you find both here and at www.AmigaCoding.de which is an entire giant forum specifically for Programming Amigas and is kinda like the reincarnation of UtilityBase (R.I.P.)
Wanna try a wonderfull strategy game with lots of handdrawn anims,
Magic Spells and Monsters, Incredible playability and lastability,
English speech, etc. Total Chaos AGA
 

Offline olsen

Re: 64 bit integers in SAS/C
« Reply #14 on: July 22, 2013, 09:48:16 AM »
Quote from: ChaosLord;741553
Yeah!!!!!!!!!!!!!!!!!!!!!!  Olsen saves the day!!!!!!  :banana:


Many of the problems which are still relevant were solved (or at least chipped away at) some 5-10 years ago. It's just getting harder to find the solutions. My own contribution is (correctly) filed away in the comm/tcp section of Aminet, but who'd look there for it?

It's challenging to build a good knowledge base for Amiga programming :(

Quote

I have the 2nd edition of that book from 1981.  Is that good enough?


I'm not the one to judge, but it appears that some algorithms covered in great depth and detail by Knuth have aged better than others. Also, Knuth selected the algorithms which he covered both for their importance and didactic reasons, which means that the books are not necessarily a "directory" of algorithms and the problems which they solve. For that kind of book, I'd recommend "The algorithm design manual" by Steven Skiena.

Quote

Have any new algorithms been invented since 1981?


Of course :)  For example, probabilistic algorithms (e.g. skip lists) were not invented until the late 1980'ies.