* ========== Copyright Header Begin ==========================================
* OpenSPARC T2 Processor File: sparcccgen.c
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES.
* The above named program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License version 2 as published by the Free Software Foundation.
* The above named program is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
* You should have received a copy of the GNU General Public
* License along with this work; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
* ========== Copyright Header End ============================================
* Sparc condition code operations are nasty ...
* Ideally we want a fast mechanism to determine if a conditional
* operation is true or not based on the condition codes.
* Except that the condition expressions dont well match
* the condition code flags.
* Now we have a 4 bit condition expression and a 4 bit condition
* code register, so we could combine to form an index for a 256
* bit array of true and false ... except that the cond expression
* is always encoded in the instruction ...
* For now we use the cond expression, as an index into a table of
* 16bit words. The cond code register selects a bit from this
* the result of which is true or false ...
* This code mechanically builds those 16bit words to be indexed
* by the condition code register value.
#include <ctype.h> /* for islower / toupper */
#include <string.h> /* for strchr */
#include <sys/param.h> /* for MAXPATHLEN */
void fatal(char* fmt
, ...);
void strcasecpy(char * top
, char * fromp
);
for (cond
=0; cond
<16; cond
++) {
for (ccr
=0; ccr
<16; ccr
++) {
if (!(ccr
& cc_bit_z
)) goto set_bit
;
if (ccr
& cc_bit_z
) goto set_bit
;
if ( !( (ccr
&cc_bit_z
) || (((ccr
>>2)^ccr
)&cc_bit_v
) ) ) goto set_bit
;
if ( (ccr
&cc_bit_z
) || (((ccr
>>2)^ccr
)&cc_bit_v
) ) goto set_bit
;
if (!( ((ccr
>>2)^ccr
)&cc_bit_v
)) goto set_bit
;
if ( ((ccr
>>2)^ccr
)&cc_bit_v
) goto set_bit
;
if (!((ccr
& cc_bit_c
) || (ccr
& cc_bit_z
))) goto set_bit
;
if ((ccr
& cc_bit_c
) || (ccr
& cc_bit_z
)) goto set_bit
;
if (!(ccr
& cc_bit_c
)) goto set_bit
;
if (ccr
& cc_bit_c
) goto set_bit
;
if (!(ccr
& cc_bit_n
)) goto set_bit
;
if (ccr
& cc_bit_n
) goto set_bit
;
if (!(ccr
& cc_bit_v
)) goto set_bit
;
if (ccr
& cc_bit_v
) goto set_bit
;
fprintf(fp
, "\t0x%04lx%s\n", (uint32_t)mask
, cond
!=15 ? "," : "");
int main(int argc
, char ** argv
)
if (argc
!= 3) fatal("usage: %s <basefilename> <basestructname>\n",
if (strlen(structnamep
)>MAXBUF
-100) fatal("basestructname is too long!");
/* Initialise the .h and .c files */
sprintf(bufp
, "%s.c", basenamep
);
if (dotc
== NULL
) fatal("creating %s", bufp
);
sprintf(bufp
, "%s.h", basenamep
);
if (doth
== NULL
) fatal("creating %s", bufp
);
/* remove any earlier path ... */
bnamep
= strrchr(basenamep
, '/');
strcasecpy(caps
, bnamep
);
/* Autogenerated file - DO NOT EDIT */\n\
uint16_t %s[16]={\n", bnamep
, structnamep
);
\n", bnamep
, structnamep
);
#endif\n", caps
, caps
, structnamep
);
return 0; /* compiler joy */
void fatal(char* fmt
, ...)
if (errno
!=0) perror("FATAL: "); else fprintf(stderr
,"FATAL: ");
(void)vfprintf(stderr
, fmt
, args
);
void strcasecpy(char * top
, char * fromp
)
*top
++ = islower((unsigned)*fromp
) ? toupper((unsigned)*fromp
) : *fromp
;
} while (*fromp
++ != '\0');