the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 2322 lines 75 kB view raw
1/// ======================================================================== 2// (C) Copyright 1994- 2014 RAD Game Tools, Inc. Global types header file 3// ======================================================================== 4 5#ifndef __RADRR_COREH__ 6#define __RADRR_COREH__ 7#define RADCOPYRIGHT "Copyright (C) 1994-2014, RAD Game Tools, Inc." 8 9// __RAD16__ means 16 bit code (Win16) 10// __RAD32__ means 32 bit code (DOS, Win386, Win32s, Mac AND Win64) 11// __RAD64__ means 64 bit code (x64) 12 13// Note oddness - __RAD32__ essentially means "at *least* 32-bit code". 14// So, on 64-bit systems, both __RAD32__ and __RAD64__ will be defined. 15 16// __RADDOS__ means DOS code (16 or 32 bit) 17// __RADWIN__ means Windows API (Win16, Win386, Win32s, Win64, Xbox, Xenon) 18// __RADWINEXT__ means Windows 386 extender (Win386) 19// __RADNT__ means Win32 or Win64 code 20// __RADWINRTAPI__ means Windows RT API (Win 8, Win Phone, ARM, Durango) 21// __RADMAC__ means Macintosh 22// __RADCARBON__ means Carbon 23// __RADMACH__ means MachO 24// __RADXBOX__ means the XBox console 25// __RADXENON__ means the Xenon console 26// __RADDURANGO__ or __RADXBOXONE__ means Xbox One 27// __RADNGC__ means the Nintendo GameCube 28// __RADWII__ means the Nintendo Wii 29// __RADWIIU__ means the Nintendo Wii U 30// __RADNDS__ means the Nintendo DS 31// __RADTWL__ means the Nintendo DSi (__RADNDS__ also defined) 32// __RAD3DS__ means the Nintendo 3DS 33// __RADPS2__ means the Sony PlayStation 2 34// __RADPSP__ means the Sony PlayStation Portable 35// __RADPS3__ means the Sony PlayStation 3 36// __RADPS4__ means the Sony PlayStation 4 37// __RADANDROID__ means Android NDK 38// __RADNACL__ means Native Client SDK 39// __RADNTBUILDLINUX__ means building Linux on NT 40// __RADLINUX__ means actually building on Linux (most likely with GCC) 41// __RADPSP2__ means NGP 42// __RADBSD__ means a BSD-style UNIX (OS X, FreeBSD, OpenBSD, NetBSD) 43// __RADPOSIX__ means POSIX-compliant 44// __RADQNX__ means QNX 45// __RADIPHONE__ means iphone 46// __RADIPHONESIM__ means iphone simulator 47 48// __RADX86__ means Intel x86 49// __RADMMX__ means Intel x86 MMX instructions are allowed 50// __RADX64__ means Intel/AMD x64 (NOT IA64=Itanium) 51// __RAD68K__ means 68K 52// __RADPPC__ means PowerPC 53// __RADMIPS__ means Mips (only R5900 right now) 54// __RADARM__ mean ARM processors 55 56// __RADLITTLEENDIAN__ means processor is little-endian (x86) 57// __RADBIGENDIAN__ means processor is big-endian (680x0, PPC) 58 59// __RADNOVARARGMACROS__ means #defines can't use ... 60 61 #ifdef WINAPI_FAMILY 62 // If this is #defined, we might be in a Windows Store App. But 63 // VC++ by default #defines this to a symbolic name, not an integer 64 // value, and those names are defined in "winapifamily.h". So if 65 // WINAPI_FAMILY is #defined, #include the header so we can parse it. 66 #include <winapifamily.h> 67 #define RAD_WINAPI_IS_APP (!WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)) 68 #else 69 #define RAD_WINAPI_IS_APP 0 70 #endif 71 72 #ifndef __RADRES__ 73 // Theoretically, this is to pad structs on platforms that don't support pragma pack or do it poorly. (PS3, PS2) 74 // In general it is assumed that your padding is set via pragma, so this is just a struct. 75 #define RADSTRUCT struct 76 77 #ifdef __GNUC_MINOR__ 78 // make a combined GCC version for testing : 79 80 #define __RAD_GCC_VERSION__ (__GNUC__ * 10000 \ 81 + __GNUC_MINOR__ * 100 \ 82 + __GNUC_PATCHLEVEL__) 83 84 /* Test for GCC > 3.2.0 */ 85 // #if GCC_VERSION > 30200 86 #endif 87 88 #if defined(__RADX32__) 89 90 #define __RADX86__ 91 #define __RADMMX__ 92 #define __RAD32__ 93 #define __RADLITTLEENDIAN__ 94 #define RADINLINE inline 95 #define RADRESTRICT __restrict 96 97 // known platforms under the RAD generic build type 98 #if defined(_WIN32) || defined(_Windows) || defined(WIN32) || defined(__WINDOWS__) || defined(_WINDOWS) 99 #define __RADNT__ 100 #define __RADWIN__ 101 #elif (defined(__MWERKS__) && !defined(__INTEL__)) || defined(__MRC__) || defined(THINK_C) || defined(powerc) || defined(macintosh) || defined(__powerc) || defined(__APPLE__) || defined(__MACH__) 102 #define __RADMAC__ 103 #undef RADSTRUCT 104 #define RADSTRUCT struct __attribute__((__packed__)) 105 #elif defined(__linux__) 106 #define __RADLINUX__ 107 #undef RADSTRUCT 108 #define RADSTRUCT struct __attribute__((__packed__)) 109 #endif 110 111#elif defined(ANDROID) 112 #define __RADANDROID__ 113 #define __RAD32__ 114 #define __RADLITTLEENDIAN__ 115 #ifdef __i386__ 116 #define __RADX86__ 117 #else 118 #define __RADARM__ 119 #endif 120 #define RADINLINE inline 121 #define RADRESTRICT __restrict 122 #undef RADSTRUCT 123 #define RADSTRUCT struct __attribute__((__packed__)) 124 125#elif defined(__QNX__) 126 #define __RAD32__ 127 #define __RADQNX__ 128 129#ifdef __arm__ 130 #define __RADARM__ 131#elif defined __i386__ 132 #define __RADX86__ 133#else 134 #error Unknown processor 135#endif 136 #define __RADLITTLEENDIAN__ 137 #define RADINLINE inline 138 #define RADRESTRICT __restrict 139 140 #undef RADSTRUCT 141 #define RADSTRUCT struct __attribute__((__packed__)) 142#elif defined(__linux__) && defined(__arm__) //This should pull in Raspberry Pi as well 143 144 #define __RAD32__ 145 #define __RADLINUX__ 146 #define __RADARM__ 147 #define __RADLITTLEENDIAN__ 148 #define RADINLINE inline 149 #define RADRESTRICT __restrict 150 151 #undef RADSTRUCT 152 #define RADSTRUCT struct __attribute__((__packed__)) 153 154#elif defined(__native_client__) 155 #define __RADNACL__ 156 #define __RAD32__ 157 #define __RADLITTLEENDIAN__ 158 #define __RADX86__ 159 #define RADINLINE inline 160 #define RADRESTRICT __restrict 161 162 #undef RADSTRUCT 163 #define RADSTRUCT struct __attribute__((__packed__)) 164 165 #elif defined(_DURANGO) || defined(_SEKRIT) || defined(_SEKRIT1) || defined(_XBOX_ONE) 166 167 #define __RADDURANGO__ 1 168 #define __RADXBOXONE__ 1 169 #if !defined(__RADSEKRIT__) // keep sekrit around for a bit for compat 170 #define __RADSEKRIT__ 1 171 #endif 172 173 #define __RADWIN__ 174 #define __RAD32__ 175 #define __RAD64__ 176 #define __RADX64__ 177 #define __RADMMX__ 178 #define __RADX86__ 179 #define __RAD64REGS__ 180 #define __RADLITTLEENDIAN__ 181 #define RADINLINE __inline 182 #define RADRESTRICT __restrict 183 #define __RADWINRTAPI__ 184 185 #elif defined(__ORBIS__) 186 187 #define __RADPS4__ 188 #if !defined(__RADSEKRIT2__) // keep sekrit2 around for a bit for compat 189 #define __RADSEKRIT2__ 1 190 #endif 191 #define __RAD32__ 192 #define __RAD64__ 193 #define __RADX64__ 194 #define __RADMMX__ 195 #define __RADX86__ 196 #define __RAD64REGS__ 197 #define __RADLITTLEENDIAN__ 198 #define RADINLINE inline 199 #define RADRESTRICT __restrict 200 201 #undef RADSTRUCT 202 #define RADSTRUCT struct __attribute__((__packed__)) 203 204 #elif defined(WINAPI_FAMILY) && RAD_WINAPI_IS_APP 205 206 #define __RADWINRTAPI__ 207 #define __RADWIN__ 208 #define RADINLINE __inline 209 #define RADRESTRICT __restrict 210 211 #if defined(_M_IX86) // WinRT on x86 212 213 #define __RAD32__ 214 #define __RADX86__ 215 #define __RADMMX__ 216 #define __RADLITTLEENDIAN__ 217 218 #elif defined(_M_X64) // WinRT on x64 219 #define __RAD32__ 220 #define __RAD64__ 221 #define __RADX86__ 222 #define __RADX64__ 223 #define __RADMMX__ 224 #define __RAD64REGS__ 225 #define __RADLITTLEENDIAN__ 226 227 #elif defined(_M_ARM) // WinRT on ARM 228 229 #define __RAD32__ 230 #define __RADARM__ 231 #define __RADLITTLEENDIAN__ 232 233 #else 234 235 #error Unrecognized WinRT platform! 236 237 #endif 238 239 #elif defined(_WIN64) 240 241 #define __RADWIN__ 242 #define __RADNT__ 243 // See note at top for why both __RAD32__ and __RAD64__ are defined. 244 #define __RAD32__ 245 #define __RAD64__ 246 #define __RADX64__ 247 #define __RADMMX__ 248 #define __RADX86__ 249 #define __RAD64REGS__ 250 #define __RADLITTLEENDIAN__ 251 #define RADINLINE __inline 252 #define RADRESTRICT __restrict 253 254 #elif defined(GENERIC_ARM) 255 256 #define __RAD32__ 257 #define __RADARM__ 258 #define __RADLITTLEENDIAN__ 259 #define __RADFIXEDPOINT__ 260 #define RADINLINE inline 261 #if (defined(__GCC__) || defined(__GNUC__)) 262 #define RADRESTRICT __restrict 263 #else 264 #define RADRESTRICT // __restrict not supported on cw 265 #endif 266 #undef RADSTRUCT 267 #define RADSTRUCT struct __attribute__((__packed__)) 268 269 #elif defined(CAFE) // has to be before HOLLYWOOD_REV since it also defines it 270 271 #define __RADWIIU__ 272 #define __RAD32__ 273 #define __RADPPC__ 274 #define __RADBIGENDIAN__ 275 #define RADINLINE inline 276 #define RADRESTRICT __restrict 277 #undef RADSTRUCT 278 #define RADSTRUCT struct __attribute__((__packed__)) 279 280 281 #elif defined(HOLLYWOOD_REV) || defined(REVOLUTION) 282 283 #define __RADWII__ 284 #define __RAD32__ 285 #define __RADPPC__ 286 #define __RADBIGENDIAN__ 287 #define RADINLINE inline 288 #define RADRESTRICT __restrict 289 290 #elif defined(NN_PLATFORM_CTR) 291 292 #define __RAD3DS__ 293 #define __RAD32__ 294 #define __RADARM__ 295 #define __RADLITTLEENDIAN__ 296 #define RADINLINE inline 297 #define RADRESTRICT 298 #undef RADSTRUCT 299 #define RADSTRUCT struct __attribute__((__packed__)) 300 301 #elif defined(GEKKO) 302 303 #define __RADNGC__ 304 #define __RAD32__ 305 #define __RADPPC__ 306 #define __RADBIGENDIAN__ 307 #define RADINLINE inline 308 #define RADRESTRICT // __restrict not supported on cw 309 310 #elif defined(SDK_ARM9) || defined(SDK_TWL) || (defined(__arm) && defined(__MWERKS__)) 311 312 #define __RADNDS__ 313 #define __RAD32__ 314 #define __RADARM__ 315 #define __RADLITTLEENDIAN__ 316 #define __RADFIXEDPOINT__ 317 #define RADINLINE inline 318 #if (defined(__GCC__) || defined(__GNUC__)) 319 #define RADRESTRICT __restrict 320 #else 321 #define RADRESTRICT // __restrict not supported on cw 322 #endif 323 324 #if defined(SDK_TWL) 325 #define __RADTWL__ 326 #endif 327 328 #elif defined(R5900) 329 330 #define __RADPS2__ 331 #define __RAD32__ 332 #define __RADMIPS__ 333 #define __RADLITTLEENDIAN__ 334 #define RADINLINE inline 335 #define RADRESTRICT __restrict 336 #define __RAD64REGS__ 337 #define U128 u_long128 338 339 #if !defined(__MWERKS__) 340 #undef RADSTRUCT 341 #define RADSTRUCT struct __attribute__((__packed__)) 342 #endif 343 344 #elif defined(__psp__) 345 346 #define __RADPSP__ 347 #define __RAD32__ 348 #define __RADMIPS__ 349 #define __RADLITTLEENDIAN__ 350 #define RADINLINE inline 351 #define RADRESTRICT __restrict 352 353 #undef RADSTRUCT 354 #define RADSTRUCT struct __attribute__((__packed__)) 355 356 #elif defined(__psp2__) 357 358 #undef RADSTRUCT 359 #define RADSTRUCT struct __attribute__((__packed__)) 360 361 #define __RADPSP2__ 362 #define __RAD32__ 363 #define __RADARM__ 364 #define __RADLITTLEENDIAN__ 365 #define RADINLINE inline 366 #define RADRESTRICT __restrict 367 368 // need packed attribute for struct with snc? 369 #elif defined(__CELLOS_LV2__) 370 371 // CB change : 10-29-10 : RAD64REGS on PPU but NOT SPU 372 373 #ifdef __SPU__ 374 #define __RADSPU__ 375 #define __RAD32__ 376 #define __RADCELL__ 377 #define __RADBIGENDIAN__ 378 #define RADINLINE inline 379 #define RADRESTRICT __restrict 380 #else 381 #define __RAD64REGS__ 382 #define __RADPS3__ 383 #define __RADPPC__ 384 #define __RAD32__ 385 #define __RADCELL__ 386 #define __RADBIGENDIAN__ 387 #define RADINLINE inline 388 #define RADRESTRICT __restrict 389 #define __RADALTIVEC__ 390 #endif 391 392 #undef RADSTRUCT 393 #define RADSTRUCT struct __attribute__((__packed__)) 394 395 #ifndef __LP32__ 396 #error "PS3 32bit ABI support only" 397 #endif 398 #elif (defined(__MWERKS__) && !defined(__INTEL__)) || defined(__MRC__) || defined(THINK_C) || defined(powerc) || defined(macintosh) || defined(__powerc) || defined(__APPLE__) || defined(__MACH__) 399 #ifdef __APPLE__ 400 #include "TargetConditionals.h" 401 #endif 402 403 #if ((defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE) || (defined(TARGET_IPHONE_SIMULATOR) && TARGET_IPHONE_SIMULATOR)) 404 405 // iPhone/iPad/iOS 406 #define __RADIPHONE__ 407 #define __RADMACAPI__ 408 409 #define __RAD32__ 410 #if defined(__x86_64__) 411 #define __RAD64__ 412 #endif 413 414 #define __RADLITTLEENDIAN__ 415 #define RADINLINE inline 416 #define RADRESTRICT __restrict 417 #define __RADMACH__ 418 419 #undef RADSTRUCT 420 #define RADSTRUCT struct __attribute__((__packed__)) 421 422 #if defined(TARGET_IPHONE_SIMULATOR) && TARGET_IPHONE_SIMULATOR 423 #if defined( __x86_64__) 424 #define __RADX64__ 425 #else 426 #define __RADX86__ 427 #endif 428 #define __RADIPHONESIM__ 429 #elif defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE 430 #define __RADARM__ 431 #endif 432 #else 433 434 // An actual MacOSX machine 435 #define __RADMAC__ 436 #define __RADMACAPI__ 437 438 #if defined(powerc) || defined(__powerc) || defined(__ppc__) 439 #define __RADPPC__ 440 #define __RADBIGENDIAN__ 441 #define __RADALTIVEC__ 442 #define RADRESTRICT 443 #elif defined(__i386__) 444 #define __RADX86__ 445 #define __RADMMX__ 446 #define __RADLITTLEENDIAN__ 447 #define RADRESTRICT __restrict 448 #elif defined(__x86_64__) 449 #define __RAD32__ 450 #define __RAD64__ 451 #define __RADX86__ 452 #define __RADX64__ 453 #define __RAD64REGS__ 454 #define __RADMMX__ 455 #define __RADLITTLEENDIAN__ 456 #define RADRESTRICT __restrict 457 #else 458 #define __RAD68K__ 459 #define __RADBIGENDIAN__ 460 #define __RADALTIVEC__ 461 #define RADRESTRICT 462 #endif 463 464 #define __RAD32__ 465 466 #if defined(__MWERKS__) 467 #if (defined(__cplusplus) || ! __option(only_std_keywords)) 468 #define RADINLINE inline 469 #endif 470 #ifdef __MACH__ 471 #define __RADMACH__ 472 #endif 473 #elif defined(__MRC__) 474 #if defined(__cplusplus) 475 #define RADINLINE inline 476 #endif 477 #elif defined(__GNUC__) || defined(__GNUG__) || defined(__MACH__) 478 #define RADINLINE inline 479 #define __RADMACH__ 480 481 #undef RADRESTRICT /* could have been defined above... */ 482 #define RADRESTRICT __restrict 483 484 #undef RADSTRUCT 485 #define RADSTRUCT struct __attribute__((__packed__)) 486 #endif 487 488 #ifdef __RADX86__ 489 #ifndef __RADCARBON__ 490 #define __RADCARBON__ 491 #endif 492 #endif 493 494 #ifdef TARGET_API_MAC_CARBON 495 #if TARGET_API_MAC_CARBON 496 #ifndef __RADCARBON__ 497 #define __RADCARBON__ 498 #endif 499 #endif 500 #endif 501 #endif 502 #elif defined(__linux__) 503 504 #define __RADLINUX__ 505 #define __RADMMX__ 506 #define __RADLITTLEENDIAN__ 507 #define __RADX86__ 508 #ifdef __x86_64 509 #define __RAD32__ 510 #define __RAD64__ 511 #define __RADX64__ 512 #define __RAD64REGS__ 513 #else 514 #define __RAD32__ 515 #endif 516 #define RADINLINE inline 517 #define RADRESTRICT __restrict 518 519 #undef RADSTRUCT 520 #define RADSTRUCT struct __attribute__((__packed__)) 521 522 #else 523 524 #if _MSC_VER >= 1400 525 #undef RADRESTRICT 526 #define RADRESTRICT __restrict 527 #else 528 #define RADRESTRICT 529 #define __RADNOVARARGMACROS__ 530 #endif 531 532 #if defined(_XENON) || ( defined(_XBOX_VER) && (_XBOX_VER == 200) ) 533 // Remember that Xenon also defines _XBOX 534 #define __RADPPC__ 535 #define __RADBIGENDIAN__ 536 #define __RADALTIVEC__ 537 #else 538 #define __RADX86__ 539 #define __RADMMX__ 540 #define __RADLITTLEENDIAN__ 541 #endif 542 543 #ifdef __MWERKS__ 544 #define _WIN32 545 #endif 546 547 #ifdef __DOS__ 548 #define __RADDOS__ 549 #define S64_DEFINED // turn off these types 550 #define U64_DEFINED 551 #define S64 double //should error 552 #define U64 double //should error 553 #define __RADNOVARARGMACROS__ 554 #endif 555 556 #ifdef __386__ 557 #define __RAD32__ 558 #endif 559 560 #ifdef _Windows //For Borland 561 #ifdef __WIN32__ 562 #define WIN32 563 #else 564 #define __WINDOWS__ 565 #endif 566 #endif 567 568 #ifdef _WINDOWS //For MS 569 #ifndef _WIN32 570 #define __WINDOWS__ 571 #endif 572 #endif 573 574 #ifdef _WIN32 575 #if defined(_XENON) || ( defined(_XBOX_VER) && (_XBOX_VER == 200) ) 576 // Remember that Xenon also defines _XBOX 577 #define __RADXENON__ 578 #define __RAD64REGS__ 579 #elif defined(_XBOX) 580 #define __RADXBOX__ 581 #elif !defined(__RADWINRTAPI__) 582 #define __RADNT__ 583 #endif 584 #define __RADWIN__ 585 #define __RAD32__ 586 #else 587 #ifdef __NT__ 588 #if defined(_XENON) || (_XBOX_VER == 200) 589 // Remember that Xenon also defines _XBOX 590 #define __RADXENON__ 591 #define __RAD64REGS__ 592 #elif defined(_XBOX) 593 #define __RADXBOX__ 594 #else 595 #define __RADNT__ 596 #endif 597 #define __RADWIN__ 598 #define __RAD32__ 599 #else 600 #ifdef __WINDOWS_386__ 601 #define __RADWIN__ 602 #define __RADWINEXT__ 603 #define __RAD32__ 604 #define S64_DEFINED // turn off these types 605 #define U64_DEFINED 606 #define S64 double //should error 607 #define U64 double //should error 608 #else 609 #ifdef __WINDOWS__ 610 #define __RADWIN__ 611 #define __RAD16__ 612 #else 613 #ifdef WIN32 614 #if defined(_XENON) || (_XBOX_VER == 200) 615 // Remember that Xenon also defines _XBOX 616 #define __RADXENON__ 617 #elif defined(_XBOX) 618 #define __RADXBOX__ 619 #else 620 #define __RADNT__ 621 #endif 622 #define __RADWIN__ 623 #define __RAD32__ 624 #endif 625 #endif 626 #endif 627 #endif 628 #endif 629 630 #ifdef __WATCOMC__ 631 #define RADINLINE 632 #else 633 #define RADINLINE __inline 634 #endif 635 #endif 636 637 #if defined __RADMAC__ || defined __RADIPHONE__ 638 #define __RADBSD__ 639 #endif 640 641 #if defined __RADBSD__ || defined __RADLINUX__ 642 #define __RADPOSIX__ 643 #endif 644 645 #if (!defined(__RADDOS__) && !defined(__RADWIN__) && !defined(__RADMAC__) && \ 646 !defined(__RADNGC__) && !defined(__RADNDS__) && !defined(__RADXBOX__) && \ 647 !defined(__RADXENON__) && !defined(__RADDURANGO__) && !defined(__RADPS4__) && !defined(__RADLINUX__) && !defined(__RADPS2__) && \ 648 !defined(__RADPSP__) && !defined(__RADPSP2__) && !defined(__RADPS3__) && !defined(__RADSPU__) && \ 649 !defined(__RADWII__) && !defined(__RADIPHONE__) && !defined(__RADX32__) && !defined(__RADARM__) && \ 650 !defined(__RADWIIU__) && !defined(__RADANDROID__) && !defined(__RADNACL__) && !defined (__RADQNX__) ) 651 #error "RAD.H did not detect your platform. Define DOS, WINDOWS, WIN32, macintosh, powerpc, or appropriate console." 652 #endif 653 654 655 #ifdef __RADFINAL__ 656 #define RADTODO(str) { char __str[0]=str; } 657 #else 658 #define RADTODO(str) 659 #endif 660 661 #ifdef __RADX32__ 662 #if defined(_MSC_VER) 663 #define RADLINK __stdcall 664 #define RADEXPLINK __stdcall 665 #else 666 #define RADLINK __attribute__((stdcall)) 667 #define RADEXPLINK __attribute__((stdcall)) 668 #endif 669 #define RADEXPFUNC RADDEFFUNC 670 671 #elif (defined(__RADNGC__) || defined(__RADWII__) || defined( __RADPS2__) || \ 672 defined(__RADPSP__) || defined(__RADPSP2__) || defined(__RADPS3__) || \ 673 defined(__RADSPU__) || defined(__RADNDS__) || defined(__RADIPHONE__) || \ 674 (defined(__RADARM__) && !defined(__RADWINRTAPI__)) || defined(__RADWIIU__) || defined(__RADPS4__) ) 675 676 #define RADLINK 677 #define RADEXPLINK 678 #define RADEXPFUNC RADDEFFUNC 679 #define RADASMLINK 680 681 #elif defined(__RADANDROID__) 682 #define RADLINK 683 #define RADEXPLINK 684 #define RADEXPFUNC RADDEFFUNC 685 #define RADASMLINK 686 #elif defined(__RADNACL__) 687 #define RADLINK 688 #define RADEXPLINK 689 #define RADEXPFUNC RADDEFFUNC 690 #define RADASMLINK 691 #elif defined(__RADLINUX__) || defined (__RADQNX__) 692 693 #ifdef __RAD64__ 694 #define RADLINK 695 #define RADEXPLINK 696 #else 697 #define RADLINK __attribute__((cdecl)) 698 #define RADEXPLINK __attribute__((cdecl)) 699 #endif 700 701 #define RADEXPFUNC RADDEFFUNC 702 #define RADASMLINK 703 704 #elif defined(__RADMAC__) 705 706 // this define is for CodeWarrior 11's stupid new libs (even though 707 // we don't use longlong's). 708 709 #define __MSL_LONGLONG_SUPPORT__ 710 711 #define RADLINK 712 #define RADEXPLINK 713 714 #if defined(__CFM68K__) || defined(__MWERKS__) 715 #ifdef __RADINDLL__ 716 #define RADEXPFUNC RADDEFFUNC __declspec(export) 717 #else 718 #define RADEXPFUNC RADDEFFUNC __declspec(import) 719 #endif 720 #else 721 #if defined(__RADMACH__) && !defined(__MWERKS__) 722 #ifdef __RADINDLL__ 723 #define RADEXPFUNC RADDEFFUNC __attribute__((visibility("default"))) 724 #else 725 #define RADEXPFUNC RADDEFFUNC 726 #endif 727 #else 728 #define RADEXPFUNC RADDEFFUNC 729 #endif 730 #endif 731 #define RADASMLINK 732 733 #else 734 735 #ifdef __RADNT__ 736 #ifndef _WIN32 737 #define _WIN32 738 #endif 739 #ifndef WIN32 740 #define WIN32 741 #endif 742 #endif 743 744 #ifdef __RADWIN__ 745 #ifdef __RAD32__ 746 747 #ifdef __RADXBOX__ 748 749 #define RADLINK __stdcall 750 #define RADEXPLINK __stdcall 751 #define RADEXPFUNC RADDEFFUNC 752 753 #elif defined(__RADXENON__) || defined(__RADDURANGO__) 754 755 #define RADLINK __stdcall 756 #define RADEXPLINK __stdcall 757 758 #define RADEXPFUNC RADDEFFUNC 759 760 #elif defined(__RADWINRTAPI__) 761 762 #define RADLINK __stdcall 763 #define RADEXPLINK __stdcall 764 765 #if ( defined(__RADINSTATICLIB__) || defined(__RADNOEXPORTS__ ) || ( defined(__RADNOEXEEXPORTS__) && ( !defined(__RADINDLL__) ) && ( !defined(__RADINSTATICLIB__) ) ) ) 766 #define RADEXPFUNC RADDEFFUNC 767 #else 768 #ifndef __RADINDLL__ 769 #define RADEXPFUNC RADDEFFUNC __declspec(dllimport) 770 #else 771 #define RADEXPFUNC RADDEFFUNC __declspec(dllexport) 772 #endif 773 #endif 774 775 #elif defined(__RADNTBUILDLINUX__) 776 777 #define RADLINK __cdecl 778 #define RADEXPLINK __cdecl 779 #define RADEXPFUNC RADDEFFUNC 780 781 #else 782 #ifdef __RADNT__ 783 784 #define RADLINK __stdcall 785 #define RADEXPLINK __stdcall 786 787 #if ( defined(__RADINSTATICLIB__) || defined(__RADNOEXPORTS__ ) || ( defined(__RADNOEXEEXPORTS__) && ( !defined(__RADINDLL__) ) && ( !defined(__RADINSTATICLIB__) ) ) ) 788 #define RADEXPFUNC RADDEFFUNC 789 #else 790 #ifndef __RADINDLL__ 791 #define RADEXPFUNC RADDEFFUNC __declspec(dllimport) 792 #ifdef __BORLANDC__ 793 #if __BORLANDC__<=0x460 794 #undef RADEXPFUNC 795 #define RADEXPFUNC RADDEFFUNC 796 #endif 797 #endif 798 #else 799 #define RADEXPFUNC RADDEFFUNC __declspec(dllexport) 800 #endif 801 #endif 802 #else 803 #define RADLINK __pascal 804 #define RADEXPLINK __far __pascal 805 #define RADEXPFUNC RADDEFFUNC 806 #endif 807 #endif 808 #else 809 #define RADLINK __pascal 810 #define RADEXPLINK __far __pascal __export 811 #define RADEXPFUNC RADDEFFUNC 812 #endif 813 #else 814 #define RADLINK __pascal 815 #define RADEXPLINK __pascal 816 #define RADEXPFUNC RADDEFFUNC 817 #endif 818 819 #define RADASMLINK __cdecl 820 821 #endif 822 823 #if !defined(__RADXBOX__) && !defined(__RADXENON__) && !defined(__RADDURANGO__) && !defined(__RADXBOXONE__) 824 #ifdef __RADWIN__ 825 #ifndef _WINDOWS 826 #define _WINDOWS 827 #endif 828 #endif 829 #endif 830 831 #ifdef __RADLITTLEENDIAN__ 832 #ifdef __RADBIGENDIAN__ 833 #error both endians !? 834 #endif 835 #endif 836 837 #if !defined(__RADLITTLEENDIAN__) && !defined(__RADBIGENDIAN__) 838 #error neither endian! 839 #endif 840 841 842 //----------------------------------------------------------------- 843 844 #ifndef RADDEFFUNC 845 846 #ifdef __cplusplus 847 #define RADDEFFUNC extern "C" 848 #define RADDEFSTART extern "C" { 849 #define RADDEFEND } 850 #define RADDEFINEDATA extern "C" 851 #define RADDECLAREDATA extern "C" 852 #define RADDEFAULT( val ) =val 853 854 #define RR_NAMESPACE rr 855 #define RR_NAMESPACE_START namespace RR_NAMESPACE { 856 #define RR_NAMESPACE_END }; 857 #define RR_NAMESPACE_USE using namespace RR_NAMESPACE; 858 859 #else 860 #define RADDEFFUNC 861 #define RADDEFSTART 862 #define RADDEFEND 863 #define RADDEFINEDATA 864 #define RADDECLAREDATA extern 865 #define RADDEFAULT( val ) 866 867 #define RR_NAMESPACE 868 #define RR_NAMESPACE_START 869 #define RR_NAMESPACE_END 870 #define RR_NAMESPACE_USE 871 872 #endif 873 874 #endif 875 876 // probably s.b: RAD_DECLARE_ALIGNED(type, name, alignment) 877 #if (defined(__RADWII__) || defined(__RADWIIU__) || defined(__RADPSP__) || defined(__RADPSP2__) || \ 878 defined(__RADPS3__) || defined(__RADSPU__) || defined(__RADPS4__) || \ 879 defined(__RADLINUX__) || defined(__RADMAC__)) || defined(__RADNDS__) || defined(__RAD3DS__) || \ 880 defined(__RADIPHONE__) || defined(__RADANDROID__) || defined (__RADQNX__) 881 #define RAD_ALIGN(type,var,num) type __attribute__ ((aligned (num))) var 882 #elif (defined(__RADNGC__) || defined(__RADPS2__)) 883 #define RAD_ALIGN(type,var,num) __attribute__ ((aligned (num))) type var 884 #elif (defined(_MSC_VER) && (_MSC_VER >= 1300)) || defined(__RADWINRTAPI__) 885 #define RAD_ALIGN(type,var,num) type __declspec(align(num)) var 886 #else 887 // NOTE: / / is a guaranteed parse error in C/C++. 888 #define RAD_ALIGN(type,var,num) RAD_ALIGN_USED_BUT_NOT_DEFINED / / 889 #endif 890 891 // WARNING : RAD_TLS should really only be used for debug/tools stuff 892 // it's not reliable because even if we are built as a lib, our lib can 893 // be put into a DLL and then it doesn't work 894 #if defined(__RADNT__) || defined(__RADXENON__) 895 #ifndef __RADINDLL__ 896 // note that you can't use this in windows DLLs 897 #define RAD_TLS(type,var) __declspec(thread) type var 898 #endif 899 #elif defined(__RADPS3__) || defined(__RADLINUX__) || defined(__RADMAC__) 900 // works on PS3/gcc I believe : 901 #define RAD_TLS(type,var) __thread type var 902 #else 903 // RAD_TLS not defined 904 #endif 905 906 // Note that __RAD16__/__RAD32__/__RAD64__ refers to the size of a pointer. 907 // The size of integers is specified explicitly in the code, i.e. u32 or whatever. 908 909 #define RAD_S8 signed char 910 #define RAD_U8 unsigned char 911 912 #if defined(__RAD64__) 913 // Remember that __RAD32__ will also be defined! 914 #if defined(__RADX64__) 915 // x64 still has 32-bit ints! 916 #define RAD_U32 unsigned int 917 #define RAD_S32 signed int 918 // But pointers are 64 bits. 919 #if (_MSC_VER >= 1300 && defined(_Wp64) && _Wp64 ) 920 #define RAD_SINTa __w64 signed __int64 921 #define RAD_UINTa __w64 unsigned __int64 922 #else // non-vc.net compiler or /Wp64 turned off 923 #define RAD_UINTa unsigned long long 924 #define RAD_SINTa signed long long 925 #endif 926 #else 927 #error Unknown 64-bit processor (see radbase.h) 928 #endif 929 #elif defined(__RAD32__) 930 #define RAD_U32 unsigned int 931 #define RAD_S32 signed int 932 // Pointers are 32 bits. 933 934 #if ( ( defined(_MSC_VER) && (_MSC_VER >= 1300 ) ) && ( defined(_Wp64) && ( _Wp64 ) ) ) 935 #define RAD_SINTa __w64 signed long 936 #define RAD_UINTa __w64 unsigned long 937 #else // non-vc.net compiler or /Wp64 turned off 938 #ifdef _Wp64 939 #define RAD_SINTa signed long 940 #define RAD_UINTa unsigned long 941 #else 942 #define RAD_SINTa signed int 943 #define RAD_UINTa unsigned int 944 #endif 945 #endif 946 #else 947 #define RAD_U32 unsigned long 948 #define RAD_S32 signed long 949 // Pointers in 16-bit land are still 32 bits. 950 #define RAD_UINTa unsigned long 951 #define RAD_SINTa signed long 952 #endif 953 954 #define RAD_F32 float 955 #if defined(__RADPS2__) || defined(__RADPSP__) 956 typedef RADSTRUCT RAD_F64 // do this so that we don't accidentally use doubles 957 { // while using the same space 958 RAD_U32 vals[ 2 ]; 959 } RAD_F64; 960 #define RAD_F64_OR_32 float // type is F64 if available, otherwise F32 961 #else 962 #define RAD_F64 double 963 #define RAD_F64_OR_32 double // type is F64 if available, otherwise F32 964 #endif 965 966 #if (defined(__RADMAC__) || defined(__MRC__) || defined( __RADNGC__ ) || \ 967 defined(__RADLINUX__) || defined( __RADWII__ ) || defined(__RADWIIU__) || \ 968 defined(__RADNDS__) || defined(__RADPSP__) || defined(__RADPS3__) || defined(__RADPS4__) || \ 969 defined(__RADSPU__) || defined(__RADIPHONE__) || defined(__RADNACL__) || defined( __RADANDROID__) || defined( __RADQNX__ ) ) 970 #define RAD_U64 unsigned long long 971 #define RAD_S64 signed long long 972 #elif defined(__RADPS2__) 973 #define RAD_U64 unsigned long 974 #define RAD_S64 signed long 975 #elif defined(__RADARM__) 976 #define RAD_U64 unsigned long long 977 #define RAD_S64 signed long long 978 #elif defined(__RADX64__) || defined(__RAD32__) 979 #define RAD_U64 unsigned __int64 980 #define RAD_S64 signed __int64 981 #else 982 // 16-bit 983 typedef RADSTRUCT RAD_U64 // do this so that we don't accidentally use U64s 984 { // while using the same space 985 RAD_U32 vals[ 2 ]; 986 } RAD_U64; 987 typedef RADSTRUCT RAD_S64 // do this so that we don't accidentally use S64s 988 { // while using the same space 989 RAD_S32 vals[ 2 ]; 990 } RAD_S64; 991 #endif 992 993 #if defined(__RAD32__) 994 #define PTR4 995 #define RAD_U16 unsigned short 996 #define RAD_S16 signed short 997 #else 998 #define PTR4 __far 999 #define RAD_U16 unsigned int 1000 #define RAD_S16 signed int 1001 #endif 1002 1003 //------------------------------------------------- 1004 // RAD_PTRBITS and such defined here without using sizeof() 1005 // so that they can be used in align() and other macros 1006 1007 #ifdef __RAD64__ 1008 1009 #define RAD_PTRBITS 64 1010 #define RAD_PTRBYTES 8 1011 #define RAD_TWOPTRBYTES 16 1012 1013 #else 1014 1015 #define RAD_PTRBITS 32 1016 #define RAD_PTRBYTES 4 1017 #define RAD_TWOPTRBYTES 8 1018 1019 #endif 1020 1021 1022 //------------------------------------------------- 1023 // UINTr = int the size of a register 1024 1025 #ifdef __RAD64REGS__ 1026 1027 #define RAD_UINTr RAD_U64 1028 #define RAD_SINTr RAD_S64 1029 1030 #else 1031 1032 #define RAD_UINTr RAD_U32 1033 #define RAD_SINTr RAD_S32 1034 1035 #endif 1036 1037 //=========================================================================== 1038 1039 /* 1040 // CB : meh this is enough of a mess that it's probably best to just let each 1041 #if defined(__RADX86__) && defined(_MSC_VER) && _MSC_VER >= 1300 1042 #define __RADX86INTRIN2003__ 1043 #endif 1044 */ 1045 1046 // RADASSUME(expr) tells the compiler that expr is always true 1047 // RADUNREACHABLE must never be reachable - even in event of error 1048 // eg. it's okay for compiler to generate completely invalid code after RADUNREACHABLE 1049 1050 #ifdef _MSC_VER 1051 #define RADFORCEINLINE __forceinline 1052 #if _MSC_VER >= 1300 1053 #define RADNOINLINE __declspec(noinline) 1054 #else 1055 #define RADNOINLINE 1056 #endif 1057 #define RADUNREACHABLE __assume(0) 1058 #define RADASSUME(exp) __assume(exp) 1059 #elif defined(__clang__) 1060 #ifdef _DEBUG 1061 #define RADFORCEINLINE inline 1062 #else 1063 #define RADFORCEINLINE inline __attribute((always_inline)) 1064 #endif 1065 #define RADNOINLINE __attribute__((noinline)) 1066 1067 #define RADUNREACHABLE __builtin_unreachable() 1068 1069 #if __has_builtin(__builtin_assume) 1070 #define RADASSUME(exp) __builtin_assume(exp) 1071 #else 1072 #define RADASSUME(exp) RAD_STATEMENT_WRAPPER( if ( ! (exp) ) __builtin_unreachable(); ) 1073 #endif 1074 #elif (defined(__GCC__) || defined(__GNUC__)) || defined(ANDROID) 1075 #ifdef _DEBUG 1076 #define RADFORCEINLINE inline 1077 #else 1078 #define RADFORCEINLINE inline __attribute((always_inline)) 1079 #endif 1080 #define RADNOINLINE __attribute__((noinline)) 1081 1082 #if __RAD_GCC_VERSION__ >= 40500 1083 #define RADUNREACHABLE __builtin_unreachable() 1084 #define RADASSUME(exp) RAD_STATEMENT_WRAPPER( if ( ! (exp) ) __builtin_unreachable(); ) 1085 #else 1086 #define RADUNREACHABLE RAD_INFINITE_LOOP( RR_BREAK(); ) 1087 #define RADASSUME(exp) 1088 #endif 1089 #elif defined(__CWCC__) 1090 #define RADFORCEINLINE inline 1091 #define RADNOINLINE __attribute__((never_inline)) 1092 #define RADUNREACHABLE 1093 #define RADASSUME(x) (void)0 1094 #else 1095 // ? #define RADFORCEINLINE ? 1096 #define RADFORCEINLINE inline 1097 #define RADNOINLINE 1098 #define RADASSUME(x) (void)0 1099 #endif 1100 1101 //=========================================================================== 1102 1103 // RAD_ALIGN_HINT tells the compiler how a given pointer is aligned 1104 // it *must* be true, but the compiler may or may not use that information 1105 // it is not for cases where the pointer is to an inherently aligned data type, 1106 // it's when the compiler cannot tell the alignment but you have extra information. 1107 // eg : 1108 // U8 * ptr = rrMallocAligned(256,16); 1109 // RAD_ALIGN_HINT(ptr,16,0); 1110 1111 #ifdef __RADSPU__ 1112 #define RAD_ALIGN_HINT(ptr,alignment,offset) __align_hint(ptr,alignment,offset); RR_ASSERT( ((UINTa)(ptr) & ((alignment)-1)) == (UINTa)(offset) ) 1113 #else 1114 #define RAD_ALIGN_HINT(ptr,alignment,offset) RADASSUME( ((UINTa)(ptr) & ((alignment)-1)) == (UINTa)(offset) ) 1115 #endif 1116 1117 //=========================================================================== 1118 1119 // RAD_EXPECT is to tell the compiler the *likely* value of an expression 1120 // different than RADASSUME in that expr might not have that value 1121 // it's use for branch code layout and static branch prediction 1122 // condition can technically be a variable but should usually be 0 or 1 1123 1124 #if (defined(__GCC__) || defined(__GNUC__)) || defined(__clang__) 1125 1126 // __builtin_expect returns value of expr 1127 #define RAD_EXPECT(expr,cond) __builtin_expect(expr,cond) 1128 1129 #else 1130 1131 #define RAD_EXPECT(expr,cond) (expr) 1132 1133 #endif 1134 1135 // helpers for doing an if ( ) with expect : 1136 // if ( RAD_LIKELY(expr) ) { ... } 1137 1138 #define RAD_LIKELY(expr) RAD_EXPECT(expr,1) 1139 #define RAD_UNLIKELY(expr) RAD_EXPECT(expr,0) 1140 1141 //=========================================================================== 1142 1143 // __RADX86ASM__ means you can use __asm {} style inline assembly 1144 #if defined(__RADX86__) && !defined(__RADX64__) && defined(_MSC_VER) 1145 #define __RADX86ASM__ 1146 #endif 1147 1148 //------------------------------------------------- 1149 // typedefs : 1150 1151 #ifndef RADNOTYPEDEFS 1152 1153 #ifndef S8_DEFINED 1154 #define S8_DEFINED 1155 typedef RAD_S8 S8; 1156 #endif 1157 1158 #ifndef U8_DEFINED 1159 #define U8_DEFINED 1160 typedef RAD_U8 U8; 1161 #endif 1162 1163 #ifndef S16_DEFINED 1164 #define S16_DEFINED 1165 typedef RAD_S16 S16; 1166 #endif 1167 1168 #ifndef U16_DEFINED 1169 #define U16_DEFINED 1170 typedef RAD_U16 U16; 1171 #endif 1172 1173 #ifndef S32_DEFINED 1174 #define S32_DEFINED 1175 typedef RAD_S32 S32; 1176 #endif 1177 1178 #ifndef U32_DEFINED 1179 #define U32_DEFINED 1180 typedef RAD_U32 U32; 1181 #endif 1182 1183 #ifndef S64_DEFINED 1184 #define S64_DEFINED 1185 typedef RAD_S64 S64; 1186 #endif 1187 1188 #ifndef U64_DEFINED 1189 #define U64_DEFINED 1190 typedef RAD_U64 U64; 1191 #endif 1192 1193 #ifndef F32_DEFINED 1194 #define F32_DEFINED 1195 typedef RAD_F32 F32; 1196 #endif 1197 1198 #ifndef F64_DEFINED 1199 #define F64_DEFINED 1200 typedef RAD_F64 F64; 1201 #endif 1202 1203 #ifndef F64_OR_32_DEFINED 1204 #define F64_OR_32_DEFINED 1205 typedef RAD_F64_OR_32 F64_OR_32; 1206 #endif 1207 1208 // UINTa and SINTa are the ints big enough for an address 1209 1210 #ifndef SINTa_DEFINED 1211 #define SINTa_DEFINED 1212 typedef RAD_SINTa SINTa; 1213 #endif 1214 1215 #ifndef UINTa_DEFINED 1216 #define UINTa_DEFINED 1217 typedef RAD_UINTa UINTa; 1218 #endif 1219 1220 #ifndef UINTr_DEFINED 1221 #define UINTr_DEFINED 1222 typedef RAD_UINTr UINTr; 1223 #endif 1224 1225 #ifndef SINTr_DEFINED 1226 #define SINTr_DEFINED 1227 typedef RAD_SINTr SINTr; 1228 #endif 1229 1230 #elif !defined(RADNOTYPEDEFINES) 1231 1232 #ifndef S8_DEFINED 1233 #define S8_DEFINED 1234 #define S8 RAD_S8 1235 #endif 1236 1237 #ifndef U8_DEFINED 1238 #define U8_DEFINED 1239 #define U8 RAD_U8 1240 #endif 1241 1242 #ifndef S16_DEFINED 1243 #define S16_DEFINED 1244 #define S16 RAD_S16 1245 #endif 1246 1247 #ifndef U16_DEFINED 1248 #define U16_DEFINED 1249 #define U16 RAD_U16 1250 #endif 1251 1252 #ifndef S32_DEFINED 1253 #define S32_DEFINED 1254 #define S32 RAD_S32 1255 #endif 1256 1257 #ifndef U32_DEFINED 1258 #define U32_DEFINED 1259 #define U32 RAD_U32 1260 #endif 1261 1262 #ifndef S64_DEFINED 1263 #define S64_DEFINED 1264 #define S64 RAD_S64 1265 #endif 1266 1267 #ifndef U64_DEFINED 1268 #define U64_DEFINED 1269 #define U64 RAD_U64 1270 #endif 1271 1272 #ifndef F32_DEFINED 1273 #define F32_DEFINED 1274 #define F32 RAD_F32 1275 #endif 1276 1277 #ifndef F64_DEFINED 1278 #define F64_DEFINED 1279 #define F64 RAD_F64 1280 #endif 1281 1282 #ifndef F64_OR_32_DEFINED 1283 #define F64_OR_32_DEFINED 1284 #define F64_OR_32 RAD_F64_OR_32 1285 #endif 1286 1287 // UINTa and SINTa are the ints big enough for an address (pointer) 1288 #ifndef SINTa_DEFINED 1289 #define SINTa_DEFINED 1290 #define SINTa RAD_SINTa 1291 #endif 1292 1293 #ifndef UINTa_DEFINED 1294 #define UINTa_DEFINED 1295 #define UINTa RAD_UINTa 1296 #endif 1297 1298 #ifndef UINTr_DEFINED 1299 #define UINTr_DEFINED 1300 #define UINTr RAD_UINTr 1301 #endif 1302 1303 #ifndef SINTr_DEFINED 1304 #define SINTr_DEFINED 1305 #define SINTr RAD_SINTr 1306 #endif 1307 1308 #endif 1309 1310 /// Some error-checking. 1311 #if defined(__RAD64__) && !defined(__RAD32__) 1312 // See top of file for why this is. 1313 #error __RAD64__ must not be defined without __RAD32__ (see radbase.h) 1314 #endif 1315 1316#ifdef _MSC_VER 1317 // microsoft compilers 1318 1319 #if _MSC_VER >= 1400 1320 #define RAD_STATEMENT_START \ 1321 do { 1322 1323 #define RAD_STATEMENT_END_FALSE \ 1324 __pragma(warning(push)) \ 1325 __pragma(warning(disable:4127)) \ 1326 } while(0) \ 1327 __pragma(warning(pop)) 1328 1329 #define RAD_STATEMENT_END_TRUE \ 1330 __pragma(warning(push)) \ 1331 __pragma(warning(disable:4127)) \ 1332 } while(1) \ 1333 __pragma(warning(pop)) 1334 1335 #else 1336 #define RAD_USE_STANDARD_LOOP_CONSTRUCT 1337 #endif 1338#else 1339 #define RAD_USE_STANDARD_LOOP_CONSTRUCT 1340#endif 1341 1342#ifdef RAD_USE_STANDARD_LOOP_CONSTRUCT 1343 #define RAD_STATEMENT_START \ 1344 do { 1345 1346 #define RAD_STATEMENT_END_FALSE \ 1347 } while ( (void)0,0 ) 1348 1349 #define RAD_STATEMENT_END_TRUE \ 1350 } while ( (void)1,1 ) 1351 1352#endif 1353 1354#define RAD_STATEMENT_WRAPPER( code ) \ 1355 RAD_STATEMENT_START \ 1356 code \ 1357 RAD_STATEMENT_END_FALSE 1358 1359#define RAD_INFINITE_LOOP( code ) \ 1360 RAD_STATEMENT_START \ 1361 code \ 1362 RAD_STATEMENT_END_TRUE 1363 1364 1365// Must be placed after variable declarations for code compiled as .c 1366#if defined(_MSC_VER) && _MSC_VER >= 1700 // in 2012 aka 11.0 and later 1367# define RR_UNUSED_VARIABLE(x) (void) x 1368#else 1369# define RR_UNUSED_VARIABLE(x) (void)(sizeof(x)) 1370#endif 1371 1372//----------------------------------------------- 1373// RR_UINT3264 is a U64 in 64-bit code and a U32 in 32-bit code 1374// eg. it's pointer sized and the same type as a U32/U64 of the same size 1375// 1376// @@ CB 05/21/2012 : I think RR_UINT3264 may be deprecated 1377// it was useful back when UINTa was /Wp64 1378// but since we removed that maybe it's not anymore ? 1379// 1380 1381#ifdef __RAD64__ 1382#define RR_UINT3264 U64 1383#else 1384#define RR_UINT3264 U32 1385#endif 1386 1387//RR_COMPILER_ASSERT( sizeof(RR_UINT3264) == sizeof(UINTa) ); 1388 1389//-------------------------------------------------- 1390 1391// RR_LINESTRING is the current line number as a string 1392#define RR_STRINGIZE( L ) #L 1393#define RR_DO_MACRO( M, X ) M(X) 1394#define RR_STRINGIZE_DELAY( X ) RR_DO_MACRO( RR_STRINGIZE, X ) 1395#define RR_LINESTRING RR_STRINGIZE_DELAY( __LINE__ ) 1396 1397#define RR_CAT(X,Y) X ## Y 1398 1399// RR_STRING_JOIN joins strings in the preprocessor and works with LINESTRING 1400#define RR_STRING_JOIN(arg1, arg2) RR_STRING_JOIN_DELAY(arg1, arg2) 1401#define RR_STRING_JOIN_DELAY(arg1, arg2) RR_STRING_JOIN_IMMEDIATE(arg1, arg2) 1402#define RR_STRING_JOIN_IMMEDIATE(arg1, arg2) arg1 ## arg2 1403 1404// RR_NUMBERNAME is a macro to make a name unique, so that you can use it to declare 1405// variable names and they won't conflict with each other 1406// using __LINE__ is broken in MSVC with /ZI , but __COUNTER__ is an MSVC extension that works 1407 1408#ifdef _MSC_VER 1409 #define RR_NUMBERNAME(name) RR_STRING_JOIN(name,__COUNTER__) 1410#else 1411 #define RR_NUMBERNAME(name) RR_STRING_JOIN(name,__LINE__) 1412#endif 1413 1414//-------------------------------------------------- 1415// current plan is to use "rrbool" with plain old "true" and "false" 1416// if true and false give us trouble we might have to go to rrtrue and rrfalse 1417// BTW there's a danger for evil bugs here !! If you're checking == true 1418// then the rrbool must be set to exactly "1" not just "not zero" !! 1419 1420#ifndef RADNOTYPEDEFS 1421 #ifndef RRBOOL_DEFINED 1422 #define RRBOOL_DEFINED 1423 typedef S32 rrbool; 1424 typedef S32 RRBOOL; 1425 #endif 1426#elif !defined(RADNOTYPEDEFINES) 1427 #ifndef RRBOOL_DEFINED 1428 #define RRBOOL_DEFINED 1429 #define rrbool S32 1430 #define RRBOOL S32 1431 #endif 1432#endif 1433 1434//-------------------------------------------------- 1435// Range macros 1436 1437 #ifndef RR_MIN 1438 #define RR_MIN(a,b) ( (a) < (b) ? (a) : (b) ) 1439 #endif 1440 1441 #ifndef RR_MAX 1442 #define RR_MAX(a,b) ( (a) > (b) ? (a) : (b) ) 1443 #endif 1444 1445 #ifndef RR_ABS 1446 #define RR_ABS(a) ( ((a) < 0) ? -(a) : (a) ) 1447 #endif 1448 1449 #ifndef RR_CLAMP 1450 #define RR_CLAMP(val,lo,hi) RR_MAX( RR_MIN(val,hi), lo ) 1451 #endif 1452 1453//-------------------------------------------------- 1454// Data layout macros 1455 1456 #define RR_ARRAY_SIZE(array) ( sizeof(array)/sizeof(array[0]) ) 1457 1458 // MEMBER_OFFSET tells you the offset of a member in a type 1459 #ifdef __RAD3DS__ 1460 #define RR_MEMBER_OFFSET(type,member) (unsigned int)(( (char *) &(((type *)0)->member) - (char *) 0 )) 1461 #elif defined(__RADANDROID__) || defined(__RADPSP__) || defined(__RADPS3__) || defined(__RADSPU__) 1462 // offsetof() gets mucked with by system headers on android, making things dependent on #include order. 1463 #define RR_MEMBER_OFFSET(type,member) __builtin_offsetof(type, member) 1464 #elif defined(__RADLINUX__) 1465 #define RR_MEMBER_OFFSET(type,member) (offsetof(type, member)) 1466 #else 1467 #define RR_MEMBER_OFFSET(type,member) ( (size_t) (UINTa) &(((type *)0)->member) ) 1468 #endif 1469 1470 // MEMBER_SIZE tells you the size of a member in a type 1471 #define RR_MEMBER_SIZE(type,member) ( sizeof( ((type *) 0)->member) ) 1472 1473 // just to make gcc shut up about derefing null : 1474 #define RR_MEMBER_OFFSET_PTR(type,member,ptr) ( (SINTa) &(((type *)(ptr))->member) - (SINTa)(ptr) ) 1475 #define RR_MEMBER_SIZE_PTR(type,member,ptr) ( sizeof( ((type *) (ptr))->member) ) 1476 1477 // MEMBER_TO_OWNER takes a pointer to a member and gives you back the base of the object 1478 // you should then RR_ASSERT( &(ret->member) == ptr ); 1479 #define RR_MEMBER_TO_OWNER(type,member,ptr) (type *)( ((char *)(ptr)) - RR_MEMBER_OFFSET_PTR(type,member,ptr) ) 1480 1481//-------------------------------------------------- 1482// Cache / prefetch macros : 1483 1484// RR_PREFETCH for various platforms : 1485// 1486// RR_PREFETCH_SEQUENTIAL : prefetch memory for reading in a sequential scan 1487// platforms that automatically prefetch sequential (eg. PC) should be a no-op here 1488// RR_PREFETCH_WRITE_INVALIDATE : prefetch memory for writing - contents of memory are undefined 1489// (may be a no-op, may be a normal prefetch, may zero memory) 1490// warning : RR_PREFETCH_WRITE_INVALIDATE may write memory so don't do it past the end of buffers 1491 1492#ifdef __RADX86__ 1493 1494#define RR_PREFETCH_SEQUENTIAL(ptr,offset) // nop 1495#define RR_PREFETCH_WRITE_INVALIDATE(ptr,offset) // nop 1496 1497#elif defined(__RADXENON__) 1498 1499#define RR_PREFETCH_SEQUENTIAL(ptr,offset) __dcbt((int)(offset),(void *)(ptr)) 1500#define RR_PREFETCH_WRITE_INVALIDATE(ptr,offset) __dcbz128((int)(offset),(void *)(ptr)) 1501 1502#elif defined(__RADPS3__) 1503 1504#define RR_PREFETCH_SEQUENTIAL(ptr,offset) __dcbt((char *)(ptr) + (int)(offset)) 1505#define RR_PREFETCH_WRITE_INVALIDATE(ptr,offset) __dcbz((char *)(ptr) + (int)(offset)) 1506 1507#elif defined(__RADSPU__) 1508 1509#define RR_PREFETCH_SEQUENTIAL(ptr,offset) // intentional NOP 1510#define RR_PREFETCH_WRITE_INVALIDATE(ptr,offset) // nop 1511 1512#elif defined(__RADWII__) || defined(__RADWIIU__) 1513 1514#define RR_PREFETCH_SEQUENTIAL(ptr,offset) // intentional NOP for now 1515#define RR_PREFETCH_WRITE_INVALIDATE(ptr,offset) // nop 1516 1517#elif defined(__RAD3DS__) 1518 1519#define RR_PREFETCH_SEQUENTIAL(ptr,offset) __pld((char *)(ptr) + (int)(offset)) 1520#define RR_PREFETCH_WRITE_INVALIDATE(ptr,offset) __pldw((char *)(ptr) + (int)(offset)) 1521 1522#else 1523 1524// other platform 1525#define RR_PREFETCH_SEQUENTIAL(ptr,offset) // need_prefetch // compile error 1526#define RR_PREFETCH_WRITE_INVALIDATE(ptr,offset) // need_writezero // error 1527 1528#endif 1529 1530//-------------------------------------------------- 1531// LIGHTWEIGHT ASSERTS without rrAssert.h 1532 1533RADDEFSTART 1534 1535// set up RR_BREAK : 1536 1537 #ifdef __RADNGC__ 1538 1539 #define RR_BREAK() asm(" .long 0x00000001") 1540 #define RR_CACHE_LINE_SIZE xxx 1541 1542 #elif defined(__RADWII__) 1543 1544 #define RR_BREAK() __asm__ volatile("trap") 1545 #define RR_CACHE_LINE_SIZE 32 1546 1547 #elif defined(__RADWIIU__) 1548 1549 #define RR_BREAK() asm("trap") 1550 #define RR_CACHE_LINE_SIZE 32 1551 1552 #elif defined(__RAD3DS__) 1553 1554 #define RR_BREAK() *((int volatile*)0)=0 1555 #define RR_CACHE_LINE_SIZE 32 1556 1557 #elif defined(__RADNDS__) 1558 1559 #define RR_BREAK() asm("BKPT 0") 1560 #define RR_CACHE_LINE_SIZE xxx 1561 1562 #elif defined(__RADPS2__) 1563 1564 #define RR_BREAK() __asm__ volatile("break") 1565 #define RR_CACHE_LINE_SIZE 64 1566 1567 #elif defined(__RADPSP__) 1568 1569 #define RR_BREAK() __asm__("break 0") 1570 #define RR_CACHE_LINE_SIZE 64 1571 1572 #elif defined(__RADPSP2__) 1573 1574 #define RR_BREAK() { __asm__ volatile("bkpt 0x0000"); } 1575 #define RR_CACHE_LINE_SIZE 32 1576 1577 #elif defined (__RADQNX__) 1578 #define RR_BREAK() __builtin_trap() 1579 #define RR_CACHE_LINE_SIZE 32 1580 #elif defined (__RADARM__) && defined (__RADLINUX__) 1581 #define RR_BREAK() __builtin_trap() 1582 #define RR_CACHE_LINE_SIZE 32 1583 #elif defined(__RADSPU__) 1584 1585 #define RR_BREAK() __asm volatile ("stopd 0,1,1") 1586 #define RR_CACHE_LINE_SIZE 128 1587 1588 #elif defined(__RADPS3__) 1589 1590 // #ifdef snPause // in LibSN.h 1591 // snPause 1592 // __asm__ volatile ( "tw 31,1,1" ) 1593 1594 #define RR_BREAK() __asm__ volatile ( "tw 31,1,1" ) 1595 //#define RR_BREAK() __asm__ volatile("trap"); 1596 1597 #define RR_CACHE_LINE_SIZE 128 1598 1599 #elif defined(__RADMAC__) 1600 1601 #if defined(__GNUG__) || defined(__GNUC__) 1602 #ifdef __RADX86__ 1603 #define RR_BREAK() __asm__ volatile ( "int $3" ) 1604 #else 1605 #define RR_BREAK() __builtin_trap() 1606 #endif 1607 #else 1608 #ifdef __RADMACH__ 1609 void DebugStr(unsigned char const *); 1610 #else 1611 void pascal DebugStr(unsigned char const *); 1612 #endif 1613 #define RR_BREAK() DebugStr("\pRR_BREAK() was called") 1614 #endif 1615 1616 #define RR_CACHE_LINE_SIZE 64 1617 1618 #elif defined(__RADIPHONE__) 1619 #define RR_BREAK() __builtin_trap() 1620 #define RR_CACHE_LINE_SIZE 32 1621 #elif defined(__RADXENON__) 1622 #define RR_BREAK() __debugbreak() 1623 #define RR_CACHE_LINE_SIZE 128 1624 #elif defined(__RADANDROID__) 1625 #define RR_BREAK() __builtin_trap() 1626 #define RR_CACHE_LINE_SIZE 32 1627 #elif defined(__RADPS4__) 1628 #define RR_BREAK() __builtin_trap() 1629 #define RR_CACHE_LINE_SIZE 64 1630 #elif defined(__RADNACL__) 1631 #define RR_BREAK() __builtin_trap() 1632 #define RR_CACHE_LINE_SIZE 64 1633 #else 1634 // x86 : 1635 #define RR_CACHE_LINE_SIZE 64 1636 1637 #ifdef __RADLINUX__ 1638 #define RR_BREAK() __asm__ volatile ( "int $3" ) 1639 #elif defined(__WATCOMC__) 1640 1641 void RR_BREAK( void ); 1642 #pragma aux RR_BREAK = "int 0x3"; 1643 1644 #elif defined(__RADWIN__) && defined(_MSC_VER) && _MSC_VER >= 1300 1645 1646 #define RR_BREAK __debugbreak 1647 1648 #else 1649 1650 #define RR_BREAK() RAD_STATEMENT_WRAPPER( __asm {int 3} ) 1651 1652 #endif 1653 1654 #endif 1655 1656// simple RR_ASSERT : 1657 1658// CB 5-27-10 : use RR_DO_ASSERTS to toggle asserts on and off : 1659#if (defined(_DEBUG) && !defined(NDEBUG)) || defined(ASSERT_IN_RELEASE) 1660 #define RR_DO_ASSERTS 1661#endif 1662 1663/********* 1664 1665rrAsserts : 1666 1667RR_ASSERT(exp) - the normal assert thing, toggled with RR_DO_ASSERTS 1668RR_ASSERT_ALWAYS(exp) - assert that you want to test even in ALL builds (including final!) 1669RR_ASSERT_RELEASE(exp) - assert that you want to test even in release builds (not for final!) 1670RR_ASSERT_LITE(exp) - normal assert is not safe from threads or inside malloc; use this instead 1671RR_DURING_ASSERT(exp) - wrap operations that compute stuff for assert in here 1672RR_DO_ASSERTS - toggle tells you if asserts are enabled or not 1673 1674RR_BREAK() - generate a debug break - always ! 1675RR_ASSERT_BREAK() - RR_BREAK for asserts ; disable with RAD_NO_BREAK 1676 1677RR_ASSERT_FAILURE(str) - just break with a messsage; like assert with no condition 1678RR_ASSERT_FAILURE_ALWAYS(str) - RR_ASSERT_FAILURE in release builds too 1679RR_CANT_GET_HERE() - put in spots execution should never go 1680RR_COMPILER_ASSERT(exp) - checks constant conditions at compile time 1681 1682RADTODO - note to search for nonfinal stuff 1683RR_PRAGMA_MESSAGE - message dealy, use with #pragma in MSVC 1684 1685*************/ 1686 1687//----------------------------------------------------------- 1688 1689 1690#if defined(__GNUG__) || defined(__GNUC__) || (defined(_MSC_VER) && _MSC_VER > 1200) 1691 #define RR_FUNCTION_NAME __FUNCTION__ 1692#else 1693 #define RR_FUNCTION_NAME 0 1694 1695 // __func__ is in the C99 standard 1696#endif 1697 1698//----------------------------------------------------------- 1699 1700// rrDisplayAssertion might just log, or it might pop a message box, depending on settings 1701// rrDisplayAssertion returns whether you should break or not 1702typedef rrbool (RADLINK fp_rrDisplayAssertion)(int * Ignored, const char * fileName,const int line,const char * function,const char * message); 1703 1704extern fp_rrDisplayAssertion * g_fp_rrDisplayAssertion; 1705 1706// if I have func pointer, call it, else true ; true = do int 3 1707#define rrDisplayAssertion(i,n,l,f,m) ( ( g_fp_rrDisplayAssertion ) ? (*g_fp_rrDisplayAssertion)(i,n,l,f,m) : 1 ) 1708 1709//----------------------------------------------------------- 1710 1711// RAD_NO_BREAK : option if you don't like your assert to break 1712// CB : RR_BREAK is *always* a break ; RR_ASSERT_BREAK is optional 1713#ifdef RAD_NO_BREAK 1714#define RR_ASSERT_BREAK() 0 1715#else 1716#define RR_ASSERT_BREAK() RR_BREAK() 1717#endif 1718 1719// assert_always is on FINAL ! 1720#define RR_ASSERT_ALWAYS(exp) RAD_STATEMENT_WRAPPER( static int Ignored=0; if ( ! (exp) ) { if ( rrDisplayAssertion(&Ignored,__FILE__,__LINE__,RR_FUNCTION_NAME,#exp) ) RR_ASSERT_BREAK(); } ) 1721 1722// RR_ASSERT_FAILURE is like an assert without a condition - if you hit it, you're bad 1723#define RR_ASSERT_FAILURE_ALWAYS(str) RAD_STATEMENT_WRAPPER( static int Ignored=0; if ( rrDisplayAssertion(&Ignored,__FILE__,__LINE__,RR_FUNCTION_NAME,str) ) RR_ASSERT_BREAK(); ) 1724 1725#define RR_ASSERT_LITE_ALWAYS(exp) RAD_STATEMENT_WRAPPER( if ( ! (exp) ) { RR_ASSERT_BREAK(); } ) 1726 1727//----------------------------------- 1728#ifdef RR_DO_ASSERTS 1729 1730#define RR_ASSERT(exp) RR_ASSERT_ALWAYS(exp) 1731#define RR_ASSERT_LITE(exp) RR_ASSERT_LITE_ALWAYS(exp) 1732#define RR_ASSERT_NO_ASSUME(exp) RR_ASSERT_ALWAYS(exp) 1733// RR_DURING_ASSERT is to set up expressions or declare variables that are only used in asserts 1734#define RR_DURING_ASSERT(exp) exp 1735 1736#define RR_ASSERT_FAILURE(str) RR_ASSERT_FAILURE_ALWAYS(str) 1737 1738// RR_CANT_GET_HERE is for like defaults in switches that should never be hit 1739#define RR_CANT_GET_HERE() RAD_STATEMENT_WRAPPER( RR_ASSERT_FAILURE("can't get here"); RADUNREACHABLE; ) 1740 1741 1742#else // RR_DO_ASSERTS //----------------------------------- 1743 1744#define RR_ASSERT(exp) (void)0 1745#define RR_ASSERT_LITE(exp) (void)0 1746#define RR_ASSERT_NO_ASSUME(exp) (void)0 1747 1748#define RR_DURING_ASSERT(exp) (void)0 1749 1750#define RR_ASSERT_FAILURE(str) (void)0 1751 1752#define RR_CANT_GET_HERE() RADUNREACHABLE 1753 1754#endif // RR_DO_ASSERTS //----------------------------------- 1755 1756//================================================================= 1757 1758// RR_ASSERT_RELEASE is on in release build, but not final 1759 1760#ifndef __RADFINAL__ 1761 1762#define RR_ASSERT_RELEASE(exp) RR_ASSERT_ALWAYS(exp) 1763#define RR_ASSERT_LITE_RELEASE(exp) RR_ASSERT_LITE_ALWAYS(exp) 1764 1765#else 1766 1767#define RR_ASSERT_RELEASE(exp) (void)0 1768#define RR_ASSERT_LITE_RELEASE(exp) (void)0 1769 1770#endif 1771 1772// BH: This never gets compiled away except for __RADFINAL__ 1773#define RR_ASSERT_ALWAYS_NO_SHIP RR_ASSERT_RELEASE 1774 1775#define rrAssert RR_ASSERT 1776#define rrassert RR_ASSERT 1777 1778#ifdef _MSC_VER 1779 // without this, our assert errors... 1780 #if _MSC_VER >= 1300 1781 #pragma warning( disable : 4127) // conditional expression is constant 1782 #endif 1783#endif 1784 1785//--------------------------------------- 1786// Get/Put from memory in little or big endian : 1787// 1788// val = RR_GET32_BE(ptr) 1789// RR_PUT32_BE(ptr,val) 1790// 1791// available here : 1792// RR_[GET/PUT][16/32]_[BE/LE][_UNALIGNED][_OFFSET] 1793// 1794// if you don't specify _UNALIGNED , then ptr & offset shoud both be aligned to type size 1795// _OFFSET is in *bytes* ! 1796 1797// you can #define RR_GET_RESTRICT to make all RR_GETs be RESTRICT 1798// if you set nothing they are not 1799 1800#ifdef RR_GET_RESTRICT 1801#define RR_GET_PTR_POST RADRESTRICT 1802#endif 1803#ifndef RR_GET_PTR_POST 1804#define RR_GET_PTR_POST 1805#endif 1806 1807// native version of get/put is always trivial : 1808 1809#define RR_GET16_NATIVE(ptr) *((const U16 * RR_GET_PTR_POST)(ptr)) 1810#define RR_PUT16_NATIVE(ptr,val) *((U16 * RR_GET_PTR_POST)(ptr)) = (val) 1811 1812// offset is in bytes 1813#define RR_U16_PTR_OFFSET(ptr,offset) ((U16 * RR_GET_PTR_POST)((char *)(ptr) + (offset))) 1814#define RR_GET16_NATIVE_OFFSET(ptr,offset) *( RR_U16_PTR_OFFSET((ptr),offset) ) 1815#define RR_PUT16_NATIVE_OFFSET(ptr,val,offset) *( RR_U16_PTR_OFFSET((ptr),offset)) = (val) 1816 1817#define RR_GET32_NATIVE(ptr) *((const U32 * RR_GET_PTR_POST)(ptr)) 1818#define RR_PUT32_NATIVE(ptr,val) *((U32 * RR_GET_PTR_POST)(ptr)) = (val) 1819 1820// offset is in bytes 1821#define RR_U32_PTR_OFFSET(ptr,offset) ((U32 * RR_GET_PTR_POST)((char *)(ptr) + (offset))) 1822#define RR_GET32_NATIVE_OFFSET(ptr,offset) *( RR_U32_PTR_OFFSET((ptr),offset) ) 1823#define RR_PUT32_NATIVE_OFFSET(ptr,val,offset) *( RR_U32_PTR_OFFSET((ptr),offset)) = (val) 1824 1825#define RR_GET64_NATIVE(ptr) *((const U64 * RR_GET_PTR_POST)(ptr)) 1826#define RR_PUT64_NATIVE(ptr,val) *((U64 * RR_GET_PTR_POST)(ptr)) = (val) 1827 1828// offset is in bytes 1829#define RR_U64_PTR_OFFSET(ptr,offset) ((U64 * RR_GET_PTR_POST)((char *)(ptr) + (offset))) 1830#define RR_GET64_NATIVE_OFFSET(ptr,offset) *( RR_U64_PTR_OFFSET((ptr),offset) ) 1831#define RR_PUT64_NATIVE_OFFSET(ptr,val,offset) *( RR_U64_PTR_OFFSET((ptr),offset)) = (val) 1832 1833//--------------------------------------------------- 1834 1835#ifdef __RADLITTLEENDIAN__ 1836 1837#define RR_GET16_LE RR_GET16_NATIVE 1838#define RR_PUT16_LE RR_PUT16_NATIVE 1839#define RR_GET16_LE_OFFSET RR_GET16_NATIVE_OFFSET 1840#define RR_PUT16_LE_OFFSET RR_PUT16_NATIVE_OFFSET 1841 1842#define RR_GET32_LE RR_GET32_NATIVE 1843#define RR_PUT32_LE RR_PUT32_NATIVE 1844#define RR_GET32_LE_OFFSET RR_GET32_NATIVE_OFFSET 1845#define RR_PUT32_LE_OFFSET RR_PUT32_NATIVE_OFFSET 1846 1847#define RR_GET64_LE RR_GET64_NATIVE 1848#define RR_PUT64_LE RR_PUT64_NATIVE 1849#define RR_GET64_LE_OFFSET RR_GET64_NATIVE_OFFSET 1850#define RR_PUT64_LE_OFFSET RR_PUT64_NATIVE_OFFSET 1851 1852#else 1853 1854#define RR_GET16_BE RR_GET16_NATIVE 1855#define RR_PUT16_BE RR_PUT16_NATIVE 1856#define RR_GET16_BE_OFFSET RR_GET16_NATIVE_OFFSET 1857#define RR_PUT16_BE_OFFSET RR_PUT16_NATIVE_OFFSET 1858 1859#define RR_GET32_BE RR_GET32_NATIVE 1860#define RR_PUT32_BE RR_PUT32_NATIVE 1861#define RR_GET32_BE_OFFSET RR_GET32_NATIVE_OFFSET 1862#define RR_PUT32_BE_OFFSET RR_PUT32_NATIVE_OFFSET 1863 1864#define RR_GET64_BE RR_GET64_NATIVE 1865#define RR_PUT64_BE RR_PUT64_NATIVE 1866#define RR_GET64_BE_OFFSET RR_GET64_NATIVE_OFFSET 1867#define RR_PUT64_BE_OFFSET RR_PUT64_NATIVE_OFFSET 1868 1869#endif 1870 1871//------------------------- 1872// non-native Get/Put implementations go here : 1873 1874#if defined(__RADX86__) 1875// good implementation for X86 : 1876 1877#if (_MSC_VER >= 1300) 1878 1879unsigned short __cdecl _byteswap_ushort (unsigned short _Short); 1880unsigned long __cdecl _byteswap_ulong (unsigned long _Long); 1881#pragma intrinsic(_byteswap_ushort, _byteswap_ulong) 1882 1883#define RR_BSWAP16 _byteswap_ushort 1884#define RR_BSWAP32 _byteswap_ulong 1885 1886unsigned __int64 __cdecl _byteswap_uint64 (unsigned __int64 val); 1887#pragma intrinsic(_byteswap_uint64) 1888#define RR_BSWAP64 _byteswap_uint64 1889 1890#elif defined(_MSC_VER) // VC6 1891 1892RADFORCEINLINE unsigned long RR_BSWAP16 (unsigned long _Long) 1893{ 1894 __asm { 1895 mov eax, [_Long] 1896 rol ax, 8 1897 mov [_Long], eax; 1898 } 1899 return _Long; 1900} 1901 1902RADFORCEINLINE unsigned long RR_BSWAP32 (unsigned long _Long) 1903{ 1904 __asm { 1905 mov eax, [_Long] 1906 bswap eax 1907 mov [_Long], eax 1908 } 1909 return _Long; 1910} 1911 1912RADFORCEINLINE unsigned __int64 RR_BSWAP64 (unsigned __int64 _Long) 1913{ 1914 __asm { 1915 mov eax, DWORD PTR _Long 1916 mov edx, DWORD PTR _Long+4 1917 bswap eax 1918 bswap edx 1919 mov DWORD PTR _Long, edx 1920 mov DWORD PTR _Long+4, eax 1921 } 1922 return _Long; 1923} 1924 1925#elif defined(__GNUC__) || defined(__clang__) 1926 1927// GCC has __builtin_bswap16, but Clang only seems to have added it recently. 1928// We use __builtin_bswap32/64 but 16 just uses the macro version. (No big 1929// deal if that turns into shifts anyway) 1930#define RR_BSWAP16(u16) ( (U16) ( ((u16) >> 8) | ((u16) << 8) ) ) 1931#define RR_BSWAP32 __builtin_bswap32 1932#define RR_BSWAP64 __builtin_bswap64 1933 1934#endif 1935 1936#define RR_GET16_BE(ptr) RR_BSWAP16(*((U16 *)(ptr))) 1937#define RR_PUT16_BE(ptr,val) *((U16 *)(ptr)) = (U16) RR_BSWAP16(val) 1938#define RR_GET16_BE_OFFSET(ptr,offset) RR_BSWAP16(*RR_U16_PTR_OFFSET(ptr,offset)) 1939#define RR_PUT16_BE_OFFSET(ptr,val,offset) *RR_U16_PTR_OFFSET(ptr,offset) = RR_BSWAP16(val) 1940 1941#define RR_GET32_BE(ptr) RR_BSWAP32(*((U32 *)(ptr))) 1942#define RR_PUT32_BE(ptr,val) *((U32 *)(ptr)) = RR_BSWAP32(val) 1943#define RR_GET32_BE_OFFSET(ptr,offset) RR_BSWAP32(*RR_U32_PTR_OFFSET(ptr,offset)) 1944#define RR_PUT32_BE_OFFSET(ptr,val,offset) *RR_U32_PTR_OFFSET(ptr,offset) = RR_BSWAP32(val) 1945 1946#define RR_GET64_BE(ptr) RR_BSWAP64(*((U64 *)(ptr))) 1947#define RR_PUT64_BE(ptr,val) *((U64 *)(ptr)) = RR_BSWAP64(val) 1948#define RR_GET64_BE_OFFSET(ptr,offset) RR_BSWAP64(*RR_U64_PTR_OFFSET(ptr,offset)) 1949#define RR_PUT64_BE_OFFSET(ptr,val,offset) *RR_U64_PTR_OFFSET(ptr,offset) = RR_BSWAP64(val) 1950 1951// end _MSC_VER 1952 1953#elif defined(__RADXENON__) // Xenon has built-in funcs for this 1954 1955unsigned short __loadshortbytereverse(int offset, const void *base); 1956unsigned long __loadwordbytereverse (int offset, const void *base); 1957 1958void __storeshortbytereverse(unsigned short val, int offset, void *base); 1959void __storewordbytereverse (unsigned int val, int offset, void *base); 1960 1961#define RR_GET16_LE(ptr) __loadshortbytereverse(0, ptr) 1962#define RR_PUT16_LE(ptr,val) __storeshortbytereverse((U16) (val), 0, ptr) 1963 1964#define RR_GET16_LE_OFFSET(ptr,offset) __loadshortbytereverse(offset, ptr) 1965#define RR_PUT16_LE_OFFSET(ptr,val,offset) __storeshortbytereverse((U16) (val), offset, ptr) 1966 1967#define RR_GET32_LE(ptr) __loadwordbytereverse(0, ptr) 1968#define RR_PUT32_LE(ptr,val) __storewordbytereverse((U32) (val), 0, ptr) 1969 1970#define RR_GET32_LE_OFFSET(ptr,offset) __loadwordbytereverse(offset, ptr) 1971#define RR_PUT32_LE_OFFSET(ptr,val,offset) __storewordbytereverse((U32) (val), offset, ptr) 1972 1973#define RR_GET64_LE(ptr) ( ((U64)RR_GET32_OFFSET_LE(ptr,4)<<32) | RR_GET32_LE(ptr) ) 1974#define RR_PUT64_LE(ptr,val) RR_PUT32_LE(ptr, (U32) (val)), RR_PUT32_OFFSET_LE(ptr, (U32) ((val)>>32),4) 1975 1976#elif defined(__RADPS3__) 1977 1978#include <ppu_intrinsics.h> 1979 1980#define RR_GET16_LE(ptr) __lhbrx(ptr) 1981#define RR_PUT16_LE(ptr,val) __sthbrx(ptr, (U16) (val)) 1982 1983#define RR_GET16_LE_OFFSET(ptr,offset) __lhbrx(RR_U16_PTR_OFFSET(ptr, offset)) 1984#define RR_PUT16_LE_OFFSET(ptr,val,offset) __sthbrx(RR_U16_PTR_OFFSET(ptr, offset), (U16) (val)) 1985 1986#define RR_GET32_LE(ptr) __lwbrx(ptr) 1987#define RR_PUT32_LE(ptr,val) __stwbrx(ptr, (U32) (val)) 1988 1989#define RR_GET64_LE(ptr) __ldbrx(ptr) 1990#define RR_PUT64_LE(ptr,val) __stdbrx(ptr, (U32) (val)) 1991 1992#define RR_GET32_LE_OFFSET(ptr,offset) __lwbrx(RR_U32_PTR_OFFSET(ptr, offset)) 1993#define RR_PUT32_LE_OFFSET(ptr,val,offset) __stwbrx(RR_U32_PTR_OFFSET(ptr, offset), (U32) (val)) 1994 1995#elif defined(__RADWII__) 1996 1997#define RR_GET16_LE(ptr) __lhbrx(ptr, 0) 1998#define RR_PUT16_LE(ptr,val) __sthbrx((U16) (val), ptr, 0) 1999 2000#define RR_GET16_LE_OFFSET(ptr,offset) __lhbrx(ptr, offset) 2001#define RR_PUT16_LE_OFFSET(ptr,val,offset) __sthbrx((U16) (val), ptr, offset) 2002 2003#define RR_GET32_LE(ptr) __lwbrx(ptr, 0) 2004#define RR_PUT32_LE(ptr,val) __stwbrx((U32) (val), ptr, 0) 2005 2006#define RR_GET32_LE_OFFSET(ptr,offset) __lwbrx(ptr, offset) 2007#define RR_PUT32_LE_OFFSET(ptr,val,offset) __stwbrx((U32) (val), ptr, offset) 2008 2009#elif defined(__RAD3DS__) 2010 2011#define RR_GET16_BE(ptr) __rev16(*(U16 *) (ptr)) 2012#define RR_PUT16_BE(ptr,val) *(U16 *) (ptr) = __rev16(val) 2013 2014#define RR_GET16_BE_OFFSET(ptr,offset) __rev16(*RR_U16_PTR_OFFSET(ptr,offset)) 2015#define RR_PUT16_BE_OFFSET(ptr,offset,val) *RR_U16_PTR_OFFSET(ptr,offset) = __rev16(val) 2016 2017#define RR_GET32_BE(ptr) __rev(*(U32 *) (ptr)) 2018#define RR_PUT32_BE(ptr,val) *(U32 *) (ptr) = __rev(val) 2019 2020#define RR_GET32_BE_OFFSET(ptr,offset) __rev(*RR_U32_PTR_OFFSET(ptr,offset)) 2021#define RR_PUT32_BE_OFFSET(ptr,offset,val) *RR_U32_PTR_OFFSET(ptr,offset) = __rev(val) 2022 2023#elif defined(__RADIPHONE__) 2024 2025// iPhone does not seem to have intrinsics for this, so use generic fallback! 2026 2027// Bswap is just here for use of implementing get/put 2028// caller should use Get/Put , not bswap 2029#define RR_BSWAP16(u16) ( (U16) ( ((u16) >> 8) | ((u16) << 8) ) ) 2030#define RR_BSWAP32(u32) ( (U32) ( ((u32) >> 24) | (((u32)<<8) & 0x00FF0000) | (((u32)>>8) & 0x0000FF00) | ((u32) << 24) ) ) 2031 2032#define RR_GET16_BE(ptr) RR_BSWAP16(*((U16 *)(ptr))) 2033#define RR_PUT16_BE(ptr,val) *((U16 *)(ptr)) = RR_BSWAP16(val) 2034 2035#define RR_GET32_BE(ptr) RR_BSWAP32(*((U32 *)(ptr))) 2036#define RR_PUT32_BE(ptr,val) *((U32 *)(ptr)) = RR_BSWAP32(val) 2037 2038#elif defined(__RADWIIU__) 2039 2040#include <ppc_ghs.h> 2041 2042#define RR_GET16_LE(ptr) (*(__bytereversed U16 *) (ptr)) 2043#define RR_PUT16_LE(ptr,val) *(__bytereversed U16 *) (ptr) = val 2044 2045#define RR_GET16_LE_OFFSET(ptr,offset) (*(__bytereversed U16 *)RR_U16_PTR_OFFSET(ptr,offset)) 2046#define RR_PUT16_LE_OFFSET(ptr,val,offset) *(__bytereversed U16 *)RR_U16_PTR_OFFSET(ptr,offset) = val 2047 2048#define RR_GET32_LE(ptr) (*(__bytereversed U32 *) (ptr)) 2049#define RR_PUT32_LE(ptr,val) *(__bytereversed U32 *) (ptr) = val 2050 2051#define RR_GET32_LE_OFFSET(ptr,offset) (*(__bytereversed U32 *)RR_U32_PTR_OFFSET(ptr,offset)) 2052#define RR_PUT32_LE_OFFSET(ptr,val,offset) *(__bytereversed U32 *)RR_U32_PTR_OFFSET(ptr,offset) = val 2053 2054#define RR_GET64_LE(ptr) (*(__bytereversed U64 *) (ptr)) 2055#define RR_PUT64_LE(ptr,val) *(__bytereversed U64 *) (ptr) = val 2056 2057#define RR_GET64_LE_OFFSET(ptr,offset) (*(__bytereversed U64 *)RR_U32_PTR_OFFSET(ptr,offset)) 2058#define RR_PUT64_LE_OFFSET(ptr,val,offset) *(__bytereversed U64 *)RR_U32_PTR_OFFSET(ptr,offset) = val 2059 2060#elif defined(__RADWINRTAPI__) && defined(__RADARM__) 2061 2062#include <intrin.h> 2063 2064#define RR_BSWAP16(u16) _arm_rev16(u16) 2065#define RR_BSWAP32(u32) _arm_rev(u32) 2066 2067#define RR_GET16_BE(ptr) RR_BSWAP16(*((U16 *)(ptr))) 2068#define RR_PUT16_BE(ptr,val) *((U16 *)(ptr)) = RR_BSWAP16(val) 2069 2070#define RR_GET32_BE(ptr) RR_BSWAP32(*((U32 *)(ptr))) 2071#define RR_PUT32_BE(ptr,val) *((U32 *)(ptr)) = RR_BSWAP32(val) 2072 2073#elif defined(__RADPSP2__) 2074 2075// no rev16 exposed 2076#define RR_BSWAP16(u16) ( (U16) ( ((u16) >> 8) | ((u16) << 8) ) ) 2077#define RR_BSWAP32(u32) __builtin_rev(u32) 2078 2079#define RR_GET16_BE(ptr) RR_BSWAP16(*((U16 *)(ptr))) 2080#define RR_PUT16_BE(ptr,val) *((U16 *)(ptr)) = RR_BSWAP16(val) 2081 2082#define RR_GET32_BE(ptr) RR_BSWAP32(*((U32 *)(ptr))) 2083#define RR_PUT32_BE(ptr,val) *((U32 *)(ptr)) = RR_BSWAP32(val) 2084 2085#else // other platforms ? 2086 2087// fall back : 2088 2089// Bswap is just here for use of implementing get/put 2090// caller should use Get/Put , not bswap 2091#define RR_BSWAP16(u16) ( (U16) ( ((u16) >> 8) | ((u16) << 8) ) ) 2092#define RR_BSWAP32(u32) ( (U32) ( ((u32) >> 24) | (((u32)<<8) & 0x00FF0000) | (((u32)>>8) & 0x0000FF00) | ((u32) << 24) ) ) 2093#define RR_BSWAP64(u64) ( ((U64) RR_BSWAP32((U32) (u64)) << 32) | (U64) RR_BSWAP32((U32) ((u64) >> 32)) ) 2094 2095#ifdef __RADLITTLEENDIAN__ 2096 2097// comment out fallbacks so users will get errors 2098//#define RR_GET16_BE(ptr) RR_BSWAP16(*((U16 *)(ptr))) 2099//#define RR_PUT16_BE(ptr,val) *((U16 *)(ptr)) = RR_BSWAP16(val) 2100//#define RR_GET32_BE(ptr) RR_BSWAP32(*((U32 *)(ptr))) 2101//#define RR_PUT32_BE(ptr,val) *((U32 *)(ptr)) = RR_BSWAP32(val) 2102 2103#else 2104 2105// comment out fallbacks so users will get errors 2106//#define RR_GET16_LE(ptr) RR_BSWAP16(*((U16 *)(ptr))) 2107//#define RR_PUT16_LE(ptr,val) *((U16 *)(ptr)) = RR_BSWAP16(val) 2108//#define RR_GET32_LE(ptr) RR_BSWAP32(*((U32 *)(ptr))) 2109//#define RR_PUT32_LE(ptr,val) *((U32 *)(ptr)) = RR_BSWAP32(val) 2110 2111#endif 2112 2113#endif 2114 2115//=================================================================== 2116// @@ TEMP : Aliases for old names : remove me when possible : 2117 2118#define RR_GET32_OFFSET_LE RR_GET32_LE_OFFSET 2119#define RR_GET32_OFFSET_BE RR_GET32_BE_OFFSET 2120#define RR_PUT32_OFFSET_LE RR_PUT32_LE_OFFSET 2121#define RR_PUT32_OFFSET_BE RR_PUT32_BE_OFFSET 2122#define RR_GET16_OFFSET_LE RR_GET16_LE_OFFSET 2123#define RR_GET16_OFFSET_BE RR_GET16_BE_OFFSET 2124#define RR_PUT16_OFFSET_LE RR_PUT16_LE_OFFSET 2125#define RR_PUT16_OFFSET_BE RR_PUT16_BE_OFFSET 2126 2127 2128//=================================================================== 2129// UNALIGNED VERSIONS : 2130 2131#if defined(__RADX86__) || defined(__RADPPC__) // platforms where unaligned is fast : 2132 2133#define RR_GET32_BE_UNALIGNED(ptr) RR_GET32_BE(ptr) 2134#define RR_GET32_BE_UNALIGNED_OFFSET(ptr,offset) RR_GET32_BE_OFFSET(ptr,offset) 2135#define RR_GET16_BE_UNALIGNED(ptr) RR_GET16_BE(ptr) 2136#define RR_GET16_BE_UNALIGNED_OFFSET(ptr,offset) RR_GET16_BE_OFFSET(ptr,offset) 2137 2138#define RR_GET32_LE_UNALIGNED(ptr) RR_GET32_LE(ptr) 2139#define RR_GET32_LE_UNALIGNED_OFFSET(ptr,offset) RR_GET32_LE_OFFSET(ptr,offset) 2140#define RR_GET16_LE_UNALIGNED(ptr) RR_GET16_LE(ptr) 2141#define RR_GET16_LE_UNALIGNED_OFFSET(ptr,offset) RR_GET16_LE_OFFSET(ptr,offset) 2142 2143#elif defined(__RAD3DS__) 2144 2145// arm has a "__packed" qualifier to tell the compiler to do unaligned accesses 2146#define RR_U16_PTR_OFFSET_UNALIGNED(ptr,offset) ((__packed U16 * RR_GET_PTR_POST)((char *)(ptr) + (offset))) 2147#define RR_U32_PTR_OFFSET_UNALIGNED(ptr,offset) ((__packed U32 * RR_GET_PTR_POST)((char *)(ptr) + (offset))) 2148 2149#define RR_GET32_BE_UNALIGNED(ptr) __rev(*RR_U32_PTR_OFFSET_UNALIGNED(ptr,0)) 2150#define RR_GET32_BE_UNALIGNED_OFFSET(ptr,offset) __rev(*RR_U32_PTR_OFFSET_UNALIGNED(ptr,offset)) 2151#define RR_GET16_BE_UNALIGNED(ptr) __rev16(*RR_U16_PTR_OFFSET_UNALIGNED(ptr,0)) 2152#define RR_GET16_BE_UNALIGNED_OFFSET(ptr,offset) __rev16(*RR_U16_PTR_OFFSET_UNALIGNED(ptr,offset)) 2153 2154#define RR_GET32_LE_UNALIGNED(ptr) *RR_U32_PTR_OFFSET_UNALIGNED(ptr,0) 2155#define RR_GET32_LE_UNALIGNED_OFFSET(ptr,offset) *RR_U32_PTR_OFFSET_UNALIGNED(ptr,offset) 2156#define RR_GET16_LE_UNALIGNED(ptr) *RR_U16_PTR_OFFSET_UNALIGNED(ptr,0) 2157#define RR_GET16_LE_UNALIGNED_OFFSET(ptr,offset) *RR_U16_PTR_OFFSET_UNALIGNED(ptr,offset) 2158 2159#elif defined(__RADPSP2__) 2160 2161#define RR_U16_PTR_OFFSET_UNALIGNED(ptr,offset) ((U16 __unaligned * RR_GET_PTR_POST)((char *)(ptr) + (offset))) 2162#define RR_U32_PTR_OFFSET_UNALIGNED(ptr,offset) ((U32 __unaligned * RR_GET_PTR_POST)((char *)(ptr) + (offset))) 2163 2164#define RR_GET32_BE_UNALIGNED(ptr) RR_BSWAP32(*RR_U32_PTR_OFFSET_UNALIGNED(ptr,0)) 2165#define RR_GET32_BE_UNALIGNED_OFFSET(ptr,offset) RR_BSWAP32(*RR_U32_PTR_OFFSET_UNALIGNED(ptr,offset)) 2166#define RR_GET16_BE_UNALIGNED(ptr) RR_BSWAP16(*RR_U16_PTR_OFFSET_UNALIGNED(ptr,0)) 2167#define RR_GET16_BE_UNALIGNED_OFFSET(ptr,offset) RR_BSWAP16(*RR_U16_PTR_OFFSET_UNALIGNED(ptr,offset)) 2168 2169#define RR_GET32_LE_UNALIGNED(ptr) *RR_U32_PTR_OFFSET_UNALIGNED(ptr,0) 2170#define RR_GET32_LE_UNALIGNED_OFFSET(ptr,offset) *RR_U32_PTR_OFFSET_UNALIGNED(ptr,offset) 2171#define RR_GET16_LE_UNALIGNED(ptr) *RR_U16_PTR_OFFSET_UNALIGNED(ptr,0) 2172#define RR_GET16_LE_UNALIGNED_OFFSET(ptr,offset) *RR_U16_PTR_OFFSET_UNALIGNED(ptr,offset) 2173 2174#else 2175// Unaligned via bytes : 2176 2177#define RR_GET32_BE_UNALIGNED(ptr) ( \ 2178 ( (U32)(((const U8 * RR_GET_PTR_POST)(ptr)))[0] << 24 ) | \ 2179 ( (U32)(((const U8 * RR_GET_PTR_POST)(ptr)))[1] << 16 ) | \ 2180 ( (U32)(((const U8 * RR_GET_PTR_POST)(ptr)))[2] << 8 ) | \ 2181 ( (U32)(((const U8 * RR_GET_PTR_POST)(ptr)))[3] << 0 ) ) 2182 2183#define RR_GET32_BE_UNALIGNED_OFFSET(ptr,offset) ( \ 2184 ( (U32)(((const U8 * RR_GET_PTR_POST)(ptr))+(offset))[0] << 24 ) | \ 2185 ( (U32)(((const U8 * RR_GET_PTR_POST)(ptr))+(offset))[1] << 16 ) | \ 2186 ( (U32)(((const U8 * RR_GET_PTR_POST)(ptr))+(offset))[2] << 8 ) | \ 2187 ( (U32)(((const U8 * RR_GET_PTR_POST)(ptr))+(offset))[3] << 0 ) ) 2188 2189#define RR_GET16_BE_UNALIGNED(ptr) ( \ 2190 ( (U16)(((const U8 * RR_GET_PTR_POST)(ptr)))[0] << 8 ) | \ 2191 ( (U16)(((const U8 * RR_GET_PTR_POST)(ptr)))[1] << 0 ) ) 2192 2193#define RR_GET16_BE_UNALIGNED_OFFSET(ptr,offset) ( \ 2194 ( (U16)(((const U8 * RR_GET_PTR_POST)(ptr))+(offset))[0] << 8 ) | \ 2195 ( (U16)(((const U8 * RR_GET_PTR_POST)(ptr))+(offset))[1] << 0 ) ) 2196 2197#define RR_GET32_LE_UNALIGNED(ptr) ( \ 2198 ( (U32)(((const U8 * RR_GET_PTR_POST)(ptr)))[3] << 24 ) | \ 2199 ( (U32)(((const U8 * RR_GET_PTR_POST)(ptr)))[2] << 16 ) | \ 2200 ( (U32)(((const U8 * RR_GET_PTR_POST)(ptr)))[1] << 8 ) | \ 2201 ( (U32)(((const U8 * RR_GET_PTR_POST)(ptr)))[0] << 0 ) ) 2202 2203#define RR_GET32_LE_UNALIGNED_OFFSET(ptr,offset) ( \ 2204 ( (U32)(((const U8 * RR_GET_PTR_POST)(ptr))+(offset))[3] << 24 ) | \ 2205 ( (U32)(((const U8 * RR_GET_PTR_POST)(ptr))+(offset))[2] << 16 ) | \ 2206 ( (U32)(((const U8 * RR_GET_PTR_POST)(ptr))+(offset))[1] << 8 ) | \ 2207 ( (U32)(((const U8 * RR_GET_PTR_POST)(ptr))+(offset))[0] << 0 ) ) 2208 2209#define RR_GET16_LE_UNALIGNED(ptr) ( \ 2210 ( (U16)(((const U8 * RR_GET_PTR_POST)(ptr)))[1] << 8 ) | \ 2211 ( (U16)(((const U8 * RR_GET_PTR_POST)(ptr)))[0] << 0 ) ) 2212 2213#define RR_GET16_LE_UNALIGNED_OFFSET(ptr,offset) ( \ 2214 ( (U16)(((const U8 * RR_GET_PTR_POST)(ptr))+(offset))[1] << 8 ) | \ 2215 ( (U16)(((const U8 * RR_GET_PTR_POST)(ptr))+(offset))[0] << 0 ) ) 2216 2217#endif 2218 2219//=================================================================== 2220// RR_ROTL32 : 32-bit rotate 2221// 2222 2223#ifdef _MSC_VER 2224 2225 unsigned long __cdecl _lrotl(unsigned long, int); 2226 #pragma intrinsic(_lrotl) 2227 2228 #define RR_ROTL32(x,k) _lrotl((unsigned long)(x),(int)(k)) 2229 2230#elif defined(__RADCELL__) || defined(__RADLINUX__) || defined(__RADWII__) || defined(__RADMACAPI__) || defined(__RADWIIU__) || defined(__RADPS4__) || defined(__RADPSP2__) 2231 2232 // Compiler turns this into rotate correctly : 2233 #define RR_ROTL32(u32,num) ( ( (u32) << (num) ) | ( (u32) >> (32 - (num))) ) 2234 2235#elif defined(__RAD3DS__) 2236 2237 #define RR_ROTL32(u32,num) __ror(u32, (-(num))&31) 2238 2239#else 2240 2241// comment out fallbacks so users will get errors 2242// fallback implementation using shift and or : 2243//#define RR_ROTL32(u32,num) ( ( (u32) << (num) ) | ( (u32) >> (32 - (num))) ) 2244 2245#endif 2246 2247 2248//=================================================================== 2249// RR_ROTL64 : 64-bit rotate 2250 2251#if ( defined(_MSC_VER) && _MSC_VER >= 1300) 2252 2253unsigned __int64 __cdecl _rotl64(unsigned __int64 _Val, int _Shift); 2254#pragma intrinsic(_rotl64) 2255 2256#define RR_ROTL64(x,k) _rotl64((unsigned __int64)(x),(int)(k)) 2257 2258#elif defined(__RADCELL__) 2259 2260// PS3 GCC turns this into rotate correctly : 2261#define RR_ROTL64(u64,num) ( ( (u64) << (num) ) | ( (u64) >> (64 - (num))) ) 2262 2263#elif defined(__RADLINUX__) || defined(__RADMACAPI__) 2264 2265//APTODO: Just to compile linux. Should we be doing better than this? If not, combine with above. 2266#define RR_ROTL64(u64,num) ( ( (u64) << (num) ) | ( (u64) >> (64 - (num))) ) 2267 2268#else 2269 2270// comment out fallbacks so users will get errors 2271// fallback implementation using shift and or : 2272//#define RR_ROTL64(u64,num) ( ( (u64) << (num) ) | ( (u64) >> (64 - (num))) ) 2273 2274#endif 2275 2276//=================================================================== 2277 2278RADDEFEND 2279 2280//=================================================================== 2281 2282// RR_COMPILER_ASSERT 2283#if defined(__cplusplus) && !defined(RR_COMPILER_ASSERT) 2284 #if defined(_MSC_VER) && (_MSC_VER >=1400) 2285 2286 // better version of COMPILER_ASSERT using boost technique 2287 template <int x> struct RR_COMPILER_ASSERT_FAILURE; 2288 2289 template <> struct RR_COMPILER_ASSERT_FAILURE<1> { enum { value = 1 }; }; 2290 2291 template<int x> struct rr_compiler_assert_test{}; 2292 2293 // __LINE__ macro broken when -ZI is used see Q199057 2294 #define RR_COMPILER_ASSERT( B ) \ 2295 typedef rr_compiler_assert_test<\ 2296 sizeof(RR_COMPILER_ASSERT_FAILURE< (B) ? 1 : 0 >)\ 2297 > rr_compiler_assert_typedef_ 2298 2299 #endif 2300#endif 2301 2302#ifndef RR_COMPILER_ASSERT 2303 // this happens at declaration time, so if it's inside a function in a C file, drop {} around it 2304 #define RR_COMPILER_ASSERT(exp) typedef char RR_STRING_JOIN(_dummy_array, __LINE__) [ (exp) ? 1 : -1 ] 2305#endif 2306 2307//=================================================================== 2308// some error checks : 2309 2310 RR_COMPILER_ASSERT( sizeof(RAD_UINTa) == sizeof( RR_STRING_JOIN(RAD_U,RAD_PTRBITS) ) ); 2311 RR_COMPILER_ASSERT( sizeof(RAD_UINTa) == RAD_PTRBYTES ); 2312 RR_COMPILER_ASSERT( RAD_TWOPTRBYTES == 2* RAD_PTRBYTES ); 2313 2314//=================================================================== 2315 2316 #endif // __RADRES__ 2317 2318//include "testconstant.inl" // uncomment and include to test statement constants 2319 2320#endif // __RADRR_COREH__ 2321 2322