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
|
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
3e4dbcbd3718b2194ab39912db39541fdee5b04c
|
4998356d6b3f5661466691cfc13abc3811fa26c3
|
/lobster/external/libtcc/x86_64-link.c
|
8a609870ff88823ec17a0cb41ce1b5d0b4f80637
|
[
"Zlib"
] |
permissive
|
aardappel/treesheets
|
310edeece64dfb6093077f8ecbcf10bc0020b40f
|
7f68776a9e072520c735479929efecd0d58f362d
|
refs/heads/master
| 2023-09-01T22:12:08.903007
| 2023-08-31T18:32:32
| 2023-08-31T18:32:32
| 10,671,623
| 2,194
| 240
|
Zlib
| 2023-09-13T18:07:02
| 2013-06-13T17:30:30
|
C++
|
UTF-8
|
C
| false
| false
| 12,971
|
c
|
x86_64-link.c
|
#ifdef TARGET_DEFS_ONLY
#define EM_TCC_TARGET EM_X86_64
/* relocation type for 32 bit data relocation */
#define R_DATA_32 R_X86_64_32S
#define R_DATA_PTR R_X86_64_64
#define R_JMP_SLOT R_X86_64_JUMP_SLOT
#define R_GLOB_DAT R_X86_64_GLOB_DAT
#define R_COPY R_X86_64_COPY
#define R_RELATIVE R_X86_64_RELATIVE
#define R_NUM R_X86_64_NUM
#define ELF_START_ADDR 0x400000
#define ELF_PAGE_SIZE 0x200000
#define PCRELATIVE_DLLPLT 1
#define RELOCATE_DLLPLT 1
#else /* !TARGET_DEFS_ONLY */
#include "tcc.h"
#ifdef NEED_RELOC_TYPE
/* Returns 1 for a code relocation, 0 for a data relocation. For unknown
relocations, returns -1. */
int code_reloc (int reloc_type)
{
switch (reloc_type) {
case R_X86_64_32:
case R_X86_64_32S:
case R_X86_64_64:
case R_X86_64_GOTPC32:
case R_X86_64_GOTPC64:
case R_X86_64_GOTPCREL:
case R_X86_64_GOTPCRELX:
case R_X86_64_REX_GOTPCRELX:
case R_X86_64_GOTTPOFF:
case R_X86_64_GOT32:
case R_X86_64_GOT64:
case R_X86_64_GLOB_DAT:
case R_X86_64_COPY:
case R_X86_64_RELATIVE:
case R_X86_64_GOTOFF64:
case R_X86_64_TLSGD:
case R_X86_64_TLSLD:
case R_X86_64_DTPOFF32:
case R_X86_64_TPOFF32:
case R_X86_64_DTPOFF64:
case R_X86_64_TPOFF64:
return 0;
case R_X86_64_PC32:
case R_X86_64_PC64:
case R_X86_64_PLT32:
case R_X86_64_PLTOFF64:
case R_X86_64_JUMP_SLOT:
return 1;
}
return -1;
}
/* Returns an enumerator to describe whether and when the relocation needs a
GOT and/or PLT entry to be created. See tcc.h for a description of the
different values. */
int gotplt_entry_type (int reloc_type)
{
switch (reloc_type) {
case R_X86_64_GLOB_DAT:
case R_X86_64_JUMP_SLOT:
case R_X86_64_COPY:
case R_X86_64_RELATIVE:
return NO_GOTPLT_ENTRY;
/* The following relocs wouldn't normally need GOT or PLT
slots, but we need them for simplicity in the link
editor part. See our caller for comments. */
case R_X86_64_32:
case R_X86_64_32S:
case R_X86_64_64:
case R_X86_64_PC32:
case R_X86_64_PC64:
return AUTO_GOTPLT_ENTRY;
case R_X86_64_GOTTPOFF:
return BUILD_GOT_ONLY;
case R_X86_64_GOT32:
case R_X86_64_GOT64:
case R_X86_64_GOTPC32:
case R_X86_64_GOTPC64:
case R_X86_64_GOTOFF64:
case R_X86_64_GOTPCREL:
case R_X86_64_GOTPCRELX:
case R_X86_64_TLSGD:
case R_X86_64_TLSLD:
case R_X86_64_DTPOFF32:
case R_X86_64_TPOFF32:
case R_X86_64_DTPOFF64:
case R_X86_64_TPOFF64:
case R_X86_64_REX_GOTPCRELX:
case R_X86_64_PLT32:
case R_X86_64_PLTOFF64:
return ALWAYS_GOTPLT_ENTRY;
}
return -1;
}
#ifdef NEED_BUILD_GOT
ST_FUNC unsigned create_plt_entry(TCCState *s1, unsigned got_offset, struct sym_attr *attr)
{
Section *plt = s1->plt;
uint8_t *p;
int modrm;
unsigned plt_offset, relofs;
modrm = 0x25;
/* empty PLT: create PLT0 entry that pushes the library identifier
(GOT + PTR_SIZE) and jumps to ld.so resolution routine
(GOT + 2 * PTR_SIZE) */
if (plt->data_offset == 0) {
p = section_ptr_add(plt, 16);
p[0] = 0xff; /* pushl got + PTR_SIZE */
p[1] = modrm + 0x10;
write32le(p + 2, PTR_SIZE);
p[6] = 0xff; /* jmp *(got + PTR_SIZE * 2) */
p[7] = modrm;
write32le(p + 8, PTR_SIZE * 2);
}
plt_offset = plt->data_offset;
/* The PLT slot refers to the relocation entry it needs via offset.
The reloc entry is created below, so its offset is the current
data_offset */
relofs = s1->plt->reloc ? s1->plt->reloc->data_offset : 0;
/* Jump to GOT entry where ld.so initially put the address of ip + 4 */
p = section_ptr_add(plt, 16);
p[0] = 0xff; /* jmp *(got + x) */
p[1] = modrm;
write32le(p + 2, got_offset);
p[6] = 0x68; /* push $xxx */
/* On x86-64, the relocation is referred to by _index_ */
write32le(p + 7, relofs / sizeof (ElfW_Rel) - 1);
p[11] = 0xe9; /* jmp plt_start */
write32le(p + 12, -(plt->data_offset));
return plt_offset;
}
/* relocate the PLT: compute addresses and offsets in the PLT now that final
address for PLT and GOT are known (see fill_program_header) */
ST_FUNC void relocate_plt(TCCState *s1)
{
uint8_t *p, *p_end;
if (!s1->plt)
return;
p = s1->plt->data;
p_end = p + s1->plt->data_offset;
if (p < p_end) {
int x = s1->got->sh_addr - s1->plt->sh_addr - 6;
add32le(p + 2, x);
add32le(p + 8, x - 6);
p += 16;
while (p < p_end) {
add32le(p + 2, x + (s1->plt->data - p));
p += 16;
}
}
if (s1->plt->reloc) {
ElfW_Rel *rel;
int x = s1->plt->sh_addr + 16 + 6;
p = s1->got->data;
for_each_elem(s1->plt->reloc, 0, rel, ElfW_Rel) {
write64le(p + rel->r_offset, x);
x += 16;
}
}
}
#endif
#endif
void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t addr, addr_t val)
{
int sym_index, esym_index;
sym_index = ELFW(R_SYM)(rel->r_info);
switch (type) {
case R_X86_64_64:
if (s1->output_type == TCC_OUTPUT_DLL) {
esym_index = get_sym_attr(s1, sym_index, 0)->dyn_index;
qrel->r_offset = rel->r_offset;
if (esym_index) {
qrel->r_info = ELFW(R_INFO)(esym_index, R_X86_64_64);
qrel->r_addend = rel->r_addend;
qrel++;
break;
} else {
qrel->r_info = ELFW(R_INFO)(0, R_X86_64_RELATIVE);
qrel->r_addend = read64le(ptr) + val;
qrel++;
}
}
add64le(ptr, val);
break;
case R_X86_64_32:
case R_X86_64_32S:
if (s1->output_type == TCC_OUTPUT_DLL) {
/* XXX: this logic may depend on TCC's codegen
now TCC uses R_X86_64_32 even for a 64bit pointer */
qrel->r_offset = rel->r_offset;
qrel->r_info = ELFW(R_INFO)(0, R_X86_64_RELATIVE);
/* Use sign extension! */
qrel->r_addend = (int)read32le(ptr) + val;
qrel++;
}
add32le(ptr, val);
break;
case R_X86_64_PC32:
if (s1->output_type == TCC_OUTPUT_DLL) {
/* DLL relocation */
esym_index = get_sym_attr(s1, sym_index, 0)->dyn_index;
if (esym_index) {
qrel->r_offset = rel->r_offset;
qrel->r_info = ELFW(R_INFO)(esym_index, R_X86_64_PC32);
/* Use sign extension! */
qrel->r_addend = (int)read32le(ptr) + rel->r_addend;
qrel++;
break;
}
}
goto plt32pc32;
case R_X86_64_PLT32:
/* fallthrough: val already holds the PLT slot address */
plt32pc32:
{
long long diff;
diff = (long long)val - addr;
if (diff < -2147483648LL || diff > 2147483647LL) {
tcc_error("internal error: relocation failed");
}
add32le(ptr, diff);
}
break;
case R_X86_64_COPY:
break;
case R_X86_64_PLTOFF64:
add64le(ptr, val - s1->got->sh_addr + rel->r_addend);
break;
case R_X86_64_PC64:
if (s1->output_type == TCC_OUTPUT_DLL) {
/* DLL relocation */
esym_index = get_sym_attr(s1, sym_index, 0)->dyn_index;
if (esym_index) {
qrel->r_offset = rel->r_offset;
qrel->r_info = ELFW(R_INFO)(esym_index, R_X86_64_PC64);
qrel->r_addend = read64le(ptr) + rel->r_addend;
qrel++;
break;
}
}
add64le(ptr, val - addr);
break;
case R_X86_64_GLOB_DAT:
case R_X86_64_JUMP_SLOT:
/* They don't need addend */
write64le(ptr, val - rel->r_addend);
break;
case R_X86_64_GOTPCREL:
case R_X86_64_GOTPCRELX:
case R_X86_64_REX_GOTPCRELX:
add32le(ptr, s1->got->sh_addr - addr +
get_sym_attr(s1, sym_index, 0)->got_offset - 4);
break;
case R_X86_64_GOTPC32:
add32le(ptr, s1->got->sh_addr - addr + rel->r_addend);
break;
case R_X86_64_GOTPC64:
add64le(ptr, s1->got->sh_addr - addr + rel->r_addend);
break;
case R_X86_64_GOTTPOFF:
add32le(ptr, val - s1->got->sh_addr);
break;
case R_X86_64_GOT32:
/* we load the got offset */
add32le(ptr, get_sym_attr(s1, sym_index, 0)->got_offset);
break;
case R_X86_64_GOT64:
/* we load the got offset */
add64le(ptr, get_sym_attr(s1, sym_index, 0)->got_offset);
break;
case R_X86_64_GOTOFF64:
add64le(ptr, val - s1->got->sh_addr);
break;
case R_X86_64_TLSGD:
{
static const unsigned char expect[] = {
/* .byte 0x66; lea 0(%rip),%rdi */
0x66, 0x48, 0x8d, 0x3d, 0x00, 0x00, 0x00, 0x00,
/* .word 0x6666; rex64; call __tls_get_addr@PLT */
0x66, 0x66, 0x48, 0xe8, 0x00, 0x00, 0x00, 0x00 };
static const unsigned char replace[] = {
/* mov %fs:0,%rax */
0x64, 0x48, 0x8b, 0x04, 0x25, 0x00, 0x00, 0x00, 0x00,
/* lea -4(%rax),%rax */
0x48, 0x8d, 0x80, 0x00, 0x00, 0x00, 0x00 };
if (memcmp (ptr-4, expect, sizeof(expect)) == 0) {
ElfW(Sym) *sym;
Section *sec;
int32_t x;
memcpy(ptr-4, replace, sizeof(replace));
rel[1].r_info = ELFW(R_INFO)(0, R_X86_64_NONE);
sym = &((ElfW(Sym) *)symtab_section->data)[sym_index];
sec = s1->sections[sym->st_shndx];
x = sym->st_value - sec->sh_addr - sec->data_offset;
add32le(ptr + 8, x);
}
else
tcc_error("unexpected R_X86_64_TLSGD pattern");
}
break;
case R_X86_64_TLSLD:
{
static const unsigned char expect[] = {
/* lea 0(%rip),%rdi */
0x48, 0x8d, 0x3d, 0x00, 0x00, 0x00, 0x00,
/* call __tls_get_addr@PLT */
0xe8, 0x00, 0x00, 0x00, 0x00 };
static const unsigned char replace[] = {
/* data16 data16 data16 mov %fs:0,%rax */
0x66, 0x66, 0x66, 0x64, 0x48, 0x8b, 0x04, 0x25,
0x00, 0x00, 0x00, 0x00 };
if (memcmp (ptr-3, expect, sizeof(expect)) == 0) {
memcpy(ptr-3, replace, sizeof(replace));
rel[1].r_info = ELFW(R_INFO)(0, R_X86_64_NONE);
}
else
tcc_error("unexpected R_X86_64_TLSLD pattern");
}
break;
case R_X86_64_DTPOFF32:
case R_X86_64_TPOFF32:
{
ElfW(Sym) *sym;
Section *sec;
int32_t x;
sym = &((ElfW(Sym) *)symtab_section->data)[sym_index];
sec = s1->sections[sym->st_shndx];
x = val - sec->sh_addr - sec->data_offset;
add32le(ptr, x);
}
break;
case R_X86_64_DTPOFF64:
case R_X86_64_TPOFF64:
{
ElfW(Sym) *sym;
Section *sec;
int32_t x;
sym = &((ElfW(Sym) *)symtab_section->data)[sym_index];
sec = s1->sections[sym->st_shndx];
x = val - sec->sh_addr - sec->data_offset;
add64le(ptr, x);
}
break;
case R_X86_64_NONE:
break;
case R_X86_64_RELATIVE:
#ifdef TCC_TARGET_PE
add32le(ptr, val - s1->pe_imagebase);
#endif
/* do nothing */
break;
default:
fprintf(stderr,"FIXME: handle reloc type %d at %x [%p] to %x\n",
type, (unsigned)addr, ptr, (unsigned)val);
break;
}
}
#endif /* !TARGET_DEFS_ONLY */
|
b1042fe294522789f3afc9a77ea29374084bc715
|
7eaf54a78c9e2117247cb2ab6d3a0c20719ba700
|
/SOFTWARE/A64-TERES/linux-a64/kernel/task_work.c
|
65bd3c92d6f3a14cf9db95f9ab7e22c368457661
|
[
"Linux-syscall-note",
"GPL-2.0-only",
"GPL-1.0-or-later",
"LicenseRef-scancode-free-unknown",
"Apache-2.0"
] |
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
|
UTF-8
|
C
| false
| false
| 2,223
|
c
|
task_work.c
|
#include <linux/spinlock.h>
#include <linux/task_work.h>
#include <linux/tracehook.h>
static struct callback_head work_exited; /* all we need is ->next == NULL */
int
task_work_add(struct task_struct *task, struct callback_head *work, bool notify)
{
struct callback_head *head;
do {
head = ACCESS_ONCE(task->task_works);
if (unlikely(head == &work_exited))
return -ESRCH;
work->next = head;
} while (cmpxchg(&task->task_works, head, work) != head);
if (notify)
set_notify_resume(task);
return 0;
}
struct callback_head *
task_work_cancel(struct task_struct *task, task_work_func_t func)
{
struct callback_head **pprev = &task->task_works;
struct callback_head *work = NULL;
unsigned long flags;
/*
* If cmpxchg() fails we continue without updating pprev.
* Either we raced with task_work_add() which added the
* new entry before this work, we will find it again. Or
* we raced with task_work_run(), *pprev == NULL/exited.
*/
raw_spin_lock_irqsave(&task->pi_lock, flags);
while ((work = ACCESS_ONCE(*pprev))) {
read_barrier_depends();
if (work->func != func)
pprev = &work->next;
else if (cmpxchg(pprev, work, work->next) == work)
break;
}
raw_spin_unlock_irqrestore(&task->pi_lock, flags);
return work;
}
void task_work_run(void)
{
struct task_struct *task = current;
struct callback_head *work, *head, *next;
for (;;) {
/*
* work->func() can do task_work_add(), do not set
* work_exited unless the list is empty.
*/
do {
work = ACCESS_ONCE(task->task_works);
head = !work && (task->flags & PF_EXITING) ?
&work_exited : NULL;
} while (cmpxchg(&task->task_works, work, head) != work);
if (!work)
break;
/*
* Synchronize with task_work_cancel(). It can't remove
* the first entry == work, cmpxchg(task_works) should
* fail, but it can play with *work and other entries.
*/
raw_spin_unlock_wait(&task->pi_lock);
smp_mb();
/* Reverse the list to run the works in fifo order */
head = NULL;
do {
next = work->next;
work->next = head;
head = work;
work = next;
} while (work);
work = head;
do {
next = work->next;
work->func(work);
work = next;
cond_resched();
} while (work);
}
}
|
11e53faeb1f357105401072238cf695c60ca52fd
|
eecd5e4c50d8b78a769bcc2675250576bed34066
|
/src/dm/impls/stag/stag.c
|
b3e1b77f704571442da8e2f5870ebdeadd82606d
|
[
"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
| 43,695
|
c
|
stag.c
|
/*
Implementation of DMStag, defining dimension-independent functions in the
DM API. stag1d.c, stag2d.c, and stag3d.c may include dimension-specific
implementations of DM API functions, and other files here contain additional
DMStag-specific API functions, as well as internal functions.
*/
#include <petsc/private/dmstagimpl.h>
#include <petscsf.h>
static PetscErrorCode DMCreateFieldDecomposition_Stag(DM dm, PetscInt *len, char ***namelist, IS **islist, DM **dmlist)
{
PetscInt f0, f1, f2, f3, dof0, dof1, dof2, dof3, n_entries, k, d, cnt, n_fields, dim;
DMStagStencil *stencil0, *stencil1, *stencil2, *stencil3;
PetscFunctionBegin;
PetscCall(DMGetDimension(dm, &dim));
PetscCall(DMStagGetDOF(dm, &dof0, &dof1, &dof2, &dof3));
PetscCall(DMStagGetEntriesPerElement(dm, &n_entries));
f0 = 1;
f1 = f2 = f3 = 0;
if (dim == 1) {
f1 = 1;
} else if (dim == 2) {
f1 = 2;
f2 = 1;
} else if (dim == 3) {
f1 = 3;
f2 = 3;
f3 = 1;
} else SETERRQ(PetscObjectComm((PetscObject)dm), PETSC_ERR_SUP, "Unsupported dimension %" PetscInt_FMT, dim);
PetscCall(PetscCalloc1(f0 * dof0, &stencil0));
PetscCall(PetscCalloc1(f1 * dof1, &stencil1));
if (dim >= 2) PetscCall(PetscCalloc1(f2 * dof2, &stencil2));
if (dim >= 3) PetscCall(PetscCalloc1(f3 * dof3, &stencil3));
for (k = 0; k < f0; ++k) {
for (d = 0; d < dof0; ++d) {
stencil0[dof0 * k + d].i = 0;
stencil0[dof0 * k + d].j = 0;
stencil0[dof0 * k + d].j = 0;
}
}
for (k = 0; k < f1; ++k) {
for (d = 0; d < dof1; ++d) {
stencil1[dof1 * k + d].i = 0;
stencil1[dof1 * k + d].j = 0;
stencil1[dof1 * k + d].j = 0;
}
}
if (dim >= 2) {
for (k = 0; k < f2; ++k) {
for (d = 0; d < dof2; ++d) {
stencil2[dof2 * k + d].i = 0;
stencil2[dof2 * k + d].j = 0;
stencil2[dof2 * k + d].j = 0;
}
}
}
if (dim >= 3) {
for (k = 0; k < f3; ++k) {
for (d = 0; d < dof3; ++d) {
stencil3[dof3 * k + d].i = 0;
stencil3[dof3 * k + d].j = 0;
stencil3[dof3 * k + d].j = 0;
}
}
}
n_fields = 0;
if (dof0 != 0) ++n_fields;
if (dof1 != 0) ++n_fields;
if (dim >= 2 && dof2 != 0) ++n_fields;
if (dim >= 3 && dof3 != 0) ++n_fields;
if (len) *len = n_fields;
if (islist) {
PetscCall(PetscMalloc1(n_fields, islist));
if (dim == 1) {
/* face, element */
for (d = 0; d < dof0; ++d) {
stencil0[d].loc = DMSTAG_LEFT;
stencil0[d].c = d;
}
for (d = 0; d < dof1; ++d) {
stencil1[d].loc = DMSTAG_ELEMENT;
stencil1[d].c = d;
}
} else if (dim == 2) {
/* vertex, edge(down,left), element */
for (d = 0; d < dof0; ++d) {
stencil0[d].loc = DMSTAG_DOWN_LEFT;
stencil0[d].c = d;
}
/* edge */
cnt = 0;
for (d = 0; d < dof1; ++d) {
stencil1[cnt].loc = DMSTAG_DOWN;
stencil1[cnt].c = d;
++cnt;
}
for (d = 0; d < dof1; ++d) {
stencil1[cnt].loc = DMSTAG_LEFT;
stencil1[cnt].c = d;
++cnt;
}
/* element */
for (d = 0; d < dof2; ++d) {
stencil2[d].loc = DMSTAG_ELEMENT;
stencil2[d].c = d;
}
} else if (dim == 3) {
/* vertex, edge(down,left), face(down,left,back), element */
for (d = 0; d < dof0; ++d) {
stencil0[d].loc = DMSTAG_BACK_DOWN_LEFT;
stencil0[d].c = d;
}
/* edges */
cnt = 0;
for (d = 0; d < dof1; ++d) {
stencil1[cnt].loc = DMSTAG_BACK_DOWN;
stencil1[cnt].c = d;
++cnt;
}
for (d = 0; d < dof1; ++d) {
stencil1[cnt].loc = DMSTAG_BACK_LEFT;
stencil1[cnt].c = d;
++cnt;
}
for (d = 0; d < dof1; ++d) {
stencil1[cnt].loc = DMSTAG_DOWN_LEFT;
stencil1[cnt].c = d;
++cnt;
}
/* faces */
cnt = 0;
for (d = 0; d < dof2; ++d) {
stencil2[cnt].loc = DMSTAG_BACK;
stencil2[cnt].c = d;
++cnt;
}
for (d = 0; d < dof2; ++d) {
stencil2[cnt].loc = DMSTAG_DOWN;
stencil2[cnt].c = d;
++cnt;
}
for (d = 0; d < dof2; ++d) {
stencil2[cnt].loc = DMSTAG_LEFT;
stencil2[cnt].c = d;
++cnt;
}
/* elements */
for (d = 0; d < dof3; ++d) {
stencil3[d].loc = DMSTAG_ELEMENT;
stencil3[d].c = d;
}
} else SETERRQ(PetscObjectComm((PetscObject)dm), PETSC_ERR_SUP, "Unsupported dimension %" PetscInt_FMT, dim);
cnt = 0;
if (dof0 != 0) {
PetscCall(DMStagCreateISFromStencils(dm, f0 * dof0, stencil0, &(*islist)[cnt]));
++cnt;
}
if (dof1 != 0) {
PetscCall(DMStagCreateISFromStencils(dm, f1 * dof1, stencil1, &(*islist)[cnt]));
++cnt;
}
if (dim >= 2 && dof2 != 0) {
PetscCall(DMStagCreateISFromStencils(dm, f2 * dof2, stencil2, &(*islist)[cnt]));
++cnt;
}
if (dim >= 3 && dof3 != 0) {
PetscCall(DMStagCreateISFromStencils(dm, f3 * dof3, stencil3, &(*islist)[cnt]));
++cnt;
}
}
if (namelist) {
PetscCall(PetscMalloc1(n_fields, namelist));
cnt = 0;
if (dim == 1) {
if (dof0 != 0) {
PetscCall(PetscStrallocpy("vertex", &(*namelist)[cnt]));
++cnt;
}
if (dof1 != 0) {
PetscCall(PetscStrallocpy("element", &(*namelist)[cnt]));
++cnt;
}
} else if (dim == 2) {
if (dof0 != 0) {
PetscCall(PetscStrallocpy("vertex", &(*namelist)[cnt]));
++cnt;
}
if (dof1 != 0) {
PetscCall(PetscStrallocpy("face", &(*namelist)[cnt]));
++cnt;
}
if (dof2 != 0) {
PetscCall(PetscStrallocpy("element", &(*namelist)[cnt]));
++cnt;
}
} else if (dim == 3) {
if (dof0 != 0) {
PetscCall(PetscStrallocpy("vertex", &(*namelist)[cnt]));
++cnt;
}
if (dof1 != 0) {
PetscCall(PetscStrallocpy("edge", &(*namelist)[cnt]));
++cnt;
}
if (dof2 != 0) {
PetscCall(PetscStrallocpy("face", &(*namelist)[cnt]));
++cnt;
}
if (dof3 != 0) {
PetscCall(PetscStrallocpy("element", &(*namelist)[cnt]));
++cnt;
}
}
} else SETERRQ(PetscObjectComm((PetscObject)dm), PETSC_ERR_SUP, "Unsupported dimension %" PetscInt_FMT, dim);
if (dmlist) {
PetscCall(PetscMalloc1(n_fields, dmlist));
cnt = 0;
if (dof0 != 0) {
PetscCall(DMStagCreateCompatibleDMStag(dm, dof0, 0, 0, 0, &(*dmlist)[cnt]));
++cnt;
}
if (dof1 != 0) {
PetscCall(DMStagCreateCompatibleDMStag(dm, 0, dof1, 0, 0, &(*dmlist)[cnt]));
++cnt;
}
if (dim >= 2 && dof2 != 0) {
PetscCall(DMStagCreateCompatibleDMStag(dm, 0, 0, dof2, 0, &(*dmlist)[cnt]));
++cnt;
}
if (dim >= 3 && dof3 != 0) {
PetscCall(DMStagCreateCompatibleDMStag(dm, 0, 0, 0, dof3, &(*dmlist)[cnt]));
++cnt;
}
}
PetscCall(PetscFree(stencil0));
PetscCall(PetscFree(stencil1));
if (dim >= 2) PetscCall(PetscFree(stencil2));
if (dim >= 3) PetscCall(PetscFree(stencil3));
PetscFunctionReturn(PETSC_SUCCESS);
}
static PetscErrorCode DMClone_Stag(DM dm, DM *newdm)
{
PetscFunctionBegin;
/* Destroy the DM created by generic logic in DMClone() */
if (*newdm) PetscCall(DMDestroy(newdm));
PetscCall(DMStagDuplicateWithoutSetup(dm, PetscObjectComm((PetscObject)dm), newdm));
PetscCall(DMSetUp(*newdm));
PetscFunctionReturn(PETSC_SUCCESS);
}
static PetscErrorCode DMCoarsen_Stag(DM dm, MPI_Comm comm, DM *dmc)
{
const DM_Stag *const stag = (DM_Stag *)dm->data;
PetscInt d, dim;
PetscFunctionBegin;
PetscCall(DMStagDuplicateWithoutSetup(dm, comm, dmc));
PetscCall(DMSetOptionsPrefix(*dmc, ((PetscObject)dm)->prefix));
PetscCall(DMGetDimension(dm, &dim));
for (d = 0; d < dim; ++d) PetscCheck(stag->N[d] % 2 == 0, PetscObjectComm((PetscObject)dm), PETSC_ERR_SUP, "coarsening not supported except for even numbers of elements in each dimension ");
PetscCall(DMStagSetGlobalSizes(*dmc, stag->N[0] / 2, stag->N[1] / 2, stag->N[2] / 2));
{
PetscInt *l[DMSTAG_MAX_DIM];
for (d = 0; d < dim; ++d) {
PetscInt i;
PetscCall(PetscMalloc1(stag->nRanks[d], &l[d]));
for (i = 0; i < stag->nRanks[d]; ++i) {
PetscCheck(stag->l[d][i] % 2 == 0, PetscObjectComm((PetscObject)dm), PETSC_ERR_SUP, "coarsening not supported except for an even number of elements in each direction on each rank");
l[d][i] = stag->l[d][i] / 2; /* Just halve everything */
}
}
PetscCall(DMStagSetOwnershipRanges(*dmc, l[0], l[1], l[2]));
for (d = 0; d < dim; ++d) PetscCall(PetscFree(l[d]));
}
PetscCall(DMSetUp(*dmc));
if (dm->coordinates[0].dm) { /* Note that with product coordinates, dm->coordinates = NULL, so we check the DM */
DM coordinate_dm, coordinate_dmc;
PetscBool isstag, isprod;
PetscCall(DMGetCoordinateDM(dm, &coordinate_dm));
PetscCall(PetscObjectTypeCompare((PetscObject)coordinate_dm, DMSTAG, &isstag));
PetscCall(PetscObjectTypeCompare((PetscObject)coordinate_dm, DMPRODUCT, &isprod));
if (isstag) {
PetscCall(DMStagSetUniformCoordinatesExplicit(*dmc, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)); /* Coordinates will be overwritten */
PetscCall(DMGetCoordinateDM(*dmc, &coordinate_dmc));
PetscCall(DMStagRestrictSimple(coordinate_dm, dm->coordinates[0].x, coordinate_dmc, (*dmc)->coordinates[0].x));
} else if (isprod) {
PetscCall(DMStagSetUniformCoordinatesProduct(*dmc, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)); /* Coordinates will be overwritten */
PetscCall(DMGetCoordinateDM(*dmc, &coordinate_dmc));
for (d = 0; d < dim; ++d) {
DM subdm_coarse, subdm_coord_coarse, subdm_fine, subdm_coord_fine;
PetscCall(DMProductGetDM(coordinate_dm, d, &subdm_fine));
PetscCall(DMGetCoordinateDM(subdm_fine, &subdm_coord_fine));
PetscCall(DMProductGetDM(coordinate_dmc, d, &subdm_coarse));
PetscCall(DMGetCoordinateDM(subdm_coarse, &subdm_coord_coarse));
PetscCall(DMStagRestrictSimple(subdm_coord_fine, subdm_fine->coordinates[0].xl, subdm_coord_coarse, subdm_coarse->coordinates[0].xl));
}
} else SETERRQ(PetscObjectComm((PetscObject)dm), PETSC_ERR_SUP, "Unknown coordinate DM type");
}
PetscFunctionReturn(PETSC_SUCCESS);
}
static PetscErrorCode DMRefine_Stag(DM dm, MPI_Comm comm, DM *dmc)
{
const DM_Stag *const stag = (DM_Stag *)dm->data;
PetscFunctionBegin;
PetscCall(DMStagDuplicateWithoutSetup(dm, comm, dmc));
PetscCall(DMSetOptionsPrefix(*dmc, ((PetscObject)dm)->prefix));
PetscCall(DMStagSetGlobalSizes(*dmc, stag->N[0] * 2, stag->N[1] * 2, stag->N[2] * 2));
{
PetscInt dim, d;
PetscInt *l[DMSTAG_MAX_DIM];
PetscCall(DMGetDimension(dm, &dim));
for (d = 0; d < dim; ++d) {
PetscInt i;
PetscCall(PetscMalloc1(stag->nRanks[d], &l[d]));
for (i = 0; i < stag->nRanks[d]; ++i) { l[d][i] = stag->l[d][i] * 2; /* Just double everything */ }
}
PetscCall(DMStagSetOwnershipRanges(*dmc, l[0], l[1], l[2]));
for (d = 0; d < dim; ++d) PetscCall(PetscFree(l[d]));
}
PetscCall(DMSetUp(*dmc));
/* Note: For now, we do not refine coordinates */
PetscFunctionReturn(PETSC_SUCCESS);
}
static PetscErrorCode DMDestroy_Stag(DM dm)
{
DM_Stag *stag;
PetscInt i;
PetscFunctionBegin;
stag = (DM_Stag *)dm->data;
for (i = 0; i < DMSTAG_MAX_DIM; ++i) PetscCall(PetscFree(stag->l[i]));
PetscCall(VecScatterDestroy(&stag->gtol));
PetscCall(VecScatterDestroy(&stag->ltog_injective));
PetscCall(PetscFree(stag->neighbors));
PetscCall(PetscFree(stag->locationOffsets));
PetscCall(PetscFree(stag->coordinateDMType));
PetscCall(PetscFree(stag));
PetscFunctionReturn(PETSC_SUCCESS);
}
static PetscErrorCode DMCreateGlobalVector_Stag(DM dm, Vec *vec)
{
DM_Stag *const stag = (DM_Stag *)dm->data;
PetscFunctionBegin;
PetscCheck(dm->setupcalled, PetscObjectComm((PetscObject)dm), PETSC_ERR_ARG_WRONGSTATE, "This function must be called after DMSetUp()");
PetscCall(VecCreate(PetscObjectComm((PetscObject)dm), vec));
PetscCall(VecSetSizes(*vec, stag->entries, PETSC_DETERMINE));
PetscCall(VecSetType(*vec, dm->vectype));
PetscCall(VecSetDM(*vec, dm));
/* Could set some ops, as DMDA does */
PetscCall(VecSetLocalToGlobalMapping(*vec, dm->ltogmap));
PetscFunctionReturn(PETSC_SUCCESS);
}
static PetscErrorCode DMCreateLocalVector_Stag(DM dm, Vec *vec)
{
DM_Stag *const stag = (DM_Stag *)dm->data;
PetscFunctionBegin;
PetscCheck(dm->setupcalled, PetscObjectComm((PetscObject)dm), PETSC_ERR_ARG_WRONGSTATE, "This function must be called after DMSetUp()");
PetscCall(VecCreate(PETSC_COMM_SELF, vec));
PetscCall(VecSetSizes(*vec, stag->entriesGhost, PETSC_DETERMINE));
PetscCall(VecSetType(*vec, dm->vectype));
PetscCall(VecSetBlockSize(*vec, stag->entriesPerElement));
PetscCall(VecSetDM(*vec, dm));
PetscFunctionReturn(PETSC_SUCCESS);
}
/* Helper function to check for the limited situations for which interpolation
and restriction functions are implemented */
static PetscErrorCode CheckTransferOperatorRequirements_Private(DM dmc, DM dmf)
{
PetscInt dim, stencilWidthc, stencilWidthf, nf[DMSTAG_MAX_DIM], nc[DMSTAG_MAX_DIM], doff[DMSTAG_MAX_STRATA], dofc[DMSTAG_MAX_STRATA];
PetscFunctionBegin;
PetscCall(DMGetDimension(dmc, &dim));
PetscCall(DMStagGetStencilWidth(dmc, &stencilWidthc));
PetscCheck(stencilWidthc >= 1, PetscObjectComm((PetscObject)dmc), PETSC_ERR_SUP, "DMCreateRestriction not implemented for coarse grid stencil width < 1");
PetscCall(DMStagGetStencilWidth(dmf, &stencilWidthf));
PetscCheck(stencilWidthf >= 1, PetscObjectComm((PetscObject)dmf), PETSC_ERR_SUP, "DMCreateRestriction not implemented for fine grid stencil width < 1");
PetscCall(DMStagGetLocalSizes(dmf, &nf[0], &nf[1], &nf[2]));
PetscCall(DMStagGetLocalSizes(dmc, &nc[0], &nc[1], &nc[2]));
for (PetscInt d = 0; d < dim; ++d)
PetscCheck(nf[d] == 2 * nc[d], PetscObjectComm((PetscObject)dmc), PETSC_ERR_SUP, "No support for fine to coarse ratio other than 2 (it is %" PetscInt_FMT " to %" PetscInt_FMT " in dimension %" PetscInt_FMT ")", nf[d], nc[d], d);
PetscCall(DMStagGetDOF(dmc, &dofc[0], &dofc[1], &dofc[2], &dofc[3]));
PetscCall(DMStagGetDOF(dmf, &doff[0], &doff[1], &doff[2], &doff[3]));
for (PetscInt d = 0; d < dim + 1; ++d)
PetscCheck(dofc[d] == doff[d], PetscObjectComm((PetscObject)dmc), PETSC_ERR_SUP, "No support for different numbers of dof per stratum between coarse and fine DMStag objects: dof%" PetscInt_FMT " is %" PetscInt_FMT " (fine) but %" PetscInt_FMT "(coarse))", d, doff[d], dofc[d]);
PetscFunctionReturn(PETSC_SUCCESS);
}
/* Since the interpolation uses MATMAIJ for dof > 0 we convert requests for non-MATAIJ baseded matrices to MATAIJ.
This is a bit of a hack; the reason for it is partially because -dm_mat_type defines the
matrix type for both the operator matrices and the interpolation matrices so that users
can select matrix types of base MATAIJ for accelerators
Note: The ConvertToAIJ() code below *has been copied from dainterp.c*! ConvertToAIJ() should perhaps be placed somewhere
in mat/utils to avoid code duplication, but then the DMStag and DMDA code would need to include the private Mat headers.
Since it is only used in two places, I have simply duplicated the code to avoid the need to exposure the private
Mat routines in parts of DM. If we find a need for ConvertToAIJ() elsewhere, then we should consolidate it to one
place in mat/utils.
*/
static PetscErrorCode ConvertToAIJ(MatType intype, MatType *outtype)
{
PetscInt i;
char const *types[3] = {MATAIJ, MATSEQAIJ, MATMPIAIJ};
PetscBool flg;
PetscFunctionBegin;
*outtype = MATAIJ;
for (i = 0; i < 3; i++) {
PetscCall(PetscStrbeginswith(intype, types[i], &flg));
if (flg) {
*outtype = intype;
break;
}
}
PetscFunctionReturn(PETSC_SUCCESS);
}
static PetscErrorCode DMCreateInterpolation_Stag(DM dmc, DM dmf, Mat *A, Vec *vec)
{
PetscInt dim, entriesf, entriesc, doff[DMSTAG_MAX_STRATA];
ISLocalToGlobalMapping ltogmf, ltogmc;
MatType mattype;
PetscFunctionBegin;
PetscCall(CheckTransferOperatorRequirements_Private(dmc, dmf));
PetscCall(DMStagGetEntries(dmf, &entriesf));
PetscCall(DMStagGetEntries(dmc, &entriesc));
PetscCall(DMGetLocalToGlobalMapping(dmf, <ogmf));
PetscCall(DMGetLocalToGlobalMapping(dmc, <ogmc));
PetscCall(MatCreate(PetscObjectComm((PetscObject)dmc), A));
PetscCall(MatSetSizes(*A, entriesf, entriesc, PETSC_DECIDE, PETSC_DECIDE));
PetscCall(ConvertToAIJ(dmc->mattype, &mattype));
PetscCall(MatSetType(*A, mattype));
PetscCall(MatSetLocalToGlobalMapping(*A, ltogmf, ltogmc));
PetscCall(DMGetDimension(dmc, &dim));
PetscCall(DMStagGetDOF(dmf, &doff[0], &doff[1], &doff[2], &doff[3]));
if (dim == 1) {
PetscCall(DMStagPopulateInterpolation1d_a_b_Private(dmc, dmf, *A));
} else if (dim == 2) {
if (doff[0] == 0) {
PetscCall(DMStagPopulateInterpolation2d_0_a_b_Private(dmc, dmf, *A));
} else
SETERRQ(PetscObjectComm((PetscObject)dmc), PETSC_ERR_SUP, "No default interpolation available between 2d DMStag objects with %" PetscInt_FMT " dof/vertex, %" PetscInt_FMT " dof/face and %" PetscInt_FMT " dof/element", doff[0], doff[1], doff[2]);
} else if (dim == 3) {
if (doff[0] == 0 && doff[1] == 0) {
PetscCall(DMStagPopulateInterpolation3d_0_0_a_b_Private(dmc, dmf, *A));
} else
SETERRQ(PetscObjectComm((PetscObject)dmc), PETSC_ERR_SUP, "No default interpolation available between 3d DMStag objects with %" PetscInt_FMT " dof/vertex, %" PetscInt_FMT " dof/edge, %" PetscInt_FMT " dof/face and %" PetscInt_FMT " dof/element", doff[0], doff[1], doff[2], doff[3]);
} else SETERRQ(PetscObjectComm((PetscObject)dmc), PETSC_ERR_ARG_OUTOFRANGE, "Unsupported dimension %" PetscInt_FMT, dim);
PetscCall(MatAssemblyBegin(*A, MAT_FINAL_ASSEMBLY));
PetscCall(MatAssemblyEnd(*A, MAT_FINAL_ASSEMBLY));
if (vec) *vec = NULL;
PetscFunctionReturn(PETSC_SUCCESS);
}
static PetscErrorCode DMCreateRestriction_Stag(DM dmc, DM dmf, Mat *A)
{
PetscInt dim, entriesf, entriesc, doff[DMSTAG_MAX_STRATA];
ISLocalToGlobalMapping ltogmf, ltogmc;
MatType mattype;
PetscFunctionBegin;
PetscCall(CheckTransferOperatorRequirements_Private(dmc, dmf));
PetscCall(DMStagGetEntries(dmf, &entriesf));
PetscCall(DMStagGetEntries(dmc, &entriesc));
PetscCall(DMGetLocalToGlobalMapping(dmf, <ogmf));
PetscCall(DMGetLocalToGlobalMapping(dmc, <ogmc));
PetscCall(MatCreate(PetscObjectComm((PetscObject)dmc), A));
PetscCall(MatSetSizes(*A, entriesc, entriesf, PETSC_DECIDE, PETSC_DECIDE)); /* Note transpose wrt interpolation */
PetscCall(ConvertToAIJ(dmc->mattype, &mattype));
PetscCall(MatSetType(*A, mattype));
PetscCall(MatSetLocalToGlobalMapping(*A, ltogmc, ltogmf)); /* Note transpose wrt interpolation */
PetscCall(DMGetDimension(dmc, &dim));
PetscCall(DMStagGetDOF(dmf, &doff[0], &doff[1], &doff[2], &doff[3]));
if (dim == 1) {
PetscCall(DMStagPopulateRestriction1d_a_b_Private(dmc, dmf, *A));
} else if (dim == 2) {
if (doff[0] == 0) {
PetscCall(DMStagPopulateRestriction2d_0_a_b_Private(dmc, dmf, *A));
} else
SETERRQ(PetscObjectComm((PetscObject)dmc), PETSC_ERR_SUP, "No default restriction available between 2d DMStag objects with %" PetscInt_FMT " dof/vertex, %" PetscInt_FMT " dof/face and %" PetscInt_FMT " dof/element", doff[0], doff[1], doff[2]);
} else if (dim == 3) {
if (doff[0] == 0 && doff[0] == 0) {
PetscCall(DMStagPopulateRestriction3d_0_0_a_b_Private(dmc, dmf, *A));
} else
SETERRQ(PetscObjectComm((PetscObject)dmc), PETSC_ERR_SUP, "No default restriction available between 3d DMStag objects with %" PetscInt_FMT " dof/vertex, %" PetscInt_FMT " dof/edge, %" PetscInt_FMT " dof/face and %" PetscInt_FMT " dof/element", doff[0], doff[1], doff[2], doff[3]);
} else SETERRQ(PetscObjectComm((PetscObject)dmc), PETSC_ERR_ARG_OUTOFRANGE, "Unsupported dimension %" PetscInt_FMT, dim);
PetscCall(MatAssemblyBegin(*A, MAT_FINAL_ASSEMBLY));
PetscCall(MatAssemblyEnd(*A, MAT_FINAL_ASSEMBLY));
PetscFunctionReturn(PETSC_SUCCESS);
}
static PetscErrorCode DMCreateMatrix_Stag(DM dm, Mat *mat)
{
MatType mat_type;
PetscBool is_shell, is_aij;
PetscInt dim, entries;
ISLocalToGlobalMapping ltogmap;
PetscFunctionBegin;
PetscCheck(dm->setupcalled, PetscObjectComm((PetscObject)dm), PETSC_ERR_ARG_WRONGSTATE, "This function must be called after DMSetUp()");
PetscCall(DMGetDimension(dm, &dim));
PetscCall(DMGetMatType(dm, &mat_type));
PetscCall(DMStagGetEntries(dm, &entries));
PetscCall(MatCreate(PetscObjectComm((PetscObject)dm), mat));
PetscCall(MatSetSizes(*mat, entries, entries, PETSC_DETERMINE, PETSC_DETERMINE));
PetscCall(MatSetType(*mat, mat_type));
PetscCall(MatSetUp(*mat));
PetscCall(DMGetLocalToGlobalMapping(dm, <ogmap));
PetscCall(MatSetLocalToGlobalMapping(*mat, ltogmap, ltogmap));
PetscCall(MatSetDM(*mat, dm));
/* Compare to similar and perhaps superior logic in DMCreateMatrix_DA, which creates
the matrix first and then performs this logic by checking for preallocation functions */
PetscCall(PetscObjectBaseTypeCompare((PetscObject)*mat, MATAIJ, &is_aij));
if (!is_aij) PetscCall(PetscObjectBaseTypeCompare((PetscObject)*mat, MATSEQAIJ, &is_aij));
if (!is_aij) PetscCall(PetscObjectBaseTypeCompare((PetscObject)*mat, MATMPIAIJ, &is_aij));
PetscCall(PetscStrcmp(mat_type, MATSHELL, &is_shell));
if (is_aij) {
Mat preallocator;
PetscInt m, n;
const PetscBool fill_with_zeros = PETSC_FALSE;
PetscCall(MatCreate(PetscObjectComm((PetscObject)dm), &preallocator));
PetscCall(MatSetType(preallocator, MATPREALLOCATOR));
PetscCall(MatGetLocalSize(*mat, &m, &n));
PetscCall(MatSetSizes(preallocator, m, n, PETSC_DECIDE, PETSC_DECIDE));
PetscCall(MatSetLocalToGlobalMapping(preallocator, ltogmap, ltogmap));
PetscCall(MatSetUp(preallocator));
switch (dim) {
case 1:
PetscCall(DMCreateMatrix_Stag_1D_AIJ_Assemble(dm, preallocator));
break;
case 2:
PetscCall(DMCreateMatrix_Stag_2D_AIJ_Assemble(dm, preallocator));
break;
case 3:
PetscCall(DMCreateMatrix_Stag_3D_AIJ_Assemble(dm, preallocator));
break;
default:
SETERRQ(PetscObjectComm((PetscObject)dm), PETSC_ERR_ARG_OUTOFRANGE, "Unsupported dimension %" PetscInt_FMT, dim);
}
PetscCall(MatPreallocatorPreallocate(preallocator, fill_with_zeros, *mat));
PetscCall(MatDestroy(&preallocator));
if (!dm->prealloc_only) {
/* Bind to CPU before assembly, to prevent unnecessary copies of zero entries from CPU to GPU */
PetscCall(MatBindToCPU(*mat, PETSC_TRUE));
switch (dim) {
case 1:
PetscCall(DMCreateMatrix_Stag_1D_AIJ_Assemble(dm, *mat));
break;
case 2:
PetscCall(DMCreateMatrix_Stag_2D_AIJ_Assemble(dm, *mat));
break;
case 3:
PetscCall(DMCreateMatrix_Stag_3D_AIJ_Assemble(dm, *mat));
break;
default:
SETERRQ(PetscObjectComm((PetscObject)dm), PETSC_ERR_ARG_OUTOFRANGE, "Unsupported dimension %" PetscInt_FMT, dim);
}
PetscCall(MatBindToCPU(*mat, PETSC_FALSE));
}
} else if (is_shell) {
/* nothing more to do */
} else SETERRQ(PetscObjectComm((PetscObject)dm), PETSC_ERR_SUP, "Not implemented for Mattype %s", mat_type);
PetscFunctionReturn(PETSC_SUCCESS);
}
static PetscErrorCode DMGetCompatibility_Stag(DM dm, DM dm2, PetscBool *compatible, PetscBool *set)
{
const DM_Stag *const stag = (DM_Stag *)dm->data;
const DM_Stag *const stag2 = (DM_Stag *)dm2->data;
PetscInt dim, dim2, i;
MPI_Comm comm;
PetscMPIInt sameComm;
DMType type2;
PetscBool sameType;
PetscFunctionBegin;
PetscCall(DMGetType(dm2, &type2));
PetscCall(PetscStrcmp(DMSTAG, type2, &sameType));
if (!sameType) {
PetscCall(PetscInfo((PetscObject)dm, "DMStag compatibility check not implemented with DM of type %s\n", type2));
*set = PETSC_FALSE;
PetscFunctionReturn(PETSC_SUCCESS);
}
PetscCall(PetscObjectGetComm((PetscObject)dm, &comm));
PetscCallMPI(MPI_Comm_compare(comm, PetscObjectComm((PetscObject)dm2), &sameComm));
if (sameComm != MPI_IDENT) {
PetscCall(PetscInfo((PetscObject)dm, "DMStag objects have different communicators: %" PETSC_INTPTR_T_FMT " != %" PETSC_INTPTR_T_FMT "\n", (PETSC_INTPTR_T)comm, (PETSC_INTPTR_T)PetscObjectComm((PetscObject)dm2)));
*set = PETSC_FALSE;
PetscFunctionReturn(PETSC_SUCCESS);
}
PetscCall(DMGetDimension(dm, &dim));
PetscCall(DMGetDimension(dm2, &dim2));
if (dim != dim2) {
PetscCall(PetscInfo((PetscObject)dm, "DMStag objects have different dimensions\n"));
*set = PETSC_TRUE;
*compatible = PETSC_FALSE;
PetscFunctionReturn(PETSC_SUCCESS);
}
for (i = 0; i < dim; ++i) {
if (stag->N[i] != stag2->N[i]) {
PetscCall(PetscInfo((PetscObject)dm, "DMStag objects have different global numbers of elements in dimension %" PetscInt_FMT ": %" PetscInt_FMT " != %" PetscInt_FMT "\n", i, stag->n[i], stag2->n[i]));
*set = PETSC_TRUE;
*compatible = PETSC_FALSE;
PetscFunctionReturn(PETSC_SUCCESS);
}
if (stag->n[i] != stag2->n[i]) {
PetscCall(PetscInfo((PetscObject)dm, "DMStag objects have different local numbers of elements in dimension %" PetscInt_FMT ": %" PetscInt_FMT " != %" PetscInt_FMT "\n", i, stag->n[i], stag2->n[i]));
*set = PETSC_TRUE;
*compatible = PETSC_FALSE;
PetscFunctionReturn(PETSC_SUCCESS);
}
if (stag->boundaryType[i] != stag2->boundaryType[i]) {
PetscCall(PetscInfo((PetscObject)dm, "DMStag objects have different boundary types in dimension %" PetscInt_FMT ": %s != %s\n", i, DMBoundaryTypes[stag->boundaryType[i]], DMBoundaryTypes[stag2->boundaryType[i]]));
*set = PETSC_TRUE;
*compatible = PETSC_FALSE;
PetscFunctionReturn(PETSC_SUCCESS);
}
}
/* Note: we include stencil type and width in the notion of compatibility, as this affects
the "atlas" (local subdomains). This might be irritating in legitimate cases
of wanting to transfer between two other-wise compatible DMs with different
stencil characteristics. */
if (stag->stencilType != stag2->stencilType) {
PetscCall(PetscInfo((PetscObject)dm, "DMStag objects have different ghost stencil types: %s != %s\n", DMStagStencilTypes[stag->stencilType], DMStagStencilTypes[stag2->stencilType]));
*set = PETSC_TRUE;
*compatible = PETSC_FALSE;
PetscFunctionReturn(PETSC_SUCCESS);
}
if (stag->stencilWidth != stag2->stencilWidth) {
PetscCall(PetscInfo((PetscObject)dm, "DMStag objects have different ghost stencil widths: %" PetscInt_FMT " != %" PetscInt_FMT "\n", stag->stencilWidth, stag->stencilWidth));
*set = PETSC_TRUE;
*compatible = PETSC_FALSE;
PetscFunctionReturn(PETSC_SUCCESS);
}
*set = PETSC_TRUE;
*compatible = PETSC_TRUE;
PetscFunctionReturn(PETSC_SUCCESS);
}
static PetscErrorCode DMHasCreateInjection_Stag(DM dm, PetscBool *flg)
{
PetscFunctionBegin;
PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
PetscAssertPointer(flg, 2);
*flg = PETSC_FALSE;
PetscFunctionReturn(PETSC_SUCCESS);
}
/*
Note there are several orderings in play here.
In all cases, non-element dof are associated with the element that they are below/left/behind, and the order in 2D proceeds vertex/bottom edge/left edge/element (with all dof on each together).
Also in all cases, only subdomains which are the last in their dimension have partial elements.
1) "Natural" Ordering (not used). Number adding each full or partial (on the right or top) element, starting at the bottom left (i=0,j=0) and proceeding across the entire domain, row by row to get a global numbering.
2) Global ("PETSc") ordering. The same as natural, but restricted to each domain. So, traverse all elements (again starting at the bottom left and going row-by-row) on rank 0, then continue numbering with rank 1, and so on.
3) Local ordering. Including ghost elements (both interior and on the right/top/front to complete partial elements), use the same convention to create a local numbering.
*/
static PetscErrorCode DMLocalToGlobalBegin_Stag(DM dm, Vec l, InsertMode mode, Vec g)
{
DM_Stag *const stag = (DM_Stag *)dm->data;
PetscFunctionBegin;
if (mode == ADD_VALUES) {
PetscCall(VecScatterBegin(stag->gtol, l, g, mode, SCATTER_REVERSE));
} else if (mode == INSERT_VALUES) {
if (stag->ltog_injective) {
PetscCall(VecScatterBegin(stag->ltog_injective, l, g, mode, SCATTER_FORWARD));
} else {
PetscCall(VecScatterBegin(stag->gtol, l, g, mode, SCATTER_REVERSE_LOCAL));
}
} else SETERRQ(PetscObjectComm((PetscObject)dm), PETSC_ERR_SUP, "Unsupported InsertMode");
PetscFunctionReturn(PETSC_SUCCESS);
}
static PetscErrorCode DMLocalToGlobalEnd_Stag(DM dm, Vec l, InsertMode mode, Vec g)
{
DM_Stag *const stag = (DM_Stag *)dm->data;
PetscFunctionBegin;
if (mode == ADD_VALUES) {
PetscCall(VecScatterEnd(stag->gtol, l, g, mode, SCATTER_REVERSE));
} else if (mode == INSERT_VALUES) {
if (stag->ltog_injective) {
PetscCall(VecScatterEnd(stag->ltog_injective, l, g, mode, SCATTER_FORWARD));
} else {
PetscCall(VecScatterEnd(stag->gtol, l, g, mode, SCATTER_REVERSE_LOCAL));
}
} else SETERRQ(PetscObjectComm((PetscObject)dm), PETSC_ERR_SUP, "Unsupported InsertMode");
PetscFunctionReturn(PETSC_SUCCESS);
}
static PetscErrorCode DMGlobalToLocalBegin_Stag(DM dm, Vec g, InsertMode mode, Vec l)
{
DM_Stag *const stag = (DM_Stag *)dm->data;
PetscFunctionBegin;
PetscCall(VecScatterBegin(stag->gtol, g, l, mode, SCATTER_FORWARD));
PetscFunctionReturn(PETSC_SUCCESS);
}
static PetscErrorCode DMGlobalToLocalEnd_Stag(DM dm, Vec g, InsertMode mode, Vec l)
{
DM_Stag *const stag = (DM_Stag *)dm->data;
PetscFunctionBegin;
PetscCall(VecScatterEnd(stag->gtol, g, l, mode, SCATTER_FORWARD));
PetscFunctionReturn(PETSC_SUCCESS);
}
/*
If a stratum is active (non-zero dof), make it active in the coordinate DM.
*/
static PetscErrorCode DMCreateCoordinateDM_Stag(DM dm, DM *dmc)
{
DM_Stag *const stag = (DM_Stag *)dm->data;
PetscInt dim;
PetscBool isstag, isproduct;
const char *prefix;
PetscFunctionBegin;
PetscCheck(stag->coordinateDMType, PetscObjectComm((PetscObject)dm), PETSC_ERR_ARG_OUTOFRANGE, "Before creating a coordinate DM, a type must be specified with DMStagSetCoordinateDMType()");
PetscCall(DMGetDimension(dm, &dim));
PetscCall(PetscStrcmp(stag->coordinateDMType, DMSTAG, &isstag));
PetscCall(PetscStrcmp(stag->coordinateDMType, DMPRODUCT, &isproduct));
if (isstag) {
PetscCall(DMStagCreateCompatibleDMStag(dm, stag->dof[0] > 0 ? dim : 0, stag->dof[1] > 0 ? dim : 0, stag->dof[2] > 0 ? dim : 0, stag->dof[3] > 0 ? dim : 0, dmc));
} else if (isproduct) {
PetscCall(DMCreate(PETSC_COMM_WORLD, dmc));
PetscCall(DMSetType(*dmc, DMPRODUCT));
PetscCall(DMSetDimension(*dmc, dim));
} else SETERRQ(PetscObjectComm((PetscObject)dm), PETSC_ERR_SUP, "Unsupported coordinate DM type %s", stag->coordinateDMType);
PetscCall(PetscObjectGetOptionsPrefix((PetscObject)dm, &prefix));
PetscCall(PetscObjectSetOptionsPrefix((PetscObject)*dmc, prefix));
PetscCall(PetscObjectAppendOptionsPrefix((PetscObject)*dmc, "cdm_"));
PetscFunctionReturn(PETSC_SUCCESS);
}
static PetscErrorCode DMGetNeighbors_Stag(DM dm, PetscInt *nRanks, const PetscMPIInt *ranks[])
{
DM_Stag *const stag = (DM_Stag *)dm->data;
PetscInt dim;
PetscFunctionBegin;
PetscCall(DMGetDimension(dm, &dim));
switch (dim) {
case 1:
*nRanks = 3;
break;
case 2:
*nRanks = 9;
break;
case 3:
*nRanks = 27;
break;
default:
SETERRQ(PetscObjectComm((PetscObject)dm), PETSC_ERR_SUP, "Get neighbors not implemented for dim = %" PetscInt_FMT, dim);
}
*ranks = stag->neighbors;
PetscFunctionReturn(PETSC_SUCCESS);
}
static PetscErrorCode DMView_Stag(DM dm, PetscViewer viewer)
{
DM_Stag *const stag = (DM_Stag *)dm->data;
PetscBool isascii, viewAllRanks;
PetscMPIInt rank, size;
PetscInt dim, maxRanksToView, i;
PetscFunctionBegin;
PetscCallMPI(MPI_Comm_rank(PetscObjectComm((PetscObject)dm), &rank));
PetscCallMPI(MPI_Comm_size(PetscObjectComm((PetscObject)dm), &size));
PetscCall(DMGetDimension(dm, &dim));
PetscCall(PetscObjectTypeCompare((PetscObject)viewer, PETSCVIEWERASCII, &isascii));
if (isascii) {
PetscCall(PetscViewerASCIIPrintf(viewer, "Dimension: %" PetscInt_FMT "\n", dim));
switch (dim) {
case 1:
PetscCall(PetscViewerASCIIPrintf(viewer, "Global size: %" PetscInt_FMT "\n", stag->N[0]));
break;
case 2:
PetscCall(PetscViewerASCIIPrintf(viewer, "Global sizes: %" PetscInt_FMT " x %" PetscInt_FMT "\n", stag->N[0], stag->N[1]));
PetscCall(PetscViewerASCIIPrintf(viewer, "Parallel decomposition: %" PetscInt_FMT " x %" PetscInt_FMT " ranks\n", stag->nRanks[0], stag->nRanks[1]));
break;
case 3:
PetscCall(PetscViewerASCIIPrintf(viewer, "Global sizes: %" PetscInt_FMT " x %" PetscInt_FMT " x %" PetscInt_FMT "\n", stag->N[0], stag->N[1], stag->N[2]));
PetscCall(PetscViewerASCIIPrintf(viewer, "Parallel decomposition: %" PetscInt_FMT " x %" PetscInt_FMT " x %" PetscInt_FMT " ranks\n", stag->nRanks[0], stag->nRanks[1], stag->nRanks[2]));
break;
default:
SETERRQ(PetscObjectComm((PetscObject)dm), PETSC_ERR_SUP, "not implemented for dim==%" PetscInt_FMT, dim);
}
PetscCall(PetscViewerASCIIPrintf(viewer, "Boundary ghosting:"));
for (i = 0; i < dim; ++i) PetscCall(PetscViewerASCIIPrintf(viewer, " %s", DMBoundaryTypes[stag->boundaryType[i]]));
PetscCall(PetscViewerASCIIPrintf(viewer, "\n"));
PetscCall(PetscViewerASCIIPrintf(viewer, "Elementwise ghost stencil: %s", DMStagStencilTypes[stag->stencilType]));
if (stag->stencilType != DMSTAG_STENCIL_NONE) {
PetscCall(PetscViewerASCIIPrintf(viewer, ", width %" PetscInt_FMT "\n", stag->stencilWidth));
} else {
PetscCall(PetscViewerASCIIPrintf(viewer, "\n"));
}
PetscCall(PetscViewerASCIIPrintf(viewer, "%" PetscInt_FMT " DOF per vertex (0D)\n", stag->dof[0]));
if (dim == 3) PetscCall(PetscViewerASCIIPrintf(viewer, "%" PetscInt_FMT " DOF per edge (1D)\n", stag->dof[1]));
if (dim > 1) PetscCall(PetscViewerASCIIPrintf(viewer, "%" PetscInt_FMT " DOF per face (%" PetscInt_FMT "D)\n", stag->dof[dim - 1], dim - 1));
PetscCall(PetscViewerASCIIPrintf(viewer, "%" PetscInt_FMT " DOF per element (%" PetscInt_FMT "D)\n", stag->dof[dim], dim));
if (dm->coordinates[0].dm) PetscCall(PetscViewerASCIIPrintf(viewer, "Has coordinate DM\n"));
maxRanksToView = 16;
viewAllRanks = (PetscBool)(size <= maxRanksToView);
if (viewAllRanks) {
PetscCall(PetscViewerASCIIPushSynchronized(viewer));
switch (dim) {
case 1:
PetscCall(PetscViewerASCIISynchronizedPrintf(viewer, "[%d] Local elements : %" PetscInt_FMT " (%" PetscInt_FMT " with ghosts)\n", rank, stag->n[0], stag->nGhost[0]));
break;
case 2:
PetscCall(PetscViewerASCIISynchronizedPrintf(viewer, "[%d] Rank coordinates (%d,%d)\n", rank, stag->rank[0], stag->rank[1]));
PetscCall(PetscViewerASCIISynchronizedPrintf(viewer, "[%d] Local elements : %" PetscInt_FMT " x %" PetscInt_FMT " (%" PetscInt_FMT " x %" PetscInt_FMT " with ghosts)\n", rank, stag->n[0], stag->n[1], stag->nGhost[0], stag->nGhost[1]));
break;
case 3:
PetscCall(PetscViewerASCIISynchronizedPrintf(viewer, "[%d] Rank coordinates (%d,%d,%d)\n", rank, stag->rank[0], stag->rank[1], stag->rank[2]));
PetscCall(PetscViewerASCIISynchronizedPrintf(viewer, "[%d] Local elements : %" PetscInt_FMT " x %" PetscInt_FMT " x %" PetscInt_FMT " (%" PetscInt_FMT " x %" PetscInt_FMT " x %" PetscInt_FMT " with ghosts)\n", rank, stag->n[0], stag->n[1],
stag->n[2], stag->nGhost[0], stag->nGhost[1], stag->nGhost[2]));
break;
default:
SETERRQ(PetscObjectComm((PetscObject)dm), PETSC_ERR_SUP, "not implemented for dim==%" PetscInt_FMT, dim);
}
PetscCall(PetscViewerASCIISynchronizedPrintf(viewer, "[%d] Local native entries: %" PetscInt_FMT "\n", rank, stag->entries));
PetscCall(PetscViewerASCIISynchronizedPrintf(viewer, "[%d] Local entries total : %" PetscInt_FMT "\n", rank, stag->entriesGhost));
PetscCall(PetscViewerFlush(viewer));
PetscCall(PetscViewerASCIIPopSynchronized(viewer));
} else {
PetscCall(PetscViewerASCIIPrintf(viewer, "(Per-rank information omitted since >%" PetscInt_FMT " ranks used)\n", maxRanksToView));
}
}
PetscFunctionReturn(PETSC_SUCCESS);
}
static PetscErrorCode DMSetFromOptions_Stag(DM dm, PetscOptionItems *PetscOptionsObject)
{
DM_Stag *const stag = (DM_Stag *)dm->data;
PetscInt dim;
PetscFunctionBegin;
PetscCall(DMGetDimension(dm, &dim));
PetscOptionsHeadBegin(PetscOptionsObject, "DMStag Options");
PetscCall(PetscOptionsInt("-stag_grid_x", "Number of grid points in x direction", "DMStagSetGlobalSizes", stag->N[0], &stag->N[0], NULL));
if (dim > 1) PetscCall(PetscOptionsInt("-stag_grid_y", "Number of grid points in y direction", "DMStagSetGlobalSizes", stag->N[1], &stag->N[1], NULL));
if (dim > 2) PetscCall(PetscOptionsInt("-stag_grid_z", "Number of grid points in z direction", "DMStagSetGlobalSizes", stag->N[2], &stag->N[2], NULL));
PetscCall(PetscOptionsInt("-stag_ranks_x", "Number of ranks in x direction", "DMStagSetNumRanks", stag->nRanks[0], &stag->nRanks[0], NULL));
if (dim > 1) PetscCall(PetscOptionsInt("-stag_ranks_y", "Number of ranks in y direction", "DMStagSetNumRanks", stag->nRanks[1], &stag->nRanks[1], NULL));
if (dim > 2) PetscCall(PetscOptionsInt("-stag_ranks_z", "Number of ranks in z direction", "DMStagSetNumRanks", stag->nRanks[2], &stag->nRanks[2], NULL));
PetscCall(PetscOptionsInt("-stag_stencil_width", "Elementwise stencil width", "DMStagSetStencilWidth", stag->stencilWidth, &stag->stencilWidth, NULL));
PetscCall(PetscOptionsEnum("-stag_stencil_type", "Elementwise stencil stype", "DMStagSetStencilType", DMStagStencilTypes, (PetscEnum)stag->stencilType, (PetscEnum *)&stag->stencilType, NULL));
PetscCall(PetscOptionsEnum("-stag_boundary_type_x", "Treatment of (physical) boundaries in x direction", "DMStagSetBoundaryTypes", DMBoundaryTypes, (PetscEnum)stag->boundaryType[0], (PetscEnum *)&stag->boundaryType[0], NULL));
PetscCall(PetscOptionsEnum("-stag_boundary_type_y", "Treatment of (physical) boundaries in y direction", "DMStagSetBoundaryTypes", DMBoundaryTypes, (PetscEnum)stag->boundaryType[1], (PetscEnum *)&stag->boundaryType[1], NULL));
PetscCall(PetscOptionsEnum("-stag_boundary_type_z", "Treatment of (physical) boundaries in z direction", "DMStagSetBoundaryTypes", DMBoundaryTypes, (PetscEnum)stag->boundaryType[2], (PetscEnum *)&stag->boundaryType[2], NULL));
PetscCall(PetscOptionsInt("-stag_dof_0", "Number of dof per 0-cell (vertex)", "DMStagSetDOF", stag->dof[0], &stag->dof[0], NULL));
PetscCall(PetscOptionsInt("-stag_dof_1", "Number of dof per 1-cell (element in 1D, face in 2D, edge in 3D)", "DMStagSetDOF", stag->dof[1], &stag->dof[1], NULL));
PetscCall(PetscOptionsInt("-stag_dof_2", "Number of dof per 2-cell (element in 2D, face in 3D)", "DMStagSetDOF", stag->dof[2], &stag->dof[2], NULL));
PetscCall(PetscOptionsInt("-stag_dof_3", "Number of dof per 3-cell (element in 3D)", "DMStagSetDOF", stag->dof[3], &stag->dof[3], NULL));
PetscOptionsHeadEnd();
PetscFunctionReturn(PETSC_SUCCESS);
}
/*MC
DMSTAG - `"stag"` - A `DM` object representing a "staggered grid" or a structured cell complex.
Level: beginner
Notes:
This implementation parallels the `DMDA` implementation in many ways, but allows degrees of freedom
to be associated with all "strata" in a logically-rectangular grid.
Each stratum can be characterized by the dimension of the entities ("points", to borrow the `DMPLEX`
terminology), from 0- to 3-dimensional.
In some cases this numbering is used directly, for example with `DMStagGetDOF()`.
To allow easier reading and to some extent more similar code between different-dimensional implementations
of the same problem, we associate canonical names for each type of point, for each dimension of DMStag.
* 1-dimensional `DMSTAG` objects have vertices (0D) and elements (1D).
* 2-dimensional `DMSTAG` objects have vertices (0D), faces (1D), and elements (2D).
* 3-dimensional `DMSTAG` objects have vertices (0D), edges (1D), faces (2D), and elements (3D).
This naming is reflected when viewing a `DMSTAG` object with `DMView()`, and in forming
convenient options prefixes when creating a decomposition with `DMCreateFieldDecomposition()`.
.seealso: [](ch_stag), `DM`, `DMPRODUCT`, `DMDA`, `DMPLEX`, `DMStagCreate1d()`, `DMStagCreate2d()`, `DMStagCreate3d()`, `DMType`, `DMCreate()`,
`DMSetType()`, `DMStagVecSplitToDMDA()`
M*/
PETSC_EXTERN PetscErrorCode DMCreate_Stag(DM dm)
{
DM_Stag *stag;
PetscInt i, dim;
PetscFunctionBegin;
PetscAssertPointer(dm, 1);
PetscCall(PetscNew(&stag));
dm->data = stag;
stag->gtol = NULL;
stag->ltog_injective = NULL;
for (i = 0; i < DMSTAG_MAX_STRATA; ++i) stag->dof[i] = 0;
for (i = 0; i < DMSTAG_MAX_DIM; ++i) stag->l[i] = NULL;
stag->stencilType = DMSTAG_STENCIL_NONE;
stag->stencilWidth = 0;
for (i = 0; i < DMSTAG_MAX_DIM; ++i) stag->nRanks[i] = -1;
stag->coordinateDMType = NULL;
PetscCall(DMGetDimension(dm, &dim));
PetscCheck(dim == 1 || dim == 2 || dim == 3, PetscObjectComm((PetscObject)dm), PETSC_ERR_ARG_WRONGSTATE, "DMSetDimension() must be called to set a dimension with value 1, 2, or 3");
PetscCall(PetscMemzero(dm->ops, sizeof(*(dm->ops))));
dm->ops->createcoordinatedm = DMCreateCoordinateDM_Stag;
dm->ops->createglobalvector = DMCreateGlobalVector_Stag;
dm->ops->createlocalvector = DMCreateLocalVector_Stag;
dm->ops->creatematrix = DMCreateMatrix_Stag;
dm->ops->hascreateinjection = DMHasCreateInjection_Stag;
dm->ops->refine = DMRefine_Stag;
dm->ops->coarsen = DMCoarsen_Stag;
dm->ops->createinterpolation = DMCreateInterpolation_Stag;
dm->ops->createrestriction = DMCreateRestriction_Stag;
dm->ops->destroy = DMDestroy_Stag;
dm->ops->getneighbors = DMGetNeighbors_Stag;
dm->ops->globaltolocalbegin = DMGlobalToLocalBegin_Stag;
dm->ops->globaltolocalend = DMGlobalToLocalEnd_Stag;
dm->ops->localtoglobalbegin = DMLocalToGlobalBegin_Stag;
dm->ops->localtoglobalend = DMLocalToGlobalEnd_Stag;
dm->ops->setfromoptions = DMSetFromOptions_Stag;
switch (dim) {
case 1:
dm->ops->setup = DMSetUp_Stag_1d;
break;
case 2:
dm->ops->setup = DMSetUp_Stag_2d;
break;
case 3:
dm->ops->setup = DMSetUp_Stag_3d;
break;
default:
SETERRQ(PetscObjectComm((PetscObject)dm), PETSC_ERR_ARG_OUTOFRANGE, "Unsupported dimension %" PetscInt_FMT, dim);
}
dm->ops->clone = DMClone_Stag;
dm->ops->view = DMView_Stag;
dm->ops->getcompatibility = DMGetCompatibility_Stag;
dm->ops->createfielddecomposition = DMCreateFieldDecomposition_Stag;
PetscFunctionReturn(PETSC_SUCCESS);
}
|
916cc983e8bea3c044bc069f9ea333fca1260834
|
f79dec3c4033ca3cbb55d8a51a748cc7b8b6fbab
|
/x11/9term/patches/patch-libtext_text.c
|
ac0ff592e6774c1f8dacc18f14b48f8c51b41059
|
[] |
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
| 495
|
c
|
patch-libtext_text.c
|
$NetBSD: patch-libtext_text.c,v 1.1 2012/05/04 20:13:48 joerg Exp $
--- libtext/text.c.orig 1994-12-15 15:01:45.000000000 +0000
+++ libtext/text.c
@@ -4,7 +4,10 @@
#include <frame.h>
#include <text.h>
+#ifndef MAX
#define MAX(x, y) ((x > y) ? x : y)
+#endif
+
#define BUTTON(n) (1<<(n-1))
static Menu edit;
@@ -47,6 +50,7 @@ textalloc(Bitmap *b, Rectangle r, Font *
berror("textalloc: calloc");
t->length = 0;
t->base = 0;
+ t->end = 0;
t->p0 = 0;
t->p1 = 0;
t->pout = 0;
|
f2a38a8a1c371365dbd342511122e9ca295b7140
|
52c8ed39b32ccc7c0673278c1adea3638797c9ff
|
/src/framework/hardware/l-adc.c
|
93b67ee33f6619a2ae6f1b561af3b87edce26696
|
[
"MIT"
] |
permissive
|
xboot/xboot
|
0cab7b440b612aa0a4c366025598a53a7ec3adf1
|
6d6b93947b7fcb8c3924fedb0715c23877eedd5e
|
refs/heads/master
| 2023-08-20T05:56:25.149388
| 2023-07-12T07:38:29
| 2023-07-12T07:38:29
| 471,539
| 765
| 296
|
MIT
| 2023-05-25T09:39:01
| 2010-01-14T08:25:12
|
C
|
UTF-8
|
C
| false
| false
| 3,240
|
c
|
l-adc.c
|
/*
* framework/hardware/l-adc.c
*
* Copyright(c) 2007-2023 Jianjun Jiang <8192542@qq.com>
* Official site: http://xboot.org
* Mobile phone: +86-18665388956
* QQ: 8192542
*
* 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 <adc/adc.h>
#include <hardware/l-hardware.h>
static int l_adc_new(lua_State * L)
{
const char * name = luaL_optstring(L, 1, NULL);
struct adc_t * adc = search_adc(name);
if(!adc)
return 0;
lua_pushlightuserdata(L, adc);
luaL_setmetatable(L, MT_HARDWARE_ADC);
return 1;
}
static int l_adc_list(lua_State * L)
{
struct device_t * pos, * n;
struct adc_t * adc;
lua_newtable(L);
list_for_each_entry_safe(pos, n, &__device_head[DEVICE_TYPE_ADC], head)
{
adc = (struct adc_t *)(pos->priv);
if(!adc)
continue;
lua_pushlightuserdata(L, adc);
luaL_setmetatable(L, MT_HARDWARE_ADC);
lua_setfield(L, -2, pos->name);
}
return 1;
}
static const luaL_Reg l_adc[] = {
{"new", l_adc_new},
{"list", l_adc_list},
{NULL, NULL}
};
static int m_adc_tostring(lua_State * L)
{
struct adc_t * adc = luaL_checkudata(L, 1, MT_HARDWARE_ADC);
lua_pushstring(L, adc->name);
return 1;
}
static int m_adc_channels(lua_State * L)
{
struct adc_t * adc = luaL_checkudata(L, 1, MT_HARDWARE_ADC);
lua_pushinteger(L, adc->nchannel);
return 1;
}
static int m_adc_read_raw(lua_State * L)
{
struct adc_t * adc = luaL_checkudata(L, 1, MT_HARDWARE_ADC);
int channel = luaL_checkinteger(L, 2);
u32_t raw = adc_read_raw(adc, channel);
lua_pushinteger(L, raw);
return 1;
}
static int m_adc_read_voltage(lua_State * L)
{
struct adc_t * adc = luaL_checkudata(L, 1, MT_HARDWARE_ADC);
int channel = luaL_checkinteger(L, 2);
int voltage = adc_read_voltage(adc, channel);
lua_pushnumber(L, voltage / (lua_Number)(1000000));
return 1;
}
static const luaL_Reg m_adc[] = {
{"__tostring", m_adc_tostring},
{"channels", m_adc_channels},
{"readRaw", m_adc_read_raw},
{"readVoltage", m_adc_read_voltage},
{NULL, NULL}
};
int luaopen_hardware_adc(lua_State * L)
{
luaL_newlib(L, l_adc);
luahelper_create_metatable(L, MT_HARDWARE_ADC, m_adc);
return 1;
}
|
7cae3bfbbe143abab637b3d202a7d412ef2d00ef
|
eb9c014c5d8a4ee9e959f717f7a17a2cf332f861
|
/src/service/cia301/co_sdo.h
|
37a68d649d663f6c808fea232eddfb2ee9d2be4e
|
[
"Apache-2.0",
"LicenseRef-scancode-proprietary-license"
] |
permissive
|
embedded-office/canopen-stack
|
bdc4af7504e5646fb7033c0a3d69b2a4cd33c1c9
|
f4e4db8b7792dc176f08c8d8fd9f2a3f6ac99621
|
refs/heads/master
| 2023-07-25T07:33:24.495170
| 2022-08-20T22:05:44
| 2022-08-20T22:05:44
| 234,890,722
| 319
| 105
|
Apache-2.0
| 2023-09-11T11:20:37
| 2020-01-19T11:43:51
|
C
|
UTF-8
|
C
| false
| false
| 5,874
|
h
|
co_sdo.h
|
/******************************************************************************
Copyright 2020 Embedded Office GmbH & Co. KG
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.
******************************************************************************/
#ifndef CO_SDO_H_
#define CO_SDO_H_
#if defined __cplusplus
extern "C"{
#endif
/******************************************************************************
* INCLUDES
******************************************************************************/
#include "co_types.h"
#include "co_cfg.h"
#include "co_obj.h"
/******************************************************************************
* PUBLIC DEFINES
******************************************************************************/
#define CO_SDO_ID_OFF ((uint32_t)1<<31) /*!< Disabled SDO server/COBID */
/*! \brief SDO server/client COB-ID parameter
*
* These macros constructs the COB-ID for usage in object entries
* index 1200..12ff: COB-ID for SDO servers and clients. The standard
* defines the following encoding:
* - bit31: valid: SDO exists (0) or not (1)
* - bit30: dyn: value is static (0) or dynamic (1)
* - bit29: frame = 11bit CAN-ID (0) or 29bit CAN-ID (1)
* - bit28-0: CAN-ID
*
* \param valid
* EMCY exists (1), or not (0)
*
* \param dynamic
* the value is static (0) or dynamic (1)
*
* \param id
* the CAN-ID (standard or extended format)
*
* \note: the macro inverts the given value for valid in comparison to the
* standard definition to avoid negated logic
* \{
*/
#define CO_COBID_SDO_STD(valid, dynamic, id) \
(uint32_t)(((uint32_t)(id) & 0x7ffuL) | \
(((uint32_t)(dynamic) & 0x1u) << 30u) | \
((uint32_t)(1uL - ((valid) & 0x1u)) << 31u))
#define CO_COBID_SDO_EXT(valid, dynamic, id) \
(uint32_t)(((uint32_t)(id) & 0x1fffffffuL) | \
((uint32_t)0x1u << 29u) | \
(((uint32_t)(dynamic) & 0x1u) << 30u) | \
((uint32_t)(1uL - ((valid) & 0x1u)) << 31u))
/*! \} */
/*! \brief SDO Default Connection
*
* The CANopen standard defines a mandatory connection for SDO server #0.
*/
#define CO_COBID_SDO_REQUEST() CO_COBID_SDO_STD(1u,0u,0x600uL)
#define CO_COBID_SDO_RESPONSE() CO_COBID_SDO_STD(1u,0u,0x580uL)
#define CO_SDO_ERR_TBIT 0x05030000 /*!< Toggle bit not alternated */
#define CO_SDO_ERR_TIMEOUT 0x05040000 /*!< SDO protocol timed out */
#define CO_SDO_ERR_CMD 0x05040001 /*!< SDO command specifier invalid/unknown */
#define CO_SDO_ERR_BLK_SIZE 0x05040002 /*!< Invalid block size (block mode) */
#define CO_SDO_ERR_SEQ_NUM 0x05040003 /*!< Invalid Sequence number (block mode) */
#define CO_SDO_ERR_CRC 0x05040004 /*!< Invalid CRC (block mode) */
#define CO_SDO_ERR_MEM 0x05040005 /*!< Out of memory */
#define CO_SDO_ERR_UNSUP 0x06010000 /*!< Unsupported access to an object */
#define CO_SDO_ERR_RD 0x06010001 /*!< Attempt to read a write only object */
#define CO_SDO_ERR_WR 0x06010002 /*!< Attempt to write a read only object */
#define CO_SDO_ERR_OBJ 0x06020000 /*!< Object doesn't exist in dictionary */
#define CO_SDO_ERR_HW_ACCESS 0x06060000 /*!< Access failed due to an hardware error */
#define CO_SDO_ERR_LEN 0x06070010 /*!< Length of parameter does not match */
#define CO_SDO_ERR_LEN_HIGH 0x06070012 /*!< Length of parameter too high */
#define CO_SDO_ERR_LEN_SMALL 0x06070013 /*!< Length of parameter too small */
#define CO_SDO_ERR_SUB 0x06090011 /*!< Subindex doesn't exist in dictionary */
#define CO_SDO_ERR_RANGE 0x06090030 /*!< Value range of parameter exceeded */
#define CO_SDO_ERR_TOS 0x08000020 /*!< Data can't be transfered or stored */
#define CO_SDO_ERR_TOS_STATE 0x08000022 /*!< Data can't be transfered or stored, */
/* because of the present device state */
#define CO_SDO_ERR_OBJ_MAP 0x06040041 /*!< Object cannot be mapped to the PDO */
#define CO_SDO_ERR_OBJ_MAP_N 0x06040042 /*!< Number and length exceed PDO */
#define CO_SDO_ERR_PARA_INCOMP 0x06040043 /*!< parameter incompatibility reason */
#define CO_SDO_ERR_GENERAL 0x08000000 /*!< General error */
#define CO_SDO_BUF_SEG 127
#define CO_SDO_BUF_BYTE (CO_SDO_BUF_SEG*7) /*!< transfer buffer size in byte */
/******************************************************************************
* PUBLIC TYPES
******************************************************************************/
/*! \brief SDO TRANSFER BUFFER
*
* This structure holds the data, which are needed for the SDO transfer
* buffer.
*/
typedef struct CO_SDO_BUF_T {
uint32_t Num; /*!< Number of bytes in transfer buffer */
uint8_t *Start; /*!< Pointer to start of transfer buffer */
uint8_t *Cur; /*!< Pointer to next free buffer location */
} CO_SDO_BUF;
#if defined __cplusplus
}
#endif
#endif /* CO_SDO_H_ */
|
ab9fdc3dbdf0a3416dac78f285dfd7e210c9911a
|
5a3056b45cbb1f4b8781e1086f68eeb3c455d5e6
|
/dependencies/SDL_sound/libmodplug/fastmix.c
|
dd702adfcd5d2f4e6d6afc6b2a8441d0411e0c31
|
[
"MIT",
"Zlib"
] |
permissive
|
gosu/gosu
|
d530632ba1cf257c99e3366649f6988dbff8a440
|
d92455f943e0c7447a9d86fde04225605dc3d440
|
refs/heads/master
| 2023-09-04T17:56:22.156971
| 2023-09-04T15:00:46
| 2023-09-04T15:00:46
| 193,464
| 1,353
| 161
|
NOASSERTION
| 2023-09-14T14:04:56
| 2009-05-05T22:35:44
|
C++
|
UTF-8
|
C
| false
| false
| 55,561
|
c
|
fastmix.c
|
/*
* This source code is public domain.
*
* Authors: Olivier Lapicque <olivierl@jps.net>
* Markus Fick <webmaster@mark-f.de> spline + fir-resampler
*/
#include "libmodplug.h"
#include <math.h>
#include "SDL_stdinc.h"
#define floor SDL_floor
/*
*-----------------------------------------------------------------------------
cubic spline interpolation doc,
(derived from "digital image warping", g. wolberg)
interpolation polynomial: f(x) = A3*(x-floor(x))**3 + A2*(x-floor(x))**2 +
A1*(x-floor(x)) + A0
with Y = equispaced data points (dist=1), YD = first derivates of data points and IP = floor(x)
the A[0..3] can be found by solving
A0 = Y[IP]
A1 = YD[IP]
A2 = 3*(Y[IP+1]-Y[IP])-2.0*YD[IP]-YD[IP+1]
A3 = -2.0 * (Y[IP+1]-Y[IP]) + YD[IP] - YD[IP+1]
with the first derivates as
YD[IP] = 0.5 * (Y[IP+1] - Y[IP-1]);
YD[IP+1] = 0.5 * (Y[IP+2] - Y[IP])
the coefs becomes
A0 = Y[IP]
A1 = YD[IP]
= 0.5*(Y[IP+1] - Y[IP-1]);
A2 = 3.0*(Y[IP+1]-Y[IP])-2.0*YD[IP]-YD[IP+1]
= 3.0*(Y[IP+1]-Y[IP]) - 0.5*2.0*(Y[IP+1]-Y[IP-1]) - 0.5*(Y[IP+2]-Y[IP])
= 3.0*Y[IP+1] - 3.0*Y[IP] - Y[IP+1] + Y[IP-1] - 0.5*Y[IP+2] + 0.5*Y[IP]
= -0.5*Y[IP+2] + 2.0 * Y[IP+1] - 2.5*Y[IP] + Y[IP-1]
= Y[IP-1] + 2 * Y[IP+1] - 0.5 * (5.0 * Y[IP] + Y[IP+2])
A3 = -2.0*(Y[IP+1]-Y[IP]) + YD[IP] + YD[IP+1]
= -2.0*Y[IP+1] + 2.0*Y[IP] + 0.5*(Y[IP+1]-Y[IP-1]) + 0.5*(Y[IP+2]-Y[IP])
= -2.0*Y[IP+1] + 2.0*Y[IP] + 0.5*Y[IP+1] - 0.5*Y[IP-1] + 0.5*Y[IP+2] - 0.5*Y[IP]
= 0.5 * Y[IP+2] - 1.5 * Y[IP+1] + 1.5 * Y[IP] - 0.5 * Y[IP-1]
= 0.5 * (3.0 * (Y[IP] - Y[IP+1]) - Y[IP-1] + YP[IP+2])
then interpolated data value is (horner rule)
out = (((A3*x)+A2)*x+A1)*x+A0
this gives parts of data points Y[IP-1] to Y[IP+2] of
part x**3 x**2 x**1 x**0
Y[IP-1] -0.5 1 -0.5 0
Y[IP] 1.5 -2.5 0 1
Y[IP+1] -1.5 2 0.5 0
Y[IP+2] 0.5 -0.5 0 0
*---------------------------------------------------------------------------
*/
// number of bits used to scale spline coefs
#define SPLINE_QUANTBITS 14
#define SPLINE_QUANTSCALE (1L<<SPLINE_QUANTBITS)
#define SPLINE_8SHIFT (SPLINE_QUANTBITS-8)
#define SPLINE_16SHIFT (SPLINE_QUANTBITS)
// forces coefsset to unity gain
#define SPLINE_CLAMPFORUNITY
// log2(number) of precalculated splines (range is [4..14])
#define SPLINE_FRACBITS 10
#define SPLINE_LUTLEN (1L<<SPLINE_FRACBITS)
static signed short CzCUBICSPLINE_lut[4*(1L<<SPLINE_FRACBITS)];
static void initCzCUBICSPLINE(void)
{
int _LIi;
int _LLen = (1L<<SPLINE_FRACBITS);
float _LFlen = 1.0f / (float)_LLen;
float _LScale = (float)SPLINE_QUANTSCALE;
for(_LIi=0;_LIi<_LLen;_LIi++)
{ float _LCm1, _LC0, _LC1, _LC2;
float _LX = ((float)_LIi)*_LFlen;
int _LSum,_LIdx = _LIi<<2;
_LCm1 = (float)floor( 0.5 + _LScale*(-0.5*_LX*_LX*_LX + 1.0*_LX*_LX - 0.5*_LX ) );
_LC0 = (float)floor( 0.5 + _LScale*( 1.5*_LX*_LX*_LX - 2.5*_LX*_LX + 1.0 ) );
_LC1 = (float)floor( 0.5 + _LScale*(-1.5*_LX*_LX*_LX + 2.0*_LX*_LX + 0.5*_LX ) );
_LC2 = (float)floor( 0.5 + _LScale*( 0.5*_LX*_LX*_LX - 0.5*_LX*_LX) );
CzCUBICSPLINE_lut[_LIdx+0] = (signed short)( (_LCm1 < -_LScale) ? -_LScale : ((_LCm1 > _LScale) ? _LScale : _LCm1) );
CzCUBICSPLINE_lut[_LIdx+1] = (signed short)( (_LC0 < -_LScale) ? -_LScale : ((_LC0 > _LScale) ? _LScale : _LC0 ) );
CzCUBICSPLINE_lut[_LIdx+2] = (signed short)( (_LC1 < -_LScale) ? -_LScale : ((_LC1 > _LScale) ? _LScale : _LC1 ) );
CzCUBICSPLINE_lut[_LIdx+3] = (signed short)( (_LC2 < -_LScale) ? -_LScale : ((_LC2 > _LScale) ? _LScale : _LC2 ) );
#ifdef SPLINE_CLAMPFORUNITY
_LSum = CzCUBICSPLINE_lut[_LIdx+0]+CzCUBICSPLINE_lut[_LIdx+1]+CzCUBICSPLINE_lut[_LIdx+2]+CzCUBICSPLINE_lut[_LIdx+3];
if( _LSum != SPLINE_QUANTSCALE )
{ int _LMax = _LIdx;
if( CzCUBICSPLINE_lut[_LIdx+1]>CzCUBICSPLINE_lut[_LMax] ) _LMax = _LIdx+1;
if( CzCUBICSPLINE_lut[_LIdx+2]>CzCUBICSPLINE_lut[_LMax] ) _LMax = _LIdx+2;
if( CzCUBICSPLINE_lut[_LIdx+3]>CzCUBICSPLINE_lut[_LMax] ) _LMax = _LIdx+3;
CzCUBICSPLINE_lut[_LMax] += ((signed short)SPLINE_QUANTSCALE-_LSum);
}
#endif
}
}
/*
------------------------------------------------------------------------------
fir interpolation doc,
(derived from "an engineer's guide to fir digital filters", n.j. loy)
calculate coefficients for ideal lowpass filter (with cutoff = fc in
0..1 (mapped to 0..nyquist))
c[-N..N] = (i==0) ? fc : sin(fc*pi*i)/(pi*i)
then apply selected window to coefficients
c[-N..N] *= w(0..N)
with n in 2*N and w(n) being a window function (see loy)
then calculate gain and scale filter coefs to have unity gain.
------------------------------------------------------------------------------
*/
// quantizer scale of window coefs
#define WFIR_QUANTBITS 15
#define WFIR_QUANTSCALE (1L<<WFIR_QUANTBITS)
#define WFIR_8SHIFT (WFIR_QUANTBITS-8)
#define WFIR_16BITSHIFT (WFIR_QUANTBITS)
// log2(number)-1 of precalculated taps range is [4..12]
#define WFIR_FRACBITS 10
#define WFIR_LUTLEN ((1L<<(WFIR_FRACBITS+1))+1)
// number of samples in window
#define WFIR_LOG2WIDTH 3
#define WFIR_WIDTH (1L<<WFIR_LOG2WIDTH)
#define WFIR_SMPSPERWING ((WFIR_WIDTH-1)>>1)
// cutoff (1.0 == pi/2)
#define WFIR_CUTOFF 0.90f
// wfir type
#define WFIR_HANN 0
#define WFIR_HAMMING 1
#define WFIR_BLACKMANEXACT 2
#define WFIR_BLACKMAN3T61 3
#define WFIR_BLACKMAN3T67 4
#define WFIR_BLACKMAN4T92 5
#define WFIR_BLACKMAN4T74 6
#define WFIR_KAISER4T 7
#define WFIR_TYPE WFIR_BLACKMANEXACT
// wfir help
#ifndef M_zPI
#define M_zPI 3.1415926535897932384626433832795
#endif
#define M_zEPS 1e-8
#define M_zBESSELEPS 1e-21
static float CzWINDOWEDFIR_coef( int _PCnr, float _POfs, float _PCut, int _PWidth, int _PType )
//OLD args to coef: float _PPos, float _PFc, int _PLen )
{
double _LWidthM1 = _PWidth-1;
double _LWidthM1Half = 0.5*_LWidthM1;
double _LPosU = ((double)_PCnr - _POfs);
double _LPos = _LPosU-_LWidthM1Half;
double _LPIdl = 2.0*M_zPI/_LWidthM1;
double _LWc,_LSi;
if( SDL_fabs(_LPos)<M_zEPS ) {
_LWc = 1.0;
_LSi = _PCut;
} else {
switch( _PType )
{
case WFIR_HANN:
_LWc = 0.50 - 0.50 * SDL_cos(_LPIdl*_LPosU);
break;
case WFIR_HAMMING:
_LWc = 0.54 - 0.46 * SDL_cos(_LPIdl*_LPosU);
break;
case WFIR_BLACKMANEXACT:
_LWc = 0.42 - 0.50 * SDL_cos(_LPIdl*_LPosU) +
0.08 * SDL_cos(2.0*_LPIdl*_LPosU);
break;
case WFIR_BLACKMAN3T61:
_LWc = 0.44959 - 0.49364 * SDL_cos(_LPIdl*_LPosU) +
0.05677 * SDL_cos(2.0*_LPIdl*_LPosU);
break;
case WFIR_BLACKMAN3T67:
_LWc = 0.42323 - 0.49755 * SDL_cos(_LPIdl*_LPosU) +
0.07922 * SDL_cos(2.0*_LPIdl*_LPosU);
break;
case WFIR_BLACKMAN4T92:
_LWc = 0.35875 - 0.48829 * SDL_cos(_LPIdl*_LPosU) +
0.14128 * SDL_cos(2.0*_LPIdl*_LPosU) -
0.01168 * SDL_cos(3.0*_LPIdl*_LPosU);
break;
case WFIR_BLACKMAN4T74:
_LWc = 0.40217 - 0.49703 * SDL_cos(_LPIdl*_LPosU) +
0.09392 * SDL_cos(2.0*_LPIdl*_LPosU) -
0.00183 * SDL_cos(3.0*_LPIdl*_LPosU);
break;
case WFIR_KAISER4T:
_LWc = 0.40243 - 0.49804 * SDL_cos(_LPIdl*_LPosU) +
0.09831 * SDL_cos(2.0*_LPIdl*_LPosU) -
0.00122 * SDL_cos(3.0*_LPIdl*_LPosU);
break;
default:
_LWc = 1.0;
break;
}
_LPos *= M_zPI;
_LSi = SDL_sin(_PCut*_LPos)/_LPos;
}
return (float)(_LWc*_LSi);
}
static signed short CzWINDOWEDFIR_lut[WFIR_LUTLEN*WFIR_WIDTH];
static void initCzWINDOWEDFIR(void)
{
int _LPcl;
float _LPcllen = (float)(1L<<WFIR_FRACBITS); // number of precalculated lines for 0..1 (-1..0)
float _LNorm = 1.0f / (float)(2.0f * _LPcllen);
float _LCut = WFIR_CUTOFF;
float _LScale = (float)WFIR_QUANTSCALE;
for( _LPcl=0;_LPcl<WFIR_LUTLEN;_LPcl++ )
{
float _LGain,_LCoefs[WFIR_WIDTH];
float _LOfs = ((float)_LPcl-_LPcllen)*_LNorm;
int _LCc,_LIdx = _LPcl<<WFIR_LOG2WIDTH;
for( _LCc=0,_LGain=0.0f;_LCc<WFIR_WIDTH;_LCc++ )
{ _LGain += (_LCoefs[_LCc] = CzWINDOWEDFIR_coef( _LCc, _LOfs, _LCut, WFIR_WIDTH, WFIR_TYPE ));
}
_LGain = 1.0f/_LGain;
for( _LCc=0;_LCc<WFIR_WIDTH;_LCc++ )
{ float _LCoef = (float)floor( 0.5 + _LScale*_LCoefs[_LCc]*_LGain );
CzWINDOWEDFIR_lut[_LIdx+_LCc] = (signed short)( (_LCoef<-_LScale)?-_LScale:((_LCoef>_LScale)?_LScale:_LCoef) );
}
}
}
void init_modplug_filters(void)
{
static int inited_filters = 0;
if (inited_filters) return;
inited_filters = 1;
initCzCUBICSPLINE();
initCzWINDOWEDFIR();
}
// ----------------------------------------------------------------------------
// MIXING MACROS
// ----------------------------------------------------------------------------
#define SNDMIX_BEGINSAMPLELOOP8\
register MODCHANNEL * const pChn = pChannel;\
const signed char *p = (signed char *)(pChn->pCurrentSample+pChn->nPos);\
int *pvol = pbuffer;\
nPos = pChn->nPosLo;\
if (pChn->dwFlags & CHN_STEREO) p += pChn->nPos;\
do {
#define SNDMIX_BEGINSAMPLELOOP16\
register MODCHANNEL * const pChn = pChannel;\
const signed short *p = (signed short *)(pChn->pCurrentSample+(pChn->nPos*2));\
int *pvol = pbuffer;\
nPos = pChn->nPosLo;\
if (pChn->dwFlags & CHN_STEREO) p += pChn->nPos;\
do {
#define SNDMIX_ENDSAMPLELOOP\
nPos += pChn->nInc;\
} while (pvol < pbufmax);\
pChn->nPos += nPos >> 16;\
pChn->nPosLo = nPos & 0xFFFF;
#define SNDMIX_ENDSAMPLELOOP8 SNDMIX_ENDSAMPLELOOP
#define SNDMIX_ENDSAMPLELOOP16 SNDMIX_ENDSAMPLELOOP
//////////////////////////////////////////////////////////////////////////////
// Mono
// No interpolation
#define SNDMIX_GETMONOVOL8NOIDO\
int vol = p[nPos >> 16] << 8;
#define SNDMIX_GETMONOVOL16NOIDO\
int vol = p[nPos >> 16];
// Linear Interpolation
#define SNDMIX_GETMONOVOL8LINEAR\
int poshi = nPos >> 16;\
int poslo = (nPos >> 8) & 0xFF;\
int srcvol = p[poshi];\
int destvol = p[poshi+1];\
int vol = (srcvol<<8) + ((int)(poslo * (destvol - srcvol)));
#define SNDMIX_GETMONOVOL16LINEAR\
int poshi = nPos >> 16;\
int poslo = (nPos >> 8) & 0xFF;\
int srcvol = p[poshi];\
int destvol = p[poshi+1];\
int vol = srcvol + ((int)(poslo * (destvol - srcvol)) >> 8);
// spline interpolation (2 guard bits should be enough???)
#define SPLINE_FRACSHIFT ((16-SPLINE_FRACBITS)-2)
#define SPLINE_FRACMASK (((1L<<(16-SPLINE_FRACSHIFT))-1)&~3)
#define SNDMIX_GETMONOVOL8SPLINE \
int poshi = nPos >> 16; \
int poslo = (nPos >> SPLINE_FRACSHIFT) & SPLINE_FRACMASK; \
int vol = (CzCUBICSPLINE_lut[poslo ]*(int)p[poshi-1] + \
CzCUBICSPLINE_lut[poslo+1]*(int)p[poshi ] + \
CzCUBICSPLINE_lut[poslo+3]*(int)p[poshi+2] + \
CzCUBICSPLINE_lut[poslo+2]*(int)p[poshi+1]) >> SPLINE_8SHIFT;
#define SNDMIX_GETMONOVOL16SPLINE \
int poshi = nPos >> 16; \
int poslo = (nPos >> SPLINE_FRACSHIFT) & SPLINE_FRACMASK; \
int vol = (CzCUBICSPLINE_lut[poslo ]*(int)p[poshi-1] + \
CzCUBICSPLINE_lut[poslo+1]*(int)p[poshi ] + \
CzCUBICSPLINE_lut[poslo+3]*(int)p[poshi+2] + \
CzCUBICSPLINE_lut[poslo+2]*(int)p[poshi+1]) >> SPLINE_16SHIFT;
// fir interpolation
#define WFIR_FRACSHIFT (16-(WFIR_FRACBITS+1+WFIR_LOG2WIDTH))
#define WFIR_FRACMASK ((((1L<<(17-WFIR_FRACSHIFT))-1)&~((1L<<WFIR_LOG2WIDTH)-1)))
#define WFIR_FRACHALVE (1L<<(16-(WFIR_FRACBITS+2)))
#define SNDMIX_GETMONOVOL8FIRFILTER \
int poshi = nPos >> 16;\
int poslo = (nPos & 0xFFFF);\
int firidx = ((poslo+WFIR_FRACHALVE)>>WFIR_FRACSHIFT) & WFIR_FRACMASK; \
int vol = (CzWINDOWEDFIR_lut[firidx+0]*(int)p[poshi+1-4]); \
vol += (CzWINDOWEDFIR_lut[firidx+1]*(int)p[poshi+2-4]); \
vol += (CzWINDOWEDFIR_lut[firidx+2]*(int)p[poshi+3-4]); \
vol += (CzWINDOWEDFIR_lut[firidx+3]*(int)p[poshi+4-4]); \
vol += (CzWINDOWEDFIR_lut[firidx+4]*(int)p[poshi+5-4]); \
vol += (CzWINDOWEDFIR_lut[firidx+5]*(int)p[poshi+6-4]); \
vol += (CzWINDOWEDFIR_lut[firidx+6]*(int)p[poshi+7-4]); \
vol += (CzWINDOWEDFIR_lut[firidx+7]*(int)p[poshi+8-4]); \
vol >>= WFIR_8SHIFT;
#define SNDMIX_GETMONOVOL16FIRFILTER \
int poshi = nPos >> 16;\
int poslo = (nPos & 0xFFFF);\
int firidx = ((poslo+WFIR_FRACHALVE)>>WFIR_FRACSHIFT) & WFIR_FRACMASK; \
int vol1, vol2, vol; \
vol1 = (CzWINDOWEDFIR_lut[firidx+0]*(int)p[poshi+1-4]); \
vol1 += (CzWINDOWEDFIR_lut[firidx+1]*(int)p[poshi+2-4]); \
vol1 += (CzWINDOWEDFIR_lut[firidx+2]*(int)p[poshi+3-4]); \
vol1 += (CzWINDOWEDFIR_lut[firidx+3]*(int)p[poshi+4-4]); \
vol2 = (CzWINDOWEDFIR_lut[firidx+4]*(int)p[poshi+5-4]); \
vol2 += (CzWINDOWEDFIR_lut[firidx+5]*(int)p[poshi+6-4]); \
vol2 += (CzWINDOWEDFIR_lut[firidx+6]*(int)p[poshi+7-4]); \
vol2 += (CzWINDOWEDFIR_lut[firidx+7]*(int)p[poshi+8-4]); \
vol = ((vol1>>1)+(vol2>>1)) >> (WFIR_16BITSHIFT-1);
/////////////////////////////////////////////////////////////////////////////
// Stereo
// No interpolation
#define SNDMIX_GETSTEREOVOL8NOIDO\
int vol_l = p[(nPos>>16)*2] << 8;\
int vol_r = p[(nPos>>16)*2+1] << 8;
#define SNDMIX_GETSTEREOVOL16NOIDO\
int vol_l = p[(nPos>>16)*2];\
int vol_r = p[(nPos>>16)*2+1];
// Linear Interpolation
#define SNDMIX_GETSTEREOVOL8LINEAR\
int poshi = nPos >> 16;\
int poslo = (nPos >> 8) & 0xFF;\
int srcvol_l = p[poshi*2];\
int vol_l = (srcvol_l<<8) + ((int)(poslo * (p[poshi*2+2] - srcvol_l)));\
int srcvol_r = p[poshi*2+1];\
int vol_r = (srcvol_r<<8) + ((int)(poslo * (p[poshi*2+3] - srcvol_r)));
#define SNDMIX_GETSTEREOVOL16LINEAR\
int poshi = nPos >> 16;\
int poslo = (nPos >> 8) & 0xFF;\
int srcvol_l = p[poshi*2];\
int vol_l = srcvol_l + ((int)(poslo * (p[poshi*2+2] - srcvol_l)) >> 8);\
int srcvol_r = p[poshi*2+1];\
int vol_r = srcvol_r + ((int)(poslo * (p[poshi*2+3] - srcvol_r)) >> 8);\
// Spline Interpolation
#define SNDMIX_GETSTEREOVOL8SPLINE \
int poshi = nPos >> 16; \
int poslo = (nPos >> SPLINE_FRACSHIFT) & SPLINE_FRACMASK; \
int vol_l = (CzCUBICSPLINE_lut[poslo ]*(int)p[(poshi-1)*2 ] + \
CzCUBICSPLINE_lut[poslo+1]*(int)p[(poshi )*2 ] + \
CzCUBICSPLINE_lut[poslo+2]*(int)p[(poshi+1)*2 ] + \
CzCUBICSPLINE_lut[poslo+3]*(int)p[(poshi+2)*2 ]) >> SPLINE_8SHIFT; \
int vol_r = (CzCUBICSPLINE_lut[poslo ]*(int)p[(poshi-1)*2+1] + \
CzCUBICSPLINE_lut[poslo+1]*(int)p[(poshi )*2+1] + \
CzCUBICSPLINE_lut[poslo+2]*(int)p[(poshi+1)*2+1] + \
CzCUBICSPLINE_lut[poslo+3]*(int)p[(poshi+2)*2+1]) >> SPLINE_8SHIFT;
#define SNDMIX_GETSTEREOVOL16SPLINE \
int poshi = nPos >> 16; \
int poslo = (nPos >> SPLINE_FRACSHIFT) & SPLINE_FRACMASK; \
int vol_l = (CzCUBICSPLINE_lut[poslo ]*(int)p[(poshi-1)*2 ] + \
CzCUBICSPLINE_lut[poslo+1]*(int)p[(poshi )*2 ] + \
CzCUBICSPLINE_lut[poslo+2]*(int)p[(poshi+1)*2 ] + \
CzCUBICSPLINE_lut[poslo+3]*(int)p[(poshi+2)*2 ]) >> SPLINE_16SHIFT; \
int vol_r = (CzCUBICSPLINE_lut[poslo ]*(int)p[(poshi-1)*2+1] + \
CzCUBICSPLINE_lut[poslo+1]*(int)p[(poshi )*2+1] + \
CzCUBICSPLINE_lut[poslo+2]*(int)p[(poshi+1)*2+1] + \
CzCUBICSPLINE_lut[poslo+3]*(int)p[(poshi+2)*2+1]) >> SPLINE_16SHIFT;
// fir interpolation
#define SNDMIX_GETSTEREOVOL8FIRFILTER \
int poshi = nPos >> 16;\
int poslo = (nPos & 0xFFFF);\
int firidx = ((poslo+WFIR_FRACHALVE)>>WFIR_FRACSHIFT) & WFIR_FRACMASK; \
int vol_l, vol_r; \
vol_l = (CzWINDOWEDFIR_lut[firidx+0]*(int)p[(poshi+1-4)*2 ]); \
vol_l += (CzWINDOWEDFIR_lut[firidx+1]*(int)p[(poshi+2-4)*2 ]); \
vol_l += (CzWINDOWEDFIR_lut[firidx+2]*(int)p[(poshi+3-4)*2 ]); \
vol_l += (CzWINDOWEDFIR_lut[firidx+3]*(int)p[(poshi+4-4)*2 ]); \
vol_l += (CzWINDOWEDFIR_lut[firidx+4]*(int)p[(poshi+5-4)*2 ]); \
vol_l += (CzWINDOWEDFIR_lut[firidx+5]*(int)p[(poshi+6-4)*2 ]); \
vol_l += (CzWINDOWEDFIR_lut[firidx+6]*(int)p[(poshi+7-4)*2 ]); \
vol_l += (CzWINDOWEDFIR_lut[firidx+7]*(int)p[(poshi+8-4)*2 ]); \
vol_l >>= WFIR_8SHIFT; \
vol_r = (CzWINDOWEDFIR_lut[firidx+0]*(int)p[(poshi+1-4)*2+1]); \
vol_r += (CzWINDOWEDFIR_lut[firidx+1]*(int)p[(poshi+2-4)*2+1]); \
vol_r += (CzWINDOWEDFIR_lut[firidx+2]*(int)p[(poshi+3-4)*2+1]); \
vol_r += (CzWINDOWEDFIR_lut[firidx+3]*(int)p[(poshi+4-4)*2+1]); \
vol_r += (CzWINDOWEDFIR_lut[firidx+4]*(int)p[(poshi+5-4)*2+1]); \
vol_r += (CzWINDOWEDFIR_lut[firidx+5]*(int)p[(poshi+6-4)*2+1]); \
vol_r += (CzWINDOWEDFIR_lut[firidx+6]*(int)p[(poshi+7-4)*2+1]); \
vol_r += (CzWINDOWEDFIR_lut[firidx+7]*(int)p[(poshi+8-4)*2+1]); \
vol_r >>= WFIR_8SHIFT;
#define SNDMIX_GETSTEREOVOL16FIRFILTER \
int poshi = nPos >> 16;\
int poslo = (nPos & 0xFFFF);\
int firidx = ((poslo+WFIR_FRACHALVE)>>WFIR_FRACSHIFT) & WFIR_FRACMASK; \
int vol1_l, vol2_l, vol_l, vol1_r, vol2_r, vol_r; \
vol1_l = (CzWINDOWEDFIR_lut[firidx+0]*(int)p[(poshi+1-4)*2 ]); \
vol1_l += (CzWINDOWEDFIR_lut[firidx+1]*(int)p[(poshi+2-4)*2 ]); \
vol1_l += (CzWINDOWEDFIR_lut[firidx+2]*(int)p[(poshi+3-4)*2 ]); \
vol1_l += (CzWINDOWEDFIR_lut[firidx+3]*(int)p[(poshi+4-4)*2 ]); \
vol2_l = (CzWINDOWEDFIR_lut[firidx+4]*(int)p[(poshi+5-4)*2 ]); \
vol2_l += (CzWINDOWEDFIR_lut[firidx+5]*(int)p[(poshi+6-4)*2 ]); \
vol2_l += (CzWINDOWEDFIR_lut[firidx+6]*(int)p[(poshi+7-4)*2 ]); \
vol2_l += (CzWINDOWEDFIR_lut[firidx+7]*(int)p[(poshi+8-4)*2 ]); \
vol_l = ((vol1_l>>1)+(vol2_l>>1)) >> (WFIR_16BITSHIFT-1); \
vol1_r = (CzWINDOWEDFIR_lut[firidx+0]*(int)p[(poshi+1-4)*2+1]); \
vol1_r += (CzWINDOWEDFIR_lut[firidx+1]*(int)p[(poshi+2-4)*2+1]); \
vol1_r += (CzWINDOWEDFIR_lut[firidx+2]*(int)p[(poshi+3-4)*2+1]); \
vol1_r += (CzWINDOWEDFIR_lut[firidx+3]*(int)p[(poshi+4-4)*2+1]); \
vol2_r = (CzWINDOWEDFIR_lut[firidx+4]*(int)p[(poshi+5-4)*2+1]); \
vol2_r += (CzWINDOWEDFIR_lut[firidx+5]*(int)p[(poshi+6-4)*2+1]); \
vol2_r += (CzWINDOWEDFIR_lut[firidx+6]*(int)p[(poshi+7-4)*2+1]); \
vol2_r += (CzWINDOWEDFIR_lut[firidx+7]*(int)p[(poshi+8-4)*2+1]); \
vol_r = ((vol1_r>>1)+(vol2_r>>1)) >> (WFIR_16BITSHIFT-1);
/////////////////////////////////////////////////////////////////////////////
#define SNDMIX_STOREMONOVOL\
pvol[0] += vol * pChn->nRightVol;\
pvol[1] += vol * pChn->nLeftVol;\
pvol += 2;
#define SNDMIX_STORESTEREOVOL\
pvol[0] += vol_l * pChn->nRightVol;\
pvol[1] += vol_r * pChn->nLeftVol;\
pvol += 2;
#define SNDMIX_STOREFASTMONOVOL\
do { \
int v = vol * pChn->nRightVol;\
pvol[0] += v;\
pvol[1] += v;\
pvol += 2; \
} while (0);
#define SNDMIX_RAMPMONOVOL\
nRampLeftVol += pChn->nLeftRamp;\
nRampRightVol += pChn->nRightRamp;\
pvol[0] += vol * (nRampRightVol >> VOLUMERAMPPRECISION);\
pvol[1] += vol * (nRampLeftVol >> VOLUMERAMPPRECISION);\
pvol += 2;
#define SNDMIX_RAMPFASTMONOVOL\
nRampRightVol += pChn->nRightRamp;\
do { \
int fastvol = vol * (nRampRightVol >> VOLUMERAMPPRECISION);\
pvol[0] += fastvol;\
pvol[1] += fastvol;\
pvol += 2; \
} while (0);
#define SNDMIX_RAMPSTEREOVOL\
nRampLeftVol += pChn->nLeftRamp;\
nRampRightVol += pChn->nRightRamp;\
pvol[0] += vol_l * (nRampRightVol >> VOLUMERAMPPRECISION);\
pvol[1] += vol_r * (nRampLeftVol >> VOLUMERAMPPRECISION);\
pvol += 2;
///////////////////////////////////////////////////
// Resonant Filters
// Mono
#define MIX_BEGIN_FILTER\
int fy1 = pChannel->nFilter_Y1;\
int fy2 = pChannel->nFilter_Y2;\
#define MIX_END_FILTER\
pChannel->nFilter_Y1 = fy1;\
pChannel->nFilter_Y2 = fy2;
#define SNDMIX_PROCESSFILTER\
vol = (vol * pChn->nFilter_A0 + fy1 * pChn->nFilter_B0 + fy2 * pChn->nFilter_B1 + 4096) >> 13;\
fy2 = fy1;\
fy1 = vol;\
// Stereo
#define MIX_BEGIN_STEREO_FILTER\
int fy1 = pChannel->nFilter_Y1;\
int fy2 = pChannel->nFilter_Y2;\
int fy3 = pChannel->nFilter_Y3;\
int fy4 = pChannel->nFilter_Y4;\
#define MIX_END_STEREO_FILTER\
pChannel->nFilter_Y1 = fy1;\
pChannel->nFilter_Y2 = fy2;\
pChannel->nFilter_Y3 = fy3;\
pChannel->nFilter_Y4 = fy4;\
#define SNDMIX_PROCESSSTEREOFILTER\
vol_l = (vol_l * pChn->nFilter_A0 + fy1 * pChn->nFilter_B0 + fy2 * pChn->nFilter_B1 + 4096) >> 13;\
vol_r = (vol_r * pChn->nFilter_A0 + fy3 * pChn->nFilter_B0 + fy4 * pChn->nFilter_B1 + 4096) >> 13;\
fy2 = fy1; fy1 = vol_l;\
fy4 = fy3; fy3 = vol_r;\
//////////////////////////////////////////////////////////
// Interfaces
typedef VOID (MPPASMCALL * LPMIXINTERFACE)(MODCHANNEL *, int *, int *);
#define BEGIN_MIX_INTERFACE(func)\
VOID MPPASMCALL func(MODCHANNEL *pChannel, int *pbuffer, int *pbufmax)\
{\
LONG nPos;
#define END_MIX_INTERFACE()\
SNDMIX_ENDSAMPLELOOP\
}
// Volume Ramps
#define BEGIN_RAMPMIX_INTERFACE(func)\
BEGIN_MIX_INTERFACE(func)\
LONG nRampRightVol = pChannel->nRampRightVol;\
LONG nRampLeftVol = pChannel->nRampLeftVol;
#define END_RAMPMIX_INTERFACE()\
SNDMIX_ENDSAMPLELOOP\
pChannel->nRampRightVol = nRampRightVol;\
pChannel->nRightVol = nRampRightVol >> VOLUMERAMPPRECISION;\
pChannel->nRampLeftVol = nRampLeftVol;\
pChannel->nLeftVol = nRampLeftVol >> VOLUMERAMPPRECISION;\
}
#define BEGIN_FASTRAMPMIX_INTERFACE(func)\
BEGIN_MIX_INTERFACE(func)\
LONG nRampRightVol = pChannel->nRampRightVol;
#define END_FASTRAMPMIX_INTERFACE()\
SNDMIX_ENDSAMPLELOOP\
pChannel->nRampRightVol = nRampRightVol;\
pChannel->nRampLeftVol = nRampRightVol;\
pChannel->nRightVol = nRampRightVol >> VOLUMERAMPPRECISION;\
pChannel->nLeftVol = pChannel->nRightVol;\
}
// Mono Resonant Filters
#define BEGIN_MIX_FLT_INTERFACE(func)\
BEGIN_MIX_INTERFACE(func)\
MIX_BEGIN_FILTER
#define END_MIX_FLT_INTERFACE()\
SNDMIX_ENDSAMPLELOOP\
MIX_END_FILTER\
}
#define BEGIN_RAMPMIX_FLT_INTERFACE(func)\
BEGIN_MIX_INTERFACE(func)\
LONG nRampRightVol = pChannel->nRampRightVol;\
LONG nRampLeftVol = pChannel->nRampLeftVol;\
MIX_BEGIN_FILTER
#define END_RAMPMIX_FLT_INTERFACE()\
SNDMIX_ENDSAMPLELOOP\
MIX_END_FILTER\
pChannel->nRampRightVol = nRampRightVol;\
pChannel->nRightVol = nRampRightVol >> VOLUMERAMPPRECISION;\
pChannel->nRampLeftVol = nRampLeftVol;\
pChannel->nLeftVol = nRampLeftVol >> VOLUMERAMPPRECISION;\
}
// Stereo Resonant Filters
#define BEGIN_MIX_STFLT_INTERFACE(func)\
BEGIN_MIX_INTERFACE(func)\
MIX_BEGIN_STEREO_FILTER
#define END_MIX_STFLT_INTERFACE()\
SNDMIX_ENDSAMPLELOOP\
MIX_END_STEREO_FILTER\
}
#define BEGIN_RAMPMIX_STFLT_INTERFACE(func)\
BEGIN_MIX_INTERFACE(func)\
LONG nRampRightVol = pChannel->nRampRightVol;\
LONG nRampLeftVol = pChannel->nRampLeftVol;\
MIX_BEGIN_STEREO_FILTER
#define END_RAMPMIX_STFLT_INTERFACE()\
SNDMIX_ENDSAMPLELOOP\
MIX_END_STEREO_FILTER\
pChannel->nRampRightVol = nRampRightVol;\
pChannel->nRightVol = nRampRightVol >> VOLUMERAMPPRECISION;\
pChannel->nRampLeftVol = nRampLeftVol;\
pChannel->nLeftVol = nRampLeftVol >> VOLUMERAMPPRECISION;\
}
/////////////////////////////////////////////////////
//
static void MPPASMCALL X86_InitMixBuffer(int *pBuffer, UINT nSamples);
static void MPPASMCALL X86_EndChannelOfs(MODCHANNEL *pChannel, int *pBuffer, UINT nSamples);
void MPPASMCALL X86_StereoFill(int *pBuffer, UINT nSamples, LPLONG lpROfs, LPLONG lpLOfs);
/////////////////////////////////////////////////////
// Mono samples functions
BEGIN_MIX_INTERFACE(Mono8BitMix)
SNDMIX_BEGINSAMPLELOOP8
SNDMIX_GETMONOVOL8NOIDO
SNDMIX_STOREMONOVOL
END_MIX_INTERFACE()
BEGIN_MIX_INTERFACE(Mono16BitMix)
SNDMIX_BEGINSAMPLELOOP16
SNDMIX_GETMONOVOL16NOIDO
SNDMIX_STOREMONOVOL
END_MIX_INTERFACE()
BEGIN_MIX_INTERFACE(Mono8BitLinearMix)
SNDMIX_BEGINSAMPLELOOP8
SNDMIX_GETMONOVOL8LINEAR
SNDMIX_STOREMONOVOL
END_MIX_INTERFACE()
BEGIN_MIX_INTERFACE(Mono16BitLinearMix)
SNDMIX_BEGINSAMPLELOOP16
SNDMIX_GETMONOVOL16LINEAR
SNDMIX_STOREMONOVOL
END_MIX_INTERFACE()
BEGIN_MIX_INTERFACE(Mono8BitSplineMix)
SNDMIX_BEGINSAMPLELOOP8
SNDMIX_GETMONOVOL8SPLINE
SNDMIX_STOREMONOVOL
END_MIX_INTERFACE()
BEGIN_MIX_INTERFACE(Mono16BitSplineMix)
SNDMIX_BEGINSAMPLELOOP16
SNDMIX_GETMONOVOL16SPLINE
SNDMIX_STOREMONOVOL
END_MIX_INTERFACE()
BEGIN_MIX_INTERFACE(Mono8BitFirFilterMix)
SNDMIX_BEGINSAMPLELOOP8
SNDMIX_GETMONOVOL8FIRFILTER
SNDMIX_STOREMONOVOL
END_MIX_INTERFACE()
BEGIN_MIX_INTERFACE(Mono16BitFirFilterMix)
SNDMIX_BEGINSAMPLELOOP16
SNDMIX_GETMONOVOL16FIRFILTER
SNDMIX_STOREMONOVOL
END_MIX_INTERFACE()
// Volume Ramps
BEGIN_RAMPMIX_INTERFACE(Mono8BitRampMix)
SNDMIX_BEGINSAMPLELOOP8
SNDMIX_GETMONOVOL8NOIDO
SNDMIX_RAMPMONOVOL
END_RAMPMIX_INTERFACE()
BEGIN_RAMPMIX_INTERFACE(Mono16BitRampMix)
SNDMIX_BEGINSAMPLELOOP16
SNDMIX_GETMONOVOL16NOIDO
SNDMIX_RAMPMONOVOL
END_RAMPMIX_INTERFACE()
BEGIN_RAMPMIX_INTERFACE(Mono8BitLinearRampMix)
SNDMIX_BEGINSAMPLELOOP8
SNDMIX_GETMONOVOL8LINEAR
SNDMIX_RAMPMONOVOL
END_RAMPMIX_INTERFACE()
BEGIN_RAMPMIX_INTERFACE(Mono16BitLinearRampMix)
SNDMIX_BEGINSAMPLELOOP16
SNDMIX_GETMONOVOL16LINEAR
SNDMIX_RAMPMONOVOL
END_RAMPMIX_INTERFACE()
BEGIN_RAMPMIX_INTERFACE(Mono8BitSplineRampMix)
SNDMIX_BEGINSAMPLELOOP8
SNDMIX_GETMONOVOL8SPLINE
SNDMIX_RAMPMONOVOL
END_RAMPMIX_INTERFACE()
BEGIN_RAMPMIX_INTERFACE(Mono16BitSplineRampMix)
SNDMIX_BEGINSAMPLELOOP16
SNDMIX_GETMONOVOL16SPLINE
SNDMIX_RAMPMONOVOL
END_RAMPMIX_INTERFACE()
BEGIN_RAMPMIX_INTERFACE(Mono8BitFirFilterRampMix)
SNDMIX_BEGINSAMPLELOOP8
SNDMIX_GETMONOVOL8FIRFILTER
SNDMIX_RAMPMONOVOL
END_RAMPMIX_INTERFACE()
BEGIN_RAMPMIX_INTERFACE(Mono16BitFirFilterRampMix)
SNDMIX_BEGINSAMPLELOOP16
SNDMIX_GETMONOVOL16FIRFILTER
SNDMIX_RAMPMONOVOL
END_RAMPMIX_INTERFACE()
//////////////////////////////////////////////////////
// Fast mono mix for leftvol=rightvol (1 less imul)
BEGIN_MIX_INTERFACE(FastMono8BitMix)
SNDMIX_BEGINSAMPLELOOP8
SNDMIX_GETMONOVOL8NOIDO
SNDMIX_STOREFASTMONOVOL
END_MIX_INTERFACE()
BEGIN_MIX_INTERFACE(FastMono16BitMix)
SNDMIX_BEGINSAMPLELOOP16
SNDMIX_GETMONOVOL16NOIDO
SNDMIX_STOREFASTMONOVOL
END_MIX_INTERFACE()
BEGIN_MIX_INTERFACE(FastMono8BitLinearMix)
SNDMIX_BEGINSAMPLELOOP8
SNDMIX_GETMONOVOL8LINEAR
SNDMIX_STOREFASTMONOVOL
END_MIX_INTERFACE()
BEGIN_MIX_INTERFACE(FastMono16BitLinearMix)
SNDMIX_BEGINSAMPLELOOP16
SNDMIX_GETMONOVOL16LINEAR
SNDMIX_STOREFASTMONOVOL
END_MIX_INTERFACE()
BEGIN_MIX_INTERFACE(FastMono8BitSplineMix)
SNDMIX_BEGINSAMPLELOOP8
SNDMIX_GETMONOVOL8SPLINE
SNDMIX_STOREFASTMONOVOL
END_MIX_INTERFACE()
BEGIN_MIX_INTERFACE(FastMono16BitSplineMix)
SNDMIX_BEGINSAMPLELOOP16
SNDMIX_GETMONOVOL16SPLINE
SNDMIX_STOREFASTMONOVOL
END_MIX_INTERFACE()
BEGIN_MIX_INTERFACE(FastMono8BitFirFilterMix)
SNDMIX_BEGINSAMPLELOOP8
SNDMIX_GETMONOVOL8FIRFILTER
SNDMIX_STOREFASTMONOVOL
END_MIX_INTERFACE()
BEGIN_MIX_INTERFACE(FastMono16BitFirFilterMix)
SNDMIX_BEGINSAMPLELOOP16
SNDMIX_GETMONOVOL16FIRFILTER
SNDMIX_STOREFASTMONOVOL
END_MIX_INTERFACE()
// Fast Ramps
BEGIN_FASTRAMPMIX_INTERFACE(FastMono8BitRampMix)
SNDMIX_BEGINSAMPLELOOP8
SNDMIX_GETMONOVOL8NOIDO
SNDMIX_RAMPFASTMONOVOL
END_FASTRAMPMIX_INTERFACE()
BEGIN_FASTRAMPMIX_INTERFACE(FastMono16BitRampMix)
SNDMIX_BEGINSAMPLELOOP16
SNDMIX_GETMONOVOL16NOIDO
SNDMIX_RAMPFASTMONOVOL
END_FASTRAMPMIX_INTERFACE()
BEGIN_FASTRAMPMIX_INTERFACE(FastMono8BitLinearRampMix)
SNDMIX_BEGINSAMPLELOOP8
SNDMIX_GETMONOVOL8LINEAR
SNDMIX_RAMPFASTMONOVOL
END_FASTRAMPMIX_INTERFACE()
BEGIN_FASTRAMPMIX_INTERFACE(FastMono16BitLinearRampMix)
SNDMIX_BEGINSAMPLELOOP16
SNDMIX_GETMONOVOL16LINEAR
SNDMIX_RAMPFASTMONOVOL
END_FASTRAMPMIX_INTERFACE()
BEGIN_FASTRAMPMIX_INTERFACE(FastMono8BitSplineRampMix)
SNDMIX_BEGINSAMPLELOOP8
SNDMIX_GETMONOVOL8SPLINE
SNDMIX_RAMPFASTMONOVOL
END_FASTRAMPMIX_INTERFACE()
BEGIN_FASTRAMPMIX_INTERFACE(FastMono16BitSplineRampMix)
SNDMIX_BEGINSAMPLELOOP16
SNDMIX_GETMONOVOL16SPLINE
SNDMIX_RAMPFASTMONOVOL
END_FASTRAMPMIX_INTERFACE()
BEGIN_FASTRAMPMIX_INTERFACE(FastMono8BitFirFilterRampMix)
SNDMIX_BEGINSAMPLELOOP8
SNDMIX_GETMONOVOL8FIRFILTER
SNDMIX_RAMPFASTMONOVOL
END_FASTRAMPMIX_INTERFACE()
BEGIN_FASTRAMPMIX_INTERFACE(FastMono16BitFirFilterRampMix)
SNDMIX_BEGINSAMPLELOOP16
SNDMIX_GETMONOVOL16FIRFILTER
SNDMIX_RAMPFASTMONOVOL
END_FASTRAMPMIX_INTERFACE()
//////////////////////////////////////////////////////
// Stereo samples
BEGIN_MIX_INTERFACE(Stereo8BitMix)
SNDMIX_BEGINSAMPLELOOP8
SNDMIX_GETSTEREOVOL8NOIDO
SNDMIX_STORESTEREOVOL
END_MIX_INTERFACE()
BEGIN_MIX_INTERFACE(Stereo16BitMix)
SNDMIX_BEGINSAMPLELOOP16
SNDMIX_GETSTEREOVOL16NOIDO
SNDMIX_STORESTEREOVOL
END_MIX_INTERFACE()
BEGIN_MIX_INTERFACE(Stereo8BitLinearMix)
SNDMIX_BEGINSAMPLELOOP8
SNDMIX_GETSTEREOVOL8LINEAR
SNDMIX_STORESTEREOVOL
END_MIX_INTERFACE()
BEGIN_MIX_INTERFACE(Stereo16BitLinearMix)
SNDMIX_BEGINSAMPLELOOP16
SNDMIX_GETSTEREOVOL16LINEAR
SNDMIX_STORESTEREOVOL
END_MIX_INTERFACE()
BEGIN_MIX_INTERFACE(Stereo8BitSplineMix)
SNDMIX_BEGINSAMPLELOOP8
SNDMIX_GETSTEREOVOL8SPLINE
SNDMIX_STORESTEREOVOL
END_MIX_INTERFACE()
BEGIN_MIX_INTERFACE(Stereo16BitSplineMix)
SNDMIX_BEGINSAMPLELOOP16
SNDMIX_GETSTEREOVOL16SPLINE
SNDMIX_STORESTEREOVOL
END_MIX_INTERFACE()
BEGIN_MIX_INTERFACE(Stereo8BitFirFilterMix)
SNDMIX_BEGINSAMPLELOOP8
SNDMIX_GETSTEREOVOL8FIRFILTER
SNDMIX_STORESTEREOVOL
END_MIX_INTERFACE()
BEGIN_MIX_INTERFACE(Stereo16BitFirFilterMix)
SNDMIX_BEGINSAMPLELOOP16
SNDMIX_GETSTEREOVOL16FIRFILTER
SNDMIX_STORESTEREOVOL
END_MIX_INTERFACE()
// Volume Ramps
BEGIN_RAMPMIX_INTERFACE(Stereo8BitRampMix)
SNDMIX_BEGINSAMPLELOOP8
SNDMIX_GETSTEREOVOL8NOIDO
SNDMIX_RAMPSTEREOVOL
END_RAMPMIX_INTERFACE()
BEGIN_RAMPMIX_INTERFACE(Stereo16BitRampMix)
SNDMIX_BEGINSAMPLELOOP16
SNDMIX_GETSTEREOVOL16NOIDO
SNDMIX_RAMPSTEREOVOL
END_RAMPMIX_INTERFACE()
BEGIN_RAMPMIX_INTERFACE(Stereo8BitLinearRampMix)
SNDMIX_BEGINSAMPLELOOP8
SNDMIX_GETSTEREOVOL8LINEAR
SNDMIX_RAMPSTEREOVOL
END_RAMPMIX_INTERFACE()
BEGIN_RAMPMIX_INTERFACE(Stereo16BitLinearRampMix)
SNDMIX_BEGINSAMPLELOOP16
SNDMIX_GETSTEREOVOL16LINEAR
SNDMIX_RAMPSTEREOVOL
END_RAMPMIX_INTERFACE()
BEGIN_RAMPMIX_INTERFACE(Stereo8BitSplineRampMix)
SNDMIX_BEGINSAMPLELOOP8
SNDMIX_GETSTEREOVOL8SPLINE
SNDMIX_RAMPSTEREOVOL
END_RAMPMIX_INTERFACE()
BEGIN_RAMPMIX_INTERFACE(Stereo16BitSplineRampMix)
SNDMIX_BEGINSAMPLELOOP16
SNDMIX_GETSTEREOVOL16SPLINE
SNDMIX_RAMPSTEREOVOL
END_RAMPMIX_INTERFACE()
BEGIN_RAMPMIX_INTERFACE(Stereo8BitFirFilterRampMix)
SNDMIX_BEGINSAMPLELOOP8
SNDMIX_GETSTEREOVOL8FIRFILTER
SNDMIX_RAMPSTEREOVOL
END_RAMPMIX_INTERFACE()
BEGIN_RAMPMIX_INTERFACE(Stereo16BitFirFilterRampMix)
SNDMIX_BEGINSAMPLELOOP16
SNDMIX_GETSTEREOVOL16FIRFILTER
SNDMIX_RAMPSTEREOVOL
END_RAMPMIX_INTERFACE()
//////////////////////////////////////////////////////
// Resonant Filter Mix
#ifndef NO_FILTER
// Mono Filter Mix
BEGIN_MIX_FLT_INTERFACE(FilterMono8BitMix)
SNDMIX_BEGINSAMPLELOOP8
SNDMIX_GETMONOVOL8NOIDO
SNDMIX_PROCESSFILTER
SNDMIX_STOREMONOVOL
END_MIX_FLT_INTERFACE()
BEGIN_MIX_FLT_INTERFACE(FilterMono16BitMix)
SNDMIX_BEGINSAMPLELOOP16
SNDMIX_GETMONOVOL16NOIDO
SNDMIX_PROCESSFILTER
SNDMIX_STOREMONOVOL
END_MIX_FLT_INTERFACE()
BEGIN_MIX_FLT_INTERFACE(FilterMono8BitLinearMix)
SNDMIX_BEGINSAMPLELOOP8
SNDMIX_GETMONOVOL8LINEAR
SNDMIX_PROCESSFILTER
SNDMIX_STOREMONOVOL
END_MIX_FLT_INTERFACE()
BEGIN_MIX_FLT_INTERFACE(FilterMono16BitLinearMix)
SNDMIX_BEGINSAMPLELOOP16
SNDMIX_GETMONOVOL16LINEAR
SNDMIX_PROCESSFILTER
SNDMIX_STOREMONOVOL
END_MIX_FLT_INTERFACE()
BEGIN_MIX_FLT_INTERFACE(FilterMono8BitSplineMix)
SNDMIX_BEGINSAMPLELOOP8
SNDMIX_GETMONOVOL8SPLINE
SNDMIX_PROCESSFILTER
SNDMIX_STOREMONOVOL
END_MIX_FLT_INTERFACE()
BEGIN_MIX_FLT_INTERFACE(FilterMono16BitSplineMix)
SNDMIX_BEGINSAMPLELOOP16
SNDMIX_GETMONOVOL16SPLINE
SNDMIX_PROCESSFILTER
SNDMIX_STOREMONOVOL
END_MIX_FLT_INTERFACE()
BEGIN_MIX_FLT_INTERFACE(FilterMono8BitFirFilterMix)
SNDMIX_BEGINSAMPLELOOP8
SNDMIX_GETMONOVOL8FIRFILTER
SNDMIX_PROCESSFILTER
SNDMIX_STOREMONOVOL
END_MIX_FLT_INTERFACE()
BEGIN_MIX_FLT_INTERFACE(FilterMono16BitFirFilterMix)
SNDMIX_BEGINSAMPLELOOP16
SNDMIX_GETMONOVOL16FIRFILTER
SNDMIX_PROCESSFILTER
SNDMIX_STOREMONOVOL
END_MIX_FLT_INTERFACE()
// Filter + Ramp
BEGIN_RAMPMIX_FLT_INTERFACE(FilterMono8BitRampMix)
SNDMIX_BEGINSAMPLELOOP8
SNDMIX_GETMONOVOL8NOIDO
SNDMIX_PROCESSFILTER
SNDMIX_RAMPMONOVOL
END_RAMPMIX_FLT_INTERFACE()
BEGIN_RAMPMIX_FLT_INTERFACE(FilterMono16BitRampMix)
SNDMIX_BEGINSAMPLELOOP16
SNDMIX_GETMONOVOL16NOIDO
SNDMIX_PROCESSFILTER
SNDMIX_RAMPMONOVOL
END_RAMPMIX_FLT_INTERFACE()
BEGIN_RAMPMIX_FLT_INTERFACE(FilterMono8BitLinearRampMix)
SNDMIX_BEGINSAMPLELOOP8
SNDMIX_GETMONOVOL8LINEAR
SNDMIX_PROCESSFILTER
SNDMIX_RAMPMONOVOL
END_RAMPMIX_FLT_INTERFACE()
BEGIN_RAMPMIX_FLT_INTERFACE(FilterMono16BitLinearRampMix)
SNDMIX_BEGINSAMPLELOOP16
SNDMIX_GETMONOVOL16LINEAR
SNDMIX_PROCESSFILTER
SNDMIX_RAMPMONOVOL
END_RAMPMIX_FLT_INTERFACE()
BEGIN_RAMPMIX_FLT_INTERFACE(FilterMono8BitSplineRampMix)
SNDMIX_BEGINSAMPLELOOP8
SNDMIX_GETMONOVOL8SPLINE
SNDMIX_PROCESSFILTER
SNDMIX_RAMPMONOVOL
END_RAMPMIX_FLT_INTERFACE()
BEGIN_RAMPMIX_FLT_INTERFACE(FilterMono16BitSplineRampMix)
SNDMIX_BEGINSAMPLELOOP16
SNDMIX_GETMONOVOL16SPLINE
SNDMIX_PROCESSFILTER
SNDMIX_RAMPMONOVOL
END_RAMPMIX_FLT_INTERFACE()
BEGIN_RAMPMIX_FLT_INTERFACE(FilterMono8BitFirFilterRampMix)
SNDMIX_BEGINSAMPLELOOP8
SNDMIX_GETMONOVOL8FIRFILTER
SNDMIX_PROCESSFILTER
SNDMIX_RAMPMONOVOL
END_RAMPMIX_FLT_INTERFACE()
BEGIN_RAMPMIX_FLT_INTERFACE(FilterMono16BitFirFilterRampMix)
SNDMIX_BEGINSAMPLELOOP16
SNDMIX_GETMONOVOL16FIRFILTER
SNDMIX_PROCESSFILTER
SNDMIX_RAMPMONOVOL
END_RAMPMIX_FLT_INTERFACE()
// Stereo Filter Mix
BEGIN_MIX_STFLT_INTERFACE(FilterStereo8BitMix)
SNDMIX_BEGINSAMPLELOOP8
SNDMIX_GETSTEREOVOL8NOIDO
SNDMIX_PROCESSSTEREOFILTER
SNDMIX_STORESTEREOVOL
END_MIX_STFLT_INTERFACE()
BEGIN_MIX_STFLT_INTERFACE(FilterStereo16BitMix)
SNDMIX_BEGINSAMPLELOOP16
SNDMIX_GETSTEREOVOL16NOIDO
SNDMIX_PROCESSSTEREOFILTER
SNDMIX_STORESTEREOVOL
END_MIX_STFLT_INTERFACE()
BEGIN_MIX_STFLT_INTERFACE(FilterStereo8BitLinearMix)
SNDMIX_BEGINSAMPLELOOP8
SNDMIX_GETSTEREOVOL8LINEAR
SNDMIX_PROCESSSTEREOFILTER
SNDMIX_STORESTEREOVOL
END_MIX_STFLT_INTERFACE()
BEGIN_MIX_STFLT_INTERFACE(FilterStereo16BitLinearMix)
SNDMIX_BEGINSAMPLELOOP16
SNDMIX_GETSTEREOVOL16LINEAR
SNDMIX_PROCESSSTEREOFILTER
SNDMIX_STORESTEREOVOL
END_MIX_STFLT_INTERFACE()
BEGIN_MIX_STFLT_INTERFACE(FilterStereo8BitSplineMix)
SNDMIX_BEGINSAMPLELOOP8
SNDMIX_GETSTEREOVOL8SPLINE
SNDMIX_PROCESSSTEREOFILTER
SNDMIX_STORESTEREOVOL
END_MIX_STFLT_INTERFACE()
BEGIN_MIX_STFLT_INTERFACE(FilterStereo16BitSplineMix)
SNDMIX_BEGINSAMPLELOOP16
SNDMIX_GETSTEREOVOL16SPLINE
SNDMIX_PROCESSSTEREOFILTER
SNDMIX_STORESTEREOVOL
END_MIX_STFLT_INTERFACE()
BEGIN_MIX_STFLT_INTERFACE(FilterStereo8BitFirFilterMix)
SNDMIX_BEGINSAMPLELOOP8
SNDMIX_GETSTEREOVOL8FIRFILTER
SNDMIX_PROCESSSTEREOFILTER
SNDMIX_STORESTEREOVOL
END_MIX_STFLT_INTERFACE()
BEGIN_MIX_STFLT_INTERFACE(FilterStereo16BitFirFilterMix)
SNDMIX_BEGINSAMPLELOOP16
SNDMIX_GETSTEREOVOL16FIRFILTER
SNDMIX_PROCESSSTEREOFILTER
SNDMIX_STORESTEREOVOL
END_MIX_STFLT_INTERFACE()
// Stereo Filter + Ramp
BEGIN_RAMPMIX_STFLT_INTERFACE(FilterStereo8BitRampMix)
SNDMIX_BEGINSAMPLELOOP8
SNDMIX_GETSTEREOVOL8NOIDO
SNDMIX_PROCESSSTEREOFILTER
SNDMIX_RAMPSTEREOVOL
END_RAMPMIX_STFLT_INTERFACE()
BEGIN_RAMPMIX_STFLT_INTERFACE(FilterStereo16BitRampMix)
SNDMIX_BEGINSAMPLELOOP16
SNDMIX_GETSTEREOVOL16NOIDO
SNDMIX_PROCESSSTEREOFILTER
SNDMIX_RAMPSTEREOVOL
END_RAMPMIX_STFLT_INTERFACE()
BEGIN_RAMPMIX_STFLT_INTERFACE(FilterStereo8BitLinearRampMix)
SNDMIX_BEGINSAMPLELOOP8
SNDMIX_GETSTEREOVOL8LINEAR
SNDMIX_PROCESSSTEREOFILTER
SNDMIX_RAMPSTEREOVOL
END_RAMPMIX_STFLT_INTERFACE()
BEGIN_RAMPMIX_STFLT_INTERFACE(FilterStereo16BitLinearRampMix)
SNDMIX_BEGINSAMPLELOOP16
SNDMIX_GETSTEREOVOL16LINEAR
SNDMIX_PROCESSSTEREOFILTER
SNDMIX_RAMPSTEREOVOL
END_RAMPMIX_STFLT_INTERFACE()
BEGIN_RAMPMIX_STFLT_INTERFACE(FilterStereo8BitSplineRampMix)
SNDMIX_BEGINSAMPLELOOP8
SNDMIX_GETSTEREOVOL8SPLINE
SNDMIX_PROCESSSTEREOFILTER
SNDMIX_RAMPSTEREOVOL
END_RAMPMIX_STFLT_INTERFACE()
BEGIN_RAMPMIX_STFLT_INTERFACE(FilterStereo16BitSplineRampMix)
SNDMIX_BEGINSAMPLELOOP16
SNDMIX_GETSTEREOVOL16SPLINE
SNDMIX_PROCESSSTEREOFILTER
SNDMIX_RAMPSTEREOVOL
END_RAMPMIX_STFLT_INTERFACE()
BEGIN_RAMPMIX_STFLT_INTERFACE(FilterStereo8BitFirFilterRampMix)
SNDMIX_BEGINSAMPLELOOP8
SNDMIX_GETSTEREOVOL8FIRFILTER
SNDMIX_PROCESSSTEREOFILTER
SNDMIX_RAMPSTEREOVOL
END_RAMPMIX_STFLT_INTERFACE()
BEGIN_RAMPMIX_STFLT_INTERFACE(FilterStereo16BitFirFilterRampMix)
SNDMIX_BEGINSAMPLELOOP16
SNDMIX_GETSTEREOVOL16FIRFILTER
SNDMIX_PROCESSSTEREOFILTER
SNDMIX_RAMPSTEREOVOL
END_RAMPMIX_STFLT_INTERFACE()
#else
// Mono
#define FilterMono8BitMix Mono8BitMix
#define FilterMono16BitMix Mono16BitMix
#define FilterMono8BitLinearMix Mono8BitLinearMix
#define FilterMono16BitLinearMix Mono16BitLinearMix
#define FilterMono8BitSplineMix Mono8BitSplineMix
#define FilterMono16BitSplineMix Mono16BitSplineMix
#define FilterMono8BitFirFilterMix Mono8BitFirFilterMix
#define FilterMono16BitFirFilterMix Mono16BitFirFilterMix
#define FilterMono8BitRampMix Mono8BitRampMix
#define FilterMono16BitRampMix Mono16BitRampMix
#define FilterMono8BitLinearRampMix Mono8BitLinearRampMix
#define FilterMono16BitLinearRampMix Mono16BitLinearRampMix
#define FilterMono8BitSplineRampMix Mono8BitSplineRampMix
#define FilterMono16BitSplineRampMix Mono16BitSplineRampMix
#define FilterMono8BitFirFilterRampMix Mono8BitFirFilterRampMix
#define FilterMono16BitFirFilterRampMix Mono16BitFirFilterRampMix
// Stereo
#define FilterStereo8BitMix Stereo8BitMix
#define FilterStereo16BitMix Stereo16BitMix
#define FilterStereo8BitLinearMix Stereo8BitLinearMix
#define FilterStereo16BitLinearMix Stereo16BitLinearMix
#define FilterStereo8BitSplineMix Stereo8BitSplineMix
#define FilterStereo16BitSplineMix Stereo16BitSplineMix
#define FilterStereo8BitFirFilterMix Stereo8BitFirFilterMix
#define FilterStereo16BitFirFilterMix Stereo16BitFirFilterMix
#define FilterStereo8BitRampMix Stereo8BitRampMix
#define FilterStereo16BitRampMix Stereo16BitRampMix
#define FilterStereo8BitLinearRampMix Stereo8BitLinearRampMix
#define FilterStereo16BitLinearRampMix Stereo16BitLinearRampMix
#define FilterStereo8BitSplineRampMix Stereo8BitSplineRampMix
#define FilterStereo16BitSplineRampMix Stereo16BitSplineRampMix
#define FilterStereo8BitFirFilterRampMix Stereo8BitFirFilterRampMix
#define FilterStereo16BitFirFilterRampMix Stereo16BitFirFilterRampMix
#endif
///////////////////////////////////////////////////////////////////////////////
//
// Mix function tables
//
//
// Index is as follow:
// [b1-b0] format (8-bit-mono, 16-bit-mono, 8-bit-stereo, 16-bit-stereo)
// [b2] ramp
// [b3] filter
// [b5-b4] src type
//
#define MIXNDX_16BIT 0x01
#define MIXNDX_STEREO 0x02
#define MIXNDX_RAMP 0x04
#define MIXNDX_FILTER 0x08
#define MIXNDX_LINEARSRC 0x10
#define MIXNDX_SPLINESRC 0x20
#define MIXNDX_FIRSRC 0x30
static const LPMIXINTERFACE gpMixFunctionTable[2*2*16] =
{
// No SRC
Mono8BitMix, Mono16BitMix, Stereo8BitMix, Stereo16BitMix,
Mono8BitRampMix, Mono16BitRampMix, Stereo8BitRampMix,
Stereo16BitRampMix,
// No SRC, Filter
FilterMono8BitMix, FilterMono16BitMix, FilterStereo8BitMix,
FilterStereo16BitMix, FilterMono8BitRampMix, FilterMono16BitRampMix,
FilterStereo8BitRampMix, FilterStereo16BitRampMix,
// Linear SRC
Mono8BitLinearMix, Mono16BitLinearMix, Stereo8BitLinearMix,
Stereo16BitLinearMix, Mono8BitLinearRampMix, Mono16BitLinearRampMix,
Stereo8BitLinearRampMix,Stereo16BitLinearRampMix,
// Linear SRC, Filter
FilterMono8BitLinearMix, FilterMono16BitLinearMix,
FilterStereo8BitLinearMix, FilterStereo16BitLinearMix,
FilterMono8BitLinearRampMix, FilterMono16BitLinearRampMix,
FilterStereo8BitLinearRampMix, FilterStereo16BitLinearRampMix,
// FirFilter SRC
Mono8BitSplineMix, Mono16BitSplineMix, Stereo8BitSplineMix,
Stereo16BitSplineMix, Mono8BitSplineRampMix, Mono16BitSplineRampMix,
Stereo8BitSplineRampMix,Stereo16BitSplineRampMix,
// Spline SRC, Filter
FilterMono8BitSplineMix, FilterMono16BitSplineMix,
FilterStereo8BitSplineMix, FilterStereo16BitSplineMix,
FilterMono8BitSplineRampMix, FilterMono16BitSplineRampMix,
FilterStereo8BitSplineRampMix, FilterStereo16BitSplineRampMix,
// FirFilter SRC
Mono8BitFirFilterMix, Mono16BitFirFilterMix, Stereo8BitFirFilterMix,
Stereo16BitFirFilterMix, Mono8BitFirFilterRampMix,
Mono16BitFirFilterRampMix, Stereo8BitFirFilterRampMix,
Stereo16BitFirFilterRampMix,
// FirFilter SRC, Filter
FilterMono8BitFirFilterMix, FilterMono16BitFirFilterMix,
FilterStereo8BitFirFilterMix, FilterStereo16BitFirFilterMix,
FilterMono8BitFirFilterRampMix, FilterMono16BitFirFilterRampMix,
FilterStereo8BitFirFilterRampMix, FilterStereo16BitFirFilterRampMix
};
static const LPMIXINTERFACE gpFastMixFunctionTable[2*2*16] =
{
// No SRC
FastMono8BitMix, FastMono16BitMix, Stereo8BitMix, Stereo16BitMix,
FastMono8BitRampMix, FastMono16BitRampMix, Stereo8BitRampMix,
Stereo16BitRampMix,
// No SRC, Filter
FilterMono8BitMix, FilterMono16BitMix, FilterStereo8BitMix,
FilterStereo16BitMix, FilterMono8BitRampMix, FilterMono16BitRampMix,
FilterStereo8BitRampMix, FilterStereo16BitRampMix,
// Linear SRC
FastMono8BitLinearMix, FastMono16BitLinearMix, Stereo8BitLinearMix,
Stereo16BitLinearMix, FastMono8BitLinearRampMix,
FastMono16BitLinearRampMix, Stereo8BitLinearRampMix,
Stereo16BitLinearRampMix,
// Linear SRC, Filter
FilterMono8BitLinearMix, FilterMono16BitLinearMix,
FilterStereo8BitLinearMix, FilterStereo16BitLinearMix,
FilterMono8BitLinearRampMix, FilterMono16BitLinearRampMix,
FilterStereo8BitLinearRampMix, FilterStereo16BitLinearRampMix,
// Spline SRC
Mono8BitSplineMix, Mono16BitSplineMix, Stereo8BitSplineMix,
Stereo16BitSplineMix, Mono8BitSplineRampMix, Mono16BitSplineRampMix,
Stereo8BitSplineRampMix, Stereo16BitSplineRampMix,
// Spline SRC, Filter
FilterMono8BitSplineMix, FilterMono16BitSplineMix,
FilterStereo8BitSplineMix, FilterStereo16BitSplineMix,
FilterMono8BitSplineRampMix, FilterMono16BitSplineRampMix,
FilterStereo8BitSplineRampMix, FilterStereo16BitSplineRampMix,
// FirFilter SRC
Mono8BitFirFilterMix, Mono16BitFirFilterMix, Stereo8BitFirFilterMix,
Stereo16BitFirFilterMix, Mono8BitFirFilterRampMix,
Mono16BitFirFilterRampMix, Stereo8BitFirFilterRampMix,
Stereo16BitFirFilterRampMix,
// FirFilter SRC, Filter
FilterMono8BitFirFilterMix, FilterMono16BitFirFilterMix,
FilterStereo8BitFirFilterMix, FilterStereo16BitFirFilterMix,
FilterMono8BitFirFilterRampMix, FilterMono16BitFirFilterRampMix,
FilterStereo8BitFirFilterRampMix, FilterStereo16BitFirFilterRampMix,
};
/////////////////////////////////////////////////////////////////////////
static LONG MPPFASTCALL GetSampleCount(MODCHANNEL *pChn, LONG nSamples)
//---------------------------------------------------------------------
{
LONG nLoopStart = (pChn->dwFlags & CHN_LOOP) ? pChn->nLoopStart : 0;
LONG nInc = pChn->nInc;
LONG nPos, nPosLo, nSmpCount;
if ((nSamples <= 0) || (!nInc) || (!pChn->nLength)) return 0;
// Under zero ?
if ((LONG)pChn->nPos < nLoopStart)
{
if (nInc < 0)
{
// Invert loop for bidi loops
LONG nDelta = ((nLoopStart - pChn->nPos) << 16) - (pChn->nPosLo & 0xffff);
pChn->nPos = nLoopStart | (nDelta>>16);
pChn->nPosLo = nDelta & 0xffff;
if (((LONG)pChn->nPos < nLoopStart) ||
(pChn->nPos >= (nLoopStart+pChn->nLength)/2))
{
pChn->nPos = nLoopStart; pChn->nPosLo = 0;
}
nInc = -nInc;
pChn->nInc = nInc;
pChn->dwFlags &= ~(CHN_PINGPONGFLAG); // go forward
if ((!(pChn->dwFlags & CHN_LOOP)) || (pChn->nPos >= pChn->nLength))
{
pChn->nPos = pChn->nLength;
pChn->nPosLo = 0;
return 0;
}
} else
{
// We probably didn't hit the loop end yet
// (first loop), so we do nothing
if ((LONG)pChn->nPos < 0) pChn->nPos = 0;
}
} else
// Past the end
if (pChn->nPos >= pChn->nLength)
{
if (!(pChn->dwFlags & CHN_LOOP)) return 0; // not looping -> stop this channel
if (pChn->dwFlags & CHN_PINGPONGLOOP)
{
LONG nDeltaHi, nDeltaLo;
// Invert loop
if (nInc > 0)
{
nInc = -nInc;
pChn->nInc = nInc;
}
pChn->dwFlags |= CHN_PINGPONGFLAG;
// adjust loop position
nDeltaHi = (pChn->nPos - pChn->nLength);
nDeltaLo = 0x10000 - (pChn->nPosLo & 0xffff);
pChn->nPos = pChn->nLength - nDeltaHi - (nDeltaLo>>16);
pChn->nPosLo = nDeltaLo & 0xffff;
if ((pChn->nPos <= pChn->nLoopStart) ||
(pChn->nPos >= pChn->nLength))
pChn->nPos = pChn->nLength-1;
} else
{
if (nInc < 0) // This is a bug
{
nInc = -nInc;
pChn->nInc = nInc;
}
// Restart at loop start
pChn->nPos += nLoopStart - pChn->nLength;
if ((LONG)pChn->nPos < nLoopStart)
pChn->nPos = pChn->nLoopStart;
}
}
nPos = pChn->nPos;
// too big increment, and/or too small loop length
if (nPos < nLoopStart)
{
if ((nPos < 0) || (nInc < 0)) return 0;
}
if ((nPos < 0) || (nPos >= (LONG)pChn->nLength)) return 0;
nPosLo = (USHORT)pChn->nPosLo, nSmpCount = nSamples;
if (nInc < 0)
{
LONG nInv = -nInc;
LONG maxsamples = 16384 / ((nInv>>16)+1);
LONG nDeltaHi, nDeltaLo, nPosDest;
if (maxsamples < 2) maxsamples = 2;
if (nSamples > maxsamples) nSamples = maxsamples;
nDeltaHi = (nInv>>16) * (nSamples - 1);
nDeltaLo = (nInv&0xffff) * (nSamples - 1);
nPosDest = nPos - nDeltaHi + ((nPosLo - nDeltaLo) >> 16);
if (nPosDest < nLoopStart)
{
nSmpCount = (ULONG)(((((LONGLONG)nPos - nLoopStart) << 16) + nPosLo - 1) / nInv) + 1;
}
} else
{
LONG maxsamples = 16384 / ((nInc>>16)+1);
LONG nDeltaHi, nDeltaLo, nPosDest;
if (maxsamples < 2) maxsamples = 2;
if (nSamples > maxsamples) nSamples = maxsamples;
nDeltaHi = (nInc>>16) * (nSamples - 1);
nDeltaLo = (nInc&0xffff) * (nSamples - 1);
nPosDest = nPos + nDeltaHi + ((nPosLo + nDeltaLo)>>16);
if (nPosDest >= (LONG)pChn->nLength)
{
nSmpCount = (ULONG)(((((LONGLONG)pChn->nLength - nPos) << 16) - nPosLo - 1) / nInc) + 1;
}
}
if (nSmpCount <= 1) return 1;
if (nSmpCount > nSamples) return nSamples;
return nSmpCount;
}
UINT CSoundFile_CreateStereoMix(CSoundFile *_this, int count)
//-----------------------------------------
{
LPLONG pOfsL, pOfsR;
DWORD nchused, nchmixed;
UINT nrampsamples, nChn;
if (!count) return 0;
if (_this->gnChannels > 2) X86_InitMixBuffer(_this->MixRearBuffer, count*2);
nchused = nchmixed = 0;
for (nChn=0; nChn<_this->m_nMixChannels; nChn++)
{
const LPMIXINTERFACE *pMixFuncTable;
MODCHANNEL * const pChannel = &_this->Chn[_this->ChnMix[nChn]];
UINT nFlags;//, nMasterCh
LONG nSmpCount;
int nsamples;
int *pbuffer;
UINT naddmix;
if (!pChannel->pCurrentSample) continue;
//nMasterCh = (_this->ChnMix[nChn] < _this->m_nChannels) ? _this->ChnMix[nChn]+1 : pChannel->nMasterChn;
pOfsR = &_this->gnDryROfsVol;
pOfsL = &_this->gnDryLOfsVol;
nFlags = 0;
if (pChannel->dwFlags & CHN_16BIT) nFlags |= MIXNDX_16BIT;
if (pChannel->dwFlags & CHN_STEREO) nFlags |= MIXNDX_STEREO;
#ifndef NO_FILTER
if (pChannel->dwFlags & CHN_FILTER) nFlags |= MIXNDX_FILTER;
#endif
if (!(pChannel->dwFlags & CHN_NOIDO))
{
// use hq-fir mixer?
if( (_this->gdwSoundSetup & (SNDMIX_HQRESAMPLER|SNDMIX_ULTRAHQSRCMODE)) ==
(SNDMIX_HQRESAMPLER|SNDMIX_ULTRAHQSRCMODE) )
nFlags += MIXNDX_FIRSRC;
else if( (_this->gdwSoundSetup & (SNDMIX_HQRESAMPLER)) == SNDMIX_HQRESAMPLER )
nFlags += MIXNDX_SPLINESRC;
else
nFlags += MIXNDX_LINEARSRC; // use
}
if ((nFlags < 0x40) && (pChannel->nLeftVol == pChannel->nRightVol)
&& ((!pChannel->nRampLength) || (pChannel->nLeftRamp == pChannel->nRightRamp)))
{
pMixFuncTable = gpFastMixFunctionTable;
} else
{
pMixFuncTable = gpMixFunctionTable;
}
nsamples = count;
#ifndef MODPLUG_NO_REVERB
pbuffer = (_this->gdwSoundSetup & SNDMIX_REVERB) ? _this->MixReverbBuffer : _this->MixSoundBuffer;
if (pChannel->dwFlags & CHN_NOREVERB) pbuffer = _this->MixSoundBuffer;
if (pChannel->dwFlags & CHN_REVERB) pbuffer = _this->MixReverbBuffer;
if (pbuffer == _this->MixReverbBuffer)
{
if (!_this->gnReverbSend) SDL_memset(_this->MixReverbBuffer, 0, count * 8);
_this->gnReverbSend += count;
}
#else
pbuffer = _this->MixSoundBuffer;
#endif
nchused++;
////////////////////////////////////////////////////
SampleLooping:
nrampsamples = nsamples;
if (pChannel->nRampLength > 0)
{
if ((LONG)nrampsamples > pChannel->nRampLength) nrampsamples = pChannel->nRampLength;
}
if ((nSmpCount = GetSampleCount(pChannel, nrampsamples)) <= 0)
{
// Stopping the channel
pChannel->pCurrentSample = NULL;
pChannel->nLength = 0;
pChannel->nPos = 0;
pChannel->nPosLo = 0;
pChannel->nRampLength = 0;
X86_EndChannelOfs(pChannel, pbuffer, nsamples);
*pOfsR += pChannel->nROfs;
*pOfsL += pChannel->nLOfs;
pChannel->nROfs = pChannel->nLOfs = 0;
pChannel->dwFlags &= ~CHN_PINGPONGFLAG;
continue;
}
// Should we mix this channel ?
if (((nchmixed >= _this->m_nMaxMixChannels) && (!(_this->gdwSoundSetup & SNDMIX_DIRECTTODISK)))
|| ((!pChannel->nRampLength) && (!(pChannel->nLeftVol|pChannel->nRightVol))))
{
LONG delta = (pChannel->nInc * (LONG)nSmpCount) + (LONG)pChannel->nPosLo;
pChannel->nPosLo = delta & 0xFFFF;
pChannel->nPos += (delta >> 16);
pChannel->nROfs = pChannel->nLOfs = 0;
pbuffer += nSmpCount*2;
naddmix = 0;
} else
// Do mixing
{
// Choose function for mixing
LPMIXINTERFACE pMixFunc;
int *pbufmax;
pMixFunc = (pChannel->nRampLength) ? pMixFuncTable[nFlags|MIXNDX_RAMP] : pMixFuncTable[nFlags];
pbufmax = pbuffer + (nSmpCount*2);
pChannel->nROfs = - *(pbufmax-2);
pChannel->nLOfs = - *(pbufmax-1);
pMixFunc(pChannel, pbuffer, pbufmax);
pChannel->nROfs += *(pbufmax-2);
pChannel->nLOfs += *(pbufmax-1);
pbuffer = pbufmax;
naddmix = 1;
}
nsamples -= nSmpCount;
if (pChannel->nRampLength)
{
pChannel->nRampLength -= nSmpCount;
if (pChannel->nRampLength <= 0)
{
pChannel->nRampLength = 0;
pChannel->nRightVol = pChannel->nNewRightVol;
pChannel->nLeftVol = pChannel->nNewLeftVol;
pChannel->nRightRamp = pChannel->nLeftRamp = 0;
if ((pChannel->dwFlags & CHN_NOTEFADE) && (!(pChannel->nFadeOutVol)))
{
pChannel->nLength = 0;
pChannel->pCurrentSample = NULL;
}
}
}
if (nsamples > 0) goto SampleLooping;
nchmixed += naddmix;
}
return nchused;
}
// Clip and convert to 8 bit
//---GCCFIX: Asm replaced with C function
// The C version was written by Rani Assaf <rani@magic.metawire.com>, I believe
DWORD MPPASMCALL X86_Convert32To8(LPVOID lp8, int *pBuffer, DWORD lSampleCount, LPLONG lpMin, LPLONG lpMax)
{
int vumin = *lpMin, vumax = *lpMax;
unsigned char *p = (unsigned char *)lp8;
UINT i;
for (i=0; i<lSampleCount; i++)
{
int n = pBuffer[i];
if (n < MIXING_CLIPMIN)
n = MIXING_CLIPMIN;
else if (n > MIXING_CLIPMAX)
n = MIXING_CLIPMAX;
if (n < vumin)
vumin = n;
else if (n > vumax)
vumax = n;
p[i] = (n >> (24-MIXING_ATTENUATION)) ^ 0x80; // 8-bit unsigned
}
*lpMin = vumin;
*lpMax = vumax;
return lSampleCount;
}
// Clip and convert to 16 bit
//---GCCFIX: Asm replaced with C function
// The C version was written by Rani Assaf <rani@magic.metawire.com>, I believe
DWORD MPPASMCALL X86_Convert32To16(LPVOID lp16, int *pBuffer, DWORD lSampleCount, LPLONG lpMin, LPLONG lpMax)
{
int vumin = *lpMin, vumax = *lpMax;
signed short *p = (signed short *)lp16;
UINT i;
for (i=0; i<lSampleCount; i++)
{
int n = pBuffer[i];
if (n < MIXING_CLIPMIN)
n = MIXING_CLIPMIN;
else if (n > MIXING_CLIPMAX)
n = MIXING_CLIPMAX;
if (n < vumin)
vumin = n;
else if (n > vumax)
vumax = n;
p[i] = n >> (16-MIXING_ATTENUATION); // 16-bit signed
}
*lpMin = vumin;
*lpMax = vumax;
return lSampleCount * 2;
}
// Clip and convert to 24 bit
//---GCCFIX: Asm replaced with C function
DWORD MPPASMCALL X86_Convert32To24(LPVOID lp16, int *pBuffer, DWORD lSampleCount, LPLONG lpMin, LPLONG lpMax)
{
UINT i ;
int vumin = *lpMin, vumax = *lpMax;
int n,p ;
unsigned char* buf = (unsigned char*)lp16 ;
for ( i=0; i<lSampleCount; i++)
{
n = pBuffer[i];
if (n < MIXING_CLIPMIN)
n = MIXING_CLIPMIN;
else if (n > MIXING_CLIPMAX)
n = MIXING_CLIPMAX;
if (n < vumin)
vumin = n;
else if (n > vumax)
vumax = n;
p = n >> (8-MIXING_ATTENUATION) ; // 24-bit signed
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
buf[i*3+0] = (p >> 16) & 0xFF;
buf[i*3+1] = (p >> 8) & 0xFF;
buf[i*3+2] = (p >> 0) & 0xFF;
#else
buf[i*3+0] = (p >> 0) & 0xFF;
buf[i*3+1] = (p >> 8) & 0xFF;
buf[i*3+2] = (p >> 16) & 0xFF;
#endif
}
*lpMin = vumin;
*lpMax = vumax;
return lSampleCount * 3;
}
// Clip and convert to 32 bit
//---GCCFIX: Asm replaced with C function
DWORD MPPASMCALL X86_Convert32To32(LPVOID lp16, int *pBuffer, DWORD lSampleCount, LPLONG lpMin, LPLONG lpMax)
{
UINT i ;
int vumin = *lpMin, vumax = *lpMax;
int32_t *p = (int32_t *)lp16;
for ( i=0; i<lSampleCount; i++)
{
int n = pBuffer[i];
if (n < MIXING_CLIPMIN)
n = MIXING_CLIPMIN;
else if (n > MIXING_CLIPMAX)
n = MIXING_CLIPMAX;
if (n < vumin)
vumin = n;
else if (n > vumax)
vumax = n;
p[i] = n << MIXING_ATTENUATION; // 32-bit signed
}
*lpMin = vumin;
*lpMax = vumax;
return lSampleCount * 4;
}
//---GCCFIX: Asm replaced with C function
// Will fill in later.
static void MPPASMCALL X86_InitMixBuffer(int *pBuffer, UINT nSamples)
{
SDL_memset(pBuffer, 0, nSamples * sizeof(int));
}
//---GCCFIX: Asm replaced with C function
// Multichannel not supported.
void MPPASMCALL X86_InterleaveFrontRear(int *pFrontBuf, int *pRearBuf, DWORD nSamples)
{
}
//---GCCFIX: Asm replaced with C function
VOID MPPASMCALL X86_MonoFromStereo(int *pMixBuf, UINT nSamples)
{
UINT i, j;
for(i = 0; i < nSamples; i++)
{
j = i << 1;
pMixBuf[i] = (pMixBuf[j] + pMixBuf[j + 1]) >> 1;
}
}
//---GCCFIX: Asm replaced with C function
#define OFSDECAYSHIFT 8
#define OFSDECAYMASK 0xFF
void MPPASMCALL X86_StereoFill(int *pBuffer, UINT nSamples, LPLONG lpROfs, LPLONG lpLOfs)
//----------------------------------------------------------------------------
{
int rofs = *lpROfs;
int lofs = *lpLOfs;
UINT i;
if ((!rofs) && (!lofs))
{
X86_InitMixBuffer(pBuffer, nSamples*2);
return;
}
for (i=0; i<nSamples; i++)
{
int x_r = (rofs + (((-rofs)>>31) & OFSDECAYMASK)) >> OFSDECAYSHIFT;
int x_l = (lofs + (((-lofs)>>31) & OFSDECAYMASK)) >> OFSDECAYSHIFT;
rofs -= x_r;
lofs -= x_l;
pBuffer[i*2] = x_r;
pBuffer[i*2+1] = x_l;
}
*lpROfs = rofs;
*lpLOfs = lofs;
}
//---GCCFIX: Asm replaced with C function
// Will fill in later.
static void MPPASMCALL X86_EndChannelOfs(MODCHANNEL *pChannel, int *pBuffer, UINT nSamples)
{
int rofs = pChannel->nROfs;
int lofs = pChannel->nLOfs;
UINT i;
if ((!rofs) && (!lofs)) return;
for (i=0; i<nSamples; i++)
{
int x_r = (rofs + (((-rofs)>>31) & OFSDECAYMASK)) >> OFSDECAYSHIFT;
int x_l = (lofs + (((-lofs)>>31) & OFSDECAYMASK)) >> OFSDECAYSHIFT;
rofs -= x_r;
lofs -= x_l;
pBuffer[i*2] += x_r;
pBuffer[i*2+1] += x_l;
}
pChannel->nROfs = rofs;
pChannel->nLOfs = lofs;
}
|
b286766c4cf8110ce7326b62e1db31fb5db7806b
|
8a51a96f61699f0318315ccc89cef39f6866f2b5
|
/src/include/catalog/binary_upgrade.h
|
82a9125ba9c3eda3733094bcb45e6374cd79191f
|
[
"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
| 1,453
|
h
|
binary_upgrade.h
|
/*-------------------------------------------------------------------------
*
* binary_upgrade.h
* variables used for binary upgrades
*
*
* Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* src/include/catalog/binary_upgrade.h
*
*-------------------------------------------------------------------------
*/
#ifndef BINARY_UPGRADE_H
#define BINARY_UPGRADE_H
#include "common/relpath.h"
extern PGDLLIMPORT Oid binary_upgrade_next_pg_tablespace_oid;
extern PGDLLIMPORT Oid binary_upgrade_next_pg_type_oid;
extern PGDLLIMPORT Oid binary_upgrade_next_array_pg_type_oid;
extern PGDLLIMPORT Oid binary_upgrade_next_mrng_pg_type_oid;
extern PGDLLIMPORT Oid binary_upgrade_next_mrng_array_pg_type_oid;
extern PGDLLIMPORT Oid binary_upgrade_next_heap_pg_class_oid;
extern PGDLLIMPORT RelFileNumber binary_upgrade_next_heap_pg_class_relfilenumber;
extern PGDLLIMPORT Oid binary_upgrade_next_index_pg_class_oid;
extern PGDLLIMPORT RelFileNumber binary_upgrade_next_index_pg_class_relfilenumber;
extern PGDLLIMPORT Oid binary_upgrade_next_toast_pg_class_oid;
extern PGDLLIMPORT RelFileNumber binary_upgrade_next_toast_pg_class_relfilenumber;
extern PGDLLIMPORT Oid binary_upgrade_next_pg_enum_oid;
extern PGDLLIMPORT Oid binary_upgrade_next_pg_authid_oid;
extern PGDLLIMPORT bool binary_upgrade_record_init_privs;
#endif /* BINARY_UPGRADE_H */
|
8f6f953322ee3d777eb28a83f0dcf43d3cc64bf1
|
19a9f2c19bcb81c4a14ba17831d3098de7731fb5
|
/ni/src/lib/hlu/ViewI.h
|
27dcec70dd02c23b3538a6d9e96d7c142c8a53cc
|
[
"Apache-2.0"
] |
permissive
|
NCAR/ncl
|
243c30eaefce642d53373aa583b73df72eb59f22
|
8a96101fe14d0cf0f5ed66a5e6b1733084bc69df
|
refs/heads/develop
| 2023-03-17T07:53:18.883458
| 2022-05-11T16:01:03
| 2022-05-11T16:01:03
| 67,087,395
| 254
| 68
|
NOASSERTION
| 2022-10-08T07:20:06
| 2016-09-01T01:34:28
|
C
|
UTF-8
|
C
| false
| false
| 2,641
|
h
|
ViewI.h
|
/*
* $Id: ViewI.h,v 1.8 2003-04-04 18:34:08 dbrown Exp $
*/
/************************************************************************
* *
* Copyright (C) 1994 *
* University Corporation for Atmospheric Research *
* All Rights Reserved *
* *
************************************************************************/
/*
* File: ViewI.h
*
* Author: Jeff W. Boote
* National Center for Atmospheric Research
* PO 3000, Boulder, Colorado
*
* Date: Wed Jan 26 17:52:02 MST 1994
*
* Description: Private global function declarations for View.
*/
#ifndef _NVIEWI_H
#define _NVIEWI_H
#include <ncarg/hlu/hluP.h>
#include <ncarg/hlu/Segments.h>
#include <ncarg/hlu/View.h>
/*
* Globally callable functions from Segments.c
*/
extern void _NhlDestroySegTransDat(
#if NhlNeedProto
NhlTransDat* /* transdat */
#endif
);
extern NhlTransDat *_NhlInitSegTransDat(
#if NhlNeedProto
float*, /* x */
float* /* y */
#endif
);
extern void _NhlResetSegTransDat(
#if NhlNeedProto
NhlTransDat*, /* transdat */
float*, /* x */
float* /* y */
#endif
);
extern void _NhlComputeSegTrans(
#if NhlNeedProto
NhlTransDat*, /* transdat */
float *, /* transform */
float *, /* xprime */
float * /* yprime */
#endif
);
extern NhlBoolean _NhlSegmentSpansArea(
#if NhlNeedProto
NhlTransDat* transdat,
float xmin,
float xmax,
float ymin,
float ymax
#endif
);
extern NhlErrorTypes _NhlDrawSegment(
#if NhlNeedProto
NhlTransDat*, /* transdat */
int /* wksid */
#endif
);
extern void _NhlEvalTrans(
#if NhlNeedProto
float *, /*transform */
float, /* x */
float, /* y */
float *, /* xprime */
float * /* yprime */
#endif
);
extern NhlErrorTypes _NhlStartSegment(
#if NhlNeedProto
NhlTransDat* /* transdat */
#endif
);
extern void _NhlSetSegTrans(
#if NhlNeedProto
NhlTransDat*, /* transdat */
float* /* transform */
#endif
);
extern void _NhlEndSegment(
#if NhlNeedProto
NhlTransDat* /* transdat */
#endif
);
typedef struct _NhlViewClassRec *NhlViewClass;
typedef struct _NhlViewLayerRec *NhlViewLayer;
typedef struct _NhlAnnoStatusCBDataRec
_NhlAnnoStatusCBDataRec, *_NhlAnnoStatusCBData;
struct _NhlAnnoStatusCBDataRec {
int id; /* layer id */
int base_id; /* id of base plot */
int anno_manager_id; /* NhlNULLOBJID on remove */
NhlBoolean isanno; /* True on add; False on remove */
};
#define _NhlCBvpAnnoStatus "CBvpAnnoStatus" /* cbdata.ptrval is
_NhlAnnoStatusCBData */
#endif /* _NVIEWI_H */
|
7967e7bbd216c89a7df4496edddf9b7200de95b1
|
4d28185e7a78a569f9a449f39f183cac3024f711
|
/packages/Python/lldbsuite/test/python_api/symbol-context/two-files/decls.h
|
7c80458420629092d6ed94220288b229fc716284
|
[
"NCSA",
"Apache-2.0",
"LLVM-exception"
] |
permissive
|
apple/swift-lldb
|
2789bf44f648609a1674ee520ac20b64c95de072
|
d74be846ef3e62de946df343e8c234bde93a8912
|
refs/heads/stable
| 2023-04-06T00:28:15.882479
| 2019-10-25T22:46:59
| 2019-10-25T22:46:59
| 44,838,862
| 780
| 291
|
Apache-2.0
| 2020-01-10T19:28:43
| 2015-10-23T21:13:18
|
C++
|
UTF-8
|
C
| false
| false
| 117
|
h
|
decls.h
|
struct struct1 {
~struct1();
static void f();
};
struct struct2 {
~struct2();
static void f();
};
int g();
|
fba1733bcca4f956c0236d05eee4dbce2105c2be
|
b36f34b6a24d019d624d1cc74f5b29062eef2ba4
|
/frameworks/cocos2d-x/cocos/base/ccCArray.h
|
8a41dad9f06593bbc557f4c95782e48c222e57ff
|
[
"MIT"
] |
permissive
|
zhongfq/cocos-lua
|
f49c1639f2c9a2a7678f9ed67e58114986ac882f
|
c2cf0f36ac0f0c91fb3456b555cacd8e8587be46
|
refs/heads/main
| 2023-08-17T17:13:05.705639
| 2023-08-17T06:06:36
| 2023-08-17T06:06:36
| 192,316,318
| 165
| 63
|
MIT
| 2023-08-14T23:59:30
| 2019-06-17T09:27:37
|
C
|
UTF-8
|
C
| false
| false
| 8,216
|
h
|
ccCArray.h
|
/****************************************************************************
Copyright (c) 2007 Scott Lembcke
Copyright (c) 2010-2012 cocos2d-x.org
Copyright (c) 2013-2016 Chukong Technologies Inc.
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
http://www.cocos2d-x.org
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.
****************************************************************************/
/**
@file
based on Chipmunk cpArray.
ccArray is a faster alternative to NSMutableArray, it does pretty much the
same thing (stores NSObjects and retains/releases them appropriately). It's
faster because:
- it uses a plain C interface so it doesn't incur Objective-c messaging overhead
- it assumes you know what you're doing, so it doesn't spend time on safety checks
(index out of bounds, required capacity etc.)
- comparisons are done using pointer equality instead of isEqual
There are 2 kind of functions:
- ccArray functions that manipulates objective-c objects (retain and release are performed)
- ccCArray functions that manipulates values like if they were standard C structures (no retain/release is performed)
*/
#ifndef CC_ARRAY_H
#define CC_ARRAY_H
/// @cond DO_NOT_SHOW
#include "base/ccMacros.h"
#include "base/CCRef.h"
#include <stdlib.h>
#include <string.h>
#include <limits.h>
NS_CC_BEGIN
// Easy integration
#define CCARRAYDATA_FOREACH(__array__, __object__) \
__object__=__array__->arr[0]; for(ssize_t i=0, num=__array__->num; i<num; i++, __object__=__array__->arr[i]) \
typedef struct _ccArray {
ssize_t num, max;
Ref** arr;
} ccArray;
/** Allocates and initializes a new array with specified capacity */
ccArray* ccArrayNew(ssize_t capacity);
/** Frees array after removing all remaining objects. Silently ignores nil arr. */
void ccArrayFree(ccArray*& arr);
/** Doubles array capacity */
void ccArrayDoubleCapacity(ccArray *arr);
/** Increases array capacity such that max >= num + extra. */
void ccArrayEnsureExtraCapacity(ccArray *arr, ssize_t extra);
/** shrinks the array so the memory footprint corresponds with the number of items */
void ccArrayShrink(ccArray *arr);
/** Returns index of first occurrence of object, NSNotFound if object not found. */
ssize_t ccArrayGetIndexOfObject(ccArray *arr, Ref* object);
/** Returns a Boolean value that indicates whether object is present in array. */
bool ccArrayContainsObject(ccArray *arr, Ref* object);
/** Appends an object. Behavior undefined if array doesn't have enough capacity. */
void ccArrayAppendObject(ccArray *arr, Ref* object);
/** Appends an object. Capacity of arr is increased if needed. */
void ccArrayAppendObjectWithResize(ccArray *arr, Ref* object);
/** Appends objects from plusArr to arr.
Behavior undefined if arr doesn't have enough capacity. */
void ccArrayAppendArray(ccArray *arr, ccArray *plusArr);
/** Appends objects from plusArr to arr. Capacity of arr is increased if needed. */
void ccArrayAppendArrayWithResize(ccArray *arr, ccArray *plusArr);
/** Inserts an object at index */
void ccArrayInsertObjectAtIndex(ccArray *arr, Ref* object, ssize_t index);
/** Swaps two objects */
void ccArraySwapObjectsAtIndexes(ccArray *arr, ssize_t index1, ssize_t index2);
/** Removes all objects from arr */
void ccArrayRemoveAllObjects(ccArray *arr);
/** Removes object at specified index and pushes back all subsequent objects.
Behavior undefined if index outside [0, num-1]. */
void ccArrayRemoveObjectAtIndex(ccArray *arr, ssize_t index, bool releaseObj = true);
/** Removes object at specified index and fills the gap with the last object,
thereby avoiding the need to push back subsequent objects.
Behavior undefined if index outside [0, num-1]. */
void ccArrayFastRemoveObjectAtIndex(ccArray *arr, ssize_t index);
void ccArrayFastRemoveObject(ccArray *arr, Ref* object);
/** Searches for the first occurrence of object and removes it. If object is not
found the function has no effect. */
void ccArrayRemoveObject(ccArray *arr, Ref* object, bool releaseObj = true);
/** Removes from arr all objects in minusArr. For each object in minusArr, the
first matching instance in arr will be removed. */
void ccArrayRemoveArray(ccArray *arr, ccArray *minusArr);
/** Removes from arr all objects in minusArr. For each object in minusArr, all
matching instances in arr will be removed. */
void ccArrayFullRemoveArray(ccArray *arr, ccArray *minusArr);
//
// // ccCArray for Values (c structures)
typedef struct _ccCArray {
ssize_t num, max;
void** arr;
} ccCArray;
/** Allocates and initializes a new C array with specified capacity */
ccCArray* ccCArrayNew(ssize_t capacity);
/** Frees C array after removing all remaining values. Silently ignores nil arr. */
void ccCArrayFree(ccCArray *arr);
/** Doubles C array capacity */
void ccCArrayDoubleCapacity(ccCArray *arr);
/** Increases array capacity such that max >= num + extra. */
void ccCArrayEnsureExtraCapacity(ccCArray *arr, ssize_t extra);
/** Returns index of first occurrence of value, NSNotFound if value not found. */
ssize_t ccCArrayGetIndexOfValue(ccCArray *arr, void* value);
/** Returns a Boolean value that indicates whether value is present in the C array. */
bool ccCArrayContainsValue(ccCArray *arr, void* value);
/** Inserts a value at a certain position. Behavior undefined if array doesn't have enough capacity */
void ccCArrayInsertValueAtIndex( ccCArray *arr, void* value, ssize_t index);
/** Appends an value. Behavior undefined if array doesn't have enough capacity. */
void ccCArrayAppendValue(ccCArray *arr, void* value);
/** Appends an value. Capacity of arr is increased if needed. */
void ccCArrayAppendValueWithResize(ccCArray *arr, void* value);
/** Appends values from plusArr to arr. Behavior undefined if arr doesn't have
enough capacity. */
void ccCArrayAppendArray(ccCArray *arr, ccCArray *plusArr);
/** Appends values from plusArr to arr. Capacity of arr is increased if needed. */
void ccCArrayAppendArrayWithResize(ccCArray *arr, ccCArray *plusArr);
/** Removes all values from arr */
void ccCArrayRemoveAllValues(ccCArray *arr);
/** Removes value at specified index and pushes back all subsequent values.
Behavior undefined if index outside [0, num-1].
@since v0.99.4
*/
void ccCArrayRemoveValueAtIndex(ccCArray *arr, ssize_t index);
/** Removes value at specified index and fills the gap with the last value,
thereby avoiding the need to push back subsequent values.
Behavior undefined if index outside [0, num-1].
@since v0.99.4
*/
void ccCArrayFastRemoveValueAtIndex(ccCArray *arr, ssize_t index);
/** Searches for the first occurrence of value and removes it. If value is not found the function has no effect.
@since v0.99.4
*/
void ccCArrayRemoveValue(ccCArray *arr, void* value);
/** Removes from arr all values in minusArr. For each Value in minusArr, the first matching instance in arr will be removed.
@since v0.99.4
*/
void ccCArrayRemoveArray(ccCArray *arr, ccCArray *minusArr);
/** Removes from arr all values in minusArr. For each value in minusArr, all matching instances in arr will be removed.
@since v0.99.4
*/
void ccCArrayFullRemoveArray(ccCArray *arr, ccCArray *minusArr);
NS_CC_END
/// @endcond
#endif // CC_ARRAY_H
|
e9330a762cbce05d3302a4ca4115c6ef0f5c6012
|
b6acd6eed2b8946c1c1e19fa30081cbab0a2954f
|
/starry_fmu/Framework/include/butter.h
|
d21771034ffdea46cd166de1c160c7e42dc23284
|
[
"BSD-3-Clause"
] |
permissive
|
JcZou/StarryPilot
|
7ce1ed454f133ccd30d71916811e2bf23196d2eb
|
97af0338a54e1eeece877c72222aeaf4b7e80ad7
|
refs/heads/master
| 2023-03-12T19:10:17.225314
| 2021-11-27T19:44:26
| 2021-11-27T19:44:26
| 137,048,745
| 304
| 172
|
BSD-3-Clause
| 2020-08-26T07:34:49
| 2018-06-12T09:27:59
|
C
|
UTF-8
|
C
| false
| false
| 842
|
h
|
butter.h
|
/*
* File : butter.h
*
* Change Logs:
* Date Author Notes
* 2018-03-30 zoujiachi first version.
*/
#ifndef __BUTTER_H__
#define __BUTTER_H__
typedef struct{
float _cutoff_freq;
float _a1;
float _a2;
float _b0;
float _b1;
float _b2;
float _delay_element_1; // buffered sample -1
float _delay_element_2; // buffered sample -2
}Butter2;
typedef struct
{
float A[4];
float B[4];
float X[4];
float Y[4];
}Butter3;
/* butter filter */
void butter2_set_cutoff_frequency(Butter2 *butter, float sample_freq, float cutoff_freq);
float butter2_reset(Butter2 *butter, float sample);
float butter2_filter_process(Butter2 *butter, float sample);
Butter3* butter3_filter_create(float b[4], float a[4]);
float butter3_filter_process(float in, Butter3* butter);
#endif
|
0078fc272cb3859c3ce0eac8374024a4f37b537b
|
e22fd36933c9114a9df1694e7a6274bf059de2a6
|
/third_party/linux/include/media/cam_icp.h
|
680d05b630a67e3d1e2cdee3860f55a074a6dae4
|
[
"LicenseRef-scancode-warranty-disclaimer",
"MIT"
] |
permissive
|
commaai/openpilot
|
66dfb7f31290bc8f58c9ead95d56697a52b45afb
|
a0b49d54222c52ff0112c402bc0e0d9262e77a66
|
refs/heads/master
| 2023-09-05T21:34:14.076796
| 2023-09-05T21:15:18
| 2023-09-05T21:15:18
| 74,627,617
| 46,071
| 9,878
|
MIT
| 2023-09-14T21:51:23
| 2016-11-24T01:33:30
|
Python
|
UTF-8
|
C
| false
| false
| 5,472
|
h
|
cam_icp.h
|
#ifndef __UAPI_CAM_ICP_H__
#define __UAPI_CAM_ICP_H__
#include "cam_defs.h"
/* icp, ipe, bps, cdm(ipe/bps) are used in querycap */
#define CAM_ICP_DEV_TYPE_A5 1
#define CAM_ICP_DEV_TYPE_IPE 2
#define CAM_ICP_DEV_TYPE_BPS 3
#define CAM_ICP_DEV_TYPE_IPE_CDM 4
#define CAM_ICP_DEV_TYPE_BPS_CDM 5
#define CAM_ICP_DEV_TYPE_MAX 5
/* definitions needed for icp aquire device */
#define CAM_ICP_RES_TYPE_BPS 1
#define CAM_ICP_RES_TYPE_IPE_RT 2
#define CAM_ICP_RES_TYPE_IPE 3
#define CAM_ICP_RES_TYPE_MAX 4
/* packet opcode types */
#define CAM_ICP_OPCODE_IPE_UPDATE 0
#define CAM_ICP_OPCODE_BPS_UPDATE 1
/* IPE input port resource type */
#define CAM_ICP_IPE_INPUT_IMAGE_FULL 0x0
#define CAM_ICP_IPE_INPUT_IMAGE_DS4 0x1
#define CAM_ICP_IPE_INPUT_IMAGE_DS16 0x2
#define CAM_ICP_IPE_INPUT_IMAGE_DS64 0x3
#define CAM_ICP_IPE_INPUT_IMAGE_FULL_REF 0x4
#define CAM_ICP_IPE_INPUT_IMAGE_DS4_REF 0x5
#define CAM_ICP_IPE_INPUT_IMAGE_DS16_REF 0x6
#define CAM_ICP_IPE_INPUT_IMAGE_DS64_REF 0x7
/* IPE output port resource type */
#define CAM_ICP_IPE_OUTPUT_IMAGE_DISPLAY 0x8
#define CAM_ICP_IPE_OUTPUT_IMAGE_VIDEO 0x9
#define CAM_ICP_IPE_OUTPUT_IMAGE_FULL_REF 0xA
#define CAM_ICP_IPE_OUTPUT_IMAGE_DS4_REF 0xB
#define CAM_ICP_IPE_OUTPUT_IMAGE_DS16_REF 0xC
#define CAM_ICP_IPE_OUTPUT_IMAGE_DS64_REF 0xD
#define CAM_ICP_IPE_IMAGE_MAX 0xE
/* BPS input port resource type */
#define CAM_ICP_BPS_INPUT_IMAGE 0x0
/* BPS output port resource type */
#define CAM_ICP_BPS_OUTPUT_IMAGE_FULL 0x1
#define CAM_ICP_BPS_OUTPUT_IMAGE_DS4 0x2
#define CAM_ICP_BPS_OUTPUT_IMAGE_DS16 0x3
#define CAM_ICP_BPS_OUTPUT_IMAGE_DS64 0x4
#define CAM_ICP_BPS_OUTPUT_IMAGE_STATS_BG 0x5
#define CAM_ICP_BPS_OUTPUT_IMAGE_STATS_BHIST 0x6
#define CAM_ICP_BPS_OUTPUT_IMAGE_REG1 0x7
#define CAM_ICP_BPS_OUTPUT_IMAGE_REG2 0x8
#define CAM_ICP_BPS_IO_IMAGES_MAX 0x9
/* Command meta types */
#define CAM_ICP_CMD_META_GENERIC_BLOB 0x1
/* Generic blob types */
#define CAM_ICP_CMD_GENERIC_BLOB_CLK 0x1
#define CAM_ICP_CMD_GENERIC_BLOB_CFG_IO 0x2
/**
* struct cam_icp_clk_bw_request
*
* @budget_ns: Time required to process frame
* @frame_cycles: Frame cycles needed to process the frame
* @rt_flag: Flag to indicate real time stream
* @uncompressed_bw: Bandwidth required to process frame
* @compressed_bw: Compressed bandwidth to process frame
*/
struct cam_icp_clk_bw_request {
uint64_t budget_ns;
uint32_t frame_cycles;
uint32_t rt_flag;
uint64_t uncompressed_bw;
uint64_t compressed_bw;
};
/**
* struct cam_icp_dev_ver - Device information for particular hw type
*
* This is used to get device version info of
* ICP, IPE, BPS and CDM related IPE and BPS from firmware
* and use this info in CAM_QUERY_CAP IOCTL
*
* @dev_type: hardware type for the cap info(icp, ipe, bps, cdm(ipe/bps))
* @reserved: reserved field
* @hw_ver: major, minor and incr values of a device version
*/
struct cam_icp_dev_ver {
uint32_t dev_type;
uint32_t reserved;
struct cam_hw_version hw_ver;
};
/**
* struct cam_icp_ver - ICP version info
*
* This strcuture is used for fw and api version
* this is used to get firmware version and api version from firmware
* and use this info in CAM_QUERY_CAP IOCTL
*
* @major: FW version major
* @minor: FW version minor
* @revision: FW version increment
*/
struct cam_icp_ver {
uint32_t major;
uint32_t minor;
uint32_t revision;
uint32_t reserved;
};
/**
* struct cam_icp_query_cap_cmd - ICP query device capability payload
*
* @dev_iommu_handle: icp iommu handles for secure/non secure modes
* @cdm_iommu_handle: iommu handles for secure/non secure modes
* @fw_version: firmware version info
* @api_version: api version info
* @num_ipe: number of ipes
* @num_bps: number of bps
* @dev_ver: returned device capability array
*/
struct cam_icp_query_cap_cmd {
struct cam_iommu_handle dev_iommu_handle;
struct cam_iommu_handle cdm_iommu_handle;
struct cam_icp_ver fw_version;
struct cam_icp_ver api_version;
uint32_t num_ipe;
uint32_t num_bps;
struct cam_icp_dev_ver dev_ver[CAM_ICP_DEV_TYPE_MAX];
};
/**
* struct cam_icp_res_info - ICP output resource info
*
* @format: format of the resource
* @width: width in pixels
* @height: height in lines
* @fps: fps
*/
struct cam_icp_res_info {
uint32_t format;
uint32_t width;
uint32_t height;
uint32_t fps;
};
/**
* struct cam_icp_acquire_dev_info - An ICP device info
*
* @scratch_mem_size: Output param - size of scratch memory
* @dev_type: device type (IPE_RT/IPE_NON_RT/BPS)
* @io_config_cmd_size: size of IO config command
* @io_config_cmd_handle: IO config command for each acquire
* @secure_mode: camera mode (secure/non secure)
* @chain_info: chaining info of FW device handles
* @in_res: resource info used for clock and bandwidth calculation
* @num_out_res: number of output resources
* @out_res: output resource
*/
struct cam_icp_acquire_dev_info {
uint32_t scratch_mem_size;
uint32_t dev_type;
uint32_t io_config_cmd_size;
int32_t io_config_cmd_handle;
uint32_t secure_mode;
int32_t chain_info;
struct cam_icp_res_info in_res;
uint32_t num_out_res;
struct cam_icp_res_info out_res[1];
} __attribute__((__packed__));
#endif /* __UAPI_CAM_ICP_H__ */
|
304a62f095372661ab50f02582157eaba3b7bc41
|
f3eed0234b4d0ad2bbb2abd700cf1e2c7a0e8a1d
|
/AKWF-c/AKWF_0004/AKWF_0391.h
|
12335a1a761410a73743aec4052e0778de42671e
|
[
"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_0391.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_0391 256 samples
+-----------------------------------------------------------------------------------------------------------------+
| ********** * |
| **** ********************** |
| *** *** |
| ** ** |
| ** ** |
|** ** |
|* * |
| * |
| * *|
| ** **|
| *** ** |
| ** *** |
| **** *** |
| ********************** ***** |
| * ********** |
+-----------------------------------------------------------------------------------------------------------------+
*/
const uint16_t AKWF_0391 [] = {
32953, 34715, 36535, 38099, 39644, 41034, 42391, 43606, 44781, 45829, 46836, 47730, 48579, 49335, 50048, 50688,
51285, 51829, 52331, 52796, 53215, 53618, 53971, 54324, 54623, 54933, 55191, 55466, 55691, 55935, 56135, 56353,
56535, 56726, 56898, 57066, 57230, 57376, 57538, 57659, 57825, 57924, 58095, 58171, 58349, 58404, 58588, 58625,
58814, 58839, 59028, 59044, 59230, 59248, 59419, 59451, 59590, 59656, 59746, 59874, 59867, 60130, 59890, 60632,
55311, 52732, 53734, 53235, 53741, 53480, 53830, 53680, 53939, 53859, 54050, 54022, 54161, 54174, 54267, 54311,
54370, 54437, 54466, 54548, 54554, 54644, 54632, 54722, 54697, 54782, 54746, 54819, 54775, 54828, 54781, 54811,
54756, 54755, 54698, 54659, 54593, 54510, 54434, 54296, 54210, 54010, 53900, 53631, 53486, 53137, 52944, 52505,
52245, 51705, 51353, 50704, 50232, 49466, 48841, 47958, 47147, 46156, 45123, 44064, 42753, 41735, 39982, 39484,
30855, 25879, 25726, 23634, 22946, 21313, 20565, 19236, 18526, 17451, 16814, 15962, 15402, 14743, 14260, 13764,
13349, 12984, 12628, 12372, 12069, 11895, 11638, 11531, 11316, 11256, 11081, 11052, 10916, 10908, 10806, 10814,
10746, 10758, 10723, 10737, 10735, 10742, 10770, 10771, 10828, 10820, 10904, 10887, 10994, 10969, 11096, 11066,
11208, 11174, 11327, 11296, 11451, 11431, 11577, 11581, 11702, 11746, 11821, 11935, 11918, 12175, 11931, 12675,
7353, 4774, 5773, 5279, 5791, 5545, 5903, 5773, 6047, 5990, 6205, 6209, 6378, 6428, 6565, 6648,
6764, 6876, 6975, 7111, 7202, 7355, 7446, 7611, 7708, 7883, 7989, 8172, 8293, 8484, 8623, 8825,
8985, 9197, 9388, 9613, 9834, 10080, 10336, 10610, 10906, 11218, 11560, 11921, 12318, 12741, 13206, 13706,
14252, 14846, 15491, 16200, 16959, 17804, 18702, 19705, 20757, 21929, 23147, 24500, 25894, 27435, 29002, 30820,
};
|
72f40619e7d424bfecdf81bde15196675ec9124c
|
45cdca1150701f88c488a0b4ab897169f433e2e3
|
/quicklz/quicklz.h
|
29f0ce36e82d04b5f896f662712aacb80be562a0
|
[] |
no_license
|
inikep/lzbench
|
47886cdaafe0e5c0d11447e742aff3bd459c42b9
|
d138844ea56b36ff1c1c43b259c866069deb64ad
|
refs/heads/master
| 2023-09-05T11:39:15.985186
| 2023-08-27T16:18:11
| 2023-08-27T16:18:11
| 45,305,126
| 806
| 185
| null | 2023-08-27T16:18:12
| 2015-10-31T14:41:09
|
C
|
UTF-8
|
C
| false
| false
| 7,047
|
h
|
quicklz.h
|
#ifndef QLZ_HEADER
#define QLZ_HEADER
// Fast data compression library
// Copyright (C) 2006-2011 Lasse Mikkel Reinhold
// lar@quicklz.com
//
// QuickLZ can be used for free under the GPL 1, 2 or 3 license (where anything
// released into public must be open source) or under a commercial license if such
// has been acquired (see http://www.quicklz.com/order.html). The commercial license
// does not cover derived or ported versions created by third parties under GPL.
// You can edit following user settings. Data must be decompressed with the same
// setting of QLZ_COMPRESSION_LEVEL and QLZ_STREAMING_BUFFER as it was compressed
// (see manual). If QLZ_STREAMING_BUFFER > 0, scratch buffers must be initially
// zeroed out (see manual). First #ifndef makes it possible to define settings from
// the outside like the compiler command line.
// 1.5.0 final
#ifndef QLZ_COMPRESSION_LEVEL
#define QLZ_COMPRESSION_LEVEL 2
//#define QLZ_COMPRESSION_LEVEL 2
//#define QLZ_COMPRESSION_LEVEL 3
#define QLZ_STREAMING_BUFFER 0
//#define QLZ_STREAMING_BUFFER 100000
//#define QLZ_STREAMING_BUFFER 1000000
//#define QLZ_MEMORY_SAFE
#endif
#if QLZ_COMPRESSION_LEVEL == 1
#define RESET_TABLE_COMPRESS reset_table_compress_1
#define RESET_TABLE_DECOMPRESS reset_table_decompress_1
#define HASH_FUNC hash_func_1
#define UPDATE_HASH update_hash_1
#define UPDATE_HASH_UPTO update_hash_upto_1
#define QLZ_COMPRESS_CORE qlz_compress_core_1
#define QLZ_DECOMPRESS_CORE qlz_decompress_core_1
#define QLZ_DECOMPRESS qlz_decompress_1
#define QLZ_COMPRESS qlz_compress_1
#define QLZ_GET_SETTING qlz_get_setting_1
#define FAST_READ fast_read_1
#define HASHAT hashat_1
#define FAST_WRITE fast_write_1
#define QLZ_SIZE_DECOMPRESSED qlz_size_decompressed_1
#define QLZ_SIZE_COMPRESSED qlz_size_compressed_1
#define QLZ_SIZE_HEADER qlz_size_header_1
#define MEMCPY_UP memcpy_up_1
#elif QLZ_COMPRESSION_LEVEL == 2
#define RESET_TABLE_COMPRESS reset_table_compress_2
#define RESET_TABLE_DECOMPRESS reset_table_decompress_2
#define HASH_FUNC hash_func_2
#define UPDATE_HASH update_hash_2
#define UPDATE_HASH_UPTO update_hash_upto_2
#define QLZ_COMPRESS_CORE qlz_compress_core_2
#define QLZ_DECOMPRESS_CORE qlz_decompress_core_2
#define QLZ_DECOMPRESS qlz_decompress_2
#define QLZ_COMPRESS qlz_compress_2
#define QLZ_GET_SETTING qlz_get_setting_2
#define FAST_READ fast_read_2
#define HASHAT hashat_2
#define FAST_WRITE fast_write_2
#define QLZ_SIZE_DECOMPRESSED qlz_size_decompressed_2
#define QLZ_SIZE_COMPRESSED qlz_size_compressed_2
#define QLZ_SIZE_HEADER qlz_size_header_2
#define MEMCPY_UP memcpy_up_2
#else
#define RESET_TABLE_COMPRESS reset_table_compress_3
#define RESET_TABLE_DECOMPRESS reset_table_decompress_3
#define HASH_FUNC hash_func_3
#define UPDATE_HASH update_hash_3
#define UPDATE_HASH_UPTO update_hash_upto_3
#define QLZ_COMPRESS_CORE qlz_compress_core_3
#define QLZ_DECOMPRESS_CORE qlz_decompress_core_3
#define QLZ_DECOMPRESS qlz_decompress_3
#define QLZ_COMPRESS qlz_compress_3
#define QLZ_GET_SETTING qlz_get_setting_3
#define FAST_READ fast_read_3
#define HASHAT hashat_3
#define FAST_WRITE fast_write_3
#define QLZ_SIZE_DECOMPRESSED qlz_size_decompressed_3
#define QLZ_SIZE_COMPRESSED qlz_size_compressed_3
#define QLZ_SIZE_HEADER qlz_size_header_3
#define MEMCPY_UP memcpy_up_3
#endif
#define QLZ150_VERSION_MAJOR 1
#define QLZ150_VERSION_MINOR 5
#define QLZ150_VERSION_REVISION 0
// Using size_t, memset() and memcpy()
#include <string.h>
// Verify compression level
#if QLZ_COMPRESSION_LEVEL != 1 && QLZ_COMPRESSION_LEVEL != 2 && QLZ_COMPRESSION_LEVEL != 3
#error QLZ_COMPRESSION_LEVEL must be 1, 2 or 3
#endif
typedef unsigned int ui32;
typedef unsigned short int ui16;
// Decrease QLZ_POINTERS for level 3 to increase compression speed. Do not touch any other values!
#if QLZ_COMPRESSION_LEVEL == 1
#define QLZ_POINTERS 1
#define QLZ_HASH_VALUES 4096
#elif QLZ_COMPRESSION_LEVEL == 2
#define QLZ_POINTERS 4
#define QLZ_HASH_VALUES 2048
#elif QLZ_COMPRESSION_LEVEL == 3
#define QLZ_POINTERS 16
#define QLZ_HASH_VALUES 4096
#endif
// Detect if pointer size is 64-bit. It's not fatal if some 64-bit target is not detected because this is only for adding an optional 64-bit optimization.
#if defined _LP64 || defined __LP64__ || defined __64BIT__ || _ADDR64 || defined _WIN64 || defined __arch64__ || __WORDSIZE == 64 || (defined __sparc && defined __sparcv9) || defined __x86_64 || defined __amd64 || defined __x86_64__ || defined _M_X64 || defined _M_IA64 || defined __ia64 || defined __IA64__
#define QLZ_PTR_64
#endif
// hash entry
typedef struct
{
#if QLZ_COMPRESSION_LEVEL == 1
ui32 cache;
#if defined QLZ_PTR_64 && QLZ_STREAMING_BUFFER == 0
unsigned int offset;
#else
const unsigned char *offset;
#endif
#else
const unsigned char *offset[QLZ_POINTERS];
#endif
} qlz150_hash_compress;
typedef struct
{
#if QLZ_COMPRESSION_LEVEL == 1
const unsigned char *offset;
#else
const unsigned char *offset[QLZ_POINTERS];
#endif
} qlz150_hash_decompress;
// states
typedef struct
{
#if QLZ_STREAMING_BUFFER > 0
unsigned char stream_buffer[QLZ_STREAMING_BUFFER];
#endif
size_t stream_counter;
qlz150_hash_compress hash[QLZ_HASH_VALUES];
unsigned char hash_counter[QLZ_HASH_VALUES];
} qlz150_state_compress;
#if QLZ_COMPRESSION_LEVEL == 1 || QLZ_COMPRESSION_LEVEL == 2
typedef struct
{
#if QLZ_STREAMING_BUFFER > 0
unsigned char stream_buffer[QLZ_STREAMING_BUFFER];
#endif
qlz150_hash_decompress hash[QLZ_HASH_VALUES];
unsigned char hash_counter[QLZ_HASH_VALUES];
size_t stream_counter;
} qlz150_state_decompress;
#elif QLZ_COMPRESSION_LEVEL == 3
typedef struct
{
#if QLZ_STREAMING_BUFFER > 0
unsigned char stream_buffer[QLZ_STREAMING_BUFFER];
#endif
#if QLZ_COMPRESSION_LEVEL <= 2
qlz150_hash_decompress hash[QLZ_HASH_VALUES];
#endif
size_t stream_counter;
} qlz150_state_decompress;
#endif
#if defined (__cplusplus)
extern "C" {
#endif
// Public functions of QuickLZ
size_t qlz_size_decompressed_1(const char *source);
size_t qlz_size_decompressed_2(const char *source);
size_t qlz_size_decompressed_3(const char *source);
size_t qlz_size_compressed_1(const char *source);
size_t qlz_size_compressed_2(const char *source);
size_t qlz_size_compressed_3(const char *source);
size_t qlz_compress_1(const void *source, char *destination, size_t size, qlz150_state_compress *state);
size_t qlz_compress_2(const void *source, char *destination, size_t size, qlz150_state_compress *state);
size_t qlz_compress_3(const void *source, char *destination, size_t size, qlz150_state_compress *state);
size_t qlz_decompress_1(const char *source, void *destination, qlz150_state_decompress *state);
size_t qlz_decompress_2(const char *source, void *destination, qlz150_state_decompress *state);
size_t qlz_decompress_3(const char *source, void *destination, qlz150_state_decompress *state);
int qlz_get_setting_1(int setting);
int qlz_get_setting_2(int setting);
int qlz_get_setting_3(int setting);
#if defined (__cplusplus)
}
#endif
#endif
|
c5be9f51aef743af767ca2f3f057f5432795d006
|
fcc9b5cb92607deaac4b097776ed0490789d8c3e
|
/src/runtime/sunos-os.c
|
83e8590e6e49a6849f131879bff946353121cbd8
|
[
"LicenseRef-scancode-other-permissive",
"LicenseRef-scancode-public-domain",
"BSD-2-Clause",
"LicenseRef-scancode-warranty-disclaimer",
"BSD-3-Clause",
"LicenseRef-scancode-mit-specification-disclaimer",
"MIT",
"LicenseRef-scancode-public-domain-disclaimer",
"UPL-1.0"
] |
permissive
|
sbcl/sbcl
|
ef248b5e8614ba7f0a1132c4f2cfcb000a074400
|
85003adf60ef659082c244972e816ea62240b9cb
|
refs/heads/master
| 2023-09-01T05:14:15.225083
| 2023-08-31T20:09:49
| 2023-08-31T20:09:49
| 1,890,957
| 1,737
| 408
|
NOASSERTION
| 2023-08-28T13:05:04
| 2011-06-13T20:33:25
|
Common Lisp
|
UTF-8
|
C
| false
| false
| 2,452
|
c
|
sunos-os.c
|
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <sys/file.h>
#include <limits.h>
#include <unistd.h>
#include <errno.h>
#include <sys/param.h>
#include "sbcl.h"
#include "os.h"
#include "arch.h"
#include "interr.h"
#include "interrupt.h"
#include "globals.h"
#include "validate.h"
#include "target-arch-os.h"
#ifdef LISP_FEATURE_X86
#include "genesis/static-symbols.h"
#include "genesis/fdefn.h"
#endif
#include "gc.h"
void os_init() {}
os_vm_address_t os_alloc_gc_space(int __attribute__((unused)) space_id,
int attributes, os_vm_address_t addr, os_vm_size_t len)
{
int protection = attributes & IS_GUARD_PAGE ? OS_VM_PROT_NONE : OS_VM_PROT_ALL;
attributes &= ~IS_GUARD_PAGE;
int flags = MAP_PRIVATE | MAP_NORESERVE | MAP_ANON;
if (addr)
flags |= MAP_FIXED;
addr = mmap(addr, len, protection, flags, -1, 0);
if (addr == MAP_FAILED) {
perror("mmap");
/* While it is generally hard to recover from out-of-memory
* situations, we require callers to decide on the right course
* of action here. Consider thread creation: Failure to mmap
* here is common if users have started too many threads, and
* often we can recover from that and treat it as an ordinary
* error. */
return 0;
}
return addr;
}
#if defined LISP_FEATURE_GENERATIONAL
void
sigsegv_handler(int signal, siginfo_t *info, os_context_t *context)
{
void* fault_addr = (void*)info->si_addr;
if (gencgc_handle_wp_violation(context, fault_addr)) return;
if (!handle_guard_page_triggered(context, fault_addr))
lisp_memory_fault_error(context, fault_addr);
}
#else
static void
sigsegv_handler(int signal, siginfo_t *info, os_context_t *context)
{
os_vm_address_t addr = arch_get_bad_addr(signal, info, context);
if (cheneygc_handle_wp_violation(context, addr)) return;
if (!handle_guard_page_triggered(context,addr))
lisp_memory_fault_error(context, addr);
}
#endif
void
os_install_interrupt_handlers()
{
ll_install_handler(SIG_MEMORY_FAULT, sigsegv_handler);
}
char *os_get_runtime_executable_path()
{
char path[PATH_MAX + 1];
int size = readlink("/proc/self/path/a.out", path, sizeof(path) - 1);
if (size < 0)
return NULL;
path[size] = '\0';
if (strcmp(path, "unknown") == 0)
return NULL;
return copied_string(path);
}
|
3cdd66124fe9f9a6970115e1e18dbc148729d510
|
78297bc868d588dd7a16cfea059ef7365ba18622
|
/lib/api/include/irods/unregDataObj.h
|
ecbed4b074ad1d33dc24f0a239a6a9c34b56d6ed
|
[
"BSD-3-Clause"
] |
permissive
|
irods/irods
|
ab72a41fdf05a4a905c3e3a97bb7ba3c2a6ae52d
|
f3ccaa842218e477395ebcf553639134433b63ee
|
refs/heads/main
| 2023-09-01T20:12:33.322002
| 2023-08-23T18:22:59
| 2023-08-31T13:41:31
| 14,724,975
| 381
| 167
|
NOASSERTION
| 2023-09-11T18:18:14
| 2013-11-26T18:10:18
|
C++
|
UTF-8
|
C
| false
| false
| 608
|
h
|
unregDataObj.h
|
#ifndef UNREG_DATA_OBJ_H__
#define UNREG_DATA_OBJ_H__
#include "irods/rcConnect.h"
#include "irods/objInfo.h"
typedef struct {
dataObjInfo_t *dataObjInfo;
keyValPair_t *condInput;
} unregDataObj_t;
#define UnregDataObj_PI "struct *DataObjInfo_PI; struct *KeyValPair_PI;"
/* rcUnregDataObj - Unregister a iRODS dataObject.
* Input -
* rcComm_t *conn - The client connection handle.
* unregDataObj_t *unregDataObjInp - the dataObjInfo to unregister
*
* OutPut -
* int status - status of the operation.
*/
int rcUnregDataObj( rcComm_t *conn, unregDataObj_t *unregDataObjInp );
#endif
|
1584c6c9ab9e8120f6b9cf35a1fa0a3cd6e6f62f
|
7be8e3636bf08ebdc6662879dc5afec548705537
|
/ios/Pods/Headers/Private/Flipper-Folly/folly/detail/Futex-inl.h
|
afc21a520d9f8e360cd186399c782d9311118f85
|
[
"MIT"
] |
permissive
|
rdhox/react-native-smooth-picker
|
3c7384f1fed0e37f076361cce96071d01b70e209
|
ae9316c49512f7ed9824c5a3ad50cdf5e80fffa9
|
refs/heads/master
| 2023-01-08T16:59:40.709147
| 2021-07-03T14:13:21
| 2021-07-03T14:13:21
| 160,224,312
| 230
| 31
|
MIT
| 2023-01-06T01:46:04
| 2018-12-03T16:54:10
|
TypeScript
|
UTF-8
|
C
| false
| false
| 53
|
h
|
Futex-inl.h
|
../../../../../Flipper-Folly/folly/detail/Futex-inl.h
|
ed9c6810a0acfa58c4e7b6c9988a60d8891d7305
|
9de0cec678bc4a3bec2b4adabef9f39ff5b4afac
|
/PWGLF/SPECTRA/IdentifiedHighPt/lib/LinkDef.h
|
fda3e1b99bb1b853e9272f36c75c902e9f38dcc4
|
[] |
permissive
|
alisw/AliPhysics
|
91bf1bd01ab2af656a25ff10b25e618a63667d3e
|
5df28b2b415e78e81273b0d9bf5c1b99feda3348
|
refs/heads/master
| 2023-08-31T20:41:44.927176
| 2023-08-31T14:51:12
| 2023-08-31T14:51:12
| 61,661,378
| 129
| 1,150
|
BSD-3-Clause
| 2023-09-14T18:48:45
| 2016-06-21T19:31:29
|
C++
|
UTF-8
|
C
| false
| false
| 354
|
h
|
LinkDef.h
|
// four use by cint
#ifdef __CINT__
#pragma link off all globals;
#pragma link off all classes;
#pragma link off all functions;
#pragma link C++ class AliHighPtDeDxBase+;
#pragma link C++ class AliHighPtDeDxCalib+;
#pragma link C++ class AliHighPtDeDxData+;
#pragma link C++ class AliHighPtDeDxMc+;
#pragma link C++ class AliHighPtDeDxSpectra+;
#endif
|
6a51484484622d01d72fcb5a710e45d37814d95e
|
dbeb56474c78ef4b198f2e378ef85e915914d7d4
|
/core/external-crypto/modes/ltc/ltc_eax.c
|
9ea5760c4c8f14a717804c96a2623f2080bc1e03
|
[
"Apache-2.0"
] |
permissive
|
square/subzero
|
3b2468d53e609e3acc61ea51656c86e43c3082a6
|
f4f4d86dec3bc5bf27d7b88cefc79537000ce013
|
refs/heads/master
| 2023-09-02T18:52:30.958103
| 2023-08-01T16:22:22
| 2023-08-01T16:22:22
| 144,076,009
| 686
| 102
|
Apache-2.0
| 2023-09-14T17:58:22
| 2018-08-08T22:58:11
|
C
|
UTF-8
|
C
| false
| false
| 5,201
|
c
|
ltc_eax.c
|
/*
This code has been derived from LibTomCrypt, the cryptographic library
authored by Tom St Denis. His contribution is hence acknowledged. This
code has been developed to obtain two independent implementations of the
combined AES encryption/authentication modes (CCM, GCM and EAX) in order
to be able to check test vectors before their publication.
*/
#include <stdlib.h>
#include <string.h>
#include "ltc_eax.h"
int eax_init( const unsigned char key[], unsigned long key_len,
const unsigned char nonce[], unsigned long nonce_len,
const unsigned char hdr[], unsigned long header_len,
eax_state eax[1] )
{
unsigned char *buf;
int err = EXIT_FAILURE;
omac_state *omac;
unsigned long len;
if( header_len > 0 && hdr == NULL )
goto exit3;
if( ( buf = malloc( AES_BLOCK_SIZE ) ) == NULL )
goto exit3;
if( ( omac = malloc( sizeof(*omac) ) ) == NULL )
goto exit2;
memset( buf, 0, AES_BLOCK_SIZE );
if( (err = omac_init(key, key_len, omac)) != EXIT_SUCCESS )
goto exit1;
if( (err = omac_process(buf, AES_BLOCK_SIZE, omac)) != EXIT_SUCCESS )
goto exit1;
if( (err = omac_process(nonce, nonce_len, omac)) != EXIT_SUCCESS )
goto exit1;
len = sizeof( eax->nv );
if( (err = omac_done(eax->nv, &len, omac)) != EXIT_SUCCESS )
goto exit1;
memset( buf, 0, AES_BLOCK_SIZE );
buf[AES_BLOCK_SIZE - 1] = 1;
if( (err = omac_init(key, key_len, eax->hdr_omac)) != EXIT_SUCCESS )
goto exit1;
if( (err = omac_process(buf, AES_BLOCK_SIZE, eax->hdr_omac)) != EXIT_SUCCESS )
goto exit1;
if( header_len != 0 && ( (err = omac_process(hdr, header_len, eax->hdr_omac) ) != EXIT_SUCCESS ) )
goto exit1;
if( (err = ctr_start(eax->nv, key, key_len, 0, CTR_COUNTER_BIG_ENDIAN, eax->ctr) ) != EXIT_SUCCESS )
goto exit1;
if( (err = omac_init(key, key_len, eax->ctx_omac)) != EXIT_SUCCESS )
goto exit1;
memset( buf, 0, AES_BLOCK_SIZE );
buf[AES_BLOCK_SIZE - 1] = 2;
if( (err = omac_process(buf, AES_BLOCK_SIZE, eax->ctx_omac)) != EXIT_SUCCESS )
goto exit1;
err = EXIT_SUCCESS;
exit1:
free( omac );
exit2:
free( buf );
exit3:
return err;
}
int eax_addheader( const unsigned char hdr[], unsigned long length, eax_state eax[1] )
{
return omac_process( hdr, length, eax->hdr_omac );
}
int eax_encryptx( const unsigned char pt[], unsigned char ct[], unsigned long length,
eax_state eax[1] )
{
int err;
if( (err = ctr_encrypt( pt, ct, length, eax->ctr )) != EXIT_SUCCESS )
return err;
return omac_process( ct, length, eax->ctx_omac );
}
int eax_decryptx( const unsigned char ct[], unsigned char pt[], unsigned long length,
eax_state eax[1] )
{
int err;
if( (err = omac_process( ct, length, eax->ctx_omac )) != EXIT_SUCCESS )
return err;
return ctr_decrypt( ct, pt, length, eax->ctr );
}
int eax_done( unsigned char tag[], unsigned long tag_len, eax_state eax[1] )
{
int err = EXIT_FAILURE;
unsigned char *headermac, *ctmac;
unsigned long x, len;
if( ( headermac = malloc( AES_BLOCK_SIZE ) ) == NULL )
goto exit3;
if( ( ctmac = malloc( AES_BLOCK_SIZE ) ) == NULL )
goto exit2;
len = AES_BLOCK_SIZE;
if( (err = omac_done( ctmac, &len, eax->ctx_omac )) != EXIT_SUCCESS )
goto exit1;
if( (err = omac_done( headermac, &len, eax->hdr_omac )) != EXIT_SUCCESS )
goto exit1;
if( (err = ctr_done( eax->ctr )) != 0 )
goto exit1;
for( x = 0; x < len && x < tag_len; x++ )
tag[x] = eax->nv[x] ^ headermac[x] ^ ctmac[x];
err = EXIT_SUCCESS;
exit1:
free( ctmac );
exit2:
free( headermac );
exit3:
return err;
}
int eax_memory( const unsigned char key[], unsigned long key_len,
const unsigned char nonce[], unsigned long nonce_len,
const unsigned char hdr[], unsigned long header_len,
unsigned char pt[], unsigned long pt_len, unsigned char ct[],
unsigned char tag[], unsigned long tag_len,
int dir, int *stat )
{
int err = EXIT_FAILURE;
eax_state *eax;
if( ( eax = malloc( sizeof(eax_state) ) ) == NULL )
goto exit2;
if( dir == EAX_ENCRYPT )
{
if( ( err = eax_init( key, key_len, nonce, nonce_len, hdr, header_len, eax ) ) == EXIT_SUCCESS )
if( ( err = eax_encryptx( pt, ct, pt_len, eax ) ) == EXIT_SUCCESS )
err = eax_done( tag, tag_len, eax );
}
else
{
uint8_t *buf;
*stat = EXIT_FAILURE;
if( ( buf = malloc( tag_len ) ) == NULL )
goto exit1;
if( ( err = eax_init( key, key_len, nonce, nonce_len, hdr, header_len, eax ) ) == EXIT_SUCCESS )
if( ( err = eax_decryptx( ct, pt, pt_len, eax ) ) == EXIT_SUCCESS )
if( ( err = eax_done( buf, tag_len, eax ) ) == EXIT_SUCCESS )
if( memcmp( buf, tag, tag_len ) == 0 )
*stat = EXIT_SUCCESS;
free( buf );
}
exit1:
free( eax );
exit2:
return err;
}
|
24bde3633fed61da1912c439f6b4f391cde7246d
|
7eaf54a78c9e2117247cb2ab6d3a0c20719ba700
|
/SOFTWARE/A64-TERES/u-boot_new/include/configs/km/kmp204x-common.h
|
efd96352eca45f93f3ba951a319b8a6c9e4106b3
|
[
"LicenseRef-scancode-free-unknown",
"Apache-2.0",
"GPL-2.0-or-later"
] |
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
|
UTF-8
|
C
| false
| false
| 15,329
|
h
|
kmp204x-common.h
|
/*
* (C) Copyright 2013 Keymile AG
* Valentin Longchamp <valentin.longchamp@keymile.com>
*
* SPDX-License-Identifier: GPL-2.0+
*/
#ifndef _CONFIG_KMP204X_H
#define _CONFIG_KMP204X_H
#define CONFIG_PHYS_64BIT
#define CONFIG_PPC_P2041
#define CONFIG_SYS_TEXT_BASE 0xfff80000
#define CONFIG_KM_DEF_NETDEV "netdev=eth0\0"
/* an additionnal option is required for UBI as subpage access is
* supported in u-boot */
#define CONFIG_KM_UBI_PART_BOOT_OPTS ",2048"
#define CONFIG_NAND_ECC_BCH
/* common KM defines */
#include "keymile-common.h"
#define CONFIG_SYS_RAMBOOT
#define CONFIG_RAMBOOT_PBL
#define CONFIG_RAMBOOT_TEXT_BASE CONFIG_SYS_TEXT_BASE
#define CONFIG_RESET_VECTOR_ADDRESS 0xfffffffc
#define CONFIG_SYS_FSL_PBL_PBI board/keymile/kmp204x/pbi.cfg
#define CONFIG_SYS_FSL_PBL_RCW board/keymile/kmp204x/rcw_kmp204x.cfg
/* High Level Configuration Options */
#define CONFIG_BOOKE
#define CONFIG_E500 /* BOOKE e500 family */
#define CONFIG_E500MC /* BOOKE e500mc family */
#define CONFIG_SYS_BOOK3E_HV /* Category E.HV supported */
#define CONFIG_FSL_CORENET /* Freescale CoreNet platform */
#define CONFIG_MP /* support multiple processors */
#define CONFIG_SYS_FSL_CPC /* Corenet Platform Cache */
#define CONFIG_SYS_NUM_CPC CONFIG_NUM_DDR_CONTROLLERS
#define CONFIG_FSL_ELBC /* Has Enhanced localbus controller */
#define CONFIG_PCI /* Enable PCI/PCIE */
#define CONFIG_PCIE1 /* PCIE controler 1 */
#define CONFIG_PCIE3 /* PCIE controler 3 */
#define CONFIG_FSL_PCI_INIT /* Use common FSL init code */
#define CONFIG_SYS_PCI_64BIT /* enable 64-bit PCI resources */
#define CONFIG_SYS_DPAA_RMAN /* RMan */
#define CONFIG_FSL_LAW /* Use common FSL init code */
/* Environment in SPI Flash */
#define CONFIG_SYS_EXTRA_ENV_RELOC
#define CONFIG_ENV_IS_IN_SPI_FLASH
#define CONFIG_ENV_SPI_BUS 0
#define CONFIG_ENV_SPI_CS 0
#define CONFIG_ENV_SPI_MAX_HZ 20000000
#define CONFIG_ENV_SPI_MODE 0
#define CONFIG_ENV_OFFSET 0x100000 /* 1MB for u-boot */
#define CONFIG_ENV_SIZE 0x004000 /* 16K env */
#define CONFIG_ENV_SECT_SIZE 0x010000
#define CONFIG_ENV_OFFSET_REDUND 0x110000
#define CONFIG_ENV_TOTAL_SIZE 0x020000
#define CONFIG_SYS_REDUNDAND_ENVIRONMENT
#ifndef __ASSEMBLY__
unsigned long get_board_sys_clk(unsigned long dummy);
#endif
#define CONFIG_SYS_CLK_FREQ get_board_sys_clk(0)
/*
* These can be toggled for performance analysis, otherwise use default.
*/
#define CONFIG_SYS_CACHE_STASHING
#define CONFIG_BACKSIDE_L2_CACHE
#define CONFIG_SYS_INIT_L2CSR0 L2CSR0_L2E
#define CONFIG_BTB /* toggle branch predition */
#define CONFIG_ENABLE_36BIT_PHYS
#define CONFIG_ADDR_MAP
#define CONFIG_SYS_NUM_ADDR_MAP 64 /* number of TLB1 entries */
#define CONFIG_POST CONFIG_SYS_POST_MEM_REGIONS /* POST memory regions test */
/*
* Config the L3 Cache as L3 SRAM
*/
#define CONFIG_SYS_INIT_L3_ADDR CONFIG_RAMBOOT_TEXT_BASE
#define CONFIG_SYS_INIT_L3_ADDR_PHYS (0xf00000000ull | \
CONFIG_RAMBOOT_TEXT_BASE)
#define CONFIG_SYS_L3_SIZE (1024 << 10)
#define CONFIG_SYS_INIT_L3_END (CONFIG_SYS_INIT_L3_ADDR + CONFIG_SYS_L3_SIZE)
#define CONFIG_SYS_DCSRBAR 0xf0000000
#define CONFIG_SYS_DCSRBAR_PHYS 0xf00000000ull
/*
* DDR Setup
*/
#define CONFIG_VERY_BIG_RAM
#define CONFIG_SYS_DDR_SDRAM_BASE 0x00000000
#define CONFIG_SYS_SDRAM_BASE CONFIG_SYS_DDR_SDRAM_BASE
#define CONFIG_DIMM_SLOTS_PER_CTLR 1
#define CONFIG_CHIP_SELECTS_PER_CTRL (4 * CONFIG_DIMM_SLOTS_PER_CTLR)
#define CONFIG_DDR_SPD
#define CONFIG_SYS_FSL_DDR3
#define CONFIG_FSL_DDR_INTERACTIVE
#define CONFIG_SYS_SPD_BUS_NUM 0
#define SPD_EEPROM_ADDRESS 0x54
#define CONFIG_SYS_SDRAM_SIZE 4096 /* for fixed parameter use */
#define CONFIG_SYS_LOAD_ADDR 0x100000 /* default load address */
#define CONFIG_SYS_I2C_EEPROM_ADDR_LEN 2
/******************************************************************************
* (PRAM usage)
* ... -------------------------------------------------------
* ... |ROOTFSSIZE | PNVRAM |PHRAM |RESERVED_PRAM | END_OF_RAM
* ... |<------------------- pram -------------------------->|
* ... -------------------------------------------------------
* @END_OF_RAM:
* @CONFIG_KM_RESERVED_PRAM: reserved pram for special purpose
* @CONFIG_KM_PHRAM: address for /var
* @CONFIG_KM_PNVRAM: address for PNVRAM (for the application)
* @CONFIG_KM_ROOTFSSIZE: address for rootfilesystem in RAM
*/
/* size of rootfs in RAM */
#define CONFIG_KM_ROOTFSSIZE 0x0
/* pseudo-non volatile RAM [hex] */
#define CONFIG_KM_PNVRAM 0x80000
/* physical RAM MTD size [hex] */
#define CONFIG_KM_PHRAM 0x100000
/* reserved pram area at the end of memory [hex]
* u-boot reserves some memory for the MP boot page */
#define CONFIG_KM_RESERVED_PRAM 0x1000
/* set the default PRAM value to at least PNVRAM + PHRAM when pram env variable
* is not valid yet, which is the case for when u-boot copies itself to RAM */
#define CONFIG_PRAM ((CONFIG_KM_PNVRAM + CONFIG_KM_PHRAM)>>10)
#define CONFIG_KM_CRAMFS_ADDR 0x2000000
#define CONFIG_KM_KERNEL_ADDR 0x1000000 /* max kernel size 15.5Mbytes */
#define CONFIG_KM_FDT_ADDR 0x1F80000 /* max dtb size 0.5Mbytes */
/*
* Local Bus Definitions
*/
/* Set the local bus clock 1/8 of plat clk, 2 clk delay LALE */
#define CONFIG_SYS_LBC_LCRR (LCRR_CLKDIV_8 | LCRR_EADC_2)
/* Nand Flash */
#define CONFIG_NAND_FSL_ELBC
#define CONFIG_SYS_NAND_BASE 0xffa00000
#define CONFIG_SYS_NAND_BASE_PHYS 0xfffa00000ull
#define CONFIG_SYS_NAND_BASE_LIST {CONFIG_SYS_NAND_BASE}
#define CONFIG_SYS_MAX_NAND_DEVICE 1
#define CONFIG_MTD_NAND_VERIFY_WRITE
#define CONFIG_CMD_NAND
#define CONFIG_SYS_NAND_BLOCK_SIZE (128 * 1024)
#define CONFIG_BCH
/* NAND flash config */
#define CONFIG_SYS_NAND_BR_PRELIM (BR_PHYS_ADDR(CONFIG_SYS_NAND_BASE_PHYS) \
| BR_PS_8 /* Port Size = 8 bit */ \
| BR_MS_FCM /* MSEL = FCM */ \
| BR_V) /* valid */
#define CONFIG_SYS_NAND_OR_PRELIM (OR_AM_256KB /* length 256K */ \
| OR_FCM_BCTLD /* LBCTL not ass */ \
| OR_FCM_SCY_1 /* 1 clk wait cycle */ \
| OR_FCM_RST /* 1 clk read setup */ \
| OR_FCM_PGS /* Large page size */ \
| OR_FCM_CST) /* 0.25 command setup */
#define CONFIG_SYS_BR0_PRELIM CONFIG_SYS_NAND_BR_PRELIM /* NAND Base Address */
#define CONFIG_SYS_OR0_PRELIM CONFIG_SYS_NAND_OR_PRELIM /* NAND Options */
/* QRIO FPGA */
#define CONFIG_SYS_QRIO_BASE 0xfb000000
#define CONFIG_SYS_QRIO_BASE_PHYS 0xffb000000ull
#define CONFIG_SYS_QRIO_BR_PRELIM (BR_PHYS_ADDR(CONFIG_SYS_QRIO_BASE_PHYS) \
| BR_PS_8 /* Port Size 8 bits */ \
| BR_DECC_OFF /* no error corr */ \
| BR_MS_GPCM /* MSEL = GPCM */ \
| BR_V) /* valid */
#define CONFIG_SYS_QRIO_OR_PRELIM (OR_AM_64KB /* length 64K */ \
| OR_GPCM_BCTLD /* no LCTL assert */ \
| OR_GPCM_ACS_DIV4 /* LCS 1/4 clk after */ \
| OR_GPCM_SCY_2 /* 2 clk wait cycles */ \
| OR_GPCM_TRLX /* relaxed tmgs */ \
| OR_GPCM_EAD) /* extra bus clk cycles */
#define CONFIG_SYS_BR1_PRELIM CONFIG_SYS_QRIO_BR_PRELIM /* QRIO Base Address */
#define CONFIG_SYS_OR1_PRELIM CONFIG_SYS_QRIO_OR_PRELIM /* QRIO Options */
/* bootcounter in QRIO */
#define CONFIG_BOOTCOUNT_LIMIT
#define CONFIG_SYS_BOOTCOUNT_ADDR (CONFIG_SYS_QRIO_BASE + 0x20)
#define CONFIG_BOARD_EARLY_INIT_F
#define CONFIG_BOARD_EARLY_INIT_R /* call board_early_init_r function */
#define CONFIG_MISC_INIT_F
#define CONFIG_MISC_INIT_R
#define CONFIG_LAST_STAGE_INIT
#define CONFIG_HWCONFIG
/* define to use L1 as initial stack */
#define CONFIG_L1_INIT_RAM
#define CONFIG_SYS_INIT_RAM_LOCK
#define CONFIG_SYS_INIT_RAM_ADDR 0xffd00000 /* Initial L1 address */
#define CONFIG_SYS_INIT_RAM_ADDR_PHYS_HIGH 0xf
#define CONFIG_SYS_INIT_RAM_ADDR_PHYS_LOW CONFIG_SYS_INIT_RAM_ADDR
/* The assembler doesn't like typecast */
#define CONFIG_SYS_INIT_RAM_ADDR_PHYS \
((CONFIG_SYS_INIT_RAM_ADDR_PHYS_HIGH * 1ull << 32) | \
CONFIG_SYS_INIT_RAM_ADDR_PHYS_LOW)
#define CONFIG_SYS_INIT_RAM_SIZE 0x00004000
#define CONFIG_SYS_GBL_DATA_OFFSET (CONFIG_SYS_INIT_RAM_SIZE - \
GENERATED_GBL_DATA_SIZE)
#define CONFIG_SYS_INIT_SP_OFFSET CONFIG_SYS_GBL_DATA_OFFSET
#define CONFIG_SYS_MONITOR_BASE CONFIG_SYS_TEXT_BASE
#define CONFIG_SYS_MONITOR_LEN (512 * 1024)
#define CONFIG_SYS_MALLOC_LEN (1024 * 1024)
/* Serial Port - controlled on board with jumper J8
* open - index 2
* shorted - index 1
*/
#define CONFIG_CONS_INDEX 1
#define CONFIG_SYS_NS16550
#define CONFIG_SYS_NS16550_SERIAL
#define CONFIG_SYS_NS16550_REG_SIZE 1
#define CONFIG_SYS_NS16550_CLK (get_bus_freq(0)/2)
#define CONFIG_SYS_NS16550_COM1 (CONFIG_SYS_CCSRBAR+0x11C500)
#define CONFIG_SYS_NS16550_COM2 (CONFIG_SYS_CCSRBAR+0x11C600)
#define CONFIG_SYS_NS16550_COM3 (CONFIG_SYS_CCSRBAR+0x11D500)
#define CONFIG_SYS_NS16550_COM4 (CONFIG_SYS_CCSRBAR+0x11D600)
#define CONFIG_KM_CONSOLE_TTY "ttyS0"
/* Use the HUSH parser */
#define CONFIG_SYS_HUSH_PARSER
/* pass open firmware flat tree */
#define CONFIG_OF_LIBFDT
#define CONFIG_OF_BOARD_SETUP
#define CONFIG_OF_STDOUT_VIA_ALIAS
/* new uImage format support */
#define CONFIG_FIT
#define CONFIG_FIT_VERBOSE /* enable fit_format_{error,warning}() */
/* I2C */
#define CONFIG_SYS_I2C
#define CONFIG_SYS_I2C_INIT_BOARD
#define CONFIG_SYS_I2C_SPEED 100000 /* deblocking */
#define CONFIG_SYS_NUM_I2C_BUSES 3
#define CONFIG_SYS_I2C_MAX_HOPS 1
#define CONFIG_SYS_I2C_FSL /* Use FSL I2C driver */
#define CONFIG_I2C_MULTI_BUS
#define CONFIG_I2C_CMD_TREE
#define CONFIG_SYS_FSL_I2C_SPEED 400000
#define CONFIG_SYS_FSL_I2C_SLAVE 0x7F
#define CONFIG_SYS_FSL_I2C_OFFSET 0x118000
#define CONFIG_SYS_I2C_BUSES { {0, {I2C_NULL_HOP} }, \
{0, {{I2C_MUX_PCA9547, 0x70, 1 } } }, \
{0, {{I2C_MUX_PCA9547, 0x70, 2 } } }, \
}
#ifndef __ASSEMBLY__
void set_sda(int state);
void set_scl(int state);
int get_sda(void);
int get_scl(void);
#endif
#define CONFIG_KM_IVM_BUS 1 /* I2C1 (Mux-Port 1)*/
/*
* eSPI - Enhanced SPI
*/
#define CONFIG_FSL_ESPI
#define CONFIG_SPI_FLASH
#define CONFIG_SPI_FLASH_BAR /* 4 byte-addressing */
#define CONFIG_SPI_FLASH_STMICRO
#define CONFIG_SPI_FLASH_SPANSION
#define CONFIG_CMD_SF
#define CONFIG_SF_DEFAULT_SPEED 20000000
#define CONFIG_SF_DEFAULT_MODE 0
/*
* General PCI
* Memory space is mapped 1-1, but I/O space must start from 0.
*/
/* controller 1, direct to uli, tgtid 3, Base address 20000 */
#define CONFIG_SYS_PCIE1_MEM_VIRT 0x80000000
#define CONFIG_SYS_PCIE1_MEM_BUS 0xe0000000
#define CONFIG_SYS_PCIE1_MEM_PHYS 0xc00000000ull
#define CONFIG_SYS_PCIE1_MEM_SIZE 0x20000000 /* 512M */
#define CONFIG_SYS_PCIE1_IO_VIRT 0xf8000000
#define CONFIG_SYS_PCIE1_IO_BUS 0x00000000
#define CONFIG_SYS_PCIE1_IO_PHYS 0xff8000000ull
#define CONFIG_SYS_PCIE1_IO_SIZE 0x00010000 /* 64k */
/* controller 3, Slot 1, tgtid 1, Base address 202000 */
#define CONFIG_SYS_PCIE3_MEM_VIRT 0xa0000000
#define CONFIG_SYS_PCIE3_MEM_BUS 0xe0000000
#define CONFIG_SYS_PCIE3_MEM_PHYS 0xc20000000ull
#define CONFIG_SYS_PCIE3_MEM_SIZE 0x20000000 /* 512M */
#define CONFIG_SYS_PCIE3_IO_VIRT 0xf8010000
#define CONFIG_SYS_PCIE3_IO_BUS 0x00000000
#define CONFIG_SYS_PCIE3_IO_PHYS 0xff8010000ull
#define CONFIG_SYS_PCIE3_IO_SIZE 0x00010000 /* 64k */
/* Qman/Bman */
#define CONFIG_SYS_DPAA_QBMAN /* Support Q/Bman */
#define CONFIG_SYS_BMAN_NUM_PORTALS 10
#define CONFIG_SYS_BMAN_MEM_BASE 0xf4000000
#define CONFIG_SYS_BMAN_MEM_PHYS 0xff4000000ull
#define CONFIG_SYS_BMAN_MEM_SIZE 0x00200000
#define CONFIG_SYS_QMAN_NUM_PORTALS 10
#define CONFIG_SYS_QMAN_MEM_BASE 0xf4200000
#define CONFIG_SYS_QMAN_MEM_PHYS 0xff4200000ull
#define CONFIG_SYS_QMAN_MEM_SIZE 0x00200000
#define CONFIG_SYS_DPAA_FMAN
#define CONFIG_SYS_DPAA_PME
/* Default address of microcode for the Linux Fman driver
* env is stored at 0x100000, sector size is 0x10000, x2 (redundant)
* ucode is stored after env, so we got 0x120000.
*/
#define CONFIG_SYS_QE_FW_IN_SPIFLASH
#define CONFIG_SYS_FMAN_FW_ADDR 0x120000
#define CONFIG_SYS_QE_FMAN_FW_LENGTH 0x10000
#define CONFIG_SYS_FDT_PAD (0x3000 + CONFIG_SYS_QE_FMAN_FW_LENGTH)
#define CONFIG_FMAN_ENET
#define CONFIG_PHYLIB_10G
#define CONFIG_PHY_MARVELL /* there is a marvell phy */
#define CONFIG_PCI_INDIRECT_BRIDGE
#define CONFIG_PCI_PNP /* do pci plug-and-play */
#define CONFIG_E1000
#define CONFIG_PCI_SCAN_SHOW /* show pci devices on startup */
#define CONFIG_DOS_PARTITION
/* RGMII (FM1@DTESC5) is used as debug itf, it's the only one configured */
#define CONFIG_SYS_FM1_DTSEC5_PHY_ADDR 0x11
#define CONFIG_SYS_TBIPA_VALUE 8
#define CONFIG_PHYLIB /* recommended PHY management */
#define CONFIG_ETHPRIME "FM1@DTSEC5"
#define CONFIG_PHY_GIGE /* Include GbE speed/duplex detection */
/*
* Environment
*/
#define CONFIG_LOADS_ECHO /* echo on for serial download */
#define CONFIG_SYS_LOADS_BAUD_CHANGE /* allow baudrate change */
/*
* additionnal command line configuration.
*/
#define CONFIG_CMD_PCI
#define CONFIG_CMD_NET
#define CONFIG_CMD_ERRATA
/* we don't need flash support */
#define CONFIG_SYS_NO_FLASH
#undef CONFIG_CMD_IMLS
#undef CONFIG_CMD_FLASH
#undef CONFIG_FLASH_CFI_MTD
#undef CONFIG_JFFS2_CMDLINE
/*
* For booting Linux, the board info and command line data
* have to be in the first 64 MB of memory, since this is
* the maximum mapped by the Linux kernel during initialization.
*/
#define CONFIG_SYS_BOOTMAPSZ (64 << 20) /* Initial Memory for Linux */
#define CONFIG_SYS_BOOTM_LEN (64 << 20) /* Increase max gunzip size */
#ifdef CONFIG_CMD_KGDB
#define CONFIG_KGDB_BAUDRATE 230400 /* speed to run kgdb serial port */
#endif
#define __USB_PHY_TYPE utmi
/*
* Environment Configuration
*/
#define CONFIG_ENV_OVERWRITE
#ifndef CONFIG_KM_DEF_ENV /* if not set by keymile-common.h */
#define CONFIG_KM_DEF_ENV "km-common=empty\0"
#endif
#ifndef MTDIDS_DEFAULT
# define MTDIDS_DEFAULT "nand0=fsl_elbc_nand"
#endif /* MTDIDS_DEFAULT */
#ifndef MTDPARTS_DEFAULT
# define MTDPARTS_DEFAULT "mtdparts=" \
"fsl_elbc_nand:" \
"-(" CONFIG_KM_UBI_PARTITION_NAME_BOOT ");"
#endif /* MTDPARTS_DEFAULT */
/* architecture specific default bootargs */
#define CONFIG_KM_DEF_BOOT_ARGS_CPU ""
/* FIXME: FDT_ADDR is unspecified */
#define CONFIG_KM_DEF_ENV_CPU \
"boot=bootm ${load_addr_r} - ${fdt_addr_r}\0" \
"cramfsloadfdt=" \
"cramfsload ${fdt_addr_r} " \
"fdt_0x${IVM_BoardId}_0x${IVM_HWKey}.dtb\0" \
"fdt_addr_r=" __stringify(CONFIG_KM_FDT_ADDR) "\0" \
"u-boot="__stringify(CONFIG_HOSTNAME) "/u-boot.pbl\0" \
"update=" \
"sf probe 0;sf erase 0 +${filesize};" \
"sf write ${load_addr_r} 0 ${filesize};\0" \
"set_fdthigh=true\0" \
""
#define CONFIG_HW_ENV_SETTINGS \
"hwconfig=fsl_ddr:ctlr_intlv=cacheline\0" \
"usb_phy_type=" __stringify(__USB_PHY_TYPE) "\0" \
"usb_dr_mode=host\0"
#define CONFIG_KM_NEW_ENV \
"newenv=sf probe 0;" \
"sf erase " __stringify(CONFIG_ENV_OFFSET) " " \
__stringify(CONFIG_ENV_TOTAL_SIZE)"\0"
/* ppc_82xx is the equivalent to ppc_6xx, the generic ppc toolchain */
#ifndef CONFIG_KM_DEF_ARCH
#define CONFIG_KM_DEF_ARCH "arch=ppc_82xx\0"
#endif
#define CONFIG_EXTRA_ENV_SETTINGS \
CONFIG_KM_DEF_ENV \
CONFIG_KM_DEF_ARCH \
CONFIG_KM_NEW_ENV \
CONFIG_HW_ENV_SETTINGS \
"EEprom_ivm=pca9547:70:9\0" \
""
#endif /* _CONFIG_KMP204X_H */
|
cec0906d0e148c59042641cce07d854852fe83ec
|
b7ee9ac14d6981e18fa1b19214366878a4884a42
|
/Projects/ThirdParty/source/libmpg123/config.h
|
299a9731b2732c8563782f5f4e91a2fee0ab77aa
|
[
"MIT"
] |
permissive
|
skylicht-lab/skylicht-engine
|
89d51b4240ca6ed5a7f15b413df5711288580e9e
|
ff0e875581840efd15503cdfa49f112b6adade98
|
refs/heads/master
| 2023-09-01T02:23:45.865965
| 2023-08-29T08:21:41
| 2023-08-29T08:21:41
| 220,988,542
| 492
| 46
|
MIT
| 2023-06-05T10:18:45
| 2019-11-11T13:34:56
|
C++
|
UTF-8
|
C
| false
| false
| 189
|
h
|
config.h
|
#define OPT_MULTI
#define OPT_GENERIC
#define OPT_I386
// disable ASM compile
#define OPT_NO_OPTIMIZE
#if defined(_WIN32)
#include "config_window.h"
#else
#include "config_linux.h"
#endif
|
19918440abe5911da8da0645e83fdca22a3b8d21
|
c9bc99866cfab223c777cfb741083be3e9439d81
|
/framework/include/internal/fwk_core.h
|
ca580cd10a95b000120fffff1777fb017438710b
|
[
"BSD-3-Clause"
] |
permissive
|
ARM-software/SCP-firmware
|
4738ca86ce42d82588ddafc2226a1f353ff2c797
|
f6bcca436768359ffeadd84d65e8ea0c3efc7ef1
|
refs/heads/master
| 2023-09-01T16:13:36.962036
| 2023-08-17T13:00:20
| 2023-08-31T07:43:37
| 134,399,880
| 211
| 165
|
NOASSERTION
| 2023-09-13T14:27:10
| 2018-05-22T10:35:56
|
C
|
UTF-8
|
C
| false
| false
| 4,562
|
h
|
fwk_core.h
|
/*
* Arm SCP/MCP Software
* Copyright (c) 2015-2022, Arm Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef FWK_INTERNAL_CORE_H
#define FWK_INTERNAL_CORE_H
#include <fwk_core.h>
#include <fwk_event.h>
#include <fwk_noreturn.h>
#include <stddef.h>
/*
* \brief Initialize the core framework component.
*
* \param event_count The maximum number of events in all queues at all time.
*
* \retval ::FWK_SUCCESS The core framework component was initialized.
* \retval ::FWK_E_NOMEM Insufficient memory available for event queues.
*/
int __fwk_init(size_t event_count);
/*
* \brief Loop forever, processing events raised by modules and interrupt
* handlers. This function will suspend execution if the queue is empty and
* resume on an interrupt.
*
* \return The function does not return.
*/
noreturn void __fwk_run_main_loop(void);
/*
* \brief Get the event being currently processed.
*
* \return The event being currently processed, or \c NULL if event processing
* has not yet begun.
*/
const struct fwk_event *__fwk_get_current_event(void);
/*
* \brief Put a notification event in one of the event queues.
*
* \details The core component copies the notification event description into
* its internal data and so does not keep track of the pointer passed as a
* parameter.
*
* If the function is called from an ISR, the validity of the event source
* identifier is checked and the event is put in the ISR event queue.
*
* \param event Pointer to the notification event to queue.
*
* \retval ::FWK_SUCCESS The event was queued.
* \retval ::FWK_E_PARAM The source identifier is not valid.
* \retval ::FWK_E_NOMEM No memory space to copy the event data.
*/
int __fwk_put_notification(struct fwk_event *event);
/*!
* \brief Put an event in one of the event queues.
*
* \details The framework copies the event description into its internal data
* and so does not keep track of the pointer passed as a parameter.
*
* In the runtime phase, the source identifier of the event is populated
* with the identifier of the caller, and it is therefore unnecessary for
* the caller to do so manually. Note that this does not occur in the
* pre-runtime phase.
*
* If the function is called from an ISR, the event is put in the ISR
* event queue.
*
* In both cases, the event identifier and target identifier are checked
* to be valid and to refer to the same module.
*
* In the case of a delayed response event, the event's 'is_response' flag
* must be set.
*
*
* \param[in] event Pointer to the event to queue. Must not be \c NULL.
*
* \retval ::FWK_SUCCESS The event was queued.
* \retval ::FWK_E_INIT The core framework component is not initialized.
* \retval ::FWK_E_PARAM An invalid parameter was encountered:
* - The `event` parameter was a null pointer value.
* - One or more fields of the event were invalid.
* \retval ::FWK_E_OS Operating system error.
*
* \return Status code representing the result of the operation.
*/
int __fwk_put_event(struct fwk_event *event);
/*!
* \brief Put a light event by converting to a normal event in one of the event
* queues.
*
* \details The framework copies the light event description into its internal
* data(<tt> struct fwk_event </tt>) and so does not keep track of the
* pointer passed as a parameter.
*
* In the runtime phase, the source identifier of the event is populated
* with the identifier of the caller, and it is therefore unnecessary for
* the caller to do so manually. Note that this does not occur in the
* pre-runtime phase.
*
* If the function is called from an ISR, the event is put in the ISR
* event queue.
*
* In both cases, the event identifier and target identifier are checked
* to be valid and to refer to the same module.
*
*
* \param[in] event Pointer to the event to queue. Must not be \c NULL.
*
* \retval ::FWK_SUCCESS The event was queued.
* \retval ::FWK_E_INIT The core framework component is not initialized.
* \retval ::FWK_E_PARAM An invalid parameter was encountered:
* - The `event` parameter was a null pointer value.
* - One or more fields of the event were invalid.
* \retval ::FWK_E_OS Operating system error.
*
* \return Status code representing the result of the operation.
*/
int __fwk_put_event_light(struct fwk_event_light *event);
#endif /* FWK_INTERNAL_CORE_H */
|
af2fd9ad46eec2d1d05ad6c1b78de7e541497266
|
fae867d62224cdf27ceb85654525a311fb8c4226
|
/rp-api/api/src/gen_handler.h
|
ce3926b9f4c56f8ecfdfea176397f3db521d7e2d
|
[
"BSD-3-Clause"
] |
permissive
|
RedPitaya/RedPitaya
|
a4a9b0bda0d1806e39b90ee9f3164e2e0dee0ab6
|
69826707f78c764e5835f3197e61f68ced90f77b
|
refs/heads/master
| 2023-09-01T12:25:51.370133
| 2023-07-26T03:51:31
| 2023-07-26T03:51:31
| 17,261,658
| 447
| 601
|
NOASSERTION
| 2023-07-27T04:07:43
| 2014-02-27T19:38:52
|
C
|
UTF-8
|
C
| false
| false
| 5,244
|
h
|
gen_handler.h
|
/**
* $Id: $
*
* @brief Red Pitaya library Generate handler interface
*
* @Author Red Pitaya
*
* (c) Red Pitaya http://www.redpitaya.com
*
* This part of code is written in C programming language.
* Please visit http://en.wikipedia.org/wiki/C_(programming_language)
* for more details on the language used herein.
*/
#ifndef GENERATE_HANDLER_H_
#define GENERATE_HANDLER_H_
#include "redpitaya/rp.h"
#include "rp_hw-profiles.h"
int gen_SetDefaultValues();
int gen_Disable(rp_channel_t chanel);
int gen_Enable(rp_channel_t chanel);
int gen_EnableSync(bool enable);
int gen_IsEnable(rp_channel_t channel, bool *value);
int gen_setAmplitude(rp_channel_t channel, float amplitude);
int gen_getAmplitude(rp_channel_t channel, float *amplitude);
int gen_setOffset(rp_channel_t channel, float offset) ;
int gen_getOffset(rp_channel_t channel, float *offset) ;
int gen_setFrequency(rp_channel_t channel, float frequency);
int gen_setFrequencyDirect(rp_channel_t channel, float frequency); // Used for sweepmode
int gen_getFrequency(rp_channel_t channel, float *frequency);
int gen_setSweepStartFrequency(rp_channel_t channel, float frequency);
int gen_getSweepStartFrequency(rp_channel_t channel, float *frequency);
int gen_setSweepEndFrequency(rp_channel_t channel, float frequency);
int gen_getSweepEndFrequency(rp_channel_t channel, float *frequency);
int gen_setPhase(rp_channel_t channel, float phase);
int gen_getPhase(rp_channel_t channel, float *phase);
int gen_setWaveform(rp_channel_t channel, rp_waveform_t type);
int gen_getWaveform(rp_channel_t channel, rp_waveform_t *type);
int gen_setSweepMode(rp_channel_t channel, rp_gen_sweep_mode_t mode);
int gen_getSweepMode(rp_channel_t channel, rp_gen_sweep_mode_t *mode);
int gen_setSweepDir(rp_channel_t channel, rp_gen_sweep_dir_t mode);
int gen_getSweepDir(rp_channel_t channel, rp_gen_sweep_dir_t *mode);
int gen_setArbWaveform(rp_channel_t channel, float *data, uint32_t length);
int gen_getArbWaveform(rp_channel_t channel, float *data, uint32_t *length);
int gen_setDutyCycle(rp_channel_t channel, float ratio);
int gen_getDutyCycle(rp_channel_t channel, float *ratio);
int gen_setRiseTime(rp_channel_t channel, float time);
int gen_getRiseTime(rp_channel_t channel, float *time);
int gen_setFallTime(rp_channel_t channel, float time);
int gen_getFallTime(rp_channel_t channel, float *time);
int gen_setRiseFallMin(rp_channel_t channel, float min);
int gen_setRiseFallMax(rp_channel_t channel, float max);
int gen_getRiseFallMin(rp_channel_t channel, float *min);
int gen_getRiseFallMax(rp_channel_t channel, float *max);
int gen_setGenMode(rp_channel_t channel, rp_gen_mode_t mode);
int gen_getGenMode(rp_channel_t channel, rp_gen_mode_t *mode);
int gen_setBurstCount(rp_channel_t channel, int num);
int gen_getBurstCount(rp_channel_t channel, int *num);
int gen_setBurstRepetitions(rp_channel_t channel, int repetitions);
int gen_getBurstRepetitions(rp_channel_t channel, int *repetitions);
int gen_setBurstPeriod(rp_channel_t channel, uint32_t period);
int gen_getBurstPeriod(rp_channel_t channel, uint32_t *period);
int gen_GetDACSamplePeriod(double *value);
int gen_setTriggerSource(rp_channel_t chanel, rp_trig_src_t src);
int gen_getTriggerSource(rp_channel_t chanel, rp_trig_src_t *src);
int gen_Trigger(uint32_t channel);
int gen_TriggerSync();
int gen_TriggerOnly(uint32_t channel);
int gen_SynchroniseSM();
int gen_ResetChannelSM(rp_channel_t channel);
int triggerIfInternal(rp_channel_t channel);
int synthesize_signal(rp_channel_t channel);
int synthesis_sin(float scale, float *data_out,uint16_t buffSize);
int synthesis_sweep(float scale,float frequency,float frequency_start,float frequency_end,float phaseRad,rp_gen_sweep_mode_t mode,rp_gen_sweep_dir_t dir,float *data_out,uint16_t buffSize);
int synthesis_triangle(float scale,float *data_out,uint16_t buffSize);
int synthesis_arbitrary(float scale,rp_channel_t channel, float *data_out, uint32_t * size);
int synthesis_square(float scale,float frequency, float riseTime, float fallTime, float *data_out,uint16_t buffSize);
int synthesis_rampUp(float scale,float *data_out,uint16_t buffSize);
int synthesis_rampDown(float scale,float *data_out,uint16_t buffSize);
int synthesis_DC(float scale,float *data_out,uint16_t buffSize);
int synthesis_DC_NEG(float scale,float *data_out,uint16_t buffSize);
int synthesis_PWM(float scale,float ratio, float *data_out,uint16_t buffSize);
int gen_setBurstLastValue(rp_channel_t channel, float amplitude);
int gen_getBurstLastValue(rp_channel_t channel, float *amplitude);
int gen_setInitGenValue(rp_channel_t channel, float amplitude);
int gen_getInitGenValue(rp_channel_t channel, float *amplitude);
int gen_setGainOut(rp_channel_t channel,rp_gen_gain_t mode);
int gen_getGainOut(rp_channel_t channel,rp_gen_gain_t *status);
int gen_setEnableTempProtection(rp_channel_t channel, bool enable);
int gen_getEnableTempProtection(rp_channel_t channel, bool *enable);
int gen_setLatchTempAlarm(rp_channel_t channel, bool status);
int gen_getLatchTempAlarm(rp_channel_t channel, bool *status);
int gen_getRuntimeTempAlarm(rp_channel_t channel, bool *status);
int gen_SetExtTriggerDebouncerUs(double value);
int gen_GetExtTriggerDebouncerUs(double *value);
#endif
|
5778a193278b6b0e25692caafb2c587bce425f43
|
b32981054539b3afbe4e6e0bf6f498a5727d9d55
|
/tests/com.oracle.truffle.llvm.tests.debug/debug/testFunctionPointer.c
|
d324a5ce0d24874ee57de9a990ec1139786f699a
|
[
"BSD-3-Clause",
"NCSA",
"MIT"
] |
permissive
|
graalvm/sulong
|
20675cddc60c039c0c4053b3ab231b0b21131d97
|
20686f6a72e222ad0a6ebc6ef002a5b353a45fc6
|
refs/heads/master
| 2023-03-08T19:07:57.500164
| 2018-12-05T11:00:54
| 2018-12-05T11:00:54
| 49,868,718
| 679
| 92
|
NOASSERTION
| 2019-02-14T10:27:23
| 2016-01-18T10:12:52
|
Java
|
UTF-8
|
C
| false
| false
| 2,793
|
c
|
testFunctionPointer.c
|
/*
* Copyright (c) 2018, 2018, Oracle and/or its affiliates.
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided
* with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used to
* endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdio.h>
void voidFuncNoArgs(void) {
}
void voidFuncImplicitVarArgs() {
}
void voidFuncIntArg(int i) {
}
void voidFuncIntVarArgs(int i, ...) {
}
int intFuncNoArgs(void) {
return 42;
}
int intFuncImplicitVarArgs() {
return 42;
}
int intFuncIntArg(int i) {
return 42;
}
int intFuncIntVarArgs(int i, ...) {
return 42;
}
int start() __attribute__((constructor)) {
void (*voidFuncNoArgsPtr)(void) = &voidFuncNoArgs;
void (*voidFuncImplicitVarArgsPtr)() = &voidFuncImplicitVarArgs;
void (*voidFuncIntArgPtr)(int) = &voidFuncIntArg;
void (*voidFuncIntVarArgsPtr)(int, ...) = &voidFuncIntVarArgs;
int (*intFuncNoArgsPtr)(void) = &intFuncNoArgs;
int (*intFuncImplicitVarArgsPtr)() = &intFuncImplicitVarArgs;
int (*intFuncIntArgPtr)(int) = &intFuncIntArg;
int (*intFuncIntVarArgsPtr)(int, ...) = &intFuncIntVarArgs;
__builtin_debugtrap();
voidFuncNoArgsPtr();
voidFuncImplicitVarArgsPtr();
voidFuncIntArgPtr(42);
voidFuncIntVarArgsPtr(42, 42, 42);
int res;
res = intFuncNoArgsPtr();
res = intFuncImplicitVarArgsPtr();
res = intFuncIntArgPtr(42);
res = intFuncIntVarArgsPtr(42, 42, 42);
return 0;
}
|
2e8896fccb251e2f25676846c23d1fd59bb309b6
|
4f14b1901d909b0b917d35815e7b19233692f25b
|
/free-small-fft-in-multiple-languages/fft-complex-test.c
|
95c7fcc49b2d96ae82073f30394ea428d358f728
|
[] |
no_license
|
nayuki/Nayuki-web-published-code
|
e61a761e5c188aeacd35e5c8ddd005460545c94e
|
49414617b088ec4c4e339a6c1caa7ec0f40eb58f
|
refs/heads/master
| 2023-08-24T10:54:42.862243
| 2023-03-14T05:29:56
| 2023-03-14T05:29:56
| 25,706,873
| 133
| 53
| null | 2017-02-20T08:39:16
| 2014-10-24T20:33:24
|
Java
|
UTF-8
|
C
| false
| false
| 5,599
|
c
|
fft-complex-test.c
|
/*
* FFT and convolution test (C)
*
* Copyright (c) 2021 Project Nayuki. (MIT License)
* https://www.nayuki.io/page/free-small-fft-in-multiple-languages
*
* 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 <complex.h>
#include <math.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "fft-complex.h"
// Private function prototypes
static void test_fft(int n);
static void test_convolution(int n);
static void naive_dft(const double complex invec[restrict], double complex outvec[restrict], int n, bool inverse);
static void naive_convolve(const double complex xvec[restrict], const double complex yvec[restrict], double complex outvec[restrict], int n);
static double log10_rms_err(const double complex xvec[], const double complex yvec[], int n);
static double complex *random_complexes(int n);
static void *memdup(const void *src, size_t n);
static double max_log_error = -INFINITY;
/*---- Main and test functions ----*/
int main(void) {
srand(time(NULL));
// Test power-of-2 size FFTs
for (int i = 0; i <= 12; i++)
test_fft(1 << i);
// Test small size FFTs
for (int i = 0; i < 30; i++)
test_fft(i);
// Test diverse size FFTs
for (int i = 0, prev = 0; i <= 100; i++) {
int n = (int)lround(pow(1500, i / 100.0));
if (n > prev) {
test_fft(n);
prev = n;
}
}
// Test power-of-2 size convolutions
for (int i = 0; i <= 12; i++)
test_convolution(1 << i);
// Test diverse size convolutions
for (int i = 0, prev = 0; i <= 100; i++) {
int n = (int)lround(pow(1500, i / 100.0));
if (n > prev) {
test_convolution(n);
prev = n;
}
}
printf("\n");
printf("Max log err = %.1f\n", max_log_error);
printf("Test %s\n", max_log_error < -10 ? "passed" : "failed");
return EXIT_SUCCESS;
}
static void test_fft(int n) {
double complex *input = random_complexes(n);
double complex *expect = malloc(n * sizeof(double complex));
naive_dft(input, expect, n, false);
double complex *actual = memdup(input, n * sizeof(double complex));
Fft_transform(actual, n, false);
double err0 = log10_rms_err(expect, actual, n);
for (int i = 0; i < n; i++)
actual[i] /= n;
Fft_transform(actual, n, true);
double err1 = log10_rms_err(input, actual, n);
printf("fftsize=%4d logerr=%5.1f\n", n, (err0 > err1 ? err0 : err1));
free(input);
free(expect);
free(actual);
}
static void test_convolution(int n) {
double complex *input0 = random_complexes(n);
double complex *input1 = random_complexes(n);
double complex *expect = malloc(n * sizeof(double complex));
naive_convolve(input0, input1, expect, n);
double complex *actual = malloc(n * sizeof(double complex));
Fft_convolve(input0, input1, actual, n);
printf("convsize=%4d logerr=%5.1f\n", n, log10_rms_err(expect, actual, n));
free(input0);
free(input1);
free(expect);
free(actual);
}
/*---- Naive reference computation functions ----*/
static void naive_dft(const double complex invec[restrict], double complex outvec[restrict], int n, bool inverse) {
double coef = (inverse ? 2 : -2) * M_PI;
for (int k = 0; k < n; k++) { // For each output element
double complex sum = 0.0;
for (int t = 0; t < n; t++) { // For each input element
double angle = coef * ((uintmax_t)t * k % n) / n;
sum += invec[t] * cexp(angle * I);
}
outvec[k] = sum;
}
}
static void naive_convolve(const double complex xvec[restrict], const double complex yvec[restrict], double complex outvec[restrict], int n) {
for (int i = 0; i < n; i++)
outvec[i] = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++)
outvec[(i + j) % n] += xvec[i] * yvec[j];
}
}
/*---- Utility functions ----*/
static double log10_rms_err(const double complex xvec[], const double complex yvec[], int n) {
double err = pow(10, -99 * 2);
for (int i = 0; i < n; i++) {
double temp = cabs(xvec[i] - yvec[i]);
err += temp * temp;
}
err /= n > 0 ? n : 1;
err = sqrt(err); // Now this is a root mean square (RMS) error
err = log10(err);
if (err > max_log_error)
max_log_error = err;
return err;
}
static double complex *random_complexes(int n) {
double complex *result = malloc(n * sizeof(double complex));
for (int i = 0; i < n; i++) {
double re = (rand() / (RAND_MAX + 1.0)) * 2 - 1;
double im = (rand() / (RAND_MAX + 1.0)) * 2 - 1;
result[i] = re + im * I;
}
return result;
}
static void *memdup(const void *src, size_t n) {
void *dest = malloc(n);
if (n > 0 && dest != NULL)
memcpy(dest, src, n);
return dest;
}
|
514f6d810cfc62b1f97a969d15a55d993aecfc0d
|
0063e707c6300c49d95efeae210e374972509c59
|
/ext/tensor/exceptions/tensorexception.zep.h
|
44f14a6671828e9ec9b80b5cf2ad333bf8bedf25
|
[
"MIT",
"CC-BY-NC-4.0"
] |
permissive
|
RubixML/Tensor
|
f6b5e0f076b973cd6e9d6876afee16ec6bb2c42d
|
47e524db9672afb36aee47fdd51ebfdc9188c051
|
refs/heads/master
| 2023-04-18T10:28:34.557923
| 2023-02-27T00:37:40
| 2023-02-27T00:37:40
| 151,361,731
| 184
| 26
|
MIT
| 2023-09-13T15:10:41
| 2018-10-03T04:43:19
|
PHP
|
UTF-8
|
C
| false
| true
| 120
|
h
|
tensorexception.zep.h
|
extern zend_class_entry *tensor_exceptions_tensorexception_ce;
ZEPHIR_INIT_CLASS(Tensor_Exceptions_TensorException);
|
dad11e81e34b78662853b1f73051f18b1cdceb7c
|
fbd6afa22568045d8806ecdda93144d1a6e44af2
|
/Src/Representations/MotionControl/StandGenerator.h
|
14441e4b530b4e3ea6b8cc17ed957cf73f98716f
|
[
"BSD-2-Clause"
] |
permissive
|
bhuman/BHumanCodeRelease
|
5ccbcc60b968c12f29983992d603ab464a51051b
|
645031c46ff88efcf32129301d21e109857cde3d
|
refs/heads/master
| 2023-05-22T09:49:04.827692
| 2023-03-29T15:27:24
| 2023-03-29T15:27:24
| 15,512,849
| 212
| 151
| null | 2018-04-12T12:36:26
| 2013-12-29T18:24:40
|
C++
|
UTF-8
|
C
| false
| false
| 346
|
h
|
StandGenerator.h
|
/**
* @file StandGenerator.h
*
* This file declares a representation that can create stand phases.
*
* @author Arne Hasselbring
*/
#pragma once
#include "Streaming/Function.h"
#include "Tools/Motion/MotionGenerator.h"
#include "Streaming/AutoStreamable.h"
STREAMABLE_WITH_BASE(StandGenerator, MotionGenerator,
{
BASE_HAS_FUNCTION,
});
|
c8da4a5ebd21251bbcacc2308c3e28e89531b103
|
2f60633ec3120ebf07e458f9ad196c75c15c90ca
|
/3rdparty/fcpp/cpp3.c
|
65c6b2436edb30dea3f6b207e5249611ed952899
|
[
"MIT",
"LicenseRef-scancode-free-unknown",
"BSD-2-Clause",
"BSD-3-Clause",
"LicenseRef-scancode-public-domain"
] |
permissive
|
bkaradzic/bgfx
|
1f51d0222c4428e87e36a99d788fb909027ad504
|
98f16cd1252e62e9fc76c3b41ab86fcc0fe149a7
|
refs/heads/master
| 2023-08-31T18:00:06.315091
| 2023-08-29T03:07:37
| 2023-08-29T03:07:37
| 3,925,242
| 13,956
| 2,454
|
BSD-2-Clause
| 2023-09-11T03:52:45
| 2012-04-04T03:39:04
|
C++
|
UTF-8
|
C
| false
| false
| 12,228
|
c
|
cpp3.c
|
/******************************************************************************
Copyright (c) 1999 Daniel Stenberg
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 <stdio.h>
#include <ctype.h>
#include <time.h> /*OIS*0.92*/
#include "cppdef.h"
#include "cpp.h"
ReturnCode fpp_openfile(struct Global *global, char *filename)
{
/*
* Open a file, add it to the linked list of open files.
* This is called only from fpp_openfile() in cpp2.c.
*/
FILE *fp;
ReturnCode ret;
if (global->openfile)
fp = global->openfile(filename, "r", global->userdata);
else
fp = fopen(filename, "r");
if (fp == NULL)
ret=FPP_OPEN_ERROR;
else
ret=fpp_addfile(global, fp, filename);
if(!ret && global->depends) {
global->depends(filename, global->userdata);
}
if(!ret && global->showincluded) {
/* no error occured! */
fpp_Error(global, "cpp: included \"");
fpp_Error(global, filename);
fpp_Error(global, "\"\n");
}
return(ret);
}
ReturnCode fpp_addfile(struct Global *global,
FILE *fp, /* Open file pointer */
char *filename) /* Name of the file */
{
/*
* Initialize tables for this open file. This is called from fpp_openfile()
* above (for #include files), and from the entry to cpp to open the main
* input file. It calls a common routine, fpp_getfile() to build the FILEINFO
* structure which is used to read characters. (fpp_getfile() is also called
* to setup a macro replacement.)
*/
FILEINFO *file;
ReturnCode ret;
ret = fpp_getfile(global, NBUFF, filename, &file);
if(ret)
return(ret);
file->fp = fp; /* Better remember FILE * */
file->buffer[0] = EOS; /* Initialize for first read */
global->line = 1; /* Working on line 1 now */
global->wrongline = FPP_TRUE; /* Force out initial #line */
return(FPP_OK);
}
int fpp_dooptions(struct Global *global, struct fppTag *tags)
{
/*
* fpp_dooptions is called to process command line arguments (-Detc).
* It is called only at cpp startup.
*/
DEFBUF *dp;
char end=FPP_FALSE; /* end of taglist */
while(tags && !end) {
switch(tags->tag) {
case FPPTAG_END:
end=FPP_TRUE;
break;
case FPPTAG_INITFUNC:
global->initialfunc = (char *) tags->data;
break;
case FPPTAG_DISPLAYFUNCTIONS:
global->outputfunctions = tags->data?1:0;
break;
case FPPTAG_RIGHTCONCAT:
global->rightconcat = tags->data?1:0;
break;
case FPPTAG_OUTPUTMAIN:
global->outputfile = tags->data?1:0;
break;
case FPPTAG_NESTED_COMMENTS:
global->nestcomments = tags->data?1:0;
break;
case FPPTAG_WARNMISSINCLUDE:
global->warnnoinclude = tags->data?1:0;
break;
case FPPTAG_WARN_NESTED_COMMENTS:
global->warnnestcomments = tags->data?1:0;
break;
case FPPTAG_OUTPUTSPACE:
global->showspace = tags->data?1:0;
break;
case FPPTAG_OUTPUTBALANCE:
global->showbalance = tags->data?1:0;
break;
case FPPTAG_OUTPUTINCLUDES:
global->showincluded = tags->data?1:0;
break;
case FPPTAG_SHOWVERSION:
global->showversion = tags->data?1:0;
break;
case FPPTAG_WARNILLEGALCPP:
global->warnillegalcpp = tags->data?1:0;
break;
case FPPTAG_OUTPUTLINE:
global->outputLINE = tags->data?1:0;
break;
case FPPTAG_KEEPCOMMENTS:
if(tags->data) {
global->cflag = FPP_TRUE;
global->keepcomments = FPP_TRUE;
}
break;
case FPPTAG_DEFINE:
/*
* If the option is just "-Dfoo", make it -Dfoo=1
*/
{
char *symbol=(char *)tags->data;
char *text=symbol;
while (*text != EOS && *text != '=')
text++;
if (*text == EOS)
text = "1";
else
*text++ = EOS;
/*
* Now, save the word and its definition.
*/
dp = fpp_defendel(global, symbol, FPP_FALSE);
if(!dp)
return(FPP_OUT_OF_MEMORY);
dp->repl = fpp_savestring(global, text);
dp->nargs = DEF_NOARGS;
}
break;
case FPPTAG_IGNORE_NONFATAL:
global->eflag = FPP_TRUE;
break;
case FPPTAG_INCLUDE_DIR:
if (global->incend >= &global->incdir[NINCLUDE]) {
fpp_cfatal(global, FATAL_TOO_MANY_INCLUDE_DIRS);
return(FPP_TOO_MANY_INCLUDE_DIRS);
}
*global->incend++ = (char *)tags->data;
break;
case FPPTAG_INCLUDE_FILE:
case FPPTAG_INCLUDE_MACRO_FILE:
if (global->included >= NINCLUDE) {
fpp_cfatal(global, FATAL_TOO_MANY_INCLUDE_FILES);
return(FPP_TOO_MANY_INCLUDE_FILES);
}
global->include[(unsigned)global->included] = (char *)tags->data;
global->includeshow[(unsigned)global->included] =
(tags->tag == FPPTAG_INCLUDE_FILE);
global->included++;
break;
case FPPTAG_BUILTINS:
global->nflag|=(tags->data?NFLAG_BUILTIN:0);
break;
case FPPTAG_PREDEFINES:
global->nflag|=(tags->data?NFLAG_PREDEFINE:0);
break;
case FPPTAG_IGNORE_CPLUSPLUS:
global->cplusplus=!tags->data;
break;
case FPPTAG_SIZEOF_TABLE:
{
SIZES *sizp; /* For -S */
int size; /* For -S */
int isdatum; /* FPP_FALSE for -S* */
int endtest; /* For -S */
char *text=(char *)tags->data;
sizp = size_table;
if ((isdatum = (*text != '*'))) /* If it's just -S, */
endtest = T_FPTR; /* Stop here */
else { /* But if it's -S* */
text++; /* Step over '*' */
endtest = 0; /* Stop at end marker */
}
while (sizp->bits != endtest && *text != EOS) {
if (!isdigit(*text)) { /* Skip to next digit */
text++;
continue;
}
size = 0; /* Compile the value */
while (isdigit(*text)) {
size *= 10;
size += (*text++ - '0');
}
if (isdatum)
sizp->size = size; /* Datum size */
else
sizp->psize = size; /* Pointer size */
sizp++;
}
if (sizp->bits != endtest)
fpp_cwarn(global, WARN_TOO_FEW_VALUES_TO_SIZEOF, NULL);
else if (*text != EOS)
fpp_cwarn(global, WARN_TOO_MANY_VALUES_TO_SIZEOF, NULL);
}
break;
case FPPTAG_UNDEFINE:
if (fpp_defendel(global, (char *)tags->data, FPP_TRUE) == NULL)
fpp_cwarn(global, WARN_NOT_DEFINED, tags->data);
break;
case FPPTAG_OUTPUT_DEFINES:
global->wflag++;
break;
case FPPTAG_INPUT_NAME:
strcpy(global->work, tags->data); /* Remember input filename */
global->first_file=tags->data;
break;
case FPPTAG_DEPENDS:
global->depends=(void (*)(char *, void *))tags->data;
break;
case FPPTAG_INPUT:
global->input=(char *(*)(char *, int, void *))tags->data;
break;
case FPPTAG_OUTPUT:
global->output=(void (*)(int, void *))tags->data;
break;
case FPPTAG_ERROR:
global->error=(void (*)(void *, char *, va_list))tags->data;
break;
case FPPTAG_USERDATA:
global->userdata=tags->data;
break;
case FPPTAG_LINE:
global->linelines= tags->data?1:0;
break;
case FPPTAG_EXCLFUNC:
global->excludedinit[ global->excluded++ ] = (char *)tags->data;
break;
case FPPTAG_WEBMODE:
global->webmode=(tags->data?1:0);
break;
case FPPTAG_ALLOW_INCLUDE_LOCAL:
global->allowincludelocal=(tags->data?1:0);
break;
case FPPTAG_FILEOPENFUNC:
global->openfile = (FILE* (*)(char *,char *,void *))tags->data;
break;
default:
fpp_cwarn(global, WARN_INTERNAL_ERROR, NULL);
break;
}
tags++;
}
return(0);
}
ReturnCode fpp_initdefines(struct Global *global)
{
/*
* Initialize the built-in #define's. There are two flavors:
* #define decus 1 (static definitions)
* #define __FILE__ ?? (dynamic, evaluated by magic)
* Called only on cpp startup.
*
* Note: the built-in static definitions are supressed by the -N option.
* __LINE__, __FILE__, __TIME__ and __DATE__ are always present.
*/
char **pp;
char *tp;
DEFBUF *dp;
struct tm *tm;
int i;
time_t tvec;
static char months[12][4] = {
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
};
/*
* Predefine the built-in symbols. Allow the
* implementor to pre-define a symbol as "" to
* eliminate it.
*/
if (!(global->nflag & NFLAG_BUILTIN)) {
for (pp = global->preset; *pp != NULL; pp++) {
if (*pp[0] != EOS) {
dp = fpp_defendel(global, *pp, FPP_FALSE);
if(!dp)
return(FPP_OUT_OF_MEMORY);
dp->repl = fpp_savestring(global, "1");
dp->nargs = DEF_NOARGS;
}
}
}
/*
* The magic pre-defines (__FILE__ and __LINE__ are
* initialized with negative argument counts. fpp_expand()
* notices this and calls the appropriate routine.
* DEF_NOARGS is one greater than the first "magic" definition.
*/
if (!(global->nflag & NFLAG_PREDEFINE)) {
for (pp = global->magic, i = DEF_NOARGS; *pp != NULL; pp++) {
dp = fpp_defendel(global, *pp, FPP_FALSE);
if(!dp)
return(FPP_OUT_OF_MEMORY);
dp->nargs = --i;
}
#if OK_DATE
/*
* Define __DATE__ as today's date.
*/
dp = fpp_defendel(global, "__DATE__", FPP_FALSE);
tp = malloc(32);
if(!tp || !dp)
return(FPP_OUT_OF_MEMORY);
dp->repl = tp;
dp->nargs = DEF_NOARGS;
time(&tvec);
tm = localtime(&tvec);
sprintf(tp, "\"%3s %2d %4d\"", /* "Aug 20 1988" */
months[tm->tm_mon],
tm->tm_mday,
tm->tm_year + 1900);
/*
* Define __TIME__ as this moment's time.
*/
dp = fpp_defendel(global, "__TIME__", FPP_FALSE);
tp = malloc(11);
if(!tp || !dp)
return(FPP_OUT_OF_MEMORY);
dp->repl = tp;
dp->nargs = DEF_NOARGS;
sprintf(tp, "\"%2d:%02d:%02d\"", /* "20:42:31" */
tm->tm_hour,
tm->tm_min,
tm->tm_sec);
#endif
}
return(FPP_OK);
}
void fpp_delbuiltindefines(struct Global *global)
{
/*
* Delete the built-in #define's.
*/
char **pp;
/*
* Delete the built-in symbols, unless -WW.
*/
if (global->wflag < 2) {
for (pp = global->preset; *pp != NULL; pp++) {
fpp_defendel(global, *pp, FPP_TRUE);
}
}
/*
* The magic pre-defines __FILE__ and __LINE__
*/
for (pp = global->magic; *pp != NULL; pp++) {
fpp_defendel(global, *pp, FPP_TRUE);
}
#if OK_DATE
/*
* Undefine __DATE__.
*/
fpp_defendel(global, "__DATE__", FPP_TRUE);
/*
* Undefine __TIME__.
*/
fpp_defendel(global, "__TIME__", FPP_TRUE);
#endif
return;
}
|
581d1efdfdd5e5d863e47f4234914d8388c289fd
|
7b92efd7dfb60d9b0a498871d5ffa699d0cf7d9e
|
/src/modules/gfx_ip.c
|
7fa0afc7a4de4cb506b2e1264ca5b80f8b61f286
|
[
"ISC"
] |
permissive
|
shinyblink/sled
|
854499be7c589b2d705050b41b8324ed66948e45
|
9d8e60ccbf6d8a30db83f41a8a4435d4c6b317a1
|
refs/heads/master
| 2023-07-24T08:30:03.348039
| 2023-07-08T14:00:54
| 2023-07-08T22:17:15
| 115,367,599
| 107
| 20
|
ISC
| 2023-07-08T22:17:17
| 2017-12-25T23:06:04
|
C
|
UTF-8
|
C
| false
| false
| 3,552
|
c
|
gfx_ip.c
|
// Module that shows the IP addresses of the system.
//
// Copyright (c) 2019, Adrian "vifino" Pistol <vifino@tty.sh>
//
// 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 <types.h>
#include <matrix.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <ifaddrs.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <block_for.h>
#include "text.h"
#define BLOCK_TIME 3 // Execute at most every three minutes
static text **lines = NULL;
static int linecount = 0;
static int columncount = 0;
static const char *ignored_interfaces;
static void reset_lines(void)
{
for(int i = 0; i < linecount; i++) {
text_free(&lines[i]);
lines[i] = NULL;
}
}
int init (int moduleno, char *argstr) {
if (matrix_gety() < 7)
return 1; // not enough Y to be usable
linecount = matrix_gety() / 8;
columncount = matrix_getx() / 3;
lines = calloc(linecount, sizeof(text *));
ignored_interfaces = getenv("SLED_IP_BLACKLIST");
if(ignored_interfaces == NULL)
ignored_interfaces = "lo";
return 0;
}
void reset(int _modno) {
char buff[INET6_ADDRSTRLEN];
char displaybuff[columncount];
buff[0] = 0;
reset_lines();
struct ifaddrs *ifap;
getifaddrs(&ifap);
int displayed_interface_count = 0;
int i = 0;
for(struct ifaddrs *curr = ifap; curr != NULL; curr = curr->ifa_next) {
const char *ignored = strstr(ignored_interfaces, curr->ifa_name);
if(ignored != NULL) {
size_t len = strlen(curr->ifa_name);
if(ignored[len] == 0 || ignored[len] == ',')
continue;
}
struct sockaddr_in *addr = (struct sockaddr_in *)curr->ifa_addr;
if(curr->ifa_addr && inet_ntop(curr->ifa_addr->sa_family, &(addr->sin_addr), buff, INET6_ADDRSTRLEN) != NULL) {
displayed_interface_count++;
snprintf(displaybuff, columncount, "%s", curr->ifa_name);
lines[i] = text_render(displaybuff);
i++;
if (i >= linecount) break;
snprintf(displaybuff, columncount, " %s", buff);
lines[i] = text_render(displaybuff);
i++;
if (i >= linecount) break;
}
}
freeifaddrs(ifap);
if (displayed_interface_count == 0){
block_for(1);
// block yourself for the next minute
// if interfaces come up, it might get unblocked
}
}
int draw(int _modno, int argc, char **argv) {
if (check_block()) return 1;
RGB black = RGB(0, 0, 0);
for(int y = 0; y < matrix_gety(); y++) {
for(int x = 0; x < matrix_getx(); x++) {
matrix_set(x, y, black);
}
}
for(int i = 0; i < linecount; i++) {
if(lines[i] == NULL)
continue;
for (int y = 0; y < matrix_gety() && y < 8; y++) {
for (int x = 0; x < matrix_getx(); x++) {
byte v = text_point(lines[i], x, y);
RGB color = RGB(v, v, v);
matrix_set(x, i * 8 + y, color);
}
}
}
matrix_render();
block_for(BLOCK_TIME);
return 0;
}
void deinit(int _modno) {
reset_lines();
free(lines);
lines = NULL;
}
|
c5f90cf946d385587ffe498f05e1d3fe8c13ed6c
|
9c4ec01e04f7b0a1d213e1060c6b0a008dde7cbd
|
/series0/rtc/rtc_lfxo/src/main.c
|
44023ba68336ed3d71496fdd359546e6c517e988
|
[
"Zlib"
] |
permissive
|
SiliconLabs/peripheral_examples
|
edf5ee87cd0bcb2e7ad5066e278fa1ad3b92bd35
|
87b252e5a1bf5b36a548c121e8ffda085d3bcbc4
|
refs/heads/master
| 2023-07-26T22:20:57.916375
| 2023-07-07T18:18:01
| 2023-07-07T18:20:16
| 116,865,771
| 326
| 212
|
NOASSERTION
| 2021-06-17T20:12:04
| 2018-01-09T20:13:39
|
C
|
UTF-8
|
C
| false
| false
| 4,112
|
c
|
main.c
|
/***************************************************************************//**
* @file main.c
* @brief This project demonstrates the use of the RTC. The real time clock is
* set to interrupt every 3 seconds and toggle LED1.
*******************************************************************************
* # License
* <b>Copyright 2020 Silicon Laboratories Inc. www.silabs.com</b>
*******************************************************************************
*
* SPDX-License-Identifier: Zlib
*
* The licensor of this software is Silicon Laboratories Inc.
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*
*******************************************************************************
* # Evaluation Quality
* This code has been minimally tested to ensure that it builds and is suitable
* as a demonstration for evaluation purposes only. This code will be maintained
* at the sole discretion of Silicon Labs.
******************************************************************************/
#include <stdio.h>
#include "em_device.h"
#include "em_chip.h"
#include "em_cmu.h"
#include "em_emu.h"
#include "em_rtc.h"
#include "em_gpio.h"
#include "bsp.h"
#define DELAY_SECONDS 3.0
#define LFXOFREQ 32768
#define COMPARE_TOP (DELAY_SECONDS * LFXOFREQ - 1)
/**************************************************************************//**
* @brief RTCC interrupt service routine
*****************************************************************************/
void RTC_IRQHandler(void)
{
//Reset counter
RTC_CounterReset();
// Clear the interrupt source
RTC_IntClear(RTC_IFC_COMP0);
// Toggle LED 0
GPIO_PinOutToggle(BSP_GPIO_LED0_PORT, BSP_GPIO_LED0_PIN);
}
/**************************************************************************//**
* @brief GPIO initialization
*****************************************************************************/
void initGPIO(void)
{
//Turn on the clock for the GPIO
CMU_ClockEnable(cmuClock_GPIO, true);
//Enable LED0
GPIO_PinModeSet(BSP_GPIO_LED0_PORT, BSP_GPIO_LED0_PIN, gpioModePushPull, 0);
}
/**************************************************************************//**
* @brief RTCC initialization
*****************************************************************************/
void rtcSetup(void)
{
// Enable the oscillator for the RTC
CMU_OscillatorEnable(cmuOsc_LFXO, true, true);
// Turn on the clock for Low Energy clocks
CMU_ClockEnable(cmuClock_HFLE, true);
CMU_ClockSelectSet(cmuClock_LFA, cmuSelect_LFXO);
// Turn on the RTC clock
CMU_ClockEnable(cmuClock_RTC, true);
// Set RTC compare value for RTC 0
RTC_CompareSet(0, COMPARE_TOP);
// Allow channel 0 to cause an interrupt
RTC_IntEnable(RTC_IEN_COMP0);
NVIC_ClearPendingIRQ(RTC_IRQn);
NVIC_EnableIRQ(RTC_IRQn);
// Configure the RTC settings
RTC_Init_TypeDef rtc = RTC_INIT_DEFAULT;
// Initialise RTC with pre-defined settings
RTC_Init(&rtc);
}
/**************************************************************************//**
* @brief Main function
*****************************************************************************/
int main(void)
{
// Chip errata
CHIP_Init();
// Initializations
initGPIO();
rtcSetup();
// Infinite loop
while(1)
{
EMU_EnterEM2(true);
}
}
|
d7dd438091e103e02ca58c366631d5c0d09a212f
|
99bdb3251fecee538e0630f15f6574054dfc1468
|
/bsp/apollo2/libraries/drivers/regs/am_reg_adc.h
|
90d3531f0f4e1fa67180d24151057d86f9295423
|
[
"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
| 46,750
|
h
|
am_reg_adc.h
|
//*****************************************************************************
//
// am_reg_adc.h
//! @file
//!
//! @brief Register macros for the ADC module
//
//*****************************************************************************
//*****************************************************************************
//
// Copyright (c) 2017, Ambiq Micro
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// 3. Neither the name of the copyright holder nor the names of its
// contributors may be used to endorse or promote products derived from this
// software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// This is part of revision 1.2.11 of the AmbiqSuite Development Package.
//
//*****************************************************************************
#ifndef AM_REG_ADC_H
#define AM_REG_ADC_H
//*****************************************************************************
//
// Instance finder. (1 instance(s) available)
//
//*****************************************************************************
#define AM_REG_ADC_NUM_MODULES 1
#define AM_REG_ADCn(n) \
(REG_ADC_BASEADDR + 0x00000000 * n)
//*****************************************************************************
//
// Register offsets.
//
//*****************************************************************************
#define AM_REG_ADC_CFG_O 0x00000000
#define AM_REG_ADC_STAT_O 0x00000004
#define AM_REG_ADC_SWT_O 0x00000008
#define AM_REG_ADC_SL0CFG_O 0x0000000C
#define AM_REG_ADC_SL1CFG_O 0x00000010
#define AM_REG_ADC_SL2CFG_O 0x00000014
#define AM_REG_ADC_SL3CFG_O 0x00000018
#define AM_REG_ADC_SL4CFG_O 0x0000001C
#define AM_REG_ADC_SL5CFG_O 0x00000020
#define AM_REG_ADC_SL6CFG_O 0x00000024
#define AM_REG_ADC_SL7CFG_O 0x00000028
#define AM_REG_ADC_WULIM_O 0x0000002C
#define AM_REG_ADC_WLLIM_O 0x00000030
#define AM_REG_ADC_FIFO_O 0x00000038
#define AM_REG_ADC_INTEN_O 0x00000200
#define AM_REG_ADC_INTSTAT_O 0x00000204
#define AM_REG_ADC_INTCLR_O 0x00000208
#define AM_REG_ADC_INTSET_O 0x0000020C
//*****************************************************************************
//
// ADC_INTEN - ADC Interrupt registers: Enable
//
//*****************************************************************************
// Window comparator voltage incursion interrupt.
#define AM_REG_ADC_INTEN_WCINC_S 5
#define AM_REG_ADC_INTEN_WCINC_M 0x00000020
#define AM_REG_ADC_INTEN_WCINC(n) (((uint32_t)(n) << 5) & 0x00000020)
#define AM_REG_ADC_INTEN_WCINC_WCINCINT 0x00000020
// Window comparator voltage excursion interrupt.
#define AM_REG_ADC_INTEN_WCEXC_S 4
#define AM_REG_ADC_INTEN_WCEXC_M 0x00000010
#define AM_REG_ADC_INTEN_WCEXC(n) (((uint32_t)(n) << 4) & 0x00000010)
#define AM_REG_ADC_INTEN_WCEXC_WCEXCINT 0x00000010
// FIFO 100 percent full interrupt.
#define AM_REG_ADC_INTEN_FIFOOVR2_S 3
#define AM_REG_ADC_INTEN_FIFOOVR2_M 0x00000008
#define AM_REG_ADC_INTEN_FIFOOVR2(n) (((uint32_t)(n) << 3) & 0x00000008)
#define AM_REG_ADC_INTEN_FIFOOVR2_FIFOFULLINT 0x00000008
// FIFO 75 percent full interrupt.
#define AM_REG_ADC_INTEN_FIFOOVR1_S 2
#define AM_REG_ADC_INTEN_FIFOOVR1_M 0x00000004
#define AM_REG_ADC_INTEN_FIFOOVR1(n) (((uint32_t)(n) << 2) & 0x00000004)
#define AM_REG_ADC_INTEN_FIFOOVR1_FIFO75INT 0x00000004
// ADC scan complete interrupt.
#define AM_REG_ADC_INTEN_SCNCMP_S 1
#define AM_REG_ADC_INTEN_SCNCMP_M 0x00000002
#define AM_REG_ADC_INTEN_SCNCMP(n) (((uint32_t)(n) << 1) & 0x00000002)
#define AM_REG_ADC_INTEN_SCNCMP_SCNCMPINT 0x00000002
// ADC conversion complete interrupt.
#define AM_REG_ADC_INTEN_CNVCMP_S 0
#define AM_REG_ADC_INTEN_CNVCMP_M 0x00000001
#define AM_REG_ADC_INTEN_CNVCMP(n) (((uint32_t)(n) << 0) & 0x00000001)
#define AM_REG_ADC_INTEN_CNVCMP_CNVCMPINT 0x00000001
//*****************************************************************************
//
// ADC_INTSTAT - ADC Interrupt registers: Status
//
//*****************************************************************************
// Window comparator voltage incursion interrupt.
#define AM_REG_ADC_INTSTAT_WCINC_S 5
#define AM_REG_ADC_INTSTAT_WCINC_M 0x00000020
#define AM_REG_ADC_INTSTAT_WCINC(n) (((uint32_t)(n) << 5) & 0x00000020)
#define AM_REG_ADC_INTSTAT_WCINC_WCINCINT 0x00000020
// Window comparator voltage excursion interrupt.
#define AM_REG_ADC_INTSTAT_WCEXC_S 4
#define AM_REG_ADC_INTSTAT_WCEXC_M 0x00000010
#define AM_REG_ADC_INTSTAT_WCEXC(n) (((uint32_t)(n) << 4) & 0x00000010)
#define AM_REG_ADC_INTSTAT_WCEXC_WCEXCINT 0x00000010
// FIFO 100 percent full interrupt.
#define AM_REG_ADC_INTSTAT_FIFOOVR2_S 3
#define AM_REG_ADC_INTSTAT_FIFOOVR2_M 0x00000008
#define AM_REG_ADC_INTSTAT_FIFOOVR2(n) (((uint32_t)(n) << 3) & 0x00000008)
#define AM_REG_ADC_INTSTAT_FIFOOVR2_FIFOFULLINT 0x00000008
// FIFO 75 percent full interrupt.
#define AM_REG_ADC_INTSTAT_FIFOOVR1_S 2
#define AM_REG_ADC_INTSTAT_FIFOOVR1_M 0x00000004
#define AM_REG_ADC_INTSTAT_FIFOOVR1(n) (((uint32_t)(n) << 2) & 0x00000004)
#define AM_REG_ADC_INTSTAT_FIFOOVR1_FIFO75INT 0x00000004
// ADC scan complete interrupt.
#define AM_REG_ADC_INTSTAT_SCNCMP_S 1
#define AM_REG_ADC_INTSTAT_SCNCMP_M 0x00000002
#define AM_REG_ADC_INTSTAT_SCNCMP(n) (((uint32_t)(n) << 1) & 0x00000002)
#define AM_REG_ADC_INTSTAT_SCNCMP_SCNCMPINT 0x00000002
// ADC conversion complete interrupt.
#define AM_REG_ADC_INTSTAT_CNVCMP_S 0
#define AM_REG_ADC_INTSTAT_CNVCMP_M 0x00000001
#define AM_REG_ADC_INTSTAT_CNVCMP(n) (((uint32_t)(n) << 0) & 0x00000001)
#define AM_REG_ADC_INTSTAT_CNVCMP_CNVCMPINT 0x00000001
//*****************************************************************************
//
// ADC_INTCLR - ADC Interrupt registers: Clear
//
//*****************************************************************************
// Window comparator voltage incursion interrupt.
#define AM_REG_ADC_INTCLR_WCINC_S 5
#define AM_REG_ADC_INTCLR_WCINC_M 0x00000020
#define AM_REG_ADC_INTCLR_WCINC(n) (((uint32_t)(n) << 5) & 0x00000020)
#define AM_REG_ADC_INTCLR_WCINC_WCINCINT 0x00000020
// Window comparator voltage excursion interrupt.
#define AM_REG_ADC_INTCLR_WCEXC_S 4
#define AM_REG_ADC_INTCLR_WCEXC_M 0x00000010
#define AM_REG_ADC_INTCLR_WCEXC(n) (((uint32_t)(n) << 4) & 0x00000010)
#define AM_REG_ADC_INTCLR_WCEXC_WCEXCINT 0x00000010
// FIFO 100 percent full interrupt.
#define AM_REG_ADC_INTCLR_FIFOOVR2_S 3
#define AM_REG_ADC_INTCLR_FIFOOVR2_M 0x00000008
#define AM_REG_ADC_INTCLR_FIFOOVR2(n) (((uint32_t)(n) << 3) & 0x00000008)
#define AM_REG_ADC_INTCLR_FIFOOVR2_FIFOFULLINT 0x00000008
// FIFO 75 percent full interrupt.
#define AM_REG_ADC_INTCLR_FIFOOVR1_S 2
#define AM_REG_ADC_INTCLR_FIFOOVR1_M 0x00000004
#define AM_REG_ADC_INTCLR_FIFOOVR1(n) (((uint32_t)(n) << 2) & 0x00000004)
#define AM_REG_ADC_INTCLR_FIFOOVR1_FIFO75INT 0x00000004
// ADC scan complete interrupt.
#define AM_REG_ADC_INTCLR_SCNCMP_S 1
#define AM_REG_ADC_INTCLR_SCNCMP_M 0x00000002
#define AM_REG_ADC_INTCLR_SCNCMP(n) (((uint32_t)(n) << 1) & 0x00000002)
#define AM_REG_ADC_INTCLR_SCNCMP_SCNCMPINT 0x00000002
// ADC conversion complete interrupt.
#define AM_REG_ADC_INTCLR_CNVCMP_S 0
#define AM_REG_ADC_INTCLR_CNVCMP_M 0x00000001
#define AM_REG_ADC_INTCLR_CNVCMP(n) (((uint32_t)(n) << 0) & 0x00000001)
#define AM_REG_ADC_INTCLR_CNVCMP_CNVCMPINT 0x00000001
//*****************************************************************************
//
// ADC_INTSET - ADC Interrupt registers: Set
//
//*****************************************************************************
// Window comparator voltage incursion interrupt.
#define AM_REG_ADC_INTSET_WCINC_S 5
#define AM_REG_ADC_INTSET_WCINC_M 0x00000020
#define AM_REG_ADC_INTSET_WCINC(n) (((uint32_t)(n) << 5) & 0x00000020)
#define AM_REG_ADC_INTSET_WCINC_WCINCINT 0x00000020
// Window comparator voltage excursion interrupt.
#define AM_REG_ADC_INTSET_WCEXC_S 4
#define AM_REG_ADC_INTSET_WCEXC_M 0x00000010
#define AM_REG_ADC_INTSET_WCEXC(n) (((uint32_t)(n) << 4) & 0x00000010)
#define AM_REG_ADC_INTSET_WCEXC_WCEXCINT 0x00000010
// FIFO 100 percent full interrupt.
#define AM_REG_ADC_INTSET_FIFOOVR2_S 3
#define AM_REG_ADC_INTSET_FIFOOVR2_M 0x00000008
#define AM_REG_ADC_INTSET_FIFOOVR2(n) (((uint32_t)(n) << 3) & 0x00000008)
#define AM_REG_ADC_INTSET_FIFOOVR2_FIFOFULLINT 0x00000008
// FIFO 75 percent full interrupt.
#define AM_REG_ADC_INTSET_FIFOOVR1_S 2
#define AM_REG_ADC_INTSET_FIFOOVR1_M 0x00000004
#define AM_REG_ADC_INTSET_FIFOOVR1(n) (((uint32_t)(n) << 2) & 0x00000004)
#define AM_REG_ADC_INTSET_FIFOOVR1_FIFO75INT 0x00000004
// ADC scan complete interrupt.
#define AM_REG_ADC_INTSET_SCNCMP_S 1
#define AM_REG_ADC_INTSET_SCNCMP_M 0x00000002
#define AM_REG_ADC_INTSET_SCNCMP(n) (((uint32_t)(n) << 1) & 0x00000002)
#define AM_REG_ADC_INTSET_SCNCMP_SCNCMPINT 0x00000002
// ADC conversion complete interrupt.
#define AM_REG_ADC_INTSET_CNVCMP_S 0
#define AM_REG_ADC_INTSET_CNVCMP_M 0x00000001
#define AM_REG_ADC_INTSET_CNVCMP(n) (((uint32_t)(n) << 0) & 0x00000001)
#define AM_REG_ADC_INTSET_CNVCMP_CNVCMPINT 0x00000001
//*****************************************************************************
//
// ADC_CFG - Configuration Register
//
//*****************************************************************************
// Select the source and frequency for the ADC clock. All values not enumerated
// below are undefined.
#define AM_REG_ADC_CFG_CLKSEL_S 24
#define AM_REG_ADC_CFG_CLKSEL_M 0x03000000
#define AM_REG_ADC_CFG_CLKSEL(n) (((uint32_t)(n) << 24) & 0x03000000)
#define AM_REG_ADC_CFG_CLKSEL_OFF 0x00000000
#define AM_REG_ADC_CFG_CLKSEL_HFRC 0x01000000
#define AM_REG_ADC_CFG_CLKSEL_HFRC_DIV2 0x02000000
// This bit selects the ADC trigger polarity for external off chip triggers.
#define AM_REG_ADC_CFG_TRIGPOL_S 19
#define AM_REG_ADC_CFG_TRIGPOL_M 0x00080000
#define AM_REG_ADC_CFG_TRIGPOL(n) (((uint32_t)(n) << 19) & 0x00080000)
#define AM_REG_ADC_CFG_TRIGPOL_RISING_EDGE 0x00000000
#define AM_REG_ADC_CFG_TRIGPOL_FALLING_EDGE 0x00080000
// Select the ADC trigger source.
#define AM_REG_ADC_CFG_TRIGSEL_S 16
#define AM_REG_ADC_CFG_TRIGSEL_M 0x00070000
#define AM_REG_ADC_CFG_TRIGSEL(n) (((uint32_t)(n) << 16) & 0x00070000)
#define AM_REG_ADC_CFG_TRIGSEL_EXT0 0x00000000
#define AM_REG_ADC_CFG_TRIGSEL_EXT1 0x00010000
#define AM_REG_ADC_CFG_TRIGSEL_EXT2 0x00020000
#define AM_REG_ADC_CFG_TRIGSEL_EXT3 0x00030000
#define AM_REG_ADC_CFG_TRIGSEL_VCOMP 0x00040000
#define AM_REG_ADC_CFG_TRIGSEL_SWT 0x00070000
// Select the ADC reference voltage.
#define AM_REG_ADC_CFG_REFSEL_S 8
#define AM_REG_ADC_CFG_REFSEL_M 0x00000300
#define AM_REG_ADC_CFG_REFSEL(n) (((uint32_t)(n) << 8) & 0x00000300)
#define AM_REG_ADC_CFG_REFSEL_INT2P0 0x00000000
#define AM_REG_ADC_CFG_REFSEL_INT1P5 0x00000100
#define AM_REG_ADC_CFG_REFSEL_EXT2P0 0x00000200
#define AM_REG_ADC_CFG_REFSEL_EXT1P5 0x00000300
// Clock mode register
#define AM_REG_ADC_CFG_CKMODE_S 4
#define AM_REG_ADC_CFG_CKMODE_M 0x00000010
#define AM_REG_ADC_CFG_CKMODE(n) (((uint32_t)(n) << 4) & 0x00000010)
#define AM_REG_ADC_CFG_CKMODE_LPCKMODE 0x00000000
#define AM_REG_ADC_CFG_CKMODE_LLCKMODE 0x00000010
// Select power mode to enter between active scans.
#define AM_REG_ADC_CFG_LPMODE_S 3
#define AM_REG_ADC_CFG_LPMODE_M 0x00000008
#define AM_REG_ADC_CFG_LPMODE(n) (((uint32_t)(n) << 3) & 0x00000008)
#define AM_REG_ADC_CFG_LPMODE_MODE0 0x00000000
#define AM_REG_ADC_CFG_LPMODE_MODE1 0x00000008
// This bit enables Repeating Scan Mode.
#define AM_REG_ADC_CFG_RPTEN_S 2
#define AM_REG_ADC_CFG_RPTEN_M 0x00000004
#define AM_REG_ADC_CFG_RPTEN(n) (((uint32_t)(n) << 2) & 0x00000004)
#define AM_REG_ADC_CFG_RPTEN_SINGLE_SCAN 0x00000000
#define AM_REG_ADC_CFG_RPTEN_REPEATING_SCAN 0x00000004
// This bit enables the ADC module. While the ADC is enabled, the ADCCFG and
// SLOT Configuration regsiter settings must remain stable and unchanged. All
// configuration register settings, slot configuration settings and window
// comparison settings should be written prior to setting the ADCEN bit to '1'.
#define AM_REG_ADC_CFG_ADCEN_S 0
#define AM_REG_ADC_CFG_ADCEN_M 0x00000001
#define AM_REG_ADC_CFG_ADCEN(n) (((uint32_t)(n) << 0) & 0x00000001)
#define AM_REG_ADC_CFG_ADCEN_DIS 0x00000000
#define AM_REG_ADC_CFG_ADCEN_EN 0x00000001
//*****************************************************************************
//
// ADC_STAT - ADC Power Status
//
//*****************************************************************************
// Indicates the power-status of the ADC.
#define AM_REG_ADC_STAT_PWDSTAT_S 0
#define AM_REG_ADC_STAT_PWDSTAT_M 0x00000001
#define AM_REG_ADC_STAT_PWDSTAT(n) (((uint32_t)(n) << 0) & 0x00000001)
#define AM_REG_ADC_STAT_PWDSTAT_ON 0x00000000
#define AM_REG_ADC_STAT_PWDSTAT_POWERED_DOWN 0x00000001
//*****************************************************************************
//
// ADC_SWT - Software trigger
//
//*****************************************************************************
// Writing 0x37 to this register generates a software trigger.
#define AM_REG_ADC_SWT_SWT_S 0
#define AM_REG_ADC_SWT_SWT_M 0x000000FF
#define AM_REG_ADC_SWT_SWT(n) (((uint32_t)(n) << 0) & 0x000000FF)
#define AM_REG_ADC_SWT_SWT_GEN_SW_TRIGGER 0x00000037
//*****************************************************************************
//
// ADC_SL0CFG - Slot 0 Configuration Register
//
//*****************************************************************************
// Select the number of measurements to average in the accumulate divide module
// for this slot.
#define AM_REG_ADC_SL0CFG_ADSEL0_S 24
#define AM_REG_ADC_SL0CFG_ADSEL0_M 0x07000000
#define AM_REG_ADC_SL0CFG_ADSEL0(n) (((uint32_t)(n) << 24) & 0x07000000)
#define AM_REG_ADC_SL0CFG_ADSEL0_AVG_1_MSRMT 0x00000000
#define AM_REG_ADC_SL0CFG_ADSEL0_AVG_2_MSRMTS 0x01000000
#define AM_REG_ADC_SL0CFG_ADSEL0_AVG_4_MSRMTS 0x02000000
#define AM_REG_ADC_SL0CFG_ADSEL0_AVG_8_MSRMT 0x03000000
#define AM_REG_ADC_SL0CFG_ADSEL0_AVG_16_MSRMTS 0x04000000
#define AM_REG_ADC_SL0CFG_ADSEL0_AVG_32_MSRMTS 0x05000000
#define AM_REG_ADC_SL0CFG_ADSEL0_AVG_64_MSRMTS 0x06000000
#define AM_REG_ADC_SL0CFG_ADSEL0_AVG_128_MSRMTS 0x07000000
// Set the Precision Mode For Slot.
#define AM_REG_ADC_SL0CFG_PRMODE0_S 16
#define AM_REG_ADC_SL0CFG_PRMODE0_M 0x00030000
#define AM_REG_ADC_SL0CFG_PRMODE0(n) (((uint32_t)(n) << 16) & 0x00030000)
#define AM_REG_ADC_SL0CFG_PRMODE0_P14B 0x00000000
#define AM_REG_ADC_SL0CFG_PRMODE0_P12B 0x00010000
#define AM_REG_ADC_SL0CFG_PRMODE0_P10B 0x00020000
#define AM_REG_ADC_SL0CFG_PRMODE0_P8B 0x00030000
// Select one of the 14 channel inputs for this slot.
#define AM_REG_ADC_SL0CFG_CHSEL0_S 8
#define AM_REG_ADC_SL0CFG_CHSEL0_M 0x00000F00
#define AM_REG_ADC_SL0CFG_CHSEL0(n) (((uint32_t)(n) << 8) & 0x00000F00)
#define AM_REG_ADC_SL0CFG_CHSEL0_SE0 0x00000000
#define AM_REG_ADC_SL0CFG_CHSEL0_SE1 0x00000100
#define AM_REG_ADC_SL0CFG_CHSEL0_SE2 0x00000200
#define AM_REG_ADC_SL0CFG_CHSEL0_SE3 0x00000300
#define AM_REG_ADC_SL0CFG_CHSEL0_SE4 0x00000400
#define AM_REG_ADC_SL0CFG_CHSEL0_SE5 0x00000500
#define AM_REG_ADC_SL0CFG_CHSEL0_SE6 0x00000600
#define AM_REG_ADC_SL0CFG_CHSEL0_SE7 0x00000700
#define AM_REG_ADC_SL0CFG_CHSEL0_SE8 0x00000800
#define AM_REG_ADC_SL0CFG_CHSEL0_SE9 0x00000900
#define AM_REG_ADC_SL0CFG_CHSEL0_DF0 0x00000A00
#define AM_REG_ADC_SL0CFG_CHSEL0_DF1 0x00000B00
#define AM_REG_ADC_SL0CFG_CHSEL0_TEMP 0x00000C00
#define AM_REG_ADC_SL0CFG_CHSEL0_BATT 0x00000D00
#define AM_REG_ADC_SL0CFG_CHSEL0_VSS 0x00000E00
// This bit enables the window compare function for slot 0.
#define AM_REG_ADC_SL0CFG_WCEN0_S 1
#define AM_REG_ADC_SL0CFG_WCEN0_M 0x00000002
#define AM_REG_ADC_SL0CFG_WCEN0(n) (((uint32_t)(n) << 1) & 0x00000002)
#define AM_REG_ADC_SL0CFG_WCEN0_WCEN 0x00000002
// This bit enables slot 0 for ADC conversions.
#define AM_REG_ADC_SL0CFG_SLEN0_S 0
#define AM_REG_ADC_SL0CFG_SLEN0_M 0x00000001
#define AM_REG_ADC_SL0CFG_SLEN0(n) (((uint32_t)(n) << 0) & 0x00000001)
#define AM_REG_ADC_SL0CFG_SLEN0_SLEN 0x00000001
//*****************************************************************************
//
// ADC_SL1CFG - Slot 1 Configuration Register
//
//*****************************************************************************
// Select the number of measurements to average in the accumulate divide module
// for this slot.
#define AM_REG_ADC_SL1CFG_ADSEL1_S 24
#define AM_REG_ADC_SL1CFG_ADSEL1_M 0x07000000
#define AM_REG_ADC_SL1CFG_ADSEL1(n) (((uint32_t)(n) << 24) & 0x07000000)
#define AM_REG_ADC_SL1CFG_ADSEL1_AVG_1_MSRMT 0x00000000
#define AM_REG_ADC_SL1CFG_ADSEL1_AVG_2_MSRMTS 0x01000000
#define AM_REG_ADC_SL1CFG_ADSEL1_AVG_4_MSRMTS 0x02000000
#define AM_REG_ADC_SL1CFG_ADSEL1_AVG_8_MSRMT 0x03000000
#define AM_REG_ADC_SL1CFG_ADSEL1_AVG_16_MSRMTS 0x04000000
#define AM_REG_ADC_SL1CFG_ADSEL1_AVG_32_MSRMTS 0x05000000
#define AM_REG_ADC_SL1CFG_ADSEL1_AVG_64_MSRMTS 0x06000000
#define AM_REG_ADC_SL1CFG_ADSEL1_AVG_128_MSRMTS 0x07000000
// Set the Precision Mode For Slot.
#define AM_REG_ADC_SL1CFG_PRMODE1_S 16
#define AM_REG_ADC_SL1CFG_PRMODE1_M 0x00030000
#define AM_REG_ADC_SL1CFG_PRMODE1(n) (((uint32_t)(n) << 16) & 0x00030000)
#define AM_REG_ADC_SL1CFG_PRMODE1_P14B 0x00000000
#define AM_REG_ADC_SL1CFG_PRMODE1_P12B 0x00010000
#define AM_REG_ADC_SL1CFG_PRMODE1_P10B 0x00020000
#define AM_REG_ADC_SL1CFG_PRMODE1_P8B 0x00030000
// Select one of the 14 channel inputs for this slot.
#define AM_REG_ADC_SL1CFG_CHSEL1_S 8
#define AM_REG_ADC_SL1CFG_CHSEL1_M 0x00000F00
#define AM_REG_ADC_SL1CFG_CHSEL1(n) (((uint32_t)(n) << 8) & 0x00000F00)
#define AM_REG_ADC_SL1CFG_CHSEL1_SE0 0x00000000
#define AM_REG_ADC_SL1CFG_CHSEL1_SE1 0x00000100
#define AM_REG_ADC_SL1CFG_CHSEL1_SE2 0x00000200
#define AM_REG_ADC_SL1CFG_CHSEL1_SE3 0x00000300
#define AM_REG_ADC_SL1CFG_CHSEL1_SE4 0x00000400
#define AM_REG_ADC_SL1CFG_CHSEL1_SE5 0x00000500
#define AM_REG_ADC_SL1CFG_CHSEL1_SE6 0x00000600
#define AM_REG_ADC_SL1CFG_CHSEL1_SE7 0x00000700
#define AM_REG_ADC_SL1CFG_CHSEL1_SE8 0x00000800
#define AM_REG_ADC_SL1CFG_CHSEL1_SE9 0x00000900
#define AM_REG_ADC_SL1CFG_CHSEL1_DF0 0x00000A00
#define AM_REG_ADC_SL1CFG_CHSEL1_DF1 0x00000B00
#define AM_REG_ADC_SL1CFG_CHSEL1_TEMP 0x00000C00
#define AM_REG_ADC_SL1CFG_CHSEL1_BATT 0x00000D00
#define AM_REG_ADC_SL1CFG_CHSEL1_VSS 0x00000E00
// This bit enables the window compare function for slot 1.
#define AM_REG_ADC_SL1CFG_WCEN1_S 1
#define AM_REG_ADC_SL1CFG_WCEN1_M 0x00000002
#define AM_REG_ADC_SL1CFG_WCEN1(n) (((uint32_t)(n) << 1) & 0x00000002)
#define AM_REG_ADC_SL1CFG_WCEN1_WCEN 0x00000002
// This bit enables slot 1 for ADC conversions.
#define AM_REG_ADC_SL1CFG_SLEN1_S 0
#define AM_REG_ADC_SL1CFG_SLEN1_M 0x00000001
#define AM_REG_ADC_SL1CFG_SLEN1(n) (((uint32_t)(n) << 0) & 0x00000001)
#define AM_REG_ADC_SL1CFG_SLEN1_SLEN 0x00000001
//*****************************************************************************
//
// ADC_SL2CFG - Slot 2 Configuration Register
//
//*****************************************************************************
// Select the number of measurements to average in the accumulate divide module
// for this slot.
#define AM_REG_ADC_SL2CFG_ADSEL2_S 24
#define AM_REG_ADC_SL2CFG_ADSEL2_M 0x07000000
#define AM_REG_ADC_SL2CFG_ADSEL2(n) (((uint32_t)(n) << 24) & 0x07000000)
#define AM_REG_ADC_SL2CFG_ADSEL2_AVG_1_MSRMT 0x00000000
#define AM_REG_ADC_SL2CFG_ADSEL2_AVG_2_MSRMTS 0x01000000
#define AM_REG_ADC_SL2CFG_ADSEL2_AVG_4_MSRMTS 0x02000000
#define AM_REG_ADC_SL2CFG_ADSEL2_AVG_8_MSRMT 0x03000000
#define AM_REG_ADC_SL2CFG_ADSEL2_AVG_16_MSRMTS 0x04000000
#define AM_REG_ADC_SL2CFG_ADSEL2_AVG_32_MSRMTS 0x05000000
#define AM_REG_ADC_SL2CFG_ADSEL2_AVG_64_MSRMTS 0x06000000
#define AM_REG_ADC_SL2CFG_ADSEL2_AVG_128_MSRMTS 0x07000000
// Set the Precision Mode For Slot.
#define AM_REG_ADC_SL2CFG_PRMODE2_S 16
#define AM_REG_ADC_SL2CFG_PRMODE2_M 0x00030000
#define AM_REG_ADC_SL2CFG_PRMODE2(n) (((uint32_t)(n) << 16) & 0x00030000)
#define AM_REG_ADC_SL2CFG_PRMODE2_P14B 0x00000000
#define AM_REG_ADC_SL2CFG_PRMODE2_P12B 0x00010000
#define AM_REG_ADC_SL2CFG_PRMODE2_P10B 0x00020000
#define AM_REG_ADC_SL2CFG_PRMODE2_P8B 0x00030000
// Select one of the 14 channel inputs for this slot.
#define AM_REG_ADC_SL2CFG_CHSEL2_S 8
#define AM_REG_ADC_SL2CFG_CHSEL2_M 0x00000F00
#define AM_REG_ADC_SL2CFG_CHSEL2(n) (((uint32_t)(n) << 8) & 0x00000F00)
#define AM_REG_ADC_SL2CFG_CHSEL2_SE0 0x00000000
#define AM_REG_ADC_SL2CFG_CHSEL2_SE1 0x00000100
#define AM_REG_ADC_SL2CFG_CHSEL2_SE2 0x00000200
#define AM_REG_ADC_SL2CFG_CHSEL2_SE3 0x00000300
#define AM_REG_ADC_SL2CFG_CHSEL2_SE4 0x00000400
#define AM_REG_ADC_SL2CFG_CHSEL2_SE5 0x00000500
#define AM_REG_ADC_SL2CFG_CHSEL2_SE6 0x00000600
#define AM_REG_ADC_SL2CFG_CHSEL2_SE7 0x00000700
#define AM_REG_ADC_SL2CFG_CHSEL2_SE8 0x00000800
#define AM_REG_ADC_SL2CFG_CHSEL2_SE9 0x00000900
#define AM_REG_ADC_SL2CFG_CHSEL2_DF0 0x00000A00
#define AM_REG_ADC_SL2CFG_CHSEL2_DF1 0x00000B00
#define AM_REG_ADC_SL2CFG_CHSEL2_TEMP 0x00000C00
#define AM_REG_ADC_SL2CFG_CHSEL2_BATT 0x00000D00
#define AM_REG_ADC_SL2CFG_CHSEL2_VSS 0x00000E00
// This bit enables the window compare function for slot 2.
#define AM_REG_ADC_SL2CFG_WCEN2_S 1
#define AM_REG_ADC_SL2CFG_WCEN2_M 0x00000002
#define AM_REG_ADC_SL2CFG_WCEN2(n) (((uint32_t)(n) << 1) & 0x00000002)
#define AM_REG_ADC_SL2CFG_WCEN2_WCEN 0x00000002
// This bit enables slot 2 for ADC conversions.
#define AM_REG_ADC_SL2CFG_SLEN2_S 0
#define AM_REG_ADC_SL2CFG_SLEN2_M 0x00000001
#define AM_REG_ADC_SL2CFG_SLEN2(n) (((uint32_t)(n) << 0) & 0x00000001)
#define AM_REG_ADC_SL2CFG_SLEN2_SLEN 0x00000001
//*****************************************************************************
//
// ADC_SL3CFG - Slot 3 Configuration Register
//
//*****************************************************************************
// Select the number of measurements to average in the accumulate divide module
// for this slot.
#define AM_REG_ADC_SL3CFG_ADSEL3_S 24
#define AM_REG_ADC_SL3CFG_ADSEL3_M 0x07000000
#define AM_REG_ADC_SL3CFG_ADSEL3(n) (((uint32_t)(n) << 24) & 0x07000000)
#define AM_REG_ADC_SL3CFG_ADSEL3_AVG_1_MSRMT 0x00000000
#define AM_REG_ADC_SL3CFG_ADSEL3_AVG_2_MSRMTS 0x01000000
#define AM_REG_ADC_SL3CFG_ADSEL3_AVG_4_MSRMTS 0x02000000
#define AM_REG_ADC_SL3CFG_ADSEL3_AVG_8_MSRMT 0x03000000
#define AM_REG_ADC_SL3CFG_ADSEL3_AVG_16_MSRMTS 0x04000000
#define AM_REG_ADC_SL3CFG_ADSEL3_AVG_32_MSRMTS 0x05000000
#define AM_REG_ADC_SL3CFG_ADSEL3_AVG_64_MSRMTS 0x06000000
#define AM_REG_ADC_SL3CFG_ADSEL3_AVG_128_MSRMTS 0x07000000
// Set the Precision Mode For Slot.
#define AM_REG_ADC_SL3CFG_PRMODE3_S 16
#define AM_REG_ADC_SL3CFG_PRMODE3_M 0x00030000
#define AM_REG_ADC_SL3CFG_PRMODE3(n) (((uint32_t)(n) << 16) & 0x00030000)
#define AM_REG_ADC_SL3CFG_PRMODE3_P14B 0x00000000
#define AM_REG_ADC_SL3CFG_PRMODE3_P12B 0x00010000
#define AM_REG_ADC_SL3CFG_PRMODE3_P10B 0x00020000
#define AM_REG_ADC_SL3CFG_PRMODE3_P8B 0x00030000
// Select one of the 14 channel inputs for this slot.
#define AM_REG_ADC_SL3CFG_CHSEL3_S 8
#define AM_REG_ADC_SL3CFG_CHSEL3_M 0x00000F00
#define AM_REG_ADC_SL3CFG_CHSEL3(n) (((uint32_t)(n) << 8) & 0x00000F00)
#define AM_REG_ADC_SL3CFG_CHSEL3_SE0 0x00000000
#define AM_REG_ADC_SL3CFG_CHSEL3_SE1 0x00000100
#define AM_REG_ADC_SL3CFG_CHSEL3_SE2 0x00000200
#define AM_REG_ADC_SL3CFG_CHSEL3_SE3 0x00000300
#define AM_REG_ADC_SL3CFG_CHSEL3_SE4 0x00000400
#define AM_REG_ADC_SL3CFG_CHSEL3_SE5 0x00000500
#define AM_REG_ADC_SL3CFG_CHSEL3_SE6 0x00000600
#define AM_REG_ADC_SL3CFG_CHSEL3_SE7 0x00000700
#define AM_REG_ADC_SL3CFG_CHSEL3_SE8 0x00000800
#define AM_REG_ADC_SL3CFG_CHSEL3_SE9 0x00000900
#define AM_REG_ADC_SL3CFG_CHSEL3_DF0 0x00000A00
#define AM_REG_ADC_SL3CFG_CHSEL3_DF1 0x00000B00
#define AM_REG_ADC_SL3CFG_CHSEL3_TEMP 0x00000C00
#define AM_REG_ADC_SL3CFG_CHSEL3_BATT 0x00000D00
#define AM_REG_ADC_SL3CFG_CHSEL3_VSS 0x00000E00
// This bit enables the window compare function for slot 3.
#define AM_REG_ADC_SL3CFG_WCEN3_S 1
#define AM_REG_ADC_SL3CFG_WCEN3_M 0x00000002
#define AM_REG_ADC_SL3CFG_WCEN3(n) (((uint32_t)(n) << 1) & 0x00000002)
#define AM_REG_ADC_SL3CFG_WCEN3_WCEN 0x00000002
// This bit enables slot 3 for ADC conversions.
#define AM_REG_ADC_SL3CFG_SLEN3_S 0
#define AM_REG_ADC_SL3CFG_SLEN3_M 0x00000001
#define AM_REG_ADC_SL3CFG_SLEN3(n) (((uint32_t)(n) << 0) & 0x00000001)
#define AM_REG_ADC_SL3CFG_SLEN3_SLEN 0x00000001
//*****************************************************************************
//
// ADC_SL4CFG - Slot 4 Configuration Register
//
//*****************************************************************************
// Select the number of measurements to average in the accumulate divide module
// for this slot.
#define AM_REG_ADC_SL4CFG_ADSEL4_S 24
#define AM_REG_ADC_SL4CFG_ADSEL4_M 0x07000000
#define AM_REG_ADC_SL4CFG_ADSEL4(n) (((uint32_t)(n) << 24) & 0x07000000)
#define AM_REG_ADC_SL4CFG_ADSEL4_AVG_1_MSRMT 0x00000000
#define AM_REG_ADC_SL4CFG_ADSEL4_AVG_2_MSRMTS 0x01000000
#define AM_REG_ADC_SL4CFG_ADSEL4_AVG_4_MSRMTS 0x02000000
#define AM_REG_ADC_SL4CFG_ADSEL4_AVG_8_MSRMT 0x03000000
#define AM_REG_ADC_SL4CFG_ADSEL4_AVG_16_MSRMTS 0x04000000
#define AM_REG_ADC_SL4CFG_ADSEL4_AVG_32_MSRMTS 0x05000000
#define AM_REG_ADC_SL4CFG_ADSEL4_AVG_64_MSRMTS 0x06000000
#define AM_REG_ADC_SL4CFG_ADSEL4_AVG_128_MSRMTS 0x07000000
// Set the Precision Mode For Slot.
#define AM_REG_ADC_SL4CFG_PRMODE4_S 16
#define AM_REG_ADC_SL4CFG_PRMODE4_M 0x00030000
#define AM_REG_ADC_SL4CFG_PRMODE4(n) (((uint32_t)(n) << 16) & 0x00030000)
#define AM_REG_ADC_SL4CFG_PRMODE4_P14B 0x00000000
#define AM_REG_ADC_SL4CFG_PRMODE4_P12B 0x00010000
#define AM_REG_ADC_SL4CFG_PRMODE4_P10B 0x00020000
#define AM_REG_ADC_SL4CFG_PRMODE4_P8B 0x00030000
// Select one of the 14 channel inputs for this slot.
#define AM_REG_ADC_SL4CFG_CHSEL4_S 8
#define AM_REG_ADC_SL4CFG_CHSEL4_M 0x00000F00
#define AM_REG_ADC_SL4CFG_CHSEL4(n) (((uint32_t)(n) << 8) & 0x00000F00)
#define AM_REG_ADC_SL4CFG_CHSEL4_SE0 0x00000000
#define AM_REG_ADC_SL4CFG_CHSEL4_SE1 0x00000100
#define AM_REG_ADC_SL4CFG_CHSEL4_SE2 0x00000200
#define AM_REG_ADC_SL4CFG_CHSEL4_SE3 0x00000300
#define AM_REG_ADC_SL4CFG_CHSEL4_SE4 0x00000400
#define AM_REG_ADC_SL4CFG_CHSEL4_SE5 0x00000500
#define AM_REG_ADC_SL4CFG_CHSEL4_SE6 0x00000600
#define AM_REG_ADC_SL4CFG_CHSEL4_SE7 0x00000700
#define AM_REG_ADC_SL4CFG_CHSEL4_SE8 0x00000800
#define AM_REG_ADC_SL4CFG_CHSEL4_SE9 0x00000900
#define AM_REG_ADC_SL4CFG_CHSEL4_DF0 0x00000A00
#define AM_REG_ADC_SL4CFG_CHSEL4_DF1 0x00000B00
#define AM_REG_ADC_SL4CFG_CHSEL4_TEMP 0x00000C00
#define AM_REG_ADC_SL4CFG_CHSEL4_BATT 0x00000D00
#define AM_REG_ADC_SL4CFG_CHSEL4_VSS 0x00000E00
// This bit enables the window compare function for slot 4.
#define AM_REG_ADC_SL4CFG_WCEN4_S 1
#define AM_REG_ADC_SL4CFG_WCEN4_M 0x00000002
#define AM_REG_ADC_SL4CFG_WCEN4(n) (((uint32_t)(n) << 1) & 0x00000002)
#define AM_REG_ADC_SL4CFG_WCEN4_WCEN 0x00000002
// This bit enables slot 4 for ADC conversions.
#define AM_REG_ADC_SL4CFG_SLEN4_S 0
#define AM_REG_ADC_SL4CFG_SLEN4_M 0x00000001
#define AM_REG_ADC_SL4CFG_SLEN4(n) (((uint32_t)(n) << 0) & 0x00000001)
#define AM_REG_ADC_SL4CFG_SLEN4_SLEN 0x00000001
//*****************************************************************************
//
// ADC_SL5CFG - Slot 5 Configuration Register
//
//*****************************************************************************
// Select number of measurements to average in the accumulate divide module for
// this slot.
#define AM_REG_ADC_SL5CFG_ADSEL5_S 24
#define AM_REG_ADC_SL5CFG_ADSEL5_M 0x07000000
#define AM_REG_ADC_SL5CFG_ADSEL5(n) (((uint32_t)(n) << 24) & 0x07000000)
#define AM_REG_ADC_SL5CFG_ADSEL5_AVG_1_MSRMT 0x00000000
#define AM_REG_ADC_SL5CFG_ADSEL5_AVG_2_MSRMTS 0x01000000
#define AM_REG_ADC_SL5CFG_ADSEL5_AVG_4_MSRMTS 0x02000000
#define AM_REG_ADC_SL5CFG_ADSEL5_AVG_8_MSRMT 0x03000000
#define AM_REG_ADC_SL5CFG_ADSEL5_AVG_16_MSRMTS 0x04000000
#define AM_REG_ADC_SL5CFG_ADSEL5_AVG_32_MSRMTS 0x05000000
#define AM_REG_ADC_SL5CFG_ADSEL5_AVG_64_MSRMTS 0x06000000
#define AM_REG_ADC_SL5CFG_ADSEL5_AVG_128_MSRMTS 0x07000000
// Set the Precision Mode For Slot.
#define AM_REG_ADC_SL5CFG_PRMODE5_S 16
#define AM_REG_ADC_SL5CFG_PRMODE5_M 0x00030000
#define AM_REG_ADC_SL5CFG_PRMODE5(n) (((uint32_t)(n) << 16) & 0x00030000)
#define AM_REG_ADC_SL5CFG_PRMODE5_P14B 0x00000000
#define AM_REG_ADC_SL5CFG_PRMODE5_P12B 0x00010000
#define AM_REG_ADC_SL5CFG_PRMODE5_P10B 0x00020000
#define AM_REG_ADC_SL5CFG_PRMODE5_P8B 0x00030000
// Select one of the 14 channel inputs for this slot.
#define AM_REG_ADC_SL5CFG_CHSEL5_S 8
#define AM_REG_ADC_SL5CFG_CHSEL5_M 0x00000F00
#define AM_REG_ADC_SL5CFG_CHSEL5(n) (((uint32_t)(n) << 8) & 0x00000F00)
#define AM_REG_ADC_SL5CFG_CHSEL5_SE0 0x00000000
#define AM_REG_ADC_SL5CFG_CHSEL5_SE1 0x00000100
#define AM_REG_ADC_SL5CFG_CHSEL5_SE2 0x00000200
#define AM_REG_ADC_SL5CFG_CHSEL5_SE3 0x00000300
#define AM_REG_ADC_SL5CFG_CHSEL5_SE4 0x00000400
#define AM_REG_ADC_SL5CFG_CHSEL5_SE5 0x00000500
#define AM_REG_ADC_SL5CFG_CHSEL5_SE6 0x00000600
#define AM_REG_ADC_SL5CFG_CHSEL5_SE7 0x00000700
#define AM_REG_ADC_SL5CFG_CHSEL5_SE8 0x00000800
#define AM_REG_ADC_SL5CFG_CHSEL5_SE9 0x00000900
#define AM_REG_ADC_SL5CFG_CHSEL5_DF0 0x00000A00
#define AM_REG_ADC_SL5CFG_CHSEL5_DF1 0x00000B00
#define AM_REG_ADC_SL5CFG_CHSEL5_TEMP 0x00000C00
#define AM_REG_ADC_SL5CFG_CHSEL5_BATT 0x00000D00
#define AM_REG_ADC_SL5CFG_CHSEL5_VSS 0x00000E00
// This bit enables the window compare function for slot 5.
#define AM_REG_ADC_SL5CFG_WCEN5_S 1
#define AM_REG_ADC_SL5CFG_WCEN5_M 0x00000002
#define AM_REG_ADC_SL5CFG_WCEN5(n) (((uint32_t)(n) << 1) & 0x00000002)
#define AM_REG_ADC_SL5CFG_WCEN5_WCEN 0x00000002
// This bit enables slot 5 for ADC conversions.
#define AM_REG_ADC_SL5CFG_SLEN5_S 0
#define AM_REG_ADC_SL5CFG_SLEN5_M 0x00000001
#define AM_REG_ADC_SL5CFG_SLEN5(n) (((uint32_t)(n) << 0) & 0x00000001)
#define AM_REG_ADC_SL5CFG_SLEN5_SLEN 0x00000001
//*****************************************************************************
//
// ADC_SL6CFG - Slot 6 Configuration Register
//
//*****************************************************************************
// Select the number of measurements to average in the accumulate divide module
// for this slot.
#define AM_REG_ADC_SL6CFG_ADSEL6_S 24
#define AM_REG_ADC_SL6CFG_ADSEL6_M 0x07000000
#define AM_REG_ADC_SL6CFG_ADSEL6(n) (((uint32_t)(n) << 24) & 0x07000000)
#define AM_REG_ADC_SL6CFG_ADSEL6_AVG_1_MSRMT 0x00000000
#define AM_REG_ADC_SL6CFG_ADSEL6_AVG_2_MSRMTS 0x01000000
#define AM_REG_ADC_SL6CFG_ADSEL6_AVG_4_MSRMTS 0x02000000
#define AM_REG_ADC_SL6CFG_ADSEL6_AVG_8_MSRMT 0x03000000
#define AM_REG_ADC_SL6CFG_ADSEL6_AVG_16_MSRMTS 0x04000000
#define AM_REG_ADC_SL6CFG_ADSEL6_AVG_32_MSRMTS 0x05000000
#define AM_REG_ADC_SL6CFG_ADSEL6_AVG_64_MSRMTS 0x06000000
#define AM_REG_ADC_SL6CFG_ADSEL6_AVG_128_MSRMTS 0x07000000
// Set the Precision Mode For Slot.
#define AM_REG_ADC_SL6CFG_PRMODE6_S 16
#define AM_REG_ADC_SL6CFG_PRMODE6_M 0x00030000
#define AM_REG_ADC_SL6CFG_PRMODE6(n) (((uint32_t)(n) << 16) & 0x00030000)
#define AM_REG_ADC_SL6CFG_PRMODE6_P14B 0x00000000
#define AM_REG_ADC_SL6CFG_PRMODE6_P12B 0x00010000
#define AM_REG_ADC_SL6CFG_PRMODE6_P10B 0x00020000
#define AM_REG_ADC_SL6CFG_PRMODE6_P8B 0x00030000
// Select one of the 14 channel inputs for this slot.
#define AM_REG_ADC_SL6CFG_CHSEL6_S 8
#define AM_REG_ADC_SL6CFG_CHSEL6_M 0x00000F00
#define AM_REG_ADC_SL6CFG_CHSEL6(n) (((uint32_t)(n) << 8) & 0x00000F00)
#define AM_REG_ADC_SL6CFG_CHSEL6_SE0 0x00000000
#define AM_REG_ADC_SL6CFG_CHSEL6_SE1 0x00000100
#define AM_REG_ADC_SL6CFG_CHSEL6_SE2 0x00000200
#define AM_REG_ADC_SL6CFG_CHSEL6_SE3 0x00000300
#define AM_REG_ADC_SL6CFG_CHSEL6_SE4 0x00000400
#define AM_REG_ADC_SL6CFG_CHSEL6_SE5 0x00000500
#define AM_REG_ADC_SL6CFG_CHSEL6_SE6 0x00000600
#define AM_REG_ADC_SL6CFG_CHSEL6_SE7 0x00000700
#define AM_REG_ADC_SL6CFG_CHSEL6_SE8 0x00000800
#define AM_REG_ADC_SL6CFG_CHSEL6_SE9 0x00000900
#define AM_REG_ADC_SL6CFG_CHSEL6_DF0 0x00000A00
#define AM_REG_ADC_SL6CFG_CHSEL6_DF1 0x00000B00
#define AM_REG_ADC_SL6CFG_CHSEL6_TEMP 0x00000C00
#define AM_REG_ADC_SL6CFG_CHSEL6_BATT 0x00000D00
#define AM_REG_ADC_SL6CFG_CHSEL6_VSS 0x00000E00
// This bit enables the window compare function for slot 6.
#define AM_REG_ADC_SL6CFG_WCEN6_S 1
#define AM_REG_ADC_SL6CFG_WCEN6_M 0x00000002
#define AM_REG_ADC_SL6CFG_WCEN6(n) (((uint32_t)(n) << 1) & 0x00000002)
#define AM_REG_ADC_SL6CFG_WCEN6_WCEN 0x00000002
// This bit enables slot 6 for ADC conversions.
#define AM_REG_ADC_SL6CFG_SLEN6_S 0
#define AM_REG_ADC_SL6CFG_SLEN6_M 0x00000001
#define AM_REG_ADC_SL6CFG_SLEN6(n) (((uint32_t)(n) << 0) & 0x00000001)
#define AM_REG_ADC_SL6CFG_SLEN6_SLEN 0x00000001
//*****************************************************************************
//
// ADC_SL7CFG - Slot 7 Configuration Register
//
//*****************************************************************************
// Select the number of measurements to average in the accumulate divide module
// for this slot.
#define AM_REG_ADC_SL7CFG_ADSEL7_S 24
#define AM_REG_ADC_SL7CFG_ADSEL7_M 0x07000000
#define AM_REG_ADC_SL7CFG_ADSEL7(n) (((uint32_t)(n) << 24) & 0x07000000)
#define AM_REG_ADC_SL7CFG_ADSEL7_AVG_1_MSRMT 0x00000000
#define AM_REG_ADC_SL7CFG_ADSEL7_AVG_2_MSRMTS 0x01000000
#define AM_REG_ADC_SL7CFG_ADSEL7_AVG_4_MSRMTS 0x02000000
#define AM_REG_ADC_SL7CFG_ADSEL7_AVG_8_MSRMT 0x03000000
#define AM_REG_ADC_SL7CFG_ADSEL7_AVG_16_MSRMTS 0x04000000
#define AM_REG_ADC_SL7CFG_ADSEL7_AVG_32_MSRMTS 0x05000000
#define AM_REG_ADC_SL7CFG_ADSEL7_AVG_64_MSRMTS 0x06000000
#define AM_REG_ADC_SL7CFG_ADSEL7_AVG_128_MSRMTS 0x07000000
// Set the Precision Mode For Slot.
#define AM_REG_ADC_SL7CFG_PRMODE7_S 16
#define AM_REG_ADC_SL7CFG_PRMODE7_M 0x00030000
#define AM_REG_ADC_SL7CFG_PRMODE7(n) (((uint32_t)(n) << 16) & 0x00030000)
#define AM_REG_ADC_SL7CFG_PRMODE7_P14B 0x00000000
#define AM_REG_ADC_SL7CFG_PRMODE7_P12B 0x00010000
#define AM_REG_ADC_SL7CFG_PRMODE7_P10B 0x00020000
#define AM_REG_ADC_SL7CFG_PRMODE7_P8B 0x00030000
// Select one of the 14 channel inputs for this slot.
#define AM_REG_ADC_SL7CFG_CHSEL7_S 8
#define AM_REG_ADC_SL7CFG_CHSEL7_M 0x00000F00
#define AM_REG_ADC_SL7CFG_CHSEL7(n) (((uint32_t)(n) << 8) & 0x00000F00)
#define AM_REG_ADC_SL7CFG_CHSEL7_SE0 0x00000000
#define AM_REG_ADC_SL7CFG_CHSEL7_SE1 0x00000100
#define AM_REG_ADC_SL7CFG_CHSEL7_SE2 0x00000200
#define AM_REG_ADC_SL7CFG_CHSEL7_SE3 0x00000300
#define AM_REG_ADC_SL7CFG_CHSEL7_SE4 0x00000400
#define AM_REG_ADC_SL7CFG_CHSEL7_SE5 0x00000500
#define AM_REG_ADC_SL7CFG_CHSEL7_SE6 0x00000600
#define AM_REG_ADC_SL7CFG_CHSEL7_SE7 0x00000700
#define AM_REG_ADC_SL7CFG_CHSEL7_SE8 0x00000800
#define AM_REG_ADC_SL7CFG_CHSEL7_SE9 0x00000900
#define AM_REG_ADC_SL7CFG_CHSEL7_DF0 0x00000A00
#define AM_REG_ADC_SL7CFG_CHSEL7_DF1 0x00000B00
#define AM_REG_ADC_SL7CFG_CHSEL7_TEMP 0x00000C00
#define AM_REG_ADC_SL7CFG_CHSEL7_BATT 0x00000D00
#define AM_REG_ADC_SL7CFG_CHSEL7_VSS 0x00000E00
// This bit enables the window compare function for slot 7.
#define AM_REG_ADC_SL7CFG_WCEN7_S 1
#define AM_REG_ADC_SL7CFG_WCEN7_M 0x00000002
#define AM_REG_ADC_SL7CFG_WCEN7(n) (((uint32_t)(n) << 1) & 0x00000002)
#define AM_REG_ADC_SL7CFG_WCEN7_WCEN 0x00000002
// This bit enables slot 7 for ADC conversions.
#define AM_REG_ADC_SL7CFG_SLEN7_S 0
#define AM_REG_ADC_SL7CFG_SLEN7_M 0x00000001
#define AM_REG_ADC_SL7CFG_SLEN7(n) (((uint32_t)(n) << 0) & 0x00000001)
#define AM_REG_ADC_SL7CFG_SLEN7_SLEN 0x00000001
//*****************************************************************************
//
// ADC_WULIM - Window Comparator Upper Limits Register
//
//*****************************************************************************
// Sets the upper limit for the wondow comparator.
#define AM_REG_ADC_WULIM_ULIM_S 0
#define AM_REG_ADC_WULIM_ULIM_M 0x000FFFFF
#define AM_REG_ADC_WULIM_ULIM(n) (((uint32_t)(n) << 0) & 0x000FFFFF)
//*****************************************************************************
//
// ADC_WLLIM - Window Comparator Lower Limits Register
//
//*****************************************************************************
// Sets the lower limit for the wondow comparator.
#define AM_REG_ADC_WLLIM_LLIM_S 0
#define AM_REG_ADC_WLLIM_LLIM_M 0x000FFFFF
#define AM_REG_ADC_WLLIM_LLIM(n) (((uint32_t)(n) << 0) & 0x000FFFFF)
//*****************************************************************************
//
// ADC_FIFO - FIFO Data and Valid Count Register
//
//*****************************************************************************
// RESERVED.
#define AM_REG_ADC_FIFO_RSVD_S 31
#define AM_REG_ADC_FIFO_RSVD_M 0x80000000
#define AM_REG_ADC_FIFO_RSVD(n) (((uint32_t)(n) << 31) & 0x80000000)
// Slot number associated with this FIFO data.
#define AM_REG_ADC_FIFO_SLOTNUM_S 28
#define AM_REG_ADC_FIFO_SLOTNUM_M 0x70000000
#define AM_REG_ADC_FIFO_SLOTNUM(n) (((uint32_t)(n) << 28) & 0x70000000)
// Number of valid entries in the ADC FIFO.
#define AM_REG_ADC_FIFO_COUNT_S 20
#define AM_REG_ADC_FIFO_COUNT_M 0x0FF00000
#define AM_REG_ADC_FIFO_COUNT(n) (((uint32_t)(n) << 20) & 0x0FF00000)
// Oldest data in the FIFO.
#define AM_REG_ADC_FIFO_DATA_S 0
#define AM_REG_ADC_FIFO_DATA_M 0x000FFFFF
#define AM_REG_ADC_FIFO_DATA(n) (((uint32_t)(n) << 0) & 0x000FFFFF)
#endif // AM_REG_ADC_H
|
1c57a976bf413de06fd1e265245e125b321c9ce6
|
54c67306d63bb69a5cf381d12108d3dc98ae0f5d
|
/third-party/cubeb/cubeb/src/cubeb_array_queue.h
|
d6d95813251ed3463f6eee41afa2114ecfd26589
|
[
"ISC",
"LicenseRef-scancode-unknown-license-reference"
] |
permissive
|
open-goal/jak-project
|
adf30a3459c24afda5b180e3abe1583c93458a37
|
d96dce27149fbf58586160cfecb634614f055943
|
refs/heads/master
| 2023-09-01T21:51:16.736237
| 2023-09-01T16:10:59
| 2023-09-01T16:10:59
| 289,585,720
| 1,826
| 131
|
ISC
| 2023-09-14T13:27:47
| 2020-08-22T23:55:21
|
Common Lisp
|
UTF-8
|
C
| false
| false
| 1,888
|
h
|
cubeb_array_queue.h
|
/*
* Copyright © 2016 Mozilla Foundation
*
* This program is made available under an ISC-style license. See the
* accompanying file LICENSE for details.
*/
#ifndef CUBEB_ARRAY_QUEUE_H
#define CUBEB_ARRAY_QUEUE_H
#include <assert.h>
#include <pthread.h>
#include <unistd.h>
#if defined(__cplusplus)
extern "C" {
#endif
typedef struct {
void ** buf;
size_t num;
size_t writePos;
size_t readPos;
pthread_mutex_t mutex;
} array_queue;
array_queue *
array_queue_create(size_t num)
{
assert(num != 0);
array_queue * new_queue = (array_queue *)calloc(1, sizeof(array_queue));
new_queue->buf = (void **)calloc(1, sizeof(void *) * num);
new_queue->readPos = 0;
new_queue->writePos = 0;
new_queue->num = num;
pthread_mutex_init(&new_queue->mutex, NULL);
return new_queue;
}
void
array_queue_destroy(array_queue * aq)
{
assert(aq);
free(aq->buf);
pthread_mutex_destroy(&aq->mutex);
free(aq);
}
int
array_queue_push(array_queue * aq, void * item)
{
assert(item);
pthread_mutex_lock(&aq->mutex);
int ret = -1;
if (aq->buf[aq->writePos % aq->num] == NULL) {
aq->buf[aq->writePos % aq->num] = item;
aq->writePos = (aq->writePos + 1) % aq->num;
ret = 0;
}
// else queue is full
pthread_mutex_unlock(&aq->mutex);
return ret;
}
void *
array_queue_pop(array_queue * aq)
{
pthread_mutex_lock(&aq->mutex);
void * value = aq->buf[aq->readPos % aq->num];
if (value) {
aq->buf[aq->readPos % aq->num] = NULL;
aq->readPos = (aq->readPos + 1) % aq->num;
}
pthread_mutex_unlock(&aq->mutex);
return value;
}
size_t
array_queue_get_size(array_queue * aq)
{
pthread_mutex_lock(&aq->mutex);
ssize_t r = aq->writePos - aq->readPos;
if (r < 0) {
r = aq->num + r;
assert(r >= 0);
}
pthread_mutex_unlock(&aq->mutex);
return (size_t)r;
}
#if defined(__cplusplus)
}
#endif
#endif // CUBE_ARRAY_QUEUE_H
|
2c4aae331919e4a05a1fb457865e085399a0b6ed
|
3a30cfb29aac91e5c75d4dbcefddfd1f34d5f18c
|
/c-tests/lacc/for.c
|
98774c7c269914f2db2ae45e6bbf09634b53c419
|
[
"MIT",
"MPL-1.0",
"LicenseRef-scancode-warranty-disclaimer",
"Apache-2.0",
"LGPL-2.0-only"
] |
permissive
|
vnmakarov/mir
|
a1725bc9c828e8580df6b7ae94e04175db8abe93
|
928e28fb3acaa50d051a906e76a55cc48a556574
|
refs/heads/master
| 2023-09-02T11:10:37.434581
| 2023-08-25T19:25:40
| 2023-08-25T19:25:40
| 178,932,492
| 2,005
| 156
|
MIT
| 2023-08-01T20:29:59
| 2019-04-01T19:24:56
|
C
|
UTF-8
|
C
| false
| false
| 194
|
c
|
for.c
|
int main(int argc, char *argv[])
{
int i, j;
for (i = 1; i & 7; i = i + 1) {
if (i & 2)
continue;
for (j = 1; j & 3; j = j + 1) {
if ((j + i) ^ 3)
break;
}
}
return i + j;
}
|
fd06191de69bb03aa83511a91c1f0cd420d4c23a
|
f3eed0234b4d0ad2bbb2abd700cf1e2c7a0e8a1d
|
/AKWF-c/AKWF_cello/AKWF_cello_0019.h
|
2f11234a7cf435922b77dcfe4f49d0933a5390a7
|
[
"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,684
|
h
|
AKWF_cello_0019.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_cello_0019 256 samples
+-----------------------------------------------------------------------------------------------------------------+
| ** ** *** |
| **** ** *********** ** |
| **** *** ** ** |
| *** ******** ** ** |
| ** ** ** ** |
|** * ** *** |
|* * * ***** ******** ***|
| ** ** ********* **** |
| ** **** ** |
| * *** ** ** |
| ** *** ** ** |
| *** ** ** |
| ** *** |
| * *** |
| ** *** |
+-----------------------------------------------------------------------------------------------------------------+
*/
const uint16_t AKWF_cello_0019 [] = {
32848, 33441, 34209, 34964, 35827, 36707, 37609, 38519, 39497, 40529, 41599, 42545, 43437, 44297, 45021, 45736,
46367, 46916, 47389, 47779, 48196, 48522, 48835, 49188, 49522, 49900, 50425, 51080, 51795, 52544, 53234, 53993,
54764, 55485, 56165, 56689, 56964, 56937, 56647, 56144, 55398, 54408, 53151, 51689, 50171, 48639, 47248, 46037,
45028, 44244, 43628, 43251, 43126, 43187, 43323, 43416, 43445, 43493, 43588, 43623, 43517, 43203, 42766, 42167,
41264, 40058, 38608, 36946, 35078, 33042, 30809, 28537, 26303, 24158, 22172, 20364, 18798, 17485, 16430, 15660,
15234, 15081, 15195, 15579, 16202, 17006, 17901, 18851, 19860, 20878, 21798, 22629, 23324, 23840, 24170, 24282,
24201, 23879, 23283, 22393, 21210, 19813, 18210, 16391, 14407, 12349, 10337, 8421, 6620, 5006, 3595, 2428,
1467, 712, 220, 12, 44, 322, 815, 1487, 2316, 3130, 3953, 4822, 5675, 6450, 7163, 7826,
8472, 9132, 9780, 10456, 11220, 12103, 13128, 14300, 15598, 17013, 18552, 20180, 21840, 23506, 25198, 26908,
28613, 30340, 32039, 33692, 35304, 36872, 38416, 39924, 41358, 42695, 43975, 45214, 46334, 47370, 48291, 49088,
49818, 50354, 50753, 50983, 51018, 50953, 50717, 50416, 50085, 49739, 49440, 49157, 49050, 49112, 49238, 49496,
49860, 50327, 50826, 51321, 51789, 52129, 52330, 52381, 52192, 51734, 51120, 50264, 49151, 47859, 46419, 44769,
43034, 41322, 39744, 38402, 37054, 35798, 34718, 33808, 33131, 32646, 32226, 31783, 31408, 31126, 30875, 30588,
30382, 30233, 30016, 29857, 29731, 29629, 29518, 29346, 29299, 29235, 29130, 29052, 29012, 29216, 29194, 29200,
29549, 29911, 30356, 30730, 31231, 31862, 32371, 32851, 33220, 33493, 33666, 33657, 33552, 33281, 32856, 32366,
31859, 31301, 30735, 30215, 29861, 29727, 29692, 29734, 29915, 30173, 30398, 30741, 31072, 31461, 31976, 32494,
};
|
b93f379e6f6ce7d87f455a0c2dcbc7841c9544cf
|
c26d7b0ed875357278e61627da2da0650da77986
|
/src/cmd/smallc/8080/exit.c
|
10a7fe15d691316f993bc4b9cbffcb33e369c55e
|
[
"BSD-3-Clause",
"LicenseRef-scancode-public-domain"
] |
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
| 63
|
c
|
exit.c
|
exit(retcode) int retcode; {
#asm
jmp 0
#endasm
}
|
3034fa2b4eec016c3491eb3b6cc576a2413c3f2c
|
554e0d92071d8ce0a1888e970edd77be59699c01
|
/gumbo/util.c
|
af151cab6005a744e0c61b5659171b408fd6c3ab
|
[
"Apache-2.0"
] |
permissive
|
craigbarnes/lua-gumbo
|
5e424186d2905f48a2058b80312f70421ca72a7d
|
9f2defdcc2e0d660a9fb0dd29c6e11f8cac87d01
|
refs/heads/master
| 2022-06-24T01:01:51.124075
| 2022-06-01T01:47:02
| 2022-06-01T01:47:02
| 12,173,574
| 135
| 19
|
Apache-2.0
| 2018-04-29T23:53:11
| 2013-08-17T04:50:04
|
C
|
UTF-8
|
C
| false
| false
| 2,695
|
c
|
util.c
|
/*
Copyright (c) 2021, Craig Barnes.
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
https://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 <limits.h>
#include <stddef.h>
#include <lua.h>
#include <lauxlib.h>
#include "compat.h"
#include "../lib/ascii.h"
#include "../lib/macros.h"
static const char *do_trim(const char *str, size_t *n)
{
size_t len = *n;
while (len && ascii_isspace(*str)) {
len--;
str++;
}
const char *end = str + len - 1;
while (len && ascii_isspace(*end)) {
len--;
end--;
}
*n = len;
return str;
}
static int trim_and_collapse(lua_State *L)
{
luaL_Buffer b;
size_t len;
const char *str = luaL_checklstring(L, 1, &len);
str = do_trim(str, &len);
#if LUA_VERSION_NUM >= 502
char *out = luaL_buffinitsize(L, &b, len);
size_t pos = 0;
#else
luaL_buffinit(L, &b);
#endif
for (size_t i = 0; i < len; ) {
char ch = str[i++];
if (ascii_isspace(ch)) {
while (i < len && ascii_isspace(str[i])) {
i++;
}
ch = ' ';
}
#if LUA_VERSION_NUM >= 502
out[pos++] = ch;
#else
luaL_addchar(&b, ch);
#endif
}
#if LUA_VERSION_NUM >= 502
luaL_addsize(&b, pos);
#endif
luaL_pushresult(&b);
return 1;
}
static int trim(lua_State *L)
{
size_t len;
const char *str = luaL_checklstring(L, 1, &len);
const char *trimmed = do_trim(str, &len);
lua_pushlstring(L, trimmed, len);
return 1;
}
static int createtable(lua_State *L)
{
lua_Integer narr = luaL_checkinteger(L, 1);
lua_Integer nrec = luaL_checkinteger(L, 2);
if (unlikely(narr < 0 || narr > INT_MAX)) {
luaL_argerror(L, 1, "value outside valid range");
}
if (unlikely(nrec < 0 || nrec > INT_MAX)) {
luaL_argerror(L, 2, "value outside valid range");
}
lua_createtable(L, (int)narr, (int)nrec);
return 1;
}
static const luaL_Reg lib[] = {
{"trim", trim},
{"trimAndCollapseWhitespace", trim_and_collapse},
{"createtable", createtable},
{NULL, NULL}
};
EXPORT int luaopen_gumbo_util(lua_State *L)
{
luaL_newlib(L, lib);
return 1;
}
|
55654cfcbd2329c627587ef92dae9e09377eceac
|
88ae8695987ada722184307301e221e1ba3cc2fa
|
/third_party/ffmpeg/libavcodec/rawenc.c
|
8c577006d922d497a45deefb8eee473b5a2ea65b
|
[
"Apache-2.0",
"LGPL-2.0-or-later",
"MIT",
"GPL-1.0-or-later",
"BSD-3-Clause",
"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
| 3,126
|
c
|
rawenc.c
|
/*
* Raw Video Encoder
* Copyright (c) 2001 Fabrice Bellard
*
* 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
*/
/**
* @file
* Raw Video Encoder
*/
#include "avcodec.h"
#include "codec_internal.h"
#include "encode.h"
#include "raw.h"
#include "internal.h"
#include "libavutil/pixdesc.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/imgutils.h"
#include "libavutil/internal.h"
static av_cold int raw_encode_init(AVCodecContext *avctx)
{
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(avctx->pix_fmt);
avctx->bits_per_coded_sample = av_get_bits_per_pixel(desc);
if(!avctx->codec_tag)
avctx->codec_tag = avcodec_pix_fmt_to_codec_tag(avctx->pix_fmt);
avctx->bit_rate = ff_guess_coded_bitrate(avctx);
return 0;
}
static int raw_encode(AVCodecContext *avctx, AVPacket *pkt,
const AVFrame *frame, int *got_packet)
{
int ret = av_image_get_buffer_size(frame->format,
frame->width, frame->height, 1);
if (ret < 0)
return ret;
if ((ret = ff_get_encode_buffer(avctx, pkt, ret, 0)) < 0)
return ret;
if ((ret = av_image_copy_to_buffer(pkt->data, pkt->size,
(const uint8_t **)frame->data, frame->linesize,
frame->format,
frame->width, frame->height, 1)) < 0)
return ret;
if(avctx->codec_tag == AV_RL32("yuv2") && ret > 0 &&
frame->format == AV_PIX_FMT_YUYV422) {
int x;
for(x = 1; x < frame->height*frame->width*2; x += 2)
pkt->data[x] ^= 0x80;
} else if (avctx->codec_tag == AV_RL32("b64a") && ret > 0 &&
frame->format == AV_PIX_FMT_RGBA64BE) {
uint64_t v;
int x;
for (x = 0; x < frame->height * frame->width; x++) {
v = AV_RB64(&pkt->data[8 * x]);
AV_WB64(&pkt->data[8 * x], v << 48 | v >> 16);
}
}
*got_packet = 1;
return 0;
}
const FFCodec ff_rawvideo_encoder = {
.p.name = "rawvideo",
CODEC_LONG_NAME("raw video"),
.p.type = AVMEDIA_TYPE_VIDEO,
.p.id = AV_CODEC_ID_RAWVIDEO,
.p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS |
AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE,
.init = raw_encode_init,
FF_CODEC_ENCODE_CB(raw_encode),
};
|
6435f0b37caeea85e9016236d0b2c5337a02d5ab
|
50dd46b8ece33f3cdd174284b15d1d51f89669d4
|
/third_party/edk2/MdePkg/Library/BaseLib/Ia32/MultU64x64.c
|
8f6bdc7b85c27d968c08c9c4926c91444671a1a9
|
[
"LicenseRef-scancode-generic-cla",
"Apache-2.0",
"BSD-2-Clause",
"OpenSSL"
] |
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
| 1,519
|
c
|
MultU64x64.c
|
/** @file
Calculate the product of a 64-bit integer and another 64-bit integer
Copyright (c) 2006 - 2010, 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
which 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.
**/
/**
Multiplies a 64-bit unsigned integer by a 64-bit unsigned integer
and generates a 64-bit unsigned result.
This function multiplies the 64-bit unsigned value Multiplicand by the 64-bit
unsigned value Multiplier and generates a 64-bit unsigned result. This 64-
bit unsigned result is returned.
@param Multiplicand A 64-bit unsigned value.
@param Multiplier A 64-bit unsigned value.
@return Multiplicand * Multiplier
**/
UINT64
EFIAPI
InternalMathMultU64x64 (
IN UINT64 Multiplicand,
IN UINT64 Multiplier
)
{
_asm {
mov ebx, dword ptr [Multiplicand + 0]
mov edx, dword ptr [Multiplier + 0]
mov ecx, ebx
mov eax, edx
imul ebx, dword ptr [Multiplier + 4]
imul edx, dword ptr [Multiplicand + 4]
add ebx, edx
mul ecx
add edx, ebx
}
}
|
dc9f0f959eb93af232487dacd4fae3aa83abab55
|
a12b448f44beb4d521cb7e31677281f41df35f0b
|
/3rdParty/isl/test_inputs/codegen/single_valued.c
|
e071002b79d3a48c7af8eb074842bc977a9477fe
|
[
"MIT",
"LGPL-2.0-or-later"
] |
permissive
|
Tiramisu-Compiler/tiramisu
|
d45f65dd9c35f643b3531ec79df1203c7ea3371d
|
f13e480f0ddb142cec371b7d7431a41d8ca885ec
|
refs/heads/master
| 2023-08-25T12:21:26.889736
| 2023-05-09T18:40:52
| 2023-05-09T18:40:52
| 58,378,976
| 906
| 168
|
MIT
| 2023-09-08T11:47:06
| 2016-05-09T13:33:51
|
C++
|
UTF-8
|
C
| false
| false
| 75
|
c
|
single_valued.c
|
if (2 * ((t1 - 1) % 64) + 8 >= t1)
S(-(2 * ((t1 - 1) % 64)) + t1 + 126);
|
16ee4c34a8d0aa7a199578b4b4c9f93c50199487
|
f3eed0234b4d0ad2bbb2abd700cf1e2c7a0e8a1d
|
/AKWF-c/AKWF_dbass/AKWF_dbass_0052.h
|
b4c0333db22a4c99ec71e9de282174ddef45ef37
|
[
"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,684
|
h
|
AKWF_dbass_0052.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_dbass_0052 256 samples
+-----------------------------------------------------------------------------------------------------------------+
| ****** ** |
| *** ** |
| ** ** |
| ** * |
| * * |
| * ** |
| * * |
|** * |
|* * |
|* ** ********** **** |
| *** ***** ** **** *|
| ******* *** *|
| ***** *** ***** * |
| *** ***** ***** ***** *** *** |
| ** *** ********* ********* |
+-----------------------------------------------------------------------------------------------------------------+
*/
const uint16_t AKWF_dbass_0052 [] = {
33258, 35134, 37169, 39357, 41506, 43495, 45317, 46946, 48540, 49994, 51350, 52584, 53689, 54659, 55649, 56546,
57370, 58142, 58785, 59559, 60282, 60920, 61495, 61913, 62322, 62577, 62784, 63068, 63265, 63426, 63560, 63779,
64024, 64300, 64660, 64893, 65088, 65098, 64971, 64936, 65014, 65175, 65385, 65519, 65485, 65196, 64587, 63697,
62556, 61354, 59989, 58517, 56925, 55121, 53270, 51298, 49329, 47331, 45330, 43402, 41468, 39761, 38108, 36581,
35178, 33880, 32719, 31519, 30443, 29286, 28291, 27596, 27132, 26956, 26968, 27257, 27576, 27911, 28235, 28526,
28713, 28913, 29252, 29660, 30266, 30904, 31396, 31833, 32095, 32177, 32309, 32364, 32564, 32790, 33175, 33593,
33972, 34252, 34464, 34614, 34731, 34804, 34846, 34892, 34894, 34946, 34780, 34801, 34694, 34493, 34070, 33932,
33526, 32914, 32211, 32526, 32836, 33095, 33584, 33248, 33816, 33520, 33528, 33391, 32718, 32419, 32263, 31893,
31609, 30753, 29956, 29633, 29039, 28831, 28093, 27370, 26898, 26519, 25821, 25703, 25798, 26026, 25827, 25170,
24563, 23736, 22880, 21964, 21154, 20447, 19822, 18877, 17830, 16682, 15844, 15562, 15582, 15627, 15971, 16459,
17165, 18420, 19639, 20408, 21081, 21489, 21719, 22022, 22174, 22198, 22327, 22675, 23035, 23602, 23932, 23958,
23512, 22942, 22556, 22068, 21775, 21666, 21604, 21531, 21454, 21007, 20365, 19551, 18776, 18367, 18183, 18173,
18143, 17902, 17778, 17979, 18246, 18459, 18556, 18651, 18856, 19289, 19618, 19930, 20153, 20390, 20751, 20986,
21278, 21491, 21716, 22010, 22635, 23447, 24103, 24488, 24522, 24483, 24401, 24399, 24287, 24080, 23750, 23241,
22802, 22446, 22124, 21732, 21220, 20572, 19977, 19413, 18952, 18505, 18210, 18086, 18002, 17930, 17783, 17720,
17795, 17959, 18152, 18446, 18787, 19234, 19872, 20536, 21277, 22183, 23174, 24422, 25962, 27802, 29506, 31423,
};
|
54a3f9831b1d8f2d2c290bfc1ef707eb0ebcb0fc
|
fd72e569835f284faf9f5491bac13e1f9eb50258
|
/大三/大三下/计算机应用设计/MSP-EXP430F5529 LAB CODE/LAB6/UserExperienceDemo/Puzzle/fsm_transition.h
|
a8831f3432df2c4da5294415804a1114d896aad5
|
[] |
no_license
|
ChangWinde/SouthEastUniversity
|
119e4320f4dd2ca589dc38826aa9e9c9d8ceddf5
|
347873f2ee8063ca6392770d52fafb86034b6d53
|
refs/heads/master
| 2023-07-04T19:17:46.666846
| 2020-12-12T04:09:49
| 2020-12-12T04:09:49
| 150,752,892
| 227
| 83
| null | 2023-07-02T16:11:55
| 2018-09-28T14:31:13
|
C
|
UTF-8
|
C
| false
| false
| 1,071
|
h
|
fsm_transition.h
|
//****************************************************************************//
// LCD Library
// fsm_transition.h
//
// Describtion:
// Transition functions
//
// Target MCU: MSP430F5529
//
// Implemented with Application report: SLAA402
//
//****************************************************************************//
#ifndef FSM_TRANSITION_H
#define FSM_TRANSITION_H
//****************************************************************************//
// Game position typedef
//****************************************************************************//
typedef struct
{
uint8_t PosX;
uint8_t PosY;
} GAME_POS;
//****************************************************************************//
// Some useful macros
//****************************************************************************//
#define FIELD_SIZE 9
#define NR_OFFSET 0x30
//****************************************************************************//
#endif /* FSM_TRANSITION_H */
//****************************************************************************//
|
4ced767b062c1976fc0d5ce1ad0a58a20a0702d5
|
abc0d80b9d6831d9820a3d00f5b28a9b250be891
|
/libMachO/MachO_ABI/Symbols/symbol.h
|
e1594c3f3ab01b8c42977a37f3272251d44997e0
|
[
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] |
permissive
|
DeVaukz/MachO-Kit
|
b917cef9df4acc91b6ea0fa9b02e9fc00cfd1119
|
ef5272fc3a6fe8b612df534ca1150f9733cd6c66
|
refs/heads/master
| 2022-09-05T11:36:24.773711
| 2021-12-06T04:24:18
| 2021-12-06T04:24:18
| 29,898,256
| 521
| 75
|
MIT
| 2022-08-10T20:28:58
| 2015-01-27T05:03:50
|
Objective-C
|
UTF-8
|
C
| false
| false
| 4,757
|
h
|
symbol.h
|
//----------------------------------------------------------------------------//
//|
//| MachOKit - A Lightweight Mach-O Parsing Library
//! @file symbol.h
//!
//! @author D.V.
//! @copyright Copyright (c) 2014-2015 D.V. All rights reserved.
//|
//| 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.
//----------------------------------------------------------------------------//
//----------------------------------------------------------------------------//
//! @defgroup SYMBOLS Symbols
//! @ingroup MACH
//!
//! Parsers for Symbols.
//----------------------------------------------------------------------------//
#ifndef _symbol_h
#define _symbol_h
//! @addtogroup SYMBOLS
//! @{
//!
//----------------------------------------------------------------------------//
#pragma mark - Types
//! @name Types
//----------------------------------------------------------------------------//
//◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦//
typedef union {
void *any;
struct nlist *nlist;
struct nlist_64 *nlist_64;
} mk_macho_nlist_ptr _mk_transparent_union;
//◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦//
//! @internal
//
typedef struct mk_symbol_s {
__MK_RUNTIME_BASE
mk_symbol_table_ref symbol_table;
mk_macho_nlist_ptr nlist;
} mk_symbol_t;
//◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦//
//! The Symbol polymorphic type.
//
typedef union {
mk_type_ref type;
struct mk_symbol_s *symbol;
} mk_symbol_ref _mk_transparent_union;
//! The identifier for the Symbol type.
_mk_export intptr_t mk_symbol_type;
//----------------------------------------------------------------------------//
#pragma mark - Working With Symbols
//! @name Working With Symbols
//----------------------------------------------------------------------------//
//! Initializes the provided symbol with the provided Mach nlist structure
//! in \a image.
_mk_export mk_error_t
mk_symbol_init(mk_symbol_table_ref symbol_table, mk_macho_nlist_ptr nlist, mk_symbol_t* symbol);
//! Returns the Mach-O image that the specified symbol resides within.
_mk_export mk_macho_ref
mk_symbol_get_macho(mk_symbol_ref symbol);
//! Returns the symbol table that the specified symbol resides within.
_mk_export mk_symbol_table_ref
mk_symbol_get_symbol_table(mk_symbol_ref symbol);
//! Returns range of memory (in the target address space) that the specified
//! symbol occupies.
_mk_export mk_vm_range_t
mk_symbol_get_target_range(mk_symbol_ref symbol);
//----------------------------------------------------------------------------//
#pragma mark - Symbol Values
//! @name Symbol Values
//!
//! These functions return values directly from the underlying Mach
//! nlist(_64) structure.
//----------------------------------------------------------------------------//
_mk_export uint32_t
mk_symbol_get_strx(mk_symbol_ref symbol);
_mk_export uint8_t
mk_symbol_get_type(mk_symbol_ref symbol);
_mk_export uint8_t
mk_symbol_get_sect(mk_symbol_ref symbol);
_mk_export int16_t
mk_symbol_get_desc(mk_symbol_ref symbol);
_mk_export uint64_t
mk_symbol_get_value(mk_symbol_ref symbol);
//! @} SYMBOLS !//
#endif /* _symbol_h */
|
4011ebefc4f9b41bb52a3901b9af48c3bb437db8
|
ae90aa32e949a5eab9665f526f886f05860161d2
|
/code/c/07-linux/01-thread/race.c
|
bdb17888e149ea2768ac063f9a24357e4f79ca4c
|
[
"CC-BY-SA-3.0",
"MIT"
] |
permissive
|
cccbook/sp
|
4097ab760cfb013b689dc4739a439de29d85d324
|
aff23e6b18ba6221022b14b024fd562427c46d9a
|
refs/heads/master
| 2022-05-22T03:31:33.324045
| 2019-06-06T07:04:37
| 2019-06-06T07:04:37
| 156,299,694
| 257
| 96
|
MIT
| 2022-03-19T08:48:32
| 2018-11-05T23:56:37
|
Assembly
|
UTF-8
|
C
| false
| false
| 511
|
c
|
race.c
|
#include <stdio.h>
#include <pthread.h>
#define LOOPS 100000000
int counter = 0;
void *inc()
{
for (int i=0; i<LOOPS; i++) {
counter = counter + 1;
}
return NULL;
}
void *dec()
{
for (int i=0; i<LOOPS; i++) {
counter = counter - 1;
}
return NULL;
}
int main()
{
pthread_t thread1, thread2;
pthread_create(&thread1, NULL, inc, NULL);
pthread_create(&thread2, NULL, dec, NULL);
pthread_join( thread1, NULL);
pthread_join( thread2, NULL);
printf("counter=%d\n", counter);
}
|
2264f0a1e5057cd461d1137b78024fdc8bca6ea2
|
7c857119fe1505b1d80d6e62969661c06dc1a2f4
|
/MdePkg/Include/Library/DxeServicesTableLib.h
|
5e90cc81fefa59772ce9f4c446bf6e6f57df4153
|
[
"BSD-2-Clause"
] |
permissive
|
CloverHackyColor/CloverBootloader
|
7042ca7dd6b513d22be591a295e49071ae1482ee
|
2711170df4f60b2ae5aa20add3e00f35cf57b7e5
|
refs/heads/master
| 2023-08-30T22:14:34.590134
| 2023-08-27T19:14:02
| 2023-08-27T19:14:02
| 205,810,121
| 4,734
| 770
|
BSD-2-Clause
| 2023-09-03T12:41:33
| 2019-09-02T08:22:14
|
C
|
UTF-8
|
C
| false
| false
| 1,057
|
h
|
DxeServicesTableLib.h
|
/** @file
Provides a service to retrieve a pointer to the DXE Services Table.
Only available to DXE module types.
This library does not contain any functions or macros. It simply exports a global
pointer to the DXE Services Table as defined in the Platform Initialization Driver
Execution Environment Core Interface Specification. The library constructor must
initialize this global pointer to the DX Services Table, so it is available at the
module's entry point. Since there is overhead in looking up the pointer to the DXE
Services Table, only those modules that actually require access to the DXE Services
Table should use this library. This will typically be DXE Drivers that require GCD
or Dispatcher services.
Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#ifndef __DXE_SERVICES_TABLE_LIB_H__
#define __DXE_SERVICES_TABLE_LIB_H__
///
/// Cache copy of the DXE Services Table
///
extern EFI_DXE_SERVICES *gDS;
#endif
|
5960760594dacce886feb41d1560ff68cb6170ec
|
6d54a7b26d0eb82152a549a6a9dfde656687752c
|
/scripts/tools/zap/tests/outputs/all-clusters-app/app-templates/gen_config.h
|
bf4dbc94ede3f7d6eb8c5aeab96b630f52e2862a
|
[
"Apache-2.0",
"LicenseRef-scancode-warranty-disclaimer"
] |
permissive
|
project-chip/connectedhomeip
|
81a123d675cf527773f70047d1ed1c43be5ffe6d
|
ea3970a7f11cd227ac55917edaa835a2a9bc4fc8
|
refs/heads/master
| 2023-09-01T11:43:37.546040
| 2023-09-01T08:01:32
| 2023-09-01T08:01:32
| 244,694,174
| 6,409
| 1,789
|
Apache-2.0
| 2023-09-14T20:56:31
| 2020-03-03T17:05:10
|
C++
|
UTF-8
|
C
| false
| false
| 20,557
|
h
|
gen_config.h
|
/*
*
* Copyright (c) 2022 Project CHIP Authors
*
* 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.
*/
// THIS FILE IS GENERATED BY ZAP
// Prevent multiple inclusion
#pragma once
/**** Cluster endpoint counts ****/
#define EMBER_AF_IDENTIFY_CLUSTER_SERVER_ENDPOINT_COUNT (3)
#define EMBER_AF_GROUPS_CLUSTER_SERVER_ENDPOINT_COUNT (3)
#define EMBER_AF_SCENES_CLUSTER_SERVER_ENDPOINT_COUNT (2)
#define EMBER_AF_ON_OFF_CLUSTER_SERVER_ENDPOINT_COUNT (2)
#define EMBER_AF_ON_OFF_SWITCH_CONFIGURATION_CLUSTER_SERVER_ENDPOINT_COUNT (1)
#define EMBER_AF_LEVEL_CONTROL_CLUSTER_SERVER_ENDPOINT_COUNT (1)
#define EMBER_AF_BINARY_INPUT_BASIC_CLUSTER_SERVER_ENDPOINT_COUNT (1)
#define EMBER_AF_DESCRIPTOR_CLUSTER_SERVER_ENDPOINT_COUNT (4)
#define EMBER_AF_BINDING_CLUSTER_SERVER_ENDPOINT_COUNT (2)
#define EMBER_AF_ACCESS_CONTROL_CLUSTER_SERVER_ENDPOINT_COUNT (1)
#define EMBER_AF_ACTIONS_CLUSTER_SERVER_ENDPOINT_COUNT (1)
#define EMBER_AF_BASIC_INFORMATION_CLUSTER_SERVER_ENDPOINT_COUNT (1)
#define EMBER_AF_OTA_SOFTWARE_UPDATE_PROVIDER_CLUSTER_CLIENT_ENDPOINT_COUNT (1)
#define EMBER_AF_OTA_SOFTWARE_UPDATE_REQUESTOR_CLUSTER_SERVER_ENDPOINT_COUNT (1)
#define EMBER_AF_LOCALIZATION_CONFIGURATION_CLUSTER_SERVER_ENDPOINT_COUNT (1)
#define EMBER_AF_TIME_FORMAT_LOCALIZATION_CLUSTER_SERVER_ENDPOINT_COUNT (1)
#define EMBER_AF_UNIT_LOCALIZATION_CLUSTER_SERVER_ENDPOINT_COUNT (1)
#define EMBER_AF_POWER_SOURCE_CLUSTER_SERVER_ENDPOINT_COUNT (3)
#define EMBER_AF_GENERAL_COMMISSIONING_CLUSTER_SERVER_ENDPOINT_COUNT (1)
#define EMBER_AF_NETWORK_COMMISSIONING_CLUSTER_SERVER_ENDPOINT_COUNT (2)
#define EMBER_AF_DIAGNOSTIC_LOGS_CLUSTER_SERVER_ENDPOINT_COUNT (1)
#define EMBER_AF_GENERAL_DIAGNOSTICS_CLUSTER_SERVER_ENDPOINT_COUNT (1)
#define EMBER_AF_SOFTWARE_DIAGNOSTICS_CLUSTER_SERVER_ENDPOINT_COUNT (1)
#define EMBER_AF_THREAD_NETWORK_DIAGNOSTICS_CLUSTER_SERVER_ENDPOINT_COUNT (1)
#define EMBER_AF_WIFI_NETWORK_DIAGNOSTICS_CLUSTER_SERVER_ENDPOINT_COUNT (1)
#define EMBER_AF_ETHERNET_NETWORK_DIAGNOSTICS_CLUSTER_SERVER_ENDPOINT_COUNT (1)
#define EMBER_AF_SWITCH_CLUSTER_SERVER_ENDPOINT_COUNT (1)
#define EMBER_AF_ADMINISTRATOR_COMMISSIONING_CLUSTER_SERVER_ENDPOINT_COUNT (1)
#define EMBER_AF_OPERATIONAL_CREDENTIALS_CLUSTER_SERVER_ENDPOINT_COUNT (1)
#define EMBER_AF_GROUP_KEY_MANAGEMENT_CLUSTER_SERVER_ENDPOINT_COUNT (1)
#define EMBER_AF_FIXED_LABEL_CLUSTER_SERVER_ENDPOINT_COUNT (2)
#define EMBER_AF_USER_LABEL_CLUSTER_SERVER_ENDPOINT_COUNT (2)
#define EMBER_AF_BOOLEAN_STATE_CLUSTER_SERVER_ENDPOINT_COUNT (1)
#define EMBER_AF_MODE_SELECT_CLUSTER_SERVER_ENDPOINT_COUNT (1)
#define EMBER_AF_DOOR_LOCK_CLUSTER_SERVER_ENDPOINT_COUNT (1)
#define EMBER_AF_WINDOW_COVERING_CLUSTER_SERVER_ENDPOINT_COUNT (1)
#define EMBER_AF_BARRIER_CONTROL_CLUSTER_SERVER_ENDPOINT_COUNT (1)
#define EMBER_AF_PUMP_CONFIGURATION_AND_CONTROL_CLUSTER_SERVER_ENDPOINT_COUNT (1)
#define EMBER_AF_THERMOSTAT_CLUSTER_SERVER_ENDPOINT_COUNT (1)
#define EMBER_AF_FAN_CONTROL_CLUSTER_SERVER_ENDPOINT_COUNT (1)
#define EMBER_AF_THERMOSTAT_USER_INTERFACE_CONFIGURATION_CLUSTER_SERVER_ENDPOINT_COUNT (1)
#define EMBER_AF_COLOR_CONTROL_CLUSTER_SERVER_ENDPOINT_COUNT (1)
#define EMBER_AF_ILLUMINANCE_MEASUREMENT_CLUSTER_SERVER_ENDPOINT_COUNT (1)
#define EMBER_AF_TEMPERATURE_MEASUREMENT_CLUSTER_SERVER_ENDPOINT_COUNT (1)
#define EMBER_AF_PRESSURE_MEASUREMENT_CLUSTER_SERVER_ENDPOINT_COUNT (1)
#define EMBER_AF_FLOW_MEASUREMENT_CLUSTER_SERVER_ENDPOINT_COUNT (1)
#define EMBER_AF_RELATIVE_HUMIDITY_MEASUREMENT_CLUSTER_SERVER_ENDPOINT_COUNT (2)
#define EMBER_AF_OCCUPANCY_SENSING_CLUSTER_SERVER_ENDPOINT_COUNT (2)
#define EMBER_AF_WAKE_ON_LAN_CLUSTER_SERVER_ENDPOINT_COUNT (1)
#define EMBER_AF_CHANNEL_CLUSTER_SERVER_ENDPOINT_COUNT (1)
#define EMBER_AF_TARGET_NAVIGATOR_CLUSTER_SERVER_ENDPOINT_COUNT (1)
#define EMBER_AF_MEDIA_PLAYBACK_CLUSTER_SERVER_ENDPOINT_COUNT (1)
#define EMBER_AF_MEDIA_INPUT_CLUSTER_SERVER_ENDPOINT_COUNT (1)
#define EMBER_AF_LOW_POWER_CLUSTER_SERVER_ENDPOINT_COUNT (1)
#define EMBER_AF_KEYPAD_INPUT_CLUSTER_SERVER_ENDPOINT_COUNT (1)
#define EMBER_AF_CONTENT_LAUNCHER_CLUSTER_SERVER_ENDPOINT_COUNT (1)
#define EMBER_AF_AUDIO_OUTPUT_CLUSTER_SERVER_ENDPOINT_COUNT (1)
#define EMBER_AF_APPLICATION_LAUNCHER_CLUSTER_SERVER_ENDPOINT_COUNT (1)
#define EMBER_AF_APPLICATION_BASIC_CLUSTER_SERVER_ENDPOINT_COUNT (1)
#define EMBER_AF_ACCOUNT_LOGIN_CLUSTER_SERVER_ENDPOINT_COUNT (1)
#define EMBER_AF_ELECTRICAL_MEASUREMENT_CLUSTER_SERVER_ENDPOINT_COUNT (1)
#define EMBER_AF_UNIT_TESTING_CLUSTER_SERVER_ENDPOINT_COUNT (1)
#define EMBER_AF_FAULT_INJECTION_CLUSTER_SERVER_ENDPOINT_COUNT (1)
/**** Cluster Plugins ****/
// Use this macro to check if the server side of the Identify cluster is included
#define ZCL_USING_IDENTIFY_CLUSTER_SERVER
#define EMBER_AF_PLUGIN_IDENTIFY_SERVER
#define EMBER_AF_PLUGIN_IDENTIFY
// Use this macro to check if the server side of the Groups cluster is included
#define ZCL_USING_GROUPS_CLUSTER_SERVER
#define EMBER_AF_PLUGIN_GROUPS_SERVER
#define EMBER_AF_PLUGIN_GROUPS
// Use this macro to check if the server side of the Scenes cluster is included
#define ZCL_USING_SCENES_CLUSTER_SERVER
#define EMBER_AF_PLUGIN_SCENES_SERVER
#define EMBER_AF_PLUGIN_SCENES
// User options for server plugin Scenes
// Cluster spec 1.4.8.2
#ifdef CHIP_CONFIG_MAX_SCENES_PER_FABRIC
#define MATTER_SCENES_TABLE_SIZE CHIP_CONFIG_MAX_SCENES_PER_FABRIC
#else
#define MATTER_SCENES_TABLE_SIZE 16
#endif
// Scenes FeatureMap Attribute Toggle Scenes Name feature
// App cluster specs 1.4.4
#define MATTER_CLUSTER_SCENE_NAME_SUPPORT_MASK 0x0001
#define MATTER_CLUSTER_SCENE_NAME_SUPPORT (0x0000 & MATTER_CLUSTER_SCENE_NAME_SUPPORT_MASK)
// Use this macro to check if the server side of the On/Off cluster is included
#define ZCL_USING_ON_OFF_CLUSTER_SERVER
#define EMBER_AF_PLUGIN_ON_OFF_SERVER
#define EMBER_AF_PLUGIN_ON_OFF
// Use this macro to check if the server side of the On/off Switch Configuration cluster is included
#define ZCL_USING_ON_OFF_SWITCH_CONFIGURATION_CLUSTER_SERVER
#define EMBER_AF_PLUGIN_ON_OFF_SWITCH_CONFIGURATION_SERVER
#define EMBER_AF_PLUGIN_ON_OFF_SWITCH_CONFIGURATION
// Use this macro to check if the server side of the Level Control cluster is included
#define ZCL_USING_LEVEL_CONTROL_CLUSTER_SERVER
#define EMBER_AF_PLUGIN_LEVEL_CONTROL_SERVER
#define EMBER_AF_PLUGIN_LEVEL_CONTROL
// User options for server plugin Level Control
#define EMBER_AF_PLUGIN_LEVEL_CONTROL_MAXIMUM_LEVEL 254
#define EMBER_AF_PLUGIN_LEVEL_CONTROL_MINIMUM_LEVEL 0
#define EMBER_AF_PLUGIN_LEVEL_CONTROL_RATE 0
// Use this macro to check if the server side of the Binary Input (Basic) cluster is included
#define ZCL_USING_BINARY_INPUT_BASIC_CLUSTER_SERVER
#define EMBER_AF_PLUGIN_BINARY_INPUT_BASIC_SERVER
#define EMBER_AF_PLUGIN_BINARY_INPUT_BASIC
// Use this macro to check if the server side of the Descriptor cluster is included
#define ZCL_USING_DESCRIPTOR_CLUSTER_SERVER
#define EMBER_AF_PLUGIN_DESCRIPTOR_SERVER
#define EMBER_AF_PLUGIN_DESCRIPTOR
// Use this macro to check if the server side of the Binding cluster is included
#define ZCL_USING_BINDING_CLUSTER_SERVER
#define EMBER_AF_PLUGIN_BINDING_SERVER
#define EMBER_AF_PLUGIN_BINDING
// Use this macro to check if the server side of the Access Control cluster is included
#define ZCL_USING_ACCESS_CONTROL_CLUSTER_SERVER
#define EMBER_AF_PLUGIN_ACCESS_CONTROL_SERVER
#define EMBER_AF_PLUGIN_ACCESS_CONTROL
// Use this macro to check if the server side of the Actions cluster is included
#define ZCL_USING_ACTIONS_CLUSTER_SERVER
#define EMBER_AF_PLUGIN_ACTIONS_SERVER
#define EMBER_AF_PLUGIN_ACTIONS
// Use this macro to check if the server side of the Basic Information cluster is included
#define ZCL_USING_BASIC_INFORMATION_CLUSTER_SERVER
#define EMBER_AF_PLUGIN_BASIC_INFORMATION_SERVER
#define EMBER_AF_PLUGIN_BASIC_INFORMATION
// Use this macro to check if the client side of the OTA Software Update Provider cluster is included
#define ZCL_USING_OTA_SOFTWARE_UPDATE_PROVIDER_CLUSTER_CLIENT
#define EMBER_AF_PLUGIN_OTA_SOFTWARE_UPDATE_PROVIDER_CLIENT
// Use this macro to check if the server side of the OTA Software Update Requestor cluster is included
#define ZCL_USING_OTA_SOFTWARE_UPDATE_REQUESTOR_CLUSTER_SERVER
#define EMBER_AF_PLUGIN_OTA_SOFTWARE_UPDATE_REQUESTOR_SERVER
#define EMBER_AF_PLUGIN_OTA_SOFTWARE_UPDATE_REQUESTOR
// Use this macro to check if the server side of the Localization Configuration cluster is included
#define ZCL_USING_LOCALIZATION_CONFIGURATION_CLUSTER_SERVER
#define EMBER_AF_PLUGIN_LOCALIZATION_CONFIGURATION_SERVER
#define EMBER_AF_PLUGIN_LOCALIZATION_CONFIGURATION
// Use this macro to check if the server side of the Time Format Localization cluster is included
#define ZCL_USING_TIME_FORMAT_LOCALIZATION_CLUSTER_SERVER
#define EMBER_AF_PLUGIN_TIME_FORMAT_LOCALIZATION_SERVER
#define EMBER_AF_PLUGIN_TIME_FORMAT_LOCALIZATION
// Use this macro to check if the server side of the Unit Localization cluster is included
#define ZCL_USING_UNIT_LOCALIZATION_CLUSTER_SERVER
#define EMBER_AF_PLUGIN_UNIT_LOCALIZATION_SERVER
#define EMBER_AF_PLUGIN_UNIT_LOCALIZATION
// Use this macro to check if the server side of the Power Source cluster is included
#define ZCL_USING_POWER_SOURCE_CLUSTER_SERVER
#define EMBER_AF_PLUGIN_POWER_SOURCE_SERVER
#define EMBER_AF_PLUGIN_POWER_SOURCE
// Use this macro to check if the server side of the General Commissioning cluster is included
#define ZCL_USING_GENERAL_COMMISSIONING_CLUSTER_SERVER
#define EMBER_AF_PLUGIN_GENERAL_COMMISSIONING_SERVER
#define EMBER_AF_PLUGIN_GENERAL_COMMISSIONING
// Use this macro to check if the server side of the Network Commissioning cluster is included
#define ZCL_USING_NETWORK_COMMISSIONING_CLUSTER_SERVER
#define EMBER_AF_PLUGIN_NETWORK_COMMISSIONING_SERVER
#define EMBER_AF_PLUGIN_NETWORK_COMMISSIONING
// Use this macro to check if the server side of the Diagnostic Logs cluster is included
#define ZCL_USING_DIAGNOSTIC_LOGS_CLUSTER_SERVER
#define EMBER_AF_PLUGIN_DIAGNOSTIC_LOGS_SERVER
#define EMBER_AF_PLUGIN_DIAGNOSTIC_LOGS
// Use this macro to check if the server side of the General Diagnostics cluster is included
#define ZCL_USING_GENERAL_DIAGNOSTICS_CLUSTER_SERVER
#define EMBER_AF_PLUGIN_GENERAL_DIAGNOSTICS_SERVER
#define EMBER_AF_PLUGIN_GENERAL_DIAGNOSTICS
// Use this macro to check if the server side of the Software Diagnostics cluster is included
#define ZCL_USING_SOFTWARE_DIAGNOSTICS_CLUSTER_SERVER
#define EMBER_AF_PLUGIN_SOFTWARE_DIAGNOSTICS_SERVER
#define EMBER_AF_PLUGIN_SOFTWARE_DIAGNOSTICS
// Use this macro to check if the server side of the Thread Network Diagnostics cluster is included
#define ZCL_USING_THREAD_NETWORK_DIAGNOSTICS_CLUSTER_SERVER
#define EMBER_AF_PLUGIN_THREAD_NETWORK_DIAGNOSTICS_SERVER
#define EMBER_AF_PLUGIN_THREAD_NETWORK_DIAGNOSTICS
// Use this macro to check if the server side of the WiFi Network Diagnostics cluster is included
#define ZCL_USING_WIFI_NETWORK_DIAGNOSTICS_CLUSTER_SERVER
#define EMBER_AF_PLUGIN_WI_FI_NETWORK_DIAGNOSTICS_SERVER
#define EMBER_AF_PLUGIN_WI_FI_NETWORK_DIAGNOSTICS
// Use this macro to check if the server side of the Ethernet Network Diagnostics cluster is included
#define ZCL_USING_ETHERNET_NETWORK_DIAGNOSTICS_CLUSTER_SERVER
#define EMBER_AF_PLUGIN_ETHERNET_NETWORK_DIAGNOSTICS_SERVER
#define EMBER_AF_PLUGIN_ETHERNET_NETWORK_DIAGNOSTICS
// Use this macro to check if the server side of the Switch cluster is included
#define ZCL_USING_SWITCH_CLUSTER_SERVER
#define EMBER_AF_PLUGIN_SWITCH_SERVER
#define EMBER_AF_PLUGIN_SWITCH
// Use this macro to check if the server side of the Administrator Commissioning cluster is included
#define ZCL_USING_ADMINISTRATOR_COMMISSIONING_CLUSTER_SERVER
#define EMBER_AF_PLUGIN_ADMINISTRATOR_COMMISSIONING_SERVER
#define EMBER_AF_PLUGIN_ADMINISTRATOR_COMMISSIONING
// Use this macro to check if the server side of the Operational Credentials cluster is included
#define ZCL_USING_OPERATIONAL_CREDENTIALS_CLUSTER_SERVER
#define EMBER_AF_PLUGIN_OPERATIONAL_CREDENTIALS_SERVER
#define EMBER_AF_PLUGIN_OPERATIONAL_CREDENTIALS
// Use this macro to check if the server side of the Group Key Management cluster is included
#define ZCL_USING_GROUP_KEY_MANAGEMENT_CLUSTER_SERVER
#define EMBER_AF_PLUGIN_GROUP_KEY_MANAGEMENT_SERVER
#define EMBER_AF_PLUGIN_GROUP_KEY_MANAGEMENT
// Use this macro to check if the server side of the Fixed Label cluster is included
#define ZCL_USING_FIXED_LABEL_CLUSTER_SERVER
#define EMBER_AF_PLUGIN_FIXED_LABEL_SERVER
#define EMBER_AF_PLUGIN_FIXED_LABEL
// Use this macro to check if the server side of the User Label cluster is included
#define ZCL_USING_USER_LABEL_CLUSTER_SERVER
#define EMBER_AF_PLUGIN_USER_LABEL_SERVER
#define EMBER_AF_PLUGIN_USER_LABEL
// Use this macro to check if the server side of the Boolean State cluster is included
#define ZCL_USING_BOOLEAN_STATE_CLUSTER_SERVER
#define EMBER_AF_PLUGIN_BOOLEAN_STATE_SERVER
#define EMBER_AF_PLUGIN_BOOLEAN_STATE
// Use this macro to check if the server side of the Mode Select cluster is included
#define ZCL_USING_MODE_SELECT_CLUSTER_SERVER
#define EMBER_AF_PLUGIN_MODE_SELECT_SERVER
#define EMBER_AF_PLUGIN_MODE_SELECT
// Use this macro to check if the server side of the Door Lock cluster is included
#define ZCL_USING_DOOR_LOCK_CLUSTER_SERVER
#define EMBER_AF_PLUGIN_DOOR_LOCK_SERVER
#define EMBER_AF_PLUGIN_DOOR_LOCK
// Use this macro to check if the server side of the Window Covering cluster is included
#define ZCL_USING_WINDOW_COVERING_CLUSTER_SERVER
#define EMBER_AF_PLUGIN_WINDOW_COVERING_SERVER
#define EMBER_AF_PLUGIN_WINDOW_COVERING
// Use this macro to check if the server side of the Barrier Control cluster is included
#define ZCL_USING_BARRIER_CONTROL_CLUSTER_SERVER
#define EMBER_AF_PLUGIN_BARRIER_CONTROL_SERVER
#define EMBER_AF_PLUGIN_BARRIER_CONTROL
// Use this macro to check if the server side of the Pump Configuration and Control cluster is included
#define ZCL_USING_PUMP_CONFIGURATION_AND_CONTROL_CLUSTER_SERVER
#define EMBER_AF_PLUGIN_PUMP_CONFIGURATION_AND_CONTROL_SERVER
#define EMBER_AF_PLUGIN_PUMP_CONFIGURATION_AND_CONTROL
// Use this macro to check if the server side of the Thermostat cluster is included
#define ZCL_USING_THERMOSTAT_CLUSTER_SERVER
#define EMBER_AF_PLUGIN_THERMOSTAT_SERVER
#define EMBER_AF_PLUGIN_THERMOSTAT
// Use this macro to check if the server side of the Fan Control cluster is included
#define ZCL_USING_FAN_CONTROL_CLUSTER_SERVER
#define EMBER_AF_PLUGIN_FAN_CONTROL_SERVER
#define EMBER_AF_PLUGIN_FAN_CONTROL
// Use this macro to check if the server side of the Thermostat User Interface Configuration cluster is included
#define ZCL_USING_THERMOSTAT_USER_INTERFACE_CONFIGURATION_CLUSTER_SERVER
#define EMBER_AF_PLUGIN_THERMOSTAT_USER_INTERFACE_CONFIGURATION_SERVER
#define EMBER_AF_PLUGIN_THERMOSTAT_USER_INTERFACE_CONFIGURATION
// Use this macro to check if the server side of the Color Control cluster is included
#define ZCL_USING_COLOR_CONTROL_CLUSTER_SERVER
#define EMBER_AF_PLUGIN_COLOR_CONTROL_SERVER
#define EMBER_AF_PLUGIN_COLOR_CONTROL
// User options for server plugin Color Control
#define EMBER_AF_PLUGIN_COLOR_CONTROL_SERVER_XY
#define EMBER_AF_PLUGIN_COLOR_CONTROL_SERVER_TEMP
#define EMBER_AF_PLUGIN_COLOR_CONTROL_SERVER_HSV
// Use this macro to check if the server side of the Illuminance Measurement cluster is included
#define ZCL_USING_ILLUMINANCE_MEASUREMENT_CLUSTER_SERVER
#define EMBER_AF_PLUGIN_ILLUMINANCE_MEASUREMENT_SERVER
#define EMBER_AF_PLUGIN_ILLUMINANCE_MEASUREMENT
// Use this macro to check if the server side of the Temperature Measurement cluster is included
#define ZCL_USING_TEMPERATURE_MEASUREMENT_CLUSTER_SERVER
#define EMBER_AF_PLUGIN_TEMPERATURE_MEASUREMENT_SERVER
#define EMBER_AF_PLUGIN_TEMPERATURE_MEASUREMENT
// Use this macro to check if the server side of the Pressure Measurement cluster is included
#define ZCL_USING_PRESSURE_MEASUREMENT_CLUSTER_SERVER
#define EMBER_AF_PLUGIN_PRESSURE_MEASUREMENT_SERVER
#define EMBER_AF_PLUGIN_PRESSURE_MEASUREMENT
// Use this macro to check if the server side of the Flow Measurement cluster is included
#define ZCL_USING_FLOW_MEASUREMENT_CLUSTER_SERVER
#define EMBER_AF_PLUGIN_FLOW_MEASUREMENT_SERVER
#define EMBER_AF_PLUGIN_FLOW_MEASUREMENT
// Use this macro to check if the server side of the Relative Humidity Measurement cluster is included
#define ZCL_USING_RELATIVE_HUMIDITY_MEASUREMENT_CLUSTER_SERVER
#define EMBER_AF_PLUGIN_RELATIVE_HUMIDITY_MEASUREMENT_SERVER
#define EMBER_AF_PLUGIN_RELATIVE_HUMIDITY_MEASUREMENT
// Use this macro to check if the server side of the Occupancy Sensing cluster is included
#define ZCL_USING_OCCUPANCY_SENSING_CLUSTER_SERVER
#define EMBER_AF_PLUGIN_OCCUPANCY_SENSING_SERVER
#define EMBER_AF_PLUGIN_OCCUPANCY_SENSING
// Use this macro to check if the server side of the Wake on LAN cluster is included
#define ZCL_USING_WAKE_ON_LAN_CLUSTER_SERVER
#define EMBER_AF_PLUGIN_WAKE_ON_LAN_SERVER
#define EMBER_AF_PLUGIN_WAKE_ON_LAN
// Use this macro to check if the server side of the Channel cluster is included
#define ZCL_USING_CHANNEL_CLUSTER_SERVER
#define EMBER_AF_PLUGIN_CHANNEL_SERVER
#define EMBER_AF_PLUGIN_CHANNEL
// Use this macro to check if the server side of the Target Navigator cluster is included
#define ZCL_USING_TARGET_NAVIGATOR_CLUSTER_SERVER
#define EMBER_AF_PLUGIN_TARGET_NAVIGATOR_SERVER
#define EMBER_AF_PLUGIN_TARGET_NAVIGATOR
// Use this macro to check if the server side of the Media Playback cluster is included
#define ZCL_USING_MEDIA_PLAYBACK_CLUSTER_SERVER
#define EMBER_AF_PLUGIN_MEDIA_PLAYBACK_SERVER
#define EMBER_AF_PLUGIN_MEDIA_PLAYBACK
// Use this macro to check if the server side of the Media Input cluster is included
#define ZCL_USING_MEDIA_INPUT_CLUSTER_SERVER
#define EMBER_AF_PLUGIN_MEDIA_INPUT_SERVER
#define EMBER_AF_PLUGIN_MEDIA_INPUT
// Use this macro to check if the server side of the Low Power cluster is included
#define ZCL_USING_LOW_POWER_CLUSTER_SERVER
#define EMBER_AF_PLUGIN_LOW_POWER_SERVER
#define EMBER_AF_PLUGIN_LOW_POWER
// Use this macro to check if the server side of the Keypad Input cluster is included
#define ZCL_USING_KEYPAD_INPUT_CLUSTER_SERVER
#define EMBER_AF_PLUGIN_KEYPAD_INPUT_SERVER
#define EMBER_AF_PLUGIN_KEYPAD_INPUT
// Use this macro to check if the server side of the Content Launcher cluster is included
#define ZCL_USING_CONTENT_LAUNCHER_CLUSTER_SERVER
#define EMBER_AF_PLUGIN_CONTENT_LAUNCHER_SERVER
#define EMBER_AF_PLUGIN_CONTENT_LAUNCHER
// Use this macro to check if the server side of the Audio Output cluster is included
#define ZCL_USING_AUDIO_OUTPUT_CLUSTER_SERVER
#define EMBER_AF_PLUGIN_AUDIO_OUTPUT_SERVER
#define EMBER_AF_PLUGIN_AUDIO_OUTPUT
// Use this macro to check if the server side of the Application Launcher cluster is included
#define ZCL_USING_APPLICATION_LAUNCHER_CLUSTER_SERVER
#define EMBER_AF_PLUGIN_APPLICATION_LAUNCHER_SERVER
#define EMBER_AF_PLUGIN_APPLICATION_LAUNCHER
// Use this macro to check if the server side of the Application Basic cluster is included
#define ZCL_USING_APPLICATION_BASIC_CLUSTER_SERVER
#define EMBER_AF_PLUGIN_APPLICATION_BASIC_SERVER
#define EMBER_AF_PLUGIN_APPLICATION_BASIC
// Use this macro to check if the server side of the Account Login cluster is included
#define ZCL_USING_ACCOUNT_LOGIN_CLUSTER_SERVER
#define EMBER_AF_PLUGIN_ACCOUNT_LOGIN_SERVER
#define EMBER_AF_PLUGIN_ACCOUNT_LOGIN
// Use this macro to check if the server side of the Electrical Measurement cluster is included
#define ZCL_USING_ELECTRICAL_MEASUREMENT_CLUSTER_SERVER
#define EMBER_AF_PLUGIN_ELECTRICAL_MEASUREMENT_SERVER
#define EMBER_AF_PLUGIN_ELECTRICAL_MEASUREMENT
// Use this macro to check if the server side of the Unit Testing cluster is included
#define ZCL_USING_UNIT_TESTING_CLUSTER_SERVER
#define EMBER_AF_PLUGIN_UNIT_TESTING_SERVER
#define EMBER_AF_PLUGIN_UNIT_TESTING
// Use this macro to check if the server side of the Fault Injection cluster is included
#define ZCL_USING_FAULT_INJECTION_CLUSTER_SERVER
#define EMBER_AF_PLUGIN_FAULT_INJECTION_SERVER
#define EMBER_AF_PLUGIN_FAULT_INJECTION
|
cd690745ebd95ae65e9f601985ca20621337df7e
|
fb0f9abad373cd635c2635bbdf491ea0f32da5ff
|
/src/mono/mono/utils/mono-poll.h
|
4293cf884cd44e4aaa2a4ab37dc1e58e3504bfa1
|
[
"MIT"
] |
permissive
|
dotnet/runtime
|
f6fd23936752e202f8e4d6d94f3a4f3b0e77f58f
|
47bb554d298e1e34c4e3895d7731e18ad1c47d02
|
refs/heads/main
| 2023-09-03T15:35:46.493337
| 2023-09-03T08:13:23
| 2023-09-03T08:13:23
| 210,716,005
| 13,765
| 5,179
|
MIT
| 2023-09-14T21:58:52
| 2019-09-24T23:36:39
|
C#
|
UTF-8
|
C
| false
| false
| 1,031
|
h
|
mono-poll.h
|
/**
* \file
*/
#ifndef MONO_POLL_H
#define MONO_POLL_H
#include <mono/utils/mono-publib.h>
#include <config.h>
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
#include <sys/types.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef HAVE_POLL
#ifdef HAVE_POLL_H
#include <poll.h>
#elif defined(HAVE_SYS_POLL_H)
#include <sys/poll.h>
#endif
#define MONO_POLLIN POLLIN
#define MONO_POLLPRI POLLPRI
#define MONO_POLLOUT POLLOUT
#define MONO_POLLERR POLLERR
#define MONO_POLLHUP POLLHUP
#define MONO_POLLNVAL POLLNVAL
typedef struct pollfd mono_pollfd;
#else
#ifdef HOST_WIN32
#include <windows.h>
#endif
#define MONO_POLLIN 1
#define MONO_POLLPRI 2
#define MONO_POLLOUT 4
#define MONO_POLLERR 8
#define MONO_POLLHUP 0x10
#define MONO_POLLNVAL 0x20
typedef struct {
int fd;
short events;
short revents;
} mono_pollfd;
#endif
int
mono_poll_can_add (mono_pollfd *ufds, unsigned int nfds, int fd);
MONO_API int mono_poll (mono_pollfd *ufds, unsigned int nfds, int timeout);
#endif /* MONO_POLL_H */
|
18bbb2a946ffe0efacce30ef5c3765a05067a472
|
88ae8695987ada722184307301e221e1ba3cc2fa
|
/third_party/eigen3/src/lapack/lapack_common.h
|
5ca6dd79c7e6598f6735432de13cad91dfc86823
|
[
"Apache-2.0",
"LGPL-2.0-or-later",
"MIT",
"GPL-1.0-or-later",
"BSD-3-Clause",
"LicenseRef-scancode-unknown-license-reference",
"MPL-2.0",
"Minpack"
] |
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
| 859
|
h
|
lapack_common.h
|
// This file is part of Eigen, a lightweight C++ template library
// for linear algebra.
//
// Copyright (C) 2010-2014 Gael Guennebaud <gael.guennebaud@inria.fr>
//
// This Source Code Form is subject to the terms of the Mozilla
// Public License v. 2.0. If a copy of the MPL was not distributed
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
#ifndef EIGEN_LAPACK_COMMON_H
#define EIGEN_LAPACK_COMMON_H
#include "../blas/common.h"
#include "lapack.h"
#define EIGEN_LAPACK_FUNC(FUNC,ARGLIST) \
extern "C" { int EIGEN_BLAS_FUNC(FUNC) ARGLIST; } \
int EIGEN_BLAS_FUNC(FUNC) ARGLIST
typedef Eigen::Map<Eigen::Transpositions<Eigen::Dynamic,Eigen::Dynamic,int> > PivotsType;
#if ISCOMPLEX
#define EIGEN_LAPACK_ARG_IF_COMPLEX(X) X,
#else
#define EIGEN_LAPACK_ARG_IF_COMPLEX(X)
#endif
#endif // EIGEN_LAPACK_COMMON_H
|
2eafe1e0fef546c7dcd445712515656046d6878c
|
2ef0e696b0b8d1b762a3df21a258406f1e0c73e2
|
/include/EASTL/internal/atomic/compiler/gcc/compiler_gcc_and_fetch.h
|
a35307f018a462d1b297e3ddf1b4ab9c7b002089
|
[
"BSD-3-Clause"
] |
permissive
|
electronicarts/EASTL
|
3fdf65152aaadae7c86e94aa482b950494f31c2f
|
05f4b4aef33f2f3ded08f19fa97f5a27ff35ff9f
|
refs/heads/master
| 2023-08-30T16:35:49.267717
| 2023-08-16T17:55:47
| 2023-08-16T17:55:47
| 48,068,902
| 7,952
| 1,216
|
BSD-3-Clause
| 2023-08-16T17:55:48
| 2015-12-15T21:04:13
|
C++
|
UTF-8
|
C
| false
| false
| 5,231
|
h
|
compiler_gcc_and_fetch.h
|
/////////////////////////////////////////////////////////////////////////////////
// Copyright (c) Electronic Arts Inc. All rights reserved.
/////////////////////////////////////////////////////////////////////////////////
#ifndef EASTL_ATOMIC_INTERNAL_COMPILER_GCC_AND_FETCH_H
#define EASTL_ATOMIC_INTERNAL_COMPILER_GCC_AND_FETCH_H
#if defined(EA_PRAGMA_ONCE_SUPPORTED)
#pragma once
#endif
#define EASTL_GCC_ATOMIC_AND_FETCH_N(integralType, type, ret, ptr, val, gccMemoryOrder) \
EASTL_GCC_ATOMIC_FETCH_INTRIN_N(integralType, __atomic_and_fetch, type, ret, ptr, val, gccMemoryOrder)
#define EASTL_GCC_ATOMIC_AND_FETCH_8(type, ret, ptr, val, gccMemoryOrder) \
EASTL_GCC_ATOMIC_AND_FETCH_N(uint8_t, type, ret, ptr, val, gccMemoryOrder)
#define EASTL_GCC_ATOMIC_AND_FETCH_16(type, ret, ptr, val, gccMemoryOrder) \
EASTL_GCC_ATOMIC_AND_FETCH_N(uint16_t, type, ret, ptr, val, gccMemoryOrder)
#define EASTL_GCC_ATOMIC_AND_FETCH_32(type, ret, ptr, val, gccMemoryOrder) \
EASTL_GCC_ATOMIC_AND_FETCH_N(uint32_t, type, ret, ptr, val, gccMemoryOrder)
#define EASTL_GCC_ATOMIC_AND_FETCH_64(type, ret, ptr, val, gccMemoryOrder) \
EASTL_GCC_ATOMIC_AND_FETCH_N(uint64_t, type, ret, ptr, val, gccMemoryOrder)
#define EASTL_GCC_ATOMIC_AND_FETCH_128(type, ret, ptr, val, gccMemoryOrder) \
EASTL_GCC_ATOMIC_AND_FETCH_N(__uint128_t, type, ret, ptr, val, gccMemoryOrder)
/////////////////////////////////////////////////////////////////////////////////
//
// void EASTL_COMPILER_ATOMIC_AND_FETCH_*_N(type, type ret, type * ptr, type val)
//
#define EASTL_COMPILER_ATOMIC_AND_FETCH_RELAXED_8(type, ret, ptr, val) \
EASTL_GCC_ATOMIC_AND_FETCH_8(type, ret, ptr, val, __ATOMIC_RELAXED)
#define EASTL_COMPILER_ATOMIC_AND_FETCH_RELAXED_16(type, ret, ptr, val) \
EASTL_GCC_ATOMIC_AND_FETCH_16(type, ret, ptr, val, __ATOMIC_RELAXED)
#define EASTL_COMPILER_ATOMIC_AND_FETCH_RELAXED_32(type, ret, ptr, val) \
EASTL_GCC_ATOMIC_AND_FETCH_32(type, ret, ptr, val, __ATOMIC_RELAXED)
#define EASTL_COMPILER_ATOMIC_AND_FETCH_RELAXED_64(type, ret, ptr, val) \
EASTL_GCC_ATOMIC_AND_FETCH_64(type, ret, ptr, val, __ATOMIC_RELAXED)
#define EASTL_COMPILER_ATOMIC_AND_FETCH_RELAXED_128(type, ret, ptr, val) \
EASTL_GCC_ATOMIC_AND_FETCH_128(type, ret, ptr, val, __ATOMIC_RELAXED)
#define EASTL_COMPILER_ATOMIC_AND_FETCH_ACQUIRE_8(type, ret, ptr, val) \
EASTL_GCC_ATOMIC_AND_FETCH_8(type, ret, ptr, val, __ATOMIC_ACQUIRE)
#define EASTL_COMPILER_ATOMIC_AND_FETCH_ACQUIRE_16(type, ret, ptr, val) \
EASTL_GCC_ATOMIC_AND_FETCH_16(type, ret, ptr, val, __ATOMIC_ACQUIRE)
#define EASTL_COMPILER_ATOMIC_AND_FETCH_ACQUIRE_32(type, ret, ptr, val) \
EASTL_GCC_ATOMIC_AND_FETCH_32(type, ret, ptr, val, __ATOMIC_ACQUIRE)
#define EASTL_COMPILER_ATOMIC_AND_FETCH_ACQUIRE_64(type, ret, ptr, val) \
EASTL_GCC_ATOMIC_AND_FETCH_64(type, ret, ptr, val, __ATOMIC_ACQUIRE)
#define EASTL_COMPILER_ATOMIC_AND_FETCH_ACQUIRE_128(type, ret, ptr, val) \
EASTL_GCC_ATOMIC_AND_FETCH_128(type, ret, ptr, val, __ATOMIC_ACQUIRE)
#define EASTL_COMPILER_ATOMIC_AND_FETCH_RELEASE_8(type, ret, ptr, val) \
EASTL_GCC_ATOMIC_AND_FETCH_8(type, ret, ptr, val, __ATOMIC_RELEASE)
#define EASTL_COMPILER_ATOMIC_AND_FETCH_RELEASE_16(type, ret, ptr, val) \
EASTL_GCC_ATOMIC_AND_FETCH_16(type, ret, ptr, val, __ATOMIC_RELEASE)
#define EASTL_COMPILER_ATOMIC_AND_FETCH_RELEASE_32(type, ret, ptr, val) \
EASTL_GCC_ATOMIC_AND_FETCH_32(type, ret, ptr, val, __ATOMIC_RELEASE)
#define EASTL_COMPILER_ATOMIC_AND_FETCH_RELEASE_64(type, ret, ptr, val) \
EASTL_GCC_ATOMIC_AND_FETCH_64(type, ret, ptr, val, __ATOMIC_RELEASE)
#define EASTL_COMPILER_ATOMIC_AND_FETCH_RELEASE_128(type, ret, ptr, val) \
EASTL_GCC_ATOMIC_AND_FETCH_128(type, ret, ptr, val, __ATOMIC_RELEASE)
#define EASTL_COMPILER_ATOMIC_AND_FETCH_ACQ_REL_8(type, ret, ptr, val) \
EASTL_GCC_ATOMIC_AND_FETCH_8(type, ret, ptr, val, __ATOMIC_ACQ_REL)
#define EASTL_COMPILER_ATOMIC_AND_FETCH_ACQ_REL_16(type, ret, ptr, val) \
EASTL_GCC_ATOMIC_AND_FETCH_16(type, ret, ptr, val, __ATOMIC_ACQ_REL)
#define EASTL_COMPILER_ATOMIC_AND_FETCH_ACQ_REL_32(type, ret, ptr, val) \
EASTL_GCC_ATOMIC_AND_FETCH_32(type, ret, ptr, val, __ATOMIC_ACQ_REL)
#define EASTL_COMPILER_ATOMIC_AND_FETCH_ACQ_REL_64(type, ret, ptr, val) \
EASTL_GCC_ATOMIC_AND_FETCH_64(type, ret, ptr, val, __ATOMIC_ACQ_REL)
#define EASTL_COMPILER_ATOMIC_AND_FETCH_ACQ_REL_128(type, ret, ptr, val) \
EASTL_GCC_ATOMIC_AND_FETCH_128(type, ret, ptr, val, __ATOMIC_ACQ_REL)
#define EASTL_COMPILER_ATOMIC_AND_FETCH_SEQ_CST_8(type, ret, ptr, val) \
EASTL_GCC_ATOMIC_AND_FETCH_8(type, ret, ptr, val, __ATOMIC_SEQ_CST)
#define EASTL_COMPILER_ATOMIC_AND_FETCH_SEQ_CST_16(type, ret, ptr, val) \
EASTL_GCC_ATOMIC_AND_FETCH_16(type, ret, ptr, val, __ATOMIC_SEQ_CST)
#define EASTL_COMPILER_ATOMIC_AND_FETCH_SEQ_CST_32(type, ret, ptr, val) \
EASTL_GCC_ATOMIC_AND_FETCH_32(type, ret, ptr, val, __ATOMIC_SEQ_CST)
#define EASTL_COMPILER_ATOMIC_AND_FETCH_SEQ_CST_64(type, ret, ptr, val) \
EASTL_GCC_ATOMIC_AND_FETCH_64(type, ret, ptr, val, __ATOMIC_SEQ_CST)
#define EASTL_COMPILER_ATOMIC_AND_FETCH_SEQ_CST_128(type, ret, ptr, val) \
EASTL_GCC_ATOMIC_AND_FETCH_128(type, ret, ptr, val, __ATOMIC_SEQ_CST)
#endif /* EASTL_ATOMIC_INTERNAL_COMPILER_GCC_AND_FETCH_H */
|
3bf9bc15bb5ccf238f44fc56807ff381480b05a0
|
40062e1545591a1a93c04e0ea084c48405c665fa
|
/third_party/libjpeg-turbo/libjpeg-turbo/tjbench.c
|
be6d23caeed22ca6f76e208309b75407ec8ce290
|
[
"MIT",
"BSD-3-Clause",
"IJG",
"Zlib",
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-warranty-disclaimer"
] |
permissive
|
neka-nat/cupoch
|
ad1f55eba2f4fb810ff2cd3af620f11a90aef69a
|
122b69b5312885734c224f9deef813e2b1463017
|
refs/heads/master
| 2023-07-09T00:08:50.033219
| 2023-06-30T07:53:53
| 2023-06-30T07:53:53
| 216,847,240
| 739
| 103
|
MIT
| 2023-04-04T15:30:55
| 2019-10-22T15:26:24
|
C++
|
UTF-8
|
C
| false
| false
| 39,536
|
c
|
tjbench.c
|
/*
* Copyright (C)2009-2019 D. R. Commander. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* - Neither the name of the libjpeg-turbo Project 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 HOLDERS 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 <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <errno.h>
#include <limits.h>
#include <cdjpeg.h>
#include "./tjutil.h"
#include "./turbojpeg.h"
#define THROW(op, err) { \
printf("ERROR in line %d while %s:\n%s\n", __LINE__, op, err); \
retval = -1; goto bailout; \
}
#define THROW_UNIX(m) THROW(m, strerror(errno))
char tjErrorStr[JMSG_LENGTH_MAX] = "\0", tjErrorMsg[JMSG_LENGTH_MAX] = "\0";
int tjErrorLine = -1, tjErrorCode = -1;
#define THROW_TJG(m) { \
printf("ERROR in line %d while %s:\n%s\n", __LINE__, m, \
tjGetErrorStr2(NULL)); \
retval = -1; goto bailout; \
}
#define THROW_TJ(m) { \
int _tjErrorCode = tjGetErrorCode(handle); \
char *_tjErrorStr = tjGetErrorStr2(handle); \
\
if (!(flags & TJFLAG_STOPONWARNING) && _tjErrorCode == TJERR_WARNING) { \
if (strncmp(tjErrorStr, _tjErrorStr, JMSG_LENGTH_MAX) || \
strncmp(tjErrorMsg, m, JMSG_LENGTH_MAX) || \
tjErrorCode != _tjErrorCode || tjErrorLine != __LINE__) { \
strncpy(tjErrorStr, _tjErrorStr, JMSG_LENGTH_MAX - 1); \
strncpy(tjErrorMsg, m, JMSG_LENGTH_MAX - 1); \
tjErrorCode = _tjErrorCode; \
tjErrorLine = __LINE__; \
printf("WARNING in line %d while %s:\n%s\n", __LINE__, m, _tjErrorStr); \
} \
} else { \
printf("%s in line %d while %s:\n%s\n", \
_tjErrorCode == TJERR_WARNING ? "WARNING" : "ERROR", __LINE__, m, \
_tjErrorStr); \
retval = -1; goto bailout; \
} \
}
int flags = TJFLAG_NOREALLOC, compOnly = 0, decompOnly = 0, doYUV = 0,
quiet = 0, doTile = 0, pf = TJPF_BGR, yuvPad = 1, doWrite = 1;
char *ext = "ppm";
const char *pixFormatStr[TJ_NUMPF] = {
"RGB", "BGR", "RGBX", "BGRX", "XBGR", "XRGB", "GRAY", "", "", "", "", "CMYK"
};
const char *subNameLong[TJ_NUMSAMP] = {
"4:4:4", "4:2:2", "4:2:0", "GRAY", "4:4:0", "4:1:1"
};
const char *csName[TJ_NUMCS] = {
"RGB", "YCbCr", "GRAY", "CMYK", "YCCK"
};
const char *subName[TJ_NUMSAMP] = {
"444", "422", "420", "GRAY", "440", "411"
};
tjscalingfactor *scalingFactors = NULL, sf = { 1, 1 };
int nsf = 0, xformOp = TJXOP_NONE, xformOpt = 0;
int (*customFilter) (short *, tjregion, tjregion, int, int, tjtransform *);
double benchTime = 5.0, warmup = 1.0;
static char *formatName(int subsamp, int cs, char *buf)
{
if (cs == TJCS_YCbCr)
return (char *)subNameLong[subsamp];
else if (cs == TJCS_YCCK || cs == TJCS_CMYK) {
snprintf(buf, 80, "%s %s", csName[cs], subNameLong[subsamp]);
return buf;
} else
return (char *)csName[cs];
}
static char *sigfig(double val, int figs, char *buf, int len)
{
char format[80];
int digitsAfterDecimal = figs - (int)ceil(log10(fabs(val)));
if (digitsAfterDecimal < 1)
snprintf(format, 80, "%%.0f");
else
snprintf(format, 80, "%%.%df", digitsAfterDecimal);
snprintf(buf, len, format, val);
return buf;
}
/* Custom DCT filter which produces a negative of the image */
static int dummyDCTFilter(short *coeffs, tjregion arrayRegion,
tjregion planeRegion, int componentIndex,
int transformIndex, tjtransform *transform)
{
int i;
for (i = 0; i < arrayRegion.w * arrayRegion.h; i++)
coeffs[i] = -coeffs[i];
return 0;
}
/* Decompression test */
static int decomp(unsigned char *srcBuf, unsigned char **jpegBuf,
unsigned long *jpegSize, unsigned char *dstBuf, int w, int h,
int subsamp, int jpegQual, char *fileName, int tilew,
int tileh)
{
char tempStr[1024], sizeStr[24] = "\0", qualStr[13] = "\0", *ptr;
FILE *file = NULL;
tjhandle handle = NULL;
int row, col, iter = 0, dstBufAlloc = 0, retval = 0;
double elapsed, elapsedDecode;
int ps = tjPixelSize[pf];
int scaledw = TJSCALED(w, sf);
int scaledh = TJSCALED(h, sf);
int pitch = scaledw * ps;
int ntilesw = (w + tilew - 1) / tilew, ntilesh = (h + tileh - 1) / tileh;
unsigned char *dstPtr, *dstPtr2, *yuvBuf = NULL;
if (jpegQual > 0) {
snprintf(qualStr, 13, "_Q%d", jpegQual);
qualStr[12] = 0;
}
if ((handle = tjInitDecompress()) == NULL)
THROW_TJ("executing tjInitDecompress()");
if (dstBuf == NULL) {
if ((unsigned long long)pitch * (unsigned long long)scaledh >
(unsigned long long)((size_t)-1))
THROW("allocating destination buffer", "Image is too large");
if ((dstBuf = (unsigned char *)malloc((size_t)pitch * scaledh)) == NULL)
THROW_UNIX("allocating destination buffer");
dstBufAlloc = 1;
}
/* Set the destination buffer to gray so we know whether the decompressor
attempted to write to it */
memset(dstBuf, 127, pitch * scaledh);
if (doYUV) {
int width = doTile ? tilew : scaledw;
int height = doTile ? tileh : scaledh;
unsigned long yuvSize = tjBufSizeYUV2(width, yuvPad, height, subsamp);
if (yuvSize == (unsigned long)-1)
THROW_TJ("allocating YUV buffer");
if ((yuvBuf = (unsigned char *)malloc(yuvSize)) == NULL)
THROW_UNIX("allocating YUV buffer");
memset(yuvBuf, 127, yuvSize);
}
/* Benchmark */
iter = -1;
elapsed = elapsedDecode = 0.;
while (1) {
int tile = 0;
double start = getTime();
for (row = 0, dstPtr = dstBuf; row < ntilesh;
row++, dstPtr += pitch * tileh) {
for (col = 0, dstPtr2 = dstPtr; col < ntilesw;
col++, tile++, dstPtr2 += ps * tilew) {
int width = doTile ? min(tilew, w - col * tilew) : scaledw;
int height = doTile ? min(tileh, h - row * tileh) : scaledh;
if (doYUV) {
double startDecode;
if (tjDecompressToYUV2(handle, jpegBuf[tile], jpegSize[tile], yuvBuf,
width, yuvPad, height, flags) == -1)
THROW_TJ("executing tjDecompressToYUV2()");
startDecode = getTime();
if (tjDecodeYUV(handle, yuvBuf, yuvPad, subsamp, dstPtr2, width,
pitch, height, pf, flags) == -1)
THROW_TJ("executing tjDecodeYUV()");
if (iter >= 0) elapsedDecode += getTime() - startDecode;
} else if (tjDecompress2(handle, jpegBuf[tile], jpegSize[tile],
dstPtr2, width, pitch, height, pf,
flags) == -1)
THROW_TJ("executing tjDecompress2()");
}
}
elapsed += getTime() - start;
if (iter >= 0) {
iter++;
if (elapsed >= benchTime) break;
} else if (elapsed >= warmup) {
iter = 0;
elapsed = elapsedDecode = 0.;
}
}
if (doYUV) elapsed -= elapsedDecode;
if (tjDestroy(handle) == -1) THROW_TJ("executing tjDestroy()");
handle = NULL;
if (quiet) {
printf("%-6s%s",
sigfig((double)(w * h) / 1000000. * (double)iter / elapsed, 4,
tempStr, 1024),
quiet == 2 ? "\n" : " ");
if (doYUV)
printf("%s\n",
sigfig((double)(w * h) / 1000000. * (double)iter / elapsedDecode,
4, tempStr, 1024));
else if (quiet != 2) printf("\n");
} else {
printf("%s --> Frame rate: %f fps\n",
doYUV ? "Decomp to YUV" : "Decompress ", (double)iter / elapsed);
printf(" Throughput: %f Megapixels/sec\n",
(double)(w * h) / 1000000. * (double)iter / elapsed);
if (doYUV) {
printf("YUV Decode --> Frame rate: %f fps\n",
(double)iter / elapsedDecode);
printf(" Throughput: %f Megapixels/sec\n",
(double)(w * h) / 1000000. * (double)iter / elapsedDecode);
}
}
if (!doWrite) goto bailout;
if (sf.num != 1 || sf.denom != 1)
snprintf(sizeStr, 24, "%d_%d", sf.num, sf.denom);
else if (tilew != w || tileh != h)
snprintf(sizeStr, 24, "%dx%d", tilew, tileh);
else snprintf(sizeStr, 24, "full");
if (decompOnly)
snprintf(tempStr, 1024, "%s_%s.%s", fileName, sizeStr, ext);
else
snprintf(tempStr, 1024, "%s_%s%s_%s.%s", fileName, subName[subsamp],
qualStr, sizeStr, ext);
if (tjSaveImage(tempStr, dstBuf, scaledw, 0, scaledh, pf, flags) == -1)
THROW_TJG("saving bitmap");
ptr = strrchr(tempStr, '.');
snprintf(ptr, 1024 - (ptr - tempStr), "-err.%s", ext);
if (srcBuf && sf.num == 1 && sf.denom == 1) {
if (!quiet) printf("Compression error written to %s.\n", tempStr);
if (subsamp == TJ_GRAYSCALE) {
unsigned long index, index2;
for (row = 0, index = 0; row < h; row++, index += pitch) {
for (col = 0, index2 = index; col < w; col++, index2 += ps) {
unsigned long rindex = index2 + tjRedOffset[pf];
unsigned long gindex = index2 + tjGreenOffset[pf];
unsigned long bindex = index2 + tjBlueOffset[pf];
int y = (int)((double)srcBuf[rindex] * 0.299 +
(double)srcBuf[gindex] * 0.587 +
(double)srcBuf[bindex] * 0.114 + 0.5);
if (y > 255) y = 255;
if (y < 0) y = 0;
dstBuf[rindex] = abs(dstBuf[rindex] - y);
dstBuf[gindex] = abs(dstBuf[gindex] - y);
dstBuf[bindex] = abs(dstBuf[bindex] - y);
}
}
} else {
for (row = 0; row < h; row++)
for (col = 0; col < w * ps; col++)
dstBuf[pitch * row + col] =
abs(dstBuf[pitch * row + col] - srcBuf[pitch * row + col]);
}
if (tjSaveImage(tempStr, dstBuf, w, 0, h, pf, flags) == -1)
THROW_TJG("saving bitmap");
}
bailout:
if (file) fclose(file);
if (handle) tjDestroy(handle);
if (dstBuf && dstBufAlloc) free(dstBuf);
if (yuvBuf) free(yuvBuf);
return retval;
}
static int fullTest(unsigned char *srcBuf, int w, int h, int subsamp,
int jpegQual, char *fileName)
{
char tempStr[1024], tempStr2[80];
FILE *file = NULL;
tjhandle handle = NULL;
unsigned char **jpegBuf = NULL, *yuvBuf = NULL, *tmpBuf = NULL, *srcPtr,
*srcPtr2;
double start, elapsed, elapsedEncode;
int totalJpegSize = 0, row, col, i, tilew = w, tileh = h, retval = 0;
int iter;
unsigned long *jpegSize = NULL, yuvSize = 0;
int ps = tjPixelSize[pf];
int ntilesw = 1, ntilesh = 1, pitch = w * ps;
const char *pfStr = pixFormatStr[pf];
if ((unsigned long long)pitch * (unsigned long long)h >
(unsigned long long)((size_t)-1))
THROW("allocating temporary image buffer", "Image is too large");
if ((tmpBuf = (unsigned char *)malloc((size_t)pitch * h)) == NULL)
THROW_UNIX("allocating temporary image buffer");
if (!quiet)
printf(">>>>> %s (%s) <--> JPEG %s Q%d <<<<<\n", pfStr,
(flags & TJFLAG_BOTTOMUP) ? "Bottom-up" : "Top-down",
subNameLong[subsamp], jpegQual);
for (tilew = doTile ? 8 : w, tileh = doTile ? 8 : h; ;
tilew *= 2, tileh *= 2) {
if (tilew > w) tilew = w;
if (tileh > h) tileh = h;
ntilesw = (w + tilew - 1) / tilew;
ntilesh = (h + tileh - 1) / tileh;
if ((jpegBuf = (unsigned char **)malloc(sizeof(unsigned char *) *
ntilesw * ntilesh)) == NULL)
THROW_UNIX("allocating JPEG tile array");
memset(jpegBuf, 0, sizeof(unsigned char *) * ntilesw * ntilesh);
if ((jpegSize = (unsigned long *)malloc(sizeof(unsigned long) *
ntilesw * ntilesh)) == NULL)
THROW_UNIX("allocating JPEG size array");
memset(jpegSize, 0, sizeof(unsigned long) * ntilesw * ntilesh);
if ((flags & TJFLAG_NOREALLOC) != 0)
for (i = 0; i < ntilesw * ntilesh; i++) {
if (tjBufSize(tilew, tileh, subsamp) > (unsigned long)INT_MAX)
THROW("getting buffer size", "Image is too large");
if ((jpegBuf[i] = (unsigned char *)
tjAlloc(tjBufSize(tilew, tileh, subsamp))) == NULL)
THROW_UNIX("allocating JPEG tiles");
}
/* Compression test */
if (quiet == 1)
printf("%-4s (%s) %-5s %-3d ", pfStr,
(flags & TJFLAG_BOTTOMUP) ? "BU" : "TD", subNameLong[subsamp],
jpegQual);
for (i = 0; i < h; i++)
memcpy(&tmpBuf[pitch * i], &srcBuf[w * ps * i], w * ps);
if ((handle = tjInitCompress()) == NULL)
THROW_TJ("executing tjInitCompress()");
if (doYUV) {
yuvSize = tjBufSizeYUV2(tilew, yuvPad, tileh, subsamp);
if (yuvSize == (unsigned long)-1)
THROW_TJ("allocating YUV buffer");
if ((yuvBuf = (unsigned char *)malloc(yuvSize)) == NULL)
THROW_UNIX("allocating YUV buffer");
memset(yuvBuf, 127, yuvSize);
}
/* Benchmark */
iter = -1;
elapsed = elapsedEncode = 0.;
while (1) {
int tile = 0;
totalJpegSize = 0;
start = getTime();
for (row = 0, srcPtr = srcBuf; row < ntilesh;
row++, srcPtr += pitch * tileh) {
for (col = 0, srcPtr2 = srcPtr; col < ntilesw;
col++, tile++, srcPtr2 += ps * tilew) {
int width = min(tilew, w - col * tilew);
int height = min(tileh, h - row * tileh);
if (doYUV) {
double startEncode = getTime();
if (tjEncodeYUV3(handle, srcPtr2, width, pitch, height, pf, yuvBuf,
yuvPad, subsamp, flags) == -1)
THROW_TJ("executing tjEncodeYUV3()");
if (iter >= 0) elapsedEncode += getTime() - startEncode;
if (tjCompressFromYUV(handle, yuvBuf, width, yuvPad, height,
subsamp, &jpegBuf[tile], &jpegSize[tile],
jpegQual, flags) == -1)
THROW_TJ("executing tjCompressFromYUV()");
} else {
if (tjCompress2(handle, srcPtr2, width, pitch, height, pf,
&jpegBuf[tile], &jpegSize[tile], subsamp, jpegQual,
flags) == -1)
THROW_TJ("executing tjCompress2()");
}
totalJpegSize += jpegSize[tile];
}
}
elapsed += getTime() - start;
if (iter >= 0) {
iter++;
if (elapsed >= benchTime) break;
} else if (elapsed >= warmup) {
iter = 0;
elapsed = elapsedEncode = 0.;
}
}
if (doYUV) elapsed -= elapsedEncode;
if (tjDestroy(handle) == -1) THROW_TJ("executing tjDestroy()");
handle = NULL;
if (quiet == 1) printf("%-5d %-5d ", tilew, tileh);
if (quiet) {
if (doYUV)
printf("%-6s%s",
sigfig((double)(w * h) / 1000000. *
(double)iter / elapsedEncode, 4, tempStr, 1024),
quiet == 2 ? "\n" : " ");
printf("%-6s%s",
sigfig((double)(w * h) / 1000000. * (double)iter / elapsed, 4,
tempStr, 1024),
quiet == 2 ? "\n" : " ");
printf("%-6s%s",
sigfig((double)(w * h * ps) / (double)totalJpegSize, 4, tempStr2,
80),
quiet == 2 ? "\n" : " ");
} else {
printf("\n%s size: %d x %d\n", doTile ? "Tile" : "Image", tilew, tileh);
if (doYUV) {
printf("Encode YUV --> Frame rate: %f fps\n",
(double)iter / elapsedEncode);
printf(" Output image size: %lu bytes\n", yuvSize);
printf(" Compression ratio: %f:1\n",
(double)(w * h * ps) / (double)yuvSize);
printf(" Throughput: %f Megapixels/sec\n",
(double)(w * h) / 1000000. * (double)iter / elapsedEncode);
printf(" Output bit stream: %f Megabits/sec\n",
(double)yuvSize * 8. / 1000000. * (double)iter / elapsedEncode);
}
printf("%s --> Frame rate: %f fps\n",
doYUV ? "Comp from YUV" : "Compress ",
(double)iter / elapsed);
printf(" Output image size: %d bytes\n",
totalJpegSize);
printf(" Compression ratio: %f:1\n",
(double)(w * h * ps) / (double)totalJpegSize);
printf(" Throughput: %f Megapixels/sec\n",
(double)(w * h) / 1000000. * (double)iter / elapsed);
printf(" Output bit stream: %f Megabits/sec\n",
(double)totalJpegSize * 8. / 1000000. * (double)iter / elapsed);
}
if (tilew == w && tileh == h && doWrite) {
snprintf(tempStr, 1024, "%s_%s_Q%d.jpg", fileName, subName[subsamp],
jpegQual);
if ((file = fopen(tempStr, "wb")) == NULL)
THROW_UNIX("opening reference image");
if (fwrite(jpegBuf[0], jpegSize[0], 1, file) != 1)
THROW_UNIX("writing reference image");
fclose(file); file = NULL;
if (!quiet) printf("Reference image written to %s\n", tempStr);
}
/* Decompression test */
if (!compOnly) {
if (decomp(srcBuf, jpegBuf, jpegSize, tmpBuf, w, h, subsamp, jpegQual,
fileName, tilew, tileh) == -1)
goto bailout;
}
for (i = 0; i < ntilesw * ntilesh; i++) {
if (jpegBuf[i]) tjFree(jpegBuf[i]);
jpegBuf[i] = NULL;
}
free(jpegBuf); jpegBuf = NULL;
free(jpegSize); jpegSize = NULL;
if (doYUV) {
free(yuvBuf); yuvBuf = NULL;
}
if (tilew == w && tileh == h) break;
}
bailout:
if (file) { fclose(file); file = NULL; }
if (jpegBuf) {
for (i = 0; i < ntilesw * ntilesh; i++) {
if (jpegBuf[i]) tjFree(jpegBuf[i]);
jpegBuf[i] = NULL;
}
free(jpegBuf); jpegBuf = NULL;
}
if (yuvBuf) { free(yuvBuf); yuvBuf = NULL; }
if (jpegSize) { free(jpegSize); jpegSize = NULL; }
if (tmpBuf) { free(tmpBuf); tmpBuf = NULL; }
if (handle) { tjDestroy(handle); handle = NULL; }
return retval;
}
static int decompTest(char *fileName)
{
FILE *file = NULL;
tjhandle handle = NULL;
unsigned char **jpegBuf = NULL, *srcBuf = NULL;
unsigned long *jpegSize = NULL, srcSize, totalJpegSize;
tjtransform *t = NULL;
double start, elapsed;
int ps = tjPixelSize[pf], tile, row, col, i, iter, retval = 0, decompsrc = 0;
char *temp = NULL, tempStr[80], tempStr2[80];
/* Original image */
int w = 0, h = 0, tilew, tileh, ntilesw = 1, ntilesh = 1, subsamp = -1,
cs = -1;
/* Transformed image */
int tw, th, ttilew, ttileh, tntilesw, tntilesh, tsubsamp;
if ((file = fopen(fileName, "rb")) == NULL)
THROW_UNIX("opening file");
if (fseek(file, 0, SEEK_END) < 0 ||
(srcSize = ftell(file)) == (unsigned long)-1)
THROW_UNIX("determining file size");
if ((srcBuf = (unsigned char *)malloc(srcSize)) == NULL)
THROW_UNIX("allocating memory");
if (fseek(file, 0, SEEK_SET) < 0)
THROW_UNIX("setting file position");
if (fread(srcBuf, srcSize, 1, file) < 1)
THROW_UNIX("reading JPEG data");
fclose(file); file = NULL;
temp = strrchr(fileName, '.');
if (temp != NULL) *temp = '\0';
if ((handle = tjInitTransform()) == NULL)
THROW_TJ("executing tjInitTransform()");
if (tjDecompressHeader3(handle, srcBuf, srcSize, &w, &h, &subsamp,
&cs) == -1)
THROW_TJ("executing tjDecompressHeader3()");
if (w < 1 || h < 1)
THROW("reading JPEG header", "Invalid image dimensions");
if (cs == TJCS_YCCK || cs == TJCS_CMYK) {
pf = TJPF_CMYK; ps = tjPixelSize[pf];
}
if (quiet == 1) {
printf("All performance values in Mpixels/sec\n\n");
printf("Bitmap JPEG JPEG %s %s Xform Comp Decomp ",
doTile ? "Tile " : "Image", doTile ? "Tile " : "Image");
if (doYUV) printf("Decode");
printf("\n");
printf("Format CS Subsamp Width Height Perf Ratio Perf ");
if (doYUV) printf("Perf");
printf("\n\n");
} else if (!quiet)
printf(">>>>> JPEG %s --> %s (%s) <<<<<\n",
formatName(subsamp, cs, tempStr), pixFormatStr[pf],
(flags & TJFLAG_BOTTOMUP) ? "Bottom-up" : "Top-down");
for (tilew = doTile ? 16 : w, tileh = doTile ? 16 : h; ;
tilew *= 2, tileh *= 2) {
if (tilew > w) tilew = w;
if (tileh > h) tileh = h;
ntilesw = (w + tilew - 1) / tilew;
ntilesh = (h + tileh - 1) / tileh;
if ((jpegBuf = (unsigned char **)malloc(sizeof(unsigned char *) *
ntilesw * ntilesh)) == NULL)
THROW_UNIX("allocating JPEG tile array");
memset(jpegBuf, 0, sizeof(unsigned char *) * ntilesw * ntilesh);
if ((jpegSize = (unsigned long *)malloc(sizeof(unsigned long) *
ntilesw * ntilesh)) == NULL)
THROW_UNIX("allocating JPEG size array");
memset(jpegSize, 0, sizeof(unsigned long) * ntilesw * ntilesh);
if ((flags & TJFLAG_NOREALLOC) != 0 &&
(doTile || xformOp != TJXOP_NONE || xformOpt != 0 || customFilter))
for (i = 0; i < ntilesw * ntilesh; i++) {
if (tjBufSize(tilew, tileh, subsamp) > (unsigned long)INT_MAX)
THROW("getting buffer size", "Image is too large");
if ((jpegBuf[i] = (unsigned char *)
tjAlloc(tjBufSize(tilew, tileh, subsamp))) == NULL)
THROW_UNIX("allocating JPEG tiles");
}
tw = w; th = h; ttilew = tilew; ttileh = tileh;
if (!quiet) {
printf("\n%s size: %d x %d", doTile ? "Tile" : "Image", ttilew, ttileh);
if (sf.num != 1 || sf.denom != 1)
printf(" --> %d x %d", TJSCALED(tw, sf), TJSCALED(th, sf));
printf("\n");
} else if (quiet == 1) {
printf("%-4s (%s) %-5s %-5s ", pixFormatStr[pf],
(flags & TJFLAG_BOTTOMUP) ? "BU" : "TD", csName[cs],
subNameLong[subsamp]);
printf("%-5d %-5d ", tilew, tileh);
}
tsubsamp = subsamp;
if (doTile || xformOp != TJXOP_NONE || xformOpt != 0 || customFilter) {
if ((t = (tjtransform *)malloc(sizeof(tjtransform) * ntilesw *
ntilesh)) == NULL)
THROW_UNIX("allocating image transform array");
if (xformOp == TJXOP_TRANSPOSE || xformOp == TJXOP_TRANSVERSE ||
xformOp == TJXOP_ROT90 || xformOp == TJXOP_ROT270) {
tw = h; th = w; ttilew = tileh; ttileh = tilew;
}
if (xformOpt & TJXOPT_GRAY) tsubsamp = TJ_GRAYSCALE;
if (xformOp == TJXOP_HFLIP || xformOp == TJXOP_ROT180)
tw = tw - (tw % tjMCUWidth[tsubsamp]);
if (xformOp == TJXOP_VFLIP || xformOp == TJXOP_ROT180)
th = th - (th % tjMCUHeight[tsubsamp]);
if (xformOp == TJXOP_TRANSVERSE || xformOp == TJXOP_ROT90)
tw = tw - (tw % tjMCUHeight[tsubsamp]);
if (xformOp == TJXOP_TRANSVERSE || xformOp == TJXOP_ROT270)
th = th - (th % tjMCUWidth[tsubsamp]);
tntilesw = (tw + ttilew - 1) / ttilew;
tntilesh = (th + ttileh - 1) / ttileh;
if (xformOp == TJXOP_TRANSPOSE || xformOp == TJXOP_TRANSVERSE ||
xformOp == TJXOP_ROT90 || xformOp == TJXOP_ROT270) {
if (tsubsamp == TJSAMP_422) tsubsamp = TJSAMP_440;
else if (tsubsamp == TJSAMP_440) tsubsamp = TJSAMP_422;
}
for (row = 0, tile = 0; row < tntilesh; row++) {
for (col = 0; col < tntilesw; col++, tile++) {
t[tile].r.w = min(ttilew, tw - col * ttilew);
t[tile].r.h = min(ttileh, th - row * ttileh);
t[tile].r.x = col * ttilew;
t[tile].r.y = row * ttileh;
t[tile].op = xformOp;
t[tile].options = xformOpt | TJXOPT_TRIM;
t[tile].customFilter = customFilter;
if (t[tile].options & TJXOPT_NOOUTPUT && jpegBuf[tile]) {
tjFree(jpegBuf[tile]); jpegBuf[tile] = NULL;
}
}
}
iter = -1;
elapsed = 0.;
while (1) {
start = getTime();
if (tjTransform(handle, srcBuf, srcSize, tntilesw * tntilesh, jpegBuf,
jpegSize, t, flags) == -1)
THROW_TJ("executing tjTransform()");
elapsed += getTime() - start;
if (iter >= 0) {
iter++;
if (elapsed >= benchTime) break;
} else if (elapsed >= warmup) {
iter = 0;
elapsed = 0.;
}
}
free(t); t = NULL;
for (tile = 0, totalJpegSize = 0; tile < tntilesw * tntilesh; tile++)
totalJpegSize += jpegSize[tile];
if (quiet) {
printf("%-6s%s%-6s%s",
sigfig((double)(w * h) / 1000000. / elapsed, 4, tempStr, 80),
quiet == 2 ? "\n" : " ",
sigfig((double)(w * h * ps) / (double)totalJpegSize, 4,
tempStr2, 80),
quiet == 2 ? "\n" : " ");
} else if (!quiet) {
printf("Transform --> Frame rate: %f fps\n",
1.0 / elapsed);
printf(" Output image size: %lu bytes\n",
totalJpegSize);
printf(" Compression ratio: %f:1\n",
(double)(w * h * ps) / (double)totalJpegSize);
printf(" Throughput: %f Megapixels/sec\n",
(double)(w * h) / 1000000. / elapsed);
printf(" Output bit stream: %f Megabits/sec\n",
(double)totalJpegSize * 8. / 1000000. / elapsed);
}
} else {
if (quiet == 1) printf("N/A N/A ");
if (jpegBuf[0]) tjFree(jpegBuf[0]);
jpegBuf[0] = NULL;
decompsrc = 1;
}
if (w == tilew) ttilew = tw;
if (h == tileh) ttileh = th;
if (!(xformOpt & TJXOPT_NOOUTPUT)) {
if (decomp(NULL, decompsrc ? &srcBuf : jpegBuf,
decompsrc ? &srcSize : jpegSize, NULL, tw, th, tsubsamp, 0,
fileName, ttilew, ttileh) == -1)
goto bailout;
} else if (quiet == 1) printf("N/A\n");
for (i = 0; i < ntilesw * ntilesh; i++) {
if (jpegBuf[i]) tjFree(jpegBuf[i]);
jpegBuf[i] = NULL;
}
free(jpegBuf); jpegBuf = NULL;
if (jpegSize) { free(jpegSize); jpegSize = NULL; }
if (tilew == w && tileh == h) break;
}
bailout:
if (file) { fclose(file); file = NULL; }
if (jpegBuf) {
for (i = 0; i < ntilesw * ntilesh; i++) {
if (jpegBuf[i]) tjFree(jpegBuf[i]);
jpegBuf[i] = NULL;
}
free(jpegBuf); jpegBuf = NULL;
}
if (jpegSize) { free(jpegSize); jpegSize = NULL; }
if (srcBuf) { free(srcBuf); srcBuf = NULL; }
if (t) { free(t); t = NULL; }
if (handle) { tjDestroy(handle); handle = NULL; }
return retval;
}
static void usage(char *progName)
{
int i;
printf("USAGE: %s\n", progName);
printf(" <Inputfile (BMP|PPM)> <Quality> [options]\n\n");
printf(" %s\n", progName);
printf(" <Inputfile (JPG)> [options]\n\n");
printf("Options:\n\n");
printf("-alloc = Dynamically allocate JPEG image buffers\n");
printf("-bmp = Generate output images in Windows Bitmap format (default = PPM)\n");
printf("-bottomup = Test bottom-up compression/decompression\n");
printf("-tile = Test performance of the codec when the image is encoded as separate\n");
printf(" tiles of varying sizes.\n");
printf("-rgb, -bgr, -rgbx, -bgrx, -xbgr, -xrgb =\n");
printf(" Test the specified color conversion path in the codec (default = BGR)\n");
printf("-cmyk = Indirectly test YCCK JPEG compression/decompression (the source\n");
printf(" and destination bitmaps are still RGB. The conversion is done\n");
printf(" internally prior to compression or after decompression.)\n");
printf("-fastupsample = Use the fastest chrominance upsampling algorithm available in\n");
printf(" the underlying codec\n");
printf("-fastdct = Use the fastest DCT/IDCT algorithms available in the underlying\n");
printf(" codec\n");
printf("-accuratedct = Use the most accurate DCT/IDCT algorithms available in the\n");
printf(" underlying codec\n");
printf("-progressive = Use progressive entropy coding in JPEG images generated by\n");
printf(" compression and transform operations.\n");
printf("-subsamp <s> = When testing JPEG compression, this option specifies the level\n");
printf(" of chrominance subsampling to use (<s> = 444, 422, 440, 420, 411, or\n");
printf(" GRAY). The default is to test Grayscale, 4:2:0, 4:2:2, and 4:4:4 in\n");
printf(" sequence.\n");
printf("-quiet = Output results in tabular rather than verbose format\n");
printf("-yuv = Test YUV encoding/decoding functions\n");
printf("-yuvpad <p> = If testing YUV encoding/decoding, this specifies the number of\n");
printf(" bytes to which each row of each plane in the intermediate YUV image is\n");
printf(" padded (default = 1)\n");
printf("-scale M/N = Scale down the width/height of the decompressed JPEG image by a\n");
printf(" factor of M/N (M/N = ");
for (i = 0; i < nsf; i++) {
printf("%d/%d", scalingFactors[i].num, scalingFactors[i].denom);
if (nsf == 2 && i != nsf - 1) printf(" or ");
else if (nsf > 2) {
if (i != nsf - 1) printf(", ");
if (i == nsf - 2) printf("or ");
}
if (i % 8 == 0 && i != 0) printf("\n ");
}
printf(")\n");
printf("-hflip, -vflip, -transpose, -transverse, -rot90, -rot180, -rot270 =\n");
printf(" Perform the corresponding lossless transform prior to\n");
printf(" decompression (these options are mutually exclusive)\n");
printf("-grayscale = Perform lossless grayscale conversion prior to decompression\n");
printf(" test (can be combined with the other transforms above)\n");
printf("-copynone = Do not copy any extra markers (including EXIF and ICC profile data)\n");
printf(" when transforming the image.\n");
printf("-benchtime <t> = Run each benchmark for at least <t> seconds (default = 5.0)\n");
printf("-warmup <t> = Run each benchmark for <t> seconds (default = 1.0) prior to\n");
printf(" starting the timer, in order to prime the caches and thus improve the\n");
printf(" consistency of the results.\n");
printf("-componly = Stop after running compression tests. Do not test decompression.\n");
printf("-nowrite = Do not write reference or output images (improves consistency of\n");
printf(" performance measurements.)\n");
printf("-stoponwarning = Immediately discontinue the current\n");
printf(" compression/decompression/transform operation if the underlying codec\n");
printf(" throws a warning (non-fatal error)\n\n");
printf("NOTE: If the quality is specified as a range (e.g. 90-100), a separate\n");
printf("test will be performed for all quality values in the range.\n\n");
exit(1);
}
int main(int argc, char *argv[])
{
unsigned char *srcBuf = NULL;
int w = 0, h = 0, i, j, minQual = -1, maxQual = -1;
char *temp;
int minArg = 2, retval = 0, subsamp = -1;
if ((scalingFactors = tjGetScalingFactors(&nsf)) == NULL || nsf == 0)
THROW("executing tjGetScalingFactors()", tjGetErrorStr());
if (argc < minArg) usage(argv[0]);
temp = strrchr(argv[1], '.');
if (temp != NULL) {
if (!strcasecmp(temp, ".bmp")) ext = "bmp";
if (!strcasecmp(temp, ".jpg") || !strcasecmp(temp, ".jpeg"))
decompOnly = 1;
}
printf("\n");
if (!decompOnly) {
minArg = 3;
if (argc < minArg) usage(argv[0]);
if ((minQual = atoi(argv[2])) < 1 || minQual > 100) {
puts("ERROR: Quality must be between 1 and 100.");
exit(1);
}
if ((temp = strchr(argv[2], '-')) != NULL && strlen(temp) > 1 &&
sscanf(&temp[1], "%d", &maxQual) == 1 && maxQual > minQual &&
maxQual >= 1 && maxQual <= 100) {}
else maxQual = minQual;
}
if (argc > minArg) {
for (i = minArg; i < argc; i++) {
if (!strcasecmp(argv[i], "-tile")) {
doTile = 1; xformOpt |= TJXOPT_CROP;
} else if (!strcasecmp(argv[i], "-fastupsample")) {
printf("Using fast upsampling code\n\n");
flags |= TJFLAG_FASTUPSAMPLE;
} else if (!strcasecmp(argv[i], "-fastdct")) {
printf("Using fastest DCT/IDCT algorithm\n\n");
flags |= TJFLAG_FASTDCT;
} else if (!strcasecmp(argv[i], "-accuratedct")) {
printf("Using most accurate DCT/IDCT algorithm\n\n");
flags |= TJFLAG_ACCURATEDCT;
} else if (!strcasecmp(argv[i], "-progressive")) {
printf("Using progressive entropy coding\n\n");
flags |= TJFLAG_PROGRESSIVE;
} else if (!strcasecmp(argv[i], "-rgb"))
pf = TJPF_RGB;
else if (!strcasecmp(argv[i], "-rgbx"))
pf = TJPF_RGBX;
else if (!strcasecmp(argv[i], "-bgr"))
pf = TJPF_BGR;
else if (!strcasecmp(argv[i], "-bgrx"))
pf = TJPF_BGRX;
else if (!strcasecmp(argv[i], "-xbgr"))
pf = TJPF_XBGR;
else if (!strcasecmp(argv[i], "-xrgb"))
pf = TJPF_XRGB;
else if (!strcasecmp(argv[i], "-cmyk"))
pf = TJPF_CMYK;
else if (!strcasecmp(argv[i], "-bottomup"))
flags |= TJFLAG_BOTTOMUP;
else if (!strcasecmp(argv[i], "-quiet"))
quiet = 1;
else if (!strcasecmp(argv[i], "-qq"))
quiet = 2;
else if (!strcasecmp(argv[i], "-scale") && i < argc - 1) {
int temp1 = 0, temp2 = 0, match = 0;
if (sscanf(argv[++i], "%d/%d", &temp1, &temp2) == 2) {
for (j = 0; j < nsf; j++) {
if ((double)temp1 / (double)temp2 ==
(double)scalingFactors[j].num /
(double)scalingFactors[j].denom) {
sf = scalingFactors[j];
match = 1; break;
}
}
if (!match) usage(argv[0]);
} else usage(argv[0]);
} else if (!strcasecmp(argv[i], "-hflip"))
xformOp = TJXOP_HFLIP;
else if (!strcasecmp(argv[i], "-vflip"))
xformOp = TJXOP_VFLIP;
else if (!strcasecmp(argv[i], "-transpose"))
xformOp = TJXOP_TRANSPOSE;
else if (!strcasecmp(argv[i], "-transverse"))
xformOp = TJXOP_TRANSVERSE;
else if (!strcasecmp(argv[i], "-rot90"))
xformOp = TJXOP_ROT90;
else if (!strcasecmp(argv[i], "-rot180"))
xformOp = TJXOP_ROT180;
else if (!strcasecmp(argv[i], "-rot270"))
xformOp = TJXOP_ROT270;
else if (!strcasecmp(argv[i], "-grayscale"))
xformOpt |= TJXOPT_GRAY;
else if (!strcasecmp(argv[i], "-custom"))
customFilter = dummyDCTFilter;
else if (!strcasecmp(argv[i], "-nooutput"))
xformOpt |= TJXOPT_NOOUTPUT;
else if (!strcasecmp(argv[i], "-copynone"))
xformOpt |= TJXOPT_COPYNONE;
else if (!strcasecmp(argv[i], "-benchtime") && i < argc - 1) {
double tempd = atof(argv[++i]);
if (tempd > 0.0) benchTime = tempd;
else usage(argv[0]);
} else if (!strcasecmp(argv[i], "-warmup") && i < argc - 1) {
double tempd = atof(argv[++i]);
if (tempd >= 0.0) warmup = tempd;
else usage(argv[0]);
printf("Warmup time = %.1f seconds\n\n", warmup);
} else if (!strcasecmp(argv[i], "-alloc"))
flags &= (~TJFLAG_NOREALLOC);
else if (!strcasecmp(argv[i], "-bmp"))
ext = "bmp";
else if (!strcasecmp(argv[i], "-yuv")) {
printf("Testing YUV planar encoding/decoding\n\n");
doYUV = 1;
} else if (!strcasecmp(argv[i], "-yuvpad") && i < argc - 1) {
int tempi = atoi(argv[++i]);
if (tempi >= 1) yuvPad = tempi;
} else if (!strcasecmp(argv[i], "-subsamp") && i < argc - 1) {
i++;
if (toupper(argv[i][0]) == 'G') subsamp = TJSAMP_GRAY;
else {
int tempi = atoi(argv[i]);
switch (tempi) {
case 444: subsamp = TJSAMP_444; break;
case 422: subsamp = TJSAMP_422; break;
case 440: subsamp = TJSAMP_440; break;
case 420: subsamp = TJSAMP_420; break;
case 411: subsamp = TJSAMP_411; break;
}
}
} else if (!strcasecmp(argv[i], "-componly"))
compOnly = 1;
else if (!strcasecmp(argv[i], "-nowrite"))
doWrite = 0;
else if (!strcasecmp(argv[i], "-stoponwarning"))
flags |= TJFLAG_STOPONWARNING;
else usage(argv[0]);
}
}
if ((sf.num != 1 || sf.denom != 1) && doTile) {
printf("Disabling tiled compression/decompression tests, because those tests do not\n");
printf("work when scaled decompression is enabled.\n");
doTile = 0;
}
if ((flags & TJFLAG_NOREALLOC) == 0 && doTile) {
printf("Disabling tiled compression/decompression tests, because those tests do not\n");
printf("work when dynamic JPEG buffer allocation is enabled.\n\n");
doTile = 0;
}
if (!decompOnly) {
if ((srcBuf = tjLoadImage(argv[1], &w, 1, &h, &pf, flags)) == NULL)
THROW_TJG("loading bitmap");
temp = strrchr(argv[1], '.');
if (temp != NULL) *temp = '\0';
}
if (quiet == 1 && !decompOnly) {
printf("All performance values in Mpixels/sec\n\n");
printf("Bitmap JPEG JPEG %s %s ",
doTile ? "Tile " : "Image", doTile ? "Tile " : "Image");
if (doYUV) printf("Encode ");
printf("Comp Comp Decomp ");
if (doYUV) printf("Decode");
printf("\n");
printf("Format Subsamp Qual Width Height ");
if (doYUV) printf("Perf ");
printf("Perf Ratio Perf ");
if (doYUV) printf("Perf");
printf("\n\n");
}
if (decompOnly) {
decompTest(argv[1]);
printf("\n");
goto bailout;
}
if (subsamp >= 0 && subsamp < TJ_NUMSAMP) {
for (i = maxQual; i >= minQual; i--)
fullTest(srcBuf, w, h, subsamp, i, argv[1]);
printf("\n");
} else {
if (pf != TJPF_CMYK) {
for (i = maxQual; i >= minQual; i--)
fullTest(srcBuf, w, h, TJSAMP_GRAY, i, argv[1]);
printf("\n");
}
for (i = maxQual; i >= minQual; i--)
fullTest(srcBuf, w, h, TJSAMP_420, i, argv[1]);
printf("\n");
for (i = maxQual; i >= minQual; i--)
fullTest(srcBuf, w, h, TJSAMP_422, i, argv[1]);
printf("\n");
for (i = maxQual; i >= minQual; i--)
fullTest(srcBuf, w, h, TJSAMP_444, i, argv[1]);
printf("\n");
}
bailout:
if (srcBuf) tjFree(srcBuf);
return retval;
}
|
57c1fb94235983a83149c6617eeb558c340590a5
|
2b4867ce106d3068b67f2244019247df9cf6f341
|
/tests/runner-tests/decls/typedef/4.c
|
54dae244fc191d4ac4439bd79328b8f9009f913d
|
[
"BSD-3-Clause"
] |
permissive
|
jyn514/saltwater
|
d22b29ac40a4e3deb6128d904759d9183f081ab4
|
097c72d30e325de57fbed8a506431754a0560374
|
refs/heads/master
| 2023-05-09T05:44:43.147928
| 2021-06-03T02:53:32
| 2021-06-03T02:53:32
| 190,940,981
| 131
| 25
|
BSD-3-Clause
| 2021-04-07T22:58:39
| 2019-06-08T22:26:45
|
Rust
|
UTF-8
|
C
| false
| false
| 42
|
c
|
4.c
|
// no-main
typedef struct __IO_FILE FILE;
|
876f2dff68599d53f2186337e48c6ded938efb21
|
61c4b7973dc50c0c2481c745436ff39a8600ff1c
|
/2018/threadoverhead/malloc-memusage.c
|
3554c0697e5947f067418090e578a2beaad2f4ee
|
[
"Unlicense",
"LicenseRef-scancode-public-domain"
] |
permissive
|
eliben/code-for-blog
|
ff1a0b3a495db2c57bfeb431107767bb728b9417
|
94e36f22017424b5e372c5f362e0dde0f21b7fd3
|
refs/heads/master
| 2023-09-01T17:57:08.074883
| 2023-08-28T13:13:26
| 2023-08-28T13:13:26
| 23,960,698
| 1,482
| 1,019
|
Unlicense
| 2023-07-06T13:58:51
| 2014-09-12T12:59:05
|
Python
|
UTF-8
|
C
| false
| false
| 1,680
|
c
|
malloc-memusage.c
|
// Demonstrate VSZ usage vs. RSS usage.
//
// Eli Bendersky [http://eli.thegreenplace.net]
// This code is in the public domain.
#include <ctype.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/resource.h>
#include <unistd.h>
// This function is used to prevent optimizations by the compiler for p, while
// compiling to no instructions. It lets the compiler believe that p may be used
// for updating all memory
void escape(void* p) {
asm volatile("" : : "g"(p) : "memory");
}
void report_memory(const char* prefix) {
struct rusage ru;
if (getrusage(RUSAGE_SELF, &ru)) {
perror("getrusage");
exit(1);
}
char statusfilename[256];
snprintf(statusfilename, 256, "/proc/%d/status", getpid());
FILE* f = fopen(statusfilename, "r");
if (!f) {
perror("fopen");
exit(1);
}
char buf[256] = {'\0'};
char* bufstart = buf;
while (fgets(buf, 256, f)) {
if (strstr(buf, "VmSize") == buf) {
bufstart = buf + 7;
// Skip leading spaces and trim trailing newline.
while (isspace(*bufstart)) {
bufstart++;
}
char* pos = strchr(bufstart, '\n');
if (pos) {
*pos = '\0';
}
break;
}
}
printf("%s: max RSS = %ld kB; vm size = %s\n", prefix, ru.ru_maxrss,
bufstart);
}
int main(int argc, char** argv) {
printf("PID = %d\n", getpid());
report_memory("started");
int N = 100 * 1024 * 1024;
int* m = malloc(N * sizeof(int));
escape(m);
report_memory("after malloc");
for (int i = 0; i < N; ++i) {
m[i] = i;
}
report_memory("after touch");
printf("press ENTER\n");
(void)fgetc(stdin);
return 0;
}
|
964cd95c835779cc8f573337e51810e55bc7c893
|
e65a4dbfbfb0e54e59787ba7741efee12f7687f3
|
/graphics/libvisual/files/patch-libvisual-lv_cpu.c
|
b81f188e1bf328a90881ea65d4ac189f254f3f40
|
[
"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
| 307
|
c
|
patch-libvisual-lv_cpu.c
|
--- libvisual/lv_cpu.c.orig 2010-04-25 17:13:26.000000000 +0200
+++ libvisual/lv_cpu.c 2010-04-25 17:11:29.000000000 +0200
@@ -423,7 +423,7 @@
#endif
#endif /* VISUAL_ARCH_X86 */
-#if VISUAL_ARCH_POWERPC
+#if defined(VISUAL_ARCH_POWERPC)
check_os_altivec_support ();
#endif /* VISUAL_ARCH_POWERPC */
|
744ec8009236d1d33bc6917d4e3218c5cac1ed9f
|
89db60818afeb3dc7c3b7abe9ceae155f074f7f2
|
/src/cmd/9660/dump.c
|
ad762f2175f6dcbff6568956fa634866de15238d
|
[
"bzip2-1.0.6",
"LPL-1.02",
"MIT"
] |
permissive
|
9fans/plan9port
|
63c3d01928c6f8a8617d3ea6ecc05bac72391132
|
65c090346a38a8c30cb242d345aa71060116340c
|
refs/heads/master
| 2023-08-25T17:14:26.233105
| 2023-08-23T13:21:37
| 2023-08-23T18:47:08
| 26,095,474
| 1,645
| 468
|
NOASSERTION
| 2023-09-05T16:55:41
| 2014-11-02T22:40:13
|
C
|
UTF-8
|
C
| false
| false
| 9,576
|
c
|
dump.c
|
#include <u.h>
#include <libc.h>
#include <bio.h>
#include <libsec.h>
#include <ctype.h>
#include "iso9660.h"
static void
md5cd(Cdimg *cd, ulong block, ulong length, uchar *digest)
{
int n;
uchar buf[Blocksize];
DigestState *s;
s = md5(nil, 0, nil, nil);
while(length > 0) {
n = length;
if(n > Blocksize)
n = Blocksize;
Creadblock(cd, buf, block, n);
md5(buf, n, nil, s);
block++;
length -= n;
}
md5(nil, 0, digest, s);
}
static Dumpdir*
mkdumpdir(char *name, uchar *md5, ulong block, ulong length)
{
Dumpdir *d;
assert(block != 0);
d = emalloc(sizeof *d);
d->name = name;
memmove(d->md5, md5, sizeof d->md5);
d->block = block;
d->length = length;
return d;
}
static Dumpdir**
ltreewalkmd5(Dumpdir **l, uchar *md5)
{
int i;
while(*l) {
i = memcmp(md5, (*l)->md5, MD5dlen);
if(i < 0)
l = &(*l)->md5left;
else if(i == 0)
return l;
else
l = &(*l)->md5right;
}
return l;
}
static Dumpdir**
ltreewalkblock(Dumpdir **l, ulong block)
{
while(*l) {
if(block < (*l)->block)
l = &(*l)->blockleft;
else if(block == (*l)->block)
return l;
else
l = &(*l)->blockright;
}
return l;
}
/*
* Add a particular file to our binary tree.
*/
static void
addfile(Cdimg *cd, Dump *d, char *name, Direc *dir)
{
uchar md5[MD5dlen];
Dumpdir **lblock;
assert((dir->mode & DMDIR) == 0);
if(dir->length == 0)
return;
lblock = ltreewalkblock(&d->blockroot, dir->block);
if(*lblock != nil) {
if((*lblock)->length == dir->length)
return;
fprint(2, "block %lud length %lud %s %lud %s\n", dir->block, (*lblock)->length, (*lblock)->name,
dir->length, dir->name);
assert(0);
}
md5cd(cd, dir->block, dir->length, md5);
if(chatty > 1)
fprint(2, "note file %.16H %lud (%s)\n", md5, dir->length, dir->name);
insertmd5(d, name, md5, dir->block, dir->length);
}
void
insertmd5(Dump *d, char *name, uchar *md5, ulong block, ulong length)
{
Dumpdir **lmd5;
Dumpdir **lblock;
lblock = ltreewalkblock(&d->blockroot, block);
if(*lblock != nil) {
if((*lblock)->length == length)
return;
fprint(2, "block %lud length %lud %lud\n", block, (*lblock)->length, length);
assert(0);
}
assert(length != 0);
*lblock = mkdumpdir(name, md5, block, length);
lmd5 = ltreewalkmd5(&d->md5root, md5);
if(*lmd5 != nil)
fprint(2, "warning: data duplicated on CD\n");
else
*lmd5 = *lblock;
}
/*
* Fill all the children entries for a particular directory;
* all we care about is block, length, and whether it is a directory.
*/
void
readkids(Cdimg *cd, Direc *dir, char *(*cvt)(uchar*, int))
{
char *dot, *dotdot;
int m, n;
uchar buf[Blocksize], *ebuf, *p;
ulong b, nb;
Cdir *c;
Direc dx;
assert(dir->mode & DMDIR);
dot = atom(".");
dotdot = atom("..");
ebuf = buf+Blocksize;
nb = (dir->length+Blocksize-1) / Blocksize;
n = 0;
for(b=0; b<nb; b++) {
Creadblock(cd, buf, dir->block + b, Blocksize);
p = buf;
while(p < ebuf) {
c = (Cdir*)p;
if(c->len == 0)
break;
if(p+c->len > ebuf)
break;
if(parsedir(cd, &dx, p, ebuf-p, cvt) == 0 && dx.name != dot && dx.name != dotdot)
n++;
p += c->len;
}
}
m = (n+Ndirblock-1)/Ndirblock * Ndirblock;
dir->child = emalloc(m*sizeof dir->child[0]);
dir->nchild = n;
n = 0;
for(b=0; b<nb; b++) {
assert(n <= dir->nchild);
Creadblock(cd, buf, dir->block + b, Blocksize);
p = buf;
while(p < ebuf) {
c = (Cdir*)p;
if(c->len == 0)
break;
if(p+c->len > ebuf)
break;
if(parsedir(cd, &dx, p, ebuf-p, cvt) == 0 && dx.name != dot && dx.name != dotdot) {
assert(n < dir->nchild);
dir->child[n++] = dx;
}
p += c->len;
}
}
}
/*
* Free the children. Make sure their children are free too.
*/
void
freekids(Direc *dir)
{
int i;
for(i=0; i<dir->nchild; i++)
assert(dir->child[i].nchild == 0);
free(dir->child);
dir->child = nil;
dir->nchild = 0;
}
/*
* Add a whole directory and all its children to our binary tree.
*/
static void
adddir(Cdimg *cd, Dump *d, Direc *dir)
{
int i;
readkids(cd, dir, isostring);
for(i=0; i<dir->nchild; i++) {
if(dir->child[i].mode & DMDIR)
adddir(cd, d, &dir->child[i]);
else
addfile(cd, d, atom(dir->name), &dir->child[i]);
}
freekids(dir);
}
Dumpdir*
lookupmd5(Dump *d, uchar *md5)
{
return *ltreewalkmd5(&d->md5root, md5);
}
void
adddirx(Cdimg *cd, Dump *d, Direc *dir, int lev)
{
int i;
Direc dd;
if(lev == 2){
dd = *dir;
adddir(cd, d, &dd);
return;
}
for(i=0; i<dir->nchild; i++)
adddirx(cd, d, &dir->child[i], lev+1);
}
Dump*
dumpcd(Cdimg *cd, Direc *dir)
{
Dump *d;
d = emalloc(sizeof *d);
d->cd = cd;
adddirx(cd, d, dir, 0);
return d;
}
/*
static ulong
minblock(Direc *root, int lev)
{
int i;
ulong m, n;
m = root->block;
for(i=0; i<root->nchild; i++) {
n = minblock(&root->child[i], lev-1);
if(m > n)
m = n;
}
return m;
}
*/
void
copybutname(Direc *d, Direc *s)
{
Direc x;
x = *d;
*d = *s;
d->name = x.name;
d->confname = x.confname;
}
Direc*
createdumpdir(Direc *root, XDir *dir, char *utfname)
{
char *p;
Direc *d;
if(utfname[0]=='/')
sysfatal("bad dump name '%s'", utfname);
p = strchr(utfname, '/');
if(p == nil || strchr(p+1, '/'))
sysfatal("bad dump name '%s'", utfname);
*p++ = '\0';
if((d = walkdirec(root, utfname)) == nil)
d = adddirec(root, utfname, dir);
if(walkdirec(d, p))
sysfatal("duplicate dump name '%s/%s'", utfname, p);
d = adddirec(d, p, dir);
return d;
}
static void
rmdirec(Direc *d, Direc *kid)
{
Direc *ekid;
ekid = d->child+d->nchild;
assert(d->child <= kid && kid < ekid);
if(ekid != kid+1)
memmove(kid, kid+1, (ekid-(kid+1))*sizeof(*kid));
d->nchild--;
}
void
rmdumpdir(Direc *root, char *utfname)
{
char *p;
Direc *d, *dd;
if(utfname[0]=='/')
sysfatal("bad dump name '%s'", utfname);
p = strchr(utfname, '/');
if(p == nil || strchr(p+1, '/'))
sysfatal("bad dump name '%s'", utfname);
*p++ = '\0';
if((d = walkdirec(root, utfname)) == nil)
sysfatal("cannot remove %s/%s: %s does not exist", utfname, p, utfname);
p[-1] = '/';
if((dd = walkdirec(d, p)) == nil)
sysfatal("cannot remove %s: does not exist", utfname);
rmdirec(d, dd);
if(d->nchild == 0)
rmdirec(root, d);
}
char*
adddumpdir(Direc *root, ulong now, XDir *dir)
{
char buf[40], *p;
int n;
Direc *dday, *dyear;
Tm tm;
tm = *localtime(now);
sprint(buf, "%d", tm.year+1900);
if((dyear = walkdirec(root, buf)) == nil) {
dyear = adddirec(root, buf, dir);
assert(dyear != nil);
}
n = 0;
sprint(buf, "%.2d%.2d", tm.mon+1, tm.mday);
p = buf+strlen(buf);
while(walkdirec(dyear, buf))
sprint(p, "%d", ++n);
dday = adddirec(dyear, buf, dir);
assert(dday != nil);
sprint(buf, "%s/%s", dyear->name, dday->name);
assert(walkdirec(root, buf)==dday);
return atom(buf);
}
/*
* The dump directory tree is inferred from a linked list of special blocks.
* One block is written at the end of each dump.
* The blocks have the form
*
* plan 9 dump cd
* <dump-name> <dump-time> <next-block> <conform-block> <conform-length> \
* <iroot-block> <iroot-length> <jroot-block> <jroot-length>
*
* If only the first line is present, this is the end of the chain.
*/
static char magic[] = "plan 9 dump cd\n";
ulong
Cputdumpblock(Cdimg *cd)
{
ulong x;
Cwseek(cd, cd->nextblock*Blocksize);
x = Cwoffset(cd);
Cwrite(cd, magic, sizeof(magic)-1);
Cpadblock(cd);
return x/Blocksize;
}
int
hasdump(Cdimg *cd)
{
int i;
char buf[128];
for(i=16; i<24; i++) {
Creadblock(cd, buf, i, sizeof buf);
if(memcmp(buf, magic, sizeof(magic)-1) == 0)
return i;
}
return 0;
}
Direc
readdumpdirs(Cdimg *cd, XDir *dir, char *(*cvt)(uchar*, int))
{
char buf[Blocksize];
char *p, *q, *f[16];
int i, nf;
ulong db, t;
Direc *nr, root;
XDir xd;
mkdirec(&root, dir);
db = hasdump(cd);
xd = *dir;
for(;;){
if(db == 0)
sysfatal("error in dump blocks");
Creadblock(cd, buf, db, sizeof buf);
if(memcmp(buf, magic, sizeof(magic)-1) != 0)
break;
p = buf+sizeof(magic)-1;
if(p[0] == '\0')
break;
if((q = strchr(p, '\n')) != nil)
*q = '\0';
nf = tokenize(p, f, nelem(f));
i = 5;
if(nf < i || (cvt==jolietstring && nf < i+2))
sysfatal("error in dump block %lud: nf=%d; p='%s'", db, nf, p);
nr = createdumpdir(&root, &xd, f[0]);
t = strtoul(f[1], 0, 0);
xd.mtime = xd.ctime = xd.atime = t;
db = strtoul(f[2], 0, 0);
if(cvt == jolietstring)
i += 2;
nr->block = strtoul(f[i], 0, 0);
nr->length = strtoul(f[i+1], 0, 0);
}
cd->nulldump = db;
return root;
}
extern void addtx(char*, char*);
static int
isalldigit(char *s)
{
while(*s)
if(!isdigit((uchar)*s++))
return 0;
return 1;
}
void
readdumpconform(Cdimg *cd)
{
char buf[Blocksize];
char *p, *q, *f[10];
ulong cb, nc, m, db;
int nf;
db = hasdump(cd);
assert(map==nil || map->nt == 0);
for(;;){
if(db == 0)
sysfatal("error0 in dump blocks");
Creadblock(cd, buf, db, sizeof buf);
if(memcmp(buf, magic, sizeof(magic)-1) != 0)
break;
p = buf+sizeof(magic)-1;
if(p[0] == '\0')
break;
if((q = strchr(p, '\n')) != nil)
*q = '\0';
nf = tokenize(p, f, nelem(f));
if(nf < 5)
sysfatal("error0 in dump block %lud", db);
db = strtoul(f[2], 0, 0);
cb = strtoul(f[3], 0, 0);
nc = strtoul(f[4], 0, 0);
Crseek(cd, cb*Blocksize);
m = cb*Blocksize+nc;
while(Croffset(cd) < m && (p = Crdline(cd, '\n')) != nil){
p[Clinelen(cd)-1] = '\0';
if(tokenize(p, f, 2) != 2 || (f[0][0] != 'D' && f[0][0] != 'F')
|| strlen(f[0]) != 7 || !isalldigit(f[0]+1))
break;
addtx(atom(f[1]), atom(f[0]));
}
}
if(map)
cd->nconform = map->nt;
else
cd->nconform = 0;
}
|
0e74fb05412a81692b85295d6fb24add602a9d19
|
fbdc48c28e54fb33ae4842ef95ff63893902c99a
|
/src/hal/cmsis/src/dsp/FilteringFunctions/arm_fir_lattice_init_q31.c
|
4dc30cced6b2b78b57cd04a0988c3efd1acb9997
|
[
"MIT",
"LicenseRef-scancode-proprietary-license"
] |
permissive
|
openmv/openmv
|
44d4b79fc8693950a2e330e5e0fd95b5c36e230f
|
8a90e070a88b7fc14c87a00351b9c4a213278419
|
refs/heads/master
| 2023-08-30T20:59:57.227603
| 2023-08-23T16:50:55
| 2023-08-23T16:50:55
| 14,360,940
| 2,150
| 1,226
|
MIT
| 2023-09-14T07:18:15
| 2013-11-13T10:23:44
|
C
|
UTF-8
|
C
| false
| false
| 2,018
|
c
|
arm_fir_lattice_init_q31.c
|
/* ----------------------------------------------------------------------
* Project: CMSIS DSP Library
* Title: arm_fir_lattice_init_q31.c
* Description: Q31 FIR lattice filter initialization function
*
* $Date: 27. January 2017
* $Revision: V.1.5.1
*
* Target Processor: Cortex-M cores
* -------------------------------------------------------------------- */
/*
* Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved.
*
* SPDX-License-Identifier: Apache-2.0
*
* 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
*
* 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 "arm_math.h"
/**
* @ingroup groupFilters
*/
/**
* @addtogroup FIR_Lattice
* @{
*/
/**
* @brief Initialization function for the Q31 FIR lattice filter.
* @param[in] *S points to an instance of the Q31 FIR lattice structure.
* @param[in] numStages number of filter stages.
* @param[in] *pCoeffs points to the coefficient buffer. The array is of length numStages.
* @param[in] *pState points to the state buffer. The array is of length numStages.
* @return none.
*/
void arm_fir_lattice_init_q31(
arm_fir_lattice_instance_q31 * S,
uint16_t numStages,
q31_t * pCoeffs,
q31_t * pState)
{
/* Assign filter taps */
S->numStages = numStages;
/* Assign coefficient pointer */
S->pCoeffs = pCoeffs;
/* Clear state buffer and size is always numStages */
memset(pState, 0, (numStages) * sizeof(q31_t));
/* Assign state pointer */
S->pState = pState;
}
/**
* @} end of FIR_Lattice group
*/
|
51c39ed7379af806c2aa1629332df9304844dd3b
|
4581c9aeab6aceb1eac7e82446aba885e115790e
|
/src/libpgagroal/management.c
|
1b1041498a63a529c861fe620c20a25579b65b5f
|
[
"BSD-3-Clause"
] |
permissive
|
agroal/pgagroal
|
7fc1b5205c5ce7ff9a18c0e42f1d9a9aefe5aae2
|
3792436d73a4ea9296d03ed25fc8e71b0487d316
|
refs/heads/master
| 2023-08-31T09:01:47.500071
| 2023-07-14T14:59:55
| 2023-07-14T14:59:55
| 204,962,510
| 613
| 59
|
BSD-3-Clause
| 2023-09-05T12:35:46
| 2019-08-28T15:19:42
|
C
|
UTF-8
|
C
| false
| false
| 42,343
|
c
|
management.c
|
/*
* Copyright (C) 2023 Red Hat
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list
* of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may
* be used to endorse or promote products derived from this software without specific
* prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/* pgagroal */
#include <pgagroal.h>
#include <logging.h>
#include <network.h>
#include <management.h>
#include <message.h>
#include <pool.h>
#include <utils.h>
#include <configuration.h>
/* system */
#include <errno.h>
#include <stdio.h>
#include <stdatomic.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/un.h>
#include <openssl/err.h>
#include <openssl/ssl.h>
#define MANAGEMENT_HEADER_SIZE 5
static int read_complete(SSL* ssl, int socket, void* buf, size_t size);
static int write_complete(SSL* ssl, int socket, void* buf, size_t size);
static int write_socket(int socket, void* buf, size_t size);
static int write_ssl(SSL* ssl, void* buf, size_t size);
static int write_header(SSL* ssl, int fd, signed char type, int slot);
int
pgagroal_management_read_header(int socket, signed char* id, int32_t* slot)
{
char header[MANAGEMENT_HEADER_SIZE];
if (read_complete(NULL, socket, &header[0], sizeof(header)))
{
pgagroal_log_warn("pgagroal_management_read_header: %d %s", socket, strerror(errno));
errno = 0;
goto error;
}
*id = pgagroal_read_byte(&(header));
*slot = pgagroal_read_int32(&(header[1]));
return 0;
error:
*id = -1;
*slot = -1;
return 1;
}
int
pgagroal_management_read_payload(int socket, signed char id, int* payload_i, char** payload_s)
{
int nr;
char* s = NULL;
char buf2[2];
char buf4[4];
int size;
struct cmsghdr* cmptr = NULL;
struct iovec iov[1];
struct msghdr msg;
*payload_i = -1;
*payload_s = NULL;
switch (id)
{
case MANAGEMENT_TRANSFER_CONNECTION:
case MANAGEMENT_CLIENT_FD:
memset(&buf2[0], 0, sizeof(buf2));
iov[0].iov_base = &buf2[0];
iov[0].iov_len = sizeof(buf2);
cmptr = calloc(1, CMSG_SPACE(sizeof(int)));
if (cmptr == NULL)
{
goto error;
}
cmptr->cmsg_len = CMSG_LEN(sizeof(int));
cmptr->cmsg_level = SOL_SOCKET;
cmptr->cmsg_type = SCM_RIGHTS;
msg.msg_name = NULL;
msg.msg_namelen = 0;
msg.msg_iov = iov;
msg.msg_iovlen = 1;
msg.msg_control = cmptr;
msg.msg_controllen = CMSG_SPACE(sizeof(int));
msg.msg_flags = 0;
if ((nr = recvmsg(socket, &msg, 0)) < 0)
{
goto error;
}
else if (nr == 0)
{
goto error;
}
*payload_i = *(int*)CMSG_DATA(cmptr);
free(cmptr);
break;
case MANAGEMENT_FLUSH:
if (read_complete(NULL, socket, &buf4[0], sizeof(buf4)))
{
goto error;
}
*payload_i = pgagroal_read_int32(&buf4);
if (read_complete(NULL, socket, &buf4[0], sizeof(buf4)))
{
goto error;
}
size = pgagroal_read_int32(&buf4);
s = calloc(1, size + 1);
if (s == NULL)
{
goto error;
}
if (read_complete(NULL, socket, s, size))
{
goto error;
}
*payload_s = s;
break;
case MANAGEMENT_KILL_CONNECTION:
case MANAGEMENT_CLIENT_DONE:
case MANAGEMENT_REMOVE_FD:
if (read_complete(NULL, socket, &buf4[0], sizeof(buf4)))
{
goto error;
}
*payload_i = pgagroal_read_int32(&buf4);
break;
case MANAGEMENT_ENABLEDB:
case MANAGEMENT_DISABLEDB:
case MANAGEMENT_CONFIG_GET:
case MANAGEMENT_CONFIG_SET:
if (read_complete(NULL, socket, &buf4[0], sizeof(buf4)))
{
goto error;
}
*payload_i = pgagroal_read_int32(&buf4);
s = calloc(1, *payload_i + 1);
if (s == NULL)
{
goto error;
}
if (read_complete(NULL, socket, s, *payload_i))
{
goto error;
}
*payload_s = s;
break;
case MANAGEMENT_RESET_SERVER:
case MANAGEMENT_SWITCH_TO:
s = calloc(1, MISC_LENGTH);
if (s == NULL)
{
goto error;
}
if (read_complete(NULL, socket, s, MISC_LENGTH))
{
goto error;
}
*payload_s = s;
break;
case MANAGEMENT_RETURN_CONNECTION:
case MANAGEMENT_GRACEFULLY:
case MANAGEMENT_STOP:
case MANAGEMENT_CANCEL_SHUTDOWN:
case MANAGEMENT_STATUS:
case MANAGEMENT_DETAILS:
case MANAGEMENT_RESET:
case MANAGEMENT_RELOAD:
break;
default:
goto error;
break;
}
return 0;
error:
if (cmptr)
{
free(cmptr);
}
return 1;
}
int
pgagroal_management_transfer_connection(int32_t slot)
{
int fd;
struct configuration* config;
struct cmsghdr* cmptr = NULL;
struct iovec iov[1];
struct msghdr msg;
char buf2[2];
config = (struct configuration*)shmem;
if (pgagroal_connect_unix_socket(config->unix_socket_dir, MAIN_UDS, &fd))
{
pgagroal_log_warn("pgagroal_management_transfer_connection: connect: %d", fd);
errno = 0;
goto error;
}
if (write_header(NULL, fd, MANAGEMENT_TRANSFER_CONNECTION, slot))
{
pgagroal_log_warn("pgagroal_management_transfer_connection: write: %d", fd);
errno = 0;
goto error;
}
/* Write file descriptor */
memset(&buf2[0], 0, sizeof(buf2));
iov[0].iov_base = &buf2[0];
iov[0].iov_len = sizeof(buf2);
cmptr = calloc(1, CMSG_SPACE(sizeof(int)));
if (cmptr == NULL)
{
goto error;
}
cmptr->cmsg_level = SOL_SOCKET;
cmptr->cmsg_type = SCM_RIGHTS;
cmptr->cmsg_len = CMSG_LEN(sizeof(int));
msg.msg_name = NULL;
msg.msg_namelen = 0;
msg.msg_iov = iov;
msg.msg_iovlen = 1;
msg.msg_control = cmptr;
msg.msg_controllen = CMSG_SPACE(sizeof(int));
msg.msg_flags = 0;
*(int*)CMSG_DATA(cmptr) = config->connections[slot].fd;
if (sendmsg(fd, &msg, 0) != 2)
{
goto error;
}
free(cmptr);
pgagroal_disconnect(fd);
return 0;
error:
if (cmptr)
{
free(cmptr);
}
pgagroal_disconnect(fd);
pgagroal_kill_connection(slot, NULL);
return 1;
}
int
pgagroal_management_return_connection(int32_t slot)
{
int fd;
struct configuration* config;
config = (struct configuration*)shmem;
if (pgagroal_connect_unix_socket(config->unix_socket_dir, MAIN_UDS, &fd))
{
pgagroal_log_warn("pgagroal_management_return_connection: connect: %d", fd);
errno = 0;
goto error;
}
if (write_header(NULL, fd, MANAGEMENT_RETURN_CONNECTION, slot))
{
pgagroal_log_warn("pgagroal_management_return_connection: write: %d", fd);
errno = 0;
goto error;
}
pgagroal_disconnect(fd);
return 0;
error:
pgagroal_disconnect(fd);
return 1;
}
int
pgagroal_management_kill_connection(int32_t slot, int socket)
{
int fd;
char buf[4];
struct configuration* config;
config = (struct configuration*)shmem;
if (pgagroal_connect_unix_socket(config->unix_socket_dir, MAIN_UDS, &fd))
{
pgagroal_log_warn("pgagroal_management_kill_connection: connect: %d", fd);
errno = 0;
goto error;
}
if (write_header(NULL, fd, MANAGEMENT_KILL_CONNECTION, slot))
{
pgagroal_log_warn("pgagroal_management_kill_connection: write: %d", fd);
errno = 0;
goto error;
}
pgagroal_write_int32(&buf, socket);
if (write_complete(NULL, fd, &buf, sizeof(buf)))
{
pgagroal_log_warn("pgagroal_management_kill_connection: write: %d %s", fd, strerror(errno));
errno = 0;
goto error;
}
pgagroal_disconnect(fd);
return 0;
error:
pgagroal_disconnect(fd);
return 1;
}
int
pgagroal_management_flush(SSL* ssl, int fd, int32_t mode, char* database)
{
char buf[4];
if (write_header(ssl, fd, MANAGEMENT_FLUSH, -1))
{
pgagroal_log_warn("pgagroal_management_flush: write: %d", fd);
errno = 0;
goto error;
}
pgagroal_write_int32(&buf, mode);
if (write_complete(ssl, fd, &buf, sizeof(buf)))
{
pgagroal_log_warn("pgagroal_management_flush: write: %d %s", fd, strerror(errno));
errno = 0;
goto error;
}
pgagroal_write_int32(&buf, strlen(database));
if (write_complete(ssl, fd, &buf, sizeof(buf)))
{
pgagroal_log_warn("pgagroal_management_flush: write: %d %s", fd, strerror(errno));
errno = 0;
goto error;
}
if (write_complete(ssl, fd, database, strlen(database)))
{
pgagroal_log_warn("pgagroal_management_flush: write: %d %s", fd, strerror(errno));
errno = 0;
goto error;
}
return 0;
error:
return 1;
}
int
pgagroal_management_enabledb(SSL* ssl, int fd, char* database)
{
char buf[4];
if (write_header(ssl, fd, MANAGEMENT_ENABLEDB, -1))
{
pgagroal_log_warn("pgagroal_management_enabledb: write: %d", fd);
errno = 0;
goto error;
}
pgagroal_write_int32(&buf, strlen(database));
if (write_complete(ssl, fd, &buf, sizeof(buf)))
{
pgagroal_log_warn("pgagroal_management_enabledb: write: %d %s", fd, strerror(errno));
errno = 0;
goto error;
}
if (write_complete(ssl, fd, database, strlen(database)))
{
pgagroal_log_warn("pgagroal_management_enabledb: write: %d %s", fd, strerror(errno));
errno = 0;
goto error;
}
return 0;
error:
return 1;
}
int
pgagroal_management_disabledb(SSL* ssl, int fd, char* database)
{
char buf[4];
if (write_header(ssl, fd, MANAGEMENT_DISABLEDB, -1))
{
pgagroal_log_warn("pgagroal_management_disabledb: write: %d", fd);
errno = 0;
goto error;
}
pgagroal_write_int32(&buf, strlen(database));
if (write_complete(ssl, fd, &buf, sizeof(buf)))
{
pgagroal_log_warn("pgagroal_management_disabledb: write: %d %s", fd, strerror(errno));
errno = 0;
goto error;
}
if (write_complete(ssl, fd, database, strlen(database)))
{
pgagroal_log_warn("pgagroal_management_disabledb: write: %d %s", fd, strerror(errno));
errno = 0;
goto error;
}
return 0;
error:
return 1;
}
int
pgagroal_management_gracefully(SSL* ssl, int fd)
{
if (write_header(ssl, fd, MANAGEMENT_GRACEFULLY, -1))
{
pgagroal_log_warn("pgagroal_management_gracefully: write: %d", fd);
errno = 0;
goto error;
}
return 0;
error:
return 1;
}
int
pgagroal_management_stop(SSL* ssl, int fd)
{
if (write_header(ssl, fd, MANAGEMENT_STOP, -1))
{
pgagroal_log_warn("pgagroal_management_stop: write: %d", fd);
errno = 0;
goto error;
}
return 0;
error:
return 1;
}
int
pgagroal_management_cancel_shutdown(SSL* ssl, int fd)
{
if (write_header(ssl, fd, MANAGEMENT_CANCEL_SHUTDOWN, -1))
{
pgagroal_log_warn("pgagroal_management_cancel_shutdown: write: %d", fd);
errno = 0;
goto error;
}
return 0;
error:
return 1;
}
int
pgagroal_management_status(SSL* ssl, int fd)
{
if (write_header(ssl, fd, MANAGEMENT_STATUS, -1))
{
pgagroal_log_warn("pgagroal_management_status: write: %d", fd);
errno = 0;
goto error;
}
return 0;
error:
return 1;
}
int
pgagroal_management_read_status(SSL* ssl, int socket)
{
char buf[16];
char disabled[NUMBER_OF_DISABLED][MAX_DATABASE_LENGTH];
int status;
int active;
int total;
int max;
memset(&buf, 0, sizeof(buf));
memset(&disabled, 0, sizeof(disabled));
if (read_complete(ssl, socket, &buf[0], sizeof(buf)))
{
pgagroal_log_warn("pgagroal_management_read_status: read: %d %s", socket, strerror(errno));
errno = 0;
goto error;
}
if (read_complete(ssl, socket, &disabled[0], sizeof(disabled)))
{
pgagroal_log_warn("pgagroal_management_read_status: read: %d %s", socket, strerror(errno));
errno = 0;
goto error;
}
status = pgagroal_read_int32(&buf);
active = pgagroal_read_int32(&(buf[4]));
total = pgagroal_read_int32(&(buf[8]));
max = pgagroal_read_int32(&(buf[12]));
printf("Status: %s\n", (status == 1 ? "Running" : "Graceful shutdown"));
printf("Active connections: %d\n", active);
printf("Total connections: %d\n", total);
printf("Max connections: %d\n", max);
for (int i = 0; i < NUMBER_OF_DISABLED; i++)
{
if (strcmp(disabled[i], ""))
{
if (!strcmp(disabled[i], "*"))
{
printf("Disabled database: ALL\n");
}
else
{
printf("Disabled database: %s\n", disabled[i]);
}
}
}
return 0;
error:
return 1;
}
int
pgagroal_management_write_status(int socket, bool graceful)
{
char buf[16];
int active;
int total;
struct configuration* config;
memset(&buf, 0, sizeof(buf));
active = 0;
total = 0;
config = (struct configuration*)shmem;
if (!graceful)
{
pgagroal_write_int32(&buf, 1);
}
else
{
pgagroal_write_int32(&buf, 2);
}
for (int i = 0; i < config->max_connections; i++)
{
int state = atomic_load(&config->states[i]);
switch (state)
{
case STATE_IN_USE:
case STATE_GRACEFULLY:
active++;
case STATE_INIT:
case STATE_FREE:
case STATE_FLUSH:
case STATE_IDLE_CHECK:
case STATE_MAX_CONNECTION_AGE:
case STATE_VALIDATION:
case STATE_REMOVE:
total++;
break;
default:
break;
}
}
pgagroal_write_int32(&(buf[4]), active);
pgagroal_write_int32(&(buf[8]), total);
pgagroal_write_int32(&(buf[12]), config->max_connections);
if (write_complete(NULL, socket, &buf, sizeof(buf)))
{
pgagroal_log_warn("pgagroal_management_write_status: write: %d %s", socket, strerror(errno));
errno = 0;
goto error;
}
if (write_complete(NULL, socket, &config->disabled, sizeof(config->disabled)))
{
pgagroal_log_warn("pgagroal_management_write_status: write: %d %s", socket, strerror(errno));
errno = 0;
goto error;
}
return 0;
error:
return 1;
}
int
pgagroal_management_details(SSL* ssl, int fd)
{
if (write_header(ssl, fd, MANAGEMENT_DETAILS, -1))
{
pgagroal_log_warn("pgagroal_management_details: write: %d", fd);
errno = 0;
goto error;
}
return 0;
error:
return 1;
}
int
pgagroal_management_read_details(SSL* ssl, int socket)
{
char header[12 + MAX_NUMBER_OF_CONNECTIONS];
int max_connections = 0;
int limits = 0;
int servers = 0;
memset(&header, 0, sizeof(header));
if (read_complete(ssl, socket, &header[0], sizeof(header)))
{
pgagroal_log_warn("pgagroal_management_read_details: read: %d %s", socket, strerror(errno));
errno = 0;
goto error;
}
max_connections = pgagroal_read_int32(&header);
limits = pgagroal_read_int32(&(header[4]));
servers = pgagroal_read_int32(&(header[8]));
for (int i = 0; i < servers; i++)
{
char server[5 + MISC_LENGTH + MISC_LENGTH];
signed char state;
memset(&server, 0, sizeof(server));
if (read_complete(ssl, socket, &server[0], sizeof(server)))
{
pgagroal_log_warn("pgagroal_management_read_details: read: %d %s", socket, strerror(errno));
errno = 0;
goto error;
}
state = pgagroal_read_byte(&(server[MISC_LENGTH + MISC_LENGTH + 4]));
printf("---------------------\n");
printf("Server: %s\n", pgagroal_read_string(&(server[0])));
printf("Host: %s\n", pgagroal_read_string(&(server[MISC_LENGTH])));
printf("Port: %d\n", pgagroal_read_int32(&(server[MISC_LENGTH + MISC_LENGTH])));
switch (state)
{
case SERVER_NOTINIT:
printf("State: Not init\n");
break;
case SERVER_NOTINIT_PRIMARY:
printf("State: Not init (primary)\n");
break;
case SERVER_PRIMARY:
printf("State: Primary\n");
break;
case SERVER_REPLICA:
printf("State: Replica\n");
break;
case SERVER_FAILOVER:
printf("State: Failover\n");
break;
case SERVER_FAILED:
printf("State: Failed\n");
break;
default:
printf("State: %d\n", state);
break;
}
}
printf("---------------------\n");
for (int i = 0; i < limits; i++)
{
char limit[16 + MAX_DATABASE_LENGTH + MAX_USERNAME_LENGTH];
memset(&limit, 0, sizeof(limit));
if (read_complete(ssl, socket, &limit[0], sizeof(limit)))
{
pgagroal_log_warn("pgagroal_management_read_details: read: %d %s", socket, strerror(errno));
errno = 0;
goto error;
}
printf("Database: %s\n", pgagroal_read_string(&(limit[16])));
printf("Username: %s\n", pgagroal_read_string(&(limit[16 + MAX_DATABASE_LENGTH])));
printf("Active connections: %d\n", pgagroal_read_int32(&(limit)));
printf("Max connections: %d\n", pgagroal_read_int32(&(limit[4])));
printf("Initial connections: %d\n", pgagroal_read_int32(&(limit[8])));
printf("Min connections: %d\n", pgagroal_read_int32(&(limit[12])));
printf("---------------------\n");
}
for (int i = 0; i < max_connections; i++)
{
char details[16 + MAX_DATABASE_LENGTH + MAX_USERNAME_LENGTH + MAX_APPLICATION_NAME];
signed char state;
long time;
time_t t;
char ts[20] = {0};
int pid;
char p[10] = {0};
int fd;
char f[10] = {0};
memset(&details, 0, sizeof(details));
if (read_complete(ssl, socket, &details[0], sizeof(details)))
{
pgagroal_log_warn("pgagroal_management_read_details: read: %d %s", socket, strerror(errno));
errno = 0;
goto error;
}
state = (signed char)header[12 + i];
time = pgagroal_read_long(&(details[0]));
pid = pgagroal_read_int32(&(details[8]));
fd = pgagroal_read_int32(&(details[12]));
t = time;
strftime(ts, 20, "%Y-%m-%d %H:%M:%S", localtime(&t));
sprintf(p, "%d", pid);
sprintf(f, "%d", fd);
printf("Connection %4d: %-15s %-19s %-6s %-6s %s %s %s\n",
i,
pgagroal_get_state_string(state),
time > 0 ? ts : "",
pid > 0 ? p : "",
fd > 0 ? f : "",
pgagroal_read_string(&(details[16])),
pgagroal_read_string(&(details[16 + MAX_DATABASE_LENGTH])),
pgagroal_read_string(&(details[16 + MAX_DATABASE_LENGTH + MAX_USERNAME_LENGTH])));
}
return 0;
error:
return 1;
}
int
pgagroal_management_write_details(int socket)
{
char header[12 + MAX_NUMBER_OF_CONNECTIONS];
struct configuration* config;
config = (struct configuration*)shmem;
memset(&header, 0, sizeof(header));
pgagroal_write_int32(header, config->max_connections);
pgagroal_write_int32(header + 4, config->number_of_limits);
pgagroal_write_int32(header + 8, config->number_of_servers);
for (int i = 0; i < config->max_connections; i++)
{
signed char state = atomic_load(&config->states[i]);
header[12 + i] = (char)state;
}
if (write_complete(NULL, socket, header, sizeof(header)))
{
pgagroal_log_warn("pgagroal_management_write_details: write: %d %s", socket, strerror(errno));
errno = 0;
goto error;
}
for (int i = 0; i < config->number_of_servers; i++)
{
char server[5 + MISC_LENGTH + MISC_LENGTH];
memset(&server, 0, sizeof(server));
pgagroal_write_string(server, config->servers[i].name);
pgagroal_write_string(server + MISC_LENGTH, config->servers[i].host);
pgagroal_write_int32(server + MISC_LENGTH + MISC_LENGTH, config->servers[i].port);
pgagroal_write_byte(server + MISC_LENGTH + MISC_LENGTH + 4, atomic_load(&config->servers[i].state));
if (write_complete(NULL, socket, server, sizeof(server)))
{
pgagroal_log_warn("pgagroal_management_write_details: write: %d %s", socket, strerror(errno));
errno = 0;
goto error;
}
}
for (int i = 0; i < config->number_of_limits; i++)
{
char limit[16 + MAX_DATABASE_LENGTH + MAX_USERNAME_LENGTH];
memset(&limit, 0, sizeof(limit));
pgagroal_write_int32(limit, atomic_load(&config->limits[i].active_connections));
pgagroal_write_int32(limit + 4, config->limits[i].max_size);
pgagroal_write_int32(limit + 8, config->limits[i].initial_size);
pgagroal_write_int32(limit + 12, config->limits[i].min_size);
pgagroal_write_string(limit + 16, config->limits[i].database);
pgagroal_write_string(limit + 16 + MAX_DATABASE_LENGTH, config->limits[i].username);
if (write_complete(NULL, socket, &limit, sizeof(limit)))
{
pgagroal_log_warn("pgagroal_management_write_details: write: %d %s", socket, strerror(errno));
errno = 0;
goto error;
}
}
for (int i = 0; i < config->max_connections; i++)
{
char details[16 + MAX_DATABASE_LENGTH + MAX_USERNAME_LENGTH + MAX_APPLICATION_NAME];
memset(&details, 0, sizeof(details));
pgagroal_write_long(details, (long)config->connections[i].start_time);
pgagroal_write_long(details, (long)config->connections[i].timestamp);
pgagroal_write_int32(details + 8, (int)config->connections[i].pid);
pgagroal_write_int32(details + 12, (int)config->connections[i].fd);
pgagroal_write_string(details + 16, config->connections[i].database);
pgagroal_write_string(details + 16 + MAX_DATABASE_LENGTH, config->connections[i].username);
pgagroal_write_string(details + 16 + MAX_DATABASE_LENGTH + MAX_USERNAME_LENGTH, config->connections[i].appname);
if (write_complete(NULL, socket, &details, sizeof(details)))
{
pgagroal_log_warn("pgagroal_management_write_details: write: %d %s", socket, strerror(errno));
errno = 0;
goto error;
}
}
return 0;
error:
return 1;
}
int
pgagroal_management_isalive(SSL* ssl, int fd)
{
if (write_header(ssl, fd, MANAGEMENT_ISALIVE, -1))
{
pgagroal_log_warn("pgagroal_management_isalive: write: %d", fd);
errno = 0;
goto error;
}
return 0;
error:
return 1;
}
int
pgagroal_management_read_isalive(SSL* ssl, int socket, int* status)
{
char buf[4];
memset(&buf, 0, sizeof(buf));
if (read_complete(ssl, socket, &buf[0], sizeof(buf)))
{
pgagroal_log_warn("pgagroal_management_read_isalive: read: %d %s", socket, strerror(errno));
errno = 0;
goto error;
}
*status = pgagroal_read_int32(&buf);
return 0;
error:
return 1;
}
int
pgagroal_management_write_isalive(int socket, bool gracefully)
{
char buf[4];
memset(&buf, 0, sizeof(buf));
if (!gracefully)
{
pgagroal_write_int32(buf, 1);
}
else
{
pgagroal_write_int32(buf, 2);
}
if (write_complete(NULL, socket, &buf, sizeof(buf)))
{
pgagroal_log_warn("pgagroal_management_write_isalive: write: %d %s", socket, strerror(errno));
errno = 0;
goto error;
}
return 0;
error:
return 1;
}
int
pgagroal_management_reset(SSL* ssl, int fd)
{
if (write_header(ssl, fd, MANAGEMENT_RESET, -1))
{
pgagroal_log_warn("pgagroal_management_reset: write: %d", fd);
errno = 0;
goto error;
}
return 0;
error:
return 1;
}
int
pgagroal_management_reset_server(SSL* ssl, int fd, char* server)
{
char name[MISC_LENGTH];
if (write_header(ssl, fd, MANAGEMENT_RESET_SERVER, -1))
{
pgagroal_log_warn("pgagroal_management_reset_server: write: %d", fd);
errno = 0;
goto error;
}
memset(&name[0], 0, MISC_LENGTH);
memcpy(&name[0], server, strlen(server));
if (write_complete(ssl, fd, &name[0], sizeof(name)))
{
pgagroal_log_warn("pgagroal_management_reset_server_: write: %d %s", fd, strerror(errno));
errno = 0;
goto error;
}
return 0;
error:
return 1;
}
int
pgagroal_management_client_done(pid_t pid)
{
char buf[4];
int fd;
struct configuration* config;
config = (struct configuration*)shmem;
if (pgagroal_connect_unix_socket(config->unix_socket_dir, MAIN_UDS, &fd))
{
pgagroal_log_warn("pgagroal_management_client_done: connect: %d", fd);
errno = 0;
goto error;
}
if (write_header(NULL, fd, MANAGEMENT_CLIENT_DONE, -1))
{
pgagroal_log_warn("pgagroal_management_client_done: write: %d", fd);
errno = 0;
goto error;
}
memset(&buf, 0, sizeof(buf));
pgagroal_write_int32(buf, pid);
if (write_complete(NULL, fd, &buf, sizeof(buf)))
{
pgagroal_log_warn("pgagroal_management_client_done: write: %d %s", fd, strerror(errno));
errno = 0;
goto error;
}
pgagroal_disconnect(fd);
return 0;
error:
pgagroal_disconnect(fd);
return 1;
}
int
pgagroal_management_client_fd(int32_t slot, pid_t pid)
{
char p[MISC_LENGTH];
int fd;
struct configuration* config;
struct cmsghdr* cmptr = NULL;
struct iovec iov[1];
struct msghdr msg;
char buf[2]; /* send_fd()/recv_fd() 2-byte protocol */
config = (struct configuration*)shmem;
memset(&p, 0, sizeof(p));
snprintf(&p[0], sizeof(p), ".s.%d", pid);
if (pgagroal_connect_unix_socket(config->unix_socket_dir, &p[0], &fd))
{
pgagroal_log_debug("pgagroal_management_client_fd: connect: %d", fd);
errno = 0;
goto unavailable;
}
if (write_header(NULL, fd, MANAGEMENT_CLIENT_FD, slot))
{
pgagroal_log_warn("pgagroal_management_client_fd: write: %d", fd);
errno = 0;
goto error;
}
/* Write file descriptor */
iov[0].iov_base = buf;
iov[0].iov_len = 2;
msg.msg_iov = iov;
msg.msg_iovlen = 1;
msg.msg_name = NULL;
msg.msg_namelen = 0;
cmptr = malloc(CMSG_LEN(sizeof(int)));
cmptr->cmsg_level = SOL_SOCKET;
cmptr->cmsg_type = SCM_RIGHTS;
cmptr->cmsg_len = CMSG_LEN(sizeof(int));
msg.msg_control = cmptr;
msg.msg_controllen = CMSG_LEN(sizeof(int));
*(int*)CMSG_DATA(cmptr) = config->connections[slot].fd;
buf[1] = 0; /* zero status means OK */
buf[0] = 0; /* null byte flag to recv_fd() */
if (sendmsg(fd, &msg, 0) != 2)
{
goto error;
}
free(cmptr);
pgagroal_disconnect(fd);
return 0;
unavailable:
free(cmptr);
pgagroal_disconnect(fd);
return 1;
error:
free(cmptr);
pgagroal_disconnect(fd);
pgagroal_kill_connection(slot, NULL);
return 1;
}
int
pgagroal_management_switch_to(SSL* ssl, int fd, char* server)
{
char name[MISC_LENGTH];
if (write_header(ssl, fd, MANAGEMENT_SWITCH_TO, -1))
{
pgagroal_log_warn("pgagroal_management_switch_to: write: %d", fd);
errno = 0;
goto error;
}
memset(&name[0], 0, MISC_LENGTH);
memcpy(&name[0], server, strlen(server));
if (write_complete(ssl, fd, &name[0], sizeof(name)))
{
pgagroal_log_warn("pgagroal_management_switch_to: write: %d %s", fd, strerror(errno));
errno = 0;
goto error;
}
return 0;
error:
return 1;
}
int
pgagroal_management_reload(SSL* ssl, int fd)
{
if (write_header(ssl, fd, MANAGEMENT_RELOAD, -1))
{
pgagroal_log_warn("pgagroal_management_reload: write: %d", fd);
errno = 0;
goto error;
}
return 0;
error:
return 1;
}
int
pgagroal_management_remove_fd(int32_t slot, int socket, pid_t pid)
{
char p[MISC_LENGTH];
int fd;
char buf[4];
struct configuration* config;
config = (struct configuration*)shmem;
if (atomic_load(&config->states[slot]) == STATE_NOTINIT)
{
return 0;
}
memset(&p, 0, sizeof(p));
snprintf(&p[0], sizeof(p), ".s.%d", pid);
if (pgagroal_connect_unix_socket(config->unix_socket_dir, &p[0], &fd))
{
pgagroal_log_debug("pgagroal_management_remove_fd: slot %d state %d database %s user %s socket %d pid %d connect: %d",
slot, atomic_load(&config->states[slot]),
config->connections[slot].database, config->connections[slot].username, socket, pid, fd);
errno = 0;
goto error;
}
if (write_header(NULL, fd, MANAGEMENT_REMOVE_FD, slot))
{
pgagroal_log_warn("pgagroal_management_remove_fd: write: %d", fd);
errno = 0;
goto error;
}
pgagroal_write_int32(&buf, socket);
if (write_complete(NULL, fd, &buf, sizeof(buf)))
{
pgagroal_log_warn("pgagroal_management_remove_fd: write: %d %s", fd, strerror(errno));
errno = 0;
goto error;
}
pgagroal_disconnect(fd);
return 0;
error:
pgagroal_disconnect(fd);
return 1;
}
static int
read_complete(SSL* ssl, int socket, void* buf, size_t size)
{
ssize_t r;
size_t offset;
size_t needs;
int retries;
offset = 0;
needs = size;
retries = 0;
read:
if (ssl == NULL)
{
r = read(socket, buf + offset, needs);
}
else
{
r = SSL_read(ssl, buf + offset, needs);
}
if (r == -1)
{
if (errno == EAGAIN || errno == EWOULDBLOCK)
{
errno = 0;
goto read;
}
goto error;
}
else if (r < needs)
{
SLEEP(10000000L)
pgagroal_log_trace("Got: %ld, needs: %ld", r, needs);
if (retries < 100)
{
offset += r;
needs -= r;
retries++;
goto read;
}
else
{
errno = EINVAL;
goto error;
}
}
return 0;
error:
return 1;
}
static int
write_complete(SSL* ssl, int socket, void* buf, size_t size)
{
if (ssl == NULL)
{
return write_socket(socket, buf, size);
}
return write_ssl(ssl, buf, size);
}
static int
write_socket(int socket, void* buf, size_t size)
{
bool keep_write = false;
ssize_t numbytes;
int offset;
ssize_t totalbytes;
ssize_t remaining;
numbytes = 0;
offset = 0;
totalbytes = 0;
remaining = size;
do
{
numbytes = write(socket, buf + offset, remaining);
if (likely(numbytes == size))
{
return 0;
}
else if (numbytes != -1)
{
offset += numbytes;
totalbytes += numbytes;
remaining -= numbytes;
if (totalbytes == size)
{
return 0;
}
pgagroal_log_debug("Write %d - %zd/%zd vs %zd", socket, numbytes, totalbytes, size);
keep_write = true;
errno = 0;
}
else
{
switch (errno)
{
case EAGAIN:
keep_write = true;
errno = 0;
break;
default:
keep_write = false;
break;
}
}
}
while (keep_write);
return 1;
}
static int
write_ssl(SSL* ssl, void* buf, size_t size)
{
bool keep_write = false;
ssize_t numbytes;
int offset;
ssize_t totalbytes;
ssize_t remaining;
numbytes = 0;
offset = 0;
totalbytes = 0;
remaining = size;
do
{
numbytes = SSL_write(ssl, buf + offset, remaining);
if (likely(numbytes == size))
{
return 0;
}
else if (numbytes > 0)
{
offset += numbytes;
totalbytes += numbytes;
remaining -= numbytes;
if (totalbytes == size)
{
return 0;
}
pgagroal_log_debug("SSL/Write %d - %zd/%zd vs %zd", SSL_get_fd(ssl), numbytes, totalbytes, size);
keep_write = true;
errno = 0;
}
else
{
int err = SSL_get_error(ssl, numbytes);
switch (err)
{
case SSL_ERROR_ZERO_RETURN:
case SSL_ERROR_WANT_READ:
case SSL_ERROR_WANT_WRITE:
case SSL_ERROR_WANT_CONNECT:
case SSL_ERROR_WANT_ACCEPT:
case SSL_ERROR_WANT_X509_LOOKUP:
#ifndef HAVE_OPENBSD
#if (OPENSSL_VERSION_NUMBER >= 0x10100000L)
case SSL_ERROR_WANT_ASYNC:
case SSL_ERROR_WANT_ASYNC_JOB:
#if (OPENSSL_VERSION_NUMBER >= 0x10101000L)
case SSL_ERROR_WANT_CLIENT_HELLO_CB:
#endif
#endif
#endif
errno = 0;
keep_write = true;
break;
case SSL_ERROR_SYSCALL:
pgagroal_log_error("SSL_ERROR_SYSCALL: %s (%d)", strerror(errno), SSL_get_fd(ssl));
errno = 0;
keep_write = false;
break;
case SSL_ERROR_SSL:
pgagroal_log_error("SSL_ERROR_SSL: %s (%d)", strerror(errno), SSL_get_fd(ssl));
errno = 0;
keep_write = false;
break;
}
ERR_clear_error();
if (!keep_write)
{
return 1;
}
}
}
while (keep_write);
return 1;
}
static int
write_header(SSL* ssl, int fd, signed char type, int slot)
{
char header[MANAGEMENT_HEADER_SIZE];
pgagroal_write_byte(&(header), type);
pgagroal_write_int32(&(header[1]), slot);
return write_complete(ssl, fd, &(header), MANAGEMENT_HEADER_SIZE);
}
int
pgagroal_management_config_get(SSL* ssl, int socket, char* config_key)
{
char buf[4];
size_t size;
// security check: avoid writing something null or with too much stuff!
if (!config_key || !strlen(config_key))
{
pgagroal_log_debug("pgagroal_management_config_get: no key specified");
goto error;
}
size = strlen(config_key) + 1;
if (size > MISC_LENGTH)
{
pgagroal_log_debug("pgagroal_management_config_get: key <%s> too big (%d bytes)", config_key, size);
goto error;
}
// send the header for this command
if (write_header(ssl, socket, MANAGEMENT_CONFIG_GET, -1))
{
pgagroal_log_debug("pgagroal_management_config_get: write error on header for key <%s> on socket %d", config_key, socket);
goto error;
}
// send the size of the payload
memset(&buf, 0, sizeof(buf));
pgagroal_write_int32(&buf, size);
if (write_complete(ssl, socket, &buf, sizeof(buf)))
{
pgagroal_log_debug("pgagroal_management_config_get: write error for the size of the payload (%d bytes for <%s>, socket %d): %s",
size,
config_key,
socket,
strerror(errno));
goto error;
}
// send the effective payload, i.e., the configuration parameter name to get
memset(&buf, 0, sizeof(buf));
if (write_complete(ssl, socket, config_key, size))
{
pgagroal_log_debug("pgagroal_management_config_get: write error sending the configuration name <%s> over socket %d: %s", config_key, socket, strerror(errno));
goto error;
}
return 0;
error:
errno = 0;
return 1;
}
int
pgagroal_management_write_config_get(int socket, char* config_key)
{
char data[MISC_LENGTH];
char buf[4];
size_t size;
if (!config_key || !strlen(config_key))
{
pgagroal_log_debug("pgagroal_management_write_config_get: no key specified");
goto error;
}
size = strlen(config_key) + 1;
if (size > MISC_LENGTH)
{
pgagroal_log_debug("pgagroal_management_write_config_get: key <%s> too big (%d bytes)", config_key, size);
goto error;
}
memset(&data, 0, sizeof(data));
if (pgagroal_write_config_value(&data[0], config_key, sizeof(data)))
{
pgagroal_log_debug("pgagroal_management_write_config_get: unknwon configuration key <%s>", config_key);
// leave the payload empty, so a zero filled payload will be sent
}
// send the size of the payload
memset(&buf, 0, sizeof(buf));
size = strlen(data) + 1;
pgagroal_write_int32(&buf, size);
if (write_complete(NULL, socket, &buf, sizeof(buf)))
{
pgagroal_log_debug("pgagroal_management_write_config_get: write error for the size of the payload <%s> (%d bytes for <%s>, socket %d): %s",
data,
size,
config_key,
socket,
strerror(errno));
goto error;
}
if (write_complete(NULL, socket, data, size))
{
pgagroal_log_debug("pgagroal_management_write_config_get (%s): write: %d %s", config_key, socket, strerror(errno));
goto error;
}
return 0;
error:
errno = 0;
return 1;
}
int
pgagroal_management_read_config_get(int socket, char** data)
{
int size = MISC_LENGTH;
return pgagroal_management_read_payload(socket, MANAGEMENT_CONFIG_GET, &size, data);
}
int
pgagroal_management_config_set(SSL* ssl, int socket, char* config_key, char* config_value)
{
char buf[4];
size_t size;
// security check: avoid writing something null or with too much stuff!
if (!config_key || !strlen(config_key) || !config_value || !strlen(config_value))
{
pgagroal_log_debug("pgagroal_management_config_set: no key or value specified");
goto error;
}
if (strlen(config_key) > MISC_LENGTH - 1 || strlen(config_value) > MISC_LENGTH - 1)
{
pgagroal_log_debug("pgagroal_management_config_set: key <%s> or value <%s> too big (max %d bytes)", config_key, config_value, MISC_LENGTH);
goto error;
}
// send the header for this command
if (write_header(ssl, socket, MANAGEMENT_CONFIG_SET, -1))
{
pgagroal_log_debug("pgagroal_management_config_set: write error on header for key <%s> on socket %d", config_key, socket);
goto error;
}
/*
* send a message with the size of the key, the key
* then the size of the value and the value
*/
// send the size of the payload for the config key
memset(&buf, 0, sizeof(buf));
size = strlen(config_key) + 1;
pgagroal_write_int32(&buf, size);
if (write_complete(ssl, socket, &buf, sizeof(buf)))
{
pgagroal_log_debug("pgagroal_management_config_set: write error for the size of the payload (%d bytes for <%s>, socket %d): %s",
size,
config_key,
socket,
strerror(errno));
goto error;
}
// send the effective payload, i.e., the configuration parameter name to get
memset(&buf, 0, sizeof(buf));
if (write_complete(ssl, socket, config_key, size))
{
pgagroal_log_debug("pgagroal_management_config_set: write error sending the configuration name <%s> over socket %d: %s", config_key, socket, strerror(errno));
goto error;
}
// send the size of the payload for the config value
memset(&buf, 0, sizeof(buf));
size = strlen(config_value) + 1;
pgagroal_write_int32(&buf, size);
if (write_complete(ssl, socket, &buf, sizeof(buf)))
{
pgagroal_log_debug("pgagroal_management_config_set: write error for the size of the payload (%d bytes for <%s>, socket %d): %s",
size,
config_value,
socket,
strerror(errno));
goto error;
}
// send the effective payload, i.e., the configuration value to set
memset(&buf, 0, sizeof(buf));
if (write_complete(ssl, socket, config_value, size))
{
pgagroal_log_warn("pgagroal_management_config_set: write error sending the configuration value <%s> over socket %d: %s", config_value, socket, strerror(errno));
goto error;
}
return 0;
error:
errno = 0;
return 1;
}
int
pgagroal_management_write_config_set(int socket, char* config_key, char* config_value)
{
if (!config_key || !strlen(config_key) || !config_value || !strlen(config_value))
{
pgagroal_log_warn("pgagroal_management_write_config_set: no key or value specified");
goto error;
}
if (strlen(config_key) > MISC_LENGTH - 1 || strlen(config_value) > MISC_LENGTH - 1)
{
pgagroal_log_warn("pgagroal_management_write_config_set: key <%s> or value <%s> too big (max %d bytes)", config_key, config_value, MISC_LENGTH);
goto error;
}
pgagroal_log_debug("pgagroal_management_write_config_set: trying to set <%s> to <%s>", config_key, config_value);
// do set the configuration value
if (pgagroal_apply_configuration(config_key, config_value))
{
pgagroal_log_debug("pgagroal_management_write_config_set: unable to apply changes to <%s> -> <%s>", config_key, config_value);
}
// query back the status of the parameter
// and send it over the socket
return pgagroal_management_write_config_get(socket, config_key);
error:
errno = 0;
return 1;
}
|
19ad131a7b7c67610de67861565e3d1b36403eb5
|
670c8a0a88870f92e3218a75a113ad375e17a3ae
|
/code/cha11/Time.h
|
d7e34e9450b7d9f897ce9e0b8f8c32f0f02e4eea
|
[] |
no_license
|
AllenDowney/ThinkCPP
|
8797a856e802b5b9c5c666ad71ba0780e388ba48
|
2ca51172a3104f455612e879be36681bf6c1b230
|
refs/heads/master
| 2022-04-26T19:13:02.534278
| 2022-03-16T20:31:36
| 2022-03-16T20:31:36
| 37,997,579
| 117
| 58
| null | 2022-03-16T20:31:37
| 2015-06-24T16:46:10
|
PostScript
|
UTF-8
|
C
| false
| false
| 360
|
h
|
Time.h
|
struct Time {
// instance variables
int hour, minute;
double second;
// constructors
Time (int hour, int min, double secs);
Time (double secs);
// modifiers
void increment (double secs);
// functions
void print () const;
bool after (const Time& time2) const;
Time add (const Time& t2) const;
double convertToSeconds () const;
};
|
c4e677841832983bae5a1a424c14234732abc2f9
|
c0bfd93cd7f26a271268e504959256f1e02c6806
|
/components/libsodium/libsodium/test/default/aead_chacha20poly1305.c
|
8d1b3aaeba7bbc7207a19ca7a2e539f1a96aef62
|
[
"ISC",
"Apache-2.0"
] |
permissive
|
espressif/ESP8266_RTOS_SDK
|
606f396e92d2675d9854f0fabd88587fbbbaf267
|
af0cdc36fa2600033d0a09301c754008cf1503c1
|
refs/heads/master
| 2023-08-24T22:40:15.373553
| 2023-05-06T02:04:24
| 2023-05-06T02:04:24
| 27,584,181
| 3,163
| 1,749
|
Apache-2.0
| 2023-08-09T10:48:13
| 2014-12-05T09:27:12
|
C
|
UTF-8
|
C
| false
| false
| 13,726
|
c
|
aead_chacha20poly1305.c
|
#define TEST_NAME "aead_chacha20poly1305"
#include "cmptest.h"
static int
tv(void)
{
#undef MLEN
#define MLEN 10U
#undef ADLEN
#define ADLEN 10U
#undef CLEN
#define CLEN (MLEN + crypto_aead_chacha20poly1305_ABYTES)
static const unsigned char firstkey[crypto_aead_chacha20poly1305_KEYBYTES]
= { 0x42, 0x90, 0xbc, 0xb1, 0x54, 0x17, 0x35, 0x31, 0xf3, 0x14, 0xaf,
0x57, 0xf3, 0xbe, 0x3b, 0x50, 0x06, 0xda, 0x37, 0x1e, 0xce, 0x27,
0x2a, 0xfa, 0x1b, 0x5d, 0xbd, 0xd1, 0x10, 0x0a, 0x10, 0x07 };
static const unsigned char m[MLEN]
= { 0x86, 0xd0, 0x99, 0x74, 0x84, 0x0b, 0xde, 0xd2, 0xa5, 0xca };
static const unsigned char nonce[crypto_aead_chacha20poly1305_NPUBBYTES]
= { 0xcd, 0x7c, 0xf6, 0x7b, 0xe3, 0x9c, 0x79, 0x4a };
static const unsigned char ad[ADLEN]
= { 0x87, 0xe2, 0x29, 0xd4, 0x50, 0x08, 0x45, 0xa0, 0x79, 0xc0 };
unsigned char *c = (unsigned char *) sodium_malloc(CLEN);
unsigned char *detached_c = (unsigned char *) sodium_malloc(MLEN);
unsigned char *mac = (unsigned char *) sodium_malloc(crypto_aead_chacha20poly1305_ABYTES);
unsigned char *m2 = (unsigned char *) sodium_malloc(MLEN);
unsigned long long found_clen;
unsigned long long found_maclen;
unsigned long long m2len;
size_t i;
crypto_aead_chacha20poly1305_encrypt(c, &found_clen, m, MLEN,
ad, ADLEN,
NULL, nonce, firstkey);
if (found_clen != CLEN) {
printf("found_clen is not properly set\n");
}
for (i = 0U; i < CLEN; ++i) {
printf(",0x%02x", (unsigned int) c[i]);
if (i % 8 == 7) {
printf("\n");
}
}
printf("\n");
crypto_aead_chacha20poly1305_encrypt_detached(detached_c,
mac, &found_maclen,
m, MLEN, ad, ADLEN,
NULL, nonce, firstkey);
if (found_maclen != crypto_aead_chacha20poly1305_abytes()) {
printf("found_maclen is not properly set\n");
}
if (memcmp(detached_c, c, MLEN) != 0) {
printf("detached ciphertext is bogus\n");
}
if (crypto_aead_chacha20poly1305_decrypt(m2, &m2len, NULL, c, CLEN,
ad, ADLEN,
nonce, firstkey) != 0) {
printf("crypto_aead_chacha20poly1305_decrypt() failed\n");
}
if (m2len != MLEN) {
printf("m2len is not properly set\n");
}
if (memcmp(m, m2, MLEN) != 0) {
printf("m != m2\n");
}
memset(m2, 0, m2len);
if (crypto_aead_chacha20poly1305_decrypt_detached(m2, NULL,
c, MLEN, mac,
ad, ADLEN,
nonce, firstkey) != 0) {
printf("crypto_aead_chacha20poly1305_decrypt_detached() failed\n");
}
if (memcmp(m, m2, MLEN) != 0) {
printf("detached m != m2\n");
}
for (i = 0U; i < CLEN; i++) {
c[i] ^= (i + 1U);
if (crypto_aead_chacha20poly1305_decrypt(m2, NULL, NULL, c, CLEN,
ad, ADLEN, nonce, firstkey)
== 0 || memcmp(m, m2, MLEN) == 0) {
printf("message can be forged\n");
}
c[i] ^= (i + 1U);
}
crypto_aead_chacha20poly1305_encrypt(c, &found_clen, m, MLEN,
NULL, 0U, NULL, nonce, firstkey);
if (found_clen != CLEN) {
printf("found_clen is not properly set (adlen=0)\n");
}
for (i = 0U; i < CLEN; ++i) {
printf(",0x%02x", (unsigned int) c[i]);
if (i % 8 == 7) {
printf("\n");
}
}
printf("\n");
if (crypto_aead_chacha20poly1305_decrypt(m2, &m2len, NULL, c, CLEN,
NULL, 0U, nonce, firstkey) != 0) {
printf("crypto_aead_chacha20poly1305_decrypt() failed (adlen=0)\n");
}
if (m2len != MLEN) {
printf("m2len is not properly set (adlen=0)\n");
}
if (memcmp(m, m2, MLEN) != 0) {
printf("m != m2 (adlen=0)\n");
}
m2len = 1;
if (crypto_aead_chacha20poly1305_decrypt(
m2, &m2len, NULL, NULL,
randombytes_uniform(crypto_aead_chacha20poly1305_ABYTES),
NULL, 0U, nonce, firstkey) != -1) {
printf("crypto_aead_chacha20poly1305_decrypt() worked with a short "
"ciphertext\n");
}
if (m2len != 0) {
printf("Message length should have been set to zero after a failure\n");
}
m2len = 1;
if (crypto_aead_chacha20poly1305_decrypt(m2, &m2len, NULL, c, 0U, NULL, 0U,
nonce, firstkey) != -1) {
printf("crypto_aead_chacha20poly1305_decrypt() worked with an empty "
"ciphertext\n");
}
if (m2len != 0) {
printf("Message length should have been set to zero after a failure\n");
}
memcpy(c, m, MLEN);
crypto_aead_chacha20poly1305_encrypt(c, &found_clen, c, MLEN,
NULL, 0U, NULL, nonce, firstkey);
if (found_clen != CLEN) {
printf("found_clen is not properly set (adlen=0)\n");
}
for (i = 0U; i < CLEN; ++i) {
printf(",0x%02x", (unsigned int) c[i]);
if (i % 8 == 7) {
printf("\n");
}
}
printf("\n");
if (crypto_aead_chacha20poly1305_decrypt(c, &m2len, NULL, c, CLEN,
NULL, 0U, nonce, firstkey) != 0) {
printf("crypto_aead_chacha20poly1305_decrypt() failed (adlen=0)\n");
}
if (m2len != MLEN) {
printf("m2len is not properly set (adlen=0)\n");
}
if (memcmp(m, c, MLEN) != 0) {
printf("m != c (adlen=0)\n");
}
sodium_free(c);
sodium_free(detached_c);
sodium_free(mac);
sodium_free(m2);
assert(crypto_aead_chacha20poly1305_keybytes() > 0U);
assert(crypto_aead_chacha20poly1305_npubbytes() > 0U);
assert(crypto_aead_chacha20poly1305_nsecbytes() == 0U);
return 0;
}
static int
tv_ietf(void)
{
#undef MLEN
#define MLEN 114U
#undef ADLEN
#define ADLEN 12U
#undef CLEN
#define CLEN (MLEN + crypto_aead_chacha20poly1305_ietf_ABYTES)
static const unsigned char firstkey[crypto_aead_chacha20poly1305_ietf_KEYBYTES]
= {
0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f
};
#undef MESSAGE
#define MESSAGE "Ladies and Gentlemen of the class of '99: If I could offer you " \
"only one tip for the future, sunscreen would be it."
unsigned char *m = (unsigned char *) sodium_malloc(MLEN);
static const unsigned char nonce[crypto_aead_chacha20poly1305_ietf_NPUBBYTES]
= { 0x07, 0x00, 0x00, 0x00,
0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47 };
static const unsigned char ad[ADLEN]
= { 0x50, 0x51, 0x52, 0x53, 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7 };
unsigned char *c = (unsigned char *) sodium_malloc(CLEN);
unsigned char *detached_c = (unsigned char *) sodium_malloc(MLEN);
unsigned char *mac = (unsigned char *) sodium_malloc(crypto_aead_chacha20poly1305_ietf_ABYTES);
unsigned char *m2 = (unsigned char *) sodium_malloc(MLEN);
unsigned long long found_clen;
unsigned long long found_maclen;
unsigned long long m2len;
size_t i;
assert(sizeof MESSAGE - 1U == MLEN);
memcpy(m, MESSAGE, MLEN);
crypto_aead_chacha20poly1305_ietf_encrypt(c, &found_clen, m, MLEN,
ad, ADLEN,
NULL, nonce, firstkey);
if (found_clen != MLEN + crypto_aead_chacha20poly1305_ietf_abytes()) {
printf("found_clen is not properly set\n");
}
for (i = 0U; i < CLEN; ++i) {
printf(",0x%02x", (unsigned int) c[i]);
if (i % 8 == 7) {
printf("\n");
}
}
printf("\n");
crypto_aead_chacha20poly1305_ietf_encrypt_detached(detached_c,
mac, &found_maclen,
m, MLEN,
ad, ADLEN,
NULL, nonce, firstkey);
if (found_maclen != crypto_aead_chacha20poly1305_ietf_abytes()) {
printf("found_maclen is not properly set\n");
}
if (memcmp(detached_c, c, MLEN) != 0) {
printf("detached ciphertext is bogus\n");
}
if (crypto_aead_chacha20poly1305_ietf_decrypt(m2, &m2len, NULL, c, CLEN, ad,
ADLEN, nonce, firstkey) != 0) {
printf("crypto_aead_chacha20poly1305_ietf_decrypt() failed\n");
}
if (m2len != MLEN) {
printf("m2len is not properly set\n");
}
if (memcmp(m, m2, MLEN) != 0) {
printf("m != m2\n");
}
memset(m2, 0, m2len);
if (crypto_aead_chacha20poly1305_ietf_decrypt_detached(m2, NULL,
c, MLEN, mac,
ad, ADLEN,
nonce, firstkey) != 0) {
printf("crypto_aead_chacha20poly1305_ietf_decrypt_detached() failed\n");
}
if (memcmp(m, m2, MLEN) != 0) {
printf("detached m != m2\n");
}
for (i = 0U; i < CLEN; i++) {
c[i] ^= (i + 1U);
if (crypto_aead_chacha20poly1305_ietf_decrypt(m2, NULL, NULL, c, CLEN,
ad, ADLEN, nonce, firstkey)
== 0 || memcmp(m, m2, MLEN) == 0) {
printf("message can be forged\n");
}
c[i] ^= (i + 1U);
}
crypto_aead_chacha20poly1305_ietf_encrypt(c, &found_clen, m, MLEN,
NULL, 0U, NULL, nonce, firstkey);
if (found_clen != CLEN) {
printf("clen is not properly set (adlen=0)\n");
}
for (i = 0U; i < CLEN; ++i) {
printf(",0x%02x", (unsigned int) c[i]);
if (i % 8 == 7) {
printf("\n");
}
}
printf("\n");
if (crypto_aead_chacha20poly1305_ietf_decrypt(m2, &m2len, NULL, c, CLEN,
NULL, 0U, nonce, firstkey) != 0) {
printf("crypto_aead_chacha20poly1305_ietf_decrypt() failed (adlen=0)\n");
}
if (m2len != MLEN) {
printf("m2len is not properly set (adlen=0)\n");
}
if (memcmp(m, m2, MLEN) != 0) {
printf("m != m2 (adlen=0)\n");
}
m2len = 1;
if (crypto_aead_chacha20poly1305_ietf_decrypt(
m2, &m2len, NULL, NULL,
randombytes_uniform(crypto_aead_chacha20poly1305_ietf_ABYTES),
NULL, 0U, nonce, firstkey) != -1) {
printf("crypto_aead_chacha20poly1305_ietf_decrypt() worked with a short "
"ciphertext\n");
}
if (m2len != 0) {
printf("Message length should have been set to zero after a failure\n");
}
m2len = 1;
if (crypto_aead_chacha20poly1305_ietf_decrypt(m2, &m2len, NULL, c, 0U, NULL, 0U,
nonce, firstkey) != -1) {
printf("crypto_aead_chacha20poly1305_ietf_decrypt() worked with an empty "
"ciphertext\n");
}
if (m2len != 0) {
printf("Message length should have been set to zero after a failure\n");
}
memcpy(c, m, MLEN);
crypto_aead_chacha20poly1305_ietf_encrypt(c, &found_clen, c, MLEN,
NULL, 0U, NULL, nonce, firstkey);
if (found_clen != CLEN) {
printf("clen is not properly set (adlen=0)\n");
}
for (i = 0U; i < CLEN; ++i) {
printf(",0x%02x", (unsigned int) c[i]);
if (i % 8 == 7) {
printf("\n");
}
}
printf("\n");
if (crypto_aead_chacha20poly1305_ietf_decrypt(c, &m2len, NULL, c, CLEN,
NULL, 0U, nonce, firstkey) != 0) {
printf("crypto_aead_chacha20poly1305_ietf_decrypt() failed (adlen=0)\n");
}
if (m2len != MLEN) {
printf("m2len is not properly set (adlen=0)\n");
}
if (memcmp(m, c, MLEN) != 0) {
printf("m != c (adlen=0)\n");
}
sodium_free(c);
sodium_free(detached_c);
sodium_free(mac);
sodium_free(m2);
sodium_free(m);
assert(crypto_aead_chacha20poly1305_ietf_keybytes() > 0U);
assert(crypto_aead_chacha20poly1305_ietf_keybytes() == crypto_aead_chacha20poly1305_keybytes());
assert(crypto_aead_chacha20poly1305_ietf_npubbytes() > 0U);
assert(crypto_aead_chacha20poly1305_ietf_npubbytes() > crypto_aead_chacha20poly1305_npubbytes());
assert(crypto_aead_chacha20poly1305_ietf_nsecbytes() == 0U);
assert(crypto_aead_chacha20poly1305_ietf_nsecbytes() == crypto_aead_chacha20poly1305_nsecbytes());
assert(crypto_aead_chacha20poly1305_IETF_KEYBYTES == crypto_aead_chacha20poly1305_ietf_KEYBYTES);
assert(crypto_aead_chacha20poly1305_IETF_NSECBYTES == crypto_aead_chacha20poly1305_ietf_NSECBYTES);
assert(crypto_aead_chacha20poly1305_IETF_NPUBBYTES == crypto_aead_chacha20poly1305_ietf_NPUBBYTES);
assert(crypto_aead_chacha20poly1305_IETF_ABYTES == crypto_aead_chacha20poly1305_ietf_ABYTES);
return 0;
}
int
main(void)
{
tv();
tv_ietf();
return 0;
}
|
9e839a97f28d600ca5a61499c75257db62a0da5b
|
88ae8695987ada722184307301e221e1ba3cc2fa
|
/third_party/wayland/src/tests/queue-test.c
|
86a360256fcf07944e61c782889e980672337ed9
|
[
"Apache-2.0",
"LGPL-2.0-or-later",
"MIT",
"GPL-1.0-or-later",
"BSD-3-Clause"
] |
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
| 10,060
|
c
|
queue-test.c
|
/*
* Copyright © 2012 Jonas Ådahl
*
* 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 (including the
* next paragraph) 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 <stdlib.h>
#include <stdint.h>
#include <stdio.h>
#include <stdbool.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <assert.h>
#include "wayland-client.h"
#include "wayland-server.h"
#include "test-runner.h"
#include "test-compositor.h"
#define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0])
static void
registry_handle_global(void *data, struct wl_registry *registry,
uint32_t id, const char *interface, uint32_t version)
{
int *pcounter = data;
(*pcounter)++;
assert(*pcounter == 1);
wl_registry_destroy(registry);
}
static const struct wl_registry_listener registry_listener = {
registry_handle_global,
NULL
};
/* Test that destroying a proxy object doesn't result in any more
* callback being invoked, even though were many queued. */
static void
client_test_proxy_destroy(void)
{
struct wl_display *display;
struct wl_registry *registry;
int counter = 0;
display = wl_display_connect(NULL);
assert(display);
registry = wl_display_get_registry(display);
assert(registry != NULL);
wl_registry_add_listener(registry, ®istry_listener,
&counter);
assert(wl_display_roundtrip(display) != -1);
assert(counter == 1);
/* don't destroy the registry, we have already destroyed them
* in the global handler */
wl_display_disconnect(display);
}
struct multiple_queues_state {
struct wl_display *display;
struct wl_callback* callback2;
bool done;
};
static void
sync_callback(void *data, struct wl_callback *callback, uint32_t serial)
{
struct multiple_queues_state *state = data;
state->done = true;
wl_callback_destroy(callback);
wl_display_dispatch_pending(state->display);
wl_callback_destroy(state->callback2);
}
static const struct wl_callback_listener sync_listener = {
sync_callback
};
/* Test that when receiving the first of two synchronization
* callback events, destroying the second one doesn't cause any
* errors even if the delete_id event is handled out of order. */
static void
client_test_multiple_queues(void)
{
struct wl_event_queue *queue;
struct wl_callback *callback1;
struct multiple_queues_state state;
int ret = 0;
state.display = wl_display_connect(NULL);
assert(state.display);
queue = wl_display_create_queue(state.display);
assert(queue);
state.done = false;
callback1 = wl_display_sync(state.display);
assert(callback1 != NULL);
wl_callback_add_listener(callback1, &sync_listener, &state);
wl_proxy_set_queue((struct wl_proxy *) callback1, queue);
state.callback2 = wl_display_sync(state.display);
assert(state.callback2 != NULL);
wl_callback_add_listener(state.callback2, &sync_listener, NULL);
wl_proxy_set_queue((struct wl_proxy *) state.callback2, queue);
wl_display_flush(state.display);
while (!state.done && !ret)
ret = wl_display_dispatch_queue(state.display, queue);
wl_event_queue_destroy(queue);
wl_display_disconnect(state.display);
exit(ret == -1 ? -1 : 0);
}
static void
sync_callback_roundtrip(void *data, struct wl_callback *callback, uint32_t serial)
{
bool *done = data;
*done = true;
}
static const struct wl_callback_listener sync_listener_roundtrip = {
sync_callback_roundtrip
};
/* Test that doing a roundtrip on a queue only the events on that
* queue get dispatched. */
static void
client_test_queue_roundtrip(void)
{
struct wl_event_queue *queue;
struct wl_callback *callback1;
struct wl_callback *callback2;
struct wl_display *display;
bool done1 = false;
bool done2 = false;
display = wl_display_connect(NULL);
assert(display);
queue = wl_display_create_queue(display);
assert(queue);
/* arm a callback on the default queue */
callback1 = wl_display_sync(display);
assert(callback1 != NULL);
wl_callback_add_listener(callback1, &sync_listener_roundtrip, &done1);
/* arm a callback on the other queue */
callback2 = wl_display_sync(display);
assert(callback2 != NULL);
wl_callback_add_listener(callback2, &sync_listener_roundtrip, &done2);
wl_proxy_set_queue((struct wl_proxy *) callback2, queue);
/* roundtrip on default queue must not dispatch the other queue. */
wl_display_roundtrip(display);
assert(done1 == true);
assert(done2 == false);
/* re-arm the sync callback on the default queue, so we see that
* wl_display_roundtrip_queue() does not dispatch the default queue. */
wl_callback_destroy(callback1);
done1 = false;
callback1 = wl_display_sync(display);
assert(callback1 != NULL);
wl_callback_add_listener(callback1, &sync_listener_roundtrip, &done1);
wl_display_roundtrip_queue(display, queue);
assert(done1 == false);
assert(done2 == true);
wl_callback_destroy(callback1);
wl_callback_destroy(callback2);
wl_event_queue_destroy(queue);
wl_display_disconnect(display);
}
static void
client_test_queue_proxy_wrapper(void)
{
struct wl_event_queue *queue;
struct wl_display *display;
struct wl_display *display_wrapper;
struct wl_callback *callback;
bool done = false;
/*
* For an illustration of what usage would normally fail without using
* proxy wrappers, see the `client_test_queue_set_queue_race' test case.
*/
display = wl_display_connect(NULL);
assert(display);
/* Pretend we are in a separate thread where a thread-local queue is
* used. */
queue = wl_display_create_queue(display);
assert(queue);
display_wrapper = wl_proxy_create_wrapper(display);
assert(display_wrapper);
wl_proxy_set_queue((struct wl_proxy *) display_wrapper, queue);
callback = wl_display_sync(display_wrapper);
wl_proxy_wrapper_destroy(display_wrapper);
assert(callback != NULL);
/* Pretend we are now another thread and dispatch the dispatch the main
* queue while also knowing our callback is read and queued. */
wl_display_roundtrip(display);
/* Make sure that the pretend-to-be main thread didn't dispatch our
* callback, behind our back. */
wl_callback_add_listener(callback, &sync_listener_roundtrip, &done);
wl_display_flush(display);
assert(!done);
/* Make sure that we eventually end up dispatching our callback. */
while (!done)
assert(wl_display_dispatch_queue(display, queue) != -1);
wl_callback_destroy(callback);
wl_event_queue_destroy(queue);
wl_display_disconnect(display);
}
static void
client_test_queue_set_queue_race(void)
{
struct wl_event_queue *queue;
struct wl_display *display;
struct wl_callback *callback;
bool done = false;
/*
* This test illustrates the multi threading scenario which would fail
* without doing what is done in the `client_test_queue_proxy_wrapper'
* test.
*/
display = wl_display_connect(NULL);
assert(display);
/* Pretend we are in a separate thread where a thread-local queue is
* used. */
queue = wl_display_create_queue(display);
assert(queue);
callback = wl_display_sync(display);
assert(callback != NULL);
/* Pretend we are now another thread and dispatch the dispatch the main
* queue while also knowing our callback is read, queued on the wrong
* queue, and dispatched. */
wl_display_roundtrip(display);
/* Pretend we are back in the separate thread, and continue with setting
* up our callback. */
wl_callback_add_listener(callback, &sync_listener_roundtrip, &done);
wl_proxy_set_queue((struct wl_proxy *) callback, queue);
/* Roundtrip our separate thread queue to make sure any events are
* dispatched. */
wl_display_roundtrip_queue(display, queue);
/* Verify that the callback has indeed been dropped. */
assert(!done);
wl_callback_destroy(callback);
wl_event_queue_destroy(queue);
wl_display_disconnect(display);
}
static void
dummy_bind(struct wl_client *client,
void *data, uint32_t version, uint32_t id)
{
}
TEST(queue_proxy_destroy)
{
struct display *d;
const struct wl_interface *dummy_interfaces[] = {
&wl_seat_interface,
&wl_pointer_interface,
&wl_keyboard_interface,
&wl_surface_interface
};
unsigned int i;
d = display_create();
for (i = 0; i < ARRAY_LENGTH(dummy_interfaces); i++)
wl_global_create(d->wl_display, dummy_interfaces[i],
dummy_interfaces[i]->version,
NULL, dummy_bind);
test_set_timeout(2);
client_create_noarg(d, client_test_proxy_destroy);
display_run(d);
display_destroy(d);
}
TEST(queue_multiple_queues)
{
struct display *d = display_create();
test_set_timeout(2);
client_create_noarg(d, client_test_multiple_queues);
display_run(d);
display_destroy(d);
}
TEST(queue_roundtrip)
{
struct display *d = display_create();
test_set_timeout(2);
client_create_noarg(d, client_test_queue_roundtrip);
display_run(d);
display_destroy(d);
}
TEST(queue_set_queue_proxy_wrapper)
{
struct display *d = display_create();
test_set_timeout(2);
client_create_noarg(d, client_test_queue_proxy_wrapper);
display_run(d);
display_destroy(d);
}
TEST(queue_set_queue_race)
{
struct display *d = display_create();
test_set_timeout(2);
client_create_noarg(d, client_test_queue_set_queue_race);
display_run(d);
display_destroy(d);
}
|
32aaaf5e413da5c4f79ae611e94166c22b331d96
|
810237086aae7600b9ef87a610aec4777b1bf156
|
/Example/Pods/Headers/Private/SJBaseVideoPlayer/CALayer+SJBaseVideoPlayerExtended.h
|
b54ffe7e9374684d53eed906fd98a4f2c0baea22
|
[
"MIT"
] |
permissive
|
changsanjiang/SJVideoPlayer
|
f63f3156d5ad07ec107b0feb481110222dd45a85
|
bff75e1f7f033edc05e07c333ce3557cb289c95c
|
refs/heads/master
| 2022-12-20T22:47:04.095976
| 2022-12-10T08:57:46
| 2022-12-10T08:57:46
| 100,693,284
| 2,680
| 513
|
MIT
| 2022-11-02T11:04:42
| 2017-08-18T08:56:30
|
Objective-C
|
UTF-8
|
C
| false
| false
| 93
|
h
|
CALayer+SJBaseVideoPlayerExtended.h
|
../../../SJBaseVideoPlayer/SJBaseVideoPlayer/Common/UIKit/CALayer+SJBaseVideoPlayerExtended.h
|
75a22d67556bffa8f5f88f5316b138505f35254b
|
a3d6556180e74af7b555f8d47d3fea55b94bcbda
|
/third_party/brotli/enc/compress_fragment.h
|
099a97913b2c2094102fb333ecc8c7e287678198
|
[
"MIT",
"LicenseRef-scancode-unknown-license-reference",
"BSD-3-Clause",
"GPL-1.0-or-later",
"LGPL-2.0-or-later",
"Apache-2.0"
] |
permissive
|
chromium/chromium
|
aaa9eda10115b50b0616d2f1aed5ef35d1d779d6
|
a401d6cf4f7bf0e2d2e964c512ebb923c3d8832c
|
refs/heads/main
| 2023-08-24T00:35:12.585945
| 2023-08-23T22:01:11
| 2023-08-23T22:01:11
| 120,360,765
| 17,408
| 7,102
|
BSD-3-Clause
| 2023-09-10T23:44:27
| 2018-02-05T20:55:32
| null |
UTF-8
|
C
| false
| false
| 3,597
|
h
|
compress_fragment.h
|
/* Copyright 2015 Google Inc. All Rights Reserved.
Distributed under MIT license.
See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
*/
/* Function for fast encoding of an input fragment, independently from the input
history. This function uses one-pass processing: when we find a backward
match, we immediately emit the corresponding command and literal codes to
the bit stream. */
#ifndef BROTLI_ENC_COMPRESS_FRAGMENT_H_
#define BROTLI_ENC_COMPRESS_FRAGMENT_H_
#include "../common/constants.h"
#include "../common/platform.h"
#include <brotli/types.h>
#include "entropy_encode.h"
#if defined(__cplusplus) || defined(c_plusplus)
extern "C" {
#endif
typedef struct BrotliOnePassArena {
uint8_t lit_depth[256];
uint16_t lit_bits[256];
/* Command and distance prefix codes (each 64 symbols, stored back-to-back)
used for the next block. The command prefix code is over a smaller alphabet
with the following 64 symbols:
0 - 15: insert length code 0, copy length code 0 - 15, same distance
16 - 39: insert length code 0, copy length code 0 - 23
40 - 63: insert length code 0 - 23, copy length code 0
Note that symbols 16 and 40 represent the same code in the full alphabet,
but we do not use either of them. */
uint8_t cmd_depth[128];
uint16_t cmd_bits[128];
uint32_t cmd_histo[128];
/* The compressed form of the command and distance prefix codes for the next
block. */
uint8_t cmd_code[512];
size_t cmd_code_numbits;
HuffmanTree tree[2 * BROTLI_NUM_LITERAL_SYMBOLS + 1];
uint32_t histogram[256];
uint8_t tmp_depth[BROTLI_NUM_COMMAND_SYMBOLS];
uint16_t tmp_bits[64];
} BrotliOnePassArena;
/* Compresses "input" string to the "*storage" buffer as one or more complete
meta-blocks, and updates the "*storage_ix" bit position.
If "is_last" is 1, emits an additional empty last meta-block.
"cmd_depth" and "cmd_bits" contain the command and distance prefix codes
(see comment in encode.h) used for the encoding of this input fragment.
If "is_last" is 0, they are updated to reflect the statistics
of this input fragment, to be used for the encoding of the next fragment.
"*cmd_code_numbits" is the number of bits of the compressed representation
of the command and distance prefix codes, and "cmd_code" is an array of
at least "(*cmd_code_numbits + 7) >> 3" size that contains the compressed
command and distance prefix codes. If "is_last" is 0, these are also
updated to represent the updated "cmd_depth" and "cmd_bits".
REQUIRES: "input_size" is greater than zero, or "is_last" is 1.
REQUIRES: "input_size" is less or equal to maximal metablock size (1 << 24).
REQUIRES: All elements in "table[0..table_size-1]" are initialized to zero.
REQUIRES: "table_size" is an odd (9, 11, 13, 15) power of two
OUTPUT: maximal copy distance <= |input_size|
OUTPUT: maximal copy distance <= BROTLI_MAX_BACKWARD_LIMIT(18) */
BROTLI_INTERNAL void BrotliCompressFragmentFast(BrotliOnePassArena* s,
const uint8_t* input,
size_t input_size,
BROTLI_BOOL is_last,
int* table, size_t table_size,
size_t* storage_ix,
uint8_t* storage);
#if defined(__cplusplus) || defined(c_plusplus)
} /* extern "C" */
#endif
#endif /* BROTLI_ENC_COMPRESS_FRAGMENT_H_ */
|
2d1c02bb2d0c005c8a65f4ec6edc49fa2af831f9
|
b6fd3ebe265cc089f76391068f07d2e7ea361e76
|
/core/fmt/savescr.c
|
373fea492b3b25c7ae3bd29ed495db62b81fa755
|
[
"MIT"
] |
permissive
|
foone/BRender-v1.3.2
|
55bbdba6470234e158f82247bb5e03c2c27b9e3e
|
d88d0ed41122664b9781015b517db64353e16f19
|
refs/heads/main
| 2022-05-05T22:39:56.191332
| 2022-05-05T22:33:54
| 2022-05-05T22:33:54
| 488,348,032
| 486
| 35
|
MIT
| 2022-05-03T23:06:16
| 2022-05-03T20:06:34
|
C
|
UTF-8
|
C
| false
| false
| 7,293
|
c
|
savescr.c
|
/*
* Copyright (c) 1993-1995 by Argonaut Technologies Limited. All rights reserved.
*
* $Id: savescr.c 1.2 1998/03/05 20:24:07 jon Exp $
* $Locker: $
*
* Save a Material Script file
*/
#include "brender.h"
#include "fmt.h"
BR_RCS_ID("$Id: savescr.c 1.2 1998/03/05 20:24:07 jon Exp $")
/*
* The default material used to load a script
*/
extern br_material _DefaultScriptMaterial;
STATIC struct {
char *name;
int value;
} MaterialFlagNames[] = {
{ "light" , BR_MATF_LIGHT },
{ "prelit" , BR_MATF_PRELIT },
{ "smooth" , BR_MATF_SMOOTH },
{ "environment" , BR_MATF_ENVIRONMENT_I },
{ "environment_local" , BR_MATF_ENVIRONMENT_L },
{ "perspective" , BR_MATF_PERSPECTIVE },
{ "decal" , BR_MATF_DECAL },
{ "always_visible" , BR_MATF_ALWAYS_VISIBLE },
{ "two_sided" , BR_MATF_TWO_SIDED },
{ "force_front" , BR_MATF_FORCE_FRONT },
{ "force_back" , BR_MATF_FORCE_BACK },
{ "dither" , BR_MATF_DITHER },
{ "map_antialiasing" , BR_MATF_MAP_ANTIALIASING },
{ "map_interpolation" , BR_MATF_MAP_INTERPOLATION },
{ "mip_interpolation" , BR_MATF_MIP_INTERPOLATION },
{ "subdivide" , BR_MATF_SUBDIVIDE },
{ "fog_local" , BR_MATF_FOG_LOCAL },
{ "quad_mapping" , BR_MATF_QUAD_MAPPING },
{ "inhibit_depth_write" , BR_MATF_INHIBIT_DEPTH_WRITE},
};
STATIC struct {
char *name;
int value;
} DepthTestNames[] = {
{ "gt" , BR_MATM_DEPTH_TEST_GT },
{ "ge" , BR_MATM_DEPTH_TEST_GE },
{ "eq" , BR_MATM_DEPTH_TEST_EQ },
{ "ne" , BR_MATM_DEPTH_TEST_NE },
{ "le" , BR_MATM_DEPTH_TEST_LE },
{ "lt" , BR_MATM_DEPTH_TEST_LT },
{ "nv" , BR_MATM_DEPTH_TEST_NV },
{ "al" , BR_MATM_DEPTH_TEST_AL },
};
STATIC struct {
char *name;
int value;
} BlendModeNames[] = {
{ "standard" , BR_MATM_BLEND_MODE_STANDARD },
{ "summed" , BR_MATM_BLEND_MODE_SUMMED },
{ "dimmed" , BR_MATM_BLEND_MODE_DIMMED },
{ "premultiplied" , BR_MATM_BLEND_MODE_PREMULTIPLIED },
};
STATIC struct {
char *name;
int value;
} WidthLimitNames[] = {
{ "wrap" , BR_MATM_MAP_WIDTH_LIMIT_WRAP },
{ "clamp" , BR_MATM_MAP_WIDTH_LIMIT_CLAMP },
{ "mirror" , BR_MATM_MAP_WIDTH_LIMIT_MIRROR },
};
STATIC struct {
char *name;
int value;
} HeightLimitNames[] = {
{ "wrap" , BR_MATM_MAP_HEIGHT_LIMIT_WRAP },
{ "clamp" , BR_MATM_MAP_HEIGHT_LIMIT_CLAMP },
{ "mirror" , BR_MATM_MAP_HEIGHT_LIMIT_MIRROR },
};
STATIC void WriteScriptMaterial(br_material *mat, void *df)
{
int i,j;
BrFilePrintf(df,"\nmaterial = [\n");
if(mat->identifier)
BrFilePrintf(df," identifier = \"%s\";\n",mat->identifier);
/*
* Flags
*/
if(mat->flags != _DefaultScriptMaterial.flags) {
BrFilePrintf(df," flags = [");
for(i=0,j=0; i < BR_ASIZE(MaterialFlagNames); i++)
if(mat->flags & MaterialFlagNames[i].value) {
BrFilePrintf(df,"%s%s",j?", ":"",MaterialFlagNames[i].name);
j++;
}
BrFilePrintf(df,"];\n");
}
/*
* Lighting parameters
*/
if(mat->colour != _DefaultScriptMaterial.colour)
BrFilePrintf(df," colour = [%d,%d,%d];\n",
BR_RED(mat->colour),
BR_GRN(mat->colour),
BR_BLU(mat->colour));
if(mat->opacity != _DefaultScriptMaterial.opacity)
BrFilePrintf(df," opacity = %d;\n",mat->opacity);
if(mat->ka != _DefaultScriptMaterial.ka)
BrFilePrintf(df," ambient = %f;\n",BrScalarToFloat(BrUFractionToScalar(mat->ka)));
if(mat->kd != _DefaultScriptMaterial.kd)
BrFilePrintf(df," diffuse = %f;\n",BrScalarToFloat(BrUFractionToScalar(mat->kd)));
if(mat->ks != _DefaultScriptMaterial.ks)
BrFilePrintf(df," specular = %f;\n",BrScalarToFloat(BrUFractionToScalar(mat->ks)));
if(mat->power != _DefaultScriptMaterial.power)
BrFilePrintf(df," power = %f;\n",BrScalarToFloat(mat->power));
if(mat->index_base != _DefaultScriptMaterial.index_base)
BrFilePrintf(df," index_base = %d;\n",mat->index_base);
if(mat->index_range != _DefaultScriptMaterial.index_range)
BrFilePrintf(df," index_range = %d;\n",mat->index_range);
/*
* Map Transform
*/
for(i=0; i < 3; i++)
if(mat->map_transform.m[i][0] != _DefaultScriptMaterial.map_transform.m[i][0] ||
mat->map_transform.m[i][1] != _DefaultScriptMaterial.map_transform.m[i][1])
break;
if( i < 3) {
/*
* Matrices were different
*/
BrFilePrintf(df," map_transform = [\n");
for(i=0; i < 3; i ++)
BrFilePrintf(df,
" [%f,%f]%s\n",
BrScalarToFloat(mat->map_transform.m[i][0]),
BrScalarToFloat(mat->map_transform.m[i][1]),
i != 2?",":"");
BrFilePrintf(df," ];\n");
}
if((mat->mode & BR_MATM_DEPTH_TEST_MASK) != (_DefaultScriptMaterial.mode & BR_MATM_DEPTH_TEST_MASK))
for (i = 0; i < BR_ASIZE(DepthTestNames); i++)
if ((mat->mode & BR_MATM_DEPTH_TEST_MASK) == DepthTestNames[i].value) {
BrFilePrintf(df," depth_test = %s;\n",DepthTestNames[i].name);
break;
}
if((mat->mode & BR_MATM_BLEND_MODE_MASK) != (_DefaultScriptMaterial.mode & BR_MATM_BLEND_MODE_MASK))
for (i = 0; i < BR_ASIZE(BlendModeNames); i++)
if ((mat->mode & BR_MATM_BLEND_MODE_MASK) == BlendModeNames[i].value) {
BrFilePrintf(df," blend_mode = %s;\n",BlendModeNames[i].name);
break;
}
if((mat->mode & BR_MATM_MAP_WIDTH_LIMIT_MASK) != (_DefaultScriptMaterial.mode & BR_MATM_MAP_WIDTH_LIMIT_MASK))
for (i = 0; i < BR_ASIZE(WidthLimitNames); i++)
if ((mat->mode & BR_MATM_MAP_WIDTH_LIMIT_MASK) == WidthLimitNames[i].value) {
BrFilePrintf(df," map_width_limit = %s;\n",WidthLimitNames[i].name);
break;
}
if((mat->mode & BR_MATM_MAP_HEIGHT_LIMIT_MASK) != (_DefaultScriptMaterial.mode & BR_MATM_MAP_HEIGHT_LIMIT_MASK))
for (i = 0; i < BR_ASIZE(HeightLimitNames); i++)
if ((mat->mode & BR_MATM_MAP_HEIGHT_LIMIT_MASK) == HeightLimitNames[i].value) {
BrFilePrintf(df," map_height_limit = %s;\n",HeightLimitNames[i].name);
break;
}
/*
* Maps and Tables
*/
if(mat->colour_map && mat->colour_map->identifier)
BrFilePrintf(df," colour_map = \"%s\";\n",mat->colour_map->identifier);
if(mat->screendoor && mat->screendoor->identifier)
BrFilePrintf(df," screendoor = \"%s\";\n",mat->screendoor->identifier);
if(mat->index_shade && mat->index_shade->identifier)
BrFilePrintf(df," index_shade = \"%s\";\n",mat->index_shade->identifier);
if(mat->index_blend && mat->index_blend->identifier)
BrFilePrintf(df," index_blend = \"%s\";\n",mat->index_blend->identifier);
BrFilePrintf(df,"];\n");
}
/*
* Write out a material script
*/
br_uint_32 BR_PUBLIC_ENTRY BrFmtScriptMaterialSaveMany(char *filename,br_material **materials,br_uint_16 num)
{
void *df;
int i,count;
/*
* Open file and write header
*/
df = BrFileOpenWrite(filename,1);
if(df == NULL)
return 0;
/*
* Write a header
*/
BrFilePutLine("# BRender Material Script",df);
BrFilePutLine("#",df);
if(materials) {
for(i=0; i<num; i++)
WriteScriptMaterial(materials[i],df);
count = num;
} else {
BrMaterialEnum(NULL,(br_material_enum_cbfn *)WriteScriptMaterial,df);
count = BrMaterialCount(NULL);
}
BrFileClose(df);
return count;
}
br_uint_32 BR_PUBLIC_ENTRY BrFmtScriptMaterialSave(char *filename, br_material *ptr)
{
return BrFmtScriptMaterialSaveMany(filename,&ptr,1);
}
|
ef614ea2cba9a67015ecf85f6d7ab4b0f16dcb5c
|
2c401decaf99fae89bb5a24018c14591578998c6
|
/app/src/main/jni/auxiliary/spectre-gen.c
|
b2fa1c5f0853cad9fb4cb2ee5d2479348c511203
|
[
"MIT"
] |
permissive
|
chrisboyle/sgtpuzzles
|
71270d9e8d29e60223eae049b45466abaf329969
|
6d550adc204c2b56e640f471603199875b1a96cd
|
refs/heads/main
| 2023-08-31T15:07:52.664146
| 2023-08-30T20:47:27
| 2023-08-30T20:47:27
| 356,848
| 469
| 165
|
NOASSERTION
| 2023-06-04T05:29:42
| 2009-11-01T10:04:16
|
C
|
UTF-8
|
C
| false
| false
| 22,870
|
c
|
spectre-gen.c
|
/*
* Generate the lookup tables used by the Spectre tiling.
*/
#include <assert.h>
#include <errno.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include "puzzles.h"
#include "tree234.h"
#include "spectre-internal.h"
#include "spectre-tables-manual.h"
#include "spectre-tables-extra.h"
#include "spectre-help.h"
struct HexData {
const Hex *subhexes;
const unsigned *orientations;
const int *edges;
Point hex_outline_start, hex_outline_direction;
unsigned spectre_outline_start_spec, spectre_outline_start_vertex;
};
static const struct HexData hexdata[] = {
#define HEXDATA_ENTRY(x) { subhexes_##x, orientations_##x, edges_##x, \
HEX_OUTLINE_START_##x, SPEC_OUTLINE_START_##x },
HEX_LETTERS(HEXDATA_ENTRY)
#undef HEXDATA_ENTRY
};
/*
* Store information about an edge of the hexagonal tiling.
*/
typedef struct EdgeData {
/* Edges are regarded as directed, so that we can store
* information separately about what's on each side of one. The
* names 'start' and 'finish' indicate a direction of travel,
* which is taken to be anticlockwise around a hexagon, i.e. if
* you walk from 'start' to 'finish' then the hexagon in question
* is the one on your left. */
Point start, finish;
/* Whether this edge is internal (i.e. owned by a hexagon). */
bool internal;
/*
* High- and low-order parts of the edge identity.
*
* If the edge is internal, then 'hi' indexes the hexagon it's an
* edge of, and 'lo' identifies one of its edges.
*
* If it's external, then 'hi' is the index of the edge segment
* corresponding to a particular edge of the superhex, and 'lo'
* the sub-index within that segment.
*/
unsigned hi, lo;
} EdgeData;
static int edge_cmp(void *av, void *bv)
{
const EdgeData *a = (const EdgeData *)av;
const EdgeData *b = (const EdgeData *)bv;
size_t i;
for (i = 0; i < 4; i++) {
if (a->start.coeffs[i] < b->start.coeffs[i])
return -1;
if (a->start.coeffs[i] > b->start.coeffs[i])
return +1;
}
for (i = 0; i < 4; i++) {
if (a->finish.coeffs[i] < b->finish.coeffs[i])
return -1;
if (a->finish.coeffs[i] > b->finish.coeffs[i])
return +1;
}
return 0;
}
static void lay_out_hexagons(Hex h, Graphics *gr, FILE *hdr)
{
size_t i, j;
tree234 *edge_map = newtree234(edge_cmp);
EdgeData *edge;
EdgeData *intmap[48], *extmap[22];
unsigned edgestarts[7];
const struct HexData *hd = h == NO_HEX ? NULL : &hexdata[h];
/*
* Iterate over all hexagons and enter their edges into the edge
* map.
*/
for (i = 0; i < (h == NO_HEX ? 8 : num_subhexes(h)); i++) {
Point centre = hex_centres[i];
Point vrel = {{ -2, 0, 4, 0 }};
Point vertices[6];
if (hd)
vrel = point_mul(vrel, point_rot(2*hd->orientations[i]));
for (j = 0; j < 6; j++) {
Point vrelnext = point_mul(vrel, point_rot(2));
edge = snew(EdgeData);
edge->start = point_add(centre, vrel);
edge->finish = point_add(centre, vrelnext);
edge->internal = true;
edge->hi = i;
edge->lo = j;
add234(edge_map, edge);
intmap[6*i + j] = edge;
vertices[j] = edge->start;
vrel = vrelnext;
}
gr_draw_hex(gr, gr->jigsaw_mode ? -1 : i,
hd ? hd->subhexes[i] : NO_HEX, vertices);
}
/*
* Trace round the exterior outline of the hex expansion,
* following the list of edge types.
*/
if (hd) {
Point pos, dir;
size_t mappos = 0;
pos = hd->hex_outline_start;
dir = hd->hex_outline_direction;
for (i = 0; i < 6; i++) {
int edge_type = hd->edges[i];
int sign = edge_type < 0 ? -1 : +1;
const int *edge_shape = hex_edge_shapes[abs(edge_type)];
size_t len = hex_edge_lengths[abs(edge_type)];
size_t index = sign < 0 ? len-2 : 0;
if (gr->vertex_blobs)
gr_draw_blob(gr, (i == 0 ? "startpoint" : "edgesep"),
gr_logcoords(pos), (i == 0 ? 0.6 : 0.3));
edgestarts[i] = mappos;
for (j = 0; j < len; j++) {
Point posnext = point_add(pos, dir);
if (j < len-1) {
dir = point_mul(dir, point_rot(sign * edge_shape[index]));
index += sign;
}
edge = snew(EdgeData);
edge->start = pos;
edge->finish = posnext;
edge->internal = false;
edge->hi = i;
edge->lo = j;
add234(edge_map, edge);
assert(mappos < lenof(extmap));
extmap[mappos++] = edge;
pos = posnext;
}
/*
* In the hex expansion, every pair of edges meet at a
* 60-degree left turn.
*/
dir = point_mul(dir, point_rot(-2));
}
edgestarts[i] = mappos; /* record end position */
for (i = 0; i < 4; i++)
assert(pos.coeffs[i] == hd->hex_outline_start.coeffs[i]);
}
/*
* Draw the labels on the edges.
*/
if (gr->number_edges) {
for (i = 0; (edge = index234(edge_map, i)) != NULL; i++) {
char buf[64];
double textheight = 0.8, offset = textheight * 0.2;
GrCoords start = gr_logcoords(edge->start);
GrCoords finish = gr_logcoords(edge->finish);
GrCoords len = { finish.x - start.x, finish.y - start.y };
GrCoords perp = { -len.y, +len.x };
GrCoords mid = { (start.x+finish.x)/2, (start.y+finish.y)/2 };
if (edge->internal) {
sprintf(buf, "%u", edge->lo);
} else {
sprintf(buf, "%u.%u", edge->lo, edge->hi);
offset = textheight * 0.3;
}
{
GrCoords pos = {
mid.x + offset * perp.x,
mid.y + offset * perp.y,
};
gr_draw_text(gr, pos, textheight, buf);
}
}
}
/*
* Write out C array declarations for the machine-readable version
* of the maps we just generated.
*/
if (hdr) {
fprintf(hdr, "static const struct MapEntry hexmap_%s[] = {\n",
hex_names[h]);
for (i = 0; i < 6 * num_subhexes(h); i++) {
EdgeData *our_edge = intmap[i];
EdgeData key, *rev_edge;
key.finish = our_edge->start;
key.start = our_edge->finish;
rev_edge = find234(edge_map, &key, NULL);
assert(rev_edge);
fprintf(hdr, " { %-6s %u, %u }, /* edge %u of hex %u (%s) */\n",
rev_edge->internal ? "true," : "false,",
rev_edge->hi, rev_edge->lo,
our_edge->lo, our_edge->hi,
hex_names[hd->subhexes[our_edge->hi]]);
}
fprintf(hdr, "};\n");
fprintf(hdr, "static const struct MapEdge hexedges_%s[] = {\n",
hex_names[h]);
for (i = 0; i < 6; i++)
fprintf(hdr, " { %2u, %u },\n", edgestarts[i],
edgestarts[i+1] - edgestarts[i]);
fprintf(hdr, "};\n");
fprintf(hdr, "static const struct MapEntry hexin_%s[] = {\n",
hex_names[h]);
for (i = 0; i < edgestarts[6]; i++) {
EdgeData *our_edge = extmap[i];
EdgeData key, *rev_edge;
key.finish = our_edge->start;
key.start = our_edge->finish;
rev_edge = find234(edge_map, &key, NULL);
assert(rev_edge);
fprintf(hdr, " { %-6s %u, %u }, /* subedge %u of edge %u */\n",
rev_edge->internal ? "true," : "false,",
rev_edge->hi, rev_edge->lo,
our_edge->lo, our_edge->hi);
}
fprintf(hdr, "};\n");
}
while ((edge = delpos234(edge_map, 0)) != NULL)
sfree(edge);
freetree234(edge_map);
}
static void lay_out_spectres(Hex h, Graphics *gr, FILE *hdr)
{
size_t i, j;
tree234 *edge_map = newtree234(edge_cmp);
EdgeData *edge;
EdgeData *intmap[28], *extmap[24];
Point vertices[28];
unsigned edgestarts[7];
const struct HexData *hd = (h == NO_HEX ? NULL : &hexdata[h]);
/*
* Iterate over the Spectres in a hex (usually only one), and enter
* their edges into the edge map.
*/
for (i = 0; i < (h == NO_HEX ? 2 : num_spectres(h)); i++) {
Point start = {{ 0, 0, 0, 0 }};
Point pos = start;
Point diag = {{ 2, 0, 0, 2 }};
Point dir = point_mul(diag, point_rot(5));
/*
* Usually the single Spectre in each map is oriented in the
* same place. For spectre #1 in the G map, however, we orient
* it manually in a different location. (There's no point
* making an organised lookup table for just this one
* exceptional case.)
*/
if (i == 1) {
Point unusual_start = {{ 2, 6, 2, 0 }};
pos = unusual_start;
dir = point_mul(dir, point_rot(+1));
}
for (j = 0; j < 14; j++) {
edge = snew(EdgeData);
edge->start = pos;
edge->finish = point_add(pos, dir);
edge->internal = true;
edge->hi = i;
edge->lo = j;
add234(edge_map, edge);
intmap[14*i + j] = edge;
vertices[14*i + j] = edge->start;
pos = edge->finish;
dir = point_mul(dir, point_rot(spectre_angles[(j+1) % 14]));
}
gr_draw_spectre(gr, h, i, vertices + 14*i);
}
/*
* Trace round the exterior outline of the hex expansion,
* following the list of edge types. Due to the confusing
* reflection of all the expansions, we end up doing this in the
* reverse order to the hexes code above.
*/
if (hd) {
Point start, pos, dir;
size_t mappos = lenof(extmap);
start = pos = vertices[14 * hd->spectre_outline_start_spec +
hd->spectre_outline_start_vertex];
edgestarts[6] = mappos;
for (i = 0; i < 6; i++) {
int edge_type = hd->edges[5-i];
int sign = edge_type < 0 ? -1 : +1;
const int *edge_shape = spec_edge_shapes[abs(edge_type)];
size_t len = spec_edge_lengths[abs(edge_type)];
size_t index = sign < 0 ? len-2 : 0;
if (gr->vertex_blobs)
gr_draw_blob(gr, (i == 0 ? "startpoint" : "edgesep"),
gr_logcoords(pos), (i == 0 ? 0.6 : 0.3));
if (h == HEX_S && i >= 4) {
/*
* Two special cases
*/
if (i == 4)
/* leave dir from last time */;
else
dir = point_mul(dir, point_rot(6)); /* reverse */
} else {
/*
* Determine the direction of the first sub-edge of
* this edge expansion, by iterating over all the
* edges in edge_map starting at this point and
* finding one whose reverse isn't in the map (hence,
* it's an exterior edge).
*/
EdgeData dummy, *iter, *found = NULL;
dummy.start = pos;
for (j = 0; j < 4; j++)
dummy.finish.coeffs[j] = INT_MIN;
for (iter = findrel234(edge_map, &dummy, NULL, REL234_GE);
iter != NULL && point_equal(iter->start, pos);
iter = findrel234(edge_map, iter, NULL, REL234_GT)) {
EdgeData *rev;
dummy.finish = iter->start;
dummy.start = iter->finish;
rev = find234(edge_map, &dummy, NULL);
if (!rev) {
found = iter;
break;
}
}
assert(found);
dir = point_sub(found->finish, found->start);
}
for (j = 0; j < len; j++) {
Point posnext = point_add(pos, dir);
if (j < len-1) {
dir = point_mul(dir, point_rot(sign * edge_shape[index]));
index += sign;
}
edge = snew(EdgeData);
edge->start = posnext;
edge->finish = pos;
edge->internal = false;
edge->hi = 5-i;
edge->lo = len-1-j;
add234(edge_map, edge);
assert(mappos > 0);
extmap[--mappos] = edge;
pos = posnext;
}
edgestarts[5-i] = mappos;
}
assert(point_equal(pos, start));
}
/*
* Draw the labels on the edges.
*/
if (gr->number_edges) {
for (i = 0; (edge = index234(edge_map, i)) != NULL; i++) {
char buf[64];
double textheight = 0.8, offset = textheight * 0.2;
GrCoords start = gr_logcoords(edge->start);
GrCoords finish = gr_logcoords(edge->finish);
GrCoords len = { finish.x - start.x, finish.y - start.y };
GrCoords perp = { +len.y, -len.x };
GrCoords mid = { (start.x+finish.x)/2, (start.y+finish.y)/2 };
if (edge->internal) {
sprintf(buf, "%u", edge->lo);
} else {
sprintf(buf, "%u.%u", edge->lo, edge->hi);
textheight = 0.6;
}
if (strlen(buf) > 1)
offset = textheight * 0.35;
{
GrCoords pos = {
mid.x + offset * perp.x,
mid.y + offset * perp.y,
};
gr_draw_text(gr, pos, textheight, buf);
}
}
}
/*
* Write out C array declarations for the machine-readable version
* of the maps we just generated.
*
* Also, because it's easier than having a whole extra iteration,
* draw lines for the extraordinary edges outside the S diagram.
*/
if (hdr) {
fprintf(hdr, "static const struct MapEntry specmap_%s[] = {\n",
hex_names[h]);
for (i = 0; i < 14 * num_spectres(h); i++) {
EdgeData *our_edge = intmap[i];
EdgeData key, *rev_edge;
key.finish = our_edge->start;
key.start = our_edge->finish;
rev_edge = find234(edge_map, &key, NULL);
assert(rev_edge);
fprintf(hdr, " { %-6s %u, %2u }, /* edge %2u of Spectre %u */\n",
rev_edge->internal ? "true," : "false,",
rev_edge->hi, rev_edge->lo,
our_edge->lo, our_edge->hi);
}
fprintf(hdr, "};\n");
fprintf(hdr, "static const struct MapEdge specedges_%s[] = {\n",
hex_names[h]);
for (i = 0; i < 6; i++)
fprintf(hdr, " { %2u, %u },\n", edgestarts[i] - edgestarts[0],
edgestarts[i+1] - edgestarts[i]);
fprintf(hdr, "};\n");
fprintf(hdr, "static const struct MapEntry specin_%s[] = {\n",
hex_names[h]);
for (i = edgestarts[0]; i < edgestarts[6]; i++) {
EdgeData *our_edge = extmap[i];
EdgeData key, *rev_edge;
key.finish = our_edge->start;
key.start = our_edge->finish;
rev_edge = find234(edge_map, &key, NULL);
assert(rev_edge);
fprintf(hdr, " { %-6s %u, %2u }, /* subedge %u of edge %u */\n",
rev_edge->internal ? "true," : "false,",
rev_edge->hi, rev_edge->lo,
our_edge->lo, our_edge->hi);
if (!our_edge->internal && !rev_edge->internal)
gr_draw_extra_edge(gr, key.start, key.finish);
}
fprintf(hdr, "};\n");
}
while ((edge = delpos234(edge_map, 0)) != NULL)
sfree(edge);
freetree234(edge_map);
}
static void draw_base_hex(Hex h, Graphics *gr)
{
size_t i;
Point vertices[6];
/*
* Plot the points of the hex.
*/
for (i = 0; i < 6; i++) {
Point startvertex = {{ -2, 0, 4, 0 }};
vertices[i] = point_mul(startvertex, point_rot(2*i));
}
/*
* Draw the hex itself.
*/
gr_draw_hex(gr, -1, h, vertices);
if (gr->vertex_blobs) {
/*
* Draw edge-division blobs on all vertices, to match the ones on
* the expansion diagrams.
*/
for (i = 0; i < 6; i++) {
gr_draw_blob(gr, (i == 0 ? "startpoint" : "edgesep"),
gr_logcoords(vertices[i]), (i == 0 ? 0.6 : 0.3));
}
}
if (gr->number_edges) {
/*
* Draw the labels on its edges.
*/
for (i = 0; i < 6; i++) {
char buf[64];
double textheight = 0.8, offset = textheight * 0.2;
GrCoords start = gr_logcoords(vertices[i]);
GrCoords finish = gr_logcoords(vertices[(i+1) % 6]);
GrCoords len = { finish.x - start.x, finish.y - start.y };
GrCoords perp = { -len.y, +len.x };
GrCoords mid = { (start.x+finish.x)/2, (start.y+finish.y)/2 };
sprintf(buf, "%zu", i);
{
GrCoords pos = {
mid.x + offset * perp.x,
mid.y + offset * perp.y,
};
gr_draw_text(gr, pos, textheight, buf);
}
}
}
}
static void draw_one_spectre(Graphics *gr)
{
size_t i, j;
Point vertices[14];
{
Point start = {{ 0, 0, 0, 0 }};
Point pos = start;
Point diag = {{ 2, 0, 0, 2 }};
Point dir = point_mul(diag, point_rot(9));
for (j = 0; j < 14; j++) {
vertices[j] = pos;
pos = point_add(pos, dir);
dir = point_mul(dir, point_rot(spectre_angles[(j+1) % 14]));
}
gr_draw_spectre(gr, NO_HEX, -1, vertices);
}
/*
* Draw the labels on the edges.
*/
if (gr->number_edges) {
for (i = 0; i < 14; i++) {
char buf[64];
double textheight = 0.8, offset = textheight * 0.2;
GrCoords start = gr_logcoords(vertices[i]);
GrCoords finish = gr_logcoords(vertices[(i+1) % 14]);
GrCoords len = { finish.x - start.x, finish.y - start.y };
GrCoords perp = { +len.y, -len.x };
GrCoords mid = { (start.x+finish.x)/2, (start.y+finish.y)/2 };
sprintf(buf, "%zu", i);
if (strlen(buf) > 1)
offset = textheight * 0.35;
{
GrCoords pos = {
mid.x + offset * perp.x,
mid.y + offset * perp.y,
};
gr_draw_text(gr, pos, textheight, buf);
}
}
}
}
static void make_parent_tables(FILE *fp)
{
size_t i, j, k;
for (i = 0; i < 9; i++) {
fprintf(fp, "static const struct Possibility poss_%s[] = {\n",
hex_names[i]);
for (j = 0; j < 9; j++) {
for (k = 0; k < num_subhexes(j); k++) {
if (hexdata[j].subhexes[k] == i) {
fprintf(fp, " { HEX_%s, %zu, PROB_%s },\n",
hex_names[j], k, hex_names[j]);
}
}
}
fprintf(fp, "};\n");
}
fprintf(fp, "static const struct Possibility poss_spectre[] = {\n");
for (j = 0; j < 9; j++) {
for (k = 0; k < num_spectres(j); k++) {
fprintf(fp, " { HEX_%s, %zu, PROB_%s },\n",
hex_names[j], k, hex_names[j]);
}
}
fprintf(fp, "};\n");
}
int main(void)
{
size_t i;
FILE *fp = fopen("spectre-tables-auto.h", "w");
fprintf(fp,
"/*\n"
" * Autogenerated transition tables for the Spectre tiling.\n"
" * Generated by auxiliary/spectre-gen.c.\n"
" */\n\n");
for (i = 0; i < 9; i++) {
char buf[64];
sprintf(buf, "hexmap_%s.svg", hex_names[i]);
Graphics *gr = gr_new(buf, -11, +11, -20, +4.5, 13);
lay_out_hexagons(i, gr, fp);
gr_free(gr);
}
for (i = 0; i < 9; i++) {
char buf[64];
sprintf(buf, "specmap_%s.svg", hex_names[i]);
Graphics *gr = gr_new(buf, (i == HEX_S ? -14 : -11.5),
(i == HEX_G ? +10 : 0.5),
-2, +12, 15);
lay_out_spectres(i, gr, fp);
gr_free(gr);
}
for (i = 0; i < 9; i++) {
char buf[64];
sprintf(buf, "basehex_%s.svg", hex_names[i]);
Graphics *gr = gr_new(buf, -4, +4, -4.2, +4.5, 15);
draw_base_hex(i, gr);
gr_free(gr);
}
for (i = 0; i < 9; i++) {
char buf[64];
sprintf(buf, "jigsawhex_%s.svg", hex_names[i]);
Graphics *gr = gr_new(buf, -4, +4, -4.2, +4.5, 20);
gr->jigsaw_mode = true;
gr->vertex_blobs = false;
gr->number_edges = false;
draw_base_hex(i, gr);
gr_free(gr);
}
{
Graphics *gr = gr_new("basehex_null.svg", -4, +4, -4.2, +4.5, 20);
gr->vertex_blobs = false;
draw_base_hex(NO_HEX, gr);
gr_free(gr);
}
{
Graphics *gr = gr_new("basespec_null.svg", -7, +6, -14, +1, 15);
gr->vertex_blobs = false;
draw_one_spectre(gr);
gr_free(gr);
}
{
Graphics *gr = gr_new("hexmap_null.svg", -11, +11, -20, +4.5, 10);
gr->vertex_blobs = false;
gr->number_edges = false;
gr->hex_arrows = false;
lay_out_hexagons(NO_HEX, gr, NULL);
gr_free(gr);
}
{
Graphics *gr = gr_new("specmap_null.svg", -11.5, +10, -2, +12, 15);
gr->vertex_blobs = false;
gr->number_edges = false;
gr->hex_arrows = false;
lay_out_spectres(NO_HEX, gr, NULL);
gr_free(gr);
}
for (i = 0; i < 2; i++) {
char buf[64];
sprintf(buf, "jigsawexpand_%s.svg", hex_names[i]);
Graphics *gr = gr_new(buf, -11, +11, -20, +4.5, 10);
gr->jigsaw_mode = true;
gr->vertex_blobs = false;
gr->number_edges = false;
lay_out_hexagons(i, gr, fp);
gr_free(gr);
}
make_parent_tables(fp);
fclose(fp);
return 0;
}
|
ccf9016fdd91784fe394bd1a9d1e6b20b441a6f2
|
d2253070a3a64b14dee5ca0b3d311919178e590c
|
/tools/gbagfx/options.h
|
830158b52e901edebfa1bf68cad9ae96843effb1
|
[
"MIT"
] |
permissive
|
pret/pokeemerald
|
ce232eccdde78502f3c251d672b26af3e1d7e508
|
d67914e114c937c4c80ce128ddc5523d4dc2cd40
|
refs/heads/master
| 2023-08-31T11:23:13.877932
| 2023-08-27T23:40:59
| 2023-08-27T23:40:59
| 43,677,244
| 1,944
| 1,903
| null | 2023-09-12T22:48:06
| 2015-10-05T10:09:22
|
C
|
UTF-8
|
C
| false
| false
| 610
|
h
|
options.h
|
// Copyright (c) 2018 huderlem
#ifndef OPTIONS_H
#define OPTIONS_H
#include <stdbool.h>
#include "gfx.h"
struct GbaToPngOptions {
char *paletteFilePath;
int bitDepth;
bool hasTransparency;
int width;
int metatileWidth;
int metatileHeight;
char *tilemapFilePath;
bool isAffineMap;
bool isTiled;
int dataWidth;
};
struct PngToGbaOptions {
int numTiles;
enum NumTilesMode numTilesMode;
int bitDepth;
int metatileWidth;
int metatileHeight;
char *tilemapFilePath;
bool isAffineMap;
bool isTiled;
int dataWidth;
};
#endif // OPTIONS_H
|
687c2fde35cfb616d56c2d1bbd488485c286c43e
|
4aec457e24812a0baedb622f96f02c9bf81984a8
|
/tests/bench_server.c
|
d9c28ea76536b94eada8b16683b9cfa5ffe923f7
|
[
"MIT"
] |
permissive
|
starwing/znet
|
fb2df876315fd4533a2b0c3d1a7ff7177223f88f
|
4380d8bc41312288fea8a9c0bca86908a0bb9e13
|
refs/heads/master
| 2022-05-25T13:20:39.304556
| 2022-03-31T12:49:30
| 2022-04-29T13:40:36
| 36,144,118
| 170
| 41
|
MIT
| 2022-04-29T13:40:37
| 2015-05-23T21:53:04
|
C
|
UTF-8
|
C
| false
| false
| 3,776
|
c
|
bench_server.c
|
#define ZN_IMPLEMENTATION
#include "../znet.h"
#include "../zn_buffer.h"
#include "zn_bufferpool.h"
#include <stdio.h>
/* server */
zn_State *S;
zn_BufferPool pool;
#define INTERVAL 5000
int send_count = 0;
int recv_count = 0;
int connect_count = 0;
static void on_send(void *ud, zn_Tcp *tcp, unsigned err, unsigned count) {
zn_BufferPoolNode *node = (zn_BufferPoolNode*)ud;
if (err != ZN_OK) {
zn_putbuffer(&pool, node);
zn_deltcp(tcp);
return;
}
send_count += count;
zn_sendfinish(&node->send, count);
}
static void on_recv(void *ud, zn_Tcp *tcp, unsigned err, unsigned count) {
zn_BufferPoolNode *node = (zn_BufferPoolNode*)ud;
if (err != ZN_OK) {
zn_putbuffer(&pool, node);
zn_deltcp(tcp);
return;
}
recv_count += count;
zn_recvfinish(&node->recv, count);
zn_recv(tcp,
zn_recvbuff(&node->recv),
zn_recvsize(&node->recv), on_recv, ud);
}
static size_t on_header(void *ud, const char *buff, size_t len) {
unsigned short plen;
if (len < 2) return 0;
memcpy(&plen, buff, 2);
return ntohs(plen);
}
static void on_packet(void *ud, const char *buff, size_t len) {
zn_BufferPoolNode *node = (zn_BufferPoolNode*)ud;
zn_sendprepare(&node->send, buff, len);
zn_send(node->tcp,
zn_sendbuff(&node->send),
zn_sendsize(&node->send), on_send, node);
}
static void on_accept(void *ud, zn_Accept *accept, unsigned err, zn_Tcp *tcp) {
zn_BufferPoolNode *node;
if (err != ZN_OK)
exit(2);
++connect_count;
node = zn_getbuffer(&pool);
zn_recvonheader(&node->recv, on_header, node);
zn_recvonpacket(&node->recv, on_packet, node);
node->tcp = tcp;
if (zn_recv(tcp,
zn_recvbuff(&node->recv),
zn_recvsize(&node->recv), on_recv, node) != ZN_OK) {
zn_putbuffer(&pool, node);
zn_deltcp(tcp);
}
zn_accept(accept, on_accept, ud);
}
static zn_Time on_timer(void *ud, zn_Timer *timer, zn_Time elapsed) {
printf("%d: connect=%d, recv=%d, send=%d\n",
zn_time(), connect_count, recv_count, send_count);
connect_count = 0;
recv_count = 0;
send_count = 0;
return INTERVAL;
}
static void cleanup(void) {
printf("exiting ... ");
zn_close(S);
printf("OK\n");
printf("deinitialize ... ");
zn_deinitialize();
printf("OK\n");
}
#ifdef _WIN32
static int deinited = 0;
static BOOL WINAPI on_interrupted(DWORD dwCtrlEvent) {
if (!deinited) {
deinited = 1;
/* windows ctrl handler is running at another thread */
zn_post(S, (zn_PostHandler*)cleanup, NULL);
}
return TRUE;
}
static void register_interrupted(void) {
SetConsoleCtrlHandler(on_interrupted, TRUE);
}
#else
#include <signal.h>
static void on_interrupted(int signum) {
if (signum == SIGINT)
cleanup();
}
static void register_interrupted(void) {
struct sigaction act;
act.sa_flags = SA_RESETHAND;
act.sa_handler = on_interrupted;
sigaction(SIGINT, &act, NULL);
}
#endif
int main(int argc, char **argv) {
unsigned port = 12345;
zn_Accept *accept;
zn_Timer *timer;
if (argc == 2) {
unsigned p = atoi(argv[1]);
if (p != 0) port = p;
}
zn_initialize();
S = zn_newstate();
zn_initbuffpool(&pool);
if (S == NULL)
return 2;
accept = zn_newaccept(S);
if (accept == NULL)
return 2;
zn_listen(accept, "0.0.0.0", port);
zn_accept(accept, on_accept, NULL);
printf("listening at: %u\n", port);
timer = zn_newtimer(S, on_timer, NULL);
zn_starttimer(timer, INTERVAL);
register_interrupted();
return zn_run(S, ZN_RUN_LOOP);
}
/* cc: flags+='-s -O3' libs+='-lws2_32' */
|
4ad8a0788ef589f82f4783cae04db4c8dd05b3c5
|
a17149fe4e58b1a087d2c055e09e3efa194dbc04
|
/linux/term.c
|
0aa8f82a0fede3bd0837a82da966966a01db74f0
|
[
"ISC",
"MIT"
] |
permissive
|
laanwj/k210-sdk-stuff
|
7a05d5d936c086cc3398cdff1cdaded451b40a99
|
ecdd3e8790a8f014b627f4b35e1dd3a37cef86a5
|
refs/heads/master
| 2023-04-07T14:50:34.919197
| 2023-03-18T15:20:00
| 2023-03-18T15:20:00
| 184,874,120
| 141
| 39
|
ISC
| 2022-04-04T09:11:39
| 2019-05-04T09:12:28
|
C
|
UTF-8
|
C
| false
| false
| 3,604
|
c
|
term.c
|
/** term: Minimal interactive serial console.
* Usage: term /dev/ttyS1
*
* Copyright (c) 2020 W.J. van der Laan
* Distributed under the MIT software license,
*/
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <termios.h>
#include <unistd.h>
#include <poll.h>
int set_raw(int fd)
{
struct termios tty;
if (tcgetattr(fd, &tty) < 0) {
printf("Error from tcgetattr: %s\n", strerror(errno));
return -1;
}
tty.c_iflag &= ~(ICRNL | IXON);
tty.c_lflag &= ~(ECHO | ICANON);
if (tcsetattr(fd, TCSANOW, &tty) != 0) {
printf("Error from tcsetattr: %s\n", strerror(errno));
return -1;
}
return 0;
}
int set_interface_attribs(int fd, int speed)
{
struct termios tty;
if (tcgetattr(fd, &tty) < 0) {
printf("Error from tcgetattr: %s\n", strerror(errno));
return -1;
}
cfsetospeed(&tty, (speed_t)speed);
cfsetispeed(&tty, (speed_t)speed);
tty.c_cflag |= (CLOCAL | CREAD); /* ignore modem controls */
tty.c_cflag &= ~CSIZE;
tty.c_cflag |= CS8; /* 8-bit characters */
tty.c_cflag &= ~PARENB; /* no parity bit */
tty.c_cflag &= ~CSTOPB; /* only need 1 stop bit */
tty.c_cflag &= ~CRTSCTS; /* no hardware flowcontrol */
/* setup for non-canonical mode */
tty.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON);
tty.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
tty.c_oflag &= ~OPOST;
/* fetch bytes as they become available */
tty.c_cc[VMIN] = 1;
tty.c_cc[VTIME] = 1;
if (tcsetattr(fd, TCSANOW, &tty) != 0) {
printf("Error from tcsetattr: %s\n", strerror(errno));
return -1;
}
return 0;
}
int main(int argc, char **argv) {
if (argc < 2) {
fprintf(stderr, "Pass serial device on command line\n");
exit(1);
}
const char *portname = argv[1];
int fd = open(portname, O_RDWR | O_NOCTTY | O_SYNC);
if (fd < 0) {
fprintf(stderr, "Error opening %s: %s\n", portname, strerror(errno));
exit(1);
}
set_raw(STDIN_FILENO);
/*baudrate 115200, 8 bits, no parity, 1 stop bit */
set_interface_attribs(fd, B115200);
struct pollfd fds[2] = {
{STDIN_FILENO, POLLIN, 0},
{fd, POLLIN, 0},
};
do {
for (int i=0; i<2; ++i) {
fds[i].revents = 0;
}
if (poll(fds, 2, -1) < 0) {
fprintf(stderr, "Poll error: %s\n", strerror(errno));
exit(1);
}
for (int i=0; i<2; ++i) {
if (fds[i].revents & POLLIN) {
char ch;
int rdlen = read(fds[i].fd, &ch, 1);
if (rdlen < 0) {
fprintf(stderr, "Error from read: %d: %s\n", rdlen, strerror(errno));
exit(1);
} else if (rdlen == 0) {
/* EOF */
exit(0);
}
if (i == 1 && ch == '\r') {
/* Don't print \r */
continue;
}
if (i == 0 && ch == '\n') {
/* Add extra \r before newline */
char cr = '\r';
write(fds[1-i].fd, &cr, 1);
}
int wlen = write(fds[1-i].fd, &ch, 1);
if (wlen <= 0) {
fprintf(stderr, "Error from write: %d: %s\n", wlen, strerror(errno));
exit(1);
}
}
}
} while (1);
}
|
5094f487161f0d8700a26f78a9c9afeefd00cd65
|
fbe68d84e97262d6d26dd65c704a7b50af2b3943
|
/third_party/libdwarf-20191104/dwarfdump/print_macros.c
|
caac95cdf6d2a0adecc18347c37599b00b1c7be6
|
[
"LGPL-2.0-or-later",
"GPL-1.0-or-later",
"GPL-2.0-only",
"MIT",
"LGPL-2.1-only"
] |
permissive
|
thalium/icebox
|
c4e6573f2b4f0973b6c7bb0bf068fe9e795fdcfb
|
6f78952d58da52ea4f0e55b2ab297f28e80c1160
|
refs/heads/master
| 2022-08-14T00:19:36.984579
| 2022-02-22T13:10:31
| 2022-02-22T13:10:31
| 190,019,914
| 585
| 109
|
MIT
| 2022-01-13T20:58:15
| 2019-06-03T14:18:12
|
C++
|
UTF-8
|
C
| false
| false
| 6,932
|
c
|
print_macros.c
|
/*
Copyright (C) 2000-2006 Silicon Graphics, Inc. All Rights Reserved.
Portions Copyright 2007-2010 Sun Microsystems, Inc. All rights reserved.
Portions Copyright 2009-2018 SN Systems Ltd. All rights reserved.
Portions Copyright 2008-2018 David Anderson. All rights reserved.
This program is free software; you can redistribute it and/or modify it
under the terms of version 2 of the GNU General Public License as
published by the Free Software Foundation.
This program is distributed in the hope that it would be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Further, this software is distributed without any warranty that it is
free of the rightful claim of any third person regarding infringement
or the like. Any license provided herein, whether implied or
otherwise, applies only to this software file. Patent licenses, if
any, provided herein do not apply to combinations of this program with
other software, or any other product whatsoever.
You should have received a copy of the GNU General Public License along
with this program; if not, write the Free Software Foundation, Inc., 51
Franklin Street - Fifth Floor, Boston MA 02110-1301, USA.
*/
#include "globals.h"
#include "naming.h"
#include "macrocheck.h"
#include "esb.h"
#include "esb_using_functions.h"
#include "sanitized.h"
#include "print_sections.h"
#include "print_frames.h"
#define TRUE 1
#define FALSE 0
struct macro_counts_s {
long mc_start_file;
long mc_end_file;
long mc_define;
long mc_undef;
long mc_extension;
long mc_code_zero;
long mc_unknown;
};
static void
print_one_macro_entry_detail(long i,
char *type,
struct Dwarf_Macro_Details_s *mdp)
{
/* "DW_MACINFO_*: section-offset file-index [line] string\n" */
if (glflags.gf_do_print_dwarf) {
if (mdp->dmd_macro) {
printf("%3ld %s: %6" DW_PR_DUu " %2" DW_PR_DSd " [%4"
DW_PR_DSd "] \"%s\" \n",
i,
type,
(Dwarf_Unsigned)mdp->dmd_offset,
mdp->dmd_fileindex, mdp->dmd_lineno,
sanitized(mdp->dmd_macro));
} else {
printf("%3ld %s: %6" DW_PR_DUu " %2" DW_PR_DSd " [%4"
DW_PR_DSd "] 0\n",
i,
type,
(Dwarf_Unsigned)mdp->dmd_offset,
mdp->dmd_fileindex, mdp->dmd_lineno);
}
}
}
static void
print_one_macro_entry(long i,
struct Dwarf_Macro_Details_s *mdp,
struct macro_counts_s *counts)
{
switch (mdp->dmd_type) {
case 0:
counts->mc_code_zero++;
print_one_macro_entry_detail(i, "DW_MACINFO_type-code-0", mdp);
break;
case DW_MACINFO_start_file:
counts->mc_start_file++;
print_one_macro_entry_detail(i, "DW_MACINFO_start_file", mdp);
break;
case DW_MACINFO_end_file:
counts->mc_end_file++;
print_one_macro_entry_detail(i, "DW_MACINFO_end_file ", mdp);
break;
case DW_MACINFO_vendor_ext:
counts->mc_extension++;
print_one_macro_entry_detail(i, "DW_MACINFO_vendor_ext", mdp);
break;
case DW_MACINFO_define:
counts->mc_define++;
print_one_macro_entry_detail(i, "DW_MACINFO_define ", mdp);
break;
case DW_MACINFO_undef:
counts->mc_undef++;
print_one_macro_entry_detail(i, "DW_MACINFO_undef ", mdp);
break;
default:
{
struct esb_s typeb;
esb_constructor(&typeb);
counts->mc_unknown++;
esb_append_printf(&typeb,
"DW_MACINFO_0x%x", mdp->dmd_type);
print_one_macro_entry_detail(i,
esb_get_string(&typeb), mdp);
esb_destructor(&typeb);
}
break;
}
}
/* print data in .debug_macinfo */
/*ARGSUSED*/ extern void
print_macinfo_by_offset(Dwarf_Debug dbg,Dwarf_Unsigned offset)
{
Dwarf_Unsigned max = 0;
Dwarf_Signed count = 0;
Dwarf_Macro_Details *maclist = NULL;
int lres = 0;
long i = 0;
struct macro_counts_s counts;
Dwarf_Unsigned totallen = 0;
Dwarf_Bool is_primary = TRUE;
Dwarf_Error error = 0;
glflags.current_section_id = DEBUG_MACINFO;
/* No real need to get the real section name, this
section not used much in modern compilers
as this definition of macro data (V2-V4)
is obsolete as it takes too much space to be
much used. */
lres = dwarf_get_macro_details(dbg, offset,
max, &count, &maclist, &error);
if (lres == DW_DLV_ERROR) {
print_error(dbg, "dwarf_get_macro_details", lres, error);
} else if (lres == DW_DLV_NO_ENTRY) {
return;
}
memset(&counts, 0, sizeof(counts));
if (glflags.gf_do_print_dwarf) {
struct esb_s truename;
char buf[DWARF_SECNAME_BUFFER_SIZE];
esb_constructor_fixed(&truename,buf,sizeof(buf));
get_true_section_name(dbg,".debug_macinfo",
&truename,TRUE);
printf("\n%s\n",sanitized(esb_get_string(&truename)));
esb_destructor(&truename);
printf("\n");
printf("compilation-unit .debug_macinfo offset "
"0x%" DW_PR_XZEROS DW_PR_DUx "\n",offset);
printf("num name section-offset file-index [line] \"string\"\n");
}
for (i = 0; i < count; i++) {
struct Dwarf_Macro_Details_s *mdp = &maclist[i];
print_one_macro_entry(i, mdp, &counts);
}
if (counts.mc_start_file == 0) {
printf("DW_MACINFO file count of zero is invalid DWARF2/3/4\n");
}
if (counts.mc_start_file != counts.mc_end_file) {
printf("Counts of DW_MACINFO file (%ld) end_file (%ld) "
"do not match!.\n",
counts.mc_start_file, counts.mc_end_file);
}
if (counts.mc_code_zero < 1) {
printf("Count of zeros in macro group should be non-zero "
"(1 preferred), count is %ld\n",
counts.mc_code_zero);
}
/* next byte is maclist[count - 1].dmd_offset + 1; */
totallen = (maclist[count - 1].dmd_offset + 1) - offset;
add_macro_import(&macinfo_check_tree,is_primary, offset);
add_macro_area_len(&macinfo_check_tree,offset,totallen);
if (glflags.gf_do_print_dwarf) {
printf("Macro counts: start file %ld, "
"end file %ld, "
"define %ld, "
"undef %ld, "
"ext %ld, "
"code-zero %ld, "
"unknown %ld\n",
counts.mc_start_file,
counts.mc_end_file,
counts.mc_define,
counts.mc_undef,
counts.mc_extension,
counts.mc_code_zero, counts.mc_unknown);
}
/* int type= maclist[count - 1].dmd_type; */
/* ASSERT: type is zero */
dwarf_dealloc(dbg, maclist, DW_DLA_STRING);
return;
}
|
cba3ee1c70a8772a4c07ee0d77db088d523ff1d7
|
fbe68d84e97262d6d26dd65c704a7b50af2b3943
|
/third_party/virtualbox/src/VBox/Devices/Graphics/shaderlib/wine/include/corerror.h
|
a7e17c186102c688f40a63eda50d5333c2c4da18
|
[
"LGPL-2.0-or-later",
"LGPL-2.1-or-later",
"LGPL-2.1-only",
"GPL-1.0-or-later",
"LGPL-2.0-only",
"GPL-2.0-only",
"LicenseRef-scancode-unknown-license-reference",
"CDDL-1.0",
"LicenseRef-scancode-warranty-disclaimer",
"GPL-2.0-or-later",
"MPL-1.0",
"LicenseRef-scancode-generic-exception",
"Apache-2.0",
"OpenSSL",
"MIT"
] |
permissive
|
thalium/icebox
|
c4e6573f2b4f0973b6c7bb0bf068fe9e795fdcfb
|
6f78952d58da52ea4f0e55b2ab297f28e80c1160
|
refs/heads/master
| 2022-08-14T00:19:36.984579
| 2022-02-22T13:10:31
| 2022-02-22T13:10:31
| 190,019,914
| 585
| 109
|
MIT
| 2022-01-13T20:58:15
| 2019-06-03T14:18:12
|
C++
|
UTF-8
|
C
| false
| false
| 6,793
|
h
|
corerror.h
|
/*
* Copyright 2008 James Hawkins
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
/*
* Oracle LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
* other than GPL or LGPL is available it will apply instead, Oracle elects to use only
* the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
* a choice of LGPL license versions is made available with the language indicating
* that LGPLv2 or any later version may be used, or where a choice of which version
* of the LGPL is applied is otherwise unspecified.
*/
#ifndef __WINE_CORERROR_H
#define __WINE_CORERROR_H
#include <winerror.h>
#ifndef FACILITY_URT
#define FACILITY_URT 0x13
#endif
#ifndef EMAKEHR
#define SMAKEHR(val) MAKE_HRESULT(SEVERITY_SUCCESS, FACILITY_URT, val)
#define EMAKEHR(val) MAKE_HRESULT(SEVERITY_ERROR, FACILITY_URT, val)
#endif
#define COR_E_ARGUMENT E_INVALIDARG
#define COR_E_INVALIDCAST E_NOINTERFACE
#define COR_E_NULLREFERENCE E_POINTER
#define COR_E_OUTOFMEMORY E_OUTOFMEMORY
#define COR_E_UNAUTHORIZEDACCESS E_ACCESSDENIED
#define COR_E_ARITHMETIC HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW)
#define COR_E_STACKOVERFLOW HRESULT_FROM_WIN32(ERROR_STACK_OVERFLOW)
#define COR_E_ENDOFSTREAM HRESULT_FROM_WIN32(ERROR_HANDLE_EOF)
#define COR_E_FILENOTFOUND HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)
#define COR_E_BAD_PATHNAME HRESULT_FROM_WIN32(ERROR_BAD_PATHNAME)
#define COR_E_DIRECTORYNOTFOUND HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND)
#define COR_E_PATHTOOLONG HRESULT_FROM_WIN32(ERROR_FILENAME_EXCED_RANGE)
#define COR_E_AMBIGUOUSMATCH _HRESULT_TYPEDEF_(0x8000211D)
#define COR_E_TARGETPARAMCOUNT _HRESULT_TYPEDEF_(0x8002000E)
#define COR_E_DIVIDEBYZERO _HRESULT_TYPEDEF_(0x80020012)
#define COR_E_BADIMAGEFORMAT _HRESULT_TYPEDEF_(0x8007000B)
#define COR_E_ASSEMBLYEXPECTED EMAKEHR(0x1018)
#define COR_E_TYPEUNLOADED EMAKEHR(0x1013)
#define COR_E_EXCEPTION EMAKEHR(0x1500)
#define COR_E_SYSTEM EMAKEHR(0x1501)
#define COR_E_ARGUMENTOUTOFRANGE EMAKEHR(0x1502)
#define COR_E_ARRAYTYPEMISMATCH EMAKEHR(0x1503)
#define COR_E_CONTEXTMARSHAL EMAKEHR(0x1504)
#define COR_E_TIMEOUT EMAKEHR(0x1505)
#define COR_E_EXECUTIONENGINE EMAKEHR(0x1506)
#define COR_E_FIELDACCESS EMAKEHR(0x1507)
#define COR_E_INDEXOUTOFRANGE EMAKEHR(0x1508)
#define COR_E_INVALIDOPERATION EMAKEHR(0x1509)
#define COR_E_SECURITY EMAKEHR(0x150A)
#define COR_E_REMOTING EMAKEHR(0x150B)
#define COR_E_SERIALIZATION EMAKEHR(0x150C)
#define COR_E_VERIFICATION EMAKEHR(0x150D)
#define COR_E_SERVER EMAKEHR(0x150E)
#define COR_E_SERVICEDCOMPONENT EMAKEHR(0x150F)
#define COR_E_METHODACCESS EMAKEHR(0x1510)
#define COR_E_MISSINGFIELD EMAKEHR(0x1511)
#define COR_E_MISSINGMEMBER EMAKEHR(0x1512)
#define COR_E_MISSINGMETHOD EMAKEHR(0x1513)
#define COR_E_MULTICASTNOTSUPPORTED EMAKEHR(0x1514)
#define COR_E_NOTSUPPORTED EMAKEHR(0x1515)
#define COR_E_OVERFLOW EMAKEHR(0x1516)
#define COR_E_RANK EMAKEHR(0x1517)
#define COR_E_SYNCHRONIZATIONLOCK EMAKEHR(0x1518)
#define COR_E_THREADINTERRUPTED EMAKEHR(0x1519)
#define COR_E_MEMBERACCESS EMAKEHR(0x151A)
#define COR_E_THREADSTATE EMAKEHR(0x1520)
#define COR_E_THREADSTOP EMAKEHR(0x1521)
#define COR_E_TYPELOAD EMAKEHR(0x1522)
#define COR_E_ENTRYPOINTNOTFOUND EMAKEHR(0x1523)
#define COR_E_DLLNOTFOUND EMAKEHR(0x1524)
#define COR_E_THREADSTART EMAKEHR(0x1525)
#define COR_E_INVALIDCOMOBJECT EMAKEHR(0x1527)
#define COR_E_NOTFINITENUMBER EMAKEHR(0x1528)
#define COR_E_DUPLICATEWAITOBJECT EMAKEHR(0x1529)
#define COR_E_SEMAPHOREFULL EMAKEHR(0x152B)
#define COR_E_WAITHANDLECANNOTBEOPENED EMAKEHR(0x152C)
#define COR_E_ABANDONEDMUTEX EMAKEHR(0x152D)
#define COR_E_INVALIDOLEVARIANTTYPE EMAKEHR(0x1531)
#define COR_E_MISSINGMANIFESTRESOURCE EMAKEHR(0x1532)
#define COR_E_SAFEARRAYTYPEMISMATCH EMAKEHR(0x1533)
#define COR_E_TYPEINITIALIZATION EMAKEHR(0x1534)
#define COR_E_MARSHALDIRECTIVE EMAKEHR(0x1535)
#define COR_E_MISSINGSATELLITEASSEMBLY EMAKEHR(0x1536)
#define COR_E_FORMAT EMAKEHR(0x1537)
#define COR_E_SAFEARRAYRANKMISMATCH EMAKEHR(0x1538)
#define COR_E_PLATFORMNOTSUPPORTED EMAKEHR(0x1539)
#define COR_E_INVALIDPROGRAM EMAKEHR(0x153A)
#define COR_E_OPERATIONCANCELED EMAKEHR(0x153B)
#define COR_E_INSUFFICIENTMEMORY EMAKEHR(0x153D)
#define COR_E_RUNTIMEWRAPPED EMAKEHR(0x153E)
#define COR_E_DEVICESNOTSUPPORTED EMAKEHR(0x1540)
#define COR_E_DATAMISALIGNED EMAKEHR(0x1541)
#define COR_E_KEYNOTFOUND EMAKEHR(0x1577)
#define COR_E_APPLICATION EMAKEHR(0x1600)
#define COR_E_INVALIDFILTERCRITERIA EMAKEHR(0x1601)
#define COR_E_REFLECTIONTYPELOAD EMAKEHR(0x1602)
#define COR_E_TARGET EMAKEHR(0x1603)
#define COR_E_TARGETINVOCATION EMAKEHR(0x1604)
#define COR_E_CUSTOMATTRIBUTEFORMAT EMAKEHR(0x1605)
#define COR_E_IO EMAKEHR(0x1620)
#define COR_E_FILELOAD EMAKEHR(0x1621)
#define COR_E_OBJECTDISPOSED EMAKEHR(0x1622)
#define COR_E_FAILFAST EMAKEHR(0x1623)
#define COR_E_HOSTPROTECTION EMAKEHR(0x1640)
#define COR_E_ILLEGAL_REENTRANCY EMAKEHR(0x1641)
#define FUSION_E_PRIVATE_ASM_DISALLOWED EMAKEHR(0x1044)
#define FUSION_E_INVALID_NAME EMAKEHR(0x1047)
#define CLDB_E_FILE_OLDVER EMAKEHR(0x1107)
#define CLR_E_SHIM_RUNTIME EMAKEHR(0x1700)
#define CLR_E_SHIM_RUNTIMEEXPORT EMAKEHR(0x1701)
#endif /* __WINE_CORERROR_H */
|
c3442461c1777b921e1d11056cc137f34a699aed
|
7664f318ed04bd0680f3d82321c18896e3ef6ad5
|
/src/overlays/effects/ovl_Effect_Ss_Stone1/z_eff_ss_stone1.h
|
680345014fcc2eb3facdc0196be896d22ff73c1f
|
[] |
no_license
|
zeldaret/oot
|
9c80ce17f2d8fd61514b375f92ee4739b5ce9d4e
|
2875ab4fcf5c5f81d76353d1ee0024c9ea8d0b23
|
refs/heads/master
| 2023-08-29T05:29:31.356427
| 2023-08-28T22:48:52
| 2023-08-28T22:48:52
| 247,875,738
| 4,401
| 802
| null | 2023-09-14T13:34:38
| 2020-03-17T04:02:19
|
C
|
UTF-8
|
C
| false
| false
| 213
|
h
|
z_eff_ss_stone1.h
|
#ifndef Z_EFF_SS_STONE1_H
#define Z_EFF_SS_STONE1_H
#include "ultra64.h"
#include "global.h"
typedef struct {
/* 0x00 */ Vec3f pos;
/* 0x00 */ s32 unk_C;
} EffectSsStone1InitParams; // size = 0x
#endif
|
ba02c1c787452f4e44cc3ec3ad34877fa5a4f972
|
3499b1145f0827498625ec0ac71ba82bbbbda4ed
|
/board-package-source/libraries/Arduboy2/examples/HardwareTest/bitmaps.h
|
f2969487deef917d4d5a9243ee7b7b62077c9d98
|
[
"CC0-1.0",
"Zlib",
"LGPL-2.0-or-later",
"LGPL-2.1-only",
"BSD-3-Clause",
"MIT",
"LicenseRef-scancode-public-domain",
"BSD-2-Clause",
"LGPL-2.1-or-later"
] |
permissive
|
MrBlinky/Arduboy-homemade-package
|
09120974a9c6a9ad1871ac68cbf852bb253bbd8e
|
3b71be313e1a4daaa745a15cdf2b58c92b101441
|
refs/heads/master
| 2023-07-22T18:36:15.664481
| 2023-07-15T22:08:51
| 2023-07-15T22:08:51
| 121,283,656
| 104
| 31
|
CC0-1.0
| 2023-01-02T08:24:54
| 2018-02-12T18:16:15
|
C++
|
UTF-8
|
C
| false
| false
| 10,030
|
h
|
bitmaps.h
|
#ifndef BITMAPS_H
#define BITMAPS_H
/*******************
* Background image
*******************/
const unsigned char PROGMEM background_gfx[] =
{
// width, height,
128, 64,
0x00, 0x00, 0xfe, 0xfe, 0xfe, 0x66, 0x66, 0xe6, 0xe6, 0xfe, 0xbe, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x10, 0x48, 0xa8, 0x48, 0xa8, 0x48, 0xa8, 0x48, 0xa8, 0x48, 0xa8, 0x48, 0xa8, 0x48, 0xa8, 0x48, 0xa8, 0x48, 0xa8, 0x48, 0xa8, 0x48, 0xa8, 0x48, 0xa8, 0x48, 0xa8, 0x48, 0xa8, 0x48, 0xa8, 0x48, 0xa8, 0x48, 0xa8, 0x48, 0xa8, 0x48, 0xa8, 0x48, 0xa8, 0x48, 0xa8, 0x48, 0xa8, 0x48, 0xa8, 0x48, 0xa8, 0x48, 0xa8, 0x48, 0xa8, 0x48, 0xa8, 0x48, 0xa8, 0x48, 0xa8, 0x48, 0xa8, 0x48, 0xa8, 0x48, 0xa8, 0x48, 0xa8, 0x48, 0xa8, 0x48, 0xa8, 0x48, 0xa8, 0x48, 0xa8, 0x48, 0xa8, 0x48, 0xa8, 0x48, 0xa8, 0x48, 0xa8, 0x48, 0xa8, 0x48, 0xa8, 0x48, 0xa8, 0x48, 0xa8, 0x48, 0xa8, 0x48, 0xa8, 0x48, 0xa8, 0x48, 0xa8, 0x48, 0xa8, 0x48, 0xa8, 0x48, 0xa8, 0x48, 0x10, 0xe0, 0x00, 0x00,
0x00, 0x00, 0x07, 0x07, 0x87, 0x80, 0x80, 0x80, 0x81, 0x87, 0x07, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x01, 0x00, 0x00, 0x00,
0x00, 0x00, 0x7e, 0xff, 0xff, 0xc3, 0x81, 0x81, 0xd3, 0xf7, 0xf7, 0xf6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x44, 0x92, 0xaa, 0x92, 0xaa, 0x92, 0xaa, 0x92, 0xaa, 0x92, 0xaa, 0x92, 0xaa, 0x92, 0xaa, 0x92, 0xaa, 0x92, 0xaa, 0x92, 0xaa, 0x92, 0xaa, 0x92, 0xaa, 0x92, 0xaa, 0x92, 0xaa, 0x92, 0xaa, 0x92, 0xaa, 0x92, 0xaa, 0x92, 0xaa, 0x92, 0xaa, 0x92, 0xaa, 0x92, 0xaa, 0x92, 0xaa, 0x92, 0xaa, 0x92, 0xaa, 0x92, 0xaa, 0x92, 0xaa, 0x92, 0xaa, 0x92, 0xaa, 0x92, 0xaa, 0x92, 0xaa, 0x92, 0xaa, 0x92, 0xaa, 0x92, 0xaa, 0x92, 0xaa, 0x92, 0xaa, 0x92, 0xaa, 0x92, 0xaa, 0x92, 0xaa, 0x92, 0xaa, 0x92, 0xaa, 0x92, 0xaa, 0x92, 0xaa, 0x92, 0xaa, 0x92, 0xaa, 0x92, 0xaa, 0x92, 0xaa, 0x92, 0xaa, 0x92, 0xaa, 0x92, 0xaa, 0x92, 0xaa, 0x92, 0xaa, 0x92, 0xaa, 0x92, 0x44, 0x38, 0x00, 0x00,
0x00, 0x00, 0xe0, 0xe0, 0xe1, 0x61, 0x61, 0x61, 0xe0, 0xe1, 0xc1, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x7f, 0x7f, 0x7f, 0x66, 0x66, 0x66, 0x67, 0x7f, 0x7d, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x11, 0x24, 0x2a, 0x24, 0x2a, 0x24, 0x2a, 0x24, 0x2a, 0x24, 0x2a, 0x24, 0x2a, 0x24, 0x2a, 0x24, 0x2a, 0x24, 0x2a, 0x24, 0x2a, 0x24, 0x2a, 0x24, 0x2a, 0x24, 0x2a, 0x24, 0x2a, 0x24, 0x2a, 0x24, 0x2a, 0x24, 0x2a, 0x24, 0x2a, 0x24, 0x2a, 0x24, 0x2a, 0x24, 0x2a, 0x24, 0x2a, 0x24, 0x2a, 0x24, 0x2a, 0x24, 0x2a, 0x24, 0x2a, 0x24, 0x2a, 0x24, 0x2a, 0x24, 0x2a, 0x24, 0x2a, 0x24, 0x2a, 0x24, 0x2a, 0x24, 0x2a, 0x24, 0x2a, 0x24, 0x2a, 0x24, 0x2a, 0x24, 0x2a, 0x24, 0x2a, 0x24, 0x2a, 0x24, 0x2a, 0x24, 0x2a, 0x24, 0x2a, 0x24, 0x2a, 0x24, 0x2a, 0x24, 0x2a, 0x24, 0x2a, 0x24, 0x2a, 0x24, 0x2a, 0x24, 0x2a, 0x24, 0x2a, 0x24, 0x2a, 0x24, 0x2a, 0x24, 0x11, 0x0e, 0x00, 0x00,
0x00, 0x00, 0xe0, 0xe0, 0x20, 0xe0, 0xc0, 0x00, 0x40, 0xc0, 0x80, 0xc0, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xc0, 0x60, 0x20, 0x60, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xc0, 0x60, 0x20, 0x60, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0xaa, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0xaa, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x2a, 0x14, 0x40, 0x20, 0x00, 0x10, 0x00, 0x10, 0x00, 0x20, 0x40, 0x00, 0x00,
0x00, 0x80, 0x87, 0x87, 0x81, 0x87, 0x86, 0x00, 0x04, 0x06, 0x03, 0x06, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0xfe, 0x03, 0x01, 0x0c, 0xfe, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0xfe, 0x03, 0x01, 0xcc, 0x66, 0x3c, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd5, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x55, 0x00, 0x00, 0x00, 0x38, 0x16, 0x38, 0x80, 0x40, 0x00, 0x20, 0x00, 0x20, 0x00, 0x40, 0x80, 0x05, 0x10, 0x20, 0x00, 0x40, 0x00, 0x40, 0x00, 0x20, 0x10, 0x05, 0x00,
0x00, 0x00, 0x00, 0x1f, 0x1f, 0x00, 0x00, 0x00, 0x11, 0x1b, 0x0e, 0x1b, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x07, 0x00, 0x03, 0x06, 0x0c, 0x19, 0x31, 0x21, 0x30, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x07, 0x00, 0x03, 0x06, 0x0c, 0x19, 0x31, 0x21, 0x30, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0xaa, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0xaa, 0x00, 0x02, 0x00, 0x02, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x20, 0x40, 0x00, 0x80, 0x00, 0x80, 0x00, 0x40, 0x20, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
/**************************
* self masked images
**************************/
const unsigned char PROGMEM button_gfx[] =
{
// width, height,
8, 8,
0x1c, 0x3e, 0x7f, 0x5f, 0x4f, 0x26, 0x1c, 0x00,
};
const unsigned char PROGMEM buttonleft_gfx[] =
{
// width, height,
8, 8,
0x7f, 0x5f, 0x5f, 0x4f, 0x6f, 0x36, 0x1c, 0x08,
};
const unsigned char PROGMEM buttonright_gfx[] =
{
// width, height,
8, 8,
0x08, 0x1c, 0x3e, 0x7f, 0x5f, 0x5f, 0x43, 0x7f,
};
const unsigned char PROGMEM buttonup_gfx[] =
{
// width, height,
8, 8,
0x1f, 0x3f, 0x7f, 0xdf, 0x67, 0x31, 0x1f, 0x00,
};
const unsigned char PROGMEM buttondown_gfx[] =
{
// width, height,
8, 8,
0xf8, 0xfc, 0xbe, 0xbf, 0xbe, 0x8c, 0xf8, 0x00,
};
const unsigned char PROGMEM off_gfx[] =
{
// width, height,
18, 8,
0x38, 0x7c, 0x44, 0x7c, 0x38, 0x00, 0x7c, 0x7c, 0x14, 0x14, 0x04, 0x00, 0x7c, 0x7c, 0x14, 0x14, 0x04, 0x00,
};
const unsigned char PROGMEM txt_on_gfx[] =
{
// width, height,
18, 8,
0x38, 0x7c, 0x44, 0x7c, 0x38, 0x00, 0x7c, 0x7c, 0x18, 0x30, 0x7c, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
const unsigned char PROGMEM on_gfx[] =
{
// width, height,
18, 8,
0x38, 0x7c, 0x44, 0x7c, 0x38, 0x00, 0x7c, 0x7c, 0x18, 0x30, 0x7c, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
const unsigned char PROGMEM sound_gfx[] =
{
// width, height,
6, 16,
0x00, 0x08, 0x0c, 0x46, 0x62, 0x20,
0x00, 0x10, 0x30, 0x62, 0x46, 0x04,
};
/**************************
* non masked images
**************************/
const unsigned char PROGMEM red_focus_gfx[] =
{
// width, height,
14, 16,
0xfe, 0xff, 0x03, 0x03, 0x03, 0x33, 0x33, 0x33, 0x33, 0x03, 0x83, 0x87, 0xfe, 0x7c,
0x1f, 0x3f, 0x30, 0x30, 0x30, 0x3f, 0x1f, 0x1e, 0x3c, 0x30, 0x30, 0x31, 0x3f, 0x1f,
};
const unsigned char PROGMEM green_focus_gfx[] =
{
// width, height,
14, 16,
0xf8, 0xfc, 0x0e, 0x07, 0x03, 0xe3, 0xf3, 0xf3, 0x63, 0x43, 0x47, 0x4e, 0xfc, 0xf8,
0x07, 0x0f, 0x1c, 0x38, 0x30, 0x31, 0x33, 0x33, 0x19, 0x30, 0x30, 0x30, 0x3f, 0x3f,
};
const unsigned char PROGMEM blue_focus_gfx[] =
{
// width, height,
14, 16,
0xfe, 0xff, 0x03, 0x03, 0x03, 0x33, 0x33, 0x33, 0x03, 0x03, 0x47, 0xfe, 0xfc, 0x80,
0x1f, 0x3f, 0x30, 0x30, 0x30, 0x33, 0x33, 0x33, 0x33, 0x30, 0x30, 0x38, 0x1f, 0x0f,
};
const unsigned char PROGMEM rxled_on_focus_gfx[] =
{
// width, height,
14, 8,
0x00, 0xff, 0x81, 0x81, 0xed, 0x81, 0x93, 0xfe, 0xba, 0x92, 0xc6, 0x92, 0xba, 0xee,
};
const unsigned char PROGMEM txled_on_focus_gfx[] =
{
// width, height,
14, 8,
0x07, 0x05, 0xfd, 0x81, 0x81, 0xfd, 0x05, 0xef, 0xba, 0x92, 0xc6, 0x92, 0xba, 0xee,
};
const unsigned char PROGMEM speaker1_on_focus_gfx[] =
{
// width, height,
14, 24,
0xe0, 0x10, 0x10, 0x10, 0xe0, 0x30, 0x98, 0xcc, 0x66, 0x32, 0xfa, 0xf2, 0x06, 0xfc,
0xff, 0x00, 0x00, 0x00, 0xff, 0x80, 0x3f, 0x7f, 0xde, 0xc0, 0xdf, 0xff, 0x00, 0xff,
0x00, 0x01, 0x01, 0x01, 0x00, 0x01, 0x03, 0x06, 0x0c, 0x09, 0x0b, 0x09, 0x0c, 0x07,
};
const unsigned char PROGMEM speaker2_on_focus_gfx[] =
{
// width, height,
14, 24,
0xe0, 0x10, 0x10, 0x10, 0xe0, 0x30, 0x98, 0xcc, 0x66, 0x32, 0x7a, 0xf2, 0x06, 0xfc,
0xff, 0x00, 0x00, 0x00, 0xff, 0x80, 0x3f, 0x7f, 0xc6, 0xd3, 0xd8, 0xff, 0x00, 0xff,
0x00, 0x01, 0x01, 0x01, 0x00, 0x01, 0x03, 0x06, 0x0c, 0x09, 0x0b, 0x09, 0x0c, 0x07,
};
const unsigned char PROGMEM slider_gfx[] =
{
// width, height,
7, 16,
0x00, 0xfc, 0xfe, 0xfa, 0x06, 0xfc, 0x00,
0x00, 0x0f, 0x1f, 0x17, 0x18, 0x0f, 0x00,
};
const unsigned char PROGMEM nospeaker_gfx[] =
{
// width, height,
12, 24,
0xe0, 0xe3, 0x1f, 0xfc, 0xe0, 0x00, 0xe0, 0xfc, 0x1f, 0x83, 0x08, 0xf8,
0xff, 0xff, 0x1f, 0xe0, 0xff, 0x1f, 0xff, 0xe0, 0x0c, 0x27, 0x00, 0xff,
0x00, 0x18, 0x1f, 0x07, 0x00, 0x00, 0x00, 0x07, 0x1f, 0x18, 0x02, 0x03,
};
#endif
|
273c1ef90f53a49d37ec5745f4ea9a371cd41d8d
|
d9ea45dbc964799991b9191ae620d2f150652a3d
|
/Sources/kinc/input/pen.h
|
d16e957ed28e085461605cde6d9a192cafd92d20
|
[
"Zlib"
] |
permissive
|
Kode/Kinc
|
6ebb1cfa11c6e9ed0e153c486f573f1d7dca5664
|
d90b7478b192c8270e0ee32c0c3ee18977becd7a
|
refs/heads/main
| 2023-08-08T16:50:01.534587
| 2023-08-07T20:22:46
| 2023-08-07T20:22:46
| 10,254,751
| 283
| 249
|
Zlib
| 2023-08-26T12:27:36
| 2013-05-23T22:22:58
|
C
|
UTF-8
|
C
| false
| false
| 5,058
|
h
|
pen.h
|
#pragma once
#include <kinc/global.h>
/*! \file pen.h
\brief Provides pen-support.
*/
#ifdef __cplusplus
extern "C" {
#endif
/// <summary>
/// Sets the pen-press-callback which is called when the pen is touching the drawing-surface.
/// </summary>
/// <param name="value">The callback</param>
KINC_FUNC void kinc_pen_set_press_callback(void (*value)(int /*window*/, int /*x*/, int /*y*/, float /*pressure*/));
/// <summary>
/// Sets the pen-move-callback which is called when the pen is moved.
/// </summary>
/// <param name="value">The callback</param>
KINC_FUNC void kinc_pen_set_move_callback(void (*value)(int /*window*/, int /*x*/, int /*y*/, float /*pressure*/));
/// <summary>
/// Sets the pen-release-callback which is called when the pen is moved away from the drawing-surface.
/// </summary>
/// <param name="value">The callback</param>
KINC_FUNC void kinc_pen_set_release_callback(void (*value)(int /*window*/, int /*x*/, int /*y*/, float /*pressure*/));
/// <summary>
/// Sets the eraser-press-callback which is called when the pen is touching the drawing-surface in eraser-mode.
/// </summary>
/// <param name="value">The callback</param>
KINC_FUNC void kinc_eraser_set_press_callback(void (*value)(int /*window*/, int /*x*/, int /*y*/, float /*pressure*/));
/// <summary>
/// Sets the eraser-move-callback which is called when the pen is moved while in eraser-mode.
/// </summary>
/// <param name="value">The callback</param>
KINC_FUNC void kinc_eraser_set_move_callback(void (*value)(int /*window*/, int /*x*/, int /*y*/, float /*pressure*/));
/// <summary>
/// Sets the eraser-release-callback which is called when the pen is moved away from the drawing-surface when in eraser-mode.
/// </summary>
/// <param name="value">The callback</param>
KINC_FUNC void kinc_eraser_set_release_callback(void (*value)(int /*window*/, int /*x*/, int /*y*/, float /*pressure*/));
void kinc_internal_pen_trigger_move(int window, int x, int y, float pressure);
void kinc_internal_pen_trigger_press(int window, int x, int y, float pressure);
void kinc_internal_pen_trigger_release(int window, int x, int y, float pressure);
void kinc_internal_eraser_trigger_move(int window, int x, int y, float pressure);
void kinc_internal_eraser_trigger_press(int window, int x, int y, float pressure);
void kinc_internal_eraser_trigger_release(int window, int x, int y, float pressure);
#ifdef KINC_IMPLEMENTATION_INPUT
#define KINC_IMPLEMENTATION
#endif
#ifdef KINC_IMPLEMENTATION
#include <memory.h>
static void (*pen_press_callback)(int /*window*/, int /*x*/, int /*y*/, float /*pressure*/) = NULL;
static void (*pen_move_callback)(int /*window*/, int /*x*/, int /*y*/, float /*pressure*/) = NULL;
static void (*pen_release_callback)(int /*window*/, int /*x*/, int /*y*/, float /*pressure*/) = NULL;
static void (*eraser_press_callback)(int /*window*/, int /*x*/, int /*y*/, float /*pressure*/) = NULL;
static void (*eraser_move_callback)(int /*window*/, int /*x*/, int /*y*/, float /*pressure*/) = NULL;
static void (*eraser_release_callback)(int /*window*/, int /*x*/, int /*y*/, float /*pressure*/) = NULL;
void kinc_pen_set_press_callback(void (*value)(int /*window*/, int /*x*/, int /*y*/, float /*pressure*/)) {
pen_press_callback = value;
}
void kinc_pen_set_move_callback(void (*value)(int /*window*/, int /*x*/, int /*y*/, float /*pressure*/)) {
pen_move_callback = value;
}
void kinc_pen_set_release_callback(void (*value)(int /*window*/, int /*x*/, int /*y*/, float /*pressure*/)) {
pen_release_callback = value;
}
void kinc_eraser_set_press_callback(void (*value)(int /*window*/, int /*x*/, int /*y*/, float /*pressure*/)) {
eraser_press_callback = value;
}
void kinc_eraser_set_move_callback(void (*value)(int /*window*/, int /*x*/, int /*y*/, float /*pressure*/)) {
eraser_move_callback = value;
}
void kinc_eraser_set_release_callback(void (*value)(int /*window*/, int /*x*/, int /*y*/, float /*pressure*/)) {
eraser_release_callback = value;
}
void kinc_internal_pen_trigger_press(int window, int x, int y, float pressure) {
if (pen_press_callback != NULL) {
pen_press_callback(window, x, y, pressure);
}
}
void kinc_internal_pen_trigger_move(int window, int x, int y, float pressure) {
if (pen_move_callback != NULL) {
pen_move_callback(window, x, y, pressure);
}
}
void kinc_internal_pen_trigger_release(int window, int x, int y, float pressure) {
if (pen_release_callback != NULL) {
pen_release_callback(window, x, y, pressure);
}
}
void kinc_internal_eraser_trigger_press(int window, int x, int y, float pressure) {
if (eraser_press_callback != NULL) {
eraser_press_callback(window, x, y, pressure);
}
}
void kinc_internal_eraser_trigger_move(int window, int x, int y, float pressure) {
if (eraser_move_callback != NULL) {
eraser_move_callback(window, x, y, pressure);
}
}
void kinc_internal_eraser_trigger_release(int window, int x, int y, float pressure) {
if (eraser_release_callback != NULL) {
eraser_release_callback(window, x, y, pressure);
}
}
#endif
#ifdef __cplusplus
}
#endif
|
19c143fde654e1f06ac5248f121f1319991b14e2
|
88ae8695987ada722184307301e221e1ba3cc2fa
|
/third_party/ffmpeg/libavcodec/mips/cabac.h
|
20ecab43207ca79094a740d4ce317386ee5af8d0
|
[
"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
| 11,187
|
h
|
cabac.h
|
/*
* Loongson SIMD optimized h264chroma
*
* Copyright (c) 2018 Loongson Technology Corporation Limited
* Contributed by Shiyou Yin <yinshiyou-hf@loongson.cn>
* Gu Xiwei(guxiwei-hf@loongson.cn)
*
* 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
*/
#ifndef AVCODEC_MIPS_CABAC_H
#define AVCODEC_MIPS_CABAC_H
#include "libavutil/attributes.h"
#include "libavcodec/cabac.h"
#include "libavutil/mips/mmiutils.h"
#include "config.h"
#if !HAVE_MIPS32R6 && !HAVE_MIPS64R6
#define get_cabac_inline get_cabac_inline_mips
static av_always_inline int get_cabac_inline_mips(CABACContext *c,
uint8_t * const state){
mips_reg tmp0, tmp1, tmp2, bit;
__asm__ volatile (
"lbu %[bit], 0(%[state]) \n\t"
"and %[tmp0], %[c_range], 0xC0 \n\t"
PTR_SLL "%[tmp0], %[tmp0], 0x01 \n\t"
PTR_ADDU "%[tmp0], %[tmp0], %[tables] \n\t"
PTR_ADDU "%[tmp0], %[tmp0], %[bit] \n\t"
/* tmp1: RangeLPS */
"lbu %[tmp1], %[lps_off](%[tmp0]) \n\t"
PTR_SUBU "%[c_range], %[c_range], %[tmp1] \n\t"
PTR_SLL "%[tmp0], %[c_range], 0x11 \n\t"
"slt %[tmp2], %[tmp0], %[c_low] \n\t"
"beqz %[tmp2], 1f \n\t"
"move %[c_range], %[tmp1] \n\t"
"not %[bit], %[bit] \n\t"
PTR_SUBU "%[c_low], %[c_low], %[tmp0] \n\t"
"1: \n\t"
/* tmp1: *state */
PTR_ADDU "%[tmp0], %[tables], %[bit] \n\t"
"lbu %[tmp1], %[mlps_off](%[tmp0]) \n\t"
/* tmp2: lps_mask */
PTR_ADDU "%[tmp0], %[tables], %[c_range] \n\t"
"lbu %[tmp2], %[norm_off](%[tmp0]) \n\t"
"sb %[tmp1], 0(%[state]) \n\t"
"and %[bit], %[bit], 0x01 \n\t"
PTR_SLL "%[c_range], %[c_range], %[tmp2] \n\t"
PTR_SLL "%[c_low], %[c_low], %[tmp2] \n\t"
"and %[tmp1], %[c_low], %[cabac_mask] \n\t"
"bnez %[tmp1], 1f \n\t"
PTR_ADDIU "%[tmp0], %[c_low], -0X01 \n\t"
"xor %[tmp0], %[c_low], %[tmp0] \n\t"
PTR_SRA "%[tmp0], %[tmp0], 0x0f \n\t"
PTR_ADDU "%[tmp0], %[tmp0], %[tables] \n\t"
/* tmp2: ff_h264_norm_shift[x >> (CABAC_BITS - 1)] */
"lbu %[tmp2], %[norm_off](%[tmp0]) \n\t"
#if HAVE_BIGENDIAN
"lhu %[tmp0], 0(%[c_bytestream]) \n\t"
#else
"lhu %[tmp0], 0(%[c_bytestream]) \n\t"
#if HAVE_MIPS32R2 || HAVE_MIPS64R2
"wsbh %[tmp0], %[tmp0] \n\t"
#else
"and %[tmp1], %[tmp0], 0xff00ff00 \n\t"
"srl %[tmp1], %[tmp1], 8 \n\t"
"and %[tmp0], %[tmp0], 0x00ff00ff \n\t"
"sll %[tmp0], %[tmp0], 8 \n\t"
"or %[tmp0], %[tmp0], %[tmp1] \n\t"
#endif
#endif
PTR_SLL "%[tmp0], %[tmp0], 0x01 \n\t"
PTR_SUBU "%[tmp0], %[tmp0], %[cabac_mask] \n\t"
"li %[tmp1], 0x07 \n\t"
PTR_SUBU "%[tmp1], %[tmp1], %[tmp2] \n\t"
PTR_SLL "%[tmp0], %[tmp0], %[tmp1] \n\t"
PTR_ADDU "%[c_low], %[c_low], %[tmp0] \n\t"
#if UNCHECKED_BITSTREAM_READER
PTR_ADDIU "%[c_bytestream], %[c_bytestream], 0x02 \n\t"
#else
"slt %[tmp0], %[c_bytestream], %[c_bytestream_end] \n\t"
PTR_ADDIU "%[tmp2], %[c_bytestream], 0x02 \n\t"
"movn %[c_bytestream], %[tmp2], %[tmp0] \n\t"
#endif
"1: \n\t"
: [bit]"=&r"(bit), [tmp0]"=&r"(tmp0), [tmp1]"=&r"(tmp1), [tmp2]"=&r"(tmp2),
[c_range]"+&r"(c->range), [c_low]"+&r"(c->low),
[c_bytestream]"+&r"(c->bytestream)
: [state]"r"(state), [tables]"r"(ff_h264_cabac_tables),
#if !UNCHECKED_BITSTREAM_READER
[c_bytestream_end]"r"(c->bytestream_end),
#endif
[lps_off]"i"(H264_LPS_RANGE_OFFSET),
[mlps_off]"i"(H264_MLPS_STATE_OFFSET + 128),
[norm_off]"i"(H264_NORM_SHIFT_OFFSET),
[cabac_mask]"r"(CABAC_MASK)
: "memory"
);
return bit;
}
#define get_cabac_bypass get_cabac_bypass_mips
static av_always_inline int get_cabac_bypass_mips(CABACContext *c)
{
mips_reg tmp0, tmp1;
int res = 0;
__asm__ volatile(
PTR_SLL "%[c_low], %[c_low], 0x01 \n\t"
"and %[tmp0], %[c_low], %[cabac_mask] \n\t"
"bnez %[tmp0], 1f \n\t"
#if HAVE_BIGENDIAN
"lhu %[tmp1], 0(%[c_bytestream]) \n\t"
#else
"lhu %[tmp1], 0(%[c_bytestream]) \n\t"
#if HAVE_MIPS32R2 || HAVE_MIPS64R2
"wsbh %[tmp1], %[tmp1] \n\t"
#else
"and %[tmp0], %[tmp1], 0xff00ff00 \n\t"
"srl %[tmp0], %[tmp0], 8 \n\t"
"and %[tmp1], %[tmp1], 0x00ff00ff \n\t"
"sll %[tmp1], %[tmp1], 8 \n\t"
"or %[tmp1], %[tmp1], %[tmp0] \n\t"
#endif
#endif
PTR_SLL "%[tmp1], %[tmp1], 0x01 \n\t"
PTR_SUBU "%[tmp1], %[tmp1], %[cabac_mask] \n\t"
PTR_ADDU "%[c_low], %[c_low], %[tmp1] \n\t"
#if UNCHECKED_BITSTREAM_READER
PTR_ADDIU "%[c_bytestream], %[c_bytestream], 0x02 \n\t"
#else
"slt %[tmp0], %[c_bytestream], %[c_bytestream_end] \n\t"
PTR_ADDIU "%[tmp1], %[c_bytestream], 0x02 \n\t"
"movn %[c_bytestream], %[tmp1], %[tmp0] \n\t"
#endif
"1: \n\t"
PTR_SLL "%[tmp1], %[c_range], 0x11 \n\t"
"slt %[tmp0], %[c_low], %[tmp1] \n\t"
PTR_SUBU "%[tmp1], %[c_low], %[tmp1] \n\t"
"movz %[res], %[one], %[tmp0] \n\t"
"movz %[c_low], %[tmp1], %[tmp0] \n\t"
: [tmp0]"=&r"(tmp0), [tmp1]"=&r"(tmp1), [res]"+&r"(res),
[c_range]"+&r"(c->range), [c_low]"+&r"(c->low),
[c_bytestream]"+&r"(c->bytestream)
: [cabac_mask]"r"(CABAC_MASK),
#if !UNCHECKED_BITSTREAM_READER
[c_bytestream_end]"r"(c->bytestream_end),
#endif
[one]"r"(0x01)
: "memory"
);
return res;
}
#define get_cabac_bypass_sign get_cabac_bypass_sign_mips
static av_always_inline int get_cabac_bypass_sign_mips(CABACContext *c, int val)
{
mips_reg tmp0, tmp1;
int res = val;
__asm__ volatile(
PTR_SLL "%[c_low], %[c_low], 0x01 \n\t"
"and %[tmp0], %[c_low], %[cabac_mask] \n\t"
"bnez %[tmp0], 1f \n\t"
#if HAVE_BIGENDIAN
"lhu %[tmp1], 0(%[c_bytestream]) \n\t"
#else
"lhu %[tmp1], 0(%[c_bytestream]) \n\t"
#if HAVE_MIPS32R2 || HAVE_MIPS64R2
"wsbh %[tmp1], %[tmp1] \n\t"
#else
"and %[tmp0], %[tmp1], 0xff00ff00 \n\t"
"srl %[tmp0], %[tmp0], 8 \n\t"
"and %[tmp1], %[tmp1], 0x00ff00ff \n\t"
"sll %[tmp1], %[tmp1], 8 \n\t"
"or %[tmp1], %[tmp1], %[tmp0] \n\t"
#endif
#endif
PTR_SLL "%[tmp1], %[tmp1], 0x01 \n\t"
PTR_SUBU "%[tmp1], %[tmp1], %[cabac_mask] \n\t"
PTR_ADDU "%[c_low], %[c_low], %[tmp1] \n\t"
#if UNCHECKED_BITSTREAM_READER
PTR_ADDIU "%[c_bytestream], %[c_bytestream], 0x02 \n\t"
#else
"slt %[tmp0], %[c_bytestream], %[c_bytestream_end] \n\t"
PTR_ADDIU "%[tmp1], %[c_bytestream], 0x02 \n\t"
"movn %[c_bytestream], %[tmp1], %[tmp0] \n\t"
#endif
"1: \n\t"
PTR_SLL "%[tmp1], %[c_range], 0x11 \n\t"
"slt %[tmp0], %[c_low], %[tmp1] \n\t"
PTR_SUBU "%[tmp1], %[c_low], %[tmp1] \n\t"
"movz %[c_low], %[tmp1], %[tmp0] \n\t"
PTR_SUBU "%[tmp1], %[zero], %[res] \n\t"
"movn %[res], %[tmp1], %[tmp0] \n\t"
: [tmp0]"=&r"(tmp0), [tmp1]"=&r"(tmp1), [res]"+&r"(res),
[c_range]"+&r"(c->range), [c_low]"+&r"(c->low),
[c_bytestream]"+&r"(c->bytestream)
: [cabac_mask]"r"(CABAC_MASK),
#if !UNCHECKED_BITSTREAM_READER
[c_bytestream_end]"r"(c->bytestream_end),
#endif
[zero]"r"(0x0)
: "memory"
);
return res;
}
#endif /* !HAVE_MIPS32R6 && !HAVE_MIPS64R6 */
#endif /* AVCODEC_MIPS_CABAC_H */
|
90c2537809de96638ce76ecc3268137554593509
|
aa3befea459382dc5c01c925653d54f435b3fb0f
|
/boards/xtensa/esp32/esp32-wrover-kit/src/esp32_autoleds.c
|
ef658a70351f6571e29e6c81e8073a145c317389
|
[
"MIT-open-group",
"BSD-3-Clause",
"HPND-sell-variant",
"BSD-4-Clause-UC",
"LicenseRef-scancode-warranty-disclaimer",
"MIT-0",
"LicenseRef-scancode-bsd-atmel",
"LicenseRef-scancode-gary-s-brown",
"LicenseRef-scancode-proprietary-license",
"SunPro",
"MIT",
"LicenseRef-scancode-public-domain-disclaimer",
"LicenseRef-scancode-other-permissive",
"HPND",
"ISC",
"Apache-2.0",
"LicenseRef-scancode-public-domain",
"BSD-2-Clause",
"GPL-1.0-or-later",
"CC-BY-2.0",
"CC-BY-4.0"
] |
permissive
|
apache/nuttx
|
14519a7bff4a87935d94fb8fb2b19edb501c7cec
|
606b6d9310fb25c7d92c6f95bf61737e3c79fa0f
|
refs/heads/master
| 2023-08-25T06:55:45.822534
| 2023-08-23T16:03:31
| 2023-08-24T21:25:47
| 228,103,273
| 407
| 241
|
Apache-2.0
| 2023-09-14T18:26:05
| 2019-12-14T23:27:55
|
C
|
UTF-8
|
C
| false
| false
| 5,424
|
c
|
esp32_autoleds.c
|
/****************************************************************************
* boards/xtensa/esp32/esp32-wrover-kit/src/esp32_autoleds.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.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdint.h>
#include <stdbool.h>
#include <debug.h>
#include <nuttx/board.h>
#include <arch/board/board.h>
#include "esp32_gpio.h"
#include "esp32-wrover-kit.h"
#ifdef CONFIG_ARCH_LEDS
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* The following definitions map the encoded LED setting to GPIO settings */
#ifndef CONFIG_ARCH_LEDS_CPU_ACTIVITY
# define LED_STARTED_BITS (BOARD_LED2_BIT)
# define LED_HEAPALLOCATE_BITS (BOARD_LED3_BIT)
# define LED_IRQSENABLED_BITS (BOARD_LED3_BIT | BOARD_LED2_BIT)
# define LED_STACKCREATED_BITS (BOARD_LED3_BIT)
# define LED_INIRQ_BITS (BOARD_LED1_BIT | BOARD_LED3_BIT)
# define LED_SIGNAL_BITS (BOARD_LED2_BIT | BOARD_LED3_BIT)
# define LED_ASSERTION_BITS (BOARD_LED1_BIT | BOARD_LED2_BIT |\
BOARD_LED3_BIT)
# define LED_PANIC_BITS (BOARD_LED1_BIT)
#endif
/****************************************************************************
* Private Data
****************************************************************************/
#ifndef CONFIG_ARCH_LEDS_CPU_ACTIVITY
static const unsigned int g_ledbits[8] =
{
LED_STARTED_BITS,
LED_HEAPALLOCATE_BITS,
LED_IRQSENABLED_BITS,
LED_STACKCREATED_BITS,
LED_INIRQ_BITS,
LED_SIGNAL_BITS,
LED_ASSERTION_BITS,
LED_PANIC_BITS
};
#endif
/****************************************************************************
* Private Functions
****************************************************************************/
static inline void led_clrbits(unsigned int clrbits)
{
if ((clrbits & BOARD_LED1_BIT) != 0)
{
esp32_gpiowrite(GPIO_LED1, false);
}
if ((clrbits & BOARD_LED2_BIT) != 0)
{
esp32_gpiowrite(GPIO_LED2, false);
}
if ((clrbits & BOARD_LED3_BIT) != 0)
{
esp32_gpiowrite(GPIO_LED3, false);
}
}
static inline void led_setbits(unsigned int setbits)
{
if ((setbits & BOARD_LED1_BIT) != 0)
{
esp32_gpiowrite(GPIO_LED1, true);
}
if ((setbits & BOARD_LED2_BIT) != 0)
{
esp32_gpiowrite(GPIO_LED2, true);
}
if ((setbits & BOARD_LED3_BIT) != 0)
{
esp32_gpiowrite(GPIO_LED3, true);
}
}
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: board_autoled_initialize
****************************************************************************/
void board_autoled_initialize(void)
{
/* Configure LED1-4 GPIOs for output */
esp32_configgpio(GPIO_LED1, OUTPUT);
esp32_configgpio(GPIO_LED2, OUTPUT);
esp32_configgpio(GPIO_LED3, OUTPUT);
}
/****************************************************************************
* Name: board_autoled_on
****************************************************************************/
void board_autoled_on(int led)
{
#ifdef CONFIG_ARCH_LEDS_CPU_ACTIVITY
switch (led)
{
case LED_CPU0:
esp32_gpiowrite(GPIO_LED1, true);
break;
case LED_CPU1:
esp32_gpiowrite(GPIO_LED2, true);
break;
case LED_HEAPALLOCATE:
esp32_gpiowrite(GPIO_LED3, true);
break;
default:
break;
}
#else
led_clrbits(BOARD_LED1_BIT | BOARD_LED2_BIT | BOARD_LED3_BIT);
led_setbits(g_ledbits[led]);
#endif
}
/****************************************************************************
* Name: board_autoled_off
****************************************************************************/
void board_autoled_off(int led)
{
#ifdef CONFIG_ARCH_LEDS_CPU_ACTIVITY
switch (led)
{
case LED_CPU0:
esp32_gpiowrite(GPIO_LED1, false);
break;
case LED_CPU1:
esp32_gpiowrite(GPIO_LED2, false);
break;
case LED_HEAPALLOCATE:
esp32_gpiowrite(GPIO_LED3, false);
break;
default:
break;
}
#else
led_clrbits(g_ledbits[led]);
#endif
}
#endif /* CONFIG_ARCH_LEDS */
|
060b932cd14a58021abdca09a81ae4fa923bd743
|
290c96ec464bc49084696b1df71c088ddcc9ffff
|
/modules/iopcore/cdvdman/internal.h
|
f64292a0dabe2909d46b013f0de7d02f877789ae
|
[
"AFL-3.0"
] |
permissive
|
ps2homebrew/Open-PS2-Loader
|
c23cce4e8b6d08bdc4b229da9bcb7c9bd31fc255
|
9e12706ef5ac0f4a3b72fe5860c1e38d2e94e151
|
refs/heads/master
| 2023-08-14T21:37:43.222099
| 2023-08-14T18:18:19
| 2023-08-14T18:18:19
| 70,989,832
| 1,378
| 262
|
AFL-3.0
| 2023-08-19T21:20:14
| 2016-10-15T13:37:16
|
C
|
UTF-8
|
C
| false
| false
| 3,494
|
h
|
internal.h
|
#ifndef __CDVDMAN_INTERNAL__
#define __CDVDMAN_INTERNAL__
#include "dev9.h"
#include "oplsmb.h"
#include "smb.h"
#include "atad.h"
#include "ioplib_util.h"
#include "cdvdman_opl.h"
#include "cdvd_config.h"
#include "device.h"
#include <loadcore.h>
#include <stdio.h>
#include <sifman.h>
#include <sysclib.h>
#include <sysmem.h>
#include <thbase.h>
#include <thevent.h>
#include <intrman.h>
#include <ioman.h>
#include <thsemap.h>
#include <errno.h>
#include <io_common.h>
#include <usbd.h>
#include <cdvdman.h>
#include "ioman_add.h"
#include <defs.h>
#include "smsutils.h"
#ifdef __IOPCORE_DEBUG
#define DPRINTF(args...) printf(args)
#define iDPRINTF(args...) Kprintf(args)
#else
#define DPRINTF(args...)
#define iDPRINTF(args...)
#endif
#ifdef HDD_DRIVER
#define CDVDMAN_SETTINGS_TYPE cdvdman_settings_hdd
#define CDVDMAN_SETTINGS_DEFAULT_DEVICE_SETTINGS CDVDMAN_SETTINGS_DEFAULT_HDD,
#elif SMB_DRIVER
#define CDVDMAN_SETTINGS_TYPE cdvdman_settings_smb
#define CDVDMAN_SETTINGS_DEFAULT_DEVICE_SETTINGS CDVDMAN_SETTINGS_DEFAULT_SMB,
#elif BDM_DRIVER
#define CDVDMAN_SETTINGS_TYPE cdvdman_settings_bdm
#define CDVDMAN_SETTINGS_DEFAULT_DEVICE_SETTINGS
#else
#error Unknown driver type. Please check the Makefile.
#endif
#define btoi(b) ((b) / 16 * 10 + (b) % 16) /* BCD to u_char */
#define itob(i) ((i) / 10 * 16 + (i) % 10) /* u_char to BCD */
struct SteamingData
{
unsigned short int StBufmax;
unsigned short int StBankmax;
unsigned short int StBanksize;
unsigned short int StWritePtr;
unsigned short int StReadPtr;
unsigned short int StStreamed;
unsigned short int StStat;
unsigned short int StIsReading;
void *StIOP_bufaddr;
u32 Stlsn;
};
typedef struct
{
int err;
u8 status; // SCECdvdDriveState
struct SteamingData StreamingData;
int intr_ef;
int disc_type_reg; // SCECdvdMediaType
u32 cdread_lba;
u32 cdread_sectors;
u16 sector_size;
void *cdread_buf;
} cdvdman_status_t;
struct dirTocEntry
{
short length;
u32 fileLBA; // 2
u32 fileLBA_bigend; // 6
u32 fileSize; // 10
u32 fileSize_bigend; // 14
u8 dateStamp[6]; // 18
u8 reserved1; // 24
u8 fileProperties; // 25
u8 reserved2[6]; // 26
u8 filenameLength; // 32
char filename[128]; // 33
} __attribute__((packed));
typedef void (*StmCallback_t)(void);
// Internal (common) function prototypes
extern void SetStm0Callback(StmCallback_t callback);
extern int cdvdman_AsyncRead(u32 lsn, u32 sectors, u16 sector_size, void *buf);
extern int cdvdman_SyncRead(u32 lsn, u32 sectors, u16 sector_size, void *buf);
extern int cdvdman_sendSCmd(u8 cmd, const void *in, u16 in_size, void *out, u16 out_size);
extern void cdvdman_cb_event(int reason);
extern void cdvdman_init(void);
extern void cdvdman_fs_init(void);
extern void cdvdman_searchfile_init(void);
extern void cdvdman_initdev(void);
extern struct CDVDMAN_SETTINGS_TYPE cdvdman_settings;
#ifdef HDD_DRIVER
// HDD driver also uses this buffer, for aligning unaligned reads.
#define CDVDMAN_BUF_SECTORS 2
#else
// Normally this buffer is only used by 'searchfile', only 1 sector used
#define CDVDMAN_BUF_SECTORS 1
#endif
extern u8 cdvdman_buf[CDVDMAN_BUF_SECTORS * 2048];
extern int cdrom_io_sema;
extern int cdvdman_searchfilesema;
extern cdvdman_status_t cdvdman_stat;
extern unsigned char sync_flag;
extern unsigned char cdvdman_cdinited;
extern u32 mediaLsnCount;
#endif
|
82caecdbb328cec60d594e755964c065525c452a
|
4ba76056c744ada0a01fb27b7cad8464cefc7aa0
|
/supports/toolchains/LiveEditor/PainterEngine_Startup.h
|
5c31d99ebc1efae835b12e9cda7892350b4114ed
|
[
"BSD-3-Clause"
] |
permissive
|
matrixcascade/PainterEngine
|
23e110e25a39e1d016ed7936eac23e06932456b4
|
1d3e6e85f337e8a8db44680094ab3f4b988507cb
|
refs/heads/master
| 2023-08-29T11:29:26.934779
| 2023-08-23T09:23:04
| 2023-08-23T09:23:04
| 190,119,926
| 1,989
| 253
|
BSD-3-Clause
| 2023-09-05T12:19:31
| 2019-06-04T03:08:26
|
C
|
UTF-8
|
C
| false
| false
| 2,084
|
h
|
PainterEngine_Startup.h
|
#ifndef PAINTERENGINE_STARTUP_H
#define PAINTERENGINE_STARTUP_H
//////////////////////////////////////////////////////////////////////////
//Configures
#include "platform/modules/px_file.h"
#define PX_APPLICATION_NAME "PainterEngine LiveFramework Editor"
#define PX_APPLICATION_SURFACE_SIZE 800
#define PX_APPLICATION_MEMORYPOOL_UI_SIZE 1024*1024*16
#define PX_APPLICATION_MEMORYPOOL_RESOURCES_SIZE 1024*1024*96
#define PX_APPLICATION_MEMORYPOOL_GAME_SIZE 1024*1024*8
#define PX_APPLICATION_MEMORYPOOL_SPACE_SIZE 1024*1024*8
//////////////////////////////////////////////////////////////////////////
#include "architecture/PainterEngine_Runtime.h"
px_bool PX_ApplicationInitializeDefault(PX_Runtime *runtime, px_int screen_width, px_int screen_height);
px_void PX_ApplicationEventDefault(PX_Runtime *runtime,PX_Object_Event e);
#ifdef PAINTERENGINE_FILE_H
px_bool PX_LoadTextureFromFile(px_memorypool *mp,px_texture *tex,const px_char path[]);
px_bool PX_LoadShapeFromFile(px_memorypool *mp,px_shape *shape,const px_char path[]);
px_bool PX_LoadSoundFromFile(px_memorypool *mp,px_shape *shape,const px_char path[]);
px_bool PX_LoadAnimationLibraryFromFile(px_memorypool *mp,PX_AnimationLibrary *lib,const px_char path[]);
px_bool PX_LoadScriptFromFile(px_memory *code,const px_char path[]);
px_bool PX_LoadScriptInstanceFromFile(px_memorypool *mp,PX_VM *ins,const px_char path[]);
px_bool PX_LoadTextureToResource(PX_ResourceLibrary *presourcelib,const px_char Path[],const px_char key[]);
px_bool PX_LoadShapeToResource(PX_ResourceLibrary *presourcelib,const px_char Path[],const px_char key[]);
px_bool PX_LoadAnimationToResource(PX_ResourceLibrary *presourcelib,const px_char Path[],const px_char key[]);
px_bool PX_LoadScriptToResource(PX_ResourceLibrary *presourcelib,const px_char Path[],const px_char key[]);
px_bool PX_LoadSoundToResource(PX_ResourceLibrary *presourcelib,const px_char Path[],const px_char key[]);
px_bool PX_LoadFontModuleFromFile(PX_FontModule *fm,const px_char Path[]);
px_bool PX_LoadJsonFromFile(PX_Json *json,const px_char *path);
#endif
#endif
|
47bc1bf0f73df1ae33733cd3d372f25013848baf
|
248f9d022d678a8e12e84b9ed004d1f544b1962d
|
/include/os_nvm.h
|
b5d550aa080b3c90bc0aaf6e3cc514d762b45ace
|
[
"Apache-2.0"
] |
permissive
|
LedgerHQ/nanos-secure-sdk
|
09893a7ed38adb1d814bec75216f6dc137e212e8
|
12e5f6f875bf5deb9464b944f50079aaca1a3b98
|
refs/heads/master
| 2023-09-04T10:38:06.237940
| 2023-09-01T11:37:06
| 2023-09-01T11:37:06
| 64,407,069
| 102
| 69
|
Apache-2.0
| 2023-06-28T07:13:03
| 2016-07-28T15:30:40
|
C
|
UTF-8
|
C
| false
| false
| 1,420
|
h
|
os_nvm.h
|
#pragma once
#include "bolos_target.h"
#include "decorators.h"
#if defined(ST31)
#define NVM_ERASED_WORD_VALUE 0xFFFFFFFFUL
#elif defined(ST33)
#define NVM_ERASED_WORD_VALUE 0xFFFFFFFF
#endif
// write in persistent memory, to make things easy keep a layout of the memory
// in a structure and update fields upon needs The function throws exception
// when the requesting application buffer being written in its declared data
// segment. The later is declared during the application slot allocation (using
// --dataSize parameter in the python scripts) NOTE: accept copy from far memory
// to another far memory.
// @param src_adr NULL to fill with 00's
SYSCALL void nvm_write(void *dst_adr PLENGTH(src_len),
void *src_adr PLENGTH(src_len), unsigned int src_len);
SYSCALL void nvm_erase(void *dst_adr PLENGTH(len), unsigned int len);
// program a page with the content of the nvm_page_buffer, only callable by the
// privileged APIs HAL for the high level NVM management functions
SUDOCALL void nvm_write_page(unsigned int page_adr);
// erase a nvm page at given address, only callable by the privileged APIs
SUDOCALL void nvm_erase_page(unsigned int page_adr);
// any application can wipe the global pin, global seed, user's keys
// disabled for security reasons // SYSCALL void os_perso_wipe(void);
// erase seed, settings AND applications
SYSCALL void os_perso_erase_all(void);
|
bf6980e4da579b89a54ea75bb00752ce14e3b117
|
d61b532db0d3e08818338cfaac530a1ced1ffe3b
|
/util/ceg/defaults/pseudo/C_insertpart.c
|
50331be03f4623564d33ff181dde0e1a61e2684c
|
[
"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
| 543
|
c
|
C_insertpart.c
|
#define CODE_EXPANDER
#include <em.h>
#include "back.h"
void
C_insertpart( d)
int d;
{
char *s;
swtxt();
C_jump(extnd_part( d));
symbol_definition( s = extnd_cont( d));
set_local_visible( s);
}
void
C_beginpart( d)
int d;
{
char *s;
swtxt();
C_jump(extnd_main( d));
symbol_definition(s = extnd_part( d));
set_local_visible(s);
}
void
C_endpart( d)
int d;
{
char *s;
swtxt();
C_jump(extnd_cont( d));
symbol_definition(s = extnd_main( d));
set_local_visible(s);
}
int
C_getid()
{
static int id = 0;
return ++id;
}
|
765cb67c31761eca093f0db70f7b7c44c3c662cc
|
f79dec3c4033ca3cbb55d8a51a748cc7b8b6fbab
|
/games/boson/patches/patch-boson_bo3dsload.h
|
a9eaf57e5bf463d13e36d2a654e6acbe72f8f27a
|
[] |
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
| 813
|
h
|
patch-boson_bo3dsload.h
|
$NetBSD: patch-boson_bo3dsload.h,v 1.1 2011/12/20 10:35:09 wiz Exp $
Avoid duplicate name in declaration.
--- boson/bo3dsload.h.orig 2003-01-07 07:20:47.000000000 +0000
+++ boson/bo3dsload.h
@@ -86,9 +86,9 @@ protected:
void loadFrame(int frame);
void countNodes(Lib3dsNode* node, int* count);
void loadFrameNode(BoFrame* frame, int* index, Lib3dsNode* node);
- void loadVertices(BoMesh* mesh, Lib3dsMesh* mesh);
- void loadTexels(BoMesh* mesh, Lib3dsMesh* mesh, Lib3dsMaterial* material);
- void loadFaces(BoMesh* mesh, Lib3dsMesh* mesh);
+ void loadVertices(BoMesh* bomesh, Lib3dsMesh* mesh);
+ void loadTexels(BoMesh* bomesh, Lib3dsMesh* mesh, Lib3dsMaterial* material);
+ void loadFaces(BoMesh* bomesh, Lib3dsMesh* mesh);
/**
* Render the specified node according to the values for the current
|
cc376c5e008c3c07f7d25a806a21cb2b4dc99dc6
|
9907672fcd81ab73ac63b2a83422a82bf31eadde
|
/tyama_icpc2014dpB(aizu2583-kcs1013B).c
|
6c4f42dc314d12588979f732fb2e8ae6bf824c31
|
[
"0BSD"
] |
permissive
|
cielavenir/procon
|
bbe1974b9bddb51b76d58722a0686a5b477c4456
|
746e1a91f574f20647e8aaaac0d9e6173f741176
|
refs/heads/master
| 2023-06-21T23:11:24.562546
| 2023-06-11T13:15:15
| 2023-06-11T13:15:15
| 7,557,464
| 137
| 136
| null | 2020-10-20T09:35:52
| 2013-01-11T09:40:26
|
C++
|
UTF-8
|
C
| false
| false
| 655
|
c
|
tyama_icpc2014dpB(aizu2583-kcs1013B).c
|
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define LINE 1100
char M[1001][LINE];
char* myfgets(char *b,int n,FILE *f){
char *r=fgets(b,n,f);
if(!r)return NULL;
if(b[strlen(b)-1]=='\n')b[strlen(b)-1]=0;
if(b[strlen(b)-1]=='\r')b[strlen(b)-1]=0;
return r;
}
int main(){
int n,i,j,k;
for(;myfgets(*M,LINE,stdin),n=strtol(*M,NULL,10);){
memset(M,0,sizeof(M));
for(i=0;i<n;i++)myfgets(M[i],LINE,stdin);
for(i=0;i<n;i++){
for(j=0;M[i][j]=='.';j++)M[i][j]=' ';
if(j)M[i][j-1]='+';
}
for(i=n-1;i;i--){
for(j=0;M[i][j]!='+';j++);
for(k=i-1;M[k][j]==' ';k--)M[k][j]='|';
}
for(i=0;i<n;i++)puts(M[i]);
}
return 0;
}
|
fd3b8ebdb55e6348b11e8f99d910afd3dcc7c986
|
03b2c80dbc41e904b167d504666e27d798da5447
|
/develop/windows/windows_screen.c
|
a1080863eaa458942c8bab14063cb26b78e7ce74
|
[
"Unlicense"
] |
permissive
|
nptcl/npt
|
7c1570b497cdce0b8971cb445fbc04cb500232d3
|
aa714a2370ac9fa5348c2fc96159b40b9de3de07
|
refs/heads/master
| 2023-03-20T09:13:54.669118
| 2022-07-02T11:17:44
| 2022-07-02T11:17:44
| 171,985,905
| 160
| 12
|
Unlicense
| 2023-03-11T01:36:37
| 2019-02-22T03:11:34
|
C
|
UTF-8
|
C
| false
| false
| 1,687
|
c
|
windows_screen.c
|
#include "windows_screen.h"
#include "terme_arch.h"
#include "typedef.h"
#include <Windows.h>
int Window_Mode;
int Window_Exit;
int Window_Update;
unsigned Window_SizeX;
unsigned Window_SizeY;
unsigned Window_CursorX;
unsigned Window_CursorY;
static CRITICAL_SECTION Windows_Lock;
COLORREF Window_Color1_Default;
COLORREF Window_Color2_Default;
COLORREF Window_Color1;
COLORREF Window_Color2;
void windows_screen_init(void)
{
Window_Mode = 0;
Window_Exit = 0;
Window_Update = 0;
Window_SizeX = 80;
Window_SizeY = 24;
Window_CursorX = 0;
Window_CursorY = 0;
terme_arch_size_update();
cleartype(Windows_Lock);
Window_Color1_Default = RGB(0xFF, 0xFF, 0xFF);
Window_Color2_Default = RGB(0x00, 0x00, 0x00);
Window_Color1 = Window_Color1_Default;
Window_Color2 = Window_Color2_Default;
}
void windows_screen_begin(void)
{
Window_Mode = 0;
}
void windows_screen_end(void)
{
Window_Mode = 0;
}
void windows_screen_textmode(void)
{
windows_screen_enter();
Window_Mode = 0;
windows_screen_leave();
}
void windows_screen_rawmode(void)
{
windows_screen_enter();
Window_Mode = 1;
windows_screen_leave();
}
int windows_screen_getmode(void)
{
int value;
windows_screen_enter();
value = Window_Mode;
windows_screen_leave();
return value;
}
void windows_screen_setmode(int mode)
{
windows_screen_enter();
Window_Mode = mode;
windows_screen_leave();
}
void windows_screen_lock_init(void)
{
InitializeCriticalSection(&Windows_Lock);
}
void windows_screen_lock_free(void)
{
DeleteCriticalSection(&Windows_Lock);
}
void windows_screen_enter(void)
{
EnterCriticalSection(&Windows_Lock);
}
void windows_screen_leave(void)
{
LeaveCriticalSection(&Windows_Lock);
}
|
3b1f41e0f8d11af676333d600ec40ead3505fb96
|
d61b532db0d3e08818338cfaac530a1ced1ffe3b
|
/util/ego/share/show.c
|
f709a62b73a4f7a9c07145b4840a71c9eca5426a
|
[
"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
| 7,151
|
c
|
show.c
|
/* $Id$ */
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
/* S H O W . C */
/* This program can be used to make the output of the 'cf' pass
* human readable. It will display either the procedure table,
* the datablock table, the basic block table or the EM text,
* depending on the flag that is passed as first argument.
*/
#include <stdio.h>
#include <em_spec.h>
#include <em_pseu.h>
#include "types.h"
#include "def.h"
#include "global.h"
#define BMASK 0377
#define space1() printf(" ")
char format[] = " %-11s%d\n";
char lformat[] = " %-11s%ld\n";
char sformat[] = " %-10s%s\n";
char dformat[] = " %-11s%d\n";
char oformat[] = " %-11s%ld\n";
FILE *f; /* input file */
#define getbyte() getc(f)
short getshort()
{
register n;
n = getbyte();
n |= getbyte() << 8;
return n;
}
offset getoff()
{
register offset n;
n = getshort() & 0xFFFF;
n |= ((offset) getshort() ) << 16;
return n;
}
int getint()
{
/* Read an integer from the input file. This routine is
* only used when reading a bitvector-set. We expect an
* integer to be either a short or a long.
*/
if (sizeof(int) == sizeof(short)) {
return getshort();
} else {
return getoff();
}
}
/* VARARGS 1 */
error(s,a) char *s,*a; {
fprintf(stderr,"error");
fprintf(stderr,": ");
fprintf(stderr,s,a);
fprintf(stderr,"\n");
exit(-1);
}
main(argc, argv)
int argc;
char *argv[];
{
if (argc != 3 || argv[1][0] != '-') {
error("usage: %s -[ldpbc] filename",argv[0]);
}
if ((f = fopen(argv[2], "rb")) == NULL) {
error("cannot open %s", argv[2]);
}
switch(argv[1][1]) {
case 'l':
showl();
break;
case 'd':
showd();
break;
case 'p':
showp();
break;
case 'b':
showb();
break;
case 'c':
showc();
break;
default:
error("bad flag");
}
fclose(f);
exit(0);
}
showcset()
{
/* print a compact (bitvector) set */
short size;
register short i,j;
int w, mask;
size = getshort();
/* # significant bits in bitvector */
i = 1;
printf(" { ");
if (size == 0) {
printf("}\n");
return;
}
for (;;) {
w = getint();
mask = 1 ;
for (j = 1; j <= sizeof(int)*8; j++) {
if (w & mask) {
printf("%d ",i);
}
if (i++ == size) {
printf ("}\n");
return;
}
mask <<= 1;
}
}
}
showp()
{
byte b;
short n;
short all;
printf("total number of procs: %d\n\n",getshort());
all = getshort();
while (TRUE) {
n = getshort();
if (feof(f)) break;
printf("PROC\n");
printf(format,"id =",n);
printf(format,"flags1 =",b = getbyte());
if (b & PF_BODYSEEN) {
printf(format,"# labels =",getshort());
printf(lformat,"# locals =",getoff());
printf(lformat,"# formals =",getoff());
if (all == 1) {
printf(" changed ="); showcset();
printf(format,"c_flags =",getshort());
printf(format,"u_flags =",getshort());
printf(" calling ="); showcset();
}
} else {
printf(" body not available\n");
}
}
}
char *pseudo[5] = {"hol", "bss", "rom", "con", "unknown" };
showd()
{
short n;
printf("total number of objects: %d\n\n",getshort());
while (TRUE) {
n = getbyte();
if (feof(f)) break;
switch(n) {
case MARK_DBLOCK:
printf("DBLOCK\n");
printf(format,"id =",getshort());
printf(sformat,"pseudo =",
pseudo[(short) getbyte()]);
printf(lformat,"size =",getoff());
printf(format,"fragment =",getshort());
printf(format,"flags1 =",
(short) getbyte());
break;
case MARK_OBJ:
printf(" OBJ\n");
space1();
printf(format,"id =",getshort());
space1();
printf(lformat,"size =",getoff());
space1();
printf(lformat,"offset =",getoff());
break;
case MARK_ARG:
printf(" VALUE\n");
space1();
printf(lformat,"offset =",getoff());
break;
}
}
}
/* The mnemonics of the EM instructions and pseudos */
extern char em_mnem[];
extern char em_pseu[];
char lab_mnem[] = "instrlab";
char sym_mnem[] = "datalab";
showinstr()
{
short instr;
char *s;
instr = (short) getbyte();
if (feof(f)) return FALSE;
if (instr >= sp_fmnem && instr <= sp_lmnem) {
s = &(em_mnem[(instr-sp_fmnem) *4]);
} else {
if (instr == op_lab) {
s = lab_mnem;
} else {
if (instr == ps_sym) {
s = sym_mnem;
} else {
s = &(em_pseu[(instr-sp_fpseu)*4]);
}
}
}
printf("%s",s);
switch((short) getbyte()) {
case OPSHORT:
case OPOBJECT:
printf(" %d", getshort());
break;
case OPPROC:
printf(" $%d",getshort());
break;
case OPINSTRLAB:
printf(" *%d",getshort());
break;
case OPOFFSET:
printf(" %ld", getoff());
break;
case OPLIST:
arglist();
break;
}
printf("\n");
return TRUE;
}
showl()
{
while (showinstr());
}
arglist()
{
short length;
for (;;) {
switch((short) getbyte()) {
case ARGOBJECT:
printf(" %d", getshort());
break;
case ARGPROC:
printf(" $%d",getshort());
break;
case ARGINSTRLAB:
printf(" *%d",getshort());
break;
case ARGOFF:
printf(" %ld", getoff());
break;
case ARGICN:
case ARGUCN:
case ARGFCN:
printf(" %d",getshort());
/* Fall through !! */
case ARGSTRING:
length = getshort();
putchar(' ');
putchar('"');
while (length--) {
putchar(getbyte());
}
putchar('"');
break;
case ARGCEND:
return;
}
}
}
showlset()
{
register short x;
printf("{ ");
while (x = getshort()) {
printf("%d ",x);
}
printf("}\n");
}
showb()
{
/* basic block file */
short n,m;
while (TRUE) {
n = getshort();
if (feof(f)) break;
if (n == 0) {
printf("Declaration Unit:\n");
printf(dformat,"#instrs =",getshort());
printf("\n");
continue;
}
printf("Control Flow Graph:\n");
printf("number of basic blocks: %d\n",n);
m = getshort(); /* #loops */
while (n--) {
printf(" BASIC BLOCK\n");
printf(dformat,"id =",getshort());
printf(dformat,"# instrs =",getshort());
printf(" succ =");
showlset();
printf(" pred =");
showlset();
printf(dformat,"idom =",getshort());
printf(" loops =");
showlset();
printf(dformat,"flags =",getshort());
}
printf("number of loops: %d\n",m);
while (m--) {
printf(" LOOP\n");
printf(dformat,"id =",getshort());
printf(dformat,"level =",getshort());
printf(dformat,"entry =",getshort());
printf(dformat,"end =",getshort());
}
printf("\n");
}
}
showc()
{
int n,m,cnt,t;
cnt = 1;
while(TRUE) {
t = getshort();
if (feof(f)) break;
printf("CALL %d\n",cnt++);
printf(format,"nestlevel =",t);
printf(format,"calling p. =",getshort());
printf(format,"call_id =",getshort());
printf(format,"called p. =",getshort());
printf(format,"looplevel =",getbyte());
printf(format,"flags =",getbyte());
printf(format,"ratio =",getshort());
printf(" actuals:");
n = getshort();
if (n == 0) {
printf(" ---\n");
} else {
while (n--) {
printf("\n");
m = getshort();
printf(oformat,"size =",getoff());
printf(dformat,"inl =",getbyte());
while (m--) {
printf(" ");
showinstr();
}
}
}
}
}
|
c674d39d2abc069bf2d0db35b6a424964ada819b
|
22506f26940deb3916b9a320e7d4485f2f58ecc1
|
/libass/ass_parse.c
|
fae575a8254cf9cb3d88a8c66fd6329aa808b50c
|
[
"ISC"
] |
permissive
|
libass/libass
|
92b865e13ccd897212960b57b1c68ab00a452d91
|
5c15c883a4783641f7e71a6a1f440209965eb64f
|
refs/heads/master
| 2023-09-04T20:40:39.928295
| 2023-08-06T01:57:20
| 2023-08-21T01:11:57
| 11,696,642
| 828
| 234
|
ISC
| 2023-09-05T21:52:57
| 2013-07-26T23:11:51
|
C
|
UTF-8
|
C
| false
| false
| 40,664
|
c
|
ass_parse.c
|
/*
* Copyright (C) 2009 Grigori Goronzy <greg@geekmind.org>
*
* This file is part of libass.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include "config.h"
#include "ass_compat.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include "ass_library.h"
#include "ass_render.h"
#include "ass_parse.h"
#define MAX_VALID_NARGS 7
#define MAX_BE 127
#define NBSP 0xa0 // unicode non-breaking space character
struct arg {
char *start, *end;
};
static inline int32_t argtoi32(struct arg arg)
{
int32_t value;
mystrtoi32(&arg.start, 10, &value);
return value;
}
static inline double argtod(struct arg arg)
{
double value;
mystrtod(&arg.start, &value);
return value;
}
static inline void push_arg(struct arg *args, int *nargs, char *start, char *end)
{
if (*nargs <= MAX_VALID_NARGS) {
rskip_spaces(&end, start);
if (end > start) {
args[*nargs] = (struct arg) {start, end};
++*nargs;
}
}
}
/**
* \brief Check if starting part of (*p) matches sample.
* If true, shift p to the first symbol after the matching part.
*/
static inline int mystrcmp(char **p, const char *sample)
{
char *p2;
for (p2 = *p; *sample != 0 && *p2 == *sample; p2++, sample++)
;
if (*sample == 0) {
*p = p2;
return 1;
}
return 0;
}
/**
* \brief Change current font, using setting from render_priv->state.
*/
void ass_update_font(RenderContext *state)
{
unsigned val;
ASS_FontDesc desc;
desc.family = state->family;
if (!desc.family.str)
return;
if (desc.family.len && desc.family.str[0] == '@') {
desc.vertical = 1;
desc.family.str++;
desc.family.len--;
} else {
desc.vertical = 0;
}
val = state->bold;
// 0 = normal, 1 = bold, >1 = exact weight
if (val == 1 || val == -1)
val = 700; // bold
else if (val <= 0)
val = 400; // normal
desc.bold = val;
val = state->italic;
if (val == 1)
val = 100; // italic
else if (val <= 0)
val = 0; // normal
desc.italic = val;
ass_cache_dec_ref(state->font);
state->font = ass_font_new(state->renderer, &desc);
}
/**
* \brief Convert double to int32_t without UB
* on out-of-range values; match x86 behavior
*/
static inline int32_t dtoi32(double val)
{
if (isnan(val) || val <= INT32_MIN || val >= INT32_MAX + 1LL)
return INT32_MIN;
return val;
}
static double calc_anim(double new, double old, double pwr)
{
return (1 - pwr) * old + new * pwr;
}
static int32_t calc_anim_int32(uint32_t new, uint32_t old, double pwr)
{
return dtoi32(calc_anim(new, old, pwr));
}
/**
* \brief Calculate a weighted average of two colors
* calculates c1*(1-a) + c2*a, but separately for each component except alpha
*/
static void change_color(uint32_t *var, uint32_t new, double pwr)
{
uint32_t co = ass_bswap32(*var);
uint32_t cn = ass_bswap32(new);
uint32_t cc = (calc_anim_int32(cn & 0xff0000, co & 0xff0000, pwr) & 0xff0000) |
(calc_anim_int32(cn & 0x00ff00, co & 0x00ff00, pwr) & 0x00ff00) |
(calc_anim_int32(cn & 0x0000ff, co & 0x0000ff, pwr) & 0x0000ff);
(*var) = (ass_bswap32(cc & 0xffffff)) | _a(*var);
}
// like change_color, but for alpha component only
static inline void change_alpha(uint32_t *var, int32_t new, double pwr)
{
*var = (*var & 0xFFFFFF00) | (uint8_t)calc_anim_int32(new, _a(*var), pwr);
}
/**
* \brief Multiply two alpha values
* \param a first value
* \param b second value
* \return result of multiplication
* At least one of the parameters must be less than or equal to 0xFF.
* The result is less than or equal to max(a, b, 0xFF).
*/
static inline uint32_t mult_alpha(uint32_t a, uint32_t b)
{
return a - ((uint64_t) a * b + 0x7F) / 0xFF + b;
}
void ass_apply_fade(uint32_t *clr, int fade)
{
// VSFilter compatibility: apply fade only when it's positive
if (fade > 0)
change_alpha(clr, mult_alpha(_a(*clr), fade), 1);
}
/**
* \brief Calculate alpha value by piecewise linear function
* Used for \fad, \fade implementation.
*/
static int
interpolate_alpha(long long now, int32_t t1, int32_t t2, int32_t t3,
int32_t t4, int a1, int a2, int a3)
{
int a;
double cf;
if (now < t1) {
a = a1;
} else if (now < t2) {
cf = ((double) (int32_t) ((uint32_t) now - t1)) /
(int32_t) ((uint32_t) t2 - t1);
a = a1 * (1 - cf) + a2 * cf;
} else if (now < t3) {
a = a2;
} else if (now < t4) {
cf = ((double) (int32_t) ((uint32_t) now - t3)) /
(int32_t) ((uint32_t) t4 - t3);
a = a2 * (1 - cf) + a3 * cf;
} else { // now >= t4
a = a3;
}
return a;
}
/**
* Parse a vector clip into an outline, using the proper scaling
* parameters. Translate it to correct for screen borders, if needed.
*/
static bool parse_vector_clip(RenderContext *state,
struct arg *args, int nargs)
{
if (nargs != 1 && nargs != 2)
return false;
int scale = 1;
if (nargs == 2)
scale = argtoi32(args[0]);
struct arg text = args[nargs - 1];
state->clip_drawing_text.str = text.start;
state->clip_drawing_text.len = text.end - text.start;
state->clip_drawing_scale = scale;
return true;
}
static int32_t parse_alpha_tag(char *str)
{
int32_t alpha = 0;
while (*str == '&' || *str == 'H')
++str;
mystrtoi32(&str, 16, &alpha);
return alpha;
}
static uint32_t parse_color_tag(char *str)
{
int32_t color = 0;
while (*str == '&' || *str == 'H')
++str;
mystrtoi32(&str, 16, &color);
return ass_bswap32((uint32_t) color);
}
/**
* \brief find style by name as in \r
* \param track track
* \param name style name
* \param len style name length
* \return style in track->styles
* Returns NULL if no style has the given name.
*/
static ASS_Style *lookup_style_strict(ASS_Track *track, char *name, size_t len)
{
int i;
for (i = track->n_styles - 1; i >= 0; --i) {
if (strncmp(track->styles[i].Name, name, len) == 0 &&
track->styles[i].Name[len] == '\0')
return track->styles + i;
}
ass_msg(track->library, MSGL_WARN,
"[%p]: Warning: no style named '%.*s' found",
track, (int) len, name);
return NULL;
}
/**
* \brief Parse style override tags.
* \param p string to parse
* \param end end of string to parse, which must be '}', ')', or the first
* of a number of spaces immediately preceding '}' or ')'
* \param pwr multiplier for some tag effects (comes from \t tags)
*/
char *ass_parse_tags(RenderContext *state, char *p, char *end, double pwr,
bool nested)
{
ASS_Renderer *render_priv = state->renderer;
for (char *q; p < end; p = q) {
while (*p != '\\' && p != end)
++p;
if (*p != '\\')
break;
++p;
if (p != end)
skip_spaces(&p);
q = p;
while (*q != '(' && *q != '\\' && q != end)
++q;
if (q == p)
continue;
char *name_end = q;
// Store one extra element to be able to detect excess arguments
struct arg args[MAX_VALID_NARGS + 1];
int nargs = 0;
bool has_backslash_arg = false;
for (int i = 0; i <= MAX_VALID_NARGS; ++i)
args[i].start = args[i].end = "";
// Split parenthesized arguments. Do this for all tags and before
// any non-parenthesized argument because that's what VSFilter does.
if (*q == '(') {
++q;
while (1) {
if (q != end)
skip_spaces(&q);
// Split on commas. If there is a backslash, ignore any
// commas following it and lump everything starting from
// the last comma, through the backslash and all the way
// to the end of the argument string into a single argument.
char *r = q;
while (*r != ',' && *r != '\\' && *r != ')' && r != end)
++r;
if (*r == ',') {
push_arg(args, &nargs, q, r);
q = r + 1;
} else {
// Swallow the rest of the parenthesized string. This could
// be either a backslash-argument or simply the last argument.
if (*r == '\\') {
has_backslash_arg = true;
while (*r != ')' && r != end)
++r;
}
push_arg(args, &nargs, q, r);
q = r;
// The closing parenthesis could be missing.
if (q != end)
++q;
break;
}
}
}
#define tag(name) (mystrcmp(&p, (name)) && (push_arg(args, &nargs, p, name_end), 1))
#define complex_tag(name) mystrcmp(&p, (name))
// New tags introduced in vsfilter 2.39
if (tag("xbord")) {
double val;
if (nargs) {
val = argtod(*args);
val = state->border_x * (1 - pwr) + val * pwr;
val = (val < 0) ? 0 : val;
} else
val = state->style->Outline;
state->border_x = val;
} else if (tag("ybord")) {
double val;
if (nargs) {
val = argtod(*args);
val = state->border_y * (1 - pwr) + val * pwr;
val = (val < 0) ? 0 : val;
} else
val = state->style->Outline;
state->border_y = val;
} else if (tag("xshad")) {
double val;
if (nargs) {
val = argtod(*args);
val = state->shadow_x * (1 - pwr) + val * pwr;
} else
val = state->style->Shadow;
state->shadow_x = val;
} else if (tag("yshad")) {
double val;
if (nargs) {
val = argtod(*args);
val = state->shadow_y * (1 - pwr) + val * pwr;
} else
val = state->style->Shadow;
state->shadow_y = val;
} else if (tag("fax")) {
double val;
if (nargs) {
val = argtod(*args);
state->fax =
val * pwr + state->fax * (1 - pwr);
} else
state->fax = 0.;
} else if (tag("fay")) {
double val;
if (nargs) {
val = argtod(*args);
state->fay =
val * pwr + state->fay * (1 - pwr);
} else
state->fay = 0.;
} else if (complex_tag("iclip")) {
if (nargs == 4) {
int32_t x0, y0, x1, y1;
x0 = argtoi32(args[0]);
y0 = argtoi32(args[1]);
x1 = argtoi32(args[2]);
y1 = argtoi32(args[3]);
state->clip_x0 =
state->clip_x0 * (1 - pwr) + x0 * pwr;
state->clip_x1 =
state->clip_x1 * (1 - pwr) + x1 * pwr;
state->clip_y0 =
state->clip_y0 * (1 - pwr) + y0 * pwr;
state->clip_y1 =
state->clip_y1 * (1 - pwr) + y1 * pwr;
state->clip_mode = 1;
} else if (!state->clip_drawing_text.str) {
if (parse_vector_clip(state, args, nargs))
state->clip_drawing_mode = 1;
}
} else if (tag("blur")) {
double val;
if (nargs) {
val = argtod(*args);
val = state->blur * (1 - pwr) + val * pwr;
val = (val < 0) ? 0 : val;
val = (val > BLUR_MAX_RADIUS) ? BLUR_MAX_RADIUS : val;
state->blur = val;
} else
state->blur = 0.0;
// ASS standard tags
} else if (tag("fscx")) {
double val;
if (nargs) {
val = argtod(*args) / 100;
val = state->scale_x * (1 - pwr) + val * pwr;
val = (val < 0) ? 0 : val;
} else
val = state->style->ScaleX;
state->scale_x = val;
} else if (tag("fscy")) {
double val;
if (nargs) {
val = argtod(*args) / 100;
val = state->scale_y * (1 - pwr) + val * pwr;
val = (val < 0) ? 0 : val;
} else
val = state->style->ScaleY;
state->scale_y = val;
} else if (tag("fsc")) {
state->scale_x = state->style->ScaleX;
state->scale_y = state->style->ScaleY;
} else if (tag("fsp")) {
double val;
if (nargs) {
val = argtod(*args);
state->hspacing =
state->hspacing * (1 - pwr) + val * pwr;
} else
state->hspacing = state->style->Spacing;
} else if (tag("fs")) {
double val = 0;
if (nargs) {
val = argtod(*args);
if (*args->start == '+' || *args->start == '-')
val = state->font_size * (1 + pwr * val / 10);
else
val = state->font_size * (1 - pwr) + val * pwr;
}
if (val <= 0)
val = state->style->FontSize;
state->font_size = val;
} else if (tag("bord")) {
double val, xval, yval;
if (nargs) {
val = argtod(*args);
xval = state->border_x * (1 - pwr) + val * pwr;
yval = state->border_y * (1 - pwr) + val * pwr;
xval = (xval < 0) ? 0 : xval;
yval = (yval < 0) ? 0 : yval;
} else
xval = yval = state->style->Outline;
state->border_x = xval;
state->border_y = yval;
} else if (complex_tag("move")) {
double x1, x2, y1, y2;
int32_t t1, t2, delta_t, t;
double x, y;
double k;
if (nargs == 4 || nargs == 6) {
x1 = argtod(args[0]);
y1 = argtod(args[1]);
x2 = argtod(args[2]);
y2 = argtod(args[3]);
t1 = t2 = 0;
if (nargs == 6) {
t1 = argtoi32(args[4]);
t2 = argtoi32(args[5]);
if (t1 > t2) {
long long tmp = t2;
t2 = t1;
t1 = tmp;
}
}
} else
continue;
if (t1 <= 0 && t2 <= 0) {
t1 = 0;
t2 = state->event->Duration;
}
delta_t = (uint32_t) t2 - t1;
t = render_priv->time - state->event->Start;
if (t <= t1)
k = 0.;
else if (t >= t2)
k = 1.;
else
k = ((double) (int32_t) ((uint32_t) t - t1)) / delta_t;
x = k * (x2 - x1) + x1;
y = k * (y2 - y1) + y1;
if (!(state->evt_type & EVENT_POSITIONED)) {
state->pos_x = x;
state->pos_y = y;
state->detect_collisions = 0;
state->evt_type |= EVENT_POSITIONED;
}
} else if (tag("frx")) {
double val;
if (nargs) {
val = argtod(*args);
state->frx =
val * pwr + state->frx * (1 - pwr);
} else
state->frx = 0.;
} else if (tag("fry")) {
double val;
if (nargs) {
val = argtod(*args);
state->fry =
val * pwr + state->fry * (1 - pwr);
} else
state->fry = 0.;
} else if (tag("frz") || tag("fr")) {
double val;
if (nargs) {
val = argtod(*args);
state->frz =
val * pwr + state->frz * (1 - pwr);
} else
state->frz =
state->style->Angle;
} else if (tag("fn")) {
char *start = args->start;
if (nargs && strncmp(start, "0", args->end - start)) {
skip_spaces(&start);
state->family.str = start;
state->family.len = args->end - start;
} else {
state->family.str = state->style->FontName;
state->family.len = strlen(state->style->FontName);
}
ass_update_font(state);
} else if (tag("alpha")) {
int i;
if (nargs) {
int32_t a = parse_alpha_tag(args->start);
for (i = 0; i < 4; ++i)
change_alpha(&state->c[i], a, pwr);
} else {
change_alpha(&state->c[0],
_a(state->style->PrimaryColour), 1);
change_alpha(&state->c[1],
_a(state->style->SecondaryColour), 1);
change_alpha(&state->c[2],
_a(state->style->OutlineColour), 1);
change_alpha(&state->c[3],
_a(state->style->BackColour), 1);
}
// FIXME: simplify
} else if (tag("an")) {
int32_t val = argtoi32(*args);
if ((state->parsed_tags & PARSED_A) == 0) {
if (val >= 1 && val <= 9)
state->alignment = numpad2align(val);
else
state->alignment =
state->style->Alignment;
state->parsed_tags |= PARSED_A;
}
} else if (tag("a")) {
int32_t val = argtoi32(*args);
if ((state->parsed_tags & PARSED_A) == 0) {
if (val >= 1 && val <= 11)
// take care of a vsfilter quirk:
// handle illegal \a8 and \a4 like \a5
state->alignment = ((val & 3) == 0) ? 5 : val;
else
state->alignment =
state->style->Alignment;
state->parsed_tags |= PARSED_A;
}
} else if (complex_tag("pos")) {
double v1, v2;
if (nargs == 2) {
v1 = argtod(args[0]);
v2 = argtod(args[1]);
} else
continue;
if (state->evt_type & EVENT_POSITIONED) {
ass_msg(render_priv->library, MSGL_V, "Subtitle has a new \\pos "
"after \\move or \\pos, ignoring");
} else {
state->evt_type |= EVENT_POSITIONED;
state->detect_collisions = 0;
state->pos_x = v1;
state->pos_y = v2;
}
} else if (complex_tag("fade") || complex_tag("fad")) {
int32_t a1, a2, a3;
int32_t t1, t2, t3, t4;
if (nargs == 2) {
// 2-argument version (\fad, according to specs)
a1 = 0xFF;
a2 = 0;
a3 = 0xFF;
t1 = -1;
t2 = argtoi32(args[0]);
t3 = argtoi32(args[1]);
t4 = -1;
} else if (nargs == 7) {
// 7-argument version (\fade)
a1 = argtoi32(args[0]);
a2 = argtoi32(args[1]);
a3 = argtoi32(args[2]);
t1 = argtoi32(args[3]);
t2 = argtoi32(args[4]);
t3 = argtoi32(args[5]);
t4 = argtoi32(args[6]);
} else
continue;
if (t1 == -1 && t4 == -1) {
t1 = 0;
t4 = state->event->Duration;
t3 = (uint32_t) t4 - t3;
}
if ((state->parsed_tags & PARSED_FADE) == 0) {
state->fade =
interpolate_alpha(render_priv->time -
state->event->Start, t1, t2,
t3, t4, a1, a2, a3);
state->parsed_tags |= PARSED_FADE;
}
} else if (complex_tag("org")) {
double v1, v2;
if (nargs == 2) {
v1 = argtod(args[0]);
v2 = argtod(args[1]);
} else
continue;
if (!state->have_origin) {
state->org_x = v1;
state->org_y = v2;
state->have_origin = 1;
state->detect_collisions = 0;
}
} else if (complex_tag("t")) {
double accel;
int cnt = nargs - 1;
int32_t t1, t2, t, delta_t;
double k;
// VSFilter compatibility (because we can): parse the
// timestamps differently depending on argument count.
if (cnt == 3) {
t1 = argtoi32(args[0]);
t2 = argtoi32(args[1]);
accel = argtod(args[2]);
} else if (cnt == 2) {
t1 = dtoi32(argtod(args[0]));
t2 = dtoi32(argtod(args[1]));
accel = 1.;
} else if (cnt == 1) {
t1 = 0;
t2 = 0;
accel = argtod(args[0]);
} else {
t1 = 0;
t2 = 0;
accel = 1.;
}
state->detect_collisions = 0;
if (t2 == 0)
t2 = state->event->Duration;
delta_t = (uint32_t) t2 - t1;
t = render_priv->time - state->event->Start; // FIXME: move to render_context
if (t < t1)
k = 0.;
else if (t >= t2)
k = 1.;
else {
assert(delta_t != 0.);
k = pow((double) (int32_t) ((uint32_t) t - t1) / delta_t, accel);
}
if (nested)
pwr = k;
if (cnt < 0 || cnt > 3)
continue;
// If there's no backslash in the arguments, there are no
// override tags, so it's pointless to try to parse them.
if (!has_backslash_arg)
continue;
p = args[cnt].start;
if (args[cnt].end < end) {
assert(!nested);
p = ass_parse_tags(state, p, args[cnt].end, k, true);
} else {
assert(q == end);
// No other tags can possibly follow this \t tag,
// so we don't need to restore pwr after parsing \t.
// The recursive call is now essentially a tail call,
// so optimize it away.
pwr = k;
nested = true;
q = p;
}
} else if (complex_tag("clip")) {
if (nargs == 4) {
int32_t x0, y0, x1, y1;
x0 = argtoi32(args[0]);
y0 = argtoi32(args[1]);
x1 = argtoi32(args[2]);
y1 = argtoi32(args[3]);
state->clip_x0 =
state->clip_x0 * (1 - pwr) + x0 * pwr;
state->clip_x1 =
state->clip_x1 * (1 - pwr) + x1 * pwr;
state->clip_y0 =
state->clip_y0 * (1 - pwr) + y0 * pwr;
state->clip_y1 =
state->clip_y1 * (1 - pwr) + y1 * pwr;
state->clip_mode = 0;
} else if (!state->clip_drawing_text.str) {
if (parse_vector_clip(state, args, nargs))
state->clip_drawing_mode = 0;
}
} else if (tag("c") || tag("1c")) {
if (nargs) {
uint32_t val = parse_color_tag(args->start);
change_color(&state->c[0], val, pwr);
} else
change_color(&state->c[0],
state->style->PrimaryColour, 1);
} else if (tag("2c")) {
if (nargs) {
uint32_t val = parse_color_tag(args->start);
change_color(&state->c[1], val, pwr);
} else
change_color(&state->c[1],
state->style->SecondaryColour, 1);
} else if (tag("3c")) {
if (nargs) {
uint32_t val = parse_color_tag(args->start);
change_color(&state->c[2], val, pwr);
} else
change_color(&state->c[2],
state->style->OutlineColour, 1);
} else if (tag("4c")) {
if (nargs) {
uint32_t val = parse_color_tag(args->start);
change_color(&state->c[3], val, pwr);
} else
change_color(&state->c[3],
state->style->BackColour, 1);
} else if (tag("1a")) {
if (nargs) {
uint32_t val = parse_alpha_tag(args->start);
change_alpha(&state->c[0], val, pwr);
} else
change_alpha(&state->c[0],
_a(state->style->PrimaryColour), 1);
} else if (tag("2a")) {
if (nargs) {
uint32_t val = parse_alpha_tag(args->start);
change_alpha(&state->c[1], val, pwr);
} else
change_alpha(&state->c[1],
_a(state->style->SecondaryColour), 1);
} else if (tag("3a")) {
if (nargs) {
uint32_t val = parse_alpha_tag(args->start);
change_alpha(&state->c[2], val, pwr);
} else
change_alpha(&state->c[2],
_a(state->style->OutlineColour), 1);
} else if (tag("4a")) {
if (nargs) {
uint32_t val = parse_alpha_tag(args->start);
change_alpha(&state->c[3], val, pwr);
} else
change_alpha(&state->c[3],
_a(state->style->BackColour), 1);
} else if (tag("r")) {
if (nargs) {
int len = args->end - args->start;
ass_reset_render_context(state,
lookup_style_strict(render_priv->track, args->start, len));
} else
ass_reset_render_context(state, NULL);
} else if (tag("be")) {
double dval;
if (nargs) {
int32_t val;
dval = argtod(*args);
// VSFilter always adds +0.5, even if the value is negative
val = dtoi32(state->be * (1 - pwr) + dval * pwr + 0.5);
// Clamp to a safe upper limit, since high values need excessive CPU
val = (val < 0) ? 0 : val;
val = (val > MAX_BE) ? MAX_BE : val;
state->be = val;
} else
state->be = 0;
} else if (tag("b")) {
int32_t val = argtoi32(*args);
if (!nargs || !(val == 0 || val == 1 || val >= 100))
val = state->style->Bold;
state->bold = val;
ass_update_font(state);
} else if (tag("i")) {
int32_t val = argtoi32(*args);
if (!nargs || !(val == 0 || val == 1))
val = state->style->Italic;
state->italic = val;
ass_update_font(state);
} else if (tag("kt")) {
// v4++
double val = 0;
if (nargs)
val = argtod(*args) * 10;
state->effect_skip_timing = dtoi32(val);
state->effect_timing = 0;
state->reset_effect = true;
} else if (tag("kf") || tag("K")) {
double val = 100;
if (nargs)
val = argtod(*args);
state->effect_type = EF_KARAOKE_KF;
state->effect_skip_timing +=
(uint32_t) state->effect_timing;
state->effect_timing = dtoi32(val * 10);
} else if (tag("ko")) {
double val = 100;
if (nargs)
val = argtod(*args);
state->effect_type = EF_KARAOKE_KO;
state->effect_skip_timing +=
(uint32_t) state->effect_timing;
state->effect_timing = dtoi32(val * 10);
} else if (tag("k")) {
double val = 100;
if (nargs)
val = argtod(*args);
state->effect_type = EF_KARAOKE;
state->effect_skip_timing +=
(uint32_t) state->effect_timing;
state->effect_timing = dtoi32(val * 10);
} else if (tag("shad")) {
double val, xval, yval;
if (nargs) {
val = argtod(*args);
xval = state->shadow_x * (1 - pwr) + val * pwr;
yval = state->shadow_y * (1 - pwr) + val * pwr;
// VSFilter compatibility: clip for \shad but not for \[xy]shad
xval = (xval < 0) ? 0 : xval;
yval = (yval < 0) ? 0 : yval;
} else
xval = yval = state->style->Shadow;
state->shadow_x = xval;
state->shadow_y = yval;
} else if (tag("s")) {
int32_t val = argtoi32(*args);
if (!nargs || !(val == 0 || val == 1))
val = state->style->StrikeOut;
if (val)
state->flags |= DECO_STRIKETHROUGH;
else
state->flags &= ~DECO_STRIKETHROUGH;
} else if (tag("u")) {
int32_t val = argtoi32(*args);
if (!nargs || !(val == 0 || val == 1))
val = state->style->Underline;
if (val)
state->flags |= DECO_UNDERLINE;
else
state->flags &= ~DECO_UNDERLINE;
} else if (tag("pbo")) {
double val = argtod(*args);
state->pbo = val;
} else if (tag("p")) {
int32_t val = argtoi32(*args);
val = (val < 0) ? 0 : val;
state->drawing_scale = val;
} else if (tag("q")) {
int32_t val = argtoi32(*args);
if (!nargs || !(val >= 0 && val <= 3))
val = render_priv->track->WrapStyle;
state->wrap_style = val;
} else if (tag("fe")) {
int32_t val;
if (nargs)
val = argtoi32(*args);
else
val = state->style->Encoding;
state->font_encoding = val;
}
}
return p;
}
void ass_apply_transition_effects(RenderContext *state)
{
ASS_Renderer *render_priv = state->renderer;
int v[4];
int cnt;
ASS_Event *event = state->event;
char *p = event->Effect;
if (!p || !*p)
return;
cnt = 0;
while (cnt < 4 && (p = strchr(p, ';'))) {
v[cnt++] = atoi(++p);
}
ASS_Vector layout_res = ass_layout_res(render_priv);
if (strncmp(event->Effect, "Banner;", 7) == 0) {
double delay;
if (cnt < 1) {
ass_msg(render_priv->library, MSGL_V,
"Error parsing effect: '%s'", event->Effect);
return;
}
if (cnt >= 2 && v[1]) // left-to-right
state->scroll_direction = SCROLL_LR;
else // right-to-left
state->scroll_direction = SCROLL_RL;
delay = v[0];
// VSF works in storage coordinates, but scales delay to PlayRes canvas
// before applying max(scaled_ delay, 1). This means, if scaled_delay < 1
// (esp. delay=0) we end up with 1 ms per _storage pixel_ without any
// PlayRes scaling.
// The way libass deals with delay, it is automatically relative to the
// PlayRes canvas, so we only want to "unscale" the small delay values.
//
// VSF also casts the scaled delay to int, which if not emulated leads to
// easily noticeable deviations from VSFilter as the effect goes on.
// To achieve both we need to keep our Playres-relative delay with high precision,
// but must temporarily convert to storage-relative and truncate and take the
// maxuimum there, before converting back.
double scale_x = ((double) layout_res.x) / render_priv->track->PlayResX;
delay = ((int) FFMAX(delay / scale_x, 1)) * scale_x;
state->scroll_shift =
(render_priv->time - event->Start) / delay;
state->evt_type |= EVENT_HSCROLL;
state->detect_collisions = 0;
state->wrap_style = 2;
return;
}
if (strncmp(event->Effect, "Scroll up;", 10) == 0) {
state->scroll_direction = SCROLL_BT;
} else if (strncmp(event->Effect, "Scroll down;", 12) == 0) {
state->scroll_direction = SCROLL_TB;
} else {
ass_msg(render_priv->library, MSGL_DBG2,
"Unknown transition effect: '%s'", event->Effect);
return;
}
// parse scroll up/down parameters
{
double delay;
int y0, y1;
if (cnt < 3) {
ass_msg(render_priv->library, MSGL_V,
"Error parsing effect: '%s'", event->Effect);
return;
}
delay = v[2];
// See explanation for Banner
double scale_y = ((double) layout_res.y) / render_priv->track->PlayResY;
delay = ((int) FFMAX(delay / scale_y, 1)) * scale_y;
state->scroll_shift =
(render_priv->time - event->Start) / delay;
if (v[0] < v[1]) {
y0 = v[0];
y1 = v[1];
} else {
y0 = v[1];
y1 = v[0];
}
state->scroll_y0 = y0;
state->scroll_y1 = y1;
state->evt_type |= EVENT_VSCROLL;
state->detect_collisions = 0;
}
}
/**
* \brief determine karaoke effects
* Karaoke effects cannot be calculated during parse stage (ass_get_next_char()),
* so they are done in a separate step.
* Parse stage: when karaoke style override is found, its parameters are stored in the next glyph's
* (the first glyph of the karaoke word)'s effect_type and effect_timing.
* This function:
* 1. sets effect_type for all glyphs in the word (_karaoke_ word)
* 2. sets effect_timing for all glyphs to x coordinate of the border line between the left and right karaoke parts
* (left part is filled with PrimaryColour, right one - with SecondaryColour).
*/
void ass_process_karaoke_effects(RenderContext *state)
{
TextInfo *text_info = state->text_info;
long long tm_current = state->renderer->time - state->event->Start;
int32_t timing = 0, skip_timing = 0;
Effect effect_type = EF_NONE;
GlyphInfo *last_boundary = NULL;
bool has_reset = false;
for (int i = 0; i <= text_info->length; i++) {
if (i < text_info->length &&
!text_info->glyphs[i].starts_new_run) {
if (text_info->glyphs[i].reset_effect) {
has_reset = true;
skip_timing = 0;
}
// VSFilter compatibility: if we have \k12345\k0 without a run
// break, subsequent text is still part of the same karaoke word,
// the current word's starting and ending time stay unchanged,
// but the starting time of the next karaoke word is advanced.
skip_timing += (uint32_t) text_info->glyphs[i].effect_skip_timing;
continue;
}
GlyphInfo *start = last_boundary;
GlyphInfo *end = text_info->glyphs + i;
last_boundary = end;
if (!start)
continue;
if (start->effect_type != EF_NONE)
effect_type = start->effect_type;
if (effect_type == EF_NONE)
continue;
if (start->reset_effect)
timing = 0;
long long tm_start = timing + start->effect_skip_timing;
long long tm_end = tm_start + start->effect_timing;
timing = !has_reset * tm_end + skip_timing;
skip_timing = 0;
has_reset = false;
if (effect_type != EF_KARAOKE_KF)
tm_end = tm_start;
int x;
if (tm_current < tm_start)
x = -100000000;
else if (tm_current >= tm_end)
x = 100000000;
else {
GlyphInfo *first_visible = start, *last_visible = end - 1;
while (first_visible < last_visible && first_visible->skip)
++first_visible;
while (first_visible < last_visible && last_visible->skip)
--last_visible;
int x_start = first_visible->pos.x;
int x_end = last_visible->pos.x + last_visible->advance.x;
double dt = (double) (tm_current - tm_start) / (tm_end - tm_start);
double frz = fmod(start->frz, 360);
if (frz > 90 && frz < 270) {
// Fill from right to left
dt = 1 - dt;
for (GlyphInfo *info = start; info < end; info++) {
uint32_t tmp = info->c[0];
info->c[0] = info->c[1];
info->c[1] = tmp;
}
}
x = x_start + lrint((x_end - x_start) * dt);
}
for (GlyphInfo *info = start; info < end; info++) {
info->effect_type = effect_type;
info->effect_timing = x - info->pos.x;
}
}
}
/**
* \brief Get next ucs4 char from string, parsing UTF-8 and escapes
* \param str string pointer
* \return ucs4 code of the next char
* On return str points to the unparsed part of the string
*/
unsigned ass_get_next_char(RenderContext *state, char **str)
{
char *p = *str;
unsigned chr;
if (*p == '\t') {
++p;
*str = p;
return ' ';
}
if (*p == '\\') {
if ((p[1] == 'N') || ((p[1] == 'n') &&
(state->wrap_style == 2))) {
p += 2;
*str = p;
return '\n';
} else if (p[1] == 'n') {
p += 2;
*str = p;
return ' ';
} else if (p[1] == 'h') {
p += 2;
*str = p;
return NBSP;
} else if (p[1] == '{') {
p += 2;
*str = p;
return '{';
} else if (p[1] == '}') {
p += 2;
*str = p;
return '}';
}
}
chr = ass_utf8_get_char((char **) &p);
*str = p;
return chr;
}
// Return 1 if the event contains tags that will apply overrides the selective
// style override code should not touch. Return 0 otherwise.
int ass_event_has_hard_overrides(char *str)
{
// look for \pos and \move tags inside {...}
// mirrors ass_get_next_char, but is faster and doesn't change any global state
while (*str) {
if (str[0] == '\\' && str[1] != '\0') {
str += 2;
} else if (str[0] == '{') {
str++;
while (*str && *str != '}') {
if (*str == '\\') {
char *p = str + 1;
if (mystrcmp(&p, "pos") || mystrcmp(&p, "move") ||
mystrcmp(&p, "clip") || mystrcmp(&p, "iclip") ||
mystrcmp(&p, "org") || mystrcmp(&p, "pbo") ||
mystrcmp(&p, "p"))
return 1;
}
str++;
}
} else {
str++;
}
}
return 0;
}
|
3119d5d9e7be7ba4e0ee17967b944d4cd47d5818
|
3bd385b466cb035fecd2b0c11ae054d42bf44fc2
|
/src/core/sequence_buffer.h
|
9104babf6b09bdbf23cff467bf3a2c38355ff881
|
[
"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
| 5,556
|
h
|
sequence_buffer.h
|
/*
Copyright (c) 2009 Sascha Steinbiss <steinbiss@zbh.uni-hamburg.de>
Copyright (c) 2009 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 SEQUENCE_BUFFER_H
#define SEQUENCE_BUFFER_H
#include "core/chardef_api.h"
#include "core/error_api.h"
#include "core/filelengthvalues.h"
#include "core/desc_buffer.h"
#include "core/str_array.h"
#include "core/sequence_buffer_dust.h"
/* A <GtSequenceBuffer> represents a group of sequence files of a certain type.
These files are parsed on-the-fly and the sequences and descriptions
contained in them are made available.
Sequences can be read character-wise using gt_sequence_buffer_next(), with
GT_SEPARATOR symbols in between (see chardef.h).
Note that the <GtSequenceBuffer> is a rather low-level tool for efficient
sequence access. For simple access to whole sequences, use the
<GtSeqIterator> class. */
typedef struct GtSequenceBuffer GtSequenceBuffer;
typedef struct GtSequenceBufferClass GtSequenceBufferClass;
/* Increases the reference count of the <GtSequenceBuffer>. */
GtSequenceBuffer* gt_sequence_buffer_ref(GtSequenceBuffer*);
/* Creates a new <GtSequenceBuffer>, choosing the appropriate type by looking
at the first input file. All files must be of the same type.
If NULL is returned, an error occurred. */
GtSequenceBuffer* gt_sequence_buffer_new_guess_type(const GtStrArray*,
GtError*);
/* Fetches next character from <GtSequenceBuffer>.
Returns 1 if a new character could be read, 0 if all files are exhausted, or
-1 on error (see the <GtError> object for details). */
int gt_sequence_buffer_next(GtSequenceBuffer*, GtUchar*, GtError*);
/* Fetches next character from <GtSequenceBuffer>.
This method also always delivers the original character at the current
reading position, regardless of symbol mappings that may apply.
Returns 1 if a new character could be read, 0 if all files are exhausted, or
-1 on error (see the <GtError> object for details). */
int gt_sequence_buffer_next_with_original_raw(GtSequenceBuffer*,
GtUchar *val, char *orig,
GtError*);
/* Wrapper-function. Calls gt_sequence_buffer_next_with_original_raw() if
dust_masker is NULL, gt_dust_masker_next_with_original() otherwise. */
int gt_sequence_buffer_next_with_original(GtSequenceBuffer*,
GtDustMasker *dust_masker,
GtUchar *val, char *orig,
GtError*);
/* Returns the index of the currently read sequence file in the input file
<GtStrArray>. */
GtUword gt_sequence_buffer_get_file_index(GtSequenceBuffer*);
/* Assigns a symbol map to the sequence iterator to transform sequences with.
Set to NULL to disable alphabet transformation (default). */
void gt_sequence_buffer_set_symbolmap(GtSequenceBuffer*,
const GtUchar *);
/* Assigns an array of Filelengthvalue structs to the sequence iterator. This
is filled during iteration. Note that the length of the array must equal the
number of sequence files traversed.
Set to NULL to disable Filelengthvalue counting (default). */
void gt_sequence_buffer_set_filelengthtab(GtSequenceBuffer*,
GtFilelengthvalues*);
/* Assigns a <GtDescBuffer> in which for each sequence file, the respective
description string is written. If this is not set, or set to NULL,
then descriptions are ignored in the input files. */
void gt_sequence_buffer_set_desc_buffer(GtSequenceBuffer *si,
GtDescBuffer *db);
/* Assigns an array which counts the occurrences of each alphabet character in
the read sequence. It must have at least as many elements as the number of
characters in the expected alphabet.
Set to NULL to disable character distribution counting (default). */
void gt_sequence_buffer_set_chardisttab(GtSequenceBuffer*,
GtUword*);
/* Returns the length of the last processed continuous stretch of special
characters (wildcards or separators, see chardef.h). */
uint64_t gt_sequence_buffer_get_lastspeciallength(const GtSequenceBuffer*);
/* Returns a pointer to a memory location holding the number of characters
read altogether in this sequence of files. */
const GtUint64*
gt_sequence_buffer_get_counter(const GtSequenceBuffer *si);
void gt_sequence_buffer_delete(GtSequenceBuffer*);
int gt_sequence_buffer_unit_test(GtError*);
#endif
|
37a7fccaf889469fda8d233118df7f3ba19f6c94
|
a36899b1da27a9bf6f89c5fef60bd71b96779fc7
|
/apis/isis-ants-api/isis-ants-api/ants-api.h
|
7cdc7d002a5e309e8512d0dec7fcd8435dafb68c
|
[
"Apache-2.0"
] |
permissive
|
kubos/kubos
|
b26cb13f8bc60b9e333906f391c51d8c8651d6ce
|
49b4bf78939cac4161374e696f1b8c834921ad7c
|
refs/heads/master
| 2023-08-03T10:19:22.732695
| 2023-02-21T19:32:46
| 2023-02-21T19:32:46
| 117,996,656
| 300
| 70
|
Apache-2.0
| 2023-07-25T22:54:04
| 2018-01-18T14:55:14
|
Rust
|
UTF-8
|
C
| false
| false
| 8,933
|
h
|
ants-api.h
|
/*
* Copyright (C) 2018 Kubos 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.
*/
/**
* @defgroup ISIS_ANTS_API ISIS ISIS ANTS API
* @addtogroup ISIS_ANTS_API
* @{
*/
#pragma once
#include <stdbool.h>
#include <stdint.h>
#include <i2c.h>
/** \cond WE DO NOT WANT TO HAVE THESE IN OUR GENERATED DOCS */
/* AntS command values */
#define SYSTEM_RESET 0xAA
#define WATCHDOG_RESET 0xCC
#define ARM_ANTS 0xAD
#define DISARM_ANTS 0xAC
#define DEPLOY_1 0xA1
#define DEPLOY_2 0xA2
#define DEPLOY_3 0xA3
#define DEPLOY_4 0xA4
#define AUTO_DEPLOY 0xA5
#define DEPLOY_1_OVERRIDE 0xBA
#define DEPLOY_2_OVERRIDE 0xBB
#define DEPLOY_3_OVERRIDE 0xBC
#define DEPLOY_4_OVERRIDE 0xBD
#define CANCEL_DEPLOY 0xA9
#define GET_TEMP 0xC0
#define GET_STATUS 0xC3
#define GET_UPTIME_SYS 0xC6
#define GET_TELEMETRY 0xC7
#define GET_COUNT_1 0xB0
#define GET_COUNT_2 0xB1
#define GET_COUNT_3 0xB2
#define GET_COUNT_4 0xB3
#define GET_UPTIME_1 0xB4
#define GET_UPTIME_2 0xB5
#define GET_UPTIME_3 0xB6
#define GET_UPTIME_4 0xB7
/** \endcond */
/**
* @name Deployment Status Flags
*/
/**@{*/
#define SYS_BURN_ACTIVE (1 << 4) /**< Antenna system independent burn is active */
#define SYS_IGNORE_DEPLOY (1 << 8) /**< Antenna system is ignoring the deployment switches */
#define SYS_ARMED (1 << 0) /**< Antenna system is armed */
#define ANT_1_NOT_DEPLOYED (8 << 12) /**< Antenna 1 is not deployed */
#define ANT_1_STOPPED_TIME (4 << 12) /**< Antenna 1 deployment time limit was reached */
#define ANT_1_ACTIVE (2 << 12) /**< Antenna 1 deployment system is active */
#define ANT_2_NOT_DEPLOYED (8 << 8) /**< Antenna 2 is not deployed */
#define ANT_2_STOPPED_TIME (4 << 8) /**< Antenna 2 deployment time limit was reached */
#define ANT_2_ACTIVE (2 << 8) /**< Antenna 2 deployment system is active */
#define ANT_3_NOT_DEPLOYED (8 << 4) /**< Antenna 3 is not deployed */
#define ANT_3_STOPPED_TIME (4 << 4) /**< Antenna 3 deployment time limit was reached */
#define ANT_3_ACTIVE (2 << 4) /**< Antenna 3 deployment system is active */
#define ANT_4_NOT_DEPLOYED (8 << 0) /**< Antenna 4 is not deployed */
#define ANT_4_STOPPED_TIME (4 << 0) /**< Antenna 4 deployment time limit was reached */
#define ANT_4_ACTIVE (2 << 0) /**< Antenna 4 deployment system is active */
/**@}*/
/**
* Antenna function return values
*/
typedef enum {
ANTS_OK, /**< Requested function completed successfully */
ANTS_ERROR, /**< Generic error */
ANTS_ERROR_CONFIG, /**< Configuration error */
ANTS_ERROR_NOT_IMPLEMENTED /**< Requested function has not been implemented for the subsystem */
} KANTSStatus;
/**
* Antenna microcontrollers
*/
typedef enum {
PRIMARY, /**< Issue commands using the primary microcontroller */
SECONDARY, /**< Issue commands using the secondary microcontroller (if available) */
} KANTSController;
/**
* System Antennas
*/
typedef enum {
ANT_1, /**< Antenna 1 */
ANT_2, /**< Antenna 2 */
ANT_3, /**< Antenna 3 */
ANT_4 /**< Antenna 4 */
} KANTSAnt;
/**
* System telemetry fields returned from ::k_ants_get_system_telemetry
*/
typedef struct
{
uint16_t raw_temp; /**< Current temperature (raw value) */
uint16_t deploy_status; /**< Current deployment status flags */
uint32_t uptime; /**< System uptime (in seconds) */
} __attribute__((packed)) ants_telemetry;
/*
* Public Functions
*/
/**
* Initialize the antenna interface
* @param [in] bus I2C bus device the antenna systems device is connected to
* @param [in] primary The I2C address of the device's primary microcontroller
* @param [in] secondary The I2C address of the device's secondary/redundant microcontroller
* @param [in] ant_count The number of antennas that the device can deploy
* @param [in] timeout The watchdog timeout interval (in seconds)
* @return KANTSStatus ANTS_OK if OK, error otherwise
*/
KANTSStatus k_ants_init(char * bus, uint8_t primary, uint8_t secondary, uint8_t ant_count, uint32_t timeout);
/**
* Terminate the antenna interface
*/
void k_ants_terminate(void);
/**
* Configure the antenna
* @param [in] config Microntroller to use for system commanding
* @return KANTSStatus ANTS_OK if OK, error otherwise
*/
KANTSStatus k_ants_configure(KANTSController config);
/**
* Reset both of the antenna's microcontrollers
* @return KANTSStatus ANTS_OK if OK, error otherwise
*/
KANTSStatus k_ants_reset(void);
/**
* Arm the antenna
* @return KANTSStatus ANTS_OK if OK, error otherwise
*/
KANTSStatus k_ants_arm(void);
/**
* Disarm the antenna
* @return KANTSStatus ANTS_OK if OK, error otherwise
*/
KANTSStatus k_ants_disarm(void);
/**
* Deploy an antenna
* @param [in] antenna Antenna to deploy
* @param [in] override Indicates whether system should ignore previous
* successful deployment
* @param [in] timeout Maximum time, in seconds, system should spend deploying
* the antenna
* @return KANTSStatus ANTS_OK if OK, error otherwise
*/
KANTSStatus k_ants_deploy(KANTSAnt antenna, bool override, uint8_t timeout);
/**
* Automatically deploy each antenna in sequence
* @param [in] timeout Maximum time, in seconds, system should spend deploying
* a single antenna
* @return KANTSStatus ANTS_OK if OK, error otherwise
*/
KANTSStatus k_ants_auto_deploy(uint8_t timeout);
/**
* Cancel all current deployment actions
* @return KANTSStatus `ANTS_OK` if OK, error otherwise
*/
KANTSStatus k_ants_cancel_deploy(void);
/**
* Get current deployment status
* @param [out] resp Pointer to storage for data
* @return KANTSStatus `ANTS_OK` if OK, error otherwise
*/
KANTSStatus k_ants_get_deploy_status(uint16_t * resp);
/**
* Get system uptime
* @param [out] uptime Pointer to storage for data
* @return KANTSStatus `ANTS_OK` if OK, error otherwise
*/
KANTSStatus k_ants_get_uptime(uint32_t * uptime);
/**
* Get the current system telemetry
* @param [out] telem Pointer to ::ants_telemetry structure
* @return KANTSStatus `ANTS_OK` if OK, error otherwise
*/
KANTSStatus k_ants_get_system_telemetry(ants_telemetry * telem);
/**
* Get an antenna's activation count
* @param [in] antenna Antenna to query
* @param [out] count Number of times antenna deployment has been attempted
* @return KANTSStatus `ANTS_OK` if OK, error otherwise
*/
KANTSStatus k_ants_get_activation_count(KANTSAnt antenna, uint8_t * count);
/**
* Get an antenna's activation time
* @param [in] antenna Antenna to query
* @param [out] time Amount of time spent deploying antenna in 50ms steps
* @return KANTSStatus `ANTS_OK` if OK, error otherwise
*/
KANTSStatus k_ants_get_activation_time(KANTSAnt antenna, uint16_t * time);
/**
* Kick the AntS's watchdogs once
* @return KANTSStatus `ANTS_OK` if OK, error otherwise
*/
KANTSStatus k_ants_watchdog_kick(void);
/**
* Start a thread to kick the AntS's watchdogs at an interval of
* (timeout/3) seconds
* @return KANTSStatus `ANTS_OK` if OK, error otherwise
*/
KANTSStatus k_ants_watchdog_start(void);
/**
* Stop the watchdog thread
* @return KANTSStatus `ANTS_OK` if OK, error otherwise
*/
KANTSStatus k_ants_watchdog_stop(void);
/**
* Pass a command packet directly through to the antenna.
* Useful for executing commands which have not been implemented in either the
* generic or specific antenna APIs.
* @param [in] tx Pointer to command packet to send
* @param [in] tx_len Size of command packet
* @param [out] rx Pointer to storage for command response
* @param [in] rx_len Expected length of command response
* @return KANTSStatus ANTS_OK if OK, error otherwise
*/
KANTSStatus k_ants_passthrough(const uint8_t * tx, int tx_len, uint8_t * rx,
int rx_len);
/* @} */
|
3d8ea386986e9ce075f1bc0cd3687d19b077ae0a
|
e8b04bef9aa1ac8e2c109dd315f133c8f4d28ae6
|
/projects/robots/robotis/darwin-op/libraries/robotis-op2/robotis/Linux/include/mjpg_streamer.h
|
d0a5abeabc44ea6e6fc3b6b04da40a8740218bf9
|
[
"Apache-2.0"
] |
permissive
|
cyberbotics/webots
|
f075dacf4067e8dcebbfd89e8690df8525f6d745
|
8aba6eaae76989facf3442305c8089d3cc366bcf
|
refs/heads/master
| 2023-08-31T09:41:13.205940
| 2023-08-18T10:48:30
| 2023-08-18T10:48:30
| 156,228,018
| 2,495
| 1,525
|
Apache-2.0
| 2023-08-28T16:30:33
| 2018-11-05T14:09:10
|
C++
|
UTF-8
|
C
| false
| false
| 161
|
h
|
mjpg_streamer.h
|
/*
* mjpg_streamer.h
*
* Author: ROBOTIS
*
*/
#ifndef _MJPG_STREAMER_H_
#define _MJPG_STREAMER_H_
#include "../build/streamer/mjpg_streamer.h"
#endif
|
ddae7f0aa4f3876561d3cda3acb9ccad2ea9faae
|
aa3befea459382dc5c01c925653d54f435b3fb0f
|
/include/nuttx/trace.h
|
70c68d3f673bc99c105d9f4f715a021de580ce3f
|
[
"MIT-open-group",
"BSD-3-Clause",
"HPND-sell-variant",
"BSD-4-Clause-UC",
"LicenseRef-scancode-warranty-disclaimer",
"MIT-0",
"LicenseRef-scancode-bsd-atmel",
"LicenseRef-scancode-gary-s-brown",
"LicenseRef-scancode-proprietary-license",
"SunPro",
"MIT",
"LicenseRef-scancode-public-domain-disclaimer",
"LicenseRef-scancode-other-permissive",
"HPND",
"ISC",
"Apache-2.0",
"LicenseRef-scancode-public-domain",
"BSD-2-Clause",
"GPL-1.0-or-later",
"CC-BY-2.0",
"CC-BY-4.0"
] |
permissive
|
apache/nuttx
|
14519a7bff4a87935d94fb8fb2b19edb501c7cec
|
606b6d9310fb25c7d92c6f95bf61737e3c79fa0f
|
refs/heads/master
| 2023-08-25T06:55:45.822534
| 2023-08-23T16:03:31
| 2023-08-24T21:25:47
| 228,103,273
| 407
| 241
|
Apache-2.0
| 2023-09-14T18:26:05
| 2019-12-14T23:27:55
|
C
|
UTF-8
|
C
| false
| false
| 4,584
|
h
|
trace.h
|
/****************************************************************************
* include/nuttx/trace.h
*
* 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.
*
****************************************************************************/
#ifndef __INCLUDE_NUTTX_TRACE_H
#define __INCLUDE_NUTTX_TRACE_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/sched_note.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#ifdef CONFIG_TRACE
# define trace_begin(tag) sched_note_begin(tag)
# define trace_end(tag) sched_note_end(tag)
#else
# define trace_begin(tag)
# define trace_end(tag)
#endif
#ifdef CONFIG_TRACE_APP
# define app_trace_begin() trace_begin(NOTE_TAG_APP)
# define app_trace_end() trace_end(NOTE_TAG_APP)
#else
# define app_trace_begin()
# define app_trace_end()
#endif
#ifdef CONFIG_TRACE_ARCH
# define arch_trace_begin() trace_begin(NOTE_TAG_ARCH)
# define arch_trace_end() trace_end(NOTE_TAG_ARCH)
#else
# define arch_trace_begin()
# define arch_trace_end()
#endif
#ifdef CONFIG_TRACE_AUDIO
# define audio_trace_begin() trace_begin(NOTE_TAG_AUDIO)
# define audio_trace_end() trace_end(NOTE_TAG_AUDIO)
#else
# define audio_trace_begin()
# define audio_trace_end()
#endif
#ifdef CONFIG_TRACE_BOARDS
# define boards_trace_begin() trace_begin(NOTE_TAG_BOARDS)
# define boards_trace_end() trace_end(NOTE_TAG_BOARDS)
#else
# define boards_trace_begin()
# define boards_trace_end()
#endif
#ifdef CONFIG_TRACE_CRYPTO
# define crypto_trace_begin() trace_begin(NOTE_TAG_CRYPTO)
# define crypto_trace_end() trace_end(NOTE_TAG_CRYPTO)
#else
# define crypto_trace_begin()
# define crypto_trace_end()
#endif
#ifdef CONFIG_TRACE_DRIVERS
# define drivers_trace_begin() trace_begin(NOTE_TAG_DRIVERS)
# define drivers_trace_end() trace_end(NOTE_TAG_DRIVERS)
#else
# define drivers_trace_begin()
# define drivers_trace_end()
#endif
#ifdef CONFIG_TRACE_FS
# define fs_trace_begin() trace_begin(NOTE_TAG_FS)
# define fs_trace_end() trace_end(NOTE_TAG_FS)
#else
# define fs_trace_begin()
# define fs_trace_end()
#endif
#ifdef CONFIG_TRACE_GRAPHICS
# define graphics_trace_begin() trace_begin(NOTE_TAG_GRAPHICS)
# define graphics_trace_end() trace_end(NOTE_TAG_GRAPHICS)
#else
# define graphics_trace_begin()
# define graphics_trace_end()
#endif
#ifdef CONFIG_TRACE_LIBS
# define libs_trace_begin() trace_begin(NOTE_TAG_LIBS)
# define libs_trace_end() trace_end(NOTE_TAG_LIBS)
#else
# define libs_trace_begin()
# define libs_trace_end()
#endif
#ifdef CONFIG_TRACE_MM
# define mm_trace_begin() trace_begin(NOTE_TAG_MM)
# define mm_trace_end() trace_end(NOTE_TAG_MM)
#else
# define mm_trace_begin()
# define mm_trace_end()
#endif
#ifdef CONFIG_TRACE_NET
# define net_trace_begin() trace_begin(NOTE_TAG_NET)
# define net_trace_end() trace_end(NOTE_TAG_NET)
#else
# define net_trace_begin()
# define net_trace_end()
#endif
#ifdef CONFIG_TRACE_SCHED
# define sched_trace_begin() trace_begin(NOTE_TAG_SCHED)
# define sched_trace_end() trace_end(NOTE_TAG_SCHED)
#else
# define sched_trace_begin()
# define sched_trace_end()
#endif
#ifdef CONFIG_TRACE_VIDEO
# define video_trace_begin() trace_begin(NOTE_TAG_VIDEO)
# define video_trace_end() trace_end(NOTE_TAG_VIDEO)
#else
# define video_trace_begin()
# define video_trace_end()
#endif
#ifdef CONFIG_TRACE_WIRELESS
# define wireless_trace_begin() trace_begin(NOTE_TAG_WIRLESS)
# define wireless_trace_end() trace_end(NOTE_TAG_WIRLESS)
#else
# define wireless_trace_begin()
# define wireless_trace_end()
#endif
#endif /* __INCLUDE_NUTTX_TRACE_H */
|
bff9fa399fc574f91446a85ce0d89f102023267f
|
c9a59aa6cad390cf8d5c6216fb099c453bfe39fc
|
/include/wx/tls.h
|
5c317582dd9ff4f20e998feecac3cf424f765d6b
|
[] |
no_license
|
wxWidgets/wxWidgets
|
c4e771419c1559236dc9907baeb80b20d89131b4
|
8ca3d3bc75e8fa1b851cbaeaef128575fd8af0af
|
refs/heads/master
| 2023-08-31T21:26:31.145264
| 2023-08-29T11:06:06
| 2023-08-31T16:00:35
| 1,764,646
| 5,766
| 2,177
| null | 2023-09-14T18:04:44
| 2011-05-18T05:54:03
|
C++
|
UTF-8
|
C
| false
| false
| 1,513
|
h
|
tls.h
|
///////////////////////////////////////////////////////////////////////////////
// Name: wx/tls.h
// Purpose: Implementation of thread local storage (obsolete)
// Author: Vadim Zeitlin
// Created: 2008-08-08
// Copyright: (c) 2008 Vadim Zeitlin <vadim@wxwidgets.org>
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
#ifndef _WX_TLS_H_
#define _WX_TLS_H_
#include "wx/defs.h"
// ----------------------------------------------------------------------------
// check for compiler support of thread-specific variables
// ----------------------------------------------------------------------------
// when not using threads at all, there is no need for thread-specific
// values to be really thread-specific
#if !wxUSE_THREADS
#define wxTHREAD_SPECIFIC_DECL
#else
#define wxTHREAD_SPECIFIC_DECL thread_local
#endif
// ----------------------------------------------------------------------------
// define wxTLS_TYPE()
// ----------------------------------------------------------------------------
// All these preprocessor symbols are obsolete and defined only for
// compatibility: C++11 compilers always support variables with thread storage,
// so you should just always use thread_local directly in the new code instead.
#define wxHAS_COMPILER_TLS
#define wxTLS_TYPE(T) wxTHREAD_SPECIFIC_DECL T
#define wxTLS_TYPE_REF(T) T&
#define wxTLS_PTR(var) (&(var))
#define wxTLS_VALUE(var) (var)
#endif // _WX_TLS_H_
|
7e228f650f102c69164053546c8bc93a94b8f244
|
74d6907d48467117fa5dc66e8e22ae6c33a9ca53
|
/test/c/interpolation.c
|
9284bc376d09d74d94ba2be49fe34ccb1b699c7a
|
[
"MIT"
] |
permissive
|
msteinbeck/tinyspline
|
3276e69e8186ddda92170abf2869ecb51dad71f1
|
18b5a930cda18ccd39eb11dd981beae166350529
|
refs/heads/master
| 2023-09-06T03:13:00.008868
| 2023-07-13T21:35:57
| 2023-07-13T21:35:57
| 24,473,646
| 953
| 182
|
MIT
| 2023-07-13T21:35:58
| 2014-09-25T20:13:48
|
C
|
UTF-8
|
C
| false
| false
| 13,162
|
c
|
interpolation.c
|
#include <testutils.h>
void
interpolation_cubic_natural(CuTest *tc)
{
___SETUP___
tsBSpline spline = ts_bspline_init();
tsReal points[10];
tsReal dist, *ctrlp = NULL, *knots = NULL;
___GIVEN___
points[0] = 1.0; points[1] = -1.0;
points[2] = -1.0; points[3] = 2.0;
points[4] = 1.0; points[5] = 4.0;
points[6] = 4.0; points[7] = 3.0;
points[8] = 7.0; points[9] = 5.0;
___WHEN___
C(ts_bspline_interpolate_cubic_natural(points, 5, 2, &spline, &status))
___THEN___
CuAssertIntEquals(tc, 16,
(int) ts_bspline_num_control_points(&spline));
C(ts_bspline_control_points(&spline, &ctrlp, &status))
/* First bezier. */
dist = ts_distance_varargs(tc, 2, ctrlp, 1.0, -1.0);
CuAssertDblEquals(tc, 0, dist, POINT_EPSILON);
dist = ts_distance_varargs(tc, 2, ctrlp + 2, 0.0, 0.0);
CuAssertDblEquals(tc, 0, dist, POINT_EPSILON);
dist = ts_distance_varargs(tc, 2, ctrlp + 4, -1.0, 1.0);
CuAssertDblEquals(tc, 0, dist, POINT_EPSILON);
dist = ts_distance_varargs(tc, 2, ctrlp + 6, -1.0, 2.0);
CuAssertDblEquals(tc, 0, dist, POINT_EPSILON);
/* Second bezier. */
dist = ts_distance_varargs(tc, 2, ctrlp + 8, -1.0, 2.0);
CuAssertDblEquals(tc, 0, dist, POINT_EPSILON);
dist = ts_distance_varargs(tc, 2, ctrlp + 10, -1.0, 3.0);
CuAssertDblEquals(tc, 0, dist, POINT_EPSILON);
dist = ts_distance_varargs(tc, 2, ctrlp + 12, 0.0, 4.0);
CuAssertDblEquals(tc, 0, dist, POINT_EPSILON);
dist = ts_distance_varargs(tc, 2, ctrlp + 14, 1.0, 4.0);
CuAssertDblEquals(tc, 0, dist, POINT_EPSILON);
/* Third bezier. */
dist = ts_distance_varargs(tc, 2, ctrlp + 16, 1.0, 4.0);
CuAssertDblEquals(tc, 0, dist, POINT_EPSILON);
dist = ts_distance_varargs(tc, 2, ctrlp + 18, 2.0, 4.0);
CuAssertDblEquals(tc, 0, dist, POINT_EPSILON);
dist = ts_distance_varargs(tc, 2, ctrlp + 20, 3.0, 3.0);
CuAssertDblEquals(tc, 0, dist, POINT_EPSILON);
dist = ts_distance_varargs(tc, 2, ctrlp + 22, 4.0, 3.0);
CuAssertDblEquals(tc, 0, dist, POINT_EPSILON);
/* Forth bezier. */
dist = ts_distance_varargs(tc, 2, ctrlp + 24, 4.0, 3.0);
CuAssertDblEquals(tc, 0, dist, POINT_EPSILON);
dist = ts_distance_varargs(tc, 2, ctrlp + 26, 5.0, 3.0);
CuAssertDblEquals(tc, 0, dist, POINT_EPSILON);
dist = ts_distance_varargs(tc, 2, ctrlp + 28, 6.0, 4.0);
CuAssertDblEquals(tc, 0, dist, POINT_EPSILON);
dist = ts_distance_varargs(tc, 2, ctrlp + 30, 7.0, 5.0);
CuAssertDblEquals(tc, 0, dist, POINT_EPSILON);
CuAssertIntEquals(tc, 20,(int) ts_bspline_num_knots(&spline));
C(ts_bspline_knots(&spline, &knots, &status))
CuAssertDblEquals(tc, 0.0, knots[0], TS_KNOT_EPSILON);
CuAssertDblEquals(tc, 0.0, knots[1], TS_KNOT_EPSILON);
CuAssertDblEquals(tc, 0.0, knots[2], TS_KNOT_EPSILON);
CuAssertDblEquals(tc, 0.0, knots[3], TS_KNOT_EPSILON);
CuAssertDblEquals(tc, 0.25, knots[4], TS_KNOT_EPSILON);
CuAssertDblEquals(tc, 0.25, knots[5], TS_KNOT_EPSILON);
CuAssertDblEquals(tc, 0.25, knots[6], TS_KNOT_EPSILON);
CuAssertDblEquals(tc, 0.25, knots[7], TS_KNOT_EPSILON);
CuAssertDblEquals(tc, 0.5, knots[8], TS_KNOT_EPSILON);
CuAssertDblEquals(tc, 0.5, knots[9], TS_KNOT_EPSILON);
CuAssertDblEquals(tc, 0.5, knots[10], TS_KNOT_EPSILON);
CuAssertDblEquals(tc, 0.5, knots[11], TS_KNOT_EPSILON);
CuAssertDblEquals(tc, 0.75, knots[12], TS_KNOT_EPSILON);
CuAssertDblEquals(tc, 0.75, knots[13], TS_KNOT_EPSILON);
CuAssertDblEquals(tc, 0.75, knots[14], TS_KNOT_EPSILON);
CuAssertDblEquals(tc, 0.75, knots[15], TS_KNOT_EPSILON);
CuAssertDblEquals(tc, 1.0, knots[16], TS_KNOT_EPSILON);
CuAssertDblEquals(tc, 1.0, knots[17], TS_KNOT_EPSILON);
CuAssertDblEquals(tc, 1.0, knots[18], TS_KNOT_EPSILON);
CuAssertDblEquals(tc, 1.0, knots[19], TS_KNOT_EPSILON);
___TEARDOWN___
ts_bspline_free(&spline);
free(ctrlp);
free(knots);
}
void
interpolation_cubic_natural_single_point(CuTest *tc)
{
___SETUP___
tsBSpline spline = ts_bspline_init();
tsBSpline point = ts_bspline_init();
tsReal ctrlp[3] = { (tsReal) -5.0, (tsReal) 5.0, (tsReal) 3.2 };
___GIVEN___
C(ts_bspline_new(1, 3, 0, TS_CLAMPED, &point, &status))
C(ts_bspline_set_control_points(&point, ctrlp, &status))
___WHEN___
C(ts_bspline_interpolate_cubic_natural(
ctrlp, 1, 3, &spline, &status))
___THEN___
CuAssertIntEquals(tc, 3, (int) ts_bspline_degree(&spline));
CuAssertIntEquals(tc, 4, (int) ts_bspline_num_control_points(&spline));
CuAssertIntEquals(tc, 3, (int) ts_bspline_dimension(&spline));
assert_equal_shape(tc, &spline, &point);
___TEARDOWN___
ts_bspline_free(&spline);
ts_bspline_free(&point);
}
void
interpolation_issue32(CuTest *tc)
{
___SETUP___
tsBSpline spline = ts_bspline_init();
tsReal points[6];
tsReal dist, *ctrlp = NULL, *knots = NULL;
___GIVEN___
points[0] = -1.0; points[1] = 0.5;
points[2] = 0.0; points[3] = 0.0;
points[4] = 3.0; points[5] = 3.0;
___WHEN___
C(ts_bspline_interpolate_cubic_natural(points, 3, 2, &spline, &status))
___THEN___
CuAssertIntEquals(tc, 8, (int) ts_bspline_num_control_points(&spline));
C(ts_bspline_control_points(&spline, &ctrlp, &status))
/* First bezier. */
dist = ts_distance_varargs(tc, 2, ctrlp, -1.0, 0.5);
CuAssertDblEquals(tc, 0, dist, POINT_EPSILON);
dist = ts_distance_varargs(tc, 2, ctrlp + 2,
-0.83333335816860199, 0.041666667908430099);
CuAssertDblEquals(tc, 0, dist, POINT_EPSILON);
dist = ts_distance_varargs(tc, 2, ctrlp + 4,
-0.66666668653488159, -0.41666667908430099);
CuAssertDblEquals(tc, 0, dist, POINT_EPSILON);
dist = ts_distance_varargs(tc, 2, ctrlp + 6, 0.0, 0.0);
CuAssertDblEquals(tc, 0, dist, POINT_EPSILON);
/* Second bezier. */
dist = ts_distance_varargs(tc, 2, ctrlp + 8, 0.0, 0.0);
CuAssertDblEquals(tc, 0, dist, POINT_EPSILON);
dist = ts_distance_varargs(tc, 2, ctrlp + 10,
0.66666668653488159, 0.41666667908430099);
CuAssertDblEquals(tc, 0, dist, POINT_EPSILON);
dist = ts_distance_varargs(tc, 2, ctrlp + 12,
1.8333333879709244, 1.7083333842456341);
CuAssertDblEquals(tc, 0, dist, POINT_EPSILON);
dist = ts_distance_varargs(tc, 2, ctrlp + 14, 3.0, 3.0);
CuAssertDblEquals(tc, 0, dist, POINT_EPSILON);
CuAssertIntEquals(tc, 12,(int) ts_bspline_num_knots(&spline));
C(ts_bspline_knots(&spline, &knots, &status))
CuAssertDblEquals(tc, 0.0, knots[0], TS_KNOT_EPSILON);
CuAssertDblEquals(tc, 0.0, knots[1], TS_KNOT_EPSILON);
CuAssertDblEquals(tc, 0.0, knots[2], TS_KNOT_EPSILON);
CuAssertDblEquals(tc, 0.0, knots[3], TS_KNOT_EPSILON);
CuAssertDblEquals(tc, 0.5, knots[4], TS_KNOT_EPSILON);
CuAssertDblEquals(tc, 0.5, knots[5], TS_KNOT_EPSILON);
CuAssertDblEquals(tc, 0.5, knots[6], TS_KNOT_EPSILON);
CuAssertDblEquals(tc, 0.5, knots[7], TS_KNOT_EPSILON);
CuAssertDblEquals(tc, 1.0, knots[8], TS_KNOT_EPSILON);
CuAssertDblEquals(tc, 1.0, knots[9], TS_KNOT_EPSILON);
CuAssertDblEquals(tc, 1.0, knots[10], TS_KNOT_EPSILON);
CuAssertDblEquals(tc, 1.0, knots[11], TS_KNOT_EPSILON);
___TEARDOWN___
ts_bspline_free(&spline);
free(ctrlp);
free(knots);
}
void interpolation_issue226(CuTest *tc)
{
___SETUP___
tsBSpline spline = ts_bspline_init();
const tsReal *ctrlp;
tsReal dist;
___GIVEN___
tsReal points[9] = {
(tsReal) -30.1021881, (tsReal) 1.06910026, (tsReal) 13.1142778,
(tsReal) -30.2044067, (tsReal) 1.17131793, (tsReal) 13.1142778,
(tsReal) -30.3066235, (tsReal) 1.06910026, (tsReal) 13.1142778
};
___WHEN___
C(ts_bspline_interpolate_cubic_natural(points, 3, 3, &spline, &status))
___THEN___
CuAssertIntEquals(tc, 24, (int) ts_bspline_len_control_points(&spline));
ctrlp = ts_bspline_control_points_ptr(&spline);
/* First bezier. */
dist = ts_distance_varargs(tc, 3, ctrlp,
-30.1021881,
1.06910026,
13.1142778);
CuAssertDblEquals(tc, 0, dist, POINT_EPSILON);
dist = ts_distance_varargs(tc, 3, ctrlp + 3,
-30.136262014797236,
1.1202091283848326,
13.114278190835936);
CuAssertDblEquals(tc, 0, dist, POINT_EPSILON);
dist = ts_distance_varargs(tc, 3, ctrlp + 6,
-30.170335032479358,
1.1713179649079948,
13.114278190835936);
CuAssertDblEquals(tc, 0, dist, POINT_EPSILON);
dist = ts_distance_varargs(tc, 3, ctrlp + 9,
-30.204407600161467,
1.1713179649079948,
13.114278190835936);
CuAssertDblEquals(tc, 0, dist, POINT_EPSILON);
/* Second bezier. */
dist = ts_distance_varargs(tc, 3, ctrlp + 12,
-30.204407600161467,
1.1713179649079948,
13.114278190835936);
CuAssertDblEquals(tc, 0, dist, POINT_EPSILON);
dist = ts_distance_varargs(tc, 3, ctrlp + 15,
-30.238480167843576,
1.1713179649079948,
13.114278190835936);
CuAssertDblEquals(tc, 0, dist, POINT_EPSILON);
dist = ts_distance_varargs(tc, 3, ctrlp + 18,
-30.27255228552567,
1.1202091283848326,
13.114278190835936);
CuAssertDblEquals(tc, 0, dist, POINT_EPSILON);
dist = ts_distance_varargs(tc, 3, ctrlp + 21,
-30.3066235,
1.06910026,
13.1142778);
CuAssertDblEquals(tc, 0, dist, POINT_EPSILON);
___TEARDOWN___
ts_bspline_free(&spline);
}
void
interpolation_catmull_rom(CuTest *tc)
{
___SETUP___
tsBSpline spline = ts_bspline_init();
tsDeBoorNet net = ts_deboornet_init();
tsReal dist, eps, *result = NULL;
size_t i;
___GIVEN___
/* POINT_EPSILON is slightly too small to compare the interpolated
* points with their reference points. Thus, we use an adjusted epsilon
* environment in this test to assert the distances. */
eps = (tsReal) 0.000017; /* from 1e-5f (0.00001) */
#ifdef TINYSPLINE_FLOAT_PRECISION
eps = (tsReal) 0.0016; /* from 1e-3f (0.001) */
#endif
/* Points to be interpolated. */
tsReal points[14] = {
0.0, 1.5, /* P1 */
2.0, 2.0, /* P2 */
3.0, 1.0, /* P3 */
4.0, 0.5, /* P4 */
5.0, 1.0, /* P5 */
6.0, 2.0, /* P6 */
7.0, 3.0 /* P7 */
};
/* Generated with catmullrom.py (alpha = 0.5). */
tsReal samples[800] = {
#include "res/interpolation_catmull_rom.txt"
};
___WHEN___
C(ts_bspline_interpolate_catmull_rom(
points, 7, 2, 0.5, NULL, NULL,
POINT_EPSILON, &spline, &status))
___THEN___
for (i = 0; i < 400; i++) {
C(ts_bspline_bisect(&spline,
samples[i * 2],
POINT_EPSILON,
1, /* persnickety */
0, /* index */
1, /* ascending */
50, /* max_iter */
&net,
&status))
C(ts_deboornet_result(&net, &result, &status))
dist = ts_distance(samples + i*2, result, 2);
CuAssertDblEquals(tc, 0, dist, eps);
ts_deboornet_free(&net);
free(result);
}
___TEARDOWN___
ts_bspline_free(&spline);
}
void
interpolation_catmull_rom_single_point(CuTest *tc)
{
___SETUP___
tsBSpline spline = ts_bspline_init();
tsBSpline point = ts_bspline_init();
tsReal ctrlp[2] = { 10.0, 10.0 };
___GIVEN___
C(ts_bspline_new(1, 2, 0, TS_CLAMPED, &point, &status))
C(ts_bspline_set_control_points(&point, ctrlp, &status))
___WHEN___
C(ts_bspline_interpolate_catmull_rom(
ctrlp, 1, 2, 0.5, NULL, NULL,
POINT_EPSILON, &spline, &status))
___THEN___
CuAssertIntEquals(tc, 3, (int) ts_bspline_degree(&spline));
CuAssertIntEquals(tc, 4, (int) ts_bspline_num_control_points(&spline));
CuAssertIntEquals(tc, 2, (int) ts_bspline_dimension(&spline));
assert_equal_shape(tc, &spline, &point);
___TEARDOWN___
ts_bspline_free(&spline);
ts_bspline_free(&point);
}
void
interpolation_catmull_rom_same_point(CuTest *tc)
{
___SETUP___
tsBSpline spline = ts_bspline_init();
tsBSpline point = ts_bspline_init();
tsReal ctrlp[6] = { (tsReal) 1.0, (tsReal) 2.0,
(tsReal) 1.1, (tsReal) 2.0,
(tsReal) 1.0, (tsReal) 2.1 };
___GIVEN___
C(ts_bspline_new(1, 2, 0, TS_CLAMPED, &point, &status))
C(ts_bspline_set_control_points(&point, ctrlp, &status))
___WHEN___
C(ts_bspline_interpolate_catmull_rom(
ctrlp, 3, 2, 0.5, NULL, NULL,
(tsReal) 0.2, &spline, &status))
___THEN___
CuAssertIntEquals(tc, 3, (int) ts_bspline_degree(&spline));
CuAssertIntEquals(tc, 4, (int) ts_bspline_num_control_points(&spline));
CuAssertIntEquals(tc, 2, (int) ts_bspline_dimension(&spline));
assert_equal_shape(tc, &spline, &point);
___TEARDOWN___
ts_bspline_free(&spline);
ts_bspline_free(&point);
}
CuSuite* get_interpolation_suite()
{
CuSuite* suite = CuSuiteNew();
SUITE_ADD_TEST(suite, interpolation_cubic_natural);
SUITE_ADD_TEST(suite, interpolation_cubic_natural_single_point);
SUITE_ADD_TEST(suite, interpolation_issue226);
SUITE_ADD_TEST(suite, interpolation_issue32);
SUITE_ADD_TEST(suite, interpolation_catmull_rom);
SUITE_ADD_TEST(suite, interpolation_catmull_rom_single_point);
SUITE_ADD_TEST(suite, interpolation_catmull_rom_same_point);
return suite;
}
|
277de4fa74792e40eb4eb6f2fce07024a1e51c03
|
99bdb3251fecee538e0630f15f6574054dfc1468
|
/bsp/imxrt/libraries/MIMXRT1170/MIMXRT1176/drivers/fsl_pmu.c
|
3cf953f29437f7566beea41d30567970b1ff4bdc
|
[
"Zlib",
"LicenseRef-scancode-proprietary-license",
"MIT",
"BSD-3-Clause",
"X11",
"BSD-4-Clause-UC",
"LicenseRef-scancode-unknown-license-reference",
"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
| 37,674
|
c
|
fsl_pmu.c
|
/*
* Copyright 2020-2021 NXP
* All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include "fsl_pmu.h"
#include "fsl_anatop_ai.h"
/* Component ID definition, used by tools. */
#ifndef FSL_COMPONENT_ID
#define FSL_COMPONENT_ID "platform.drivers.pmu_1"
#endif
/*******************************************************************************
* Definitions
******************************************************************************/
#define PMU_LDO_LPSR_DIG_TRG_SPX_REG_SETPOINT_COUNTS 4U
#define PMU_LDO_LPSR_DIG_TRG_SPX_VOLTAGE_SETPOINTX_BIT_WIDTH 8UL
#define PMU_POWER_DETECT_CTRL_REGISTER (ANADIG_PMU->PMU_POWER_DETECT_CTRL)
#define PMU_BIAS_CTRL_WB_CFG_1P8_WELL_SELECT_MASK (0x1U)
#define PMU_BIAS_CTRL_WB_CFG_1P8_VOLTAGE_THRESHOLD_MASK (0x2U)
#define PMU_BIAS_CTRL_WB_CFG_1P8_VOLTAGE_THRESHOLD_SHIFT 1U
#define PMU_BIAS_CTRL_WB_CFG_1P8_VOLTAGE_THRESHOLD(x) \
(((uint32_t)(((uint32_t)(x)) << PMU_BIAS_CTRL_WB_CFG_1P8_VOLTAGE_THRESHOLD_SHIFT)) & \
PMU_BIAS_CTRL_WB_CFG_1P8_VOLTAGE_THRESHOLD_MASK)
#define PMU_BIAS_CTRL_WB_CFG_1P8_DRIVE_STRENGTH_MASK (0x1CU)
#define PMU_BIAS_CTRL_WB_CFG_1P8_DRIVE_STRENGTH_SHIFT 2U
#define PMU_BIAS_CTRL_WB_CFG_1P8_DRIVE_STRENGTH(x) \
(((uint32_t)(((uint32_t)(x)) << PMU_BIAS_CTRL_WB_CFG_1P8_DRIVE_STRENGTH_SHIFT)) & \
PMU_BIAS_CTRL_WB_CFG_1P8_DRIVE_STRENGTH_MASK)
#define PMU_BIAS_CTRL_WB_CFG_1P8_OSCILLATOR_FREQ_MASK (0x1E0U)
#define PMU_BIAS_CTRL_WB_CFG_1P8_OSCILLATOR_FREQ_SHIFT 5U
#define PMU_BIAS_CTRL_WB_CFG_1P8_OSCILLATOR_FREQ(x) \
(((uint32_t)(((uint32_t)(x)) << PMU_BIAS_CTRL_WB_CFG_1P8_OSCILLATOR_FREQ_SHIFT)) & \
PMU_BIAS_CTRL_WB_CFG_1P8_OSCILLATOR_FREQ_MASK)
#define PMU_GET_ANADIG_PMU_MEMBER_ADDRESS(member) \
((uint32_t)((ANADIG_PMU_BASE) + (uint32_t)offsetof(ANADIG_PMU_Type, member)))
#define PMU_LDO_ENABLE_SETPOINT_REGISTERS \
{ \
PMU_GET_ANADIG_PMU_MEMBER_ADDRESS(LDO_PLL_ENABLE_SP), \
PMU_GET_ANADIG_PMU_MEMBER_ADDRESS(LDO_LPSR_ANA_ENABLE_SP), \
PMU_GET_ANADIG_PMU_MEMBER_ADDRESS(LDO_LPSR_DIG_ENABLE_SP), 0UL \
}
#define PMU_LDO_LP_MODE_EN_SETPOINT_REGISTERS \
{ \
0UL, PMU_GET_ANADIG_PMU_MEMBER_ADDRESS(LDO_LPSR_ANA_LP_MODE_SP), \
PMU_GET_ANADIG_PMU_MEMBER_ADDRESS(LDO_LPSR_DIG_LP_MODE_SP), 0UL \
}
#define PMU_LDO_TRACKING_EN_SETPOINT_REGISTERS \
{ \
0UL, PMU_GET_ANADIG_PMU_MEMBER_ADDRESS(LDO_LPSR_ANA_TRACKING_EN_SP), \
PMU_GET_ANADIG_PMU_MEMBER_ADDRESS(LDO_LPSR_DIG_TRACKING_EN_SP), 0UL \
}
#define PMU_LDO_BYPASS_EN_SETPOINT_REGISTERS \
{ \
0UL, PMU_GET_ANADIG_PMU_MEMBER_ADDRESS(LDO_LPSR_ANA_BYPASS_EN_SP), \
PMU_GET_ANADIG_PMU_MEMBER_ADDRESS(LDO_LPSR_DIG_BYPASS_EN_SP), 0UL \
}
#define PMU_LDO_STBY_EN_REGISTERS \
{ \
PMU_GET_ANADIG_PMU_MEMBER_ADDRESS(PLL_LDO_STBY_EN_SP), \
PMU_GET_ANADIG_PMU_MEMBER_ADDRESS(LDO_LPSR_ANA_STBY_EN_SP), \
PMU_GET_ANADIG_PMU_MEMBER_ADDRESS(LDO_LPSR_DIG_STBY_EN_SP), 0UL \
}
#define PMU_LPSR_DIG_TRG_REGISTERS \
{ \
PMU_GET_ANADIG_PMU_MEMBER_ADDRESS(LDO_LPSR_DIG_TRG_SP0), \
PMU_GET_ANADIG_PMU_MEMBER_ADDRESS(LDO_LPSR_DIG_TRG_SP1), \
PMU_GET_ANADIG_PMU_MEMBER_ADDRESS(LDO_LPSR_DIG_TRG_SP2), \
PMU_GET_ANADIG_PMU_MEMBER_ADDRESS(LDO_LPSR_DIG_TRG_SP3) \
}
#if (defined(PMU_HAS_FBB) && PMU_HAS_FBB)
#define PMU_BODY_BIAS_ENABLE_REGISTERS \
{ \
PMU_GET_ANADIG_PMU_MEMBER_ADDRESS(FBB_M7_ENABLE_SP), PMU_GET_ANADIG_PMU_MEMBER_ADDRESS(RBB_SOC_ENABLE_SP), \
PMU_GET_ANADIG_PMU_MEMBER_ADDRESS(RBB_LPSR_ENABLE_SP) \
}
#else
#define PMU_BODY_BIAS_ENABLE_REGISTERS \
{ \
PMU_GET_ANADIG_PMU_MEMBER_ADDRESS(RBB_SOC_ENABLE_SP), PMU_GET_ANADIG_PMU_MEMBER_ADDRESS(RBB_LPSR_ENABLE_SP) \
}
#endif /* PMU_HAS_FBB */
#if (defined(PMU_HAS_FBB) && PMU_HAS_FBB)
#define PMU_BODY_BIAS_STBY_EN_REGISTERS \
{ \
PMU_GET_ANADIG_PMU_MEMBER_ADDRESS(FBB_M7_STBY_EN_SP), PMU_GET_ANADIG_PMU_MEMBER_ADDRESS(RBB_SOC_STBY_EN_SP), \
PMU_GET_ANADIG_PMU_MEMBER_ADDRESS(RBB_LPSR_STBY_EN_SP) \
}
#else
#define PMU_BODY_BIAS_STBY_EN_REGISTERS \
{ \
PMU_GET_ANADIG_PMU_MEMBER_ADDRESS(RBB_SOC_STBY_EN_SP), PMU_GET_ANADIG_PMU_MEMBER_ADDRESS(RBB_LPSR_STBY_EN_SP) \
}
#endif /* PMU_HAS_FBB */
#if (defined(PMU_HAS_FBB) && PMU_HAS_FBB)
#define PMU_BODY_BIAS_CONFIGURE_REGISTERS \
{ \
PMU_GET_ANADIG_PMU_MEMBER_ADDRESS(FBB_M7_CONFIGURE), PMU_GET_ANADIG_PMU_MEMBER_ADDRESS(RBB_SOC_CONFIGURE), \
PMU_GET_ANADIG_PMU_MEMBER_ADDRESS(RBB_LPSR_CONFIGURE) \
}
#else
#define PMU_BODY_BIAS_CONFIGURE_REGISTERS \
{ \
PMU_GET_ANADIG_PMU_MEMBER_ADDRESS(RBB_SOC_CONFIGURE), PMU_GET_ANADIG_PMU_MEMBER_ADDRESS(RBB_LPSR_CONFIGURE) \
}
#endif /* PMU_HAS_FBB */
/*******************************************************************************
* Prototypes
******************************************************************************/
/*******************************************************************************
* Variables
******************************************************************************/
/*******************************************************************************
* Code
******************************************************************************/
/*!
* brief Selects the control mode of the PLL LDO.
*
* param base PMU peripheral base address.
* param mode The control mode of the PLL LDO. Please refer to pmu_control_mode_t.
*/
void PMU_SetPllLdoControlMode(ANADIG_PMU_Type *base, pmu_control_mode_t mode)
{
if (mode == kPMU_StaticMode)
{
base->PMU_LDO_PLL &= ~ANADIG_PMU_PMU_LDO_PLL_LDO_PLL_CONTROL_MODE_MASK;
}
else
{
base->PMU_LDO_PLL |= ANADIG_PMU_PMU_LDO_PLL_LDO_PLL_CONTROL_MODE_MASK;
}
}
/*!
* brief Switches the PLL LDO from Static/Software Mode to GPC/Hardware Mode.
*
* param base PMU peripheral base address.
*/
void PMU_SwitchPllLdoToGPCMode(ANADIG_PMU_Type *base)
{
if ((base->LDO_PLL_ENABLE_SP & ANADIG_PMU_LDO_PLL_ENABLE_SP_ON_OFF_SETPOINT0_MASK) != 0UL)
{
base->PMU_LDO_PLL |= ANADIG_PMU_PMU_LDO_PLL_LDO_PLL_ENABLE_MASK;
}
else
{
base->PMU_LDO_PLL &= ~ANADIG_PMU_PMU_LDO_PLL_LDO_PLL_ENABLE_MASK;
}
}
/*!
* brief Enables PLL LDO via AI interface in Static/Software mode.
*
* param base PMU peripheral base address.
*/
void PMU_StaticEnablePllLdo(ANADIG_PMU_Type *base)
{
uint32_t temp32;
temp32 = ANATOP_AI_Read(kAI_Itf_Ldo, kAI_PHY_LDO_CTRL0);
if (temp32 !=
(AI_PHY_LDO_CTRL0_OUTPUT_TRG(0x10) | AI_PHY_LDO_CTRL0_LINREG_EN_MASK | AI_PHY_LDO_CTRL0_LIMIT_EN_MASK))
{
ANATOP_AI_Write(
kAI_Itf_Ldo, kAI_PHY_LDO_CTRL0,
(AI_PHY_LDO_CTRL0_OUTPUT_TRG(0x10) | AI_PHY_LDO_CTRL0_LINREG_EN_MASK | AI_PHY_LDO_CTRL0_LIMIT_EN_MASK));
SDK_DelayAtLeastUs(1, SDK_DEVICE_MAXIMUM_CPU_CLOCK_FREQUENCY);
/* Enable Voltage Reference for PLLs before those PLLs were enabled. */
base->PMU_REF_CTRL |= ANADIG_PMU_PMU_REF_CTRL_EN_PLL_VOL_REF_BUFFER_MASK;
}
}
/*!
* brief Disables PLL LDO via AI interface in Static/Software mode.
*/
void PMU_StaticDisablePllLdo(void)
{
ANATOP_AI_Write(kAI_Itf_Ldo, kAI_PHY_LDO_CTRL0, 0UL);
}
/*!
* brief Selects the control mode of the LPSR ANA LDO.
*
* param base PMU peripheral base address.
* param mode The control mode of the LPSR ANA LDO. Please refer to pmu_control_mode_t.
*/
void PMU_SetLpsrAnaLdoControlMode(ANADIG_LDO_SNVS_Type *base, pmu_control_mode_t mode)
{
if (mode == kPMU_StaticMode)
{
base->PMU_LDO_LPSR_ANA &= ~ANADIG_LDO_SNVS_PMU_LDO_LPSR_ANA_LPSR_ANA_CONTROL_MODE_MASK;
}
else
{
base->PMU_LDO_LPSR_ANA |= ANADIG_LDO_SNVS_PMU_LDO_LPSR_ANA_LPSR_ANA_CONTROL_MODE_MASK;
}
}
/*!
* brief Sets the Bypass mode of the LPSR ANA LDO.
*
* param base ANADIG_LDO_SNVS peripheral base address.
* param enable Enable/Disable bypass mode.
* - \b true Enable LPSR ANA Bypass mode.
* - \b false Disable LPSR ANA Bypass mode.
*/
void PMU_StaticEnableLpsrAnaLdoBypassMode(ANADIG_LDO_SNVS_Type *base, bool enable)
{
if (enable == false)
{
/* Enable LPSR ANA LDO and HP mode. */
base->PMU_LDO_LPSR_ANA &=
~(ANADIG_LDO_SNVS_PMU_LDO_LPSR_ANA_REG_LP_EN_MASK | ANADIG_LDO_SNVS_PMU_LDO_LPSR_ANA_REG_DISABLE_MASK);
SDK_DelayAtLeastUs(1000, SDK_DEVICE_MAXIMUM_CPU_CLOCK_FREQUENCY);
/* Clear Bypass. */
base->PMU_LDO_LPSR_ANA &= ~(ANADIG_LDO_SNVS_PMU_LDO_LPSR_ANA_BYPASS_MODE_EN_MASK);
SDK_DelayAtLeastUs(1000, SDK_DEVICE_MAXIMUM_CPU_CLOCK_FREQUENCY);
/* Disable Tracking mode. */
base->PMU_LDO_LPSR_ANA &= ~ANADIG_LDO_SNVS_PMU_LDO_LPSR_ANA_TRACK_MODE_EN_MASK;
}
else
{
/* Enable HP mode. */
base->PMU_LDO_LPSR_ANA &= ~ANADIG_LDO_SNVS_PMU_LDO_LPSR_ANA_REG_LP_EN_MASK;
SDK_DelayAtLeastUs(1000, SDK_DEVICE_MAXIMUM_CPU_CLOCK_FREQUENCY);
/* Enable Tracking mode. */
base->PMU_LDO_LPSR_ANA |= ANADIG_LDO_SNVS_PMU_LDO_LPSR_ANA_TRACK_MODE_EN_MASK;
SDK_DelayAtLeastUs(1000, SDK_DEVICE_MAXIMUM_CPU_CLOCK_FREQUENCY);
/* Enabled Bypass. */
base->PMU_LDO_LPSR_ANA |= ANADIG_LDO_SNVS_PMU_LDO_LPSR_ANA_BYPASS_MODE_EN_MASK;
SDK_DelayAtLeastUs(1000, SDK_DEVICE_MAXIMUM_CPU_CLOCK_FREQUENCY);
/* Disable LPSR ANA LDO. */
base->PMU_LDO_LPSR_ANA |= ANADIG_LDO_SNVS_PMU_LDO_LPSR_ANA_REG_DISABLE_MASK;
}
}
/*!
* brief Fill the LPSR ANA LDO configuration structure with default settings.
*
* The default values are:
* code
* config->mode = kPMU_HighPowerMode;
config->enable2mALoad = true;
config->enable20uALoad = false;
config->enable4mALoad = true;
config->enableStandbyMode = false;
config->driverStrength = kPMU_LpsrAnaLdoDriverStrength0;
config->brownOutDetectorConfig = kPMU_LpsrAnaLdoBrownOutDetectorDisable;
config->chargePumpCurrent = kPMU_LpsrAnaChargePump300nA;
config->outputRange = kPMU_LpsrAnaLdoOutputFrom1P77To1P83;
* endcode
*
* param config Pointer to the structure pmu_static_lpsr_ana_ldo_config_t. Please refer to @ref
* pmu_static_lpsr_ana_ldo_config_t.
*/
void PMU_StaticGetLpsrAnaLdoDefaultConfig(pmu_static_lpsr_ana_ldo_config_t *config)
{
assert(config != NULL);
(void)memset(config, 0, sizeof(*config));
config->mode = kPMU_HighPowerMode;
config->enable2mALoad = true;
config->enable20uALoad = false;
config->enable4mALoad = true;
config->enableStandbyMode = false;
}
/*!
* brief Initialize the LPSR ANA LDO in Static/Sofware Mode.
*
* param base ANADIG_LDO_SNVS peripheral base address.
* param config Pointer to the structure pmu_static_lpsr_ana_ldo_config_t. Please refer to @ref
* pmu_static_lpsr_ana_ldo_config_t.
*/
void PMU_StaticLpsrAnaLdoInit(ANADIG_LDO_SNVS_Type *base, const pmu_static_lpsr_ana_ldo_config_t *config)
{
assert(config != NULL);
uint32_t regValue = base->PMU_LDO_LPSR_ANA;
regValue &=
~(ANADIG_LDO_SNVS_PMU_LDO_LPSR_ANA_REG_LP_EN_MASK | ANADIG_LDO_SNVS_PMU_LDO_LPSR_ANA_PULL_DOWN_2MA_EN_MASK |
ANADIG_LDO_SNVS_PMU_LDO_LPSR_ANA_ALWAYS_4MA_PULLDOWN_EN_MASK |
ANADIG_LDO_SNVS_PMU_LDO_LPSR_ANA_PULL_DOWN_20UA_EN_MASK | ANADIG_LDO_SNVS_PMU_LDO_LPSR_ANA_STANDBY_EN_MASK);
if ((config->mode) == kPMU_LowPowerMode)
{
regValue |= ANADIG_LDO_SNVS_PMU_LDO_LPSR_ANA_REG_LP_EN_MASK;
}
regValue |= ANADIG_LDO_SNVS_PMU_LDO_LPSR_ANA_PULL_DOWN_2MA_EN(config->enable2mALoad);
regValue |= ANADIG_LDO_SNVS_PMU_LDO_LPSR_ANA_ALWAYS_4MA_PULLDOWN_EN(config->enable4mALoad);
regValue |= ANADIG_LDO_SNVS_PMU_LDO_LPSR_ANA_PULL_DOWN_20UA_EN(config->enable20uALoad);
regValue |= ANADIG_LDO_SNVS_PMU_LDO_LPSR_ANA_STANDBY_EN(config->enableStandbyMode);
base->PMU_LDO_LPSR_ANA = regValue;
/* Enable LPSR ANA DIG. */
base->PMU_LDO_LPSR_ANA &= ~ANADIG_LDO_SNVS_PMU_LDO_LPSR_ANA_REG_DISABLE_MASK;
}
/*!
* brief Disable the output of LPSR ANA LDO.
*
* param base ANADIG_LDO_SNVS peripheral base address.
*/
void PMU_StaticLpsrAnaLdoDeinit(ANADIG_LDO_SNVS_Type *base)
{
/* Disable LPSR ANA LDO. */
base->PMU_LDO_LPSR_ANA |= ANADIG_LDO_SNVS_PMU_LDO_LPSR_ANA_REG_DISABLE_MASK;
}
/*!
* brief Selects the control mode of the LPSR DIG LDO.
*
* param base ANADIG_LDO_SNVS peripheral base address.
* param mode The control mode of the LPSR DIG LDO. Please refer to pmu_control_mode_t.
*/
void PMU_SetLpsrDigLdoControlMode(ANADIG_LDO_SNVS_Type *base, pmu_control_mode_t mode)
{
if (mode == kPMU_StaticMode)
{
base->PMU_LDO_LPSR_DIG &= ~ANADIG_LDO_SNVS_PMU_LDO_LPSR_DIG_LPSR_DIG_CONTROL_MODE_MASK;
}
else
{
base->PMU_LDO_LPSR_DIG |= ANADIG_LDO_SNVS_PMU_LDO_LPSR_DIG_LPSR_DIG_CONTROL_MODE_MASK;
}
}
/*!
* brief Turn on/off Bypass mode of the LPSR DIG LDO in Static/Software mode.
*
* param base ANADIG_LDO_SNVS peripheral base address.
* param enable
* true - Turn on Bypass mode of the LPSR DIG LDO.
* false - Turn off Bypass mode of the LPSR DIG LDO.
*/
void PMU_StaticEnableLpsrDigLdoBypassMode(ANADIG_LDO_SNVS_Type *base, bool enable)
{
if (enable)
{
/* tracking */
base->PMU_LDO_LPSR_DIG |= ANADIG_LDO_SNVS_PMU_LDO_LPSR_DIG_TRACKING_MODE_MASK;
SDK_DelayAtLeastUs(1000, SDK_DEVICE_MAXIMUM_CPU_CLOCK_FREQUENCY);
/* set BYPASS */
base->PMU_LDO_LPSR_DIG |= ANADIG_LDO_SNVS_PMU_LDO_LPSR_DIG_BYPASS_MODE_MASK;
SDK_DelayAtLeastUs(1000, SDK_DEVICE_MAXIMUM_CPU_CLOCK_FREQUENCY);
/* Disable LPSR DIG LDO */
base->PMU_LDO_LPSR_DIG &= ~ANADIG_LDO_SNVS_PMU_LDO_LPSR_DIG_REG_EN_MASK;
}
else
{
/* Enable LPSR DIG LDO and HP mode */
base->PMU_LDO_LPSR_DIG |= (ANADIG_LDO_SNVS_PMU_LDO_LPSR_DIG_REG_EN_MASK);
SDK_DelayAtLeastUs(1000, SDK_DEVICE_MAXIMUM_CPU_CLOCK_FREQUENCY);
/* Clear BYPASS */
base->PMU_LDO_LPSR_DIG &= ~ANADIG_LDO_SNVS_PMU_LDO_LPSR_DIG_BYPASS_MODE_MASK;
SDK_DelayAtLeastUs(1000, SDK_DEVICE_MAXIMUM_CPU_CLOCK_FREQUENCY);
/* Disable tracking */
base->PMU_LDO_LPSR_DIG &= ~ANADIG_LDO_SNVS_PMU_LDO_LPSR_DIG_TRACKING_MODE_MASK;
}
}
/*!
* @brief Gets the default configuration of LPSR DIG LDO.
*
* @param config Pointer to the structure pmu_static_lpsr_dig_config_t. Please refer to @ref
* pmu_static_lpsr_dig_config_t.
*/
void PMU_StaticGetLpsrDigLdoDefaultConfig(pmu_static_lpsr_dig_config_t *config)
{
assert(config != NULL);
(void)memset(config, 0, sizeof(*config));
config->voltageStepTime = kPMU_LpsrDigVoltageStepInc50us;
config->targetVoltage = kPMU_LpsrDigTargetStableVoltage1P0V;
}
/*!
* @brief Initialize the LPSR DIG LDO in static mode.
*
* @param base ANADIG_LDO_SNVS peripheral base address.
* @param config Pointer to the structure pmu_static_lpsr_dig_config_t. Please refer to @ref
* pmu_static_lpsr_dig_config_t.
*/
void PMU_StaticLpsrDigLdoInit(ANADIG_LDO_SNVS_Type *base, const pmu_static_lpsr_dig_config_t *config)
{
assert(config != NULL);
uint32_t temp32 = base->PMU_LDO_LPSR_DIG;
temp32 &= ~ANADIG_LDO_SNVS_PMU_LDO_LPSR_DIG_VOLTAGE_SELECT_MASK;
temp32 |= ANADIG_LDO_SNVS_PMU_LDO_LPSR_DIG_VOLTAGE_SELECT(config->targetVoltage);
base->PMU_LDO_LPSR_DIG = temp32;
temp32 = base->PMU_LDO_LPSR_DIG_2;
temp32 &= ~ANADIG_LDO_SNVS_PMU_LDO_LPSR_DIG_2_VOLTAGE_STEP_INC_MASK;
temp32 |= ANADIG_LDO_SNVS_PMU_LDO_LPSR_DIG_2_VOLTAGE_STEP_INC(config->voltageStepTime);
base->PMU_LDO_LPSR_DIG_2 = temp32;
/* Enable LPSR DIG LDO. */
base->PMU_LDO_LPSR_DIG |= ANADIG_LDO_SNVS_PMU_LDO_LPSR_DIG_REG_EN_MASK;
SDK_DelayAtLeastUs(125U, SDK_DEVICE_MAXIMUM_CPU_CLOCK_FREQUENCY);
PMU_POWER_DETECT_CTRL_REGISTER |= ANADIG_PMU_PMU_POWER_DETECT_CTRL_CKGB_LPSR1P0_MASK;
}
/*!
* @brief Disable the LPSR DIG LDO.
*
* @param base ANADIG_LDO_SNVS peripheral base address.
*/
void PMU_StaticLpsrDigLdoDeinit(ANADIG_LDO_SNVS_Type *base)
{
PMU_POWER_DETECT_CTRL_REGISTER &= ~ANADIG_PMU_PMU_POWER_DETECT_CTRL_CKGB_LPSR1P0_MASK;
base->PMU_LDO_LPSR_DIG &= ~ANADIG_LDO_SNVS_PMU_LDO_LPSR_DIG_REG_EN_MASK;
}
/*!
* brief Sets the voltage step of LPSR DIG LDO in the certain setpoint during GPC mode.
*
* note The function provides the feature to set the voltage step to the different setpoints.
*
* param setpointMap The map of setpoints should be the OR'ed Value of _pmu_setpoint_map.
* param voltageStep The voltage step to be set.
*/
void PMU_GPCSetLpsrDigLdoTargetVoltage(uint32_t setpointMap, pmu_lpsr_dig_target_output_voltage_t voltageValue)
{
uint32_t regValue = 0UL;
const uint32_t lpsrDigTrgRegArray[] = PMU_LPSR_DIG_TRG_REGISTERS;
uint8_t regIndex;
uint8_t temp8;
uint32_t i;
for (regIndex = 0U; regIndex < ARRAY_SIZE(lpsrDigTrgRegArray); regIndex++)
{
temp8 = (((uint8_t)(setpointMap >> (PMU_LDO_LPSR_DIG_TRG_SPX_REG_SETPOINT_COUNTS * regIndex))) & 0xFU);
if (temp8 != 0UL)
{
regValue = (*(volatile uint32_t *)lpsrDigTrgRegArray[regIndex]);
for (i = 0U; i < PMU_LDO_LPSR_DIG_TRG_SPX_REG_SETPOINT_COUNTS; i++)
{
if (((temp8 >> (1U * i)) & 0x1U) != 0U)
{
regValue &= ~(0xFFUL << (PMU_LDO_LPSR_DIG_TRG_SPX_VOLTAGE_SETPOINTX_BIT_WIDTH * i));
regValue |= (uint32_t)voltageValue << (PMU_LDO_LPSR_DIG_TRG_SPX_VOLTAGE_SETPOINTX_BIT_WIDTH * i);
}
}
(*(volatile uint32_t *)lpsrDigTrgRegArray[regIndex]) = regValue;
}
}
}
/*!
* brief Gets the default config of the SNVS DIG LDO.
*
* The default values are:
* code
* config->mode = kPMU_LowPowerMode;
* config->chargePumpCurrent = kPMU_SnvsDigChargePump12P5nA;
* config->dischargeResistorValue = kPMU_SnvsDigDischargeResistor15K;
* config->trimValue = 0U;
* config->enablePullDown = true;
* config->enableLdoStable = false;
* endcode
*
* param config Pointer to the structure pmu_snvs_dig_config_t. Please refer to pmu_snvs_dig_config_t.
*/
void PMU_GetSnvsDigLdoDefaultConfig(pmu_snvs_dig_config_t *config)
{
assert(config != NULL);
(void)memset(config, 0, sizeof(*config));
config->mode = kPMU_LowPowerMode;
config->chargePumpCurrent = kPMU_SnvsDigChargePump12P5nA;
config->dischargeResistorValue = kPMU_SnvsDigDischargeResistor15K;
config->trimValue = 0U;
config->enablePullDown = true;
config->enableLdoStable = false;
}
/*!
* brief Initialize the SNVS DIG LDO.
*
* param base LDO SNVS DIG peripheral base address.
* param mode Used to control LDO power mode, please refer to pmu_ldo_operate_mode_t.
*/
void PMU_SnvsDigLdoInit(ANADIG_LDO_SNVS_DIG_Type *base, pmu_ldo_operate_mode_t mode)
{
uint32_t temp32 = base->PMU_LDO_SNVS_DIG;
temp32 &= ~(ANADIG_LDO_SNVS_DIG_PMU_LDO_SNVS_DIG_REG_LP_EN_MASK);
temp32 |= (ANADIG_LDO_SNVS_DIG_PMU_LDO_SNVS_DIG_REG_LP_EN(mode) | ANADIG_LDO_SNVS_DIG_PMU_LDO_SNVS_DIG_REG_EN_MASK);
base->PMU_LDO_SNVS_DIG = temp32;
}
/*!
* brief Controls the ON/OFF of the selected LDO in the certain setpoints with GPC mode.
*
* param name The name of the selected ldo. Please see the enumeration pmu_ldo_name_t for details.
* param setpointMap The map of setpoints should be the OR'ed Value of @ref _pmu_setpoint_map, 1b'1
* means enable specific ldo in that setpoint.
* For example, the code PMU_GPCEnableLdo(kPMU_PllLdo, 0x1U) means enable PLL LDO in setpoint 0, disable
* PLL LDO in other setpoint.
*/
void PMU_GPCEnableLdo(pmu_ldo_name_t name, uint32_t setpointMap)
{
assert(name != kPMU_SnvsDigLdo);
uint32_t ldoEnableRegArray[] = PMU_LDO_ENABLE_SETPOINT_REGISTERS;
(*(volatile uint32_t *)ldoEnableRegArray[(uint8_t)name]) = ~setpointMap;
}
/*!
* brief Sets the operating mode of the selected LDO in the certain setpoints with GPC mode.
*
* param name The name of the selected ldo. Please see the enumeration pmu_ldo_name_t for details.
* param setpointMap The map of setpoints should be the OR'ed Value of _pmu_setpoint_map.
* param mode The operating mode of the selected ldo. Please refer to the enumeration pmu_ldo_operate_mode_t for
* details.
*/
void PMU_GPCSetLdoOperateMode(pmu_ldo_name_t name, uint32_t setpointMap, pmu_ldo_operate_mode_t mode)
{
assert(name > kPMU_PllLdo);
assert(name < kPMU_SnvsDigLdo);
uint32_t ldoLpModeRegArray[] = PMU_LDO_LP_MODE_EN_SETPOINT_REGISTERS;
if (mode == kPMU_LowPowerMode)
{
(*(volatile uint32_t *)ldoLpModeRegArray[(uint8_t)name]) &= ~setpointMap;
}
else
{
(*(volatile uint32_t *)ldoLpModeRegArray[(uint8_t)name]) |= setpointMap;
}
}
/*!
* brief Controls the ON/OFF of the selected LDOs' Tracking mode in the certain setpoints with GPC mode.
*
* param name The name of the selected ldo. Please see the enumeration pmu_ldo_name_t for details.
* param setpointMap The map of setpoints that the LDO tracking mode will be enabled in those setpoints, this value
* should be the OR'ed Value of @ref _pmu_setpoint_map.
*/
void PMU_GPCEnableLdoTrackingMode(pmu_ldo_name_t name, uint32_t setpointMap)
{
assert(name > kPMU_PllLdo);
assert(name < kPMU_SnvsDigLdo);
uint32_t ldoTrackingEnableRegArray[] = PMU_LDO_TRACKING_EN_SETPOINT_REGISTERS;
(*(volatile uint32_t *)ldoTrackingEnableRegArray[(uint8_t)name]) = setpointMap;
}
/*!
* brief Controls the ON/OFF of the selected LDOs' Bypass mode in the certain setpoints with GPC mode.
*
* param name The name of the selected ldo. Please see the enumeration pmu_ldo_name_t for details.
* param setpointMap The map of setpoints that the LDO bypass mode will be enabled in those setpoints, this value
* should be the OR'ed Value of @ref _pmu_setpoint_map.
*/
void PMU_GPCEnableLdoBypassMode(pmu_ldo_name_t name, uint32_t setpointMap)
{
assert(name > kPMU_PllLdo);
assert(name < kPMU_SnvsDigLdo);
uint32_t ldoBypassEnableRegArray[] = PMU_LDO_BYPASS_EN_SETPOINT_REGISTERS;
(*(volatile uint32_t *)ldoBypassEnableRegArray[(uint8_t)name]) = setpointMap;
}
/*!
* brief When STBY assert, enable/disable the selected LDO enter it's Low power mode.
*
* param name The name of the selected ldo. Please see the enumeration pmu_ldo_name_t for details.
* param setpointMap The map of setpoints that the LDO low power mode will be enabled in those setpoints if STBY
* assert, this value should be the OR'ed Value of @ref _pmu_setpoint_map.
*/
void PMU_GPCEnableLdoStandbyMode(pmu_ldo_name_t name, uint32_t setpointMap)
{
assert(name != kPMU_SnvsDigLdo);
uint32_t ldoStandbyEnableRegArray[] = PMU_LDO_STBY_EN_REGISTERS;
(*(volatile uint32_t *)ldoStandbyEnableRegArray[(uint8_t)name]) = setpointMap;
}
/*!
* brief Selects the control mode of the Bandgap Reference.
*
* param base PMU peripheral base address.
* param mode The control mode of the Bandgap Reference. Please refer to pmu_control_mode_t.
*/
void PMU_SetBandgapControlMode(ANADIG_PMU_Type *base, pmu_control_mode_t mode)
{
if (mode == kPMU_StaticMode)
{
base->PMU_REF_CTRL &= ~ANADIG_PMU_PMU_REF_CTRL_REF_CONTROL_MODE_MASK;
}
else
{
base->PMU_REF_CTRL |= ANADIG_PMU_PMU_REF_CTRL_REF_CONTROL_MODE_MASK;
}
}
/*!
* brief Switches the Bandgap from Static/Software Mode to GPC/Hardware Mode.
*
* param base PMU peripheral base address.
*/
void PMU_SwitchBandgapToGPCMode(ANADIG_PMU_Type *base)
{
if ((base->BANDGAP_ENABLE_SP & ANADIG_PMU_BANDGAP_ENABLE_SP_ON_OFF_SETPOINT0_MASK) == 0UL)
{
base->PMU_REF_CTRL &= ~ANADIG_PMU_PMU_REF_CTRL_REF_ENABLE_MASK;
}
else
{
base->PMU_REF_CTRL |= ANADIG_PMU_PMU_REF_CTRL_REF_ENABLE_MASK;
}
}
/*!
* brief Disables Bandgap self bias for best noise performance.
*
* This function waits for the bandgap to be stable and disables the bandgap self bias.
* After being powered up, it needs to wait for the bandgap stable to be stable and then disable Bandgap
* Self bias for best noise performance.
*/
void PMU_DisableBandgapSelfBiasAfterPowerUp(void)
{
uint32_t temp32;
uint32_t regValue;
/* Wait Bandgap stable. */
do
{
regValue = ANATOP_AI_Read(kAI_Itf_Bandgap, kAI_BANDGAP_STAT0);
} while ((regValue & AI_BANDGAP_STAT0_REFTOP_VBGUP_MASK) == 0UL);
/* Disable Bandgap self bias for best noise performance. */
temp32 = ANATOP_AI_Read(kAI_Itf_Bandgap, kAI_BANDGAP_CTRL0);
temp32 |= AI_BANDGAP_CTRL0_REFTOP_SELFBIASOFF_MASK;
ANATOP_AI_Write(kAI_Itf_Bandgap, kAI_BANDGAP_CTRL0, temp32);
}
/*!
* brief Enables Bandgap self bias before power down.
*
* This function will enable Bandgap self bias feature before powering down or there
* will be risk of Bandgap not starting properly.
*/
void PMU_EnableBandgapSelfBiasBeforePowerDown(void)
{
uint32_t temp32;
temp32 = ANATOP_AI_Read(kAI_Itf_Bandgap, kAI_BANDGAP_CTRL0);
temp32 &= ~AI_BANDGAP_CTRL0_REFTOP_SELFBIASOFF_MASK;
ANATOP_AI_Write(kAI_Itf_Bandgap, kAI_BANDGAP_CTRL0, temp32);
}
/*!
* brief Init Bandgap.
*
* param config. Pointer to the structure pmu_static_bandgap_config_t. Please refer to pmu_static_bandgap_config_t.
*/
void PMU_StaticBandgapInit(const pmu_static_bandgap_config_t *config)
{
assert(config != NULL);
uint32_t temp32;
temp32 = ANATOP_AI_Read(kAI_Itf_Bandgap, kAI_BANDGAP_CTRL0);
temp32 &= ~(AI_BANDGAP_CTRL0_REFTOP_PWD_MASK | AI_BANDGAP_CTRL0_REFTOP_LINREGREF_PWD_MASK |
AI_BANDGAP_CTRL0_REFTOP_PWDVBGUP_MASK | AI_BANDGAP_CTRL0_REFTOP_LOWPOWER_MASK |
AI_BANDGAP_CTRL0_REFTOP_VBGADJ_MASK | AI_BANDGAP_CTRL0_REFTOP_IBZTCADJ_MASK);
temp32 |= ((uint32_t)(config->powerDownOption) &
(AI_BANDGAP_CTRL0_REFTOP_PWD_MASK | AI_BANDGAP_CTRL0_REFTOP_LINREGREF_PWD_MASK |
AI_BANDGAP_CTRL0_REFTOP_PWDVBGUP_MASK));
temp32 |= AI_BANDGAP_CTRL0_REFTOP_LOWPOWER(config->enableLowPowerMode);
temp32 |= AI_BANDGAP_CTRL0_REFTOP_VBGADJ(config->outputVoltage);
temp32 |= AI_BANDGAP_CTRL0_REFTOP_IBZTCADJ(config->outputCurrent);
ANATOP_AI_Write(kAI_Itf_Bandgap, kAI_BANDGAP_CTRL0, temp32);
}
/*!
* brief Configures Well bias, such as power source, clock source and so on.
*
* param base PMU peripheral base address.
* param config Pointer to the pmu_well_bias_config_t structure.
*/
void PMU_WellBiasInit(ANADIG_PMU_Type *base, const pmu_well_bias_config_t *config)
{
assert(config != NULL);
uint32_t tmp32;
tmp32 = base->PMU_BIAS_CTRL;
tmp32 &= ~(ANADIG_PMU_PMU_BIAS_CTRL_WB_CFG_1P8_MASK | ANADIG_PMU_PMU_BIAS_CTRL_WB_VDD_SEL_1P8_MASK);
tmp32 |= ((uint32_t)config->wellBiasOption.wellBiasData &
(ANADIG_PMU_PMU_BIAS_CTRL_WB_CFG_1P8_MASK | ANADIG_PMU_PMU_BIAS_CTRL_WB_VDD_SEL_1P8_MASK));
base->PMU_BIAS_CTRL = tmp32;
tmp32 = base->PMU_BIAS_CTRL2;
tmp32 &= ~ANADIG_PMU_PMU_BIAS_CTRL2_WB_ADJ_1P8_MASK;
tmp32 |= ANADIG_PMU_PMU_BIAS_CTRL2_WB_ADJ_1P8(config->adjustment);
base->PMU_BIAS_CTRL2 = tmp32;
}
/*!
* brief Enables/disables the selected body bias.
*
* param base PMU peripheral base address.
* param name The name of the body bias to be turned on/off, please refer to pmu_body_bias_name_t.
* param enable Used to turn on/off the specific body bias.
* - \b true Enable the selected body bias.
* - \b false Disable the selected body bias.
*/
void PMU_GetWellBiasDefaultConfig(pmu_well_bias_config_t *config)
{
assert(config != NULL);
(void)memset(config, 0, sizeof(*config));
config->wellBiasOption.wellBiasData = 0U;
config->adjustment = kPMU_Cref0fFCspl0fFDeltaC0fF;
}
/*!
* brief Selects the control mode of the Body Bias.
*
* param base PMU peripheral base address.
* param name The name of the body bias. Please refer to pmu_body_bias_name_t.
* param mode The control mode of the Body Bias. Please refer to pmu_control_mode_t.
*/
void PMU_SetBodyBiasControlMode(ANADIG_PMU_Type *base, pmu_body_bias_name_t name, pmu_control_mode_t mode)
{
uint32_t temp32;
switch (name)
{
#if (defined(PMU_HAS_FBB) && PMU_HAS_FBB)
case kPMU_FBB_CM7:
{
temp32 = base->PMU_BIAS_CTRL2;
temp32 &= ~ANADIG_PMU_PMU_BIAS_CTRL2_FBB_M7_CONTROL_MODE_MASK;
temp32 |= ANADIG_PMU_PMU_BIAS_CTRL2_FBB_M7_CONTROL_MODE(mode);
base->PMU_BIAS_CTRL2 = temp32;
break;
}
#endif /* PMU_HAS_FBB */
case kPMU_RBB_SOC:
{
temp32 = base->PMU_BIAS_CTRL2;
temp32 &= ~ANADIG_PMU_PMU_BIAS_CTRL2_RBB_SOC_CONTROL_MODE_MASK;
temp32 |= ANADIG_PMU_PMU_BIAS_CTRL2_RBB_SOC_CONTROL_MODE(mode);
base->PMU_BIAS_CTRL2 = temp32;
break;
}
case kPMU_RBB_LPSR:
{
temp32 = base->PMU_BIAS_CTRL2;
temp32 &= ~ANADIG_PMU_PMU_BIAS_CTRL2_RBB_LPSR_CONTROL_MODE_MASK;
temp32 |= ANADIG_PMU_PMU_BIAS_CTRL2_RBB_LPSR_CONTROL_MODE(mode);
base->PMU_BIAS_CTRL2 = temp32;
break;
}
default:
/* This branch should never be hit. */
break;
}
}
/*!
* brief Enables/disables the selected body bias.
*
* param base PMU peripheral base address.
* param name The name of the body bias to be turned on/off, please refer to pmu_body_bias_name_t.
* param enable Used to turn on/off the specific body bias.
* - \b true Enable the selected body bias.
* - \b false Disable the selected body bias.
*/
void PMU_EnableBodyBias(ANADIG_PMU_Type *base, pmu_body_bias_name_t name, bool enable)
{
uint32_t tmp32;
if (enable)
{
switch (name)
{
#if (defined(PMU_HAS_FBB) && PMU_HAS_FBB)
case kPMU_FBB_CM7:
{
tmp32 = base->PMU_BIAS_CTRL;
tmp32 &= ~PMU_BIAS_CTRL_WB_CFG_1P8_WELL_SELECT_MASK;
tmp32 |= PMU_BIAS_CTRL_WB_CFG_1P8_VOLTAGE_THRESHOLD_MASK;
base->PMU_BIAS_CTRL = tmp32;
tmp32 = base->PMU_BIAS_CTRL2;
tmp32 &= ~(ANADIG_PMU_PMU_BIAS_CTRL2_WB_PWR_SW_EN_1P8_MASK);
tmp32 |= ANADIG_PMU_PMU_BIAS_CTRL2_WB_PWR_SW_EN_1P8(1U) | ANADIG_PMU_PMU_BIAS_CTRL2_WB_EN_MASK;
base->PMU_BIAS_CTRL2 = tmp32;
while ((base->PMU_BIAS_CTRL2 & ANADIG_PMU_PMU_BIAS_CTRL2_WB_OK_MASK) !=
ANADIG_PMU_PMU_BIAS_CTRL2_WB_OK_MASK)
{
}
break;
}
#endif /* PMU_HAS_FBB */
case kPMU_RBB_SOC:
{
tmp32 = base->PMU_BIAS_CTRL;
tmp32 &= ~(PMU_BIAS_CTRL_WB_CFG_1P8_WELL_SELECT_MASK | PMU_BIAS_CTRL_WB_CFG_1P8_VOLTAGE_THRESHOLD_MASK);
base->PMU_BIAS_CTRL = tmp32;
tmp32 = base->PMU_BIAS_CTRL2;
tmp32 &= ~(ANADIG_PMU_PMU_BIAS_CTRL2_WB_PWR_SW_EN_1P8_MASK);
tmp32 |= ANADIG_PMU_PMU_BIAS_CTRL2_WB_PWR_SW_EN_1P8(2U) | ANADIG_PMU_PMU_BIAS_CTRL2_WB_EN_MASK;
base->PMU_BIAS_CTRL2 = tmp32;
while ((base->PMU_BIAS_CTRL2 & ANADIG_PMU_PMU_BIAS_CTRL2_WB_OK_MASK) !=
ANADIG_PMU_PMU_BIAS_CTRL2_WB_OK_MASK)
{
}
break;
}
case kPMU_RBB_LPSR:
{
tmp32 = base->PMU_BIAS_CTRL;
tmp32 &= ~(PMU_BIAS_CTRL_WB_CFG_1P8_WELL_SELECT_MASK | PMU_BIAS_CTRL_WB_CFG_1P8_VOLTAGE_THRESHOLD_MASK);
base->PMU_BIAS_CTRL = tmp32;
tmp32 = base->PMU_BIAS_CTRL2;
tmp32 &= ~(ANADIG_PMU_PMU_BIAS_CTRL2_WB_PWR_SW_EN_1P8_MASK);
tmp32 |= ANADIG_PMU_PMU_BIAS_CTRL2_WB_PWR_SW_EN_1P8(4U) | ANADIG_PMU_PMU_BIAS_CTRL2_WB_EN_MASK;
base->PMU_BIAS_CTRL2 = tmp32;
while ((base->PMU_BIAS_CTRL2 & ANADIG_PMU_PMU_BIAS_CTRL2_WB_OK_MASK) !=
ANADIG_PMU_PMU_BIAS_CTRL2_WB_OK_MASK)
{
}
break;
}
default:
/* This branch should never be hit. */
break;
}
}
else
{
base->PMU_BIAS_CTRL2 &=
~(ANADIG_PMU_PMU_BIAS_CTRL2_WB_PWR_SW_EN_1P8_MASK | ANADIG_PMU_PMU_BIAS_CTRL2_WB_EN_MASK);
}
}
/*!
* brief Controls the ON/OFF of the selected body bias in the certain setpoints with GPC mode.
*
* param name The name of the selected body bias. Please see the enumeration pmu_body_bias_name_t for details.
* param setpointMap The map of setpoints that the specific body bias will be enabled in those setpoints, this value
* should be the OR'ed Value of _pmu_setpoint_map.
*/
void PMU_GPCEnableBodyBias(pmu_body_bias_name_t name, uint32_t setpointMap)
{
uint32_t bodyBiasEnableRegArray[] = PMU_BODY_BIAS_ENABLE_REGISTERS;
(*(volatile uint32_t *)bodyBiasEnableRegArray[(uint8_t)name]) = ~setpointMap;
}
/*!
* brief Controls the ON/OFF of the selected Body Bias' Wbias power switch in certain setpoints with GPC mode.
*
* param name The name of the selected body bias. Please see the enumeration pmu_body_bias_name_t for details.
* param setpointMap The map of setpoints that the specific body bias's wbias power switch will be turn on in those
* setpoints, this value should be the OR'ed Value of _pmu_setpoint_map.
*/
void PMU_GPCEnableBodyBiasStandbyMode(pmu_body_bias_name_t name, uint32_t setpointMap)
{
uint32_t BBStandbyEnableRegArray[] = PMU_BODY_BIAS_STBY_EN_REGISTERS;
(*(volatile uint32_t *)BBStandbyEnableRegArray[(uint8_t)name]) = setpointMap;
}
/*!
* brief Gets the default config of body bias in GPC mode.
*
* param config Pointer to the structure pmu_gpc_body_bias_config_t.
*/
void PMU_GPCGetBodyBiasDefaultConfig(pmu_gpc_body_bias_config_t *config)
{
assert(config != NULL);
config->PWELLRegulatorSize = 1U;
config->NWELLRegulatorSize = 1U;
config->oscillatorSize = 7U;
config->regulatorStrength = 5U;
}
/*!
* brief Sets the config of the selected Body Bias in GPC mode.
*
* param name The name of the selected body bias. Please see the enumeration pmu_body_bias_name_t for details.
* param config Pointer to the structure pmu_gpc_body_bias_config_t.
*/
void PMU_GPCSetBodyBiasConfig(pmu_body_bias_name_t name, const pmu_gpc_body_bias_config_t *config)
{
assert(config != NULL);
uint32_t bodyBiasConfigRegArray[] = PMU_BODY_BIAS_CONFIGURE_REGISTERS;
uint32_t temp32;
temp32 = (*(volatile uint32_t *)bodyBiasConfigRegArray[(uint8_t)name]);
temp32 &=
(ANADIG_PMU_RBB_SOC_CONFIGURE_WB_CFG_PW_MASK | ANADIG_PMU_RBB_SOC_CONFIGURE_WB_CFG_NW_MASK |
ANADIG_PMU_RBB_SOC_CONFIGURE_OSCILLATOR_BITS_MASK | ANADIG_PMU_RBB_SOC_CONFIGURE_REGULATOR_STRENGTH_MASK);
temp32 |= ANADIG_PMU_RBB_SOC_CONFIGURE_WB_CFG_PW(config->PWELLRegulatorSize) |
ANADIG_PMU_RBB_SOC_CONFIGURE_WB_CFG_NW(config->NWELLRegulatorSize) |
ANADIG_PMU_RBB_SOC_CONFIGURE_OSCILLATOR_BITS(config->oscillatorSize) |
ANADIG_PMU_RBB_SOC_CONFIGURE_REGULATOR_STRENGTH(config->regulatorStrength);
(*(volatile uint32_t *)bodyBiasConfigRegArray[(uint8_t)name]) = temp32;
}
|
418c6d5c40af092368557193a99ec4759588d14f
|
caa3fd7b505b9f374d67716d838fc9657135f06d
|
/libgo/runtime/go-signal.c
|
aa1b6305ad09d90e6938330b5fda679d7b61becf
|
[
"LicenseRef-scancode-generic-cla",
"LicenseRef-scancode-google-patent-license-golang",
"BSD-3-Clause"
] |
permissive
|
golang/gofrontend
|
674700d5e4682daf09e3f27be4e0f2844c0e1dd2
|
d04b024021bb7dbaa434a6d902bd12beb08e315f
|
refs/heads/master
| 2023-08-18T00:26:59.887760
| 2023-07-20T18:21:13
| 2023-07-20T19:28:09
| 28,939,900
| 874
| 155
|
BSD-3-Clause
| 2023-07-26T00:00:24
| 2015-01-07T23:54:58
|
Go
|
UTF-8
|
C
| false
| false
| 13,254
|
c
|
go-signal.c
|
/* go-signal.c -- signal handling for Go.
Copyright 2009 The Go Authors. All rights reserved.
Use of this source code is governed by a BSD-style
license that can be found in the LICENSE file. */
#include <signal.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/time.h>
#include <ucontext.h>
#include "runtime.h"
#ifndef SA_RESTART
#define SA_RESTART 0
#endif
#ifdef USING_SPLIT_STACK
extern void __splitstack_getcontext(void *context[10]);
extern void __splitstack_setcontext(void *context[10]);
extern void *__splitstack_find_context(void *context[10], size_t *,
void **, void **, void **);
#endif
// The rest of the signal handler, written in Go.
extern void sigtrampgo(uint32, siginfo_t *, void *)
__asm__(GOSYM_PREFIX "runtime.sigtrampgo");
// The Go signal handler, written in C. This should be running on the
// alternate signal stack. This is responsible for setting up the
// split stack context so that stack guard checks will work as
// expected.
void sigtramp(int, siginfo_t *, void *)
__attribute__ ((no_split_stack));
void sigtramp(int, siginfo_t *, void *)
__asm__ (GOSYM_PREFIX "runtime.sigtramp");
#ifndef USING_SPLIT_STACK
// When not using split stacks, there are no stack checks, and there
// is nothing special for this function to do.
void
sigtramp(int sig, siginfo_t *info, void *context)
{
sigtrampgo(sig, info, context);
}
#else // USING_SPLIT_STACK
void
sigtramp(int sig, siginfo_t *info, void *context)
{
G *gp;
void *stack_context[10];
void *stack;
void *find_stack;
size_t stack_size;
void *next_segment;
void *next_sp;
void *initial_sp;
uintptr sp;
stack_t st;
uintptr stsp;
gp = runtime_g();
if (gp == nil) {
// Let the Go code handle this case.
// It should only call nosplit functions in this case.
sigtrampgo(sig, info, context);
return;
}
// If this signal is one for which we will panic, we are not
// on the alternate signal stack. It's OK to call split-stack
// functions here.
if (sig == SIGBUS || sig == SIGFPE || sig == SIGSEGV) {
sigtrampgo(sig, info, context);
return;
}
// We are running on the alternate signal stack.
__splitstack_getcontext(&stack_context[0]);
find_stack =
__splitstack_find_context((void*)(&gp->m->gsignal->stackcontext[0]),
&stack_size, &next_segment,
&next_sp, &initial_sp);
stack = find_stack;
if (stack == NULL) {
stack = gp->m->gsignalstack;
stack_size = gp->m->gsignalstacksize;
}
// If some non-Go code called sigaltstack, adjust.
sp = (uintptr)(&stack_size);
if (sp < (uintptr)(stack) || sp >= (uintptr)(stack) + stack_size) {
sigaltstack(nil, &st);
if ((st.ss_flags & SS_DISABLE) != 0) {
runtime_printf("signal %d received on thread with no signal stack\n", (int32)(sig));
runtime_throw("non-Go code disabled sigaltstack");
}
stsp = (uintptr)(st.ss_sp);
if (sp < stsp || sp >= stsp + st.ss_size) {
runtime_printf("signal %d received but handler not on signal stack\n", (int32)(sig));
runtime_throw("non-Go code set up signal handler without SA_ONSTACK flag");
}
// Unfortunately __splitstack_find_context will return NULL
// when it is called on a context that has never been used.
// There isn't much we can do but assume all is well.
if (find_stack != NULL) {
// Here the gc runtime adjusts the gsignal
// stack guard to match the values returned by
// sigaltstack. Unfortunately we have no way
// to do that.
runtime_printf("signal %d received on unknown signal stack\n", (int32)(sig));
runtime_throw("non-Go code changed signal stack");
}
}
// Set the split stack context so that the stack guards are
// checked correctly.
__splitstack_setcontext((void*)(&gp->m->gsignal->stackcontext[0]));
sigtrampgo(sig, info, context);
// We are going to return back to the signal trampoline and
// then to whatever we were doing before we got the signal.
// Restore the split stack context so that stack guards are
// checked correctly.
__splitstack_setcontext(&stack_context[0]);
}
#endif // USING_SPLIT_STACK
// C function to return the address of the sigtramp function.
uintptr getSigtramp(void) __asm__ (GOSYM_PREFIX "runtime.getSigtramp");
uintptr
getSigtramp()
{
return (uintptr)(void*)sigtramp;
}
// C code to manage the sigaction sa_sigaction field, which is
// typically a union and so hard for mksysinfo.sh to handle.
uintptr getSigactionHandler(struct sigaction*)
__attribute__ ((no_split_stack));
uintptr getSigactionHandler(struct sigaction*)
__asm__ (GOSYM_PREFIX "runtime.getSigactionHandler");
uintptr
getSigactionHandler(struct sigaction* sa)
{
return (uintptr)(sa->sa_sigaction);
}
void setSigactionHandler(struct sigaction*, uintptr)
__attribute__ ((no_split_stack));
void setSigactionHandler(struct sigaction*, uintptr)
__asm__ (GOSYM_PREFIX "runtime.setSigactionHandler");
void
setSigactionHandler(struct sigaction* sa, uintptr handler)
{
sa->sa_sigaction = (void*)(handler);
}
#ifdef __linux__
// Workaround for https://sourceware.org/bugzilla/show_bug.cgi?id=27417
#ifndef sigev_notify_thread_id
#define sigev_notify_thread_id _sigev_un._tid
#endif
void setSigeventTID(struct sigevent*, int32_t)
__asm__ (GOSYM_PREFIX "runtime.setSigeventTID");
void
setSigeventTID(struct sigevent *sev, int32_t v)
{
sev->sigev_notify_thread_id = v;
}
#endif // defined(__linux__)
// C code to fetch values from the siginfo_t and ucontext_t pointers
// passed to a signal handler.
uintptr getSiginfoCode(siginfo_t *)
__attribute__ ((no_split_stack));
uintptr getSiginfoCode(siginfo_t *)
__asm__ (GOSYM_PREFIX "runtime.getSiginfoCode");
uintptr
getSiginfoCode(siginfo_t *info)
{
return (uintptr)(info->si_code);
}
struct getSiginfoRet {
uintptr sigaddr;
uintptr sigpc;
};
struct getSiginfoRet getSiginfo(siginfo_t *, void *)
__asm__(GOSYM_PREFIX "runtime.getSiginfo");
struct getSiginfoRet
getSiginfo(siginfo_t *info, void *context __attribute__((unused)))
{
struct getSiginfoRet ret;
Location loc[1];
int32 n;
if (info == nil) {
ret.sigaddr = 0;
} else {
ret.sigaddr = (uintptr)(info->si_addr);
}
ret.sigpc = 0;
// There doesn't seem to be a portable way to get the PC.
// Use unportable code to pull it from context, and if that fails
// try a stack backtrace across the signal handler.
#if defined(__x86_64__) && defined(__linux__)
ret.sigpc = ((ucontext_t*)(context))->uc_mcontext.gregs[REG_RIP];
#elif defined(__i386__) && defined(__linux__)
ret.sigpc = ((ucontext_t*)(context))->uc_mcontext.gregs[REG_EIP];
#elif defined(__alpha__) && defined(__linux__)
ret.sigpc = ((ucontext_t*)(context))->uc_mcontext.sc_pc;
#elif defined(__PPC64__) && defined(__linux__)
ret.sigpc = ((ucontext_t*)(context))->uc_mcontext.gp_regs[32];
#elif defined(__PPC__) && defined(__linux__)
# if defined(__GLIBC__)
ret.sigpc = ((ucontext_t*)(context))->uc_mcontext.uc_regs->gregs[32];
# else
ret.sigpc = ((ucontext_t*)(context))->uc_mcontext.gregs[32];
# endif
#elif defined(__PPC__) && defined(_AIX)
ret.sigpc = ((ucontext_t*)(context))->uc_mcontext.jmp_context.iar;
#elif defined(__aarch64__) && defined(__linux__)
ret.sigpc = ((ucontext_t*)(context))->uc_mcontext.pc;
#elif defined(__NetBSD__)
ret.sigpc = _UC_MACHINE_PC(((ucontext_t*)(context)));
#endif
if (ret.sigpc == 0) {
// Skip getSiginfo/sighandler/sigtrampgo/sigtramp/handler.
n = runtime_callers(5, &loc[0], 1, false);
if (n > 0) {
ret.sigpc = loc[0].pc;
}
}
return ret;
}
// Dump registers when crashing in a signal.
// There is no portable way to write this,
// so we just have some CPU/OS specific implementations.
void dumpregs(siginfo_t *, void *)
__asm__(GOSYM_PREFIX "runtime.dumpregs");
void
dumpregs(siginfo_t *info __attribute__((unused)), void *context __attribute__((unused)))
{
#if defined(__x86_64__) && defined(__linux__)
{
mcontext_t *m = &((ucontext_t*)(context))->uc_mcontext;
runtime_printf("rax %X\n", m->gregs[REG_RAX]);
runtime_printf("rbx %X\n", m->gregs[REG_RBX]);
runtime_printf("rcx %X\n", m->gregs[REG_RCX]);
runtime_printf("rdx %X\n", m->gregs[REG_RDX]);
runtime_printf("rdi %X\n", m->gregs[REG_RDI]);
runtime_printf("rsi %X\n", m->gregs[REG_RSI]);
runtime_printf("rbp %X\n", m->gregs[REG_RBP]);
runtime_printf("rsp %X\n", m->gregs[REG_RSP]);
runtime_printf("r8 %X\n", m->gregs[REG_R8]);
runtime_printf("r9 %X\n", m->gregs[REG_R9]);
runtime_printf("r10 %X\n", m->gregs[REG_R10]);
runtime_printf("r11 %X\n", m->gregs[REG_R11]);
runtime_printf("r12 %X\n", m->gregs[REG_R12]);
runtime_printf("r13 %X\n", m->gregs[REG_R13]);
runtime_printf("r14 %X\n", m->gregs[REG_R14]);
runtime_printf("r15 %X\n", m->gregs[REG_R15]);
runtime_printf("rip %X\n", m->gregs[REG_RIP]);
runtime_printf("rflags %X\n", m->gregs[REG_EFL]);
runtime_printf("cs %X\n", m->gregs[REG_CSGSFS] & 0xffff);
runtime_printf("fs %X\n", (m->gregs[REG_CSGSFS] >> 16) & 0xffff);
runtime_printf("gs %X\n", (m->gregs[REG_CSGSFS] >> 32) & 0xffff);
}
#elif defined(__i386__) && defined(__linux__)
{
mcontext_t *m = &((ucontext_t*)(context))->uc_mcontext;
runtime_printf("eax %x\n", m->gregs[REG_EAX]);
runtime_printf("ebx %x\n", m->gregs[REG_EBX]);
runtime_printf("ecx %x\n", m->gregs[REG_ECX]);
runtime_printf("edx %x\n", m->gregs[REG_EDX]);
runtime_printf("edi %x\n", m->gregs[REG_EDI]);
runtime_printf("esi %x\n", m->gregs[REG_ESI]);
runtime_printf("ebp %x\n", m->gregs[REG_EBP]);
runtime_printf("esp %x\n", m->gregs[REG_ESP]);
runtime_printf("eip %x\n", m->gregs[REG_EIP]);
runtime_printf("eflags %x\n", m->gregs[REG_EFL]);
runtime_printf("cs %x\n", m->gregs[REG_CS]);
runtime_printf("fs %x\n", m->gregs[REG_FS]);
runtime_printf("gs %x\n", m->gregs[REG_GS]);
}
#elif defined(__alpha__) && defined(__linux__)
{
mcontext_t *m = &((ucontext_t*)(context))->uc_mcontext;
runtime_printf("v0 %X\n", m->sc_regs[0]);
runtime_printf("t0 %X\n", m->sc_regs[1]);
runtime_printf("t1 %X\n", m->sc_regs[2]);
runtime_printf("t2 %X\n", m->sc_regs[3]);
runtime_printf("t3 %X\n", m->sc_regs[4]);
runtime_printf("t4 %X\n", m->sc_regs[5]);
runtime_printf("t5 %X\n", m->sc_regs[6]);
runtime_printf("t6 %X\n", m->sc_regs[7]);
runtime_printf("t7 %X\n", m->sc_regs[8]);
runtime_printf("s0 %X\n", m->sc_regs[9]);
runtime_printf("s1 %X\n", m->sc_regs[10]);
runtime_printf("s2 %X\n", m->sc_regs[11]);
runtime_printf("s3 %X\n", m->sc_regs[12]);
runtime_printf("s4 %X\n", m->sc_regs[13]);
runtime_printf("s5 %X\n", m->sc_regs[14]);
runtime_printf("fp %X\n", m->sc_regs[15]);
runtime_printf("a0 %X\n", m->sc_regs[16]);
runtime_printf("a1 %X\n", m->sc_regs[17]);
runtime_printf("a2 %X\n", m->sc_regs[18]);
runtime_printf("a3 %X\n", m->sc_regs[19]);
runtime_printf("a4 %X\n", m->sc_regs[20]);
runtime_printf("a5 %X\n", m->sc_regs[21]);
runtime_printf("t8 %X\n", m->sc_regs[22]);
runtime_printf("t9 %X\n", m->sc_regs[23]);
runtime_printf("t10 %X\n", m->sc_regs[24]);
runtime_printf("t11 %X\n", m->sc_regs[25]);
runtime_printf("ra %X\n", m->sc_regs[26]);
runtime_printf("t12 %X\n", m->sc_regs[27]);
runtime_printf("at %X\n", m->sc_regs[28]);
runtime_printf("gp %X\n", m->sc_regs[29]);
runtime_printf("sp %X\n", m->sc_regs[30]);
runtime_printf("pc %X\n", m->sc_pc);
}
#elif defined(__PPC__) && defined(__linux__)
{
int i;
# if defined(__PPC64__)
mcontext_t *m = &((ucontext_t*)(context))->uc_mcontext;
for (i = 0; i < 32; i++)
runtime_printf("r%d %X\n", i, m->gp_regs[i]);
runtime_printf("pc %X\n", m->gp_regs[32]);
runtime_printf("msr %X\n", m->gp_regs[33]);
runtime_printf("cr %X\n", m->gp_regs[38]);
runtime_printf("lr %X\n", m->gp_regs[36]);
runtime_printf("ctr %X\n", m->gp_regs[35]);
runtime_printf("xer %X\n", m->gp_regs[37]);
# else
# if defined(__GLIBC__)
mcontext_t *m = ((ucontext_t*)(context))->uc_mcontext.uc_regs;
# else
mcontext_t *m = &((ucontext_t*)(context))->uc_mcontext;
# endif
for (i = 0; i < 32; i++)
runtime_printf("r%d %x\n", i, m->gregs[i]);
runtime_printf("pc %x\n", m->gregs[32]);
runtime_printf("msr %x\n", m->gregs[33]);
runtime_printf("cr %x\n", m->gregs[38]);
runtime_printf("lr %x\n", m->gregs[36]);
runtime_printf("ctr %x\n", m->gregs[35]);
runtime_printf("xer %x\n", m->gregs[37]);
# endif
}
#elif defined(__PPC__) && defined(_AIX)
{
mcontext_t *m = &((ucontext_t*)(context))->uc_mcontext;
int i;
for (i = 0; i < 32; i++)
runtime_printf("r%d %p\n", i, m->jmp_context.gpr[i]);
runtime_printf("pc %p\n", m->jmp_context.iar);
runtime_printf("msr %p\n", m->jmp_context.msr);
runtime_printf("cr %x\n", m->jmp_context.cr);
runtime_printf("lr %p\n", m->jmp_context.lr);
runtime_printf("ctr %p\n", m->jmp_context.ctr);
runtime_printf("xer %x\n", m->jmp_context.xer);
}
#elif defined(__aarch64__) && defined(__linux__)
{
mcontext_t *m = &((ucontext_t*)(context))->uc_mcontext;
int i;
for (i = 0; i < 31; i++)
runtime_printf("x%d %X\n", i, m->regs[i]);
runtime_printf("sp %X\n", m->sp);
runtime_printf("pc %X\n", m->pc);
runtime_printf("pstate %X\n", m->pstate);
}
#endif
}
|
0c1c2dfa156f685783ba3f85ddc7f3f060dbb3a8
|
fdbb74a95924e2677466614f6ab6e2bb13b2a95a
|
/libc/thread/pthread_attr_setscope.c
|
9f8d4b307b1ac1475d4d553019b9ff3f98317b2e
|
[
"ISC"
] |
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
| 2,973
|
c
|
pthread_attr_setscope.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 "libc/dce.h"
#include "libc/errno.h"
#include "libc/thread/thread.h"
/**
* Sets contention scope attribute.
*
* @param contentionscope may be one of:
* - `PTHREAD_SCOPE_SYSTEM` to fight the system for resources
* - `PTHREAD_SCOPE_PROCESS` to fight familiar threads for resources
* @return 0 on success, or errno on error
* @raise ENOTSUP if `contentionscope` isn't supported on host OS
* @raise EINVAL if `contentionscope` was invalid
*/
errno_t pthread_attr_setscope(pthread_attr_t *attr, int contentionscope) {
switch (contentionscope) {
case PTHREAD_SCOPE_SYSTEM:
attr->__contentionscope = contentionscope;
return 0;
case PTHREAD_SCOPE_PROCESS:
// Linux almost certainly doesn't support thread scoping
// FreeBSD has THR_SYSTEM_SCOPE but it's not implemented
// OpenBSD pthreads claims support but really ignores it
// NetBSD pthreads claims support, but really ignores it
// XNU sources appear to make no mention of thread scope
// WIN32 documentation says nothing about thread scoping
return ENOTSUP;
default:
return EINVAL;
}
}
|
1b8e57c009396810ceb39a875671f3ac57127db0
|
e73547787354afd9b717ea57fe8dd0695d161821
|
/src/world/common/enemy/Paragoomba_Wander.inc.c
|
b100b1617aea2113da4899ef1387146a9c6b879a
|
[] |
no_license
|
pmret/papermario
|
8b514b19653cef8d6145e47499b3636b8c474a37
|
9774b26d93f1045dd2a67e502b6efc9599fb6c31
|
refs/heads/main
| 2023-08-31T07:09:48.951514
| 2023-08-21T18:07:08
| 2023-08-21T18:07:08
| 287,151,133
| 904
| 139
| null | 2023-09-14T02:44:23
| 2020-08-13T01:22:57
|
C
|
UTF-8
|
C
| false
| false
| 918
|
c
|
Paragoomba_Wander.inc.c
|
#include "Paragoomba.h"
#include "world/common/enemy/ai/FlyingAI.inc.c"
MobileAISettings N(AISettings_Paragoomba_Wander) = {
.moveSpeed = 1.6f,
.moveTime = 60,
.waitTime = 30,
.alertRadius = 80.0f,
.playerSearchInterval = 5,
.chaseSpeed = 2.2f,
.chaseTurnRate = 60,
.chaseUpdateInterval = 15,
.chaseRadius = 100.0f,
.unk_AI_2C = 1,
};
EvtScript N(EVS_NpcAI_Paragoomba_Wander) = {
EVT_CALL(SetSelfVar, 0, 0)
EVT_CALL(SetSelfVar, 5, -500)
EVT_CALL(SetSelfVar, 6, 21)
EVT_CALL(SetSelfVar, 1, 580)
EVT_CALL(N(FlyingAI_Main), EVT_PTR(N(AISettings_Paragoomba_Wander)))
EVT_RETURN
EVT_END
};
NpcSettings N(NpcSettings_Paragoomba_Wander) = {
.height = 20,
.radius = 21,
.level = ACTOR_LEVEL_PARAGOOMBA,
.ai = &N(EVS_NpcAI_Paragoomba_Wander),
.onHit = &EnemyNpcHit,
.onDefeat = &EnemyNpcDefeat,
.actionFlags = AI_ACTION_02,
};
|
e19a7cd2f3949f426f2626beb1f3ded1c6c44d09
|
6fb39aaadfb3c2306920066448e0f927461633e2
|
/simulator/ms-tpm-20-ref/TPMCmd/tpm/include/Ossl/TpmToOsslHash.h
|
56f41446431cbc162a49e3571806fdec96dce58e
|
[
"LicenseRef-scancode-proprietary-license",
"Apache-2.0",
"BSD-3-Clause",
"BSD-2-Clause"
] |
permissive
|
google/go-tpm-tools
|
f6d9db521c4a1e823679d5312298419643affdc7
|
9e1f35d66b888ca2021fe0cb721b7ce5daf9eaef
|
refs/heads/master
| 2023-08-28T00:38:37.132933
| 2023-08-16T18:50:59
| 2023-08-16T18:50:59
| 161,976,966
| 181
| 57
|
Apache-2.0
| 2023-09-14T21:55:06
| 2018-12-16T07:10:09
|
C
|
UTF-8
|
C
| false
| false
| 8,884
|
h
|
TpmToOsslHash.h
|
/* Microsoft Reference Implementation for TPM 2.0
*
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and
* contributor rights, including patent rights, and no such rights are granted
* under this license.
*
* Copyright (c) Microsoft Corporation
*
* All rights reserved.
*
* BSD License
*
* 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.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ""AS IS""
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
//** Introduction
//
// This header file is used to 'splice' the OpenSSL hash code into the TPM code.
//
#ifndef HASH_LIB_DEFINED
#define HASH_LIB_DEFINED
#define HASH_LIB_OSSL
#include <openssl/evp.h>
#include <openssl/sha.h>
#include <openssl/ossl_typ.h>
//***************************************************************
//** Links to the OpenSSL HASH code
//***************************************************************
// Redefine the internal name used for each of the hash state structures to the
// name used by the library.
// These defines need to be known in all parts of the TPM so that the structure
// sizes can be properly computed when needed.
#define tpmHashStateSHA1_t SHA_CTX
#define tpmHashStateSHA256_t SHA256_CTX
#define tpmHashStateSHA384_t SHA512_CTX
#define tpmHashStateSHA512_t SHA512_CTX
#if ALG_SM3_256
# error "The version of OpenSSL used by this code does not support SM3"
#endif
// The defines below are only needed when compiling CryptHash.c or CryptSmac.c.
// This isolation is primarily to avoid name space collision. However, if there
// is a real collision, it will likely show up when the linker tries to put things
// together.
#ifdef _CRYPT_HASH_C_
typedef BYTE *PBYTE;
typedef const BYTE *PCBYTE;
// Define the interface between CryptHash.c to the functions provided by the
// library. For each method, define the calling parameters of the method and then
// define how the method is invoked in CryptHash.c.
//
// All hashes are required to have the same calling sequence. If they don't, create
// a simple adaptation function that converts from the "standard" form of the call
// to the form used by the specific hash (and then send a nasty letter to the
// person who wrote the hash function for the library).
//
// The macro that calls the method also defines how the
// parameters get swizzled between the default form (in CryptHash.c)and the
// library form.
//
// Initialize the hash context
#define HASH_START_METHOD_DEF void (HASH_START_METHOD)(PANY_HASH_STATE state)
#define HASH_START(hashState) \
((hashState)->def->method.start)(&(hashState)->state);
// Add data to the hash
#define HASH_DATA_METHOD_DEF \
void (HASH_DATA_METHOD)(PANY_HASH_STATE state, \
PCBYTE buffer, \
size_t size)
#define HASH_DATA(hashState, dInSize, dIn) \
((hashState)->def->method.data)(&(hashState)->state, dIn, dInSize)
// Finalize the hash and get the digest
#define HASH_END_METHOD_DEF \
void (HASH_END_METHOD)(BYTE *buffer, PANY_HASH_STATE state)
#define HASH_END(hashState, buffer) \
((hashState)->def->method.end)(buffer, &(hashState)->state)
// Copy the hash context
// Note: For import, export, and copy, memcpy() is used since there is no
// reformatting necessary between the internal and external forms.
#define HASH_STATE_COPY_METHOD_DEF \
void (HASH_STATE_COPY_METHOD)(PANY_HASH_STATE to, \
PCANY_HASH_STATE from, \
size_t size)
#define HASH_STATE_COPY(hashStateOut, hashStateIn) \
((hashStateIn)->def->method.copy)(&(hashStateOut)->state, \
&(hashStateIn)->state, \
(hashStateIn)->def->contextSize)
// Copy (with reformatting when necessary) an internal hash structure to an
// external blob
#define HASH_STATE_EXPORT_METHOD_DEF \
void (HASH_STATE_EXPORT_METHOD)(BYTE *to, \
PCANY_HASH_STATE from, \
size_t size)
#define HASH_STATE_EXPORT(to, hashStateFrom) \
((hashStateFrom)->def->method.copyOut) \
(&(((BYTE *)(to))[offsetof(HASH_STATE, state)]), \
&(hashStateFrom)->state, \
(hashStateFrom)->def->contextSize)
// Copy from an external blob to an internal formate (with reformatting when
// necessary
#define HASH_STATE_IMPORT_METHOD_DEF \
void (HASH_STATE_IMPORT_METHOD)(PANY_HASH_STATE to, \
const BYTE *from, \
size_t size)
#define HASH_STATE_IMPORT(hashStateTo, from) \
((hashStateTo)->def->method.copyIn) \
(&(hashStateTo)->state, \
&(((const BYTE *)(from))[offsetof(HASH_STATE, state)]),\
(hashStateTo)->def->contextSize)
// Function aliases. The code in CryptHash.c uses the internal designation for the
// functions. These need to be translated to the function names of the library.
#define tpmHashStart_SHA1 SHA1_Init // external name of the
// initialization method
#define tpmHashData_SHA1 SHA1_Update
#define tpmHashEnd_SHA1 SHA1_Final
#define tpmHashStateCopy_SHA1 memcpy
#define tpmHashStateExport_SHA1 memcpy
#define tpmHashStateImport_SHA1 memcpy
#define tpmHashStart_SHA256 SHA256_Init
#define tpmHashData_SHA256 SHA256_Update
#define tpmHashEnd_SHA256 SHA256_Final
#define tpmHashStateCopy_SHA256 memcpy
#define tpmHashStateExport_SHA256 memcpy
#define tpmHashStateImport_SHA256 memcpy
#define tpmHashStart_SHA384 SHA384_Init
#define tpmHashData_SHA384 SHA384_Update
#define tpmHashEnd_SHA384 SHA384_Final
#define tpmHashStateCopy_SHA384 memcpy
#define tpmHashStateExport_SHA384 memcpy
#define tpmHashStateImport_SHA384 memcpy
#define tpmHashStart_SHA512 SHA512_Init
#define tpmHashData_SHA512 SHA512_Update
#define tpmHashEnd_SHA512 SHA512_Final
#define tpmHashStateCopy_SHA512 memcpy
#define tpmHashStateExport_SHA512 memcpy
#define tpmHashStateImport_SHA512 memcpy
#endif // _CRYPT_HASH_C_
#define LibHashInit()
// This definition would change if there were something to report
#define HashLibSimulationEnd()
#endif // HASH_LIB_DEFINED
|
941de00caa2530e8d07ccd11a90709607459c775
|
c9b9d9e93505e1e42adb61597c885b58c153894f
|
/source/platforms/macosx/brstartup.h
|
efd0b3f9c05ecf0ea7fc984b9fc7e2d6258be522
|
[
"MIT",
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-warranty-disclaimer",
"Zlib"
] |
permissive
|
Olde-Skuul/burgerlib
|
a3b860bf00bdbc699086a32a1d4756848866d3dc
|
4d9dfa0cd5586d23688978e7ec0fd5881bf75912
|
refs/heads/master
| 2023-08-30T17:13:52.487215
| 2023-08-18T21:56:27
| 2023-08-18T21:56:27
| 18,419,163
| 163
| 11
| null | null | null | null |
UTF-8
|
C
| false
| false
| 2,205
|
h
|
brstartup.h
|
/***************************************
Start up code for games based applications
MacOSX version
Copyright (c) 1995-2017 by Rebecca Ann Heineman <becky@burgerbecky.com>
It is released under an MIT Open Source license. Please see LICENSE for
license details. Yes, you can use it in a commercial title without paying
anything, just give me a credit.
Please? It's not like I'm asking you for money!
***************************************/
#ifndef __BRSTARTUP_H__
#define __BRSTARTUP_H__
#ifndef __BURGER__
#include <burger.h>
#endif
//
// Initialize defaults
//
#if !defined(GAMENAME)
#define GAMENAME "Test Application"
#endif
#if !defined(MEMORYSIZE)
#define MEMORYSIZE Burger::MemoryManagerHandle::kSystemMemoryChuckSize
#endif
#if !defined(HANDLECOUNT)
#define HANDLECOUNT Burger::MemoryManagerHandle::kDefaultHandleCount
#endif
#if !defined(MINIMUMRESERVE)
#define MINIMUMRESERVE Burger::MemoryManagerHandle::kSystemMemoryReservedSize
#endif
/***************************************
This is the main entry point for a MacOSX version of the game
***************************************/
int BURGER_ANSIAPI main(int argc, const char** argv);
int BURGER_ANSIAPI main(int /* argc */, const char** /* argv */)
{
// Exit without error if already running
int iResult = 0;
// Singular instance enabled?
#if defined(GAMELOCK)
Burger::DetectMultiLaunch OneShot;
if (!OneShot.IsMultiLaunched(GAMELOCK)) {
#endif
// Create an application instance
Burger::GameApp MyApp(MEMORYSIZE, HANDLECOUNT, MINIMUMRESERVE);
// Error on startup?
iResult = Burger::Globals::GetErrorCode();
if (!iResult) {
// Create the default menu items for a Mac OSX application without
// an Interface Builder XML file
// Define BURGER_NOMENUS if the Mac OSX application uses Interface
// Builder to handle menu generation
#if !defined(BURGER_NOMENUS)
Burger::Globals::CreateDefaultMenus();
#endif
iResult = CodeEntry(&MyApp);
}
// Needed to properly close for the lock
#if defined(GAMELOCK)
}
#endif
return iResult;
}
#endif
|
b01d239dcd6de1a0688f96c24c75b149eec048f0
|
eecd5e4c50d8b78a769bcc2675250576bed34066
|
/src/ksp/ksp/tests/ex55.c
|
c01c8bd51f5e12832a26778df747ef804ca75339
|
[
"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
| 2,463
|
c
|
ex55.c
|
static const char help[] = "Example demonstrating PCCOMPOSITE where one of the inner PCs uses a different operator\n\
\n";
#include <petscksp.h>
int main(int argc, char **argv)
{
PetscInt n = 10, i, col[3];
Vec x, b;
Mat A, B;
KSP ksp;
PC pc, subpc;
PetscScalar value[3];
PetscFunctionBeginUser;
PetscCall(PetscInitialize(&argc, &argv, (char *)0, help));
/* Create a diagonal matrix with a given distribution of diagonal elements */
PetscCall(MatCreate(PETSC_COMM_WORLD, &A));
PetscCall(MatSetSizes(A, PETSC_DECIDE, PETSC_DECIDE, n, n));
PetscCall(MatSetFromOptions(A));
PetscCall(MatSetUp(A));
/*
Assemble matrix
*/
value[0] = -1.0;
value[1] = 2.0;
value[2] = -1.0;
for (i = 1; i < n - 1; i++) {
col[0] = i - 1;
col[1] = i;
col[2] = i + 1;
PetscCall(MatSetValues(A, 1, &i, 3, col, value, INSERT_VALUES));
}
i = n - 1;
col[0] = n - 2;
col[1] = n - 1;
PetscCall(MatSetValues(A, 1, &i, 2, col, value, INSERT_VALUES));
i = 0;
col[0] = 0;
col[1] = 1;
value[0] = 2.0;
value[1] = -1.0;
PetscCall(MatSetValues(A, 1, &i, 2, col, value, INSERT_VALUES));
PetscCall(MatAssemblyBegin(A, MAT_FINAL_ASSEMBLY));
PetscCall(MatAssemblyEnd(A, MAT_FINAL_ASSEMBLY));
PetscCall(MatCreateVecs(A, &x, &b));
/* Create a KSP object */
PetscCall(KSPCreate(PETSC_COMM_WORLD, &ksp));
PetscCall(KSPSetOperators(ksp, A, A));
/* Set up a composite preconditioner */
PetscCall(KSPGetPC(ksp, &pc));
PetscCall(PCSetType(pc, PCCOMPOSITE)); /* default composite with single Identity PC */
PetscCall(PCCompositeSetType(pc, PC_COMPOSITE_ADDITIVE));
PetscCall(PCCompositeAddPCType(pc, PCLU));
PetscCall(PCCompositeGetPC(pc, 0, &subpc));
/* B is set to the diagonal of A; this demonstrates that setting the operator for a subpc changes the preconditioning */
PetscCall(MatDuplicate(A, MAT_DO_NOT_COPY_VALUES, &B));
PetscCall(MatGetDiagonal(A, b));
PetscCall(MatDiagonalSet(B, b, ADD_VALUES));
PetscCall(PCSetOperators(subpc, B, B));
PetscCall(PCCompositeAddPCType(pc, PCNONE));
PetscCall(KSPSetFromOptions(ksp));
PetscCall(KSPSolve(ksp, b, x));
PetscCall(KSPDestroy(&ksp));
PetscCall(MatDestroy(&A));
PetscCall(MatDestroy(&B));
PetscCall(VecDestroy(&x));
PetscCall(VecDestroy(&b));
PetscCall(PetscFinalize());
return 0;
}
/*TEST
test:
args: -ksp_monitor -pc_composite_type multiplicative
TEST*/
|
697f6e078abade7031ec5adb452695a850c4ada2
|
7eaf54a78c9e2117247cb2ab6d3a0c20719ba700
|
/SOFTWARE/A64-TERES/linux-a64/arch/powerpc/include/asm/cputhreads.h
|
ac3eedb9b74ae073f5019dc960862d82e3605455
|
[
"LicenseRef-scancode-free-unknown",
"Apache-2.0",
"Linux-syscall-note",
"GPL-2.0-only",
"GPL-1.0-or-later"
] |
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
|
UTF-8
|
C
| false
| false
| 2,304
|
h
|
cputhreads.h
|
#ifndef _ASM_POWERPC_CPUTHREADS_H
#define _ASM_POWERPC_CPUTHREADS_H
#include <linux/cpumask.h>
/*
* Mapping of threads to cores
*
* Note: This implementation is limited to a power of 2 number of
* threads per core and the same number for each core in the system
* (though it would work if some processors had less threads as long
* as the CPU numbers are still allocated, just not brought online).
*
* However, the API allows for a different implementation in the future
* if needed, as long as you only use the functions and not the variables
* directly.
*/
#ifdef CONFIG_SMP
extern int threads_per_core;
extern int threads_shift;
extern cpumask_t threads_core_mask;
#else
#define threads_per_core 1
#define threads_shift 0
#define threads_core_mask (CPU_MASK_CPU0)
#endif
/* cpu_thread_mask_to_cores - Return a cpumask of one per cores
* hit by the argument
*
* @threads: a cpumask of threads
*
* This function returns a cpumask which will have one "cpu" (or thread)
* bit set for each core that has at least one thread set in the argument.
*
* This can typically be used for things like IPI for tlb invalidations
* since those need to be done only once per core/TLB
*/
static inline cpumask_t cpu_thread_mask_to_cores(const struct cpumask *threads)
{
cpumask_t tmp, res;
int i;
cpumask_clear(&res);
for (i = 0; i < NR_CPUS; i += threads_per_core) {
cpumask_shift_left(&tmp, &threads_core_mask, i);
if (cpumask_intersects(threads, &tmp))
cpumask_set_cpu(i, &res);
}
return res;
}
static inline int cpu_nr_cores(void)
{
return NR_CPUS >> threads_shift;
}
static inline cpumask_t cpu_online_cores_map(void)
{
return cpu_thread_mask_to_cores(cpu_online_mask);
}
#ifdef CONFIG_SMP
int cpu_core_index_of_thread(int cpu);
int cpu_first_thread_of_core(int core);
#else
static inline int cpu_core_index_of_thread(int cpu) { return cpu; }
static inline int cpu_first_thread_of_core(int core) { return core; }
#endif
static inline int cpu_thread_in_core(int cpu)
{
return cpu & (threads_per_core - 1);
}
static inline int cpu_first_thread_sibling(int cpu)
{
return cpu & ~(threads_per_core - 1);
}
static inline int cpu_last_thread_sibling(int cpu)
{
return cpu | (threads_per_core - 1);
}
#endif /* _ASM_POWERPC_CPUTHREADS_H */
|
395d06be140e3a7101241f45996fb7bdaed8bcc4
|
63a611d8e587f850e5077637594617083ccf64c0
|
/javatools_launcher/src/main/c/os_macos.c
|
f6fd0b3386b6a797fd8e85fa78df0c6a0c523387
|
[
"CC-BY-4.0",
"LicenseRef-scancode-generic-cla",
"Apache-2.0"
] |
permissive
|
xtclang/xvm
|
077a5500c90eecacae47a2e0775c5ef6cce5b4bd
|
d35279a7ab3613ac84938a7e5c399313ba2d8af4
|
refs/heads/master
| 2023-09-01T21:08:59.379497
| 2023-09-01T15:45:37
| 2023-09-01T15:45:37
| 196,110,471
| 187
| 16
|
NOASSERTION
| 2023-08-30T11:56:59
| 2019-07-10T01:46:15
|
Java
|
UTF-8
|
C
| false
| false
| 770
|
c
|
os_macos.c
|
#include <string.h>
#include <mach-o/dyld.h>
#include "launcher.h"
#include "os_specific.h"
const char* findLauncherPath()
{
char* result = NULL;
char localBuf[32];
uint32_t size = 32;
int err = _NSGetExecutablePath(localBuf, &size);
switch (err)
{
case 0:
result = allocBuffer(strlen(localBuf));
strcpy(result, localBuf);
break;
case -1:
result = allocBuffer(size);
if (_NSGetExecutablePath(result, &size) != 0)
{
abortLaunch("failure in _NSGetExecutablePath()");
}
break;
default:
abortLaunch("failure in initial _NSGetExecutablePath()");
}
return result;
}
|
f70cdbfdab0db7a5786a44e81b21a59c3e1e9da5
|
8c2e6410771ecd17b9c5c4ec3170ac08137a53f2
|
/src/test.c
|
5ec682ac190821aad482183f5555620c09b71e4e
|
[
"MIT"
] |
permissive
|
ryanlayer/giggle
|
f09b8f982010dee5ef26d4f6c581e0b2d5a2c991
|
4071cb773f8af74aa3e3a2db1c22cca551409b70
|
refs/heads/master
| 2022-12-22T19:20:13.269573
| 2022-12-12T17:09:14
| 2022-12-12T17:09:14
| 47,425,454
| 219
| 30
|
MIT
| 2022-12-12T17:09:16
| 2015-12-04T19:48:08
|
C
|
UTF-8
|
C
| false
| false
| 3,690
|
c
|
test.c
|
#include <stdlib.h>
#include <stdio.h>
#include <err.h>
#include <string.h>
#include "giggle_index.h"
#include "wah.h"
#include "cache.h"
#include "ll.h"
int main(int argc, char **argv)
{
uint32_t num_chrms = 100;
if ((argc != 4)) {
errx(1,
"usage:\t%s <index dir> <region> <w|i>",
argv[0]);
}
char *index_dir = argv[1];
char *region_s = argv[2];
char *i_type = argv[3];
struct giggle_index *gi;
gi = giggle_load(index_dir,
uint64_t_ll_giggle_set_data_handler);
#if 0
char *chrm = region_s;
uint32_t start = 0, end = 0;
uint32_t i, len = strlen(region_s);
for (i = 0; i < len; ++i) {
if (region_s[i] == ':') {
region_s[i] = '\0';
start = atoi(region_s + i + 1);
} else if (region_s[i] == '-') {
region_s[i] = '\0';
end = atoi(region_s + i + 1);
break;
}
}
struct giggle_index *gi;
if (i_type[0] == 'i') {
gi = giggle_load(index_dir,
uint64_t_ll_giggle_set_data_handler);
struct uint64_t_ll *R =
(struct uint64_t_ll *)giggle_query_region(gi,
chrm,
start,
end);
if (R != NULL)
printf("Hits:%u\n", R->len);
else
printf("Hits:0\n");
} else {
gi = giggle_load(index_dir,
wah_giggle_set_data_handler);
uint32_t chr_id = giggle_get_chrm_id(gi, chrm);
//return giggle_search(chr_id, gi->root_ids[chr_id], start, end);
uint32_t domain = chr_id;
uint32_t root_id = gi->root_ids[chr_id];
uint32_t leaf_start_id;
int pos_start_id;
uint32_t nld_start_id = bpt_find(domain,
root_id,
&leaf_start_id,
&pos_start_id,
start);
fprintf(stderr,
"nld_start_id:%u\t"
"leaf_start_id:%u\t"
"pos_start_id:%u\n",
nld_start_id,
leaf_start_id,
pos_start_id);
struct bpt_node *leaf_start = cache.get(domain,
leaf_start_id - 1,
&bpt_node_cache_handler);
bpt_print_node(leaf_start);
struct wah_bpt_non_leading_data *nld =
cache.get(domain,
BPT_POINTERS(leaf_start)[0] - 1,
&wah_non_leading_cache_handler);
fprintf(stderr,
"WAH_LEN:%u\t"
"wah_get_ints_count:%u\t"
"\n",
WAH_LEN(nld->SA),
wah_get_ints_count(nld->SA));
uint32_t *R = NULL;
uint32_t R_len = wah_get_ints(nld->SA, &R);
uint32_t i;
for (i = 0; i < R_len; ++i) {
fprintf(stderr, "%u:%u\n", i, R[i]);
}
/*
uint8_t *R = (uint8_t *)giggle_query_region(gi,
chrm,
start,
end);
if (R != NULL)
printf("Hits:%u\n", wah_get_ints_count(R));
else
printf("Hits:0\n");
*/
}
#endif
giggle_index_destroy(&gi);
cache.destroy();
}
|
c8dacb26bd8e5d07cdd107410f7d7b5233c9e846
|
4bcc9806152542ab43fc2cf47c499424f200896c
|
/tensorflow/lite/kernels/internal/optimized/neon_check.h
|
bbf745ce1d12c7ad24d3f71d71b608ab706e91d4
|
[
"Apache-2.0",
"LicenseRef-scancode-generic-cla",
"BSD-2-Clause"
] |
permissive
|
tensorflow/tensorflow
|
906276dbafcc70a941026aa5dc50425ef71ee282
|
a7f3934a67900720af3d3b15389551483bee50b8
|
refs/heads/master
| 2023-08-25T04:24:41.611870
| 2023-08-25T04:06:24
| 2023-08-25T04:14:08
| 45,717,250
| 208,740
| 109,943
|
Apache-2.0
| 2023-09-14T20:55:50
| 2015-11-07T01:19:20
|
C++
|
UTF-8
|
C
| false
| false
| 1,473
|
h
|
neon_check.h
|
/* Copyright 2019 The TensorFlow Authors. 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.
==============================================================================*/
#ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_OPTIMIZED_NEON_CHECK_H_
#define TENSORFLOW_LITE_KERNELS_INTERNAL_OPTIMIZED_NEON_CHECK_H_
#if defined(__ARM_NEON__) || defined(__ARM_NEON)
#define USE_NEON
#include <arm_neon.h>
#endif
#if defined __GNUC__ && defined __SSE4_1__ && !defined TF_LITE_DISABLE_X86_NEON
#define USE_NEON
#include "NEON_2_SSE.h"
#endif
// NEON_OR_PORTABLE(SomeFunc, args) calls NeonSomeFunc(args) if USE_NEON is
// defined, PortableSomeFunc(args) otherwise.
#ifdef USE_NEON
// Always use Neon code
#define NEON_OR_PORTABLE(funcname, ...) Neon##funcname(__VA_ARGS__)
#else
// No NEON available: Use Portable code
#define NEON_OR_PORTABLE(funcname, ...) Portable##funcname(__VA_ARGS__)
#endif // defined(USE_NEON)
#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_OPTIMIZED_NEON_CHECK_H_
|
ab342106050e5e225fa9718ddee6a0c504f5e580
|
2e4f2be5f3a130762740b48c33030a8ec26e2885
|
/cmod/MemModel/MemModel.h
|
39d7bf5201b0ea82bfa8982e177b6f3aec17d044
|
[
"Apache-2.0",
"MIT"
] |
permissive
|
NVlabs/matchlib
|
8031c14d67693185d6c1b4fd12b1708b22ed1914
|
12786cc09d78cd5677a35a94c676f0fec7348f07
|
refs/heads/main
| 2023-08-29T18:06:38.045736
| 2023-07-24T21:25:54
| 2023-07-24T22:20:46
| 176,341,843
| 213
| 52
|
NOASSERTION
| 2023-07-24T22:20:48
| 2019-03-18T17:59:52
|
C++
|
UTF-8
|
C
| false
| false
| 1,060
|
h
|
MemModel.h
|
/*
* Copyright (c) 2016-2019, NVIDIA CORPORATION. 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.
*/
#ifndef MEM_MODEL_H
#define MEM_MODEL_H
#include <nvhls_int.h>
#include <nvhls_types.h>
#include <mem_array.h>
#include <hls_globals.h>
#include "mem_config.h"
// Top-level function used to model mem_array
// data represent the i/o data line
// mem_op is memory operation type (READ/WRITE)
// addr is the memory address
void MemModel(MemWord_t write_data, MemWord_t & read_data, NVUINT1 mem_op, MemAddr_t addr);
#endif
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.