Login
Username:

Password:

Remember me



Lost Password?

Register now!

Sections

Who's Online
87 user(s) are online (55 user(s) are browsing Forums)

Members: 0
Guests: 87

more...

Headlines

 
  Register To Post  

(1) 2 »
UDivMod32 ?
Home away from home
Home away from home


See User information
Did utility.library on aos4 have UDivMod32() function as it was in older utility.libraryes ?

I didn't find it in aos4 autodocs, but i find a notes about this in:

SDK:include/include_h/pragmas/utility_pragmas.h
SDK:include/include_h/inline/utility.h
SDK:include/include_h/clib/utility_protos.h

So questions is:

1). Why it disappear from utility.library autodocs
2). Is it available only for clib2, but not for newlib ?
3). How to compile/link such example on os4:

#include <proto/intuition.h>

main()
{
     
ULONG aa;
     
aa=UDivMod32(var1,var2);
}


As it "simply" divide, then maybe something like this should be fine enough:

main()
{
       
ULONG aa;
       
aa= (ULONG) (var1 var2);
}


?

4). What faster will be: ulong + / from gcc, or UDivMod32 itself when avail ? I assume UDivMod32 can be faster for os3, as it can be done on asm in utility.library, or speed is the same and i can safely replace it everythere ?

Join us to improve dopus5!
AmigaOS4 on youtube
Go to top
Re: UDivMod32 ?
Home away from home
Home away from home


See User information
Remainder = UDivMod32( Dividend, Divisor );

some thing like:

Remainder = Dividend % Divisor ;

I guess it's due to lack of FPU on MC680X0.


#ifdef __AmigaOS4__
#define UDivMod32( Dividend, Divisor ) Dividend % Divisor
#endif

(NutsAboutAmiga)

Basilisk II for AmigaOS4
AmigaInputAnywhere
Excalibur
and other tools and apps.
Go to top
Re: UDivMod32 ?
Home away from home
Home away from home


See User information
@LiveForIt

But 68k gcc for example understand pretty well "/", so i can compile it like:

Quote:

quotient = (ULONG)(num / div);


Is then there any point to use UDivMod32 at all for 68k ? I assume GCC will carry about it even if no FPU present ? So question still valid, what way will be faster, UDivMod32 or gcc-divide ?

Join us to improve dopus5!
AmigaOS4 on youtube
Go to top
Re: UDivMod32 ?
Home away from home
Home away from home


See User information
Quote:
As it "simply" divide, then maybe something like this should be fine enough:


no mod and div is not the same.


Resized Image

/ (div) gives you have many whole you have, while % (mod) gives you the fraction of the divider.

(NutsAboutAmiga)

Basilisk II for AmigaOS4
AmigaInputAnywhere
Excalibur
and other tools and apps.
Go to top
Re: UDivMod32 ?
Home away from home
Home away from home


See User information
@LiveForIt

What about those ones: UMult32() and SDivMod32() ? I currently have it like:

Quote:

#define UDivMod32(x,y) x % y // UDivMod32() replacement (so on os3 it still be used as it)
#define UMult32(x,y) x * y // UMult32() replacement (so on os3 it still be used)
#define SDivMod32 ??


UDivMod32 is unsigned, SDivMod32 is signed, so need to care about it in #define as well

Quote:

/ (div) gives you have many whole you have, while % (mod) gives you the fraction of the divider.


Right, old utility autodoc says:
Quote:

UDivMod32 -- unsigned 32 by 32 bit division and modulus


Join us to improve dopus5!
AmigaOS4 on youtube
Go to top
Re: UDivMod32 ?
Home away from home
Home away from home


See User information
Mod = modulus

U is unsigned, S is signed.

The same macro will work on both, if you won't be 100% correct you put some casting in there.

(NutsAboutAmiga)

Basilisk II for AmigaOS4
AmigaInputAnywhere
Excalibur
and other tools and apps.
Go to top
Re: UDivMod32 ?
Home away from home
Home away from home


See User information
@LiveForIT
Yep, i do it like:

#ifdef __amigaos4__
#define UDivMod32(x,y)( (ULONG) x % (ULONG) y ) // UDivMod32() replacement (so on os3 it still be used as it)
#define SDivMod32(x,y) ( (LONG) x % (LONG) y )  // SDivMode32() replacement (so on os3 it still be used)
#define UMult32(x,y) ( (ULONG) x * (ULONG) y )  // UMult32() replacement (so on os3 it still be used)
#endif


Thanks

Join us to improve dopus5!
AmigaOS4 on youtube
Go to top
Re: UDivMod32 ?
Home away from home
Home away from home


See User information
http://amigadev.elowar.com/read/ADCD_ ... cs_3._guide/node05AD.html

It looks like it uses D0 and D1 as result

RESULTS
D0 quotient - signed 32 quotient of the division.
D1 remainder - signed 32 remainder of the division.

(NutsAboutAmiga)

Basilisk II for AmigaOS4
AmigaInputAnywhere
Excalibur
and other tools and apps.
Go to top
Re: UDivMod32 ?
Home away from home
Home away from home


See User information
Quote:

It looks like it uses D0 and D1 as result


In the code SDivMod32 uses like this:

short line,x,y;

x=input->gpi_Mouse.X+gadget->LeftEdge;
y=input->gpi_Mouse.Y+gadget->TopEdge;

..
some more fun games with x,and then:

line=SDivMod32(y-data->text_dims.Top,data->text_height);


Join us to improve dopus5!
AmigaOS4 on youtube
Go to top
Re: UDivMod32 ?
Home away from home
Home away from home


See User information
I think it's the line number calculation so it should be divided not modulus.

(NutsAboutAmiga)

Basilisk II for AmigaOS4
AmigaInputAnywhere
Excalibur
and other tools and apps.
Go to top
Re: UDivMod32 ?
Home away from home
Home away from home


See User information
But autodoc cleary says "division and modulus". Just signed, not unsigned

Join us to improve dopus5!
AmigaOS4 on youtube
Go to top
Re: UDivMod32 ?
Home away from home
Home away from home


See User information
unsigned int32 reg68k[16];

#define getreg(r) reg68k[r]

unsigned int32 UDivMod32( unsigned int32 Dividend, unsigned int32 Divisor )
{
reg68k[1] = (unsigned int32) Dividend % Divisor;
reg68k[0] = (unsigned int32) Dividend / Divisor;
return reg68k[0];
}

singned int32 SDivMod32( singed int32 Dividend, signed int32 Divisor )
{
reg68k[1] = (unsigned int32) Dividend % Divisor;
reg68k[0] = (unsigned int32) Dividend / Divisor;
return (singned int32) reg68k[0];
}

(NutsAboutAmiga)

Basilisk II for AmigaOS4
AmigaInputAnywhere
Excalibur
and other tools and apps.
Go to top
Re: UDivMod32 ?
Home away from home
Home away from home


See User information
@LiveForIt

Why there "#define getreg(r) reg68k[r]" if getreg() never used ?

Join us to improve dopus5!
AmigaOS4 on youtube
Go to top
Re: UDivMod32 ?
Home away from home
Home away from home


See User information

(NutsAboutAmiga)

Basilisk II for AmigaOS4
AmigaInputAnywhere
Excalibur
and other tools and apps.
Go to top
Re: UDivMod32 ?
Home away from home
Home away from home


See User information
@Kas1e

if getreg is not used then, you can use simple macros, if get reg is used you need to emulate registers, and support Modula.

(NutsAboutAmiga)

Basilisk II for AmigaOS4
AmigaInputAnywhere
Excalibur
and other tools and apps.
Go to top
Re: UDivMod32 ?
Home away from home
Home away from home


See User information
@liveforit
Still dont get it :)
I mean you do:

#define getreg(r) reg68k[r]

But you never user getreg. I.e. your define is define for getreg. Maybe you mean #define reg68k[r] getreg(r) ? Then getreg is SASC only function, which we need to avoid as well.

Or you just copy+paste that snipped from some place ?

Quote:

if get reg is used you need to emulate registers, and support Modula.


? Modula ? Why i need to worry about Modula, if its all about GCC only? :) Need fully working GCC replacement, without involving sasc-specific parts, pure cross-platform gcc.

Join us to improve dopus5!
AmigaOS4 on youtube
Go to top
Re: UDivMod32 ?
Home away from home
Home away from home


See User information
Or else you might do a version that returns a struct.

Struct {
uint32 div;
Uint32 mod;
} UDivMod;

Struct UDivMod _UDivMod32_( unsigned int32 Dividend, unsigned int32 Divisor )
{
Struct UDivMod ret;
ret.div= (unsigned int32) Dividend / Divisor;
ret.mod= (unsigned int32) Dividend % Divisor;
return ret;
}

(NutsAboutAmiga)

Basilisk II for AmigaOS4
AmigaInputAnywhere
Excalibur
and other tools and apps.
Go to top
Re: UDivMod32 ?
Home away from home
Home away from home


See User information
Quote:

Or else you might do a version that returns a struct.


No main code changes should be done in , should be just 1:1 and 100% replacements which do and return the same as old os3 originals. Currently i just do it like:

Quote:

#define UDivMod32(x,y)( (ULONG) x % (ULONG) y ) // UDivMod32() replacement (so on os3 it still be used as it)
#define SDivMod32(x,y) ( (LONG) x % (LONG) y ) // SDivMod32() replacement (so on os3 it still be used)
#define UMult32(x,y) ( (ULONG) x * (ULONG) y ) // UMult32() replacement (so on os3 it still be used)

Join us to improve dopus5!
AmigaOS4 on youtube
Go to top
Re: UDivMod32 ?
Home away from home
Home away from home


See User information
Kas1e

These are 68k function for use in assembler only (multiple return registers) (possible there may be compiler spscific glue to us them with C but not needed)

in clibrary code the clibrary has it's own equivalents "/" and "%" replace all usages of them if you want portable code

End of story


Go to top
Re: UDivMod32 ?
Home away from home
Home away from home


See User information
@Andy
Right, already done it like this then.

ps. what is strange, its why we still references to them in os4 sdk (pretty a lot should to say).

Join us to improve dopus5!
AmigaOS4 on youtube
Go to top

  Register To Post
(1) 2 »

 




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




Powered by XOOPS 2.0 © 2001-2023 The XOOPS Project