libspe2  0.9a
handler_utils.h
Go to the documentation of this file.
1 /* handler_utils.h - definitions for assisted SPE library calls.
2  *
3  * Copyright (C) 2005 IBM Corp.
4  *
5  * This library is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU Lesser General Public License as published by
7  * the Free Software Foundation; either version 2.1 of the License,
8  * or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
13  * License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with this library; if not, write to the Free Software Foundation,
17  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */
19 
20 #ifndef __HANDLER_UTILS_H__
21 #define __HANDLER_UTILS_H__
22 
23 struct spe_reg128 {
24  unsigned int slot[4];
25 };
26 
27 #ifndef LS_SIZE
28 #define LS_SIZE 0x40000 /* 256K (in bytes) */
29 #define LS_ADDR_MASK (LS_SIZE - 1)
30 #endif /* LS_SIZE */
31 
32 #define __PRINTF(fmt, args...) { fprintf(stderr,fmt , ## args); }
33 #ifdef DEBUG
34 #define DEBUG_PRINTF(fmt, args...) __PRINTF(fmt , ## args)
35 #else
36 #define DEBUG_PRINTF(fmt, args...)
37 #endif
38 
39 #define LS_ARG_ADDR(_index) \
40  (&((struct spe_reg128 *) ((char *) ls + ls_args))[_index])
41 
42 #define DECL_RET() \
43  struct spe_reg128 *ret = LS_ARG_ADDR(0)
44 
45 #define GET_LS_PTR(_off) \
46  (void *) ((char *) ls + ((_off) & LS_ADDR_MASK))
47 
48 #define GET_LS_PTR_NULL(_off) \
49  ((_off) ? GET_LS_PTR(_off) : NULL)
50 
51 #define DECL_0_ARGS() \
52  unsigned int ls_args = (opdata & 0xffffff)
53 
54 #define DECL_1_ARGS() \
55  DECL_0_ARGS(); \
56  struct spe_reg128 *arg0 = LS_ARG_ADDR(0)
57 
58 #define DECL_2_ARGS() \
59  DECL_1_ARGS(); \
60  struct spe_reg128 *arg1 = LS_ARG_ADDR(1)
61 
62 #define DECL_3_ARGS() \
63  DECL_2_ARGS(); \
64  struct spe_reg128 *arg2 = LS_ARG_ADDR(2)
65 
66 #define DECL_4_ARGS() \
67  DECL_3_ARGS(); \
68  struct spe_reg128 *arg3 = LS_ARG_ADDR(3)
69 
70 #define DECL_5_ARGS() \
71  DECL_4_ARGS(); \
72  struct spe_reg128 *arg4 = LS_ARG_ADDR(4)
73 
74 #define DECL_6_ARGS() \
75  DECL_5_ARGS(); \
76  struct spe_reg128 *arg5 = LS_ARG_ADDR(5)
77 
78 #define PUT_LS_RC(_a, _b, _c, _d) \
79  ret->slot[0] = (unsigned int) (_a); \
80  ret->slot[1] = (unsigned int) (_b); \
81  ret->slot[2] = (unsigned int) (_c); \
82  ret->slot[3] = (unsigned int) (_d); \
83  __asm__ __volatile__ ("sync" : : : "memory")
84 
85 #endif /* __HANDLER_UTILS_H__ */