Main Page | Alphabetical List | Class List | File List | Class Members | File Members

slice_stdio_os1.h

Go to the documentation of this file.
00001 /*--------------------------------------------------------
00002  * /
00003  * / apeNEXT multidata stdio for OS1
00004  * /
00005  * / $Id: slice_stdio_os1.h,v 1.17 2006/01/10 11:27:16 morinl Exp $
00006  * /
00007  * /--------------------------------------------------------*/
00008 #ifndef __ANEXT_OS1_SLICE_STDIO_H__
00009 #define __ANEXT_OS1_SLICE_STDIO_H__
00010 
00011 #include <nlibc.h>
00012 
00013 #include <stdarg.h>             // for va_list etc.
00014 #include <os1/defs_os1.h>       // for SYS_IOFMT_*
00015 
00016 /*-------------------------------------------------------------------------
00017 | NAME
00018 |     mfputi, mfputx, mfputd,
00019 |     mfputu, mputi, mputx, mputd,
00020 |     mputu - formatted output of int, complex, double and unsigned
00021 |     from specified node(s)
00022 | SYNOPSIS
00023 |   #include <stdio.h>
00024 | 
00025 |   mfputi( int x1, int y1, int z1, [ int x2, int y2, int z2, ] 
00026 |                    int value, FILE *stream )
00027 |   mfputx( int x1, int y1, int z1, [ int x2, int y2, int z2, ] 
00028 |                    complex value, FILE *stream )
00029 |   mfputd( int x1, int y1, int z1, [ int x2, int y2, int z2, ] 
00030 |                    double value, FILE *stream )
00031 |   mfputu( int x1, int y1, int z1, [ int x2, int y2, int z2, ] 
00032 |                    unsigned value, FILE *stream )
00033 |   mputi( int x1, int y1, int z1, [ int x2, int y2, int z2, ] 
00034 |                    int value )
00035 |   mputx( int x1, int y1, int z1, [ int x2, int y2, int z2, ] 
00036 |                    complex value )
00037 |   mputd( int x1, int y1, int z1, [ int x2, int y2, int z2, ] 
00038 |                    double value )
00039 |   mputu( int x1, int y1, int z1, [ int x2, int y2, int z2, ] 
00040 |                    unsigned value )
00041 |
00042 |
00043 | DESCRIPTION
00044 |   The functions produce formatted output of their value argument on
00045 |   the specified stream (fput variants) or on stdout (put variants).
00046 |   The format used is defined by nose.
00047 |   The specification of the second coordinate triple is optional.
00048 |   If present, it specifies the 'upper' corner of a slice of nodes.
00049 |   If not present, the first triple specifies coordinates of a single
00050 |   node.
00051 |
00052 +-------------------------------------------------------------------------*/
00053 #define __MIOPUT(ITS, CTS, CTYPE, STREAM) \
00054         va_list ap;\
00055         int n_args;\
00056         int x2 = x1, y2 = y1, z2 = z1;\
00057         CTYPE value;\
00058         vector int sys_retval;\
00059         int fput_retval;\
00060         FILE *stream;\
00061 \
00062         asm("\n\t!! begin mfput"#CTS"()");\
00063         va_start( ap, z1 );\
00064 \
00065         n_args = __builtin_argcount();\
00066         if( n_args >= 6 ) {\
00067                 x2 = va_arg(ap, int);\
00068                 y2 = va_arg(ap, int);\
00069                 z2 = va_arg(ap, int);\
00070         }\
00071 \
00072         value = va_arg(ap,CTYPE);\
00073         stream = STREAM;\
00074 \
00075         asm("\t$io_start\n"\
00076             "\t$io_fd( 0.%1 )\n"\
00077             "\t$io_slice(0.%2,0.%3,0.%4,0.%5,0.%6,0.%7)\n"\
00078             "\t$io_put"#ITS"( 0x0.%8 )\n"\
00079             "\t$io_end\n"\
00080             "\tlmtr %0 $MEM_SYS_RVAL\n"\
00081             : "=r" (sys_retval)\
00082             : "r" (stream->fd),\
00083               "r" (x1),  "r" (y1),  "r" (z1),  "r" (x2),  "r" (y2),  "r" (z2), \
00084               "r" (&value) );\
00085 \
00086         fput_retval = (sys_retval.lo) ? -1 : 0;\
00087         asm("\t!! end mfput"#CTS"()");\
00088         return fput_retval
00089 
00090 #ifdef __HAS_MAIN
00091 #define BODY(args) args
00092 #else
00093 #define BODY(args) ;
00094 #endif
00095 
00096 #if !defined(__cflow_processed) || defined(_uses_mfputi_slice_stdio_os1_h)
00097 int mfputi( int x1, int y1, int z1, ... ) BODY({ __MIOPUT(d,i,int,(va_arg(ap, FILE*))); })
00098 #endif // mfputi()
00099 
00100 #if !defined(__cflow_processed) || defined(_uses_mputi_slice_stdio_os1_h)
00101 int mputi( int x1, int y1, int z1, ... ) BODY({ __MIOPUT(d,i,int,stdout); })
00102 #endif // mfputi()
00103 
00104 #if !defined(__cflow_processed) || defined(_uses_mfputiv_slice_stdio_os1_h)
00105 int mfputiv( int x1, int y1, int z1, ... ) BODY({ __MIOPUT(dv,iv,int,(va_arg(ap, FILE*))); })
00106 #endif // mfputiv()
00107 
00108 #if !defined(__cflow_processed) || defined(_uses_mputiv_slice_stdio_os1_h)
00109 int mputiv( int x1, int y1, int z1, ... ) BODY({ __MIOPUT(dv,iv,int,stdout); })
00110 #endif // mfputiv()
00111 
00112 #if !defined(__cflow_processed) || defined(_uses_mfputx_slice_stdio_os1_h)
00113 int mfputx( int x1, int y1, int z1, ... ) BODY({ __MIOPUT(z,x,complex,(va_arg(ap, FILE*))); })
00114 #endif // mfputx()
00115 
00116 #if !defined(__cflow_processed) || defined(_uses_mputx_slice_stdio_os1_h)
00117 int mputx( int x1, int y1, int z1, ... ) BODY({ __MIOPUT(z,x,complex,stdout); })
00118 #endif // mputx()
00119 
00120 #if !defined(__cflow_processed) || defined(_uses_mfputd_slice_stdio_os1_h)
00121 int mfputd( int x1, int y1, int z1, ... ) BODY({ __MIOPUT(e,d,double,(va_arg(ap, FILE*))); })
00122 #endif // mfputd()
00123 
00124 #if !defined(__cflow_processed) || defined(_uses_mputd_slice_stdio_os1_h)
00125 int mputd( int x1, int y1, int z1, ... ) BODY({ __MIOPUT(e,d,double,stdout); })
00126 #endif // mputd()
00127 
00128 #if !defined(__cflow_processed) || defined(_uses_mfputu_slice_stdio_os1_h)
00129 int mfputu( int x1, int y1, int z1, ... ) BODY({ __MIOPUT(x,u,unsigned,(va_arg(ap, FILE*))); })
00130 #endif // mfputu()
00131 
00132 #if !defined(__cflow_processed) || defined(_uses_mputu_slice_stdio_os1_h)
00133 int mputu( int x1, int y1, int z1, ... ) BODY({ __MIOPUT(x,u,unsigned,stdout); })
00134 #endif // mputu()
00135 
00136 #if !defined(__cflow_processed) || defined(_uses_mfputh_slice_stdio_os1_h)
00137 int mfputh( int x1, int y1, int z1, ... ) BODY({ __MIOPUT(x,u,unsigned,(va_arg(ap, FILE*))); })
00138 #endif // mfputh()
00139 
00140 #if !defined(__cflow_processed) || defined(_uses_mputh_slice_stdio_os1_h)
00141 int mputh( int x1, int y1, int z1, ... ) BODY({ __MIOPUT(x,u,unsigned,stdout); })
00142 #endif // mputh()
00143 
00144 #if !defined(__cflow_processed) || defined(_uses_mfputhv_slice_stdio_os1_h)
00145 int mfputhv( int x1, int y1, int z1, ... ) BODY({ __MIOPUT(xv,u,unsigned,(va_arg(ap, FILE*))); })
00146 #endif // mfputhv()
00147 
00148 #if !defined(__cflow_processed) || defined(_uses_mputhv_slice_stdio_os1_h)
00149 int mputhv( int x1, int y1, int z1, ... ) BODY({ __MIOPUT(xv,u,unsigned,stdout); })
00150 #endif // mputhv()
00151 
00152 #define __MIOPUTA(ITS, ITYPE, CTS, CTYPE, BS,STREAM) \
00153         va_list ap;\
00154         int n_args;\
00155         int x2 = x1, y2 = y1, z2 = z1;\
00156         CTYPE *ptr;\
00157         int size;\
00158         vector int sys_retval;\
00159         int fput_retval;\
00160         FILE *stream;\
00161 \
00162         asm("\n\t!! begin mfput"#CTS"a()");\
00163         va_start( ap, z1 );\
00164 \
00165         n_args = __builtin_argcount();\
00166         if( n_args >= 7 ) {\
00167                 x2 = va_arg(ap, int);\
00168                 y2 = va_arg(ap, int);\
00169                 z2 = va_arg(ap, int);\
00170         }\
00171 \
00172         ptr = va_arg(ap,CTYPE *);\
00173         size= va_arg(ap,int);\
00174         stream = STREAM;\
00175 \
00176         asm("\t$io_start\n"\
00177             "\t$io_fd( 0.%1 )\n"\
00178             "\t$io_slice(0.%2,0.%3,0.%4,0.%5,0.%6,0.%7)\n"\
00179             "\t\\equ $cmd   $SYS_IOCMD_SWR\n"\
00180             "\t\\equ $fmt   <$SYS_IOFMT_"#ITYPE">\n"\
00181             "\t\\equ $bs    "#BS"\n"\
00182             "\t\\equ $sep   <$SYS_IOPSEP_NL .or. $SYS_IOWSEP_SPACE>\n"\
00183             "\t$io_packet($cmd, <$fmt .or. $sep>, $SYS_IORDFLG_NOP, $SYS_IODEV_MEM, 0.%9, $bs, 0.%8)\n"\
00184             "\t$io_end\n"\
00185             "\tlmtr %0 $MEM_SYS_RVAL\n"\
00186             : "=r" (sys_retval)\
00187             : "r" (stream->fd),\
00188               "r" (x1),  "r" (y1),  "r" (z1),  "r" (x2),  "r" (y2),  "r" (z2), \
00189               "r" (ptr), "r" (size) );\
00190 \
00191         fput_retval = (sys_retval.lo) ? -1 : 0;\
00192         asm("\t!! end mfput"#CTS"a()");\
00193         return fput_retval
00194 
00195 #if !defined(__cflow_processed) || defined(_uses_mfputia_slice_stdio_os1_h)
00196 int mfputia( int x1, int y1, int z1, ... ) BODY({ __MIOPUTA(d,INT,i,int,$SYS_IOBS_L,(va_arg(ap, FILE*))); })
00197 #endif // mfputi()
00198 
00199 #if !defined(__cflow_processed) || defined(_uses_mputia_slice_stdio_os1_h)
00200 int mputia( int x1, int y1, int z1, ... ) BODY({ __MIOPUTA(d,INT,i,int,$SYS_IOBS_L,stdout); })
00201 #endif // mputi()
00202 
00203 #if !defined(__cflow_processed) || defined(_uses_mfputxa_slice_stdio_os1_h)
00204 int mfputxa( int x1, int y1, int z1, ... ) BODY({ __MIOPUTA(z,DBL.or.$SYS_IOBSEP_RBRACKET,x,complex,$SYS_IOBS_V,(va_arg(ap, FILE*))); })
00205 #endif // mputxa()
00206 
00207 #if !defined(__cflow_processed) || defined(_uses_mputxa_slice_stdio_os1_h)
00208 int mputxa( int x1, int y1, int z1, ... ) BODY({ __MIOPUTA(z,DBL.or.$SYS_IOBSEP_RBRACKET,x,complex,$SYS_IOBS_V,stdout); })
00209 #endif // mputxa()
00210 
00211 #if !defined(__cflow_processed) || defined(_uses_mfputda_slice_stdio_os1_h)
00212 int mfputda( int x1, int y1, int z1, ... ) BODY({ __MIOPUTA(e,DBL,d,double,$SYS_IOBS_L,(va_arg(ap, FILE*))); })
00213 #endif // mfputd()
00214 
00215 #if !defined(__cflow_processed) || defined(_uses_mputda_slice_stdio_os1_h)
00216 int mputda( int x1, int y1, int z1, ... ) BODY({ __MIOPUTA(e,DBL,d,double,$SYS_IOBS_L,stdout); })
00217 #endif // mputd()
00218 
00219 #if !defined(__cflow_processed) || defined(_uses_mfputva_slice_stdio_os1_h)
00220 int mfputva( int x1, int y1, int z1, ... ) BODY({ __MIOPUTA(z,DBL.or.$SYS_IOBSEP_RBRACKET,v,vector,$SYS_IOBS_V,(va_arg(ap, FILE*))); })
00221 #endif // mputva()
00222 
00223 #if !defined(__cflow_processed) || defined(_uses_mputva_slice_stdio_os1_h)
00224 int mputva( int x1, int y1, int z1, ... ) BODY({ __MIOPUTA(z,DBL.or.$SYS_IOBSEP_RBRACKET,v,vector,$SYS_IOBS_V,stdout); })
00225 #endif // mputva()
00226 
00227 /*-------------------------------------------------------------------------
00228 | NAME
00229 |     mfgeti, mfgetx, mfgetd,
00230 |     mfgetu, mgeti, mgetx, mgetd,
00231 |     mgetu - formatted outget of int, complex, double and unsigned
00232 |     from specified node(s)
00233 | SYNOPSIS
00234 |   #include <stdio.h>
00235 | 
00236 |   mfgeti( int x1, int y1, int z1, [ int x2, int y2, int z2, ] 
00237 |                    int *ptr, FILE *stream )
00238 |   mfgetx( int x1, int y1, int z1, [ int x2, int y2, int z2, ] 
00239 |                    complex *ptr, FILE *stream )
00240 |   mfgetd( int x1, int y1, int z1, [ int x2, int y2, int z2, ] 
00241 |                    double *ptr, FILE *stream )
00242 |   mfgetu( int x1, int y1, int z1, [ int x2, int y2, int z2, ] 
00243 |                    unsigned *ptr, FILE *stream )
00244 |   mgeti( int x1, int y1, int z1, [ int x2, int y2, int z2, ] 
00245 |                    int *ptr )
00246 |   mgetx( int x1, int y1, int z1, [ int x2, int y2, int z2, ] 
00247 |                    complex *ptr )
00248 |   mgetd( int x1, int y1, int z1, [ int x2, int y2, int z2, ] 
00249 |                    double *ptr )
00250 |   mgetu( int x1, int y1, int z1, [ int x2, int y2, int z2, ] 
00251 |                    unsigned *ptr )
00252 |
00253 |
00254 +----------------------------------------------------------------------*/
00255 
00256 #define __MIOGET(ITS, CTS, CTYPE, STREAM) \
00257         va_list ap;\
00258         int n_args;\
00259         int x2 = x1, y2 = y1, z2 = z1;\
00260         CTYPE *ptr;\
00261         vector int sys_retval;\
00262         int fput_retval;\
00263         FILE *stream;\
00264 \
00265         asm("\n\t!! begin mfput"#CTS"()");\
00266         va_start( ap, z1 );\
00267 \
00268         n_args = __builtin_argcount();\
00269         if( n_args >= 6 ) {\
00270                 x2 = va_arg(ap, int);\
00271                 y2 = va_arg(ap, int);\
00272                 z2 = va_arg(ap, int);\
00273         }\
00274 \
00275         ptr = va_arg(ap, CTYPE *);\
00276         stream = STREAM;\
00277 \
00278         asm("\t$io_start\n"\
00279             "\t$io_fd( 0.%1 )\n"\
00280             "\t$io_slice(0.%2,0.%3,0.%4,0.%5,0.%6,0.%7)\n"\
00281             "\t$io_get"#ITS"( 0.%8 )\n"\
00282             "\t$io_end\n"\
00283             "\tlmtr %0 $MEM_SYS_RVAL\n"\
00284             : "=r" (sys_retval)\
00285             : "r" (stream->fd),\
00286               "r" (x1),  "r" (y1),  "r" (z1),  "r" (x2),  "r" (y2),  "r" (z2), \
00287               "r" (ptr) );\
00288 \
00289         fput_retval = (sys_retval.lo) ? -1 : 0;\
00290         asm("\t!! end mfput"#CTS"()");\
00291         return fput_retval
00292 
00293 #if !defined(__cflow_processed) || defined(_uses_mfgeti_slice_stdio_os1_h)
00294 int mfgeti( int x1, int y1, int z1, ... ) BODY({ __MIOGET(d,i,int,(va_arg(ap, FILE*))); })
00295 #endif // mfgeti()
00296 
00297 #if !defined(__cflow_processed) || defined(_uses_mfgetx_slice_stdio_os1_h)
00298 int mfgetx( int x1, int y1, int z1, ... ) BODY({ __MIOGET(z,x,complex,(va_arg(ap, FILE*))); })
00299 #endif // mfgetx()
00300 
00301 #if !defined(__cflow_processed) || defined(_uses_mfgetdi_slice_stdio_os1_h)
00302 int mfgetdi( int x1, int y1, int z1, ... ) BODY({ __MIOGET(e,d,double,(va_arg(ap, FILE*))); })
00303 #endif // mfgetdi()
00304 
00305 #undef BODY
00306 
00307 //---------------------------------------------------------------------------------------------
00357 #define mprintf(ARGS...) mfprintf(stdout, ##ARGS)
00358 
00359 #ifndef __HAS_MAIN
00360 extern int mfprintf(FILE *stream, int x1, int y1, int z1, ... );
00361 #else
00362 #if !defined(__cflow_processed) || defined(_uses_mfprintf_slice_stdio_os1_h)
00363 int mfprintf(FILE *stream, int x1, int y1, int z1, ... ) {
00364         int iocnt;
00365         vector int argcnt, sys_retval;
00366         va_list ap, ap2; 
00367         int x2 = x1, y2 = y1, z2 = z1;
00368         char *format;
00369 
00370         asm("\t!! begin mfprintf()");
00371 
00372         if( ! stream->fd ) { 
00373                 errno = EBADF;
00374                 return 0;
00375         }
00376 
00377         va_start( ap, z1 );
00378 
00379         argcnt = __builtin_argcount();
00380         iocnt = argcnt.lo;
00381         // function expects 5 or 8 arguments
00382         if( (iocnt != 5) && (iocnt != 8) ) 
00383                 return 0;
00384         
00385         // check if more node coordinates follow
00386         // by testing the argument type 
00387         //  if 'int' : read 3 more coords
00388         //   else    : assume it's the 'format' arg.
00389         {    va_list ap2; 
00390              vector int arginfo; 
00391              void *ptr = _va_ptr(ap2);
00392 
00393              va_copy(ap2,ap);
00394              arginfo = _va_info(ap2);
00395              if( arginfo.hi == NLCC_INT ) {
00396                 x2 = va_arg(ap, int);
00397                 y2 = va_arg(ap, int);
00398                 z2 = va_arg(ap, int);
00399                 iocnt -= 8;
00400              } else
00401                 iocnt -= 5;
00402         }
00403 
00404         format = va_arg(ap, char *);
00405 
00406         // output format string
00407         asm("\t$io_start\n"
00408             "\t$io_fd( 0.%0 )\n"
00409             "\t$io_slice(0.%3,0.%4,0.%5,0.%6,0.%7,0.%8)\n"\
00410             "\t$io_cnt_set( %2 )\n"
00411             "\t\\equ $cmd   $SYS_IOCMD_SPRF\n"
00412             "\t\\equ $fmt   $SYS_IOFMT_VARSTR\n"
00413             "\t\\equ $sep   <$SYS_IOPSEP_NOP .or. $SYS_IOWSEP_SPACE>\n"
00414             "\t\\equ $dev   $SYS_IODEV_MEM\n"
00415             "\t\\equ $bs    $SYS_IOBS_V\n"
00416             "\t\\equ $rdflg $SYS_IORDFLG_NOP\n"
00417             "\t$io_packet($cmd, < $fmt .or. $sep >, $rdflg, $dev, 0, $bs, 0.%1 )"
00418             : : "r" (stream->fd), "r" (format), "r" (iocnt),
00419                 "r" (x1), "r" (y1), "r" (z1), 
00420                 "r" (x2), "r" (y2), "r" (z2));
00421 
00422         asm("\t$io_setloopflg\n");
00423 
00424         for(; iocnt > 0; iocnt -- ) {
00425                 vector int arginfo = _va_info(ap);
00426                 void *ptr = _va_ptr(ap);
00427                 _va_skip( ap, arginfo.lo );
00428                 if( arginfo.hi == NLCC_STRING ) {
00429                         char *str = *(char **)ptr;
00430                         asm("\t$io_cnt_decr\n"
00431                             "\t\\equ $cmd   $SYS_IOCMD_SPRF\n"
00432                             "\t\\equ $fmt   $SYS_IOFMT_VARSTR\n"
00433                             "\t\\equ $sep   <$SYS_IOPSEP_NOP .or. $SYS_IOWSEP_NOP>\n"
00434                             "\t\\equ $dev   $SYS_IODEV_MEM\n"
00435                             "\t\\equ $bs    $SYS_IOBS_V\n"
00436                             "\t\\equ $rdflg $SYS_IORDFLG_NOP\n"
00437                             "\t$io_packet($cmd, <$fmt .or. $sep>, $rdflg, $dev, 0, $bs, 0.%0)\n"
00438                             : :  "r" (str) );
00439                 } else {
00440                         asm("\t$io_cnt_decr\n"
00441                             "\t\\equ $cmd   $SYS_IOCMD_SPRF\n"
00442                             "\t\\equ $fmt   $SYS_IOFMT_BIN\n"
00443                             "\t\\equ $sep   <$SYS_IOPSEP_NOP .or. $SYS_IOWSEP_NOP>\n"
00444                             "\t\\equ $dev   $SYS_IODEV_MEM\n"
00445                             "\t\\equ $l     0.%1\n"
00446                             "\t\\equ $bs    $SYS_IOBS_V\n"
00447                             "\t\\equ $rdflg $SYS_IORDFLG_NOP\n"
00448                             "\t$io_packet($cmd, <$fmt .or. $sep>, $rdflg, $dev, $l, $bs, 0.%0)\n"
00449                             : :  "r" (ptr), "r" (arginfo.lo) );
00450                 }
00451         }
00452         va_end(ap);
00453 
00454         asm("\t$io_cnt_clear\n"
00455             "\tlmtr %0 $MEM_SYS_RVAL\n"
00456             "\t$io_end\n"
00457             "\t!! end mfprintf()\n"
00458             : "=r" (sys_retval) );
00459 
00460         return (int) (sys_retval.hi);
00461 }
00462 #endif // mfprintf()
00463 #endif // Has Main
00464 
00465 #define mvprintf(ARGS...) mvfprintf(stdout, ##ARGS)
00466 
00467 #ifndef __HAS_MAIN
00468 extern int mvfprintf(FILE *stream, int x1, int y1, int z1, ... );
00469 #else
00470 #if !defined(__cflow_processed) || defined(_uses_mvfprintf_slice_stdio_os1_h)
00471 int mvfprintf(FILE *stream, int x1, int y1, int z1, ... ) {
00472         int n_args, n_pargs;
00473         vector int sys_retval;
00474         va_list ap, ap2, ap3; 
00475         int x2 = x1, y2 = y1, z2 = z1;
00476         char *format;
00477         int xxx;
00478 
00479         asm("\t!! begin mvfprintf()");
00480 
00481         va_start( ap, z1 );
00482 
00483         n_args = __builtin_argcount();
00484         n_pargs = n_args;
00485         // function expects at 5 or 8 arguments
00486 
00487         printf("n_args: %d\n",n_args);
00488 
00489         if( (n_args != 6) && (n_args !=9) ) 
00490         {
00491             return(0);
00492         }
00493         else
00494         {
00495         
00496             // check if more node coordinates follow
00497             // by testing the argument type 
00498             //  if 'int' : read 3 more coords
00499             //   else    : assume it's the 'format' arg.
00500             {   
00501                 va_list ap2; 
00502                 vector int arginfo; 
00503                 void *ptr = _va_ptr(ap2);
00504                 
00505                 va_copy(ap2,ap);
00506                 arginfo = _va_info(ap2);
00507                 if( arginfo.hi == NLCC_INT ) {
00508                     x2 = va_arg(ap, int);
00509                     y2 = va_arg(ap, int);
00510                     z2 = va_arg(ap, int);
00511                     n_pargs -= 8;
00512                 } else
00513                     n_pargs -= 5;
00514             }
00515 
00516             printf("n_pargs: %d\n",n_pargs);
00517             
00518             format = va_arg(ap, char *);
00519             
00520             va_copy(ap3,(va_list)va_arg(ap, va_list));
00521             
00522             n_pargs=_va_args(ap3);
00523             
00524             if( ! stream->fd ) { 
00525                 errno = EBADF;
00526                 return 0;
00527             }
00528             
00529             // output format string
00530             asm("\t$io_start\n"
00531                 "\t$io_fd( 0.%0 )\n"
00532                 "\t$io_slice(0.%3,0.%4,0.%5,0.%6,0.%7,0.%8)\n"\
00533                 "\t$io_cnt_set( %2 )\n"
00534                 "\t\\equ $cmd   $SYS_IOCMD_SPRF\n"
00535                 "\t\\equ $fmt   $SYS_IOFMT_VARSTR\n"
00536                 "\t\\equ $sep   <$SYS_IOPSEP_NOP .or. $SYS_IOWSEP_SPACE>\n"
00537                 "\t\\equ $dev   $SYS_IODEV_MEM\n"
00538                 "\t\\equ $bs    $SYS_IOBS_V\n"
00539                 "\t\\equ $rdflg $SYS_IORDFLG_NOP\n"
00540                 "\t$io_packet($cmd, < $fmt .or. $sep >, $rdflg, $dev, 0, $bs, 0.%1 )"
00541                 : : "r" (stream->fd), "r" (format), "r" (n_pargs),
00542                 "r" (x1), "r" (y1), "r" (z1), 
00543                 "r" (x2), "r" (y2), "r" (z2));
00544             
00545             for(; n_pargs > 0; n_pargs -- ) {
00546                 vector int arginfo = _va_info(ap3);
00547                 void *ptr = _va_ptr(ap3);
00548                 _va_skip( ap3, arginfo.lo );
00549                 if( arginfo.hi == NLCC_STRING ) {
00550                     char *str = *(char **)ptr;
00551                     asm("\t$io_cnt_decr\n"
00552                         "\t\\equ $cmd   $SYS_IOCMD_SPRF\n"
00553                         "\t\\equ $fmt   $SYS_IOFMT_VARSTR\n"
00554                         "\t\\equ $sep   <$SYS_IOPSEP_NOP .or. $SYS_IOWSEP_NOP>\n"
00555                         "\t\\equ $dev   $SYS_IODEV_MEM\n"
00556                         "\t\\equ $bs    $SYS_IOBS_V\n"
00557                         "\t\\equ $rdflg $SYS_IORDFLG_NOP\n"
00558                         "\t$io_packet($cmd, <$fmt .or. $sep>, $rdflg, $dev, 0, $bs, 0.%0)\n"
00559                         : :  "r" (str) );
00560                 } else {
00561                     asm("\t$io_cnt_decr\n"
00562                         "\t\\equ $cmd   $SYS_IOCMD_SPRF\n"
00563                         "\t\\equ $fmt   $SYS_IOFMT_BIN\n"
00564                         "\t\\equ $sep   <$SYS_IOPSEP_NOP .or. $SYS_IOWSEP_NOP>\n"
00565                         "\t\\equ $dev   $SYS_IODEV_MEM\n"
00566                         "\t\\equ $l     0.%1\n"
00567                         "\t\\equ $bs    $SYS_IOBS_V\n"
00568                         "\t\\equ $rdflg $SYS_IORDFLG_NOP\n"
00569                         "\t$io_packet($cmd, <$fmt .or. $sep>, $rdflg, $dev, $l, $bs, 0.%0)\n"
00570                         : :  "r" (ptr), "r" (arginfo.lo) );
00571                 }
00572             }
00573             va_end(ap3);
00574             va_end(ap);
00575             asm("\t$io_cnt_clear\n"
00576                 "\tlmtr %0 $MEM_SYS_RVAL\n"
00577                 "\t$io_end\n"
00578                 "\t!! end mvfprintf()\n"
00579                 : "=r" (sys_retval) );
00580             
00581             return (int) (sys_retval.hi);
00582         }
00583 }
00584 #endif // mvfprintf()
00585 #endif // Has Main
00586 
00587 /*---------------------------------------------------------------------------------------------
00588 \par NAME   
00589           slread(), mfread(), mfwrite() -  binary stream input/output for slices      \n
00590           \n
00591           slread() - read single data to slice of nodes  \n
00592           mfread() - read multiple data to slice of nodes  \n
00593           mfwrite() - write multiple data to slice of nodes\n
00594           \n
00595 \par SYNOPSIS
00596           #include <stdio.h>            \n
00597           \n
00598           size_t slead(int x1, int y1, int z1,[int x2, int y2, int z2,]
00599                                 void *ptr, size_t size, size_t nmemb, FILE *stream,     \n
00600           \n
00601           size_t fread(int x1, int y1, int z1,[int x2, int y2, int z2,]
00602                                 void *ptr, size_t size, size_t nmemb, FILE *stream,     \n
00603           \n
00604           size_t fwrite(int x1, int y1, int z1,[int x2, int y2, int z2,]
00605                                 void *ptr, size_t size, size_t nmemb, FILE *stream,     \n
00606           \n
00607 \par DESCRIPTION 
00608           see: fread(), fwrite() \n
00609 \par RETURN VALUE
00610           see: fread(), fwrite() \n
00611 \par BUG
00612           fmread, slread bug: if reading exeeds EOF, no data are read to memory and the memory remains unchanged \n
00613 \par NOTE
00614           nodes read/write according to node_abs_id, starting with lowest number. \n
00615           (the id is calculated to be: node_abs_id = x*LY*LZ + y*LY + z) \n
00616 \par IMPLEMENTATION for APEnext:
00617           mostly done \n
00618 ------------------------------------------------------------------------------------------*/
00619 
00620 #define __MF_ANZARGS 7
00621 #define __TMF_ANZARGS 7
00622 
00623 #define __MFSTART(ANZARGS) \
00624         int iocnt, retval, nbytes;\
00625         vector int argcnt, sys_rval;\
00626         size_t size, nmemb;\
00627         void *ptr;\
00628         FILE *stream;\
00629         va_list ap;\
00630         int x2 = x1, y2 = y1, z2 = z1;\
00631 \
00632         va_start( ap, z1 );\
00633         argcnt = __builtin_argcount();\
00634         iocnt = argcnt.lo;\
00635 \
00636         if (iocnt==ANZARGS+3) {\
00637                 x2 = va_arg(ap, int);\
00638                 y2 = va_arg(ap, int);\
00639                 z2 = va_arg(ap, int);\
00640         }\
00641         else if (iocnt!=ANZARGS) return 0
00642 
00643 #define __MFCHECK(STREAM) \
00644         assert( (nbytes%16)==0 );\
00645         stream = STREAM;\
00646         if( ! stream->fd ) {\
00647                 errno = EBADF;\
00648                 return 0;\
00649         }  
00650 
00651 #define __MIOPACKET(IOCMD,IOBS) \
00652       asm("\t$io_start\n"\
00653             "\t\\equl $cmd   "#IOCMD"\n"\
00654             "\t\\equl $fmt   $SYS_IOFMT_BIN\n"\
00655             "\t\\equl $sep   $SYS_IOPSEP_NOP\n"\
00656             "\t\\equl $rdflg $SYS_IORDFLG_NOP\n"\
00657             "\t\\equl $dev   $SYS_IODEV_MEM\n"\
00658             "\t\\equl $l     %1>>4\n"\
00659             "\t\\equl $bs    "#IOBS"\n"\
00660             "\t$io_fd( 0.%2 )\n"\
00661             "\t$io_slice(0.%4,0.%5,0.%6,0.%7,0.%8,0.%9)\n"\
00662             "\t$io_slice_set\n"\
00663             "\t$io_packet($cmd, <$fmt .or. $sep>, $rdflg, $dev, $l, $bs, 0.%3)\n"\
00664             "\t$io_end\n"\
00665             "\tlmtr %0 $MEM_SYS_RVAL\n"\
00666             : "=r" (sys_rval) : "r" (nbytes), "r" (stream->fd), "r" (ptr),\
00667                "r" (x1), "r" (y1), "r" (z1), "r" (x2), "r" (y2), "r" (z2) )
00668 
00669 #define __MFEND \
00670         retval = nmemb;\
00671         where (sys_rval.lo) {\
00672                 stream->err = 1;\
00673                 retval = 0;\
00674         }\
00675 \
00676         return retval
00677 
00678 // ------------------------------------------------
00679 
00680 #define _MFIO(IOCMD,STREAM) \
00681         __MFSTART(__MF_ANZARGS);\
00682         ptr = va_arg(ap, void*);\
00683         size = va_arg(ap, size_t);\
00684         nmemb = va_arg(ap, size_t);\
00685         nbytes = size * nmemb;\
00686         __MFCHECK(STREAM);\
00687         __MIOPACKET(IOCMD,$SYS_IOBS_V);\
00688         __MFEND
00689 
00690 #define _TMFIO(IOCMD,STREAM) \
00691         __MFSTART(__TMF_ANZARGS);\
00692         ptr = va_arg(ap, void*);\
00693         size = va_arg(ap, size_t);\
00694         nmemb = 1;\
00695         nbytes = size * nmemb;\
00696         __MFCHECK(STREAM);\
00697         if( (tcode==NLCC_FLOAT) || (tcode==NLCC_DOUBLE) || (tcode==NLCC_INT) || (tcode==NLCC_UNSIGNED) ) {\
00698                 __MIOPACKET(IOCMD,$SYS_IOBS_L);\
00699         }\
00700         else if( (tcode==NLCC_COMPLEX) || (tcode==NLCC_VECTOR) || (tcode==NLCC_VFLOAT) || (tcode==NLCC_VINT) || (tcode==NLCC_VUINT) ) {\
00701                 __MIOPACKET(IOCMD,$SYS_IOBS_V);\
00702         }\
00703         __MFEND
00704 
00705 // ------------------------------------------------
00706 
00707 #ifdef __HAS_MAIN
00708 #define BODY(args) args
00709 #else
00710 #define BODY(args) ;
00711 #endif
00712 
00713 #ifndef __HAS_MAIN
00714 extern size_t slread(int x1, int y1, int z1, ...);
00715 #else
00716 #if !defined(__cflow_processed) || defined(_uses_slread_slice_stdio_os1_h)
00717 size_t slread(int x1, int y1, int z1, ...) BODY({ _MFIO($SYS_IOCMD_BRD,(va_arg(ap, FILE*)));})  
00718 #endif // slread()
00719 #endif // Has Main
00720 
00721 #ifndef __HAS_MAIN
00722 extern size_t mfread(int x1, int y1, int z1, ...);
00723 #else
00724 #if !defined(__cflow_processed) || defined(_uses_mfread_slice_stdio_os1_h)
00725 size_t mfread(int x1, int y1, int z1, ...) BODY({ _MFIO($SYS_IOCMD_MRD,(va_arg(ap, FILE*)));})  
00726 #endif // mfread()
00727 #endif // Has Main
00728 
00729 #ifndef __HAS_MAIN
00730 extern size_t mfwrite(int x1, int y1, int z1, ...);
00731 #else
00732 #if !defined(__cflow_processed) || defined(_uses_mfwrite_slice_stdio_os1_h)
00733 size_t mfwrite(int x1, int y1, int z1, ...) BODY({ _MFIO($SYS_IOCMD_SWR,(va_arg(ap, FILE*)));}) 
00734 #endif // mfwrite()
00735 #endif // Has Main
00736 
00737 #undef BODY
00738 
00739 #endif //  __ANEXT_OS1_SLICE_STDIO_H__
00740         

Generated on Tue Jan 10 12:43:39 2006 for nlibc by doxygen 1.3.5