content
stringlengths
19
48.2k
/* -Header_File SpiceCel.h ( CSPICE Cell definitions ) -Abstract Perform CSPICE definitions for the SpiceCell data type. -Disclaimer THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE SOFTWARE AND RELATED MATERIALS, HOWEVER USED. IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. -Required_Reading CELLS -Particulars This header defines structures, macros, and enumerated types that may be referenced in application code that calls CSPICE cell functions. CSPICE cells are data structures that implement functionality parallel to that of the cell abstract data type in SPICELIB. In CSPICE, a cell is a C structure containing bookkeeping information, including a pointer to an associated data array. For numeric data types, the data array is simply a SPICELIB-style cell, including a valid control area. For character cells, the data array has the same number of elements as the corresponding SPICELIB-style cell, but the contents of the control area are not maintained, and the data elements are null-terminated C-style strings. CSPICE cells should be declared using the declaration macros provided in this header file. See the table of macros below. Structures ========== Name Description ---- ---------- SpiceCell Structure containing CSPICE cell metadata. The members are: dtype: Data type of cell: character, integer, or double precision. dtype has type SpiceCellDataType. length: For character cells, the declared length of the cell's string array. size: The maximum number of data items that can be stored in the cell's data array. card: The cell's "cardinality": the number of data items currently present in the cell. isSet: Boolean flag indicating whether the cell is a CSPICE set. Sets have no duplicate data items, and their data items are stored in increasing order. adjust: Boolean flag indicating whether the cell's data area has adjustable size. Adjustable size cell data areas are not currently implemented. init: Boolean flag indicating whether the cell has been initialized. base: is a void pointer to the associated data array. base points to the start of the control area of this array. data: is a void pointer to the first data slot in the associated data array. This slot is the element following the control area. ConstSpiceCell A const SpiceCell. Declaration Macros ================== Name Description ---- ---------- SPICECHAR_CELL ( name, size, length ) Declare a character CSPICE cell having cell name name, maximum cell cardinality size, and string length length. The macro declares both the cell and the associated data array. The name of the data array begins with "SPICE_". SPICEDOUBLE_CELL ( name, size ) Like SPICECHAR_CELL, but declares a double precision cell. SPICEINT_CELL ( name, size ) Like SPICECHAR_CELL, but declares an integer cell. Assignment Macros ================= Name Description ---- ---------- SPICE_CELL_SET_C( item, i, cell ) Assign the ith element of a character cell. Arguments cell and item are pointers. SPICE_CELL_SET_D( item, i, cell ) Assign the ith element of a double precision cell. Argument cell is a pointer. SPICE_CELL_SET_I( item, i, cell ) Assign the ith element of an integer cell. Argument cell is a pointer. Fetch Macros ============== Name Description ---- ---------- SPICE_CELL_GET_C( cell, i, lenout, item ) Fetch the ith element from a character cell. Arguments cell and item are pointers. Argument lenout is the available space in item. SPICE_CELL_GET_D( cell, i, item ) Fetch the ith element from a double precision cell. Arguments cell and item are pointers. SPICE_CELL_GET_I( cell, i, item ) Fetch the ith element from an integer cell. Arguments cell and item are pointers. Element Pointer Macros ====================== Name Description ---- ---------- SPICE_CELL_ELEM_C( cell, i ) Macro evaluates to a SpiceChar pointer to the ith data element of a character cell. Argument cell is a pointer. SPICE_CELL_ELEM_D( cell, i ) Macro evaluates to a SpiceDouble pointer to the ith data element of a double precision cell. Argument cell is a pointer. SPICE_CELL_ELEM_I( cell, i ) Macro evaluates to a SpiceInt pointer to the ith data element of an integer cell. Argument cell is a pointer. -Literature_References None. -Author_and_Institution N.J. Bachman (JPL) -Restrictions None. -Version -CSPICE Version 1.0.0, 22-AUG-2002 (NJB) */ #ifndef HAVE_SPICE_CELLS_H #define HAVE_SPICE_CELLS_H /* Data type codes: */ typedef enum _SpiceDataType SpiceCellDataType; /* Cell structure: */ struct _SpiceCell { SpiceCellDataType dtype; SpiceInt length; SpiceInt size; SpiceInt card; SpiceBoolean isSet; SpiceBoolean adjust; SpiceBoolean init; void * base; void * data; }; typedef struct _SpiceCell SpiceCell; typedef const SpiceCell ConstSpiceCell; /* SpiceCell control area size: */ #define SPICE_CELL_CTRLSZ 6 /* Declaration macros: */ #define SPICECHAR_CELL( name, size, length ) \ \ static SpiceChar SPICE_CELL_##name[SPICE_CELL_CTRLSZ + size][length]; \ \ static SpiceCell name = \ \ { SPICE_CHR, \ length, \ size, \ 0, \ SPICETRUE, \ SPICEFALSE, \ SPICEFALSE, \ (void *) &(SPICE_CELL_##name), \ (void *) &(SPICE_CELL_##name[SPICE_CELL_CTRLSZ]) } #define SPICEDOUBLE_CELL( name, size ) \ \ static SpiceDouble SPICE_CELL_##name [SPICE_CELL_CTRLSZ + size]; \ \ static SpiceCell name = \ \ { SPICE_DP, \ 0, \ size, \ 0, \ SPICETRUE, \ SPICEFALSE, \ SPICEFALSE, \ (void *) &(SPICE_CELL_##name), \ (void *) &(SPICE_CELL_##name[SPICE_CELL_CTRLSZ]) } #define SPICEINT_CELL( name, size ) \ \ static SpiceInt SPICE_CELL_##name [SPICE_CELL_CTRLSZ + size]; \ \ static SpiceCell name = \ \ { SPICE_INT, \ 0, \ size, \ 0, \ SPICETRUE, \ SPICEFALSE, \ SPICEFALSE, \ (void *) &(SPICE_CELL_##name), \ (void *) &(SPICE_CELL_##name[SPICE_CELL_CTRLSZ]) } /* Access macros for individual elements: */ /* Data element pointer macros: */ #define SPICE_CELL_ELEM_C( cell, i ) \ \ ( ( (SpiceChar *) (cell)->data ) + (i)*( (cell)->length ) ) #define SPICE_CELL_ELEM_D( cell, i ) \ \ ( ( (SpiceDouble *) (cell)->data )[(i)] ) #define SPICE_CELL_ELEM_I( cell, i ) \ \ ( ( (SpiceInt *) (cell)->data )[(i)] ) /* "Fetch" macros: */ #define SPICE_CELL_GET_C( cell, i, lenout, item ) \ \ { \ SpiceInt nBytes; \ \ nBytes = brckti_c ( (cell)->length, 0, (lenout-1) ) \ * sizeof ( SpiceChar ); \ \ memmove ( (item), SPICE_CELL_ELEM_C((cell), (i)), nBytes ); \ \ item[nBytes] = NULLCHAR; \ } #define SPICE_CELL_GET_D( cell, i, item ) \ \ ( (*item) = ( (SpiceDouble *) (cell)->data)[i] ) #define SPICE_CELL_GET_I( cell, i, item ) \ \ ( (*item) = ( (SpiceInt *) (cell)->data)[i] ) /* Assignment macros: */ #define SPICE_CELL_SET_C( item, i, cell ) \ \ { \ SpiceChar * sPtr; \ SpiceInt nBytes; \ \ nBytes = brckti_c ( strlen(item), 0, (cell)->length - 1 ) \ * sizeof ( SpiceChar ); \ \ sPtr = SPICE_CELL_ELEM_C((cell), (i)); \ \ memmove ( sPtr, (item), nBytes ); \ \ sPtr[nBytes] = NULLCHAR; \ } #define SPICE_CELL_SET_D( item, i, cell ) \ \ ( ( (SpiceDouble *) (cell)->data)[i] = (item) ) #define SPICE_CELL_SET_I( item, i, cell ) \ \ ( ( (SpiceInt *) (cell)->data)[i] = (item) ) /* The enum SpiceTransDir is used to indicate language translation direction: C to Fortran or vice versa. */ enum _SpiceTransDir { C2F = 0, F2C = 1 }; typedef enum _SpiceTransDir SpiceTransDir; #endif
/* Perform the transfers with the process. */ void kcd_process_do_xfer(struct kcd_process *self) { kcd_process_handle_input(self); kcd_process_handle_output(self, self->desc + 2, &self->out_str, "stdout"); kcd_process_handle_output(self, self->desc + 4, &self->err_str, "stderr"); }
/* * Read a pin on the EMIO port quickly. Only supports pins in range 53 ~ 117. */ inline static int emio_fast_read(unsigned int pin) { unsigned int bank; uint32_t read; uint32_t *reg; D_ASSERT(pin >= 53 && pin <= 117) ; pin -= 54; bank = (pin >> 5) + 2; reg = (uint32_t*)(bank * XGPIOPS_DATA_BANK_OFFSET); return (XGpioPs_ReadReg(XPS_GPIO_BASEADDR, ((bank) * XGPIOPS_DATA_BANK_OFFSET) + XGPIOPS_DATA_RO_OFFSET) >> pin) & 0x01; }
/** * Return the closest int for the given float. Returns SK_MaxS32FitsInFloat for NaN. */ static inline int sk_float_saturate2int(float x) { x = x < SK_MaxS32FitsInFloat ? x : SK_MaxS32FitsInFloat; x = x > SK_MinS32FitsInFloat ? x : SK_MinS32FitsInFloat; return (int)x; }
/* start of generated data */ static BN_ULONG bn_group_1024_value[] = { bn_pack4(0x9FC6,0x1D2F,0xC0EB,0x06E3), bn_pack4(0xFD51,0x38FE,0x8376,0x435B), bn_pack4(0x2FD4,0xCBF4,0x976E,0xAA9A), bn_pack4(0x68ED,0xBC3C,0x0572,0x6CC0), bn_pack4(0xC529,0xF566,0x660E,0x57EC), bn_pack4(0x8255,0x9B29,0x7BCF,0x1885), bn_pack4(0xCE8E,0xF4AD,0x69B1,0x5D49), bn_pack4(0x5DC7,0xD7B4,0x6154,0xD6B6), bn_pack4(0x8E49,0x5C1D,0x6089,0xDAD1), bn_pack4(0xE0D5,0xD8E2,0x50B9,0x8BE4), bn_pack4(0x383B,0x4813,0xD692,0xC6E0), bn_pack4(0xD674,0xDF74,0x96EA,0x81D3), bn_pack4(0x9EA2,0x314C,0x9C25,0x6576), bn_pack4(0x6072,0x6187,0x75FF,0x3C0B), bn_pack4(0x9C33,0xF80A,0xFA8F,0xC5E8), bn_pack4(0xEEAF,0x0AB9,0xADB3,0x8DD6) }; static BIGNUM bn_group_1024 = { bn_group_1024_value, (sizeof bn_group_1024_value)/sizeof(BN_ULONG), (sizeof bn_group_1024_value)/sizeof(BN_ULONG), 0, BN_FLG_STATIC_DATA }; static BN_ULONG bn_group_1536_value[] = { bn_pack4(0xCF76,0xE3FE,0xD135,0xF9BB), bn_pack4(0x1518,0x0F93,0x499A,0x234D), bn_pack4(0x8CE7,0xA28C,0x2442,0xC6F3), bn_pack4(0x5A02,0x1FFF,0x5E91,0x479E), bn_pack4(0x7F8A,0x2FE9,0xB8B5,0x292E), bn_pack4(0x837C,0x264A,0xE3A9,0xBEB8), bn_pack4(0xE442,0x734A,0xF7CC,0xB7AE), bn_pack4(0x6577,0x2E43,0x7D6C,0x7F8C), bn_pack4(0xDB2F,0xD53D,0x24B7,0xC486), bn_pack4(0x6EDF,0x0195,0x3934,0x9627), bn_pack4(0x158B,0xFD3E,0x2B9C,0x8CF5), bn_pack4(0x764E,0x3F4B,0x53DD,0x9DA1), bn_pack4(0x4754,0x8381,0xDBC5,0xB1FC), bn_pack4(0x9B60,0x9E0B,0xE3BA,0xB63D), bn_pack4(0x8134,0xB1C8,0xB979,0x8914), bn_pack4(0xDF02,0x8A7C,0xEC67,0xF0D0), bn_pack4(0x80B6,0x55BB,0x9A22,0xE8DC), bn_pack4(0x1558,0x903B,0xA0D0,0xF843), bn_pack4(0x51C6,0xA94B,0xE460,0x7A29), bn_pack4(0x5F4F,0x5F55,0x6E27,0xCBDE), bn_pack4(0xBEEE,0xA961,0x4B19,0xCC4D), bn_pack4(0xDBA5,0x1DF4,0x99AC,0x4C80), bn_pack4(0xB1F1,0x2A86,0x17A4,0x7BBB), bn_pack4(0x9DEF,0x3CAF,0xB939,0x277A) }; static BIGNUM bn_group_1536 = { bn_group_1536_value, (sizeof bn_group_1536_value)/sizeof(BN_ULONG), (sizeof bn_group_1536_value)/sizeof(BN_ULONG), 0, BN_FLG_STATIC_DATA }; static BN_ULONG bn_group_2048_value[] = { bn_pack4(0x0FA7,0x111F,0x9E4A,0xFF73), bn_pack4(0x9B65,0xE372,0xFCD6,0x8EF2), bn_pack4(0x35DE,0x236D,0x525F,0x5475), bn_pack4(0x94B5,0xC803,0xD89F,0x7AE4), bn_pack4(0x71AE,0x35F8,0xE9DB,0xFBB6), bn_pack4(0x2A56,0x98F3,0xA8D0,0xC382), bn_pack4(0x9CCC,0x041C,0x7BC3,0x08D8), bn_pack4(0xAF87,0x4E73,0x03CE,0x5329), bn_pack4(0x6160,0x2790,0x04E5,0x7AE6), bn_pack4(0x032C,0xFBDB,0xF52F,0xB378), bn_pack4(0x5EA7,0x7A27,0x75D2,0xECFA), bn_pack4(0x5445,0x23B5,0x24B0,0xD57D), bn_pack4(0x5B9D,0x32E6,0x88F8,0x7748), bn_pack4(0xF1D2,0xB907,0x8717,0x461A), bn_pack4(0x76BD,0x207A,0x436C,0x6481), bn_pack4(0xCA97,0xB43A,0x23FB,0x8016), bn_pack4(0x1D28,0x1E44,0x6B14,0x773B), bn_pack4(0x7359,0xD041,0xD5C3,0x3EA7), bn_pack4(0xA80D,0x740A,0xDBF4,0xFF74), bn_pack4(0x55F9,0x7993,0xEC97,0x5EEA), bn_pack4(0x2918,0xA996,0x2F0B,0x93B8), bn_pack4(0x661A,0x05FB,0xD5FA,0xAAE8), bn_pack4(0xCF60,0x9517,0x9A16,0x3AB3), bn_pack4(0xE808,0x3969,0xEDB7,0x67B0), bn_pack4(0xCD7F,0x48A9,0xDA04,0xFD50), bn_pack4(0xD523,0x12AB,0x4B03,0x310D), bn_pack4(0x8193,0xE075,0x7767,0xA13D), bn_pack4(0xA373,0x29CB,0xB4A0,0x99ED), bn_pack4(0xFC31,0x9294,0x3DB5,0x6050), bn_pack4(0xAF72,0xB665,0x1987,0xEE07), bn_pack4(0xF166,0xDE5E,0x1389,0x582F), bn_pack4(0xAC6B,0xDB41,0x324A,0x9A9B) }; static BIGNUM bn_group_2048 = { bn_group_2048_value, (sizeof bn_group_2048_value)/sizeof(BN_ULONG), (sizeof bn_group_2048_value)/sizeof(BN_ULONG), 0, BN_FLG_STATIC_DATA }; static BN_ULONG bn_group_3072_value[] = { bn_pack4(0xFFFF,0xFFFF,0xFFFF,0xFFFF), bn_pack4(0x4B82,0xD120,0xA93A,0xD2CA), bn_pack4(0x43DB,0x5BFC,0xE0FD,0x108E), bn_pack4(0x08E2,0x4FA0,0x74E5,0xAB31), bn_pack4(0x7709,0x88C0,0xBAD9,0x46E2), bn_pack4(0xBBE1,0x1757,0x7A61,0x5D6C), bn_pack4(0x521F,0x2B18,0x177B,0x200C), bn_pack4(0xD876,0x0273,0x3EC8,0x6A64), bn_pack4(0xF12F,0xFA06,0xD98A,0x0864), bn_pack4(0xCEE3,0xD226,0x1AD2,0xEE6B), bn_pack4(0x1E8C,0x94E0,0x4A25,0x619D), bn_pack4(0xABF5,0xAE8C,0xDB09,0x33D7), bn_pack4(0xB397,0x0F85,0xA6E1,0xE4C7), bn_pack4(0x8AEA,0x7157,0x5D06,0x0C7D), bn_pack4(0xECFB,0x8504,0x58DB,0xEF0A), bn_pack4(0xA855,0x21AB,0xDF1C,0xBA64), bn_pack4(0xAD33,0x170D,0x0450,0x7A33), bn_pack4(0x1572,0x8E5A,0x8AAA,0xC42D), bn_pack4(0x15D2,0x2618,0x98FA,0x0510), bn_pack4(0x3995,0x497C,0xEA95,0x6AE5), bn_pack4(0xDE2B,0xCBF6,0x9558,0x1718), bn_pack4(0xB5C5,0x5DF0,0x6F4C,0x52C9), bn_pack4(0x9B27,0x83A2,0xEC07,0xA28F), bn_pack4(0xE39E,0x772C,0x180E,0x8603), bn_pack4(0x3290,0x5E46,0x2E36,0xCE3B), bn_pack4(0xF174,0x6C08,0xCA18,0x217C), bn_pack4(0x670C,0x354E,0x4ABC,0x9804), bn_pack4(0x9ED5,0x2907,0x7096,0x966D), bn_pack4(0x1C62,0xF356,0x2085,0x52BB), bn_pack4(0x8365,0x5D23,0xDCA3,0xAD96), bn_pack4(0x6916,0x3FA8,0xFD24,0xCF5F), bn_pack4(0x98DA,0x4836,0x1C55,0xD39A), bn_pack4(0xC200,0x7CB8,0xA163,0xBF05), bn_pack4(0x4928,0x6651,0xECE4,0x5B3D), bn_pack4(0xAE9F,0x2411,0x7C4B,0x1FE6), bn_pack4(0xEE38,0x6BFB,0x5A89,0x9FA5), bn_pack4(0x0BFF,0x5CB6,0xF406,0xB7ED), bn_pack4(0xF44C,0x42E9,0xA637,0xED6B), bn_pack4(0xE485,0xB576,0x625E,0x7EC6), bn_pack4(0x4FE1,0x356D,0x6D51,0xC245), bn_pack4(0x302B,0x0A6D,0xF25F,0x1437), bn_pack4(0xEF95,0x19B3,0xCD3A,0x431B), bn_pack4(0x514A,0x0879,0x8E34,0x04DD), bn_pack4(0x020B,0xBEA6,0x3B13,0x9B22), bn_pack4(0x2902,0x4E08,0x8A67,0xCC74), bn_pack4(0xC4C6,0x628B,0x80DC,0x1CD1), bn_pack4(0xC90F,0xDAA2,0x2168,0xC234), bn_pack4(0xFFFF,0xFFFF,0xFFFF,0xFFFF) }; static BIGNUM bn_group_3072 = { bn_group_3072_value, (sizeof bn_group_3072_value)/sizeof(BN_ULONG), (sizeof bn_group_3072_value)/sizeof(BN_ULONG), 0, BN_FLG_STATIC_DATA }; static BN_ULONG bn_group_4096_value[] = { bn_pack4(0xFFFF,0xFFFF,0xFFFF,0xFFFF), bn_pack4(0x4DF4,0x35C9,0x3406,0x3199), bn_pack4(0x86FF,0xB7DC,0x90A6,0xC08F), bn_pack4(0x93B4,0xEA98,0x8D8F,0xDDC1), bn_pack4(0xD006,0x9127,0xD5B0,0x5AA9), bn_pack4(0xB81B,0xDD76,0x2170,0x481C), bn_pack4(0x1F61,0x2970,0xCEE2,0xD7AF), bn_pack4(0x233B,0xA186,0x515B,0xE7ED), bn_pack4(0x99B2,0x964F,0xA090,0xC3A2), bn_pack4(0x287C,0x5947,0x4E6B,0xC05D), bn_pack4(0x2E8E,0xFC14,0x1FBE,0xCAA6), bn_pack4(0xDBBB,0xC2DB,0x04DE,0x8EF9), bn_pack4(0x2583,0xE9CA,0x2AD4,0x4CE8), bn_pack4(0x1A94,0x6834,0xB615,0x0BDA), bn_pack4(0x99C3,0x2718,0x6AF4,0xE23C), bn_pack4(0x8871,0x9A10,0xBDBA,0x5B26), bn_pack4(0x1A72,0x3C12,0xA787,0xE6D7), bn_pack4(0x4B82,0xD120,0xA921,0x0801), bn_pack4(0x43DB,0x5BFC,0xE0FD,0x108E), bn_pack4(0x08E2,0x4FA0,0x74E5,0xAB31), bn_pack4(0x7709,0x88C0,0xBAD9,0x46E2), bn_pack4(0xBBE1,0x1757,0x7A61,0x5D6C), bn_pack4(0x521F,0x2B18,0x177B,0x200C), bn_pack4(0xD876,0x0273,0x3EC8,0x6A64), bn_pack4(0xF12F,0xFA06,0xD98A,0x0864), bn_pack4(0xCEE3,0xD226,0x1AD2,0xEE6B), bn_pack4(0x1E8C,0x94E0,0x4A25,0x619D), bn_pack4(0xABF5,0xAE8C,0xDB09,0x33D7), bn_pack4(0xB397,0x0F85,0xA6E1,0xE4C7), bn_pack4(0x8AEA,0x7157,0x5D06,0x0C7D), bn_pack4(0xECFB,0x8504,0x58DB,0xEF0A), bn_pack4(0xA855,0x21AB,0xDF1C,0xBA64), bn_pack4(0xAD33,0x170D,0x0450,0x7A33), bn_pack4(0x1572,0x8E5A,0x8AAA,0xC42D), bn_pack4(0x15D2,0x2618,0x98FA,0x0510), bn_pack4(0x3995,0x497C,0xEA95,0x6AE5), bn_pack4(0xDE2B,0xCBF6,0x9558,0x1718), bn_pack4(0xB5C5,0x5DF0,0x6F4C,0x52C9), bn_pack4(0x9B27,0x83A2,0xEC07,0xA28F), bn_pack4(0xE39E,0x772C,0x180E,0x8603), bn_pack4(0x3290,0x5E46,0x2E36,0xCE3B), bn_pack4(0xF174,0x6C08,0xCA18,0x217C), bn_pack4(0x670C,0x354E,0x4ABC,0x9804), bn_pack4(0x9ED5,0x2907,0x7096,0x966D), bn_pack4(0x1C62,0xF356,0x2085,0x52BB), bn_pack4(0x8365,0x5D23,0xDCA3,0xAD96), bn_pack4(0x6916,0x3FA8,0xFD24,0xCF5F), bn_pack4(0x98DA,0x4836,0x1C55,0xD39A), bn_pack4(0xC200,0x7CB8,0xA163,0xBF05), bn_pack4(0x4928,0x6651,0xECE4,0x5B3D), bn_pack4(0xAE9F,0x2411,0x7C4B,0x1FE6), bn_pack4(0xEE38,0x6BFB,0x5A89,0x9FA5), bn_pack4(0x0BFF,0x5CB6,0xF406,0xB7ED), bn_pack4(0xF44C,0x42E9,0xA637,0xED6B), bn_pack4(0xE485,0xB576,0x625E,0x7EC6), bn_pack4(0x4FE1,0x356D,0x6D51,0xC245), bn_pack4(0x302B,0x0A6D,0xF25F,0x1437), bn_pack4(0xEF95,0x19B3,0xCD3A,0x431B), bn_pack4(0x514A,0x0879,0x8E34,0x04DD), bn_pack4(0x020B,0xBEA6,0x3B13,0x9B22), bn_pack4(0x2902,0x4E08,0x8A67,0xCC74), bn_pack4(0xC4C6,0x628B,0x80DC,0x1CD1), bn_pack4(0xC90F,0xDAA2,0x2168,0xC234), bn_pack4(0xFFFF,0xFFFF,0xFFFF,0xFFFF) }; static BIGNUM bn_group_4096 = { bn_group_4096_value, (sizeof bn_group_4096_value)/sizeof(BN_ULONG), (sizeof bn_group_4096_value)/sizeof(BN_ULONG), 0, BN_FLG_STATIC_DATA }; static BN_ULONG bn_group_6144_value[] = { bn_pack4(0xFFFF,0xFFFF,0xFFFF,0xFFFF), bn_pack4(0xE694,0xF91E,0x6DCC,0x4024), bn_pack4(0x12BF,0x2D5B,0x0B74,0x74D6), bn_pack4(0x043E,0x8F66,0x3F48,0x60EE), bn_pack4(0x387F,0xE8D7,0x6E3C,0x0468), bn_pack4(0xDA56,0xC9EC,0x2EF2,0x9632), bn_pack4(0xEB19,0xCCB1,0xA313,0xD55C), bn_pack4(0xF550,0xAA3D,0x8A1F,0xBFF0), bn_pack4(0x06A1,0xD58B,0xB7C5,0xDA76), bn_pack4(0xA797,0x15EE,0xF29B,0xE328), bn_pack4(0x14CC,0x5ED2,0x0F80,0x37E0), bn_pack4(0xCC8F,0x6D7E,0xBF48,0xE1D8), bn_pack4(0x4BD4,0x07B2,0x2B41,0x54AA), bn_pack4(0x0F1D,0x45B7,0xFF58,0x5AC5), bn_pack4(0x23A9,0x7A7E,0x36CC,0x88BE), bn_pack4(0x59E7,0xC97F,0xBEC7,0xE8F3), bn_pack4(0xB5A8,0x4031,0x900B,0x1C9E), bn_pack4(0xD55E,0x702F,0x4698,0x0C82), bn_pack4(0xF482,0xD7CE,0x6E74,0xFEF6), bn_pack4(0xF032,0xEA15,0xD172,0x1D03), bn_pack4(0x5983,0xCA01,0xC64B,0x92EC), bn_pack4(0x6FB8,0xF401,0x378C,0xD2BF), bn_pack4(0x3320,0x5151,0x2BD7,0xAF42), bn_pack4(0xDB7F,0x1447,0xE6CC,0x254B), bn_pack4(0x44CE,0x6CBA,0xCED4,0xBB1B), bn_pack4(0xDA3E,0xDBEB,0xCF9B,0x14ED), bn_pack4(0x1797,0x27B0,0x865A,0x8918), bn_pack4(0xB06A,0x53ED,0x9027,0xD831), bn_pack4(0xE5DB,0x382F,0x4130,0x01AE), bn_pack4(0xF8FF,0x9406,0xAD9E,0x530E), bn_pack4(0xC975,0x1E76,0x3DBA,0x37BD), bn_pack4(0xC1D4,0xDCB2,0x6026,0x46DE), bn_pack4(0x36C3,0xFAB4,0xD27C,0x7026), bn_pack4(0x4DF4,0x35C9,0x3402,0x8492), bn_pack4(0x86FF,0xB7DC,0x90A6,0xC08F), bn_pack4(0x93B4,0xEA98,0x8D8F,0xDDC1), bn_pack4(0xD006,0x9127,0xD5B0,0x5AA9), bn_pack4(0xB81B,0xDD76,0x2170,0x481C), bn_pack4(0x1F61,0x2970,0xCEE2,0xD7AF), bn_pack4(0x233B,0xA186,0x515B,0xE7ED), bn_pack4(0x99B2,0x964F,0xA090,0xC3A2), bn_pack4(0x287C,0x5947,0x4E6B,0xC05D), bn_pack4(0x2E8E,0xFC14,0x1FBE,0xCAA6), bn_pack4(0xDBBB,0xC2DB,0x04DE,0x8EF9), bn_pack4(0x2583,0xE9CA,0x2AD4,0x4CE8), bn_pack4(0x1A94,0x6834,0xB615,0x0BDA), bn_pack4(0x99C3,0x2718,0x6AF4,0xE23C), bn_pack4(0x8871,0x9A10,0xBDBA,0x5B26), bn_pack4(0x1A72,0x3C12,0xA787,0xE6D7), bn_pack4(0x4B82,0xD120,0xA921,0x0801), bn_pack4(0x43DB,0x5BFC,0xE0FD,0x108E), bn_pack4(0x08E2,0x4FA0,0x74E5,0xAB31), bn_pack4(0x7709,0x88C0,0xBAD9,0x46E2), bn_pack4(0xBBE1,0x1757,0x7A61,0x5D6C), bn_pack4(0x521F,0x2B18,0x177B,0x200C), bn_pack4(0xD876,0x0273,0x3EC8,0x6A64), bn_pack4(0xF12F,0xFA06,0xD98A,0x0864), bn_pack4(0xCEE3,0xD226,0x1AD2,0xEE6B), bn_pack4(0x1E8C,0x94E0,0x4A25,0x619D), bn_pack4(0xABF5,0xAE8C,0xDB09,0x33D7), bn_pack4(0xB397,0x0F85,0xA6E1,0xE4C7), bn_pack4(0x8AEA,0x7157,0x5D06,0x0C7D), bn_pack4(0xECFB,0x8504,0x58DB,0xEF0A), bn_pack4(0xA855,0x21AB,0xDF1C,0xBA64), bn_pack4(0xAD33,0x170D,0x0450,0x7A33), bn_pack4(0x1572,0x8E5A,0x8AAA,0xC42D), bn_pack4(0x15D2,0x2618,0x98FA,0x0510), bn_pack4(0x3995,0x497C,0xEA95,0x6AE5), bn_pack4(0xDE2B,0xCBF6,0x9558,0x1718), bn_pack4(0xB5C5,0x5DF0,0x6F4C,0x52C9), bn_pack4(0x9B27,0x83A2,0xEC07,0xA28F), bn_pack4(0xE39E,0x772C,0x180E,0x8603), bn_pack4(0x3290,0x5E46,0x2E36,0xCE3B), bn_pack4(0xF174,0x6C08,0xCA18,0x217C), bn_pack4(0x670C,0x354E,0x4ABC,0x9804), bn_pack4(0x9ED5,0x2907,0x7096,0x966D), bn_pack4(0x1C62,0xF356,0x2085,0x52BB), bn_pack4(0x8365,0x5D23,0xDCA3,0xAD96), bn_pack4(0x6916,0x3FA8,0xFD24,0xCF5F), bn_pack4(0x98DA,0x4836,0x1C55,0xD39A), bn_pack4(0xC200,0x7CB8,0xA163,0xBF05), bn_pack4(0x4928,0x6651,0xECE4,0x5B3D), bn_pack4(0xAE9F,0x2411,0x7C4B,0x1FE6), bn_pack4(0xEE38,0x6BFB,0x5A89,0x9FA5), bn_pack4(0x0BFF,0x5CB6,0xF406,0xB7ED), bn_pack4(0xF44C,0x42E9,0xA637,0xED6B), bn_pack4(0xE485,0xB576,0x625E,0x7EC6), bn_pack4(0x4FE1,0x356D,0x6D51,0xC245), bn_pack4(0x302B,0x0A6D,0xF25F,0x1437), bn_pack4(0xEF95,0x19B3,0xCD3A,0x431B), bn_pack4(0x514A,0x0879,0x8E34,0x04DD), bn_pack4(0x020B,0xBEA6,0x3B13,0x9B22), bn_pack4(0x2902,0x4E08,0x8A67,0xCC74), bn_pack4(0xC4C6,0x628B,0x80DC,0x1CD1), bn_pack4(0xC90F,0xDAA2,0x2168,0xC234), bn_pack4(0xFFFF,0xFFFF,0xFFFF,0xFFFF) }; static BIGNUM bn_group_6144 = { bn_group_6144_value, (sizeof bn_group_6144_value)/sizeof(BN_ULONG), (sizeof bn_group_6144_value)/sizeof(BN_ULONG), 0, BN_FLG_STATIC_DATA }; static BN_ULONG bn_group_8192_value[] = { bn_pack4(0xFFFF,0xFFFF,0xFFFF,0xFFFF), bn_pack4(0x60C9,0x80DD,0x98ED,0xD3DF), bn_pack4(0xC81F,0x56E8,0x80B9,0x6E71), bn_pack4(0x9E30,0x50E2,0x7656,0x94DF), bn_pack4(0x9558,0xE447,0x5677,0xE9AA), bn_pack4(0xC919,0x0DA6,0xFC02,0x6E47), bn_pack4(0x889A,0x002E,0xD5EE,0x382B), bn_pack4(0x4009,0x438B,0x481C,0x6CD7), bn_pack4(0x3590,0x46F4,0xEB87,0x9F92), bn_pack4(0xFAF3,0x6BC3,0x1ECF,0xA268), bn_pack4(0xB1D5,0x10BD,0x7EE7,0x4D73), bn_pack4(0xF9AB,0x4819,0x5DED,0x7EA1), bn_pack4(0x64F3,0x1CC5,0x0846,0x851D), bn_pack4(0x4597,0xE899,0xA025,0x5DC1), bn_pack4(0xDF31,0x0EE0,0x74AB,0x6A36), bn_pack4(0x6D2A,0x13F8,0x3F44,0xF82D), bn_pack4(0x062B,0x3CF5,0xB3A2,0x78A6), bn_pack4(0x7968,0x3303,0xED5B,0xDD3A), bn_pack4(0xFA9D,0x4B7F,0xA2C0,0x87E8), bn_pack4(0x4BCB,0xC886,0x2F83,0x85DD), bn_pack4(0x3473,0xFC64,0x6CEA,0x306B), bn_pack4(0x13EB,0x57A8,0x1A23,0xF0C7), bn_pack4(0x2222,0x2E04,0xA403,0x7C07), bn_pack4(0xE3FD,0xB8BE,0xFC84,0x8AD9), bn_pack4(0x238F,0x16CB,0xE39D,0x652D), bn_pack4(0x3423,0xB474,0x2BF1,0xC978), bn_pack4(0x3AAB,0x639C,0x5AE4,0xF568), bn_pack4(0x2576,0xF693,0x6BA4,0x2466), bn_pack4(0x741F,0xA7BF,0x8AFC,0x47ED), bn_pack4(0x3BC8,0x32B6,0x8D9D,0xD300), bn_pack4(0xD8BE,0xC4D0,0x73B9,0x31BA), bn_pack4(0x3877,0x7CB6,0xA932,0xDF8C), bn_pack4(0x74A3,0x926F,0x12FE,0xE5E4), bn_pack4(0xE694,0xF91E,0x6DBE,0x1159), bn_pack4(0x12BF,0x2D5B,0x0B74,0x74D6), bn_pack4(0x043E,0x8F66,0x3F48,0x60EE), bn_pack4(0x387F,0xE8D7,0x6E3C,0x0468), bn_pack4(0xDA56,0xC9EC,0x2EF2,0x9632), bn_pack4(0xEB19,0xCCB1,0xA313,0xD55C), bn_pack4(0xF550,0xAA3D,0x8A1F,0xBFF0), bn_pack4(0x06A1,0xD58B,0xB7C5,0xDA76), bn_pack4(0xA797,0x15EE,0xF29B,0xE328), bn_pack4(0x14CC,0x5ED2,0x0F80,0x37E0), bn_pack4(0xCC8F,0x6D7E,0xBF48,0xE1D8), bn_pack4(0x4BD4,0x07B2,0x2B41,0x54AA), bn_pack4(0x0F1D,0x45B7,0xFF58,0x5AC5), bn_pack4(0x23A9,0x7A7E,0x36CC,0x88BE), bn_pack4(0x59E7,0xC97F,0xBEC7,0xE8F3), bn_pack4(0xB5A8,0x4031,0x900B,0x1C9E), bn_pack4(0xD55E,0x702F,0x4698,0x0C82), bn_pack4(0xF482,0xD7CE,0x6E74,0xFEF6), bn_pack4(0xF032,0xEA15,0xD172,0x1D03), bn_pack4(0x5983,0xCA01,0xC64B,0x92EC), bn_pack4(0x6FB8,0xF401,0x378C,0xD2BF), bn_pack4(0x3320,0x5151,0x2BD7,0xAF42), bn_pack4(0xDB7F,0x1447,0xE6CC,0x254B), bn_pack4(0x44CE,0x6CBA,0xCED4,0xBB1B), bn_pack4(0xDA3E,0xDBEB,0xCF9B,0x14ED), bn_pack4(0x1797,0x27B0,0x865A,0x8918), bn_pack4(0xB06A,0x53ED,0x9027,0xD831), bn_pack4(0xE5DB,0x382F,0x4130,0x01AE), bn_pack4(0xF8FF,0x9406,0xAD9E,0x530E), bn_pack4(0xC975,0x1E76,0x3DBA,0x37BD), bn_pack4(0xC1D4,0xDCB2,0x6026,0x46DE), bn_pack4(0x36C3,0xFAB4,0xD27C,0x7026), bn_pack4(0x4DF4,0x35C9,0x3402,0x8492), bn_pack4(0x86FF,0xB7DC,0x90A6,0xC08F), bn_pack4(0x93B4,0xEA98,0x8D8F,0xDDC1), bn_pack4(0xD006,0x9127,0xD5B0,0x5AA9), bn_pack4(0xB81B,0xDD76,0x2170,0x481C), bn_pack4(0x1F61,0x2970,0xCEE2,0xD7AF), bn_pack4(0x233B,0xA186,0x515B,0xE7ED), bn_pack4(0x99B2,0x964F,0xA090,0xC3A2), bn_pack4(0x287C,0x5947,0x4E6B,0xC05D), bn_pack4(0x2E8E,0xFC14,0x1FBE,0xCAA6), bn_pack4(0xDBBB,0xC2DB,0x04DE,0x8EF9), bn_pack4(0x2583,0xE9CA,0x2AD4,0x4CE8), bn_pack4(0x1A94,0x6834,0xB615,0x0BDA), bn_pack4(0x99C3,0x2718,0x6AF4,0xE23C), bn_pack4(0x8871,0x9A10,0xBDBA,0x5B26), bn_pack4(0x1A72,0x3C12,0xA787,0xE6D7), bn_pack4(0x4B82,0xD120,0xA921,0x0801), bn_pack4(0x43DB,0x5BFC,0xE0FD,0x108E), bn_pack4(0x08E2,0x4FA0,0x74E5,0xAB31), bn_pack4(0x7709,0x88C0,0xBAD9,0x46E2), bn_pack4(0xBBE1,0x1757,0x7A61,0x5D6C), bn_pack4(0x521F,0x2B18,0x177B,0x200C), bn_pack4(0xD876,0x0273,0x3EC8,0x6A64), bn_pack4(0xF12F,0xFA06,0xD98A,0x0864), bn_pack4(0xCEE3,0xD226,0x1AD2,0xEE6B), bn_pack4(0x1E8C,0x94E0,0x4A25,0x619D), bn_pack4(0xABF5,0xAE8C,0xDB09,0x33D7), bn_pack4(0xB397,0x0F85,0xA6E1,0xE4C7), bn_pack4(0x8AEA,0x7157,0x5D06,0x0C7D), bn_pack4(0xECFB,0x8504,0x58DB,0xEF0A), bn_pack4(0xA855,0x21AB,0xDF1C,0xBA64), bn_pack4(0xAD33,0x170D,0x0450,0x7A33), bn_pack4(0x1572,0x8E5A,0x8AAA,0xC42D), bn_pack4(0x15D2,0x2618,0x98FA,0x0510), bn_pack4(0x3995,0x497C,0xEA95,0x6AE5), bn_pack4(0xDE2B,0xCBF6,0x9558,0x1718), bn_pack4(0xB5C5,0x5DF0,0x6F4C,0x52C9), bn_pack4(0x9B27,0x83A2,0xEC07,0xA28F), bn_pack4(0xE39E,0x772C,0x180E,0x8603), bn_pack4(0x3290,0x5E46,0x2E36,0xCE3B), bn_pack4(0xF174,0x6C08,0xCA18,0x217C), bn_pack4(0x670C,0x354E,0x4ABC,0x9804), bn_pack4(0x9ED5,0x2907,0x7096,0x966D), bn_pack4(0x1C62,0xF356,0x2085,0x52BB), bn_pack4(0x8365,0x5D23,0xDCA3,0xAD96), bn_pack4(0x6916,0x3FA8,0xFD24,0xCF5F), bn_pack4(0x98DA,0x4836,0x1C55,0xD39A), bn_pack4(0xC200,0x7CB8,0xA163,0xBF05), bn_pack4(0x4928,0x6651,0xECE4,0x5B3D), bn_pack4(0xAE9F,0x2411,0x7C4B,0x1FE6), bn_pack4(0xEE38,0x6BFB,0x5A89,0x9FA5), bn_pack4(0x0BFF,0x5CB6,0xF406,0xB7ED), bn_pack4(0xF44C,0x42E9,0xA637,0xED6B), bn_pack4(0xE485,0xB576,0x625E,0x7EC6), bn_pack4(0x4FE1,0x356D,0x6D51,0xC245), bn_pack4(0x302B,0x0A6D,0xF25F,0x1437), bn_pack4(0xEF95,0x19B3,0xCD3A,0x431B), bn_pack4(0x514A,0x0879,0x8E34,0x04DD), bn_pack4(0x020B,0xBEA6,0x3B13,0x9B22), bn_pack4(0x2902,0x4E08,0x8A67,0xCC74), bn_pack4(0xC4C6,0x628B,0x80DC,0x1CD1), bn_pack4(0xC90F,0xDAA2,0x2168,0xC234), bn_pack4(0xFFFF,0xFFFF,0xFFFF,0xFFFF) }; static BIGNUM bn_group_8192 = { bn_group_8192_value, (sizeof bn_group_8192_value)/sizeof(BN_ULONG), (sizeof bn_group_8192_value)/sizeof(BN_ULONG), 0, BN_FLG_STATIC_DATA }; static BN_ULONG bn_generator_19_value[] = {19} ; static BIGNUM bn_generator_19 = { bn_generator_19_value, 1, 1, 0, BN_FLG_STATIC_DATA }; static BN_ULONG bn_generator_5_value[] = {5} ; static BIGNUM bn_generator_5 = { bn_generator_5_value, 1, 1, 0, BN_FLG_STATIC_DATA }; static BN_ULONG bn_generator_2_value[] = {2} ; static BIGNUM bn_generator_2 = { bn_generator_2_value, 1, 1, 0, BN_FLG_STATIC_DATA }; static SRP_gN knowngN[] = { {"8192",&bn_generator_19 , &bn_group_8192}, {"6144",&bn_generator_5 , &bn_group_6144}, {"4096",&bn_generator_5 , &bn_group_4096}, {"3072",&bn_generator_5 , &bn_group_3072}, {"2048",&bn_generator_2 , &bn_group_2048}, {"1536",&bn_generator_2 , &bn_group_1536}, {"1024",&bn_generator_2 , &bn_group_1024}, }; #define KNOWN_GN_NUMBER sizeof(knowngN) / sizeof(SRP_gN) /* end of generated data */
/** * Make_Run * Initialize the nodes to remake and the list of nodes which are * ready to be made by doing a breadth-first traversal of the graph * starting from the nodes in the given list. Once this traversal * is finished, all the 'leaves' of the graph are in the toBeMade * queue. * Using this queue and the Job module, work back up the graph, * calling on MakeStartJobs to keep the job table as full as * possible. * * Results: * TRUE if work was done. FALSE otherwise. * * Side Effects: * The make field of all nodes involved in the creation of the given * targets is set to 1. The toBeMade list is set to contain all the * 'leaves' of these subgraphs. */ Boolean Make_Run(Lst *targs) { GNode *gn; GNode *cgn; Lst examine; int errors; LstNode *ln; Lst_Init(&examine); Lst_Duplicate(&examine, targs, NOCOPY); numNodes = 0; while (!Lst_IsEmpty(&examine)) { gn = Lst_DeQueue(&examine); if (!gn->make) { gn->make = TRUE; numNodes++; LST_FOREACH(ln, &gn->children) if (Make_HandleUse(Lst_Datum(ln), gn)) break; Suff_FindDeps(gn); if (gn->unmade != 0) { LST_FOREACH(ln, &gn->children) { cgn = Lst_Datum(ln); if (!cgn->make && !(cgn->type & OP_USE)) Lst_EnQueue(&examine, cgn); } } else { Lst_EnQueue(&toBeMade, gn); } } } if (queryFlag) { return (MakeStartJobs()); } else { MakeStartJobs(); } while (!Job_Empty()) { Job_CatchOutput(!Lst_IsEmpty(&toBeMade)); Job_CatchChildren(!usePipes); MakeStartJobs(); } errors = Job_Finish(); errors = ((errors == 0) && (numNodes != 0)); LST_FOREACH(ln, targs) MakePrintStatus(Lst_Datum(ln), errors); return (TRUE); }
/// Should not be used, since the actual length depends on the geometry. void SetActualLength(double actual_length) { if (actual_length > actual_length_) { SetPropagateStaticness(); } actual_length_ = actual_length; }
/* * Create a pv entry for page at pa for (pmap, va). If the page table page * holding the VA is managed, mpte will be non-NULL. */ static void pmap_insert_entry(pmap_t pmap, vm_offset_t va, vm_page_t mpte, vm_page_t m) { pv_entry_t pv; crit_enter(); pv = get_pv_entry(); pv->pv_va = va; pv->pv_pmap = pmap; pv->pv_ptem = mpte; TAILQ_INSERT_TAIL(&pmap->pm_pvlist, pv, pv_plist); TAILQ_INSERT_TAIL(&m->md.pv_list, pv, pv_list); m->md.pv_list_count++; atomic_add_int(&m->object->agg_pv_list_count, 1); crit_exit(); }
/** * @brief Set codec ADC gain. * @param ad_gain_left: ADC left channel digital volume gain * This parameter can be one of the following values: * @arg 7'h00: -17.625dB * @arg ... * @arg 7'h2f: 0dB * @arg 7'h30: 0.375dB * @arg ... * @arg 7'h7f: 30dB * @param ad_gain_right: ADC right channel digital volume gain * This parameter can be one of the following values: * @arg 7'h00: -17.625dB * @arg ... * @arg 7'h2f: 0dB * @arg 7'h30: 0.375dB * @arg ... * @arg 7'h7f: 30dB * @note ADC digital volume is -17.625dB~+30dB in 0.375 dB step. * @return None */ void CODEC_SetAdcGain(u32 ad_gain_left, u32 ad_gain_right) { u32 reg_value = 0; reg_value = AUDIO_SI_ReadReg(0x13); reg_value &= ~0x1fc0; reg_value |= (ad_gain_left << 6); AUDIO_SI_WriteReg(0x13, reg_value); reg_value = AUDIO_SI_ReadReg(0x16); reg_value &= ~0x1fc0; reg_value |= (ad_gain_right << 6); AUDIO_SI_WriteReg(0x16, reg_value); }
main(a,b){scanf("%d%d",&a,&b);puts(a<b?"0":"10");}
// we will simply fix the broken _snprintf. In VC, it will not null terminate buffers that get // truncated, AND the return is - if we truncate. We fix both of these issues, and bring snprintf // for VC up to C99 standard. int vc_fixed_snprintf(char *Dest, size_t max_cnt, const char *Fmt, ...) { va_list varg; int len; va_start(varg, Fmt); len = _vsnprintf(Dest, max_cnt, Fmt, varg); if (len < 0) { int len_now = max_cnt; Dest[max_cnt-1] = 0; while (len < 0) { char *cp; len_now *= 2; cp = (char*)malloc(len_now); len = _vsnprintf(cp, len_now, Fmt, varg); free(cp); } } va_end(varg); return len; }
/* * Copyright 1997, Regents of the University of Minnesota * * mincover.c * * This file implements the minimum cover algorithm * * Started 8/1/97 * George * * $Id: mincover.c,v 1.1 1998/11/27 17:59:22 karypis Exp $ */ #include <metis.h> /************************************************************************* * Constants used by mincover algorithm **************************************************************************/ #define INCOL 10 #define INROW 20 #define VC 1 #define SC 2 #define HC 3 #define VR 4 #define SR 5 #define HR 6 /************************************************************************* * This function returns the min-cover of a bipartite graph. * The algorithm used is due to Hopcroft and Karp as modified by Duff etal * adj: the adjacency list of the bipartite graph * asize: the number of vertices in the first part of the bipartite graph * bsize-asize: the number of vertices in the second part * 0..(asize-1) > A vertices * asize..bsize > B vertices * * Returns: * cover : the actual cover (array) * csize : the size of the cover **************************************************************************/ void MinCover(idxtype *xadj, idxtype *adjncy, int asize, int bsize, idxtype *cover, int *csize) { int i, j; idxtype *mate, *queue, *flag, *level, *lst; int fptr, rptr, lstptr; int row, maxlevel, col; mate = idxsmalloc(bsize, -1, "MinCover: mate"); flag = idxmalloc(bsize, "MinCover: flag"); level = idxmalloc(bsize, "MinCover: level"); queue = idxmalloc(bsize, "MinCover: queue"); lst = idxmalloc(bsize, "MinCover: lst"); /* Get a cheap matching */ for (i=0; i<asize; i++) { for (j=xadj[i]; j<xadj[i+1]; j++) { if (mate[adjncy[j]] == -1) { mate[i] = adjncy[j]; mate[adjncy[j]] = i; break; } } } /* Get into the main loop */ while (1) { /* Initialization */ fptr = rptr = 0; /* Empty Queue */ lstptr = 0; /* Empty List */ for (i=0; i<bsize; i++) { level[i] = -1; flag[i] = 0; } maxlevel = bsize; /* Insert free nodes into the queue */ for (i=0; i<asize; i++) if (mate[i] == -1) { queue[rptr++] = i; level[i] = 0; } /* Perform the BFS */ while (fptr != rptr) { row = queue[fptr++]; if (level[row] < maxlevel) { flag[row] = 1; for (j=xadj[row]; j<xadj[row+1]; j++) { col = adjncy[j]; if (!flag[col]) { /* If this column has not been accessed yet */ flag[col] = 1; if (mate[col] == -1) { /* Free column node was found */ maxlevel = level[row]; lst[lstptr++] = col; } else { /* This column node is matched */ if (flag[mate[col]]) printf("\nSomething wrong, flag[%d] is 1",mate[col]); queue[rptr++] = mate[col]; level[mate[col]] = level[row] + 1; } } } } } if (lstptr == 0) break; /* No free columns can be reached */ /* Perform restricted DFS from the free column nodes */ for (i=0; i<lstptr; i++) MinCover_Augment(xadj, adjncy, lst[i], mate, flag, level, maxlevel); } MinCover_Decompose(xadj, adjncy, asize, bsize, mate, cover, csize); GKfree(&mate, &flag, &level, &queue, &lst, LTERM); } /************************************************************************* * This function perfoms a restricted DFS and augments matchings **************************************************************************/ int MinCover_Augment(idxtype *xadj, idxtype *adjncy, int col, idxtype *mate, idxtype *flag, idxtype *level, int maxlevel) { int i; int row = -1; int status; flag[col] = 2; for (i=xadj[col]; i<xadj[col+1]; i++) { row = adjncy[i]; if (flag[row] == 1) { /* First time through this row node */ if (level[row] == maxlevel) { /* (col, row) is an edge of the G^T */ flag[row] = 2; /* Mark this node as being visited */ if (maxlevel != 0) status = MinCover_Augment(xadj, adjncy, mate[row], mate, flag, level, maxlevel-1); else status = 1; if (status) { mate[col] = row; mate[row] = col; return 1; } } } } return 0; } /************************************************************************* * This function performs a coarse decomposition and determines the * min-cover. * REF: Pothen ACMTrans. on Amth Software **************************************************************************/ void MinCover_Decompose(idxtype *xadj, idxtype *adjncy, int asize, int bsize, idxtype *mate, idxtype *cover, int *csize) { int i, k; idxtype *where; int card[10]; where = idxmalloc(bsize, "MinCover_Decompose: where"); for (i=0; i<10; i++) card[i] = 0; for (i=0; i<asize; i++) where[i] = SC; for (; i<bsize; i++) where[i] = SR; for (i=0; i<asize; i++) if (mate[i] == -1) MinCover_ColDFS(xadj, adjncy, i, mate, where, INCOL); for (; i<bsize; i++) if (mate[i] == -1) MinCover_RowDFS(xadj, adjncy, i, mate, where, INROW); for (i=0; i<bsize; i++) card[where[i]]++; k = 0; if (abs(card[VC]+card[SC]-card[HR]) < abs(card[VC]-card[SR]-card[HR])) { /* S = VC+SC+HR */ /* printf("%d %d ",vc+sc, hr); */ for (i=0; i<bsize; i++) if (where[i] == VC || where[i] == SC || where[i] == HR) cover[k++] = i; } else { /* S = VC+SR+HR */ /* printf("%d %d ",vc, hr+sr); */ for (i=0; i<bsize; i++) if (where[i] == VC || where[i] == SR || where[i] == HR) cover[k++] = i; } *csize = k; free(where); } /************************************************************************* * This function perfoms a dfs starting from an unmatched col node * forming alternate paths **************************************************************************/ void MinCover_ColDFS(idxtype *xadj, idxtype *adjncy, int root, idxtype *mate, idxtype *where, int flag) { int i; if (flag == INCOL) { if (where[root] == HC) return; where[root] = HC; for (i=xadj[root]; i<xadj[root+1]; i++) MinCover_ColDFS(xadj, adjncy, adjncy[i], mate, where, INROW); } else { if (where[root] == HR) return; where[root] = HR; if (mate[root] != -1) MinCover_ColDFS(xadj, adjncy, mate[root], mate, where, INCOL); } } /************************************************************************* * This function perfoms a dfs starting from an unmatched col node * forming alternate paths **************************************************************************/ void MinCover_RowDFS(idxtype *xadj, idxtype *adjncy, int root, idxtype *mate, idxtype *where, int flag) { int i; if (flag == INROW) { if (where[root] == VR) return; where[root] = VR; for (i=xadj[root]; i<xadj[root+1]; i++) MinCover_RowDFS(xadj, adjncy, adjncy[i], mate, where, INCOL); } else { if (where[root] == VC) return; where[root] = VC; if (mate[root] != -1) MinCover_RowDFS(xadj, adjncy, mate[root], mate, where, INROW); } }
/* * We supply this function for the msg module */ const char * _cap_msg(Msg mid) { return (gettext(MSG_ORIG(mid))); }
/** * Procedure for MPLS tunnel configuration. * INPUT: * mpls_tunnel - mpls tunnel data * Note * By default, code is assumed to occupy GLEM entries only when * necessary (and not just when it does no harm). */ int vpls_create_mpls_tunnel( int unit, mpls_tunnel_initiator_create_s * mpls_tunnel) { bcm_mpls_egress_label_t label_array[2]; int rv, i, ii; char *proc_name; char *occupy_glem; proc_name = "vpls_create_mpls_tunnel"; bcm_mpls_egress_label_t_init(&label_array[0]); for (i = MAX_NOF_TUNNELS - 1; i >= 0; i--) { if ((mpls_tunnel[i].label[0] >= MIN_LABEL) && (mpls_tunnel[i].label[0] <= MAX_LABEL)) { label_array[0].label = mpls_tunnel[i].label[0]; label_array[0].flags = mpls_tunnel[i].flags; label_array[0].flags2 = mpls_tunnel[i].flags2; BCM_L3_ITF_SET(label_array[0].tunnel_id, BCM_L3_ITF_TYPE_LIF, mpls_tunnel[i].tunnel_id); label_array[0].l3_intf_id = mpls_tunnel[i].l3_intf_id; label_array[0].action = mpls_tunnel[i].action; label_array[0].encap_access = mpls_tunnel[i].encap_access; label_array[0].qos_map_id = mpls_tunnel[i].qos_map_id; label_array[0].exp = mpls_tunnel[i].exp; label_array[0].egress_qos_model.egress_qos = mpls_tunnel->egress_qos_model.egress_qos; label_array[0].egress_qos_model.egress_ttl = mpls_tunnel->egress_qos_model.egress_ttl; label_array[1].label = mpls_tunnel[i].label[1]; label_array[1].flags = mpls_tunnel[i].flags; BCM_L3_ITF_SET(label_array[1].tunnel_id, BCM_L3_ITF_TYPE_LIF, mpls_tunnel[i].tunnel_id); label_array[1].l3_intf_id = mpls_tunnel[i].l3_intf_id; label_array[1].action = mpls_tunnel[i].action; label_array[1].encap_access = mpls_tunnel[i].encap_access; label_array[1].qos_map_id = mpls_tunnel[i].qos_map_id; label_array[1].egress_qos_model.egress_qos = mpls_tunnel->egress_qos_model.egress_qos; label_array[1].egress_qos_model.egress_ttl = mpls_tunnel->egress_qos_model.egress_ttl; occupy_glem = "YES"; if (i != 0) { label_array[0].flags |= BCM_MPLS_EGRESS_LABEL_VIRTUAL_EGRESS_POINTED; occupy_glem = "NO"; } else { label_array[0].flags &= ~BCM_MPLS_EGRESS_LABEL_VIRTUAL_EGRESS_POINTED; occupy_glem = "YES"; } rv = bcm_mpls_tunnel_initiator_create(unit, 0, mpls_tunnel[i].num_labels, label_array); if (rv != BCM_E_NONE) { printf("%s(): Error, in bcm_mpls_tunnel_initiator_create\n", proc_name); return rv; } mpls_tunnel[i].tunnel_id = label_array[0].tunnel_id; if (i != 0) { mpls_tunnel[i - 1].l3_intf_id = mpls_tunnel[i].tunnel_id; } if(vpls_util_verbose == 1) { printf("%s(): i = %d, label_1 = 0x%x, label_2 = 0x%x, occupy_glem = %s, l3_intf_id = 0x%08X, tunnel_id 0x%08X, flags = 0x%08X\n", proc_name, i, label_array[0].label, label_array[1].label, occupy_glem, label_array[0].l3_intf_id, label_array[0].tunnel_id, label_array[0].flags); } } } return rv; }
// the angle facing the across edge double farAngle() { return angle(t->vtx[mod3(o+1)]->pt, t->vtx[o]->pt, t->vtx[mod3(o+2)]->pt); }
/* *-------------------------------------------------------------------------- * * _mongoc_cluster_auth_node_plain -- * * Perform SASL PLAIN authentication for @node. We do this manually * instead of using the SASL module because its rather simplistic. * * Returns: * true if successful; otherwise false and error is set. * * Side effects: * error may be set. * *-------------------------------------------------------------------------- */ static bool _mongoc_cluster_auth_node_plain (mongoc_cluster_t *cluster, mongoc_stream_t *stream, bson_error_t *error) { mongoc_cmd_parts_t parts; char buf[4096]; int buflen = 0; const char *username; const char *password; bson_t b = BSON_INITIALIZER; bson_t reply; size_t len; char *str; bool ret; BSON_ASSERT (cluster); BSON_ASSERT (stream); username = mongoc_uri_get_username (cluster->uri); if (!username) { username = ""; } password = mongoc_uri_get_password (cluster->uri); if (!password) { password = ""; } str = bson_strdup_printf ("%c%s%c%s", '\0', username, '\0', password); len = strlen (username) + strlen (password) + 2; buflen = mongoc_b64_ntop ((const uint8_t *) str, len, buf, sizeof buf); bson_free (str); if (buflen == -1) { bson_set_error (error, MONGOC_ERROR_CLIENT, MONGOC_ERROR_CLIENT_AUTHENTICATE, "failed base64 encoding message"); return false; } BSON_APPEND_INT32 (&b, "saslStart", 1); BSON_APPEND_UTF8 (&b, "mechanism", "PLAIN"); bson_append_utf8 (&b, "payload", 7, (const char *) buf, buflen); BSON_APPEND_INT32 (&b, "autoAuthorize", 1); mongoc_cmd_parts_init (&parts, "$external", MONGOC_QUERY_SLAVE_OK, &b); ret = mongoc_cluster_run_command_private ( cluster, &parts, stream, 0, &reply, error); if (!ret) { error->domain = MONGOC_ERROR_CLIENT; error->code = MONGOC_ERROR_CLIENT_AUTHENTICATE; } mongoc_cmd_parts_cleanup (&parts); bson_destroy (&b); bson_destroy (&reply); return ret; }
/* * Tune RF RX sensitivity based on the number of false alarms detected * during the last beacon period. */ static void iwn_tune_sensitivity(struct iwn_softc *sc, const struct iwn_rx_stats *stats) { #define inc(val, inc, max) \ if ((val) < (max)) { \ if ((val) < (max) - (inc)) \ (val) += (inc); \ else \ (val) = (max); \ needs_update = 1; \ } #define dec(val, dec, min) \ if ((val) > (min)) { \ if ((val) > (min) + (dec)) \ (val) -= (dec); \ else \ (val) = (min); \ needs_update = 1; \ } const struct iwn_sensitivity_limits *limits = sc->limits; struct iwn_calib_state *calib = &sc->calib; uint32_t val, rxena, fa; uint32_t energy[3], energy_min; uint8_t noise[3], noise_ref; int i, needs_update = 0; if ((rxena = le32toh(stats->general.load)) == 0) return; fa = le32toh(stats->ofdm.bad_plcp) - calib->bad_plcp_ofdm; fa += le32toh(stats->ofdm.fa) - calib->fa_ofdm; fa *= 200 * 1024; calib->bad_plcp_ofdm = le32toh(stats->ofdm.bad_plcp); calib->fa_ofdm = le32toh(stats->ofdm.fa); if (fa > 50 * rxena) { IWN_DBG("OFDM high false alarm count: %u", fa); inc(calib->ofdm_x1, 1, limits->max_ofdm_x1); inc(calib->ofdm_mrc_x1, 1, limits->max_ofdm_mrc_x1); inc(calib->ofdm_x4, 1, limits->max_ofdm_x4); inc(calib->ofdm_mrc_x4, 1, limits->max_ofdm_mrc_x4); } else if (fa < 5 * rxena) { IWN_DBG("OFDM low false alarm count: %u", fa); dec(calib->ofdm_x1, 1, limits->min_ofdm_x1); dec(calib->ofdm_mrc_x1, 1, limits->min_ofdm_mrc_x1); dec(calib->ofdm_x4, 1, limits->min_ofdm_x4); dec(calib->ofdm_mrc_x4, 1, limits->min_ofdm_mrc_x4); } for (i = 0; i < 3; i++) noise[i] = (le32toh(stats->general.noise[i]) >> 8) & 0xff; val = MAX(noise[0], noise[1]); val = MAX(noise[2], val); calib->noise_samples[calib->cur_noise_sample] = (uint8_t)val; calib->cur_noise_sample = (calib->cur_noise_sample + 1) % 20; noise_ref = calib->noise_samples[0]; for (i = 1; i < 20; i++) noise_ref = MAX(noise_ref, calib->noise_samples[i]); for (i = 0; i < 3; i++) energy[i] = le32toh(stats->general.energy[i]); val = MIN(energy[0], energy[1]); val = MIN(energy[2], val); calib->energy_samples[calib->cur_energy_sample] = val; calib->cur_energy_sample = (calib->cur_energy_sample + 1) % 10; energy_min = calib->energy_samples[0]; for (i = 1; i < 10; i++) energy_min = MAX(energy_min, calib->energy_samples[i]); energy_min += 6; fa = le32toh(stats->cck.bad_plcp) - calib->bad_plcp_cck; fa += le32toh(stats->cck.fa) - calib->fa_cck; fa *= 200 * 1024; calib->bad_plcp_cck = le32toh(stats->cck.bad_plcp); calib->fa_cck = le32toh(stats->cck.fa); if (fa > 50 * rxena) { IWN_DBG("CCK high false alarm count: %u", fa); calib->cck_state = IWN_CCK_STATE_HIFA; calib->low_fa = 0; if (calib->cck_x4 > 160) { calib->noise_ref = noise_ref; if (calib->energy_cck > 2) dec(calib->energy_cck, 2, energy_min); } if (calib->cck_x4 < 160) { calib->cck_x4 = 161; needs_update = 1; } else inc(calib->cck_x4, 3, limits->max_cck_x4); inc(calib->cck_mrc_x4, 3, limits->max_cck_mrc_x4); } else if (fa < 5 * rxena) { IWN_DBG("CCK low false alarm count: %u", fa); calib->cck_state = IWN_CCK_STATE_LOFA; calib->low_fa++; if (calib->cck_state != IWN_CCK_STATE_INIT && (((int32_t)calib->noise_ref - (int32_t)noise_ref) > 2 || calib->low_fa > 100)) { inc(calib->energy_cck, 2, limits->min_energy_cck); dec(calib->cck_x4, 3, limits->min_cck_x4); dec(calib->cck_mrc_x4, 3, limits->min_cck_mrc_x4); } } else { IWN_DBG("CCK normal false alarm count: %u", fa); calib->low_fa = 0; calib->noise_ref = noise_ref; if (calib->cck_state == IWN_CCK_STATE_HIFA) { dec(calib->energy_cck, 8, energy_min); } calib->cck_state = IWN_CCK_STATE_INIT; } if (needs_update) (void)iwn_send_sensitivity(sc); #undef dec #undef inc }
/* Fast-ageing of ARL entries for a given port, equivalent to an ARL * flush for that port. */ static int bcm_sf2_sw_fast_age_port(struct dsa_switch *ds, int port) { struct bcm_sf2_priv *priv = ds_to_priv(ds); unsigned int timeout = 1000; u32 reg; core_writel(priv, port, CORE_FAST_AGE_PORT); reg = core_readl(priv, CORE_FAST_AGE_CTRL); reg |= EN_AGE_PORT | EN_AGE_DYNAMIC | FAST_AGE_STR_DONE; core_writel(priv, reg, CORE_FAST_AGE_CTRL); do { reg = core_readl(priv, CORE_FAST_AGE_CTRL); if (!(reg & FAST_AGE_STR_DONE)) break; cpu_relax(); } while (timeout--); if (!timeout) return -ETIMEDOUT; core_writel(priv, 0, CORE_FAST_AGE_CTRL); return 0; }
/****************************************************************************** * * Copyright(c) 2013 Realtek Corporation. All rights reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * 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. * ******************************************************************************/ #ifndef __RTW_ODM_H__ #define __RTW_ODM_H__ #include <drv_types.h> /* * This file provides utilities/wrappers for rtw driver to use ODM */ void rtw_odm_dbg_comp_msg(void *sel, struct adapter *adapter); void rtw_odm_dbg_comp_set(struct adapter *adapter, u64 comps); void rtw_odm_dbg_level_msg(void *sel, struct adapter *adapter); void rtw_odm_dbg_level_set(struct adapter *adapter, u32 level); void rtw_odm_ability_msg(void *sel, struct adapter *adapter); void rtw_odm_ability_set(struct adapter *adapter, u32 ability); void rtw_odm_adaptivity_parm_msg(void *sel, struct adapter *adapter); void rtw_odm_adaptivity_parm_set(struct adapter *adapter, s8 TH_L2H_ini, s8 TH_EDCCA_HL_diff, s8 IGI_Base, bool ForceEDCCA, u8 AdapEn_RSSI, u8 IGI_LowerBound); void rtw_odm_get_perpkt_rssi(void *sel, struct adapter *adapter); #endif /* __RTW_ODM_H__ */
// SPDX-License-Identifier: BSD-3-Clause /* Copyright 2015-2020, Intel Corporation */ /* * ulog.h -- unified log public interface */ #ifndef LIBPMEMOBJ_ULOG_H #define LIBPMEMOBJ_ULOG_H 1 #include <stddef.h> #include <stdint.h> #include <time.h> #include "vec.h" #include "pmemops.h" #include<x86intrin.h> ////cmd write optimization /* struct ulog_cmd_packet{ uint32_t ulog_offset : 32; uint32_t base_offset : 32; uint32_t src : 32; uint32_t size : 32; }; */ struct ulog_entry_base { uint64_t offset; /* offset with operation type flag */ }; /* * ulog_entry_val -- log entry */ struct ulog_entry_val { struct ulog_entry_base base; uint64_t value; /* value to be applied */ }; /* * ulog_entry_buf - ulog buffer entry */ struct ulog_entry_buf { struct ulog_entry_base base; /* offset with operation type flag */ uint64_t checksum; /* checksum of the entire log entry */ uint64_t size; /* size of the buffer to be modified */ uint8_t data[]; /* content to fill in */ }; #define ULOG_UNUSED ((CACHELINE_SIZE - 40) / 8) /* * This structure *must* be located at a cacheline boundary. To achieve this, * the next field is always allocated with extra padding, and then the offset * is additionally aligned. */ #define ULOG(capacity_bytes) {\ /* 64 bytes of metadata */\ uint64_t checksum; /* checksum of ulog header and its entries */\ uint64_t next; /* offset of ulog extension */\ uint64_t capacity; /* capacity of this ulog in bytes */\ uint64_t gen_num; /* generation counter */\ uint64_t flags; /* ulog flags */\ uint64_t unused[ULOG_UNUSED]; /* must be 0 */\ uint8_t data[capacity_bytes]; /* N bytes of data */\ }\ #define SIZEOF_ULOG(base_capacity)\ (sizeof(struct ulog) + base_capacity) /* * Ulog buffer allocated by the user must be marked by this flag. * It is important to not free it at the end: * what user has allocated - user should free himself. */ #define ULOG_USER_OWNED (1U << 0) /* use this for allocations of aligned ulog extensions */ #define SIZEOF_ALIGNED_ULOG(base_capacity)\ ALIGN_UP(SIZEOF_ULOG(base_capacity + (2 * CACHELINE_SIZE)), CACHELINE_SIZE) struct ulog ULOG(0); VEC(ulog_next, uint64_t); typedef uint64_t ulog_operation_type; #define ULOG_OPERATION_SET (0b000ULL << 61ULL) #define ULOG_OPERATION_AND (0b001ULL << 61ULL) #define ULOG_OPERATION_OR (0b010ULL << 61ULL) #define ULOG_OPERATION_BUF_SET (0b101ULL << 61ULL) #define ULOG_OPERATION_BUF_CPY (0b110ULL << 61ULL) #define ULOG_BIT_OPERATIONS (ULOG_OPERATION_AND | ULOG_OPERATION_OR) /* immediately frees all associated ulog structures */ #define ULOG_FREE_AFTER_FIRST (1U << 0) /* increments gen_num of the first, preallocated, ulog */ #define ULOG_INC_FIRST_GEN_NUM (1U << 1) /* informs if there was any buffer allocated by user in the tx */ #define ULOG_ANY_USER_BUFFER (1U << 2) typedef int (*ulog_check_offset_fn)(void *ctx, uint64_t offset); typedef int (*ulog_extend_fn)(void *, uint64_t *, uint64_t); typedef int (*ulog_entry_cb)(struct ulog_entry_base *e, void *arg, const struct pmem_ops *p_ops); typedef int (*ulog_entry_cb_ndp)(struct ulog_entry_base *e, struct ulog_entry_base *f, void *arg, const struct pmem_ops *p_ops); typedef void (*ulog_free_fn)(void *base, uint64_t *next); typedef int (*ulog_rm_user_buffer_fn)(void *, void *addr); struct ulog *ulog_next(struct ulog *ulog, const struct pmem_ops *p_ops); void ulog_construct(uint64_t offset, size_t capacity, uint64_t gen_num, int flush, uint64_t flags, const struct pmem_ops *p_ops); size_t ulog_capacity(struct ulog *ulog, size_t ulog_base_bytes, const struct pmem_ops *p_ops); void ulog_rebuild_next_vec(struct ulog *ulog, struct ulog_next *next, const struct pmem_ops *p_ops); int ulog_foreach_entry(struct ulog *ulog, ulog_entry_cb cb, void *arg, const struct pmem_ops *ops, struct ulog *ulognvm); int ulog_foreach_entry_ndp(struct ulog *ulogdram, struct ulog *ulognvm, ulog_entry_cb_ndp cb, void *arg, const struct pmem_ops *ops); int ulog_reserve(struct ulog *ulog, size_t ulog_base_nbytes, size_t gen_num, int auto_reserve, size_t *new_capacity_bytes, ulog_extend_fn extend, struct ulog_next *next, const struct pmem_ops *p_ops); void ulog_store(struct ulog *dest, struct ulog *src, size_t nbytes, size_t ulog_base_nbytes, size_t ulog_total_capacity, struct ulog_next *next, const struct pmem_ops *p_ops); int ulog_free_next(struct ulog *u, const struct pmem_ops *p_ops, ulog_free_fn ulog_free, ulog_rm_user_buffer_fn user_buff_remove, uint64_t flags); void ulog_clobber(struct ulog *dest, struct ulog_next *next, const struct pmem_ops *p_ops); int ulog_clobber_data(struct ulog *dest, size_t nbytes, size_t ulog_base_nbytes, struct ulog_next *next, ulog_free_fn ulog_free, ulog_rm_user_buffer_fn user_buff_remove, const struct pmem_ops *p_ops, unsigned flags); void ulog_clobber_entry(const struct ulog_entry_base *e, const struct pmem_ops *p_ops); void ulog_process(struct ulog *ulog, ulog_check_offset_fn check, const struct pmem_ops *p_ops); void ulog_process_ndp(struct ulog *ulognvm, struct ulog *ulogdeam, ulog_check_offset_fn check, const struct pmem_ops *p_ops); size_t ulog_base_nbytes(struct ulog *ulog); int ulog_recovery_needed(struct ulog *ulog, int verify_checksum); struct ulog *ulog_by_offset(size_t offset, const struct pmem_ops *p_ops); uint64_t ulog_entry_offset(const struct ulog_entry_base *entry); ulog_operation_type ulog_entry_type( const struct ulog_entry_base *entry); struct ulog_entry_val *ulog_entry_val_create(struct ulog *ulog, size_t offset, uint64_t *dest, uint64_t value, ulog_operation_type type, const struct pmem_ops *p_ops); #ifdef USE_NDP_CLOBBER struct ulog_entry_buf * ulog_entry_buf_create(struct ulog *ulog, size_t offset, uint64_t gen_num, uint64_t *dest, const void *src, uint64_t size, ulog_operation_type type, const struct pmem_ops *p_ops, int clear_next_header); #else struct ulog_entry_buf * ulog_entry_buf_create(struct ulog *ulog, size_t offset, uint64_t gen_num, uint64_t *dest, const void *src, uint64_t size, ulog_operation_type type, const struct pmem_ops *p_ops); #endif void ulog_entry_apply(const struct ulog_entry_base *e, int persist, const struct pmem_ops *p_ops); void ulog_entry_apply_ndp(const struct ulog_entry_base *e, const struct ulog_entry_base *f, int persist, const struct pmem_ops *p_ops); size_t ulog_entry_size(const struct ulog_entry_base *entry); void ulog_recover(struct ulog *ulog, ulog_check_offset_fn check, const struct pmem_ops *p_ops); int ulog_check(struct ulog *ulog, ulog_check_offset_fn check, const struct pmem_ops *p_ops); #endif
/*********************** * isPacketToBeFiltered() * * Inspect a receved packet and check whether it need to be filtered * * Arguments : * pkt - INPUT. pointer to the packet buffer. * pktLen - INPUT. leghth of packet. * * Return: * EDPAT_TRUE - packet need to be filtered/discarded * EDPAT_FALSE - packet should not be filtered * ********/ static EDPAT_BOOL isPacketToBeFiltered(unsigned char *pkt,int pktLen) { unsigned short ethType; unsigned short srcPort; unsigned short dstPort; if (EDPAT_TRUE != EnableBroadcastPacketFiltering) { return EDPAT_FALSE; } ethType = ((pkt[12] << 8) | pkt[13]); switch(ethType) { case 0x0806: VerboseStringPrint( "Received ARP packet filtered"); return EDPAT_TRUE; case 0x88CC: VerboseStringPrint( "Received LLDP packet filtered"); return EDPAT_TRUE; case 0x0800: switch(pkt[23]) { case 0x02: VerboseStringPrint( "Received IGMP packet filtered"); return EDPAT_TRUE; case 0x11: srcPort = ((pkt[34] << 8) | pkt[35]); dstPort = ((pkt[36] << 8) | pkt[37]); switch(srcPort) { case 0x0043: case 0x0044: VerboseStringPrint( "Received DHCP packet filtered"); return EDPAT_TRUE; case 0xd7e8: case 0x076c: VerboseStringPrint( "Received SSDP packet filtered"); return EDPAT_TRUE; case 0x14e9: VerboseStringPrint( "Received MDNS packet filtered"); return EDPAT_TRUE; } switch(dstPort) { case 0x0043: case 0x0044: VerboseStringPrint( "Received DHCP packet filtered"); return EDPAT_TRUE; case 0xd7e8: case 0x076c: VerboseStringPrint( "Received SSDP packet filtered"); return EDPAT_TRUE; case 0x14e9: VerboseStringPrint( "Received MDNS packet filtered"); return EDPAT_TRUE; } } break; case 0x86dd: VerboseStringPrint("Received IPv6 packet filtered"); return EDPAT_TRUE; } return EDPAT_FALSE; }
/* * Remove storage for the widget's title. */ void cleanCdkTitle (CDKOBJS *obj) { if (obj != 0) { CDKfreeChtypes (obj->title); obj->title = 0; freeAndNull (obj->titlePos); freeAndNull (obj->titleLen); obj->titleLines = 0; } }
// SPDX-License-Identifier: GPL-2.0+ /* * (C) Copyright 2015 - 2016 Xilinx, Inc. * Michal Simek <michal.simek@xilinx.com> */ #include <common.h> #include <dm.h> #include <ahci.h> #include <generic-phy.h> #include <log.h> #include <reset.h> #include <scsi.h> #include <asm/io.h> #include <dm/device_compat.h> #include <linux/ioport.h> /* Vendor Specific Register Offsets */ #define AHCI_VEND_PCFG 0xA4 #define AHCI_VEND_PPCFG 0xA8 #define AHCI_VEND_PP2C 0xAC #define AHCI_VEND_PP3C 0xB0 #define AHCI_VEND_PP4C 0xB4 #define AHCI_VEND_PP5C 0xB8 #define AHCI_VEND_AXICC 0xBc #define AHCI_VEND_PAXIC 0xC0 #define AHCI_VEND_PTC 0xC8 /* Vendor Specific Register bit definitions */ #define PAXIC_ADBW_BW64 0x1 #define PAXIC_MAWIDD (1 << 8) #define PAXIC_MARIDD (1 << 16) #define PAXIC_OTL (0x4 << 20) #define PCFG_TPSS_VAL (0x32 << 16) #define PCFG_TPRS_VAL (0x2 << 12) #define PCFG_PAD_VAL 0x2 #define PPCFG_TTA 0x1FFFE #define PPCFG_PSSO_EN (1 << 28) #define PPCFG_PSS_EN (1 << 29) #define PPCFG_ESDF_EN (1 << 31) #define PP2C_CIBGMN 0x0F #define PP2C_CIBGMX (0x25 << 8) #define PP2C_CIBGN (0x18 << 16) #define PP2C_CINMP (0x29 << 24) #define PP3C_CWBGMN 0x04 #define PP3C_CWBGMX (0x0B << 8) #define PP3C_CWBGN (0x08 << 16) #define PP3C_CWNMP (0x0F << 24) #define PP4C_BMX 0x0a #define PP4C_BNM (0x08 << 8) #define PP4C_SFD (0x4a << 16) #define PP4C_PTST (0x06 << 24) #define PP5C_RIT 0x60216 #define PP5C_RCT (0x7f0 << 20) #define PTC_RX_WM_VAL 0x40 #define PTC_RSVD (1 << 27) #define PORT0_BASE 0x100 #define PORT1_BASE 0x180 /* Port Control Register Bit Definitions */ #define PORT_SCTL_SPD_GEN3 (0x3 << 4) #define PORT_SCTL_SPD_GEN2 (0x2 << 4) #define PORT_SCTL_SPD_GEN1 (0x1 << 4) #define PORT_SCTL_IPM (0x3 << 8) #define PORT_BASE 0x100 #define PORT_OFFSET 0x80 #define NR_PORTS 2 #define DRV_NAME "ahci-ceva" #define CEVA_FLAG_BROKEN_GEN2 1 /* flag bit definition */ #define FLAG_COHERENT 1 /* register config value */ #define CEVA_PHY1_CFG 0xa003fffe #define CEVA_PHY2_CFG 0x28184d1f #define CEVA_PHY3_CFG 0x0e081509 #define CEVA_TRANS_CFG 0x08000029 #define CEVA_AXICC_CFG 0x3fffffff /* for ls1021a */ #define LS1021_AHCI_VEND_AXICC 0xC0 #define LS1021_CEVA_PHY2_CFG 0x28183414 #define LS1021_CEVA_PHY3_CFG 0x0e080e06 #define LS1021_CEVA_PHY4_CFG 0x064a080b #define LS1021_CEVA_PHY5_CFG 0x2aa86470 /* ecc val pair */ #define ECC_DIS_VAL_CH1 0x00020000 #define ECC_DIS_VAL_CH2 0x80000000 #define ECC_DIS_VAL_CH3 0x40000000 enum ceva_soc { CEVA_1V84, CEVA_LS1012A, CEVA_LS1021A, CEVA_LS1028A, CEVA_LS1043A, CEVA_LS1046A, CEVA_LS1088A, CEVA_LS2080A, }; struct ceva_sata_priv { ulong base; ulong ecc_base; enum ceva_soc soc; ulong flag; }; static int ceva_init_sata(struct ceva_sata_priv *priv) { ulong ecc_addr = priv->ecc_base; ulong base = priv->base; ulong tmp; switch (priv->soc) { case CEVA_1V84: tmp = PAXIC_ADBW_BW64 | PAXIC_MAWIDD | PAXIC_MARIDD | PAXIC_OTL; writel(tmp, base + AHCI_VEND_PAXIC); tmp = PCFG_TPSS_VAL | PCFG_TPRS_VAL | PCFG_PAD_VAL; writel(tmp, base + AHCI_VEND_PCFG); tmp = PPCFG_TTA | PPCFG_PSS_EN | PPCFG_ESDF_EN; writel(tmp, base + AHCI_VEND_PPCFG); tmp = PTC_RX_WM_VAL | PTC_RSVD; writel(tmp, base + AHCI_VEND_PTC); break; case CEVA_LS1021A: if (!ecc_addr) return -EINVAL; writel(ECC_DIS_VAL_CH1, ecc_addr); writel(CEVA_PHY1_CFG, base + AHCI_VEND_PPCFG); writel(LS1021_CEVA_PHY2_CFG, base + AHCI_VEND_PP2C); writel(LS1021_CEVA_PHY3_CFG, base + AHCI_VEND_PP3C); writel(LS1021_CEVA_PHY4_CFG, base + AHCI_VEND_PP4C); writel(LS1021_CEVA_PHY5_CFG, base + AHCI_VEND_PP5C); writel(CEVA_TRANS_CFG, base + AHCI_VEND_PTC); break; case CEVA_LS1012A: case CEVA_LS1043A: case CEVA_LS1046A: if (!ecc_addr) return -EINVAL; writel(ECC_DIS_VAL_CH2, ecc_addr); /* fallthrough */ case CEVA_LS2080A: writel(CEVA_PHY1_CFG, base + AHCI_VEND_PPCFG); writel(CEVA_TRANS_CFG, base + AHCI_VEND_PTC); break; case CEVA_LS1028A: case CEVA_LS1088A: if (!ecc_addr) return -EINVAL; writel(ECC_DIS_VAL_CH3, ecc_addr); writel(CEVA_PHY1_CFG, base + AHCI_VEND_PPCFG); writel(CEVA_TRANS_CFG, base + AHCI_VEND_PTC); break; } if (priv->flag & FLAG_COHERENT) writel(CEVA_AXICC_CFG, base + AHCI_VEND_AXICC); return 0; } static int sata_ceva_bind(struct udevice *dev) { struct udevice *scsi_dev; return ahci_bind_scsi(dev, &scsi_dev); } static int sata_ceva_probe(struct udevice *dev) { struct ceva_sata_priv *priv = dev_get_priv(dev); struct phy phy; int ret; struct reset_ctl_bulk resets; ret = generic_phy_get_by_index(dev, 0, &phy); if (!ret) { dev_dbg(dev, "Perform PHY initialization\n"); ret = generic_phy_init(&phy); if (ret) return ret; } else if (ret != -ENOENT) { dev_dbg(dev, "could not get phy (err %d)\n", ret); return ret; } /* reset is optional */ ret = reset_get_bulk(dev, &resets); if (ret && ret != -ENOTSUPP && ret != -ENOENT) { dev_dbg(dev, "Getting reset fails (err %d)\n", ret); return ret; } /* Just trigger reset when reset is specified */ if (!ret) { dev_dbg(dev, "Perform IP reset\n"); ret = reset_deassert_bulk(&resets); if (ret) { dev_dbg(dev, "Reset fails (err %d)\n", ret); reset_release_bulk(&resets); return ret; } } if (phy.dev) { dev_dbg(dev, "Perform PHY power on\n"); ret = generic_phy_power_on(&phy); if (ret) { dev_dbg(dev, "PHY power on failed (err %d)\n", ret); return ret; } } ceva_init_sata(priv); return ahci_probe_scsi(dev, priv->base); } static const struct udevice_id sata_ceva_ids[] = { { .compatible = "ceva,ahci-1v84", .data = CEVA_1V84 }, { .compatible = "fsl,ls1012a-ahci", .data = CEVA_LS1012A }, { .compatible = "fsl,ls1021a-ahci", .data = CEVA_LS1021A }, { .compatible = "fsl,ls1028a-ahci", .data = CEVA_LS1028A }, { .compatible = "fsl,ls1043a-ahci", .data = CEVA_LS1043A }, { .compatible = "fsl,ls1046a-ahci", .data = CEVA_LS1046A }, { .compatible = "fsl,ls1088a-ahci", .data = CEVA_LS1088A }, { .compatible = "fsl,ls2080a-ahci", .data = CEVA_LS2080A }, { } }; static int sata_ceva_of_to_plat(struct udevice *dev) { struct ceva_sata_priv *priv = dev_get_priv(dev); struct resource res_regs; int ret; if (dev_read_bool(dev, "dma-coherent")) priv->flag |= FLAG_COHERENT; priv->base = dev_read_addr(dev); if (priv->base == FDT_ADDR_T_NONE) return -EINVAL; ret = dev_read_resource_byname(dev, "sata-ecc", &res_regs); if (ret) priv->ecc_base = 0; else priv->ecc_base = res_regs.start; priv->soc = dev_get_driver_data(dev); debug("ccsr-sata-base %lx\t ecc-base %lx\n", priv->base, priv->ecc_base); return 0; } U_BOOT_DRIVER(ceva_host_blk) = { .name = "ceva_sata", .id = UCLASS_AHCI, .of_match = sata_ceva_ids, .bind = sata_ceva_bind, .ops = &scsi_ops, .priv_auto = sizeof(struct ceva_sata_priv), .probe = sata_ceva_probe, .of_to_plat = sata_ceva_of_to_plat, };
/* * __wt_clock_to_nsec -- * Convert from clock ticks to nanoseconds. */ uint64_t __wt_clock_to_nsec(uint64_t end, uint64_t begin) { double clock_diff; if (end < begin) return (0); clock_diff = (double)(end - begin); return ((uint64_t)(clock_diff / __wt_process.tsc_nsec_ratio)); }
/** * @brief Disable DRDY interrupt mode * @param pObj the device pObj * @retval 0 in case of success, an error code otherwise */ int32_t AIS2DW12_ACC_Disable_DRDY_Interrupt(AIS2DW12_Object_t *pObj) { ais2dw12_ctrl5_int2_t int2_pad_ctrl; if (ais2dw12_pin_int2_route_get(&(pObj->Ctx), &int2_pad_ctrl) != AIS2DW12_OK) { return AIS2DW12_ERROR; } int2_pad_ctrl.int2_drdy = 0; if (ais2dw12_pin_int2_route_set(&(pObj->Ctx), &int2_pad_ctrl) != AIS2DW12_OK) { return AIS2DW12_ERROR; } return AIS2DW12_OK; }
// SPDX-License-Identifier: GPL-2.0 /* * arch/sh/drivers/dma/dma-pvr2.c * * NEC PowerVR 2 (Dreamcast) DMA support * * Copyright (C) 2003, 2004 Paul Mundt */ #include <linux/init.h> #include <linux/kernel.h> #include <linux/module.h> #include <linux/interrupt.h> #include <mach/sysasic.h> #include <mach/dma.h> #include <asm/dma.h> #include <asm/io.h> static unsigned int xfer_complete; static int count; static irqreturn_t pvr2_dma_interrupt(int irq, void *dev_id) { if (get_dma_residue(PVR2_CASCADE_CHAN)) { printk(KERN_WARNING "DMA: SH DMAC did not complete transfer " "on channel %d, waiting..\n", PVR2_CASCADE_CHAN); dma_wait_for_completion(PVR2_CASCADE_CHAN); } if (count++ < 10) pr_debug("Got a pvr2 dma interrupt for channel %d\n", irq - HW_EVENT_PVR2_DMA); xfer_complete = 1; return IRQ_HANDLED; } static int pvr2_request_dma(struct dma_channel *chan) { if (__raw_readl(PVR2_DMA_MODE) != 0) return -EBUSY; __raw_writel(0, PVR2_DMA_LMMODE0); return 0; } static int pvr2_get_dma_residue(struct dma_channel *chan) { return xfer_complete == 0; } static int pvr2_xfer_dma(struct dma_channel *chan) { if (chan->sar || !chan->dar) return -EINVAL; xfer_complete = 0; __raw_writel(chan->dar, PVR2_DMA_ADDR); __raw_writel(chan->count, PVR2_DMA_COUNT); __raw_writel(chan->mode & DMA_MODE_MASK, PVR2_DMA_MODE); return 0; } static struct dma_ops pvr2_dma_ops = { .request = pvr2_request_dma, .get_residue = pvr2_get_dma_residue, .xfer = pvr2_xfer_dma, }; static struct dma_info pvr2_dma_info = { .name = "pvr2_dmac", .nr_channels = 1, .ops = &pvr2_dma_ops, .flags = DMAC_CHANNELS_TEI_CAPABLE, }; static int __init pvr2_dma_init(void) { if (request_irq(HW_EVENT_PVR2_DMA, pvr2_dma_interrupt, 0, "pvr2 DMA handler", NULL)) pr_err("Failed to register pvr2 DMA handler interrupt\n"); request_dma(PVR2_CASCADE_CHAN, "pvr2 cascade"); return register_dmac(&pvr2_dma_info); } static void __exit pvr2_dma_exit(void) { free_dma(PVR2_CASCADE_CHAN); free_irq(HW_EVENT_PVR2_DMA, 0); unregister_dmac(&pvr2_dma_info); } subsys_initcall(pvr2_dma_init); module_exit(pvr2_dma_exit); MODULE_AUTHOR("Paul Mundt <lethal@linux-sh.org>"); MODULE_DESCRIPTION("NEC PowerVR 2 DMA driver"); MODULE_LICENSE("GPL v2");
/*****************************************************************************/ /* * RoomObjectDestroyAndFree: Free memory associated with a room object, and the * room object itself. Returns NULL. */ room_contents_node *RoomObjectDestroyAndFree(room_contents_node *r) { RoomObjectDestroy(r); SafeFree(r); return NULL; }
#include<stdio.h> #include<stdlib.h> #include<string.h> #include<math.h> int main() { //freopen("in.txt","r",stdin); int a,b,c,x,y,z,count=0; scanf("%d%d%d",&a,&b,&c); x=a+b-c; if(x>=0&&(x%2==0)) { x=x/2; count++; } y=b+c-a; if(y>=0&&(y%2==0)) { y=y/2; count++; } z=a+c-b; if(z>=0&&(z%2==0)) { z=z/2; count++; } if(count==3) printf("%d %d %d\n",x,y,z); else printf("Impossible\n"); return 0; }
#include<stdio.h> int main() { long int n, b, d; scanf("%ld%ld%ld", &n, &b, &d); // printf("Done"); long int arr[n]; long int waste = 0, empty = 0; // printf("Enter array elements"); for(long int i = 0; i<n; i++) scanf("%ld", &arr[i]); for(long int i = 0; i<n; i++) { if(arr[i]>b)//throw continue; waste = waste + arr[i]; if(waste>d) { waste = 0; empty++; } } printf("%ld", empty); }
// This function uses libCEED to compute the action of the restriction operator static PetscErrorCode MatMult_Restrict(Mat A, Vec X, Vec Y) { PetscErrorCode ierr; UserIR user; PetscScalar *x, *y; PetscFunctionBeginUser; ierr = MatShellGetContext(A, &user); CHKERRQ(ierr); ierr = VecZeroEntries(user->Xloc); CHKERRQ(ierr); ierr = DMGlobalToLocalBegin(user->dmf, X, INSERT_VALUES, user->Xloc); CHKERRQ(ierr); ierr = DMGlobalToLocalEnd(user->dmf, X, INSERT_VALUES, user->Xloc); CHKERRQ(ierr); ierr = VecZeroEntries(user->Yloc); CHKERRQ(ierr); ierr = VecPointwiseMult(user->Xloc, user->Xloc, user->mult); CHKERRQ(ierr); ierr = VecGetArrayRead(user->Xloc, (const PetscScalar **)&x); CHKERRQ(ierr); ierr = VecGetArray(user->Yloc, &y); CHKERRQ(ierr); CeedVectorSetArray(user->ceedvecf, CEED_MEM_HOST, CEED_USE_POINTER, x); CeedVectorSetArray(user->ceedvecc, CEED_MEM_HOST, CEED_USE_POINTER, y); CeedOperatorApply(user->op, user->ceedvecf, user->ceedvecc, CEED_REQUEST_IMMEDIATE); CeedVectorSyncArray(user->ceedvecc, CEED_MEM_HOST); ierr = VecRestoreArrayRead(user->Xloc, (const PetscScalar **)&x); CHKERRQ(ierr); ierr = VecRestoreArray(user->Yloc, &y); CHKERRQ(ierr); ierr = VecZeroEntries(Y); CHKERRQ(ierr); ierr = DMLocalToGlobalBegin(user->dmc, user->Yloc, ADD_VALUES, Y); CHKERRQ(ierr); ierr = DMLocalToGlobalEnd(user->dmc, user->Yloc, ADD_VALUES, Y); CHKERRQ(ierr); PetscFunctionReturn(0); }
/************************************************************************* * WCMD_opt_s_strip_quotes * * Remove first and last quote WCHARacters, preserving all other text */ void WCMD_opt_s_strip_quotes(WCHAR *cmd) { WCHAR *src = cmd + 1, *dest = cmd, *lastq = NULL; while((*dest=*src) != '\0') { if (*src=='\"') lastq=dest; dest++, src++; } if (lastq) { dest=lastq++; while ((*dest++=*lastq++) != 0) ; } }
/* $NoKeywords: $ */ /* // // Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved. // OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert // McNeel & Associates. // // THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY. // ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF // MERCHANTABILITY ARE HEREBY DISCLAIMED. // // For complete openNURBS copyright information see <http://www.opennurbs.org>. // //////////////////////////////////////////////////////////////// */ #if !defined(OPENNURBS_3DM_PROPERTIES_INC_) #define OPENNURBS_3DM_PROPERTIES_INC_ ////////////////////////////////////////////////////////////////////////////////////////// class ON_CLASS ON_3dmRevisionHistory { public: ON_3dmRevisionHistory(); ~ON_3dmRevisionHistory(); // C++ default operator= and copy constructor work fine. void Default(); ON_BOOL32 IsValid() const; int NewRevision(); // returns updated revision count ON_BOOL32 Read( ON_BinaryArchive& ); ON_BOOL32 Write( ON_BinaryArchive& ) const; void Dump( ON_TextLog& ) const; /* Returns: true if m_create_time is >= January 1, 1970 */ bool CreateTimeIsSet() const; /* Returns: true if m_last_edit_time is >= January 1, 1970 */ bool LastEditedTimeIsSet() const; ON_wString m_sCreatedBy; ON_wString m_sLastEditedBy; struct tm m_create_time; // UCT create time struct tm m_last_edit_time; // UCT las edited time int m_revision_count; }; ////////////////////////////////////////////////////////////////////////////////////////// class ON_CLASS ON_3dmNotes { public: ON_3dmNotes(); ON_3dmNotes( const ON_3dmNotes& ); ~ON_3dmNotes(); ON_3dmNotes& operator=(const ON_3dmNotes&); void Default(); ON_BOOL32 IsValid() const; ON_BOOL32 Read( ON_BinaryArchive& ); ON_BOOL32 Write( ON_BinaryArchive& ) const; void Dump(ON_TextLog&) const; //////////////////////////////////////////////////////////////// // // Interface - this information is serialized. Applications // may want to derive a runtime class that has additional // window and font information. ON_wString m_notes; // UNICODE ON_BOOL32 m_bVisible; // true if notes window is showing ON_BOOL32 m_bHTML; // true if notes are in HTML // last window position int m_window_left; int m_window_top; int m_window_right; int m_window_bottom; }; ////////////////////////////////////////////////////////////////////////////////////////// class ON_CLASS ON_3dmApplication { // application that created the 3dm file public: ON_3dmApplication(); ON_3dmApplication( const ON_3dmApplication& ); ~ON_3dmApplication(); ON_3dmApplication& operator=(const ON_3dmApplication&); void Default(); ON_BOOL32 IsValid() const; ON_BOOL32 Read( ON_BinaryArchive& ); ON_BOOL32 Write( ON_BinaryArchive& ) const; void Dump( ON_TextLog& ) const; ON_wString m_application_name; // short name like "Rhino 2.0" ON_wString m_application_URL; // URL ON_wString m_application_details; // whatever you want }; ////////////////////////////////////////////////////////////////////////////////////////// class ON_CLASS ON_3dmProperties { public: ON_3dmProperties(); ~ON_3dmProperties(); ON_3dmProperties(const ON_3dmProperties&); ON_3dmProperties& operator=(const ON_3dmProperties&); void Default(); ON_BOOL32 Read(ON_BinaryArchive&); ON_BOOL32 Write(ON_BinaryArchive&) const; void Dump( ON_TextLog& ) const; ON_3dmRevisionHistory m_RevisionHistory; ON_3dmNotes m_Notes; ON_WindowsBitmap m_PreviewImage; // preview image of model ON_3dmApplication m_Application; // application that created 3DM file }; ////////////////////////////////////////////////////////////////////////////////////////// #endif
/* Return the number of instructions it takes to form a constant in as many gprs are needed for MODE. */ int num_insns_constant (rtx op, machine_mode mode) { HOST_WIDE_INT val; switch (GET_CODE (op)) { case CONST_INT: val = INTVAL (op); break; case CONST_WIDE_INT: { int insns = 0; for (int i = 0; i < CONST_WIDE_INT_NUNITS (op); i++) insns += num_insns_constant_multi (CONST_WIDE_INT_ELT (op, i), DImode); return insns; } case CONST_DOUBLE: { const struct real_value *rv = CONST_DOUBLE_REAL_VALUE (op); if (mode == SFmode || mode == SDmode) { long l; if (mode == SDmode) REAL_VALUE_TO_TARGET_DECIMAL32 (*rv, l); else REAL_VALUE_TO_TARGET_SINGLE (*rv, l); val = l; mode = SImode; } else if (mode == DFmode || mode == DDmode) { long l[2]; if (mode == DDmode) REAL_VALUE_TO_TARGET_DECIMAL64 (*rv, l); else REAL_VALUE_TO_TARGET_DOUBLE (*rv, l); val = (unsigned HOST_WIDE_INT) l[WORDS_BIG_ENDIAN ? 0 : 1] << 32; val |= l[WORDS_BIG_ENDIAN ? 1 : 0] & 0xffffffffUL; mode = DImode; } else if (mode == TFmode || mode == TDmode || mode == KFmode || mode == IFmode) { long l[4]; int insns; if (mode == TDmode) REAL_VALUE_TO_TARGET_DECIMAL128 (*rv, l); else REAL_VALUE_TO_TARGET_LONG_DOUBLE (*rv, l); val = (unsigned HOST_WIDE_INT) l[WORDS_BIG_ENDIAN ? 0 : 3] << 32; val |= l[WORDS_BIG_ENDIAN ? 1 : 2] & 0xffffffffUL; insns = num_insns_constant_multi (val, DImode); val = (unsigned HOST_WIDE_INT) l[WORDS_BIG_ENDIAN ? 2 : 1] << 32; val |= l[WORDS_BIG_ENDIAN ? 3 : 0] & 0xffffffffUL; insns += num_insns_constant_multi (val, DImode); return insns; } else gcc_unreachable (); } break; default: gcc_unreachable (); } return num_insns_constant_multi (val, mode); }
/**************************************************************************** * Name: up_txready * * Description: * Return true if the tranmsit fifo is not full * ****************************************************************************/ static bool up_txready(struct uart_dev_s *dev) { struct up_dev_s *priv = (struct up_dev_s*)dev->priv; uint16_t base = priv->base; return inb(base+COM_LSR) & COM_LSR_ETR; }
/*! * @brief Basic interrupt handler. It needs to be called from the ISR body. * E.g.: ISR(INT0_vect) { net_dev_irq_handler(); } */ inline void net_dev_irq_handler(void) { void (*irq_hdlr_f)(struct net_dev_s *); if (nd_irq_hdlr.net_dev) { irq_hdlr_f = pgm_read_ptr(&nd_irq_hdlr.net_dev->netdev_ops->irq_handler); irq_hdlr_f(nd_irq_hdlr.net_dev); } }
/** * cairo_scale: * @cr: a cairo context * @sx: scale factor for the X dimension * @sy: scale factor for the Y dimension * * Modifies the current transformation matrix (CTM) by scaling the X * and Y user-space axes by @sx and @sy respectively. The scaling of * the axes takes place after any existing transformation of user * space. **/ void cairo_scale (cairo_t *cr, double sx, double sy) { if (cr->status) return; cr->status = _cairo_gstate_scale (cr->gstate, sx, sy); if (cr->status) _cairo_set_error (cr, cr->status); }
#include <THC/THC.h> #include <stdio.h> #include "nms_cuda_kernel.h" // this symbol will be resolved automatically from PyTorch libs extern THCState *state; int nms_cuda(THCudaIntTensor *keep_out, THCudaTensor *boxes_host, THCudaIntTensor *num_out, float nms_overlap_thresh) { nms_cuda_compute(THCudaIntTensor_data(state, keep_out), THCudaIntTensor_data(state, num_out), THCudaTensor_data(state, boxes_host), THCudaTensor_size(state, boxes_host, 0), THCudaTensor_size(state, boxes_host, 1), nms_overlap_thresh); return 1; }
/* * unix_file_io.c * * This hacked together file allows unix-style programs * to read and save Triangulations. */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include "unix_file_io.h" #define READ_OLD_FILE_FORMAT 0 #define FALSE 0 #define TRUE 1 /* * gcc complains about the * * use of `l' length character with `f' type character * * in fprintf() calls. Presumably it considers the 'l' unnecessary * because even floats would undergo default promotion to doubles * in the function call (see section A7.3.2 in Appendix A of K&R 2nd ed.). * Therefore I've changed "%lf" to "%f" in all fprintf() calls. * If this makes trouble on your system, change it back, and please * let me know (weeks@northnet.org). */ static TriangulationData *ReadNewFileFormat(FILE *fp); static void my_fgets( char *string, int max, FILE *fp ); #if READ_OLD_FILE_FORMAT extern FuncResult read_old_manifold(FILE *fp, Triangulation **manifold); #endif Triangulation *get_triangulation( char *file_name) { FILE *fp; Boolean theNewFormat; Triangulation *manifold; /* * If the file_name is nonempty, read the file. * If the file_name is empty, read from stdin. */ if (strlen(file_name) > 0) { fp = fopen(file_name, "r"); if (fp == NULL) return NULL; /* * Take a peek at the first line to see whether this is * the new file format or the old one. */ theNewFormat = (getc(fp) == '%'); rewind(fp); } else { fp = stdin; theNewFormat = TRUE; /* read only the new format from stdin */ } if (theNewFormat == TRUE) { TriangulationData *theTriangulationData; theTriangulationData = ReadNewFileFormat(fp); if (theTriangulationData==NULL) { if (fp != stdin) fclose(fp); return NULL; } data_to_triangulation(theTriangulationData, &manifold); free(theTriangulationData->name); free(theTriangulationData->cusp_data); free(theTriangulationData->tetrahedron_data); free(theTriangulationData); } else { #if READ_OLD_FILE_FORMAT read_old_manifold(fp, &manifold); #else fprintf(stderr, "The manifold is in the old file format.\n"); fprintf(stderr, "I recommend converting it to the new format.\n"); fprintf(stderr, "If absolutely necessary, I can provide code for reading the old format.\n"); fprintf(stderr, "Questions? Contact me at weeks@northnet.org.\n"); uFatalError("get_triangulation", "unix file io"); #endif } if (fp != stdin) fclose(fp); return manifold; } static TriangulationData *ReadNewFileFormat( FILE *fp) { char theScratchString[100]; TriangulationData *theTriangulationData; int theTotalNumCusps, i, j, k, v, f; /* * Read and ignore the header (% Triangulation). */ my_fgets(theScratchString, 100, fp); if (strcmp(theScratchString, "% Triangulation") != 0) return NULL; /* * Allocate the TriangulationData. */ theTriangulationData = (TriangulationData *) malloc(sizeof(TriangulationData)); if (theTriangulationData == NULL) uFatalError("ReadNewFileFormat1", "unix file io"); theTriangulationData->name = NULL; theTriangulationData->cusp_data = NULL; theTriangulationData->tetrahedron_data = NULL; /* * Allocate and read the name of the manifold. */ theTriangulationData->name = (char *) malloc(100 * sizeof(char)); if (theTriangulationData->name == NULL) uFatalError("ReadNewFileFormat", "unix file io"); /* * The name will be on the first nonempty line. */ my_fgets(theTriangulationData->name, 100, fp); /* * Read the filled solution type. */ fscanf(fp, "%s", theScratchString); if (strcmp(theScratchString, "not_attempted") == 0) theTriangulationData->solution_type = not_attempted; else if (strcmp(theScratchString, "geometric_solution") == 0) theTriangulationData->solution_type = geometric_solution; else if (strcmp(theScratchString, "nongeometric_solution") == 0) theTriangulationData->solution_type = nongeometric_solution; else if (strcmp(theScratchString, "flat_solution") == 0) theTriangulationData->solution_type = flat_solution; else if (strcmp(theScratchString, "degenerate_solution") == 0) theTriangulationData->solution_type = degenerate_solution; else if (strcmp(theScratchString, "other_solution") == 0) theTriangulationData->solution_type = other_solution; else if (strcmp(theScratchString, "no_solution") == 0) theTriangulationData->solution_type = no_solution; else uFatalError("ReadNewFileFormat", "unix file io"); /* * Read the volume. */ fscanf(fp, "%lf", &theTriangulationData->volume); /* * Read the orientability. */ fscanf(fp, "%s", theScratchString); if (strcmp(theScratchString, "oriented_manifold") == 0) theTriangulationData->orientability = oriented_manifold; else if (strcmp(theScratchString, "nonorientable_manifold") == 0) theTriangulationData->orientability = nonorientable_manifold; else if (strcmp(theScratchString, "unknown_orientability") == 0) theTriangulationData->orientability = unknown_orientability; else uFatalError("ReadNewFileFormat", "unix file io"); /* * Read the Chern-Simons invariant, if present. */ fscanf(fp, "%s", theScratchString); if (strcmp(theScratchString, "CS_known") == 0) theTriangulationData->CS_value_is_known = TRUE; else if (strcmp(theScratchString, "CS_unknown") == 0) theTriangulationData->CS_value_is_known = FALSE; else uFatalError("ReadNewFileFormat", "unix file io"); if (theTriangulationData->CS_value_is_known == TRUE) fscanf(fp, "%lf", &theTriangulationData->CS_value); else theTriangulationData->CS_value = 0.0; /* * Read the number of cusps, allocate an array for the cusp data, * and read the cusp data. */ fscanf(fp, "%d%d", &theTriangulationData->num_or_cusps, &theTriangulationData->num_nonor_cusps); theTotalNumCusps = theTriangulationData->num_or_cusps + theTriangulationData->num_nonor_cusps; theTriangulationData->cusp_data = (CuspData *) malloc(theTotalNumCusps * sizeof(CuspData)); if (theTriangulationData->cusp_data == NULL) uFatalError("ReadNewFileFormat", "unix file io"); for (i = 0; i < theTotalNumCusps; i++) { if (fscanf(fp, "%s%lf%lf", theScratchString, &theTriangulationData->cusp_data[i].m, &theTriangulationData->cusp_data[i].l) != 3) uFatalError("ReadNewFileFormat", "unix file io"); switch (theScratchString[0]) { case 't': case 'T': theTriangulationData->cusp_data[i].topology = torus_cusp; break; case 'k': case 'K': theTriangulationData->cusp_data[i].topology = Klein_cusp; break; default: uFatalError("ReadNewFileFormat", "unix file io"); } } /* * Read the number of tetrahedra, allocate an array for the * tetrahedron data, and read the tetrahedron data. */ fscanf(fp, "%d", &theTriangulationData->num_tetrahedra); theTriangulationData->tetrahedron_data = (TetrahedronData *) malloc(theTriangulationData->num_tetrahedra * sizeof(TetrahedronData)); if (theTriangulationData->tetrahedron_data == NULL) uFatalError("ReadNewFileFormat", "unix file io"); for (i = 0; i < theTriangulationData->num_tetrahedra; i++) { /* * Read the neighbor indices. */ for (j = 0; j < 4; j++) { fscanf(fp, "%d", &theTriangulationData->tetrahedron_data[i].neighbor_index[j]); if (theTriangulationData->tetrahedron_data[i].neighbor_index[j] < 0 || theTriangulationData->tetrahedron_data[i].neighbor_index[j] >= theTriangulationData->num_tetrahedra) uFatalError("ReadNewFileFormat", "unix file io"); } /* * Read the gluings. */ for (j = 0; j < 4; j++) for (k = 0; k < 4; k++) { fscanf(fp, "%1d", &theTriangulationData->tetrahedron_data[i].gluing[j][k]); if (theTriangulationData->tetrahedron_data[i].gluing[j][k] < 0 || theTriangulationData->tetrahedron_data[i].gluing[j][k] > 3) uFatalError("ReadNewFileFormat", "unix file io"); } /* * Read the cusp indices. * * 99/06/04 Allow an index of -1 on "cusps" that are * really finite vertices. */ for (j = 0; j < 4; j++) { fscanf(fp, "%d", &theTriangulationData->tetrahedron_data[i].cusp_index[j]); if (theTriangulationData->tetrahedron_data[i].cusp_index[j] < -1 || theTriangulationData->tetrahedron_data[i].cusp_index[j] >= theTotalNumCusps) uFatalError("ReadNewFileFormat", "unix file io"); } /* * Read the peripheral curves. */ for (j = 0; j < 2; j++) /* meridian, longitude */ for (k = 0; k < 2; k++) /* righthanded, lefthanded */ for (v = 0; v < 4; v++) for (f = 0; f < 4; f++) fscanf(fp, "%d", &theTriangulationData->tetrahedron_data[i].curve[j][k][v][f]); /* * Read the filled shape (which the kernel ignores). */ fscanf(fp, "%lf%lf", &theTriangulationData->tetrahedron_data[i].filled_shape.real, &theTriangulationData->tetrahedron_data[i].filled_shape.imag); } return theTriangulationData; } void save_triangulation( Triangulation *manifold, char *file_name) { TriangulationData *theTriangulationData; FILE *fp; /* * If the file_name is nonempty, write the file. * If the file_name is empty, write to stdout. */ if (strlen(file_name) > 0) { fp = fopen(file_name, "w"); if (fp == NULL) { printf("couldn't open %s\n", file_name); return; } } else fp = stdout; triangulation_to_data(manifold, &theTriangulationData); WriteNewFileFormat(fp, theTriangulationData); free_triangulation_data(theTriangulationData); if (fp != stdout) fclose(fp); } extern void WriteNewFileFormat( FILE *fp, TriangulationData *data) { int i, j, k, v, f; fprintf(fp, "%% Triangulation\n"); if (data->name != NULL) fprintf(fp, "%s\n", data->name); else fprintf(fp, "untitled\n"); switch (data->solution_type) { case not_attempted: fprintf(fp, "not_attempted"); break; case geometric_solution: fprintf(fp, "geometric_solution"); break; case nongeometric_solution: fprintf(fp, "nongeometric_solution"); break; case flat_solution: fprintf(fp, "flat_solution"); break; case degenerate_solution: fprintf(fp, "degenerate_solution"); break; case other_solution: fprintf(fp, "other_solution"); break; case no_solution: fprintf(fp, "no_solution"); break; default: fprintf(fp, "not_attempted"); break; } if (data->solution_type != not_attempted) fprintf(fp, " %.8f\n", data->volume); else fprintf(fp, " %.1f\n", 0.0); switch (data->orientability) { case oriented_manifold: fprintf(fp, "oriented_manifold\n"); break; case nonorientable_manifold: fprintf(fp, "nonorientable_manifold\n"); break; case oriented_orbifold: /* DJH */ fprintf(fp, "oriented_orbifold\n"); break; case nonorientable_orbifold: /* DJH */ fprintf( fp, "nonorientable_orbifold\n"); break; } if (data->CS_value_is_known == TRUE) fprintf(fp, "CS_known %.16f\n", data->CS_value); else fprintf(fp, "CS_unknown\n"); fprintf(fp, "\n%d %d\n", data->num_or_cusps, data->num_nonor_cusps); for (i = 0; i < data->num_or_cusps + data->num_nonor_cusps; i++) fprintf(fp, " %s %16.12f %16.12f\n", (data->cusp_data[i].topology == torus_cusp) ? "torus" : "Klein", data->cusp_data[i].m, data->cusp_data[i].l); fprintf(fp, "\n"); fprintf(fp, "%d\n", data->num_tetrahedra); for (i = 0; i < data->num_tetrahedra; i++) { for (j = 0; j < 4; j++) fprintf(fp, "%4d ", data->tetrahedron_data[i].neighbor_index[j]); fprintf(fp, "\n"); for (j = 0; j < 4; j++) { fprintf(fp, " "); for (k = 0; k < 4; k++) fprintf(fp, "%d", data->tetrahedron_data[i].gluing[j][k]); } fprintf(fp, "\n"); for (j = 0; j < 4; j++) fprintf(fp, "%4d ", data->tetrahedron_data[i].cusp_index[j]); fprintf(fp, "\n"); for (j = 0; j < 2; j++) /* meridian, longitude */ for (k = 0; k < 2; k++) /* righthanded, lefthanded */ { for (v = 0; v < 4; v++) for (f = 0; f < 4; f++) fprintf(fp, " %2d", data->tetrahedron_data[i].curve[j][k][v][f]); fprintf(fp, "\n"); } if (data->solution_type != not_attempted) fprintf(fp, "%16.12f %16.12f\n\n", data->tetrahedron_data[i].filled_shape.real, data->tetrahedron_data[i].filled_shape.imag); else fprintf(fp, "%3.1f %3.1f\n\n", 0.0, 0.0); } } void my_fgets( char *string, int max, FILE *fp ) { int c, ch; c = 0; /* remove newlines at the beginning */ while( (ch = getc( fp )) == '\n' || ch == '\r' ) rewind( fp ); ungetc(ch, fp); while( (ch = getc( fp )) != '\n' && ch != '\r' && c < max-1 ) string[c++] = ch; string[c] = '\0'; }
/* set the carrier parameters; to be called with the spinlock held */ static void it8709_set_carrier_params(struct ite_dev *dev, bool high_freq, bool use_demodulator, u8 carrier_freq_bits, u8 allowance_bits, u8 pulse_width_bits) { u8 val; val = (it8709_rr(dev, IT85_C0CFR) &~(IT85_HCFS | IT85_CFQ)) | carrier_freq_bits; if (high_freq) val |= IT85_HCFS; it8709_wr(dev, val, IT85_C0CFR); val = it8709_rr(dev, IT85_C0RCR) & ~(IT85_RXEND | IT85_RXDCR); if (use_demodulator) val |= IT85_RXEND; val |= allowance_bits; it8709_wr(dev, val, IT85_C0RCR); val = it8709_rr(dev, IT85_C0TCR) & ~IT85_TXMPW; val |= pulse_width_bits; it8709_wr(dev, val, IT85_C0TCR); }
/*! * Checks if a vertex is a border vertex * * \param vp Vertex to check * * \retval true if vertex is a border vertex * \retval false if vertex isn't a border vertex */ static bool isBorderVertex(VertexPointer vp) { assert(vp); assert(!vp->IsD()); if( !(vp->VHp()) ) return true; Pos<MeshType> p( vp->VHp() ); do { if(!p.F()) return true; p.FlipE(); p.FlipF(); }while(p.HE() != vp->VHp()); return false; }
/* this returns locked reference to the emuldata entry (if found) */ struct linux_emuldata * em_find(struct proc *p, int locked) { struct linux_emuldata *em; LIN_SDT_PROBE2(emul, em_find, entry, p, locked); if (locked == EMUL_DOLOCK) EMUL_LOCK(&emul_lock); em = p->p_emuldata; if (em == NULL && locked == EMUL_DOLOCK) EMUL_UNLOCK(&emul_lock); LIN_SDT_PROBE1(emul, em_find, return, em); return (em); }
/** * @brief Changes milliseconds to a time object. * * @param mseconds The milliseonds to convert. * @param time The time object to put it into. * * @return A status code. */ ml_error_code _ml_mseconds_to_time(uint32_t mseconds, ml_time_t *time) { if (time == NULL) { return ML_NULL_POINTER; } time->seconds = (mseconds / 1000); time->mseconds = mseconds - (time->seconds * 1000); return ML_OK; }
/* * Copyright (c) 2012 The WebM project authors. All Rights Reserved. * * Use of this source code is governed by a BSD-style license * that can be found in the LICENSE file in the root of the source * tree. An additional intellectual property rights grant can be found * in the file PATENTS. All contributing project authors may * be found in the AUTHORS file in the root of the source tree. */ #ifndef VPX_VP8_ENCODER_DENOISING_H_ #define VPX_VP8_ENCODER_DENOISING_H_ #include "block.h" #include "vp8/common/loopfilter.h" #ifdef __cplusplus extern "C" { #endif #define SUM_DIFF_THRESHOLD 512 #define SUM_DIFF_THRESHOLD_HIGH 600 #define MOTION_MAGNITUDE_THRESHOLD (8 * 3) #define SUM_DIFF_THRESHOLD_UV (96) // (8 * 8 * 1.5) #define SUM_DIFF_THRESHOLD_HIGH_UV (8 * 8 * 2) #define SUM_DIFF_FROM_AVG_THRESH_UV (8 * 8 * 8) #define MOTION_MAGNITUDE_THRESHOLD_UV (8 * 3) #define MAX_GF_ARF_DENOISE_RANGE (8) enum vp8_denoiser_decision { COPY_BLOCK, FILTER_BLOCK }; enum vp8_denoiser_filter_state { kNoFilter, kFilterZeroMV, kFilterNonZeroMV }; enum vp8_denoiser_mode { kDenoiserOff, kDenoiserOnYOnly, kDenoiserOnYUV, kDenoiserOnYUVAggressive, kDenoiserOnAdaptive }; typedef struct { // Scale factor on sse threshold above which no denoising is done. unsigned int scale_sse_thresh; // Scale factor on motion magnitude threshold above which no // denoising is done. unsigned int scale_motion_thresh; // Scale factor on motion magnitude below which we increase the strength of // the temporal filter (in function vp8_denoiser_filter). unsigned int scale_increase_filter; // Scale factor to bias to ZEROMV for denoising. unsigned int denoise_mv_bias; // Scale factor to bias to ZEROMV for coding mode selection. unsigned int pickmode_mv_bias; // Quantizer threshold below which we use the segmentation map to switch off // loop filter for blocks that have been coded as ZEROMV-LAST a certain number // (consec_zerolast) of consecutive frames. Note that the delta-QP is set to // 0 when segmentation map is used for shutting off loop filter. unsigned int qp_thresh; // Threshold for number of consecutive frames for blocks coded as ZEROMV-LAST. unsigned int consec_zerolast; // Threshold for amount of spatial blur on Y channel. 0 means no spatial blur. unsigned int spatial_blur; } denoise_params; typedef struct vp8_denoiser { YV12_BUFFER_CONFIG yv12_running_avg[MAX_REF_FRAMES]; YV12_BUFFER_CONFIG yv12_mc_running_avg; // TODO(marpan): Should remove yv12_last_source and use vp8_lookahead_peak. YV12_BUFFER_CONFIG yv12_last_source; unsigned char *denoise_state; int num_mb_cols; int denoiser_mode; int threshold_aggressive_mode; int nmse_source_diff; int nmse_source_diff_count; int qp_avg; int qp_threshold_up; int qp_threshold_down; int bitrate_threshold; denoise_params denoise_pars; } VP8_DENOISER; int vp8_denoiser_allocate(VP8_DENOISER *denoiser, int width, int height, int num_mb_rows, int num_mb_cols, int mode); void vp8_denoiser_free(VP8_DENOISER *denoiser); void vp8_denoiser_set_parameters(VP8_DENOISER *denoiser, int mode); void vp8_denoiser_denoise_mb(VP8_DENOISER *denoiser, MACROBLOCK *x, unsigned int best_sse, unsigned int zero_mv_sse, int recon_yoffset, int recon_uvoffset, loop_filter_info_n *lfi_n, int mb_row, int mb_col, int block_index, int consec_zero_last); #ifdef __cplusplus } // extern "C" #endif #endif // VPX_VP8_ENCODER_DENOISING_H_
#include <stdio.h> int main(void){ // Your code here! int n,t,a,h[1000]; scanf("%d %d\n%d\n",&n,&t,&a); for(int i=0;i<n;i++){ int b; scanf("%d",&b); h[i]=b; } /*printf("%d\n%d\n%d\n",n,t,a); for(int i=0;i<n;i++){ printf("%d ",h[i]); }*/ long int x,z; x=(a-t)*1000+h[0]*6; int j=0; for(int i=0;i<n;i++){ long int y=(a-t)*1000+h[i]*6; int f=0; if(0<=y&&y<=x) f=1; else if(x>=y&&y>=0) f=1; else if(-x<=y&&y<=x) f=1; else if(x<=y&&y<=-x) f=1; if(f==1) x=y,j=i; } printf("%d\n",j+1); }
/************************************************************************* Mathematica source file Copyright 1986 through 1999 by Wolfram Research Inc. *************************************************************************/ #pragma once /* C language definitions for use with Mathematica output */ #define Power(x, y) (pow((ldouble)(x), (ldouble)(y))) #define Sqrt(x) (sqrt((ldouble)(x))) #define Sqrtl(x) (sqrt((ldouble)(x))) #define Abs(x) (fabs((ldouble)(x))) #define Exp(x) (exp((ldouble)(x))) #define Log(x) (log((ldouble)(x))) #define Sin(x) (sin((ldouble)(x))) #define Cos(x) (cos((ldouble)(x))) #define Tan(x) (tan((ldouble)(x))) #define ArcSin(x) (asin((ldouble)(x))) #define ArcCos(x) (acos((ldouble)(x))) #define ArcTan(x) (atan((ldouble)(x))) #define Sinh(x) (sinh((ldouble)(x))) #define Cosh(x) (cosh((ldouble)(x))) #define Tanh(x) (tanh((ldouble)(x))) #define Cot(x) (1./tan((ldouble)(x))) #define Csc(x) (1./sin((ldouble)(x))) #define Sec(x) (1./cos((ldouble)(x))) /** Could add definitions for Random(), SeedRandom(), etc. **/
/************************************************************************* _netr_ServerAuthenticate Create the initial credentials. *************************************************************************/ NTSTATUS _netr_ServerAuthenticate(struct pipes_struct *p, struct netr_ServerAuthenticate *r) { struct netr_ServerAuthenticate3 a; uint32_t negotiate_flags = 0; uint32_t rid; a.in.server_name = r->in.server_name; a.in.account_name = r->in.account_name; a.in.secure_channel_type = r->in.secure_channel_type; a.in.computer_name = r->in.computer_name; a.in.credentials = r->in.credentials; a.in.negotiate_flags = &negotiate_flags; a.out.return_credentials = r->out.return_credentials; a.out.rid = &rid; a.out.negotiate_flags = &negotiate_flags; return _netr_ServerAuthenticate3(p, &a); }
/** * Check if any 2+ fingers are close enough together to assume this is a * ClickFinger action. */ static int clickpad_guess_clickfingers(SynapticsPrivate * priv, struct SynapticsHwState *hw) { int nfingers = 0; uint32_t close_point = 0; int i, j; BUG_RETURN_VAL(hw->num_mt_mask > sizeof(close_point) * 8, 0); for (i = 0; i < hw->num_mt_mask - 1; i++) { ValuatorMask *f1; if (hw->slot_state[i] == SLOTSTATE_EMPTY || hw->slot_state[i] == SLOTSTATE_CLOSE) continue; f1 = hw->mt_mask[i]; for (j = i + 1; j < hw->num_mt_mask; j++) { ValuatorMask *f2; double x1, x2, y1, y2; if (hw->slot_state[j] == SLOTSTATE_EMPTY || hw->slot_state[j] == SLOTSTATE_CLOSE) continue; f2 = hw->mt_mask[j]; x1 = valuator_mask_get_double(f1, 0); y1 = valuator_mask_get_double(f1, 1); x2 = valuator_mask_get_double(f2, 0); y2 = valuator_mask_get_double(f2, 1); if (abs(x1 - x2) < (priv->maxx - priv->minx) * .3 && abs(y1 - y2) < (priv->maxy - priv->miny) * .3) { close_point |= (1 << j); close_point |= (1 << i); } } } while (close_point > 0) { nfingers += close_point & 0x1; close_point >>= 1; } if (hw->numFingers >= 3 && hw->num_mt_mask < 3) nfingers = 3; return nfingers; }
#include<stdio.h> #include<math.h> int main() { int n, a[100][2], i, c=0,j, x, d; do scanf("%d", &n); while(n<1 || n>100); for(i=0; i<n; i++) { do { scanf("%d%d", &x, &d); }while((x<(pow(10,4)*-1) || x>pow(10,4)) || (d<(-2*pow(10,4)) || d>(2*pow(10,4)))); a[i][0]=x; a[i][1]=d; } for(i=0; (i<n-1 && c!=1); i++) for(j=i+1; (j<n && c!=1); j++) { if(((a[i][0]+a[i][1])==a[j][0])&&((a[j][0]+a[j][1])==a[i][0])) { printf("YES"); c=1; } } if(c==0) printf("NO"); return 0; }
#include <ctype.h> #include <limits.h> #include <math.h> #include <stdbool.h> #include <stdio.h> #include <stdlib.h> #include <string.h> int main(int argc, char **argv) { int n; long y; scanf("%d %ld", &n, &y); for (int i = 0; i <= n; i++) { long amt = 10000L * i; for (int j = 0; j <= n - i; j++) { int k = n - i - j; if (amt + 5000L * j + 1000L * k == y) { printf("%d %d %d\n", i, j, k); return EXIT_SUCCESS; } } } printf("-1 -1 -1\n"); return EXIT_SUCCESS; }
/* * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana * University Research and Technology * Corporation. All rights reserved. * Copyright (c) 2004-2005 The University of Tennessee and The University * of Tennessee Research Foundation. All rights * reserved. * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart, * University of Stuttgart. All rights reserved. * Copyright (c) 2004-2005 The Regents of the University of California. * All rights reserved. * Copyright (c) 2011-2012 Cisco Systems, Inc. All rights reserved. * Copyright (c) 2015 Research Organization for Information Science * and Technology (RIST). All rights reserved. * $COPYRIGHT$ * * Additional copyrights may follow * * $HEADER$ */ #include "ompi_config.h" #include "ompi/mpi/fortran/mpif-h/bindings.h" #if OMPI_BUILD_MPI_PROFILING #if OPAL_HAVE_WEAK_SYMBOLS #pragma weak PMPI_TYPE_CONTIGUOUS = ompi_type_contiguous_f #pragma weak pmpi_type_contiguous = ompi_type_contiguous_f #pragma weak pmpi_type_contiguous_ = ompi_type_contiguous_f #pragma weak pmpi_type_contiguous__ = ompi_type_contiguous_f #pragma weak PMPI_Type_contiguous_f = ompi_type_contiguous_f #pragma weak PMPI_Type_contiguous_f08 = ompi_type_contiguous_f #else OMPI_GENERATE_F77_BINDINGS (PMPI_TYPE_CONTIGUOUS, pmpi_type_contiguous, pmpi_type_contiguous_, pmpi_type_contiguous__, pompi_type_contiguous_f, (MPI_Fint *count, MPI_Fint *oldtype, MPI_Fint *newtype, MPI_Fint *ierr), (count, oldtype, newtype, ierr) ) #endif #endif #if OPAL_HAVE_WEAK_SYMBOLS #pragma weak MPI_TYPE_CONTIGUOUS = ompi_type_contiguous_f #pragma weak mpi_type_contiguous = ompi_type_contiguous_f #pragma weak mpi_type_contiguous_ = ompi_type_contiguous_f #pragma weak mpi_type_contiguous__ = ompi_type_contiguous_f #pragma weak MPI_Type_contiguous_f = ompi_type_contiguous_f #pragma weak MPI_Type_contiguous_f08 = ompi_type_contiguous_f #else #if ! OMPI_BUILD_MPI_PROFILING OMPI_GENERATE_F77_BINDINGS (MPI_TYPE_CONTIGUOUS, mpi_type_contiguous, mpi_type_contiguous_, mpi_type_contiguous__, ompi_type_contiguous_f, (MPI_Fint *count, MPI_Fint *oldtype, MPI_Fint *newtype, MPI_Fint *ierr), (count, oldtype, newtype, ierr) ) #else #define ompi_type_contiguous_f pompi_type_contiguous_f #endif #endif void ompi_type_contiguous_f(MPI_Fint *count, MPI_Fint *oldtype, MPI_Fint *newtype, MPI_Fint *ierr) { int c_ierr; MPI_Datatype c_old = PMPI_Type_f2c(*oldtype); MPI_Datatype c_new; c_ierr = PMPI_Type_contiguous(OMPI_FINT_2_INT(*count), c_old, &c_new); if (NULL != ierr) *ierr = OMPI_INT_2_FINT(c_ierr); if (MPI_SUCCESS == c_ierr) { *newtype = PMPI_Type_c2f(c_new); } }
/*! \brief Flushes the TWI buffers */ void Flush_TWI_Buffers(void) { TWI_RxTail = 0; TWI_RxHead = 0; TWI_TxTail = 0; TWI_TxHead = 0; }
/* Author: Jason Williams <jdw@cromulence.com> Copyright (c) 2014 Cromulence LLC 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 "libcgc.h" #include "cgc_mymath.h" #include "cgc_stdint.h" double cgc_floor( double val ) { if ( val > 0.0 ) return cgc_rint( val + 0.5 ) - 1.0; else if ( val < 0.0 ) return cgc_rint( val - 0.5 ) + 1.0; else return 0.0; } double cgc_round_away_from_zero( double val ) { if ( val > 0.0 ) return cgc_rint( val + 0.5 ); else if ( val < 0.0 ) return cgc_rint( val - 0.5 ); else return 0.0; } double cgc_round( double val, double n ) { // Round to n digits n = cgc_rint( n ); double high_pow10 = cgc_pow( 10, n ); double low_pow10 = cgc_pow( 10, -n ); return (cgc_round_away_from_zero( val * high_pow10 ) * low_pow10); }
/* * kdb_print_state - Print the state data for the current processor * for debugging. * Inputs: * text Identifies the debug point * value Any integer value to be printed, e.g. reason code. */ void kdb_print_state(const char *text, int value) { kdb_printf("state: %s cpu %d value %d initial %d state %x\n", text, raw_smp_processor_id(), value, kdb_initial_cpu, kdb_state); }
/************************************************************************ * Copyright © 2020 The Multiphysics Modeling and Computation (M2C) Lab * <kevin.wgy@gmail.com> <kevinw3@vt.edu> ************************************************************************/ #pragma once #include <Vector3D.h> #include <cassert> /************************************************************************** * This file declares some basic geometry tools *************************************************************************/ namespace GeoTools { /************************************************************************** * Check if a point in 2D is within a disk * Inputs: * x,y -- coords of the point * cen_x, cen_y -- coords of the center of the disk * r -- radius of the disk * Outputs: true or false */ inline bool IsPointInDisk(double x, double y, double cen_x, double cen_y, double r) { return ( (x-cen_x)*(x-cen_x) + (y-cen_y)*(y-cen_y) <= r*r); } /************************************************************************** * Check if a point in 2D is within a rectangle * Inputs: * x,y -- coords of the point * cen_x, cen_y -- coords of the center of the rectangle * lx, ly -- dimensions of the rectangle in x and y directions * Outputs: true or false */ inline bool IsPointInRectangle(double x, double y, double cen_x, double cen_y, double lx, double ly) { return x >= cen_x - 0.5*lx && x <= cen_x + 0.5*lx && y >= cen_y - 0.5*ly && y <= cen_y + 0.5*ly; } /************************************************************************** * Project a point onto a line in 3D, specified using an edge (line segment) * Inputs: * x0 -- coords of the point * xA -- coords of the start point of the edge * xB -- coords of the end point of the edge * Outputs: * alpha -- affine coordinate (i.e. xA + alpha*AB = projection point) * return value -- distance from the point to the line * Note: If the "edge" is actually a point (i.e. xA = xB), alpha will be 0, * and the distance will be the distance to that point */ inline double ProjectPointToLine(Vec3D& x0, Vec3D& xA, Vec3D& xB, double &alpha) { Vec3D AB= xB-xA; Vec3D AX = x0-xA; double length2 = AB*AB; alpha = (length2 != 0) ? AB*AX/length2 : 0.0; Vec3D P = xA + alpha*AB; return (P-x0).norm(); } /************************************************************************** * Calculate the shortest distance from a point to a line segement in 3D * (this is unsigned distance, i.e. always positive) * Inputs: * x0 -- coords of the point * xA -- coords of the start point of the edge * xB -- coords of the end point of the edge * Outputs: * alpha -- affine coordinate of the closest point (between 0 and 1) * return value -- shortest distance from x0 to the line segment AB * Note: This function can handle the degenerate case of a point (i.e. * xA = xB) */ inline double GetShortestDistanceFromPointToLineSegment(Vec3D& x0, Vec3D& xA, Vec3D& xB, double &alpha) { double dist = ProjectPointToLine(x0, xA, xB, alpha); if(alpha>1.0) { dist = (x0-xB).norm(); alpha = 1.0; } else if (alpha<0.0 || !std::isfinite(alpha)/*xA=xB*/) { dist = (x0-xA).norm(); alpha = 0.0; } return dist; } /************************************************************************** * Calculate the normal direction and area of a triangle (by cross product) * Inputs: * xA, xB, xC -- coords of the three vertices of the triangle * (the order matters!) * Outputs: * dir -- unit normal dir (xB-xA)^(xC-xA) * return value -- area of the triangle */ inline double GetNormalAndAreaOfTriangle(Vec3D& xA, Vec3D& xB, Vec3D& xC, Vec3D& dir) { Vec3D ABC = 0.5*(xB-xA)^(xC-xA); //cross product double area = ABC.norm(); assert(area != 0.0); dir = 1.0/area*ABC; return area; } /************************************************************************** * Project a point onto a plane defined by a point on the plane and the * normal direction * Inputs: * x0 -- the point * O -- a point on the plane * dir -- normal direction * normalized -- (T/F) whether "dir" is normalized (i.e. norm = 1) * Outputs: * return value -- SIGNED distance from the point to the plane, along "dir" */ inline double ProjectPointToPlane(Vec3D& x0, Vec3D& O, Vec3D& dir, bool normalized = false) { if(normalized) return (x0-O)*dir; double norm = dir.norm(); assert(norm!=0.0); return (x0-O)*dir/norm; } /************************************************************************** * Project a point onto a plane defined by a triangle in 3D, specified by nodal coordinates * Inputs: * x0 -- the point * xA, xB, xC -- coords of the three vertices of the triangle (order matters!) * area (optional) -- area of the triangle * dir (optional) -- unit normal direction of the triangle * Outputs: * xi[3] -- barycentric coordinates (sum = 1) of the projection point, i.e. * the projection point is at xi[0]*xA + xi[1]*xB + x[2]*xC * return value -- SIGNED distance from the point TO THE PLANE defined by the triangle * Note: * If you do not care about the sign of the returned value, the order of A, B, C, and * the orientation of "dir" do not matter. But be careful, the returned value may * be negative. * If you care about the sign of the returned value, xA, xB, xC have to be ordered * such that the normal of the triangle can be determined based on the right-hand rule. * This is the case even if you explicitly specify "dir". */ double ProjectPointToPlane(Vec3D& x0, Vec3D& xA, Vec3D& xB, Vec3D& xC, double xi[3], double* area = NULL, Vec3D* dir = NULL); /************************************************************************** * Project a point onto a triangle, that is, find the closest point on the triangle * to the point. * Inputs: * x0 -- the point * xA, xB, xC -- coords of the three vertices of the triangle (order matters!) * area (optional) -- area of the triangle * dir (optional) -- unit normal direction of the triangle * return_signed_distance -- whether the returned distance is the signed distance or * just the magnitude (usually it should be the latter) * Outputs: * xi[3] -- barycentric coordinates (sum = 1) of the closest point, i.e. * the point is at xi[0]*xA + xi[1]*xB + x[2]*xC. All the coords are in [0, 1] * return value -- Distance from the point to the triangle, unsigned by default * Note: * - Usually, you should avoid getting/using the "sign" of the returned value, as it has * a sharp discontinuity when a point moves across the plane at a point outside the triange. * - If you do not care about the sign of the returned value, the order of A, B, C, and * the orientation of "dir" do not matter. But be careful, if "return_signed_distance" is * mistakenly turned on, the returned value may be negative. * - If you care about the sign of the returned value, xA, xB, xC have to be ordered * such that the normal of the triangle can be determined based on the right-hand rule. * This is the case even if you explicitly specify "dir". */ double ProjectPointToTriangle(Vec3D& x0, Vec3D& xA, Vec3D& xB, Vec3D& xC, double xi[3], double* area = NULL, Vec3D* dir = NULL, bool return_signed_distance = false); /************************************************************************** * Project a point onto a parallelogram. Find the closest point to the point * Inputs: * x0 -- the point * xA -- coords of one vertex of the parallelogram * AB, AC -- the two edges that have xA as a vertex (vector) * area (optional) -- area of the parallelogram * dir (optional) -- unit normal direction of the parallelogram * return_signed_distance -- whether the returned distance is the signed distance or * just the magnitude (usually it should be the latter) * Outputs: * xi[2] -- coordinates of the closest point. Specifically, * the point is at xA + xi[0]*AB + xi[1]*AC. Both coords are in [0, 1] * return value -- Distance from the point to the parallelogram, unsigned by default * Note: * - Usually, you should avoid getting/using the "sign" of the returned value, as it has * a sharp discontinuity when a point moves across the plane at a point outside the parallelogram * - If you do not care about the sign of the returned value, the order of AB and AC and * the orientation of "dir" do not matter. But be careful, if "return_signed_distance" is * mistakenly turned on, the returned value may be negative. * - If you care about the sign of the returned value, AB and AC must be ordered * such that the normal of the triangle can be determined based on the right-hand rule. * This is the case even if you explicitly specify "dir". */ double ProjectPointToParallelogram(Vec3D& x0, Vec3D& xA, Vec3D& AB, Vec3D& AC, double xi[2], double* area = NULL, Vec3D* dir = NULL, bool return_signed_distance = false); /************************************************************************** * Find if the distance from a point to a triangle is less than "half_thickness" * Inputs: * x0 -- the point * xA, xB, xC -- coords of the three vertices of the triangle (order matters!) * half_thickness -- half the thickness of the (thickened & widened) triangle * area (optional) -- area of the triangle * dir (optional) -- unit normal direction of the triangle * Output: * xi_out[3] (optional) -- barycentric coords of the CLOSEST POINT on the triangle. It is * guaranteed that 0<= xi[i] <= 1 for i = 1,2,3. */ bool IsPointInsideTriangle(Vec3D& x0, Vec3D& xA, Vec3D& xB, Vec3D& xC, double half_thickness = 1.0e-14, double* area = NULL, Vec3D* dir = NULL, double* xi_out = NULL); /************************************************************************** * Check if a ray collides with a moving triangle (continuous collision * detection (CCD)). Vertices of the triangle are assumed to move along * straight lines at constant speeds. * Inputs: * x0 -- initial position of the point * x -- current position of the point * A0,B0,C0 -- initial positions of the three vertices of the triangle * A,B,C -- current positions of the three vertices (same order!) * half_thickness (optional) -- half of the thickness of the triangle. Default: 0 * area0, dir0 (optional) -- area and normal of the original triangle (A0-B0-C0) * area, dir (optional) -- area and normal of the current triangle (A-B-C) * Output: * time (optional): time of collision, [0, 1] * Ref: * See M2C notes. */ bool ContinuousRayTriangleCollision(Vec3D& x0, Vec3D &x, Vec3D& A0, Vec3D& B0, Vec3D& C0, Vec3D& A, Vec3D& B, Vec3D& C, double* time = NULL, double half_thickness = 1.0e-14, double* area0 = NULL, Vec3D* dir0 = NULL, double* area = NULL, Vec3D* dir = NULL); /************************************************************************** * Find if a point is swept by a moving triangle (continuous collision * detection (CCD)). Vertices of the triangle are assumed to move along * straight lines at constant speeds. * Inputs: * x -- position of the point * A0,B0,C0 -- initial positions of the three vertices of the triangle * A,B,C -- current positions of the three vertices (same order!) * half_thickness (optional) -- half of the thickness of the triangle. Default: 0 * area0, dir0 (optional) -- area and normal of the original triangle (A0-B0-C0) * area, dir (optional) -- area and normal of the current triangle (A-B-C) * Output: * time (optional): time of collision, [0, 1] */ inline bool IsPointSweptByTriangle(Vec3D& x, Vec3D& A0, Vec3D& B0, Vec3D& C0, Vec3D& A, Vec3D& B, Vec3D& C, double* time = NULL, double half_thickness = 1.0e-14, double* area0 = NULL, Vec3D* dir0 = NULL, double* area = NULL, Vec3D* dir = NULL) { return ContinuousRayTriangleCollision(x, x, A0, B0, C0, A, B, C, time, half_thickness, area0, dir0, area, dir); } /************************************************************************** * Trilinear interpolation * Inputs: * xi = (xi1, xi2, xi3) -- local coordinates the interpolation point * c000, c100, c010, c110, c001, c101, c011, c111 --- 8 nodal values (i,j,k) * Outputs: * return value: interpolated value. */ inline double TrilinearInterpolation(Vec3D &xi, double c000, double c100, double c010, double c110, double c001, double c101, double c011, double c111) { double c00 = c000*(1.0 - xi[0]) + c100*xi[0]; double c01 = c001*(1.0 - xi[0]) + c101*xi[0]; double c10 = c010*(1.0 - xi[0]) + c110*xi[0]; double c11 = c011*(1.0 - xi[0]) + c111*xi[0]; double c0 = c00*(1.0 - xi[1]) + c10*xi[1]; double c1 = c01*(1.0 - xi[1]) + c11*xi[1]; return c0*(1.0 - xi[2]) + c1*xi[2]; } /************************************************************************** * Find the smallest 3D axis-aligned boundingbox of a circle * Inputs: * x0 -- center of the circle * dir -- normal direction * r -- radius of circle * Outputs: * xyzmin, xyzmax -- the bounding box, defined by two points: (xmin,ymin,zmin) and (xmax,ymax,zmax) */ inline void BoundingBoxOfCircle3D(Vec3D &x0, Vec3D &dir, double r, Vec3D &xyzmin, Vec3D &xyzmax) { Vec3D dir0 = dir / dir.norm(); double r_axis; for(int i=0; i<3; i++) { r_axis = sqrt(1.0 - dir0[i]*dir0[i])*r; xyzmin[i] = x0[i] - r_axis; xyzmax[i] = x0[i] + r_axis; } } /************************************************************************** * Find the smallest 3D axis-aligned boundingbox of a cylinder or truncated cone * Inputs: * x0 -- center of the base * r0 -- radius of the base * x1 -- center of the cap * r1 -- radius of the cap * dir -- normal direction * Outputs: * bbmin, bbmax -- the bounding box, defined by two points: (xmin,ymin,zmin) and (xmax,ymax,zmax) */ inline void BoundingBoxOfCylinder(Vec3D &x0, double r0, Vec3D &x1, double r1, Vec3D &dir, Vec3D &bbmin, Vec3D &bbmax) { BoundingBoxOfCircle3D(x0, dir, r0, bbmin, bbmax); Vec3D xyzmin(0.0), xyzmax(0.0); BoundingBoxOfCircle3D(x1, dir, r1, xyzmin, xyzmax); for(int i=0; i<3; i++) { if(bbmin[i] > xyzmin[i]) bbmin[i] = xyzmin[i]; if(bbmax[i] < xyzmax[i]) bbmax[i] = xyzmax[i]; } } /************************************************************************** * For a given vector, find two unit vectors such that the three form an * orthonormal basis. (If the given vector is NOT normalized, this function * takes care of it, but does not change it. The VALUE of U0 is passed in, * not a reference.) * Inputs: * U0 -- a given vector * U0_normalized -- (T/F) whether U0 is normalized. * Outputs: * U1, U2: two unit vectors that are orthogonal to each other, and to U0. */ void GetOrthonormalVectors(Vec3D U0, Vec3D &U1, Vec3D &U2, bool U0_normalized = false); } //end of namespace
/****************************************************************************** * label_propagation_refinement.h * * * Source of KaHIP -- Karlsruhe High Quality Partitioning. * Christian Schulz <christian.schulz.phone@gmail.com> *****************************************************************************/ #ifndef LABEL_PROPAGATION_REFINEMENT_R4XW141Y #define LABEL_PROPAGATION_REFINEMENT_R4XW141Y #include "definitions.h" #include "../refinement.h" class label_propagation_refinement : public refinement { public: label_propagation_refinement(); virtual ~label_propagation_refinement(); virtual EdgeWeight perform_refinement(PartitionConfig & config, graph_access & G, complete_boundary & boundary); }; #endif /* end of include guard: LABEL_PROPAGATION_REFINEMENT_R4XW141Y */
/* Insert table into sfnt directory in tag order */ static Table *insertTable(Tag tag) { int index = getTableIndex(tag); Table *tbl = &sfnt.directory[index]; if (tbl->tag != tag) { int i; if (++sfnt.numTables > MAX_TABLES) fatal(SFED_MSG_TABLELIMIT, MAX_TABLES); for (i = sfnt.numTables - 2; i >= index; i--) sfnt.directory[i + 1] = sfnt.directory[i]; tbl->flags = 0; tbl->xfilename = NULL; tbl->afilename = NULL; } return tbl; }
/* * IOCTL request handler to set/get generic IE. * * In addition to various generic IEs, this function can also be * used to set the ARP filter. */ static int mwifiex_misc_ioctl_gen_ie(struct mwifiex_private *priv, struct mwifiex_ds_misc_gen_ie *gen_ie, u16 action) { struct mwifiex_adapter *adapter = priv->adapter; switch (gen_ie->type) { case MWIFIEX_IE_TYPE_GEN_IE: if (action == HostCmd_ACT_GEN_GET) { gen_ie->len = priv->wpa_ie_len; memcpy(gen_ie->ie_data, priv->wpa_ie, gen_ie->len); } else { mwifiex_set_gen_ie_helper(priv, gen_ie->ie_data, (u16) gen_ie->len); } break; case MWIFIEX_IE_TYPE_ARP_FILTER: memset(adapter->arp_filter, 0, sizeof(adapter->arp_filter)); if (gen_ie->len > ARP_FILTER_MAX_BUF_SIZE) { adapter->arp_filter_size = 0; mwifiex_dbg(adapter, ERROR, "invalid ARP filter size\n"); return -1; } else { memcpy(adapter->arp_filter, gen_ie->ie_data, gen_ie->len); adapter->arp_filter_size = gen_ie->len; } break; default: mwifiex_dbg(adapter, ERROR, "invalid IE type\n"); return -1; } return 0; }
/* SPDX-License-Identifier: GPL-2.0 */ /* * Audio driver for AK4458 * * Copyright (C) 2016 Asahi Kasei Microdevices Corporation * Copyright 2018 NXP */ #ifndef _AK4458_H #define _AK4458_H #include <linux/regmap.h> /* Settings */ #define AK4458_00_CONTROL1 0x00 #define AK4458_01_CONTROL2 0x01 #define AK4458_02_CONTROL3 0x02 #define AK4458_03_LCHATT 0x03 #define AK4458_04_RCHATT 0x04 #define AK4458_05_CONTROL4 0x05 #define AK4458_06_DSD1 0x06 #define AK4458_07_CONTROL5 0x07 #define AK4458_08_SOUND_CONTROL 0x08 #define AK4458_09_DSD2 0x09 #define AK4458_0A_CONTROL6 0x0A #define AK4458_0B_CONTROL7 0x0B #define AK4458_0C_CONTROL8 0x0C #define AK4458_0D_CONTROL9 0x0D #define AK4458_0E_CONTROL10 0x0E #define AK4458_0F_L2CHATT 0x0F #define AK4458_10_R2CHATT 0x10 #define AK4458_11_L3CHATT 0x11 #define AK4458_12_R3CHATT 0x12 #define AK4458_13_L4CHATT 0x13 #define AK4458_14_R4CHATT 0x14 /* Bitfield Definitions */ /* AK4458_00_CONTROL1 (0x00) Fields * Addr Register Name D7 D6 D5 D4 D3 D2 D1 D0 * 00H Control 1 ACKS 0 0 0 DIF2 DIF1 DIF0 RSTN */ /* Digital Filter (SD, SLOW, SSLOW) */ #define AK4458_SD_MASK GENMASK(5, 5) #define AK4458_SLOW_MASK GENMASK(0, 0) #define AK4458_SSLOW_MASK GENMASK(0, 0) /* DIF2 1 0 * x 1 0 MSB justified Figure 3 (default) * x 1 1 I2S Compliment Figure 4 */ #define AK4458_DIF_SHIFT 1 #define AK4458_DIF_MASK GENMASK(3, 1) #define AK4458_DIF_16BIT_LSB (0 << 1) #define AK4458_DIF_24BIT_I2S (3 << 1) #define AK4458_DIF_32BIT_LSB (5 << 1) #define AK4458_DIF_32BIT_MSB (6 << 1) #define AK4458_DIF_32BIT_I2S (7 << 1) /* AK4458_00_CONTROL1 (0x00) D0 bit */ #define AK4458_RSTN_MASK GENMASK(0, 0) #define AK4458_RSTN (0x1 << 0) /* AK4458_0A_CONTROL6 Mode bits */ #define AK4458_MODE_SHIFT 6 #define AK4458_MODE_MASK GENMASK(7, 6) #define AK4458_MODE_NORMAL (0 << AK4458_MODE_SHIFT) #define AK4458_MODE_TDM128 (1 << AK4458_MODE_SHIFT) #define AK4458_MODE_TDM256 (2 << AK4458_MODE_SHIFT) #define AK4458_MODE_TDM512 (3 << AK4458_MODE_SHIFT) /* DAC Digital attenuator transition time setting * Table 19 * Mode ATS1 ATS2 ATT speed * 0 0 0 4080/fs * 1 0 1 2040/fs * 2 1 0 510/fs * 3 1 1 255/fs * */ #define AK4458_ATS_SHIFT 6 #define AK4458_ATS_MASK GENMASK(7, 6) #define AK4458_DCHAIN_MASK (0x1 << 1) #define AK4458_DSDSEL_MASK (0x1 << 0) #define AK4458_DP_MASK (0x1 << 7) #endif
/* Relocate a pointer to a ref. */ /* See gsmemory.h for why the argument is const and the result is not. */ ref_packed * igc_reloc_ref_ptr_nocheck(const ref_packed * prp, gc_state_t *gcst) { const ref_packed *rp = prp; uint dec = 0; #ifdef ALIGNMENT_ALIASING_BUG const ref *rpref; # define RP_REF(rp) (rpref = (const ref *)rp, rpref) #else # define RP_REF(rp) ((const ref *)rp) #endif for (;;) { if (r_is_packed(rp)) { rputc(gcst->heap, (*rp & lp_mark ? '1' : '0')); if (!(*rp & lp_mark)) { if (*rp != pt_tag(pt_integer) + packed_max_value) { rputc(gcst->heap, '\n'); rp = print_reloc(prp, "ref", (const ref_packed *) ((const char *)prp - (*rp & packed_value_mask) + dec)); break; } dec += sizeof(ref_packed) * align_packed_per_ref; rp += align_packed_per_ref; } else rp++; continue; } if (!ref_type_uses_size_or_null(r_type(RP_REF(rp)))) { rputc(gcst->heap, '\n'); rp = print_reloc(prp, "ref", (const ref_packed *) (r_size(RP_REF(rp)) == 0 ? prp : (const ref_packed *)((const char *)prp - r_size(RP_REF(rp)) + dec))); break; } rputc(gcst->heap, 'u'); rp += packed_per_ref; } { union { const ref_packed *r; ref_packed *w; } u; u.r = rp; return u.w; } #undef RP_REF }
#include <stdio.h> int main() { int n, k, l, c, d, p, nl, np, i, a, b, e; scanf(" %d %d %d %d %d %d %d %d", &n, &k, &l, &c, &d, &p, &nl, &np); a = k*l / nl; e = c*d; b = p / np; if (a < e) { if (a < b) { printf("%d\n", a / n); } else { printf("%d\n", b / n); } } else { if (e<b){ printf("%d\n", e / n); } else { printf("%d\n", b / n); } } }
/** multiplies operand1 with operand2 and stores result in resultant */ void SCIPintervalMul( SCIP_Real infinity, SCIP_INTERVAL* resultant, SCIP_INTERVAL operand1, SCIP_INTERVAL operand2 ) { SCIP_ROUNDMODE roundmode; assert(resultant != NULL); assert(!SCIPintervalIsEmpty(infinity, operand1)); assert(!SCIPintervalIsEmpty(infinity, operand2)); roundmode = SCIPintervalGetRoundingMode(); SCIPintervalSetRoundingMode(SCIP_ROUND_DOWNWARDS); SCIPintervalMulInf(infinity, resultant, operand1, operand2); SCIPintervalSetRoundingMode(SCIP_ROUND_UPWARDS); SCIPintervalMulSup(infinity, resultant, operand1, operand2); SCIPintervalSetRoundingMode(roundmode); }
/** * @brief Handle Motion Plus event. * * @param mp A pointer to a motionplus_t structure. * @param msg The message specified in the event packet. */ void motion_plus_event(struct motion_plus_t* mp, byte* msg) { mp->acc_mode = ((msg[4] & 0x2) << 1) | ((msg[3] & 0x1) << 1) | ((msg[3] & 0x2) >> 1); mp->raw_gyro.r = ((msg[4] & 0xFC) << 6) | msg[1]; mp->raw_gyro.p = ((msg[5] & 0xFC) << 6) | msg[2]; mp->raw_gyro.y = ((msg[3] & 0xFC) << 6) | msg[0]; if((mp->raw_gyro.r > 5000) && (mp->raw_gyro.p > 5000) && (mp->raw_gyro.y > 5000) && !(mp->cal_gyro.r) && !(mp->cal_gyro.p) && !(mp->cal_gyro.y)) { wiic_calibrate_motion_plus(mp); } calculate_gyro_rates(mp); }
#include <stdio.h> #include <string.h> int main(void) { int i,a=0,b=0,c=0; char x[101],y[101],z[101]; gets(x); gets(y); gets(z); for(i=0;i<strlen(x);i++) if(x[i] == 'a' ||x[i] == 'e' ||x[i] == 'i' ||x[i] == 'o' ||x[i] == 'u' ) a++; for(i=0;i<strlen(y);i++) if(y[i] == 'a' ||y[i] == 'e' ||y[i] == 'i' ||y[i] == 'o' ||y[i] == 'u' ) b++; for(i=0;i<strlen(z);i++) if(z[i] == 'a' ||z[i] == 'e' ||z[i] == 'i' ||z[i] == 'o' ||z[i] == 'u' ) c++; if(a==5 && b==7 && c==5) printf("YES"); else printf("NO"); }
//************************************************************************ // Copyright 2022 Massachusets Institute of Technology // SPDX License Identifier: BSD-2-Clause // // File Name: // Program: Common Evaluation Platform (CEP) // Description: // Notes: // //************************************************************************ #ifndef __C_DISPATCH_H #define __C_DISPATCH_H // Dispatch setup #ifdef LONGTEST #define MAX_LOOP 50 #else #define MAX_LOOP 5 #endif #endif
/* create a (named) dictionary */ BsDict* bsCreate(const char *name, const uint32_t flags) { size_t slen = 0; BsDict *ret; xcalloc(ret, 1, sizeof(BsDict)); if(name == NULL || ((slen = strlen(name)) == 0)) { xmalloc(ret->name, 1); ret->name[0] = '\0'; } else { xmalloc(ret->name, slen + 1); memcpy(ret->name, name, slen); } *(ret->name + slen) = '\0'; ret->flags = flags; _bsCreateNode(ret, NULL, BS_NODE_ROOT,NULL,0,NULL,0); if(!(flags & BS_NOINDEX)) { ret->index = bsIndexCreate(); if(ret->index == NULL) { bsFree(ret); return NULL; } } return ret; }
/* * To read a register in an I2C device, an address must be written to the "pointer" first. * The STOP condition can be sent after. * Then, upon issuing a READ command, the data returned will be that from the register address * in the pointer. */ uint16_t SendReadCommandI2C(uint8_t deviceAddress, uint8_t regAddress) { uint16_t result = UCB0RXBUF; while (I2C_BUSY && (!TXBUF_EMPTY)); I2C_OTHER_ADDRESS_REG = deviceAddress; I2C_TRANSMIT; I2C_START; while (ADDRESS_SENDING); if (NACK_RECEIVED) { I2C_STOP; while (I2C_STOP_PENDING); return 0; } SendByteI2C(regAddress); if (NACK_RECEIVED) { I2C_STOP; while (I2C_STOP_PENDING); return 0; } I2C_RECEIVE; I2C_START; while (ADDRESS_SENDING); while (!DATA_RECEIVED); result = (UCB0RXBUF << 8); RESET_RXIFG; while (!DATA_RECEIVED); result |= UCB0RXBUF; I2C_STOP; while (I2C_STOP_PENDING); return result; }
// Auto-generated file. Do not edit! // Template: src/f32-spmm/neon-blocked.c.in // Generator: tools/xngen // // Copyright 2019 Google LLC // // This source code is licensed under the BSD-style license found in the // LICENSE file in the root directory of this source tree. #include <assert.h> #include <arm_neon.h> #include <xnnpack/prefetch.h> #include <xnnpack/spmm.h> void xnn_f32_spmm_minmax_ukernel_8x4__aarch64_neonfma( size_t mc, size_t nc, const float* input, const float* weights, const int32_t* widx_dmap, const uint32_t* nidx_nnzmap, float* output, size_t output_stride, const union xnn_f32_minmax_params params[restrict XNN_MIN_ELEMENTS(1)]) { assert(mc != 0); assert(mc % sizeof(float) == 0); assert(nc != 0); #if XNN_ARCH_ARM64 const float32x4x2_t vminmax = vld2q_dup_f32(&params->scalar.min); const float32x4_t vmin = vminmax.val[0]; const float32x4_t vmax = vminmax.val[1]; #else const float32x2x2_t vminmax = vld2_dup_f32(&params->scalar.min); const float32x4_t vmin = vcombine_f32(vminmax.val[0], vminmax.val[0]); const float32x4_t vmax = vcombine_f32(vminmax.val[1], vminmax.val[1]); #endif size_t output_decrement = output_stride * nc - 8 * sizeof(float); while XNN_LIKELY(mc >= 8 * sizeof(float)) { const float* w = weights; const int32_t* dmap = widx_dmap; const uint32_t* nnzmap = nidx_nnzmap; size_t n = nc; while (n >= 4) { uint32_t nnz = *nnzmap++; float32x4_t vacc0123n0 = vld1q_dup_f32(w); w += 1; float32x4_t vacc4567n0 = vacc0123n0; float32x4_t vacc0123n1 = vld1q_dup_f32(w); w += 1; float32x4_t vacc4567n1 = vacc0123n1; float32x4_t vacc0123n2 = vld1q_dup_f32(w); w += 1; float32x4_t vacc4567n2 = vacc0123n2; float32x4_t vacc0123n3 = vld1q_dup_f32(w); w += 1; float32x4_t vacc4567n3 = vacc0123n3; if XNN_LIKELY(nnz != 0) { do { const intptr_t diff = *dmap++; const float32x4_t vi0123 = vld1q_f32(input); const float32x4_t vi4567 = vld1q_f32(input + 4); input = (const float*) ((uintptr_t) input + (uintptr_t) diff); xnn_prefetch_to_l1(input + 16); const float32x4_t vw = vld1q_f32(w); w += 4; xnn_prefetch_to_l1(w + 32); vacc0123n0 = vfmaq_laneq_f32(vacc0123n0, vi0123, vw, 0); vacc4567n0 = vfmaq_laneq_f32(vacc4567n0, vi4567, vw, 0); vacc0123n1 = vfmaq_laneq_f32(vacc0123n1, vi0123, vw, 1); vacc4567n1 = vfmaq_laneq_f32(vacc4567n1, vi4567, vw, 1); vacc0123n2 = vfmaq_laneq_f32(vacc0123n2, vi0123, vw, 2); vacc4567n2 = vfmaq_laneq_f32(vacc4567n2, vi4567, vw, 2); vacc0123n3 = vfmaq_laneq_f32(vacc0123n3, vi0123, vw, 3); vacc4567n3 = vfmaq_laneq_f32(vacc4567n3, vi4567, vw, 3); } while (--nnz != 0); } float32x4_t vout0123n0 = vminq_f32(vacc0123n0, vmax); float32x4_t vout4567n0 = vminq_f32(vacc4567n0, vmax); float32x4_t vout0123n1 = vminq_f32(vacc0123n1, vmax); float32x4_t vout4567n1 = vminq_f32(vacc4567n1, vmax); float32x4_t vout0123n2 = vminq_f32(vacc0123n2, vmax); float32x4_t vout4567n2 = vminq_f32(vacc4567n2, vmax); float32x4_t vout0123n3 = vminq_f32(vacc0123n3, vmax); float32x4_t vout4567n3 = vminq_f32(vacc4567n3, vmax); vout0123n0 = vmaxq_f32(vout0123n0, vmin); vout4567n0 = vmaxq_f32(vout4567n0, vmin); vout0123n1 = vmaxq_f32(vout0123n1, vmin); vout4567n1 = vmaxq_f32(vout4567n1, vmin); vout0123n2 = vmaxq_f32(vout0123n2, vmin); vout4567n2 = vmaxq_f32(vout4567n2, vmin); vout0123n3 = vmaxq_f32(vout0123n3, vmin); vout4567n3 = vmaxq_f32(vout4567n3, vmin); vst1q_f32(output + 0, vout0123n0); vst1q_f32(output + 4, vout4567n0); output = (float*) ((uintptr_t) output + output_stride); vst1q_f32(output + 0, vout0123n1); vst1q_f32(output + 4, vout4567n1); output = (float*) ((uintptr_t) output + output_stride); vst1q_f32(output + 0, vout0123n2); vst1q_f32(output + 4, vout4567n2); output = (float*) ((uintptr_t) output + output_stride); vst1q_f32(output + 0, vout0123n3); vst1q_f32(output + 4, vout4567n3); output = (float*) ((uintptr_t) output + output_stride); n -= 4; } // clean up loop, fall back to nr=1 if XNN_UNLIKELY(n != 0) { do { uint32_t nnz = *nnzmap++; float32x4_t vacc0123 = vld1q_dup_f32(w); w += 1; float32x4_t vacc4567 = vacc0123; if XNN_LIKELY(nnz != 0) { do { const intptr_t diff = *dmap++; const float32x4_t vi0123 = vld1q_f32(input); const float32x4_t vi4567 = vld1q_f32(input + 4); input = (const float*) ((uintptr_t) input + (uintptr_t) diff); xnn_prefetch_to_l1(input + 16); const float32x4_t vw = vld1q_dup_f32(w); w += 1; xnn_prefetch_to_l1(w + 32); vacc0123 = vfmaq_f32(vacc0123, vi0123, vw); vacc4567 = vfmaq_f32(vacc4567, vi4567, vw); } while (--nnz != 0); } float32x4_t vout0123 = vminq_f32(vacc0123, vmax); float32x4_t vout4567 = vminq_f32(vacc4567, vmax); vout0123 = vmaxq_f32(vout0123, vmin); vout4567 = vmaxq_f32(vout4567, vmin); vst1q_f32(output + 0, vout0123); vst1q_f32(output + 4, vout4567); output = (float*) ((uintptr_t) output + output_stride); n -= 1; } while (n != 0); } output = (float*) ((uintptr_t) output - output_decrement); input += 8; mc -= 8 * sizeof(float); } if XNN_UNLIKELY(mc != 0) { output_decrement += 4 * sizeof(float); if (mc & (4 * sizeof(float))) { const float* w = weights; const int32_t* dmap = widx_dmap; const uint32_t* nnzmap = nidx_nnzmap; size_t n = nc; while (n >= 4) { uint32_t nnz = *nnzmap++; float32x4_t vacc0123n0 = vld1q_dup_f32(w); w += 1; float32x4_t vacc0123n1 = vld1q_dup_f32(w); w += 1; float32x4_t vacc0123n2 = vld1q_dup_f32(w); w += 1; float32x4_t vacc0123n3 = vld1q_dup_f32(w); w += 1; if XNN_LIKELY(nnz != 0) { do { const intptr_t diff = *dmap++; const float32x4_t vi0123 = vld1q_f32(input); input = (const float*) ((uintptr_t) input + (uintptr_t) diff); const float32x4_t vw = vld1q_f32(w); w += 4; vacc0123n0 = vfmaq_laneq_f32(vacc0123n0, vi0123, vw, 0); vacc0123n1 = vfmaq_laneq_f32(vacc0123n1, vi0123, vw, 1); vacc0123n2 = vfmaq_laneq_f32(vacc0123n2, vi0123, vw, 2); vacc0123n3 = vfmaq_laneq_f32(vacc0123n3, vi0123, vw, 3); } while (--nnz != 0); } float32x4_t vout0123n0 = vminq_f32(vacc0123n0, vmax); float32x4_t vout0123n1 = vminq_f32(vacc0123n1, vmax); float32x4_t vout0123n2 = vminq_f32(vacc0123n2, vmax); float32x4_t vout0123n3 = vminq_f32(vacc0123n3, vmax); vout0123n0 = vmaxq_f32(vout0123n0, vmin); vout0123n1 = vmaxq_f32(vout0123n1, vmin); vout0123n2 = vmaxq_f32(vout0123n2, vmin); vout0123n3 = vmaxq_f32(vout0123n3, vmin); vst1q_f32(output + 0, vout0123n0); output = (float*) ((uintptr_t) output + output_stride); vst1q_f32(output + 0, vout0123n1); output = (float*) ((uintptr_t) output + output_stride); vst1q_f32(output + 0, vout0123n2); output = (float*) ((uintptr_t) output + output_stride); vst1q_f32(output + 0, vout0123n3); output = (float*) ((uintptr_t) output + output_stride); n -= 4; } // clean up loop, fall back to nr=1 if XNN_UNLIKELY(n != 0) { do { uint32_t nnz = *nnzmap++; float32x4_t vacc0123 = vld1q_dup_f32(w); w += 1; if XNN_LIKELY(nnz != 0) { do { const intptr_t diff = *dmap++; const float32x4_t vi0123 = vld1q_f32(input); input = (const float*) ((uintptr_t) input + (uintptr_t) diff); const float32x4_t vw = vld1q_dup_f32(w); w += 1; vacc0123 = vfmaq_f32(vacc0123, vi0123, vw); } while (--nnz != 0); } float32x4_t vout0123 = vminq_f32(vacc0123, vmax); vout0123 = vmaxq_f32(vout0123, vmin); vst1q_f32(output + 0, vout0123); output = (float*) ((uintptr_t) output + output_stride); n -= 1; } while (n != 0); } output = (float*) ((uintptr_t) output - output_decrement); input += 4; } output_decrement += 2 * sizeof(float); if (mc & (2 * sizeof(float))) { const float* w = weights; const int32_t* dmap = widx_dmap; const uint32_t* nnzmap = nidx_nnzmap; size_t n = nc; while (n >= 4) { uint32_t nnz = *nnzmap++; float32x2_t vacc01n0 = vld1_dup_f32(w); w += 1; float32x2_t vacc01n1 = vld1_dup_f32(w); w += 1; float32x2_t vacc01n2 = vld1_dup_f32(w); w += 1; float32x2_t vacc01n3 = vld1_dup_f32(w); w += 1; if XNN_LIKELY(nnz != 0) { do { const intptr_t diff = *dmap++; const float32x2_t vi01 = vld1_f32(input); input = (const float*) ((uintptr_t) input + (uintptr_t) diff); const float32x4_t vw = vld1q_f32(w); w += 4; vacc01n0 = vfma_laneq_f32(vacc01n0, vi01, vw, 0); vacc01n1 = vfma_laneq_f32(vacc01n1, vi01, vw, 1); vacc01n2 = vfma_laneq_f32(vacc01n2, vi01, vw, 2); vacc01n3 = vfma_laneq_f32(vacc01n3, vi01, vw, 3); } while (--nnz != 0); } float32x2_t vout01n0 = vmin_f32(vacc01n0, vget_low_f32(vmax)); float32x2_t vout01n1 = vmin_f32(vacc01n1, vget_low_f32(vmax)); float32x2_t vout01n2 = vmin_f32(vacc01n2, vget_low_f32(vmax)); float32x2_t vout01n3 = vmin_f32(vacc01n3, vget_low_f32(vmax)); vout01n0 = vmax_f32(vout01n0, vget_low_f32(vmin)); vout01n1 = vmax_f32(vout01n1, vget_low_f32(vmin)); vout01n2 = vmax_f32(vout01n2, vget_low_f32(vmin)); vout01n3 = vmax_f32(vout01n3, vget_low_f32(vmin)); vst1_f32(output + 0, vout01n0); output = (float*) ((uintptr_t) output + output_stride); vst1_f32(output + 0, vout01n1); output = (float*) ((uintptr_t) output + output_stride); vst1_f32(output + 0, vout01n2); output = (float*) ((uintptr_t) output + output_stride); vst1_f32(output + 0, vout01n3); output = (float*) ((uintptr_t) output + output_stride); n -= 4; } // clean up loop, fall back to nr=1 if XNN_UNLIKELY(n != 0) { do { uint32_t nnz = *nnzmap++; float32x2_t vacc01 = vld1_dup_f32(w); w += 1; if XNN_LIKELY(nnz != 0) { do { const intptr_t diff = *dmap++; const float32x2_t vi01 = vld1_f32(input); input = (const float*) ((uintptr_t) input + (uintptr_t) diff); const float32x2_t vw = vld1_dup_f32(w); w += 1; vacc01 = vfma_f32(vacc01, vi01, vw); } while (--nnz != 0); } float32x2_t vout01 = vmin_f32(vacc01, vget_low_f32(vmax)); vout01 = vmax_f32(vout01, vget_low_f32(vmin)); vst1_f32(output, vout01); output = (float*) ((uintptr_t) output + output_stride); n -= 1; } while (n != 0); } output = (float*) ((uintptr_t) output - output_decrement); input += 2; } output_decrement += 1 * sizeof(float); if (mc & (1 * sizeof(float))) { const float* w = weights; const int32_t* dmap = widx_dmap; const uint32_t* nnzmap = nidx_nnzmap; size_t n = nc; while (n >= 4) { uint32_t nnz = *nnzmap++; float32x2_t vacc0n0 = vld1_dup_f32(w); w += 1; float32x2_t vacc0n1 = vld1_dup_f32(w); w += 1; float32x2_t vacc0n2 = vld1_dup_f32(w); w += 1; float32x2_t vacc0n3 = vld1_dup_f32(w); w += 1; if XNN_LIKELY(nnz != 0) { do { const intptr_t diff = *dmap++; const float32x2_t vi0 = vld1_dup_f32(input); input = (const float*) ((uintptr_t) input + (uintptr_t) diff); const float32x4_t vw = vld1q_f32(w); w += 4; vacc0n0 = vfma_laneq_f32(vacc0n0, vi0, vw, 0); vacc0n1 = vfma_laneq_f32(vacc0n1, vi0, vw, 1); vacc0n2 = vfma_laneq_f32(vacc0n2, vi0, vw, 2); vacc0n3 = vfma_laneq_f32(vacc0n3, vi0, vw, 3); } while (--nnz != 0); } float32x2_t vout0n0 = vmin_f32(vacc0n0, vget_low_f32(vmax)); float32x2_t vout0n1 = vmin_f32(vacc0n1, vget_low_f32(vmax)); float32x2_t vout0n2 = vmin_f32(vacc0n2, vget_low_f32(vmax)); float32x2_t vout0n3 = vmin_f32(vacc0n3, vget_low_f32(vmax)); vout0n0 = vmax_f32(vout0n0, vget_low_f32(vmin)); vout0n1 = vmax_f32(vout0n1, vget_low_f32(vmin)); vout0n2 = vmax_f32(vout0n2, vget_low_f32(vmin)); vout0n3 = vmax_f32(vout0n3, vget_low_f32(vmin)); vst1_lane_f32(output + 0, vout0n0, 0); output = (float*) ((uintptr_t) output + output_stride); vst1_lane_f32(output + 0, vout0n1, 0); output = (float*) ((uintptr_t) output + output_stride); vst1_lane_f32(output + 0, vout0n2, 0); output = (float*) ((uintptr_t) output + output_stride); vst1_lane_f32(output + 0, vout0n3, 0); output = (float*) ((uintptr_t) output + output_stride); n -= 4; } // clean up loop, fall back to nr=1 if XNN_UNLIKELY(n != 0) { do { uint32_t nnz = *nnzmap++; float32x2_t vacc0 = vld1_dup_f32(w); w += 1; if XNN_LIKELY(nnz != 0) { do { const intptr_t diff = *dmap++; const float32x2_t vi0 = vld1_dup_f32(input); input = (const float*) ((uintptr_t) input + (uintptr_t) diff); const float32x2_t vw = vld1_dup_f32(w); w += 1; vacc0 = vfma_f32(vacc0, vi0, vw); } while (--nnz != 0); } float32x2_t vout0 = vmin_f32(vacc0, vget_low_f32(vmax)); vout0 = vmax_f32(vout0, vget_low_f32(vmin)); vst1_lane_f32(output, vout0, 1); output = (float*) ((uintptr_t) output + output_stride); n -= 1; } while (n != 0); } output = (float*) ((uintptr_t) output - output_decrement); input += 1; } } }
/******************************************************************************* * * FUNCTION: ApGetExpectedTypes * * PARAMETERS: Buffer - Where the formatted string is returned * ExpectedBTypes - Bitfield of expected data types * * RETURN: None, formatted string * * DESCRIPTION: Format the expected object types into a printable string. * ******************************************************************************/ static void ApGetExpectedTypes ( char *Buffer, UINT32 ExpectedBtypes) { UINT32 ThisRtype; UINT32 i; UINT32 j; j = 1; Buffer[0] = 0; ThisRtype = ACPI_RTYPE_INTEGER; for (i = 0; i < ACPI_NUM_RTYPES; i++) { if (ExpectedBtypes & ThisRtype) { ACPI_STRCAT (Buffer, &AcpiRtypeNames[i][j]); j = 0; } ThisRtype <<= 1; } }
/* If type is empty or only type qualifiers are present, add default type of id (otherwise grokdeclarator will default to int). */ static tree adjust_type_for_id_default (tree type) { if (!type) type = make_node (TREE_LIST); if (!TREE_VALUE (type)) TREE_VALUE (type) = objc_object_type; else if (TREE_CODE (TREE_VALUE (type)) == RECORD_TYPE && TYPED_OBJECT (TREE_VALUE (type))) error ("can not use an object as parameter to a method"); return type; }
/* * Unpack a 32x32 pixel polygon stipple from user memory using the * current pixel unpack settings. */ void _mesa_unpack_polygon_stipple( const GLubyte *pattern, GLuint dest[32], const struct gl_pixelstore_attrib *unpacking ) { GLubyte *ptrn = (GLubyte *) _mesa_unpack_bitmap(32, 32, pattern, unpacking); if (ptrn) { GLubyte *p = ptrn; GLint i; for (i = 0; i < 32; i++) { dest[i] = (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | (p[3] ); p += 4; } free(ptrn); } }
/** * This will revive all the uniques so the sim player * can kill them again. */ static void revive_uniques(void) { int i; for (i = 1; i < z_info->r_max - 1; i++) { struct monster_race *race = &r_info[i]; if (rf_has(race->flags, RF_UNIQUE)) race->max_num = 1; } }
/** * @file CudaLib/generate_euclidean_distance_matrix_second_step.h * @date Oct 30, 2014 * @author Bernd Doser, HITS gGmbH */ #pragma once #include <thrust/device_vector.h> namespace pink { /** * CUDA Kernel Device code * * Reduce temp. array d_tmp to final arrays d_euclidean_distance_matrix and d_best_rotation_matrix. */ template <typename T> __global__ void second_step_kernel(T *euclidean_distance_matrix, uint32_t *best_rotation_matrix, T const *first_step, uint32_t number_of_spatial_transformations, uint32_t som_size) { int i = blockDim.x * blockIdx.x + threadIdx.x; if (i >= som_size) return; T const *pFirstStep = first_step + i * number_of_spatial_transformations; T *pDist = euclidean_distance_matrix + i; *pDist = pFirstStep[0]; best_rotation_matrix[i] = 0; for (uint32_t n = 1; n < number_of_spatial_transformations; ++n) { if (pFirstStep[n] < *pDist) { *pDist = pFirstStep[n]; best_rotation_matrix[i] = n; } } } /** * Host function that prepares data array and passes it to the CUDA kernel. */ template <typename T> void generate_euclidean_distance_matrix_second_step(thrust::device_vector<T>& d_euclidean_distance_matrix, thrust::device_vector<uint32_t>& d_best_rotation_matrix, thrust::device_vector<T> const& d_first_step, uint32_t number_of_spatial_transformations, uint32_t som_size) { const uint32_t block_size = 16; const uint32_t grid_size = static_cast<uint32_t>(ceil(static_cast<float>(som_size) / block_size)); // Setup execution parameters dim3 dimBlock(block_size); dim3 dimGrid(grid_size); // Start kernel second_step_kernel<<<dimGrid, dimBlock>>>(thrust::raw_pointer_cast(&d_euclidean_distance_matrix[0]), thrust::raw_pointer_cast(&d_best_rotation_matrix[0]), thrust::raw_pointer_cast(&d_first_step[0]), number_of_spatial_transformations, som_size); gpuErrchk(cudaPeekAtLastError()); gpuErrchk(cudaDeviceSynchronize()); } } // namespace pink
/* * Copyright (c) 1997-1999, 2003 Massachusetts Institute of Technology * * 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 2 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, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ #include <stdio.h> #include <stdlib.h> #include "sched.h" int main(int argc, char **argv) { int **sched; int npes = -1, sortpe = -1, steps; if (argc >= 2) { npes = atoi(argv[1]); if (npes <= 0) { fprintf(stderr,"npes must be positive!"); return 1; } } if (argc >= 3) { sortpe = atoi(argv[2]); if (sortpe < 0 || sortpe >= npes) { fprintf(stderr,"sortpe must be between 0 and npes-1.\n"); return 1; } } if (npes != -1) { printf("Computing schedule for npes = %d:\n",npes); sched = make_comm_schedule(npes); if (!sched) { fprintf(stderr,"Out of memory!"); return 6; } if (steps = check_comm_schedule(sched,npes)) printf("schedule OK (takes %d steps to complete).\n", steps); else printf("schedule not OK.\n"); print_comm_schedule(sched, npes); if (sortpe != -1) { printf("\nSorting schedule for sortpe = %d...\n", sortpe); sort_comm_schedule(sched,npes,sortpe); if (steps = check_comm_schedule(sched,npes)) printf("schedule OK (takes %d steps to complete).\n", steps); else printf("schedule not OK.\n"); print_comm_schedule(sched, npes); printf("\nInverting schedule...\n"); invert_comm_schedule(sched,npes); if (steps = check_comm_schedule(sched,npes)) printf("schedule OK (takes %d steps to complete).\n", steps); else printf("schedule not OK.\n"); print_comm_schedule(sched, npes); free_comm_schedule(sched,npes); } } else { printf("Doing infinite tests...\n"); for (npes = 1; ; ++npes) { printf("npes = %d...",npes); sched = make_comm_schedule(npes); if (!sched) { fprintf(stderr,"Out of memory!\n"); return 5; } for (sortpe = 0; sortpe < npes; ++sortpe) { empty_comm_schedule(sched,npes); fill_comm_schedule(sched,npes); if (!check_comm_schedule(sched,npes)) { fprintf(stderr, "\n -- fill error for sortpe = %d!\n",sortpe); return 2; } sort_comm_schedule(sched,npes,sortpe); if (!check_comm_schedule(sched,npes)) { fprintf(stderr, "\n -- sort error for sortpe = %d!\n",sortpe); return 3; } invert_comm_schedule(sched,npes); if (!check_comm_schedule(sched,npes)) { fprintf(stderr, "\n -- invert error for sortpe = %d!\n", sortpe); return 4; } } free_comm_schedule(sched,npes); printf("OK\n"); if (npes % 50 == 0) printf("(...Hit Ctrl-C to stop...)\n"); } } return 0; }
/* Read no more than BUFSIZE bytes of data from FD, storing them to BUF. If TIMEOUT is non-zero, the operation aborts if no data is received after that many seconds. If TIMEOUT is -1, the value of opt.timeout is used for TIMEOUT. */ int fd_read (int fd, char *buf, int bufsize, double timeout) { struct transport_info *info; LAZY_RETRIEVE_INFO (info); if (!poll_internal (fd, info, WAIT_FOR_READ, timeout)) return -1; if (info && info->reader) return info->reader (fd, buf, bufsize, info->ctx); else return sock_read (fd, buf, bufsize); }
/* * read_cards: Reads the cards into the external variables num_in_rank and * num_in_suit; checks for bad cards and duplicate cards. */ void read_cards(void) { bool card_exists[NUM_RANKS][NUM_SUITS]; char c, rank_ch, suit_ch; int rank, suit; bool bad_card; int cards_read = 0; for (rank = 0; rank < NUM_RANKS; rank++) { num_in_rank[rank] = 0; for (suit = 0; suit < NUM_SUITS; suit++) card_exists[rank][suit] = false; } for (suit = 0; suit < NUM_SUITS; suit++) num_in_suit[suit] = 0; while (cards_read < NUM_CARDS) { bad_card = false; printf("Enter a card: "); rank_ch = getchar(); switch (rank_ch) { case '0': exit(EXIT_SUCCESS); case '2': rank = 0; break; case '3': rank = 1; break; case '4': rank = 2; break; case '5': rank = 3; break; case '6': rank = 4; break; case '7': rank = 5; break; case '8': rank = 6; break; case '9': rank = 7; break; case 't': case 'T': rank = 8; break; case 'j': case 'J': rank = 9; break; case 'q': case 'Q': rank = 10; break; case 'k': case 'K': rank = 11; break; case 'a': case 'A': rank = 12; break; default: bad_card = true; } suit_ch = getchar(); switch (suit_ch) { case 'c': case 'C': suit = 0; break; case 'd': case 'D': suit = 1; break; case 'h': case 'H': suit = 2; break; case 's': case 'S': suit = 3; break; default: bad_card = true; } while ((c = getchar()) != '\n') if (c != ' ') bad_card = true; if (bad_card) printf("Bad card; ignored.\n"); else if (card_exists[rank][suit]) printf("Duplicate card; ignored.\n"); else { num_in_rank[rank]++; num_in_suit[suit]++; card_exists[rank][suit] = true; cards_read++; } } }
/**************************************************************************/ /* */ /* Copyright (c) Microsoft Corporation. All rights reserved. */ /* */ /* This software is licensed under the Microsoft Software License */ /* Terms for Microsoft Azure RTOS. Full text of the license can be */ /* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ /* and in the root directory of this software. */ /* */ /**************************************************************************/ /**************************************************************************/ /**************************************************************************/ /** */ /** ThreadX Component */ /** */ /** Trace */ /** */ /**************************************************************************/ /**************************************************************************/ #ifndef TX_SOURCE_CODE #define TX_SOURCE_CODE #endif /* Include necessary system files. */ #include "tx_api.h" #include "tx_trace.h" /**************************************************************************/ /* */ /* FUNCTION RELEASE */ /* */ /* _tx_trace_buffer_full_notify PORTABLE C */ /* 6.1 */ /* AUTHOR */ /* */ /* William E. Lamie, Microsoft Corporation */ /* */ /* DESCRIPTION */ /* */ /* This function sets up the application callback function that is */ /* called whenever the trace buffer becomes full. The application */ /* can then swap to a new trace buffer in order not to lose any */ /* events. */ /* */ /* INPUT */ /* */ /* full_buffer_callback Full trace buffer processing */ /* function */ /* */ /* OUTPUT */ /* */ /* Completion Status */ /* */ /* CALLS */ /* */ /* None */ /* */ /* CALLED BY */ /* */ /* Application Code */ /* */ /* RELEASE HISTORY */ /* */ /* DATE NAME DESCRIPTION */ /* */ /* 05-19-2020 William E. Lamie Initial Version 6.0 */ /* 09-30-2020 Yuxin Zhou Modified comment(s), */ /* resulting in version 6.1 */ /* */ /**************************************************************************/ UINT _tx_trace_buffer_full_notify(VOID (*full_buffer_callback)(VOID *buffer)) { #ifdef TX_ENABLE_EVENT_TRACE /* Setup the callback function pointer. */ _tx_trace_full_notify_function = full_buffer_callback; /* Return success. */ return(TX_SUCCESS); #else UINT status; /* Access input arguments just for the sake of lint, MISRA, etc. */ if (full_buffer_callback != TX_NULL) { /* Trace not enabled, return an error. */ status = TX_FEATURE_NOT_ENABLED; } else { /* Trace not enabled, return an error. */ status = TX_FEATURE_NOT_ENABLED; } /* Return completion status. */ return(status); #endif }
/* * APIC support * * Copyright (c) 2004-2005 Fabrice Bellard * * 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, see <http://www.gnu.org/licenses/> */ #include "qemu/osdep.h" #include "qemu/thread.h" #include "qemu/error-report.h" #include "hw/i386/apic_internal.h" #include "hw/i386/apic.h" #include "hw/intc/ioapic.h" #include "hw/intc/i8259.h" #include "hw/intc/kvm_irqcount.h" #include "hw/pci/msi.h" #include "qemu/host-utils.h" #include "sysemu/kvm.h" #include "trace.h" #include "hw/i386/apic-msidef.h" #include "qapi/error.h" #include "qom/object.h" #define MAX_APICS 255 #define MAX_APIC_WORDS 8 #define SYNC_FROM_VAPIC 0x1 #define SYNC_TO_VAPIC 0x2 #define SYNC_ISR_IRR_TO_VAPIC 0x4 static APICCommonState *local_apics[MAX_APICS + 1]; #define TYPE_APIC "apic" /*This is reusing the APICCommonState typedef from APIC_COMMON */ DECLARE_INSTANCE_CHECKER(APICCommonState, APIC, TYPE_APIC) static void apic_set_irq(APICCommonState *s, int vector_num, int trigger_mode); static void apic_update_irq(APICCommonState *s); static void apic_get_delivery_bitmask(uint32_t *deliver_bitmask, uint8_t dest, uint8_t dest_mode); /* Find first bit starting from msb */ static int apic_fls_bit(uint32_t value) { return 31 - clz32(value); } /* Find first bit starting from lsb */ static int apic_ffs_bit(uint32_t value) { return ctz32(value); } static inline void apic_reset_bit(uint32_t *tab, int index) { int i, mask; i = index >> 5; mask = 1 << (index & 0x1f); tab[i] &= ~mask; } /* return -1 if no bit is set */ static int get_highest_priority_int(uint32_t *tab) { int i; for (i = 7; i >= 0; i--) { if (tab[i] != 0) { return i * 32 + apic_fls_bit(tab[i]); } } return -1; } static void apic_sync_vapic(APICCommonState *s, int sync_type) { VAPICState vapic_state; size_t length; off_t start; int vector; if (!s->vapic_paddr) { return; } if (sync_type & SYNC_FROM_VAPIC) { cpu_physical_memory_read(s->vapic_paddr, &vapic_state, sizeof(vapic_state)); s->tpr = vapic_state.tpr; } if (sync_type & (SYNC_TO_VAPIC | SYNC_ISR_IRR_TO_VAPIC)) { start = offsetof(VAPICState, isr); length = offsetof(VAPICState, enabled) - offsetof(VAPICState, isr); if (sync_type & SYNC_TO_VAPIC) { assert(qemu_cpu_is_self(CPU(s->cpu))); vapic_state.tpr = s->tpr; vapic_state.enabled = 1; start = 0; length = sizeof(VAPICState); } vector = get_highest_priority_int(s->isr); if (vector < 0) { vector = 0; } vapic_state.isr = vector & 0xf0; vapic_state.zero = 0; vector = get_highest_priority_int(s->irr); if (vector < 0) { vector = 0; } vapic_state.irr = vector & 0xff; address_space_write_rom(&address_space_memory, s->vapic_paddr + start, MEMTXATTRS_UNSPECIFIED, ((void *)&vapic_state) + start, length); } } static void apic_vapic_base_update(APICCommonState *s) { apic_sync_vapic(s, SYNC_TO_VAPIC); } static void apic_local_deliver(APICCommonState *s, int vector) { uint32_t lvt = s->lvt[vector]; int trigger_mode; trace_apic_local_deliver(vector, (lvt >> 8) & 7); if (lvt & APIC_LVT_MASKED) return; switch ((lvt >> 8) & 7) { case APIC_DM_SMI: cpu_interrupt(CPU(s->cpu), CPU_INTERRUPT_SMI); break; case APIC_DM_NMI: cpu_interrupt(CPU(s->cpu), CPU_INTERRUPT_NMI); break; case APIC_DM_EXTINT: cpu_interrupt(CPU(s->cpu), CPU_INTERRUPT_HARD); break; case APIC_DM_FIXED: trigger_mode = APIC_TRIGGER_EDGE; if ((vector == APIC_LVT_LINT0 || vector == APIC_LVT_LINT1) && (lvt & APIC_LVT_LEVEL_TRIGGER)) trigger_mode = APIC_TRIGGER_LEVEL; apic_set_irq(s, lvt & 0xff, trigger_mode); } } void apic_deliver_pic_intr(DeviceState *dev, int level) { APICCommonState *s = APIC(dev); if (level) { apic_local_deliver(s, APIC_LVT_LINT0); } else { uint32_t lvt = s->lvt[APIC_LVT_LINT0]; switch ((lvt >> 8) & 7) { case APIC_DM_FIXED: if (!(lvt & APIC_LVT_LEVEL_TRIGGER)) break; apic_reset_bit(s->irr, lvt & 0xff); /* fall through */ case APIC_DM_EXTINT: apic_update_irq(s); break; } } } static void apic_external_nmi(APICCommonState *s) { apic_local_deliver(s, APIC_LVT_LINT1); } #define foreach_apic(apic, deliver_bitmask, code) \ {\ int __i, __j;\ for(__i = 0; __i < MAX_APIC_WORDS; __i++) {\ uint32_t __mask = deliver_bitmask[__i];\ if (__mask) {\ for(__j = 0; __j < 32; __j++) {\ if (__mask & (1U << __j)) {\ apic = local_apics[__i * 32 + __j];\ if (apic) {\ code;\ }\ }\ }\ }\ }\ } static void apic_bus_deliver(const uint32_t *deliver_bitmask, uint8_t delivery_mode, uint8_t vector_num, uint8_t trigger_mode) { APICCommonState *apic_iter; switch (delivery_mode) { case APIC_DM_LOWPRI: /* XXX: search for focus processor, arbitration */ { int i, d; d = -1; for(i = 0; i < MAX_APIC_WORDS; i++) { if (deliver_bitmask[i]) { d = i * 32 + apic_ffs_bit(deliver_bitmask[i]); break; } } if (d >= 0) { apic_iter = local_apics[d]; if (apic_iter) { apic_set_irq(apic_iter, vector_num, trigger_mode); } } } return; case APIC_DM_FIXED: break; case APIC_DM_SMI: foreach_apic(apic_iter, deliver_bitmask, cpu_interrupt(CPU(apic_iter->cpu), CPU_INTERRUPT_SMI) ); return; case APIC_DM_NMI: foreach_apic(apic_iter, deliver_bitmask, cpu_interrupt(CPU(apic_iter->cpu), CPU_INTERRUPT_NMI) ); return; case APIC_DM_INIT: /* normal INIT IPI sent to processors */ foreach_apic(apic_iter, deliver_bitmask, cpu_interrupt(CPU(apic_iter->cpu), CPU_INTERRUPT_INIT) ); return; case APIC_DM_EXTINT: /* handled in I/O APIC code */ break; default: return; } foreach_apic(apic_iter, deliver_bitmask, apic_set_irq(apic_iter, vector_num, trigger_mode) ); } void apic_deliver_irq(uint8_t dest, uint8_t dest_mode, uint8_t delivery_mode, uint8_t vector_num, uint8_t trigger_mode) { uint32_t deliver_bitmask[MAX_APIC_WORDS]; trace_apic_deliver_irq(dest, dest_mode, delivery_mode, vector_num, trigger_mode); apic_get_delivery_bitmask(deliver_bitmask, dest, dest_mode); apic_bus_deliver(deliver_bitmask, delivery_mode, vector_num, trigger_mode); } static void apic_set_base(APICCommonState *s, uint64_t val) { s->apicbase = (val & 0xfffff000) | (s->apicbase & (MSR_IA32_APICBASE_BSP | MSR_IA32_APICBASE_ENABLE)); /* if disabled, cannot be enabled again */ if (!(val & MSR_IA32_APICBASE_ENABLE)) { s->apicbase &= ~MSR_IA32_APICBASE_ENABLE; cpu_clear_apic_feature(&s->cpu->env); s->spurious_vec &= ~APIC_SV_ENABLE; } } static void apic_set_tpr(APICCommonState *s, uint8_t val) { /* Updates from cr8 are ignored while the VAPIC is active */ if (!s->vapic_paddr) { s->tpr = val << 4; apic_update_irq(s); } } int apic_get_highest_priority_irr(DeviceState *dev) { APICCommonState *s; if (!dev) { /* no interrupts */ return -1; } s = APIC_COMMON(dev); return get_highest_priority_int(s->irr); } static uint8_t apic_get_tpr(APICCommonState *s) { apic_sync_vapic(s, SYNC_FROM_VAPIC); return s->tpr >> 4; } int apic_get_ppr(APICCommonState *s) { int tpr, isrv, ppr; tpr = (s->tpr >> 4); isrv = get_highest_priority_int(s->isr); if (isrv < 0) isrv = 0; isrv >>= 4; if (tpr >= isrv) ppr = s->tpr; else ppr = isrv << 4; return ppr; } static int apic_get_arb_pri(APICCommonState *s) { /* XXX: arbitration */ return 0; } /* * <0 - low prio interrupt, * 0 - no interrupt, * >0 - interrupt number */ static int apic_irq_pending(APICCommonState *s) { int irrv, ppr; if (!(s->spurious_vec & APIC_SV_ENABLE)) { return 0; } irrv = get_highest_priority_int(s->irr); if (irrv < 0) { return 0; } ppr = apic_get_ppr(s); if (ppr && (irrv & 0xf0) <= (ppr & 0xf0)) { return -1; } return irrv; } /* signal the CPU if an irq is pending */ static void apic_update_irq(APICCommonState *s) { CPUState *cpu; DeviceState *dev = (DeviceState *)s; cpu = CPU(s->cpu); if (!qemu_cpu_is_self(cpu)) { cpu_interrupt(cpu, CPU_INTERRUPT_POLL); } else if (apic_irq_pending(s) > 0) { cpu_interrupt(cpu, CPU_INTERRUPT_HARD); } else if (!apic_accept_pic_intr(dev) || !pic_get_output(isa_pic)) { cpu_reset_interrupt(cpu, CPU_INTERRUPT_HARD); } } void apic_poll_irq(DeviceState *dev) { APICCommonState *s = APIC(dev); apic_sync_vapic(s, SYNC_FROM_VAPIC); apic_update_irq(s); } static void apic_set_irq(APICCommonState *s, int vector_num, int trigger_mode) { kvm_report_irq_delivered(!apic_get_bit(s->irr, vector_num)); apic_set_bit(s->irr, vector_num); if (trigger_mode) apic_set_bit(s->tmr, vector_num); else apic_reset_bit(s->tmr, vector_num); if (s->vapic_paddr) { apic_sync_vapic(s, SYNC_ISR_IRR_TO_VAPIC); /* * The vcpu thread needs to see the new IRR before we pull its current * TPR value. That way, if we miss a lowering of the TRP, the guest * has the chance to notice the new IRR and poll for IRQs on its own. */ smp_wmb(); apic_sync_vapic(s, SYNC_FROM_VAPIC); } apic_update_irq(s); } static void apic_eoi(APICCommonState *s) { int isrv; isrv = get_highest_priority_int(s->isr); if (isrv < 0) return; apic_reset_bit(s->isr, isrv); if (!(s->spurious_vec & APIC_SV_DIRECTED_IO) && apic_get_bit(s->tmr, isrv)) { ioapic_eoi_broadcast(isrv); } apic_sync_vapic(s, SYNC_FROM_VAPIC | SYNC_TO_VAPIC); apic_update_irq(s); } static int apic_find_dest(uint8_t dest) { APICCommonState *apic = local_apics[dest]; int i; if (apic && apic->id == dest) return dest; /* shortcut in case apic->id == local_apics[dest]->id */ for (i = 0; i < MAX_APICS; i++) { apic = local_apics[i]; if (apic && apic->id == dest) return i; if (!apic) break; } return -1; } static void apic_get_delivery_bitmask(uint32_t *deliver_bitmask, uint8_t dest, uint8_t dest_mode) { APICCommonState *apic_iter; int i; if (dest_mode == 0) { if (dest == 0xff) { memset(deliver_bitmask, 0xff, MAX_APIC_WORDS * sizeof(uint32_t)); } else { int idx = apic_find_dest(dest); memset(deliver_bitmask, 0x00, MAX_APIC_WORDS * sizeof(uint32_t)); if (idx >= 0) apic_set_bit(deliver_bitmask, idx); } } else { /* XXX: cluster mode */ memset(deliver_bitmask, 0x00, MAX_APIC_WORDS * sizeof(uint32_t)); for(i = 0; i < MAX_APICS; i++) { apic_iter = local_apics[i]; if (apic_iter) { if (apic_iter->dest_mode == 0xf) { if (dest & apic_iter->log_dest) apic_set_bit(deliver_bitmask, i); } else if (apic_iter->dest_mode == 0x0) { if ((dest & 0xf0) == (apic_iter->log_dest & 0xf0) && (dest & apic_iter->log_dest & 0x0f)) { apic_set_bit(deliver_bitmask, i); } } } else { break; } } } } static void apic_startup(APICCommonState *s, int vector_num) { s->sipi_vector = vector_num; cpu_interrupt(CPU(s->cpu), CPU_INTERRUPT_SIPI); } void apic_sipi(DeviceState *dev) { APICCommonState *s = APIC(dev); cpu_reset_interrupt(CPU(s->cpu), CPU_INTERRUPT_SIPI); if (!s->wait_for_sipi) return; cpu_x86_load_seg_cache_sipi(s->cpu, s->sipi_vector); s->wait_for_sipi = 0; } static void apic_deliver(DeviceState *dev, uint8_t dest, uint8_t dest_mode, uint8_t delivery_mode, uint8_t vector_num, uint8_t trigger_mode) { APICCommonState *s = APIC(dev); uint32_t deliver_bitmask[MAX_APIC_WORDS]; int dest_shorthand = (s->icr[0] >> 18) & 3; APICCommonState *apic_iter; switch (dest_shorthand) { case 0: apic_get_delivery_bitmask(deliver_bitmask, dest, dest_mode); break; case 1: memset(deliver_bitmask, 0x00, sizeof(deliver_bitmask)); apic_set_bit(deliver_bitmask, s->id); break; case 2: memset(deliver_bitmask, 0xff, sizeof(deliver_bitmask)); break; case 3: memset(deliver_bitmask, 0xff, sizeof(deliver_bitmask)); apic_reset_bit(deliver_bitmask, s->id); break; } switch (delivery_mode) { case APIC_DM_INIT: { int trig_mode = (s->icr[0] >> 15) & 1; int level = (s->icr[0] >> 14) & 1; if (level == 0 && trig_mode == 1) { foreach_apic(apic_iter, deliver_bitmask, apic_iter->arb_id = apic_iter->id ); return; } } break; case APIC_DM_SIPI: foreach_apic(apic_iter, deliver_bitmask, apic_startup(apic_iter, vector_num) ); return; } apic_bus_deliver(deliver_bitmask, delivery_mode, vector_num, trigger_mode); } static bool apic_check_pic(APICCommonState *s) { DeviceState *dev = (DeviceState *)s; if (!apic_accept_pic_intr(dev) || !pic_get_output(isa_pic)) { return false; } apic_deliver_pic_intr(dev, 1); return true; } int apic_get_interrupt(DeviceState *dev) { APICCommonState *s = APIC(dev); int intno; /* if the APIC is installed or enabled, we let the 8259 handle the IRQs */ if (!s) return -1; if (!(s->spurious_vec & APIC_SV_ENABLE)) return -1; apic_sync_vapic(s, SYNC_FROM_VAPIC); intno = apic_irq_pending(s); /* if there is an interrupt from the 8259, let the caller handle * that first since ExtINT interrupts ignore the priority. */ if (intno == 0 || apic_check_pic(s)) { apic_sync_vapic(s, SYNC_TO_VAPIC); return -1; } else if (intno < 0) { apic_sync_vapic(s, SYNC_TO_VAPIC); return s->spurious_vec & 0xff; } apic_reset_bit(s->irr, intno); apic_set_bit(s->isr, intno); apic_sync_vapic(s, SYNC_TO_VAPIC); apic_update_irq(s); return intno; } int apic_accept_pic_intr(DeviceState *dev) { APICCommonState *s = APIC(dev); uint32_t lvt0; if (!s) return -1; lvt0 = s->lvt[APIC_LVT_LINT0]; if ((s->apicbase & MSR_IA32_APICBASE_ENABLE) == 0 || (lvt0 & APIC_LVT_MASKED) == 0) return isa_pic != NULL; return 0; } static void apic_timer_update(APICCommonState *s, int64_t current_time) { if (apic_next_timer(s, current_time)) { timer_mod(s->timer, s->next_time); } else { timer_del(s->timer); } } static void apic_timer(void *opaque) { APICCommonState *s = opaque; apic_local_deliver(s, APIC_LVT_TIMER); apic_timer_update(s, s->next_time); } static uint64_t apic_mem_read(void *opaque, hwaddr addr, unsigned size) { DeviceState *dev; APICCommonState *s; uint32_t val; int index; if (size < 4) { return 0; } dev = cpu_get_current_apic(); if (!dev) { return 0; } s = APIC(dev); index = (addr >> 4) & 0xff; switch(index) { case 0x02: /* id */ val = s->id << 24; break; case 0x03: /* version */ val = s->version | ((APIC_LVT_NB - 1) << 16); break; case 0x08: apic_sync_vapic(s, SYNC_FROM_VAPIC); if (apic_report_tpr_access) { cpu_report_tpr_access(&s->cpu->env, TPR_ACCESS_READ); } val = s->tpr; break; case 0x09: val = apic_get_arb_pri(s); break; case 0x0a: /* ppr */ val = apic_get_ppr(s); break; case 0x0b: val = 0; break; case 0x0d: val = s->log_dest << 24; break; case 0x0e: val = (s->dest_mode << 28) | 0xfffffff; break; case 0x0f: val = s->spurious_vec; break; case 0x10 ... 0x17: val = s->isr[index & 7]; break; case 0x18 ... 0x1f: val = s->tmr[index & 7]; break; case 0x20 ... 0x27: val = s->irr[index & 7]; break; case 0x28: val = s->esr; break; case 0x30: case 0x31: val = s->icr[index & 1]; break; case 0x32 ... 0x37: val = s->lvt[index - 0x32]; break; case 0x38: val = s->initial_count; break; case 0x39: val = apic_get_current_count(s); break; case 0x3e: val = s->divide_conf; break; default: s->esr |= APIC_ESR_ILLEGAL_ADDRESS; val = 0; break; } trace_apic_mem_readl(addr, val); return val; } static void apic_send_msi(MSIMessage *msi) { uint64_t addr = msi->address; uint32_t data = msi->data; uint8_t dest = (addr & MSI_ADDR_DEST_ID_MASK) >> MSI_ADDR_DEST_ID_SHIFT; uint8_t vector = (data & MSI_DATA_VECTOR_MASK) >> MSI_DATA_VECTOR_SHIFT; uint8_t dest_mode = (addr >> MSI_ADDR_DEST_MODE_SHIFT) & 0x1; uint8_t trigger_mode = (data >> MSI_DATA_TRIGGER_SHIFT) & 0x1; uint8_t delivery = (data >> MSI_DATA_DELIVERY_MODE_SHIFT) & 0x7; /* XXX: Ignore redirection hint. */ apic_deliver_irq(dest, dest_mode, delivery, vector, trigger_mode); } static void apic_mem_write(void *opaque, hwaddr addr, uint64_t val, unsigned size) { DeviceState *dev; APICCommonState *s; int index = (addr >> 4) & 0xff; if (size < 4) { return; } if (addr > 0xfff || !index) { /* MSI and MMIO APIC are at the same memory location, * but actually not on the global bus: MSI is on PCI bus * APIC is connected directly to the CPU. * Mapping them on the global bus happens to work because * MSI registers are reserved in APIC MMIO and vice versa. */ MSIMessage msi = { .address = addr, .data = val }; apic_send_msi(&msi); return; } dev = cpu_get_current_apic(); if (!dev) { return; } s = APIC(dev); trace_apic_mem_writel(addr, val); switch(index) { case 0x02: s->id = (val >> 24); break; case 0x03: break; case 0x08: if (apic_report_tpr_access) { cpu_report_tpr_access(&s->cpu->env, TPR_ACCESS_WRITE); } s->tpr = val; apic_sync_vapic(s, SYNC_TO_VAPIC); apic_update_irq(s); break; case 0x09: case 0x0a: break; case 0x0b: /* EOI */ apic_eoi(s); break; case 0x0d: s->log_dest = val >> 24; break; case 0x0e: s->dest_mode = val >> 28; break; case 0x0f: s->spurious_vec = val & 0x1ff; apic_update_irq(s); break; case 0x10 ... 0x17: case 0x18 ... 0x1f: case 0x20 ... 0x27: case 0x28: break; case 0x30: s->icr[0] = val; apic_deliver(dev, (s->icr[1] >> 24) & 0xff, (s->icr[0] >> 11) & 1, (s->icr[0] >> 8) & 7, (s->icr[0] & 0xff), (s->icr[0] >> 15) & 1); break; case 0x31: s->icr[1] = val; break; case 0x32 ... 0x37: { int n = index - 0x32; s->lvt[n] = val; if (n == APIC_LVT_TIMER) { apic_timer_update(s, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL)); } else if (n == APIC_LVT_LINT0 && apic_check_pic(s)) { apic_update_irq(s); } } break; case 0x38: s->initial_count = val; s->initial_count_load_time = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); apic_timer_update(s, s->initial_count_load_time); break; case 0x39: break; case 0x3e: { int v; s->divide_conf = val & 0xb; v = (s->divide_conf & 3) | ((s->divide_conf >> 1) & 4); s->count_shift = (v + 1) & 7; } break; default: s->esr |= APIC_ESR_ILLEGAL_ADDRESS; break; } } static void apic_pre_save(APICCommonState *s) { apic_sync_vapic(s, SYNC_FROM_VAPIC); } static void apic_post_load(APICCommonState *s) { if (s->timer_expiry != -1) { timer_mod(s->timer, s->timer_expiry); } else { timer_del(s->timer); } } static const MemoryRegionOps apic_io_ops = { .read = apic_mem_read, .write = apic_mem_write, .impl.min_access_size = 1, .impl.max_access_size = 4, .valid.min_access_size = 1, .valid.max_access_size = 4, .endianness = DEVICE_NATIVE_ENDIAN, }; static void apic_realize(DeviceState *dev, Error **errp) { APICCommonState *s = APIC(dev); if (s->id >= MAX_APICS) { error_setg(errp, "%s initialization failed. APIC ID %d is invalid", object_get_typename(OBJECT(dev)), s->id); return; } if (kvm_enabled()) { warn_report("Userspace local APIC is deprecated for KVM."); warn_report("Do not use kernel-irqchip except for the -M isapc machine type."); } memory_region_init_io(&s->io_memory, OBJECT(s), &apic_io_ops, s, "apic-msi", APIC_SPACE_SIZE); s->timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, apic_timer, s); local_apics[s->id] = s; msi_nonbroken = true; } static void apic_unrealize(DeviceState *dev) { APICCommonState *s = APIC(dev); timer_free(s->timer); local_apics[s->id] = NULL; } static void apic_class_init(ObjectClass *klass, void *data) { APICCommonClass *k = APIC_COMMON_CLASS(klass); k->realize = apic_realize; k->unrealize = apic_unrealize; k->set_base = apic_set_base; k->set_tpr = apic_set_tpr; k->get_tpr = apic_get_tpr; k->vapic_base_update = apic_vapic_base_update; k->external_nmi = apic_external_nmi; k->pre_save = apic_pre_save; k->post_load = apic_post_load; k->send_msi = apic_send_msi; } static const TypeInfo apic_info = { .name = TYPE_APIC, .instance_size = sizeof(APICCommonState), .parent = TYPE_APIC_COMMON, .class_init = apic_class_init, }; static void apic_register_types(void) { type_register_static(&apic_info); } type_init(apic_register_types)
// Move to a new parent mem context __attribute__((always_inline)) static inline StringList * strLstMove(StringList *const this, MemContext *const parentNew) { return (StringList *)lstMove((List *)this, parentNew); }
/* * Copyright (c) 2009, Giampaolo Rodola', Landry Breuil. * All rights reserved. * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ #include <Python.h> #include <fcntl.h> #include <sys/types.h> #include <sys/param.h> #include <sys/sysctl.h> #include <sys/proc.h> #include <kvm.h> #include "../../_psutil_common.h" #include "../../_psutil_posix.h" #define PSUTIL_KPT2DOUBLE(t) (t ## _sec + t ## _usec / 1000000.0) // #define PSUTIL_TV2DOUBLE(t) ((t).tv_sec + (t).tv_usec / 1000000.0) // ============================================================================ // Utility functions // ============================================================================ int psutil_kinfo_proc(pid_t pid, struct kinfo_proc *proc) { // Fills a kinfo_proc struct based on process pid. int ret; int mib[6]; size_t size = sizeof(struct kinfo_proc); mib[0] = CTL_KERN; mib[1] = KERN_PROC; mib[2] = KERN_PROC_PID; mib[3] = pid; mib[4] = size; mib[5] = 1; ret = sysctl((int*)mib, 6, proc, &size, NULL, 0); if (ret == -1) { PyErr_SetFromErrno(PyExc_OSError); return -1; } // sysctl stores 0 in the size if we can't find the process information. if (size == 0) { NoSuchProcess("sysctl (size = 0)"); return -1; } return 0; } struct kinfo_file * kinfo_getfile(pid_t pid, int* cnt) { // Mimic's FreeBSD kinfo_file call, taking a pid and a ptr to an // int as arg and returns an array with cnt struct kinfo_file. int mib[6]; size_t len; struct kinfo_file* kf; mib[0] = CTL_KERN; mib[1] = KERN_FILE; mib[2] = KERN_FILE_BYPID; mib[3] = pid; mib[4] = sizeof(struct kinfo_file); mib[5] = 0; /* get the size of what would be returned */ if (sysctl(mib, 6, NULL, &len, NULL, 0) < 0) { PyErr_SetFromErrno(PyExc_OSError); return NULL; } if ((kf = malloc(len)) == NULL) { PyErr_NoMemory(); return NULL; } mib[5] = (int)(len / sizeof(struct kinfo_file)); if (sysctl(mib, 6, kf, &len, NULL, 0) < 0) { free(kf); PyErr_SetFromErrno(PyExc_OSError); return NULL; } *cnt = (int)(len / sizeof(struct kinfo_file)); return kf; } // ============================================================================ // APIS // ============================================================================ int psutil_get_proc_list(struct kinfo_proc **procList, size_t *procCount) { // Returns a list of all BSD processes on the system. This routine // allocates the list and puts it in *procList and a count of the // number of entries in *procCount. You are responsible for freeing // this list (use "free" from System framework). // On success, the function returns 0. // On error, the function returns a BSD errno value. struct kinfo_proc *result; // Declaring name as const requires us to cast it when passing it to // sysctl because the prototype doesn't include the const modifier. char errbuf[_POSIX2_LINE_MAX]; int cnt; kvm_t *kd; assert(procList != NULL); assert(*procList == NULL); assert(procCount != NULL); kd = kvm_openfiles(NULL, NULL, NULL, KVM_NO_FILES, errbuf); if (! kd) { convert_kvm_err("kvm_openfiles", errbuf); return 1; } result = kvm_getprocs(kd, KERN_PROC_ALL, 0, sizeof(struct kinfo_proc), &cnt); if (result == NULL) { PyErr_Format(PyExc_RuntimeError, "kvm_getprocs syscall failed"); kvm_close(kd); return 1; } *procCount = (size_t)cnt; size_t mlen = cnt * sizeof(struct kinfo_proc); if ((*procList = malloc(mlen)) == NULL) { PyErr_NoMemory(); kvm_close(kd); return 1; } memcpy(*procList, result, mlen); assert(*procList != NULL); kvm_close(kd); return 0; } // TODO: refactor this (it's clunky) PyObject * psutil_proc_cmdline(PyObject *self, PyObject *args) { pid_t pid; int mib[4]; static char **argv; char **p; size_t argv_size = 128; PyObject *py_retlist = PyList_New(0); PyObject *py_arg = NULL; if (py_retlist == NULL) return NULL; if (! PyArg_ParseTuple(args, _Py_PARSE_PID, &pid)) goto error; mib[0] = CTL_KERN; mib[1] = KERN_PROC_ARGS; mib[2] = pid; mib[3] = KERN_PROC_ARGV; // Loop and reallocate until we have enough space to fit argv. for (;; argv_size *= 2) { if (argv_size >= 8192) { PyErr_SetString(PyExc_RuntimeError, "can't allocate enough space for KERN_PROC_ARGV"); goto error; } if ((argv = realloc(argv, argv_size)) == NULL) continue; if (sysctl(mib, 4, argv, &argv_size, NULL, 0) == 0) break; if (errno == ENOMEM) continue; PyErr_SetFromErrno(PyExc_OSError); goto error; } for (p = argv; *p != NULL; p++) { py_arg = PyUnicode_DecodeFSDefault(*p); if (!py_arg) goto error; if (PyList_Append(py_retlist, py_arg)) goto error; Py_DECREF(py_arg); } return py_retlist; error: Py_XDECREF(py_arg); Py_DECREF(py_retlist); return NULL; } PyObject * psutil_proc_threads(PyObject *self, PyObject *args) { // OpenBSD reference: // https://github.com/janmojzis/pstree/blob/master/proc_kvm.c // Note: this requires root access, else it will fail trying // to access /dev/kmem. pid_t pid; kvm_t *kd = NULL; int nentries, i; char errbuf[4096]; struct kinfo_proc *kp; PyObject *py_retlist = PyList_New(0); PyObject *py_tuple = NULL; if (py_retlist == NULL) return NULL; if (! PyArg_ParseTuple(args, _Py_PARSE_PID, &pid)) goto error; kd = kvm_openfiles(0, 0, 0, O_RDONLY, errbuf); if (! kd) { convert_kvm_err("kvm_openfiles()", errbuf); goto error; } kp = kvm_getprocs( kd, KERN_PROC_PID | KERN_PROC_SHOW_THREADS | KERN_PROC_KTHREAD, pid, sizeof(*kp), &nentries); if (! kp) { if (strstr(errbuf, "Permission denied") != NULL) AccessDenied("kvm_getprocs"); else PyErr_Format(PyExc_RuntimeError, "kvm_getprocs() syscall failed"); goto error; } for (i = 0; i < nentries; i++) { if (kp[i].p_tid < 0) continue; if (kp[i].p_pid == pid) { py_tuple = Py_BuildValue( _Py_PARSE_PID "dd", kp[i].p_tid, PSUTIL_KPT2DOUBLE(kp[i].p_uutime), PSUTIL_KPT2DOUBLE(kp[i].p_ustime)); if (py_tuple == NULL) goto error; if (PyList_Append(py_retlist, py_tuple)) goto error; Py_DECREF(py_tuple); } } kvm_close(kd); return py_retlist; error: Py_XDECREF(py_tuple); Py_DECREF(py_retlist); if (kd != NULL) kvm_close(kd); return NULL; } PyObject * psutil_proc_num_fds(PyObject *self, PyObject *args) { pid_t pid; int cnt; struct kinfo_file *freep; struct kinfo_proc kipp; if (! PyArg_ParseTuple(args, _Py_PARSE_PID, &pid)) return NULL; if (psutil_kinfo_proc(pid, &kipp) == -1) return NULL; freep = kinfo_getfile(pid, &cnt); if (freep == NULL) return NULL; free(freep); return Py_BuildValue("i", cnt); } PyObject * psutil_proc_cwd(PyObject *self, PyObject *args) { // Reference: // https://github.com/openbsd/src/blob/ // 588f7f8c69786211f2d16865c552afb91b1c7cba/bin/ps/print.c#L191 pid_t pid; struct kinfo_proc kp; char path[MAXPATHLEN]; size_t pathlen = sizeof path; if (! PyArg_ParseTuple(args, _Py_PARSE_PID, &pid)) return NULL; if (psutil_kinfo_proc(pid, &kp) == -1) return NULL; int name[] = { CTL_KERN, KERN_PROC_CWD, pid }; if (sysctl(name, 3, path, &pathlen, NULL, 0) != 0) { if (errno == ENOENT) { psutil_debug("sysctl(KERN_PROC_CWD) -> ENOENT converted to ''"); return Py_BuildValue("s", ""); } else { PyErr_SetFromErrno(PyExc_OSError); return NULL; } } return PyUnicode_DecodeFSDefault(path); }
// REQUIRES: powerpc-registered-target // RUN: %clang_cc1 -triple powerpc64-unknown-unknown -target-cpu pwr10 \ // RUN: -fsyntax-only -Wall -Werror -verify %s // RUN: %clang_cc1 -triple powerpc64le-unknown-unknown -target-cpu pwr10 \ // RUN: -fsyntax-only -Wall -Werror -verify %s // RUN: %clang_cc1 -triple powerpc64-unknown-aix -target-cpu pwr10 \ // RUN: -fsyntax-only -Wall -Werror -verify %s // RUN: %clang_cc1 -triple powerpc-unknown-aix -target-cpu pwr10 \ // RUN: -fsyntax-only -Wall -Werror -verify %s #include <altivec.h> vector unsigned char vuca; vector unsigned short vusa; vector unsigned int vuia; vector unsigned long long vulla; unsigned long long test_vec_cntm_uc(void) { return vec_cntm(vuca, -1); // expected-error 1+ {{argument value 255 is outside the valid range [0, 1]}} } unsigned long long test_vec_cntm_us(void) { return vec_cntm(vusa, -1); // expected-error 1+ {{argument value 255 is outside the valid range [0, 1]}} } unsigned long long test_vec_cntm_ui(void) { return vec_cntm(vuia, 2); // expected-error 1+ {{argument value 2 is outside the valid range [0, 1]}} } unsigned long long test_vec_cntm_ull(void) { return vec_cntm(vulla, 2); // expected-error 1+ {{argument value 2 is outside the valid range [0, 1]}} } vector unsigned char test_xxgenpcvbm(void) { return vec_genpcvm(vuca, -1); // expected-error 1+ {{argument value -1 is outside the valid range [0, 3]}} } vector unsigned short test_xxgenpcvhm(void) { return vec_genpcvm(vusa, -1); // expected-error 1+ {{argument value -1 is outside the valid range [0, 3]}} } vector unsigned int test_xxgenpcvwm(void) { return vec_genpcvm(vuia, 4); // expected-error 1+ {{argument value 4 is outside the valid range [0, 3]}} } vector unsigned long long test_xxgenpcvdm(void) { return vec_genpcvm(vulla, 4); // expected-error 1+ {{argument value 4 is outside the valid range [0, 3]}} }
/* Flush all blocks in the key cache to disk. SYNOPSIS flush_all_key_blocks() keycache pointer to key cache root structure DESCRIPTION Flushing of the whole key cache is done in two phases. 1. Flush all changed blocks, waiting for them if necessary. Loop until there is no changed block left in the cache. 2. Free all clean blocks. Normally this means free all blocks. The changed blocks were flushed in phase 1 and became clean. However we may need to wait for blocks that are read by other threads. While we wait, a clean block could become changed if that operation started before the resize operation started. To be safe we must restart at phase 1. When we can run through the changed_blocks and file_blocks hashes without finding a block any more, then we are done. Note that we hold keycache->cache_lock all the time unless we need to wait for something. RETURN 0 OK != 0 Error */ static int flush_all_key_blocks(SIMPLE_KEY_CACHE_CB *keycache) { BLOCK_LINK *block; uint total_found; uint found; uint idx; uint changed_blocks_hash_size= keycache->changed_blocks_hash_size; DBUG_ENTER("flush_all_key_blocks"); do { mysql_mutex_assert_owner(&keycache->cache_lock); total_found= 0; do { found= 0; for (idx= 0; idx < changed_blocks_hash_size; idx++) { while ((block= keycache->changed_blocks[idx])) { found++; if (flush_key_blocks_int(keycache, block->hash_link->file, FLUSH_FORCE_WRITE)) DBUG_RETURN(1); } } } while (found); do { found= 0; for (idx= 0; idx < changed_blocks_hash_size; idx++) { while ((block= keycache->file_blocks[idx])) { total_found++; found++; if (flush_key_blocks_int(keycache, block->hash_link->file, FLUSH_RELEASE)) DBUG_RETURN(1); } } } while (found); } while (total_found); #ifndef DBUG_OFF for (idx= 0; idx < changed_blocks_hash_size; idx++) { DBUG_ASSERT(!keycache->changed_blocks[idx]); DBUG_ASSERT(!keycache->file_blocks[idx]); } #endif DBUG_RETURN(0); }
/******************************************************************* Force a share file to be deleted. ********************************************************************/ static int delete_share_file(connection_struct *conn, char *fname ) { if (read_only) return -1; become_root(False); if(unlink(fname) != 0) { DEBUG(0,("delete_share_file: Can't delete share file %s (%s)\n", fname, strerror(errno))); } else { DEBUG(5,("delete_share_file: Deleted share file %s\n", fname)); } unbecome_root(False); return 0; }
// // This is really just a utility function, but exposing it makes things // easier for chpl_comm_ugni_getHeapPageSize() callers in the launcher, // where the regular chplsys.c support isn't available. // size_t chpl_comm_ugni_getSysPageSize(void) { static size_t sps = 0; if (sps != 0) return sps; #if defined _SC_PAGESIZE sps = (size_t) sysconf(_SC_PAGESIZE); #elif defined _SC_PAGE_SIZE sps = (size_t) sysconf(_SC_PAGE_SIZE); #endif if (sps == 0) chpl_internal_error("can't get system page size"); return sps; }
// RUN: %clang -x c-header %s -o %t.pch -MMD -MT dependencies -MF %t.d -### 2> %t // RUN: FileCheck %s -input-file=%t // CHECK: -emit-pch // CHECK: -dependency-file // CHECK: -module-file-deps // RUN: %clang -c %s -o %t -MMD -MT dependencies -MF %t.d -### 2> %t // RUN: FileCheck %s -check-prefix=CHECK-NOPCH -input-file=%t // CHECK-NOPCH: -dependency-file // CHECK-NOPCH-NOT: -module-file-deps // RUN: %clang -x c-header %s -o %t.pch -MMD -MT dependencies -MF %t.d \ // RUN: -fno-module-file-deps -### 2> %t // RUN: FileCheck %s -check-prefix=CHECK-EXPLICIT -input-file=%t // CHECK-EXPLICIT: -dependency-file // CHECK-EXPLICIT-NOT: -module-file-deps // RUN: %clang -x c++ %s -o %t.o -MMD -MT dependencies -MF %t.d -fmodule-file-deps -### 2> %t // RUN: FileCheck %s -check-prefix=CHECK-EXPLICIT-NOPCH -input-file=%t // CHECK-EXPLICIT-NOPCH: -dependency-file // CHECK-EXPLICIT-NOPCH: -module-file-deps
/** * @file HandleControlPacket.c * This file contains the routines to deal with * sending and receiving of control packets. */ #include "headers.h" /** * When a control packet is received, analyze the * "status" and call appropriate response function. * Enqueue the control packet for Application. * @return None */ static VOID handle_rx_control_packet(struct bcm_mini_adapter *Adapter, struct sk_buff *skb) { struct bcm_tarang_data *pTarang = NULL; bool HighPriorityMessage = false; struct sk_buff *newPacket = NULL; CHAR cntrl_msg_mask_bit = 0; bool drop_pkt_flag = TRUE; USHORT usStatus = *(PUSHORT)(skb->data); if (netif_msg_pktdata(Adapter)) print_hex_dump(KERN_DEBUG, PFX "rx control: ", DUMP_PREFIX_NONE, 16, 1, skb->data, skb->len, 0); switch (usStatus) { case CM_RESPONSES: /* 0xA0 */ BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, CP_CTRL_PKT, DBG_LVL_ALL, "MAC Version Seems to be Non Multi-Classifier, rejected by Driver"); HighPriorityMessage = TRUE; break; case CM_CONTROL_NEWDSX_MULTICLASSIFIER_RESP: HighPriorityMessage = TRUE; if (Adapter->LinkStatus == LINKUP_DONE) CmControlResponseMessage(Adapter, (skb->data + sizeof(USHORT))); break; case LINK_CONTROL_RESP: /* 0xA2 */ case STATUS_RSP: /* 0xA1 */ BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, CP_CTRL_PKT, DBG_LVL_ALL, "LINK_CONTROL_RESP"); HighPriorityMessage = TRUE; LinkControlResponseMessage(Adapter, (skb->data + sizeof(USHORT))); break; case STATS_POINTER_RESP: /* 0xA6 */ HighPriorityMessage = TRUE; StatisticsResponse(Adapter, (skb->data + sizeof(USHORT))); break; case IDLE_MODE_STATUS: /* 0xA3 */ BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, CP_CTRL_PKT, DBG_LVL_ALL, "IDLE_MODE_STATUS Type Message Got from F/W"); InterfaceIdleModeRespond(Adapter, (PUINT)(skb->data + sizeof(USHORT))); HighPriorityMessage = TRUE; break; case AUTH_SS_HOST_MSG: HighPriorityMessage = TRUE; break; default: BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, CP_CTRL_PKT, DBG_LVL_ALL, "Got Default Response"); /* Let the Application Deal with This Packet */ break; } /* Queue The Control Packet to The Application Queues */ down(&Adapter->RxAppControlQueuelock); for (pTarang = Adapter->pTarangs; pTarang; pTarang = pTarang->next) { if (Adapter->device_removed) break; drop_pkt_flag = TRUE; /* * There are cntrl msg from A0 to AC. It has been mapped to 0 to * C bit in the cntrl mask. * Also, by default AD to BF has been masked to the rest of the * bits... which wil be ON by default. * if mask bit is enable to particular pkt status, send it out * to app else stop it. */ cntrl_msg_mask_bit = (usStatus & 0x1F); /* * printk("\ninew msg mask bit which is disable in mask:%X", * cntrl_msg_mask_bit); */ if (pTarang->RxCntrlMsgBitMask & (1 << cntrl_msg_mask_bit)) drop_pkt_flag = false; if ((drop_pkt_flag == TRUE) || (pTarang->AppCtrlQueueLen > MAX_APP_QUEUE_LEN) || ((pTarang->AppCtrlQueueLen > MAX_APP_QUEUE_LEN / 2) && (HighPriorityMessage == false))) { /* * Assumption:- * 1. every tarang manages it own dropped pkt * statitistics * 2. Total packet dropped per tarang will be equal to * the sum of all types of dropped pkt by that * tarang only. */ switch (*(PUSHORT)skb->data) { case CM_RESPONSES: pTarang->stDroppedAppCntrlMsgs.cm_responses++; break; case CM_CONTROL_NEWDSX_MULTICLASSIFIER_RESP: pTarang->stDroppedAppCntrlMsgs.cm_control_newdsx_multiclassifier_resp++; break; case LINK_CONTROL_RESP: pTarang->stDroppedAppCntrlMsgs.link_control_resp++; break; case STATUS_RSP: pTarang->stDroppedAppCntrlMsgs.status_rsp++; break; case STATS_POINTER_RESP: pTarang->stDroppedAppCntrlMsgs.stats_pointer_resp++; break; case IDLE_MODE_STATUS: pTarang->stDroppedAppCntrlMsgs.idle_mode_status++; break; case AUTH_SS_HOST_MSG: pTarang->stDroppedAppCntrlMsgs.auth_ss_host_msg++; break; default: pTarang->stDroppedAppCntrlMsgs.low_priority_message++; break; } continue; } newPacket = skb_clone(skb, GFP_KERNEL); if (!newPacket) break; ENQUEUEPACKET(pTarang->RxAppControlHead, pTarang->RxAppControlTail, newPacket); pTarang->AppCtrlQueueLen++; } up(&Adapter->RxAppControlQueuelock); wake_up(&Adapter->process_read_wait_queue); dev_kfree_skb(skb); BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, CP_CTRL_PKT, DBG_LVL_ALL, "After wake_up_interruptible"); } /** * @ingroup ctrl_pkt_functions * Thread to handle control pkt reception */ int control_packet_handler(struct bcm_mini_adapter *Adapter /* pointer to adapter object*/) { struct sk_buff *ctrl_packet = NULL; unsigned long flags = 0; /* struct timeval tv; */ /* int *puiBuffer = NULL; */ BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, CP_CTRL_PKT, DBG_LVL_ALL, "Entering to make thread wait on control packet event!"); while (1) { wait_event_interruptible(Adapter->process_rx_cntrlpkt, atomic_read(&Adapter->cntrlpktCnt) || Adapter->bWakeUpDevice || kthread_should_stop()); if (kthread_should_stop()) { BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, CP_CTRL_PKT, DBG_LVL_ALL, "Exiting\n"); return 0; } if (TRUE == Adapter->bWakeUpDevice) { Adapter->bWakeUpDevice = false; if ((false == Adapter->bTriedToWakeUpFromlowPowerMode) && ((TRUE == Adapter->IdleMode) || (TRUE == Adapter->bShutStatus))) { BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, CP_CTRL_PKT, DBG_LVL_ALL, "Calling InterfaceAbortIdlemode\n"); /* * Adapter->bTriedToWakeUpFromlowPowerMode * = TRUE; */ InterfaceIdleModeWakeup(Adapter); } continue; } while (atomic_read(&Adapter->cntrlpktCnt)) { spin_lock_irqsave(&Adapter->control_queue_lock, flags); ctrl_packet = Adapter->RxControlHead; if (ctrl_packet) { DEQUEUEPACKET(Adapter->RxControlHead, Adapter->RxControlTail); /* Adapter->RxControlHead=ctrl_packet->next; */ } spin_unlock_irqrestore(&Adapter->control_queue_lock, flags); handle_rx_control_packet(Adapter, ctrl_packet); atomic_dec(&Adapter->cntrlpktCnt); } SetUpTargetDsxBuffers(Adapter); } return STATUS_SUCCESS; } INT flushAllAppQ(void) { struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev); struct bcm_tarang_data *pTarang = NULL; struct sk_buff *PacketToDrop = NULL; for (pTarang = Adapter->pTarangs; pTarang; pTarang = pTarang->next) { while (pTarang->RxAppControlHead != NULL) { PacketToDrop = pTarang->RxAppControlHead; DEQUEUEPACKET(pTarang->RxAppControlHead, pTarang->RxAppControlTail); dev_kfree_skb(PacketToDrop); } pTarang->AppCtrlQueueLen = 0; /* dropped contrl packet statistics also should be reset. */ memset((PVOID)&pTarang->stDroppedAppCntrlMsgs, 0, sizeof(struct bcm_mibs_dropped_cntrl_msg)); } return STATUS_SUCCESS; }
/* Get a Unicode code point from the TCHAR string in defined API encodeing */ static DWORD tchar2uni ( const TCHAR** str ) { DWORD uc; const TCHAR *p = *str; #if FF_LFN_UNICODE == 1 WCHAR wc; uc = *p++; if (IsSurrogate(uc)) { wc = *p++; if (!IsSurrogateH(uc) || !IsSurrogateL(wc)) return 0xFFFFFFFF; uc = uc << 16 | wc; } #elif FF_LFN_UNICODE == 2 BYTE b; int nf; uc = (BYTE)*p++; if (uc & 0x80) { if ((uc & 0xE0) == 0xC0) { uc &= 0x1F; nf = 1; } else { if ((uc & 0xF0) == 0xE0) { uc &= 0x0F; nf = 2; } else { if ((uc & 0xF8) == 0xF0) { uc &= 0x07; nf = 3; } else { return 0xFFFFFFFF; } } } do { b = (BYTE)*p++; if ((b & 0xC0) != 0x80) return 0xFFFFFFFF; uc = uc << 6 | (b & 0x3F); } while (--nf != 0); if (uc < 0x80 || IsSurrogate(uc) || uc >= 0x110000) return 0xFFFFFFFF; if (uc >= 0x010000) uc = 0xD800DC00 | ((uc - 0x10000) << 6 & 0x3FF0000) | (uc & 0x3FF); } #elif FF_LFN_UNICODE == 3 uc = (TCHAR)*p++; if (uc >= 0x110000 || IsSurrogate(uc)) return 0xFFFFFFFF; if (uc >= 0x010000) uc = 0xD800DC00 | ((uc - 0x10000) << 6 & 0x3FF0000) | (uc & 0x3FF); #else BYTE b; WCHAR wc; wc = (BYTE)*p++; if (dbc_1st((BYTE)wc)) { b = (BYTE)*p++; if (!dbc_2nd(b)) return 0xFFFFFFFF; wc = (wc << 8) + b; } if (wc != 0) { wc = ff_oem2uni(wc, CODEPAGE); if (wc == 0) return 0xFFFFFFFF; } uc = wc; #endif *str = p; return uc; }
/*------------------------------------------------- extract_scanline32 - copy pixels from a single scanline of a bitmap to a 32bpp buffer -------------------------------------------------*/ void extract_scanline32(bitmap_t *bitmap, INT32 srcx, INT32 srcy, INT32 length, UINT32 *destptr) { assert(bitmap != NULL); assert(bitmap->bpp == 16 || bitmap->bpp == 32); if (bitmap->bpp == 16) EXTRACTSCANLINE_CORE(UINT16); else EXTRACTSCANLINE_CORE(UINT32); }
/* * nilfs_sc_cstage_inc(), nilfs_sc_cstage_set(), nilfs_sc_cstage_get() are * wrapper functions of stage count (nilfs_sc_info->sc_stage.scnt). Users of * the variable must use them because transition of stage count must involve * trace events (trace_nilfs2_collection_stage_transition). * * nilfs_sc_cstage_get() isn't required for the above purpose because it doesn't * produce tracepoint events. It is provided just for making the intention * clear. */ static inline void nilfs_sc_cstage_inc(struct nilfs_sc_info *sci) { sci->sc_stage.scnt++; trace_nilfs2_collection_stage_transition(sci); }
/* forward to char position in "s" that IS a space or tab, or stop at EOS */ char *nonblank_advance(char *s) { register char *p; for (p=s; ((*p)!=EOS) && ISNOTBLANK(*p); p++); return (p); }
// Retrieve pointer to PTD entry at specific index. static inline ptde_t *ptde_at(ptdaddr_t ptd, uint64_t index) { uint64_t *ptr = (uint64_t *)ptd_to_virt_ptr(ptd); return (ptde_t *)&ptr[index]; }
/* *************************************************************************** ** Determines if a timestamp should be output with the current error message. ** ** If timestamp required, it gets created in the beginning of the buffer ** argument. *************************************************************************** */ static int TimeStampRequired (void) { static time_t lastStamp_t =0; time_t currStamp_t; time(&currStamp_t); if ((currStamp_t - lastStamp_t) > TS_SENSITIVITY) { lastStamp_t = currStamp_t; if (TimeStampFill(currStamp_t) != SUCCESS) { return FAILURE; } } return SUCCESS; }
// // Function: mosquitoElementDirectionSet // // Set the direction of a single time element // static void mosquitoElementDirectionSet(timeElement_t *element) { float elementRad; u16 angle; mosRandBase = (u16)(mosRandSeed * (mosRandVal + mcClockNewTM) * 213); mosRandVal = mcCycleCounter * mosRandSeed + mosRandBase; angle = mosRandVal % (90 - MOS_DIRECTION_ANGLE_MIN * 2) + MOS_DIRECTION_ANGLE_MIN; elementRad = (float)(angle + 90 * (((mosRandVal >> 3) + angle) % 4)) / 180L * M_PI; element->dx = sin(elementRad) * MOS_ELEMENT_SPEED; element->dy = -cos(elementRad) * MOS_ELEMENT_SPEED; }
/* * Clear any entry in the unicast key mapping table. */ static int node_clear_keyixmap(struct ieee80211_node_table *nt, struct ieee80211_node *ni) { ieee80211_keyix keyix; keyix = ni->ni_ucastkey.wk_rxkeyix; if (nt->nt_keyixmap != NULL && keyix < nt->nt_keyixmax && nt->nt_keyixmap[keyix] == ni) { IEEE80211_DPRINTF(ni->ni_vap, IEEE80211_MSG_NODE, "%s: %p<%s> clear key map entry %u\n", __func__, ni, ether_sprintf(ni->ni_macaddr), keyix); nt->nt_keyixmap[keyix] = NULL; ieee80211_node_decref(ni); return 1; } return 0; }
/** * @brief Set the RTC current date. * @param RTCx RTC Instance * @param RTC_Format This parameter can be one of the following values: * @arg @ref LL_RTC_FORMAT_BIN * @arg @ref LL_RTC_FORMAT_BCD * @param RTC_DateStruct: pointer to a RTC_DateTypeDef structure that contains * the date configuration information for the RTC. * @retval An ErrorStatus enumeration value: * - SUCCESS: RTC Day register is configured * - ERROR: RTC Day register is not configured */ ErrorStatus LL_RTC_DATE_Init(RTC_TypeDef *RTCx, uint32_t RTC_Format, LL_RTC_DateTypeDef *RTC_DateStruct) { ErrorStatus status = ERROR; assert_param(IS_RTC_ALL_INSTANCE(RTCx)); assert_param(IS_LL_RTC_FORMAT(RTC_Format)); if ((RTC_Format == LL_RTC_FORMAT_BIN) && ((RTC_DateStruct->Month & 0x10U) == 0x10U)) { RTC_DateStruct->Month = (RTC_DateStruct->Month & (uint32_t)~(0x10U)) + 0x0AU; } if (RTC_Format == LL_RTC_FORMAT_BIN) { assert_param(IS_LL_RTC_YEAR(RTC_DateStruct->Year)); assert_param(IS_LL_RTC_MONTH(RTC_DateStruct->Month)); assert_param(IS_LL_RTC_DAY(RTC_DateStruct->Day)); } else { assert_param(IS_LL_RTC_YEAR(__LL_RTC_CONVERT_BCD2BIN(RTC_DateStruct->Year))); assert_param(IS_LL_RTC_MONTH(__LL_RTC_CONVERT_BCD2BIN(RTC_DateStruct->Month))); assert_param(IS_LL_RTC_DAY(__LL_RTC_CONVERT_BCD2BIN(RTC_DateStruct->Day))); } assert_param(IS_LL_RTC_WEEKDAY(RTC_DateStruct->WeekDay)); LL_RTC_DisableWriteProtection(RTCx); if (LL_RTC_EnterInitMode(RTCx) != ERROR) { if (RTC_Format != LL_RTC_FORMAT_BIN) { LL_RTC_DATE_Config(RTCx, RTC_DateStruct->WeekDay, RTC_DateStruct->Day, RTC_DateStruct->Month, RTC_DateStruct->Year); } else { LL_RTC_DATE_Config(RTCx, RTC_DateStruct->WeekDay, __LL_RTC_CONVERT_BIN2BCD(RTC_DateStruct->Day), __LL_RTC_CONVERT_BIN2BCD(RTC_DateStruct->Month), __LL_RTC_CONVERT_BIN2BCD(RTC_DateStruct->Year)); } LL_RTC_DisableInitMode(RTC); #if defined(RTC_CR_BYPSHAD) if (LL_RTC_IsShadowRegBypassEnabled(RTCx) == 0U) { status = LL_RTC_WaitForSynchro(RTCx); } else { status = SUCCESS; } #else status = SUCCESS; #endif } LL_RTC_EnableWriteProtection(RTCx); return status; }
/** * xs_destroy - prepare to shutdown a transport * @xprt: doomed transport * */ static void xs_destroy(struct rpc_xprt *xprt) { dprintk("RPC: xs_destroy xprt %p\n", xprt); cancel_delayed_work(&xprt->connect_worker); flush_scheduled_work(); xprt_disconnect(xprt); xs_close(xprt); kfree(xprt->slot); }
/* convert a float to a long. Overflow is max possible result. */ int bf_float_to_int( FLOAT *f) { FLOAT dummy, intprt; int value; if( f->expnt < 1) return 0; if( f->expnt > 31) { if( f->mntsa.e[MS_MNTSA] & SIGN_BIT) return SIGN_BIT; return ~SIGN_BIT; } bf_split( f, &intprt, &dummy); if( intprt.mntsa.e[MS_MNTSA] & SIGN_BIT) { bf_negate( &intprt); value = -(intprt.mntsa.e[MS_MNTSA] >> ( 31 - intprt.expnt)); } else value = intprt.mntsa.e[MS_MNTSA] >> ( 31 - intprt.expnt); return value; }
/** * This is the ROS message dissector. A ROS message contains two parts: a msg header; a msg payload. * Because the packet is all in binary format, we don't really know the payload format (we don't know the payload type either). * However, every packet has the same header as defined here: http://docs.ros.org/api/std_msgs/html/msg/Header.html * So, we can break this one down and display it. */ static gint dissect_ros_message(tvbuff_t *tvb, proto_tree *root_tree, packet_info *pinfo, gint offset) { proto_item *ti; proto_tree *sub_tree; gint consumed_len = 0; guint32 total_len = tvb_get_letohl(tvb, offset); guint payload_len; col_append_str(pinfo->cinfo, COL_INFO, "[ROS Msg] "); ti = proto_tree_add_item(root_tree, hf_tcpros_message, tvb, offset + consumed_len, SIZE_OF_LENGTH_FIELD, ENC_NA | ENC_LITTLE_ENDIAN); sub_tree = proto_item_add_subtree(ti, ett_tcpros); proto_tree_add_item(sub_tree, hf_tcpros_message_length, tvb, offset + consumed_len, SIZE_OF_LENGTH_FIELD, ENC_LITTLE_ENDIAN); consumed_len += SIZE_OF_LENGTH_FIELD; ti = proto_tree_add_item(sub_tree, hf_tcpros_message_body, tvb, offset + consumed_len, total_len, ENC_NA); sub_tree = proto_item_add_subtree(ti, ett_tcpros); consumed_len += dissect_ros_message_header(tvb, sub_tree, pinfo, offset + consumed_len); payload_len = (total_len + SIZE_OF_LENGTH_FIELD) - consumed_len; proto_tree_add_item(sub_tree, hf_tcpros_message_payload, tvb, offset + consumed_len, payload_len, ENC_NA); consumed_len += payload_len; return consumed_len; }
/* dlaqsp.f -- translated by f2c (version 20061008). You must link the resulting object file with libf2c: on Microsoft Windows system, link with libf2c.lib; on Linux or Unix systems, link with .../path/to/libf2c.a -lm or, if you install libf2c.a in a standard place, with -lf2c -lm -- in that order, at the end of the command line, as in cc *.o -lf2c -lm Source for libf2c is in /netlib/f2c/libf2c.zip, e.g., http://www.netlib.org/f2c/libf2c.zip */ #include "f2c.h" #include "blaswrap.h" /* Subroutine */ int dlaqsp_(char *uplo, integer *n, doublereal *ap, doublereal *s, doublereal *scond, doublereal *amax, char *equed) { /* System generated locals */ integer i__1, i__2; /* Local variables */ integer i__, j, jc; doublereal cj, large; extern logical lsame_(char *, char *); doublereal small; extern doublereal dlamch_(char *); /* -- LAPACK auxiliary routine (version 3.2) -- */ /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ /* November 2006 */ /* .. Scalar Arguments .. */ /* .. */ /* .. Array Arguments .. */ /* .. */ /* Purpose */ /* ======= */ /* DLAQSP equilibrates a symmetric matrix A using the scaling factors */ /* in the vector S. */ /* Arguments */ /* ========= */ /* UPLO (input) CHARACTER*1 */ /* Specifies whether the upper or lower triangular part of the */ /* symmetric matrix A is stored. */ /* = 'U': Upper triangular */ /* = 'L': Lower triangular */ /* N (input) INTEGER */ /* The order of the matrix A. N >= 0. */ /* AP (input/output) DOUBLE PRECISION array, dimension (N*(N+1)/2) */ /* On entry, the upper or lower triangle of the symmetric matrix */ /* A, packed columnwise in a linear array. The j-th column of A */ /* is stored in the array AP as follows: */ /* if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j; */ /* if UPLO = 'L', AP(i + (j-1)*(2n-j)/2) = A(i,j) for j<=i<=n. */ /* On exit, the equilibrated matrix: diag(S) * A * diag(S), in */ /* the same storage format as A. */ /* S (input) DOUBLE PRECISION array, dimension (N) */ /* The scale factors for A. */ /* SCOND (input) DOUBLE PRECISION */ /* Ratio of the smallest S(i) to the largest S(i). */ /* AMAX (input) DOUBLE PRECISION */ /* Absolute value of largest matrix entry. */ /* EQUED (output) CHARACTER*1 */ /* Specifies whether or not equilibration was done. */ /* = 'N': No equilibration. */ /* = 'Y': Equilibration was done, i.e., A has been replaced by */ /* diag(S) * A * diag(S). */ /* Internal Parameters */ /* =================== */ /* THRESH is a threshold value used to decide if scaling should be done */ /* based on the ratio of the scaling factors. If SCOND < THRESH, */ /* scaling is done. */ /* LARGE and SMALL are threshold values used to decide if scaling should */ /* be done based on the absolute size of the largest matrix element. */ /* If AMAX > LARGE or AMAX < SMALL, scaling is done. */ /* ===================================================================== */ /* .. Parameters .. */ /* .. */ /* .. Local Scalars .. */ /* .. */ /* .. External Functions .. */ /* .. */ /* .. Executable Statements .. */ /* Quick return if possible */ /* Parameter adjustments */ --s; --ap; /* Function Body */ if (*n <= 0) { *(unsigned char *)equed = 'N'; return 0; } /* Initialize LARGE and SMALL. */ small = dlamch_("Safe minimum") / dlamch_("Precision"); large = 1. / small; if (*scond >= .1 && *amax >= small && *amax <= large) { /* No equilibration */ *(unsigned char *)equed = 'N'; } else { /* Replace A by diag(S) * A * diag(S). */ if (lsame_(uplo, "U")) { /* Upper triangle of A is stored. */ jc = 1; i__1 = *n; for (j = 1; j <= i__1; ++j) { cj = s[j]; i__2 = j; for (i__ = 1; i__ <= i__2; ++i__) { ap[jc + i__ - 1] = cj * s[i__] * ap[jc + i__ - 1]; /* L10: */ } jc += j; /* L20: */ } } else { /* Lower triangle of A is stored. */ jc = 1; i__1 = *n; for (j = 1; j <= i__1; ++j) { cj = s[j]; i__2 = *n; for (i__ = j; i__ <= i__2; ++i__) { ap[jc + i__ - j] = cj * s[i__] * ap[jc + i__ - j]; /* L30: */ } jc = jc + *n - j + 1; /* L40: */ } } *(unsigned char *)equed = 'Y'; } return 0; /* End of DLAQSP */ } /* dlaqsp_ */
/** * Retrieve the boot reason from pstore */ bool osp_unit_reboot_get(enum osp_reboot_type *type, char *reason, ssize_t reason_sz) { struct dirent *pde; char fpath[C_MAXPATH_LEN]; bool retval = false; DIR *psd = NULL; char *pmsg = NULL; *type = OSP_REBOOT_UNKNOWN; if (reason_sz == 0) reason = NULL; if (reason != NULL) reason[0] = '\0'; if (access(PSTORE_REBOOT_TMP, R_OK) == 0) { LOG(DEBUG, "osp_reboot: Using cached reboot reason: %s", PSTORE_REBOOT_TMP); if (!pstore_parse_reboot(PSTORE_REBOOT_TMP, type, reason, reason_sz)) { LOG(ERR, "osp_reboot: Error reading reboot reason cache."); goto exit; } return true; } psd = opendir(CONFIG_OSP_REBOOT_PSTORE_FS); if (psd == NULL) { LOG(ERR, "osp_reboot: Error opening PSTORE folder."); return false; } pmsg = NULL; while ((pde = readdir(psd)) != NULL) { if (fnmatch(PSTORE_DMESG, pde->d_name, FNM_PATHNAME) == 0) { LOG(DEBUG, "osp_reboot: Found DMESG file: %s", pde->d_name); if (*type == OSP_REBOOT_UNKNOWN) { int rc; rc = snprintf(fpath, sizeof(fpath), "%s/%s", CONFIG_OSP_REBOOT_PSTORE_FS, pde->d_name); if (rc >= (int)sizeof(fpath)) { LOG(ERR, "osp_reboot: pstore filesystem path too long: %s/%s", CONFIG_OSP_REBOOT_PSTORE_FS, pde->d_name); continue; } pstore_parse_dmesg(fpath, type, reason, reason_sz); } if (unlinkat(dirfd(psd), pde->d_name, 0) == 0) { rewinddir(psd); } else { LOG(WARN, "osp_reboot: Error unlinking dmesg file: %s", pde->d_name); } continue; } if (fnmatch(PSTORE_PMSG, pde->d_name, FNM_PATHNAME) == 0) { if (pmsg == NULL) { pmsg = strdup(pde->d_name); } continue; } } if (*type != OSP_REBOOT_UNKNOWN) { retval = true; goto exit; } if (pmsg != NULL) { snprintf(fpath, sizeof(fpath), "%s/%s", CONFIG_OSP_REBOOT_PSTORE_FS, pmsg); LOG(DEBUG, "osp_reboot: Found PMSG file: %s", fpath); if (!pstore_parse_reboot(fpath, type, reason, reason_sz)) { *type = OSP_REBOOT_POWER_CYCLE; if (reason != NULL) { strscpy(reason, "Power cycle.", reason_sz); } } retval = true; goto exit; } *type = OSP_REBOOT_COLD_BOOT; strscpy(reason, "Power up.", reason_sz); retval = true; exit: if (retval) { FILE *fc; fc = fopen(PSTORE_REBOOT_TMP, "w+"); if (fc != NULL) { fprintf(fc, "REBOOT %s %s\n", pstore_reboot_type_str(*type), reason); ioctl(fileno(fc), FS_IOC_SETFLAGS, (int[]){ FS_IMMUTABLE_FL }); fclose(fc); } else { LOG(ERR, "osp_reboot: Unable to create cache file: %s", PSTORE_REBOOT_TMP); } LOG(INFO, "osp_reboot: Last reboot reason: [%s] %s", pstore_reboot_type_str(*type), reason == NULL ? "" : reason); } FREE(pmsg); if (psd != NULL && closedir(psd) != 0) { LOG(WARN, "osp_reboot: Error closing PSTORE folder."); } return retval; }
/* gasnetc_exit_master * * We say a polite goodbye to our peers and then listen for their replies. * This forms the root node's portion of a barrier for graceful shutdown. * * The "goodbyes" are just an AM containing the desired exit code. * The AM helps ensure that on non-collective exits the "other" nodes know to exit. * If we see a "goodbye" from all of our peers we know we've managed to coordinate * an orderly shutdown. If not, then in gasnetc_exit_body() we can ask the bootstrap * support to kill the job in a less graceful way. * * Takes the exitcode and a timeout in us as arguments * * Returns 0 on success, non-zero on any sort of failure including timeout. */ static int gasnetc_exit_master(int exitcode, int64_t timeout_us) { int i, rc; gasneti_tick_t start_time; gasneti_assert(timeout_us > 0); start_time = gasneti_ticks_now(); for (i = 0; i < gasneti_nodes; ++i) { if (i == gasneti_mynode) continue; if (gasneti_ticks_to_ns(gasneti_ticks_now() - start_time) / 1000 > timeout_us) return -1; rc = gasnetc_RequestSysShort(i, NULL, gasneti_handleridx(gasnetc_exit_reqh), 1, (gasnet_handlerarg_t)exitcode); if (rc != GASNET_OK) return -1; } while (gasneti_atomic_read(&gasnetc_exit_reps, 0) < (gasneti_nodes - 1)) { if (gasneti_ticks_to_ns(gasneti_ticks_now() - start_time) / 1000 > timeout_us) return -1; gasnetc_sndrcv_poll(0); } return 0; }