2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
5 Some shortcuts that provide the highest flexibility
6 for 64bit and 32bit Systems.
9 #ifndef __MATHIEEE64BIT_DEFINES_H__
10 #define __MATHIEEE64BIT_DEFINES_H__
14 #if defined(AROS_64BIT_TYPE)
15 # define Get_High32of64(val) ((QUAD)(val) >> 32L )
16 # define Set_High32of64(Dest,Src) Dest = ConvertTo64(Src,Get_Low32of64(Dest))
17 # define Get_Low32of64(val) ((QUAD)(val) & 0xFFFFFFFF)
18 # define Set_Low32of64(Dest,Src) Dest = ConvertTo64(Get_High32of64(Dest),Src)
19 # define ConvertTo64(HI,LO) ((((QUAD)(HI)) << 32L) | LO)
21 # define Get_High32of64(val) ((val).high)
22 # define Set_High32of64(Dest,Src) ((Dest).high) = Src
23 # define Get_Low32of64(val) ((val).low)
24 # define Set_Low32of64(Dest,Src) ((Dest).low) = Src
25 # define ConvertTo64(HI,LO) {HI,LO}
28 #if defined AROS_64BIT_TYPE
29 #define QuadData(Const64_Hi, Const64_Lo, Const64) \
30 ConvertTo64(Const64_Hi, Const64_Lo)
32 #define QuadData(Const64_Hi, Const64_Lo, Const64) \
33 {Const64_Hi, Const64_Lo}
40 #if defined AROS_64BIT_TYPE
41 #define XOR64C(Dest64, Var1_64, Const64_Hi, Const64_Lo) \
42 Dest64 = Var1_64 ^ ConvertTo64(Const64_Hi, Const64_Lo)
44 #define XOR64C(Dest64, Var1_64, Const64_Hi, Const64_Lo) \
46 Set_High32of64(Dest64, Get_High32of64(Var1_64) ^ Const64_Hi); \
47 Set_Low32of64( Dest64, Get_Low32of64(Var1_64) ^ Const64_Lo); \
51 #if defined AROS_64BIT_TYPE
52 #define XOR64QC(Dest64, Const64_Hi, Const64_Lo) \
53 Dest64 ^= ConvertTo64(Const64_Hi, Const64_Lo)
55 #define XOR64QC(Dest64, Const64_Hi, Const64_Lo) \
57 Set_High32of64(Dest64, Get_High32of64(Dest64) ^ Const64_Hi); \
58 Set_Low32of64( Dest64, Get_Low32of64(Dest64) ^ Const64_Lo); \
64 #if defined AROS_64BIT_TYPE
65 #define NOT64(Dest64, Src64) \
68 #define NOT64(Dest64, Src64) \
70 Set_High32of64(Dest64, ~Get_High32of64(Src64)); \
71 Set_Low32of64( Dest64, ~Get_Low32of64 (Src64)); \
78 #if defined AROS_64BIT_TYPE
79 #define OR64(Dest64, Var1_64, Var2_64) \
80 Dest64 = Var1_64 | Var2_64 ;
82 #define OR64(Dest64, Var1_64, Var2_64) \
84 Set_High32of64(Dest64, (Get_High32of64(Var1_64) | Get_High32of64(Var2_64))); \
85 Set_Low32of64( Dest64, (Get_Low32of64 (Var1_64) | Get_Low32of64 (Var2_64))); \
89 #if defined AROS_64BIT_TYPE
90 #define OR64Q(Dest64, Var64) \
93 #define OR64Q(Dest64, Var64) \
95 Set_High32of64(Dest64, (Get_High32of64(Dest64) | Get_High32of64(Var64))); \
96 Set_Low32of64( Dest64, (Get_Low32of64 (Dest64) | Get_Low32of64 (Var64))); \
100 #if defined AROS_64BIT_TYPE
101 #define OR64C(Dest64, Var64, Const64_Hi, Const64_Lo) \
102 Dest64 = Var64 | ConvertTo64(Const64_Hi, Const64_Lo);
104 #define OR64C(Dest64, Var64, Const64_Hi, Const64_Lo) \
106 Set_High32of64(Dest64, Get_High32of64(Var64) | Const64_Hi); \
107 Set_Low32of64( Dest64, Get_Low32of64(Var64) | Const64_Lo); \
111 #if defined AROS_64BIT_TYPE
112 #define OR64QC(Dest64, Const64_Hi, Const64_Lo) \
113 Dest64 |= ConvertTo64(Const64_Hi, Const64_Lo);
115 #define OR64QC(Dest64, Const64_Hi, Const64_Lo) \
117 Set_High32of64(Dest64, Get_High32of64(Dest64) | Const64_Hi); \
118 Set_Low32of64( Dest64, Get_Low32of64(Dest64) | Const64_Lo); \
124 #if defined AROS_64BIT_TYPE
125 #define AND64C(Dest64, Var64, Const64_Hi, Const64_Lo) \
126 Dest64 = Var64 & ConvertTo64(Const64_Hi, Const64_Lo) ;
128 #define AND64C(Dest64, Var64, Const64_Hi, Const64_Lo) \
130 Set_High32of64(Dest64, Get_High32of64(Var64) & Const64_Hi); \
131 Set_Low32of64( Dest64, Get_Low32of64(Var64) & Const64_Lo); \
135 #if defined AROS_64BIT_TYPE
136 #define AND64Q(Dest64, Var64) \
139 #define AND64Q(Dest64, Var64) \
141 Set_High32of64(Dest64, (Get_High32of64(Dest64) & Get_High32of64(Var64))); \
142 Set_Low32of64( Dest64, (Get_Low32of64 (Dest64) & Get_Low32of64 (Var64))); \
146 #if defined AROS_64BIT_TYPE
147 #define AND64QC(Dest64, Const64_Hi, Const64_Lo) \
148 Dest64 &= ConvertTo64(Const64_Hi, Const64_Lo) ;
150 #define AND64QC(Dest64, Const64_Hi, Const64_Lo) \
152 Set_High32of64(Dest64, Get_High32of64(Dest64) & Const64_Hi); \
153 Set_Low32of64( Dest64, Get_Low32of64(Dest64) & Const64_Lo); \
158 /* SHL (shift left n bits)*/
160 #if defined AROS_64BIT_TYPE
161 #define SHL64(Dest64, Src64, n) \
162 Dest64 = Src64 << (n);
164 #define SHL64(Dest64, Src64, n) \
167 Set_High32of64(Dest64, (Get_High32of64(Src64) << n) | \
168 (ULONG)(Get_Low32of64 (Src64)) >> (32-(n)) ); \
169 Set_Low32of64(Dest64, (Get_Low32of64 (Src64) << n) ); \
174 Set_High32of64(Dest64, (ULONG)Get_Low32of64(Src64) << ( (n)-32) );\
175 Set_Low32of64(Dest64, 0 ); \
180 Set_High32of64(Dest64, 0); \
181 Set_Low32of64(Dest64, 0); \
186 #if defined AROS_64BIT_TYPE
187 #define SHL32(Dest64, Src32, Shift) \
188 Dest64 = ((QUAD)Src32) << (Shift);
190 #define SHL32(Dest64, Src32, Shift) \
193 Set_High32of64(Dest64, (Src32 >> (32-(Shift)) ) ); \
194 Set_Low32of64 (Dest64, (Src32 << (Shift) ) ); \
200 Set_High32of64(Dest64, (Src32 << ((Shift)-32)) ); \
201 Set_Low32of64 (Dest64, 0 ); \
204 Set_Value64C(Dest64, 0, 0); \
209 /* SHR (shifting to the right **signed/unsigned**) */
211 #if defined AROS_64BIT_TYPE
212 #define SHRU64(Dest64, Src64, Shift) \
213 Dest64 = (UQUAD)Src64 >> (Shift);
215 #define SHRU64(Dest64, Src64, Shift) \
218 Set_Low32of64 (Dest64,((ULONG)Get_Low32of64 (Src64) >> (Shift) )| \
219 ( Get_High32of64(Src64) <<(32-(Shift))) ); \
220 Set_High32of64(Dest64, (ULONG)Get_High32of64(Src64) >> (Shift) ); \
226 Set_Low32of64 (Dest64, (ULONG)Get_High32of64(Src64) >> ((Shift)-32) ); \
227 Set_High32of64(Dest64, 0); \
231 Set_High32of64(Dest64, 0); \
232 Set_Low32of64(Dest64, 0); \
238 #if defined AROS_64BIT_TYPE
239 #define SHRU32(Dest32, Src64, Shift) \
240 Dest32 = (UQUAD)Src64 >> (Shift);
242 #define SHRU32(Dest32, Src64, Shift) \
245 Dest32 = (ULONG)Get_Low32of64(Src64) >> (Shift) | \
246 Get_High32of64(Src64) << (32-(Shift)) \
252 Dest32 = (ULONG)Get_High32of64(Src64) >> ((Shift)-32) ; \
262 /* SHR ** signed ** */
264 #if defined AROS_64BIT_TYPE
265 #define SHRS64(Dest64, Src64, n) \
266 Dest64 = (QUAD)Src64 >> n;
268 #define SHRS64(Dest64, Src64, n) \
272 Set_Low32of64 (Dest64, (ULONG)Get_Low32of64(Src64) >> (n) | \
273 Get_High32of64(Src64) << ((n)-32)); \
274 Set_High32of64(Dest64, ((LONG)Get_High32of64(Src64) >> (n)) ); \
279 Set_Low32of64 (Dest64, (LONG)Get_High32of64(Src64) >> ((n)-32) );\
280 Set_High32of64(Dest64, (LONG)Get_High32of64(Src64) >> 32 ); \
284 Set_High32of64(Dest64, (LONG)Get_High32of64(Src64) >> 32 ); \
285 Set_Low32of64 (Dest64, (LONG)Get_High32of64(Src64) >> 32 ); \
292 #if defined AROS_64BIT_TYPE
293 #define Set_Value64(Dest64, Var64) \
296 #define Set_Value64(Dest64, Var64) \
298 Set_High32of64(Dest64, Get_High32of64(Var64)); \
299 Set_Low32of64(Dest64, Get_Low32of64(Var64)); \
303 #if defined AROS_64BIT_TYPE
304 #define Set_Value64C(Dest64, Const64_Hi, Const64_Lo) \
305 Dest64 = ConvertTo64(Const64_Hi, Const64_Lo)
307 #define Set_Value64C(Dest64, Const64_Hi, Const64_Lo) \
309 Set_High32of64(Dest64, Const64_Hi);\
310 Set_Low32of64 (Dest64, Const64_Lo);\
314 #if defined AROS_64BIT_TYPE
315 #define Set_Value64from32(Dest64, Var32) \
318 #define Set_Value64from32(Dest64, Var32) \
320 Set_Low32of64 (Dest64, Var32); \
321 Set_High32of64(Dest64, 0); \
328 #if defined AROS_64BIT_TYPE
329 #define is_eq(Var1_64, Var2_64) \
332 #define is_eq(Var1_64, Var2_64) \
333 (Get_Low32of64(Var1_64) == Get_Low32of64(Var2_64) && \
334 Get_High32of64(Var1_64) == Get_High32of64(Var2_64))
337 #if defined AROS_64BIT_TYPE
338 #define is_eqC(Var1_64, Const64_Hi, Const64_Lo) \
339 (Var1_64 == ConvertTo64(Const64_Hi, Const64_Lo))
341 #define is_eqC(Var64, Const64_Hi, Const64_Lo) \
342 (Get_Low32of64(Var64) == Const64_Lo && \
343 Get_High32of64(Var64) == Const64_Hi )
346 #if defined AROS_64BIT_TYPE
347 #define is_neq(Var1_64, Var2_64) \
350 #define is_neq(Var1_64, Var2_64) \
351 (Get_Low32of64 (Var1_64) != Get_Low32of64 (Var2_64) || \
352 Get_High32of64(Var1_64) != Get_High32of64(Var2_64) )
355 #if defined AROS_64BIT_TYPE
356 #define is_neqC(Var64, Const64_Hi, Const64_Lo) \
357 (Var64 != ConvertTo64(Const64_Hi, Const64_Lo))
359 #define is_neqC(Var64, Const64_Hi, Const64_Lo) \
360 (Get_Low32of64(Var64) != Const64_Lo || \
361 Get_High32of64(Var64) != Const64_Hi )
364 #if defined AROS_64BIT_TYPE
365 #define is_greater(Var1_64, Var2_64 ) \
368 #define is_greater(Var1_64, Var2_64 ) \
369 ( (Get_High32of64(Var1_64) > Get_High32of64(Var2_64)) || \
370 (Get_High32of64(Var1_64) == Get_High32of64(Var2_64) && \
371 Get_Low32of64(Var1_64) > Get_Low32of64(Var2_64) ) )
374 #if defined AROS_64BIT_TYPE
375 #define is_greaterC(Var1_64, Const64_Hi, Const64_Lo ) \
376 (Var1_64 > ConvertTo64(Const64_Hi, Const64_Lo))
378 #define is_greaterC(Var1_64, Const64_Hi, Const64_Lo ) \
379 ( (Get_High32of64(Var1_64) > Const64_Hi) || \
380 (Get_High32of64(Var1_64) == Const64_Hi && \
381 Get_Low32of64 (Var1_64) > Const64_Hi) )
384 #if defined AROS_64BIT_TYPE
385 #define is_geq(Var1_64, Var2_64 ) \
388 #define is_geq(Var1_64, Var2_64 ) \
389 ( (Get_High32of64(Var1_64) >= Get_High32of64(Var2_64)) || \
390 (Get_High32of64(Var1_64) == Get_High32of64(Var2_64) && \
391 Get_High32of64(Var1_64) >= Get_High32of64(Var2_64) ) )
394 #if defined AROS_64BIT_TYPE
395 #define is_geqC(Var1_64, Const64_Hi, Const64_Lo ) \
396 (Var1_64 > ConvertTo64(Const64_Hi, Const64_Lo))
398 #define is_geqC(Var1_64, Const64_Hi, Const64_Lo ) \
399 ( (Get_High32of64(Var1_64) >= Const64_Hi) || \
400 (Get_High32of64(Var1_64) == Const64_Hi && \
401 Get_Low32of64(Var1_64) >= Const64_Lo) )
404 #if defined AROS_64BIT_TYPE
405 #define is_less(Var1_64, Var2_64 ) \
408 #define is_less(Var1_64, Var2_64 ) \
409 ( ((ULONG)Get_High32of64(Var1_64) < (ULONG)Get_High32of64(Var2_64)) || \
410 ((ULONG)Get_High32of64(Var1_64) == (ULONG)Get_High32of64(Var2_64) && \
411 (ULONG)Get_Low32of64(Var1_64) < (ULONG)Get_Low32of64(Var2_64) ) )
414 #if defined AROS_64BIT_TYPE
415 #define is_lessC(Var1_64, Const64_Hi, Const64_Lo ) \
416 ((UQUAD)Var1_64 < (UQUAD)ConvertTo64(Const64_Hi, Const64_Lo))
418 #define is_lessC(Var1_64, Const64_Hi, Const64_Lo ) \
419 ( ((ULONG)Get_High32of64(Var1_64) < (ULONG)Const64_Hi) || \
420 ((ULONG)Get_High32of64(Var1_64) == (ULONG)Const64_Hi && \
421 (ULONG)Get_Low32of64(Var1_64) < (ULONG)Const64_Lo) )
424 #if defined AROS_64BIT_TYPE
425 #define is_lessSC(Var1_64, Const64_Hi, Const64_Lo ) \
426 ((QUAD)Var1_64 < (QUAD)ConvertTo64(Const64_Hi, Const64_Lo) )
428 #define is_lessSC(Var1_64, Const64_Hi, Const64_Lo ) \
429 ( ((LONG)Get_High32of64(Var1_64) < (LONG)Const64_Hi) || \
430 ((LONG)Get_High32of64(Var1_64) == (LONG)Const64_Hi && \
431 (LONG)Get_Low32of64(Var1_64) < (LONG)Const64_Lo) )
434 #if defined AROS_64BIT_TYPE
435 #define is_leq(Var1_64, Var2_64 ) \
436 ((UQUAD)Var1_64 <= (UQUAD)Var2_64)
438 #define is_leq(Var1_64, Var2_64 ) \
439 /* first comparison has to be a "<" !!! */ \
440 ( ((ULONG)Get_High32of64(Var1_64) < (ULONG)Get_High32of64(Var2_64)) || \
441 ((ULONG)Get_High32of64(Var1_64) == (ULONG)Get_High32of64(Var2_64) && \
442 (ULONG) Get_Low32of64(Var1_64) <= (ULONG) Get_Low32of64(Var2_64) ) )
445 #if defined AROS_64BIT_TYPE
446 #define is_leqC(Var1_64, Const64_Hi, Const64_Lo ) \
447 ((UQUAD)Var1_64 <= (UQUAD)ConvertTo64(Const64_Hi, Const64_Lo))
449 #define is_leqC(Var1_64, Const64_Hi, Const64_Lo ) \
450 /* first comparison has to be a "<" !!! */ \
451 ( ((ULONG)Get_High32of64(Var1_64) < (ULONG)Const64_Hi) || \
452 ((ULONG)Get_High32of64(Var1_64) == (ULONG)Const64_Hi && \
453 (ULONG)Get_Low32of64(Var1_64) <= (ULONG)Const64_Lo) )
456 #if defined AROS_64BIT_TYPE
457 #define is_leqSC(Var1_64, Const64_Hi, Const64_Lo ) \
458 ((QUAD)Var1_64 <= (QUAD)ConvertTo64(Const64_Hi, Const64_Lo))
460 #define is_leqSC(Var1_64, Const64_Hi, Const64_Lo ) \
461 /* first comparison has to be a "<" !!! */ \
462 ( (( LONG)Get_High32of64(Var1_64) < ( LONG)Const64_Hi) || \
463 (( LONG)Get_High32of64(Var1_64) == ( LONG)Const64_Hi && \
464 (ULONG)Get_Low32of64(Var1_64) <= (ULONG)Const64_Lo) )
469 #if defined AROS_64BIT_TYPE
470 #define ADD64(Dest64, Var1_64, Var2_64) \
471 Dest64 = Var1_64 + Var2_64;
473 #define ADD64(Dest64, Var1_64, Var2_64) \
474 if ((LONG) Get_Low32of64(Var1_64) < 0 && \
475 (LONG) Get_Low32of64(Var2_64) < 0 ) \
477 Set_Low32of64 (Dest64, Get_Low32of64 (Var1_64) + Get_Low32of64 (Var2_64) ); \
478 Set_High32of64(Dest64, Get_High32of64(Var1_64) + Get_High32of64(Var2_64) + 1 ); \
481 if ((LONG) Get_Low32of64(Var1_64) >= 0 && \
482 (LONG) Get_Low32of64(Var2_64) >= 0 ) \
484 Set_Low32of64 (Dest64, Get_Low32of64 (Var1_64) + Get_Low32of64 (Var2_64) ); \
485 Set_High32of64(Dest64, Get_High32of64(Var1_64) + Get_High32of64(Var2_64) ); \
489 Set_Low32of64 (Dest64, Get_Low32of64 (Var1_64) + Get_Low32of64 (Var2_64) ); \
490 if ((LONG)Get_Low32of64(Dest64) >= 0 ) \
491 Set_High32of64(Dest64, Get_High32of64(Var1_64) + Get_High32of64(Var2_64) + 1 ); \
493 Set_High32of64(Dest64, Get_High32of64(Var1_64) + Get_High32of64(Var2_64) ); \
497 #if defined AROS_64BIT_TYPE
498 #define ADD64Q(Dest64, Var64) \
501 #define ADD64Q(Dest64, Var64) \
502 if ((LONG) Get_Low32of64(Dest64) < 0 && \
503 (LONG) Get_Low32of64(Var64) < 0 ) \
505 Set_Low32of64 (Dest64, Get_Low32of64 (Dest64) + Get_Low32of64 (Var64) ); \
506 Set_High32of64(Dest64, Get_High32of64(Dest64) + Get_High32of64(Var64) + 1 ); \
509 if ((LONG) Get_Low32of64(Dest64) >= 0 && \
510 (LONG) Get_Low32of64(Var64) >= 0 ) \
512 Set_Low32of64 (Dest64, Get_Low32of64 (Dest64) + Get_Low32of64 (Var64) ); \
513 Set_High32of64(Dest64, Get_High32of64(Dest64) + Get_High32of64(Var64) ); \
517 Set_Low32of64 (Dest64, Get_Low32of64 (Dest64) + Get_Low32of64 (Var64) ); \
518 if ((LONG)Get_Low32of64(Dest64) >= 0 ) \
519 Set_High32of64(Dest64, Get_High32of64(Dest64) + Get_High32of64(Var64) + 1 ); \
521 Set_High32of64(Dest64, Get_High32of64(Dest64) + Get_High32of64(Var64) ); \
525 #if defined AROS_64BIT_TYPE
526 #define ADD64QC(Dest64, Const64_Hi, Const64_Lo ) \
527 Dest64 += ConvertTo64(Const64_Hi, Const64_Lo);
529 #define ADD64QC(Dest64, Const64_Hi, Const64_Lo ) \
530 if ((LONG) Get_Low32of64(Dest64) < 0 && \
531 (LONG) Const64_Lo < 0 ) \
533 Set_Low32of64 (Dest64, Get_Low32of64 (Dest64) + Const64_Lo ); \
534 Set_High32of64(Dest64, Get_High32of64(Dest64) + Const64_Hi + 1 ); \
537 if ((LONG) Get_Low32of64(Dest64) >= 0 && \
538 (LONG) Const64_Lo >= 0 ) \
540 Set_Low32of64 (Dest64, Get_Low32of64 (Dest64) + Const64_Lo ); \
541 Set_High32of64(Dest64, Get_High32of64(Dest64) + Const64_Hi ); \
545 Set_Low32of64 (Dest64, Get_Low32of64 (Dest64) + Const64_Lo ); \
546 if ((LONG)Get_Low32of64(Dest64) >= 0 ) \
547 Set_High32of64(Dest64, Get_High32of64(Dest64) + Const64_Hi + 1 ); \
549 Set_High32of64(Dest64, Get_High32of64(Dest64) + Const64_Hi ); \
554 #if defined AROS_64BIT_TYPE
555 #define SUB64(Dest64, Var1_64, Var2_64) \
556 Dest64 = Var1_64 - Var2_64;
558 #define SUB64(Dest64, Var1_64, Var2_64) \
559 if ((ULONG)Get_Low32of64(Var2_64) > (ULONG)Get_Low32of64(Var1_64)) \
561 Set_Low32of64 ( Dest64, Get_Low32of64 (Var1_64)- Get_Low32of64 (Var2_64)); \
562 Set_High32of64( Dest64, Get_High32of64(Var1_64)- Get_High32of64(Var2_64)-1); \
566 Set_Low32of64 ( Dest64, Get_Low32of64 (Var1_64) - Get_Low32of64 (Var2_64)); \
567 Set_High32of64( Dest64, Get_High32of64(Var1_64) - Get_High32of64(Var2_64)); \
571 #if defined AROS_64BIT_TYPE
572 #define SUB64QC(Dest64, Const64_Hi, Const64_Lo ) \
573 Dest64 -= ConvertTo64(Const64_Hi, Const64_Lo);
575 #define SUB64QC(Dest64, Const64_Hi, Const64_Lo ) \
576 if ((ULONG)Const64_Lo > (ULONG)Get_Low32of64(Dest64)) \
578 Set_Low32of64 ( Dest64, Get_Low32of64 (Dest64)-Const64_Lo); \
579 Set_High32of64( Dest64, Get_High32of64(Dest64)-Const64_Hi-1); \
583 Set_Low32of64 ( Dest64, Get_Low32of64 (Dest64)-Const64_Lo); \
584 Set_High32of64( Dest64, Get_High32of64(Dest64)-Const64_Hi); \
590 #if defined AROS_64BIT_TYPE
591 #define NEG64(Dest64) \
594 #define NEG64(Dest64) \
595 if (0 == Get_Low32of64(Dest64)) \
596 Set_High32of64( Dest64, -Get_High32of64(Dest64) ); \
599 Set_High32of64( Dest64, Get_High32of64(Dest64) ^ 0xFFFFFFFF ); \
600 Set_Low32of64 ( Dest64, -Get_Low32of64(Dest64)); \
605 #endif /* __MATHIEEE64BIT_DEFINES_H__ */