Welcome, Guest. Please login or register.
Amiga Kit Amiga Store Hollywood MAL AMIStore App Store A600 Memory

AuthorTopic: how to use timer.device's EClock unit's higher LONG  (Read 885 times)

0 Members and 1 Guest are viewing this topic.

Offline Jose

how to use timer.device's EClock unit's higher LONG
« on: May 10, 2005, 05:31:08 PM »
Hey. Does anyone knows how to use the EClockVal structure's (which is returned by ReadEClock()) ev_hi element ? The RKM Devices has an example but doesn't use the full 64 bit value (only uses ev_lo).
The goal is to calculate elapsed time whith good precision. And by the way, I suppose 64bits correspond to a way big amount of time, why use that instead of the VBlank unit for big intervals, since the RKM states that the VBlank unit can have higher precision then MicroHz or Eclock for big time intervals.

[EDIT] I meant the higher long not the higher byte.
\\"We made Amiga, they {bleep}ed it up\\"
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
  • Total likes: 0
    • http://www.iki.fi/sintonen/
Re: how to use timer.device's EClock unit's higher byte
« Reply #1 on: May 10, 2005, 05:33:42 PM »
Uh? Just use it?
 

Offline Jose

Re: how to use timer.device's EClock unit's higher byte
« Reply #2 on: May 10, 2005, 06:56:47 PM »
lol! yes... but if I subtract two ev_hi's and divide the result by the tics per second to obtain the fracctions of a second that passed between both readings do I have to multiply the result by a FFFF ? I'm just confused, first time I mess with doubles that.

[EDIT]
So maybe I just declare a double variable and assign it the result of each reading and the compiler will do the rest ?


[EDIT] I meant the higher long not the higher byte.
\\"We made Amiga, they {bleep}ed it up\\"
 

Offline Trev

Re: how to use timer.device's EClock unit's higher byte
« Reply #3 on: May 10, 2005, 07:24:22 PM »
This has Mac in the name, but it's all about 64-bit integer math on 68k.

http://www.mactech.com/articles/develop/issue_26/semchishen.html
 

Offline Jose

Re: how to use timer.device's EClock unit's higher byte
« Reply #4 on: May 10, 2005, 07:27:55 PM »
@Trev

Ahh, thanks.. just what I was needing. I was actually confused thinking that the returned 64bit value would be a double or something (I know a double is still probably needed to get the result of the division...). I'll now of course read it...
\\"We made Amiga, they {bleep}ed it up\\"
 

Offline Trev

Re: how to use timer.device's EClock unit's higher byte
« Reply #5 on: May 11, 2005, 12:56:45 AM »
No problem. I wouldn't use a double unless you really need the dangly bits. For timing, I'm guessing you just need to know whether or not you've passed a certain interval. If you do need the extra precision, a bit of calculus might get you what you need without resorting to floating-point math.

Trev
 

Offline Jose

Re: how to use timer.device's EClock unit's higher byte
« Reply #6 on: May 12, 2005, 07:10:25 PM »
I was gonna make a routine in assembler to do it, started checking the VBCC docs to see how to interface to asm (how can you access a variable that's in your C code from assembler when using inline assebler, anyone ?) and stumbled across the long long type, apparently only supported by more recent C standarts (ISO99 or something, what's the difference anyway is ISO incompatible with ANSI ?)...

So it goes like this: just use some casting to assign the EClockVal *ptr function argument to a long long, repeat the same when doing the second reading (to a different variable of course), use C's ordinary substraction to substract the 2nd reading from the 1st one and divide the obtained value by the returned ticks per seoncd, and finally cast the result to a double to obtain the fraccions of a second that passed (wich I don't think the RKM should refer as fracctions since from what I understand can be much more than a second..).

Will that work as easy as it seems ? :-)
\\"We made Amiga, they {bleep}ed it up\\"
 

Offline Trev

Re: how to use timer.device's EClock unit's higher byte
« Reply #7 on: May 12, 2005, 11:02:59 PM »
It should work as long the structure is packed and stored just like a big endian 64-bit long in memory. But you're better off doing something like this:

long long val = (long long)((ptr->ev_hi << 32) + ptr->ev_lo);

And then you don't have to worry about how EClockVal is stored. Plus, the shift and add will allow the compiler to optimize the code. Casting pointers may require guessing on the compiler's part, which may lead to no optimization at all. The VBCC manual does a pretty good job of documenting what's optimized and what's not.

Per VBCC, the following register pairs are used for storing long long values: d0/d1, d2/d3, d4/d5, and d6/d7. Keep that in mind if you plan on using assembler or direct register references in your C code.

But if you're going to use floating point division, then you may as well keep your code simple and use double values throughout.

Trev