SFBMacros.h

Go to the documentation of this file.
00001 /*                                              -*- mode:C++; fill-column:100 -*-
00002   SFBMacros.h - Standalone early macros requiring no constants.
00003   Copyright (C) 2008 The Regents of the University of New Mexico.  All rights reserved.
00004 
00005   This library is free software; you can redistribute it and/or
00006   modify it under the terms of the GNU Lesser General Public
00007   License as published by the Free Software Foundation; either
00008   version 2.1 of the License, or (at your option) any later version.
00009 
00010   This library is distributed in the hope that it will be useful,
00011   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013   Lesser General Public License for more details.
00014 
00015   You should have received a copy of the GNU General Public License
00016   along with this library; if not, write to the Free Software
00017   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
00018   USA
00019 */
00020 
00027 #ifndef SFBMACROS_H_
00028 #define SFBMACROS_H_
00029 
00030 #include "SFBTypes.h"
00031 
00032 
00037 #define CLOCKWISE_FACE(dir)        GET_MAP4BY2(MAP4BY2(EAST,WEST,SOUTH,NORTH),dir) 
00040 #define COUNTERCLOCKWISE_FACE(dir) GET_MAP4BY2(MAP4BY2(WEST,EAST,NORTH,SOUTH),dir) 
00043 #define ANTICLOCKWISE_FACE(dir) COUNTERCLOCKWISE_FACE(dir)
00044 #define OPPOSITE_FACE(dir)         GET_MAP4BY2(MAP4BY2(SOUTH,NORTH,WEST,EAST),dir) 
00048 extern const char * const faceNames[];
00049 #define FACE_NAME(face) (faceNames[face]) 
00050 #define FACE_CODE(face) GET_MAP4BY8(MAP4BY8('N','S','E','W'),face) 
00052 #define FACE_NUMBER_FROM_CODE(code) (((((code)&~0x20)^(((code)&~0x20)>>1))-1)&0x3)  
00057 /* This looks fancy shmancy but compiles into ten instructions:
00058 
00059   #define IS_FACE_CODE(code) ((((code)>>6)==1) && ((0x00884020>>((code)&0x1f))&1))
00060 
00061   (mostly because developing the constant sucks), whereas this looks gross and stupid but compiles
00062   into eight instructions: */
00063 #define IS_FACE_CODE(code)                     \
00064   (((code)&~0x20)=='N'||   \
00065    ((code)&~0x20)=='S'||   \
00066    ((code)&~0x20)=='E'||   \
00067    ((code)&~0x20)=='W')       
00071 
00072 
00076 
00087 #define SET_BIT(value,bitNum) ((value) |= (1<<(bitNum)))
00088 
00099 #define CLEAR_BIT(value,bitNum) ((value) &= ~(1<<(bitNum)))
00100 
00112 #define GET_BIT(value,bitNum) (((value)>>(bitNum))&1)
00113 
00126 #define TEST_BIT(value,bitNum) ((value)&(1<<(bitNum)))
00127 
00143 #define BIT_PAIR_AT_POSITION(bits,newValue,position) \
00144   ((bits) = ((bits)&(~(3<<(position))))|((newValue)<<(position)))
00145 
00147 /****************** Structured H/W register access *****************/
00148 
00153 #define REGISTER_OFFSET(baseAddress,byteOffset) \
00154   (*((uv32 *) (((u32)(baseAddress))+(byteOffset))))
00155 
00176 #define MAP4BY2(a, b, c, d) ((((((((u8) d)<<2)|(c))<<2)|(b))<<2)|(a))
00177 
00192 #define GET_MAP4BY2(map, idx) (((map)>>((idx)<<1))&0x3)
00193 
00210 #define MAP4BY4(a, b, c, d) ((((((((u16) d)<<4)|(c))<<4)|(b))<<4)|(a))
00211 
00226 #define GET_MAP4BY4(map, idx) (((map)>>((idx)<<2))&0xf)
00227 
00244 #define MAP4BY8(a, b, c, d) ((((((((u32) d)<<8)|(c))<<8)|(b))<<8)|(a))
00245 
00259 #define GET_MAP4BY8(map, idx) (((map)>>((idx)<<3))&0xff)
00260 
00289 #define MAP3BY3(a, b, c) ((((((u16) c)<<3)|(b))<<3)|(a))
00290 
00304 #define GET_MAP3BY3(map, idx) (((map)>>((idx)*3))&0x7)
00305 
00322 #define BLINK_MAP(red,green,blue) MAP3BY3(blue,green,red)
00323 
00324 
00338 #define GET_BLINK_MAP_COLOR(code,color) GET_MAP3BY3(code,2-(color))
00339 
00411 #define IS_EARLIER(a,b)          ((((u32)(a))-((u32)(b))) > 0x80000000UL)
00412 
00413 #define IS_LATER_OR_EQUAL(a,b)   ((((u32)(a))-((u32)(b))) < 0x80000000UL) 
00416 #define IS_LATER(a,b)            ((((u32)(b))-((u32)(a))) > 0x80000000UL) 
00419 #define IS_EARLIER_OR_EQUAL(a,b) ((((u32)(b))-((u32)(a))) < 0x80000000UL) 
00423 #define IS_EARLIER16(a,b)        ((u16)(((u16)(a))-((u16)(b))) > 0x8000UL)  
00426 #define IS_LATER_OR_EQUAL16(a,b) ((u16)(((u16)(a))-((u16)(b))) < 0x8000UL)  
00429 #define IS_LATER16(a,b)          ((u16)(((u16)(b))-((u16)(a))) > 0x8000UL)  
00432 #define IS_EARLIER_OR_EQUAL16(a,b) ((u16)(((u16)(b))-((u16)(a))) < 0x8000UL)
00435 #define IS_EARLIER8(a,b)        ((u8)(((u8)(a))-((u8)(b))) > 0x80UL)  
00438 #define IS_LATER_OR_EQUAL8(a,b) ((u8)(((u8)(a))-((u8)(b))) < 0x80UL)  
00441 #define IS_LATER8(a,b)          ((u8)(((u8)(b))-((u8)(a))) > 0x80UL)  
00444 #define IS_EARLIER_OR_EQUAL8(a,b) ((u8)(((u8)(b))-((u8)(a))) < 0x80UL)
00448 
00449 
00452 
00471 #define STRUCT_MEMBER_OFFSET(structure,member) ((uptr) &(((structure *) 0)->member))
00472 
00473 #define XSTR(arg) STR(arg)  
00476 #define STR(arg) #arg       
00480 #define MIN(a,b) (((a)<(b))?(a):(b))  
00486 #define MAX(a,b) (((a)>(b))?(a):(b)) 
00493 #define FILEPOS __FILE__ ":" XSTR(__LINE__)
00494 
00497 /****************** B36 constants macros ******************/
00498 
00500 #define B36_CONST_0 0u
00501 #define B36_CONST_1 1u
00502 #define B36_CONST_2 2u
00503 #define B36_CONST_3 3u
00504 #define B36_CONST_4 4u
00505 #define B36_CONST_5 5u
00506 #define B36_CONST_6 6u
00507 #define B36_CONST_7 7u
00508 #define B36_CONST_8 8u
00509 #define B36_CONST_9 9u
00510 #define B36_CONST_A 10u
00511 #define B36_CONST_a 10u
00512 #define B36_CONST_B 11u
00513 #define B36_CONST_b 11u
00514 #define B36_CONST_C 12u
00515 #define B36_CONST_c 12u
00516 #define B36_CONST_D 13u
00517 #define B36_CONST_d 13u
00518 #define B36_CONST_E 14u
00519 #define B36_CONST_e 14u
00520 #define B36_CONST_F 15u
00521 #define B36_CONST_f 15u
00522 #define B36_CONST_G 16u
00523 #define B36_CONST_g 16u
00524 #define B36_CONST_H 17u
00525 #define B36_CONST_h 17u
00526 #define B36_CONST_I 18u
00527 #define B36_CONST_i 18u
00528 #define B36_CONST_J 19u
00529 #define B36_CONST_j 19u
00530 #define B36_CONST_K 20u
00531 #define B36_CONST_k 20u
00532 #define B36_CONST_L 21u
00533 #define B36_CONST_l 21u
00534 #define B36_CONST_M 22u
00535 #define B36_CONST_m 22u
00536 #define B36_CONST_N 23u
00537 #define B36_CONST_n 23u
00538 #define B36_CONST_O 24u
00539 #define B36_CONST_o 24u
00540 #define B36_CONST_P 25u
00541 #define B36_CONST_p 25u
00542 #define B36_CONST_Q 26u
00543 #define B36_CONST_q 26u
00544 #define B36_CONST_R 27u
00545 #define B36_CONST_r 27u
00546 #define B36_CONST_S 28u
00547 #define B36_CONST_s 28u
00548 #define B36_CONST_T 29u
00549 #define B36_CONST_t 29u
00550 #define B36_CONST_U 30u
00551 #define B36_CONST_u 30u
00552 #define B36_CONST_V 31u
00553 #define B36_CONST_v 31u
00554 #define B36_CONST_W 32u
00555 #define B36_CONST_w 32u
00556 #define B36_CONST_X 33u
00557 #define B36_CONST_x 33u
00558 #define B36_CONST_Y 34u
00559 #define B36_CONST_y 34u
00560 #define B36_CONST_Z 35u
00561 #define B36_CONST_z 35u
00562 
00564 #define B36_1(a) B36_CONST_##a                                  
00565 #define B36_2(a,b) (B36_1(a)*36u+B36_1(b))                      
00566 #define B36_3(a,b,c) (B36_2(a,b)*36u+B36_1(c))                  
00567 #define B36_4(a,b,c,d) (B36_3(a,b,c)*36u+B36_1(d))              
00568 #define B36_5(a,b,c,d,e) (B36_4(a,b,c,d)*36u+B36_1(e))          
00569 #define B36_6(a,b,c,d,e,f) (B36_5(a,b,c,d,e)*36u+B36_1(f))      
00570 #define B36_7(a,b,c,d,e,f,g) (B36_6(a,b,c,d,e,f)*36u+B36_1(g))  
00572 /****************** Memory placement macros ******************/
00573 
00574 #ifndef HOST_MODE
00575 
00576 #define IN_BODYRAM  __attribute__((section (".bodyram")))
00577 #define IN_TALKRAM  __attribute__((section (".talkram")))
00578 #define IN_FASTRAM  __attribute__((section (".fastram")))
00579 
00580 #define IN_BODYRAM_BSS  __attribute__((section (".bss.bodyram")))
00581 #define IN_TALKRAM_BSS  __attribute__((section (".bss.talkram")))
00582 #define IN_FASTRAM_BSS  __attribute__((section (".bss.fastram")))
00583 
00584 #else
00585 
00586 #define IN_BODYRAM  /* in host mode */
00587 #define IN_TALKRAM  /* no special ram regions */
00588 #define IN_FASTRAM  /* are defined */
00589 
00590 #define IN_BODYRAM_BSS  /* for */
00591 #define IN_TALKRAM_BSS  /* any */
00592 #define IN_FASTRAM_BSS  /* thing */
00593 
00594 #endif
00595 
00596 #endif /*SFBMACROS_H_*/

Generated on Fri Apr 22 06:54:11 2011 for SFB by doxygen 1.5.9