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
|
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
87f0875b822a902cf918809967a19fec2e6d0afc
|
4b52bc727e3757a133a02fe5b98dcbdbe80bb2e6
|
/back/object.c
|
4f14d89b465c57c901a562b828ca39ed25f82e28
|
[
"MIT"
] |
permissive
|
never-lang/never
|
bbad1b6c6de7cd14c1cd956fdb9622f03cd2db9a
|
008b8f3a143513cda312473595dccb9b1212981d
|
refs/heads/master
| 2023-09-04T09:20:41.379437
| 2023-09-02T07:39:04
| 2023-09-02T07:39:04
| 134,974,042
| 432
| 19
|
MIT
| 2023-09-02T07:29:45
| 2018-05-26T15:41:59
|
C
|
UTF-8
|
C
| false
| false
| 11,322
|
c
|
object.c
|
/**
* Copyright 2018 Slawomir Maludzinski
*
* 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 "object.h"
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
unsigned int nil_ptr = 0;
object * object_new()
{
object * obj = (object *)malloc(sizeof(object));
return obj;
}
object * object_new_int(int value)
{
object * obj = (object *)malloc(sizeof(object));
obj->type = OBJECT_INT;
obj->int_value = value;
return obj;
}
object * object_new_long(long long value)
{
object * obj = (object *)malloc(sizeof(object));
obj->type = OBJECT_LONG;
obj->long_value = value;
return obj;
}
object * object_new_float(float value)
{
object * obj = (object *)malloc(sizeof(object));
obj->type = OBJECT_FLOAT;
obj->float_value = value;
return obj;
}
object * object_new_double(double value)
{
object * obj = (object *)malloc(sizeof(object));
obj->type = OBJECT_DOUBLE;
obj->double_value = value;
return obj;
}
object * object_new_char(float value)
{
object * obj = (object *)malloc(sizeof(object));
obj->type = OBJECT_CHAR;
obj->char_value = value;
return obj;
}
object * object_new_string(char * value)
{
object * obj = (object *)malloc(sizeof(object));
obj->type = OBJECT_STRING;
obj->string_value = strdup(value);
return obj;
}
object * object_new_string_take(char * value)
{
object * obj = (object *)malloc(sizeof(object));
obj->type = OBJECT_STRING;
obj->string_value = value;
return obj;
}
object * object_new_string_ref(mem_ptr str_value)
{
object * obj = (object *)malloc(sizeof(object));
obj->type = OBJECT_STRING_REF;
obj->string_ref_value = str_value;
return obj;
}
object * object_new_string_arr(unsigned int argc, char ** argv)
{
object * obj = (object *)malloc(sizeof(object));
obj->type = OBJECT_STRING_ARR;
obj->string_arr_value->argc = argc;
obj->string_arr_value->argv = argv;
return obj;
}
object * object_new_c_ptr(void * value)
{
object * obj = (object *)malloc(sizeof(object));
obj->type = OBJECT_C_PTR;
obj->c_ptr_value = value;
return obj;
}
object * object_new_vec(unsigned int size)
{
object * obj = (object *)malloc(sizeof(object));
object_vec * vec_value = (object_vec *)malloc(sizeof(object_vec));
vec_value->size = size;
if (vec_value->size == 0)
{
vec_value->value = NULL;
}
else
{
vec_value->value = (mem_ptr *)malloc(size * sizeof(mem_ptr));
}
obj->type = OBJECT_VEC;
obj->vec_value = vec_value;
return obj;
}
object * object_new_vec_ref(mem_ptr vec_value)
{
object * obj = (object *)malloc(sizeof(object));
obj->type = OBJECT_VEC_REF;
obj->vec_ref_value = vec_value;
return obj;
}
object * object_new_arr(unsigned int dims, object_arr_dim * dv)
{
object * obj = (object *)malloc(sizeof(object));
object_arr * arr_value = (object_arr *)malloc(sizeof(object_arr));
arr_value->dims = dims;
arr_value->dv = dv;
object_arr_dim_mult(dims, arr_value->dv, &arr_value->elems);
if (arr_value->elems != 0)
{
arr_value->value =
(mem_ptr *)malloc(arr_value->elems * sizeof(mem_ptr));
}
else
{
arr_value->value = NULL;
}
obj->type = OBJECT_ARRAY;
obj->arr_value = arr_value;
return obj;
}
object * object_new_arr_ref(mem_ptr arr_value)
{
object * obj = (object *)malloc(sizeof(object));
obj->type = OBJECT_ARRAY_REF;
obj->arr_ref_value = arr_value;
return obj;
}
object * object_new_func(mem_ptr vec, ip_ptr addr)
{
object * obj = (object *)malloc(sizeof(object));
object_func * func_value = (object_func *)malloc(sizeof(object_func));
func_value->vec = vec;
func_value->addr = addr;
obj->type = OBJECT_FUNC;
obj->func_value = func_value;
return obj;
}
void object_delete(object * obj)
{
switch (obj->type)
{
case OBJECT_UNKNOWN:
assert(0);
break;
case OBJECT_INT:
case OBJECT_LONG:
case OBJECT_FLOAT:
case OBJECT_DOUBLE:
case OBJECT_CHAR:
break;
case OBJECT_STRING:
if (obj->string_value != NULL)
{
free(obj->string_value);
}
break;
case OBJECT_STRING_REF:
break;
case OBJECT_STRING_ARR:
object_str_arr_delete(obj->string_arr_value);
break;
case OBJECT_C_PTR:
break;
case OBJECT_VEC:
if (obj->vec_value != NULL && obj->vec_value->value != NULL)
{
free(obj->vec_value->value);
}
if (obj->vec_value != NULL)
{
free(obj->vec_value);
}
break;
case OBJECT_VEC_REF:
break;
case OBJECT_ARRAY:
if (obj->arr_value != NULL)
{
object_arr_delete(obj->arr_value);
}
break;
case OBJECT_ARRAY_REF:
break;
case OBJECT_FUNC:
free(obj->func_value);
break;
}
free(obj);
}
void object_arr_delete(object_arr * arr_value)
{
if (arr_value->value != NULL)
{
free(arr_value->value);
}
if (arr_value->dv != NULL)
{
object_arr_dim_delete(arr_value->dv);
}
free(arr_value);
}
object_str_arr * object_str_arr_new(unsigned int argc, char ** argv)
{
object_str_arr * value = (object_str_arr *)malloc(sizeof(object_str_arr));
value->argc = argc;
value->argv = argv;
return value;
}
void object_str_arr_delete(object_str_arr * value)
{
if (value)
{
free(value);
}
}
object_arr_dim * object_arr_dim_new(unsigned int dims)
{
object_arr_dim * dv =
(object_arr_dim *)malloc(dims * sizeof(object_arr_dim));
return dv;
}
void object_arr_dim_delete(object_arr_dim * dv) { free(dv); }
void object_arr_dim_mult(unsigned int dims, object_arr_dim * dv,
unsigned int * elems)
{
unsigned int d = 0;
unsigned int e = 1;
for (d = 0; d < dims; d++)
{
e *= dv[d].elems;
}
*elems = e;
for (d = 0; d < dims; d++)
{
if (dv[d].elems != 0)
{
e /= dv[d].elems;
dv[d].mult = e;
}
else
{
dv[d].mult = 1;
}
}
}
unsigned int object_arr_dim_addr(unsigned int dims, object_arr_dim * dv,
object_arr_dim * addr, int * oobounds)
{
unsigned int m;
unsigned int addr_int = 0;
for (m = 0; m < dims; m++)
{
if (dv[m].elems <= addr[m].mult)
{
*oobounds = m;
return 0;
}
addr_int += dv[m].mult * addr[m].mult;
}
*oobounds = -1;
return addr_int;
}
object_arr_dim * object_arr_dim_copy(unsigned int dims, object_arr_dim * value)
{
unsigned int d;
object_arr_dim * dv =
(object_arr_dim *)malloc(dims * sizeof(object_arr_dim));
for (d = 0; d < dims; d++)
{
dv[d].elems = value[d].elems;
dv[d].mult = value[d].mult;
}
return dv;
}
object * object_arr_copy(object * value)
{
object * obj = (object *)malloc(sizeof(object));
object_arr * arr_value = value->arr_value;
object_arr * copy = (object_arr *)malloc(sizeof(object_arr));
copy->dims = arr_value->dims;
copy->elems = arr_value->elems;
copy->dv = object_arr_dim_copy(arr_value->dims, arr_value->dv);
if (copy->elems != 0)
{
copy->value =
(mem_ptr *)malloc(copy->elems * sizeof(mem_ptr));
}
else
{
copy->value = NULL;
}
obj->type = OBJECT_ARRAY;
obj->arr_value = copy;
return obj;
}
void object_arr_append(object_arr * arr_value, mem_ptr value)
{
assert(arr_value->dims == 1);
arr_value->elems++;
arr_value->dv[0].elems++;
arr_value->value = (mem_ptr *)realloc(arr_value->value, sizeof(mem_ptr) * arr_value->elems);
arr_value->value[arr_value->elems - 1] = value;
}
char object_arr_can_add(object_arr * arr1, object_arr * arr2)
{
unsigned int d;
if (arr1 == NULL || arr2 == NULL)
{
return 0;
}
if (arr1->dims != arr2->dims)
{
return 0;
}
for (d = 0; d < arr1->dims; d++)
{
if (arr1->dv[d].elems != arr2->dv[d].elems)
{
return 0;
}
}
return 1;
}
char object_arr_can_mult(object_arr * arr1, object_arr * arr2)
{
if (arr1 == NULL || arr2 == NULL)
{
return 0;
}
if (arr1->dims != 2 || arr2->dims != 2)
{
return 0;
}
if (arr1->dv[1].elems == arr2->dv[0].elems)
{
return 1;
}
return 0;
}
void object_arr_print(object_arr * value)
{
unsigned int d;
printf("object_array\n");
printf("arr->dims %d\n", value->dims);
printf("arr->elems %d\n", value->elems);
for (d = 0; d < value->dims; d++)
{
printf("arr->dv[%d].elems %d\n", d, value->dv[d].elems);
printf("arr->dv[%d].mult %d\n", d, value->dv[d].mult);
}
}
void object_print(object * obj)
{
switch (obj->type)
{
case OBJECT_UNKNOWN:
printf("object_unknown\n");
break;
case OBJECT_INT:
printf("object_int %d\n", obj->int_value);
break;
case OBJECT_LONG:
printf("object_long\n");
break;
case OBJECT_FLOAT:
printf("object_float\n");
break;
case OBJECT_DOUBLE:
printf("object_double\n");
break;
case OBJECT_CHAR:
printf("object_char\n");
break;
case OBJECT_STRING:
printf("object_string\n");
break;
case OBJECT_STRING_REF:
printf("object_string_ref\n");
break;
case OBJECT_STRING_ARR:
printf("object_string_arr\n");
break;
case OBJECT_C_PTR:
printf("object_c_ptr\n");
break;
case OBJECT_VEC:
printf("object_vec\n");
break;
case OBJECT_VEC_REF:
printf("object_vec_ref\n");
break;
case OBJECT_ARRAY:
object_arr_print(obj->arr_value);
break;
case OBJECT_ARRAY_REF:
printf("object_arr_ref\n");
break;
case OBJECT_FUNC:
printf("object_func\n");
break;
}
}
|
6798132417828fce9d02a2962740c159ac8fead7
|
e73547787354afd9b717ea57fe8dd0695d161821
|
/src/world/common/enemy/FlyingMagikoopa.h
|
72e6397ff5df82a0958a50a509297a2e201a89d4
|
[] |
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
| 2,437
|
h
|
FlyingMagikoopa.h
|
#include "common.h"
#include "sprite/npc/Magikoopa.h"
#include "sprite/npc/FlyingMagikoopa.h"
#define FLYING_MAGINO_DROPS \
{ \
.dropFlags = NPC_DROP_FLAG_80, \
.itemDropChance = 5, \
.itemDrops = { \
{ ITEM_SUPER_SHROOM, 5, 0 }, \
{ ITEM_MAPLE_SYRUP, 5, 0 }, \
{ ITEM_THUNDER_RAGE, 5, 0 }, \
{ ITEM_STOP_WATCH, 5, 0 }, \
}, \
.heartDrops = STANDARD_HEART_DROPS(2), \
.flowerDrops = STANDARD_FLOWER_DROPS(5), \
.minCoinBonus = 1, \
.maxCoinBonus = 3, \
}
#define FLYING_MAGIKOOPA_ANIMS \
{ \
.idle = ANIM_FlyingMagikoopa_Anim00, \
.walk = ANIM_FlyingMagikoopa_Anim01, \
.run = ANIM_FlyingMagikoopa_Anim01, \
.chase = ANIM_FlyingMagikoopa_Anim01, \
.anim_4 = ANIM_FlyingMagikoopa_Anim01, \
.anim_5 = ANIM_FlyingMagikoopa_Anim01, \
.death = ANIM_FlyingMagikoopa_Anim04, \
.hit = ANIM_FlyingMagikoopa_Anim04, \
.anim_8 = ANIM_FlyingMagikoopa_Anim02, \
.anim_9 = ANIM_FlyingMagikoopa_Anim03, \
.anim_A = ANIM_FlyingMagikoopa_Anim01, \
.anim_B = ANIM_FlyingMagikoopa_Anim01, \
.anim_C = ANIM_FlyingMagikoopa_Anim01, \
.anim_D = ANIM_FlyingMagikoopa_Anim01, \
.anim_E = ANIM_FlyingMagikoopa_Anim01, \
.anim_F = ANIM_FlyingMagikoopa_Anim01, \
}
#define FLYING_MAGIKOOPA_SPELL_HITBOX(npcID) \
{ \
.id = npcID, \
.settings = &N(NpcSettings_FlyingMagikoopa_Hitbox), \
.pos = { NPC_DISPOSE_LOCATION }, \
.yaw = 90, \
.flags = ENEMY_FLAG_IGNORE_WORLD_COLLISION | ENEMY_FLAG_IGNORE_ENTITY_COLLISION | ENEMY_FLAG_FLYING | ENEMY_FLAG_NO_DROPS, \
.drops = NO_DROPS, \
.animations = { \
.idle = ANIM_FlyingMagikoopa_Anim00, \
.walk = ANIM_FlyingMagikoopa_Anim00, \
.run = ANIM_FlyingMagikoopa_Anim00, \
.chase = ANIM_FlyingMagikoopa_Anim00, \
.anim_4 = ANIM_FlyingMagikoopa_Anim00, \
.anim_5 = ANIM_FlyingMagikoopa_Anim00, \
.death = ANIM_FlyingMagikoopa_Anim00, \
.hit = ANIM_FlyingMagikoopa_Anim00, \
.anim_8 = ANIM_FlyingMagikoopa_Anim00, \
.anim_9 = ANIM_FlyingMagikoopa_Anim00, \
.anim_A = ANIM_FlyingMagikoopa_Anim00, \
.anim_B = ANIM_FlyingMagikoopa_Anim00, \
.anim_C = ANIM_FlyingMagikoopa_Anim00, \
.anim_D = ANIM_FlyingMagikoopa_Anim00, \
.anim_E = ANIM_FlyingMagikoopa_Anim00, \
.anim_F = ANIM_FlyingMagikoopa_Anim00, \
}, \
}
|
7559f9bfa7fa87b0cb8f7e2ce19ef0236d0361df
|
99bdb3251fecee538e0630f15f6574054dfc1468
|
/bsp/allwinner/libraries/sunxi-hal/hal/source/sdmmc/_sdio.h
|
f3d790405046aaac1a4ee99161a6c45678eb8411
|
[
"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
| 2,870
|
h
|
_sdio.h
|
/*
* Copyright (C) 2017 ALLWINNERTECH TECHNOLOGY CO., LTD. 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 ALLWINNERTECH TECHNOLOGY CO., LTD. nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _ROM_DRIVER_CHIP_SDMMC__SDIO_H_
#define _ROM_DRIVER_CHIP_SDMMC__SDIO_H_
#include "_core.h"
#ifdef __cplusplus
extern "C" {
#endif
/*
* Standard SDIO Function Interfaces
*/
#define SDIO_CLASS_NONE 0x00 /* Not a SDIO standard interface */
#define SDIO_CLASS_UART 0x01 /* standard UART interface */
#define SDIO_CLASS_BT_A 0x02 /* Type-A BlueTooth std interface */
#define SDIO_CLASS_BT_B 0x03 /* Type-B BlueTooth std interface */
#define SDIO_CLASS_GPS 0x04 /* GPS standard interface */
#define SDIO_CLASS_CAMERA 0x05 /* Camera standard interface */
#define SDIO_CLASS_PHS 0x06 /* PHS standard interface */
#define SDIO_CLASS_WLAN 0x07 /* WLAN interface */
#define SDIO_CLASS_ATA 0x08 /* Embedded SDIO-ATA std interface */
#define SDIO_CLASS_BT_AMP 0x09 /* Type-A Bluetooth AMP interface */
extern uint32_t mmc_sdio_get_max_clock(struct mmc_card *card);
extern uint32_t sdio_reset(struct mmc_host *host);
extern int mmc_attach_sdio(struct mmc_card *card, struct mmc_host *host);
extern void mmc_deattach_sdio(struct mmc_card *card, struct mmc_host *host);
#ifdef __cplusplus
}
#endif
#endif /* _ROM_DRIVER_CHIP_SDMMC__SDIO_H_ */
|
f6d9472cd8c7a9212bf50ece466ca1ced1f100fc
|
7eaf54a78c9e2117247cb2ab6d3a0c20719ba700
|
/SOFTWARE/A64-TERES/linux-a64/drivers/usb/sunxi_usb/udc/sunxi_udc_dma.h
|
f74470e49846ebf20bd32fffa2aed348324e8a63
|
[
"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,319
|
h
|
sunxi_udc_dma.h
|
/*
* drivers/usb/sunxi_usb/udc/sunxi_udc_dma.h
* (C) Copyright 2010-2015
* Allwinner Technology Co., Ltd. <www.allwinnertech.com>
* javen, 2010-3-3, create this file
*
* udc dma ops.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
*/
#ifndef __SUNXI_UDC_DMA_H__
#define __SUNXI_UDC_DMA_H__
#ifdef SW_UDC_DMA
#define is_udc_support_dma() 1
#else
#define is_udc_support_dma() 0
#endif
/* dma channel total */
#define DMA_CHAN_TOTAL (8)
typedef int *dm_hdl_t;
/* define dma channel struct */
typedef struct {
u32 used; /* 1 used, 0 unuse */
u32 channel_num;
u32 ep_num; /* the ep's index in sunxi_udc.ep[] */
void __iomem *reg_base; /* regs base addr */
spinlock_t lock; /* dma channel lock */
}dma_channel_t;
extern dma_channel_t dma_chnl[DMA_CHAN_TOTAL];
/*
* dma config information
*/
struct dma_config_t {
spinlock_t lock; /* dma channel lock */
u32 dma_num;
u32 dma_working;
u32 dma_en;
u32 dma_bst_len;
u32 dma_dir;
u32 dma_for_ep;
u32 dma_sdram_str_addr;
u32 dma_bc;
u32 dma_residual_bc;
};
void sunxi_udc_switch_bus_to_dma(struct sunxi_udc_ep *ep, u32 is_tx);
void sunxi_udc_switch_bus_to_pio(struct sunxi_udc_ep *ep, __u32 is_tx);
void sunxi_udc_enable_dma_channel_irq(struct sunxi_udc_ep *ep);
void sunxi_udc_disable_dma_channel_irq(struct sunxi_udc_ep *ep);
void sunxi_dma_set_config(dm_hdl_t dma_hdl, struct dma_config_t *pcfg);
dm_hdl_t sunxi_udc_dma_request(void);
int sunxi_udc_dma_release(dm_hdl_t dma_hdl);
void sunxi_udc_dma_set_config(struct sunxi_udc_ep *ep, struct sunxi_udc_request *req, __u32 buff_addr, __u32 len);
void sunxi_udc_dma_start(struct sunxi_udc_ep *ep, void __iomem *fifo, __u32 buffer, __u32 len);
void sunxi_udc_dma_stop(struct sunxi_udc_ep *ep);
__u32 sunxi_udc_dma_transmit_length(struct sunxi_udc_ep *ep);
__u32 sunxi_udc_dma_is_busy(struct sunxi_udc_ep *ep);
void sunxi_udc_dma_completion(struct sunxi_udc *dev, struct sunxi_udc_ep *ep, struct sunxi_udc_request *req);
__s32 sunxi_udc_dma_probe(struct sunxi_udc *dev);
__s32 sunxi_udc_dma_remove(struct sunxi_udc *dev);
#endif //__SUNXI_UDC_DMA_H__
|
18ae184ee4bfac653f7059299e2811cb36533509
|
a212573b7e2de18939686746cb405ea228a25f1b
|
/fifo.h
|
1ed9709806eaaa9e5784eb43981455689fa2f243
|
[
"ISC"
] |
permissive
|
mypaint/libmypaint
|
0878b446455eb8773ea708e646dff97cf5afbcb9
|
826069db12843b5b3ddbc8ad1690453c9a36e19e
|
refs/heads/master
| 2023-06-23T07:10:42.234308
| 2021-04-16T13:40:11
| 2021-04-17T14:27:41
| 20,728,367
| 305
| 112
|
NOASSERTION
| 2023-06-14T18:41:00
| 2014-06-11T14:31:54
|
C
|
UTF-8
|
C
| false
| false
| 355
|
h
|
fifo.h
|
#ifndef FIFO_H
#define FIFO_H
typedef struct fifo Fifo;
typedef void (*FifoUserFreeFunction) (void *item_data);
Fifo* fifo_new(void);
void fifo_free(Fifo* self, FifoUserFreeFunction data_free);
void fifo_push(Fifo* self, void* data);
void* fifo_pop(Fifo* self);
void* fifo_peek_first(Fifo *queue);
void* fifo_peek_last(Fifo *queue);
#endif // FIFO_H
|
b20f51c44133383970160a6ea0a83c91a5524ba3
|
35e28d7705773eed54345af4440700522c9d1863
|
/deps/libgdal/gdal/frmts/hdf4/hdf-eos/HDFEOSVersion.h
|
6d316c9b619b80f5bb5b3d6fd7eb4c44be6e96bf
|
[
"Apache-2.0",
"LicenseRef-scancode-public-domain",
"BSD-2-Clause",
"LicenseRef-scancode-warranty-disclaimer",
"MIT",
"SunPro",
"LicenseRef-scancode-info-zip-2005-02",
"BSD-3-Clause"
] |
permissive
|
naturalatlas/node-gdal
|
0ee3447861bf2d1abc48d4fbdbcf15aba5473a27
|
c83e7858a9ec566cc91d65db74fd07b99789c0f0
|
refs/heads/master
| 2023-09-03T00:11:41.576937
| 2022-03-12T20:41:59
| 2022-03-12T20:41:59
| 19,504,824
| 522
| 122
|
Apache-2.0
| 2022-06-04T20:03:43
| 2014-05-06T18:02:34
|
C++
|
UTF-8
|
C
| false
| false
| 797
|
h
|
HDFEOSVersion.h
|
#include <stdlib.h>
/* define strings that will be displayed by the using the UNIX "what" command
on a file containing these strings */
#define HDFEOSd_BANNER "@(#)## ================= HDFEOS ================"
#ifdef __GNUC__
#define HDFEOSd_HDFEOS_VER "@(#)## HDFEOS Version: "HDFEOSVERSION1
/* #define HDFEOSd_DATE "@(#)## Build date: "__DATE__" @ "__TIME__ */
#else
#define HDFEOSd_HDFEOS_VER "@(#)## HDFEOS Version: "##HDFEOSVERSION1
/* #define HDFEOSd_DATE "@(#)## Build date: "##__DATE__##" @ "##__TIME__ */
#endif
const char *hdfeosg_LibraryVersionString01 = HDFEOSd_BANNER;
const char *hdfeosg_LibraryVersionString02 = HDFEOSd_HDFEOS_VER;
/*const char *hdfeosg_LibraryVersionString03 = HDFEOSd_DATE; */
const char *hdfeosg_LibraryVersionString04 = HDFEOSd_BANNER;
|
4dcfe7be4e34fe33fc6803c886780e7c0ec00ae4
|
baa9fffc817a2a993d4ecc774d3f277783308c20
|
/src/ucp/proto/proto_single.h
|
a414f123a811fa1e723a69487897d5898051a5b2
|
[
"BSD-3-Clause"
] |
permissive
|
openucx/ucx
|
9a0f2205295afbdf3cff14b5d24af781b123f5ea
|
73a48700badb7cbace64d94b82f408e2a26fca32
|
refs/heads/master
| 2023-09-01T16:51:26.913950
| 2023-09-01T13:02:25
| 2023-09-01T13:02:25
| 25,379,390
| 966
| 420
|
NOASSERTION
| 2023-09-14T12:29:35
| 2014-10-17T22:17:24
|
C
|
UTF-8
|
C
| false
| false
| 1,378
|
h
|
proto_single.h
|
/**
* Copyright (c) NVIDIA CORPORATION & AFFILIATES, 2020-2021. ALL RIGHTS RESERVED.
*
* See file LICENSE for terms.
*/
#ifndef UCP_PROTO_SINGLE_H_
#define UCP_PROTO_SINGLE_H_
#include "proto.h"
#include "proto_common.h"
typedef struct {
ucp_proto_common_lane_priv_t super;
ucp_md_index_t reg_md; /* memory domain to register on, or NULL */
} ucp_proto_single_priv_t;
typedef struct {
ucp_proto_common_init_params_t super;
ucp_lane_type_t lane_type; /* Type of lane to select */
uint64_t tl_cap_flags; /* Required iface capabilities */
} ucp_proto_single_init_params_t;
ucs_status_t ucp_proto_single_init(const ucp_proto_single_init_params_t *params);
ucs_status_t
ucp_proto_single_init_priv(const ucp_proto_single_init_params_t *params,
ucp_proto_single_priv_t *spriv);
void ucp_proto_single_query(const ucp_proto_query_params_t *params,
ucp_proto_query_attr_t *attr);
typedef ucs_status_t (*ucp_proto_send_single_cb_t)(
ucp_request_t *req, const ucp_proto_single_priv_t *spriv,
uct_iov_t *iov);
typedef ucs_status_t (*ucp_proto_request_zcopy_init_cb_t)(
ucp_request_t *req, ucp_md_map_t md_map,
uct_completion_callback_t comp_func, unsigned uct_reg_flags,
unsigned dt_mask);
#endif
|
b0d3f5ce375d39a4a9fd3c9cdf94902546f38990
|
8149d6751e142ecbc200b43c2da2d5a94c0735df
|
/modules/gst/gst.c
|
d088f7e742df6d24018b9c68c2d763db791334e1
|
[
"BSD-3-Clause"
] |
permissive
|
baresip/baresip
|
3c8ebef031f6a01a1462a9f36264197f90ce6ffe
|
5ace2f75b317bba60d46030ca3fd5e8fa045fecf
|
refs/heads/main
| 2023-08-25T12:55:24.860248
| 2023-08-17T06:56:31
| 2023-08-17T06:56:31
| 16,664,594
| 834
| 205
|
BSD-3-Clause
| 2023-09-14T12:47:57
| 2014-02-09T10:44:09
|
C
|
UTF-8
|
C
| false
| false
| 10,818
|
c
|
gst.c
|
/**
* @file gst/gst.c Gstreamer 1.0 playbin pipeline
*
* Copyright (C) 2010 - 2015 Alfred E. Heggestad
*/
#define _DEFAULT_SOURCE 1
#define _POSIX_C_SOURCE 199309L
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <gst/gst.h>
#include <unistd.h>
#include <re.h>
#include <rem.h>
#include <baresip.h>
/**
* @defgroup gst gst
*
* Audio source module using gstreamer 1.0 as input
*
* The module 'gst' is using the Gstreamer framework to play external
* media and provide this as an internal audio source.
*
* Example config:
\verbatim
audio_source gst,http://relay.slayradio.org:8000/
\endverbatim
*/
/**
* Defines the Gstreamer state
*
* <pre>
* ptime=variable ptime=20ms
* .-----------. N kHz .---------. N kHz
* | | 1-2 channels | | 1-2 channels
* | Gstreamer |--------------->|Packetize|-------------> [read handler]
* | | | |
* '-----------' '---------'
*
* </pre>
*/
struct ausrc_st {
bool run; /**< Running flag */
bool eos; /**< Reached end of stream */
ausrc_read_h *rh; /**< Read handler */
ausrc_error_h *errh; /**< Error handler */
void *arg; /**< Handler argument */
struct ausrc_prm prm; /**< Read parameters */
struct aubuf *aubuf; /**< Packet buffer */
size_t psize; /**< Packet size in bytes */
size_t sampc;
uint32_t ptime;
int16_t *buf;
int err;
struct tmr tmr;
/* Gstreamer */
char *uri;
GstElement *pipeline, *bin, *source, *capsfilt, *sink;
};
static struct ausrc *ausrc;
static char *uri_regex = "([a-z][a-z0-9+.-]*):(?://).*";
static GstBusSyncReply
sync_handler(
GstBus * bus, GstMessage * msg,
struct ausrc_st *st)
{
GstTagList *tag_list;
gchar *title;
GError *err;
gchar *d;
(void)bus;
switch (GST_MESSAGE_TYPE(msg)) {
case GST_MESSAGE_EOS:
st->run = false;
st->eos = true;
break;
case GST_MESSAGE_ERROR:
gst_message_parse_error(msg, &err, &d);
warning("gst: Error: %d(%m) message=\"%s\"\n",
err->code,
err->code, err->message);
warning("gst: Debug: %s\n", d);
g_free(d);
st->err = err->code;
/* Call error handler */
if (st->errh)
st->errh(err->code, err->message, st->arg);
g_error_free(err);
st->run = false;
break;
case GST_MESSAGE_TAG:
gst_message_parse_tag(msg, &tag_list);
if (gst_tag_list_get_string(
tag_list,
GST_TAG_TITLE,
&title)) {
info("gst: title: '%s'\n", title);
g_free(title);
}
gst_tag_list_unref(tag_list);
break;
default:
break;
}
gst_message_unref(msg);
return GST_BUS_DROP;
}
static void format_check(struct ausrc_st *st, GstStructure *s)
{
int rate, channels;
if (!st || !s)
return;
gst_structure_get_int(s, "rate", &rate);
gst_structure_get_int(s, "channels", &channels);
if ((int)st->prm.srate != rate) {
warning("gst: expected %u Hz (got %u Hz)\n", st->prm.srate,
rate);
}
if (st->prm.ch != channels) {
warning("gst: expected %d channels (got %d)\n",
st->prm.ch, channels);
}
}
static void play_packet(struct ausrc_st *st)
{
struct auframe af;
auframe_init(&af, AUFMT_S16LE, st->buf, st->sampc, st->prm.srate,
st->prm.ch);
/* timed read from audio-buffer */
if (st->prm.ptime && aubuf_get_samp(st->aubuf, st->prm.ptime, st->buf,
st->sampc))
return;
/* immediate read from audio-buffer */
if (!st->prm.ptime)
aubuf_read_samp(st->aubuf, st->buf, st->sampc);
/* call read handler */
if (st->rh)
st->rh(&af, st->arg);
}
/* Expected format: 16-bit signed PCM */
static void packet_handler(struct ausrc_st *st, GstBuffer *buffer)
{
GstMapInfo info;
int err;
if (!st->run)
return;
/* NOTE: When streaming from files, the buffer will be filled up
* pretty quickly..
*/
if (!gst_buffer_map(buffer, &info, GST_MAP_READ)) {
warning("gst: gst_buffer_map failed\n");
return;
}
err = aubuf_write(st->aubuf, info.data, info.size);
if (err) {
warning("gst: aubuf_write: %m\n", err);
}
gst_buffer_unmap(buffer, &info);
/* Empty buffer now */
while (st->run) {
const struct timespec delay = {0, st->prm.ptime*1000000/2};
play_packet(st);
if (aubuf_cur_size(st->aubuf) < st->psize)
break;
(void)nanosleep(&delay, NULL);
}
}
static void handoff_handler(GstElement *sink, GstBuffer *buffer,
GstPad *pad, gpointer user_data)
{
struct ausrc_st *st = user_data;
GstCaps *caps;
(void)sink;
caps = gst_pad_get_current_caps(pad);
format_check(st, gst_caps_get_structure(caps, 0));
gst_caps_unref(caps);
packet_handler(st, buffer);
}
static void set_caps(struct ausrc_st *st)
{
GstCaps *caps;
/* Set the capabilities we want */
caps = gst_caps_new_simple("audio/x-raw",
"format", G_TYPE_STRING, "S16LE",
"rate", G_TYPE_INT, st->prm.srate,
"channels", G_TYPE_INT, st->prm.ch,
NULL);
g_object_set(G_OBJECT(st->capsfilt), "caps", caps, NULL);
gst_caps_unref(caps);
}
/**
* Set up the Gstreamer pipeline. The playbin element is used to decode
* all kinds of different formats. The capsfilter is used to deliver the
* audio in a fixed format (X Hz, 1-2 channels, 16 bit signed)
*
* The pipeline looks like this:
*
* <pre>
* .--------------. .------------------------------------------.
* | playbin | |mybin .------------. .------------. |
* |----. .----| |-----. | capsfilter | | fakesink | |
* |sink| |src |--->|ghost| |----. .---| |----. .---| | handoff
* |----' '----| |pad |-->|sink| |src|-->|sink| |src|--+--> handler
* | | |-----' '------------' '------------' |
* '--------------' '------------------------------------------'
* </pre>
*
* @param st Audio source state
*
* @return 0 if success, otherwise errorcode
*/
static int gst_setup(struct ausrc_st *st)
{
GstBus *bus;
GstPad *pad;
st->pipeline = gst_pipeline_new("pipeline");
if (!st->pipeline) {
warning("gst: failed to create pipeline element\n");
return ENOMEM;
}
/********************* Player BIN **************************/
st->source = gst_element_factory_make("playbin", "source");
if (!st->source) {
warning("gst: failed to create playbin source element\n");
return ENOMEM;
}
/********************* My BIN **************************/
st->bin = gst_bin_new("mybin");
st->capsfilt = gst_element_factory_make("capsfilter", NULL);
if (!st->capsfilt) {
warning("gst: failed to create capsfilter element\n");
return ENOMEM;
}
set_caps(st);
st->sink = gst_element_factory_make("fakesink", "sink");
if (!st->sink) {
warning("gst: failed to create sink element\n");
return ENOMEM;
}
g_object_set(st->sink, "async", false, NULL);
gst_bin_add_many(GST_BIN(st->bin), st->capsfilt, st->sink, NULL);
gst_element_link_many(st->capsfilt, st->sink, NULL);
/* add ghostpad */
pad = gst_element_get_static_pad(st->capsfilt, "sink");
gst_element_add_pad(st->bin, gst_ghost_pad_new("sink", pad));
gst_object_unref(GST_OBJECT(pad));
/* put all elements in a bin */
gst_bin_add_many(GST_BIN(st->pipeline), st->source, NULL);
/* Override audio-sink handoff handler */
g_signal_connect(st->sink, "handoff", G_CALLBACK(handoff_handler), st);
g_object_set(G_OBJECT(st->sink),
"signal-handoffs", TRUE,
"async", FALSE, NULL);
g_object_set(G_OBJECT(st->source), "audio-sink", st->bin, NULL);
/********************* Misc **************************/
/* Bus watch */
bus = gst_pipeline_get_bus(GST_PIPELINE(st->pipeline));
gst_bus_enable_sync_message_emission(bus);
gst_bus_set_sync_handler(
bus, (GstBusSyncHandler) sync_handler,
st, NULL);
gst_object_unref(bus);
/* Set URI */
g_object_set(G_OBJECT(st->source), "uri", st->uri, NULL);
return 0;
}
static int setup_uri(struct ausrc_st *st, const char *device)
{
int err = 0;
if (g_regex_match_simple(
uri_regex, device, 0, G_REGEX_MATCH_NOTEMPTY)) {
err = str_dup(&st->uri, device);
}
else {
if (!access(device, R_OK)) {
size_t urilength = strlen(device) + 8;
char *uri = mem_alloc(urilength, NULL);
if (re_snprintf(uri, urilength, "file://%s",
device) < 0)
return ENOMEM;
st->uri = uri;
}
else {
err = errno;
}
}
return err;
}
static void gst_destructor(void *arg)
{
struct ausrc_st *st = arg;
if (st->run) {
st->run = false;
}
tmr_cancel(&st->tmr);
gst_element_set_state(st->pipeline, GST_STATE_NULL);
gst_object_unref(GST_OBJECT(st->pipeline));
mem_deref(st->uri);
mem_deref(st->aubuf);
mem_deref(st->buf);
}
static void timeout(void *arg)
{
struct ausrc_st *st = arg;
tmr_start(&st->tmr, st->ptime ? st->ptime : 40, timeout, st);
/* check if source is still running */
if (!st->run) {
tmr_cancel(&st->tmr);
if (st->eos) {
debug("gst: end of file\n");
/* error handler must be called from re_main thread */
if (st->errh)
st->errh(0, "end of file", st->arg);
}
}
}
static int gst_alloc(struct ausrc_st **stp, const struct ausrc *as,
struct ausrc_prm *prm, const char *device,
ausrc_read_h *rh, ausrc_error_h *errh, void *arg)
{
struct ausrc_st *st;
int err;
if (!stp || !as || !prm)
return EINVAL;
if (!str_isset(device))
return EINVAL;
if (prm->fmt != AUFMT_S16LE) {
warning("gst: unsupported sample format (%s)\n",
aufmt_name(prm->fmt));
return ENOTSUP;
}
st = mem_zalloc(sizeof(*st), gst_destructor);
if (!st)
return ENOMEM;
st->rh = rh;
st->arg = arg;
err = setup_uri(st, device);
if (err) goto out;
st->ptime = prm->ptime;
if (!st->ptime)
st->ptime = 20;
if (!prm->srate)
prm->srate = 16000;
if (!prm->ch)
prm->ch = 1;
st->prm = *prm;
st->sampc = prm->srate * prm->ch * st->ptime / 1000;
st->psize = 2 * st->sampc;
st->buf = mem_zalloc(st->psize, NULL);
if (!st->buf) {
err = ENOMEM;
goto out;
}
err = aubuf_alloc(&st->aubuf, 0, 0);
if (err)
goto out;
err = gst_setup(st);
if (err)
goto out;
st->run = true;
st->eos = false;
gst_element_set_state(st->pipeline, GST_STATE_PLAYING);
if (!st->run) {
err = st->err;
goto out;
}
st->errh = errh;
tmr_start(&st->tmr, st->ptime, timeout, st);
out:
if (err)
mem_deref(st);
else
*stp = st;
return err;
}
static int mod_gst_init(void)
{
gchar *s;
gst_init(0, NULL);
s = gst_version_string();
info("gst: init: %s\n", s);
g_free(s);
return ausrc_register(&ausrc, baresip_ausrcl(), "gst", gst_alloc);
}
static int mod_gst_close(void)
{
gst_deinit();
ausrc = mem_deref(ausrc);
return 0;
}
EXPORT_SYM const struct mod_export DECL_EXPORTS(gst) = {
"gst",
"sound",
mod_gst_init,
mod_gst_close
};
|
542a1f525f7d6ed29961f34d6068f13641f0a4b6
|
fbe68d84e97262d6d26dd65c704a7b50af2b3943
|
/third_party/virtualbox/src/VBox/Devices/PC/ipxe/src/hci/keymap/keymap_no.c
|
45cf9e84774c6f528add2ce4172c13480872e870
|
[
"GPL-2.0-only",
"LicenseRef-scancode-unknown-license-reference",
"CDDL-1.0",
"LicenseRef-scancode-warranty-disclaimer",
"GPL-1.0-or-later",
"LGPL-2.1-or-later",
"GPL-2.0-or-later",
"MPL-1.0",
"LicenseRef-scancode-generic-exception",
"Apache-2.0",
"OpenSSL",
"MIT",
"LicenseRef-scancode-public-domain"
] |
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
| 3,416
|
c
|
keymap_no.c
|
/** @file
*
* "no" keyboard mapping
*
* This file is automatically generated; do not edit
*
*/
FILE_LICENCE ( PUBLIC_DOMAIN );
#include <ipxe/keymap.h>
/** "no" keyboard mapping */
struct key_mapping no_mapping[] __keymap = {
{ 0x02, 0x18 }, /* Ctrl-B => Ctrl-X */
{ 0x03, 0x0a }, /* Ctrl-C => Ctrl-J */
{ 0x04, 0x05 }, /* Ctrl-D => Ctrl-E */
{ 0x06, 0x15 }, /* Ctrl-F => Ctrl-U */
{ 0x07, 0x09 }, /* Ctrl-G => Ctrl-I */
{ 0x08, 0x04 }, /* Ctrl-H => Ctrl-D */
{ 0x0a, 0x08 }, /* Ctrl-J => Ctrl-H */
{ 0x0b, 0x14 }, /* Ctrl-K => Ctrl-T */
{ 0x0c, 0x0e }, /* Ctrl-L => Ctrl-N */
{ 0x0e, 0x02 }, /* Ctrl-N => Ctrl-B */
{ 0x0f, 0x12 }, /* Ctrl-O => Ctrl-R */
{ 0x10, 0x0c }, /* Ctrl-P => Ctrl-L */
{ 0x12, 0x10 }, /* Ctrl-R => Ctrl-P */
{ 0x13, 0x0f }, /* Ctrl-S => Ctrl-O */
{ 0x14, 0x19 }, /* Ctrl-T => Ctrl-Y */
{ 0x15, 0x07 }, /* Ctrl-U => Ctrl-G */
{ 0x16, 0x0b }, /* Ctrl-V => Ctrl-K */
{ 0x18, 0x11 }, /* Ctrl-X => Ctrl-Q */
{ 0x19, 0x06 }, /* Ctrl-Y => Ctrl-F */
{ 0x22, 0x5f }, /* '"' => '_' */
{ 0x26, 0x2f }, /* '&' => '/' */
{ 0x27, 0x2d }, /* '\'' => '-' */
{ 0x28, 0x29 }, /* '(' => ')' */
{ 0x29, 0x3d }, /* ')' => '=' */
{ 0x2a, 0x28 }, /* '*' => '(' */
{ 0x2b, 0x60 }, /* '+' => '`' */
{ 0x2c, 0x77 }, /* ',' => 'w' */
{ 0x2d, 0x2b }, /* '-' => '+' */
{ 0x2e, 0x76 }, /* '.' => 'v' */
{ 0x2f, 0x7a }, /* '/' => 'z' */
{ 0x3a, 0x53 }, /* ':' => 'S' */
{ 0x3b, 0x73 }, /* ';' => 's' */
{ 0x3c, 0x57 }, /* '<' => 'W' */
{ 0x3d, 0x5c }, /* '=' => '\\' */
{ 0x3e, 0x56 }, /* '>' => 'V' */
{ 0x3f, 0x5a }, /* '?' => 'Z' */
{ 0x40, 0x22 }, /* '@' => '"' */
{ 0x42, 0x58 }, /* 'B' => 'X' */
{ 0x43, 0x4a }, /* 'C' => 'J' */
{ 0x44, 0x45 }, /* 'D' => 'E' */
{ 0x45, 0x3a }, /* 'E' => ':' */
{ 0x46, 0x55 }, /* 'F' => 'U' */
{ 0x47, 0x49 }, /* 'G' => 'I' */
{ 0x48, 0x44 }, /* 'H' => 'D' */
{ 0x49, 0x43 }, /* 'I' => 'C' */
{ 0x4a, 0x48 }, /* 'J' => 'H' */
{ 0x4b, 0x54 }, /* 'K' => 'T' */
{ 0x4c, 0x4e }, /* 'L' => 'N' */
{ 0x4e, 0x42 }, /* 'N' => 'B' */
{ 0x4f, 0x52 }, /* 'O' => 'R' */
{ 0x50, 0x4c }, /* 'P' => 'L' */
{ 0x52, 0x50 }, /* 'R' => 'P' */
{ 0x53, 0x4f }, /* 'S' => 'O' */
{ 0x54, 0x59 }, /* 'T' => 'Y' */
{ 0x55, 0x47 }, /* 'U' => 'G' */
{ 0x56, 0x4b }, /* 'V' => 'K' */
{ 0x57, 0x3b }, /* 'W' => ';' */
{ 0x58, 0x51 }, /* 'X' => 'Q' */
{ 0x59, 0x46 }, /* 'Y' => 'F' */
{ 0x5b, 0x27 }, /* '[' => '\'' */
{ 0x5c, 0x3c }, /* '\\' => '<' */
{ 0x5d, 0x7e }, /* ']' => '~' */
{ 0x5e, 0x26 }, /* '^' => '&' */
{ 0x5f, 0x3f }, /* '_' => '?' */
{ 0x60, 0x7c }, /* '`' => '|' */
{ 0x62, 0x78 }, /* 'b' => 'x' */
{ 0x63, 0x6a }, /* 'c' => 'j' */
{ 0x64, 0x65 }, /* 'd' => 'e' */
{ 0x65, 0x2e }, /* 'e' => '.' */
{ 0x66, 0x75 }, /* 'f' => 'u' */
{ 0x67, 0x69 }, /* 'g' => 'i' */
{ 0x68, 0x64 }, /* 'h' => 'd' */
{ 0x69, 0x63 }, /* 'i' => 'c' */
{ 0x6a, 0x68 }, /* 'j' => 'h' */
{ 0x6b, 0x74 }, /* 'k' => 't' */
{ 0x6c, 0x6e }, /* 'l' => 'n' */
{ 0x6e, 0x62 }, /* 'n' => 'b' */
{ 0x6f, 0x72 }, /* 'o' => 'r' */
{ 0x70, 0x6c }, /* 'p' => 'l' */
{ 0x72, 0x70 }, /* 'r' => 'p' */
{ 0x73, 0x6f }, /* 's' => 'o' */
{ 0x74, 0x79 }, /* 't' => 'y' */
{ 0x75, 0x67 }, /* 'u' => 'g' */
{ 0x76, 0x6b }, /* 'v' => 'k' */
{ 0x77, 0x2c }, /* 'w' => ',' */
{ 0x78, 0x71 }, /* 'x' => 'q' */
{ 0x79, 0x66 }, /* 'y' => 'f' */
{ 0x7b, 0x2a }, /* '{' => '*' */
{ 0x7c, 0x3e }, /* '|' => '>' */
{ 0x7d, 0x5e }, /* '}' => '^' */
};
|
b04e593bd8cdb0ab278cc6db199675aae819f4e9
|
b732361d6b3405c3e79ac0a7d8361cf5b329b015
|
/ext/phalcon/encryption/crypt/padding/ansi.zep.c
|
d59f825ffa118d3c277142b4ef67a432ec10036e
|
[
"BSD-3-Clause"
] |
permissive
|
phalcon/cphalcon
|
4a5b26f47b5c2a4107541d7fd73c595c0d90ed73
|
fc183e11e8b96c43daf7d893244846206dc2aa73
|
refs/heads/master
| 2023-03-07T22:09:48.814291
| 2023-02-28T16:45:15
| 2023-02-28T16:45:15
| 2,854,337
| 8,135
| 2,343
|
BSD-3-Clause
| 2023-09-12T12:41:13
| 2011-11-26T05:52:50
|
PHP
|
UTF-8
|
C
| false
| true
| 4,459
|
c
|
ansi.zep.c
|
#ifdef HAVE_CONFIG_H
#include "../../../../ext_config.h"
#endif
#include <php.h>
#include "../../../../php_ext.h"
#include "../../../../ext.h"
#include <Zend/zend_operators.h>
#include <Zend/zend_exceptions.h>
#include <Zend/zend_interfaces.h>
#include "kernel/main.h"
#include "kernel/concat.h"
#include "kernel/memory.h"
#include "kernel/fcall.h"
#include "kernel/operators.h"
#include "kernel/object.h"
#include "kernel/string.h"
/**
* This file is part of the Phalcon Framework.
*
* (c) Phalcon Team <team@phalcon.io>
*
* For the full copyright and license information, please view the LICENSE.txt
* file that was distributed with this source code.
*/
/**
* Class Ansi
*
* @package Phalcon\Encryption\Crypt\Padding
*/
ZEPHIR_INIT_CLASS(Phalcon_Encryption_Crypt_Padding_Ansi)
{
ZEPHIR_REGISTER_CLASS(Phalcon\\Encryption\\Crypt\\Padding, Ansi, phalcon, encryption_crypt_padding_ansi, phalcon_encryption_crypt_padding_ansi_method_entry, 0);
zend_class_implements(phalcon_encryption_crypt_padding_ansi_ce, 1, phalcon_encryption_crypt_padding_padinterface_ce);
return SUCCESS;
}
/**
* @param int $paddingSize
*
* @return string
*/
PHP_METHOD(Phalcon_Encryption_Crypt_Padding_Ansi, pad)
{
zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL;
zval *paddingSize_param = NULL, _0, _1, _2, _3;
zend_long paddingSize, ZEPHIR_LAST_CALL_STATUS;
zval *this_ptr = getThis();
ZVAL_UNDEF(&_0);
ZVAL_UNDEF(&_1);
ZVAL_UNDEF(&_2);
ZVAL_UNDEF(&_3);
#if PHP_VERSION_ID >= 80000
bool is_null_true = 1;
ZEND_PARSE_PARAMETERS_START(1, 1)
Z_PARAM_LONG(paddingSize)
ZEND_PARSE_PARAMETERS_END();
#endif
ZEPHIR_MM_GROW();
zephir_fetch_params(1, 1, 0, &paddingSize_param);
paddingSize = zephir_get_intval(paddingSize_param);
ZVAL_LONG(&_0, 0);
ZEPHIR_CALL_FUNCTION(&_1, "chr", NULL, 242, &_0);
zephir_check_call_status();
ZVAL_LONG(&_0, (paddingSize - 1));
ZEPHIR_CALL_FUNCTION(&_2, "str_repeat", NULL, 1, &_1, &_0);
zephir_check_call_status();
ZVAL_LONG(&_0, paddingSize);
ZEPHIR_CALL_FUNCTION(&_3, "chr", NULL, 242, &_0);
zephir_check_call_status();
ZEPHIR_CONCAT_VV(return_value, &_2, &_3);
RETURN_MM();
}
/**
* @param string $input
* @param int $blockSize
*
* @return int
*/
PHP_METHOD(Phalcon_Encryption_Crypt_Padding_Ansi, unpad)
{
zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL;
zend_long blockSize, ZEPHIR_LAST_CALL_STATUS;
zval *input_param = NULL, *blockSize_param = NULL, last, length, ord, padding, paddingSize, repeat, _0, _1, _2$$4, _3$$4, _4$$3, _5$$3;
zval input;
zval *this_ptr = getThis();
ZVAL_UNDEF(&input);
ZVAL_UNDEF(&last);
ZVAL_UNDEF(&length);
ZVAL_UNDEF(&ord);
ZVAL_UNDEF(&padding);
ZVAL_UNDEF(&paddingSize);
ZVAL_UNDEF(&repeat);
ZVAL_UNDEF(&_0);
ZVAL_UNDEF(&_1);
ZVAL_UNDEF(&_2$$4);
ZVAL_UNDEF(&_3$$4);
ZVAL_UNDEF(&_4$$3);
ZVAL_UNDEF(&_5$$3);
#if PHP_VERSION_ID >= 80000
bool is_null_true = 1;
ZEND_PARSE_PARAMETERS_START(2, 2)
Z_PARAM_STR(input)
Z_PARAM_LONG(blockSize)
ZEND_PARSE_PARAMETERS_END();
#endif
ZEPHIR_MM_GROW();
zephir_fetch_params(1, 2, 0, &input_param, &blockSize_param);
zephir_get_strval(&input, input_param);
blockSize = zephir_get_intval(blockSize_param);
ZEPHIR_INIT_VAR(&paddingSize);
ZVAL_LONG(&paddingSize, 0);
ZEPHIR_INIT_VAR(&length);
ZVAL_LONG(&length, zephir_fast_strlen_ev(&input));
ZVAL_LONG(&_0, (zephir_get_numberval(&length) - 1));
ZVAL_LONG(&_1, 1);
ZEPHIR_INIT_VAR(&last);
zephir_substr(&last, &input, zephir_get_intval(&_0), 1 , 0);
ZEPHIR_CALL_FUNCTION(&ord, "ord", NULL, 243, &last);
zephir_check_call_status();
if (ZEPHIR_LE_LONG(&ord, blockSize)) {
ZEPHIR_CPY_WRT(&paddingSize, &ord);
ZEPHIR_INIT_VAR(&repeat);
ZVAL_STRING(&repeat, "");
if (ZEPHIR_GT_LONG(&paddingSize, 1)) {
ZVAL_LONG(&_2$$4, 0);
ZEPHIR_CALL_FUNCTION(&_3$$4, "chr", NULL, 242, &_2$$4);
zephir_check_call_status();
ZVAL_LONG(&_2$$4, (zephir_get_numberval(&paddingSize) - 1));
ZEPHIR_CALL_FUNCTION(&repeat, "str_repeat", NULL, 1, &_3$$4, &_2$$4);
zephir_check_call_status();
}
ZEPHIR_INIT_VAR(&padding);
ZEPHIR_CONCAT_VV(&padding, &repeat, &last);
ZEPHIR_INIT_VAR(&_4$$3);
zephir_sub_function(&_4$$3, &length, &paddingSize);
ZEPHIR_INIT_VAR(&_5$$3);
zephir_substr(&_5$$3, &input, zephir_get_intval(&_4$$3), 0, ZEPHIR_SUBSTR_NO_LENGTH);
if (!ZEPHIR_IS_IDENTICAL(&_5$$3, &padding)) {
ZEPHIR_INIT_NVAR(&paddingSize);
ZVAL_LONG(&paddingSize, 0);
}
}
RETURN_CCTOR(&paddingSize);
}
|
24e60169606dfa334849ee3d7460d7444041035d
|
6f286be4a4e16867cc6e488080b8e3eced1dcd62
|
/src/tools-TEST/CnvHunter_Test.h
|
0c14149825ecbac6de79f0fecc13bb2ed25d06c2
|
[
"MIT"
] |
permissive
|
imgag/ngs-bits
|
3587404be01687d52c5a77b933874ca77faf8e6b
|
0597c96f6bc09067598c2364877d11091350bed8
|
refs/heads/master
| 2023-09-03T20:20:16.975954
| 2023-09-01T13:17:35
| 2023-09-01T13:17:35
| 38,034,492
| 110
| 36
|
MIT
| 2023-09-12T14:21:59
| 2015-06-25T07:23:55
|
C++
|
UTF-8
|
C
| false
| false
| 1,767
|
h
|
CnvHunter_Test.h
|
#include "TestFramework.h"
#include "Settings.h"
#include "NGSD.h"
TEST_CLASS(CnvHunter_Test)
{
Q_OBJECT
private slots:
void hpPDv3_annotate_seg_debug()
{
QString ref_file = Settings::string("reference_genome", true);
if (ref_file=="") SKIP("Test needs the reference genome!");
QStringList in = Helper::findFiles(TESTDATA("data_in/CnvHunter1/"), "*.cov", false);
EXECUTE("CnvHunter", "-in " + in.join(" ") + " -out out/CnvHunter_out1.tsv -debug GS120224_01 -seg GS120551_01 -cnp_file " + TESTDATA("data_in/CnvHunter_cnp_file.bed") + " -annotate " + TESTDATA("data_in/CnvHunter_genes.bed"));
COMPARE_FILES("out/CnvHunter_out1.tsv", TESTDATA("data_out/CnvHunter_out1.tsv"));
COMPARE_FILES("out/CnvHunter_out1_regions.tsv", TESTDATA("data_out/CnvHunter_out1_regions.tsv"));
COMPARE_FILES("out/CnvHunter_out1_samples.tsv", TESTDATA("data_out/CnvHunter_out1_samples.tsv"));
COMPARE_FILES("out/CnvHunter_out1_debug.tsv", TESTDATA("data_out/CnvHunter_out1_debug.tsv"));
COMPARE_FILES("out/CnvHunter_out1.seg", TESTDATA("data_out/CnvHunter_out1.seg"));
}
void ssHAEv6_cnpfile()
{
QString ref_file = Settings::string("reference_genome", true);
if (ref_file=="") SKIP("Test needs the reference genome!");
QStringList in = Helper::findFiles(TESTDATA("data_in/CnvHunter2/"), "*.cov", false);
Helper::storeTextFile("out/CnvHunter_infiles2.tsv", in);
EXECUTE("CnvHunter", "-in out/CnvHunter_infiles2.tsv -out out/CnvHunter_out2.tsv -sam_min_corr 0.8 -reg_max_cv 0.5 -sam_corr_regs 250000 -cnp_file " + TESTDATA("data_in/CnvHunter_cnp_file.bed"));
COMPARE_FILES_DELTA("out/CnvHunter_out2.tsv", TESTDATA("data_out/CnvHunter_out2.tsv"), 1.0, true, '\t'); //delta because of rounding differences between Linux/Windows
}
};
|
035ddfdd954eb43c9575f9234f6429f7ac280ef7
|
7eaf54a78c9e2117247cb2ab6d3a0c20719ba700
|
/SOFTWARE/A64-TERES/linux-a64/drivers/char/sunxi-scr/smartcard.c
|
aa2f863f850a415a9216f1451877224238efbc08
|
[
"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
| 5,063
|
c
|
smartcard.c
|
//code for iso7816 smart card
#include <linux/module.h>
#include "smartcard.h"
#include "sunxi-scr-common.h"
extern u32 scr_debug_mask;
uint32_t smartcard_params_init(pscatr_struct pscatr)
{
pscatr->TS = 0x3B;
pscatr->TK_NUM = 0x00;
pscatr->T = 0; //T=0 Protocol
pscatr->FMAX = 4; //4MHz
pscatr->F = 372;
pscatr->D = 1;
pscatr->I = 50; //50mA
pscatr->P = 5; //5V
pscatr->N = 2;
return 0;
}
uint32_t smartcard_atr_decode(pscr_struct pscr, pscatr_struct pscatr, uint8_t* pdata, ppps_struct pps, uint32_t with_ts)
{
uint32_t index=0;
uint8_t temp;
uint32_t i;
dprintk(DEBUG_INIT, "%s: enter!!\n", __func__);
pps->ppss = 0xff; //PPSS
pps->pps0 = 0;
if(with_ts)
{
pscatr->TS = pdata[0]; //TS
index ++;
}
temp = pdata[index]; //T0
index ++;
pscatr->TK_NUM = temp & 0xf;
if(temp & 0x10) //TA1
{
smartcard_ta1_decode(pscatr, pdata[index]);
pps->pps0 |= 0x1<<4;
pps->pps1 = pdata[index];
index ++;
}
if(temp & 0x20) //TB1
{
smartcard_tb1_decode(pscatr, pdata[index]);
index++;
}
if(temp & 0x40) //TC1
{
pscatr->N = pdata[index] & 0xff;
index ++;
}
if(temp & 0x80) //TD1
{
dprintk(DEBUG_INIT, "%s: TD1 parse 0x%x !!\n", __func__, pdata[index]);
temp = pdata[index];
pscatr->T = temp & 0xf;
pps->pps0 |= temp & 0xf;
if(pscatr->T == 1)
scr_set_t_protocol(pscr, 1);
else
scr_set_t_protocol(pscr, 0);
if(pscatr->N == 0xff) //Adjust Guard Time
{
if(pscatr->T == 1)
pscatr->N = 1;
else
pscatr->N = 2;
}
index ++;
}
else
{
if(pscatr->N == 0xff) pscatr->N = 2;
goto rx_tk;
}
if(temp & 0x10) //TA2
{
dprintk(DEBUG_INIT, "TA2 Exist!!\n");
index ++;
}
if(temp & 0x20) //TB2
{
dprintk(DEBUG_INIT, "TB2 Exist!!\n");
index ++;
}
if(temp & 0x40) //TC2
{
dprintk(DEBUG_INIT, "TC2 Exist!!\n");
index ++;
}
if(temp & 0x80) //TD2
{
dprintk(DEBUG_INIT, "TD2 Exist!!\n");
temp = pdata[index];
index ++;
}
else
{
goto rx_tk;
}
if(temp & 0x10) //TA3
{
dprintk(DEBUG_INIT, "TA3 Exist!!\n");
index ++;
}
if(temp & 0x20) //TB3
{
dprintk(DEBUG_INIT, "TB3 Exist!!\n");
index ++;
}
if(temp & 0x40) //TC3
{
dprintk(DEBUG_INIT, "TC3 Exist!!\n");
index ++;
}
if(temp & 0x80) //TD3
{
dprintk(DEBUG_INIT, "TD3 Exist!!\n");
temp = pdata[index];
index ++;
}
else
{
goto rx_tk;
}
if(temp & 0x10) //TA4
{
dprintk(DEBUG_INIT, "TA4 Exist!!\n");
index ++;
}
if(temp & 0x20) //TB4
{
dprintk(DEBUG_INIT, "TB4 Exist!!\n");
index ++;
}
if(temp & 0x40) //TC4
{
dprintk(DEBUG_INIT, "TC4 Exist!!\n");
index ++;
}
if(temp & 0x80) //TD4
{
dprintk(DEBUG_INIT, "TD4 Exist!!\n");
temp = pdata[index];
index ++;
}
else
{
goto rx_tk;
}
rx_tk:
for(i=0; i<(pscatr->TK_NUM); i++)
{
pscatr->TK[i] = pdata[index++];
}
pps->pck = pps->ppss;
pps->pck ^= pps->pps0;
if(pps->pps0&(0x1<<4))
{
pps->pck ^= pps->pps1;
}
if(pps->pps0&(0x1<<5))
{
pps->pck ^= pps->pps2;
}
if(pps->pps0&(0x1<<6))
{
pps->pck ^= pps->pps3;
}
return 0;
}
void smartcard_ta1_decode(pscatr_struct pscatr, uint8_t ta1)
{
uint8_t temp = ta1;
dprintk(DEBUG_INIT, "%s: enter!!\n", __func__);
switch((temp>>4)&0xf)
{
case 0x0:
pscatr->FMAX = 4;
pscatr->F = 372;
break;
case 0x1:
pscatr->FMAX = 5;
pscatr->F = 372;
break;
case 0x2:
pscatr->FMAX = 6;
pscatr->F = 558;
break;
case 0x3:
pscatr->FMAX = 8;
pscatr->F = 744;
break;
case 0x4:
pscatr->FMAX = 12;
pscatr->F = 1116;
break;
case 0x5:
pscatr->FMAX = 16;
pscatr->F = 1488;
break;
case 0x6:
pscatr->FMAX = 20;
pscatr->F = 1860;
break;
case 0x9:
pscatr->FMAX = 5;
pscatr->F = 512;
break;
case 0xA:
pscatr->FMAX = 7;
pscatr->F = 768;
break;
case 0xB:
pscatr->FMAX = 10;
pscatr->F = 1024;
break;
case 0xC:
pscatr->FMAX = 15;
pscatr->F = 1536;
break;
case 0xD:
pscatr->FMAX = 20;
pscatr->F = 2048;
break;
default: //0x7/0x8/0xE/0xF
pscatr->FMAX = 4;
pscatr->F = 372;
dprintk(DEBUG_INIT, "Unsupport ta1 = 0x%x\n", ta1);
break;
}
switch(temp&0xf)
{
case 0x1:
pscatr->D = 1;
break;
case 0x2:
pscatr->D = 2;
break;
case 0x3:
pscatr->D = 4;
break;
case 0x4:
pscatr->D = 8;
break;
case 0x5:
pscatr->D = 16;
break;
case 0x6:
pscatr->D = 32;
break;
case 0x8:
pscatr->D = 12;
break;
case 0x9:
pscatr->D = 20;
break;
default: //0x0/0x7/0xA/0xB/0xC/0xD/0xE/0xF
pscatr->D = 1;
dprintk(DEBUG_INIT, "Unsupport ta1 = 0x%x\n", ta1);
break;
}
}
void smartcard_tb1_decode(pscatr_struct pscatr, uint8_t tb1)
{
uint8_t temp = tb1;
dprintk(DEBUG_INIT, "%s: enter!!\n", __func__);
switch((temp>>5)&0x3)
{
case 0:
pscatr->I = 25;
break;
case 1:
pscatr->I = 50;
break;
case 2:
pscatr->I = 100;
break;
default:
pscatr->I = 50;
}
if(((temp&0x1f)>4)&&((temp&0x1f)<26))
{
pscatr->P = (temp&0x1f); //5~25 in Volts
}
else if((temp&0x1f)==0)
{
pscatr->P = 0; //NC
}
else
{
pscatr->P = 5; //NC
}
}
|
6335ac4ec681f33b461b100179209b6ea1faa0f6
|
802341b5d8523d610ffd31f2e737aa915b9395f7
|
/memprof_arginfo.h
|
52acb0fe108474e3f745d862f00cc9b9317f1abe
|
[
"MIT"
] |
permissive
|
arnaud-lb/php-memory-profiler
|
45b517cc0807fd7b7b99234487f530dea799832c
|
9fa6eae94b7f9a84b029f8b24731035856c65067
|
refs/heads/v3
| 2023-08-30T08:34:13.437684
| 2022-06-01T12:40:52
| 2022-06-01T12:40:52
| 7,067,090
| 703
| 54
|
MIT
| 2023-09-02T11:53:12
| 2012-12-08T12:14:19
|
C
|
UTF-8
|
C
| false
| false
| 1,616
|
h
|
memprof_arginfo.h
|
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: afb43b76aec85442c7267aba0b45bfd00d5c8cf1 */
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_memprof_enabled, 0, 0, _IS_BOOL, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_memprof_enabled_flags, 0, 0, IS_ARRAY, 0)
ZEND_END_ARG_INFO()
#define arginfo_memprof_enable arginfo_memprof_enabled
#define arginfo_memprof_disable arginfo_memprof_enabled
#define arginfo_memprof_dump_array arginfo_memprof_enabled_flags
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_memprof_dump_callgrind, 0, 1, IS_VOID, 0)
ZEND_ARG_INFO(0, handle)
ZEND_END_ARG_INFO()
#define arginfo_memprof_dump_pprof arginfo_memprof_dump_callgrind
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_memprof_version, 0, 0, IS_STRING, 0)
ZEND_END_ARG_INFO()
ZEND_FUNCTION(memprof_enabled);
ZEND_FUNCTION(memprof_enabled_flags);
ZEND_FUNCTION(memprof_enable);
ZEND_FUNCTION(memprof_disable);
ZEND_FUNCTION(memprof_dump_array);
ZEND_FUNCTION(memprof_dump_callgrind);
ZEND_FUNCTION(memprof_dump_pprof);
ZEND_FUNCTION(memprof_version);
static const zend_function_entry ext_functions[] = {
ZEND_FE(memprof_enabled, arginfo_memprof_enabled)
ZEND_FE(memprof_enabled_flags, arginfo_memprof_enabled_flags)
ZEND_FE(memprof_enable, arginfo_memprof_enable)
ZEND_FE(memprof_disable, arginfo_memprof_disable)
ZEND_FE(memprof_dump_array, arginfo_memprof_dump_array)
ZEND_FE(memprof_dump_callgrind, arginfo_memprof_dump_callgrind)
ZEND_FE(memprof_dump_pprof, arginfo_memprof_dump_pprof)
ZEND_FE(memprof_version, arginfo_memprof_version)
ZEND_FE_END
};
|
afae38a1183953b32bc2187b8a1fdcc13bc47803
|
a10d78a4520a2a60b310103cb98070ec6041f1a2
|
/src/main.c
|
aadfbca4a82c10b32244fbc44ebe3f09c66a6b81
|
[] |
no_license
|
floooh/v6502r
|
c35e7f314752d6543b3d7c0f177cbd07e15932d6
|
3a89891882e84e596fdd1c2047795586379a8f34
|
refs/heads/master
| 2023-08-08T04:20:15.553151
| 2023-07-26T15:48:34
| 2023-07-26T15:48:34
| 218,528,298
| 214
| 28
| null | 2023-01-11T16:40:18
| 2019-10-30T12:59:57
|
C
|
UTF-8
|
C
| false
| false
| 5,235
|
c
|
main.c
|
//------------------------------------------------------------------------------
// v6502r.c
// Main source file.
//------------------------------------------------------------------------------
#include "sokol_app.h"
#include "sokol_args.h"
#include "sokol_log.h"
#include "util.h"
#include "gfx.h"
#include "input.h"
#include "ui.h"
#include "ui_asm.h"
#include "pick.h"
#include "trace.h"
#include "sim.h"
#include "segdefs.h"
const char* init_src =
#if defined(CHIP_6502)
"\tlda #0\n"
"loop:\tjsr func\n"
"\tjmp loop\n"
"func:\tinx\n"
"\tdey\n"
"\tinc data\n"
"\tsec\n"
"\tadc #2\n"
"\trts\n"
"data:\tdb $40\n\n";
#elif defined(CHIP_Z80)
"\tld sp,stack\n"
"loop:\tcall func\n"
"\tjr loop\n"
"func:\tld hl,data\n"
"\tinc (hl)\n"
"\tret\n"
"data:\tdb 40h\n"
"stack:\torg 30h\n";
#elif defined(CHIP_2A03)
"\tlda #0\n"
"loop:\tjsr func\n"
"\tjmp loop\n"
"func:\tinx\n"
"\tdey\n"
"\tinc data\n"
"\tsec\n"
"\tadc #2\n"
"\trts\n"
"data:\tdb $40\n\n";
#endif
static void app_init(void) {
util_init();
gfx_preinit();
ui_init();
gfx_init(&(gfx_desc_t){
.seg_vertices = {
[0] = SG_RANGE(seg_vertices_0),
[1] = SG_RANGE(seg_vertices_1),
#if !defined(CHIP_Z80)
[2] = SG_RANGE(seg_vertices_2),
#endif
[3] = SG_RANGE(seg_vertices_3),
[4] = SG_RANGE(seg_vertices_4),
[5] = SG_RANGE(seg_vertices_5),
},
.seg_min_x = seg_min_x,
.seg_min_y = seg_min_y,
.seg_max_x = seg_max_x,
.seg_max_y = seg_max_y,
});
input_init();
pick_init(&(pick_desc_t){
.seg_min_x = seg_min_x,
.seg_min_y = seg_min_y,
.seg_max_x = seg_max_x,
.seg_max_y = seg_max_y,
.layers = {
[0] = {
.verts = (const pick_vertex_t*) seg_vertices_0,
.num_verts = sizeof(seg_vertices_0) / 8,
},
[1] = {
.verts = (const pick_vertex_t*) seg_vertices_1,
.num_verts = sizeof(seg_vertices_1) / 8,
},
#if !defined(CHIP_Z80)
[2] = {
.verts = (const pick_vertex_t*) seg_vertices_2,
.num_verts = sizeof(seg_vertices_2) / 8,
},
#endif
[3] = {
.verts = (const pick_vertex_t*) seg_vertices_3,
.num_verts = sizeof(seg_vertices_3) / 8,
},
[4] = {
.verts = (const pick_vertex_t*) seg_vertices_4,
.num_verts = sizeof(seg_vertices_4) / 8,
},
[5] = {
.verts = (const pick_vertex_t*) seg_vertices_5,
.num_verts = sizeof(seg_vertices_5) / 8,
},
},
.mesh = {
.tris = (const pick_triangle_t*) pick_tris,
.num_tris = sizeof(pick_tris) / 8,
},
.grid = {
.num_cells_x = grid_cells,
.num_cells_y = grid_cells,
.cells = (const pick_cell_t*) pick_grid,
.num_cells = sizeof(pick_grid) / 8,
}
});
trace_init();
sim_init();
ui_asm_put_source("start", (range_t){ .ptr = (void*)init_src, strlen(init_src) });
ui_asm_assemble();
sim_start();
}
static void app_frame(void) {
gfx_new_frame(sapp_widthf(), sapp_heightf());
ui_frame();
sim_frame();
if (ui_is_nodeexplorer_active()) {
ui_write_nodeexplorer_visual_state(gfx_get_nodestate_buffer());
}
else if (ui_is_diffview()) {
const ui_diffview_t diffview = ui_get_diffview();
trace_write_diff_visual_state(diffview.cycle0, diffview.cycle1, gfx_get_nodestate_buffer());
}
else {
sim_write_node_visual_state(gfx_get_nodestate_buffer());
}
const pick_result_t pick_result = pick_dopick(
input_get_mouse_pos(),
gfx_get_display_size(),
gfx_get_offset(),
gfx_get_aspect(),
gfx_get_scale()
);
for (int i = 0; i < pick_result.num_hits; i++) {
if (!sim_is_ignore_picking_highlight_node(pick_result.node_index[i])) {
gfx_highlight_node(pick_result.node_index[i]);
}
}
gfx_begin();
gfx_draw();
ui_draw();
gfx_end();
}
static void app_input(const sapp_event* ev) {
input_handle_event(ev);
}
static void app_shutdown(void) {
pick_shutdown();
sim_shutdown();
trace_shutdown();
ui_shutdown();
input_shutdown();
gfx_shutdown();
util_shutdown();
}
sapp_desc sokol_main(int argc, char* argv[]) {
sargs_setup(&(sargs_desc){ .argc = argc, .argv = argv });
return (sapp_desc){
.init_cb = app_init,
.frame_cb = app_frame,
.event_cb = app_input,
.cleanup_cb = app_shutdown,
.width = 900,
.height = 700,
.window_title = WINDOW_TITLE,
.enable_clipboard = true,
.sample_count = 4,
.high_dpi = sargs_boolean("highdpi"),
.clipboard_size = 16*1024,
.icon = {
.sokol_default = true
},
.logger = {
.func = slog_func,
}
};
}
|
f5d4fe4b423d79417ce9a7782193c831ea9101ce
|
1f399edf85d995443d01f66d77eca0723886d0ff
|
/hypervisor/release/profiling.c
|
cc761e5f58e5df74f0ee36b9d013afc35c14de6a
|
[
"BSD-3-Clause"
] |
permissive
|
projectacrn/acrn-hypervisor
|
f9c5864d54929a5d2fa36b5e78c08f19b46b8f98
|
390740aa1b1e9d62c51f8e3afa0c29e07e43fa23
|
refs/heads/master
| 2023-08-18T05:07:01.310327
| 2023-08-11T07:49:36
| 2023-08-16T13:20:27
| 123,983,554
| 1,059
| 686
|
BSD-3-Clause
| 2023-09-14T09:51:10
| 2018-03-05T21:52:25
|
C
|
UTF-8
|
C
| false
| false
| 384
|
c
|
profiling.c
|
/*
* Copyright (C) 2018-2022 Intel Corporation.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <types.h>
#include <asm/guest/vcpu.h>
void profiling_vmenter_handler(__unused struct acrn_vcpu *vcpu) {}
void profiling_pre_vmexit_handler(__unused struct acrn_vcpu *vcpu) {}
void profiling_post_vmexit_handler(__unused struct acrn_vcpu *vcpu) {}
void profiling_setup(void) {}
|
51b999ebde85a8af4d2645833b464ccd49afb0f7
|
9de0cec678bc4a3bec2b4adabef9f39ff5b4afac
|
/PWGCF/EBYE/PIDFluctuation/macros/AddAliEbyENetChargeFluctuationBinTask.C
|
14d9cc1f16ad75f74a5b3ce2dcec01bf33985239
|
[] |
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
| 5,281
|
c
|
AddAliEbyENetChargeFluctuationBinTask.C
|
//=========================================================================//
// //
// Analysis AddTask for Particle Ratio Fluctuation Study //
// Author: Deepika Rathee || Satyajit Jenara //
// drathee@cern.ch || sjena@cern.ch //
// Thu Dec 19 09:09:38 CET 2013
// //
//=========================================================================//
void AddAliEbyENetChargeFluctuationBinTask(const Char_t *taskname="TOFTPC",
const Char_t *centralityEstimator = "V0M",
Bool_t isModeAOD = 1,
Int_t aodFilterBit = 768,
Int_t sysType = 0, // 0-pp,1-pA,2-AA, 3,4,5 mc
Int_t cuttype = 9, // esd cut type
Int_t pidtype = 2,
Int_t requestTofPid = 1,
Double_t nSigmaCut = 3.,
Double_t lptfortof = 0.5,
Double_t ptl = 0.5,
Double_t pth = 5.0,
Double_t gEta = 0.8,
Double_t gRap = 0.5,
Double_t dcaxy = 2.4,
Double_t dcaz = 3.2,
Double_t vz = 10.,
Int_t nSample = 25,
Int_t analType = 1,
Int_t isBasic = 0) {
Double_t vx = 3.; Double_t vy = 3.;
AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
if (!mgr) {
::Error("AddTaskFluctuations", "No analysis manager to connect to.");
return NULL;
}
if (!mgr->GetInputEventHandler()) {
::Error("AddTaskFluctuations", "This task requires an input event handler");
return NULL;
}
Bool_t isMC = (mgr->GetMCtruthEventHandler() != NULL);
if (isMC)
Info("AddTaskNetParticle", "This task has MC.");
AliHelperPID* help = new AliHelperPID();
help->SetNameTitle(taskname,taskname);
help->Print();
help->SetNSigmaCut(nSigmaCut);
help->SetPIDType(pidtype); // kNSigmaTPC,kNSigmaTOF, kNSigmaTPCTOF
if (requestTofPid) {
help->SetfRequestTOFPID(requestTofPid);
if (ptl != 0 ) help->SetfPtTOFPID(lptfortof);
}
if (sysType > 2) help->SetisMC(1); else help->SetisMC(0);
if (pidtype == 3){
AliPIDCombined *pidc=new AliPIDCombined();
pidc->SetDefaultTPCPriors();
help->SetPIDCombined(pidc);
}
AliEbyENetChargeFluctuationTask *task[8];
AliAnalysisDataContainer *cout1[8];
AliAnalysisDataContainer *cout2[8];
AliAnalysisDataContainer *cout3[8];
AliAnalysisDataContainer *cout4[8];
gROOT->LoadMacro("$ALICE_PHYSICS/PWGCF/EBYE/PIDFluctuation/macros/configureNetChargeTrackCut.C");
AliESDtrackCuts *cuts[8];
for (Int_t iEta = 0; iEta < 8; iEta++ ) {
TString taskname_ctr = Form("%s_E%d",taskname,iEta);
Double_t eEta = 0.1 + iEta * 0.1;
task[iEta] = new AliEbyENetChargeFluctuationTask(Form("%s_%s",taskname,taskname_ctr.Data()));
if (!task[iEta]) {
Error("EbyEPidRatio", "Task could not be created.");
return NULL;
}
Printf("=========== Run For the Eta Window %s ==========",taskname_ctr.Data());
if (isMC) task[iEta]->SetIsMC();
Int_t sysii = sysType;
if (sysType > 2) {task[iEta]->SetIsMC(); sysii = sysType - 3;}
if (isModeAOD) {
task[iEta]->SetIsAOD();
task[iEta]->SetTrackFilterBit(aodFilterBit);
}
task[iEta]->SetSystemType(sysii);
task[iEta]->SetEventSelectionBit(AliVEvent::kMB);
task[iEta]->SetCentralityEstimator(centralityEstimator);
task[iEta]->SetVertexDiamond(vx,vy,vz);
task[iEta]->SetKinematicsCuts(ptl,pth,eEta,gRap);
task[iEta]->SetNSubSamples(nSample);
task[iEta]->SetDca(dcaxy,dcaz);
if (iEta == 7) task[iEta]->DoBasicQA();
if (!isModeAOD) {
cuts[iEta] = configureNetChargeTrackCut(taskname_ctr.Data(),cuttype,10001006, eEta, 5.,5.);
task[iEta]->SetAnalysisCutObject(cuts[iEta]);
Printf("=========== Cut Applied %s ==========",taskname_ctr.Data());
}
task[iEta]->SetHelperPID(help);
task[iEta]->SetAnal(analType,isBasic);
mgr->AddTask(task[iEta]);
TString commonname = Form("%s:%s_E%d", AliAnalysisManager::GetCommonFileName(),taskname, iEta);
cout1[iEta] = mgr->CreateContainer(Form("%s_phy",taskname_ctr.Data()), TList::Class(),
AliAnalysisManager::kOutputContainer, commonname);
cout2[iEta] = mgr->CreateContainer(Form("%s_qa",taskname_ctr.Data()), TList::Class(),
AliAnalysisManager::kOutputContainer, commonname);
cout3[iEta] = mgr->CreateContainer(Form("%s_dca",taskname_ctr.Data()), TList::Class(),
AliAnalysisManager::kOutputContainer, commonname);
cout4[iEta] = mgr->CreateContainer(Form("%s_eff",taskname_ctr.Data()), TList::Class(),
AliAnalysisManager::kOutputContainer, commonname);
mgr->ConnectInput(task[iEta], 0, mgr->GetCommonInputContainer());
mgr->ConnectOutput(task[iEta], 1, cout1[iEta]);
mgr->ConnectOutput(task[iEta], 2, cout2[iEta]);
mgr->ConnectOutput(task[iEta], 3, cout3[iEta]);
mgr->ConnectOutput(task[iEta], 4, cout4[iEta]);
}
return;
}
|
72424f3b1196469ed6e99910a7ac5ea2401be4b9
|
e47e2263ca0b60d0c8327f74b4d4078deadea430
|
/tess-two/jni/com_googlecode_leptonica_android/src/src/pixafunc1.c
|
885b6ae27a36225cc000fdca470beaeb4fc8903d
|
[
"BSD-2-Clause",
"CC-BY-2.5",
"Apache-2.0"
] |
permissive
|
rmtheis/tess-two
|
43ed1bdcceee88df696efdee7c3965572ff2121f
|
ab4cab1bd9794aacb74162aff339daa921a68c3f
|
refs/heads/master
| 2023-03-10T08:27:42.539055
| 2022-03-17T11:21:24
| 2022-03-17T11:21:24
| 2,581,357
| 3,632
| 1,331
|
Apache-2.0
| 2019-10-20T00:51:50
| 2011-10-15T11:14:00
|
C
|
UTF-8
|
C
| false
| false
| 80,437
|
c
|
pixafunc1.c
|
/*====================================================================*
- Copyright (C) 2001 Leptonica. 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.
-
- 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 ANY
- CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*====================================================================*/
/*!
* \file pixafunc1.c
* <pre>
*
* Filters
* PIX *pixSelectBySize()
* PIXA *pixaSelectBySize()
* NUMA *pixaMakeSizeIndicator()
*
* PIX *pixSelectByPerimToAreaRatio()
* PIXA *pixaSelectByPerimToAreaRatio()
* PIX *pixSelectByPerimSizeRatio()
* PIXA *pixaSelectByPerimSizeRatio()
* PIX *pixSelectByAreaFraction()
* PIXA *pixaSelectByAreaFraction()
* PIX *pixSelectByWidthHeightRatio()
* PIXA *pixaSelectByWidthHeightRatio()
*
* PIXA *pixaSelectWithIndicator()
* l_int32 pixRemoveWithIndicator()
* l_int32 pixAddWithIndicator()
* PIXA *pixaSelectWithString()
* PIX *pixaRenderComponent()
*
* Sort functions
* PIXA *pixaSort()
* PIXA *pixaBinSort()
* PIXA *pixaSortByIndex()
* PIXAA *pixaSort2dByIndex()
*
* Pixa and Pixaa range selection
* PIXA *pixaSelectRange()
* PIXAA *pixaaSelectRange()
*
* Pixa and Pixaa scaling
* PIXAA *pixaaScaleToSize()
* PIXAA *pixaaScaleToSizeVar()
* PIXA *pixaScaleToSize()
* PIXA *pixaScaleToSizeRel()
* PIXA *pixaScale()
*
* Miscellaneous
* PIXA *pixaAddBorderGeneral()
* PIXA *pixaaFlattenToPixa()
* l_int32 pixaaSizeRange()
* l_int32 pixaSizeRange()
* PIXA *pixaClipToPix()
* l_int32 pixaGetRenderingDepth()
* l_int32 pixaHasColor()
* l_int32 pixaAnyColormaps()
* l_int32 pixaGetDepthInfo()
* PIXA *pixaConvertToSameDepth()
* l_int32 pixaEqual()
* PIXA *pixaRotateOrth()
* </pre>
*/
#include <string.h>
#include "allheaders.h"
/* For more than this number of c.c. in a binarized image of
* semi-perimeter (w + h) about 5000 or less, the O(n) binsort
* is faster than the O(nlogn) shellsort. */
static const l_int32 MIN_COMPS_FOR_BIN_SORT = 200;
/*---------------------------------------------------------------------*
* Filters *
*---------------------------------------------------------------------*/
/*
* These filters work on the connected components of 1 bpp images.
* They are typically used on pixa that have been generated from a Pix
* using pixConnComp(), so that the corresponding Boxa is available.
*
* The filters remove or retain c.c. based on these properties:
* (a) size [pixaFindDimensions()]
* (b) area-to-perimeter ratio [pixaFindAreaPerimRatio()]
* (c) foreground area as a fraction of bounding box area (w * h)
* [pixaFindForegroundArea()]
* (d) number of foreground pixels [pixaCountPixels()]
* (e) width/height aspect ratio [pixFindWidthHeightRatio()]
*
* We provide two different high-level interfaces:
* (1) Functions that use one of the filters on either
* a pix or the pixa of components.
* (2) A general method that generates numas of indicator functions,
* logically combines them, and efficiently removes or adds
* the selected components.
*
* For interface (1), the filtering is performed with a single function call.
* This is the easiest way to do simple filtering. These functions
* are named pixSelectBy*() and pixaSelectBy*(), where the '*' is one of:
* Size
* PerimToAreaRatio
* PerimSizeRatio
* AreaFraction
* WidthHeightRatio
*
* For more complicated filtering, use the general method (2).
* The numa indicator functions for a pixa are generated by these functions:
* pixaFindDimensions()
* pixaFindPerimToAreaRatio()
* pixaFindPerimSizeRatio()
* pixaFindAreaFraction()
* pixaCountPixels()
* pixaFindWidthHeightRatio()
* pixaFindWidthHeightProduct()
*
* Here is an illustration using the general method. Suppose you want
* all 8-connected components that have a height greater than 40 pixels,
* a width not more than 30 pixels, between 150 and 300 fg pixels,
* and a perimeter-to-size ratio between 1.2 and 2.0.
*
* // Generate the pixa of 8 cc pieces.
* boxa = pixConnComp(pixs, &pixa, 8);
*
* // Extract the data we need about each component.
* pixaFindDimensions(pixa, &naw, &nah);
* nas = pixaCountPixels(pixa);
* nar = pixaFindPerimSizeRatio(pixa);
*
* // Build the indicator arrays for the set of components,
* // based on thresholds and selection criteria.
* na1 = numaMakeThresholdIndicator(nah, 40, L_SELECT_IF_GT);
* na2 = numaMakeThresholdIndicator(naw, 30, L_SELECT_IF_LTE);
* na3 = numaMakeThresholdIndicator(nas, 150, L_SELECT_IF_GTE);
* na4 = numaMakeThresholdIndicator(nas, 300, L_SELECT_IF_LTE);
* na5 = numaMakeThresholdIndicator(nar, 1.2, L_SELECT_IF_GTE);
* na6 = numaMakeThresholdIndicator(nar, 2.0, L_SELECT_IF_LTE);
*
* // Combine the indicator arrays logically to find
* // the components that will be retained.
* nad = numaLogicalOp(NULL, na1, na2, L_INTERSECTION);
* numaLogicalOp(nad, nad, na3, L_INTERSECTION);
* numaLogicalOp(nad, nad, na4, L_INTERSECTION);
* numaLogicalOp(nad, nad, na5, L_INTERSECTION);
* numaLogicalOp(nad, nad, na6, L_INTERSECTION);
*
* // Invert to get the components that will be removed.
* numaInvert(nad, nad);
*
* // Remove the components, in-place.
* pixRemoveWithIndicator(pixs, pixa, nad);
*/
/*!
* \brief pixSelectBySize()
*
* \param[in] pixs 1 bpp
* \param[in] width, height threshold dimensions
* \param[in] connectivity 4 or 8
* \param[in] type L_SELECT_WIDTH, L_SELECT_HEIGHT,
* L_SELECT_IF_EITHER, L_SELECT_IF_BOTH
* \param[in] relation L_SELECT_IF_LT, L_SELECT_IF_GT,
* L_SELECT_IF_LTE, L_SELECT_IF_GTE
* \param[out] pchanged [optional] 1 if changed; 0 otherwise
* \return filtered pixd, or NULL on error
*
* <pre>
* Notes:
* (1) The args specify constraints on the size of the
* components that are kept.
* (2) If unchanged, returns a copy of pixs. Otherwise,
* returns a new pix with the filtered components.
* (3) If the selection type is L_SELECT_WIDTH, the input
* height is ignored, and v.v.
* (4) To keep small components, use relation = L_SELECT_IF_LT or
* L_SELECT_IF_LTE.
* To keep large components, use relation = L_SELECT_IF_GT or
* L_SELECT_IF_GTE.
* </pre>
*/
PIX *
pixSelectBySize(PIX *pixs,
l_int32 width,
l_int32 height,
l_int32 connectivity,
l_int32 type,
l_int32 relation,
l_int32 *pchanged)
{
l_int32 w, h, empty, changed, count;
BOXA *boxa;
PIX *pixd;
PIXA *pixas, *pixad;
PROCNAME("pixSelectBySize");
if (!pixs)
return (PIX *)ERROR_PTR("pixs not defined", procName, NULL);
if (connectivity != 4 && connectivity != 8)
return (PIX *)ERROR_PTR("connectivity not 4 or 8", procName, NULL);
if (type != L_SELECT_WIDTH && type != L_SELECT_HEIGHT &&
type != L_SELECT_IF_EITHER && type != L_SELECT_IF_BOTH)
return (PIX *)ERROR_PTR("invalid type", procName, NULL);
if (relation != L_SELECT_IF_LT && relation != L_SELECT_IF_GT &&
relation != L_SELECT_IF_LTE && relation != L_SELECT_IF_GTE)
return (PIX *)ERROR_PTR("invalid relation", procName, NULL);
if (pchanged) *pchanged = FALSE;
/* Check if any components exist */
pixZero(pixs, &empty);
if (empty)
return pixCopy(NULL, pixs);
/* Identify and select the components */
boxa = pixConnComp(pixs, &pixas, connectivity);
pixad = pixaSelectBySize(pixas, width, height, type, relation, &changed);
boxaDestroy(&boxa);
pixaDestroy(&pixas);
if (!changed) {
pixaDestroy(&pixad);
return pixCopy(NULL, pixs);
}
/* Render the result */
if (pchanged) *pchanged = TRUE;
pixGetDimensions(pixs, &w, &h, NULL);
count = pixaGetCount(pixad);
if (count == 0) { /* return empty pix */
pixd = pixCreateTemplate(pixs);
} else {
pixd = pixaDisplay(pixad, w, h);
pixCopyResolution(pixd, pixs);
pixCopyColormap(pixd, pixs);
pixCopyText(pixd, pixs);
pixCopyInputFormat(pixd, pixs);
}
pixaDestroy(&pixad);
return pixd;
}
/*!
* \brief pixaSelectBySize()
*
* \param[in] pixas
* \param[in] width, height threshold dimensions
* \param[in] type L_SELECT_WIDTH, L_SELECT_HEIGHT,
* L_SELECT_IF_EITHER, L_SELECT_IF_BOTH
* \param[in] relation L_SELECT_IF_LT, L_SELECT_IF_GT,
* L_SELECT_IF_LTE, L_SELECT_IF_GTE
* \param[out] pchanged [optional] 1 if changed; 0 otherwise
* \return pixad, or NULL on error
*
* <pre>
* Notes:
* (1) The args specify constraints on the size of the
* components that are kept.
* (2) Uses pix and box clones in the new pixa.
* (3) If the selection type is L_SELECT_WIDTH, the input
* height is ignored, and v.v.
* (4) To keep small components, use relation = L_SELECT_IF_LT or
* L_SELECT_IF_LTE.
* To keep large components, use relation = L_SELECT_IF_GT or
* L_SELECT_IF_GTE.
* </pre>
*/
PIXA *
pixaSelectBySize(PIXA *pixas,
l_int32 width,
l_int32 height,
l_int32 type,
l_int32 relation,
l_int32 *pchanged)
{
NUMA *na;
PIXA *pixad;
PROCNAME("pixaSelectBySize");
if (!pixas)
return (PIXA *)ERROR_PTR("pixas not defined", procName, NULL);
if (type != L_SELECT_WIDTH && type != L_SELECT_HEIGHT &&
type != L_SELECT_IF_EITHER && type != L_SELECT_IF_BOTH)
return (PIXA *)ERROR_PTR("invalid type", procName, NULL);
if (relation != L_SELECT_IF_LT && relation != L_SELECT_IF_GT &&
relation != L_SELECT_IF_LTE && relation != L_SELECT_IF_GTE)
return (PIXA *)ERROR_PTR("invalid relation", procName, NULL);
/* Compute the indicator array for saving components */
na = pixaMakeSizeIndicator(pixas, width, height, type, relation);
/* Filter to get output */
pixad = pixaSelectWithIndicator(pixas, na, pchanged);
numaDestroy(&na);
return pixad;
}
/*!
* \brief pixaMakeSizeIndicator()
*
* \param[in] pixa
* \param[in] width, height threshold dimensions
* \param[in] type L_SELECT_WIDTH, L_SELECT_HEIGHT,
* L_SELECT_IF_EITHER, L_SELECT_IF_BOTH
* \param[in] relation L_SELECT_IF_LT, L_SELECT_IF_GT,
* L_SELECT_IF_LTE, L_SELECT_IF_GTE
* \return na indicator array, or NULL on error
*
* <pre>
* Notes:
* (1) The args specify constraints on the size of the
* components that are kept.
* (2) If the selection type is L_SELECT_WIDTH, the input
* height is ignored, and v.v.
* (3) To keep small components, use relation = L_SELECT_IF_LT or
* L_SELECT_IF_LTE.
* To keep large components, use relation = L_SELECT_IF_GT or
* L_SELECT_IF_GTE.
* </pre>
*/
NUMA *
pixaMakeSizeIndicator(PIXA *pixa,
l_int32 width,
l_int32 height,
l_int32 type,
l_int32 relation)
{
l_int32 i, n, w, h, ival;
NUMA *na;
PROCNAME("pixaMakeSizeIndicator");
if (!pixa)
return (NUMA *)ERROR_PTR("pixa not defined", procName, NULL);
if (type != L_SELECT_WIDTH && type != L_SELECT_HEIGHT &&
type != L_SELECT_IF_EITHER && type != L_SELECT_IF_BOTH)
return (NUMA *)ERROR_PTR("invalid type", procName, NULL);
if (relation != L_SELECT_IF_LT && relation != L_SELECT_IF_GT &&
relation != L_SELECT_IF_LTE && relation != L_SELECT_IF_GTE)
return (NUMA *)ERROR_PTR("invalid relation", procName, NULL);
n = pixaGetCount(pixa);
na = numaCreate(n);
for (i = 0; i < n; i++) {
ival = 0;
pixaGetPixDimensions(pixa, i, &w, &h, NULL);
switch (type)
{
case L_SELECT_WIDTH:
if ((relation == L_SELECT_IF_LT && w < width) ||
(relation == L_SELECT_IF_GT && w > width) ||
(relation == L_SELECT_IF_LTE && w <= width) ||
(relation == L_SELECT_IF_GTE && w >= width))
ival = 1;
break;
case L_SELECT_HEIGHT:
if ((relation == L_SELECT_IF_LT && h < height) ||
(relation == L_SELECT_IF_GT && h > height) ||
(relation == L_SELECT_IF_LTE && h <= height) ||
(relation == L_SELECT_IF_GTE && h >= height))
ival = 1;
break;
case L_SELECT_IF_EITHER:
if (((relation == L_SELECT_IF_LT) && (w < width || h < height)) ||
((relation == L_SELECT_IF_GT) && (w > width || h > height)) ||
((relation == L_SELECT_IF_LTE) && (w <= width || h <= height)) ||
((relation == L_SELECT_IF_GTE) && (w >= width || h >= height)))
ival = 1;
break;
case L_SELECT_IF_BOTH:
if (((relation == L_SELECT_IF_LT) && (w < width && h < height)) ||
((relation == L_SELECT_IF_GT) && (w > width && h > height)) ||
((relation == L_SELECT_IF_LTE) && (w <= width && h <= height)) ||
((relation == L_SELECT_IF_GTE) && (w >= width && h >= height)))
ival = 1;
break;
default:
L_WARNING("can't get here!\n", procName);
break;
}
numaAddNumber(na, ival);
}
return na;
}
/*!
* \brief pixSelectByPerimToAreaRatio()
*
* \param[in] pixs 1 bpp
* \param[in] thresh threshold ratio of fg boundary to fg pixels
* \param[in] connectivity 4 or 8
* \param[in] type L_SELECT_IF_LT, L_SELECT_IF_GT,
* L_SELECT_IF_LTE, L_SELECT_IF_GTE
* \param[out] pchanged [optional] 1 if changed; 0 if clone returned
* \return pixd, or NULL on error
*
* <pre>
* Notes:
* (1) The args specify constraints on the size of the
* components that are kept.
* (2) If unchanged, returns a copy of pixs. Otherwise,
* returns a new pix with the filtered components.
* (3) This filters "thick" components, where a thick component
* is defined to have a ratio of boundary to interior pixels
* that is smaller than a given threshold value.
* (4) Use L_SELECT_IF_LT or L_SELECT_IF_LTE to save the thicker
* components, and L_SELECT_IF_GT or L_SELECT_IF_GTE to remove them.
* </pre>
*/
PIX *
pixSelectByPerimToAreaRatio(PIX *pixs,
l_float32 thresh,
l_int32 connectivity,
l_int32 type,
l_int32 *pchanged)
{
l_int32 w, h, empty, changed, count;
BOXA *boxa;
PIX *pixd;
PIXA *pixas, *pixad;
PROCNAME("pixSelectByPerimToAreaRatio");
if (!pixs)
return (PIX *)ERROR_PTR("pixs not defined", procName, NULL);
if (connectivity != 4 && connectivity != 8)
return (PIX *)ERROR_PTR("connectivity not 4 or 8", procName, NULL);
if (type != L_SELECT_IF_LT && type != L_SELECT_IF_GT &&
type != L_SELECT_IF_LTE && type != L_SELECT_IF_GTE)
return (PIX *)ERROR_PTR("invalid type", procName, NULL);
if (pchanged) *pchanged = FALSE;
/* Check if any components exist */
pixZero(pixs, &empty);
if (empty)
return pixCopy(NULL, pixs);
/* Filter thin components */
boxa = pixConnComp(pixs, &pixas, connectivity);
pixad = pixaSelectByPerimToAreaRatio(pixas, thresh, type, &changed);
boxaDestroy(&boxa);
pixaDestroy(&pixas);
if (!changed) {
pixaDestroy(&pixad);
return pixCopy(NULL, pixs);
}
/* Render the result */
if (pchanged) *pchanged = TRUE;
pixGetDimensions(pixs, &w, &h, NULL);
count = pixaGetCount(pixad);
if (count == 0) { /* return empty pix */
pixd = pixCreateTemplate(pixs);
} else {
pixd = pixaDisplay(pixad, w, h);
pixCopyResolution(pixd, pixs);
pixCopyColormap(pixd, pixs);
pixCopyText(pixd, pixs);
pixCopyInputFormat(pixd, pixs);
}
pixaDestroy(&pixad);
return pixd;
}
/*!
* \brief pixaSelectByPerimToAreaRatio()
*
* \param[in] pixas
* \param[in] thresh threshold ratio of fg boundary to fg pixels
* \param[in] type L_SELECT_IF_LT, L_SELECT_IF_GT,
* L_SELECT_IF_LTE, L_SELECT_IF_GTE
* \param[out] pchanged [optional] 1 if changed; 0 if clone returned
* \return pixad, or NULL on error
*
* <pre>
* Notes:
* (1) Returns a pixa clone if no components are removed.
* (2) Uses pix and box clones in the new pixa.
* (3) See pixSelectByPerimToAreaRatio().
* </pre>
*/
PIXA *
pixaSelectByPerimToAreaRatio(PIXA *pixas,
l_float32 thresh,
l_int32 type,
l_int32 *pchanged)
{
NUMA *na, *nai;
PIXA *pixad;
PROCNAME("pixaSelectByPerimToAreaRatio");
if (!pixas)
return (PIXA *)ERROR_PTR("pixas not defined", procName, NULL);
if (type != L_SELECT_IF_LT && type != L_SELECT_IF_GT &&
type != L_SELECT_IF_LTE && type != L_SELECT_IF_GTE)
return (PIXA *)ERROR_PTR("invalid type", procName, NULL);
/* Compute component ratios. */
na = pixaFindPerimToAreaRatio(pixas);
/* Generate indicator array for elements to be saved. */
nai = numaMakeThresholdIndicator(na, thresh, type);
numaDestroy(&na);
/* Filter to get output */
pixad = pixaSelectWithIndicator(pixas, nai, pchanged);
numaDestroy(&nai);
return pixad;
}
/*!
* \brief pixSelectByPerimSizeRatio()
*
* \param[in] pixs 1 bpp
* \param[in] thresh threshold ratio of fg boundary to fg pixels
* \param[in] connectivity 4 or 8
* \param[in] type L_SELECT_IF_LT, L_SELECT_IF_GT,
* L_SELECT_IF_LTE, L_SELECT_IF_GTE
* \param[out] pchanged [optional] 1 if changed; 0 if clone returned
* \return pixd, or NULL on error
*
* <pre>
* Notes:
* (1) The args specify constraints on the size of the
* components that are kept.
* (2) If unchanged, returns a copy of pixs. Otherwise,
* returns a new pix with the filtered components.
* (3) This filters components with smooth vs. dendritic shape, using
* the ratio of the fg boundary pixels to the circumference of
* the bounding box, and comparing it to a threshold value.
* (4) Use L_SELECT_IF_LT or L_SELECT_IF_LTE to save the smooth
* boundary components, and L_SELECT_IF_GT or L_SELECT_IF_GTE
* to remove them.
* </pre>
*/
PIX *
pixSelectByPerimSizeRatio(PIX *pixs,
l_float32 thresh,
l_int32 connectivity,
l_int32 type,
l_int32 *pchanged)
{
l_int32 w, h, empty, changed, count;
BOXA *boxa;
PIX *pixd;
PIXA *pixas, *pixad;
PROCNAME("pixSelectByPerimSizeRatio");
if (!pixs)
return (PIX *)ERROR_PTR("pixs not defined", procName, NULL);
if (connectivity != 4 && connectivity != 8)
return (PIX *)ERROR_PTR("connectivity not 4 or 8", procName, NULL);
if (type != L_SELECT_IF_LT && type != L_SELECT_IF_GT &&
type != L_SELECT_IF_LTE && type != L_SELECT_IF_GTE)
return (PIX *)ERROR_PTR("invalid type", procName, NULL);
if (pchanged) *pchanged = FALSE;
/* Check if any components exist */
pixZero(pixs, &empty);
if (empty)
return pixCopy(NULL, pixs);
/* Filter thin components */
boxa = pixConnComp(pixs, &pixas, connectivity);
pixad = pixaSelectByPerimSizeRatio(pixas, thresh, type, &changed);
boxaDestroy(&boxa);
pixaDestroy(&pixas);
if (!changed) {
pixaDestroy(&pixad);
return pixCopy(NULL, pixs);
}
/* Render the result */
if (pchanged) *pchanged = TRUE;
pixGetDimensions(pixs, &w, &h, NULL);
count = pixaGetCount(pixad);
if (count == 0) { /* return empty pix */
pixd = pixCreateTemplate(pixs);
} else {
pixd = pixaDisplay(pixad, w, h);
pixCopyResolution(pixd, pixs);
pixCopyColormap(pixd, pixs);
pixCopyText(pixd, pixs);
pixCopyInputFormat(pixd, pixs);
}
pixaDestroy(&pixad);
return pixd;
}
/*!
* \brief pixaSelectByPerimSizeRatio()
*
* \param[in] pixas
* \param[in] thresh threshold ratio of fg boundary to b.b. circumference
* \param[in] type L_SELECT_IF_LT, L_SELECT_IF_GT,
* L_SELECT_IF_LTE, L_SELECT_IF_GTE
* \param[out] pchanged [optional] 1 if changed; 0 if clone returned
* \return pixad, or NULL on error
*
* <pre>
* Notes:
* (1) Returns a pixa clone if no components are removed.
* (2) Uses pix and box clones in the new pixa.
* (3) See pixSelectByPerimSizeRatio().
* </pre>
*/
PIXA *
pixaSelectByPerimSizeRatio(PIXA *pixas,
l_float32 thresh,
l_int32 type,
l_int32 *pchanged)
{
NUMA *na, *nai;
PIXA *pixad;
PROCNAME("pixaSelectByPerimSizeRatio");
if (!pixas)
return (PIXA *)ERROR_PTR("pixas not defined", procName, NULL);
if (type != L_SELECT_IF_LT && type != L_SELECT_IF_GT &&
type != L_SELECT_IF_LTE && type != L_SELECT_IF_GTE)
return (PIXA *)ERROR_PTR("invalid type", procName, NULL);
/* Compute component ratios. */
na = pixaFindPerimSizeRatio(pixas);
/* Generate indicator array for elements to be saved. */
nai = numaMakeThresholdIndicator(na, thresh, type);
numaDestroy(&na);
/* Filter to get output */
pixad = pixaSelectWithIndicator(pixas, nai, pchanged);
numaDestroy(&nai);
return pixad;
}
/*!
* \brief pixSelectByAreaFraction()
*
* \param[in] pixs 1 bpp
* \param[in] thresh threshold ratio of fg pixels to (w * h)
* \param[in] connectivity 4 or 8
* \param[in] type L_SELECT_IF_LT, L_SELECT_IF_GT,
* L_SELECT_IF_LTE, L_SELECT_IF_GTE
* \param[out] pchanged [optional] 1 if changed; 0 if clone returned
* \return pixd, or NULL on error
*
* <pre>
* Notes:
* (1) The args specify constraints on the amount of foreground
* coverage of the components that are kept.
* (2) If unchanged, returns a copy of pixs. Otherwise,
* returns a new pix with the filtered components.
* (3) This filters components based on the fraction of fg pixels
* of the component in its bounding box.
* (4) Use L_SELECT_IF_LT or L_SELECT_IF_LTE to save components
* with less than the threshold fraction of foreground, and
* L_SELECT_IF_GT or L_SELECT_IF_GTE to remove them.
* </pre>
*/
PIX *
pixSelectByAreaFraction(PIX *pixs,
l_float32 thresh,
l_int32 connectivity,
l_int32 type,
l_int32 *pchanged)
{
l_int32 w, h, empty, changed, count;
BOXA *boxa;
PIX *pixd;
PIXA *pixas, *pixad;
PROCNAME("pixSelectByAreaFraction");
if (!pixs)
return (PIX *)ERROR_PTR("pixs not defined", procName, NULL);
if (connectivity != 4 && connectivity != 8)
return (PIX *)ERROR_PTR("connectivity not 4 or 8", procName, NULL);
if (type != L_SELECT_IF_LT && type != L_SELECT_IF_GT &&
type != L_SELECT_IF_LTE && type != L_SELECT_IF_GTE)
return (PIX *)ERROR_PTR("invalid type", procName, NULL);
if (pchanged) *pchanged = FALSE;
/* Check if any components exist */
pixZero(pixs, &empty);
if (empty)
return pixCopy(NULL, pixs);
/* Filter components */
boxa = pixConnComp(pixs, &pixas, connectivity);
pixad = pixaSelectByAreaFraction(pixas, thresh, type, &changed);
boxaDestroy(&boxa);
pixaDestroy(&pixas);
if (!changed) {
pixaDestroy(&pixad);
return pixCopy(NULL, pixs);
}
/* Render the result */
if (pchanged) *pchanged = TRUE;
pixGetDimensions(pixs, &w, &h, NULL);
count = pixaGetCount(pixad);
if (count == 0) { /* return empty pix */
pixd = pixCreateTemplate(pixs);
} else {
pixd = pixaDisplay(pixad, w, h);
pixCopyResolution(pixd, pixs);
pixCopyColormap(pixd, pixs);
pixCopyText(pixd, pixs);
pixCopyInputFormat(pixd, pixs);
}
pixaDestroy(&pixad);
return pixd;
}
/*!
* \brief pixaSelectByAreaFraction()
*
* \param[in] pixas
* \param[in] thresh threshold ratio of fg pixels to (w * h)
* \param[in] type L_SELECT_IF_LT, L_SELECT_IF_GT,
* L_SELECT_IF_LTE, L_SELECT_IF_GTE
* \param[out] pchanged [optional] 1 if changed; 0 if clone returned
* \return pixad, or NULL on error
*
* <pre>
* Notes:
* (1) Returns a pixa clone if no components are removed.
* (2) Uses pix and box clones in the new pixa.
* (3) This filters components based on the fraction of fg pixels
* of the component in its bounding box.
* (4) Use L_SELECT_IF_LT or L_SELECT_IF_LTE to save components
* with less than the threshold fraction of foreground, and
* L_SELECT_IF_GT or L_SELECT_IF_GTE to remove them.
* </pre>
*/
PIXA *
pixaSelectByAreaFraction(PIXA *pixas,
l_float32 thresh,
l_int32 type,
l_int32 *pchanged)
{
NUMA *na, *nai;
PIXA *pixad;
PROCNAME("pixaSelectByAreaFraction");
if (!pixas)
return (PIXA *)ERROR_PTR("pixas not defined", procName, NULL);
if (type != L_SELECT_IF_LT && type != L_SELECT_IF_GT &&
type != L_SELECT_IF_LTE && type != L_SELECT_IF_GTE)
return (PIXA *)ERROR_PTR("invalid type", procName, NULL);
/* Compute component ratios. */
na = pixaFindAreaFraction(pixas);
/* Generate indicator array for elements to be saved. */
nai = numaMakeThresholdIndicator(na, thresh, type);
numaDestroy(&na);
/* Filter to get output */
pixad = pixaSelectWithIndicator(pixas, nai, pchanged);
numaDestroy(&nai);
return pixad;
}
/*!
* \brief pixSelectByWidthHeightRatio()
*
* \param[in] pixs 1 bpp
* \param[in] thresh threshold ratio of width/height
* \param[in] connectivity 4 or 8
* \param[in] type L_SELECT_IF_LT, L_SELECT_IF_GT,
* L_SELECT_IF_LTE, L_SELECT_IF_GTE
* \param[out] pchanged [optional] 1 if changed; 0 if clone returned
* \return pixd, or NULL on error
*
* <pre>
* Notes:
* (1) The args specify constraints on the width-to-height ratio
* for components that are kept.
* (2) If unchanged, returns a copy of pixs. Otherwise,
* returns a new pix with the filtered components.
* (3) This filters components based on the width-to-height ratios.
* (4) Use L_SELECT_IF_LT or L_SELECT_IF_LTE to save components
* with less than the threshold ratio, and
* L_SELECT_IF_GT or L_SELECT_IF_GTE to remove them.
* </pre>
*/
PIX *
pixSelectByWidthHeightRatio(PIX *pixs,
l_float32 thresh,
l_int32 connectivity,
l_int32 type,
l_int32 *pchanged)
{
l_int32 w, h, empty, changed, count;
BOXA *boxa;
PIX *pixd;
PIXA *pixas, *pixad;
PROCNAME("pixSelectByWidthHeightRatio");
if (!pixs)
return (PIX *)ERROR_PTR("pixs not defined", procName, NULL);
if (connectivity != 4 && connectivity != 8)
return (PIX *)ERROR_PTR("connectivity not 4 or 8", procName, NULL);
if (type != L_SELECT_IF_LT && type != L_SELECT_IF_GT &&
type != L_SELECT_IF_LTE && type != L_SELECT_IF_GTE)
return (PIX *)ERROR_PTR("invalid type", procName, NULL);
if (pchanged) *pchanged = FALSE;
/* Check if any components exist */
pixZero(pixs, &empty);
if (empty)
return pixCopy(NULL, pixs);
/* Filter components */
boxa = pixConnComp(pixs, &pixas, connectivity);
pixad = pixaSelectByWidthHeightRatio(pixas, thresh, type, &changed);
boxaDestroy(&boxa);
pixaDestroy(&pixas);
if (!changed) {
pixaDestroy(&pixad);
return pixCopy(NULL, pixs);
}
/* Render the result */
if (pchanged) *pchanged = TRUE;
pixGetDimensions(pixs, &w, &h, NULL);
count = pixaGetCount(pixad);
if (count == 0) { /* return empty pix */
pixd = pixCreateTemplate(pixs);
} else {
pixd = pixaDisplay(pixad, w, h);
pixCopyResolution(pixd, pixs);
pixCopyColormap(pixd, pixs);
pixCopyText(pixd, pixs);
pixCopyInputFormat(pixd, pixs);
}
pixaDestroy(&pixad);
return pixd;
}
/*!
* \brief pixaSelectByWidthHeightRatio()
*
* \param[in] pixas
* \param[in] thresh threshold ratio of width/height
* \param[in] type L_SELECT_IF_LT, L_SELECT_IF_GT,
* L_SELECT_IF_LTE, L_SELECT_IF_GTE
* \param[out] pchanged [optional] 1 if changed; 0 if clone returned
* \return pixad, or NULL on error
*
* <pre>
* Notes:
* (1) Returns a pixa clone if no components are removed.
* (2) Uses pix and box clones in the new pixa.
* (3) This filters components based on the width-to-height ratio
* of each pix.
* (4) Use L_SELECT_IF_LT or L_SELECT_IF_LTE to save components
* with less than the threshold ratio, and
* L_SELECT_IF_GT or L_SELECT_IF_GTE to remove them.
* </pre>
*/
PIXA *
pixaSelectByWidthHeightRatio(PIXA *pixas,
l_float32 thresh,
l_int32 type,
l_int32 *pchanged)
{
NUMA *na, *nai;
PIXA *pixad;
PROCNAME("pixaSelectByWidthHeightRatio");
if (!pixas)
return (PIXA *)ERROR_PTR("pixas not defined", procName, NULL);
if (type != L_SELECT_IF_LT && type != L_SELECT_IF_GT &&
type != L_SELECT_IF_LTE && type != L_SELECT_IF_GTE)
return (PIXA *)ERROR_PTR("invalid type", procName, NULL);
/* Compute component ratios. */
na = pixaFindWidthHeightRatio(pixas);
/* Generate indicator array for elements to be saved. */
nai = numaMakeThresholdIndicator(na, thresh, type);
numaDestroy(&na);
/* Filter to get output */
pixad = pixaSelectWithIndicator(pixas, nai, pchanged);
numaDestroy(&nai);
return pixad;
}
/*!
* \brief pixaSelectWithIndicator()
*
* \param[in] pixas
* \param[in] na indicator numa
* \param[out] pchanged [optional] 1 if changed; 0 if clone returned
* \return pixad, or NULL on error
*
* <pre>
* Notes:
* (1) Returns a pixa clone if no components are removed.
* (2) Uses pix and box clones in the new pixa.
* (3) The indicator numa has values 0 (ignore) and 1 (accept).
* (4) If the source boxa is not fully populated, it is left
* empty in the dest pixa.
* </pre>
*/
PIXA *
pixaSelectWithIndicator(PIXA *pixas,
NUMA *na,
l_int32 *pchanged)
{
l_int32 i, n, nbox, ival, nsave;
BOX *box;
PIX *pixt;
PIXA *pixad;
PROCNAME("pixaSelectWithIndicator");
if (!pixas)
return (PIXA *)ERROR_PTR("pixas not defined", procName, NULL);
if (!na)
return (PIXA *)ERROR_PTR("na not defined", procName, NULL);
nsave = 0;
n = numaGetCount(na);
for (i = 0; i < n; i++) {
numaGetIValue(na, i, &ival);
if (ival == 1) nsave++;
}
if (nsave == n) {
if (pchanged) *pchanged = FALSE;
return pixaCopy(pixas, L_CLONE);
}
if (pchanged) *pchanged = TRUE;
pixad = pixaCreate(nsave);
nbox = pixaGetBoxaCount(pixas);
for (i = 0; i < n; i++) {
numaGetIValue(na, i, &ival);
if (ival == 0) continue;
pixt = pixaGetPix(pixas, i, L_CLONE);
pixaAddPix(pixad, pixt, L_INSERT);
if (nbox == n) { /* fully populated boxa */
box = pixaGetBox(pixas, i, L_CLONE);
pixaAddBox(pixad, box, L_INSERT);
}
}
return pixad;
}
/*!
* \brief pixRemoveWithIndicator()
*
* \param[in] pixs 1 bpp pix from which components are removed; in-place
* \param[in] pixa of connected components in pixs
* \param[in] na numa indicator: remove components corresponding to 1s
* \return 0 if OK, 1 on error
*
* <pre>
* Notes:
* (1) This complements pixAddWithIndicator(). Here, the selected
* components are set subtracted from pixs.
* </pre>
*/
l_int32
pixRemoveWithIndicator(PIX *pixs,
PIXA *pixa,
NUMA *na)
{
l_int32 i, n, ival, x, y, w, h;
BOX *box;
PIX *pix;
PROCNAME("pixRemoveWithIndicator");
if (!pixs)
return ERROR_INT("pixs not defined", procName, 1);
if (!pixa)
return ERROR_INT("pixa not defined", procName, 1);
if (!na)
return ERROR_INT("na not defined", procName, 1);
n = pixaGetCount(pixa);
if (n != numaGetCount(na))
return ERROR_INT("pixa and na sizes not equal", procName, 1);
for (i = 0; i < n; i++) {
numaGetIValue(na, i, &ival);
if (ival == 1) {
pix = pixaGetPix(pixa, i, L_CLONE);
box = pixaGetBox(pixa, i, L_CLONE);
boxGetGeometry(box, &x, &y, &w, &h);
pixRasterop(pixs, x, y, w, h, PIX_DST & PIX_NOT(PIX_SRC),
pix, 0, 0);
boxDestroy(&box);
pixDestroy(&pix);
}
}
return 0;
}
/*!
* \brief pixAddWithIndicator()
*
* \param[in] pixs 1 bpp pix from which components are added; in-place
* \param[in] pixa of connected components, some of which will be put
* into pixs
* \param[in] na numa indicator: add components corresponding to 1s
* \return 0 if OK, 1 on error
*
* <pre>
* Notes:
* (1) This complements pixRemoveWithIndicator(). Here, the selected
* components are added to pixs.
* </pre>
*/
l_int32
pixAddWithIndicator(PIX *pixs,
PIXA *pixa,
NUMA *na)
{
l_int32 i, n, ival, x, y, w, h;
BOX *box;
PIX *pix;
PROCNAME("pixAddWithIndicator");
if (!pixs)
return ERROR_INT("pixs not defined", procName, 1);
if (!pixa)
return ERROR_INT("pixa not defined", procName, 1);
if (!na)
return ERROR_INT("na not defined", procName, 1);
n = pixaGetCount(pixa);
if (n != numaGetCount(na))
return ERROR_INT("pixa and na sizes not equal", procName, 1);
for (i = 0; i < n; i++) {
numaGetIValue(na, i, &ival);
if (ival == 1) {
pix = pixaGetPix(pixa, i, L_CLONE);
box = pixaGetBox(pixa, i, L_CLONE);
boxGetGeometry(box, &x, &y, &w, &h);
pixRasterop(pixs, x, y, w, h, PIX_SRC | PIX_DST, pix, 0, 0);
boxDestroy(&box);
pixDestroy(&pix);
}
}
return 0;
}
/*!
* \brief pixaSelectWithString()
*
* \param[in] pixas
* \param[in] str string of indices into pixa, giving the pix to be selected
* \param[out] perror [optional] 1 if any indices are invalid;
* 0 if all indices are valid
* \return pixad, or NULL on error
*
* <pre>
* Notes:
* (1) Returns a pixa with copies of selected pix.
* (2) Associated boxes are also copied, if fully populated.
* </pre>
*/
PIXA *
pixaSelectWithString(PIXA *pixas,
const char *str,
l_int32 *perror)
{
l_int32 i, nval, npix, nbox, val, imaxval;
l_float32 maxval;
BOX *box;
NUMA *na;
PIX *pix1;
PIXA *pixad;
PROCNAME("pixaSelectWithString");
if (perror) *perror = 0;
if (!pixas)
return (PIXA *)ERROR_PTR("pixas not defined", procName, NULL);
if (!str)
return (PIXA *)ERROR_PTR("str not defined", procName, NULL);
if ((na = numaCreateFromString(str)) == NULL)
return (PIXA *)ERROR_PTR("na not made", procName, NULL);
if ((nval = numaGetCount(na)) == 0) {
numaDestroy(&na);
return (PIXA *)ERROR_PTR("no indices found", procName, NULL);
}
numaGetMax(na, &maxval, NULL);
imaxval = (l_int32)(maxval + 0.1);
nbox = pixaGetBoxaCount(pixas);
npix = pixaGetCount(pixas);
if (imaxval >= npix) {
if (perror) *perror = 1;
L_ERROR("max index = %d, size of pixa = %d\n", procName, imaxval, npix);
}
pixad = pixaCreate(nval);
for (i = 0; i < nval; i++) {
numaGetIValue(na, i, &val);
if (val < 0 || val >= npix) {
L_ERROR("index %d out of range of pix\n", procName, val);
continue;
}
pix1 = pixaGetPix(pixas, val, L_COPY);
pixaAddPix(pixad, pix1, L_INSERT);
if (nbox == npix) { /* fully populated boxa */
box = pixaGetBox(pixas, val, L_COPY);
pixaAddBox(pixad, box, L_INSERT);
}
}
numaDestroy(&na);
return pixad;
}
/*!
* \brief pixaRenderComponent()
*
* \param[in] pixs [optional] 1 bpp pix
* \param[in] pixa of 1 bpp connected components, one of which will
* be rendered in pixs, with its origin determined
* by the associated box.
* \param[in] index of component to be rendered
* \return pixd, or NULL on error
*
* <pre>
* Notes:
* (1) If pixs is null, this generates an empty pix of a size determined
* by union of the component bounding boxes, and including the origin.
* (2) The selected component is blitted into pixs.
* </pre>
*/
PIX *
pixaRenderComponent(PIX *pixs,
PIXA *pixa,
l_int32 index)
{
l_int32 n, x, y, w, h, maxdepth;
BOX *box;
BOXA *boxa;
PIX *pix;
PROCNAME("pixaRenderComponent");
if (!pixa)
return (PIX *)ERROR_PTR("pixa not defined", procName, pixs);
n = pixaGetCount(pixa);
if (index < 0 || index >= n)
return (PIX *)ERROR_PTR("invalid index", procName, pixs);
if (pixs && (pixGetDepth(pixs) != 1))
return (PIX *)ERROR_PTR("pixs not 1 bpp", procName, pixs);
pixaVerifyDepth(pixa, &maxdepth);
if (maxdepth > 1)
return (PIX *)ERROR_PTR("not all pix with d == 1", procName, pixs);
boxa = pixaGetBoxa(pixa, L_CLONE);
if (!pixs) {
boxaGetExtent(boxa, &w, &h, NULL);
pixs = pixCreate(w, h, 1);
}
pix = pixaGetPix(pixa, index, L_CLONE);
box = boxaGetBox(boxa, index, L_CLONE);
boxGetGeometry(box, &x, &y, &w, &h);
pixRasterop(pixs, x, y, w, h, PIX_SRC | PIX_DST, pix, 0, 0);
boxDestroy(&box);
pixDestroy(&pix);
boxaDestroy(&boxa);
return pixs;
}
/*---------------------------------------------------------------------*
* Sort functions *
*---------------------------------------------------------------------*/
/*!
* \brief pixaSort()
*
* \param[in] pixas
* \param[in] sorttype L_SORT_BY_X, L_SORT_BY_Y, L_SORT_BY_WIDTH,
* L_SORT_BY_HEIGHT, L_SORT_BY_MIN_DIMENSION,
* L_SORT_BY_MAX_DIMENSION, L_SORT_BY_PERIMETER,
* L_SORT_BY_AREA, L_SORT_BY_ASPECT_RATIO
* \param[in] sortorder L_SORT_INCREASING, L_SORT_DECREASING
* \param[out] pnaindex [optional] index of sorted order into
* original array
* \param[in] copyflag L_COPY, L_CLONE
* \return pixad sorted version of pixas, or NULL on error
*
* <pre>
* Notes:
* (1) This sorts based on the data in the boxa. If the boxa
* count is not the same as the pixa count, this returns an error.
* (2) The copyflag refers to the pix and box copies that are
* inserted into the sorted pixa. These are either L_COPY
* or L_CLONE.
* </pre>
*/
PIXA *
pixaSort(PIXA *pixas,
l_int32 sorttype,
l_int32 sortorder,
NUMA **pnaindex,
l_int32 copyflag)
{
l_int32 i, n, x, y, w, h;
BOXA *boxa;
NUMA *na, *naindex;
PIXA *pixad;
PROCNAME("pixaSort");
if (pnaindex) *pnaindex = NULL;
if (!pixas)
return (PIXA *)ERROR_PTR("pixas not defined", procName, NULL);
if (sorttype != L_SORT_BY_X && sorttype != L_SORT_BY_Y &&
sorttype != L_SORT_BY_WIDTH && sorttype != L_SORT_BY_HEIGHT &&
sorttype != L_SORT_BY_MIN_DIMENSION &&
sorttype != L_SORT_BY_MAX_DIMENSION &&
sorttype != L_SORT_BY_PERIMETER &&
sorttype != L_SORT_BY_AREA &&
sorttype != L_SORT_BY_ASPECT_RATIO)
return (PIXA *)ERROR_PTR("invalid sort type", procName, NULL);
if (sortorder != L_SORT_INCREASING && sortorder != L_SORT_DECREASING)
return (PIXA *)ERROR_PTR("invalid sort order", procName, NULL);
if (copyflag != L_COPY && copyflag != L_CLONE)
return (PIXA *)ERROR_PTR("invalid copy flag", procName, NULL);
if ((boxa = pixas->boxa) == NULL) /* not owned; do not destroy */
return (PIXA *)ERROR_PTR("boxa not found", procName, NULL);
n = pixaGetCount(pixas);
if (boxaGetCount(boxa) != n)
return (PIXA *)ERROR_PTR("boxa and pixa counts differ", procName, NULL);
/* Use O(n) binsort if possible */
if (n > MIN_COMPS_FOR_BIN_SORT &&
((sorttype == L_SORT_BY_X) || (sorttype == L_SORT_BY_Y) ||
(sorttype == L_SORT_BY_WIDTH) || (sorttype == L_SORT_BY_HEIGHT) ||
(sorttype == L_SORT_BY_PERIMETER)))
return pixaBinSort(pixas, sorttype, sortorder, pnaindex, copyflag);
/* Build up numa of specific data */
if ((na = numaCreate(n)) == NULL)
return (PIXA *)ERROR_PTR("na not made", procName, NULL);
for (i = 0; i < n; i++) {
boxaGetBoxGeometry(boxa, i, &x, &y, &w, &h);
switch (sorttype)
{
case L_SORT_BY_X:
numaAddNumber(na, x);
break;
case L_SORT_BY_Y:
numaAddNumber(na, y);
break;
case L_SORT_BY_WIDTH:
numaAddNumber(na, w);
break;
case L_SORT_BY_HEIGHT:
numaAddNumber(na, h);
break;
case L_SORT_BY_MIN_DIMENSION:
numaAddNumber(na, L_MIN(w, h));
break;
case L_SORT_BY_MAX_DIMENSION:
numaAddNumber(na, L_MAX(w, h));
break;
case L_SORT_BY_PERIMETER:
numaAddNumber(na, w + h);
break;
case L_SORT_BY_AREA:
numaAddNumber(na, w * h);
break;
case L_SORT_BY_ASPECT_RATIO:
numaAddNumber(na, (l_float32)w / (l_float32)h);
break;
default:
L_WARNING("invalid sort type\n", procName);
}
}
/* Get the sort index for data array */
if ((naindex = numaGetSortIndex(na, sortorder)) == NULL)
return (PIXA *)ERROR_PTR("naindex not made", procName, NULL);
/* Build up sorted pixa using sort index */
if ((pixad = pixaSortByIndex(pixas, naindex, copyflag)) == NULL)
return (PIXA *)ERROR_PTR("pixad not made", procName, NULL);
if (pnaindex)
*pnaindex = naindex;
else
numaDestroy(&naindex);
numaDestroy(&na);
return pixad;
}
/*!
* \brief pixaBinSort()
*
* \param[in] pixas
* \param[in] sorttype L_SORT_BY_X, L_SORT_BY_Y, L_SORT_BY_WIDTH,
* L_SORT_BY_HEIGHT, L_SORT_BY_PERIMETER
* \param[in] sortorder L_SORT_INCREASING, L_SORT_DECREASING
* \param[out] pnaindex [optional] index of sorted order into
* original array
* \param[in] copyflag L_COPY, L_CLONE
* \return pixad sorted version of pixas, or NULL on error
*
* <pre>
* Notes:
* (1) This sorts based on the data in the boxa. If the boxa
* count is not the same as the pixa count, this returns an error.
* (2) The copyflag refers to the pix and box copies that are
* inserted into the sorted pixa. These are either L_COPY
* or L_CLONE.
* (3) For a large number of boxes (say, greater than 1000), this
* O(n) binsort is much faster than the O(nlogn) shellsort.
* For 5000 components, this is over 20x faster than boxaSort().
* (4) Consequently, pixaSort() calls this function if it will
* likely go much faster.
* </pre>
*/
PIXA *
pixaBinSort(PIXA *pixas,
l_int32 sorttype,
l_int32 sortorder,
NUMA **pnaindex,
l_int32 copyflag)
{
l_int32 i, n, x, y, w, h;
BOXA *boxa;
NUMA *na, *naindex;
PIXA *pixad;
PROCNAME("pixaBinSort");
if (pnaindex) *pnaindex = NULL;
if (!pixas)
return (PIXA *)ERROR_PTR("pixas not defined", procName, NULL);
if (sorttype != L_SORT_BY_X && sorttype != L_SORT_BY_Y &&
sorttype != L_SORT_BY_WIDTH && sorttype != L_SORT_BY_HEIGHT &&
sorttype != L_SORT_BY_PERIMETER)
return (PIXA *)ERROR_PTR("invalid sort type", procName, NULL);
if (sortorder != L_SORT_INCREASING && sortorder != L_SORT_DECREASING)
return (PIXA *)ERROR_PTR("invalid sort order", procName, NULL);
if (copyflag != L_COPY && copyflag != L_CLONE)
return (PIXA *)ERROR_PTR("invalid copy flag", procName, NULL);
/* Verify that the pixa and its boxa have the same count */
if ((boxa = pixas->boxa) == NULL) /* not owned; do not destroy */
return (PIXA *)ERROR_PTR("boxa not found", procName, NULL);
n = pixaGetCount(pixas);
if (boxaGetCount(boxa) != n)
return (PIXA *)ERROR_PTR("boxa and pixa counts differ", procName, NULL);
/* Generate Numa of appropriate box dimensions */
if ((na = numaCreate(n)) == NULL)
return (PIXA *)ERROR_PTR("na not made", procName, NULL);
for (i = 0; i < n; i++) {
boxaGetBoxGeometry(boxa, i, &x, &y, &w, &h);
switch (sorttype)
{
case L_SORT_BY_X:
numaAddNumber(na, x);
break;
case L_SORT_BY_Y:
numaAddNumber(na, y);
break;
case L_SORT_BY_WIDTH:
numaAddNumber(na, w);
break;
case L_SORT_BY_HEIGHT:
numaAddNumber(na, h);
break;
case L_SORT_BY_PERIMETER:
numaAddNumber(na, w + h);
break;
default:
L_WARNING("invalid sort type\n", procName);
}
}
/* Get the sort index for data array */
if ((naindex = numaGetBinSortIndex(na, sortorder)) == NULL)
return (PIXA *)ERROR_PTR("naindex not made", procName, NULL);
/* Build up sorted pixa using sort index */
if ((pixad = pixaSortByIndex(pixas, naindex, copyflag)) == NULL)
return (PIXA *)ERROR_PTR("pixad not made", procName, NULL);
if (pnaindex)
*pnaindex = naindex;
else
numaDestroy(&naindex);
numaDestroy(&na);
return pixad;
}
/*!
* \brief pixaSortByIndex()
*
* \param[in] pixas
* \param[in] naindex na that maps from the new pixa to the input pixa
* \param[in] copyflag L_COPY, L_CLONE
* \return pixad sorted, or NULL on error
*/
PIXA *
pixaSortByIndex(PIXA *pixas,
NUMA *naindex,
l_int32 copyflag)
{
l_int32 i, n, index;
BOX *box;
PIX *pix;
PIXA *pixad;
PROCNAME("pixaSortByIndex");
if (!pixas)
return (PIXA *)ERROR_PTR("pixas not defined", procName, NULL);
if (!naindex)
return (PIXA *)ERROR_PTR("naindex not defined", procName, NULL);
if (copyflag != L_CLONE && copyflag != L_COPY)
return (PIXA *)ERROR_PTR("invalid copyflag", procName, NULL);
n = pixaGetCount(pixas);
pixad = pixaCreate(n);
for (i = 0; i < n; i++) {
numaGetIValue(naindex, i, &index);
pix = pixaGetPix(pixas, index, copyflag);
box = pixaGetBox(pixas, index, copyflag);
pixaAddPix(pixad, pix, L_INSERT);
pixaAddBox(pixad, box, L_INSERT);
}
return pixad;
}
/*!
* \brief pixaSort2dByIndex()
*
* \param[in] pixas
* \param[in] naa numaa that maps from the new pixaa to the input pixas
* \param[in] copyflag L_CLONE or L_COPY
* \return paa sorted, or NULL on error
*/
PIXAA *
pixaSort2dByIndex(PIXA *pixas,
NUMAA *naa,
l_int32 copyflag)
{
l_int32 pixtot, ntot, i, j, n, nn, index;
BOX *box;
NUMA *na;
PIX *pix;
PIXA *pixa;
PIXAA *paa;
PROCNAME("pixaSort2dByIndex");
if (!pixas)
return (PIXAA *)ERROR_PTR("pixas not defined", procName, NULL);
if (!naa)
return (PIXAA *)ERROR_PTR("naindex not defined", procName, NULL);
/* Check counts */
ntot = numaaGetNumberCount(naa);
pixtot = pixaGetCount(pixas);
if (ntot != pixtot)
return (PIXAA *)ERROR_PTR("element count mismatch", procName, NULL);
n = numaaGetCount(naa);
paa = pixaaCreate(n);
for (i = 0; i < n; i++) {
na = numaaGetNuma(naa, i, L_CLONE);
nn = numaGetCount(na);
pixa = pixaCreate(nn);
for (j = 0; j < nn; j++) {
numaGetIValue(na, j, &index);
pix = pixaGetPix(pixas, index, copyflag);
box = pixaGetBox(pixas, index, copyflag);
pixaAddPix(pixa, pix, L_INSERT);
pixaAddBox(pixa, box, L_INSERT);
}
pixaaAddPixa(paa, pixa, L_INSERT);
numaDestroy(&na);
}
return paa;
}
/*---------------------------------------------------------------------*
* Pixa and Pixaa range selection *
*---------------------------------------------------------------------*/
/*!
* \brief pixaSelectRange()
*
* \param[in] pixas
* \param[in] first use 0 to select from the beginning
* \param[in] last use 0 to select to the end
* \param[in] copyflag L_COPY, L_CLONE
* \return pixad, or NULL on error
*
* <pre>
* Notes:
* (1) The copyflag specifies what we do with each pix from pixas.
* Specifically, L_CLONE inserts a clone into pixad of each
* selected pix from pixas.
* </pre>
*/
PIXA *
pixaSelectRange(PIXA *pixas,
l_int32 first,
l_int32 last,
l_int32 copyflag)
{
l_int32 n, npix, i;
PIX *pix;
PIXA *pixad;
PROCNAME("pixaSelectRange");
if (!pixas)
return (PIXA *)ERROR_PTR("pixas not defined", procName, NULL);
if (copyflag != L_COPY && copyflag != L_CLONE)
return (PIXA *)ERROR_PTR("invalid copyflag", procName, NULL);
n = pixaGetCount(pixas);
first = L_MAX(0, first);
if (last <= 0) last = n - 1;
if (first >= n)
return (PIXA *)ERROR_PTR("invalid first", procName, NULL);
if (first > last)
return (PIXA *)ERROR_PTR("first > last", procName, NULL);
npix = last - first + 1;
pixad = pixaCreate(npix);
for (i = first; i <= last; i++) {
pix = pixaGetPix(pixas, i, copyflag);
pixaAddPix(pixad, pix, L_INSERT);
}
return pixad;
}
/*!
* \brief pixaaSelectRange()
*
* \param[in] paas
* \param[in] first use 0 to select from the beginning
* \param[in] last use 0 to select to the end
* \param[in] copyflag L_COPY, L_CLONE
* \return paad, or NULL on error
*
* <pre>
* Notes:
* (1) The copyflag specifies what we do with each pixa from paas.
* Specifically, L_CLONE inserts a clone into paad of each
* selected pixa from paas.
* </pre>
*/
PIXAA *
pixaaSelectRange(PIXAA *paas,
l_int32 first,
l_int32 last,
l_int32 copyflag)
{
l_int32 n, npixa, i;
PIXA *pixa;
PIXAA *paad;
PROCNAME("pixaaSelectRange");
if (!paas)
return (PIXAA *)ERROR_PTR("paas not defined", procName, NULL);
if (copyflag != L_COPY && copyflag != L_CLONE)
return (PIXAA *)ERROR_PTR("invalid copyflag", procName, NULL);
n = pixaaGetCount(paas, NULL);
first = L_MAX(0, first);
if (last <= 0) last = n - 1;
if (first >= n)
return (PIXAA *)ERROR_PTR("invalid first", procName, NULL);
if (first > last)
return (PIXAA *)ERROR_PTR("first > last", procName, NULL);
npixa = last - first + 1;
paad = pixaaCreate(npixa);
for (i = first; i <= last; i++) {
pixa = pixaaGetPixa(paas, i, copyflag);
pixaaAddPixa(paad, pixa, L_INSERT);
}
return paad;
}
/*---------------------------------------------------------------------*
* Pixa and Pixaa scaling *
*---------------------------------------------------------------------*/
/*!
* \brief pixaaScaleToSize()
*
* \param[in] paas
* \param[in] wd target width; use 0 if using height as target
* \param[in] hd target height; use 0 if using width as target
* \return paad, or NULL on error
*
* <pre>
* Notes:
* (1) This guarantees that each output scaled image has the
* dimension(s) you specify.
* ~ To specify the width with isotropic scaling, set %hd = 0.
* ~ To specify the height with isotropic scaling, set %wd = 0.
* ~ If both %wd and %hd are specified, the image is scaled
* (in general, anisotropically) to that size.
* ~ It is an error to set both %wd and %hd to 0.
* </pre>
*/
PIXAA *
pixaaScaleToSize(PIXAA *paas,
l_int32 wd,
l_int32 hd)
{
l_int32 n, i;
PIXA *pixa1, *pixa2;
PIXAA *paad;
PROCNAME("pixaaScaleToSize");
if (!paas)
return (PIXAA *)ERROR_PTR("paas not defined", procName, NULL);
if (wd <= 0 && hd <= 0)
return (PIXAA *)ERROR_PTR("neither wd nor hd > 0", procName, NULL);
n = pixaaGetCount(paas, NULL);
paad = pixaaCreate(n);
for (i = 0; i < n; i++) {
pixa1 = pixaaGetPixa(paas, i, L_CLONE);
pixa2 = pixaScaleToSize(pixa1, wd, hd);
pixaaAddPixa(paad, pixa2, L_INSERT);
pixaDestroy(&pixa1);
}
return paad;
}
/*!
* \brief pixaaScaleToSizeVar()
*
* \param[in] paas
* \param[in] nawd [optional] target widths; use NULL if using height
* \param[in] nahd [optional] target height; use NULL if using width
* \return paad, or NULL on error
*
* <pre>
* Notes:
* (1) This guarantees that the scaled images in each pixa have the
* dimension(s) you specify in the numas.
* ~ To specify the width with isotropic scaling, set %nahd = NULL.
* ~ To specify the height with isotropic scaling, set %nawd = NULL.
* ~ If both %nawd and %nahd are specified, the image is scaled
* (in general, anisotropically) to that size.
* ~ It is an error to set both %nawd and %nahd to NULL.
* (2) If either nawd and/or nahd is defined, it must have the same
* count as the number of pixa in paas.
* </pre>
*/
PIXAA *
pixaaScaleToSizeVar(PIXAA *paas,
NUMA *nawd,
NUMA *nahd)
{
l_int32 n, i, wd, hd;
PIXA *pixa1, *pixa2;
PIXAA *paad;
PROCNAME("pixaaScaleToSizeVar");
if (!paas)
return (PIXAA *)ERROR_PTR("paas not defined", procName, NULL);
if (!nawd && !nahd)
return (PIXAA *)ERROR_PTR("!nawd && !nahd", procName, NULL);
n = pixaaGetCount(paas, NULL);
if (nawd && (n != numaGetCount(nawd)))
return (PIXAA *)ERROR_PTR("nawd wrong size", procName, NULL);
if (nahd && (n != numaGetCount(nahd)))
return (PIXAA *)ERROR_PTR("nahd wrong size", procName, NULL);
paad = pixaaCreate(n);
for (i = 0; i < n; i++) {
wd = hd = 0;
if (nawd) numaGetIValue(nawd, i, &wd);
if (nahd) numaGetIValue(nahd, i, &hd);
pixa1 = pixaaGetPixa(paas, i, L_CLONE);
pixa2 = pixaScaleToSize(pixa1, wd, hd);
pixaaAddPixa(paad, pixa2, L_INSERT);
pixaDestroy(&pixa1);
}
return paad;
}
/*!
* \brief pixaScaleToSize()
*
* \param[in] pixas
* \param[in] wd target width; use 0 if using height as target
* \param[in] hd target height; use 0 if using width as target
* \return pixad, or NULL on error
*
* <pre>
* Notes:
* (1) See pixaaScaleToSize()
* </pre>
*/
PIXA *
pixaScaleToSize(PIXA *pixas,
l_int32 wd,
l_int32 hd)
{
l_int32 n, i;
PIX *pix1, *pix2;
PIXA *pixad;
PROCNAME("pixaScaleToSize");
if (!pixas)
return (PIXA *)ERROR_PTR("pixas not defined", procName, NULL);
if (wd <= 0 && hd <= 0)
return (PIXA *)ERROR_PTR("neither wd nor hd > 0", procName, NULL);
n = pixaGetCount(pixas);
pixad = pixaCreate(n);
for (i = 0; i < n; i++) {
pix1 = pixaGetPix(pixas, i, L_CLONE);
pix2 = pixScaleToSize(pix1, wd, hd);
pixCopyText(pix2, pix1);
pixaAddPix(pixad, pix2, L_INSERT);
pixDestroy(&pix1);
}
return pixad;
}
/*!
* \brief pixaScaleToSizeRel()
*
* \param[in] pixas
* \param[in] delw change in width, in pixels; 0 means no change
* \param[in] delh change in height, in pixels; 0 means no change
* return pixad, or NULL on error
*
* <pre>
* Notes:
* (1) If a requested change in a pix is not possible because
* either the requested width or height is <= 0, issue a
* warning and return a copy.
* </pre>
*/
PIXA *
pixaScaleToSizeRel(PIXA *pixas,
l_int32 delw,
l_int32 delh)
{
l_int32 n, i;
PIX *pix1, *pix2;
PIXA *pixad;
PROCNAME("pixaScaleToSizeRel");
if (!pixas)
return (PIXA *)ERROR_PTR("pixas not defined", procName, NULL);
n = pixaGetCount(pixas);
pixad = pixaCreate(n);
for (i = 0; i < n; i++) {
pix1 = pixaGetPix(pixas, i, L_CLONE);
pix2 = pixScaleToSizeRel(pix1, delw, delh);
if (pix2) {
pixaAddPix(pixad, pix2, L_INSERT);
} else {
L_WARNING("relative scale to size failed; use a copy\n", procName);
pixaAddPix(pixad, pix1, L_COPY);
}
pixDestroy(&pix1);
}
return pixad;
}
/*!
* \brief pixaScale()
*
* \param[in] pixas
* \param[in] scalex
* \param[in] scaley
* \return pixad, or NULL on error
*
* <pre>
* Notes:
* (1) If pixas has a full boxes, it is scaled as well.
* </pre>
*/
PIXA *
pixaScale(PIXA *pixas,
l_float32 scalex,
l_float32 scaley)
{
l_int32 i, n, nb;
BOXA *boxa1, *boxa2;
PIX *pix1, *pix2;
PIXA *pixad;
PROCNAME("pixaScale");
if (!pixas)
return (PIXA *)ERROR_PTR("pixas not defined", procName, NULL);
if (scalex <= 0.0 || scaley <= 0.0)
return (PIXA *)ERROR_PTR("invalid scaling parameters", procName, NULL);
n = pixaGetCount(pixas);
pixad = pixaCreate(n);
for (i = 0; i < n; i++) {
pix1 = pixaGetPix(pixas, i, L_CLONE);
pix2 = pixScale(pix1, scalex, scaley);
pixCopyText(pix2, pix1);
pixaAddPix(pixad, pix2, L_INSERT);
pixDestroy(&pix1);
}
boxa1 = pixaGetBoxa(pixas, L_CLONE);
nb = boxaGetCount(boxa1);
if (nb == n) {
boxa2 = boxaTransform(boxa1, 0, 0, scalex, scaley);
pixaSetBoxa(pixad, boxa2, L_INSERT);
} else {
boxaDestroy(&boxa1);
}
return pixad;
}
/*---------------------------------------------------------------------*
* Miscellaneous functions *
*---------------------------------------------------------------------*/
/*!
* \brief pixaAddBorderGeneral()
*
* \param[in] pixad can be null or equal to pixas
* \param[in] pixas containing pix of all depths; colormap ok
* \param[in] left, right, top, bot number of pixels added
* \param[in] val value of added border pixels
* \return pixad with border added to each pix, including on error
*
* <pre>
* Notes:
* (1) For binary images:
* white: val = 0
* black: val = 1
* For grayscale images:
* white: val = 2 ** d - 1
* black: val = 0
* For rgb color images:
* white: val = 0xffffff00
* black: val = 0
* For colormapped images, use 'index' found this way:
* white: pixcmapGetRankIntensity(cmap, 1.0, &index);
* black: pixcmapGetRankIntensity(cmap, 0.0, &index);
* (2) For in-place replacement of each pix with a bordered version,
* use %pixad = %pixas. To make a new pixa, use %pixad = NULL.
* (3) In both cases, the boxa has sides adjusted as if it were
* expanded by the border.
* </pre>
*/
PIXA *
pixaAddBorderGeneral(PIXA *pixad,
PIXA *pixas,
l_int32 left,
l_int32 right,
l_int32 top,
l_int32 bot,
l_uint32 val)
{
l_int32 i, n, nbox;
BOX *box;
BOXA *boxad;
PIX *pixs, *pixd;
PROCNAME("pixaAddBorderGeneral");
if (!pixas)
return (PIXA *)ERROR_PTR("pixas not defined", procName, pixad);
if (left < 0 || right < 0 || top < 0 || bot < 0)
return (PIXA *)ERROR_PTR("negative border added!", procName, pixad);
if (pixad && (pixad != pixas))
return (PIXA *)ERROR_PTR("pixad defined but != pixas", procName, pixad);
n = pixaGetCount(pixas);
if (!pixad)
pixad = pixaCreate(n);
for (i = 0; i < n; i++) {
pixs = pixaGetPix(pixas, i, L_CLONE);
pixd = pixAddBorderGeneral(pixs, left, right, top, bot, val);
if (pixad == pixas) /* replace */
pixaReplacePix(pixad, i, pixd, NULL);
else
pixaAddPix(pixad, pixd, L_INSERT);
pixDestroy(&pixs);
}
nbox = pixaGetBoxaCount(pixas);
boxad = pixaGetBoxa(pixad, L_CLONE);
for (i = 0; i < nbox; i++) {
if ((box = pixaGetBox(pixas, i, L_COPY)) == NULL) {
L_WARNING("box %d not found\n", procName, i);
break;
}
boxAdjustSides(box, box, -left, right, -top, bot);
if (pixad == pixas) /* replace */
boxaReplaceBox(boxad, i, box);
else
boxaAddBox(boxad, box, L_INSERT);
}
boxaDestroy(&boxad);
return pixad;
}
/*!
* \brief pixaaFlattenToPixa()
*
* \param[in] paa
* \param[out] pnaindex [optional] the pixa index in the pixaa
* \param[in] copyflag L_COPY or L_CLONE
* \return pixa, or NULL on error
*
* <pre>
* Notes:
* (1) This 'flattens' the pixaa to a pixa, taking the pix in
* order in the first pixa, then the second, etc.
* (2) If \&naindex is defined, we generate a Numa that gives, for
* each pix in the pixaa, the index of the pixa to which it belongs.
* </pre>
*/
PIXA *
pixaaFlattenToPixa(PIXAA *paa,
NUMA **pnaindex,
l_int32 copyflag)
{
l_int32 i, j, m, mb, n;
BOX *box;
NUMA *naindex;
PIX *pix;
PIXA *pixa, *pixat;
PROCNAME("pixaaFlattenToPixa");
if (pnaindex) *pnaindex = NULL;
if (!paa)
return (PIXA *)ERROR_PTR("paa not defined", procName, NULL);
if (copyflag != L_COPY && copyflag != L_CLONE)
return (PIXA *)ERROR_PTR("invalid copyflag", procName, NULL);
if (pnaindex) {
naindex = numaCreate(0);
*pnaindex = naindex;
}
n = pixaaGetCount(paa, NULL);
pixa = pixaCreate(n);
for (i = 0; i < n; i++) {
pixat = pixaaGetPixa(paa, i, L_CLONE);
m = pixaGetCount(pixat);
mb = pixaGetBoxaCount(pixat);
for (j = 0; j < m; j++) {
pix = pixaGetPix(pixat, j, copyflag);
pixaAddPix(pixa, pix, L_INSERT);
if (j < mb) {
box = pixaGetBox(pixat, j, copyflag);
pixaAddBox(pixa, box, L_INSERT);
}
if (pnaindex)
numaAddNumber(naindex, i); /* save 'row' number */
}
pixaDestroy(&pixat);
}
return pixa;
}
/*!
* \brief pixaaSizeRange()
*
* \param[in] paa
* \param[out] pminw, pminh, pmaxw, pmaxh [optional] range of
* dimensions of all boxes
* \return 0 if OK, 1 on error
*/
l_int32
pixaaSizeRange(PIXAA *paa,
l_int32 *pminw,
l_int32 *pminh,
l_int32 *pmaxw,
l_int32 *pmaxh)
{
l_int32 minw, minh, maxw, maxh, minpw, minph, maxpw, maxph, i, n;
PIXA *pixa;
PROCNAME("pixaaSizeRange");
if (pminw) *pminw = 0;
if (pminh) *pminh = 0;
if (pmaxw) *pmaxw = 0;
if (pmaxh) *pmaxh = 0;
if (!paa)
return ERROR_INT("paa not defined", procName, 1);
if (!pminw && !pmaxw && !pminh && !pmaxh)
return ERROR_INT("no data can be returned", procName, 1);
minw = minh = 100000000;
maxw = maxh = 0;
n = pixaaGetCount(paa, NULL);
for (i = 0; i < n; i++) {
pixa = pixaaGetPixa(paa, i, L_CLONE);
pixaSizeRange(pixa, &minpw, &minph, &maxpw, &maxph);
if (minpw < minw)
minw = minpw;
if (minph < minh)
minh = minph;
if (maxpw > maxw)
maxw = maxpw;
if (maxph > maxh)
maxh = maxph;
pixaDestroy(&pixa);
}
if (pminw) *pminw = minw;
if (pminh) *pminh = minh;
if (pmaxw) *pmaxw = maxw;
if (pmaxh) *pmaxh = maxh;
return 0;
}
/*!
* \brief pixaSizeRange()
*
* \param[in] pixa
* \param[out] pminw, pminh, pmaxw, pmaxh [optional] range of
* dimensions of pix in the array
* \return 0 if OK, 1 on error
*/
l_int32
pixaSizeRange(PIXA *pixa,
l_int32 *pminw,
l_int32 *pminh,
l_int32 *pmaxw,
l_int32 *pmaxh)
{
l_int32 minw, minh, maxw, maxh, i, n, w, h;
PIX *pix;
PROCNAME("pixaSizeRange");
if (pminw) *pminw = 0;
if (pminh) *pminh = 0;
if (pmaxw) *pmaxw = 0;
if (pmaxh) *pmaxh = 0;
if (!pixa)
return ERROR_INT("pixa not defined", procName, 1);
if (!pminw && !pmaxw && !pminh && !pmaxh)
return ERROR_INT("no data can be returned", procName, 1);
minw = minh = 1000000;
maxw = maxh = 0;
n = pixaGetCount(pixa);
for (i = 0; i < n; i++) {
pix = pixaGetPix(pixa, i, L_CLONE);
w = pixGetWidth(pix);
h = pixGetHeight(pix);
if (w < minw)
minw = w;
if (h < minh)
minh = h;
if (w > maxw)
maxw = w;
if (h > maxh)
maxh = h;
pixDestroy(&pix);
}
if (pminw) *pminw = minw;
if (pminh) *pminh = minh;
if (pmaxw) *pmaxw = maxw;
if (pmaxh) *pmaxh = maxh;
return 0;
}
/*!
* \brief pixaClipToPix()
*
* \param[in] pixas
* \param[in] pixs
* \return pixad, or NULL on error
*
* <pre>
* Notes:
* (1) This is intended for use in situations where pixas
* was originally generated from the input pixs.
* (2) Returns a pixad where each pix in pixas is ANDed
* with its associated region of the input pixs. This
* region is specified by the the box that is associated
* with the pix.
* (3) In a typical application of this function, pixas has
* a set of region masks, so this generates a pixa of
* the parts of pixs that correspond to each region
* mask component, along with the bounding box for
* the region.
* </pre>
*/
PIXA *
pixaClipToPix(PIXA *pixas,
PIX *pixs)
{
l_int32 i, n;
BOX *box;
PIX *pix, *pixc;
PIXA *pixad;
PROCNAME("pixaClipToPix");
if (!pixas)
return (PIXA *)ERROR_PTR("pixas not defined", procName, NULL);
if (!pixs)
return (PIXA *)ERROR_PTR("pixs not defined", procName, NULL);
n = pixaGetCount(pixas);
if ((pixad = pixaCreate(n)) == NULL)
return (PIXA *)ERROR_PTR("pixad not made", procName, NULL);
for (i = 0; i < n; i++) {
pix = pixaGetPix(pixas, i, L_CLONE);
box = pixaGetBox(pixas, i, L_COPY);
pixc = pixClipRectangle(pixs, box, NULL);
pixAnd(pixc, pixc, pix);
pixaAddPix(pixad, pixc, L_INSERT);
pixaAddBox(pixad, box, L_INSERT);
pixDestroy(&pix);
}
return pixad;
}
/*!
* \brief pixaGetRenderingDepth()
*
* \param[in] pixa
* \param[out] pdepth depth required to render if all
* colormaps are removed
* \return 0 if OK; 1 on error
*/
l_int32
pixaGetRenderingDepth(PIXA *pixa,
l_int32 *pdepth)
{
l_int32 hascolor, maxdepth;
PROCNAME("pixaGetRenderingDepth");
if (!pdepth)
return ERROR_INT("&depth not defined", procName, 1);
*pdepth = 0;
if (!pixa)
return ERROR_INT("pixa not defined", procName, 1);
pixaHasColor(pixa, &hascolor);
if (hascolor) {
*pdepth = 32;
return 0;
}
pixaGetDepthInfo(pixa, &maxdepth, NULL);
if (maxdepth == 1)
*pdepth = 1;
else /* 2, 4, 8 or 16 */
*pdepth = 8;
return 0;
}
/*!
* \brief pixaHasColor()
*
* \param[in] pixa
* \param[out] phascolor 1 if any pix is rgb or has
* a colormap with color; 0 otherwise
* \return 0 if OK; 1 on error
*/
l_int32
pixaHasColor(PIXA *pixa,
l_int32 *phascolor)
{
l_int32 i, n, hascolor, d;
PIX *pix;
PIXCMAP *cmap;
PROCNAME("pixaHasColor");
if (!phascolor)
return ERROR_INT("&hascolor not defined", procName, 1);
*phascolor = 0;
if (!pixa)
return ERROR_INT("pixa not defined", procName, 1);
n = pixaGetCount(pixa);
for (i = 0; i < n; i++) {
pix = pixaGetPix(pixa, i, L_CLONE);
if ((cmap = pixGetColormap(pix)) != NULL)
pixcmapHasColor(cmap, &hascolor);
d = pixGetDepth(pix);
pixDestroy(&pix);
if (d == 32 || hascolor == 1) {
*phascolor = 1;
break;
}
}
return 0;
}
/*!
* \brief pixaAnyColormaps()
*
* \param[in] pixa
* \param[out] phascmap 1 if any pix has a colormap; 0 otherwise
* \return 0 if OK; 1 on error
*/
l_int32
pixaAnyColormaps(PIXA *pixa,
l_int32 *phascmap)
{
l_int32 i, n;
PIX *pix;
PIXCMAP *cmap;
PROCNAME("pixaAnyColormaps");
if (!phascmap)
return ERROR_INT("&hascmap not defined", procName, 1);
*phascmap = 0;
if (!pixa)
return ERROR_INT("pixa not defined", procName, 1);
n = pixaGetCount(pixa);
for (i = 0; i < n; i++) {
pix = pixaGetPix(pixa, i, L_CLONE);
cmap = pixGetColormap(pix);
pixDestroy(&pix);
if (cmap) {
*phascmap = 1;
return 0;
}
}
return 0;
}
/*!
* \brief pixaGetDepthInfo()
*
* \param[in] pixa
* \param[out] pmaxdepth [optional] max pixel depth of pix in pixa
* \param[out] psame [optional] true if all depths are equal
* \return 0 if OK; 1 on error
*/
l_int32
pixaGetDepthInfo(PIXA *pixa,
l_int32 *pmaxdepth,
l_int32 *psame)
{
l_int32 i, n, d, d0;
l_int32 maxd, same; /* depth info */
PROCNAME("pixaGetDepthInfo");
if (pmaxdepth) *pmaxdepth = 0;
if (psame) *psame = TRUE;
if (!pmaxdepth && !psame) return 0;
if (!pixa)
return ERROR_INT("pixa not defined", procName, 1);
if ((n = pixaGetCount(pixa)) == 0)
return ERROR_INT("pixa is empty", procName, 1);
same = TRUE;
maxd = 0;
for (i = 0; i < n; i++) {
pixaGetPixDimensions(pixa, i, NULL, NULL, &d);
if (i == 0)
d0 = d;
else if (d != d0)
same = FALSE;
if (d > maxd) maxd = d;
}
if (pmaxdepth) *pmaxdepth = maxd;
if (psame) *psame = same;
return 0;
}
/*!
* \brief pixaConvertToSameDepth()
*
* \param[in] pixas
* \return pixad, or NULL on error
*
* <pre>
* Notes:
* (1) If any pix has a colormap, they are all converted to rgb.
* Otherwise, they are all converted to the maximum depth of
* all the pix.
* (2) This can be used to allow lossless rendering onto a single pix.
* </pre>
*/
PIXA *
pixaConvertToSameDepth(PIXA *pixas)
{
l_int32 i, n, same, hascmap, maxdepth;
PIX *pix, *pixt;
PIXA *pixat, *pixad;
PROCNAME("pixaConvertToSameDepth");
if (!pixas)
return (PIXA *)ERROR_PTR("pixas not defined", procName, NULL);
/* Remove colormaps to rgb */
if ((n = pixaGetCount(pixas)) == 0)
return (PIXA *)ERROR_PTR("no components", procName, NULL);
pixaAnyColormaps(pixas, &hascmap);
if (hascmap) {
pixat = pixaCreate(n);
for (i = 0; i < n; i++) {
pixt = pixaGetPix(pixas, i, L_CLONE);
pix = pixConvertTo32(pixt);
pixaAddPix(pixat, pix, L_INSERT);
pixDestroy(&pixt);
}
} else {
pixat = pixaCopy(pixas, L_CLONE);
}
pixaGetDepthInfo(pixat, &maxdepth, &same);
if (!same) { /* at least one pix has depth < maxdepth */
pixad = pixaCreate(n);
for (i = 0; i < n; i++) {
pixt = pixaGetPix(pixat, i, L_CLONE);
if (maxdepth <= 8)
pix = pixConvertTo8(pixt, 0);
else
pix = pixConvertTo32(pixt);
pixaAddPix(pixad, pix, L_INSERT);
pixDestroy(&pixt);
}
} else {
pixad = pixaCopy(pixat, L_CLONE);
}
pixaDestroy(&pixat);
return pixad;
}
/*!
* \brief pixaEqual()
*
* \param[in] pixa1
* \param[in] pixa2
* \param[in] maxdist
* \param[out] pnaindex [optional] index array of correspondences
* [out] psame (1 if equal; 0 otherwise
* \return 0 if OK, 1 on error
*
* <pre>
* Notes:
* (1) The two pixa are the "same" if they contain the same
* boxa and the same ordered set of pix. However, if they
* have boxa, the pix in each pixa can differ in ordering
* by an amount given by the parameter %maxdist. If they
* don't have a boxa, the %maxdist parameter is ignored,
* and the ordering must be identical.
* (2) This applies only to boxa geometry, pixels and ordering;
* other fields in the pix are ignored.
* (3) naindex[i] gives the position of the box in pixa2 that
* corresponds to box i in pixa1. It is only returned if the
* pixa have boxa and the boxa are equal.
* (4) In situations where the ordering is very different, so that
* a large %maxdist is required for "equality", this should be
* implemented with a hash function for efficiency.
* </pre>
*/
l_int32
pixaEqual(PIXA *pixa1,
PIXA *pixa2,
l_int32 maxdist,
NUMA **pnaindex,
l_int32 *psame)
{
l_int32 i, j, n, same, sameboxa;
BOXA *boxa1, *boxa2;
NUMA *na;
PIX *pix1, *pix2;
PROCNAME("pixaEqual");
if (pnaindex) *pnaindex = NULL;
if (!psame)
return ERROR_INT("&same not defined", procName, 1);
*psame = 0;
sameboxa = 0;
na = NULL;
if (!pixa1 || !pixa2)
return ERROR_INT("pixa1 and pixa2 not both defined", procName, 1);
n = pixaGetCount(pixa1);
if (n != pixaGetCount(pixa2))
return 0;
boxa1 = pixaGetBoxa(pixa1, L_CLONE);
boxa2 = pixaGetBoxa(pixa2, L_CLONE);
if (!boxa1 && !boxa2)
maxdist = 0; /* exact ordering required */
if (boxa1 && !boxa2) {
boxaDestroy(&boxa1);
return 0;
}
if (!boxa1 && boxa2) {
boxaDestroy(&boxa2);
return 0;
}
if (boxa1 && boxa2) {
boxaEqual(boxa1, boxa2, maxdist, &na, &sameboxa);
boxaDestroy(&boxa1);
boxaDestroy(&boxa2);
if (!sameboxa) {
numaDestroy(&na);
return 0;
}
}
for (i = 0; i < n; i++) {
pix1 = pixaGetPix(pixa1, i, L_CLONE);
if (na)
numaGetIValue(na, i, &j);
else
j = i;
pix2 = pixaGetPix(pixa2, j, L_CLONE);
pixEqual(pix1, pix2, &same);
pixDestroy(&pix1);
pixDestroy(&pix2);
if (!same) {
numaDestroy(&na);
return 0;
}
}
*psame = 1;
if (pnaindex)
*pnaindex = na;
else
numaDestroy(&na);
return 0;
}
/*!
* \brief pixaRotateOrth()
*
* \param[in] pixas
* \param[in] rotation 0 = noop, 1 = 90 deg, 2 = 180 deg, 3 = 270 deg;
* all rotations are clockwise
* \return pixad, or NULL on error
*
* <pre>
* Notes:
* (1) Rotates each pix in the pixa. Rotates and saves the boxes in
* the boxa if the boxa is full.
* </pre>
*/
PIXA *
pixaRotateOrth(PIXA *pixas,
l_int32 rotation)
{
l_int32 i, n, nb, w, h;
BOX *boxs, *boxd;
PIX *pixs, *pixd;
PIXA *pixad;
PROCNAME("pixaRotateOrth");
if (!pixas)
return (PIXA *)ERROR_PTR("pixas not defined", procName, NULL);
if (rotation < 0 || rotation > 3)
return (PIXA *)ERROR_PTR("rotation not in {0,1,2,3}", procName, NULL);
if (rotation == 0)
return pixaCopy(pixas, L_COPY);
n = pixaGetCount(pixas);
nb = pixaGetBoxaCount(pixas);
if ((pixad = pixaCreate(n)) == NULL)
return (PIXA *)ERROR_PTR("pixad not made", procName, NULL);
for (i = 0; i < n; i++) {
if ((pixs = pixaGetPix(pixas, i, L_CLONE)) == NULL)
return (PIXA *)ERROR_PTR("pixs not found", procName, NULL);
pixd = pixRotateOrth(pixs, rotation);
pixaAddPix(pixad, pixd, L_INSERT);
if (n == nb) {
boxs = pixaGetBox(pixas, i, L_COPY);
pixGetDimensions(pixs, &w, &h, NULL);
boxd = boxRotateOrth(boxs, w, h, rotation);
pixaAddBox(pixad, boxd, L_INSERT);
boxDestroy(&boxs);
}
pixDestroy(&pixs);
}
return pixad;
}
|
fd31b78ca01b4d5e1870e831cf1c8d64f1b14dda
|
010279e2ba272d09e9d2c4e903722e5faba2cf7a
|
/contrib/python/scipy/py3/scipy/special/cephes/incbet.c
|
df5cacbe830326cc59e0be26f426b929775348ec
|
[
"Python-2.0",
"LicenseRef-scancode-unknown-license-reference",
"MIT",
"Qhull",
"BSD-3-Clause",
"BSL-1.0",
"Apache-2.0",
"BSD-2-Clause"
] |
permissive
|
catboost/catboost
|
854c1a1f439a96f1ae6b48e16644be20aa04dba2
|
f5042e35b945aded77b23470ead62d7eacefde92
|
refs/heads/master
| 2023-09-01T12:14:14.174108
| 2023-09-01T10:01:01
| 2023-09-01T10:22:12
| 97,556,265
| 8,012
| 1,425
|
Apache-2.0
| 2023-09-11T03:32:32
| 2017-07-18T05:29:04
|
Python
|
UTF-8
|
C
| false
| false
| 7,021
|
c
|
incbet.c
|
/* incbet.c
*
* Incomplete beta integral
*
*
* SYNOPSIS:
*
* double a, b, x, y, incbet();
*
* y = incbet( a, b, x );
*
*
* DESCRIPTION:
*
* Returns incomplete beta integral of the arguments, evaluated
* from zero to x. The function is defined as
*
* x
* - -
* | (a+b) | | a-1 b-1
* ----------- | t (1-t) dt.
* - - | |
* | (a) | (b) -
* 0
*
* The domain of definition is 0 <= x <= 1. In this
* implementation a and b are restricted to positive values.
* The integral from x to 1 may be obtained by the symmetry
* relation
*
* 1 - incbet( a, b, x ) = incbet( b, a, 1-x ).
*
* The integral is evaluated by a continued fraction expansion
* or, when b*x is small, by a power series.
*
* ACCURACY:
*
* Tested at uniformly distributed random points (a,b,x) with a and b
* in "domain" and x between 0 and 1.
* Relative error
* arithmetic domain # trials peak rms
* IEEE 0,5 10000 6.9e-15 4.5e-16
* IEEE 0,85 250000 2.2e-13 1.7e-14
* IEEE 0,1000 30000 5.3e-12 6.3e-13
* IEEE 0,10000 250000 9.3e-11 7.1e-12
* IEEE 0,100000 10000 8.7e-10 4.8e-11
* Outputs smaller than the IEEE gradual underflow threshold
* were excluded from these statistics.
*
* ERROR MESSAGES:
* message condition value returned
* incbet domain x<0, x>1 0.0
* incbet underflow 0.0
*/
/*
* Cephes Math Library, Release 2.3: March, 1995
* Copyright 1984, 1995 by Stephen L. Moshier
*/
#include "mconf.h"
#define MAXGAM 171.624376956302725
extern double MACHEP, MINLOG, MAXLOG;
static double big = 4.503599627370496e15;
static double biginv = 2.22044604925031308085e-16;
static double incbcf(double a, double b, double x);
static double incbd(double a, double b, double x);
static double pseries(double a, double b, double x);
double incbet(aa, bb, xx)
double aa, bb, xx;
{
double a, b, t, x, xc, w, y;
int flag;
if (aa <= 0.0 || bb <= 0.0)
goto domerr;
if ((xx <= 0.0) || (xx >= 1.0)) {
if (xx == 0.0)
return (0.0);
if (xx == 1.0)
return (1.0);
domerr:
sf_error("incbet", SF_ERROR_DOMAIN, NULL);
return (NPY_NAN);
}
flag = 0;
if ((bb * xx) <= 1.0 && xx <= 0.95) {
t = pseries(aa, bb, xx);
goto done;
}
w = 1.0 - xx;
/* Reverse a and b if x is greater than the mean. */
if (xx > (aa / (aa + bb))) {
flag = 1;
a = bb;
b = aa;
xc = xx;
x = w;
}
else {
a = aa;
b = bb;
xc = w;
x = xx;
}
if (flag == 1 && (b * x) <= 1.0 && x <= 0.95) {
t = pseries(a, b, x);
goto done;
}
/* Choose expansion for better convergence. */
y = x * (a + b - 2.0) - (a - 1.0);
if (y < 0.0)
w = incbcf(a, b, x);
else
w = incbd(a, b, x) / xc;
/* Multiply w by the factor
* a b _ _ _
* x (1-x) | (a+b) / ( a | (a) | (b) ) . */
y = a * log(x);
t = b * log(xc);
if ((a + b) < MAXGAM && fabs(y) < MAXLOG && fabs(t) < MAXLOG) {
t = pow(xc, b);
t *= pow(x, a);
t /= a;
t *= w;
t *= 1.0 / beta(a, b);
goto done;
}
/* Resort to logarithms. */
y += t - lbeta(a,b);
y += log(w / a);
if (y < MINLOG)
t = 0.0;
else
t = exp(y);
done:
if (flag == 1) {
if (t <= MACHEP)
t = 1.0 - MACHEP;
else
t = 1.0 - t;
}
return (t);
}
/* Continued fraction expansion #1
* for incomplete beta integral
*/
static double incbcf(a, b, x)
double a, b, x;
{
double xk, pk, pkm1, pkm2, qk, qkm1, qkm2;
double k1, k2, k3, k4, k5, k6, k7, k8;
double r, t, ans, thresh;
int n;
k1 = a;
k2 = a + b;
k3 = a;
k4 = a + 1.0;
k5 = 1.0;
k6 = b - 1.0;
k7 = k4;
k8 = a + 2.0;
pkm2 = 0.0;
qkm2 = 1.0;
pkm1 = 1.0;
qkm1 = 1.0;
ans = 1.0;
r = 1.0;
n = 0;
thresh = 3.0 * MACHEP;
do {
xk = -(x * k1 * k2) / (k3 * k4);
pk = pkm1 + pkm2 * xk;
qk = qkm1 + qkm2 * xk;
pkm2 = pkm1;
pkm1 = pk;
qkm2 = qkm1;
qkm1 = qk;
xk = (x * k5 * k6) / (k7 * k8);
pk = pkm1 + pkm2 * xk;
qk = qkm1 + qkm2 * xk;
pkm2 = pkm1;
pkm1 = pk;
qkm2 = qkm1;
qkm1 = qk;
if (qk != 0)
r = pk / qk;
if (r != 0) {
t = fabs((ans - r) / r);
ans = r;
}
else
t = 1.0;
if (t < thresh)
goto cdone;
k1 += 1.0;
k2 += 1.0;
k3 += 2.0;
k4 += 2.0;
k5 += 1.0;
k6 -= 1.0;
k7 += 2.0;
k8 += 2.0;
if ((fabs(qk) + fabs(pk)) > big) {
pkm2 *= biginv;
pkm1 *= biginv;
qkm2 *= biginv;
qkm1 *= biginv;
}
if ((fabs(qk) < biginv) || (fabs(pk) < biginv)) {
pkm2 *= big;
pkm1 *= big;
qkm2 *= big;
qkm1 *= big;
}
}
while (++n < 300);
cdone:
return (ans);
}
/* Continued fraction expansion #2
* for incomplete beta integral
*/
static double incbd(a, b, x)
double a, b, x;
{
double xk, pk, pkm1, pkm2, qk, qkm1, qkm2;
double k1, k2, k3, k4, k5, k6, k7, k8;
double r, t, ans, z, thresh;
int n;
k1 = a;
k2 = b - 1.0;
k3 = a;
k4 = a + 1.0;
k5 = 1.0;
k6 = a + b;
k7 = a + 1.0;;
k8 = a + 2.0;
pkm2 = 0.0;
qkm2 = 1.0;
pkm1 = 1.0;
qkm1 = 1.0;
z = x / (1.0 - x);
ans = 1.0;
r = 1.0;
n = 0;
thresh = 3.0 * MACHEP;
do {
xk = -(z * k1 * k2) / (k3 * k4);
pk = pkm1 + pkm2 * xk;
qk = qkm1 + qkm2 * xk;
pkm2 = pkm1;
pkm1 = pk;
qkm2 = qkm1;
qkm1 = qk;
xk = (z * k5 * k6) / (k7 * k8);
pk = pkm1 + pkm2 * xk;
qk = qkm1 + qkm2 * xk;
pkm2 = pkm1;
pkm1 = pk;
qkm2 = qkm1;
qkm1 = qk;
if (qk != 0)
r = pk / qk;
if (r != 0) {
t = fabs((ans - r) / r);
ans = r;
}
else
t = 1.0;
if (t < thresh)
goto cdone;
k1 += 1.0;
k2 -= 1.0;
k3 += 2.0;
k4 += 2.0;
k5 += 1.0;
k6 += 1.0;
k7 += 2.0;
k8 += 2.0;
if ((fabs(qk) + fabs(pk)) > big) {
pkm2 *= biginv;
pkm1 *= biginv;
qkm2 *= biginv;
qkm1 *= biginv;
}
if ((fabs(qk) < biginv) || (fabs(pk) < biginv)) {
pkm2 *= big;
pkm1 *= big;
qkm2 *= big;
qkm1 *= big;
}
}
while (++n < 300);
cdone:
return (ans);
}
/* Power series for incomplete beta integral.
* Use when b*x is small and x not too close to 1. */
static double pseries(a, b, x)
double a, b, x;
{
double s, t, u, v, n, t1, z, ai;
ai = 1.0 / a;
u = (1.0 - b) * x;
v = u / (a + 1.0);
t1 = v;
t = u;
n = 2.0;
s = 0.0;
z = MACHEP * ai;
while (fabs(v) > z) {
u = (n - b) * x / n;
t *= u;
v = t / (a + n);
s += v;
n += 1.0;
}
s += t1;
s += ai;
u = a * log(x);
if ((a + b) < MAXGAM && fabs(u) < MAXLOG) {
t = 1.0 / beta(a, b);
s = s * t * pow(x, a);
}
else {
t = -lbeta(a,b) + u + log(s);
if (t < MINLOG)
s = 0.0;
else
s = exp(t);
}
return (s);
}
|
2ffda957d77949e1b1400e97a590ae849beba3c9
|
2c052c996d4267623276a681308bf87ea7388f60
|
/tools/contgen.c
|
1a9a93e7c101b9387e1f2033b48c260519ddbbb2
|
[
"Apache-2.0"
] |
permissive
|
nanovms/nanos
|
17d3ce113b63c4370e40d291b8fd8fb9d943c02d
|
9085e091e5250fc58bf036591c8959e05fd7957f
|
refs/heads/master
| 2023-08-25T16:49:14.521701
| 2023-08-25T14:00:54
| 2023-08-25T14:14:13
| 115,159,616
| 2,055
| 131
|
Apache-2.0
| 2023-09-14T17:16:19
| 2017-12-23T00:25:34
|
C
|
UTF-8
|
C
| false
| false
| 3,500
|
c
|
contgen.c
|
#include <stdarg.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
/* Helper functions to ignore unused result (eliminate CC warning) */
static inline void igr(int x) {}
char *output;
int size;
int fill = 0;
int nleft, nright;
int twiggy;
void ins(char x)
{
if (fill == size) output = realloc(output, size *= 2);
output[fill++] = x;
}
void pint(int x)
{
if (x) {
pint(x/10);
ins('0' + (x%10));
}
}
void pi(char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
for (char *i = fmt; *i ; i++) {
int count = nright;
switch (*i) {
case '@':
if (twiggy) {
ins(',');
ins(' ');
}
break;
case '%':
{
int x = va_arg(ap, unsigned int);
if (x) pint(x); else ins('0');
}
break;
case '^':
count = nleft;
case '~':
{
char *subformat = va_arg(ap, char *);
if (count == 0)
break;
for (int i = 0 ; i < count; i++)
pi(subformat, i, i);
twiggy = 1;
break;
}
case '|':
ins('\\');
ins('\n');
break;
default: ins(*i);
}
}
va_end(ap);
}
#define p(...) {twiggy = 0; pi(__VA_ARGS__);}
void cblock()
{
p("#define CLOSURE_STRUCT_%_%(_rettype, _name^~)|", nleft, nright, ", _lt%, _ln%", ", _rt%, _rn%");
p("struct _closure_##_name {|");
p(" _rettype (*__apply)(struct _closure_##_name *~);|", ", _rt%");
p(" struct _closure_common __c;|");
for (int i = 0; i < nleft ; i++) p(" _lt% _ln%;|", i, i);
p("};\n\n");
p("#define CLOSURE_DECLARE_FUNCS_%_%(_rettype, _name^~)|", nleft, nright, ", _lt%, _ln%", ", _rt%, _rn%");
p("static _rettype (**_fill_##_name(u64 ctx, struct _closure_##_name* n, bytes s^))(void *~);|", ", _lt% l%", ", _rt%");
p("static _rettype _name(struct _closure_##_name *~);\n\n", ", _rt%");
p("#define CLOSURE_DEFINE_%_%(_rettype, _name^~)|", nleft, nright, ", _lt%, _ln%", ", _rt%, _rn%");
p("static _rettype (**_fill_##_name(u64 ctx, struct _closure_##_name* n, bytes s^))(void *~) {|", ", _lt% l%", ", _rt%");
p(" if (n != INVALID_ADDRESS) {|");
p(" n->__apply = _name;|");
p(" n->__c.name = #_name;|");
p(" n->__c.ctx = ctx;|");
p(" n->__c.size = s;|");
for (int i = 0; i < nleft ; i++) p(" n->_ln% = l%;|", i, i);
p(" }|");
p(" return (_rettype (**)(void *~))n;|", ", _rt%");
p("}|");
p("static _rettype _name(struct _closure_##_name *__self~)\n\n\n", ", _rt% _rn%");
p("#define CLOSURE_SIMPLE_DEFINE_%_%(_rettype, _name^~)|", nleft, nright, ", _lt%, _ln%", ", _rt%, _rn%");
p("typedef _rettype (**_name##_func)(void *~);|", ", _rt%");
p("static _rettype _name(struct _closure_##_name *__self~)\n\n\n", ", _rt% _rn%");
}
int main(int argc, char **argv)
{
if (argc < 3) {
char *p = strrchr(argv[0], '/');
if (p != NULL)
*p++ = '\0';
else
p = argv[0];
fprintf(stderr, "Usage: %s lc rc\n", p);
exit(1);
}
int lc = atoi(argv[1]);
int rc = atoi(argv[2]);
output = malloc(size = 1024);
for (nleft = 0; nleft < lc; nleft++)
for (nright = 0; nright < rc; nright++)
cblock();
igr(write(1, output, fill));
}
|
b9ccca91dca9c84f70a17b19a7c6af895c462cf3
|
673b3a4e8be3cc5e6997cd215cb5b9e2eaeca8b6
|
/core/cmd_thread.c
|
18802c9ff160212a3b9007722638f68bd9d1849d
|
[
"Apache-2.0"
] |
permissive
|
adamgreen/mri
|
c0bf4c1610003fd216fe506e8cb79a735442daa4
|
5d7e4dfcef0f5c59d78844bf63ae11136cd1656e
|
refs/heads/master
| 2023-08-19T18:22:30.128341
| 2023-08-14T20:56:29
| 2023-08-14T20:56:29
| 4,280,328
| 124
| 47
|
Apache-2.0
| 2023-07-01T07:40:30
| 2012-05-10T04:40:49
|
C
|
UTF-8
|
C
| false
| false
| 2,741
|
c
|
cmd_thread.c
|
/* Copyright 2020 Adam Green (https://github.com/adamgreen/)
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.
*/
/* Command handler for gdb commands related to threads. */
#include <core/mri.h>
#include <core/core.h>
#include <core/cmd_thread.h>
#include <core/platforms.h>
#include <core/try_catch.h>
/* Handle the 'H' command which is sent to switch thread register context.
Command Format: Hgxxxxxxxx
Response Format: OK
Where xxxxxxxx is the hexadecimal representation of the ID for the thread to use for future register read/write
commands.
*/
uint32_t HandleThreadContextCommand(void)
{
Buffer* pBuffer = GetBuffer();
__try
{
uint32_t threadId = 0;
MriContext* pContext = NULL;
char ch;
__throwing_func( ch = Buffer_ReadChar(pBuffer) );
if (ch != 'g')
{
setExceptionCode(invalidArgumentException);
break;
}
__throwing_func( threadId = Buffer_ReadUIntegerAsHex(pBuffer) );
pContext = Platform_RtosGetThreadContext(threadId);
if (pContext == NULL)
{
setExceptionCode(invalidArgumentException);
break;
}
SetContext(pContext);
PrepareStringResponse("OK");
}
__catch
{
PrepareStringResponse(MRI_ERROR_INVALID_ARGUMENT);
}
return 0;
}
/* Handle the 'T' command which is sent to see if a thread ID is still active.
Command Format: Txxxxxxxx
Response Format: OK if thread is still active.
E01 is thread isn't active.
Where xxxxxxxx is the hexadecimal representation of the thread ID.
*/
uint32_t HandleIsThreadActiveCommand(void)
{
Buffer* pBuffer = GetBuffer();
__try
{
uint32_t threadId = 0;
int isActive = 0;
__throwing_func( threadId = Buffer_ReadUIntegerAsHex(pBuffer) );
isActive = Platform_RtosIsThreadActive(threadId);
if (!isActive)
{
setExceptionCode(invalidArgumentException);
break;
}
PrepareStringResponse("OK");
}
__catch
{
PrepareStringResponse(MRI_ERROR_INVALID_ARGUMENT);
}
return 0;
}
|
641d78fbcb5edea02802957e90c6c4b031b62dd8
|
e65a4dbfbfb0e54e59787ba7741efee12f7687f3
|
/mail/xmailwatcher/files/patch-box.c
|
dfb562ea01f31c38995f9ec4a62d22645fbc19af
|
[
"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
| 459
|
c
|
patch-box.c
|
--- box.c.orig Sat Feb 3 18:13:00 2001
+++ box.c Sat Feb 3 18:13:50 2001
@@ -31,7 +31,7 @@
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
-#include <sys/dir.h>
+#include <dirent.h>
#include <X11/Xos.h>
/* MIME processing */
@@ -235,7 +235,7 @@
int n, i, tally;
char oneFrom[160];
char *pos;
- char filename[PATH_MAX];
+ char filename[FILENAME_MAX];
if (flags & BOX_DEBUG) (void) printf("MHparseMailbox(%s)\n", mailbox);
|
15bbf4926c347271a88ec4aa59c84744eb677721
|
376e1818d427b5e4d32fa6dd6c7b71e9fd88afdb
|
/devel/devIL/patches/patch-src-IL_include_altivec__common.h
|
1313a84f6e2f6196152a89db92e9737620149c9c
|
[] |
no_license
|
NetBSD/pkgsrc
|
a0732c023519650ef821ab89c23ab6ab59e25bdb
|
d042034ec4896cc5b47ed6f2e5b8802d9bc5c556
|
refs/heads/trunk
| 2023-09-01T07:40:12.138283
| 2023-09-01T05:25:19
| 2023-09-01T05:25:19
| 88,439,572
| 321
| 138
| null | 2023-07-12T22:34:14
| 2017-04-16T20:04:15
| null |
UTF-8
|
C
| false
| false
| 412
|
h
|
patch-src-IL_include_altivec__common.h
|
$NetBSD: patch-src-IL_include_altivec__common.h,v 1.1 2022/09/24 21:06:42 he Exp $
Use <altivec.h> if __ALTIVEC__ is defined.
--- ./src-IL/include/altivec_common.h.orig 2009-03-08 07:10:08.000000000 +0000
+++ ./src-IL/include/altivec_common.h
@@ -8,6 +8,10 @@
#include "il_internal.h"
+#ifdef __ALTIVEC__
+#include <altivec.h>
+#endif
+
#ifdef ALTIVEC_GCC
#ifndef ALTIVEC_COMMON
#define ALTIVEC_COMMON
|
b0cebc24541a21bb2edd3f1f270775dd2d040656
|
690dfa54baa46dd17cda7bb0651db2e87159f90c
|
/examples/dynamic-library/dll/ui/resource.h
|
84cf0ca309a5f24b332be53796bf9d726cd6e857
|
[
"MIT"
] |
permissive
|
whtiehack/wingui
|
846bafe006ab2684852b4d91e68c2967c543d57f
|
7aaab1687367287fd94e35f7f1f6d440e38520ea
|
refs/heads/master
| 2023-07-23T14:37:19.476876
| 2023-07-13T07:16:44
| 2023-07-13T07:16:44
| 206,737,581
| 127
| 28
|
MIT
| 2023-07-13T06:39:30
| 2019-09-06T07:24:16
|
Go
|
UTF-8
|
C
| false
| false
| 211
|
h
|
resource.h
|
#ifndef IDC_STATIC
#define IDC_STATIC (-1)
#endif
#define IDD_DIALOG1 100
#define IDB_OK 40000
#define IDB_CANCEL 40001
|
0896e15c2cc06e941ca5e1b9e0d60f97446f031e
|
0ba9681b235b377b3f57d52532ab7212d4d4cd8a
|
/examples/simon-speck/speck.c
|
ee2676e479f25706f13f8aef329ac3c2cd9f4e23
|
[
"BSD-3-Clause",
"GPL-3.0-only",
"MIT",
"GPL-2.0-only"
] |
permissive
|
GaloisInc/saw-script
|
d9a3eb7b05c1bcbcc319987223cd53b903b55b5d
|
79ddd800bec59528958ed6d7593304e2b17b7dfb
|
refs/heads/master
| 2023-09-01T09:47:31.415255
| 2023-08-30T11:26:08
| 2023-08-30T11:26:08
| 34,082,065
| 458
| 82
|
BSD-3-Clause
| 2023-09-14T16:23:09
| 2015-04-16T21:39:32
|
Haskell
|
UTF-8
|
C
| false
| false
| 7,617
|
c
|
speck.c
|
/*
* Speck cipher implementation and testing code
* (c) 2013 by Sebastian Gesemann
*
* Speck is a family of lightweight block ciphers designed by a team
* of NSA members (see http://eprint.iacr.org/2013/404.pdf )
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
// Configuration / Selecting a member from the Speck family
#ifndef N
#define N 32 // bits per word, only 32 and 64 are supported
#endif
#ifndef M
#define M (144/N) // words per key
#endif
#ifndef R // rounds per en-/decryption
#if N==32
#define R (23+M)
#elif N==64
#define R (30+M)
#else
#error "number of rounds not given"
#endif
#endif
// Checking config parameters
#if N==32
typedef uint32_t word_t;
#elif N==64
typedef uint64_t word_t;
#else
#error "only word sizes 32 and 64 are supported"
#endif
#if M<2 || M>4 || (M==2 && N==32)
#error "invalid number of key words"
#endif
#if R<M
#error "too few rounds"
#endif
// Speck key schedule, encryption, decryption
#define LCS(x,n) (((x) << (n)) | ((x) >> (N-(n))))
#define RCS(x,n) (((x) >> (n)) | ((x) << (N-(n))))
#if N>=24
#define ROUND(x,y,k) (x=RCS(x,8), x+=y, x^=k, y=LCS(y,3), y^=x)
#define INV_ROUND(x,y,k) (y^=x, y=RCS(y,3), x^=k, x-=y, x=LCS(x,8))
#else
#error "cyclic shifts in round function are incorrect for this word size"
#endif
/// expands a key of M words into R round keys in-place
void speck_keyexpand(word_t K[])
{
word_t tmp[M], *p;
memcpy(tmp,K,sizeof tmp);
// K[0] stays the same
for (int i=0; i<(R-1);) {
p = tmp + (1+(i%(M-1)));
ROUND(*p,tmp[0],i);
++i;
K[i] = tmp[0];
}
}
/// encrypts block in-place given the round keys
void speck_encrypt(word_t io[2], word_t xK[])
{
speck_keyexpand(xK);
for (int i=0; i<R; ++i) {
ROUND(io[1],io[0],xK[i]);
}
}
/// decrypts block in-place given the round keys
void speck_decrypt(word_t io[2], word_t xK[])
{
speck_keyexpand(xK);
for (int i=R; i-->0;) {
INV_ROUND(io[1],io[0],xK[i]);
}
}
// Test program ...
#ifndef SAW
void display(int n, const word_t data[])
{
static const char hex[] = "0123456789abcdef";
char temp[2+((N+3)/4)] = " ";
for (int i=n; i-->0;) {
word_t tmp = data[i];
for (int k=0; k<((N+3)/4); ++k) {
temp[((N+3)/4)-k] = hex[tmp & 0xF];
tmp >>= 4;
}
printf("%s",temp+(i+1==n));
}
puts("");
}
/// tests the given test vector
/// @return 0=ok, 1=encryption error, 2=decryption error
#if N==32 && M==4
int test_test_vector(void)
{
static const word_t p[2] = {0x7475432d, 0x3b726574};
static const word_t c[2] = {0x454e028b, 0x8c6fa548};
word_t k[R] = {0x03020100, 0x0b0a0908, 0x13121110, 0x1b1a1918};
word_t k2[R] = {0x03020100, 0x0b0a0908, 0x13121110, 0x1b1a1918};
word_t io[] = {p[0],p[1]};
speck_encrypt(io,k);
if (io[0]!=c[0] || io[1]!=c[1]) {
puts("encryption error");
return 1;
}
puts("encryption ok");
speck_decrypt(io,k2);
if (io[0]!=p[0] || io[1]!=p[1]) {
puts("decryption error");
return 2;
}
puts("decryption ok");
return 0;
}
//[0x0F0E0D0C0B0A0908, 0x0706050403020100] (0x6C61766975716520, 0x7469206564616D20) == (0xA65D985179783265, 0x7860FEDF5C570D18)
#else
int test_test_vector(void)
{
static const word_t p[2] = {0x7469206564616D20ULL, 0x6C61766975716520ULL};
static const word_t c[2] = {0x7860FEDF5C570D18ULL, 0xA65D985179783265ULL};
word_t k[R] = {0x0706050403020100ULL, 0x0F0E0D0C0B0A0908ULL};
word_t k2[R] = {0x0706050403020100ULL, 0x0F0E0D0C0B0A0908ULL};
word_t io[] = {p[0],p[1]};
speck_encrypt(io,k);
if (io[0]!=c[0] || io[1]!=c[1]) {
puts("encryption error");
return 1;
}
puts("encryption ok");
speck_decrypt(io,k2);
if (io[0]!=p[0] || io[1]!=p[1]) {
puts("decryption error");
return 2;
}
puts("decryption ok");
return 0;
}
#endif
#if N==32
int count_set_bits(word_t t)
{
t = ((t & 0xAAAAAAAA) >> 1) + (t & 0x55555555);
t = ((t & 0xCCCCCCCC) >> 2) + (t & 0x33333333);
t = ((t & 0xF0F0F0F0) >> 4) + (t & 0x0F0F0F0F);
t += t >> 16;
t += t >> 8;
return t & 0xFF;
}
#elif N==64
int count_set_bits(word_t t)
{
t = ((t & 0xAAAAAAAAAAAAAAAAu) >> 1) + (t & 0x5555555555555555u);
t = ((t & 0xCCCCCCCCCCCCCCCCu) >> 2) + (t & 0x3333333333333333u);
t = ((t & 0xF0F0F0F0F0F0F0F0u) >> 4) + (t & 0x0F0F0F0F0F0F0F0Fu);
t += t >> 32;
t += t >> 16;
t += t >> 8;
return t & 0xFF;
}
#endif
word_t rand_word(void)
{
word_t result = 0;
#if N % 8
#error "expected word size to be dividable by 8"
#endif
for (int i=0; i<N; i+=8) {
result = (result << 8) | (rand() & 0xFFu);
}
return result;
}
static int test_confusion_once(void)
{
word_t kA[R];
word_t kB[R];
word_t ioA[2];
word_t ioB[2];
for (int i=0; i<M; ++i)
kA[i] = kB[i] = rand_word();
#if N & (N-1)
#error "I actually expect N to be a power of two"
#else
kB[rand() % M] ^= ((word_t)1u) << (rand() & (N-1));
#endif
for (int i=0; i<2; ++i) {
ioA[i] = ioB[i] = rand_word();
}
speck_encrypt(ioA,kA);
speck_encrypt(ioB,kB);
int result = 0;
for (int i=0; i<2; ++i)
result += count_set_bits(ioA[i]^ioB[i]);
return result;
}
int test_diffusion_once(void)
{
word_t k[R];
word_t k2[R];
word_t ioA[2];
word_t ioB[2];
for (int i=0; i<M; ++i)
k2[i] = k[i] = rand_word();
for (int i=0; i<2; ++i) {
ioA[i] = ioB[i] = rand_word();
}
#if N & (N-1)
#error "I actually expect N to be a power of two"
#else
ioB[rand()&1] ^= ((word_t)1u) << (rand() & (N-1));
#endif
speck_encrypt(ioA,k);
speck_encrypt(ioB,k2);
int result = 0;
for (int i=0; i<2; ++i)
result += count_set_bits(ioA[i]^ioB[i]);
return result;
}
/// estimates the mean and variance of a distribution
/// from a given histogram
void compute_mean_and_vari_from_hist(
int slots, const unsigned long counts[],
double *pmean, double *pvari)
{
unsigned long long sum0 = 0;
unsigned long long sum1 = 0;
for (int i=0; i<slots; ++i) {
unsigned long long tmp = counts[i];
sum0 += tmp;
sum1 += tmp * i;
}
*pmean = (double)sum1 / (double)sum0;
double sum2 = 0;
for (int i=0; i<slots; ++i) {
unsigned long tmp = counts[i];
double delta = i - *pmean;
sum2 += tmp * delta*delta;
}
*pvari = sum2/(sum0-1);
}
void test(const char* what, int (*pfun)(void))
{
unsigned long histogram[N*2+1] = {0};
for (unsigned long pass=0; pass<1222333; ++pass) {
int hd = pfun();
if (0<=hd && hd<=(N*2)) {
histogram[hd]++;
} else {
puts("unexpected output difference, internal error");
abort();
}
}
double m, v;
compute_mean_and_vari_from_hist(N*2+1,histogram,&m,&v);
printf("Speck-%d-%d [nr=%d], %s test: mean=%f, variance=%f\n",2*N,M*N,R,what,m,v);
}
int main(void)
{
srand(time(0));
test("confusion",test_confusion_once);
test("diffusion",test_diffusion_once);
return test_test_vector();
}
#endif
|
131eb9546dd0a2af25d44b527ccd03d5e5e1b0ae
|
28d0f8c01599f8f6c711bdde0b59f9c2cd221203
|
/sys/external/bsd/drm2/dist/drm/amd/display/dc/dcn21/dcn21_link_encoder.h
|
280e48bd02715b2909ee096e77157d108499799c
|
[] |
no_license
|
NetBSD/src
|
1a9cbc22ed778be638b37869ed4fb5c8dd616166
|
23ee83f7c0aea0777bd89d8ebd7f0cde9880d13c
|
refs/heads/trunk
| 2023-08-31T13:24:58.105962
| 2023-08-27T15:50:47
| 2023-08-27T15:50:47
| 88,439,547
| 656
| 348
| null | 2023-07-20T20:07:24
| 2017-04-16T20:03:43
| null |
UTF-8
|
C
| false
| false
| 4,949
|
h
|
dcn21_link_encoder.h
|
/* $NetBSD: dcn21_link_encoder.h,v 1.2 2021/12/18 23:45:03 riastradh Exp $ */
/*
* Copyright 2012-15 Advanced Micro Devices, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, 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 COPYRIGHT HOLDER(S) OR AUTHOR(S) 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.
*
* Authors: AMD
*
*/
#ifndef __DC_LINK_ENCODER__DCN21_H__
#define __DC_LINK_ENCODER__DCN21_H__
#include "dcn20/dcn20_link_encoder.h"
struct dcn21_link_encoder {
struct dcn10_link_encoder enc10;
struct dpcssys_phy_seq_cfg phy_seq_cfg;
};
#define DPCS_DCN21_MASK_SH_LIST(mask_sh)\
DPCS_DCN2_MASK_SH_LIST(mask_sh),\
LE_SF(RDPCSTX0_RDPCSTX_PHY_FUSE3, RDPCS_PHY_TX_VBOOST_LVL, mask_sh),\
LE_SF(RDPCSTX0_RDPCSTX_PHY_FUSE2, RDPCS_PHY_DP_MPLLB_CP_PROP_GS, mask_sh),\
LE_SF(RDPCSTX0_RDPCSTX_PHY_FUSE0, RDPCS_PHY_RX_VREF_CTRL, mask_sh),\
LE_SF(RDPCSTX0_RDPCSTX_PHY_FUSE0, RDPCS_PHY_DP_MPLLB_CP_INT_GS, mask_sh),\
LE_SF(RDPCSTX0_RDPCSTX_DMCU_DPALT_DIS_BLOCK_REG, RDPCS_DMCU_DPALT_DIS_BLOCK_REG, mask_sh),\
LE_SF(RDPCSTX0_RDPCSTX_PHY_CNTL15, RDPCS_PHY_SUP_PRE_HP, mask_sh),\
LE_SF(RDPCSTX0_RDPCSTX_PHY_CNTL15, RDPCS_PHY_DP_TX0_VREGDRV_BYP, mask_sh),\
LE_SF(RDPCSTX0_RDPCSTX_PHY_CNTL15, RDPCS_PHY_DP_TX1_VREGDRV_BYP, mask_sh),\
LE_SF(RDPCSTX0_RDPCSTX_PHY_CNTL15, RDPCS_PHY_DP_TX2_VREGDRV_BYP, mask_sh),\
LE_SF(RDPCSTX0_RDPCSTX_PHY_CNTL15, RDPCS_PHY_DP_TX3_VREGDRV_BYP, mask_sh),\
LE_SF(RDPCSTX0_RDPCSTX_PHY_CNTL6, RDPCS_PHY_DPALT_DP4, mask_sh),\
LE_SF(RDPCSTX0_RDPCSTX_PHY_CNTL6, RDPCS_PHY_DPALT_DISABLE, mask_sh),\
LE_SF(RDPCSTX0_RDPCSTX_PHY_FUSE0, RDPCS_PHY_DP_TX0_EQ_MAIN, mask_sh),\
LE_SF(RDPCSTX0_RDPCSTX_PHY_FUSE0, RDPCS_PHY_DP_TX0_EQ_PRE, mask_sh),\
LE_SF(RDPCSTX0_RDPCSTX_PHY_FUSE0, RDPCS_PHY_DP_TX0_EQ_POST, mask_sh),\
LE_SF(RDPCSTX0_RDPCSTX_PHY_FUSE1, RDPCS_PHY_DP_TX1_EQ_MAIN, mask_sh),\
LE_SF(RDPCSTX0_RDPCSTX_PHY_FUSE1, RDPCS_PHY_DP_TX1_EQ_PRE, mask_sh),\
LE_SF(RDPCSTX0_RDPCSTX_PHY_FUSE1, RDPCS_PHY_DP_TX1_EQ_POST, mask_sh),\
LE_SF(RDPCSTX0_RDPCSTX_PHY_FUSE2, RDPCS_PHY_DP_TX2_EQ_MAIN, mask_sh),\
LE_SF(RDPCSTX0_RDPCSTX_PHY_FUSE2, RDPCS_PHY_DP_TX2_EQ_PRE, mask_sh),\
LE_SF(RDPCSTX0_RDPCSTX_PHY_FUSE2, RDPCS_PHY_DP_TX2_EQ_POST, mask_sh),\
LE_SF(RDPCSTX0_RDPCSTX_PHY_FUSE3, RDPCS_PHY_DP_TX3_EQ_MAIN, mask_sh),\
LE_SF(RDPCSTX0_RDPCSTX_PHY_FUSE3, RDPCS_PHY_DCO_FINETUNE, mask_sh),\
LE_SF(RDPCSTX0_RDPCSTX_PHY_FUSE3, RDPCS_PHY_DCO_RANGE, mask_sh),\
LE_SF(RDPCSTX0_RDPCSTX_PHY_FUSE3, RDPCS_PHY_DP_TX3_EQ_PRE, mask_sh),\
LE_SF(RDPCSTX0_RDPCSTX_PHY_FUSE3, RDPCS_PHY_DP_TX3_EQ_POST, mask_sh),\
LE_SF(DCIO_SOFT_RESET, UNIPHYA_SOFT_RESET, mask_sh),\
LE_SF(DCIO_SOFT_RESET, UNIPHYB_SOFT_RESET, mask_sh),\
LE_SF(DCIO_SOFT_RESET, UNIPHYC_SOFT_RESET, mask_sh),\
LE_SF(DCIO_SOFT_RESET, UNIPHYD_SOFT_RESET, mask_sh),\
LE_SF(DCIO_SOFT_RESET, UNIPHYE_SOFT_RESET, mask_sh)
#define DPCS_DCN21_REG_LIST(id) \
DPCS_DCN2_REG_LIST(id),\
SRI(RDPCSTX_PHY_CNTL15, RDPCSTX, id),\
SRI(RDPCSTX_DMCU_DPALT_DIS_BLOCK_REG, RDPCSTX, id)
#define LINK_ENCODER_MASK_SH_LIST_DCN21(mask_sh)\
LINK_ENCODER_MASK_SH_LIST_DCN20(mask_sh),\
LE_SF(UNIPHYA_CHANNEL_XBAR_CNTL, UNIPHY_CHANNEL0_XBAR_SOURCE, mask_sh),\
LE_SF(UNIPHYA_CHANNEL_XBAR_CNTL, UNIPHY_CHANNEL1_XBAR_SOURCE, mask_sh),\
LE_SF(UNIPHYA_CHANNEL_XBAR_CNTL, UNIPHY_CHANNEL2_XBAR_SOURCE, mask_sh),\
LE_SF(UNIPHYA_CHANNEL_XBAR_CNTL, UNIPHY_CHANNEL3_XBAR_SOURCE, mask_sh), \
SRI(RDPCSTX_PHY_FUSE2, RDPCSTX, id), \
SRI(RDPCSTX_PHY_FUSE3, RDPCSTX, id), \
SR(RDPCSTX0_RDPCSTX_SCRATCH)
void dcn21_link_encoder_enable_dp_output(
struct link_encoder *enc,
const struct dc_link_settings *link_settings,
enum clock_source_id clock_source);
void dcn21_link_encoder_construct(
struct dcn21_link_encoder *enc21,
const struct encoder_init_data *init_data,
const struct encoder_feature_support *enc_features,
const struct dcn10_link_enc_registers *link_regs,
const struct dcn10_link_enc_aux_registers *aux_regs,
const struct dcn10_link_enc_hpd_registers *hpd_regs,
const struct dcn10_link_enc_shift *link_shift,
const struct dcn10_link_enc_mask *link_mask);
#endif
|
56975a26c34845b29b2a56dfbb09b59a15d33654
|
aeef4d7bab4ca441fbecc2823815e9f94cb4563b
|
/src/utils/lzssopt.h
|
aefcba80f5a27f236cb96833f60dc47cf82ef382
|
[
"BSD-2-Clause"
] |
permissive
|
FreeFalcon/freefalcon-central
|
8fc80b6d82eab44ce314a39860e6ee8e6f5ee71a
|
c28d807183ab447ef6a801068aa3769527d55deb
|
refs/heads/develop
| 2021-01-23T20:49:45.844619
| 2014-10-30T18:32:35
| 2014-10-30T18:32:35
| 7,615,342
| 133
| 90
| null | 2014-10-30T18:32:35
| 2013-01-15T00:02:23
|
C++
|
UTF-8
|
C
| false
| false
| 232
|
h
|
lzssopt.h
|
#ifndef LZSSOPT_H
#define LZSSOPT_H
// Undefine C_LINKAGE if you want to use C++
#define C_LINKAGE
// Undefine INCLUDE_FILE_COMPRESSION if you don't need the file io compression routines
//#define INCLUDE_FILE_COMPRESSION
#endif
|
ce7b399dc330fad7ff48307a75e5b63fce693020
|
e9878c0204b6ee2442ee86beb9d48c61a52b357f
|
/Pods/Headers/Private/PureCamera/UIImage+CropRotate.h
|
eacf23f250d60c7d69427e4417673ee27f47cd89
|
[
"MIT"
] |
permissive
|
Jacke-xu/WYBasisKit
|
5c0a95e2ef5c33b9eaf5c3844dda2d45d72c9218
|
e4d9d47efb511bddbaf0acaf4dc91f14138c99e3
|
refs/heads/master
| 2021-09-27T21:57:49.195146
| 2021-09-16T05:32:17
| 2021-09-16T05:32:17
| 135,020,912
| 213
| 40
| null | null | null | null |
UTF-8
|
C
| false
| false
| 51
|
h
|
UIImage+CropRotate.h
|
../../../PureCamera/PureCamera/UIImage+CropRotate.h
|
b1d17d527ff4b2f326e0893637388a08a6c2e3be
|
5d2934b38bb87b806d5ef36f7e61cf72d4064a20
|
/Cfg/Template/app_cfg.h
|
0d380bf074dccdbd47031aeb125fcc2b6889cd57
|
[
"Apache-2.0",
"LicenseRef-scancode-proprietary-license",
"LicenseRef-scancode-warranty-disclaimer",
"LicenseRef-scancode-free-unknown"
] |
permissive
|
weston-embedded/uC-OS2
|
83cae77ff97bb921c5fef81f827884eab405eaab
|
bfc6120f20cb27a927a9fc5dd667f9e455495777
|
refs/heads/develop
| 2023-01-10T09:41:16.763300
| 2023-01-05T18:18:13
| 2023-01-05T18:18:13
| 243,857,957
| 347
| 123
|
Apache-2.0
| 2023-01-12T22:57:11
| 2020-02-28T21:30:55
|
C
|
UTF-8
|
C
| false
| false
| 3,742
|
h
|
app_cfg.h
|
/*
*********************************************************************************************************
* EXAMPLE CODE
*
* This file is provided as an example on how to use Micrium products.
*
* Please feel free to use any application code labeled as 'EXAMPLE CODE' in
* your application products. Example code may be used as is, in whole or in
* part, or may be used as a reference only. This file can be modified as
* required to meet the end-product requirements.
*
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*
* APPLICATION CONFIGURATION
*
* EXAMPLE CODE
*
* Filename : app_cfg.h
*********************************************************************************************************
*/
#ifndef _APP_CFG_H_
#define _APP_CFG_H_
/*
*********************************************************************************************************
* INCLUDE FILES
*********************************************************************************************************
*/
#include <stdarg.h>
#include <stdio.h>
/*
*********************************************************************************************************
* MODULE ENABLE / DISABLE
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* TASK PRIORITIES
*********************************************************************************************************
*/
#define APP_CFG_STARTUP_TASK_PRIO 3u
#define OS_TASK_TMR_PRIO (OS_LOWEST_PRIO - 2u)
/*
*********************************************************************************************************
* TASK STACK SIZES
* Size of the task stacks (# of OS_STK entries)
*********************************************************************************************************
*/
#define APP_CFG_STARTUP_TASK_STK_SIZE 128u
/*
*********************************************************************************************************
* TRACE / DEBUG CONFIGURATION
*********************************************************************************************************
*/
#ifndef TRACE_LEVEL_OFF
#define TRACE_LEVEL_OFF 0u
#endif
#ifndef TRACE_LEVEL_INFO
#define TRACE_LEVEL_INFO 1u
#endif
#ifndef TRACE_LEVEL_DBG
#define TRACE_LEVEL_DBG 2u
#endif
#define APP_TRACE_LEVEL TRACE_LEVEL_OFF
#define APP_TRACE printf
#define APP_TRACE_INFO(x) ((APP_TRACE_LEVEL >= TRACE_LEVEL_INFO) ? (void)(APP_TRACE x) : (void)0)
#define APP_TRACE_DBG(x) ((APP_TRACE_LEVEL >= TRACE_LEVEL_DBG) ? (void)(APP_TRACE x) : (void)0)
/*
*********************************************************************************************************
* MODULE END
*********************************************************************************************************
*/
#endif /* End of module include. */
|
cbc34c6c6beaf5efa6cdb5182eedbb94bfc1a85e
|
88ae8695987ada722184307301e221e1ba3cc2fa
|
/third_party/libei/include/linux/gigaset_dev.h
|
279551af8ebf284812dc1feb568f1712f03ae3f8
|
[
"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
| 1,442
|
h
|
gigaset_dev.h
|
/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
/*
* interface to user space for the gigaset driver
*
* Copyright (c) 2004 by Hansjoerg Lipp <hjlipp@web.de>
*
* =====================================================================
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
* =====================================================================
*/
#ifndef GIGASET_INTERFACE_H
#define GIGASET_INTERFACE_H
#include <linux/ioctl.h>
/* The magic IOCTL value for this interface. */
#define GIGASET_IOCTL 0x47
/* enable/disable device control via character device (lock out ISDN subsys) */
#define GIGASET_REDIR _IOWR(GIGASET_IOCTL, 0, int)
/* enable adapter configuration mode (M10x only) */
#define GIGASET_CONFIG _IOWR(GIGASET_IOCTL, 1, int)
/* set break characters (M105 only) */
#define GIGASET_BRKCHARS _IOW(GIGASET_IOCTL, 2, unsigned char[6])
/* get version information selected by arg[0] */
#define GIGASET_VERSION _IOWR(GIGASET_IOCTL, 3, unsigned[4])
/* values for GIGASET_VERSION arg[0] */
#define GIGVER_DRIVER 0 /* get driver version */
#define GIGVER_COMPAT 1 /* get interface compatibility version */
#define GIGVER_FWBASE 2 /* get base station firmware version */
#endif
|
e221edad1f106e1de5eb757ccb7e774ff1f02245
|
693bd39eb66eade67997bc608fe84e76e66eeec2
|
/mpp/hal/vpu/h264e/hal_h264e_vepu2_v2.c
|
94568a91aaa9ce02165a769647938920d8b5330e
|
[] |
permissive
|
HermanChen/mpp
|
6a1751777b120b764f86e0f34975231054a3c262
|
0af9b5becc76c4685831214808e124e65543297b
|
refs/heads/develop
| 2023-08-17T07:17:49.489974
| 2023-07-31T08:26:14
| 2023-08-11T07:38:17
| 71,088,248
| 139
| 79
|
Apache-2.0
| 2023-03-08T09:44:01
| 2016-10-17T01:13:37
|
C
|
UTF-8
|
C
| false
| false
| 27,079
|
c
|
hal_h264e_vepu2_v2.c
|
/*
* Copyright 2015 Rockchip Electronics Co. LTD
*
* 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.
*/
#define MODULE_TAG "hal_h264e_vepu2_v2"
#include <string.h>
#include "mpp_env.h"
#include "mpp_mem.h"
#include "mpp_frame.h"
#include "mpp_common.h"
#include "mpp_device.h"
#include "mpp_rc.h"
#include "mpp_enc_hal.h"
#include "h264e_debug.h"
#include "h264e_sps.h"
#include "h264e_pps.h"
#include "h264e_slice.h"
#include "hal_h264e_debug.h"
#include "hal_h264e_vpu_tbl.h"
#include "hal_h264e_vepu_v2.h"
#include "hal_h264e_stream_amend.h"
#include "hal_h264e_vepu2_reg_tbl.h"
typedef struct HalH264eVepu2Ctx_t {
MppEncCfgSet *cfg;
MppDev dev;
RK_S32 frame_cnt;
/* buffers management */
HalH264eVepuBufs hw_bufs;
/* preprocess config */
HalH264eVepuPrep hw_prep;
/* input / recon / refer address config */
HalH264eVepuAddr hw_addr;
VepuOffsetCfg hw_offset;
/* macroblock ratecontrol config */
HalH264eVepuMbRc hw_mbrc;
/* syntax for input from enc_impl */
RK_U32 updated;
H264eSps *sps;
H264ePps *pps;
H264eSlice *slice;
H264eFrmInfo *frms;
H264eReorderInfo *reorder;
H264eMarkingInfo *marking;
H264ePrefixNal *prefix;
/* special TSVC stream header fixup */
HalH264eVepuStreamAmend amend;
/* vepu2 macroblock ratecontrol context */
HalH264eVepuMbRcCtx rc_ctx;
H264eVpu2RegSet regs_set;
H264eVpu2RegSet regs_get;
} HalH264eVepu2Ctx;
static MPP_RET hal_h264e_vepu2_deinit_v2(void *hal)
{
HalH264eVepu2Ctx *p = (HalH264eVepu2Ctx *)hal;
hal_h264e_dbg_func("enter %p\n", p);
if (p->dev) {
mpp_dev_deinit(p->dev);
p->dev = NULL;
}
h264e_vepu_buf_deinit(&p->hw_bufs);
if (p->rc_ctx) {
h264e_vepu_mbrc_deinit(p->rc_ctx);
p->rc_ctx = NULL;
}
h264e_vepu_stream_amend_deinit(&p->amend);
hal_h264e_dbg_func("leave %p\n", p);
return MPP_OK;
}
static MPP_RET hal_h264e_vepu2_init_v2(void *hal, MppEncHalCfg *cfg)
{
HalH264eVepu2Ctx *p = (HalH264eVepu2Ctx *)hal;
MPP_RET ret = MPP_OK;
hal_h264e_dbg_func("enter %p\n", p);
p->cfg = cfg->cfg;
/* update output to MppEnc */
cfg->type = VPU_CLIENT_VEPU2;
ret = mpp_dev_init(&cfg->dev, cfg->type);
if (ret) {
mpp_err_f("mpp_dev_init failed ret: %d\n", ret);
goto DONE;
}
p->dev = cfg->dev;
ret = h264e_vepu_buf_init(&p->hw_bufs);
if (ret) {
mpp_err_f("init vepu buffer failed ret: %d\n", ret);
goto DONE;
}
ret = h264e_vepu_mbrc_init(&p->rc_ctx, &p->hw_mbrc);
if (ret) {
mpp_err_f("init mb rate control failed ret: %d\n", ret);
goto DONE;
}
/* create buffer to TSVC stream */
h264e_vepu_stream_amend_init(&p->amend);
DONE:
if (ret)
hal_h264e_vepu2_deinit_v2(hal);
hal_h264e_dbg_func("leave %p\n", p);
return ret;
}
static RK_U32 update_vepu2_syntax(HalH264eVepu2Ctx *ctx, MppSyntax *syntax)
{
H264eSyntaxDesc *desc = syntax->data;
RK_S32 syn_num = syntax->number;
RK_U32 updated = 0;
RK_S32 i;
for (i = 0; i < syn_num; i++, desc++) {
switch (desc->type) {
case H264E_SYN_CFG : {
hal_h264e_dbg_detail("update cfg");
ctx->cfg = desc->p;
} break;
case H264E_SYN_SPS : {
hal_h264e_dbg_detail("update sps");
ctx->sps = desc->p;
} break;
case H264E_SYN_PPS : {
hal_h264e_dbg_detail("update pps");
ctx->pps = desc->p;
} break;
case H264E_SYN_DPB : {
hal_h264e_dbg_detail("update dpb");
} break;
case H264E_SYN_SLICE : {
hal_h264e_dbg_detail("update slice");
ctx->slice = desc->p;
} break;
case H264E_SYN_FRAME : {
hal_h264e_dbg_detail("update frames");
ctx->frms = desc->p;
} break;
case H264E_SYN_PREFIX : {
hal_h264e_dbg_detail("update prefix nal");
ctx->prefix = desc->p;
} break;
default : {
mpp_log_f("invalid syntax type %d\n", desc->type);
} break;
}
updated |= SYN_TYPE_FLAG(desc->type);
}
return updated;
}
static MPP_RET hal_h264e_vepu2_get_task_v2(void *hal, HalEncTask *task)
{
HalH264eVepu2Ctx *ctx = (HalH264eVepu2Ctx *)hal;
RK_U32 updated = update_vepu2_syntax(ctx, &task->syntax);
MppEncPrepCfg *prep = &ctx->cfg->prep;
HalH264eVepuPrep *hw_prep = &ctx->hw_prep;
HalH264eVepuAddr *hw_addr = &ctx->hw_addr;
HalH264eVepuBufs *hw_bufs = &ctx->hw_bufs;
VepuOffsetCfg *hw_offset = &ctx->hw_offset;
H264eFrmInfo *frms = ctx->frms;
hal_h264e_dbg_func("enter %p\n", hal);
if (updated & SYN_TYPE_FLAG(H264E_SYN_CFG)) {
h264e_vepu_buf_set_frame_size(hw_bufs, prep->width, prep->height);
/* preprocess setup */
h264e_vepu_prep_setup(hw_prep, prep);
h264e_vepu_mbrc_setup(ctx->rc_ctx, ctx->cfg);
}
if (updated & SYN_TYPE_FLAG(H264E_SYN_SLICE)) {
H264eSlice *slice = ctx->slice;
h264e_vepu_buf_set_cabac_idc(hw_bufs, slice->cabac_init_idc);
}
h264e_vepu_prep_get_addr(hw_prep, task->input, &hw_addr->orig);
MppBuffer recn = h264e_vepu_buf_get_frame_buffer(hw_bufs, frms->curr_idx);
MppBuffer refr = h264e_vepu_buf_get_frame_buffer(hw_bufs, frms->refr_idx);
hw_addr->recn[0] = mpp_buffer_get_fd(recn);
hw_addr->refr[0] = mpp_buffer_get_fd(refr);
hw_addr->recn[1] = hw_addr->recn[0];
hw_addr->refr[1] = hw_addr->refr[0];
hw_offset->fmt = prep->format;
hw_offset->width = prep->width;
hw_offset->height = prep->height;
hw_offset->hor_stride = prep->hor_stride;
hw_offset->ver_stride = prep->ver_stride;
hw_offset->offset_x = mpp_frame_get_offset_x(task->frame);
hw_offset->offset_y = mpp_frame_get_offset_y(task->frame);
get_vepu_offset_cfg(hw_offset);
h264e_vepu_stream_amend_config(&ctx->amend, task->packet, ctx->cfg,
ctx->slice, ctx->prefix);
hal_h264e_dbg_func("leave %p\n", hal);
return MPP_OK;
}
static RK_S32 setup_output_packet(HalH264eVepu2Ctx *ctx, RK_U32 *reg, MppBuffer buf, RK_U32 offset)
{
RK_U32 offset8 = offset & (~0x7);
RK_S32 fd = mpp_buffer_get_fd(buf);
RK_U32 hdr_rem_msb = 0;
RK_U32 hdr_rem_lsb = 0;
RK_U32 limit = 0;
if (offset) {
RK_U8 *buf32 = (RK_U8 *)mpp_buffer_get_ptr(buf) + offset8;
hdr_rem_msb = MPP_RB32(buf32);
hdr_rem_lsb = MPP_RB32(buf32 + 4);
}
hal_h264e_dbg_detail("offset %d offset8 %d\n", offset, offset8);
H264E_HAL_SET_REG(reg, VEPU_REG_ADDR_OUTPUT_STREAM, fd);
mpp_dev_set_reg_offset(ctx->dev, VEPU_REG_ADDR_OUTPUT_STREAM >> 2, offset8);
/* output buffer size is 64 bit address then 8 multiple size */
limit = mpp_buffer_get_size(buf);
limit -= offset8;
limit >>= 3;
limit &= ~7;
H264E_HAL_SET_REG(reg, VEPU_REG_STR_BUF_LIMIT, limit);
hal_h264e_dbg_detail("msb %08x lsb %08x", hdr_rem_msb, hdr_rem_lsb);
H264E_HAL_SET_REG(reg, VEPU_REG_STR_HDR_REM_MSB, hdr_rem_msb);
H264E_HAL_SET_REG(reg, VEPU_REG_STR_HDR_REM_LSB, hdr_rem_lsb);
return (offset - offset8) * 8;
}
static MPP_RET setup_intra_refresh(HalH264eVepu2Ctx *ctx, EncFrmStatus *frm)
{
MPP_RET ret = MPP_OK;
RK_U32 mb_w = ctx->sps->pic_width_in_mbs;
RK_U32 mb_h = ctx->sps->pic_height_in_mbs;
RK_U32 refresh_num = ctx->cfg->rc.refresh_num;
MppEncCfgSet *cfg = ctx->cfg;
RK_U32 *reg = ctx->regs_set.val;
RK_U32 val = 0;
RK_S32 top = 0;
RK_S32 left = 0;
RK_S32 right = 0;
RK_S32 bottom = 0;
RK_U32 refresh_idx = frm->seq_idx % cfg->rc.gop;
hal_h264e_dbg_func("enter\n");
if (!ctx->cfg->rc.refresh_en || !frm->is_i_refresh) {
goto RET;
}
if (ctx->cfg->rc.refresh_mode == MPP_ENC_RC_INTRA_REFRESH_ROW) {
left = 0;
right = mb_w;
top = refresh_idx * refresh_num - 2;
bottom = (refresh_idx + 1) * refresh_num - 1;
top = mpp_clip(top, 0, mb_h);
bottom = mpp_clip(bottom, 0, mb_h);
} else if (ctx->cfg->rc.refresh_mode == MPP_ENC_RC_INTRA_REFRESH_COL) {
top = 0;
bottom = mb_h;
left = refresh_idx * refresh_num - 2;
right = (refresh_idx + 1) * refresh_num - 1;
left = mpp_clip(left, 0, mb_w);
right = mpp_clip(right, 0, mb_w);
}
RET:
val = VEPU_REG_INTRA_AREA_TOP(top)
| VEPU_REG_INTRA_AREA_BOTTOM(bottom)
| VEPU_REG_INTRA_AREA_LEFT(left)
| VEPU_REG_INTRA_AREA_RIGHT(right);
H264E_HAL_SET_REG(reg, VEPU_REG_INTRA_AREA_CTRL, val);
hal_h264e_dbg_func("leave, ret %d\n", ret);
return ret;
}
static MPP_RET hal_h264e_vepu2_gen_regs_v2(void *hal, HalEncTask *task)
{
//MPP_RET ret = MPP_OK;
HalH264eVepu2Ctx *ctx = (HalH264eVepu2Ctx *)hal;
HalH264eVepuBufs *hw_bufs = &ctx->hw_bufs;
HalH264eVepuPrep *hw_prep = &ctx->hw_prep;
HalH264eVepuAddr *hw_addr = &ctx->hw_addr;
HalH264eVepuMbRc *hw_mbrc = &ctx->hw_mbrc;
VepuOffsetCfg *hw_offset = &ctx->hw_offset;
EncRcTaskInfo *rc_info = &task->rc_task->info;
EncFrmStatus *frm = &task->rc_task->frm;
H264eSps *sps = ctx->sps;
H264ePps *pps = ctx->pps;
H264eSlice *slice = ctx->slice;
RK_U32 *reg = ctx->regs_set.val;
RK_U32 mb_w = ctx->sps->pic_width_in_mbs;
RK_U32 mb_h = ctx->sps->pic_height_in_mbs;
RK_U32 offset = mpp_packet_get_length(task->packet);
RK_U32 first_free_bit = 0;
RK_U32 val = 0;
RK_S32 i = 0;
if (hw_prep->rotation) {
mb_w = ctx->sps->pic_height_in_mbs;
mb_h = ctx->sps->pic_width_in_mbs;
}
hw_mbrc->qp_init = rc_info->quality_target;
hw_mbrc->qp_max = rc_info->quality_max;
hw_mbrc->qp_min = rc_info->quality_min;
hal_h264e_dbg_func("enter %p\n", hal);
hal_h264e_dbg_detail("frame %d generate regs now", frm->seq_idx);
// prepare mb rc config
h264e_vepu_mbrc_prepare(ctx->rc_ctx, &ctx->hw_mbrc, task->rc_task);
h264e_vepu_slice_split_cfg(ctx->slice, &ctx->hw_mbrc, task->rc_task, ctx->cfg);
/* setup output address with offset */
first_free_bit = setup_output_packet(ctx, reg, task->output, offset);
/* set extra byte for header */
hw_mbrc->hdr_strm_size = offset;
hw_mbrc->hdr_free_size = first_free_bit / 8;
hw_mbrc->out_strm_size = 0;
/*
* The hardware needs only the value for luma plane, because
* values of other planes are calculated internally based on
* format setting.
*/
setup_intra_refresh(ctx, frm);
val = VEPU_REG_AXI_CTRL_READ_ID(0);
val |= VEPU_REG_AXI_CTRL_WRITE_ID(0);
val |= VEPU_REG_AXI_CTRL_BURST_LEN(16);
val |= VEPU_REG_AXI_CTRL_INCREMENT_MODE(0);
val |= VEPU_REG_AXI_CTRL_BIRST_DISCARD(0);
H264E_HAL_SET_REG(reg, VEPU_REG_AXI_CTRL, val);
H264E_HAL_SET_REG(reg, VEPU_QP_ADJUST_MAD_DELTA_ROI,
hw_mbrc->mad_qp_change);
val = 0;
if (mb_w * mb_h > 3600)
val = VEPU_REG_DISABLE_QUARTER_PIXEL_MV;
val |= VEPU_REG_CABAC_INIT_IDC(slice->cabac_init_idc);
if (pps->entropy_coding_mode)
val |= VEPU_REG_ENTROPY_CODING_MODE;
if (pps->transform_8x8_mode)
val |= VEPU_REG_H264_TRANS8X8_MODE;
if (sps->profile_idc > 31)
val |= VEPU_REG_H264_INTER4X4_MODE;
/*reg |= VEPU_REG_H264_STREAM_MODE;*/
val |= VEPU_REG_H264_SLICE_SIZE(hw_mbrc->slice_size_mb_rows);
H264E_HAL_SET_REG(reg, VEPU_REG_ENC_CTRL0, val);
RK_U32 scaler = MPP_MAX(1, 200 / (mb_w + mb_h));
RK_U32 skip_penalty = MPP_MIN(255, h264_skip_sad_penalty[hw_mbrc->qp_init] * scaler);
RK_U32 overfill_r = (hw_prep->src_w & 0x0f) ?
((16 - (hw_prep->src_w & 0x0f)) / 4) : 0;
RK_U32 overfill_b = (hw_prep->src_h & 0x0f) ?
(16 - (hw_prep->src_h & 0x0f)) : 0;
val = VEPU_REG_STREAM_START_OFFSET(first_free_bit) |
VEPU_REG_SKIP_MACROBLOCK_PENALTY(skip_penalty) |
VEPU_REG_IN_IMG_CTRL_OVRFLR_D4(overfill_r) |
VEPU_REG_IN_IMG_CTRL_OVRFLB(overfill_b);
H264E_HAL_SET_REG(reg, VEPU_REG_ENC_OVER_FILL_STRM_OFFSET, val);
// When offset is zero row length should be total 16 aligned width
val = VEPU_REG_IN_IMG_CHROMA_OFFSET(0)
| VEPU_REG_IN_IMG_LUMA_OFFSET(0)
| VEPU_REG_IN_IMG_CTRL_ROW_LEN(hw_prep->pixel_stride);
H264E_HAL_SET_REG(reg, VEPU_REG_INPUT_LUMA_INFO, val);
val = VEPU_REG_CHECKPOINT_CHECK1(hw_mbrc->cp_target[0])
| VEPU_REG_CHECKPOINT_CHECK0(hw_mbrc->cp_target[1]);
H264E_HAL_SET_REG(reg, VEPU_REG_CHECKPOINT(0), val);
val = VEPU_REG_CHECKPOINT_CHECK1(hw_mbrc->cp_target[2])
| VEPU_REG_CHECKPOINT_CHECK0(hw_mbrc->cp_target[3]);
H264E_HAL_SET_REG(reg, VEPU_REG_CHECKPOINT(1), val);
val = VEPU_REG_CHECKPOINT_CHECK1(hw_mbrc->cp_target[4])
| VEPU_REG_CHECKPOINT_CHECK0(hw_mbrc->cp_target[5]);
H264E_HAL_SET_REG(reg, VEPU_REG_CHECKPOINT(2), val);
val = VEPU_REG_CHECKPOINT_CHECK1(hw_mbrc->cp_target[6])
| VEPU_REG_CHECKPOINT_CHECK0(hw_mbrc->cp_target[7]);
H264E_HAL_SET_REG(reg, VEPU_REG_CHECKPOINT(3), val);
val = VEPU_REG_CHECKPOINT_CHECK1(hw_mbrc->cp_target[8])
| VEPU_REG_CHECKPOINT_CHECK0(hw_mbrc->cp_target[9]);
H264E_HAL_SET_REG(reg, VEPU_REG_CHECKPOINT(4), val);
val = VEPU_REG_CHKPT_WORD_ERR_CHK1(hw_mbrc->cp_error[0])
| VEPU_REG_CHKPT_WORD_ERR_CHK0(hw_mbrc->cp_error[1]);
H264E_HAL_SET_REG(reg, VEPU_REG_CHKPT_WORD_ERR(0), val);
val = VEPU_REG_CHKPT_WORD_ERR_CHK1(hw_mbrc->cp_error[2])
| VEPU_REG_CHKPT_WORD_ERR_CHK0(hw_mbrc->cp_error[3]);
H264E_HAL_SET_REG(reg, VEPU_REG_CHKPT_WORD_ERR(1), val);
val = VEPU_REG_CHKPT_WORD_ERR_CHK1(hw_mbrc->cp_error[4])
| VEPU_REG_CHKPT_WORD_ERR_CHK0(hw_mbrc->cp_error[5]);
H264E_HAL_SET_REG(reg, VEPU_REG_CHKPT_WORD_ERR(2), val);
val = VEPU_REG_CHKPT_DELTA_QP_CHK6(hw_mbrc->cp_delta_qp[6])
| VEPU_REG_CHKPT_DELTA_QP_CHK5(hw_mbrc->cp_delta_qp[5])
| VEPU_REG_CHKPT_DELTA_QP_CHK4(hw_mbrc->cp_delta_qp[4])
| VEPU_REG_CHKPT_DELTA_QP_CHK3(hw_mbrc->cp_delta_qp[3])
| VEPU_REG_CHKPT_DELTA_QP_CHK2(hw_mbrc->cp_delta_qp[2])
| VEPU_REG_CHKPT_DELTA_QP_CHK1(hw_mbrc->cp_delta_qp[1])
| VEPU_REG_CHKPT_DELTA_QP_CHK0(hw_mbrc->cp_delta_qp[0]);
H264E_HAL_SET_REG(reg, VEPU_REG_CHKPT_DELTA_QP, val);
val = VEPU_REG_MAD_THRESHOLD(hw_mbrc->mad_threshold)
| VEPU_REG_IN_IMG_CTRL_FMT(hw_prep->src_fmt)
| VEPU_REG_IN_IMG_ROTATE_MODE(hw_prep->rotation)
| VEPU_REG_SIZE_TABLE_PRESENT; //FIXED
H264E_HAL_SET_REG(reg, VEPU_REG_ENC_CTRL1, val);
val = VEPU_REG_INTRA16X16_MODE(h264_intra16_favor[hw_mbrc->qp_init])
| VEPU_REG_INTER_MODE(h264_inter_favor[hw_mbrc->qp_init]);
H264E_HAL_SET_REG(reg, VEPU_REG_INTRA_INTER_MODE, val);
val = VEPU_REG_PPS_INIT_QP(pps->pic_init_qp)
| VEPU_REG_SLICE_FILTER_ALPHA(slice->slice_alpha_c0_offset_div2)
| VEPU_REG_SLICE_FILTER_BETA(slice->slice_beta_offset_div2)
| VEPU_REG_CHROMA_QP_OFFSET(pps->chroma_qp_index_offset)
| VEPU_REG_IDR_PIC_ID(slice->idr_pic_id);
if (slice->disable_deblocking_filter_idc)
val |= VEPU_REG_FILTER_DISABLE;
if (pps->constrained_intra_pred)
val |= VEPU_REG_CONSTRAINED_INTRA_PREDICTION;
H264E_HAL_SET_REG(reg, VEPU_REG_ENC_CTRL2, val);
H264E_HAL_SET_REG(reg, VEPU_REG_ADDR_NEXT_PIC, 0);
H264E_HAL_SET_REG(reg, VEPU_REG_ADDR_MV_OUT, 0);
MppBuffer cabac_table = hw_bufs->cabac_table;
RK_S32 cabac_table_fd = cabac_table ? mpp_buffer_get_fd(cabac_table) : 0;
H264E_HAL_SET_REG(reg, VEPU_REG_ADDR_CABAC_TBL, cabac_table_fd);
val = VEPU_REG_ROI1_TOP_MB(mb_h)
| VEPU_REG_ROI1_BOTTOM_MB(mb_h)
| VEPU_REG_ROI1_LEFT_MB(mb_w)
| VEPU_REG_ROI1_RIGHT_MB(mb_w);
H264E_HAL_SET_REG(reg, VEPU_REG_ROI1, val);
val = VEPU_REG_ROI2_TOP_MB(mb_h)
| VEPU_REG_ROI2_BOTTOM_MB(mb_h)
| VEPU_REG_ROI2_LEFT_MB(mb_w)
| VEPU_REG_ROI2_RIGHT_MB(mb_w);
H264E_HAL_SET_REG(reg, VEPU_REG_ROI2, val);
H264E_HAL_SET_REG(reg, VEPU_REG_STABLILIZATION_OUTPUT, 0);
val = VEPU_REG_RGB2YUV_CONVERSION_COEFB(hw_prep->color_conversion_coeff_b)
| VEPU_REG_RGB2YUV_CONVERSION_COEFA(hw_prep->color_conversion_coeff_a);
H264E_HAL_SET_REG(reg, VEPU_REG_RGB2YUV_CONVERSION_COEF1, val);
val = VEPU_REG_RGB2YUV_CONVERSION_COEFE(hw_prep->color_conversion_coeff_e)
| VEPU_REG_RGB2YUV_CONVERSION_COEFC(hw_prep->color_conversion_coeff_c);
H264E_HAL_SET_REG(reg, VEPU_REG_RGB2YUV_CONVERSION_COEF2, val);
val = VEPU_REG_RGB2YUV_CONVERSION_COEFF(hw_prep->color_conversion_coeff_f);
H264E_HAL_SET_REG(reg, VEPU_REG_RGB2YUV_CONVERSION_COEF3, val);
val = VEPU_REG_RGB_MASK_B_MSB(hw_prep->b_mask_msb)
| VEPU_REG_RGB_MASK_G_MSB(hw_prep->g_mask_msb)
| VEPU_REG_RGB_MASK_R_MSB(hw_prep->r_mask_msb);
H264E_HAL_SET_REG(reg, VEPU_REG_RGB_MASK_MSB, val); //FIXED
{
RK_U32 diff_mv_penalty[3] = {0};
diff_mv_penalty[0] = h264_diff_mv_penalty4p[hw_mbrc->qp_init];
diff_mv_penalty[1] = h264_diff_mv_penalty[hw_mbrc->qp_init];
diff_mv_penalty[2] = h264_diff_mv_penalty[hw_mbrc->qp_init];
val = VEPU_REG_1MV_PENALTY(diff_mv_penalty[1])
| VEPU_REG_QMV_PENALTY(diff_mv_penalty[2])
| VEPU_REG_4MV_PENALTY(diff_mv_penalty[0]);
}
val |= VEPU_REG_SPLIT_MV_MODE_EN;
H264E_HAL_SET_REG(reg, VEPU_REG_MV_PENALTY, val);
val = VEPU_REG_H264_LUMA_INIT_QP(hw_mbrc->qp_init)
| VEPU_REG_H264_QP_MAX(hw_mbrc->qp_max)
| VEPU_REG_H264_QP_MIN(hw_mbrc->qp_min)
| VEPU_REG_H264_CHKPT_DISTANCE(hw_mbrc->cp_distance_mbs);
H264E_HAL_SET_REG(reg, VEPU_REG_QP_VAL, val);
val = VEPU_REG_ZERO_MV_FAVOR_D2(10);
H264E_HAL_SET_REG(reg, VEPU_REG_MVC_RELATE, val);
val = VEPU_REG_OUTPUT_SWAP32
| VEPU_REG_OUTPUT_SWAP16
| VEPU_REG_OUTPUT_SWAP8
| VEPU_REG_INPUT_SWAP8_(hw_prep->swap_8_in)
| VEPU_REG_INPUT_SWAP16_(hw_prep->swap_16_in)
| VEPU_REG_INPUT_SWAP32_(hw_prep->swap_32_in);
H264E_HAL_SET_REG(reg, VEPU_REG_DATA_ENDIAN, val);
val = VEPU_REG_PPS_ID(pps->pps_id)
| VEPU_REG_INTRA_PRED_MODE(h264_prev_mode_favor[hw_mbrc->qp_init])
| VEPU_REG_FRAME_NUM(slice->frame_num);
H264E_HAL_SET_REG(reg, VEPU_REG_ENC_CTRL3, val);
val = VEPU_REG_INTERRUPT_TIMEOUT_EN;
H264E_HAL_SET_REG(reg, VEPU_REG_INTERRUPT, val);
{
RK_U8 dmv_penalty[128] = {0};
RK_U8 dmv_qpel_penalty[128] = {0};
for (i = 0; i < 128; i++) {
dmv_penalty[i] = i;
dmv_qpel_penalty[i] = MPP_MIN(255, exp_golomb_signed(i));
}
for (i = 0; i < 128; i += 4) {
val = VEPU_REG_DMV_PENALTY_TABLE_BIT(dmv_penalty[i], 3);
val |= VEPU_REG_DMV_PENALTY_TABLE_BIT(dmv_penalty[i + 1], 2);
val |= VEPU_REG_DMV_PENALTY_TABLE_BIT(dmv_penalty[i + 2], 1);
val |= VEPU_REG_DMV_PENALTY_TABLE_BIT(dmv_penalty[i + 3], 0);
H264E_HAL_SET_REG(reg, VEPU_REG_DMV_PENALTY_TBL(i / 4), val);
val = VEPU_REG_DMV_Q_PIXEL_PENALTY_TABLE_BIT(
dmv_qpel_penalty[i], 3);
val |= VEPU_REG_DMV_Q_PIXEL_PENALTY_TABLE_BIT(
dmv_qpel_penalty[i + 1], 2);
val |= VEPU_REG_DMV_Q_PIXEL_PENALTY_TABLE_BIT(
dmv_qpel_penalty[i + 2], 1);
val |= VEPU_REG_DMV_Q_PIXEL_PENALTY_TABLE_BIT(
dmv_qpel_penalty[i + 3], 0);
H264E_HAL_SET_REG(reg, VEPU_REG_DMV_Q_PIXEL_PENALTY_TBL(i / 4), val);
}
}
/* set buffers addr */
H264E_HAL_SET_REG(reg, VEPU_REG_ADDR_IN_LUMA, hw_addr->orig[0]);
if (hw_offset->offset_byte[0])
mpp_dev_set_reg_offset(ctx->dev, VEPU_REG_ADDR_IN_LUMA >> 2,
hw_offset->offset_byte[0]);
H264E_HAL_SET_REG(reg, VEPU_REG_ADDR_IN_CB, hw_addr->orig[1]);
if (hw_offset->offset_byte[1])
mpp_dev_set_reg_offset(ctx->dev, VEPU_REG_ADDR_IN_CB >> 2,
hw_offset->offset_byte[1]);
H264E_HAL_SET_REG(reg, VEPU_REG_ADDR_IN_CR, hw_addr->orig[2]);
if (hw_offset->offset_byte[2])
mpp_dev_set_reg_offset(ctx->dev, VEPU_REG_ADDR_IN_CR >> 2,
hw_offset->offset_byte[2]);
MppBuffer nal_size_table = h264e_vepu_buf_get_nal_size_table(hw_bufs);
RK_S32 nal_size_table_fd = nal_size_table ? mpp_buffer_get_fd(nal_size_table) : 0;
H264E_HAL_SET_REG(reg, VEPU_REG_ADDR_OUTPUT_CTRL, nal_size_table_fd);
H264E_HAL_SET_REG(reg, VEPU_REG_ADDR_REC_LUMA, hw_addr->recn[0]);
H264E_HAL_SET_REG(reg, VEPU_REG_ADDR_REC_CHROMA, hw_addr->recn[1]);
mpp_dev_set_reg_offset(ctx->dev, VEPU_REG_ADDR_REC_CHROMA >> 2, hw_bufs->yuv_size);
H264E_HAL_SET_REG(reg, VEPU_REG_ADDR_REF_LUMA, hw_addr->refr[0]);
H264E_HAL_SET_REG(reg, VEPU_REG_ADDR_REF_CHROMA, hw_addr->refr[1]);
mpp_dev_set_reg_offset(ctx->dev, VEPU_REG_ADDR_REF_CHROMA >> 2, hw_bufs->yuv_size);
/* set important encode mode info */
val = VEPU_REG_MB_HEIGHT(mb_h)
| VEPU_REG_MB_WIDTH(mb_w)
| VEPU_REG_PIC_TYPE(slice->idr_flag)
| VEPU_REG_ENCODE_FORMAT(3)
| VEPU_REG_ENCODE_ENABLE;
H264E_HAL_SET_REG(reg, VEPU_REG_ENCODE_START, val);
ctx->frame_cnt++;
hal_h264e_dbg_func("leave %p\n", hal);
return MPP_OK;
}
static MPP_RET hal_h264e_vepu2_start_v2(void *hal, HalEncTask *task)
{
MPP_RET ret = MPP_OK;
HalH264eVepu2Ctx *ctx = (HalH264eVepu2Ctx *)hal;
(void)task;
hal_h264e_dbg_func("enter %p\n", hal);
if (ctx->dev) {
MppDevRegWrCfg wr_cfg;
MppDevRegRdCfg rd_cfg;
RK_U32 reg_size = sizeof(ctx->regs_set);
do {
wr_cfg.reg = &ctx->regs_set;
wr_cfg.size = reg_size;
wr_cfg.offset = 0;
ret = mpp_dev_ioctl(ctx->dev, MPP_DEV_REG_WR, &wr_cfg);
if (ret) {
mpp_err_f("set register write failed %d\n", ret);
break;
}
rd_cfg.reg = &ctx->regs_get;
rd_cfg.size = reg_size;
rd_cfg.offset = 0;
ret = mpp_dev_ioctl(ctx->dev, MPP_DEV_REG_RD, &rd_cfg);
if (ret) {
mpp_err_f("set register read failed %d\n", ret);
break;
}
ret = mpp_dev_ioctl(ctx->dev, MPP_DEV_CMD_SEND, NULL);
if (ret) {
mpp_err_f("send cmd failed %d\n", ret);
break;
}
} while (0);
} else
mpp_err("invalid NULL device ctx\n");
hal_h264e_dbg_func("leave %p\n", hal);
return ret;
}
static void h264e_vepu2_get_mbrc(HalH264eVepuMbRc *mb_rc, H264eVpu2RegSet *reg)
{
RK_S32 i = 0;
RK_U32 cpt_prev = 0;
RK_U32 overflow = 0;
RK_U32 cpt_idx = VEPU_REG_CHECKPOINT(0) / 4;
RK_U32 *reg_val = reg->val;
mb_rc->hw_status = reg_val[VEPU_REG_INTERRUPT / 4];
mb_rc->out_strm_size = reg_val[VEPU_REG_STR_BUF_LIMIT / 4] / 8 - mb_rc->hdr_free_size;
mb_rc->qp_sum = ((reg_val[VEPU_REG_QP_SUM_DIV2 / 4] >> 11) & 0x001fffff) * 2;
mb_rc->less_mad_count = (reg_val[VEPU_REG_MB_CTRL / 4] >> 16) & 0xffff;
mb_rc->rlc_count = reg_val[VEPU_REG_RLC_SUM / 4] & 0x3fffff;
for (i = 0; i < VEPU_CHECK_POINTS_MAX; i++) {
RK_U32 cpt = VEPU_REG_CHECKPOINT_RESULT(reg_val[cpt_idx]);
if (cpt < cpt_prev)
overflow += (1 << 21);
cpt_prev = cpt;
mb_rc->cp_usage[i] = cpt + overflow;
cpt_idx += (i & 1);
}
}
static MPP_RET hal_h264e_vepu2_wait_v2(void *hal, HalEncTask *task)
{
HalH264eVepu2Ctx *ctx = (HalH264eVepu2Ctx *)hal;
HalH264eVepuMbRc *hw_mbrc = &ctx->hw_mbrc;
MPP_RET ret = MPP_NOK;
(void) task;
hal_h264e_dbg_func("enter %p\n", hal);
if (ctx->dev) {
ret = mpp_dev_ioctl(ctx->dev, MPP_DEV_CMD_POLL, NULL);
if (ret)
mpp_err_f("poll cmd failed %d\n", ret);
} else {
mpp_err("invalid NULL device ctx\n");
return ret;
}
h264e_vepu2_get_mbrc(hw_mbrc, &ctx->regs_get);
h264e_vepu_mbrc_update(ctx->rc_ctx, hw_mbrc);
{
HalH264eVepuStreamAmend *amend = &ctx->amend;
if (amend->enable) {
amend->old_length = hw_mbrc->out_strm_size;
h264e_vepu_stream_amend_proc(amend, &ctx->cfg->codec.h264.hw_cfg);
ctx->hw_mbrc.out_strm_size = amend->new_length;
} else if (amend->prefix) {
/* check prefix value */
amend->old_length = hw_mbrc->out_strm_size;
h264e_vepu_stream_amend_sync_ref_idc(amend);
}
}
task->hw_length += ctx->hw_mbrc.out_strm_size;
hal_h264e_dbg_func("leave %p\n", hal);
return MPP_OK;
}
static MPP_RET hal_h264e_vepu2_ret_task_v2(void *hal, HalEncTask *task)
{
HalH264eVepu2Ctx *ctx = (HalH264eVepu2Ctx *)hal;
EncRcTaskInfo *rc_info = &task->rc_task->info;
RK_U32 mb_w = ctx->sps->pic_width_in_mbs;
RK_U32 mb_h = ctx->sps->pic_height_in_mbs;
RK_U32 mbs = mb_w * mb_h;
hal_h264e_dbg_func("enter %p\n", hal);
task->length += task->hw_length;
rc_info->bit_real = task->hw_length * 8;
rc_info->quality_real = ctx->hw_mbrc.qp_sum / mbs;
hal_h264e_dbg_rc("real bit %d quality %d\n", rc_info->bit_real, rc_info->quality_real);
task->hal_ret.data = rc_info;
task->hal_ret.number = 1;
hal_h264e_dbg_func("leave %p\n", hal);
return MPP_OK;
}
const MppEncHalApi hal_h264e_vepu2 = {
.name = "hal_h264e_vepu2",
.coding = MPP_VIDEO_CodingAVC,
.ctx_size = sizeof(HalH264eVepu2Ctx),
.flag = 0,
.init = hal_h264e_vepu2_init_v2,
.deinit = hal_h264e_vepu2_deinit_v2,
.prepare = NULL,
.get_task = hal_h264e_vepu2_get_task_v2,
.gen_regs = hal_h264e_vepu2_gen_regs_v2,
.start = hal_h264e_vepu2_start_v2,
.wait = hal_h264e_vepu2_wait_v2,
.part_start = NULL,
.part_wait = NULL,
.ret_task = hal_h264e_vepu2_ret_task_v2,
};
|
ddd7498f3dc42648e8e6b15bf2cc5340bba3aef6
|
2dfc2beac0ad497f8fc59201921097a412f0df7f
|
/trunk/3rdparty/ffmpeg-4-fit/libavcodec/psymodel.h
|
e5f917d495d0bbf405b16ed7228df41517861220
|
[
"Apache-2.0",
"LicenseRef-scancode-mulanpsl-2.0-en",
"MIT",
"MulanPSL-2.0",
"LicenseRef-scancode-unknown-license-reference",
"OpenSSL",
"JSON",
"LGPL-3.0-only",
"LGPL-2.0-or-later",
"LGPL-3.0-or-later",
"IJG",
"LicenseRef-scancode-proprietary-license",
"GPL-2.0-or-later",
"LGPL-2.1-or-later",
"GPL-3.0-only",
"GPL-2.0-only",
"LicenseRef-scancode-other-permissive",
"GPL-1.0-or-later"
] |
permissive
|
ossrs/srs
|
cf9442478fedcd32ef2817f8d53f405a6fa2c7d1
|
7138edd318d30b545e73e80500adda771817f8d1
|
refs/heads/develop
| 2023-09-01T03:38:35.057515
| 2023-08-31T01:45:25
| 2023-08-31T01:49:36
| 34,777,562
| 23,557
| 5,046
|
MIT
| 2023-09-09T00:57:42
| 2015-04-29T06:59:32
|
C++
|
UTF-8
|
C
| false
| false
| 7,534
|
h
|
psymodel.h
|
/*
* audio encoder psychoacoustic model
* Copyright (C) 2008 Konstantin Shishkov
*
* 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_PSYMODEL_H
#define AVCODEC_PSYMODEL_H
#include "avcodec.h"
/** maximum possible number of bands */
#define PSY_MAX_BANDS 128
/** maximum number of channels */
#define PSY_MAX_CHANS 20
/* cutoff for VBR is purposely increased, since LP filtering actually
* hinders VBR performance rather than the opposite
*/
#define AAC_CUTOFF_FROM_BITRATE(bit_rate,channels,sample_rate) (bit_rate ? FFMIN3(FFMIN3( \
FFMAX(bit_rate/channels/5, bit_rate/channels*15/32 - 5500), \
3000 + bit_rate/channels/4, \
12000 + bit_rate/channels/16), \
22000, \
sample_rate / 2): (sample_rate / 2))
#define AAC_CUTOFF(s) ( \
(s->flags & AV_CODEC_FLAG_QSCALE) \
? s->sample_rate / 2 \
: AAC_CUTOFF_FROM_BITRATE(s->bit_rate, s->channels, s->sample_rate) \
)
/**
* single band psychoacoustic information
*/
typedef struct FFPsyBand {
int bits;
float energy;
float threshold;
float spread; /* Energy spread over the band */
} FFPsyBand;
/**
* single channel psychoacoustic information
*/
typedef struct FFPsyChannel {
FFPsyBand psy_bands[PSY_MAX_BANDS]; ///< channel bands information
float entropy; ///< total PE for this channel
} FFPsyChannel;
/**
* psychoacoustic information for an arbitrary group of channels
*/
typedef struct FFPsyChannelGroup {
FFPsyChannel *ch[PSY_MAX_CHANS]; ///< pointers to the individual channels in the group
uint8_t num_ch; ///< number of channels in this group
uint8_t coupling[PSY_MAX_BANDS]; ///< allow coupling for this band in the group
} FFPsyChannelGroup;
/**
* windowing related information
*/
typedef struct FFPsyWindowInfo {
int window_type[3]; ///< window type (short/long/transitional, etc.) - current, previous and next
int window_shape; ///< window shape (sine/KBD/whatever)
int num_windows; ///< number of windows in a frame
int grouping[8]; ///< window grouping (for e.g. AAC)
float clipping[8]; ///< maximum absolute normalized intensity in the given window for clip avoidance
int *window_sizes; ///< sequence of window sizes inside one frame (for eg. WMA)
} FFPsyWindowInfo;
/**
* context used by psychoacoustic model
*/
typedef struct FFPsyContext {
AVCodecContext *avctx; ///< encoder context
const struct FFPsyModel *model; ///< encoder-specific model functions
FFPsyChannel *ch; ///< single channel information
FFPsyChannelGroup *group; ///< channel group information
int num_groups; ///< number of channel groups
int cutoff; ///< lowpass frequency cutoff for analysis
uint8_t **bands; ///< scalefactor band sizes for possible frame sizes
int *num_bands; ///< number of scalefactor bands for possible frame sizes
int num_lens; ///< number of scalefactor band sets
struct {
int size; ///< size of the bitresevoir in bits
int bits; ///< number of bits used in the bitresevoir
int alloc; ///< number of bits allocated by the psy, or -1 if no allocation was done
} bitres;
void* model_priv_data; ///< psychoacoustic model implementation private data
} FFPsyContext;
/**
* codec-specific psychoacoustic model implementation
*/
typedef struct FFPsyModel {
const char *name;
int (*init) (FFPsyContext *apc);
/**
* Suggest window sequence for channel.
*
* @param ctx model context
* @param audio samples for the current frame
* @param la lookahead samples (NULL when unavailable)
* @param channel number of channel element to analyze
* @param prev_type previous window type
*
* @return suggested window information in a structure
*/
FFPsyWindowInfo (*window)(FFPsyContext *ctx, const float *audio, const float *la, int channel, int prev_type);
/**
* Perform psychoacoustic analysis and set band info (threshold, energy) for a group of channels.
*
* @param ctx model context
* @param channel channel number of the first channel in the group to perform analysis on
* @param coeffs array of pointers to the transformed coefficients
* @param wi window information for the channels in the group
*/
void (*analyze)(FFPsyContext *ctx, int channel, const float **coeffs, const FFPsyWindowInfo *wi);
void (*end) (FFPsyContext *apc);
} FFPsyModel;
/**
* Initialize psychoacoustic model.
*
* @param ctx model context
* @param avctx codec context
* @param num_lens number of possible frame lengths
* @param bands scalefactor band lengths for all frame lengths
* @param num_bands number of scalefactor bands for all frame lengths
* @param num_groups number of channel groups
* @param group_map array with # of channels in group - 1, for each group
*
* @return zero if successful, a negative value if not
*/
int ff_psy_init(FFPsyContext *ctx, AVCodecContext *avctx, int num_lens,
const uint8_t **bands, const int *num_bands,
int num_groups, const uint8_t *group_map);
/**
* Determine what group a channel belongs to.
*
* @param ctx psymodel context
* @param channel channel to locate the group for
*
* @return pointer to the FFPsyChannelGroup this channel belongs to
*/
FFPsyChannelGroup *ff_psy_find_group(FFPsyContext *ctx, int channel);
/**
* Cleanup model context at the end.
*
* @param ctx model context
*/
void ff_psy_end(FFPsyContext *ctx);
/**************************************************************************
* Audio preprocessing stuff. *
* This should be moved into some audio filter eventually. *
**************************************************************************/
struct FFPsyPreprocessContext;
/**
* psychoacoustic model audio preprocessing initialization
*/
struct FFPsyPreprocessContext *ff_psy_preprocess_init(AVCodecContext *avctx);
/**
* Preprocess several channel in audio frame in order to compress it better.
*
* @param ctx preprocessing context
* @param audio samples to be filtered (in place)
* @param channels number of channel to preprocess
*/
void ff_psy_preprocess(struct FFPsyPreprocessContext *ctx, float **audio, int channels);
/**
* Cleanup audio preprocessing module.
*/
void ff_psy_preprocess_end(struct FFPsyPreprocessContext *ctx);
#endif /* AVCODEC_PSYMODEL_H */
|
1db30f3dfab33f0b402c6aaf2200e4408e3acba4
|
28d0f8c01599f8f6c711bdde0b59f9c2cd221203
|
/sys/net/if_stats.h
|
410227ef132fdef024f9cabeb53fd0e0b4f56f25
|
[
"BSD-3-Clause"
] |
permissive
|
NetBSD/src
|
1a9cbc22ed778be638b37869ed4fb5c8dd616166
|
23ee83f7c0aea0777bd89d8ebd7f0cde9880d13c
|
refs/heads/trunk
| 2023-08-31T13:24:58.105962
| 2023-08-27T15:50:47
| 2023-08-27T15:50:47
| 88,439,547
| 656
| 348
| null | 2023-07-20T20:07:24
| 2017-04-16T20:03:43
| null |
UTF-8
|
C
| false
| false
| 3,745
|
h
|
if_stats.h
|
/* $NetBSD: if_stats.h,v 1.3 2021/06/29 21:19:58 riastradh Exp $ */
/*-
* Copyright (c) 2020 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Jason R. Thorpe.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _NET_IF_STATS_H_
#define _NET_IF_STATS_H_
#include <net/net_stats.h>
/*
* Interface statistics. All values are unsigned 64-bit.
*/
typedef enum {
if_ipackets = 0, /* packets received on interface */
if_ierrors = 1, /* input errors on interface */
if_opackets = 2, /* packets sent on interface */
if_oerrors = 3, /* output errors on interface */
if_collisions = 4, /* collisions on csma interfaces */
if_ibytes = 5, /* total number of octets received */
if_obytes = 6, /* total number of octets sent */
if_imcasts = 7, /* packets received via multicast */
if_omcasts = 8, /* packets sent via multicast */
if_iqdrops = 9, /* dropped on input, this interface */
if_noproto = 10, /* destined for unsupported protocol */
IF_NSTATS = 11
} if_stat_t;
#ifdef _KERNEL
#define IF_STAT_GETREF(ifp) _NET_STAT_GETREF((ifp)->if_stats)
#define IF_STAT_PUTREF(ifp) _NET_STAT_PUTREF((ifp)->if_stats)
static inline void
if_statinc(ifnet_t *ifp, if_stat_t x)
{
_NET_STATINC((ifp)->if_stats, x);
}
static inline void
if_statinc_ref(net_stat_ref_t nsr, if_stat_t x)
{
_NET_STATINC_REF(nsr, x);
}
static inline void
if_statdec(ifnet_t *ifp, if_stat_t x)
{
_NET_STATDEC((ifp)->if_stats, x);
}
static inline void
if_statdec_ref(net_stat_ref_t nsr, if_stat_t x)
{
_NET_STATDEC_REF(nsr, x);
}
static inline void
if_statadd(ifnet_t *ifp, if_stat_t x, uint64_t v)
{
_NET_STATADD((ifp)->if_stats, x, v);
}
static inline void
if_statadd_ref(net_stat_ref_t nsr, if_stat_t x, uint64_t v)
{
_NET_STATADD_REF(nsr, x, v);
}
static inline void
if_statadd2(ifnet_t *ifp, if_stat_t x1, uint64_t v1, if_stat_t x2, uint64_t v2)
{
net_stat_ref_t _nsr_ = IF_STAT_GETREF(ifp);
_NET_STATADD_REF(_nsr_, x1, v1);
_NET_STATADD_REF(_nsr_, x2, v2);
IF_STAT_PUTREF(ifp);
}
static inline void
if_statsub(ifnet_t *ifp, if_stat_t x, uint64_t v)
{
_NET_STATSUB((ifp)->if_stats, x, v);
}
static inline void
if_statsub_ref(net_stat_ref_t nsr, if_stat_t x, uint64_t v)
{
_NET_STATSUB_REF(nsr, x, v);
}
void if_stats_init(ifnet_t *);
void if_stats_fini(ifnet_t *);
void if_stats_to_if_data(ifnet_t *, struct if_data *, bool);
#endif /* _KERNEL */
#endif /* !_NET_IF_STATS_H_ */
|
dd379decb6cca9050a69f56d28e499d3797c5e45
|
634f578ec3016e8aad06a57c948377f63fc36b16
|
/c/ch5/heat.c
|
83c7fc41ba01a2b1d5e7925ffdc200fcc0b9d5a1
|
[
"MIT"
] |
permissive
|
bueler/p4pdes
|
ecad37430c3a0bf350d786d7d0e284abdb446317
|
098e000a0eea4f96e074fa437752086a1ab15207
|
refs/heads/master
| 2023-07-31T17:30:43.546800
| 2023-07-18T21:45:11
| 2023-07-18T21:45:11
| 24,288,784
| 179
| 66
| null | null | null | null |
UTF-8
|
C
| false
| false
| 7,663
|
c
|
heat.c
|
static char help[] =
"Solves time-dependent heat equation in 2D using TS. Option prefix -ht_.\n"
"Equation is u_t = D_0 laplacian u + f. Domain is (0,1) x (0,1).\n"
"Boundary conditions are non-homogeneous Neumann in x and periodic in y.\n"
"Energy is conserved (for these particular conditions/source) and an extra\n"
"'monitor' is demonstrated. Discretization is by centered finite differences.\n"
"Converts the PDE into a system X_t = G(t,X) (PETSc type 'nonlinear') by\n"
"method of lines. Uses backward Euler time-stepping by default.\n";
#include <petsc.h>
typedef struct {
PetscReal D0; // conductivity
} HeatCtx;
static PetscReal f_source(PetscReal x, PetscReal y) {
return 3.0 * PetscExpReal(-25.0 * (x-0.6) * (x-0.6))
* PetscSinReal(2.0*PETSC_PI*y);
}
static PetscReal gamma_neumann(PetscReal y) {
return PetscSinReal(6.0 * PETSC_PI * y);
}
extern PetscErrorCode Spacings(DMDALocalInfo*, PetscReal*, PetscReal*);
extern PetscErrorCode EnergyMonitor(TS, PetscInt, PetscReal, Vec, void*);
extern PetscErrorCode FormRHSFunctionLocal(DMDALocalInfo*, PetscReal, PetscReal**,
PetscReal**, HeatCtx*);
extern PetscErrorCode FormRHSJacobianLocal(DMDALocalInfo*, PetscReal, PetscReal**,
Mat, Mat, HeatCtx*);
int main(int argc,char **argv) {
HeatCtx user;
TS ts;
Vec u;
DM da;
DMDALocalInfo info;
PetscReal t0, tf;
PetscBool monitorenergy = PETSC_FALSE;
PetscCall(PetscInitialize(&argc,&argv,NULL,help));
user.D0 = 1.0;
PetscOptionsBegin(PETSC_COMM_WORLD, "ht_", "options for heat", "");
PetscCall(PetscOptionsReal("-D0","constant thermal diffusivity",
"heat.c",user.D0,&user.D0,NULL));
PetscCall(PetscOptionsBool("-monitor","also display total heat energy at each step",
"heat.c",monitorenergy,&monitorenergy,NULL));
PetscOptionsEnd();
//STARTDMDASETUP
PetscCall(DMDACreate2d(PETSC_COMM_WORLD,
DM_BOUNDARY_NONE, DM_BOUNDARY_PERIODIC, DMDA_STENCIL_STAR,
5,4,PETSC_DECIDE,PETSC_DECIDE, // default to hx=hx=0.25 grid
1,1, // degrees of freedom, stencil width
NULL,NULL,&da));
PetscCall(DMSetFromOptions(da));
PetscCall(DMSetUp(da));
PetscCall(DMCreateGlobalVector(da,&u));
//ENDDMDASETUP
//STARTTSSETUP
PetscCall(TSCreate(PETSC_COMM_WORLD,&ts));
PetscCall(TSSetProblemType(ts,TS_NONLINEAR));
PetscCall(TSSetDM(ts,da));
PetscCall(TSSetApplicationContext(ts,&user));
PetscCall(DMDATSSetRHSFunctionLocal(da,INSERT_VALUES,
(DMDATSRHSFunctionLocal)FormRHSFunctionLocal,&user));
PetscCall(DMDATSSetRHSJacobianLocal(da,
(DMDATSRHSJacobianLocal)FormRHSJacobianLocal,&user));
if (monitorenergy) {
PetscCall(TSMonitorSet(ts,EnergyMonitor,&user,NULL));
}
PetscCall(TSSetType(ts,TSBDF));
PetscCall(TSSetTime(ts,0.0));
PetscCall(TSSetMaxTime(ts,0.1));
PetscCall(TSSetTimeStep(ts,0.001));
PetscCall(TSSetExactFinalTime(ts,TS_EXACTFINALTIME_MATCHSTEP));
PetscCall(TSSetFromOptions(ts));
//ENDTSSETUP
// report on set up
PetscCall(TSGetTime(ts,&t0));
PetscCall(TSGetMaxTime(ts,&tf));
PetscCall(DMDAGetLocalInfo(da,&info));
PetscCall(PetscPrintf(PETSC_COMM_WORLD,
"solving on %d x %d grid for t0=%g to tf=%g ...\n",
info.mx,info.my,t0,tf));
// solve
PetscCall(VecSet(u,0.0)); // initial condition
PetscCall(TSSolve(ts,u));
PetscCall(VecDestroy(&u));
PetscCall(TSDestroy(&ts));
PetscCall(DMDestroy(&da));
PetscCall(PetscFinalize());
return 0;
}
PetscErrorCode Spacings(DMDALocalInfo *info, PetscReal *hx, PetscReal *hy) {
if (hx) *hx = 1.0 / (PetscReal)(info->mx-1);
if (hy) *hy = 1.0 / (PetscReal)(info->my); // periodic direction
return 0;
}
//STARTMONITOR
PetscErrorCode EnergyMonitor(TS ts, PetscInt step, PetscReal time, Vec u,
void *ctx) {
HeatCtx *user = (HeatCtx*)ctx;
PetscReal lenergy = 0.0, energy, dt, hx, hy, **au;
PetscInt i,j;
MPI_Comm com;
DM da;
DMDALocalInfo info;
PetscCall(TSGetDM(ts,&da));
PetscCall(DMDAGetLocalInfo(da,&info));
PetscCall(DMDAVecGetArrayRead(da,u,&au));
for (j = info.ys; j < info.ys + info.ym; j++) {
for (i = info.xs; i < info.xs + info.xm; i++) {
if ((i == 0) || (i == info.mx-1))
lenergy += 0.5 * au[j][i];
else
lenergy += au[j][i];
}
}
PetscCall(DMDAVecRestoreArrayRead(da,u,&au));
PetscCall(Spacings(&info,&hx,&hy));
lenergy *= hx * hy;
PetscCall(PetscObjectGetComm((PetscObject)(da),&com));
PetscCall(MPI_Allreduce(&lenergy,&energy,1,MPIU_REAL,MPIU_SUM,com));
PetscCall(TSGetTimeStep(ts,&dt));
PetscCall(PetscPrintf(PETSC_COMM_WORLD," energy = %9.2e nu = %8.4f\n",
energy,user->D0*dt/(hx*hy)));
return 0;
}
//ENDMONITOR
//STARTRHSFUNCTION
PetscErrorCode FormRHSFunctionLocal(DMDALocalInfo *info,
PetscReal t, PetscReal **au,
PetscReal **aG, HeatCtx *user) {
PetscInt i, j, mx = info->mx;
PetscReal hx, hy, x, y, ul, ur, uxx, uyy;
PetscCall(Spacings(info,&hx,&hy));
for (j = info->ys; j < info->ys + info->ym; j++) {
y = hy * j;
for (i = info->xs; i < info->xs + info->xm; i++) {
x = hx * i;
// apply Neumann b.c.s
ul = (i == 0) ? au[j][i+1] + 2.0 * hx * gamma_neumann(y)
: au[j][i-1];
ur = (i == mx-1) ? au[j][i-1] : au[j][i+1];
uxx = (ul - 2.0 * au[j][i]+ ur) / (hx*hx);
// DMDA is periodic in y
uyy = (au[j-1][i] - 2.0 * au[j][i]+ au[j+1][i]) / (hy*hy);
aG[j][i] = user->D0 * (uxx + uyy) + f_source(x,y);
}
}
return 0;
}
//ENDRHSFUNCTION
//STARTRHSJACOBIAN
PetscErrorCode FormRHSJacobianLocal(DMDALocalInfo *info,
PetscReal t, PetscReal **au,
Mat J, Mat P, HeatCtx *user) {
PetscInt i, j, ncols;
const PetscReal D = user->D0;
PetscReal hx, hy, hx2, hy2, v[5];
MatStencil col[5],row;
PetscCall(Spacings(info,&hx,&hy));
hx2 = hx * hx; hy2 = hy * hy;
for (j = info->ys; j < info->ys+info->ym; j++) {
row.j = j; col[0].j = j;
for (i = info->xs; i < info->xs+info->xm; i++) {
// set up a standard 5-point stencil for the row
row.i = i;
col[0].i = i;
v[0] = - 2.0 * D * (1.0 / hx2 + 1.0 / hy2);
col[1].j = j-1; col[1].i = i; v[1] = D / hy2;
col[2].j = j+1; col[2].i = i; v[2] = D / hy2;
col[3].j = j; col[3].i = i-1; v[3] = D / hx2;
col[4].j = j; col[4].i = i+1; v[4] = D / hx2;
ncols = 5;
// if at the boundary, edit the row back to 4 nonzeros
if (i == 0) {
ncols = 4;
col[3].j = j; col[3].i = i+1; v[3] = 2.0 * D / hx2;
} else if (i == info->mx-1) {
ncols = 4;
col[3].j = j; col[3].i = i-1; v[3] = 2.0 * D / hx2;
}
PetscCall(MatSetValuesStencil(P,1,&row,ncols,col,v,INSERT_VALUES));
}
}
PetscCall(MatAssemblyBegin(P,MAT_FINAL_ASSEMBLY));
PetscCall(MatAssemblyEnd(P,MAT_FINAL_ASSEMBLY));
if (J != P) {
PetscCall(MatAssemblyBegin(J,MAT_FINAL_ASSEMBLY));
PetscCall(MatAssemblyEnd(J,MAT_FINAL_ASSEMBLY));
}
return 0;
}
//ENDRHSJACOBIAN
|
fd5261e437035f0208aa0cd8e22bca24404ac10b
|
36971bb11dddf22b4516a72b59b93cb58ed5558e
|
/kiwi/version.h
|
562d447eb3d2b12a88533c65ea8e6ab62b74f717
|
[
"BSD-3-Clause"
] |
permissive
|
nucleic/kiwi
|
065cda8590b058c4170975dbb5c44240f72723e5
|
03adafeb0f1188e34cde4c7ca8fe384912bd9e1b
|
refs/heads/main
| 2023-08-31T04:21:12.828926
| 2023-08-24T06:51:32
| 2023-08-24T06:51:32
| 14,909,729
| 648
| 98
|
NOASSERTION
| 2023-07-06T05:05:30
| 2013-12-04T00:21:26
|
C++
|
UTF-8
|
C
| false
| false
| 515
|
h
|
version.h
|
/*-----------------------------------------------------------------------------
| Copyright (c) 2013-2022, Nucleic Development Team.
|
| Distributed under the terms of the Modified BSD License.
|
| The full license is in the file LICENSE, distributed with this software.
|----------------------------------------------------------------------------*/
#pragma once
#define KIWI_MAJOR_VERSION 1
#define KIWI_MINOR_VERSION 4
#define KIWI_MICRO_VERSION 2
#define KIWI_VERSION_HEX 0x010402
#define KIWI_VERSION "1.4.2"
|
7fcd887b4793e6a2b9092d798a91afcb4343bd6a
|
cb507ccc0da50fda097f85690f73f50eec0ceb90
|
/Software/Python/grove_chainable_rgb_led/direct_serial_lib/prototype_c_code/PN532SPI.h
|
173631d553a713d241c425c6f06a144d6f753399
|
[
"MIT"
] |
permissive
|
DexterInd/GrovePi
|
cb3ee9b9d73bc668018e953bed38c6077bcfbc5c
|
4a30c93a9900f88281680afd6bf1096e9bc5c359
|
refs/heads/master
| 2022-12-10T01:09:24.513065
| 2022-12-06T16:03:45
| 2022-12-06T16:03:45
| 13,320,430
| 506
| 542
|
NOASSERTION
| 2022-12-06T16:03:47
| 2013-10-04T09:12:30
|
Python
|
UTF-8
|
C
| false
| false
| 2,849
|
h
|
PN532SPI.h
|
/*
The original files can be found in http://blog.iteadstudio.com/to-drive-itead-pn532-nfc-module-with-raspberry-pi/
All the contents are based on that article. I made some modification to the file, removed P2P communication, simplified some codes.
This files(include the header file and source file) are modified by @DaochenShi (shidaochen@live.com)
*/
#ifndef __PN532_H__
#define __PN532_H__
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <wiringPi.h>
#include <wiringPiSPI.h>
#define PN532_PREAMBLE 0x00
#define PN532_STARTCODE1 0x00
#define PN532_STARTCODE2 0xFF
#define PN532_POSTAMBLE 0x00
#define PN532_HOSTTOPN532 0xD4
#define PN532_FIRMWAREVERSION 0x02
#define PN532_GETGENERALSTATUS 0x04
#define PN532_SAMCONFIGURATION 0x14
#define PN532_INLISTPASSIVETARGET 0x4A
#define PN532_INDATAEXCHANGE 0x40
#define PN532_INJUMPFORDEP 0x56
#define PN532_TGINITASTARGET 0x8C
#define PN532_TGGETDATA 0x86
#define PN532_TGSETDATA 0x8E
#define PN532_MIFARE_READ 0x30
#define PN532_MIFARE_WRITE 0xA0
#define PN532_AUTH_WITH_KEYA 0x60
#define PN532_AUTH_WITH_KEYB 0x61
#define PN532_WAKEUP 0x55
#define PN532_SPI_STATREAD 0x02
#define PN532_SPI_DATAWRITE 0x01
#define PN532_SPI_DATAREAD 0x03
#define PN532_SPI_READY 0x01
#define PN532_MIFARE_ISO14443A 0x0
#define KEY_A 1
#define KEY_B 2
#define PN532_BAUDRATE_201K 1
#define PN532_BAUDRATE_424K 2
#define boolean int
#define channel 1
#define byte unsigned char
#define false 0
#define true 1
#define CHIPSELECT
// This is which pin you used for ChipSelect. SPI slave accept the instrctions when its CS pulled to ground.
#ifdef CHIPSELECT
#define _chipSelect 11
#endif
void initialPN532SPI(void);
boolean SAMConfig(void);
uint32_t getFirmwareVersion(void);
uint32_t readPassiveTargetID(uint8_t cardbaudrate);
uint32_t authenticateBlock(
uint8_t cardnumber /*1 or 2*/,
uint32_t cid /*Card NUID*/,
uint8_t blockaddress /*0 to 63*/,
uint8_t authtype /*Either KEY_A or KEY_B */,
uint8_t* keys);
boolean readMemoryBlock(uint8_t cardnumber /*1 or 2*/,uint8_t blockaddress /*0 to 63*/, uint8_t * block);
//boolean writeMemoryBlock(uint8_t cardnumber /*1 or 2*/,uint8_t blockaddress /*0 to 63*/, uint8_t * block);
//uint32_t configurePeerAsInitiator(uint8_t baudrate /* Any number from 0-2. 0 for 106kbps or 1 for 201kbps or 2 for 424kbps */); //106kps is not supported
//uint32_t configurePeerAsTarget();
//boolean initiatorTxRx(char* dataOut,char* dataIn);
//uint32_t targetTxRx(char* dataOut,char* dataIn);
boolean sendCommandCheckAck(uint8_t *cmd, uint8_t cmdlen, uint16_t timeout);
void nfcPN532Write(uint8_t _data);
uint8_t readF(void);
uint8_t readSpiStatus(void);
boolean checkSpiAck();
void nfcPN532Read(uint8_t* buff, uint8_t n);
void writeCommand(uint8_t* cmd, uint8_t cmdlen);
#endif
|
d85b44b90b7e9d0f4442d1460cd660b3d91c5914
|
8838eb997879add5759b6dfb23f9a646464e53ca
|
/src/cmds/hardware/sensors/vl53l0x/vl53l0x.c
|
d4a7f32dea925cbdf2d6e56e131c3315dbeb0dba
|
[
"BSD-2-Clause"
] |
permissive
|
embox/embox
|
d6aacec876978522f01cdc4b8de37a668c6f4c80
|
98e3c06e33f3fdac10a29c069c20775568e0a6d1
|
refs/heads/master
| 2023-09-04T03:02:20.165042
| 2023-09-02T14:55:31
| 2023-09-02T14:55:31
| 33,078,138
| 1,087
| 325
|
BSD-2-Clause
| 2023-09-14T16:58:34
| 2015-03-29T15:27:48
|
C
|
UTF-8
|
C
| false
| false
| 2,809
|
c
|
vl53l0x.c
|
/**
* @file
* @brief
*
* @date 21.04.2023
* @author Andrew Bursian
*/
#include <stdint.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <drivers/diag.h>
//#include <drivers/sensors/vl53l0x.h>
#include "stm32l4xx_hal.h"
#include "stm32l475e_iot01.h"
#include "vl53l0x_def.h"
#include "vl53l0x_api.h"
#include "vl53l0x_tof.h"
#define PROXIMITY_I2C_ADDRESS ((uint16_t)0x0052)
#define VL53L0X_ID ((uint16_t)0xEEAA)
#define VL53L0X_XSHUT_Pin GPIO_PIN_6
#define VL53L0X_XSHUT_GPIO_Port GPIOC
static void VL53L0X_PROXIMITY_MspInit(void);
static uint16_t VL53L0X_PROXIMITY_GetDistance(void);
static int VL53L0X_PROXIMITY_Init(void);
extern void SENSOR_IO_Init(void);
extern I2C_HandleTypeDef hI2cHandler;
static VL53L0X_Dev_t Dev =
{
.I2cHandle = &hI2cHandler,
.I2cDevAddr = PROXIMITY_I2C_ADDRESS
};
int main(int argc, char **argv) {
printf("Testing vl53l0x sensor output\n");
if (VL53L0X_PROXIMITY_Init()) {
printf("Failed to init VL53L0X!\n");
return -1;
}
while (!diag_kbhit()) {
int x = VL53L0X_PROXIMITY_GetDistance();
printf(" Proximity: %d mm \r", x);
fflush(stdout);
usleep(500*1000);
}
printf("\n");
return 0;
}
static int VL53L0X_PROXIMITY_Init(void)
{
uint16_t vl53l0x_id = 0;
VL53L0X_DeviceInfo_t VL53L0X_DeviceInfo;
/* Initialize IO interface */
SENSOR_IO_Init();
VL53L0X_PROXIMITY_MspInit();
memset(&VL53L0X_DeviceInfo, 0, sizeof(VL53L0X_DeviceInfo_t));
if (VL53L0X_ERROR_NONE != VL53L0X_GetDeviceInfo(&Dev, &VL53L0X_DeviceInfo)) {
printf("VL53L0X: Failed to get infos!\n");
return -1;
}
if (VL53L0X_ERROR_NONE != VL53L0X_RdWord(&Dev, VL53L0X_REG_IDENTIFICATION_MODEL_ID, (uint16_t *) &vl53l0x_id)) {
printf("VL53L0X: Failed to Initialize!\n");
return -1;
}
if (vl53l0x_id != VL53L0X_ID) {
printf("VL53L0X: Failed to send its ID!\n");
return -1;
}
if (VL53L0X_ERROR_NONE != VL53L0X_DataInit(&Dev)) {
printf("VL53L0X_DataInit() failed!\n");
return -1;
}
Dev.Present = 1;
SetupSingleShot(Dev);
return 0;
}
static void VL53L0X_PROXIMITY_MspInit(void)
{
GPIO_InitTypeDef GPIO_InitStruct;
/*Configure GPIO pin : VL53L0X_XSHUT_Pin */
GPIO_InitStruct.Pin = VL53L0X_XSHUT_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
HAL_GPIO_Init(VL53L0X_XSHUT_GPIO_Port, &GPIO_InitStruct);
HAL_GPIO_WritePin(VL53L0X_XSHUT_GPIO_Port, VL53L0X_XSHUT_Pin, GPIO_PIN_SET);
HAL_Delay(1000);
}
static uint16_t VL53L0X_PROXIMITY_GetDistance(void)
{
VL53L0X_RangingMeasurementData_t RangingMeasurementData;
VL53L0X_PerformSingleRangingMeasurement(&Dev, &RangingMeasurementData);
return RangingMeasurementData.RangeMilliMeter;
}
|
6fe54ea27788cb7b3cc5337c0a7187fc92014d4c
|
110044654f706e920380dad2779bb32a77f1f26f
|
/test/D/MixedDAndC/Image/cmod.c
|
72ace7b56d5eeccee689ba04f444460ea91da691
|
[
"MIT",
"LicenseRef-scancode-free-unknown",
"LicenseRef-scancode-unknown-license-reference"
] |
permissive
|
SCons/scons
|
89327bb9635cee6e7cc59249edca9cd859d7d1ff
|
b2a7d7066a2b854460a334a5fe737ea389655e6e
|
refs/heads/master
| 2023-09-01T19:37:03.603772
| 2023-08-28T04:32:42
| 2023-08-28T04:32:42
| 104,670,160
| 1,827
| 342
|
MIT
| 2023-09-14T15:13:21
| 2017-09-24T19:23:46
|
Python
|
UTF-8
|
C
| false
| false
| 110
|
c
|
cmod.c
|
// SPDX-License-Identifier: MIT
//
// Copyright The SCons Foundation
int csqr(int arg) {
return arg*arg;
}
|
b04c3bbc144e496c43ade2ec86b07e7a32fe5bae
|
0ad1c3ca518de95e3312695022744975fa382e51
|
/Player/AsyncGetUrlUnderMouseCursor.h
|
4125011dbc4e6aa2fc355a3c42f94b954cc3692a
|
[
"MIT"
] |
permissive
|
aliakseis/FFmpegPlayer
|
924397a6243e7eb4e3d8becc9f832d24288e4552
|
377ef823db72a8dd32d28a31ada015e309ec1469
|
refs/heads/master
| 2023-08-22T12:52:39.817250
| 2023-08-07T20:34:52
| 2023-08-07T20:34:52
| 37,139,532
| 118
| 48
|
MIT
| 2023-03-05T16:51:46
| 2015-06-09T15:09:27
|
C++
|
UTF-8
|
C
| false
| false
| 84
|
h
|
AsyncGetUrlUnderMouseCursor.h
|
#pragma once
enum { WM_ON_ASYNC_URL = 1234 };
void AsyncGetUrlUnderMouseCursor();
|
b064828dd79414ffa319794d01258ca34fa3707c
|
f3eed0234b4d0ad2bbb2abd700cf1e2c7a0e8a1d
|
/AKWF-c/AKWF_bw_squrounded/AKWF_rAsymSqu_09.h
|
706a8f00499ea9dc2fc5e3688c695601fe63696e
|
[
"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,686
|
h
|
AKWF_rAsymSqu_09.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_rAsymSqu_09 256 samples
+-----------------------------------------------------------------------------------------------------------------+
| ********* ** |
| **** * |
| *** ** |
| *** * |
| ** * |
| * ** |
|* ** |
| * |
| ** *|
| ** **|
| ** * |
| *** ** |
| *** * |
| **** * |
| ******** ** |
+-----------------------------------------------------------------------------------------------------------------+
*/
const uint16_t AKWF_rAsymSqu_09 [] = {
33196, 35145, 37069, 38856, 40542, 42107, 43592, 44964, 46270, 47473, 48620, 49677, 50685, 51611, 52498, 53312,
54088, 54803, 55486, 56114, 56712, 57266, 57790, 58276, 58736, 59165, 59568, 59943, 60295, 60627, 60936, 61228,
61498, 61755, 61992, 62218, 62427, 62625, 62808, 62983, 63142, 63294, 63437, 63570, 63694, 63812, 63921, 64024,
64120, 64211, 64295, 64374, 64448, 64518, 64584, 64644, 64702, 64754, 64805, 64852, 64896, 64938, 64977, 65012,
65047, 65078, 65110, 65137, 65162, 65188, 65211, 65232, 65252, 65271, 65289, 65305, 65321, 65336, 65350, 65361,
65374, 65385, 65397, 65406, 65415, 65424, 65433, 65440, 65446, 65455, 65460, 65467, 65470, 65478, 65481, 65486,
65488, 65496, 65496, 65502, 65505, 65509, 65509, 65514, 65515, 65518, 65520, 65522, 65525, 65525, 65529, 65527,
65535, 65528, 65535, 65527, 65481, 64184, 61283, 57895, 54416, 51069, 47875, 44877, 42052, 39408, 36926, 34603,
32425, 30384, 28471, 26678, 24999, 23423, 21950, 20565, 19272, 18057, 16920, 15854, 14857, 13919, 13043, 12220,
11451, 10729, 10054, 9419, 8826, 8269, 7747, 7259, 6800, 6371, 5969, 5594, 5241, 4910, 4599, 4309,
4036, 3782, 3543, 3319, 3109, 2913, 2728, 2554, 2394, 2242, 2099, 1966, 1841, 1724, 1614, 1513,
1416, 1325, 1241, 1161, 1088, 1018, 953, 892, 834, 781, 731, 683, 640, 598, 559, 524,
489, 457, 427, 398, 373, 349, 326, 305, 283, 265, 247, 231, 214, 201, 186, 174,
161, 151, 140, 130, 120, 112, 104, 96, 90, 81, 77, 68, 67, 58, 57, 48,
49, 40, 41, 33, 33, 26, 28, 21, 22, 16, 17, 14, 11, 11, 6, 10,
1, 11, 0, 13, 51, 1358, 4247, 7649, 11112, 14477, 17650, 20673, 23467, 26149, 28579, 30990,
};
|
82df9e7ea98ead25f5b8a2f309bb4abd06c073c3
|
fdbb74a95924e2677466614f6ab6e2bb13b2a95a
|
/libc/isystem/net/if.h
|
dd43a30dd516deac47b1e80516f56035d0db879e
|
[
"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
| 244
|
h
|
if.h
|
#ifndef COSMOPOLITAN_LIBC_ISYSTEM_NET_IF_H_
#define COSMOPOLITAN_LIBC_ISYSTEM_NET_IF_H_
#include "libc/sock/struct/ifconf.h"
#include "libc/sock/struct/ifreq.h"
#include "libc/sysv/consts/iff.h"
#endif /* COSMOPOLITAN_LIBC_ISYSTEM_NET_IF_H_ */
|
2e0b9b91050e2447a8199b7bc5b21094978c7503
|
57d291312405dd9093fbca45743984ab56c549d0
|
/include/siri/version.h
|
52b8907c1a6c340693fe56a6d8e4175646451eb9
|
[
"MIT"
] |
permissive
|
SiriDB/siridb-server
|
159f9cc8f0f53401a5507e0394929f828f80a244
|
f0edd48c02bc18a39c8bdfd53b9b179b8c216f86
|
refs/heads/master
| 2023-08-19T09:17:38.075457
| 2023-03-21T10:24:13
| 2023-03-21T10:24:13
| 55,093,657
| 176
| 24
|
MIT
| 2022-09-17T06:59:52
| 2016-03-30T19:58:40
|
C
|
UTF-8
|
C
| false
| false
| 1,352
|
h
|
version.h
|
/*
* version.h - SiriDB version info.
*/
#ifndef SIRI_VERSION_H_
#define SIRI_VERSION_H_
#define SIRIDB_VERSION_MAJOR 2
#define SIRIDB_VERSION_MINOR 0
#define SIRIDB_VERSION_PATCH 50
/*
* Use SIRIDB_VERSION_PRE_RELEASE for alpha release versions.
* This should be an empty string when building a final release.
* Examples: "-alpha-0" "-alpha-1", ""
* Note that debian alpha packages should use versions like this:
* 2.0.34-0alpha0
*/
#define SIRIDB_VERSION_PRE_RELEASE ""
#ifndef NDEBUG
#define SIRIDB_VERSION_BUILD_RELEASE "+debug"
#else
#define SIRIDB_VERSION_BUILD_RELEASE ""
#endif
#define SIRIDB_STRINGIFY(num) #num
#define SIRIDB_VERSION_STR(major,minor,patch) \
SIRIDB_STRINGIFY(major) "." \
SIRIDB_STRINGIFY(minor) "." \
SIRIDB_STRINGIFY(patch)
#define SIRIDB_VERSION SIRIDB_VERSION_STR( \
SIRIDB_VERSION_MAJOR, \
SIRIDB_VERSION_MINOR, \
SIRIDB_VERSION_PATCH) \
SIRIDB_VERSION_PRE_RELEASE \
SIRIDB_VERSION_BUILD_RELEASE
#define SIRIDB_CONTRIBUTERS \
"https://github.com/SiriDB/siridb-server/contributors"
#define SIRIDB_HOME_PAGE \
"https://siridb.net"
int siri_version_cmp(const char * version_a, const char * version_b);
/* SiriDB can only connect with servers having at least this version. */
#define SIRIDB_MINIMAL_VERSION "2.0.0"
#endif /* SIRI_VERSION_H_ */
|
c2d1cee0fc096d4d821db372f82dfcc1b1491bbf
|
ded35da1b23aac56f52c8602b710033427d7bf0c
|
/C/BiosLib/strupr.c
|
1ad6f04961a16c07929b685416e18bdf633a43ac
|
[
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-generic-cla"
] |
permissive
|
JFLarvoire/SysToolsLib
|
82575f9c196691be9c35d96eec3ea3212392d013
|
60926b5736a493331fa08b80eb1f8e974ee05506
|
refs/heads/master
| 2023-04-28T08:10:19.564222
| 2023-04-23T18:02:14
| 2023-04-23T18:02:14
| 56,332,727
| 293
| 108
|
Apache-2.0
| 2022-04-13T11:38:17
| 2016-04-15T16:03:02
|
C
|
UTF-8
|
C
| false
| false
| 1,575
|
c
|
strupr.c
|
/*****************************************************************************\
* *
* File name: STRUPR.C *
* *
* Description: C library routines for use in an environment where the *
* standard libraries can't be used. *
* *
* Notes: *
* *
* History: *
* 1993/10/06 JFL Separated this file from CLIBC.C. *
* *
* (c) Copyright 1995-2017 Hewlett Packard Enterprise Development LP *
* Licensed under the Apache 2.0 license - www.apache.org/licenses/LICENSE-2.0 *
\*****************************************************************************/
#include "clibdef.h" /* Make sure our implementation matches the
definition there */
//+--------------------------------------------------------------------------
//+ Function : strupr
//+
//+ Purpose : Redefinition of a C library routine
//+
//+ Parameters : See a C library reference for the list of arguments
//+
//+ Return : See a C library reference for the return value.
//+
//+ Notes: :
//+
//+ Creation : 14-dec-1995 by JFL
//+
//+ Modification History:
//+ Date Author Description
//+ ----------- ------ ----------------------------------------------------
//+
//+--------------------------------------------------------------------------
char *strupr(char *s)
{
char c;
char *s0;
s0 = s;
while (c = *s)
{
*s = toupper(c);
s += 1;
}
return s0;
}
|
7709ef2f01c98767563c85d79f8ca887e183afe3
|
a07b39497632c8fb57e3a948eb552c52d7e73e43
|
/src/picotorrent/version.h
|
a60ea20025dd53d3a60b13e33dca384bd4be92cb
|
[
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] |
permissive
|
picotorrent/picotorrent
|
59f4aa718c9f95acefbc0fc1c6395919956e12be
|
c7f9975e792c68faed6ede41efa36ac6b0177a35
|
refs/heads/master
| 2023-06-20T04:26:57.150925
| 2023-05-20T17:16:00
| 2023-05-20T17:16:00
| 38,457,549
| 2,760
| 336
|
MIT
| 2023-08-20T14:24:09
| 2015-07-02T21:21:34
|
C++
|
UTF-8
|
C
| false
| false
| 1,168
|
h
|
version.h
|
#pragma once
#include <winver.h>
#define STRINGIZE2(s) #s
#define STRINGIZE(s) STRINGIZE2(s)
#define VER_FILE_DESCRIPTION_STR "PicoTorrent"
#define VER_FILE_VERSION PICO_VERSION_MAJOR, PICO_VERSION_MINOR, PICO_VERSION_PATCH
#define VER_FILE_VERSION_STR STRINGIZE(PICO_VERSION_MAJOR) \
"." STRINGIZE(PICO_VERSION_MINOR) \
"." STRINGIZE(PICO_VERSION_PATCH) \
" (" STRINGIZE(PICO_GIT_COMMITISH) ")" \
#define VER_PRODUCTNAME_STR "PicoTorrent"
#define VER_PRODUCT_VERSION VER_FILE_VERSION
#define VER_PRODUCT_VERSION_STR VER_FILE_VERSION_STR
#define VER_ORIGINAL_FILENAME_STR VER_PRODUCTNAME_STR ".exe"
#define VER_INTERNAL_NAME_STR VER_ORIGINAL_FILENAME_STR
#define VER_COPYRIGHT_STR "Copyright (C) 2020, PicoTorrent contributors"
#ifdef _DEBUG
#define VER_VER_DEBUG VS_FF_DEBUG
#else
#define VER_VER_DEBUG 0
#endif
#define VER_FILEOS 0x00040004
#define VER_FILEFLAGS VER_VER_DEBUG
#define VER_FILETYPE 0x00000001
|
127e5711c682a1741607ecb2af897ce12014a656
|
7d3d2af0389f9c0dee5d7ca789660bf21d97249d
|
/blasfeo_hp_cm/dpotrf.c
|
bc9d18a36cdcb5bf61bcd62fdb45d4e974b849db
|
[
"BSD-2-Clause"
] |
permissive
|
giaf/blasfeo
|
0ecbcd67429d0507d7f462c090037c388e84a49e
|
b85a0c3121eae491480f07774fedf67e76b1f038
|
refs/heads/master
| 2023-07-22T15:40:53.961071
| 2023-07-18T15:42:08
| 2023-07-18T15:42:08
| 70,173,581
| 248
| 78
|
NOASSERTION
| 2022-11-25T15:42:08
| 2016-10-06T16:48:09
|
Assembly
|
UTF-8
|
C
| false
| false
| 65,836
|
c
|
dpotrf.c
|
/**************************************************************************************************
* *
* This file is part of BLASFEO. *
* *
* BLASFEO -- BLAS for embedded optimization. *
* Copyright (C) 2019 by Gianluca Frison. *
* Developed at IMTEK (University of Freiburg) under the supervision of Moritz Diehl. *
* All rights reserved. *
* *
* The 2-Clause BSD License *
* *
* Redistribution and use in source and binary forms, with or without *
* modification, are permitted provided that the following conditions are met: *
* *
* 1. Redistributions of source code must retain the above copyright notice, this *
* list of conditions and the following disclaimer. *
* 2. Redistributions in binary form must reproduce the above copyright notice, *
* this list of conditions and the following disclaimer in the documentation *
* and/or other materials provided with the distribution. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND *
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED *
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE *
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR *
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; *
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND *
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
* *
* Author: Gianluca Frison, gianluca.frison (at) imtek.uni-freiburg.de *
* *
**************************************************************************************************/
#include <stdlib.h>
#include <stdio.h>
//#define PRINT_NAME
#include <blasfeo_target.h>
#include <blasfeo_block_size.h>
#include <blasfeo_common.h>
#include <blasfeo_d_aux.h>
#include <blasfeo_d_kernel.h>
#include <blasfeo_stdlib.h>
#include <blasfeo_memory.h>
#if ( defined(BLAS_API) & defined(MF_PANELMAJ) )
#define blasfeo_dmat blasfeo_cm_dmat
#define blasfeo_hp_dpotrf_l blasfeo_hp_cm_dpotrf_l
#define blasfeo_hp_dpotrf_u blasfeo_hp_cm_dpotrf_u
#define blasfeo_hp_dpotrf_l_mn blasfeo_hp_cm_dpotrf_l_mn
#define blasfeo_dpotrf_l blasfeo_cm_dpotrf_l
#define blasfeo_dpotrf_u blasfeo_cm_dpotrf_u
#define blasfeo_dpotrf_l_mn blasfeo_cm_dpotrf_l_mn
#endif
#if ( defined(BLAS_API) & defined(MF_PANELMAJ) )
#define blasfeo_hp_dtrsm_rltn blasfeo_hp_cm_dtrsm_rltn
#define blasfeo_hp_dsyrk3_ln blasfeo_hp_cm_dsyrk3_ln
#endif
#include <blasfeo_d_blasfeo_hp_api.h>
#define CACHE_LINE_EL D_CACHE_LINE_EL
#define L1_CACHE_EL D_L1_CACHE_EL
#define L2_CACHE_EL D_L2_CACHE_EL
#define LLC_CACHE_EL D_LLC_CACHE_EL
#define PS D_PS
#define M_KERNEL D_M_KERNEL
#define N_KERNEL D_N_KERNEL
#define KC D_KC
#define NC D_NC
#define MC D_MC
static void blasfeo_hp_dpotrf_l_mn_m2(int m, int n, double *C, int ldc, double *D, int ldd, double *pA, double *dA, int sda)
{
int ii, jj;
int kend;
double d_1 = 1.0;
#if defined(TARGET_X64_INTEL_SKYLAKE_X)
const int ps = 4; // XXX TODO fix once implemented missing kernels !!!
#else
const int ps = PS;
#endif
ii = 0;
#if defined(TARGET_X64_INTEL_HASWELL) | defined(TARGET_ARMV8A_ARM_CORTEX_A53)
for(; ii<m-11; ii+=12)
{
jj = 0;
for(; jj<ii & jj<n-3; jj+=4)
{
kernel_dtrsm_nt_rl_inv_12x4_lib44ccc(jj, pA+ii*sda, sda, pA+jj*sda, C+ii+jj*ldc, ldc, D+ii+jj*ldd, ldd, D+jj+jj*ldd, ldd, dA+jj);
kernel_dpack_nn_12_lib4(4, D+ii+jj*ldd, ldd, pA+ii*sda+jj*ps, sda);
}
if(jj<n)
{
if(jj<ii) // dtrsm
{
kernel_dtrsm_nt_rl_inv_12x4_vs_lib44ccc(jj, pA+ii*sda, sda, pA+jj*sda, C+ii+jj*ldc, ldc, D+ii+jj*ldd, ldd, D+jj+jj*ldd, ldd, dA+jj, m-ii, n-jj);
kend = n-jj<4 ? n-jj : 4;
kernel_dpack_nn_12_vs_lib4(kend, D+ii+jj*ldd, ldd, pA+ii*sda+jj*ps, sda, m-ii);
}
else // dpotrf
{
if(jj<n-11)
{
kernel_dpotrf_nt_l_12x4_lib44cc(jj, pA+ii*sda, sda, pA+jj*sda, C+ii+jj*ldc, ldc, D+ii+jj*ldd, ldd, dA+jj);
kernel_dpack_nn_8_lib4(4, D+ii+4+jj*ldd, ldd, pA+(ii+4)*sda+jj*ps, sda);
#if defined(TARGET_X64_INTEL_HASWELL)
kernel_dpotrf_nt_l_8x8_lib44cc(jj+4, pA+(ii+4)*sda, sda, pA+(jj+4)*sda, sda, C+ii+4+(jj+4)*ldc, ldc, D+ii+4+(jj+4)*ldd, ldd, dA+jj+4);
kernel_dpack_nn_4_lib4(4, D+ii+8+(jj+4)*ldd, ldd, pA+(ii+8)*sda+(jj+4)*ps);
#else
kernel_dpotrf_nt_l_8x4_lib44cc(jj+4, pA+(ii+4)*sda, sda, pA+(jj+4)*sda, C+ii+4+(jj+4)*ldc, ldc, D+ii+4+(jj+4)*ldd, ldd, dA+jj+4);
kernel_dpack_nn_4_lib4(4, D+ii+8+(jj+4)*ldd, ldd, pA+(ii+8)*sda+(jj+4)*ps);
kernel_dpotrf_nt_l_4x4_lib44cc(jj+8, pA+(ii+8)*sda, pA+(jj+8)*sda, C+ii+8+(jj+8)*ldc, ldc, D+ii+8+(jj+8)*ldd, ldd, dA+jj+8);
#endif
}
else
{
kernel_dpotrf_nt_l_12x4_vs_lib44cc(jj, pA+ii*sda, sda, pA+jj*sda, C+ii+jj*ldc, ldc, D+ii+jj*ldd, ldd, dA+jj, m-ii, n-jj);
kend = n-jj<4 ? n-jj : 4;
kernel_dpack_nn_8_vs_lib4(kend, D+ii+4+jj*ldd, ldd, pA+(ii+4)*sda+jj*ps, sda, m-ii);
#if defined(TARGET_X64_INTEL_HASWELL)
if(jj<n-8)
{
kernel_dpotrf_nt_l_8x8_vs_lib44cc(jj+4, pA+(ii+4)*sda, sda, pA+(jj+4)*sda, sda, C+ii+4+(jj+4)*ldc, ldc, D+ii+4+(jj+4)*ldd, ldd, dA+jj+4, m-ii-4, n-jj-4);
kend = n-jj-4<4 ? n-jj-4 : 4;
kernel_dpack_nn_4_vs_lib4(kend, D+ii+8+(jj+4)*ldd, ldd, pA+(ii+8)*sda+(jj+4)*ps, m-ii-4);
}
else
{
#endif
if(jj<n-4)
{
kernel_dpotrf_nt_l_8x4_vs_lib44cc(jj+4, pA+(ii+4)*sda, sda, pA+(jj+4)*sda, C+ii+4+(jj+4)*ldc, ldc, D+ii+4+(jj+4)*ldd, ldd, dA+jj+4, m-ii-4, n-jj-4);
kend = n-jj-4<4 ? n-jj-4 : 4;
kernel_dpack_nn_4_vs_lib4(kend, D+ii+8+(jj+4)*ldd, ldd, pA+(ii+8)*sda+(jj+4)*ps, m-ii-4);
if(jj<n-8)
{
kernel_dpotrf_nt_l_4x4_vs_lib44cc(jj+8, pA+(ii+8)*sda, pA+(jj+8)*sda, C+ii+8+(jj+8)*ldc, ldc, D+ii+8+(jj+8)*ldd, ldd, dA+jj+8, m-ii-8, n-jj-8);
}
}
#if defined(TARGET_X64_INTEL_HASWELL)
}
#endif
}
}
}
}
if(ii<m)
{
if(m-ii<=4)
{
goto l_1_left_4;
}
if(m-ii<=8)
{
goto l_1_left_8;
}
else
{
goto l_1_left_12;
}
}
#elif defined(TARGET_X64_INTEL_SANDY_BRIDGE) | defined(TARGET_ARMV8A_ARM_CORTEX_A57)
for(; ii<m-7; ii+=8)
{
jj = 0;
for(; jj<ii & jj<n-3; jj+=4)
{
kernel_dtrsm_nt_rl_inv_8x4_lib44ccc(jj, pA+ii*sda, sda, pA+jj*sda, C+ii+jj*ldc, ldc, D+ii+jj*ldd, ldd, D+jj+jj*ldd, ldd, dA+jj);
kernel_dpack_nn_8_lib4(4, D+ii+jj*ldd, ldd, pA+ii*sda+jj*ps, sda);
}
if(jj<n)
{
if(jj<ii) // dtrsm
{
kernel_dtrsm_nt_rl_inv_8x4_vs_lib44ccc(jj, pA+ii*sda, sda, pA+jj*sda, C+ii+jj*ldc, ldc, D+ii+jj*ldd, ldd, D+jj+jj*ldd, ldd, dA+jj, m-ii, n-jj);
kend = n-jj<4 ? n-jj : 4;
kernel_dpack_nn_8_vs_lib4(kend, D+ii+jj*ldd, ldd, pA+ii*sda+jj*ps, sda, m-ii);
}
else // dpotrf
{
if(jj<n-7)
{
kernel_dpotrf_nt_l_8x4_lib44cc(jj, pA+ii*sda, sda, pA+jj*sda, C+ii+jj*ldc, ldc, D+ii+jj*ldd, ldd, dA+jj);
kernel_dpack_nn_4_lib4(4, D+ii+4+jj*ldd, ldd, pA+(ii+4)*sda+jj*ps);
kernel_dpotrf_nt_l_4x4_lib44cc(jj+4, pA+(ii+4)*sda, pA+(jj+4)*sda, C+ii+4+(jj+4)*ldc, ldc, D+ii+4+(jj+4)*ldd, ldd, dA+jj+4);
}
else
{
kernel_dpotrf_nt_l_8x4_vs_lib44cc(jj, pA+ii*sda, sda, pA+jj*sda, C+ii+jj*ldc, ldc, D+ii+jj*ldd, ldd, dA+jj, m-ii, n-jj);
kend = n-jj<4 ? n-jj : 4;
kernel_dpack_nn_4_vs_lib4(kend, D+ii+4+jj*ldd, ldd, pA+(ii+4)*sda+jj*ps, m-ii-4);
if(jj<n-4)
{
kernel_dpotrf_nt_l_4x4_vs_lib44cc(jj+4, pA+(ii+4)*sda, pA+(jj+4)*sda, C+ii+4+(jj+4)*ldc, ldc, D+ii+4+(jj+4)*ldd, ldd, dA+jj+4, m-ii-4, n-jj-4);
}
}
}
}
}
if(ii<m)
{
if(m-ii<=4)
{
goto l_1_left_4;
}
else
{
goto l_1_left_8;
}
}
#else
for(; ii<m-3; ii+=4)
{
jj = 0;
for(; jj<ii & jj<n-3; jj+=4)
{
kernel_dtrsm_nt_rl_inv_4x4_lib44ccc(jj, pA+ii*sda, pA+jj*sda, &d_1, C+ii+jj*ldc, ldc, D+ii+jj*ldd, ldd, D+jj+jj*ldd, ldd, dA+jj);
kernel_dpack_nn_4_lib4(4, D+ii+jj*ldd, ldd, pA+ii*sda+jj*ps);
}
if(jj<n)
{
if(jj<ii) // dtrsm
{
kernel_dtrsm_nt_rl_inv_4x4_vs_lib44ccc(jj, pA+ii*sda, pA+jj*sda, &d_1, C+ii+jj*ldc, ldc, D+ii+jj*ldd, ldd, D+jj+jj*ldd, ldd, dA+jj, m-ii, n-jj);
kend = n-jj<4 ? n-jj : 4;
kernel_dpack_nn_4_vs_lib4(kend, D+ii+jj*ldd, ldd, pA+ii*sda+jj*ps, m-ii);
}
else // dpotrf
{
if(jj<n-3)
{
kernel_dpotrf_nt_l_4x4_lib44cc(jj, pA+ii*sda, pA+jj*sda, C+ii+jj*ldc, ldc, D+ii+jj*ldd, ldd, dA+jj);
}
else
{
kernel_dpotrf_nt_l_4x4_vs_lib44cc(jj, pA+ii*sda, pA+jj*sda, C+ii+jj*ldc, ldc, D+ii+jj*ldd, ldd, dA+jj, m-ii, n-jj);
}
}
}
}
if(ii<m)
{
goto l_1_left_4;
}
#endif
goto l_1_return;
#if defined(TARGET_X64_INTEL_HASWELL) | defined(TARGET_ARMV8A_ARM_CORTEX_A53)
l_1_left_12:
jj = 0;
for(; jj<ii & jj<n; jj+=4)
{
kernel_dtrsm_nt_rl_inv_12x4_vs_lib44ccc(jj, pA+ii*sda, sda, pA+jj*sda, C+ii+jj*ldc, ldc, D+ii+jj*ldd, ldd, D+jj+jj*ldd, ldd, dA+jj, m-ii, n-jj);
kend = n-jj<4 ? n-jj : 4;
kernel_dpack_nn_12_vs_lib4(kend, D+ii+jj*ldd, ldd, pA+ii*sda+jj*ps, sda, m-ii);
}
if(jj<n)
{
kernel_dpotrf_nt_l_12x4_vs_lib44cc(jj, pA+ii*sda, sda, pA+jj*sda, C+ii+jj*ldc, ldc, D+ii+jj*ldd, ldd, dA+jj, m-ii, n-jj);
kend = n-jj<4 ? n-jj : 4;
kernel_dpack_nn_8_vs_lib4(kend, D+ii+4+jj*ldd, ldd, pA+(ii+4)*sda+jj*ps, sda, m-ii-4);
#if defined(TARGET_X64_INTEL_HASWELL)
if(jj<n-8)
{
kernel_dpotrf_nt_l_8x8_vs_lib44cc(jj+4, pA+(ii+4)*sda, sda, pA+(jj+4)*sda, sda, C+ii+4+(jj+4)*ldc, ldc, D+ii+4+(jj+4)*ldd, ldd, dA+jj+4, m-(ii+4), n-(jj+4));
kend = n-jj-4<4 ? n-jj-4 : 4;
kernel_dpack_nn_4_vs_lib4(kend, D+ii+8+(jj+4)*ldd, ldd, pA+(ii+8)*sda+(jj+4)*ps, m-ii-8);
goto l_1_return;
}
#endif
if(jj<n-4)
{
kernel_dpotrf_nt_l_8x4_vs_lib44cc(jj+4, pA+(ii+4)*sda, sda, pA+(jj+4)*sda, C+ii+4+(jj+4)*ldc, ldc, D+ii+4+(jj+4)*ldd, ldd, dA+jj+4, m-(ii+4), n-(jj+4));
kend = n-jj-4<4 ? n-jj-4 : 4;
kernel_dpack_nn_4_vs_lib4(kend, D+ii+8+(jj+4)*ldd, ldd, pA+(ii+8)*sda+(jj+4)*ps, m-ii-8);
if(jj<n-8)
{
kernel_dpotrf_nt_l_4x4_vs_lib44cc(jj+8, pA+(ii+8)*sda, pA+(jj+8)*sda, C+ii+8+(jj+8)*ldc, ldc, D+ii+8+(jj+8)*ldd, ldd, dA+jj+8, m-ii-8, n-jj-8);
}
}
}
goto l_1_return;
#endif
#if defined(TARGET_X64_INTEL_HASWELL) | defined(TARGET_X64_INTEL_SANDY_BRIDGE) | defined(TARGET_ARMV8A_ARM_CORTEX_A57) | defined(TARGET_ARMV8A_ARM_CORTEX_A53)
l_1_left_8:
for(jj=0; jj<ii & jj<n; jj+=4)
{
kernel_dtrsm_nt_rl_inv_8x4_vs_lib44ccc(jj, pA+ii*sda, sda, pA+jj*sda, C+ii+jj*ldc, ldc, D+ii+jj*ldd, ldd, D+jj+jj*ldd, ldd, dA+jj, m-ii, n-jj);
kend = n-jj<4 ? n-jj : 4;
kernel_dpack_nn_8_vs_lib4(kend, D+ii+jj*ldd, ldd, pA+ii*sda+jj*ps, sda, m-ii);
}
if(jj<n)
{
#if defined(TARGET_X64_INTEL_HASWELL)
if(jj<n-4)
{
kernel_dpotrf_nt_l_8x8_vs_lib44cc(jj, pA+ii*sda, sda, pA+jj*sda, sda, C+ii+jj*ldc, ldc, D+ii+jj*ldd, ldd, dA+jj, m-ii, n-jj);
kend = n-jj<4 ? n-jj : 4;
kernel_dpack_nn_4_vs_lib4(kend, D+ii+4+jj*ldd, ldd, pA+(ii+4)*sda+jj*ps, m-ii-4);
goto l_1_return;
}
#endif
kernel_dpotrf_nt_l_8x4_vs_lib44cc(jj, pA+ii*sda, sda, pA+jj*sda, C+ii+jj*ldc, ldc, D+ii+jj*ldd, ldd, dA+jj, m-ii, n-jj);
kend = n-jj<4 ? n-jj : 4;
kernel_dpack_nn_4_vs_lib4(kend, D+ii+4+jj*ldd, ldd, pA+(ii+4)*sda+jj*ps, m-ii-4);
if(jj<n-4)
{
kernel_dpotrf_nt_l_4x4_vs_lib44cc(jj+4, pA+(ii+4)*sda, pA+(jj+4)*sda, C+ii+4+(jj+4)*ldc, ldc, D+ii+4+(jj+4)*ldd, ldd, dA+jj+4, m-ii-4, n-jj-4);
}
}
goto l_1_return;
#endif
l_1_left_4:
for(jj=0; jj<ii & jj<n; jj+=4)
{
kernel_dtrsm_nt_rl_inv_4x4_vs_lib44ccc(jj, pA+ii*sda, pA+jj*sda, &d_1, C+ii+jj*ldc, ldc, D+ii+jj*ldd, ldd, D+jj+jj*ldd, ldd, dA+jj, m-ii, n-jj);
kend = n-jj<4 ? n-jj : 4;
kernel_dpack_nn_4_vs_lib4(kend, D+ii+jj*ldd, ldd, pA+ii*sda+jj*ps, m-ii);
}
if(jj<n)
{
kernel_dpotrf_nt_l_4x4_vs_lib44cc(jj, pA+ii*sda, pA+jj*sda, C+ii+jj*ldc, ldc, D+ii+jj*ldd, ldd, dA+jj, m-ii, n-jj);
}
goto l_1_return;
l_1_return:
return;
}
static void blasfeo_hp_dsyrk_ln_mn_m2(int m, int n, int k, double alpha, double *pA, int sda, double *pB, int sdb, double beta, double *C, int ldc, double *D, int ldd)
{
int ii, jj;
int kend;
double d_1 = 1.0;
#if defined(TARGET_X64_INTEL_SKYLAKE_X)
const int ps = 4; // XXX TODO fix once implemented missing kernels !!!
#else
const int ps = PS;
#endif
ii = 0;
#if defined(TARGET_X64_INTEL_HASWELL) | defined(TARGET_ARMV8A_ARM_CORTEX_A53)
for(; ii<m-11; ii+=12)
{
for(jj=0; jj<ii & jj<n-3; jj+=4)
{
kernel_dgemm_nt_12x4_lib44cc(k, &alpha, pA+ii*sda, sda, pB+jj*sdb, &beta, C+ii+jj*ldc, ldc, D+ii+jj*ldd, ldd);
}
if(jj<n)
{
if(jj<ii) // dgemm
{
kernel_dgemm_nt_12x4_vs_lib44cc(k, &alpha, pA+ii*sda, sda, pB+jj*sdb, &beta, C+ii+jj*ldc, ldc, D+ii+jj*ldd, ldd, m-ii, n-jj);
}
else // dsyrk
{
if(jj<n-11)
{
kernel_dsyrk_nt_l_12x4_lib44cc(k, &alpha, pA+ii*sda, sda, pB+jj*sdb, &beta, C+ii+jj*ldc, ldc, D+ii+jj*ldd, ldd);
// kernel_dsyrk_nt_l_8x8_lib44cc(k, &alpha, pA+(ii+4)*sda, sda, pB+(jj+4)*sdb, sdb, &beta, C+(ii+4)+(jj+4)*ldc, ldc, D+(ii+4)+(jj+4)*ldd, ldd);
kernel_dsyrk_nt_l_8x4_lib44cc(k, &alpha, pA+(ii+4)*sda, sda, pB+(jj+4)*sdb, &beta, C+(ii+4)+(jj+4)*ldc, ldc, D+(ii+4)+(jj+4)*ldd, ldd);
kernel_dsyrk_nt_l_4x4_lib44cc(k, &alpha, pA+(ii+8)*sda, pB+(jj+8)*sdb, &beta, C+(ii+8)+(jj+8)*ldc, ldc, D+(ii+8)+(jj+8)*ldd, ldd);
}
else
{
kernel_dsyrk_nt_l_12x4_vs_lib44cc(k, &alpha, pA+ii*sda, sda, pB+jj*sdb, &beta, C+ii+jj*ldc, ldc, D+ii+jj*ldd, ldd, m-ii, n-jj);
if(jj<n-4)
{
kernel_dsyrk_nt_l_8x4_vs_lib44cc(k, &alpha, pA+(ii+4)*sda, sda, pB+(jj+4)*sdb, &beta, C+(ii+4)+(jj+4)*ldc, ldc, D+(ii+4)+(jj+4)*ldd, ldd, m-ii-4, n-jj-4);
if(jj<n-8)
{
kernel_dsyrk_nt_l_4x4_vs_lib44cc(k, &alpha, pA+(ii+8)*sda, pB+(jj+8)*sdb, &beta, C+(ii+8)+(jj+8)*ldc, ldc, D+(ii+8)+(jj+8)*ldd, ldd, m-ii-8, n-jj-8);
}
}
}
}
}
}
if(ii<m)
{
if(m-ii<=4)
{
goto lx_2_left_4;
}
if(m-ii<=8)
{
goto lx_2_left_8;
}
else
{
goto lx_2_left_12;
}
}
#elif defined(TARGET_X64_INTEL_SANDY_BRIDGE) | defined(TARGET_ARMV8A_ARM_CORTEX_A57)
for(; ii<m-7; ii+=8)
{
for(jj=0; jj<ii & jj<n-3; jj+=4)
{
kernel_dgemm_nt_8x4_lib44cc(k, &alpha, pA+ii*sda, sda, pB+jj*sdb, &beta, C+ii+jj*ldc, ldc, D+ii+jj*ldd, ldd);
}
if(jj<n)
{
if(jj<ii) // dgemm
{
kernel_dgemm_nt_8x4_vs_lib44cc(k, &alpha, pA+ii*sda, sda, pB+jj*sdb, &beta, C+ii+jj*ldc, ldc, D+ii+jj*ldd, ldd, m-ii, n-jj);
}
else // dsyrk
{
if(jj<n-7)
{
kernel_dsyrk_nt_l_8x4_lib44cc(k, &alpha, pA+ii*sda, sda, pB+jj*sdb, &beta, C+ii+jj*ldc, ldc, D+ii+jj*ldd, ldd);
kernel_dsyrk_nt_l_4x4_lib44cc(k, &alpha, pA+(ii+4)*sda, pB+(jj+4)*sdb, &beta, C+(ii+4)+(jj+4)*ldc, ldc, D+(ii+4)+(jj+4)*ldd, ldd);
}
else
{
kernel_dsyrk_nt_l_8x4_vs_lib44cc(k, &alpha, pA+ii*sda, sda, pB+jj*sdb, &beta, C+ii+jj*ldc, ldc, D+ii+jj*ldd, ldd, m-ii, n-jj);
if(jj<n-4)
{
kernel_dsyrk_nt_l_4x4_vs_lib44cc(k, &alpha, pA+(ii+4)*sda, pB+(jj+4)*sdb, &beta, C+(ii+4)+(jj+4)*ldc, ldc, D+(ii+4)+(jj+4)*ldd, ldd, m-ii-4, n-jj-4);
}
}
}
}
}
if(ii<m)
{
if(m-ii<=4)
{
goto lx_2_left_4;
}
else
{
goto lx_2_left_8;
}
}
#else
for(; ii<m-3; ii+=4)
{
for(jj=0; jj<ii & jj<n-3; jj+=4)
{
kernel_dgemm_nt_4x4_lib44cc(k, &alpha, pA+ii*sda, pB+jj*sdb, &beta, C+ii+jj*ldc, ldc, D+ii+jj*ldd, ldd);
}
if(jj<n)
{
if(jj<ii) // dgemm
{
kernel_dgemm_nt_4x4_vs_lib44cc(k, &alpha, pA+ii*sda, pB+jj*sdb, &beta, C+ii+jj*ldc, ldc, D+ii+jj*ldd, ldd, m-ii, n-jj);
}
else // dsyrk
{
if(jj<n-3)
{
kernel_dsyrk_nt_l_4x4_lib44cc(k, &alpha, pA+ii*sda, pB+jj*sdb, &beta, C+ii+jj*ldc, ldc, D+ii+jj*ldd, ldd);
}
else
{
kernel_dsyrk_nt_l_4x4_vs_lib44cc(k, &alpha, pA+ii*sda, pB+jj*sdb, &beta, C+ii+jj*ldc, ldc, D+ii+jj*ldd, ldd, m-ii, n-jj);
}
}
}
}
if(ii<m)
{
goto lx_2_left_4;
}
#endif
goto lx_2_return;
#if defined(TARGET_X64_INTEL_HASWELL) | defined(TARGET_ARMV8A_ARM_CORTEX_A53)
lx_2_left_12:
for(jj=0; jj<ii & jj<n; jj+=4)
{
kernel_dgemm_nt_12x4_vs_lib44cc(k, &alpha, pA+ii*sda, sda, pB+jj*sdb, &beta, C+ii+jj*ldc, ldc, D+ii+jj*ldd, ldd, m-ii, n-jj);
}
// kernel_dsyrk_nt_l_8x8_vs_lib44cc(k, &alpha, pA+(ii+4)**sda, sda, pB+(jj+4)*sdb, sdb, &beta, C+(ii+4)+(jj+4)*ldc, ldc, D+(ii+4)+(jj+4)*ldd, ldd, m-(ii+4), m-(jj+4));
if(jj<n)
{
kernel_dsyrk_nt_l_12x4_vs_lib44cc(k, &alpha, pA+ii*sda, sda, pB+jj*sdb, &beta, C+ii+jj*ldc, ldc, D+ii+jj*ldd, ldd, m-ii, n-jj);
if(jj<n-4)
{
kernel_dsyrk_nt_l_8x4_vs_lib44cc(k, &alpha, pA+(ii+4)*sda, sda, pB+(jj+4)*sdb, &beta, C+(ii+4)+(jj+4)*ldc, ldc, D+(ii+4)+(jj+4)*ldd, ldd, m-(ii+4), n-(jj+4));
if(jj<n-8)
{
kernel_dsyrk_nt_l_4x4_vs_lib44cc(k, &alpha, pA+(ii+8)*sda, pB+(jj+8)*sdb, &beta, C+(ii+8)+(jj+8)*ldc, ldc, D+(ii+8)+(jj+8)*ldd, ldd, m-(ii+8), n-(jj+8));
}
}
}
goto lx_2_return;
#endif
#if defined(TARGET_X64_INTEL_HASWELL) | defined(TARGET_X64_INTEL_SANDY_BRIDGE) | defined(TARGET_ARMV8A_ARM_CORTEX_A57) | defined(TARGET_ARMV8A_ARM_CORTEX_A53)
lx_2_left_8:
for(jj=0; jj<ii & jj<n; jj+=4)
{
kernel_dgemm_nt_8x4_vs_lib44cc(k, &alpha, pA+ii*sda, sda, pB+jj*sdb, &beta, C+ii+jj*ldc, ldc, D+ii+jj*ldd, ldd, m-ii, n-jj);
}
// kernel_dsyrk_nt_l_8x8_vs_lib44cc(k, &alpha, pA+ii*sda, sda, pB+jj*sdb, sdb, &beta, C+ii+jj*ldc, ldc, D+ii+jj*ldd, ldd, m-ii, m-jj);
if(jj<n)
{
kernel_dsyrk_nt_l_8x4_vs_lib44cc(k, &alpha, pA+ii*sda, sda, pB+jj*sdb, &beta, C+ii+jj*ldc, ldc, D+ii+jj*ldd, ldd, m-ii, n-jj);
if(jj<n-4)
{
kernel_dsyrk_nt_l_4x4_vs_lib44cc(k, &alpha, pA+(ii+4)*sda, pB+(jj+4)*sdb, &beta, C+(ii+4)+(jj+4)*ldc, ldc, D+(ii+4)+(jj+4)*ldd, ldd, m-(ii+4), n-(jj+4));
}
}
goto lx_2_return;
#endif
lx_2_left_4:
for(jj=0; jj<ii & jj<n; jj+=4)
{
kernel_dgemm_nt_4x4_vs_lib44cc(k, &alpha, pA+ii*sda, pB+jj*sdb, &beta, C+ii+jj*ldc, ldc, D+ii+jj*ldd, ldd, m-ii, n-jj);
}
if(jj<n)
{
kernel_dsyrk_nt_l_4x4_vs_lib44cc(k, &alpha, pA+ii*sda, pB+jj*sdb, &beta, C+ii+jj*ldc, ldc, D+ii+jj*ldd, ldd, m-ii, n-jj);
}
goto lx_2_return;
lx_2_return:
return;
}
void blasfeo_hp_dpotrf_l(int m, struct blasfeo_dmat *sC, int ci, int cj, struct blasfeo_dmat *sD, int di, int dj)
{
#if defined(PRINT_NAME)
printf("\nblasfeo_hp_dpotrf_l (cm) %d %p %d %d %p %d %d\n", m, sC, ci, cj, sD, di, dj);
#endif
if(m<=0)
return;
// extract pointer to column-major matrices from structures
int ldc = sC->m;
int ldd = sD->m;
double *C = sC->pA + ci + cj*ldc;
double *D = sD->pA + di + dj*ldd;
// printf("\n%p %d %p %d\n", C, ldc, D, ldd);
int ii, jj, ll;
int ii0, ll0, jj0, iii;
int mc, nc, kc;
int mleft, nleft, kleft;
int mc0, nc0, kc0;
int ldc1;
double beta1;
double *pA, *pB, *C1, *dA, *dB;
#if defined(TARGET_X64_INTEL_SKYLAKE_X)
const int ps = 4; // XXX TODO fix once implemented missing kernels !!!
#else
const int ps = PS;
#endif
int k0;
k0 = m;
#if defined(TARGET_GENERIC)
double pU_stack[M_KERNEL*K_MAX_STACK];
double pd_stack[K_MAX_STACK];
#else
ALIGNED( double pU_stack[M_KERNEL*K_MAX_STACK], 64 );
ALIGNED( double pd_stack[K_MAX_STACK], 64 );
#endif
int sdu_stack = K_MAX_STACK;
int k4 = (k0+3)/4*4;
struct blasfeo_pm_dmat tA, tB;
int sda, sdb;
int tA_size, tB_size;
void *mem;
char *mem_align;
int m1, n1, k1;
int pack_B;
double *pU, *dU;
int sdu;
int pU_size;
const int m_kernel = M_KERNEL;
const int l1_cache_el = L1_CACHE_EL;
const int reals_per_cache_line = CACHE_LINE_EL;
const int m_cache = (m+reals_per_cache_line-1)/reals_per_cache_line*reals_per_cache_line;
// const int n_cache = (n+reals_per_cache_line-1)/reals_per_cache_line*reals_per_cache_line;
// const int k_cache = (k+reals_per_cache_line-1)/reals_per_cache_line*reals_per_cache_line;
const int m_kernel_cache = (m_kernel+reals_per_cache_line-1)/reals_per_cache_line*reals_per_cache_line;
int m_min = m_cache<m_kernel_cache ? m_cache : m_kernel_cache;
// int n_min = n_cache<m_kernel_cache ? n_cache : m_kernel_cache;
double d_1 = 1.0;
double d_m1 = -1.0;
// goto l_1;
goto l_2;
#if defined(TARGET_X64_INTEL_HASWELL)
if(m<200 & k0<=K_MAX_STACK)
#elif defined(TARGET_X64_INTEL_SANDY_BRIDGE)
if(m<64 & k0<=K_MAX_STACK)
#else
if(m<12 & k0<=K_MAX_STACK)
#endif
{
goto l_1;
}
else
{
goto l_2;
}
// never to get here
return;
l_1:
pU = pU_stack;
sdu = sdu_stack;
dU = pd_stack;
ii = 0;
#if defined(TARGET_X64_INTEL_HASWELL)
for(; ii<m-11; ii+=12)
{
for(jj=0; jj<ii; jj+=4)
{
kernel_dtrsm_nt_rl_inv_12x4_lib4cccc(jj, pU, sdu, D+jj, ldd, &d_1, C+ii+jj*ldc, ldc, D+ii+jj*ldd, ldd, D+jj+jj*ldd, ldd, dU+jj);
kernel_dpack_nn_12_lib4(4, D+ii+jj*ldd, ldd, pU+jj*ps, sdu);
}
kernel_dpotrf_nt_l_12x4_lib44cc(jj, pU, sdu, pU, C+ii+jj*ldc, ldc, D+ii+jj*ldd, ldd, dU+jj);
kernel_dpack_nn_8_lib4(4, D+ii+4+jj*ldd, ldd, pU+4*sdu+jj*ps, sdu);
kernel_dpotrf_nt_l_8x8_lib44cc(jj+4, pU+4*sdu, sdu, pU+4*sdu, sdu, C+ii+4+(jj+4)*ldc, ldc, D+ii+4+(jj+4)*ldd, ldd, dU+jj+4);
}
if(ii<m)
{
if(m-ii<=4)
{
goto l_1_left_4;
}
if(m-ii<=8)
{
goto l_1_left_8;
}
else
{
goto l_1_left_12;
}
}
#elif defined(TARGET_X64_INTEL_SANDY_BRIDGE)
for(; ii<m-7; ii+=8)
{
for(jj=0; jj<ii; jj+=4)
{
kernel_dtrsm_nt_rl_inv_8x4_lib4cccc(jj, pU, sdu, D+jj, ldd, &d_1, C+ii+jj*ldc, ldc, D+ii+jj*ldd, ldd, D+jj+jj*ldd, ldd, dU+jj);
kernel_dpack_nn_8_lib4(4, D+ii+jj*ldd, ldd, pU+jj*ps, sdu);
}
kernel_dpotrf_nt_l_8x4_lib44cc(jj, pU, sdu, pU, C+ii+jj*ldc, ldc, D+ii+jj*ldd, ldd, dU+jj);
kernel_dpack_nn_4_lib4(4, D+ii+4+jj*ldd, ldd, pU+4*sdu+jj*ps);
kernel_dpotrf_nt_l_4x4_lib44cc(jj+4, pU+4*sdu, pU+4*sdu, C+ii+4+(jj+4)*ldc, ldc, D+ii+4+(jj+4)*ldd, ldd, dU+jj+4);
}
if(ii<m)
{
if(m-ii<=4)
{
goto l_1_left_4;
}
else
{
goto l_1_left_8;
}
}
#else
for(; ii<m-3; ii+=4)
{
for(jj=0; jj<ii; jj+=4)
{
kernel_dtrsm_nt_rl_inv_4x4_lib4cccc(jj, pU, D+jj, ldd, &d_1, C+ii+jj*ldc, ldc, D+ii+jj*ldd, ldd, D+jj+jj*ldd, ldd, dU+jj);
kernel_dpack_nn_4_lib4(4, D+ii+jj*ldd, ldd, pU+jj*ps);
}
kernel_dpotrf_nt_l_4x4_lib44cc(jj, pU, pU, C+ii+jj*ldc, ldc, D+ii+jj*ldd, ldd, dU+jj);
}
if(ii<m)
{
goto l_1_left_4;
}
#endif
goto l_1_return;
#if defined(TARGET_X64_INTEL_HASWELL)
l_1_left_12:
for(jj=0; jj<ii; jj+=4)
{
kernel_dtrsm_nt_rl_inv_12x4_vs_lib4cccc(jj, pU, sdu, D+jj, ldd, &d_1, C+ii+jj*ldc, ldc, D+ii+jj*ldd, ldd, D+jj+jj*ldd, ldd, dU+jj, m-ii, ii-jj);
kernel_dpack_nn_12_vs_lib4(4, D+ii+jj*ldd, ldd, pU+jj*ps, sdu, m-ii);
}
kernel_dpotrf_nt_l_12x4_vs_lib44cc(jj, pU, sdu, pU, C+ii+jj*ldc, ldc, D+ii+jj*ldd, ldd, dU+jj, m-ii, m-jj);
kernel_dpack_nn_8_vs_lib4(4, D+ii+4+jj*ldd, ldd, pU+4*sdu+jj*ps, sdu, m-ii-4);
kernel_dpotrf_nt_l_8x8_vs_lib44cc(jj+4, pU+4*sdu, sdu, pU+4*sdu, sdu, C+ii+4+(jj+4)*ldc, ldc, D+ii+4+(jj+4)*ldd, ldd, dU+jj+4, m-ii-4, m-ii-4);
goto l_1_return;
#endif
// TODO use haswell 8x8
#if defined(TARGET_X64_INTEL_HASWELL) | defined(TARGET_X64_INTEL_SANDY_BRIDGE)
l_1_left_8:
for(jj=0; jj<ii; jj+=4)
{
kernel_dtrsm_nt_rl_inv_8x4_vs_lib4cccc(jj, pU, sdu, D+jj, ldd, &d_1, C+ii+jj*ldc, ldc, D+ii+jj*ldd, ldd, D+jj+jj*ldd, ldd, dU+jj, m-ii, ii-jj);
kernel_dpack_nn_8_vs_lib4(4, D+ii+jj*ldd, ldd, pU+jj*ps, sdu, m-ii);
}
kernel_dpotrf_nt_l_8x4_vs_lib44cc(jj, pU, sdu, pU, C+ii+jj*ldc, ldc, D+ii+jj*ldd, ldd, dU+jj, m-ii, m-jj);
kernel_dpack_nn_4_vs_lib4(4, D+ii+4+jj*ldd, ldd, pU+4*sdu+jj*ps, m-ii-4);
kernel_dpotrf_nt_l_4x4_vs_lib44cc(jj+4, pU+4*sdu, pU+4*sdu, C+ii+4+(jj+4)*ldc, ldc, D+ii+4+(jj+4)*ldd, ldd, dU+jj+4, m-ii-4, m-jj-4);
goto l_1_return;
#endif
l_1_left_4:
for(jj=0; jj<ii; jj+=4)
{
kernel_dtrsm_nt_rl_inv_4x4_vs_lib4cccc(jj, pU, D+jj, ldd, &d_1, C+ii+jj*ldc, ldc, D+ii+jj*ldd, ldd, D+jj+jj*ldd, ldd, dU+jj, m-ii, ii-jj);
kernel_dpack_nn_4_vs_lib4(4, D+ii+jj*ldd, ldd, pU+jj*ps, m-ii);
}
kernel_dpotrf_nt_l_4x4_vs_lib44cc(jj, pU, pU, C+ii+jj*ldc, ldc, D+ii+jj*ldd, ldd, dU+jj, m-ii, m-jj);
goto l_1_return;
l_1_return:
return;
l_2:
#if ! defined(TARGET_X64_INTEL_SKYLAKE_X)
// cache blocking alg
mc0 = MC;
nc0 = NC;
kc0 = KC;
// these must all be multiple of ps !!!
// mc0 = 12;
// nc0 = 4;
// kc0 = 8;
mc = m<mc0 ? m : mc0;
// nc = n<nc0 ? n : nc0;
nc = m<nc0 ? m : nc0;
// kc = k<kc0 ? k : kc0;
kc = m<kc0 ? m : kc0;
tA_size = blasfeo_pm_memsize_dmat(ps, mc0, kc0);
tB_size = blasfeo_pm_memsize_dmat(ps, nc0, kc0);
tA_size = (tA_size + 4096 - 1) / 4096 * 4096;
tB_size = (tB_size + 4096 - 1) / 4096 * 4096;
if(blasfeo_is_init()==0)
{
blasfeo_malloc(&mem, tA_size+tB_size+2*4096);
}
else
{
mem = blasfeo_get_buffer();
}
blasfeo_align_4096_byte(mem, (void **) &mem_align);
blasfeo_pm_create_dmat(ps, mc0, kc0, &tA, (void *) mem_align);
mem_align += tA_size;
mem_align += 4096-4*128;
blasfeo_pm_create_dmat(ps, nc0, kc0, &tB, (void *) mem_align);
mem_align += tB_size;
pA = tA.pA;
dA = tA.dA;
pB = tB.pA;
for(ii=0; ii<m; ii+=mleft)
{
mleft = m-ii<mc ? m-ii : mc;
for(ll=0; ll<mleft; ll+=kleft)
{
kleft = mleft-ll<kc ? mleft-ll : kc;
sda = (kleft+4-1)/4*4; // XXX
sdb = (kleft+4-1)/4*4; // XXX
blasfeo_hp_dpotrf_l_mn_m2(mleft-ll, kleft, C+ii+ll+(ii+ll)*ldc, ldc, D+ii+ll+(ii+ll)*ldd, ldd, pA, dA, sda);
for(jj=ll+kleft; jj<mleft; jj+=nleft)
{
nleft = mleft-jj<nc ? mleft-jj : nc;
blasfeo_hp_dsyrk_ln_mn_m2(mleft-jj, nleft, kleft, d_m1, pA+(jj-ll)*sda, sda, pA+(jj-ll)*sda, sda, d_1, C+ii+jj+(ii+jj)*ldc, ldc, D+ii+jj+(ii+jj)*ldd, ldd);
}
}
blasfeo_hp_dtrsm_rltn(m-ii-mleft, mleft, 1.0, sD, di+ii, dj+ii, sC, ci+ii+mleft, cj+ii, sD, di+ii+mleft, dj+ii);
blasfeo_hp_dsyrk3_ln(m-ii-mleft, mleft, -1.0, sD, di+ii+mleft, dj+ii, 1.0, sC, ci+ii+mleft, cj+ii+mleft, sD, di+ii+mleft, dj+ii+mleft);
}
free(mem);
return;
#else
m1 = (m+128-1)/128*128;
tA_size = blasfeo_pm_memsize_dmat(ps, m1, m1);
mem = malloc(tA_size+64);
blasfeo_align_64_byte(mem, (void **) &mem_align);
blasfeo_pm_create_dmat(ps, m, m, &tA, (void *) mem_align);
sda = tA.cn;
dA = tA.dA;
ii = 0;
#if defined(TARGET_X64_INTEL_HASWELL) | defined(TARGET_ARMV8A_ARM_CORTEX_A53)
for(; ii<m-11; ii+=12)
{
jj = 0;
for(; jj<ii; jj+=4)
{
kernel_dtrsm_nt_rl_inv_12x4_lib44ccc(jj, tA.pA+ii*sda, sda, tA.pA+jj*sda, C+ii+jj*ldc, ldc, D+ii+jj*ldd, ldd, D+jj+jj*ldd, ldd, dA+jj);
kernel_dpack_nn_12_lib4(4, D+ii+jj*ldd, ldd, tA.pA+ii*sda+jj*ps, sda);
}
kernel_dpotrf_nt_l_12x4_lib44cc(jj, tA.pA+ii*sda, sda, tA.pA+jj*sda, C+ii+jj*ldc, ldc, D+ii+jj*ldd, ldd, dA+jj);
kernel_dpack_nn_8_lib4(4, D+ii+4+jj*ldd, ldd, tA.pA+(ii+4)*sda+jj*ps, sda);
#if defined(TARGET_X64_INTEL_HASWELL)
kernel_dpotrf_nt_l_8x8_lib44cc(jj+4, tA.pA+(ii+4)*sda, sda, tA.pA+(jj+4)*sda, sda, C+ii+4+(jj+4)*ldc, ldc, D+ii+4+(jj+4)*ldd, ldd, dA+jj+4);
kernel_dpack_nn_4_lib4(4, D+ii+8+(jj+4)*ldd, ldd, tA.pA+(ii+8)*sda+(jj+4)*ps); // TODO comment out ?? no !!!!!!!!!!!!!!!!!!!!
#else
kernel_dpotrf_nt_l_8x4_lib44cc(jj+4, tA.pA+(ii+4)*sda, sda, tA.pA+(jj+4)*sda, C+ii+4+(jj+4)*ldc, ldc, D+ii+4+(jj+4)*ldd, ldd, dA+jj+4);
kernel_dpack_nn_4_lib4(4, D+ii+8+(jj+4)*ldd, ldd, tA.pA+(ii+8)*sda+(jj+4)*ps);
kernel_dpotrf_nt_l_4x4_lib44cc(jj+8, tA.pA+(ii+8)*sda, tA.pA+(jj+8)*sda, C+ii+8+(jj+8)*ldc, ldc, D+ii+8+(jj+8)*ldd, ldd, dA+jj+8);
#endif
}
if(ii<m)
{
if(m-ii<=4)
{
goto l_2_left_4;
}
if(m-ii<=8)
{
goto l_2_left_8;
}
else
{
goto l_2_left_12;
}
}
#elif defined(TARGET_X64_INTEL_SANDY_BRIDGE) | defined(TARGET_ARMV8A_ARM_CORTEX_A57)
for(; ii<m-7; ii+=8)
{
jj = 0;
for(; jj<ii; jj+=4)
{
kernel_dtrsm_nt_rl_inv_8x4_lib44ccc(jj, tA.pA+ii*sda, sda, tA.pA+jj*sda, C+ii+jj*ldc, ldc, D+ii+jj*ldd, ldd, D+jj+jj*ldd, ldd, dA+jj);
kernel_dpack_nn_8_lib4(4, D+ii+jj*ldd, ldd, tA.pA+ii*sda+jj*ps, sda);
}
kernel_dpotrf_nt_l_8x4_lib44cc(jj, tA.pA+ii*sda, sda, tA.pA+jj*sda, C+ii+jj*ldc, ldc, D+ii+jj*ldd, ldd, dA+jj);
kernel_dpack_nn_4_lib4(4, D+ii+4+jj*ldd, ldd, tA.pA+(ii+4)*sda+jj*ps);
kernel_dpotrf_nt_l_4x4_lib44cc(jj+4, tA.pA+(ii+4)*sda, tA.pA+(jj+4)*sda, C+ii+4+(jj+4)*ldc, ldc, D+ii+4+(jj+4)*ldd, ldd, dA+jj+4);
}
if(ii<m)
{
if(m-ii<=4)
{
goto l_2_left_4;
}
else
{
goto l_2_left_8;
}
}
#else
for(; ii<m-3; ii+=4)
{
jj = 0;
for(; jj<ii; jj+=4)
{
kernel_dtrsm_nt_rl_inv_4x4_lib44ccc(jj, tA.pA+ii*sda, tA.pA+jj*sda, &d_1, C+ii+jj*ldc, ldc, D+ii+jj*ldd, ldd, D+jj+jj*ldd, ldd, dA+jj);
kernel_dpack_nn_4_lib4(4, D+ii+jj*ldd, ldd, tA.pA+ii*sda+jj*ps);
}
kernel_dpotrf_nt_l_4x4_lib44cc(jj, tA.pA+ii*sda, tA.pA+jj*sda, C+ii+jj*ldc, ldc, D+ii+jj*ldd, ldd, dA+jj);
}
if(ii<m)
{
goto l_2_left_4;
}
#endif
goto l_2_return;
#if defined(TARGET_X64_INTEL_HASWELL) | defined(TARGET_ARMV8A_ARM_CORTEX_A53)
l_2_left_12:
for(jj=0; jj<ii; jj+=4)
{
kernel_dtrsm_nt_rl_inv_12x4_vs_lib44ccc(jj, tA.pA+ii*sda, sda, tA.pA+jj*sda, C+ii+jj*ldc, ldc, D+ii+jj*ldd, ldd, D+jj+jj*ldd, ldd, dA+jj, m-ii, ii-jj);
kernel_dpack_nn_12_vs_lib4(4, D+ii+jj*ldd, ldd, tA.pA+ii*sda+jj*ps, sda, m-ii);
}
kernel_dpotrf_nt_l_12x4_vs_lib44cc(jj, tA.pA+ii*sda, sda, tA.pA+jj*sda, C+ii+jj*ldc, ldc, D+ii+jj*ldd, ldd, dA+jj, m-ii, m-jj);
kernel_dpack_nn_8_vs_lib4(4, D+ii+4+jj*ldd, ldd, tA.pA+(ii+4)*sda+jj*ps, sda, m-ii-4);
#if defined(TARGET_X64_INTEL_HASWELL)
kernel_dpotrf_nt_l_8x8_vs_lib44cc(jj+4, tA.pA+(ii+4)*sda, sda, tA.pA+(jj+4)*sda, sda, C+ii+4+(jj+4)*ldc, ldc, D+ii+4+(jj+4)*ldd, ldd, dA+jj+4, m-ii-4, m-jj-4);
// XXX not needed before return
// kernel_dpack_nn_4_vs_lib4(4, D+ii+8+(jj+4)*ldd, ldd, tA.pA+(ii+8)*sda+(jj+4)*ps, m-ii-8);
#else
kernel_dpotrf_nt_l_8x4_vs_lib44cc(jj+4, tA.pA+(ii+4)*sda, sda, tA.pA+(jj+4)*sda, C+ii+4+(jj+4)*ldc, ldc, D+ii+4+(jj+4)*ldd, ldd, dA+jj+4, m-(ii+4), m-(jj+4));
// kernel_dpack_nn_4_vs_lib4(8, D+ii+8+(jj+4)*ldd, ldd, tA.pA+(ii+8)*sda+(jj+4)*ps, m-ii-8);
kernel_dpack_nn_4_vs_lib4(4, D+ii+8+(jj+4)*ldd, ldd, tA.pA+(ii+8)*sda+(jj+4)*ps, m-ii-8);
kernel_dpotrf_nt_l_4x4_vs_lib44cc(jj+8, tA.pA+(ii+8)*sda, tA.pA+(jj+8)*sda, C+ii+8+(jj+8)*ldc, ldc, D+ii+8+(jj+8)*ldd, ldd, dA+jj+8, m-ii-8, m-jj-8);
#endif
goto l_2_return;
#endif
#if defined(TARGET_X64_INTEL_HASWELL) | defined(TARGET_X64_INTEL_SANDY_BRIDGE) | defined(TARGET_ARMV8A_ARM_CORTEX_A57) | defined(TARGET_ARMV8A_ARM_CORTEX_A53)
l_2_left_8:
for(jj=0; jj<ii; jj+=4)
{
kernel_dtrsm_nt_rl_inv_8x4_vs_lib44ccc(jj, tA.pA+ii*sda, sda, tA.pA+jj*sda, C+ii+jj*ldc, ldc, D+ii+jj*ldd, ldd, D+jj+jj*ldd, ldd, dA+jj, m-ii, ii-jj);
kernel_dpack_nn_8_vs_lib4(4, D+ii+jj*ldd, ldd, tA.pA+ii*sda+jj*ps, sda, m-ii);
}
#if defined(TARGET_X64_INTEL_HASWELL)
kernel_dpotrf_nt_l_8x8_vs_lib44cc(jj, tA.pA+ii*sda, sda, tA.pA+jj*sda, sda, C+ii+jj*ldc, ldc, D+ii+jj*ldd, ldd, dA+jj, m-ii, m-jj);
#else
kernel_dpotrf_nt_l_8x4_vs_lib44cc(jj, tA.pA+ii*sda, sda, tA.pA+jj*sda, C+ii+jj*ldc, ldc, D+ii+jj*ldd, ldd, dA+jj, m-ii, m-jj);
kernel_dpack_nn_4_vs_lib4(4, D+ii+4+jj*ldd, ldd, tA.pA+(ii+4)*sda+jj*ps, m-ii-4);
kernel_dpotrf_nt_l_4x4_vs_lib44cc(jj+4, tA.pA+(ii+4)*sda, tA.pA+(jj+4)*sda, C+ii+4+(jj+4)*ldc, ldc, D+ii+4+(jj+4)*ldd, ldd, dA+jj+4, m-ii-4, m-jj-4);
#endif
goto l_2_return;
#endif
l_2_left_4:
for(jj=0; jj<ii; jj+=4)
{
kernel_dtrsm_nt_rl_inv_4x4_vs_lib44ccc(jj, tA.pA+ii*sda, tA.pA+jj*sda, &d_1, C+ii+jj*ldc, ldc, D+ii+jj*ldd, ldd, D+jj+jj*ldd, ldd, dA+jj, m-ii, ii-jj);
kernel_dpack_nn_4_vs_lib4(4, D+ii+jj*ldd, ldd, tA.pA+ii*sda+jj*ps, m-ii);
}
kernel_dpotrf_nt_l_4x4_vs_lib44cc(jj, tA.pA+ii*sda, tA.pA+jj*sda, C+ii+jj*ldc, ldc, D+ii+jj*ldd, ldd, dA+jj, m-ii, m-jj);
goto l_2_return;
l_2_return:
free(mem);
return;
#endif
// never to get here
return;
}
void blasfeo_hp_dpotrf_u(int m, struct blasfeo_dmat *sC, int ci, int cj, struct blasfeo_dmat *sD, int di, int dj)
{
#if defined(PRINT_NAME)
printf("\nblasfeo_hp_dpotrf_u (cm) %d %p %d %d %p %d %d\n", m, sC, ci, cj, sD, di, dj);
#endif
if(m<=0)
return;
// extract pointer to column-major matrices from structures
int ldc = sC->m;
int ldd = sD->m;
double *C = sC->pA + ci + cj*ldc;
double *D = sD->pA + di + dj*ldd;
// printf("\n%p %d %p %d\n", C, ldc, D, ldd);
int ii, jj;
const int ps = 4; //D_PS;
#if defined(TARGET_GENERIC)
double pU[4*K_MAX_STACK];
double dU[K_MAX_STACK];
double pD[M_KERNEL*N_KERNEL];
#else
ALIGNED( double pU[M_KERNEL*K_MAX_STACK], 64 );
ALIGNED( double dU[K_MAX_STACK], 64 );
ALIGNED( double pD[M_KERNEL*N_KERNEL], 64 );
#endif
int sdu = (m+3)/4*4;
sdu = sdu<K_MAX_STACK ? sdu : K_MAX_STACK;
struct blasfeo_pm_dmat tA;
int sda;
double *dA;
int tA_size;
void *mem;
char *mem_align;
int m1, n1, k1;
int pack_B;
const int m_kernel = M_KERNEL;
const int l1_cache_el = L1_CACHE_EL;
const int reals_per_cache_line = CACHE_LINE_EL;
const int m_cache = (m+reals_per_cache_line-1)/reals_per_cache_line*reals_per_cache_line;
// const int n_cache = (n+reals_per_cache_line-1)/reals_per_cache_line*reals_per_cache_line;
// const int k_cache = (k+reals_per_cache_line-1)/reals_per_cache_line*reals_per_cache_line;
const int m_kernel_cache = (m_kernel+reals_per_cache_line-1)/reals_per_cache_line*reals_per_cache_line;
int m_min = m_cache<m_kernel_cache ? m_cache : m_kernel_cache;
// int n_min = n_cache<m_kernel_cache ? n_cache : m_kernel_cache;
double d_1 = 1.0;
// goto u_1;
// goto u_2;
#if defined(TARGET_X64_INTEL_HASWELL)
if(m>=256 | m>K_MAX_STACK)
#elif defined(TARGET_X64_INTEL_SANDY_BRIDGE)
if(m>=64 | m>K_MAX_STACK)
#else
if(m>=12 | m>K_MAX_STACK)
#endif
{
goto u_2;
}
else
{
goto u_1;
}
// never to get here
return;
u_1:
ii = 0;
#if defined(TARGET_X64_INTEL_HASWELL)
for(; ii<m-11; ii+=12)
{
for(jj=0; jj<ii; jj+=4)
{
kernel_dpack_tn_4_lib4(4, C+jj+(ii+0)*ldc, ldc, pU+jj*ps+0*sdu);
kernel_dpack_tn_4_lib4(4, C+jj+(ii+4)*ldc, ldc, pU+jj*ps+4*sdu);
kernel_dpack_tn_4_lib4(4, C+jj+(ii+8)*ldc, ldc, pU+jj*ps+8*sdu);
kernel_dtrsm_nn_ru_inv_12x4_lib4c44c(jj, pU, sdu, D+jj*ldd, ldd, &d_1, pU+jj*ps, sdu, pU+jj*ps, sdu, D+jj+jj*ldd, ldd, dU+jj);
kernel_dunpack_nt_4_lib4(4, pU+jj*ps+0*sdu, D+jj+(ii+0)*ldd, ldd);
kernel_dunpack_nt_4_lib4(4, pU+jj*ps+4*sdu, D+jj+(ii+4)*ldd, ldd);
kernel_dunpack_nt_4_lib4(4, pU+jj*ps+8*sdu, D+jj+(ii+8)*ldd, ldd);
}
kernel_dpack_tn_4_lib4(4, C+ii+(ii+0)*ldc, ldc, pD+0*4);
kernel_dpack_tn_4_lib4(4, C+ii+(ii+4)*ldc, ldc, pD+4*4);
kernel_dpack_tn_4_lib4(4, C+ii+(ii+8)*ldc, ldc, pD+8*4);
kernel_dpotrf_nt_l_12x4_lib4(ii, pU, sdu, pU, pD, ps, pD, ps, dU+ii);
kernel_dunpack_nt_4_lib4(4, pD+0*4, D+ii+(ii+0)*ldd, ldd);
kernel_dunpack_nt_4_lib4(4, pD+4*4, D+ii+(ii+4)*ldd, ldd);
kernel_dunpack_nt_4_lib4(4, pD+8*4, D+ii+(ii+8)*ldd, ldd); // TODO unpack l !!!!!!!!!!!!!!!!
kernel_dpack_tn_4_lib4(4, D+ii+(ii+4)*ldd, ldd, pU+4*sdu+ii*ps);
kernel_dpack_tn_4_lib4(4, D+ii+(ii+8)*ldd, ldd, pU+8*sdu+ii*ps);
#if 1
kernel_dpack_tn_4_lib4(4, C+ii+4+(ii+4)*ldc, ldc, pD+0*4);
kernel_dpack_tn_4_lib4(4, C+ii+4+(ii+8)*ldc, ldc, pD+8*4);
kernel_dpack_tn_4_lib4(4, C+ii+8+(ii+8)*ldc, ldc, pD+12*4);
kernel_dpotrf_nt_l_8x8_lib4(ii+4, pU+4*sdu, sdu, pU+4*sdu, sdu, pD, 8, pD, 8, dU+ii+4);
kernel_dunpack_nt_4_lib4(4, pD+0*4, D+ii+4+(ii+4)*ldd, ldd); // TODO unpack l !!!!!!!!!!!!!!!!
kernel_dunpack_nt_4_lib4(4, pD+8*4, D+ii+4+(ii+8)*ldd, ldd);
kernel_dunpack_nt_4_lib4(4, pD+12*4, D+ii+8+(ii+8)*ldd, ldd); // TODO unpack l !!!!!!!!!!!!!!!!
#else
kernel_dpack_tn_4_lib4(4, C+ii+4+(ii+4)*ldc, ldc, pD+0*4);
kernel_dpack_tn_4_lib4(4, C+ii+4+(ii+8)*ldc, ldc, pD+4*4);
kernel_dpotrf_nt_l_8x4_lib4(ii+4, pU+4*sdu, sdu, pU+4*sdu, pD, ps, pD, ps, dU+ii+4);
kernel_dunpack_nt_4_lib4(4, pD+0*4, D+ii+4+(ii+4)*ldd, ldd);
kernel_dunpack_nt_4_lib4(4, pD+4*4, D+ii+4+(ii+8)*ldd, ldd); // TODO unpack l !!!!!!!!!!!!!!!!
kernel_dpack_tn_4_lib4(4, D+ii+4+(ii+8)*ldd, ldd, pU+8*sdu+(ii+4)*ps);
kernel_dpack_tn_4_lib4(4, C+ii+8+(ii+8)*ldc, ldc, pD);
kernel_dpotrf_nt_l_4x4_lib4(ii+8, pU+8*sdu, pU+8*sdu, pD, pD, dU+ii+8);
kernel_dunpack_nt_4_lib4(4, pD, D+ii+8+(ii+8)*ldd, ldd); // TODO unpack l !!!!!!!!!!!!!!!!
#endif
}
if(ii<m)
{
if(m-ii<=4)
{
goto u_1_left_4;
}
if(m-ii<=8)
{
goto u_1_left_8;
}
else
{
goto u_1_left_12;
}
}
#elif defined(TARGET_X64_INTEL_SANDY_BRIDGE)
for(; ii<m-7; ii+=8)
{
for(jj=0; jj<ii; jj+=4)
{
kernel_dpack_tn_4_lib4(4, C+jj+(ii+0)*ldc, ldc, pU+jj*ps+0*sdu);
kernel_dpack_tn_4_lib4(4, C+jj+(ii+4)*ldc, ldc, pU+jj*ps+4*sdu);
kernel_dtrsm_nn_ru_inv_8x4_lib4c44c(jj, pU, sdu, D+jj*ldd, ldd, &d_1, pU+jj*ps, sdu, pU+jj*ps, sdu, D+jj+jj*ldd, ldd, dU+jj);
kernel_dunpack_nt_4_lib4(4, pU+jj*ps+0*sdu, D+jj+(ii+0)*ldd, ldd);
kernel_dunpack_nt_4_lib4(4, pU+jj*ps+4*sdu, D+jj+(ii+4)*ldd, ldd);
}
kernel_dpack_tn_4_lib4(4, C+ii+(ii+0)*ldc, ldc, pD+0*4);
kernel_dpack_tn_4_lib4(4, C+ii+(ii+4)*ldc, ldc, pD+4*4);
kernel_dpotrf_nt_l_8x4_lib4(ii, pU, sdu, pU, pD, ps, pD, ps, dU+ii);
kernel_dunpack_nt_4_lib4(4, pD+0*4, D+ii+(ii+0)*ldd, ldd);
kernel_dunpack_nt_4_lib4(4, pD+4*4, D+ii+(ii+4)*ldd, ldd); // TODO unpack l !!!!!!!!!!!!!!!!
kernel_dpack_tn_4_lib4(4, D+ii+(ii+4)*ldd, ldd, pU+4*sdu+ii*ps);
kernel_dpack_tn_4_lib4(4, C+ii+4+(ii+4)*ldc, ldc, pD);
kernel_dpotrf_nt_l_4x4_lib4(ii+4, pU+4*sdu, pU+4*sdu, pD, pD, dU+ii+4);
kernel_dunpack_nt_4_lib4(4, pD, D+ii+4+(ii+4)*ldd, ldd); // TODO unpack l !!!!!!!!!!!!!!!!
}
if(ii<m)
{
if(m-ii<=4)
{
goto u_1_left_4;
}
else
{
goto u_1_left_8;
}
}
#else
for(; ii<m-3; ii+=4)
{
for(jj=0; jj<ii; jj+=4)
{
kernel_dpack_tn_4_lib4(4, C+jj+ii*ldc, ldc, pU+jj*ps);
kernel_dtrsm_nn_ru_inv_4x4_lib4c44c(jj, pU, D+jj*ldd, ldd, &d_1, pU+jj*ps, pU+jj*ps, D+jj+jj*ldd, ldd, dU+jj);
kernel_dunpack_nt_4_lib4(4, pU+jj*ps, D+jj+ii*ldd, ldd);
}
kernel_dpack_tn_4_lib4(4, C+ii+ii*ldc, ldc, pD);
kernel_dpotrf_nt_l_4x4_lib4(ii, pU, pU, pD, pD, dU+ii);
kernel_dunpack_nt_4_lib4(4, pD, D+ii+ii*ldd, ldd); // TODO unpack l !!!!!!!!!!!!!!!!
}
if(ii<m)
{
goto u_1_left_4;
}
#endif
goto u_1_return;
#if defined(TARGET_X64_INTEL_HASWELL) | defined(TARGET_X64_INTEL_SANDY_BRIDGE)
u_1_left_12:
for(jj=0; jj<ii; jj+=4)
{
kernel_dpack_tn_4_lib4(4, C+jj+(ii+0)*ldc, ldc, pU+jj*ps+0*sdu);
kernel_dpack_tn_4_lib4(4, C+jj+(ii+4)*ldc, ldc, pU+jj*ps+4*sdu);
kernel_dpack_tn_4_vs_lib4(4, C+jj+(ii+8)*ldc, ldc, pU+jj*ps+8*sdu, m-ii-8);
kernel_dtrsm_nn_ru_inv_12x4_lib4c44c(jj, pU, sdu, D+jj*ldd, ldd, &d_1, pU+jj*ps, sdu, pU+jj*ps, sdu, D+jj+jj*ldd, ldd, dU+jj); // TODO vs
kernel_dunpack_nt_4_lib4(4, pU+jj*ps+0*sdu, D+jj+(ii+0)*ldd, ldd);
kernel_dunpack_nt_4_lib4(4, pU+jj*ps+4*sdu, D+jj+(ii+4)*ldd, ldd);
kernel_dunpack_nt_4_vs_lib4(4, pU+jj*ps+8*sdu, D+jj+(ii+8)*ldd, ldd, m-ii-8);
}
kernel_dpack_tn_4_lib4(4, C+ii+(ii+0)*ldc, ldc, pD+0*4);
kernel_dpack_tn_4_lib4(4, C+ii+(ii+4)*ldc, ldc, pD+4*4);
kernel_dpack_tn_4_vs_lib4(4, C+ii+(ii+8)*ldc, ldc, pD+8*4, m-ii-8);
kernel_dpotrf_nt_l_12x4_vs_lib4(ii, pU, sdu, pU, pD, ps, pD, ps, dU+ii, m-ii, m-ii);
kernel_dunpack_nt_4_lib4(4, pD+0*4, D+ii+(ii+0)*ldd, ldd);
kernel_dunpack_nt_4_lib4(4, pD+4*4, D+ii+(ii+4)*ldd, ldd);
kernel_dunpack_nt_4_vs_lib4(4, pD+8*4, D+ii+(ii+8)*ldd, ldd, m-ii-8); // TODO pack vs with m and n, or triangle
kernel_dpack_tn_4_lib4(4, D+ii+(ii+4)*ldd, ldd, pU+4*sdu+ii*ps);
kernel_dpack_tn_4_lib4(4, D+ii+(ii+8)*ldd, ldd, pU+8*sdu+ii*ps);
#if 1
kernel_dpack_tn_4_lib4(4, C+ii+4+(ii+4)*ldc, ldc, pD+0*4);
kernel_dpack_tn_4_vs_lib4(4, C+ii+4+(ii+8)*ldc, ldc, pD+8*4, m-ii-8);
kernel_dpack_tn_4_vs_lib4(4, C+ii+8+(ii+8)*ldc, ldc, pD+12*4, m-ii-8);
kernel_dpotrf_nt_l_8x8_vs_lib4(ii+4, pU+4*sdu, sdu, pU+4*sdu, sdu, pD, 8, pD, 8, dU+ii+4, m-ii-4, m-ii-4);
kernel_dunpack_nt_4_lib4(4, pD+0*4, D+ii+4+(ii+4)*ldd, ldd); // TODO pack vs with m and n, or triangle
kernel_dunpack_nt_4_vs_lib4(4, pD+8*4, D+ii+4+(ii+8)*ldd, ldd, m-ii-8);
kernel_dunpack_nt_4_vs_lib4(4, pD+12*4, D+ii+8+(ii+8)*ldd, ldd, m-ii-8); // TODO pack vs with m and n, or triangle
#else
kernel_dpack_tn_4_lib4(4, C+ii+4+(ii+4)*ldc, ldc, pD+0*4);
kernel_dpack_tn_4_vs_lib4(4, C+ii+4+(ii+8)*ldc, ldc, pD+4*4, m-ii-8);
kernel_dpotrf_nt_l_8x4_vs_lib4(ii+4, pU+4*sdu, sdu, pU+4*sdu, pD, ps, pD, ps, dU+ii+4, m-ii-4, m-ii-4);
kernel_dunpack_nt_4_lib4(4, pD+0*4, D+ii+4+(ii+4)*ldd, ldd);
kernel_dunpack_nt_4_vs_lib4(4, pD+4*4, D+ii+4+(ii+8)*ldd, ldd, m-ii-8); // TODO pack vs with m and n, or triangle
kernel_dpack_tn_4_lib4(4, D+ii+4+(ii+8)*ldd, ldd, pU+8*sdu+(ii+4)*ps);
kernel_dpack_tn_4_vs_lib4(4, C+ii+8+(ii+8)*ldc, ldc, pD, m-ii-8);
kernel_dpotrf_nt_l_4x4_vs_lib4(ii+8, pU+8*sdu, pU+8*sdu, pD, pD, dU+ii+8, m-ii-8, m-ii-8);
kernel_dunpack_nt_4_vs_lib4(4, pD, D+ii+8+(ii+8)*ldd, ldd, m-ii-8); // TODO pack vs with m and n, or triangle
#endif
goto u_1_return;
#endif
#if defined(TARGET_X64_INTEL_HASWELL) | defined(TARGET_X64_INTEL_SANDY_BRIDGE)
u_1_left_8:
for(jj=0; jj<ii; jj+=4)
{
kernel_dpack_tn_4_lib4(4, C+jj+(ii+0)*ldc, ldc, pU+jj*ps+0*sdu);
kernel_dpack_tn_4_vs_lib4(4, C+jj+(ii+4)*ldc, ldc, pU+jj*ps+4*sdu, m-ii-4);
kernel_dtrsm_nn_ru_inv_8x4_lib4c44c(jj, pU, sdu, D+jj*ldd, ldd, &d_1, pU+jj*ps, sdu, pU+jj*ps, sdu, D+jj+jj*ldd, ldd, dU+jj); // TODO vs
kernel_dunpack_nt_4_lib4(4, pU+jj*ps+0*sdu, D+jj+(ii+0)*ldd, ldd);
kernel_dunpack_nt_4_vs_lib4(4, pU+jj*ps+4*sdu, D+jj+(ii+4)*ldd, ldd, m-ii-4);
}
kernel_dpack_tn_4_lib4(4, C+ii+(ii+0)*ldc, ldc, pD+0*4);
kernel_dpack_tn_4_vs_lib4(4, C+ii+(ii+4)*ldc, ldc, pD+4*4, m-ii-4);
kernel_dpotrf_nt_l_8x4_vs_lib4(ii, pU, sdu, pU, pD, ps, pD, ps, dU+ii, m-ii, m-ii);
kernel_dunpack_nt_4_lib4(4, pD+0*4, D+ii+(ii+0)*ldd, ldd);
kernel_dunpack_nt_4_vs_lib4(4, pD+4*4, D+ii+(ii+4)*ldd, ldd, m-ii-4);
kernel_dpack_tn_4_lib4(4, D+ii+(ii+4)*ldd, ldd, pU+4*sdu+ii*ps);
kernel_dpack_tn_4_vs_lib4(4, C+ii+4+(ii+4)*ldc, ldc, pD, m-ii-4); // TODO pack vs with m and n, or triangle
kernel_dpotrf_nt_l_4x4_vs_lib4(ii+4, pU+4*sdu, pU+4*sdu, pD, pD, dU+ii+4, m-ii-4, m-ii-4);
kernel_dunpack_nt_4_vs_lib4(4, pD, D+ii+4+(ii+4)*ldd, ldd, m-ii-4); // TODO pack vs with m and n, or triangle
goto u_1_return;
#endif
u_1_left_4:
for(jj=0; jj<ii; jj+=4)
{
kernel_dpack_tn_4_vs_lib4(4, C+jj+ii*ldc, ldc, pU+jj*ps, m-ii);
kernel_dtrsm_nn_ru_inv_4x4_lib4c44c(jj, pU, D+jj*ldd, ldd, &d_1, pU+jj*ps, pU+jj*ps, D+jj+jj*ldd, ldd, dU+jj); // TODO vs
kernel_dunpack_nt_4_vs_lib4(4, pU+jj*ps, D+jj+ii*ldd, ldd, m-ii); // TODO vs
}
kernel_dpack_tn_4_vs_lib4(4, C+ii+ii*ldc, ldc, pD, m-ii); // TODO pack vs with m and n, or triangle
kernel_dpotrf_nt_l_4x4_vs_lib4(ii, pU, pU, pD, pD, dU+ii, m-ii, m-ii);
kernel_dunpack_nt_4_vs_lib4(4, pD, D+ii+ii*ldd, ldd, m-ii); // TODO pack vs with m and n, or triangle
goto u_1_return;
u_1_return:
return;
u_2:
m1 = (m+128-1)/128*128;
tA_size = blasfeo_pm_memsize_dmat(ps, m1, m1);
// tA_size = blasfeo_memsize_dmat(m, m);
mem = malloc(tA_size+64);
blasfeo_align_64_byte(mem, (void **) &mem_align);
blasfeo_pm_create_dmat(ps, m, m, &tA, (void *) mem_align);
sda = tA.cn;
dA = tA.dA;
ii = 0;
#if defined(TARGET_X64_INTEL_HASWELL) | defined(TARGET_ARMV8A_ARM_CORTEX_A53)
for(; ii<m-11; ii+=12)
{
for(jj=0; jj<ii; jj+=4)
{
kernel_dpack_tn_4_lib4(4, C+jj+(ii+0)*ldc, ldc, tA.pA+(ii+0)*sda+jj*ps);
kernel_dpack_tn_4_lib4(4, C+jj+(ii+4)*ldc, ldc, tA.pA+(ii+4)*sda+jj*ps);
kernel_dpack_tn_4_lib4(4, C+jj+(ii+8)*ldc, ldc, tA.pA+(ii+8)*sda+jj*ps);
kernel_dtrsm_nt_rl_inv_12x4_lib4(jj, tA.pA+ii*sda, sda, tA.pA+jj*sda, &d_1, tA.pA+ii*sda+jj*ps, sda, tA.pA+ii*sda+jj*ps, sda, tA.pA+jj*sda+jj*ps, dA+jj);
kernel_dunpack_nt_4_lib4(4, tA.pA+(ii+0)*sda+jj*ps, D+jj+(ii+0)*ldd, ldd);
kernel_dunpack_nt_4_lib4(4, tA.pA+(ii+4)*sda+jj*ps, D+jj+(ii+4)*ldd, ldd);
kernel_dunpack_nt_4_lib4(4, tA.pA+(ii+8)*sda+jj*ps, D+jj+(ii+8)*ldd, ldd);
}
kernel_dpack_tn_4_lib4(4, C+ii+(ii+0)*ldc, ldc, tA.pA+(ii+0)*sda+ii*ps);
kernel_dpack_tn_4_lib4(4, C+ii+(ii+4)*ldc, ldc, tA.pA+(ii+4)*sda+ii*ps);
kernel_dpack_tn_4_lib4(4, C+ii+(ii+8)*ldc, ldc, tA.pA+(ii+8)*sda+ii*ps);
kernel_dpotrf_nt_l_12x4_lib4(ii, tA.pA+ii*sda, sda, tA.pA+ii*sda, tA.pA+ii*sda+ii*ps, sda, tA.pA+ii*sda+ii*ps, sda, dA+ii);
kernel_dunpack_nt_4_lib4(4, tA.pA+(ii+0)*sda+ii*ps, D+ii+(ii+0)*ldd, ldd);
kernel_dunpack_nt_4_lib4(4, tA.pA+(ii+4)*sda+ii*ps, D+ii+(ii+4)*ldd, ldd);
kernel_dunpack_nt_4_lib4(4, tA.pA+(ii+8)*sda+ii*ps, D+ii+(ii+8)*ldd, ldd);
kernel_dpack_tn_4_lib4(4, C+ii+4+(ii+4)*ldc, ldc, tA.pA+(ii+4)*sda+(ii+4)*ps);
kernel_dpack_tn_4_lib4(4, C+ii+4+(ii+8)*ldc, ldc, tA.pA+(ii+8)*sda+(ii+4)*ps);
#if defined(TARGET_X64_INTEL_HASWELL)
kernel_dpack_tn_4_lib4(4, C+ii+8+(ii+8)*ldc, ldc, tA.pA+(ii+8)*sda+(ii+8)*ps);
kernel_dpotrf_nt_l_8x8_lib4(ii+4, tA.pA+(ii+4)*sda, sda, tA.pA+(ii+4)*sda, sda, tA.pA+(ii+4)*sda+(ii+4)*ps, sda, tA.pA+(ii+4)*sda+(ii+4)*ps, sda, dA+ii+4);
kernel_dunpack_nt_4_lib4(4, tA.pA+(ii+4)*sda+(ii+4)*ps, D+ii+4+(ii+4)*ldd, ldd);
kernel_dunpack_nt_4_lib4(4, tA.pA+(ii+8)*sda+(ii+4)*ps, D+ii+4+(ii+8)*ldd, ldd);
kernel_dunpack_nt_4_lib4(4, tA.pA+(ii+8)*sda+(ii+8)*ps, D+ii+8+(ii+8)*ldd, ldd);
#else
kernel_dpotrf_nt_l_8x4_lib4(ii+4, tA.pA+(ii+4)*sda, sda, tA.pA+(ii+4)*sda, tA.pA+(ii+4)*sda+(ii+4)*ps, sda, tA.pA+(ii+4)*sda+(ii+4)*ps, sda, dA+ii+4);
kernel_dunpack_nt_4_lib4(4, tA.pA+(ii+4)*sda+(ii+4)*ps, D+ii+4+(ii+4)*ldd, ldd);
kernel_dunpack_nt_4_lib4(4, tA.pA+(ii+8)*sda+(ii+4)*ps, D+ii+4+(ii+8)*ldd, ldd);
kernel_dpack_tn_4_lib4(4, C+ii+8+(ii+8)*ldc, ldc, tA.pA+(ii+8)*sda+(ii+8)*ps);
kernel_dpotrf_nt_l_4x4_lib4(ii+8, tA.pA+(ii+8)*sda, tA.pA+(ii+8)*sda, tA.pA+(ii+8)*sda+(ii+8)*ps, tA.pA+(ii+8)*sda+(ii+8)*ps, dA+ii+8);
kernel_dunpack_nt_4_lib4(4, tA.pA+(ii+8)*sda+(ii+8)*ps, D+ii+8+(ii+8)*ldd, ldd);
#endif
}
if(ii<m)
{
if(m-ii<=4)
{
goto u_2_left_4;
}
if(m-ii<=8)
{
goto u_2_left_8;
}
else
{
goto u_2_left_12;
}
}
#elif defined(TARGET_X64_INTEL_SANDY_BRIDGE) | defined(TARGET_ARMV8A_ARM_CORTEX_A57)
for(; ii<m-7; ii+=8)
{
for(jj=0; jj<ii; jj+=4)
{
kernel_dpack_tn_4_lib4(4, C+jj+(ii+0)*ldc, ldc, tA.pA+(ii+0)*sda+jj*ps);
kernel_dpack_tn_4_lib4(4, C+jj+(ii+4)*ldc, ldc, tA.pA+(ii+4)*sda+jj*ps);
kernel_dtrsm_nt_rl_inv_8x4_lib4(jj, tA.pA+ii*sda, sda, tA.pA+jj*sda, &d_1, tA.pA+ii*sda+jj*ps, sda, tA.pA+ii*sda+jj*ps, sda, tA.pA+jj*sda+jj*ps, dA+jj);
kernel_dunpack_nt_4_lib4(4, tA.pA+(ii+0)*sda+jj*ps, D+jj+(ii+0)*ldd, ldd);
kernel_dunpack_nt_4_lib4(4, tA.pA+(ii+4)*sda+jj*ps, D+jj+(ii+4)*ldd, ldd);
}
kernel_dpack_tn_4_lib4(4, C+ii+(ii+0)*ldc, ldc, tA.pA+(ii+0)*sda+ii*ps);
kernel_dpack_tn_4_lib4(4, C+ii+(ii+4)*ldc, ldc, tA.pA+(ii+4)*sda+ii*ps);
kernel_dpotrf_nt_l_8x4_lib4(ii, tA.pA+ii*sda, sda, tA.pA+ii*sda, tA.pA+ii*sda+ii*ps, sda, tA.pA+ii*sda+ii*ps, sda, dA+ii);
kernel_dunpack_nt_4_lib4(4, tA.pA+(ii+0)*sda+ii*ps, D+ii+(ii+0)*ldd, ldd);
kernel_dunpack_nt_4_lib4(4, tA.pA+(ii+4)*sda+ii*ps, D+ii+(ii+4)*ldd, ldd);
kernel_dpack_tn_4_lib4(4, C+ii+4+(ii+4)*ldc, ldc, tA.pA+(ii+4)*sda+(ii+4)*ps);
kernel_dpotrf_nt_l_4x4_lib4(ii+4, tA.pA+(ii+4)*sda, tA.pA+(ii+4)*sda, tA.pA+(ii+4)*sda+(ii+4)*ps, tA.pA+(ii+4)*sda+(ii+4)*ps, dA+ii+4);
kernel_dunpack_nt_4_lib4(4, tA.pA+(ii+4)*sda+(ii+4)*ps, D+ii+4+(ii+4)*ldd, ldd);
}
if(ii<m)
{
if(m-ii<=4)
{
goto u_2_left_4;
}
else
{
goto u_2_left_8;
}
}
#else
for(; ii<m-3; ii+=4)
{
for(jj=0; jj<ii; jj+=4)
{
kernel_dpack_tn_4_lib4(4, C+jj+ii*ldc, ldc, tA.pA+ii*sda+jj*ps);
kernel_dtrsm_nt_rl_inv_4x4_lib4(jj, tA.pA+ii*sda, tA.pA+jj*sda, &d_1, tA.pA+ii*sda+jj*ps, tA.pA+ii*sda+jj*ps, tA.pA+jj*sda+jj*ps, dA+jj);
kernel_dunpack_nt_4_lib4(4, tA.pA+ii*sda+jj*ps, D+jj+ii*ldd, ldd);
}
kernel_dpack_tn_4_lib4(4, C+ii+ii*ldc, ldc, tA.pA+ii*sda+ii*ps);
kernel_dpotrf_nt_l_4x4_lib4(ii, tA.pA+ii*sda, tA.pA+ii*sda, tA.pA+ii*sda+ii*ps, tA.pA+ii*sda+ii*ps, dA+ii);
kernel_dunpack_nt_4_lib4(4, tA.pA+ii*sda+ii*ps, D+ii+ii*ldd, ldd);
}
if(ii<m)
{
goto u_2_left_4;
}
#endif
goto u_2_return;
#if defined(TARGET_X64_INTEL_HASWELL) | defined(TARGET_ARMV8A_ARM_CORTEX_A53)
u_2_left_12:
for(jj=0; jj<ii; jj+=4)
{
kernel_dpack_tn_4_lib4(4, C+jj+(ii+0)*ldc, ldc, tA.pA+(ii+0)*sda+jj*ps);
kernel_dpack_tn_4_lib4(4, C+jj+(ii+4)*ldc, ldc, tA.pA+(ii+4)*sda+jj*ps);
kernel_dpack_tn_4_vs_lib4(4, C+jj+(ii+8)*ldc, ldc, tA.pA+(ii+8)*sda+jj*ps, m-ii-8);
kernel_dtrsm_nt_rl_inv_12x4_vs_lib4(jj, tA.pA+ii*sda, sda, tA.pA+jj*sda, &d_1, tA.pA+ii*sda+jj*ps, sda, tA.pA+ii*sda+jj*ps, sda, tA.pA+jj*sda+jj*ps, dA+jj, m-ii, m-jj);
kernel_dunpack_nt_4_lib4(4, tA.pA+(ii+0)*sda+jj*ps, D+jj+(ii+0)*ldd, ldd);
kernel_dunpack_nt_4_lib4(4, tA.pA+(ii+4)*sda+jj*ps, D+jj+(ii+4)*ldd, ldd);
kernel_dunpack_nt_4_vs_lib4(4, tA.pA+(ii+8)*sda+jj*ps, D+jj+(ii+8)*ldd, ldd, m-ii-8);
}
kernel_dpack_tn_4_lib4(4, C+ii+(ii+0)*ldc, ldc, tA.pA+(ii+0)*sda+ii*ps);
kernel_dpack_tn_4_lib4(4, C+ii+(ii+4)*ldc, ldc, tA.pA+(ii+4)*sda+ii*ps);
kernel_dpack_tn_4_vs_lib4(4, C+ii+(ii+8)*ldc, ldc, tA.pA+(ii+8)*sda+ii*ps, m-ii-8);
kernel_dpotrf_nt_l_12x4_vs_lib4(ii, tA.pA+ii*sda, sda, tA.pA+ii*sda, tA.pA+ii*sda+ii*ps, sda, tA.pA+ii*sda+ii*ps, sda, dA+ii, m-ii, m-ii);
kernel_dunpack_nt_4_lib4(4, tA.pA+(ii+0)*sda+ii*ps, D+ii+(ii+0)*ldd, ldd);
kernel_dunpack_nt_4_lib4(4, tA.pA+(ii+4)*sda+ii*ps, D+ii+(ii+4)*ldd, ldd);
kernel_dunpack_nt_4_vs_lib4(4, tA.pA+(ii+8)*sda+ii*ps, D+ii+(ii+8)*ldd, ldd, m-ii-8);
kernel_dpack_tn_4_lib4(4, C+ii+4+(ii+4)*ldc, ldc, tA.pA+(ii+4)*sda+(ii+4)*ps);
kernel_dpack_tn_4_vs_lib4(4, C+ii+4+(ii+8)*ldc, ldc, tA.pA+(ii+8)*sda+(ii+4)*ps, m-ii-8);
#if defined(TARGET_X64_INTEL_HASWELL)
kernel_dpack_tn_4_vs_lib4(4, C+ii+8+(ii+8)*ldc, ldc, tA.pA+(ii+8)*sda+(ii+8)*ps, m-ii-8); // TODO triangle
kernel_dpotrf_nt_l_8x8_vs_lib4(ii+4, tA.pA+(ii+4)*sda, sda, tA.pA+(ii+4)*sda, sda, tA.pA+(ii+4)*sda+(ii+4)*ps, sda, tA.pA+(ii+4)*sda+(ii+4)*ps, sda, dA+ii+4, m-ii-4, m-ii-4);
kernel_dunpack_nt_4_lib4(4, tA.pA+(ii+4)*sda+(ii+4)*ps, D+ii+4+(ii+4)*ldd, ldd);
kernel_dunpack_nt_4_vs_lib4(4, tA.pA+(ii+8)*sda+(ii+4)*ps, D+ii+4+(ii+8)*ldd, ldd, m-ii-8);
kernel_dunpack_nt_4_vs_lib4(4, tA.pA+(ii+8)*sda+(ii+8)*ps, D+ii+8+(ii+8)*ldd, ldd, m-ii-8); // TODO triangle
#else
kernel_dpotrf_nt_l_8x4_vs_lib4(ii+4, tA.pA+(ii+4)*sda, sda, tA.pA+(ii+4)*sda, tA.pA+(ii+4)*sda+(ii+4)*ps, sda, tA.pA+(ii+4)*sda+(ii+4)*ps, sda, dA+ii+4, m-ii-4, m-ii-4);
kernel_dunpack_nt_4_lib4(4, tA.pA+(ii+4)*sda+(ii+4)*ps, D+ii+4+(ii+4)*ldd, ldd);
kernel_dunpack_nt_4_vs_lib4(4, tA.pA+(ii+8)*sda+(ii+4)*ps, D+ii+4+(ii+8)*ldd, ldd, m-ii-8);
kernel_dpack_tn_4_vs_lib4(4, C+ii+8+(ii+8)*ldc, ldc, tA.pA+(ii+8)*sda+(ii+8)*ps, m-ii-8); // TODO triangle
kernel_dpotrf_nt_l_4x4_vs_lib4(ii+8, tA.pA+(ii+8)*sda, tA.pA+(ii+8)*sda, tA.pA+(ii+8)*sda+(ii+8)*ps, tA.pA+(ii+8)*sda+(ii+8)*ps, dA+ii+8, m-ii-8, m-ii-8);
kernel_dunpack_nt_4_vs_lib4(4, tA.pA+(ii+8)*sda+(ii+8)*ps, D+ii+8+(ii+8)*ldd, ldd, m-ii-8); // TODO triangle
#endif
goto u_2_return;
#endif
#if defined(TARGET_X64_INTEL_HASWELL) | defined(TARGET_X64_INTEL_SANDY_BRIDGE) | defined(TARGET_ARMV8A_ARM_CORTEX_A57) | defined(TARGET_ARMV8A_ARM_CORTEX_A53)
u_2_left_8:
for(jj=0; jj<ii; jj+=4)
{
kernel_dpack_tn_4_lib4(4, C+jj+(ii+0)*ldc, ldc, tA.pA+(ii+0)*sda+jj*ps);
kernel_dpack_tn_4_vs_lib4(4, C+jj+(ii+4)*ldc, ldc, tA.pA+(ii+4)*sda+jj*ps, m-ii-4);
kernel_dtrsm_nt_rl_inv_8x4_vs_lib4(jj, tA.pA+ii*sda, sda, tA.pA+jj*sda, &d_1, tA.pA+ii*sda+jj*ps, sda, tA.pA+ii*sda+jj*ps, sda, tA.pA+jj*sda+jj*ps, dA+jj, m-ii, m-jj);
kernel_dunpack_nt_4_lib4(4, tA.pA+(ii+0)*sda+jj*ps, D+jj+(ii+0)*ldd, ldd);
kernel_dunpack_nt_4_vs_lib4(4, tA.pA+(ii+4)*sda+jj*ps, D+jj+(ii+4)*ldd, ldd, m-ii-4);
}
kernel_dpack_tn_4_lib4(4, C+ii+(ii+0)*ldc, ldc, tA.pA+(ii+0)*sda+ii*ps);
kernel_dpack_tn_4_vs_lib4(4, C+ii+(ii+4)*ldc, ldc, tA.pA+(ii+4)*sda+ii*ps, m-ii-4);
kernel_dpotrf_nt_l_8x4_vs_lib4(ii, tA.pA+ii*sda, sda, tA.pA+ii*sda, tA.pA+ii*sda+ii*ps, sda, tA.pA+ii*sda+ii*ps, sda, dA+ii, m-ii, m-ii);
kernel_dunpack_nt_4_lib4(4, tA.pA+(ii+0)*sda+ii*ps, D+ii+(ii+0)*ldd, ldd);
kernel_dunpack_nt_4_vs_lib4(4, tA.pA+(ii+4)*sda+ii*ps, D+ii+(ii+4)*ldd, ldd, m-ii-4);
kernel_dpack_tn_4_vs_lib4(4, C+ii+4+(ii+4)*ldc, ldc, tA.pA+(ii+4)*sda+(ii+4)*ps, m-ii-4); // TODO triangle
kernel_dpotrf_nt_l_4x4_vs_lib4(ii+4, tA.pA+(ii+4)*sda, tA.pA+(ii+4)*sda, tA.pA+(ii+4)*sda+(ii+4)*ps, tA.pA+(ii+4)*sda+(ii+4)*ps, dA+ii+4, m-ii-4, m-ii-4);
kernel_dunpack_nt_4_vs_lib4(4, tA.pA+(ii+4)*sda+(ii+4)*ps, D+ii+4+(ii+4)*ldd, ldd, m-ii-4); // TODO triangle
goto u_2_return;
#endif
u_2_left_4:
for(jj=0; jj<ii; jj+=4)
{
kernel_dpack_tn_4_vs_lib4(4, C+jj+ii*ldc, ldc, tA.pA+ii*sda+jj*ps, m-ii);
kernel_dtrsm_nt_rl_inv_4x4_vs_lib4(jj, tA.pA+ii*sda, tA.pA+jj*sda, &d_1, tA.pA+ii*sda+jj*ps, tA.pA+ii*sda+jj*ps, tA.pA+jj*sda+jj*ps, dA+jj, m-ii, m-jj);
kernel_dunpack_nt_4_vs_lib4(4, tA.pA+ii*sda+jj*ps, D+jj+ii*ldd, ldd, m-ii);
}
kernel_dpack_tn_4_vs_lib4(4, C+ii+ii*ldc, ldc, tA.pA+ii*sda+ii*ps, m-ii); // TODO triangle
kernel_dpotrf_nt_l_4x4_vs_lib4(ii, tA.pA+ii*sda, tA.pA+ii*sda, tA.pA+ii*sda+ii*ps, tA.pA+ii*sda+ii*ps, dA+ii, m-ii, m-ii);
kernel_dunpack_nt_4_vs_lib4(4, tA.pA+ii*sda+ii*ps, D+ii+ii*ldd, ldd, m-ii); // TODO triangle
goto u_2_return;
u_2_return:
free(mem);
return;
// never to get here
return;
}
void blasfeo_hp_dpotrf_l_mn(int m, int n, struct blasfeo_dmat *sC, int ci, int cj, struct blasfeo_dmat *sD, int di, int dj)
{
#if defined(PRINT_NAME)
printf("\nblasfeo_hp_dpotrf_l_mn (cm) %d %d %p %d %d %p %d %d\n", m, n, sC, ci, cj, sD, di, dj);
#endif
if(m<=0)
return;
// extract pointer to column-major matrices from structures
int ldc = sC->m;
int ldd = sD->m;
double *C = sC->pA + ci + cj*ldc;
double *D = sD->pA + di + dj*ldd;
// printf("\n%p %d %p %d\n", C, ldc, D, ldd);
int ii, jj;
const int ps = 4; //D_PS;
#if defined(TARGET_GENERIC)
double pU[4*K_MAX_STACK];
double dU[K_MAX_STACK];
#else
ALIGNED( double pU[M_KERNEL*K_MAX_STACK], 64 );
ALIGNED( double dU[K_MAX_STACK], 64 );
#endif
int sdu = (m+3)/4*4;
sdu = sdu<K_MAX_STACK ? sdu : K_MAX_STACK;
struct blasfeo_pm_dmat tA;
int sda;
double *dA;
int tA_size;
void *mem;
char *mem_align;
int m1, n1, k1;
int pack_B;
const int m_kernel = M_KERNEL;
const int l1_cache_el = L1_CACHE_EL;
const int reals_per_cache_line = CACHE_LINE_EL;
const int m_cache = (m+reals_per_cache_line-1)/reals_per_cache_line*reals_per_cache_line;
const int n_cache = (n+reals_per_cache_line-1)/reals_per_cache_line*reals_per_cache_line;
// const int k_cache = (k+reals_per_cache_line-1)/reals_per_cache_line*reals_per_cache_line;
const int m_kernel_cache = (m_kernel+reals_per_cache_line-1)/reals_per_cache_line*reals_per_cache_line;
int m_min = m_cache<m_kernel_cache ? m_cache : m_kernel_cache;
// int n_min = n_cache<m_kernel_cache ? n_cache : m_kernel_cache;
double d_1 = 1.0;
int kend;
// goto l_0;
// goto l_1;
#if defined(TARGET_X64_INTEL_HASWELL)
if(m>=200 | m>K_MAX_STACK)
#elif defined(TARGET_X64_INTEL_SANDY_BRIDGE)
if(m>=64 | m>K_MAX_STACK)
#else
if(m>=12 | m>K_MAX_STACK)
#endif
{
goto l_1;
}
else
{
goto l_0;
}
// never to get here
return;
l_0:
ii = 0;
#if defined(TARGET_X64_INTEL_HASWELL)
for(; ii<m-11; ii+=12)
{
for(jj=0; jj<ii & jj<n-3; jj+=4)
{
kernel_dtrsm_nt_rl_inv_12x4_lib4cccc(jj, pU, sdu, D+jj, ldd, &d_1, C+ii+jj*ldc, ldc, D+ii+jj*ldd, ldd, D+jj+jj*ldd, ldd, dU+jj);
kernel_dpack_nn_12_lib4(4, D+ii+jj*ldd, ldd, pU+jj*ps, sdu);
}
if(jj<n)
{
if(jj<ii) // dtrsm
{
kernel_dtrsm_nt_rl_inv_12x4_vs_lib4cccc(jj, pU, sdu, D+jj, ldd, &d_1, C+ii+jj*ldc, ldc, D+ii+jj*ldd, ldd, D+jj+jj*ldd, ldd, dU+jj, m-ii, n-jj);
kend = n-jj<4 ? n-jj : 4;
kernel_dpack_nn_12_vs_lib4(kend, D+ii+jj*ldd, ldd, pU+jj*ps, sdu, m-ii);
}
else // dpotrf
{
if(jj<n-11)
{
kernel_dpotrf_nt_l_12x4_lib44cc(jj, pU, sdu, pU, C+ii+jj*ldc, ldc, D+ii+jj*ldd, ldd, dU+jj);
kernel_dpack_nn_8_lib4(4, D+ii+4+jj*ldd, ldd, pU+4*sdu+jj*ps, sdu);
#if defined(TARGET_X64_INTEL_HASWELL)
kernel_dpotrf_nt_l_8x8_lib44cc(jj+4, pU+4*sdu, sdu, pU+4*sdu, sdu, C+ii+4+(jj+4)*ldc, ldc, D+ii+4+(jj+4)*ldd, ldd, dU+jj+4);
kernel_dpack_nn_4_lib4(4, D+ii+8+(jj+4)*ldd, ldd, pU+8*sdu+(jj+4)*ps);
#else
kernel_dpotrf_nt_l_8x4_lib44cc(jj+4, pU+4*sdu, sdu, pU+4*sdu, C+ii+4+(jj+4)*ldc, ldc, D+ii+4+(jj+4)*ldd, ldd, dU+jj+4);
kernel_dpack_nn_4_lib4(4, D+ii+8+(jj+4)*ldd, ldd, pU+8*sdu+(jj+4)*ps);
kernel_dpotrf_nt_l_4x4_lib44cc(jj+8, pU+8*sdu, pU+8*sdu, C+ii+8+(jj+8)*ldc, ldc, D+ii+8+(jj+8)*ldd, ldd, dU+jj+8);
#endif
}
else
{
kernel_dpotrf_nt_l_12x4_vs_lib44cc(jj, pU, sdu, pU, C+ii+jj*ldc, ldc, D+ii+jj*ldd, ldd, dU+jj, m-ii, n-jj);
kend = n-jj<4 ? n-jj : 4;
kernel_dpack_nn_8_vs_lib4(kend, D+ii+4+jj*ldd, ldd, pU+4*sdu+jj*ps, sdu, m-ii);
#if defined(TARGET_X64_INTEL_HASWELL)
if(jj<n-8)
{
kernel_dpotrf_nt_l_8x8_vs_lib44cc(jj+4, pU+4*sdu, sdu, pU+4*sdu, sdu, C+ii+4+(jj+4)*ldc, ldc, D+ii+4+(jj+4)*ldd, ldd, dU+jj+4, m-ii-4, n-jj-4);
kend = n-jj-4<4 ? n-jj-4 : 4;
kernel_dpack_nn_4_vs_lib4(kend, D+ii+8+(jj+4)*ldd, ldd, pU+8*sdu+(jj+4)*ps, m-ii-4);
}
else
{
#endif
if(jj<n-4)
{
kernel_dpotrf_nt_l_8x4_vs_lib44cc(jj+4, pU+4*sdu, sdu, pU+4*sdu, C+ii+4+(jj+4)*ldc, ldc, D+ii+4+(jj+4)*ldd, ldd, dU+jj+4, m-ii-4, n-jj-4);
kend = n-jj-4<4 ? n-jj-4 : 4;
kernel_dpack_nn_4_vs_lib4(kend, D+ii+8+(jj+4)*ldd, ldd, pU+8*sdu+(jj+4)*ps, m-ii-4);
if(jj<n-8)
{
kernel_dpotrf_nt_l_4x4_vs_lib44cc(jj+8, pU+8*sdu, pU+8*sdu, C+ii+8+(jj+8)*ldc, ldc, D+ii+8+(jj+8)*ldd, ldd, dU+jj+8, m-ii-8, n-jj-8);
}
}
#if defined(TARGET_X64_INTEL_HASWELL)
}
#endif
}
}
}
}
if(ii<m)
{
if(m-ii<=4)
{
goto l_0_left_4;
}
if(m-ii<=8)
{
goto l_0_left_8;
}
else
{
goto l_0_left_12;
}
}
#elif defined(TARGET_X64_INTEL_SANDY_BRIDGE)
for(; ii<m-7; ii+=8)
{
for(jj=0; jj<ii & jj<n-3; jj+=4)
{
kernel_dtrsm_nt_rl_inv_8x4_lib4cccc(jj, pU, sdu, D+jj, ldd, &d_1, C+ii+jj*ldc, ldc, D+ii+jj*ldd, ldd, D+jj+jj*ldd, ldd, dU+jj);
kernel_dpack_nn_8_lib4(4, D+ii+jj*ldd, ldd, pU+jj*ps, sdu);
}
if(jj<n)
{
if(jj<ii) // dtrsm
{
kernel_dtrsm_nt_rl_inv_8x4_vs_lib4cccc(jj, pU, sdu, D+jj, ldd, &d_1, C+ii+jj*ldc, ldc, D+ii+jj*ldd, ldd, D+jj+jj*ldd, ldd, dU+jj, m-ii, n-jj);
kend = n-jj<4 ? n-jj : 4;
kernel_dpack_nn_8_vs_lib4(kend, D+ii+jj*ldd, ldd, pU+jj*ps, sdu, m-ii);
}
else // dpotrf
{
if(jj<n-7)
{
kernel_dpotrf_nt_l_8x4_lib44cc(jj, pU, sdu, pU, C+ii+jj*ldc, ldc, D+ii+jj*ldd, ldd, dU+jj);
kernel_dpack_nn_4_lib4(4, D+ii+4+jj*ldd, ldd, pU+4*sdu+jj*ps);
kernel_dpotrf_nt_l_4x4_lib44cc(jj+4, pU+4*sdu, pU+4*sdu, C+ii+4+(jj+4)*ldc, ldc, D+ii+4+(jj+4)*ldd, ldd, dU+jj+4);
}
else
{
kernel_dpotrf_nt_l_8x4_vs_lib44cc(jj, pU, sdu, pU, C+ii+jj*ldc, ldc, D+ii+jj*ldd, ldd, dU+jj, m-ii, n-jj);
kend = n-jj<4 ? n-jj : 4;
kernel_dpack_nn_4_vs_lib4(kend, D+ii+4+jj*ldd, ldd, pU+4*sdu+jj*ps, m-ii-4);
if(jj<n-4)
{
kernel_dpotrf_nt_l_4x4_vs_lib44cc(jj+4, pU+4*sdu, pU+4*sdu, C+ii+4+(jj+4)*ldc, ldc, D+ii+4+(jj+4)*ldd, ldd, dU+jj+4, m-ii-4, n-jj-4);
}
}
}
}
}
if(ii<m)
{
if(m-ii<=4)
{
goto l_0_left_4;
}
else
{
goto l_0_left_8;
}
}
#else
for(; ii<m-3; ii+=4)
{
for(jj=0; jj<ii & jj<n-3; jj+=4)
{
kernel_dtrsm_nt_rl_inv_4x4_lib4cccc(jj, pU, D+jj, ldd, &d_1, C+ii+jj*ldc, ldc, D+ii+jj*ldd, ldd, D+jj+jj*ldd, ldd, dU+jj);
kernel_dpack_nn_4_lib4(4, D+ii+jj*ldd, ldd, pU+jj*ps);
}
if(jj<n)
{
if(jj<ii) // dtrsm
{
kernel_dtrsm_nt_rl_inv_4x4_vs_lib4cccc(jj, pU, D+jj, ldd, &d_1, C+ii+jj*ldc, ldc, D+ii+jj*ldd, ldd, D+jj+jj*ldd, ldd, dU+jj, m-ii, n-jj);
kend = n-jj<4 ? n-jj : 4;
kernel_dpack_nn_4_vs_lib4(kend, D+ii+jj*ldd, ldd, pU+jj*ps, m-ii);
}
else // dpotrf
{
if(jj<n-3)
{
kernel_dpotrf_nt_l_4x4_lib44cc(jj, pU, pU, C+ii+jj*ldc, ldc, D+ii+jj*ldd, ldd, dU+jj);
}
else
{
kernel_dpotrf_nt_l_4x4_vs_lib44cc(jj, pU, pU, C+ii+jj*ldc, ldc, D+ii+jj*ldd, ldd, dU+jj, m-ii, n-jj);
}
}
}
}
if(ii<m)
{
goto l_0_left_4;
}
#endif
goto l_0_return;
#if defined(TARGET_X64_INTEL_HASWELL)
l_0_left_12:
for(jj=0; jj<ii & jj<n; jj+=4)
{
kernel_dtrsm_nt_rl_inv_12x4_vs_lib4cccc(jj, pU, sdu, D+jj, ldd, &d_1, C+ii+jj*ldc, ldc, D+ii+jj*ldd, ldd, D+jj+jj*ldd, ldd, dU+jj, m-ii, n-jj);
kernel_dpack_nn_12_vs_lib4(4, D+ii+jj*ldd, ldd, pU+jj*ps, sdu, m-ii);
}
if(jj<n)
{
kernel_dpotrf_nt_l_12x4_vs_lib44cc(jj, pU, sdu, pU, C+ii+jj*ldc, ldc, D+ii+jj*ldd, ldd, dU+jj, m-ii, n-jj);
kend = n-jj<4 ? n-jj : 4;
kernel_dpack_nn_8_vs_lib4(kend, D+ii+4+jj*ldd, ldd, pU+4*sdu+jj*ps, sdu, m-ii-4);
#if defined(TARGET_X64_INTEL_HASWELL)
if(jj<n-8)
{
kernel_dpotrf_nt_l_8x8_vs_lib44cc(jj+4, pU+4*sdu, sdu, pU+4*sdu, sdu, C+ii+4+(jj+4)*ldc, ldc, D+ii+4+(jj+4)*ldd, ldd, dU+jj+4, m-(ii+4), n-(jj+4));
// XXX not needed before return
// kend = n-jj-4<4 ? n-jj-4 : 4;
// kernel_dpack_nn_4_vs_lib4(kend, D+ii+8+(jj+4)*ldd, ldd, pU+8*sdu+(jj+4)*ps, m-ii-8);
goto l_0_return;
}
#endif
if(jj<n-4)
{
kernel_dpotrf_nt_l_8x4_vs_lib44cc(jj+4, pU+4*sdu, sdu, pU+4*sdu, C+ii+4+(jj+4)*ldc, ldc, D+ii+4+(jj+4)*ldd, ldd, dU+jj+4, m-(ii+4), n-(jj+4));
kend = n-jj-4<4 ? n-jj-4 : 4;
kernel_dpack_nn_4_vs_lib4(kend, D+ii+8+(jj+4)*ldd, ldd, pU+8*sdu+(jj+4)*ps, m-ii-8);
if(jj<n-8)
{
kernel_dpotrf_nt_l_4x4_vs_lib44cc(jj+8, pU+8*sdu, pU+8*sdu, C+ii+8+(jj+8)*ldc, ldc, D+ii+8+(jj+8)*ldd, ldd, dU+jj+8, m-ii-8, n-jj-8);
}
}
}
goto l_0_return;
#endif
#if defined(TARGET_X64_INTEL_HASWELL) | defined(TARGET_X64_INTEL_SANDY_BRIDGE)
l_0_left_8:
for(jj=0; jj<ii & jj<n; jj+=4)
{
kernel_dtrsm_nt_rl_inv_8x4_vs_lib4cccc(jj, pU, sdu, D+jj, ldd, &d_1, C+ii+jj*ldc, ldc, D+ii+jj*ldd, ldd, D+jj+jj*ldd, ldd, dU+jj, m-ii, n-jj);
kend = n-jj<4 ? n-jj : 4;
kernel_dpack_nn_8_vs_lib4(kend, D+ii+jj*ldd, ldd, pU+jj*ps, sdu, m-ii);
}
if(jj<n)
{
#if defined(TARGET_X64_INTEL_HASWELL)
if(jj<n-4)
{
kernel_dpotrf_nt_l_8x8_vs_lib44cc(jj, pU, sdu, pU, sdu, C+ii+jj*ldc, ldc, D+ii+jj*ldd, ldd, dU+jj, m-ii, n-jj);
// XXX not needed before return
// kend = n-jj<4 ? n-jj : 4;
// kernel_dpack_nn_4_vs_lib4(kend, D+ii+4+jj*ldd, ldd, pU+4*sdu+jj*ps, m-ii-4);
goto l_0_return;
}
#endif
kernel_dpotrf_nt_l_8x4_vs_lib44cc(jj, pU, sdu, pU, C+ii+jj*ldc, ldc, D+ii+jj*ldd, ldd, dU+jj, m-ii, n-jj);
kend = n-jj<4 ? n-jj : 4;
kernel_dpack_nn_4_vs_lib4(kend, D+ii+4+jj*ldd, ldd, pU+4*sdu+jj*ps, m-ii-4);
if(jj<n-4)
{
kernel_dpotrf_nt_l_4x4_vs_lib44cc(jj+4, pU+4*sdu, pU+4*sdu, C+ii+4+(jj+4)*ldc, ldc, D+ii+4+(jj+4)*ldd, ldd, dU+jj+4, m-ii-4, n-jj-4);
}
}
goto l_0_return;
#endif
l_0_left_4:
for(jj=0; jj<ii & jj<n; jj+=4)
{
kernel_dtrsm_nt_rl_inv_4x4_vs_lib4cccc(jj, pU, D+jj, ldd, &d_1, C+ii+jj*ldc, ldc, D+ii+jj*ldd, ldd, D+jj+jj*ldd, ldd, dU+jj, m-ii, n-jj);
kend = n-jj<4 ? n-jj : 4;
kernel_dpack_nn_4_vs_lib4(kend, D+ii+jj*ldd, ldd, pU+jj*ps, m-ii);
}
if(jj<n)
{
kernel_dpotrf_nt_l_4x4_vs_lib44cc(jj, pU, pU, C+ii+jj*ldc, ldc, D+ii+jj*ldd, ldd, dU+jj, m-ii, n-jj);
}
goto l_0_return;
l_0_return:
return;
l_1:
m1 = (m+128-1)/128*128;
n1 = (n+128-1)/128*128;
tA_size = blasfeo_pm_memsize_dmat(ps, m1, n1);
mem = malloc(tA_size+64);
blasfeo_align_64_byte(mem, (void **) &mem_align);
blasfeo_pm_create_dmat(ps, m, n, &tA, (void *) mem_align);
sda = tA.cn;
dA = tA.dA;
blasfeo_hp_dpotrf_l_mn_m2(m, n, C, ldc, D, ldd, tA.pA, dA, sda);
free(mem);
return;
// never to get here
return;
}
#if defined(LA_HIGH_PERFORMANCE)
void blasfeo_dpotrf_l(int m, struct blasfeo_dmat *sC, int ci, int cj, struct blasfeo_dmat *sD, int di, int dj)
{
blasfeo_hp_dpotrf_l(m, sC, ci, cj, sD, di, dj);
}
void blasfeo_dpotrf_u(int m, struct blasfeo_dmat *sC, int ci, int cj, struct blasfeo_dmat *sD, int di, int dj)
{
blasfeo_hp_dpotrf_u(m, sC, ci, cj, sD, di, dj);
}
void blasfeo_dpotrf_l_mn(int m, int n, struct blasfeo_dmat *sC, int ci, int cj, struct blasfeo_dmat *sD, int di, int dj)
{
blasfeo_hp_dpotrf_l_mn(m, n, sC, ci, cj, sD, di, dj);
}
#endif
|
3cf8a93fee2182d7036ccd39bb0e357600eee219
|
99bdb3251fecee538e0630f15f6574054dfc1468
|
/bsp/wch/arm/ch579m/libraries/StdPeriphDriver/inc/CH57x_usbdev.h
|
e01e11fa0d293692762bdbe0afb53796ee2318ad
|
[
"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
| 2,318
|
h
|
CH57x_usbdev.h
|
#ifndef __CH57x_USBDEV_H__
#define __CH57x_USBDEV_H__
#ifdef __cplusplus
extern "C" {
#endif
#include "CH579SFR.h"
#include "core_cm0.h"
/* 以下缓存区是USB模块收发使用的数据缓冲区,总共9个通道(9块缓存),用户可根据实际使用的通道数定义相应缓存区 */
extern PUINT8 pEP0_RAM_Addr; //ep0(64)+ep4_out(64)+ep4_in(64)
extern PUINT8 pEP1_RAM_Addr; //ep1_out(64)+ep1_in(64)
extern PUINT8 pEP2_RAM_Addr; //ep2_out(64)+ep2_in(64)
extern PUINT8 pEP3_RAM_Addr; //ep3_out(64)+ep3_in(64)
#define pSetupReqPak ((PUSB_SETUP_REQ)pEP0_RAM_Addr)
#define pEP0_DataBuf (pEP0_RAM_Addr)
#define pEP1_OUT_DataBuf (pEP1_RAM_Addr)
#define pEP1_IN_DataBuf (pEP1_RAM_Addr+64)
#define pEP2_OUT_DataBuf (pEP2_RAM_Addr)
#define pEP2_IN_DataBuf (pEP2_RAM_Addr+64)
#define pEP3_OUT_DataBuf (pEP3_RAM_Addr)
#define pEP3_IN_DataBuf (pEP3_RAM_Addr+64)
#define pEP4_OUT_DataBuf (pEP0_RAM_Addr+64)
#define pEP4_IN_DataBuf (pEP0_RAM_Addr+128)
void USB_DeviceInit( void ); /* USB设备功能初始化,4个端点,8个通道 */
void USB_DevTransProcess( void ); /* USB设备应答传输处理 */
void DevEP1_OUT_Deal( UINT8 l ); /* 设备端点1下传通道处理 */
void DevEP2_OUT_Deal( UINT8 l ); /* 设备端点2下传通道处理 */
void DevEP3_OUT_Deal( UINT8 l ); /* 设备端点3下传通道处理 */
void DevEP4_OUT_Deal( UINT8 l ); /* 设备端点4下传通道处理 */
void DevEP1_IN_Deal( UINT8 l ); /* 设备端点1上传通道处理 */
void DevEP2_IN_Deal( UINT8 l ); /* 设备端点2上传通道处理 */
void DevEP3_IN_Deal( UINT8 l ); /* 设备端点3上传通道处理 */
void DevEP4_IN_Deal( UINT8 l ); /* 设备端点4上传通道处理 */
// 0-未完成 (!0)-已完成
#define EP1_GetINSta() (R8_UEP1_CTRL&UEP_T_RES_NAK) /* 查询端点1是否上传完成 */
#define EP2_GetINSta() (R8_UEP2_CTRL&UEP_T_RES_NAK) /* 查询端点2是否上传完成 */
#define EP3_GetINSta() (R8_UEP3_CTRL&UEP_T_RES_NAK) /* 查询端点3是否上传完成 */
#define EP4_GetINSta() (R8_UEP4_CTRL&UEP_T_RES_NAK) /* 查询端点4是否上传完成 */
#ifdef __cplusplus
}
#endif
#endif // __CH57x_USBDEV_H__
|
fa300e85f4493bf6c90204e68014c48ac6b2b68d
|
28d0f8c01599f8f6c711bdde0b59f9c2cd221203
|
/sys/arch/arm/sunxi/sun9i_a80_cpusclk.c
|
7fb51788ed6ffa273e512165d184fd230a7a40d7
|
[] |
no_license
|
NetBSD/src
|
1a9cbc22ed778be638b37869ed4fb5c8dd616166
|
23ee83f7c0aea0777bd89d8ebd7f0cde9880d13c
|
refs/heads/trunk
| 2023-08-31T13:24:58.105962
| 2023-08-27T15:50:47
| 2023-08-27T15:50:47
| 88,439,547
| 656
| 348
| null | 2023-07-20T20:07:24
| 2017-04-16T20:03:43
| null |
UTF-8
|
C
| false
| false
| 5,901
|
c
|
sun9i_a80_cpusclk.c
|
/* $NetBSD: sun9i_a80_cpusclk.c,v 1.2 2021/01/27 03:10:20 thorpej Exp $ */
/*-
* Copyright (c) 2017 Jared McNeill <jmcneill@invisible.ca>
* 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.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: sun9i_a80_cpusclk.c,v 1.2 2021/01/27 03:10:20 thorpej Exp $");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/device.h>
#include <sys/kmem.h>
#include <sys/bus.h>
#include <dev/clk/clk_backend.h>
#include <dev/fdt/fdtvar.h>
#define CPUS_CLK_SRC_SEL __BITS(17,16)
#define CPUS_CLK_SRC_SEL_PLL_PERIPH0 2
#define CPUS_POST_DIV __BITS(12,8)
#define CPUS_CLK_RATIO __BITS(5,4)
static int sun9i_a80_cpusclk_match(device_t, cfdata_t, void *);
static void sun9i_a80_cpusclk_attach(device_t, device_t, void *);
static struct clk *sun9i_a80_cpusclk_decode(device_t, int, const void *, size_t);
static const struct fdtbus_clock_controller_func sun9i_a80_cpusclk_fdt_funcs = {
.decode = sun9i_a80_cpusclk_decode
};
static struct clk *sun9i_a80_cpusclk_get(void *, const char *);
static void sun9i_a80_cpusclk_put(void *, struct clk *);
static int sun9i_a80_cpusclk_set_rate(void *, struct clk *, u_int);
static u_int sun9i_a80_cpusclk_get_rate(void *, struct clk *);
static struct clk *sun9i_a80_cpusclk_get_parent(void *, struct clk *);
static const struct clk_funcs sun9i_a80_cpusclk_clk_funcs = {
.get = sun9i_a80_cpusclk_get,
.put = sun9i_a80_cpusclk_put,
.set_rate = sun9i_a80_cpusclk_set_rate,
.get_rate = sun9i_a80_cpusclk_get_rate,
.get_parent = sun9i_a80_cpusclk_get_parent,
};
struct sun9i_a80_cpusclk_softc {
device_t sc_dev;
int sc_phandle;
bus_space_tag_t sc_bst;
bus_space_handle_t sc_bsh;
struct clk_domain sc_clkdom;
struct clk sc_clk;
};
#define RD4(sc, reg) \
bus_space_read_4((sc)->sc_bst, (sc)->sc_bsh, (reg))
#define WR4(sc, reg, val) \
bus_space_write_4((sc)->sc_bst, (sc)->sc_bsh, (reg), (val))
CFATTACH_DECL_NEW(sunxi_a80_cpusclk, sizeof(struct sun9i_a80_cpusclk_softc),
sun9i_a80_cpusclk_match, sun9i_a80_cpusclk_attach, NULL, NULL);
static const struct device_compatible_entry compat_data[] = {
{ .compat = "allwinner,sun9i-a80-cpus-clk" },
DEVICE_COMPAT_EOL
};
static int
sun9i_a80_cpusclk_match(device_t parent, cfdata_t cf, void *aux)
{
const struct fdt_attach_args *faa = aux;
return of_compatible_match(faa->faa_phandle, compat_data);
}
static void
sun9i_a80_cpusclk_attach(device_t parent, device_t self, void *aux)
{
struct sun9i_a80_cpusclk_softc * const sc = device_private(self);
const struct fdt_attach_args *faa = aux;
const int phandle = faa->faa_phandle;
bus_addr_t addr;
bus_size_t size;
if (fdtbus_get_reg(phandle, 0, &addr, &size) != 0) {
aprint_error(": couldn't get registers\n");
return;
}
sc->sc_dev = self;
sc->sc_phandle = phandle;
sc->sc_bst = faa->faa_bst;
if (bus_space_map(sc->sc_bst, addr, size, 0, &sc->sc_bsh) != 0) {
aprint_error(": couldn't map registers\n");
return;
}
sc->sc_clkdom.funcs = &sun9i_a80_cpusclk_clk_funcs;
sc->sc_clkdom.priv = sc;
sc->sc_clk.domain = &sc->sc_clkdom;
sc->sc_clk.name = kmem_asprintf("%s", faa->faa_name);
aprint_naive("\n");
aprint_normal(": A80 CPUS clock\n");
fdtbus_register_clock_controller(self, phandle, &sun9i_a80_cpusclk_fdt_funcs);
}
static struct clk *
sun9i_a80_cpusclk_decode(device_t dev, int cc_phandle, const void *data,
size_t len)
{
struct sun9i_a80_cpusclk_softc * const sc = device_private(dev);
if (len != 0)
return NULL;
return &sc->sc_clk;
}
static struct clk *
sun9i_a80_cpusclk_get(void *priv, const char *name)
{
struct sun9i_a80_cpusclk_softc * const sc = priv;
if (strcmp(name, sc->sc_clk.name) != 0)
return NULL;
return &sc->sc_clk;
}
static void
sun9i_a80_cpusclk_put(void *priv, struct clk *clk)
{
}
static int
sun9i_a80_cpusclk_set_rate(void *priv, struct clk *clk, u_int rate)
{
return ENXIO;
}
static u_int
sun9i_a80_cpusclk_get_rate(void *priv, struct clk *clk)
{
struct sun9i_a80_cpusclk_softc * const sc = priv;
struct clk *clk_parent = clk_get_parent(clk);
u_int rate;
const uint32_t val = RD4(sc, 0);
const u_int sel = __SHIFTOUT(val, CPUS_CLK_SRC_SEL);
const u_int post_div = __SHIFTOUT(val, CPUS_POST_DIV);
const u_int clk_ratio = __SHIFTOUT(val, CPUS_CLK_RATIO);
rate = clk_get_rate(clk_parent) / (clk_ratio + 1);
if (sel == CPUS_CLK_SRC_SEL_PLL_PERIPH0)
rate /= (post_div + 1);
return rate;
}
static struct clk *
sun9i_a80_cpusclk_get_parent(void *priv, struct clk *clk)
{
struct sun9i_a80_cpusclk_softc * const sc = priv;
const uint32_t val = RD4(sc, 0);
const u_int sel = __SHIFTOUT(val, CPUS_CLK_SRC_SEL);
return fdtbus_clock_get_index(sc->sc_phandle, sel);
}
|
c7f1c060a3ed6d269de26e57c37fa34fe90ff8e0
|
2249ea163713b21f14fdf8784ba3ef3c0b540d1a
|
/lib/nauty/nauty.h
|
2215c2f36ab4290d7ef7db7836c3800f4eff62dc
|
[
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-warranty-disclaimer",
"Apache-2.0",
"MIT"
] |
permissive
|
lsils/mockturtle
|
58c106fc957f17206e062b5428055778c68b4a69
|
82fce07b7204b14fc4c53fd35c284b7ea68f05fd
|
refs/heads/master
| 2023-08-31T04:18:37.954364
| 2023-08-24T12:05:37
| 2023-08-24T12:05:37
| 131,001,448
| 159
| 80
|
MIT
| 2023-08-24T09:43:55
| 2018-04-25T12:15:49
|
C++
|
UTF-8
|
C
| false
| false
| 53,468
|
h
|
nauty.h
|
/**************************************************************************
* This is the header file for Version 2.6 of nauty(). *
* nauty.h. Generated from nauty-h.in by configure.
**************************************************************************/
#ifndef _NAUTY_H_ /* only process this file once */
#define _NAUTY_H_
/* The parts between the ==== lines are modified by configure when
creating nauty.h out of nauty-h.in. If configure is not being used,
it is necessary to check they are correct.
====================================================================*/
/* Check whether various headers or options are available */
#define HAVE_UNISTD_H 1 /* <unistd.h> */
#define HAVE_SYSTYPES_H 1 /* <sys/types.h> */
#define HAVE_STDDEF_H 1 /* <stddef.h> */
#define HAVE_STDLIB_H 1 /* <stdlib.h> */
#define HAVE_STRING_H 1 /* <string.h> */
#define MALLOC_DEC 1 /* 1 = malloc() is declared in stdlib.h, */
/* 2 = in malloc.h, 0 = in neither place */
#define HAS_MATH_INF 1 /* INFINITY is defined in math.h or */
/* some system header likely to be used */
#define HAS_STDIO_UNLOCK 1 /* Whether there are getc_unlocked, */
/* putc_unlocked,flockfile and funlockfile*/
#define DEFAULT_WORDSIZE 0
#define SIZEOF_INT 4
#define SIZEOF_LONG 8
#define SIZEOF_LONG_LONG 8 /* 0 if nonexistent */
#define SIZEOF_INT128 16 /* 0 if nonexistent */
#define HAVE_CONST 1 /* compiler properly supports const */
/* Note that the following is only for running nauty in multiple threads
and will slow it down a little otherwise. */
#define HAVE_TLS 0 /* have storage attribute for thread-local */
#define TLS_ATTR /* if so, what it is. if not, empty */
#define USE_ANSICONTROLS 0
/* whether --enable-ansicontrols is used */
#define _FILE_OFFSET_BITS 0
#if _FILE_OFFSET_BITS == 64
#define _LARGEFILE_SOURCE
#else
#undef _FILE_OFFSET_BITS
#endif
/* Support of gcc extensions __builtin_clz, __builtin_clzl, __builtin_clzll */
#define HAVE_CLZ 1
#define HAVE_CLZL 1
#define HAVE_CLZLL 1
/* Support of gcc extensions
__builtin_popcount, __builtin_popcountl, __builtin_popcountll
Note that these may only be fast if the compiler switch -mpopcnt is used.
Also the intrinsics
_mm_popcnt_u32, _mm_popcnt_u64
for the Intel compiler icc. These need no compiler switch.
*/
#define HAVE_HWPOPCNT 0
#define HAVE_POPCNT 0
#define HAVE_POPCNTL 0
#define HAVE_POPCNTLL 0
#define HAVE_MMPOP32 0
#define HAVE_MMPOP64 0
/*==================================================================*/
/* The following line must be uncommented for compiling into Magma. */
/* #define NAUTY_IN_MAGMA */
#ifdef NAUTY_IN_MAGMA
#include "defs.h"
#include "system.h"
#include "bs.h"
#define OLDEXTDEFS
#else
#include <stdio.h>
#define P_(x) x
#endif
#if defined(__unix) || defined(__unix__) || defined(unix)
#define SYS_UNIX
#endif
#if !HAVE_CONST
#define const
#endif
/*****************************************************************************
* *
* AUTHOR: Brendan D. McKay *
* Research School of Computer Science *
* Australian National University *
* Canberra, ACT 2601, Australia *
* phone: +61 2 6125 3845 *
* email: Brendan.McKay@anu.edu.au *
* *
* This software is subject to copyright as detailed in the file COPYRIGHT. *
* *
* Reference manual: *
* B. D. McKay and A. Piperno, nauty User's Guide (Version 2.5), *
* http://pallini.di.uniroma1.it *
* http://cs.anu.edu.au/~bdm/nauty/ *
* *
* CHANGE HISTORY *
* 10-Nov-87 : final changes for version 1.2 *
* 5-Dec-87 : renamed to version 1.3 (no changes to this file) *
* 28-Sep-88 : added PC Turbo C support, making version 1.4 *
* 23-Mar-89 : changes for version 1.5 : *
* - reworked M==1 code *
* - defined NAUTYVERSION string *
* - made NAUTYH_READ to allow this file to be read twice *
* - added optional ANSI function prototypes *
* - added validity check for WORDSIZE *
* - added new fields to optionblk structure *
* - updated DEFAULTOPTIONS to add invariants fields *
* - added (set*) cast to definition of GRAPHROW *
* - added definition of ALLOCS and FREES *
* 25-Mar-89 : - added declaration of new function doref() *
* - added UNION macro *
* 29-Mar-89 : - reduced the default MAXN for small machines *
* - removed OUTOFSPACE (no longer used) *
* - added SETDIFF and XOR macros *
* 2-Apr-89 : - extended statsblk structure *
* 4-Apr-89 : - added IS_* macros *
* - added ERRFILE definition *
* - replaced statsblk.outofspace by statsblk.errstatus *
* 5-Apr-89 : - deleted definition of np2vector (no longer used) *
* - introduced EMPTYSET macro *
* 12-Apr-89 : - eliminated MARK, UNMARK and ISMARKED (no longer used) *
* 18-Apr-89 : - added MTOOBIG and CANONGNIL *
* 12-May-89 : - made ISELEM1 and ISELEMENT return 0 or 1 *
* 2-Mar-90 : - added EXTPROC macro and used it *
* 12-Mar-90 : - added SYS_CRAY, with help from N. Sloane and A. Grosky *
* - added dummy groupopts field to optionblk *
* - select some ANSI things if __STDC__ exists *
* 20-Mar-90 : - changed default MAXN for Macintosh versions *
* - created SYS_MACTHINK for Macintosh THINK compiler *
* 27-Mar-90 : - split SYS_MSDOS into SYS_PCMS4 and SYS_PCMS5 *
* 13-Oct-90 : changes for version 1.6: *
* - fix definition of setword for WORDSIZE==64 *
* 14-Oct-90 : - added SYS_APOLLO version to avoid compiler bug *
* 15-Oct-90 : - improve detection of ANSI conformance *
* 17-Oct-90 : - changed temp name in EMPTYSET to avoid A/UX bug *
* 16-Apr-91 : changes for version 1.7: *
* - made version SYS_PCTURBO use free(), not cfree() *
* 2-Sep-91 : - noted that SYS_PCMS5 also works for Quick C *
* - moved MULTIPLY to here from nauty.c *
* 12-Jun-92 : - changed the top part of this comment *
* 27-Aug-92 : - added version SYS_IBMC, thanks to Ivo Duentsch *
* 5-Jun-93 : - renamed to version 1.7+, only change in naututil.h *
* 29-Jul-93 : changes for version 1.8: *
* - fixed error in default 64-bit version of FIRSTBIT *
* (not used in any version before ALPHA) *
* - installed ALPHA version (thanks to Gordon Royle) *
* - defined ALLOCS,FREES for SYS_IBMC *
* 3-Sep-93 : - make calloc void* in ALPHA version *
* 17-Sep-93 : - renamed to version 1.9, *
* changed only dreadnaut.c and nautinv.c *
* 24-Feb-94 : changes for version 1.10: *
* - added version SYS_AMIGAAZT, thanks to Carsten Saager *
* (making 1.9+) *
* 19-Apr-95 : - added prototype wrapper for C++, *
* thanks to Daniel Huson *
* 5-Mar-96 : - added SYS_ALPHA32 version (32-bit setwords on Alpha) *
* 13-Jul-96 : changes for version 2.0: *
* - added dynamic allocation *
* - ERRFILE must be defined *
* - added FLIPELEM1 and FLIPELEMENT macros *
* 13-Aug-96 : - added SWCHUNK? macros *
* - added TAKEBIT macro *
* 28-Nov-96 : - include sys/types.h if not ANSI (tentative!) *
* 24-Jan-97 : - and stdlib.h if ANSI *
* - removed use of cfree() from UNIX variants *
* 25-Jan-97 : - changed options.getcanon from boolean to int *
* Backwards compatibility is ok, as boolean and int *
* are the same. Now getcanon=2 means to get the label *
* and not care about the group. Sometimes faster. *
* 6-Feb-97 : - Put in #undef for FALSE and TRUE to cope with *
* compilers that illegally predefine them. *
* - declared nauty_null and nautil_null *
* 2-Jul-98 : - declared ALLBITS *
* 21-Oct-98 : - allow WORDSIZE==64 using unsigned long long *
* - added BIGNAUTY option for really big graphs *
* 11-Dec-99 : - made bit, leftbit and bytecount static in each file *
* 9-Jan-00 : - declared nauty_check() and nautil_check() *
* 12-Feb-00 : - Used #error for compile-time checks *
* - Added DYNREALLOC *
* 4-Mar-00 : - declared ALLMASK(n) *
* 27-May-00 : - declared CONDYNFREE *
* 28-May-00 : - declared nautil_freedyn() *
* 16-Aug-00 : - added OLDNAUTY and changed canonical labelling *
* 16-Nov-00 : - function prototypes are now default and unavoidable *
* - removed UPROC, now assume all compilers know void *
* - removed nvector, now just int (as it always was) *
* - added extra parameter to targetcell() *
* - removed old versions which were only to skip around *
* bugs that should have been long fixed: *
* SYS_APOLLO and SYS_VAXBSD. *
* - DEFAULTOPIONS now specifies no output *
* - Removed obsolete SYS_MACLSC version *
* 21-Apr-01 : - Added code to satisfy compilation into Magma. This *
* is activated by defining NAUTY_IN_MAGMA above. *
* - The *_null routines no longer exist *
* - Default maxinvarlevel is now 1. (This has no effect *
* unless an invariant is specified.) *
* - Now labelorg has a concrete declaration in nautil.c *
* and EXTDEFS is not needed *
* 5-May-01 : - NILFUNCTION, NILSET, NILGRAPH now obsolete. Use NULL. *
* 11-Sep-01 : - setword is unsigned int in the event that UINT_MAX *
* is defined and indicates it is big enough *
* 17-Oct-01 : - major rewrite for 2.1. SYS_* variables gone! *
* Some modernity assumed, eg size_t *
* 8-Aug-02 : - removed MAKEEMPTY (use EMPTYSET instead) *
* - deleted OLDNAUTY everywhere *
* 27-Aug-02 : - converted to use autoconf. Now the original of this *
* file is nauty-h.in. Run configure to make nauty.h. *
* 20-Dec-02 : - increased INFINITY *
* some reorganization to please Magma *
* - declared nauty_freedyn() *
* 17-Nov-03 : - renamed INFINITY to NAUTY_INFINITY *
* 29-May-04 : - added definition of SETWORD_FORMAT *
* 14-Sep-04 : - extended prototypes even to recursive functions *
* 16-Oct-04 : - added DEFAULTOPTIONS_GRAPH *
* 24-Oct-04 : Starting 2.3 *
* - remove register declarations as modern compilers *
* tend to find them a nuisance *
* - Don't define the obsolete symbol INFINITY if it is *
* defined already *
* 17-Nov-04 : - make 6 counters in statsblk unsigned long *
* 17-Jan-04 : - add init() and cleanup() to dispatchvec *
* 12-Nov-05 : - Changed NAUTY_INFINITY to 2^30+2 in BIGNAUTY case *
* 22-Nov-06 : Starting 2.4 *
* - removed usertcellproc from options *
* changed bestcell to targetcell in dispatch vector *
* declare targetcell and maketargetcell *
* 29-Nov-06 : - add extraoptions to optionblk *
* - add declarations of extra_autom and extra_level *
* 10-Dec-06 : - BIGNAUTY is gone! Now permutation=shortish=int. *
* NAUTY_INFINITY only depends on whether sizeof(int)=2. *
* 27-Jun-08 : - define nauty_counter and LONG_LONG_COUNTERS *
* 30-Jun-08 : - declare version 2.4 *
* 8-Nov-09 : - final release of version 2.4; *
* 10-Nov-10 : Starting 2.5 *
* - declare shortish and permutation obsolete, now int *
* 14-Nov-10 : - SETWORDSNEEDED(n) *
* 23-May-10 : - declare densenauty() *
* 29-Jun-10 : - add PRINT_COUNTER(f,x) *
* - add DEFAULTOPTIONS_DIGRAPH() *
* 27-Mar-11 : - declare writegroupsize() *
* 14-Jan-12 : - add HAVE_TLS and TLS_ATTR *
* 21-Feb-12 : - add ENABLE_ANSI *
* 18-Mar-12 : - add COUNTER_FMT *
* 18-Aug-12 : - add ADDONEARC, ADDONEEDGE, EMPTYGRAPH *
* 29-Aug-12 : - add CLZ macros and FIRSTBITNZ *
* 19-Oct-12 : - add DEFAULT_WORDSIZE *
* 3-Jan-12 : Released 2.5rc1 *
* 18-Jan-12 : Froze 2.5 *
* 18-Jan-12 : - add NAUABORTED and NAUKILLED *
* - add nauty_kill_request *
* - add usercanonproc *
* 1-Oct-15 : - add COUNTER_FMT_RAW *
* 10-Jan-16 : - defined POPCOUNTMAC, optionally use popcnt *
* - remove SYS_CRAY, let's hope it is long obsolete *
* - add Intel popcount intrinsics for icc *
* 12-Jan-16 : - DYNFREE and CONDYNFREE now set the pointer to NULL *
* 16-Jan-16 : - Change NAUTY_INFINITY to 2 billion + 2 *
* : Froze 2.6 *
* 12-Mar-16 : - Add const to alloc_error() *
* *
* ++++++ This file is automatically generated, don't edit it by hand! ++++++
* *
*****************************************************************************/
/*****************************************************************************
* *
* 16-bit, 32-bit and 64-bit versions can be selected by defining WORDSIZE. *
* The largest graph that can be handled has MAXN vertices. *
* Both WORDSIZE and MAXN can be defined on the command line. *
* WORDSIZE must be 16, 32 or 64; MAXN must be <= NAUTY_INFINITY-2; *
* *
* With a very slight loss of efficiency (depending on platform), nauty *
* can be compiled to dynamically allocate arrays. Predefine MAXN=0 to *
* achieve this effect, which is default behaviour from version 2.0. *
* In that case, graphs of size up to NAUTY_INFINITY-2 can be handled *
* if the the memory is available. *
* *
* If only very small graphs need to be processed, use MAXN<=WORDSIZE *
* since this causes substantial code optimizations. *
* *
* Conventions and Assumptions: *
* *
* A 'setword' is the chunk of memory that is occupied by one part of *
* a set. This is assumed to be >= WORDSIZE bits in size. *
* *
* The rightmost (loworder) WORDSIZE bits of setwords are numbered *
* 0..WORDSIZE-1, left to right. It is necessary that the 2^WORDSIZE *
* setwords with the other bits zero are totally ordered under <,=,>. *
* This needs care on a 1's-complement machine. *
* *
* The int variables m and n have consistent meanings throughout. *
* Graphs have n vertices always, and sets have m setwords always. *
* *
* A 'set' consists of m contiguous setwords, whose bits are numbered *
* 0,1,2,... from left (high-order) to right (low-order), using only *
* the rightmost WORDSIZE bits of each setword. It is used to *
* represent a subset of {0,1,...,n-1} in the usual way - bit number x *
* is 1 iff x is in the subset. Bits numbered n or greater, and *
* unnumbered bits, are assumed permanently zero. *
* *
* A 'graph' consists of n contiguous sets. The i-th set represents *
* the vertices adjacent to vertex i, for i = 0,1,...,n-1. *
* *
* A 'permutation' is an array of n ints repesenting a permutation of *
* the set {0,1,...,n-1}. The value of the i-th entry is the number to *
* which i is mapped. *
* *
* If g is a graph and p is a permutation, then g^p is the graph in *
* which vertex i is adjacent to vertex j iff vertex p[i] is adjacent *
* to vertex p[j] in g. *
* *
* A partition nest is represented by a pair (lab,ptn), where lab and ptn *
* are int arrays. The "partition at level x" is the partition whose *
* cells are {lab[i],lab[i+1],...,lab[j]}, where [i,j] is a maximal *
* subinterval of [0,n-1] such that ptn[k] > x for i <= k < j and *
* ptn[j] <= x. The partition at level 0 is given to nauty by the user. *
* This is refined for the root of the tree, which has level 1. *
* *
*****************************************************************************/
#ifndef NAUTY_IN_MAGMA
#if HAVE_SYSTYPES_H
#include <sys/types.h>
#endif
#if HAVE_UNISTD_H
#include <unistd.h>
#endif
#if HAVE_STDDEF_H
#include <stddef.h>
#endif
#if HAVE_STDLIB_H
#include <stdlib.h>
#endif
#if HAVE_STRING_H
#include <string.h>
#else
#include <strings.h>
#endif
#endif
/* WORDSIZE is the number of set elements per setword (16, 32 or 64).
WORDSIZE and setword are defined as follows:
DEFAULT_WORDSIZE is usually 0 but is set by the configure script
to NN if --enable-wordsize=NN is used, where NN is 16, 32 or 64.
If WORDSIZE is not defined, but DEFAULT_WORDSIZE > 0, then set
WORDSIZE to the same value as DEFAULT_WORDSIZE.
If WORDSIZE is so far undefined, use 32 unless longs have more
than 32 bits, in which case use 64.
Define setword thus:
WORDSIZE==16 : unsigned short
WORDSIZE==32 : unsigned int unless it is too small,
in which case unsigned long
WORDSIZE==64 : the first of unsigned int, unsigned long,
unsigned long long, which is large enough.
*/
#ifdef NAUTY_IN_MAGMA
#undef WORDSIZE
#define WORDSIZE WORDBITS
#endif
#ifndef WORDSIZE
#if DEFAULT_WORDSIZE > 0
#define WORDSIZE DEFAULT_WORDSIZE
#endif
#endif
#ifdef WORDSIZE
#if (WORDSIZE != 16) && (WORDSIZE != 32) && (WORDSIZE != 64)
#error "WORDSIZE must be 16, 32 or 64"
#endif
#else /* WORDSIZE undefined */
#if SIZEOF_LONG>4
#define WORDSIZE 64
#else
#define WORDSIZE 32
#endif
#endif /* WORDSIZE */
#ifdef NAUTY_IN_MAGMA
typedef t_uint setword;
#define SETWORD_INT /* Don't assume this is correct in Magma. */
#else /* NAUTY_IN_MAGMA */
#if WORDSIZE==16
typedef unsigned short setword;
#define SETWORD_SHORT
#endif
#if WORDSIZE==32
#if SIZEOF_INT>=4
typedef unsigned int setword;
#define SETWORD_INT
#else
typedef unsigned long setword;
#define SETWORD_LONG
#endif
#endif
#if WORDSIZE==64
#if SIZEOF_INT>=8
typedef unsigned int setword;
#define SETWORD_INT
#else
#if SIZEOF_LONG>=8
typedef unsigned long setword;
#define SETWORD_LONG
#else
typedef unsigned long long setword;
#define SETWORD_LONGLONG
#endif
#endif
#endif
#endif /* NAUTY_IN_MAGMA else */
#if SIZEOF_LONG_LONG>=8 && SIZEOF_LONG==4
typedef unsigned long long nauty_counter;
#define LONG_LONG_COUNTERS 1
#define COUNTER_FMT "%llu"
#define COUNTER_FMT_RAW "llu"
#else
typedef unsigned long nauty_counter;
#define LONG_LONG_COUNTERS 0
#define COUNTER_FMT "%lu"
#define COUNTER_FMT_RAW "lu"
#endif
#define PRINT_COUNTER(f,x) fprintf(f,COUNTER_FMT,x)
#define NAUTYVERSIONID (26040+HAVE_TLS) /* 10000*version + HAVE_TLS */
#define NAUTYREQUIRED NAUTYVERSIONID /* Minimum compatible version */
#if WORDSIZE==16
#define NAUTYVERSION "2.6 (16 bits)"
#endif
#if WORDSIZE==32
#define NAUTYVERSION "2.6 (32 bits)"
#endif
#if WORDSIZE==64
#define NAUTYVERSION "2.6 (64 bits)"
#endif
#ifndef MAXN /* maximum allowed n value; use 0 for dynamic sizing. */
#define MAXN 0
#define MAXM 0
#else
#define MAXM ((MAXN+WORDSIZE-1)/WORDSIZE) /* max setwords in a set */
#endif /* MAXN */
/* Starting at version 2.2, set operations work for all set sizes unless
ONE_WORD_SETS is defined. In the latter case, if MAXM=1, set ops
work only for single-setword sets. In any case, macro versions
ending with 1 work for single-setword sets and versions ending with
0 work for all set sizes.
*/
#if WORDSIZE==16
#define SETWD(pos) ((pos)>>4) /* number of setword containing bit pos */
#define SETBT(pos) ((pos)&0xF) /* position within setword of bit pos */
#define TIMESWORDSIZE(w) ((w)<<4)
#define SETWORDSNEEDED(n) ((((n)-1)>>4)+1) /* setwords needed for n bits */
#endif
#if WORDSIZE==32
#define SETWD(pos) ((pos)>>5)
#define SETBT(pos) ((pos)&0x1F)
#define TIMESWORDSIZE(w) ((w)<<5)
#define SETWORDSNEEDED(n) ((((n)-1)>>5)+1)
#endif
#if WORDSIZE==64
#define SETWD(pos) ((pos)>>6)
#define SETBT(pos) ((pos)&0x3F)
#define TIMESWORDSIZE(w) ((w)<<6) /* w*WORDSIZE */
#define SETWORDSNEEDED(n) ((((n)-1)>>6)+1)
#endif
#ifdef NAUTY_IN_MAGMA
#define BITT bs_bit
#else
#define BITT bit
#endif
#define ADDELEMENT1(setadd,pos) (*(setadd) |= BITT[pos])
#define DELELEMENT1(setadd,pos) (*(setadd) &= ~BITT[pos])
#define FLIPELEMENT1(setadd,pos) (*(setadd) ^= BITT[pos])
#define ISELEMENT1(setadd,pos) ((*(setadd) & BITT[pos]) != 0)
#define EMPTYSET1(setadd,m) *(setadd) = 0;
#define GRAPHROW1(g,v,m) ((set*)(g)+(v))
#define ADDONEARC1(g,v,w,m) (g)[v] |= BITT[w]
#define ADDONEEDGE1(g,v,w,m) { ADDONEARC1(g,v,w,m); ADDONEARC1(g,w,v,m); }
#define EMPTYGRAPH1(g,m,n) EMPTYSET0(g,n) /* really EMPTYSET0 */
#define ADDELEMENT0(setadd,pos) ((setadd)[SETWD(pos)] |= BITT[SETBT(pos)])
#define DELELEMENT0(setadd,pos) ((setadd)[SETWD(pos)] &= ~BITT[SETBT(pos)])
#define FLIPELEMENT0(setadd,pos) ((setadd)[SETWD(pos)] ^= BITT[SETBT(pos)])
#define ISELEMENT0(setadd,pos) (((setadd)[SETWD(pos)] & BITT[SETBT(pos)]) != 0)
#define EMPTYSET0(setadd,m) \
{setword *es; \
for (es = (setword*)(setadd)+(m); --es >= (setword*)(setadd);) *es=0;}
#define GRAPHROW0(g,v,m) ((set*)(g) + (m)*(size_t)(v))
#define ADDONEARC0(g,v,w,m) ADDELEMENT0(GRAPHROW0(g,v,m),w)
#define ADDONEEDGE0(g,v,w,m) { ADDONEARC0(g,v,w,m); ADDONEARC0(g,w,v,m); }
#define EMPTYGRAPH0(g,m,n) EMPTYSET0(g,(m)*(size_t)(n))
#if (MAXM==1) && defined(ONE_WORD_SETS)
#define ADDELEMENT ADDELEMENT1
#define DELELEMENT DELELEMENT1
#define FLIPELEMENT FLIPELEMENT1
#define ISELEMENT ISELEMENT1
#define EMPTYSET EMPTYSET1
#define GRAPHROW GRAPHROW1
#define ADDONEARC ADDONEARC1
#define ADDONEEDGE ADDONEEDGE1
#define EMPTYGRAPH EMPTYGRAPH1
#else
#define ADDELEMENT ADDELEMENT0
#define DELELEMENT DELELEMENT0
#define FLIPELEMENT FLIPELEMENT0
#define ISELEMENT ISELEMENT0
#define EMPTYSET EMPTYSET0
#define GRAPHROW GRAPHROW0
#define ADDONEARC ADDONEARC0
#define ADDONEEDGE ADDONEEDGE0
#define EMPTYGRAPH EMPTYGRAPH0
#endif
#ifdef NAUTY_IN_MAGMA
#undef EMPTYSET
#define EMPTYSET(setadd,m) {t_int _i; bsp_makeempty(setadd,m,_i);}
#endif
#define NOTSUBSET(word1,word2) ((word1) & ~(word2)) /* test if the 1-bits
in setword word1 do not form a subset of those in word2 */
#define INTERSECT(word1,word2) ((word1) &= (word2)) /* AND word2 into word1 */
#define UNION(word1,word2) ((word1) |= (word2)) /* OR word2 into word1 */
#define SETDIFF(word1,word2) ((word1) &= ~(word2)) /* - word2 into word1 */
#define XOR(word1,word2) ((word1) ^= (word2)) /* XOR word2 into word1 */
#define ZAPBIT(word,x) ((word) &= ~BITT[x]) /* delete bit x in setword */
#define TAKEBIT(iw,w) {(iw) = FIRSTBITNZ(w); (w) ^= BITT[iw];}
#ifdef SETWORD_LONGLONG
#define MSK3232 0xFFFFFFFF00000000ULL
#define MSK1648 0xFFFF000000000000ULL
#define MSK0856 0xFF00000000000000ULL
#define MSK1632 0x0000FFFF00000000ULL
#define MSK0840 0xFF0000000000ULL
#define MSK1616 0xFFFF0000ULL
#define MSK0824 0xFF000000ULL
#define MSK0808 0xFF00ULL
#define MSK63C 0x7FFFFFFFFFFFFFFFULL
#define MSK31C 0x7FFFFFFFULL
#define MSK15C 0x7FFFULL
#define MSK64 0xFFFFFFFFFFFFFFFFULL
#define MSK32 0xFFFFFFFFULL
#define MSK16 0xFFFFULL
#define MSK8 0xFFULL
#endif
#ifdef SETWORD_LONG
#define MSK3232 0xFFFFFFFF00000000UL
#define MSK1648 0xFFFF000000000000UL
#define MSK0856 0xFF00000000000000UL
#define MSK1632 0x0000FFFF00000000UL
#define MSK0840 0xFF0000000000UL
#define MSK1616 0xFFFF0000UL
#define MSK0824 0xFF000000UL
#define MSK0808 0xFF00UL
#define MSK63C 0x7FFFFFFFFFFFFFFFUL
#define MSK31C 0x7FFFFFFFUL
#define MSK15C 0x7FFFUL
#define MSK64 0xFFFFFFFFFFFFFFFFUL
#define MSK32 0xFFFFFFFFUL
#define MSK16 0xFFFFUL
#define MSK8 0xFFUL
#endif
#if defined(SETWORD_INT) || defined(SETWORD_SHORT)
#define MSK3232 0xFFFFFFFF00000000U
#define MSK1648 0xFFFF000000000000U
#define MSK0856 0xFF00000000000000U
#define MSK1632 0x0000FFFF00000000U
#define MSK0840 0xFF0000000000U
#define MSK1616 0xFFFF0000U
#define MSK0824 0xFF000000U
#define MSK0808 0xFF00U
#define MSK63C 0x7FFFFFFFFFFFFFFFU
#define MSK31C 0x7FFFFFFFU
#define MSK15C 0x7FFFU
#define MSK64 0xFFFFFFFFFFFFFFFFU
#define MSK32 0xFFFFFFFFU
#define MSK16 0xFFFFU
#define MSK8 0xFFU
#endif
#if defined(SETWORD_LONGLONG)
#if WORDSIZE==16
#define SETWORD_FORMAT "%04llx"
#endif
#if WORDSIZE==32
#define SETWORD_FORMAT "%08llx"
#endif
#if WORDSIZE==64
#define SETWORD_FORMAT "%16llx"
#endif
#endif
#if defined(SETWORD_LONG)
#if WORDSIZE==16
#define SETWORD_FORMAT "%04lx"
#endif
#if WORDSIZE==32
#define SETWORD_FORMAT "%08lx"
#endif
#if WORDSIZE==64
#define SETWORD_FORMAT "%16lx"
#endif
#endif
#if defined(SETWORD_INT)
#if WORDSIZE==16
#define SETWORD_FORMAT "%04x"
#endif
#if WORDSIZE==32
#define SETWORD_FORMAT "%08x"
#endif
#if WORDSIZE==64
#define SETWORD_FORMAT "%16x"
#endif
#endif
#if defined(SETWORD_SHORT)
#if WORDSIZE==16
#define SETWORD_FORMAT "%04hx"
#endif
#if WORDSIZE==32
#define SETWORD_FORMAT "%08hx"
#endif
#if WORDSIZE==64
#define SETWORD_FORMAT "%16hx"
#endif
#endif
/* POPCOUNT(x) = number of 1-bits in a setword x
POPCOUNTMAC(x) = Macro version of POPCOUNT
FIRSTBIT(x) = number of first 1-bit in non-zero setword (0..WORDSIZE-1)
or WORDSIZE if x == 0
FIRSTBITNZ(x) = as FIRSTBIT(x) but assumes x is not zero
BITMASK(x) = setword whose rightmost WORDSIZE-x-1 (numbered) bits
are 1 and the rest 0 (0 <= x < WORDSIZE)
(I.e., bits 0..x are unselected and the rest selected.)
ALLBITS = all (numbered) bits in a setword */
#if WORDSIZE==64
#define POPCOUNTMAC(x) (bytecount[(x)>>56 & 0xFF] + bytecount[(x)>>48 & 0xFF] \
+ bytecount[(x)>>40 & 0xFF] + bytecount[(x)>>32 & 0xFF] \
+ bytecount[(x)>>24 & 0xFF] + bytecount[(x)>>16 & 0xFF] \
+ bytecount[(x)>>8 & 0xFF] + bytecount[(x) & 0xFF])
#define FIRSTBIT(x) ((x) & MSK3232 ? \
(x) & MSK1648 ? \
(x) & MSK0856 ? \
0+leftbit[((x)>>56) & MSK8] : \
8+leftbit[(x)>>48] \
: (x) & MSK0840 ? \
16+leftbit[(x)>>40] : \
24+leftbit[(x)>>32] \
: (x) & MSK1616 ? \
(x) & MSK0824 ? \
32+leftbit[(x)>>24] : \
40+leftbit[(x)>>16] \
: (x) & MSK0808 ? \
48+leftbit[(x)>>8] : \
56+leftbit[x])
#define BITMASK(x) (MSK63C >> (x))
#define ALLBITS MSK64
#define SWCHUNK0(w) ((long)((w)>>48)&0xFFFFL)
#define SWCHUNK1(w) ((long)((w)>>32)&0xFFFFL)
#define SWCHUNK2(w) ((long)((w)>>16)&0xFFFFL)
#define SWCHUNK3(w) ((long)(w)&0xFFFFL)
#endif
#if WORDSIZE==32
#define POPCOUNTMAC(x) (bytecount[(x)>>24 & 0xFF] + bytecount[(x)>>16 & 0xFF] \
+ bytecount[(x)>>8 & 0xFF] + bytecount[(x) & 0xFF])
#define FIRSTBIT(x) ((x) & MSK1616 ? ((x) & MSK0824 ? \
leftbit[((x)>>24) & MSK8] : 8+leftbit[(x)>>16]) \
: ((x) & MSK0808 ? 16+leftbit[(x)>>8] : 24+leftbit[x]))
#define BITMASK(x) (MSK31C >> (x))
#define ALLBITS MSK32
#define SWCHUNK0(w) ((long)((w)>>16)&0xFFFFL)
#define SWCHUNK1(w) ((long)(w)&0xFFFFL)
#endif
#if WORDSIZE==16
#define POPCOUNTMAC(x) (bytecount[(x)>>8 & 0xFF] + bytecount[(x) & 0xFF])
#define FIRSTBIT(x) ((x) & MSK0808 ? leftbit[((x)>>8) & MSK8] : 8+leftbit[x])
#define BITMASK(x) (MSK15C >> (x))
#define ALLBITS MSK16
#define SWCHUNK0(w) ((long)(w)&0xFFFFL)
#endif
#if defined(SETWORD_LONGLONG) && HAVE_CLZLL
#undef FIRSTBIT
#undef FIRSTBITNZ
#define FIRSTBITNZ(x) __builtin_clzll(x)
#define FIRSTBIT(x) ((x) ? FIRSTBITNZ(x) : WORDSIZE)
#endif
#if defined(SETWORD_LONG) && HAVE_CLZL
#undef FIRSTBIT
#undef FIRSTBITNZ
#define FIRSTBITNZ(x) __builtin_clzl(x)
#define FIRSTBIT(x) ((x) ? FIRSTBITNZ(x) : WORDSIZE)
#endif
#if defined(SETWORD_INT) && HAVE_CLZ
#undef FIRSTBIT
#undef FIRSTBITNZ
#define FIRSTBITNZ(x) __builtin_clz(x)
#define FIRSTBIT(x) ((x) ? FIRSTBITNZ(x) : WORDSIZE)
#endif
#ifndef FIRSTBITNZ
#define FIRSTBITNZ FIRSTBIT
#endif
/* Use popcount instructions if available */
#define POPCOUNT POPCOUNTMAC
#ifdef __INTEL_COMPILER
#include <nmmintrin.h>
#if WORDSIZE==64 && HAVE_MMPOP64
#undef POPCOUNT
#define POPCOUNT(x) _mm_popcnt_u64(x)
#endif
#if WORDSIZE==32 && HAVE_MMPOP32
#undef POPCOUNT
#define POPCOUNT(x) _mm_popcnt_u32(x)
#endif
#else
/* Note that, unlike icc, gcc will not use the POPCNT instruction without
permission, in which case it defines __POPCNT__ .
*/
#ifdef __POPCNT__
#if defined(SETWORD_LONGLONG) && HAVE_POPCNTLL
#undef POPCOUNT
#define POPCOUNT(x) __builtin_popcountll(x)
#endif
#if defined(SETWORD_LONG) && HAVE_POPCNTL
#undef POPCOUNT
#define POPCOUNT(x) __builtin_popcountl(x)
#endif
#if defined(SETWORD_INT) && HAVE_POPCNT
#undef POPCOUNT
#define POPCOUNT(x) __builtin_popcount(x)
#endif
#endif
#endif
#ifdef NAUTY_IN_MAGMA
#undef POPCOUNT
#undef FIRSTBIT
#undef BITMASK
#define POPCOUNT(x) bs_popcount(x)
#define FIRSTBIT(x) bs_firstbit(x)
#define BITMASK(x) bs_bitmask(x)
#endif
#define ALLMASK(n) ((n)?~BITMASK((n)-1):(setword)0) /* First n bits */
/* various constants: */
#undef FALSE
#undef TRUE
#define FALSE 0
#define TRUE 1
#if SIZEOF_INT>=4
#define NAUTY_INFINITY 2000000002 /* Max graph size is 2 billion */
#else
#define NAUTY_INFINITY 0x7FFF
#endif
/* The following four types are obsolete, use int in new code. */
typedef int shortish;
typedef shortish permutation;
typedef int nvector,np2vector;
/* For backward compatibility: */
#if !HAS_MATH_INF && !defined(INFINITY)
#define INFINITY NAUTY_INFINITY
#endif
#if MAXN > NAUTY_INFINITY-2
#error MAXN must be at most NAUTY_INFINITY-2
#endif
/* typedefs for sets, graphs, permutations, etc.: */
typedef int boolean; /* boolean MUST be the same as int */
#define UPROC void /* obsolete */
typedef setword set,graph;
#ifdef NAUTY_IN_MAGMA
typedef graph nauty_graph;
typedef set nauty_set;
#endif
typedef struct
{
double grpsize1; /* size of group is */
int grpsize2; /* grpsize1 * 10^grpsize2 */
#define groupsize1 grpsize1 /* for backwards compatibility */
#define groupsize2 grpsize2
int numorbits; /* number of orbits in group */
int numgenerators; /* number of generators found */
int errstatus; /* if non-zero : an error code */
#define outofspace errstatus; /* for backwards compatibility */
unsigned long numnodes; /* total number of nodes */
unsigned long numbadleaves; /* number of leaves of no use */
int maxlevel; /* maximum depth of search */
unsigned long tctotal; /* total size of all target cells */
unsigned long canupdates; /* number of updates of best label */
unsigned long invapplics; /* number of applications of invarproc */
unsigned long invsuccesses; /* number of successful uses of invarproc() */
int invarsuclevel; /* least level where invarproc worked */
} statsblk;
/* codes for errstatus field (see nauty.c for more accurate descriptions): */
/* 0 is normal - no error */
#define NTOOBIG 1 /* n > MAXN or n > WORDSIZE*m */
#define MTOOBIG 2 /* m > MAXM */
#define CANONGNIL 3 /* canong = NULL, but getcanon = TRUE */
#define NAUABORTED 4 /* nauty is terminated early under program control */
#define NAUKILLED 5 /* nauty is terminated early by caught signal */
/* manipulation of real approximation to group size */
#define MULTIPLY(s1,s2,i) if ((s1 *= i) >= 1e10) {s1 /= 1e10; s2 += 10;}
struct optionstruct; /* incomplete definition */
typedef struct
{
boolean (*isautom) /* test for automorphism */
(graph*,int*,boolean,int,int);
int (*testcanlab) /* test for better labelling */
(graph*,graph*,int*,int*,int,int);
void (*updatecan) /* update canonical object */
(graph*,graph*,int*,int,int,int);
void (*refine) /* refine partition */
(graph*,int*,int*,int,int*,int*,set*,int*,int,int);
void (*refine1) /* refine partition, MAXM==1 */
(graph*,int*,int*,int,int*,int*,set*,int*,int,int);
boolean (*cheapautom) /* test for easy automorphism */
(int*,int,boolean,int);
int (*targetcell) /* decide which cell to split */
(graph*,int*,int*,int,int,boolean,int,int,int);
void (*freedyn)(void); /* free dynamic memory */
void (*check) /* check compilation parameters */
(int,int,int,int);
void (*init)(graph*,graph**,graph*,graph**,int*,int*,set*,
struct optionstruct*,int*,int,int);
void (*cleanup)(graph*,graph**,graph*,graph**,int*,int*,
struct optionstruct*,statsblk*,int,int);
} dispatchvec;
typedef struct optionstruct
{
int getcanon; /* make canong and canonlab? */
#define LABELONLY 2 /* new value UNIMPLEMENTED */
boolean digraph; /* multiple edges or loops? */
boolean writeautoms; /* write automorphisms? */
boolean writemarkers; /* write stats on pts fixed, etc.? */
boolean defaultptn; /* set lab,ptn,active for single cell? */
boolean cartesian; /* use cartesian rep for writing automs? */
int linelength; /* max chars/line (excl. '\n') for output */
FILE *outfile; /* file for output, if any */
void (*userrefproc) /* replacement for usual refine procedure */
(graph*,int*,int*,int,int*,int*,set*,int*,int,int);
void (*userautomproc) /* procedure called for each automorphism */
(int,int*,int*,int,int,int);
void (*userlevelproc) /* procedure called for each level */
(int*,int*,int,int*,statsblk*,int,int,int,int,int,int);
void (*usernodeproc) /* procedure called for each node */
(graph*,int*,int*,int,int,int,int,int,int);
int (*usercanonproc) /* procedure called for better labellings */
(graph*,int*,graph*,int,int,int,int);
void (*invarproc) /* procedure to compute vertex-invariant */
(graph*,int*,int*,int,int,int,int*,int,boolean,int,int);
int tc_level; /* max level for smart target cell choosing */
int mininvarlevel; /* min level for invariant computation */
int maxinvarlevel; /* max level for invariant computation */
int invararg; /* value passed to (*invarproc)() */
dispatchvec *dispatch; /* vector of object-specific routines */
boolean schreier; /* use random schreier method */
void *extra_options; /* arbitrary extra options */
#ifdef NAUTY_IN_MAGMA
boolean print_stats; /* CAYLEY specfic - GYM Sep 1990 */
char *invarprocname; /* Magma - no longer global sjc 1994 */
int lab_h; /* Magma - no longer global sjc 1994 */
int ptn_h; /* Magma - no longer global sjc 1994 */
int orbitset_h; /* Magma - no longer global sjc 1994 */
#endif
} optionblk;
#ifndef CONSOLWIDTH
#define CONSOLWIDTH 78
#endif
/* The following are obsolete. Just use NULL. */
#define NILFUNCTION ((void(*)())NULL) /* nil pointer to user-function */
#define NILSET ((set*)NULL) /* nil pointer to set */
#define NILGRAPH ((graph*)NULL) /* nil pointer to graph */
#define DEFAULTOPTIONS_GRAPH(options) optionblk options = \
{0,FALSE,FALSE,FALSE,TRUE,FALSE,CONSOLWIDTH, \
NULL,NULL,NULL,NULL,NULL,NULL,NULL,100,0,1,0,&dispatch_graph,FALSE,NULL}
#define DEFAULTOPTIONS_DIGRAPH(options) optionblk options = \
{0,TRUE,FALSE,FALSE,TRUE,FALSE,CONSOLWIDTH, \
NULL,NULL,NULL,NULL,NULL,NULL,adjacencies,100,0,999,0,&dispatch_graph,FALSE,NULL}
#ifndef DEFAULTOPTIONS
#define DEFAULTOPTIONS DEFAULTOPTIONS_GRAPH
#endif
#ifndef DEFAULTOPTIONS_DENSEGRAPH
#define DEFAULTOPTIONS_DENSEGRAPH DEFAULTOPTIONS_GRAPH
#endif
#ifdef NAUTY_IN_MAGMA
#define PUTC(c,f) io_putchar(c)
#else
#ifdef IS_JAVA
extern void javastream(FILE* f,char c);
#define PUTC(c,f) javastream(f,c)
#else
#define PUTC(c,f) putc(c,f)
#endif
#endif
/* We hope that malloc, free, realloc are declared either in <stdlib.h>
or <malloc.h>. Otherwise we will define them. We also assume that
size_t has been defined by the time we get to define malloc(). */
#ifndef NAUTY_IN_MAGMA
#if MALLOC_DEC==2
#include <malloc.h>
#endif
#if MALLOC_DEC==0
extern void *malloc(size_t);
extern void *realloc(void*,size_t);
extern void free(void*);
#endif
#endif
/* ALLOCS(x,y) should return a pointer (any pointer type) to x*y units of new
storage, not necessarily initialised. A "unit" of storage is defined by
the sizeof operator. x and y are integer values of type int or larger,
but x*y may well be too large for an int. The macro should cast to the
correct type for the call. On failure, ALLOCS(x,y) should return a NULL
pointer. FREES(p) should free storage previously allocated by ALLOCS,
where p is the value that ALLOCS returned. */
#ifdef NAUTY_IN_MAGMA
#define ALLOCS(x,y) mem_malloc((size_t)(x)*(size_t)(y))
#define REALLOCS(p,x) mem_realloc(p,(size_t)(x))
#define FREES(p) mem_free(p)
#else
#define ALLOCS(x,y) malloc((size_t)(x)*(size_t)(y))
#define REALLOCS(p,x) realloc(p,(size_t)(x))
#define FREES(p) free(p)
#endif
/* The following macros are used by nauty if MAXN=0. They dynamically
allocate arrays of size dependent on m or n. For each array there
should be two static variables:
type *name;
size_t name_sz;
"name" will hold a pointer to an allocated array. "name_sz" will hold
the size of the allocated array in units of sizeof(type). DYNALLSTAT
declares both variables and initialises name_sz=0. DYNALLOC1 and
DYNALLOC2 test if there is enough space allocated, and if not free
the existing space and allocate a bigger space. The allocated space
is not initialised.
In the case of DYNALLOC1, the space is allocated using
ALLOCS(sz,sizeof(type)).
In the case of DYNALLOC2, the space is allocated using
ALLOCS(sz1,sz2*sizeof(type)).
DYNREALLOC is like DYNALLOC1 except that the old contents are copied
into the new space. Availability of realloc() is assumed.
DYNFREE frees any allocated array and sets name_sz back to 0.
CONDYNFREE does the same, but only if name_sz exceeds some limit.
*/
#define DYNALLSTAT(type,name,name_sz) \
static TLS_ATTR type *name; static TLS_ATTR size_t name_sz=0
#define DYNALLOC1(type,name,name_sz,sz,msg) \
if ((size_t)(sz) > name_sz) \
{ if (name_sz) FREES(name); name_sz = (sz); \
if ((name=(type*)ALLOCS(sz,sizeof(type))) == NULL) {alloc_error(msg);}}
#define DYNALLOC2(type,name,name_sz,sz1,sz2,msg) \
if ((size_t)(sz1)*(size_t)(sz2) > name_sz) \
{ if (name_sz) FREES(name); name_sz = (size_t)(sz1)*(size_t)(sz2); \
if ((name=(type*)ALLOCS((sz1),(sz2)*sizeof(type))) == NULL) \
{alloc_error(msg);}}
#define DYNREALLOC(type,name,name_sz,sz,msg) \
{if ((size_t)(sz) > name_sz) \
{ if ((name = (type*)REALLOCS(name,(sz)*sizeof(type))) == NULL) \
{alloc_error(msg);} else name_sz = (sz);}}
#define DYNFREE(name,name_sz) \
{ if (name) FREES(name); name = NULL; name_sz = 0;}
#define CONDYNFREE(name,name_sz,minsz) \
if (name_sz > (size_t)(minsz)) {DYNFREE(name,name_sz);}
/* File to write error messages to (used as first argument to fprintf()). */
#define ERRFILE stderr
/* Don't use OLDEXTDEFS, it is only still here for Magma. */
#ifdef OLDEXTDEFS
#define EXTDEF_CLASS
#ifdef EXTDEFS
#define EXTDEF_TYPE 1
#else
#define EXTDEF_TYPE 2
#endif
#else
#define EXTDEF_CLASS static
#define EXTDEF_TYPE 2
#endif
extern int labelorg; /* Declared in nautil.c */
extern volatile int nauty_kill_request; /* Also declared in nautil.c */
#ifndef NAUTY_IN_MAGMA
/* Things equivalent to bit, bytecount, leftbit are defined
in bs.h for Magma. */
#if EXTDEF_TYPE==1
extern setword bit[];
extern int bytecount[];
extern int leftbit[];
#else
/* array giving setwords with single 1-bit */
#if WORDSIZE==64
#ifdef SETWORD_LONGLONG
EXTDEF_CLASS const
setword bit[] = {01000000000000000000000LL,0400000000000000000000LL,
0200000000000000000000LL,0100000000000000000000LL,
040000000000000000000LL,020000000000000000000LL,
010000000000000000000LL,04000000000000000000LL,
02000000000000000000LL,01000000000000000000LL,
0400000000000000000LL,0200000000000000000LL,
0100000000000000000LL,040000000000000000LL,
020000000000000000LL,010000000000000000LL,
04000000000000000LL,02000000000000000LL,
01000000000000000LL,0400000000000000LL,0200000000000000LL,
0100000000000000LL,040000000000000LL,020000000000000LL,
010000000000000LL,04000000000000LL,02000000000000LL,
01000000000000LL,0400000000000LL,0200000000000LL,
0100000000000LL,040000000000LL,020000000000LL,010000000000LL,
04000000000LL,02000000000LL,01000000000LL,0400000000LL,
0200000000LL,0100000000LL,040000000LL,020000000LL,
010000000LL,04000000LL,02000000LL,01000000LL,0400000LL,
0200000LL,0100000LL,040000LL,020000LL,010000LL,04000LL,
02000LL,01000LL,0400LL,0200LL,0100LL,040LL,020LL,010LL,
04LL,02LL,01LL};
#else
EXTDEF_CLASS const
setword bit[] = {01000000000000000000000,0400000000000000000000,
0200000000000000000000,0100000000000000000000,
040000000000000000000,020000000000000000000,
010000000000000000000,04000000000000000000,
02000000000000000000,01000000000000000000,
0400000000000000000,0200000000000000000,
0100000000000000000,040000000000000000,020000000000000000,
010000000000000000,04000000000000000,02000000000000000,
01000000000000000,0400000000000000,0200000000000000,
0100000000000000,040000000000000,020000000000000,
010000000000000,04000000000000,02000000000000,
01000000000000,0400000000000,0200000000000,0100000000000,
040000000000,020000000000,010000000000,04000000000,
02000000000,01000000000,0400000000,0200000000,0100000000,
040000000,020000000,010000000,04000000,02000000,01000000,
0400000,0200000,0100000,040000,020000,010000,04000,
02000,01000,0400,0200,0100,040,020,010,04,02,01};
#endif
#endif
#if WORDSIZE==32
EXTDEF_CLASS const
setword bit[] = {020000000000,010000000000,04000000000,02000000000,
01000000000,0400000000,0200000000,0100000000,040000000,
020000000,010000000,04000000,02000000,01000000,0400000,
0200000,0100000,040000,020000,010000,04000,02000,01000,
0400,0200,0100,040,020,010,04,02,01};
#endif
#if WORDSIZE==16
EXTDEF_CLASS const
setword bit[] = {0100000,040000,020000,010000,04000,02000,01000,0400,0200,
0100,040,020,010,04,02,01};
#endif
/* array giving number of 1-bits in bytes valued 0..255: */
EXTDEF_CLASS const
int bytecount[] = {0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4,
1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,
1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,
2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,
2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,
2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
4,5,5,6,5,6,6,7,5,6,6,7,6,7,7,8};
/* array giving position (1..7) of high-order 1-bit in byte: */
EXTDEF_CLASS const
int leftbit[] = {8,7,6,6,5,5,5,5,4,4,4,4,4,4,4,4,
3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
#endif /* EXTDEFS */
#endif /* not NAUTY_IN_MAGMA */
#define ANSIPROT 1
#define EXTPROC(func,args) extern func args; /* obsolete */
/* The following is for C++ programs that read nauty.h. Compile nauty
itself using C, not C++. */
#ifdef __cplusplus
extern "C" {
#endif
extern void alloc_error(const char*);
extern void breakout(int*,int*,int,int,int,set*,int);
extern boolean cheapautom(int*,int,boolean,int);
extern void doref(graph*,int*,int*,int,int*,int*,int*,set*,int*,
void(*)(graph*,int*,int*,int,int*,int*,set*,int*,int,int),
void(*)(graph*,int*,int*,int,int,int,int*,int,boolean,int,int),
int,int,int,boolean,int,int);
extern void extra_autom(int*,int);
extern void extra_level(int,int*,int*,int,int,int,int,int,int);
extern boolean isautom(graph*,int*,boolean,int,int);
extern dispatchvec dispatch_graph;
extern int itos(int,char*);
extern void fmperm(int*,set*,set*,int,int);
extern void fmptn(int*,int*,int,set*,set*,int,int);
extern void longprune(set*,set*,set*,set*,int);
extern void nauty(graph*,int*,int*,set*,int*,optionblk*,
statsblk*,set*,int,int,int,graph*);
extern void maketargetcell(graph*,int*,int*,int,set*,int*,int*,int,boolean,
int,int (*)(graph*,int*,int*,int,int,boolean,int,int,int),int,int);
extern int nextelement(set*,int,int);
extern int orbjoin(int*,int*,int);
extern void permset(set*,set*,int,int*);
extern void putstring(FILE*,char*);
extern void refine(graph*,int*,int*,int,int*,int*,set*,int*,int,int);
extern void refine1(graph*,int*,int*,int,int*,int*,set*,int*,int,int);
extern void shortprune(set*,set*,int);
extern int targetcell(graph*,int*,int*,int,int,boolean,int,int,int);
extern int testcanlab(graph*,graph*,int*,int*,int,int);
extern void updatecan(graph*,graph*,int*,int,int,int);
extern void writeperm(FILE*,int*,boolean,int,int);
extern void nauty_freedyn(void);
extern void nauty_check(int,int,int,int);
extern void naugraph_check(int,int,int,int);
extern void nautil_check(int,int,int,int);
extern void nautil_freedyn(void);
extern void naugraph_freedyn(void);
extern void densenauty(graph*,int*,int*,int*,
optionblk*,statsblk*,int,int,graph*);
extern void writegroupsize(FILE*,double,int);
#ifdef __cplusplus
}
#endif
/* ++++++ This file is automatically generated, don't edit it by hand! ++++++ */
#endif /* _NAUTY_H_ */
|
33db7b8a09e458d867889dedec350d9e2f2914f6
|
79d343002bb63a44f8ab0dbac0c9f4ec54078c3a
|
/lib/libc/include/any-windows-any/d3d10_1shader.h
|
a9aa135fe04a32760c9da8b74f6a60d83a201099
|
[
"MIT",
"LicenseRef-scancode-warranty-disclaimer",
"LicenseRef-scancode-public-domain"
] |
permissive
|
ziglang/zig
|
4aa75d8d3bcc9e39bf61d265fd84b7f005623fc5
|
f4c9e19bc3213c2bc7e03d7b06d7129882f39f6c
|
refs/heads/master
| 2023-08-31T13:16:45.980913
| 2023-08-31T05:50:29
| 2023-08-31T05:50:29
| 40,276,274
| 25,560
| 2,399
|
MIT
| 2023-09-14T21:09:50
| 2015-08-06T00:51:28
|
Zig
|
UTF-8
|
C
| false
| false
| 2,623
|
h
|
d3d10_1shader.h
|
#undef INTERFACE
/*
* Copyright 2010 Rico Schüller
*
* 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
*/
#ifndef __D3D10_1SHADER_H__
#define __D3D10_1SHADER_H__
#include "d3d10shader.h"
DEFINE_GUID(IID_ID3D10ShaderReflection1, 0xc3457783, 0xa846, 0x47ce, 0x95, 0x20, 0xce, 0xa6, 0xf6, 0x6e, 0x74, 0x47);
#define INTERFACE ID3D10ShaderReflection1
DECLARE_INTERFACE_(ID3D10ShaderReflection1, IUnknown)
{
/* IUnknown methods */
STDMETHOD(QueryInterface)(THIS_ REFIID riid, void **out) PURE;
STDMETHOD_(ULONG, AddRef)(THIS) PURE;
STDMETHOD_(ULONG, Release)(THIS) PURE;
/* ID3D10ShaderReflection1 methods */
STDMETHOD(GetDesc)(THIS_ D3D10_SHADER_DESC *desc) PURE;
STDMETHOD_(struct ID3D10ShaderReflectionConstantBuffer *, GetConstantBufferByIndex)(THIS_ UINT index) PURE;
STDMETHOD_(struct ID3D10ShaderReflectionConstantBuffer *, GetConstantBufferByName)(THIS_ const char *name) PURE;
STDMETHOD(GetResourceBindingDesc)(THIS_ UINT index, D3D10_SHADER_INPUT_BIND_DESC *desc) PURE;
STDMETHOD(GetInputParameterDesc)(THIS_ UINT index, D3D10_SIGNATURE_PARAMETER_DESC *desc) PURE;
STDMETHOD(GetOutputParameterDesc)(THIS_ UINT index, D3D10_SIGNATURE_PARAMETER_DESC *desc) PURE;
STDMETHOD_(struct ID3D10ShaderReflectionVariable *, GetVariableByName)(THIS_ const char *name) PURE;
STDMETHOD(GetResourceBindingDescByName)(THIS_ const char *name, D3D10_SHADER_INPUT_BIND_DESC *desc) PURE;
STDMETHOD(GetMovInstructionCount)(THIS_ UINT *count) PURE;
STDMETHOD(GetMovcInstructionCount)(THIS_ UINT *count) PURE;
STDMETHOD(GetConversionInstructionCount)(THIS_ UINT *count) PURE;
STDMETHOD(GetBitwiseInstructionCount)(THIS_ UINT *count) PURE;
STDMETHOD(GetGSInputPrimitive)(THIS_ D3D10_PRIMITIVE *prim) PURE;
STDMETHOD(IsLevel9Shader)(THIS_ WINBOOL *level9shader) PURE;
STDMETHOD(IsSampleFrequencyShader)(THIS_ WINBOOL *samplefrequency) PURE;
};
#undef INTERFACE
#endif
|
80ba1c9913f431f482be8635de591f859cf17d09
|
e73547787354afd9b717ea57fe8dd0695d161821
|
/include/mapfs/iwa_00_shape.h
|
77e69f6a3a745be0bd0d115930f4e081dbf2da21
|
[] |
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
| 1,544
|
h
|
iwa_00_shape.h
|
#define MODEL_Root 0x28
#define MODEL_suberi 0x27
#define MODEL_suberi01 0x26
#define MODEL_kabe 0x25
#define MODEL_o969 0x24
#define MODEL_o837 0x23
#define MODEL_o957 0x22
#define MODEL_o992 0x21
#define MODEL_o993 0x20
#define MODEL_sen1 0x1F
#define MODEL_se1 0x1E
#define MODEL_hashi 0x1D
#define MODEL_o1061 0x1C
#define MODEL_o976 0x1B
#define MODEL_kusa 0x1A
#define MODEL_o950 0x19
#define MODEL_toi 0x18
#define MODEL_o949 0x17
#define MODEL_water 0x16
#define MODEL_o933 0x15
#define MODEL_o926 0x14
#define MODEL_ishi 0x13
#define MODEL_o1018 0x12
#define MODEL_o1019 0x11
#define MODEL_bero 0x10
#define MODEL_o911 0xF
#define MODEL_s_ishi 0xE
#define MODEL_o1056 0xD
#define MODEL_o896 0xC
#define MODEL_o895 0xB
#define MODEL_o893 0xA
#define MODEL_g326 0x9
#define MODEL_o965 0x8
#define MODEL_o1069 0x7
#define MODEL_o1068 0x6
#define MODEL_o1067 0x5
#define MODEL_o1065 0x4
#define MODEL_jimen 0x3
#define MODEL_o882 0x2
#define MODEL_o838 0x1
#define MODEL_o1066 0x0
|
0deebb84bfa505ea2edfa00965ceb4116e0c43c4
|
ce32e0e1b9568c710a3168abc3c638d6f9f6c31b
|
/vnpy/api/uft/include/uft/HSDataType.h
|
285e4b7ccdceaf92c4c63a63c5860e8d29260cb1
|
[
"MIT"
] |
permissive
|
msincenselee/vnpy
|
55ae76ca32cae47369a66bd2d6589c13d7a0bdd4
|
7f4fd3cd202712b083ed7dc2f346ba4bb1bda6d7
|
refs/heads/vnpy2
| 2022-05-19T10:06:55.504408
| 2022-03-19T15:26:01
| 2022-03-19T15:26:01
| 38,525,806
| 359
| 158
|
MIT
| 2020-09-09T00:09:12
| 2015-07-04T07:27:46
|
C++
|
GB18030
|
C
| false
| false
| 26,658
|
h
|
HSDataType.h
|
/**
* @author 寿贺飞
* @company 恒生电子股份有限公司
* @file HSDateType.h
* @brief 定义了接口使用的业务数据类型
* @date 20170927
*/
#ifndef HS_DATATYPE_H
#define HS_DATATYPE_H
#define API_VERSIONSTRING "V3.7.1.16"
//////////////////////////////////////////////////////////////////////////
/// HSInstrumentID:合约编码
//////////////////////////////////////////////////////////////////////////
typedef char HSInstrumentID[32];
//////////////////////////////////////////////////////////////////////////
/// HSOptionsType:期权类型
//////////////////////////////////////////////////////////////////////////
/// 看涨(认购)
#define HS_OT_CallOptions 'C'
/// 看跌(认沽)
#define HS_OT_PutOptions 'P'
typedef char HSOptionsType;
//////////////////////////////////////////////////////////////////////////
/// HSExchangeID:交易所代码
//////////////////////////////////////////////////////////////////////////
/// 上海证券交易所
#define HS_EI_SSE "1"
/// 深圳证券交易所
#define HS_EI_SZSE "2"
/// 郑州商品交易所
#define HS_EI_CZCE "F1"
/// 大连商品交易所
#define HS_EI_DCE "F2"
/// 上海期货交易所
#define HS_EI_SHFE "F3"
/// 中国金融期货交易所
#define HS_EI_CFFEX "F4"
/// 上海国际能源交易中心股份有限公司
#define HS_EI_INE "F5"
typedef char HSExchangeID[4];
//////////////////////////////////////////////////////////////////////////
/// HSInstrumentName:合约名字
//////////////////////////////////////////////////////////////////////////
typedef char HSInstrumentName[32];
//////////////////////////////////////////////////////////////////////////
/// HSVolume:数量
//////////////////////////////////////////////////////////////////////////
typedef double HSVolume;
//////////////////////////////////////////////////////////////////////////
/// HSArbitPositionID:套利持仓号
//////////////////////////////////////////////////////////////////////////
typedef char HSArbitPositionID[32];
//////////////////////////////////////////////////////////////////////////
/// HSLegID:腿号
//////////////////////////////////////////////////////////////////////////
typedef double HSLegID;
//////////////////////////////////////////////////////////////////////////
/// HSConfigNo:配置编号
//////////////////////////////////////////////////////////////////////////
typedef double HSConfigNo;
//////////////////////////////////////////////////////////////////////////
/// HSConfigValue:配置开关状态
/// 根据不同的配置编号,有不同的字典项
//////////////////////////////////////////////////////////////////////////
typedef char HSConfigValue[128];
//////////////////////////////////////////////////////////////////////////
/// HSExerciseType:期权行权类型
//////////////////////////////////////////////////////////////////////////
/// 放弃
#define HS_ET_Abandon '0'
/// 执行
#define HS_ET_Exec '1'
typedef char HSExerciseType;
//////////////////////////////////////////////////////////////////////////
/// HSPrice:价格
//////////////////////////////////////////////////////////////////////////
typedef double HSPrice;
//////////////////////////////////////////////////////////////////////////
/// HSBalance:金额
//////////////////////////////////////////////////////////////////////////
typedef double HSBalance;
//////////////////////////////////////////////////////////////////////////
/// HSDate:日期 格式YYYYMMDD
//////////////////////////////////////////////////////////////////////////
typedef int HSDate;
//////////////////////////////////////////////////////////////////////////
/// HSMsgContent:消息正文
//////////////////////////////////////////////////////////////////////////
typedef char HSMsgContent[256];
//////////////////////////////////////////////////////////////////////////
/// HSCombStrategyID:组合策略编码
//////////////////////////////////////////////////////////////////////////
/// 认购牛市价差
#define HS_CSI_CNSJC "CNSJC"
/// 认沽熊市价差
#define HS_CSI_PXSJC "PXSJC"
/// 认沽牛市价差
#define HS_CSI_PNSJC "PNSJC"
/// 认购熊市价差
#define HS_CSI_CXSJC "CXSJC"
/// 跨式空头
#define HS_CSI_KS "KS"
/// 宽跨式空头
#define HS_CSI_KKS "KKS"
/// 普通转备兑
#define HS_CSI_ZBD "ZBD"
/// 备兑转普通
#define HS_CSI_ZXJ "ZXJ"
typedef char HSCombStrategyID[8];
/////////////////////////////////////////////////////////////////////////
/// HSRemarks:备注
/////////////////////////////////////////////////////////////////////////
typedef char HSRemarks[256];
/////////////////////////////////////////////////////////////////////////
/// HSDirection:买卖方向类型
/////////////////////////////////////////////////////////////////////////
/// 买
#define HS_D_Buy '1'
/// 卖
#define HS_D_Sell '2'
typedef char HSDirection;
/////////////////////////////////////////////////////////////////////////
/// HSOffsetFlag:开平标志类型
/////////////////////////////////////////////////////////////////////////
/// 开仓
#define HS_OF_Open '1'
/// 平仓
#define HS_OF_Close '2'
/// 交割
#define HS_OF_Delivery '3'
/// 平今仓
#define HS_OF_CloseToday '4'
typedef char HSOffsetFlag;
/////////////////////////////////////////////////////////////////////////
/// HSCombDirection:组合指令方向类型
/////////////////////////////////////////////////////////////////////////
/// 组合
#define HS_CD_Comb '1'
/// 拆分
#define HS_CD_UnComb '2'
typedef char HSCombDirection;
//////////////////////////////////////////////////////////////////////////
/// HSRef:引用
//////////////////////////////////////////////////////////////////////////
typedef char HSRef[32];
//////////////////////////////////////////////////////////////////////////
/// HSTime:时间 格式HHMMSSFFF
//////////////////////////////////////////////////////////////////////////
typedef int HSTime;
/////////////////////////////////////////////////////////////////////////
/// HSPositionType:持仓类型类型
/// 权利方
#define HS_PT_Right '0'
/// 义务方
#define HS_PT_Voluntary '1'
/// 备兑方
#define HS_PT_Covered '2'
typedef char HSPositionType;
/////////////////////////////////////////////////////////////////////////
/// HSLockType:锁定方向类型
/////////////////////////////////////////////////////////////////////////
/// 锁定
#define HS_LT_Lock '1'
/// 解锁
#define HS_LT_Unlock '2'
typedef char HSLockType;
/////////////////////////////////////////////////////////////////////////
/// HSOrderStatus:报单状态类型
/////////////////////////////////////////////////////////////////////////
/// 未报
#define HS_OS_NotReported '0'
/// 待报
#define HS_OS_ToBeReported '1'
/// 已报
#define HS_OS_Reported '2'
/// 已报待撤
#define HS_OS_ReportedToBeCancel '3'
/// 部成待撤
#define HS_OS_PartsTradedToBeCancel '4'
/// 部撤
#define HS_OS_CanceledWithPartsTraded '5'
/// 已撤
#define HS_OS_Canceled '6'
/// 部成
#define HS_OS_PartsTraded '7'
/// 已成
#define HS_OS_Traded '8'
/// 废单
#define HS_OS_Abandoned '9'
/// 撤废
#define HS_OS_CancelFailed 'D'
/// 已确认(询价请求)
#define HS_OS_Confirmed 'V'
/// 待确认
#define HS_OS_ToBeConfirmed 'W'
typedef char HSOrderStatus;
//////////////////////////////////////////////////////////////////////////
/// HSErrorID:错误编码
//////////////////////////////////////////////////////////////////////////
typedef int HSErrorID;
//////////////////////////////////////////////////////////////////////////
/// HSErrorMsg:错误信息
//////////////////////////////////////////////////////////////////////////
typedef char HSErrorMsg[256];
/////////////////////////////////////////////////////////////////////////
/// HSOrderSource:报单发起方类型
/////////////////////////////////////////////////////////////////////////
/// 个人投资者发起
#define HS_OSRC_Personal '0'
/// 交易所发起
#define HS_OSRC_Exchange '1'
/// 会员发起
#define HS_OSRC_Member '2'
/// 机构投资者发起
#define HS_OSRC_Organization '3'
/// 自营交易发起
#define HS_OSRC_Proprietary '4'
/// 流动性服务提供商发起
#define HS_OSRC_MobileServiceProvider '5'
typedef char HSOrderSource;
//////////////////////////////////////////////////////////////////////////
/// HSTradeID:成交编码
//////////////////////////////////////////////////////////////////////////
typedef char HSTradeID[32];
//////////////////////////////////////////////////////////////////////////
/// HSRiskDegree:风险度
//////////////////////////////////////////////////////////////////////////
typedef double HSRiskDegree;
//////////////////////////////////////////////////////////////////////////
/// HSBankID:银行编码
//////////////////////////////////////////////////////////////////////////
typedef char HSBankID[8];
//////////////////////////////////////////////////////////////////////////
/// HSTransferType:转账类型
//////////////////////////////////////////////////////////////////////////
/// 银行转经纪公司
#define HS_TT_BankToBroker '1'
/// 经纪公司转银行
#define HS_TT_BrokerToBank '2'
typedef char HSTransferType;
//////////////////////////////////////////////////////////////////////////
/// HSBankName:银行名字
//////////////////////////////////////////////////////////////////////////
typedef char HSBankName[64];
//////////////////////////////////////////////////////////////////////////
/// HSTransferSource:转账发起方
//////////////////////////////////////////////////////////////////////////
/// 经纪公司
#define HS_TSRC_Broker '0'
/// 银行
#define HS_TSRC_Bank '1'
/// 互相
#define HS_TSRC_Each '2'
/// 第三方
#define HS_TSRC_Third '3'
typedef char HSTransferSource;
//////////////////////////////////////////////////////////////////////////
/// HSTransferStatus:转账状态
//////////////////////////////////////////////////////////////////////////
/// 未报
#define HS_TS_NotReported '0'
/// 已报
#define HS_TS_Reported '1'
/// 成功
#define HS_TS_Success '2'
/// 作废
#define HS_TS_Abandoned '3'
/// 待撤
#define HS_TS_ReportedToBeCancel '4'
/// 撤销
#define HS_TS_Canceled '5'
/// 待冲正
#define HS_TS_PendingReversal '7'
///已冲正
#define HS_TS_Reversal '8'
/// 待报
#define HS_TS_ToBeReported 'A'
/// 正报
#define HS_TS_Reporting 'P'
/// 已确认
#define HS_TS_Confirmed 'Q'
/// 待确定
#define HS_TS_PendingConfirm 'x'
typedef char HSTransferStatus;
//////////////////////////////////////////////////////////////////////////
/// HSBankErrorMsg:银行错误信息
//////////////////////////////////////////////////////////////////////////
typedef char HSBankErrorMsg[256];
//////////////////////////////////////////////////////////////////////////
/// HSBankAccountID:银行账号编码
//////////////////////////////////////////////////////////////////////////
typedef char HSBankAccountID[32];
//////////////////////////////////////////////////////////////////////////
/// HSAccountID:账号
//////////////////////////////////////////////////////////////////////////
typedef char HSAccountID[18];
//////////////////////////////////////////////////////////////////////////
/// HSBillContent:账单内容
//////////////////////////////////////////////////////////////////////////
typedef char HSBillContent[256];
//////////////////////////////////////////////////////////////////////////
/// HSHedgeType:投机/套保/备兑类型
//////////////////////////////////////////////////////////////////////////
/// 投机
#define HS_HT_Speculation '0'
/// 套保
#define HS_HT_Hedge '1'
/// 套利
#define HS_HT_Arbitrage '2'
/// 做市商
#define HS_HT_MarketMaker '3'
/// 备兑
#define HS_HT_Covered '4'
typedef char HSHedgeType;
//////////////////////////////////////////////////////////////////////////
/// HSRate:费率
//////////////////////////////////////////////////////////////////////////
typedef double HSRate;
//////////////////////////////////////////////////////////////////////////
/// HSSessionID:会话编码
//////////////////////////////////////////////////////////////////////////
typedef int HSSessionID;
//////////////////////////////////////////////////////////////////////////
/// HSUserStationInfo:用户站点信息
//////////////////////////////////////////////////////////////////////////
typedef char HSUserStationInfo[64];
//////////////////////////////////////////////////////////////////////////
/// HSOrderSysID:报单编号
//////////////////////////////////////////////////////////////////////////
typedef char HSOrderSysID[32];
//////////////////////////////////////////////////////////////////////////
/// HSCombPositionID:组合持仓编码
//////////////////////////////////////////////////////////////////////////
typedef char HSCombPositionID[32];
//////////////////////////////////////////////////////////////////////////
/// HSPassword:密码
//////////////////////////////////////////////////////////////////////////
typedef char HSPassword[16];
//////////////////////////////////////////////////////////////////////////
/// HSPositionStr:定位串
//////////////////////////////////////////////////////////////////////////
typedef char HSPositionStr[100];
//////////////////////////////////////////////////////////////////////////
/// HSMacAddress:Mac地址
//////////////////////////////////////////////////////////////////////////
typedef char HSMacAddress[32];
//////////////////////////////////////////////////////////////////////////
/// HSIPAddress:IP地址
//////////////////////////////////////////////////////////////////////////
typedef char HSIPAddress[64];
//////////////////////////////////////////////////////////////////////////
/// HSSystemNodeID:系统节点编码
//////////////////////////////////////////////////////////////////////////
typedef char HSSystemNodeID[32];
//////////////////////////////////////////////////////////////////////////
/// HSBillConfirmFlag:是否需要确认帐单的标志
//////////////////////////////////////////////////////////////////////////
/// 不需要确认
#define HS_BCF_NO '0'
/// 需要确认
#define HS_BCF_YES '1'
typedef char HSBillConfirmFlag;
//////////////////////////////////////////////////////////////////////////
/// HSBillConfirmStatus:账单确认状态
//////////////////////////////////////////////////////////////////////////
/// 未确认
#define HS_BCFD_NO '0'
/// 已确认
#define HS_BCFD_YES '1'
typedef char HSBillConfirmStatus;
//////////////////////////////////////////////////////////////////////////
/// HSDelta:虚实度
//////////////////////////////////////////////////////////////////////////
typedef double HSDelta;
//////////////////////////////////////////////////////////////////////////
/// HSInstrumentTradeStatus:合约交易状态
//////////////////////////////////////////////////////////////////////////
/// 启动(开始前)
#define HS_IT_Init 'S'
/// 集合竞价
#define HS_IT_CallAuction 'C'
/// 连续交易
#define HS_IT_Trinding 'T'
/// 休市
#define HS_IT_Pause 'B'
/// 闭市
#define HS_IT_Close 'E'
/// 收盘集合竞价
#define HS_IT_ClosingCallAuction 'U'
/// 波动性中断
#define HS_IT_Fusing 'V'
/// 临时停牌
#define HS_IT_Halt 'P'
/// 全天停牌
#define HS_IT_HaltAllDay '1'
/// 熔断(盘中集合竞价)
#define HS_IT_FuseToCallAuction 'M'
/// 熔断(暂停交易至闭市)
#define HS_IT_FuseToClose 'N'
typedef char HSInstrumentTradeStatus;
//////////////////////////////////////////////////////////////////////////
/// HSOpenRestriction:合约实时开仓限制
//////////////////////////////////////////////////////////////////////////
/// 限制买入开仓
#define HS_OR_LimitBidOpen '0'
/// 限制卖出开仓
#define HS_OR_LimitSellOpen '1'
/// 限制备兑开仓
#define HS_OR_LimitCoveredOpen '2'
typedef char HSOpenRestriction[64];
//////////////////////////////////////////////////////////////////////////
/// HSProductID:合约品种类别
//////////////////////////////////////////////////////////////////////////
typedef char HSProductID[4];
//////////////////////////////////////////////////////////////////////////
/// HSMaxMarginSideAlgorithm:大额单边保证金算法类型
//////////////////////////////////////////////////////////////////////////
/// 不使用大额单边保证金算法
#define HS_MMSA_NO '0'
/// 使用大额单边保证金算法
#define HS_MMSA_YES '1'
typedef char HSMaxMarginSideAlgorithm;
//////////////////////////////////////////////////////////////////////////
/// HSMaxMarginSideProductID:大额单边保证金优惠品种
//////////////////////////////////////////////////////////////////////////
typedef char HSMaxMarginSideProductID[256];
//////////////////////////////////////////////////////////////////////////
/// HSUserName:客户姓名
//////////////////////////////////////////////////////////////////////////
typedef char HSUserName[32];
//////////////////////////////////////////////////////////////////////////
/// HSForceCloseReason:强平原因
//////////////////////////////////////////////////////////////////////////
/// 非强平
#define HS_FCR_NotForceClose '0'
/// 资金不足
#define HS_FCR_LackDeposit '1'
/// 客户超仓
#define HS_FCR_ClientOverPositionLimit '2'
///会员超仓
#define HS_FCR_MemberOverPositionLimit '3'
/// 持仓非整数倍
#define HS_FCR_NotMultiple '4'
/// 违规
#define HS_FCR_Violation '5'
/// 其它
#define HS_FCR_Other '6'
typedef char HSForceCloseReason;
//////////////////////////////////////////////////////////////////////////
/// HSTradingFlag:申报标志
//////////////////////////////////////////////////////////////////////////
/// 禁止申报
#define HS_TF_No '0'
/// 可以申报
#define HS_TF_Yes '1'
typedef char HSTradingFlag;
//////////////////////////////////////////////////////////////////////////
/// HSSwapOrderFlag:互换标志
//////////////////////////////////////////////////////////////////////////
///非互换
#define HS_SOF_Normal '0'
/// 互换
#define HS_SOF_Swap '1'
typedef char HSSwapOrderFlag;
//////////////////////////////////////////////////////////////////////////
/// HSPasswordType:密码类型
//////////////////////////////////////////////////////////////////////////
/// 资金密码
#define HS_PWDT_Fund '1'
/// 交易密码
#define HS_PWDT_Trade '2'
typedef char HSPasswordType;
//////////////////////////////////////////////////////////////////////////
/// HSOrderCommand:报单指令
//////////////////////////////////////////////////////////////////////////
/// 限价
#define HS_CT_Limit "L"
/// 限价即时全部成交否则撤销
#define HS_CT_LimitFOK "LFOK"
/// 限价任意数量即时成交剩余撤销
#define HS_CT_LimitFAK "LFAK"
/// 限价止损
#define HS_CT_LimitStopLoss "LLOS"
/// 限价止盈
#define HS_CT_LimitStopProfit "LPFT"
/// 市价
#define HS_CT_Market "M"
/// 市价即时全部成交否则撤销
#define HS_CT_MarketFOK "MFOK"
/// 市价任意数量即时成交剩余撤销
#define HS_CT_MarketFAK "MFAK"
/// 市价指定成交数量即时成交剩余撤销
#define HS_CT_MarketFAKV "MFAKV"
/// 市价止损
#define HS_CT_MarketStopLoss "MLOS"
/// 市价止盈
#define HS_CT_MarketStopProfit "MPFT"
/// 市价即时成交剩余转限价
#define HS_CT_MarketToLimit "MTL"
/// 五档市价即时成交剩余撤销
#define HS_CT_Market5FAK "M5FAK"
/// 五档市价即时成交剩余转限价
#define HS_CT_Market5ToLimit "M5TL"
/// 最优价即时成交剩余转限价
#define HS_CT_Market1ToLimit "M1TL"
/// 最优价即时成交剩余撤销
#define HS_CT_Market1FAK "M1FAK"
/// 最优价即时全部成交否则撤销
#define HS_CT_Market1FOK "M1FOK"
/// 本方最优价转限价
#define HS_CT_MarketSelfToLimit "MSTL"
typedef char HSOrderCommand[8];
//////////////////////////////////////////////////////////////////////////
/// HSNum:数字
//////////////////////////////////////////////////////////////////////////
typedef int HSNum;
//////////////////////////////////////////////////////////////////////////
/// HSBrokerOrderID:经纪公司报单编码
//////////////////////////////////////////////////////////////////////////
typedef char HSBrokerOrderID[32];
//////////////////////////////////////////////////////////////////////////
/// HSBusinessName:业务名称
//////////////////////////////////////////////////////////////////////////
typedef char HSBusinessName[64];
//////////////////////////////////////////////////////////////////////////
/// HSUserApplicationType:投资者端应用类别
//////////////////////////////////////////////////////////////////////////
typedef char HSUserApplicationType;
//////////////////////////////////////////////////////////////////////////
/// HSUserApplicationInfo:投资者端应用信息
//////////////////////////////////////////////////////////////////////////
typedef char HSUserApplicationInfo[32];
//////////////////////////////////////////////////////////////////////////
/// HSInstrumentEngName:合约英文名称
//////////////////////////////////////////////////////////////////////////
typedef char HSInstrumentEngName[32];
//////////////////////////////////////////////////////////////////////////
/// HSProductType:产品类型
//////////////////////////////////////////////////////////////////////////
/// 期货
#define HS_PTYPE_Futures '1'
/// 期货期权
#define HS_PTYPE_OptFutu '2'
/// 组合
#define HS_PTYPE_Combination '3'
/// 即期
#define HS_PTYPE_Spot '4'
/// 期转现
#define HS_PTYPE_FutuToSpot '5'
/// 证券
#define HS_PTYPE_Securities '6'
/// 股票期权
#define HS_PTYPE_OptStock '7'
typedef char HSProductType;
//////////////////////////////////////////////////////////////////////////
/// HSCurrencyID:币种
//////////////////////////////////////////////////////////////////////////
/// 人民币
#define HS_CID_CNY '0'
/// 美元
#define HS_CID_USD '1'
/// 港币
#define HS_CID_HKD '2'
typedef char HSCurrencyID;
//////////////////////////////////////////////////////////////////////////
/// HSCloseFlag:期权行权后生成的头寸是否自动平仓标志
//////////////////////////////////////////////////////////////////////////
/// 不自动平仓
#define HS_CF_NO '0'
/// 自动平仓
#define HS_CF_YES '1'
typedef char HSCloseFlag;
//////////////////////////////////////////////////////////////////////////
/// HSCombType:组合类型
//////////////////////////////////////////////////////////////////////////
/// 普通
#define HS_COMBT_PT '0'
/// 跨期
#define HS_COMBT_KQ '1'
/// 跨品种
#define HS_COMBT_KPZ '2'
typedef char HSCombType;
//////////////////////////////////////////////////////////////////////////
/// HSRiskLevel:风险等级
//////////////////////////////////////////////////////////////////////////
/// 默认型
#define HS_RL_Default '0'
/// 保守型
#define HS_RL_Keep '1'
/// 谨慎型
#define HS_RL_Cautions '2'
/// 稳健型
#define HS_RL_Steady '3'
/// 积极型
#define HS_RL_Active '4'
/// 成长型
#define HS_RL_Growth '6'
/// 专业投资者
#define HS_RL_Profession '99'
/// 自定义风险等级
#define HS_RL_Diy '100'
typedef char HSRiskLevel[4];
//////////////////////////////////////////////////////////////////////////
/// HSAppID:密码
//////////////////////////////////////////////////////////////////////////
typedef char HSAppID[32];
//////////////////////////////////////////////////////////////////////////
/// HSAuthCode:认证码
//////////////////////////////////////////////////////////////////////////
typedef char HSAuthCode[128];
//////////////////////////////////////////////////////////////////////////
/// HSTradeType:成交类型
//////////////////////////////////////////////////////////////////////////
///普通成交、套利组合拆仓
#define HS_TT_Common '0'
///期权执行
#define HS_TT_OptionsExecution '1'
///OTC成交
#define HS_TT_OTC '2'
///期转现衍生成交
#define HS_TT_EFPDerived '3'
///组合衍生成交
#define HS_TT_CombinationDerived '4'
typedef char HSTradeType;
//////////////////////////////////////////////////////////////////////////
/// HSExchangeRate:汇率
//////////////////////////////////////////////////////////////////////////
typedef double HSExchangeRate;
//////////////////////////////////////////////////////////////////////////
/// HSOccasion:场景
//////////////////////////////////////////////////////////////////////////
typedef char HSOccasion[32];
//////////////////////////////////////////////////////////////////////////
/// 回报订阅模式
//////////////////////////////////////////////////////////////////////////
///从本交易日开始重传
#define HS_TERT_RESTART "0"
///从上次收到的续传
#define HS_TERT_RESUME "1"
///从登录后最新的开始传
#define HS_TERT_QUICK "2"
#endif
|
c252c7215419e77b428f3b9c739d42bbc350fd62
|
f9730fecd72f2d7b0cb87b2cd6dfca6ea3176d0b
|
/src/object-hierarchy.h
|
6eab63a7ba5483613e715f8f52a4fb7ae52c7357
|
[
"MIT"
] |
permissive
|
chipx86/gtkparasite
|
ecec9143903a7429e58bad422be054577f662290
|
745f89adfa550cca025fc2d4558e9ac3b0e6187c
|
refs/heads/master
| 2022-06-01T07:12:49.375372
| 2020-02-13T11:57:52
| 2020-02-13T11:57:52
| 37,561
| 160
| 27
| null | 2014-03-13T17:07:27
| 2008-07-27T03:37:32
|
C
|
UTF-8
|
C
| false
| false
| 2,656
|
h
|
object-hierarchy.h
|
/*
* Copyright (c) 2013 Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef _GTKPARASITE_OBJECTHIERARCHY_H_
#define _GTKPARASITE_OBJECTHIERARCHY_H_
#include <gtk/gtk.h>
#define PARASITE_TYPE_OBJECTHIERARCHY (parasite_objecthierarchy_get_type())
#define PARASITE_OBJECTHIERARCHY(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), PARASITE_TYPE_OBJECTHIERARCHY, ParasiteObjectHierarchy))
#define PARASITE_OBJECTHIERARCHY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), PARASITE_TYPE_OBJECTHIERARCHY, ParasiteObjectHierarchyClass))
#define PARASITE_IS_OBJECTHIERARCHY(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), PARASITE_TYPE_OBJECTHIERARCHY))
#define PARASITE_IS_OBJECTHIERARCHY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), PARASITE_TYPE_OBJECTHIERARCHY))
#define PARASITE_OBJECTHIERARCHY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), PARASITE_TYPE_OBJECTHIERARCHY, ParasiteObjectHierarchyClass))
typedef struct _ParasiteObjectHierarchyPrivate ParasiteObjectHierarchyPrivate;
typedef struct _ParasiteObjectHierarchy {
GtkBox parent;
ParasiteObjectHierarchyPrivate *priv;
} ParasiteObjectHierarchy;
typedef struct _ParasiteObjectHierarchyClass {
GtkBoxClass parent;
} ParasiteObjectHierarchyClass;
G_BEGIN_DECLS
GType parasite_objecthierarchy_get_type (void);
GtkWidget *parasite_objecthierarchy_new (void);
void parasite_objecthierarchy_set_object (ParasiteObjectHierarchy *editor,
GObject *object);
G_END_DECLS
#endif // _GTKPARASITE_OBJECTHIERARCHY_H_
// vim: set et sw=4 ts=4:
|
15e6f8a748d4e802838f4e741fad8768afe202a7
|
ea885245dfebeb46e6e9477af2a7eb4e210e0dd8
|
/Samples/I2C/I2C_LSM6DS3_HighLevelApp/main.c
|
bc3c057b509a42ee78e083388321ea4b1116cec0
|
[
"MIT",
"LicenseRef-scancode-generic-cla"
] |
permissive
|
Azure/azure-sphere-samples
|
5e5e6107cf157e3835e710dd8abce1ac7189e677
|
96fc529d76e3a964b0ad75d5abebdad8acaf7695
|
refs/heads/main
| 2023-07-08T23:48:15.437132
| 2023-06-20T20:23:01
| 2023-06-20T20:23:01
| 141,919,956
| 234
| 254
|
NOASSERTION
| 2023-06-20T20:23:03
| 2018-07-22T18:17:51
|
C
|
UTF-8
|
C
| false
| false
| 15,083
|
c
|
main.c
|
/* Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the MIT License. */
// This sample C application for Azure Sphere uses the Azure Sphere I2C APIs to display
// data from an accelerometer connected via I2C.
//
// It uses the APIs for the following Azure Sphere application libraries:
// - log (displays messages in the Device Output window during debugging)
// - i2c (communicates with LSM6DS3 accelerometer)
// - eventloop (system invokes handlers for timer events)
#include <errno.h>
#include <signal.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
// applibs_versions.h defines the API struct versions to use for applibs APIs.
#include "applibs_versions.h"
#include <applibs/log.h>
#include <applibs/i2c.h>
#include <applibs/eventloop.h>
// The following #include imports a "sample appliance" hardware definition. This provides a set of
// named constants such as SAMPLE_BUTTON_1 which are used when opening the peripherals, rather
// that using the underlying pin names. This enables the same code to target different hardware.
//
// By default, this app targets hardware that follows the MT3620 Reference Development Board (RDB)
// specification, such as the MT3620 Dev Kit from Seeed Studio. To target different hardware, you'll
// need to update the TARGET_HARDWARE variable in CMakeLists.txt - see instructions in that file.
//
// You can also use hardware definitions related to all other peripherals on your dev board because
// the sample_appliance header file recursively includes underlying hardware definition headers.
// See https://aka.ms/azsphere-samples-hardwaredefinitions for further details on this feature.
#include <hw/sample_appliance.h>
#include "eventloop_timer_utilities.h"
/// <summary>
/// Exit codes for this application. These are used for the
/// application exit code. They must all be between zero and 255,
/// where zero is reserved for successful termination.
/// </summary>
typedef enum {
ExitCode_Success = 0,
ExitCode_TermHandler_SigTerm = 1,
ExitCode_AccelTimer_Consume = 2,
ExitCode_AccelTimer_ReadStatus = 3,
ExitCode_AccelTimer_ReadZAccel = 4,
ExitCode_ReadWhoAmI_WriteThenRead = 5,
ExitCode_ReadWhoAmI_WriteThenReadCompare = 6,
ExitCode_ReadWhoAmI_Write = 7,
ExitCode_ReadWhoAmI_Read = 8,
ExitCode_ReadWhoAmI_WriteReadCompare = 9,
ExitCode_ReadWhoAmI_PosixWrite = 10,
ExitCode_ReadWhoAmI_PosixRead = 11,
ExitCode_ReadWhoAmI_PosixCompare = 12,
ExitCode_SampleRange_Reset = 13,
ExitCode_SampleRange_SetRange = 14,
ExitCode_Init_EventLoop = 15,
ExitCode_Init_AccelTimer = 16,
ExitCode_Init_OpenMaster = 17,
ExitCode_Init_SetBusSpeed = 18,
ExitCode_Init_SetTimeout = 19,
ExitCode_Init_SetDefaultTarget = 20,
ExitCode_Main_EventLoopFail = 21
} ExitCode;
// Support functions.
static void TerminationHandler(int signalNumber);
static void AccelTimerEventHandler(EventLoopTimer *timer);
static ExitCode ReadWhoAmI(void);
static bool CheckTransferSize(const char *desc, size_t expectedBytes, ssize_t actualBytes);
static ExitCode ResetAndSetSampleRange(void);
static ExitCode InitPeripheralsAndHandlers(void);
static void CloseFdAndPrintError(int fd, const char *fdName);
static void ClosePeripheralsAndHandlers(void);
// File descriptors - initialized to invalid value
static int i2cFd = -1;
static EventLoop *eventLoop = NULL;
static EventLoopTimer *accelTimer = NULL;
// DocID026899 Rev 10, S6.1.1, I2C operation
// SDO is tied to ground so the least significant bit of the address is zero.
static const uint8_t lsm6ds3Address = 0x6A;
// Termination state
static volatile sig_atomic_t exitCode = ExitCode_Success;
/// <summary>
/// Signal handler for termination requests. This handler must be async-signal-safe.
/// </summary>
static void TerminationHandler(int signalNumber)
{
// Don't use Log_Debug here, as it is not guaranteed to be async-signal-safe.
exitCode = ExitCode_TermHandler_SigTerm;
}
/// <summary>
/// Print latest data from accelerometer.
/// </summary>
static void AccelTimerEventHandler(EventLoopTimer *timer)
{
static int iter = 1;
if (ConsumeEventLoopTimerEvent(timer) != 0) {
exitCode = ExitCode_AccelTimer_Consume;
return;
}
// Status register describes whether accelerometer is available.
// DocID026899 Rev 10, S9.26, STATUS_REG (1Eh); [0] = XLDA
static const uint8_t statusRegId = 0x1E;
uint8_t status;
ssize_t transferredBytes = I2CMaster_WriteThenRead(
i2cFd, lsm6ds3Address, &statusRegId, sizeof(statusRegId), &status, sizeof(status));
if (!CheckTransferSize("I2CMaster_WriteThenRead (STATUS_REG)",
sizeof(statusRegId) + sizeof(status), transferredBytes)) {
exitCode = ExitCode_AccelTimer_ReadStatus;
return;
}
if ((status & 0x1) == 0) {
Log_Debug("INFO: %d: No accelerometer data.\n", iter);
} else {
// Read two-byte Z-axis output register.
// DocID026899 Rev 10, S9.38, OUTZ_L_XL (2Ch)
static const uint8_t outZLXl = 0x2C;
int16_t zRaw;
transferredBytes = I2CMaster_WriteThenRead(i2cFd, lsm6ds3Address, &outZLXl, sizeof(outZLXl),
(uint8_t *)&zRaw, sizeof(zRaw));
if (!CheckTransferSize("I2CMaster_WriteThenRead (OUTZ_L_XL)",
sizeof(outZLXl) + sizeof(zRaw), transferredBytes)) {
exitCode = ExitCode_AccelTimer_ReadZAccel;
return;
}
// DocID026899 Rev 10, S4.1, Mechanical characteristics
// These constants are specific to LA_So where FS = +/-4g, as set in CTRL1_X.
double g = (zRaw * 0.122) / 1000.0;
Log_Debug("INFO: %d: vertical acceleration: %.2lfg\n", iter, g);
}
++iter;
}
/// <summary>
/// Demonstrates three ways of reading data from the attached device.
// This also works as a smoke test to ensure the Azure Sphere device can talk to
/// the I2C device.
/// </summary>
/// <returns>
/// ExitCode_Success on success; otherwise another ExitCode value which indicates
/// the specific failure.
/// </returns>
static ExitCode ReadWhoAmI(void)
{
// DocID026899 Rev 10, S9.11, WHO_AM_I (0Fh); has fixed value 0x69.
static const uint8_t whoAmIRegId = 0x0F;
static const uint8_t expectedWhoAmI = 0x69;
uint8_t actualWhoAmI;
// Read register value using AppLibs combination read and write API.
ssize_t transferredBytes =
I2CMaster_WriteThenRead(i2cFd, lsm6ds3Address, &whoAmIRegId, sizeof(whoAmIRegId),
&actualWhoAmI, sizeof(actualWhoAmI));
if (!CheckTransferSize("I2CMaster_WriteThenRead (WHO_AM_I)",
sizeof(whoAmIRegId) + sizeof(actualWhoAmI), transferredBytes)) {
return ExitCode_ReadWhoAmI_WriteThenRead;
}
Log_Debug("INFO: WHO_AM_I=0x%02x (I2CMaster_WriteThenRead)\n", actualWhoAmI);
if (actualWhoAmI != expectedWhoAmI) {
Log_Debug("ERROR: Unexpected WHO_AM_I value.\n");
return ExitCode_ReadWhoAmI_WriteThenReadCompare;
}
// Read register value using AppLibs separate read and write APIs.
transferredBytes = I2CMaster_Write(i2cFd, lsm6ds3Address, &whoAmIRegId, sizeof(whoAmIRegId));
if (!CheckTransferSize("I2CMaster_Write (WHO_AM_I)", sizeof(whoAmIRegId), transferredBytes)) {
return ExitCode_ReadWhoAmI_Write;
}
transferredBytes = I2CMaster_Read(i2cFd, lsm6ds3Address, &actualWhoAmI, sizeof(actualWhoAmI));
if (!CheckTransferSize("I2CMaster_Read (WHO_AM_I)", sizeof(actualWhoAmI), transferredBytes)) {
return ExitCode_ReadWhoAmI_Read;
}
Log_Debug("INFO: WHO_AM_I=0x%02x (I2CMaster_Write + I2CMaster_Read)\n", actualWhoAmI);
if (actualWhoAmI != expectedWhoAmI) {
Log_Debug("ERROR: Unexpected WHO_AM_I value.\n");
return ExitCode_ReadWhoAmI_WriteReadCompare;
}
// Read register value using POSIX APIs.
// This uses the I2C target address which was set earlier with
// I2CMaster_SetDefaultTargetAddress.
transferredBytes = write(i2cFd, &whoAmIRegId, sizeof(whoAmIRegId));
if (!CheckTransferSize("write (WHO_AM_I)", sizeof(whoAmIRegId), transferredBytes)) {
return ExitCode_ReadWhoAmI_PosixWrite;
}
transferredBytes = read(i2cFd, &actualWhoAmI, sizeof(actualWhoAmI));
if (!CheckTransferSize("read (WHO_AM_I)", sizeof(actualWhoAmI), transferredBytes)) {
return ExitCode_ReadWhoAmI_PosixRead;
}
Log_Debug("INFO: WHO_AM_I=0x%02x (POSIX read + write)\n", actualWhoAmI);
if (actualWhoAmI != expectedWhoAmI) {
Log_Debug("ERROR: Unexpected WHO_AM_I value.\n");
return ExitCode_ReadWhoAmI_PosixCompare;
}
return ExitCode_Success;
}
/// <summary>
/// Checks the number of transferred bytes for I2C functions and prints an error
/// message if the functions failed or if the number of bytes is different than
/// expected number of bytes to be transferred.
/// </summary>
/// <returns>true on success, or false on failure</returns>
static bool CheckTransferSize(const char *desc, size_t expectedBytes, ssize_t actualBytes)
{
if (actualBytes < 0) {
Log_Debug("ERROR: %s: errno=%d (%s)\n", desc, errno, strerror(errno));
return false;
}
if (actualBytes != (ssize_t)expectedBytes) {
Log_Debug("ERROR: %s: transferred %zd bytes; expected %zd\n", desc, actualBytes,
expectedBytes);
return false;
}
return true;
}
/// <summary>
/// Resets the accelerometer and sets the sample range.
/// </summary>
/// <returns>
/// ExitCode_Success on success; otherwise another ExitCode value which indicates
/// the specific failure.
/// </returns>
static ExitCode ResetAndSetSampleRange(void)
{
// Reset device to put registers into default state.
// DocID026899 Rev 10, S9.14, CTRL3_C (12h); [0] = SW_RESET
static const uint8_t ctrl3cRegId = 0x12;
const uint8_t resetCommand[] = {ctrl3cRegId, 0x01};
ssize_t transferredBytes =
I2CMaster_Write(i2cFd, lsm6ds3Address, resetCommand, sizeof(resetCommand));
if (!CheckTransferSize("I2CMaster_Write (CTRL3_C)", sizeof(resetCommand), transferredBytes)) {
return ExitCode_SampleRange_Reset;
}
// Wait for device to come out of reset.
uint8_t ctrl3c;
do {
transferredBytes = I2CMaster_WriteThenRead(i2cFd, lsm6ds3Address, &ctrl3cRegId,
sizeof(ctrl3cRegId), &ctrl3c, sizeof(ctrl3c));
} while (!(transferredBytes == (sizeof(ctrl3cRegId) + sizeof(ctrl3c)) && (ctrl3c & 0x1) == 0));
// Use sample range +/- 4g, with 12.5Hz frequency.
// DocID026899 Rev 10, S9.12, CTRL1_XL (10h)
static const uint8_t setCtrl1XlCommand[] = {0x10, 0x18};
transferredBytes =
I2CMaster_Write(i2cFd, lsm6ds3Address, setCtrl1XlCommand, sizeof(setCtrl1XlCommand));
if (!CheckTransferSize("I2CMaster_Write (CTRL1_XL)", sizeof(setCtrl1XlCommand),
transferredBytes)) {
return ExitCode_SampleRange_SetRange;
}
return ExitCode_Success;
}
/// <summary>
/// Set up SIGTERM termination handler, initialize peripherals, and set up event handlers.
/// </summary>
/// <returns>
/// ExitCode_Success if all resources were allocated successfully; otherwise another
/// ExitCode value which indicates the specific failure.
/// </returns>
static ExitCode InitPeripheralsAndHandlers(void)
{
struct sigaction action;
memset(&action, 0, sizeof(struct sigaction));
action.sa_handler = TerminationHandler;
sigaction(SIGTERM, &action, NULL);
eventLoop = EventLoop_Create();
if (eventLoop == NULL) {
Log_Debug("Could not create event loop.\n");
return ExitCode_Init_EventLoop;
}
// Print accelerometer data every second.
static const struct timespec accelReadPeriod = {.tv_sec = 1, .tv_nsec = 0};
accelTimer = CreateEventLoopPeriodicTimer(eventLoop, &AccelTimerEventHandler, &accelReadPeriod);
if (accelTimer == NULL) {
return ExitCode_Init_AccelTimer;
}
i2cFd = I2CMaster_Open(SAMPLE_LSM6DS3_I2C);
if (i2cFd == -1) {
Log_Debug("ERROR: I2CMaster_Open: errno=%d (%s)\n", errno, strerror(errno));
return ExitCode_Init_OpenMaster;
}
int result = I2CMaster_SetBusSpeed(i2cFd, I2C_BUS_SPEED_STANDARD);
if (result != 0) {
Log_Debug("ERROR: I2CMaster_SetBusSpeed: errno=%d (%s)\n", errno, strerror(errno));
return ExitCode_Init_SetBusSpeed;
}
result = I2CMaster_SetTimeout(i2cFd, 100);
if (result != 0) {
Log_Debug("ERROR: I2CMaster_SetTimeout: errno=%d (%s)\n", errno, strerror(errno));
return ExitCode_Init_SetTimeout;
}
// This default address is used for POSIX read and write calls. The AppLibs APIs take a target
// address argument for each read or write.
result = I2CMaster_SetDefaultTargetAddress(i2cFd, lsm6ds3Address);
if (result != 0) {
Log_Debug("ERROR: I2CMaster_SetDefaultTargetAddress: errno=%d (%s)\n", errno,
strerror(errno));
return ExitCode_Init_SetDefaultTarget;
}
ExitCode localExitCode = ReadWhoAmI();
if (localExitCode != ExitCode_Success) {
return localExitCode;
}
localExitCode = ResetAndSetSampleRange();
if (localExitCode != ExitCode_Success) {
return localExitCode;
}
return ExitCode_Success;
}
/// <summary>
/// Closes a file descriptor and prints an error on failure.
/// </summary>
/// <param name="fd">File descriptor to close</param>
/// <param name="fdName">File descriptor name to use in error message</param>
static void CloseFdAndPrintError(int fd, const char *fdName)
{
if (fd >= 0) {
int result = close(fd);
if (result != 0) {
Log_Debug("ERROR: Could not close fd %s: %s (%d).\n", fdName, strerror(errno), errno);
}
}
}
/// <summary>
/// Close peripherals and handlers.
/// </summary>
static void ClosePeripheralsAndHandlers(void)
{
DisposeEventLoopTimer(accelTimer);
EventLoop_Close(eventLoop);
Log_Debug("Closing file descriptors.\n");
CloseFdAndPrintError(i2cFd, "i2c");
}
/// <summary>
/// Main entry point for this application.
/// </summary>
int main(int argc, char *argv[])
{
Log_Debug("I2C accelerometer application starting.\n");
exitCode = InitPeripheralsAndHandlers();
// Use event loop to wait for events and trigger handlers, until an error or SIGTERM happens
while (exitCode == ExitCode_Success) {
EventLoop_Run_Result result = EventLoop_Run(eventLoop, -1, true);
// Continue if interrupted by signal, e.g. due to breakpoint being set.
if (result == EventLoop_Run_Failed && errno != EINTR) {
exitCode = ExitCode_Main_EventLoopFail;
}
}
ClosePeripheralsAndHandlers();
Log_Debug("Application exiting.\n");
return exitCode;
}
|
dbfda1c21e76c9fcd8d3264165d02f92cdfc36ab
|
e65a4dbfbfb0e54e59787ba7741efee12f7687f3
|
/security/snortsam/files/patch-src_snortsam.h
|
7e8fe2d2dd4ffeec87155b4ed189294c1f5530bb
|
[
"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
| 468
|
h
|
patch-src_snortsam.h
|
Avoid redefining bool
snortsam.c:750:6: error: conflicting types for 'parseline'
void parseline(char *arg,bool first,char *file,unsigned long line)
^
./snortsam.h:470:6: note: previous declaration is here
void parseline(char *arg,bool first,char *file,unsigned long line);
^
--- src/snortsam.h.orig 2020-03-30 10:54:24 UTC
+++ src/snortsam.h
@@ -59,6 +59,7 @@
#endif
+#include <stdbool.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
|
6c6ff9af3cb507cbd738549afbf58a006cc22724
|
e3c0499cc58c9fbec887a2e85672d5e29588f9e0
|
/dex/clibs/basic/arch/common/time/ctime.c
|
5e97e17874e1ddbb07441efb5d582d7bafb4dd5b
|
[
"BSD-3-Clause"
] |
permissive
|
stevenknown/xoc
|
bf19fba2a7851f0c91d62846b61f12000993fa94
|
3514aaf0d742e7c1bff956f5a5e96a92102abe8a
|
refs/heads/master
| 2023-05-14T10:18:34.851859
| 2023-04-29T08:15:24
| 2023-04-29T08:15:24
| 40,242,945
| 132
| 19
|
NOASSERTION
| 2023-09-08T08:04:04
| 2015-08-05T12:02:52
|
C++
|
UTF-8
|
C
| false
| false
| 4,632
|
c
|
ctime.c
|
/*Copyright 2011 Alibaba Group*/
#include "time/ctimeport.h"
static const UInt16 _normal_mdays[] = {
0, //1,31
31, //2,28 + 1
59, //3,31
90, //4,30
120, //5,31
151, //6,30
181, //7,31
212, //8,31
243, //9,30
273, //10,31
304, //11,30
334, //12,31
365,
999,
999
};
static const UInt16 _leap_mdays[] = {
0, //1,31
31, //2,29
60, //3,31
91, //4,30
121, //5,31
152, //6,30
182, //7,31
213, //8,31
244, //9,30
274, //10,31
305, //11,30
335, //12,31
366,
999,
999
};
/**
* set the local timezone, this will affect cTimeGetLocalDate() and cTimeTime2LocalDate()
* @param z: timezone, values of [-12 to +12]
*/
void cTimeSetTimeZone(Float32 z) {
cTimeSetTimeZonePort(z);
}
/**
* get the local timezone
*/
Float32 cTimeGetTimeZone() {
return cTimeGetTimeZonePort();
}
/**
* get date of the specified timezone, if need GMT date, set param z to 0
*/
void cTimeGetDate(CDateT* d, Float32 z) {
if(d) {
CTimeT t = cTimeGetTimePort();
cTimeTime2Date(t, d, z);
}
}
/**
* get local date
*/
void cTimeGetLocalDate(CDateT* d) {
cTimeGetDate(d, cTimeGetTimeZonePort());
}
/**
* get the gmt time
*/
CTimeT cTimeGetTime(void) {
return cTimeGetTimePort();
}
/**
* get the gmt nano time
*/
CTimeT cTimeGetNanoTime(void) {
return cTimeGetNanoTimePort();
}
UInt32 cTimeTicks(void) {
return cTimeTicksPort();
}
/**
* convert one date to another date of a specified timezone
* @param d1: source date
* @param d2: dist date
* @param z: dist timezone
*/
void cTimeDateConvert(CDateT* d1, CDateT* d2, Float32 z) {
if(d1 && d2) {
CTimeT t = cTimeDate2Time(d1);
cTimeTime2Date(t, d2, z);
}
}
/**
* convert time to date of specified timezone, if need GMT date, set param z to 0
*/
void cTimeTime2Date(CTimeT t, CDateT* d, Float32 z) {
if(t && d) {
UInt16 nday,nyear,n;
UInt32 secs = CTIME_SECOND(t)+(Int32)(z*3600);
nday = secs/(24*3600) + 1;/*Modified by larry:20090223*/
nyear = nday/365;
while((n = cTimeGetDays((UInt16)(1970+nyear), (UInt8)1, (UInt8)1)) > nday) {
nyear--;
}
d->year = 1970+nyear;
nday -= n;
d->yday = nday+1;
n = cTimeGetMonthAndDay(d->year,d->yday);
d->mon = n>>8;
d->mday = n&0xff;
d->wday = cTimeGetWeekDay(d->year,d->mon,d->mday);
secs %= 24*3600;
d->hour = secs/3600;
d->min = (secs/60)%60;
d->sec = secs%60;
d->ms = CTIME_MS(t);
d->zone = z;
}
}
/**
* convert time to local date
*/
void cTimeTime2LocalDate(CTimeT t, CDateT* d) {
cTimeTime2Date(t, d, cTimeGetTimeZonePort());
}
/**
* convert date to time
*/
CTimeT cTimeDate2Time(CDateT* d) {
CTimeT t;
if(d == NULL)
return 0;
t = ((cTimeGetDays(d->year,d->mon,d->mday)*24)+d->hour)*3600-(Int32)d->zone*3600
+ d->min * 60 + d->sec;
t += t*1000+d->ms;
return t;
}
bool cTimeIsLeapYear(UInt16 year) {
Int32 n1,n2,n3;
bool ret;
n1 = year%4;
n2 = year%400;
n3 = year%100;
ret = (!n2)||((!n1)&&n3);
return ret;
}
bool cTimeIsDateValid(UInt16 year, UInt8 month, UInt8 mday) {
const UInt16 * _mdays;
if(month < 1 || month > 12)
return false;
_mdays = cTimeIsLeapYear(year) ? _leap_mdays : _normal_mdays;
return mday > 0 && mday <= (_mdays[month]-_mdays[month-1]);
}
/**
* get days since 1970-1-1, begin from 0
* for example:
* cTimeGetDays(1970,1,2) returns 1
*/
UInt32 cTimeGetDays(UInt16 year, UInt8 month, UInt8 mday) {
UInt32 n = (year-2001)/100;
n -= n/4;
return (year-1970)*365 + ((year-1969)/4) - n + cTimeGetYearDay(year,month,mday)-1;
}
UInt16 cTimeGetYearDay(UInt16 year, UInt8 month, UInt8 mday) {
return (cTimeIsLeapYear(year) ? _leap_mdays[month-1] : _normal_mdays[month-1]) + mday;
}
UInt8 cTimeGetWeekDay(UInt16 year, UInt8 month, UInt8 mday) {
UInt8 wday;
if (month < 3) {
month += 13;
year--;
}
else {
month++;
}
wday = (mday + 26 * month / 10 + year + year / 4 - year / 100 + year / 400 + 6) % 7;
wday = wday ? wday : 7;
return wday;
}
UInt16 cTimeGetMonthAndDay(UInt16 year, UInt16 yday) {
UInt16 mday,month;
const UInt16 * _mdays = cTimeIsLeapYear(year) ? _leap_mdays : _normal_mdays;
month = (yday+27)/28;
while(yday <= _mdays[month-1]) {
month--;
}
mday = yday-_mdays[month-1];
return (month<<8) | mday;
}
|
da970efac32049baea31840351bc5e5adebc7715
|
9de0cec678bc4a3bec2b4adabef9f39ff5b4afac
|
/PWGLF/FORWARD/analysis2/trains/MakeFMDMCTrackTrain.C
|
3d9345969fa5756347a21abe777606e3f9e5e69c
|
[] |
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
| 9,184
|
c
|
MakeFMDMCTrackTrain.C
|
/**
* @file MakeFMDMCTrackTrain.C
* @author Christian Holm Christensen <cholm@nbi.dk>
* @date Fri Jun 1 13:54:47 2012
*
* @brief
*
* @ingroup pwglf_forward_trains_specific
*/
#include "TrainSetup.C"
// #include "ParUtilities.C"
//====================================================================
/**
* Analysis train to make Forward and Central MC corrections
*
*
* @ingroup pwglf_forward_mc
* @ingroup pwglf_forward_trains_specific
*/
class MakeFMDMCTrackTrain : public TrainSetup
{
public:
/**
* Constructor. Date and time must be specified when running this
* in Termiante mode on Grid
*
* @param name Name of train (free form)
*/
MakeFMDMCTrackTrain(const char* name)
: TrainSetup(name)
{
fOptions.Add("use-tuple", "Whether to make an NTuple of hits");
fOptions.Add("max-strips", "NUMBER", "Max strips/cluster", 2);
fOptions.Set("type", "ESD");
}
protected:
/**
* Create the tasks
*
* @param mgr Analysis manager
*/
void CreateTasks(AliAnalysisManager* mgr)
{
// --- Output file name ------------------------------------------
AliAnalysisManager::SetCommonFileName("forward_mctracks.root");
// --- Load libraries/pars ---------------------------------------
fRailway->LoadLibrary("PWGLFforward2");
// fRailway->LoadLibrary("Proof");
// fRailway->LoadLibrary("Gui"); // Sigh! CDB depends on GUI!
// fRailway->LoadLibrary("CDB");
// fRailway->LoadLibrary("RAWDatabase");
// fRailway->LoadLibrary("STEER");
// fRailway->LoadLibrary("FMDbase");
// fRailway->LoadLibrary("FMDsim");
// fRailway->LoadLibrary("PWGLFforwardhit");
// --- Set load path ---------------------------------------------
gROOT->SetMacroPath(Form("%s:$(ALICE_PHYSICS)/PWGLF/FORWARD/analysis2",
gROOT->GetMacroPath()));
// --- Check if this is MC ---------------------------------------
if (!mgr->GetMCtruthEventHandler())
Fatal("CreateTasks", "No MC truth handler");
Bool_t useTuple = fOptions.AsBool("use-tuple");
UShort_t maxStrips = fOptions.AsInt("max-strips");
Int_t verbose = fOptions.AsInt("verbose");
TString args = TString::Format("%d,%d,%d",
useTuple,
maxStrips,
verbose);
if (!CoupleCar("AddTaskFMDMCTracks.C", args))
Fatal("CreateTasks", "Couldn't add our task");
}
//__________________________________________________________________
/**
* Create physics selection , and add to manager
*
* @param mc Whether this is for MC
* @param mgr Manager
*/
void CreatePhysicsSelection(Bool_t mc,
AliAnalysisManager* mgr)
{
TrainSetup::CreatePhysicsSelection(mc, mgr);
// --- Get input event handler -----------------------------------
AliInputEventHandler* ih =
dynamic_cast<AliInputEventHandler*>(mgr->GetInputEventHandler());
if (!ih)
Fatal("CreatePhysicsSelection", "Couldn't get input handler (%p)", ih);
// --- Get Physics selection -------------------------------------
AliPhysicsSelection* ps =
dynamic_cast<AliPhysicsSelection*>(ih->GetEventSelection());
if (!ps)
Fatal("CreatePhysicsSelection", "Couldn't get PhysicsSelection (%p)", ps);
// --- Ignore trigger class when selecting events. This means ---
// --- that we get offline+(A,C,E) events too --------------------
// ps->SetSkipTriggerClassSelection(true);
}
//__________________________________________________________________
/**
* @return 0 - AOD disabled
*/
virtual AliVEventHandler* CreateOutputHandler(UShort_t) { return 0; }
/**
* Do not the centrality selection
*/
// void CreateCentralitySelection(Bool_t) {}
//__________________________________________________________________
const char* ClassName() const { return "MakeFMDMCTrackTrain"; }
/**
* Overloaded to create new dNdeta.C and dndeta.sh in the output
* directory
*
* @param asShellScript
*/
void SaveSetup(Bool_t asShellScript)
{
TrainSetup::SaveSetup(asShellScript);
SaveSummarize();
SaveAnalyseNTuple();
SaveReFit();
if (!fRailway || fRailway->Mode() != Railway::kGrid) return;
SaveDownloadTrees();
}
/**
* Write a ROOT script to draw summary
*
*/
void SaveSummarize()
{
std::ofstream f("Summarize.C");
if (!f) {
Error("SaveSummarize", "Failed to open Summarize.C script");
return;
}
f << "// Generated by " << ClassName() << "\n"
<< "// WHAT is a bit mask of\n"
<< "// 0x001 Event inspector\n"
<< "// 0x002 Track inspector\n"
<< "// 0x004 Energy loss fits\n"
<< "// 0x100 Landscape\n"
<< "// 0x200 Pause\n"
<< "//\n"
<< "void Summarize(const char* filename=\"forward_mctracks.root\",\n"
<< " UShort_t what=0x10F)\n"
<< "{\n"
<< " const char* fwd=\"$ALICE_PHYSICS/PWGLF/FORWARD/analysis2\";\n"
<< " gROOT->LoadMacro(Form(\"%s/scripts/SummaryMCTrackDrawer.C+g\",fwd));\n"
<< " SummaryMCTrackDrawer smd;\n"
<< " smd.Run(filename,what);\n"
<< "}\n"
<< "// EOF" << std::endl;
f.close();
}
/**
* Make a ROOT Script to download the generated AODs
*
*/
void SaveDownloadTrees()
{
std::ofstream f("DownloadTrees.C");
if (!f) {
Error("SaveDownloadTrees", "Failed to open DownloadTrees.C");
return;
}
f << "// Generated by " << ClassName() << "\n"
<< "void DownloadTrees(Bool_t force=false)\n"
<< "{\n"
<< " if (!TGrid::Connect(\"alien://\")) {\n"
<< " Error(\"DownloadTrees\",\"Failed to connect to AliEn\");\n"
<< " return;\n"
<< " }\n\n"
<< " TString dir(\"" << fRailway->OutputPath() << "\");\n"
<< " TString pat(\"*/forward_tuple.root\");\n"
<< " TGridResult* r = gGrid->Query(dir,pat);\n"
<< " if (!r) {\n"
<< " Error(\"DownloadTrees\",\"No result from query\");\n"
<< " return;\n"
<< " }\n\n"
<< " Int_t n = r->GetEntries();\n"
<< " Printf(\"=== Got a total of %d AOD files\",n);\n"
<< " for (Int_t i = 0; i < n; i++) {\n"
<< " TString path(r->GetKey(i, \"turl\"));\n"
<< " TString dir(gSystem->DirName(path));\n"
<< " TString sub(gSystem->BaseName(dir));\n"
<< " TString subsub(gSystem->BaseName(gSystem->DirName(dir)));\n"
<< " TString out = TString::Format(\"forward_tree_%s_%s.root\",\n"
<< " subsub.Data(),sub.Data());\n"
<< " if (!gSystem->AccessPathName(out.Data()) && !force) {\n"
<< " Printf(\"=== Already have %s\",out.Data());\n"
<< " continue;\n"
<< " }\n"
<< " Printf(\"=== Getting %s %s (%3d/%3d)\",\n"
<< " subsub.Data(),sub.Data(),i,n);\n"
<< " if (!TFile::Cp(path, out)) {\n"
<< " Warning(\"DownloadTrees\",\"Failed to copy %s -> %s\",\n"
<< " path.Data(), out.Data());\n"
<< " continue;\n"
<< " }\n"
<< " }\n"
<< "}\n"
<< "// EOF\n"
<< std::endl;
f.close();
}
/**
* Make a ROOT Script to download the generated AODs
*
*/
void SaveAnalyseNTuple()
{
std::ofstream f("AnalyseNTuple.C");
if (!f) {
Error("SaveAnalyseNTuple", "Failed to open AnalyseNTuple.C");
return;
}
f << "// Generated by " << ClassName() << "\n"
<< "// Process with bare ROOT in ProofLite\n"
<< "void AnalyseNTuple(Bool_t proof=true,\n"
<< " Long64_t max=-1,\n"
<< " const char* opt=\"\")\n"
<< "{\n"
<< " const char* fwd=\"$ALICE_PHYSICS/PWGLF/FORWARD/analysis2\";\n"
<< " gSystem->AddIncludePath(\"-I${ALICE_PHYSICS}/include\");\n"
<< " gROOT->Macro(Form(\"%s/scripts/LoadLibs.C\",fwd));\n"
<< " gROOT->LoadMacro(Form(\"%s/scripts/TupleSelector.C+%s\",\n"
<< " fwd, opt));\n"
<< " if (proof) TupleSelector::Proof(maxEvents, opt);\n"
<< " else TupleSelector::Run(maxEvents);\n"
<< "}\n"
<< "// EOF" << std::endl;
f.close();
}
void SaveReFit()
{
std::ofstream f("ReFit.C");
if (!f) {
Error("SaveRerun", "Failed to open ReFit.C script");
return;
}
f << std::boolalpha
<< "// Generated by " << ClassName() << "\n"
<< "// If force=true, then force set parameters\n"
<< "//\n"
<< "void ReFit(Bool_t force=false,\n"
<< " const char* filename=\"forward_mctracks.root\")\n"
<< "{\n"
<< " const char* fwd=\"$ALICE_PHYSICS/PWGLF/FORWARD/analysis2\";\n"
<< " gROOT->LoadMacro(Form(\"%s/corrs/RerunTrackELoss.C\",fwd));\n"
<< " RerunTrackELoss(force,filename);\n"
<< "}\n"
<< "// EOF" << std::endl;
f.close();
}
void PostShellCode(std::ostream& f)
{
f << " echo \"=== Summarizing results ...\"\n"
<< " aliroot -l -b -q ${prefix}Summarize.C\n"
<< std::endl;
}
};
//
// EOF
//
|
61dd0f3c454b33a12d34474cc4af217cf851fd64
|
0f83867baae6c990b4b0c254ea7bb36c9a6646a5
|
/src/hardware_dep/dpdk/data_plane/externs/dpdkx_psa_checksum.c
|
78bd046ffb41def164563976fae0303ddd2b53fc
|
[
"Apache-2.0"
] |
permissive
|
P4ELTE/t4p4s
|
dc587e7567b62a5679dc7cc4c2985894684d8e6e
|
7cd5bacc7475892f4a1d8b22c2cf9c28e16e5781
|
refs/heads/master
| 2023-03-17T14:52:30.702080
| 2023-01-11T15:24:33
| 2023-01-11T15:24:33
| 62,548,413
| 107
| 55
|
Apache-2.0
| 2022-01-21T15:22:23
| 2016-07-04T09:14:10
|
C
|
UTF-8
|
C
| false
| false
| 4,691
|
c
|
dpdkx_psa_checksum.c
|
// SPDX-License-Identifier: Apache-2.0
// Copyright 2017 Eotvos Lorand University, Budapest, Hungary
#include "dpdk_model_psa.h"
#include <rte_ip.h>
#include "actions.h"
#include "util_debug.h"
#include "dpdk_lib.h"
#include "stateful_memory.h"
extern struct all_metadatas_t all_metadatas;
void EXTERNIMPL0(verify)(bool check, error_error_t toSignal, SHORT_STDPARAMS) {
// TODO implement call to extern
debug(" : Called extern " T4LIT(verify,extern) "\n");
}
void verify_checksum__b8s__b16(bool cond, uint8_buffer_t data, bitfield_handle_t cksum_field_handle, enum_PSA_HashAlgorithm_t algorithm, SHORT_STDPARAMS) {
debug(" :::: Calling extern " T4LIT(verify_checksum,extern) "\n");
}
void update_checksum__b8s__b16(bool cond, uint8_buffer_t data, bitfield_handle_t cksum_field_handle, enum_PSA_HashAlgorithm_t algorithm, SHORT_STDPARAMS) {
debug(" :::: Calling extern " T4LIT(update_checksum,extern) "\n");
}
void verify_checksum_offload(bitfield_handle_t cksum_field_handle, enum_PSA_HashAlgorithm_t algorithm, SHORT_STDPARAMS) {
debug(" :::: Calling extern " T4LIT(verify_checksum_offload,extern) "\n");
}
void update_checksum_offload(bitfield_handle_t cksum_field_handle, enum_PSA_HashAlgorithm_t algorithm, uint8_t len_l2, uint8_t len_l3, SHORT_STDPARAMS) {
debug(" :::: Calling extern " T4LIT(update_checksum_offload,extern) "\n");
}
//void verify(bool check, error_error_t toSignal, SHORT_STDPARAMS) {
// debug(" :::: Calling extern " T4LIT(verify,extern) "\n");
//}
void verify_checksum_with_payload(bool condition, uint8_buffer_t data, bitfield_handle_t checksum, enum_PSA_HashAlgorithm_t algo, SHORT_STDPARAMS) {
debug(" :::: Calling extern " T4LIT(verify_checksum_with_payload,extern) "\n");
}
void update_checksum_with_payload(bool condition, uint8_buffer_t data, bitfield_handle_t checksum, enum_PSA_HashAlgorithm_t algo, SHORT_STDPARAMS) {
debug(" :::: Calling extern " T4LIT(update_checksum_with_payload,extern) "\n");
}
////////////////////////////////
void EXTERNCALL0(InternetChecksum,init)(EXTERNTYPE0(InternetChecksum)* checksum, SHORT_STDPARAMS) {
debug(" :::: calling extern " T4LIT(InternetChecksum_t_init,extern) "\n");
}
void EXTERNCALL0(InternetChecksum,clear)(EXTERNTYPE0(InternetChecksum)* checksum, SHORT_STDPARAMS) {
debug(" :::: calling extern " T4LIT(extern_InternetChecksum_clear,extern) "\n");
}
void EXTERNCALL0(InternetChecksum,add)(EXTERNTYPE0(InternetChecksum)* checksum, SHORT_STDPARAMS) {
debug(" :::: calling extern " T4LIT(extern_InternetChecksum_add,extern) "\n");
}
// TODO autogenerate tuple cases
void EXTERNCALL1(InternetChecksum,add,tuple_0)(EXTERNTYPE0(InternetChecksum)* checksum, int data, SHORT_STDPARAMS) {
debug(" :::: calling extern " T4LIT(extern_InternetChecksum_add,extern) "\n");
}
uint16_t EXTERNCALL0(InternetChecksum,get)(EXTERNTYPE0(InternetChecksum)* checksum, SHORT_STDPARAMS) {
debug(" :::: calling extern " T4LIT(InternetChecksum_t_get,extern) "\n");
return 0;
}
void EXTERNCALL0(InternetChecksum,subtract)(EXTERNTYPE0(InternetChecksum)* checksum, uint16_t data, SHORT_STDPARAMS) {
debug(" :::: calling extern " T4LIT(InternetChecksum_t_subtract,extern) "\n");
}
uint16_t EXTERNCALL0(InternetChecksum,get_state)(EXTERNTYPE0(InternetChecksum)* checksum, SHORT_STDPARAMS) {
debug(" :::: calling extern " T4LIT(InternetChecksum_t_get_state,extern) "\n");
return 0;
}
void EXTERNCALL0(InternetChecksum,set_state)(EXTERNTYPE0(InternetChecksum)* checksum, uint16_t checksum_state, SHORT_STDPARAMS) {
debug(" :::: calling extern " T4LIT(InternetChecksum_t_set_state,extern) "\n");
}
enum_PSA_MeterColor_t EXTERNCALL0(Meter,execute)(SMEMTYPE(meter)* smem, int x, SHORT_STDPARAMS) {
debug(" :::: calling extern " T4LIT(Meter_execute,extern) "\n");
// TODO temporary implementation
return enum_PSA_MeterColor_t_RED;
}
enum_PSA_MeterColor_t EXTERNCALL1(Meter,execute,i32)(uint32_t x, enum_PSA_MeterType_t meter_type, int index, int color, SMEMTYPE(meter)* smem, SHORT_STDPARAMS) {
debug(" :::: calling extern " T4LIT(Meter_execute,extern) "\n");
// TODO temporary implementation
return enum_PSA_MeterColor_t_RED;
}
void EXTERNCALL2(Register,write,u32,i32)(uint32_t x1, int index, uint32_t value, REGTYPE(uint,32)* reg, SHORT_STDPARAMS) {
debug(" :::: calling extern " T4LIT(Register/write/u32/i32,extern) "\n");
}
// TODO the return type should appear as a parameter like this: EXTERNCALL0(Register,read,u32)
int EXTERNCALL0(Register,read)(REGTYPE(uint,32)* reg, SHORT_STDPARAMS) {
debug(" :::: calling extern " T4LIT(Register/read,extern) "\n");
// TODO temporary implementation
return 0;
}
|
91679a0f3179fae4b486892f1bcc187659053617
|
e65a4dbfbfb0e54e59787ba7741efee12f7687f3
|
/devel/electron23/files/patch-components_feature__engagement_public_feature__list.h
|
066fff8050d92cab8dc89e8ac814f5e1bcaeeea6
|
[
"BSD-2-Clause",
"BSD-3-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
| 2,415
|
h
|
patch-components_feature__engagement_public_feature__list.h
|
--- components/feature_engagement/public/feature_list.h.orig 2023-02-01 18:43:16 UTC
+++ components/feature_engagement/public/feature_list.h
@@ -223,7 +223,7 @@ DEFINE_VARIATION_PARAM(kIPHPriceNotificationsWhileBrow
#endif // BUILDFLAG(IS_IOS)
#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_APPLE) || BUILDFLAG(IS_LINUX) || \
- BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_FUCHSIA)
+ BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_FUCHSIA) || BUILDFLAG(IS_BSD)
DEFINE_VARIATION_PARAM(kIPHBatterySaverModeFeature, "IPH_BatterySaverMode");
DEFINE_VARIATION_PARAM(kIPHDesktopTabGroupsNewGroupFeature,
"IPH_DesktopTabGroupsNewGroup");
@@ -269,7 +269,8 @@ DEFINE_VARIATION_PARAM(kIPHPriceTrackingInSidePanelFea
// BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_FUCHSIA)
#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_APPLE) || BUILDFLAG(IS_LINUX) || \
- BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_FUCHSIA)
+ BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_FUCHSIA) || \
+ BUILDFLAG(IS_BSD)
DEFINE_VARIATION_PARAM(kIPHAutofillVirtualCardSuggestionFeature,
"IPH_AutofillVirtualCardSuggestion");
#endif // BUILDFLAG(IS_WIN) || BUILDFLAG(IS_APPLE) || BUILDFLAG(IS_LINUX) ||
@@ -377,7 +378,7 @@ constexpr flags_ui::FeatureEntry::FeatureVariation
VARIATION_ENTRY(kIPHOverflowMenuTipFeature),
VARIATION_ENTRY(kIPHPriceNotificationsWhileBrowsingFeature),
#elif BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_LINUX) || \
- BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_FUCHSIA)
+ BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_FUCHSIA) || BUILDFLAG(IS_BSD)
VARIATION_ENTRY(kIPHBatterySaverModeFeature),
VARIATION_ENTRY(kIPHDesktopTabGroupsNewGroupFeature),
VARIATION_ENTRY(kIPHExtensionsMenuFeature),
@@ -410,7 +411,8 @@ constexpr flags_ui::FeatureEntry::FeatureVariation
// BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_FUCHSIA)
#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_APPLE) || BUILDFLAG(IS_LINUX) || \
- BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_FUCHSIA)
+ BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_FUCHSIA) || \
+ BUILDFLAG(IS_BSD)
VARIATION_ENTRY(kIPHAutofillVirtualCardSuggestionFeature),
#endif // BUILDFLAG(IS_WIN) || BUILDFLAG(IS_APPLE) || BUILDFLAG(IS_LINUX) ||
// BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID) ||
|
aeac824a134ec534ec9a118091bfe7c44e24a61a
|
6ba7897c6f6968fe1b3da18c968ba759ba89828d
|
/code/AbsolutelyEverything.c
|
4849c769021b2311a1d6a61fdee27142c279cd93
|
[
"MIT"
] |
permissive
|
illacceptanything/illacceptanything
|
0414d351f060d493e293398b145baffc7050793e
|
1c9c339ba1ca3633211e0e01307508e81d539971
|
refs/heads/master
| 2023-08-08T19:30:58.680465
| 2023-07-20T06:05:22
| 2023-07-20T06:05:22
| 33,564,006
| 1,749
| 814
|
MIT
| 2023-08-20T08:25:41
| 2015-04-07T19:34:36
|
Ruby
|
UTF-8
|
C
| false
| false
| 22
|
c
|
AbsolutelyEverything.c
|
#include <universe.h>
|
7a1583ee68c898889d1f177ebc7f4bc53ca3c988
|
41f3926cd680231f740c3af9d31d9c9c581483fe
|
/User/COMPONENT/SHA256/sha256.c
|
c277ab0cb4fb2536caebf183cf10d56f2849d41d
|
[
"MIT"
] |
permissive
|
ShareCat/STM32CommandLine
|
2eed6c3d789e7cf51d3a24ee83a3ea61e4aaf142
|
1eb0f008400ecae14c074fecb7bfbd14beff648f
|
refs/heads/master
| 2023-04-30T18:46:40.416278
| 2023-04-24T09:43:23
| 2023-04-24T09:43:23
| 127,528,770
| 175
| 46
| null | null | null | null |
UTF-8
|
C
| false
| false
| 6,502
|
c
|
sha256.c
|
/*
* SHA-256 implementation.
*
* Copyright (c) 2010 Ilya O. Levin, http://www.literatecode.com
*
* 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.
*/
#define SWAP_BYTES
#define USE_STD_MEMCPY
// #define SELF_TEST
#ifdef USE_STD_MEMCPY
#include <string.h>
#endif
#include "sha256.h"
#ifdef __cplusplus
extern "C" {
#endif
#define RL(x,n) (((x) << n) | ((x) >> (32 - n)))
#define RR(x,n) (((x) >> n) | ((x) << (32 - n)))
#define S0(x) (RR((x), 2) ^ RR((x),13) ^ RR((x),22))
#define S1(x) (RR((x), 6) ^ RR((x),11) ^ RR((x),25))
#define G0(x) (RR((x), 7) ^ RR((x),18) ^ ((x) >> 3))
#define G1(x) (RR((x),17) ^ RR((x),19) ^ ((x) >> 10))
#ifdef SWAP_BYTES
#define BSWP(x,y) _bswapw((uint32_t *)(x), (uint32_t)(y))
#else
#define BSWP(p,n)
#endif
#ifdef USE_STD_MEMCPY
#define MEMCP(x,y,z) memcpy((x),(y),(z))
#else
#define MEMCP(x,y,z) _memcp((x),(y),(z))
#endif
#ifndef __cdecl
#define __cdecl
#endif
static const uint32_t K[64] = {
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
};
/* -------------------------------------------------------------------------- */
static void _bswapw(uint32_t *p, uint32_t i)
{
while (i--) p[i] = (RR(p[i],24) & 0x00ff00ff) | (RR(p[i],8) & 0xff00ff00);
} /* _bswapw */
/* -------------------------------------------------------------------------- */
#ifndef USE_STD_MEMCPY
void * __cdecl _memcp (void *d, const void *s, uint32_t sz)
{
void *rv = d;
while (sz--) *(char *)d = *(char *)s, d = (char *)d + 1, s = (char *)s + 1;
return(rv);
} /* _memcp */
#endif
/* -------------------------------------------------------------------------- */
static void _rtrf(uint32_t *b, uint32_t *p, uint32_t i, uint32_t j)
{
#define B(x, y) b[(x-y) & 7]
#define P(x, y) p[(x+y) & 15]
B(7,i) += (j ? (p[i & 15] += G1(P(i,14)) + P(i,9) + G0(P(i,1))) : p[i & 15])
+ K[i+j] + S1(B(4,i))
+ (B(6,i) ^ (B(4,i) & (B(5,i) ^ B(6,i))));
B(3,i) += B(7,i);
B(7,i) += S0(B(0,i)) + ( (B(0,i) & B(1,i)) | (B(2,i) & (B(0,i) ^ B(1,i))) );
#undef P
#undef B
} /* _rtrf */
/* -------------------------------------------------------------------------- */
static void _hash(sha256_context *ctx)
{
uint32_t b[8], *p, j;
b[0] = ctx->hash[0]; b[1] = ctx->hash[1]; b[2] = ctx->hash[2];
b[3] = ctx->hash[3]; b[4] = ctx->hash[4]; b[5] = ctx->hash[5];
b[6] = ctx->hash[6]; b[7] = ctx->hash[7];
for (p = ctx->buf, j = 0; j < 64; j += 16)
_rtrf(b, p, 0, j), _rtrf(b, p, 1, j), _rtrf(b, p, 2, j),
_rtrf(b, p, 3, j), _rtrf(b, p, 4, j), _rtrf(b, p, 5, j),
_rtrf(b, p, 6, j), _rtrf(b, p, 7, j), _rtrf(b, p, 8, j),
_rtrf(b, p, 9, j), _rtrf(b, p, 10, j), _rtrf(b, p, 11, j),
_rtrf(b, p, 12, j), _rtrf(b, p, 13, j), _rtrf(b, p, 14, j),
_rtrf(b, p, 15, j);
ctx->hash[0] += b[0]; ctx->hash[1] += b[1]; ctx->hash[2] += b[2];
ctx->hash[3] += b[3]; ctx->hash[4] += b[4]; ctx->hash[5] += b[5];
ctx->hash[6] += b[6]; ctx->hash[7] += b[7];
} /* _hash */
/* -------------------------------------------------------------------------- */
void sha256_init(sha256_context ctx[1])
{
ctx->len[0] = ctx->len[1] = 0;
ctx->hash[0] = 0x6a09e667; ctx->hash[1] = 0xbb67ae85;
ctx->hash[2] = 0x3c6ef372; ctx->hash[3] = 0xa54ff53a;
ctx->hash[4] = 0x510e527f; ctx->hash[5] = 0x9b05688c;
ctx->hash[6] = 0x1f83d9ab; ctx->hash[7] = 0x5be0cd19;
} /* sha256_init */
/* -------------------------------------------------------------------------- */
void sha256_hash(sha256_context *ctx, uint8_t *dat, uint32_t sz)
{
register uint32_t i = ctx->len[0] & 63, l, j;
if ((ctx->len[0] += sz) < sz) ++(ctx->len[1]);
for (j = 0, l = 64-i; sz >= l; j += l, sz -= l, l = 64, i = 0)
{
MEMCP(&ctx->buf[i], &dat[j], l);
BSWP(ctx->buf, 16 );
_hash(ctx);
}
MEMCP(&ctx->buf[i], &dat[j], sz);
} /* _hash */
/* -------------------------------------------------------------------------- */
void sha256_done(sha256_context *ctx, uint8_t *buf)
{
uint32_t i = (uint32_t)(ctx->len[0] & 63), j = ((~i) & 3) << 3;
BSWP(ctx->buf, (i + 3) >> 2);
ctx->buf[i >> 2] &= 0xffffff80 << j; /* add padding */
ctx->buf[i >> 2] |= 0x00000080 << j;
if (i < 56) i = (i >> 2) + 1;
else ctx->buf[15] ^= (i < 60) ? ctx->buf[15] : 0, _hash(ctx), i = 0;
while (i < 14) ctx->buf[i++] = 0;
ctx->buf[14] = (ctx->len[1] << 3)|(ctx->len[0] >> 29); /* add length */
ctx->buf[15] = ctx->len[0] << 3;
_hash(ctx);
for (i = 0; i < 32; i++)
ctx->buf[i % 16] = 0, /* may remove this line in case of a DIY cleanup */
buf[i] = (uint8_t)(ctx->hash[i >> 2] >> ((~i & 3) << 3));
} /* sha256_done */
void HAL_SHA256_Once(uint8_t * send_buffer,uint32_t send_buffer_len,uint8_t *recv_buffer)
{
sha256_context ctx;
sha256_init(&ctx);
sha256_hash(&ctx, (uint8_t *)send_buffer, (uint32_t)send_buffer_len);
sha256_done(&ctx, recv_buffer);
return;
}
#ifdef __cplusplus
}
#endif
|
d01b86020cbee34488bdc626f4d6fc4e2b823ea1
|
e65a4dbfbfb0e54e59787ba7741efee12f7687f3
|
/www/ungoogled-chromium/files/patch-chrome_browser_web__applications_os__integration_os__integration__test__override.h
|
488ad5de5154cd360f6693f0bf0d2f9ebb02276d
|
[
"BSD-2-Clause",
"BSD-3-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
| 676
|
h
|
patch-chrome_browser_web__applications_os__integration_os__integration__test__override.h
|
--- chrome/browser/web_applications/os_integration/os_integration_test_override.h.orig 2023-06-05 19:39:05 UTC
+++ chrome/browser/web_applications/os_integration/os_integration_test_override.h
@@ -92,7 +92,7 @@ class OsIntegrationTestOverride
virtual const base::FilePath& chrome_apps_folder() = 0;
virtual void EnableOrDisablePathOnLogin(const base::FilePath& file_path,
bool enable_on_login) = 0;
-#elif BUILDFLAG(IS_LINUX)
+#elif BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_BSD)
virtual const base::FilePath& desktop() = 0;
virtual const base::FilePath& startup() = 0;
virtual const base::FilePath& applications_dir() = 0;
|
113828e5fe66cd2369c732b99239a98776193999
|
eecd5e4c50d8b78a769bcc2675250576bed34066
|
/src/ksp/ksp/tests/ex15.c
|
93ac49eab581c4dbd96486d31727bd7502bd3e06
|
[
"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,912
|
c
|
ex15.c
|
static char help[] = "KSP linear solver on an operator with a null space.\n\n";
#include <petscksp.h>
int main(int argc, char **args)
{
Vec x, b, u; /* approx solution, RHS, exact solution */
Mat A; /* linear system matrix */
KSP ksp; /* KSP context */
PetscInt i, n = 10, col[3], its, i1, i2;
PetscScalar none = -1.0, value[3], avalue;
PetscReal norm;
PC pc;
PetscFunctionBeginUser;
PetscCall(PetscInitialize(&argc, &args, (char *)0, help));
PetscCall(PetscOptionsGetInt(NULL, NULL, "-n", &n, NULL));
/* Create vectors */
PetscCall(VecCreate(PETSC_COMM_WORLD, &x));
PetscCall(VecSetSizes(x, PETSC_DECIDE, n));
PetscCall(VecSetFromOptions(x));
PetscCall(VecDuplicate(x, &b));
PetscCall(VecDuplicate(x, &u));
/* create a solution that is orthogonal to the constants */
PetscCall(VecGetOwnershipRange(u, &i1, &i2));
for (i = i1; i < i2; i++) {
avalue = i;
VecSetValues(u, 1, &i, &avalue, INSERT_VALUES);
}
PetscCall(VecAssemblyBegin(u));
PetscCall(VecAssemblyEnd(u));
PetscCall(VecSum(u, &avalue));
avalue = -avalue / (PetscReal)n;
PetscCall(VecShift(u, avalue));
/* Create and assemble matrix */
PetscCall(MatCreate(PETSC_COMM_WORLD, &A));
PetscCall(MatSetSizes(A, PETSC_DECIDE, PETSC_DECIDE, n, n));
PetscCall(MatSetFromOptions(A));
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;
value[1] = 1.0;
PetscCall(MatSetValues(A, 1, &i, 2, col, value, INSERT_VALUES));
i = 0;
col[0] = 0;
col[1] = 1;
value[0] = 1.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(MatMult(A, u, b));
/* Create KSP context; set operators and options; solve linear system */
PetscCall(KSPCreate(PETSC_COMM_WORLD, &ksp));
PetscCall(KSPSetOperators(ksp, A, A));
/* Insure that preconditioner has same null space as matrix */
/* currently does not do anything */
PetscCall(KSPGetPC(ksp, &pc));
PetscCall(KSPSetFromOptions(ksp));
PetscCall(KSPSolve(ksp, b, x));
/* PetscCall(KSPView(ksp,PETSC_VIEWER_STDOUT_WORLD)); */
/* Check error */
PetscCall(VecAXPY(x, none, u));
PetscCall(VecNorm(x, NORM_2, &norm));
PetscCall(KSPGetIterationNumber(ksp, &its));
PetscCall(PetscPrintf(PETSC_COMM_WORLD, "Norm of error %g, Iterations %" PetscInt_FMT "\n", (double)norm, its));
/* Free work space */
PetscCall(VecDestroy(&x));
PetscCall(VecDestroy(&u));
PetscCall(VecDestroy(&b));
PetscCall(MatDestroy(&A));
PetscCall(KSPDestroy(&ksp));
PetscCall(PetscFinalize());
return 0;
}
|
71503ca73f0f3358e4dbc5aa8f907973ab70cdf7
|
14ac14bee6ddd3f74937ff316b37cb947a4ef882
|
/RelationalOperators.c
|
25b333f4dd94249b1c3b6805f086646bcb4d2727
|
[
"MIT"
] |
permissive
|
gouravthakur39/beginners-C-program-examples
|
ebe18c68c9b889d0622dc4d45ee0584e63a98d7c
|
373d27c131e35bacdbf5c500f79fd234c6d4ec9b
|
refs/heads/master
| 2023-09-02T16:15:01.129754
| 2022-07-08T11:50:46
| 2022-07-08T11:50:46
| 150,301,917
| 498
| 403
|
MIT
| 2023-08-07T16:11:02
| 2018-09-25T17:12:58
|
C
|
UTF-8
|
C
| false
| false
| 1,024
|
c
|
RelationalOperators.c
|
// Relational operators in c language
#include<stdio.h>
int main()
{
int a, b;
printf("Enter two numbers a and b respectively\n");
scanf("%d%d",&a,&b);
// Greater than operator
if (a>b)
printf("a is greater than b\n");
else
printf("a is smaller than b\n");
// Greater than equal to
if (a>=b)
printf("a is greater than equal to b\n");
else
printf("a is not greater than equal to b\n");
//Less than
if (a<b)
printf("a is less than b\n");
else
printf("a is greater than b\n");
//Lesser than equal to
if (a<=b)
printf("a is less than equal to b\n");
else
printf("a is greater than equal to b\n");
//equal to
if (a==b)
printf("a is equal to b\n");
else
printf("a is not equal to b\n");
//not equal to
if (a!=b)
printf("a is not equal to b\n");
else
printf("a is equal to b\n");
return 0;
}
|
442ce12840cc7a99972c08c8d22178753ccb66bb
|
99bdb3251fecee538e0630f15f6574054dfc1468
|
/bsp/stm32/stm32f429-atk-apollo/board/ports/audio/drv_wm8978.c
|
0f650538f993a6573332bf6f95ded310d0bf1edb
|
[
"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
| 37,438
|
c
|
drv_wm8978.c
|
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2018-11-14 ZeroFree first implementation
* 2019-07-28 Ernest perfect player, add record funciton and other APIs
*/
#include <rtthread.h>
#include <rtdevice.h>
#include "drv_wm8978.h"
#include <stdlib.h>
/* Register Definitions */
#define REG_SOFTWARE_RESET ((uint16_t)0)
#define REG_POWER_MANAGEMENT1 ((uint16_t)(1 << 9))
#define REG_POWER_MANAGEMENT2 ((uint16_t)(2 << 9))
#define REG_POWER_MANAGEMENT3 ((uint16_t)(3 << 9))
#define REG_AUDIO_INTERFACE ((uint16_t)(4 << 9))
#define REG_COMPANDING ((uint16_t)(5 << 9))
#define REG_CLOCK_GEN ((uint16_t)(6 << 9))
#define REG_ADDITIONAL ((uint16_t)(7 << 9))
#define REG_GPIO ((uint16_t)(8 << 9))
#define REG_JACK_DETECT1 ((uint16_t)(9 << 9))
#define REG_DAC ((uint16_t)(10 << 9))
#define REG_LEFT_DAC_VOL ((uint16_t)(11 << 9))
#define REG_RIGHT_DAC_VOL ((uint16_t)(12 << 9))
#define REG_JACK_DETECT2 ((uint16_t)(13 << 9))
#define REG_ADC ((uint16_t)(14 << 9))
#define REG_LEFT_ADC_VOL ((uint16_t)(15 << 9))
#define REG_RIGHT_ADC_VOL ((uint16_t)(16 << 9))
#define REG_EQ1 ((uint16_t)(18 << 9))
#define REG_EQ2 ((uint16_t)(19 << 9))
#define REG_EQ3 ((uint16_t)(20 << 9))
#define REG_EQ4 ((uint16_t)(21 << 9))
#define REG_EQ5 ((uint16_t)(22 << 9))
#define REG_DAC_LIMITER1 ((uint16_t)(24 << 9))
#define REG_DAC_LIMITER2 ((uint16_t)(25 << 9))
#define REG_NOTCH_FILTER1 ((uint16_t)(27 << 9))
#define REG_NOTCH_FILTER2 ((uint16_t)(28 << 9))
#define REG_NOTCH_FILTER3 ((uint16_t)(29 << 9))
#define REG_NOTCH_FILTER4 ((uint16_t)(30 << 9))
#define REG_ALC1 ((uint16_t)(32 << 9))
#define REG_ALC2 ((uint16_t)(33 << 9))
#define REG_ALC3 ((uint16_t)(34 << 9))
#define REG_NOISE_GATE ((uint16_t)(35 << 9))
#define REG_PLL_N ((uint16_t)(36 << 9))
#define REG_PLL_K1 ((uint16_t)(37 << 9))
#define REG_PLL_K2 ((uint16_t)(38 << 9))
#define REG_PLL_K3 ((uint16_t)(39 << 9))
#define REG_3D ((uint16_t)(41 << 9))
#define REG_BEEP ((uint16_t)(43 << 9))
#define REG_INPUT ((uint16_t)(44 << 9))
#define REG_LEFT_PGA_GAIN ((uint16_t)(45 << 9))
#define REG_RIGHT_PGA_GAIN ((uint16_t)(46 << 9))
#define REG_LEFT_ADC_BOOST ((uint16_t)(47 << 9))
#define REG_RIGHT_ADC_BOOST ((uint16_t)(48 << 9))
#define REG_OUTPUT ((uint16_t)(49 << 9))
#define REG_LEFT_MIXER ((uint16_t)(50 << 9))
#define REG_RIGHT_MIXER ((uint16_t)(51 << 9))
#define REG_LOUT1_VOL ((uint16_t)(52 << 9))
#define REG_ROUT1_VOL ((uint16_t)(53 << 9))
#define REG_LOUT2_VOL ((uint16_t)(54 << 9))
#define REG_ROUT2_VOL ((uint16_t)(55 << 9))
#define REG_OUT3_MIXER ((uint16_t)(56 << 9))
#define REG_OUT4_MIXER ((uint16_t)(57 << 9))
// R01 REG_POWER_MANAGEMENT1
#define BUFDCOPEN (1 << 8)
#define OUT4MIXEN (1 << 7)
#define OUT3MIXEN (1 << 6)
#define PLLEN (1 << 5)
#define MICBEN (1 << 4)
#define BIASEN (1 << 3)
#define BUFIOEN (1 << 2)
#define VMIDSEL_OFF (0)
#define VMIDSEL_75K (1)
#define VMIDSEL_300K (2)
#define VMIDSEL_5K (3)
// R02 REG_POWER_MANAGEMENT2
#define ROUT1EN (1 << 8)
#define LOUT1EN (1 << 7)
#define SLEEP (1 << 6)
#define BOOSTENR (1 << 5)
#define BOOSTENL (1 << 4)
#define INPPGAENR (1 << 3)
#define INPPGAENL (1 << 2)
#define ADCENR (1 << 1)
#define ADCENL (1)
// R03 REG_POWER_MANAGEMENT3
#define OUT4EN (1 << 8)
#define OUT3EN (1 << 7)
#define LOUT2EN (1 << 6)
#define ROUT2EN (1 << 5)
#define RMIXEN (1 << 3)
#define LMIXEN (1 << 2)
#define DACENR (1 << 1)
#define DACENL (1)
// R04 REG_AUDIO_INTERFACE
#define BCP_NORMAL (0)
#define BCP_INVERTED (1 << 8)
#define LRP_NORMAL (0)
#define LRP_INVERTED (1 << 7)
#define WL_16BITS (0)
#define WL_20BITS (1 << 5)
#define WL_24BITS (2 << 5) // Default value
#define WL_32BITS (3 << 5)
#define FMT_RIGHT_JUSTIFIED (0)
#define FMT_LEFT_JUSTIFIED (1 << 3)
#define FMT_I2S (2 << 3) // Default value
#define FMT_PCM (3 << 3)
#define DACLRSWAP (1 << 2)
#define ADCLRSWAP (1 << 1)
#define MONO (1)
// R05 REG_COMPANDING
#define WL8 (1 << 5)
#define DAC_COMP_OFF (0) // Default value
#define DAC_COMP_ULAW (2 << 3)
#define DAC_COMP_ALAW (3 << 3)
#define ADC_COMP_OFF (0) // Default value
#define ADC_COMP_ULAW (2 << 1)
#define ADC_COMP_ALAW (3 << 1)
#define LOOPBACK (1)
// R06 REG_CLOCK_GEN
#define CLKSEL_MCLK (0)
#define CLKSEL_PLL (1 << 8) // Default value
#define MCLK_DIV1 (0)
#define MCLK_DIV1_5 (1 << 5)
#define MCLK_DIV2 (2 << 5) // Default value
#define MCLK_DIV3 (3 << 5)
#define MCLK_DIV4 (4 << 5)
#define MCLK_DIV6 (5 << 5)
#define MCLK_DIV8 (6 << 5)
#define MCLK_DIV12 (7 << 5)
#define BCLK_DIV1 (0) // Default value
#define BCLK_DIV2 (1 << 2)
#define BCLK_DIV4 (2 << 2)
#define BCLK_DIV8 (3 << 2)
#define BCLK_DIV16 (4 << 2)
#define BCLK_DIV32 (5 << 2)
#define MS (1)
// R07 REG_ADDITIONAL
#define WM_SR_48KHZ (0) // Default value
#define WM_SR_32KHZ (1 << 1)
#define WM_SR_24KHZ (2 << 1)
#define WM_SR_16KHZ (3 << 1)
#define WM_SR_12KHZ (4 << 1)
#define WM_SR_8KHZ (5 << 1)
#define SLOWCLKEN (1)
// R08 REG_GPIO
#define OPCLK_DIV1 (0) // Default value
#define OPCLK_DIV2 (1 << 4)
#define OPCLK_DIV3 (2 << 4)
#define OPCLK_DIV4 (3 << 4)
#define GPIO1POL_NONINVERTED (0) // Default value
#define GPIO1POL_INVERTED (1 << 3)
#define GPIO1SEL_INPUT (0) // Default value
#define GPIO1SEL_TEMP_OK (2)
#define GPIO1SEL_AMUTE_ACTIVE (3)
#define GPIO1SEL_PLL_CLK_OP (4)
#define GPIO1SEL_PLL_LOCK (5)
#define GPIO1SEL_LOGIC1 (6)
#define GPIO1SEL_LOGIC0 (7)
// R09 REG_JACK_DETECT1
#define JD_VMID_EN1 (1 << 8)
#define JD_VMID_EN0 (1 << 7)
#define JD_EN (1 << 6)
#define JD_SEL_GPIO1 (0 << 4) // Default value
#define JD_SEL_GPIO2 (1 << 4)
#define JD_SEL_GPIO3 (2 << 4)
// R10 REG_DAC
#define SOFTMUTE (1 << 6)
#define DACOSR128 (1 << 3)
#define AMUTE (1 << 2)
#define DACPOLR (1 << 1)
#define DACPOLL (1)
// R11 & R12 REG_LEFT_DAC_VOL & REG_RIGHT_DAC_VOL
#define DACVU (1 << 8)
#define DACVOL_POS (0)
#define DACVOL_MASK (0xFF)
// R13 REG_JACK_DETECT2
#define JD_OUT4_EN1 (1 << 7)
#define JD_OUT3_EN1 (1 << 6)
#define JD_OUT2_EN1 (1 << 5)
#define JD_OUT1_EN1 (1 << 4)
#define JD_OUT4_EN0 (1 << 3)
#define JD_OUT3_EN0 (1 << 2)
#define JD_OUT2_EN0 (1 << 1)
#define JD_OUT1_EN0 (1)
// R14 REG_ADC
#define HPFEN (1 << 8)
#define HPFAPP (1 << 7)
#define HPFCUT_POS (4)
#define HPFCUT_MASK (7)
#define HPFCUT_0 (0)
#define HPFCUT_1 (1 << 4)
#define HPFCUT_2 (2 << 4)
#define HPFCUT_3 (3 << 4)
#define HPFCUT_4 (4 << 4)
#define HPFCUT_5 (5 << 4)
#define HPFCUT_6 (6 << 4)
#define HPFCUT_7 (7 << 4)
#define ADCOSR128 (1 << 3)
#define ADCRPOL (1 << 1)
#define ADCLPOL (1)
// R15 & R16 REG_LEFT_ADC_VOL & REG_RIGHT_ADC_VOL
#define ADCVU (1 << 8)
#define ADCVOL_POS (0)
#define ADCVOL_MASK (0xFF)
// R18 REG_EQ1
#define EQ3DMODE_ADC (0)
#define EQ3DMODE_DAC (1 << 8) // Default value
#define EQ1C_80HZ (0)
#define EQ1C_105HZ (1 << 5) // Default value
#define EQ1C_135HZ (2 << 5)
#define EQ1C_175HZ (3 << 5)
// R19 REG_EQ2
#define EQ2BW_NARROW (0) // Default value
#define EQ2BW_WIDE (1 << 8)
#define EQ2C_230HZ (0)
#define EQ2C_300HZ (1 << 5) // Default value
#define EQ2C_385HZ (2 << 5)
#define EQ2C_500HZ (3 << 5)
// R20 REG_EQ3
#define EQ3BW_NARROW (0) // Default value
#define EQ3BW_WIDE (1 << 8)
#define EQ3C_650HZ (0)
#define EQ3C_850HZ (1 << 5) // Default value
#define EQ3C_1_1KHZ (2 << 5)
#define EQ3C_1_4KHZ (3 << 5)
// R21 REG_EQ4
#define EQ4BW_NARROW (0) // Default value
#define EQ4BW_WIDE (1 << 8)
#define EQ4C_1_8KHZ (0)
#define EQ4C_2_4KHZ (1 << 5) // Default value
#define EQ4C_3_2KHZ (2 << 5)
#define EQ4C_4_1KHZ (3 << 5)
// R22 REG_EQ5
#define EQ5C_5_3KHZ (0)
#define EQ5C_6_9KHZ (1 << 5) // Default value
#define EQ5C_9KHZ (2 << 5)
#define EQ5C_11_7KHZ (3 << 5)
// R18 - R22
#define EQC_POS (5)
#define EQC_MASK (3)
#define EQG_POS (0)
#define EQG_MASK (31)
// R24 REG_DAC_LIMITER1
#define LIMEN (1 << 8)
#define LIMDCY_POS (4)
#define LIMDCY_MASK (15)
#define LIMDCY_750US (0)
#define LIMDCY_1_5MS (1 << 4)
#define LIMDCY_3MS (2 << 4)
#define LIMDCY_6MS (3 << 4) // Default value
#define LIMDCY_12MS (4 << 4)
#define LIMDCY_24MS (5 << 4)
#define LIMDCY_48MS (6 << 4)
#define LIMDCY_96MS (7 << 4)
#define LIMDCY_192MS (8 << 4)
#define LIMDCY_384MS (9 << 4)
#define LIMDCY_768MS (10 << 4)
#define LIMATK_POS (0)
#define LIMATK_MASK (15)
#define LIMATK_94US (0)
#define LIMATK_188US (1)
#define LIMATK_375US (2) // Default value
#define LIMATK_750US (3)
#define LIMATK_1_5MS (4)
#define LIMATK_3MS (5)
#define LIMATK_6MS (6)
#define LIMATK_12MS (7)
#define LIMATK_24MS (8)
#define LIMATK_48MS (9)
#define LIMATK_96MS (10)
#define LIMATK_192MS (11)
// R25 REG_DAC_LIMITER2
#define LIMLVL_POS (4)
#define LIMLVL_MASK (7)
#define LIMLVL_N1DB (0) // Default value
#define LIMLVL_N2DB (1 << 4)
#define LIMLVL_N3DB (2 << 4)
#define LIMLVL_N4DB (3 << 4)
#define LIMLVL_N5DB (4 << 4)
#define LIMLVL_N6DB (5 << 4)
#define LIMBOOST_POS (0)
#define LIMBOOST_MASK (15)
#define LIMBOOST_0DB (0)
#define LIMBOOST_1DB (1)
#define LIMBOOST_2DB (2)
#define LIMBOOST_3DB (3)
#define LIMBOOST_4DB (4)
#define LIMBOOST_5DB (5)
#define LIMBOOST_6DB (6)
#define LIMBOOST_7DB (7)
#define LIMBOOST_8DB (8)
#define LIMBOOST_9DB (9)
#define LIMBOOST_10DB (10)
#define LIMBOOST_11DB (11)
#define LIMBOOST_12DB (12)
// R27 - R30 REG_NOTCH_FILTER1 - REG_NOTCH_FILTER4
#define NFU (1 << 8)
#define NFEN (1 << 7)
#define NFA_POS (0)
#define NFA_MASK (127)
// R32 REG_ALC1
#define ALCSEL_OFF (0) // Default value
#define ALCSEL_RIGHT_ONLY (1 << 7)
#define ALCSEL_LEFT_ONLY (2 << 7)
#define ALCSEL_BOTH_ON (3 << 7)
#define ALCMAXGAIN_POS (3)
#define ALCMAXGAIN_MASK (7)
#define ALCMAXGAIN_N6_75DB (0)
#define ALCMAXGAIN_N0_75DB (1 << 3)
#define ALCMAXGAIN_5_25DB (2 << 3)
#define ALCMAXGAIN_11_25DB (3 << 3)
#define ALCMAXGAIN_17_25DB (4 << 3)
#define ALCMAXGAIN_23_25DB (5 << 3)
#define ALCMAXGAIN_29_25DB (6 << 3)
#define ALCMAXGAIN_35_25DB (7 << 3) // Default value
#define ALCMINGAIN_POS (0)
#define ALCMINGAIN_MASK (7)
#define ALCMINGAIN_N12DB (0) // Default value
#define ALCMINGAIN_N6DB (1)
#define ALCMINGAIN_0DB (2)
#define ALCMINGAIN_6DB (3)
#define ALCMINGAIN_12DB (4)
#define ALCMINGAIN_18DB (5)
#define ALCMINGAIN_24DB (6)
#define ALCMINGAIN_30DB (7)
// R33 REG_ALC2
#define ALCHLD_POS (4)
#define ALCHLD_MASK (15)
#define ALCHLD_0MS (0) // Default value
#define ALCHLD_2_67MS (1 << 4)
#define ALCHLD_5_33MS (2 << 4)
#define ALCHLD_10_67MS (3 << 4)
#define ALCHLD_21_33MS (4 << 4)
#define ALCHLD_42_67MS (5 << 4)
#define ALCHLD_85_33MS (6 << 4)
#define ALCHLD_170_67MS (7 << 4)
#define ALCHLD_341_33MS (8 << 4)
#define ALCHLD_682_67MS (9 << 4)
#define ALCHLD_1_36S (10 << 4)
#define ALCLVL_POS (0)
#define ALCLVL_MASK (15)
#define ALCLVL_N22_5DBFS (0)
#define ALCLVL_N21DBFS (1)
#define ALCLVL_N19_5DBFS (2)
#define ALCLVL_N18DBFS (3)
#define ALCLVL_N16_5DBFS (4)
#define ALCLVL_N15DBFS (5)
#define ALCLVL_N13_5DBFS (6)
#define ALCLVL_N12DBFS (7)
#define ALCLVL_N10_5DBFS (8)
#define ALCLVL_N9DBFS (9)
#define ALCLVL_N7_5DBFS (10)
#define ALCLVL_N6DBFS (11) // Default value
#define ALCLVL_N4_5DBFS (12)
#define ALCLVL_N3DBFS (13)
#define ALCLVL_N1_5DBFS (14)
// R34 REG_ALC3
#define ALCMODE_ALC (0) // Default value
#define ALCMODE_LIMITER (1 << 8)
#define ALCDCY_POS (4)
#define ALCDCY_MASK (15)
#define ALCDCY_0 (0)
#define ALCDCY_1 (1 << 4)
#define ALCDCY_2 (2 << 4)
#define ALCDCY_3 (3 << 4) // Default value
#define ALCDCY_4 (4 << 4)
#define ALCDCY_5 (5 << 4)
#define ALCDCY_6 (6 << 4)
#define ALCDCY_7 (7 << 4)
#define ALCDCY_8 (8 << 4)
#define ALCDCY_9 (9 << 4)
#define ALCDCY_10 (10 << 4)
#define ALCATK_POS (0)
#define ALCATK_MASK (15)
#define ALCATK_0 (0)
#define ALCATK_1 (1)
#define ALCATK_2 (2) // Default value
#define ALCATK_3 (3)
#define ALCATK_4 (4)
#define ALCATK_5 (5)
#define ALCATK_6 (6)
#define ALCATK_7 (7)
#define ALCATK_8 (8)
#define ALCATK_9 (9)
#define ALCATK_10 (10)
// R35 REG_NOISE_GATE
#define NGEN (1 << 3)
#define NGTH_POS (0)
#define NGTH_MASK (7)
#define NGTH_N39DB (0) // Default value
#define NGTH_N45DB (1)
#define NGTH_N51DB (2)
#define NGTH_N57DB (3)
#define NGTH_N63DB (4)
#define NGTH_N69DB (5)
#define NGTH_N75DB (6)
#define NGTH_N81DB (7)
// R36 REG_PLL_N
#define PLLPRESCALE (1 << 4)
#define PLLN_POS (0)
#define PLLN_MASK (15)
// R37 - R39 REG_PLL_K1 - REG_PLL_K3
#define PLLK1_POS (0)
#define PLLK1_MASK (63)
#define PLLK2_POS (0)
#define PLLK2_MASK (511)
#define PLLK3_POS (0)
#define PLLK3_MASK (511)
// R41 REG_3D
#define DEPTH3D_POS (0)
#define DEPTH3D_MASK (15)
#define DEPTH3D_0 (0) // Default value
#define DEPTH3D_6_67 (1)
#define DEPTH3D_13_33 (2)
#define DEPTH3D_20 (3)
#define DEPTH3D_26_67 (4)
#define DEPTH3D_33_33 (5)
#define DEPTH3D_40 (6)
#define DEPTH3D_46_67 (7)
#define DEPTH3D_53_33 (8)
#define DEPTH3D_60 (9)
#define DEPTH3D_66_67 (10)
#define DEPTH3D_73_33 (11)
#define DEPTH3D_80 (12)
#define DEPTH3D_86_67 (13)
#define DEPTH3D_93_33 (14)
#define DEPTH3D_100 (15)
// R43 REG_BEEP
#define MUTERPGA2INV (1 << 5)
#define INVROUT2 (1 << 4)
#define BEEPVOL_POS (1)
#define BEEPVOL_MASK (7)
#define BEEPVOL_N15DB (0)
#define BEEPVOL_N12DB (1 << 1)
#define BEEPVOL_N9DB (2 << 1)
#define BEEPVOL_N6DB (3 << 1)
#define BEEPVOL_N3DB (4 << 1)
#define BEEPVOL_0DB (5 << 1)
#define BEEPVOL_3DB (6 << 1)
#define BEEPVOL_6DB (7 << 1)
#define BEEPEN (1)
// R44 REG_INPUT
#define MBVSEL_0_9AVDD (0) // Default value
#define MBVSEL_0_65AVDD (1 << 8)
#define R2_2INPVGA (1 << 6)
#define RIN2INPVGA (1 << 5) // Default value
#define RIP2INPVGA (1 << 4) // Default value
#define L2_2INPVGA (1 << 2)
#define LIN2INPVGA (1 << 1) // Default value
#define LIP2INPVGA (1) // Default value
// R45 REG_LEFT_PGA_GAIN
#define INPPGAUPDATE (1 << 8)
#define INPPGAZCL (1 << 7)
#define INPPGAMUTEL (1 << 6)
// R46 REG_RIGHT_PGA_GAIN
#define INPPGAZCR (1 << 7)
#define INPPGAMUTER (1 << 6)
// R45 - R46
#define INPPGAVOL_POS (0)
#define INPPGAVOL_MASK (63)
// R47 REG_LEFT_ADC_BOOST
#define PGABOOSTL (1 << 8) // Default value
#define L2_2BOOSTVOL_POS (4)
#define L2_2BOOSTVOL_MASK (7)
#define L2_2BOOSTVOL_DISABLED (0) // Default value
#define L2_2BOOSTVOL_N12DB (1 << 4)
#define L2_2BOOSTVOL_N9DB (2 << 4)
#define L2_2BOOSTVOL_N6DB (3 << 4)
#define L2_2BOOSTVOL_N3DB (4 << 4)
#define L2_2BOOSTVOL_0DB (5 << 4)
#define L2_2BOOSTVOL_3DB (6 << 4)
#define L2_2BOOSTVOL_6DB (7 << 4)
#define AUXL2BOOSTVOL_POS (0)
#define AUXL2BOOSTVOL_MASK (7)
#define AUXL2BOOSTVOL_DISABLED (0) // Default value
#define AUXL2BOOSTVOL_N12DB (1)
#define AUXL2BOOSTVOL_N9DB (2)
#define AUXL2BOOSTVOL_N6DB (3)
#define AUXL2BOOSTVOL_N3DB (4)
#define AUXL2BOOSTVOL_0DB (5)
#define AUXL2BOOSTVOL_3DB (6)
#define AUXL2BOOSTVOL_6DB (7)
// R48 REG_RIGHT_ADC_BOOST
#define PGABOOSTR (1 << 8) // Default value
#define R2_2BOOSTVOL_POS (4)
#define R2_2BOOSTVOL_MASK (7)
#define R2_2BOOSTVOL_DISABLED (0) // Default value
#define R2_2BOOSTVOL_N12DB (1 << 4)
#define R2_2BOOSTVOL_N9DB (2 << 4)
#define R2_2BOOSTVOL_N6DB (3 << 4)
#define R2_2BOOSTVOL_N3DB (4 << 4)
#define R2_2BOOSTVOL_0DB (5 << 4)
#define R2_2BOOSTVOL_3DB (6 << 4)
#define R2_2BOOSTVOL_6DB (7 << 4)
#define AUXR2BOOSTVOL_POS (0)
#define AUXR2BOOSTVOL_MASK (7)
#define AUXR2BOOSTVOL_DISABLED (0) // Default value
#define AUXR2BOOSTVOL_N12DB (1)
#define AUXR2BOOSTVOL_N9DB (2)
#define AUXR2BOOSTVOL_N6DB (3)
#define AUXR2BOOSTVOL_N3DB (4)
#define AUXR2BOOSTVOL_0DB (5)
#define AUXR2BOOSTVOL_3DB (6)
#define AUXR2BOOSTVOL_6DB (7)
// R49 REG_OUTPUT
#define DACL2RMIX (1 << 6)
#define DACR2LMIX (1 << 5)
#define OUT4BOOST (1 << 4)
#define OUT3BOOST (1 << 3)
#define SPKBOOST (1 << 2)
#define TSDEN (1 << 1)
#define VROI (1)
// R50 REG_LEFT_MIXER
#define AUXLMIXVOL_POS (6)
#define AUXLMIXVOL_MASK (7)
#define AUXLMIXVOL_N15DB (0) // Default value
#define AUXLMIXVOL_N12DB (1 << 6)
#define AUXLMIXVOL_N9DB (2 << 6)
#define AUXLMIXVOL_N6DB (3 << 6)
#define AUXLMIXVOL_N3DB (4 << 6)
#define AUXLMIXVOL_0DB (5 << 6)
#define AUXLMIXVOL_3DB (6 << 6)
#define AUXLMIXVOL_6DB (7 << 6)
#define AUXL2LMIX (1 << 5)
#define BYPLMIXVOL_POS (2)
#define BYPLMIXVOL_MASK (7)
#define BYPLMIXVOL_N15DB (0) // Default value
#define BYPLMIXVOL_N12DB (1 << 2)
#define BYPLMIXVOL_N9DB (2 << 2)
#define BYPLMIXVOL_N6DB (3 << 2)
#define BYPLMIXVOL_N3DB (4 << 2)
#define BYPLMIXVOL_0DB (5 << 2)
#define BYPLMIXVOL_3DB (6 << 2)
#define BYPLMIXVOL_6DB (7 << 2)
#define BYPL2LMIX (1 << 1)
#define DACL2LMIX (1)
// R51 REG_RIGHT_MIXER
#define AUXRMIXVOL_POS (6)
#define AUXRMIXVOL_MASK (7)
#define AUXRMIXVOL_N15DB (0) // Default value
#define AUXRMIXVOL_N12DB (1 << 6)
#define AUXRMIXVOL_N9DB (2 << 6)
#define AUXRMIXVOL_N6DB (3 << 6)
#define AUXRMIXVOL_N3DB (4 << 6)
#define AUXRMIXVOL_0DB (5 << 6)
#define AUXRMIXVOL_3DB (6 << 6)
#define AUXRMIXVOL_6DB (7 << 6)
#define AUXR2RMIX (1 << 5)
#define BYPRMIXVOL_POS (2)
#define BYPRMIXVOL_MASK (7)
#define BYPRMIXVOL_N15DB (0) // Default value
#define BYPRMIXVOL_N12DB (1 << 2)
#define BYPRMIXVOL_N9DB (2 << 2)
#define BYPRMIXVOL_N6DB (3 << 2)
#define BYPRMIXVOL_N3DB (4 << 2)
#define BYPRMIXVOL_0DB (5 << 2)
#define BYPRMIXVOL_3DB (6 << 2)
#define BYPRMIXVOL_6DB (7 << 2)
#define BYPR2RMIX (1 << 1)
#define DACR2RMIX (1)
// R52 - R55 REG_LOUT1_VOL - REG_ROUT2_VOL
#define HPVU (1 << 8)
#define SPKVU (1 << 8)
#define LOUT1ZC (1 << 7)
#define LOUT1MUTE (1 << 6)
#define ROUT1ZC (1 << 7)
#define ROUT1MUTE (1 << 6)
#define LOUT2ZC (1 << 7)
#define LOUT2MUTE (1 << 6)
#define ROUT2ZC (1 << 7)
#define ROUT2MUTE (1 << 6)
#define VOL_POS (0)
#define VOL_MASK (63)
// R56 REG_OUT3_MIXER
#define OUT3MUTE (1 << 6)
#define OUT4_2OUT3 (1 << 3)
#define BYPL2OUT3 (1 << 2)
#define LMIX2OUT3 (1 << 1)
#define LDAC2OUT3 (1)
// R57 REG_OUT4_MIXER
#define OUT4MUTE (1 << 6)
#define HALFSIG (1 << 5)
#define LMIX2OUT4 (1 << 4)
#define LDAC2OUT4 (1 << 3)
#define BYPR2OUT4 (1 << 2)
#define RMIX2OUT4 (1 << 1)
#define RDAC2OUT4 (1)
static rt_uint16_t wm8978_regval_tbl[58] =
{
0X0000, 0X0000, 0X0000, 0X0000, 0X0050, 0X0000, 0X0140, 0X0000,
0X0000, 0X0000, 0X0000, 0X00FF, 0X00FF, 0X0000, 0X0100, 0X00FF,
0X00FF, 0X0000, 0X012C, 0X002C, 0X002C, 0X002C, 0X002C, 0X0000,
0X0032, 0X0000, 0X0000, 0X0000, 0X0000, 0X0000, 0X0000, 0X0000,
0X0038, 0X000B, 0X0032, 0X0000, 0X0008, 0X000C, 0X0093, 0X00E9,
0X0000, 0X0000, 0X0000, 0X0000, 0X0003, 0X0010, 0X0010, 0X0100,
0X0100, 0X0002, 0X0001, 0X0001, 0X0039, 0X0039, 0X0039, 0X0039,
0X0001, 0X0001
};
static void wm8978_write_reg(struct rt_i2c_bus_device *dev, rt_uint16_t s_data)
{
struct rt_i2c_msg msg;
rt_uint8_t send_buffer[2];
RT_ASSERT(dev != RT_NULL);
/* store temp */
wm8978_regval_tbl[s_data >> 9] = s_data & 0x1FF;
send_buffer[0] = (rt_uint8_t)(s_data >> 8);
send_buffer[1] = (rt_uint8_t)(s_data);
msg.addr = 0x1A;
msg.flags = RT_I2C_WR;
msg.len = 2;
msg.buf = send_buffer;
rt_i2c_transfer(dev, &msg, 1);
}
static rt_uint16_t wm8978_read_reg(struct rt_i2c_bus_device *dev, rt_uint16_t reg)
{
return wm8978_regval_tbl[reg >> 9];
}
/**
* @brief Init WM8978 Codec device.
* @param dev: I2C device handle
* @retval RT_EOK if correct communication, else wrong communication
*/
void wm8978_player_start(struct rt_i2c_bus_device *dev)
{
wm8978_reset(dev);
/* 1.5x boost power up sequence,Mute all outputs. */
wm8978_write_reg(dev, REG_LOUT1_VOL | LOUT1MUTE);
wm8978_write_reg(dev, REG_ROUT1_VOL | ROUT1MUTE);
wm8978_write_reg(dev, REG_LOUT2_VOL | LOUT2MUTE);
wm8978_write_reg(dev, REG_ROUT2_VOL | ROUT2MUTE);
/* Enable unused output chosen from L/ROUT2, OUT3 or OUT4. */
wm8978_write_reg(dev, REG_POWER_MANAGEMENT3 | OUT4EN);
/* Set BUFDCOPEN=1, BIASEN=1 and BUFIOEN=1 in register R1 */
wm8978_write_reg(dev, REG_POWER_MANAGEMENT1 | BUFDCOPEN | BUFIOEN | BIASEN);
/* Set SPKBOOST=1 in register R49. */
wm8978_write_reg(dev, REG_OUTPUT | SPKBOOST);
/* Set VMIDSEL[1:0] to required value in register R1. */
wm8978_write_reg(dev, REG_POWER_MANAGEMENT1 | BUFDCOPEN | BUFIOEN | VMIDSEL_75K);
/* Set L/RMIXEN=1 and DACENL/R=1 in register R3.*/
wm8978_write_reg(dev, REG_POWER_MANAGEMENT3 | LMIXEN | RMIXEN | DACENL | DACENR);
/* Set BIASEN=1 in register R1. */
wm8978_write_reg(dev, REG_POWER_MANAGEMENT1 | BUFDCOPEN | BUFIOEN | VMIDSEL_75K);
/* Set L/ROUT2EN=1 in register R3. */
wm8978_write_reg(dev, REG_POWER_MANAGEMENT3 | LMIXEN | RMIXEN | DACENL | DACENR | LOUT2EN | ROUT2EN);
/* Enable other outputs as required. */
wm8978_write_reg(dev, REG_POWER_MANAGEMENT2 | LOUT1EN | ROUT1EN | BOOSTENL | BOOSTENR | INPPGAENL | INPPGAENR);
wm8978_write_reg(dev, REG_POWER_MANAGEMENT2 | LOUT1EN | ROUT1EN | BOOSTENL | BOOSTENR | INPPGAENL | INPPGAENR | ADCENL | ADCENR);
/* Digital inferface setup. */
wm8978_write_reg(dev, REG_AUDIO_INTERFACE | BCP_NORMAL | LRP_NORMAL | WL_16BITS | FMT_I2S);
wm8978_write_reg(dev, REG_ADDITIONAL | WM_SR_8KHZ);
wm8978_write_reg(dev, REG_POWER_MANAGEMENT1 | BUFDCOPEN | BUFIOEN | VMIDSEL_75K | MICBEN | BIASEN);
wm8978_write_reg(dev, REG_CLOCK_GEN | CLKSEL_MCLK | MCLK_DIV1);
/* Enable DAC 128x oversampling. */
wm8978_write_reg(dev, REG_DAC | DACOSR128);
/* Set LOUT2/ROUT2 in BTL operation. */
wm8978_write_reg(dev, REG_BEEP | INVROUT2);
wm8978_DAC_enabled(dev, 1);
/* Set output volume. */
wm8978_set_volume(dev, 50);
}
void wm8978_record_start(struct rt_i2c_bus_device *dev)
{
wm8978_write_reg(dev, REG_POWER_MANAGEMENT1 | MICBEN | BIASEN | VMIDSEL_5K);
wm8978_write_reg(dev, REG_POWER_MANAGEMENT2 | ROUT1EN | LOUT1EN | BOOSTENR | BOOSTENL);
wm8978_write_reg(dev, REG_POWER_MANAGEMENT3 | LOUT2EN | ROUT2EN | RMIXEN | LMIXEN);
/* mclk be supplied by outside */
wm8978_write_reg(dev, REG_CLOCK_GEN);
wm8978_write_reg(dev, (REG_BEEP | BEEPVOL_N3DB));
wm8978_write_reg(dev, (REG_LEFT_ADC_BOOST | PGABOOSTL));
wm8978_write_reg(dev, (REG_RIGHT_ADC_BOOST | PGABOOSTR));
wm8978_write_reg(dev, (REG_OUTPUT | TSDEN | SPKBOOST));
wm8978_write_reg(dev, (REG_DAC | RMIXEN));
wm8978_write_reg(dev, (REG_ADC | ADCOSR128));
wm8978_ADC_enabled(dev, 1);
wm8978_DAC_enabled(dev, 0);
wm8978_mic_enabled(dev, 1);
wm8978_linein_enabled(dev, 1);
wm8978_aux_enabled(dev, 0);
wm8978_output_set(dev, 0, 0);
wm8978_aux_gain(dev, 5);
wm8978_mic_gain(dev, 50);
}
rt_err_t wm8978_init(struct rt_i2c_bus_device *dev)
{
wm8978_reset(dev);
wm8978_write_reg(dev, REG_POWER_MANAGEMENT1 | MICBEN | BIASEN | VMIDSEL_5K);
wm8978_write_reg(dev, REG_POWER_MANAGEMENT2 | ROUT1EN | LOUT1EN | BOOSTENR | BOOSTENL);
wm8978_write_reg(dev, REG_POWER_MANAGEMENT3 | LOUT2EN | ROUT2EN | RMIXEN | LMIXEN);
/* mclk be supplied by outside */
wm8978_write_reg(dev, REG_CLOCK_GEN);
wm8978_write_reg(dev, (REG_BEEP | BEEPVOL_N3DB));
wm8978_write_reg(dev, (REG_LEFT_ADC_BOOST | PGABOOSTL));
wm8978_write_reg(dev, (REG_RIGHT_ADC_BOOST | PGABOOSTR));
wm8978_write_reg(dev, (REG_OUTPUT | TSDEN | SPKBOOST));
wm8978_write_reg(dev, (REG_DAC | RMIXEN));
wm8978_write_reg(dev, (REG_ADC | ADCOSR128));
wm8978_interface_cfg(dev, I2S_FOMAT_SELECT, 16);
wm8978_mic_enabled(dev, 0);
return RT_EOK;
}
void wm8978_DAC_enabled(struct rt_i2c_bus_device *dev, rt_bool_t bool)
{
rt_uint16_t value;
value = wm8978_read_reg(dev, REG_POWER_MANAGEMENT3);
bool ? (value |= 3) : (value &= ~3);
wm8978_write_reg(dev, REG_POWER_MANAGEMENT3 | value);
}
void wm8978_ADC_enabled(struct rt_i2c_bus_device *dev, rt_bool_t bool)
{
rt_uint16_t value;
value = wm8978_read_reg(dev, REG_POWER_MANAGEMENT2);
bool ? (value |= 3) : (value &= ~3);
wm8978_write_reg(dev, REG_POWER_MANAGEMENT2 | value);
}
void wm8978_mic_enabled(struct rt_i2c_bus_device *dev, rt_bool_t bool)
{
rt_uint16_t value;
value = wm8978_read_reg(dev, REG_POWER_MANAGEMENT2);
bool ? (value |= 3 << 2) : (value &= ~(3 << 2));
wm8978_write_reg(dev, REG_POWER_MANAGEMENT2 | value);
value = wm8978_read_reg(dev, REG_INPUT);
bool ? (value |= 3 << 4 | 3) : (value &= ~(3 << 4 | 3));
wm8978_write_reg(dev, REG_INPUT | value);
}
void wm8978_linein_gain(struct rt_i2c_bus_device *dev, rt_uint8_t value)
{
rt_uint16_t regval;
value &= 0x7;
/* set left boost */
regval = wm8978_read_reg(dev, REG_LEFT_ADC_BOOST);
regval &= ~(7 << 4);
wm8978_write_reg(dev, REG_LEFT_ADC_BOOST | regval | value << 4);
/* set right boost */
regval = wm8978_read_reg(dev, REG_RIGHT_ADC_BOOST);
regval &= ~(7 << 4);
wm8978_write_reg(dev, REG_RIGHT_ADC_BOOST | regval | value << 4);
}
void wm8978_aux_gain(struct rt_i2c_bus_device *dev, rt_uint8_t value)
{
rt_uint16_t regval;
value &= 0x7;
/* set left boost */
regval = wm8978_read_reg(dev, REG_LEFT_ADC_BOOST);
regval &= ~(7 << 0);
wm8978_write_reg(dev, REG_LEFT_ADC_BOOST | regval | value << 0);
/* set right boost */
regval = wm8978_read_reg(dev, REG_RIGHT_ADC_BOOST);
regval &= ~(7 << 0);
wm8978_write_reg(dev, REG_RIGHT_ADC_BOOST | regval | value << 0);
}
void wm8978_mic_gain(struct rt_i2c_bus_device *dev, rt_uint8_t gain)
{
gain &= 0X3F;
wm8978_write_reg(dev, REG_LEFT_PGA_GAIN | gain);
wm8978_write_reg(dev, REG_RIGHT_PGA_GAIN | gain | 1 << 8);
}
void wm8978_linein_enabled(struct rt_i2c_bus_device *dev, rt_bool_t bool)
{
wm8978_linein_gain(dev, (bool ? L2_2BOOSTVOL_0DB : 0));
}
void wm8978_aux_enabled(struct rt_i2c_bus_device *dev, rt_bool_t bool)
{
wm8978_linein_gain(dev, (bool ? AUXL2BOOSTVOL_6DB : 0));
}
void wm8978_output_set(struct rt_i2c_bus_device *dev, rt_bool_t dacen, rt_bool_t bypass)
{
rt_uint16_t regval = 0;
if (dacen)
{
regval |= 1 << 0;
}
if (bypass)
{
regval |= 1 << 1;
regval |= 5 << 2;
}
wm8978_write_reg(dev, REG_LEFT_MIXER | regval);
wm8978_write_reg(dev, REG_RIGHT_MIXER | regval);
}
void wm8978_hpvol_set(struct rt_i2c_bus_device *dev, rt_uint8_t volume)
{
volume &= 0X3F;
if (volume == 0)
{
volume |= 1 << 6;//mute mode
}
wm8978_write_reg(dev, REG_LOUT1_VOL | volume);
wm8978_write_reg(dev, REG_ROUT1_VOL | volume | (1 << 8));
}
void wm8978_spkvol_set(struct rt_i2c_bus_device *dev, rt_uint8_t volume)
{
volume &= 0X3F;
if (volume == 0)
{
volume |= 1 << 6;//mute mode
}
wm8978_write_reg(dev, REG_LOUT2_VOL | volume);
wm8978_write_reg(dev, REG_ROUT2_VOL | volume | (1 << 8));
}
/**
* @brief Set WM8978 DAC volume level.
* @param dev: I2C device handle
* @param vol: volume level(0 ~ 99)
* @retval RT_EOK if correct communication, else wrong communication
*/
int wm8978_set_volume(struct rt_i2c_bus_device *dev, int vol)
{
vol = 63 * vol / 100;
vol = (vol & VOL_MASK) << VOL_POS;
wm8978_write_reg(dev, REG_LOUT1_VOL | vol);
wm8978_write_reg(dev, REG_ROUT1_VOL | HPVU | vol);
wm8978_write_reg(dev, REG_LOUT2_VOL | vol);
wm8978_write_reg(dev, REG_ROUT2_VOL | SPKVU | vol);
return RT_EOK;
}
void wm8978_interface_cfg(struct rt_i2c_bus_device *dev, enum data_fomat_select fmt, rt_uint32_t bitBand)
{
rt_uint16_t temp = 0;
switch (fmt)
{
case RIGHT_FOMAT_SELECT:
temp = FMT_RIGHT_JUSTIFIED;
break;
case LEFT_FOMAT_SELECT:
temp = FMT_LEFT_JUSTIFIED;
break;
case I2S_FOMAT_SELECT:
temp = FMT_I2S;
break;
case PCM_FOMAT_SELECT:
temp = FMT_PCM;
break;
default:
break;
}
switch (bitBand)
{
case 16:
temp |= WL_16BITS;
break;
case 20:
temp |= WL_20BITS;
break;
case 24:
temp |= WL_24BITS;
break;
case 32:
temp |= WL_32BITS;
break;
default:
break;
}
wm8978_write_reg(dev, REG_AUDIO_INTERFACE | temp);
}
void wm8978_reset(struct rt_i2c_bus_device *dev)
{
wm8978_write_reg(dev, REG_SOFTWARE_RESET);
}
void wm8978_mute_enabled(struct rt_i2c_bus_device *dev, rt_bool_t enable)
{
wm8978_write_reg(dev, REG_POWER_MANAGEMENT1 | (enable ? BIASEN : 0));
}
rt_err_t wm8978_set_EQ1(struct rt_i2c_bus_device *dev, rt_uint8_t freq, rt_uint8_t gain)
{
rt_uint16_t temp = 0;
if (freq > 3 || gain > 24)
{
return -RT_ERROR;
}
switch (freq)
{
case 0:
temp = EQ1C_80HZ;
break;
case 1:
temp = EQ1C_105HZ;
break;
case 2:
temp = EQ1C_135HZ;
break;
case 3:
temp = EQ1C_175HZ;
break;
default:
break;
}
/* 0 - 24 as -12~+12dB */
gain = 24 - gain;
temp |= gain;
wm8978_write_reg(dev, REG_EQ1 | temp);
return RT_EOK;
}
rt_err_t wm8978_set_EQ2(struct rt_i2c_bus_device *dev, rt_uint8_t freq, rt_uint8_t gain)
{
rt_uint16_t temp = 0;
if (freq > 3 || gain > 24)
{
return -RT_ERROR;
}
switch (freq)
{
case 0:
temp = EQ2C_230HZ;
break;
case 1:
temp = EQ2C_300HZ;
break;
case 2:
temp = EQ2C_385HZ;
break;
case 3:
temp = EQ2C_500HZ;
break;
default:
break;
}
/* 0 - 24 as -12~+12dB */
gain = 24 - gain;
temp |= gain;
wm8978_write_reg(dev, REG_EQ2 | temp);
return RT_EOK;
}
rt_err_t wm8978_set_EQ3(struct rt_i2c_bus_device *dev, rt_uint8_t freq, rt_uint8_t gain)
{
rt_uint16_t temp = 0;
if (freq > 3 || gain > 24)
{
return -RT_ERROR;
}
switch (freq)
{
case 0:
temp = EQ3C_650HZ;
break;
case 1:
temp = EQ3C_850HZ;
break;
case 2:
temp = EQ3C_1_1KHZ;
break;
case 3:
temp = EQ3C_1_4KHZ;
break;
default:
break;
}
/* 0 - 24 as -12~+12dB */
gain = 24 - gain;
temp |= gain;
wm8978_write_reg(dev, REG_EQ3 | temp);
return RT_EOK;
}
rt_err_t wm8978_set_EQ4(struct rt_i2c_bus_device *dev, rt_uint8_t freq, rt_uint8_t gain)
{
rt_uint16_t temp = 0;
if (freq > 3 || gain > 24)
{
return -RT_ERROR;
}
switch (freq)
{
case 0:
temp = EQ4C_1_8KHZ;
break;
case 1:
temp = EQ4C_2_4KHZ;
break;
case 2:
temp = EQ4C_3_2KHZ;
break;
case 3:
temp = EQ4C_4_1KHZ;
break;
default:
break;
}
/* 0 - 24 as -12~+12dB */
gain = 24 - gain;
temp |= gain;
wm8978_write_reg(dev, REG_EQ4 | temp);
return RT_EOK;
}
rt_err_t wm8978_set_EQ5(struct rt_i2c_bus_device *dev, rt_uint8_t freq, rt_uint8_t gain)
{
rt_uint16_t temp = 0;
if (freq > 3 || gain > 24)
{
return -RT_ERROR;
}
switch (freq)
{
case 0:
temp = EQ5C_5_3KHZ;
break;
case 1:
temp = EQ5C_6_9KHZ;
break;
case 2:
temp = EQ5C_9KHZ;
break;
case 3:
temp = EQ5C_11_7KHZ;
break;
default:
break;
}
/* 0 - 24 as -12~+12dB */
gain = 24 - gain;
temp |= gain;
wm8978_write_reg(dev, REG_EQ5 | temp);
return RT_EOK;
}
void wm8978_3D_Set(struct rt_i2c_bus_device *dev, rt_uint8_t depth)
{
wm8978_write_reg(dev, REG_3D | (depth & 0xf));
}
|
f118ac9be6ea7e109a09cfa91a3c3ae83f814871
|
e028fd9d09e9a030db19344cf5ac060287a4e4c6
|
/tests/test-iff.c
|
2ab280bb8017b59bf33957293b9dce1191421729
|
[
"BSD-2-Clause",
"LicenseRef-scancode-free-unknown"
] |
permissive
|
septag/sx
|
b321b5dfc4c74e2caf5a2c3769d7a20135ecbfe2
|
fff3c92f74382f570d18647655a17ecba84a62e7
|
refs/heads/master
| 2023-08-21T04:54:32.606625
| 2022-07-08T08:25:57
| 2022-07-08T08:25:57
| 141,604,220
| 930
| 55
|
BSD-2-Clause
| 2022-07-08T08:25:58
| 2018-07-19T16:17:59
|
C
|
UTF-8
|
C
| false
| false
| 6,521
|
c
|
test-iff.c
|
#include "sx/allocator.h"
#include "sx/io.h"
#include "sx/string.h"
#include <stdio.h>
static const uint8_t dummy_data[473] =
{
0x7b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x22, 0x66, 0x6f, 0x6c, 0x64, 0x65, 0x72, 0x73, 0x22, 0x3a,
0x20, 0x5b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x7b, 0x0a, 0x20, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x22, 0x70, 0x61, 0x74, 0x68, 0x22, 0x3a,
0x20, 0x22, 0x2e, 0x22, 0x2c, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x22, 0x66, 0x6f, 0x6c, 0x64, 0x65, 0x72, 0x5f, 0x65, 0x78, 0x63, 0x6c, 0x75, 0x64,
0x65, 0x5f, 0x70, 0x61, 0x74, 0x74, 0x65, 0x72, 0x6e, 0x73, 0x22, 0x3a, 0x20, 0x5b, 0x0a, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x22,
0x62, 0x75, 0x69, 0x6c, 0x64, 0x22, 0x2c, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x22, 0x2e, 0x76, 0x73, 0x63, 0x6f, 0x64, 0x65,
0x22, 0x2c, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x20, 0x22, 0x2e, 0x63, 0x6c, 0x61, 0x6e, 0x67, 0x64, 0x22, 0x2c, 0x0a, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x22, 0x62,
0x69, 0x6e, 0x22, 0x2c, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x22, 0x62, 0x75, 0x69, 0x6c, 0x64, 0x2d, 0x2a, 0x22, 0x0a, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x5d, 0x2c, 0x0a, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x22, 0x66, 0x69, 0x6c, 0x65, 0x5f,
0x65, 0x78, 0x63, 0x6c, 0x75, 0x64, 0x65, 0x5f, 0x70, 0x61, 0x74, 0x74, 0x65, 0x72, 0x6e, 0x73,
0x22, 0x3a, 0x20, 0x5b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x22, 0x2e, 0x67, 0x69, 0x74, 0x69, 0x67, 0x6e, 0x6f, 0x72, 0x65,
0x22, 0x2c, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x20, 0x22, 0x2e, 0x74, 0x72, 0x61, 0x76, 0x69, 0x73, 0x2e, 0x79, 0x6d, 0x6c, 0x22,
0x2c, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x22, 0x2e, 0x67, 0x69, 0x74, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x73, 0x22, 0x2c,
0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x22, 0x2e, 0x63, 0x6c, 0x61, 0x6e, 0x67, 0x2d, 0x66, 0x6f, 0x72, 0x6d, 0x61, 0x74, 0x22,
0x2c, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x22, 0x63, 0x6f, 0x6d, 0x70, 0x69, 0x6c, 0x65, 0x5f, 0x63, 0x6f, 0x6d, 0x6d, 0x61,
0x6e, 0x64, 0x73, 0x2e, 0x6a, 0x73, 0x6f, 0x6e, 0x22, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x5d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x7d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x5d, 0x0a, 0x7d,
};
#define LEVEL1_FOURCC sx_makefourcc('L', 'V', 'L', '1')
#define LEVEL2_FOURCC sx_makefourcc('L', 'V', 'L', '2')
static void test_write_iff(const char* filename)
{
sx_file f;
if (sx_file_open(&f, filename, SX_FILE_WRITE)) {
sx_iff_file iff;
sx_iff_init_from_file_writer(&iff, &f, 0, sx_alloc_malloc());
int level1 = sx_iff_put_chunk(&iff, 0, LEVEL1_FOURCC, dummy_data, sizeof(dummy_data), 0, 0);
sx_iff_put_chunk(&iff, level1, LEVEL2_FOURCC, dummy_data, sizeof(dummy_data), 0, 0);
sx_iff_put_chunk(&iff, level1, LEVEL2_FOURCC, dummy_data, sizeof(dummy_data), 0, 0);
sx_iff_put_chunk(&iff, 0, LEVEL1_FOURCC, dummy_data, sizeof(dummy_data), 0, 0);
sx_iff_release(&iff);
sx_file_close(&f);
}
}
static void test_append_iff(const char* filename)
{
sx_file f;
if (sx_file_open(&f, filename, SX_FILE_WRITE|SX_FILE_APPEND)) {
sx_iff_file iff;
sx_iff_init_from_file_writer(&iff, &f, SX_IFFFLAG_APPEND|SX_IFFFLAG_READ_ALL_CHUNKS, sx_alloc_malloc());
int level1 = sx_iff_put_chunk(&iff, 0, LEVEL1_FOURCC, dummy_data, sizeof(dummy_data), 0, 0);
sx_iff_put_chunk(&iff, level1, LEVEL2_FOURCC, dummy_data, sizeof(dummy_data), 0, 0);
sx_iff_put_chunk(&iff, level1, LEVEL2_FOURCC, dummy_data, sizeof(dummy_data), 0, 0);
sx_iff_put_chunk(&iff, 0, LEVEL1_FOURCC, dummy_data, sizeof(dummy_data), 0, 0);
sx_iff_release(&iff);
sx_file_close(&f);
}
}
static const char* get_tabs(int depth)
{
static char depth_str[256];
for (int i = 0; i < depth; i++) {
depth_str[i] = '\t';
}
depth_str[depth] = '\0';
return depth_str;
}
static void test_load_iff(const char* filename)
{
sx_file f;
if (sx_file_open(&f, filename, SX_FILE_READ)) {
sx_iff_file iff;
sx_iff_init_from_file_reader(&iff, &f, 0, sx_alloc_malloc());
int depth = 0;
int level1 = sx_iff_get_chunk(&iff, LEVEL1_FOURCC, 0);
while (level1 != -1) {
printf("%sChunk [Level%d] - size: %u (parent: %d)\n",
get_tabs(depth), depth+1, (uint32_t)iff.chunks[level1].size, iff.chunks[level1].parent_id);
depth++;
int level2 = sx_iff_get_chunk(&iff, LEVEL2_FOURCC, level1);
while (level2 != -1) {
printf("%sChunk [level%d] - size: %u (parent: %d)\n",
get_tabs(depth), depth+1, (uint32_t)iff.chunks[level2].size, iff.chunks[level2].parent_id);
level2 = sx_iff_get_next_chunk(&iff, level2);
}
depth--;
level1 = sx_iff_get_next_chunk(&iff, level1);
}
}
}
int main(int argc, char* argv[])
{
if (argc != 2) {
puts("You must provide a command and a file:");
puts(" test-iff load");
puts(" test-iff save");
return -1;
}
const char* command = argv[1];
if (sx_strequal(command, "save")) {
test_write_iff("test.bin");
} else if (sx_strequal(command, "load")) {
test_load_iff("test.bin");
} else if (sx_strequal(command, "append")) {
test_append_iff("test.bin");
}
return 0;
}
|
df5dbc76ff745eee6dd5729f21940d64808dcbd8
|
9ceacf33fd96913cac7ef15492c126d96cae6911
|
/regress/lib/libc/sys/t_mlock.c
|
865bd9e36baa7fc19c606aad14430765972b09d7
|
[] |
no_license
|
openbsd/src
|
ab97ef834fd2d5a7f6729814665e9782b586c130
|
9e79f3a0ebd11a25b4bff61e900cb6de9e7795e9
|
refs/heads/master
| 2023-09-02T18:54:56.624627
| 2023-09-02T15:16:12
| 2023-09-02T15:16:12
| 66,966,208
| 3,394
| 1,235
| null | 2023-08-08T02:42:25
| 2016-08-30T18:18:25
|
C
|
UTF-8
|
C
| false
| false
| 8,592
|
c
|
t_mlock.c
|
/* $OpenBSD: t_mlock.c,v 1.3 2021/12/13 16:56:48 deraadt Exp $ */
/* $NetBSD: t_mlock.c,v 1.8 2020/01/24 08:45:16 skrll Exp $ */
/*-
* Copyright (c) 2012 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Jukka Ruohonen.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include "macros.h"
#include <sys/mman.h>
#include <sys/resource.h>
#include <sys/sysctl.h>
#include <sys/wait.h>
#include <errno.h>
#include "atf-c.h"
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
static long page = 0;
ATF_TC(mlock_clip);
ATF_TC_HEAD(mlock_clip, tc)
{
atf_tc_set_md_var(tc, "descr", "Test with mlock(2) that UVM only "
"clips if the clip address is within the entry (PR kern/44788)");
}
ATF_TC_BODY(mlock_clip, tc)
{
void *buf;
int err1, err2;
buf = malloc(page);
ATF_REQUIRE(buf != NULL);
fprintf(stderr, "mlock_clip: buf = %p (page=%ld)\n", buf, page);
if (page < 1024)
atf_tc_skip("page size too small");
for (size_t i = page; i >= 1; i = i - 1024) {
err1 = mlock(buf, page - i);
if (err1 != 0)
fprintf(stderr, "mlock_clip: page=%ld i=%zu,"
" mlock(%p, %ld): %s\n", page, i, buf, page - i,
strerror(errno));
err2 = munlock(buf, page - i);
if (err2 != 0)
fprintf(stderr, "mlock_clip: page=%ld i=%zu,"
" munlock(%p, %ld): %s (mlock %s)\n", page, i,
buf, page - i, strerror(errno), err1?"failed":"ok");
}
free(buf);
}
ATF_TC(mlock_err);
ATF_TC_HEAD(mlock_err, tc)
{
atf_tc_set_md_var(tc, "descr",
"Test error conditions in mlock(2) and munlock(2)");
}
ATF_TC_BODY(mlock_err, tc)
{
void *invalid_ptr;
void *buf;
int mlock_err, munlock_err;
/*
* Any bad address must return ENOMEM (for lock & unlock)
*/
errno = 0;
ATF_REQUIRE_ERRNO(ENOMEM, mlock(NULL, page) == -1);
errno = 0;
ATF_REQUIRE_ERRNO(ENOMEM, mlock((char *)0, page) == -1);
errno = 0;
#ifdef __OpenBSD__
ATF_REQUIRE_ERRNO(EINVAL, mlock((char *)-1, page) == -1);
#else
ATF_REQUIRE_ERRNO(ENOMEM, mlock((char *)-1, page) == -1);
#endif
errno = 0;
ATF_REQUIRE_ERRNO(ENOMEM, munlock(NULL, page) == -1);
errno = 0;
ATF_REQUIRE_ERRNO(ENOMEM, munlock((char *)0, page) == -1);
errno = 0;
#ifdef __OpenBSD__
ATF_REQUIRE_ERRNO(EINVAL, munlock((char *)-1, page) == -1);
#else
ATF_REQUIRE_ERRNO(ENOMEM, munlock((char *)-1, page) == -1);
#endif
buf = malloc(page);
ATF_REQUIRE(buf != NULL);
fprintf(stderr, "mlock_err: buf = %p (page=%ld)\n", buf, page);
/*
* unlocking memory that is not locked is an error...
*/
#ifndef __OpenBSD__
errno = 0;
ATF_REQUIRE_ERRNO(ENOMEM, munlock(buf, page) == -1);
#endif
/*
* These are permitted to fail (EINVAL) but do not on NetBSD
*/
mlock_err = mlock((void *)(((uintptr_t)buf) + page/3), page/5);
if (mlock_err != 0)
fprintf(stderr, "mlock_err: mlock(%p, %ld): %d [%d] %s\n",
(void *)(((uintptr_t)buf) + page/3), page/5, mlock_err,
errno, strerror(errno));
ATF_REQUIRE(mlock_err == 0);
munlock_err= munlock((void *)(((uintptr_t)buf) + page/3), page/5);
if (munlock_err != 0)
fprintf(stderr, "mlock_err: munlock(%p, %ld): %d [%d] %s\n",
(void *)(((uintptr_t)buf) + page/3), page/5, munlock_err,
errno, strerror(errno));
ATF_REQUIRE(munlock_err == 0);
(void)free(buf);
/*
* Try to create a pointer to an unmapped page - first after current
* brk will likely do.
*/
invalid_ptr = (void*)(((uintptr_t)sbrk(0)+page) & ~(page-1));
printf("testing with (hopefully) invalid pointer %p\n", invalid_ptr);
errno = 0;
ATF_REQUIRE_ERRNO(ENOMEM, mlock(invalid_ptr, page) == -1);
errno = 0;
ATF_REQUIRE_ERRNO(ENOMEM, munlock(invalid_ptr, page) == -1);
}
ATF_TC(mlock_limits);
ATF_TC_HEAD(mlock_limits, tc)
{
atf_tc_set_md_var(tc, "descr", "Test system limits with mlock(2)");
}
ATF_TC_BODY(mlock_limits, tc)
{
struct rlimit res;
void *buf;
pid_t pid;
int sta;
buf = malloc(page);
ATF_REQUIRE(buf != NULL);
fprintf(stderr, "mlock_limits: buf = %p (page=%ld)\n", buf, page);
pid = fork();
ATF_REQUIRE(pid >= 0);
if (pid == 0) {
for (ssize_t i = page; i >= 2; i -= 100) {
res.rlim_cur = i - 1;
res.rlim_max = i - 1;
(void)fprintf(stderr, "trying to lock %zu bytes "
"with %zu byte limit\n", i, (size_t)res.rlim_cur);
if (setrlimit(RLIMIT_MEMLOCK, &res) != 0)
_exit(EXIT_FAILURE);
errno = 0;
if ((sta = mlock(buf, i)) != -1 || errno != EAGAIN) {
fprintf(stderr, "mlock(%p, %zu): %d [%d] %s\n",
buf, i, sta, errno, strerror(errno));
(void)munlock(buf, i);
_exit(EXIT_FAILURE);
}
}
_exit(EXIT_SUCCESS);
}
(void)wait(&sta);
if (WIFEXITED(sta) == 0 || WEXITSTATUS(sta) != EXIT_SUCCESS)
atf_tc_fail("mlock(2) locked beyond system limits");
free(buf);
}
ATF_TC(mlock_mmap);
ATF_TC_HEAD(mlock_mmap, tc)
{
atf_tc_set_md_var(tc, "descr", "Test mlock(2)-mmap(2) interaction");
}
ATF_TC_BODY(mlock_mmap, tc)
{
#ifdef __OpenBSD__
static const int flags = MAP_ANON | MAP_PRIVATE;
#else
static const int flags = MAP_ANON | MAP_PRIVATE | MAP_WIRED;
#endif
void *buf;
/*
* Make a wired RW mapping and check that mlock(2)
* does not fail for the (already locked) mapping.
*/
buf = mmap(NULL, page, PROT_READ | PROT_WRITE, flags, -1, 0);
if (buf == MAP_FAILED)
fprintf(stderr,
"mlock_mmap: mmap(NULL, %ld, %#x, %#x, -1, 0): MAP_FAILED"
" [%d] %s\n", page, PROT_READ | PROT_WRITE, flags, errno,
strerror(errno));
ATF_REQUIRE(buf != MAP_FAILED);
fprintf(stderr, "mlock_mmap: buf=%p, page=%ld\n", buf, page);
ATF_REQUIRE(mlock(buf, page) == 0);
ATF_REQUIRE(munlock(buf, page) == 0);
ATF_REQUIRE(munmap(buf, page) == 0);
ATF_REQUIRE(munlock(buf, page) != 0);
fprintf(stderr, "mlock_mmap: first test succeeded\n");
/*
* But it should be impossible to mlock(2) a PROT_NONE mapping.
*/
buf = mmap(NULL, page, PROT_NONE, flags, -1, 0);
if (buf == MAP_FAILED)
fprintf(stderr,
"mlock_mmap: mmap(NULL, %ld, %#x, %#x, -1, 0): MAP_FAILED"
" [%d] %s\n", page, PROT_NONE, flags, errno,
strerror(errno));
ATF_REQUIRE(buf != MAP_FAILED);
ATF_REQUIRE(mlock(buf, page) != 0);
ATF_REQUIRE(munmap(buf, page) == 0);
fprintf(stderr, "mlock_mmap: second test succeeded\n");
}
ATF_TC(mlock_nested);
ATF_TC_HEAD(mlock_nested, tc)
{
atf_tc_set_md_var(tc, "descr",
"Test that consecutive mlock(2) calls succeed");
}
ATF_TC_BODY(mlock_nested, tc)
{
const size_t maxiter = 100;
void *buf;
int err;
buf = malloc(page);
ATF_REQUIRE(buf != NULL);
fprintf(stderr, "mlock_nested: buf = %p (page=%ld)\n", buf, page);
for (size_t i = 0; i < maxiter; i++) {
err = mlock(buf, page);
if (err != 0)
fprintf(stderr,
"mlock_nested: i=%zu (of %zu) mlock(%p, %ld): %d [%d] %s\n",
i, maxiter, buf, page, err, errno, strerror(errno));
ATF_REQUIRE(err == 0);
}
err = munlock(buf, page);
if (err != 0)
fprintf(stderr, "mlock_nested: munlock(%p, %ld): %d [%d] %s\n",
buf, page, err, errno, strerror(errno));
ATF_REQUIRE(err == 0);
free(buf);
}
ATF_TP_ADD_TCS(tp)
{
page = sysconf(_SC_PAGESIZE);
ATF_REQUIRE(page >= 0);
ATF_TP_ADD_TC(tp, mlock_clip);
ATF_TP_ADD_TC(tp, mlock_err);
ATF_TP_ADD_TC(tp, mlock_limits);
ATF_TP_ADD_TC(tp, mlock_mmap);
ATF_TP_ADD_TC(tp, mlock_nested);
return atf_no_error();
}
|
d0d65e00e4bfdf123800d28a4b7034bb75245d85
|
fdbfbcf4d6a0ef6f3c1b600e7b8037eed0f03f9e
|
/multibody/hydroelastics/hydroelastic_user_guide_doxygen.h
|
3c008e47a7d32ed08e09660859c82f2beb3020eb
|
[
"BSD-3-Clause"
] |
permissive
|
RobotLocomotion/drake
|
4529c397f8424145623dd70665531b5e246749a0
|
3905758e8e99b0f2332461b1cb630907245e0572
|
refs/heads/master
| 2023-08-30T21:45:12.782437
| 2023-08-30T15:59:07
| 2023-08-30T15:59:07
| 16,256,144
| 2,904
| 1,270
|
NOASSERTION
| 2023-09-14T20:51:30
| 2014-01-26T16:11:05
|
C++
|
UTF-8
|
C
| false
| false
| 37,527
|
h
|
hydroelastic_user_guide_doxygen.h
|
/** @file
Doxygen-only documentation for @ref hydroelastic_user_guide,
*/
/**
@defgroup hydroelastic_user_guide Hydroelastic Contact User Guide
@ingroup multibody
@section hug_title Hydroelastic Contact User Guide
@subsection hug_introduction Introduction
There are many ways to model contact between rigid bodies. Drake uses an
approach we call “compliant” contact. In compliant contact, nominally rigid
bodies are allowed to penetrate slightly, as if the rigid body had a slightly
deformable layer, but whose compression has no appreciable effect on the body’s
mass properties. The contact force between two deformed bodies is distributed
over a contact patch with an uneven pressure distribution over that patch. It
is common in robotics to model that as a single point contact or a set of point
contacts. Hydroelastic contact instead attempts to approximate the patch and
pressure distribution to provide much richer and more realistic contact
behavior. For a high-level overview, see [this blog post]
(https://medium.com/toyotaresearch/rethinking-contact-simulation-for-robot-manipulation-434a56b5ec88).
Drake implements two models for resolving contact to forces: point contact and
hydroelastic contact. See @ref hydro_appendix_a for a fuller discussion of the
theory and practice of contact models. For notes on implementation status, see
@ref hydro_appendix_b. Also see @ref hydro_appendix_examples_and_tutorials.
@subsection hug_working_with_hydro Working with Hydroelastic Contact
It is relatively simple to enable a simulation to use hydroelastic
contact. However, using it effectively requires some experience and
consideration. This section details the mechanisms and choices involved in
enabling hydroelastic contact and the next section helps guide you through some
common tips, tricks, and traps.
Using hydroelastic contact requires two things:
- Configuring the system (drake::multibody::MultibodyPlant) to use hydroelastic
contact.
- Applying appropriate properties to the collision geometries to enable
hydroelastic contact calculations.
Collision geometries for hydroelastic contact can be either
"compliant-hydroelastic" with tetrahedral meshes describing an
internal pressure field or "rigid-hydroelastic" with triangle
surface meshes that are regarded as infinitely stiff.
The figure below shows examples of a compliant hydroelastic box
and a rigid hydroelastic box.
<!-- N.B. This image is also used by hydroelastic_contact_basics.ipynb. -->
@image html "multibody/hydroelastics/images/HydroelasticTutorialCompliantRigidOutsideInside800x669.jpg"
The figure below shows a contact surface between a compliant-hydroelastic cylinder
and a compliant-hydroelastic sphere. The contact surface is internal to both
solids and is defined as the surface where the two pressure fields are equal.
<!-- N.B. This image is also used by hydroelastic_contact_basics.ipynb. -->
@image html "multibody/hydroelastics/images/HydroelasticTutorialContactSurfaceCompliantCompliant.png"
Pictured below, a rigid-hydroelastic cylindrical spatula handle is grasped
by two hydroelastic-compliant ellipsoidal bubble grippers.
The contact surface between the spatula handle's rigid-hydroelastic
geometry and either gripper is on the <b>surface</b> of the
rigid-hydroelastic geometry.
<!-- N.B. This image is also used by hydroelastic_contact_basics.ipynb. -->
@image html "multibody/hydroelastics/images/HydroelasticTutorialContactSurfaceRigidCompliantBubble.png"
@subsubsection hug_enabling Enabling Hydroelastic contact in your simulation
Because @ref drake::multibody::MultibodyPlant "MultibodyPlant"
is responsible for computing the dynamics of the
system (and the contact forces are part of that), the ability to enable/disable
the hydroelastic contact model is part of `MultibodyPlant`’s API:
drake::multibody::MultibodyPlant::set_contact_model().
There are three different options:
- drake::multibody::ContactModel::kPoint
- drake::multibody::ContactModel::kHydroelastic
- drake::multibody::ContactModel::kHydroelasticWithFallback
The default model is
@ref drake::multibody::ContactModel::kHydroelasticWithFallback
"kHydroelasticWithFallback".
@ref drake::multibody::ContactModel::kPoint "kPoint" is the implementation of
the point contact model (see @ref hydro_appendix_a).
Models @ref drake::multibody::ContactModel::kHydroelastic "kHydroelastic" and
@ref drake::multibody::ContactModel::kHydroelasticWithFallback
"kHydroelasticWithFallback" will both enable the hydroelastic contact. For
forces to be created from hydroelastic contact, geometries need to have
hydroelastic representations (see @ref creating_hydro_reps).
@ref drake::multibody::ContactModel::kHydroelastic "kHydroelastic" is a strict
contact model that will attempt to create a hydroelastic contact surface
whenever a geometry with a hydroelastic representation appears to be in contact
(based on broad-phase bounding volume culling). With this contact model, the
simulator will throw an exception if:
- The contact is between two geometries with rigid hydroelastic representation,
or
- The contact is between a geometry with a hydroelastic representation and one
without.
Collisions between two geometries where neither has a hydroelastic
representation are simply ignored.
@ref drake::multibody::ContactModel::kHydroelasticWithFallback
"kHydroelasticWithFallback" provides “fallback” behavior for when
@ref drake::multibody::ContactModel::kHydroelastic "kHydroelastic" would throw.
When those scenarios are detected, it uses the point contact model between the
colliding geometries so that the contact can be accounted for and produce
contact forces. As the implementation evolves, more and more contact will be
captured with hydroelastic contact and the circumstances in which the
point-contact fallback is applied will decrease.
@subsubsection creating_hydro_reps Creating hydroelastic representations of collision geometries
By default no geometry in drake::geometry::SceneGraph has a hydroelastic
representation. So, enabling hydroelastic contact in `MultibodyPlant`, but
forgetting to configure the geometries will lead to either simulation crashes
or point contact-based forces.
In order for a mesh to be given a hydroelastic representation, it must be
assigned certain properties. The exact properties it needs depends on the Shape
type and whether it is rigid or compliant. Some properties can be defined, but
if they are absent they’ll be provided by `MultibodyPlant`. First we’ll discuss
each of the properties and then discuss how they can be specified.
@paragraph hug_properties Properties for hydroelastic contact
<!-- TODO(rpoyner-tri): consider restructuring this section to paragraphs,
rather than a nested list -->
- Hydroelastic classification
- To have a hydroelastic representation, a shape needs to be classified as
either “compliant” or “rigid”. This must be explicit -- there are no
implicit assumptions. Otherwise, it will participate in point contact only.
- Resolution hint (meters)
- A positive real value in meters.
- Most shapes (capsules, cylinders, ellipsoids, spheres) need to be
tessellated into meshes. The resolution hint controls the fineness of the
meshes.
- For all tessellated geometries, Drake puts hard limits on the effect of
the resolution hint property. There is a limit to how fine Drake will
tessellate a primitive. Drake has hard-coded internal limits that are
still very generous (approximately 100 million tetrahedra or triangles)
which should be more than enough for any application. In practice,
resolution hints will be quite “large” as coarser meshes are typically
more desirable.
- Notes on choosing a value:
- Generally, the coarsest mesh that produces desirable results will allow
the simulation to run as efficiently as possible.
- The coarsest mesh will typically be generated when the resolution is
equal to the geometry’s maximum measure (see the details below).
- If tessellation artifacts become obvious in the simulation, either make
the object more compliant (see hydroelastic modulus) or increase the
resolution (as discussed for the various shapes below).
- Geometric detail:
- For each geometry type, the resolution hint works with some (maybe
abstract) choice of a representative circle, and its effect is defined
in terms of the circumference of that circle. The resolution hint is the
target length of each edge of the tessellated mesh around the
circle. The circle will have N = ⌈2πr/h⌉ edges, where r is the capsule
radius and h is the resolution hint. The number N changes
discontinuously as h changes. However, generally, decreasing the
resolution hint by some factor will increase the number of edges by that
same factor. The number of elements will grow quadratically.
- Sphere
- The representative circle is the great circle of the sphere.
- Cylinder
- The representative circle is the base of the cylinder.
- Capsule
- The representative circle is the base of the cylinder, which is also
the great circle of each hemisphere.
- Ellipsoid
- The representative circle is an abstract circle whose radius is that
of the largest semi-axis of the elllipsoid.
- Resolution hint has no effect on Box.
- Hydroelastic modulus (Pa (N/m²))
- This is the measure of how stiff the material is. It directly defines how
much pressure is exerted given a certain amount of penetration. More
pressure leads to greater forces. Larger values create stiffer objects. An
infinite modulus is mathematically equivalent to a “rigid”
object. (Although, it is definitely better, in that case, to simply declare
it “rigid”.)
- This is *only* required for shapes declared to be “compliant”. It can be
defined for shapes declared as “rigid”, but the value will be ignored. (It
can be convenient to always define it to enable tests where one might
toggle the classification between rigid and compliant such that the
compliant declaration is always well formed.)
- Declaring a geometry to be compliant but not providing a valid hydroelastic
modulus will produce an error at the time the geometry is added to
`SceneGraph`.
- This is similar to something like Young’s modulus but it is not identical.
- The primary distinction is this isn’t purely a material property. The
value is entangled with the geometry. It essentially scales the force
based on the *percentage* of penetration into an object (i.e.,
strain). So, a fixed modulus value might lead to a 1cm penetration on one
sphere. But if the sphere were scaled up by a factor of 10, the
penetration would become 10cm. So, if there are constraints on
penetration depth, the modulus would have to increase with the scale of
the geometry.
- Notes on choosing a value:
- Starting with the value for Young’s modulus is not
unreasonable. Empirical evidence suggests that the hydroelastic modulus
tends to be smaller depending on the size of the objects.
- For large modulus values, the resolution of the representations matter
more. A very high modulus will keep the contact near the surface of the
geometry, exposing tessellation artifacts. A smaller modulus has a
smoothing effect.
- Hunt-Crossley dissipation (s/m)
- A non-negative real value.
- This gives the contact an energy-damping property.
- The larger the value, the more energy is damped.
- If no value is provided, `MultibodyPlant` provides a default value of zero.
- Notes on choosing a value:
- For objects that are nominally rigid, starting with zero-damping is good.
- If the behavior seems “jittery”, gradually increase the amount of
dissipation. Typical values would remain in the range [0, 3] with 1 being
a typical damping amount.
- Remember, as this value increases, your simulation will lose energy at a
higher rate.
- See @ref mbp_dissipation_model "Modeling Dissipation" for details.
- Slab thickness
- A positive real value in meters
- Only used for compliant half spaces. Declaring a half space to be compliant
but lacking a value for slab thickness will cause the simulation to error
out.
- A measure of the thickness of the compliant material near the boundary of
the half space.
- A compliant half space can be made more rigid by:
- Increasing the hydroelastic modulus and fixing slab thickness.
- Fixing the hydroelastic modulus and decreasing the slab thickness.
- Increasing the hydroelastic modulus and decreasing the slab thickness.
@subsubsection hug_geometry_properties Assigning hydroelastic properties to geometries
Properties can be assigned to geometries inside a URDF or SDFormat file using
some custom Drake XML tags. Alternatively, the properties can be assigned
programmatically.
@paragraph hug_file_specs Assigning hydroelastic properties in file specifications
Drake has introduced a number of custom tags to provide a uniform language to
specify hydroelastic properties in both URDF and SDFormat. The tag names are
the same but the values are expressed differently (to align with the practices
common to URDF and SDFormat). For example, consider a custom tag <drake:foo>
that takes a single integer value. In an SDFormat file it would look like:
<drake:foo>17</drake:foo>
But in a URDF file it would look like this:
<drake:foo value=”17”/>
Both URDF and SDFormat files define a <collision> tag. This tag contains the
tag for specifying the geometry type and associated properties. The
hydroelastic properties can be specified as a child of the <collision>
tag. Consider the following SDFormat example:
…
<collision name="body1_collision">
<geometry>
...
</geometry>
<drake:proximity_properties>
<drake:compliant_hydroelastic/>
<drake:mesh_resolution_hint>0.1</drake:mesh_resolution_hint>
<drake:hydroelastic_modulus>5e7</drake:hydroelastic_modulus>
<drake:hunt_crossley_dissipation>1.25</drake:hunt_crossley_dissipation>
</drake:proximity_properties>
</collision>
…
For a body, we’ve defined a collision geometry called “body1_collision”. Inside
the <collision> tag (as a sibling to the <geometry> tag), we’ve introduced the
Drake-specific <drake:proximity_properties> tag. In it we’ve defined the
geometry to be compliant for hydroelastic contact and specified its resolution
hint, its hydroelastic modulus, and its dissipation.
Let’s look at the specific tags:
- <@ref tag_drake_proximity_properties>: This is the container for all
Drake-specific proximity property values.
- The following tags define hydroelastic properties for the collision geometry
and would be contained in the <@ref tag_drake_proximity_properties> tag.
- <@ref tag_drake_rigid_hydroelastic> or
<@ref tag_drake_compliant_hydroelastic>
- <@ref tag_drake_mesh_resolution_hint>
- <@ref tag_drake_hydroelastic_modulus> (for compliant geometry only)
- <@ref tag_drake_hunt_crossley_dissipation>
- In the name of completeness, the following tags would be children of the
<@ref tag_drake_proximity_properties> tag as well, but are not restricted to
use with hydroelastic contact.
- <@ref tag_drake_point_contact_stiffness>: Only used when this geometry is
for point contact. Defines the compliance of the point contact. This
property is allowed to exist even if the geometry has been specified to be
of hydroelastic type, it will have no effect on hydroelastic computations.
- <@ref tag_drake_mu_static> The coefficient for static friction; this
applies to both point contact and hydroelastic contact.
- <@ref tag_drake_mu_dynamic> The coefficient for dynamic friction; this
applies to both point contact and hydroelastic contact.
@paragraph hug_code_properties Assigning hydroelastic properties in code
Hydroelastic properties can be set to objects programmatically via the following
APIs (see their documentation for further details):
- AddContactMaterial()
- AddRigidHydroelasticProperties()
- AddCompliantHydroelasticProperties()
- AddCompliantHydroelasticPropertiesForHalfSpace()
Some extra notes:
AddContactMaterial() isn’t hydroelastic contact specific, but does provide a
mechanism for setting the friction coefficients that hydroelastic and point
contact models both use.
AddRigidHydroelasticProperties() is overloaded. One version accepts a value for
resolution hint, one does not. When in doubt which to use, it is harmless to
provide a resolution hint value that would be ignored for some geometries, but
failing to provide one where necessary will cause the simulation to throw an
exception. Note the special case for declaring a compliant half space -- it
takes the required slab thickness parameter in addition to the hydroelastic
modulus value.
@subsection hug_visualizing Visualizing hydroelastic contact
Currently we can only visualize the contact surface using the legacy
``drake_visualizer`` application of days past; however, it will be replaced by
[MeshCat](https://github.com/meshcat-dev/meshcat) in the future.
Start Drake Visualizer by:
$ bazel run //tools:drake_visualizer &
Run a simulation with hydroelastic contact model; for example,
$ bazel run //examples/hydroelastic/ball_plate:ball_plate_run_dynamics -- \
--mbp_dt=0.001 --simulator_publish_every_time_step --x0=0.10 --z0=0.15 \
--simulation_time=0.015 --simulator_target_realtime_rate=0.05 --vz=-7.0
By default, at the time of this writing, Drake Visualizer will look like this:
<!-- N.B. Do not attempt to line wrap this table. -->
| | |
| :-: | :-: |
| @image html "multibody/hydroelastics/images/drake-vis-01.png" width=90% | @image html "multibody/hydroelastics/images/drake-vis-02.png" width=95% |
In the above pictures, we see two red force vectors acting at the centroids of
the two contact surfaces and also the blue moment vector. One contact surface
represents the ball pushing the dinner plate down. The other contact surface
represents the rectangular floor pushing the dinner plate up. Gravity forces
are not shown.
In the next picture, we zoom-in and rotate to show the contact surface between
the dinner plate and the floor better. The ball is pushing one side of the
plate downward enough that only half of the bottom of the plate makes contact
with the floor.
@image html "multibody/hydroelastics/images/drake-vis-03.png"
The Scene Browser lists all the hydroelastic contacts. We can turn off the
plate-ball contact keeping only the plate-floor contact for clarity. Use the
“eye” icon to toggle off the ball-plate contact as shown in the following
picture. We can also make the dinner plate transparent too.
@image html "multibody/hydroelastics/images/drake-vis-04.png"
To customize the contact visualization, go to the following menu:
Plugins` > `Contacts` > `Configure Hydroelastic Contact Visualization
@image html "multibody/hydroelastics/images/drake-vis-05.png"
You can set `Maximum pressure` to what is observed (5e4 Pa in this example,
default 1e8 Pa), so the shading of the contact surface looks more reasonable in
the following picture:
@image html "multibody/hydroelastics/images/drake-vis-06.png"
You can set `Edge width` of the white meshes of the contact surface with
options to toggle the pressure shading (`Render contact surface with pressure`)
and the contact mesh (`Render contact surface edges`).
By default, the force vectors are drawn at fixed length. We can draw each force
according to its magnitude by `Vector scaling mode` and `Global scale of all
vectors`. The following picture shows that the floor-plate contact force is
slightly stronger than the floor-ball contact force to compensate for gravity.
Vector scaling mode = Scaled (default Fixed Length)
Global scale of all vectors = 0.001 (default 0.300)
@image html "multibody/hydroelastics/images/drake-vis-07.png"
@subsection hug_pitfalls Pitfalls/Troubleshooting
Here are various ways that hydroelastic contact may surprise you.
- By default, a rigid body is not a rigid hydroelastic body until users say
so. Otherwise, it is ignored by the hydroelastic contact model and might get
point contact instead.
- Users need to call AddRigidHydroelasticProperties() or use the URDF or
SDFormat tag <drake:rigid_hydroelastic/>.
- Backface culling -- the visualized contact surface is not what you
expect. Or, “Why are there holes?”
<!-- TODO(rpoyner-tri): This should come with some illustrations to make this
clear. -->
- Hydroelastic modulus is not properly a material property; it combines
material and geometry.
- Make the sphere bigger, the force gets weaker for the same contact surface.
- “I don’t seem to be getting any contact surfaces although my spheres are
clearly overlapping!” Depending on how coarsely you tessellated your geometry
(a sphere, at its coarsest, is an octahedron), there can be a large amount of
error between the primitive surface and discrete mesh’s surface. Make sure
you visualize the hydro meshes and have what you expect.
- Stiff and coarse is seldom a good thing. The stiffer an object is, the more
the details of the discrete tessellation will directly contribute to the
dynamics.
<!-- TODO(rpoyner-tri): Ideally, there should be a demo that shows a coarse
sphere with decreasing elasticity rolling would be good. One rolls like
an 8-sided dice. One more closely approximates a sphere. -->
- Getting moments out of the contact depends on how many elements are in the
contact surface. If the elements of the two contributing meshes are much
larger than the actual contact surface, the contact can become, in essence,
point contact.
- Half spaces are not represented by meshes. They don’t contribute *any*
geometry to the resultant contact surface. The contact surface’s refinement
will depend on the other geometry’s level of refinement.
@subsubsection hug_tips Tips and Tricks
This is a random collection of things we can do to maximize the benefits of the
hydroelastic contact model. Some of these tricks accommodate current
implementation limitations, and some are to work within the theoretical
framework.
@paragraph hug_gaming Gaming the model
- Rigid meshes need not be closed. You can use this to provide fine grained
control over where a contact surface can actually exist. Be careful to have a
consistent direction of surface normals on the triangles. They should point
outward.
- For a given relative configuration between bodies, the magnitude of force can
be tuned in two ways: increasing the hydroelastic modulus and/or scaling the
geometry up (in essence, increasing the average penetration depth).
@section hydro_appendix_a Appendix A: Compliant Contact Models
@subsection hug_point_contact_theory Compliant Point Contact
Before we get into hydroelastic contact, it’s worth describing the compliant
point contact model as a reference model. The point contact model defines the
contact force by determining the minimum translational displacement (MTD). The
minimum translational displacement is the smallest relative displacement
between two volumes that will take them from intersecting to just
touching. This quantity need not be unique (if two spheres have coincident
centers, any direction will serve). Once we have this displacement, we get
three quantities that we use to define the contact force:
- The direction of the displacement vector is the contact normal.
- The magnitude is a measure of the amount of penetration (and is correlated
with the magnitude of the normal component of the contact force).
- Two witness points for the MTD. The witness points comprise one point on
the surface of each volume such that when we apply the minimum
translational displacement, they are coincident. We use the witness points
(and other physical parameters) to define the point at which the contact
force is applied.
This model is simple to implement and cheap to compute, but has some drawbacks.
- A single measure of “maximum penetration” cannot distinguish between a large
intersecting volume and a small intersecting volume (see Figure 1). The two
intersections would produce the same amount of contact force despite the fact
that one is clearly compressing more material.
- Contact along a large interface is treated as contact at a single point (see
Figure 2). Effects that depend on a contact interface over a domain with
non-zero area disappear (e.g., torsional friction).
- The witness points are not necessarily unique. This means,
generally, there is no guarantee that the witness points will be consistent
from frame to frame, which means that the point at which the force is applied
will not be consistent. This can produce non-physical artifacts like sudden
changes in force direction.
@image html "multibody/hydroelastics/images/contact-fig-01.png"
Figure 1: Two intersections with significantly different intersecting volumes
characterized with the same measure: d.
@image html "multibody/hydroelastics/images/contact-fig-02.png"
Figure 2: Modeling contact forces with point contact (considering the blue half
space as rigid). (a) the actual intersection of the simulated bodies. (b) the
conceptual deformation of the orange body creating a large area of contact. (c)
how point contact sees the deformation: contact at a single point.
Hydroelastic contact was created to address some of the short-comings in point
contact. In fact, one might argue that many of the strategies used to mitigate
the shortcomings of point contact (such as using lots of points) push it closer
and closer to hydroelastic contact.
@subsection hug_hydro_theory Hydroelastic Contact
Hydroelastic Contact is another compliant contact formulation. It was
originally introduced by @ref Elandt2019 "[Elandt 2019]". Modifications and
further development of the model can be found in
@ref Masterjohn2022 "[Masterjohn 2022]". In Drake, we refer to this model as
the “hydroelastic” model. It differs from point contact in how it characterizes
the contact. Rather than a single point, it imagines an entire contact
surface. This surface is an approximation of the contact surface as visualized
in Figure 2(b).
When two objects come into contact, forces are produced due to deformation
("strain") of the objects at the contact interface. At first touch, there are no
forces but as the objects are pressed further they deform to produce a region
over which contact pressure is non-zero, causing equal-and-opposite forces to
act on the objects. Calculating the actual deformations is expensive.
Hydroelastic contact is based on the idea that for relatively small deformations
we can approximate the resulting contact interface and pressure distribution
without having to compute the actual deformations. We do that by precalculating
a "pressure field" on the interior of compliant objects (see Figure 3). The
pressure field approximates the pressure that would result from deforming the
surface to some point within the field. A point on the surface (that is, no
deformation) experiences zero pressure, but as it is pressed inward, it
experiences an increase in pressure (up to a maximum pressure on the interior of
the body). When two bodies are colliding, we look for a surface in the
intersecting volume where the pressure on the surface is the same in each
object; it’s an equilibrium surface (see Figure 4). There is pressure defined
across the entire contact surface. It is integrated to define the resultant
contact force and moment.
@image html "multibody/hydroelastics/images/contact-fig-03.png"
Figure 3: Three shapes and possible pressure fields in the interior of the
object. Pressure is zero at the outer boundary, and maximum on the interior.
@image html "multibody/hydroelastics/images/contact-fig-04.png"
Figure 4: The equilibrium contact surface (pale green) between two bodies where
the left-hand, yellow body has (a) less compliance, (b) equal compliance, and
(c) greater compliance.
This equilibrium surface has important properties:
- The contact surface will always be contained within the intersecting volume.
- The surface’s edge will always lie on the surface of both objects and have
zero pressure.
- The location of the surface depends on the relative compliance of the two
objects. As one object becomes more rigid than the other, the contact surface
begins to converge to its surface (see Figure 4). As one surface becomes
perfectly rigid, the other object deforms completely to conform to its shape.
- The contacting bodies need not be convex, nor will the contact surface
between two objects necessarily be a single contiguous patch. For non-convex
geometries, the contact can be meaningfully represented by multiple disjoint
patches. The resultant contact force will still be meaningful.
- The resultant contact force is continuous with respect to the relative pose
between bodies. In fact, the contact surface’s mesh, its area, and the
pressures measured on the surface are likewise continuous.
@subsection hug_hydro_practice Hydroelastic Contact in practice
The theory operates on arbitrary geometries and pressure fields. In practice,
we operate on discrete representations of both the geometry and the field.
Compliant objects are represented by tetrahedral meshes. The Drake data
type is @ref drake::geometry::VolumeMesh "VolumeMesh". The pressure fields on
those meshes are piecewise linear.
The resulting contact surface is likewise a discrete mesh. This mesh may be
built of nothing but triangles or polygons. The choice of representation has
various implications on the computation of contact forces (see below). The
pressure on the contact surface is likewise a piecewise linear function.
We model perfectly rigid objects (objects with no compliance at all) as
triangle surface meshes. They have no pressure field associated with them
because any penetration from the surface instantaneously produces infinite
pressure. When colliding a rigid object against a compliant object, the contact
surface always follows the surface of the rigid object. Think of it as the
compliant object doing 100% of the deformation, so it conforms to the shape of
the rigid object.
Important points to note:
- The time cost of resolving contact scales with the complexity of the contact
surface (number of faces).
- The complexity of the contact surface is a function of the complexity of the
contacting geometries.
- The best performance comes from the lowest resolution meshes that produce
“acceptable” behaviors.
- It is not universally true that every geometry is represented discretely. The
implementation may represent some shapes differently when it allows
performance improvements. The canonical example would be a half space
geometry. As a shape with infinite volume, it would be infeasible to create a
finite, discrete representation. It is also unnecessary. Intersecting meshes
directly with a half space is far more efficient.
- When an object is very near rigid it is more efficient to model it as rigid
than as a very stiff compliant object. Modeling as rigid allows us to take
advantage of the fact that the contact surface will lie on the surface of the
rigid object.
@section hydro_appendix_b Appendix B: Current state of implementation
This section will be updated as the scope and feature set of
hydroelastic contact is advanced. The main crux of this section is to clearly
indicate what can and cannot be done with hydroelastic contact.
@subsection hug_implemented What can you do with hydroelastic contact?
- Hydroelastic contact can be used with MultibodyPlant in either continuous or
discrete mode.
- You can visualize the contact surfaces, their pressure fields, and the
resultant contact forces in MeshCat as the simulation progresses. However,
for playing back recordings in MeshCat, only the contact forces and moments
are available (see issue
[19142](https://github.com/RobotLocomotion/drake/issues/19142)).
- All Drake Shape types can be used to create rigid hydroelastic bodies (this
includes arbitrary meshes defined as OBJs).
- Drake primitive Shape types (Box, Capsule, Cylinder, Ellipsoid, HalfSpace,
and Cylinder) can all be used to create both compliant hydroelastic bodies
and rigid hydroelastic bodies.
- The Drake Convex Shape type can be used both as a compliant hydroelastic body
and a rigid hydroelastic body. To use Convex, add the custom tag
`<drake:declare_convex/>` tag under the `<mesh>` tag in either an SDFormat
or URDF file.
- The Drake Mesh Shape type can be used as a compliant hydroelastic body
using a tetrahedral mesh in VTK file.
See
[examples/hydroelastic/python_nonconvex_mesh.]
(https://github.com/RobotLocomotion/drake/tree/master/examples/hydroelastic/python_nonconvex_mesh)
@subsection hug_not_yet_implemented What can’t you do with hydroelastic contact?
- You can’t get contact surfaces between two rigid hydroelastic geometries.
The contact surface between rigid geometries is ill defined and will most
likely never be supported.
The default drake::multibody::ContactModel::kHydroelasticWithFallback uses
point contact model for the rigid-rigid contact.
See @ref hug_enabling.
- Hydroelastics cannot model true deformations given the model does not
introduce state. Therefore effects such as tangential compliance or
short time scale waves are not captured by the model.
Currently we are actively developing code for deformable bodies in
@ref drake::multibody::DeformableModel.
@subsection hug_dissipation_and_solver Current dissipation models
- SAP does not support Hunt-Crossley dissipation at this time for both
point and hydroelastic contact
(issue [19320](https://github.com/RobotLocomotion/drake/issues/19320)).
See the documentation for that in the
[MultibodyPlant documentation.]
(https://drake.mit.edu/doxygen_cxx/classdrake_1_1multibody_1_1_multibody_plant.html#:~:text=%E2%81%B4%20We%20allow%20to,will%20be%20ignored.)
We allow the user to specify both hunt_crossley_dissipation (TAMSI and
continuous mode parameter) and relaxation_time (SAP specific parameter) on
the model, but the parameter may be ignored depending on your plant
configuration.
@section hydro_appendix_examples_and_tutorials Appendix C: Examples and Tutorials
- Example
[Contact between a ball, dinner plate, and floor in C++]
(https://github.com/RobotLocomotion/drake/tree/master/examples/hydroelastic/ball_plate)
uses the hydroelastic contact model for a convex ball and non-convex
dinner plate.
- Example
[Contact between a ball and paddle (box) in Python]
(https://github.com/RobotLocomotion/drake/tree/master/examples/hydroelastic/python_ball_paddle)
uses the hydroelastic contact model for a ball on stationary paddle (box).
- Example
[Contact between a bell pepper, dinner bowl, and floor in Python]
(https://github.com/RobotLocomotion/drake/tree/master/examples/hydroelastic/python_nonconvex_mesh)
uses the hydroelastic contact model for a non-convex bell pepper in
a non-convex dinner bowl.
- Example
[Slip control for a spatula handle between finger grippers in C++]
(https://github.com/RobotLocomotion/drake/tree/master/examples/hydroelastic/spatula_slip_control)
uses the hydroelastic contact model for a spatula handle between finger
grippers.
- Tutorial
[Hydroelastic Contact Basics with Jupyter Python notebook]
(https://github.com/RobotLocomotion/drake/blob/master/tutorials/hydroelastic_contact_basics.ipynb)
shows how to simulate hydroelastic contact for a compliant block dropped
on a rigid rectangular plate.
The below-left picture shows one frame of the block's contact with
the contact force as a red arrow and the contact torque as a blue arrow.
The below-right picture zooms into the hydroelastic contact surface showing
pressure distribution.
<!-- N.B. This image is also used by hydroelastic_contact_basics.ipynb. -->
@image html "multibody/hydroelastics/images/HydroelasticTutorialImage600x388.jpg"
@section hydro_references Sources referenced within this documentation
- @anchor Elandt2019 [Elandt 2019] Elandt, R., Drumwright, E., Sherman, M.,
& Ruina, A. (2019, November). A pressure field model for fast, robust
approximation of net contact force and moment between nominally rigid
objects. In 2019 IEEE/RSJ International Conference on Intelligent Robots
and Systems(IROS) (pp. 8238-8245). IEEE. https://arxiv.org/abs/1904.11433 .
- @anchor Masterjohn2022 [Masterjohn 2022] Masterjohn, J., Guoy, D., Shepherd,
J., & Castro, A. (2022). Velocity Level Approximation of Pressure Field
Contact Patches. In 2022 IEEE/RSJ International Conference on Intelligent
Robots and Systems(IROS). https://arxiv.org/abs/2110.04157 .
- @anchor Sherman2022 [Sherman 2022] Sherman, M. (2022, June). Rethinking
Contact Simulation for Robot Manipulation. Blog post in Medium.
https://medium.com/toyotaresearch/rethinking-contact-simulation-for-robot-manipulation-434a56b5ec88 .
*/
|
c8b400708dc03250d42d4bc7316c00c35d015bd4
|
e21389c404551d11c735b7172956f8d805511ea2
|
/wrappers/Fluent/CoolProp_Properties_of_Water.c
|
6d79ae5777edf8b06f901d86ac2db9f2946eca06
|
[
"MIT"
] |
permissive
|
CoolProp/CoolProp
|
38668506a110c5e7ba05df25a7077f0ae362ba6b
|
c4108e5a57e6846c553978c538d4d9981ea1d46f
|
refs/heads/master
| 2023-08-29T04:13:09.209077
| 2023-08-29T00:54:20
| 2023-08-29T00:54:20
| 19,775,824
| 671
| 375
|
MIT
| 2023-09-13T07:17:20
| 2014-05-14T10:43:50
|
C++
|
UTF-8
|
C
| false
| false
| 2,989
|
c
|
CoolProp_Properties_of_Water.c
|
#include "udf.h"
#include <string.h>
struct string;
const char FLUID[] = "Water";
const real gauge = 101325; /*operating pressure in pascal (as defined in fluent) */
double PropsSI(char*, char*, double, char*, double, char*);
/*Density of the FLUID[]*/
DEFINE_PROPERTY(water_density, c, t) {
real temperature = C_T(c, t);
real pressure = C_P(c, t) + gauge;
real density;
density = PropsSI((char*)"D", (char*)"T", temperature, (char*)"P", pressure, (char*)FLUID);
return density;
}
/*Thermal Conductivity of the FLUID[]*/
DEFINE_PROPERTY(water_thermalConductivity, c, t) {
real thermalConductivity;
real temperature = C_T(c, t);
real pressure = C_P(c, t) + gauge;
thermalConductivity = PropsSI((char*)"L", (char*)"T", temperature, (char*)"P", pressure, (char*)FLUID);
return thermalConductivity;
}
/*Viscosity of the FLUID[]*/
DEFINE_PROPERTY(water_viscosity, c, t) {
real viscosity;
real temperature = C_T(c, t);
real pressure = C_P(c, t) + gauge;
viscosity = PropsSI((char*)"V", (char*)"T", temperature, (char*)"P", pressure, (char*)FLUID);
return viscosity;
}
/*Specific heat of the FLUID[]*/
DEFINE_SPECIFIC_HEAT(water_specificHeat, temperature, Tref, enthalpy, yi) {
real pressure;
/*
density = 1.7730;
*/
/* The following commented code is supposed to get the pressure
from the cell to use with Coolprop. Left commented because
specific heat depends very little on pressure. Will increase
computational time significantly. */
Domain* domain = Get_Domain(1);
Thread* t;
cell_t c;
thread_loop_c(t, domain) {
begin_c_loop(c, t) {
real pressure = C_P(c, t) + gauge;
temperature = C_T(c, t);
real specificHeat;
specificHeat = PropsSI((char*)"C", (char*)"T", temperature, (char*)"P", pressure, (char*)FLUID);
*enthalpy = specificHeat * (temperature - Tref);
return specificHeat;
}
end_c_loop(c, t)
}
}
/* test coolprop integration */
DEFINE_ON_DEMAND(call_coolprop_water) {
real p, t, density, specificHeat, thermalConductivity, enthalpy, viscosity;
p = 101325.0;
t = 298.15;
density = PropsSI((char*)"D", (char*)"T", t, (char*)"P", p, (char*)FLUID);
specificHeat = PropsSI((char*)"C", (char*)"T", t, (char*)"P", p, (char*)FLUID);
viscosity = PropsSI((char*)"V", (char*)"T", t, (char*)"P", p, (char*)FLUID);
thermalConductivity = PropsSI((char*)"L", (char*)"T", t, (char*)"P", p, (char*)FLUID);
enthalpy = PropsSI((char*)"H", (char*)"T", t, (char*)"P", p, (char*)FLUID);
Message("p = %lf, T = %lf => density = %lf\n", p, t, density);
Message("p = %lf, T = %lf => specific heat = %lf\n", p, t, specificHeat);
Message("p = %lf, T = %lf => viscosity = %lf\n", p, t, viscosity);
Message("p = %lf, T = %lf => thermal conductivity = %lf\n", p, t, thermalConductivity);
Message("p = %lf, T = %lf => enthalpy = %lf\n", p, t, enthalpy);
}
|
1cb18f722aa8dc5204e4fd2e7b57014a78814347
|
8f3bf2d3f72e9c7022b3e2efde3d787c9ca354fc
|
/test/fuzz/tcti-spi-helper-fuzz-test.c
|
2535bd882bb44555c5074a9f51cce775428bf61d
|
[
"BSD-2-Clause"
] |
permissive
|
tpm2-software/tpm2-tss
|
27dc9cddb545a04958c29839a9cdafb0df54ff3c
|
b7bad346b4b55def7fd1cd78c8724df00dddd76c
|
refs/heads/master
| 2023-09-03T19:58:41.440023
| 2023-08-15T18:30:40
| 2023-08-16T07:09:48
| 38,320,020
| 563
| 311
|
BSD-2-Clause
| 2023-09-14T08:28:43
| 2015-06-30T16:21:57
|
C
|
UTF-8
|
C
| false
| false
| 5,881
|
c
|
tcti-spi-helper-fuzz-test.c
|
/* SPDX-License-Identifier: BSD-2-Clause */
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdbool.h>
#include <stdlib.h>
#define LOGMODULE test
#include "tss2_sys.h"
#include "tss2_tcti.h"
#include "tss2/tss2_tcti_spi_helper.h"
#include "util/log.h"
#include "test.h"
#include "test-options.h"
#include "context-util.h"
#include "tss2-sys/sysapi_util.h"
#include "tcti/tcti-fuzzing.h"
typedef struct fuzz_user_data fuzz_user_data;
struct fuzz_user_data {
size_t len;
const uint8_t *fuzz_data;
};
typedef enum {
TPM_DID_VID_HEAD = 0,
TPM_DID_VID_BODY,
TPM_ACCESS_HEAD,
TPM_ACCESS_BODY,
TPM_STS_HEAD,
TPM_STS_BODY,
TPM_RID_HEAD,
TPM_RID_BODY
} tpm_state_t;
static const unsigned char TPM_DID_VID_0[] = {0x83, 0xd4, 0x0f, 0x00, 0xd1, 0x15, 0x1b, 0x00};
static const unsigned char TPM_ACCESS_0[] = {0x80, 0xd4, 0x00, 0x00, 0xa1};
static const unsigned char TPM_STS_0[] = {0x83, 0xd4, 0x00, 0x18, 0x40, 0x00, 0x00, 0x00};
static const unsigned char TPM_RID_0[] = {0x80, 0xd4, 0x0f, 0x04, 0x00};
static bool is_init = true;
TSS2_RC platform_sleep_ms (void* user_data, int32_t milliseconds)
{
UNUSED(user_data);
UNUSED(milliseconds);
return TSS2_RC_SUCCESS;
}
TSS2_RC platform_start_timeout (void* user_data, int32_t milliseconds)
{
UNUSED(user_data);
UNUSED(milliseconds);
return TSS2_RC_SUCCESS;
}
TSS2_RC platform_timeout_expired (void* user_data, bool *is_timeout_expired)
{
UNUSED(user_data);
*is_timeout_expired = true;
return TSS2_RC_SUCCESS;
}
TSS2_RC platform_spi_acquire (void* user_data)
{
UNUSED(user_data);
return TSS2_RC_SUCCESS;
}
TSS2_RC platform_spi_release (void* user_data)
{
UNUSED(user_data);
return TSS2_RC_SUCCESS;
}
TSS2_RC platform_spi_transfer_with_wait_state (void* user_data, const void *data_out, void *data_in, size_t cnt)
{
UNUSED(user_data);
UNUSED(data_out);
UNUSED(cnt);
static tpm_state_t tpm_state = TPM_DID_VID_HEAD;
switch (tpm_state++) {
case TPM_DID_VID_HEAD:
memcpy (data_in, TPM_DID_VID_0, 4);
((unsigned char *)data_in)[3] |= 0x01;
break;
case TPM_DID_VID_BODY:
memcpy (data_in, TPM_DID_VID_0 + 4, sizeof (TPM_DID_VID_0) - 4);
break;
case TPM_ACCESS_HEAD:
memcpy (data_in, TPM_ACCESS_0, 4);
((unsigned char *)data_in)[3] |= 0x01;
break;
case TPM_ACCESS_BODY:
memcpy (data_in, TPM_ACCESS_0 + 4, sizeof (TPM_ACCESS_0) - 4);
break;
case TPM_STS_HEAD:
memcpy (data_in, TPM_STS_0, 4);
((unsigned char *)data_in)[3] |= 0x01;
break;
case TPM_STS_BODY:
memcpy (data_in, TPM_STS_0 + 4, sizeof (TPM_STS_0) - 4);
break;
case TPM_RID_HEAD:
memcpy (data_in, TPM_RID_0, 4);
((unsigned char *)data_in)[3] |= 0x01;
break;
case TPM_RID_BODY:
memcpy (data_in, TPM_RID_0 + 4, 1);
break;
default:
return TSS2_TCTI_RC_IO_ERROR;
}
return TSS2_RC_SUCCESS;
}
TSS2_RC platform_spi_transfer_fuzz (void* user_data, const void *data_out, void *data_in, size_t cnt)
{
UNUSED(data_out);
fuzz_user_data *udata = (fuzz_user_data *)user_data;
/* libfuzzer input might only be 2 bytes, but cnt might be 32 */
size_t min = cnt > udata->len ? cnt : udata->len;
memcpy(data_in, udata->fuzz_data, min);
return TSS2_RC_SUCCESS;
}
TSS2_RC platform_spi_transfer (void* user_data, const void *data_out, void *data_in, size_t cnt)
{
/*
* Use if we're past init to start fuzzing
*/
return is_init ?
platform_spi_transfer_with_wait_state(user_data, data_out, data_in, cnt) :
platform_spi_transfer_fuzz(user_data, data_out, data_in, cnt);
}
void platform_finalize(void* user_data)
{
UNUSED(user_data);
}
int
LLVMFuzzerTestOneInput (
const uint8_t *fuzz_data,
size_t size)
{
if (!fuzz_data) {
return -1;
}
TSS2_TCTI_CONTEXT *tcti_ctx = NULL;
TSS2_SYS_CONTEXT *sapi_ctx = NULL;
fuzz_user_data udata = {
.len = size,
.fuzz_data = fuzz_data
};
TSS2_TCTI_SPI_HELPER_PLATFORM conf = {
.user_data = &udata,
.sleep_ms = platform_sleep_ms,
.start_timeout = platform_start_timeout,
.timeout_expired = platform_timeout_expired,
.spi_acquire = platform_spi_acquire,
.spi_release = platform_spi_release,
.spi_transfer = platform_spi_transfer,
.finalize = platform_finalize
};
size_t tcti_size = 0;
TSS2_RC rc = Tss2_Tcti_Spi_Helper_Init (
NULL, &tcti_size, &conf);
if (rc != TSS2_RC_SUCCESS) {
LOG_ERROR("Tss2_Tcti_Spi_Helper_Init failed 0x%x", rc);
return EXIT_FAILURE;
}
tcti_ctx = (TSS2_TCTI_CONTEXT *)calloc(1, tcti_size);
if (!tcti_ctx) {
LOG_ERROR("OOM allocating TCTI");
goto error;
}
rc = Tss2_Tcti_Spi_Helper_Init (
tcti_ctx, &tcti_size, &conf);
if (rc != TSS2_RC_SUCCESS) {
LOG_ERROR("Tss2_Tcti_Spi_Helper_Init failed 0x%x", rc);
goto error;
}
is_init = false;
size_t sapi_size = Tss2_Sys_GetContextSize(0);
sapi_ctx = (TSS2_SYS_CONTEXT *)calloc(1, sapi_size);
if (!sapi_ctx) {
LOG_ERROR("OOM allocating SAPI");
goto error;
}
rc = Tss2_Sys_Initialize(sapi_ctx, sapi_size, tcti_ctx, NULL);
if (rc != TSS2_RC_SUCCESS) {
LOG_ERROR("Tss2_Sys_Initialize failed 0x%x", rc);
goto error;
}
/*
* ignore the RC (we expect jibberish from the TCTI)
* but this should get the TCTI firing through transfer.
*/
TPM2B_DIGEST buf = { 0 };
UNUSED(Tss2_Sys_GetRandom(sapi_ctx, NULL, 4, &buf, NULL));
error:
Tss2_Sys_Finalize(sapi_ctx);
free(sapi_ctx);
Tss2_Tcti_Finalize(tcti_ctx);
free(tcti_ctx);
return 0;
}
|
68165b9b3b9954f01c54643df0121851331d8e4c
|
62bf09400de89c1aa77d8c2570d7f66cec0b5d36
|
/fnet_stack/stack/fnet_raw.c
|
dc1f09fcd64e780fb82939b9f05447bfaf1adf9a
|
[
"Apache-2.0"
] |
permissive
|
butok/FNET
|
41b1d2ec4cc683c1b5c188a17ab6a4bb890a6af6
|
ea43715752e6f6823bfcc8bdc94e440443112e7c
|
refs/heads/master
| 2023-08-03T16:32:09.317085
| 2023-07-20T07:01:55
| 2023-07-20T07:01:55
| 50,664,554
| 115
| 40
|
Apache-2.0
| 2023-07-20T07:01:56
| 2016-01-29T13:39:30
|
C
|
UTF-8
|
C
| false
| false
| 17,394
|
c
|
fnet_raw.c
|
/**************************************************************************
*
* Copyright 2011-2017 by Andrey Butok. FNET Community.
*
***************************************************************************
*
* 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.
*
***************************************************************************
*
* RAW socket implementation.
*
***************************************************************************/
#include "fnet.h"
#include "fnet_raw.h"
#include "fnet_ip_prv.h"
#include "fnet_prot.h"
#if FNET_CFG_RAW
/************************************************************************
* Function Prototypes
*************************************************************************/
static fnet_return_t _fnet_raw_attach( fnet_socket_if_t *sk );
static fnet_return_t _fnet_raw_detach( fnet_socket_if_t *sk );
static fnet_return_t _fnet_raw_connect( fnet_socket_if_t *sk, struct fnet_sockaddr *foreign_addr);
static fnet_int32_t _fnet_raw_snd( fnet_socket_if_t *sk, const fnet_uint8_t *buf, fnet_size_t len, fnet_flag_t flags, const struct fnet_sockaddr *addr);
static fnet_int32_t _fnet_raw_rcv(fnet_socket_if_t *sk, fnet_uint8_t *buf, fnet_size_t len, fnet_flag_t flags, struct fnet_sockaddr *addr);
static fnet_return_t _fnet_raw_shutdown( fnet_socket_if_t *sk, fnet_sd_flags_t how );
static void _fnet_raw_release(void);
static fnet_error_t _fnet_raw_output(struct fnet_sockaddr *src_addr, const struct fnet_sockaddr *dest_addr, fnet_uint8_t protocol_number, fnet_socket_option_t *sockoption, fnet_netbuf_t *nb);
/************************************************************************
* Global Data Structures
*************************************************************************/
/************************************************************************
* Protocol API structures.
************************************************************************/
static const fnet_socket_prot_if_t fnet_raw_socket_api =
{
FNET_FALSE, /* Flag that protocol is connection oriented.*/
_fnet_raw_attach, /* Protocol "attach" function.*/
_fnet_raw_detach, /* Protocol "detach" function.*/
_fnet_raw_connect, /* Protocol "connect" function.*/
0, /* Protocol "accept" function.*/
_fnet_raw_rcv, /* Protocol "receive" function.*/
_fnet_raw_snd, /* Protocol "send" function.*/
_fnet_raw_shutdown, /* Protocol "shutdown" function.*/
_fnet_ip_setsockopt, /* Protocol "setsockopt" function.*/
_fnet_ip_getsockopt, /* Protocol "getsockopt" function.*/
0, /* Protocol "listen" function.*/
};
fnet_prot_if_t fnet_raw_prot_if =
{
.family = AF_SUPPORTED, /* Address domain family.*/
.type = SOCK_RAW, /* Socket type used for.*/
.prot_release = _fnet_raw_release, /* Protocol release function.*/
.prot_input = _fnet_raw_input, /* Protocol input function,.*/
.socket_api = &fnet_raw_socket_api /* Socket API */
};
/************************************************************************
* DESCRIPTION: This function releases all sockets associated
* with RAW protocol.
*************************************************************************/
static void _fnet_raw_release( void )
{
while(fnet_raw_prot_if.head)
{
_fnet_socket_release(&fnet_raw_prot_if.head, fnet_raw_prot_if.head);
}
}
/************************************************************************
* DESCRIPTION: RAW output function
*************************************************************************/
static fnet_error_t _fnet_raw_output( struct fnet_sockaddr *src_addr, const struct fnet_sockaddr *dest_addr, fnet_uint8_t protocol_number,
fnet_socket_option_t *sockoption, fnet_netbuf_t *nb )
{
fnet_error_t error = FNET_ERR_OK;
fnet_netif_t *netif = _fnet_netif_get_by_scope_id( dest_addr->sa_scope_id );
#if FNET_CFG_IP4
if(dest_addr->sa_family == AF_INET)
{
error = _fnet_ip4_output(netif, ((struct fnet_sockaddr_in *)(src_addr))->sin_addr.s_addr,
((const struct fnet_sockaddr_in *)(dest_addr))->sin_addr.s_addr,
protocol_number,
sockoption->ip4_opt.tos,
#if FNET_CFG_MULTICAST
(fnet_uint8_t)((FNET_IP4_ADDR_IS_MULTICAST(((const struct fnet_sockaddr_in *)(dest_addr))->sin_addr.s_addr) ? sockoption->ip4_opt.ttl_multicast : sockoption->ip4_opt.ttl)),
#else
sockoption->ip4_opt.ttl,
#endif /* FNET_CFG_MULTICAST */
nb, FNET_FALSE, sockoption->so_dontroute,
0
);
}
#endif
#if FNET_CFG_IP6
if(dest_addr->sa_family == AF_INET6)
{
error = _fnet_ip6_output( netif,
fnet_socket_addr_is_unspecified(src_addr) ? FNET_NULL : & ((struct fnet_sockaddr_in6 *)(src_addr))->sin6_addr.s6_addr,
&((const struct fnet_sockaddr_in6 *)(dest_addr))->sin6_addr.s6_addr,
protocol_number,
FNET_IP6_ADDR_IS_MULTICAST(&((const struct fnet_sockaddr_in6 *)(dest_addr))->sin6_addr.s6_addr) ? sockoption->ip6_opt.hops_multicast : sockoption->ip6_opt.hops_unicast,
nb, 0);
}
#endif
return (error);
}
/************************************************************************
* DESCRIPTION: RAW input function.
*************************************************************************/
void _fnet_raw_input(fnet_netif_t *netif, struct fnet_sockaddr *foreign_addr, struct fnet_sockaddr *local_addr, fnet_netbuf_t *nb, fnet_netbuf_t *ip_nb)
{
fnet_socket_if_t *sock;
fnet_socket_if_t *last;
fnet_netbuf_t *nb_tmp;
fnet_uint32_t protocol_number;
if(netif && nb && ip_nb && (nb->total_length))
{
#if FNET_CFG_IP4
if(foreign_addr->sa_family == AF_INET)
{
protocol_number = (fnet_uint32_t)((fnet_ip4_header_t *)(ip_nb->data_ptr))->protocol;
}
else
#endif
#if FNET_CFG_IP6
if(foreign_addr->sa_family == AF_INET6)
{
protocol_number = (fnet_uint32_t)((fnet_ip6_header_t *)(ip_nb->data_ptr))->next_header;
}
else
#endif
{
protocol_number = 0u;
}
/* Demultiplex broadcast & multicast datagrams.*/
if((_fnet_socket_addr_is_broadcast(local_addr, netif)) || (fnet_socket_addr_is_multicast(local_addr)))
{
last = 0;
for (sock = fnet_raw_prot_if.head; sock != 0; sock = sock->next)
{
/* Ignore local port number.*/
/* Check protocol number.*/
if(sock->protocol_number != protocol_number)
{
continue; /* => ignore.*/
}
#if FNET_CFG_MULTICAST
if(fnet_socket_addr_is_multicast(local_addr))
{
fnet_index_t m;
fnet_bool_t for_us = FNET_FALSE;
#if FNET_CFG_IP4
if(local_addr->sa_family == AF_INET)
{
for(m = 0u; m < FNET_CFG_MULTICAST_SOCKET_MAX; m++)
{
if(sock->ip4_multicast_entry[m])
{
if((sock->ip4_multicast_entry[m]->group_addr == ((struct fnet_sockaddr_in *)(local_addr))->sin_addr.s_addr) && (sock->ip4_multicast_entry[m]->netif == netif ))
{
for_us = FNET_TRUE;
}
}
}
}
#endif
#if FNET_CFG_IP6
if(local_addr->sa_family == AF_INET6)
{
for(m = 0u; m < FNET_CFG_MULTICAST_SOCKET_MAX; m++)
{
if(sock->ip6_multicast_entry[m])
{
if(FNET_IP6_ADDR_EQUAL(&sock->ip6_multicast_entry[m]->group_addr, &((struct fnet_sockaddr_in6 *)(local_addr))->sin6_addr.s6_addr) && (sock->ip6_multicast_entry[m]->netif == netif))
{
for_us = FNET_TRUE;
}
}
}
}
#endif
if(for_us == FNET_FALSE)
{
continue;
}
}
else
#endif /* FNET_CFG_MULTICAST */
{
/* Compare local address.*/
if(!fnet_socket_addr_is_unspecified(&sock->local_addr))
{
if(!fnet_socket_addr_are_equal(&sock->local_addr, local_addr))
{
continue;
}
}
/* Compare foreign address and port number.*/
if(!fnet_socket_addr_is_unspecified(&sock->foreign_addr))
{
if((!fnet_socket_addr_are_equal(&sock->foreign_addr, foreign_addr)) )
{
continue;
}
}
}
if((last != 0) && (last->receive_buffer.is_shutdown == FNET_FALSE))
{
if((nb_tmp = _fnet_netbuf_copy(nb, 0u, FNET_NETBUF_COPYALL, FNET_FALSE)) != 0)
{
if(_fnet_socket_buffer_append_address(&(last->receive_buffer), nb_tmp, foreign_addr) == FNET_ERR)
{
_fnet_netbuf_free_chain(nb_tmp);
}
}
}
last = sock;
}
if(last == 0)
{
goto BAD;
}
if(last->receive_buffer.is_shutdown) /* Is shutdown.*/
{
goto BAD;
}
/* Copy buffer.*/
if((nb_tmp = _fnet_netbuf_copy(nb, 0u, FNET_NETBUF_COPYALL, FNET_FALSE)) != 0)
{
if(_fnet_socket_buffer_append_address(&(last->receive_buffer), nb_tmp, foreign_addr) == FNET_ERR)
{
_fnet_netbuf_free_chain(nb_tmp);
goto BAD;
}
}
else
{
goto BAD;
}
}
else /* For unicast datagram.*/
{
sock = _fnet_socket_lookup(fnet_raw_prot_if.head, local_addr, foreign_addr, protocol_number);
if(sock)
{
if(sock->receive_buffer.is_shutdown) /* Is shutdown.*/
{
goto BAD;
}
/* Copy buffer.*/
if((nb_tmp = _fnet_netbuf_copy(nb, 0u, FNET_NETBUF_COPYALL, FNET_FALSE)) != 0)
{
if(_fnet_socket_buffer_append_address(&(sock->receive_buffer), nb_tmp, foreign_addr) == FNET_ERR)
{
_fnet_netbuf_free_chain(nb_tmp);
goto BAD;
}
}
else
{
goto BAD;
}
}
}
}
BAD:
return;
}
/************************************************************************
* DESCRIPTION: RAW attach function.
*************************************************************************/
static fnet_return_t _fnet_raw_attach( fnet_socket_if_t *sk )
{
#if FNET_CFG_IP4
sk->options.ip4_opt.ttl = FNET_RAW_TTL;
sk->options.ip4_opt.tos = 0u;
#endif
#if FNET_CFG_IP6
sk->options.ip6_opt.hops_unicast = 0u; /* Defined by ND.*/
#endif
sk->send_buffer.count_max = FNET_RAW_TX_BUF_MAX;
sk->receive_buffer.count_max = FNET_RAW_RX_BUF_MAX;
return (FNET_OK);
}
/************************************************************************
* DESCRIPTION: RAW close function.
*************************************************************************/
static fnet_return_t _fnet_raw_detach( fnet_socket_if_t *sk )
{
fnet_isr_lock();
_fnet_socket_release(&fnet_raw_prot_if.head, sk);
fnet_isr_unlock();
return (FNET_OK);
}
/************************************************************************
* DESCRIPTION: RAW shutdown function.
*************************************************************************/
static fnet_return_t _fnet_raw_shutdown( fnet_socket_if_t *sk, fnet_sd_flags_t how )
{
fnet_isr_lock();
if((how & SD_READ) != 0u)
{
sk->receive_buffer.is_shutdown = FNET_TRUE;
_fnet_socket_buffer_release(&sk->receive_buffer);
}
if((how & SD_WRITE) != 0u)
{
sk->send_buffer.is_shutdown = FNET_TRUE;
}
fnet_isr_unlock();
return (FNET_OK);
}
/************************************************************************
* DESCRIPTION: RAW connect function.
*************************************************************************/
static fnet_return_t _fnet_raw_connect( fnet_socket_if_t *sk, struct fnet_sockaddr *foreign_addr)
{
fnet_isr_lock();
fnet_memcpy(&sk->foreign_addr, foreign_addr, sizeof(sk->foreign_addr));
sk->local_addr.sa_port = 0u;
sk->foreign_addr.sa_port = 0u;
sk->state = SS_CONNECTED;
_fnet_socket_buffer_release(&sk->receive_buffer);
fnet_isr_unlock();
return (FNET_OK);
}
/************************************************************************
* DESCRIPTION: RAW send function.
*************************************************************************/
static fnet_int32_t _fnet_raw_snd( fnet_socket_if_t *sk, const fnet_uint8_t *buf, fnet_size_t len, fnet_flag_t flags, const struct fnet_sockaddr *addr)
{
fnet_netbuf_t *nb;
fnet_error_t error = FNET_ERR_OK;
const struct fnet_sockaddr *foreign_addr;
fnet_bool_t flags_save = FNET_FALSE;
fnet_isr_lock();
if(len > sk->send_buffer.count_max)
{
error = FNET_ERR_MSGSIZE; /* Message too long. */
goto ERROR;
}
if(addr)
{
foreign_addr = addr;
}
else
{
foreign_addr = &sk->foreign_addr;
}
if((nb = _fnet_netbuf_from_buf(buf, len, FNET_FALSE)) == 0)
{
error = FNET_ERR_NOMEM; /* Cannot allocate memory.*/
goto ERROR;
}
if((flags & MSG_DONTROUTE) != 0u) /* Save */
{
flags_save = sk->options.so_dontroute;
sk->options.so_dontroute = FNET_TRUE;
}
error = _fnet_raw_output(&sk->local_addr, foreign_addr, (fnet_uint8_t)sk->protocol_number, &(sk->options), nb);
if((flags & MSG_DONTROUTE) != 0u) /* Restore.*/
{
sk->options.so_dontroute = flags_save;
}
if((error == FNET_ERR_OK) && (sk->options.local_error == FNET_ERR_OK)) /* We get RAW or ICMP error.*/
{
fnet_isr_unlock();
return (fnet_int32_t)(len);
}
ERROR:
_fnet_socket_set_error(sk, error);
fnet_isr_unlock();
return (FNET_ERR);
}
/************************************************************************
* DESCRIPTION :RAW receive function.
*************************************************************************/
static fnet_int32_t _fnet_raw_rcv(fnet_socket_if_t *sk, fnet_uint8_t *buf, fnet_size_t len, fnet_flag_t flags, struct fnet_sockaddr *addr)
{
fnet_error_t error = FNET_ERR_OK;
fnet_int32_t length;
struct fnet_sockaddr foreign_addr;
fnet_memset_zero ((void *)&foreign_addr, sizeof(foreign_addr));
#if FNET_CFG_TCP_URGENT
if(flags & MSG_OOB)
{
error = FNET_ERR_OPNOTSUPP; /* Operation not supported.*/
goto ERROR;
}
#endif /* FNET_CFG_TCP_URGENT */
if((length = _fnet_socket_buffer_read_address(&(sk->receive_buffer), buf,
len, &foreign_addr, ((flags & MSG_PEEK) == 0u) ? FNET_TRUE : FNET_FALSE)) == FNET_ERR)
{
/* The message was too large to fit into the specified buffer and was truncated.*/
error = FNET_ERR_MSGSIZE;
goto ERROR;
}
if((error == FNET_ERR_OK) && (sk->options.local_error == FNET_ERR_OK)) /* We get RAW or ICMP error.*/
{
if(addr)
{
_fnet_socket_addr_copy(&foreign_addr, addr);
}
return (length);
}
ERROR:
_fnet_socket_set_error(sk, error);
return (FNET_ERR);
}
#endif /* FNET_CFG_RAW */
|
a3b864e09f5752258ec95c7fcc5580709fb52dbe
|
aa3befea459382dc5c01c925653d54f435b3fb0f
|
/boards/xtensa/esp32s3/common/src/esp32s3_board_tim.c
|
216a091728f176c4b025ba4ef90d69b026c803ff
|
[
"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,542
|
c
|
esp32s3_board_tim.c
|
/****************************************************************************
* boards/xtensa/esp32s3/common/src/esp32s3_board_tim.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 <sys/types.h>
#include <debug.h>
#ifdef CONFIG_ONESHOT
#include <nuttx/timers/oneshot.h>
#ifdef CONFIG_CPULOAD_ONESHOT
#include <nuttx/clock.h>
#endif
#endif
#include "esp32s3_board_tim.h"
#include "esp32s3_tim.h"
#include "esp32s3_tim_lowerhalf.h"
#ifdef CONFIG_ONESHOT
#include "esp32s3_oneshot.h"
#endif
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: config_oneshot_timer
*
* Description:
* Configure the oneshot timer driver.
*
* Returned Value:
* Zero (OK) is returned on success; A negated errno value is returned
* to indicate the nature of any failure.
*
****************************************************************************/
#ifdef CONFIG_ONESHOT
static int config_oneshot_timer(int timer, uint16_t resolution)
{
int ret = OK;
struct oneshot_lowerhalf_s *os_lower = NULL;
os_lower = oneshot_initialize(timer, resolution);
if (os_lower == NULL)
{
syslog(LOG_ERR, "Failed to initialize oneshot timer.\n");
return -EBUSY;
}
#if defined(CONFIG_CPULOAD_ONESHOT)
/* Configure the oneshot timer to support CPU load measurement */
nxsched_oneshot_extclk(os_lower);
#else
ret = oneshot_register("/dev/oneshot", os_lower);
if (ret < 0)
{
syslog(LOG_ERR, "Failed to register oneshot device: %d\n", ret);
}
#endif /* CONFIG_CPULOAD_ONESHOT */
return ret;
}
#endif
/****************************************************************************
* Name: board_tim_init
*
* Description:
* Configure the timer driver.
*
* Returned Value:
* Zero (OK) is returned on success; A negated errno value is returned
* to indicate the nature of any failure.
*
****************************************************************************/
int board_tim_init(void)
{
int ret = OK;
#if defined(CONFIG_ESP32S3_TIMER0) && !defined(CONFIG_ONESHOT)
ret = esp32s3_timer_initialize("/dev/timer0", ESP32S3_TIMER0);
if (ret < 0)
{
syslog(LOG_ERR, "Failed to initialize TIMER0: %d\n", ret);
}
#endif
#if defined(CONFIG_ESP32S3_TIMER1)
ret = esp32s3_timer_initialize("/dev/timer1", ESP32S3_TIMER1);
if (ret < 0)
{
syslog(LOG_ERR, "Failed to initialize TIMER1: %d\n", ret);
}
#endif
#if defined(CONFIG_ESP32S3_TIMER2)
ret = esp32s3_timer_initialize("/dev/timer2", ESP32S3_TIMER2);
if (ret < 0)
{
syslog(LOG_ERR, "Failed to initialize TIMER2: %d\n", ret);
}
#endif
#if defined(CONFIG_ESP32S3_TIMER3)
ret = esp32s3_timer_initialize("/dev/timer3", ESP32S3_TIMER3);
if (ret < 0)
{
syslog(LOG_ERR, "Failed to initialize TIMER3: %d\n", ret);
}
#endif
#if defined(CONFIG_ONESHOT) && defined(CONFIG_ESP32S3_TIMER0)
/* Now register one oneshot driver */
ret = config_oneshot_timer(ESP32S3_TIMER0, ONESHOT_RESOLUTION_US);
if (ret < 0)
{
syslog(LOG_ERR, "Failed to initialize oneshot timer: %d\n", ret);
}
#endif /* CONFIG_ONESHOT */
return ret;
}
|
99efc336741fe140292641dc3bbb754ae69e7c10
|
54a60696114ae0fc8233baf0111f3b0cf72be5b9
|
/inform7/Tests/Test Makes/Eg8-C/Eg8.c
|
7446efcbf9121172a1084a4915af51b207eec407
|
[
"Artistic-2.0",
"LicenseRef-scancode-free-unknown",
"Glulxe"
] |
permissive
|
ganelson/inform
|
de89a3df0fa5b40660707a7c66853cf5b066b1c9
|
56be55c4879b133a37fcd55fcd2452868a881551
|
refs/heads/master
| 2023-09-01T01:08:43.133920
| 2023-08-31T23:06:22
| 2023-08-31T23:06:22
| 169,170,146
| 1,130
| 63
|
Artistic-2.0
| 2023-09-12T09:56:18
| 2019-02-05T00:18:15
|
C
|
UTF-8
|
C
| false
| false
| 684
|
c
|
Eg8.c
|
#include "inform7_clib.h"
#include "inform7_symbols.h"
i7word_t collatz(i7process_t *proc, i7word_t x) {
printf("MR C: My friend Mrs I calls my attention to %d, ", x);
if (x == 1) {
printf("so I win! Haha!\n");
} else if (x % 2 == 0) {
printf("so I divide by two.\n");
i7_F_run_the_collatz_algorithm_on_X(proc, x/2);
} else {
printf("so I triple and add one.\n");
i7_F_run_the_collatz_algorithm_on_X(proc, 3*x + 1);
}
return 0;
}
int main(int argc, char **argv) {
i7process_t proc = i7_new_process();
int exit_code = i7_run_process(&proc);
if (exit_code == 1) {
printf("*** Fatal error: halted ***\n");
fflush(stdout); fflush(stderr);
}
return exit_code;
}
|
7fc92a022f0f2260c542a7619215e94781464c79
|
2c052c996d4267623276a681308bf87ea7388f60
|
/src/runtime/sg.c
|
8f4c720f1d2ec36251237d1872fc1cd44f31a1d7
|
[
"Apache-2.0"
] |
permissive
|
nanovms/nanos
|
17d3ce113b63c4370e40d291b8fd8fb9d943c02d
|
9085e091e5250fc58bf036591c8959e05fd7957f
|
refs/heads/master
| 2023-08-25T16:49:14.521701
| 2023-08-25T14:00:54
| 2023-08-25T14:14:13
| 115,159,616
| 2,055
| 131
|
Apache-2.0
| 2023-09-14T17:16:19
| 2017-12-23T00:25:34
|
C
|
UTF-8
|
C
| false
| false
| 7,804
|
c
|
sg.c
|
#ifdef KERNEL
#include <kernel.h>
#else
#include <runtime.h>
#endif
//#define SG_DEBUG
#if defined(SG_DEBUG)
#define sg_debug(x, ...) do {rprintf("SG: " x, ##__VA_ARGS__);} while(0)
#else
#define sg_debug(x, ...)
#endif
#define DEFAULT_SG_FRAGS 8
BSS_RO_AFTER_INIT static heap sg_heap;
static struct list free_sg_lists;
#ifdef KERNEL
static struct spinlock sg_spinlock; /* for free list */
static inline void sg_lock_init(void)
{
spin_lock_init(&sg_spinlock);
}
static inline void sg_lock(void)
{
spin_lock(&sg_spinlock);
}
static inline void sg_unlock(void)
{
spin_unlock(&sg_spinlock);
}
#else
#define sg_lock_init()
#define sg_lock()
#define sg_unlock()
#endif
void sg_consume(sg_list sg, u64 length)
{
sg_list_foreach(sg, sgb) {
if (length + sgb->offset >= sgb->size) {
sg_list_head_remove(sg);
length -= sg_buf_len(sgb);
sg_buf_release(sgb);
if (length == 0)
break;
} else {
sgb->offset += length;
break;
}
}
}
/* TODO clean up redundant parts of loop with macros or static closures */
/* copy content of sg, up to length bytes, into target, releasing consumed buffers */
u64 sg_copy_to_buf(void *target, sg_list sg, u64 n)
{
sg_buf sgb;
u64 remain = n;
sg_debug("%s: target %p, sg %p, length 0x%lx, count %ld\n", __func__, target, sg, length, sg->count);
while (remain > 0 && (sgb = sg_list_head_peek(sg)) != INVALID_ADDRESS) {
assert(sgb->size > sgb->offset); /* invariant: no null-length bufs */
u64 len = MIN(remain, sg_buf_len(sgb));
runtime_memcpy(target, sgb->buf + sgb->offset, len);
target += len;
sgb->offset += len;
remain -= len;
if (sgb->offset < sgb->size)
break;
sg_list_head_remove(sg);
sg_buf_release(sgb);
}
return n - remain;
}
u64 sg_move(sg_list dest, sg_list src, u64 n)
{
sg_buf ssgb;
u64 remain = n;
while (remain > 0 && (ssgb = sg_list_head_peek(src)) != INVALID_ADDRESS) {
assert(ssgb->size > ssgb->offset);
u64 len = MIN(remain, sg_buf_len(ssgb));
sg_buf dsgb = sg_list_tail_add(dest, len);
assert(dsgb != INVALID_ADDRESS);
dsgb->buf = ssgb->buf;
dsgb->size = ssgb->offset + len;
dsgb->offset = ssgb->offset;
refcount_reserve(ssgb->refcount);
dsgb->refcount = ssgb->refcount;
ssgb->offset += len;
remain -= len;
if (ssgb->offset < ssgb->size)
break;
sg_list_head_remove(src);
sg_buf_release(ssgb);
}
return n - remain;
}
u64 sg_zero_fill(sg_list sg, u64 n)
{
sg_buf sgb;
u64 remain = n;
while (remain > 0 && (sgb = sg_list_head_peek(sg)) != INVALID_ADDRESS) {
assert(sgb->size > sgb->offset);
u64 len = MIN(remain, sg_buf_len(sgb));
zero(sgb->buf + sgb->offset, len);
sgb->offset += len;
remain -= len;
if (sgb->offset < sgb->size)
break;
sg_list_head_remove(sg);
sg_buf_release(sgb);
}
return n - remain;
}
/* copy content of sg, up to limit bytes, into target, consuming and
deallocating everything */
u64 sg_copy_to_buf_and_release(void *target, sg_list sg, u64 n)
{
sg_buf sgb;
u64 remain = n;
sg_debug("%s: target %p, sg %p, limit 0x%lx, count %ld\n", __func__, target, sg, limit, sg->count);
while ((sgb = sg_list_head_remove(sg)) != INVALID_ADDRESS) {
assert(sgb->size > sgb->offset);
u64 len = MIN(remain, sg_buf_len(sgb));
if (len > 0) {
runtime_memcpy(target, sgb->buf, len);
target += len;
sgb->offset += len;
remain -= len;
}
/* release all buffers */
sg_buf_release(sgb);
}
deallocate_sg_list(sg);
return n - remain;
}
#ifdef KERNEL
/* Touch n bytes from sg, without consuming the SG list or its buffers, and return whether the
* buffers being accessed point to valid memory. */
boolean sg_fault_in(sg_list sg, u64 n)
{
sg_buf sgb;
u64 sgb_index = 0;
context ctx = get_current_context(current_cpu());
if (context_set_err(ctx))
return false;
while (n > 0 && (sgb = sg_list_peek_at(sg, sgb_index)) != INVALID_ADDRESS) {
s64 len = MIN(n, sg_buf_len(sgb));
n -= len;
volatile u8 *bp = sgb->buf + sgb->offset;
while (len > 0) {
(void)*bp;
bp += PAGESIZE;
len -= PAGESIZE;
}
sgb_index++;
}
context_clear_err(ctx);
return true;
}
#endif
sg_list allocate_sg_list(void)
{
sg_lock();
list l = list_get_next(&free_sg_lists);
if (l) {
list_delete(l);
sg_unlock();
return struct_from_list(l, sg_list, l);
}
sg_unlock();
sg_list sg = allocate(sg_heap, sizeof(struct sg_list));
if (!sg)
return sg;
sg->b = allocate_buffer(sg_heap, sizeof(struct sg_buf) * DEFAULT_SG_FRAGS);
if (sg->b == INVALID_ADDRESS) {
deallocate(sg_heap, sg, sizeof(struct sg_list));
return INVALID_ADDRESS;
}
list_init(&sg->l);
sg->count = 0;
return sg;
}
void deallocate_sg_list(sg_list sg)
{
buffer_clear(sg->b);
/* Recycle extremely large fragment buffers */
if (buffer_space(sg->b) > SG_FRAG_BYTE_THRESHOLD)
assert(buffer_set_capacity(sg->b, SG_FRAG_BYTE_THRESHOLD) == SG_FRAG_BYTE_THRESHOLD);
sg->count = 0;
sg_lock();
list_insert_after(&free_sg_lists, &sg->l);
sg_unlock();
}
closure_function(4, 0, void, sg_wrapped_buf_release,
refcount, refcount, heap, backed, void *, buf, bytes, padlen)
{
deallocate(sg_heap, bound(refcount), sizeof(struct refcount));
deallocate(bound(backed), bound(buf), bound(padlen));
closure_finish();
}
/* wrap linear block io into an sg reader - for uses without pagecache (stage2, dump) */
closure_function(3, 3, void, sg_wrapped_read,
block_io, block_read, int, block_order, heap, backed,
sg_list, sg, range, q, status_handler, sh)
{
int block_order = bound(block_order);
bytes length = range_span(q);
bytes padlen = pad(length, 1 << block_order);
void *buf = allocate(bound(backed), padlen);
sg_debug("%s: io %p, order %d, backed %p, sg %p, range %R, sh %p\n",
__func__, bound(block_read), block_order, bound(backed), sg, q, sh);
if (buf == INVALID_ADDRESS) {
apply(sh, timm("result", "%s: failed to allocate backed buffer of size %ld",
__func__, padlen));
return;
}
refcount refcount = allocate(sg_heap, sizeof(struct refcount));
if (refcount == INVALID_ADDRESS) {
apply(sh, timm("result", "%s: alloc failed", __func__));
return;
}
init_refcount(refcount, 1, closure(sg_heap, sg_wrapped_buf_release,
refcount, bound(backed), buf, padlen));
sg_buf sgb = sg_list_tail_add(sg, length);
assert(sgb != INVALID_ADDRESS);
sgb->buf = buf;
sgb->size = length;
sgb->offset = 0;
sgb->refcount = refcount;
assert((q.start & MASK(block_order)) == 0);
range blocks = range_rshift(irange(q.start, q.start + padlen), block_order);
sg_debug(" reading into sgb %p, buf %p, blocks %R\n", sgb, buf, blocks);
apply(bound(block_read), buf, blocks, sh);
}
sg_io sg_wrapped_block_reader(block_io bio, int block_order, heap backed)
{
sg_debug("%s, heap %p, bio %p, order %d, backed %p\n", __func__, sg_heap, bio, block_order, backed);
return closure(sg_heap, sg_wrapped_read, bio, block_order, backed);
}
void init_sg(heap h)
{
sg_debug("%s\n", __func__);
sg_heap = h;
list_init(&free_sg_lists);
sg_lock_init();
}
|
ec78a6736ee87a8633882ccdf7bd1de3d989e7b5
|
75b0d3e42c36d73afeea24326b61fc43b591140e
|
/bytestool.h
|
61d3555f232eefba1ac64f8b129dc2238b3dac7f
|
[
"MIT"
] |
permissive
|
dosgo/ngrok-c
|
0c0462ddb912d51584a448b34033b253b804dacc
|
34b7346ba368c23057503073e7250e88f8e4e1f7
|
refs/heads/master
| 2023-07-13T16:12:59.277312
| 2022-11-24T15:41:18
| 2022-11-24T15:41:18
| 31,640,501
| 607
| 270
|
MIT
| 2021-09-01T01:20:06
| 2015-03-04T05:51:22
|
C
|
UTF-8
|
C
| false
| false
| 2,088
|
h
|
bytestool.h
|
#ifndef BYTESTOOL_H_INCLUDED
#define BYTESTOOL_H_INCLUDED
#define BigEndian 1
#define LittleEndian 0
/*
void swapByteOrder(unsigned long long& ull)
{
ull = (ull >> 56) |
((ull<<40) & 0x00FF000000000000) |
((ull<<24) & 0x0000FF0000000000) |
((ull<<8) & 0x000000FF00000000) |
((ull>>8) & 0x00000000FF000000) |
((ull>>24) & 0x0000000000FF0000) |
((ull>>40) & 0x000000000000FF00) |
(ull << 56);
}
*/
/*mingw 4.3 add LL*//*
static void swapByteOrder(unsigned long long& ull)
{
ull = (ull >> 56) |
((ull<<40) & 0x00FF000000000000LL) |
((ull<<24) & 0x0000FF0000000000LL) |
((ull<<8) & 0x000000FF00000000LL) |
((ull>>8) & 0x00000000FF000000LL) |
((ull>>24) & 0x0000000000FF0000LL) |
((ull>>40) & 0x000000000000FF00LL) |
(ull << 56);
}*/
inline bool BigEndianTest()
{
unsigned int usData = 0x12345678;
unsigned char *pucData = (unsigned char*)&usData;
return *pucData == 0x78?LittleEndian:BigEndian;
}
//#define BigEndianTest()( usData = 0x12345678;unsigned char *pucData = (unsigned char*)&usData;return *pucData == 0x78?LittleEndian:BigEndian;)
#define Swap16(s) ((((s) & 0xff) << 8) | (((s) >> 8) & 0xff))
#define Swap32(l) (((l) >> 24) |(((l) &0x00ff0000) >> 8)|(((l) &0x0000ff00) << 8) |((l) << 24))
#define Swap64(ll) (((ll) >> 56) |(((ll) & 0x00ff000000000000LL) >> 40) |(((ll) & 0x0000ff0000000000LL) >> 24) |(((ll) & 0x000000ff00000000LL) >> 8)|(((ll) & 0x00000000ff000000LL) << 8) |(((ll) & 0x0000000000ff0000LL) << 24) |(((ll) & 0x000000000000ff00LL) << 40) |(((ll) << 56)))
#define BigEndian_16(s) BigEndianTest() ? s : Swap16(s)
#define LittleEndian_16(s) BigEndianTest() ? Swap16(s) : s
#define BigEndian_32(l) BigEndianTest() ? l : Swap32(l)
#define LittleEndian_32(l) BigEndianTest() ? Swap32(l) : l
#define BigEndian_64(ll) BigEndianTest() ? ll : Swap64(ll)
#define LittleEndian_64(ll) BigEndianTest() ? Swap64(ll) : ll
#endif // SSLBIO_H_INCLUDED
|
c77cd60e8d1b7c29562eebe6fa009fc5945040b1
|
9ceacf33fd96913cac7ef15492c126d96cae6911
|
/sys/arch/hppa/include/exec.h
|
7ab6826025eb8c401d0e13ac5b76135a64bf7f03
|
[] |
no_license
|
openbsd/src
|
ab97ef834fd2d5a7f6729814665e9782b586c130
|
9e79f3a0ebd11a25b4bff61e900cb6de9e7795e9
|
refs/heads/master
| 2023-09-02T18:54:56.624627
| 2023-09-02T15:16:12
| 2023-09-02T15:16:12
| 66,966,208
| 3,394
| 1,235
| null | 2023-08-08T02:42:25
| 2016-08-30T18:18:25
|
C
|
UTF-8
|
C
| false
| false
| 4,353
|
h
|
exec.h
|
/* $OpenBSD: exec.h,v 1.15 2022/02/21 12:22:21 jsg Exp $ */
/*
* Copyright (c) 1994, The University of Utah and
* the Computer Systems Laboratory at the University of Utah (CSL).
* All rights reserved.
*
* Permission to use, copy, modify and distribute this software is hereby
* granted provided that (1) source code retains these copyright, permission,
* and disclaimer notices, and (2) redistributions including binaries
* reproduce the notices in supporting documentation, and (3) all advertising
* materials mentioning features or use of this software display the following
* acknowledgement: ``This product includes software developed by the
* Computer Systems Laboratory at the University of Utah.''
*
* THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS
* IS" CONDITION. THE UNIVERSITY OF UTAH AND CSL DISCLAIM ANY LIABILITY OF
* ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
*
* CSL requests users of this software to return to csl-dist@cs.utah.edu any
* improvements that they make and grant CSL redistribution rights.
*
* Utah $Hdr: exec.h 1.3 94/12/16$
*/
#ifndef _MACHINE_EXEC_H_
#define _MACHINE_EXEC_H_
/* Size of a page in an object file. */
#define __LDPGSZ 4096
#define ARCH_ELFSIZE 32
#define ELF_TARG_CLASS ELFCLASS32
#define ELF_TARG_DATA ELFDATA2MSB
#define ELF_TARG_MACH EM_PARISC
/*
* the following MD ELF values definitions are from the:
* "Processor-Specific ELF Supplement for PA-RISC.
* Including HP and HP-UX Extensions. Version 1.43. October 6, 1997"
* http://devrsrc1.external.hp.com/STK/partner/elf-pa.pdf
*
*/
/* parisc-specific elf flags */
#define EF_PARISC_TRAPNIL 0x00010000 /* trap on NULL derefs */
#define EF_PARISC_EXT 0x00020000 /* program uses arch exts */
#define EF_PARISC_LSB 0x00040000 /* program expects LSB mode */
#define EF_PARISC_WIDE 0x00080000 /* program expects wide mode */
#define EF_PARISC_NO_KABP 0x00100000 /* don't allow kernel assisted
branch prediction */
#define EF_PARISC_LAZYSWAP 0x00200000 /* allow lazy swap allocation
for dynamically allocated
program segments */
#define EF_PARISC_ARCH 0x0000ffff /* architecture version */
#define EFA_PARISC_1_0 0x020B
#define EFA_PARISC_1_1 0x0210
#define EFA_PARISC_2_0 0x0214
/* legend: 0 - pa7000, 1 - pa7100, 2 - pa7200, 3 - pa7100LC, 4 - pa8000 */
#define PARISC_AE_QWSI 0x00000001 /* 0 : enable quadword stores */
#define PARISC_AE_FPLSU 0x00000002 /* 1: fp load/store to I/O space */
#define PARISC_AE_RSQRT 0x00000004 /* 0 : reciprocal sqrt */
#define PARISC_AE_FDCG 0x00000008 /* 0,1: fdc includes graph flushes */
#define PARISC_AE_HPAR 0x00000010 /* 3,4: half-word add/sub/av */
#define PARISC_AE_BSW 0x00000020 /* 3,4: half-word shift-add */
#define PARISC_AE_HPSA 0x00000040 /* 3 : byte-swapping stores */
#define PARISC_AE_DPR0 0x00000080 /* 2,4: data prefetch via ld to r0 */
#define SHN_PARISC_ANSI_COMMON 0xff00
#define SHN_PARISC_HUGE_COMMON 0xff01
/* sh_type */
#define SHT_PARISC_EXT 0x70000000 /* contains product-specific
extension bits */
#define SHT_PARISC_UNWIND 0x70000001 /* contains unwind table entries
sh_info contains index of
the code section to which
unwind entries apply */
#define SHT_PARISC_DOC 0x70000002 /* contains debug info for -O */
#define SHT_PARISC_ANNOT 0x70000003 /* contains code annotations */
/* sh_flags */
#define SHF_PARISC_SBP 0x80000000 /* contains code compiled for
static branch prediction */
#define SHF_PARISC_HUGE 0x40000000 /* should be allocated far from gp */
#define SHF_PARISC_SHORT 0x20000000 /* should be allocated near from gp */
#define ELF_PARISC_ARCHEXT ".PARISC.archext"
#define ELF_PARISC_MILLI ".PARISC.milli"
#define ELF_PARISC_UNWIND ".PARISC.unwind"
#define ELF_PARISC_UNWIND_INFO ".PARISC.unwind_info"
#define ELF_PARISC_SDATA ".sdata"
#define ELF_PARISC_NOBITS ".sbss"
#define STT_PARISC_MILLI 13 /* entry point of a millicode routine */
#define PT_PARISC_ARCHEXT 0x70000000 /* segment contains
.PARISC.archext section */
#define PT_PARISC_UNWIND 0x70000001 /* segment contains
.unwind section */
#define PF_PARISC_SBP 0x08000000 /* segment contains code
compiled for static branch prediction */
#endif /* _MACHINE_EXEC_H_ */
|
1d8e5798896136947a26ece4936f49f85c0397a3
|
e1cddfd754d952134e72dfd03522c5ea4fb6008e
|
/src/plugins/nat/det44/det44_in2out.c
|
5fe4a9a0658154c98b74835ccd8347dd24b8a06b
|
[
"Apache-2.0"
] |
permissive
|
FDio/vpp
|
0ad30fa1bec2975ffa6b66b45c9f4f32163123b6
|
f234b0d4626d7e686422cc9dfd25958584f4931e
|
refs/heads/master
| 2023-08-31T16:09:04.068646
| 2022-03-14T09:49:15
| 2023-08-31T09:50:00
| 96,556,718
| 1,048
| 630
|
Apache-2.0
| 2023-06-21T05:39:17
| 2017-07-07T16:29:40
|
C
|
UTF-8
|
C
| false
| false
| 30,064
|
c
|
det44_in2out.c
|
/*
* Copyright (c) 2020 Cisco and/or its affiliates.
* 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.
*/
/**
* @file
* @brief Deterministic NAT (CGN) inside to outside translation
*/
#include <vlib/vlib.h>
#include <vnet/vnet.h>
#include <vnet/ip/ip.h>
#include <vnet/fib/ip4_fib.h>
#include <vppinfra/error.h>
#include <vppinfra/elog.h>
#include <nat/det44/det44.h>
#include <nat/det44/det44_inlines.h>
#include <nat/lib/lib.h>
#include <nat/lib/inlines.h>
#include <nat/lib/nat_inlines.h>
typedef enum
{
DET44_IN2OUT_NEXT_LOOKUP,
DET44_IN2OUT_NEXT_DROP,
DET44_IN2OUT_NEXT_ICMP_ERROR,
DET44_IN2OUT_N_NEXT,
} det44_in2out_next_t;
typedef struct
{
u32 sw_if_index;
u32 next_index;
u32 session_index;
} det44_in2out_trace_t;
#define foreach_det44_in2out_error \
_(UNSUPPORTED_PROTOCOL, "Unsupported protocol") \
_(NO_TRANSLATION, "No translation") \
_(BAD_ICMP_TYPE, "unsupported ICMP type") \
_(OUT_OF_PORTS, "Out of ports") \
_(IN2OUT_PACKETS, "Good in2out packets processed")
typedef enum
{
#define _(sym,str) DET44_IN2OUT_ERROR_##sym,
foreach_det44_in2out_error
#undef _
DET44_IN2OUT_N_ERROR,
} det44_in2out_error_t;
static char *det44_in2out_error_strings[] = {
#define _(sym,string) string,
foreach_det44_in2out_error
#undef _
};
static u8 *
format_det44_in2out_trace (u8 * s, va_list * args)
{
CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
det44_in2out_trace_t *t = va_arg (*args, det44_in2out_trace_t *);
s = format (s, "DET44_IN2OUT: sw_if_index %d, next index %d, session %d",
t->sw_if_index, t->next_index, t->session_index);
return s;
}
#ifndef CLIB_MARCH_VARIANT
/**
* Get address and port values to be used for ICMP packet translation
* and create session if needed
*
* @param[in,out] node NAT node runtime
* @param[in] thread_index thread index
* @param[in,out] b0 buffer containing packet to be translated
* @param[in,out] ip0 ip header
* @param[out] p_proto protocol used for matching
* @param[out] p_value address and port after NAT translation
* @param[out] p_dont_translate if packet should not be translated
* @param d optional parameter
* @param e optional parameter
*/
u32
icmp_match_in2out_det (vlib_node_runtime_t * node,
u32 thread_index, vlib_buffer_t * b0,
ip4_header_t * ip0, ip4_address_t * addr,
u16 * port, u32 * fib_index,
nat_protocol_t * proto, void *d, void *e,
u8 * dont_translate)
{
det44_main_t *dm = &det44_main;
vlib_main_t *vm = vlib_get_main ();
icmp46_header_t *icmp0;
u32 sw_if_index0;
u32 rx_fib_index0;
nat_protocol_t protocol;
snat_det_out_key_t key0;
u32 next0 = ~0;
icmp_echo_header_t *echo0, *inner_echo0 = 0;
ip4_header_t *inner_ip0;
void *l4_header = 0;
icmp46_header_t *inner_icmp0;
snat_det_map_t *mp0 = 0;
ip4_address_t new_addr0;
u16 lo_port0, i0;
snat_det_session_t *ses0 = 0;
ip4_address_t in_addr;
u16 in_port;
*dont_translate = 0;
icmp0 = (icmp46_header_t *) ip4_next_header (ip0);
echo0 = (icmp_echo_header_t *) (icmp0 + 1);
sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX];
rx_fib_index0 = ip4_fib_table_get_index_for_sw_if_index (sw_if_index0);
if (!icmp_type_is_error_message
(vnet_buffer (b0)->ip.reass.icmp_type_or_tcp_flags))
{
protocol = NAT_PROTOCOL_ICMP;
in_addr = ip0->src_address;
in_port = vnet_buffer (b0)->ip.reass.l4_src_port;
}
else
{
/* if error message, then it's not fragmented and we can access it */
inner_ip0 = (ip4_header_t *) (echo0 + 1);
l4_header = ip4_next_header (inner_ip0);
protocol = ip_proto_to_nat_proto (inner_ip0->protocol);
in_addr = inner_ip0->dst_address;
switch (protocol)
{
case NAT_PROTOCOL_ICMP:
inner_icmp0 = (icmp46_header_t *) l4_header;
inner_echo0 = (icmp_echo_header_t *) (inner_icmp0 + 1);
in_port = inner_echo0->identifier;
break;
case NAT_PROTOCOL_UDP:
case NAT_PROTOCOL_TCP:
in_port = ((tcp_udp_header_t *) l4_header)->dst_port;
break;
default:
b0->error = node->errors[DET44_IN2OUT_ERROR_UNSUPPORTED_PROTOCOL];
next0 = DET44_IN2OUT_NEXT_DROP;
goto out;
}
}
mp0 = snat_det_map_by_user (&in_addr);
if (PREDICT_FALSE (!mp0))
{
if (PREDICT_FALSE (det44_translate (node, sw_if_index0, ip0,
IP_PROTOCOL_ICMP, rx_fib_index0)))
{
*dont_translate = 1;
goto out;
}
next0 = DET44_IN2OUT_NEXT_DROP;
b0->error = node->errors[DET44_IN2OUT_ERROR_NO_TRANSLATION];
goto out;
}
snat_det_forward (mp0, &in_addr, &new_addr0, &lo_port0);
key0.ext_host_addr = ip0->dst_address;
key0.ext_host_port = 0;
ses0 = snat_det_find_ses_by_in (mp0, &in_addr, in_port, key0);
if (PREDICT_FALSE (!ses0))
{
if (PREDICT_FALSE (det44_translate (node, sw_if_index0, ip0,
IP_PROTOCOL_ICMP, rx_fib_index0)))
{
*dont_translate = 1;
goto out;
}
if (icmp0->type != ICMP4_echo_request)
{
b0->error = node->errors[DET44_IN2OUT_ERROR_BAD_ICMP_TYPE];
next0 = DET44_IN2OUT_NEXT_DROP;
goto out;
}
for (i0 = 0; i0 < mp0->ports_per_host; i0++)
{
key0.out_port = clib_host_to_net_u16 (lo_port0 +
((i0 +
clib_net_to_host_u16
(echo0->identifier)) %
mp0->ports_per_host));
if (snat_det_get_ses_by_out (mp0, &in_addr, key0.as_u64))
continue;
ses0 =
snat_det_ses_create (thread_index, mp0,
&in_addr, echo0->identifier, &key0);
break;
}
if (PREDICT_FALSE (!ses0))
{
next0 = DET44_IN2OUT_NEXT_DROP;
b0->error = node->errors[DET44_IN2OUT_ERROR_OUT_OF_PORTS];
goto out;
}
}
if (PREDICT_FALSE
(vnet_buffer (b0)->ip.reass.icmp_type_or_tcp_flags != ICMP4_echo_request
&& !icmp_type_is_error_message (vnet_buffer (b0)->ip.
reass.icmp_type_or_tcp_flags)))
{
b0->error = node->errors[DET44_IN2OUT_ERROR_BAD_ICMP_TYPE];
next0 = DET44_IN2OUT_NEXT_DROP;
goto out;
}
u32 now = (u32) vlib_time_now (vm);
ses0->state = DET44_SESSION_ICMP_ACTIVE;
ses0->expire = now + dm->timeouts.icmp;
out:
*proto = protocol;
if (ses0)
{
*addr = new_addr0;
*fib_index = dm->outside_fib_index;
*port = ses0->out.out_port;
}
if (d)
*(snat_det_session_t **) d = ses0;
if (e)
*(snat_det_map_t **) e = mp0;
return next0;
}
#endif
#ifndef CLIB_MARCH_VARIANT
u32
det44_icmp_in2out (vlib_buffer_t * b0,
ip4_header_t * ip0,
icmp46_header_t * icmp0,
u32 sw_if_index0,
u32 rx_fib_index0,
vlib_node_runtime_t * node,
u32 next0, u32 thread_index, void *d, void *e)
{
vlib_main_t *vm = vlib_get_main ();
u16 old_id0, new_id0, port, checksum0, old_checksum0, new_checksum0;
u32 new_addr0, old_addr0, next0_tmp, fib_index;
icmp_echo_header_t *echo0, *inner_echo0;
icmp46_header_t *inner_icmp0;
ip4_header_t *inner_ip0;
ip4_address_t addr;
void *l4_header;
u8 dont_translate;
ip_csum_t sum0;
nat_protocol_t protocol;
echo0 = (icmp_echo_header_t *) (icmp0 + 1);
next0_tmp = icmp_match_in2out_det (node, thread_index, b0, ip0,
&addr, &port, &fib_index, &protocol,
d, e, &dont_translate);
if (next0_tmp != ~0)
next0 = next0_tmp;
if (next0 == DET44_IN2OUT_NEXT_DROP || dont_translate)
goto out;
if (PREDICT_TRUE (!ip4_is_fragment (ip0)))
{
sum0 =
ip_incremental_checksum_buffer (vm, b0,
(u8 *) icmp0 -
(u8 *) vlib_buffer_get_current (b0),
ntohs (ip0->length) -
ip4_header_bytes (ip0), 0);
checksum0 = ~ip_csum_fold (sum0);
if (PREDICT_FALSE (checksum0 != 0 && checksum0 != 0xffff))
{
next0 = DET44_IN2OUT_NEXT_DROP;
goto out;
}
}
old_addr0 = ip0->src_address.as_u32;
new_addr0 = ip0->src_address.as_u32 = addr.as_u32;
sum0 = ip0->checksum;
sum0 = ip_csum_update (sum0, old_addr0, new_addr0, ip4_header_t,
src_address /* changed member */ );
ip0->checksum = ip_csum_fold (sum0);
if (!vnet_buffer (b0)->ip.reass.is_non_first_fragment)
{
if (icmp0->checksum == 0)
icmp0->checksum = 0xffff;
if (!icmp_type_is_error_message (icmp0->type))
{
new_id0 = port;
if (PREDICT_FALSE (new_id0 != echo0->identifier))
{
old_id0 = echo0->identifier;
new_id0 = port;
echo0->identifier = new_id0;
sum0 = icmp0->checksum;
sum0 =
ip_csum_update (sum0, old_id0, new_id0, icmp_echo_header_t,
identifier);
icmp0->checksum = ip_csum_fold (sum0);
}
}
else
{
inner_ip0 = (ip4_header_t *) (echo0 + 1);
l4_header = ip4_next_header (inner_ip0);
if (!ip4_header_checksum_is_valid (inner_ip0))
{
next0 = DET44_IN2OUT_NEXT_DROP;
goto out;
}
/* update inner destination IP address */
old_addr0 = inner_ip0->dst_address.as_u32;
inner_ip0->dst_address = addr;
new_addr0 = inner_ip0->dst_address.as_u32;
sum0 = icmp0->checksum;
sum0 = ip_csum_update (sum0, old_addr0, new_addr0, ip4_header_t,
dst_address /* changed member */ );
icmp0->checksum = ip_csum_fold (sum0);
/* update inner IP header checksum */
old_checksum0 = inner_ip0->checksum;
sum0 = inner_ip0->checksum;
sum0 = ip_csum_update (sum0, old_addr0, new_addr0, ip4_header_t,
dst_address /* changed member */ );
inner_ip0->checksum = ip_csum_fold (sum0);
new_checksum0 = inner_ip0->checksum;
sum0 = icmp0->checksum;
sum0 =
ip_csum_update (sum0, old_checksum0, new_checksum0, ip4_header_t,
checksum);
icmp0->checksum = ip_csum_fold (sum0);
switch (protocol)
{
case NAT_PROTOCOL_ICMP:
inner_icmp0 = (icmp46_header_t *) l4_header;
inner_echo0 = (icmp_echo_header_t *) (inner_icmp0 + 1);
old_id0 = inner_echo0->identifier;
new_id0 = port;
inner_echo0->identifier = new_id0;
sum0 = icmp0->checksum;
sum0 =
ip_csum_update (sum0, old_id0, new_id0, icmp_echo_header_t,
identifier);
icmp0->checksum = ip_csum_fold (sum0);
break;
case NAT_PROTOCOL_UDP:
case NAT_PROTOCOL_TCP:
old_id0 = ((tcp_udp_header_t *) l4_header)->dst_port;
new_id0 = port;
((tcp_udp_header_t *) l4_header)->dst_port = new_id0;
sum0 = icmp0->checksum;
sum0 = ip_csum_update (sum0, old_id0, new_id0, tcp_udp_header_t,
dst_port);
icmp0->checksum = ip_csum_fold (sum0);
break;
default:
ASSERT (0);
}
}
}
if (vnet_buffer (b0)->sw_if_index[VLIB_TX] == ~0)
vnet_buffer (b0)->sw_if_index[VLIB_TX] = fib_index;
out:
return next0;
}
#endif
VLIB_NODE_FN (det44_in2out_node) (vlib_main_t * vm,
vlib_node_runtime_t * node,
vlib_frame_t * frame)
{
u32 n_left_from, *from;
u32 pkts_processed = 0;
det44_main_t *dm = &det44_main;
u32 now = (u32) vlib_time_now (vm);
u32 thread_index = vm->thread_index;
from = vlib_frame_vector_args (frame);
n_left_from = frame->n_vectors;
vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b = bufs;
u16 nexts[VLIB_FRAME_SIZE], *next = nexts;
vlib_get_buffers (vm, from, b, n_left_from);
while (n_left_from >= 2)
{
vlib_buffer_t *b0, *b1;
u32 next0, next1;
u32 sw_if_index0, sw_if_index1;
ip4_header_t *ip0, *ip1;
ip_csum_t sum0, sum1;
ip4_address_t new_addr0, old_addr0, new_addr1, old_addr1;
u16 old_port0, new_port0, lo_port0, i0;
u16 old_port1, new_port1, lo_port1, i1;
udp_header_t *udp0, *udp1;
tcp_header_t *tcp0, *tcp1;
u32 proto0, proto1;
snat_det_out_key_t key0, key1;
snat_det_map_t *mp0, *mp1;
snat_det_session_t *ses0 = 0, *ses1 = 0;
u32 rx_fib_index0, rx_fib_index1;
icmp46_header_t *icmp0, *icmp1;
b0 = *b;
b++;
b1 = *b;
b++;
/* Prefetch next iteration. */
if (PREDICT_TRUE (n_left_from >= 4))
{
vlib_buffer_t *p2, *p3;
p2 = *b;
p3 = *(b + 1);
vlib_prefetch_buffer_header (p2, LOAD);
vlib_prefetch_buffer_header (p3, LOAD);
clib_prefetch_load (p2->data);
clib_prefetch_load (p3->data);
}
next0 = DET44_IN2OUT_NEXT_LOOKUP;
next1 = DET44_IN2OUT_NEXT_LOOKUP;
ip0 = vlib_buffer_get_current (b0);
udp0 = ip4_next_header (ip0);
tcp0 = (tcp_header_t *) udp0;
sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX];
if (PREDICT_FALSE (ip0->ttl == 1))
{
vnet_buffer (b0)->sw_if_index[VLIB_TX] = (u32) ~ 0;
icmp4_error_set_vnet_buffer (b0, ICMP4_time_exceeded,
ICMP4_time_exceeded_ttl_exceeded_in_transit,
0);
next0 = DET44_IN2OUT_NEXT_ICMP_ERROR;
goto trace0;
}
proto0 = ip_proto_to_nat_proto (ip0->protocol);
if (PREDICT_FALSE (proto0 == NAT_PROTOCOL_ICMP))
{
rx_fib_index0 =
ip4_fib_table_get_index_for_sw_if_index (sw_if_index0);
icmp0 = (icmp46_header_t *) udp0;
// TODO:
next0 = det44_icmp_in2out (b0, ip0, icmp0, sw_if_index0,
rx_fib_index0, node, next0,
thread_index, &ses0, &mp0);
goto trace0;
}
mp0 = snat_det_map_by_user (&ip0->src_address);
if (PREDICT_FALSE (!mp0))
{
det44_log_info ("no match for internal host %U",
format_ip4_address, &ip0->src_address);
next0 = DET44_IN2OUT_NEXT_DROP;
b0->error = node->errors[DET44_IN2OUT_ERROR_NO_TRANSLATION];
goto trace0;
}
snat_det_forward (mp0, &ip0->src_address, &new_addr0, &lo_port0);
key0.ext_host_addr = ip0->dst_address;
key0.ext_host_port = tcp0->dst;
ses0 =
snat_det_find_ses_by_in (mp0, &ip0->src_address, tcp0->src, key0);
if (PREDICT_FALSE (!ses0))
{
for (i0 = 0; i0 < mp0->ports_per_host; i0++)
{
key0.out_port = clib_host_to_net_u16 (lo_port0 +
((i0 +
clib_net_to_host_u16
(tcp0->src)) %
mp0->ports_per_host));
if (snat_det_get_ses_by_out
(mp0, &ip0->src_address, key0.as_u64))
continue;
ses0 =
snat_det_ses_create (thread_index, mp0, &ip0->src_address,
tcp0->src, &key0);
break;
}
if (PREDICT_FALSE (!ses0))
{
/* too many sessions for user, send ICMP error packet */
vnet_buffer (b0)->sw_if_index[VLIB_TX] = (u32) ~ 0;
icmp4_error_set_vnet_buffer (b0,
ICMP4_destination_unreachable,
ICMP4_destination_unreachable_destination_unreachable_host,
0);
next0 = DET44_IN2OUT_NEXT_ICMP_ERROR;
goto trace0;
}
}
old_port0 = udp0->src_port;
udp0->src_port = new_port0 = ses0->out.out_port;
old_addr0.as_u32 = ip0->src_address.as_u32;
ip0->src_address.as_u32 = new_addr0.as_u32;
vnet_buffer (b0)->sw_if_index[VLIB_TX] = dm->outside_fib_index;
sum0 = ip0->checksum;
sum0 = ip_csum_update (sum0, old_addr0.as_u32, new_addr0.as_u32,
ip4_header_t, src_address /* changed member */ );
ip0->checksum = ip_csum_fold (sum0);
if (PREDICT_TRUE (proto0 == NAT_PROTOCOL_TCP))
{
if (tcp0->flags & TCP_FLAG_SYN)
ses0->state = DET44_SESSION_TCP_SYN_SENT;
else if (tcp0->flags & TCP_FLAG_ACK
&& ses0->state == DET44_SESSION_TCP_SYN_SENT)
ses0->state = DET44_SESSION_TCP_ESTABLISHED;
else if (tcp0->flags & TCP_FLAG_FIN
&& ses0->state == DET44_SESSION_TCP_ESTABLISHED)
ses0->state = DET44_SESSION_TCP_FIN_WAIT;
else if (tcp0->flags & TCP_FLAG_ACK
&& ses0->state == DET44_SESSION_TCP_FIN_WAIT)
snat_det_ses_close (mp0, ses0);
else if (tcp0->flags & TCP_FLAG_FIN
&& ses0->state == DET44_SESSION_TCP_CLOSE_WAIT)
ses0->state = DET44_SESSION_TCP_LAST_ACK;
else if (tcp0->flags == 0 && ses0->state == DET44_SESSION_UNKNOWN)
ses0->state = DET44_SESSION_TCP_ESTABLISHED;
sum0 = tcp0->checksum;
sum0 = ip_csum_update (sum0, old_addr0.as_u32, new_addr0.as_u32,
ip4_header_t,
dst_address /* changed member */ );
sum0 = ip_csum_update (sum0, old_port0, new_port0,
ip4_header_t /* cheat */ ,
length /* changed member */ );
mss_clamping (dm->mss_clamping, tcp0, &sum0);
tcp0->checksum = ip_csum_fold (sum0);
}
else
{
ses0->state = DET44_SESSION_UDP_ACTIVE;
if (PREDICT_FALSE (udp0->checksum))
{
sum0 = udp0->checksum;
sum0 =
ip_csum_update (sum0, old_addr0.as_u32, new_addr0.as_u32,
ip4_header_t,
dst_address /* changed member */ );
sum0 =
ip_csum_update (sum0, old_port0, new_port0,
ip4_header_t /* cheat */ ,
length /* changed member */ );
udp0->checksum = ip_csum_fold (sum0);
}
}
switch (ses0->state)
{
case DET44_SESSION_UDP_ACTIVE:
ses0->expire = now + dm->timeouts.udp;
break;
case DET44_SESSION_TCP_SYN_SENT:
case DET44_SESSION_TCP_FIN_WAIT:
case DET44_SESSION_TCP_CLOSE_WAIT:
case DET44_SESSION_TCP_LAST_ACK:
ses0->expire = now + dm->timeouts.tcp.transitory;
break;
case DET44_SESSION_TCP_ESTABLISHED:
ses0->expire = now + dm->timeouts.tcp.established;
break;
}
trace0:
if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE)
&& (b0->flags & VLIB_BUFFER_IS_TRACED)))
{
det44_in2out_trace_t *t =
vlib_add_trace (vm, node, b0, sizeof (*t));
t->sw_if_index = sw_if_index0;
t->next_index = next0;
t->session_index = ~0;
if (ses0)
t->session_index = ses0 - mp0->sessions;
}
pkts_processed += next0 != DET44_IN2OUT_NEXT_DROP;
ip1 = vlib_buffer_get_current (b1);
udp1 = ip4_next_header (ip1);
tcp1 = (tcp_header_t *) udp1;
sw_if_index1 = vnet_buffer (b1)->sw_if_index[VLIB_RX];
if (PREDICT_FALSE (ip1->ttl == 1))
{
vnet_buffer (b1)->sw_if_index[VLIB_TX] = (u32) ~ 0;
icmp4_error_set_vnet_buffer (b1, ICMP4_time_exceeded,
ICMP4_time_exceeded_ttl_exceeded_in_transit,
0);
next1 = DET44_IN2OUT_NEXT_ICMP_ERROR;
goto trace1;
}
proto1 = ip_proto_to_nat_proto (ip1->protocol);
if (PREDICT_FALSE (proto1 == NAT_PROTOCOL_ICMP))
{
rx_fib_index1 =
ip4_fib_table_get_index_for_sw_if_index (sw_if_index1);
icmp1 = (icmp46_header_t *) udp1;
next1 = det44_icmp_in2out (b1, ip1, icmp1, sw_if_index1,
rx_fib_index1, node, next1,
thread_index, &ses1, &mp1);
goto trace1;
}
mp1 = snat_det_map_by_user (&ip1->src_address);
if (PREDICT_FALSE (!mp1))
{
det44_log_info ("no match for internal host %U",
format_ip4_address, &ip0->src_address);
next1 = DET44_IN2OUT_NEXT_DROP;
b1->error = node->errors[DET44_IN2OUT_ERROR_NO_TRANSLATION];
goto trace1;
}
snat_det_forward (mp1, &ip1->src_address, &new_addr1, &lo_port1);
key1.ext_host_addr = ip1->dst_address;
key1.ext_host_port = tcp1->dst;
ses1 =
snat_det_find_ses_by_in (mp1, &ip1->src_address, tcp1->src, key1);
if (PREDICT_FALSE (!ses1))
{
for (i1 = 0; i1 < mp1->ports_per_host; i1++)
{
key1.out_port = clib_host_to_net_u16 (lo_port1 +
((i1 +
clib_net_to_host_u16
(tcp1->src)) %
mp1->ports_per_host));
if (snat_det_get_ses_by_out
(mp1, &ip1->src_address, key1.as_u64))
continue;
ses1 =
snat_det_ses_create (thread_index, mp1, &ip1->src_address,
tcp1->src, &key1);
break;
}
if (PREDICT_FALSE (!ses1))
{
/* too many sessions for user, send ICMP error packet */
vnet_buffer (b1)->sw_if_index[VLIB_TX] = (u32) ~ 0;
icmp4_error_set_vnet_buffer (b1,
ICMP4_destination_unreachable,
ICMP4_destination_unreachable_destination_unreachable_host,
0);
next1 = DET44_IN2OUT_NEXT_ICMP_ERROR;
goto trace1;
}
}
old_port1 = udp1->src_port;
udp1->src_port = new_port1 = ses1->out.out_port;
old_addr1.as_u32 = ip1->src_address.as_u32;
ip1->src_address.as_u32 = new_addr1.as_u32;
vnet_buffer (b1)->sw_if_index[VLIB_TX] = dm->outside_fib_index;
sum1 = ip1->checksum;
sum1 = ip_csum_update (sum1, old_addr1.as_u32, new_addr1.as_u32,
ip4_header_t, src_address /* changed member */ );
ip1->checksum = ip_csum_fold (sum1);
if (PREDICT_TRUE (proto1 == NAT_PROTOCOL_TCP))
{
if (tcp1->flags & TCP_FLAG_SYN)
ses1->state = DET44_SESSION_TCP_SYN_SENT;
else if (tcp1->flags & TCP_FLAG_ACK
&& ses1->state == DET44_SESSION_TCP_SYN_SENT)
ses1->state = DET44_SESSION_TCP_ESTABLISHED;
else if (tcp1->flags & TCP_FLAG_FIN
&& ses1->state == DET44_SESSION_TCP_ESTABLISHED)
ses1->state = DET44_SESSION_TCP_FIN_WAIT;
else if (tcp1->flags & TCP_FLAG_ACK
&& ses1->state == DET44_SESSION_TCP_FIN_WAIT)
snat_det_ses_close (mp1, ses1);
else if (tcp1->flags & TCP_FLAG_FIN
&& ses1->state == DET44_SESSION_TCP_CLOSE_WAIT)
ses1->state = DET44_SESSION_TCP_LAST_ACK;
else if (tcp1->flags == 0 && ses1->state == DET44_SESSION_UNKNOWN)
ses1->state = DET44_SESSION_TCP_ESTABLISHED;
sum1 = tcp1->checksum;
sum1 = ip_csum_update (sum1, old_addr1.as_u32, new_addr1.as_u32,
ip4_header_t,
dst_address /* changed member */ );
sum1 = ip_csum_update (sum1, old_port1, new_port1,
ip4_header_t /* cheat */ ,
length /* changed member */ );
mss_clamping (dm->mss_clamping, tcp1, &sum1);
tcp1->checksum = ip_csum_fold (sum1);
}
else
{
ses1->state = DET44_SESSION_UDP_ACTIVE;
if (PREDICT_FALSE (udp1->checksum))
{
sum1 = udp1->checksum;
sum1 =
ip_csum_update (sum1, old_addr1.as_u32, new_addr1.as_u32,
ip4_header_t,
dst_address /* changed member */ );
sum1 =
ip_csum_update (sum1, old_port1, new_port1,
ip4_header_t /* cheat */ ,
length /* changed member */ );
udp1->checksum = ip_csum_fold (sum1);
}
}
switch (ses1->state)
{
case DET44_SESSION_UDP_ACTIVE:
ses1->expire = now + dm->timeouts.udp;
break;
case DET44_SESSION_TCP_SYN_SENT:
case DET44_SESSION_TCP_FIN_WAIT:
case DET44_SESSION_TCP_CLOSE_WAIT:
case DET44_SESSION_TCP_LAST_ACK:
ses1->expire = now + dm->timeouts.tcp.transitory;
break;
case DET44_SESSION_TCP_ESTABLISHED:
ses1->expire = now + dm->timeouts.tcp.established;
break;
}
trace1:
if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE)
&& (b1->flags & VLIB_BUFFER_IS_TRACED)))
{
det44_in2out_trace_t *t =
vlib_add_trace (vm, node, b1, sizeof (*t));
t->sw_if_index = sw_if_index1;
t->next_index = next1;
t->session_index = ~0;
if (ses1)
t->session_index = ses1 - mp1->sessions;
}
pkts_processed += next1 != DET44_IN2OUT_NEXT_DROP;
n_left_from -= 2;
next[0] = next0;
next[1] = next1;
next += 2;
}
while (n_left_from > 0)
{
vlib_buffer_t *b0;
u32 next0;
u32 sw_if_index0;
ip4_header_t *ip0;
ip_csum_t sum0;
ip4_address_t new_addr0, old_addr0;
u16 old_port0, new_port0, lo_port0, i0;
udp_header_t *udp0;
tcp_header_t *tcp0;
u32 proto0;
snat_det_out_key_t key0;
snat_det_map_t *mp0;
snat_det_session_t *ses0 = 0;
u32 rx_fib_index0;
icmp46_header_t *icmp0;
b0 = *b;
b++;
next0 = DET44_IN2OUT_NEXT_LOOKUP;
ip0 = vlib_buffer_get_current (b0);
udp0 = ip4_next_header (ip0);
tcp0 = (tcp_header_t *) udp0;
sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX];
if (PREDICT_FALSE (ip0->ttl == 1))
{
vnet_buffer (b0)->sw_if_index[VLIB_TX] = (u32) ~ 0;
icmp4_error_set_vnet_buffer (b0, ICMP4_time_exceeded,
ICMP4_time_exceeded_ttl_exceeded_in_transit,
0);
next0 = DET44_IN2OUT_NEXT_ICMP_ERROR;
goto trace00;
}
proto0 = ip_proto_to_nat_proto (ip0->protocol);
if (PREDICT_FALSE (proto0 == NAT_PROTOCOL_ICMP))
{
rx_fib_index0 =
ip4_fib_table_get_index_for_sw_if_index (sw_if_index0);
icmp0 = (icmp46_header_t *) udp0;
next0 = det44_icmp_in2out (b0, ip0, icmp0, sw_if_index0,
rx_fib_index0, node, next0,
thread_index, &ses0, &mp0);
goto trace00;
}
mp0 = snat_det_map_by_user (&ip0->src_address);
if (PREDICT_FALSE (!mp0))
{
det44_log_info ("no match for internal host %U",
format_ip4_address, &ip0->src_address);
next0 = DET44_IN2OUT_NEXT_DROP;
b0->error = node->errors[DET44_IN2OUT_ERROR_NO_TRANSLATION];
goto trace00;
}
snat_det_forward (mp0, &ip0->src_address, &new_addr0, &lo_port0);
key0.ext_host_addr = ip0->dst_address;
key0.ext_host_port = tcp0->dst;
ses0 =
snat_det_find_ses_by_in (mp0, &ip0->src_address, tcp0->src, key0);
if (PREDICT_FALSE (!ses0))
{
for (i0 = 0; i0 < mp0->ports_per_host; i0++)
{
key0.out_port = clib_host_to_net_u16 (lo_port0 +
((i0 +
clib_net_to_host_u16
(tcp0->src)) %
mp0->ports_per_host));
if (snat_det_get_ses_by_out
(mp0, &ip0->src_address, key0.as_u64))
continue;
ses0 =
snat_det_ses_create (thread_index, mp0, &ip0->src_address,
tcp0->src, &key0);
break;
}
if (PREDICT_FALSE (!ses0))
{
/* too many sessions for user, send ICMP error packet */
vnet_buffer (b0)->sw_if_index[VLIB_TX] = (u32) ~ 0;
icmp4_error_set_vnet_buffer (b0,
ICMP4_destination_unreachable,
ICMP4_destination_unreachable_destination_unreachable_host,
0);
next0 = DET44_IN2OUT_NEXT_ICMP_ERROR;
goto trace00;
}
}
old_port0 = udp0->src_port;
udp0->src_port = new_port0 = ses0->out.out_port;
old_addr0.as_u32 = ip0->src_address.as_u32;
ip0->src_address.as_u32 = new_addr0.as_u32;
vnet_buffer (b0)->sw_if_index[VLIB_TX] = dm->outside_fib_index;
sum0 = ip0->checksum;
sum0 = ip_csum_update (sum0, old_addr0.as_u32, new_addr0.as_u32,
ip4_header_t, src_address /* changed member */ );
ip0->checksum = ip_csum_fold (sum0);
if (PREDICT_TRUE (proto0 == NAT_PROTOCOL_TCP))
{
if (tcp0->flags & TCP_FLAG_SYN)
ses0->state = DET44_SESSION_TCP_SYN_SENT;
else if (tcp0->flags & TCP_FLAG_ACK
&& ses0->state == DET44_SESSION_TCP_SYN_SENT)
ses0->state = DET44_SESSION_TCP_ESTABLISHED;
else if (tcp0->flags & TCP_FLAG_FIN
&& ses0->state == DET44_SESSION_TCP_ESTABLISHED)
ses0->state = DET44_SESSION_TCP_FIN_WAIT;
else if (tcp0->flags & TCP_FLAG_ACK
&& ses0->state == DET44_SESSION_TCP_FIN_WAIT)
snat_det_ses_close (mp0, ses0);
else if (tcp0->flags & TCP_FLAG_FIN
&& ses0->state == DET44_SESSION_TCP_CLOSE_WAIT)
ses0->state = DET44_SESSION_TCP_LAST_ACK;
else if (tcp0->flags == 0 && ses0->state == DET44_SESSION_UNKNOWN)
ses0->state = DET44_SESSION_TCP_ESTABLISHED;
sum0 = tcp0->checksum;
sum0 = ip_csum_update (sum0, old_addr0.as_u32, new_addr0.as_u32,
ip4_header_t,
dst_address /* changed member */ );
sum0 = ip_csum_update (sum0, old_port0, new_port0,
ip4_header_t /* cheat */ ,
length /* changed member */ );
mss_clamping (dm->mss_clamping, tcp0, &sum0);
tcp0->checksum = ip_csum_fold (sum0);
}
else
{
ses0->state = DET44_SESSION_UDP_ACTIVE;
if (PREDICT_FALSE (udp0->checksum))
{
sum0 = udp0->checksum;
sum0 =
ip_csum_update (sum0, old_addr0.as_u32, new_addr0.as_u32,
ip4_header_t,
dst_address /* changed member */ );
sum0 =
ip_csum_update (sum0, old_port0, new_port0,
ip4_header_t /* cheat */ ,
length /* changed member */ );
udp0->checksum = ip_csum_fold (sum0);
}
}
switch (ses0->state)
{
case DET44_SESSION_UDP_ACTIVE:
ses0->expire = now + dm->timeouts.udp;
break;
case DET44_SESSION_TCP_SYN_SENT:
case DET44_SESSION_TCP_FIN_WAIT:
case DET44_SESSION_TCP_CLOSE_WAIT:
case DET44_SESSION_TCP_LAST_ACK:
ses0->expire = now + dm->timeouts.tcp.transitory;
break;
case DET44_SESSION_TCP_ESTABLISHED:
ses0->expire = now + dm->timeouts.tcp.established;
break;
}
trace00:
if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE)
&& (b0->flags & VLIB_BUFFER_IS_TRACED)))
{
det44_in2out_trace_t *t =
vlib_add_trace (vm, node, b0, sizeof (*t));
t->sw_if_index = sw_if_index0;
t->next_index = next0;
t->session_index = ~0;
if (ses0)
t->session_index = ses0 - mp0->sessions;
}
pkts_processed += next0 != DET44_IN2OUT_NEXT_DROP;
n_left_from--;
next[0] = next0;
next++;
}
vlib_buffer_enqueue_to_next (vm, node, from, (u16 *) nexts,
frame->n_vectors);
vlib_node_increment_counter (vm, dm->in2out_node_index,
DET44_IN2OUT_ERROR_IN2OUT_PACKETS,
pkts_processed);
return frame->n_vectors;
}
/* *INDENT-OFF* */
VLIB_REGISTER_NODE (det44_in2out_node) = {
.name = "det44-in2out",
.vector_size = sizeof (u32),
.format_trace = format_det44_in2out_trace,
.type = VLIB_NODE_TYPE_INTERNAL,
.n_errors = ARRAY_LEN(det44_in2out_error_strings),
.error_strings = det44_in2out_error_strings,
.runtime_data_bytes = sizeof (det44_runtime_t),
.n_next_nodes = DET44_IN2OUT_N_NEXT,
/* edit / add dispositions here */
.next_nodes = {
[DET44_IN2OUT_NEXT_DROP] = "error-drop",
[DET44_IN2OUT_NEXT_LOOKUP] = "ip4-lookup",
[DET44_IN2OUT_NEXT_ICMP_ERROR] = "ip4-icmp-error",
},
};
/* *INDENT-ON* */
/*
* fd.io coding-style-patch-verification: ON
*
* Local Variables:
* eval: (c-set-style "gnu")
* End:
*/
|
941ee63ceef2cd8a3da7cef3be046f6330a010e5
|
9de0cec678bc4a3bec2b4adabef9f39ff5b4afac
|
/EVEANALYSIS/EveAnalysisLinkDef.h
|
8c9f17a120ba7a56d0e2236cefe78afee4fcd0ac
|
[] |
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
| 735
|
h
|
EveAnalysisLinkDef.h
|
// Main authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007
/**************************************************************************
* Copyright(c) 1998-2008, ALICE Experiment at CERN, all rights reserved. *
* See http://aliceinfo.cern.ch/Offline/AliRoot/License.html for *
* full copyright notice. *
**************************************************************************/
#pragma link off all functions;
#pragma link off all globals;
#pragma link off all classes;
// AliEveLego
#pragma link C++ class AliEveLego+;
#pragma link C++ class AliEveLegoEditor+;
// AliEveBeamInfo
#pragma link C++ class AliEveBeamsInfo+;
#pragma link C++ class AliEveBeamsInfoEditor+;
|
2a939e53910abe4721cf382569a1d1f04dd69490
|
f07e66293cc41a9fe71fc44f765b432fd7a0997c
|
/selfdrive/camerad/cameras/camera_qcom2.h
|
104ba49d8e9e9eacc21911ec358e4062affd4efb
|
[
"MIT",
"LicenseRef-scancode-warranty-disclaimer"
] |
permissive
|
kegman/openpilot
|
c9ba96a72d905956f02c684e065091e023942883
|
b35291c91783657a5fc83abfff012d3bb49dd89f
|
refs/heads/kegman-ultimate
| 2022-05-22T17:07:16.656336
| 2021-10-25T13:35:28
| 2021-10-25T13:35:28
| 229,979,925
| 105
| 212
|
MIT
| 2022-03-13T05:47:51
| 2019-12-24T17:27:11
|
C
|
UTF-8
|
C
| false
| false
| 1,734
|
h
|
camera_qcom2.h
|
#pragma once
#include <stdint.h>
#include <stdbool.h>
#include <pthread.h>
#include "camera_common.h"
#include "media/cam_req_mgr.h"
#define FRAME_BUF_COUNT 4
#define ANALOG_GAIN_MAX_IDX 10 // 0xF is bypass
#define EXPOSURE_TIME_MIN 2 // with HDR, fastest ss
#define EXPOSURE_TIME_MAX 1757 // with HDR, slowest ss
#define HLC_THRESH 222
#define HLC_A 80
#define HISTO_CEIL_K 5
#define EF_LOWPASS_K 0.35
#define DEBAYER_LOCAL_WORKSIZE 16
typedef struct CameraState {
CameraInfo ci;
float analog_gain_frac;
uint16_t analog_gain;
bool dc_gain_enabled;
int exposure_time;
int exposure_time_min;
int exposure_time_max;
float ef_filtered;
int device_iommu;
int cdm_iommu;
int video0_fd;
int video1_fd;
int isp_fd;
int sensor_fd;
int csiphy_fd;
int camera_num;
uint32_t session_handle;
uint32_t sensor_dev_handle;
uint32_t isp_dev_handle;
uint32_t csiphy_dev_handle;
int32_t link_handle;
int buf0_handle;
int buf_handle[FRAME_BUF_COUNT];
int sync_objs[FRAME_BUF_COUNT];
int request_ids[FRAME_BUF_COUNT];
int request_id_last;
int frame_id_last;
int idx_offset;
bool skipped;
struct cam_req_mgr_session_info req_mgr_session_info;
CameraBuf buf;
} CameraState;
typedef struct MultiCameraState {
int device;
int video0_fd;
int video1_fd;
int isp_fd;
CameraState road_cam;
CameraState wide_road_cam;
CameraState driver_cam;
pthread_mutex_t isp_lock;
SubMaster *sm;
PubMaster *pm;
} MultiCameraState;
void cameras_init(VisionIpcServer *v, MultiCameraState *s, cl_device_id device_id, cl_context ctx);
void cameras_open(MultiCameraState *s);
void cameras_run(MultiCameraState *s);
void camera_autoexposure(CameraState *s, float grey_frac);
|
3ac35aebab0df5798acf52ac0a1b45b86c28553a
|
063f2c9cedc15982d5fe3096997f5768fcdec1a2
|
/brom-payload/common.c
|
e372db7d54a22abca40aba1d01e2a86dc54afff9
|
[] |
no_license
|
amonet-kamakiri/kamakiri
|
4d2a7dfe45107c16c12e437a863958c74e7552a7
|
2b0878a2e270bcca5364f596d2688a013aafbd79
|
refs/heads/master
| 2023-08-18T18:25:15.895924
| 2022-03-04T20:22:59
| 2022-03-04T20:22:59
| 213,044,549
| 110
| 46
| null | 2021-07-17T12:05:16
| 2019-10-05T17:46:18
|
C
|
UTF-8
|
C
| false
| false
| 371
|
c
|
common.c
|
#include "common.h"
void low_uart_put(int ch) {
volatile uint32_t *uart_reg0 = (volatile uint32_t*)0x11003014;
volatile uint32_t *uart_reg1 = (volatile uint32_t*)0x11003000;
while ( !((*uart_reg0) & 0x20) )
{}
*uart_reg1 = ch;
}
void _putchar(char character)
{
if (character == '\n')
low_uart_put('\r');
low_uart_put(character);
}
|
4f69058378c5bf970b0baeebe54842e38dc831a1
|
e814383d36a10839104efaa4df277996ab220fa3
|
/opal/include/opal/types.h
|
bca24de238f4ea427e5539079b64a129eddd02bb
|
[
"mpich2",
"BSD-3-Clause-Open-MPI"
] |
permissive
|
open-mpi/ompi
|
a1d7483ae1d83dd8fd8ae3ee95e832e0a0ee04e3
|
1edfdb025c4450f694600083ad871cf06c8d45cd
|
refs/heads/main
| 2023-09-01T01:30:02.040705
| 2023-08-29T17:32:18
| 2023-08-29T17:32:18
| 24,107,001
| 2,008
| 973
|
NOASSERTION
| 2023-09-14T20:59:26
| 2014-09-16T16:08:30
|
C
|
UTF-8
|
C
| false
| false
| 4,899
|
h
|
types.h
|
/*
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
* University Research and Technology
* Corporation. All rights reserved.
* Copyright (c) 2004-2005 The University of Tennessee and The University
* of Tennessee Research Foundation. All rights
* reserved.
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
* University of Stuttgart. All rights reserved.
* Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 2014 Intel, Inc. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#ifndef OPAL_TYPES_H
#define OPAL_TYPES_H
#include "opal_config.h"
#include <stdint.h>
#ifdef HAVE_SYS_TYPES_H
# include <sys/types.h>
#endif
#ifdef HAVE_SYS_SOCKET_H
# include <sys/socket.h>
#endif
#ifdef HAVE_SYS_SELECT_H
# include <sys/select.h>
#endif
#ifdef HAVE_NETINET_IN_H
# include <netinet/in.h>
#endif
#ifdef HAVE_ARPA_INET_H
# include <arpa/inet.h>
#endif
#if OPAL_ENABLE_DEBUG
# include "opal/util/output.h"
#endif
/*
* portable assignment of pointer to int
*/
typedef union {
uint64_t lval;
uint32_t ival;
void *pval;
struct {
uint32_t uval;
uint32_t lval;
} sval;
} opal_ptr_t;
/*
* handle differences in iovec
*/
#if defined(__APPLE__) || defined(__WINDOWS__)
typedef char *opal_iov_base_ptr_t;
# define OPAL_IOVBASE char
#else
# define OPAL_IOVBASE void
typedef void *opal_iov_base_ptr_t;
#endif
/*
* handle differences in socklen_t
*/
#if defined(HAVE_SOCKLEN_T)
typedef socklen_t opal_socklen_t;
#else
typedef int opal_socklen_t;
#endif
/*
* Convert a 64 bit value to network byte order.
*/
static inline uint64_t hton64(uint64_t val) __opal_attribute_const__;
static inline uint64_t hton64(uint64_t val)
{
#ifdef HAVE_UNIX_BYTESWAP
union {
uint64_t ll;
uint32_t l[2];
} w, r;
/* platform already in network byte order? */
if (htonl(1) == 1L)
return val;
w.ll = val;
r.l[0] = htonl(w.l[1]);
r.l[1] = htonl(w.l[0]);
return r.ll;
#else
return val;
#endif
}
/*
* Convert a 64 bit value from network to host byte order.
*/
static inline uint64_t ntoh64(uint64_t val) __opal_attribute_const__;
static inline uint64_t ntoh64(uint64_t val)
{
#ifdef HAVE_UNIX_BYTESWAP
union {
uint64_t ll;
uint32_t l[2];
} w, r;
/* platform already in network byte order? */
if (htonl(1) == 1L)
return val;
w.ll = val;
r.l[0] = ntohl(w.l[1]);
r.l[1] = ntohl(w.l[0]);
return r.ll;
#else
return val;
#endif
}
/**
* Convert between a local representation of pointer and a 64 bits value.
*/
static inline uint64_t opal_ptr_ptol(void *ptr) __opal_attribute_const__;
static inline uint64_t opal_ptr_ptol(void *ptr)
{
return (uint64_t)(uintptr_t) ptr;
}
static inline void *opal_ptr_ltop(uint64_t value) __opal_attribute_const__;
static inline void *opal_ptr_ltop(uint64_t value)
{
#if SIZEOF_VOID_P == 4 && OPAL_ENABLE_DEBUG
if (value > ((1ULL << 32) - 1ULL)) {
opal_output(0, "Warning: truncating value in opal_ptr_ltop");
}
#endif
return (void *) (uintptr_t) value;
}
#if defined(WORDS_BIGENDIAN) || !defined(HAVE_UNIX_BYTESWAP)
static inline uint16_t opal_swap_bytes2(uint16_t val) __opal_attribute_const__;
static inline uint16_t opal_swap_bytes2(uint16_t val)
{
union {
uint16_t bigval;
uint8_t arrayval[2];
} w, r;
w.bigval = val;
r.arrayval[0] = w.arrayval[1];
r.arrayval[1] = w.arrayval[0];
return r.bigval;
}
static inline uint32_t opal_swap_bytes4(uint32_t val) __opal_attribute_const__;
static inline uint32_t opal_swap_bytes4(uint32_t val)
{
union {
uint32_t bigval;
uint8_t arrayval[4];
} w, r;
w.bigval = val;
r.arrayval[0] = w.arrayval[3];
r.arrayval[1] = w.arrayval[2];
r.arrayval[2] = w.arrayval[1];
r.arrayval[3] = w.arrayval[0];
return r.bigval;
}
static inline uint64_t opal_swap_bytes8(uint64_t val) __opal_attribute_const__;
static inline uint64_t opal_swap_bytes8(uint64_t val)
{
union {
uint64_t bigval;
uint8_t arrayval[8];
} w, r;
w.bigval = val;
r.arrayval[0] = w.arrayval[7];
r.arrayval[1] = w.arrayval[6];
r.arrayval[2] = w.arrayval[5];
r.arrayval[3] = w.arrayval[4];
r.arrayval[4] = w.arrayval[3];
r.arrayval[5] = w.arrayval[2];
r.arrayval[6] = w.arrayval[1];
r.arrayval[7] = w.arrayval[0];
return r.bigval;
}
#else
# define opal_swap_bytes2 htons
# define opal_swap_bytes4 htonl
# define opal_swap_bytes8 hton64
#endif /* WORDS_BIGENDIAN || !HAVE_UNIX_BYTESWAP */
#endif /* OPAL_TYPES_H */
|
f6b3e4deff8979b4e6fbd7514f88a5796a6b1eda
|
68bc5885147e5a0294f716e0ea7c5cb79cb54b31
|
/bin/client.c
|
a26e82934273acf7f1b767e8f993f72e620e3680
|
[
"BSD-3-Clause",
"BSD-2-Clause"
] |
permissive
|
NTAP/quant
|
ebcdc38b1c5b38db86a50118c77bc6d8a68df71a
|
dc77211c300fbf677c016796f4eeecb8fc542ffe
|
refs/heads/main
| 2023-08-21T19:43:04.122856
| 2023-08-08T13:57:35
| 2023-08-08T13:57:35
| 75,819,176
| 275
| 41
|
BSD-2-Clause
| 2023-08-08T13:57:37
| 2016-12-07T09:12:31
|
C
|
UTF-8
|
C
| false
| false
| 23,295
|
c
|
client.c
|
// SPDX-License-Identifier: BSD-2-Clause
//
// Copyright (c) 2016-2022, NetApp, Inc.
// 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.
//
// 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 <errno.h>
#include <fcntl.h>
#include <libgen.h>
#include <limits.h>
#include <net/if.h>
#include <netdb.h>
#include <netinet/in.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/param.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/uio.h>
#include <time.h>
#include <unistd.h>
#define klib_unused
#include <http_parser.h>
#include <picohttp/h3zero.h>
#include <quant/quant.h>
#define bps(bytes, secs) \
__extension__({ \
static char _str[32]; \
const double _bps = ((secs) > 1e-9) ? (double)(bytes)*8 / (secs) : 0; \
if (_bps > NS_PER_S) \
snprintf(_str, sizeof(_str), "%.3f Gb/s", _bps / NS_PER_S); \
else if (_bps > US_PER_S) \
snprintf(_str, sizeof(_str), "%.3f Mb/s", _bps / US_PER_S); \
else if (_bps > MS_PER_S) \
snprintf(_str, sizeof(_str), "%.3f Kb/s", _bps / MS_PER_S); \
else \
snprintf(_str, sizeof(_str), "%.3f b/s", _bps); \
_str; \
})
struct conn_cache_entry {
struct q_conn * c;
struct addrinfo * peerinfo;
#ifndef NO_MIGRATION
struct addrinfo * migr_peer;
#endif
bool migrated;
uint8_t _unused[7];
};
KHASH_MAP_INIT_INT64(conn_cache, struct conn_cache_entry *)
static uint32_t vers = 0;
static uint32_t timeout = 10;
static uint32_t initial_rtt = 500;
static uint32_t num_bufs = 100000;
static uint32_t reps = 1;
static bool do_h3 = false;
static bool prefer_v6 = false;
static bool do_chacha = false;
static bool flip_keys = false;
static bool zlen_cids = false;
static bool write_files = false;
static bool test_qr = false;
static bool disable_pmtud = false;
static bool enable_grease = false;
#ifndef NO_MIGRATION
static bool rebind = false;
static bool switch_ip = false;
#endif
struct stream_entry {
sl_entry(stream_entry) next;
struct conn_cache_entry * cce;
struct q_stream * s;
char * url;
uint64_t req_t;
uint64_t rep_t;
struct w_iov_sq req;
struct w_iov_sq rep;
};
static sl_head(stream_list, stream_entry) sl = sl_head_initializer(sl);
static inline uint64_t __attribute__((nonnull))
conn_cache_key(const struct sockaddr * const sock)
{
const struct sockaddr_in * const sock4 =
(const struct sockaddr_in *)(const void *)sock;
return ((uint64_t)sock4->sin_addr.s_addr
<< sizeof(sock4->sin_addr.s_addr) * 8) |
(uint64_t)sock4->sin_port;
}
static void __attribute__((noreturn, nonnull))
usage(const char * const name,
const char * const ifname,
const char * const cache,
const char * const tls_log,
const char * const qlog_dir,
const char * const tls_ca_store)
{
printf("%s [options] URL [URL...]\n", name);
printf("\t[-3]\t\tsend a static H3 request; default %s\n",
do_h3 ? "true" : "false");
printf("\t[-6]\t\tprefer IPv6; default %s\n", prefer_v6 ? "true" : "false");
printf("\t[-a]\t\tforce Chacha20; default %s\n",
do_chacha ? "true" : "false");
printf("\t[-b bufs]\tnumber of network buffers to allocate; default %u\n",
num_bufs);
printf("\t[-c]\t\tverify TLS certs using this CA cert; default %s\n",
*tls_ca_store ? tls_ca_store : "WebPKI");
printf("\t[-e version]\tQUIC version to use; default 0x%08x\n",
vers ? vers : DRAFT_VERSION);
printf("\t[-g]\t\tenable greasing the QUIC bit; default %s\n",
enable_grease ? "true" : "false");
printf("\t[-i interface]\tinterface to run over; default %s\n", ifname);
printf("\t[-l log]\tlog file for TLS keys; default %s\n",
*tls_log ? tls_log : "false");
printf("\t[-m]\t\ttest multi-pkt initial (\"quantum-readiness\"); default "
"%s\n",
test_qr ? "true" : "false");
#ifndef NO_MIGRATION
printf("\t[-n]\t\tsimulate NAT rebind (use twice for \"real\" migration); "
"default %s\n",
rebind ? "true" : "false");
#endif
printf("\t[-o]\t\tdisable PMTUD; default %s\n",
disable_pmtud ? "true" : "false");
printf("\t[-q log]\twrite qlog events to directory; default %s\n",
*qlog_dir ? qlog_dir : "false");
printf("\t[-r reps]\trepetitions for all URLs; default %u\n", reps);
printf("\t[-s cache]\tTLS 0-RTT state cache; default %s\n", cache);
printf("\t[-t timeout]\tidle timeout in seconds; default %u\n", timeout);
printf("\t[-u]\t\tupdate TLS keys; default %s\n",
flip_keys ? "true" : "false");
#ifndef NDEBUG
printf("\t[-v verbosity]\tverbosity level (0-%d, default %d)\n", DLEVEL,
util_dlevel);
#endif
printf("\t[-w]\t\twrite retrieved objects to disk; default %s\n",
write_files ? "true" : "false");
printf("\t[-x rtt]\tinitial RTT in milliseconds (default %u)\n",
initial_rtt);
printf("\t[-z]\t\tuse zero-length source connection IDs; default %s\n",
zlen_cids ? "true" : "false");
exit(0);
}
static void __attribute__((nonnull))
set_from_url(char * const var,
const size_t len,
const char * const url,
const struct http_parser_url * const u,
const enum http_parser_url_fields f,
const char * const def)
{
if ((u->field_set & (1 << f)) == 0) {
strncpy(var, def, len);
var[len - 1] = 0;
} else {
const uint16_t l = f == UF_PATH
? (uint16_t)strlen(url) - u->field_data[f].off
: u->field_data[f].len;
strncpy(var, &url[u->field_data[f].off], l);
var[l] = 0;
}
}
#ifndef NO_MIGRATION
static void __attribute__((nonnull(1)))
try_migrate(struct conn_cache_entry * const cce)
{
if (rebind && cce->migrated == false)
cce->migrated = q_migrate(cce->c, switch_ip,
cce->migr_peer ? cce->migr_peer->ai_addr : 0);
}
#else
#define try_migrate(...)
#endif
static struct addrinfo * __attribute__((nonnull))
get_addr(const char * const dest,
const char * const port,
struct addrinfo ** peer_v4,
struct addrinfo ** peer_v6)
{
*peer_v4 = *peer_v6 = 0;
struct addrinfo * peer = 0;
const int err = getaddrinfo(dest, port, 0, &peer);
if (err != 0) {
warn(ERR, "getaddrinfo: %s", gai_strerror(err));
if (peer)
freeaddrinfo(peer);
return 0;
}
for (struct addrinfo * cand = peer; cand; cand = cand->ai_next) {
if (*peer_v4 == 0 && cand->ai_family == AF_INET)
*peer_v4 = cand;
if (*peer_v6 == 0 && cand->ai_family == AF_INET6)
*peer_v6 = cand;
}
return peer;
}
static struct q_conn * __attribute__((nonnull))
get(char * const url, struct w_engine * const w, khash_t(conn_cache) * cc)
{
// parse and verify the URIs passed on the command line
struct http_parser_url u = {0};
if (http_parser_parse_url(url, strlen(url), 0, &u)) {
warn(ERR, "URL \"%s\" is malformed (%s)", url,
http_errno_description((enum http_errno)errno));
return 0;
}
ensure((u.field_set & (1 << UF_USERINFO)) == 0,
"userinfo unsupported in URL");
// extract relevant info from URL
char dest[1024];
char port[64];
char path[8192];
set_from_url(dest, sizeof(dest), url, &u, UF_HOST, "localhost");
set_from_url(port, sizeof(port), url, &u, UF_PORT, "4433");
set_from_url(path, sizeof(path), url, &u, UF_PATH, "/index.html");
struct addrinfo * peer_v4 = 0;
struct addrinfo * peer_v6 = 0;
struct addrinfo * const peerinfo = get_addr(dest, port, &peer_v4, &peer_v6);
if (peerinfo == 0)
goto fail;
struct addrinfo * const peer =
(prefer_v6 && peer_v6) ? peer_v6 : (peer_v4 ? peer_v4 : peer_v6);
if (peer == 0)
goto fail;
#ifndef NO_MIGRATION
struct addrinfo * const migr_peer =
peer->ai_family == AF_INET ? peer_v6 : peer_v4;
#endif
// do we have a connection open to this peer?
khiter_t k = kh_get(conn_cache, cc, conn_cache_key(peer->ai_addr));
struct conn_cache_entry * cce = (k == kh_end(cc) ? 0 : kh_val(cc, k));
// add to stream list
struct stream_entry * se = calloc(1, sizeof(*se));
ensure(se, "calloc failed");
sq_init(&se->rep);
sl_insert_head(&sl, se, next);
sq_init(&se->req);
if (do_h3) {
q_alloc(w, &se->req, 0, peer->ai_family, 1024);
struct w_iov * const v = sq_first(&se->req);
const uint16_t len =
(uint16_t)(h3zero_create_request_header_frame(
&v->buf[3], v->buf + v->len - 3, (uint8_t *)path,
strlen(path), dest) -
&v->buf[3]);
v->buf[0] = h3zero_frame_header;
if (len < 64) {
v->buf[1] = (uint8_t)len;
memmove(&v->buf[2], &v->buf[3], len);
v->len = 2 + len;
} else {
v->buf[1] = (uint8_t)((len >> 8) | 0x40);
v->buf[2] = (uint8_t)(len & 0xff);
v->len = 3 + len;
}
} else {
// assemble an HTTP/0.9 request
char req_str[sizeof(path) + 6];
const int req_str_len =
snprintf(req_str, sizeof(req_str), "GET %s\r\n", path);
q_chunk_str(w, cce ? cce->c : 0, peer->ai_family, req_str,
(uint32_t)req_str_len, &se->req);
}
const bool opened_new = cce == 0;
if (opened_new) {
se->req_t = w_now(CLOCK_MONOTONIC_RAW);
// no, open a new connection
char alpn[16];
if (vers == 0x1)
snprintf(alpn, sizeof(alpn), "h%c%s", do_h3 ? '3' : 'q',
do_h3 ? "" : "-interop");
else
snprintf(alpn, sizeof(alpn), "h%c-%02u", do_h3 ? '3' : 'q',
vers ? vers & 0x000000ff : DRAFT_VERSION);
struct q_conn * const c =
q_connect(w, peer->ai_addr, dest, &se->req, &se->s, true, alpn, 0);
if (c == 0)
goto fail;
if (do_h3) {
// we need to open a uni stream for an empty H/3 SETTINGS frame
struct q_stream * const ss = q_rsv_stream(c, false);
if (ss == 0)
return 0;
static const uint8_t h3_empty_settings[] = {
0x00, h3zero_frame_settings, 0x00};
// XXX lsquic doesn't like a FIN on this stream
q_write_str(w, ss, (const char *)h3_empty_settings,
sizeof(h3_empty_settings), false);
}
cce = calloc(1, sizeof(*cce));
ensure(cce, "calloc failed");
cce->c = c;
cce->peerinfo = peerinfo;
#ifndef NO_MIGRATION
cce->migr_peer = migr_peer;
#endif
// insert into connection cache
int ret;
k = kh_put(conn_cache, cc, conn_cache_key(peer->ai_addr), &ret);
ensure(ret >= 1, "inserted returned %d", ret);
kh_val(cc, k) = cce;
} else {
freeaddrinfo(peerinfo);
se->s = q_rsv_stream(cce->c, true);
if (se->s) {
se->req_t = w_now(CLOCK_MONOTONIC_RAW);
q_write(se->s, &se->req, true);
}
}
try_migrate(cce);
se->cce = cce;
se->url = url;
return cce->c;
fail:
freeaddrinfo(peerinfo);
return 0;
}
static void __attribute__((nonnull)) free_cc(khash_t(conn_cache) * cc)
{
struct conn_cache_entry * cce;
kh_foreach_value(cc, cce, {
freeaddrinfo(cce->peerinfo);
free(cce);
});
kh_release(conn_cache, cc);
}
static void free_se(struct stream_entry * const se)
{
q_free(&se->req);
q_free(&se->rep);
free(se);
}
static void free_sl_head(void)
{
struct stream_entry * const se = sl_first(&sl);
sl_remove_head(&sl, next);
free_se(se);
}
static void free_sl(void)
{
while (sl_empty(&sl) == false)
free_sl_head();
}
static void __attribute__((nonnull))
write_object(struct stream_entry * const se)
{
char * const slash = strrchr(se->url, '/');
if (slash && *(slash + 1) == 0)
// this URL ends in a slash, so strip that to name the file
*slash = 0;
const int fd =
open(*basename(se->url) == 0 ? "index.html" : basename(se->url),
O_CREAT | O_WRONLY | O_CLOEXEC,
S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
ensure(fd != -1, "cannot open %s", basename(se->url));
struct iovec vec[IOV_MAX];
struct w_iov * v = sq_first(&se->rep);
int i = 0;
while (v) {
vec[i].iov_base = v->buf;
vec[i].iov_len = v->len;
if (++i == IOV_MAX || sq_next(v, next) == 0) {
ensure(writev(fd, vec, i) != -1, "cannot writev");
i = 0;
}
v = sq_next(v, next);
}
close(fd);
}
int main(int argc, char * argv[])
{
#ifndef NDEBUG
util_dlevel = DLEVEL; // default to maximum compiled-in verbosity
#endif
char ifname[IFNAMSIZ] = "lo"
#ifndef __linux__
"0"
#endif
;
int ch;
char cache[MAXPATHLEN] = "/tmp/" QUANT "-session";
char tls_log[MAXPATHLEN] = "";
char qlog_dir[MAXPATHLEN] = "";
char tls_ca_store[MAXPATHLEN] = "";
int ret = -1;
// set default TLS log file from environment
const char * const keylog = getenv("SSLKEYLOGFILE");
if (keylog) {
strncpy(tls_log, keylog, MAXPATHLEN);
tls_log[MAXPATHLEN - 1] = 0;
}
while ((ch = getopt(argc, argv,
"hi:v:s:t:l:c:u36azb:wr:q:me:x:og"
#ifndef NO_MIGRATION
"n"
#endif
)) != -1) {
switch (ch) {
case 'i':
strncpy(ifname, optarg, sizeof(ifname) - 1);
break;
case 's':
strncpy(cache, optarg, sizeof(cache) - 1);
break;
case 'q':
strncpy(qlog_dir, optarg, sizeof(qlog_dir) - 1);
break;
case 't':
timeout = (uint32_t)MIN(600, strtoul(optarg, 0, 10)); // 10 min
break;
case 'b':
num_bufs = (uint32_t)MIN(strtoul(optarg, 0, 10), UINT32_MAX);
break;
case 'r':
reps = (uint32_t)MAX(1, MIN(strtoul(optarg, 0, 10), UINT32_MAX));
break;
case 'e':
vers = (uint32_t)MAX(1, MIN(strtoul(optarg, 0, 16), UINT32_MAX));
break;
case 'x':
initial_rtt = MAX(1, (uint32_t)strtoul(optarg, 0, 10));
break;
case 'l':
strncpy(tls_log, optarg, sizeof(tls_log) - 1);
break;
case 'c':
strncpy(tls_ca_store, optarg, sizeof(tls_ca_store) - 1);
break;
case 'u':
flip_keys = true;
break;
case '3':
do_h3 = true;
break;
case '6':
prefer_v6 = true;
break;
case 'a':
do_chacha = true;
break;
case 'z':
zlen_cids = true;
break;
case 'w':
write_files = true;
break;
case 'm':
test_qr = true;
break;
case 'o':
disable_pmtud = true;
break;
case 'g':
enable_grease = true;
break;
#ifndef NO_MIGRATION
case 'n':
if (rebind)
switch_ip = true;
rebind = true;
break;
#endif
case 'v':
#ifndef NDEBUG
util_dlevel = (short)MIN(DLEVEL, strtoul(optarg, 0, 10));
#endif
break;
case 'h':
case '?':
default:
usage(basename(argv[0]), ifname, cache, tls_log, qlog_dir,
tls_ca_store);
}
}
struct w_engine * const w = q_init(
ifname,
&(const struct q_conf){
.conn_conf =
&(struct q_conn_conf){.initial_rtt = initial_rtt,
.enable_tls_key_updates = flip_keys,
.enable_spinbit = true,
.enable_udp_zero_checksums = true,
.idle_timeout = timeout,
.version = vers,
.disable_pmtud = disable_pmtud,
.enable_grease = enable_grease,
.enable_quantum_readiness_test = test_qr},
.qlog_dir = *qlog_dir ? qlog_dir : 0,
.force_chacha20 = do_chacha,
.num_bufs = num_bufs,
.ticket_store = cache,
.tls_log = *tls_log ? tls_log : 0,
.client_cid_len = zlen_cids ? 0 : 4,
.tls_ca_store = *tls_ca_store ? tls_ca_store : 0});
khash_t(conn_cache) cc = {0};
if (reps > 1)
puts("size\ttime\t\tbps\t\turl");
double sum_len = 0;
double sum_elapsed = 0;
for (uint64_t r = 1; r <= reps; r++) {
int url_idx = optind;
while (url_idx < argc) {
// open a new connection, or get an open one
warn(INF, "%s retrieving %s", basename(argv[0]), argv[url_idx]);
get(argv[url_idx++], w, &cc);
}
// collect the replies
bool all_closed;
do {
all_closed = true;
bool rxed_new = false;
struct stream_entry * se = 0;
struct stream_entry * tmp = 0;
sl_foreach_safe (se, &sl, next, tmp) {
if (se->cce == 0 || se->cce->c == 0 || se->s == 0) {
sl_remove(&sl, se, stream_entry, next);
free_se(se);
continue;
}
try_migrate(se->cce);
rxed_new |= q_read_stream(se->s, &se->rep, false);
const bool is_closed = q_peer_closed_stream(se->s);
all_closed &= is_closed;
if (is_closed)
se->rep_t = w_now(CLOCK_MONOTONIC_RAW);
}
if (rxed_new == false && all_closed == false) {
struct q_conn * c;
q_ready(w, timeout * NS_PER_S, &c);
if (c == 0)
break;
if (q_is_conn_closed(c))
break;
}
} while (all_closed == false);
// print/save the replies
while (sl_empty(&sl) == false) {
struct stream_entry * const se = sl_first(&sl);
if (ret == -1)
ret = w_iov_sq_cnt(&se->rep) == 0;
else
ret |= w_iov_sq_cnt(&se->rep) == 0;
const double elapsed =
se->rep_t >= se->req_t
? (double)(se->rep_t - se->req_t) / NS_PER_S
: 0;
const uint_t rep_len = w_iov_sq_len(&se->rep);
sum_len += (double)rep_len;
sum_elapsed += elapsed;
if (reps > 1)
printf("%" PRIu "\t%f\t\"%s\"\t%s\n", rep_len, elapsed,
bps(rep_len, elapsed), se->url);
#ifndef NDEBUG
char cid_str[64];
q_cid_str(se->cce->c, cid_str, sizeof(cid_str));
warn(WRN,
"read %" PRIu
" byte%s in %.3f sec (%s) on conn %s strm %" PRIu,
rep_len, plural(rep_len), elapsed < 0 ? 0 : elapsed,
bps(rep_len, elapsed), cid_str, q_sid(se->s));
#endif
// retrieve the TX'ed request
q_stream_get_written(se->s, &se->req);
if (write_files)
write_object(se);
// save the object, and print its first three packets to stdout
struct w_iov * v;
uint32_t n = 0;
sq_foreach (v, &se->rep, next) {
// cppcheck-suppress nullPointer
const bool is_last = v == sq_last(&se->rep, w_iov, next);
if (w_iov_sq_cnt(&se->rep) > 100 || reps > 1)
// don't print large responses, or repeated ones
continue;
// XXX the strnlen() test is super-hacky
if (do_h3 && n == 0 &&
(v->buf[0] != 0x01 && v->buf[0] != 0xff &&
strnlen((char *)v->buf, v->len) == v->len))
warn(WRN, "no h3 payload");
if (n < 4 || is_last) {
if (do_h3) {
#ifndef NDEBUG
if (util_dlevel == DBG)
hexdump(v->buf, v->len);
#endif
} else {
// don't print newlines to console log
for (uint16_t p = 0; p < v->len; p++)
if (v->buf[p] == '\n' || v->buf[p] == '\r')
v->buf[p] = ' ';
printf("%.*s%s", v->len, v->buf, is_last ? "\n" : "");
if (is_last)
fflush(stdout);
}
} else
printf(".");
n++;
}
q_free_stream(se->s);
free_sl_head();
}
}
if (reps > 1)
printf("TOTAL: %s\n", bps(sum_len, sum_elapsed));
free_cc(&cc);
free_sl();
q_cleanup(w);
warn(DBG, "%s exiting with %d", basename(argv[0]), ret);
return ret;
}
|
f02b40e900a1463192d3a13ff373ede1d94c8311
|
fbe68d84e97262d6d26dd65c704a7b50af2b3943
|
/third_party/virtualbox/include/VBox/vmm/vm.h
|
21b9240ac5f0c53945ea9fc6ea133835c20f56eb
|
[
"GPL-2.0-only",
"LicenseRef-scancode-unknown-license-reference",
"CDDL-1.0",
"LicenseRef-scancode-warranty-disclaimer",
"GPL-1.0-or-later",
"LGPL-2.1-or-later",
"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
| 57,242
|
h
|
vm.h
|
/** @file
* VM - The Virtual Machine, data.
*/
/*
* Copyright (C) 2006-2017 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* you can redistribute it and/or modify it under the terms of the GNU
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*
* The contents of this file may alternatively be used under the terms
* of the Common Development and Distribution License Version 1.0
* (CDDL) only, as it comes in the "COPYING.CDDL" file of the
* VirtualBox OSE distribution, in which case the provisions of the
* CDDL are applicable instead of those of the GPL.
*
* You may elect to license modified versions of this file under the
* terms and conditions of either the GPL or the CDDL or both.
*/
#ifndef ___VBox_vmm_vm_h
#define ___VBox_vmm_vm_h
#ifndef VBOX_FOR_DTRACE_LIB
# include <iprt/param.h>
# include <VBox/types.h>
# include <VBox/vmm/cpum.h>
# include <VBox/vmm/stam.h>
# include <VBox/vmm/vmapi.h>
# include <VBox/vmm/vmm.h>
# include <VBox/sup.h>
#else
# pragma D depends_on library vbox-types.d
# pragma D depends_on library CPUMInternal.d
# define ___CPUMInternal_h
#endif
/** @defgroup grp_vm The Virtual Machine
* @ingroup grp_vmm
* @{
*/
/*MYCODE*/
typedef struct HardwarePage_t{
int ReferenceCount; //Number of breakpoint using this page
uint64_t PageSize; //Size of the page
uint64_t HCPhys; //Host-Context physical address of the page
uint8_t* R3Ptr; //Ring-3 virtual address of the page
}HardwarePage_t;
typedef struct GCPhysArea_t{
uint64_t Start;
uint64_t End;
}GCPhysArea_t;
typedef struct PfnEntrie_t{
uint8_t n;
struct{
bool u1Present;
bool u1Write;
bool u1Execute;
bool u1Breakable;
}u;
}PfnEntrie_t;
typedef struct BreakpointEntrie_t{
//Is the breakpoint activated or free
bool breakpointActivated;
//Tag the breakpoint to know if the breakpoint changed...
uint64_t breakpointTag;
//Kind of breakpoint PAGEHBP, HARDHBP, SOFTHBP
uint8_t breakpointType;
//Guest virtual address of the breakpoint or start of the breakpoint
uint64_t breakpointGCPtr;
//Guest physical address of the breakpoint or start of the breakpoint
uint64_t breakpointGCPhys;
//Lengt of the breakpoint (PAGEHBP only)
uint64_t breakpointLength;
//EXECUTE_BP, READ_BP, WRITE_BP
uint8_t breakpointAccessType;
//Size of the page where the breakpoint is
uint64_t breakpointPageSize;
//Original host physical page
uint64_t breakpointOrigHCPhys;
//Original opcode byte
uint8_t breakpointOriginalByte;
//Pointer to HardwarePage
HardwarePage_t* breakpointHardwarePage;
uint64_t breakpointGCPhysAreaCount;
GCPhysArea_t* breakpointGCPhysAreaTable;
//Condition
uint64_t breakpointCr3;
}BreakpointEntrie_t;
#define MAX_BREAKPOINT_ID 1024
#define MEMORY_SIZE 0x200000000
#define MAX_PAGE ((MEMORY_SIZE)/4096)
/*ENDMYCODE*/
/**
* The state of a Virtual CPU.
*
* The basic state indicated here is whether the CPU has been started or not. In
* addition, there are sub-states when started for assisting scheduling (GVMM
* mostly).
*
* The transition out of the STOPPED state is done by a vmR3PowerOn.
* The transition back to the STOPPED state is done by vmR3PowerOff.
*
* (Alternatively we could let vmR3PowerOn start CPU 0 only and let the SPIP
* handling switch on the other CPUs. Then vmR3Reset would stop all but CPU 0.)
*/
typedef enum VMCPUSTATE
{
/** The customary invalid zero. */
VMCPUSTATE_INVALID = 0,
/** Virtual CPU has not yet been started. */
VMCPUSTATE_STOPPED,
/** CPU started. */
VMCPUSTATE_STARTED,
/** CPU started in HM context. */
VMCPUSTATE_STARTED_HM,
/** Executing guest code and can be poked (RC or STI bits of HM). */
VMCPUSTATE_STARTED_EXEC,
/** Executing guest code in the recompiler. */
VMCPUSTATE_STARTED_EXEC_REM,
/** Halted. */
VMCPUSTATE_STARTED_HALTED,
/** The end of valid virtual CPU states. */
VMCPUSTATE_END,
/** Ensure 32-bit type. */
VMCPUSTATE_32BIT_HACK = 0x7fffffff
} VMCPUSTATE;
/**
* The cross context virtual CPU structure.
*
* Run 'kmk run-struct-tests' (from src/VBox/VMM if you like) after updating!
*/
typedef struct VMCPU
{
/** Per CPU forced action.
* See the VMCPU_FF_* \#defines. Updated atomically. */
uint32_t volatile fLocalForcedActions; /* 0 */
/** The CPU state. */
VMCPUSTATE volatile enmState; /* 4 */
/** Pointer to the ring-3 UVMCPU structure. */
PUVMCPU pUVCpu; /* 8 */
/** Ring-3 Host Context VM Pointer. */
PVMR3 pVMR3; /* 16 / 12 */
/** Ring-0 Host Context VM Pointer. */
PVMR0 pVMR0; /* 24 / 16 */
/** Raw-mode Context VM Pointer. */
PVMRC pVMRC; /* 32 / 20 */
/** The CPU ID.
* This is the index into the VM::aCpu array. */
VMCPUID idCpu; /* 36 / 24 */
/** The native thread handle. */
RTNATIVETHREAD hNativeThread; /* 40 / 28 */
/** The native R0 thread handle. (different from the R3 handle!) */
RTNATIVETHREAD hNativeThreadR0; /* 48 / 32 */
/** Which host CPU ID is this EMT running on.
* Only valid when in RC or HMR0 with scheduling disabled. */
RTCPUID volatile idHostCpu; /* 56 / 36 */
/** The CPU set index corresponding to idHostCpu, UINT32_MAX if not valid.
* @remarks Best to make sure iHostCpuSet shares cache line with idHostCpu! */
uint32_t volatile iHostCpuSet; /* 60 / 40 */
#if HC_ARCH_BITS == 32
/** Align the structures below bit on a 64-byte boundary and make sure it starts
* at the same offset in both 64-bit and 32-bit builds.
*
* @remarks The alignments of the members that are larger than 48 bytes should be
* 64-byte for cache line reasons. structs containing small amounts of
* data could be lumped together at the end with a < 64 byte padding
* following it (to grow into and align the struct size).
*/
uint8_t abAlignment1[HC_ARCH_BITS == 64 ? 0 : 20];
#endif
/** IEM part.
* @remarks This comes first as it allows the use of 8-bit immediates for the
* first 64 bytes of the structure, reducing code size a wee bit. */
#ifdef ___IEMInternal_h /* For PDB hacking. */
union VMCPUUNIONIEMFULL
#else
union VMCPUUNIONIEMSTUB
#endif
{
#ifdef ___IEMInternal_h
struct IEMCPU s;
#endif
uint8_t padding[18496]; /* multiple of 64 */
} iem;
/** HM part. */
union VMCPUUNIONHM
{
#ifdef ___HMInternal_h
struct HMCPU s;
#endif
uint8_t padding[5824]; /* multiple of 64 */
} hm;
/** EM part. */
union VMCPUUNIONEM
{
#ifdef ___EMInternal_h
struct EMCPU s;
#endif
uint8_t padding[1408]; /* multiple of 64 */
} em;
/** TRPM part. */
union VMCPUUNIONTRPM
{
#ifdef ___TRPMInternal_h
struct TRPMCPU s;
#endif
uint8_t padding[128]; /* multiple of 64 */
} trpm;
/** TM part. */
union VMCPUUNIONTM
{
#ifdef ___TMInternal_h
struct TMCPU s;
#endif
uint8_t padding[384]; /* multiple of 64 */
} tm;
/** VMM part. */
union VMCPUUNIONVMM
{
#ifdef ___VMMInternal_h
struct VMMCPU s;
#endif
uint8_t padding[704]; /* multiple of 64 */
} vmm;
/** PDM part. */
union VMCPUUNIONPDM
{
#ifdef ___PDMInternal_h
struct PDMCPU s;
#endif
uint8_t padding[256]; /* multiple of 64 */
} pdm;
/** IOM part. */
union VMCPUUNIONIOM
{
#ifdef ___IOMInternal_h
struct IOMCPU s;
#endif
uint8_t padding[512]; /* multiple of 64 */
} iom;
/** DBGF part.
* @todo Combine this with other tiny structures. */
union VMCPUUNIONDBGF
{
#ifdef ___DBGFInternal_h
struct DBGFCPU s;
#endif
uint8_t padding[256]; /* multiple of 64 */
} dbgf;
/** GIM part. */
union VMCPUUNIONGIM
{
#ifdef ___GIMInternal_h
struct GIMCPU s;
#endif
uint8_t padding[512]; /* multiple of 64 */
} gim;
/** APIC part. */
union VMCPUUNIONAPIC
{
#ifdef ___APICInternal_h
struct APICCPU s;
#endif
uint8_t padding[1792]; /* multiple of 64 */
} apic;
/*
* Some less frequently used global members that doesn't need to take up
* precious space at the head of the structure.
*/
/** Trace groups enable flags. */
uint32_t fTraceGroups; /* 64 / 44 */
/** State data for use by ad hoc profiling. */
uint32_t uAdHoc;
/** Profiling samples for use by ad hoc profiling. */
STAMPROFILEADV aStatAdHoc[8]; /* size: 40*8 = 320 */
/** Align the following members on page boundary. */
uint8_t abAlignment2[2104];
/** PGM part. */
union VMCPUUNIONPGM
{
#ifdef ___PGMInternal_h
struct PGMCPU s;
#endif
uint8_t padding[4096]; /* multiple of 4096 */
} pgm;
/** CPUM part. */
union VMCPUUNIONCPUM
{
#ifdef ___CPUMInternal_h
struct CPUMCPU s;
#endif
#ifdef VMCPU_INCL_CPUM_GST_CTX
/** The guest CPUM context for direct use by execution engines.
* This is not for general consumption, but for HM, REM, IEM, and maybe a few
* others. The rest will use the function based CPUM API. */
CPUMCTX GstCtx;
#endif
uint8_t padding[4096]; /* multiple of 4096 */
} cpum;
/*MYCODE*/
union
{
struct{
volatile uint8_t u8StateBitmap;
volatile bool bSingleStepRequired;
volatile bool bPauseRequired;
volatile bool bDisableInterrupt;
volatile bool bRebootRequired;
volatile bool bSuspendRequired;
volatile bool bRestoreRequired;
volatile bool bPageFaultOverflowGuard;
volatile bool bHardHyperBreakPointHitted;
volatile bool bPageHyperBreakPointHitted;
volatile bool bSoftHyperBreakPointHitted;
volatile bool bMsrHyperBreakPointHitted;
volatile bool bCrHyperBreakPointHitted;
volatile bool bInstallDrBreakpointRequired;
//Fake Debug registers to keep "legit-guest" values
uint64_t aGuestDr[8];
volatile uint64_t u64TickCount;
void* pCpuShm;
}s;
uint8_t padding[4096]; /* multiple of 4096 */
} mystate;
/*ENDMYCODE*/
} VMCPU;
#ifndef VBOX_FOR_DTRACE_LIB
/** @name Operations on VMCPU::enmState
* @{ */
/** Gets the VMCPU state. */
#define VMCPU_GET_STATE(pVCpu) ( (pVCpu)->enmState )
/** Sets the VMCPU state. */
#define VMCPU_SET_STATE(pVCpu, enmNewState) \
ASMAtomicWriteU32((uint32_t volatile *)&(pVCpu)->enmState, (enmNewState))
/** Cmpares and sets the VMCPU state. */
#define VMCPU_CMPXCHG_STATE(pVCpu, enmNewState, enmOldState) \
ASMAtomicCmpXchgU32((uint32_t volatile *)&(pVCpu)->enmState, (enmNewState), (enmOldState))
/** Checks the VMCPU state. */
#ifdef VBOX_STRICT
# define VMCPU_ASSERT_STATE(pVCpu, enmExpectedState) \
do { \
VMCPUSTATE enmState = VMCPU_GET_STATE(pVCpu); \
AssertMsg(enmState == (enmExpectedState), \
("enmState=%d enmExpectedState=%d idCpu=%u\n", \
enmState, enmExpectedState, (pVCpu)->idCpu)); \
} while (0)
#else
# define VMCPU_ASSERT_STATE(pVCpu, enmExpectedState) do { } while (0)
#endif
/** Tests if the state means that the CPU is started. */
#define VMCPUSTATE_IS_STARTED(enmState) ( (enmState) > VMCPUSTATE_STOPPED )
/** Tests if the state means that the CPU is stopped. */
#define VMCPUSTATE_IS_STOPPED(enmState) ( (enmState) == VMCPUSTATE_STOPPED )
/** @} */
/** The name of the raw-mode context VMM Core module. */
#define VMMRC_MAIN_MODULE_NAME "VMMRC.rc"
/** The name of the ring-0 context VMM Core module. */
#define VMMR0_MAIN_MODULE_NAME "VMMR0.r0"
/**
* Wrapper macro for avoiding too much \#ifdef VBOX_WITH_RAW_MODE.
*/
#ifdef VBOX_WITH_RAW_MODE
# define VM_WHEN_RAW_MODE(a_WithExpr, a_WithoutExpr) a_WithExpr
#else
# define VM_WHEN_RAW_MODE(a_WithExpr, a_WithoutExpr) a_WithoutExpr
#endif
/** VM Forced Action Flags.
*
* Use the VM_FF_SET() and VM_FF_CLEAR() macros to change the force
* action mask of a VM.
*
* Available VM bits:
* 0, 1, 5, 6, 7, 13, 14, 15, 16, 17, 21, 22, 23, 24, 25, 26, 27, 28, 30
*
*
* Available VMCPU bits:
* 11, 14, 15, 31
*
* @todo If we run low on VMCPU, we may consider merging the SELM bits
*
* @{
*/
/** The virtual sync clock has been stopped, go to TM until it has been
* restarted... */
#define VM_FF_TM_VIRTUAL_SYNC RT_BIT_32(2)
/** PDM Queues are pending. */
#define VM_FF_PDM_QUEUES RT_BIT_32(VM_FF_PDM_QUEUES_BIT)
/** The bit number for VM_FF_PDM_QUEUES. */
#define VM_FF_PDM_QUEUES_BIT 3
/** PDM DMA transfers are pending. */
#define VM_FF_PDM_DMA RT_BIT_32(VM_FF_PDM_DMA_BIT)
/** The bit number for VM_FF_PDM_DMA. */
#define VM_FF_PDM_DMA_BIT 4
/** This action forces the VM to call DBGF so DBGF can service debugger
* requests in the emulation thread.
* This action flag stays asserted till DBGF clears it.*/
#define VM_FF_DBGF RT_BIT_32(VM_FF_DBGF_BIT)
/** The bit number for VM_FF_DBGF. */
#define VM_FF_DBGF_BIT 8
/** This action forces the VM to service pending requests from other
* thread or requests which must be executed in another context. */
#define VM_FF_REQUEST RT_BIT_32(9)
/** Check for VM state changes and take appropriate action. */
#define VM_FF_CHECK_VM_STATE RT_BIT_32(VM_FF_CHECK_VM_STATE_BIT)
/** The bit number for VM_FF_CHECK_VM_STATE. */
#define VM_FF_CHECK_VM_STATE_BIT 10
/** Reset the VM. (postponed) */
#define VM_FF_RESET RT_BIT_32(VM_FF_RESET_BIT)
/** The bit number for VM_FF_RESET. */
#define VM_FF_RESET_BIT 11
/** EMT rendezvous in VMM. */
#define VM_FF_EMT_RENDEZVOUS RT_BIT_32(VM_FF_EMT_RENDEZVOUS_BIT)
/** The bit number for VM_FF_EMT_RENDEZVOUS. */
#define VM_FF_EMT_RENDEZVOUS_BIT 12
/** PGM needs to allocate handy pages. */
#define VM_FF_PGM_NEED_HANDY_PAGES RT_BIT_32(18)
/** PGM is out of memory.
* Abandon all loops and code paths which can be resumed and get up to the EM
* loops. */
#define VM_FF_PGM_NO_MEMORY RT_BIT_32(19)
/** PGM is about to perform a lightweight pool flush
* Guest SMP: all EMT threads should return to ring 3
*/
#define VM_FF_PGM_POOL_FLUSH_PENDING RT_BIT_32(20)
/** REM needs to be informed about handler changes. */
#define VM_FF_REM_HANDLER_NOTIFY RT_BIT_32(VM_FF_REM_HANDLER_NOTIFY_BIT)
/** The bit number for VM_FF_REM_HANDLER_NOTIFY. */
#define VM_FF_REM_HANDLER_NOTIFY_BIT 29
/** Suspend the VM - debug only. */
#define VM_FF_DEBUG_SUSPEND RT_BIT_32(31)
/** This action forces the VM to check any pending interrupts on the APIC. */
#define VMCPU_FF_INTERRUPT_APIC RT_BIT_32(0)
/** This action forces the VM to check any pending interrups on the PIC. */
#define VMCPU_FF_INTERRUPT_PIC RT_BIT_32(1)
/** This action forces the VM to schedule and run pending timer (TM).
* @remarks Don't move - PATM compatibility. */
#define VMCPU_FF_TIMER RT_BIT_32(2)
/** This action forces the VM to check any pending NMIs. */
#define VMCPU_FF_INTERRUPT_NMI_BIT 3
#define VMCPU_FF_INTERRUPT_NMI RT_BIT_32(VMCPU_FF_INTERRUPT_NMI_BIT)
/** This action forces the VM to check any pending SMIs. */
#define VMCPU_FF_INTERRUPT_SMI_BIT 4
#define VMCPU_FF_INTERRUPT_SMI RT_BIT_32(VMCPU_FF_INTERRUPT_SMI_BIT)
/** PDM critical section unlocking is pending, process promptly upon return to R3. */
#define VMCPU_FF_PDM_CRITSECT RT_BIT_32(5)
/** Special EM internal force flag that is used by EMUnhaltAndWakeUp() to force
* the virtual CPU out of the next (/current) halted state. It is not processed
* nor cleared by emR3ForcedActions (similar to VMCPU_FF_BLOCK_NMIS), instead it
* is cleared the next time EM leaves the HALTED state. */
#define VMCPU_FF_UNHALT RT_BIT_32(6)
/** Pending IEM action (bit number). */
#define VMCPU_FF_IEM_BIT 7
/** Pending IEM action (mask). */
#define VMCPU_FF_IEM RT_BIT_32(VMCPU_FF_IEM_BIT)
/** Pending APIC action (bit number). */
#define VMCPU_FF_UPDATE_APIC_BIT 8
/** This action forces the VM to update APIC's asynchronously arrived
* interrupts as pending interrupts. */
#define VMCPU_FF_UPDATE_APIC RT_BIT_32(VMCPU_FF_UPDATE_APIC_BIT)
/** This action forces the VM to service pending requests from other
* thread or requests which must be executed in another context. */
#define VMCPU_FF_REQUEST RT_BIT_32(9)
/** Pending DBGF event (alternative to passing VINF_EM_DBG_EVENT around). */
#define VMCPU_FF_DBGF RT_BIT_32(VMCPU_FF_DBGF_BIT)
/** The bit number for VMCPU_FF_DBGF. */
#define VMCPU_FF_DBGF_BIT 10
/** This action forces the VM to service any pending updates to CR3 (used only
* by HM). */
#define VMCPU_FF_HM_UPDATE_CR3 RT_BIT_32(12)
/** This action forces the VM to service any pending updates to PAE PDPEs (used
* only by HM). */
#define VMCPU_FF_HM_UPDATE_PAE_PDPES RT_BIT_32(13)
/** This action forces the VM to resync the page tables before going
* back to execute guest code. (GLOBAL FLUSH) */
#define VMCPU_FF_PGM_SYNC_CR3 RT_BIT_32(16)
/** Same as VM_FF_PGM_SYNC_CR3 except that global pages can be skipped.
* (NON-GLOBAL FLUSH) */
#define VMCPU_FF_PGM_SYNC_CR3_NON_GLOBAL RT_BIT_32(17)
/** Check for pending TLB shootdown actions (deprecated)
* Reserved for furture HM re-use if necessary / safe.
* Consumer: HM */
#define VMCPU_FF_TLB_SHOOTDOWN_UNUSED RT_BIT_32(18)
/** Check for pending TLB flush action.
* Consumer: HM
* @todo rename to VMCPU_FF_HM_TLB_FLUSH */
#define VMCPU_FF_TLB_FLUSH RT_BIT_32(VMCPU_FF_TLB_FLUSH_BIT)
/** The bit number for VMCPU_FF_TLB_FLUSH. */
#define VMCPU_FF_TLB_FLUSH_BIT 19
#ifdef VBOX_WITH_RAW_MODE
/** Check the interrupt and trap gates */
# define VMCPU_FF_TRPM_SYNC_IDT RT_BIT_32(20)
/** Check Guest's TSS ring 0 stack */
# define VMCPU_FF_SELM_SYNC_TSS RT_BIT_32(21)
/** Check Guest's GDT table */
# define VMCPU_FF_SELM_SYNC_GDT RT_BIT_32(22)
/** Check Guest's LDT table */
# define VMCPU_FF_SELM_SYNC_LDT RT_BIT_32(23)
#endif /* VBOX_WITH_RAW_MODE */
/** Inhibit interrupts pending. See EMGetInhibitInterruptsPC(). */
#define VMCPU_FF_INHIBIT_INTERRUPTS RT_BIT_32(24)
/** Block injection of non-maskable interrupts to the guest. */
#define VMCPU_FF_BLOCK_NMIS RT_BIT_32(25)
#ifdef VBOX_WITH_RAW_MODE
/** CSAM needs to scan the page that's being executed */
# define VMCPU_FF_CSAM_SCAN_PAGE RT_BIT_32(26)
/** CSAM needs to do some homework. */
# define VMCPU_FF_CSAM_PENDING_ACTION RT_BIT_32(27)
#endif /* VBOX_WITH_RAW_MODE */
/** Force return to Ring-3. */
#define VMCPU_FF_TO_R3 RT_BIT_32(28)
/** Force return to ring-3 to service pending I/O or MMIO write.
* This is a backup for mechanism VINF_IOM_R3_IOPORT_COMMIT_WRITE and
* VINF_IOM_R3_MMIO_COMMIT_WRITE, allowing VINF_EM_DBG_BREAKPOINT and similar
* status codes to be propagated at the same time without loss. */
#define VMCPU_FF_IOM RT_BIT_32(29)
#ifdef VBOX_WITH_RAW_MODE
/** CPUM need to adjust CR0.TS/EM before executing raw-mode code again. */
# define VMCPU_FF_CPUM RT_BIT_32(VMCPU_FF_CPUM_BIT)
/** The bit number for VMCPU_FF_CPUM. */
# define VMCPU_FF_CPUM_BIT 30
#endif /* VBOX_WITH_RAW_MODE */
/** Hardware virtualized nested-guest interrupt pending. */
#define VMCPU_FF_INTERRUPT_NESTED_GUEST RT_BIT_32(31)
/** Externally VM forced actions. Used to quit the idle/wait loop. */
#define VM_FF_EXTERNAL_SUSPENDED_MASK ( VM_FF_CHECK_VM_STATE | VM_FF_DBGF | VM_FF_REQUEST | VM_FF_EMT_RENDEZVOUS )
/** Externally VMCPU forced actions. Used to quit the idle/wait loop. */
#define VMCPU_FF_EXTERNAL_SUSPENDED_MASK ( VMCPU_FF_REQUEST | VMCPU_FF_DBGF )
/** Externally forced VM actions. Used to quit the idle/wait loop. */
#define VM_FF_EXTERNAL_HALTED_MASK ( VM_FF_CHECK_VM_STATE | VM_FF_DBGF | VM_FF_REQUEST \
| VM_FF_PDM_QUEUES | VM_FF_PDM_DMA | VM_FF_EMT_RENDEZVOUS )
/** Externally forced VMCPU actions. Used to quit the idle/wait loop. */
#define VMCPU_FF_EXTERNAL_HALTED_MASK ( VMCPU_FF_UPDATE_APIC | VMCPU_FF_INTERRUPT_APIC | VMCPU_FF_INTERRUPT_PIC \
| VMCPU_FF_REQUEST | VMCPU_FF_INTERRUPT_NMI | VMCPU_FF_INTERRUPT_SMI \
| VMCPU_FF_UNHALT | VMCPU_FF_TIMER | VMCPU_FF_DBGF )
/** High priority VM pre-execution actions. */
#define VM_FF_HIGH_PRIORITY_PRE_MASK ( VM_FF_CHECK_VM_STATE | VM_FF_DBGF | VM_FF_TM_VIRTUAL_SYNC \
| VM_FF_DEBUG_SUSPEND | VM_FF_PGM_NEED_HANDY_PAGES | VM_FF_PGM_NO_MEMORY \
| VM_FF_EMT_RENDEZVOUS )
/** High priority VMCPU pre-execution actions. */
#define VMCPU_FF_HIGH_PRIORITY_PRE_MASK ( VMCPU_FF_TIMER | VMCPU_FF_INTERRUPT_APIC | VMCPU_FF_INTERRUPT_PIC \
| VMCPU_FF_UPDATE_APIC | VMCPU_FF_INHIBIT_INTERRUPTS | VMCPU_FF_DBGF \
| VMCPU_FF_PGM_SYNC_CR3 | VMCPU_FF_PGM_SYNC_CR3_NON_GLOBAL \
| VM_WHEN_RAW_MODE( VMCPU_FF_SELM_SYNC_TSS | VMCPU_FF_TRPM_SYNC_IDT \
| VMCPU_FF_SELM_SYNC_GDT | VMCPU_FF_SELM_SYNC_LDT, 0 ) )
/** High priority VM pre raw-mode execution mask. */
#define VM_FF_HIGH_PRIORITY_PRE_RAW_MASK ( VM_FF_PGM_NEED_HANDY_PAGES | VM_FF_PGM_NO_MEMORY )
/** High priority VMCPU pre raw-mode execution mask. */
#define VMCPU_FF_HIGH_PRIORITY_PRE_RAW_MASK ( VMCPU_FF_PGM_SYNC_CR3 | VMCPU_FF_PGM_SYNC_CR3_NON_GLOBAL \
| VMCPU_FF_INHIBIT_INTERRUPTS \
| VM_WHEN_RAW_MODE( VMCPU_FF_SELM_SYNC_TSS | VMCPU_FF_TRPM_SYNC_IDT \
| VMCPU_FF_SELM_SYNC_GDT | VMCPU_FF_SELM_SYNC_LDT, 0) )
/** High priority post-execution actions. */
#define VM_FF_HIGH_PRIORITY_POST_MASK ( VM_FF_PGM_NO_MEMORY )
/** High priority post-execution actions. */
#define VMCPU_FF_HIGH_PRIORITY_POST_MASK ( VMCPU_FF_PDM_CRITSECT | VM_WHEN_RAW_MODE(VMCPU_FF_CSAM_PENDING_ACTION, 0) \
| VMCPU_FF_HM_UPDATE_CR3 | VMCPU_FF_HM_UPDATE_PAE_PDPES \
| VMCPU_FF_IEM | VMCPU_FF_IOM )
/** Normal priority VM post-execution actions. */
#define VM_FF_NORMAL_PRIORITY_POST_MASK ( VM_FF_CHECK_VM_STATE | VM_FF_DBGF | VM_FF_RESET \
| VM_FF_PGM_NO_MEMORY | VM_FF_EMT_RENDEZVOUS)
/** Normal priority VMCPU post-execution actions. */
#define VMCPU_FF_NORMAL_PRIORITY_POST_MASK ( VM_WHEN_RAW_MODE(VMCPU_FF_CSAM_SCAN_PAGE, 0) | VMCPU_FF_DBGF )
/** Normal priority VM actions. */
#define VM_FF_NORMAL_PRIORITY_MASK ( VM_FF_REQUEST | VM_FF_PDM_QUEUES | VM_FF_PDM_DMA \
| VM_FF_REM_HANDLER_NOTIFY | VM_FF_EMT_RENDEZVOUS)
/** Normal priority VMCPU actions. */
#define VMCPU_FF_NORMAL_PRIORITY_MASK ( VMCPU_FF_REQUEST )
/** Flags to clear before resuming guest execution. */
#define VMCPU_FF_RESUME_GUEST_MASK ( VMCPU_FF_TO_R3 )
/** VM flags that cause the REP[|NE|E] STRINS loops to yield immediately. */
#define VM_FF_HIGH_PRIORITY_POST_REPSTR_MASK ( VM_FF_TM_VIRTUAL_SYNC | VM_FF_PGM_NEED_HANDY_PAGES | VM_FF_PGM_NO_MEMORY \
| VM_FF_EMT_RENDEZVOUS | VM_FF_PGM_POOL_FLUSH_PENDING | VM_FF_RESET)
/** VM flags that cause the REP[|NE|E] STRINS loops to yield. */
#define VM_FF_YIELD_REPSTR_MASK ( VM_FF_HIGH_PRIORITY_POST_REPSTR_MASK \
| VM_FF_PDM_QUEUES | VM_FF_PDM_DMA | VM_FF_DBGF | VM_FF_DEBUG_SUSPEND )
/** VMCPU flags that cause the REP[|NE|E] STRINS loops to yield immediately. */
#ifdef IN_RING3
# define VMCPU_FF_HIGH_PRIORITY_POST_REPSTR_MASK ( VMCPU_FF_PGM_SYNC_CR3 | VMCPU_FF_PGM_SYNC_CR3_NON_GLOBAL | VMCPU_FF_DBGF )
#else
# define VMCPU_FF_HIGH_PRIORITY_POST_REPSTR_MASK ( VMCPU_FF_TO_R3 | VMCPU_FF_IEM | VMCPU_FF_IOM | VMCPU_FF_PGM_SYNC_CR3 \
| VMCPU_FF_PGM_SYNC_CR3_NON_GLOBAL | VMCPU_FF_DBGF )
#endif
/** VMCPU flags that cause the REP[|NE|E] STRINS loops to yield, interrupts
* enabled. */
#define VMCPU_FF_YIELD_REPSTR_MASK ( VMCPU_FF_HIGH_PRIORITY_POST_REPSTR_MASK \
| VMCPU_FF_INTERRUPT_APIC | VMCPU_FF_UPDATE_APIC | VMCPU_FF_INTERRUPT_PIC \
| VMCPU_FF_INTERRUPT_NMI | VMCPU_FF_INTERRUPT_SMI | VMCPU_FF_PDM_CRITSECT \
| VMCPU_FF_TIMER | VMCPU_FF_REQUEST )
/** VMCPU flags that cause the REP[|NE|E] STRINS loops to yield, interrupts
* disabled. */
#define VMCPU_FF_YIELD_REPSTR_NOINT_MASK ( VMCPU_FF_YIELD_REPSTR_MASK \
& ~(VMCPU_FF_INTERRUPT_APIC | VMCPU_FF_UPDATE_APIC | VMCPU_FF_INTERRUPT_PIC) )
/** VM Flags that cause the HM loops to go back to ring-3. */
#define VM_FF_HM_TO_R3_MASK ( VM_FF_TM_VIRTUAL_SYNC | VM_FF_PGM_NEED_HANDY_PAGES | VM_FF_PGM_NO_MEMORY \
| VM_FF_PDM_QUEUES | VM_FF_EMT_RENDEZVOUS)
/** VMCPU Flags that cause the HM loops to go back to ring-3. */
#define VMCPU_FF_HM_TO_R3_MASK ( VMCPU_FF_TO_R3 | VMCPU_FF_TIMER | VMCPU_FF_PDM_CRITSECT \
| VMCPU_FF_IEM | VMCPU_FF_IOM)
/** High priority ring-0 VM pre HM-mode execution mask. */
#define VM_FF_HP_R0_PRE_HM_MASK (VM_FF_HM_TO_R3_MASK | VM_FF_REQUEST | VM_FF_PGM_POOL_FLUSH_PENDING | VM_FF_PDM_DMA)
/** High priority ring-0 VMCPU pre HM-mode execution mask. */
#define VMCPU_FF_HP_R0_PRE_HM_MASK ( VMCPU_FF_HM_TO_R3_MASK | VMCPU_FF_PGM_SYNC_CR3 \
| VMCPU_FF_PGM_SYNC_CR3_NON_GLOBAL | VMCPU_FF_REQUEST)
/** High priority ring-0 VM pre HM-mode execution mask, single stepping. */
#define VM_FF_HP_R0_PRE_HM_STEP_MASK (VM_FF_HP_R0_PRE_HM_MASK & ~( VM_FF_TM_VIRTUAL_SYNC | VM_FF_PDM_QUEUES \
| VM_FF_EMT_RENDEZVOUS | VM_FF_REQUEST \
| VM_FF_PDM_DMA) )
/** High priority ring-0 VMCPU pre HM-mode execution mask, single stepping. */
#define VMCPU_FF_HP_R0_PRE_HM_STEP_MASK (VMCPU_FF_HP_R0_PRE_HM_MASK & ~( VMCPU_FF_TO_R3 | VMCPU_FF_TIMER \
| VMCPU_FF_PDM_CRITSECT | VMCPU_FF_REQUEST) )
/** All the forced VM flags. */
#define VM_FF_ALL_MASK (UINT32_MAX)
/** All the forced VMCPU flags. */
#define VMCPU_FF_ALL_MASK (UINT32_MAX)
/** All the forced VM flags except those related to raw-mode and hardware
* assisted execution. */
#define VM_FF_ALL_REM_MASK (~(VM_FF_HIGH_PRIORITY_PRE_RAW_MASK) | VM_FF_PGM_NEED_HANDY_PAGES | VM_FF_PGM_NO_MEMORY)
/** All the forced VMCPU flags except those related to raw-mode and hardware
* assisted execution. */
#define VMCPU_FF_ALL_REM_MASK (~( VMCPU_FF_HIGH_PRIORITY_PRE_RAW_MASK | VMCPU_FF_PDM_CRITSECT \
| VMCPU_FF_TLB_FLUSH | VM_WHEN_RAW_MODE(VMCPU_FF_CSAM_PENDING_ACTION, 0) ))
/** @} */
/** @def VM_FF_SET
* Sets a force action flag.
*
* @param pVM The cross context VM structure.
* @param fFlag The flag to set.
*/
#if 1
# define VM_FF_SET(pVM, fFlag) ASMAtomicOrU32(&(pVM)->fGlobalForcedActions, (fFlag))
#else
# define VM_FF_SET(pVM, fFlag) \
do { ASMAtomicOrU32(&(pVM)->fGlobalForcedActions, (fFlag)); \
RTLogPrintf("VM_FF_SET : %08x %s - %s(%d) %s\n", (pVM)->fGlobalForcedActions, #fFlag, __FILE__, __LINE__, __FUNCTION__); \
} while (0)
#endif
/** @def VMCPU_FF_SET
* Sets a force action flag for the given VCPU.
*
* @param pVCpu The cross context virtual CPU structure.
* @param fFlag The flag to set.
*/
#define VMCPU_FF_SET(pVCpu, fFlag) ASMAtomicOrU32(&(pVCpu)->fLocalForcedActions, (fFlag))
/** @def VM_FF_CLEAR
* Clears a force action flag.
*
* @param pVM The cross context VM structure.
* @param fFlag The flag to clear.
*/
#if 1
# define VM_FF_CLEAR(pVM, fFlag) ASMAtomicAndU32(&(pVM)->fGlobalForcedActions, ~(fFlag))
#else
# define VM_FF_CLEAR(pVM, fFlag) \
do { ASMAtomicAndU32(&(pVM)->fGlobalForcedActions, ~(fFlag)); \
RTLogPrintf("VM_FF_CLEAR: %08x %s - %s(%d) %s\n", (pVM)->fGlobalForcedActions, #fFlag, __FILE__, __LINE__, __FUNCTION__); \
} while (0)
#endif
/** @def VMCPU_FF_CLEAR
* Clears a force action flag for the given VCPU.
*
* @param pVCpu The cross context virtual CPU structure.
* @param fFlag The flag to clear.
*/
#define VMCPU_FF_CLEAR(pVCpu, fFlag) ASMAtomicAndU32(&(pVCpu)->fLocalForcedActions, ~(fFlag))
/** @def VM_FF_IS_SET
* Checks if a force action flag is set.
*
* @param pVM The cross context VM structure.
* @param fFlag The flag to check.
*/
#define VM_FF_IS_SET(pVM, fFlag) (((pVM)->fGlobalForcedActions & (fFlag)) == (fFlag))
/** @def VMCPU_FF_IS_SET
* Checks if a force action flag is set for the given VCPU.
*
* @param pVCpu The cross context virtual CPU structure.
* @param fFlag The flag to check.
*/
#define VMCPU_FF_IS_SET(pVCpu, fFlag) (((pVCpu)->fLocalForcedActions & (fFlag)) == (fFlag))
/** @def VM_FF_IS_PENDING
* Checks if one or more force action in the specified set is pending.
*
* @param pVM The cross context VM structure.
* @param fFlags The flags to check for.
*/
#define VM_FF_IS_PENDING(pVM, fFlags) RT_BOOL((pVM)->fGlobalForcedActions & (fFlags))
/** @def VM_FF_TEST_AND_CLEAR
* Checks if one (!) force action in the specified set is pending and clears it atomically
*
* @returns true if the bit was set.
* @returns false if the bit was clear.
* @param pVM The cross context VM structure.
* @param iBit Bit position to check and clear
*/
#define VM_FF_TEST_AND_CLEAR(pVM, iBit) (ASMAtomicBitTestAndClear(&(pVM)->fGlobalForcedActions, iBit##_BIT))
/** @def VMCPU_FF_TEST_AND_CLEAR
* Checks if one (!) force action in the specified set is pending and clears it atomically
*
* @returns true if the bit was set.
* @returns false if the bit was clear.
* @param pVCpu The cross context virtual CPU structure.
* @param iBit Bit position to check and clear
*/
#define VMCPU_FF_TEST_AND_CLEAR(pVCpu, iBit) (ASMAtomicBitTestAndClear(&(pVCpu)->fLocalForcedActions, iBit##_BIT))
/** @def VMCPU_FF_IS_PENDING
* Checks if one or more force action in the specified set is pending for the given VCPU.
*
* @param pVCpu The cross context virtual CPU structure.
* @param fFlags The flags to check for.
*/
#define VMCPU_FF_IS_PENDING(pVCpu, fFlags) RT_BOOL((pVCpu)->fLocalForcedActions & (fFlags))
/** @def VM_FF_IS_PENDING_EXCEPT
* Checks if one or more force action in the specified set is pending while one
* or more other ones are not.
*
* @param pVM The cross context VM structure.
* @param fFlags The flags to check for.
* @param fExcpt The flags that should not be set.
*/
#define VM_FF_IS_PENDING_EXCEPT(pVM, fFlags, fExcpt) ( ((pVM)->fGlobalForcedActions & (fFlags)) && !((pVM)->fGlobalForcedActions & (fExcpt)) )
/** @def VMCPU_FF_IS_PENDING_EXCEPT
* Checks if one or more force action in the specified set is pending for the given
* VCPU while one or more other ones are not.
*
* @param pVCpu The cross context virtual CPU structure.
* @param fFlags The flags to check for.
* @param fExcpt The flags that should not be set.
*/
#define VMCPU_FF_IS_PENDING_EXCEPT(pVCpu, fFlags, fExcpt) ( ((pVCpu)->fLocalForcedActions & (fFlags)) && !((pVCpu)->fLocalForcedActions & (fExcpt)) )
/** @def VM_IS_EMT
* Checks if the current thread is the emulation thread (EMT).
*
* @remark The ring-0 variation will need attention if we expand the ring-0
* code to let threads other than EMT mess around with the VM.
*/
#ifdef IN_RC
# define VM_IS_EMT(pVM) true
#else
# define VM_IS_EMT(pVM) (VMMGetCpu(pVM) != NULL)
#endif
/** @def VMCPU_IS_EMT
* Checks if the current thread is the emulation thread (EMT) for the specified
* virtual CPU.
*/
#ifdef IN_RC
# define VMCPU_IS_EMT(pVCpu) true
#else
# define VMCPU_IS_EMT(pVCpu) ((pVCpu) && ((pVCpu) == VMMGetCpu((pVCpu)->CTX_SUFF(pVM))))
#endif
/** @def VM_ASSERT_EMT
* Asserts that the current thread IS the emulation thread (EMT).
*/
#ifdef IN_RC
# define VM_ASSERT_EMT(pVM) Assert(VM_IS_EMT(pVM))
#elif defined(IN_RING0)
# define VM_ASSERT_EMT(pVM) Assert(VM_IS_EMT(pVM))
#else
# define VM_ASSERT_EMT(pVM) \
AssertMsg(VM_IS_EMT(pVM), \
("Not emulation thread! Thread=%RTnthrd ThreadEMT=%RTnthrd\n", RTThreadNativeSelf(), VMR3GetVMCPUNativeThread(pVM)))
#endif
/** @def VMCPU_ASSERT_EMT
* Asserts that the current thread IS the emulation thread (EMT) of the
* specified virtual CPU.
*/
#ifdef IN_RC
# define VMCPU_ASSERT_EMT(pVCpu) Assert(VMCPU_IS_EMT(pVCpu))
#elif defined(IN_RING0)
# define VMCPU_ASSERT_EMT(pVCpu) AssertMsg(VMCPU_IS_EMT(pVCpu), \
("Not emulation thread! Thread=%RTnthrd ThreadEMT=%RTnthrd idCpu=%u\n", \
RTThreadNativeSelf(), (pVCpu) ? (pVCpu)->hNativeThreadR0 : 0, \
(pVCpu) ? (pVCpu)->idCpu : 0))
#else
# define VMCPU_ASSERT_EMT(pVCpu) AssertMsg(VMCPU_IS_EMT(pVCpu), \
("Not emulation thread! Thread=%RTnthrd ThreadEMT=%RTnthrd idCpu=%#x\n", \
RTThreadNativeSelf(), (pVCpu)->hNativeThread, (pVCpu)->idCpu))
#endif
/** @def VM_ASSERT_EMT_RETURN
* Asserts that the current thread IS the emulation thread (EMT) and returns if it isn't.
*/
#ifdef IN_RC
# define VM_ASSERT_EMT_RETURN(pVM, rc) AssertReturn(VM_IS_EMT(pVM), (rc))
#elif defined(IN_RING0)
# define VM_ASSERT_EMT_RETURN(pVM, rc) AssertReturn(VM_IS_EMT(pVM), (rc))
#else
# define VM_ASSERT_EMT_RETURN(pVM, rc) \
AssertMsgReturn(VM_IS_EMT(pVM), \
("Not emulation thread! Thread=%RTnthrd ThreadEMT=%RTnthrd\n", RTThreadNativeSelf(), VMR3GetVMCPUNativeThread(pVM)), \
(rc))
#endif
/** @def VMCPU_ASSERT_EMT_RETURN
* Asserts that the current thread IS the emulation thread (EMT) and returns if it isn't.
*/
#ifdef IN_RC
# define VMCPU_ASSERT_EMT_RETURN(pVCpu, rc) AssertReturn(VMCPU_IS_EMT(pVCpu), (rc))
#elif defined(IN_RING0)
# define VMCPU_ASSERT_EMT_RETURN(pVCpu, rc) AssertReturn(VMCPU_IS_EMT(pVCpu), (rc))
#else
# define VMCPU_ASSERT_EMT_RETURN(pVCpu, rc) \
AssertMsgReturn(VMCPU_IS_EMT(pVCpu), \
("Not emulation thread! Thread=%RTnthrd ThreadEMT=%RTnthrd idCpu=%#x\n", \
RTThreadNativeSelf(), (pVCpu)->hNativeThread, (pVCpu)->idCpu), \
(rc))
#endif
/** @def VMCPU_ASSERT_EMT_OR_GURU
* Asserts that the current thread IS the emulation thread (EMT) of the
* specified virtual CPU.
*/
#if defined(IN_RC) || defined(IN_RING0)
# define VMCPU_ASSERT_EMT_OR_GURU(pVCpu) Assert( VMCPU_IS_EMT(pVCpu) \
|| pVCpu->CTX_SUFF(pVM)->enmVMState == VMSTATE_GURU_MEDITATION \
|| pVCpu->CTX_SUFF(pVM)->enmVMState == VMSTATE_GURU_MEDITATION_LS )
#else
# define VMCPU_ASSERT_EMT_OR_GURU(pVCpu) \
AssertMsg( VMCPU_IS_EMT(pVCpu) \
|| pVCpu->CTX_SUFF(pVM)->enmVMState == VMSTATE_GURU_MEDITATION \
|| pVCpu->CTX_SUFF(pVM)->enmVMState == VMSTATE_GURU_MEDITATION_LS, \
("Not emulation thread! Thread=%RTnthrd ThreadEMT=%RTnthrd idCpu=%#x\n", \
RTThreadNativeSelf(), (pVCpu)->hNativeThread, (pVCpu)->idCpu))
#endif
/** @def VMCPU_ASSERT_EMT_OR_NOT_RUNNING
* Asserts that the current thread IS the emulation thread (EMT) of the
* specified virtual CPU or the VM is not running.
*/
#if defined(IN_RC) || defined(IN_RING0)
# define VMCPU_ASSERT_EMT_OR_NOT_RUNNING(pVCpu) \
Assert( VMCPU_IS_EMT(pVCpu) \
|| !VM_IS_RUNNING_FOR_ASSERTIONS_ONLY((pVCpu)->CTX_SUFF(pVM)) )
#else
# define VMCPU_ASSERT_EMT_OR_NOT_RUNNING(pVCpu) \
AssertMsg( VMCPU_IS_EMT(pVCpu) \
|| !VM_IS_RUNNING_FOR_ASSERTIONS_ONLY((pVCpu)->CTX_SUFF(pVM)), \
("Not emulation thread! Thread=%RTnthrd ThreadEMT=%RTnthrd idCpu=%#x\n", \
RTThreadNativeSelf(), (pVCpu)->hNativeThread, (pVCpu)->idCpu))
#endif
/** @def VM_IS_RUNNING_FOR_ASSERTIONS_ONLY
* Checks if the the VM is running.
* @note Thie is only for pure debug assertions. No AssertReturn or similar!
*/
#define VM_IS_RUNNING_FOR_ASSERTIONS_ONLY(pVM) \
( (pVM)->enmVMState == VMSTATE_RUNNING \
|| (pVM)->enmVMState == VMSTATE_RUNNING_LS \
|| (pVM)->enmVMState == VMSTATE_RUNNING_FT )
/** @def VM_ASSERT_IS_NOT_RUNNING
* Asserts that the VM is not running.
*/
#if defined(IN_RC) || defined(IN_RING0)
#define VM_ASSERT_IS_NOT_RUNNING(pVM) Assert(!VM_IS_RUNNING_FOR_ASSERTIONS_ONLY(pVM))
#else
#define VM_ASSERT_IS_NOT_RUNNING(pVM) AssertMsg(!VM_IS_RUNNING_FOR_ASSERTIONS_ONLY(pVM), \
("VM is running. enmVMState=%d\n", (pVM)->enmVMState))
#endif
/** @def VM_ASSERT_EMT0
* Asserts that the current thread IS emulation thread \#0 (EMT0).
*/
#define VM_ASSERT_EMT0(pVM) VMCPU_ASSERT_EMT(&(pVM)->aCpus[0])
/** @def VM_ASSERT_EMT0_RETURN
* Asserts that the current thread IS emulation thread \#0 (EMT0) and returns if
* it isn't.
*/
#define VM_ASSERT_EMT0_RETURN(pVM, rc) VMCPU_ASSERT_EMT_RETURN(&(pVM)->aCpus[0], (rc))
/**
* Asserts that the current thread is NOT the emulation thread.
*/
#define VM_ASSERT_OTHER_THREAD(pVM) \
AssertMsg(!VM_IS_EMT(pVM), ("Not other thread!!\n"))
/** @def VM_ASSERT_STATE
* Asserts a certain VM state.
*/
#define VM_ASSERT_STATE(pVM, _enmState) \
AssertMsg((pVM)->enmVMState == (_enmState), \
("state %s, expected %s\n", VMGetStateName((pVM)->enmVMState), VMGetStateName(_enmState)))
/** @def VM_ASSERT_STATE_RETURN
* Asserts a certain VM state and returns if it doesn't match.
*/
#define VM_ASSERT_STATE_RETURN(pVM, _enmState, rc) \
AssertMsgReturn((pVM)->enmVMState == (_enmState), \
("state %s, expected %s\n", VMGetStateName((pVM)->enmVMState), VMGetStateName(_enmState)), \
(rc))
/** @def VM_IS_VALID_EXT
* Asserts a the VM handle is valid for external access, i.e. not being destroy
* or terminated. */
#define VM_IS_VALID_EXT(pVM) \
( RT_VALID_ALIGNED_PTR(pVM, PAGE_SIZE) \
&& ( (unsigned)(pVM)->enmVMState < (unsigned)VMSTATE_DESTROYING \
|| ( (unsigned)(pVM)->enmVMState == (unsigned)VMSTATE_DESTROYING \
&& VM_IS_EMT(pVM))) )
/** @def VM_ASSERT_VALID_EXT_RETURN
* Asserts a the VM handle is valid for external access, i.e. not being
* destroy or terminated.
*/
#define VM_ASSERT_VALID_EXT_RETURN(pVM, rc) \
AssertMsgReturn(VM_IS_VALID_EXT(pVM), \
("pVM=%p state %s\n", (pVM), RT_VALID_ALIGNED_PTR(pVM, PAGE_SIZE) \
? VMGetStateName(pVM->enmVMState) : ""), \
(rc))
/** @def VMCPU_ASSERT_VALID_EXT_RETURN
* Asserts a the VMCPU handle is valid for external access, i.e. not being
* destroy or terminated.
*/
#define VMCPU_ASSERT_VALID_EXT_RETURN(pVCpu, rc) \
AssertMsgReturn( RT_VALID_ALIGNED_PTR(pVCpu, 64) \
&& RT_VALID_ALIGNED_PTR((pVCpu)->CTX_SUFF(pVM), PAGE_SIZE) \
&& (unsigned)(pVCpu)->CTX_SUFF(pVM)->enmVMState < (unsigned)VMSTATE_DESTROYING, \
("pVCpu=%p pVM=%p state %s\n", (pVCpu), RT_VALID_ALIGNED_PTR(pVCpu, 64) ? (pVCpu)->CTX_SUFF(pVM) : NULL, \
RT_VALID_ALIGNED_PTR(pVCpu, 64) && RT_VALID_ALIGNED_PTR((pVCpu)->CTX_SUFF(pVM), PAGE_SIZE) \
? VMGetStateName((pVCpu)->pVMR3->enmVMState) : ""), \
(rc))
#endif /* !VBOX_FOR_DTRACE_LIB */
/**
* The cross context VM structure.
*
* It contains all the VM data which have to be available in all contexts.
* Even if it contains all the data the idea is to use APIs not to modify all
* the members all around the place. Therefore we make use of unions to hide
* everything which isn't local to the current source module. This means we'll
* have to pay a little bit of attention when adding new members to structures
* in the unions and make sure to keep the padding sizes up to date.
*
* Run 'kmk run-struct-tests' (from src/VBox/VMM if you like) after updating!
*/
typedef struct VM
{
/** The state of the VM.
* This field is read only to everyone except the VM and EM. */
VMSTATE volatile enmVMState;
/** Forced action flags.
* See the VM_FF_* \#defines. Updated atomically.
*/
volatile uint32_t fGlobalForcedActions;
/** Pointer to the array of page descriptors for the VM structure allocation. */
R3PTRTYPE(PSUPPAGE) paVMPagesR3;
/** Session handle. For use when calling SUPR0 APIs. */
PSUPDRVSESSION pSession;
/** Pointer to the ring-3 VM structure. */
PUVM pUVM;
/** Ring-3 Host Context VM Pointer. */
R3PTRTYPE(struct VM *) pVMR3;
/** Ring-0 Host Context VM Pointer. */
R0PTRTYPE(struct VM *) pVMR0;
/** Raw-mode Context VM Pointer. */
RCPTRTYPE(struct VM *) pVMRC;
/** The GVM VM handle. Only the GVM should modify this field. */
uint32_t hSelf;
/** Number of virtual CPUs. */
uint32_t cCpus;
/** CPU excution cap (1-100) */
uint32_t uCpuExecutionCap;
/** Size of the VM structure including the VMCPU array. */
uint32_t cbSelf;
/** Offset to the VMCPU array starting from beginning of this structure. */
uint32_t offVMCPU;
/**
* VMMSwitcher assembly entry point returning to host context.
*
* Depending on how the host handles the rc status given in @a eax, this may
* return and let the caller resume whatever it was doing prior to the call.
*
*
* @param eax The return code, register.
* @remark Assume interrupts disabled.
* @remark This method pointer lives here because TRPM needs it.
*/
RTRCPTR pfnVMMRCToHostAsm/*(int32_t eax)*/;
/**
* VMMSwitcher assembly entry point returning to host context without saving the
* raw-mode context (hyper) registers.
*
* Unlike pfnVMMRC2HCAsm, this will not return to the caller. Instead it
* expects the caller to save a RC context in CPUM where one might return if the
* return code indicate that this is possible.
*
* This method pointer lives here because TRPM needs it.
*
* @param eax The return code, register.
* @remark Assume interrupts disabled.
* @remark This method pointer lives here because TRPM needs it.
*/
RTRCPTR pfnVMMRCToHostAsmNoReturn/*(int32_t eax)*/;
/** @name Various items that are frequently accessed.
* @{ */
/** Whether to recompile user mode code or run it raw/hm. */
bool fRecompileUser;
/** Whether to recompile supervisor mode code or run it raw/hm. */
bool fRecompileSupervisor;
/** Whether raw mode supports ring-1 code or not. */
bool fRawRing1Enabled;
/** PATM enabled flag.
* This is placed here for performance reasons. */
bool fPATMEnabled;
/** CSAM enabled flag.
* This is placed here for performance reasons. */
bool fCSAMEnabled;
/** Hardware VM support is available and enabled.
* Determined very early during init.
* This is placed here for performance reasons. */
bool fHMEnabled;
/** For asserting on fHMEnable usage. */
bool fHMEnabledFixed;
/** Hardware VM support requires a minimal raw-mode context.
* This is never set on 64-bit hosts, only 32-bit hosts requires it. */
bool fHMNeedRawModeCtx;
/** Set when this VM is the master FT node.
* @todo This doesn't need to be here, FTM should store it in it's own
* structures instead. */
bool fFaultTolerantMaster;
/** Large page enabled flag.
* @todo This doesn't need to be here, PGM should store it in it's own
* structures instead. */
bool fUseLargePages;
/** @} */
/** Alignment padding. */
uint8_t uPadding1[2];
/** @name Debugging
* @{ */
/** Raw-mode Context VM Pointer. */
RCPTRTYPE(RTTRACEBUF) hTraceBufRC;
/** Ring-3 Host Context VM Pointer. */
R3PTRTYPE(RTTRACEBUF) hTraceBufR3;
/** Ring-0 Host Context VM Pointer. */
R0PTRTYPE(RTTRACEBUF) hTraceBufR0;
/** @} */
#if HC_ARCH_BITS == 32
/** Alignment padding. */
uint32_t uPadding2;
#endif
/** @name Switcher statistics (remove)
* @{ */
/** Profiling the total time from Qemu to GC. */
STAMPROFILEADV StatTotalQemuToGC;
/** Profiling the total time from GC to Qemu. */
STAMPROFILEADV StatTotalGCToQemu;
/** Profiling the total time spent in GC. */
STAMPROFILEADV StatTotalInGC;
/** Profiling the total time spent not in Qemu. */
STAMPROFILEADV StatTotalInQemu;
/** Profiling the VMMSwitcher code for going to GC. */
STAMPROFILEADV StatSwitcherToGC;
/** Profiling the VMMSwitcher code for going to HC. */
STAMPROFILEADV StatSwitcherToHC;
STAMPROFILEADV StatSwitcherSaveRegs;
STAMPROFILEADV StatSwitcherSysEnter;
STAMPROFILEADV StatSwitcherDebug;
STAMPROFILEADV StatSwitcherCR0;
STAMPROFILEADV StatSwitcherCR4;
STAMPROFILEADV StatSwitcherJmpCR3;
STAMPROFILEADV StatSwitcherRstrRegs;
STAMPROFILEADV StatSwitcherLgdt;
STAMPROFILEADV StatSwitcherLidt;
STAMPROFILEADV StatSwitcherLldt;
STAMPROFILEADV StatSwitcherTSS;
/** @} */
/** Padding - the unions must be aligned on a 64 bytes boundary and the unions
* must start at the same offset on both 64-bit and 32-bit hosts. */
uint8_t abAlignment3[(HC_ARCH_BITS == 32 ? 24 : 0) + 40];
/** CPUM part. */
union
{
#ifdef ___CPUMInternal_h
struct CPUM s;
#endif
#ifdef ___VBox_vmm_cpum_h
/** Read only info exposed about the host and guest CPUs. */
struct
{
/** Padding for hidden fields. */
uint8_t abHidden0[64];
/** Host CPU feature information. */
CPUMFEATURES HostFeatures;
/** Guest CPU feature information. */
CPUMFEATURES GuestFeatures;
} const ro;
#endif
uint8_t padding[1536]; /* multiple of 64 */
} cpum;
/** VMM part. */
union
{
#ifdef ___VMMInternal_h
struct VMM s;
#endif
uint8_t padding[1600]; /* multiple of 64 */
} vmm;
/** PGM part. */
union
{
#ifdef ___PGMInternal_h
struct PGM s;
#endif
uint8_t padding[4096*2+6080]; /* multiple of 64 */
} pgm;
/** HM part. */
union
{
#ifdef ___HMInternal_h
struct HM s;
#endif
uint8_t padding[5440]; /* multiple of 64 */
} hm;
/** TRPM part. */
union
{
#ifdef ___TRPMInternal_h
struct TRPM s;
#endif
uint8_t padding[5248]; /* multiple of 64 */
} trpm;
/** SELM part. */
union
{
#ifdef ___SELMInternal_h
struct SELM s;
#endif
uint8_t padding[768]; /* multiple of 64 */
} selm;
/** MM part. */
union
{
#ifdef ___MMInternal_h
struct MM s;
#endif
uint8_t padding[192]; /* multiple of 64 */
} mm;
/** PDM part. */
union
{
#ifdef ___PDMInternal_h
struct PDM s;
#endif
uint8_t padding[1920]; /* multiple of 64 */
} pdm;
/** IOM part. */
union
{
#ifdef ___IOMInternal_h
struct IOM s;
#endif
uint8_t padding[896]; /* multiple of 64 */
} iom;
/** EM part. */
union
{
#ifdef ___EMInternal_h
struct EM s;
#endif
uint8_t padding[256]; /* multiple of 64 */
} em;
/** TM part. */
union
{
#ifdef ___TMInternal_h
struct TM s;
#endif
uint8_t padding[2496]; /* multiple of 64 */
} tm;
/** DBGF part. */
union
{
#ifdef ___DBGFInternal_h
struct DBGF s;
#endif
#ifdef ___VBox_vmm_dbgf_h
/** Read only info exposed about interrupt breakpoints and selected events. */
struct
{
/** Bitmap of enabled hardware interrupt breakpoints. */
uint32_t bmHardIntBreakpoints[256 / 32];
/** Bitmap of enabled software interrupt breakpoints. */
uint32_t bmSoftIntBreakpoints[256 / 32];
/** Bitmap of selected events.
* This includes non-selectable events too for simplicity, we maintain the
* state for some of these, as it may come in handy. */
uint64_t bmSelectedEvents[(DBGFEVENT_END + 63) / 64];
/** Enabled hardware interrupt breakpoints. */
uint32_t cHardIntBreakpoints;
/** Enabled software interrupt breakpoints. */
uint32_t cSoftIntBreakpoints;
/** The number of selected events. */
uint32_t cSelectedEvents;
/** The number of enabled hardware breakpoints. */
uint8_t cEnabledHwBreakpoints;
/** The number of enabled hardware I/O breakpoints. */
uint8_t cEnabledHwIoBreakpoints;
/** The number of enabled INT3 breakpoints. */
uint8_t cEnabledInt3Breakpoints;
uint8_t abPadding[1]; /**< Unused padding space up for grabs. */
} const ro;
#endif
uint8_t padding[2368]; /* multiple of 64 */
} dbgf;
/** SSM part. */
union
{
#ifdef ___SSMInternal_h
struct SSM s;
#endif
uint8_t padding[128]; /* multiple of 64 */
} ssm;
/** FTM part. */
union
{
#ifdef ___FTMInternal_h
struct FTM s;
#endif
uint8_t padding[512]; /* multiple of 64 */
} ftm;
#ifdef VBOX_WITH_RAW_MODE
/** PATM part. */
union
{
# ifdef ___PATMInternal_h
struct PATM s;
# endif
uint8_t padding[768]; /* multiple of 64 */
} patm;
/** CSAM part. */
union
{
# ifdef ___CSAMInternal_h
struct CSAM s;
# endif
uint8_t padding[1088]; /* multiple of 64 */
} csam;
#endif
#ifdef VBOX_WITH_REM
/** REM part. */
union
{
# ifdef ___REMInternal_h
struct REM s;
# endif
uint8_t padding[0x11100]; /* multiple of 64 */
} rem;
#endif
union
{
#ifdef ___GIMInternal_h
struct GIM s;
#endif
uint8_t padding[448]; /* multiple of 64 */
} gim;
union
{
#ifdef ___APICInternal_h
struct APIC s;
#endif
uint8_t padding[128]; /* multiple of 8 */
} apic;
/* ---- begin small stuff ---- */
/** VM part. */
union
{
#ifdef ___VMInternal_h
struct VMINT s;
#endif
uint8_t padding[24]; /* multiple of 8 */
} vm;
/** CFGM part. */
union
{
#ifdef ___CFGMInternal_h
struct CFGM s;
#endif
uint8_t padding[8]; /* multiple of 8 */
} cfgm;
/** Padding for aligning the cpu array on a page boundary. */
#if defined(VBOX_WITH_REM) && defined(VBOX_WITH_RAW_MODE)
uint8_t abAlignment2[3870];
#elif defined(VBOX_WITH_REM) && !defined(VBOX_WITH_RAW_MODE)
uint8_t abAlignment2[1630];
#elif !defined(VBOX_WITH_REM) && defined(VBOX_WITH_RAW_MODE)
uint8_t abAlignment2[30];
#else
uint8_t abAlignment2[1886];
#endif
/*MYCODE*/
union{
BreakpointEntrie_t l[MAX_BREAKPOINT_ID+1];
uint8_t padding[4096*32]; /* Must be page aligned ! */
}bp;
union{
struct{
void *pFdpShm;
uint32_t u32HardwarePageTableCount;
HardwarePage_t aHardwarePageTable[64];
volatile uint8_t u8StateBitmap;
PfnEntrie_t *pPfnTableR3;
PfnEntrie_t *pPfnTableR0;
RTSPINLOCK CpuLock;
}s;
uint8_t padding[4096]; /* Must be page aligned ! */
}mystate;
/*ENDMYCODE*/
/* ---- end small stuff ---- */
/** VMCPU array for the configured number of virtual CPUs.
* Must be aligned on a page boundary for TLB hit reasons as well as
* alignment of VMCPU members. */
VMCPU aCpus[1];
} VM;
#ifdef IN_RC
RT_C_DECLS_BEGIN
/** The VM structure.
* This is imported from the VMMRCBuiltin module, i.e. it's a one of those magic
* globals which we should avoid using.
*/
extern DECLIMPORT(VM) g_VM;
RT_C_DECLS_END
#endif
/** @} */
#endif
|
f5c0de21d1bb03b2e59c71317816b74f76a7bec4
|
7664f318ed04bd0680f3d82321c18896e3ef6ad5
|
/src/overlays/actors/ovl_En_Ms/z_en_ms.c
|
e3c7c6c654d3179bf2606f30e8634fcaf8939090
|
[] |
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
| 5,966
|
c
|
z_en_ms.c
|
/*
* File: z_en_ms.c
* Overlay: ovl_En_Ms
* Description: Magic Bean Salesman
*/
#include "z_en_ms.h"
#include "assets/objects/object_ms/object_ms.h"
#define FLAGS (ACTOR_FLAG_0 | ACTOR_FLAG_3)
void EnMs_Init(Actor* thisx, PlayState* play);
void EnMs_Destroy(Actor* thisx, PlayState* play);
void EnMs_Update(Actor* thisx, PlayState* play);
void EnMs_Draw(Actor* thisx, PlayState* play);
void EnMs_SetOfferText(EnMs* this, PlayState* play);
void EnMs_Wait(EnMs* this, PlayState* play);
void EnMs_Talk(EnMs* this, PlayState* play);
void EnMs_Sell(EnMs* this, PlayState* play);
void EnMs_TalkAfterPurchase(EnMs* this, PlayState* play);
ActorInit En_Ms_InitVars = {
ACTOR_EN_MS,
ACTORCAT_NPC,
FLAGS,
OBJECT_MS,
sizeof(EnMs),
(ActorFunc)EnMs_Init,
(ActorFunc)EnMs_Destroy,
(ActorFunc)EnMs_Update,
(ActorFunc)EnMs_Draw,
};
static ColliderCylinderInitType1 sCylinderInit = {
{
COLTYPE_NONE,
AT_NONE,
AC_ON | AC_TYPE_PLAYER,
OC1_ON | OC1_TYPE_ALL,
COLSHAPE_CYLINDER,
},
{ 0x00, { 0x00000000, 0x00, 0x00 }, { 0xFFCFFFFF, 0x00, 0x00 }, 0x00, 0x01, 0x01 },
{ 22, 37, 0, { 0 } },
};
static s16 sPrices[] = {
10, 20, 30, 40, 50, 60, 70, 80, 90, 100,
};
static u16 sOfferTextIDs[] = {
0x405E, 0x405F, 0x4060, 0x4061, 0x4062, 0x4063, 0x4064, 0x4065, 0x4066, 0x4067,
};
static InitChainEntry sInitChain[] = {
ICHAIN_U8(targetMode, 2, ICHAIN_CONTINUE),
ICHAIN_F32(targetArrowOffset, 500, ICHAIN_STOP),
};
void EnMs_SetOfferText(EnMs* this, PlayState* play) {
this->actor.textId = Text_GetFaceReaction(play, 0x1B);
if (this->actor.textId == 0) {
if (BEANS_BOUGHT >= 10) {
this->actor.textId = 0x406B;
} else {
this->actor.textId = sOfferTextIDs[BEANS_BOUGHT];
}
}
}
void EnMs_Init(Actor* thisx, PlayState* play) {
EnMs* this = (EnMs*)thisx;
s32 pad;
if (LINK_AGE_IN_YEARS != YEARS_CHILD) {
Actor_Kill(&this->actor);
return;
}
Actor_ProcessInitChain(&this->actor, sInitChain);
SkelAnime_InitFlex(play, &this->skelAnime, &gBeanSalesmanSkel, &gBeanSalesmanEatingAnim, this->jointTable,
this->morphTable, 9);
Collider_InitCylinder(play, &this->collider);
Collider_SetCylinderType1(play, &this->collider, &this->actor, &sCylinderInit);
ActorShape_Init(&this->actor.shape, 0.0f, ActorShadow_DrawCircle, 35.0f);
Actor_SetScale(&this->actor, 0.015f);
this->actor.colChkInfo.mass = MASS_IMMOVABLE;
this->actor.speed = 0.0f;
this->actor.velocity.y = 0.0f;
this->actor.gravity = -1.0f;
EnMs_SetOfferText(this, play);
this->actionFunc = EnMs_Wait;
}
void EnMs_Destroy(Actor* thisx, PlayState* play) {
EnMs* this = (EnMs*)thisx;
Collider_DestroyCylinder(play, &this->collider);
}
void EnMs_Wait(EnMs* this, PlayState* play) {
s16 yawDiff;
yawDiff = this->actor.yawTowardsPlayer - this->actor.shape.rot.y;
EnMs_SetOfferText(this, play);
if (Actor_ProcessTalkRequest(&this->actor, play)) { // if talk is initiated
this->actionFunc = EnMs_Talk;
} else if ((this->actor.xzDistToPlayer < 90.0f) && (ABS(yawDiff) < 0x2000)) { // talk range
func_8002F2CC(&this->actor, play, 90.0f);
}
}
void EnMs_Talk(EnMs* this, PlayState* play) {
u8 dialogState;
dialogState = Message_GetState(&play->msgCtx);
if (dialogState != TEXT_STATE_CHOICE) {
if ((dialogState == TEXT_STATE_DONE) && Message_ShouldAdvance(play)) { // advanced final textbox
this->actionFunc = EnMs_Wait;
}
} else if (Message_ShouldAdvance(play)) {
switch (play->msgCtx.choiceIndex) {
case 0: // yes
if (gSaveContext.save.info.playerData.rupees < sPrices[BEANS_BOUGHT]) {
Message_ContinueTextbox(play, 0x4069); // not enough rupees text
return;
}
Actor_OfferGetItem(&this->actor, play, GI_MAGIC_BEAN, 90.0f, 10.0f);
this->actionFunc = EnMs_Sell;
return;
case 1: // no
Message_ContinueTextbox(play, 0x4068);
default:
return;
}
}
}
void EnMs_Sell(EnMs* this, PlayState* play) {
if (Actor_HasParent(&this->actor, play)) {
Rupees_ChangeBy(-sPrices[BEANS_BOUGHT]);
this->actor.parent = NULL;
this->actionFunc = EnMs_TalkAfterPurchase;
} else {
Actor_OfferGetItem(&this->actor, play, GI_MAGIC_BEAN, 90.0f, 10.0f);
}
}
void EnMs_TalkAfterPurchase(EnMs* this, PlayState* play) {
// if dialog state is 6 and player responded to textbox
if ((Message_GetState(&play->msgCtx)) == TEXT_STATE_DONE && Message_ShouldAdvance(play)) {
Message_ContinueTextbox(play, 0x406C);
this->actionFunc = EnMs_Talk;
}
}
void EnMs_Update(Actor* thisx, PlayState* play) {
EnMs* this = (EnMs*)thisx;
s32 pad;
this->activeTimer++;
Actor_SetFocus(&this->actor, 20.0f);
this->actor.targetArrowOffset = 500.0f;
Actor_SetScale(&this->actor, 0.015f);
SkelAnime_Update(&this->skelAnime);
this->actionFunc(this, play);
if (gSaveContext.save.entranceIndex == ENTR_LON_LON_RANCH_0 &&
gSaveContext.sceneLayer == 8) { // ride carpet if in credits
Actor_MoveXZGravity(&this->actor);
osSyncPrintf("OOOHHHHHH %f\n", this->actor.velocity.y);
Actor_UpdateBgCheckInfo(play, &this->actor, 0.0f, 0.0f, 0.0f, UPDBGCHECKINFO_FLAG_2);
}
Collider_UpdateCylinder(&this->actor, &this->collider);
CollisionCheck_SetOC(play, &play->colChkCtx, &this->collider.base);
}
void EnMs_Draw(Actor* thisx, PlayState* play) {
EnMs* this = (EnMs*)thisx;
Gfx_SetupDL_25Opa(play->state.gfxCtx);
SkelAnime_DrawFlexOpa(play, this->skelAnime.skeleton, this->skelAnime.jointTable, this->skelAnime.dListCount, NULL,
NULL, this);
}
|
14dba122844d0ad0603efabb1019f1fc1012e4b1
|
52c8ed39b32ccc7c0673278c1adea3638797c9ff
|
/src/lib/libc/path/fileext.c
|
452c120093bc73a469ed13b413be1bbcbe93cdfe
|
[
"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
| 400
|
c
|
fileext.c
|
/*
* libc/path/fileext.c
*/
#include <string.h>
#include <path.h>
#include <xboot/module.h>
const char * fileext(const char * filename)
{
const char * ret = NULL;
const char * p;
if(filename != NULL)
{
ret = p = strchr(filename, '.');
while(p != NULL)
{
p = strchr(p + 1, '.');
if(p != NULL)
ret = p;
}
if(ret != NULL)
ret++;
}
return ret;
}
EXPORT_SYMBOL(fileext);
|
ada847119012645ad6aae9471cc732b99a285d75
|
d61b532db0d3e08818338cfaac530a1ced1ffe3b
|
/util/int/core.c
|
f62b1ae2d2f0f29fdb1f971a45ded6772f4fd1dc
|
[
"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
| 1,739
|
c
|
core.c
|
/** @file
Core dumping routines
*/
#include "logging.h"
#include "global.h"
#include "warn.h"
#include "shadow.h"
#include "fra.h"
#include <stdio.h>
void core_dump(void)
{
FILE *core_file;
core_file = fopen("int.core", "wb");
if (!core_file) {
/* no point in giving a fatal error again! */
return;
}
/******** EM Machine capacity parameters ********/
fprintf(core_file, "wsize=%ld\n", wsize);
fprintf(core_file, "psize=%ld\n", psize);
/******** EM program parameters ********/
fprintf(core_file, "ML=%lu\n", ML);
fprintf(core_file, "HB=%lu\n", HB);
fprintf(core_file, "DB=%lu\n", DB);
fprintf(core_file, "NProc=%ld\n", NProc);
/******** EM machine registers ********/
fprintf(core_file, "PI=%ld\n", PI);
fprintf(core_file, "PC=%lu\n", PC);
fprintf(core_file, "HP=%lu\n", HP);
fprintf(core_file, "SP=%lu\n", SP);
fprintf(core_file, "LB=%lu\n", LB);
fprintf(core_file, "AB=%lu\n", AB);
fprintf(core_file, "ES=%ld\n", ES);
fprintf(core_file, "ES_def=%d\n", ES_def);
fprintf(core_file, "OnTrap=%d\n", OnTrap);
fprintf(core_file, "IgnMask=%ld\n", IgnMask);
fprintf(core_file, "TrapPI=%ld\n", TrapPI);
fprintf(core_file, "FRASize=%ld\n", FRASize);
fprintf(core_file, "FRA_def=%d\n", FRA_def);
fprintf(core_file, "HL=%lu\n", HL);
fprintf(core_file, "SL=%lu\n", SL);
/******** The EM machine memory ********/
fwrite(text, 1, (int)(DB), core_file);
fwrite(data, 1, (int)(HL), core_file);
fwrite(stack, 1, (int)(ML+1-SL), core_file);
fwrite(FRA, 1, (int)(FRALimit), core_file);
#ifdef LOGGING
fwrite(FRA_sh, 1, (int)(FRALimit), core_file);
fwrite(data_sh, 1, (int)(HL), core_file);
fwrite(stack_sh, 1, (int)(ML+1-SL), core_file);
#endif /* LOGGING */
fclose(core_file);
core_file = 0;
}
|
f65e9ba148420b4b7183f02b515cb02980785a0e
|
d2d479bfdf2cef5436e4cd468a74f844fa8ecae5
|
/config.h
|
22ec3084c2f0f9903abe47c0c2cef8a516727adc
|
[
"BSD-2-Clause"
] |
permissive
|
n0la/rcon
|
4d2f4c7b729392d9bfd299cbe9c92726b18d8eb4
|
e7e2d9bb21930d7e2b00f9b35effe1eee1ec5585
|
refs/heads/master
| 2022-07-16T00:55:12.637356
| 2022-06-27T06:54:51
| 2022-06-27T06:54:51
| 68,371,211
| 128
| 30
|
BSD-2-Clause
| 2023-07-07T20:42:37
| 2016-09-16T10:30:01
|
C
|
UTF-8
|
C
| false
| false
| 258
|
h
|
config.h
|
#ifndef RCON_CONFIG_H
#define RCON_CONFIG_H
#include <stdbool.h>
void config_free(void);
int config_load(char const *file);
int config_host_data(char const *name, char **hostname,
char **port, char **passwd, bool *minecraft);
#endif
|
e561d5103beb4dd6c39005b433592e22b80264d1
|
0744dcc5394cebf57ebcba343747af6871b67017
|
/external/audiocodec/aacdec/ms_synt.c
|
aae078fcbc57b5046f01146d734647ad5919ea06
|
[
"Apache-2.0",
"MIT"
] |
permissive
|
Samsung/TizenRT
|
96abf62f1853f61fcf91ff14671a5e0c6ca48fdb
|
1a5c2e00a4b1bbf4c505bbf5cc6a8259e926f686
|
refs/heads/master
| 2023-08-31T08:59:33.327998
| 2023-08-08T06:09:20
| 2023-08-31T04:38:20
| 82,517,252
| 590
| 719
|
Apache-2.0
| 2023-09-14T06:54:49
| 2017-02-20T04:38:30
|
C
|
UTF-8
|
C
| false
| false
| 14,862
|
c
|
ms_synt.c
|
/******************************************************************
*
* Copyright 2018 Samsung Electronics All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************/
/* ------------------------------------------------------------------
* Copyright (C) 1998-2009 PacketVideo
*
* 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.
* -------------------------------------------------------------------
*/
/*
Pathname: ms_synt.c
------------------------------------------------------------------------------
REVISION HISTORY
Description: Modified from original shareware code
Description: Cleaned up a bit, not finished.
Description:
Copied in code from pns_intensity_right.c, which has the same structure as
this file. Also, merged in code from ms_map_mask.c
Description:
(1) Various optimizations (eliminated extra variables by making use of a
single temporary register throughout the code, etc.)
(2) Wrote pseudocode, pasted in correct function template, etc.
Description: Unrolled loops to get speed up code
------------------------------------------------------------------------------
INPUT AND OUTPUT DEFINITIONS
Inputs:
wins_in_group = Number of windows in the current group.
[const Int]
coef_per_win = Number of coefficients per window.
[const Int]
num_bands = Number of scalefactor bands.
[const Int]
band_length = Number of coefficients per scalefactor band.
[const Int]
pFirst_Window_CoefsL = Array containing the spectral coefficients for
the left channel.
[Int32 *, length LN]
pFirst_Window_CoefsR = Array containing the spectral coefficients for
the right channel.
[Int32 *, length LN]
q_formatLeft = Array containing the q-format used to encode each
scalefactor band's data on the left channel.
[Int *, length MAXBANDS]
q_formatRight = Array containing the q-format used to encode each
scalefactor band's data on the right channel.
[Int *, length MAXBANDS]
Local Stores/Buffers/Pointers Needed:
None
Global Stores/Buffers/Pointers Needed:
None
Outputs:
None
Pointers and Buffers Modified:
pFirst_Window_CoefsL The coefficients in the group will be modified per the
formula for M/S stereo on each scalefactor band where
M/S stereo is active.
pFirst_Window_CoefsR The coefficients in the group will be modified per the
formula for M/S stereo on each scalefactor band where
M/S stereo is active.
q_formatLeft The q_format may be modified on scalefactor bands
where M/S stereo is active.
q_formatRight The q_format may be modified on scalefactor bands
where M/S stereo is active.
Local Stores Modified:
Global Stores Modified:
------------------------------------------------------------------------------
FUNCTION DESCRIPTION
This module applies the formula for M/S coding to one grouped scalefactor
band. The ISO code has a similar function which applies M/S coding to an
entire frame.
It is the calling function's responsibility to check the map_mask array, which
is filled by the function getmask. If a scalefactor band is identified as
using M/S stereo, the coefficients in that array are calculated using
the following formula...
TempLeft = LeftCoefficient;
LeftCoefficient = LeftCoefficient + RightCoefficient;
RightCoefficient = TempLeft - RightCoefficient;
This function should be inlined if the compiler supports C99 inlining,
as this short function is only called by sfb_tools_ms().
Therefore, inlining will not increase the code size.
------------------------------------------------------------------------------
REQUIREMENTS
------------------------------------------------------------------------------
REFERENCES
(1) ISO/IEC 14496-3:1999(E)
Part 3
Subpart 4.6.7.1 M/S stereo
Subpart 4.6.2 ScaleFactors
(2) MPEG-2 NBC Audio Decoder
"This software module was originally developed by AT&T, Dolby
Laboratories, Fraunhofer Gesellschaft IIS in the course of development
of the MPEG-2 NBC/MPEG-4 Audio standard ISO/IEC 13818-7, 14496-1,2 and
3. This software module is an implementation of a part of one or more
MPEG-2 NBC/MPEG-4 Audio tools as specified by the MPEG-2 NBC/MPEG-4
Audio standard. ISO/IEC gives users of the MPEG-2 NBC/MPEG-4 Audio
standards free license to this software module or modifications thereof
for use in hardware or software products claiming conformance to the
MPEG-2 NBC/MPEG-4 Audio standards. Those intending to use this software
module in hardware or software products are advised that this use may
infringe existing patents. The original developer of this software
module and his/her company, the subsequent editors and their companies,
and ISO/IEC have no liability for use of this software module or
modifications thereof in an implementation. Copyright is not released
for non MPEG-2 NBC/MPEG-4 Audio conforming products.The original
developer retains full right to use the code for his/her own purpose,
assign or donate the code to a third party and to inhibit third party
from using the code for non MPEG-2 NBC/MPEG-4 Audio conforming products.
This copyright notice must be included in all copies or derivative
works."
Copyright(c)1996.
------------------------------------------------------------------------------
PSEUDO-CODE
start_indx = 0;
pCoefR = coefLeft;
pCoefL = coefRight;
FOR (win_indx = wins_in_group; win_indx > 0; win_indx--)
tempInt = q_formatLeft[start_indx] - q_formatRight[start_indx];
IF (tempInt > 0)
THEN
shift_left_chan = 1 + tempInt;
shift_right_chan = 1;
q_formatLeft[start_indx] = (q_formatRight[start_indx] - 1);
q_formatRight[start_indx] = (q_formatRight[start_indx] - 1);
ELSE
shift_left_chan = 1;
shift_right_chan = 1 - tempInt;
q_formatRight[start_indx] = (q_formatLeft[start_indx] - 1);
q_formatLeft[start_indx] = (q_formatLeft[start_indx] - 1);
ENDIF
FOR (tempInt = band_length; tempInt > 0; tempInt--)
temp_left = *(pCoefL) >> shift_left_chan;
temp_right = *(pCoefR) >> shift_right_chan;
*(pCoefL++) = temp_left + temp_right;
*(pCoefR++) = temp_left - temp_right;
ENDFOR
tempInt = (coef_per_win - band_length);
pCoefR = pCoefR + tempInt;
pCoefL = pCoefL + tempInt;
start_indx = start_indx + num_bands;
ENDFOR
------------------------------------------------------------------------------
RESOURCES USED
When the code is written for a specific target processor the
resources used should be documented below.
STACK USAGE: [stack count for this module] + [variable to represent
stack usage for each subroutine called]
where: [stack usage variable] = stack usage for [subroutine
name] (see [filename].ext)
DATA MEMORY USED: x words
PROGRAM MEMORY USED: x words
CLOCK CYCLES: [cycle count equation for this module] + [variable
used to represent cycle count for each subroutine
called]
where: [cycle count variable] = cycle count for [subroutine
name] (see [filename].ext)
------------------------------------------------------------------------------
*/
/*----------------------------------------------------------------------------
; INCLUDES
----------------------------------------------------------------------------*/
#include "pv_audio_type_defs.h"
#include "ms_synt.h"
#include "fxp_mul32.h"
#include "aac_mem_funcs.h"
#include "window_block_fxp.h"
/*----------------------------------------------------------------------------
; MACROS
; Define module specific macros here
----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------
; DEFINES
; Include all pre-processor statements here. Include conditional
; compile variables also.
----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------
; LOCAL FUNCTION DEFINITIONS
; Function Prototype declaration
----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------
; LOCAL STORE/BUFFER/POINTER DEFINITIONS
; Variable declaration - defined here and used outside this module
----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------
; EXTERNAL FUNCTION REFERENCES
; Declare functions defined elsewhere and referenced in this module
----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------
; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
; Declare variables used in this module but defined elsewhere
----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------
; FUNCTION CODE
----------------------------------------------------------------------------*/
void ms_synt(
const Int wins_in_group,
const Int coef_per_win,
const Int num_bands,
const Int band_length,
Int32 coefLeft[],
Int32 coefRight[],
Int q_formatLeft[],
Int q_formatRight[])
{
Int32 *pCoefL = coefLeft;
Int32 *pCoefR = coefRight;
Int start_indx = 0;
if (band_length < 0 || band_length > LONG_WINDOW)
{
return; /* avoid any processing on error condition */
}
Int nextWinPtrUpdate = (coef_per_win - band_length);
for (Int win_indx = wins_in_group; win_indx > 0; win_indx--)
{
if (q_formatRight[start_indx] < 31)
{
Int tempInt = q_formatLeft[start_indx] - q_formatRight[start_indx];
/* Normalize the left and right channel to the same q-format */
if (tempInt > 0)
{
/*
* shift_left_chan and shift_right_chan each have an offset
* of 1. Even if the left and right channel share the same
* q-format, we must shift each by 1 to guard against
* overflow.
*/
Int shift_left_chan = 1 + tempInt;
/*
* Following code line is equivalent to...
* q_formatLeft = q_formatRight - 1;
* q_formatRight = q_formatRight - 1;
*/
q_formatLeft[start_indx] = --(q_formatRight[start_indx]);
/*
* band_length is always an even number (check tables in pg.66 IS0 14496-3)
*/
Int32 temp_left = *(pCoefL) >> shift_left_chan;
Int32 temp_right = *(pCoefR) >> 1;
for (Int i = band_length; i != 0; i--)
{
*(pCoefL++) = temp_left + temp_right;
*(pCoefR++) = temp_left - temp_right;
temp_left = *(pCoefL) >> shift_left_chan;
temp_right = *(pCoefR) >> 1;
}
}
else
{
/*
* shift_left_chan and shift_right_chan each have an offset
* of 1. Even if the left and right channel share the same
* q-format, we must shift each by 1 to guard against
* overflow.
*/
Int shift_right_chan = 1 - tempInt;
/*
* Following code line is equivalent to...
* q_formatRight = q_formatLeft - 1;
* q_formatLeft = q_formatLeft - 1;
*/
q_formatRight[start_indx] = --(q_formatLeft[start_indx]);
/*
* band_length is always an even number (check tables in pg.66 IS0 14496-3)
*/
Int32 temp_left = *(pCoefL) >> 1;
Int32 temp_right = *(pCoefR) >> shift_right_chan;
for (Int i = band_length; i != 0; i--)
{
*(pCoefL++) = temp_left + temp_right;
*(pCoefR++) = temp_left - temp_right;
temp_left = *(pCoefL) >> 1;
temp_right = *(pCoefR) >> shift_right_chan;
}
}
}
else
{
/*
* Nothing on right channel, just copy left into right
*/
q_formatRight[start_indx] = (q_formatLeft[start_indx]);
pv_memcpy(pCoefR, pCoefL, band_length*sizeof(*pCoefR));
pCoefR += band_length;
pCoefL += band_length;
}
/*
* Increment the window pointers so they point
* to the next window in the group
*/
pCoefL += nextWinPtrUpdate;
pCoefR += nextWinPtrUpdate;
start_indx += num_bands;
} /* for (win_indx) */
return;
} /* MS_synt */
|
34bd2eb7ccc424b5563f8d2efbfd3af49f99605d
|
8886361e436c7598419f444a52ae587bf94b1fbe
|
/plugins/codecs/zfp/include/zfp/version.h
|
87a1d221024f377ad853582367b7e4bca7aa1a2c
|
[
"BSD-3-Clause"
] |
permissive
|
Blosc/c-blosc2
|
d4b69bf735e1440ea1d7e147f434b488f975c8d4
|
6bbade9e13bd166ea0189f8c3b6253c9bbe9bb54
|
refs/heads/main
| 2023-08-31T15:47:35.224132
| 2023-08-31T03:01:37
| 2023-08-31T06:01:40
| 40,355,993
| 358
| 85
|
NOASSERTION
| 2023-09-12T09:26:36
| 2015-08-07T10:51:35
|
C
|
UTF-8
|
C
| false
| false
| 847
|
h
|
version.h
|
#ifndef ZFP_VERSION_H
#define ZFP_VERSION_H
/* stringification */
#define _zfp_str_(x) # x
#define _zfp_str(x) _zfp_str_(x)
/* library version information */
#define ZFP_VERSION_MAJOR 0 /* library major version number */
#define ZFP_VERSION_MINOR 5 /* library minor version number */
#define ZFP_VERSION_PATCH 5 /* library patch version number */
#define ZFP_VERSION_RELEASE ZFP_VERSION_PATCH
/* codec version number (see also zfp_codec_version) */
#define ZFP_CODEC 5
/* library version number (see also zfp_library_version) */
#define ZFP_VERSION \
((ZFP_VERSION_MAJOR << 8) + \
(ZFP_VERSION_MINOR << 4) + \
(ZFP_VERSION_PATCH << 0))
/* library version string (see also zfp_version_string) */
#define ZFP_VERSION_STRING \
_zfp_str(ZFP_VERSION_MAJOR) "." \
_zfp_str(ZFP_VERSION_MINOR) "." \
_zfp_str(ZFP_VERSION_PATCH)
#endif
|
7a1740917a2fddf17ed6b36f3718f2b59946c6e1
|
99bdb3251fecee538e0630f15f6574054dfc1468
|
/components/drivers/cputime/cputime_cortexm.c
|
100910a9f9fa5be80dc624a8a1e79b6699b79059
|
[
"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
| 1,584
|
c
|
cputime_cortexm.c
|
/*
* Copyright (c) 2006-2023, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2017-12-23 Bernard first version
* 2022-06-14 Meco Man suuport pref_counter
*/
#include <rthw.h>
#include <rtdevice.h>
#include <rtthread.h>
#include <board.h>
#ifdef PKG_USING_PERF_COUNTER
#include <perf_counter.h>
#endif
/* Use Cycle counter of Data Watchpoint and Trace Register for CPU time */
static uint64_t cortexm_cputime_getres(void)
{
uint64_t ret = 1000UL * 1000 * 1000;
ret = (ret * (1000UL * 1000)) / SystemCoreClock;
return ret;
}
static uint64_t cortexm_cputime_gettime(void)
{
#ifdef PKG_USING_PERF_COUNTER
return get_system_ticks();
#else
return DWT->CYCCNT;
#endif
}
const static struct rt_clock_cputime_ops _cortexm_ops =
{
cortexm_cputime_getres,
cortexm_cputime_gettime
};
int cortexm_cputime_init(void)
{
#ifdef PKG_USING_PERF_COUNTER
clock_cpu_setops(&_cortexm_ops);
#else
/* check support bit */
if ((DWT->CTRL & (1UL << DWT_CTRL_NOCYCCNT_Pos)) == 0)
{
/* enable trace*/
CoreDebug->DEMCR |= (1UL << CoreDebug_DEMCR_TRCENA_Pos);
/* whether cycle counter not enabled */
if ((DWT->CTRL & (1UL << DWT_CTRL_CYCCNTENA_Pos)) == 0)
{
/* enable cycle counter */
DWT->CTRL |= (1UL << DWT_CTRL_CYCCNTENA_Pos);
}
clock_cpu_setops(&_cortexm_ops);
}
#endif /* PKG_USING_PERF_COUNTER */
return 0;
}
INIT_BOARD_EXPORT(cortexm_cputime_init);
|
6afdd48f26eb675f4846221e5ccbec095c9ec9b6
|
308f5596f1c7d382520cfce13ceaa5dff6f4f783
|
/hphp/hack/src/utils/cgroup/cgroupWatcher.c
|
00e9d7bdccecbf00491c3267bc633f5c03711947
|
[
"PHP-3.01",
"Zend-2.0",
"MIT"
] |
permissive
|
facebook/hhvm
|
7e200a309a1cad5304621b0516f781c689d07a13
|
d8203129dc7e7bf8639a2b99db596baad3d56b46
|
refs/heads/master
| 2023-09-04T04:44:12.892628
| 2023-09-04T00:43:05
| 2023-09-04T00:43:05
| 455,600
| 10,335
| 2,326
|
NOASSERTION
| 2023-09-14T21:24:04
| 2010-01-02T01:17:06
|
C++
|
UTF-8
|
C
| false
| false
| 6,236
|
c
|
cgroupWatcher.c
|
// (c) Meta Platforms, Inc. and affiliates.
//
// This source code is licensed under the MIT license found in the
// LICENSE file in the "hack" directory of this source tree.
#define CAML_NAME_SPACE
#include <caml/mlvalues.h>
#include <caml/memory.h>
#include <caml/alloc.h>
#include <stdio.h>
#include <string.h>
#include <pthread.h>
#include <time.h>
#include <stdint.h>
#include <inttypes.h>
// Highest expected peak cgroup memory. We only write to scuba as many
// entries as there actually are, so it's fine for this to be large.
// If it were too small then we'd "clip", i.e, anything bigger than
// GB_MAX would be ascribed to GB_MAX.
#define GB_MAX 1024
// We'll have a background thread which reads cgroup this frequently.
// I don't know if there'll be adverse perf impact of having it more frequent.
// If it's too infrequent, then we'll fail to capture short-lived peaks.
#define INTERVAL_MS 20
// This lock protects all the following static data
pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
// Accumulates how many seconds have been spent at each total cgroup size.
// This is reset by [cgroup_watcher_start], and read by [cgroup_watcher_get].
// The final entry in the array accumulates time spent at GB_MAX or higher.
static double seconds_at_gb[GB_MAX];
// Records the high-water-mark
static int hwm_kb;
// How many cgroup readings have we taken since the last reset
static int num_readings;
// These are the cgroup memory.current and memory.swap.current file we'll read
// for the current value. We'll add them together. The paths
// include the leading "/sys/fs/group/" and the trailing "/memory.current"
static char *path1 = NULL;
static char *path2 = NULL;
// The seconds_at_gb array will be relative to this, e.g. a reading of Xgb
// would increment the tally kept at seconds_at_gb[X-subtract_kb_for_array/1GiB].
static int subtract_kb_for_array;
// 1 or 0 for whether the thread has been launched
static int thread_is_running = 0;
// Reads the current unsigned long long from the contents of 'path1+path2', and returns it /1024.
// If it fails to open the file, -1. If it fails to parse the contents, -2.
static int get_mem_kb(void) {
FILE *file1 = fopen(path1, "r");
FILE *file2 = fopen(path2, "r");
if (file1 == NULL || file2 == NULL) {
return -1;
}
unsigned long long mem1, mem2;
int i1 = fscanf(file1, "%llu", &mem1);
int i2 = fscanf(file2, "%llu", &mem2);
fclose(file1);
fclose(file2);
return (i1 == 1 && i2 == 1) ? (mem1 + mem2) / 1024 : -2;
}
#define UNUSED(x) ((void)(x))
// This is the background thread code. Every INTERVAL_MS, it reads the cgroup
// memory.current from [path], and updates the counters [hwm_kb, seconds_at_gb, num_readings].
// If there are any errors, then the counters simply won't be updated.
static void *threadfunc(void *arg) {
UNUSED(arg);
struct timespec tprev, t;
clock_gettime(CLOCK_MONOTONIC_RAW, &tprev);
while (1) {
if (pthread_mutex_lock(&lock) == 0) {
clock_gettime(CLOCK_MONOTONIC_RAW, &t);
const double seconds = (double)( t.tv_sec - tprev.tv_sec ) + (((double)(t.tv_nsec - tprev.tv_nsec)) / 1000000000.0);
tprev = t;
int kb = get_mem_kb();
int kb0 = kb;
if (kb >= 0) {
hwm_kb = kb > hwm_kb ? kb : hwm_kb;
kb -= subtract_kb_for_array;
if (kb < 0) {
// Underflow, because the value dropped below what it was initially.
// We'll "clip" it, tallying it under seconds_at_gb[0]
kb = 0;
}
int gb = kb / 1024 / 1024;
if (gb >= GB_MAX) {
// Overflow, because the value was higher than we ever dreamt.
// We'll "clip" it, tallying it under seconds_at_gb[GB_MAX-1]
gb = GB_MAX-1;
}
seconds_at_gb[gb] += seconds;
num_readings += 1;
}
pthread_mutex_unlock(&lock);
}
nanosleep((const struct timespec[]){{0, INTERVAL_MS * 1000 * 1000}}, NULL);
}
return NULL; // to silence -Werror=return-type "no return statement in function returning non-void"
}
// This will (1) reset the counters and update [path1],[path2] so threadfunc
// will pick up the new value next tick, (2) starts the thread if it's not already running.
// Any failures aren't reported here; they're manifest in [cgroup_watcher_get]
CAMLprim value cgroup_watcher_start(value path1_, value path2_, value subtract_kb_for_array_) {
CAMLparam3(path1_, path2_, subtract_kb_for_array_);
const char *cpath1 = String_val(path1_);
const char *cpath2 = String_val(path2_);
int csubtract_kb_for_array = Int_val(subtract_kb_for_array_);
int rc;
if (pthread_mutex_lock(&lock) == 0) {
if (path1 != NULL) free(path1);
path1 = malloc(strlen(cpath1) + 1);
strcpy(path1, cpath1);
if (path2 != NULL) free(path2);
path2 = malloc(strlen(cpath2) + 1);
strcpy(path2, cpath2);
subtract_kb_for_array = csubtract_kb_for_array;
hwm_kb = 0;
num_readings = 0;
for (int i=0; i<GB_MAX; i++) {
seconds_at_gb[i] = 0.0;
}
if (thread_is_running == 0) {
pthread_t thread;
pthread_create(&thread, NULL, threadfunc, NULL);
thread_is_running = 1;
}
pthread_mutex_unlock(&lock);
}
CAMLreturn(Val_unit);
}
// Fetch the current total so far of hwm/seconds.
// Returns (hwm_kb, num_readings, seconds_at_gb[||]).
// If there had been failures along the way, e.g. the path was invalid
// or cgroups don't exist, then it will return (0,0,[||]).
CAMLprim value cgroup_watcher_get(void) {
CAMLparam0();
CAMLlocal2(list, result);
// We'll copy values out of the mutex, before doing any ocaml allocation
double ss[GB_MAX];
int hwm=0;
int readings=0;
int max=0;
if (pthread_mutex_lock(&lock) == 0) {
memcpy(ss, seconds_at_gb, GB_MAX*sizeof(ss[0]));
hwm = hwm_kb;
readings = num_readings;
pthread_mutex_unlock(&lock);
for (int i=0; i<GB_MAX; i++) {
max = ss[i] > 0.0 ? i+1 : max;
}
}
list = caml_alloc(max, Double_array_tag);
for (int i=0; i<max; i++) {
Store_double_field(list, i, ss[i]);
}
result = caml_alloc_tuple(3);
Store_field(result, 0, Val_int(hwm));
Store_field(result, 1, Val_int(readings));
Store_field(result, 2, list);
CAMLreturn(result);
}
|
fe96c3233809dae2f3d4a458abf9f58999dd13e1
|
909095842af0bbf2e769aff361b5af344abc7433
|
/engine/lib/openal/FreeBSD/al/alctypes.h
|
72ff496893f29ff6923ed79b61828ee188d0ec16
|
[
"MIT",
"LGPL-2.0-or-later"
] |
permissive
|
TorqueGameEngines/Torque2D
|
316105e8b91cebf8660ff43871440e1c4d0b1c5e
|
2c555d6dd0172a05ddb6a14f014d22f335b4ccad
|
refs/heads/master
| 2023-09-01T02:22:53.663431
| 2023-05-02T20:45:37
| 2023-05-02T20:45:37
| 268,352,960
| 1,001
| 117
|
MIT
| 2023-05-02T20:19:19
| 2020-05-31T19:51:55
|
C
|
UTF-8
|
C
| false
| false
| 3,376
|
h
|
alctypes.h
|
#ifndef _ALCTYPES_H_
#define _ALCTYPES_H_
/**
* OpenAL cross platform audio library
* Copyright (C) 1999-2000 by authors.
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
* Or go to http://www.gnu.org/copyleft/lgpl.html
*/
#ifdef __cplusplus
extern "C" {
#endif
/** ALC boolean type. */
typedef char ALCboolean;
/** ALC 8bit signed byte. */
typedef char ALCbyte;
/** ALC 8bit unsigned byte. */
typedef unsigned char ALCubyte;
/** ALC 16bit signed short integer type. */
typedef short ALCshort;
/** ALC 16bit unsigned short integer type. */
typedef unsigned short ALCushort;
/** ALC 32bit unsigned integer type. */
typedef unsigned ALCuint;
/** ALC 32bit signed integer type. */
typedef int ALCint;
/** ALC 32bit floating point type. */
typedef float ALCfloat;
/** ALC 64bit double point type. */
typedef double ALCdouble;
/** ALC 32bit type. */
typedef unsigned int ALCsizei;
/** ALC void type */
typedef void ALCvoid;
/** ALC enumerations. */
typedef int ALCenum;
typedef ALCvoid ALCdevice;
typedef ALCvoid ALCcontext;
/* Bad value. */
#define ALC_INVALID (-1)
/* Boolean False. */
#define ALC_FALSE 0
/* Boolean True. */
#define ALC_TRUE 1
/** Errors: No Error. */
#define ALC_NO_ERROR ALC_FALSE
#define ALC_MAJOR_VERSION 0x1000
#define ALC_MINOR_VERSION 0x1001
#define ALC_ATTRIBUTES_SIZE 0x1002
#define ALC_ALL_ATTRIBUTES 0x1003
#define ALC_DEFAULT_DEVICE_SPECIFIER 0x1004
#define ALC_DEVICE_SPECIFIER 0x1005
#define ALC_EXTENSIONS 0x1006
#define ALC_FREQUENCY 0x1007
#define ALC_REFRESH 0x1008
#define ALC_SYNC 0x1009
/**
* The device argument does not name a valid dvice.
*/
#define ALC_INVALID_DEVICE 0xA001
/**
* The context argument does not name a valid context.
*/
#define ALC_INVALID_CONTEXT 0xA002
/**
* A function was called at inappropriate time,
* or in an inappropriate way, causing an illegal state.
* This can be an incompatible ALenum, object ID,
* and/or function.
*/
#define ALC_INVALID_ENUM 0xA003
/**
* Illegal value passed as an argument to an AL call.
* Applies to parameter values, but not to enumerations.
*/
#define ALC_INVALID_VALUE 0xA004
/**
* A function could not be completed,
* because there is not enough memory available.
*/
#define ALC_OUT_OF_MEMORY 0xA005
#ifdef __cplusplus
}
#endif
#endif
|
9c77d0e32f510110ccdaa2a27c746e15dd1a6112
|
88ae8695987ada722184307301e221e1ba3cc2fa
|
/third_party/ffmpeg/libavcodec/startcode.c
|
d84f32652188435263ce5c04d7507818564966a4
|
[
"LGPL-2.1-only",
"LGPL-3.0-only",
"LGPL-2.0-or-later",
"GPL-1.0-or-later",
"GPL-2.0-only",
"LGPL-2.1-or-later",
"GPL-3.0-or-later",
"LGPL-3.0-or-later",
"IJG",
"LicenseRef-scancode-other-permissive",
"MIT",
"GPL-2.0-or-later",
"Apache-2.0",
"GPL-3.0-only",
"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
| 1,814
|
c
|
startcode.c
|
/*
* Copyright (c) 2003-2010 Michael Niedermayer <michaelni@gmx.at>
*
* 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
* Accelerated start code search function for start codes common to
* MPEG-1/2/4 video, VC-1, H.264/5
* @author Michael Niedermayer <michaelni@gmx.at>
*/
#include "libavutil/intreadwrite.h"
#include "startcode.h"
#include "config.h"
int ff_startcode_find_candidate_c(const uint8_t *buf, int size)
{
int i = 0;
#if HAVE_FAST_UNALIGNED
/* we check i < size instead of i + 3 / 7 because it is
* simpler and there must be AV_INPUT_BUFFER_PADDING_SIZE
* bytes at the end.
*/
#if HAVE_FAST_64BIT
while (i < size &&
!((~AV_RN64(buf + i) &
(AV_RN64(buf + i) - 0x0101010101010101ULL)) &
0x8080808080808080ULL))
i += 8;
#else
while (i < size &&
!((~AV_RN32(buf + i) &
(AV_RN32(buf + i) - 0x01010101U)) &
0x80808080U))
i += 4;
#endif
#endif
for (; i < size; i++)
if (!buf[i])
break;
return i;
}
|
89392ad13350722fc68a763686fefe980b346b45
|
70ffcb065027032a399f44b9ec91e7b61d73583d
|
/tests/fuzz/fuzz-close_tx.c
|
58f4a67203bf7d7e4b59da6b98de2ea0996185b8
|
[
"MIT"
] |
permissive
|
ElementsProject/lightning
|
4e260841b2ebad8c772a5ff91ef1ebbc3fe1ad71
|
990096f904e26386527a4eddd8d3262464bacabd
|
refs/heads/master
| 2023-09-01T07:11:34.794039
| 2023-08-31T09:55:14
| 2023-08-31T22:02:14
| 37,350,472
| 2,812
| 961
|
NOASSERTION
| 2023-09-14T19:33:22
| 2015-06-13T00:04:22
|
C
|
UTF-8
|
C
| false
| false
| 2,635
|
c
|
fuzz-close_tx.c
|
#include "config.h"
#include <assert.h>
#include <bitcoin/chainparams.h>
#include <bitcoin/pubkey.h>
#include <bitcoin/script.h>
#include <common/close_tx.h>
#include <common/setup.h>
#include <common/utils.h>
#include <tests/fuzz/libfuzz.h>
#include <wire/wire.h>
void init(int *argc, char ***argv)
{
common_setup("fuzzer");
chainparams = chainparams_for_network("bitcoin");
}
void run(const uint8_t *data, size_t size)
{
const uint8_t *wire_ptr;
size_t wire_max, min_size, script_size;
struct bitcoin_outpoint outpoint;
struct amount_sat funding, to_us, to_them, dust_limit, max;
const uint8_t *our_script, *their_script, *funding_script;
struct pubkey *pk1, *pk2;
/* create_close_tx wants:
* - 3 scripts: 3 * N bytes
* - 1 txid: 32 bytes
* - 1 u32: 4 bytes
* - 4 amount_sat: 4 * 8 bytes
*
* Since both output scripts size are not restricted, we also try
* to vary their length.
* Therefore, we allocate the entire remaining bytes to scripts.
*/
min_size = 8 * 3 + 4 + 32;
if (size < min_size + 2)
return;
script_size = (size - min_size) / 2;
wire_ptr = data;
wire_max = 8;
to_us = fromwire_amount_sat(&wire_ptr, &wire_max);
assert(wire_ptr);
wire_max = 8;
to_them = fromwire_amount_sat(&wire_ptr, &wire_max);
assert(wire_ptr);
wire_max = 8;
dust_limit = fromwire_amount_sat(&wire_ptr, &wire_max);
/* The funding must be > to_us + to_them (TODO: we could simulate some fees) .. */
if (!(amount_sat_add(&funding, to_us, to_them)))
return;
/* .. And < max_btc as we assert it's not nonsensical! */
max = AMOUNT_SAT((u32)WALLY_SATOSHI_PER_BTC * WALLY_BTC_MAX);
if (amount_sat_greater(funding, max)) {
funding = max;
to_us = amount_sat_div(max, 2);
to_them = amount_sat_div(max, 2);
}
wire_max = 36;
fromwire_bitcoin_outpoint(&wire_ptr, &wire_max, &outpoint);
our_script = tal_dup_arr(tmpctx, const uint8_t, wire_ptr, script_size, 0);
their_script = tal_dup_arr(tmpctx, const uint8_t, wire_ptr + script_size,
script_size, 0);
/* We assert it's valid, so we can't throw garbage at the funding script.. */
pk1 = tal(tmpctx, struct pubkey);
pk2 = tal(tmpctx, struct pubkey);
assert(pubkey_from_hexstr("034fede2c619f647fe7c01d40ae22e4c285291ca2ffb47937bbfb7d6e8285a081f",
2 * PUBKEY_CMPR_LEN, pk1));
assert(pubkey_from_hexstr("028dfe31019dd61fa04c76ad065410e5d063ac2949c04c14b214c1b363e517452f",
2 * PUBKEY_CMPR_LEN, pk2));
funding_script = bitcoin_redeem_2of2(tmpctx, pk1, pk2);
create_close_tx(tmpctx, chainparams, NULL, NULL, our_script,
their_script, funding_script, &outpoint,
funding, to_us, to_them, dust_limit);
clean_tmpctx();
}
|
e9fc843e7d2cd694f74998f75d29c9cdd9f273eb
|
ca4c4631f3d47a90b8415bbe70dbc7cae18c071e
|
/src/node_kernels/TKERodiNodeKernel.C
|
55f9f8cfdc8c93ab459acd08b93c01b2a6d8a223
|
[
"BSD-3-Clause",
"BSD-2-Clause"
] |
permissive
|
Exawind/nalu-wind
|
5765078c445d379ea952d2b25a01f5ff490837a6
|
722cd7757a412c9306645963808047824c312a17
|
refs/heads/master
| 2023-08-16T17:44:54.744168
| 2023-08-15T18:05:23
| 2023-08-15T18:05:23
| 132,016,365
| 111
| 87
|
NOASSERTION
| 2023-09-14T04:02:07
| 2018-05-03T15:39:32
|
C
|
UTF-8
|
C
| false
| false
| 3,425
|
c
|
TKERodiNodeKernel.C
|
// Copyright 2017 National Technology & Engineering Solutions of Sandia, LLC
// (NTESS), National Renewable Energy Laboratory, University of Texas Austin,
// Northwest Research Associates. Under the terms of Contract DE-NA0003525
// with NTESS, the U.S. Government retains certain rights in this software.
//
// This software is released under the BSD 3-clause license. See LICENSE file
// for more details.
//
#include "node_kernels/TKERodiNodeKernel.h"
#include "node_kernels/NodeKernel.h"
#include "Realm.h"
#include "SolutionOptions.h"
// stk_mesh/base/fem
#include <stk_mesh/base/MetaData.hpp>
#include "utils/StkHelpers.h"
#include <stk_mesh/base/Field.hpp>
#include <stk_mesh/base/Types.hpp>
namespace sierra {
namespace nalu {
//==========================================================================
// Class Definition
//==========================================================================
// TKERodiNodeKernel Pb = beta*mu^t/Pr^t gi/Cp dh/dxi
//==========================================================================
//--------------------------------------------------------------------------
//-------- constructor -----------------------------------------------------
//--------------------------------------------------------------------------
TKERodiNodeKernel::TKERodiNodeKernel(
const stk::mesh::MetaData& meta, const SolutionOptions& solnOpts)
: NGPNodeKernel<TKERodiNodeKernel>(),
dhdxID_(get_field_ordinal(meta, "dhdx")),
specificHeatID_(get_field_ordinal(meta, "specific_heat")),
tviscID_(get_field_ordinal(meta, "turbulent_viscosity")),
dualNodalVolumeID_(get_field_ordinal(meta, "dual_nodal_volume")),
turbPr_(0), // Set in setup()
beta_(solnOpts.thermalExpansionCoeff_),
nDim_(meta.spatial_dimension())
{
const std::vector<double>& solnOptsGravity =
solnOpts.get_gravity_vector(nDim_);
for (int i = 0; i < nDim_; i++)
gravity_[i] = solnOptsGravity[i];
}
//--------------------------------------------------------------------------
//-------- setup -----------------------------------------------------------
//--------------------------------------------------------------------------
void
TKERodiNodeKernel::setup(Realm& realm)
{
const auto& fieldMgr = realm.ngp_field_manager();
dhdx_ = fieldMgr.get_field<double>(dhdxID_);
specificHeat_ = fieldMgr.get_field<double>(specificHeatID_);
tvisc_ = fieldMgr.get_field<double>(tviscID_);
dualNodalVolume_ = fieldMgr.get_field<double>(dualNodalVolumeID_);
turbPr_ = realm.get_turb_prandtl("enthalpy");
}
//--------------------------------------------------------------------------
//-------- execute ----------------------------------------------------
//--------------------------------------------------------------------------
KOKKOS_FUNCTION
void
TKERodiNodeKernel::execute(
NodeKernelTraits::LhsType& /*lhs*/,
NodeKernelTraits::RhsType& rhs,
const stk::mesh::FastMeshIndex& node)
{
typedef NodeKernelTraits::DblType Dbl;
const Dbl dualVolume = dualNodalVolume_.get(node, 0);
const Dbl specificHeat = specificHeat_.get(node, 0);
const Dbl tvisc = tvisc_.get(node, 0);
Dbl sum = 0.0;
for (int i = 0; i < nDim_; ++i) {
const Dbl dhdx = dhdx_.get(node, i);
sum += gravity_[i] * dhdx;
}
// no lhs contribution; all rhs source term
rhs(0) += beta_ * tvisc / turbPr_ * sum / specificHeat * dualVolume;
}
} // namespace nalu
} // namespace sierra
|
3a68656b65377223b982363cb957479cf44033bb
|
ba6029ab6b9e1511ce447a223b08df864ee1f6a5
|
/code/dnmx/feature_for_mixin.h
|
d6e28e5a3eb18195d860fdaf33633e5ac01a28f7
|
[
"MIT",
"CC-BY-4.0"
] |
permissive
|
iboB/dynamix
|
a47d3d822860a74ea2156f584a5ebdc3f76292e3
|
d69e989ddb0913a6fe7a17ed2b7cb303671c4b42
|
refs/heads/master
| 2023-05-05T21:01:05.967634
| 2023-04-26T04:16:16
| 2023-04-26T04:16:16
| 61,472,488
| 680
| 57
|
MIT
| 2023-04-23T03:31:23
| 2016-06-19T09:11:56
|
C++
|
UTF-8
|
C
| false
| false
| 579
|
h
|
feature_for_mixin.h
|
// Copyright (c) Borislav Stanimirov
// SPDX-License-Identifier: MIT
//
#pragma once
#include "feature_payload.h"
#include <stdint.h>
#if defined(__cplusplus)
extern "C" {
#endif
typedef struct dnmx_feature_info dnmx_feature_info;
// a structure that describes a feature with the payload for a concrete mixin
typedef struct dnmx_feature_for_mixin {
// pointer to registered feature info
const dnmx_feature_info* info;
dnmx_feature_payload payload;
// perks
int32_t bid;
int32_t priority;
} dnmx_feature_for_mixin;
#if defined(__cplusplus)
}
#endif
|
d20ae08eb276785df112a62870fffdadf7854137
|
b0dd7779c225971e71ae12c1093dc75ed9889921
|
/libs/math/quaternion/quaternion_mi2.h
|
d7fe9e0ff6e1b907d50afc6424a5392b7801e472
|
[
"LicenseRef-scancode-warranty-disclaimer",
"BSL-1.0"
] |
permissive
|
blackberry/Boost
|
6e653cd91a7806855a162347a5aeebd2a8c055a2
|
fc90c3fde129c62565c023f091eddc4a7ed9902b
|
refs/heads/1_48_0-gnu
| 2021-01-15T14:31:33.706351
| 2013-06-25T16:02:41
| 2013-06-25T16:02:41
| 2,599,411
| 244
| 154
|
BSL-1.0
| 2018-10-13T18:35:09
| 2011-10-18T14:25:18
|
C++
|
UTF-8
|
C
| false
| false
| 423
|
h
|
quaternion_mi2.h
|
// test file for quaternion.hpp
// (C) Copyright Hubert Holin 2001.
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_QUATERNION_MULTIPLE_INCLUDE_TEST_2
#define BOOST_QUATERNION_MULTIPLE_INCLUDE_TEST_2
void quaternion_mi2();
#endif /* BOOST_QUATERNION_MULTIPLE_INCLUDE_TEST_2 */
|
1b756cad583a40519177f182399c68860a7e6cdc
|
13e2a9bf3ebb4d2c6cdcc5b3cadaa9d87d94933e
|
/src/formats/pilot.h
|
a0509c9a73082af5129c3ce3b2c2ccf34e7f34c5
|
[
"MIT"
] |
permissive
|
omf2097/openomf
|
5421fa6702efa16c33b4154bfacd36a1a9127aae
|
4287067184d9f16d02035f6cf0abcafb0f9755be
|
refs/heads/master
| 2023-08-26T00:39:11.531162
| 2023-07-27T14:49:11
| 2023-07-27T14:49:11
| 7,473,802
| 299
| 40
|
MIT
| 2023-07-27T14:49:13
| 2013-01-06T22:58:13
|
C
|
UTF-8
|
C
| false
| false
| 7,420
|
h
|
pilot.h
|
/*! \file
* \brief Pilot structure handling.
* \details Functions and structs for reading, writing and modifying OMF:2097 pilot data structures.
* \copyright MIT license.
* \date 2013-2014
* \author Andrew Thompson
* \author Tuomas Virtanen
*/
#ifndef SD_PILOT_H
#define SD_PILOT_H
#include "formats/internal/memreader.h"
#include "formats/internal/memwriter.h"
#include "formats/internal/reader.h"
#include "formats/internal/writer.h"
#include "formats/palette.h"
#include "formats/sprite.h"
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/*! \brief PIC pilot information
*
* Contains a pilot information. Current upgrades, powers, tournament, etc.
*/
typedef struct {
uint32_t unknown_a; ///< Unknown
char name[18]; ///< Pilot name
uint16_t wins; ///< Matches won by this pilot
uint16_t losses; ///< Matches lost by this pilot
uint8_t rank; ///< Rank
uint8_t har_id; ///< Har Identifier (255 = random)
uint8_t arm_power; ///< HAR Arm power (0-9).
uint8_t leg_power; ///< HAR Leg power (0-9).
uint8_t arm_speed; ///< HAR Arm speed (0-9).
uint8_t leg_speed; ///< HAR Leg speed (0-9).
uint8_t armor; ///< Har armor (0-9).
uint8_t stun_resistance; ///< Har stun resistance (0-9).
uint8_t power; ///< Pilot power (1-25).
uint8_t agility; ///< Pilot agility (1-25).
uint8_t endurance; ///< Pilot endurance (1-25).
uint16_t offense; ///< Offense preference value (100 high, should be under 200).
uint16_t defense; ///< Defense preference value (100 high, should be under 200).
uint32_t money; ///< Amount of money the pilot currently has
uint8_t color_1; ///< Color 1 field for the HAR (0-15). 255 means random.
uint8_t color_2; ///< Color 2 field for the HAR (0-15). 255 means random.
uint8_t color_3; ///< Color 3 field for the HAR (0-15). 255 means random.
char trn_name[13]; ///< Tournament file
char trn_desc[31]; ///< Tournament description
char trn_image[13]; ///< Tournament image file
float unk_f_c; ///< Unknown
float unk_f_d; ///< Unknown
uint8_t pilot_id; ///< Pilot ID
uint8_t unknown_k; ///< Unknown
uint16_t force_arena; ///< Tells if this pilot needs to play on a certain arena
uint8_t difficulty; ///< Difficulty setting
char unk_block_b[2]; ///< Unknown
uint8_t movement; ///< Pilot can move in rankings
uint16_t unk_block_c[3]; ///< Unknown
char enhancements[11]; ///< Har enchancements. A field for each HAR.
uint8_t secret; ///< This character is a secret character, and only comes out when requirements match
uint8_t only_fight_once; ///< This character can only be fought once per tournament
uint8_t req_enemy; ///< Required defeated enemy for this character to appear (Value 0 if not set, otherwise
///< character id + 1)
uint8_t req_difficulty; ///< Required difficulty level for this character to appear
uint8_t req_rank; ///< Required minimum ranking for this character to appear
uint8_t req_vitality; ///< Required vitality for this character to appear
uint8_t req_fighter; ///< Required fighter for this character to appear
uint8_t req_accuracy; ///< Required accuracy for this character to appear
uint8_t req_avg_dmg; ///< Required average damage for this character to appear
uint8_t req_max_rank; ///< When you reach this ranking, this character appears.
uint8_t req_scrap; ///< Must have scrapped an enemy for this character to appear
uint8_t req_destroy; ///< Must have destroyed an enemy for this character to appear
uint8_t att_normal; ///< Standard fighting method
uint8_t att_hyper; ///< More aggressive
uint8_t att_jump; ///< Jumps more often
uint8_t att_def; ///< More defensive
uint8_t att_sniper; ///< Tries to sneak in quick hits
uint16_t unk_block_d[3]; ///< Unknown
int16_t ap_throw; ///< AI Preference for throw moves. Accepted value range (-400, 400).
int16_t ap_special; ///< AI Preference for special moves. Accepted value range (-400, 400).
int16_t ap_jump; ///< AI Preference for jump moves. Accepted value range (-400, 400).
int16_t ap_high; ///< AI Preference for high moves. Accepted value range (-400, 400).
int16_t ap_low; ///< AI Preference for low moves. Accepted value range (-400, 400).
int16_t ap_middle; ///< AI Preference for middle moves. Accepted value range (-400, 400).
int16_t pref_jump; ///< AI Preference for jump movement. Accepted value range (-400, 400).
int16_t pref_fwd; ///< AI Preference for forwards movement. Accepted value range (-400, 400).
int16_t pref_back; ///< AI Preference for backwards movement. Accepted value range (-400, 400).
uint32_t unknown_e; ///< Unknown
float learning; ///< How actively this pilot learns your combat tactics. Accepted value range (0-15).
float forget; ///< How quickly this pilot forgets your combat tactics. Accepted value range (0-3).
char unk_block_f[14]; ///< Unknown. Probably pointers and scratch variables
uint16_t enemies_inc_unranked; ///< Enemies in current tournament, including unranked opponents
uint16_t enemies_ex_unranked; ///< Same as above, excluding unranked opponents.
uint16_t unk_d_a; ///< Unknown.
uint32_t har_trades; ///< Unknown. Possible a bitmask ?
uint32_t winnings; ///< Money made by winning opponents
uint32_t total_value; ///< Total value for the pilot
float unk_f_a; ///< Unknown
float unk_f_b; ///< Unknown
palette palette; ///< Palette for photo ?
uint16_t unk_block_i; ///< Unknown
uint16_t photo_id; ///< Which face photo this pilot uses
char *quotes[10]; ///< Pilot quotes for each supported language
sd_sprite *photo; ///< Pilot photo, in tournament mode only
} sd_pilot;
typedef enum
{
PRIMARY,
SECONDARY,
TERTIARY
} player_color;
/*! \brief Initialize pilot struct
*
* Initializes the pilot structure with empty values.
*
* \retval SD_INVALID_INPUT Pilot struct pointer was NULL
* \retval SD_SUCCESS Success.
*
* \param pilot Allocated pilot struct pointer.
*/
int sd_pilot_create(sd_pilot *pilot);
/*! \brief Free pilot structure
*
* Frees up all memory reserved by the pilot structure.
* All contents will be freed, all pointers to contents will be invalid.
*
* \param pilot Pilot struct pointer.
*/
void sd_pilot_free(sd_pilot *pilot);
void sd_pilot_load_player_from_mem(memreader *mreader, sd_pilot *pilot);
void sd_pilot_load_from_mem(memreader *mreader, sd_pilot *pilot);
int sd_pilot_load(sd_reader *reader, sd_pilot *pilot);
void sd_pilot_save_player_to_mem(memwriter *mwriter, const sd_pilot *pilot);
void sd_pilot_save_to_mem(memwriter *mwriter, const sd_pilot *pilot);
int sd_pilot_save(sd_writer *writer, const sd_pilot *pilot);
void sd_pilot_set_player_color(sd_pilot *pilot, player_color index, uint8_t color);
#ifdef __cplusplus
}
#endif
#endif // SD_PILOT_H
|
94c8c2452a41203a7737c0b787a08bc0bb5d82a6
|
7eaf54a78c9e2117247cb2ab6d3a0c20719ba700
|
/SOFTWARE/A64-TERES/linux-a64/arch/sparc/power/hibernate.c
|
17bd2e167e07edd934dfe9957c43712b21401c55
|
[
"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
| 828
|
c
|
hibernate.c
|
/*
* hibernate.c: Hibernaton support specific for sparc64.
*
* Copyright (C) 2013 Kirill V Tkhai (tkhai@yandex.ru)
*/
#include <linux/mm.h>
#include <asm/hibernate.h>
#include <asm/visasm.h>
#include <asm/page.h>
#include <asm/sections.h>
#include <asm/tlb.h>
struct saved_context saved_context;
/*
* pfn_is_nosave - check if given pfn is in the 'nosave' section
*/
int pfn_is_nosave(unsigned long pfn)
{
unsigned long nosave_begin_pfn = PFN_DOWN((unsigned long)&__nosave_begin);
unsigned long nosave_end_pfn = PFN_DOWN((unsigned long)&__nosave_end);
return (pfn >= nosave_begin_pfn) && (pfn < nosave_end_pfn);
}
void save_processor_state(void)
{
save_and_clear_fpu();
}
void restore_processor_state(void)
{
struct mm_struct *mm = current->active_mm;
load_secondary_context(mm);
tsb_context_switch(mm);
}
|
7133de690d1b580cbc6e32331d08105a0e3c622d
|
bb38c44037a99d0a12a12d92059678f2faebbc80
|
/src/include/opfusion/opfusion_util.h
|
7246dc72048c03a686d28bde4817a4eed413d7a6
|
[
"LicenseRef-scancode-mulanpsl-2.0-en",
"LicenseRef-scancode-unknown-license-reference",
"PostgreSQL",
"BSD-3-Clause",
"LGPL-2.0-or-later",
"LicenseRef-scancode-unicode",
"LicenseRef-scancode-warranty-disclaimer",
"curl",
"GPL-1.0-or-later",
"LGPL-2.1-or-later",
"LGPL-2.1-only",
"CC-BY-4.0",
"LicenseRef-scancode-protobuf",
"OpenSSL",
"LicenseRef-scancode-generic-export-compliance",
"X11-distribute-modifications-variant",
"LicenseRef-scancode-other-permissive",
"MIT",
"NCSA",
"Python-2.0",
"LicenseRef-scancode-openssl",
"LicenseRef-scancode-ssleay-windows",
"CC-BY-3.0",
"LicenseRef-scancode-other-copyleft",
"GPL-2.0-only",
"BSL-1.0",
"Apache-2.0",
"LGPL-2.0-only",
"LicenseRef-scancode-public-domain",
"BSD-2-Clause",
"Zlib"
] |
permissive
|
opengauss-mirror/openGauss-server
|
a9c5a62908643492347830826c56da49f0942796
|
310e84631c68c8bf37b004148b66f94064f701e4
|
refs/heads/master
| 2023-07-26T19:29:12.495484
| 2023-07-17T12:23:32
| 2023-07-17T12:23:32
| 276,117,477
| 591
| 208
|
MulanPSL-2.0
| 2023-04-28T12:30:18
| 2020-06-30T14:08:59
|
C++
|
UTF-8
|
C
| false
| false
| 9,463
|
h
|
opfusion_util.h
|
/*
* Copyright (c) 2020 Huawei Technologies Co.,Ltd.
*
* openGauss is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
*
* http://license.coscl.org.cn/MulanPSL2
*
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
* ---------------------------------------------------------------------------------------
*
* opfusion_util.h
* Declaration of utilities for bypass executor.
*
* IDENTIFICATION
* src/include/opfusion/opfusion_util.h
*
* ---------------------------------------------------------------------------------------
*/
#ifndef SRC_INCLUDE_OPFUSION_OPFUSION_UTIL_H_
#define SRC_INCLUDE_OPFUSION_OPFUSION_UTIL_H_
#include "commands/prepare.h"
#include "lib/stringinfo.h"
#include "nodes/parsenodes.h"
#include "opfusion/opfusion_scan.h"
#include "pgxc/pgxcnode.h"
#include "utils/plancache.h"
#include "utils/syscache.h"
const int FUSION_EXECUTE = 0;
const int FUSION_DESCRIB = 1;
typedef struct pnFusionObj {
char portalname[NAMEDATALEN];
OpFusion *opfusion;
} pnFusionObj;
#define HASH_TBL_LEN 64
enum FusionType {
NONE_FUSION,
SELECT_FUSION,
SELECT_FOR_UPDATE_FUSION,
INSERT_FUSION,
UPDATE_FUSION,
DELETE_FUSION,
INSERT_SUB_FUSION,
DELETE_SUB_FUSION,
AGG_INDEX_FUSION,
SORT_INDEX_FUSION,
MOT_JIT_SELECT_FUSION,
MOT_JIT_MODIFY_FUSION,
BYPASS_OK,
NOBYPASS_NO_CPLAN,
NOBYPASS_NO_SIMPLE_PLAN,
NOBYPASS_NO_QUERY_TYPE,
NOBYPASS_LIMITOFFSET_CONST_LESS_THAN_ZERO,
NOBYPASS_LIMITCOUNT_CONST_LESS_THAN_ZERO,
NOBYPASS_LIMIT_NOT_CONST,
NOBYPASS_INVALID_SELECT_FOR_UPDATE,
NOBYPASS_INVALID_MODIFYTABLE,
NOBYPASS_NO_SIMPLE_INSERT,
NOBYPASS_UPSERT_NOT_SUPPORT,
NOBYPASS_NO_INDEXSCAN,
NOBYPASS_ONLY_SUPPORT_BTREE_INDEX,
NOBYPASS_INDEXSCAN_WITH_ORDERBY,
NOBYPASS_INDEXSCAN_WITH_QUAL,
NOBYPASS_INDEXSCAN_CONDITION_INVALID,
NOBYPASS_INDEXONLYSCAN_WITH_ORDERBY,
NOBYPASS_INDEXONLYSCAN_WITH_QUAL,
NOBYPASS_INDEXONLYSCAN_CONDITION_INVALID,
NOBYPASS_TARGET_WITH_SYS_COL,
NOBYPASS_TARGET_WITH_NO_TABLE_COL,
NOBYPASS_NO_TARGETENTRY,
NOBYPASS_PARAM_TYPE_INVALID,
NOBYPASS_DML_RELATION_NUM_INVALID,
NOBYPASS_DML_RELATION_NOT_SUPPORT,
NOBYPASS_DML_TARGET_TYPE_INVALID,
NOBYPASS_EXP_NOT_SUPPORT,
NOBYPASS_STREAM_NOT_SUPPORT,
NOBYPASS_NULLTEST_TYPE_INVALID,
NOBYPASS_INVALID_PLAN,
NOBYPASS_NOT_PLAIN_AGG,
NOBYPASS_ONE_TARGET_ALLOWED,
NOBYPASS_AGGREF_TARGET_ALLOWED,
NOBYPASS_JUST_SUM_ALLOWED,
NOBYPASS_JUST_VAR_FOR_AGGARGS,
NOBYPASS_JUST_MERGE_UNSUPPORTED,
NOBYPASS_JUST_VAR_ALLOWED_IN_SORT,
NOBYPASS_ZERO_PARTITION,
NOBYPASS_MULTI_PARTITION,
NOBYPASS_EXP_NOT_SUPPORT_IN_PARTITION,
NO_BYPASS_PARTITIONKEY_IS_NULL,
NOBYPASS_NO_UPDATE_PARTITIONKEY,
NOBYPASS_NO_INCLUDING_PARTITIONKEY,
NOBYPASS_PARTITION_BYPASS_NOT_OPEN,
NOBYPASS_VERSION_SCAN_PLAN,
NOBYPASS_PARTITION_TYPE_NOT_SUPPORT,
NOBYPASS_REPLACE_NOT_SUPPORT,
NOBYPASS_INSERT_SUB_FUSION_NOT_SUPPORT_PARTITION_BYPASS,
NOBYPASS_GPC_NOT_SUPPORT_PARTITION_BYPASS
};
enum FusionDebug {
BYPASS_OFF,
BYPASS_LOG,
};
const int MAX_OP_FUNCTION_NUM = 2;
typedef struct FuncExprInfo {
AttrNumber resno;
Oid funcid;
List *args;
char *resname;
} FuncExprInfo;
const int OPFUSION_FUNCTION_ID_MAX_HASH_SIZE = 200;
/* length of function_id should not more than OPFUSION_FUNCTION_ID_MAX_HASH_SIZE */
const Oid function_id[] = {
311, /* convert float4 to float8 */
312, /* convert float8 to float4 */
313, /* convert int2 to int4 */
314, /* convert int4 to int2 */
315, /* int2vectoreq */
316, /* convert int4 to float8 */
317, /* convert float8 to int4 */
318, /* convert int4 to float4 */
319, /* convert float4 to int4 */
406, /* convert name to text */
407, /* convert text to name */
408, /* convert name to char(n) */
409, /* convert char(n) to name */
668, /* adjust char() to typmod length */
669, /* adjust varchar() to typmod length */
944, /* convert text to char */
946, /* convert char to text */
1200, /* adjust interval precision */
1400, /* convert varchar to name */
1401, /* convert name to varchar */
1683, /* convert int4 to bitstring */
1684, /* convert bitstring to int4 */
1685, /* adjust bit() to typmod length */
1687, /* adjust varbit() to typmod length */
1703, /* adjust numeric to typmod precision/scale */
1705, /* abs */
1706, /* sign */
1707, /* round */
1711, /* ceil */
1712, /* floor */
1728, /* mod */
1740, /* convert int4 to numeric */
1742, /* convert float4 to numeric */
1743, /* convert float8 to numeric */
1744, /* convert numeric to int4 */
1745, /* convert numeric to float4 */
1746, /* convert numeric to float8 */
1778, /* convert text to timestamp with time zone */
1780, /* convert text to date */
1961, /* adjust timestamp precision */
1967, /* adjust timestamptz precision */
1968, /* adjust time precision */
1969, /* adjust time with time zone precision */
2089, /* convert int4 number to hex */
2090, /* convert int8 number to hex */
2617, /* ceiling */
3180, /* convert int2 to boolen */
3192, /* convert int4 to bpchar */
3207, /* convert text to timestamp without time zone */
3811, /* convert int4 to money */
3812, /* convert int8 to money */
3823, /* convert money to numeric */
3824, /* convert numeric to money */
3961, /* adjust nvarchar2() to typmod length */
3961, /* adjust nvarchar2() to typmod length */
4065, /* convert int1 to varchar */
4066, /* convert int1 to nvarchar2 */
4067, /* convert int1 to bpchar */
4068, /* convert int2 to bpchar */
4069, /* convert int8 to bpchar */
4070, /* convert float4 to bpchar */
4071, /* convert float8 to bpchar */
4072, /* convert numeric to bpchar */
4073, /* convert text to timestamp */
4167, /* convert int4 to text */
4168, /* convert int8 to text */
4169, /* convert float4 to text */
4170, /* convert float8 to text */
4171, /* convert numeric to text */
4172, /* convert bpchar to numeric */
4173, /* convert varchar to numeric */
4174, /* convert varchar to int4 */
4175, /* convert bpchar to int4 */
4176, /* convert varchar to int8 */
4177, /* convert timestampzone to text */
4178, /* convert timestamp to text */
4179, /* convert timestamp to text */
4180, /* convert int2 to varchar */
4181, /* convert int4 to varchar */
4182, /* convert int8 to varchar */
4183, /* convert numeric to varchar */
4184, /* convert float4 to varchar */
4185, /* convert float8 to varchar */
4186, /* convert varchar to timestamp */
4187, /* convert bpchar to timestamp */
4188, /* convert text to int1 */
4189, /* convert text to int2 */
4190, /* convert text to int4 */
4191, /* convert text to int8 */
4192, /* convert text to float4 */
4193, /* convert text to float8 */
4194, /* convert text to numeric */
4195, /* convert bpchar to int8 */
4196, /* convert bpchar to float4 */
4197, /* convert bpchar to float8 */
4198, /* convert varchar to float4 */
4199, /* convert varchar to float8 */
5523, /* convert int1 to int2 */
5524, /* convert int2 to int1 */
5525, /* convert int1 to int4 */
5526, /* convert int4 to int1 */
5527, /* convert int1 to int8 */
5528, /* convert int8 to int1 */
5529, /* convert int1 to float4 */
5530, /* convert float4 to int1 */
5531, /* convert int1 to float8 */
5532, /* convert float8 to int1 */
5533, /* convert int1 to bool */
5534 /* convert bool to int1 */
};
extern int namestrcmp(Name name, const char *str);
extern void report_qps_type(CmdType commandType);
void InitOpfusionFunctionId();
Node *JudgePlanIsPartIterator(Plan *plan);
const char *getBypassReason(FusionType result);
void BypassUnsupportedReason(FusionType result);
FusionType getSelectFusionType(List *stmt_list, ParamListInfo params);
FusionType getInsertFusionType(List *stmt_list, ParamListInfo params);
FusionType getUpdateFusionType(List *stmt_list, ParamListInfo params);
FusionType getDeleteFusionType(List *stmt_list, ParamListInfo params);
void tpslot_free_heaptuple(TupleTableSlot *reslot);
void InitPartitionByScanFusion(Relation rel, Relation *fakRel, Partition *part, EState *estate, const ScanFusion *scan);
Relation InitBucketRelation(int2 bucketid, Relation rel, Partition part);
void ExecDoneStepInFusion(EState *estate);
Oid GetRelOidForPartitionTable(Scan scan, const Relation rel, ParamListInfo params);
Relation InitPartitionIndexInFusion(Oid parentIndexOid, Oid partOid, Partition *partIndex, Relation *parentIndex,
Relation rel);
void InitPartitionRelationInFusion(Oid partOid, Relation parentRel, Partition *partRel, Relation *rel);
void ExeceDoneInIndexFusionConstruct(bool isPartTbl, Relation *parentRel, Partition *part, Relation *index,
Relation *rel);
#endif /* SRC_INCLUDE_OPFUSION_OPFUSION_UTIL_H_ */
|
5628c3f2058e6dc262ae75362fd7cb7ca42645ab
|
e2990cde74213c8858d1b56adb64fa7e479ec7bc
|
/auto-gen/bridge/stack/bridge.h
|
c6e51e04831318325140248e06826af6080243fb
|
[
"MIT"
] |
permissive
|
huawenyu/Design-Patterns-in-C
|
2b0c23c16460d2b220f74b23eab64c5defbce3b5
|
e18e87d39ea894d24f77b2d1e6ca37db231f1908
|
refs/heads/master
| 2023-04-10T13:10:39.251309
| 2023-04-05T16:38:18
| 2023-04-05T16:38:18
| 18,507,912
| 382
| 123
|
MIT
| 2022-08-01T14:08:10
| 2014-04-07T06:12:51
|
C
|
UTF-8
|
C
| false
| false
| 666
|
h
|
bridge.h
|
/**
* bridge.h 2014-05-02 01:32:58
* anonymouse(anonymouse@email)
*
* Copyright (C) 2000-2014 All Right Reserved
*
* THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
* KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
* PARTICULAR PURPOSE.
*
* Auto generate for Design Patterns in C
*/
#ifndef __BRIDGE_H__
#define __BRIDGE_H__
#include "stack_hanoi.h"
#include "stack_fifo.h"
#include "stack_impl_array.h"
#include "stack_impl_list.h"
struct bridge {
};
void bridge_init(struct bridge *);
void bridge_main_entry(void);
#endif /* __BRIDGE_H__ */
|
ef13ba064d7550743f921f37d369252259abfae6
|
fb47ab6337a71029dee71933e449cf7f6805fc0f
|
/arch/x86/include/arch/x86.h
|
c23a812ca2d5102c3625e6abc0d7d7642b050c48
|
[
"MIT"
] |
permissive
|
littlekernel/lk
|
7e7ba50b87b1f2e0b6e2f052c59249825c91975b
|
30dc320054f70910e1c1ee40a6948ee99672acec
|
refs/heads/master
| 2023-09-02T00:47:52.203963
| 2023-06-21T22:42:35
| 2023-06-21T22:42:35
| 3,058,456
| 3,077
| 618
|
MIT
| 2023-08-30T09:41:31
| 2011-12-27T19:19:36
|
C
|
UTF-8
|
C
| false
| false
| 18,278
|
h
|
x86.h
|
/*
* Copyright (c) 2009 Corey Tabaka
* Copyright (c) 2015 Intel Corporation
* Copyright (c) 2016 Travis Geiselbrecht
* Copyright 2016 The Fuchsia Authors
*
*
* Use of this source code is governed by a MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT
*/
#pragma once
#include <lk/compiler.h>
#include <sys/types.h>
#include <stdlib.h>
#include <stdbool.h>
__BEGIN_CDECLS
#define PFEX_P 0x01
#define PFEX_W 0x02
#define PFEX_U 0x04
#define PFEX_RSV 0x08
#define PFEX_I 0x10
#define X86_8BYTE_MASK 0xFFFFFFFF
struct x86_32_iframe {
uint32_t di, si, bp, sp, bx, dx, cx, ax; // pushed by common handler using pusha
uint32_t ds, es, fs, gs; // pushed by common handler
uint32_t vector; // pushed by stub
uint32_t err_code; // pushed by interrupt or stub
uint32_t ip, cs, flags; // pushed by interrupt
uint32_t user_sp, user_ss; // pushed by interrupt if priv change occurs
};
struct x86_64_iframe {
uint64_t di, si, bp, bx, dx, cx, ax; // pushed by common handler
uint64_t r8, r9, r10, r11, r12, r13, r14, r15; // pushed by common handler
uint64_t vector; // pushed by stub
uint64_t err_code; // pushed by interrupt or stub
uint64_t ip, cs, flags; // pushed by interrupt
uint64_t user_sp, user_ss; // pushed by interrupt if priv change occurs
};
#if ARCH_X86_32
typedef struct x86_32_iframe x86_iframe_t;
#elif ARCH_X86_64
typedef struct x86_64_iframe x86_iframe_t;
#endif
struct x86_32_context_switch_frame {
uint32_t edi, esi, ebp, esp, ebx, edx, ecx, eax;
uint32_t eflags;
uint32_t eip;
};
struct x86_64_context_switch_frame {
uint64_t r15, r14, r13, r12;
uint64_t rbp;
uint64_t rbx;
uint64_t rflags;
uint64_t rip;
};
void x86_64_context_switch(vaddr_t *oldsp, vaddr_t newsp);
/*
* x86-32 TSS structure
*/
typedef struct {
uint16_t backlink, __blh;
uint32_t esp0;
uint16_t ss0, __ss0h;
uint32_t esp1;
uint16_t ss1, __ss1h;
uint32_t esp2;
uint16_t ss2, __ss2h;
uint32_t cr3;
uint32_t eip;
uint32_t eflags;
uint32_t eax, ecx, edx, ebx;
uint32_t esp, ebp, esi, edi;
uint16_t es, __esh;
uint16_t cs, __csh;
uint16_t ss, __ssh;
uint16_t ds, __dsh;
uint16_t fs, __fsh;
uint16_t gs, __gsh;
uint16_t ldt, __ldth;
uint16_t trace, bitmap;
uint8_t tss_bitmap[8192];
} __PACKED tss_32_t;
/*
* x86-64 TSS structure
*/
typedef struct {
uint32_t rsvd0;
uint64_t rsp0;
uint64_t rsp1;
uint64_t rsp2;
uint32_t rsvd1;
uint32_t rsvd2;
uint64_t ist1;
uint64_t ist2;
uint64_t ist3;
uint64_t ist4;
uint64_t ist5;
uint64_t ist6;
uint64_t ist7;
uint32_t rsvd3;
uint32_t rsvd4;
uint16_t rsvd5;
uint16_t iomap_base;
} __PACKED tss_64_t;
#if ARCH_X86_32
typedef tss_32_t tss_t;
#elif ARCH_X86_64
typedef tss_64_t tss_t;
#endif
/* x86 register bits */
#define X86_CR0_PE (1U<<0) /* protected mode enable */
#define X86_CR0_MP (1U<<1) /* monitor coprocessor */
#define X86_CR0_EM (1U<<2) /* emulation */
#define X86_CR0_TS (1U<<3) /* task switched */
#define X86_CR0_ET (1U<<4) /* extension type */
#define X86_CR0_NE (1U<<5) /* enable x87 exception */
#define X86_CR0_WP (1U<<16) /* supervisor write protect */
#define X86_CR0_AM (1U<<18) /* alignment mask */
#define X86_CR0_NW (1U<<29) /* not write-through */
#define X86_CR0_CD (1U<<30) /* cache disable */
#define X86_CR0_PG (1U<<31) /* enable paging */
#define X86_CR4_VME (1U<<0) /* Virtual-8086 mode extensions */
#define X86_CR4_PVI (1U<<1) /* Protected Mode Virtual Interrupts */
#define X86_CR4_TSD (1U<<2) /* Time stamp disable*/
#define X86_CR4_DE (1U<<3) /* Debugging extensions */
#define X86_CR4_PSE (1U<<4) /* Page Size Extensions */
#define X86_CR4_PAE (1U<<5) /* PAE paging */
#define X86_CR4_MCE (1U<<6) /* Machine Check Enable */
#define X86_CR4_PGE (1U<<7) /* Page Global Enable */
#define X86_CR4_PCE (1U<<8) /* Performance Monitoring Counter Enable */
#define X86_CR4_OSFXSR (1U<<9) /* os supports fxsave */
#define X86_CR4_OSXMMEXPT (1U<<10) /* os supports xmm exception */
#define X86_CR4_UMIP (1U<<11) /* User-mode instruction prevention */
#define X86_CR4_LA57 (1U<<12) /* 57-bit Linear Addresses */
#define X86_CR4_VMXE (1U<<13) /* enable vmx */
#define X86_CR4_SMXE (1U<<14) /* enable smx */
#define X86_CR4_FSGSBASE (1U<<16) /* enable {rd,wr}{fs,gs}base */
#define X86_CR4_PCIDE (1U<<17) /* Process-context ID enable */
#define X86_CR4_OSXSAVE (1U<<18) /* os supports xsave */
#define X86_CR4_KL (1U<<19) /* key locker enable */
#define X86_CR4_SMEP (1U<<20) /* SMEP protection enabling */
#define X86_CR4_SMAP (1U<<21) /* SMAP protection enabling */
#define X86_CR4_PKE (1U<<22) /* Enable protection keys for user mode pages */
#define X86_CR4_CET (1U<<23) /* Control flow enforcement */
#define X86_CR4_PKS (1U<<24) /* Enable protection keys for supervisor mode pages */
#define X86_EFER_SCE (1U<<0) /* enable SYSCALL */
#define X86_EFER_LME (1U<<8) /* long mode enable */
#define X86_EFER_LMA (1U<<10) /* long mode active */
#define X86_EFER_NXE (1U<<11) /* no execute enable */
#define X86_EFER_SVME (1U<<12) /* secure virtual machine enable */
#define X86_EFER_LMSLE (1U<<13) /* long mode segment limit enable */
#define X86_EFER_FFXSR (1U<<14) /* fast fxsave/fxrstor */
#define X86_EFER_TCE (1U<<15) /* translation cache extension */
#define X86_EFER_MCOMMIT (1U<<17) /* enable mcommit instruction */
#define X86_EFER_INTWB (1U<<18) /* interrupt wbinvd/wbnoinvd enable */
#define X86_EFER_UAIE (1U<<20) /* upper address ignore enable */
#define X86_EFER_AIBRSE (1U<<20) /* automatic ibrs enable */
#define X86_MSR_IA32_PLATFORM_ID 0x00000017 /* platform id */
#define X86_MSR_IA32_APIC_BASE 0x0000001b /* APIC base physical address */
#define X86_MSR_IA32_TSC_ADJUST 0x0000003b /* TSC adjust */
#define X86_MSR_IA32_BIOS_SIGN_ID 0x0000008b /* BIOS update signature */
#define X86_MSR_IA32_MTRRCAP 0x000000fe /* MTRR capability */
#define X86_MSR_IA32_SYSENTER_CS 0x00000174 /* SYSENTER CS */
#define X86_MSR_IA32_SYSENTER_ESP 0x00000175 /* SYSENTER ESP */
#define X86_MSR_IA32_SYSENTER_EIP 0x00000176 /* SYSENTER EIP */
#define X86_MSR_IA32_MCG_CAP 0x00000179 /* global machine check capability */
#define X86_MSR_IA32_MCG_STATUS 0x0000017a /* global machine check status */
#define X86_MSR_IA32_MISC_ENABLE 0x000001a0 /* enable/disable misc processor features */
#define X86_MSR_IA32_TEMPERATURE_TARGET 0x000001a2 /* Temperature target */
#define X86_MSR_IA32_MTRR_PHYSBASE0 0x00000200 /* MTRR PhysBase0 */
#define X86_MSR_IA32_MTRR_PHYSMASK0 0x00000201 /* MTRR PhysMask0 */
#define X86_MSR_IA32_MTRR_PHYSMASK9 0x00000213 /* MTRR PhysMask9 */
#define X86_MSR_IA32_MTRR_DEF_TYPE 0x000002ff /* MTRR default type */
#define X86_MSR_IA32_MTRR_FIX64K_00000 0x00000250 /* MTRR FIX64K_00000 */
#define X86_MSR_IA32_MTRR_FIX16K_80000 0x00000258 /* MTRR FIX16K_80000 */
#define X86_MSR_IA32_MTRR_FIX16K_A0000 0x00000259 /* MTRR FIX16K_A0000 */
#define X86_MSR_IA32_MTRR_FIX4K_C0000 0x00000268 /* MTRR FIX4K_C0000 */
#define X86_MSR_IA32_MTRR_FIX4K_F8000 0x0000026f /* MTRR FIX4K_F8000 */
#define X86_MSR_IA32_PAT 0x00000277 /* PAT */
#define X86_MSR_IA32_TSC_DEADLINE 0x000006e0 /* TSC deadline */
#define X86_MSR_IA32_PM_ENABLE 0x00000770 /* enable/disable HWP */
#define X86_MSR_IA32_HWP_CAPABILITIES 0x00000771 /* HWP performance range enumeration */
#define X86_MSR_IA32_HWP_REQUEST 0x00000774 /* power manage control hints */
#define X86_MSR_IA32_EFER 0xc0000080 /* EFER */
#define X86_MSR_IA32_STAR 0xc0000081 /* system call address */
#define X86_MSR_IA32_LSTAR 0xc0000082 /* long mode call address */
#define X86_MSR_IA32_CSTAR 0xc0000083 /* ia32-e compat call address */
#define X86_MSR_IA32_FMASK 0xc0000084 /* system call flag mask */
#define X86_MSR_IA32_FS_BASE 0xc0000100 /* fs base address */
#define X86_MSR_IA32_GS_BASE 0xc0000101 /* gs base address */
#define X86_MSR_IA32_KERNEL_GS_BASE 0xc0000102 /* kernel gs base */
#define X86_MSR_IA32_TSC_AUX 0xc0000103 /* TSC aux */
// Non-architectural MSRs
#define X86_MSR_RAPL_POWER_UNIT 0x00000606 /* RAPL unit multipliers */
#define X86_MSR_PKG_POWER_LIMIT 0x00000610 /* Package power limits */
#define X86_MSR_PKG_POWER_LIMIT_PL1_CLAMP (1U << 16)
#define X86_MSR_PKG_POWER_LIMIT_PL1_ENABLE (1U << 15)
#define X86_MSR_PKG_ENERGY_STATUS 0x00000611 /* Package energy status */
#define X86_MSR_PKG_POWER_INFO 0x00000614 /* Package power range info */
#define X86_MSR_DRAM_POWER_LIMIT 0x00000618 /* DRAM RAPL power limit control */
#define X86_MSR_DRAM_ENERGY_STATUS 0x00000619 /* DRAM energy status */
#define X86_MSR_PP0_POWER_LIMIT 0x00000638 /* PP0 RAPL power limit control */
#define X86_MSR_PP0_ENERGY_STATUS 0x00000639 /* PP0 energy status */
#define X86_MSR_PP1_POWER_LIMIT 0x00000640 /* PP1 RAPL power limit control */
#define X86_MSR_PP1_ENERGY_STATUS 0x00000641 /* PP1 energy status */
#define X86_MSR_PLATFORM_ENERGY_COUNTER 0x0000064d /* Platform energy counter */
#define X86_MSR_PLATFORM_POWER_LIMIT 0x0000065c /* Platform power limit control */
/* EFLAGS/RFLAGS */
#define X86_FLAGS_CF (1U<<0)
#define X86_FLAGS_PF (1U<<2)
#define X86_FLAGS_AF (1U<<4)
#define X86_FLAGS_ZF (1U<<6)
#define X86_FLAGS_SF (1U<<7)
#define X86_FLAGS_TF (1U<<8)
#define X86_FLAGS_IF (1U<<9)
#define X86_FLAGS_DF (1U<<10)
#define X86_FLAGS_OF (1U<<11)
#define X86_FLAGS_STATUS_MASK (0xfff)
#define X86_FLAGS_IOPL_MASK (3U<<12)
#define X86_FLAGS_IOPL_SHIFT (12)
#define X86_FLAGS_NT (1U<<14)
#define X86_FLAGS_RF (1U<<16)
#define X86_FLAGS_VM (1U<<17)
#define X86_FLAGS_AC (1U<<18)
#define X86_FLAGS_VIF (1U<<19)
#define X86_FLAGS_VIP (1U<<20)
#define X86_FLAGS_ID (1U<<21)
#define X86_FLAGS_RESERVED_ONES (0x2)
#define X86_FLAGS_RESERVED (0xffc0802a)
#define X86_FLAGS_USER (X86_FLAGS_CF | \
X86_FLAGS_PF | \
X86_FLAGS_AF | \
X86_FLAGS_ZF | \
X86_FLAGS_SF | \
X86_FLAGS_TF | \
X86_FLAGS_DF | \
X86_FLAGS_OF | \
X86_FLAGS_NT | \
X86_FLAGS_AC | \
X86_FLAGS_ID)
static inline void x86_clts(void) { __asm__ __volatile__("clts"); }
static inline void x86_hlt(void) { __asm__ __volatile__("hlt"); }
static inline void x86_sti(void) { __asm__ __volatile__("sti"); }
static inline void x86_cli(void) { __asm__ __volatile__("cli"); }
static inline void x86_ltr(uint16_t sel) { __asm__ __volatile__("ltr %%ax" ::"a"(sel)); }
static inline void x86_lidt(uintptr_t base) { __asm volatile("lidt (%0)" ::"r"(base) : "memory"); }
static inline void x86_lgdt(uintptr_t base) { __asm volatile("lgdt (%0)" ::"r"(base) : "memory"); }
static inline ulong x86_get_cr0(void) {
ulong rv;
__asm__ __volatile__("mov %%cr0, %0 \n\t" : "=r"(rv));
return rv;
}
static inline void x86_set_cr0(ulong in_val) {
__asm__ __volatile__("mov %0,%%cr0 \n\t" : : "r"(in_val));
}
static inline void set_in_cr0(ulong mask) {
x86_set_cr0(x86_get_cr0() | mask);
}
static inline void clear_in_cr0(ulong mask) {
x86_set_cr0(x86_get_cr0() & ~mask);
}
static inline ulong x86_get_cr2(void) {
ulong rv;
__asm__ __volatile__("mov %%cr2, %0" : "=r"(rv));
return rv;
}
static inline ulong x86_get_cr3(void) {
ulong rv;
__asm__ __volatile__("mov %%cr3, %0" : "=r"(rv));
return rv;
}
static inline void x86_set_cr3(ulong in_val) {
__asm__ __volatile__("mov %0,%%cr3 \n\t" : : "r"(in_val));
}
static inline ulong x86_get_cr4(void) {
ulong rv;
__asm__ __volatile__("mov %%cr4, %0 \n\t" : "=r"(rv));
return rv;
}
static inline void x86_set_cr4(ulong in_val) {
__asm__ __volatile__("mov %0,%%cr4 \n\t" : : "r"(in_val));
}
static inline uint8_t inp(uint16_t _port) {
uint8_t rv;
__asm__ __volatile__("inb %1, %0" : "=a"(rv) : "dN"(_port));
return (rv);
}
static inline uint16_t inpw(uint16_t _port) {
uint16_t rv;
__asm__ __volatile__("inw %1, %0" : "=a"(rv) : "dN"(_port));
return (rv);
}
static inline uint32_t inpd(uint16_t _port) {
uint32_t rv;
__asm__ __volatile__("inl %1, %0" : "=a"(rv) : "dN"(_port));
return (rv);
}
static inline void outp(uint16_t _port, uint8_t _data) {
__asm__ __volatile__("outb %1, %0" : : "dN"(_port), "a"(_data));
}
static inline void outpw(uint16_t _port, uint16_t _data) {
__asm__ __volatile__("outw %1, %0" : : "dN"(_port), "a"(_data));
}
static inline void outpd(uint16_t _port, uint32_t _data) {
__asm__ __volatile__("outl %1, %0" : : "dN"(_port), "a"(_data));
}
static inline void inprep(uint16_t _port, uint8_t* _buffer, uint32_t _reads) {
__asm__ __volatile__(
"pushf \n\t"
"cli \n\t"
"cld \n\t"
"rep insb \n\t"
"popf \n\t"
: "+D"(_buffer), "+c"(_reads)
: "d"(_port)
: "memory");
}
static inline void outprep(uint16_t _port, uint8_t* _buffer, uint32_t _writes) {
__asm__ __volatile__(
"pushf \n\t"
"cli \n\t"
"cld \n\t"
"rep outsb \n\t"
"popf \n\t"
: "+S"(_buffer), "+c"(_writes)
: "d"(_port));
}
static inline void inpwrep(uint16_t _port, uint16_t* _buffer, uint32_t _reads) {
__asm__ __volatile__(
"pushf \n\t"
"cli \n\t"
"cld \n\t"
"rep insw \n\t"
"popf \n\t"
: "+D"(_buffer), "+c"(_reads)
: "d"(_port)
: "memory");
}
static inline void outpwrep(uint16_t _port, uint16_t* _buffer, uint32_t _writes) {
__asm__ __volatile__(
"pushf \n\t"
"cli \n\t"
"cld \n\t"
"rep outsw \n\t"
"popf \n\t"
: "+S"(_buffer), "+c"(_writes)
: "d"(_port));
}
static inline void inpdrep(uint16_t _port, uint32_t* _buffer, uint32_t _reads) {
__asm__ __volatile__(
"pushf \n\t"
"cli \n\t"
"cld \n\t"
"rep insl \n\t"
"popf \n\t"
: "+D"(_buffer), "+c"(_reads)
: "d"(_port)
: "memory");
}
static inline void outpdrep(uint16_t _port, uint32_t* _buffer, uint32_t _writes) {
__asm__ __volatile__(
"pushf \n\t"
"cli \n\t"
"cld \n\t"
"rep outsl \n\t"
"popf \n\t"
: "+S"(_buffer), "+c"(_writes)
: "d"(_port));
}
static inline bool x86_is_paging_enabled(void) {
if (x86_get_cr0() & X86_CR0_PG)
return true;
return false;
}
static inline bool x86_is_PAE_enabled(void) {
if (x86_is_paging_enabled() == false)
return false;
if (!(x86_get_cr4() & X86_CR4_PAE))
return false;
return true;
}
static inline void cpuid(uint32_t leaf, uint32_t *a, uint32_t *b, uint32_t *c, uint32_t *d) {
__asm__ __volatile__ (
"cpuid"
: "=a"(*a), "=b"(*b), "=c"(*c), "=d"(*d)
: "a"(leaf), "c"(0));
}
static inline void cpuid_c(uint32_t leaf, uint32_t csel, uint32_t *a, uint32_t *b, uint32_t *c, uint32_t *d) {
__asm__ __volatile__ (
"cpuid"
: "=a"(*a), "=b"(*b), "=c"(*c), "=d"(*d)
: "a"(leaf), "c"(csel));
}
static inline uint64_t read_msr (uint32_t msr_id) {
uint64_t msr_read_val;
uint32_t low_val;
uint32_t high_val;
__asm__ __volatile__ (
"rdmsr \n\t"
: "=a" (low_val), "=d"(high_val)
: "c" (msr_id));
msr_read_val = high_val;
msr_read_val = (msr_read_val << 32) | low_val;
return msr_read_val;
}
static inline void write_msr (uint32_t msr_id, uint64_t msr_write_val) {
uint32_t low_val = (uint32_t)msr_write_val;
uint32_t high_val = (uint32_t)(msr_write_val >> 32);
__asm__ __volatile__ (
"wrmsr \n\t"
: : "c" (msr_id), "a" (low_val), "d"(high_val));
}
typedef ulong x86_flags_t;
static inline x86_flags_t x86_save_flags(void) {
x86_flags_t state;
__asm__ volatile(
"pushf;"
"pop %0"
: "=rm" (state)
:: "memory");
return state;
}
static inline void x86_restore_flags(x86_flags_t flags) {
__asm__ volatile(
"push %0;"
"popf"
:: "g" (flags)
: "memory", "cc");
}
static inline void tlbsync_local(vaddr_t address) {
asm volatile("invlpg %0" :: "m"(*(uint8_t *)address));
}
__END_CDECLS
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.