file
stringlengths 18
26
| data
stringlengths 2
1.05M
|
---|---|
the_stack_data/153266891.c | #include <assert.h>
int g = 1;
int main() {
// After the presolve phase, g is in the start state but neither in the context nor in the start variables.
// If the start state of main is not overwriten when main is destabilized because of a changed start state,
// the first assert will wrongly succeed and the second fail in the incremental run
assert(g == 1); // success before, unknown after
assert(g == 2); // fail before, unknown after
return 0;
}
|
the_stack_data/165764538.c | #include <stdio.h>
int main(void)
{
int num[5];
num[0] = 42;
num[1] = 83;
num[4] = 77;
num[2] = num[4] - num[1];
num[3] = num[0] / num[2];
int garbage[42];
printf("done\n");
} |
the_stack_data/66415.c | double function() {
int a = 4, b = 5;
return a % b;
}
|
the_stack_data/41353.c | #include <stdio.h>
void func2(int a) { // 0x400537
printf("About to segfault... a=%d\n", a); // 0x400542
*(int*)0 = a; // 0x400558
printf("Did segfault!\n"); // 0x400562
}
void func1(int a) { // 0x400571
printf("Calling func2\n"); // 0x40057c
func2(a % 5); // 0x400588
}
int main() {
func1(42); // 0x4005b8
}
|
the_stack_data/111077394.c | #include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
int main() {
int vendas,nvendas;
float salario,valorvendas,bonus;
scanf("%d",&vendas);
if (vendas>=15){
valorvendas= vendas * 19.90;
nvendas= vendas/15;
bonus= valorvendas * (0.08 * nvendas);
salario= valorvendas * 0.5;
salario= salario + bonus;
printf("%.2lf\n",valorvendas);
printf("%.2lf\n",bonus);
printf("%.2lf\n",salario);
}
else{
valorvendas= vendas * 19.90;
nvendas= vendas/15;
bonus= valorvendas * (0.08 * nvendas);
salario= vendas * 19.90 ;
salario= salario * 0.5;
printf("%.2lf\n",valorvendas);
printf("%.2lf\n",bonus);
printf("%.2lf\n",salario);
}
return 0;
}
|
the_stack_data/32948953.c | #include <stdio.h>
#include <stdlib.h>
char* trim(char*);
int main(void) {
char* buffer = (char*) malloc(strlen(" cat ") + 1);
strcpy(buffer, " cat");
printf("|%s|\n", trim(buffer));
return EXIT_SUCCESS;
}
char* trim(char* phrase) {
char* old = phrase;
char* new = phrase;
while(*(old) == ' ') {
old++;
}
while(*(old)) {
*(new++) = *(old++);
}
*(new) = 0;
return (char*) realloc(phrase, strlen(phrase)+1);
}
|
the_stack_data/529700.c | /* { dg-do compile } */
/* { dg-options "-O2 -fno-math-errno -fno-trapping-math -msse2 -mno-sse4 -mfpmath=sse" } */
float
f1 (float f)
{
return __builtin_rintf (f);
}
double
f2 (double f)
{
return __builtin_rint (f);
}
/* { dg-final { scan-assembler-times "\tucomiss\t" 1 } } */
/* { dg-final { scan-assembler-times "\tucomisd\t" 1 } } */
|
the_stack_data/86153.c | /* Verify that call declarations are not redirected according to indirect
inlining edges too early. */
/* { dg-do run } */
/* { dg-options "-O3 -fno-early-inlining" } */
extern void abort (void);
int bar (int k)
{
return k+2;
}
int baz (int k)
{
return k+1;
}
static int foo (int (*p)(int), int i)
{
return p (i+1);
}
int (*g)(int) = baz;
int main (int argc, char *argv[])
{
if (foo (bar, 0) != 3)
abort ();
if (foo (g, 1) != 3)
abort ();
return 0;
}
|
the_stack_data/29911.c | /*
* Copyright 2014 The Emscripten Authors. All rights reserved.
* Emscripten is available under two separate licenses, the MIT license and the
* University of Illinois/NCSA Open Source License. Both these licenses can be
* found in the LICENSE file.
*/
/*
** A program for performance testing.
**
** The available command-line options are described below:
*/
static const char zHelp[] =
"Usage: %s [--options] DATABASE\n"
"Options:\n"
" --autovacuum Enable AUTOVACUUM mode\n"
" --cachesize N Set the cache size to N\n"
" --exclusive Enable locking_mode=EXCLUSIVE\n"
" --explain Like --sqlonly but with added EXPLAIN keywords\n"
" --heap SZ MIN Memory allocator uses SZ bytes & min allocation MIN\n"
" --incrvacuum Enable incremenatal vacuum mode\n"
" --journalmode M Set the journal_mode to MODE\n"
" --key KEY Set the encryption key to KEY\n"
" --lookaside N SZ Configure lookaside for N slots of SZ bytes each\n"
" --nosync Set PRAGMA synchronous=OFF\n"
" --notnull Add NOT NULL constraints to table columns\n"
" --pagesize N Set the page size to N\n"
" --pcache N SZ Configure N pages of pagecache each of size SZ bytes\n"
" --primarykey Use PRIMARY KEY instead of UNIQUE where appropriate\n"
" --reprepare Reprepare each statement upon every invocation\n"
" --scratch N SZ Configure scratch memory for N slots of SZ bytes each\n"
" --sqlonly No-op. Only show the SQL that would have been run.\n"
" --size N Relative test size. Default=100\n"
" --stats Show statistics at the end\n"
" --testset T Run test-set T\n"
" --trace Turn on SQL tracing\n"
" --utf16be Set text encoding to UTF-16BE\n"
" --utf16le Set text encoding to UTF-16LE\n"
" --verify Run additional verification steps.\n"
" --without-rowid Use WITHOUT ROWID where appropriate\n"
;
#include "sqlite3.h"
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <ctype.h>
/* All global state is held in this structure */
static struct Global {
sqlite3 *db; /* The open database connection */
sqlite3_stmt *pStmt; /* Current SQL statement */
sqlite3_int64 iStart; /* Start-time for the current test */
sqlite3_int64 iTotal; /* Total time */
int bWithoutRowid; /* True for --without-rowid */
int bReprepare; /* True to reprepare the SQL on each rerun */
int bSqlOnly; /* True to print the SQL once only */
int bExplain; /* Print SQL with EXPLAIN prefix */
int bVerify; /* Try to verify that results are correct */
int szTest; /* Scale factor for test iterations */
const char *zWR; /* Might be WITHOUT ROWID */
const char *zNN; /* Might be NOT NULL */
const char *zPK; /* Might be UNIQUE or PRIMARY KEY */
unsigned int x, y; /* Pseudo-random number generator state */
int nResult; /* Size of the current result */
char zResult[3000]; /* Text of the current result */
} g;
/* Print an error message and exit */
static void fatal_error(const char *zMsg, ...){
va_list ap;
va_start(ap, zMsg);
vfprintf(stderr, zMsg, ap);
va_end(ap);
exit(1);
}
/*
** Return the value of a hexadecimal digit. Return -1 if the input
** is not a hex digit.
*/
static int hexDigitValue(char c){
if( c>='0' && c<='9' ) return c - '0';
if( c>='a' && c<='f' ) return c - 'a' + 10;
if( c>='A' && c<='F' ) return c - 'A' + 10;
return -1;
}
/* Provide an alternative to sqlite3_stricmp() in older versions of
** SQLite */
#if SQLITE_VERSION_NUMBER<3007011
# define sqlite3_stricmp strcmp
#endif
/*
** Interpret zArg as an integer value, possibly with suffixes.
*/
static int integerValue(const char *zArg){
sqlite3_int64 v = 0;
static const struct { char *zSuffix; int iMult; } aMult[] = {
{ "KiB", 1024 },
{ "MiB", 1024*1024 },
{ "GiB", 1024*1024*1024 },
{ "KB", 1000 },
{ "MB", 1000000 },
{ "GB", 1000000000 },
{ "K", 1000 },
{ "M", 1000000 },
{ "G", 1000000000 },
};
int i;
int isNeg = 0;
if( zArg[0]=='-' ){
isNeg = 1;
zArg++;
}else if( zArg[0]=='+' ){
zArg++;
}
if( zArg[0]=='0' && zArg[1]=='x' ){
int x;
zArg += 2;
while( (x = hexDigitValue(zArg[0]))>=0 ){
v = (v<<4) + x;
zArg++;
}
}else{
while( isdigit(zArg[0]) ){
v = v*10 + zArg[0] - '0';
zArg++;
}
}
for(i=0; i<sizeof(aMult)/sizeof(aMult[0]); i++){
if( sqlite3_stricmp(aMult[i].zSuffix, zArg)==0 ){
v *= aMult[i].iMult;
break;
}
}
if( v>0x7fffffff ) fatal_error("parameter too large - max 2147483648");
return (int)(isNeg? -v : v);
}
/* Return the current wall-clock time, in milliseconds */
sqlite3_int64 speedtest1_timestamp(void){
static sqlite3_vfs *clockVfs = 0;
sqlite3_int64 t;
if( clockVfs==0 ) clockVfs = sqlite3_vfs_find(0);
#if SQLITE_VERSION_NUMBER>=3007000
if( clockVfs->iVersion>=2 && clockVfs->xCurrentTimeInt64!=0 ){
clockVfs->xCurrentTimeInt64(clockVfs, &t);
}else
#endif
{
double r;
clockVfs->xCurrentTime(clockVfs, &r);
t = (sqlite3_int64)(r*86400000.0);
}
return t;
}
/* Return a pseudo-random unsigned integer */
unsigned int speedtest1_random(void){
g.x = (g.x>>1) ^ ((1+~(g.x&1)) & 0xd0000001);
g.y = g.y*1103515245 + 12345;
return g.x ^ g.y;
}
/* Map the value in within the range of 1...limit into another
** number in a way that is chatic and invertable.
*/
unsigned swizzle(unsigned in, unsigned limit){
unsigned out = 0;
while( limit ){
out = (out<<1) | (in&1);
in >>= 1;
limit >>= 1;
}
return out;
}
/* Round up a number so that it is a power of two minus one
*/
unsigned roundup_allones(unsigned limit){
unsigned m = 1;
while( m<limit ) m = (m<<1)+1;
return m;
}
/* The speedtest1_numbername procedure below converts its argment (an integer)
** into a string which is the English-language name for that number.
** The returned string should be freed with sqlite3_free().
**
** Example:
**
** speedtest1_numbername(123) -> "one hundred twenty three"
*/
int speedtest1_numbername(unsigned int n, char *zOut, int nOut){
static const char *ones[] = { "zero", "one", "two", "three", "four", "five",
"six", "seven", "eight", "nine", "ten", "eleven", "twelve",
"thirteen", "fourteen", "fifteen", "sixteen", "seventeen",
"eighteen", "nineteen" };
static const char *tens[] = { "", "ten", "twenty", "thirty", "forty",
"fifty", "sixty", "seventy", "eighty", "ninety" };
int i = 0;
if( n>=1000000000 ){
i += speedtest1_numbername(n/1000000000, zOut+i, nOut-i);
sqlite3_snprintf(nOut-i, zOut+i, " billion");
i += (int)strlen(zOut+i);
n = n % 1000000000;
}
if( n>=1000000 ){
if( i && i<nOut-1 ) zOut[i++] = ' ';
i += speedtest1_numbername(n/1000000, zOut+i, nOut-i);
sqlite3_snprintf(nOut-i, zOut+i, " million");
i += (int)strlen(zOut+i);
n = n % 1000000;
}
if( n>=1000 ){
if( i && i<nOut-1 ) zOut[i++] = ' ';
i += speedtest1_numbername(n/1000, zOut+i, nOut-i);
sqlite3_snprintf(nOut-i, zOut+i, " thousand");
i += (int)strlen(zOut+i);
n = n % 1000;
}
if( n>=100 ){
if( i && i<nOut-1 ) zOut[i++] = ' ';
sqlite3_snprintf(nOut-i, zOut+i, "%s hundred", ones[n/100]);
i += (int)strlen(zOut+i);
n = n % 100;
}
if( n>=20 ){
if( i && i<nOut-1 ) zOut[i++] = ' ';
sqlite3_snprintf(nOut-i, zOut+i, "%s", tens[n/10]);
i += (int)strlen(zOut+i);
n = n % 10;
}
if( n>0 ){
if( i && i<nOut-1 ) zOut[i++] = ' ';
sqlite3_snprintf(nOut-i, zOut+i, "%s", ones[n]);
i += (int)strlen(zOut+i);
}
if( i==0 ){
sqlite3_snprintf(nOut-i, zOut+i, "zero");
i += (int)strlen(zOut+i);
}
return i;
}
/* Start a new test case */
#define NAMEWIDTH 60
static const char zDots[] =
".......................................................................";
void speedtest1_begin_test(int iTestNum, const char *zTestName, ...){
int n = (int)strlen(zTestName);
char *zName;
va_list ap;
va_start(ap, zTestName);
zName = sqlite3_vmprintf(zTestName, ap);
va_end(ap);
n = (int)strlen(zName);
if( n>NAMEWIDTH ){
zName[NAMEWIDTH] = 0;
n = NAMEWIDTH;
}
if( g.bSqlOnly ){
printf("/* %4d - %s%.*s */\n", iTestNum, zName, NAMEWIDTH-n, zDots);
}else{
printf("%4d - %s%.*s ", iTestNum, zName, NAMEWIDTH-n, zDots);
fflush(stdout);
}
sqlite3_free(zName);
g.nResult = 0;
g.iStart = speedtest1_timestamp();
g.x = 0xad131d0b;
g.y = 0x44f9eac8;
}
/* Complete a test case */
void speedtest1_end_test(void){
sqlite3_int64 iElapseTime = speedtest1_timestamp() - g.iStart;
if( !g.bSqlOnly ){
g.iTotal += iElapseTime;
printf("%4d.%03ds\n", (int)(iElapseTime/1000), (int)(iElapseTime%1000));
}
if( g.pStmt ){
sqlite3_finalize(g.pStmt);
g.pStmt = 0;
}
}
/* Report end of testing */
void speedtest1_final(void){
if( !g.bSqlOnly ){
printf(" TOTAL%.*s %4d.%03ds\n", NAMEWIDTH-5, zDots,
(int)(g.iTotal/1000), (int)(g.iTotal%1000));
}
}
/* Print an SQL statement to standard output */
static void printSql(const char *zSql){
int n = (int)strlen(zSql);
while( n>0 && (zSql[n-1]==';' || isspace(zSql[n-1])) ){ n--; }
if( g.bExplain ) printf("EXPLAIN ");
printf("%.*s;\n", n, zSql);
if( g.bExplain
#if SQLITE_VERSION_NUMBER>=3007010
&& ( sqlite3_strglob("CREATE *", zSql)==0
|| sqlite3_strglob("DROP *", zSql)==0
|| sqlite3_strglob("ALTER *", zSql)==0
)
#endif
){
printf("%.*s;\n", n, zSql);
}
}
/* Run SQL */
void speedtest1_exec(const char *zFormat, ...){
va_list ap;
char *zSql;
va_start(ap, zFormat);
zSql = sqlite3_vmprintf(zFormat, ap);
va_end(ap);
if( g.bSqlOnly ){
printSql(zSql);
}else{
char *zErrMsg = 0;
int rc = sqlite3_exec(g.db, zSql, 0, 0, &zErrMsg);
if( zErrMsg ) fatal_error("SQL error: %s\n%s\n", zErrMsg, zSql);
if( rc!=SQLITE_OK ) fatal_error("exec error: %s\n", sqlite3_errmsg(g.db));
}
sqlite3_free(zSql);
}
/* Prepare an SQL statement */
void speedtest1_prepare(const char *zFormat, ...){
va_list ap;
char *zSql;
va_start(ap, zFormat);
zSql = sqlite3_vmprintf(zFormat, ap);
va_end(ap);
if( g.bSqlOnly ){
printSql(zSql);
}else{
int rc;
if( g.pStmt ) sqlite3_finalize(g.pStmt);
rc = sqlite3_prepare_v2(g.db, zSql, -1, &g.pStmt, 0);
if( rc ){
fatal_error("SQL error: %s\n", sqlite3_errmsg(g.db));
}
}
sqlite3_free(zSql);
}
/* Run an SQL statement previously prepared */
void speedtest1_execute(void){
int i, n, len;
if( g.bSqlOnly ) return;
assert( g.pStmt );
g.nResult = 0;
while( sqlite3_step(g.pStmt)==SQLITE_ROW ){
n = sqlite3_column_count(g.pStmt);
for(i=0; i<n; i++){
const char *z = (const char*)sqlite3_column_text(g.pStmt, i);
if( z==0 ) z = "nil";
len = (int)strlen(z);
if( g.nResult+len<sizeof(g.zResult)-2 ){
if( g.nResult>0 ) g.zResult[g.nResult++] = ' ';
memcpy(g.zResult + g.nResult, z, len+1);
g.nResult += len;
}
}
}
if( g.bReprepare ){
sqlite3_stmt *pNew;
sqlite3_prepare_v2(g.db, sqlite3_sql(g.pStmt), -1, &pNew, 0);
sqlite3_finalize(g.pStmt);
g.pStmt = pNew;
}else{
sqlite3_reset(g.pStmt);
}
}
/* The sqlite3_trace() callback function */
static void traceCallback(void *NotUsed, const char *zSql){
int n = (int)strlen(zSql);
while( n>0 && (zSql[n-1]==';' || isspace(zSql[n-1])) ) n--;
fprintf(stderr,"%.*s;\n", n, zSql);
}
/* Substitute random() function that gives the same random
** sequence on each run, for repeatability. */
static void randomFunc1(
sqlite3_context *context,
int NotUsed,
sqlite3_value **NotUsed2
){
sqlite3_result_int64(context, (sqlite3_int64)speedtest1_random());
}
/* Estimate the square root of an integer */
static int est_square_root(int x){
int y0 = x/2;
int y1;
int n;
for(n=0; y0>0 && n<10; n++){
y1 = (y0 + x/y0)/2;
if( y1==y0 ) break;
y0 = y1;
}
return y0;
}
/*
** The main and default testset
*/
void testset_main(void){
int i; /* Loop counter */
int n; /* iteration count */
int sz; /* Size of the tables */
int maxb; /* Maximum swizzled value */
unsigned x1, x2; /* Parameters */
int len; /* Length of the zNum[] string */
char zNum[2000]; /* A number name */
sz = n = g.szTest*500;
maxb = roundup_allones(sz);
speedtest1_begin_test(100, "%d INSERTs into table with no index", n);
speedtest1_exec("BEGIN");
speedtest1_exec("CREATE TABLE t1(a INTEGER %s, b INTEGER %s, c TEXT %s);",
g.zNN, g.zNN, g.zNN);
speedtest1_prepare("INSERT INTO t1 VALUES(?1,?2,?3); -- %d times", n);
for(i=1; i<=n; i++){
x1 = swizzle(i,maxb);
speedtest1_numbername(x1, zNum, sizeof(zNum));
sqlite3_bind_int64(g.pStmt, 1, (sqlite3_int64)x1);
sqlite3_bind_int(g.pStmt, 2, i);
sqlite3_bind_text(g.pStmt, 3, zNum, -1, SQLITE_STATIC);
speedtest1_execute();
}
speedtest1_exec("COMMIT");
speedtest1_end_test();
n = sz;
speedtest1_begin_test(110, "%d ordered INSERTS with one index/PK", n);
speedtest1_exec("BEGIN");
speedtest1_exec("CREATE TABLE t2(a INTEGER %s %s, b INTEGER %s, c TEXT %s) %s",
g.zNN, g.zPK, g.zNN, g.zNN, g.zWR);
speedtest1_prepare("INSERT INTO t2 VALUES(?1,?2,?3); -- %d times", n);
for(i=1; i<=n; i++){
x1 = swizzle(i,maxb);
speedtest1_numbername(x1, zNum, sizeof(zNum));
sqlite3_bind_int(g.pStmt, 1, i);
sqlite3_bind_int64(g.pStmt, 2, (sqlite3_int64)x1);
sqlite3_bind_text(g.pStmt, 3, zNum, -1, SQLITE_STATIC);
speedtest1_execute();
}
speedtest1_exec("COMMIT");
speedtest1_end_test();
n = sz;
speedtest1_begin_test(120, "%d unordered INSERTS with one index/PK", n);
speedtest1_exec("BEGIN");
speedtest1_exec("CREATE TABLE t3(a INTEGER %s %s, b INTEGER %s, c TEXT %s) %s",
g.zNN, g.zPK, g.zNN, g.zNN, g.zWR);
speedtest1_prepare("INSERT INTO t3 VALUES(?1,?2,?3); -- %d times", n);
for(i=1; i<=n; i++){
x1 = swizzle(i,maxb);
speedtest1_numbername(x1, zNum, sizeof(zNum));
sqlite3_bind_int(g.pStmt, 2, i);
sqlite3_bind_int64(g.pStmt, 1, (sqlite3_int64)x1);
sqlite3_bind_text(g.pStmt, 3, zNum, -1, SQLITE_STATIC);
speedtest1_execute();
}
speedtest1_exec("COMMIT");
speedtest1_end_test();
n = 25;
speedtest1_begin_test(130, "%d SELECTS, numeric BETWEEN, unindexed", n);
speedtest1_exec("BEGIN");
speedtest1_prepare(
"SELECT count(*), avg(b), sum(length(c)) FROM t1\n"
" WHERE b BETWEEN ?1 AND ?2; -- %d times", n
);
for(i=1; i<=n; i++){
x1 = speedtest1_random()%maxb;
x2 = speedtest1_random()%10 + sz/5000 + x1;
sqlite3_bind_int(g.pStmt, 1, x1);
sqlite3_bind_int(g.pStmt, 2, x2);
speedtest1_execute();
}
speedtest1_exec("COMMIT");
speedtest1_end_test();
n = 10;
speedtest1_begin_test(140, "%d SELECTS, LIKE, unindexed", n);
speedtest1_exec("BEGIN");
speedtest1_prepare(
"SELECT count(*), avg(b), sum(length(c)) FROM t1\n"
" WHERE c LIKE ?1; -- %d times", n
);
for(i=1; i<=n; i++){
x1 = speedtest1_random()%maxb;
zNum[0] = '%';
len = speedtest1_numbername(i, zNum+1, sizeof(zNum)-2);
zNum[len] = '%';
zNum[len+1] = 0;
sqlite3_bind_text(g.pStmt, 1, zNum, len, SQLITE_STATIC);
speedtest1_execute();
}
speedtest1_exec("COMMIT");
speedtest1_end_test();
n = 10;
speedtest1_begin_test(142, "%d SELECTS w/ORDER BY, unindexed", n);
speedtest1_exec("BEGIN");
speedtest1_prepare(
"SELECT a, b, c FROM t1 WHERE c LIKE ?1\n"
" ORDER BY a; -- %d times", n
);
for(i=1; i<=n; i++){
x1 = speedtest1_random()%maxb;
zNum[0] = '%';
len = speedtest1_numbername(i, zNum+1, sizeof(zNum)-2);
zNum[len] = '%';
zNum[len+1] = 0;
sqlite3_bind_text(g.pStmt, 1, zNum, len, SQLITE_STATIC);
speedtest1_execute();
}
speedtest1_exec("COMMIT");
speedtest1_end_test();
n = 10; //g.szTest/5;
speedtest1_begin_test(145, "%d SELECTS w/ORDER BY and LIMIT, unindexed", n);
speedtest1_exec("BEGIN");
speedtest1_prepare(
"SELECT a, b, c FROM t1 WHERE c LIKE ?1\n"
" ORDER BY a LIMIT 10; -- %d times", n
);
for(i=1; i<=n; i++){
x1 = speedtest1_random()%maxb;
zNum[0] = '%';
len = speedtest1_numbername(i, zNum+1, sizeof(zNum)-2);
zNum[len] = '%';
zNum[len+1] = 0;
sqlite3_bind_text(g.pStmt, 1, zNum, len, SQLITE_STATIC);
speedtest1_execute();
}
speedtest1_exec("COMMIT");
speedtest1_end_test();
speedtest1_begin_test(150, "CREATE INDEX five times");
speedtest1_exec("BEGIN;");
speedtest1_exec("CREATE UNIQUE INDEX t1b ON t1(b);");
speedtest1_exec("CREATE INDEX t1c ON t1(c);");
speedtest1_exec("CREATE UNIQUE INDEX t2b ON t2(b);");
speedtest1_exec("CREATE INDEX t2c ON t2(c DESC);");
speedtest1_exec("CREATE INDEX t3bc ON t3(b,c);");
speedtest1_exec("COMMIT;");
speedtest1_end_test();
n = sz/5;
speedtest1_begin_test(160, "%d SELECTS, numeric BETWEEN, indexed", n);
speedtest1_exec("BEGIN");
speedtest1_prepare(
"SELECT count(*), avg(b), sum(length(c)) FROM t1\n"
" WHERE b BETWEEN ?1 AND ?2; -- %d times", n
);
for(i=1; i<=n; i++){
x1 = speedtest1_random()%maxb;
x2 = speedtest1_random()%10 + sz/5000 + x1;
sqlite3_bind_int(g.pStmt, 1, x1);
sqlite3_bind_int(g.pStmt, 2, x2);
speedtest1_execute();
}
speedtest1_exec("COMMIT");
speedtest1_end_test();
n = sz/5;
speedtest1_begin_test(161, "%d SELECTS, numeric BETWEEN, PK", n);
speedtest1_exec("BEGIN");
speedtest1_prepare(
"SELECT count(*), avg(b), sum(length(c)) FROM t2\n"
" WHERE a BETWEEN ?1 AND ?2; -- %d times", n
);
for(i=1; i<=n; i++){
x1 = speedtest1_random()%maxb;
x2 = speedtest1_random()%10 + sz/5000 + x1;
sqlite3_bind_int(g.pStmt, 1, x1);
sqlite3_bind_int(g.pStmt, 2, x2);
speedtest1_execute();
}
speedtest1_exec("COMMIT");
speedtest1_end_test();
n = sz/5;
speedtest1_begin_test(170, "%d SELECTS, text BETWEEN, indexed", n);
speedtest1_exec("BEGIN");
speedtest1_prepare(
"SELECT count(*), avg(b), sum(length(c)) FROM t1\n"
" WHERE c BETWEEN ?1 AND (?1||'~'); -- %d times", n
);
for(i=1; i<=n; i++){
x1 = swizzle(i, maxb);
len = speedtest1_numbername(x1, zNum, sizeof(zNum)-1);
sqlite3_bind_text(g.pStmt, 1, zNum, len, SQLITE_STATIC);
speedtest1_execute();
}
speedtest1_exec("COMMIT");
speedtest1_end_test();
n = sz;
speedtest1_begin_test(180, "%d INSERTS with three indexes", n);
speedtest1_exec("BEGIN");
speedtest1_exec(
"CREATE TABLE t4(\n"
" a INTEGER %s %s,\n"
" b INTEGER %s,\n"
" c TEXT %s\n"
") %s",
g.zNN, g.zPK, g.zNN, g.zNN, g.zWR);
speedtest1_exec("CREATE INDEX t4b ON t4(b)");
speedtest1_exec("CREATE INDEX t4c ON t4(c)");
speedtest1_exec("INSERT INTO t4 SELECT * FROM t1");
speedtest1_exec("COMMIT");
speedtest1_end_test();
n = sz;
speedtest1_begin_test(190, "DELETE and REFILL one table", n);
speedtest1_exec("DELETE FROM t2;");
speedtest1_exec("INSERT INTO t2 SELECT * FROM t1;");
speedtest1_end_test();
// #include <emscripten.h>
speedtest1_begin_test(200, "VACUUM");
// EM_ASM( alert('pre') );
speedtest1_exec("VACUUM");
// EM_ASM( alert('post') );
speedtest1_end_test();
speedtest1_begin_test(210, "ALTER TABLE ADD COLUMN, and query");
speedtest1_exec("ALTER TABLE t2 ADD COLUMN d DEFAULT 123");
speedtest1_exec("SELECT sum(d) FROM t2");
speedtest1_end_test();
n = sz/5;
speedtest1_begin_test(230, "%d UPDATES, numeric BETWEEN, indexed", n);
speedtest1_exec("BEGIN");
speedtest1_prepare(
"UPDATE t2 SET d=b*2 WHERE b BETWEEN ?1 AND ?2; -- %d times", n
);
for(i=1; i<=n; i++){
x1 = speedtest1_random()%maxb;
x2 = speedtest1_random()%10 + sz/5000 + x1;
sqlite3_bind_int(g.pStmt, 1, x1);
sqlite3_bind_int(g.pStmt, 2, x2);
speedtest1_execute();
}
speedtest1_exec("COMMIT");
speedtest1_end_test();
n = sz;
speedtest1_begin_test(240, "%d UPDATES of individual rows", n);
speedtest1_exec("BEGIN");
speedtest1_prepare(
"UPDATE t2 SET d=b*3 WHERE a=?1; -- %d times", n
);
for(i=1; i<=n; i++){
x1 = speedtest1_random()%sz + 1;
sqlite3_bind_int(g.pStmt, 1, x1);
speedtest1_execute();
}
speedtest1_exec("COMMIT");
speedtest1_end_test();
speedtest1_begin_test(250, "One big UPDATE of the whole %d-row table", sz);
speedtest1_exec("UPDATE t2 SET d=b*4");
speedtest1_end_test();
speedtest1_begin_test(260, "Query added column after filling");
speedtest1_exec("SELECT sum(d) FROM t2");
speedtest1_end_test();
n = sz/5;
speedtest1_begin_test(270, "%d DELETEs, numeric BETWEEN, indexed", n);
speedtest1_exec("BEGIN");
speedtest1_prepare(
"DELETE FROM t2 WHERE b BETWEEN ?1 AND ?2; -- %d times", n
);
for(i=1; i<=n; i++){
x1 = speedtest1_random()%maxb + 1;
x2 = speedtest1_random()%10 + sz/5000 + x1;
sqlite3_bind_int(g.pStmt, 1, x1);
sqlite3_bind_int(g.pStmt, 2, x2);
speedtest1_execute();
}
speedtest1_exec("COMMIT");
speedtest1_end_test();
n = sz;
speedtest1_begin_test(280, "%d DELETEs of individual rows", n);
speedtest1_exec("BEGIN");
speedtest1_prepare(
"DELETE FROM t3 WHERE a=?1; -- %d times", n
);
for(i=1; i<=n; i++){
x1 = speedtest1_random()%sz + 1;
sqlite3_bind_int(g.pStmt, 1, x1);
speedtest1_execute();
}
speedtest1_exec("COMMIT");
speedtest1_end_test();
speedtest1_begin_test(290, "Refill two %d-row tables using REPLACE", sz);
speedtest1_exec("REPLACE INTO t2(a,b,c) SELECT a,b,c FROM t1");
speedtest1_exec("REPLACE INTO t3(a,b,c) SELECT a,b,c FROM t1");
speedtest1_end_test();
speedtest1_begin_test(300, "Refill a %d-row table using (b&1)==(a&1)", sz);
speedtest1_exec("DELETE FROM t2;");
speedtest1_exec("INSERT INTO t2(a,b,c)\n"
" SELECT a,b,c FROM t1 WHERE (b&1)==(a&1);");
speedtest1_exec("INSERT INTO t2(a,b,c)\n"
" SELECT a,b,c FROM t1 WHERE (b&1)<>(a&1);");
speedtest1_end_test();
n = sz/5;
speedtest1_begin_test(310, "%d four-ways joins", n);
speedtest1_exec("BEGIN");
speedtest1_prepare(
"SELECT t1.c FROM t1, t2, t3, t4\n"
" WHERE t4.a BETWEEN ?1 AND ?2\n"
" AND t3.a=t4.b\n"
" AND t2.a=t3.b\n"
" AND t1.c=t2.c"
);
for(i=1; i<=n; i++){
x1 = speedtest1_random()%sz + 1;
x2 = speedtest1_random()%10 + x1 + 4;
sqlite3_bind_int(g.pStmt, 1, x1);
sqlite3_bind_int(g.pStmt, 2, x2);
speedtest1_execute();
}
speedtest1_exec("COMMIT");
speedtest1_end_test();
speedtest1_begin_test(320, "subquery in result set", n);
speedtest1_prepare(
"SELECT sum(a), max(c),\n"
" avg((SELECT a FROM t2 WHERE 5+t2.b=t1.b) AND rowid<?1), max(c)\n"
" FROM t1 WHERE rowid<?1;"
);
sqlite3_bind_int(g.pStmt, 1, est_square_root(g.szTest)*50);
speedtest1_execute();
speedtest1_end_test();
speedtest1_begin_test(980, "PRAGMA integrity_check");
speedtest1_exec("PRAGMA integrity_check");
speedtest1_end_test();
speedtest1_begin_test(990, "ANALYZE");
speedtest1_exec("ANALYZE");
speedtest1_end_test();
}
/*
** A testset for common table expressions. This exercises code
** for views, subqueries, co-routines, etc.
*/
void testset_cte(void){
static const char *azPuzzle[] = {
/* Easy */
"534...9.."
"67.195..."
".98....6."
"8...6...3"
"4..8.3..1"
"....2...6"
".6....28."
"...419..5"
"...28..79",
/* Medium */
"53....9.."
"6..195..."
".98....6."
"8...6...3"
"4..8.3..1"
"....2...6"
".6....28."
"...419..5"
"....8..79",
/* Hard */
"53......."
"6..195..."
".98....6."
"8...6...3"
"4..8.3..1"
"....2...6"
".6....28."
"...419..5"
"....8..79",
};
const char *zPuz;
double rSpacing;
int nElem;
if( g.szTest<25 ){
zPuz = azPuzzle[0];
}else if( g.szTest<70 ){
zPuz = azPuzzle[1];
}else{
zPuz = azPuzzle[2];
}
speedtest1_begin_test(100, "Sudoku with recursive 'digits'");
speedtest1_prepare(
"WITH RECURSIVE\n"
" input(sud) AS (VALUES(?1)),\n"
" digits(z,lp) AS (\n"
" VALUES('1', 1)\n"
" UNION ALL\n"
" SELECT CAST(lp+1 AS TEXT), lp+1 FROM digits WHERE lp<9\n"
" ),\n"
" x(s, ind) AS (\n"
" SELECT sud, instr(sud, '.') FROM input\n"
" UNION ALL\n"
" SELECT\n"
" substr(s, 1, ind-1) || z || substr(s, ind+1),\n"
" instr( substr(s, 1, ind-1) || z || substr(s, ind+1), '.' )\n"
" FROM x, digits AS z\n"
" WHERE ind>0\n"
" AND NOT EXISTS (\n"
" SELECT 1\n"
" FROM digits AS lp\n"
" WHERE z.z = substr(s, ((ind-1)/9)*9 + lp, 1)\n"
" OR z.z = substr(s, ((ind-1)%%9) + (lp-1)*9 + 1, 1)\n"
" OR z.z = substr(s, (((ind-1)/3) %% 3) * 3\n"
" + ((ind-1)/27) * 27 + lp\n"
" + ((lp-1) / 3) * 6, 1)\n"
" )\n"
" )\n"
"SELECT s FROM x WHERE ind=0;"
);
sqlite3_bind_text(g.pStmt, 1, zPuz, -1, SQLITE_STATIC);
speedtest1_execute();
speedtest1_end_test();
speedtest1_begin_test(200, "Sudoku with VALUES 'digits'");
speedtest1_prepare(
"WITH RECURSIVE\n"
" input(sud) AS (VALUES(?1)),\n"
" digits(z,lp) AS (VALUES('1',1),('2',2),('3',3),('4',4),('5',5),\n"
" ('6',6),('7',7),('8',8),('9',9)),\n"
" x(s, ind) AS (\n"
" SELECT sud, instr(sud, '.') FROM input\n"
" UNION ALL\n"
" SELECT\n"
" substr(s, 1, ind-1) || z || substr(s, ind+1),\n"
" instr( substr(s, 1, ind-1) || z || substr(s, ind+1), '.' )\n"
" FROM x, digits AS z\n"
" WHERE ind>0\n"
" AND NOT EXISTS (\n"
" SELECT 1\n"
" FROM digits AS lp\n"
" WHERE z.z = substr(s, ((ind-1)/9)*9 + lp, 1)\n"
" OR z.z = substr(s, ((ind-1)%%9) + (lp-1)*9 + 1, 1)\n"
" OR z.z = substr(s, (((ind-1)/3) %% 3) * 3\n"
" + ((ind-1)/27) * 27 + lp\n"
" + ((lp-1) / 3) * 6, 1)\n"
" )\n"
" )\n"
"SELECT s FROM x WHERE ind=0;"
);
sqlite3_bind_text(g.pStmt, 1, zPuz, -1, SQLITE_STATIC);
speedtest1_execute();
speedtest1_end_test();
rSpacing = 5.0/g.szTest;
speedtest1_begin_test(300, "Mandelbrot Set with spacing=%f", rSpacing);
speedtest1_prepare(
"WITH RECURSIVE \n"
" xaxis(x) AS (VALUES(-2.0) UNION ALL SELECT x+?1 FROM xaxis WHERE x<1.2),\n"
" yaxis(y) AS (VALUES(-1.0) UNION ALL SELECT y+?2 FROM yaxis WHERE y<1.0),\n"
" m(iter, cx, cy, x, y) AS (\n"
" SELECT 0, x, y, 0.0, 0.0 FROM xaxis, yaxis\n"
" UNION ALL\n"
" SELECT iter+1, cx, cy, x*x-y*y + cx, 2.0*x*y + cy FROM m \n"
" WHERE (x*x + y*y) < 4.0 AND iter<28\n"
" ),\n"
" m2(iter, cx, cy) AS (\n"
" SELECT max(iter), cx, cy FROM m GROUP BY cx, cy\n"
" ),\n"
" a(t) AS (\n"
" SELECT group_concat( substr(' .+*#', 1+min(iter/7,4), 1), '') \n"
" FROM m2 GROUP BY cy\n"
" )\n"
"SELECT group_concat(rtrim(t),x'0a') FROM a;"
);
sqlite3_bind_double(g.pStmt, 1, rSpacing*.05);
sqlite3_bind_double(g.pStmt, 2, rSpacing);
speedtest1_execute();
speedtest1_end_test();
nElem = 10000*g.szTest;
speedtest1_begin_test(400, "EXCEPT operator on %d-element tables", nElem);
speedtest1_prepare(
"WITH RECURSIVE \n"
" t1(x) AS (VALUES(2) UNION ALL SELECT x+2 FROM t1 WHERE x<%d),\n"
" t2(y) AS (VALUES(3) UNION ALL SELECT y+3 FROM t2 WHERE y<%d)\n"
"SELECT count(x), avg(x) FROM (\n"
" SELECT x FROM t1 EXCEPT SELECT y FROM t2 ORDER BY 1\n"
");",
nElem, nElem
);
speedtest1_execute();
speedtest1_end_test();
}
/* Generate two numbers between 1 and mx. The first number is less than
** the second. Usually the numbers are near each other but can sometimes
** be far apart.
*/
static void twoCoords(
int p1, int p2, /* Parameters adjusting sizes */
unsigned mx, /* Range of 1..mx */
unsigned *pX0, unsigned *pX1 /* OUT: write results here */
){
unsigned d, x0, x1, span;
span = mx/100 + 1;
if( speedtest1_random()%3==0 ) span *= p1;
if( speedtest1_random()%p2==0 ) span = mx/2;
d = speedtest1_random()%span + 1;
x0 = speedtest1_random()%(mx-d) + 1;
x1 = x0 + d;
*pX0 = x0;
*pX1 = x1;
}
/* The following routine is an R-Tree geometry callback. It returns
** true if the object overlaps a slice on the Y coordinate between the
** two values given as arguments. In other words
**
** SELECT count(*) FROM rt1 WHERE id MATCH xslice(10,20);
**
** Is the same as saying:
**
** SELECT count(*) FROM rt1 WHERE y1>=10 AND y0<=20;
*/
static int xsliceGeometryCallback(
sqlite3_rtree_geometry *p,
int nCoord,
double *aCoord,
int *pRes
){
*pRes = aCoord[3]>=p->aParam[0] && aCoord[2]<=p->aParam[1];
return SQLITE_OK;
}
/*
** A testset for the R-Tree virtual table
*/
void testset_rtree(int p1, int p2){
unsigned i, n;
unsigned mxCoord;
unsigned x0, x1, y0, y1, z0, z1;
unsigned iStep;
int *aCheck = sqlite3_malloc( sizeof(int)*g.szTest*100 );
mxCoord = 15000;
n = g.szTest*100;
speedtest1_begin_test(100, "%d INSERTs into an r-tree", n);
speedtest1_exec("BEGIN");
speedtest1_exec("CREATE VIRTUAL TABLE rt1 USING rtree(id,x0,x1,y0,y1,z0,z1)");
speedtest1_prepare("INSERT INTO rt1(id,x0,x1,y0,y1,z0,z1)"
"VALUES(?1,?2,?3,?4,?5,?6,?7)");
for(i=1; i<=n; i++){
twoCoords(p1, p2, mxCoord, &x0, &x1);
twoCoords(p1, p2, mxCoord, &y0, &y1);
twoCoords(p1, p2, mxCoord, &z0, &z1);
sqlite3_bind_int(g.pStmt, 1, i);
sqlite3_bind_int(g.pStmt, 2, x0);
sqlite3_bind_int(g.pStmt, 3, x1);
sqlite3_bind_int(g.pStmt, 4, y0);
sqlite3_bind_int(g.pStmt, 5, y1);
sqlite3_bind_int(g.pStmt, 6, z0);
sqlite3_bind_int(g.pStmt, 7, z1);
speedtest1_execute();
}
speedtest1_exec("COMMIT");
speedtest1_end_test();
speedtest1_begin_test(101, "Copy from rtree to a regular table");
speedtest1_exec("CREATE TABLE t1(id INTEGER PRIMARY KEY,x0,x1,y0,y1,z0,z1)");
speedtest1_exec("INSERT INTO t1 SELECT * FROM rt1");
speedtest1_end_test();
n = g.szTest*20;
speedtest1_begin_test(110, "%d one-dimensional intersect slice queries", n);
speedtest1_prepare("SELECT count(*) FROM rt1 WHERE x0>=?1 AND x1<=?2");
iStep = mxCoord/n;
for(i=0; i<n; i++){
sqlite3_bind_int(g.pStmt, 1, i*iStep);
sqlite3_bind_int(g.pStmt, 2, (i+1)*iStep);
speedtest1_execute();
aCheck[i] = atoi(g.zResult);
}
speedtest1_end_test();
if( g.bVerify ){
n = g.szTest*20;
speedtest1_begin_test(111, "Verify result from 1-D intersect slice queries");
speedtest1_prepare("SELECT count(*) FROM t1 WHERE x0>=?1 AND x1<=?2");
iStep = mxCoord/n;
for(i=0; i<n; i++){
sqlite3_bind_int(g.pStmt, 1, i*iStep);
sqlite3_bind_int(g.pStmt, 2, (i+1)*iStep);
speedtest1_execute();
if( aCheck[i]!=atoi(g.zResult) ){
fatal_error("Count disagree step %d: %d..%d. %d vs %d",
i, i*iStep, (i+1)*iStep, aCheck[i], atoi(g.zResult));
}
}
speedtest1_end_test();
}
n = g.szTest*20;
speedtest1_begin_test(120, "%d one-dimensional overlap slice queries", n);
speedtest1_prepare("SELECT count(*) FROM rt1 WHERE y1>=?1 AND y0<=?2");
iStep = mxCoord/n;
for(i=0; i<n; i++){
sqlite3_bind_int(g.pStmt, 1, i*iStep);
sqlite3_bind_int(g.pStmt, 2, (i+1)*iStep);
speedtest1_execute();
aCheck[i] = atoi(g.zResult);
}
speedtest1_end_test();
if( g.bVerify ){
n = g.szTest*20;
speedtest1_begin_test(121, "Verify result from 1-D overlap slice queries");
speedtest1_prepare("SELECT count(*) FROM t1 WHERE y1>=?1 AND y0<=?2");
iStep = mxCoord/n;
for(i=0; i<n; i++){
sqlite3_bind_int(g.pStmt, 1, i*iStep);
sqlite3_bind_int(g.pStmt, 2, (i+1)*iStep);
speedtest1_execute();
if( aCheck[i]!=atoi(g.zResult) ){
fatal_error("Count disagree step %d: %d..%d. %d vs %d",
i, i*iStep, (i+1)*iStep, aCheck[i], atoi(g.zResult));
}
}
speedtest1_end_test();
}
n = g.szTest*20;
speedtest1_begin_test(125, "%d custom geometry callback queries", n);
//sqlite3_rtree_geometry_callback(g.db, "xslice", xsliceGeometryCallback, 0);
speedtest1_prepare("SELECT count(*) FROM rt1 WHERE id MATCH xslice(?1,?2)");
iStep = mxCoord/n;
for(i=0; i<n; i++){
sqlite3_bind_int(g.pStmt, 1, i*iStep);
sqlite3_bind_int(g.pStmt, 2, (i+1)*iStep);
speedtest1_execute();
if( aCheck[i]!=atoi(g.zResult) ){
fatal_error("Count disagree step %d: %d..%d. %d vs %d",
i, i*iStep, (i+1)*iStep, aCheck[i], atoi(g.zResult));
}
}
speedtest1_end_test();
n = g.szTest*80;
speedtest1_begin_test(130, "%d three-dimensional intersect box queries", n);
speedtest1_prepare("SELECT count(*) FROM rt1 WHERE x1>=?1 AND x0<=?2"
" AND y1>=?1 AND y0<=?2 AND z1>=?1 AND z0<=?2");
iStep = mxCoord/n;
for(i=0; i<n; i++){
sqlite3_bind_int(g.pStmt, 1, i*iStep);
sqlite3_bind_int(g.pStmt, 2, (i+1)*iStep);
speedtest1_execute();
aCheck[i] = atoi(g.zResult);
}
speedtest1_end_test();
n = g.szTest*100;
speedtest1_begin_test(140, "%d rowid queries", n);
speedtest1_prepare("SELECT * FROM rt1 WHERE id=?1");
for(i=1; i<=n; i++){
sqlite3_bind_int(g.pStmt, 1, i);
speedtest1_execute();
}
speedtest1_end_test();
}
/*
** A testset used for debugging speedtest1 itself.
*/
void testset_debug1(void){
unsigned i, n;
unsigned x1, x2;
char zNum[2000]; /* A number name */
n = g.szTest;
for(i=1; i<=n; i++){
x1 = swizzle(i, n);
x2 = swizzle(x1, n);
speedtest1_numbername(x1, zNum, sizeof(zNum));
printf("%5d %5d %5d %s\n", i, x1, x2, zNum);
}
}
int main(int argc, char **argv){
int doAutovac = 0; /* True for --autovacuum */
int cacheSize = 0; /* Desired cache size. 0 means default */
int doExclusive = 0; /* True for --exclusive */
int nHeap = 0, mnHeap = 0; /* Heap size from --heap */
int doIncrvac = 0; /* True for --incrvacuum */
const char *zJMode = 0; /* Journal mode */
const char *zKey = 0; /* Encryption key */
int nLook = 0, szLook = 0; /* --lookaside configuration */
int noSync = 0; /* True for --nosync */
int pageSize = 0; /* Desired page size. 0 means default */
int nPCache = 0, szPCache = 0;/* --pcache configuration */
int nScratch = 0, szScratch=0;/* --scratch configuration */
int showStats = 0; /* True for --stats */
const char *zTSet = "main"; /* Which --testset torun */
int doTrace = 0; /* True for --trace */
const char *zEncoding = 0; /* --utf16be or --utf16le */
const char *zDbName = 0; /* Name of the test database */
void *pHeap = 0; /* Allocated heap space */
void *pLook = 0; /* Allocated lookaside space */
void *pPCache = 0; /* Allocated storage for pcache */
void *pScratch = 0; /* Allocated storage for scratch */
int iCur, iHi; /* Stats values, current and "highwater" */
int i; /* Loop counter */
int rc; /* API return code */
/* Process command-line arguments */
g.zWR = "";
g.zNN = "";
g.zPK = "UNIQUE";
g.szTest = 100;
/* Emscripten commandline argument processing - first arg is ours */
int arg = argc > 1 ? argv[1][0] - '0' : 3;
switch(arg) {
case 0: return 0; break;
case 1: arg = 5; break;
case 2: arg = 10; break;
case 3: arg = 20; break;
case 4: arg = 40; break;
case 5: arg = 80; break;
default:
printf("error: %d\\n", arg);
return -1;
}
g.szTest = arg;
/* Back to sqlite - after the first is theirs*/
for(i=2; i<argc; i++){
const char *z = argv[i];
if( z[0]=='-' ){
do{ z++; }while( z[0]=='-' );
if( strcmp(z,"autovacuum")==0 ){
doAutovac = 1;
}else if( strcmp(z,"cachesize")==0 ){
if( i>=argc-1 ) fatal_error("missing argument on %s\n", argv[i]);
i++;
cacheSize = integerValue(argv[i]);
}else if( strcmp(z,"exclusive")==0 ){
doExclusive = 1;
}else if( strcmp(z,"explain")==0 ){
g.bSqlOnly = 1;
g.bExplain = 1;
}else if( strcmp(z,"heap")==0 ){
if( i>=argc-2 ) fatal_error("missing arguments on %s\n", argv[i]);
nHeap = integerValue(argv[i+1]);
mnHeap = integerValue(argv[i+2]);
i += 2;
}else if( strcmp(z,"incrvacuum")==0 ){
doIncrvac = 1;
}else if( strcmp(z,"journal")==0 ){
if( i>=argc-1 ) fatal_error("missing argument on %s\n", argv[i]);
zJMode = argv[++i];
}else if( strcmp(z,"key")==0 ){
if( i>=argc-1 ) fatal_error("missing argument on %s\n", argv[i]);
zKey = argv[++i];
}else if( strcmp(z,"lookaside")==0 ){
if( i>=argc-2 ) fatal_error("missing arguments on %s\n", argv[i]);
nLook = integerValue(argv[i+1]);
szLook = integerValue(argv[i+2]);
i += 2;
}else if( strcmp(z,"nosync")==0 ){
noSync = 1;
}else if( strcmp(z,"notnull")==0 ){
g.zNN = "NOT NULL";
}else if( strcmp(z,"pagesize")==0 ){
if( i>=argc-1 ) fatal_error("missing argument on %s\n", argv[i]);
pageSize = integerValue(argv[++i]);
}else if( strcmp(z,"pcache")==0 ){
if( i>=argc-2 ) fatal_error("missing arguments on %s\n", argv[i]);
nPCache = integerValue(argv[i+1]);
szPCache = integerValue(argv[i+2]);
i += 2;
}else if( strcmp(z,"primarykey")==0 ){
g.zPK = "PRIMARY KEY";
}else if( strcmp(z,"reprepare")==0 ){
g.bReprepare = 1;
}else if( strcmp(z,"scratch")==0 ){
if( i>=argc-2 ) fatal_error("missing arguments on %s\n", argv[i]);
nScratch = integerValue(argv[i+1]);
szScratch = integerValue(argv[i+2]);
i += 2;
}else if( strcmp(z,"sqlonly")==0 ){
g.bSqlOnly = 1;
}else if( strcmp(z,"size")==0 ){
if( i>=argc-1 ) fatal_error("missing argument on %s\n", argv[i]);
g.szTest = integerValue(argv[++i]);
}else if( strcmp(z,"stats")==0 ){
showStats = 1;
}else if( strcmp(z,"testset")==0 ){
if( i>=argc-1 ) fatal_error("missing argument on %s\n", argv[i]);
zTSet = argv[++i];
}else if( strcmp(z,"trace")==0 ){
doTrace = 1;
}else if( strcmp(z,"utf16le")==0 ){
zEncoding = "utf16le";
}else if( strcmp(z,"utf16be")==0 ){
zEncoding = "utf16be";
}else if( strcmp(z,"verify")==0 ){
g.bVerify = 1;
}else if( strcmp(z,"without-rowid")==0 ){
g.zWR = "WITHOUT ROWID";
g.zPK = "PRIMARY KEY";
}else if( strcmp(z, "help")==0 || strcmp(z,"?")==0 ){
printf(zHelp, argv[0]);
exit(0);
}else{
fatal_error("unknown option: %s\nUse \"%s -?\" for help\n",
argv[i], argv[0]);
}
}else if( zDbName==0 ){
zDbName = argv[i];
}else{
fatal_error("surplus argument: %s\nUse \"%s -?\" for help\n",
argv[i], argv[0]);
}
}
#if 0
if( zDbName==0 ){
fatal_error(zHelp, argv[0]);
}
#endif
if( nHeap>0 ){
pHeap = malloc( nHeap );
if( pHeap==0 ) fatal_error("cannot allocate %d-byte heap\n", nHeap);
rc = sqlite3_config(SQLITE_CONFIG_HEAP, pHeap, nHeap, mnHeap);
if( rc ) fatal_error("heap configuration failed: %d\n", rc);
}
if( nPCache>0 && szPCache>0 ){
pPCache = malloc( nPCache*(sqlite3_int64)szPCache );
if( pPCache==0 ) fatal_error("cannot allocate %lld-byte pcache\n",
nPCache*(sqlite3_int64)szPCache);
rc = sqlite3_config(SQLITE_CONFIG_PAGECACHE, pPCache, szPCache, nPCache);
if( rc ) fatal_error("pcache configuration failed: %d\n", rc);
}
if( nScratch>0 && szScratch>0 ){
pScratch = malloc( nScratch*(sqlite3_int64)szScratch );
if( pScratch==0 ) fatal_error("cannot allocate %lld-byte scratch\n",
nScratch*(sqlite3_int64)szScratch);
rc = sqlite3_config(SQLITE_CONFIG_SCRATCH, pScratch, szScratch, nScratch);
if( rc ) fatal_error("scratch configuration failed: %d\n", rc);
}
if( nLook>0 ){
sqlite3_config(SQLITE_CONFIG_LOOKASIDE, 0, 0);
}
/* Open the database and the input file */
if( sqlite3_open(":memory:", &g.db) ){
fatal_error("Cannot open database file: %s\n", zDbName);
}
if( nLook>0 && szLook>0 ){
pLook = malloc( nLook*szLook );
rc = sqlite3_db_config(g.db, SQLITE_DBCONFIG_LOOKASIDE, pLook, szLook,nLook);
if( rc ) fatal_error("lookaside configuration failed: %d\n", rc);
}
/* Set database connection options */
sqlite3_create_function(g.db, "random", 0, SQLITE_UTF8, 0, randomFunc1, 0, 0);
if( doTrace ) sqlite3_trace(g.db, traceCallback, 0);
if( zKey ){
speedtest1_exec("PRAGMA key('%s')", zKey);
}
if( zEncoding ){
speedtest1_exec("PRAGMA encoding=%s", zEncoding);
}
if( doAutovac ){
speedtest1_exec("PRAGMA auto_vacuum=FULL");
}else if( doIncrvac ){
speedtest1_exec("PRAGMA auto_vacuum=INCREMENTAL");
}
if( pageSize ){
speedtest1_exec("PRAGMA page_size=%d", pageSize);
}
if( cacheSize ){
speedtest1_exec("PRAGMA cache_size=%d", cacheSize);
}
if( noSync ) speedtest1_exec("PRAGMA synchronous=OFF");
if( doExclusive ){
speedtest1_exec("PRAGMA locking_mode=EXCLUSIVE");
}
if( zJMode ){
speedtest1_exec("PRAGMA journal_mode=%s", zJMode);
}
if( g.bExplain ) printf(".explain\n.echo on\n");
if( strcmp(zTSet,"main")==0 ){
testset_main();
}else if( strcmp(zTSet,"debug1")==0 ){
testset_debug1();
}else if( strcmp(zTSet,"cte")==0 ){
testset_cte();
}else if( strcmp(zTSet,"rtree")==0 ){
testset_rtree(6, 147);
}else{
fatal_error("unknown testset: \"%s\"\nChoices: main debug1 cte rtree\n",
zTSet);
}
speedtest1_final();
/* Database connection statistics printed after both prepared statements
** have been finalized */
#if SQLITE_VERSION_NUMBER>=3007009
if( showStats ){
sqlite3_db_status(g.db, SQLITE_DBSTATUS_LOOKASIDE_USED, &iCur, &iHi, 0);
printf("-- Lookaside Slots Used: %d (max %d)\n", iCur,iHi);
sqlite3_db_status(g.db, SQLITE_DBSTATUS_LOOKASIDE_HIT, &iCur, &iHi, 0);
printf("-- Successful lookasides: %d\n", iHi);
sqlite3_db_status(g.db, SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE, &iCur,&iHi,0);
printf("-- Lookaside size faults: %d\n", iHi);
sqlite3_db_status(g.db, SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL, &iCur,&iHi,0);
printf("-- Lookaside OOM faults: %d\n", iHi);
sqlite3_db_status(g.db, SQLITE_DBSTATUS_CACHE_USED, &iCur, &iHi, 0);
printf("-- Pager Heap Usage: %d bytes\n", iCur);
sqlite3_db_status(g.db, SQLITE_DBSTATUS_CACHE_HIT, &iCur, &iHi, 1);
printf("-- Page cache hits: %d\n", iCur);
sqlite3_db_status(g.db, SQLITE_DBSTATUS_CACHE_MISS, &iCur, &iHi, 1);
printf("-- Page cache misses: %d\n", iCur);
#if SQLITE_VERSION_NUMBER>=3007012
sqlite3_db_status(g.db, SQLITE_DBSTATUS_CACHE_WRITE, &iCur, &iHi, 1);
printf("-- Page cache writes: %d\n", iCur);
#endif
sqlite3_db_status(g.db, SQLITE_DBSTATUS_SCHEMA_USED, &iCur, &iHi, 0);
printf("-- Schema Heap Usage: %d bytes\n", iCur);
sqlite3_db_status(g.db, SQLITE_DBSTATUS_STMT_USED, &iCur, &iHi, 0);
printf("-- Statement Heap Usage: %d bytes\n", iCur);
}
#endif
sqlite3_close(g.db);
/* Global memory usage statistics printed after the database connection
** has closed. Memory usage should be zero at this point. */
if( showStats ){
sqlite3_status(SQLITE_STATUS_MEMORY_USED, &iCur, &iHi, 0);
printf("-- Memory Used (bytes): %d (max %d)\n", iCur,iHi);
#if SQLITE_VERSION_NUMBER>=3007000
sqlite3_status(SQLITE_STATUS_MALLOC_COUNT, &iCur, &iHi, 0);
printf("-- Outstanding Allocations: %d (max %d)\n", iCur,iHi);
#endif
sqlite3_status(SQLITE_STATUS_PAGECACHE_OVERFLOW, &iCur, &iHi, 0);
printf("-- Pcache Overflow Bytes: %d (max %d)\n", iCur,iHi);
sqlite3_status(SQLITE_STATUS_SCRATCH_OVERFLOW, &iCur, &iHi, 0);
printf("-- Scratch Overflow Bytes: %d (max %d)\n", iCur,iHi);
sqlite3_status(SQLITE_STATUS_MALLOC_SIZE, &iCur, &iHi, 0);
printf("-- Largest Allocation: %d bytes\n",iHi);
sqlite3_status(SQLITE_STATUS_PAGECACHE_SIZE, &iCur, &iHi, 0);
printf("-- Largest Pcache Allocation: %d bytes\n",iHi);
sqlite3_status(SQLITE_STATUS_SCRATCH_SIZE, &iCur, &iHi, 0);
printf("-- Largest Scratch Allocation: %d bytes\n", iHi);
}
/* Release memory */
free( pLook );
free( pPCache );
free( pScratch );
free( pHeap );
return 0;
}
|
the_stack_data/1137533.c | //Chris Wells 2015
//956335
//November 12, 2014
//guessthenumber.c
//Purpose: To let the user guess a random number [1 - 10,000] until they get it right and print out how many guesses they took.
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
//Begin main function
void main()
{
int num; //Declare variable to store the random number
int guess; //Declare variable to store the number that the user guesses
int i; //Declare controller variable
int total = 0; //Initialize variable to store the number guesses that the user has made
//Set the rand seed
srand(time(NULL));
//Generate the random number
num = rand() % 1000 + 1;
//Loop to let the user guess the number
i = 0;
while( i == 0 )
{
//Take the user's guess
guess = -1;
while( (guess < 1) || (guess > 1000) )
{
printf("Guess a number between 1 and 1,000: ");
scanf("%d", &guess);
if( (guess < 1) || (guess > 1000) )
printf("Not in number range.\n");
}
//Increase number of guesses taken
total += 1;
//Test if number is correct, higher or lower
if( guess == num ) //Correct
{
i = 1;
}
else if( num > guess ) //Higher
{
printf("Higher!\n");
}
else if( num < guess ) //Lower
{
printf("Lower!\n");
}
}
//Print end message, as user has correctly guessed
printf("~~~~~~~\n");
printf("Correct! The number is %d.\n", num);
printf("Guesses: %d\n", total);
//Test if player made 10 or less guesses
if( total <= 10 )
printf("Congratz! You guessed the number in 10 or less guesses.");
else
printf("Unfortunately it took you more than 10 guesses to get the correct number.");
} |
the_stack_data/154829605.c | #include <stdlib.h>
typedef char const* (*PTRFUN)();
typedef struct {
PTRFUN* vtable;
char const* name;
} Parrot;
char const* name(Parrot* p) { return p->name; }
char const* greet(void) { return "grr!"; }
char const* menu(void) { return "sjemenke"; }
PTRFUN vtable[] = {(PTRFUN)name, greet, menu};
void* create(char const* name) {
Parrot* p = (Parrot*)malloc(sizeof(Parrot));
p->vtable = vtable;
p->name = name;
return p;
}
void* createStack(char const* name) {
Parrot p;
p.vtable = vtable;
p.name = name;
return &p;
}
|
the_stack_data/864034.c | // Example Program for making patterns:
#include <stdio.h>
int main()
{
int i, j, a;
a=5;
for(i=1; i<=5; i++)
{
for(j=1; j<a; j++)
printf(" ");
a--;
{
for(j=1; j<=i; j++)
{
printf("*");
}
printf("\n");
}
}
return 0;
}
|
the_stack_data/79559.c | #include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#define NUM 1000
struct mystruct {
pthread_mutex_t mylock;
pthread_cond_t read_ok;
pthread_cond_t write_ok;
int r_pend,r_count;
int w_pend,w_count;
};
struct foo_struct
{
struct mystruct *lock_ptr;
int *data;
};
void rwlock_init(struct mystruct *lock)
{
pthread_cond_init(&(lock->write_ok),NULL);
pthread_cond_init(&(lock->read_ok),NULL);
pthread_mutex_init(&(lock->mylock),NULL);
lock->r_pend = 0;
lock->r_count = 0;
lock->w_pend = 0;
lock->w_count = 0;
}
void readlock(struct mystruct *lock)
{
pthread_mutex_lock(&(lock->mylock));
(lock->r_pend)++;
while(lock->w_count>0 || lock->w_pend>0)
pthread_cond_wait(&(lock->read_ok),&(lock->mylock));
(lock->r_pend)--;(lock->r_count)++;
pthread_mutex_unlock(&(lock->mylock));
}
void writelock(struct mystruct *lock)
{
pthread_mutex_lock(&(lock->mylock));
(lock->w_pend)++;
while(lock->w_count>0 || lock->r_count>0)
pthread_cond_wait(&(lock->write_ok),&(lock->mylock));
(lock->w_pend)--;
(lock->w_count)++;
pthread_mutex_unlock(&(lock->mylock));
}
void unlock(struct mystruct *lock)
{
pthread_mutex_lock(&(lock->mylock));
if(lock->w_count>0)lock->w_count=0;
else if(lock->r_count>0) (lock->r_count)--;
pthread_mutex_unlock(&(lock->mylock));
if(lock->r_count==0 && lock->w_pend>0)
pthread_cond_signal(&(lock->write_ok));
else if(lock->w_count==0 && lock->r_pend>0)
pthread_cond_signal(&(lock->read_ok));
}
struct node { int d; struct node *n; } *list;
void insert(int d)
{
struct node *x = (struct node *)malloc(sizeof(struct node));
x->d = d; x->n = list; list = x;
}
struct node* search(int d)
{
struct node *nd;
for(nd = list; (nd != NULL)&&(nd->d != d); nd = nd->n);
return nd;
}
void *foo(void *x)
{
int id = *(( ((struct foo_struct *) x)->data));
int i, j = -1;
for(i = 0; i < 10*NUM; i++)
if(i%10 == 0)
{
writelock( (( ((struct foo_struct *) x)->lock_ptr)) );
j++; insert (1000*id+j);
unlock( (( ((struct foo_struct *) x)->lock_ptr)) );
}
else
{
readlock((( ((struct foo_struct *) x)->lock_ptr)));
search (1000*id+j);
unlock( (( ((struct foo_struct *) x)->lock_ptr)) );
}
pthread_exit(NULL);
}
int main()
{
list = NULL;
struct mystruct *lock = (struct mystruct *)malloc(sizeof(struct mystruct));
rwlock_init(lock);
int i, a[5];
pthread_t t[5];
struct foo_struct foo_s[5];
for(i = 0; i < 5; i++) {
foo_s[i].lock_ptr = lock;
a[i] = i;
foo_s[i].data = &a[i];
pthread_create(&t[i],NULL,foo,&foo_s[i]);}
for(i = 0; i < 5; i++) pthread_join(t[i],NULL);
int count = 0;
for(struct node *nd = list; nd != NULL; nd = nd->n) { printf("%d, ",nd->d); count++;}
puts("");
if(count == 5*NUM) printf("OK\n"); else printf("ERROR\n");
}
|
the_stack_data/97012898.c | // https://www.urionlinejudge.com.br/judge/en/runs/add/1017
#include <stdio.h>
int main()
{
int hours, average_speed;
scanf("%d", &hours);
scanf("%d", &average_speed);
float liters_per_km = 12;
float liters = (hours * average_speed) / liters_per_km;
printf("%.3f\n", liters);
return 0;
}
|
the_stack_data/6318.c | //
// file: main.c
// author: Michael Brockus
// gmail: <[email protected]>
//
#include <assert.h>
#include <limits.h>
#include <math.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char* readline();
char** split_string(char*);
//
// Complete the simpleArraySum function below.
//
int simpleArraySum(int ar_count, int* ar) {
int sum = 0;
for (int index = 0; index < ar_count; ++index)
{
sum += *(ar + index);
} // end for
return sum;
} // end of function simpleArraySum
// main is where program execution starts
int main(void)
{
FILE* fptr = fopen(getenv("OUTPUT_PATH"), "w");
char* ar_count_endptr;
char* ar_count_str = readline();
int ar_count = strtol(ar_count_str, &ar_count_endptr, 10);
if (ar_count_endptr == ar_count_str || *ar_count_endptr != '\0')
{
return EXIT_FAILURE;
} // end if
char** ar_temp = split_string(readline());
int ar[ar_count];
for (int ar_itr = 0; ar_itr < ar_count; ar_itr++) {
char* ar_item_endptr;
char* ar_item_str = ar_temp[ar_itr];
int ar_item = strtol(ar_item_str, &ar_item_endptr, 10);
if (ar_item_endptr == ar_item_str || *ar_item_endptr != '\0') { exit(EXIT_FAILURE); }
ar[ar_itr] = ar_item;
} // end for
int result = simpleArraySum(ar_count, ar);
fprintf(fptr, "%d\n", result);
fclose(fptr);
return EXIT_SUCCESS;
} // end of function main
//
// Utility from HackerRank
//
char* readline()
{
size_t alloc_length = 1024;
size_t data_length = 0;
char* data = malloc(alloc_length);
while (true)
{
char* cursor = data + data_length;
char* line = fgets(cursor, alloc_length - data_length, stdin);
if (!line) { break; }
data_length += strlen(cursor);
if (data_length < alloc_length - 1 || data[data_length - 1] == '\n') { break; }
size_t new_length = alloc_length << 1;
data = realloc(data, new_length);
if (!data) { break; }
alloc_length = new_length;
} // end while
if (data[data_length - 1] == '\n') {
data[data_length - 1] = '\0';
} // end if
data = realloc(data, data_length);
return data;
} // end of function readline
//
// Utility from HackerRank
//
char** split_string(char* str)
{
char** splits = NULL;
char* token = strtok(str, " ");
int spaces = 0;
while (token)
{
splits = realloc(splits, sizeof(char*) * ++spaces);
if (!splits)
{
return splits;
} // end if
splits[spaces - 1] = token;
token = strtok(NULL, " ");
} // end while
return splits;
} // end of function split_string
|
the_stack_data/3262608.c | #include <stdio.h>
#include <stdlib.h>
#define SIZE 1337
int main (void)
{
int *tab;
int i;
tab = malloc (SIZE * sizeof(int));
if ((tab == NULL))
{
perror ("malloc()");
exit (-1);
}
for (i = 0; i < SIZE; i++)
{
tab[i] = random();
}
printf("%i",*tab);
free(tab);
return 0;
}
|
the_stack_data/118922.c | #include <stdio.h>
void one_three(void);
void two(void);
int main(void)
{
printf("Starting now:\n");
one_three();
printf("done!\n");
return 0;
}
void one_three(void)
{
printf("one\n");
two();
printf("three\n");
}
void two(void)
{
printf("two\n");
}
|
the_stack_data/98397.c | #include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<signal.h>
#include<termios.h>
#define PASSWD_LEN 8
char *getpasswd(char *prompt) {
FILE *fp = NULL;
if (NULL == (fp = fopen(ctermid(NULL), "r+"))) {
perror("fopen");
exit(EXIT_FAILURE);
}
printf("%s\n", ctermid(NULL));
setvbuf(fp, (char *) NULL, _IONBF, 0);
sigset_t myset, setsave;
sigemptyset(&myset);
sigaddset(&myset, SIGINT);
sigaddset(&myset, SIGTSTP);
sigprocmask(SIG_BLOCK, &myset, &setsave);
struct termios termnew, termsave;
tcgetattr(fileno(fp), &termsave);
termnew = termsave;
termnew.c_lflag = termnew.c_lflag & ~(ECHO | ECHOCTL | ECHOE | ECHOK);
tcsetattr(fileno(fp), TCSAFLUSH, &termnew);
fputs(prompt, fp);
static char buf[PASSWD_LEN + 1];
int c;
char *ptr = buf;
while ((c = getc(fp)) != EOF && c != '\0' && c != '\n' && c != '\r') {
if (ptr < &buf[PASSWD_LEN]) {
*ptr++ = c;
}
fflush(fp);
}
*ptr = '\0';
putc('\n', fp);
tcsetattr(fileno(fp), TCSAFLUSH, &termsave);
sigprocmask(SIG_BLOCK, &setsave, NULL);
return buf;
}
int main(void) {
char *ptr = NULL;
ptr = getpasswd("#");
printf("%s\n", ptr);
}
|
the_stack_data/3263580.c | #include <stdlib.h>
#include <math.h>
int randRange(int min, int max) {
int size = (double) (rand() % (max-min) + min);
return size;
}
int randExp(int min, int max) {
double k = log(((double) max)/min);
double r = ((double) (rand() % (int)(k*10000))) / 10000;
int size = (int) ((double) max / exp(r));
return size;
}
|
the_stack_data/7090.c | #include <stdio.h>
enum zwierzak
{
pies,kot,chomik,zlota_rybka,papuga
};
int main()
{
enum zwierzak cos=zlota_rybka;
switch(cos)
{
case pies:
printf("pies\n");
break;
case kot:
printf("kot\n");
break;
case papuga:
printf("papuga\n");
break;
default:
printf("cos innego\n");
break;
}
return 0;
}
|
the_stack_data/157426.c | /*
* libusb synchronization using POSIX Threads
*
* Copyright (C) 2011 Vitali Lovich <[email protected]>
* Copyright (C) 2011 Peter Stuge <[email protected]>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifdef _XOPEN_SOURCE
# if _XOPEN_SOURCE < 500
# undef _XOPEN_SOURCE
# define _XOPEN_SOURCE 500
# endif
#else
#define _XOPEN_SOURCE 500
#endif /* _XOPEN_SOURCE */
#include <pthread.h>
int usbi_mutex_init_recursive(pthread_mutex_t *mutex, pthread_mutexattr_t *attr)
{
int err;
pthread_mutexattr_t stack_attr;
if (!attr) {
attr = &stack_attr;
err = pthread_mutexattr_init(&stack_attr);
if (err != 0)
return err;
}
err = pthread_mutexattr_settype(attr, PTHREAD_MUTEX_RECURSIVE);
if (err != 0)
goto finish;
err = pthread_mutex_init(mutex, attr);
finish:
if (attr == &stack_attr)
pthread_mutexattr_destroy(&stack_attr);
return err;
}
|
the_stack_data/9511632.c | /*
* The Initial Developer of the Original Code is International
* Business Machines Corporation. Portions created by IBM
* Corporation are Copyright (C) 2005, 2006 International Business
* Machines Corporation. All Rights Reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the Common Public License as published by
* IBM Corporation; either version 1 of the License, or (at your option)
* any later version.
*
* This 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
* Common Public License for more details.
*
* You should have received a copy of the Common Public License
* along with this program; if not, a copy can be viewed at
* http://www.opensource.org/licenses/cpl1.0.php.
*/
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <netinet/in.h>
int main() {
char startup[] = {
0, 193, /* TPM_TAG_RQU_COMMAND */
0, 0, 0, 12, /* length */
0, 0, 0, 153, /* TPM_ORD_Startup */
0, 1 /* ST_CLEAR */
};
char selftest[] = {
0, 193, /* TPM_TAG_RQU_COMMAND */
0, 0, 0, 10, /* length */
0, 0, 0, 80 /* TPM_ORD_SelfTestFull */
};
int fd;
int err;
int rc = 1;
fd = open( "/dev/tpm0", O_RDWR );
if ( fd < 0 ) {
printf( "Unable to open the device.\n" );
goto out_noclose;
}
err = write( fd, startup, sizeof(startup) );
if ( err != sizeof( startup ) ){
printf( "Error occured while writing the startup command: %d\n", errno );
goto out;
}
err = read( fd, startup, sizeof(startup) );
if ( err != 10 ) {
printf( "Error occured while reading the startup result: %d %d %s\n", err, errno, strerror(errno));
goto out;
}
err = ntohl( *((uint32_t *)(startup+6)) );
if ( err == 38 ) {
printf( "TPM already started.\n" );
goto out;
}
if ( err != 0 ) {
printf( "TPM Error occured: %d\n", err );
goto out;
}
rc = 0;
printf( "Startup successful\n" );
out:
err = write( fd, selftest, sizeof(selftest) );
if ( err != sizeof( selftest ) ){
printf( "Error occured while writing the selftest command: %d\n", errno );
goto out;
}
err = read( fd, selftest, sizeof(selftest) );
if ( err != 10 ) {
printf( "Error occured while reading the selftest result: %d %d %s\n", err, errno, strerror(errno));
goto out;
}
err = ntohl( *((uint32_t *)(selftest+6)) );
if ( err != 0 ) {
printf( "TPM Error occured: %d\n", err );
goto out;
} else {
rc = 0;
printf( "Selftest successful\n" );
}
close(fd);
out_noclose:
return rc;
}
|
the_stack_data/42086.c | /* The Pythagoras' theorem states the relation among the three sides of
* a right-angled triangle, where the sum of the areas of the two
* squares on the sides (a, b) equals the area of the square on the
* hypotenuse (c), and it can be represented with the equation
* a^2 + b^2 = c^2
*
* This program uses two threads; each one to calculate the areas of the
* two squares on the sides. Initially, the hypotenuse value is set to
* zero. When one thread has made its calculation, it sums it to the
* hypotenuse, therefore it has to be treated as a critical section.
* It uses mutex to protect the shared data. To compile it may be
* necessary to add the option -lm to link the math.h library.
*
* Compilation
* gcc -lm -Wall -lpthread -o pythagoras pythagoras.c
*
* Execution
* ./pythagoras <side_a> <side_b>
*
*
* File: pythagoras.c Author: Manases Galindo
* Date: 09.02.2017
*/
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <math.h>
#define NUM_THREADS 2 /* default number of threads */
/* Shared global variables. All threads can access them. */
float hypotenuse;
pthread_mutex_t mutexsum;
void *square_side (void *);
int main (int argc, char **argv)
{
int i; /* loop variable */
float sides[2]; /* right-angled triangle sides */
pthread_t *thr_ids; /* array of thread ids */
switch (argc) /* check command line arguments */
{
case 3:
/* Get the values of the right-angled triangle sides */
sides[0] = atof (argv[1]);
sides[1] = atof (argv[2]);
if ((sides[0] < 1) || (sides[1] < 1))
{
fprintf (stderr, "Error: wrong values for triangle sides.\n"
"Usage:\n"
" %s <side_a> <side_b>\n"
"values of sizes should be > 0\n",
argv[0]);
exit (EXIT_FAILURE);
}
break;
default:
fprintf (stderr, "Error: wrong number of parameters.\n"
"Usage:\n"
" %s <side_a> <side_b>\n",
argv[0]);
exit (EXIT_FAILURE);
}
/* allocate memory for all dynamic data structures */
thr_ids = (pthread_t *) malloc (NUM_THREADS * sizeof (pthread_t));
/* Validate that memory was successfully allocated */
if (thr_ids == NULL)
{
fprintf (stderr, "File: %s, line %d: Can't allocate memory.",
__FILE__, __LINE__);
exit (EXIT_FAILURE);
}
printf ("\nPythagoras' theorem | a^2 + b^2 = c^2 \n");
hypotenuse = 0;
/* Initialize the mutex to protect share data (hypotenuse) */
pthread_mutex_init (&mutexsum, NULL);
/* Create the threads and calculate the squares on the sides */
pthread_create (&thr_ids[0], NULL, square_side, &sides[0]);
pthread_create (&thr_ids[1], NULL, square_side, &sides[1]);
/* Using join to syncronize the threads */
for (i = 0; i < NUM_THREADS; i++)
{
pthread_join (thr_ids[i], NULL);
}
printf ("Hypotenuse is %.2f\n", sqrt(hypotenuse));
/* Deallocate any memory or resources associated */
pthread_mutex_destroy (&mutexsum);
free (thr_ids);
return EXIT_SUCCESS;
}
/* square_side runs as a thread and calculates the areas of the
* square on the side, then sums the value to the hypotenuse.
* It uses a mutex to protect the hypotenuse and avoid a race
* conditiong within the threads.
*
* Input: arg pointer to triangle side value
* Return value: none
*
*/
void *square_side (void *arg)
{
float side;
/* Get the value of the triangle side and print the square */
side = *( ( float* )arg );
printf ("%.2f^2 = %.2f\n", side, side * side);
/* Mutex lock/unlock to safely update the value of hypotenuse */
pthread_mutex_lock (&mutexsum);
hypotenuse += side * side;
pthread_mutex_unlock (&mutexsum);
pthread_exit (EXIT_SUCCESS); /* Terminate the thread */
}
|
the_stack_data/899463.c |
void not_linearized_array_indices(int n, float fx[n], float pot[n])
{
for(int i = 0; i <= n; i += 1)
fx[i] = pot[((i+1)&128)-1]/(2.*(float) 6.f/128);
}
|
the_stack_data/64448.c | /**
******************************************************************************
* @file stm32wlxx_ll_pka.c
* @author MCD Application Team
* @brief PKA LL module driver.
******************************************************************************
* @attention
*
* <h2><center>© Copyright (c) 2019 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
******************************************************************************
*/
#if defined(USE_FULL_LL_DRIVER)
/* Includes ------------------------------------------------------------------*/
#include "stm32wlxx_ll_pka.h"
#include "stm32wlxx_ll_bus.h"
#ifdef USE_FULL_ASSERT
#include "stm32_assert.h"
#else
#define assert_param(expr) ((void)0U)
#endif
/** @addtogroup STM32WLxx_LL_Driver
* @{
*/
#if defined(PKA)
/** @addtogroup PKA_LL
* @{
*/
/* Private types -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private constants ---------------------------------------------------------*/
/* Private macros ------------------------------------------------------------*/
/** @defgroup PKA_LL_Private_Macros PKA Private Constants
* @{
*/
#define IS_LL_PKA_MODE(__VALUE__) (((__VALUE__) == LL_PKA_MODE_MONTGOMERY_PARAM_MOD_EXP) ||\
((__VALUE__) == LL_PKA_MODE_MONTGOMERY_PARAM) ||\
((__VALUE__) == LL_PKA_MODE_MODULAR_EXP) ||\
((__VALUE__) == LL_PKA_MODE_MONTGOMERY_PARAM_ECC) ||\
((__VALUE__) == LL_PKA_MODE_ECC_KP_PRIMITIVE) ||\
((__VALUE__) == LL_PKA_MODE_ECDSA_SIGNATURE) ||\
((__VALUE__) == LL_PKA_MODE_ECDSA_VERIFICATION) ||\
((__VALUE__) == LL_PKA_MODE_POINT_CHECK) ||\
((__VALUE__) == LL_PKA_MODE_RSA_CRT_EXP) ||\
((__VALUE__) == LL_PKA_MODE_MODULAR_INV) ||\
((__VALUE__) == LL_PKA_MODE_ARITHMETIC_ADD) ||\
((__VALUE__) == LL_PKA_MODE_ARITHMETIC_SUB) ||\
((__VALUE__) == LL_PKA_MODE_ARITHMETIC_MUL) ||\
((__VALUE__) == LL_PKA_MODE_COMPARISON) ||\
((__VALUE__) == LL_PKA_MODE_MODULAR_REDUC) ||\
((__VALUE__) == LL_PKA_MODE_MODULAR_ADD) ||\
((__VALUE__) == LL_PKA_MODE_MODULAR_SUB) ||\
((__VALUE__) == LL_PKA_MODE_MONTGOMERY_MUL))
/**
* @}
*/
/* Private function prototypes -----------------------------------------------*/
/* Exported functions --------------------------------------------------------*/
/** @addtogroup PKA_LL_Exported_Functions
* @{
*/
/** @addtogroup PKA_LL_EF_Init
* @{
*/
/**
* @brief De-initialize PKA registers (Registers restored to their default values).
* @param PKAx PKA Instance.
* @retval ErrorStatus
* - SUCCESS: PKA registers are de-initialized
* - ERROR: PKA registers are not de-initialized
*/
ErrorStatus LL_PKA_DeInit(PKA_TypeDef *PKAx)
{
ErrorStatus status = SUCCESS;
/* Check the parameters */
assert_param(IS_PKA_ALL_INSTANCE(PKAx));
if (PKAx == PKA)
{
/* Force PKA reset */
LL_AHB3_GRP1_ForceReset(LL_AHB3_GRP1_PERIPH_PKA);
/* Release PKA reset */
LL_AHB3_GRP1_ReleaseReset(LL_AHB3_GRP1_PERIPH_PKA);
}
else
{
status = ERROR;
}
return (status);
}
/**
* @brief Initialize PKA registers according to the specified parameters in PKA_InitStruct.
* @param PKAx PKA Instance.
* @param PKA_InitStruct pointer to a @ref LL_PKA_InitTypeDef structure
* that contains the configuration information for the specified PKA peripheral.
* @retval ErrorStatus
* - SUCCESS: PKA registers are initialized according to PKA_InitStruct content
* - ERROR: Not applicable
*/
ErrorStatus LL_PKA_Init(PKA_TypeDef *PKAx, LL_PKA_InitTypeDef *PKA_InitStruct)
{
assert_param(IS_PKA_ALL_INSTANCE(PKAx));
assert_param(IS_LL_PKA_MODE(PKA_InitStruct->Mode));
LL_PKA_Config(PKAx, PKA_InitStruct->Mode);
return (SUCCESS);
}
/**
* @brief Set each @ref LL_PKA_InitTypeDef field to default value.
* @param PKA_InitStruct pointer to a @ref LL_PKA_InitTypeDef structure
* whose fields will be set to default values.
* @retval None
*/
void LL_PKA_StructInit(LL_PKA_InitTypeDef *PKA_InitStruct)
{
/* Reset PKA init structure parameters values */
PKA_InitStruct->Mode = LL_PKA_MODE_MONTGOMERY_PARAM_MOD_EXP;
}
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
#endif /* defined (PKA) */
/**
* @}
*/
#endif /* USE_FULL_LL_DRIVER */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
the_stack_data/70449621.c | #ifdef __ARM_EABI__
#include <math.h>
#include "ibm.h"
#include "x86.h"
#include "x87.h"
#include "386_common.h"
#include "codegen.h"
#include "codegen_allocator.h"
#include "codegen_backend.h"
#include "codegen_backend_arm_defs.h"
#include "codegen_backend_arm_ops.h"
#include "codegen_ir_defs.h"
static inline int get_arm_imm(uint32_t imm_data, uint32_t *arm_imm)
{
int shift = 0;
//pclog("get_arm_imm - imm_data=%08x\n", imm_data);
if (!(imm_data & 0xffff))
{
shift += 16;
imm_data >>= 16;
}
if (!(imm_data & 0xff))
{
shift += 8;
imm_data >>= 8;
}
if (!(imm_data & 0xf))
{
shift += 4;
imm_data >>= 4;
}
if (!(imm_data & 0x3))
{
shift += 2;
imm_data >>= 2;
}
if (imm_data > 0xff) /*Note - should handle rotation round the word*/
return 0;
//pclog(" imm_data=%02x shift=%i\n", imm_data, shift);
*arm_imm = imm_data | ((((32 - shift) >> 1) & 15) << 8);
return 1;
}
static inline int in_range(void *addr, void *base)
{
int diff = (uintptr_t)addr - (uintptr_t)base;
if (diff < -4095 || diff > 4095)
return 0;
return 1;
}
static inline int in_range_h(void *addr, void *base)
{
int diff = (uintptr_t)addr - (uintptr_t)base;
if (diff < 0 || diff > 255)
return 0;
return 1;
}
void host_arm_call(codeblock_t *block, void *dst_addr)
{
host_arm_MOV_IMM(block, REG_R3, (uintptr_t)dst_addr);
host_arm_BLX(block, REG_R3);
}
void host_arm_nop(codeblock_t *block)
{
host_arm_MOV_REG_LSL(block, REG_R0, REG_R0, 0);
}
#define HOST_REG_GET(reg) (IREG_GET_REG(reg) & 0xf)
#define REG_IS_L(size) (size == IREG_SIZE_L)
#define REG_IS_W(size) (size == IREG_SIZE_W)
#define REG_IS_B(size) (size == IREG_SIZE_B)
#define REG_IS_BH(size) (size == IREG_SIZE_BH)
#define REG_IS_D(size) (size == IREG_SIZE_D)
#define REG_IS_Q(size) (size == IREG_SIZE_Q)
static int codegen_ADD(codeblock_t *block, uop_t *uop)
{
int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_a = HOST_REG_GET(uop->src_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real);
int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_a = IREG_GET_SIZE(uop->src_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real);
if (REG_IS_L(dest_size) && REG_IS_L(src_size_a) && REG_IS_L(src_size_b))
{
host_arm_ADD_REG_LSL(block, dest_reg, src_reg_a, src_reg_b, 0);
}
else if (REG_IS_W(dest_size) && REG_IS_W(src_size_a) && REG_IS_W(src_size_b))
{
host_arm_ADD_REG(block, REG_TEMP, src_reg_a, src_reg_b);
host_arm_BFI(block, dest_reg, REG_TEMP, 0, 16);
}
else if (REG_IS_B(dest_size) && REG_IS_B(src_size_a) && REG_IS_B(src_size_b))
{
host_arm_ADD_REG(block, REG_TEMP, src_reg_a, src_reg_b);
host_arm_BFI(block, dest_reg, REG_TEMP, 0, 8);
}
else if (REG_IS_B(dest_size) && REG_IS_B(src_size_a) && REG_IS_BH(src_size_b) && dest_reg == src_reg_a)
{
host_arm_UXTB(block, REG_TEMP, src_reg_b, 8);
host_arm_UADD8(block, dest_reg, src_reg_a, REG_TEMP);
}
else if (REG_IS_B(dest_size) && REG_IS_B(src_size_a) && REG_IS_BH(src_size_b))
{
host_arm_ADD_REG_LSR(block, REG_TEMP, src_reg_a, src_reg_b, 8);
host_arm_BFI(block, dest_reg, REG_TEMP, 8, 8);
}
else if (REG_IS_BH(dest_size) && REG_IS_BH(src_size_a) && REG_IS_B(src_size_b) && dest_reg == src_reg_a)
{
host_arm_UXTB(block, REG_TEMP, src_reg_b, 0);
host_arm_MOV_REG_LSL(block, REG_TEMP, REG_TEMP, 8);
host_arm_UADD8(block, dest_reg, src_reg_a, REG_TEMP);
}
else if (REG_IS_BH(dest_size) && REG_IS_BH(src_size_a) && REG_IS_BH(src_size_b) && dest_reg == src_reg_a)
{
host_arm_AND_IMM(block, REG_TEMP, src_reg_b, 0x0000ff00);
host_arm_UADD8(block, dest_reg, src_reg_a, REG_TEMP);
}
else
fatal("ADD %02x %02x %02x\n", uop->dest_reg_a_real, uop->src_reg_a_real, uop->src_reg_b_real);
return 0;
}
static int codegen_ADD_IMM(codeblock_t *block, uop_t *uop)
{
// host_arm_ADD_IMM(block, uop->dest_reg_a_real, uop->src_reg_a_real, uop->imm_data);
// return 0;
int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg = HOST_REG_GET(uop->src_reg_a_real);
int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size = IREG_GET_SIZE(uop->src_reg_a_real);
if (REG_IS_L(dest_size) && REG_IS_L(src_size))
{
host_arm_ADD_IMM(block, dest_reg, src_reg, uop->imm_data);
}
else if (REG_IS_W(dest_size) && REG_IS_W(src_size))
{
host_arm_ADD_IMM(block, REG_TEMP, src_reg, uop->imm_data);
host_arm_BFI(block, dest_reg, REG_TEMP, 0, 16);
}
else if (REG_IS_B(dest_size) && REG_IS_B(src_size))
{
host_arm_ADD_IMM(block, REG_TEMP, src_reg, uop->imm_data);
host_arm_BFI(block, dest_reg, REG_TEMP, 0, 8);
}
else if (REG_IS_BH(dest_size) && REG_IS_BH(src_size) && src_reg == dest_reg)
{
host_arm_MOV_IMM(block, REG_TEMP, uop->imm_data << 8);
host_arm_UADD8(block, dest_reg, src_reg, REG_TEMP);
}
else
fatal("ADD_IMM %02x %02x\n", uop->dest_reg_a_real, uop->src_reg_a_real);
return 0;
}
static int codegen_ADD_LSHIFT(codeblock_t *block, uop_t *uop)
{
host_arm_ADD_REG_LSL(block, uop->dest_reg_a_real, uop->src_reg_a_real, uop->src_reg_b_real, uop->imm_data);
return 0;
}
static int codegen_AND(codeblock_t *block, uop_t *uop)
{
int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_a = HOST_REG_GET(uop->src_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real);
int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_a = IREG_GET_SIZE(uop->src_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real);
if (REG_IS_Q(dest_size) && REG_IS_Q(src_size_a) && REG_IS_Q(src_size_b))
{
host_arm_VAND_D(block, dest_reg, src_reg_a, src_reg_b);
}
else if (REG_IS_L(dest_size) && REG_IS_L(src_size_a) && REG_IS_L(src_size_b))
{
host_arm_AND_REG_LSL(block, dest_reg, src_reg_a, src_reg_b, 0);
}
else if (REG_IS_W(dest_size) && REG_IS_W(src_size_a) && REG_IS_W(src_size_b) && dest_reg == src_reg_a)
{
host_arm_MVN_REG_LSL(block, REG_TEMP, src_reg_b, 16);
host_arm_BIC_REG_LSR(block, dest_reg, src_reg_a, REG_TEMP, 16);
}
else if (REG_IS_B(dest_size) && REG_IS_B(src_size_a) && REG_IS_B(src_size_b) && dest_reg == src_reg_a)
{
host_arm_MVN_REG_LSL(block, REG_TEMP, src_reg_b, 24);
host_arm_BIC_REG_LSR(block, dest_reg, src_reg_a, REG_TEMP, 24);
}
else if (REG_IS_B(dest_size) && REG_IS_B(src_size_a) && REG_IS_BH(src_size_b) && dest_reg == src_reg_a)
{
host_arm_MVN_REG_LSL(block, REG_TEMP, src_reg_b, 16);
host_arm_BIC_REG_LSR(block, dest_reg, src_reg_a, REG_TEMP, 24);
}
else if (REG_IS_BH(dest_size) && REG_IS_BH(src_size_a) && REG_IS_B(src_size_b) && dest_reg == src_reg_a)
{
host_arm_MVN_REG_LSL(block, REG_TEMP, src_reg_b, 8);
host_arm_AND_IMM(block, REG_TEMP, REG_TEMP, 0x0000ff00);
host_arm_BIC_REG_LSL(block, dest_reg, src_reg_a, REG_TEMP, 0);
}
else if (REG_IS_BH(dest_size) && REG_IS_BH(src_size_a) && REG_IS_BH(src_size_b) && dest_reg == src_reg_a)
{
host_arm_MVN_REG_LSL(block, REG_TEMP, src_reg_b, 0);
host_arm_AND_IMM(block, REG_TEMP, REG_TEMP, 0x0000ff00);
host_arm_BIC_REG_LSL(block, dest_reg, src_reg_a, REG_TEMP, 0);
}
else if (REG_IS_W(dest_size) && REG_IS_W(src_size_a) && REG_IS_W(src_size_b))
{
host_arm_AND_REG_LSL(block, REG_TEMP, src_reg_a, src_reg_b, 0);
host_arm_BFI(block, dest_reg, REG_TEMP, 0, 16);
}
else if (REG_IS_B(dest_size) && REG_IS_B(src_size_a) && REG_IS_B(src_size_b))
{
host_arm_AND_REG_LSL(block, REG_TEMP, src_reg_a, src_reg_b, 0);
host_arm_BFI(block, dest_reg, REG_TEMP, 0, 8);
}
else if (REG_IS_B(dest_size) && REG_IS_B(src_size_a) && REG_IS_BH(src_size_b))
{
host_arm_AND_REG_LSR(block, REG_TEMP, src_reg_a, src_reg_b, 8);
host_arm_BFI(block, dest_reg, REG_TEMP, 0, 8);
}
else if (REG_IS_B(dest_size) && REG_IS_BH(src_size_a) && REG_IS_B(src_size_b))
{
host_arm_AND_REG_LSR(block, REG_TEMP, src_reg_b, src_reg_a, 8);
host_arm_BFI(block, dest_reg, REG_TEMP, 0, 8);
}
else if (REG_IS_B(dest_size) && REG_IS_BH(src_size_a) && REG_IS_BH(src_size_b))
{
host_arm_AND_REG_LSL(block, REG_TEMP, src_reg_a, src_reg_b, 0);
host_arm_MOV_REG_LSR(block, REG_TEMP, REG_TEMP, 8);
host_arm_BFI(block, dest_reg, REG_TEMP, 0, 8);
}
else
fatal("AND %02x %02x %02x\n", uop->dest_reg_a_real, uop->src_reg_a_real, uop->src_reg_b_real);
return 0;
}
static int codegen_AND_IMM(codeblock_t *block, uop_t *uop)
{
int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg = HOST_REG_GET(uop->src_reg_a_real);
int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size = IREG_GET_SIZE(uop->src_reg_a_real);
if (REG_IS_L(dest_size) && REG_IS_L(src_size))
{
host_arm_AND_IMM(block, dest_reg, src_reg, uop->imm_data);
}
else if (REG_IS_W(dest_size) && REG_IS_W(src_size) && dest_reg == src_reg)
{
host_arm_AND_IMM(block, dest_reg, src_reg, uop->imm_data | 0xffff0000);
}
else if (REG_IS_B(dest_size) && REG_IS_B(src_size) && dest_reg == src_reg)
{
host_arm_AND_IMM(block, dest_reg, src_reg, uop->imm_data | 0xffffff00);
}
else if (REG_IS_BH(dest_size) && REG_IS_BH(src_size) && dest_reg == src_reg)
{
host_arm_AND_IMM(block, dest_reg, src_reg, (uop->imm_data << 8) | 0xffff00ff);
}
else if (REG_IS_W(dest_size) && REG_IS_W(src_size))
{
host_arm_AND_IMM(block, REG_TEMP, src_reg, uop->imm_data);
host_arm_BFI(block, dest_reg, REG_TEMP, 0, 16);
}
else if (REG_IS_B(dest_size) && REG_IS_B(src_size))
{
host_arm_AND_IMM(block, REG_TEMP, src_reg, uop->imm_data);
host_arm_BFI(block, dest_reg, REG_TEMP, 0, 8);
}
else if (REG_IS_B(dest_size) && REG_IS_BH(src_size))
{
host_arm_MOV_REG_LSR(block, REG_TEMP, src_reg, 8);
host_arm_AND_IMM(block, REG_TEMP, REG_TEMP, uop->imm_data);
host_arm_BFI(block, dest_reg, REG_TEMP, 0, 8);
}
else
fatal("AND_IMM %02x %02x\n", uop->dest_reg_a_real, uop->src_reg_a_real);
return 0;
}
static int codegen_ANDN(codeblock_t *block, uop_t *uop)
{
int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_a = HOST_REG_GET(uop->src_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real);
int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_a = IREG_GET_SIZE(uop->src_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real);
if (REG_IS_Q(dest_size) && REG_IS_Q(src_size_a) && REG_IS_Q(src_size_b))
{
host_arm_VBIC_D(block, dest_reg, src_reg_b, src_reg_a);
}
else
fatal("ANDN %02x %02x %02x\n", uop->dest_reg_a_real, uop->src_reg_a_real, uop->src_reg_b_real);
return 0;
}
static int codegen_CALL_FUNC(codeblock_t *block, uop_t *uop)
{
host_arm_call(block, uop->p);
return 0;
}
static int codegen_CALL_FUNC_RESULT(codeblock_t *block, uop_t *uop)
{
int dest_reg = HOST_REG_GET(uop->dest_reg_a_real);
int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real);
if (!REG_IS_L(dest_size))
fatal("CALL_FUNC_RESULT %02x\n", uop->dest_reg_a_real);
host_arm_call(block, uop->p);
host_arm_MOV_REG(block, dest_reg, REG_R0);
return 0;
}
static int codegen_CALL_INSTRUCTION_FUNC(codeblock_t *block, uop_t *uop)
{
host_arm_call(block, uop->p);
host_arm_TST_REG(block, REG_R0, REG_R0);
host_arm_BNE(block, (uintptr_t)codegen_exit_rout);
return 0;
}
static int codegen_CMP_IMM_JZ(codeblock_t *block, uop_t *uop)
{
int src_reg = HOST_REG_GET(uop->src_reg_a_real);
int src_size = IREG_GET_SIZE(uop->src_reg_a_real);
if (REG_IS_L(src_size))
{
host_arm_CMP_IMM(block, src_reg, uop->imm_data);
}
else
fatal("CMP_IMM_JZ %02x\n", uop->src_reg_a_real);
host_arm_BEQ(block, (uintptr_t)uop->p);
return 0;
}
static int codegen_CMP_IMM_JNZ_DEST(codeblock_t *block, uop_t *uop)
{
int src_reg = HOST_REG_GET(uop->src_reg_a_real);
int src_size = IREG_GET_SIZE(uop->src_reg_a_real);
if (REG_IS_L(src_size))
{
host_arm_CMP_IMM(block, src_reg, uop->imm_data);
}
else if (REG_IS_W(src_size))
{
host_arm_UXTH(block, REG_TEMP, src_reg, 0);
host_arm_CMP_IMM(block, REG_TEMP, uop->imm_data);
}
else
fatal("CMP_IMM_JNZ_DEST %02x\n", uop->src_reg_a_real);
uop->p = host_arm_BNE_(block);
return 0;
}
static int codegen_CMP_IMM_JZ_DEST(codeblock_t *block, uop_t *uop)
{
int src_reg = HOST_REG_GET(uop->src_reg_a_real);
int src_size = IREG_GET_SIZE(uop->src_reg_a_real);
if (REG_IS_L(src_size))
{
host_arm_CMP_IMM(block, src_reg, uop->imm_data);
}
else if (REG_IS_W(src_size))
{
host_arm_UXTH(block, REG_TEMP, src_reg, 0);
host_arm_CMP_IMM(block, REG_TEMP, uop->imm_data);
}
else
fatal("CMP_IMM_JZ_DEST %02x\n", uop->src_reg_a_real);
uop->p = host_arm_BEQ_(block);
return 0;
}
static int codegen_CMP_JB(codeblock_t *block, uop_t *uop)
{
int src_reg_a = HOST_REG_GET(uop->src_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real);
int src_size_a = IREG_GET_SIZE(uop->src_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real);
uint32_t *jump_p;
if (REG_IS_L(src_size_a) && REG_IS_L(src_size_b))
{
host_arm_CMP_REG(block, src_reg_a, src_reg_b);
}
else
fatal("CMP_JB %02x\n", uop->src_reg_a_real);
jump_p = host_arm_BCC_(block);
*jump_p |= ((((uintptr_t)uop->p - (uintptr_t)jump_p) - 8) & 0x3fffffc) >> 2;
return 0;
}
static int codegen_CMP_JNBE(codeblock_t *block, uop_t *uop)
{
int src_reg_a = HOST_REG_GET(uop->src_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real);
int src_size_a = IREG_GET_SIZE(uop->src_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real);
uint32_t *jump_p;
if (REG_IS_L(src_size_a) && REG_IS_L(src_size_b))
{
host_arm_CMP_REG(block, src_reg_a, src_reg_b);
}
else
fatal("CMP_JNBE %02x\n", uop->src_reg_a_real);
jump_p = host_arm_BHI_(block);
*jump_p |= ((((uintptr_t)uop->p - (uintptr_t)jump_p) - 8) & 0x3fffffc) >> 2;
return 0;
}
static int codegen_CMP_JNB_DEST(codeblock_t *block, uop_t *uop)
{
int src_reg_a = HOST_REG_GET(uop->src_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real);
int src_size_a = IREG_GET_SIZE(uop->src_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real);
if (REG_IS_L(src_size_a) && REG_IS_L(src_size_b))
{
host_arm_CMP_REG(block, src_reg_a, src_reg_b);
}
else if (REG_IS_W(src_size_a) && REG_IS_W(src_size_b))
{
host_arm_MOV_REG_LSL(block, REG_TEMP, src_reg_a, 16);
host_arm_CMP_REG_LSL(block, REG_TEMP, src_reg_b, 16);
}
else if (REG_IS_B(src_size_a) && REG_IS_B(src_size_b))
{
host_arm_MOV_REG_LSL(block, REG_TEMP, src_reg_a, 24);
host_arm_CMP_REG_LSL(block, REG_TEMP, src_reg_b, 24);
}
else
fatal("CMP_JNB_DEST %02x\n", uop->src_reg_a_real);
uop->p = host_arm_BCS_(block);
return 0;
}
static int codegen_CMP_JNBE_DEST(codeblock_t *block, uop_t *uop)
{
int src_reg_a = HOST_REG_GET(uop->src_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real);
int src_size_a = IREG_GET_SIZE(uop->src_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real);
if (REG_IS_L(src_size_a) && REG_IS_L(src_size_b))
{
host_arm_CMP_REG(block, src_reg_a, src_reg_b);
}
else if (REG_IS_W(src_size_a) && REG_IS_W(src_size_b))
{
host_arm_MOV_REG_LSL(block, REG_TEMP, src_reg_a, 16);
host_arm_CMP_REG_LSL(block, REG_TEMP, src_reg_b, 16);
}
else if (REG_IS_B(src_size_a) && REG_IS_B(src_size_b))
{
host_arm_MOV_REG_LSL(block, REG_TEMP, src_reg_a, 24);
host_arm_CMP_REG_LSL(block, REG_TEMP, src_reg_b, 24);
}
else
fatal("CMP_JNBE_DEST %02x\n", uop->src_reg_a_real);
uop->p = host_arm_BHI_(block);
return 0;
}
static int codegen_CMP_JNL_DEST(codeblock_t *block, uop_t *uop)
{
int src_reg_a = HOST_REG_GET(uop->src_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real);
int src_size_a = IREG_GET_SIZE(uop->src_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real);
if (REG_IS_L(src_size_a) && REG_IS_L(src_size_b))
{
host_arm_CMP_REG(block, src_reg_a, src_reg_b);
}
else if (REG_IS_W(src_size_a) && REG_IS_W(src_size_b))
{
host_arm_MOV_REG_LSL(block, REG_TEMP, src_reg_a, 16);
host_arm_CMP_REG_LSL(block, REG_TEMP, src_reg_b, 16);
}
else if (REG_IS_B(src_size_a) && REG_IS_B(src_size_b))
{
host_arm_MOV_REG_LSL(block, REG_TEMP, src_reg_a, 24);
host_arm_CMP_REG_LSL(block, REG_TEMP, src_reg_b, 24);
}
else
fatal("CMP_JNL_DEST %02x\n", uop->src_reg_a_real);
uop->p = host_arm_BGE_(block);
return 0;
}
static int codegen_CMP_JNLE_DEST(codeblock_t *block, uop_t *uop)
{
int src_reg_a = HOST_REG_GET(uop->src_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real);
int src_size_a = IREG_GET_SIZE(uop->src_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real);
if (REG_IS_L(src_size_a) && REG_IS_L(src_size_b))
{
host_arm_CMP_REG(block, src_reg_a, src_reg_b);
}
else if (REG_IS_W(src_size_a) && REG_IS_W(src_size_b))
{
host_arm_MOV_REG_LSL(block, REG_TEMP, src_reg_a, 16);
host_arm_CMP_REG_LSL(block, REG_TEMP, src_reg_b, 16);
}
else if (REG_IS_B(src_size_a) && REG_IS_B(src_size_b))
{
host_arm_MOV_REG_LSL(block, REG_TEMP, src_reg_a, 24);
host_arm_CMP_REG_LSL(block, REG_TEMP, src_reg_b, 24);
}
else
fatal("CMP_JNLE_DEST %02x\n", uop->src_reg_a_real);
uop->p = host_arm_BGT_(block);
return 0;
}
static int codegen_CMP_JNO_DEST(codeblock_t *block, uop_t *uop)
{
int src_reg_a = HOST_REG_GET(uop->src_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real);
int src_size_a = IREG_GET_SIZE(uop->src_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real);
if (REG_IS_L(src_size_a) && REG_IS_L(src_size_b))
{
host_arm_CMP_REG(block, src_reg_a, src_reg_b);
}
else if (REG_IS_W(src_size_a) && REG_IS_W(src_size_b))
{
host_arm_MOV_REG_LSL(block, REG_TEMP, src_reg_a, 16);
host_arm_CMP_REG_LSL(block, REG_TEMP, src_reg_b, 16);
}
else if (REG_IS_B(src_size_a) && REG_IS_B(src_size_b))
{
host_arm_MOV_REG_LSL(block, REG_TEMP, src_reg_a, 24);
host_arm_CMP_REG_LSL(block, REG_TEMP, src_reg_b, 24);
}
else
fatal("CMP_JNO_DEST %02x\n", uop->src_reg_a_real);
uop->p = host_arm_BVC_(block);
return 0;
}
static int codegen_CMP_JNZ_DEST(codeblock_t *block, uop_t *uop)
{
int src_reg_a = HOST_REG_GET(uop->src_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real);
int src_size_a = IREG_GET_SIZE(uop->src_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real);
if (REG_IS_L(src_size_a) && REG_IS_L(src_size_b))
{
host_arm_CMP_REG(block, src_reg_a, src_reg_b);
}
else if (REG_IS_W(src_size_a) && REG_IS_W(src_size_b))
{
host_arm_MOV_REG_LSL(block, REG_TEMP, src_reg_a, 16);
host_arm_CMP_REG_LSL(block, REG_TEMP, src_reg_b, 16);
}
else if (REG_IS_B(src_size_a) && REG_IS_B(src_size_b))
{
host_arm_MOV_REG_LSL(block, REG_TEMP, src_reg_a, 24);
host_arm_CMP_REG_LSL(block, REG_TEMP, src_reg_b, 24);
}
else
fatal("CMP_JNZ_DEST %02x\n", uop->src_reg_a_real);
uop->p = host_arm_BNE_(block);
return 0;
}
static int codegen_CMP_JB_DEST(codeblock_t *block, uop_t *uop)
{
int src_reg_a = HOST_REG_GET(uop->src_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real);
int src_size_a = IREG_GET_SIZE(uop->src_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real);
if (REG_IS_L(src_size_a) && REG_IS_L(src_size_b))
{
host_arm_CMP_REG(block, src_reg_a, src_reg_b);
}
else if (REG_IS_W(src_size_a) && REG_IS_W(src_size_b))
{
host_arm_MOV_REG_LSL(block, REG_TEMP, src_reg_a, 16);
host_arm_CMP_REG_LSL(block, REG_TEMP, src_reg_b, 16);
}
else if (REG_IS_B(src_size_a) && REG_IS_B(src_size_b))
{
host_arm_MOV_REG_LSL(block, REG_TEMP, src_reg_a, 24);
host_arm_CMP_REG_LSL(block, REG_TEMP, src_reg_b, 24);
}
else
fatal("CMP_JB_DEST %02x\n", uop->src_reg_a_real);
uop->p = host_arm_BCC_(block);
return 0;
}
static int codegen_CMP_JBE_DEST(codeblock_t *block, uop_t *uop)
{
int src_reg_a = HOST_REG_GET(uop->src_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real);
int src_size_a = IREG_GET_SIZE(uop->src_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real);
if (REG_IS_L(src_size_a) && REG_IS_L(src_size_b))
{
host_arm_CMP_REG(block, src_reg_a, src_reg_b);
}
else if (REG_IS_W(src_size_a) && REG_IS_W(src_size_b))
{
host_arm_MOV_REG_LSL(block, REG_TEMP, src_reg_a, 16);
host_arm_CMP_REG_LSL(block, REG_TEMP, src_reg_b, 16);
}
else if (REG_IS_B(src_size_a) && REG_IS_B(src_size_b))
{
host_arm_MOV_REG_LSL(block, REG_TEMP, src_reg_a, 24);
host_arm_CMP_REG_LSL(block, REG_TEMP, src_reg_b, 24);
}
else
fatal("CMP_JBE_DEST %02x\n", uop->src_reg_a_real);
uop->p = host_arm_BLS_(block);
return 0;
}
static int codegen_CMP_JL_DEST(codeblock_t *block, uop_t *uop)
{
int src_reg_a = HOST_REG_GET(uop->src_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real);
int src_size_a = IREG_GET_SIZE(uop->src_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real);
if (REG_IS_L(src_size_a) && REG_IS_L(src_size_b))
{
host_arm_CMP_REG(block, src_reg_a, src_reg_b);
}
else if (REG_IS_W(src_size_a) && REG_IS_W(src_size_b))
{
host_arm_MOV_REG_LSL(block, REG_TEMP, src_reg_a, 16);
host_arm_CMP_REG_LSL(block, REG_TEMP, src_reg_b, 16);
}
else if (REG_IS_B(src_size_a) && REG_IS_B(src_size_b))
{
host_arm_MOV_REG_LSL(block, REG_TEMP, src_reg_a, 24);
host_arm_CMP_REG_LSL(block, REG_TEMP, src_reg_b, 24);
}
else
fatal("CMP_JL_DEST %02x\n", uop->src_reg_a_real);
uop->p = host_arm_BLT_(block);
return 0;
}
static int codegen_CMP_JLE_DEST(codeblock_t *block, uop_t *uop)
{
int src_reg_a = HOST_REG_GET(uop->src_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real);
int src_size_a = IREG_GET_SIZE(uop->src_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real);
if (REG_IS_L(src_size_a) && REG_IS_L(src_size_b))
{
host_arm_CMP_REG(block, src_reg_a, src_reg_b);
}
else if (REG_IS_W(src_size_a) && REG_IS_W(src_size_b))
{
host_arm_MOV_REG_LSL(block, REG_TEMP, src_reg_a, 16);
host_arm_CMP_REG_LSL(block, REG_TEMP, src_reg_b, 16);
}
else if (REG_IS_B(src_size_a) && REG_IS_B(src_size_b))
{
host_arm_MOV_REG_LSL(block, REG_TEMP, src_reg_a, 24);
host_arm_CMP_REG_LSL(block, REG_TEMP, src_reg_b, 24);
}
else
fatal("CMP_JLE_DEST %02x\n", uop->src_reg_a_real);
uop->p = host_arm_BLE_(block);
return 0;
}
static int codegen_CMP_JO_DEST(codeblock_t *block, uop_t *uop)
{
int src_reg_a = HOST_REG_GET(uop->src_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real);
int src_size_a = IREG_GET_SIZE(uop->src_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real);
if (REG_IS_L(src_size_a) && REG_IS_L(src_size_b))
{
host_arm_CMP_REG(block, src_reg_a, src_reg_b);
}
else if (REG_IS_W(src_size_a) && REG_IS_W(src_size_b))
{
host_arm_MOV_REG_LSL(block, REG_TEMP, src_reg_a, 16);
host_arm_CMP_REG_LSL(block, REG_TEMP, src_reg_b, 16);
}
else if (REG_IS_B(src_size_a) && REG_IS_B(src_size_b))
{
host_arm_MOV_REG_LSL(block, REG_TEMP, src_reg_a, 24);
host_arm_CMP_REG_LSL(block, REG_TEMP, src_reg_b, 24);
}
else
fatal("CMP_JO_DEST %02x\n", uop->src_reg_a_real);
uop->p = host_arm_BVS_(block);
return 0;
}
static int codegen_CMP_JZ_DEST(codeblock_t *block, uop_t *uop)
{
int src_reg_a = HOST_REG_GET(uop->src_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real);
int src_size_a = IREG_GET_SIZE(uop->src_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real);
if (REG_IS_L(src_size_a) && REG_IS_L(src_size_b))
{
host_arm_CMP_REG(block, src_reg_a, src_reg_b);
}
else if (REG_IS_W(src_size_a) && REG_IS_W(src_size_b))
{
host_arm_MOV_REG_LSL(block, REG_TEMP, src_reg_a, 16);
host_arm_CMP_REG_LSL(block, REG_TEMP, src_reg_b, 16);
}
else if (REG_IS_B(src_size_a) && REG_IS_B(src_size_b))
{
host_arm_MOV_REG_LSL(block, REG_TEMP, src_reg_a, 24);
host_arm_CMP_REG_LSL(block, REG_TEMP, src_reg_b, 24);
}
else
fatal("CMP_JZ_DEST %02x\n", uop->src_reg_a_real);
uop->p = host_arm_BEQ_(block);
return 0;
}
static int codegen_FABS(codeblock_t *block, uop_t *uop)
{
int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_a = HOST_REG_GET(uop->src_reg_a_real);
int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_a = IREG_GET_SIZE(uop->src_reg_a_real);
if (REG_IS_D(dest_size) && REG_IS_D(src_size_a))
{
host_arm_VABS_D(block, dest_reg, src_reg_a);
}
else
fatal("codegen_FABS %02x %02x %02x\n", uop->dest_reg_a_real, uop->src_reg_a_real);
return 0;
}
static int codegen_FCHS(codeblock_t *block, uop_t *uop)
{
int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_a = HOST_REG_GET(uop->src_reg_a_real);
int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_a = IREG_GET_SIZE(uop->src_reg_a_real);
if (REG_IS_D(dest_size) && REG_IS_D(src_size_a))
{
host_arm_VNEG_D(block, dest_reg, src_reg_a);
}
else
fatal("codegen_FCHS %02x %02x %02x\n", uop->dest_reg_a_real, uop->src_reg_a_real);
return 0;
}
static int codegen_FSQRT(codeblock_t *block, uop_t *uop)
{
int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_a = HOST_REG_GET(uop->src_reg_a_real);
int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_a = IREG_GET_SIZE(uop->src_reg_a_real);
if (REG_IS_D(dest_size) && REG_IS_D(src_size_a))
{
host_arm_VSQRT_D(block, dest_reg, src_reg_a);
}
else
fatal("codegen_FSQRT %02x %02x %02x\n", uop->dest_reg_a_real, uop->src_reg_a_real);
return 0;
}
static int codegen_FTST(codeblock_t *block, uop_t *uop)
{
int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_a = HOST_REG_GET(uop->src_reg_a_real);
int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_a = IREG_GET_SIZE(uop->src_reg_a_real);
if (REG_IS_W(dest_size) && REG_IS_D(src_size_a))
{
host_arm_VSUB_D(block, REG_D_TEMP, REG_D_TEMP, REG_D_TEMP);
host_arm_VCMP_D(block, src_reg_a, REG_D_TEMP);
host_arm_MOV_IMM(block, dest_reg, 0);
host_arm_VMRS_APSR(block);
host_arm_ORREQ_IMM(block, dest_reg, dest_reg, C3);
host_arm_ORRCC_IMM(block, dest_reg, dest_reg, C0);
host_arm_ORRVS_IMM(block, dest_reg, dest_reg, C0|C2|C3);
}
else
fatal("codegen_FTST %02x %02x %02x\n", uop->dest_reg_a_real, uop->src_reg_a_real, uop->src_reg_b_real);
return 0;
}
static int codegen_FADD(codeblock_t *block, uop_t *uop)
{
int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_a = HOST_REG_GET(uop->src_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real);
int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_a = IREG_GET_SIZE(uop->src_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real);
if (REG_IS_D(dest_size) && REG_IS_D(src_size_a) && REG_IS_D(src_size_b))
{
host_arm_VADD_D(block, dest_reg, src_reg_a, src_reg_b);
}
else
fatal("codegen_FADD %02x %02x %02x\n", uop->dest_reg_a_real, uop->src_reg_a_real, uop->src_reg_b_real);
return 0;
}
static int codegen_FCOM(codeblock_t *block, uop_t *uop)
{
int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_a = HOST_REG_GET(uop->src_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real);
int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_a = IREG_GET_SIZE(uop->src_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real);
if (REG_IS_W(dest_size) && REG_IS_D(src_size_a) && REG_IS_D(src_size_b))
{
host_arm_VCMP_D(block, src_reg_a, src_reg_b);
host_arm_MOV_IMM(block, dest_reg, 0);
host_arm_VMRS_APSR(block);
host_arm_ORREQ_IMM(block, dest_reg, dest_reg, C3);
host_arm_ORRCC_IMM(block, dest_reg, dest_reg, C0);
host_arm_ORRVS_IMM(block, dest_reg, dest_reg, C0|C2|C3);
}
else
fatal("codegen_FCOM %02x %02x %02x\n", uop->dest_reg_a_real, uop->src_reg_a_real, uop->src_reg_b_real);
return 0;
}
static int codegen_FDIV(codeblock_t *block, uop_t *uop)
{
int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_a = HOST_REG_GET(uop->src_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real);
int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_a = IREG_GET_SIZE(uop->src_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real);
if (REG_IS_D(dest_size) && REG_IS_D(src_size_a) && REG_IS_D(src_size_b))
{
host_arm_VDIV_D(block, dest_reg, src_reg_a, src_reg_b);
}
else
fatal("codegen_FDIV %02x %02x %02x\n", uop->dest_reg_a_real, uop->src_reg_a_real, uop->src_reg_b_real);
return 0;
}
static int codegen_FMUL(codeblock_t *block, uop_t *uop)
{
int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_a = HOST_REG_GET(uop->src_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real);
int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_a = IREG_GET_SIZE(uop->src_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real);
if (REG_IS_D(dest_size) && REG_IS_D(src_size_a) && REG_IS_D(src_size_b))
{
host_arm_VMUL_D(block, dest_reg, src_reg_a, src_reg_b);
}
else
fatal("codegen_FMUL %02x %02x %02x\n", uop->dest_reg_a_real, uop->src_reg_a_real, uop->src_reg_b_real);
return 0;
}
static int codegen_FSUB(codeblock_t *block, uop_t *uop)
{
int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_a = HOST_REG_GET(uop->src_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real);
int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_a = IREG_GET_SIZE(uop->src_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real);
if (REG_IS_D(dest_size) && REG_IS_D(src_size_a) && REG_IS_D(src_size_b))
{
host_arm_VSUB_D(block, dest_reg, src_reg_a, src_reg_b);
}
else
fatal("codegen_FSUB %02x %02x %02x\n", uop->dest_reg_a_real, uop->src_reg_a_real, uop->src_reg_b_real);
return 0;
}
static int codegen_FP_ENTER(codeblock_t *block, uop_t *uop)
{
uint32_t *branch_ptr;
if (!in_range(&cr0, &cpu_state))
fatal("codegen_FP_ENTER - out of range\n");
host_arm_LDR_IMM(block, REG_TEMP, REG_CPUSTATE, (uintptr_t)&cr0 - (uintptr_t)&cpu_state);
host_arm_TST_IMM(block, REG_TEMP, 0xc);
branch_ptr = host_arm_BEQ_(block);
host_arm_MOV_IMM(block, REG_TEMP, uop->imm_data);
host_arm_STR_IMM(block, REG_TEMP, REG_CPUSTATE, (uintptr_t)&cpu_state.oldpc - (uintptr_t)&cpu_state);
host_arm_MOV_IMM(block, REG_ARG0, 7);
host_arm_call(block, x86_int);
host_arm_B(block, (uintptr_t)codegen_exit_rout);
*branch_ptr |= ((((uintptr_t)&block_write_data[block_pos] - (uintptr_t)branch_ptr) - 8) & 0x3fffffc) >> 2;
return 0;
}
static int codegen_MMX_ENTER(codeblock_t *block, uop_t *uop)
{
uint32_t *branch_ptr;
if (!in_range(&cr0, &cpu_state))
fatal("codegen_MMX_ENTER - out of range\n");
host_arm_LDR_IMM(block, REG_TEMP, REG_CPUSTATE, (uintptr_t)&cr0 - (uintptr_t)&cpu_state);
host_arm_TST_IMM(block, REG_TEMP, 0xc);
branch_ptr = host_arm_BEQ_(block);
host_arm_MOV_IMM(block, REG_TEMP, uop->imm_data);
host_arm_STR_IMM(block, REG_TEMP, REG_CPUSTATE, (uintptr_t)&cpu_state.oldpc - (uintptr_t)&cpu_state);
host_arm_MOV_IMM(block, REG_ARG0, 7);
host_arm_call(block, x86_int);
host_arm_B(block, (uintptr_t)codegen_exit_rout);
*branch_ptr |= ((((uintptr_t)&block_write_data[block_pos] - (uintptr_t)branch_ptr) - 8) & 0x3fffffc) >> 2;
host_arm_MOV_IMM(block, REG_TEMP, 0x01010101);
host_arm_STR_IMM(block, REG_TEMP, REG_CPUSTATE, (uintptr_t)&cpu_state.tag[0] - (uintptr_t)&cpu_state);
host_arm_STR_IMM(block, REG_TEMP, REG_CPUSTATE, (uintptr_t)&cpu_state.tag[4] - (uintptr_t)&cpu_state);
host_arm_MOV_IMM(block, REG_TEMP, 0);
host_arm_STR_IMM(block, REG_TEMP, REG_CPUSTATE, (uintptr_t)&cpu_state.TOP - (uintptr_t)&cpu_state);
host_arm_STRB_IMM(block, REG_TEMP, REG_CPUSTATE, (uintptr_t)&cpu_state.ismmx - (uintptr_t)&cpu_state);
return 0;
}
static int codegen_JMP(codeblock_t *block, uop_t *uop)
{
host_arm_B(block, (uintptr_t)uop->p);
return 0;
}
static int codegen_LOAD_FUNC_ARG0(codeblock_t *block, uop_t *uop)
{
int src_reg = HOST_REG_GET(uop->src_reg_a_real);
int src_size = IREG_GET_SIZE(uop->src_reg_a_real);
if (REG_IS_W(src_size))
{
host_arm_UXTH(block, REG_ARG0, src_reg, 0);
}
else
fatal("codegen_LOAD_FUNC_ARG0 %02x\n", uop->src_reg_a_real);
return 0;
}
static int codegen_LOAD_FUNC_ARG1(codeblock_t *block, uop_t *uop)
{
fatal("codegen_LOAD_FUNC_ARG1 %02x\n", uop->src_reg_a_real);
return 0;
}
static int codegen_LOAD_FUNC_ARG2(codeblock_t *block, uop_t *uop)
{
fatal("codegen_LOAD_FUNC_ARG2 %02x\n", uop->src_reg_a_real);
return 0;
}
static int codegen_LOAD_FUNC_ARG3(codeblock_t *block, uop_t *uop)
{
fatal("codegen_LOAD_FUNC_ARG3 %02x\n", uop->src_reg_a_real);
return 0;
}
static int codegen_LOAD_FUNC_ARG0_IMM(codeblock_t *block, uop_t *uop)
{
host_arm_MOV_IMM(block, REG_ARG0, uop->imm_data);
return 0;
}
static int codegen_LOAD_FUNC_ARG1_IMM(codeblock_t *block, uop_t *uop)
{
host_arm_MOV_IMM(block, REG_ARG1, uop->imm_data);
return 0;
}
static int codegen_LOAD_FUNC_ARG2_IMM(codeblock_t *block, uop_t *uop)
{
host_arm_MOV_IMM(block, REG_ARG2, uop->imm_data);
return 0;
}
static int codegen_LOAD_FUNC_ARG3_IMM(codeblock_t *block, uop_t *uop)
{
host_arm_MOV_IMM(block, REG_ARG3, uop->imm_data);
return 0;
}
static int codegen_LOAD_SEG(codeblock_t *block, uop_t *uop)
{
int src_reg = HOST_REG_GET(uop->src_reg_a_real);
int src_size = IREG_GET_SIZE(uop->src_reg_a_real);
if (!REG_IS_W(src_size))
fatal("LOAD_SEG %02x %p\n", uop->src_reg_a_real, uop->p);
host_arm_UXTH(block, REG_ARG0, src_reg, 0);
host_arm_MOV_IMM(block, REG_ARG1, (uint32_t)uop->p);
host_arm_call(block, loadseg);
host_arm_TST_REG(block, REG_R0, REG_R0);
host_arm_BNE(block, (uintptr_t)codegen_exit_rout);
return 0;
}
static int codegen_MEM_LOAD_ABS(codeblock_t *block, uop_t *uop)
{
int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), seg_reg = HOST_REG_GET(uop->src_reg_a_real);
int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real);
host_arm_ADD_IMM(block, REG_R0, seg_reg, uop->imm_data);
if (REG_IS_B(dest_size) || REG_IS_BH(dest_size))
{
host_arm_BL(block, (uintptr_t)codegen_mem_load_byte);
}
else if (REG_IS_W(dest_size))
{
host_arm_BL(block, (uintptr_t)codegen_mem_load_word);
}
else if (REG_IS_L(dest_size))
{
host_arm_BL(block, (uintptr_t)codegen_mem_load_long);
}
else
fatal("MEM_LOAD_ABS - %02x\n", uop->dest_reg_a_real);
host_arm_TST_REG(block, REG_R1, REG_R1);
host_arm_BNE(block, (uintptr_t)codegen_exit_rout);
if (REG_IS_B(dest_size))
{
host_arm_BFI(block, dest_reg, REG_R0, 0, 8);
}
else if (REG_IS_BH(dest_size))
{
host_arm_BFI(block, dest_reg, REG_R0, 8, 8);
}
else if (REG_IS_W(dest_size))
{
host_arm_BFI(block, dest_reg, REG_R0, 0, 16);
}
else if (REG_IS_L(dest_size))
{
host_arm_MOV_REG(block, dest_reg, REG_R0);
}
return 0;
}
static int codegen_MEM_LOAD_REG(codeblock_t *block, uop_t *uop)
{
int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), seg_reg = HOST_REG_GET(uop->src_reg_a_real), addr_reg = HOST_REG_GET(uop->src_reg_b_real);
int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real);
host_arm_ADD_REG(block, REG_R0, seg_reg, addr_reg);
if (uop->imm_data)
host_arm_ADD_IMM(block, REG_R0, REG_R0, uop->imm_data);
if (REG_IS_B(dest_size) || REG_IS_BH(dest_size))
{
host_arm_BL(block, (uintptr_t)codegen_mem_load_byte);
}
else if (REG_IS_W(dest_size))
{
host_arm_BL(block, (uintptr_t)codegen_mem_load_word);
}
else if (REG_IS_L(dest_size))
{
host_arm_BL(block, (uintptr_t)codegen_mem_load_long);
}
else if (REG_IS_Q(dest_size))
{
host_arm_BL(block, (uintptr_t)codegen_mem_load_quad);
}
else
fatal("MEM_LOAD_REG - %02x\n", uop->dest_reg_a_real);
host_arm_TST_REG(block, REG_R1, REG_R1);
host_arm_BNE(block, (uintptr_t)codegen_exit_rout);
if (REG_IS_B(dest_size))
{
host_arm_BFI(block, dest_reg, REG_R0, 0, 8);
}
else if (REG_IS_BH(dest_size))
{
host_arm_BFI(block, dest_reg, REG_R0, 8, 8);
}
else if (REG_IS_W(dest_size))
{
host_arm_BFI(block, dest_reg, REG_R0, 0, 16);
}
else if (REG_IS_L(dest_size))
{
host_arm_MOV_REG(block, dest_reg, REG_R0);
}
else if (REG_IS_Q(dest_size))
{
host_arm_VMOV_D_D(block, dest_reg, REG_D_TEMP);
}
return 0;
}
static int codegen_MEM_LOAD_SINGLE(codeblock_t *block, uop_t *uop)
{
int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), seg_reg = HOST_REG_GET(uop->src_reg_a_real), addr_reg = HOST_REG_GET(uop->src_reg_b_real);
int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real);
if (!REG_IS_D(dest_size))
fatal("MEM_LOAD_SINGLE - %02x\n", uop->dest_reg_a_real);
host_arm_ADD_REG(block, REG_R0, seg_reg, addr_reg);
if (uop->imm_data)
host_arm_ADD_IMM(block, REG_R0, REG_R0, uop->imm_data);
host_arm_BL(block, (uintptr_t)codegen_mem_load_single);
host_arm_TST_REG(block, REG_R1, REG_R1);
host_arm_BNE(block, (uintptr_t)codegen_exit_rout);
host_arm_VCVT_D_S(block, dest_reg, REG_D_TEMP);
return 0;
}
static int codegen_MEM_LOAD_DOUBLE(codeblock_t *block, uop_t *uop)
{
int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), seg_reg = HOST_REG_GET(uop->src_reg_a_real), addr_reg = HOST_REG_GET(uop->src_reg_b_real);
int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real);
if (!REG_IS_D(dest_size))
fatal("MEM_LOAD_DOUBLE - %02x\n", uop->dest_reg_a_real);
host_arm_ADD_REG(block, REG_R0, seg_reg, addr_reg);
if (uop->imm_data)
host_arm_ADD_IMM(block, REG_R0, REG_R0, uop->imm_data);
host_arm_BL(block, (uintptr_t)codegen_mem_load_double);
host_arm_TST_REG(block, REG_R1, REG_R1);
host_arm_BNE(block, (uintptr_t)codegen_exit_rout);
host_arm_VMOV_D_D(block, dest_reg, REG_D_TEMP);
return 0;
}
static int codegen_MEM_STORE_ABS(codeblock_t *block, uop_t *uop)
{
int seg_reg = HOST_REG_GET(uop->src_reg_a_real), src_reg = HOST_REG_GET(uop->src_reg_b_real);
int src_size = IREG_GET_SIZE(uop->src_reg_b_real);
host_arm_ADD_IMM(block, REG_R0, seg_reg, uop->imm_data);
if (REG_IS_B(src_size))
{
host_arm_MOV_REG(block, REG_R1, src_reg);
host_arm_BL(block, (uintptr_t)codegen_mem_store_byte);
}
else if (REG_IS_W(src_size))
{
host_arm_MOV_REG(block, REG_R1, src_reg);
host_arm_BL(block, (uintptr_t)codegen_mem_store_word);
}
else if (REG_IS_L(src_size))
{
host_arm_MOV_REG(block, REG_R1, src_reg);
host_arm_BL(block, (uintptr_t)codegen_mem_store_long);
}
else
fatal("MEM_STORE_ABS - %02x\n", uop->src_reg_b_real);
host_arm_TST_REG(block, REG_R1, REG_R1);
host_arm_BNE(block, (uintptr_t)codegen_exit_rout);
return 0;
}
static int codegen_MEM_STORE_REG(codeblock_t *block, uop_t *uop)
{
int seg_reg = HOST_REG_GET(uop->src_reg_a_real), addr_reg = HOST_REG_GET(uop->src_reg_b_real), src_reg = HOST_REG_GET(uop->src_reg_c_real);
int src_size = IREG_GET_SIZE(uop->src_reg_c_real);
host_arm_ADD_REG(block, REG_R0, seg_reg, addr_reg);
if (uop->imm_data)
host_arm_ADD_IMM(block, REG_R0, REG_R0, uop->imm_data);
if (REG_IS_B(src_size))
{
host_arm_MOV_REG(block, REG_R1, src_reg);
host_arm_BL(block, (uintptr_t)codegen_mem_store_byte);
}
else if (REG_IS_BH(src_size))
{
host_arm_MOV_REG_LSR(block, REG_R1, src_reg, 8);
host_arm_BL(block, (uintptr_t)codegen_mem_store_byte);
}
else if (REG_IS_W(src_size))
{
host_arm_MOV_REG(block, REG_R1, src_reg);
host_arm_BL(block, (uintptr_t)codegen_mem_store_word);
}
else if (REG_IS_L(src_size))
{
host_arm_MOV_REG(block, REG_R1, src_reg);
host_arm_BL(block, (uintptr_t)codegen_mem_store_long);
}
else if (REG_IS_Q(src_size))
{
host_arm_VMOV_D_D(block, REG_D_TEMP, src_reg);
host_arm_BL(block, (uintptr_t)codegen_mem_store_quad);
}
else
fatal("MEM_STORE_REG - %02x\n", uop->src_reg_c_real);
host_arm_TST_REG(block, REG_R1, REG_R1);
host_arm_BNE(block, (uintptr_t)codegen_exit_rout);
return 0;
}
static int codegen_MEM_STORE_IMM_8(codeblock_t *block, uop_t *uop)
{
int seg_reg = HOST_REG_GET(uop->src_reg_a_real), addr_reg = HOST_REG_GET(uop->src_reg_b_real);
host_arm_ADD_REG(block, REG_R0, seg_reg, addr_reg);
host_arm_MOV_IMM(block, REG_R1, uop->imm_data);
host_arm_BL(block, (uintptr_t)codegen_mem_store_byte);
host_arm_TST_REG(block, REG_R1, REG_R1);
host_arm_BNE(block, (uintptr_t)codegen_exit_rout);
return 0;
}
static int codegen_MEM_STORE_IMM_16(codeblock_t *block, uop_t *uop)
{
int seg_reg = HOST_REG_GET(uop->src_reg_a_real), addr_reg = HOST_REG_GET(uop->src_reg_b_real);
host_arm_ADD_REG(block, REG_R0, seg_reg, addr_reg);
host_arm_MOV_IMM(block, REG_R1, uop->imm_data);
host_arm_BL(block, (uintptr_t)codegen_mem_store_word);
host_arm_TST_REG(block, REG_R1, REG_R1);
host_arm_BNE(block, (uintptr_t)codegen_exit_rout);
return 0;
}
static int codegen_MEM_STORE_IMM_32(codeblock_t *block, uop_t *uop)
{
int seg_reg = HOST_REG_GET(uop->src_reg_a_real), addr_reg = HOST_REG_GET(uop->src_reg_b_real);
host_arm_ADD_REG(block, REG_R0, seg_reg, addr_reg);
host_arm_MOV_IMM(block, REG_R1, uop->imm_data);
host_arm_BL(block, (uintptr_t)codegen_mem_store_long);
host_arm_TST_REG(block, REG_R1, REG_R1);
host_arm_BNE(block, (uintptr_t)codegen_exit_rout);
return 0;
}
static int codegen_MEM_STORE_SINGLE(codeblock_t *block, uop_t *uop)
{
int seg_reg = HOST_REG_GET(uop->src_reg_a_real), addr_reg = HOST_REG_GET(uop->src_reg_b_real), src_reg = HOST_REG_GET(uop->src_reg_c_real);
int src_size = IREG_GET_SIZE(uop->src_reg_c_real);
if (!REG_IS_D(src_size))
fatal("MEM_STORE_REG - %02x\n", uop->dest_reg_a_real);
host_arm_ADD_REG(block, REG_R0, seg_reg, addr_reg);
if (uop->imm_data)
host_arm_ADD_IMM(block, REG_R0, REG_R0, uop->imm_data);
host_arm_VCVT_S_D(block, REG_D_TEMP, src_reg);
host_arm_BL(block, (uintptr_t)codegen_mem_store_single);
host_arm_TST_REG(block, REG_R1, REG_R1);
host_arm_BNE(block, (uintptr_t)codegen_exit_rout);
return 0;
}
static int codegen_MEM_STORE_DOUBLE(codeblock_t *block, uop_t *uop)
{
int seg_reg = HOST_REG_GET(uop->src_reg_a_real), addr_reg = HOST_REG_GET(uop->src_reg_b_real), src_reg = HOST_REG_GET(uop->src_reg_c_real);
int src_size = IREG_GET_SIZE(uop->src_reg_c_real);
if (!REG_IS_D(src_size))
fatal("MEM_STORE_REG - %02x\n", uop->dest_reg_a_real);
host_arm_ADD_REG(block, REG_R0, seg_reg, addr_reg);
if (uop->imm_data)
host_arm_ADD_IMM(block, REG_R0, REG_R0, uop->imm_data);
host_arm_VMOV_D_D(block, REG_D_TEMP, src_reg);
host_arm_BL(block, (uintptr_t)codegen_mem_store_double);
host_arm_TST_REG(block, REG_R1, REG_R1);
host_arm_BNE(block, (uintptr_t)codegen_exit_rout);
return 0;
}
static int codegen_MOV(codeblock_t *block, uop_t *uop)
{
int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg = HOST_REG_GET(uop->src_reg_a_real);
int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size = IREG_GET_SIZE(uop->src_reg_a_real);
if (REG_IS_L(dest_size) && REG_IS_L(src_size))
{
host_arm_MOV_REG_LSL(block, dest_reg, src_reg, 0);
}
else if (REG_IS_W(dest_size) && REG_IS_W(src_size))
{
host_arm_BFI(block, dest_reg, src_reg, 0, 16);
}
else if (REG_IS_B(dest_size) && REG_IS_B(src_size))
{
host_arm_BFI(block, dest_reg, src_reg, 0, 8);
}
else if (REG_IS_BH(dest_size) && REG_IS_B(src_size))
{
host_arm_BFI(block, dest_reg, src_reg, 8, 8);
}
else if (REG_IS_B(dest_size) && REG_IS_BH(src_size))
{
host_arm_MOV_REG_LSR(block, REG_TEMP, src_reg, 8);
host_arm_BFI(block, dest_reg, REG_TEMP, 0, 8);
}
else if (REG_IS_BH(dest_size) && REG_IS_BH(src_size))
{
host_arm_MOV_REG_LSR(block, REG_TEMP, src_reg, 8);
host_arm_BFI(block, dest_reg, REG_TEMP, 8, 8);
}
else if (REG_IS_D(dest_size) && REG_IS_D(src_size))
{
host_arm_VMOV_D_D(block, dest_reg, src_reg);
}
else if (REG_IS_Q(dest_size) && REG_IS_Q(src_size))
{
host_arm_VMOV_D_D(block, dest_reg, src_reg);
}
else
fatal("MOV %02x %02x\n", uop->dest_reg_a_real, uop->src_reg_a_real);
return 0;
}
static int codegen_MOV_IMM(codeblock_t *block, uop_t *uop)
{
int dest_reg = HOST_REG_GET(uop->dest_reg_a_real);
int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real);
if (REG_IS_L(dest_size))
{
host_arm_MOV_IMM(block, dest_reg, uop->imm_data);
}
else if (REG_IS_W(dest_size))
{
host_arm_MOVW_IMM(block, REG_TEMP, uop->imm_data);
host_arm_BFI(block, dest_reg, REG_TEMP, 0, 16);
}
else if (REG_IS_B(dest_size))
{
host_arm_AND_IMM(block, dest_reg, dest_reg, ~0x000000ff);
host_arm_ORR_IMM(block, dest_reg, dest_reg, uop->imm_data);
}
else if (REG_IS_BH(dest_size))
{
host_arm_AND_IMM(block, dest_reg, dest_reg, ~0x0000ff00);
host_arm_ORR_IMM(block, dest_reg, dest_reg, uop->imm_data << 8);
}
else
fatal("MOV_IMM %02x\n", uop->dest_reg_a_real);
return 0;
}
static int codegen_MOV_PTR(codeblock_t *block, uop_t *uop)
{
host_arm_MOV_IMM(block, uop->dest_reg_a_real, (uintptr_t)uop->p);
return 0;
}
static int codegen_MOVSX(codeblock_t *block, uop_t *uop)
{
int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg = HOST_REG_GET(uop->src_reg_a_real);
int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size = IREG_GET_SIZE(uop->src_reg_a_real);
if (REG_IS_L(dest_size) && REG_IS_B(src_size))
{
host_arm_SXTB(block, dest_reg, src_reg, 0);
}
else if (REG_IS_L(dest_size) && REG_IS_BH(src_size))
{
host_arm_SXTB(block, dest_reg, src_reg, 8);
}
else if (REG_IS_L(dest_size) && REG_IS_W(src_size))
{
host_arm_SXTH(block, dest_reg, src_reg, 0);
}
else if (REG_IS_W(dest_size) && REG_IS_B(src_size))
{
host_arm_SXTB(block, REG_TEMP, src_reg, 0);
host_arm_BFI(block, dest_reg, REG_TEMP, 0, 16);
}
else if (REG_IS_W(dest_size) && REG_IS_BH(src_size))
{
host_arm_SXTB(block, REG_TEMP, src_reg, 8);
host_arm_BFI(block, dest_reg, REG_TEMP, 0, 16);
}
else
fatal("MOVSX %02x %02x\n", uop->dest_reg_a_real, uop->src_reg_a_real);
return 0;
}
static int codegen_MOVZX(codeblock_t *block, uop_t *uop)
{
int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg = HOST_REG_GET(uop->src_reg_a_real);
int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size = IREG_GET_SIZE(uop->src_reg_a_real);
if (REG_IS_Q(dest_size) && REG_IS_L(src_size))
{
host_arm_MOV_IMM(block, REG_TEMP, 0);
host_arm_VMOV_D_64(block, dest_reg, src_reg, REG_TEMP);
}
else if (REG_IS_L(dest_size) && REG_IS_Q(src_size))
{
host_arm_VMOV_32_S(block, dest_reg, src_reg);
}
else if (REG_IS_L(dest_size) && REG_IS_B(src_size))
{
host_arm_UXTB(block, dest_reg, src_reg, 0);
}
else if (REG_IS_L(dest_size) && REG_IS_BH(src_size))
{
host_arm_UXTB(block, dest_reg, src_reg, 8);
}
else if (REG_IS_L(dest_size) && REG_IS_W(src_size))
{
host_arm_UXTH(block, dest_reg, src_reg, 0);
}
else if (REG_IS_W(dest_size) && REG_IS_B(src_size))
{
if (src_reg == dest_reg)
host_arm_BIC_IMM(block, dest_reg, dest_reg, 0xff00);
else
{
host_arm_UXTB(block, REG_TEMP, src_reg, 0);
host_arm_BFI(block, dest_reg, REG_TEMP, 0, 16);
}
}
else if (REG_IS_W(dest_size) && REG_IS_BH(src_size))
{
host_arm_MOV_REG_LSR(block, REG_TEMP, src_reg, 8);
host_arm_BIC_IMM(block, dest_reg, dest_reg, 0xff00);
host_arm_BFI(block, dest_reg, REG_TEMP, 0, 8);
}
else
fatal("MOVZX %02x %02x\n", uop->dest_reg_a_real, uop->src_reg_a_real);
return 0;
}
static double int64_to_double(int64_t a)
{
return (double)a;
}
static int codegen_MOV_DOUBLE_INT(codeblock_t *block, uop_t *uop)
{
int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg = HOST_REG_GET(uop->src_reg_a_real);
int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size = IREG_GET_SIZE(uop->src_reg_a_real);
if (REG_IS_D(dest_size) && REG_IS_L(src_size))
{
host_arm_VMOV_S_32(block, REG_D_TEMP, src_reg);
host_arm_VCVT_D_IS(block, dest_reg, REG_D_TEMP);
}
else if (REG_IS_D(dest_size) && REG_IS_W(src_size))
{
host_arm_SXTH(block, REG_TEMP, src_reg, 0);
host_arm_VMOV_S_32(block, REG_D_TEMP, REG_TEMP);
host_arm_VCVT_D_IS(block, dest_reg, REG_D_TEMP);
}
else if (REG_IS_D(dest_size) && REG_IS_Q(src_size))
{
/*ARMv7 has no instructions to convert a 64-bit integer to a double.
For simplicity, call a C function and let the compiler do it.*/
host_arm_VMOV_64_D(block, REG_R0, REG_R1, src_reg);
host_arm_BL(block, (uintptr_t)int64_to_double); /*Input - R0/R1, Output - D0*/
host_arm_VMOV_D_D(block, dest_reg, REG_D0);
}
else
fatal("MOV_DOUBLE_INT %02x %02x\n", uop->dest_reg_a_real, uop->src_reg_a_real);
return 0;
}
static int codegen_MOV_INT_DOUBLE(codeblock_t *block, uop_t *uop)
{
int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg = HOST_REG_GET(uop->src_reg_a_real);
int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size = IREG_GET_SIZE(uop->src_reg_a_real);
if (REG_IS_L(dest_size) && REG_IS_D(src_size))
{
host_arm_VMOV_D_D(block, REG_D_TEMP, src_reg);
host_arm_BL(block, (uintptr_t)codegen_fp_round);
host_arm_VMOV_32_S(block, dest_reg, REG_D_TEMP);
}
else if (REG_IS_W(dest_size) && REG_IS_D(src_size))
{
host_arm_VMOV_D_D(block, REG_D_TEMP, src_reg);
host_arm_BL(block, (uintptr_t)codegen_fp_round);
host_arm_VMOV_32_S(block, REG_TEMP, REG_D_TEMP);
host_arm_BFI(block, dest_reg, REG_TEMP, 0, 16);
}
else
fatal("MOV_INT_DOUBLE %02x %02x\n", uop->dest_reg_a_real, uop->src_reg_a_real);
return 0;
}
static int64_t x87_fround64(double b)
{
int64_t a, c;
switch ((cpu_state.npxc >> 10) & 3)
{
case 0: /*Nearest*/
a = (int64_t)floor(b);
c = (int64_t)floor(b + 1.0);
if ((b - a) < (c - b))
return a;
else if ((b - a) > (c - b))
return c;
else
return (a & 1) ? c : a;
case 1: /*Down*/
return (int64_t)floor(b);
case 2: /*Up*/
return (int64_t)ceil(b);
case 3: /*Chop*/
return (int64_t)b;
}
return 0;
}
static int codegen_MOV_INT_DOUBLE_64(codeblock_t *block, uop_t *uop)
{
int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg = HOST_REG_GET(uop->src_reg_a_real), src_64_reg = HOST_REG_GET(uop->src_reg_b_real), tag_reg = HOST_REG_GET(uop->src_reg_c_real);
int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size = IREG_GET_SIZE(uop->src_reg_a_real), src_64_size = IREG_GET_SIZE(uop->src_reg_b_real);
if (REG_IS_Q(dest_size) && REG_IS_D(src_size) && REG_IS_Q(src_64_size))
{
uint32_t *branch_offset;
/*If TAG_UINT64 is set then the source is MM[]. Otherwise it is a double in ST()*/
host_arm_VMOV_D_D(block, dest_reg, src_64_reg);
host_arm_TST_IMM(block, tag_reg, TAG_UINT64);
branch_offset = host_arm_BNE_(block);
/*VFP/NEON has no instructions to convert a float to 64-bit integer,
so call out to C.*/
host_arm_VMOV_D_D(block, REG_D0, src_reg);
host_arm_call(block, x87_fround64);
host_arm_VMOV_D_64(block, REG_D_TEMP, REG_R0, REG_R1);
*branch_offset |= ((((uintptr_t)&block_write_data[block_pos] - (uintptr_t)branch_offset) - 8) & 0x3fffffc) >> 2;
}
else
fatal("MOV_INT_DOUBLE_64 %02x %02x\n", uop->dest_reg_a_real, uop->src_reg_a_real);
return 0;
}
static int codegen_MOV_REG_PTR(codeblock_t *block, uop_t *uop)
{
int dest_reg = HOST_REG_GET(uop->dest_reg_a_real);
int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real);
host_arm_MOV_IMM(block, REG_TEMP, (uintptr_t)uop->p);
if (REG_IS_L(dest_size))
{
host_arm_LDR_IMM(block, dest_reg, REG_TEMP, 0);
}
else
fatal("MOV_REG_PTR %02x\n", uop->dest_reg_a_real);
return 0;
}
static int codegen_MOVZX_REG_PTR_8(codeblock_t *block, uop_t *uop)
{
int dest_reg = HOST_REG_GET(uop->dest_reg_a_real);
int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real);
host_arm_MOV_IMM(block, REG_TEMP, (uintptr_t)uop->p);
if (REG_IS_L(dest_size))
{
host_arm_LDRB_IMM(block, dest_reg, REG_TEMP, 0);
}
else if (REG_IS_W(dest_size))
{
host_arm_LDRB_IMM(block, REG_TEMP, REG_TEMP, 0);
host_arm_BFI(block, dest_reg, REG_TEMP, 0, 16);
}
else if (REG_IS_B(dest_size))
{
host_arm_LDRB_IMM(block, REG_TEMP, REG_TEMP, 0);
host_arm_BFI(block, dest_reg, REG_TEMP, 0, 8);
}
else
fatal("MOVZX_REG_PTR_8 %02x\n", uop->dest_reg_a_real);
return 0;
}
static int codegen_MOVZX_REG_PTR_16(codeblock_t *block, uop_t *uop)
{
int dest_reg = HOST_REG_GET(uop->dest_reg_a_real);
int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real);
host_arm_MOV_IMM(block, REG_TEMP, (uintptr_t)uop->p);
if (REG_IS_L(dest_size))
{
host_arm_LDRH_IMM(block, dest_reg, REG_TEMP, 0);
}
else if (REG_IS_W(dest_size))
{
host_arm_LDRH_IMM(block, REG_TEMP, REG_TEMP, 0);
host_arm_BFI(block, dest_reg, REG_TEMP, 0, 16);
}
else
fatal("MOVZX_REG_PTR_16 %02x\n", uop->dest_reg_a_real);
return 0;
}
static int codegen_NOP(codeblock_t *block, uop_t *uop)
{
return 0;
}
static int codegen_OR(codeblock_t *block, uop_t *uop)
{
int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_a = HOST_REG_GET(uop->src_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real);
int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_a = IREG_GET_SIZE(uop->src_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real);
if (REG_IS_Q(dest_size) && REG_IS_Q(src_size_a) && REG_IS_Q(src_size_b))
{
host_arm_VORR_D(block, dest_reg, src_reg_a, src_reg_b);
}
else if (REG_IS_L(dest_size) && REG_IS_L(src_size_a) && REG_IS_L(src_size_b))
{
host_arm_ORR_REG_LSL(block, dest_reg, src_reg_a, src_reg_b, 0);
}
else if (REG_IS_W(dest_size) && REG_IS_W(src_size_a) && REG_IS_W(src_size_b))
{
host_arm_ORR_REG_LSL(block, REG_TEMP, src_reg_a, src_reg_b, 0);
host_arm_BFI(block, dest_reg, REG_TEMP, 0, 16);
}
else if (REG_IS_B(dest_size) && REG_IS_B(src_size_a) && REG_IS_B(src_size_b) && dest_reg == src_reg_a)
{
host_arm_UXTB(block, REG_TEMP, src_reg_b, 0);
host_arm_ORR_REG_LSL(block, dest_reg, src_reg_a, REG_TEMP, 0);
}
else if (REG_IS_B(dest_size) && REG_IS_B(src_size_a) && REG_IS_BH(src_size_b) && dest_reg == src_reg_a)
{
host_arm_UXTB(block, REG_TEMP, src_reg_b, 8);
host_arm_ORR_REG_LSL(block, dest_reg, src_reg_a, REG_TEMP, 0);
}
else if (REG_IS_BH(dest_size) && REG_IS_BH(src_size_a) && REG_IS_B(src_size_b) && dest_reg == src_reg_a)
{
host_arm_UXTB(block, REG_TEMP, src_reg_b, 0);
host_arm_ORR_REG_LSL(block, dest_reg, src_reg_a, REG_TEMP, 8);
}
else if (REG_IS_BH(dest_size) && REG_IS_BH(src_size_a) && REG_IS_BH(src_size_b) && dest_reg == src_reg_a)
{
host_arm_UXTB(block, REG_TEMP, src_reg_b, 8);
host_arm_ORR_REG_LSL(block, dest_reg, src_reg_a, REG_TEMP, 8);
}
else
fatal("OR %02x %02x %02x\n", uop->dest_reg_a_real, uop->src_reg_a_real, uop->src_reg_b_real);
return 0;
}
static int codegen_OR_IMM(codeblock_t *block, uop_t *uop)
{
int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg = HOST_REG_GET(uop->src_reg_a_real);
int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size = IREG_GET_SIZE(uop->src_reg_a_real);
if (REG_IS_L(dest_size) && REG_IS_L(src_size))
{
host_arm_ORR_IMM(block, dest_reg, src_reg, uop->imm_data);
}
else if (REG_IS_W(dest_size) && REG_IS_W(src_size) && dest_reg == src_reg)
{
host_arm_ORR_IMM(block, dest_reg, src_reg, uop->imm_data);
}
else if (REG_IS_B(dest_size) && REG_IS_B(src_size) && dest_reg == src_reg)
{
host_arm_ORR_IMM(block, dest_reg, src_reg, uop->imm_data);
}
else if (REG_IS_BH(dest_size) && REG_IS_BH(src_size) && dest_reg == src_reg)
{
host_arm_ORR_IMM(block, dest_reg, src_reg, uop->imm_data << 8);
}
else
fatal("OR_IMM %02x %02x\n", uop->dest_reg_a_real, uop->src_reg_a_real);
return 0;
}
static int codegen_PACKSSWB(codeblock_t *block, uop_t *uop)
{
int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_a = HOST_REG_GET(uop->src_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real);
int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_a = IREG_GET_SIZE(uop->src_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real);
if (REG_IS_Q(dest_size) && REG_IS_Q(src_size_a) && REG_IS_Q(src_size_b))
{
host_arm_VMOV_D_D(block, REG_Q_TEMP, src_reg_a);
host_arm_VMOV_D_D(block, REG_Q_TEMP_2, src_reg_b);
host_arm_VQMOVN_S16(block, dest_reg, REG_Q_TEMP);
host_arm_VQMOVN_S16(block, REG_D_TEMP, REG_Q_TEMP_2);
host_arm_VZIP_D32(block, dest_reg, REG_D_TEMP);
}
else
fatal("PACKSSWB %02x %02x %02x\n", uop->dest_reg_a_real, uop->src_reg_a_real, uop->src_reg_b_real);
return 0;
}
static int codegen_PACKSSDW(codeblock_t *block, uop_t *uop)
{
int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_a = HOST_REG_GET(uop->src_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real);
int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_a = IREG_GET_SIZE(uop->src_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real);
if (REG_IS_Q(dest_size) && REG_IS_Q(src_size_a) && REG_IS_Q(src_size_b))
{
host_arm_VMOV_D_D(block, REG_Q_TEMP, src_reg_a);
host_arm_VMOV_D_D(block, REG_Q_TEMP_2, src_reg_b);
host_arm_VQMOVN_S32(block, dest_reg, REG_Q_TEMP);
host_arm_VQMOVN_S32(block, REG_D_TEMP, REG_Q_TEMP_2);
host_arm_VZIP_D32(block, dest_reg, REG_D_TEMP);
}
else
fatal("PACKSSDW %02x %02x %02x\n", uop->dest_reg_a_real, uop->src_reg_a_real, uop->src_reg_b_real);
return 0;
}
static int codegen_PACKUSWB(codeblock_t *block, uop_t *uop)
{
int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_a = HOST_REG_GET(uop->src_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real);
int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_a = IREG_GET_SIZE(uop->src_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real);
if (REG_IS_Q(dest_size) && REG_IS_Q(src_size_a) && REG_IS_Q(src_size_b))
{
host_arm_VMOV_D_D(block, REG_Q_TEMP, src_reg_a);
host_arm_VMOV_D_D(block, REG_Q_TEMP_2, src_reg_b);
host_arm_VQMOVN_U16(block, dest_reg, REG_Q_TEMP);
host_arm_VQMOVN_U16(block, REG_D_TEMP, REG_Q_TEMP_2);
host_arm_VZIP_D32(block, dest_reg, REG_D_TEMP);
}
else
fatal("PACKUSWB %02x %02x %02x\n", uop->dest_reg_a_real, uop->src_reg_a_real, uop->src_reg_b_real);
return 0;
}
static int codegen_PADDB(codeblock_t *block, uop_t *uop)
{
int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_a = HOST_REG_GET(uop->src_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real);
int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_a = IREG_GET_SIZE(uop->src_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real);
if (REG_IS_Q(dest_size) && REG_IS_Q(src_size_a) && REG_IS_Q(src_size_b))
{
host_arm_VADD_I8(block, dest_reg, src_reg_a, src_reg_b);
}
else
fatal("PADDB %02x %02x %02x\n", uop->dest_reg_a_real, uop->src_reg_a_real, uop->src_reg_b_real);
return 0;
}
static int codegen_PADDW(codeblock_t *block, uop_t *uop)
{
int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_a = HOST_REG_GET(uop->src_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real);
int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_a = IREG_GET_SIZE(uop->src_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real);
if (REG_IS_Q(dest_size) && REG_IS_Q(src_size_a) && REG_IS_Q(src_size_b))
{
host_arm_VADD_I16(block, dest_reg, src_reg_a, src_reg_b);
}
else
fatal("PADDW %02x %02x %02x\n", uop->dest_reg_a_real, uop->src_reg_a_real, uop->src_reg_b_real);
return 0;
}
static int codegen_PADDD(codeblock_t *block, uop_t *uop)
{
int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_a = HOST_REG_GET(uop->src_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real);
int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_a = IREG_GET_SIZE(uop->src_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real);
if (REG_IS_Q(dest_size) && REG_IS_Q(src_size_a) && REG_IS_Q(src_size_b))
{
host_arm_VADD_I32(block, dest_reg, src_reg_a, src_reg_b);
}
else
fatal("PADDD %02x %02x %02x\n", uop->dest_reg_a_real, uop->src_reg_a_real, uop->src_reg_b_real);
return 0;
}
static int codegen_PADDSB(codeblock_t *block, uop_t *uop)
{
int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_a = HOST_REG_GET(uop->src_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real);
int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_a = IREG_GET_SIZE(uop->src_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real);
if (REG_IS_Q(dest_size) && REG_IS_Q(src_size_a) && REG_IS_Q(src_size_b))
{
host_arm_VQADD_S8(block, dest_reg, src_reg_a, src_reg_b);
}
else
fatal("PADDSB %02x %02x %02x\n", uop->dest_reg_a_real, uop->src_reg_a_real, uop->src_reg_b_real);
return 0;
}
static int codegen_PADDSW(codeblock_t *block, uop_t *uop)
{
int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_a = HOST_REG_GET(uop->src_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real);
int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_a = IREG_GET_SIZE(uop->src_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real);
if (REG_IS_Q(dest_size) && REG_IS_Q(src_size_a) && REG_IS_Q(src_size_b))
{
host_arm_VQADD_S16(block, dest_reg, src_reg_a, src_reg_b);
}
else
fatal("PADDSW %02x %02x %02x\n", uop->dest_reg_a_real, uop->src_reg_a_real, uop->src_reg_b_real);
return 0;
}
static int codegen_PADDUSB(codeblock_t *block, uop_t *uop)
{
int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_a = HOST_REG_GET(uop->src_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real);
int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_a = IREG_GET_SIZE(uop->src_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real);
if (REG_IS_Q(dest_size) && REG_IS_Q(src_size_a) && REG_IS_Q(src_size_b))
{
host_arm_VQADD_U8(block, dest_reg, src_reg_a, src_reg_b);
}
else
fatal("PADDUSB %02x %02x %02x\n", uop->dest_reg_a_real, uop->src_reg_a_real, uop->src_reg_b_real);
return 0;
}
static int codegen_PADDUSW(codeblock_t *block, uop_t *uop)
{
int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_a = HOST_REG_GET(uop->src_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real);
int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_a = IREG_GET_SIZE(uop->src_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real);
if (REG_IS_Q(dest_size) && REG_IS_Q(src_size_a) && REG_IS_Q(src_size_b))
{
host_arm_VQADD_U16(block, dest_reg, src_reg_a, src_reg_b);
}
else
fatal("PADDUSW %02x %02x %02x\n", uop->dest_reg_a_real, uop->src_reg_a_real, uop->src_reg_b_real);
return 0;
}
static int codegen_PCMPEQB(codeblock_t *block, uop_t *uop)
{
int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_a = HOST_REG_GET(uop->src_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real);
int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_a = IREG_GET_SIZE(uop->src_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real);
if (REG_IS_Q(dest_size) && REG_IS_Q(src_size_a) && REG_IS_Q(src_size_b))
{
host_arm_VCEQ_I8(block, dest_reg, src_reg_a, src_reg_b);
}
else
fatal("PCMPEQB %02x %02x %02x\n", uop->dest_reg_a_real, uop->src_reg_a_real, uop->src_reg_b_real);
return 0;
}
static int codegen_PCMPEQW(codeblock_t *block, uop_t *uop)
{
int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_a = HOST_REG_GET(uop->src_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real);
int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_a = IREG_GET_SIZE(uop->src_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real);
if (REG_IS_Q(dest_size) && REG_IS_Q(src_size_a) && REG_IS_Q(src_size_b))
{
host_arm_VCEQ_I16(block, dest_reg, src_reg_a, src_reg_b);
}
else
fatal("PCMPEQW %02x %02x %02x\n", uop->dest_reg_a_real, uop->src_reg_a_real, uop->src_reg_b_real);
return 0;
}
static int codegen_PCMPEQD(codeblock_t *block, uop_t *uop)
{
int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_a = HOST_REG_GET(uop->src_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real);
int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_a = IREG_GET_SIZE(uop->src_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real);
if (REG_IS_Q(dest_size) && REG_IS_Q(src_size_a) && REG_IS_Q(src_size_b))
{
host_arm_VCEQ_I32(block, dest_reg, src_reg_a, src_reg_b);
}
else
fatal("PCMPEQD %02x %02x %02x\n", uop->dest_reg_a_real, uop->src_reg_a_real, uop->src_reg_b_real);
return 0;
}
static int codegen_PCMPGTB(codeblock_t *block, uop_t *uop)
{
int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_a = HOST_REG_GET(uop->src_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real);
int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_a = IREG_GET_SIZE(uop->src_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real);
if (REG_IS_Q(dest_size) && REG_IS_Q(src_size_a) && REG_IS_Q(src_size_b))
{
host_arm_VCGT_S8(block, dest_reg, src_reg_a, src_reg_b);
}
else
fatal("PCMPGTB %02x %02x %02x\n", uop->dest_reg_a_real, uop->src_reg_a_real, uop->src_reg_b_real);
return 0;
}
static int codegen_PCMPGTW(codeblock_t *block, uop_t *uop)
{
int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_a = HOST_REG_GET(uop->src_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real);
int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_a = IREG_GET_SIZE(uop->src_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real);
if (REG_IS_Q(dest_size) && REG_IS_Q(src_size_a) && REG_IS_Q(src_size_b))
{
host_arm_VCGT_S16(block, dest_reg, src_reg_a, src_reg_b);
}
else
fatal("PCMPGTW %02x %02x %02x\n", uop->dest_reg_a_real, uop->src_reg_a_real, uop->src_reg_b_real);
return 0;
}
static int codegen_PCMPGTD(codeblock_t *block, uop_t *uop)
{
int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_a = HOST_REG_GET(uop->src_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real);
int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_a = IREG_GET_SIZE(uop->src_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real);
if (REG_IS_Q(dest_size) && REG_IS_Q(src_size_a) && REG_IS_Q(src_size_b))
{
host_arm_VCGT_S32(block, dest_reg, src_reg_a, src_reg_b);
}
else
fatal("PCMPGTD %02x %02x %02x\n", uop->dest_reg_a_real, uop->src_reg_a_real, uop->src_reg_b_real);
return 0;
}
static int codegen_PF2ID(codeblock_t *block, uop_t *uop)
{
int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_a = HOST_REG_GET(uop->src_reg_a_real);
int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_a = IREG_GET_SIZE(uop->src_reg_a_real);
if (REG_IS_Q(dest_size) && REG_IS_Q(src_size_a))
{
host_arm_VCVT_S32_F32(block, dest_reg, src_reg_a);
}
else
fatal("PF2ID %02x %02x\n", uop->dest_reg_a_real);
return 0;
}
static int codegen_PFADD(codeblock_t *block, uop_t *uop)
{
int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_a = HOST_REG_GET(uop->src_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real);
int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_a = IREG_GET_SIZE(uop->src_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real);
if (REG_IS_Q(dest_size) && REG_IS_Q(src_size_a) && REG_IS_Q(src_size_b))
{
host_arm_VADD_F32(block, dest_reg, src_reg_a, src_reg_b);
}
else
fatal("PFADD %02x %02x %02x\n", uop->dest_reg_a_real, uop->src_reg_a_real, uop->src_reg_b_real);
return 0;
}
static int codegen_PFCMPEQ(codeblock_t *block, uop_t *uop)
{
int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_a = HOST_REG_GET(uop->src_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real);
int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_a = IREG_GET_SIZE(uop->src_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real);
if (REG_IS_Q(dest_size) && REG_IS_Q(src_size_a) && REG_IS_Q(src_size_b))
{
host_arm_VCEQ_F32(block, dest_reg, src_reg_a, src_reg_b);
}
else
fatal("PFCMPEQ %02x %02x %02x\n", uop->dest_reg_a_real, uop->src_reg_a_real, uop->src_reg_b_real);
return 0;
}
static int codegen_PFCMPGE(codeblock_t *block, uop_t *uop)
{
int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_a = HOST_REG_GET(uop->src_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real);
int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_a = IREG_GET_SIZE(uop->src_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real);
if (REG_IS_Q(dest_size) && REG_IS_Q(src_size_a) && REG_IS_Q(src_size_b))
{
host_arm_VCGE_F32(block, dest_reg, src_reg_a, src_reg_b);
}
else
fatal("PFCMPGE %02x %02x %02x\n", uop->dest_reg_a_real, uop->src_reg_a_real, uop->src_reg_b_real);
return 0;
}
static int codegen_PFCMPGT(codeblock_t *block, uop_t *uop)
{
int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_a = HOST_REG_GET(uop->src_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real);
int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_a = IREG_GET_SIZE(uop->src_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real);
if (REG_IS_Q(dest_size) && REG_IS_Q(src_size_a) && REG_IS_Q(src_size_b))
{
host_arm_VCGT_F32(block, dest_reg, src_reg_a, src_reg_b);
}
else
fatal("PFCMPGT %02x %02x %02x\n", uop->dest_reg_a_real, uop->src_reg_a_real, uop->src_reg_b_real);
return 0;
}
static int codegen_PFMAX(codeblock_t *block, uop_t *uop)
{
int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_a = HOST_REG_GET(uop->src_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real);
int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_a = IREG_GET_SIZE(uop->src_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real);
if (REG_IS_Q(dest_size) && REG_IS_Q(src_size_a) && REG_IS_Q(src_size_b))
{
host_arm_VMAX_F32(block, dest_reg, src_reg_a, src_reg_b);
}
else
fatal("PFMAX %02x %02x %02x\n", uop->dest_reg_a_real, uop->src_reg_a_real, uop->src_reg_b_real);
return 0;
}
static int codegen_PFMIN(codeblock_t *block, uop_t *uop)
{
int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_a = HOST_REG_GET(uop->src_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real);
int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_a = IREG_GET_SIZE(uop->src_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real);
if (REG_IS_Q(dest_size) && REG_IS_Q(src_size_a) && REG_IS_Q(src_size_b))
{
host_arm_VMIN_F32(block, dest_reg, src_reg_a, src_reg_b);
}
else
fatal("PFMIN %02x %02x %02x\n", uop->dest_reg_a_real, uop->src_reg_a_real, uop->src_reg_b_real);
return 0;
}
static int codegen_PFMUL(codeblock_t *block, uop_t *uop)
{
int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_a = HOST_REG_GET(uop->src_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real);
int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_a = IREG_GET_SIZE(uop->src_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real);
if (REG_IS_Q(dest_size) && REG_IS_Q(src_size_a) && REG_IS_Q(src_size_b))
{
host_arm_VMUL_F32(block, dest_reg, src_reg_a, src_reg_b);
}
else
fatal("PFMUL %02x %02x %02x\n", uop->dest_reg_a_real, uop->src_reg_a_real, uop->src_reg_b_real);
return 0;
}
static int codegen_PFRCP(codeblock_t *block, uop_t *uop)
{
int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_a = HOST_REG_GET(uop->src_reg_a_real);
int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_a = IREG_GET_SIZE(uop->src_reg_a_real);
if (REG_IS_Q(dest_size) && REG_IS_Q(src_size_a))
{
/*TODO: This could be improved (use VRECPE/VRECPS)*/
host_arm_VMOV_F32_ONE(block, REG_D_TEMP);
host_arm_VDIV_S(block, dest_reg, REG_D_TEMP, src_reg_a);
host_arm_VDUP_32(block, dest_reg, dest_reg, 0);
}
else
fatal("PFRCP %02x %02x\n", uop->dest_reg_a_real);
return 0;
}
static int codegen_PFRSQRT(codeblock_t *block, uop_t *uop)
{
int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_a = HOST_REG_GET(uop->src_reg_a_real);
int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_a = IREG_GET_SIZE(uop->src_reg_a_real);
if (REG_IS_Q(dest_size) && REG_IS_Q(src_size_a))
{
/*TODO: This could be improved (use VRSQRTE/VRSQRTS)*/
host_arm_VSQRT_S(block, REG_D_TEMP, src_reg_a);
host_arm_VMOV_F32_ONE(block, REG_D_TEMP);
host_arm_VDIV_S(block, dest_reg, dest_reg, REG_D_TEMP);
host_arm_VDUP_32(block, dest_reg, dest_reg, 0);
}
else
fatal("PFRSQRT %02x %02x\n", uop->dest_reg_a_real);
return 0;
}
static int codegen_PFSUB(codeblock_t *block, uop_t *uop)
{
int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_a = HOST_REG_GET(uop->src_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real);
int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_a = IREG_GET_SIZE(uop->src_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real);
if (REG_IS_Q(dest_size) && REG_IS_Q(src_size_a) && REG_IS_Q(src_size_b))
{
host_arm_VSUB_F32(block, dest_reg, src_reg_a, src_reg_b);
}
else
fatal("PFSUB %02x %02x %02x\n", uop->dest_reg_a_real, uop->src_reg_a_real, uop->src_reg_b_real);
return 0;
}
static int codegen_PI2FD(codeblock_t *block, uop_t *uop)
{
int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_a = HOST_REG_GET(uop->src_reg_a_real);
int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_a = IREG_GET_SIZE(uop->src_reg_a_real);
if (REG_IS_Q(dest_size) && REG_IS_Q(src_size_a))
{
host_arm_VCVT_F32_S32(block, dest_reg, src_reg_a);
}
else
fatal("PI2FD %02x %02x\n", uop->dest_reg_a_real);
return 0;
}
static int codegen_PMADDWD(codeblock_t *block, uop_t *uop)
{
int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_a = HOST_REG_GET(uop->src_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real);
int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_a = IREG_GET_SIZE(uop->src_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real);
if (REG_IS_Q(dest_size) && REG_IS_Q(src_size_a) && REG_IS_Q(src_size_b))
{
host_arm_VMULL_S16(block, REG_Q_TEMP, src_reg_a, src_reg_b);
host_arm_VPADDL_Q_S32(block, REG_Q_TEMP, REG_Q_TEMP);
host_arm_VMOVN_I64(block, dest_reg, REG_Q_TEMP);
}
else
fatal("PMULHW %02x %02x %02x\n", uop->dest_reg_a_real, uop->src_reg_a_real, uop->src_reg_b_real);
return 0;
}
static int codegen_PMULHW(codeblock_t *block, uop_t *uop)
{
int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_a = HOST_REG_GET(uop->src_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real);
int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_a = IREG_GET_SIZE(uop->src_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real);
if (REG_IS_Q(dest_size) && REG_IS_Q(src_size_a) && REG_IS_Q(src_size_b))
{
host_arm_VMULL_S16(block, REG_Q_TEMP, src_reg_a, src_reg_b);
host_arm_VSHRN_32(block, dest_reg, REG_Q_TEMP, 16);
}
else
fatal("PMULHW %02x %02x %02x\n", uop->dest_reg_a_real, uop->src_reg_a_real, uop->src_reg_b_real);
return 0;
}
static int codegen_PMULLW(codeblock_t *block, uop_t *uop)
{
int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_a = HOST_REG_GET(uop->src_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real);
int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_a = IREG_GET_SIZE(uop->src_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real);
if (REG_IS_Q(dest_size) && REG_IS_Q(src_size_a) && REG_IS_Q(src_size_b))
{
host_arm_VMUL_S16(block, dest_reg, src_reg_a, src_reg_b);
}
else
fatal("PMULLW %02x %02x %02x\n", uop->dest_reg_a_real, uop->src_reg_a_real, uop->src_reg_b_real);
return 0;
}
static int codegen_PSLLW_IMM(codeblock_t *block, uop_t *uop)
{
int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg = HOST_REG_GET(uop->src_reg_a_real);
int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size = IREG_GET_SIZE(uop->src_reg_a_real);
if (REG_IS_Q(dest_size) && REG_IS_Q(src_size))
{
if (uop->imm_data == 0)
host_arm_VMOV_D_D(block, dest_reg, src_reg);
else if (uop->imm_data > 15)
host_arm_VEOR_D(block, dest_reg, dest_reg, dest_reg);
else
host_arm_VSHL_D_IMM_16(block, dest_reg, src_reg, uop->imm_data);
}
else
fatal("PSLLW_IMM %02x %02x\n", uop->dest_reg_a_real, uop->src_reg_a_real);
return 0;
}
static int codegen_PSLLD_IMM(codeblock_t *block, uop_t *uop)
{
int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg = HOST_REG_GET(uop->src_reg_a_real);
int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size = IREG_GET_SIZE(uop->src_reg_a_real);
if (REG_IS_Q(dest_size) && REG_IS_Q(src_size))
{
if (uop->imm_data == 0)
host_arm_VMOV_D_D(block, dest_reg, src_reg);
else if (uop->imm_data > 31)
host_arm_VEOR_D(block, dest_reg, dest_reg, dest_reg);
else
host_arm_VSHL_D_IMM_32(block, dest_reg, src_reg, uop->imm_data);
}
else
fatal("PSLLD_IMM %02x %02x\n", uop->dest_reg_a_real, uop->src_reg_a_real);
return 0;
}
static int codegen_PSLLQ_IMM(codeblock_t *block, uop_t *uop)
{
int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg = HOST_REG_GET(uop->src_reg_a_real);
int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size = IREG_GET_SIZE(uop->src_reg_a_real);
if (REG_IS_Q(dest_size) && REG_IS_Q(src_size))
{
if (uop->imm_data == 0)
host_arm_VMOV_D_D(block, dest_reg, src_reg);
else if (uop->imm_data > 63)
host_arm_VEOR_D(block, dest_reg, dest_reg, dest_reg);
else
host_arm_VSHL_D_IMM_64(block, dest_reg, src_reg, uop->imm_data);
}
else
fatal("PSLLQ_IMM %02x %02x\n", uop->dest_reg_a_real, uop->src_reg_a_real);
return 0;
}
static int codegen_PSRAW_IMM(codeblock_t *block, uop_t *uop)
{
int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg = HOST_REG_GET(uop->src_reg_a_real);
int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size = IREG_GET_SIZE(uop->src_reg_a_real);
if (REG_IS_Q(dest_size) && REG_IS_Q(src_size))
{
if (uop->imm_data == 0)
host_arm_VMOV_D_D(block, dest_reg, src_reg);
else if (uop->imm_data > 15)
host_arm_VSHR_D_S16(block, dest_reg, src_reg, 15);
else
host_arm_VSHR_D_S16(block, dest_reg, src_reg, uop->imm_data);
}
else
fatal("PSRAW_IMM %02x %02x\n", uop->dest_reg_a_real, uop->src_reg_a_real);
return 0;
}
static int codegen_PSRAD_IMM(codeblock_t *block, uop_t *uop)
{
int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg = HOST_REG_GET(uop->src_reg_a_real);
int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size = IREG_GET_SIZE(uop->src_reg_a_real);
if (REG_IS_Q(dest_size) && REG_IS_Q(src_size))
{
if (uop->imm_data == 0)
host_arm_VMOV_D_D(block, dest_reg, src_reg);
else if (uop->imm_data > 31)
host_arm_VSHR_D_S32(block, dest_reg, src_reg, 31);
else
host_arm_VSHR_D_S32(block, dest_reg, src_reg, uop->imm_data);
}
else
fatal("PSRAD_IMM %02x %02x\n", uop->dest_reg_a_real, uop->src_reg_a_real);
return 0;
}
static int codegen_PSRAQ_IMM(codeblock_t *block, uop_t *uop)
{
int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg = HOST_REG_GET(uop->src_reg_a_real);
int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size = IREG_GET_SIZE(uop->src_reg_a_real);
if (REG_IS_Q(dest_size) && REG_IS_Q(src_size))
{
if (uop->imm_data == 0)
host_arm_VMOV_D_D(block, dest_reg, src_reg);
else if (uop->imm_data > 63)
host_arm_VSHR_D_S64(block, dest_reg, src_reg, 63);
else
host_arm_VSHR_D_S64(block, dest_reg, src_reg, uop->imm_data);
}
else
fatal("PSRAQ_IMM %02x %02x\n", uop->dest_reg_a_real, uop->src_reg_a_real);
return 0;
}
static int codegen_PSRLW_IMM(codeblock_t *block, uop_t *uop)
{
int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg = HOST_REG_GET(uop->src_reg_a_real);
int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size = IREG_GET_SIZE(uop->src_reg_a_real);
if (REG_IS_Q(dest_size) && REG_IS_Q(src_size))
{
if (uop->imm_data == 0)
host_arm_VMOV_D_D(block, dest_reg, src_reg);
else if (uop->imm_data > 15)
host_arm_VEOR_D(block, dest_reg, dest_reg, dest_reg);
else
host_arm_VSHR_D_U16(block, dest_reg, src_reg, uop->imm_data);
}
else
fatal("PSRLW_IMM %02x %02x\n", uop->dest_reg_a_real, uop->src_reg_a_real);
return 0;
}
static int codegen_PSRLD_IMM(codeblock_t *block, uop_t *uop)
{
int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg = HOST_REG_GET(uop->src_reg_a_real);
int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size = IREG_GET_SIZE(uop->src_reg_a_real);
if (REG_IS_Q(dest_size) && REG_IS_Q(src_size))
{
if (uop->imm_data == 0)
host_arm_VMOV_D_D(block, dest_reg, src_reg);
else if (uop->imm_data > 31)
host_arm_VEOR_D(block, dest_reg, dest_reg, dest_reg);
else
host_arm_VSHR_D_U32(block, dest_reg, src_reg, uop->imm_data);
}
else
fatal("PSRLD_IMM %02x %02x\n", uop->dest_reg_a_real, uop->src_reg_a_real);
return 0;
}
static int codegen_PSRLQ_IMM(codeblock_t *block, uop_t *uop)
{
int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg = HOST_REG_GET(uop->src_reg_a_real);
int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size = IREG_GET_SIZE(uop->src_reg_a_real);
if (REG_IS_Q(dest_size) && REG_IS_Q(src_size))
{
if (uop->imm_data == 0)
host_arm_VMOV_D_D(block, dest_reg, src_reg);
else if (uop->imm_data > 63)
host_arm_VEOR_D(block, dest_reg, dest_reg, dest_reg);
else
host_arm_VSHR_D_U64(block, dest_reg, src_reg, uop->imm_data);
}
else
fatal("PSRLQ_IMM %02x %02x\n", uop->dest_reg_a_real, uop->src_reg_a_real);
return 0;
}
static int codegen_PSUBB(codeblock_t *block, uop_t *uop)
{
int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_a = HOST_REG_GET(uop->src_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real);
int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_a = IREG_GET_SIZE(uop->src_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real);
if (REG_IS_Q(dest_size) && REG_IS_Q(src_size_a) && REG_IS_Q(src_size_b))
{
host_arm_VSUB_I8(block, dest_reg, src_reg_a, src_reg_b);
}
else
fatal("PSUBB %02x %02x %02x\n", uop->dest_reg_a_real, uop->src_reg_a_real, uop->src_reg_b_real);
return 0;
}
static int codegen_PSUBW(codeblock_t *block, uop_t *uop)
{
int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_a = HOST_REG_GET(uop->src_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real);
int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_a = IREG_GET_SIZE(uop->src_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real);
if (REG_IS_Q(dest_size) && REG_IS_Q(src_size_a) && REG_IS_Q(src_size_b))
{
host_arm_VSUB_I16(block, dest_reg, src_reg_a, src_reg_b);
}
else
fatal("PSUBW %02x %02x %02x\n", uop->dest_reg_a_real, uop->src_reg_a_real, uop->src_reg_b_real);
return 0;
}
static int codegen_PSUBD(codeblock_t *block, uop_t *uop)
{
int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_a = HOST_REG_GET(uop->src_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real);
int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_a = IREG_GET_SIZE(uop->src_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real);
if (REG_IS_Q(dest_size) && REG_IS_Q(src_size_a) && REG_IS_Q(src_size_b))
{
host_arm_VSUB_I32(block, dest_reg, src_reg_a, src_reg_b);
}
else
fatal("PSUBD %02x %02x %02x\n", uop->dest_reg_a_real, uop->src_reg_a_real, uop->src_reg_b_real);
return 0;
}
static int codegen_PSUBSB(codeblock_t *block, uop_t *uop)
{
int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_a = HOST_REG_GET(uop->src_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real);
int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_a = IREG_GET_SIZE(uop->src_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real);
if (REG_IS_Q(dest_size) && REG_IS_Q(src_size_a) && REG_IS_Q(src_size_b))
{
host_arm_VQSUB_S8(block, dest_reg, src_reg_a, src_reg_b);
}
else
fatal("PSUBSB %02x %02x %02x\n", uop->dest_reg_a_real, uop->src_reg_a_real, uop->src_reg_b_real);
return 0;
}
static int codegen_PSUBSW(codeblock_t *block, uop_t *uop)
{
int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_a = HOST_REG_GET(uop->src_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real);
int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_a = IREG_GET_SIZE(uop->src_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real);
if (REG_IS_Q(dest_size) && REG_IS_Q(src_size_a) && REG_IS_Q(src_size_b))
{
host_arm_VQSUB_S16(block, dest_reg, src_reg_a, src_reg_b);
}
else
fatal("PSUBSW %02x %02x %02x\n", uop->dest_reg_a_real, uop->src_reg_a_real, uop->src_reg_b_real);
return 0;
}
static int codegen_PSUBUSB(codeblock_t *block, uop_t *uop)
{
int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_a = HOST_REG_GET(uop->src_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real);
int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_a = IREG_GET_SIZE(uop->src_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real);
if (REG_IS_Q(dest_size) && REG_IS_Q(src_size_a) && REG_IS_Q(src_size_b))
{
host_arm_VQSUB_U8(block, dest_reg, src_reg_a, src_reg_b);
}
else
fatal("PSUBUSB %02x %02x %02x\n", uop->dest_reg_a_real, uop->src_reg_a_real, uop->src_reg_b_real);
return 0;
}
static int codegen_PSUBUSW(codeblock_t *block, uop_t *uop)
{
int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_a = HOST_REG_GET(uop->src_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real);
int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_a = IREG_GET_SIZE(uop->src_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real);
if (REG_IS_Q(dest_size) && REG_IS_Q(src_size_a) && REG_IS_Q(src_size_b))
{
host_arm_VQSUB_U16(block, dest_reg, src_reg_a, src_reg_b);
}
else
fatal("PSUBUSW %02x %02x %02x\n", uop->dest_reg_a_real, uop->src_reg_a_real, uop->src_reg_b_real);
return 0;
}
static int codegen_PUNPCKHBW(codeblock_t *block, uop_t *uop)
{
int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_a = HOST_REG_GET(uop->src_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real);
int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_a = IREG_GET_SIZE(uop->src_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real);
if (REG_IS_Q(dest_size) && REG_IS_Q(src_size_a) && REG_IS_Q(src_size_b))
{
host_arm_VMOV_D_D(block, REG_D_TEMP, src_reg_b);
if (dest_reg != src_reg_a)
host_arm_VMOV_D_D(block, dest_reg, src_reg_a);
host_arm_VZIP_D8(block, dest_reg, REG_D_TEMP);
host_arm_VMOV_D_D(block, dest_reg, REG_D_TEMP);
}
else
fatal("PUNPCKHBW %02x %02x %02x\n", uop->dest_reg_a_real, uop->src_reg_a_real, uop->src_reg_b_real);
return 0;
}
static int codegen_PUNPCKHWD(codeblock_t *block, uop_t *uop)
{
int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_a = HOST_REG_GET(uop->src_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real);
int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_a = IREG_GET_SIZE(uop->src_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real);
if (REG_IS_Q(dest_size) && REG_IS_Q(src_size_a) && REG_IS_Q(src_size_b))
{
host_arm_VMOV_D_D(block, REG_D_TEMP, src_reg_b);
if (dest_reg != src_reg_a)
host_arm_VMOV_D_D(block, dest_reg, src_reg_a);
host_arm_VZIP_D16(block, dest_reg, REG_D_TEMP);
host_arm_VMOV_D_D(block, dest_reg, REG_D_TEMP);
}
else
fatal("PUNPCKHWD %02x %02x %02x\n", uop->dest_reg_a_real, uop->src_reg_a_real, uop->src_reg_b_real);
return 0;
}
static int codegen_PUNPCKHDQ(codeblock_t *block, uop_t *uop)
{
int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_a = HOST_REG_GET(uop->src_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real);
int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_a = IREG_GET_SIZE(uop->src_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real);
if (REG_IS_Q(dest_size) && REG_IS_Q(src_size_a) && REG_IS_Q(src_size_b))
{
host_arm_VMOV_D_D(block, REG_D_TEMP, src_reg_b);
if (dest_reg != src_reg_a)
host_arm_VMOV_D_D(block, dest_reg, src_reg_a);
host_arm_VZIP_D32(block, dest_reg, REG_D_TEMP);
host_arm_VMOV_D_D(block, dest_reg, REG_D_TEMP);
}
else
fatal("PUNPCKHDQ %02x %02x %02x\n", uop->dest_reg_a_real, uop->src_reg_a_real, uop->src_reg_b_real);
return 0;
}
static int codegen_PUNPCKLBW(codeblock_t *block, uop_t *uop)
{
int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_a = HOST_REG_GET(uop->src_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real);
int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_a = IREG_GET_SIZE(uop->src_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real);
if (REG_IS_Q(dest_size) && REG_IS_Q(src_size_a) && REG_IS_Q(src_size_b))
{
host_arm_VMOV_D_D(block, REG_D_TEMP, src_reg_b);
if (dest_reg != src_reg_a)
host_arm_VMOV_D_D(block, dest_reg, src_reg_a);
host_arm_VZIP_D8(block, dest_reg, REG_D_TEMP);
}
else
fatal("PUNPCKLBW %02x %02x %02x\n", uop->dest_reg_a_real, uop->src_reg_a_real, uop->src_reg_b_real);
return 0;
}
static int codegen_PUNPCKLWD(codeblock_t *block, uop_t *uop)
{
int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_a = HOST_REG_GET(uop->src_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real);
int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_a = IREG_GET_SIZE(uop->src_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real);
if (REG_IS_Q(dest_size) && REG_IS_Q(src_size_a) && REG_IS_Q(src_size_b))
{
host_arm_VMOV_D_D(block, REG_D_TEMP, src_reg_b);
if (dest_reg != src_reg_a)
host_arm_VMOV_D_D(block, dest_reg, src_reg_a);
host_arm_VZIP_D16(block, dest_reg, REG_D_TEMP);
}
else
fatal("PUNPCKLWD %02x %02x %02x\n", uop->dest_reg_a_real, uop->src_reg_a_real, uop->src_reg_b_real);
return 0;
}
static int codegen_PUNPCKLDQ(codeblock_t *block, uop_t *uop)
{
int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_a = HOST_REG_GET(uop->src_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real);
int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_a = IREG_GET_SIZE(uop->src_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real);
if (REG_IS_Q(dest_size) && REG_IS_Q(src_size_a) && REG_IS_Q(src_size_b))
{
host_arm_VMOV_D_D(block, REG_D_TEMP, src_reg_b);
if (dest_reg != src_reg_a)
host_arm_VMOV_D_D(block, dest_reg, src_reg_a);
host_arm_VZIP_D32(block, dest_reg, REG_D_TEMP);
}
else
fatal("PUNPCKLDQ %02x %02x %02x\n", uop->dest_reg_a_real, uop->src_reg_a_real, uop->src_reg_b_real);
return 0;
}
static int codegen_ROL(codeblock_t *block, uop_t *uop)
{
int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg = HOST_REG_GET(uop->src_reg_a_real), shift_reg = HOST_REG_GET(uop->src_reg_b_real);
int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size = IREG_GET_SIZE(uop->src_reg_a_real);
if (REG_IS_L(dest_size) && REG_IS_L(src_size))
{
host_arm_RSB_IMM(block, REG_TEMP2, shift_reg, 32);
host_arm_MOV_REG_ROR_REG(block, dest_reg, src_reg, REG_TEMP2);
}
else if (REG_IS_W(dest_size) && REG_IS_W(src_size))
{
host_arm_UXTH(block, REG_TEMP, src_reg, 0);
host_arm_RSB_IMM(block, REG_TEMP2, shift_reg, 16);
host_arm_ORR_REG_LSL(block, REG_TEMP, REG_TEMP, REG_TEMP, 16);
host_arm_MOV_REG_ROR_REG(block, REG_TEMP, REG_TEMP, REG_TEMP2);
host_arm_BFI(block, dest_reg, REG_TEMP, 0, 16);
}
else if (REG_IS_B(dest_size) && REG_IS_B(src_size))
{
host_arm_RSB_IMM(block, REG_TEMP2, shift_reg, 8);
host_arm_UXTB(block, REG_TEMP, src_reg, 0);
host_arm_AND_IMM(block, REG_TEMP2, REG_TEMP2, 7);
host_arm_ORR_REG_LSL(block, REG_TEMP, REG_TEMP, REG_TEMP, 8);
host_arm_MOV_REG_LSR_REG(block, REG_TEMP, REG_TEMP, REG_TEMP2);
host_arm_BFI(block, dest_reg, REG_TEMP, 0, 8);
}
else if (REG_IS_BH(dest_size) && REG_IS_BH(src_size))
{
host_arm_RSB_IMM(block, REG_TEMP2, shift_reg, 8);
host_arm_UXTB(block, REG_TEMP, src_reg, 8);
host_arm_AND_IMM(block, REG_TEMP2, REG_TEMP2, 7);
host_arm_ORR_REG_LSL(block, REG_TEMP, REG_TEMP, REG_TEMP, 8);
host_arm_MOV_REG_LSR_REG(block, REG_TEMP, REG_TEMP, REG_TEMP2);
host_arm_BFI(block, dest_reg, REG_TEMP, 8, 8);
}
else
fatal("ROL %02x %02x\n", uop->dest_reg_a_real, uop->src_reg_a_real);
return 0;
}
static int codegen_ROL_IMM(codeblock_t *block, uop_t *uop)
{
int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg = HOST_REG_GET(uop->src_reg_a_real);
int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size = IREG_GET_SIZE(uop->src_reg_a_real);
if (REG_IS_L(dest_size) && REG_IS_L(src_size))
{
if (!(uop->imm_data & 31))
{
if (src_reg != dest_reg)
host_arm_MOV_REG(block, dest_reg, src_reg);
}
else
{
host_arm_MOV_REG_ROR(block, dest_reg, src_reg, 32 - (uop->imm_data & 31));
}
}
else if (REG_IS_W(dest_size) && REG_IS_W(src_size))
{
if ((uop->imm_data & 15) == 0)
{
if (src_reg != dest_reg)
host_arm_BFI(block, dest_reg, src_reg, 0, 16);
}
else
{
host_arm_UXTH(block, REG_TEMP, src_reg, 0);
host_arm_ORR_REG_LSL(block, REG_TEMP, REG_TEMP, REG_TEMP, 16);
host_arm_MOV_REG_LSR(block, REG_TEMP, REG_TEMP, 16-(uop->imm_data & 15));
host_arm_BFI(block, dest_reg, REG_TEMP, 0, 16);
}
}
else if (REG_IS_B(dest_size) && REG_IS_B(src_size))
{
if ((uop->imm_data & 7) == 0)
{
if (src_reg != dest_reg)
host_arm_BFI(block, dest_reg, src_reg, 0, 8);
}
else
{
host_arm_UXTB(block, REG_TEMP, src_reg, 0);
host_arm_ORR_REG_LSL(block, REG_TEMP, REG_TEMP, REG_TEMP, 8);
host_arm_MOV_REG_LSR(block, REG_TEMP, REG_TEMP, 8-(uop->imm_data & 7));
host_arm_BFI(block, dest_reg, REG_TEMP, 0, 8);
}
}
else if (REG_IS_BH(dest_size) && REG_IS_BH(src_size))
{
if ((uop->imm_data & 7) == 0)
{
if (src_reg != dest_reg)
fatal("ROL_IMM %02x %02x\n", uop->dest_reg_a_real, uop->src_reg_a_real);
}
else
{
host_arm_UXTB(block, REG_TEMP, src_reg, 8);
host_arm_ORR_REG_LSL(block, REG_TEMP, REG_TEMP, REG_TEMP, 8);
host_arm_MOV_REG_LSR(block, REG_TEMP, REG_TEMP, 8-(uop->imm_data & 7));
host_arm_BFI(block, dest_reg, REG_TEMP, 8, 8);
}
}
else
fatal("ROL_IMM %02x %02x\n", uop->dest_reg_a_real, uop->src_reg_a_real);
return 0;
}
static int codegen_ROR(codeblock_t *block, uop_t *uop)
{
int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg = HOST_REG_GET(uop->src_reg_a_real), shift_reg = HOST_REG_GET(uop->src_reg_b_real);
int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size = IREG_GET_SIZE(uop->src_reg_a_real);
if (REG_IS_L(dest_size) && REG_IS_L(src_size))
{
host_arm_MOV_REG_ROR_REG(block, dest_reg, src_reg, shift_reg);
}
else if (REG_IS_W(dest_size) && REG_IS_W(src_size))
{
host_arm_UXTH(block, REG_TEMP, src_reg, 0);
host_arm_AND_IMM(block, REG_TEMP2, shift_reg, 15);
host_arm_ORR_REG_LSL(block, REG_TEMP, REG_TEMP, REG_TEMP, 16);
host_arm_MOV_REG_LSR_REG(block, REG_TEMP, REG_TEMP, REG_TEMP2);
host_arm_BFI(block, dest_reg, REG_TEMP, 0, 16);
}
else if (REG_IS_B(dest_size) && REG_IS_B(src_size))
{
host_arm_UXTB(block, REG_TEMP, src_reg, 0);
host_arm_AND_IMM(block, REG_TEMP2, shift_reg, 7);
host_arm_ORR_REG_LSL(block, REG_TEMP, REG_TEMP, REG_TEMP, 8);
host_arm_MOV_REG_LSR_REG(block, REG_TEMP, REG_TEMP, REG_TEMP2);
host_arm_BFI(block, dest_reg, REG_TEMP, 0, 8);
}
else if (REG_IS_BH(dest_size) && REG_IS_BH(src_size))
{
host_arm_UXTB(block, REG_TEMP, src_reg, 8);
host_arm_AND_IMM(block, REG_TEMP2, shift_reg, 7);
host_arm_ORR_REG_LSL(block, REG_TEMP, REG_TEMP, REG_TEMP, 8);
host_arm_MOV_REG_LSR_REG(block, REG_TEMP, REG_TEMP, REG_TEMP2);
host_arm_BFI(block, dest_reg, REG_TEMP, 8, 8);
}
else
fatal("ROR %02x %02x\n", uop->dest_reg_a_real, uop->src_reg_a_real);
return 0;
}
static int codegen_ROR_IMM(codeblock_t *block, uop_t *uop)
{
int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg = HOST_REG_GET(uop->src_reg_a_real);
int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size = IREG_GET_SIZE(uop->src_reg_a_real);
if (REG_IS_L(dest_size) && REG_IS_L(src_size))
{
if (!(uop->imm_data & 31))
{
if (src_reg != dest_reg)
host_arm_MOV_REG(block, dest_reg, src_reg);
}
else
{
host_arm_MOV_REG_ROR(block, dest_reg, src_reg, uop->imm_data & 31);
}
}
else if (REG_IS_W(dest_size) && REG_IS_W(src_size))
{
if ((uop->imm_data & 15) == 0)
{
if (src_reg != dest_reg)
fatal("ROR_IMM %02x %02x\n", uop->dest_reg_a_real, uop->src_reg_a_real);
}
else
{
host_arm_UXTH(block, REG_TEMP, src_reg, 0);
host_arm_ORR_REG_LSL(block, REG_TEMP, REG_TEMP, REG_TEMP, 16);
host_arm_MOV_REG_LSR(block, REG_TEMP, REG_TEMP, uop->imm_data & 15);
host_arm_BFI(block, dest_reg, REG_TEMP, 0, 16);
}
}
else if (REG_IS_B(dest_size) && REG_IS_B(src_size))
{
if ((uop->imm_data & 7) == 0)
{
if (src_reg != dest_reg)
fatal("ROR_IMM %02x %02x\n", uop->dest_reg_a_real, uop->src_reg_a_real);
}
else
{
host_arm_UXTB(block, REG_TEMP, src_reg, 0);
host_arm_ORR_REG_LSL(block, REG_TEMP, REG_TEMP, REG_TEMP, 8);
host_arm_MOV_REG_LSR(block, REG_TEMP, REG_TEMP, uop->imm_data & 7);
host_arm_BFI(block, dest_reg, REG_TEMP, 0, 8);
}
}
else if (REG_IS_BH(dest_size) && REG_IS_BH(src_size))
{
if ((uop->imm_data & 7) == 0)
{
if (src_reg != dest_reg)
fatal("ROR_IMM %02x %02x\n", uop->dest_reg_a_real, uop->src_reg_a_real);
}
else
{
host_arm_UXTB(block, REG_TEMP, src_reg, 8);
host_arm_ORR_REG_LSL(block, REG_TEMP, REG_TEMP, REG_TEMP, 8);
host_arm_MOV_REG_LSR(block, REG_TEMP, REG_TEMP, uop->imm_data & 7);
host_arm_BFI(block, dest_reg, REG_TEMP, 8, 8);
}
}
else
fatal("ROR_IMM %02x %02x\n", uop->dest_reg_a_real, uop->src_reg_a_real);
return 0;
}
static int codegen_SAR(codeblock_t *block, uop_t *uop)
{
int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg = HOST_REG_GET(uop->src_reg_a_real), shift_reg = HOST_REG_GET(uop->src_reg_b_real);
int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size = IREG_GET_SIZE(uop->src_reg_a_real);
if (REG_IS_L(dest_size) && REG_IS_L(src_size))
{
host_arm_MOV_REG_ASR_REG(block, dest_reg, src_reg, shift_reg);
}
else if (REG_IS_W(dest_size) && REG_IS_W(src_size))
{
host_arm_MOV_REG_LSL(block, REG_TEMP, src_reg, 16);
host_arm_MOV_REG_ASR_REG(block, REG_TEMP, REG_TEMP, shift_reg);
host_arm_UXTH(block, REG_TEMP, REG_TEMP, 16);
host_arm_BFI(block, dest_reg, REG_TEMP, 0, 16);
}
else if (REG_IS_B(dest_size) && REG_IS_B(src_size))
{
host_arm_MOV_REG_LSL(block, REG_TEMP, src_reg, 24);
host_arm_MOV_REG_ASR_REG(block, REG_TEMP, REG_TEMP, shift_reg);
host_arm_UXTB(block, REG_TEMP, REG_TEMP, 24);
host_arm_BFI(block, dest_reg, REG_TEMP, 0, 8);
}
else if (REG_IS_BH(dest_size) && REG_IS_BH(src_size))
{
host_arm_MOV_REG_LSL(block, REG_TEMP, src_reg, 16);
host_arm_MOV_REG_ASR_REG(block, REG_TEMP, REG_TEMP, shift_reg);
host_arm_UXTB(block, REG_TEMP, REG_TEMP, 24);
host_arm_BFI(block, dest_reg, REG_TEMP, 8, 8);
}
else
fatal("SAR %02x %02x\n", uop->dest_reg_a_real, uop->src_reg_a_real);
return 0;
}
static int codegen_SAR_IMM(codeblock_t *block, uop_t *uop)
{
int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg = HOST_REG_GET(uop->src_reg_a_real);
int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size = IREG_GET_SIZE(uop->src_reg_a_real);
if (REG_IS_L(dest_size) && REG_IS_L(src_size))
{
host_arm_MOV_REG_ASR(block, dest_reg, src_reg, uop->imm_data);
}
else if (REG_IS_W(dest_size) && REG_IS_W(src_size))
{
host_arm_MOV_REG_LSL(block, REG_TEMP, src_reg, 16);
host_arm_MOV_REG_ASR(block, REG_TEMP, REG_TEMP, uop->imm_data);
host_arm_UXTH(block, REG_TEMP, REG_TEMP, 16);
host_arm_BFI(block, dest_reg, REG_TEMP, 0, 16);
}
else if (REG_IS_B(dest_size) && REG_IS_B(src_size))
{
host_arm_MOV_REG_LSL(block, REG_TEMP, src_reg, 24);
host_arm_MOV_REG_ASR(block, REG_TEMP, REG_TEMP, uop->imm_data);
host_arm_UXTB(block, REG_TEMP, REG_TEMP, 24);
host_arm_BFI(block, dest_reg, REG_TEMP, 0, 8);
}
else if (REG_IS_BH(dest_size) && REG_IS_BH(src_size))
{
host_arm_MOV_REG_LSL(block, REG_TEMP, src_reg, 16);
host_arm_MOV_REG_ASR(block, REG_TEMP, REG_TEMP, uop->imm_data);
host_arm_UXTB(block, REG_TEMP, REG_TEMP, 24);
host_arm_BFI(block, dest_reg, REG_TEMP, 8, 8);
}
else
fatal("SAR_IMM %02x %02x\n", uop->dest_reg_a_real, uop->src_reg_a_real);
return 0;
}
static int codegen_SHL(codeblock_t *block, uop_t *uop)
{
int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg = HOST_REG_GET(uop->src_reg_a_real), shift_reg = HOST_REG_GET(uop->src_reg_b_real);
int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size = IREG_GET_SIZE(uop->src_reg_a_real);
if (REG_IS_L(dest_size) && REG_IS_L(src_size))
{
host_arm_MOV_REG_LSL_REG(block, dest_reg, src_reg, shift_reg);
}
else if (REG_IS_W(dest_size) && REG_IS_W(src_size))
{
host_arm_MOV_REG_LSL_REG(block, REG_TEMP, src_reg, shift_reg);
host_arm_BFI(block, dest_reg, REG_TEMP, 0, 16);
}
else if (REG_IS_B(dest_size) && REG_IS_B(src_size))
{
host_arm_MOV_REG_LSL_REG(block, REG_TEMP, src_reg, shift_reg);
host_arm_BFI(block, dest_reg, REG_TEMP, 0, 8);
}
else if (REG_IS_BH(dest_size) && REG_IS_BH(src_size))
{
host_arm_UXTB(block, REG_TEMP, src_reg, 8);
host_arm_MOV_REG_LSL_REG(block, REG_TEMP, REG_TEMP, shift_reg);
host_arm_BFI(block, dest_reg, REG_TEMP, 8, 8);
}
else
fatal("SHL %02x %02x\n", uop->dest_reg_a_real, uop->src_reg_a_real);
return 0;
}
static int codegen_SHL_IMM(codeblock_t *block, uop_t *uop)
{
int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg = HOST_REG_GET(uop->src_reg_a_real);
int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size = IREG_GET_SIZE(uop->src_reg_a_real);
if (REG_IS_L(dest_size) && REG_IS_L(src_size))
{
host_arm_MOV_REG_LSL(block, dest_reg, src_reg, uop->imm_data);
}
else if (REG_IS_W(dest_size) && REG_IS_W(src_size))
{
host_arm_MOV_REG_LSL(block, REG_TEMP, src_reg, uop->imm_data);
host_arm_BFI(block, dest_reg, REG_TEMP, 0, 16);
}
else if (REG_IS_B(dest_size) && REG_IS_B(src_size))
{
host_arm_MOV_REG_LSL(block, REG_TEMP, src_reg, uop->imm_data);
host_arm_BFI(block, dest_reg, REG_TEMP, 0, 8);
}
else if (REG_IS_BH(dest_size) && REG_IS_BH(src_size))
{
host_arm_UXTB(block, REG_TEMP, src_reg, 8);
host_arm_MOV_REG_LSL(block, REG_TEMP, REG_TEMP, uop->imm_data);
host_arm_BFI(block, dest_reg, REG_TEMP, 8, 8);
}
else
fatal("SHL_IMM %02x %02x\n", uop->dest_reg_a_real, uop->src_reg_a_real);
return 0;
}
static int codegen_SHR(codeblock_t *block, uop_t *uop)
{
int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg = HOST_REG_GET(uop->src_reg_a_real), shift_reg = HOST_REG_GET(uop->src_reg_b_real);
int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size = IREG_GET_SIZE(uop->src_reg_a_real);
if (REG_IS_L(dest_size) && REG_IS_L(src_size))
{
host_arm_MOV_REG_LSR_REG(block, dest_reg, src_reg, shift_reg);
}
else if (REG_IS_W(dest_size) && REG_IS_W(src_size))
{
host_arm_UXTH(block, REG_TEMP, src_reg, 0);
host_arm_MOV_REG_LSR_REG(block, REG_TEMP, REG_TEMP, shift_reg);
host_arm_BFI(block, dest_reg, REG_TEMP, 0, 16);
}
else if (REG_IS_B(dest_size) && REG_IS_B(src_size))
{
host_arm_UXTB(block, REG_TEMP, src_reg, 0);
host_arm_MOV_REG_LSR_REG(block, REG_TEMP, REG_TEMP, shift_reg);
host_arm_BFI(block, dest_reg, REG_TEMP, 0, 8);
}
else if (REG_IS_BH(dest_size) && REG_IS_BH(src_size))
{
host_arm_UXTB(block, REG_TEMP, src_reg, 8);
host_arm_MOV_REG_LSR_REG(block, REG_TEMP, REG_TEMP, shift_reg);
host_arm_BFI(block, dest_reg, REG_TEMP, 8, 8);
}
else
fatal("SHR %02x %02x\n", uop->dest_reg_a_real, uop->src_reg_a_real);
return 0;
}
static int codegen_SHR_IMM(codeblock_t *block, uop_t *uop)
{
int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg = HOST_REG_GET(uop->src_reg_a_real);
int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size = IREG_GET_SIZE(uop->src_reg_a_real);
if (REG_IS_L(dest_size) && REG_IS_L(src_size))
{
host_arm_MOV_REG_LSR(block, dest_reg, src_reg, uop->imm_data);
}
else if (REG_IS_W(dest_size) && REG_IS_W(src_size))
{
host_arm_UXTH(block, REG_TEMP, src_reg, 0);
host_arm_MOV_REG_LSR(block, REG_TEMP, REG_TEMP, uop->imm_data);
host_arm_BFI(block, dest_reg, REG_TEMP, 0, 16);
}
else if (REG_IS_B(dest_size) && REG_IS_B(src_size))
{
host_arm_UXTB(block, REG_TEMP, src_reg, 0);
host_arm_MOV_REG_LSR(block, REG_TEMP, REG_TEMP, uop->imm_data);
host_arm_BFI(block, dest_reg, REG_TEMP, 0, 8);
}
else if (REG_IS_BH(dest_size) && REG_IS_BH(src_size))
{
host_arm_UXTB(block, REG_TEMP, src_reg, 8);
host_arm_MOV_REG_LSR(block, REG_TEMP, REG_TEMP, uop->imm_data);
host_arm_BFI(block, dest_reg, REG_TEMP, 8, 8);
}
else
fatal("SHR_IMM %02x %02x\n", uop->dest_reg_a_real, uop->src_reg_a_real);
return 0;
}
static int codegen_STORE_PTR_IMM(codeblock_t *block, uop_t *uop)
{
host_arm_MOV_IMM(block, REG_R0, uop->imm_data);
if (in_range(uop->p, &cpu_state))
host_arm_STR_IMM(block, REG_R0, REG_CPUSTATE, (uintptr_t)uop->p - (uintptr_t)&cpu_state);
else
fatal("codegen_STORE_PTR_IMM - not in range\n");
return 0;
}
static int codegen_STORE_PTR_IMM_8(codeblock_t *block, uop_t *uop)
{
host_arm_MOV_IMM(block, REG_R0, uop->imm_data);
if (in_range(uop->p, &cpu_state))
host_arm_STRB_IMM(block, REG_R0, REG_CPUSTATE, (uintptr_t)uop->p - (uintptr_t)&cpu_state);
else
fatal("codegen_STORE_PTR_IMM - not in range\n");
return 0;
}
static int codegen_SUB(codeblock_t *block, uop_t *uop)
{
int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_a = HOST_REG_GET(uop->src_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real);
int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_a = IREG_GET_SIZE(uop->src_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real);
if (REG_IS_L(dest_size) && REG_IS_L(src_size_a) && REG_IS_L(src_size_b))
{
host_arm_SUB_REG_LSL(block, dest_reg, src_reg_a, src_reg_b, 0);
}
else if (REG_IS_W(dest_size) && REG_IS_W(src_size_a) && REG_IS_W(src_size_b))
{
host_arm_SUB_REG_LSL(block, REG_TEMP, src_reg_a, src_reg_b, 0);
host_arm_BFI(block, dest_reg, REG_TEMP, 0, 16);
}
else if (REG_IS_B(dest_size) && REG_IS_B(src_size_a) && REG_IS_B(src_size_b))
{
host_arm_SUB_REG_LSL(block, REG_TEMP, src_reg_a, src_reg_b, 0);
host_arm_BFI(block, dest_reg, REG_TEMP, 0, 8);
}
else if (REG_IS_B(dest_size) && REG_IS_B(src_size_a) && REG_IS_BH(src_size_b))
{
host_arm_SUB_REG_LSR(block, REG_TEMP, src_reg_a, src_reg_b, 8);
host_arm_BFI(block, dest_reg, REG_TEMP, 0, 8);
}
else if (REG_IS_B(dest_size) && REG_IS_BH(src_size_a) && REG_IS_B(src_size_b))
{
host_arm_RSB_REG_LSR(block, REG_TEMP, src_reg_b, src_reg_a, 8);
host_arm_BFI(block, dest_reg, REG_TEMP, 0, 8);
}
else if (REG_IS_B(dest_size) && REG_IS_BH(src_size_a) && REG_IS_BH(src_size_b))
{
host_arm_SUB_REG_LSL(block, REG_TEMP, src_reg_a, src_reg_b, 0);
host_arm_MOV_REG_LSR(block, REG_TEMP, REG_TEMP, 8);
host_arm_BFI(block, dest_reg, REG_TEMP, 0, 8);
}
else if (REG_IS_BH(dest_size) && REG_IS_BH(src_size_a) && REG_IS_B(src_size_b))
{
host_arm_RSB_REG_LSR(block, REG_TEMP, src_reg_b, src_reg_a, 8);
host_arm_BFI(block, dest_reg, REG_TEMP, 8, 8);
}
else if (REG_IS_BH(dest_size) && REG_IS_BH(src_size_a) && REG_IS_BH(src_size_b))
{
host_arm_MOV_REG_LSR(block, REG_TEMP, src_reg_a, 8);
host_arm_SUB_REG_LSR(block, REG_TEMP, REG_TEMP, src_reg_b, 8);
host_arm_BFI(block, dest_reg, REG_TEMP, 8, 8);
}
else
fatal("SUB %02x %02x %02x\n", uop->dest_reg_a_real, uop->src_reg_a_real, uop->src_reg_b_real);
return 0;
// host_arm_SUB_REG_LSL(block, uop->dest_reg_a_real, uop->src_reg_a_real, uop->src_reg_b_real, 0);
// return 0;
}
static int codegen_SUB_IMM(codeblock_t *block, uop_t *uop)
{
int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg = HOST_REG_GET(uop->src_reg_a_real);
int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size = IREG_GET_SIZE(uop->src_reg_a_real);
if (REG_IS_L(dest_size) && REG_IS_L(src_size))
{
host_arm_SUB_IMM(block, dest_reg, src_reg, uop->imm_data);
}
else if (REG_IS_W(dest_size) && REG_IS_W(src_size))
{
host_arm_SUB_IMM(block, REG_TEMP, src_reg, uop->imm_data);
host_arm_BFI(block, dest_reg, REG_TEMP, 0, 16);
}
else if (REG_IS_B(dest_size) && REG_IS_B(src_size))
{
host_arm_SUB_IMM(block, REG_TEMP, src_reg, uop->imm_data);
host_arm_BFI(block, dest_reg, REG_TEMP, 0, 8);
}
else if (REG_IS_B(dest_size) && REG_IS_BH(src_size))
{
host_arm_SUB_IMM(block, REG_TEMP, src_reg, uop->imm_data << 8);
host_arm_MOV_REG_LSR(block, REG_TEMP, REG_TEMP, 8);
host_arm_BFI(block, dest_reg, REG_TEMP, 0, 8);
}
else if (REG_IS_BH(dest_size) && REG_IS_BH(src_size))
{
host_arm_SUB_IMM(block, REG_TEMP, src_reg, uop->imm_data << 8);
host_arm_MOV_REG_LSR(block, REG_TEMP, REG_TEMP, 8);
host_arm_BFI(block, dest_reg, REG_TEMP, 8, 8);
}
else
fatal("SUB_IMM %02x %02x\n", uop->dest_reg_a_real, uop->src_reg_a_real);
return 0;
}
static int codegen_TEST_JNS_DEST(codeblock_t *block, uop_t *uop)
{
int src_reg = HOST_REG_GET(uop->src_reg_a_real);
int src_size = IREG_GET_SIZE(uop->src_reg_a_real);
if (REG_IS_L(src_size))
{
host_arm_TST_IMM(block, src_reg, 1 << 31);
}
else if (REG_IS_W(src_size))
{
host_arm_TST_IMM(block, src_reg, 1 << 15);
}
else if (REG_IS_B(src_size))
{
host_arm_TST_IMM(block, src_reg, 1 << 7);
}
else
fatal("TEST_JNS_DEST %02x\n", uop->src_reg_a_real);
uop->p = host_arm_BEQ_(block);
return 0;
}
static int codegen_TEST_JS_DEST(codeblock_t *block, uop_t *uop)
{
int src_reg = HOST_REG_GET(uop->src_reg_a_real);
int src_size = IREG_GET_SIZE(uop->src_reg_a_real);
if (REG_IS_L(src_size))
{
host_arm_TST_IMM(block, src_reg, 1 << 31);
}
else if (REG_IS_W(src_size))
{
host_arm_TST_IMM(block, src_reg, 1 << 15);
}
else if (REG_IS_B(src_size))
{
host_arm_TST_IMM(block, src_reg, 1 << 7);
}
else
fatal("TEST_JS_DEST %02x\n", uop->src_reg_a_real);
uop->p = host_arm_BNE_(block);
return 0;
}
static int codegen_XOR(codeblock_t *block, uop_t *uop)
{
int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_a = HOST_REG_GET(uop->src_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real);
int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_a = IREG_GET_SIZE(uop->src_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real);
if (REG_IS_Q(dest_size) && REG_IS_Q(src_size_a) && REG_IS_Q(src_size_b))
{
host_arm_VEOR_D(block, dest_reg, src_reg_a, src_reg_b);
}
else if (REG_IS_L(dest_size) && REG_IS_L(src_size_a) && REG_IS_L(src_size_b))
{
host_arm_EOR_REG_LSL(block, dest_reg, src_reg_a, src_reg_b, 0);
}
else if (REG_IS_W(dest_size) && REG_IS_W(src_size_a) && REG_IS_W(src_size_b) && dest_reg == src_reg_a)
{
host_arm_UXTH(block, REG_TEMP, src_reg_b, 0);
host_arm_EOR_REG_LSL(block, dest_reg, src_reg_a, REG_TEMP, 0);
}
else if (REG_IS_B(dest_size) && REG_IS_B(src_size_a) && REG_IS_B(src_size_b) && dest_reg == src_reg_a)
{
host_arm_UXTB(block, REG_TEMP, src_reg_b, 0);
host_arm_EOR_REG_LSL(block, dest_reg, src_reg_a, REG_TEMP, 0);
}
else if (REG_IS_B(dest_size) && REG_IS_B(src_size_a) && REG_IS_BH(src_size_b) && dest_reg == src_reg_a)
{
host_arm_UXTB(block, REG_TEMP, src_reg_b, 8);
host_arm_EOR_REG_LSL(block, dest_reg, src_reg_a, REG_TEMP, 0);
}
else if (REG_IS_BH(dest_size) && REG_IS_BH(src_size_a) && REG_IS_B(src_size_b) && dest_reg == src_reg_a)
{
host_arm_UXTB(block, REG_TEMP, src_reg_b, 0);
host_arm_EOR_REG_LSL(block, dest_reg, src_reg_a, REG_TEMP, 8);
}
else if (REG_IS_BH(dest_size) && REG_IS_BH(src_size_a) && REG_IS_BH(src_size_b) && dest_reg == src_reg_a)
{
host_arm_UXTB(block, REG_TEMP, src_reg_b, 8);
host_arm_EOR_REG_LSL(block, dest_reg, src_reg_a, REG_TEMP, 8);
}
else
fatal("XOR %02x %02x %02x\n", uop->dest_reg_a_real, uop->src_reg_a_real, uop->src_reg_b_real);
return 0;
}
static int codegen_XOR_IMM(codeblock_t *block, uop_t *uop)
{
int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg = HOST_REG_GET(uop->src_reg_a_real);
int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size = IREG_GET_SIZE(uop->src_reg_a_real);
if (REG_IS_L(dest_size) && REG_IS_L(src_size))
{
host_arm_EOR_IMM(block, dest_reg, src_reg, uop->imm_data);
}
else if (REG_IS_W(dest_size) && REG_IS_W(src_size) && dest_reg == src_reg)
{
host_arm_EOR_IMM(block, dest_reg, src_reg, uop->imm_data);
}
else if (REG_IS_B(dest_size) && REG_IS_B(src_size) && dest_reg == src_reg)
{
host_arm_EOR_IMM(block, dest_reg, src_reg, uop->imm_data);
}
else if (REG_IS_BH(dest_size) && REG_IS_BH(src_size) && dest_reg == src_reg)
{
host_arm_EOR_IMM(block, dest_reg, src_reg, uop->imm_data << 8);
}
else
fatal("XOR_IMM %02x %02x\n", uop->dest_reg_a_real, uop->src_reg_a_real);
return 0;
}
const uOpFn uop_handlers[UOP_MAX] =
{
[UOP_CALL_FUNC & UOP_MASK] = codegen_CALL_FUNC,
[UOP_CALL_FUNC_RESULT & UOP_MASK] = codegen_CALL_FUNC_RESULT,
[UOP_CALL_INSTRUCTION_FUNC & UOP_MASK] = codegen_CALL_INSTRUCTION_FUNC,
[UOP_JMP & UOP_MASK] = codegen_JMP,
[UOP_LOAD_SEG & UOP_MASK] = codegen_LOAD_SEG,
[UOP_LOAD_FUNC_ARG_0 & UOP_MASK] = codegen_LOAD_FUNC_ARG0,
[UOP_LOAD_FUNC_ARG_1 & UOP_MASK] = codegen_LOAD_FUNC_ARG1,
[UOP_LOAD_FUNC_ARG_2 & UOP_MASK] = codegen_LOAD_FUNC_ARG2,
[UOP_LOAD_FUNC_ARG_3 & UOP_MASK] = codegen_LOAD_FUNC_ARG3,
[UOP_LOAD_FUNC_ARG_0_IMM & UOP_MASK] = codegen_LOAD_FUNC_ARG0_IMM,
[UOP_LOAD_FUNC_ARG_1_IMM & UOP_MASK] = codegen_LOAD_FUNC_ARG1_IMM,
[UOP_LOAD_FUNC_ARG_2_IMM & UOP_MASK] = codegen_LOAD_FUNC_ARG2_IMM,
[UOP_LOAD_FUNC_ARG_3_IMM & UOP_MASK] = codegen_LOAD_FUNC_ARG3_IMM,
[UOP_STORE_P_IMM & UOP_MASK] = codegen_STORE_PTR_IMM,
[UOP_STORE_P_IMM_8 & UOP_MASK] = codegen_STORE_PTR_IMM_8,
[UOP_MEM_LOAD_ABS & UOP_MASK] = codegen_MEM_LOAD_ABS,
[UOP_MEM_LOAD_REG & UOP_MASK] = codegen_MEM_LOAD_REG,
[UOP_MEM_LOAD_SINGLE & UOP_MASK] = codegen_MEM_LOAD_SINGLE,
[UOP_MEM_LOAD_DOUBLE & UOP_MASK] = codegen_MEM_LOAD_DOUBLE,
[UOP_MEM_STORE_ABS & UOP_MASK] = codegen_MEM_STORE_ABS,
[UOP_MEM_STORE_REG & UOP_MASK] = codegen_MEM_STORE_REG,
[UOP_MEM_STORE_IMM_8 & UOP_MASK] = codegen_MEM_STORE_IMM_8,
[UOP_MEM_STORE_IMM_16 & UOP_MASK] = codegen_MEM_STORE_IMM_16,
[UOP_MEM_STORE_IMM_32 & UOP_MASK] = codegen_MEM_STORE_IMM_32,
[UOP_MEM_STORE_SINGLE & UOP_MASK] = codegen_MEM_STORE_SINGLE,
[UOP_MEM_STORE_DOUBLE & UOP_MASK] = codegen_MEM_STORE_DOUBLE,
[UOP_MOV & UOP_MASK] = codegen_MOV,
[UOP_MOV_PTR & UOP_MASK] = codegen_MOV_PTR,
[UOP_MOV_IMM & UOP_MASK] = codegen_MOV_IMM,
[UOP_MOVSX & UOP_MASK] = codegen_MOVSX,
[UOP_MOVZX & UOP_MASK] = codegen_MOVZX,
[UOP_MOV_DOUBLE_INT & UOP_MASK] = codegen_MOV_DOUBLE_INT,
[UOP_MOV_INT_DOUBLE & UOP_MASK] = codegen_MOV_INT_DOUBLE,
[UOP_MOV_INT_DOUBLE_64 & UOP_MASK] = codegen_MOV_INT_DOUBLE_64,
[UOP_MOV_REG_PTR & UOP_MASK] = codegen_MOV_REG_PTR,
[UOP_MOVZX_REG_PTR_8 & UOP_MASK] = codegen_MOVZX_REG_PTR_8,
[UOP_MOVZX_REG_PTR_16 & UOP_MASK] = codegen_MOVZX_REG_PTR_16,
[UOP_ADD & UOP_MASK] = codegen_ADD,
[UOP_ADD_IMM & UOP_MASK] = codegen_ADD_IMM,
[UOP_ADD_LSHIFT & UOP_MASK] = codegen_ADD_LSHIFT,
[UOP_AND & UOP_MASK] = codegen_AND,
[UOP_AND_IMM & UOP_MASK] = codegen_AND_IMM,
[UOP_ANDN & UOP_MASK] = codegen_ANDN,
[UOP_OR & UOP_MASK] = codegen_OR,
[UOP_OR_IMM & UOP_MASK] = codegen_OR_IMM,
[UOP_SUB & UOP_MASK] = codegen_SUB,
[UOP_SUB_IMM & UOP_MASK] = codegen_SUB_IMM,
[UOP_XOR & UOP_MASK] = codegen_XOR,
[UOP_XOR_IMM & UOP_MASK] = codegen_XOR_IMM,
[UOP_SAR & UOP_MASK] = codegen_SAR,
[UOP_SAR_IMM & UOP_MASK] = codegen_SAR_IMM,
[UOP_SHL & UOP_MASK] = codegen_SHL,
[UOP_SHL_IMM & UOP_MASK] = codegen_SHL_IMM,
[UOP_SHR & UOP_MASK] = codegen_SHR,
[UOP_SHR_IMM & UOP_MASK] = codegen_SHR_IMM,
[UOP_ROL & UOP_MASK] = codegen_ROL,
[UOP_ROL_IMM & UOP_MASK] = codegen_ROL_IMM,
[UOP_ROR & UOP_MASK] = codegen_ROR,
[UOP_ROR_IMM & UOP_MASK] = codegen_ROR_IMM,
[UOP_CMP_IMM_JZ & UOP_MASK] = codegen_CMP_IMM_JZ,
[UOP_CMP_JB & UOP_MASK] = codegen_CMP_JB,
[UOP_CMP_JNBE & UOP_MASK] = codegen_CMP_JNBE,
[UOP_CMP_JNB_DEST & UOP_MASK] = codegen_CMP_JNB_DEST,
[UOP_CMP_JNBE_DEST & UOP_MASK] = codegen_CMP_JNBE_DEST,
[UOP_CMP_JNL_DEST & UOP_MASK] = codegen_CMP_JNL_DEST,
[UOP_CMP_JNLE_DEST & UOP_MASK] = codegen_CMP_JNLE_DEST,
[UOP_CMP_JNO_DEST & UOP_MASK] = codegen_CMP_JNO_DEST,
[UOP_CMP_JNZ_DEST & UOP_MASK] = codegen_CMP_JNZ_DEST,
[UOP_CMP_JB_DEST & UOP_MASK] = codegen_CMP_JB_DEST,
[UOP_CMP_JBE_DEST & UOP_MASK] = codegen_CMP_JBE_DEST,
[UOP_CMP_JL_DEST & UOP_MASK] = codegen_CMP_JL_DEST,
[UOP_CMP_JLE_DEST & UOP_MASK] = codegen_CMP_JLE_DEST,
[UOP_CMP_JO_DEST & UOP_MASK] = codegen_CMP_JO_DEST,
[UOP_CMP_JZ_DEST & UOP_MASK] = codegen_CMP_JZ_DEST,
[UOP_CMP_IMM_JNZ_DEST & UOP_MASK] = codegen_CMP_IMM_JNZ_DEST,
[UOP_CMP_IMM_JZ_DEST & UOP_MASK] = codegen_CMP_IMM_JZ_DEST,
[UOP_TEST_JNS_DEST & UOP_MASK] = codegen_TEST_JNS_DEST,
[UOP_TEST_JS_DEST & UOP_MASK] = codegen_TEST_JS_DEST,
[UOP_FP_ENTER & UOP_MASK] = codegen_FP_ENTER,
[UOP_MMX_ENTER & UOP_MASK] = codegen_MMX_ENTER,
[UOP_FADD & UOP_MASK] = codegen_FADD,
[UOP_FCOM & UOP_MASK] = codegen_FCOM,
[UOP_FDIV & UOP_MASK] = codegen_FDIV,
[UOP_FMUL & UOP_MASK] = codegen_FMUL,
[UOP_FSUB & UOP_MASK] = codegen_FSUB,
[UOP_FABS & UOP_MASK] = codegen_FABS,
[UOP_FCHS & UOP_MASK] = codegen_FCHS,
[UOP_FSQRT & UOP_MASK] = codegen_FSQRT,
[UOP_FTST & UOP_MASK] = codegen_FTST,
[UOP_PACKSSWB & UOP_MASK] = codegen_PACKSSWB,
[UOP_PACKSSDW & UOP_MASK] = codegen_PACKSSDW,
[UOP_PACKUSWB & UOP_MASK] = codegen_PACKUSWB,
[UOP_PADDB & UOP_MASK] = codegen_PADDB,
[UOP_PADDW & UOP_MASK] = codegen_PADDW,
[UOP_PADDD & UOP_MASK] = codegen_PADDD,
[UOP_PADDSB & UOP_MASK] = codegen_PADDSB,
[UOP_PADDSW & UOP_MASK] = codegen_PADDSW,
[UOP_PADDUSB & UOP_MASK] = codegen_PADDUSB,
[UOP_PADDUSW & UOP_MASK] = codegen_PADDUSW,
[UOP_PCMPEQB & UOP_MASK] = codegen_PCMPEQB,
[UOP_PCMPEQW & UOP_MASK] = codegen_PCMPEQW,
[UOP_PCMPEQD & UOP_MASK] = codegen_PCMPEQD,
[UOP_PCMPGTB & UOP_MASK] = codegen_PCMPGTB,
[UOP_PCMPGTW & UOP_MASK] = codegen_PCMPGTW,
[UOP_PCMPGTD & UOP_MASK] = codegen_PCMPGTD,
[UOP_PF2ID & UOP_MASK] = codegen_PF2ID,
[UOP_PFADD & UOP_MASK] = codegen_PFADD,
[UOP_PFCMPEQ & UOP_MASK] = codegen_PFCMPEQ,
[UOP_PFCMPGE & UOP_MASK] = codegen_PFCMPGE,
[UOP_PFCMPGT & UOP_MASK] = codegen_PFCMPGT,
[UOP_PFMAX & UOP_MASK] = codegen_PFMAX,
[UOP_PFMIN & UOP_MASK] = codegen_PFMIN,
[UOP_PFMUL & UOP_MASK] = codegen_PFMUL,
[UOP_PFRCP & UOP_MASK] = codegen_PFRCP,
[UOP_PFRSQRT & UOP_MASK] = codegen_PFRSQRT,
[UOP_PFSUB & UOP_MASK] = codegen_PFSUB,
[UOP_PI2FD & UOP_MASK] = codegen_PI2FD,
[UOP_PMADDWD & UOP_MASK] = codegen_PMADDWD,
[UOP_PMULHW & UOP_MASK] = codegen_PMULHW,
[UOP_PMULLW & UOP_MASK] = codegen_PMULLW,
[UOP_PSLLW_IMM & UOP_MASK] = codegen_PSLLW_IMM,
[UOP_PSLLD_IMM & UOP_MASK] = codegen_PSLLD_IMM,
[UOP_PSLLQ_IMM & UOP_MASK] = codegen_PSLLQ_IMM,
[UOP_PSRAW_IMM & UOP_MASK] = codegen_PSRAW_IMM,
[UOP_PSRAD_IMM & UOP_MASK] = codegen_PSRAD_IMM,
[UOP_PSRAQ_IMM & UOP_MASK] = codegen_PSRAQ_IMM,
[UOP_PSRLW_IMM & UOP_MASK] = codegen_PSRLW_IMM,
[UOP_PSRLD_IMM & UOP_MASK] = codegen_PSRLD_IMM,
[UOP_PSRLQ_IMM & UOP_MASK] = codegen_PSRLQ_IMM,
[UOP_PSUBB & UOP_MASK] = codegen_PSUBB,
[UOP_PSUBW & UOP_MASK] = codegen_PSUBW,
[UOP_PSUBD & UOP_MASK] = codegen_PSUBD,
[UOP_PSUBSB & UOP_MASK] = codegen_PSUBSB,
[UOP_PSUBSW & UOP_MASK] = codegen_PSUBSW,
[UOP_PSUBUSB & UOP_MASK] = codegen_PSUBUSB,
[UOP_PSUBUSW & UOP_MASK] = codegen_PSUBUSW,
[UOP_PUNPCKHBW & UOP_MASK] = codegen_PUNPCKHBW,
[UOP_PUNPCKHWD & UOP_MASK] = codegen_PUNPCKHWD,
[UOP_PUNPCKHDQ & UOP_MASK] = codegen_PUNPCKHDQ,
[UOP_PUNPCKLBW & UOP_MASK] = codegen_PUNPCKLBW,
[UOP_PUNPCKLWD & UOP_MASK] = codegen_PUNPCKLWD,
[UOP_PUNPCKLDQ & UOP_MASK] = codegen_PUNPCKLDQ,
[UOP_NOP_BARRIER & UOP_MASK] = codegen_NOP
};
void codegen_direct_read_8(codeblock_t *block, int host_reg, void *p)
{
if (in_range_h(p, &cpu_state))
host_arm_LDRB_IMM(block, host_reg, REG_CPUSTATE, (uintptr_t)p - (uintptr_t)&cpu_state);
else
fatal("codegen_direct_read_8 - not in range\n");
}
void codegen_direct_read_16(codeblock_t *block, int host_reg, void *p)
{
if (in_range_h(p, &cpu_state))
host_arm_LDRH_IMM(block, host_reg, REG_CPUSTATE, (uintptr_t)p - (uintptr_t)&cpu_state);
else
{
host_arm_MOV_IMM(block, REG_R3, (uintptr_t)p - (uintptr_t)&cpu_state);
host_arm_LDRH_REG(block, host_reg, REG_CPUSTATE, REG_R3);
}
}
void codegen_direct_read_32(codeblock_t *block, int host_reg, void *p)
{
if (in_range(p, &cpu_state))
host_arm_LDR_IMM(block, host_reg, REG_CPUSTATE, (uintptr_t)p - (uintptr_t)&cpu_state);
else
fatal("codegen_direct_read_32 - not in range\n");
}
void codegen_direct_read_pointer(codeblock_t *block, int host_reg, void *p)
{
codegen_direct_read_32(block, host_reg, p);
}
void codegen_direct_read_64(codeblock_t *block, int host_reg, void *p)
{
host_arm_VLDR_D(block, host_reg, REG_CPUSTATE, (uintptr_t)p - (uintptr_t)&cpu_state);
}
void codegen_direct_read_double(codeblock_t *block, int host_reg, void *p)
{
host_arm_VLDR_D(block, host_reg, REG_CPUSTATE, (uintptr_t)p - (uintptr_t)&cpu_state);
}
void codegen_direct_read_st_8(codeblock_t *block, int host_reg, void *base, int reg_idx)
{
host_arm_LDR_IMM(block, REG_TEMP, REG_HOST_SP, IREG_TOP_diff_stack_offset);
host_arm_ADD_IMM(block, REG_TEMP, REG_TEMP, reg_idx);
host_arm_AND_IMM(block, REG_TEMP, REG_TEMP, 7);
host_arm_ADD_REG_LSL(block, REG_TEMP, REG_CPUSTATE, REG_TEMP, 3);
host_arm_LDRB_IMM(block, host_reg, REG_TEMP, (uintptr_t)base - (uintptr_t)&cpu_state);
}
void codegen_direct_read_st_64(codeblock_t *block, int host_reg, void *base, int reg_idx)
{
host_arm_LDR_IMM(block, REG_TEMP, REG_HOST_SP, IREG_TOP_diff_stack_offset);
host_arm_ADD_IMM(block, REG_TEMP, REG_TEMP, reg_idx);
host_arm_AND_IMM(block, REG_TEMP, REG_TEMP, 7);
host_arm_ADD_REG_LSL(block, REG_TEMP, REG_CPUSTATE, REG_TEMP, 3);
host_arm_VLDR_D(block, host_reg, REG_TEMP, (uintptr_t)base - (uintptr_t)&cpu_state);
}
void codegen_direct_read_st_double(codeblock_t *block, int host_reg, void *base, int reg_idx)
{
host_arm_LDR_IMM(block, REG_TEMP, REG_HOST_SP, IREG_TOP_diff_stack_offset);
host_arm_ADD_IMM(block, REG_TEMP, REG_TEMP, reg_idx);
host_arm_AND_IMM(block, REG_TEMP, REG_TEMP, 7);
host_arm_ADD_REG_LSL(block, REG_TEMP, REG_CPUSTATE, REG_TEMP, 3);
host_arm_VLDR_D(block, host_reg, REG_TEMP, (uintptr_t)base - (uintptr_t)&cpu_state);
}
void codegen_direct_write_8(codeblock_t *block, void *p, int host_reg)
{
if (in_range(p, &cpu_state))
host_arm_STRB_IMM(block, host_reg, REG_CPUSTATE, (uintptr_t)p - (uintptr_t)&cpu_state);
else
fatal("codegen_direct_write_8 - not in range\n");
}
void codegen_direct_write_16(codeblock_t *block, void *p, int host_reg)
{
if (in_range_h(p, &cpu_state))
host_arm_STRH_IMM(block, host_reg, REG_CPUSTATE, (uintptr_t)p - (uintptr_t)&cpu_state);
else
{
host_arm_MOV_IMM(block, REG_R3, (uintptr_t)p - (uintptr_t)&cpu_state);
host_arm_STRH_REG(block, host_reg, REG_CPUSTATE, REG_R3);
}
}
void codegen_direct_write_32(codeblock_t *block, void *p, int host_reg)
{
if (in_range(p, &cpu_state))
host_arm_STR_IMM(block, host_reg, REG_CPUSTATE, (uintptr_t)p - (uintptr_t)&cpu_state);
else
fatal("codegen_direct_write_32 - not in range\n");
}
void codegen_direct_write_64(codeblock_t *block, void *p, int host_reg)
{
host_arm_VSTR_D(block, host_reg, REG_CPUSTATE, (uintptr_t)p - (uintptr_t)&cpu_state);
}
void codegen_direct_write_double(codeblock_t *block, void *p, int host_reg)
{
host_arm_VSTR_D(block, host_reg, REG_CPUSTATE, (uintptr_t)p - (uintptr_t)&cpu_state);
}
void codegen_direct_write_st_8(codeblock_t *block, void *base, int reg_idx, int host_reg)
{
host_arm_LDR_IMM(block, REG_TEMP, REG_HOST_SP, IREG_TOP_diff_stack_offset);
host_arm_ADD_IMM(block, REG_TEMP, REG_TEMP, reg_idx);
host_arm_AND_IMM(block, REG_TEMP, REG_TEMP, 7);
host_arm_ADD_REG_LSL(block, REG_TEMP, REG_CPUSTATE, REG_TEMP, 3);
host_arm_STRB_IMM(block, host_reg, REG_TEMP, (uintptr_t)base - (uintptr_t)&cpu_state);
}
void codegen_direct_write_st_64(codeblock_t *block, void *base, int reg_idx, int host_reg)
{
host_arm_LDR_IMM(block, REG_TEMP, REG_HOST_SP, IREG_TOP_diff_stack_offset);
host_arm_ADD_IMM(block, REG_TEMP, REG_TEMP, reg_idx);
host_arm_AND_IMM(block, REG_TEMP, REG_TEMP, 7);
host_arm_ADD_REG_LSL(block, REG_TEMP, REG_CPUSTATE, REG_TEMP, 3);
host_arm_VSTR_D(block, host_reg, REG_TEMP, (uintptr_t)base - (uintptr_t)&cpu_state);
}
void codegen_direct_write_st_double(codeblock_t *block, void *base, int reg_idx, int host_reg)
{
host_arm_LDR_IMM(block, REG_TEMP, REG_HOST_SP, IREG_TOP_diff_stack_offset);
host_arm_ADD_IMM(block, REG_TEMP, REG_TEMP, reg_idx);
host_arm_AND_IMM(block, REG_TEMP, REG_TEMP, 7);
host_arm_ADD_REG_LSL(block, REG_TEMP, REG_CPUSTATE, REG_TEMP, 3);
host_arm_VSTR_D(block, host_reg, REG_TEMP, (uintptr_t)base - (uintptr_t)&cpu_state);
}
void codegen_direct_write_ptr(codeblock_t *block, void *p, int host_reg)
{
if (in_range(p, &cpu_state))
host_arm_STR_IMM(block, host_reg, REG_CPUSTATE, (uintptr_t)p - (uintptr_t)&cpu_state);
else
fatal("codegen_direct_write_ptr - not in range\n");
}
void codegen_direct_read_16_stack(codeblock_t *block, int host_reg, int stack_offset)
{
if (stack_offset >= 0 && stack_offset < 256)
host_arm_LDRH_IMM(block, host_reg, REG_HOST_SP, stack_offset);
else
fatal("codegen_direct_read_32 - not in range\n");
}
void codegen_direct_read_32_stack(codeblock_t *block, int host_reg, int stack_offset)
{
if (stack_offset >= 0 && stack_offset < 4096)
host_arm_LDR_IMM(block, host_reg, REG_HOST_SP, stack_offset);
else
fatal("codegen_direct_read_32 - not in range\n");
}
void codegen_direct_read_pointer_stack(codeblock_t *block, int host_reg, int stack_offset)
{
codegen_direct_read_32_stack(block, host_reg, stack_offset);
}
void codegen_direct_read_64_stack(codeblock_t *block, int host_reg, int stack_offset)
{
host_arm_VLDR_D(block, host_reg, REG_HOST_SP, stack_offset);
}
void codegen_direct_read_double_stack(codeblock_t *block, int host_reg, int stack_offset)
{
host_arm_VLDR_D(block, host_reg, REG_HOST_SP, stack_offset);
}
void codegen_direct_write_32_stack(codeblock_t *block, int stack_offset, int host_reg)
{
if (stack_offset >= 0 && stack_offset < 4096)
host_arm_STR_IMM(block, host_reg, REG_HOST_SP, stack_offset);
else
fatal("codegen_direct_write_32 - not in range\n");
}
void codegen_direct_write_64_stack(codeblock_t *block, int stack_offset, int host_reg)
{
host_arm_VSTR_D(block, host_reg, REG_HOST_SP, stack_offset);
}
void codegen_direct_write_double_stack(codeblock_t *block, int stack_offset, int host_reg)
{
host_arm_VSTR_D(block, host_reg, REG_HOST_SP, stack_offset);
}
void codegen_set_jump_dest(codeblock_t *block, void *p)
{
*(uint32_t *)p |= ((((uintptr_t)&block_write_data[block_pos] - (uintptr_t)p) - 8) & 0x3fffffc) >> 2;
}
#endif
|
the_stack_data/48575968.c | /*
* A program to show the value of some file
* descriptors.
*/
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
int
main(int argc, char **argv) {
int fd1, fd2, fd3;
FILE *f;
printf("STDIN_FILENO: %d\n", STDIN_FILENO);
printf("stdin: %d\n", fileno(stdin));
printf("STDOUT_FILENO: %d\n", STDOUT_FILENO);
printf("stdout: %d\n", fileno(stdout));
printf("STDERR_FILENO: %d\n", STDERR_FILENO);
printf("stderr: %d\n", fileno(stderr));
printf("\nOpening /dev/zero...\n");
if ((fd1 = open("/dev/zero", O_RDONLY)) < 0) {
fprintf(stderr, "Unable to open /dev/zero: %s\n", strerror(errno));
} else {
printf("fd1: %d\n", fd1);
}
printf("\nOpening /dev/zero a second time...\n");
if ((fd2 = open("/dev/zero", O_RDONLY)) < 0) {
fprintf(stderr, "Unable to open /dev/zero: %s\n", strerror(errno));
exit(EXIT_FAILURE);
}
printf("fd2: %d\n", fd2);
printf("\nNow closing fd1, but keeping fd2 open..\n");
(void)close(fd1);
printf("\nOpening /dev/zero a third time...\n");
if ((fd3 = open("/dev/zero", O_RDONLY)) < 0) {
fprintf(stderr, "Unable to open /dev/zero: %s\n", strerror(errno));
exit(EXIT_FAILURE);
}
printf("fd3: %d\n", fd3);
printf("\nNow closing fd2 and fd3.\n");
(void)close(fd2);
(void)close(fd3);
printf("Now opening /dev/zero as a stream.\n");
if ((f = fopen("/dev/zero", "r")) == NULL) {
fprintf(stderr, "Unable to open /dev/zero: %s\n", strerror(errno));
exit(EXIT_FAILURE);
}
printf("f: %d\n", fileno(f));
(void)fclose(f);
return EXIT_SUCCESS;
}
|
the_stack_data/105833.c | /* Copyright (C) 1991-2015 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
#include <errno.h>
#include <unistd.h>
/* Get the process group ID of the calling process. */
pid_t
getpgrp (void)
{
return __getpgid (0);
}
|
the_stack_data/85286.c |
int arrangeCoins(int n)
{
long lo = 0, hi = n + 1u;
while (lo < hi)
{
long mi = (hi - lo) / 2 + lo;
if (mi * (mi + 1) / 2 <= n)
lo = mi + 1;
else
hi = mi;
}
return lo - 1;
}
|
the_stack_data/202498.c | #include<stdio.h>
int main(){
int i,j,max[50000],min[50000],n,s,a[1000];
scanf("%d",&n);
scanf("%d",&s);
/*if (s==0){
printf('0');
return 0;
}*/
for(i=1;i<=n;i++)
scanf("%d",&a[i]);
for(i=1;i<=s;i++){
max[i]=-2000000;
min[i]=2000000;
}
min[0]=max[0]=0;
for(i=1;i<=n;i++){
for(j=a[i];j<=s;j++){
if ((max[j-a[i]]+1)>max[j])
max[j]=max[j-a[i]]+1;
if ((min[j-a[i]]+1)<min[j])
min[j]=min[j-a[i]]+1;
}
}
printf("%d\n%d",min[s],max[s]);
return 0;
}
|
the_stack_data/57949326.c | // atanh_ex.c : atanh() example
// -------------------------------------------------------------
#include <math.h> // double atanh( double x );
// float atanhf( float x );
// long double atanhl( long double x );
#include <stdio.h>
#include <errno.h>
int main()
{
double x[ ] = { -1.0, -0.5, 0.0, 0.5, 0.99, 1.0, 1.01 };
puts(" x atanh(x) \n"
" ---------------------------------------");
for ( int i = 0; i < sizeof(x) / sizeof(x[0]); ++i )
{
errno = 0;
printf("%+15.2f %+20.10f\n", x[i], atanh(x[i]) );
if( errno)
perror("atanh");
}
return 0;
}
|
the_stack_data/165766565.c | #include <stdio.h>
#define MAX_LEN 1024
void expand(char s1[], char s2[]);
main()
{
char s1[] = "-a-z-A-Z-0-9-asd-5-5-5-9a-ZZ-A-G-N-T-Z";
char s2[MAX_LEN];
expand(s1, s2);//expand s1 into s2
printf("%s\n", s2);
char s[] = "-a-z 0-9 a-d-f -0-2 some text 1-1 WITH CAPITALS! 0-0 5-3 -";
char t[MAX_LEN];
expand(s, t);
printf("%s\n", t);
}
void expand(char s1[], char s2[])
{
int i, j, k;
for (i = 0, j = 0; s1[i] != '\0'; i++) {
if (s1[i] == '-' && i > 0 && s1[i+1] != '\0') {
int p = s1[i-1]; // character before -
int n = s1[i+1];// character after -
if (p < n &&
((p >= 'a' && n <= 'z') || (p >= 'A' && n <= 'Z') || (p >= '0' && n <= '9'))
) {
for (k = p + 1; k < n; k++)
s2[j++] = k;// copy middle char
} else {
s2[j++] = s1[i];//simply copy
}
} else {
s2[j++] = s1[i];//sinmply copy s1 to s2
}
}
s2[j] = '\0';
}
|
the_stack_data/34800.c | #include <pthread.h>
#include <stdio.h>
typedef struct {
int balance;
pthread_mutex_t mutex;
} bank_account;
bank_account A, B;
void deposit(bank_account *f, bank_account *t, int ammount) {
pthread_mutex_lock(&f->mutex);
pthread_mutex_lock(&t->mutex);
t->balance += ammount;
f->balance -= ammount;
pthread_mutex_unlock(&t->mutex);
pthread_mutex_unlock(&f->mutex);
}
void *t1(void *arg) {
deposit(&A, &B, rand() % 100);
return NULL;
}
void *t2(void *arg) {
deposit(&B, &A, rand() % 100);
return NULL;
}
int main(void) {
pthread_t id1, id2;
pthread_mutex_init(&A.mutex, NULL);
pthread_mutex_init(&B.mutex, NULL);
int i;
for (i = 0; i < 100000; i++) {
pthread_create(&id1, NULL, t1, NULL);
pthread_create(&id2, NULL, t2, NULL);
pthread_join (id1, NULL);
pthread_join (id2, NULL);
printf("%d: A = %d, B = %d.\n", i, A.balance, B.balance);
}
return 0;
}
|
the_stack_data/72013211.c | /*! \file bcm5699x_int.c
*
* BCM5699x INT subordinate driver.
*/
/*
* This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file.
*
* Copyright 2007-2020 Broadcom Inc. All rights reserved.
*/
#if defined(INCLUDE_INT)
#include <bcm_int/ltsw/mbcm/int.h>
#include <bcm_int/ltsw/xgs/int.h>
#include <bcm_int/ltsw/int_int.h>
#include <bcm_int/ltsw/dev.h>
#include <bcmltd/chip/bcmltd_str.h>
#include <shr/shr_debug.h>
/******************************************************************************
* Local definitions
*/
#define BSL_LOG_MODULE BSL_LS_BCM_INT
/******************************************************************************
* Private functions
*/
static bcmint_int_md_field_info_t
int_md_field_info[bcmIntMetadataCount] =
{
[bcmIntMetadataPadOne] = {1, bcmintIntMdFieldEntryWide, 0, {{0}, {0}}, (char *)PAD_ONESs},
[bcmIntMetadataPadZero] = {1, bcmintIntMdFieldEntryWide, 0, {{0}, {0}}, (char *)PAD_ZEROSs},
[bcmIntMetadataOpaqueData1] = {1, bcmintIntMdFieldEntryWide, 0, {{0}, {0}}, (char *)OPAQUE_DATA_0s},
[bcmIntMetadataOpaqueData2] = {1, bcmintIntMdFieldEntryWide, 0, {{0}, {0}}, (char *)OPAQUE_DATA_1s},
[bcmIntMetadataOpaqueData3] = {1, bcmintIntMdFieldEntryWide, 0, {{0}, {0}}, (char *)OPAQUE_DATA_2s},
[bcmIntMetadataSwitchId] = {1, bcmintIntMdFieldEntryWide, 0, {{0}, {0}}, (char *)SWITCH_IDs},
[bcmIntMetadataResidenceTimeSubSeconds] = {1, bcmintIntMdFieldEntryWide, 0, {{0}, {0}}, (char *)TRANSIT_DELAY_SUBSECONDSs},
[bcmIntMetadataCosqStat0] = {1, bcmintIntMdFieldEntryWide, 0, {{0}, {0}}, (char *)TM_STAT_0s},
[bcmIntMetadataCosqStat1] = {1, bcmintIntMdFieldEntryWide, 0, {{0}, {0}}, (char *)TM_STAT_1s},
[bcmIntMetadataIngressTimestampSubSeconds] = {1, bcmintIntMdFieldEntryWide, 0, {{0}, {0}}, (char *)ING_TIMESTAMP_SUB_SECONDSs},
[bcmIntMetadataEgressTimestampSubSeconds] = {1, bcmintIntMdFieldEntryWide, 0, {{0}, {0}}, (char *)EGR_TIMESTAMP_SUB_SECONDSs},
[bcmIntMetadataIngressTimestampSecondsLower] = {1, bcmintIntMdFieldEntryWide, 0, {{0}, {0}}, (char *)ING_TIMESTAMP_SECONDS_LOs},
[bcmIntMetadataEgressTimestampSecondsLower] = {1, bcmintIntMdFieldEntryWide, 0, {{0}, {0}}, (char *)EGR_TIMESTAMP_SECONDS_LOs},
[bcmIntMetadataIngressTimestampSecondsUpper] = {1, bcmintIntMdFieldEntryNarrow, 0, {{0}, {0}}, (char *)ING_TIMESTAMP_SECONDS_HIs},
[bcmIntMetadataEgressTimestampSecondsUpper] = {1, bcmintIntMdFieldEntryNarrow, 0, {{0}, {0}}, (char *)EGR_TIMESTAMP_SECONDS_HIs},
[bcmIntMetadataResidenceTimeSeconds] = {1, bcmintIntMdFieldEntryNarrow, 0, {{0}, {0}}, (char *)TRANSIT_DELAY_SECONDSs},
[bcmIntMetadataOverlayL3EgrIntf] = {1, bcmintIntMdFieldEntryNarrow, 0, {{0}, {0}}, (char *)L3_EIF_OVERLAYs},
[bcmIntMetadataL3EgrIntf] = {1, bcmintIntMdFieldEntryNarrow, 0, {{0}, {0}}, (char *)L3_EIFs},
[bcmIntMetadataL3IngIntf] = {1, bcmintIntMdFieldEntryNarrow, 0, {{0}, {0}}, (char *)L3_IIFs},
[bcmIntMetadataIngPortId] = {1, bcmintIntMdFieldEntryNarrow, 0, {{0}, {0}}, (char *)ING_PORTs},
[bcmIntMetadataEgrPortId] = {1, bcmintIntMdFieldEntryNarrow, 0, {{0}, {0}}, (char *)EGR_PORTs},
[bcmIntMetadataVrf] = {1, bcmintIntMdFieldEntryNarrow, 0, {{0}, {0}}, (char *)VRFs},
[bcmIntMetadataVfi] = {1, bcmintIntMdFieldEntryNarrow, 0, {{0}, {0}}, (char *)VFIs},
[bcmIntMetadataDvp] = {1, bcmintIntMdFieldEntryNarrow, 0, {{0}, {0}}, (char *)DVPs},
[bcmIntMetadataSvp] = {1, bcmintIntMdFieldEntryNarrow, 0, {{0}, {0}}, (char *)SVPs},
[bcmIntMetadataTunnelEncapIndex] = {1, bcmintIntMdFieldEntryNarrow, 0, {{0}, {0}}, (char *)TNL_ENCAP_INDEXs},
[bcmIntMetadataCng] = {1, bcmintIntMdFieldEntryNarrow, 0, {{0}, {0}}, (char *)CNGs},
[bcmIntMetadataCongestion] = {1, bcmintIntMdFieldEntryNarrow, 0, {{0}, {0}}, (char *)CONGESTIONs},
[bcmIntMetadataQueueId] = {1, bcmintIntMdFieldEntryNarrow, 0, {{0}, {0}}, (char *)QUEUE_IDs},
[bcmIntMetadataProfileId] = {1, bcmintIntMdFieldEntryNarrow, 0, {{0}, {0}}, (char *)METADATA_PROFILE_IDs},
[bcmIntMetadataCutThrough] = {1, bcmintIntMdFieldEntryNarrow, 0, {{0}, {0}}, (char *)CUT_THROUGHs},
[bcmIntMetadataCngQueueIdProfileIdCutThrough] = {1, bcmintIntMdFieldEntryNarrow, 0, {{0}, {0}}, NULL},
};
static int
bcm5699x_ltsw_int_md_field_info_get(
int unit,
bcmint_int_md_field_info_t **field_info)
{
SHR_FUNC_ENTER(unit);
SHR_NULL_CHECK(field_info, SHR_E_MEMORY);
*field_info = int_md_field_info;
exit:
SHR_FUNC_EXIT();
}
/*!
* \brief Int sub driver functions for bcm5699x.
*/
static mbcm_ltsw_int_drv_t bcm5699x_int_sub_drv = {
.int_md_field_info_get = bcm5699x_ltsw_int_md_field_info_get,
};
/******************************************************************************
* Public functions
*/
int
bcm5699x_int_sub_drv_attach(int unit, void *hdl)
{
SHR_FUNC_ENTER(unit);
SHR_IF_ERR_VERBOSE_EXIT
(mbcm_ltsw_int_drv_set(unit, &bcm5699x_int_sub_drv));
exit:
SHR_FUNC_EXIT();
}
#else
int
bcm5699x_int_sub_drv_attach(int unit, void *hdl)
{
return 0;
}
#endif /* INCLUDE_INT */
|
the_stack_data/1004311.c | #include<stdio.h>
int RectPerimeter (int num1,int num2)
{
return (num1 + num2) * 2;
}
int main (void)
{
// var declration
int num1,num2;
// user interface
printf("\nEnter Length: ");
scanf("%d",&num1);
printf("\nEnter Width: ");
scanf("%d",&num2);
// print the result
if ((num1 > 0) && (num2>0))
{
printf("\nThe perimeter of this rectangle is: %d \n \n",RectPerimeter(num1,num2));
}
else{;
printf("\nPlease enter valid length or width.\n \n");
}
return 0;
} |
the_stack_data/68886546.c | /* Copyright 2015-2016 The Chromium Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE.chromium file.
*
* Converted to C89 2015 by Tim Rühsen
*/
#include <stddef.h>
#if defined(__GNUC__) && defined(__GNUC_MINOR__)
# define _GCC_VERSION_AT_LEAST(major, minor) ((__GNUC__ > (major)) || (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor)))
#else
# define _GCC_VERSION_AT_LEAST(major, minor) 0
#endif
#define CHECK_LT(a, b) if ((a) >= b) return 0
static const char multibyte_length_table[16] = {
0, 0, 0, 0, /* 0x00-0x3F */
0, 0, 0, 0, /* 0x40-0x7F */
0, 0, 0, 0, /* 0x80-0xBF */
2, 2, 3, 4, /* 0xC0-0xFF */
};
/*
* Get length of multibyte character sequence starting at a given byte.
* Returns zero if the byte is not a valid leading byte in UTF-8.
*/
static int GetMultibyteLength(char c) {
return multibyte_length_table[((unsigned char)c) >> 4];
}
/*
* Moves pointers one byte forward.
*/
static void NextPos(const unsigned char** pos,
const char** key,
const char** multibyte_start)
{
++*pos;
if (*multibyte_start) {
/* Advance key to next byte in multibyte sequence. */
++*key;
/* Reset multibyte_start if last byte in multibyte sequence was consumed. */
if (*key - *multibyte_start == GetMultibyteLength(**multibyte_start))
*multibyte_start = 0;
} else {
if (GetMultibyteLength(**key)) {
/* Multibyte prefix was matched in the dafsa, start matching multibyte
* content in next round. */
*multibyte_start = *key;
} else {
/* Advance key as a single byte character was matched. */
++*key;
}
}
}
/*
* Read next offset from pos.
* Returns true if an offset could be read, false otherwise.
*/
static int GetNextOffset(const unsigned char** pos,
const unsigned char* end,
const unsigned char** offset)
{
size_t bytes_consumed;
if (*pos == end)
return 0;
/* When reading an offset the byte array must always contain at least
* three more bytes to consume. First the offset to read, then a node
* to skip over and finally a destination node. No object can be smaller
* than one byte. */
CHECK_LT(*pos + 2, end);
switch (**pos & 0x60) {
case 0x60: /* Read three byte offset */
*offset += (((*pos)[0] & 0x1F) << 16) | ((*pos)[1] << 8) | (*pos)[2];
bytes_consumed = 3;
break;
case 0x40: /* Read two byte offset */
*offset += (((*pos)[0] & 0x1F) << 8) | (*pos)[1];
bytes_consumed = 2;
break;
default:
*offset += (*pos)[0] & 0x3F;
bytes_consumed = 1;
}
if ((**pos & 0x80) != 0) {
*pos = end;
} else {
*pos += bytes_consumed;
}
return 1;
}
/*
* Check if byte at offset is last in label.
*/
static int IsEOL(const unsigned char* offset, const unsigned char* end)
{
CHECK_LT(offset, end);
return(*offset & 0x80) != 0;
}
/*
* Check if byte at offset matches first character in key.
* This version assumes a range check was already performed by the caller.
*/
static int IsMatchUnchecked(const unsigned char matcher,
const char* key,
const char* multibyte_start)
{
if (multibyte_start) {
/* Multibyte matching mode. */
if (multibyte_start == key) {
/* Match leading byte, which will also match the sequence length. */
return (matcher ^ 0x80) == (const unsigned char)*key;
} else {
/* Match following bytes. */
return (matcher ^ 0xC0) == (const unsigned char)*key;
}
}
/* If key points at a leading byte in a multibyte sequence, but we are not yet
* in multibyte mode, then the dafsa should contain a special byte to indicate
* a mode switch. */
if (GetMultibyteLength(*key)) {
return matcher == 0x1F;
}
/* Normal matching of a single byte character. */
return matcher == (const unsigned char)*key;
}
/*
* Check if byte at offset matches first character in key.
* This version matches characters not last in label.
*/
static int IsMatch(const unsigned char* offset,
const unsigned char* end,
const char* key,
const char* multibyte_start)
{
CHECK_LT(offset, end);
return IsMatchUnchecked(*offset, key, multibyte_start);
}
/*
* Check if byte at offset matches first character in key.
* This version matches characters last in label.
*/
static int IsEndCharMatch(const unsigned char* offset,
const unsigned char* end,
const char* key,
const char* multibyte_start)
{
CHECK_LT(offset, end);
return IsMatchUnchecked(*offset ^ 0x80, key, multibyte_start);
}
/*
* Read return value at offset.
* Returns true if a return value could be read, false otherwise.
*/
static int GetReturnValue(const unsigned char* offset,
const unsigned char* end,
const char* multibyte_start,
int* return_value)
{
CHECK_LT(offset, end);
if (!multibyte_start && (*offset & 0xE0) == 0x80) {
*return_value = *offset & 0x0F;
return 1;
}
return 0;
}
/*
* Looks up the string |key| with length |key_length| in a fixed set of
* strings. The set of strings must be known at compile time. It is converted to
* a graph structure named a DAFSA (Deterministic Acyclic Finite State
* Automaton) by the script psl-make-dafsa during compilation. This permits
* efficient (in time and space) lookup. The graph generated by psl-make-dafsa
* takes the form of a constant byte array which should be supplied via the
* |graph| and |length| parameters. The return value is kDafsaNotFound,
* kDafsaFound, or a bitmap consisting of one or more of kDafsaExceptionRule,
* kDafsaWildcardRule and kDafsaPrivateRule ORed together.
*
* Lookup a domain key in a byte array generated by psl-make-dafsa.
*/
/* prototype to skip warning with -Wmissing-prototypes */
int LookupStringInFixedSet(const unsigned char*, size_t,const char*, size_t);
int LookupStringInFixedSet(const unsigned char* graph,
size_t length,
const char* key,
size_t key_length)
{
const unsigned char* pos = graph;
const unsigned char* end = graph + length;
const unsigned char* offset = pos;
const char* key_end = key + key_length;
const char* multibyte_start = 0;
while (GetNextOffset(&pos, end, &offset)) {
/*char <char>+ end_char offsets
* char <char>+ return value
* char end_char offsets
* char return value
* end_char offsets
* return_value
*/
int did_consume = 0;
if (key != key_end && !IsEOL(offset, end)) {
/* Leading <char> is not a match. Don't dive into this child */
if (!IsMatch(offset, end, key, multibyte_start))
continue;
did_consume = 1;
NextPos(&offset, &key, &multibyte_start);
/* Possible matches at this point:
* <char>+ end_char offsets
* <char>+ return value
* end_char offsets
* return value
*/
/* Remove all remaining <char> nodes possible */
while (!IsEOL(offset, end) && key != key_end) {
if (!IsMatch(offset, end, key, multibyte_start))
return -1;
NextPos(&offset, &key, &multibyte_start);
}
}
/* Possible matches at this point:
* end_char offsets
* return_value
* If one or more <char> elements were consumed, a failure
* to match is terminal. Otherwise, try the next node.
*/
if (key == key_end) {
int return_value;
if (GetReturnValue(offset, end, multibyte_start, &return_value))
return return_value;
/* The DAFSA guarantees that if the first char is a match, all
* remaining char elements MUST match if the key is truly present.
*/
if (did_consume)
return -1;
continue;
}
if (!IsEndCharMatch(offset, end, key, multibyte_start)) {
if (did_consume)
return -1; /* Unexpected */
continue;
}
NextPos(&offset, &key, &multibyte_start);
pos = offset; /* Dive into child */
}
return -1; /* No match */
}
/* prototype to skip warning with -Wmissing-prototypes */
int GetUtfMode(const unsigned char *graph, size_t length);
int GetUtfMode(const unsigned char *graph, size_t length)
{
return length > 0 && graph[length - 1] < 0x80;
}
|
the_stack_data/72012199.c | #include <stdio.h>
int main(void) {
int N;
int n_in = 0, n_out = 0;
scanf("%d", &N);
int arr[N];
for (int i = 0; i < N; i++)
scanf("%d", &arr[i]);
for (int i = 0; i < N; i++) {
if (arr[i] >= 10 && arr[i] <= 20)
n_in++;
else
n_out++;
}
printf("%d in\n", n_in);
printf("%d out\n", n_out);
return 0;
} |
the_stack_data/4345.c | /* $OpenBSD: crypt2.c,v 1.3 2005/08/08 08:05:33 espie Exp $ */
/*
* FreeSec: libcrypt
*
* Copyright (c) 1994 David Burren
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 4. Neither the name of the author nor the names of other contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
*
* This is an original implementation of the DES and the crypt(3) interfaces
* by David Burren <[email protected]>.
*
* An excellent reference on the underlying algorithm (and related
* algorithms) is:
*
* B. Schneier, Applied Cryptography: protocols, algorithms,
* and source code in C, John Wiley & Sons, 1994.
*
* Note that in that book's description of DES the lookups for the initial,
* pbox, and final permutations are inverted (this has been brought to the
* attention of the author). A list of errata for this book has been
* posted to the sci.crypt newsgroup by the author and is available for FTP.
*/
#include <sys/types.h>
#include <sys/param.h>
#include <pwd.h>
#include <unistd.h>
#include <string.h>
#ifdef DEBUG
# include <stdio.h>
#endif
extern const u_char _des_bits8[8];
extern const u_int32_t _des_bits32[32];
extern int _des_initialised;
int
setkey(const char *key)
{
int i, j;
u_int32_t packed_keys[2];
u_char *p;
p = (u_char *) packed_keys;
for (i = 0; i < 8; i++) {
p[i] = 0;
for (j = 0; j < 8; j++)
if (*key++ & 1)
p[i] |= _des_bits8[j];
}
return(des_setkey((char *)p));
}
int
encrypt(char *block, int flag)
{
u_int32_t io[2];
u_char *p;
int i, j, retval;
if (!_des_initialised)
_des_init();
_des_setup_salt(0);
p = (u_char *)block;
for (i = 0; i < 2; i++) {
io[i] = 0L;
for (j = 0; j < 32; j++)
if (*p++ & 1)
io[i] |= _des_bits32[j];
}
retval = _des_do_des(io[0], io[1], io, io + 1, flag ? -1 : 1);
for (i = 0; i < 2; i++)
for (j = 0; j < 32; j++)
block[(i << 5) | j] = (io[i] & _des_bits32[j]) ? 1 : 0;
return(retval);
}
|
the_stack_data/1005099.c | /* 6. Design, Develop and Implement a menu driven Program in C for the following operations
on Circular QUEUE of Characters (Array Implementation of Queue with maximum size
MAX)
a. Insert an Element on to Circular QUEUE
b. Delete an Element from Circular QUEUE
c. Demonstrate Overflow and Underflow situations on Circular QUEUE
d. Display the status of Circular QUEUE
e. Exit
Support the program with appropriate functions for each of the above operations */
#include<stdio.h>
#define MAX 6
int front=0,rear=0;
char q[MAX];
//a. Insert an Element on to Circular QUEUE
void insert()
{
char item;
if(front==(rear+1)%MAX) // Check for overflow
{
printf("\n Circular Queue Overflow\n");
return;
}
rear=(rear+1)%MAX;
printf("\n Enter the character to be inserted: ");
fflush(stdin);
scanf("%c",&item);
q[rear]=item;
} // end of insert
//b. Delete an Element from Circular QUEUE
void delete()
{
if(front==rear) // check for Underflow
{
printf("\n Circular Queue Underflow\n");
return;
}
front=(front+1)%MAX;
printf("\n Deleted character is: %c ",q[front]);
} // end of delete
// d. Display the status of Circular QUEUE
void display()
{
int i;
if(front==rear)
{
printf("\nCircular Queue is Empty\n");
return;
}
printf("\n Contents of Queue is:\n");
for(i=(front+1)%MAX; i!=rear; i=(i+1)%MAX)
printf("%c\t",q[i]);
printf("%c\t",q[i]);
} // end of display
void main()
{
int choice;
while(1)
{
printf("\n CIRCULAR QUEUE OPERATIONS");
printf("\n Enter the choice");
printf("\n 1.Insert\n 2.Delete\n 3.Display\n 4.Exit\n");
scanf("%d",&choice);
switch(choice)
{
case 1:
insert();
break;
case 2:delete();
break;
case 3:display();
break;
case 4:return;
default : printf("\n Invalid Choice \n");
}// end of switch
} // end of menu loop
} //end of main
|
the_stack_data/154828883.c | #include <assert.h>
#include <time.h>
#include <stdlib.h>
void shellSort(int *array, int length) {
for (int gap = length / 2; gap > 0; gap /= 2) {
for (int i = gap; i < length; ++i) {
int key = array[i];
int j;
for (j = i - gap; j >= 0 && key < array[j]; j -= gap) {
array[j + gap] = array[j];
}
if (j != i - gap) {
array[j + gap] = key;
}
}
}
}
void test() {
/* initial random number generator */
srand(time(NULL));
const int size = 10;
int *arr = (int *) calloc(size, sizeof(int));
/* generate size random numbers from 0 to 100 */
for (int i = 0; i < size; i++) {
arr[i] = rand() % 100;
}
shellSort(arr, size);
for (int i = 0; i < size - 1; ++i) {
assert(arr[i] <= arr[i + 1]);
}
free(arr);
}
int main() {
test();
return 0;
}
|
the_stack_data/140765751.c | /*
File automatically generated by:
python3 writeGaloisFieldTable.py 4
---------------------------------------------------------------------------
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
---------------------------------------------------------------------------
*/
#include <stdint.h>
static const uint8_t gf16_log_table[16] = {
0, 15, 1, 4, 2, 8, 5, 10,
3, 14, 9, 7, 6, 13, 11, 12};
static const uint8_t gf16_exp_table[16] = {
1, 2, 4, 8, 3, 6, 12, 11,
5, 10, 7, 14, 15, 13, 9, 1};
|
the_stack_data/242331172.c | #include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#define UPPERCASE 'C'
#define LOWERCASE 'c'
int isUpperCase(char);
int isLowerCase(char);
int compare(const void* a, const void* b);
void strToLower(char*);
char* getStringFormat(char*);
void reformatString(char*, char*);
int main(){
/* Read from stdin line by line */
int lineSize = 1024;
int lineCount = 0;
char* lines = (char*)malloc(1);
char line[lineSize];
while (fgets(line, lineSize, stdin) != NULL){
if (*(line+strlen(line)-1) == '\n'){
*(line+strlen(line)-1) = '\0';
}
lineCount++;
lines = (char*)realloc(lines, lineSize*lineCount*sizeof(char));
strcpy(lines + (lineCount-1)*lineSize, line);
}
/* Get the format of each string */
int i;
for (i = 0; i < lineCount; i++){
printf("%s\n", lines + i*lineSize);
char* word = strtok(lines + i*lineSize, " ");
while (word != NULL){
char* format = getStringFormat(word);
strToLower(word);
qsort(word, strlen(word), sizeof(char), compare);
reformatString(word, format);
printf("%s ", word);
word = strtok(NULL, " ");
free(format);
}
printf("\n");
free(word);
}
free(lines);
return 0;
}
int isUpperCase(char c){
return c >= 'A' && c <= 'Z';
}
int isLowerCase(char c){
return c >= 'a' && c <= 'z';
}
int compare(const void *a, const void *b){
return *(const char *)a - *(const char *)b;
}
void strToLower(char* p){
for ( ; *p; ++p){
if (isalpha(*p))
*p = tolower(*p);
}
}
char* getStringFormat(char* line){
char* format = (char*)malloc((strlen(line)+1)*sizeof(char));
int i;
for (i = 0; i < strlen(line); i++){
char c = *(line+i);
if (isUpperCase(c)){
*(format+i) = UPPERCASE;
}
else if (isLowerCase(c)) {
*(format+i) = LOWERCASE;
}
else {
*(format+i) = c;
}
}
*(format + strlen(line)) = '\0';
return format;
}
/* Rearrange the string such that the cases and pucntiations ar ein their previos positions */
void reformatString(char* word, char* format){
// Remove all not-letters from the string
int len = (int)strlen(word);
char trimmedWord[len];
int i, j = 0;
for (i = 0; i < len; i++){
char c = *(word+i);
if (isalpha(c)){
trimmedWord[j++] = c;
}
}
trimmedWord[j] = '\0';
j = 0;
// Reformat the word
for (i = 0; i < len; i++){
char c = *(format+i);
switch (c){
case UPPERCASE:
*(word + i) = toupper(trimmedWord[j++]);
break;
case LOWERCASE:
*(word + i) = tolower(trimmedWord[j++]);
break;
default:
*(word + i) = c;
}
}
} |
the_stack_data/36553.c | /*BEGIN_LEGAL
Intel Open Source License
Copyright (c) 2002-2014 Intel Corporation. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer. Redistributions
in binary form must reproduce the above copyright notice, this list of
conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution. Neither the name of
the Intel Corporation nor the names of its contributors may be used to
endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR
ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
END_LEGAL */
/*
* This test verifies that Pin correctly clears the DF bit when executing
* the application's signal handler.
*
* This test may also be run natively, bit it fails on older kernels
* because older kernels did not correctly clear DF on entry to a signal
* handler. (The same bug Pin used to have.)
*/
#include <stdio.h>
#include <signal.h>
#include <sys/time.h>
int DidTest;
int DFSet = 0;
int Flags;
extern void SetAndClearDF();
extern void SignalHandler(int);
int main()
{
struct sigaction sigact;
struct itimerval itval;
sigact.sa_handler = SignalHandler;
sigact.sa_flags = 0;
sigemptyset(&sigact.sa_mask);
if (sigaction(SIGALRM, &sigact, 0) == -1)
{
fprintf(stderr, "Unable to set up handler\n");
return 1;
}
itval.it_interval.tv_sec = 0;
itval.it_interval.tv_usec = 100000;
itval.it_value.tv_sec = 0;
itval.it_value.tv_usec = 100000;
if (setitimer(ITIMER_REAL, &itval, 0) == -1)
{
fprintf(stderr, "Unable to set up timer\n");
return 1;
}
/*
* Continuously set and clear the DF bit until a signal arrives while DF is set.
*/
while (!DidTest)
SetAndClearDF();
itval.it_value.tv_sec = 0;
itval.it_value.tv_usec = 0;
if (setitimer(ITIMER_REAL, &itval, 0) == -1)
{
fprintf(stderr, "Unable to disable timer\n");
return 1;
}
/*
* The signal handler copied the flags to 'Flags'. Make sure the DF bit was
* cleared in the handler.
*/
if (Flags & (1<<10))
{
fprintf(stderr, "DF bit set incorrectly in signal handler\n");
return 1;
}
return 0;
}
|
the_stack_data/11215.c | // A C Program to demonstrate adjacency list representation of graphs
#include <stdio.h>
#include <stdlib.h>
// A structure to represent an adjacency list node
struct AdjListNode
{
int dest;
struct AdjListNode* next;
};
// A structure to represent an adjacency list
struct AdjList
{
struct AdjListNode *head; // pointer to head node of list
};
// A structure to represent a graph. A graph is an array of adjacency lists.
// Size of array will be V (number of vertices in graph)
struct Graph
{
int V;
struct AdjList* array;
};
// A utility function to create a new adjacency list node
struct AdjListNode* newAdjListNode(int dest)
{
struct AdjListNode* newNode =
(struct AdjListNode*) malloc(sizeof(struct AdjListNode));
newNode->dest = dest;
newNode->next = NULL;
return newNode;
}
// A utility function that creates a graph of V vertices
struct Graph* createGraph(int V)
{
struct Graph* graph = (struct Graph*) malloc(sizeof(struct Graph));
graph->V = V;
// Create an array of adjacency lists. Size of array will be V
graph->array = (struct AdjList*) malloc(V * sizeof(struct AdjList));
// Initialize each adjacency list as empty by making head as NULL
int i;
for (i = 0; i < V; ++i)
graph->array[i].head = NULL;
return graph;
}
// Adds an edge to an undirected graph
void addEdge(struct Graph* graph, int src, int dest)
{
// Add an edge from src to dest. A new node is added to the adjacency
// list of src. The node is added at the begining
struct AdjListNode* newNode = newAdjListNode(dest);
newNode->next = graph->array[src].head;
graph->array[src].head = newNode;
// Since graph is undirected, add an edge from dest to src also
newNode = newAdjListNode(src);
newNode->next = graph->array[dest].head;
graph->array[dest].head = newNode;
}
// A utility function to print the adjacenncy list representation of graph
void printGraph(struct Graph* graph)
{
int v;
for (v = 0; v < graph->V; ++v)
{
struct AdjListNode* pCrawl = graph->array[v].head;
printf("\n Adjacency list of vertex %d\n head ", v);
while (pCrawl)
{
printf("-> %d", pCrawl->dest);
pCrawl = pCrawl->next;
}
printf("\n");
}
}
// Driver program to test above functions
int main()
{
// create the graph given in above fugure
int V = 5;
struct Graph* graph = createGraph(V);
addEdge(graph, 0, 1);
addEdge(graph, 0, 4);
addEdge(graph, 1, 2);
addEdge(graph, 1, 3);
addEdge(graph, 1, 4);
addEdge(graph, 2, 3);
addEdge(graph, 3, 4);
// print the adjacency list representation of the above graph
printGraph(graph);
return 0;
}
|
the_stack_data/159516670.c | #include <stdio.h>
#include <sys/types.h>
#include <sys/file.h>
#include <math.h>
float xmin = 1.0, xmax = 0.0;
main(argc, argv)
int argc;
char *argv[];
{
int i, iycol, nfiles, nrows, i10shift[100];
char cOutput[256], cOption[256], coord1, cscale[256], cFiles[100][256];
float flog10scale[100], fget_log_scale(char *cFile, int iycol);
void gen_i10shift(int n, float *f10scale, int *i10shift);
int get_data_file_names(char cFiles[100][256]);
void gen_plt_file(int nfiles, char cFiles[100][256], char coord1,
char *cscale, int iycol, int i10shift[100]);
// Get inputs
if(argc < 2) { printf("usage: gen_plt_file <output> [<option1> <option2> ...]\n"); exit(0); }
sscanf(argv[1], "%s", cOutput);
coord1 = cOutput[0];
iycol = 2;
sprintf(cscale,"linear");
for(i=2; i<argc; i++) {
sscanf(argv[i], "%s", cOption);
if(strcmp(cOption,"part=sum") == 0) iycol = 7;
if(strcmp(cOption,"logscale" ) == 0) sprintf(cscale,"%s",cOption);
if(strcmp(cOption,"autoscale") == 0) sprintf(cscale,"%s",cOption);
}
// Get files, x-range & generate factor of 10 scaleings if requested & needed
nfiles = get_data_file_names(cFiles);
for(i=0; i<nfiles; i++) { flog10scale[i] = fget_log_scale(cFiles[i], iycol); }
for(i=0; i<nfiles; i++) i10shift[i] = 0;
if(strcmp(cscale,"autoscale")==0) gen_i10shift(nfiles, flog10scale, i10shift);
gen_plt_file(nfiles,cFiles,coord1,cscale,iycol,i10shift);
}
/****************************************************************************/
void gen_plt_file(int nfiles, char cFiles[100][256], char coord1,
char *cscale, int iycol, int i10shift[100])
{
FILE *fp, *fopen();
int i;
char cfld[100][256], cycol[256], cyfld[256], c10[256], cXlabel[256],cuse1[256];
void get_var_name(int i0, char cfin, char* cfile, char* cfld);
void gen_c10(int n, char *c10);
float xdel;
void get_xlabel(char *cXlabel);
void get_use1(char *cXlabel);
void get_var_names(int nvars, char cVars[100][256]);
sprintf(cXlabel, "set xlabel '%c'\n", coord1);
get_xlabel(cXlabel);
get_use1(cuse1);
for(i=0; i<nfiles; i++) get_var_name(11,'.',cFiles[i],cfld[i]);
get_var_names(nfiles, cfld);
xdel = 0.02 * (xmax - xmin);
fp = fopen("bar.plt", "w");
// fprintf(fp,"set xlabel '%c'\n", coord1);
fprintf(fp,"%s\n", cXlabel);
fprintf(fp,"set ylabel '");
for(i=0; i<nfiles; i++) fprintf(fp, " %s", cfld[i]);
fprintf(fp,"'\n");
if(cuse1[0] == '1') fprintf(fp,"set xrange [%f:%f]\n", xmin-xdel, xmax+xdel);
if(strcmp(cscale,"logscale")==0) fprintf(fp, "set logscale y\n");
fprintf(fp,"plot \\\n");
for(i=0; i<nfiles; i++) {
sprintf(cycol, "%d", iycol);
sprintf(cyfld, "%s", cfld[i]);
if(i10shift[i] > 0) {
gen_c10(i10shift[i], c10);
sprintf(cycol, "(%s.0*$%d)", c10, iycol);
sprintf(cyfld, "1e%d * %s", i10shift[i], cfld[i]);
if(i10shift[i] == 1) sprintf(cyfld, "10 * %s", cfld[i]);
if(i10shift[i] == 2) sprintf(cyfld, "100 * %s", cfld[i]);
}
fprintf(fp, " '%s' using %s:%s title '%s' with linespoints", cFiles[i],cuse1,cycol,cyfld);
if(i < nfiles-1) fprintf(fp, ", \\\n"); else fprintf(fp, "\n");
}
fclose(fp);
}
/****************************************************************************/
void get_xlabel(char *cXlabel)
{
FILE *fp;
char *line = NULL;
size_t len = 0;
ssize_t read;
fp = fopen("xlabel_string", "r");
if (fp == NULL) return;
read = getline(&line, &len, fp);
if(read != -1) {
/*
printf("========================================\n");
printf("Retrieved line of length %zu :\n", read);
printf("%s", line);
printf("========================================\n");
*/
sprintf(cXlabel, "%s", line);
}
if (line) free(line);
fclose(fp);
return;
}
/****************************************************************************/
void get_use1(char *cuse1)
{
FILE *fp;
char *line = NULL;
size_t len = 0;
ssize_t read;
int i, i0, i1;
sprintf(cuse1, "1");
fp = fopen("plot_string", "r");
if (fp == NULL) return;
read = getline(&line, &len, fp);
if(read != -1) {
/*
printf("========================================\n");
printf("Retrieved line of length %zu :\n", read);
printf("%s", line);
printf("========================================\n");
*/
i0 = -1;
i1 = -1;
for(i=0; i<(int)read; i++) {
if(line[i] == '(') i0 = i;
if(line[i] == ')') i1 = i;
}
if(i1 > i0 && i0 > 0) {
sprintf(cuse1, "%s", &line[i0]);
cuse1[1+i1-i0] = '\0';
}
}
if (line) free(line);
return;
}
/****************************************************************************/
void gen_c10(int n, char *c10)
{
int i;
c10[0] = '1';
for(i=0; i<n; i++) c10[i+1] = '0';
c10[n+1] = '\0';
return;
}
/****************************************************************************/
void get_var_name(int i0, char cfin, char* cfile, char* cfld)
{
int i=0;
while(cfile[i0+i] != cfin && i<100) { cfld[i] = cfile[i+i0]; i++; }
cfld[i] = '\0';
return;
}
/****************************************************************************/
void get_var_names(int nvars, char cVars[100][256])
{
FILE *fp;
char *line = NULL;
size_t len = 0;
ssize_t read;
int iVar, n;
char ca[256], cb[256], cc[256];
fp = fopen("ylabel_strings", "r");
if (fp == NULL) return;
for(iVar=0; iVar<nvars; iVar++) {
read = getline(&line, &len, fp);
if(read != -1) {
/*
printf("========================================\n");
printf("Retrieved line of length %zu :\n", read);
printf("%s", line);
printf("========================================\n");
*/
sscanf(line, "%s %s %s", ca, cb, cc);
n = strlen(cc);
strncpy(cVars[iVar], &cc[1], n-2);
cVars[iVar][n-1] = '\0';
}
}
if (line) free(line);
fclose(fp);
}
/****************************************************************************/
int get_data_file_names(char cFiles[100][256])
{
FILE *fp, *fopen();
int nfiles = 0;
fp = fopen("plot_data_files", "r");
while(fscanf(fp, "%s", cFiles[nfiles]) > 0) nfiles++;
fclose(fp);
return nfiles;
}
/****************************************************************************/
void gen_i10shift(int n, float *f10scale, int *i10shift)
{
int i;
float f10max;
f10max = f10scale[0];
for(i=1; i<n; i++) if(f10max < f10scale[i]) f10max = f10scale[i];
for(i=0; i<n; i++) {
i10shift[i] = 0;
if(f10scale[i] > -8000.0) i10shift[i] = (int)(f10max+0.5 - f10scale[i]);
}
return;
}
/****************************************************************************/
float fget_log_scale(char *cFile, int iycol)
{
float f10scale;
float min, max;
void get_minmax(char *cFile, int iycol, float *pmin, float *pmax);
get_minmax(cFile, iycol, &min, &max);
if(max < 0.0) max = -max;
if(min < 0.0) min = -min;
if(max < min) max = min; // = max(abs(min), abs(max))
if(max == 0.0) f10scale = -9000.0;
else f10scale = log(max) / log(10.0);
return f10scale;
}
/****************************************************************************/
#define NMAX 100000
void get_minmax(char *cFile, int iycol, float *min, float *max)
{
int i, nrows;
float x[NMAX], y[NMAX];
int read_cols(char *cFileIn, int icol1, int icol2, float *x, float *y);
nrows = read_cols(cFile, 1, iycol, x, y);
*min = y[0];
*max = y[0];
if(xmax < xmin) { xmin = x[0]; xmax = x[0]; }
for(i=0; i<nrows; i++) {
if(*min > y[i]) *min = y[i];
if(*max < y[i]) *max = y[i];
if(xmin > x[i]) xmin = x[i];
if(xmax < x[i]) xmax = x[i];
}
}
/****************************************************************************/
int read_cols(char *cFileIn, int icol1, int icol2, float *x, float *y)
{
FILE *fp, *fopen();
char *line = NULL;
size_t len = 0;
ssize_t read;
float d[20];
int icolmax, i,nrows, ngot;
if(icol1 < icol2) icolmax = icol2; else icolmax = icol1;
fp = fopen(cFileIn, "r");
if(fp == NULL) { printf("Could not opne %s\n", cFileIn); exit(0); }
nrows = 0;
while ((read = getline(&line, &len, fp)) != -1 && nrows < NMAX) {
if(line[0] != '#') {
ngot = sscanf(line, "%f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f\n",
&d[ 1],&d[ 2],&d[ 3],&d[ 4],&d[ 5],&d[ 6],&d[ 7],&d[ 8],&d[ 9], &d[10],
&d[11],&d[12],&d[13],&d[14],&d[15],&d[16],&d[17],&d[18],&d[19]);
if(ngot < icolmax) { printf("Max column in a row of file: %d\n", ngot+1); exit(0); }
x[nrows] = d[icol1];
y[nrows] = d[icol2];
nrows++;
}
}
fclose(fp);
return nrows;
}
|
the_stack_data/97012596.c | /******************************************************************************
* Copyright (c) 2012 IBM Corporation
* All rights reserved.
* This program and the accompanying materials
* are made available under the terms of the BSD License
* which accompanies this distribution, and is available at
* http://www.opensource.org/licenses/bsd-license.php
*
* Contributors:
* IBM Corporation - initial implementation
*****************************************************************************/
#include <string.h>
#include <stdlib.h>
char *strdup(const char *src)
{
size_t len = strlen(src) + 1;
char *ret;
ret = malloc(len);
if (ret)
memcpy(ret, src, len);
return ret;
}
|
the_stack_data/617327.c | //Autor: Matheus de Sousa Matos
//Curso: Engenharia de Software
//Período: 6º Semestre
//Matrícula: UC19104412
#include <stdio.h>
#include <stdlib.h>
int main(){
int v[5] = {1,4,6,2,3};
int k = 2;
int tam = 5;
int menor = kesimo(v,k,tam);
printf("MENOR: %d", menor);
}
int kesimo(int *v, int tam, int k){
int tiraMenor;
for (int i = 0; i < k; i++)
{
tiraMenor = tMenor(v,tam);
}
return tiraMenor;
}
int tMenor(int *v,int *tam){
int menor = __INT32_MAX__, pos = -1;
for (int i = 0; i < tam; i++)
{
if(v[i] < menor){
menor = v[i];
pos = i;
}
}
v[pos] = __INT32_MAX__;
return menor;
} |
the_stack_data/79857.c | /* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_print_combn.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: esuguimo <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/10/10 17:28:54 by esuguimo #+# #+# */
/* Updated: 2019/10/10 21:59:49 by esuguimo ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
void ft_putchar(char c);
void ft_create_tab(int array[], int n)
{
int i;
i = 0;
while (i < n)
{
array[i] = i;
i++;
}
}
int ft_get_index(int *tab, int size)
{
int i;
int max_value;
i = 0;
max_value = 10 - size;
while (i < size)
{
if (tab[i] == max_value)
return (i - 1);
if (i == (size - 1) && tab[i] < max_value)
return (i);
i++;
max_value++;
}
return (-1);
}
void ft_increment(int tab[], int index, int size)
{
int i;
i = index + 1;
tab[index]++;
while (i < size)
{
tab[i] = tab[i - 1] + 1;
i++;
}
}
void ft_print_array(int array[], int n)
{
int i;
i = 0;
while (i < n)
{
ft_putchar(array[i] + '0');
i++;
}
}
void ft_print_combn(int n)
{
int tab[n];
int index;
ft_create_tab(tab, n);
while (ft_get_index(tab, n) != -1)
{
index = ft_get_index(tab, n);
ft_print_array(tab, n);
ft_increment(tab, index, n);
ft_putchar(',');
ft_putchar(' ');
}
ft_print_array(tab, n);
}
|
the_stack_data/153267617.c | // RUN: mlir-clang %s --function=kernel_correlation --raise-scf-to-affine -S | FileCheck %s
#define DATA_TYPE double
#define SCALAR_VAL(x) ((double)x)
void use(int i);
/* Main computational kernel. The whole function will be timed,
including the call and return. */
void kernel_correlation(int start, int end) {
for (int i = end; i >= start; i--) {
use(i);
}
}
// CHECK: #map = affine_map<()[s0] -> (s0 + 1)>
// CHECK: func @kernel_correlation(%arg0: i32, %arg1: i32)
// CHECK-NEXT: %0 = arith.index_cast %arg1 : i32 to index
// CHECK-NEXT: %1 = arith.index_cast %arg0 : i32 to index
// CHECK-NEXT: affine.for %arg2 = %1 to #map()[%0] {
// CHECK-NEXT: %2 = arith.index_cast %arg2 : index to i32
// CHECK-NEXT: %3 = arith.subi %2, %arg0 : i32
// CHECK-NEXT: %4 = arith.subi %arg1, %3 : i32
// CHECK-NEXT: call @use(%4) : (i32) -> ()
// CHECK-NEXT: }
// CHECK-NEXT: return
// CHECK-NEXT: }
|
the_stack_data/289547.c | #include <stdio.h>
#include <stdlib.h>
#include <omp.h>
int main(int argc, char **argv) {
int N, M, P;
// Size of arrays
N = atoi(argv[1]);
M = atoi(argv[2]);
P = atoi(argv[3]);
// Count of threads
int L = atoi(argv[4]);
omp_set_num_threads(L);
int i, j, k;
double A[N][M], B[M][P], C[N][P];
#pragma omp parallel shared(A, B, C) private(i, j, k)
{
// Initializing arrays
#pragma omp for schedule(static)
for (i = 0; i < N; i++) {
for (j = 0; j < M; j++) {
A[i][j] = i+j;
}
}
#pragma omp for schedule(static)
for (i = 0; i < M; i++) {
for (j = 0; j < P; j++) {
B[i][j] = i*j;
}
}
#pragma omp for schedule(static)
for (i = 0; i < N; i++) {
for (j = 0; j < P; j++) {
C[i][j] = 0;
}
}
// Solve result
#pragma omp for schedule(static)
for (i = 0; i < N; i++) {
for (j = 0; j < P; j++) {
for (k = 0; k < M; k++) {
C[i][j] += A[i][k] * B[k][j];
}
}
}
}
// Print matrix
/*
for (i = 0; i < N; i++) {
for (j = 0; j < P; j++) {
printf("%.3lf ", C[i][j]);
}
printf("\n");
}
*/
return 0;
}
|
the_stack_data/1230496.c | /* Clean exit of the thread group leader should not break GDB.
Copyright 2007-2016 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This 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 program. If not, see <http://www.gnu.org/licenses/>. */
#include <pthread.h>
#include <assert.h>
#include <unistd.h>
static volatile pthread_t main_thread;
static void *
start (void *arg)
{
int i;
i = pthread_join (main_thread, NULL);
assert (i == 0);
sleep (10); /* break-here */
return arg;
}
int
main (void)
{
pthread_t thread;
int i;
main_thread = pthread_self ();
i = pthread_create (&thread, NULL, start, NULL);
assert (i == 0);
pthread_exit (NULL);
/* NOTREACHED */
return 0;
}
|
the_stack_data/1057182.c | int main() {
int a[5];
return sizeof(a);
} |
the_stack_data/82951361.c | // Test that the driver correctly combines its own diagnostics with CC1's in the
// serialized diagnostics. To test this, we need to trigger diagnostics from
// both processes, so we compile code that has a warning (with an associated
// note) and then force the driver to crash. We compile stdin so that the crash
// doesn't litter the user's system with preprocessed output.
// RUN: rm -f %t
// RUN: %clang -Wx-unknown-warning -Wall -fsyntax-only --serialize-diagnostics %t.diag %s
// RUN: c-index-test -read-diagnostics %t.diag 2>&1 | FileCheck %s
// CHECK: warning: unknown warning option '-Wx-unknown-warning' [-Wunknown-warning-option] []
// CHECK: warning: variable 'voodoo' is uninitialized when used here [-Wuninitialized]
// CHECK: note: initialize the variable 'voodoo' to silence this warning []
// CHECK: Number of diagnostics: 2
void foo() {
int voodoo;
voodoo = voodoo + 1;
}
|
the_stack_data/173579244.c | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#define ELEMENTS 50
#define OP_UNION 0
#define OP_SPLIT 1
#define MAX 1000
#define ITEM_MAX 100
void replaceChar(char *string, char oldChar, char newChar);
void generate(char *id, char *total, char *upercent, int client);
char *port[] = {"6379","6380","6381","6382","6383","6384","6385","6386","6387","6388","6389","6390","6391"};
int total_op = 0;
int union_op = 0;
int split_op = 0;
//char *initial_content[] = {"22,30/47,80/225,890/12,34","12,37,78/257,789,120/36/240,55,556/90,2","red,yellow/blue,gray,black/scarlet/green,pink/white,purple"};
char *key_list[] = {"group1","group2","group3","group4"};
int key = 0;
int len = 1;
char *ufs[ITEM_MAX];
/*arguments:
*argv[1]: thread_num
*argv[2]: total command number (union and split)
*argv[3]: union command percent
*argv[4]: id of initial content
*argv[5]: key of ufs
*/
int main(int argc, char*argv[]) {
int thread_num = atoi(argv[1]);
total_op = atoi(argv[2]);
double union_percent = atof(argv[3]);
int ufs_id = atoi(argv[4]);
key = atoi(argv[5])-1;
union_op = total_op*union_percent;
split_op = total_op-union_op;
pthread_t thread[thread_num];
int rc[thread_num];
int i;
char *r;
char str[MAX];
FILE *fr = fopen("/home/xue/ufs.txt","r+");
if (!fr) {
printf("ERROR: fail to open file\n");
return -1;
}
i = 1;
while (!feof(fr)) {
fgets(str,MAX,fr);
if (i == ufs_id) break;
i++;
}
fclose(fr);
str[strlen(str)-1] = '\0';
replaceChar(str,'/',',');
for (i = 0; i < strlen(str); i++)
if (str[i] == ',') len++;
memset(ufs,0,len);
for (i = 0; i < len; i++)
ufs[i] = (char *)malloc(sizeof(char *));
i = 0;
r = strtok(str,",");
while (r != NULL) {
strcpy((char *)ufs[i],(char *)r);
r = strtok(NULL,",");
i++;
}
int k = 0;
int max_thread = 12;
for (i = 0; i < thread_num; i++) {
k = (i < thread_num/2)?i:(max_thread/2+i-thread_num/2);
generate(argv[4],argv[2],argv[3],k+1);
sleep(1);
}
for (i = 0; i < len; i++) free(ufs[i]);
return 0 ;
}
void replaceChar(char *string, char oldChar, char newChar) {
char *result = string;
int len = strlen(string);
int i;
for (i = 0; i < len; i++){
if (result[i] == oldChar){
result[i] = newChar;
}
}
strcpy(string,result);
}
void generate(char *id, char *total, char *upercent, int client) {
int i;
printf("port: %s\n",port[client]);
FILE *fw;
char filename[50] = "/home/xue/workload/";
strcat(filename,id);
strcat(filename,"/");
strcat(filename,total);
strcat(filename,"/");
strcat(filename,upercent);
strcat(filename,"/");
strcat(filename,port[client]);
strcat(filename,".txt");
fw = fopen(filename,"w+");
if(!fw) {
printf("ERROR: fail to open file %s\n",filename);
return;
}
//*generate random operations
i = 0;
int op_type,argv1,argv2;
int union_num = 0;
int split_num = 0;
int op_num = total_op;
char *command = NULL;
srand((unsigned int)time(NULL));
while (i < op_num) {
command = (char *)malloc(sizeof(char)*100);
//choose operation type:
op_type = rand()/(double)RAND_MAX*2;
if (union_op != 0 && split_op != 0) {
if (op_type == OP_UNION && union_num == union_op)
op_type = OP_SPLIT;
if (op_type == OP_SPLIT && split_num == split_op)
op_type = OP_UNION;
}
if (op_type == OP_UNION) {
argv1 = rand()/(double)RAND_MAX*len;
argv2 = rand()/(double)RAND_MAX*len;
strcpy(command,"union ");
strcat(command,ufs[argv1]);
strcat(command," ");
strcat(command,ufs[argv2]);
strcat(command," ");
strcat(command,key_list[key]);
union_num++;
} else {
argv1 = rand()/(double)RAND_MAX*len;
strcpy(command,"split ");
strcat(command,ufs[argv1]);
strcat(command," ");
strcat(command,key_list[key]);
split_num++;
}
strcat(command,"\n");
fputs(command,fw);
free(command);
i++;
}
fclose(fw);
}
|
the_stack_data/14199798.c | /* This testcase is part of GDB, the GNU debugger.
Copyright 2015-2017 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This 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 program. If not, see <http://www.gnu.org/licenses/>. */
#include <stdlib.h>
void
shlib_second (int dummy)
{ /* second-retry */
abort (); /* second-hit */
}
void
shlib_first (void)
{ /* first-retry */
shlib_second (0); /* first-hit */
}
|
the_stack_data/148864.c | #include <stdio.h>
int main(void)
{
printf("%d\n");
} |
the_stack_data/184518592.c | /*BEGIN_LEGAL
Intel Open Source License
Copyright (c) 2002-2013 Intel Corporation. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer. Redistributions
in binary form must reproduce the above copyright notice, this list of
conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution. Neither the name of
the Intel Corporation nor the names of its contributors may be used to
endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR
ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
END_LEGAL */
// features.h does not exist on FreeBSD
#ifndef TARGET_BSD
// features initializes the system's state, including the state of __USE_GNU
#include <features.h>
#endif
// If __USE_GNU is defined, we don't need to do anything.
// If we defined it ourselves, we need to undefine it later.
#ifndef __USE_GNU
#define __USE_GNU
#define APP_UNDEF_USE_GNU
#endif
#include <ucontext.h>
// If we defined __USE_GNU ourselves, we need to undefine it here.
#ifdef APP_UNDEF_USE_GNU
#undef __USE_GNU
#undef APP_UNDEF_USE_GNU
#endif
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#ifdef TARGET_IA32
#define REG_IP REG_EIP
#else
#define REG_IP REG_RIP
#endif
void *DivideByZeroRetPoint;
int DivideByZero()
{
unsigned int i;
volatile unsigned int zero = 0;
fprintf(stderr, "Going to divide by zero\n");
i = 1 / zero;
return i/i;
}
#define DIV_OPCODE 0xf7
#define MODRM_REG 0xc0
#define MODRM_DISP8 0x40
#define MODRM_DISP32 0x80
#define IS_REG_MODE(modrmByte) ((modrmByte & MODRM_REG) == MODRM_REG)
#define IS_DISP8_MODE(modrmByte) ((modrmByte & MODRM_DISP8) == MODRM_DISP8)
#define IS_DISP32_MODE(modrmByte) ((modrmByte & MODRM_DISP32) == MODRM_DISP32)
void div0_signal_handler(int signum, siginfo_t *siginfo, void *uctxt)
{
printf("Inside div0 handler\n");
ucontext_t *frameContext = (ucontext_t *)uctxt;
unsigned char *bytes = (unsigned char *)frameContext->uc_mcontext.gregs[REG_IP];
if (bytes[0] == DIV_OPCODE)
{
if (IS_REG_MODE(bytes[1]))
{
printf("div %reg instruction\n");
// set IP pointing to the next instruction
frameContext->uc_mcontext.gregs[REG_IP] += 2;
return;
}
if (IS_DISP8_MODE(bytes[1]))
{
printf("div mem8 instruction\n");
// set IP pointing to the next instruction
frameContext->uc_mcontext.gregs[REG_IP] += 3;
return;
}
if (IS_DISP32_MODE(bytes[1]))
{
printf("div mem32 instruction\n");
// set IP pointing to the next instruction
frameContext->uc_mcontext.gregs[REG_IP] += 6;
return;
}
}
printf("Unexpected instruction at address 0x%lx\n", (unsigned long)frameContext->uc_mcontext.gregs[REG_IP]);
exit(-1);
}
int main()
{
int ret;
struct sigaction sSigaction;
/* Register the signal hander using the siginfo interface*/
sSigaction.sa_sigaction = div0_signal_handler;
sSigaction.sa_flags = SA_SIGINFO;
/* mask all other signals */
sigfillset(&sSigaction.sa_mask);
ret = sigaction(SIGFPE, &sSigaction, NULL);
if(ret)
{
perror("ERROR, sigaction failed");
exit(-1);
}
if(DivideByZero() != 1)
{
exit (-1);
}
return 0;
}
|
the_stack_data/165764836.c | /**/
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
int value, digit;
printf("\nEnter an integer > ");
scanf("%d", &value);
printf("\n");
if (value>0){
while (value!=0) {
digit=value%10;
value=value/10;
printf("%d\n", digit);
}
}
else if (value<0) {
value=abs(value);
while (value>10){
digit=value%10;
value=value/10;
printf("%d\n", digit);
}
digit=value%10;
printf("-%d\n", digit);
}
else if (value==0) {
digit=value;
printf("%d\n", digit);
}
printf("That's all, have a nice day!\n");
return(0);
}
|
the_stack_data/76699798.c | #include <stdio.h>
int main(void)
{
int num,i,is_prime;
printf("Enter a number to test: ");
scanf("%d",&num);
is_prime=1;
for(i=2;i<=num/2;i++)
if((num%i)==0) is_prime=0;
if(is_prime==1)
printf("The number is prime.\n");
else
printf("The number is not prime .\n");
}
|
the_stack_data/120226.c | #include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>
#include <dirent.h>
#include <string.h>
#include <unistd.h>
#include <time.h>
char *get_ago( time_t *t ) {
struct tm *last_modified;
last_modified = localtime( t );
char *ago = malloc( sizeof( char ) * 20 );
time_t current_time = time( NULL );
time_t file_time = mktime( last_modified );
int offset = current_time - file_time;
if( offset < 59 )
sprintf( ago, "%d secs ago", offset );
else if( offset > 59 && offset < 3600 ) {
int min = offset / 60;
sprintf( ago, "%d min ago", min );
}
else if( offset > 3600 && offset < 86400 ) {
int hour = offset / 3600;
sprintf( ago, "%d %s ago", hour, hour > 1 ? "hours" : "hour" );
}
else if( offset > 86400 ) {
int days = offset / 86400;
if( days < 31 )
sprintf( ago, "%d %s ago", days, days > 1 ? "days" : "day" );
else if( days > 31 && days < 365 ) {
int month = days / 31;
sprintf( ago, "%d %s ago", month, month > 1 ? "months" : "month" );
}
else {
int years = days / 365;
sprintf( ago, "%d %s ago", years, years > 1 ? "years" : "year" );
}
}
return ago;
}
void list_files( char *dir, _Bool recurse, _Bool show_all ) {
DIR *d;
struct dirent *dir_info;
struct stat f_stat;
char *ago;
if( ( d = opendir( dir ) ) == NULL ) {
perror( "Dir error" );
exit(1);
}
while( ( dir_info = readdir( d ) ) != NULL ) {
char *filename = ( char* ) malloc( PATH_MAX +1 );
strcpy( filename, dir );
if( filename[ strlen( filename )-1 ] != '/' )
strcat( filename, "/" );
strcat( filename, dir_info->d_name );
if( stat( filename, &f_stat ) < 0 )
perror( filename );
if( S_ISDIR( f_stat.st_mode ) && recurse && ( strcmp( dir_info->d_name, "." ) && strcmp( dir_info->d_name, ".." ) ) ) {
list_files( filename, recurse, show_all );
}
else {
if( !show_all && dir_info->d_name[0] == '.' )
continue;
ago = get_ago( &f_stat.st_mtime );
if( S_ISLNK( f_stat.st_mode ) )
printf( "l" );
else if( S_ISDIR( f_stat.st_mode ) )
printf( "d" );
else
printf( "-" );
printf( "%c%c%c",
f_stat.st_mode & S_IRUSR ? 'r' : '-',
f_stat.st_mode & S_IWUSR ? 'w' : '-',
f_stat.st_mode & S_IXUSR ? 'x' : '-'
);
printf( "%c%c%c",
f_stat.st_mode & S_IRGRP ? 'r' : '-',
f_stat.st_mode & S_IWGRP ? 'w' : '-',
f_stat.st_mode & S_IXGRP ? 'x' : '-'
);
printf( "%c%c%c\t\t",
f_stat.st_mode & S_IROTH ? 'r' : '-',
f_stat.st_mode & S_IWOTH ? 'w' : '-',
f_stat.st_mode & S_IXOTH ? 'x' : '-'
);
printf( "%10d\t\t", f_stat.st_size );
printf( "%-15s\t\t", ago );
printf("%s", dir_info->d_name );
printf( "\n" );
free( ago );
}
free( filename );
}
closedir( d );
}
void main( int argc, char * argv[] ) {
_Bool recurse = 0, show_all = 0;
char arg;
while( ( arg = getopt( argc, argv, "ra" ) ) != EOF ) {
switch( arg ) {
case 'r':
recurse = 1;
break;
case 'a':
show_all = 1;
break;
case '?':
fprintf( stderr, "Invalid option %c", optopt );
}
}
argv += optind;
argc -= optind;
if( argc == 0 )
list_files( "./", recurse, show_all );
else {
while( argc-- ) {
char *path_name = *argv++;
list_files( path_name, recurse, show_all );
}
}
} |
the_stack_data/107560.c | /* Example code for Exercises in C.
This program shows a way to represent a BigInt type (arbitrary length integers)
using C strings, with numbers represented as a string of decimal digits in reverse order.
Follow these steps to get this program working:
1) Read through the whole program so you understand the design.
2) Compile and run the program. It should run three tests, and they should fail.
3) Fill in the body of reverse_string(). When you get it working, the first test should pass.
4) Fill in the body of itoc(). When you get it working, the second test should pass.
5) Fill in the body of add_digits(). When you get it working, the third test should pass.
6) Uncomment the last test in main. If your three previous tests pass, this one should, too.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <assert.h>
/* reverse_string: Returns a new string with the characters reversed.
It is the caller's responsibility to free the result.
s: string
returns: string
*/
char *reverse_string(char *s) {
char* reversed = malloc(sizeof(char) * strlen(s));
int index = strlen(s) - 1;
int i;
// Iterate through the string and assign the characters in the
// reverse order to the variable 'reversed'.
for (i=0; i<strlen(s); i++) {
reversed[i] = s[index];
index--;
}
return reversed;
}
/* ctoi: Converts a character to integer.
c: one of the characters '0' to '9'
returns: integer 0 to 9
*/
int ctoi(char c) {
assert(isdigit(c));
return c - '0';
}
/* itoc: Converts an integer to character.
i: integer 0 to 9
returns: character '0' to '9'
*/
char itoc(int i) {
assert(i>=0 && i<=9);
return i + '0';
}
/* add_digits: Adds two decimal digits, returns the total and carry.
For example, if a='5', b='6', and carry='1', the sum is 12, so
the output value of total should be '2' and carry should be '1'
a: character '0' to '9'
b: character '0' to '9'
c: character '0' to '9'
total: pointer to char
carry: pointer to char
*/
void add_digits(char a, char b, char c, char *total, char *carry) {
// Convert the given characters to integers and sum them.
int sum = ctoi(a) + ctoi(b) + ctoi(c);
// Get the correct digit for each output value and convert to char
*total = itoc(sum % 10);
*carry = itoc(sum / 10);
}
/* Define a type to represent a BigInt.
Internally, a BigInt is a string of digits, with the digits in
reverse order.
*/
typedef char * BigInt;
/* add_bigint: Adds two BigInts
Stores the result in z.
x: BigInt
y: BigInt
carry_in: char
z: empty buffer
*/
void add_bigint(BigInt x, BigInt y, char carry_in, BigInt z) {
char total, carry_out;
int dx=1, dy=1, dz=1;
char a, b;
/* OPTIONAL TODO: Modify this function to allocate and return z
* rather than taking an empty buffer as a parameter.
* Hint: you might need a helper function.
*/
if (*x == '\0') {
a = '0';
dx = 0;
}else{
a = *x;
}
if (*y == '\0') {
b = '0';
dy = 0;
}else{
b = *y;
}
// printf("%c %c %c\n", a, b, carry_in);
add_digits(a, b, carry_in, &total, &carry_out);
// printf("%c %c\n", carry_out, total);
// if total and carry are 0, we're done
if (total == '0' && carry_out == '0') {
*z = '\0';
return;
}
// otherwise store the digit we just computed
*z = total;
// and make a recursive call to fill in the rest.
add_bigint(x+dx, y+dy, carry_out, z+dz);
}
/* print_bigint: Prints the digits of BigInt in the normal order.
big: BigInt
*/
void print_bigint(BigInt big) {
char c = *big;
if (c == '\0') return;
print_bigint(big+1);
printf("%c", c);
}
/* make_bigint: Creates and returns a BigInt.
Caller is responsible for freeing.
s: string of digits in the usual order
returns: BigInt
*/
BigInt make_bigint(char *s) {
char *r = reverse_string(s);
return (BigInt) r;
}
void test_reverse_string() {
char *s = "123";
char *t = reverse_string(s);
if (strcmp(t, "321") == 0) {
printf("reverse_string passed\n");
} else {
printf("reverse_string failed\n");
}
}
void test_itoc() {
char c = itoc(3);
if (c == '3') {
printf("itoc passed\n");
} else {
printf("itoc failed\n");
}
}
void test_add_digits() {
char total, carry;
add_digits('7', '4', '1', &total, &carry);
if (total == '2' && carry == '1') {
printf("add_digits passed\n");
} else {
printf("add_digits failed\n");
}
}
void test_add_bigint() {
char *s = "1";
char *t = "99999999999999999999999999999999999999999999";
char *res = "000000000000000000000000000000000000000000001";
BigInt big1 = make_bigint(s);
BigInt big2 = make_bigint(t);
BigInt big3 = malloc(100);
add_bigint(big1, big2, '0', big3);
if (strcmp(big3, res) == 0) {
printf("add_bigint passed\n");
} else {
printf("add_bigint failed\n");
}
}
int main (int argc, char *argv[])
{
test_reverse_string();
test_itoc();
test_add_digits();
//TODO: When you have the first three functions working,
// uncomment the following, and it should work.
test_add_bigint();
return 0;
}
|
the_stack_data/28797.c | #include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#define MAX_EXTRACT_NUMBER 512
int main( int argc, char *argv[] ) {
FILE *source, *dest, *fileTable;
uint32_t totalSize, address, checkValue, fileSize;
char filenameBuffer[256], *fileBuffer;
uint32_t addresses[MAX_EXTRACT_NUMBER];
int i, noOfElements;
const uint32_t tim_header = 16;
const uint32_t tim_4bpp = 8;
const uint32_t tim_8bpp = 9;
const uint32_t tim_16bpp = 2;
const uint32_t tim_24bpp = 3;
if (argc != 2) {
printf("Usage: extractor.exe filename\nExample: extractor.exe 0001");
return -1;
}
source = fopen(argv[1], "rb");
if (!source) {
printf("Error opening file %s", argv[1]);
return -1;
}
//get file total size
fseek(source, 0L, SEEK_END);
totalSize = ftell(source);
fileBuffer = (char*) malloc(sizeof(char)* totalSize);
noOfElements = 0;
address = 0;
fseek(source, 0, SEEK_SET);
while(fread(&checkValue, sizeof(uint32_t), 1, source) != 0) {
//if I found a possible tim header, try to next next 32 bit block if there's a valid header.
if (checkValue == tim_header) {
if (fread(&checkValue, sizeof(uint32_t), 1, source) != 0) {
if ( checkValue == tim_4bpp || checkValue == tim_8bpp || checkValue == tim_16bpp || checkValue == tim_24bpp ) {
//found it!
printf("Found possible TIM file at 0x%.4x\n", address);
addresses[noOfElements] = address;
noOfElements++;
}
}
address+= sizeof(uint32_t);
}
address+= sizeof(uint32_t);
}
printf("Found %d possible TIM images in this file\n", noOfElements);
sprintf(filenameBuffer, "%s_filetable.txt", argv[1]);
fileTable = fopen(filenameBuffer, "w");
for (i=0; i< noOfElements; i++) {
if (i!=noOfElements-1) {
//read until next register
fileSize = addresses[i+1] - addresses[i];
} else {
//read until EOF
fileSize = totalSize - addresses[i];
}
sprintf(filenameBuffer, "%s_extract_%d.tim", argv[1], i);
printf("Extracting %s, %d bytes ...\n", filenameBuffer, fileSize);
fprintf(fileTable, "%d\n", addresses[i]);
//read packed file from source
fseek(source, addresses[i] , SEEK_SET );
fread(fileBuffer, fileSize, 1, source);
//write at destiny file
dest = fopen(filenameBuffer, "wb");
if (!dest) {
printf("Error writing file %s. Did you have write permission here?", filenameBuffer);
fclose(source);
return -1;
}
fwrite(fileBuffer, fileSize, 1, dest);
fclose(dest);
}
//done
fclose(fileTable);
fclose(source);
printf("%d files processed correctly!\n", noOfElements);
return 0;
} |
the_stack_data/86075501.c | #include"stdio.h"
#include"sys/types.h"
#include"unistd.h"
#include"stdlib.h"
#include"sys/wait.h"
int main()
{
int pid = fork();
if(pid == 0)
execl("bin/ls","ls","-l",NULL);
}
|
the_stack_data/153269589.c | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
char* longest(char* s1, char* s2) {
char leters[26]="00000000000000000000000000";
int posLeter;
int pos = 0;
char car = s1[pos];
while(car != '\0'){
posLeter = car - 97;
leters[posLeter] = posLeter + 97;
pos++;
car = s1[pos];
}
pos = 0;
car = s2[pos];
while(car != '\0'){
posLeter = car - 97;
leters[posLeter] = posLeter + 97;
pos++;
car = s2[pos];
}
pos = 0;
for(int i = 0; i < 26; i++){
if(leters[i] != '0'){
leters[pos] = leters[i];
pos++;
}
}
leters[pos] = '\0';
return leters;
}
void dotest(char* s1, char* s2, char *expr)
{
char *act = longest(s1, s2);
if(strcmp(act, expr) != 0)
printf("\n%s\n%s\n\n", expr, act);
}
int main(){
dotest("aretheyhere", "yestheyarehere", "aehrsty");
dotest("loopingisfunbutdangerous", "lessdangerousthancoding", "abcdefghilnoprstu");
dotest("inmanylanguages", "theresapairoffunctions", "acefghilmnoprstuy");
dotest("lordsofthefallen", "gamekult", "adefghklmnorstu");
dotest("codewars", "codewars", "acdeorsw");
return 0;
} |
the_stack_data/241751.c | /*
* Generated with test/generate_buildtest.pl, to check that such a simple
* program builds.
*/
#include <openssl/opensslconf.h>
#ifndef OPENSSL_NO_STDIO
# include <stdio.h>
#endif
#ifndef OPENSSL_NO_OCSP
# include <openssl/ocsp.h>
#endif
int main()
{
return 0;
}
|
the_stack_data/348724.c | /******************************************************************************
* Copyright (c) 1990, 1991, 1992,
* National Aeronautics and Space Administration
* ALL RIGHTS RESERVED
*
* The software (programs, data bases and/or documentation) on or in
* any media can not be reproduced, disclosed or used except under
* terms of the license between COSMIC and your organization.
*****************************************************************************/
#ifndef FORTRAN
static int dummy; /* prevent ranlib from complaining */
#else
C ***** DO NOT USE TABS OF FORMFEEDS IN ANY UNIX FORTRAN FILES *****
C
C XZINIT. FORTRAN CALLABLE ROUTINE .
C WRITTEN IN FORTRAN TO AVOID PROBLEM OF CONVERTING A C STRING
C TO A FORTRAN-77 STRING (FOR THE STANDARD OUTPUT FILE NAME ).
C
C
C CHANGE LOG:
C
C 29-MAR-83 HARDCODE PGMINC.FIN...DM
C 30-SEP-83 STORE TERMINAL TYPE, GETTERM -> XUGETT...peb
C 15-NOV-83 LIMIT VARIABLE NAMES TO 6 CHARS FOR PORTABILITY...dm
C 17-NOV-83 Add call to xzcall...palm
C 30-NOV-83 MODIFY FOR UNIX/F77 COMPATIBILITY
C 02-DEC-83 Fix bug in XRSTR calling sequence...dm
C 06-DEC-83 Save XZSAVL common block explicitely...dm
C 08-DEC-83 Do not open terminal as stdout using LUN 6...dm
C 10-MAY-84 Position file at the end in APPEND mode...dm
C 22-MAY-84 Convert file name to lower case...dm
C 21-AUG-84 Make xzinit portable, Isolate non-portable
C routines to different source module...dm
C 01-APR-88 - APOLLO conversion requires all Fortran files to have
C ** NO TABS ** and ** NO FORMFEEDS **!!!
C - Fortran files now go through C pre-processor...ljn
C 23-JUL-91 PR325: Change STDLUN to LUN in PREOPN...ljn
C
C
SUBROUTINE XZINIT(BLOCK, DIM, STDLUN, MODE, STATUS)
#include "pgminc.fin"
INTEGER BLOCK(1)
INTEGER DIM
INTEGER STDLUN
INTEGER MODE
INTEGER STATUS
CHARACTER*(xfssiz) STDREC(2)
CHARACTER*(xfssiz) TERMNM
INTEGER LENGTH(2)
INTEGER COUNT
LOGICAL NEWFIL
LOGICAL OPENED
INTEGER L
INTEGER LINES, COLS
LOGICAL TERMNL
INTEGER TTYPE
STATUS = xsucc
CALL SETLUN(STDLUN)
CALL XRINIM(BLOCK, DIM, MODE, STATUS)
IF (STATUS .NE. xsucc) RETURN
CALL XZCALL(BLOCK)
CALL XRSTR(BLOCK, '_STDOUT', 2, STDREC, LENGTH,
+ COUNT, STATUS)
IF (STATUS. NE. xsucc) RETURN
NEWFIL = .TRUE.
IF (STDREC(2) .NE. 'CREATE') NEWFIL = .FALSE.
C
CALL XUGETT(TERMNM)
IF (TERMNM .EQ. STDREC(1)) THEN
TERMNL = .TRUE.
ELSE
TERMNL = .FALSE.
ENDIF
CALL SETSTD(TERMNL)
CALL XTINIT(TTYPE, LINES, COLS)
C
C Prepare to open the standard output file, and make sure that
C it is not already open.
C
OPENED = .FALSE.
CALL PREOPN(LUN, STDREC(1), OPENED)
IF (OPENED) RETURN
CALL OPNSTD(STDREC(1), NEWFIL, OPENED)
IF (.NOT. OPENED) THEN
c Don't fail simply because stdout couldn't be opened, so that we can
c run from something other than a terminal without triggering shell-vicar
ccccc STATUS = xfail
IF (MODE .EQ. xabort) THEN
CALL XTWRIT('Could not open standard output file '
1 / / STDREC(1)(1:L), xccstd)
CALL XZEXIT(-1, 'TAE-STDOPN')
ENDIF
ENDIF
RETURN
END
C
C OPNSTD. Fortran open for an output file.
C
SUBROUTINE OPNSTD(FILENM, NEWFIL, OPENED)
CHARACTER*(*) FILENM
LOGICAL NEWFIL
LOGICAL OPENED
CHARACTER*132 DUMMY
CHARACTER*4 STAT
INTEGER LUN
LOGICAL TERMNL
CALL GETLUN_TAE(LUN)
CALL GETSTD(TERMNL)
IF (NEWFIL) THEN
STAT = 'NEW'
ELSE
STAT = 'OLD'
ENDIF
OPEN (FILE=FILENM, UNIT=LUN, STATUS=STAT, ERR=200)
OPENED = .TRUE.
IF (NEWFIL .OR. TERMNL) THEN
RETURN
ENDIF
C
C IF OLD FILE, POSITION AT THE END.
C
999 CONTINUE
READ(UNIT=LUN, FMT=101, END=150, ERR=150) DUMMY
101 FORMAT (A)
GOTO 999
150 RETURN
200 CONTINUE
OPENED = .FALSE.
RETURN
END
#endif
|
the_stack_data/27781.c | /* f2c.h -- Standard Fortran to C header file */
/** barf [ba:rf] 2. "He suggested using FORTRAN, and everybody barfed."
- From The Shogakukan DICTIONARY OF NEW ENGLISH (Second edition) */
#ifndef F2C_INCLUDE
#define F2C_INCLUDE
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <complex.h>
#ifdef complex
#undef complex
#endif
#ifdef I
#undef I
#endif
#if defined(_WIN64)
typedef long long BLASLONG;
typedef unsigned long long BLASULONG;
#else
typedef long BLASLONG;
typedef unsigned long BLASULONG;
#endif
#ifdef LAPACK_ILP64
typedef BLASLONG blasint;
#if defined(_WIN64)
#define blasabs(x) llabs(x)
#else
#define blasabs(x) labs(x)
#endif
#else
typedef int blasint;
#define blasabs(x) abs(x)
#endif
typedef blasint integer;
typedef unsigned int uinteger;
typedef char *address;
typedef short int shortint;
typedef float real;
typedef double doublereal;
typedef struct { real r, i; } complex;
typedef struct { doublereal r, i; } doublecomplex;
static inline _Complex float Cf(complex *z) {return z->r + z->i*_Complex_I;}
static inline _Complex double Cd(doublecomplex *z) {return z->r + z->i*_Complex_I;}
static inline _Complex float * _pCf(complex *z) {return (_Complex float*)z;}
static inline _Complex double * _pCd(doublecomplex *z) {return (_Complex double*)z;}
#define pCf(z) (*_pCf(z))
#define pCd(z) (*_pCd(z))
typedef int logical;
typedef short int shortlogical;
typedef char logical1;
typedef char integer1;
#define TRUE_ (1)
#define FALSE_ (0)
/* Extern is for use with -E */
#ifndef Extern
#define Extern extern
#endif
/* I/O stuff */
typedef int flag;
typedef int ftnlen;
typedef int ftnint;
/*external read, write*/
typedef struct
{ flag cierr;
ftnint ciunit;
flag ciend;
char *cifmt;
ftnint cirec;
} cilist;
/*internal read, write*/
typedef struct
{ flag icierr;
char *iciunit;
flag iciend;
char *icifmt;
ftnint icirlen;
ftnint icirnum;
} icilist;
/*open*/
typedef struct
{ flag oerr;
ftnint ounit;
char *ofnm;
ftnlen ofnmlen;
char *osta;
char *oacc;
char *ofm;
ftnint orl;
char *oblnk;
} olist;
/*close*/
typedef struct
{ flag cerr;
ftnint cunit;
char *csta;
} cllist;
/*rewind, backspace, endfile*/
typedef struct
{ flag aerr;
ftnint aunit;
} alist;
/* inquire */
typedef struct
{ flag inerr;
ftnint inunit;
char *infile;
ftnlen infilen;
ftnint *inex; /*parameters in standard's order*/
ftnint *inopen;
ftnint *innum;
ftnint *innamed;
char *inname;
ftnlen innamlen;
char *inacc;
ftnlen inacclen;
char *inseq;
ftnlen inseqlen;
char *indir;
ftnlen indirlen;
char *infmt;
ftnlen infmtlen;
char *inform;
ftnint informlen;
char *inunf;
ftnlen inunflen;
ftnint *inrecl;
ftnint *innrec;
char *inblank;
ftnlen inblanklen;
} inlist;
#define VOID void
union Multitype { /* for multiple entry points */
integer1 g;
shortint h;
integer i;
/* longint j; */
real r;
doublereal d;
complex c;
doublecomplex z;
};
typedef union Multitype Multitype;
struct Vardesc { /* for Namelist */
char *name;
char *addr;
ftnlen *dims;
int type;
};
typedef struct Vardesc Vardesc;
struct Namelist {
char *name;
Vardesc **vars;
int nvars;
};
typedef struct Namelist Namelist;
#define abs(x) ((x) >= 0 ? (x) : -(x))
#define dabs(x) (fabs(x))
#define f2cmin(a,b) ((a) <= (b) ? (a) : (b))
#define f2cmax(a,b) ((a) >= (b) ? (a) : (b))
#define dmin(a,b) (f2cmin(a,b))
#define dmax(a,b) (f2cmax(a,b))
#define bit_test(a,b) ((a) >> (b) & 1)
#define bit_clear(a,b) ((a) & ~((uinteger)1 << (b)))
#define bit_set(a,b) ((a) | ((uinteger)1 << (b)))
#define abort_() { sig_die("Fortran abort routine called", 1); }
#define c_abs(z) (cabsf(Cf(z)))
#define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); }
#define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);}
#define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);}
#define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));}
#define c_log(R, Z) {pCf(R) = clogf(Cf(Z));}
#define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));}
//#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));}
#define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));}
#define d_abs(x) (fabs(*(x)))
#define d_acos(x) (acos(*(x)))
#define d_asin(x) (asin(*(x)))
#define d_atan(x) (atan(*(x)))
#define d_atn2(x, y) (atan2(*(x),*(y)))
#define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); }
#define r_cnjg(R, Z) { pCf(R) = conj(Cf(Z)); }
#define d_cos(x) (cos(*(x)))
#define d_cosh(x) (cosh(*(x)))
#define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 )
#define d_exp(x) (exp(*(x)))
#define d_imag(z) (cimag(Cd(z)))
#define r_imag(z) (cimag(Cf(z)))
#define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
#define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
#define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
#define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
#define d_log(x) (log(*(x)))
#define d_mod(x, y) (fmod(*(x), *(y)))
#define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x)))
#define d_nint(x) u_nint(*(x))
#define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a)))
#define d_sign(a,b) u_sign(*(a),*(b))
#define r_sign(a,b) u_sign(*(a),*(b))
#define d_sin(x) (sin(*(x)))
#define d_sinh(x) (sinh(*(x)))
#define d_sqrt(x) (sqrt(*(x)))
#define d_tan(x) (tan(*(x)))
#define d_tanh(x) (tanh(*(x)))
#define i_abs(x) abs(*(x))
#define i_dnnt(x) ((integer)u_nint(*(x)))
#define i_len(s, n) (n)
#define i_nint(x) ((integer)u_nint(*(x)))
#define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b)))
#define pow_dd(ap, bp) ( pow(*(ap), *(bp)))
#define pow_si(B,E) spow_ui(*(B),*(E))
#define pow_ri(B,E) spow_ui(*(B),*(E))
#define pow_di(B,E) dpow_ui(*(B),*(E))
#define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));}
#define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));}
#define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));}
#define s_cat(lpp, rpp, rnp, np, llp) { ftnlen i, nc, ll; char *f__rp, *lp; ll = (llp); lp = (lpp); for(i=0; i < (int)*(np); ++i) { nc = ll; if((rnp)[i] < nc) nc = (rnp)[i]; ll -= nc; f__rp = (rpp)[i]; while(--nc >= 0) *lp++ = *(f__rp)++; } while(--ll >= 0) *lp++ = ' '; }
#define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d))))
#define s_copy(A,B,C,D) { int __i,__m; for (__i=0, __m=f2cmin((C),(D)); __i<__m && (B)[__i] != 0; ++__i) (A)[__i] = (B)[__i]; }
#define sig_die(s, kill) { exit(1); }
#define s_stop(s, n) {exit(0);}
static char junk[] = "\n@(#)LIBF77 VERSION 19990503\n";
#define z_abs(z) (cabs(Cd(z)))
#define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));}
#define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
#define myexit_() break;
#define mycycle() continue;
#define myceiling(w) {ceil(w)}
#define myhuge(w) {HUGE_VAL}
//#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
#define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)}
/* procedure parameter types for -A and -C++ */
#define F2C_proc_par_types 1
#ifdef __cplusplus
typedef logical (*L_fp)(...);
#else
typedef logical (*L_fp)();
#endif
static float spow_ui(float x, integer n) {
float pow=1.0; unsigned long int u;
if(n != 0) {
if(n < 0) n = -n, x = 1/x;
for(u = n; ; ) {
if(u & 01) pow *= x;
if(u >>= 1) x *= x;
else break;
}
}
return pow;
}
static double dpow_ui(double x, integer n) {
double pow=1.0; unsigned long int u;
if(n != 0) {
if(n < 0) n = -n, x = 1/x;
for(u = n; ; ) {
if(u & 01) pow *= x;
if(u >>= 1) x *= x;
else break;
}
}
return pow;
}
static _Complex float cpow_ui(_Complex float x, integer n) {
_Complex float pow=1.0; unsigned long int u;
if(n != 0) {
if(n < 0) n = -n, x = 1/x;
for(u = n; ; ) {
if(u & 01) pow *= x;
if(u >>= 1) x *= x;
else break;
}
}
return pow;
}
static _Complex double zpow_ui(_Complex double x, integer n) {
_Complex double pow=1.0; unsigned long int u;
if(n != 0) {
if(n < 0) n = -n, x = 1/x;
for(u = n; ; ) {
if(u & 01) pow *= x;
if(u >>= 1) x *= x;
else break;
}
}
return pow;
}
static integer pow_ii(integer x, integer n) {
integer pow; unsigned long int u;
if (n <= 0) {
if (n == 0 || x == 1) pow = 1;
else if (x != -1) pow = x == 0 ? 1/x : 0;
else n = -n;
}
if ((n > 0) || !(n == 0 || x == 1 || x != -1)) {
u = n;
for(pow = 1; ; ) {
if(u & 01) pow *= x;
if(u >>= 1) x *= x;
else break;
}
}
return pow;
}
static integer dmaxloc_(double *w, integer s, integer e, integer *n)
{
double m; integer i, mi;
for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
if (w[i-1]>m) mi=i ,m=w[i-1];
return mi-s+1;
}
static integer smaxloc_(float *w, integer s, integer e, integer *n)
{
float m; integer i, mi;
for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
if (w[i-1]>m) mi=i ,m=w[i-1];
return mi-s+1;
}
static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
integer n = *n_, incx = *incx_, incy = *incy_, i;
_Complex float zdotc = 0.0;
if (incx == 1 && incy == 1) {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += conjf(Cf(&x[i])) * Cf(&y[i]);
}
} else {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]);
}
}
pCf(z) = zdotc;
}
static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
integer n = *n_, incx = *incx_, incy = *incy_, i;
_Complex double zdotc = 0.0;
if (incx == 1 && incy == 1) {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += conj(Cd(&x[i])) * Cd(&y[i]);
}
} else {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]);
}
}
pCd(z) = zdotc;
}
static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
integer n = *n_, incx = *incx_, incy = *incy_, i;
_Complex float zdotc = 0.0;
if (incx == 1 && incy == 1) {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += Cf(&x[i]) * Cf(&y[i]);
}
} else {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]);
}
}
pCf(z) = zdotc;
}
static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
integer n = *n_, incx = *incx_, incy = *incy_, i;
_Complex double zdotc = 0.0;
if (incx == 1 && incy == 1) {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += Cd(&x[i]) * Cd(&y[i]);
}
} else {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]);
}
}
pCd(z) = zdotc;
}
#endif
/* -- translated by f2c (version 20000121).
You must link the resulting object file with the libraries:
-lf2c -lm (in that order)
*/
/* Table of constant values */
static integer c__1 = 1;
/* > \brief \b ZLANSB returns the value of the 1-norm, or the Frobenius norm, or the infinity norm, or the ele
ment of largest absolute value of a symmetric band matrix. */
/* =========== DOCUMENTATION =========== */
/* Online html documentation available at */
/* http://www.netlib.org/lapack/explore-html/ */
/* > \htmlonly */
/* > Download ZLANSB + dependencies */
/* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zlansb.
f"> */
/* > [TGZ]</a> */
/* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zlansb.
f"> */
/* > [ZIP]</a> */
/* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zlansb.
f"> */
/* > [TXT]</a> */
/* > \endhtmlonly */
/* Definition: */
/* =========== */
/* DOUBLE PRECISION FUNCTION ZLANSB( NORM, UPLO, N, K, AB, LDAB, */
/* WORK ) */
/* CHARACTER NORM, UPLO */
/* INTEGER K, LDAB, N */
/* DOUBLE PRECISION WORK( * ) */
/* COMPLEX*16 AB( LDAB, * ) */
/* > \par Purpose: */
/* ============= */
/* > */
/* > \verbatim */
/* > */
/* > ZLANSB returns the value of the one norm, or the Frobenius norm, or */
/* > the infinity norm, or the element of largest absolute value of an */
/* > n by n symmetric band matrix A, with k super-diagonals. */
/* > \endverbatim */
/* > */
/* > \return ZLANSB */
/* > \verbatim */
/* > */
/* > ZLANSB = ( f2cmax(abs(A(i,j))), NORM = 'M' or 'm' */
/* > ( */
/* > ( norm1(A), NORM = '1', 'O' or 'o' */
/* > ( */
/* > ( normI(A), NORM = 'I' or 'i' */
/* > ( */
/* > ( normF(A), NORM = 'F', 'f', 'E' or 'e' */
/* > */
/* > where norm1 denotes the one norm of a matrix (maximum column sum), */
/* > normI denotes the infinity norm of a matrix (maximum row sum) and */
/* > normF denotes the Frobenius norm of a matrix (square root of sum of */
/* > squares). Note that f2cmax(abs(A(i,j))) is not a consistent matrix norm. */
/* > \endverbatim */
/* Arguments: */
/* ========== */
/* > \param[in] NORM */
/* > \verbatim */
/* > NORM is CHARACTER*1 */
/* > Specifies the value to be returned in ZLANSB as described */
/* > above. */
/* > \endverbatim */
/* > */
/* > \param[in] UPLO */
/* > \verbatim */
/* > UPLO is CHARACTER*1 */
/* > Specifies whether the upper or lower triangular part of the */
/* > band matrix A is supplied. */
/* > = 'U': Upper triangular part is supplied */
/* > = 'L': Lower triangular part is supplied */
/* > \endverbatim */
/* > */
/* > \param[in] N */
/* > \verbatim */
/* > N is INTEGER */
/* > The order of the matrix A. N >= 0. When N = 0, ZLANSB is */
/* > set to zero. */
/* > \endverbatim */
/* > */
/* > \param[in] K */
/* > \verbatim */
/* > K is INTEGER */
/* > The number of super-diagonals or sub-diagonals of the */
/* > band matrix A. K >= 0. */
/* > \endverbatim */
/* > */
/* > \param[in] AB */
/* > \verbatim */
/* > AB is COMPLEX*16 array, dimension (LDAB,N) */
/* > The upper or lower triangle of the symmetric band matrix A, */
/* > stored in the first K+1 rows of AB. The j-th column of A is */
/* > stored in the j-th column of the array AB as follows: */
/* > if UPLO = 'U', AB(k+1+i-j,j) = A(i,j) for f2cmax(1,j-k)<=i<=j; */
/* > if UPLO = 'L', AB(1+i-j,j) = A(i,j) for j<=i<=f2cmin(n,j+k). */
/* > \endverbatim */
/* > */
/* > \param[in] LDAB */
/* > \verbatim */
/* > LDAB is INTEGER */
/* > The leading dimension of the array AB. LDAB >= K+1. */
/* > \endverbatim */
/* > */
/* > \param[out] WORK */
/* > \verbatim */
/* > WORK is DOUBLE PRECISION array, dimension (MAX(1,LWORK)), */
/* > where LWORK >= N when NORM = 'I' or '1' or 'O'; otherwise, */
/* > WORK is not referenced. */
/* > \endverbatim */
/* Authors: */
/* ======== */
/* > \author Univ. of Tennessee */
/* > \author Univ. of California Berkeley */
/* > \author Univ. of Colorado Denver */
/* > \author NAG Ltd. */
/* > \date December 2016 */
/* > \ingroup complex16OTHERauxiliary */
/* ===================================================================== */
doublereal zlansb_(char *norm, char *uplo, integer *n, integer *k,
doublecomplex *ab, integer *ldab, doublereal *work)
{
/* System generated locals */
integer ab_dim1, ab_offset, i__1, i__2, i__3, i__4;
doublereal ret_val;
/* Local variables */
doublereal absa;
extern /* Subroutine */ int dcombssq_(doublereal *, doublereal *);
integer i__, j, l;
extern logical lsame_(char *, char *);
doublereal value;
extern logical disnan_(doublereal *);
doublereal colssq[2];
extern /* Subroutine */ int zlassq_(integer *, doublecomplex *, integer *,
doublereal *, doublereal *);
doublereal sum, ssq[2];
/* -- LAPACK auxiliary routine (version 3.7.0) -- */
/* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
/* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
/* December 2016 */
/* ===================================================================== */
/* Parameter adjustments */
ab_dim1 = *ldab;
ab_offset = 1 + ab_dim1 * 1;
ab -= ab_offset;
--work;
/* Function Body */
if (*n == 0) {
value = 0.;
} else if (lsame_(norm, "M")) {
/* Find f2cmax(abs(A(i,j))). */
value = 0.;
if (lsame_(uplo, "U")) {
i__1 = *n;
for (j = 1; j <= i__1; ++j) {
/* Computing MAX */
i__2 = *k + 2 - j;
i__3 = *k + 1;
for (i__ = f2cmax(i__2,1); i__ <= i__3; ++i__) {
sum = z_abs(&ab[i__ + j * ab_dim1]);
if (value < sum || disnan_(&sum)) {
value = sum;
}
/* L10: */
}
/* L20: */
}
} else {
i__1 = *n;
for (j = 1; j <= i__1; ++j) {
/* Computing MIN */
i__2 = *n + 1 - j, i__4 = *k + 1;
i__3 = f2cmin(i__2,i__4);
for (i__ = 1; i__ <= i__3; ++i__) {
sum = z_abs(&ab[i__ + j * ab_dim1]);
if (value < sum || disnan_(&sum)) {
value = sum;
}
/* L30: */
}
/* L40: */
}
}
} else if (lsame_(norm, "I") || lsame_(norm, "O") || *(unsigned char *)norm == '1') {
/* Find normI(A) ( = norm1(A), since A is symmetric). */
value = 0.;
if (lsame_(uplo, "U")) {
i__1 = *n;
for (j = 1; j <= i__1; ++j) {
sum = 0.;
l = *k + 1 - j;
/* Computing MAX */
i__3 = 1, i__2 = j - *k;
i__4 = j - 1;
for (i__ = f2cmax(i__3,i__2); i__ <= i__4; ++i__) {
absa = z_abs(&ab[l + i__ + j * ab_dim1]);
sum += absa;
work[i__] += absa;
/* L50: */
}
work[j] = sum + z_abs(&ab[*k + 1 + j * ab_dim1]);
/* L60: */
}
i__1 = *n;
for (i__ = 1; i__ <= i__1; ++i__) {
sum = work[i__];
if (value < sum || disnan_(&sum)) {
value = sum;
}
/* L70: */
}
} else {
i__1 = *n;
for (i__ = 1; i__ <= i__1; ++i__) {
work[i__] = 0.;
/* L80: */
}
i__1 = *n;
for (j = 1; j <= i__1; ++j) {
sum = work[j] + z_abs(&ab[j * ab_dim1 + 1]);
l = 1 - j;
/* Computing MIN */
i__3 = *n, i__2 = j + *k;
i__4 = f2cmin(i__3,i__2);
for (i__ = j + 1; i__ <= i__4; ++i__) {
absa = z_abs(&ab[l + i__ + j * ab_dim1]);
sum += absa;
work[i__] += absa;
/* L90: */
}
if (value < sum || disnan_(&sum)) {
value = sum;
}
/* L100: */
}
}
} else if (lsame_(norm, "F") || lsame_(norm, "E")) {
/* Find normF(A). */
/* SSQ(1) is scale */
/* SSQ(2) is sum-of-squares */
/* For better accuracy, sum each column separately. */
ssq[0] = 0.;
ssq[1] = 1.;
/* Sum off-diagonals */
if (*k > 0) {
if (lsame_(uplo, "U")) {
i__1 = *n;
for (j = 2; j <= i__1; ++j) {
colssq[0] = 0.;
colssq[1] = 1.;
/* Computing MIN */
i__3 = j - 1;
i__4 = f2cmin(i__3,*k);
/* Computing MAX */
i__2 = *k + 2 - j;
zlassq_(&i__4, &ab[f2cmax(i__2,1) + j * ab_dim1], &c__1,
colssq, &colssq[1]);
dcombssq_(ssq, colssq);
/* L110: */
}
l = *k + 1;
} else {
i__1 = *n - 1;
for (j = 1; j <= i__1; ++j) {
colssq[0] = 0.;
colssq[1] = 1.;
/* Computing MIN */
i__3 = *n - j;
i__4 = f2cmin(i__3,*k);
zlassq_(&i__4, &ab[j * ab_dim1 + 2], &c__1, colssq, &
colssq[1]);
dcombssq_(ssq, colssq);
/* L120: */
}
l = 1;
}
ssq[1] *= 2;
} else {
l = 1;
}
/* Sum diagonal */
colssq[0] = 0.;
colssq[1] = 1.;
zlassq_(n, &ab[l + ab_dim1], ldab, colssq, &colssq[1]);
dcombssq_(ssq, colssq);
value = ssq[0] * sqrt(ssq[1]);
}
ret_val = value;
return ret_val;
/* End of ZLANSB */
} /* zlansb_ */
|
the_stack_data/108576.c | #if TEST___PROGNAME
int
main(void)
{
extern char *__progname;
return !__progname;
}
#endif /* TEST___PROGNAME */
#if TEST_ARC4RANDOM
#include <stdlib.h>
int
main(void)
{
return (arc4random() + 1) ? 0 : 1;
}
#endif /* TEST_ARC4RANDOM */
#if TEST_B64_NTOP
#include <netinet/in.h>
#include <resolv.h>
int
main(void)
{
const char *src = "hello world";
char output[1024];
return b64_ntop((const unsigned char *)src, 11, output, sizeof(output)) > 0 ? 0 : 1;
}
#endif /* TEST_B64_NTOP */
#if TEST_CAPSICUM
#include <sys/capsicum.h>
int
main(void)
{
cap_enter();
return(0);
}
#endif /* TEST_CAPSICUM */
#if TEST_ERR
/*
* Copyright (c) 2015 Ingo Schwarze <[email protected]>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <err.h>
int
main(void)
{
warnx("%d. warnx", 1);
warn("%d. warn", 2);
err(0, "%d. err", 3);
/* NOTREACHED */
return 1;
}
#endif /* TEST_ERR */
#if TEST_EXPLICIT_BZERO
#include <string.h>
int
main(void)
{
char foo[10];
explicit_bzero(foo, sizeof(foo));
return(0);
}
#endif /* TEST_EXPLICIT_BZERO */
#if TEST_GETPROGNAME
#include <stdlib.h>
int
main(void)
{
const char * progname;
progname = getprogname();
return progname == NULL;
}
#endif /* TEST_GETPROGNAME */
#if TEST_INFTIM
/*
* Linux doesn't (always?) have this.
*/
#include <poll.h>
#include <stdio.h>
int
main(void)
{
printf("INFTIM is defined to be %ld\n", (long)INFTIM);
return 0;
}
#endif /* TEST_INFTIM */
#if TEST_MD5
#include <sys/types.h>
#include <md5.h>
int main(void)
{
MD5_CTX ctx;
MD5Init(&ctx);
MD5Update(&ctx, "abcd", 4);
return 0;
}
#endif /* TEST_MD5 */
#if TEST_MEMMEM
#define _GNU_SOURCE
#include <string.h>
int
main(void)
{
char *a = memmem("hello, world", strlen("hello, world"), "world", strlen("world"));
return(NULL == a);
}
#endif /* TEST_MEMMEM */
#if TEST_MEMRCHR
#if defined(__linux__) || defined(__MINT__)
#define _GNU_SOURCE /* See test-*.c what needs this. */
#endif
#include <string.h>
int
main(void)
{
const char *buf = "abcdef";
void *res;
res = memrchr(buf, 'a', strlen(buf));
return(NULL == res ? 1 : 0);
}
#endif /* TEST_MEMRCHR */
#if TEST_MEMSET_S
#include <string.h>
int main(void)
{
char buf[10];
memset_s(buf, 0, 'c', sizeof(buf));
return 0;
}
#endif /* TEST_MEMSET_S */
#if TEST_PATH_MAX
/*
* POSIX allows PATH_MAX to not be defined, see
* http://pubs.opengroup.org/onlinepubs/9699919799/functions/sysconf.html;
* the GNU Hurd is an example of a system not having it.
*
* Arguably, it would be better to test sysconf(_SC_PATH_MAX),
* but since the individual *.c files include "config.h" before
* <limits.h>, overriding an excessive value of PATH_MAX from
* "config.h" is impossible anyway, so for now, the simplest
* fix is to provide a value only on systems not having any.
* So far, we encountered no system defining PATH_MAX to an
* impractically large value, even though POSIX explicitly
* allows that.
*
* The real fix would be to replace all static buffers of size
* PATH_MAX by dynamically allocated buffers. But that is
* somewhat intrusive because it touches several files and
* because it requires changing struct mlink in mandocdb.c.
* So i'm postponing that for now.
*/
#include <limits.h>
#include <stdio.h>
int
main(void)
{
printf("PATH_MAX is defined to be %ld\n", (long)PATH_MAX);
return 0;
}
#endif /* TEST_PATH_MAX */
#if TEST_PLEDGE
#include <unistd.h>
int
main(void)
{
return !!pledge("stdio", NULL);
}
#endif /* TEST_PLEDGE */
#if TEST_PROGRAM_INVOCATION_SHORT_NAME
#define _GNU_SOURCE /* See feature_test_macros(7) */
#include <errno.h>
int
main(void)
{
return !program_invocation_short_name;
}
#endif /* TEST_PROGRAM_INVOCATION_SHORT_NAME */
#if TEST_REALLOCARRAY
#include <stdlib.h>
int
main(void)
{
return !reallocarray(NULL, 2, 2);
}
#endif /* TEST_REALLOCARRAY */
#if TEST_RECALLOCARRAY
#include <stdlib.h>
int
main(void)
{
return !recallocarray(NULL, 0, 2, 2);
}
#endif /* TEST_RECALLOCARRAY */
#if TEST_SANDBOX_INIT
#include <sandbox.h>
int
main(void)
{
char *ep;
int rc;
rc = sandbox_init(kSBXProfileNoInternet, SANDBOX_NAMED, &ep);
if (-1 == rc)
sandbox_free_error(ep);
return(-1 == rc);
}
#endif /* TEST_SANDBOX_INIT */
#if TEST_SECCOMP_FILTER
#include <sys/prctl.h>
#include <linux/seccomp.h>
#include <errno.h>
int
main(void)
{
prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, 0);
return(EFAULT == errno ? 0 : 1);
}
#endif /* TEST_SECCOMP_FILTER */
#if TEST_SOCK_NONBLOCK
/*
* Linux doesn't (always?) have this.
*/
#include <sys/socket.h>
int
main(void)
{
int fd[2];
socketpair(AF_UNIX, SOCK_STREAM|SOCK_NONBLOCK, 0, fd);
return 0;
}
#endif /* TEST_SOCK_NONBLOCK */
#if TEST_STRLCAT
#include <string.h>
int
main(void)
{
char buf[3] = "a";
return ! (strlcat(buf, "b", sizeof(buf)) == 2 &&
buf[0] == 'a' && buf[1] == 'b' && buf[2] == '\0');
}
#endif /* TEST_STRLCAT */
#if TEST_STRLCPY
#include <string.h>
int
main(void)
{
char buf[2] = "";
return ! (strlcpy(buf, "a", sizeof(buf)) == 1 &&
buf[0] == 'a' && buf[1] == '\0');
}
#endif /* TEST_STRLCPY */
#if TEST_STRNDUP
#include <string.h>
int
main(void)
{
const char *foo = "bar";
char *baz;
baz = strndup(foo, 1);
return(0 != strcmp(baz, "b"));
}
#endif /* TEST_STRNDUP */
#if TEST_STRNLEN
#include <string.h>
int
main(void)
{
const char *foo = "bar";
size_t sz;
sz = strnlen(foo, 1);
return(1 != sz);
}
#endif /* TEST_STRNLEN */
#if TEST_STRTONUM
/*
* Copyright (c) 2015 Ingo Schwarze <[email protected]>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <stdlib.h>
int
main(void)
{
const char *errstr;
if (strtonum("1", 0, 2, &errstr) != 1)
return 1;
if (errstr != NULL)
return 2;
if (strtonum("1x", 0, 2, &errstr) != 0)
return 3;
if (errstr == NULL)
return 4;
if (strtonum("2", 0, 1, &errstr) != 0)
return 5;
if (errstr == NULL)
return 6;
if (strtonum("0", 1, 2, &errstr) != 0)
return 7;
if (errstr == NULL)
return 8;
return 0;
}
#endif /* TEST_STRTONUM */
#if TEST_SYSTRACE
#include <sys/param.h>
#include <dev/systrace.h>
#include <stdlib.h>
int
main(void)
{
return(0);
}
#endif /* TEST_SYSTRACE */
#if TEST_ZLIB
#include <stddef.h>
#include <zlib.h>
int
main(void)
{
gzFile gz;
if (NULL == (gz = gzopen("/dev/null", "w")))
return(1);
gzputs(gz, "foo");
gzclose(gz);
return(0);
}
#endif /* TEST_ZLIB */
|
the_stack_data/20450877.c | #include <stdio.h>
#include <string.h>
char* find(char*, char);
int main(){
char haystack[400];
char needle;
fgets(haystack, 400, stdin);
scanf("%c", &needle);
if(find(haystack, needle) != NULL){
printf("%c", *find(haystack, needle));
}
else{
printf("-1");
}
}
char* find(char *haystack, char needle){
char *ptr;
char position = 0;
for(int i = 0; i < strlen(haystack) - 1; i++){
if(haystack[i] == needle){
position = i + '0';
break;
}
}
if(position == 0)
return NULL;
else{
ptr = &position;
return ptr;
}
}
|
the_stack_data/248581376.c | /*
* Sample Program to print 5678 to 5678 678 78 8
*/
#include<stdio.h>
#include<math.h>
int main(void){
int num=5678,no;
char i;
while(num!=0){
printf("%d\t",num);
i=0;
no = num;
while(no>9){
no/=10;
i++;
}
num = num - no*pow(10,i);
}
return 0;
}
|
the_stack_data/894926.c | #include <stdio.h>
int main() {
float naira;
float dollar;
printf("Enter the amount of Naira you want to convert:");
scanf("%f", &naira);
dollar = naira / 148;
printf("The dollar equivalent of N%.2f is $%.2f", naira, dollar);
}
|
the_stack_data/153268601.c | #include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#define OK 1
#define ERROR 0
#define TRUE 1
#define FALSE 0
typedef char ElementType;
typedef struct BinNode
{
ElementType data;
struct BinNode *left, *right;
}*BinTree;
int i = 0;
int InitTree(BinTree *tree)
{
*tree = NULL;
return OK;
}
/*
按前序输入二叉树中结点的值(一个字符)
0表示空树,构造二叉链表表示二叉树T。
*/
void FillTree(BinTree *tree, const ElementType *data)
{
if (data[i] == '0')
{
*tree = NULL;
i ++;
}
else
{
*tree = (BinTree)malloc(sizeof(struct BinNode));
(*tree)->data = data[i];
i ++;
FillTree(&(*tree)->left, data);
FillTree(&(*tree)->right, data);
}
}
void ClearTree(BinTree *tree)
{
if (!*tree)
{
return;
}
ClearTree(&(*tree)->left);
ClearTree(&(*tree)->right);
free(*tree);
*tree = NULL;//这一步必须要
}
int BinTreeEmpty(BinTree tree)
{
return tree == NULL;
}
int BiTreeDepth(BinTree tree)
{
if (tree == NULL)
{
return 0;
}
int leftDepth = BiTreeDepth(tree->left);
int rightDepth = BiTreeDepth(tree->right);
return leftDepth > rightDepth ? leftDepth + 1 : rightDepth + 1;//加1表示当前层
}
int Assign(BinTree tree,ElementType value)
{
if(!tree)
{
return ERROR;
}
tree->data = value;
return OK;
}
void PreOrderTraverse(BinTree tree)
{
// 这里的!=NULL可以去掉
if (tree != NULL)
{
// 先打印
putchar(tree->data);
// 遍历左子树
PreOrderTraverse(tree->left);
// 遍历右子树
PreOrderTraverse(tree->right);
}
}
void PreOrderTraverseWithStack(BinTree tree)
{
struct
{
BinTree data[100];
int top;
}stack = {{0},-1};
while(tree || stack.top != -1)
{
while(tree)
{
putchar(tree->data);
stack.data[++stack.top] = tree;
tree = tree->left;
}
if(stack.top != -1)
{
tree = stack.data[stack.top--];
tree = tree->right;
}
}
}
void InOrderTraverse(BinTree tree)
{
if (tree)
{
InOrderTraverse(tree->left);
putchar(tree->data);
InOrderTraverse(tree->right);
}
}
void InOrderTraverseWithStack(BinTree tree)
{
struct
{
BinTree data[100];
int top;
}stack = {{0},-1};
while(tree || stack.top != -1)
{
while(tree)
{
stack.data[++stack.top] = tree;
tree = tree->left;
}
if(stack.top != -1)
{
tree = stack.data[stack.top--];
putchar(tree->data);
tree = tree->right;
}
}
}
void PostOrderTraverse(BinTree tree)
{
if (tree)
{
PostOrderTraverse(tree->left);
PostOrderTraverse(tree->right);
putchar(tree->data);
}
}
/*
my heart has broken
*/
void PostOrderTraverseWithStack(BinTree tree)
{
int post = 0;
struct
{
BinTree data[100];
int visit[100];
int top;
}stack = {{0},{0},-1};
while(tree || stack.top != -1)
{
// A
// B C
// D E F G
// H I J
// K
// stack.data: ABDH 遍历H的右子树 ABDHK 遍历K的右子树 ABDHK K的右子树遍历完成 ABDHK popup ABDH H的右子树遍历完成 ABDH popup ABD
// stack.visit:0000 00010 00011 00012 0001 0002 000
// print: K H
// 只要进入这就表示左子树已经遍历完成
// 为1时表示上面遍历的是当前树根的右子树
// 为2时表示右子树已经访问完成
while(tree)
{
stack.data[++stack.top] = tree;
tree = tree->left;
}
stack.visit[stack.top] ++;
// 打印所有的左右子树都遍历完成的节点
while(stack.visit[stack.top] == 2)
{
stack.visit[stack.top] = 0;
tree = stack.data[stack.top--];
putchar(tree->data);
if(stack.top != -1)
{
stack.visit[stack.top] ++;
}
}
if(stack.top != -1)
{
tree = stack.data[stack.top]->right;
}
else
{
tree = NULL;
}
}
}
/* 层序遍历二叉树
使用队列实现
*/
void LevelOrderTraverse(BinTree tree)
{
struct
{
BinTree data[100];
int front;
int rear;
} queue;
queue.front = queue.rear = 0;
while (tree)
{
putchar(tree->data);
if (tree->left)
{
queue.data[queue.rear++] = tree->left;
}
if (tree->right)
{
queue.data[queue.rear++] = tree->right;
}
if(queue.front != queue.rear)
{
tree = queue.data[queue.front ++];
}
// bigfix:这一步必须要,不然没有退出条件了
else
{
tree = NULL;
}
}
}
int main(int argc, char **argv)
{
struct BinNode node;
int status;
BinTree tree;
ElementType *data;
puts("init tree");
InitTree(&tree);
printf("is binary tree empty?\n%d\n", BinTreeEmpty(tree));
// 这里缺失的节点必须要用0表示,不然无法通过单独的一个前序或后续遍历来确定一个二叉树
// 可以通过中序遍历和前/后遍历(其中一个)来唯一确定一颗二叉树
data = "ABDH0K000E00CFI000G0J00";
// A
// B C
// D E F G
// H I J
// K
FillTree(&tree, data);
printf("using data:\t%s\tto fill tree\n", data);
printf("建立二叉树后,树空否?%d 树的深度=%d\n", BinTreeEmpty(tree), BiTreeDepth(tree));
printf("层序遍历二叉树:\n");
LevelOrderTraverse(tree);
puts("");
printf("前序遍历二叉树:\n");
PreOrderTraverse(tree);
puts("");
printf("前序遍历二叉树(非递归方式):\n");
PreOrderTraverseWithStack(tree);
puts("");
printf("中序遍历二叉树:\n");
InOrderTraverse(tree);
puts("");
printf("中序遍历二叉树(非递归方式):\n");
InOrderTraverseWithStack(tree);
puts("");
printf("后序遍历二叉树:\n");
PostOrderTraverse(tree);
puts("");
printf("后序遍历二叉树(非递归方式):\n");
PostOrderTraverseWithStack(tree);
puts("");
ClearTree(&tree);
printf("清除二叉树后 is binary tree empty?\n%d\n", BinTreeEmpty(tree));
// +
// + *
// a * d e
// b c
i = 0;
data = "++a00*b00c00*d00e00";
InitTree(&tree);
FillTree(&tree, data);
printf("using data:\t%s\tto fill tree\n", data);
puts("运算表达式树的遍历");
printf("前序遍历(前缀表达式):\n");
PreOrderTraverse(tree);
puts("");
printf("中序遍历(中缀表达式):\n");
InOrderTraverse(tree);
puts("由于运算优先级的存在,中缀表达式可能不正确,如果要准确的中缀表达式,可以考虑在每两个叶子节点前后添加括号");
puts("");
printf("后序遍历(后缀表达式):\n");
PostOrderTraverse(tree);
puts("");
return 0;
} |
the_stack_data/86074689.c | #include <stdio.h>
int main(){
printf("Hello, World\n");
return 0;
}
|
the_stack_data/184517584.c | /************************************************************************/
/* */
/* Board_Data.c -- Board Customization Data for Digilent Cerebot MX4cK */
/* */
/************************************************************************/
/* Author: Gene Apperson */
/* Copyright 2011, Digilent. All rights reserved */
/************************************************************************/
/* File Description: */
/* */
/* This file contains the board specific declartions and data structure */
/* to customize the chipKIT MPIDE for use with the Digilent Cerebot */
/* MX4cK board. */
/* */
/* This code is based on earlier work: */
/* Copyright (c) 2010, 2011 by Mark Sproul */
/* Copyright (c) 2005, 2006 by David A. Mellis */
/* */
/************************************************************************/
/* Revision History: */
/* */
/* 11/28/2011(GeneA): Created by splitting data out of Board_Defs.h */
/* 11/15/2013(KeithV): This file applies to the chipKIT Pro MX4 also */
/* */
/************************************************************************/
//* This library is free software; you can redistribute it and/or
//* modify it under the terms of the GNU Lesser General Public
//* License as published by the Free Software Foundation; either
//* version 2.1 of the License, or (at your option) any later version.
//*
//* This library 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
//* Lesser General Public License for more details.
//*
//* You should have received a copy of the GNU Lesser General
//* Public License along with this library; if not, write to the
//* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
//* Boston, MA 02111-1307 USA
/************************************************************************/
#if !defined(BOARD_DATA_C)
#define BOARD_DATA_C
#include <inttypes.h>
/* ------------------------------------------------------------ */
/* Data Tables */
/* ------------------------------------------------------------ */
/* The following declarations define data used in pin mapping. */
/* ------------------------------------------------------------ */
#if defined(OPT_BOARD_DATA)
/* ------------------------------------------------------------ */
/* This table is used to map from port number to the address of
** the TRIS register for the port. This is used for setting the
** pin direction.
*/
const uint32_t port_to_tris_PGM[] = {
NOT_A_PORT, //index value 0 is not used
#if defined(_PORTA)
(uint32_t)&TRISA,
#else
NOT_A_PORT,
#endif
#if defined(_PORTB)
(uint32_t)&TRISB,
#else
NOT_A_PORT,
#endif
#if defined(_PORTC)
(uint32_t)&TRISC,
#else
NOT_A_PORT,
#endif
#if defined(_PORTD)
(uint32_t)&TRISD,
#else
NOT_A_PORT,
#endif
#if defined(_PORTE)
(uint32_t)&TRISE,
#else
NOT_A_PORT,
#endif
#if defined(_PORTF)
(uint32_t)&TRISF,
#else
NOT_A_PORT,
#endif
#if defined(_PORTG)
(uint32_t)&TRISG,
#else
NOT_A_PORT,
#endif
NOT_A_PORT,
};
/* ------------------------------------------------------------ */
/* This table is used to map the digital pin number to the port
** containing that pin.
*/
const uint8_t digital_pin_to_port_PGM[] = {
// Connector JA
_IOPORT_PE, // 0 RE0 PMD0
_IOPORT_PE, // 1 RE1 PMD1
_IOPORT_PE, // 2 RE2 PMD2
_IOPORT_PE, // 3 RE3 PMD3
_IOPORT_PE, // 4 RE4 PMD4
_IOPORT_PE, // 5 RE5 PMD5
_IOPORT_PE, // 6 RE6 PMD6
_IOPORT_PE, // 7 RE7 PMD7
// Connector JB
_IOPORT_PG, // 8 RG9 PMA2/SS2/CN11/RG9
_IOPORT_PG, // 9 RG8 PMA3/SDO2/CN10/RG8
_IOPORT_PG, // 10 RG7 PMA4/SDI2/CN9/RG7
_IOPORT_PG, // 11 RG6 PMA5/SCK2/CN8/RG6
_IOPORT_PB, // 12 RB15 PMALL/PMA0/AN15/OCFB/CN12/RB15 or SCL1/INT3/RA14 (Selected with JP3)
_IOPORT_PD, // 13 RD5 PMRD/CN14/RD5
_IOPORT_PD, // 14 RD4 PMWR/OC5/CN13
_IOPORT_PB, // 15 RB14 PMALH/PMA1/AN14/RB14
// Connector JC
_IOPORT_PG, // 16 RG12 TRD1/RG12 (S1)
_IOPORT_PG, // 17 RG13 TRD0/RG13 (S2)
_IOPORT_PG, // 18 RG14 TRD2/RG14 (S3)
_IOPORT_PG, // 19 RG15 RG15 (S4)
_IOPORT_PG, // 20 RG0 PMD8/RG0 (S5)
_IOPORT_PG, // 21 RG1 PMD9/RG1 (S6)
_IOPORT_PF, // 22 RF0 PMD11/RF0 (S7)
_IOPORT_PF, // 23 RF1 PMD10/RF1 (S8)
// Connector JD
_IOPORT_PD, // 24 RD7 PMD15/CN16/RD7
_IOPORT_PD, // 25 RD1 OC2/RD1
_IOPORT_PD, // 26 RD9 TC2/SS1/RD9
_IOPORT_PC, // 27 RC1 T2CK/RC1
_IOPORT_PD, // 28 RD6 PMD14/CN15/RD6
_IOPORT_PD, // 29 RD2 OC3/RD2
_IOPORT_PD, // 30 RD10 IC3/SCK1/PMCS2/PMA15/RD10
_IOPORT_PC, // 31 RC2 T3CK/RC2
// Connector JE
_IOPORT_PD, // 32 RD14 CN20/U1CTS/RD14
_IOPORT_PF, // 33 RF8 U1TX/RF8
_IOPORT_PF, // 34 RF2 U1RX/RF2
_IOPORT_PD, // 35 RD15 U1RTS/BCLK1/CN21/RD15
_IOPORT_PE, // 36 RE9 INT2/RE9
_IOPORT_PD, // 37 RD3 OC4/RD3
_IOPORT_PD, // 38 RD11 IC4/PMCS1/PMA14/RD11
_IOPORT_PC, // 39 RC3 T4CK/RC3
// Connector JF
_IOPORT_PA, // 40 RA14 SCL1/INT3/RA14
_IOPORT_PA, // 41 RA15 SDA1/INT4/RA15
_IOPORT_PA, // 42 RA6 TRCLK/RA6 (BTN1)
_IOPORT_PA, // 43 RA7 TRD3/RA7 (BTN2)
_IOPORT_PA, // 44 RA0 TMS/RA0
_IOPORT_PA, // 45 RA1 TCK/RA1
_IOPORT_PA, // 46 RA4 TDI/RA4
_IOPORT_PA, // 47 RA5 TDO/RA5
// Connector JH
_IOPORT_PF, // 48 RF12 U2CTS/RF12
_IOPORT_PF, // 49 RF5 PMA8/U2TX/CN18/RF5
_IOPORT_PF, // 50 RF4 PMA9/U2RX/CN17/RF4
_IOPORT_PF, // 51 RF13 U2RTS/BCLK2/RF13
_IOPORT_PE, // 52 RE8 INT1/RE8
_IOPORT_PD, // 53 RD0 SDO1/OC1/INT0/RD0
_IOPORT_PD, // 54 RD8 IC1/RTCC/RD8
_IOPORT_PD, // 55 RD13 PMD13/CN19/RD13
// Connector JJ
_IOPORT_PB, // 56 RB0 PGD1/FMUD1/AN0/CN2/RB0
_IOPORT_PB, // 57 RB1 PGC1/FMUC1/AN1/CN3/RB1
_IOPORT_PB, // 58 RB2 C2IN-/AN2/CN4/RB2
_IOPORT_PB, // 59 RB3 C2IN+/AN3/CN5/RB3
_IOPORT_PB, // 60 RB4 C1IN-/AN4/CN6/RB4
_IOPORT_PB, // 61 RB5 C1IN+/AN5/CN7/RB5
_IOPORT_PB, // 62 RB8 C1OUT/AN8/RB8
_IOPORT_PB, // 63 RB9 C2OUT/AN9/RB9
// Connector JK
_IOPORT_PB, // 64 RB10 CVREFOUT/PMA13/AN10/RB10 (LD1)
_IOPORT_PB, // 65 RB11 PMA12/AN11/RB11 (LD2)
_IOPORT_PB, // 66 RB12 PMA11/AN12/RB12 (LD3)
_IOPORT_PB, // 67 RB13 PMA10/AN13/RB13 (LD4)
_IOPORT_PA, // 68 RA9 PMA7/VREF-/CVREF-/RA9
_IOPORT_PA, // 69 RA10 PMA6/VREF+/CVREF+/RA10
_IOPORT_PD, // 70 RD12 PMD12/IC5/RD12
_IOPORT_PC, // 71 RC4 SDI1/T5CK/RC4
//J6 /I2C PORT 2
_IOPORT_PA, // 72 RA2 SCL2/RA2
_IOPORT_PA // 73 RA3 SDA2/RA3
};
/* ------------------------------------------------------------ */
/* This table is used to map from digital pin number to a bit mask
** for the corresponding bit within the port.
*/
const uint16_t digital_pin_to_bit_mask_PGM[] = {
// Connector JA
_BV( 0 ) , // 0 RE 0 PMD0
_BV( 1 ) , // 1 RE 1 PMD1
_BV( 2 ) , // 2 RE 2 PMD2
_BV( 3 ) , // 3 RE 3 PMD3
_BV( 4 ) , // 4 RE 4 PMD4
_BV( 5 ) , // 5 RE 5 PMD5
_BV( 6 ) , // 6 RE 6 PMD6
_BV( 7 ) , // 7 RE 7 PMD7
// Connector JB
_BV( 9 ) , // 8 RG9 PMA2/SS2/CN11/RG9
_BV( 8 ) , // 9 RG8 PMA3/SDO2/CN10/RG8
_BV( 7 ) , // 10 RG7 PMA4/SDI2/CN9/RG7
_BV( 6 ) , // 11 RG6 PMA5/SCK2/CN8/RG6
_BV( 15 ) , // 12 RB15 PMALL/PMA0/AN15/OCFB/CN12/RB15 or SCL1/INT3/RA14 (Selected with JP3)
_BV( 5 ) , // 13 RD5 PMRD/CN14/RD5
_BV( 4 ) , // 14 RD4 PMWR/OC5/CN13
_BV( 14 ) , // 15 RB14 PMALH/PMA1/AN14/RB14
// Connector JC
_BV( 12 ) , // 16 RG12 TRD1/RG12
_BV( 13 ) , // 17 RG13 TRD0/RG13
_BV( 14 ) , // 18 RG14 TRD2/RG14
_BV( 15 ) , // 19 RG15 RG15
_BV( 0 ) , // 20 RG0 PMD8/RG0
_BV( 1 ) , // 21 RG1 PMD9/RG1
_BV( 0 ) , // 22 RF0 PMD11/RF0
_BV( 1 ) , // 23 RF1 PMD10/RF1
// Connector JD
_BV( 7 ) , // 24 RD7 PMD15/CN16/RD7
_BV( 1 ) , // 25 RD1 OC2/RD1
_BV( 9 ) , // 26 RD9 TC2/SS1/RD9
_BV( 1 ) , // 27 RC1 T2CK/RC1
_BV( 6 ) , // 28 RD6 PMD14/CN15/RD6
_BV( 2 ) , // 29 RD2 OC3/RD2
_BV( 10 ) , // 30 RD10 IC3/SCK1/PMCS2/PMA15/RD10
_BV( 2 ) , // 31 RC2 T3CK/RC2
// Connector JE
_BV( 14 ) , // 32 RD14 CN20/U1CTS/RD14
_BV( 8 ) , // 33 RF8 U1TX/RF8
_BV( 2 ) , // 34 RF2 U1RX/RF2
_BV( 15 ) , // 35 RD15 U1RTS/BCLK1/CN21/RD15
_BV( 9 ) , // 36 RE9 INT2/RE9
_BV( 3 ) , // 37 RD3 OC4/RD3
_BV( 11 ) , // 38 RD11 IC4/PMCS1/PMA14/RD11
_BV( 3 ) , // 39 RC3 T4CK/RC3
// Connector JF
_BV( 14 ) , // 40 RA14 SCL1/INT3/RA14
_BV( 15 ) , // 41 RA15 SDA1/INT4/RA15
_BV( 6 ) , // 42 RA6 TRCLK/RA6
_BV( 7 ) , // 43 RA7 TRD3/RA7
_BV( 0 ) , // 44 RA0 TMS/RA0
_BV( 1 ) , // 45 RA1 TCK/RA1
_BV( 4 ) , // 46 RA4 TDI/RA4
_BV( 5 ) , // 47 RA5 TDO/RA5
// Connector JH
_BV( 12 ) , // 48 RF12 U2CTS/RF12
_BV( 5 ) , // 49 RF5 PMA8/U2TX/CN18/RF5
_BV( 4 ) , // 50 RF4 PMA9/U2RX/CN17/RF4
_BV( 13 ) , // 51 RF13 U2RTS/BCLK2/RF13
_BV( 8 ) , // 52 RE8 INT1/RE8
_BV( 0 ) , // 53 RD0 SDO1/OC1/INT0/RD0
_BV( 8 ) , // 54 RD8 IC1/RTCC/RD8
_BV( 13 ) , // 55 RD13 PMD13/CN19/RD13
// Connector JJ
_BV( 0 ) , // 56 RB0 PGD1/FMUD1/AN0/CN2/RB0
_BV( 1 ) , // 57 RB1 PGC1/FMUC1/AN1/CN3/RB1
_BV( 2 ) , // 58 RB2 C2IN-/AN2/CN4/RB2
_BV( 3 ) , // 59 RB3 C2IN+/AN3/CN5/RB3
_BV( 4 ) , // 60 RB4 C1IN-/AN4/CN6/RB4
_BV( 5 ) , // 61 RB5 C1IN+/AN5/CN7/RB5
_BV( 8 ) , // 62 RB8 C1OUT/AN8/RB8
_BV( 9 ) , // 63 RB9 C2OUT/AN9/RB9
// Connector JK
_BV( 10 ) , // 64 RB10 CVREFOUT/PMA13/AN10/RB10
_BV( 11 ) , // 65 RB11 PMA12/AN11/RB11
_BV( 12 ) , // 66 RB12 PMA11/AN12/RB12
_BV( 13 ) , // 67 RB11 PMA10/AN13/RB13
_BV( 9 ) , // 68 RA9 PMA7/VREF-/CVREF-/RA9
_BV( 10 ) , // 69 RA10 PMA6/VREF+/CVREF+/RA10
_BV( 12 ) , // 70 RD12 PMD12/IC5/RD12
_BV( 4 ) , // 71 RC4 SDI1/T5CK/RC4
//J6 /I2C PORT 2
_BV( 2 ) , // 72 RA2 SCL2/RA2
_BV( 3 ) // 73 RA3 SDA2/RA3
};
/* ------------------------------------------------------------ */
/* This table is used to map from digital pin number to the output
** compare number, input capture number, and timer external clock
** input associated with that pin.
*/
const uint16_t digital_pin_to_timer_PGM[] = {
// Connector JA
NOT_ON_TIMER, // 0 RE 0 PMD0
NOT_ON_TIMER, // 1 RE 1 PMD1
NOT_ON_TIMER, // 2 RE 2 PMD2
NOT_ON_TIMER, // 3 RE 3 PMD3
NOT_ON_TIMER, // 4 RE 4 PMD4
NOT_ON_TIMER, // 5 RE 5 PMD5
NOT_ON_TIMER, // 6 RE 6 PMD6
NOT_ON_TIMER, // 7 RE 7 PMD7
// Connector JB
NOT_ON_TIMER, // 8 RG9 PMA2/SS2/CN11/RG9
NOT_ON_TIMER, // 9 RG8 PMA3/SDO2/CN10/RG8
NOT_ON_TIMER, // 10 RG7 PMA4/SDI2/CN9/RG7
NOT_ON_TIMER, // 11 RG6 PMA5/SCK2/CN8/RG6
NOT_ON_TIMER, // 12 RB15 PMALL/PMA0/AN15/OCFB/CN12/RB15 or SCL1/INT3/RA14 (Selected with JP3)
NOT_ON_TIMER, // 13 RD5 PMRD/CN14/RD5
_TIMER_OC5, // 14 RD4 PMWR/OC5/CN13
NOT_ON_TIMER, // 15 RB14 PMALH/PMA1/AN14/RB14
// Connector JC
NOT_ON_TIMER, // 16 RG12 TRD1/RG12
NOT_ON_TIMER, // 17 RG13 TRD0/RG13
NOT_ON_TIMER, // 18 RG14 TRD2/RG14
NOT_ON_TIMER, // 19 RG15 RG15
NOT_ON_TIMER, // 20 RG0 PMD8/RG0
NOT_ON_TIMER, // 21 RG1 PMD9/RG1
NOT_ON_TIMER, // 22 RF0 PMD11/RF0
NOT_ON_TIMER, // 23 RF1 PMD10/RF1
// Connector JD
NOT_ON_TIMER, // 24 RD7 PMD15/CN16/RD7
_TIMER_OC2, // 25 RD1 OC2/RD1
_TIMER_IC2, // 26 RD9 IC2/SS1/RD9
_TIMER_TCK2, // 27 RC1 T2CK/RC1
NOT_ON_TIMER, // 28 RD6 PMD14/CN15/RD6
_TIMER_OC3, // 29 RD2 OC3/RD2
_TIMER_IC3, // 30 RD10 IC3/SCK1/PMCS2/PMA15/RD10
_TIMER_TCK3, // 31 RC2 T3CK/RC2
// Connector JE
NOT_ON_TIMER, // 32 RD14 CN20/U1CTS/RD14
NOT_ON_TIMER, // 33 RF8 U1TX/RF8
NOT_ON_TIMER, // 34 RF2 U1RX/RF2
NOT_ON_TIMER, // 35 RD15 U1RTS/BCLK1/CN21/RD15
NOT_ON_TIMER, // 36 RE9 INT2/RE9
_TIMER_OC4, // 37 RD3 OC4/RD3
_TIMER_IC4, // 38 RD11 IC4/PMCS1/PMA14/RD11
_TIMER_TCK4, // 39 RC3 T4CK/RC3
// Connector JF
NOT_ON_TIMER, // 40 RD14 SCL1/INT3/RA14
NOT_ON_TIMER, // 41 RA15 SDA1/INT4/RA15
NOT_ON_TIMER, // 42 RA6 TRCLK/RA6
NOT_ON_TIMER, // 43 RA7 TRD3/RA7
NOT_ON_TIMER, // 44 RA0 TMS/RA0
NOT_ON_TIMER, // 45 RA1 TCK/RA1
NOT_ON_TIMER, // 46 RA4 TDI/RA4
NOT_ON_TIMER, // 47 RA5 TDO/RA5
// Connector JH
NOT_ON_TIMER, // 48 RF12 U2CTS/RF12
NOT_ON_TIMER, // 49 RF5 PMA8/U2TX/CN18/RF5
NOT_ON_TIMER, // 50 RF4 PMA9/U2RX/CN17/RF4
NOT_ON_TIMER, // 51 RF13 U2RTS/BCLK2/RF13
NOT_ON_TIMER, // 52 RE8 INT1/RE8
_TIMER_OC1, // 53 RD0 SDO1/OC1/INT0/RD0
_TIMER_IC1, // 54 RD8 IC1/RTCC/RD8
NOT_ON_TIMER, // 55 RD13 PMD13/CN19/RD13
// Connector JJ
NOT_ON_TIMER, // 56 RB0 PGD1/FMUD1/AN0/CN2/RB0
NOT_ON_TIMER, // 57 RB1 PGC1/FMUC1/AN1/CN3/RB1
NOT_ON_TIMER, // 58 RB2 C2IN-/AN2/CN4/RB2
NOT_ON_TIMER, // 59 RB3 C2IN+/AN3/CN5/RB3
NOT_ON_TIMER, // 60 RB4 C1IN-/AN4/CN6/RB4
NOT_ON_TIMER, // 61 RB5 C1IN+/AN5/CN7/RB5
NOT_ON_TIMER, // 62 RB8 C1OUT/AN8/RB8
NOT_ON_TIMER, // 63 RB9 C2OUT/AN9/RB9
// Connector JK
NOT_ON_TIMER, // 64 RB10 CVREFOUT/PMA13/AN10/RB10
NOT_ON_TIMER, // 65 RB11 PMA12/AN11/RB11
NOT_ON_TIMER, // 66 RB12 PMA11/AN12/RB12
NOT_ON_TIMER, // 67 RB13 PMA10/AN13/RB13
NOT_ON_TIMER, // 68 RA9 PMA7/VREF-/CVREF-/RA9
NOT_ON_TIMER, // 69 RA10 PMA6/VREF+/CVREF+/RA10
_TIMER_IC5, // 70 RD12 PMD12/IC5/RD12
_TIMER_TCK5, // 71 RC4 SDI1/T5CK/RC4
//J6 /I2C PORT 2
NOT_ON_TIMER, // 72 RA2 SCL2/RA2
NOT_ON_TIMER // 73 RA3 SDA2/RA3
};
/* ------------------------------------------------------------ */
/* This table maps from a digital pin number to the corresponding
** analog pin number.
*/
const uint8_t digital_pin_to_analog_PGM[] = {
// Connector JA
NOT_ANALOG_PIN, // 0 RE 0 PMD0
NOT_ANALOG_PIN, // 1 RE 1 PMD1
NOT_ANALOG_PIN, // 2 RE 2 PMD2
NOT_ANALOG_PIN, // 3 RE 3 PMD3
NOT_ANALOG_PIN, // 4 RE 4 PMD4
NOT_ANALOG_PIN, // 5 RE 5 PMD5
NOT_ANALOG_PIN, // 6 RE 6 PMD6
NOT_ANALOG_PIN, // 7 RE 7 PMD7
// Connector JB
NOT_ANALOG_PIN, // 8 RG9 PMA2/SS2/CN11/RG9
NOT_ANALOG_PIN, // 9 RG8 PMA3/SDO2/CN10/RG8
NOT_ANALOG_PIN, // 10 RG7 PMA4/SDI2/CN9/RG7
NOT_ANALOG_PIN, // 11 RG6 PMA5/SCK2/CN8/RG6
_BOARD_AN12, // 12 RB15 PMALL/PMA0/AN15/OCFB/CN12/RB15
NOT_ANALOG_PIN, // 13 RD5 PMRD/CN14/RD5
NOT_ANALOG_PIN, // 14 RD4 PMWR/OC5/CN13
_BOARD_AN13, // 15 RB14 PMALH/PMA1/AN14/RB14
// Connector JC
NOT_ANALOG_PIN, // 16 RG12 TRD1/RG12
NOT_ANALOG_PIN, // 17 RG13 TRD0/RG13
NOT_ANALOG_PIN, // 18 RG14 TRD2/RG14
NOT_ANALOG_PIN, // 19 RG15 RG15
NOT_ANALOG_PIN, // 20 RG0 PMD8/RG0
NOT_ANALOG_PIN, // 21 RG1 PMD9/RG1
NOT_ANALOG_PIN, // 22 RF0 PMD11/RF0
NOT_ANALOG_PIN, // 23 RF1 PMD10/RF1
// Connector JD
NOT_ANALOG_PIN, // 24 RD7 PMD15/CN16/RD7
NOT_ANALOG_PIN, // 25 RD1 OC2/RD1
NOT_ANALOG_PIN, // 26 RD9 TC2/SS1/RD9
NOT_ANALOG_PIN, // 27 RC1 T2CK/RC1
NOT_ANALOG_PIN, // 28 RD6 PMD14/CN15/RD6
NOT_ANALOG_PIN, // 29 RD2 OC3/RD2
NOT_ANALOG_PIN, // 30 RD10 IC3/SCK1/PMCS2/PMA15/RD10
NOT_ANALOG_PIN, // 31 RC2 T3CK/RC2
// Connector JE
NOT_ANALOG_PIN, // 32 RD14 CN20/U1CTS/RD14
NOT_ANALOG_PIN, // 33 RF8 U1TX/RF8
NOT_ANALOG_PIN, // 34 RF2 U1RX/RF2
NOT_ANALOG_PIN, // 35 RD15 U1RTS/BCLK1/CN21/RD15
NOT_ANALOG_PIN, // 36 RE9 INT2/RE9
NOT_ANALOG_PIN, // 37 RD3 OC4/RD3
NOT_ANALOG_PIN, // 38 RD11 IC4/PMCS1/PMA14/RD11
NOT_ANALOG_PIN, // 39 RC3 T4CK/RC3
// Connector JF
NOT_ANALOG_PIN, // 40 RD14 SCL1/INT3/RA14
NOT_ANALOG_PIN, // 41 RA15 SDA1/INT4/RA15
NOT_ANALOG_PIN, // 42 RA6 TRCLK/RA6
NOT_ANALOG_PIN, // 43 RA7 TRD3/RA7
NOT_ANALOG_PIN, // 44 RA0 TMS/RA0
NOT_ANALOG_PIN, // 45 RA1 TCK/RA1
NOT_ANALOG_PIN, // 46 RA4 TDI/RA4
NOT_ANALOG_PIN, // 47 RA5 TDO/RA5
// Connector JH
NOT_ANALOG_PIN, // 48 RF12 U2CTS/RF12
NOT_ANALOG_PIN, // 49 RF5 PMA8/U2TX/CN18/RF5
NOT_ANALOG_PIN, // 50 RF4 PMA9/U2RX/CN17/RF4
NOT_ANALOG_PIN, // 51 RF13 U2RTS/BCLK2/RF13
NOT_ANALOG_PIN, // 52 RE8 INT1/RE8
NOT_ANALOG_PIN, // 53 RD0 SDO1/OC1/INT0/RD0
NOT_ANALOG_PIN, // 54 RD8 IC1/RTCC/RD8
NOT_ANALOG_PIN, // 55 RD13 PMD13/CN19/RD13
// Connector JJ
_BOARD_AN0, // 56 RB0 PGD1/FMUD1/AN0/CN2/RB0
_BOARD_AN1, // 57 RB1 PGC1/FMUC1/AN1/CN3/RB1
_BOARD_AN2, // 58 RB2 C2IN-/AN2/CN4/RB2
_BOARD_AN3, // 59 RB3 C2IN+/AN3/CN5/RB3
_BOARD_AN4, // 60 RB4 C1IN-/AN4/CN6/RB4
_BOARD_AN5, // 61 RB5 C1IN+/AN5/CN7/RB5
_BOARD_AN6, // 62 RB8 C1OUT/AN8/RB8
_BOARD_AN7, // 63 RB9 C2OUT/AN9/RB9
// Connector JK
_BOARD_AN8, // 64 RB10 CVREFOUT/PMA13/AN10/RB10
_BOARD_AN9, // 65 RB11 PMA12/AN11/RB11
_BOARD_AN10, // 66 RB12 PMA11/AN12/RB12
_BOARD_AN11, // 67 RB13 PMA10/AN13/RB13
NOT_ANALOG_PIN, // 68 RA9 PMA7/VREF-/CVREF-/RA9
NOT_ANALOG_PIN, // 69 RA10 PMA6/VREF+/CVREF+/RA10
NOT_ANALOG_PIN, // 70 RD12 PMD12/IC5/RD12
NOT_ANALOG_PIN, // 71 RC4 SDI1/T5CK/RC4
//J6 /I2C PORT 2
NOT_ANALOG_PIN, // 72 RA2 SCL2/RA2
NOT_ANALOG_PIN // 73 RA3 SDA2/RA3
};
/* ------------------------------------------------------------ */
/* This table is used to map from the analog pin number to the
** actual A/D converter channel used for that pin.
*/
const uint8_t analog_pin_to_channel_PGM[] =
{
//* chipKIT Pin PIC32 Analog channel
0, //* A0 AN0
1, //* A1 AN1
2, //* A2 AN2
3, //* A3 AN3
4, //* A4 AN4
5, //* A5 AN5
8, //* A6 AN8
9, //* A7 AN9
10, //* A8 AN10
11, //* A9 AN11
12, //* A10 AN12
13, //* A11 AN13
15, //* A12 AN15
14 //* A13 AN14
};
/* ------------------------------------------------------------ */
/* Board Customization Functions */
/* ------------------------------------------------------------ */
/* */
/* The following can be used to customize the behavior of some */
/* of the core API functions. These provide hooks that can be */
/* used to extend or replace the default behavior of the core */
/* functions. To use one of these functions, add the desired */
/* code to the function skeleton below and then set the value */
/* of the appropriate compile switch above to 1. This will */
/* cause the hook function to be compiled into the build and */
/* to cause the code to call the hook function to be compiled */
/* into the appropriate core function. */
/* */
/* ------------------------------------------------------------ */
/*** _board_init
**
** Parameters:
** none
**
** Return Value:
** none
**
** Errors:
** none
**
** Description:
** This function is called from the core init() function.
** This can be used to perform any board specific init
** that needs to be done when the processor comes out of
** reset and before the user sketch is run.
*/
#if (OPT_BOARD_INIT != 0)
void _board_init(void) {
}
#endif
/* ------------------------------------------------------------ */
/*** _board_pinMode
**
** Parameters:
** pin - digital pin number to configure
** mode - mode to which the pin should be configured
**
** Return Value:
** Returns 0 if not handled, !0 if handled.
**
** Errors:
** none
**
** Description:
** This function is called at the beginning of the pinMode
** function. It can perform any special processing needed
** when setting the pin mode. If this function returns zero,
** control will pass through the normal pinMode code. If
** it returns a non-zero value the normal pinMode code isn't
** executed.
*/
#if (OPT_BOARD_DIGITAL_IO != 0)
int _board_pinMode(uint8_t pin, uint8_t mode) {
return 0;
}
#endif
/* ------------------------------------------------------------ */
/*** _board_getPinMode
**
** Parameters:
** pin - digital pin number
** mode - pointer to variable to receive mode value
**
** Return Value:
** Returns 0 if not handled, !0 if handled.
**
** Errors:
** none
**
** Description:
** This function is called at the beginning of the getPinMode
** function. It can perform any special processing needed
** when getting the pin mode. If this function returns zero,
** control will pass through the normal getPinMode code. If
** it returns a non-zero value the normal getPinMode code isn't
** executed.
*/
#if (OPT_BOARD_DIGITAL_IO != 0)
int _board_getPinMode(uint8_t pin, uint8_t * mode) {
return 0;
}
#endif
/* ------------------------------------------------------------ */
/*** _board_digitalWrite
**
** Parameters:
** pin - digital pin number
** val - value to write to the pin
**
** Return Value:
** Returns 0 if not handled, !0 if handled.
**
** Errors:
** none
**
** Description:
** This function is called at the beginning of the digitalWrite
** function. It can perform any special processing needed
** in writing to the pin. If this function returns zero,
** control will pass through the normal digitalWrite code. If
** it returns a non-zero value the normal digitalWrite code isn't
** executed.
*/#if (OPT_BOARD_DIGITAL_IO != 0)
int _board_digitalWrite(uint8_t pin, uint8_t val) {
return 0;
}
#endif
/* ------------------------------------------------------------ */
/*** _board_digitalRead
**
** Parameters:
** pin - digital pin number
** val - pointer to variable to receive pin value
**
** Return Value:
** Returns 0 if not handled, !0 if handled.
**
** Errors:
** none
**
** Description:
** This function is called at the beginning of the digitalRead
** function. It can perform any special processing needed
** in reading from the pin. If this function returns zero,
** control will pass through the normal digitalRead code. If
** it returns a non-zero value the normal digitalRead code isn't
** executed.
*/
#if (OPT_BOARD_DIGITAL_IO != 0)
int _board_digitalRead(uint8_t pin, uint8_t * val) {
return 0;
}
#endif
/* ------------------------------------------------------------ */
/*** _board_analogRead
**
** Parameters:
** pin - analog channel number
** val - pointer to variable to receive analog value
**
** Return Value:
** Returns 0 if not handled, !0 if handled.
**
** Errors:
** none
**
** Description:
** This function is called at the beginning of the analogRead
** function. It can perform any special processing needed
** in reading from the pin. If this function returns zero,
** control will pass through the normal analogRead code. If
** it returns a non-zero value the normal analogRead code isn't
** executed.
*/
#if (OPT_BOARD_ANALOG_READ != 0)
int _board_analogRead(uint8_t pin, int * val) {
return 0;
}
#endif
/* ------------------------------------------------------------ */
/*** _board_analogReference
**
** Parameters:
**
** Return Value:
** Returns 0 if not handled, !0 if handled.
**
** Errors:
** none
**
** Description:
** This function is called at the beginning of the analogReference
** function. It can perform any special processing needed
** to set the reference voltage. If this function returns zero,
** control will pass through the normal analogReference code. If
** it returns a non-zero value the normal analogReference code isn't
** executed.
*/
#if (OPT_BOARD_ANALOG_READ != 0)
int _board_analogReference(uint8_t mode) {
return 0;
}
#endif
/* ------------------------------------------------------------ */
/*** _board_analogWrite
**
** Parameters:
** pin - pin number
** val - analog value to write
**
** Return Value:
** Returns 0 if not handled, !0 if handled.
**
** Errors:
** none
**
** Description:
** This function is called at the beginning of the analogWrite
** function. It can perform any special processing needed
** in writing to the pin. If this function returns zero,
** control will pass through the normal analogWrite code. If
** it returns a non-zero value the normal analogWrite code isn't
** executed.
*/
#if (OPT_BOARD_ANALOG_WRITE != 0)
int _board_analogWrite(uint8_t pin, int val) {
return 0;
}
#endif
#endif // OPT_BOARD_DATA
/* ------------------------------------------------------------ */
#endif // BOARD_DATA_C
/************************************************************************/
|
the_stack_data/26409.c | /*6. Fa¸ca duas fun¸c˜oes: uma que imprima o conte´udo de um vetor em ordem direta (do primeiro ao ´ultimo elemento) e
outra que imprima em ordem inversa (do ´ultimo elemento at´e o primeiro).*/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void preencheVetor(int v[],int n, int limite);
void directOrder(int v[],int n);
void reverseOrder(int v[],int n);
int main(){
int array[100], number, limit;
printf("Informe o numero de elementos do vetor e o limite(separados por espaco): ");
scanf("%d" "%d", &number, &limit);
preencheVetor(array, number, limit);
directOrder(array, number);
reverseOrder(array, number);
}
void preencheVetor(int v[],int n, int limite){
int i;
srand(time(NULL));
for(i=0; i<n; i++){
v[i]=rand()%limite;
}
}
void directOrder(int v[],int n){
int i;
for(i=0;i<n;i++)
printf("Posicao direta %d, valor %d\n",i, v[i]);
}
void reverseOrder(int v[],int n){
while(n>0){
printf("Posicao inversa %d, valor %d\n",n-1, v[n-1]);
n--;
}
}
|
the_stack_data/147872.c | /* Test case for hand function calls interrupted by a signal in another thread.
Copyright 2008-2021 Free Software Foundation, Inc.
This file is part of GDB.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This 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 program. If not, see <http://www.gnu.org/licenses/>. */
#include <pthread.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
#ifndef NR_THREADS
#define NR_THREADS 4
#endif
pthread_t threads[NR_THREADS];
/* Number of threads currently running. */
int thread_count;
pthread_mutex_t thread_count_mutex;
pthread_cond_t thread_count_condvar;
sig_atomic_t sigabrt_received;
void
incr_thread_count (void)
{
pthread_mutex_lock (&thread_count_mutex);
++thread_count;
if (thread_count == NR_THREADS)
pthread_cond_signal (&thread_count_condvar);
pthread_mutex_unlock (&thread_count_mutex);
}
void
cond_wait (pthread_cond_t *cond, pthread_mutex_t *mut)
{
pthread_mutex_lock (mut);
pthread_cond_wait (cond, mut);
pthread_mutex_unlock (mut);
}
void
noreturn (void)
{
pthread_mutex_t mut;
pthread_cond_t cond;
pthread_mutex_init (&mut, NULL);
pthread_cond_init (&cond, NULL);
/* Wait for a condition that will never be signaled, so we effectively
block the thread here. */
cond_wait (&cond, &mut);
}
void *
thread_entry (void *unused)
{
incr_thread_count ();
noreturn ();
}
void
sigabrt_handler (int signo)
{
sigabrt_received = 1;
}
/* Helper to test a hand-call being "interrupted" by a signal on another
thread. */
void
hand_call_with_signal (void)
{
const struct timespec ts = { 0, 10000000 }; /* 0.01 sec */
sigabrt_received = 0;
pthread_kill (threads[0], SIGABRT);
while (! sigabrt_received)
nanosleep (&ts, NULL);
}
/* Wait until all threads are running. */
void
wait_all_threads_running (void)
{
pthread_mutex_lock (&thread_count_mutex);
if (thread_count == NR_THREADS)
{
pthread_mutex_unlock (&thread_count_mutex);
return;
}
pthread_cond_wait (&thread_count_condvar, &thread_count_mutex);
if (thread_count == NR_THREADS)
{
pthread_mutex_unlock (&thread_count_mutex);
return;
}
pthread_mutex_unlock (&thread_count_mutex);
printf ("failed waiting for all threads to start\n");
abort ();
}
/* Called when all threads are running.
Easy place for a breakpoint. */
void
all_threads_running (void)
{
}
int
main (void)
{
int i;
signal (SIGABRT, sigabrt_handler);
pthread_mutex_init (&thread_count_mutex, NULL);
pthread_cond_init (&thread_count_condvar, NULL);
for (i = 0; i < NR_THREADS; ++i)
pthread_create (&threads[i], NULL, thread_entry, NULL);
wait_all_threads_running ();
all_threads_running ();
return 0;
}
|
the_stack_data/25136493.c | /*
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to <http://unlicense.org/>
*/
#include <stdio.h>
#include <stddef.h>
#include <math.h>
#include <malloc.h>
int main(int argc, char *argv[])
{
printf("Hello printf World\n\n");
printf("sinf(1.0f): %f\n\n", sinf(1.0f));
char file_buf[20] = {0};
FILE* file = fopen("payload", "r");
printf("Opened payload file %p\n", file);
fseek(file, 0, SEEK_END);
long file_size = ftell(file);
fseek(file, 0, SEEK_SET);
printf("Size of payload is %d\n", file_size);
size_t file_read = fread(file_buf, 1, sizeof(file_buf), file);
fclose(file);
printf("Read %d bytes from file '%s'\n\n", (int)file_read, file_buf);
void* alloc_buf = malloc(1024);
printf("Allocated 1KB at address %p\n", alloc_buf);
alloc_buf = realloc(alloc_buf, 10*1024*1024);
printf("Reallocated to 10MB at address %p\n\n", alloc_buf);
free(alloc_buf);
return 0;
}
|
the_stack_data/40762605.c | // File name: ExtremeC_examples_chapter8_1.c
// Description: Nesting structure variables
#include <stdio.h>
typedef struct {
char first_name[32];
char last_name[32];
unsigned int birth_year;
} person_t;
typedef struct {
person_t person;
char student_number[16]; // Extra attribute
unsigned int passed_credits; // Extra attribute
} student_t;
int main(int argc, char** argv) {
student_t s;
student_t* s_ptr = &s;
person_t* p_ptr = (person_t*)&s;
printf("Student pointer points to %p\n", (void*)s_ptr);
printf("Person pointer points to %p\n", (void*)p_ptr);
return 0;
}
|
the_stack_data/212642068.c | /* $Id$ */
/*
* Copyright (c) 2009 Aaron Turner.
* Copyright (c) 2013-2016 Fred Klassen <fklassen at appneta dot com> - AppNeta
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the names of the copyright owners nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* FIXME: If you are creating an encoder plugin with any options
* then you need to create API calls for each option so that the
* GUI or other programs using libtcpedit can set those values.
*
* Just uncomment the following headers, declare your methods in
* pppserial_api.h and write them here...
#include "common.h"
#include "tcpr.h"
#include "tcpedit.h"
#include "pppserial_types.h"
*/
|
the_stack_data/7949230.c | #include <stdio.h>
#define MAXSTRING 100
#define NOTFOUND -1
int any(char *s1, char *s2);
int main(void)
{
char s1[MAXSTRING];
char s2[MAXSTRING];
int firstpos;
scanf("%s\n%s", s1, s2);
firstpos = any(s1, s2);
if (firstpos != NOTFOUND)
printf("%d\n", firstpos);
else
printf("no matching characters\n");
return firstpos;
}
int any(char *s1, char *s2)
{
int i, k;
for (i = 0; s1[i] != '\0'; i++) {
for (k = 0; s2[k] != '\0' && s2[k] != s1[i]; k++)
;
if (s2[k] != '\0')
return i;
}
return NOTFOUND;
}
|
the_stack_data/76841.c | /*
** 2010 April 7
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
**
** This file implements an example of a simple VFS implementation that
** omits complex features often not required or not possible on embedded
** platforms. Code is included to buffer writes to the journal file,
** which can be a significant performance improvement on some embedded
** platforms.
**
** OVERVIEW
**
** The code in this file implements a minimal SQLite VFS that can be
** used on Linux and other posix-like operating systems. The following
** system calls are used:
**
** File-system: access(), unlink(), getcwd()
** File IO: open(), read(), write(), fsync(), close(), fstat()
** Other: sleep(), usleep(), time()
**
** The following VFS features are omitted:
**
** 1. File locking. The user must ensure that there is at most one
** connection to each database when using this VFS. Multiple
** connections to a single shared-cache count as a single connection
** for the purposes of the previous statement.
**
** 2. The loading of dynamic extensions (shared libraries).
**
** 3. Temporary files. The user must configure SQLite to use in-memory
** temp files when using this VFS. The easiest way to do this is to
** compile with:
**
** -DSQLITE_TEMP_STORE=3
**
** 4. File truncation. As of version 3.6.24, SQLite may run without
** a working xTruncate() call, providing the user does not configure
** SQLite to use "journal_mode=truncate", or use both
** "journal_mode=persist" and ATTACHed databases.
**
** It is assumed that the system uses UNIX-like path-names. Specifically,
** that '/' characters are used to separate path components and that
** a path-name is a relative path unless it begins with a '/'. And that
** no UTF-8 encoded paths are greater than 512 bytes in length.
**
** JOURNAL WRITE-BUFFERING
**
** To commit a transaction to the database, SQLite first writes rollback
** information into the journal file. This usually consists of 4 steps:
**
** 1. The rollback information is sequentially written into the journal
** file, starting at the start of the file.
** 2. The journal file is synced to disk.
** 3. A modification is made to the first few bytes of the journal file.
** 4. The journal file is synced to disk again.
**
** Most of the data is written in step 1 using a series of calls to the
** VFS xWrite() method. The buffers passed to the xWrite() calls are of
** various sizes. For example, as of version 3.6.24, when committing a
** transaction that modifies 3 pages of a database file that uses 4096
** byte pages residing on a media with 512 byte sectors, SQLite makes
** eleven calls to the xWrite() method to create the rollback journal,
** as follows:
**
** Write offset | Bytes written
** ----------------------------
** 0 512
** 512 4
** 516 4096
** 4612 4
** 4616 4
** 4620 4096
** 8716 4
** 8720 4
** 8724 4096
** 12820 4
** ++++++++++++SYNC+++++++++++
** 0 12
** ++++++++++++SYNC+++++++++++
**
** On many operating systems, this is an efficient way to write to a file.
** However, on some embedded systems that do not cache writes in OS
** buffers it is much more efficient to write data in blocks that are
** an integer multiple of the sector-size in size and aligned at the
** start of a sector.
**
** To work around this, the code in this file allocates a fixed size
** buffer of SQLITE_DEMOVFS_BUFFERSZ using sqlite3_malloc() whenever a
** journal file is opened. It uses the buffer to coalesce sequential
** writes into aligned SQLITE_DEMOVFS_BUFFERSZ blocks. When SQLite
** invokes the xSync() method to sync the contents of the file to disk,
** all accumulated data is written out, even if it does not constitute
** a complete block. This means the actual IO to create the rollback
** journal for the example transaction above is this:
**
** Write offset | Bytes written
** ----------------------------
** 0 8192
** 8192 4632
** ++++++++++++SYNC+++++++++++
** 0 12
** ++++++++++++SYNC+++++++++++
**
** Much more efficient if the underlying OS is not caching write
** operations.
*/
#if !defined(SQLITE_TEST) || SQLITE_OS_UNIX
#include "sqlite3.h"
#include <assert.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/file.h>
#include <sys/param.h>
#include <unistd.h>
#include <time.h>
#include <errno.h>
#include <fcntl.h>
/*
** Size of the write buffer used by journal files in bytes.
*/
#ifndef SQLITE_DEMOVFS_BUFFERSZ
# define SQLITE_DEMOVFS_BUFFERSZ 8192
#endif
/*
** The maximum pathname length supported by this VFS.
*/
#define MAXPATHNAME 512
/*
** When using this VFS, the sqlite3_file* handles that SQLite uses are
** actually pointers to instances of type DemoFile.
*/
typedef struct DemoFile DemoFile;
struct DemoFile {
sqlite3_file base; /* Base class. Must be first. */
int fd; /* File descriptor */
char *aBuffer; /* Pointer to malloc'd buffer */
int nBuffer; /* Valid bytes of data in zBuffer */
sqlite3_int64 iBufferOfst; /* Offset in file of zBuffer[0] */
};
/*
** Write directly to the file passed as the first argument. Even if the
** file has a write-buffer (DemoFile.aBuffer), ignore it.
*/
static int demoDirectWrite(
DemoFile *p, /* File handle */
const void *zBuf, /* Buffer containing data to write */
int iAmt, /* Size of data to write in bytes */
sqlite_int64 iOfst /* File offset to write to */
){
off_t ofst; /* Return value from lseek() */
size_t nWrite; /* Return value from write() */
ofst = lseek(p->fd, iOfst, SEEK_SET);
if( ofst!=iOfst ){
return SQLITE_IOERR_WRITE;
}
nWrite = write(p->fd, zBuf, iAmt);
if( nWrite!=iAmt ){
return SQLITE_IOERR_WRITE;
}
return SQLITE_OK;
}
/*
** Flush the contents of the DemoFile.aBuffer buffer to disk. This is a
** no-op if this particular file does not have a buffer (i.e. it is not
** a journal file) or if the buffer is currently empty.
*/
static int demoFlushBuffer(DemoFile *p){
int rc = SQLITE_OK;
if( p->nBuffer ){
rc = demoDirectWrite(p, p->aBuffer, p->nBuffer, p->iBufferOfst);
p->nBuffer = 0;
}
return rc;
}
/*
** Close a file.
*/
static int demoClose(sqlite3_file *pFile){
int rc;
DemoFile *p = (DemoFile*)pFile;
rc = demoFlushBuffer(p);
sqlite3_free(p->aBuffer);
close(p->fd);
return rc;
}
/*
** Read data from a file.
*/
static int demoRead(
sqlite3_file *pFile,
void *zBuf,
int iAmt,
sqlite_int64 iOfst
){
DemoFile *p = (DemoFile*)pFile;
off_t ofst; /* Return value from lseek() */
int nRead; /* Return value from read() */
int rc; /* Return code from demoFlushBuffer() */
/* Flush any data in the write buffer to disk in case this operation
** is trying to read data the file-region currently cached in the buffer.
** It would be possible to detect this case and possibly save an
** unnecessary write here, but in practice SQLite will rarely read from
** a journal file when there is data cached in the write-buffer.
*/
rc = demoFlushBuffer(p);
if( rc!=SQLITE_OK ){
return rc;
}
ofst = lseek(p->fd, iOfst, SEEK_SET);
if( ofst!=iOfst ){
return SQLITE_IOERR_READ;
}
nRead = read(p->fd, zBuf, iAmt);
if( nRead==iAmt ){
return SQLITE_OK;
}else if( nRead>=0 ){
return SQLITE_IOERR_SHORT_READ;
}
return SQLITE_IOERR_READ;
}
/*
** Write data to a crash-file.
*/
static int demoWrite(
sqlite3_file *pFile,
const void *zBuf,
int iAmt,
sqlite_int64 iOfst
){
DemoFile *p = (DemoFile*)pFile;
if( p->aBuffer ){
char *z = (char *)zBuf; /* Pointer to remaining data to write */
int n = iAmt; /* Number of bytes at z */
sqlite3_int64 i = iOfst; /* File offset to write to */
while( n>0 ){
int nCopy; /* Number of bytes to copy into buffer */
/* If the buffer is full, or if this data is not being written directly
** following the data already buffered, flush the buffer. Flushing
** the buffer is a no-op if it is empty.
*/
if( p->nBuffer==SQLITE_DEMOVFS_BUFFERSZ || p->iBufferOfst+p->nBuffer!=i ){
int rc = demoFlushBuffer(p);
if( rc!=SQLITE_OK ){
return rc;
}
}
assert( p->nBuffer==0 || p->iBufferOfst+p->nBuffer==i );
p->iBufferOfst = i - p->nBuffer;
/* Copy as much data as possible into the buffer. */
nCopy = SQLITE_DEMOVFS_BUFFERSZ - p->nBuffer;
if( nCopy>n ){
nCopy = n;
}
memcpy(&p->aBuffer[p->nBuffer], z, nCopy);
p->nBuffer += nCopy;
n -= nCopy;
i += nCopy;
z += nCopy;
}
}else{
return demoDirectWrite(p, zBuf, iAmt, iOfst);
}
return SQLITE_OK;
}
/*
** Truncate a file. This is a no-op for this VFS (see header comments at
** the top of the file).
*/
static int demoTruncate(sqlite3_file *pFile, sqlite_int64 size){
#if 0
if( ftruncate(((DemoFile *)pFile)->fd, size) ) return SQLITE_IOERR_TRUNCATE;
#endif
return SQLITE_OK;
}
/*
** Sync the contents of the file to the persistent media.
*/
static int demoSync(sqlite3_file *pFile, int flags){
DemoFile *p = (DemoFile*)pFile;
int rc;
rc = demoFlushBuffer(p);
if( rc!=SQLITE_OK ){
return rc;
}
rc = fsync(p->fd);
return (rc==0 ? SQLITE_OK : SQLITE_IOERR_FSYNC);
}
/*
** Write the size of the file in bytes to *pSize.
*/
static int demoFileSize(sqlite3_file *pFile, sqlite_int64 *pSize){
DemoFile *p = (DemoFile*)pFile;
int rc; /* Return code from fstat() call */
struct stat sStat; /* Output of fstat() call */
/* Flush the contents of the buffer to disk. As with the flush in the
** demoRead() method, it would be possible to avoid this and save a write
** here and there. But in practice this comes up so infrequently it is
** not worth the trouble.
*/
rc = demoFlushBuffer(p);
if( rc!=SQLITE_OK ){
return rc;
}
rc = fstat(p->fd, &sStat);
if( rc!=0 ) return SQLITE_IOERR_FSTAT;
*pSize = sStat.st_size;
return SQLITE_OK;
}
/*
** Locking functions. The xLock() and xUnlock() methods are both no-ops.
** The xCheckReservedLock() always indicates that no other process holds
** a reserved lock on the database file. This ensures that if a hot-journal
** file is found in the file-system it is rolled back.
*/
static int demoLock(sqlite3_file *pFile, int eLock){
return SQLITE_OK;
}
static int demoUnlock(sqlite3_file *pFile, int eLock){
return SQLITE_OK;
}
static int demoCheckReservedLock(sqlite3_file *pFile, int *pResOut){
*pResOut = 0;
return SQLITE_OK;
}
/*
** No xFileControl() verbs are implemented by this VFS.
*/
static int demoFileControl(sqlite3_file *pFile, int op, void *pArg){
return SQLITE_OK;
}
/*
** The xSectorSize() and xDeviceCharacteristics() methods. These two
** may return special values allowing SQLite to optimize file-system
** access to some extent. But it is also safe to simply return 0.
*/
static int demoSectorSize(sqlite3_file *pFile){
return 0;
}
static int demoDeviceCharacteristics(sqlite3_file *pFile){
return 0;
}
/*
** Open a file handle.
*/
static int demoOpen(
sqlite3_vfs *pVfs, /* VFS */
const char *zName, /* File to open, or 0 for a temp file */
sqlite3_file *pFile, /* Pointer to DemoFile struct to populate */
int flags, /* Input SQLITE_OPEN_XXX flags */
int *pOutFlags /* Output SQLITE_OPEN_XXX flags (or NULL) */
){
static const sqlite3_io_methods demoio = {
1, /* iVersion */
demoClose, /* xClose */
demoRead, /* xRead */
demoWrite, /* xWrite */
demoTruncate, /* xTruncate */
demoSync, /* xSync */
demoFileSize, /* xFileSize */
demoLock, /* xLock */
demoUnlock, /* xUnlock */
demoCheckReservedLock, /* xCheckReservedLock */
demoFileControl, /* xFileControl */
demoSectorSize, /* xSectorSize */
demoDeviceCharacteristics /* xDeviceCharacteristics */
};
DemoFile *p = (DemoFile*)pFile; /* Populate this structure */
int oflags = 0; /* flags to pass to open() call */
char *aBuf = 0;
if( zName==0 ){
return SQLITE_IOERR;
}
if( flags&SQLITE_OPEN_MAIN_JOURNAL ){
aBuf = (char *)sqlite3_malloc(SQLITE_DEMOVFS_BUFFERSZ);
if( !aBuf ){
return SQLITE_NOMEM;
}
}
if( flags&SQLITE_OPEN_EXCLUSIVE ) oflags |= O_EXCL;
if( flags&SQLITE_OPEN_CREATE ) oflags |= O_CREAT;
if( flags&SQLITE_OPEN_READONLY ) oflags |= O_RDONLY;
if( flags&SQLITE_OPEN_READWRITE ) oflags |= O_RDWR;
memset(p, 0, sizeof(DemoFile));
p->fd = open(zName, oflags, 0600);
if( p->fd<0 ){
sqlite3_free(aBuf);
return SQLITE_CANTOPEN;
}
p->aBuffer = aBuf;
if( pOutFlags ){
*pOutFlags = flags;
}
p->base.pMethods = &demoio;
return SQLITE_OK;
}
/*
** Delete the file identified by argument zPath. If the dirSync parameter
** is non-zero, then ensure the file-system modification to delete the
** file has been synced to disk before returning.
*/
static int demoDelete(sqlite3_vfs *pVfs, const char *zPath, int dirSync){
int rc; /* Return code */
rc = unlink(zPath);
if( rc!=0 && errno==ENOENT ) return SQLITE_OK;
if( rc==0 && dirSync ){
int dfd; /* File descriptor open on directory */
int i; /* Iterator variable */
char zDir[MAXPATHNAME+1]; /* Name of directory containing file zPath */
/* Figure out the directory name from the path of the file deleted. */
sqlite3_snprintf(MAXPATHNAME, zDir, "%s", zPath);
zDir[MAXPATHNAME] = '\0';
for(i=strlen(zDir); i>1 && zDir[i]!='/'; i++);
zDir[i] = '\0';
/* Open a file-descriptor on the directory. Sync. Close. */
dfd = open(zDir, O_RDONLY, 0);
if( dfd<0 ){
rc = -1;
}else{
rc = fsync(dfd);
close(dfd);
}
}
return (rc==0 ? SQLITE_OK : SQLITE_IOERR_DELETE);
}
#ifndef F_OK
# define F_OK 0
#endif
#ifndef R_OK
# define R_OK 4
#endif
#ifndef W_OK
# define W_OK 2
#endif
/*
** Query the file-system to see if the named file exists, is readable or
** is both readable and writable.
*/
static int demoAccess(
sqlite3_vfs *pVfs,
const char *zPath,
int flags,
int *pResOut
){
int rc; /* access() return code */
int eAccess = F_OK; /* Second argument to access() */
assert( flags==SQLITE_ACCESS_EXISTS /* access(zPath, F_OK) */
|| flags==SQLITE_ACCESS_READ /* access(zPath, R_OK) */
|| flags==SQLITE_ACCESS_READWRITE /* access(zPath, R_OK|W_OK) */
);
if( flags==SQLITE_ACCESS_READWRITE ) eAccess = R_OK|W_OK;
if( flags==SQLITE_ACCESS_READ ) eAccess = R_OK;
rc = access(zPath, eAccess);
*pResOut = (rc==0);
return SQLITE_OK;
}
/*
** Argument zPath points to a nul-terminated string containing a file path.
** If zPath is an absolute path, then it is copied as is into the output
** buffer. Otherwise, if it is a relative path, then the equivalent full
** path is written to the output buffer.
**
** This function assumes that paths are UNIX style. Specifically, that:
**
** 1. Path components are separated by a '/'. and
** 2. Full paths begin with a '/' character.
*/
static int demoFullPathname(
sqlite3_vfs *pVfs, /* VFS */
const char *zPath, /* Input path (possibly a relative path) */
int nPathOut, /* Size of output buffer in bytes */
char *zPathOut /* Pointer to output buffer */
){
char zDir[MAXPATHNAME+1];
if( zPath[0]=='/' ){
zDir[0] = '\0';
}else{
if( getcwd(zDir, sizeof(zDir))==0 ) return SQLITE_IOERR;
}
zDir[MAXPATHNAME] = '\0';
sqlite3_snprintf(nPathOut, zPathOut, "%s/%s", zDir, zPath);
zPathOut[nPathOut-1] = '\0';
return SQLITE_OK;
}
/*
** The following four VFS methods:
**
** xDlOpen
** xDlError
** xDlSym
** xDlClose
**
** are supposed to implement the functionality needed by SQLite to load
** extensions compiled as shared objects. This simple VFS does not support
** this functionality, so the following functions are no-ops.
*/
static void *demoDlOpen(sqlite3_vfs *pVfs, const char *zPath){
return 0;
}
static void demoDlError(sqlite3_vfs *pVfs, int nByte, char *zErrMsg){
sqlite3_snprintf(nByte, zErrMsg, "Loadable extensions are not supported");
zErrMsg[nByte-1] = '\0';
}
static void (*demoDlSym(sqlite3_vfs *pVfs, void *pH, const char *z))(void){
return 0;
}
static void demoDlClose(sqlite3_vfs *pVfs, void *pHandle){
return;
}
/*
** Parameter zByte points to a buffer nByte bytes in size. Populate this
** buffer with pseudo-random data.
*/
static int demoRandomness(sqlite3_vfs *pVfs, int nByte, char *zByte){
return SQLITE_OK;
}
/*
** Sleep for at least nMicro microseconds. Return the (approximate) number
** of microseconds slept for.
*/
static int demoSleep(sqlite3_vfs *pVfs, int nMicro){
sleep(nMicro / 1000000);
usleep(nMicro % 1000000);
return nMicro;
}
/*
** Set *pTime to the current UTC time expressed as a Julian day. Return
** SQLITE_OK if successful, or an error code otherwise.
**
** http://en.wikipedia.org/wiki/Julian_day
**
** This implementation is not very good. The current time is rounded to
** an integer number of seconds. Also, assuming time_t is a signed 32-bit
** value, it will stop working some time in the year 2038 AD (the so-called
** "year 2038" problem that afflicts systems that store time this way).
*/
static int demoCurrentTime(sqlite3_vfs *pVfs, double *pTime){
time_t t = time(0);
*pTime = t/86400.0 + 2440587.5;
return SQLITE_OK;
}
/*
** This function returns a pointer to the VFS implemented in this file.
** To make the VFS available to SQLite:
**
** sqlite3_vfs_register(sqlite3_demovfs(), 0);
*/
sqlite3_vfs *sqlite3_demovfs(void){
static sqlite3_vfs demovfs = {
1, /* iVersion */
sizeof(DemoFile), /* szOsFile */
MAXPATHNAME, /* mxPathname */
0, /* pNext */
"demo", /* zName */
0, /* pAppData */
demoOpen, /* xOpen */
demoDelete, /* xDelete */
demoAccess, /* xAccess */
demoFullPathname, /* xFullPathname */
demoDlOpen, /* xDlOpen */
demoDlError, /* xDlError */
demoDlSym, /* xDlSym */
demoDlClose, /* xDlClose */
demoRandomness, /* xRandomness */
demoSleep, /* xSleep */
demoCurrentTime, /* xCurrentTime */
};
return &demovfs;
}
#endif /* !defined(SQLITE_TEST) || SQLITE_OS_UNIX */
#ifdef SQLITE_TEST
#if defined(INCLUDE_SQLITE_TCL_H)
# include "sqlite_tcl.h"
#else
# include "tcl.h"
# ifndef SQLITE_TCLAPI
# define SQLITE_TCLAPI
# endif
#endif
#if SQLITE_OS_UNIX
static int SQLITE_TCLAPI register_demovfs(
ClientData clientData, /* Pointer to sqlite3_enable_XXX function */
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
int objc, /* Number of arguments */
Tcl_Obj *CONST objv[] /* Command arguments */
){
sqlite3_vfs_register(sqlite3_demovfs(), 1);
return TCL_OK;
}
static int SQLITE_TCLAPI unregister_demovfs(
ClientData clientData, /* Pointer to sqlite3_enable_XXX function */
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
int objc, /* Number of arguments */
Tcl_Obj *CONST objv[] /* Command arguments */
){
sqlite3_vfs_unregister(sqlite3_demovfs());
return TCL_OK;
}
/*
** Register commands with the TCL interpreter.
*/
int Sqlitetest_demovfs_Init(Tcl_Interp *interp){
Tcl_CreateObjCommand(interp, "register_demovfs", register_demovfs, 0, 0);
Tcl_CreateObjCommand(interp, "unregister_demovfs", unregister_demovfs, 0, 0);
return TCL_OK;
}
#else
int Sqlitetest_demovfs_Init(Tcl_Interp *interp){ return TCL_OK; }
#endif
#endif /* SQLITE_TEST */
|
the_stack_data/618331.c | #include <stdio.h>
void imprime(char *v, int n) {
for (char *c = v; c < v + n; c++) printf ("%c", *c);
}
int main() {
char texto[] = "teste de texto";
imprime(texto, 5);
}
//https://pt.stackoverflow.com/q/155557/101
|
the_stack_data/154827895.c | #include <stdio.h>
int main()
{
int choice;
printf("Enter a number\n");
scanf("%d",&choice);
switch(choice)
{
case 1:printf("Food item - Sandwich\nPrice - Rs149\n");break;
case 2:printf("Food item - French Fries\nPrice - Rs99\n");break;
case 3:printf("Food item - Burger\nPrice - Rs129\n");break;
case 4:printf("Food item - Pizza\nPrice - Rs239\n");break;
case 5:printf("Food item - Pasta\nPrice - Rs179\n");break;
default:printf("Invalid Input");
}
}
|
the_stack_data/596316.c |
int factorial(int n) {
if (n == 0 || n == 1)
{
return 1;
}
else
{
return n*factorial(n - 1);
}
}
|
the_stack_data/59511724.c | #include <stdio.h>
#include <stdint.h>
#define ROL(a,b) (((a) << (b)) | ((a) >> (32 - (b))))
#define QUARTERROUND(x, a, b, c, d) \
x[b] ^= ROL(x[a] + x[d], 7); \
x[c] ^= ROL(x[b] + x[a], 9); \
x[d] ^= ROL(x[c] + x[b], 13); \
x[a] ^= ROL(x[d] + x[c], 18);
void salsa20(uint32_t * in, uint32_t * out){
for (int i = 0; i < 16; i++){
out[i] = in[i];
}
for (int i = 0; i < 10; i++){
QUARTERROUND(out, 0, 4, 8, 12);
QUARTERROUND(out, 5, 9, 13, 1);
QUARTERROUND(out, 10, 14, 2, 6);
QUARTERROUND(out, 15, 3, 7, 11);
QUARTERROUND(out, 0, 1, 2, 3);
QUARTERROUND(out, 5, 6, 7, 4);
QUARTERROUND(out, 10, 11, 8, 9);
QUARTERROUND(out, 15, 12, 13, 14);
}
for (int i = 0; i < 16; i++){
out[i] += in[i];
}
return;
}
int main(){
uint8_t key[32];
// scanf("%s", key);
for (int i = 1; i < 33; i++) key[i - 1] = i;
uint32_t *k = (uint32_t*) key;
uint32_t c[] = {0x61707865, 0x3320646e, 0x79622d32, 0x6b206574};
uint8_t nonce[] = {3,1,4,1,5,9,2,6};
uint32_t *n = (uint32_t*) nonce;
uint8_t block_counter[] = {7, 0, 0, 0, 0, 0, 0, 0};
uint32_t *b = (uint32_t*) block_counter;
uint32_t plain[16] = {c[0], k[0], k[1], k[2], k[3], c[1], n[0], n[1], b[0], b[1], c[2], k[4], k[5], k[6], k[7], c[3]};
uint32_t out[16];
salsa20(plain, out);
for (int i = 0; i < 16; i++) printf("0x%08x, ", out[i]);
printf("\n");
return 0;
} |
the_stack_data/1188125.c | /**
******************************************************************************
* @file stm32l0xx_hal_cryp_ex.c
* @author MCD Application Team
* @version V1.8.0
* @date 25-November-2016
* @brief CRYPEx HAL module driver.
*
* This file provides firmware functions to manage the following
* functionalities of the Cryptography (CRYP) extension peripheral:
* + Computation completed callback.
*
******************************************************************************
* @attention
*
* <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of STMicroelectronics nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
******************************************************************************
*/
#if defined (STM32L021xx) ||defined (STM32L041xx) || defined (STM32L061xx) || defined (STM32L062xx) || defined (STM32L063xx) || defined (STM32L081xx) || defined (STM32L082xx) || defined (STM32L083xx)
/* Includes ------------------------------------------------------------------*/
#include "stm32l0xx_hal.h"
/** @addtogroup STM32L0xx_HAL_Driver
* @{
*/
#ifdef HAL_CRYP_MODULE_ENABLED
/** @addtogroup CRYPEx
* @brief CRYP HAL Extended module driver.
* @{
*/
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
/** @addtogroup CRYPEx_Exported_Functions
* @{
*/
/** @addtogroup CRYPEx_Exported_Functions_Group1
* @brief Extended features functions.
*
@verbatim
===============================================================================
##### Extended features functions #####
===============================================================================
[..] This section provides callback functions:
(+) Computation completed.
@endverbatim
* @{
*/
/**
* @brief Computation completed callbacks.
* @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
* the configuration information for CRYP module
* @retval None
*/
__weak void HAL_CRYPEx_ComputationCpltCallback(CRYP_HandleTypeDef *hcryp)
{
/* Prevent unused argument(s) compilation warning */
UNUSED(hcryp);
/* NOTE : This function Should not be modified, when the callback is needed,
the HAL_CRYP_ComputationCpltCallback could be implemented in the user file
*/
}
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
#endif /* HAL_CRYP_MODULE_ENABLED */
/**
* @}
*/
#endif /* STM32L021xx || STM32L041xx || STM32L061xx || STM32L062xx || STM32L063xx || STM32L081xx || STM32L082xx || STM32L083xx */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
the_stack_data/39545.c | int f()
{
const int* p;
int v;
v = *p;
return 0;
}
|
the_stack_data/944997.c | #include <stdio.h>
int main() {
char x = 'a';
char *p; // = &x;
*p='b';
printf("*p=%c x=%c\n", *p, x);
}
|
the_stack_data/115969.c | // #include "zipmap.h"
// void zipmapRepr(unsigned char *p) {
// unsigned int l;
// printf("{status %u}",*p++);
// while(1) {
// if (p[0] == ZIPMAP_END) {
// printf("{end}");
// break;
// } else {
// unsigned char e;
// l = zipmapDecodeLength(p);
// printf("{key %u}",l);
// p += zipmapEncodeLength(NULL,l);
// if (l != 0 && fwrite(p,l,1,stdout) == 0) perror("fwrite");
// p += l;
// l = zipmapDecodeLength(p);
// printf("{value %u}",l);
// p += zipmapEncodeLength(NULL,l);
// e = *p++;
// if (l != 0 && fwrite(p,l,1,stdout) == 0) perror("fwrite");
// p += l+e;
// if (e) {
// printf("[");
// while(e--) printf(".");
// printf("]");
// }
// }
// }
// printf("\n");
// }
// int main(void) {
// unsigned char *zm;
// zm = zipmapNew();
// zm = zipmapSet(zm,(unsigned char*) "name",4, (unsigned char*) "foo",3,NULL);
// zm = zipmapSet(zm,(unsigned char*) "surname",7, (unsigned char*) "foo",3,NULL);
// zm = zipmapSet(zm,(unsigned char*) "age",3, (unsigned char*) "foo",3,NULL);
// zipmapRepr(zm);
// zm = zipmapSet(zm,(unsigned char*) "hello",5, (unsigned char*) "world!",6,NULL);
// zm = zipmapSet(zm,(unsigned char*) "foo",3, (unsigned char*) "bar",3,NULL);
// zm = zipmapSet(zm,(unsigned char*) "foo",3, (unsigned char*) "!",1,NULL);
// zipmapRepr(zm);
// zm = zipmapSet(zm,(unsigned char*) "foo",3, (unsigned char*) "12345",5,NULL);
// zipmapRepr(zm);
// zm = zipmapSet(zm,(unsigned char*) "new",3, (unsigned char*) "xx",2,NULL);
// zm = zipmapSet(zm,(unsigned char*) "noval",5, (unsigned char*) "",0,NULL);
// zipmapRepr(zm);
// zm = zipmapDel(zm,(unsigned char*) "new",3,NULL);
// zipmapRepr(zm);
// printf("\nLook up large key:\n");
// {
// unsigned char buf[512];
// unsigned char *value;
// unsigned int vlen, i;
// for (i = 0; i < 512; i++) buf[i] = 'a';
// zm = zipmapSet(zm,buf,512,(unsigned char*) "long",4,NULL);
// if (zipmapGet(zm,buf,512,&value,&vlen)) {
// printf(" <long key> is associated to the %d bytes value: %.*s\n",
// vlen, vlen, value);
// }
// }
// printf("\nPerform a direct lookup:\n");
// {
// unsigned char *value;
// unsigned int vlen;
// if (zipmapGet(zm,(unsigned char*) "foo",3,&value,&vlen)) {
// printf(" foo is associated to the %d bytes value: %.*s\n",
// vlen, vlen, value);
// }
// }
// printf("\nIterate through elements:\n");
// {
// unsigned char *i = zipmapRewind(zm);
// unsigned char *key, *value;
// unsigned int klen, vlen;
// while((i = zipmapNext(i,&key,&klen,&value,&vlen)) != NULL) {
// printf(" %d:%.*s => %d:%.*s\n", klen, klen, key, vlen, vlen, value);
// }
// }
// return 0;
// } |
the_stack_data/53254.c | #include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdlib.h>
char *sneaky = "SOSNEAKY";
int authenticate(char *username, char *password)
{
char stored_pw[9];
stored_pw[8] = 0;
int pwfile;
// evil back d00r
if (strcmp(password, sneaky) == 0) return 1;
pwfile = open(username, O_RDONLY);
read(pwfile, stored_pw, 8);
if (strcmp(password, stored_pw) == 0) return 1;
return 0;
}
int accepted()
{
printf("Welcome to the admin console, trusted user!\n");
return 0; // Added to recompile
}
int rejected()
{
printf("Go away!");
exit(1);
}
int main(int argc, char **argv)
{
char username[9];
char password[9];
int authed;
username[8] = 0;
password[8] = 0;
printf("Username: \n");
read(0, username, 8);
read(0, &authed, 1);
printf("Password: \n");
read(0, password, 8);
read(0, &authed, 1);
authed = authenticate(username, password);
if (authed) accepted();
else rejected();
} |
the_stack_data/74512.c | #include<stdio.h>
void My_strcat(unsigned char* ptr1, unsigned char *ptr2);
int main()
{
unsigned char str1[100] = "Madhiyan";
unsigned char str2[100] = "Swathi";
My_strcat(str1,str2);
printf("\r\n%s\r\n",str1);
}
void My_strcat(unsigned char* ptr1, unsigned char *ptr2)
{
unsigned int i=0;
unsigned int j=0;
while(ptr1[i] != '\0')
{
i++;
//printf("inside- %d",i);
}
while (ptr2[j] != '\0')
{
//printf("inside - %d",j);
ptr1[i] = ptr2[j];
i++;
j++;
}
}
|
the_stack_data/179830457.c | #include <stdio.h>
/* count digits, white space, and other characters */
int main()
{
int c;
int nwhite;
int nother;
int ndigit[10];
nwhite = nother = 0;
for (int i = 0; i < 10; ++i) {
ndigit[i] = 0;
}
while ((c = getchar()) != EOF) {
if (c >= '0' && c <= '9') {
++ndigit[c-'0'];
} else if (c == ' ' || c == '\t' || c == '\n') {
++nwhite;
} else {
++nother;
}
}
printf("digits: ");
for (int i = 0; i < 10; ++i) {
printf("%d ", ndigit[i]);
}
printf(" whitespace: %d other: %d\n", nwhite, nother);
}
|
the_stack_data/132952916.c | #include<stdio.h>
#include<math.h>
int gcd(int a, int b) {
int r;
do{
r=a%b;
a=b;
b=r;
}while(r!=0);
return a;
}
int main(void){
double k,n,d,cont=0;
int x=0;
while(k!=0){
scanf("%lf",&k);
cont=0;
if(k!=0){
x=0;
d=1;
while(x==0){
for(n=0; n<=d; n++){
if(gcd(n,d) == 1){
cont++;
if(cont==k){
printf("%.0lf/%.0lf\n",n,d);
x=1;
}
}
}
d++;
}
}
}
} |
the_stack_data/161081416.c | typedef signed char __int8_t;
typedef unsigned char __uint8_t;
typedef short int __int16_t;
typedef short unsigned int __uint16_t;
typedef long int __int32_t;
typedef long unsigned int __uint32_t;
typedef long long int __int64_t;
typedef long long unsigned int __uint64_t;
typedef signed char __int_least8_t;
typedef unsigned char __uint_least8_t;
typedef short int __int_least16_t;
typedef short unsigned int __uint_least16_t;
typedef long int __int_least32_t;
typedef long unsigned int __uint_least32_t;
typedef long long int __int_least64_t;
typedef long long unsigned int __uint_least64_t;
typedef int __intptr_t;
typedef unsigned int __uintptr_t;
typedef __int8_t int8_t ;
typedef __uint8_t uint8_t ;
typedef __int16_t int16_t ;
typedef __uint16_t uint16_t ;
typedef __int32_t int32_t ;
typedef __uint32_t uint32_t ;
typedef __int64_t int64_t ;
typedef __uint64_t uint64_t ;
typedef __intptr_t intptr_t;
typedef __uintptr_t uintptr_t;
typedef __int_least8_t int_least8_t;
typedef __uint_least8_t uint_least8_t;
typedef __int_least16_t int_least16_t;
typedef __uint_least16_t uint_least16_t;
typedef __int_least32_t int_least32_t;
typedef __uint_least32_t uint_least32_t;
typedef __int_least64_t int_least64_t;
typedef __uint_least64_t uint_least64_t;
typedef int int_fast8_t;
typedef unsigned int uint_fast8_t;
typedef int int_fast16_t;
typedef unsigned int uint_fast16_t;
typedef int int_fast32_t;
typedef unsigned int uint_fast32_t;
typedef long long int int_fast64_t;
typedef long long unsigned int uint_fast64_t;
typedef long long int intmax_t;
typedef long long unsigned int uintmax_t;
typedef int ptrdiff_t;
typedef unsigned int size_t;
typedef unsigned int wchar_t;
typedef struct {
long long __max_align_ll __attribute__((__aligned__(__alignof__(long long))));
long double __max_align_ld __attribute__((__aligned__(__alignof__(long double))));
} max_align_t;
typedef signed char s8_t;
typedef signed short s16_t;
typedef signed int s32_t;
typedef signed long long s64_t;
typedef unsigned char u8_t;
typedef unsigned short u16_t;
typedef unsigned int u32_t;
typedef unsigned long long u64_t;
struct _snode {
struct _snode *next;
};
typedef struct _snode sys_snode_t;
struct _slist {
sys_snode_t *head;
sys_snode_t *tail;
};
typedef struct _slist sys_slist_t;
static inline void sys_slist_init(sys_slist_t *list)
{
list->head =
((void *)0)
;
list->tail =
((void *)0)
;
}
static inline
_Bool
sys_slist_is_empty(sys_slist_t *list)
{
return (!list->head);
}
static inline sys_snode_t *sys_slist_peek_head(sys_slist_t *list)
{
return list->head;
}
static inline sys_snode_t *sys_slist_peek_tail(sys_slist_t *list)
{
return list->tail;
}
static inline sys_snode_t *sys_slist_peek_next_no_check(sys_snode_t *node)
{
return node->next;
}
static inline sys_snode_t *sys_slist_peek_next(sys_snode_t *node)
{
return node ? sys_slist_peek_next_no_check(node) :
((void *)0)
;
}
static inline void sys_slist_prepend(sys_slist_t *list,
sys_snode_t *node)
{
node->next = list->head;
list->head = node;
if (!list->tail) {
list->tail = list->head;
}
}
static inline void sys_slist_append(sys_slist_t *list,
sys_snode_t *node)
{
node->next =
((void *)0)
;
if (!list->tail) {
list->tail = node;
list->head = node;
} else {
list->tail->next = node;
list->tail = node;
}
}
static inline void sys_slist_append_list(sys_slist_t *list,
void *head, void *tail)
{
if (!list->tail) {
list->head = (sys_snode_t *)head;
list->tail = (sys_snode_t *)tail;
} else {
list->tail->next = (sys_snode_t *)head;
list->tail = (sys_snode_t *)tail;
}
}
static inline void sys_slist_merge_slist(sys_slist_t *list,
sys_slist_t *list_to_append)
{
sys_slist_append_list(list, list_to_append->head,
list_to_append->tail);
sys_slist_init(list_to_append);
}
static inline void sys_slist_insert(sys_slist_t *list,
sys_snode_t *prev,
sys_snode_t *node)
{
if (!prev) {
sys_slist_prepend(list, node);
} else if (!prev->next) {
sys_slist_append(list, node);
} else {
node->next = prev->next;
prev->next = node;
}
}
static inline sys_snode_t *sys_slist_get_not_empty(sys_slist_t *list)
{
sys_snode_t *node = list->head;
list->head = node->next;
if (list->tail == node) {
list->tail = list->head;
}
return node;
}
static inline sys_snode_t *sys_slist_get(sys_slist_t *list)
{
return sys_slist_is_empty(list) ?
((void *)0)
: sys_slist_get_not_empty(list);
}
static inline void sys_slist_remove(sys_slist_t *list,
sys_snode_t *prev_node,
sys_snode_t *node)
{
if (!prev_node) {
list->head = node->next;
if (list->tail == node) {
list->tail = list->head;
}
} else {
prev_node->next = node->next;
if (list->tail == node) {
list->tail = prev_node;
}
}
node->next =
((void *)0)
;
}
static inline
_Bool
sys_slist_find_and_remove(sys_slist_t *list,
sys_snode_t *node)
{
sys_snode_t *prev =
((void *)0)
;
sys_snode_t *test;
for (test = sys_slist_peek_head(list); test; test = sys_slist_peek_next(test)) {
if (test == node) {
sys_slist_remove(list, prev, node);
return
1
;
}
prev = test;
}
return
0
;
}
struct _dnode {
union {
struct _dnode *head;
struct _dnode *next;
};
union {
struct _dnode *tail;
struct _dnode *prev;
};
};
typedef struct _dnode sys_dlist_t;
typedef struct _dnode sys_dnode_t;
static inline void sys_dlist_init(sys_dlist_t *list)
{
list->head = (sys_dnode_t *)list;
list->tail = (sys_dnode_t *)list;
}
static inline int sys_dlist_is_head(sys_dlist_t *list, sys_dnode_t *node)
{
return list->head == node;
}
static inline int sys_dlist_is_tail(sys_dlist_t *list, sys_dnode_t *node)
{
return list->tail == node;
}
static inline int sys_dlist_is_empty(sys_dlist_t *list)
{
return list->head == list;
}
static inline int sys_dlist_has_multiple_nodes(sys_dlist_t *list)
{
return list->head != list->tail;
}
static inline sys_dnode_t *sys_dlist_peek_head(sys_dlist_t *list)
{
return sys_dlist_is_empty(list) ?
((void *)0)
: list->head;
}
static inline sys_dnode_t *sys_dlist_peek_head_not_empty(sys_dlist_t *list)
{
return list->head;
}
static inline sys_dnode_t *sys_dlist_peek_next_no_check(sys_dlist_t *list,
sys_dnode_t *node)
{
return (node == list->tail) ?
((void *)0)
: node->next;
}
static inline sys_dnode_t *sys_dlist_peek_next(sys_dlist_t *list,
sys_dnode_t *node)
{
return node ? sys_dlist_peek_next_no_check(list, node) :
((void *)0)
;
}
static inline sys_dnode_t *sys_dlist_peek_tail(sys_dlist_t *list)
{
return sys_dlist_is_empty(list) ?
((void *)0)
: list->tail;
}
static inline void sys_dlist_append(sys_dlist_t *list, sys_dnode_t *node)
{
node->next = list;
node->prev = list->tail;
list->tail->next = node;
list->tail = node;
}
static inline void sys_dlist_prepend(sys_dlist_t *list, sys_dnode_t *node)
{
node->next = list->head;
node->prev = list;
list->head->prev = node;
list->head = node;
}
static inline void sys_dlist_insert_after(sys_dlist_t *list,
sys_dnode_t *insert_point, sys_dnode_t *node)
{
if (!insert_point) {
sys_dlist_prepend(list, node);
} else {
node->next = insert_point->next;
node->prev = insert_point;
insert_point->next->prev = node;
insert_point->next = node;
}
}
static inline void sys_dlist_insert_before(sys_dlist_t *list,
sys_dnode_t *insert_point, sys_dnode_t *node)
{
if (!insert_point) {
sys_dlist_append(list, node);
} else {
node->prev = insert_point->prev;
node->next = insert_point;
insert_point->prev->next = node;
insert_point->prev = node;
}
}
static inline void sys_dlist_insert_at(sys_dlist_t *list, sys_dnode_t *node,
int (*cond)(sys_dnode_t *, void *), void *data)
{
if (sys_dlist_is_empty(list)) {
sys_dlist_append(list, node);
} else {
sys_dnode_t *pos = sys_dlist_peek_head(list);
while (pos && !cond(pos, data)) {
pos = sys_dlist_peek_next(list, pos);
}
sys_dlist_insert_before(list, pos, node);
}
}
static inline void sys_dlist_remove(sys_dnode_t *node)
{
node->prev->next = node->next;
node->next->prev = node->prev;
}
static inline sys_dnode_t *sys_dlist_get(sys_dlist_t *list)
{
sys_dnode_t *node;
if (sys_dlist_is_empty(list)) {
return
((void *)0)
;
}
node = list->head;
sys_dlist_remove(node);
return node;
}
extern unsigned int aos_log_level;
static inline unsigned int aos_log_get_level(void)
{
return aos_log_level;
}
enum log_level_bit {
AOS_LL_V_NONE_BIT = -1,
AOS_LL_V_FATAL_BIT,
AOS_LL_V_ERROR_BIT,
AOS_LL_V_WARN_BIT,
AOS_LL_V_INFO_BIT,
AOS_LL_V_DEBUG_BIT,
AOS_LL_V_MAX_BIT
};
typedef __uint8_t u_int8_t;
typedef __uint16_t u_int16_t;
typedef __uint32_t u_int32_t;
typedef __uint64_t u_int64_t;
typedef int register_t;
typedef int _LOCK_T;
typedef int _LOCK_RECURSIVE_T;
typedef long __blkcnt_t;
typedef long __blksize_t;
typedef __uint64_t __fsblkcnt_t;
typedef __uint32_t __fsfilcnt_t;
typedef long _off_t;
typedef int __pid_t;
typedef short __dev_t;
typedef unsigned short __uid_t;
typedef unsigned short __gid_t;
typedef __uint32_t __id_t;
typedef unsigned short __ino_t;
typedef __uint32_t __mode_t;
__extension__ typedef long long _off64_t;
typedef _off_t __off_t;
typedef _off64_t __loff_t;
typedef long __key_t;
typedef long _fpos_t;
typedef unsigned int __size_t;
typedef signed int _ssize_t;
typedef _ssize_t __ssize_t;
typedef unsigned int wint_t;
typedef struct
{
int __count;
union
{
wint_t __wch;
unsigned char __wchb[4];
} __value;
} _mbstate_t;
typedef _LOCK_RECURSIVE_T _flock_t;
typedef void *_iconv_t;
typedef unsigned long __clock_t;
typedef long __time_t;
typedef unsigned long __clockid_t;
typedef unsigned long __timer_t;
typedef __uint8_t __sa_family_t;
typedef __uint32_t __socklen_t;
typedef unsigned short __nlink_t;
typedef long __suseconds_t;
typedef unsigned long __useconds_t;
typedef __builtin_va_list __va_list;
typedef unsigned long __sigset_t;
typedef __suseconds_t suseconds_t;
typedef long time_t;
struct timeval {
time_t tv_sec;
suseconds_t tv_usec;
};
struct timespec {
time_t tv_sec;
long tv_nsec;
};
struct itimerspec {
struct timespec it_interval;
struct timespec it_value;
};
typedef __sigset_t sigset_t;
typedef unsigned long fd_mask;
typedef struct _types_fd_set {
fd_mask fds_bits[(((64)+(((sizeof (fd_mask) * 8))-1))/((sizeof (fd_mask) * 8)))];
} _types_fd_set;
int select (int __n, _types_fd_set *__readfds, _types_fd_set *__writefds, _types_fd_set *__exceptfds, struct timeval *__timeout)
;
int pselect (int __n, _types_fd_set *__readfds, _types_fd_set *__writefds, _types_fd_set *__exceptfds, const struct timespec *__timeout, const sigset_t *__set)
;
typedef __uint32_t in_addr_t;
typedef __uint16_t in_port_t;
typedef unsigned char u_char;
typedef unsigned short u_short;
typedef unsigned int u_int;
typedef unsigned long u_long;
typedef unsigned short ushort;
typedef unsigned int uint;
typedef unsigned long ulong;
typedef __blkcnt_t blkcnt_t;
typedef __blksize_t blksize_t;
typedef unsigned long clock_t;
typedef long daddr_t;
typedef char * caddr_t;
typedef __fsblkcnt_t fsblkcnt_t;
typedef __fsfilcnt_t fsfilcnt_t;
typedef __id_t id_t;
typedef __ino_t ino_t;
typedef __off_t off_t;
typedef __dev_t dev_t;
typedef __uid_t uid_t;
typedef __gid_t gid_t;
typedef __pid_t pid_t;
typedef __key_t key_t;
typedef _ssize_t ssize_t;
typedef __mode_t mode_t;
typedef __nlink_t nlink_t;
typedef __clockid_t clockid_t;
typedef __timer_t timer_t;
typedef __useconds_t useconds_t;
typedef __int64_t sbintime_t;
typedef struct {
void *hdl;
} aos_hdl_t;
typedef aos_hdl_t aos_task_t;
typedef aos_hdl_t aos_mutex_t;
typedef aos_hdl_t aos_sem_t;
typedef aos_hdl_t aos_queue_t;
typedef aos_hdl_t aos_timer_t;
typedef aos_hdl_t aos_work_t;
typedef aos_hdl_t aos_event_t;
typedef struct {
void *hdl;
void *stk;
} aos_workqueue_t;
typedef unsigned int aos_task_key_t;
void aos_reboot(void);
int aos_get_hz(void);
const char *aos_version_get(void);
int aos_task_new(const char *name, void (*fn)(void *), void *arg, int stack_size);
int aos_task_new_ext(aos_task_t *task, const char *name, void (*fn)(void *), void *arg,
int stack_size, int prio);
void aos_task_exit(int code);
const char *aos_task_name(void);
int aos_task_key_create(aos_task_key_t *key);
void aos_task_key_delete(aos_task_key_t key);
int aos_task_setspecific(aos_task_key_t key, void *vp);
void *aos_task_getspecific(aos_task_key_t key);
int aos_mutex_new(aos_mutex_t *mutex);
void aos_mutex_free(aos_mutex_t *mutex);
int aos_mutex_lock(aos_mutex_t *mutex, unsigned int timeout);
int aos_mutex_unlock(aos_mutex_t *mutex);
int aos_mutex_is_valid(aos_mutex_t *mutex);
int aos_sem_new(aos_sem_t *sem, int count);
void aos_sem_free(aos_sem_t *sem);
int aos_sem_wait(aos_sem_t *sem, unsigned int timeout);
void aos_sem_signal(aos_sem_t *sem);
int aos_sem_is_valid(aos_sem_t *sem);
void aos_sem_signal_all(aos_sem_t *sem);
int aos_event_new(aos_event_t *event, unsigned int flags);
void aos_event_free(aos_event_t *event);
int aos_event_get(aos_event_t *event, unsigned int flags, unsigned char opt,
unsigned int *actl_flags, unsigned int timeout);
int aos_event_set(aos_event_t *event, unsigned int flags, unsigned char opt);
int aos_queue_new(aos_queue_t *queue, void *buf, unsigned int size, int max_msg);
void aos_queue_free(aos_queue_t *queue);
int aos_queue_send(aos_queue_t *queue, void *msg, unsigned int size);
int aos_queue_recv(aos_queue_t *queue, unsigned int ms, void *msg, unsigned int *size);
int aos_queue_is_valid(aos_queue_t *queue);
void *aos_queue_buf_ptr(aos_queue_t *queue);
int aos_timer_new(aos_timer_t *timer, void (*fn)(void *, void *),
void *arg, int ms, int repeat);
int aos_timer_new_ext(aos_timer_t *timer, void (*fn)(void *, void *),
void *arg, int ms, int repeat, unsigned char auto_run);
void aos_timer_free(aos_timer_t *timer);
int aos_timer_start(aos_timer_t *timer);
int aos_timer_stop(aos_timer_t *timer);
int aos_timer_change(aos_timer_t *timer, int ms);
int aos_workqueue_create(aos_workqueue_t *workqueue, int pri, int stack_size);
int aos_work_init(aos_work_t *work, void (*fn)(void *), void *arg, int dly);
void aos_work_destroy(aos_work_t *work);
int aos_work_run(aos_workqueue_t *workqueue, aos_work_t *work);
int aos_work_sched(aos_work_t *work);
int aos_work_cancel(aos_work_t *work);
void *aos_realloc(void *mem, unsigned int size);
void *aos_malloc(unsigned int size);
void *aos_zalloc(unsigned int size);
void aos_alloc_trace(void *addr, size_t allocator);
void aos_free(void *mem);
long long aos_now(void);
long long aos_now_ms(void);
void aos_msleep(int ms);
void aos_init(void);
void aos_start(void);
extern int csp_printf(const char *fmt, ...);
int csp_printf(const char *fmt, ...);
typedef enum {
AOS_LL_NONE,
AOS_LL_FATAL,
AOS_LL_ERROR,
AOS_LL_WARN,
AOS_LL_INFO,
AOS_LL_DEBUG,
} aos_log_level_t;
extern unsigned int aos_log_level;
static inline int aos_get_log_level(void)
{
return aos_log_level;
}
void aos_set_log_level(aos_log_level_t log_level);
void __assert (const char *, int, const char *) __attribute__ ((__noreturn__))
;
void __assert_func (const char *, int, const char *, const char *) __attribute__ ((__noreturn__))
;
typedef unsigned long __ULong;
struct _reent;
struct __locale_t;
struct _Bigint
{
struct _Bigint *_next;
int _k, _maxwds, _sign, _wds;
__ULong _x[1];
};
struct __tm
{
int __tm_sec;
int __tm_min;
int __tm_hour;
int __tm_mday;
int __tm_mon;
int __tm_year;
int __tm_wday;
int __tm_yday;
int __tm_isdst;
};
struct _on_exit_args {
void * _fnargs[32];
void * _dso_handle[32];
__ULong _fntypes;
__ULong _is_cxa;
};
struct _atexit {
struct _atexit *_next;
int _ind;
void (*_fns[32])(void);
struct _on_exit_args _on_exit_args;
};
struct __sbuf {
unsigned char *_base;
int _size;
};
struct __sFILE {
unsigned char *_p;
int _r;
int _w;
short _flags;
short _file;
struct __sbuf _bf;
int _lbfsize;
void * _cookie;
int (* _read) (struct _reent *, void *, char *, int)
;
int (* _write) (struct _reent *, void *, const char *, int)
;
_fpos_t (* _seek) (struct _reent *, void *, _fpos_t, int);
int (* _close) (struct _reent *, void *);
struct __sbuf _ub;
unsigned char *_up;
int _ur;
unsigned char _ubuf[3];
unsigned char _nbuf[1];
struct __sbuf _lb;
int _blksize;
_off_t _offset;
struct _reent *_data;
_flock_t _lock;
_mbstate_t _mbstate;
int _flags2;
};
typedef struct __sFILE __FILE;
struct _glue
{
struct _glue *_next;
int _niobs;
__FILE *_iobs;
};
struct _rand48 {
unsigned short _seed[3];
unsigned short _mult[3];
unsigned short _add;
};
struct _reent
{
int _errno;
__FILE *_stdin, *_stdout, *_stderr;
int _inc;
char _emergency[25];
int _unspecified_locale_info;
struct __locale_t *_locale;
int __sdidinit;
void (* __cleanup) (struct _reent *);
struct _Bigint *_result;
int _result_k;
struct _Bigint *_p5s;
struct _Bigint **_freelist;
int _cvtlen;
char *_cvtbuf;
union
{
struct
{
unsigned int _unused_rand;
char * _strtok_last;
char _asctime_buf[26];
struct __tm _localtime_buf;
int _gamma_signgam;
__extension__ unsigned long long _rand_next;
struct _rand48 _r48;
_mbstate_t _mblen_state;
_mbstate_t _mbtowc_state;
_mbstate_t _wctomb_state;
char _l64a_buf[8];
char _signal_buf[24];
int _getdate_err;
_mbstate_t _mbrlen_state;
_mbstate_t _mbrtowc_state;
_mbstate_t _mbsrtowcs_state;
_mbstate_t _wcrtomb_state;
_mbstate_t _wcsrtombs_state;
int _h_errno;
} _reent;
struct
{
unsigned char * _nextf[30];
unsigned int _nmalloc[30];
} _unused;
} _new;
struct _atexit *_atexit;
struct _atexit _atexit0;
void (**(_sig_func))(int);
struct _glue __sglue;
__FILE __sf[3];
};
extern struct _reent *_impure_ptr ;
extern struct _reent *const _global_impure_ptr ;
void _reclaim_reent (struct _reent *);
struct __locale_t;
typedef struct __locale_t *locale_t;
void * memchr (const void *, int, size_t);
int memcmp (const void *, const void *, size_t);
void * memcpy (void * restrict, const void * restrict, size_t);
void * memmove (void *, const void *, size_t);
void * memset (void *, int, size_t);
char *strcat (char *restrict, const char *restrict);
char *strchr (const char *, int);
int strcmp (const char *, const char *);
int strcoll (const char *, const char *);
char *strcpy (char *restrict, const char *restrict);
size_t strcspn (const char *, const char *);
char *strerror (int);
size_t strlen (const char *);
char *strncat (char *restrict, const char *restrict, size_t);
int strncmp (const char *, const char *, size_t);
char *strncpy (char *restrict, const char *restrict, size_t);
char *strpbrk (const char *, const char *);
char *strrchr (const char *, int);
size_t strspn (const char *, const char *);
char *strstr (const char *, const char *);
char *strtok (char *restrict, const char *restrict);
size_t strxfrm (char *restrict, const char *restrict, size_t);
int strcoll_l (const char *, const char *, locale_t);
char *strerror_l (int, locale_t);
size_t strxfrm_l (char *restrict, const char *restrict, size_t, locale_t);
char *strtok_r (char *restrict, const char *restrict, char **restrict);
int bcmp (const void *, const void *, size_t);
void bcopy (const void *, void *, size_t);
void bzero (void *, size_t);
void explicit_bzero (void *, size_t);
int timingsafe_bcmp (const void *, const void *, size_t);
int timingsafe_memcmp (const void *, const void *, size_t);
int ffs (int);
char *index (const char *, int);
void * memccpy (void * restrict, const void * restrict, int, size_t);
char *rindex (const char *, int);
char *stpcpy (char *restrict, const char *restrict);
char *stpncpy (char *restrict, const char *restrict, size_t);
int strcasecmp (const char *, const char *);
char *strdup (const char *);
char *_strdup_r (struct _reent *, const char *);
char *strndup (const char *, size_t);
char *_strndup_r (struct _reent *, const char *, size_t);
int strerror_r (int, char *, size_t)
__asm__ ("" "__xpg_strerror_r")
;
char * _strerror_r (struct _reent *, int, int, int *);
size_t strlcat (char *, const char *, size_t);
size_t strlcpy (char *, const char *, size_t);
int strncasecmp (const char *, const char *, size_t);
size_t strnlen (const char *, size_t);
char *strsep (char **, const char *);
char *strlwr (char *);
char *strupr (char *);
char *strsignal (int __signo);
typedef char name_t;
typedef uint32_t sem_count_t;
typedef uint32_t cpu_stack_t;
typedef uint32_t hr_timer_t;
typedef uint32_t lr_timer_t;
typedef uint32_t mutex_nested_t;
typedef uint8_t suspend_nested_t;
typedef uint64_t ctx_switch_t;
typedef uint32_t cpu_cpsr_t;
typedef aos_queue_t _queue_t;
typedef aos_sem_t _sem_t;
typedef aos_task_t _task_t;
typedef cpu_stack_t _stack_element_t;
typedef aos_mutex_t _mutex_t;
enum {
LOG_LEVEL_NONE = 0,
LOG_LEVEL_FATAL,
LOG_LEVEL_ERROR,
LOG_LEVEL_WARN,
LOG_LEVEL_INFO,
LOG_LEVEL_DEBUG,
LOG_LEVEL_MAX_BIT
};
typedef sys_dlist_t _wait_q_t;
struct k_queue {
_queue_t *_queue;
sys_dlist_t poll_events;
};
extern void k_queue_init(struct k_queue *queue);
extern void k_queue_cancel_wait(struct k_queue *queue);
extern void k_queue_append(struct k_queue *queue, void *data);
extern void k_queue_prepend(struct k_queue *queue, void *data);
extern void k_queue_insert(struct k_queue *queue, void *prev, void *data);
extern void k_queue_append_list(struct k_queue *queue, void *head, void *tail);
extern void *k_queue_get(struct k_queue *queue, s32_t timeout);
extern int k_queue_is_empty(struct k_queue *queue);
struct k_lifo {
struct k_queue _queue;
};
struct k_fifo {
struct k_queue _queue;
};
struct k_sem {
_sem_t sem;
sys_dlist_t poll_events;
};
int k_sem_init(struct k_sem *sem, unsigned int initial_count, unsigned int limit);
int k_sem_take(struct k_sem *sem, uint32_t timeout);
int k_sem_give(struct k_sem *sem);
int k_sem_delete(struct k_sem *sem);
unsigned int k_sem_count_get(struct k_sem *sem);
struct k_mutex {
_mutex_t mutex;
sys_dlist_t poll_events;
};
typedef void (*k_timer_handler_t)(void *timer, void *args);
typedef struct k_timer {
aos_timer_t timer;
k_timer_handler_t handler;
void *args;
uint32_t timeout;
uint32_t start_ms;
} k_timer_t;
void k_timer_init(k_timer_t *timer, k_timer_handler_t handle, void *args);
void k_timer_start(k_timer_t *timer, uint32_t timeout);
void k_timer_stop(k_timer_t *timer);
int64_t k_uptime_get();
inline u32_t k_uptime_get_32(void)
{
return (u32_t)aos_now_ms();
}
struct k_thread {
_task_t task;
};
typedef _stack_element_t k_thread_stack_t;
inline void k_call_stacks_analyze(void) { }
static inline char *K_THREAD_STACK_BUFFER(k_thread_stack_t *sym)
{
return (char *)sym;
}
typedef void (*k_thread_entry_t)(void *p1, void *p2, void *p3);
int k_thread_create(struct k_thread *new_thread, k_thread_stack_t *stack,
size_t stack_size, k_thread_entry_t entry,
void *p1, void *p2, void *p3,
int prio, u32_t options, s32_t delay);
int k_yield();
unsigned int irq_lock();
void irq_unlock(unsigned int key);
typedef int atomic_t;
typedef atomic_t atomic_val_t;
extern int atomic_cas(atomic_t *target, atomic_val_t old_value,
atomic_val_t new_value);
extern atomic_val_t atomic_add(atomic_t *target, atomic_val_t value);
extern atomic_val_t atomic_sub(atomic_t *target, atomic_val_t value);
extern atomic_val_t atomic_inc(atomic_t *target);
extern atomic_val_t atomic_dec(atomic_t *target);
extern atomic_val_t atomic_get(const atomic_t *target);
extern atomic_val_t atomic_set(atomic_t *target, atomic_val_t value);
extern atomic_val_t atomic_clear(atomic_t *target);
extern atomic_val_t atomic_or(atomic_t *target, atomic_val_t value);
extern atomic_val_t atomic_xor(atomic_t *target, atomic_val_t value);
extern atomic_val_t atomic_and(atomic_t *target, atomic_val_t value);
extern atomic_val_t atomic_nand(atomic_t *target, atomic_val_t value);
static inline int atomic_test_bit(const atomic_t *target, int bit)
{
atomic_val_t val = atomic_get(((target) + ((bit) / (sizeof(atomic_val_t) * 8))));
return (1 & (val >> (bit & ((sizeof(atomic_val_t) * 8) - 1))));
}
static inline int atomic_test_and_clear_bit(atomic_t *target, int bit)
{
atomic_val_t mask = (1 << ((bit) & ((sizeof(atomic_val_t) * 8) - 1)));
atomic_val_t old;
old = atomic_and(((target) + ((bit) / (sizeof(atomic_val_t) * 8))), ~mask);
return (old & mask) != 0;
}
static inline int atomic_test_and_set_bit(atomic_t *target, int bit)
{
atomic_val_t mask = (1 << ((bit) & ((sizeof(atomic_val_t) * 8) - 1)));
atomic_val_t old;
old = atomic_or(((target) + ((bit) / (sizeof(atomic_val_t) * 8))), mask);
return (old & mask) != 0;
}
static inline void atomic_clear_bit(atomic_t *target, int bit)
{
atomic_val_t mask = (1 << ((bit) & ((sizeof(atomic_val_t) * 8) - 1)));
atomic_and(((target) + ((bit) / (sizeof(atomic_val_t) * 8))), ~mask);
}
static inline void atomic_set_bit(atomic_t *target, int bit)
{
atomic_val_t mask = (1 << ((bit) & ((sizeof(atomic_val_t) * 8) - 1)));
atomic_or(((target) + ((bit) / (sizeof(atomic_val_t) * 8))), mask);
}
struct k_work_q {
struct k_fifo fifo;
};
int k_work_q_start();
enum {
K_WORK_STATE_PENDING,
};
struct k_work;
typedef void (*k_work_handler_t)(struct k_work *work);
struct k_work {
void *_reserved;
k_work_handler_t handler;
atomic_t flags[1];
};
int k_work_init(struct k_work *work, k_work_handler_t handler);
void k_work_submit(struct k_work *work);
struct k_delayed_work {
struct k_work work;
struct k_work_q *work_q;
k_timer_t timer;
};
void k_delayed_work_init(struct k_delayed_work *work, k_work_handler_t handler);
int k_delayed_work_submit(struct k_delayed_work *work, uint32_t delay);
int k_delayed_work_cancel(struct k_delayed_work *work);
s32_t k_delayed_work_remaining_get(struct k_delayed_work *work);
enum _poll_types_bits {
_POLL_TYPE_IGNORE,
_POLL_TYPE_SIGNAL,
_POLL_TYPE_SEM_AVAILABLE,
_POLL_TYPE_DATA_AVAILABLE,
_POLL_NUM_TYPES
};
enum _poll_states_bits {
_POLL_STATE_NOT_READY,
_POLL_STATE_SIGNALED,
_POLL_STATE_SEM_AVAILABLE,
_POLL_STATE_DATA_AVAILABLE,
_POLL_NUM_STATES
};
struct k_poll_event {
sys_dnode_t _node;
struct _poller *poller;
u32_t tag:8;
u32_t type:_POLL_NUM_TYPES;
u32_t state:_POLL_NUM_STATES;
u32_t mode:1;
u32_t unused:(32 - (0 + 8 + _POLL_NUM_TYPES + _POLL_NUM_STATES + 1 ));
union {
void *obj;
struct k_poll_signal *signal;
struct k_sem *sem;
struct k_fifo *fifo;
struct k_queue *queue;
};
};
struct k_poll_signal {
sys_dlist_t poll_events;
unsigned int signaled;
int result;
};
extern int k_poll_signal(struct k_poll_signal *signal, int result);
extern int k_poll(struct k_poll_event *events, int num_events, s32_t timeout);
extern void k_poll_event_init(struct k_poll_event *event, u32_t type, int mode, void *obj);
enum k_poll_modes {
K_POLL_MODE_NOTIFY_ONLY = 0,
K_POLL_NUM_MODES
};
void k_sleep(s32_t duration);
unsigned int find_msb_set(u32_t op);
unsigned int find_lsb_set(u32_t op);
typedef __builtin_va_list __gnuc_va_list;
typedef __gnuc_va_list va_list;
typedef __FILE FILE;
typedef _fpos_t fpos_t;
char * ctermid (char *);
FILE * tmpfile (void);
char * tmpnam (char *);
char * tempnam (const char *, const char *);
int fclose (FILE *);
int fflush (FILE *);
FILE * freopen (const char *restrict, const char *restrict, FILE *restrict);
void setbuf (FILE *restrict, char *restrict);
int setvbuf (FILE *restrict, char *restrict, int, size_t);
int fprintf (FILE *restrict, const char *restrict, ...) __attribute__ ((__format__ (__printf__, 2, 3)))
;
int fscanf (FILE *restrict, const char *restrict, ...) __attribute__ ((__format__ (__scanf__, 2, 3)))
;
int printf (const char *restrict, ...) __attribute__ ((__format__ (__printf__, 1, 2)))
;
int scanf (const char *restrict, ...) __attribute__ ((__format__ (__scanf__, 1, 2)))
;
int sscanf (const char *restrict, const char *restrict, ...) __attribute__ ((__format__ (__scanf__, 2, 3)))
;
int vfprintf (FILE *restrict, const char *restrict, __gnuc_va_list) __attribute__ ((__format__ (__printf__, 2, 0)))
;
int vprintf (const char *, __gnuc_va_list) __attribute__ ((__format__ (__printf__, 1, 0)))
;
int vsprintf (char *restrict, const char *restrict, __gnuc_va_list) __attribute__ ((__format__ (__printf__, 2, 0)))
;
int fgetc (FILE *);
char * fgets (char *restrict, int, FILE *restrict);
int fputc (int, FILE *);
int fputs (const char *restrict, FILE *restrict);
int getc (FILE *);
int getchar (void);
char * gets (char *);
int putc (int, FILE *);
int putchar (int);
int puts (const char *);
int ungetc (int, FILE *);
size_t fread (void * restrict, size_t _size, size_t _n, FILE *restrict);
size_t fwrite (const void * restrict , size_t _size, size_t _n, FILE *);
int fgetpos (FILE *restrict, fpos_t *restrict);
int fseek (FILE *, long, int);
int fsetpos (FILE *, const fpos_t *);
long ftell ( FILE *);
void rewind (FILE *);
void clearerr (FILE *);
int feof (FILE *);
int ferror (FILE *);
void perror (const char *);
FILE * fopen (const char *restrict _name, const char *restrict _type);
int sprintf (char *restrict, const char *restrict, ...) __attribute__ ((__format__ (__printf__, 2, 3)))
;
int remove (const char *);
int rename (const char *, const char *);
int fseeko (FILE *, off_t, int);
off_t ftello ( FILE *);
int snprintf (char *restrict, size_t, const char *restrict, ...) __attribute__ ((__format__ (__printf__, 3, 4)))
;
int vsnprintf (char *restrict, size_t, const char *restrict, __gnuc_va_list) __attribute__ ((__format__ (__printf__, 3, 0)))
;
int vfscanf (FILE *restrict, const char *restrict, __gnuc_va_list) __attribute__ ((__format__ (__scanf__, 2, 0)))
;
int vscanf (const char *, __gnuc_va_list) __attribute__ ((__format__ (__scanf__, 1, 0)))
;
int vsscanf (const char *restrict, const char *restrict, __gnuc_va_list) __attribute__ ((__format__ (__scanf__, 2, 0)))
;
int asiprintf (char **, const char *, ...) __attribute__ ((__format__ (__printf__, 2, 3)))
;
char * asniprintf (char *, size_t *, const char *, ...) __attribute__ ((__format__ (__printf__, 3, 4)))
;
char * asnprintf (char *restrict, size_t *restrict, const char *restrict, ...) __attribute__ ((__format__ (__printf__, 3, 4)))
;
int diprintf (int, const char *, ...) __attribute__ ((__format__ (__printf__, 2, 3)))
;
int fiprintf (FILE *, const char *, ...) __attribute__ ((__format__ (__printf__, 2, 3)))
;
int fiscanf (FILE *, const char *, ...) __attribute__ ((__format__ (__scanf__, 2, 3)))
;
int iprintf (const char *, ...) __attribute__ ((__format__ (__printf__, 1, 2)))
;
int iscanf (const char *, ...) __attribute__ ((__format__ (__scanf__, 1, 2)))
;
int siprintf (char *, const char *, ...) __attribute__ ((__format__ (__printf__, 2, 3)))
;
int siscanf (const char *, const char *, ...) __attribute__ ((__format__ (__scanf__, 2, 3)))
;
int sniprintf (char *, size_t, const char *, ...) __attribute__ ((__format__ (__printf__, 3, 4)))
;
int vasiprintf (char **, const char *, __gnuc_va_list) __attribute__ ((__format__ (__printf__, 2, 0)))
;
char * vasniprintf (char *, size_t *, const char *, __gnuc_va_list) __attribute__ ((__format__ (__printf__, 3, 0)))
;
char * vasnprintf (char *, size_t *, const char *, __gnuc_va_list) __attribute__ ((__format__ (__printf__, 3, 0)))
;
int vdiprintf (int, const char *, __gnuc_va_list) __attribute__ ((__format__ (__printf__, 2, 0)))
;
int vfiprintf (FILE *, const char *, __gnuc_va_list) __attribute__ ((__format__ (__printf__, 2, 0)))
;
int vfiscanf (FILE *, const char *, __gnuc_va_list) __attribute__ ((__format__ (__scanf__, 2, 0)))
;
int viprintf (const char *, __gnuc_va_list) __attribute__ ((__format__ (__printf__, 1, 0)))
;
int viscanf (const char *, __gnuc_va_list) __attribute__ ((__format__ (__scanf__, 1, 0)))
;
int vsiprintf (char *, const char *, __gnuc_va_list) __attribute__ ((__format__ (__printf__, 2, 0)))
;
int vsiscanf (const char *, const char *, __gnuc_va_list) __attribute__ ((__format__ (__scanf__, 2, 0)))
;
int vsniprintf (char *, size_t, const char *, __gnuc_va_list) __attribute__ ((__format__ (__printf__, 3, 0)))
;
FILE * fdopen (int, const char *);
int fileno (FILE *);
int pclose (FILE *);
FILE * popen (const char *, const char *);
void setbuffer (FILE *, char *, int);
int setlinebuf (FILE *);
int getw (FILE *);
int putw (int, FILE *);
int getc_unlocked (FILE *);
int getchar_unlocked (void);
void flockfile (FILE *);
int ftrylockfile (FILE *);
void funlockfile (FILE *);
int putc_unlocked (int, FILE *);
int putchar_unlocked (int);
int dprintf (int, const char *restrict, ...) __attribute__ ((__format__ (__printf__, 2, 3)))
;
FILE * fmemopen (void *restrict, size_t, const char *restrict);
FILE * open_memstream (char **, size_t *);
int vdprintf (int, const char *restrict, __gnuc_va_list) __attribute__ ((__format__ (__printf__, 2, 0)))
;
int renameat (int, const char *, int, const char *);
int _asiprintf_r (struct _reent *, char **, const char *, ...) __attribute__ ((__format__ (__printf__, 3, 4)))
;
char * _asniprintf_r (struct _reent *, char *, size_t *, const char *, ...) __attribute__ ((__format__ (__printf__, 4, 5)))
;
char * _asnprintf_r (struct _reent *, char *restrict, size_t *restrict, const char *restrict, ...) __attribute__ ((__format__ (__printf__, 4, 5)))
;
int _asprintf_r (struct _reent *, char **restrict, const char *restrict, ...) __attribute__ ((__format__ (__printf__, 3, 4)))
;
int _diprintf_r (struct _reent *, int, const char *, ...) __attribute__ ((__format__ (__printf__, 3, 4)))
;
int _dprintf_r (struct _reent *, int, const char *restrict, ...) __attribute__ ((__format__ (__printf__, 3, 4)))
;
int _fclose_r (struct _reent *, FILE *);
int _fcloseall_r (struct _reent *);
FILE * _fdopen_r (struct _reent *, int, const char *);
int _fflush_r (struct _reent *, FILE *);
int _fgetc_r (struct _reent *, FILE *);
int _fgetc_unlocked_r (struct _reent *, FILE *);
char * _fgets_r (struct _reent *, char *restrict, int, FILE *restrict);
char * _fgets_unlocked_r (struct _reent *, char *restrict, int, FILE *restrict);
int _fgetpos_r (struct _reent *, FILE *, fpos_t *);
int _fsetpos_r (struct _reent *, FILE *, const fpos_t *);
int _fiprintf_r (struct _reent *, FILE *, const char *, ...) __attribute__ ((__format__ (__printf__, 3, 4)))
;
int _fiscanf_r (struct _reent *, FILE *, const char *, ...) __attribute__ ((__format__ (__scanf__, 3, 4)))
;
FILE * _fmemopen_r (struct _reent *, void *restrict, size_t, const char *restrict);
FILE * _fopen_r (struct _reent *, const char *restrict, const char *restrict);
FILE * _freopen_r (struct _reent *, const char *restrict, const char *restrict, FILE *restrict);
int _fprintf_r (struct _reent *, FILE *restrict, const char *restrict, ...) __attribute__ ((__format__ (__printf__, 3, 4)))
;
int _fpurge_r (struct _reent *, FILE *);
int _fputc_r (struct _reent *, int, FILE *);
int _fputc_unlocked_r (struct _reent *, int, FILE *);
int _fputs_r (struct _reent *, const char *restrict, FILE *restrict);
int _fputs_unlocked_r (struct _reent *, const char *restrict, FILE *restrict);
size_t _fread_r (struct _reent *, void * restrict, size_t _size, size_t _n, FILE *restrict);
size_t _fread_unlocked_r (struct _reent *, void * restrict, size_t _size, size_t _n, FILE *restrict);
int _fscanf_r (struct _reent *, FILE *restrict, const char *restrict, ...) __attribute__ ((__format__ (__scanf__, 3, 4)))
;
int _fseek_r (struct _reent *, FILE *, long, int);
int _fseeko_r (struct _reent *, FILE *, _off_t, int);
long _ftell_r (struct _reent *, FILE *);
_off_t _ftello_r (struct _reent *, FILE *);
void _rewind_r (struct _reent *, FILE *);
size_t _fwrite_r (struct _reent *, const void * restrict, size_t _size, size_t _n, FILE *restrict);
size_t _fwrite_unlocked_r (struct _reent *, const void * restrict, size_t _size, size_t _n, FILE *restrict);
int _getc_r (struct _reent *, FILE *);
int _getc_unlocked_r (struct _reent *, FILE *);
int _getchar_r (struct _reent *);
int _getchar_unlocked_r (struct _reent *);
char * _gets_r (struct _reent *, char *);
int _iprintf_r (struct _reent *, const char *, ...) __attribute__ ((__format__ (__printf__, 2, 3)))
;
int _iscanf_r (struct _reent *, const char *, ...) __attribute__ ((__format__ (__scanf__, 2, 3)))
;
FILE * _open_memstream_r (struct _reent *, char **, size_t *);
void _perror_r (struct _reent *, const char *);
int _printf_r (struct _reent *, const char *restrict, ...) __attribute__ ((__format__ (__printf__, 2, 3)))
;
int _putc_r (struct _reent *, int, FILE *);
int _putc_unlocked_r (struct _reent *, int, FILE *);
int _putchar_unlocked_r (struct _reent *, int);
int _putchar_r (struct _reent *, int);
int _puts_r (struct _reent *, const char *);
int _remove_r (struct _reent *, const char *);
int _rename_r (struct _reent *, const char *_old, const char *_new)
;
int _scanf_r (struct _reent *, const char *restrict, ...) __attribute__ ((__format__ (__scanf__, 2, 3)))
;
int _siprintf_r (struct _reent *, char *, const char *, ...) __attribute__ ((__format__ (__printf__, 3, 4)))
;
int _siscanf_r (struct _reent *, const char *, const char *, ...) __attribute__ ((__format__ (__scanf__, 3, 4)))
;
int _sniprintf_r (struct _reent *, char *, size_t, const char *, ...) __attribute__ ((__format__ (__printf__, 4, 5)))
;
int _snprintf_r (struct _reent *, char *restrict, size_t, const char *restrict, ...) __attribute__ ((__format__ (__printf__, 4, 5)))
;
int _sprintf_r (struct _reent *, char *restrict, const char *restrict, ...) __attribute__ ((__format__ (__printf__, 3, 4)))
;
int _sscanf_r (struct _reent *, const char *restrict, const char *restrict, ...) __attribute__ ((__format__ (__scanf__, 3, 4)))
;
char * _tempnam_r (struct _reent *, const char *, const char *);
FILE * _tmpfile_r (struct _reent *);
char * _tmpnam_r (struct _reent *, char *);
int _ungetc_r (struct _reent *, int, FILE *);
int _vasiprintf_r (struct _reent *, char **, const char *, __gnuc_va_list) __attribute__ ((__format__ (__printf__, 3, 0)))
;
char * _vasniprintf_r (struct _reent*, char *, size_t *, const char *, __gnuc_va_list) __attribute__ ((__format__ (__printf__, 4, 0)))
;
char * _vasnprintf_r (struct _reent*, char *, size_t *, const char *, __gnuc_va_list) __attribute__ ((__format__ (__printf__, 4, 0)))
;
int _vasprintf_r (struct _reent *, char **, const char *, __gnuc_va_list) __attribute__ ((__format__ (__printf__, 3, 0)))
;
int _vdiprintf_r (struct _reent *, int, const char *, __gnuc_va_list) __attribute__ ((__format__ (__printf__, 3, 0)))
;
int _vdprintf_r (struct _reent *, int, const char *restrict, __gnuc_va_list) __attribute__ ((__format__ (__printf__, 3, 0)))
;
int _vfiprintf_r (struct _reent *, FILE *, const char *, __gnuc_va_list) __attribute__ ((__format__ (__printf__, 3, 0)))
;
int _vfiscanf_r (struct _reent *, FILE *, const char *, __gnuc_va_list) __attribute__ ((__format__ (__scanf__, 3, 0)))
;
int _vfprintf_r (struct _reent *, FILE *restrict, const char *restrict, __gnuc_va_list) __attribute__ ((__format__ (__printf__, 3, 0)))
;
int _vfscanf_r (struct _reent *, FILE *restrict, const char *restrict, __gnuc_va_list) __attribute__ ((__format__ (__scanf__, 3, 0)))
;
int _viprintf_r (struct _reent *, const char *, __gnuc_va_list) __attribute__ ((__format__ (__printf__, 2, 0)))
;
int _viscanf_r (struct _reent *, const char *, __gnuc_va_list) __attribute__ ((__format__ (__scanf__, 2, 0)))
;
int _vprintf_r (struct _reent *, const char *restrict, __gnuc_va_list) __attribute__ ((__format__ (__printf__, 2, 0)))
;
int _vscanf_r (struct _reent *, const char *restrict, __gnuc_va_list) __attribute__ ((__format__ (__scanf__, 2, 0)))
;
int _vsiprintf_r (struct _reent *, char *, const char *, __gnuc_va_list) __attribute__ ((__format__ (__printf__, 3, 0)))
;
int _vsiscanf_r (struct _reent *, const char *, const char *, __gnuc_va_list) __attribute__ ((__format__ (__scanf__, 3, 0)))
;
int _vsniprintf_r (struct _reent *, char *, size_t, const char *, __gnuc_va_list) __attribute__ ((__format__ (__printf__, 4, 0)))
;
int _vsnprintf_r (struct _reent *, char *restrict, size_t, const char *restrict, __gnuc_va_list) __attribute__ ((__format__ (__printf__, 4, 0)))
;
int _vsprintf_r (struct _reent *, char *restrict, const char *restrict, __gnuc_va_list) __attribute__ ((__format__ (__printf__, 3, 0)))
;
int _vsscanf_r (struct _reent *, const char *restrict, const char *restrict, __gnuc_va_list) __attribute__ ((__format__ (__scanf__, 3, 0)))
;
int fpurge (FILE *);
ssize_t __getdelim (char **, size_t *, int, FILE *);
ssize_t __getline (char **, size_t *, FILE *);
void clearerr_unlocked (FILE *);
int feof_unlocked (FILE *);
int ferror_unlocked (FILE *);
int fileno_unlocked (FILE *);
int fflush_unlocked (FILE *);
int fgetc_unlocked (FILE *);
int fputc_unlocked (int, FILE *);
size_t fread_unlocked (void * restrict, size_t _size, size_t _n, FILE *restrict);
size_t fwrite_unlocked (const void * restrict , size_t _size, size_t _n, FILE *);
int __srget_r (struct _reent *, FILE *);
int __swbuf_r (struct _reent *, int, FILE *);
FILE *funopen (const void * __cookie, int (*__readfn)(void * __cookie, char *__buf, int __n), int (*__writefn)(void * __cookie, const char *__buf, int __n), fpos_t (*__seekfn)(void * __cookie, fpos_t __off, int __whence), int (*__closefn)(void * __cookie))
;
FILE *_funopen_r (struct _reent *, const void * __cookie, int (*__readfn)(void * __cookie, char *__buf, int __n), int (*__writefn)(void * __cookie, const char *__buf, int __n), fpos_t (*__seekfn)(void * __cookie, fpos_t __off, int __whence), int (*__closefn)(void * __cookie))
;
static __inline__ int __sputc_r(struct _reent *_ptr, int _c, FILE *_p) {
if (--_p->_w >= 0 || (_p->_w >= _p->_lbfsize && (char)_c != '\n'))
return (*_p->_p++ = _c);
else
return (__swbuf_r(_ptr, _c, _p));
}
static inline int is_power_of_two(unsigned int x)
{
return (x != 0) && !(x & (x - 1));
}
static inline s64_t arithmetic_shift_right(s64_t value, u8_t shift)
{
s64_t sign_ext;
if (shift == 0) {
return value;
}
sign_ext = (value >> 63) & 1;
sign_ext = -sign_ext;
return (value >> shift) | (sign_ext << (64 - shift));
}
struct net_buf_simple {
u8_t *data;
u16_t len;
u16_t size;
u8_t __buf[0]
__attribute__((__aligned__(
sizeof(int)
)))
;
};
static inline void net_buf_simple_init(struct net_buf_simple *buf,
size_t reserve_head)
{
buf->data = buf->__buf + reserve_head;
buf->len = 0;
}
void *net_buf_simple_add(struct net_buf_simple *buf, size_t len);
void *net_buf_simple_add_mem(struct net_buf_simple *buf, const void *mem,
size_t len);
u8_t *net_buf_simple_add_u8(struct net_buf_simple *buf, u8_t val);
void net_buf_simple_add_le16(struct net_buf_simple *buf, u16_t val);
void net_buf_simple_add_be16(struct net_buf_simple *buf, u16_t val);
void net_buf_simple_add_le32(struct net_buf_simple *buf, u32_t val);
void net_buf_simple_add_be32(struct net_buf_simple *buf, u32_t val);
void *net_buf_simple_push(struct net_buf_simple *buf, size_t len);
void net_buf_simple_push_le16(struct net_buf_simple *buf, u16_t val);
void net_buf_simple_push_be16(struct net_buf_simple *buf, u16_t val);
void net_buf_simple_push_u8(struct net_buf_simple *buf, u8_t val);
void *net_buf_simple_pull(struct net_buf_simple *buf, size_t len);
u8_t net_buf_simple_pull_u8(struct net_buf_simple *buf);
u16_t net_buf_simple_pull_le16(struct net_buf_simple *buf);
u16_t net_buf_simple_pull_be16(struct net_buf_simple *buf);
u32_t net_buf_simple_pull_le32(struct net_buf_simple *buf);
u32_t net_buf_simple_pull_be32(struct net_buf_simple *buf);
static inline u8_t *net_buf_simple_tail(struct net_buf_simple *buf)
{
return buf->data + buf->len;
}
size_t net_buf_simple_headroom(struct net_buf_simple *buf);
size_t net_buf_simple_tailroom(struct net_buf_simple *buf);
struct net_buf_simple_state {
u16_t offset;
u16_t len;
};
static inline void net_buf_simple_save(struct net_buf_simple *buf,
struct net_buf_simple_state *state)
{
state->offset = net_buf_simple_headroom(buf);
state->len = buf->len;
}
static inline void net_buf_simple_restore(struct net_buf_simple *buf,
struct net_buf_simple_state *state)
{
buf->data = buf->__buf + state->offset;
buf->len = state->len;
}
struct net_buf {
union {
sys_snode_t node;
struct net_buf *frags;
};
u8_t ref;
u8_t flags;
u8_t pool_id;
union {
struct {
u8_t *data;
u16_t len;
u16_t size;
};
struct net_buf_simple b;
};
u8_t __buf[0]
__attribute__((__aligned__(
sizeof(int)
)))
;
};
struct net_buf_pool {
struct k_lifo free;
const u16_t buf_count;
u16_t uninit_count;
const u16_t buf_size;
const u16_t user_data_size;
void (*const destroy)(struct net_buf *buf);
struct net_buf * const __bufs;
};
struct net_buf_pool *net_buf_pool_get(int id);
int net_buf_id(struct net_buf *buf);
struct net_buf *net_buf_alloc(struct net_buf_pool *pool, s32_t timeout);
struct net_buf *net_buf_get(struct k_fifo *fifo, s32_t timeout);
static inline void net_buf_destroy(struct net_buf *buf)
{
struct net_buf_pool *pool = net_buf_pool_get(buf->pool_id);
k_queue_prepend((struct k_queue *) &pool->free, buf);
}
void net_buf_reset(struct net_buf *buf);
void net_buf_reserve(struct net_buf *buf, size_t reserve);
void net_buf_slist_put(sys_slist_t *list, struct net_buf *buf);
struct net_buf *net_buf_slist_get(sys_slist_t *list);
void net_buf_put(struct k_fifo *fifo, struct net_buf *buf);
void net_buf_unref(struct net_buf *buf);
struct net_buf *net_buf_ref(struct net_buf *buf);
struct net_buf *net_buf_clone(struct net_buf *buf, s32_t timeout);
static inline void *net_buf_user_data(struct net_buf *buf)
{
return (void *)(((unsigned long)((buf->__buf + buf->size)) + ((unsigned long)sizeof(int) - 1)) & ~((unsigned long)sizeof(int) - 1));
}
struct net_buf *net_buf_frag_last(struct net_buf *frags);
void net_buf_frag_insert(struct net_buf *parent, struct net_buf *frag);
struct net_buf *net_buf_frag_add(struct net_buf *head, struct net_buf *frag);
struct net_buf *net_buf_frag_del(struct net_buf *parent, struct net_buf *frag);
static inline size_t net_buf_frags_len(struct net_buf *buf)
{
size_t bytes = 0;
while (buf) {
bytes += buf->len;
buf = buf->frags;
}
return bytes;
}
typedef struct {
u8_t val[6];
} bt_addr_t;
typedef struct {
u8_t type;
bt_addr_t a;
} bt_addr_le_t;
static inline int bt_addr_cmp(const bt_addr_t *a, const bt_addr_t *b)
{
return memcmp(a, b, sizeof(*a));
}
static inline int bt_addr_le_cmp(const bt_addr_le_t *a, const bt_addr_le_t *b)
{
return memcmp(a, b, sizeof(*a));
}
static inline void bt_addr_copy(bt_addr_t *dst, const bt_addr_t *src)
{
memcpy(dst, src, sizeof(*dst));
}
static inline void bt_addr_le_copy(bt_addr_le_t *dst, const bt_addr_le_t *src)
{
memcpy(dst, src, sizeof(*dst));
}
int bt_addr_le_create_nrpa(bt_addr_le_t *addr);
int bt_addr_le_create_static(bt_addr_le_t *addr);
static inline
_Bool
bt_addr_le_is_rpa(const bt_addr_le_t *addr)
{
if (addr->type != 0x01) {
return
0
;
}
return (((&addr->a)->val[5] & 0xc0) == 0x40);
}
static inline
_Bool
bt_addr_le_is_identity(const bt_addr_le_t *addr)
{
if (addr->type == 0x00) {
return
1
;
}
return (((&addr->a)->val[5] & 0xc0) == 0xc0);
}
struct bt_hci_evt_hdr {
u8_t evt;
u8_t len;
}
__attribute__((__packed__))
;
struct bt_hci_acl_hdr {
u16_t handle;
u16_t len;
}
__attribute__((__packed__))
;
struct bt_hci_cmd_hdr {
u16_t opcode;
u8_t param_len;
}
__attribute__((__packed__))
;
struct bt_hci_op_inquiry {
u8_t lap[3];
u8_t length;
u8_t num_rsp;
}
__attribute__((__packed__))
;
struct bt_hci_cp_connect {
bt_addr_t bdaddr;
u16_t packet_type;
u8_t pscan_rep_mode;
u8_t reserved;
u16_t clock_offset;
u8_t allow_role_switch;
}
__attribute__((__packed__))
;
struct bt_hci_cp_disconnect {
u16_t handle;
u8_t reason;
}
__attribute__((__packed__))
;
struct bt_hci_cp_connect_cancel {
bt_addr_t bdaddr;
}
__attribute__((__packed__))
;
struct bt_hci_rp_connect_cancel {
u8_t status;
bt_addr_t bdaddr;
}
__attribute__((__packed__))
;
struct bt_hci_cp_accept_conn_req {
bt_addr_t bdaddr;
u8_t role;
}
__attribute__((__packed__))
;
struct bt_hci_cp_setup_sync_conn {
u16_t handle;
u32_t tx_bandwidth;
u32_t rx_bandwidth;
u16_t max_latency;
u16_t content_format;
u8_t retrans_effort;
u16_t pkt_type;
}
__attribute__((__packed__))
;
struct bt_hci_cp_accept_sync_conn_req {
bt_addr_t bdaddr;
u32_t tx_bandwidth;
u32_t rx_bandwidth;
u16_t max_latency;
u16_t content_format;
u8_t retrans_effort;
u16_t pkt_type;
}
__attribute__((__packed__))
;
struct bt_hci_cp_reject_conn_req {
bt_addr_t bdaddr;
u8_t reason;
}
__attribute__((__packed__))
;
struct bt_hci_cp_link_key_reply {
bt_addr_t bdaddr;
u8_t link_key[16];
}
__attribute__((__packed__))
;
struct bt_hci_cp_link_key_neg_reply {
bt_addr_t bdaddr;
}
__attribute__((__packed__))
;
struct bt_hci_cp_pin_code_reply {
bt_addr_t bdaddr;
u8_t pin_len;
u8_t pin_code[16];
}
__attribute__((__packed__))
;
struct bt_hci_rp_pin_code_reply {
u8_t status;
bt_addr_t bdaddr;
}
__attribute__((__packed__))
;
struct bt_hci_cp_pin_code_neg_reply {
bt_addr_t bdaddr;
}
__attribute__((__packed__))
;
struct bt_hci_rp_pin_code_neg_reply {
u8_t status;
bt_addr_t bdaddr;
}
__attribute__((__packed__))
;
struct bt_hci_cp_auth_requested {
u16_t handle;
}
__attribute__((__packed__))
;
struct bt_hci_cp_set_conn_encrypt {
u16_t handle;
u8_t encrypt;
}
__attribute__((__packed__))
;
struct bt_hci_cp_remote_name_request {
bt_addr_t bdaddr;
u8_t pscan_rep_mode;
u8_t reserved;
u16_t clock_offset;
}
__attribute__((__packed__))
;
struct bt_hci_cp_remote_name_cancel {
bt_addr_t bdaddr;
}
__attribute__((__packed__))
;
struct bt_hci_rp_remote_name_cancel {
u8_t status;
bt_addr_t bdaddr;
}
__attribute__((__packed__))
;
struct bt_hci_cp_read_remote_features {
u16_t handle;
}
__attribute__((__packed__))
;
struct bt_hci_cp_read_remote_ext_features {
u16_t handle;
u8_t page;
}
__attribute__((__packed__))
;
struct bt_hci_cp_read_remote_version_info {
u16_t handle;
}
__attribute__((__packed__))
;
struct bt_hci_cp_io_capability_reply {
bt_addr_t bdaddr;
u8_t capability;
u8_t oob_data;
u8_t authentication;
}
__attribute__((__packed__))
;
struct bt_hci_cp_user_confirm_reply {
bt_addr_t bdaddr;
}
__attribute__((__packed__))
;
struct bt_hci_rp_user_confirm_reply {
u8_t status;
bt_addr_t bdaddr;
}
__attribute__((__packed__))
;
struct bt_hci_cp_user_passkey_reply {
bt_addr_t bdaddr;
u32_t passkey;
}
__attribute__((__packed__))
;
struct bt_hci_cp_user_passkey_neg_reply {
bt_addr_t bdaddr;
}
__attribute__((__packed__))
;
struct bt_hci_cp_io_capability_neg_reply {
bt_addr_t bdaddr;
u8_t reason;
}
__attribute__((__packed__))
;
struct bt_hci_cp_set_event_mask {
u8_t events[8];
}
__attribute__((__packed__))
;
struct bt_hci_write_local_name {
u8_t local_name[248];
}
__attribute__((__packed__))
;
struct bt_hci_cp_read_tx_power_level {
u16_t handle;
u8_t type;
}
__attribute__((__packed__))
;
struct bt_hci_rp_read_tx_power_level {
u8_t status;
u16_t handle;
s8_t tx_power_level;
}
__attribute__((__packed__))
;
struct bt_hci_cp_set_ctl_to_host_flow {
u8_t flow_enable;
}
__attribute__((__packed__))
;
struct bt_hci_cp_host_buffer_size {
u16_t acl_mtu;
u8_t sco_mtu;
u16_t acl_pkts;
u16_t sco_pkts;
}
__attribute__((__packed__))
;
struct bt_hci_handle_count {
u16_t handle;
u16_t count;
}
__attribute__((__packed__))
;
struct bt_hci_cp_host_num_completed_packets {
u8_t num_handles;
struct bt_hci_handle_count h[0];
}
__attribute__((__packed__))
;
struct bt_hci_cp_write_inquiry_mode {
u8_t mode;
}
__attribute__((__packed__))
;
struct bt_hci_cp_write_ssp_mode {
u8_t mode;
}
__attribute__((__packed__))
;
struct bt_hci_cp_set_event_mask_page_2 {
u8_t events_page_2[8];
}
__attribute__((__packed__))
;
struct bt_hci_cp_write_le_host_supp {
u8_t le;
u8_t simul;
}
__attribute__((__packed__))
;
struct bt_hci_cp_write_sc_host_supp {
u8_t sc_support;
}
__attribute__((__packed__))
;
struct bt_hci_cp_read_auth_payload_timeout {
u16_t handle;
}
__attribute__((__packed__))
;
struct bt_hci_rp_read_auth_payload_timeout {
u8_t status;
u16_t handle;
u16_t auth_payload_timeout;
}
__attribute__((__packed__))
;
struct bt_hci_cp_write_auth_payload_timeout {
u16_t handle;
u16_t auth_payload_timeout;
}
__attribute__((__packed__))
;
struct bt_hci_rp_write_auth_payload_timeout {
u8_t status;
u16_t handle;
}
__attribute__((__packed__))
;
struct bt_hci_rp_read_local_version_info {
u8_t status;
u8_t hci_version;
u16_t hci_revision;
u8_t lmp_version;
u16_t manufacturer;
u16_t lmp_subversion;
}
__attribute__((__packed__))
;
struct bt_hci_rp_read_supported_commands {
u8_t status;
u8_t commands[64];
}
__attribute__((__packed__))
;
struct bt_hci_cp_read_local_ext_features {
u8_t page;
};
struct bt_hci_rp_read_local_ext_features {
u8_t status;
u8_t page;
u8_t max_page;
u8_t ext_features[8];
}
__attribute__((__packed__))
;
struct bt_hci_rp_read_local_features {
u8_t status;
u8_t features[8];
}
__attribute__((__packed__))
;
struct bt_hci_rp_read_buffer_size {
u8_t status;
u16_t acl_max_len;
u8_t sco_max_len;
u16_t acl_max_num;
u16_t sco_max_num;
}
__attribute__((__packed__))
;
struct bt_hci_rp_read_bd_addr {
u8_t status;
bt_addr_t bdaddr;
}
__attribute__((__packed__))
;
struct bt_hci_cp_read_rssi {
u16_t handle;
}
__attribute__((__packed__))
;
struct bt_hci_rp_read_rssi {
u8_t status;
u16_t handle;
s8_t rssi;
}
__attribute__((__packed__))
;
struct bt_hci_cp_read_encryption_key_size {
u16_t handle;
}
__attribute__((__packed__))
;
struct bt_hci_rp_read_encryption_key_size {
u8_t status;
u16_t handle;
u8_t key_size;
}
__attribute__((__packed__))
;
struct bt_hci_cp_le_set_event_mask {
u8_t events[8];
}
__attribute__((__packed__))
;
struct bt_hci_rp_le_read_buffer_size {
u8_t status;
u16_t le_max_len;
u8_t le_max_num;
}
__attribute__((__packed__))
;
struct bt_hci_rp_le_read_local_features {
u8_t status;
u8_t features[8];
}
__attribute__((__packed__))
;
struct bt_hci_cp_le_set_random_address {
bt_addr_t bdaddr;
}
__attribute__((__packed__))
;
struct bt_hci_cp_le_set_adv_param {
u16_t min_interval;
u16_t max_interval;
u8_t type;
u8_t own_addr_type;
bt_addr_le_t direct_addr;
u8_t channel_map;
u8_t filter_policy;
}
__attribute__((__packed__))
;
struct bt_hci_rp_le_read_chan_tx_power {
u8_t status;
s8_t tx_power_level;
}
__attribute__((__packed__))
;
struct bt_hci_cp_le_set_adv_data {
u8_t len;
u8_t data[31];
}
__attribute__((__packed__))
;
struct bt_hci_cp_le_set_scan_rsp_data {
u8_t len;
u8_t data[31];
}
__attribute__((__packed__))
;
struct bt_hci_cp_le_set_adv_enable {
u8_t enable;
}
__attribute__((__packed__))
;
struct bt_hci_cp_le_set_scan_param {
u8_t scan_type;
u16_t interval;
u16_t window;
u8_t addr_type;
u8_t filter_policy;
}
__attribute__((__packed__))
;
struct bt_hci_cp_le_set_scan_enable {
u8_t enable;
u8_t filter_dup;
}
__attribute__((__packed__))
;
struct bt_hci_cp_le_create_conn {
u16_t scan_interval;
u16_t scan_window;
u8_t filter_policy;
bt_addr_le_t peer_addr;
u8_t own_addr_type;
u16_t conn_interval_min;
u16_t conn_interval_max;
u16_t conn_latency;
u16_t supervision_timeout;
u16_t min_ce_len;
u16_t max_ce_len;
}
__attribute__((__packed__))
;
struct bt_hci_rp_le_read_wl_size {
u8_t status;
u8_t wl_size;
}
__attribute__((__packed__))
;
struct bt_hci_cp_le_add_dev_to_wl {
bt_addr_le_t addr;
}
__attribute__((__packed__))
;
struct bt_hci_cp_le_rem_dev_from_wl {
bt_addr_le_t addr;
}
__attribute__((__packed__))
;
struct hci_cp_le_conn_update {
u16_t handle;
u16_t conn_interval_min;
u16_t conn_interval_max;
u16_t conn_latency;
u16_t supervision_timeout;
u16_t min_ce_len;
u16_t max_ce_len;
}
__attribute__((__packed__))
;
struct bt_hci_cp_le_set_host_chan_classif {
u8_t ch_map[5];
}
__attribute__((__packed__))
;
struct bt_hci_cp_le_read_chan_map {
u16_t handle;
}
__attribute__((__packed__))
;
struct bt_hci_rp_le_read_chan_map {
u8_t status;
u16_t handle;
u8_t ch_map[5];
}
__attribute__((__packed__))
;
struct bt_hci_cp_le_read_remote_features {
u16_t handle;
}
__attribute__((__packed__))
;
struct bt_hci_cp_le_encrypt {
u8_t key[16];
u8_t plaintext[16];
}
__attribute__((__packed__))
;
struct bt_hci_rp_le_encrypt {
u8_t status;
u8_t enc_data[16];
}
__attribute__((__packed__))
;
struct bt_hci_rp_le_rand {
u8_t status;
u8_t rand[8];
}
__attribute__((__packed__))
;
struct bt_hci_cp_le_start_encryption {
u16_t handle;
u64_t rand;
u16_t ediv;
u8_t ltk[16];
}
__attribute__((__packed__))
;
struct bt_hci_cp_le_ltk_req_reply {
u16_t handle;
u8_t ltk[16];
}
__attribute__((__packed__))
;
struct bt_hci_rp_le_ltk_req_reply {
u8_t status;
u16_t handle;
}
__attribute__((__packed__))
;
struct bt_hci_cp_le_ltk_req_neg_reply {
u16_t handle;
}
__attribute__((__packed__))
;
struct bt_hci_rp_le_ltk_req_neg_reply {
u8_t status;
u16_t handle;
}
__attribute__((__packed__))
;
struct bt_hci_rp_le_read_supp_states {
u8_t status;
u8_t le_states[8];
}
__attribute__((__packed__))
;
struct bt_hci_cp_le_rx_test {
u8_t rx_ch;
}
__attribute__((__packed__))
;
struct bt_hci_cp_le_tx_test {
u8_t tx_ch;
u8_t test_data_len;
u8_t pkt_payload;
}
__attribute__((__packed__))
;
struct bt_hci_rp_le_test_end {
u8_t status;
u16_t rx_pkt_count;
}
__attribute__((__packed__))
;
struct bt_hci_cp_le_conn_param_req_reply {
u16_t handle;
u16_t interval_min;
u16_t interval_max;
u16_t latency;
u16_t timeout;
u16_t min_ce_len;
u16_t max_ce_len;
}
__attribute__((__packed__))
;
struct bt_hci_rp_le_conn_param_req_reply {
u8_t status;
u16_t handle;
}
__attribute__((__packed__))
;
struct bt_hci_cp_le_conn_param_req_neg_reply {
u16_t handle;
u8_t reason;
}
__attribute__((__packed__))
;
struct bt_hci_rp_le_conn_param_req_neg_reply {
u8_t status;
u16_t handle;
}
__attribute__((__packed__))
;
struct bt_hci_cp_le_set_data_len {
u16_t handle;
u16_t tx_octets;
u16_t tx_time;
}
__attribute__((__packed__))
;
struct bt_hci_rp_le_set_data_len {
u8_t status;
u16_t handle;
}
__attribute__((__packed__))
;
struct bt_hci_rp_le_read_default_data_len {
u8_t status;
u16_t max_tx_octets;
u16_t max_tx_time;
}
__attribute__((__packed__))
;
struct bt_hci_cp_le_write_default_data_len {
u16_t max_tx_octets;
u16_t max_tx_time;
}
__attribute__((__packed__))
;
struct bt_hci_cp_le_generate_dhkey {
u8_t key[64];
}
__attribute__((__packed__))
;
struct bt_hci_cp_le_add_dev_to_rl {
bt_addr_le_t peer_id_addr;
u8_t peer_irk[16];
u8_t local_irk[16];
}
__attribute__((__packed__))
;
struct bt_hci_cp_le_rem_dev_from_rl {
bt_addr_le_t peer_id_addr;
}
__attribute__((__packed__))
;
struct bt_hci_rp_le_read_rl_size {
u8_t status;
u8_t rl_size;
}
__attribute__((__packed__))
;
struct bt_hci_cp_le_read_peer_rpa {
bt_addr_le_t peer_id_addr;
}
__attribute__((__packed__))
;
struct bt_hci_rp_le_read_peer_rpa {
u8_t status;
bt_addr_t peer_rpa;
}
__attribute__((__packed__))
;
struct bt_hci_cp_le_read_local_rpa {
bt_addr_le_t peer_id_addr;
}
__attribute__((__packed__))
;
struct bt_hci_rp_le_read_local_rpa {
u8_t status;
bt_addr_t local_rpa;
}
__attribute__((__packed__))
;
struct bt_hci_cp_le_set_addr_res_enable {
u8_t enable;
}
__attribute__((__packed__))
;
struct bt_hci_cp_le_set_rpa_timeout {
u16_t rpa_timeout;
}
__attribute__((__packed__))
;
struct bt_hci_rp_le_read_max_data_len {
u8_t status;
u16_t max_tx_octets;
u16_t max_tx_time;
u16_t max_rx_octets;
u16_t max_rx_time;
}
__attribute__((__packed__))
;
struct bt_hci_cp_le_read_phy {
u16_t handle;
}
__attribute__((__packed__))
;
struct bt_hci_rp_le_read_phy {
u8_t status;
u16_t handle;
u8_t tx_phy;
u8_t rx_phy;
}
__attribute__((__packed__))
;
struct bt_hci_cp_le_set_default_phy {
u8_t all_phys;
u8_t tx_phys;
u8_t rx_phys;
}
__attribute__((__packed__))
;
struct bt_hci_cp_le_set_phy {
u16_t handle;
u8_t all_phys;
u8_t tx_phys;
u8_t rx_phys;
u16_t phy_opts;
}
__attribute__((__packed__))
;
struct bt_hci_cp_le_enh_rx_test {
u8_t rx_ch;
u8_t phy;
u8_t mod_index;
}
__attribute__((__packed__))
;
struct bt_hci_cp_le_enh_tx_test {
u8_t tx_ch;
u8_t test_data_len;
u8_t pkt_payload;
u8_t phy;
}
__attribute__((__packed__))
;
struct bt_hci_cp_le_set_adv_set_random_addr {
u8_t handle;
bt_addr_t bdaddr;
}
__attribute__((__packed__))
;
struct bt_hci_cp_le_set_ext_adv_param {
u8_t handle;
u16_t props;
u8_t prim_min_interval[3];
u8_t prim_max_interval[3];
u8_t prim_channel_map;
u8_t own_addr_type;
bt_addr_le_t peer_addr;
u8_t filter_policy;
s8_t tx_power;
u8_t prim_adv_phy;
u8_t sec_adv_max_skip;
u8_t sec_adv_phy;
u8_t sid;
u8_t scan_req_notify_enable;
}
__attribute__((__packed__))
;
struct bt_hci_rp_le_set_ext_adv_param {
u8_t status;
s8_t tx_power;
}
__attribute__((__packed__))
;
struct bt_hci_cp_le_set_ext_adv_data {
u8_t handle;
u8_t op;
u8_t frag_pref;
u8_t len;
u8_t data[251];
}
__attribute__((__packed__))
;
struct bt_hci_cp_le_set_ext_scan_rsp_data {
u8_t handle;
u8_t op;
u8_t frag_pref;
u8_t len;
u8_t data[251];
}
__attribute__((__packed__))
;
struct bt_hci_ext_adv_set {
u8_t handle;
u16_t duration;
u8_t max_ext_adv_evts;
}
__attribute__((__packed__))
;
struct bt_hci_cp_le_set_ext_adv_enable {
u8_t enable;
u8_t set_num;
struct bt_hci_ext_adv_set s[0];
}
__attribute__((__packed__))
;
struct bt_hci_rp_le_read_max_adv_data_len {
u8_t status;
u16_t max_adv_data_len;
}
__attribute__((__packed__))
;
struct bt_hci_rp_le_read_num_adv_sets {
u8_t status;
u8_t num_sets;
}
__attribute__((__packed__))
;
struct bt_hci_cp_le_remove_adv_set {
u8_t handle;
}
__attribute__((__packed__))
;
struct bt_hci_cp_le_set_per_adv_param {
u8_t handle;
u16_t min_interval;
u16_t max_interval;
u16_t props;
}
__attribute__((__packed__))
;
struct bt_hci_cp_le_set_per_adv_data {
u8_t handle;
u8_t op;
u8_t len;
u8_t data[251];
}
__attribute__((__packed__))
;
struct bt_hci_cp_le_set_per_adv_enable {
u8_t enable;
u8_t handle;
}
__attribute__((__packed__))
;
struct bt_hci_ext_scan_phy {
u8_t type;
u16_t interval;
u16_t window;
}
__attribute__((__packed__))
;
struct bt_hci_cp_le_set_ext_scan_param {
u8_t own_addr_type;
u8_t filter_policy;
u8_t phys;
struct bt_hci_ext_scan_phy p[0];
}
__attribute__((__packed__))
;
struct bt_hci_cp_le_set_ext_scan_enable {
u8_t enable;
u8_t filter_dup;
u16_t duration;
u16_t period;
}
__attribute__((__packed__))
;
struct bt_hci_ext_conn_phy {
u16_t interval;
u16_t window;
u16_t conn_interval_min;
u16_t conn_interval_max;
u16_t conn_latency;
u16_t supervision_timeout;
u16_t min_ce_len;
u16_t max_ce_len;
}
__attribute__((__packed__))
;
struct bt_hci_cp_le_ext_create_conn {
u8_t filter_policy;
u8_t own_addr_type;
bt_addr_le_t peer_addr;
u8_t phys;
struct bt_hci_ext_conn_phy p[0];
}
__attribute__((__packed__))
;
struct bt_hci_cp_le_per_adv_create_sync {
u8_t filter_policy;
u8_t sid;
bt_addr_le_t addr;
u16_t skip;
u16_t sync_timeout;
u8_t unused;
}
__attribute__((__packed__))
;
struct bt_hci_cp_le_per_adv_terminate_sync {
u16_t handle;
}
__attribute__((__packed__))
;
struct bt_hci_cp_le_add_dev_to_per_adv_list {
bt_addr_le_t addr;
u8_t sid;
}
__attribute__((__packed__))
;
struct bt_hci_cp_le_rem_dev_from_per_adv_list {
bt_addr_le_t addr;
u8_t sid;
}
__attribute__((__packed__))
;
struct bt_hci_rp_le_read_per_adv_list_size {
u8_t status;
u8_t list_size;
}
__attribute__((__packed__))
;
struct bt_hci_rp_le_read_tx_power {
u8_t status;
s8_t min_tx_power;
s8_t max_tx_power;
}
__attribute__((__packed__))
;
struct bt_hci_rp_le_read_rf_path_comp {
u8_t status;
s16_t tx_path_comp;
s16_t rx_path_comp;
}
__attribute__((__packed__))
;
struct bt_hci_cp_le_write_rf_path_comp {
s16_t tx_path_comp;
s16_t rx_path_comp;
}
__attribute__((__packed__))
;
struct bt_hci_cp_le_set_privacy_mode {
bt_addr_le_t id_addr;
u8_t mode;
}
__attribute__((__packed__))
;
struct bt_hci_evt_inquiry_complete {
u8_t status;
}
__attribute__((__packed__))
;
struct bt_hci_evt_conn_complete {
u8_t status;
u16_t handle;
bt_addr_t bdaddr;
u8_t link_type;
u8_t encr_enabled;
}
__attribute__((__packed__))
;
struct bt_hci_evt_conn_request {
bt_addr_t bdaddr;
u8_t dev_class[3];
u8_t link_type;
}
__attribute__((__packed__))
;
struct bt_hci_evt_disconn_complete {
u8_t status;
u16_t handle;
u8_t reason;
}
__attribute__((__packed__))
;
struct bt_hci_evt_auth_complete {
u8_t status;
u16_t handle;
}
__attribute__((__packed__))
;
struct bt_hci_evt_remote_name_req_complete {
u8_t status;
bt_addr_t bdaddr;
u8_t name[248];
}
__attribute__((__packed__))
;
struct bt_hci_evt_encrypt_change {
u8_t status;
u16_t handle;
u8_t encrypt;
}
__attribute__((__packed__))
;
struct bt_hci_evt_remote_features {
u8_t status;
u16_t handle;
u8_t features[8];
}
__attribute__((__packed__))
;
struct bt_hci_evt_remote_version_info {
u8_t status;
u16_t handle;
u8_t version;
u16_t manufacturer;
u16_t subversion;
}
__attribute__((__packed__))
;
struct bt_hci_evt_cmd_complete {
u8_t ncmd;
u16_t opcode;
}
__attribute__((__packed__))
;
struct bt_hci_evt_cc_status {
u8_t status;
}
__attribute__((__packed__))
;
struct bt_hci_evt_cmd_status {
u8_t status;
u8_t ncmd;
u16_t opcode;
}
__attribute__((__packed__))
;
struct bt_hci_evt_role_change {
u8_t status;
bt_addr_t bdaddr;
u8_t role;
}
__attribute__((__packed__))
;
struct bt_hci_evt_num_completed_packets {
u8_t num_handles;
struct bt_hci_handle_count h[0];
}
__attribute__((__packed__))
;
struct bt_hci_evt_pin_code_req {
bt_addr_t bdaddr;
}
__attribute__((__packed__))
;
struct bt_hci_evt_link_key_req {
bt_addr_t bdaddr;
}
__attribute__((__packed__))
;
struct bt_hci_evt_link_key_notify {
bt_addr_t bdaddr;
u8_t link_key[16];
u8_t key_type;
}
__attribute__((__packed__))
;
struct bt_hci_evt_data_buf_overflow {
u8_t link_type;
}
__attribute__((__packed__))
;
struct bt_hci_evt_inquiry_result_with_rssi {
bt_addr_t addr;
u8_t pscan_rep_mode;
u8_t reserved;
u8_t cod[3];
u16_t clock_offset;
s8_t rssi;
}
__attribute__((__packed__))
;
struct bt_hci_evt_remote_ext_features {
u8_t status;
u16_t handle;
u8_t page;
u8_t max_page;
u8_t features[8];
}
__attribute__((__packed__))
;
struct bt_hci_evt_sync_conn_complete {
u8_t status;
u16_t handle;
bt_addr_t bdaddr;
u8_t link_type;
u8_t tx_interval;
u8_t retansmission_window;
u16_t rx_pkt_length;
u16_t tx_pkt_length;
u8_t air_mode;
}
__attribute__((__packed__))
;
struct bt_hci_evt_extended_inquiry_result {
u8_t num_reports;
bt_addr_t addr;
u8_t pscan_rep_mode;
u8_t reserved;
u8_t cod[3];
u16_t clock_offset;
s8_t rssi;
u8_t eir[240];
}
__attribute__((__packed__))
;
struct bt_hci_evt_encrypt_key_refresh_complete {
u8_t status;
u16_t handle;
}
__attribute__((__packed__))
;
struct bt_hci_evt_io_capa_req {
bt_addr_t bdaddr;
}
__attribute__((__packed__))
;
struct bt_hci_evt_io_capa_resp {
bt_addr_t bdaddr;
u8_t capability;
u8_t oob_data;
u8_t authentication;
}
__attribute__((__packed__))
;
struct bt_hci_evt_user_confirm_req {
bt_addr_t bdaddr;
u32_t passkey;
}
__attribute__((__packed__))
;
struct bt_hci_evt_user_passkey_req {
bt_addr_t bdaddr;
}
__attribute__((__packed__))
;
struct bt_hci_evt_ssp_complete {
u8_t status;
bt_addr_t bdaddr;
}
__attribute__((__packed__))
;
struct bt_hci_evt_user_passkey_notify {
bt_addr_t bdaddr;
u32_t passkey;
}
__attribute__((__packed__))
;
struct bt_hci_evt_le_meta_event {
u8_t subevent;
}
__attribute__((__packed__))
;
struct bt_hci_evt_auth_payload_timeout_exp {
u16_t handle;
}
__attribute__((__packed__))
;
struct bt_hci_evt_le_conn_complete {
u8_t status;
u16_t handle;
u8_t role;
bt_addr_le_t peer_addr;
u16_t interval;
u16_t latency;
u16_t supv_timeout;
u8_t clock_accuracy;
}
__attribute__((__packed__))
;
struct bt_hci_evt_le_advertising_info {
u8_t evt_type;
bt_addr_le_t addr;
u8_t length;
u8_t data[0];
}
__attribute__((__packed__))
;
struct bt_hci_evt_le_advertising_report {
u8_t num_reports;
struct bt_hci_evt_le_advertising_info adv_info[0];
}
__attribute__((__packed__))
;
struct bt_hci_evt_le_conn_update_complete {
u8_t status;
u16_t handle;
u16_t interval;
u16_t latency;
u16_t supv_timeout;
}
__attribute__((__packed__))
;
struct bt_hci_evt_le_remote_feat_complete {
u8_t status;
u16_t handle;
u8_t features[8];
}
__attribute__((__packed__))
;
struct bt_hci_evt_le_ltk_request {
u16_t handle;
u64_t rand;
u16_t ediv;
}
__attribute__((__packed__))
;
struct bt_hci_evt_le_conn_param_req {
u16_t handle;
u16_t interval_min;
u16_t interval_max;
u16_t latency;
u16_t timeout;
}
__attribute__((__packed__))
;
struct bt_hci_evt_le_data_len_change {
u16_t handle;
u16_t max_tx_octets;
u16_t max_tx_time;
u16_t max_rx_octets;
u16_t max_rx_time;
}
__attribute__((__packed__))
;
struct bt_hci_evt_le_p256_public_key_complete {
u8_t status;
u8_t key[64];
}
__attribute__((__packed__))
;
struct bt_hci_evt_le_generate_dhkey_complete {
u8_t status;
u8_t dhkey[32];
}
__attribute__((__packed__))
;
struct bt_hci_evt_le_enh_conn_complete {
u8_t status;
u16_t handle;
u8_t role;
bt_addr_le_t peer_addr;
bt_addr_t local_rpa;
bt_addr_t peer_rpa;
u16_t interval;
u16_t latency;
u16_t supv_timeout;
u8_t clock_accuracy;
}
__attribute__((__packed__))
;
struct bt_hci_evt_le_direct_adv_info {
u8_t evt_type;
bt_addr_le_t addr;
bt_addr_le_t dir_addr;
s8_t rssi;
}
__attribute__((__packed__))
;
struct bt_hci_evt_le_direct_adv_report {
u8_t num_reports;
struct bt_hci_evt_le_direct_adv_info direct_adv_info[0];
}
__attribute__((__packed__))
;
struct bt_hci_evt_le_phy_update_complete {
u8_t status;
u16_t handle;
u8_t tx_phy;
u8_t rx_phy;
}
__attribute__((__packed__))
;
struct bt_hci_evt_le_ext_advertising_info {
u8_t evt_type;
bt_addr_le_t addr;
u8_t prim_phy;
u8_t sec_phy;
u8_t sid;
s8_t tx_power;
s8_t rssi;
u16_t interval;
bt_addr_le_t direct_addr;
u8_t length;
u8_t data[0];
}
__attribute__((__packed__))
;
struct bt_hci_evt_le_ext_advertising_report {
u8_t num_reports;
struct bt_hci_evt_le_ext_advertising_info adv_info[0];
}
__attribute__((__packed__))
;
struct bt_hci_evt_le_per_adv_sync_established {
u8_t status;
u16_t handle;
u8_t sid;
bt_addr_le_t adv_addr;
u8_t phy;
u16_t interval;
u8_t clock_accuracy;
}
__attribute__((__packed__))
;
struct bt_hci_evt_le_per_advertising_report {
u16_t handle;
s8_t tx_power;
s8_t rssi;
u8_t unused;
u8_t data_status;
u8_t length;
u8_t data[0];
}
__attribute__((__packed__))
;
struct bt_hci_evt_le_per_adv_sync_lost {
u16_t handle;
}
__attribute__((__packed__))
;
struct bt_hci_evt_le_per_adv_set_terminated {
u8_t status;
u8_t adv_handle;
u16_t conn_handle;
u8_t num_completed_ext_adv_evts;
}
__attribute__((__packed__))
;
struct bt_hci_evt_le_scan_req_received {
u8_t handle;
bt_addr_le_t addr;
}
__attribute__((__packed__))
;
struct bt_hci_evt_le_chan_sel_algo {
u16_t handle;
u8_t chan_sel_algo;
}
__attribute__((__packed__))
;
int bt_rand(void *buf, size_t len);
int bt_encrypt_le(const u8_t key[16], const u8_t plaintext[16],
u8_t enc_data[16]);
int bt_encrypt_be(const u8_t key[16], const u8_t plaintext[16],
u8_t enc_data[16]);
typedef void (*bt_ready_cb_t)(int err);
int bt_enable(bt_ready_cb_t cb);
struct bt_data {
u8_t type;
u8_t data_len;
const u8_t *data;
};
enum {
BT_LE_ADV_OPT_NONE = 0,
BT_LE_ADV_OPT_CONNECTABLE = (1UL << (0)),
BT_LE_ADV_OPT_ONE_TIME = (1UL << (1)),
};
struct bt_le_adv_param {
u8_t options;
u16_t interval_min;
u16_t interval_max;
const bt_addr_t *own_addr;
};
int bt_le_adv_start(const struct bt_le_adv_param *param,
const struct bt_data *ad, size_t ad_len,
const struct bt_data *sd, size_t sd_len);
int bt_le_adv_stop(void);
typedef void bt_le_scan_cb_t(const bt_addr_le_t *addr, s8_t rssi,
u8_t adv_type, struct net_buf_simple *buf);
struct bt_le_scan_param {
u8_t type;
u8_t filter_dup;
u16_t interval;
u16_t window;
};
int bt_le_scan_start(const struct bt_le_scan_param *param, bt_le_scan_cb_t cb);
int bt_le_scan_stop(void);
struct bt_le_oob {
bt_addr_le_t addr;
};
int bt_le_oob_get_local(struct bt_le_oob *oob);
struct bt_br_discovery_result {
u8_t _priv[4];
bt_addr_t addr;
s8_t rssi;
u8_t cod[3];
u8_t eir[240];
};
typedef void bt_br_discovery_cb_t(struct bt_br_discovery_result *results,
size_t count);
struct bt_br_discovery_param {
u8_t length;
_Bool
limited;
};
int bt_br_discovery_start(const struct bt_br_discovery_param *param,
struct bt_br_discovery_result *results, size_t count,
bt_br_discovery_cb_t cb);
int bt_br_discovery_stop(void);
struct bt_br_oob {
bt_addr_t addr;
};
int bt_br_oob_get_local(struct bt_br_oob *oob);
static inline int bt_addr_to_str(const bt_addr_t *addr, char *str, size_t len)
{
return snprintf(str, len, "%02X:%02X:%02X:%02X:%02X:%02X",
addr->val[5], addr->val[4], addr->val[3],
addr->val[2], addr->val[1], addr->val[0]);
}
static inline int bt_addr_le_to_str(const bt_addr_le_t *addr, char *str,
size_t len)
{
char type[10];
switch (addr->type) {
case 0x00:
strcpy(type, "public");
break;
case 0x01:
strcpy(type, "random");
break;
case 0x02:
strcpy(type, "public id");
break;
case 0x03:
strcpy(type, "random id");
break;
default:
snprintf(type, sizeof(type), "0x%02x", addr->type);
break;
}
return snprintf(str, len, "%02X:%02X:%02X:%02X:%02X:%02X (%s)",
addr->a.val[5], addr->a.val[4], addr->a.val[3],
addr->a.val[2], addr->a.val[1], addr->a.val[0], type);
}
int bt_br_set_discoverable(
_Bool
enable);
int bt_br_set_connectable(
_Bool
enable);
const char *bt_hex(const void *buf, size_t len);
const char *bt_addr_str(const bt_addr_t *addr);
const char *bt_addr_le_str(const bt_addr_le_t *addr);
extern int *__errno(void);
static struct k_thread work_q_thread;
static _stack_element_t work_q_stack[(512) + 0];
static struct k_work_q g_work_queue_main;
static void k_work_submit_to_queue(struct k_work_q *work_q,
struct k_work *work)
{
if (!atomic_test_and_set_bit(work->flags, K_WORK_STATE_PENDING)) {
k_queue_append((struct k_queue *) &work_q->fifo, work);
}
}
static void work_queue_thread(void *p1, void *p2, void *p3)
{
struct k_work *work;
(void)p1;
while (1) {
work = k_queue_get((struct k_queue *) &g_work_queue_main.fifo, -1);
if (atomic_test_and_clear_bit(work->flags, K_WORK_STATE_PENDING)) {
work->handler(work);
}
k_yield();
}
}
int k_work_q_start(void)
{
k_queue_init((struct k_queue *) &g_work_queue_main.fifo);
return k_thread_create(&work_q_thread, work_q_stack,
sizeof(work_q_stack),
work_queue_thread,
((void *)0)
,
((void *)0)
,
((void *)0)
, 41, 0, 0);
}
int k_work_init(struct k_work *work, k_work_handler_t handler)
{
;
atomic_clear_bit(work->flags, K_WORK_STATE_PENDING);
work->handler = handler;
return 0;
}
void k_work_submit(struct k_work *work)
{
k_work_submit_to_queue(&g_work_queue_main, work);
}
static void work_timeout(void *timer, void *args)
{
struct k_delayed_work *w = (struct k_delayed_work *)args;
k_timer_stop(&w->timer);
k_work_submit_to_queue(w->work_q, &w->work);
w->work_q =
((void *)0)
;
}
void k_delayed_work_init(struct k_delayed_work *work, k_work_handler_t handler)
{
;
k_work_init(&work->work, handler);
k_timer_init(&work->timer, work_timeout, work);
work->work_q =
((void *)0)
;
}
static int k_delayed_work_submit_to_queue(struct k_work_q *work_q,
struct k_delayed_work *work,
uint32_t delay)
{
int key = irq_lock();
int err;
if (work->work_q && work->work_q != work_q) {
err = -48;
goto done;
}
if (work->work_q == work_q) {
err = k_delayed_work_cancel(work);
if (err < 0) {
goto done;
}
}
work->work_q = work_q;
if (!delay) {
k_work_submit_to_queue(work_q, &work->work);
work->work_q =
((void *)0)
;
} else {
k_timer_start(&work->timer, delay);
}
err = 0;
done:
irq_unlock(key);
return err;
}
int k_delayed_work_submit(struct k_delayed_work *work, uint32_t delay)
{
return k_delayed_work_submit_to_queue(&g_work_queue_main, work, delay);
}
int k_delayed_work_cancel(struct k_delayed_work *work)
{
int err = 0;
int key = irq_lock();
if (atomic_test_bit(work->work.flags, K_WORK_STATE_PENDING)) {
err = -68;
goto exit;
}
if (!work->work_q) {
err = -22;
goto exit;
}
k_timer_stop(&work->timer);
work->work_q =
((void *)0)
;
exit:
irq_unlock(key);
return err;
}
s32_t k_delayed_work_remaining_get(struct k_delayed_work *work)
{
int32_t remain;
k_timer_t *timer;
if (work ==
((void *)0)
) {
return 0;
}
timer = &work->timer;
remain = timer->timeout - (aos_now_ms() - timer->start_ms);
if (remain < 0) {
remain = 0;
}
return remain;
}
|
the_stack_data/220454675.c | extern int __mark(int);
int f(int n) {
int x = 0;
for (int i = 0; __mark(0) & (i < n); ++i) {
++x;
}
for (int i = 0; __mark(1) & (i < n); ++i) {
++x;
}
for (int i = 0; __mark(2) & (i < n); ++i) {
++x;
}
for (int i = 0; __mark(3) & (i < n); ++i) {
++x;
}
for (int i = 0; __mark(4) & (i < n); ++i) {
++x;
}
for (int i = 0; __mark(5) & (i < n); ++i) {
++x;
}
for (int i = 0; __mark(6) & (i < n); ++i) {
++x;
}
for (int i = 0; __mark(7) & (i < n); ++i) {
++x;
}
for (int i = 0; __mark(8) & (i < n); ++i) {
++x;
}
return x;
}
|
the_stack_data/432672.c | /**
* $Id$
* a part of mod_websocket
*/
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <errno.h>
int
mod_websocket_tcp_server_connect(const char *host, const char *service) {
struct addrinfo hints;
struct addrinfo *res = NULL;
struct addrinfo *ai = NULL;
struct fdlist {
int fd;
struct fdlist *next;
};
struct fdlist *head = NULL, *p, *pn, *fde = NULL;
int flags, fd, maxfd = -1, connfd = -1, sockret = -1;
socklen_t socklen = sizeof(sockret);
fd_set fds;
struct timeval tv;
memset(&hints, 0, sizeof(hints));
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
hints.ai_flags = 0;
if (getaddrinfo(host, service, &hints, &res) != 0) {
return -1;
}
FD_ZERO(&fds);
for (ai = res; ai; ai = ai->ai_next) {
fd = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
if (fd < 0) {
goto go_out;
}
if ((flags = fcntl(fd, F_GETFL, 0)) < 0 ||
fcntl(fd, F_SETFL, flags | O_NONBLOCK) < 0) {
close(fd);
goto go_out;
}
fde = (struct fdlist *)malloc(sizeof(struct fdlist));
if (!fde) {
close(fd);
goto go_out;
}
fde->fd = fd;
fde->next = head;
head = fde;
if (fde->fd > maxfd) {
maxfd = fde->fd;
}
FD_SET(fde->fd, &fds);
if (connect(fde->fd, ai->ai_addr, ai->ai_addrlen) < 0) {
if (errno != EINPROGRESS) {
goto go_out;
}
}
}
/* connect timeout is to set 5 secs */
tv.tv_sec = 5;
tv.tv_usec = 0;
if (select(maxfd + 1, NULL, &fds, NULL, &tv) == 0) {
goto go_out;
} else {
for (p = head; p; p = p->next) {
if (!FD_ISSET(p->fd, &fds)) {
continue;
}
if (getsockopt(p->fd, SOL_SOCKET, SO_ERROR,
&sockret, &socklen) == 0 &&
sockret == 0) {
connfd = p->fd;
break;
}
}
}
go_out:
p = head;
while (p) {
if (p->fd != connfd) {
close(p->fd);
}
pn = p->next;
free(p);
p = pn;
}
freeaddrinfo(res);
return connfd;
}
void
mod_websocket_tcp_server_disconnect(int sockfd) {
close(sockfd);
return;
}
/* EOF */
|
the_stack_data/94054.c |
#define DOT11_RATE_SET_MAX_LENGTH 126 // 126 bytes
typedef unsigned long ULONG;
typedef unsigned char UCHAR;
typedef struct _DOT11_RATE_SET {
ULONG uRateSetLength;
/*__field_ecount_part(DOT11_RATE_SET_MAX_LENGTH, uRateSetLength) */
UCHAR ucRateSet[DOT11_RATE_SET_MAX_LENGTH];
} DOT11_RATE_SET, * PDOT11_RATE_SET;
int main(void)
{
ULONG i,j;
DOT11_RATE_SET rateSet;
DOT11_RATE_SET APRateSet;
ULONG rateSet_uRateSetLength=rateSet.uRateSetLength;
ULONG APRateSet_uRateSetLength=APRateSet.uRateSetLength;
i = 0;
while (i < rateSet_uRateSetLength)
{
for (j = 0; j < APRateSet_uRateSetLength; j++)
{
if (nondet())
break;
}
//
// remove the rate if it is not in AP's rate set
//
if (j == APRateSet_uRateSetLength)
{
rateSet_uRateSetLength--;
;
}
else
{
i++;
}
}
return 0;
}
|
the_stack_data/415134.c | /* Example: matrices represented by 2-dimensional arrays */
#include <stdio.h>
#define MATRIX_SIZE 3
void print_matrix(char label[], int matrix[][MATRIX_SIZE]) {
int i, j;
printf("%s\n", label);
for (i = 0; i < MATRIX_SIZE; i++) {
for (j = 0; j < MATRIX_SIZE; j++) {
printf("%3s%3i", "", matrix[i][j]);
}
printf("\n");
}
}
void read_matrix(int matrix[][MATRIX_SIZE]) {
int i, j;
for (i = 0; i < MATRIX_SIZE; i++) {
for (j = 0; j < MATRIX_SIZE; j++) {
scanf("%d", &matrix[i][j]);
}
}
}
main()
{
int A[MATRIX_SIZE][MATRIX_SIZE];
printf("Please enter the values for A[0..2][0..2], one row per line:\n");
read_matrix(A);
int B[MATRIX_SIZE][MATRIX_SIZE];
printf("Please enter the values for B[0..2][0..2], one row per line:\n");
read_matrix(B);
int C[MATRIX_SIZE][MATRIX_SIZE];
int i, j, k;
print_matrix("A=", A);
print_matrix("B=", B);
/* multiply C = A.B: */
for (i = 0; i < 3; i++)
for (j = 0; j < 3; j++)
{
C[i][j] = 0;
for (k =0; k < 3; k++)
C[i][j] += A[i][k] * B[k][j];
}
print_matrix("C=A.B=", C);
/* multiply C = B.A: */
for (i = 0; i < 3; i++)
for (j = 0; j < 3; j++)
{
C[i][j] = 0;
for (k =0; k < 3; k++)
C[i][j] += B[i][k] * A[k][j];
}
print_matrix("C=B.A=", C);
}
|
the_stack_data/26700537.c | #include <stdio.h>
void tower_of_hanoi(int n, char beg, char end, char aux){
if (n==1){
printf("Move the rod %c to %c\n", beg, end);
return;
}
tower_of_hanoi(n-1, beg, aux, end);
printf("Move the rod %c to %c\n", beg, end);
tower_of_hanoi(n-1, aux, beg, end);
}
int main(){
int n;
printf("\nEnter the number of disk:");
scanf("%d", &n);
tower_of_hanoi(n, 'A', 'C', 'B');
}
|
the_stack_data/117329044.c | #include <math.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <complex.h>
#ifdef complex
#undef complex
#endif
#ifdef I
#undef I
#endif
#if defined(_WIN64)
typedef long long BLASLONG;
typedef unsigned long long BLASULONG;
#else
typedef long BLASLONG;
typedef unsigned long BLASULONG;
#endif
#ifdef LAPACK_ILP64
typedef BLASLONG blasint;
#if defined(_WIN64)
#define blasabs(x) llabs(x)
#else
#define blasabs(x) labs(x)
#endif
#else
typedef int blasint;
#define blasabs(x) abs(x)
#endif
typedef blasint integer;
typedef unsigned int uinteger;
typedef char *address;
typedef short int shortint;
typedef float real;
typedef double doublereal;
typedef struct { real r, i; } complex;
typedef struct { doublereal r, i; } doublecomplex;
#ifdef _MSC_VER
static inline _Fcomplex Cf(complex *z) {_Fcomplex zz={z->r , z->i}; return zz;}
static inline _Dcomplex Cd(doublecomplex *z) {_Dcomplex zz={z->r , z->i};return zz;}
static inline _Fcomplex * _pCf(complex *z) {return (_Fcomplex*)z;}
static inline _Dcomplex * _pCd(doublecomplex *z) {return (_Dcomplex*)z;}
#else
static inline _Complex float Cf(complex *z) {return z->r + z->i*_Complex_I;}
static inline _Complex double Cd(doublecomplex *z) {return z->r + z->i*_Complex_I;}
static inline _Complex float * _pCf(complex *z) {return (_Complex float*)z;}
static inline _Complex double * _pCd(doublecomplex *z) {return (_Complex double*)z;}
#endif
#define pCf(z) (*_pCf(z))
#define pCd(z) (*_pCd(z))
typedef int logical;
typedef short int shortlogical;
typedef char logical1;
typedef char integer1;
#define TRUE_ (1)
#define FALSE_ (0)
/* Extern is for use with -E */
#ifndef Extern
#define Extern extern
#endif
/* I/O stuff */
typedef int flag;
typedef int ftnlen;
typedef int ftnint;
/*external read, write*/
typedef struct
{ flag cierr;
ftnint ciunit;
flag ciend;
char *cifmt;
ftnint cirec;
} cilist;
/*internal read, write*/
typedef struct
{ flag icierr;
char *iciunit;
flag iciend;
char *icifmt;
ftnint icirlen;
ftnint icirnum;
} icilist;
/*open*/
typedef struct
{ flag oerr;
ftnint ounit;
char *ofnm;
ftnlen ofnmlen;
char *osta;
char *oacc;
char *ofm;
ftnint orl;
char *oblnk;
} olist;
/*close*/
typedef struct
{ flag cerr;
ftnint cunit;
char *csta;
} cllist;
/*rewind, backspace, endfile*/
typedef struct
{ flag aerr;
ftnint aunit;
} alist;
/* inquire */
typedef struct
{ flag inerr;
ftnint inunit;
char *infile;
ftnlen infilen;
ftnint *inex; /*parameters in standard's order*/
ftnint *inopen;
ftnint *innum;
ftnint *innamed;
char *inname;
ftnlen innamlen;
char *inacc;
ftnlen inacclen;
char *inseq;
ftnlen inseqlen;
char *indir;
ftnlen indirlen;
char *infmt;
ftnlen infmtlen;
char *inform;
ftnint informlen;
char *inunf;
ftnlen inunflen;
ftnint *inrecl;
ftnint *innrec;
char *inblank;
ftnlen inblanklen;
} inlist;
#define VOID void
union Multitype { /* for multiple entry points */
integer1 g;
shortint h;
integer i;
/* longint j; */
real r;
doublereal d;
complex c;
doublecomplex z;
};
typedef union Multitype Multitype;
struct Vardesc { /* for Namelist */
char *name;
char *addr;
ftnlen *dims;
int type;
};
typedef struct Vardesc Vardesc;
struct Namelist {
char *name;
Vardesc **vars;
int nvars;
};
typedef struct Namelist Namelist;
#define abs(x) ((x) >= 0 ? (x) : -(x))
#define dabs(x) (fabs(x))
#define f2cmin(a,b) ((a) <= (b) ? (a) : (b))
#define f2cmax(a,b) ((a) >= (b) ? (a) : (b))
#define dmin(a,b) (f2cmin(a,b))
#define dmax(a,b) (f2cmax(a,b))
#define bit_test(a,b) ((a) >> (b) & 1)
#define bit_clear(a,b) ((a) & ~((uinteger)1 << (b)))
#define bit_set(a,b) ((a) | ((uinteger)1 << (b)))
#define abort_() { sig_die("Fortran abort routine called", 1); }
#define c_abs(z) (cabsf(Cf(z)))
#define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); }
#ifdef _MSC_VER
#define c_div(c, a, b) {Cf(c)._Val[0] = (Cf(a)._Val[0]/Cf(b)._Val[0]); Cf(c)._Val[1]=(Cf(a)._Val[1]/Cf(b)._Val[1]);}
#define z_div(c, a, b) {Cd(c)._Val[0] = (Cd(a)._Val[0]/Cd(b)._Val[0]); Cd(c)._Val[1]=(Cd(a)._Val[1]/df(b)._Val[1]);}
#else
#define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);}
#define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);}
#endif
#define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));}
#define c_log(R, Z) {pCf(R) = clogf(Cf(Z));}
#define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));}
//#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));}
#define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));}
#define d_abs(x) (fabs(*(x)))
#define d_acos(x) (acos(*(x)))
#define d_asin(x) (asin(*(x)))
#define d_atan(x) (atan(*(x)))
#define d_atn2(x, y) (atan2(*(x),*(y)))
#define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); }
#define r_cnjg(R, Z) { pCf(R) = conjf(Cf(Z)); }
#define d_cos(x) (cos(*(x)))
#define d_cosh(x) (cosh(*(x)))
#define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 )
#define d_exp(x) (exp(*(x)))
#define d_imag(z) (cimag(Cd(z)))
#define r_imag(z) (cimagf(Cf(z)))
#define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
#define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
#define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
#define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
#define d_log(x) (log(*(x)))
#define d_mod(x, y) (fmod(*(x), *(y)))
#define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x)))
#define d_nint(x) u_nint(*(x))
#define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a)))
#define d_sign(a,b) u_sign(*(a),*(b))
#define r_sign(a,b) u_sign(*(a),*(b))
#define d_sin(x) (sin(*(x)))
#define d_sinh(x) (sinh(*(x)))
#define d_sqrt(x) (sqrt(*(x)))
#define d_tan(x) (tan(*(x)))
#define d_tanh(x) (tanh(*(x)))
#define i_abs(x) abs(*(x))
#define i_dnnt(x) ((integer)u_nint(*(x)))
#define i_len(s, n) (n)
#define i_nint(x) ((integer)u_nint(*(x)))
#define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b)))
#define pow_dd(ap, bp) ( pow(*(ap), *(bp)))
#define pow_si(B,E) spow_ui(*(B),*(E))
#define pow_ri(B,E) spow_ui(*(B),*(E))
#define pow_di(B,E) dpow_ui(*(B),*(E))
#define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));}
#define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));}
#define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));}
#define s_cat(lpp, rpp, rnp, np, llp) { ftnlen i, nc, ll; char *f__rp, *lp; ll = (llp); lp = (lpp); for(i=0; i < (int)*(np); ++i) { nc = ll; if((rnp)[i] < nc) nc = (rnp)[i]; ll -= nc; f__rp = (rpp)[i]; while(--nc >= 0) *lp++ = *(f__rp)++; } while(--ll >= 0) *lp++ = ' '; }
#define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d))))
#define s_copy(A,B,C,D) { int __i,__m; for (__i=0, __m=f2cmin((C),(D)); __i<__m && (B)[__i] != 0; ++__i) (A)[__i] = (B)[__i]; }
#define sig_die(s, kill) { exit(1); }
#define s_stop(s, n) {exit(0);}
static char junk[] = "\n@(#)LIBF77 VERSION 19990503\n";
#define z_abs(z) (cabs(Cd(z)))
#define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));}
#define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
#define myexit_() break;
#define mycycle() continue;
#define myceiling(w) {ceil(w)}
#define myhuge(w) {HUGE_VAL}
//#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
#define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)}
/* procedure parameter types for -A and -C++ */
#define F2C_proc_par_types 1
#ifdef __cplusplus
typedef logical (*L_fp)(...);
#else
typedef logical (*L_fp)();
#endif
static float spow_ui(float x, integer n) {
float pow=1.0; unsigned long int u;
if(n != 0) {
if(n < 0) n = -n, x = 1/x;
for(u = n; ; ) {
if(u & 01) pow *= x;
if(u >>= 1) x *= x;
else break;
}
}
return pow;
}
static double dpow_ui(double x, integer n) {
double pow=1.0; unsigned long int u;
if(n != 0) {
if(n < 0) n = -n, x = 1/x;
for(u = n; ; ) {
if(u & 01) pow *= x;
if(u >>= 1) x *= x;
else break;
}
}
return pow;
}
#ifdef _MSC_VER
static _Fcomplex cpow_ui(complex x, integer n) {
complex pow={1.0,0.0}; unsigned long int u;
if(n != 0) {
if(n < 0) n = -n, x.r = 1/x.r, x.i=1/x.i;
for(u = n; ; ) {
if(u & 01) pow.r *= x.r, pow.i *= x.i;
if(u >>= 1) x.r *= x.r, x.i *= x.i;
else break;
}
}
_Fcomplex p={pow.r, pow.i};
return p;
}
#else
static _Complex float cpow_ui(_Complex float x, integer n) {
_Complex float pow=1.0; unsigned long int u;
if(n != 0) {
if(n < 0) n = -n, x = 1/x;
for(u = n; ; ) {
if(u & 01) pow *= x;
if(u >>= 1) x *= x;
else break;
}
}
return pow;
}
#endif
#ifdef _MSC_VER
static _Dcomplex zpow_ui(_Dcomplex x, integer n) {
_Dcomplex pow={1.0,0.0}; unsigned long int u;
if(n != 0) {
if(n < 0) n = -n, x._Val[0] = 1/x._Val[0], x._Val[1] =1/x._Val[1];
for(u = n; ; ) {
if(u & 01) pow._Val[0] *= x._Val[0], pow._Val[1] *= x._Val[1];
if(u >>= 1) x._Val[0] *= x._Val[0], x._Val[1] *= x._Val[1];
else break;
}
}
_Dcomplex p = {pow._Val[0], pow._Val[1]};
return p;
}
#else
static _Complex double zpow_ui(_Complex double x, integer n) {
_Complex double pow=1.0; unsigned long int u;
if(n != 0) {
if(n < 0) n = -n, x = 1/x;
for(u = n; ; ) {
if(u & 01) pow *= x;
if(u >>= 1) x *= x;
else break;
}
}
return pow;
}
#endif
static integer pow_ii(integer x, integer n) {
integer pow; unsigned long int u;
if (n <= 0) {
if (n == 0 || x == 1) pow = 1;
else if (x != -1) pow = x == 0 ? 1/x : 0;
else n = -n;
}
if ((n > 0) || !(n == 0 || x == 1 || x != -1)) {
u = n;
for(pow = 1; ; ) {
if(u & 01) pow *= x;
if(u >>= 1) x *= x;
else break;
}
}
return pow;
}
static integer dmaxloc_(double *w, integer s, integer e, integer *n)
{
double m; integer i, mi;
for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
if (w[i-1]>m) mi=i ,m=w[i-1];
return mi-s+1;
}
static integer smaxloc_(float *w, integer s, integer e, integer *n)
{
float m; integer i, mi;
for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
if (w[i-1]>m) mi=i ,m=w[i-1];
return mi-s+1;
}
static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
integer n = *n_, incx = *incx_, incy = *incy_, i;
#ifdef _MSC_VER
_Fcomplex zdotc = {0.0, 0.0};
if (incx == 1 && incy == 1) {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc._Val[0] += conjf(Cf(&x[i]))._Val[0] * Cf(&y[i])._Val[0];
zdotc._Val[1] += conjf(Cf(&x[i]))._Val[1] * Cf(&y[i])._Val[1];
}
} else {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc._Val[0] += conjf(Cf(&x[i*incx]))._Val[0] * Cf(&y[i*incy])._Val[0];
zdotc._Val[1] += conjf(Cf(&x[i*incx]))._Val[1] * Cf(&y[i*incy])._Val[1];
}
}
pCf(z) = zdotc;
}
#else
_Complex float zdotc = 0.0;
if (incx == 1 && incy == 1) {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += conjf(Cf(&x[i])) * Cf(&y[i]);
}
} else {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]);
}
}
pCf(z) = zdotc;
}
#endif
static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
integer n = *n_, incx = *incx_, incy = *incy_, i;
#ifdef _MSC_VER
_Dcomplex zdotc = {0.0, 0.0};
if (incx == 1 && incy == 1) {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc._Val[0] += conj(Cd(&x[i]))._Val[0] * Cd(&y[i])._Val[0];
zdotc._Val[1] += conj(Cd(&x[i]))._Val[1] * Cd(&y[i])._Val[1];
}
} else {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc._Val[0] += conj(Cd(&x[i*incx]))._Val[0] * Cd(&y[i*incy])._Val[0];
zdotc._Val[1] += conj(Cd(&x[i*incx]))._Val[1] * Cd(&y[i*incy])._Val[1];
}
}
pCd(z) = zdotc;
}
#else
_Complex double zdotc = 0.0;
if (incx == 1 && incy == 1) {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += conj(Cd(&x[i])) * Cd(&y[i]);
}
} else {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]);
}
}
pCd(z) = zdotc;
}
#endif
static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
integer n = *n_, incx = *incx_, incy = *incy_, i;
#ifdef _MSC_VER
_Fcomplex zdotc = {0.0, 0.0};
if (incx == 1 && incy == 1) {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc._Val[0] += Cf(&x[i])._Val[0] * Cf(&y[i])._Val[0];
zdotc._Val[1] += Cf(&x[i])._Val[1] * Cf(&y[i])._Val[1];
}
} else {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc._Val[0] += Cf(&x[i*incx])._Val[0] * Cf(&y[i*incy])._Val[0];
zdotc._Val[1] += Cf(&x[i*incx])._Val[1] * Cf(&y[i*incy])._Val[1];
}
}
pCf(z) = zdotc;
}
#else
_Complex float zdotc = 0.0;
if (incx == 1 && incy == 1) {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += Cf(&x[i]) * Cf(&y[i]);
}
} else {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]);
}
}
pCf(z) = zdotc;
}
#endif
static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
integer n = *n_, incx = *incx_, incy = *incy_, i;
#ifdef _MSC_VER
_Dcomplex zdotc = {0.0, 0.0};
if (incx == 1 && incy == 1) {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc._Val[0] += Cd(&x[i])._Val[0] * Cd(&y[i])._Val[0];
zdotc._Val[1] += Cd(&x[i])._Val[1] * Cd(&y[i])._Val[1];
}
} else {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc._Val[0] += Cd(&x[i*incx])._Val[0] * Cd(&y[i*incy])._Val[0];
zdotc._Val[1] += Cd(&x[i*incx])._Val[1] * Cd(&y[i*incy])._Val[1];
}
}
pCd(z) = zdotc;
}
#else
_Complex double zdotc = 0.0;
if (incx == 1 && incy == 1) {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += Cd(&x[i]) * Cd(&y[i]);
}
} else {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]);
}
}
pCd(z) = zdotc;
}
#endif
/* -- translated by f2c (version 20000121).
You must link the resulting object file with the libraries:
-lf2c -lm (in that order)
*/
/* Table of constant values */
static complex c_b1 = {0.f,0.f};
static complex c_b2 = {1.f,0.f};
static integer c__4 = 4;
static integer c_n1 = -1;
static integer c__1 = 1;
static real c_b33 = 1.f;
/* > \brief \b CHETRD_HE2HB */
/* @generated from zhetrd_he2hb.f, fortran z -> c, Wed Dec 7 08:22:40 2016 */
/* =========== DOCUMENTATION =========== */
/* Online html documentation available at */
/* http://www.netlib.org/lapack/explore-html/ */
/* > \htmlonly */
/* > Download CHETRD_HE2HB + dependencies */
/* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/chetrd.
f"> */
/* > [TGZ]</a> */
/* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/chetrd.
f"> */
/* > [ZIP]</a> */
/* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/chetrd.
f"> */
/* > [TXT]</a> */
/* > \endhtmlonly */
/* Definition: */
/* =========== */
/* SUBROUTINE CHETRD_HE2HB( UPLO, N, KD, A, LDA, AB, LDAB, TAU, */
/* WORK, LWORK, INFO ) */
/* IMPLICIT NONE */
/* CHARACTER UPLO */
/* INTEGER INFO, LDA, LDAB, LWORK, N, KD */
/* COMPLEX A( LDA, * ), AB( LDAB, * ), */
/* TAU( * ), WORK( * ) */
/* > \par Purpose: */
/* ============= */
/* > */
/* > \verbatim */
/* > */
/* > CHETRD_HE2HB reduces a complex Hermitian matrix A to complex Hermitian */
/* > band-diagonal form AB by a unitary similarity transformation: */
/* > Q**H * A * Q = AB. */
/* > \endverbatim */
/* Arguments: */
/* ========== */
/* > \param[in] UPLO */
/* > \verbatim */
/* > UPLO is CHARACTER*1 */
/* > = 'U': Upper triangle of A is stored; */
/* > = 'L': Lower triangle of A is stored. */
/* > \endverbatim */
/* > */
/* > \param[in] N */
/* > \verbatim */
/* > N is INTEGER */
/* > The order of the matrix A. N >= 0. */
/* > \endverbatim */
/* > */
/* > \param[in] KD */
/* > \verbatim */
/* > KD is INTEGER */
/* > The number of superdiagonals of the reduced matrix if UPLO = 'U', */
/* > or the number of subdiagonals if UPLO = 'L'. KD >= 0. */
/* > The reduced matrix is stored in the array AB. */
/* > \endverbatim */
/* > */
/* > \param[in,out] A */
/* > \verbatim */
/* > A is COMPLEX array, dimension (LDA,N) */
/* > On entry, the Hermitian matrix A. If UPLO = 'U', the leading */
/* > N-by-N upper triangular part of A contains the upper */
/* > triangular part of the matrix A, and the strictly lower */
/* > triangular part of A is not referenced. If UPLO = 'L', the */
/* > leading N-by-N lower triangular part of A contains the lower */
/* > triangular part of the matrix A, and the strictly upper */
/* > triangular part of A is not referenced. */
/* > On exit, if UPLO = 'U', the diagonal and first superdiagonal */
/* > of A are overwritten by the corresponding elements of the */
/* > tridiagonal matrix T, and the elements above the first */
/* > superdiagonal, with the array TAU, represent the unitary */
/* > matrix Q as a product of elementary reflectors; if UPLO */
/* > = 'L', the diagonal and first subdiagonal of A are over- */
/* > written by the corresponding elements of the tridiagonal */
/* > matrix T, and the elements below the first subdiagonal, with */
/* > the array TAU, represent the unitary matrix Q as a product */
/* > of elementary reflectors. See Further Details. */
/* > \endverbatim */
/* > */
/* > \param[in] LDA */
/* > \verbatim */
/* > LDA is INTEGER */
/* > The leading dimension of the array A. LDA >= f2cmax(1,N). */
/* > \endverbatim */
/* > */
/* > \param[out] AB */
/* > \verbatim */
/* > AB is COMPLEX array, dimension (LDAB,N) */
/* > On exit, the upper or lower triangle of the Hermitian band */
/* > matrix A, stored in the first KD+1 rows of the array. The */
/* > j-th column of A is stored in the j-th column of the array AB */
/* > as follows: */
/* > if UPLO = 'U', AB(kd+1+i-j,j) = A(i,j) for f2cmax(1,j-kd)<=i<=j; */
/* > if UPLO = 'L', AB(1+i-j,j) = A(i,j) for j<=i<=f2cmin(n,j+kd). */
/* > \endverbatim */
/* > */
/* > \param[in] LDAB */
/* > \verbatim */
/* > LDAB is INTEGER */
/* > The leading dimension of the array AB. LDAB >= KD+1. */
/* > \endverbatim */
/* > */
/* > \param[out] TAU */
/* > \verbatim */
/* > TAU is COMPLEX array, dimension (N-KD) */
/* > The scalar factors of the elementary reflectors (see Further */
/* > Details). */
/* > \endverbatim */
/* > */
/* > \param[out] WORK */
/* > \verbatim */
/* > WORK is COMPLEX array, dimension (LWORK) */
/* > On exit, if INFO = 0, or if LWORK=-1, */
/* > WORK(1) returns the size of LWORK. */
/* > \endverbatim */
/* > */
/* > \param[in] LWORK */
/* > \verbatim */
/* > LWORK is INTEGER */
/* > The dimension of the array WORK which should be calculated */
/* > by a workspace query. LWORK = MAX(1, LWORK_QUERY) */
/* > If LWORK = -1, then a workspace query is assumed; the routine */
/* > only calculates the optimal size of the WORK array, returns */
/* > this value as the first entry of the WORK array, and no error */
/* > message related to LWORK is issued by XERBLA. */
/* > LWORK_QUERY = N*KD + N*f2cmax(KD,FACTOPTNB) + 2*KD*KD */
/* > where FACTOPTNB is the blocking used by the QR or LQ */
/* > algorithm, usually FACTOPTNB=128 is a good choice otherwise */
/* > putting LWORK=-1 will provide the size of WORK. */
/* > \endverbatim */
/* > */
/* > \param[out] INFO */
/* > \verbatim */
/* > INFO is INTEGER */
/* > = 0: successful exit */
/* > < 0: if INFO = -i, the i-th argument had an illegal value */
/* > \endverbatim */
/* Authors: */
/* ======== */
/* > \author Univ. of Tennessee */
/* > \author Univ. of California Berkeley */
/* > \author Univ. of Colorado Denver */
/* > \author NAG Ltd. */
/* > \date November 2017 */
/* > \ingroup complexHEcomputational */
/* > \par Further Details: */
/* ===================== */
/* > */
/* > \verbatim */
/* > */
/* > Implemented by Azzam Haidar. */
/* > */
/* > All details are available on technical report, SC11, SC13 papers. */
/* > */
/* > Azzam Haidar, Hatem Ltaief, and Jack Dongarra. */
/* > Parallel reduction to condensed forms for symmetric eigenvalue problems */
/* > using aggregated fine-grained and memory-aware kernels. In Proceedings */
/* > of 2011 International Conference for High Performance Computing, */
/* > Networking, Storage and Analysis (SC '11), New York, NY, USA, */
/* > Article 8 , 11 pages. */
/* > http://doi.acm.org/10.1145/2063384.2063394 */
/* > */
/* > A. Haidar, J. Kurzak, P. Luszczek, 2013. */
/* > An improved parallel singular value algorithm and its implementation */
/* > for multicore hardware, In Proceedings of 2013 International Conference */
/* > for High Performance Computing, Networking, Storage and Analysis (SC '13). */
/* > Denver, Colorado, USA, 2013. */
/* > Article 90, 12 pages. */
/* > http://doi.acm.org/10.1145/2503210.2503292 */
/* > */
/* > A. Haidar, R. Solca, S. Tomov, T. Schulthess and J. Dongarra. */
/* > A novel hybrid CPU-GPU generalized eigensolver for electronic structure */
/* > calculations based on fine-grained memory aware tasks. */
/* > International Journal of High Performance Computing Applications. */
/* > Volume 28 Issue 2, Pages 196-209, May 2014. */
/* > http://hpc.sagepub.com/content/28/2/196 */
/* > */
/* > \endverbatim */
/* > */
/* > \verbatim */
/* > */
/* > If UPLO = 'U', the matrix Q is represented as a product of elementary */
/* > reflectors */
/* > */
/* > Q = H(k)**H . . . H(2)**H H(1)**H, where k = n-kd. */
/* > */
/* > Each H(i) has the form */
/* > */
/* > H(i) = I - tau * v * v**H */
/* > */
/* > where tau is a complex scalar, and v is a complex vector with */
/* > v(1:i+kd-1) = 0 and v(i+kd) = 1; conjg(v(i+kd+1:n)) is stored on exit in */
/* > A(i,i+kd+1:n), and tau in TAU(i). */
/* > */
/* > If UPLO = 'L', the matrix Q is represented as a product of elementary */
/* > reflectors */
/* > */
/* > Q = H(1) H(2) . . . H(k), where k = n-kd. */
/* > */
/* > Each H(i) has the form */
/* > */
/* > H(i) = I - tau * v * v**H */
/* > */
/* > where tau is a complex scalar, and v is a complex vector with */
/* > v(kd+1:i) = 0 and v(i+kd+1) = 1; v(i+kd+2:n) is stored on exit in */
/* > A(i+kd+2:n,i), and tau in TAU(i). */
/* > */
/* > The contents of A on exit are illustrated by the following examples */
/* > with n = 5: */
/* > */
/* > if UPLO = 'U': if UPLO = 'L': */
/* > */
/* > ( ab ab/v1 v1 v1 v1 ) ( ab ) */
/* > ( ab ab/v2 v2 v2 ) ( ab/v1 ab ) */
/* > ( ab ab/v3 v3 ) ( v1 ab/v2 ab ) */
/* > ( ab ab/v4 ) ( v1 v2 ab/v3 ab ) */
/* > ( ab ) ( v1 v2 v3 ab/v4 ab ) */
/* > */
/* > where d and e denote diagonal and off-diagonal elements of T, and vi */
/* > denotes an element of the vector defining H(i). */
/* > \endverbatim */
/* > */
/* ===================================================================== */
/* Subroutine */ int chetrd_he2hb_(char *uplo, integer *n, integer *kd,
complex *a, integer *lda, complex *ab, integer *ldab, complex *tau,
complex *work, integer *lwork, integer *info)
{
/* System generated locals */
integer a_dim1, a_offset, ab_dim1, ab_offset, i__1, i__2, i__3, i__4,
i__5;
complex q__1;
/* Local variables */
extern integer ilaenv2stage_(integer *, char *, char *, integer *,
integer *, integer *, integer *);
integer tpos, wpos, s1pos, s2pos, i__, j;
extern /* Subroutine */ int cgemm_(char *, char *, integer *, integer *,
integer *, complex *, complex *, integer *, complex *, integer *,
complex *, complex *, integer *), chemm_(char *,
char *, integer *, integer *, complex *, complex *, integer *,
complex *, integer *, complex *, complex *, integer *);
extern logical lsame_(char *, char *);
integer iinfo;
extern /* Subroutine */ int ccopy_(integer *, complex *, integer *,
complex *, integer *);
integer lwmin;
logical upper;
extern /* Subroutine */ int cher2k_(char *, char *, integer *, integer *,
complex *, complex *, integer *, complex *, integer *, real *,
complex *, integer *);
integer lk, pk, pn, lt;
extern /* Subroutine */ int cgelqf_(integer *, integer *, complex *,
integer *, complex *, complex *, integer *, integer *);
integer lw;
extern /* Subroutine */ int cgeqrf_(integer *, integer *, complex *,
integer *, complex *, complex *, integer *, integer *), clarft_(
char *, char *, integer *, integer *, complex *, integer *,
complex *, complex *, integer *), claset_(char *,
integer *, integer *, complex *, complex *, complex *, integer *), xerbla_(char *, integer *, ftnlen);
integer ls1;
logical lquery;
integer ls2, ldt, ldw, lds1, lds2;
/* -- LAPACK computational routine (version 3.8.0) -- */
/* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
/* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
/* November 2017 */
/* ===================================================================== */
/* Determine the minimal workspace size required */
/* and test the input parameters */
/* Parameter adjustments */
a_dim1 = *lda;
a_offset = 1 + a_dim1 * 1;
a -= a_offset;
ab_dim1 = *ldab;
ab_offset = 1 + ab_dim1 * 1;
ab -= ab_offset;
--tau;
--work;
/* Function Body */
*info = 0;
upper = lsame_(uplo, "U");
lquery = *lwork == -1;
lwmin = ilaenv2stage_(&c__4, "CHETRD_HE2HB", "", n, kd, &c_n1, &c_n1);
if (! upper && ! lsame_(uplo, "L")) {
*info = -1;
} else if (*n < 0) {
*info = -2;
} else if (*kd < 0) {
*info = -3;
} else if (*lda < f2cmax(1,*n)) {
*info = -5;
} else /* if(complicated condition) */ {
/* Computing MAX */
i__1 = 1, i__2 = *kd + 1;
if (*ldab < f2cmax(i__1,i__2)) {
*info = -7;
} else if (*lwork < lwmin && ! lquery) {
*info = -10;
}
}
if (*info != 0) {
i__1 = -(*info);
xerbla_("CHETRD_HE2HB", &i__1, (ftnlen)12);
return 0;
} else if (lquery) {
work[1].r = (real) lwmin, work[1].i = 0.f;
return 0;
}
/* Quick return if possible */
/* Copy the upper/lower portion of A into AB */
if (*n <= *kd + 1) {
if (upper) {
i__1 = *n;
for (i__ = 1; i__ <= i__1; ++i__) {
/* Computing MIN */
i__2 = *kd + 1;
lk = f2cmin(i__2,i__);
ccopy_(&lk, &a[i__ - lk + 1 + i__ * a_dim1], &c__1, &ab[*kd +
1 - lk + 1 + i__ * ab_dim1], &c__1);
/* L100: */
}
} else {
i__1 = *n;
for (i__ = 1; i__ <= i__1; ++i__) {
/* Computing MIN */
i__2 = *kd + 1, i__3 = *n - i__ + 1;
lk = f2cmin(i__2,i__3);
ccopy_(&lk, &a[i__ + i__ * a_dim1], &c__1, &ab[i__ * ab_dim1
+ 1], &c__1);
/* L110: */
}
}
work[1].r = 1.f, work[1].i = 0.f;
return 0;
}
/* Determine the pointer position for the workspace */
ldt = *kd;
lds1 = *kd;
lt = ldt * *kd;
lw = *n * *kd;
ls1 = lds1 * *kd;
ls2 = lwmin - lt - lw - ls1;
/* LS2 = N*MAX(KD,FACTOPTNB) */
tpos = 1;
wpos = tpos + lt;
s1pos = wpos + lw;
s2pos = s1pos + ls1;
if (upper) {
ldw = *kd;
lds2 = *kd;
} else {
ldw = *n;
lds2 = *n;
}
/* Set the workspace of the triangular matrix T to zero once such a */
/* way every time T is generated the upper/lower portion will be always zero */
claset_("A", &ldt, kd, &c_b1, &c_b1, &work[tpos], &ldt);
if (upper) {
i__1 = *n - *kd;
i__2 = *kd;
for (i__ = 1; i__2 < 0 ? i__ >= i__1 : i__ <= i__1; i__ += i__2) {
pn = *n - i__ - *kd + 1;
/* Computing MIN */
i__3 = *n - i__ - *kd + 1;
pk = f2cmin(i__3,*kd);
/* Compute the LQ factorization of the current block */
cgelqf_(kd, &pn, &a[i__ + (i__ + *kd) * a_dim1], lda, &tau[i__], &
work[s2pos], &ls2, &iinfo);
/* Copy the upper portion of A into AB */
i__3 = i__ + pk - 1;
for (j = i__; j <= i__3; ++j) {
/* Computing MIN */
i__4 = *kd, i__5 = *n - j;
lk = f2cmin(i__4,i__5) + 1;
i__4 = *ldab - 1;
ccopy_(&lk, &a[j + j * a_dim1], lda, &ab[*kd + 1 + j *
ab_dim1], &i__4);
/* L20: */
}
claset_("Lower", &pk, &pk, &c_b1, &c_b2, &a[i__ + (i__ + *kd) *
a_dim1], lda);
/* Form the matrix T */
clarft_("Forward", "Rowwise", &pn, &pk, &a[i__ + (i__ + *kd) *
a_dim1], lda, &tau[i__], &work[tpos], &ldt);
/* Compute W: */
cgemm_("Conjugate", "No transpose", &pk, &pn, &pk, &c_b2, &work[
tpos], &ldt, &a[i__ + (i__ + *kd) * a_dim1], lda, &c_b1, &
work[s2pos], &lds2);
chemm_("Right", uplo, &pk, &pn, &c_b2, &a[i__ + *kd + (i__ + *kd)
* a_dim1], lda, &work[s2pos], &lds2, &c_b1, &work[wpos], &
ldw);
cgemm_("No transpose", "Conjugate", &pk, &pk, &pn, &c_b2, &work[
wpos], &ldw, &work[s2pos], &lds2, &c_b1, &work[s1pos], &
lds1);
q__1.r = -.5f, q__1.i = 0.f;
cgemm_("No transpose", "No transpose", &pk, &pn, &pk, &q__1, &
work[s1pos], &lds1, &a[i__ + (i__ + *kd) * a_dim1], lda, &
c_b2, &work[wpos], &ldw);
/* Update the unreduced submatrix A(i+kd:n,i+kd:n), using */
/* an update of the form: A := A - V'*W - W'*V */
q__1.r = -1.f, q__1.i = 0.f;
cher2k_(uplo, "Conjugate", &pn, &pk, &q__1, &a[i__ + (i__ + *kd) *
a_dim1], lda, &work[wpos], &ldw, &c_b33, &a[i__ + *kd + (
i__ + *kd) * a_dim1], lda);
/* L10: */
}
/* Copy the upper band to AB which is the band storage matrix */
i__2 = *n;
for (j = *n - *kd + 1; j <= i__2; ++j) {
/* Computing MIN */
i__1 = *kd, i__3 = *n - j;
lk = f2cmin(i__1,i__3) + 1;
i__1 = *ldab - 1;
ccopy_(&lk, &a[j + j * a_dim1], lda, &ab[*kd + 1 + j * ab_dim1], &
i__1);
/* L30: */
}
} else {
/* Reduce the lower triangle of A to lower band matrix */
i__2 = *n - *kd;
i__1 = *kd;
for (i__ = 1; i__1 < 0 ? i__ >= i__2 : i__ <= i__2; i__ += i__1) {
pn = *n - i__ - *kd + 1;
/* Computing MIN */
i__3 = *n - i__ - *kd + 1;
pk = f2cmin(i__3,*kd);
/* Compute the QR factorization of the current block */
cgeqrf_(&pn, kd, &a[i__ + *kd + i__ * a_dim1], lda, &tau[i__], &
work[s2pos], &ls2, &iinfo);
/* Copy the upper portion of A into AB */
i__3 = i__ + pk - 1;
for (j = i__; j <= i__3; ++j) {
/* Computing MIN */
i__4 = *kd, i__5 = *n - j;
lk = f2cmin(i__4,i__5) + 1;
ccopy_(&lk, &a[j + j * a_dim1], &c__1, &ab[j * ab_dim1 + 1], &
c__1);
/* L50: */
}
claset_("Upper", &pk, &pk, &c_b1, &c_b2, &a[i__ + *kd + i__ *
a_dim1], lda);
/* Form the matrix T */
clarft_("Forward", "Columnwise", &pn, &pk, &a[i__ + *kd + i__ *
a_dim1], lda, &tau[i__], &work[tpos], &ldt);
/* Compute W: */
cgemm_("No transpose", "No transpose", &pn, &pk, &pk, &c_b2, &a[
i__ + *kd + i__ * a_dim1], lda, &work[tpos], &ldt, &c_b1,
&work[s2pos], &lds2);
chemm_("Left", uplo, &pn, &pk, &c_b2, &a[i__ + *kd + (i__ + *kd) *
a_dim1], lda, &work[s2pos], &lds2, &c_b1, &work[wpos], &
ldw);
cgemm_("Conjugate", "No transpose", &pk, &pk, &pn, &c_b2, &work[
s2pos], &lds2, &work[wpos], &ldw, &c_b1, &work[s1pos], &
lds1);
q__1.r = -.5f, q__1.i = 0.f;
cgemm_("No transpose", "No transpose", &pn, &pk, &pk, &q__1, &a[
i__ + *kd + i__ * a_dim1], lda, &work[s1pos], &lds1, &
c_b2, &work[wpos], &ldw);
/* Update the unreduced submatrix A(i+kd:n,i+kd:n), using */
/* an update of the form: A := A - V*W' - W*V' */
q__1.r = -1.f, q__1.i = 0.f;
cher2k_(uplo, "No transpose", &pn, &pk, &q__1, &a[i__ + *kd + i__
* a_dim1], lda, &work[wpos], &ldw, &c_b33, &a[i__ + *kd +
(i__ + *kd) * a_dim1], lda);
/* ================================================================== */
/* RESTORE A FOR COMPARISON AND CHECKING TO BE REMOVED */
/* DO 45 J = I, I+PK-1 */
/* LK = MIN( KD, N-J ) + 1 */
/* CALL CCOPY( LK, AB( 1, J ), 1, A( J, J ), 1 ) */
/* 45 CONTINUE */
/* ================================================================== */
/* L40: */
}
/* Copy the lower band to AB which is the band storage matrix */
i__1 = *n;
for (j = *n - *kd + 1; j <= i__1; ++j) {
/* Computing MIN */
i__2 = *kd, i__3 = *n - j;
lk = f2cmin(i__2,i__3) + 1;
ccopy_(&lk, &a[j + j * a_dim1], &c__1, &ab[j * ab_dim1 + 1], &
c__1);
/* L60: */
}
}
work[1].r = (real) lwmin, work[1].i = 0.f;
return 0;
/* End of CHETRD_HE2HB */
} /* chetrd_he2hb__ */
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.