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
|
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
138cbf12aac9136387dbb7e97765dafd2f07ecda
|
336d3942e52ba91604d479e590a1e35d6d7c14a4
|
/deps/jemalloc/include/jemalloc/internal/san_bump.h
|
8ec4a710d6f4a51e0ae3d6090585f4a1230c308d
|
[
"BSD-3-Clause",
"BSD-2-Clause"
] |
permissive
|
redis/redis
|
8fb932a09677ed8854c94d81c941655eceda2138
|
e792653753dc62b5a00822121e585511542a024b
|
refs/heads/unstable
| 2023-08-29T14:53:21.757052
| 2023-08-27T08:42:55
| 2023-08-27T08:42:55
| 156,018
| 19,822
| 6,754
|
BSD-3-Clause
| 2023-09-14T18:06:48
| 2009-03-21T22:32:25
|
C
|
UTF-8
|
C
| false
| false
| 1,449
|
h
|
san_bump.h
|
#ifndef JEMALLOC_INTERNAL_SAN_BUMP_H
#define JEMALLOC_INTERNAL_SAN_BUMP_H
#include "jemalloc/internal/edata.h"
#include "jemalloc/internal/exp_grow.h"
#include "jemalloc/internal/mutex.h"
#define SBA_RETAINED_ALLOC_SIZE ((size_t)4 << 20)
extern bool opt_retain;
typedef struct ehooks_s ehooks_t;
typedef struct pac_s pac_t;
typedef struct san_bump_alloc_s san_bump_alloc_t;
struct san_bump_alloc_s {
malloc_mutex_t mtx;
edata_t *curr_reg;
};
static inline bool
san_bump_enabled() {
/*
* We enable san_bump allocator only when it's possible to break up a
* mapping and unmap a part of it (maps_coalesce). This is needed to
* ensure the arena destruction process can destroy all retained guarded
* extents one by one and to unmap a trailing part of a retained guarded
* region when it's too small to fit a pending allocation.
* opt_retain is required, because this allocator retains a large
* virtual memory mapping and returns smaller parts of it.
*/
return maps_coalesce && opt_retain;
}
static inline bool
san_bump_alloc_init(san_bump_alloc_t* sba) {
bool err = malloc_mutex_init(&sba->mtx, "sanitizer_bump_allocator",
WITNESS_RANK_SAN_BUMP_ALLOC, malloc_mutex_rank_exclusive);
if (err) {
return true;
}
sba->curr_reg = NULL;
return false;
}
edata_t *
san_bump_alloc(tsdn_t *tsdn, san_bump_alloc_t* sba, pac_t *pac, ehooks_t *ehooks,
size_t size, bool zero);
#endif /* JEMALLOC_INTERNAL_SAN_BUMP_H */
|
63e6747672b9daecb9e03f7a411fc3006842a006
|
99bdb3251fecee538e0630f15f6574054dfc1468
|
/bsp/at32/libraries/AT32F425_Firmware_Library/drivers/inc/at32f425_usb.h
|
ff37f876a8c1814a7b96e37873906d5fac1c0784
|
[
"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
| 55,048
|
h
|
at32f425_usb.h
|
/**
**************************************************************************
* @file at32f425_usb.h
* @brief at32f425 usb header file
**************************************************************************
* Copyright notice & Disclaimer
*
* The software Board Support Package (BSP) that is made available to
* download from Artery official website is the copyrighted work of Artery.
* Artery authorizes customers to use, copy, and distribute the BSP
* software and its related documentation for the purpose of design and
* development in conjunction with Artery microcontrollers. Use of the
* software is governed by this copyright notice and the following disclaimer.
*
* THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
* GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
* TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
* STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
* INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
*
**************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __AT32F425_USB_H
#define __AT32F425_USB_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "at32f425.h"
/** @addtogroup AT32F425_periph_driver
* @{
*/
/** @addtogroup USB
* @{
*/
/** @defgroup USB_global_interrupts_definition
* @brief usb global interrupt mask
* @{
*/
#define USB_OTG_MODEMIS_INT ((uint32_t)0x00000002) /*!< usb otg mode mismatch interrupt */
#define USB_OTG_OTGINT_INT ((uint32_t)0x00000004) /*!< usb otg interrupt */
#define USB_OTG_SOF_INT ((uint32_t)0x00000008) /*!< usb otg sof interrupt */
#define USB_OTG_RXFLVL_INT ((uint32_t)0x00000010) /*!< usb otg receive fifo non-empty interrupt */
#define USB_OTG_NPTXFEMP_INT ((uint32_t)0x00000020) /*!< usb otg non-periodic tx fifo empty interrupt */
#define USB_OTG_GINNAKEFF_INT ((uint32_t)0x00000040) /*!< usb otg global non-periodic in nak effective interrupt */
#define USB_OTG_GOUTNAKEFF_INT ((uint32_t)0x00000080) /*!< usb otg global out nak effective interrupt */
#define USB_OTG_ERLYSUSP_INT ((uint32_t)0x00000400) /*!< usb otg early suspend interrupt */
#define USB_OTG_USBSUSP_INT ((uint32_t)0x00000800) /*!< usb otg suspend interrupt */
#define USB_OTG_USBRST_INT ((uint32_t)0x00001000) /*!< usb otg reset interrupt */
#define USB_OTG_ENUMDONE_INT ((uint32_t)0x00002000) /*!< usb otg enumeration done interrupt */
#define USB_OTG_ISOOUTDROP_INT ((uint32_t)0x00004000) /*!< usb otg isochronous out packet dropped interrut */
#define USB_OTG_EOPF_INT ((uint32_t)0x00008000) /*!< usb otg eop interrupt */
#define USB_OTG_IEPT_INT ((uint32_t)0x00040000) /*!< usb otg in endpoint interrupt */
#define USB_OTG_OEPT_INT ((uint32_t)0x00080000) /*!< usb otg out endpoint interrupt */
#define USB_OTG_INCOMISOIN_INT ((uint32_t)0x00100000) /*!< usb otg incomplete isochronous in transfer interrupt */
#define USB_OTG_INCOMPIP_INCOMPISOOUT_INT ((uint32_t)0x00200000) /*!< usb otg incomplete periodic transfer/isochronous out interrupt */
#define USB_OTG_PRT_INT ((uint32_t)0x01000000) /*!< usb otg host port interrupt */
#define USB_OTG_HCH_INT ((uint32_t)0x02000000) /*!< usb otg host channel interrupt */
#define USB_OTG_PTXFEMP_INT ((uint32_t)0x04000000) /*!< usb otg periodic txfifo empty interrupt */
#define USB_OTG_CONIDSCHG_INT ((uint32_t)0x10000000) /*!< usb otg connector id status change interrupt */
#define USB_OTG_DISCON_INT ((uint32_t)0x20000000) /*!< usb otg disconnect detected interrupt */
#define USB_OTG_WKUP_INT ((uint32_t)0x80000000) /*!< usb otg wakeup interrupt */
/**
* @}
*/
/** @defgroup USB_global_interrupt_flags_definition
* @brief usb global interrupt flag
* @{
*/
#define USB_OTG_CURMODE ((uint32_t)0x00000001) /*!< usb otg current mode */
#define USB_OTG_MODEMIS_FLAG ((uint32_t)0x00000002) /*!< usb otg mode mismatch flag */
#define USB_OTG_OTGINT_FLAG ((uint32_t)0x00000004) /*!< usb otg flag */
#define USB_OTG_SOF_FLAG ((uint32_t)0x00000008) /*!< usb otg sof flag */
#define USB_OTG_RXFLVL_FLAG ((uint32_t)0x00000010) /*!< usb otg receive fifo non-empty flag */
#define USB_OTG_NPTXFEMP_FLAG ((uint32_t)0x00000020) /*!< usb otg non-periodic tx fifo empty flag */
#define USB_OTG_GINNAKEFF_FLAG ((uint32_t)0x00000040) /*!< usb otg global non-periodic in nak effective flag */
#define USB_OTG_GOUTNAKEFF_FLAG ((uint32_t)0x00000080) /*!< usb otg global out nak effective flag */
#define USB_OTG_ERLYSUSP_FLAG ((uint32_t)0x00000400) /*!< usb otg early suspend flag */
#define USB_OTG_USBSUSP_FLAG ((uint32_t)0x00000800) /*!< usb otg suspend flag */
#define USB_OTG_USBRST_FLAG ((uint32_t)0x00001000) /*!< usb otg reset flag */
#define USB_OTG_ENUMDONE_FLAG ((uint32_t)0x00002000) /*!< usb otg enumeration done flag */
#define USB_OTG_ISOOUTDROP_FLAG ((uint32_t)0x00004000) /*!< usb otg isochronous out packet dropped flag */
#define USB_OTG_EOPF_FLAG ((uint32_t)0x00008000) /*!< usb otg eop flag */
#define USB_OTG_IEPT_FLAG ((uint32_t)0x00040000) /*!< usb otg in endpoint flag */
#define USB_OTG_OEPT_FLAG ((uint32_t)0x00080000) /*!< usb otg out endpoint flag */
#define USB_OTG_INCOMISOIN_FLAG ((uint32_t)0x00100000) /*!< usb otg incomplete isochronous in transfer flag */
#define USB_OTG_INCOMPIP_INCOMPISOOUT_FLAG ((uint32_t)0x00200000) /*!< usb otg incomplete periodic transfer/isochronous out flag */
#define USB_OTG_PRT_FLAG ((uint32_t)0x01000000) /*!< usb otg host port flag */
#define USB_OTG_HCH_FLAG ((uint32_t)0x02000000) /*!< usb otg host channel flag */
#define USB_OTG_PTXFEMP_FLAG ((uint32_t)0x04000000) /*!< usb otg periodic txfifo empty flag */
#define USB_OTG_CONIDSCHG_FLAG ((uint32_t)0x10000000) /*!< usb otg connector id status change flag */
#define USB_OTG_DISCON_FLAG ((uint32_t)0x20000000) /*!< usb otg disconnect detected flag */
#define USB_OTG_WKUP_FLAG ((uint32_t)0x80000000) /*!< usb otg wakeup flag */
/**
* @}
*/
/** @defgroup USB_global_setting_definition
* @brief usb global setting
* @{
*/
/**
* @brief usb turnaround time
*/
#define USB_TRDTIM_8 0x9 /*!< usb turn around time 8 */
#define USB_TRDTIM_16 0x5 /*!< usb turn around time 16 */
/**
* @brief usb receive status
*/
#define USB_OTG_GRXSTSP_EPTNUM ((uint32_t)0x0000000F) /*!< usb device receive packet endpoint number*/
#define USB_OTG_GRXSTSP_CHNUM ((uint32_t)0x0000000F) /*!< usb host receive packet channel number*/
#define USB_OTG_GRXSTSP_BCNT ((uint32_t)0x00007FF0) /*!< usb receive packet byte count */
#define USB_OTG_GRXSTSP_DPID ((uint32_t)0x00018000) /*!< usb receive packet pid */
#define USB_OTG_GRXSTSP_PKTSTS ((uint32_t)0x001E0000) /*!< usb receive packet status */
/**
* @brief usb host packet status
*/
#define PKTSTS_IN_DATA_PACKET_RECV 0x2 /*!< usb host in data packet received */
#define PKTSTS_IN_TRANSFER_COMPLETE 0x3 /*!< usb host in transfer completed */
#define PKTSTS_DATA_BIT_ERROR 0x5 /*!< usb host data toggle error */
#define PKTSTS_CHANNEL_STOP 0x7 /*!< usb host channel halted */
/**
* @brief usb device packet status
*/
#define USB_OUT_STS_NAK 0x1 /*!< usb device global out nak */
#define USB_OUT_STS_DATA 0x2 /*!< usb device out data packet received */
#define USB_OUT_STS_COMP 0x3 /*!< usb device out transfer completed */
#define USB_SETUP_STS_COMP 0x4 /*!< usb device setup transcation completed */
#define USB_SETUP_STS_DATA 0x6 /*!< usb device setup data packet received */
/**
* @}
*/
/** @defgroup USB_host_config_definition
* @{
*/
/**
* @brief usb host phy clock
*/
#define USB_HCFG_CLK_60M 0 /*!< usb host phy clock 60mhz */
#define USB_HCFG_CLK_48M 1 /*!< usb host phy clock 48mhz */
#define USB_HCFG_CLK_6M 2 /*!< usb host phy clock 6mhz */
/**
* @brief usb host port status
*/
#define USB_OTG_HPRT_PRTCONSTS ((uint32_t)0x00000001) /*!< usb host port connect status */
#define USB_OTG_HPRT_PRTCONDET ((uint32_t)0x00000002) /*!< usb host port connect detected */
#define USB_OTG_HPRT_PRTENA ((uint32_t)0x00000004) /*!< usb host port enable */
#define USB_OTG_HPRT_PRTENCHNG ((uint32_t)0x00000008) /*!< usb host port enable/disable change */
#define USB_OTG_HPRT_PRTOVRCACT ((uint32_t)0x00000010) /*!< usb host port overcurrent active */
#define USB_OTG_HPRT_PRTOVRCCHNG ((uint32_t)0x00000020) /*!< usb host port overcurrent change */
#define USB_OTG_HPRT_PRTRES ((uint32_t)0x00000040) /*!< usb host port resume */
#define USB_OTG_HPRT_PRTSUSP ((uint32_t)0x00000080) /*!< usb host port suspend */
#define USB_OTG_HPRT_PRTRST ((uint32_t)0x00000100) /*!< usb host port reset */
#define USB_OTG_HPRT_PRTLNSTS ((uint32_t)0x00000C00) /*!< usb host port line status */
#define USB_OTG_HPRT_PRTPWR ((uint32_t)0x00001000) /*!< usb host port power */
#define USB_OTG_HPRT_PRTSPD ((uint32_t)0x00060000) /*!< usb host port speed */
/**
* @brief usb port speed
*/
#define USB_PRTSPD_HIGH_SPEED 0 /*!< usb host port high speed */
#define USB_PRTSPD_FULL_SPEED 1 /*!< usb host port full speed */
#define USB_PRTSPD_LOW_SPEED 2 /*!< usb host port low speed */
/**
* @brief usb host register hcchar bit define
*/
#define USB_OTG_HCCHAR_MPS ((uint32_t)0x000007FF) /*!< channel maximum packet size */
#define USB_OTG_HCCHAR_EPTNUM ((uint32_t)0x00007800) /*!< endpoint number */
#define USB_OTG_HCCHAR_EPTDIR ((uint32_t)0x00008000) /*!< endpoint direction */
#define USB_OTG_HCCHAR_LSPDDEV ((uint32_t)0x00020000) /*!< low speed device */
#define USB_OTG_HCCHAR_EPTYPE ((uint32_t)0x000C0000) /*!< endpoint type */
#define USB_OTG_HCCHAR_MC ((uint32_t)0x00300000) /*!< multi count */
#define USB_OTG_HCCHAR_DEVADDR ((uint32_t)0x1FC00000) /*!< device address */
#define USB_OTG_HCCHAR_ODDFRM ((uint32_t)0x20000000) /*!< odd frame */
#define USB_OTG_HCCHAR_CHDIS ((uint32_t)0x40000000) /*!< channel disable */
#define USB_OTG_HCCHAR_CHENA ((uint32_t)0x80000000) /*!< channel enable */
/**
* @brief usb host register hctsiz bit define
*/
#define USB_OTG_HCTSIZ_XFERSIZE ((uint32_t)0x0007FFFF) /*!< channel transfer size */
#define USB_OTG_HCTSIZ_PKTCNT ((uint32_t)0x1FF80000) /*!< channel packet count */
#define USB_OTG_HCTSIZ_PID ((uint32_t)0x60000000) /*!< channel pid */
/**
* @brief usb host channel interrupt mask
*/
#define USB_OTG_HC_XFERCM_INT ((uint32_t)0x00000001) /*!< channel transfer complete interrupt */
#define USB_OTG_HC_CHHLTDM_INT ((uint32_t)0x00000002) /*!< channel halted interrupt */
#define USB_OTG_HC_STALLM_INT ((uint32_t)0x00000008) /*!< channel stall interrupt */
#define USB_OTG_HC_NAKM_INT ((uint32_t)0x00000010) /*!< channel nak interrupt */
#define USB_OTG_HC_ACKM_INT ((uint32_t)0x00000020) /*!< channel ack interrupt */
#define USB_OTG_HC_NYETM_INT ((uint32_t)0x00000040) /*!< channel nyet interrupt */
#define USB_OTG_HC_XACTERRM_INT ((uint32_t)0x00000080) /*!< channel transaction error interrupt */
#define USB_OTG_HC_BBLERRM_INT ((uint32_t)0x00000100) /*!< channel babble error interrupt */
#define USB_OTG_HC_FRMOVRRUN_INT ((uint32_t)0x00000200) /*!< channel frame overrun interrupt */
#define USB_OTG_HC_DTGLERRM_INT ((uint32_t)0x00000400) /*!< channel data toggle interrupt */
/**
* @brief usb host channel interrupt flag
*/
#define USB_OTG_HC_XFERC_FLAG ((uint32_t)0x00000001) /*!< channel transfer complete flag */
#define USB_OTG_HC_CHHLTD_FLAG ((uint32_t)0x00000002) /*!< channel halted flag */
#define USB_OTG_HC_STALL_FLAG ((uint32_t)0x00000008) /*!< channel stall flag */
#define USB_OTG_HC_NAK_FLAG ((uint32_t)0x00000010) /*!< channel nak flag */
#define USB_OTG_HC_ACK_FLAG ((uint32_t)0x00000020) /*!< channel ack flag */
#define USB_OTG_HC_NYET_FLAG ((uint32_t)0x00000040) /*!< channel nyet flag */
#define USB_OTG_HC_XACTERR_FLAG ((uint32_t)0x00000080) /*!< channel transaction error flag */
#define USB_OTG_HC_BBLERR_FLAG ((uint32_t)0x00000100) /*!< channel babble error flag */
#define USB_OTG_HC_FRMOVRRUN_FLAG ((uint32_t)0x00000200) /*!< channel frame overrun flag */
#define USB_OTG_HC_DTGLERR_FLAG ((uint32_t)0x00000400) /*!< channel data toggle flag */
/**
* @}
*/
/** @defgroup USB_device_config_definition
* @{
*/
/**
* @brief usb device periodic frame interval
*/
typedef enum
{
DCFG_PERFRINT_80 = 0x00, /*!< periodic frame interval 80% */
DCFG_PERFRINT_85 = 0x01, /*!< periodic frame interval 85% */
DCFG_PERFRINT_90 = 0x02, /*!< periodic frame interval 90% */
DCFG_PERFRINT_95 = 0x03 /*!< periodic frame interval 95% */
} dcfg_perfrint_type;
/**
* @brief usb device full speed
*/
#define USB_DCFG_FULL_SPEED 3 /*!< device full speed */
/**
* @brief usb device ctrl define
*/
#define USB_OTG_DCTL_RWKUPSIG ((uint32_t)0x00000001) /*!< usb device remote wakeup signaling */
#define USB_OTG_DCTL_SFTDISCON ((uint32_t)0x00000002) /*!< usb device soft disconnect */
#define USB_OTG_DCTL_GNPINNAKSTS ((uint32_t)0x00000004) /*!< usb device global non-periodic in nak status */
#define USB_OTG_DCTL_GOUTNAKSTS ((uint32_t)0x00000008) /*!< usb device global out nak status */
#define USB_OTG_DCTL_SGNPINNAK ((uint32_t)0x00000080) /*!< usb device set global non-periodic in nak */
#define USB_OTG_DCTL_CGNPINNAK ((uint32_t)0x00000100) /*!< usb device clear global non-periodic in nak */
#define USB_OTG_DCTL_SGOUTNAK ((uint32_t)0x00000200) /*!< usb device set global out nak status */
#define USB_OTG_DCTL_CGOUTNAK ((uint32_t)0x00000400) /*!< usb device clear global out nak status */
#define USB_OTG_DCTL_PWROPRGDNE ((uint32_t)0x00000800) /*!< usb device power on programming done */
/**
* @brief usb device in endpoint flag
*/
#define USB_OTG_DIEPINT_XFERC_FLAG ((uint32_t)0x00000001) /*!< usb device in transfer completed flag */
#define USB_OTG_DIEPINT_EPTDISD_FLAG ((uint32_t)0x00000002) /*!< usb device endpoint disable flag */
#define USB_OTG_DIEPINT_TIMEOUT_FLAG ((uint32_t)0x00000008) /*!< usb device in timeout */
#define USB_OTG_DIEPINT_INTKNTXFEMP_FLAG ((uint32_t)0x00000010) /*!< usb device in token received when tx fifo is empty flag */
#define USB_OTG_DIEPINT_INEPTNAK_FLAG ((uint32_t)0x00000040) /*!< usb device in endpoint nak effective flag */
#define USB_OTG_DIEPINT_TXFEMP_FLAG ((uint32_t)0x00000080) /*!< usb device transmit fifo empty flag */
/**
* @brief usb device out endpoint flag
*/
#define USB_OTG_DOEPINT_XFERC_FLAG ((uint32_t)0x00000001) /*!< usb device out transfer completed flag */
#define USB_OTG_DOEPINT_EPTDISD_FLAG ((uint32_t)0x00000002) /*!< usb device endpoint disable flag */
#define USB_OTG_DOEPINT_SETUP_FLAG ((uint32_t)0x00000008) /*!< usb device setup flag */
#define USB_OTG_DOEPINT_OUTTEPD_FLAG ((uint32_t)0x00000010) /*!< usb device out token recevied when endpoint disable flag */
#define USB_OTG_DOEPINT_B2BSTUP_FLAG ((uint32_t)0x00000040) /*!< back-to-back setup packets received */
/**
* @brief usb device in endpoint fifo space mask
*/
#define USB_OTG_DTXFSTS_INEPTFSAV ((uint32_t)0x0000FFFF) /*!< usb device in endpoint tx fifo space avail */
/**
* @brief endpoint0 maximum packet size
*/
#define USB_EPT0_MPS_64 0 /*!< usb device endpoint 0 maximum packet size 64byte */
#define USB_EPT0_MPS_32 1 /*!< usb device endpoint 0 maximum packet size 32byte */
#define USB_EPT0_MPS_16 2 /*!< usb device endpoint 0 maximum packet size 16byte */
#define USB_EPT0_MPS_8 3 /*!< usb device endpoint 0 maximum packet size 8byte */
/**
* @}
*/
/**
* @brief otg fifo size (word)
*/
#define OTG_FIFO_SIZE 320 /*!< otg usb total fifo size */
/**
* @brief otg host max buffer length (byte)
*/
#define USB_MAX_DATA_LENGTH 0x200 /*!< usb host maximum buffer size */
#define OTGFS_USB_GLOBAL
#define OTGFS_USB_DEVICE
#define OTGFS_USB_HOST
/** @defgroup USB_exported_enum_types
* @{
*/
/**
* @brief usb mode define(device, host, drd)
*/
typedef enum
{
OTG_DEVICE_MODE, /*!< usb device mode */
OTG_HOST_MODE, /*!< usb host mode */
OTG_DRD_MODE /*!< usb drd mode */
} otg_mode_type;
/**
* @brief endpoint type define
*/
typedef enum
{
EPT_CONTROL_TYPE = 0x00, /*!< usb endpoint type control */
EPT_ISO_TYPE = 0x01, /*!< usb endpoint type iso */
EPT_BULK_TYPE = 0x02, /*!< usb endpoint type bulk */
EPT_INT_TYPE = 0x03 /*!< usb endpoint type interrupt */
} endpoint_trans_type;
/**
* @brief usb endpoint number define type
*/
typedef enum
{
USB_EPT0 = 0x00, /*!< usb endpoint 0 */
USB_EPT1 = 0x01, /*!< usb endpoint 1 */
USB_EPT2 = 0x02, /*!< usb endpoint 2 */
USB_EPT3 = 0x03, /*!< usb endpoint 3 */
USB_EPT4 = 0x04, /*!< usb endpoint 4 */
USB_EPT5 = 0x05, /*!< usb endpoint 5 */
USB_EPT6 = 0x06, /*!< usb endpoint 6 */
USB_EPT7 = 0x07 /*!< usb endpoint 7 */
} usb_endpoint_number_type;
/**
* @brief usb endpoint max num define
*/
#ifndef USB_EPT_MAX_NUM
#define USB_EPT_MAX_NUM 8 /*!< usb device support endpoint number */
#endif
/**
* @brief usb channel max num define
*/
#ifndef USB_HOST_CHANNEL_NUM
#define USB_HOST_CHANNEL_NUM 16 /*!< usb host support channel number */
#endif
/**
* @brief endpoint trans dir type
*/
typedef enum
{
EPT_DIR_IN = 0x00, /*!< usb transfer direction in */
EPT_DIR_OUT = 0x01 /*!< usb transfer direction out */
} endpoint_dir_type;
/**
* @brief otgfs1 and otgfs2 select type
*/
typedef enum
{
USB_OTG1_ID, /*!< usb otg 1 id */
USB_OTG2_ID /*!< usb otg 2 id */
} otg_id_type;
/**
* @brief usb clock select
*/
typedef enum
{
USB_CLK_HICK, /*!< usb clock use hick */
USB_CLK_HEXT /*!< usb clock use hext */
}usb_clk48_s;
/**
* @}
*/
/** @defgroup USB_exported_types
* @{
*/
/**
* @brief usb endpoint infomation structure definition
*/
typedef struct
{
uint8_t eptn; /*!< endpoint register number (0~7) */
uint8_t ept_address; /*!< endpoint address */
uint8_t inout; /*!< endpoint dir EPT_DIR_IN or EPT_DIR_OUT */
uint8_t trans_type; /*!< endpoint type:
EPT_CONTROL_TYPE, EPT_BULK_TYPE, EPT_INT_TYPE, EPT_ISO_TYPE*/
uint16_t tx_addr; /*!< endpoint tx buffer offset address */
uint16_t rx_addr; /*!< endpoint rx buffer offset address */
uint32_t maxpacket; /*!< endpoint max packet*/
uint8_t is_double_buffer; /*!< endpoint double buffer flag */
uint8_t stall; /*!< endpoint is stall state */
uint32_t status;
/* transmission buffer and count */
uint8_t *trans_buf; /*!< endpoint transmission buffer */
uint32_t total_len; /*!< endpoint transmission lengtg */
uint32_t trans_len; /*!< endpoint transmission length*/
uint32_t last_len; /*!< last transfer length */
uint32_t rem0_len; /*!< rem transfer length */
uint32_t ept0_slen; /*!< endpoint 0 transfer sum length */
} usb_ept_info;
/**
* @brief usb host channel infomation structure definition
*/
typedef struct
{
uint8_t ch_num; /*!< host channel number */
uint8_t address; /*!< device address */
uint8_t dir; /*!< transmission direction */
uint8_t ept_num; /*!< device endpoint number */
uint8_t ept_type; /*!< channel transmission type */
uint32_t maxpacket; /*!< support max packet size */
uint8_t data_pid; /*!< data pid */
uint8_t speed; /*!< usb speed */
uint8_t stall; /*!< channel stall flag */
uint32_t status; /*!< channel status */
uint32_t state; /*!< channel state */
uint32_t urb_sts; /*!< usb channel request block state */
uint8_t toggle_in; /*!< channel in transfer toggle */
uint8_t toggle_out; /*!< channel out transfer toggle */
/* transmission buffer and count */
uint8_t *trans_buf; /* host channel buffer */
uint32_t trans_len; /* host channel transmission len */
uint32_t trans_count; /* host channel transmission count*/
} usb_hch_type;
typedef struct
{
/**
* @brief otgfs control and status register, offset:0x00
*/
union
{
__IO uint32_t gotgctrl;
struct
{
__IO uint32_t reserved1 : 16; /* [15:0] */
__IO uint32_t cidsts : 1; /* [16] */
__IO uint32_t reserved2 : 4; /* [20:17] */
__IO uint32_t curmod : 1; /* [21] */
__IO uint32_t reserved3 : 10; /* [31:22] */
} gotgctrl_bit;
};
/**
* @brief otgfs interrupt register, offset:0x04
*/
union
{
__IO uint32_t gotgint;
struct
{
__IO uint32_t reserved1 : 2; /* [1:0] */
__IO uint32_t sesenddet : 1; /* [2] */
__IO uint32_t reserved2 : 29; /* [31:3] */
} gotgint_bit;
};
/**
* @brief otgfs gahbcfg configuration register, offset:0x08
*/
union
{
__IO uint32_t gahbcfg;
struct
{
__IO uint32_t glbintmsk : 1; /* [0] */
__IO uint32_t reserved1 : 6; /* [6:1] */
__IO uint32_t nptxfemplvl : 1; /* [7] */
__IO uint32_t ptxfemplvl : 1; /* [8] */
__IO uint32_t reserved2 : 23; /* [31:9] */
} gahbcfg_bit;
};
/**
* @brief otgfs usb configuration register, offset:0x0C
*/
union
{
__IO uint32_t gusbcfg;
struct
{
__IO uint32_t toutcal : 3; /* [2:0] */
__IO uint32_t reserved1 : 7; /* [9:3] */
__IO uint32_t usbtrdtim : 4; /* [13:10] */
__IO uint32_t reserved2 : 15; /* [28:14] */
__IO uint32_t fhstmode : 1; /* [29] */
__IO uint32_t fdevmode : 1; /* [30] */
__IO uint32_t cotxpkt : 1; /* [31] */
} gusbcfg_bit;
};
/**
* @brief otgfs reset register, offset:0x10
*/
union
{
__IO uint32_t grstctl;
struct
{
__IO uint32_t csftrst : 1; /* [0] */
__IO uint32_t piusftrst : 1; /* [1] */
__IO uint32_t frmcntrst : 1; /* [2] */
__IO uint32_t reserved1 : 1; /* [3] */
__IO uint32_t rxfflsh : 1; /* [4] */
__IO uint32_t txfflsh : 1; /* [5] */
__IO uint32_t txfnum : 5; /* [10:6] */
__IO uint32_t reserved2 : 20; /* [30:11] */
__IO uint32_t ahbidle : 1; /* [31] */
} grstctl_bit;
};
/**
* @brief otgfs core interrupt register, offset:0x14
*/
union
{
__IO uint32_t gintsts;
struct
{
__IO uint32_t curmode : 1; /* [0] */
__IO uint32_t modemis : 1; /* [1] */
__IO uint32_t otgint : 1; /* [2] */
__IO uint32_t sof : 1; /* [3] */
__IO uint32_t rxflvl : 1; /* [4] */
__IO uint32_t nptxfemp : 1; /* [5] */
__IO uint32_t ginnakeff : 1; /* [6] */
__IO uint32_t goutnakeff : 1; /* [7] */
__IO uint32_t reserved1 : 2; /* [9:8]] */
__IO uint32_t erlysusp : 1; /* [10] */
__IO uint32_t usbsusp : 1; /* [11] */
__IO uint32_t usbrst : 1; /* [12] */
__IO uint32_t enumdone : 1; /* [13] */
__IO uint32_t isooutdrop : 1; /* [14] */
__IO uint32_t eopf : 1; /* [15] */
__IO uint32_t reserved2 : 2; /* [17:16]] */
__IO uint32_t ieptint : 1; /* [18] */
__IO uint32_t oeptint : 1; /* [19] */
__IO uint32_t incompisoin : 1; /* [20] */
__IO uint32_t incompip_incompisoout : 1; /* [21] */
__IO uint32_t reserved3 : 2; /* [23:22] */
__IO uint32_t prtint : 1; /* [24] */
__IO uint32_t hchint : 1; /* [25] */
__IO uint32_t ptxfemp : 1; /* [26] */
__IO uint32_t reserved4 : 1; /* [27] */
__IO uint32_t conidschg : 1; /* [28] */
__IO uint32_t disconint : 1; /* [29] */
__IO uint32_t reserved5 : 1; /* [30] */
__IO uint32_t wkupint : 1; /* [31] */
} gintsts_bit;
};
/**
* @brief otgfs interrupt mask register, offset:0x18
*/
union
{
__IO uint32_t gintmsk;
struct
{
__IO uint32_t reserved1 : 1; /* [0] */
__IO uint32_t modemismsk : 1; /* [1] */
__IO uint32_t otgintmsk : 1; /* [2] */
__IO uint32_t sofmsk : 1; /* [3] */
__IO uint32_t rxflvlmsk : 1; /* [4] */
__IO uint32_t nptxfempmsk : 1; /* [5] */
__IO uint32_t ginnakeffmsk : 1; /* [6] */
__IO uint32_t goutnakeffmsk : 1; /* [7] */
__IO uint32_t reserved2 : 2; /* [9:8]] */
__IO uint32_t erlysuspmsk : 1; /* [10] */
__IO uint32_t usbsuspmsk : 1; /* [11] */
__IO uint32_t usbrstmsk : 1; /* [12] */
__IO uint32_t enumdonemsk : 1; /* [13] */
__IO uint32_t isooutdropmsk : 1; /* [14] */
__IO uint32_t eopfmsk : 1; /* [15] */
__IO uint32_t reserved3 : 2; /* [17:16]] */
__IO uint32_t ieptintmsk : 1; /* [18] */
__IO uint32_t oeptintmsk : 1; /* [19] */
__IO uint32_t incompisoinmsk : 1; /* [20] */
__IO uint32_t incompip_incompisooutmsk : 1; /* [21] */
__IO uint32_t reserved4 : 2; /* [23:22] */
__IO uint32_t prtintmsk : 1; /* [24] */
__IO uint32_t hchintmsk : 1; /* [25] */
__IO uint32_t ptxfempmsk : 1; /* [26] */
__IO uint32_t reserved5 : 1; /* [27] */
__IO uint32_t conidschgmsk : 1; /* [28] */
__IO uint32_t disconintmsk : 1; /* [29] */
__IO uint32_t reserved6 : 1; /* [30] */
__IO uint32_t wkupintmsk : 1; /* [31] */
} gintmsk_bit;
};
/**
* @brief otgfs rx status debug read register, offset:0x1C
*/
union
{
__IO uint32_t grxstsr;
struct
{
__IO uint32_t eptnum : 4; /* [3:0] */
__IO uint32_t bcnt : 11; /* [14:4] */
__IO uint32_t dpid : 2; /* [16:15] */
__IO uint32_t pktsts : 4; /* [20:17] */
__IO uint32_t fn : 4; /* [24:21] */
__IO uint32_t reserved1 : 7; /* [31:25] */
} grxstsr_bit;
};
/**
* @brief otgfs rx status read and pop register, offset:0x20
*/
union
{
__IO uint32_t grxstsp;
struct
{
__IO uint32_t chnum : 4; /* [3:0] */
__IO uint32_t bcnt : 11; /* [14:4] */
__IO uint32_t dpid : 2; /* [16:15] */
__IO uint32_t pktsts : 4; /* [20:17] */
__IO uint32_t reserved1 : 11; /* [31:21] */
} grxstsp_bit;
};
/**
* @brief otgfs rx fifo size register, offset:0x24
*/
union
{
__IO uint32_t grxfsiz;
struct
{
__IO uint32_t rxfdep : 16; /* [15:0] */
__IO uint32_t reserved1 : 16; /* [31:16] */
} grxfsiz_bit;
};
/**
* @brief otgfs non-periodic and ept0 tx fifo size register, offset:0x28
*/
union
{
__IO uint32_t gnptxfsiz_ept0tx;
struct
{
__IO uint32_t nptxfstaddr : 16; /* [15:0] */
__IO uint32_t nptxfdep : 16; /* [31:16] */
} gnptxfsiz_ept0tx_bit;
};
/**
* @brief otgfs non-periodic tx fifo request queue status register, offset:0x2C
*/
union
{
__IO uint32_t gnptxsts;
struct
{
__IO uint32_t nptxfspcavail : 16; /* [15:0] */
__IO uint32_t nptxqspcavail : 8; /* [23:16] */
__IO uint32_t nptxqtop : 7; /* [30:24] */
} gnptxsts_bit;
};
__IO uint32_t reserved2[2];
/**
* @brief otgfs general core configuration register, offset:0x38
*/
union
{
__IO uint32_t gccfg;
struct
{
__IO uint32_t reserved1 : 16; /* [15:0] */
__IO uint32_t pwrdown : 1; /* [16] */
__IO uint32_t lp_mode : 1; /* [17] */
__IO uint32_t reserved2 : 2; /* [19:18] */
__IO uint32_t sofouten : 1; /* [20] */
__IO uint32_t vbusig : 1; /* [21] */
__IO uint32_t reserved3 : 10; /* [31:22] */
} gccfg_bit;
};
/**
* @brief otgfs core id register, offset:0x3C
*/
union
{
__IO uint32_t guid;
struct
{
__IO uint32_t userid : 32; /* [31:0] */
} guid_bit;
};
__IO uint32_t reserved3[48];
/**
* @brief otgfs host periodic tx fifo size register, offset:0x100
*/
union
{
__IO uint32_t hptxfsiz;
struct
{
__IO uint32_t ptxfstaddr : 16; /* [15:0] */
__IO uint32_t ptxfsize : 16; /* [31:16] */
} hptxfsiz_bit;
};
/**
* @brief otgfs host periodic tx fifo size register, offset:0x100
*/
union
{
__IO uint32_t dieptxfn[7];
struct
{
__IO uint32_t ineptxfstaddr : 16; /* [15:0] */
__IO uint32_t ineptxfdep : 16; /* [31:16] */
} dieptxfn_bit[7];
};
} otg_global_type;
typedef struct
{
/**
* @brief otgfs host mode configuration register, offset:0x400
*/
union
{
__IO uint32_t hcfg;
struct
{
__IO uint32_t fslspclksel : 2; /* [1:0] */
__IO uint32_t fslssupp : 1; /* [2] */
__IO uint32_t reserved1 : 29; /* [31:3] */
} hcfg_bit;
};
/**
* @brief otgfs host frame interval register, offset:0x404
*/
union
{
__IO uint32_t hfir;
struct
{
__IO uint32_t frint : 16; /* [15:0] */
__IO uint32_t reserved1 : 16; /* [31:15] */
} hfir_bit;
};
/**
* @brief otgfs host frame number and time remaining register, offset:0x408
*/
union
{
__IO uint32_t hfnum;
struct
{
__IO uint32_t frnum : 16; /* [15:0] */
__IO uint32_t ftrem : 16; /* [31:15] */
} hfnum_bit;
};
__IO uint32_t reserved1;
/**
* @brief otgfs host periodic tx fifo request queue register, offset:0x410
*/
union
{
__IO uint32_t hptxsts;
struct
{
__IO uint32_t ptxfspcavil : 16; /* [15:0] */
__IO uint32_t ptxqspcavil : 8; /* [23:16] */
__IO uint32_t ptxqtop : 8; /* [31:24] */
} hptxsts_bit;
};
/**
* @brief otgfs host all channel interrupt register, offset:0x414
*/
union
{
__IO uint32_t haint;
struct
{
__IO uint32_t haint : 16; /* [15:0] */
__IO uint32_t reserved1 : 16; /* [32:16] */
} haint_bit;
};
/**
* @brief otgfs host all channel interrupt mask register, offset:0x418
*/
union
{
__IO uint32_t haintmsk;
struct
{
__IO uint32_t haintmsk : 16; /* [15:0] */
__IO uint32_t reserved1 : 16; /* [32:16] */
} haintmsk_bit;
};
__IO uint32_t reserved2[9];
/**
* @brief otgfs host port control and status register, offset:0x440
*/
union
{
__IO uint32_t hprt;
struct
{
__IO uint32_t prtconsts : 1; /* [0] */
__IO uint32_t prtcondet : 1; /* [1] */
__IO uint32_t prtena : 1; /* [2] */
__IO uint32_t prtenchng : 1; /* [3] */
__IO uint32_t prtovrcact : 1; /* [4] */
__IO uint32_t prtovrcchng : 1; /* [5] */
__IO uint32_t prtres : 1; /* [6] */
__IO uint32_t prtsusp : 1; /* [7] */
__IO uint32_t prtrst : 1; /* [8] */
__IO uint32_t reserved1 : 1; /* [9] */
__IO uint32_t prtlnsts : 2; /* [11:10] */
__IO uint32_t prtpwr : 1; /* [12] */
__IO uint32_t prttsctl : 4; /* [16:13] */
__IO uint32_t prtspd : 2; /* [18:17] */
__IO uint32_t reserved2 : 13; /* [31:19] */
} hprt_bit;
};
} otg_host_type;
typedef struct
{
/**
* @brief otgfs host channel x characterisic register, offset:0x500
*/
union
{
__IO uint32_t hcchar;
struct
{
__IO uint32_t mps : 11; /* [10:0] */
__IO uint32_t eptnum : 4; /* [14:11] */
__IO uint32_t eptdir : 1; /* [15] */
__IO uint32_t reserved1 : 1; /* [16] */
__IO uint32_t lspddev : 1; /* [17] */
__IO uint32_t eptype : 2; /* [19:18] */
__IO uint32_t mc : 2; /* [21:20] */
__IO uint32_t devaddr : 7; /* [28:22] */
__IO uint32_t oddfrm : 1; /* [29] */
__IO uint32_t chdis : 1; /* [30] */
__IO uint32_t chena : 1; /* [31] */
} hcchar_bit;
};
/**
* @brief otgfs host channel split control register, offset:0x504
*/
union
{
__IO uint32_t hcsplt;
struct
{
__IO uint32_t prtaddr : 7; /* [6:0] */
__IO uint32_t hubaddr : 7; /* [13:7] */
__IO uint32_t xactpos : 2; /* [15:14] */
__IO uint32_t compsplt : 1; /* [16] */
__IO uint32_t reserved1 : 14; /* [30:17] */
__IO uint32_t spltena : 1; /* [31] */
} hcsplt_bit;
};
/**
* @brief otgfs host channel interrupt register, offset:0x508
*/
union
{
__IO uint32_t hcint;
struct
{
__IO uint32_t xferc : 1; /* [0] */
__IO uint32_t chhltd : 1; /* [1] */
__IO uint32_t reserved1 : 1; /* [2] */
__IO uint32_t stall : 1; /* [3] */
__IO uint32_t nak : 1; /* [4] */
__IO uint32_t ack : 1; /* [5] */
__IO uint32_t reserved2 : 1; /* [6] */
__IO uint32_t xacterr : 1; /* [7] */
__IO uint32_t bblerr : 1; /* [8] */
__IO uint32_t frmovrun : 1; /* [9] */
__IO uint32_t dtglerr : 1; /* [10] */
__IO uint32_t reserved3 : 21; /* [31:11] */
} hcint_bit;
};
/**
* @brief otgfs host channel interrupt mask register, offset:0x50C
*/
union
{
__IO uint32_t hcintmsk;
struct
{
__IO uint32_t xfercmsk : 1; /* [0] */
__IO uint32_t chhltdmsk : 1; /* [1] */
__IO uint32_t reserved1 : 1; /* [2] */
__IO uint32_t stallmsk : 1; /* [3] */
__IO uint32_t nakmsk : 1; /* [4] */
__IO uint32_t ackmsk : 1; /* [5] */
__IO uint32_t reserved2 : 1; /* [6] */
__IO uint32_t xacterrmsk : 1; /* [7] */
__IO uint32_t bblerrmsk : 1; /* [8] */
__IO uint32_t frmovrunmsk : 1; /* [9] */
__IO uint32_t dtglerrmsk : 1; /* [10] */
__IO uint32_t reserved3 : 21; /* [31:11] */
} hcintmsk_bit;
};
/**
* @brief otgfs host channel transfer size register, offset:0x510
*/
union
{
__IO uint32_t hctsiz;
struct
{
__IO uint32_t xfersize : 19; /* [18:0] */
__IO uint32_t pktcnt : 10; /* [28:19] */
__IO uint32_t pid : 2; /* [30:29] */
__IO uint32_t reserved1 : 1; /* [31] */
} hctsiz_bit;
};
__IO uint32_t reserved3[3];
}otg_hchannel_type;
typedef struct
{
/**
* @brief otgfs device configuration register, offset:0x800
*/
union
{
__IO uint32_t dcfg;
struct
{
__IO uint32_t devspd : 2; /* [1:0] */
__IO uint32_t nzstsouthshk : 1; /* [2] */
__IO uint32_t reserved1 : 1; /* [3] */
__IO uint32_t devaddr : 7; /* [10:4] */
__IO uint32_t perfrint : 2; /* [12:11] */
__IO uint32_t reserved2 : 19; /* [31:13] */
} dcfg_bit;
};
/**
* @brief otgfs device controls register, offset:0x804
*/
union
{
__IO uint32_t dctl;
struct
{
__IO uint32_t rwkupsig : 1; /* [0] */
__IO uint32_t sftdiscon : 1; /* [1] */
__IO uint32_t gnpinnaksts : 1; /* [2] */
__IO uint32_t goutnaksts : 1; /* [3] */
__IO uint32_t tstctl : 3; /* [6:4] */
__IO uint32_t sgnpinak : 1; /* [7] */
__IO uint32_t cgnpinak : 1; /* [8] */
__IO uint32_t sgoutnak : 1; /* [9] */
__IO uint32_t cgoutnak : 1; /* [10] */
__IO uint32_t pwroprgdne : 1; /* [11] */
__IO uint32_t reserved1 : 20; /* [31:12] */
} dctl_bit;
};
/**
* @brief otgfs device status register, offset:0x80C
*/
union
{
__IO uint32_t dsts;
struct
{
__IO uint32_t suspsts : 1; /* [0] */
__IO uint32_t enumspd : 2; /* [2:1] */
__IO uint32_t eticerr : 1; /* [3] */
__IO uint32_t reserved1 : 4; /* [7:4] */
__IO uint32_t soffn : 14; /* [21:8] */
__IO uint32_t reserved2 : 10; /* [31:22] */
} dsts_bit;
};
__IO uint32_t reserved1;
/**
* @brief otgfs device in endpoint general interrupt mask register, offset:0x810
*/
union
{
__IO uint32_t diepmsk;
struct
{
__IO uint32_t xfercmsk : 1; /* [0] */
__IO uint32_t eptdismsk : 1; /* [1] */
__IO uint32_t reserved1 : 1; /* [2] */
__IO uint32_t timeoutmsk : 1; /* [3] */
__IO uint32_t intkntxfempmsk : 1; /* [4] */
__IO uint32_t intkneptmismsk : 1; /* [5] */
__IO uint32_t ineptnakmsk : 1; /* [6] */
__IO uint32_t reserved2 : 1; /* [7] */
__IO uint32_t txfifoudrmsk : 1; /* [8] */
__IO uint32_t bnainmsk : 1; /* [9] */
__IO uint32_t reserved3 : 22; /* [31:10] */
} diepmsk_bit;
};
/**
* @brief otgfs device out endpoint general interrupt mask register, offset:0x814
*/
union
{
__IO uint32_t doepmsk;
struct
{
__IO uint32_t xfercmsk : 1; /* [0] */
__IO uint32_t eptdismsk : 1; /* [1] */
__IO uint32_t reserved1 : 1; /* [2] */
__IO uint32_t setupmsk : 1; /* [3] */
__IO uint32_t outtepdmsk : 1; /* [4] */
__IO uint32_t reserved2 : 1; /* [5] */
__IO uint32_t b2bsetupmsk : 1; /* [6] */
__IO uint32_t reserved3 : 1; /* [7] */
__IO uint32_t outperrmsk : 1; /* [8] */
__IO uint32_t bnaoutmsk : 1; /* [9] */
__IO uint32_t reserved4 : 22; /* [31:10] */
} doepmsk_bit;
};
/**
* @brief otgfs device all endpoint interrupt register, offset:0x818
*/
union
{
__IO uint32_t daint;
struct
{
__IO uint32_t ineptint : 16; /* [15:0] */
__IO uint32_t outeptint : 16; /* [31:16] */
} daint_bit;
};
/**
* @brief otgfs device all endpoint interrupt mask register, offset:0x81C
*/
union
{
__IO uint32_t daintmsk;
struct
{
__IO uint32_t ineptmsk : 16; /* [15:0] */
__IO uint32_t outeptmsk : 16; /* [31:16] */
} daintmsk_bit;
};
__IO uint32_t reserved2[5];
/**
* @brief otgfs device in endpoint fifo empty interrupt mask register, offset:0x834
*/
union
{
__IO uint32_t diepempmsk;
struct
{
__IO uint32_t ineptxfemsk : 16; /* [15:0] */
__IO uint32_t reserved1 : 16; /* [31:16] */
} diepempmsk_bit;
};
} otg_device_type;
typedef struct
{
/**
* @brief otgfs device out endpoint control register, offset:0x900
*/
union
{
__IO uint32_t diepctl;
struct
{
__IO uint32_t mps : 11; /* [10:0] */
__IO uint32_t reserved1 : 4; /* [14:11] */
__IO uint32_t usbacept : 1; /* [15] */
__IO uint32_t dpid : 1; /* [16] */
__IO uint32_t naksts : 1; /* [17] */
__IO uint32_t eptype : 2; /* [19:18] */
__IO uint32_t reserved2 : 1; /* [20] */
__IO uint32_t stall : 1; /* [21] */
__IO uint32_t txfnum : 4; /* [25:22] */
__IO uint32_t cnak : 1; /* [26] */
__IO uint32_t snak : 1; /* [27] */
__IO uint32_t setd0pid : 1; /* [28] */
__IO uint32_t setd1pid : 1; /* [29] */
__IO uint32_t eptdis : 1; /* [30] */
__IO uint32_t eptena : 1; /* [31] */
} diepctl_bit;
};
__IO uint32_t reserved1;
/**
* @brief otgfs device in endpoint interrupt register, offset:0x908
*/
union
{
__IO uint32_t diepint;
struct
{
__IO uint32_t xferc : 1; /* [0] */
__IO uint32_t epdisd : 1; /* [1] */
__IO uint32_t reserved1 : 1; /* [2] */
__IO uint32_t timeout : 1; /* [3] */
__IO uint32_t intkntxfemp : 1; /* [4] */
__IO uint32_t reserved2 : 1; /* [5] */
__IO uint32_t ineptnak : 1; /* [6] */
__IO uint32_t txfemp : 1; /* [7] */
__IO uint32_t reserved3 : 24; /* [31:8] */
} diepint_bit;
};
__IO uint32_t reserved2;
/**
* @brief otgfs device in endpoint transfer size register, offset:0x910 + endpoint number * 0x20
*/
union
{
__IO uint32_t dieptsiz;
struct
{
__IO uint32_t xfersize : 19; /* [18:0] */
__IO uint32_t pktcnt : 10; /* [28:19] */
__IO uint32_t mc : 2; /* [30:29] */
__IO uint32_t reserved1 : 1; /* [31] */
} dieptsiz_bit;
};
__IO uint32_t reserved3;
/**
* @brief otgfs device in endpoint tx fifo status register, offset:0x918 + endpoint number * 0x20
*/
union
{
__IO uint32_t dtxfsts;
struct
{
__IO uint32_t ineptxfsav : 16; /* [15:0] */
__IO uint32_t reserved1 : 16; /* [31:16] */
} dtxfsts_bit;
};
} otg_eptin_type;
typedef struct
{
/**
* @brief otgfs device out endpoint control register, offset:0xb00 + endpoint number * 0x20
*/
union
{
__IO uint32_t doepctl;
struct
{
__IO uint32_t mps : 11; /* [10:0] */
__IO uint32_t reserved1 : 4; /* [14:11] */
__IO uint32_t usbacept : 1; /* [15] */
__IO uint32_t dpid : 1; /* [16] */
__IO uint32_t naksts : 1; /* [17] */
__IO uint32_t eptype : 2; /* [19:18] */
__IO uint32_t snpm : 1; /* [20] */
__IO uint32_t stall : 1; /* [21] */
__IO uint32_t reserved2 : 4; /* [25:22] */
__IO uint32_t cnak : 1; /* [26] */
__IO uint32_t snak : 1; /* [27] */
__IO uint32_t setd0pid : 1; /* [28] */
__IO uint32_t setd1pid : 1; /* [29] */
__IO uint32_t eptdis : 1; /* [30] */
__IO uint32_t eptena : 1; /* [31] */
} doepctl_bit;
};
__IO uint32_t reserved1;
/**
* @brief otgfs device out endpoint interrupt register, offset:0xb08 + endpoint number * 0x20
*/
union
{
__IO uint32_t doepint;
struct
{
__IO uint32_t xferc : 1; /* [0] */
__IO uint32_t epdisd : 1; /* [1] */
__IO uint32_t reserved1 : 1; /* [2] */
__IO uint32_t setup : 1; /* [3] */
__IO uint32_t outtepd : 1; /* [4] */
__IO uint32_t reserved2 : 1; /* [5] */
__IO uint32_t b2pstup : 1; /* [6] */
__IO uint32_t reserved3 : 25; /* [31:7] */
} doepint_bit;
};
__IO uint32_t reserved2;
/**
* @brief otgfs device out endpoint transfer size register, offset:0xb10 + endpoint number * 0x20
*/
union
{
__IO uint32_t doeptsiz;
struct
{
__IO uint32_t xfersize : 19; /* [18:0] */
__IO uint32_t pktcnt : 10; /* [28:19] */
__IO uint32_t rxdpid_setupcnt : 2; /* [30:29] */
__IO uint32_t reserved1 : 1; /* [31] */
} doeptsiz_bit;
};
} otg_eptout_type;
typedef struct
{
/**
* @brief otgfs power and clock gating control registers, offset:0xe00
*/
union
{
__IO uint32_t pcgcctl;
struct
{
__IO uint32_t stoppclk : 1; /* [0] */
__IO uint32_t reserved1 : 3; /* [3:1] */
__IO uint32_t suspendm : 1; /* [4] */
__IO uint32_t reserved2 : 27; /* [31:5] */
} pcgcctl_bit;
};
} otg_pcgcctl_type;
/**
* @}
*/
/** @defgroup USB_exported_functions
* @{
*/
/**
* @brief usb host and device offset address
*/
#define OTG_HOST_ADDR_OFFSET 0x400 /*!< usb host register offset address */
#define OTG_HOST_CHANNEL_ADDR_OFFSET 0x500 /*!< usb host channel register offset address */
#define OTG_DEVICE_ADDR_OFFSET 0x800 /*!< usb device register offset address */
#define OTG_DEVICE_EPTIN_ADDR_OFFSET 0x900 /*!< usb device endpoint in register offset address */
#define OTG_DEVICE_EPTOUT_ADDR_OFFSET 0xB00 /*!< usb device endpoint out register offset address */
#define OTG_PCGCCTL_ADDR_OFFSET 0xE00 /*!< usb power and clock control register offset address */
#define OTG_FIFO_ADDR_OFFSET 0x1000 /*!< usb fifo offset address */
/**
* @brief usb host and device register define
*/
#define OTG1_GLOBAL ((otg_global_type *)(OTGFS1_BASE)) /*!< usb otg1 global register */
#define OTG_PCGCCTL(usbx) ((otg_pcgcctl_type *)((uint32_t)usbx + OTG_PCGCCTL_ADDR_OFFSET)) /*!< usb power and clock control register */
#define OTG_DEVICE(usbx) ((otg_device_type *)((uint32_t)usbx + OTG_DEVICE_ADDR_OFFSET)) /*!< usb device register */
#define OTG_HOST(usbx) ((otg_host_type *)((uint32_t)usbx + OTG_HOST_ADDR_OFFSET)) /*!< usb host register */
#define USB_CHL(usbx, n) ((otg_hchannel_type *)((uint32_t)usbx + OTG_HOST_CHANNEL_ADDR_OFFSET + n * 0x20)) /*!< usb channel n register */
#define USB_INEPT(usbx, eptn) ((otg_eptin_type *)((uint32_t)usbx + OTG_DEVICE_EPTIN_ADDR_OFFSET + eptn * 0x20)) /*!< usb device endpoint in register */
#define USB_OUTEPT(usbx, eptn) ((otg_eptout_type *)((uint32_t)usbx + OTG_DEVICE_EPTOUT_ADDR_OFFSET + eptn * 0x20)) /*!< usb device endpoint out register */
#define USB_FIFO(usbx, eptn) *(__IO uint32_t *)((uint32_t)usbx + OTG_FIFO_ADDR_OFFSET + eptn * 0x1000) /*!< usb fifo address */
typedef otg_global_type usb_reg_type;
/** @defgroup USB_exported_functions
* @{
*/
#ifdef OTGFS_USB_GLOBAL
error_status usb_global_reset(otg_global_type *usbx);
void usb_global_init(otg_global_type *usbx);
otg_global_type *usb_global_select_core(uint8_t usb_id);
void usb_flush_tx_fifo(otg_global_type *usbx, uint32_t fifo_num);
void usb_flush_rx_fifo(otg_global_type *usbx);
void usb_global_interrupt_enable(otg_global_type *usbx, uint16_t interrupt, confirm_state new_state);
uint32_t usb_global_get_all_interrupt(otg_global_type *usbx);
void usb_global_clear_interrupt(otg_global_type *usbx, uint32_t flag);
void usb_interrupt_enable(otg_global_type *usbx);
void usb_interrupt_disable(otg_global_type *usbx);
void usb_set_rx_fifo(otg_global_type *usbx, uint16_t size);
void usb_set_tx_fifo(otg_global_type *usbx, uint8_t txfifo, uint16_t size);
void usb_global_set_mode(otg_global_type *usbx, uint32_t mode);
void usb_global_power_on(otg_global_type *usbx);
void usb_write_packet(otg_global_type *usbx, uint8_t *pusr_buf, uint16_t num, uint16_t nbytes);
void usb_read_packet(otg_global_type *usbx, uint8_t *pusr_buf, uint16_t num, uint16_t nbytes);
void usb_stop_phy_clk(otg_global_type *usbx);
void usb_open_phy_clk(otg_global_type *usbx);
#endif
#ifdef OTGFS_USB_DEVICE
void usb_ept_open(otg_global_type *usbx, usb_ept_info *ept_info);
void usb_ept_close(otg_global_type *usbx, usb_ept_info *ept_info);
void usb_ept_stall(otg_global_type *usbx, usb_ept_info *ept_info);
void usb_ept_clear_stall(otg_global_type *usbx, usb_ept_info *ept_info);
uint32_t usb_get_all_out_interrupt(otg_global_type *usbx);
uint32_t usb_get_all_in_interrupt(otg_global_type *usbx);
uint32_t usb_ept_out_interrupt(otg_global_type *usbx, uint32_t eptn);
uint32_t usb_ept_in_interrupt(otg_global_type *usbx, uint32_t eptn);
void usb_ept_out_clear(otg_global_type *usbx, uint32_t eptn, uint32_t flag);
void usb_ept_in_clear(otg_global_type *usbx, uint32_t eptn, uint32_t flag);
void usb_set_address(otg_global_type *usbx, uint8_t address);
void usb_ept0_start(otg_global_type *usbx);
void usb_ept0_setup(otg_global_type *usbx);
void usb_connect(otg_global_type *usbx);
void usb_disconnect(otg_global_type *usbx);
void usb_remote_wkup_set(otg_global_type *usbx);
void usb_remote_wkup_clear(otg_global_type *usbx);
uint8_t usb_suspend_status_get(otg_global_type *usbx);
#endif
#ifdef OTGFS_USB_HOST
void usb_port_power_on(otg_global_type *usbx, confirm_state state);
uint32_t usbh_get_frame(otg_global_type *usbx);
void usb_hc_enable(otg_global_type *usbx,
uint8_t chn,
uint8_t ept_num,
uint8_t dev_address,
uint8_t type,
uint16_t maxpacket,
uint8_t speed);
uint32_t usb_hch_read_interrupt(otg_global_type *usbx);
void usb_host_disable(otg_global_type *usbx);
void usb_hch_halt(otg_global_type *usbx, uint8_t chn);
void usbh_fsls_clksel(otg_global_type *usbx, uint8_t clk);
#endif
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif
|
a1bf370e06a52f34f320b06bd237c0c2621abcd8
|
ff12147907a0100a7ec648c23c36c11ab15beb11
|
/args.h
|
902cffa064a86459037b7c26d9589379a67ed2a8
|
[
"Apache-2.0"
] |
permissive
|
YJBeetle/unnpk
|
5d78450f0819b70a10979f179293c0e5791b6a51
|
e99784f9ddfb988270afa3611d2f4c77b3d36ab3
|
refs/heads/master
| 2022-02-24T22:09:25.570890
| 2022-02-12T08:20:49
| 2022-02-12T08:20:49
| 108,890,634
| 240
| 90
|
Apache-2.0
| 2020-07-18T10:28:50
| 2017-10-30T18:19:13
|
C
|
UTF-8
|
C
| false
| false
| 434
|
h
|
args.h
|
#ifndef ARGS_H
#define ARGS_H
enum FORMAT{
MARKDOWN,
CSV
};
enum TYPE{
HEX,
INT,
ORIGINAL
};
struct argsdata
{
char * in_filename;
char * out_filename;
enum FORMAT format;
enum TYPE type;
};
typedef struct argsdata argsdata;
void args_init(argsdata * data);
void args_help(const char *argv0);
void args_usage(const char *argv0);
void args_parse(int argc, char *argv[], argsdata * data);
#endif // ARGS_H
|
aa6745c4bd9627a12b57a2a102fb4bee99fc6c15
|
35c04ea32351dc95bc18d46e5c70dda9c1e08668
|
/Examples/CodeWarrior.S12v5.1/TWR-S12G240/TWR-S12G240_FreeRTOS/CODE/port.c
|
8f7580a23fbd0daee0ba1b2a1f385994bfdd387b
|
[
"LicenseRef-scancode-warranty-disclaimer",
"MIT"
] |
permissive
|
ErichStyger/mcuoneclipse
|
0f8e7a2056a26ed79d9d4a0afd64777ff0b2b2fe
|
04ad311b11860ae5f8285316010961a87fa06d0c
|
refs/heads/master
| 2023-08-28T22:54:08.501719
| 2023-08-25T15:11:44
| 2023-08-25T15:11:44
| 7,446,094
| 620
| 1,191
|
NOASSERTION
| 2020-10-16T03:13:28
| 2013-01-04T19:38:12
|
Batchfile
|
UTF-8
|
C
| false
| false
| 67,396
|
c
|
port.c
|
/*
* FreeRTOS Kernel V10.0.1
* Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://www.FreeRTOS.org
* http://aws.amazon.com/freertos
*
* 1 tab == 4 spaces!
*/
/*-----------------------------------------------------------
* FreeRTOS for 56800EX port by Richy Ye in Jan. 2013.
*----------------------------------------------------------*/
/* Scheduler includes. */
#include "FreeRTOS.h"
#include "portmacro.h" /* for configCPU_FAMILY */
#include "task.h"
#include "portTicks.h" /* for CPU_CORE_CLK_HZ used in configSYSTICK_CLOCK_HZ */
#if configSYSTICK_USE_LOW_POWER_TIMER
#if MCUC1_CONFIG_NXP_SDK_2_0_USED
#include "fsl_lptmr.h" /* SDK low power timer interface */
#elif MCUC1_CONFIG_SDK_VERSION_USED == MCUC1_CONFIG_SDK_PROCESSOR_EXPERT
#include "LPTMR_PDD.h" /* PDD interface to low power timer */
#include "SIM_PDD.h" /* PDD interface to system integration module */
#endif
#endif
#include "MCUC1.h" /* include SDK and API used */
/* --------------------------------------------------- */
/* Let the user override the pre-loading of the initial LR with the address of
prvTaskExitError() in case is messes up unwinding of the stack in the
debugger. */
#ifdef configTASK_RETURN_ADDRESS
#define portTASK_RETURN_ADDRESS configTASK_RETURN_ADDRESS
#else
#define portTASK_RETURN_ADDRESS prvTaskExitError
#endif
/* --------------------------------------------------- */
/* macros dealing with tick counter */
#define ENABLE_TICK_COUNTER() (void)TickCntr1_Enable()
#define DISABLE_TICK_COUNTER() (void)TickCntr1_Disable()
#define RESET_TICK_COUNTER_VAL() /* WARNING: not possible to reset tick timer! */
#define TICK_NOF_BITS 16
#define COUNTS_UP TickCntr1_UP_COUNTER
typedef TickCntr1_TTimerValue TickCounter_t; /* for holding counter */
#if configUSE_TICKLESS_IDLE == 1
static TickCounter_t currTickDuration; /* holds the modulo counter/tick duration as no API to get it from the FreeCntr component */
#endif
#define SET_TICK_DURATION(val) (void)TickCntr1_SetCompare((TickCntr1_TTimerValue)(val)); currTickDuration=(TickCounter_t)(val)
#define GET_TICK_DURATION() currTickDuration
#define GET_TICK_CURRENT_VAL(addr) (void)TickCntr1_GetCounterValue(addr)
#if configSYSTICK_USE_LOW_POWER_TIMER
#define TIMER_COUNTS_FOR_ONE_TICK (configSYSTICK_LOW_POWER_TIMER_CLOCK_HZ/configTICK_RATE_HZ)
#else
#define TIMER_COUNTS_FOR_ONE_TICK (configSYSTICK_CLOCK_HZ/configTICK_RATE_HZ)
#endif
#if configUSE_SEGGER_SYSTEM_VIEWER_HOOKS && configCPU_FAMILY==configCPU_FAMILY_ARM_M0P
unsigned int SEGGER_SYSVIEW_TickCnt; /* tick counter for Segger SystemViewer */
#endif
#if configUSE_TICKLESS_IDLE
#define UL_TIMER_COUNTS_FOR_ONE_TICK ((TickCounter_t)(TIMER_COUNTS_FOR_ONE_TICK))
#if configCPU_FAMILY_IS_ARM(configCPU_FAMILY)
#define TICKLESS_DISABLE_INTERRUPTS() __asm volatile("cpsid i") /* disable interrupts. Note that the wfi (wait for interrupt) instruction later will still be able to wait for interrupts! */
#define TICKLESS_ENABLE_INTERRUPTS() __asm volatile("cpsie i") /* re-enable interrupts. */
#elif (configCPU_FAMILY==configCPU_FAMILY_S08) || (configCPU_FAMILY==configCPU_FAMILY_S12)
#define TICKLESS_DISABLE_INTERRUPTS() __asm("sei"); /* disable interrupts */
#define TICKLESS_ENABLE_INTERRUPTS() __asm("cli"); /* re-enable interrupts */
#else
#define TICKLESS_DISABLE_INTERRUPTS() portDISABLE_INTERRUPTS() /* this disables interrupts! Make sure they are re-enabled in vOnPreSleepProcessing()! */
#define TICKLESS_ENABLE_INTERRUPTS() portENABLE_INTERRUPTS() /* re-enable interrupts */
#endif
#if 0
#if configSYSTICK_USE_LOW_POWER_TIMER
/* using Low Power Timer */
#if CONFIG_PEX_SDK_USEDMCUC1_CONFIG_PEX_SDK_USED
#define LPTMR_CSR_TCF_MASK 0x80u
#define TICK_INTERRUPT_HAS_FIRED() (LPTMR0_BASE_PTR->CSR&LPTMR_CSR_TCF_MASK)!=0/*! \todo */ /* returns TRUE if tick interrupt had fired */
#else
#define TICK_INTERRUPT_HAS_FIRED() (LPTMR_PDD_GetInterruptFlag(LPTMR0_BASE_PTR)!=0) /* returns TRUE if tick interrupt had fired */
#endif
#define TICK_INTERRUPT_FLAG_RESET() /* not needed */
#define TICK_INTERRUPT_FLAG_SET() /* not needed */
#else
/* using directly SysTick Timer */
#define TICK_INTERRUPT_HAS_FIRED() ((portNVIC_SYSTICK_CTRL_REG&portNVIC_SYSTICK_COUNT_FLAG_BIT)!=0) /* returns TRUE if tick interrupt had fired */
#define TICK_INTERRUPT_FLAG_RESET() /* not needed */
#define TICK_INTERRUPT_FLAG_SET() /* not needed */
#endif
#else
/* using global variable to find out if interrupt has fired */
volatile uint8_t portTickCntr; /* used to find out if we woke up by the tick interrupt */
#define TICK_INTERRUPT_HAS_FIRED() (portTickCntr!=0) /* returns TRUE if tick interrupt had fired */
#define TICK_INTERRUPT_FLAG_RESET() portTickCntr=0
#define TICK_INTERRUPT_FLAG_SET() portTickCntr=1
#endif
#endif /* configUSE_TICKLESS_IDLE == 1 */
/*
* The maximum number of tick periods that can be suppressed is limited by the
* resolution of the tick timer.
*/
#if configUSE_TICKLESS_IDLE == 1
static TickCounter_t xMaximumPossibleSuppressedTicks = 0;
#endif /* configUSE_TICKLESS_IDLE */
/*
* Compensate for the CPU cycles that pass while the tick timer is stopped (low
* power functionality only).
*/
#if configUSE_TICKLESS_IDLE == 1
static TickCounter_t ulStoppedTimerCompensation = 0; /* number of timer ticks to compensate */
#define configSTOPPED_TIMER_COMPENSATION 45UL /* number of CPU cycles to compensate. ulStoppedTimerCompensation will contain the number of timer ticks. */
#endif /* configUSE_TICKLESS_IDLE */
/* Flag indicating that the tick counter interval needs to be restored back to
* the normal setting. Used when woken up from a low power mode using the LPTMR.
*/
#if configUSE_TICKLESS_IDLE && configSYSTICK_USE_LOW_POWER_TIMER
static uint8_t restoreTickInterval = 0; /* used to flag in tick ISR that compare register needs to be reloaded */
#endif
#if (configCPU_FAMILY==configCPU_FAMILY_CF1) || (configCPU_FAMILY==configCPU_FAMILY_CF2)
#define portINITIAL_FORMAT_VECTOR ((portSTACK_TYPE)0x4000)
#define portINITIAL_STATUS_REGISTER ((portSTACK_TYPE)0x2000) /* Supervisor mode set. */
#endif
#if configCPU_FAMILY_IS_ARM(configCPU_FAMILY)
/* For strict compliance with the Cortex-M spec the task start address should
have bit-0 clear, as it is loaded into the PC on exit from an ISR. */
#define portSTART_ADDRESS_MASK ( ( StackType_t ) 0xfffffffeUL )
/* Constants required to manipulate the core.
* SysTick register: http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0662b/CIAGECDD.html
* Registers first...
*/
#define portNVIC_SYSTICK_CTRL_REG (*((volatile unsigned long *)0xe000e010)) /* SYST_CSR, SysTick Control and Status Register */
#define portNVIC_SYSTICK_LOAD_REG (*((volatile unsigned long *)0xe000e014)) /* SYST_RVR, SysTick reload value register */
#define portNVIC_SYSTICK_CURRENT_VALUE_REG (*((volatile unsigned long *)0xe000e018)) /* SYST_CVR, SysTick current value register */
#define portNVIC_SYSTICK_CALIB_VALUE_REG (*((volatile unsigned long *)0xe000e01C)) /* SYST_CALIB, SysTick calibration value register */
/* ...then bits in the registers. */
#define portNVIC_SYSTICK_COUNT_FLAG_BIT (1UL<<16UL) /* returns 1 if timer counted to 0 since the last read of the register */
#if configSYSTICK_USE_CORE_CLOCK
#define portNVIC_SYSTICK_CLK_BIT (1UL<<2UL) /* clock source. 1: core clock, 0: external reference clock */
#else
#define portNVIC_SYSTICK_CLK_BIT (0UL<<2UL) /* clock source. 1: core clock, 0: external reference clock */
#endif
#define portNVIC_SYSTICK_INT_BIT (1UL<<1UL) /* SysTick interrupt enable bit */
#define portNVIC_SYSTICK_ENABLE_BIT (1UL<<0UL) /* SysTick enable bit */
/* Constants required to manipulate the NVIC: */
#define portNVIC_INT_CTRL ((volatile unsigned long*)0xe000ed04) /* interrupt control and state register (ICSR) */
#define portNVIC_PENDSVSET_BIT (1UL<<28UL) /* bit 28 in portNVIC_INT_CTRL (PENDSVSET), see http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0552a/Cihfaaha.html */
#define portNVIC_PENDSVCLEAR_BIT (1UL<<27UL) /* bit 27 in portNVIC_INT_CTRL (PENDSVCLR) */
#define portNVIC_PEND_SYSTICK_SET_BIT (1UL<<26UL) /* bit 26 in portNVIC_INT_CTRL (PENDSTSET) */
#define portNVIC_PEND_SYSTICK_CLEAR_BIT (1UL<<25UL) /* bit 25 in portNVIC_INT_CTRL (PENDSTCLR) */
#define portNVIC_SYSPRI2 ((volatile unsigned long*)0xe000ed1c) /* system handler priority register 2 (SHPR2), used for SVCall priority, http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0662b/CIAGECDD.html */
#define portNVIC_SVCALL_PRI (((unsigned long)configKERNEL_INTERRUPT_PRIORITY)<<24) /* priority of SVCall interrupt (in portNVIC_SYSPRI2) */
#define portNVIC_SYSPRI3 ((volatile unsigned long*)0xe000ed20) /* system handler priority register 3 (SHPR3), used for SysTick and PendSV priority, http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0662b/CIAGECDD.html */
#define portNVIC_SYSTICK_PRI (((unsigned long)configKERNEL_INTERRUPT_PRIORITY)<<24) /* priority of SysTick interrupt (in portNVIC_SYSPRI3) */
#define portNVIC_PENDSV_PRI (((unsigned long)configKERNEL_INTERRUPT_PRIORITY)<<16) /* priority of PendableService interrupt (in portNVIC_SYSPRI3) */
#define portNVIC_SYSPRI7 ((volatile unsigned long*)0xe000e41c) /* system handler priority register 7, PRI_28 is LPTMR */
#define portNVIC_LP_TIMER_PRI (((unsigned long)configKERNEL_INTERRUPT_PRIORITY)<<0) /* priority of low power timer interrupt */
#if configSYSTICK_USE_LOW_POWER_TIMER && MCUC1_CONFIG_SDK_VERSION_USED == MCUC1_CONFIG_SDK_PROCESSOR_EXPERT
#define IRQn_Type int
#define __NVIC_PRIO_BITS configPRIO_BITS
#define __O volatile /*!< Defines 'write only' permissions */
#define __IO volatile /*!< Defines 'read / write' permissions */
/** \brief Structure type to access the Nested Vectored Interrupt Controller (NVIC).
*/
#if configCPU_FAMILY_IS_ARM_M4_M7(configCPU_FAMILY)
typedef struct
{
__IO uint32_t ISER[8]; /*!< Offset: 0x000 (R/W) Interrupt Set Enable Register */
uint32_t RESERVED0[24];
__IO uint32_t ICER[8]; /*!< Offset: 0x080 (R/W) Interrupt Clear Enable Register */
uint32_t RSERVED1[24];
__IO uint32_t ISPR[8]; /*!< Offset: 0x100 (R/W) Interrupt Set Pending Register */
uint32_t RESERVED2[24];
__IO uint32_t ICPR[8]; /*!< Offset: 0x180 (R/W) Interrupt Clear Pending Register */
uint32_t RESERVED3[24];
__IO uint32_t IABR[8]; /*!< Offset: 0x200 (R/W) Interrupt Active bit Register */
uint32_t RESERVED4[56];
__IO uint8_t IP[240]; /*!< Offset: 0x300 (R/W) Interrupt Priority Register (8Bit wide) */
uint32_t RESERVED5[644];
__O uint32_t STIR; /*!< Offset: 0xE00 ( /W) Software Trigger Interrupt Register */
} NVIC_Type;
#else /* M0+ */
typedef struct
{
__IO uint32_t ISER[1]; /*!< Offset: 0x000 (R/W) Interrupt Set Enable Register */
uint32_t RESERVED0[31];
__IO uint32_t ICER[1]; /*!< Offset: 0x080 (R/W) Interrupt Clear Enable Register */
uint32_t RSERVED1[31];
__IO uint32_t ISPR[1]; /*!< Offset: 0x100 (R/W) Interrupt Set Pending Register */
uint32_t RESERVED2[31];
__IO uint32_t ICPR[1]; /*!< Offset: 0x180 (R/W) Interrupt Clear Pending Register */
uint32_t RESERVED3[31];
uint32_t RESERVED4[64];
__IO uint32_t IP[8]; /*!< Offset: 0x300 (R/W) Interrupt Priority Register */
} NVIC_Type;
#endif
/* Memory mapping of Cortex-M0+ Hardware */
#define SCS_BASE (0xE000E000UL) /*!< System Control Space Base Address */
#define NVIC_BASE (SCS_BASE + 0x0100UL) /*!< NVIC Base Address */
#define NVIC ((NVIC_Type *) NVIC_BASE ) /*!< NVIC configuration struct */
/* Interrupt Priorities are WORD accessible only under ARMv6M */
/* The following MACROS handle generation of the register offset and byte masks */
#define _BIT_SHIFT(IRQn) ( (((uint32_t)(IRQn) ) & 0x03) * 8 )
#define _IP_IDX(IRQn) ( ((uint32_t)(IRQn) >> 2) )
/** \brief Set Interrupt Priority
The function sets the priority of an interrupt.
\note The priority cannot be set for every core interrupt.
\param [in] IRQn Interrupt number.
\param [in] priority Priority to set.
*/
static void NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority) {
IRQn -= 16; /* PEx starts numbers with zero, while system interrupts would be negative */
#if configCPU_FAMILY_IS_ARM_M4_M7(configCPU_FAMILY)
NVIC->IP[(uint32_t)(IRQn)] = ((priority << (8 - __NVIC_PRIO_BITS)) & 0xff); /* set Priority for device specific Interrupts */
#else /* M0+ */
NVIC->IP[_IP_IDX(IRQn)] = (NVIC->IP[_IP_IDX(IRQn)] & ~(0xFF << _BIT_SHIFT(IRQn))) |
(((priority << (8 - __NVIC_PRIO_BITS)) & 0xFF) << _BIT_SHIFT(IRQn)); /* set Priority for device specific Interrupts */
#endif
}
/** \brief Enable External Interrupt
The function enables a device-specific interrupt in the NVIC interrupt controller.
\param [in] IRQn External interrupt number. Value cannot be negative.
*/
static void NVIC_EnableIRQ(IRQn_Type IRQn) {
IRQn -= 16; /* PEx starts numbers with zero, while system interrupts would be negative */
#if configCPU_FAMILY_IS_ARM_M4_M7(configCPU_FAMILY)
NVIC->ISER[(uint32_t)((int32_t)IRQn) >> 5] = (uint32_t)(1 << ((uint32_t)((int32_t)IRQn) & (uint32_t)0x1F)); /* enable interrupt */
#else /* M0+ */
NVIC->ISER[0] = (1 << ((uint32_t)(IRQn) & 0x1F)); /* enable interrupt */
#endif
}
#endif /* configSYSTICK_USE_LOW_POWER_TIMER */
/* Constants required to set up the initial stack. */
#define portINITIAL_XPSR (0x01000000)
#define portINITIAL_EXEC_RETURN (0xfffffffd)
#define portINITIAL_CONTROL_IF_UNPRIVILEGED (0x03)
#define portINITIAL_CONTROL_IF_PRIVILEGED (0x02)
#if configCPU_FAMILY_IS_ARM_FPU(configCPU_FAMILY)
/* Constants required to manipulate the VFP. */
#define portFPCCR ((volatile unsigned long *)0xe000ef34) /* Floating point context control register. */
#define portASPEN_AND_LSPEN_BITS (0x3UL<<30UL)
#endif
#endif
/* Used to keep track of the number of nested calls to taskENTER_CRITICAL().
This will be set to 0 prior to the first task being started. */
volatile unsigned portBASE_TYPE uxCriticalNesting;
#if INCLUDE_vTaskEndScheduler
#include <setjmp.h>
static jmp_buf xJumpBuf; /* Used to restore the original context when the scheduler is ended. */
#endif
/*-----------------------------------------------------------*/
void prvTaskExitError(void) {
/* A function that implements a task must not exit or attempt to return to
its caller as there is nothing to return to. If a task wants to exit it
should instead call vTaskDelete( NULL ).
Artificially force an assert() to be triggered if configASSERT() is
defined, then stop here so application writers can catch the error. */
configASSERT(uxCriticalNesting == ~0UL);
portDISABLE_INTERRUPTS();
for(;;) {
/* wait here */
}
}
/*-----------------------------------------------------------*/
#if (configCOMPILER==configCOMPILER_ARM_KEIL) && configCPU_FAMILY_IS_ARM_M4_M7(configCPU_FAMILY)
__asm uint32_t ulPortSetInterruptMask(void) {
PRESERVE8
mrs r0, basepri
mov r1, #configMAX_SYSCALL_INTERRUPT_PRIORITY
msr basepri, r1
bx r14
}
#endif /* (configCOMPILER==configCOMPILER_ARM_KEIL) */
/*-----------------------------------------------------------*/
#if (configCOMPILER==configCOMPILER_ARM_KEIL) && configCPU_FAMILY_IS_ARM_M4_M7(configCPU_FAMILY)
__asm void vPortClearInterruptMask(uint32_t ulNewMask) {
PRESERVE8
msr basepri, r0
bx r14
}
#endif /* (configCOMPILER==configCOMPILER_ARM_KEIL) */
/*-----------------------------------------------------------*/
StackType_t *pxPortInitialiseStack(portSTACK_TYPE *pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters) {
/*Place a few bytes of known values on the bottom of the stack.
This can be uncommented to provide useful stack markers when debugging.
*pxTopOfStack = (portSTACK_TYPE)0x11;
pxTopOfStack--;
*pxTopOfStack = (portSTACK_TYPE)0x22;
pxTopOfStack--;
*pxTopOfStack = (portSTACK_TYPE)0x33;
pxTopOfStack--;
*/
/* Setup the initial stack of the task. The stack is set exactly as
expected by the portRESTORE_CONTEXT() macro. In this case the stack as
expected by the HCS12 RTI instruction. */
/* The address of the task function is placed in the stack byte at a time. */
*pxTopOfStack = (portSTACK_TYPE)*(((portSTACK_TYPE*)(&pxCode))+1);
pxTopOfStack--;
*pxTopOfStack = (portSTACK_TYPE)*(((portSTACK_TYPE*)(&pxCode))+0);
pxTopOfStack--;
/* Next are all the registers that form part of the task context. */
/* Y register */
*pxTopOfStack = (portSTACK_TYPE)0xff;
pxTopOfStack--;
*pxTopOfStack = (portSTACK_TYPE)0xee;
pxTopOfStack--;
/* X register */
*pxTopOfStack = (portSTACK_TYPE)0xdd;
pxTopOfStack--;
*pxTopOfStack = (portSTACK_TYPE)0xcc;
pxTopOfStack--;
/* A register contains parameter high byte. */
*pxTopOfStack = (portSTACK_TYPE) *(((portSTACK_TYPE*)(&pvParameters))+0);
pxTopOfStack--;
/* B register contains parameter low byte. */
*pxTopOfStack = (portSTACK_TYPE)*(((portSTACK_TYPE*)(&pvParameters))+1);
pxTopOfStack--;
#ifdef __HCS12X__
/* CCR (12-bit): Note that when the task starts interrupts will be enabled since I" bit of CCR is cleared */
*pxTopOfStack = (portSTACK_TYPE)0xC0;
pxTopOfStack--;
*pxTopOfStack = (portSTACK_TYPE)0x00;
pxTopOfStack--;
#else
/* CCR(8-bit): Note that when the task starts interrupts will be enabled since "I" bit of CCR is cleared */
*pxTopOfStack = (portSTACK_TYPE)0x40; /* have the X bit still masked */
pxTopOfStack--;
#endif
#ifdef __BANKED__
#ifdef __HCS12X__
*pxTopOfStack = (portSTACK_TYPE) *(((portSTACK_TYPE*)(&pxCode))+2); /* PPage of task created */
pxTopOfStack--;
*pxTopOfStack = EPAGE;
pxTopOfStack--;
*pxTopOfStack = GPAGE;
pxTopOfStack--;
*pxTopOfStack = RPAGE;
pxTopOfStack--;
#else
/* The page of the task. */
*pxTopOfStack = (portSTACK_TYPE)((int)pxCode);
pxTopOfStack--;
#endif
#endif
/* Finally the critical nesting depth is initialised with 0 (not within a critical section). */
*pxTopOfStack = (portSTACK_TYPE)0x00;
return pxTopOfStack;
}
/*-----------------------------------------------------------*/
#if (configCOMPILER==configCOMPILER_S08_FSL) || (configCOMPILER==configCOMPILER_S12_FSL)
#if (configCOMPILER==configCOMPILER_S08_FSL)
#pragma MESSAGE DISABLE C1404 /* return expected */
#pragma MESSAGE DISABLE C20000 /* dead code detected */
#pragma NO_RETURN
#pragma CODE_SEG __NEAR_SEG NON_BANKED
#elif (configCOMPILER==configCOMPILER_S12_FSL)
#pragma MESSAGE DISABLE C1404 /* return expected */
#pragma NO_RETURN
#endif
static portBASE_TYPE xBankedStartScheduler(void) {
/* Restore the context of the first task. */
portRESTORE_CONTEXT(); /* Simulate the end of an interrupt to start the scheduler off. */
/* Should not get here! */
return pdFALSE;
}
#if (configCOMPILER==configCOMPILER_S08_FSL)
#pragma CODE_SEG DEFAULT
#pragma MESSAGE DEFAULT C1404 /* return expected */
#pragma MESSAGE DEFAULT C20000 /* dead code detected */
#elif (configCOMPILER==configCOMPILER_S12_FSL)
#pragma MESSAGE DEFAULT C1404 /* return expected */
#endif
#endif
/*-----------------------------------------------------------*/
#if configUSE_TICKLESS_IDLE == 1
#if (configCOMPILER==configCOMPILER_ARM_GCC) || (configCOMPILER==configCOMPILER_ARM_KEIL)
__attribute__((weak))
#endif
void vPortSuppressTicksAndSleep(TickType_t xExpectedIdleTime) {
unsigned long ulReloadValue, ulCompleteTickPeriods, ulCompletedSysTickIncrements;
TickCounter_t tmp; /* because of how we get the current tick counter */
bool tickISRfired;
uint32_t tickDuration;
#if configSYSTICK_USE_LOW_POWER_TIMER
/* if we wait for the tick interrupt, do not enter low power again below */
if (restoreTickInterval!=0) {
/* default wait/sleep code */
__asm("cli"); /* re-enable interrupts */
__asm("wait");
return;
}
#endif
/* Make sure the tick timer reload value does not overflow the counter. */
if(xExpectedIdleTime > xMaximumPossibleSuppressedTicks) {
xExpectedIdleTime = xMaximumPossibleSuppressedTicks;
}
/* Stop the tick timer momentarily. The time the counter is stopped for
* is accounted for as best it can be, but using the tickless mode will
* inevitably result in some tiny drift of the time maintained by the
* kernel with respect to calendar time.
*/
#if configSYSTICK_USE_LOW_POWER_TIMER
/* disabling the LPTMR does reset the timer register! So I need to get the value first, then disable the timer: */
GET_TICK_CURRENT_VAL(&tmp);
DISABLE_TICK_COUNTER();
#else /* using normal timer or SysTick */
DISABLE_TICK_COUNTER();
GET_TICK_CURRENT_VAL(&tmp);
#endif
/* Calculate the reload value required to wait xExpectedIdleTime
* tick periods. This code will execute part way through one
* of the tick periods.
*/
/* -1UL is used because this code will execute part way through one of the tick periods */
#if COUNTS_UP
ulReloadValue = (UL_TIMER_COUNTS_FOR_ONE_TICK*xExpectedIdleTime);
#if configSYSTICK_USE_LOW_POWER_TIMER
if (ulReloadValue > 0) { /* make sure it does not underflow */
ulReloadValue -= 1UL; /* LPTMR: interrupt will happen at match of compare register && increment, thus minus 1 */
}
#endif
if (tmp!=0 && ulReloadValue>=tmp) { /* make sure it does not underflow */
ulReloadValue -= tmp; /* take into account what we already executed in the current tick period */
}
#else
ulReloadValue = tmp+(UL_TIMER_COUNTS_FOR_ONE_TICK*(xExpectedIdleTime-1UL));
#endif
if (ulStoppedTimerCompensation!=0 && ulReloadValue>ulStoppedTimerCompensation) {
ulReloadValue -= ulStoppedTimerCompensation;
}
/* Enter a critical section but don't use the taskENTER_CRITICAL()
* method as that will mask interrupts that should exit sleep mode.
*/
TICKLESS_DISABLE_INTERRUPTS();
/* If a context switch is pending or a task is waiting for the scheduler
* to be unsuspended then abandon the low power entry.
*/
if (eTaskConfirmSleepModeStatus()==eAbortSleep) {
/* Must restore the duration before re-enabling the timers */
#if COUNTS_UP
#if configSYSTICK_USE_LOW_POWER_TIMER
tickDuration = UL_TIMER_COUNTS_FOR_ONE_TICK-1UL; /* LPTMR: interrupt will happen at match of compare register && increment, thus minus 1 */
#else
tickDuration = UL_TIMER_COUNTS_FOR_ONE_TICK;
#endif
if (tmp!=0 && tickDuration >= tmp) { /* make sure it does not underflow */
tickDuration -= tmp; /* take into account what we already executed in the current tick period */
}
#else
tickDuration = tmp;
#endif
SET_TICK_DURATION(tickDuration);
ENABLE_TICK_COUNTER(); /* Restart tick timer. */
TICKLESS_ENABLE_INTERRUPTS();
} else {
SET_TICK_DURATION(ulReloadValue); /* Set the new reload value. */
RESET_TICK_COUNTER_VAL(); /* Reset the counter. */
ENABLE_TICK_COUNTER(); /* Restart tick timer. */
TICK_INTERRUPT_FLAG_RESET(); /* reset flag so we know later if it has fired */
/* Sleep until something happens. configPRE_SLEEP_PROCESSING() can
* set its parameter to 0 to indicate that its implementation contains
* its own wait for interrupt or wait for event instruction, and so wfi
* should not be executed again. However, the original expected idle
* time variable must remain unmodified, so a copy is taken.
*/
/* CPU *HAS TO WAIT* in the sequence below for an interrupt. If vOnPreSleepProcessing() is not used, a default implementation is provided */
/* default wait/sleep code */
__asm("cli"); /* re-enable interrupts */
__asm("wait");
/* ----------------------------------------------------------------------------
* Here the CPU *HAS TO BE* low power mode, waiting to wake up by an interrupt
* ----------------------------------------------------------------------------*/
/* Stop tick counter. Again, the time the tick counter is stopped for is
* accounted for as best it can be, but using the tickless mode will
* inevitably result in some tiny drift of the time maintained by the
* kernel with respect to calendar time.
*/
tickISRfired = (bool)TICK_INTERRUPT_HAS_FIRED(); /* need to check Interrupt flag here, as might be modified below */
#if configSYSTICK_USE_LOW_POWER_TIMER
/* disabling the LPTMR does reset the timer register! So I need to get the value first, then disable the timer: */
GET_TICK_CURRENT_VAL(&tmp);
DISABLE_TICK_COUNTER();
#else
DISABLE_TICK_COUNTER();
GET_TICK_CURRENT_VAL(&tmp);
#endif
TICKLESS_ENABLE_INTERRUPTS();/* Re-enable interrupts */
if (tickISRfired) {
/* The tick interrupt has already executed, and the timer
* count reloaded with the modulo/match value.
* Reset the counter register with whatever remains of
* this tick period.
*/
#if COUNTS_UP
#if configSYSTICK_USE_LOW_POWER_TIMER
tickDuration = (UL_TIMER_COUNTS_FOR_ONE_TICK-1UL); /* LPTMR: interrupt will happen at match of compare register && increment, thus minus 1 */
#else
tickDuration = UL_TIMER_COUNTS_FOR_ONE_TICK;
#endif
if (tickDuration >= tmp) { /* make sure it does not underflow */
tickDuration -= tmp;
}
if (tickDuration > 1) {
/*! \todo Need to rethink this one! */
//tickDuration -= 1; /* decrement by one, to compensate for one timer tick, as we are already part way through it */
} else {
/* Not enough time to setup for the next tick, so skip it and setup for the
* next. Make sure to count the tick we skipped.
*/
tickDuration += (UL_TIMER_COUNTS_FOR_ONE_TICK - 1UL);
vTaskStepTick(1);
}
#else
tickDuration = (UL_TIMER_COUNTS_FOR_ONE_TICK-1UL)-(ulReloadValue-tmp);
#endif
SET_TICK_DURATION(tickDuration);
/* The tick interrupt handler will already have pended the tick
* processing in the kernel. As the pending tick will be
* processed as soon as this function exits, the tick value
* maintained by the tick is stepped forward by one less than the
* time spent waiting.
*/
ulCompleteTickPeriods = xExpectedIdleTime-1UL; /* -1 because we already added a completed tick from the tick interrupt */
} else {
/* Something other than the tick interrupt ended the sleep.
* Work out how long the sleep lasted rounded to complete tick
* periods (not the ulReload value which accounted for part ticks).
*/
#if COUNTS_UP
ulCompletedSysTickIncrements = tmp;
/* How many complete tick periods passed while the processor was waiting? */
ulCompleteTickPeriods = ulCompletedSysTickIncrements/UL_TIMER_COUNTS_FOR_ONE_TICK;
/* The reload value is set to whatever fraction of a single tick period remains. */
tickDuration = (((ulCompleteTickPeriods+1)*UL_TIMER_COUNTS_FOR_ONE_TICK)-1)-ulCompletedSysTickIncrements;
if (tickDuration > 1) {
tickDuration -= 1; /* decrement by one, to compensate for one timer tick, as we are already part way through it */
} else {
/* Not enough time to setup for the next tick, so skip it and setup for the
* next. Make sure to count the tick we skipped.
*/
tickDuration += (UL_TIMER_COUNTS_FOR_ONE_TICK - 1UL);
if (tickDuration > 1) { /* check for underflow */
tickDuration -= 1;
}
vTaskStepTick(1);
}
#else
ulCompletedSysTickIncrements = (xExpectedIdleTime*UL_TIMER_COUNTS_FOR_ONE_TICK)-tmp;
/* How many complete tick periods passed while the processor was waiting? */
ulCompleteTickPeriods = ulCompletedSysTickIncrements/UL_TIMER_COUNTS_FOR_ONE_TICK;
/* The reload value is set to whatever fraction of a single tick period remains. */
tickDuration = ((ulCompleteTickPeriods+1)*UL_TIMER_COUNTS_FOR_ONE_TICK)-ulCompletedSysTickIncrements;
#endif
SET_TICK_DURATION(tickDuration);
}
/* Restart SysTick so it runs from portNVIC_SYSTICK_LOAD_REG
again, then set portNVIC_SYSTICK_LOAD_REG back to its standard
value. The critical section is used to ensure the tick interrupt
can only execute once in the case that the reload register is near
zero.
*/
RESET_TICK_COUNTER_VAL();
portENTER_CRITICAL();
{
ENABLE_TICK_COUNTER();
vTaskStepTick(ulCompleteTickPeriods);
#if configSYSTICK_USE_LOW_POWER_TIMER
/* The compare register of the LPTMR should not be modified when the
* timer is running, so wait for the next tick interrupt to change it.
*/
if (tickDuration != (UL_TIMER_COUNTS_FOR_ONE_TICK-1UL)) { /* minus one because of LPTMR way to trigger interrupts */
if (tickISRfired) {
/* The pending tick interrupt will be immediately processed after
* exiting this function so we need to delay the change of the tick
* duration until the one after that.
*/
restoreTickInterval = 2;
} else {
/* Notify the tick interrupt that the tick duration needs to be
* changed back to the normal setting.
*/
restoreTickInterval = 1;
}
} else {
/* If the duration is the standard full tick, then there's no reason
* to stop and restart LPTMR in the tick interrupt.
*/
restoreTickInterval = 0;
}
#else
/* The systick has a load register that will automatically be used
* when the counter counts down to zero.
*/
SET_TICK_DURATION(UL_TIMER_COUNTS_FOR_ONE_TICK-1UL);
#endif
}
portEXIT_CRITICAL();
}
}
#endif /* #if configUSE_TICKLESS_IDLE */
/*-----------------------------------------------------------*/
void vPortInitTickTimer(void) {
#if configUSE_TICKLESS_IDLE == 1
{
#if TICK_NOF_BITS==32
xMaximumPossibleSuppressedTicks = 0xffffffffUL/TIMER_COUNTS_FOR_ONE_TICK; /* 32bit timer register */
#elif TICK_NOF_BITS==24
xMaximumPossibleSuppressedTicks = 0xffffffUL/TIMER_COUNTS_FOR_ONE_TICK; /* 24bit timer register */
#elif TICK_NOF_BITS==16
xMaximumPossibleSuppressedTicks = 0xffffUL/TIMER_COUNTS_FOR_ONE_TICK; /* 16bit timer register */
#elif TICK_NOF_BITS==8
xMaximumPossibleSuppressedTicks = 0xffUL/TIMER_COUNTS_FOR_ONE_TICK; /* 8bit timer register */
#else
error "unknown configuration!"
#endif
#if configSYSTICK_USE_LOW_POWER_TIMER
ulStoppedTimerCompensation = configSTOPPED_TIMER_COMPENSATION/(configCPU_CLOCK_HZ/configSYSTICK_LOW_POWER_TIMER_CLOCK_HZ);
#else
ulStoppedTimerCompensation = configSTOPPED_TIMER_COMPENSATION/(configCPU_CLOCK_HZ/configSYSTICK_CLOCK_HZ);
#endif
}
#endif /* configUSE_TICKLESS_IDLE */
}
/*-----------------------------------------------------------*/
void vPortStartTickTimer(void) {
/* Warning: not possible to reset timer! */
(void)TickCntr1_Enable(); /* start the tick timer */
}
/*-----------------------------------------------------------*/
void vPortStopTickTimer(void) {
(void)TickCntr1_Disable(); /* stop the tick timer */
}
/*-----------------------------------------------------------*/
#if configCPU_FAMILY_IS_ARM_FPU(configCPU_FAMILY) /* has floating point unit */
void vPortEnableVFP(void) {
#if 1 /* configLTO_HELPER: using implementation in C which is portable */
#define CPACR_REG_MEM ((volatile int*)0xE000ED88) /* location of the CPACR register */
*CPACR_REG_MEM |= (0xf<<20); /* Enable CP10 and CP11 coprocessors */
#else /* below is the original assembly code which fails with -flto because of the constant load */
__asm volatile
(
" ldr.w r0, =0xE000ED88 \n" /* The FPU enable bits are in the CPACR. */
" ldr r1, [r0] \n"
" orr r1, r1, #( 0xf << 20 ) \n" /* Enable CP10 and CP11 coprocessors, then save back. */
" str r1, [r0] \n"
" bx r14 "
);
#endif
}
#endif /* M4/M7 */
/*-----------------------------------------------------------*/
/*
* Used by the portASSERT_IF_INTERRUPT_PRIORITY_INVALID() macro to ensure
* FreeRTOS API functions are not called from interrupts that have been assigned
* a priority above configMAX_SYSCALL_INTERRUPT_PRIORITY.
*/
#if configCPU_FAMILY_IS_ARM_M4_M7(configCPU_FAMILY) && (configASSERT_DEFINED == 1)
/* Constants required to check the validity of an interrupt priority. */
#define portFIRST_USER_INTERRUPT_NUMBER ( 16 )
#define portNVIC_IP_REGISTERS_OFFSET_16 ( 0xE000E3F0 )
#define portAIRCR_REG ( * ( ( volatile uint32_t * ) 0xE000ED0C ) )
#define portMAX_8_BIT_VALUE ( ( uint8_t ) 0xff )
#define portTOP_BIT_OF_BYTE ( ( uint8_t ) 0x80 )
#define portMAX_PRIGROUP_BITS ( ( uint8_t ) 7 )
#define portPRIORITY_GROUP_MASK ( 0x07UL << 8UL )
#define portPRIGROUP_SHIFT ( 8UL )
static uint8_t ucMaxSysCallPriority = 0;
static uint32_t ulMaxPRIGROUPValue = 0;
static const volatile uint8_t * const pcInterruptPriorityRegisters = ( const volatile uint8_t * const ) portNVIC_IP_REGISTERS_OFFSET_16;
#endif /* configASSERT_DEFINED */
BaseType_t xPortStartScheduler(void) {
/* xPortStartScheduler() does not start the scheduler directly because
the header file containing the xPortStartScheduler() prototype is part
of the common kernel code, and therefore cannot use the CODE_SEG pragma.
Instead it simply calls the locally defined xBankedStartScheduler() -
which does use the CODE_SEG pragma. */
vPortInitTickTimer();
vPortStartTickTimer();
#if INCLUDE_vTaskEndScheduler
if(setjmp(xJumpBuf) != 0 ) {
/* here we will get in case of call to vTaskEndScheduler() */
return pdFALSE;
}
#endif
return xBankedStartScheduler();
}
/*-----------------------------------------------------------*/
void vPortEndScheduler(void) {
vPortStopTickTimer();
/* Jump back to the processor state prior to starting the
scheduler. This means we are not going to be using a
task stack frame so the task can be deleted. */
#if INCLUDE_vTaskEndScheduler
longjmp(xJumpBuf, 1);
#else
for(;;){} /* wait here */
#endif
}
/*-----------------------------------------------------------*/
void vPortEnterCritical(void) {
/*
* Disable interrupts before incrementing the count of critical section nesting.
* The nesting count is maintained so we know when interrupts should be
* re-enabled. Once interrupts are disabled the nesting count can be accessed
* directly. Each task maintains its own nesting count.
*/
portDISABLE_INTERRUPTS();
portPOST_ENABLE_DISABLE_INTERRUPTS();
uxCriticalNesting++;
}
/*-----------------------------------------------------------*/
void vPortExitCritical(void) {
/* Interrupts are disabled so we can access the nesting count directly. If the
* nesting is found to be 0 (no nesting) then we are leaving the critical
* section and interrupts can be re-enabled.
*/
uxCriticalNesting--;
if (uxCriticalNesting == 0) {
portENABLE_INTERRUPTS();
portPOST_ENABLE_DISABLE_INTERRUPTS();
}
}
/*-----------------------------------------------------------*/
#pragma CODE_SEG __NEAR_SEG NON_BANKED
__interrupt void vPortYieldISR(void) {
portTASK_SWITCH_FROM_ISR();
}
#pragma CODE_SEG DEFAULT
/*-----------------------------------------------------------*/
#include "portTicks.h"
/* return the tick raw counter value. It is assumed that the counter register has been reset at the last tick time */
portLONG uxGetTickCounterValue(void) {
TickCntr1_TTimerValue val;
(void)TickCntr1_GetCounterValue(&val);
return (portLONG)val;
}
/*-----------------------------------------------------------*/
#if (configCOMPILER==configCOMPILER_ARM_KEIL)
#if !MCUC1_CONFIG_PEX_SDK_USED /* the SDK expects different interrupt handler names */
#if configSYSTICK_USE_LOW_POWER_TIMER
void LPTMR0_IRQHandler(void) { /* low power timer */
#else
void SysTick_Handler(void) { /* normal SysTick */
#endif
#else
void vPortTickHandler(void) {
#endif
/* this is how we get here:
RTOSTICKLDD1_Interrupt:
push {r4, lr}
... RTOSTICKLDD1_OnCounterRestart
bl RTOSTICKLDD1_OnCounterRestart -> push {r4,lr}
pop {r4, lr} mov r4,r0
bl vPortTickHandler
pop {r4,pc}
*/
#if configUSE_SEGGER_SYSTEM_VIEWER_HOOKS && configCPU_FAMILY==configCPU_FAMILY_ARM_M0P
SEGGER_SYSVIEW_TickCnt++; /* tick counter for Segger SystemViewer */
#endif
#if configUSE_TICKLESS_IDLE == 1
TICK_INTERRUPT_FLAG_SET();
#endif
portDISABLE_INTERRUPTS(); /* disable interrupts */
#if (configUSE_TICKLESS_IDLE == 1) && configSYSTICK_USE_LOW_POWER_TIMER
if (restoreTickInterval > 0) { /* we got interrupted during tickless mode and non-standard compare value: reload normal compare value */
if (restoreTickInterval == 1) {
DISABLE_TICK_COUNTER();
SET_TICK_DURATION(UL_TIMER_COUNTS_FOR_ONE_TICK-1UL);
ENABLE_TICK_COUNTER();
}
restoreTickInterval -= 1;
}
#endif
if (xTaskIncrementTick()!=pdFALSE) { /* increment tick count */
taskYIELD();
}
portENABLE_INTERRUPTS(); /* enable interrupts again */
}
#endif
/*-----------------------------------------------------------*/
#if (configCOMPILER==configCOMPILER_ARM_GCC)
#if !MCUC1_CONFIG_PEX_SDK_USED /* the SDK expects different interrupt handler names */
#if configSYSTICK_USE_LOW_POWER_TIMER
__attribute__ ((naked)) void LPTMR0_IRQHandler(void) { /* low power timer */
#else
__attribute__ ((naked)) void SysTick_Handler(void) { /* normal SysTick */
#endif
#else
__attribute__ ((naked)) void vPortTickHandler(void) {
#endif
ACKNOWLEDGE_TICK_ISR();
#if configUSE_SEGGER_SYSTEM_VIEWER_HOOKS && configCPU_FAMILY==configCPU_FAMILY_ARM_M0P
SEGGER_SYSVIEW_TickCnt++; /* tick counter for Segger SystemViewer */
#endif
#if configUSE_TICKLESS_IDLE == 1
TICK_INTERRUPT_FLAG_SET();
#endif
/* The SysTick runs at the lowest interrupt priority, so when this interrupt
executes all interrupts must be unmasked. There is therefore no need to
save and then restore the interrupt mask value as its value is already
known. */
portDISABLE_INTERRUPTS(); /* disable interrupts */
traceISR_ENTER();
#if (configUSE_TICKLESS_IDLE == 1) && configSYSTICK_USE_LOW_POWER_TIMER
if (restoreTickInterval > 0) { /* we got interrupted during tickless mode and non-standard compare value: reload normal compare value */
if (restoreTickInterval == 1) {
DISABLE_TICK_COUNTER();
SET_TICK_DURATION(UL_TIMER_COUNTS_FOR_ONE_TICK-1UL);
ENABLE_TICK_COUNTER();
}
restoreTickInterval -= 1;
}
#endif
if (xTaskIncrementTick()!=pdFALSE) { /* increment tick count */
traceISR_EXIT_TO_SCHEDULER();
taskYIELD();
} else {
traceISR_EXIT();
}
portENABLE_INTERRUPTS(); /* re-enable interrupts */
}
#endif
/*-----------------------------------------------------------*/
#if (configCOMPILER==configCOMPILER_DSC_FSL)
void vPortStartFirstTask(void) {
/* Restore the context of the first task to run. */
portRESTORE_CONTEXT();
/* Simulate the end of the yield function. */
__asm(rts);
}
#endif
/*-----------------------------------------------------------*/
#if (configCOMPILER==configCOMPILER_ARM_KEIL)
__asm void vPortStartFirstTask(void) {
#if configCPU_FAMILY_IS_ARM_M4_M7(configCPU_FAMILY) /* Cortex M4/M7 */
/* Use the NVIC offset register to locate the stack. */
ldr r0, =0xE000ED08
ldr r0, [r0]
ldr r0, [r0]
/* Set the msp back to the start of the stack. */
msr msp, r0
/* Globally enable interrupts. */
cpsie i
/* Call SVC to start the first task. */
svc 0
nop
nop
nop
#elif configCPU_FAMILY_IS_ARM_M0(configCPU_FAMILY) /* Cortex M0+ */
/* With the latest FreeRTOS, the port for M0+ does not use the SVC instruction
* and does not need vPortSVCHandler() any more.
*/
extern pxCurrentTCB;
PRESERVE8
/* The MSP stack is not reset as, unlike on M3/4 parts, there is no vector
table offset register that can be used to locate the initial stack value.
Not all M0 parts have the application vector table at address 0. */
ldr r3, =pxCurrentTCB /* Obtain location of pxCurrentTCB. */
ldr r1, [r3]
ldr r0, [r1] /* The first item in pxCurrentTCB is the task top of stack. */
adds r0, #32 /* Discard everything up to r0. */
msr psp, r0 /* This is now the new top of stack to use in the task. */
movs r0, #2 /* Switch to the psp stack. */
msr CONTROL, r0
isb
pop {r0-r5} /* Pop the registers that are saved automatically. */
mov lr, r5 /* lr is now in r5. */
pop {r3} /* The return address is now in r3. */
pop {r2} /* Pop and discard the XPSR. */
cpsie i /* The first task has its context and interrupts can be enabled. */
bx r3 /* Finally, jump to the user defined task code. */
ALIGN
#endif
}
#endif
/*-----------------------------------------------------------*/
#if (configCOMPILER==configCOMPILER_ARM_GCC)
/* Need the 'noinline', as latest gcc with -O3 tries to inline it, and gives error message: "Error: symbol `pxCurrentTCBConst2' is already defined" */
__attribute__((noinline))
void vPortStartFirstTask(void) {
#if configUSE_TOP_USED_PRIORITY || configLTO_HELPER
/* only needed for openOCD or Segger FreeRTOS thread awareness. It needs the symbol uxTopUsedPriority present after linking */
{
extern volatile const int uxTopUsedPriority;
__attribute__((__unused__)) volatile uint8_t dummy_value_for_openocd;
dummy_value_for_openocd = uxTopUsedPriority;
}
#endif
#if( configINCLUDE_FREERTOS_TASK_C_ADDITIONS_H == 1 && configUSE_TRACE_FACILITY==1)
/* reference FreeRTOSDebugConfig, otherwise it might get removed by the linker or optimizations */
{
extern const uint8_t FreeRTOSDebugConfig[];
if (FreeRTOSDebugConfig[0]==0) { /* just use it, so the linker cannot remove FreeRTOSDebugConfig[] */
for(;;); /* FreeRTOSDebugConfig[0] should always be non-zero, so this should never happen! */
}
}
#endif
#if configHEAP_SCHEME_IDENTIFICATION
extern const uint8_t freeRTOSMemoryScheme; /* constant for NXP Kernel Awareness to indicate heap scheme */
if (freeRTOSMemoryScheme>100) { /* reference/use variable so it does not get optimized by the linker */
for(;;);
}
#endif
#if configCPU_FAMILY_IS_ARM_M4_M7(configCPU_FAMILY) /* Cortex M4/M7 */
__asm volatile (
#if configLTO_HELPER /* with -flto, we cannot load the constant directly, otherwise we get "Error: offset out of range" with "lto-wrapper failed" */
" mov r0, #0xE0000000 \n" /* build the constant 0xE000ED08. First load the upper 16 bits */
" mov r1, #0xED00 \n" /* next load part of the lower 16 bit */
" orr r0, r1 \n" /* and or it into R0. Now we have 0xE000ED00 in R0 */
" mov r1, #0x08 \n" /* next load the lowest 8 bit */
" orr r0, r1 \n" /* and or it into R0. Now we have 0xE000ED08 in R0 */
#else
" ldr r0, =0xE000ED08 \n" /* Use the NVIC offset register to locate the stack. */
#endif
" ldr r0, [r0] \n" /* load address of vector table */
" ldr r0, [r0] \n" /* load first entry of vector table which is the reset stack pointer */
" msr msp, r0 \n" /* Set the msp back to the start of the stack. */
" cpsie i \n" /* Globally enable interrupts. */
" svc 0 \n" /* System call to start first task. */
" nop \n"
);
#elif configCPU_FAMILY_IS_ARM_M0(configCPU_FAMILY) /* Cortex M0+ */
/* With the latest FreeRTOS, the port for M0+ does not use the SVC instruction
* and does not need vPortSVCHandler() any more.
*/
/* The MSP stack is not reset as, unlike on M3/4 parts, there is no vector
table offset register that can be used to locate the initial stack value.
Not all M0 parts have the application vector table at address 0. */
__asm volatile(
" ldr r2, pxCurrentTCBConst2 \n" /* Obtain location of pxCurrentTCB. */
" ldr r3, [r2] \n"
" ldr r0, [r3] \n" /* The first item in pxCurrentTCB is the task top of stack. */
" add r0, #32 \n" /* Discard everything up to r0. */
" msr psp, r0 \n" /* This is now the new top of stack to use in the task. */
" movs r0, #2 \n" /* Switch to the psp stack. */
" msr CONTROL, r0 \n"
" isb \n"
" pop {r0-r5} \n" /* Pop the registers that are saved automatically. */
" mov lr, r5 \n" /* lr is now in r5. */
" pop {r3} \n" /* Return address is now in r3. */
" pop {r2} \n" /* Pop and discard XPSR. */
" cpsie i \n" /* The first task has its context and interrupts can be enabled. */
" bx r3 \n" /* Finally, jump to the user defined task code. */
" \n"
" .align 4 \n"
"pxCurrentTCBConst2: .word pxCurrentTCB"
);
#endif
}
#endif
/*-----------------------------------------------------------*/
#if (configCOMPILER==configCOMPILER_ARM_KEIL)
#if configCPU_FAMILY_IS_ARM_M4_M7(configCPU_FAMILY) /* Cortex M4/M7 */
#if !MCUC1_CONFIG_PEX_SDK_USED /* the SDK expects different interrupt handler names */
__asm void SVC_Handler(void) {
#else
__asm void vPortSVCHandler(void) {
#endif
PRESERVE8
EXTERN pxCurrentTCB
/* Get the location of the current TCB. */
ldr r3, =pxCurrentTCB
ldr r1, [r3]
ldr r0, [r1]
/* Pop the core registers. */
#if configCPU_FAMILY_IS_ARM_FPU(configCPU_FAMILY)
ldmia r0!, {r4-r11, r14} /* \todo: r14, check http://sourceforge.net/p/freertos/discussion/382005/thread/a9406af1/?limit=25#3bc7 */
#else
ldmia r0!, {r4-r11}
#endif
msr psp, r0
mov r0, #configMAX_SYSCALL_INTERRUPT_PRIORITY
msr basepri, r0
#if configCPU_FAMILY_IS_ARM_FPU(configCPU_FAMILY)
#else
orr r14, r14, #13
#endif
bx r14
}
/*-----------------------------------------------------------*/
#elif configCPU_FAMILY_IS_ARM_M0(configCPU_FAMILY) /* Cortex M0+ and Keil */
#if !MCUC1_CONFIG_PEX_SDK_USED /* the SDK expects different interrupt handler names */
__asm void SVC_Handler(void) {
#else
__asm void vPortSVCHandler(void) {
#endif
/* This function is no longer used, but retained for backward
compatibility. */
}
#endif
#endif
/*-----------------------------------------------------------*/
#if (configCOMPILER==configCOMPILER_ARM_GCC)
#if !MCUC1_CONFIG_PEX_SDK_USED /* the SDK expects different interrupt handler names */
__attribute__ ((naked)) void SVC_Handler(void) {
#else
__attribute__ ((naked)) void vPortSVCHandler(void) {
#endif
#if configCPU_FAMILY_IS_ARM_M4_M7(configCPU_FAMILY) /* Cortex M4 or M7 */
__asm volatile (
" ldr r3, pxCurrentTCBConst2 \n" /* Restore the context. */
" ldr r1, [r3] \n" /* Use pxCurrentTCBConst to get the pxCurrentTCB address. */
" ldr r0, [r1] \n" /* The first item in pxCurrentTCB is the task top of stack. */
/* pop the core registers */
#if configCPU_FAMILY_IS_ARM_FPU(configCPU_FAMILY)
" ldmia r0!, {r4-r11, r14} \n"
#else
" ldmia r0!, {r4-r11} \n"
#endif
" msr psp, r0 \n"
" mov r0, #0 \n"
" msr basepri, r0 \n"
#if configCPU_FAMILY_IS_ARM_FPU(configCPU_FAMILY)
#else
" orr r14, r14, #13 \n"
#endif
" bx r14 \n"
" \n"
" .align 2 \n"
"pxCurrentTCBConst2: .word pxCurrentTCB \n"
);
#elif configCPU_FAMILY_IS_ARM_M0(configCPU_FAMILY) /* Cortex M0+ */
/* This function is no longer used, but retained for backward
compatibility. */
#endif
}
#endif /* (configCOMPILER==configCOMPILER_ARM_GCC) */
/*-----------------------------------------------------------*/
#if (configCOMPILER==configCOMPILER_ARM_KEIL)
#if configCPU_FAMILY_IS_ARM_M4_M7(configCPU_FAMILY) /* Cortex M4 or M7 */
#if !MCUC1_CONFIG_PEX_SDK_USED /* the SDK expects different interrupt handler names */
__asm void PendSV_Handler(void) {
#else
__asm void vPortPendSVHandler(void) {
#endif
PRESERVE8
EXTERN pxCurrentTCB
EXTERN vTaskSwitchContext
mrs r0, psp
ldr r3, =pxCurrentTCB /* Get the location of the current TCB. */
ldr r2, [r3]
#if configCPU_FAMILY_IS_ARM_FPU(configCPU_FAMILY)
tst r14, #0x10 /* Is the task using the FPU context? If so, push high vfp registers. */
it eq
vstmdbeq r0!, {s16-s31}
stmdb r0!, {r4-r11, r14} /* save remaining core registers */
#else
stmdb r0!, {r4-r11} /* Save the core registers. */
#endif
str r0, [r2] /* Save the new top of stack into the first member of the TCB. */
stmdb sp!, {r3, r14}
mov r0, #configMAX_SYSCALL_INTERRUPT_PRIORITY
msr basepri, r0
bl vTaskSwitchContext
mov r0, #0
msr basepri, r0
ldmia sp!, {r3, r14}
ldr r1, [r3] /* The first item in pxCurrentTCB is the task top of stack. */
ldr r0, [r1]
#if configCPU_FAMILY_IS_ARM_FPU(configCPU_FAMILY)
ldmia r0!, {r4-r11, r14} /* Pop the core registers */
tst r14, #0x10 /* Is the task using the FPU context? If so, pop the high vfp registers too. */
it eq
vldmiaeq r0!, {s16-s31}
#else
ldmia r0!, {r4-r11} /* Pop the core registers. */
#endif
msr psp, r0
bx r14
nop
}
#elif configCPU_FAMILY_IS_ARM_M0(configCPU_FAMILY) /* Keil: Cortex M0+ */
#if !MCUC1_CONFIG_PEX_SDK_USED /* the SDK expects different interrupt handler names */
__asm void PendSV_Handler(void) {
#else
__asm void vPortPendSVHandler(void) {
#endif
EXTERN pxCurrentTCB
EXTERN vTaskSwitchContext
mrs r0, psp
ldr r3, =pxCurrentTCB /* Get the location of the current TCB. */
ldr r2, [r3]
subs r0, #32 /* Make space for the remaining low registers. */
str r0, [r2] /* Save the new top of stack. */
stmia r0!, {r4-r7} /* Store the low registers that are not saved automatically. */
mov r4, r8 /* Store the high registers. */
mov r5, r9
mov r6, r10
mov r7, r11
stmia r0!, {r4-r7}
push {r3, r14}
cpsid i
bl vTaskSwitchContext
cpsie i
pop {r2, r3} /* lr goes in r3. r2 now holds tcb pointer. */
ldr r1, [r2]
ldr r0, [r1] /* The first item in pxCurrentTCB is the task top of stack. */
adds r0, #16 /* Move to the high registers. */
ldmia r0!, {r4-r7} /* Pop the high registers. */
mov r8, r4
mov r9, r5
mov r10, r6
mov r11, r7
msr psp, r0 /* Remember the new top of stack for the task. */
subs r0, #32 /* Go back for the low registers that are not automatically restored. */
ldmia r0!, {r4-r7} /* Pop low registers. */
bx r3
nop
}
#endif
#endif /* (configCOMPILER==configCOMPILER_ARM_KEIL) */
/*-----------------------------------------------------------*/
#if (configCOMPILER==configCOMPILER_ARM_GCC)
#if configGDB_HELPER
/* prototypes to avoid compiler warnings */
__attribute__ ((naked)) void vPortPendSVHandler_native(void);
__attribute__ ((naked)) void PendSV_Handler_jumper(void);
__attribute__ ((naked)) void vPortPendSVHandler_native(void) {
#elif !MCUC1_CONFIG_PEX_SDK_USED /* the SDK expects different interrupt handler names */
__attribute__ ((naked)) void PendSV_Handler(void) {
#else
__attribute__ ((naked)) void vPortPendSVHandler(void) {
#endif
#if configCPU_FAMILY_IS_ARM_M4_M7(configCPU_FAMILY) /* Cortex M4 or M7*/
__asm volatile (
" mrs r0, psp \n"
" ldr r3, pxCurrentTCBConst \n" /* Get the location of the current TCB. */
" ldr r2, [r3] \n"
#if configCPU_FAMILY_IS_ARM_FPU(configCPU_FAMILY)
" tst r14, #0x10 \n" /* Is the task using the FPU context? If so, push high vfp registers. */
" it eq \n"
" vstmdbeq r0!, {s16-s31} \n"
" stmdb r0!, {r4-r11, r14} \n" /* save remaining core registers */
#else
" stmdb r0!, {r4-r11} \n" /* Save the core registers. */
#endif
" str r0, [r2] \n" /* Save the new top of stack into the first member of the TCB. */
" stmdb sp!, {r3, r14} \n"
" mov r0, %0 \n"
" msr basepri, r0 \n"
" bl vTaskSwitchContext \n"
" mov r0, #0 \n"
" msr basepri, r0 \n"
" ldmia sp!, {r3, r14} \n"
" ldr r1, [r3] \n" /* The first item in pxCurrentTCB is the task top of stack. */
" ldr r0, [r1] \n"
#if configCPU_FAMILY_IS_ARM_FPU(configCPU_FAMILY)
" ldmia r0!, {r4-r11, r14} \n" /* Pop the core registers */
" tst r14, #0x10 \n" /* Is the task using the FPU context? If so, pop the high vfp registers too. */
" it eq \n"
" vldmiaeq r0!, {s16-s31} \n"
#else
" ldmia r0!, {r4-r11} \n" /* Pop the core registers. */
#endif
" msr psp, r0 \n"
" bx r14 \n"
" \n"
" .align 2 \n"
"pxCurrentTCBConst: .word pxCurrentTCB \n"
::"i"(configMAX_SYSCALL_INTERRUPT_PRIORITY)
);
#else /* Cortex M0+ */
__asm volatile (
" mrs r0, psp \n"
" \n"
" ldr r3, pxCurrentTCBConst \n" /* Get the location of the current TCB. */
" ldr r2, [r3] \n"
" \n"
" sub r0, r0, #32 \n" /* Make space for the remaining low registers. */
" str r0, [r2] \n" /* Save the new top of stack. */
" stmia r0!, {r4-r7} \n" /* Store the low registers that are not saved automatically. */
" mov r4, r8 \n" /* Store the high registers. */
" mov r5, r9 \n"
" mov r6, r10 \n"
" mov r7, r11 \n"
" stmia r0!, {r4-r7} \n"
" \n"
" push {r3, r14} \n"
" cpsid i \n"
" bl vTaskSwitchContext \n"
" cpsie i \n"
" pop {r2, r3} \n" /* lr goes in r3. r2 now holds tcb pointer. */
" \n"
" ldr r1, [r2] \n"
" ldr r0, [r1] \n" /* The first item in pxCurrentTCB is the task top of stack. */
" add r0, r0, #16 \n" /* Move to the high registers. */
" ldmia r0!, {r4-r7} \n" /* Pop the high registers. */
" mov r8, r4 \n"
" mov r9, r5 \n"
" mov r10, r6 \n"
" mov r11, r7 \n"
" \n"
" msr psp, r0 \n" /* Remember the new top of stack for the task. */
" \n"
" sub r0, r0, #32 \n" /* Go back for the low registers that are not automatically restored. */
" ldmia r0!, {r4-r7} \n" /* Pop low registers. */
" \n"
" bx r3 \n"
" \n"
".align 2 \n"
"pxCurrentTCBConst: .word pxCurrentTCB"
);
#endif
}
#if configUSE_TOP_USED_PRIORITY || configLTO_HELPER
/* This is only really needed for debugging with openOCD:
* Since at least FreeRTOS V7.5.3 uxTopUsedPriority is no longer
* present in the kernel, so it has to be supplied by other means for
* OpenOCD's threads awareness.
*
* Add this file to your project, and, if you're using --gc-sections,
* ``--undefined=uxTopUsedPriority'' (or
* ``-Wl,--undefined=uxTopUsedPriority'' when using gcc for final
* linking) to your LDFLAGS; same with all the other symbols you need.
*/
volatile const int
#ifdef __GNUC__
__attribute__((used))
#endif
uxTopUsedPriority = configMAX_PRIORITIES-1;
#endif
#if configGDB_HELPER /* if GDB debug helper is enabled */
/* Credits to:
* - Artem Pisarneko for his initial contribution
* - Prasana for the PendSVHandler updates
* - Geoffrey Wossum for the Cortex-M4 contribution
*/
/* Switch control variable:
* 0 - no hook installed (normal execution),
* 1 - hook installation performed,
* 2 - following hooked switches
*/
int volatile dbgPendSVHookState = 0;
/* Requested target task handle variable */
void *volatile dbgPendingTaskHandle;
const int volatile dbgFreeRTOSConfig_suspend_value = INCLUDE_vTaskSuspend;
const int volatile dbgFreeRTOSConfig_delete_value = INCLUDE_vTaskDelete;
__attribute__ ((naked)) void PendSV_Handler_jumper(void) {
__asm volatile("b vPortPendSVHandler_native \n");
}
#if !MCUC1_CONFIG_PEX_SDK_USED /* the SDK expects different interrupt handler names */
__attribute__ ((naked)) void PendSV_Handler(void) {
#else
__attribute__ ((naked)) void vPortPendSVHandler(void) {
#endif
#if configCPU_FAMILY_IS_ARM_M4_M7(configCPU_FAMILY) /* Cortex M4 or M7 */
__asm volatile (
#if configGDB_HELPER
" ldr r1, _dbgPendSVHookState \n" /* Check hook installed */
" ldr r0, [r1] \n"
" cmp r0, #0 \n"
" beq PendSV_Handler_jumper \n" /* if no hook installed then jump to native handler, else proceed... */
" cmp r0, #1 \n" /* check whether hook triggered for the first time... */
" bne dbg_switch_to_pending_task \n" /* if not so, then jump to switching right now, otherwise current task context must be saved first... */
" mov r0, #2 \n" /* mark hook after triggered for the first time */
" str r0, [r1] \n"
#endif /* configGDB_HELPER */
" mrs r0, psp \n"
" ldr r3, pxCurrentTCBConstG \n" /* Get the location of the current TCB. */
" ldr r2, [r3] \n"
#if configCPU_FAMILY_IS_ARM_FPU(configCPU_FAMILY)
" tst r14, #0x10 \n" /* Is the task using the FPU context? If so, push high vfp registers. */
" it eq \n"
" vstmdbeq r0!, {s16-s31} \n"
" stmdb r0!, {r4-r11, r14} \n" /* save remaining core registers */
#else
" stmdb r0!, {r4-r11} \n" /* Save the core registers. */
#endif
" str r0, [r2] \n" /* Save the new top of stack into the first member of the TCB. */
" stmdb sp!, {r3, r14} \n"
" mov r0, %0 \n"
" msr basepri, r0 \n"
" bl vTaskSwitchContext \n"
" mov r0, #0 \n"
" msr basepri, r0 \n"
" ldmia sp!, {r3, r14} \n"
#if configGDB_HELPER
"dbg_switch_to_pending_task: \n"
" ldr r3, _dbgPendingTaskHandle \n" /* --> Load task handle going to switch to <-- */
#endif /* configGDB_HELPER */
" ldr r1, [r3] \n" /* The first item in pxCurrentTCB is the task top of stack. */
" ldr r0, [r1] \n"
#if configCPU_FAMILY_IS_ARM_FPU(configCPU_FAMILY)
" ldmia r0!, {r4-r11, r14} \n" /* Pop the core registers */
" tst r14, #0x10 \n" /* Is the task using the FPU context? If so, pop the high vfp registers too. */
" it eq \n"
" vldmiaeq r0!, {s16-s31} \n"
#else
" ldmia r0!, {r4-r11} \n" /* Pop the core registers. */
#endif
" msr psp, r0 \n"
#if configGDB_HELPER
" bkpt \n" /* <-- here debugger stops and steps out to target task context */
#endif /* configGDB_HELPER */
" bx r14 \n"
" \n"
" .align 2 \n"
"pxCurrentTCBConstG: .word pxCurrentTCB \n"
#if configGDB_HELPER
"_dbgPendSVHookState: .word dbgPendSVHookState \n"
"_dbgPendingTaskHandle: .word dbgPendingTaskHandle \n"
".word dbgFreeRTOSConfig_suspend_value \n" /* force keep these symbols from cutting away by linker garbage collector */
".word dbgFreeRTOSConfig_delete_value \n"
#endif
::"i"(configMAX_SYSCALL_INTERRUPT_PRIORITY)
);
#else /* Cortex M0+ */
__asm volatile (
" mrs r0, psp \n"
" \n"
" ldr r3, pxCurrentTCBConstG \n" /* Get the location of the current TCB. */
" ldr r2, [r3] \n"
" \n"
" sub r0, r0, #32 \n" /* Make space for the remaining low registers. */
" str r0, [r2] \n" /* Save the new top of stack. */
" stmia r0!, {r4-r7} \n" /* Store the low registers that are not saved automatically. */
" mov r4, r8 \n" /* Store the high registers. */
" mov r5, r9 \n"
" mov r6, r10 \n"
" mov r7, r11 \n"
" stmia r0!, {r4-r7} \n"
" \n"
" push {r3, r14} \n"
" cpsid i \n"
" bl vTaskSwitchContext \n"
" cpsie i \n"
" pop {r2, r3} \n" /* lr goes in r3. r2 now holds tcb pointer. */
" \n"
" ldr r1, [r2] \n"
" ldr r0, [r1] \n" /* The first item in pxCurrentTCB is the task top of stack. */
" add r0, r0, #16 \n" /* Move to the high registers. */
" ldmia r0!, {r4-r7} \n" /* Pop the high registers. */
" mov r8, r4 \n"
" mov r9, r5 \n"
" mov r10, r6 \n"
" mov r11, r7 \n"
" \n"
" msr psp, r0 \n" /* Remember the new top of stack for the task. */
" \n"
" sub r0, r0, #32 \n" /* Go back for the low registers that are not automatically restored. */
" ldmia r0!, {r4-r7} \n" /* Pop low registers. */
" \n"
" bx r3 \n"
" \n"
".align 2 \n"
"pxCurrentTCBConstG: .word pxCurrentTCB"
);
#endif
}
#endif /* configGDB_HELPER */
#endif /* (configCOMPILER==configCOMPILER_ARM_GCC) */
/*-----------------------------------------------------------*/
#if configCPU_FAMILY_IS_ARM_M4_M7(configCPU_FAMILY) /* ARM M4(F) or M7 core */
#if configCOMPILER==configCOMPILER_ARM_KEIL
__asm uint32_t vPortGetIPSR(void) {
PRESERVE8
mrs r0, ipsr
bx r14
}
#endif
#if( configASSERT_DEFINED == 1 )
void vPortValidateInterruptPriority( void )
{
uint32_t ulCurrentInterrupt;
uint8_t ucCurrentPriority;
/* Obtain the number of the currently executing interrupt. */
#if configCOMPILER==configCOMPILER_ARM_KEIL
ulCurrentInterrupt = vPortGetIPSR();
#else
__asm volatile( "mrs %0, ipsr" : "=r"( ulCurrentInterrupt ) );
#endif
/* Is the interrupt number a user defined interrupt? */
if( ulCurrentInterrupt >= portFIRST_USER_INTERRUPT_NUMBER )
{
/* Look up the interrupt's priority. */
ucCurrentPriority = pcInterruptPriorityRegisters[ ulCurrentInterrupt ];
/* The following assertion will fail if a service routine (ISR) for
an interrupt that has been assigned a priority above
configMAX_SYSCALL_INTERRUPT_PRIORITY calls an ISR safe FreeRTOS API
function. ISR safe FreeRTOS API functions must *only* be called
from interrupts that have been assigned a priority at or below
configMAX_SYSCALL_INTERRUPT_PRIORITY.
Numerically low interrupt priority numbers represent logically high
interrupt priorities, therefore the priority of the interrupt must
be set to a value equal to or numerically *higher* than
configMAX_SYSCALL_INTERRUPT_PRIORITY.
Interrupts that use the FreeRTOS API must not be left at their
default priority of zero as that is the highest possible priority,
which is guaranteed to be above configMAX_SYSCALL_INTERRUPT_PRIORITY,
and therefore also guaranteed to be invalid.
FreeRTOS maintains separate thread and ISR API functions to ensure
interrupt entry is as fast and simple as possible.
The following links provide detailed information:
http://www.freertos.org/RTOS-Cortex-M3-M4.html
http://www.freertos.org/FAQHelp.html */
configASSERT( ucCurrentPriority >= ucMaxSysCallPriority );
}
/* Priority grouping: The interrupt controller (NVIC) allows the bits
that define each interrupt's priority to be split between bits that
define the interrupt's pre-emption priority bits and bits that define
the interrupt's sub-priority. For simplicity all bits must be defined
to be pre-emption priority bits. The following assertion will fail if
this is not the case (if some bits represent a sub-priority).
If the application only uses CMSIS libraries for interrupt
configuration then the correct setting can be achieved on all Cortex-M
devices by calling NVIC_SetPriorityGrouping( 0 ); before starting the
scheduler. Note however that some vendor specific peripheral libraries
assume a non-zero priority group setting, in which cases using a value
of zero will result in unpredicable behaviour. */
configASSERT( ( portAIRCR_REG & portPRIORITY_GROUP_MASK ) <= ulMaxPRIGROUPValue );
}
#endif /* configASSERT_DEFINED */
#endif /* ARM M4(F) core */
|
a9f1fa83a6ebe196114eff9963581406ddeb265e
|
7eaf54a78c9e2117247cb2ab6d3a0c20719ba700
|
/SOFTWARE/A64-TERES/linux-a64/drivers/mfd/lp8788.c
|
c3d3c9b4d3addedc53bc5b7450cd45a2e4707a72
|
[
"LicenseRef-scancode-free-unknown",
"Apache-2.0",
"Linux-syscall-note",
"GPL-2.0-only",
"GPL-1.0-or-later"
] |
permissive
|
OLIMEX/DIY-LAPTOP
|
ae82f4ee79c641d9aee444db9a75f3f6709afa92
|
a3fafd1309135650bab27f5eafc0c32bc3ca74ee
|
refs/heads/rel3
| 2023-08-04T01:54:19.483792
| 2023-04-03T07:18:12
| 2023-04-03T07:18:12
| 80,094,055
| 507
| 92
|
Apache-2.0
| 2023-04-03T07:05:59
| 2017-01-26T07:25:50
|
C
|
UTF-8
|
C
| false
| false
| 5,384
|
c
|
lp8788.c
|
/*
* TI LP8788 MFD - core interface
*
* Copyright 2012 Texas Instruments
*
* Author: Milo(Woogyom) Kim <milo.kim@ti.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
*/
#include <linux/err.h>
#include <linux/i2c.h>
#include <linux/mfd/core.h>
#include <linux/mfd/lp8788.h>
#include <linux/module.h>
#include <linux/slab.h>
#define MAX_LP8788_REGISTERS 0xA2
#define MFD_DEV_SIMPLE(_name) \
{ \
.name = LP8788_DEV_##_name, \
}
#define MFD_DEV_WITH_ID(_name, _id) \
{ \
.name = LP8788_DEV_##_name, \
.id = _id, \
}
#define MFD_DEV_WITH_RESOURCE(_name, _resource, num_resource) \
{ \
.name = LP8788_DEV_##_name, \
.resources = _resource, \
.num_resources = num_resource, \
}
static struct resource chg_irqs[] = {
/* Charger Interrupts */
{
.start = LP8788_INT_CHG_INPUT_STATE,
.end = LP8788_INT_PRECHG_TIMEOUT,
.name = LP8788_CHG_IRQ,
.flags = IORESOURCE_IRQ,
},
/* Power Routing Switch Interrupts */
{
.start = LP8788_INT_ENTER_SYS_SUPPORT,
.end = LP8788_INT_EXIT_SYS_SUPPORT,
.name = LP8788_PRSW_IRQ,
.flags = IORESOURCE_IRQ,
},
/* Battery Interrupts */
{
.start = LP8788_INT_BATT_LOW,
.end = LP8788_INT_NO_BATT,
.name = LP8788_BATT_IRQ,
.flags = IORESOURCE_IRQ,
},
};
static struct resource rtc_irqs[] = {
{
.start = LP8788_INT_RTC_ALARM1,
.end = LP8788_INT_RTC_ALARM2,
.name = LP8788_ALM_IRQ,
.flags = IORESOURCE_IRQ,
},
};
static struct mfd_cell lp8788_devs[] = {
/* 4 bucks */
MFD_DEV_WITH_ID(BUCK, 1),
MFD_DEV_WITH_ID(BUCK, 2),
MFD_DEV_WITH_ID(BUCK, 3),
MFD_DEV_WITH_ID(BUCK, 4),
/* 12 digital ldos */
MFD_DEV_WITH_ID(DLDO, 1),
MFD_DEV_WITH_ID(DLDO, 2),
MFD_DEV_WITH_ID(DLDO, 3),
MFD_DEV_WITH_ID(DLDO, 4),
MFD_DEV_WITH_ID(DLDO, 5),
MFD_DEV_WITH_ID(DLDO, 6),
MFD_DEV_WITH_ID(DLDO, 7),
MFD_DEV_WITH_ID(DLDO, 8),
MFD_DEV_WITH_ID(DLDO, 9),
MFD_DEV_WITH_ID(DLDO, 10),
MFD_DEV_WITH_ID(DLDO, 11),
MFD_DEV_WITH_ID(DLDO, 12),
/* 10 analog ldos */
MFD_DEV_WITH_ID(ALDO, 1),
MFD_DEV_WITH_ID(ALDO, 2),
MFD_DEV_WITH_ID(ALDO, 3),
MFD_DEV_WITH_ID(ALDO, 4),
MFD_DEV_WITH_ID(ALDO, 5),
MFD_DEV_WITH_ID(ALDO, 6),
MFD_DEV_WITH_ID(ALDO, 7),
MFD_DEV_WITH_ID(ALDO, 8),
MFD_DEV_WITH_ID(ALDO, 9),
MFD_DEV_WITH_ID(ALDO, 10),
/* ADC */
MFD_DEV_SIMPLE(ADC),
/* battery charger */
MFD_DEV_WITH_RESOURCE(CHARGER, chg_irqs, ARRAY_SIZE(chg_irqs)),
/* rtc */
MFD_DEV_WITH_RESOURCE(RTC, rtc_irqs, ARRAY_SIZE(rtc_irqs)),
/* backlight */
MFD_DEV_SIMPLE(BACKLIGHT),
/* current sink for vibrator */
MFD_DEV_SIMPLE(VIBRATOR),
/* current sink for keypad LED */
MFD_DEV_SIMPLE(KEYLED),
};
int lp8788_read_byte(struct lp8788 *lp, u8 reg, u8 *data)
{
int ret;
unsigned int val;
ret = regmap_read(lp->regmap, reg, &val);
if (ret < 0) {
dev_err(lp->dev, "failed to read 0x%.2x\n", reg);
return ret;
}
*data = (u8)val;
return 0;
}
EXPORT_SYMBOL_GPL(lp8788_read_byte);
int lp8788_read_multi_bytes(struct lp8788 *lp, u8 reg, u8 *data, size_t count)
{
return regmap_bulk_read(lp->regmap, reg, data, count);
}
EXPORT_SYMBOL_GPL(lp8788_read_multi_bytes);
int lp8788_write_byte(struct lp8788 *lp, u8 reg, u8 data)
{
return regmap_write(lp->regmap, reg, data);
}
EXPORT_SYMBOL_GPL(lp8788_write_byte);
int lp8788_update_bits(struct lp8788 *lp, u8 reg, u8 mask, u8 data)
{
return regmap_update_bits(lp->regmap, reg, mask, data);
}
EXPORT_SYMBOL_GPL(lp8788_update_bits);
static int lp8788_platform_init(struct lp8788 *lp)
{
struct lp8788_platform_data *pdata = lp->pdata;
return (pdata && pdata->init_func) ? pdata->init_func(lp) : 0;
}
static const struct regmap_config lp8788_regmap_config = {
.reg_bits = 8,
.val_bits = 8,
.max_register = MAX_LP8788_REGISTERS,
};
static int lp8788_probe(struct i2c_client *cl, const struct i2c_device_id *id)
{
struct lp8788 *lp;
struct lp8788_platform_data *pdata = cl->dev.platform_data;
int ret;
lp = devm_kzalloc(&cl->dev, sizeof(struct lp8788), GFP_KERNEL);
if (!lp)
return -ENOMEM;
lp->regmap = devm_regmap_init_i2c(cl, &lp8788_regmap_config);
if (IS_ERR(lp->regmap)) {
ret = PTR_ERR(lp->regmap);
dev_err(&cl->dev, "regmap init i2c err: %d\n", ret);
return ret;
}
lp->pdata = pdata;
lp->dev = &cl->dev;
i2c_set_clientdata(cl, lp);
ret = lp8788_platform_init(lp);
if (ret)
return ret;
ret = lp8788_irq_init(lp, cl->irq);
if (ret)
return ret;
return mfd_add_devices(lp->dev, -1, lp8788_devs,
ARRAY_SIZE(lp8788_devs), NULL, 0, NULL);
}
static int lp8788_remove(struct i2c_client *cl)
{
struct lp8788 *lp = i2c_get_clientdata(cl);
mfd_remove_devices(lp->dev);
lp8788_irq_exit(lp);
return 0;
}
static const struct i2c_device_id lp8788_ids[] = {
{"lp8788", 0},
{ }
};
MODULE_DEVICE_TABLE(i2c, lp8788_ids);
static struct i2c_driver lp8788_driver = {
.driver = {
.name = "lp8788",
.owner = THIS_MODULE,
},
.probe = lp8788_probe,
.remove = lp8788_remove,
.id_table = lp8788_ids,
};
static int __init lp8788_init(void)
{
return i2c_add_driver(&lp8788_driver);
}
subsys_initcall(lp8788_init);
static void __exit lp8788_exit(void)
{
i2c_del_driver(&lp8788_driver);
}
module_exit(lp8788_exit);
MODULE_DESCRIPTION("TI LP8788 MFD Driver");
MODULE_AUTHOR("Milo Kim");
MODULE_LICENSE("GPL");
|
76619c18746a08602cd1507fca518f499e043624
|
7eaf54a78c9e2117247cb2ab6d3a0c20719ba700
|
/SOFTWARE/A64-TERES/linux-a64/drivers/ipack/devices/scc2698.h
|
2ad6acd513fa9fe5f75ea726d235b9567db402d1
|
[
"LicenseRef-scancode-free-unknown",
"Apache-2.0",
"Linux-syscall-note",
"GPL-2.0-only",
"GPL-1.0-or-later"
] |
permissive
|
OLIMEX/DIY-LAPTOP
|
ae82f4ee79c641d9aee444db9a75f3f6709afa92
|
a3fafd1309135650bab27f5eafc0c32bc3ca74ee
|
refs/heads/rel3
| 2023-08-04T01:54:19.483792
| 2023-04-03T07:18:12
| 2023-04-03T07:18:12
| 80,094,055
| 507
| 92
|
Apache-2.0
| 2023-04-03T07:05:59
| 2017-01-26T07:25:50
|
C
|
UTF-8
|
C
| false
| false
| 8,803
|
h
|
scc2698.h
|
/*
* scc2698.h
*
* driver for the IPOCTAL boards
*
* Copyright (C) 2009-2012 CERN (www.cern.ch)
* Author: Nicolas Serafini, EIC2 SA
* Author: Samuel Iglesias Gonsalvez <siglesias@igalia.com>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; version 2 of the License.
*/
#ifndef SCC2698_H_
#define SCC2698_H_
/*
* union scc2698_channel - Channel access to scc2698 IO
*
* dn value are only spacer.
*
*/
union scc2698_channel {
struct {
u8 d0, mr; /* Mode register 1/2*/
u8 d1, sr; /* Status register */
u8 d2, r1; /* reserved */
u8 d3, rhr; /* Receive holding register (R) */
u8 junk[8]; /* other crap for block control */
} __packed r; /* Read access */
struct {
u8 d0, mr; /* Mode register 1/2 */
u8 d1, csr; /* Clock select register */
u8 d2, cr; /* Command register */
u8 d3, thr; /* Transmit holding register */
u8 junk[8]; /* other crap for block control */
} __packed w; /* Write access */
};
/*
* union scc2698_block - Block access to scc2698 IO
*
* The scc2698 contain 4 block.
* Each block containt two channel a and b.
* dn value are only spacer.
*
*/
union scc2698_block {
struct {
u8 d0, mra; /* Mode register 1/2 (a) */
u8 d1, sra; /* Status register (a) */
u8 d2, r1; /* reserved */
u8 d3, rhra; /* Receive holding register (a) */
u8 d4, ipcr; /* Input port change register of block */
u8 d5, isr; /* Interrupt status register of block */
u8 d6, ctur; /* Counter timer upper register of block */
u8 d7, ctlr; /* Counter timer lower register of block */
u8 d8, mrb; /* Mode register 1/2 (b) */
u8 d9, srb; /* Status register (b) */
u8 da, r2; /* reserved */
u8 db, rhrb; /* Receive holding register (b) */
u8 dc, r3; /* reserved */
u8 dd, ip; /* Input port register of block */
u8 de, ctg; /* Start counter timer of block */
u8 df, cts; /* Stop counter timer of block */
} __packed r; /* Read access */
struct {
u8 d0, mra; /* Mode register 1/2 (a) */
u8 d1, csra; /* Clock select register (a) */
u8 d2, cra; /* Command register (a) */
u8 d3, thra; /* Transmit holding register (a) */
u8 d4, acr; /* Auxiliary control register of block */
u8 d5, imr; /* Interrupt mask register of block */
u8 d6, ctu; /* Counter timer upper register of block */
u8 d7, ctl; /* Counter timer lower register of block */
u8 d8, mrb; /* Mode register 1/2 (b) */
u8 d9, csrb; /* Clock select register (a) */
u8 da, crb; /* Command register (b) */
u8 db, thrb; /* Transmit holding register (b) */
u8 dc, r1; /* reserved */
u8 dd, opcr; /* Output port configuration register of block */
u8 de, r2; /* reserved */
u8 df, r3; /* reserved */
} __packed w; /* Write access */
};
#define MR1_CHRL_5_BITS (0x0 << 0)
#define MR1_CHRL_6_BITS (0x1 << 0)
#define MR1_CHRL_7_BITS (0x2 << 0)
#define MR1_CHRL_8_BITS (0x3 << 0)
#define MR1_PARITY_EVEN (0x1 << 2)
#define MR1_PARITY_ODD (0x0 << 2)
#define MR1_PARITY_ON (0x0 << 3)
#define MR1_PARITY_FORCE (0x1 << 3)
#define MR1_PARITY_OFF (0x2 << 3)
#define MR1_PARITY_SPECIAL (0x3 << 3)
#define MR1_ERROR_CHAR (0x0 << 5)
#define MR1_ERROR_BLOCK (0x1 << 5)
#define MR1_RxINT_RxRDY (0x0 << 6)
#define MR1_RxINT_FFULL (0x1 << 6)
#define MR1_RxRTS_CONTROL_ON (0x1 << 7)
#define MR1_RxRTS_CONTROL_OFF (0x0 << 7)
#define MR2_STOP_BITS_LENGTH_1 (0x7 << 0)
#define MR2_STOP_BITS_LENGTH_2 (0xF << 0)
#define MR2_CTS_ENABLE_TX_ON (0x1 << 4)
#define MR2_CTS_ENABLE_TX_OFF (0x0 << 4)
#define MR2_TxRTS_CONTROL_ON (0x1 << 5)
#define MR2_TxRTS_CONTROL_OFF (0x0 << 5)
#define MR2_CH_MODE_NORMAL (0x0 << 6)
#define MR2_CH_MODE_ECHO (0x1 << 6)
#define MR2_CH_MODE_LOCAL (0x2 << 6)
#define MR2_CH_MODE_REMOTE (0x3 << 6)
#define CR_ENABLE_RX (0x1 << 0)
#define CR_DISABLE_RX (0x1 << 1)
#define CR_ENABLE_TX (0x1 << 2)
#define CR_DISABLE_TX (0x1 << 3)
#define CR_CMD_RESET_MR (0x1 << 4)
#define CR_CMD_RESET_RX (0x2 << 4)
#define CR_CMD_RESET_TX (0x3 << 4)
#define CR_CMD_RESET_ERR_STATUS (0x4 << 4)
#define CR_CMD_RESET_BREAK_CHANGE (0x5 << 4)
#define CR_CMD_START_BREAK (0x6 << 4)
#define CR_CMD_STOP_BREAK (0x7 << 4)
#define CR_CMD_ASSERT_RTSN (0x8 << 4)
#define CR_CMD_NEGATE_RTSN (0x9 << 4)
#define CR_CMD_SET_TIMEOUT_MODE (0xA << 4)
#define CR_CMD_DISABLE_TIMEOUT_MODE (0xC << 4)
#define SR_RX_READY (0x1 << 0)
#define SR_FIFO_FULL (0x1 << 1)
#define SR_TX_READY (0x1 << 2)
#define SR_TX_EMPTY (0x1 << 3)
#define SR_OVERRUN_ERROR (0x1 << 4)
#define SR_PARITY_ERROR (0x1 << 5)
#define SR_FRAMING_ERROR (0x1 << 6)
#define SR_RECEIVED_BREAK (0x1 << 7)
#define SR_ERROR (0xF0)
#define ACR_DELTA_IP0_IRQ_EN (0x1 << 0)
#define ACR_DELTA_IP1_IRQ_EN (0x1 << 1)
#define ACR_DELTA_IP2_IRQ_EN (0x1 << 2)
#define ACR_DELTA_IP3_IRQ_EN (0x1 << 3)
#define ACR_CT_Mask (0x7 << 4)
#define ACR_CExt (0x0 << 4)
#define ACR_CTxCA (0x1 << 4)
#define ACR_CTxCB (0x2 << 4)
#define ACR_CClk16 (0x3 << 4)
#define ACR_TExt (0x4 << 4)
#define ACR_TExt16 (0x5 << 4)
#define ACR_TClk (0x6 << 4)
#define ACR_TClk16 (0x7 << 4)
#define ACR_BRG_SET1 (0x0 << 7)
#define ACR_BRG_SET2 (0x1 << 7)
#define TX_CLK_75 (0x0 << 0)
#define TX_CLK_110 (0x1 << 0)
#define TX_CLK_38400 (0x2 << 0)
#define TX_CLK_150 (0x3 << 0)
#define TX_CLK_300 (0x4 << 0)
#define TX_CLK_600 (0x5 << 0)
#define TX_CLK_1200 (0x6 << 0)
#define TX_CLK_2000 (0x7 << 0)
#define TX_CLK_2400 (0x8 << 0)
#define TX_CLK_4800 (0x9 << 0)
#define TX_CLK_1800 (0xA << 0)
#define TX_CLK_9600 (0xB << 0)
#define TX_CLK_19200 (0xC << 0)
#define RX_CLK_75 (0x0 << 4)
#define RX_CLK_110 (0x1 << 4)
#define RX_CLK_38400 (0x2 << 4)
#define RX_CLK_150 (0x3 << 4)
#define RX_CLK_300 (0x4 << 4)
#define RX_CLK_600 (0x5 << 4)
#define RX_CLK_1200 (0x6 << 4)
#define RX_CLK_2000 (0x7 << 4)
#define RX_CLK_2400 (0x8 << 4)
#define RX_CLK_4800 (0x9 << 4)
#define RX_CLK_1800 (0xA << 4)
#define RX_CLK_9600 (0xB << 4)
#define RX_CLK_19200 (0xC << 4)
#define OPCR_MPOa_RTSN (0x0 << 0)
#define OPCR_MPOa_C_TO (0x1 << 0)
#define OPCR_MPOa_TxC1X (0x2 << 0)
#define OPCR_MPOa_TxC16X (0x3 << 0)
#define OPCR_MPOa_RxC1X (0x4 << 0)
#define OPCR_MPOa_RxC16X (0x5 << 0)
#define OPCR_MPOa_TxRDY (0x6 << 0)
#define OPCR_MPOa_RxRDY_FF (0x7 << 0)
#define OPCR_MPOb_RTSN (0x0 << 4)
#define OPCR_MPOb_C_TO (0x1 << 4)
#define OPCR_MPOb_TxC1X (0x2 << 4)
#define OPCR_MPOb_TxC16X (0x3 << 4)
#define OPCR_MPOb_RxC1X (0x4 << 4)
#define OPCR_MPOb_RxC16X (0x5 << 4)
#define OPCR_MPOb_TxRDY (0x6 << 4)
#define OPCR_MPOb_RxRDY_FF (0x7 << 4)
#define OPCR_MPP_INPUT (0x0 << 7)
#define OPCR_MPP_OUTPUT (0x1 << 7)
#define IMR_TxRDY_A (0x1 << 0)
#define IMR_RxRDY_FFULL_A (0x1 << 1)
#define IMR_DELTA_BREAK_A (0x1 << 2)
#define IMR_COUNTER_READY (0x1 << 3)
#define IMR_TxRDY_B (0x1 << 4)
#define IMR_RxRDY_FFULL_B (0x1 << 5)
#define IMR_DELTA_BREAK_B (0x1 << 6)
#define IMR_INPUT_PORT_CHANGE (0x1 << 7)
#define ISR_TxRDY_A (0x1 << 0)
#define ISR_RxRDY_FFULL_A (0x1 << 1)
#define ISR_DELTA_BREAK_A (0x1 << 2)
#define ISR_COUNTER_READY (0x1 << 3)
#define ISR_TxRDY_B (0x1 << 4)
#define ISR_RxRDY_FFULL_B (0x1 << 5)
#define ISR_DELTA_BREAK_B (0x1 << 6)
#define ISR_INPUT_PORT_CHANGE (0x1 << 7)
#define ACK_INT_REQ0 0
#define ACK_INT_REQ1 2
#endif /* SCC2698_H_ */
|
61d0e61749b8a5f2d3e2b8a185e3b2fda759a443
|
7eaf54a78c9e2117247cb2ab6d3a0c20719ba700
|
/SOFTWARE/A64-TERES/u-boot_new/arch/mips/cpu/mips32/cpu.c
|
278865b6fff54849c98b0e1bd69a7cc7b2e5ba6f
|
[
"LicenseRef-scancode-free-unknown",
"Apache-2.0",
"GPL-2.0-or-later"
] |
permissive
|
OLIMEX/DIY-LAPTOP
|
ae82f4ee79c641d9aee444db9a75f3f6709afa92
|
a3fafd1309135650bab27f5eafc0c32bc3ca74ee
|
refs/heads/rel3
| 2023-08-04T01:54:19.483792
| 2023-04-03T07:18:12
| 2023-04-03T07:18:12
| 80,094,055
| 507
| 92
|
Apache-2.0
| 2023-04-03T07:05:59
| 2017-01-26T07:25:50
|
C
|
UTF-8
|
C
| false
| false
| 3,280
|
c
|
cpu.c
|
/*
* (C) Copyright 2003
* Wolfgang Denk, DENX Software Engineering, <wd@denx.de>
*
* SPDX-License-Identifier: GPL-2.0+
*/
#include <common.h>
#include <command.h>
#include <netdev.h>
#include <asm/mipsregs.h>
#include <asm/cacheops.h>
#include <asm/reboot.h>
#define cache_op(op,addr) \
__asm__ __volatile__( \
" .set push \n" \
" .set noreorder \n" \
" .set mips3\n\t \n" \
" cache %0, %1 \n" \
" .set pop \n" \
: \
: "i" (op), "R" (*(unsigned char *)(addr)))
void __attribute__((weak)) _machine_restart(void)
{
}
int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
_machine_restart();
fprintf(stderr, "*** reset failed ***\n");
return 0;
}
#ifdef CONFIG_SYS_CACHELINE_SIZE
static inline unsigned long icache_line_size(void)
{
return CONFIG_SYS_CACHELINE_SIZE;
}
static inline unsigned long dcache_line_size(void)
{
return CONFIG_SYS_CACHELINE_SIZE;
}
#else /* !CONFIG_SYS_CACHELINE_SIZE */
static inline unsigned long icache_line_size(void)
{
unsigned long conf1, il;
conf1 = read_c0_config1();
il = (conf1 & MIPS_CONF1_IL) >> MIPS_CONF1_IL_SHIFT;
if (!il)
return 0;
return 2 << il;
}
static inline unsigned long dcache_line_size(void)
{
unsigned long conf1, dl;
conf1 = read_c0_config1();
dl = (conf1 & MIPS_CONF1_DL) >> MIPS_CONF1_DL_SHIFT;
if (!dl)
return 0;
return 2 << dl;
}
#endif /* !CONFIG_SYS_CACHELINE_SIZE */
void flush_cache(ulong start_addr, ulong size)
{
unsigned long ilsize = icache_line_size();
unsigned long dlsize = dcache_line_size();
unsigned long addr, aend;
/* aend will be miscalculated when size is zero, so we return here */
if (size == 0)
return;
addr = start_addr & ~(dlsize - 1);
aend = (start_addr + size - 1) & ~(dlsize - 1);
if (ilsize == dlsize) {
/* flush I-cache & D-cache simultaneously */
while (1) {
cache_op(HIT_WRITEBACK_INV_D, addr);
cache_op(HIT_INVALIDATE_I, addr);
if (addr == aend)
break;
addr += dlsize;
}
return;
}
/* flush D-cache */
while (1) {
cache_op(HIT_WRITEBACK_INV_D, addr);
if (addr == aend)
break;
addr += dlsize;
}
/* flush I-cache */
addr = start_addr & ~(ilsize - 1);
aend = (start_addr + size - 1) & ~(ilsize - 1);
while (1) {
cache_op(HIT_INVALIDATE_I, addr);
if (addr == aend)
break;
addr += ilsize;
}
}
void flush_dcache_range(ulong start_addr, ulong stop)
{
unsigned long lsize = dcache_line_size();
unsigned long addr = start_addr & ~(lsize - 1);
unsigned long aend = (stop - 1) & ~(lsize - 1);
while (1) {
cache_op(HIT_WRITEBACK_INV_D, addr);
if (addr == aend)
break;
addr += lsize;
}
}
void invalidate_dcache_range(ulong start_addr, ulong stop)
{
unsigned long lsize = dcache_line_size();
unsigned long addr = start_addr & ~(lsize - 1);
unsigned long aend = (stop - 1) & ~(lsize - 1);
while (1) {
cache_op(HIT_INVALIDATE_D, addr);
if (addr == aend)
break;
addr += lsize;
}
}
void write_one_tlb(int index, u32 pagemask, u32 hi, u32 low0, u32 low1)
{
write_c0_entrylo0(low0);
write_c0_pagemask(pagemask);
write_c0_entrylo1(low1);
write_c0_entryhi(hi);
write_c0_index(index);
tlb_write_indexed();
}
int cpu_eth_init(bd_t *bis)
{
#ifdef CONFIG_SOC_AU1X00
au1x00_enet_initialize(bis);
#endif
return 0;
}
|
29856203d7eeb78bd52b16a20a31ba6ef792e865
|
eecd5e4c50d8b78a769bcc2675250576bed34066
|
/src/mat/utils/pheap.c
|
74c211e2cdba22398395fbdb954f20187b789d26
|
[
"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
| 5,329
|
c
|
pheap.c
|
#include <petsc/private/petscimpl.h>
#include <petscviewer.h>
typedef struct {
PetscInt id;
PetscInt value;
} HeapNode;
struct _PetscHeap {
PetscInt end; /* one past the last item */
PetscInt alloc; /* length of array */
PetscInt stash; /* stash grows down, this points to last item */
HeapNode *base;
};
/*
The arity of the heap can be changed via the parameter B below. Consider the B=2 (arity=4 case below)
[00 (sentinel); 01 (min node); 10 (unused); 11 (unused); 0100 (first child); 0101; 0110; 0111; ...]
Slots 10 and 11 are referred to as the "hole" below in the implementation.
*/
#define B 1 /* log2(ARITY) */
#define ARITY (1 << B) /* tree branching factor */
static inline PetscInt Parent(PetscInt loc)
{
PetscInt p = loc >> B;
if (p < ARITY) return (PetscInt)(loc != 1); /* Parent(1) is 0, otherwise fix entries ending up in the hole */
return p;
}
#define Value(h, loc) ((h)->base[loc].value)
#define Id(h, loc) ((h)->base[loc].id)
static inline void Swap(PetscHeap h, PetscInt loc, PetscInt loc2)
{
PetscInt id, val;
id = Id(h, loc);
val = Value(h, loc);
h->base[loc].id = Id(h, loc2);
h->base[loc].value = Value(h, loc2);
h->base[loc2].id = id;
h->base[loc2].value = val;
}
static inline PetscInt MinChild(PetscHeap h, PetscInt loc)
{
PetscInt min, chld, left, right;
left = loc << B;
right = PetscMin(left + ARITY - 1, h->end - 1);
chld = 0;
min = PETSC_MAX_INT;
for (; left <= right; left++) {
PetscInt val = Value(h, left);
if (val < min) {
min = val;
chld = left;
}
}
return chld;
}
PetscErrorCode PetscHeapCreate(PetscInt maxsize, PetscHeap *heap)
{
PetscHeap h;
PetscFunctionBegin;
*heap = NULL;
PetscCall(PetscMalloc1(1, &h));
h->end = 1;
h->alloc = maxsize + ARITY; /* We waste all but one slot (loc=1) in the first ARITY slots */
h->stash = h->alloc;
PetscCall(PetscCalloc1(h->alloc, &h->base));
h->base[0].id = -1;
h->base[0].value = PETSC_MIN_INT;
*heap = h;
PetscFunctionReturn(PETSC_SUCCESS);
}
PetscErrorCode PetscHeapAdd(PetscHeap h, PetscInt id, PetscInt val)
{
PetscInt loc, par;
PetscFunctionBegin;
if (1 < h->end && h->end < ARITY) h->end = ARITY;
loc = h->end++;
PetscCheck(h->end <= h->stash, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Addition would exceed allocation %" PetscInt_FMT " (%" PetscInt_FMT " stashed)", h->alloc, (h->alloc - h->stash));
h->base[loc].id = id;
h->base[loc].value = val;
/* move up until heap condition is satisfied */
while ((void)(par = Parent(loc)), Value(h, par) > val) {
Swap(h, loc, par);
loc = par;
}
PetscFunctionReturn(PETSC_SUCCESS);
}
PetscErrorCode PetscHeapPop(PetscHeap h, PetscInt *id, PetscInt *val)
{
PetscInt loc, chld;
PetscFunctionBegin;
if (h->end == 1) {
*id = h->base[0].id;
*val = h->base[0].value;
PetscFunctionReturn(PETSC_SUCCESS);
}
*id = h->base[1].id;
*val = h->base[1].value;
/* rotate last entry into first position */
loc = --h->end;
if (h->end == ARITY) h->end = 2; /* Skip over hole */
h->base[1].id = Id(h, loc);
h->base[1].value = Value(h, loc);
/* move down until min heap condition is satisfied */
loc = 1;
while ((chld = MinChild(h, loc)) && Value(h, loc) > Value(h, chld)) {
Swap(h, loc, chld);
loc = chld;
}
PetscFunctionReturn(PETSC_SUCCESS);
}
PetscErrorCode PetscHeapPeek(PetscHeap h, PetscInt *id, PetscInt *val)
{
PetscFunctionBegin;
if (h->end == 1) {
*id = h->base[0].id;
*val = h->base[0].value;
PetscFunctionReturn(PETSC_SUCCESS);
}
*id = h->base[1].id;
*val = h->base[1].value;
PetscFunctionReturn(PETSC_SUCCESS);
}
PetscErrorCode PetscHeapStash(PetscHeap h, PetscInt id, PetscInt val)
{
PetscInt loc;
PetscFunctionBegin;
loc = --h->stash;
h->base[loc].id = id;
h->base[loc].value = val;
PetscFunctionReturn(PETSC_SUCCESS);
}
PetscErrorCode PetscHeapUnstash(PetscHeap h)
{
PetscFunctionBegin;
while (h->stash < h->alloc) {
PetscInt id = Id(h, h->stash), value = Value(h, h->stash);
h->stash++;
PetscCall(PetscHeapAdd(h, id, value));
}
PetscFunctionReturn(PETSC_SUCCESS);
}
PetscErrorCode PetscHeapDestroy(PetscHeap *heap)
{
PetscFunctionBegin;
PetscCall(PetscFree((*heap)->base));
PetscCall(PetscFree(*heap));
PetscFunctionReturn(PETSC_SUCCESS);
}
PetscErrorCode PetscHeapView(PetscHeap h, PetscViewer viewer)
{
PetscBool iascii;
PetscFunctionBegin;
if (!viewer) PetscCall(PetscViewerASCIIGetStdout(PETSC_COMM_SELF, &viewer));
PetscValidHeaderSpecific(viewer, PETSC_VIEWER_CLASSID, 2);
PetscCall(PetscObjectTypeCompare((PetscObject)viewer, PETSCVIEWERASCII, &iascii));
if (iascii) {
PetscCall(PetscViewerASCIIPrintf(viewer, "Heap size %" PetscInt_FMT " with %" PetscInt_FMT " stashed\n", h->end - 1, h->alloc - h->stash));
PetscCall(PetscViewerASCIIPrintf(viewer, "Heap in (id,value) pairs\n"));
PetscCall(PetscIntView(2 * (h->end - 1), (const PetscInt *)(h->base + 1), viewer));
PetscCall(PetscViewerASCIIPrintf(viewer, "Stash in (id,value) pairs\n"));
PetscCall(PetscIntView(2 * (h->alloc - h->stash), (const PetscInt *)(h->base + h->stash), viewer));
}
PetscFunctionReturn(PETSC_SUCCESS);
}
|
83a5946226c673585de286237be229b64126da05
|
a37180e6d95ed830b4b41ae75338f76c73a3652e
|
/Firmware/radio/parameters.c
|
1f2451ef3eede47711b9225abd8592494b84be22
|
[] |
permissive
|
ArduPilot/SiK
|
86620e4fa74ca970c0cc75e28774d6e555309f8c
|
ec1d5e8947581e31edcecd1d5c8423ba244ea2d3
|
refs/heads/master
| 2023-08-05T08:37:55.486220
| 2023-07-07T21:40:45
| 2023-07-11T02:45:36
| 2,713,719
| 155
| 110
|
BSD-2-Clause
| 2023-08-01T09:48:40
| 2011-11-05T03:34:08
|
C
|
UTF-8
|
C
| false
| false
| 16,114
|
c
|
parameters.c
|
// -*- Mode: C; c-basic-offset: 8; -*-
//
// Copyright (c) 2011 Michael Smith, All Rights Reserved
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// o Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// o 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.
//
///
/// @file parameters.c
///
/// Storage for program parameters.
///
/// Parameters are held in a contiguous array of 16-bit values.
/// It is up to the caller to decide how large a parameter is and to
/// access it accordingly.
///
/// When saved, parameters are copied bitwise to the flash scratch page,
/// with an 8-bit XOR checksum appended to the end of the flash range.
///
#include "radio.h"
#include "tdm.h"
#include "crc.h"
#include <flash_layout.h>
#ifdef INCLUDE_AES
#include "AES/aes.h"
#endif // INCLUDE_AES
/// In-ROM parameter info table.
///
__code const struct parameter_info {
const char *name;
param_t default_value;
} parameter_info[PARAM_MAX] = {
{"FORMAT", PARAM_FORMAT_CURRENT},
{"SERIAL_SPEED", 57}, // match APM default of 57600
{"AIR_SPEED", 64}, // relies on MAVLink flow control
{"NETID", 25},
{"TXPOWER", 20},
{"ECC", 0},
{"MAVLINK", 1},
{"OPPRESEND", 0},
{"MIN_FREQ", 0},
{"MAX_FREQ", 0},
{"NUM_CHANNELS", 0},
{"DUTY_CYCLE", 100},
{"LBT_RSSI", 0},
{"MANCHESTER", 0},
{"RTSCTS", 0},
{"MAX_WINDOW", 131},
#ifdef INCLUDE_AES
{"ENCRYPTION_LEVEL", 0}, // no Enycryption (0), 128 or 256 bit key
#endif
};
/// In-RAM parameter store.
///
/// It seems painful to have to do this, but we need somewhere to
/// hold all the parameters when we're rewriting the scratchpad
/// page anyway.
///
__xdata param_t parameter_values[PARAM_MAX];
// Three extra bytes, 1 for the number of params and 2 for the checksum
#define PARAM_FLASH_START 0
#define PARAM_FLASH_END (PARAM_FLASH_START + sizeof(parameter_values) + 3)
#if PIN_MAX > 0
__code const pins_user_info_t pins_defaults = PINS_USER_INFO_DEFAULT;
__xdata pins_user_info_t pin_values[PIN_MAX];
// Place the start away from the other params to allow for expantion 2<<7 = 256
#define PIN_FLASH_START (2<<7)
#define PIN_FLASH_END (PIN_FLASH_START + sizeof(pin_values) + 3)
// Check to make sure the End of the r and the beginning of pins dont overlap
typedef char r2pCheck[(PARAM_FLASH_END < PIN_FLASH_START) ? 0 : -1];
#else // PIN_MAX
#define PIN_FLASH_END PARAM_FLASH_END
#endif // PIN_MAX
// Place the start away from the other params to allow for expantion 2<<7 +128 = 384
#ifdef INCLUDE_AES
// Holds the encrpytion string
__xdata uint8_t encryption_key[32];
#define PARAM_E_FLASH_START (2<<7) + 128
#define PARAM_E_FLASH_END (PARAM_E_FLASH_START + sizeof(encryption_key) + 3)
// Check to make sure the End of the pins and the beginning of encryption dont overlap
typedef char p2eCheck[(PIN_FLASH_END < PARAM_E_FLASH_START) ? 0 : -1];
#else
#define PARAM_E_FLASH_END PIN_FLASH_END
#endif // INCLUDE_AES
// Check to make sure we dont overflow off the page
typedef char endCheck[(PARAM_E_FLASH_END < 1023) ? 0 : -1];
static bool
param_check(__pdata enum ParamID id, __data uint32_t val)
{
// parameter value out of range - fail
if (id >= PARAM_MAX)
return false;
switch (id) {
case PARAM_FORMAT:
return false;
case PARAM_SERIAL_SPEED:
return serial_device_valid_speed(val);
case PARAM_AIR_SPEED:
if (val > 256)
return false;
break;
case PARAM_NETID:
// all values are OK
return true;
case PARAM_TXPOWER:
if (val > BOARD_MAXTXPOWER)
return false;
break;
case PARAM_ECC:
case PARAM_OPPRESEND:
// boolean 0/1 only
if (val > 1)
return false;
break;
case PARAM_MAVLINK:
if (val > 2)
return false;
break;
case PARAM_MAX_WINDOW:
// 131 milliseconds == 0x1FFF 16 usec ticks,
// which is the maximum we can handle with a 13
// bit trailer for window remaining
if (val > 131)
return false;
break;
default:
// no sanity check for this value
break;
}
return true;
}
bool
param_set(__data enum ParamID param, __pdata param_t value)
{
// Sanity-check the parameter value first.
if (!param_check(param, value))
return false;
// some parameters we update immediately
switch (param) {
case PARAM_TXPOWER:
// useful to update power level immediately when range
// testing in RSSI mode
radio_set_transmit_power(value);
value = radio_get_transmit_power();
break;
case PARAM_DUTY_CYCLE:
// update duty cycle immediately
value = constrain(value, 0, 100);
duty_cycle = value;
break;
case PARAM_LBT_RSSI:
// update LBT RSSI immediately
if (value != 0) {
value = constrain(value, 25, 220);
}
lbt_rssi = value;
break;
case PARAM_MAVLINK:
feature_mavlink_framing = (uint8_t) value;
value = feature_mavlink_framing;
break;
case PARAM_OPPRESEND:
break;
case PARAM_RTSCTS:
feature_rtscts = value?true:false;
value = feature_rtscts?1:0;
break;
default:
break;
}
parameter_values[param] = value;
return true;
}
param_t
param_get(__data enum ParamID param)
{
if (param >= PARAM_MAX)
return 0;
return parameter_values[param];
}
bool read_params(__xdata uint8_t * __data input, uint16_t start, uint8_t size)
{
uint16_t i;
for (i = start; i < start+size; i ++)
input[i-start] = flash_read_scratch(i);
// verify checksum
if (crc16(size, input) != ((uint16_t) flash_read_scratch(i+1)<<8 | flash_read_scratch(i)))
return false;
return true;
}
void write_params(__xdata uint8_t * __data input, uint16_t start, uint8_t size)
{
uint16_t i, checksum;
// save parameters to the scratch page
for (i = start; i < start+size; i ++)
flash_write_scratch(i, input[i-start]);
// write checksum
checksum = crc16(size, input);
flash_write_scratch(i, checksum&0xFF);
flash_write_scratch(i+1, checksum>>8);
}
bool
param_load(void)
__critical {
__pdata uint8_t i, expected;
// Start with default values
param_default();
// loop reading the parameters array
expected = flash_read_scratch(PARAM_FLASH_START);
if (expected > sizeof(parameter_values) || expected < 12*sizeof(param_t))
return false;
// read and verify params
if(!read_params((__xdata uint8_t *)parameter_values, PARAM_FLASH_START+1, expected))
return false;
// decide whether we read a supported version of the structure
if (param_get(PARAM_FORMAT) != PARAM_FORMAT_CURRENT) {
debug("parameter format %lu expecting %lu", parameters[PARAM_FORMAT], PARAM_FORMAT_CURRENT);
return false;
}
for (i = 0; i < PARAM_MAX; i++) {
if (!param_check(i, parameter_values[i])) {
parameter_values[i] = parameter_info[i].default_value;
}
}
// read and verify pin params
#if PIN_MAX > 0
if(!read_params((__xdata uint8_t *)pin_values, PIN_FLASH_START+1, sizeof(pin_values)))
return false;
#endif
// read and verify encryption params
#ifdef INCLUDE_AES
if(!read_params((__xdata uint8_t *)encryption_key, PARAM_E_FLASH_START+1, sizeof(encryption_key)))
return false;
#endif // INCLUDE_AES
return true;
}
void
param_save(void)
__critical {
// tag parameters with the current format
parameter_values[PARAM_FORMAT] = PARAM_FORMAT_CURRENT;
// erase the scratch space
flash_erase_scratch();
// write param array length
flash_write_scratch(PARAM_FLASH_START, sizeof(parameter_values));
// write params
write_params((__xdata uint8_t *)parameter_values, PARAM_FLASH_START+1, sizeof(parameter_values));
// write pin params
#if PIN_MAX > 0
flash_write_scratch(PIN_FLASH_START, sizeof(pin_values));
write_params((__xdata uint8_t *)pin_values, PIN_FLASH_START+1, sizeof(pin_values));
#endif
// write encryption params
#ifdef INCLUDE_AES
flash_write_scratch(PARAM_E_FLASH_START, sizeof(encryption_key));
write_params((__xdata uint8_t *)encryption_key, PARAM_E_FLASH_START+1, sizeof(encryption_key));
#endif // INCLUDE_AES
}
void
param_default(void)
{
__pdata uint8_t i;
// set all parameters to their default values
for (i = 0; i < PARAM_MAX; i++) {
parameter_values[i] = parameter_info[i].default_value;
}
#if PIN_MAX > 0
for (i = 0; i < PIN_MAX; i ++) {
pin_values[i].output = pins_defaults.output;
pin_values[i].pin_dir = pins_defaults.pin_dir;
pin_values[i].pin_mirror = pins_defaults.pin_mirror;
}
#endif // PIN_MAX
}
enum ParamID
param_id(__data char * __pdata name)
{
__pdata uint8_t i;
for (i = 0; i < PARAM_MAX; i++) {
if (!strcmp(name, parameter_info[i].name))
break;
}
return i;
}
const char *__code
param_name(__data enum ParamID param)
{
if (param < PARAM_MAX) {
return parameter_info[param].name;
}
return 0;
}
// constraint for parameter values
uint32_t constrain(__pdata uint32_t v, __pdata uint32_t min, __pdata uint32_t max)
{
if (v < min) v = min;
if (v > max) v = max;
return v;
}
// rfd900a calibration stuff
// Change for next rfd900 revision
#if defined BOARD_rfd900a || defined BOARD_rfd900p
static __at(FLASH_CALIBRATION_AREA) uint8_t __code calibration[FLASH_CALIBRATION_AREA_SIZE];
static __at(FLASH_CALIBRATION_CRC) uint8_t __code calibration_crc;
static void
flash_write_byte(uint16_t address, uint8_t c) __reentrant __critical
{
PSCTL = 0x01; // set PSWE, clear PSEE
FLKEY = 0xa5;
FLKEY = 0xf1;
*(uint8_t __xdata *)address = c; // write the byte
PSCTL = 0x00; // disable PSWE/PSEE
}
static uint8_t
flash_read_byte(uint16_t address) __reentrant
{
// will cause reset if the byte is in a locked page
return *(uint8_t __code *)address;
}
bool
calibration_set(uint8_t idx, uint8_t value) __reentrant
{
#ifdef CPU_SI1030
PSBANK = 0x33;
#endif
// if level is valid
if (idx <= BOARD_MAXTXPOWER && value != 0xFF)
{
// if the target byte isn't yet written
if (flash_read_byte(FLASH_CALIBRATION_AREA_HIGH + idx) == 0xFF)
{
flash_write_byte(FLASH_CALIBRATION_AREA_HIGH + idx, value);
return true;
}
}
return false;
}
uint8_t
calibration_get(uint8_t level) __reentrant
{
uint8_t idx;
uint8_t crc = 0;
#ifdef CPU_SI1030
PSBANK = 0x33;
#endif
// Change for next board revision
for (idx = 0; idx < FLASH_CALIBRATION_AREA_SIZE; idx++)
{
crc ^= calibration[idx];
}
if (calibration_crc != 0xFF && calibration_crc == crc && level <= BOARD_MAXTXPOWER)
{
return calibration[level];
}
return 0xFF;
}
uint8_t
calibration_force_get(uint8_t idx) __reentrant
{
return flash_read_byte(FLASH_CALIBRATION_AREA_HIGH + idx);
}
bool
calibration_lock() __reentrant
{
uint8_t idx;
uint8_t crc = 0;
#ifdef CPU_SI1030
PSBANK = 0x33;
#endif
// check that all entries are written
if (flash_read_byte(FLASH_CALIBRATION_CRC_HIGH) == 0xFF)
{
for (idx=0; idx < FLASH_CALIBRATION_AREA_SIZE; idx++)
{
uint8_t cal = flash_read_byte(FLASH_CALIBRATION_AREA_HIGH + idx);
crc ^= cal;
if (cal == 0xFF)
{
printf("dBm level %u not calibrated\n",idx);
return false;
}
}
// write crc
flash_write_byte(FLASH_CALIBRATION_CRC_HIGH, crc);
// lock the first and last pages
// can only be reverted by reflashing the bootloader
flash_write_byte(FLASH_LOCK_BYTE, 0xFE);
return true;
}
return false;
}
#endif // BOARD_rfd900a/p
// mRo Calibration stuff.
#if defined BOARD_mro900
static __at(FLASH_CALIBRATION_OSC) uint8_t __code calibration;
static void
flash_write_byte(uint16_t address, uint8_t c) __reentrant __critical
{
PSCTL = 0x01; // set PSWE, clear PSEE
FLKEY = 0xa5;
FLKEY = 0xf1;
*(uint8_t __xdata *)address = c; // write the byte
PSCTL = 0x00; // disable PSWE/PSEE
}
static uint8_t
flash_read_byte(uint16_t address) __reentrant
{
// will cause reset if the byte is in a locked page
return *(uint8_t __code *)address;
}
bool
calibration_set(uint8_t value) __reentrant
{
PSBANK = 0x33;
// if the target byte isn't yet written
if ((flash_read_byte(FLASH_CALIBRATION_OSC_HIGH) == 0xFF))
{
flash_write_byte(FLASH_CALIBRATION_OSC_HIGH, value);
return true;
}
return false;
}
uint8_t
calibration_get() __reentrant
{
PSBANK = 0x33;
return calibration;
}
uint8_t
calibration_force_get() __reentrant
{
return flash_read_byte(FLASH_CALIBRATION_OSC_HIGH);
}
bool
calibration_lock() __reentrant
{
PSBANK = 0x33;
// check that all entries are written
if (flash_read_byte(FLASH_CALIBRATION_OSC_HIGH) == 0xFF)
{
printf("OSC value seems not defined 0xFF \n");
return false;
}
// lock the first and last pages
// can only be reverted by reflashing the bootloader
flash_write_byte(FLASH_LOCK_BYTE, 0xFE);
return true;
}
#endif // BOARD_mro900
#ifdef INCLUDE_AES
// Used to convert individial Hex digits into Integers
//
uint8_t read_hex_nibble(const uint8_t c) __reentrant
{
if ((c >='0') && (c <= '9'))
{
return c - '0';
}
else if ((c >='A') && (c <= 'F'))
{
return c - 'A' + 10;
}
else if ((c >='a') && (c <= 'f'))
{
return c - 'a' + 10;
}
else
{
// printf("[%u] read_hex_nibble: Error char not in supported range",nodeId);
return 0;
}
}
/// Convert string to hex codes
///
void convert_to_hex(__xdata unsigned char *str_in, __xdata unsigned char *str_out, __pdata uint8_t key_length)
{
__pdata uint8_t i, num;
for (i=0;i<key_length;i++) {
num = read_hex_nibble(str_in[2 * i])<<4;
num += read_hex_nibble(str_in[2 * i + 1]);
str_out[i] = num;
}
}
/// Set default encryption key
//
void param_set_default_encryption_key(__pdata uint8_t key_length)
{
__pdata uint8_t i;
__xdata uint8_t b[] = {0x62};
for (i=0;i< key_length;i++) {
// Set default key to b's
memcpy(&encryption_key[i], &b, 1);
}
}
/// set the encryption key
///
/// Note: There is a reliance on the encryption level as this determines
/// how many characters we need. So we need to set ATS16 first, THEN
/// save and then Set the encryption key.
///
bool
param_set_encryption_key(__xdata unsigned char *key)
{
__pdata uint8_t len, key_length;
// Use the new encryption level to help with key changes before reboot
// Deduce key length (bytes) from level 1 -> 16, 2 -> 24, 3 -> 32
key_length = AES_KEY_LENGTH(param_get(PARAM_ENCRYPTION));
len = strlen(key);
// If not enough characters (2 char per byte), then set default
if (len < 2 * key_length ) {
param_set_default_encryption_key(key_length);
//printf("%s\n",key);
printf("ERROR - Key length:%u, Required %u\n",len, 2 * key_length);
return true;
} else {
// We have sufficient characters for the encryption key.
// If too many characters, then it will just ignore extra ones
printf("key len %d\n",key_length);
convert_to_hex(key, encryption_key, key_length);
}
return true;
}
/// Print hex codes for given string
///
void
print_encryption_key()
{
__pdata uint8_t i;
__pdata uint8_t key_length = AES_KEY_LENGTH(param_get(PARAM_ENCRYPTION));
for (i=0; i<key_length; i++) {
if (0xF >= encryption_key[i]) {
printf("0");
}
printf("%x",encryption_key[i]);
}
printf("\n");
}
/// get the encryption key
///
__xdata uint8_t* param_get_encryption_key()
{
return encryption_key;
}
#endif // INCLUDE_AES
|
59d0f210ee85473b28139decc0b4c7f71beb453a
|
f7f043523dcacb348f7a387430ae5b7b2932b56a
|
/vendor/github.com/coreswitch/openconfigd/cli/general.h
|
1f8c54aea22706563f4aa72e3a8277d191ad85fc
|
[
"Apache-2.0",
"FSFAP",
"GPL-3.0-or-later",
"GPL-3.0-only",
"LGPL-2.0-or-later"
] |
permissive
|
coreswitch/zebra
|
2f3dcbb0f1aa0350fe63d664e5533d6895030e85
|
1931dde592c81398707a07d90d00f90321dc9b46
|
refs/heads/master
| 2021-12-15T02:26:03.510038
| 2019-05-19T12:00:34
| 2019-05-19T12:00:34
| 107,520,729
| 105
| 22
|
Apache-2.0
| 2019-05-17T01:23:34
| 2017-10-19T08:42:40
|
Go
|
UTF-8
|
C
| false
| false
| 10,209
|
h
|
general.h
|
/* general.h -- defines that everybody likes to use. */
/* Copyright (C) 1993-2009 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
Bash 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.
Bash 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 Bash. If not, see <http://www.gnu.org/licenses/>.
*/
#if !defined (_GENERAL_H_)
#define _GENERAL_H_
#include "stdc.h"
#include "bashtypes.h"
#include "chartypes.h"
#if defined (HAVE_SYS_RESOURCE_H) && defined (RLIMTYPE)
# if defined (HAVE_SYS_TIME_H)
# include <sys/time.h>
# endif
# include <sys/resource.h>
#endif
#if defined (HAVE_STRING_H)
# include <string.h>
#else
# include <strings.h>
#endif /* !HAVE_STRING_H */
#if defined (HAVE_LIMITS_H)
# include <limits.h>
#endif
#include "xmalloc.h"
/* NULL pointer type. */
#if !defined (NULL)
# if defined (__STDC__)
# define NULL ((void *) 0)
# else
# define NULL 0x0
# endif /* !__STDC__ */
#endif /* !NULL */
/* Hardly used anymore */
#define pointer_to_int(x) (int)((char *)x - (char *)0)
#if defined (alpha) && defined (__GNUC__) && !defined (strchr) && !defined (__STDC__)
extern char *strchr (), *strrchr ();
#endif
#if !defined (strcpy) && (defined (HAVE_DECL_STRCPY) && !HAVE_DECL_STRCPY)
extern char *strcpy __P((char *, const char *));
#endif
#if !defined (savestring)
# define savestring(x) (char *)strcpy (xmalloc (1 + strlen (x)), (x))
#endif
#ifndef member
# define member(c, s) ((c) ? ((char *)mbschr ((s), (c)) != (char *)NULL) : 0)
#endif
#ifndef whitespace
#define whitespace(c) (((c) == ' ') || ((c) == '\t'))
#endif
#ifndef CHAR_MAX
# ifdef __CHAR_UNSIGNED__
# define CHAR_MAX 0xff
# else
# define CHAR_MAX 0x7f
# endif
#endif
#ifndef CHAR_BIT
# define CHAR_BIT 8
#endif
/* Nonzero if the integer type T is signed. */
#define TYPE_SIGNED(t) (! ((t) 0 < (t) -1))
/* Bound on length of the string representing an integer value of type T.
Subtract one for the sign bit if T is signed;
302 / 1000 is log10 (2) rounded up;
add one for integer division truncation;
add one more for a minus sign if t is signed. */
#define INT_STRLEN_BOUND(t) \
((sizeof (t) * CHAR_BIT - TYPE_SIGNED (t)) * 302 / 1000 \
+ 1 + TYPE_SIGNED (t))
/* Define exactly what a legal shell identifier consists of. */
#define legal_variable_starter(c) (ISALPHA(c) || (c == '_'))
#define legal_variable_char(c) (ISALNUM(c) || c == '_')
/* Definitions used in subst.c and by the `read' builtin for field
splitting. */
#define spctabnl(c) ((c) == ' ' || (c) == '\t' || (c) == '\n')
/* All structs which contain a `next' field should have that field
as the first field in the struct. This means that functions
can be written to handle the general case for linked lists. */
typedef struct g_list {
struct g_list *next;
} GENERIC_LIST;
/* Here is a generic structure for associating character strings
with integers. It is used in the parser for shell tokenization. */
typedef struct {
char *word;
int token;
} STRING_INT_ALIST;
/* A macro to avoid making an unneccessary function call. */
#define REVERSE_LIST(list, type) \
((list && list->next) ? (type)list_reverse ((GENERIC_LIST *)list) \
: (type)(list))
#if __GNUC__ > 1
# define FASTCOPY(s, d, n) __builtin_memcpy ((d), (s), (n))
#else /* !__GNUC__ */
# if !defined (HAVE_BCOPY)
# if !defined (HAVE_MEMMOVE)
# define FASTCOPY(s, d, n) memcpy ((d), (s), (n))
# else
# define FASTCOPY(s, d, n) memmove ((d), (s), (n))
# endif /* !HAVE_MEMMOVE */
# else /* HAVE_BCOPY */
# define FASTCOPY(s, d, n) bcopy ((s), (d), (n))
# endif /* HAVE_BCOPY */
#endif /* !__GNUC__ */
/* String comparisons that possibly save a function call each. */
#define STREQ(a, b) ((a)[0] == (b)[0] && strcmp(a, b) == 0)
#define STREQN(a, b, n) ((n == 0) ? (1) \
: ((a)[0] == (b)[0] && strncmp(a, b, n) == 0))
/* More convenience definitions that possibly save system or libc calls. */
#define STRLEN(s) (((s) && (s)[0]) ? ((s)[1] ? ((s)[2] ? strlen(s) : 2) : 1) : 0)
#define FREE(s) do { if (s) free (s); } while (0)
#define MEMBER(c, s) (((c) && c == (s)[0] && !(s)[1]) || (member(c, s)))
/* A fairly hairy macro to check whether an allocated string has more room,
and to resize it using xrealloc if it does not.
STR is the string (char *)
CIND is the current index into the string (int)
ROOM is the amount of additional room we need in the string (int)
CSIZE is the currently-allocated size of STR (int)
SINCR is how much to increment CSIZE before calling xrealloc (int) */
#define RESIZE_MALLOCED_BUFFER(str, cind, room, csize, sincr) \
do { \
if ((cind) + (room) >= csize) \
{ \
while ((cind) + (room) >= csize) \
csize += (sincr); \
str = xrealloc (str, csize); \
} \
} while (0)
/* Function pointers can be declared as (Function *)foo. */
#if !defined (_FUNCTION_DEF)
# define _FUNCTION_DEF
typedef int Function ();
typedef void VFunction ();
typedef char *CPFunction (); /* no longer used */
typedef char **CPPFunction (); /* no longer used */
#endif /* _FUNCTION_DEF */
#ifndef SH_FUNCTION_TYPEDEF
# define SH_FUNCTION_TYPEDEF
/* Shell function typedefs with prototypes */
/* `Generic' function pointer typedefs */
typedef int sh_intfunc_t __P((int));
typedef int sh_ivoidfunc_t __P((void));
typedef int sh_icpfunc_t __P((char *));
typedef int sh_icppfunc_t __P((char **));
typedef int sh_iptrfunc_t __P((PTR_T));
typedef void sh_voidfunc_t __P((void));
typedef void sh_vintfunc_t __P((int));
typedef void sh_vcpfunc_t __P((char *));
typedef void sh_vcppfunc_t __P((char **));
typedef void sh_vptrfunc_t __P((PTR_T));
typedef int sh_wdesc_func_t __P((WORD_DESC *));
typedef int sh_wlist_func_t __P((WORD_LIST *));
typedef int sh_glist_func_t __P((GENERIC_LIST *));
typedef char *sh_string_func_t __P((char *)); /* like savestring, et al. */
typedef int sh_msg_func_t __P((const char *, ...)); /* printf(3)-like */
typedef void sh_vmsg_func_t __P((const char *, ...)); /* printf(3)-like */
/* Specific function pointer typedefs. Most of these could be done
with #defines. */
typedef void sh_sv_func_t __P((char *)); /* sh_vcpfunc_t */
typedef void sh_free_func_t __P((PTR_T)); /* sh_vptrfunc_t */
typedef void sh_resetsig_func_t __P((int)); /* sh_vintfunc_t */
typedef int sh_ignore_func_t __P((const char *)); /* sh_icpfunc_t */
typedef int sh_assign_func_t __P((const char *));
typedef int sh_wassign_func_t __P((WORD_DESC *, int));
typedef int sh_builtin_func_t __P((WORD_LIST *)); /* sh_wlist_func_t */
#endif /* SH_FUNCTION_TYPEDEF */
#define NOW ((time_t) time ((time_t *) 0))
/* Some defines for calling file status functions. */
#define FS_EXISTS 0x1
#define FS_EXECABLE 0x2
#define FS_EXEC_PREFERRED 0x4
#define FS_EXEC_ONLY 0x8
#define FS_DIRECTORY 0x10
#define FS_NODIRS 0x20
#define FS_READABLE 0x40
/* Default maximum for move_to_high_fd */
#define HIGH_FD_MAX 256
/* The type of function passed as the fourth argument to qsort(3). */
#ifdef __STDC__
typedef int QSFUNC (const void *, const void *);
#else
typedef int QSFUNC ();
#endif
/* Some useful definitions for Unix pathnames. Argument convention:
x == string, c == character */
#if !defined (__CYGWIN__)
# define ABSPATH(x) ((x)[0] == '/')
# define RELPATH(x) ((x)[0] != '/')
#else /* __CYGWIN__ */
# define ABSPATH(x) (((x)[0] && ISALPHA((unsigned char)(x)[0]) && (x)[1] == ':') || ISDIRSEP((x)[0]))
# define RELPATH(x) (ABSPATH(x) == 0)
#endif /* __CYGWIN__ */
#define ROOTEDPATH(x) (ABSPATH(x))
#define DIRSEP '/'
#if !defined (__CYGWIN__)
# define ISDIRSEP(c) ((c) == '/')
#else
# define ISDIRSEP(c) ((c) == '/' || (c) == '\\')
#endif /* __CYGWIN__ */
#define PATHSEP(c) (ISDIRSEP(c) || (c) == 0)
#if 0
/* Declarations for functions defined in xmalloc.c */
extern PTR_T xmalloc __P((size_t));
extern PTR_T xrealloc __P((void *, size_t));
extern void xfree __P((void *));
#endif
/* Declarations for functions defined in general.c */
extern void posix_initialize __P((int));
#if defined (RLIMTYPE)
extern RLIMTYPE string_to_rlimtype __P((char *));
extern void print_rlimtype __P((RLIMTYPE, int));
#endif
extern int all_digits __P((char *));
extern int legal_number __P((const char *, intmax_t *));
extern int legal_identifier __P((char *));
extern int check_identifier __P((WORD_DESC *, int));
extern int legal_alias_name __P((char *, int));
extern int assignment __P((const char *, int));
extern int sh_unset_nodelay_mode __P((int));
extern int sh_validfd __P((int));
extern int fd_ispipe __P((int));
extern void check_dev_tty __P((void));
extern int move_to_high_fd __P((int, int, int));
extern int check_binary_file __P((char *, int));
#ifdef _POSIXSTAT_H_
extern int same_file __P((char *, char *, struct stat *, struct stat *));
#endif
extern int sh_openpipe __P((int *));
extern int sh_closepipe __P((int *));
extern int file_exists __P((char *));
extern int file_isdir __P((char *));
extern int file_iswdir __P((char *));
extern int path_dot_or_dotdot __P((const char *));
extern int absolute_pathname __P((const char *));
extern int absolute_program __P((const char *));
extern char *make_absolute __P((char *, char *));
extern char *base_pathname __P((char *));
extern char *full_pathname __P((char *));
extern char *polite_directory_format __P((char *));
extern char *trim_pathname __P((char *, int));
extern char *extract_colon_unit __P((char *, int *));
extern void tilde_initialize __P((void));
extern char *bash_tilde_find_word __P((const char *, int, int *));
extern char *bash_tilde_expand __P((const char *, int));
extern int group_member __P((gid_t));
extern char **get_group_list __P((int *));
extern int *get_group_array __P((int *));
#endif /* _GENERAL_H_ */
|
1abf83b90406e26da534283ede56b1f30eb0bd6a
|
03b2c80dbc41e904b167d504666e27d798da5447
|
/src/float_plus.h
|
07350fe278a1a433571a98802b39ae71258023fd
|
[
"Unlicense"
] |
permissive
|
nptcl/npt
|
7c1570b497cdce0b8971cb445fbc04cb500232d3
|
aa714a2370ac9fa5348c2fc96159b40b9de3de07
|
refs/heads/master
| 2023-03-20T09:13:54.669118
| 2022-07-02T11:17:44
| 2022-07-02T11:17:44
| 171,985,905
| 160
| 12
|
Unlicense
| 2023-03-11T01:36:37
| 2019-02-22T03:11:34
|
C
|
UTF-8
|
C
| false
| false
| 23,907
|
h
|
float_plus.h
|
#ifndef __FLOAT_PLUS_HEADER__
#define __FLOAT_PLUS_HEADER__
#include "local.h"
#include "typedef.h"
#define plus_float_sv_alloc_ _n(plus_float_sv_alloc_)
#define plus_float_dv_alloc_ _n(plus_float_dv_alloc_)
#define plus_float_lv_alloc_ _n(plus_float_lv_alloc_)
#define plus_float_sv_local_ _n(plus_float_sv_local_)
#define plus_float_dv_local_ _n(plus_float_dv_local_)
#define plus_float_lv_local_ _n(plus_float_lv_local_)
#define plus_float_sv_heap_ _n(plus_float_sv_heap_)
#define plus_float_dv_heap_ _n(plus_float_dv_heap_)
#define plus_float_lv_heap_ _n(plus_float_lv_heap_)
#define minus_float_sv_alloc_ _n(minus_float_sv_alloc_)
#define minus_float_dv_alloc_ _n(minus_float_dv_alloc_)
#define minus_float_lv_alloc_ _n(minus_float_lv_alloc_)
#define minus_float_sv_local_ _n(minus_float_sv_local_)
#define minus_float_dv_local_ _n(minus_float_dv_local_)
#define minus_float_lv_local_ _n(minus_float_lv_local_)
#define minus_float_sv_heap_ _n(minus_float_sv_heap_)
#define minus_float_dv_heap_ _n(minus_float_dv_heap_)
#define minus_float_lv_heap_ _n(minus_float_lv_heap_)
#define minus_float_vs_alloc_ _n(minus_float_vs_alloc_)
#define minus_float_vd_alloc_ _n(minus_float_vd_alloc_)
#define minus_float_vl_alloc_ _n(minus_float_vl_alloc_)
#define minus_float_vs_local_ _n(minus_float_vs_local_)
#define minus_float_vd_local_ _n(minus_float_vd_local_)
#define minus_float_vl_local_ _n(minus_float_vl_local_)
#define minus_float_vs_heap_ _n(minus_float_vs_heap_)
#define minus_float_vd_heap_ _n(minus_float_vd_heap_)
#define minus_float_vl_heap_ _n(minus_float_vl_heap_)
#define sign_reverse_floats_alloc _n(sign_reverse_floats_alloc)
#define sign_reverse_floatd_alloc _n(sign_reverse_floatd_alloc)
#define sign_reverse_floatl_alloc _n(sign_reverse_floatl_alloc)
#define sign_reverse_floats_local _n(sign_reverse_floats_local)
#define sign_reverse_floatd_local _n(sign_reverse_floatd_local)
#define sign_reverse_floatl_local _n(sign_reverse_floatl_local)
#define sign_reverse_floats_heap _n(sign_reverse_floats_heap)
#define sign_reverse_floatd_heap _n(sign_reverse_floatd_heap)
#define sign_reverse_floatl_heap _n(sign_reverse_floatl_heap)
#define plus_float_fs_alloc_ _n(plus_float_fs_alloc_)
#define plus_float_fd_alloc_ _n(plus_float_fd_alloc_)
#define plus_float_fl_alloc_ _n(plus_float_fl_alloc_)
#define plus_float_fs_local_ _n(plus_float_fs_local_)
#define plus_float_fd_local_ _n(plus_float_fd_local_)
#define plus_float_fl_local_ _n(plus_float_fl_local_)
#define plus_float_fs_heap_ _n(plus_float_fs_heap_)
#define plus_float_fd_heap_ _n(plus_float_fd_heap_)
#define plus_float_fl_heap_ _n(plus_float_fl_heap_)
#define plus_float_bs_alloc_ _n(plus_float_bs_alloc_)
#define plus_float_bd_alloc_ _n(plus_float_bd_alloc_)
#define plus_float_bl_alloc_ _n(plus_float_bl_alloc_)
#define plus_float_bs_local_ _n(plus_float_bs_local_)
#define plus_float_bd_local_ _n(plus_float_bd_local_)
#define plus_float_bl_local_ _n(plus_float_bl_local_)
#define plus_float_bs_heap_ _n(plus_float_bs_heap_)
#define plus_float_bd_heap_ _n(plus_float_bd_heap_)
#define plus_float_bl_heap_ _n(plus_float_bl_heap_)
#define plus_float_rs_alloc_ _n(plus_float_rs_alloc_)
#define plus_float_rd_alloc_ _n(plus_float_rd_alloc_)
#define plus_float_rl_alloc_ _n(plus_float_rl_alloc_)
#define plus_float_rs_local_ _n(plus_float_rs_local_)
#define plus_float_rd_local_ _n(plus_float_rd_local_)
#define plus_float_rl_local_ _n(plus_float_rl_local_)
#define plus_float_rs_heap_ _n(plus_float_rs_heap_)
#define plus_float_rd_heap_ _n(plus_float_rd_heap_)
#define plus_float_rl_heap_ _n(plus_float_rl_heap_)
#define plus_float_ss_alloc_ _n(plus_float_ss_alloc_)
#define plus_float_sd_alloc_ _n(plus_float_sd_alloc_)
#define plus_float_sl_alloc_ _n(plus_float_sl_alloc_)
#define plus_float_ds_alloc_ _n(plus_float_ds_alloc_)
#define plus_float_dd_alloc_ _n(plus_float_dd_alloc_)
#define plus_float_dl_alloc_ _n(plus_float_dl_alloc_)
#define plus_float_ls_alloc_ _n(plus_float_ls_alloc_)
#define plus_float_ld_alloc_ _n(plus_float_ld_alloc_)
#define plus_float_ll_alloc_ _n(plus_float_ll_alloc_)
#define plus_float_ss_local_ _n(plus_float_ss_local_)
#define plus_float_sd_local_ _n(plus_float_sd_local_)
#define plus_float_sl_local_ _n(plus_float_sl_local_)
#define plus_float_ds_local_ _n(plus_float_ds_local_)
#define plus_float_dd_local_ _n(plus_float_dd_local_)
#define plus_float_dl_local_ _n(plus_float_dl_local_)
#define plus_float_ls_local_ _n(plus_float_ls_local_)
#define plus_float_ld_local_ _n(plus_float_ld_local_)
#define plus_float_ll_local_ _n(plus_float_ll_local_)
#define plus_float_ss_heap_ _n(plus_float_ss_heap_)
#define plus_float_sd_heap_ _n(plus_float_sd_heap_)
#define plus_float_sl_heap_ _n(plus_float_sl_heap_)
#define plus_float_ds_heap_ _n(plus_float_ds_heap_)
#define plus_float_dd_heap_ _n(plus_float_dd_heap_)
#define plus_float_dl_heap_ _n(plus_float_dl_heap_)
#define plus_float_ls_heap_ _n(plus_float_ls_heap_)
#define plus_float_ld_heap_ _n(plus_float_ld_heap_)
#define plus_float_ll_heap_ _n(plus_float_ll_heap_)
#define minus_float_fs_alloc_ _n(minus_float_fs_alloc_)
#define minus_float_fd_alloc_ _n(minus_float_fd_alloc_)
#define minus_float_fl_alloc_ _n(minus_float_fl_alloc_)
#define minus_float_fs_local_ _n(minus_float_fs_local_)
#define minus_float_fd_local_ _n(minus_float_fd_local_)
#define minus_float_fl_local_ _n(minus_float_fl_local_)
#define minus_float_fs_heap_ _n(minus_float_fs_heap_)
#define minus_float_fd_heap_ _n(minus_float_fd_heap_)
#define minus_float_fl_heap_ _n(minus_float_fl_heap_)
#define minus_float_sf_alloc_ _n(minus_float_sf_alloc_)
#define minus_float_df_alloc_ _n(minus_float_df_alloc_)
#define minus_float_lf_alloc_ _n(minus_float_lf_alloc_)
#define minus_float_sf_local_ _n(minus_float_sf_local_)
#define minus_float_df_local_ _n(minus_float_df_local_)
#define minus_float_lf_local_ _n(minus_float_lf_local_)
#define minus_float_sf_heap_ _n(minus_float_sf_heap_)
#define minus_float_df_heap_ _n(minus_float_df_heap_)
#define minus_float_lf_heap_ _n(minus_float_lf_heap_)
#define minus_float_bs_alloc_ _n(minus_float_bs_alloc_)
#define minus_float_bd_alloc_ _n(minus_float_bd_alloc_)
#define minus_float_bl_alloc_ _n(minus_float_bl_alloc_)
#define minus_float_bs_local_ _n(minus_float_bs_local_)
#define minus_float_bd_local_ _n(minus_float_bd_local_)
#define minus_float_bl_local_ _n(minus_float_bl_local_)
#define minus_float_bs_heap_ _n(minus_float_bs_heap_)
#define minus_float_bd_heap_ _n(minus_float_bd_heap_)
#define minus_float_bl_heap_ _n(minus_float_bl_heap_)
#define minus_float_sb_alloc_ _n(minus_float_sb_alloc_)
#define minus_float_db_alloc_ _n(minus_float_db_alloc_)
#define minus_float_lb_alloc_ _n(minus_float_lb_alloc_)
#define minus_float_sb_local_ _n(minus_float_sb_local_)
#define minus_float_db_local_ _n(minus_float_db_local_)
#define minus_float_lb_local_ _n(minus_float_lb_local_)
#define minus_float_sb_heap_ _n(minus_float_sb_heap_)
#define minus_float_db_heap_ _n(minus_float_db_heap_)
#define minus_float_lb_heap_ _n(minus_float_lb_heap_)
#define minus_float_rs_alloc_ _n(minus_float_rs_alloc_)
#define minus_float_rd_alloc_ _n(minus_float_rd_alloc_)
#define minus_float_rl_alloc_ _n(minus_float_rl_alloc_)
#define minus_float_rs_local_ _n(minus_float_rs_local_)
#define minus_float_rd_local_ _n(minus_float_rd_local_)
#define minus_float_rl_local_ _n(minus_float_rl_local_)
#define minus_float_rs_heap_ _n(minus_float_rs_heap_)
#define minus_float_rd_heap_ _n(minus_float_rd_heap_)
#define minus_float_rl_heap_ _n(minus_float_rl_heap_)
#define minus_float_sr_alloc_ _n(minus_float_sr_alloc_)
#define minus_float_dr_alloc_ _n(minus_float_dr_alloc_)
#define minus_float_lr_alloc_ _n(minus_float_lr_alloc_)
#define minus_float_sr_local_ _n(minus_float_sr_local_)
#define minus_float_dr_local_ _n(minus_float_dr_local_)
#define minus_float_lr_local_ _n(minus_float_lr_local_)
#define minus_float_sr_heap_ _n(minus_float_sr_heap_)
#define minus_float_dr_heap_ _n(minus_float_dr_heap_)
#define minus_float_lr_heap_ _n(minus_float_lr_heap_)
#define minus_float_ss_alloc_ _n(minus_float_ss_alloc_)
#define minus_float_sd_alloc_ _n(minus_float_sd_alloc_)
#define minus_float_sl_alloc_ _n(minus_float_sl_alloc_)
#define minus_float_ds_alloc_ _n(minus_float_ds_alloc_)
#define minus_float_dd_alloc_ _n(minus_float_dd_alloc_)
#define minus_float_dl_alloc_ _n(minus_float_dl_alloc_)
#define minus_float_ls_alloc_ _n(minus_float_ls_alloc_)
#define minus_float_ld_alloc_ _n(minus_float_ld_alloc_)
#define minus_float_ll_alloc_ _n(minus_float_ll_alloc_)
#define minus_float_ss_local_ _n(minus_float_ss_local_)
#define minus_float_sd_local_ _n(minus_float_sd_local_)
#define minus_float_sl_local_ _n(minus_float_sl_local_)
#define minus_float_ds_local_ _n(minus_float_ds_local_)
#define minus_float_dd_local_ _n(minus_float_dd_local_)
#define minus_float_dl_local_ _n(minus_float_dl_local_)
#define minus_float_ls_local_ _n(minus_float_ls_local_)
#define minus_float_ld_local_ _n(minus_float_ld_local_)
#define minus_float_ll_local_ _n(minus_float_ll_local_)
#define minus_float_ss_heap_ _n(minus_float_ss_heap_)
#define minus_float_sd_heap_ _n(minus_float_sd_heap_)
#define minus_float_sl_heap_ _n(minus_float_sl_heap_)
#define minus_float_ds_heap_ _n(minus_float_ds_heap_)
#define minus_float_dd_heap_ _n(minus_float_dd_heap_)
#define minus_float_dl_heap_ _n(minus_float_dl_heap_)
#define minus_float_ls_heap_ _n(minus_float_ls_heap_)
#define minus_float_ld_heap_ _n(minus_float_ld_heap_)
#define minus_float_ll_heap_ _n(minus_float_ll_heap_)
int plus_float_sv_alloc_(LocalRoot local, addr left, single_float right, addr *ret);
int plus_float_dv_alloc_(LocalRoot local, addr left, double_float right, addr *ret);
int plus_float_lv_alloc_(LocalRoot local, addr left, long_float right, addr *ret);
int plus_float_sv_local_(LocalRoot local, addr left, single_float right, addr *ret);
int plus_float_dv_local_(LocalRoot local, addr left, double_float right, addr *ret);
int plus_float_lv_local_(LocalRoot local, addr left, long_float right, addr *ret);
int plus_float_sv_heap_(addr left, single_float right, addr *ret);
int plus_float_dv_heap_(addr left, double_float right, addr *ret);
int plus_float_lv_heap_(addr left, long_float right, addr *ret);
int minus_float_sv_alloc_(LocalRoot local, addr left, single_float right, addr *ret);
int minus_float_dv_alloc_(LocalRoot local, addr left, double_float right, addr *ret);
int minus_float_lv_alloc_(LocalRoot local, addr left, long_float right, addr *ret);
int minus_float_sv_local_(LocalRoot local, addr left, single_float right, addr *ret);
int minus_float_dv_local_(LocalRoot local, addr left, double_float right, addr *ret);
int minus_float_lv_local_(LocalRoot local, addr left, long_float right, addr *ret);
int minus_float_sv_heap_(addr left, single_float right, addr *ret);
int minus_float_dv_heap_(addr left, double_float right, addr *ret);
int minus_float_lv_heap_(addr left, long_float right, addr *ret);
int minus_float_vs_alloc_(LocalRoot local, single_float left, addr right, addr *ret);
int minus_float_vd_alloc_(LocalRoot local, double_float left, addr right, addr *ret);
int minus_float_vl_alloc_(LocalRoot local, long_float left, addr right, addr *ret);
int minus_float_vs_local_(LocalRoot local, single_float left, addr right, addr *ret);
int minus_float_vd_local_(LocalRoot local, double_float left, addr right, addr *ret);
int minus_float_vl_local_(LocalRoot local, long_float left, addr right, addr *ret);
int minus_float_vs_heap_(single_float left, addr right, addr *ret);
int minus_float_vd_heap_(double_float left, addr right, addr *ret);
int minus_float_vl_heap_(long_float left, addr right, addr *ret);
void sign_reverse_floats_alloc(LocalRoot local, addr value, addr *ret);
void sign_reverse_floatd_alloc(LocalRoot local, addr value, addr *ret);
void sign_reverse_floatl_alloc(LocalRoot local, addr value, addr *ret);
void sign_reverse_floats_local(LocalRoot local, addr value, addr *ret);
void sign_reverse_floatd_local(LocalRoot local, addr value, addr *ret);
void sign_reverse_floatl_local(LocalRoot local, addr value, addr *ret);
void sign_reverse_floats_heap(addr value, addr *ret);
void sign_reverse_floatd_heap(addr value, addr *ret);
void sign_reverse_floatl_heap(addr value, addr *ret);
int plus_float_fs_alloc_(LocalRoot local, addr left, addr right, addr *ret);
int plus_float_fd_alloc_(LocalRoot local, addr left, addr right, addr *ret);
int plus_float_fl_alloc_(LocalRoot local, addr left, addr right, addr *ret);
int plus_float_fs_local_(LocalRoot local, addr left, addr right, addr *ret);
int plus_float_fd_local_(LocalRoot local, addr left, addr right, addr *ret);
int plus_float_fl_local_(LocalRoot local, addr left, addr right, addr *ret);
int plus_float_fs_heap_(addr left, addr right, addr *ret);
int plus_float_fd_heap_(addr left, addr right, addr *ret);
int plus_float_fl_heap_(addr left, addr right, addr *ret);
#define plus_float_sf_alloc_(m,a,b,r) plus_float_fs_alloc_((m),(b),(a),(r))
#define plus_float_df_alloc_(m,a,b,r) plus_float_fd_alloc_((m),(b),(a),(r))
#define plus_float_lf_alloc_(m,a,b,r) plus_float_fl_alloc_((m),(b),(a),(r))
#define plus_float_sf_local_(m,a,b,r) plus_float_fs_local_((m),(b),(a),(r))
#define plus_float_df_local_(m,a,b,r) plus_float_fd_local_((m),(b),(a),(r))
#define plus_float_lf_local_(m,a,b,r) plus_float_fl_local_((m),(b),(a),(r))
#define plus_float_sf_heap_(a,b,r) plus_float_fs_heap_((b),(a),(r))
#define plus_float_df_heap_(a,b,r) plus_float_fd_heap_((b),(a),(r))
#define plus_float_lf_heap_(a,b,r) plus_float_fl_heap_((b),(a),(r))
int plus_float_bs_alloc_(LocalRoot local, addr left, addr right, addr *ret);
int plus_float_bd_alloc_(LocalRoot local, addr left, addr right, addr *ret);
int plus_float_bl_alloc_(LocalRoot local, addr left, addr right, addr *ret);
int plus_float_bs_local_(LocalRoot local, addr left, addr right, addr *ret);
int plus_float_bd_local_(LocalRoot local, addr left, addr right, addr *ret);
int plus_float_bl_local_(LocalRoot local, addr left, addr right, addr *ret);
int plus_float_bs_heap_(addr left, addr right, addr *ret);
int plus_float_bd_heap_(addr left, addr right, addr *ret);
int plus_float_bl_heap_(addr left, addr right, addr *ret);
#define plus_float_sb_alloc_(m,a,b,r) plus_float_bs_alloc_((m),(b),(a),(r))
#define plus_float_db_alloc_(m,a,b,r) plus_float_bd_alloc_((m),(b),(a),(r))
#define plus_float_lb_alloc_(m,a,b,r) plus_float_bl_alloc_((m),(b),(a),(r))
#define plus_float_sb_local_(m,a,b,r) plus_float_bs_local_((m),(b),(a),(r))
#define plus_float_db_local_(m,a,b,r) plus_float_bd_local_((m),(b),(a),(r))
#define plus_float_lb_local_(m,a,b,r) plus_float_bl_local_((m),(b),(a),(r))
#define plus_float_sb_heap_(a,b,r) plus_float_bs_heap_((b),(a),(r))
#define plus_float_db_heap_(a,b,r) plus_float_bd_heap_((b),(a),(r))
#define plus_float_lb_heap_(a,b,r) plus_float_bl_heap_((b),(a),(r))
int plus_float_rs_alloc_(LocalRoot local, addr left, addr right, addr *ret);
int plus_float_rd_alloc_(LocalRoot local, addr left, addr right, addr *ret);
int plus_float_rl_alloc_(LocalRoot local, addr left, addr right, addr *ret);
int plus_float_rs_local_(LocalRoot local, addr left, addr right, addr *ret);
int plus_float_rd_local_(LocalRoot local, addr left, addr right, addr *ret);
int plus_float_rl_local_(LocalRoot local, addr left, addr right, addr *ret);
int plus_float_rs_heap_(addr left, addr right, addr *ret);
int plus_float_rd_heap_(addr left, addr right, addr *ret);
int plus_float_rl_heap_(addr left, addr right, addr *ret);
#define plus_float_sr_alloc_(m,a,b,r) plus_float_rs_alloc_((m),(b),(a),(r))
#define plus_float_dr_alloc_(m,a,b,r) plus_float_rd_alloc_((m),(b),(a),(r))
#define plus_float_lr_alloc_(m,a,b,r) plus_float_rl_alloc_((m),(b),(a),(r))
#define plus_float_sr_local_(m,a,b,r) plus_float_rs_local_((m),(b),(a),(r))
#define plus_float_dr_local_(m,a,b,r) plus_float_rd_local_((m),(b),(a),(r))
#define plus_float_lr_local_(m,a,b,r) plus_float_rl_local_((m),(b),(a),(r))
#define plus_float_sr_heap_(a,b,r) plus_float_rs_heap_((b),(a),(r))
#define plus_float_dr_heap_(a,b,r) plus_float_rd_heap_((b),(a),(r))
#define plus_float_lr_heap_(a,b,r) plus_float_rl_heap_((b),(a),(r))
int plus_float_ss_alloc_(LocalRoot local, addr left, addr right, addr *ret);
int plus_float_sd_alloc_(LocalRoot local, addr left, addr right, addr *ret);
int plus_float_sl_alloc_(LocalRoot local, addr left, addr right, addr *ret);
int plus_float_ds_alloc_(LocalRoot local, addr left, addr right, addr *ret);
int plus_float_dd_alloc_(LocalRoot local, addr left, addr right, addr *ret);
int plus_float_dl_alloc_(LocalRoot local, addr left, addr right, addr *ret);
int plus_float_ls_alloc_(LocalRoot local, addr left, addr right, addr *ret);
int plus_float_ld_alloc_(LocalRoot local, addr left, addr right, addr *ret);
int plus_float_ll_alloc_(LocalRoot local, addr left, addr right, addr *ret);
int plus_float_ss_local_(LocalRoot local, addr left, addr right, addr *ret);
int plus_float_sd_local_(LocalRoot local, addr left, addr right, addr *ret);
int plus_float_sl_local_(LocalRoot local, addr left, addr right, addr *ret);
int plus_float_ds_local_(LocalRoot local, addr left, addr right, addr *ret);
int plus_float_dd_local_(LocalRoot local, addr left, addr right, addr *ret);
int plus_float_dl_local_(LocalRoot local, addr left, addr right, addr *ret);
int plus_float_ls_local_(LocalRoot local, addr left, addr right, addr *ret);
int plus_float_ld_local_(LocalRoot local, addr left, addr right, addr *ret);
int plus_float_ll_local_(LocalRoot local, addr left, addr right, addr *ret);
int plus_float_ss_heap_(addr left, addr right, addr *ret);
int plus_float_sd_heap_(addr left, addr right, addr *ret);
int plus_float_sl_heap_(addr left, addr right, addr *ret);
int plus_float_ds_heap_(addr left, addr right, addr *ret);
int plus_float_dd_heap_(addr left, addr right, addr *ret);
int plus_float_dl_heap_(addr left, addr right, addr *ret);
int plus_float_ls_heap_(addr left, addr right, addr *ret);
int plus_float_ld_heap_(addr left, addr right, addr *ret);
int plus_float_ll_heap_(addr left, addr right, addr *ret);
int minus_float_fs_alloc_(LocalRoot local, addr left, addr right, addr *ret);
int minus_float_fd_alloc_(LocalRoot local, addr left, addr right, addr *ret);
int minus_float_fl_alloc_(LocalRoot local, addr left, addr right, addr *ret);
int minus_float_fs_local_(LocalRoot local, addr left, addr right, addr *ret);
int minus_float_fd_local_(LocalRoot local, addr left, addr right, addr *ret);
int minus_float_fl_local_(LocalRoot local, addr left, addr right, addr *ret);
int minus_float_fs_heap_(addr left, addr right, addr *ret);
int minus_float_fd_heap_(addr left, addr right, addr *ret);
int minus_float_fl_heap_(addr left, addr right, addr *ret);
int minus_float_sf_alloc_(LocalRoot local, addr left, addr right, addr *ret);
int minus_float_df_alloc_(LocalRoot local, addr left, addr right, addr *ret);
int minus_float_lf_alloc_(LocalRoot local, addr left, addr right, addr *ret);
int minus_float_sf_local_(LocalRoot local, addr left, addr right, addr *ret);
int minus_float_df_local_(LocalRoot local, addr left, addr right, addr *ret);
int minus_float_lf_local_(LocalRoot local, addr left, addr right, addr *ret);
int minus_float_sf_heap_(addr left, addr right, addr *ret);
int minus_float_df_heap_(addr left, addr right, addr *ret);
int minus_float_lf_heap_(addr left, addr right, addr *ret);
int minus_float_bs_alloc_(LocalRoot local, addr left, addr right, addr *ret);
int minus_float_bd_alloc_(LocalRoot local, addr left, addr right, addr *ret);
int minus_float_bl_alloc_(LocalRoot local, addr left, addr right, addr *ret);
int minus_float_bs_local_(LocalRoot local, addr left, addr right, addr *ret);
int minus_float_bd_local_(LocalRoot local, addr left, addr right, addr *ret);
int minus_float_bl_local_(LocalRoot local, addr left, addr right, addr *ret);
int minus_float_bs_heap_(addr left, addr right, addr *ret);
int minus_float_bd_heap_(addr left, addr right, addr *ret);
int minus_float_bl_heap_(addr left, addr right, addr *ret);
int minus_float_sb_alloc_(LocalRoot local, addr left, addr right, addr *ret);
int minus_float_db_alloc_(LocalRoot local, addr left, addr right, addr *ret);
int minus_float_lb_alloc_(LocalRoot local, addr left, addr right, addr *ret);
int minus_float_sb_local_(LocalRoot local, addr left, addr right, addr *ret);
int minus_float_db_local_(LocalRoot local, addr left, addr right, addr *ret);
int minus_float_lb_local_(LocalRoot local, addr left, addr right, addr *ret);
int minus_float_sb_heap_(addr left, addr right, addr *ret);
int minus_float_db_heap_(addr left, addr right, addr *ret);
int minus_float_lb_heap_(addr left, addr right, addr *ret);
int minus_float_rs_alloc_(LocalRoot local, addr left, addr right, addr *ret);
int minus_float_rd_alloc_(LocalRoot local, addr left, addr right, addr *ret);
int minus_float_rl_alloc_(LocalRoot local, addr left, addr right, addr *ret);
int minus_float_rs_local_(LocalRoot local, addr left, addr right, addr *ret);
int minus_float_rd_local_(LocalRoot local, addr left, addr right, addr *ret);
int minus_float_rl_local_(LocalRoot local, addr left, addr right, addr *ret);
int minus_float_rs_heap_(addr left, addr right, addr *ret);
int minus_float_rd_heap_(addr left, addr right, addr *ret);
int minus_float_rl_heap_(addr left, addr right, addr *ret);
int minus_float_sr_alloc_(LocalRoot local, addr left, addr right, addr *ret);
int minus_float_dr_alloc_(LocalRoot local, addr left, addr right, addr *ret);
int minus_float_lr_alloc_(LocalRoot local, addr left, addr right, addr *ret);
int minus_float_sr_local_(LocalRoot local, addr left, addr right, addr *ret);
int minus_float_dr_local_(LocalRoot local, addr left, addr right, addr *ret);
int minus_float_lr_local_(LocalRoot local, addr left, addr right, addr *ret);
int minus_float_sr_heap_(addr left, addr right, addr *ret);
int minus_float_dr_heap_(addr left, addr right, addr *ret);
int minus_float_lr_heap_(addr left, addr right, addr *ret);
int minus_float_ss_alloc_(LocalRoot local, addr left, addr right, addr *ret);
int minus_float_sd_alloc_(LocalRoot local, addr left, addr right, addr *ret);
int minus_float_sl_alloc_(LocalRoot local, addr left, addr right, addr *ret);
int minus_float_ds_alloc_(LocalRoot local, addr left, addr right, addr *ret);
int minus_float_dd_alloc_(LocalRoot local, addr left, addr right, addr *ret);
int minus_float_dl_alloc_(LocalRoot local, addr left, addr right, addr *ret);
int minus_float_ls_alloc_(LocalRoot local, addr left, addr right, addr *ret);
int minus_float_ld_alloc_(LocalRoot local, addr left, addr right, addr *ret);
int minus_float_ll_alloc_(LocalRoot local, addr left, addr right, addr *ret);
int minus_float_ss_local_(LocalRoot local, addr left, addr right, addr *ret);
int minus_float_sd_local_(LocalRoot local, addr left, addr right, addr *ret);
int minus_float_sl_local_(LocalRoot local, addr left, addr right, addr *ret);
int minus_float_ds_local_(LocalRoot local, addr left, addr right, addr *ret);
int minus_float_dd_local_(LocalRoot local, addr left, addr right, addr *ret);
int minus_float_dl_local_(LocalRoot local, addr left, addr right, addr *ret);
int minus_float_ls_local_(LocalRoot local, addr left, addr right, addr *ret);
int minus_float_ld_local_(LocalRoot local, addr left, addr right, addr *ret);
int minus_float_ll_local_(LocalRoot local, addr left, addr right, addr *ret);
int minus_float_ss_heap_(addr left, addr right, addr *ret);
int minus_float_sd_heap_(addr left, addr right, addr *ret);
int minus_float_sl_heap_(addr left, addr right, addr *ret);
int minus_float_ds_heap_(addr left, addr right, addr *ret);
int minus_float_dd_heap_(addr left, addr right, addr *ret);
int minus_float_dl_heap_(addr left, addr right, addr *ret);
int minus_float_ls_heap_(addr left, addr right, addr *ret);
int minus_float_ld_heap_(addr left, addr right, addr *ret);
int minus_float_ll_heap_(addr left, addr right, addr *ret);
#endif
|
9b2e6b37f6eb4e0971d20908557d859ad9ee2a7c
|
b71097386a6da0e3ca65f19a1906f0ebe11eac18
|
/build-aux/yuck-coru.c.m4
|
82beda35ad0e05a3b289f9375d7d91b4deaca514
|
[
"BSD-3-Clause"
] |
permissive
|
hroptatyr/dateutils
|
0584063e4a35c511ad3600c27efb2f4214af24c6
|
c57828809a018061147bc806a058aa4c4b9c449a
|
refs/heads/master
| 2023-09-05T20:26:30.356886
| 2023-07-05T12:19:20
| 2023-07-05T12:19:20
| 2,341,061
| 517
| 44
|
NOASSERTION
| 2023-06-26T12:04:46
| 2011-09-07T11:19:46
|
C
|
UTF-8
|
C
| false
| false
| 13,075
|
m4
|
yuck-coru.c.m4
|
/* -*- c -*- */
changequote`'changequote([,])dnl
changecom([#])dnl
#if defined HAVE_CONFIG_H
# include "config.h"
#endif /* HAVE_CONFIG_H */
#if defined HAVE_VERSION_H
# include "version.h"
#endif /* HAVE_VERSION_H */
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <stdio.h>
#include <limits.h>
changecom([])dnl
ifdef([YUCK_HEADER], [dnl
#include "YUCK_HEADER"
])dnl
changecom([#])dnl
#if defined __INTEL_COMPILER
# pragma warning (push)
# pragma warning (disable:177)
# pragma warning (disable:111)
# pragma warning (disable:3280)
#elif defined __GNUC__
# if __GNUC__ > 4 || __GNUC__ == 4 && __GNUC_MINOR__ >= 6
# pragma GCC diagnostic push
# endif /* GCC version */
# pragma GCC diagnostic ignored "-Wunused-label"
# pragma GCC diagnostic ignored "-Wunused-variable"
# pragma GCC diagnostic ignored "-Wunused-function"
# pragma GCC diagnostic ignored "-Wshadow"
#endif /* __INTEL_COMPILER */
pushdef([DEFUN], ifdef([YUCK_HEADER], [], [static]))[]dnl
static inline bool
yuck_streqp(const char *s1, const char *s2)
{
return !strcmp(s1, s2);
}
/* for multi-args */
static inline char**
yuck_append(char **array, size_t n, char *val)
{
if (!(n % 16U)) {
/* resize */
void *tmp = realloc(array, (n + 16U) * sizeof(*array));
if (tmp == NULL) {
free(array);
return NULL;
}
/* otherwise make it persistent */
array = tmp;
}
array[[n]] = val;
return array;
}
static enum yuck_cmds_e yuck_parse_cmd(const char *cmd)
{
if (0) {
;
}foreachq([__CMD], yuck_cmds(), [ else if (yuck_streqp(cmd, "yuck_cmd_string(defn([__CMD]))")) {
return yuck_cmd(defn([__CMD]));
}]) else {
/* error here? */
fprintf(stderr, "YUCK_UMB_STR: invalid command `%s'\n\
Try `--help' for a list of commands.\n", cmd);
}
return (enum yuck_cmds_e)-1;
}
DEFUN int yuck_parse(yuck_t tgt[[static 1U]], int argc, char *argv[[]])
{
char *op;
int i;
/* we'll have at most this many args */
memset(tgt, 0, sizeof(*tgt));
if ((tgt->args = calloc(argc, sizeof(*tgt->args))) == NULL) {
return -1;
}
ifdef([YUCK_MAX_POSARGS], [], [define([YUCK_MAX_POSARGS], [(size_t)-1])])dnl
for (i = 1; i < argc && tgt->nargs < YUCK_MAX_POSARGS; i++) {
op = argv[[i]];
switch (*op) {
case '-':
/* could be an option */
switch (*++op) {
default:
/* could be glued into one */
for (; *op; op++) {
yield(shortopt, *op);
}
break;
case '-':
if (*++op == '\0') {
i++;
yield(dashdash);
break;
}
yield(longopt, op);
break;
case '\0':
goto plain_dash;
}
break;
default:
plain_dash:
yield(arg, op);
break;
}
}
if (i < argc) {
op = argv[[i]];
if (*op++ == '-' && *op++ == '-' && !*op) {
/* another dashdash, filter out */
i++;
}
}
/* has to be here as the max_pargs condition might drive us here */
coroutine(dashdash)
{
/* dashdash loop, pile everything on tgt->args
* don't check for subcommands either, this is in accordance to
* the git tool which won't accept commands after -- */
for (; i < argc; i++) {
tgt->args[[tgt->nargs++]] = argv[[i]];
}
}
return 0;
coroutine(longopt)
{
/* split into option and arg part */
char *arg;
if ((arg = strchr(op, '=')) != NULL) {
/* \nul this one out */
*arg++ = '\0';
}
switch (tgt->cmd) {
default:
yield(yuck_cmd()[_longopt]);
break;
foreachq([__CMD], yuck_cmds(), [case yuck_cmd(defn([__CMD])):
yield(yuck_cmd(defn([__CMD]))[_longopt]);
break;
])}
resume;
dnl TYPE actions
pushdef([yuck_flag_action], [tgt->yuck_slot([$1], [$2])++; ifdef([YOPT_ALLOW_UNKNOWN_DASHDASH], [], [goto xtra_chk])])dnl
pushdef([yuck_arg_action], [tgt->yuck_slot([$1], [$2]) = arg ?: argv[[++i]]])dnl
pushdef([yuck_arg_opt_action], [tgt->yuck_slot([$1], [$2]) = arg ?: YUCK_OPTARG_NONE])dnl
pushdef([yuck_arg_mul_action], [tgt->yuck_slot([$1], [$2]) =
yuck_append(
tgt->yuck_slot([$1], [$2]), tgt->yuck_cnt_slot([$1], [$2])++,
arg ?: argv[[++i]]);
if (tgt->yuck_slot([$1], [$2]) == NULL) {
return -1;
}])dnl
pushdef([yuck_arg_mul_opt_action], [tgt->yuck_slot([$1], [$2]) =
yuck_append(
tgt->yuck_slot([$1], [$2]), tgt->yuck_cnt_slot([$1], [$2])++,
arg ?: YUCK_OPTARG_NONE);
if (tgt->yuck_slot([$1], [$2]) == NULL) {
return -1;
}])dnl
pushdef([yuck_auto_action], [/* invoke auto action and exit */
yuck_auto_[]yuck_canon([$1], [$2])(tgt);
resume_at(success)])dnl
foreachq([__CMD], yuck_umbcmds(), [coroutine(yuck_cmd(defn([__CMD]))[_longopt])
{
if (0) {
;
}dnl
foreachq([__IDN], yuck_idents(defn([__CMD])), [ dnl
pushdef([long], yuck_long(defn([__IDN]), defn([__CMD])))[]dnl
ifelse(defn([long]), [], [divert(-1)])dnl
else if (yuck_streqp(op, "defn([long])")) {
popdef([long])[]dnl
dnl now simply expand yuck_foo_action:
yuck_option_action(defn([__IDN]), defn([__CMD]));
}dnl
divert[]dnl
]) else {
ifelse(defn([__CMD]), [], [dnl
ifdef([YOPT_ALLOW_UNKNOWN_DASHDASH], [dnl
/* just treat it as argument then */
resume_at(arg);
], [dnl
/* grml */
fprintf(stderr, "YUCK_UMB_STR: unrecognized option `--%s'\n", op);
resume_at(failure);
xtra_chk:
if (arg != NULL) {
fprintf(stderr, "YUCK_UMB_STR: option `--%s' doesn't allow an argument\n", op);
resume_at(failure);
}
])dnl
], [dnl
resume_at(yuck_cmd()[_longopt]);
])dnl
}
if (i >= argc) {
fprintf(stderr, "YUCK_UMB_STR: option `--%s' requires an argument\n", op);
resume_at(failure);
}
resume;
}
])
popdef([yuck_flag_action])dnl
popdef([yuck_arg_action])dnl
popdef([yuck_arg_mul_action])dnl
popdef([yuck_arg_opt_action])dnl
popdef([yuck_arg_mul_opt_action])dnl
popdef([yuck_auto_action])dnl
}
coroutine(shortopt)
{
char *arg = op + 1U;
switch (tgt->cmd) {
default:
yield(yuck_cmd()[_shortopt]);
break;
foreachq([__CMD], yuck_cmds(), [case yuck_cmd(defn([__CMD])):
yield(yuck_cmd(defn([__CMD]))[_shortopt]);
break;
])}
resume;
dnl TYPE actions
pushdef([yuck_flag_action], [tgt->yuck_slot([$1], [$2])++])dnl
pushdef([yuck_arg_action], [tgt->yuck_slot([$1], [$2]) = *arg
? (op += strlen(arg), arg)
: argv[[++i]]])dnl
pushdef([yuck_arg_opt_action], [tgt->yuck_slot([$1], [$2]) = *arg
? (op += strlen(arg), arg)
: YUCK_OPTARG_NONE])dnl
pushdef([yuck_arg_mul_action], [tgt->yuck_slot([$1], [$2]) =
yuck_append(
tgt->yuck_slot([$1], [$2]),
tgt->yuck_cnt_slot([$1], [$2])++,
*arg ? (op += strlen(arg), arg) : argv[[++i]]);
if (tgt->yuck_slot([$1], [$2]) == NULL) {
return -1;
}])dnl
pushdef([yuck_arg_mul_opt_action], [tgt->yuck_slot([$1], [$2]) =
yuck_append(
tgt->yuck_slot([$1], [$2]),
tgt->yuck_cnt_slot([$1], [$2])++,
*arg ? (op += strlen(arg), arg) : YUCK_OPTARG_NONE);
if (tgt->yuck_slot([$1], [$2]) == NULL) {
return -1;
}])dnl
pushdef([yuck_auto_action], [/* invoke auto action and exit */
yuck_auto_[]yuck_canon([$1], [$2])(tgt);
resume_at(success)])dnl
foreachq([__CMD], yuck_umbcmds(), [coroutine(yuck_cmd(defn([__CMD]))[_shortopt])
{
switch (*op) {
default:
/* again for clarity */
switch (*op) {
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
if (op[[-1]] == '-') {
/* literal treatment of numeral */
resume_at(arg);
}
/* fallthrough */
default:
break;
}
divert(1);
ifdef([YOPT_ALLOW_UNKNOWN_DASH], [dnl
resume_at(arg);
], [dnl
fprintf(stderr, "YUCK_UMB_STR: unrecognized option -%c\n", *op);
resume_at(failure);
])dnl
ifdef([YUCK_SHORTS_HAVE_NUMERALS], [
/* [yuck_shorts()] (= yuck_shorts())
* has numerals as shortopts
* don't allow literal treatment of numerals */divert(-1)])
divert(2);
resume_at(yuck_cmd()[_shortopt]);
divert(0);
ifelse(defn([__CMD]), [], [select_divert(1)], [select_divert(2)])dnl
divert[]dnl
foreachq([__IDN], yuck_idents(defn([__CMD])), [dnl
pushdef([short], yuck_short(defn([__IDN]), defn([__CMD])))dnl
ifelse(defn([short]), [], [divert(-1)])dnl
case 'defn([short])':
popdef([short])dnl
dnl
dnl now simply expand yuck_foo_action:
yuck_option_action(defn([__IDN]), defn([__CMD]));
break;
divert[]dnl
])dnl
}
if (i >= argc) {
fprintf(stderr, "YUCK_UMB_STR: option `--%s' requires an argument\n", op);
resume_at(failure);
}
resume;
}
])
popdef([yuck_flag_action])dnl
popdef([yuck_arg_action])dnl
popdef([yuck_arg_opt_action])dnl
popdef([yuck_arg_mul_action])dnl
popdef([yuck_arg_mul_opt_action])dnl
popdef([yuck_auto_action])dnl
}
coroutine(arg)
{
if (tgt->cmd || YUCK_NCMDS == 0U) {
tgt->args[[tgt->nargs++]] = argv[[i]];
} else {
/* ah, might be an arg then */
if ((tgt->cmd = yuck_parse_cmd(op)) > YUCK_NCMDS) {
return -1;
}
}
resume;
}
coroutine(failure)
{
exit(EXIT_FAILURE);
}
coroutine(success)
{
exit(EXIT_SUCCESS);
}
}
DEFUN void yuck_free(yuck_t tgt[[static 1U]])
{
if (tgt->args != NULL) {
/* free despite const qualifier */
free(tgt->args);
}
/* free mulargs */
switch (tgt->cmd) {
void *ptr;
default:
break;
pushdef([action], [dnl
ptr = tgt->yuck_slot([$1], [$2]);
if (ptr != NULL) {
free(ptr);
}
])dnl
dnl TYPE actions
pushdef([yuck_flag_action], [])dnl
pushdef([yuck_arg_action], [])dnl
pushdef([yuck_arg_opt_action], [])dnl
pushdef([yuck_arg_mul_action], defn([action]))dnl
pushdef([yuck_arg_mul_opt_action], defn([action]))dnl
pushdef([yuck_auto_action], [])dnl
foreachq([__CMD], yuck_umbcmds(), [dnl
case yuck_cmd(defn([__CMD])):
foreachq([__IDN], yuck_idents(defn([__CMD])), [dnl
yuck_option_action(defn([__IDN]), defn([__CMD]));
])[]dnl
break;
])[]dnl
popdef([action])dnl
popdef([yuck_flag_action])dnl
popdef([yuck_arg_action])dnl
popdef([yuck_arg_opt_action])dnl
popdef([yuck_arg_mul_action])dnl
popdef([yuck_arg_mul_opt_action])dnl
popdef([yuck_auto_opt_action])dnl
}
return;
}
DEFUN void yuck_auto_usage(const yuck_t src[[static 1U]])
{
switch (src->cmd) {
default:
YUCK_NOCMD:
puts("Usage: YUCK_UMB_STR [[OPTION]]...dnl
ifelse(yuck_cmds(), [], [], [ COMMAND])[]dnl
ifelse(defn([YUCK_UMB_POSARG]), [], [], [ defn([YUCK_UMB_POSARG])])\n\
ifelse(yuck_umb_desc(), [], [], [dnl
\n\
yuck_C_literal(yuck_umb_desc())\n\
])dnl
");
break;
foreachq([__CMD], yuck_cmds(), [
case yuck_cmd(defn([__CMD])):
puts("Usage: YUCK_UMB_STR dnl
yuck_cmd_string(defn([__CMD]))[]dnl
ifelse(yuck_idents(defn([__CMD])), [], [], [ [[OPTION]]...])[]dnl
ifelse(yuck_cmd_posarg(defn([__CMD])), [], [], [ yuck_cmd_posarg(defn([__CMD]))])\n\
ifelse(yuck_cmd_desc(defn([__CMD])), [], [], [dnl
\n\
yuck_C_literal(yuck_cmd_desc(defn([__CMD])))\n\
])dnl
");
break;
])
}
#if defined yuck_post_usage
yuck_post_usage(src);
#endif /* yuck_post_usage */
return;
}
DEFUN void yuck_auto_help(const yuck_t src[[static 1U]])
{
yuck_auto_usage(src);
ifelse(yuck_cmds(), [], [], [dnl
if (src->cmd == YUCK_NOCMD) {
/* also output a list of commands */
puts("COMMAND may be one of:\n\
foreachq([__CMD], yuck_cmds(), [yuck_C_literal(yuck_cmd_line(defn([__CMD])))\n\
])");
}
])dnl
/* leave a not about common options */
if (src->cmd == YUCK_NOCMD) {
ifelse(yuck_cmds(), [], [dnl
;
], [dnl
puts("\
Options accepted by all commands:");
])dnl
ifelse(yuck_cmds(), [], [], [dnl
} else {
puts("\
Common options:\n\
foreachq([__IDN], yuck_idents([]), [dnl
yuck_C_literal(backquote([yuck_option_help_line(defn([__IDN]), [])]))[]dnl
])dnl
");
])dnl
}
switch (src->cmd) {
default:foreachq([__CMD], yuck_umbcmds(), [
case yuck_cmd(defn([__CMD])):
puts("\
ifelse(defn([__CMD]), [], [], [dnl
ifelse(yuck_idents(defn([__CMD])), [], [], [dnl
Command-specific options:\n\
])dnl
])dnl
foreachq([__IDN], yuck_idents(defn([__CMD])), [dnl
yuck_C_literal(backquote([yuck_option_help_line(defn([__IDN]), defn([__CMD]))]))[]dnl
])dnl
");
break;
])
}
#if defined yuck_post_help
yuck_post_help(src);
#endif /* yuck_post_help */
#if defined PACKAGE_BUGREPORT
puts("\n\
Report bugs to " PACKAGE_BUGREPORT);
#endif /* PACKAGE_BUGREPORT */
return;
}
DEFUN void yuck_auto_version(const yuck_t src[[static 1U]])
{
switch (src->cmd) {
default:
ifdef([YUCK_VERSION], [dnl
puts("YUCK_UMB_STR YUCK_VERSION");
], [dnl
#if 0
#elif defined package_string
puts(package_string);
#elif defined package_version
printf("YUCK_UMB_STR %s\n", package_version);
#elif defined PACKAGE_STRING
puts(PACKAGE_STRING);
#elif defined PACKAGE_VERSION
puts("YUCK_UMB_STR " PACKAGE_VERSION);
#elif defined VERSION
puts("YUCK_UMB_STR " VERSION);
#else /* !PACKAGE_VERSION, !VERSION */
puts("YUCK_UMB_STR unknown version");
#endif /* PACKAGE_VERSION */
])dnl
break;
}
#if defined yuck_post_version
yuck_post_version(src);
#endif /* yuck_post_version */
return;
}
popdef([DEFUN])dnl
#if defined __INTEL_COMPILER
# pragma warning (pop)
#elif defined __GNUC__
# if __GNUC__ > 4 || __GNUC__ == 4 && __GNUC_MINOR__ >= 6
# pragma GCC diagnostic pop
# endif /* GCC version */
#endif /* __INTEL_COMPILER */
changequote`'dnl
|
2fbbaef2c03022759ce3df944e4a3a651938b938
|
80018ddd58d966a255305b6ecda3314cc3d63386
|
/src/machine-learning/cnn.c
|
3039203b3045d0afeac635a32854148551a834aa
|
[] |
no_license
|
qq4108863/hihttps
|
983791c383289973893fd7e0abd149f60898a015
|
dbe97ecc9996d03efcd1861a74c37b261d3bd2c6
|
refs/heads/master
| 2023-03-24T19:38:38.075993
| 2023-03-12T03:34:21
| 2023-03-12T03:34:21
| 205,549,145
| 527
| 174
| null | null | null | null |
GB18030
|
C
| false
| false
| 21,977
|
c
|
cnn.c
|
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <math.h>
//#include <random.h>
#include <time.h>
#include "cnn.h"
char* intTochar(int i)// 将数字转换成字符串
{
int itemp=i;
int w=0;
while(itemp>=10){
itemp=itemp/10;
w++;
}
char* ptr=(char*)malloc((w+2)*sizeof(char));
ptr[w+1]='\0';
int r; // 余数
while(i>=10){
r=i%10;
i=i/10;
ptr[w]=(char)(r+48);
w--;
}
ptr[w]=(char)(i+48);
return ptr;
}
char * combine_strings(char *a, char *b) // 将两个字符串相连
{
char *ptr;
int lena=strlen(a),lenb=strlen(b);
int i,l=0;
ptr = (char *)malloc((lena+lenb+1) * sizeof(char));
for(i=0;i<lena;i++)
ptr[l++]=a[i];
for(i=0;i<lenb;i++)
ptr[l++]=b[i];
ptr[l]='\0';
return(ptr);
}
void cnnsetup(CNN* cnn,nSize inputSize,int outputSize)
{
cnn->layerNum=5;
nSize inSize;
int mapSize=5;
inSize.c=inputSize.c;
inSize.r=inputSize.r;
cnn->C1=initCovLayer(inSize.c,inSize.r,5,1,6);
inSize.c=inSize.c-mapSize+1;
inSize.r=inSize.r-mapSize+1;
cnn->S2=initPoolLayer(inSize.c,inSize.r,2,6,6,AvePool);
inSize.c=inSize.c/2;
inSize.r=inSize.r/2;
cnn->C3=initCovLayer(inSize.c,inSize.r,5,6,12);
inSize.c=inSize.c-mapSize+1;
inSize.r=inSize.r-mapSize+1;
cnn->S4=initPoolLayer(inSize.c,inSize.r,2,12,12,AvePool);
inSize.c=inSize.c/2;
inSize.r=inSize.r/2;
cnn->O5=initOutLayer(inSize.c*inSize.r*12,outputSize);
cnn->e=(float*)calloc(cnn->O5->outputNum,sizeof(float));
}
CovLayer* initCovLayer(int inputWidth,int inputHeight,int mapSize,int inChannels,int outChannels)
{
CovLayer* covL=(CovLayer*)malloc(sizeof(CovLayer));
covL->inputHeight=inputHeight;
covL->inputWidth=inputWidth;
covL->mapSize=mapSize;
covL->inChannels=inChannels;
covL->outChannels=outChannels;
covL->isFullConnect=true; // 默认为全连接
// 权重空间的初始化,先行再列调用,[r][c]
int i,j,c,r;
srand((unsigned)time(NULL));
covL->mapData=(float****)malloc(inChannels*sizeof(float***));
for(i=0;i<inChannels;i++){
covL->mapData[i]=(float***)malloc(outChannels*sizeof(float**));
for(j=0;j<outChannels;j++){
covL->mapData[i][j]=(float**)malloc(mapSize*sizeof(float*));
for(r=0;r<mapSize;r++){
covL->mapData[i][j][r]=(float*)malloc(mapSize*sizeof(float));
for(c=0;c<mapSize;c++){
float randnum=(((float)rand()/(float)RAND_MAX)-0.5)*2;
covL->mapData[i][j][r][c]=randnum*sqrt((float)6.0/(float)(mapSize*mapSize*(inChannels+outChannels)));
}
}
}
}
// 权重梯度变化
covL->dmapData=(float****)malloc(inChannels*sizeof(float***));
for(i=0;i<inChannels;i++){
covL->dmapData[i]=(float***)malloc(outChannels*sizeof(float**));
for(j=0;j<outChannels;j++){
covL->dmapData[i][j]=(float**)malloc(mapSize*sizeof(float*));
for(r=0;r<mapSize;r++){
covL->dmapData[i][j][r]=(float*)calloc(mapSize,sizeof(float));
}
}
}
covL->basicData=(float*)calloc(outChannels,sizeof(float));
int outW=inputWidth-mapSize+1;
int outH=inputHeight-mapSize+1;
covL->d=(float***)malloc(outChannels*sizeof(float**));
covL->v=(float***)malloc(outChannels*sizeof(float**));
covL->y=(float***)malloc(outChannels*sizeof(float**));
for(j=0;j<outChannels;j++){
covL->d[j]=(float**)malloc(outH*sizeof(float*));
covL->v[j]=(float**)malloc(outH*sizeof(float*));
covL->y[j]=(float**)malloc(outH*sizeof(float*));
for(r=0;r<outH;r++){
covL->d[j][r]=(float*)calloc(outW,sizeof(float));
covL->v[j][r]=(float*)calloc(outW,sizeof(float));
covL->y[j][r]=(float*)calloc(outW,sizeof(float));
}
}
return covL;
}
PoolLayer* initPoolLayer(int inputWidth,int inputHeight,int mapSize,int inChannels,int outChannels,int poolType)
{
PoolLayer* poolL=(PoolLayer*)malloc(sizeof(PoolLayer));
poolL->inputHeight=inputHeight;
poolL->inputWidth=inputWidth;
poolL->mapSize=mapSize;
poolL->inChannels=inChannels;
poolL->outChannels=outChannels;
poolL->poolType=poolType;
poolL->basicData=(float*)calloc(outChannels,sizeof(float));
int outW=inputWidth/mapSize;
int outH=inputHeight/mapSize;
int j,r;
poolL->d=(float***)malloc(outChannels*sizeof(float**));
poolL->y=(float***)malloc(outChannels*sizeof(float**));
for(j=0;j<outChannels;j++){
poolL->d[j]=(float**)malloc(outH*sizeof(float*));
poolL->y[j]=(float**)malloc(outH*sizeof(float*));
for(r=0;r<outH;r++){
poolL->d[j][r]=(float*)calloc(outW,sizeof(float));
poolL->y[j][r]=(float*)calloc(outW,sizeof(float));
}
}
return poolL;
}
OutLayer* initOutLayer(int inputNum,int outputNum)
{
OutLayer* outL=(OutLayer*)malloc(sizeof(OutLayer));
outL->inputNum=inputNum;
outL->outputNum=outputNum;
outL->basicData=(float*)calloc(outputNum,sizeof(float));
outL->d=(float*)calloc(outputNum,sizeof(float));
outL->v=(float*)calloc(outputNum,sizeof(float));
outL->y=(float*)calloc(outputNum,sizeof(float));
// 权重的初始化
outL->wData=(float**)malloc(outputNum*sizeof(float*)); // 输入行,输出列
int i,j;
srand((unsigned)time(NULL));
for(i=0;i<outputNum;i++){
outL->wData[i]=(float*)malloc(inputNum*sizeof(float));
for(j=0;j<inputNum;j++){
float randnum=(((float)rand()/(float)RAND_MAX)-0.5)*2; // 产生一个-1到1的随机数
outL->wData[i][j]=randnum*sqrt((float)6.0/(float)(inputNum+outputNum));
}
}
outL->isFullConnect=true;
return outL;
}
int vecmaxIndex(float* vec, int veclength)// 返回向量最大数的序号
{
int i;
float maxnum=-1.0;
int maxIndex=0;
for(i=0;i<veclength;i++){
if(maxnum<vec[i]){
maxnum=vec[i];
maxIndex=i;
}
}
return maxIndex;
}
// 测试cnn函数
float cnntest(CNN* cnn, ImgArr inputData,LabelArr outputData,int testNum)
{
int n=0;
int incorrectnum=0; //错误预测的数目
for(n=0;n<testNum;n++){
cnnff(cnn,inputData->ImgPtr[n].ImgData);
if(vecmaxIndex(cnn->O5->y,cnn->O5->outputNum)!=vecmaxIndex(outputData->LabelPtr[n].LabelData,cnn->O5->outputNum))
incorrectnum++;
cnnclear(cnn);
}
return (float)incorrectnum/(float)testNum;
}
// 保存cnn
void savecnn(CNN* cnn, const char* filename)
{
FILE *fp=NULL;
fp=fopen(filename,"wb");
if(fp==NULL)
printf("write file failed\n");
int i,j,r;
// C1的数据
for(i=0;i<cnn->C1->inChannels;i++)
for(j=0;j<cnn->C1->outChannels;j++)
for(r=0;r<cnn->C1->mapSize;r++)
fwrite(cnn->C1->mapData[i][j][r],sizeof(float),cnn->C1->mapSize,fp);
fwrite(cnn->C1->basicData,sizeof(float),cnn->C1->outChannels,fp);
// C3网络
for(i=0;i<cnn->C3->inChannels;i++)
for(j=0;j<cnn->C3->outChannels;j++)
for(r=0;r<cnn->C3->mapSize;r++)
fwrite(cnn->C3->mapData[i][j][r],sizeof(float),cnn->C3->mapSize,fp);
fwrite(cnn->C3->basicData,sizeof(float),cnn->C3->outChannels,fp);
// O5输出层
for(i=0;i<cnn->O5->outputNum;i++)
fwrite(cnn->O5->wData[i],sizeof(float),cnn->O5->inputNum,fp);
fwrite(cnn->O5->basicData,sizeof(float),cnn->O5->outputNum,fp);
fclose(fp);
}
// 导入cnn的数据
void importcnn(CNN* cnn, const char* filename)
{
FILE *fp=NULL;
fp=fopen(filename,"rb");
if(fp==NULL)
printf("write file failed\n");
int i,j,c,r;
// C1的数据
for(i=0;i<cnn->C1->inChannels;i++)
for(j=0;j<cnn->C1->outChannels;j++)
for(r=0;r<cnn->C1->mapSize;r++)
for(c=0;c<cnn->C1->mapSize;c++){
float* in=(float*)malloc(sizeof(float));
fread(in,sizeof(float),1,fp);
cnn->C1->mapData[i][j][r][c]=*in;
}
for(i=0;i<cnn->C1->outChannels;i++)
fread(&cnn->C1->basicData[i],sizeof(float),1,fp);
// C3网络
for(i=0;i<cnn->C3->inChannels;i++)
for(j=0;j<cnn->C3->outChannels;j++)
for(r=0;r<cnn->C3->mapSize;r++)
for(c=0;c<cnn->C3->mapSize;c++)
fread(&cnn->C3->mapData[i][j][r][c],sizeof(float),1,fp);
for(i=0;i<cnn->C3->outChannels;i++)
fread(&cnn->C3->basicData[i],sizeof(float),1,fp);
// O5输出层
for(i=0;i<cnn->O5->outputNum;i++)
for(j=0;j<cnn->O5->inputNum;j++)
fread(&cnn->O5->wData[i][j],sizeof(float),1,fp);
for(i=0;i<cnn->O5->outputNum;i++)
fread(&cnn->O5->basicData[i],sizeof(float),1,fp);
fclose(fp);
}
void cnntrain(CNN* cnn, ImgArr inputData,LabelArr outputData,CNNOpts opts,int trainNum)
{
// 学习训练误差曲线
cnn->L=(float*)malloc(trainNum*sizeof(float));
int e;
for(e=0;e<opts.numepochs;e++){
int n=0;
for(n=0;n<trainNum;n++){
//printf("%d\n",n);
cnnff(cnn,inputData->ImgPtr[n].ImgData); // 前向传播,这里主要计算各
cnnbp(cnn,outputData->LabelPtr[n].LabelData); // 后向传播,这里主要计算各神经元的误差梯度
char* filedir="E:\\Code\\Matlab\\PicTrans\\CNNData\\";
const char* filename=combine_strings(filedir,combine_strings(intTochar(n),".cnn"));
savecnndata(cnn,filename,inputData->ImgPtr[n].ImgData);
cnnapplygrads(cnn,opts,inputData->ImgPtr[n].ImgData); // 更新权重
cnnclear(cnn);
// 计算并保存误差能量
float l=0.0;
int i;
for(i=0;i<cnn->O5->outputNum;i++)
l=l+cnn->e[i]*cnn->e[i];
if(n==0)
cnn->L[n]=l/(float)2.0;
else
cnn->L[n]=cnn->L[n-1]*0.99+0.01*l/(float)2.0;
}
}
}
// 这里InputData是图像数据,inputData[r][c],r行c列,这里根各权重模板是一致的
void cnnff(CNN* cnn,float** inputData)
{
int outSizeW=cnn->S2->inputWidth;
int outSizeH=cnn->S2->inputHeight;
// 第一层的传播
int i,j,r,c;
// 第一层输出数据
nSize mapSize={cnn->C1->mapSize,cnn->C1->mapSize};
nSize inSize={cnn->C1->inputWidth,cnn->C1->inputHeight};
nSize outSize={cnn->S2->inputWidth,cnn->S2->inputHeight};
for(i=0;i<(cnn->C1->outChannels);i++){
for(j=0;j<(cnn->C1->inChannels);j++){
float** mapout=cov(cnn->C1->mapData[j][i],mapSize,inputData,inSize,valid);
addmat(cnn->C1->v[i],cnn->C1->v[i],outSize,mapout,outSize);
for(r=0;r<outSize.r;r++)
free(mapout[r]);
free(mapout);
}
for(r=0;r<outSize.r;r++)
for(c=0;c<outSize.c;c++)
cnn->C1->y[i][r][c]=activation_Sigma(cnn->C1->v[i][r][c],cnn->C1->basicData[i]);
}
// 第二层的输出传播S2,采样层
outSize.c=cnn->C3->inputWidth;
outSize.r=cnn->C3->inputHeight;
inSize.c=cnn->S2->inputWidth;
inSize.r=cnn->S2->inputHeight;
for(i=0;i<(cnn->S2->outChannels);i++){
if(cnn->S2->poolType==AvePool)
avgPooling(cnn->S2->y[i],outSize,cnn->C1->y[i],inSize,cnn->S2->mapSize);
}
// 第三层输出传播,这里是全连接
outSize.c=cnn->S4->inputWidth;
outSize.r=cnn->S4->inputHeight;
inSize.c=cnn->C3->inputWidth;
inSize.r=cnn->C3->inputHeight;
mapSize.c=cnn->C3->mapSize;
mapSize.r=cnn->C3->mapSize;
for(i=0;i<(cnn->C3->outChannels);i++){
for(j=0;j<(cnn->C3->inChannels);j++){
float** mapout=cov(cnn->C3->mapData[j][i],mapSize,cnn->S2->y[j],inSize,valid);
addmat(cnn->C3->v[i],cnn->C3->v[i],outSize,mapout,outSize);
for(r=0;r<outSize.r;r++)
free(mapout[r]);
free(mapout);
}
for(r=0;r<outSize.r;r++)
for(c=0;c<outSize.c;c++)
cnn->C3->y[i][r][c]=activation_Sigma(cnn->C3->v[i][r][c],cnn->C3->basicData[i]);
}
// 第四层的输出传播
inSize.c=cnn->S4->inputWidth;
inSize.r=cnn->S4->inputHeight;
outSize.c=inSize.c/cnn->S4->mapSize;
outSize.r=inSize.r/cnn->S4->mapSize;
for(i=0;i<(cnn->S4->outChannels);i++){
if(cnn->S4->poolType==AvePool)
avgPooling(cnn->S4->y[i],outSize,cnn->C3->y[i],inSize,cnn->S4->mapSize);
}
// 输出层O5的处理
// 首先需要将前面的多维输出展开成一维向量
float* O5inData=(float*)malloc((cnn->O5->inputNum)*sizeof(float));
for(i=0;i<(cnn->S4->outChannels);i++)
for(r=0;r<outSize.r;r++)
for(c=0;c<outSize.c;c++)
O5inData[i*outSize.r*outSize.c+r*outSize.c+c]=cnn->S4->y[i][r][c];
nSize nnSize={cnn->O5->inputNum,cnn->O5->outputNum};
nnff(cnn->O5->v,O5inData,cnn->O5->wData,cnn->O5->basicData,nnSize);
for(i=0;i<cnn->O5->outputNum;i++)
cnn->O5->y[i]=activation_Sigma(cnn->O5->v[i],cnn->O5->basicData[i]);
free(O5inData);
}
// 激活函数 input是数据,inputNum说明数据数目,bas表明偏置
float activation_Sigma(float input,float bas) // sigma激活函数
{
float temp=input+bas;
return (float)1.0/((float)(1.0+exp(-temp)));
}
void avgPooling(float** output,nSize outputSize,float** input,nSize inputSize,int mapSize) // 求平均值
{
int outputW=inputSize.c/mapSize;
int outputH=inputSize.r/mapSize;
if(outputSize.c!=outputW||outputSize.r!=outputH)
printf("ERROR: output size is wrong!!");
int i,j,m,n;
for(i=0;i<outputH;i++)
for(j=0;j<outputW;j++)
{
float sum=0.0;
for(m=i*mapSize;m<i*mapSize+mapSize;m++)
for(n=j*mapSize;n<j*mapSize+mapSize;n++)
sum=sum+input[m][n];
output[i][j]=sum/(float)(mapSize*mapSize);
}
}
// 单层全连接神经网络的前向传播
float vecMulti(float* vec1,float* vec2,int vecL)// 两向量相乘
{
int i;
float m=0;
for(i=0;i<vecL;i++)
m=m+vec1[i]*vec2[i];
return m;
}
void nnff(float* output,float* input,float** wdata,float* bas,nSize nnSize)
{
int w=nnSize.c;
int h=nnSize.r;
int i;
for(i=0;i<h;i++)
output[i]=vecMulti(input,wdata[i],w)+bas[i];
}
float sigma_derivation(float y){ // Logic激活函数的自变量微分
return y*(1-y); // 这里y是指经过激活函数的输出值,而不是自变量
}
void cnnbp(CNN* cnn,float* outputData) // 网络的后向传播
{
int i,j,c,r; // 将误差保存到网络中
for(i=0;i<cnn->O5->outputNum;i++)
cnn->e[i]=cnn->O5->y[i]-outputData[i];
/*从后向前反向计算*/
// 输出层O5
for(i=0;i<cnn->O5->outputNum;i++)
cnn->O5->d[i]=cnn->e[i]*sigma_derivation(cnn->O5->y[i]);
// S4层,传递到S4层的误差
// 这里没有激活函数
nSize outSize={cnn->S4->inputWidth/cnn->S4->mapSize,cnn->S4->inputHeight/cnn->S4->mapSize};
for(i=0;i<cnn->S4->outChannels;i++)
for(r=0;r<outSize.r;r++)
for(c=0;c<outSize.c;c++)
for(j=0;j<cnn->O5->outputNum;j++){
int wInt=i*outSize.c*outSize.r+r*outSize.c+c;
cnn->S4->d[i][r][c]=cnn->S4->d[i][r][c]+cnn->O5->d[j]*cnn->O5->wData[j][wInt];
}
// C3层
// 由S4层传递的各反向误差,这里只是在S4的梯度上扩充一倍
int mapdata=cnn->S4->mapSize;
nSize S4dSize={cnn->S4->inputWidth/cnn->S4->mapSize,cnn->S4->inputHeight/cnn->S4->mapSize};
// 这里的Pooling是求平均,所以反向传递到下一神经元的误差梯度没有变化
for(i=0;i<cnn->C3->outChannels;i++){
float** C3e=UpSample(cnn->S4->d[i],S4dSize,cnn->S4->mapSize,cnn->S4->mapSize);
for(r=0;r<cnn->S4->inputHeight;r++)
for(c=0;c<cnn->S4->inputWidth;c++)
cnn->C3->d[i][r][c]=C3e[r][c]*sigma_derivation(cnn->C3->y[i][r][c])/(float)(cnn->S4->mapSize*cnn->S4->mapSize);
for(r=0;r<cnn->S4->inputHeight;r++)
free(C3e[r]);
free(C3e);
}
// S2层,S2层没有激活函数,这里只有卷积层有激活函数部分
// 由卷积层传递给采样层的误差梯度,这里卷积层共有6*12个卷积模板
outSize.c=cnn->C3->inputWidth;
outSize.r=cnn->C3->inputHeight;
nSize inSize={cnn->S4->inputWidth,cnn->S4->inputHeight};
nSize mapSize={cnn->C3->mapSize,cnn->C3->mapSize};
for(i=0;i<cnn->S2->outChannels;i++){
for(j=0;j<cnn->C3->outChannels;j++){
float** corr=correlation(cnn->C3->mapData[i][j],mapSize,cnn->C3->d[j],inSize,full);
addmat(cnn->S2->d[i],cnn->S2->d[i],outSize,corr,outSize);
for(r=0;r<outSize.r;r++)
free(corr[r]);
free(corr);
}
/*
for(r=0;r<cnn->C3->inputHeight;r++)
for(c=0;c<cnn->C3->inputWidth;c++)
// 这里本来用于采样的激活
*/
}
// C1层,卷积层
mapdata=cnn->S2->mapSize;
nSize S2dSize={cnn->S2->inputWidth/cnn->S2->mapSize,cnn->S2->inputHeight/cnn->S2->mapSize};
// 这里的Pooling是求平均,所以反向传递到下一神经元的误差梯度没有变化
for(i=0;i<cnn->C1->outChannels;i++){
float** C1e=UpSample(cnn->S2->d[i],S2dSize,cnn->S2->mapSize,cnn->S2->mapSize);
for(r=0;r<cnn->S2->inputHeight;r++)
for(c=0;c<cnn->S2->inputWidth;c++)
cnn->C1->d[i][r][c]=C1e[r][c]*sigma_derivation(cnn->C1->y[i][r][c])/(float)(cnn->S2->mapSize*cnn->S2->mapSize);
for(r=0;r<cnn->S2->inputHeight;r++)
free(C1e[r]);
free(C1e);
}
}
void cnnapplygrads(CNN* cnn,CNNOpts opts,float** inputData) // 更新权重
{
// 这里存在权重的主要是卷积层和输出层
// 更新这两个地方的权重就可以了
int i,j,r,c;
// C1层的权重更新
nSize dSize={cnn->S2->inputHeight,cnn->S2->inputWidth};
nSize ySize={cnn->C1->inputHeight,cnn->C1->inputWidth};
nSize mapSize={cnn->C1->mapSize,cnn->C1->mapSize};
for(i=0;i<cnn->C1->outChannels;i++){
for(j=0;j<cnn->C1->inChannels;j++){
float** flipinputData=rotate180(inputData,ySize);
float** C1dk=cov(cnn->C1->d[i],dSize,flipinputData,ySize,valid);
multifactor(C1dk,C1dk,mapSize,-1*opts.alpha);
addmat(cnn->C1->mapData[j][i],cnn->C1->mapData[j][i],mapSize,C1dk,mapSize);
for(r=0;r<(dSize.r-(ySize.r-1));r++)
free(C1dk[r]);
free(C1dk);
for(r=0;r<ySize.r;r++)
free(flipinputData[r]);
free(flipinputData);
}
cnn->C1->basicData[i]=cnn->C1->basicData[i]-opts.alpha*summat(cnn->C1->d[i],dSize);
}
// C3层的权重更新
dSize.c=cnn->S4->inputWidth;
dSize.r=cnn->S4->inputHeight;
ySize.c=cnn->C3->inputWidth;
ySize.r=cnn->C3->inputHeight;
mapSize.c=cnn->C3->mapSize;
mapSize.r=cnn->C3->mapSize;
for(i=0;i<cnn->C3->outChannels;i++){
for(j=0;j<cnn->C3->inChannels;j++){
float** flipinputData=rotate180(cnn->S2->y[j],ySize);
float** C3dk=cov(cnn->C3->d[i],dSize,flipinputData,ySize,valid);
multifactor(C3dk,C3dk,mapSize,-1.0*opts.alpha);
addmat(cnn->C3->mapData[j][i],cnn->C3->mapData[j][i],mapSize,C3dk,mapSize);
for(r=0;r<(dSize.r-(ySize.r-1));r++)
free(C3dk[r]);
free(C3dk);
for(r=0;r<ySize.r;r++)
free(flipinputData[r]);
free(flipinputData);
}
cnn->C3->basicData[i]=cnn->C3->basicData[i]-opts.alpha*summat(cnn->C3->d[i],dSize);
}
// 输出层
// 首先需要将前面的多维输出展开成一维向量
float* O5inData=(float*)malloc((cnn->O5->inputNum)*sizeof(float));
nSize outSize={cnn->S4->inputWidth/cnn->S4->mapSize,cnn->S4->inputHeight/cnn->S4->mapSize};
for(i=0;i<(cnn->S4->outChannels);i++)
for(r=0;r<outSize.r;r++)
for(c=0;c<outSize.c;c++)
O5inData[i*outSize.r*outSize.c+r*outSize.c+c]=cnn->S4->y[i][r][c];
for(j=0;j<cnn->O5->outputNum;j++){
for(i=0;i<cnn->O5->inputNum;i++)
cnn->O5->wData[j][i]=cnn->O5->wData[j][i]-opts.alpha*cnn->O5->d[j]*O5inData[i];
cnn->O5->basicData[j]=cnn->O5->basicData[j]-opts.alpha*cnn->O5->d[j];
}
free(O5inData);
}
void cnnclear(CNN* cnn)
{
// 将神经元的部分数据清除
int j,c,r;
// C1网络
for(j=0;j<cnn->C1->outChannels;j++){
for(r=0;r<cnn->S2->inputHeight;r++){
for(c=0;c<cnn->S2->inputWidth;c++){
cnn->C1->d[j][r][c]=(float)0.0;
cnn->C1->v[j][r][c]=(float)0.0;
cnn->C1->y[j][r][c]=(float)0.0;
}
}
}
// S2网络
for(j=0;j<cnn->S2->outChannels;j++){
for(r=0;r<cnn->C3->inputHeight;r++){
for(c=0;c<cnn->C3->inputWidth;c++){
cnn->S2->d[j][r][c]=(float)0.0;
cnn->S2->y[j][r][c]=(float)0.0;
}
}
}
// C3网络
for(j=0;j<cnn->C3->outChannels;j++){
for(r=0;r<cnn->S4->inputHeight;r++){
for(c=0;c<cnn->S4->inputWidth;c++){
cnn->C3->d[j][r][c]=(float)0.0;
cnn->C3->v[j][r][c]=(float)0.0;
cnn->C3->y[j][r][c]=(float)0.0;
}
}
}
// S4网络
for(j=0;j<cnn->S4->outChannels;j++){
for(r=0;r<cnn->S4->inputHeight/cnn->S4->mapSize;r++){
for(c=0;c<cnn->S4->inputWidth/cnn->S4->mapSize;c++){
cnn->S4->d[j][r][c]=(float)0.0;
cnn->S4->y[j][r][c]=(float)0.0;
}
}
}
// O5输出
for(j=0;j<cnn->O5->outputNum;j++){
cnn->O5->d[j]=(float)0.0;
cnn->O5->v[j]=(float)0.0;
cnn->O5->y[j]=(float)0.0;
}
}
// 这是用于测试的函数
void savecnndata(CNN* cnn,const char* filename,float** inputdata) // 保存CNN网络中的相关数据
{
FILE *fp=NULL;
fp=fopen(filename,"wb");
if(fp==NULL)
printf("write file failed\n");
// C1的数据
int i,j,r;
// C1网络
for(i=0;i<cnn->C1->inputHeight;i++)
fwrite(inputdata[i],sizeof(float),cnn->C1->inputWidth,fp);
for(i=0;i<cnn->C1->inChannels;i++)
for(j=0;j<cnn->C1->outChannels;j++)
for(r=0;r<cnn->C1->mapSize;r++)
fwrite(cnn->C1->mapData[i][j][r],sizeof(float),cnn->C1->mapSize,fp);
fwrite(cnn->C1->basicData,sizeof(float),cnn->C1->outChannels,fp);
for(j=0;j<cnn->C1->outChannels;j++){
for(r=0;r<cnn->S2->inputHeight;r++){
fwrite(cnn->C1->v[j][r],sizeof(float),cnn->S2->inputWidth,fp);
}
for(r=0;r<cnn->S2->inputHeight;r++){
fwrite(cnn->C1->d[j][r],sizeof(float),cnn->S2->inputWidth,fp);
}
for(r=0;r<cnn->S2->inputHeight;r++){
fwrite(cnn->C1->y[j][r],sizeof(float),cnn->S2->inputWidth,fp);
}
}
// S2网络
for(j=0;j<cnn->S2->outChannels;j++){
for(r=0;r<cnn->C3->inputHeight;r++){
fwrite(cnn->S2->d[j][r],sizeof(float),cnn->C3->inputWidth,fp);
}
for(r=0;r<cnn->C3->inputHeight;r++){
fwrite(cnn->S2->y[j][r],sizeof(float),cnn->C3->inputWidth,fp);
}
}
// C3网络
for(i=0;i<cnn->C3->inChannels;i++)
for(j=0;j<cnn->C3->outChannels;j++)
for(r=0;r<cnn->C3->mapSize;r++)
fwrite(cnn->C3->mapData[i][j][r],sizeof(float),cnn->C3->mapSize,fp);
fwrite(cnn->C3->basicData,sizeof(float),cnn->C3->outChannels,fp);
for(j=0;j<cnn->C3->outChannels;j++){
for(r=0;r<cnn->S4->inputHeight;r++){
fwrite(cnn->C3->v[j][r],sizeof(float),cnn->S4->inputWidth,fp);
}
for(r=0;r<cnn->S4->inputHeight;r++){
fwrite(cnn->C3->d[j][r],sizeof(float),cnn->S4->inputWidth,fp);
}
for(r=0;r<cnn->S4->inputHeight;r++){
fwrite(cnn->C3->y[j][r],sizeof(float),cnn->S4->inputWidth,fp);
}
}
// S4网络
for(j=0;j<cnn->S4->outChannels;j++){
for(r=0;r<cnn->S4->inputHeight/cnn->S4->mapSize;r++){
fwrite(cnn->S4->d[j][r],sizeof(float),cnn->S4->inputWidth/cnn->S4->mapSize,fp);
}
for(r=0;r<cnn->S4->inputHeight/cnn->S4->mapSize;r++){
fwrite(cnn->S4->y[j][r],sizeof(float),cnn->S4->inputWidth/cnn->S4->mapSize,fp);
}
}
// O5输出层
for(i=0;i<cnn->O5->outputNum;i++)
fwrite(cnn->O5->wData[i],sizeof(float),cnn->O5->inputNum,fp);
fwrite(cnn->O5->basicData,sizeof(float),cnn->O5->outputNum,fp);
fwrite(cnn->O5->v,sizeof(float),cnn->O5->outputNum,fp);
fwrite(cnn->O5->d,sizeof(float),cnn->O5->outputNum,fp);
fwrite(cnn->O5->y,sizeof(float),cnn->O5->outputNum,fp);
fclose(fp);
}
|
297fcd82798415a14c13af0f6496c86df5bc09b9
|
70ffcb065027032a399f44b9ec91e7b61d73583d
|
/plugins/renepay/debug.c
|
7394dd5d5b9b740809c8523ab215534323379374
|
[
"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
| 1,015
|
c
|
debug.c
|
#include "config.h"
#include <plugins/renepay/debug.h>
void _debug_exec_branch(const char* fname,const char* fun, int lineno)
{
FILE *f = fopen(fname,"a");
fprintf(f,"executing line: %d (%s)\n",lineno,fun);
fclose(f);
}
void _debug_outreq(const char *fname, const struct out_req *req)
{
FILE *f = fopen(fname,"a");
size_t len;
const char * str = json_out_contents(req->js->jout,&len);
fprintf(f,"%s",str);
if (req->errcb)
fprintf(f,"}");
fprintf(f,"}\n");
fclose(f);
}
void _debug_call(const char* fname, const char* fun)
{
FILE *f = fopen(fname,"a");
fprintf(f,"calling function: %s\n",fun);
fclose(f);
}
void _debug_reply(const char* fname, const char* buf,const jsmntok_t *toks)
{
FILE *f = fopen(fname,"a");
fprintf(f,"%.*s\n\n",
json_tok_full_len(toks),
json_tok_full(buf, toks));
fclose(f);
}
void _debug_info(const char* fname, const char *fmt, ...)
{
FILE *f = fopen(fname,"a");
va_list args;
va_start(args, fmt);
vfprintf(f,fmt,args);
va_end(args);
fclose(f);
}
|
09eb7f71a2d62c39159b81bbbef07127e9648001
|
e2bd18a0b6a1d92755573befb52553f90c21d177
|
/cores/arduino/stm8/STM8_StdPeriph_Driver/stm8xx_tim2.c
|
e78e6e22ee6f8bf34ac4c0e38be086c6b50bbb59
|
[
"BSD-3-Clause"
] |
permissive
|
stm32duino/Arduino_Core_STM8
|
2b86bf16943a0ae4f984df79e8a8d7890feae5bf
|
cc4d30f28145a4778dfe228856e6ea48b00390b5
|
refs/heads/main
| 2023-09-02T11:14:06.407352
| 2023-03-31T07:08:07
| 2023-03-31T07:08:07
| 124,064,982
| 143
| 52
|
BSD-3-Clause
| 2021-12-08T09:57:52
| 2018-03-06T10:56:31
|
C
|
UTF-8
|
C
| false
| false
| 193
|
c
|
stm8xx_tim2.c
|
#if defined(STM8Sxx)
#if !defined(STM8S903) || !defined(STM8AF622x)
#include "stm8s_tim2.c"
#endif
#endif /* (STM8S903) || (STM8AF622x) */
#if defined(STM8Lxx)
#include "stm8l15x_tim2.c"
#endif
|
8ad90f56aa02a9c86d5626b4d4eb9d4872954843
|
d7121e03910c4b3aaf4ed470c33c5dab67ffa962
|
/iPhoneOS9.3.sdk/usr/include/arm/arch.h
|
5f638d41f476265f8a5d81d90d4478a5449af3d8
|
[
"MIT"
] |
permissive
|
theos/sdks
|
129eda2d399c209aa36fcc2e266e960ac6c91cf6
|
bb425abf3acae8eac328b828628b82df544d2774
|
refs/heads/master
| 2023-08-28T13:01:04.995109
| 2022-12-24T01:06:07
| 2022-12-24T01:06:07
| 66,124,251
| 517
| 199
|
NOASSERTION
| 2022-12-24T01:06:08
| 2016-08-20T02:36:04
|
C
|
UTF-8
|
C
| false
| false
| 1,134
|
h
|
arch.h
|
/*
* Copyright (c) 2007 Apple Inc. All rights reserved.
*/
#ifndef _ARM_ARCH_H
#define _ARM_ARCH_H
/* Collect the __ARM_ARCH_*__ compiler flags into something easier to use. */
#if defined (__ARM_ARCH_7A__) || defined (__ARM_ARCH_7S__) || defined (__ARM_ARCH_7F__) || defined (__ARM_ARCH_7K__)
#define _ARM_ARCH_7
#endif
#if defined (_ARM_ARCH_7) || defined (__ARM_ARCH_6K__) || defined (__ARM_ARCH_6ZK__)
#define _ARM_ARCH_6K
#endif
#if defined (_ARM_ARCH_7) || defined (__ARM_ARCH_6Z__) || defined (__ARM_ARCH_6ZK__)
#define _ARM_ARCH_6Z
#endif
#if defined (__ARM_ARCH_6__) || defined (__ARM_ARCH_6J__) || \
defined (_ARM_ARCH_6Z) || defined (_ARM_ARCH_6K)
#define _ARM_ARCH_6
#endif
#if defined (_ARM_ARCH_6) || defined (__ARM_ARCH_5E__) || \
defined (__ARM_ARCH_5TE__) || defined (__ARM_ARCH_5TEJ__)
#define _ARM_ARCH_5E
#endif
#if defined (_ARM_ARCH_5E) || defined (__ARM_ARCH_5__) || \
defined (__ARM_ARCH_5T__)
#define _ARM_ARCH_5
#endif
#if defined (_ARM_ARCH_5) || defined (__ARM_ARCH_4T__)
#define _ARM_ARCH_4T
#endif
#if defined (_ARM_ARCH_4T) || defined (__ARM_ARCH_4__)
#define _ARM_ARCH_4
#endif
#endif
|
a66e5ab3c4db49c9d6af52701758d4b9d415f47e
|
b9dc55919b29da24c24f8ee367c5618c9532f56f
|
/Code_source/Compiled/control/bend.out.c
|
3050ee6113086c1dfb83eb9b21189aa8e3c83039
|
[
"WTFPL",
"LicenseRef-scancode-unknown-license-reference"
] |
permissive
|
porres/pd-else
|
075e8b7ac7a78f442055fbd30d6602cae49c887e
|
b30e8c13c88bb9752c08f78514d64c6206d6678b
|
refs/heads/master
| 2023-08-18T22:26:31.120893
| 2023-08-18T00:46:59
| 2023-08-18T00:46:59
| 56,870,805
| 238
| 42
|
WTFPL
| 2023-09-12T15:55:56
| 2016-04-22T16:45:29
|
C
|
UTF-8
|
C
| false
| false
| 1,894
|
c
|
bend.out.c
|
// porres 2018
#include "m_pd.h"
typedef struct _bendout{
t_object x_ob;
t_float x_channel;
t_int x_raw;
}t_bendout;
static t_class *bendout_class;
static void bendout_float(t_bendout *x, t_float f){
t_int bend;
t_int channel = (int)x->x_channel;
if(channel <= 0)
channel = 1;
if(x->x_raw)
bend = (t_int)f;
else
bend = (t_int)(f * 8191) + 8192;
if(bend >= 0 && bend <= 16383){
outlet_float(((t_object *)x)->ob_outlet, 224 + ((channel-1) & 0x0F));
outlet_float(((t_object *)x)->ob_outlet, bend & 0x7F);
outlet_float(((t_object *)x)->ob_outlet, bend >> 7);
}
}
static void *bendout_new(t_symbol *s, t_int ac, t_atom *av){
t_bendout *x = (t_bendout *)pd_new(bendout_class);
t_symbol *curarg = s; // get rid of warning
floatinlet_new((t_object *)x, &x->x_channel);
outlet_new((t_object *)x, &s_float);
t_float channel = 1;
int floatarg = 0;
if(ac){
while(ac > 0){
if(av->a_type == A_FLOAT){
floatarg = 1;
channel = (t_int)atom_getfloatarg(0, ac, av);
ac--, av++;
}
else if(av->a_type == A_SYMBOL && !floatarg){
curarg = atom_getsymbolarg(0, ac, av);
if(curarg == gensym("-raw")){
x->x_raw = 1;
ac--, av++;
}
else
goto errstate;
}
else
goto errstate;
}
}
x->x_channel = (channel > 0 ? channel : 1);
return(x);
errstate:
pd_error(x, "[bend.out]: improper args");
return(NULL);
}
void setup_bend0x2eout(void){
bendout_class = class_new(gensym("bend.out"), (t_newmethod)bendout_new,
0, sizeof(t_bendout), 0, A_GIMME, 0);
class_addfloat(bendout_class, bendout_float);
}
|
7d48b50792f07ff673cd18348e5f1c57415ecb2b
|
31406f420f019a191a74b9288a6e37dcd89e8e82
|
/external/flowparser/include/caml/config.h
|
42f6afad3212d1d63a0bfc1cb69cd03b0c4b6c63
|
[
"MIT"
] |
permissive
|
facebook/hermes
|
b1bf3cb60b5946450c7c9a421ac8dad7a675e0f5
|
440578b31ecce46fcc5ba2ad745ffd5712d63a35
|
refs/heads/main
| 2023-09-06T04:16:02.263184
| 2023-09-05T20:12:54
| 2023-09-05T20:12:54
| 154,201,259
| 8,449
| 593
|
MIT
| 2023-09-14T21:25:56
| 2018-10-22T19:13:00
|
C++
|
UTF-8
|
C
| false
| false
| 7,949
|
h
|
config.h
|
/**************************************************************************/
/* */
/* OCaml */
/* */
/* Xavier Leroy and Damien Doligez, INRIA Rocquencourt */
/* */
/* Copyright 1996 Institut National de Recherche en Informatique et */
/* en Automatique. */
/* */
/* All rights reserved. This file is distributed under the terms of */
/* the GNU Lesser General Public License version 2.1, with the */
/* special exception on linking described in the file LICENSE. */
/* */
/**************************************************************************/
#ifndef CAML_CONFIG_H
#define CAML_CONFIG_H
#ifndef __PIC__
# define ARCH_CODE32
#endif
#define ARCH_SIXTYFOUR
#define SIZEOF_INT 4
#define SIZEOF_LONG 8
#define SIZEOF_PTR 8
#define SIZEOF_SHORT 2
#define SIZEOF_LONGLONG 8
#define INT64_LITERAL(s) s ## LL
#undef ARCH_BIG_ENDIAN
#undef ARCH_ALIGN_DOUBLE
#undef ARCH_ALIGN_INT64
#define ASM_CFI_SUPPORTED
#define PROFINFO_WIDTH 0
#define CAML_WITH_CPLUGINS
#define OCAML_OS_TYPE "Unix"
#define OCAML_STDLIB_DIR "/home/opam/.opam/4.05.0/lib/ocaml"
#define POSIX_SIGNALS
#define HAS_C99_FLOAT_OPS
#define HAS_GETRUSAGE
#define HAS_TIMES
#define HAS_SECURE_GETENV
#define HAS_TERMCAP
#define HAS_SOCKETS
#define HAS_SOCKLEN_T
#define HAS_INET_ATON
#define HAS_IPV6
#define HAS_STDINT_H
#define HAS_UNISTD
#define HAS_OFF_T
#define HAS_DIRENT
#define HAS_REWINDDIR
#define HAS_LOCKF
#define HAS_MKFIFO
#define HAS_GETCWD
#define HAS_GETWD
#define HAS_GETPRIORITY
#define HAS_UTIME
#define HAS_UTIMES
#define HAS_DUP2
#define HAS_FCHMOD
#define HAS_TRUNCATE
#define HAS_SYS_SELECT_H
#define HAS_SELECT
#define HAS_NANOSLEEP
#define HAS_SYMLINK
#define HAS_WAITPID
#define HAS_WAIT4
#define HAS_GETGROUPS
#define HAS_SETGROUPS
#define HAS_INITGROUPS
#define HAS_TERMIOS
#define HAS_ASYNC_IO
#define HAS_SETITIMER
#define HAS_GETHOSTNAME
#define HAS_UNAME
#define HAS_GETTIMEOFDAY
#define HAS_MKTIME
#define HAS_SETSID
#define HAS_PUTENV
#define HAS_LOCALE
#define SUPPORT_DYNAMIC_LINKING
#define HAS_MMAP
#define HAS_PWRITE
#define HAS_NANOSECOND_STAT 1
#define HAS_GETHOSTBYNAME_R 6
#define HAS_GETHOSTBYADDR_R 8
#define HAS_MKSTEMP
#define HAS_NICE
#define HAS_DUP3
#define HAS_PIPE2
#define HAS_ACCEPT4
#define HAS_STACK_OVERFLOW_DETECTION
#define HAS_SIGWAIT
#define HAS_HUGE_PAGES
#define HUGE_PAGE_SIZE (4 * 1024 * 1024)
#ifndef CAML_NAME_SPACE
#include "compatibility.h"
#endif
#ifdef HAS_STDINT_H
#include <stdint.h>
#endif
/* Types for 32-bit integers, 64-bit integers, and
native integers (as wide as a pointer type) */
#ifndef ARCH_INT32_TYPE
#if SIZEOF_INT == 4
#define ARCH_INT32_TYPE int
#define ARCH_UINT32_TYPE unsigned int
#define ARCH_INT32_PRINTF_FORMAT ""
#elif SIZEOF_LONG == 4
#define ARCH_INT32_TYPE long
#define ARCH_UINT32_TYPE unsigned long
#define ARCH_INT32_PRINTF_FORMAT "l"
#elif SIZEOF_SHORT == 4
#define ARCH_INT32_TYPE short
#define ARCH_UINT32_TYPE unsigned short
#define ARCH_INT32_PRINTF_FORMAT ""
#else
#error "No 32-bit integer type available"
#endif
#endif
#ifndef ARCH_INT64_TYPE
#if SIZEOF_LONGLONG == 8
#define ARCH_INT64_TYPE long long
#define ARCH_UINT64_TYPE unsigned long long
#define ARCH_INT64_PRINTF_FORMAT "ll"
#elif SIZEOF_LONG == 8
#define ARCH_INT64_TYPE long
#define ARCH_UINT64_TYPE unsigned long
#define ARCH_INT64_PRINTF_FORMAT "l"
#else
#error "No 64-bit integer type available"
#endif
#endif
#ifndef HAS_STDINT_H
/* Not a C99 compiler, typically MSVC. Define the C99 types we use. */
typedef ARCH_INT32_TYPE int32_t;
typedef ARCH_UINT32_TYPE uint32_t;
typedef ARCH_INT64_TYPE int64_t;
typedef ARCH_UINT64_TYPE uint64_t;
#if SIZEOF_SHORT == 2
typedef short int16_t;
typedef unsigned short uint16_t;
#else
#error "No 16-bit integer type available"
#endif
#endif
#if SIZEOF_PTR == SIZEOF_LONG
/* Standard models: ILP32 or I32LP64 */
typedef long intnat;
typedef unsigned long uintnat;
#define ARCH_INTNAT_PRINTF_FORMAT "l"
#elif SIZEOF_PTR == SIZEOF_INT
/* Hypothetical IP32L64 model */
typedef int intnat;
typedef unsigned int uintnat;
#define ARCH_INTNAT_PRINTF_FORMAT ""
#elif SIZEOF_PTR == 8
/* Win64 model: IL32P64 */
typedef int64_t intnat;
typedef uint64_t uintnat;
#define ARCH_INTNAT_PRINTF_FORMAT ARCH_INT64_PRINTF_FORMAT
#else
#error "No integer type available to represent pointers"
#endif
/* Endianness of floats */
/* ARCH_FLOAT_ENDIANNESS encodes the byte order of doubles as follows:
the value [0xabcdefgh] means that the least significant byte of the
float is at byte offset [a], the next lsb at [b], ..., and the
most significant byte at [h]. */
#if defined(__arm__) && !defined(__ARM_EABI__)
#define ARCH_FLOAT_ENDIANNESS 0x45670123
#elif defined(ARCH_BIG_ENDIAN)
#define ARCH_FLOAT_ENDIANNESS 0x76543210
#else
#define ARCH_FLOAT_ENDIANNESS 0x01234567
#endif
/* We use threaded code interpretation if the compiler provides labels
as first-class values (GCC 2.x). */
#if defined(__GNUC__) && __GNUC__ >= 2 && !defined(DEBUG) \
&& !defined (SHRINKED_GNUC) && !defined(CAML_JIT)
#define THREADED_CODE
#endif
/* Memory model parameters */
/* The size of a page for memory management (in bytes) is [1 << Page_log].
[Page_size] must be a multiple of [sizeof (value)].
[Page_log] must be be >= 8 and <= 20.
Do not change the definition of [Page_size]. */
#define Page_log 12 /* A page is 4 kilobytes. */
#define Page_size (1 << Page_log)
/* Initial size of stack (bytes). */
#define Stack_size (4096 * sizeof(value))
/* Minimum free size of stack (bytes); below that, it is reallocated. */
#define Stack_threshold (256 * sizeof(value))
/* Default maximum size of the stack (words). */
#define Max_stack_def (1024 * 1024)
/* Maximum size of a block allocated in the young generation (words). */
/* Must be > 4 */
#define Max_young_wosize 256
#define Max_young_whsize (Whsize_wosize (Max_young_wosize))
/* Minimum size of the minor zone (words).
This must be at least [2 * Max_young_whsize]. */
#define Minor_heap_min 4096
/* Maximum size of the minor zone (words).
Must be greater than or equal to [Minor_heap_min].
*/
#define Minor_heap_max (1 << 28)
/* Default size of the minor zone. (words) */
#define Minor_heap_def 262144
/* Minimum size increment when growing the heap (words).
Must be a multiple of [Page_size / sizeof (value)]. */
#define Heap_chunk_min (15 * Page_size)
/* Default size increment when growing the heap.
If this is <= 1000, it's a percentage of the current heap size.
If it is > 1000, it's a number of words. */
#define Heap_chunk_def 15
/* Default initial size of the major heap (words);
Must be a multiple of [Page_size / sizeof (value)]. */
#define Init_heap_def (31 * Page_size)
/* (about 512 kB for a 32-bit platform, 1 MB for a 64-bit platform.) */
/* Default speed setting for the major GC. The heap will grow until
the dead objects and the free list represent this percentage of the
total size of live objects. */
#define Percent_free_def 80
/* Default setting for the compacter: 500%
(i.e. trigger the compacter when 5/6 of the heap is free or garbage)
This can be set quite high because the overhead is over-estimated
when fragmentation occurs.
*/
#define Max_percent_free_def 500
/* Default setting for the major GC slice smoothing window: 1
(i.e. no smoothing)
*/
#define Major_window_def 1
/* Maximum size of the major GC slice smoothing window. */
#define Max_major_window 50
#endif /* CAML_CONFIG_H */
|
545af848a8365cb7477e3752fae64a7b8901a89d
|
8e3c9ccc2c77e734331cb2b3753b8a394c6c8c3c
|
/TESTING/MATGEN/dlarot.c
|
c573f4bb40545eb2f12fe22eb2f1c79dd71caf61
|
[
"BSD-2-Clause"
] |
permissive
|
xiaoyeli/superlu
|
ca84bb9f28c0ae97953308edcf07489f3287e1a2
|
1ad483880d9cc5f3eb824b058d95fba7941949cd
|
refs/heads/master
| 2023-09-01T23:43:04.721587
| 2023-08-12T20:39:42
| 2023-08-12T20:39:42
| 51,040,874
| 210
| 101
|
NOASSERTION
| 2023-09-09T19:16:55
| 2016-02-04T00:21:41
|
C
|
UTF-8
|
C
| false
| false
| 10,019
|
c
|
dlarot.c
|
/* -- translated by f2c (version 19940927).
*/
#include <stdbool.h>
/* Table of constant values */
static int c__4 = 4;
static int c__8 = 8;
static int c__1 = 1;
/* Subroutine */
int dlarot_slu(bool *lrows, bool *lleft, bool *lright,
int *nl, double *c, double *s, double *a, int *
lda, double *xleft, double *xright)
{
/* System generated locals */
int i__1;
/* Local variables */
static int iinc;
extern /* Subroutine */ int drot_(int *, double *, int *,
double *, int *, double *, double *);
static int inext, ix, iy, nt;
static double xt[2], yt[2];
extern int input_error(char *, int *);
static int iyt;
/* -- LAPACK auxiliary test routine (version 2.0) --
Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,
Courant Institute, Argonne National Lab, and Rice University
February 29, 1992
Purpose
=======
DLAROT applies a (Givens) rotation to two adjacent rows or
columns, where one element of the first and/or last column/row
may be a separate variable. This is specifically indended
for use on matrices stored in some format other than GE, so
that elements of the matrix may be used or modified for which
no array element is provided.
One example is a symmetric matrix in SB format (bandwidth=4), for
which UPLO='L': Two adjacent rows will have the format:
row j: * * * * * . . . .
row j+1: * * * * * . . . .
'*' indicates elements for which storage is provided,
'.' indicates elements for which no storage is provided, but
are not necessarily zero; their values are determined by
symmetry. ' ' indicates elements which are necessarily zero,
and have no storage provided.
Those columns which have two '*'s can be handled by DROT.
Those columns which have no '*'s can be ignored, since as long
as the Givens rotations are carefully applied to preserve
symmetry, their values are determined.
Those columns which have one '*' have to be handled separately,
by using separate variables "p" and "q":
row j: * * * * * p . . .
row j+1: q * * * * * . . . .
The element p would have to be set correctly, then that column
is rotated, setting p to its new value. The next call to
DLAROT would rotate columns j and j+1, using p, and restore
symmetry. The element q would start out being zero, and be
made non-zero by the rotation. Later, rotations would presumably
be chosen to zero q out.
Typical Calling Sequences: rotating the i-th and (i+1)-st rows.
------- ------- ---------
General dense matrix:
CALL DLAROT(.TRUE.,.FALSE.,.FALSE., N, C,S,
A(i,1),LDA, DUMMY, DUMMY)
General banded matrix in GB format:
j = MAX(1, i-KL )
NL = MIN( N, i+KU+1 ) + 1-j
CALL DLAROT( .TRUE., i-KL.GE.1, i+KU.LT.N, NL, C,S,
A(KU+i+1-j,j),LDA-1, XLEFT, XRIGHT )
[ note that i+1-j is just MIN(i,KL+1) ]
Symmetric banded matrix in SY format, bandwidth K,
lower triangle only:
j = MAX(1, i-K )
NL = MIN( K+1, i ) + 1
CALL DLAROT( .TRUE., i-K.GE.1, .TRUE., NL, C,S,
A(i,j), LDA, XLEFT, XRIGHT )
Same, but upper triangle only:
NL = MIN( K+1, N-i ) + 1
CALL DLAROT( .TRUE., .TRUE., i+K.LT.N, NL, C,S,
A(i,i), LDA, XLEFT, XRIGHT )
Symmetric banded matrix in SB format, bandwidth K,
lower triangle only:
[ same as for SY, except:]
. . . .
A(i+1-j,j), LDA-1, XLEFT, XRIGHT )
[ note that i+1-j is just MIN(i,K+1) ]
Same, but upper triangle only:
. . .
A(K+1,i), LDA-1, XLEFT, XRIGHT )
Rotating columns is just the transpose of rotating rows, except
for GB and SB: (rotating columns i and i+1)
GB:
j = MAX(1, i-KU )
NL = MIN( N, i+KL+1 ) + 1-j
CALL DLAROT( .TRUE., i-KU.GE.1, i+KL.LT.N, NL, C,S,
A(KU+j+1-i,i),LDA-1, XTOP, XBOTTM )
[note that KU+j+1-i is just MAX(1,KU+2-i)]
SB: (upper triangle)
. . . . . .
A(K+j+1-i,i),LDA-1, XTOP, XBOTTM )
SB: (lower triangle)
. . . . . .
A(1,i),LDA-1, XTOP, XBOTTM )
Arguments
=========
LROWS - LOGICAL
If .TRUE., then DLAROT will rotate two rows. If .FALSE.,
then it will rotate two columns.
Not modified.
LLEFT - LOGICAL
If .TRUE., then XLEFT will be used instead of the
corresponding element of A for the first element in the
second row (if LROWS=.FALSE.) or column (if LROWS=.TRUE.)
If .FALSE., then the corresponding element of A will be
used.
Not modified.
LRIGHT - LOGICAL
If .TRUE., then XRIGHT will be used instead of the
corresponding element of A for the last element in the
first row (if LROWS=.FALSE.) or column (if LROWS=.TRUE.) If
.FALSE., then the corresponding element of A will be used.
Not modified.
NL - INTEGER
The length of the rows (if LROWS=.TRUE.) or columns (if
LROWS=.FALSE.) to be rotated. If XLEFT and/or XRIGHT are
used, the columns/rows they are in should be included in
NL, e.g., if LLEFT = LRIGHT = .TRUE., then NL must be at
least 2. The number of rows/columns to be rotated
exclusive of those involving XLEFT and/or XRIGHT may
not be negative, i.e., NL minus how many of LLEFT and
LRIGHT are .TRUE. must be at least zero; if not, INPUT_ERROR
will be called.
Not modified.
C, S - DOUBLE PRECISION
Specify the Givens rotation to be applied. If LROWS is
true, then the matrix ( c s )
(-s c ) is applied from the left;
if false, then the transpose thereof is applied from the
right. For a Givens rotation, C**2 + S**2 should be 1,
but this is not checked.
Not modified.
A - DOUBLE PRECISION array.
The array containing the rows/columns to be rotated. The
first element of A should be the upper left element to
be rotated.
Read and modified.
LDA - INTEGER
The "effective" leading dimension of A. If A contains
a matrix stored in GE or SY format, then this is just
the leading dimension of A as dimensioned in the calling
routine. If A contains a matrix stored in band (GB or SB)
format, then this should be *one less* than the leading
dimension used in the calling routine. Thus, if
A were dimensioned A(LDA,*) in DLAROT, then A(1,j) would
be the j-th element in the first of the two rows
to be rotated, and A(2,j) would be the j-th in the second,
regardless of how the array may be stored in the calling
routine. [A cannot, however, actually be dimensioned thus,
since for band format, the row number may exceed LDA, which
is not legal FORTRAN.]
If LROWS=.TRUE., then LDA must be at least 1, otherwise
it must be at least NL minus the number of .TRUE. values
in XLEFT and XRIGHT.
Not modified.
XLEFT - DOUBLE PRECISION
If LLEFT is .TRUE., then XLEFT will be used and modified
instead of A(2,1) (if LROWS=.TRUE.) or A(1,2)
(if LROWS=.FALSE.).
Read and modified.
XRIGHT - DOUBLE PRECISION
If LRIGHT is .TRUE., then XRIGHT will be used and modified
instead of A(1,NL) (if LROWS=.TRUE.) or A(NL,1)
(if LROWS=.FALSE.).
Read and modified.
=====================================================================
Set up indices, arrays for ends
Parameter adjustments */
--a;
/* Function Body */
if (*lrows) {
iinc = *lda;
inext = 1;
} else {
iinc = 1;
inext = *lda;
}
if (*lleft) {
nt = 1;
ix = iinc + 1;
iy = *lda + 2;
xt[0] = a[1];
yt[0] = *xleft;
} else {
nt = 0;
ix = 1;
iy = inext + 1;
}
if (*lright) {
iyt = inext + 1 + (*nl - 1) * iinc;
++nt;
xt[nt - 1] = *xright;
yt[nt - 1] = a[iyt];
}
/* Check for errors */
if (*nl < nt) {
input_error("DLAROT", &c__4);
return 0;
}
if (*lda <= 0 || (!(*lrows) && *lda < *nl - nt)) {
input_error("DLAROT", &c__8);
return 0;
}
/* Rotate */
i__1 = *nl - nt;
drot_(&i__1, &a[ix], &iinc, &a[iy], &iinc, c, s);
drot_(&nt, xt, &c__1, yt, &c__1, c, s);
/* Stuff values back into XLEFT, XRIGHT, etc. */
if (*lleft) {
a[1] = xt[0];
*xleft = yt[0];
}
if (*lright) {
*xright = xt[nt - 1];
a[iyt] = yt[nt - 1];
}
return 0;
/* End of DLAROT */
} /* dlarot_slu */
|
506fb6cac1a6c40ea777b2c4349572981bd6b703
|
19a9f2c19bcb81c4a14ba17831d3098de7731fb5
|
/ni/src/ncl/NclBuiltInSupport.h
|
d24e2894c5110669a617ce04ab385b39aee73dc3
|
[
"Apache-2.0"
] |
permissive
|
NCAR/ncl
|
243c30eaefce642d53373aa583b73df72eb59f22
|
8a96101fe14d0cf0f5ed66a5e6b1733084bc69df
|
refs/heads/develop
| 2023-03-17T07:53:18.883458
| 2022-05-11T16:01:03
| 2022-05-11T16:01:03
| 67,087,395
| 254
| 68
|
NOASSERTION
| 2022-10-08T07:20:06
| 2016-09-01T01:34:28
|
C
|
UTF-8
|
C
| false
| false
| 1,078
|
h
|
NclBuiltInSupport.h
|
/*
* $Id: NclBuiltInSupport.h,v 1.2.22.1 2008-03-28 20:37:49 grubin Exp $
*/
/************************************************************************
* *
* Copyright (C) 1995 *
* University Corporation for Atmospheric Research *
* All Rights Reserved *
* *
************************************************************************/
/*
* File:
*
* Author: Ethan Alpert
* National Center for Atmospheric Research
* PO 3000, Boulder, Colorado
*
* Date: Tue Jan 31 15:14:25 MST 1995
*
* Description:
*/
#ifndef Ncl_BUILTINSUPPORT_h
#define Ncl_BUILTINSUPPORT_h
extern void *NclGetArgValue(
#if NhlNeedProto
int /*arg_num*/, int /*n_args*/,int* /*n_dims*/, ng_size_t* /*dimsizes*/, NclScalar* /*missing*/, int * /*has_missing*/, NclBasicDataTypes * /*type*/, int /* access_type */
#endif
);
extern NhlErrorTypes NclReturnValue(
#if NhlNeedProto
void *value, int /*n_dims*/, ng_size_t* /*dimsizes*/, NclScalar* /*missing*/, NclBasicDataTypes /*type*/, int /*copy_data*/
#endif
);
#endif /*Ncl_BUILTINSUPPORT_h*/
|
e915e7fbb31e43a11832a6be5a93bacccb21b22d
|
7eaf54a78c9e2117247cb2ab6d3a0c20719ba700
|
/SOFTWARE/A64-TERES/linux-a64/drivers/staging/ozwpan/ozeltbuf.c
|
ac90fc7f5441e517422e9c27efc3b2dbef752fef
|
[
"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
| 9,479
|
c
|
ozeltbuf.c
|
/* -----------------------------------------------------------------------------
* Copyright (c) 2011 Ozmo Inc
* Released under the GNU General Public License Version 2 (GPLv2).
* -----------------------------------------------------------------------------
*/
#include <linux/init.h>
#include <linux/module.h>
#include <linux/netdevice.h>
#include "ozconfig.h"
#include "ozprotocol.h"
#include "ozeltbuf.h"
#include "ozpd.h"
#include "oztrace.h"
/*------------------------------------------------------------------------------
*/
#define OZ_ELT_INFO_MAGIC_USED 0x35791057
#define OZ_ELT_INFO_MAGIC_FREE 0x78940102
/*------------------------------------------------------------------------------
* Context: softirq-serialized
*/
int oz_elt_buf_init(struct oz_elt_buf *buf)
{
memset(buf, 0, sizeof(struct oz_elt_buf));
INIT_LIST_HEAD(&buf->stream_list);
INIT_LIST_HEAD(&buf->order_list);
INIT_LIST_HEAD(&buf->isoc_list);
buf->max_free_elts = 32;
spin_lock_init(&buf->lock);
return 0;
}
/*------------------------------------------------------------------------------
* Context: softirq or process
*/
void oz_elt_buf_term(struct oz_elt_buf *buf)
{
struct list_head *e;
int i;
/* Free any elements in the order or isoc lists. */
for (i = 0; i < 2; i++) {
struct list_head *list;
if (i)
list = &buf->order_list;
else
list = &buf->isoc_list;
e = list->next;
while (e != list) {
struct oz_elt_info *ei =
container_of(e, struct oz_elt_info, link_order);
e = e->next;
kfree(ei);
}
}
/* Free any elelment in the pool. */
while (buf->elt_pool) {
struct oz_elt_info *ei =
container_of(buf->elt_pool, struct oz_elt_info, link);
buf->elt_pool = buf->elt_pool->next;
kfree(ei);
}
buf->free_elts = 0;
}
/*------------------------------------------------------------------------------
* Context: softirq or process
*/
struct oz_elt_info *oz_elt_info_alloc(struct oz_elt_buf *buf)
{
struct oz_elt_info *ei = NULL;
spin_lock_bh(&buf->lock);
if (buf->free_elts && buf->elt_pool) {
ei = container_of(buf->elt_pool, struct oz_elt_info, link);
buf->elt_pool = ei->link.next;
buf->free_elts--;
spin_unlock_bh(&buf->lock);
if (ei->magic != OZ_ELT_INFO_MAGIC_FREE) {
oz_trace("oz_elt_info_alloc: ei with bad magic: 0x%x\n",
ei->magic);
}
} else {
spin_unlock_bh(&buf->lock);
ei = kmalloc(sizeof(struct oz_elt_info), GFP_ATOMIC);
}
if (ei) {
ei->flags = 0;
ei->app_id = 0;
ei->callback = NULL;
ei->context = 0;
ei->stream = NULL;
ei->magic = OZ_ELT_INFO_MAGIC_USED;
INIT_LIST_HEAD(&ei->link);
INIT_LIST_HEAD(&ei->link_order);
}
return ei;
}
/*------------------------------------------------------------------------------
* Precondition: oz_elt_buf.lock must be held.
* Context: softirq or process
*/
void oz_elt_info_free(struct oz_elt_buf *buf, struct oz_elt_info *ei)
{
if (ei) {
if (ei->magic == OZ_ELT_INFO_MAGIC_USED) {
buf->free_elts++;
ei->link.next = buf->elt_pool;
buf->elt_pool = &ei->link;
ei->magic = OZ_ELT_INFO_MAGIC_FREE;
} else {
oz_trace("oz_elt_info_free: bad magic ei: %p"
" magic: 0x%x\n",
ei, ei->magic);
}
}
}
/*------------------------------------------------------------------------------
* Context: softirq
*/
void oz_elt_info_free_chain(struct oz_elt_buf *buf, struct list_head *list)
{
struct list_head *e;
e = list->next;
spin_lock_bh(&buf->lock);
while (e != list) {
struct oz_elt_info *ei;
ei = container_of(e, struct oz_elt_info, link);
e = e->next;
oz_elt_info_free(buf, ei);
}
spin_unlock_bh(&buf->lock);
}
/*------------------------------------------------------------------------------
*/
int oz_elt_stream_create(struct oz_elt_buf *buf, u8 id, int max_buf_count)
{
struct oz_elt_stream *st;
oz_trace("oz_elt_stream_create(0x%x)\n", id);
st = kzalloc(sizeof(struct oz_elt_stream), GFP_ATOMIC | __GFP_ZERO);
if (st == NULL)
return -ENOMEM;
atomic_set(&st->ref_count, 1);
st->id = id;
st->max_buf_count = max_buf_count;
INIT_LIST_HEAD(&st->elt_list);
spin_lock_bh(&buf->lock);
list_add_tail(&st->link, &buf->stream_list);
spin_unlock_bh(&buf->lock);
return 0;
}
/*------------------------------------------------------------------------------
*/
int oz_elt_stream_delete(struct oz_elt_buf *buf, u8 id)
{
struct list_head *e;
struct oz_elt_stream *st = NULL;
oz_trace("oz_elt_stream_delete(0x%x)\n", id);
spin_lock_bh(&buf->lock);
e = buf->stream_list.next;
while (e != &buf->stream_list) {
st = container_of(e, struct oz_elt_stream, link);
if (st->id == id) {
list_del(e);
break;
}
st = NULL;
}
if (!st) {
spin_unlock_bh(&buf->lock);
return -1;
}
e = st->elt_list.next;
while (e != &st->elt_list) {
struct oz_elt_info *ei =
container_of(e, struct oz_elt_info, link);
e = e->next;
list_del_init(&ei->link);
list_del_init(&ei->link_order);
st->buf_count -= ei->length;
oz_trace2(OZ_TRACE_STREAM, "Stream down: %d %d %d\n",
st->buf_count,
ei->length, atomic_read(&st->ref_count));
oz_elt_stream_put(st);
oz_elt_info_free(buf, ei);
}
spin_unlock_bh(&buf->lock);
oz_elt_stream_put(st);
return 0;
}
/*------------------------------------------------------------------------------
*/
void oz_elt_stream_get(struct oz_elt_stream *st)
{
atomic_inc(&st->ref_count);
}
/*------------------------------------------------------------------------------
*/
void oz_elt_stream_put(struct oz_elt_stream *st)
{
if (atomic_dec_and_test(&st->ref_count)) {
oz_trace("Stream destroyed\n");
kfree(st);
}
}
/*------------------------------------------------------------------------------
* Precondition: Element buffer lock must be held.
* If this function fails the caller is responsible for deallocating the elt
* info structure.
*/
int oz_queue_elt_info(struct oz_elt_buf *buf, u8 isoc, u8 id,
struct oz_elt_info *ei)
{
struct oz_elt_stream *st = NULL;
struct list_head *e;
if (id) {
list_for_each(e, &buf->stream_list) {
st = container_of(e, struct oz_elt_stream, link);
if (st->id == id)
break;
}
if (e == &buf->stream_list) {
/* Stream specified but stream not known so fail.
* Caller deallocates element info. */
return -1;
}
}
if (st) {
/* If this is an ISOC fixed element that needs a frame number
* then insert that now. Earlier we stored the unit count in
* this field.
*/
struct oz_isoc_fixed *body = (struct oz_isoc_fixed *)
&ei->data[sizeof(struct oz_elt)];
if ((body->app_id == OZ_APPID_USB) && (body->type
== OZ_USB_ENDPOINT_DATA) &&
(body->format == OZ_DATA_F_ISOC_FIXED)) {
u8 unit_count = body->frame_number;
body->frame_number = st->frame_number;
st->frame_number += unit_count;
}
/* Claim stream and update accounts */
oz_elt_stream_get(st);
ei->stream = st;
st->buf_count += ei->length;
/* Add to list in stream. */
list_add_tail(&ei->link, &st->elt_list);
oz_trace2(OZ_TRACE_STREAM, "Stream up: %d %d\n",
st->buf_count, ei->length);
/* Check if we have too much buffered for this stream. If so
* start dropping elements until we are back in bounds.
*/
while ((st->buf_count > st->max_buf_count) &&
!list_empty(&st->elt_list)) {
struct oz_elt_info *ei2 =
list_first_entry(&st->elt_list,
struct oz_elt_info, link);
list_del_init(&ei2->link);
list_del_init(&ei2->link_order);
st->buf_count -= ei2->length;
oz_elt_info_free(buf, ei2);
oz_elt_stream_put(st);
}
}
list_add_tail(&ei->link_order, isoc ?
&buf->isoc_list : &buf->order_list);
return 0;
}
/*------------------------------------------------------------------------------
*/
int oz_select_elts_for_tx(struct oz_elt_buf *buf, u8 isoc, unsigned *len,
unsigned max_len, struct list_head *list)
{
int count = 0;
struct list_head *e;
struct list_head *el;
struct oz_elt_info *ei;
spin_lock_bh(&buf->lock);
if (isoc)
el = &buf->isoc_list;
else
el = &buf->order_list;
e = el->next;
while (e != el) {
struct oz_app_hdr *app_hdr;
ei = container_of(e, struct oz_elt_info, link_order);
e = e->next;
if ((*len + ei->length) <= max_len) {
app_hdr = (struct oz_app_hdr *)
&ei->data[sizeof(struct oz_elt)];
app_hdr->elt_seq_num = buf->tx_seq_num[ei->app_id]++;
if (buf->tx_seq_num[ei->app_id] == 0)
buf->tx_seq_num[ei->app_id] = 1;
*len += ei->length;
list_del(&ei->link);
list_del(&ei->link_order);
if (ei->stream) {
ei->stream->buf_count -= ei->length;
oz_trace2(OZ_TRACE_STREAM,
"Stream down: %d %d\n",
ei->stream->buf_count, ei->length);
oz_elt_stream_put(ei->stream);
ei->stream = NULL;
}
INIT_LIST_HEAD(&ei->link_order);
list_add_tail(&ei->link, list);
count++;
} else {
break;
}
}
spin_unlock_bh(&buf->lock);
return count;
}
/*------------------------------------------------------------------------------
*/
int oz_are_elts_available(struct oz_elt_buf *buf)
{
return buf->order_list.next != &buf->order_list;
}
/*------------------------------------------------------------------------------
*/
void oz_trim_elt_pool(struct oz_elt_buf *buf)
{
struct list_head *free = NULL;
struct list_head *e;
spin_lock_bh(&buf->lock);
while (buf->free_elts > buf->max_free_elts) {
e = buf->elt_pool;
buf->elt_pool = e->next;
e->next = free;
free = e;
buf->free_elts--;
}
spin_unlock_bh(&buf->lock);
while (free) {
struct oz_elt_info *ei =
container_of(free, struct oz_elt_info, link);
free = free->next;
kfree(ei);
}
}
|
742b4320d69d0105fea2065e61ef5c009c55e06c
|
9ceacf33fd96913cac7ef15492c126d96cae6911
|
/sys/dev/pci/drm/amd/amdgpu/vcn_v4_0.c
|
15408c804207d3ae9c60b776ece0eaf78165a627
|
[] |
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
| 62,182
|
c
|
vcn_v4_0.c
|
/*
* Copyright 2021 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.
*
*/
#include <linux/firmware.h>
#include "amdgpu.h"
#include "amdgpu_vcn.h"
#include "amdgpu_pm.h"
#include "amdgpu_cs.h"
#include "soc15.h"
#include "soc15d.h"
#include "soc15_hw_ip.h"
#include "vcn_v2_0.h"
#include "mmsch_v4_0.h"
#include "vcn/vcn_4_0_0_offset.h"
#include "vcn/vcn_4_0_0_sh_mask.h"
#include "ivsrcid/vcn/irqsrcs_vcn_4_0.h"
#include <drm/drm_drv.h>
#define mmUVD_DPG_LMA_CTL regUVD_DPG_LMA_CTL
#define mmUVD_DPG_LMA_CTL_BASE_IDX regUVD_DPG_LMA_CTL_BASE_IDX
#define mmUVD_DPG_LMA_DATA regUVD_DPG_LMA_DATA
#define mmUVD_DPG_LMA_DATA_BASE_IDX regUVD_DPG_LMA_DATA_BASE_IDX
#define VCN_VID_SOC_ADDRESS_2_0 0x1fb00
#define VCN1_VID_SOC_ADDRESS_3_0 0x48300
#define VCN_HARVEST_MMSCH 0
#define RDECODE_MSG_CREATE 0x00000000
#define RDECODE_MESSAGE_CREATE 0x00000001
static int amdgpu_ih_clientid_vcns[] = {
SOC15_IH_CLIENTID_VCN,
SOC15_IH_CLIENTID_VCN1
};
static int vcn_v4_0_start_sriov(struct amdgpu_device *adev);
static void vcn_v4_0_set_unified_ring_funcs(struct amdgpu_device *adev);
static void vcn_v4_0_set_irq_funcs(struct amdgpu_device *adev);
static int vcn_v4_0_set_powergating_state(void *handle,
enum amd_powergating_state state);
static int vcn_v4_0_pause_dpg_mode(struct amdgpu_device *adev,
int inst_idx, struct dpg_pause_state *new_state);
static void vcn_v4_0_unified_ring_set_wptr(struct amdgpu_ring *ring);
/**
* vcn_v4_0_early_init - set function pointers
*
* @handle: amdgpu_device pointer
*
* Set ring and irq function pointers
*/
static int vcn_v4_0_early_init(void *handle)
{
struct amdgpu_device *adev = (struct amdgpu_device *)handle;
if (amdgpu_sriov_vf(adev))
adev->vcn.harvest_config = VCN_HARVEST_MMSCH;
/* re-use enc ring as unified ring */
adev->vcn.num_enc_rings = 1;
vcn_v4_0_set_unified_ring_funcs(adev);
vcn_v4_0_set_irq_funcs(adev);
return 0;
}
/**
* vcn_v4_0_sw_init - sw init for VCN block
*
* @handle: amdgpu_device pointer
*
* Load firmware and sw initialization
*/
static int vcn_v4_0_sw_init(void *handle)
{
struct amdgpu_ring *ring;
struct amdgpu_device *adev = (struct amdgpu_device *)handle;
int i, r;
r = amdgpu_vcn_sw_init(adev);
if (r)
return r;
amdgpu_vcn_setup_ucode(adev);
r = amdgpu_vcn_resume(adev);
if (r)
return r;
for (i = 0; i < adev->vcn.num_vcn_inst; i++) {
volatile struct amdgpu_vcn4_fw_shared *fw_shared;
if (adev->vcn.harvest_config & (1 << i))
continue;
/* Init instance 0 sched_score to 1, so it's scheduled after other instances */
if (i == 0)
atomic_set(&adev->vcn.inst[i].sched_score, 1);
else
atomic_set(&adev->vcn.inst[i].sched_score, 0);
/* VCN UNIFIED TRAP */
r = amdgpu_irq_add_id(adev, amdgpu_ih_clientid_vcns[i],
VCN_4_0__SRCID__UVD_ENC_GENERAL_PURPOSE, &adev->vcn.inst[i].irq);
if (r)
return r;
ring = &adev->vcn.inst[i].ring_enc[0];
ring->use_doorbell = true;
if (amdgpu_sriov_vf(adev))
ring->doorbell_index = (adev->doorbell_index.vcn.vcn_ring0_1 << 1) + i * (adev->vcn.num_enc_rings + 1) + 1;
else
ring->doorbell_index = (adev->doorbell_index.vcn.vcn_ring0_1 << 1) + 2 + 8 * i;
snprintf(ring->name, sizeof(ring->name), "vcn_unified_%d", i);
r = amdgpu_ring_init(adev, ring, 512, &adev->vcn.inst[i].irq, 0,
AMDGPU_RING_PRIO_0, &adev->vcn.inst[i].sched_score);
if (r)
return r;
fw_shared = adev->vcn.inst[i].fw_shared.cpu_addr;
fw_shared->present_flag_0 = cpu_to_le32(AMDGPU_FW_SHARED_FLAG_0_UNIFIED_QUEUE);
fw_shared->sq.is_enabled = 1;
fw_shared->present_flag_0 |= cpu_to_le32(AMDGPU_VCN_SMU_DPM_INTERFACE_FLAG);
fw_shared->smu_dpm_interface.smu_interface_type = (adev->flags & AMD_IS_APU) ?
AMDGPU_VCN_SMU_DPM_INTERFACE_APU : AMDGPU_VCN_SMU_DPM_INTERFACE_DGPU;
if (amdgpu_sriov_vf(adev))
fw_shared->present_flag_0 |= cpu_to_le32(AMDGPU_VCN_VF_RB_SETUP_FLAG);
if (amdgpu_vcnfw_log)
amdgpu_vcn_fwlog_init(&adev->vcn.inst[i]);
}
if (amdgpu_sriov_vf(adev)) {
r = amdgpu_virt_alloc_mm_table(adev);
if (r)
return r;
}
if (adev->pg_flags & AMD_PG_SUPPORT_VCN_DPG)
adev->vcn.pause_dpg_mode = vcn_v4_0_pause_dpg_mode;
return 0;
}
/**
* vcn_v4_0_sw_fini - sw fini for VCN block
*
* @handle: amdgpu_device pointer
*
* VCN suspend and free up sw allocation
*/
static int vcn_v4_0_sw_fini(void *handle)
{
struct amdgpu_device *adev = (struct amdgpu_device *)handle;
int i, r, idx;
if (drm_dev_enter(adev_to_drm(adev), &idx)) {
for (i = 0; i < adev->vcn.num_vcn_inst; i++) {
volatile struct amdgpu_vcn4_fw_shared *fw_shared;
if (adev->vcn.harvest_config & (1 << i))
continue;
fw_shared = adev->vcn.inst[i].fw_shared.cpu_addr;
fw_shared->present_flag_0 = 0;
fw_shared->sq.is_enabled = 0;
}
drm_dev_exit(idx);
}
if (amdgpu_sriov_vf(adev))
amdgpu_virt_free_mm_table(adev);
r = amdgpu_vcn_suspend(adev);
if (r)
return r;
r = amdgpu_vcn_sw_fini(adev);
return r;
}
/**
* vcn_v4_0_hw_init - start and test VCN block
*
* @handle: amdgpu_device pointer
*
* Initialize the hardware, boot up the VCPU and do some testing
*/
static int vcn_v4_0_hw_init(void *handle)
{
struct amdgpu_device *adev = (struct amdgpu_device *)handle;
struct amdgpu_ring *ring;
int i, r;
if (amdgpu_sriov_vf(adev)) {
r = vcn_v4_0_start_sriov(adev);
if (r)
goto done;
for (i = 0; i < adev->vcn.num_vcn_inst; ++i) {
if (adev->vcn.harvest_config & (1 << i))
continue;
ring = &adev->vcn.inst[i].ring_enc[0];
if (amdgpu_vcn_is_disabled_vcn(adev, VCN_ENCODE_RING, i)) {
ring->sched.ready = false;
ring->no_scheduler = true;
dev_info(adev->dev, "ring %s is disabled by hypervisor\n", ring->name);
} else {
ring->wptr = 0;
ring->wptr_old = 0;
vcn_v4_0_unified_ring_set_wptr(ring);
ring->sched.ready = true;
}
}
} else {
for (i = 0; i < adev->vcn.num_vcn_inst; ++i) {
if (adev->vcn.harvest_config & (1 << i))
continue;
ring = &adev->vcn.inst[i].ring_enc[0];
adev->nbio.funcs->vcn_doorbell_range(adev, ring->use_doorbell,
((adev->doorbell_index.vcn.vcn_ring0_1 << 1) + 8 * i), i);
r = amdgpu_ring_test_helper(ring);
if (r)
goto done;
}
}
done:
if (!r)
DRM_INFO("VCN decode and encode initialized successfully(under %s).\n",
(adev->pg_flags & AMD_PG_SUPPORT_VCN_DPG)?"DPG Mode":"SPG Mode");
return r;
}
/**
* vcn_v4_0_hw_fini - stop the hardware block
*
* @handle: amdgpu_device pointer
*
* Stop the VCN block, mark ring as not ready any more
*/
static int vcn_v4_0_hw_fini(void *handle)
{
struct amdgpu_device *adev = (struct amdgpu_device *)handle;
int i;
cancel_delayed_work_sync(&adev->vcn.idle_work);
for (i = 0; i < adev->vcn.num_vcn_inst; ++i) {
if (adev->vcn.harvest_config & (1 << i))
continue;
if (!amdgpu_sriov_vf(adev)) {
if ((adev->pg_flags & AMD_PG_SUPPORT_VCN_DPG) ||
(adev->vcn.cur_state != AMD_PG_STATE_GATE &&
RREG32_SOC15(VCN, i, regUVD_STATUS))) {
vcn_v4_0_set_powergating_state(adev, AMD_PG_STATE_GATE);
}
}
}
return 0;
}
/**
* vcn_v4_0_suspend - suspend VCN block
*
* @handle: amdgpu_device pointer
*
* HW fini and suspend VCN block
*/
static int vcn_v4_0_suspend(void *handle)
{
int r;
struct amdgpu_device *adev = (struct amdgpu_device *)handle;
r = vcn_v4_0_hw_fini(adev);
if (r)
return r;
r = amdgpu_vcn_suspend(adev);
return r;
}
/**
* vcn_v4_0_resume - resume VCN block
*
* @handle: amdgpu_device pointer
*
* Resume firmware and hw init VCN block
*/
static int vcn_v4_0_resume(void *handle)
{
int r;
struct amdgpu_device *adev = (struct amdgpu_device *)handle;
r = amdgpu_vcn_resume(adev);
if (r)
return r;
r = vcn_v4_0_hw_init(adev);
return r;
}
/**
* vcn_v4_0_mc_resume - memory controller programming
*
* @adev: amdgpu_device pointer
* @inst: instance number
*
* Let the VCN memory controller know it's offsets
*/
static void vcn_v4_0_mc_resume(struct amdgpu_device *adev, int inst)
{
uint32_t offset, size;
const struct common_firmware_header *hdr;
hdr = (const struct common_firmware_header *)adev->vcn.fw->data;
size = AMDGPU_GPU_PAGE_ALIGN(le32_to_cpu(hdr->ucode_size_bytes) + 8);
/* cache window 0: fw */
if (adev->firmware.load_type == AMDGPU_FW_LOAD_PSP) {
WREG32_SOC15(VCN, inst, regUVD_LMI_VCPU_CACHE_64BIT_BAR_LOW,
(adev->firmware.ucode[AMDGPU_UCODE_ID_VCN + inst].tmr_mc_addr_lo));
WREG32_SOC15(VCN, inst, regUVD_LMI_VCPU_CACHE_64BIT_BAR_HIGH,
(adev->firmware.ucode[AMDGPU_UCODE_ID_VCN + inst].tmr_mc_addr_hi));
WREG32_SOC15(VCN, inst, regUVD_VCPU_CACHE_OFFSET0, 0);
offset = 0;
} else {
WREG32_SOC15(VCN, inst, regUVD_LMI_VCPU_CACHE_64BIT_BAR_LOW,
lower_32_bits(adev->vcn.inst[inst].gpu_addr));
WREG32_SOC15(VCN, inst, regUVD_LMI_VCPU_CACHE_64BIT_BAR_HIGH,
upper_32_bits(adev->vcn.inst[inst].gpu_addr));
offset = size;
WREG32_SOC15(VCN, inst, regUVD_VCPU_CACHE_OFFSET0, AMDGPU_UVD_FIRMWARE_OFFSET >> 3);
}
WREG32_SOC15(VCN, inst, regUVD_VCPU_CACHE_SIZE0, size);
/* cache window 1: stack */
WREG32_SOC15(VCN, inst, regUVD_LMI_VCPU_CACHE1_64BIT_BAR_LOW,
lower_32_bits(adev->vcn.inst[inst].gpu_addr + offset));
WREG32_SOC15(VCN, inst, regUVD_LMI_VCPU_CACHE1_64BIT_BAR_HIGH,
upper_32_bits(adev->vcn.inst[inst].gpu_addr + offset));
WREG32_SOC15(VCN, inst, regUVD_VCPU_CACHE_OFFSET1, 0);
WREG32_SOC15(VCN, inst, regUVD_VCPU_CACHE_SIZE1, AMDGPU_VCN_STACK_SIZE);
/* cache window 2: context */
WREG32_SOC15(VCN, inst, regUVD_LMI_VCPU_CACHE2_64BIT_BAR_LOW,
lower_32_bits(adev->vcn.inst[inst].gpu_addr + offset + AMDGPU_VCN_STACK_SIZE));
WREG32_SOC15(VCN, inst, regUVD_LMI_VCPU_CACHE2_64BIT_BAR_HIGH,
upper_32_bits(adev->vcn.inst[inst].gpu_addr + offset + AMDGPU_VCN_STACK_SIZE));
WREG32_SOC15(VCN, inst, regUVD_VCPU_CACHE_OFFSET2, 0);
WREG32_SOC15(VCN, inst, regUVD_VCPU_CACHE_SIZE2, AMDGPU_VCN_CONTEXT_SIZE);
/* non-cache window */
WREG32_SOC15(VCN, inst, regUVD_LMI_VCPU_NC0_64BIT_BAR_LOW,
lower_32_bits(adev->vcn.inst[inst].fw_shared.gpu_addr));
WREG32_SOC15(VCN, inst, regUVD_LMI_VCPU_NC0_64BIT_BAR_HIGH,
upper_32_bits(adev->vcn.inst[inst].fw_shared.gpu_addr));
WREG32_SOC15(VCN, inst, regUVD_VCPU_NONCACHE_OFFSET0, 0);
WREG32_SOC15(VCN, inst, regUVD_VCPU_NONCACHE_SIZE0,
AMDGPU_GPU_PAGE_ALIGN(sizeof(struct amdgpu_vcn4_fw_shared)));
}
/**
* vcn_v4_0_mc_resume_dpg_mode - memory controller programming for dpg mode
*
* @adev: amdgpu_device pointer
* @inst_idx: instance number index
* @indirect: indirectly write sram
*
* Let the VCN memory controller know it's offsets with dpg mode
*/
static void vcn_v4_0_mc_resume_dpg_mode(struct amdgpu_device *adev, int inst_idx, bool indirect)
{
uint32_t offset, size;
const struct common_firmware_header *hdr;
hdr = (const struct common_firmware_header *)adev->vcn.fw->data;
size = AMDGPU_GPU_PAGE_ALIGN(le32_to_cpu(hdr->ucode_size_bytes) + 8);
/* cache window 0: fw */
if (adev->firmware.load_type == AMDGPU_FW_LOAD_PSP) {
if (!indirect) {
WREG32_SOC15_DPG_MODE(inst_idx, SOC15_DPG_MODE_OFFSET(
VCN, inst_idx, regUVD_LMI_VCPU_CACHE_64BIT_BAR_LOW),
(adev->firmware.ucode[AMDGPU_UCODE_ID_VCN + inst_idx].tmr_mc_addr_lo), 0, indirect);
WREG32_SOC15_DPG_MODE(inst_idx, SOC15_DPG_MODE_OFFSET(
VCN, inst_idx, regUVD_LMI_VCPU_CACHE_64BIT_BAR_HIGH),
(adev->firmware.ucode[AMDGPU_UCODE_ID_VCN + inst_idx].tmr_mc_addr_hi), 0, indirect);
WREG32_SOC15_DPG_MODE(inst_idx, SOC15_DPG_MODE_OFFSET(
VCN, inst_idx, regUVD_VCPU_CACHE_OFFSET0), 0, 0, indirect);
} else {
WREG32_SOC15_DPG_MODE(inst_idx, SOC15_DPG_MODE_OFFSET(
VCN, inst_idx, regUVD_LMI_VCPU_CACHE_64BIT_BAR_LOW), 0, 0, indirect);
WREG32_SOC15_DPG_MODE(inst_idx, SOC15_DPG_MODE_OFFSET(
VCN, inst_idx, regUVD_LMI_VCPU_CACHE_64BIT_BAR_HIGH), 0, 0, indirect);
WREG32_SOC15_DPG_MODE(inst_idx, SOC15_DPG_MODE_OFFSET(
VCN, inst_idx, regUVD_VCPU_CACHE_OFFSET0), 0, 0, indirect);
}
offset = 0;
} else {
WREG32_SOC15_DPG_MODE(inst_idx, SOC15_DPG_MODE_OFFSET(
VCN, inst_idx, regUVD_LMI_VCPU_CACHE_64BIT_BAR_LOW),
lower_32_bits(adev->vcn.inst[inst_idx].gpu_addr), 0, indirect);
WREG32_SOC15_DPG_MODE(inst_idx, SOC15_DPG_MODE_OFFSET(
VCN, inst_idx, regUVD_LMI_VCPU_CACHE_64BIT_BAR_HIGH),
upper_32_bits(adev->vcn.inst[inst_idx].gpu_addr), 0, indirect);
offset = size;
WREG32_SOC15_DPG_MODE(inst_idx, SOC15_DPG_MODE_OFFSET(
VCN, inst_idx, regUVD_VCPU_CACHE_OFFSET0),
AMDGPU_UVD_FIRMWARE_OFFSET >> 3, 0, indirect);
}
if (!indirect)
WREG32_SOC15_DPG_MODE(inst_idx, SOC15_DPG_MODE_OFFSET(
VCN, inst_idx, regUVD_VCPU_CACHE_SIZE0), size, 0, indirect);
else
WREG32_SOC15_DPG_MODE(inst_idx, SOC15_DPG_MODE_OFFSET(
VCN, inst_idx, regUVD_VCPU_CACHE_SIZE0), 0, 0, indirect);
/* cache window 1: stack */
if (!indirect) {
WREG32_SOC15_DPG_MODE(inst_idx, SOC15_DPG_MODE_OFFSET(
VCN, inst_idx, regUVD_LMI_VCPU_CACHE1_64BIT_BAR_LOW),
lower_32_bits(adev->vcn.inst[inst_idx].gpu_addr + offset), 0, indirect);
WREG32_SOC15_DPG_MODE(inst_idx, SOC15_DPG_MODE_OFFSET(
VCN, inst_idx, regUVD_LMI_VCPU_CACHE1_64BIT_BAR_HIGH),
upper_32_bits(adev->vcn.inst[inst_idx].gpu_addr + offset), 0, indirect);
WREG32_SOC15_DPG_MODE(inst_idx, SOC15_DPG_MODE_OFFSET(
VCN, inst_idx, regUVD_VCPU_CACHE_OFFSET1), 0, 0, indirect);
} else {
WREG32_SOC15_DPG_MODE(inst_idx, SOC15_DPG_MODE_OFFSET(
VCN, inst_idx, regUVD_LMI_VCPU_CACHE1_64BIT_BAR_LOW), 0, 0, indirect);
WREG32_SOC15_DPG_MODE(inst_idx, SOC15_DPG_MODE_OFFSET(
VCN, inst_idx, regUVD_LMI_VCPU_CACHE1_64BIT_BAR_HIGH), 0, 0, indirect);
WREG32_SOC15_DPG_MODE(inst_idx, SOC15_DPG_MODE_OFFSET(
VCN, inst_idx, regUVD_VCPU_CACHE_OFFSET1), 0, 0, indirect);
}
WREG32_SOC15_DPG_MODE(inst_idx, SOC15_DPG_MODE_OFFSET(
VCN, inst_idx, regUVD_VCPU_CACHE_SIZE1), AMDGPU_VCN_STACK_SIZE, 0, indirect);
/* cache window 2: context */
WREG32_SOC15_DPG_MODE(inst_idx, SOC15_DPG_MODE_OFFSET(
VCN, inst_idx, regUVD_LMI_VCPU_CACHE2_64BIT_BAR_LOW),
lower_32_bits(adev->vcn.inst[inst_idx].gpu_addr + offset + AMDGPU_VCN_STACK_SIZE), 0, indirect);
WREG32_SOC15_DPG_MODE(inst_idx, SOC15_DPG_MODE_OFFSET(
VCN, inst_idx, regUVD_LMI_VCPU_CACHE2_64BIT_BAR_HIGH),
upper_32_bits(adev->vcn.inst[inst_idx].gpu_addr + offset + AMDGPU_VCN_STACK_SIZE), 0, indirect);
WREG32_SOC15_DPG_MODE(inst_idx, SOC15_DPG_MODE_OFFSET(
VCN, inst_idx, regUVD_VCPU_CACHE_OFFSET2), 0, 0, indirect);
WREG32_SOC15_DPG_MODE(inst_idx, SOC15_DPG_MODE_OFFSET(
VCN, inst_idx, regUVD_VCPU_CACHE_SIZE2), AMDGPU_VCN_CONTEXT_SIZE, 0, indirect);
/* non-cache window */
WREG32_SOC15_DPG_MODE(inst_idx, SOC15_DPG_MODE_OFFSET(
VCN, inst_idx, regUVD_LMI_VCPU_NC0_64BIT_BAR_LOW),
lower_32_bits(adev->vcn.inst[inst_idx].fw_shared.gpu_addr), 0, indirect);
WREG32_SOC15_DPG_MODE(inst_idx, SOC15_DPG_MODE_OFFSET(
VCN, inst_idx, regUVD_LMI_VCPU_NC0_64BIT_BAR_HIGH),
upper_32_bits(adev->vcn.inst[inst_idx].fw_shared.gpu_addr), 0, indirect);
WREG32_SOC15_DPG_MODE(inst_idx, SOC15_DPG_MODE_OFFSET(
VCN, inst_idx, regUVD_VCPU_NONCACHE_OFFSET0), 0, 0, indirect);
WREG32_SOC15_DPG_MODE(inst_idx, SOC15_DPG_MODE_OFFSET(
VCN, inst_idx, regUVD_VCPU_NONCACHE_SIZE0),
AMDGPU_GPU_PAGE_ALIGN(sizeof(struct amdgpu_vcn4_fw_shared)), 0, indirect);
/* VCN global tiling registers */
WREG32_SOC15_DPG_MODE(inst_idx, SOC15_DPG_MODE_OFFSET(
VCN, 0, regUVD_GFX10_ADDR_CONFIG), adev->gfx.config.gb_addr_config, 0, indirect);
}
/**
* vcn_v4_0_disable_static_power_gating - disable VCN static power gating
*
* @adev: amdgpu_device pointer
* @inst: instance number
*
* Disable static power gating for VCN block
*/
static void vcn_v4_0_disable_static_power_gating(struct amdgpu_device *adev, int inst)
{
uint32_t data = 0;
if (adev->pg_flags & AMD_PG_SUPPORT_VCN) {
data = (1 << UVD_PGFSM_CONFIG__UVDM_PWR_CONFIG__SHIFT
| 1 << UVD_PGFSM_CONFIG__UVDS_PWR_CONFIG__SHIFT
| 1 << UVD_PGFSM_CONFIG__UVDLM_PWR_CONFIG__SHIFT
| 2 << UVD_PGFSM_CONFIG__UVDF_PWR_CONFIG__SHIFT
| 2 << UVD_PGFSM_CONFIG__UVDTC_PWR_CONFIG__SHIFT
| 2 << UVD_PGFSM_CONFIG__UVDB_PWR_CONFIG__SHIFT
| 2 << UVD_PGFSM_CONFIG__UVDTA_PWR_CONFIG__SHIFT
| 2 << UVD_PGFSM_CONFIG__UVDTD_PWR_CONFIG__SHIFT
| 2 << UVD_PGFSM_CONFIG__UVDTE_PWR_CONFIG__SHIFT
| 2 << UVD_PGFSM_CONFIG__UVDE_PWR_CONFIG__SHIFT
| 2 << UVD_PGFSM_CONFIG__UVDAB_PWR_CONFIG__SHIFT
| 2 << UVD_PGFSM_CONFIG__UVDTB_PWR_CONFIG__SHIFT
| 2 << UVD_PGFSM_CONFIG__UVDNA_PWR_CONFIG__SHIFT
| 2 << UVD_PGFSM_CONFIG__UVDNB_PWR_CONFIG__SHIFT);
WREG32_SOC15(VCN, inst, regUVD_PGFSM_CONFIG, data);
SOC15_WAIT_ON_RREG(VCN, inst, regUVD_PGFSM_STATUS,
UVD_PGFSM_STATUS__UVDM_UVDU_UVDLM_PWR_ON_3_0, 0x3F3FFFFF);
} else {
uint32_t value;
value = (inst) ? 0x2200800 : 0;
data = (1 << UVD_PGFSM_CONFIG__UVDM_PWR_CONFIG__SHIFT
| 1 << UVD_PGFSM_CONFIG__UVDS_PWR_CONFIG__SHIFT
| 1 << UVD_PGFSM_CONFIG__UVDLM_PWR_CONFIG__SHIFT
| 1 << UVD_PGFSM_CONFIG__UVDF_PWR_CONFIG__SHIFT
| 1 << UVD_PGFSM_CONFIG__UVDTC_PWR_CONFIG__SHIFT
| 1 << UVD_PGFSM_CONFIG__UVDB_PWR_CONFIG__SHIFT
| 1 << UVD_PGFSM_CONFIG__UVDTA_PWR_CONFIG__SHIFT
| 1 << UVD_PGFSM_CONFIG__UVDTD_PWR_CONFIG__SHIFT
| 1 << UVD_PGFSM_CONFIG__UVDTE_PWR_CONFIG__SHIFT
| 1 << UVD_PGFSM_CONFIG__UVDE_PWR_CONFIG__SHIFT
| 1 << UVD_PGFSM_CONFIG__UVDAB_PWR_CONFIG__SHIFT
| 1 << UVD_PGFSM_CONFIG__UVDTB_PWR_CONFIG__SHIFT
| 1 << UVD_PGFSM_CONFIG__UVDNA_PWR_CONFIG__SHIFT
| 1 << UVD_PGFSM_CONFIG__UVDNB_PWR_CONFIG__SHIFT);
WREG32_SOC15(VCN, inst, regUVD_PGFSM_CONFIG, data);
SOC15_WAIT_ON_RREG(VCN, inst, regUVD_PGFSM_STATUS, value, 0x3F3FFFFF);
}
data = RREG32_SOC15(VCN, inst, regUVD_POWER_STATUS);
data &= ~0x103;
if (adev->pg_flags & AMD_PG_SUPPORT_VCN)
data |= UVD_PGFSM_CONFIG__UVDM_UVDU_PWR_ON |
UVD_POWER_STATUS__UVD_PG_EN_MASK;
WREG32_SOC15(VCN, inst, regUVD_POWER_STATUS, data);
return;
}
/**
* vcn_v4_0_enable_static_power_gating - enable VCN static power gating
*
* @adev: amdgpu_device pointer
* @inst: instance number
*
* Enable static power gating for VCN block
*/
static void vcn_v4_0_enable_static_power_gating(struct amdgpu_device *adev, int inst)
{
uint32_t data;
if (adev->pg_flags & AMD_PG_SUPPORT_VCN) {
/* Before power off, this indicator has to be turned on */
data = RREG32_SOC15(VCN, inst, regUVD_POWER_STATUS);
data &= ~UVD_POWER_STATUS__UVD_POWER_STATUS_MASK;
data |= UVD_POWER_STATUS__UVD_POWER_STATUS_TILES_OFF;
WREG32_SOC15(VCN, inst, regUVD_POWER_STATUS, data);
data = (2 << UVD_PGFSM_CONFIG__UVDM_PWR_CONFIG__SHIFT
| 2 << UVD_PGFSM_CONFIG__UVDS_PWR_CONFIG__SHIFT
| 2 << UVD_PGFSM_CONFIG__UVDF_PWR_CONFIG__SHIFT
| 2 << UVD_PGFSM_CONFIG__UVDTC_PWR_CONFIG__SHIFT
| 2 << UVD_PGFSM_CONFIG__UVDB_PWR_CONFIG__SHIFT
| 2 << UVD_PGFSM_CONFIG__UVDTA_PWR_CONFIG__SHIFT
| 2 << UVD_PGFSM_CONFIG__UVDLM_PWR_CONFIG__SHIFT
| 2 << UVD_PGFSM_CONFIG__UVDTD_PWR_CONFIG__SHIFT
| 2 << UVD_PGFSM_CONFIG__UVDTE_PWR_CONFIG__SHIFT
| 2 << UVD_PGFSM_CONFIG__UVDE_PWR_CONFIG__SHIFT
| 2 << UVD_PGFSM_CONFIG__UVDAB_PWR_CONFIG__SHIFT
| 2 << UVD_PGFSM_CONFIG__UVDTB_PWR_CONFIG__SHIFT
| 2 << UVD_PGFSM_CONFIG__UVDNA_PWR_CONFIG__SHIFT
| 2 << UVD_PGFSM_CONFIG__UVDNB_PWR_CONFIG__SHIFT);
WREG32_SOC15(VCN, inst, regUVD_PGFSM_CONFIG, data);
data = (2 << UVD_PGFSM_STATUS__UVDM_PWR_STATUS__SHIFT
| 2 << UVD_PGFSM_STATUS__UVDS_PWR_STATUS__SHIFT
| 2 << UVD_PGFSM_STATUS__UVDF_PWR_STATUS__SHIFT
| 2 << UVD_PGFSM_STATUS__UVDTC_PWR_STATUS__SHIFT
| 2 << UVD_PGFSM_STATUS__UVDB_PWR_STATUS__SHIFT
| 2 << UVD_PGFSM_STATUS__UVDTA_PWR_STATUS__SHIFT
| 2 << UVD_PGFSM_STATUS__UVDLM_PWR_STATUS__SHIFT
| 2 << UVD_PGFSM_STATUS__UVDTD_PWR_STATUS__SHIFT
| 2 << UVD_PGFSM_STATUS__UVDTE_PWR_STATUS__SHIFT
| 2 << UVD_PGFSM_STATUS__UVDE_PWR_STATUS__SHIFT
| 2 << UVD_PGFSM_STATUS__UVDAB_PWR_STATUS__SHIFT
| 2 << UVD_PGFSM_STATUS__UVDTB_PWR_STATUS__SHIFT
| 2 << UVD_PGFSM_STATUS__UVDNA_PWR_STATUS__SHIFT
| 2 << UVD_PGFSM_STATUS__UVDNB_PWR_STATUS__SHIFT);
SOC15_WAIT_ON_RREG(VCN, inst, regUVD_PGFSM_STATUS, data, 0x3F3FFFFF);
}
return;
}
/**
* vcn_v4_0_disable_clock_gating - disable VCN clock gating
*
* @adev: amdgpu_device pointer
* @inst: instance number
*
* Disable clock gating for VCN block
*/
static void vcn_v4_0_disable_clock_gating(struct amdgpu_device *adev, int inst)
{
uint32_t data;
if (adev->cg_flags & AMD_CG_SUPPORT_VCN_MGCG)
return;
/* VCN disable CGC */
data = RREG32_SOC15(VCN, inst, regUVD_CGC_CTRL);
data &= ~UVD_CGC_CTRL__DYN_CLOCK_MODE_MASK;
data |= 1 << UVD_CGC_CTRL__CLK_GATE_DLY_TIMER__SHIFT;
data |= 4 << UVD_CGC_CTRL__CLK_OFF_DELAY__SHIFT;
WREG32_SOC15(VCN, inst, regUVD_CGC_CTRL, data);
data = RREG32_SOC15(VCN, inst, regUVD_CGC_GATE);
data &= ~(UVD_CGC_GATE__SYS_MASK
| UVD_CGC_GATE__UDEC_MASK
| UVD_CGC_GATE__MPEG2_MASK
| UVD_CGC_GATE__REGS_MASK
| UVD_CGC_GATE__RBC_MASK
| UVD_CGC_GATE__LMI_MC_MASK
| UVD_CGC_GATE__LMI_UMC_MASK
| UVD_CGC_GATE__IDCT_MASK
| UVD_CGC_GATE__MPRD_MASK
| UVD_CGC_GATE__MPC_MASK
| UVD_CGC_GATE__LBSI_MASK
| UVD_CGC_GATE__LRBBM_MASK
| UVD_CGC_GATE__UDEC_RE_MASK
| UVD_CGC_GATE__UDEC_CM_MASK
| UVD_CGC_GATE__UDEC_IT_MASK
| UVD_CGC_GATE__UDEC_DB_MASK
| UVD_CGC_GATE__UDEC_MP_MASK
| UVD_CGC_GATE__WCB_MASK
| UVD_CGC_GATE__VCPU_MASK
| UVD_CGC_GATE__MMSCH_MASK);
WREG32_SOC15(VCN, inst, regUVD_CGC_GATE, data);
SOC15_WAIT_ON_RREG(VCN, inst, regUVD_CGC_GATE, 0, 0xFFFFFFFF);
data = RREG32_SOC15(VCN, inst, regUVD_CGC_CTRL);
data &= ~(UVD_CGC_CTRL__UDEC_RE_MODE_MASK
| UVD_CGC_CTRL__UDEC_CM_MODE_MASK
| UVD_CGC_CTRL__UDEC_IT_MODE_MASK
| UVD_CGC_CTRL__UDEC_DB_MODE_MASK
| UVD_CGC_CTRL__UDEC_MP_MODE_MASK
| UVD_CGC_CTRL__SYS_MODE_MASK
| UVD_CGC_CTRL__UDEC_MODE_MASK
| UVD_CGC_CTRL__MPEG2_MODE_MASK
| UVD_CGC_CTRL__REGS_MODE_MASK
| UVD_CGC_CTRL__RBC_MODE_MASK
| UVD_CGC_CTRL__LMI_MC_MODE_MASK
| UVD_CGC_CTRL__LMI_UMC_MODE_MASK
| UVD_CGC_CTRL__IDCT_MODE_MASK
| UVD_CGC_CTRL__MPRD_MODE_MASK
| UVD_CGC_CTRL__MPC_MODE_MASK
| UVD_CGC_CTRL__LBSI_MODE_MASK
| UVD_CGC_CTRL__LRBBM_MODE_MASK
| UVD_CGC_CTRL__WCB_MODE_MASK
| UVD_CGC_CTRL__VCPU_MODE_MASK
| UVD_CGC_CTRL__MMSCH_MODE_MASK);
WREG32_SOC15(VCN, inst, regUVD_CGC_CTRL, data);
data = RREG32_SOC15(VCN, inst, regUVD_SUVD_CGC_GATE);
data |= (UVD_SUVD_CGC_GATE__SRE_MASK
| UVD_SUVD_CGC_GATE__SIT_MASK
| UVD_SUVD_CGC_GATE__SMP_MASK
| UVD_SUVD_CGC_GATE__SCM_MASK
| UVD_SUVD_CGC_GATE__SDB_MASK
| UVD_SUVD_CGC_GATE__SRE_H264_MASK
| UVD_SUVD_CGC_GATE__SRE_HEVC_MASK
| UVD_SUVD_CGC_GATE__SIT_H264_MASK
| UVD_SUVD_CGC_GATE__SIT_HEVC_MASK
| UVD_SUVD_CGC_GATE__SCM_H264_MASK
| UVD_SUVD_CGC_GATE__SCM_HEVC_MASK
| UVD_SUVD_CGC_GATE__SDB_H264_MASK
| UVD_SUVD_CGC_GATE__SDB_HEVC_MASK
| UVD_SUVD_CGC_GATE__SCLR_MASK
| UVD_SUVD_CGC_GATE__UVD_SC_MASK
| UVD_SUVD_CGC_GATE__ENT_MASK
| UVD_SUVD_CGC_GATE__SIT_HEVC_DEC_MASK
| UVD_SUVD_CGC_GATE__SIT_HEVC_ENC_MASK
| UVD_SUVD_CGC_GATE__SITE_MASK
| UVD_SUVD_CGC_GATE__SRE_VP9_MASK
| UVD_SUVD_CGC_GATE__SCM_VP9_MASK
| UVD_SUVD_CGC_GATE__SIT_VP9_DEC_MASK
| UVD_SUVD_CGC_GATE__SDB_VP9_MASK
| UVD_SUVD_CGC_GATE__IME_HEVC_MASK);
WREG32_SOC15(VCN, inst, regUVD_SUVD_CGC_GATE, data);
data = RREG32_SOC15(VCN, inst, regUVD_SUVD_CGC_CTRL);
data &= ~(UVD_SUVD_CGC_CTRL__SRE_MODE_MASK
| UVD_SUVD_CGC_CTRL__SIT_MODE_MASK
| UVD_SUVD_CGC_CTRL__SMP_MODE_MASK
| UVD_SUVD_CGC_CTRL__SCM_MODE_MASK
| UVD_SUVD_CGC_CTRL__SDB_MODE_MASK
| UVD_SUVD_CGC_CTRL__SCLR_MODE_MASK
| UVD_SUVD_CGC_CTRL__UVD_SC_MODE_MASK
| UVD_SUVD_CGC_CTRL__ENT_MODE_MASK
| UVD_SUVD_CGC_CTRL__IME_MODE_MASK
| UVD_SUVD_CGC_CTRL__SITE_MODE_MASK);
WREG32_SOC15(VCN, inst, regUVD_SUVD_CGC_CTRL, data);
}
/**
* vcn_v4_0_disable_clock_gating_dpg_mode - disable VCN clock gating dpg mode
*
* @adev: amdgpu_device pointer
* @sram_sel: sram select
* @inst_idx: instance number index
* @indirect: indirectly write sram
*
* Disable clock gating for VCN block with dpg mode
*/
static void vcn_v4_0_disable_clock_gating_dpg_mode(struct amdgpu_device *adev, uint8_t sram_sel,
int inst_idx, uint8_t indirect)
{
uint32_t reg_data = 0;
if (adev->cg_flags & AMD_CG_SUPPORT_VCN_MGCG)
return;
/* enable sw clock gating control */
reg_data = 0 << UVD_CGC_CTRL__DYN_CLOCK_MODE__SHIFT;
reg_data |= 1 << UVD_CGC_CTRL__CLK_GATE_DLY_TIMER__SHIFT;
reg_data |= 4 << UVD_CGC_CTRL__CLK_OFF_DELAY__SHIFT;
reg_data &= ~(UVD_CGC_CTRL__UDEC_RE_MODE_MASK |
UVD_CGC_CTRL__UDEC_CM_MODE_MASK |
UVD_CGC_CTRL__UDEC_IT_MODE_MASK |
UVD_CGC_CTRL__UDEC_DB_MODE_MASK |
UVD_CGC_CTRL__UDEC_MP_MODE_MASK |
UVD_CGC_CTRL__SYS_MODE_MASK |
UVD_CGC_CTRL__UDEC_MODE_MASK |
UVD_CGC_CTRL__MPEG2_MODE_MASK |
UVD_CGC_CTRL__REGS_MODE_MASK |
UVD_CGC_CTRL__RBC_MODE_MASK |
UVD_CGC_CTRL__LMI_MC_MODE_MASK |
UVD_CGC_CTRL__LMI_UMC_MODE_MASK |
UVD_CGC_CTRL__IDCT_MODE_MASK |
UVD_CGC_CTRL__MPRD_MODE_MASK |
UVD_CGC_CTRL__MPC_MODE_MASK |
UVD_CGC_CTRL__LBSI_MODE_MASK |
UVD_CGC_CTRL__LRBBM_MODE_MASK |
UVD_CGC_CTRL__WCB_MODE_MASK |
UVD_CGC_CTRL__VCPU_MODE_MASK);
WREG32_SOC15_DPG_MODE(inst_idx, SOC15_DPG_MODE_OFFSET(
VCN, inst_idx, regUVD_CGC_CTRL), reg_data, sram_sel, indirect);
/* turn off clock gating */
WREG32_SOC15_DPG_MODE(inst_idx, SOC15_DPG_MODE_OFFSET(
VCN, inst_idx, regUVD_CGC_GATE), 0, sram_sel, indirect);
/* turn on SUVD clock gating */
WREG32_SOC15_DPG_MODE(inst_idx, SOC15_DPG_MODE_OFFSET(
VCN, inst_idx, regUVD_SUVD_CGC_GATE), 1, sram_sel, indirect);
/* turn on sw mode in UVD_SUVD_CGC_CTRL */
WREG32_SOC15_DPG_MODE(inst_idx, SOC15_DPG_MODE_OFFSET(
VCN, inst_idx, regUVD_SUVD_CGC_CTRL), 0, sram_sel, indirect);
}
/**
* vcn_v4_0_enable_clock_gating - enable VCN clock gating
*
* @adev: amdgpu_device pointer
* @inst: instance number
*
* Enable clock gating for VCN block
*/
static void vcn_v4_0_enable_clock_gating(struct amdgpu_device *adev, int inst)
{
uint32_t data;
if (adev->cg_flags & AMD_CG_SUPPORT_VCN_MGCG)
return;
/* enable VCN CGC */
data = RREG32_SOC15(VCN, inst, regUVD_CGC_CTRL);
data |= 0 << UVD_CGC_CTRL__DYN_CLOCK_MODE__SHIFT;
data |= 1 << UVD_CGC_CTRL__CLK_GATE_DLY_TIMER__SHIFT;
data |= 4 << UVD_CGC_CTRL__CLK_OFF_DELAY__SHIFT;
WREG32_SOC15(VCN, inst, regUVD_CGC_CTRL, data);
data = RREG32_SOC15(VCN, inst, regUVD_CGC_CTRL);
data |= (UVD_CGC_CTRL__UDEC_RE_MODE_MASK
| UVD_CGC_CTRL__UDEC_CM_MODE_MASK
| UVD_CGC_CTRL__UDEC_IT_MODE_MASK
| UVD_CGC_CTRL__UDEC_DB_MODE_MASK
| UVD_CGC_CTRL__UDEC_MP_MODE_MASK
| UVD_CGC_CTRL__SYS_MODE_MASK
| UVD_CGC_CTRL__UDEC_MODE_MASK
| UVD_CGC_CTRL__MPEG2_MODE_MASK
| UVD_CGC_CTRL__REGS_MODE_MASK
| UVD_CGC_CTRL__RBC_MODE_MASK
| UVD_CGC_CTRL__LMI_MC_MODE_MASK
| UVD_CGC_CTRL__LMI_UMC_MODE_MASK
| UVD_CGC_CTRL__IDCT_MODE_MASK
| UVD_CGC_CTRL__MPRD_MODE_MASK
| UVD_CGC_CTRL__MPC_MODE_MASK
| UVD_CGC_CTRL__LBSI_MODE_MASK
| UVD_CGC_CTRL__LRBBM_MODE_MASK
| UVD_CGC_CTRL__WCB_MODE_MASK
| UVD_CGC_CTRL__VCPU_MODE_MASK
| UVD_CGC_CTRL__MMSCH_MODE_MASK);
WREG32_SOC15(VCN, inst, regUVD_CGC_CTRL, data);
data = RREG32_SOC15(VCN, inst, regUVD_SUVD_CGC_CTRL);
data |= (UVD_SUVD_CGC_CTRL__SRE_MODE_MASK
| UVD_SUVD_CGC_CTRL__SIT_MODE_MASK
| UVD_SUVD_CGC_CTRL__SMP_MODE_MASK
| UVD_SUVD_CGC_CTRL__SCM_MODE_MASK
| UVD_SUVD_CGC_CTRL__SDB_MODE_MASK
| UVD_SUVD_CGC_CTRL__SCLR_MODE_MASK
| UVD_SUVD_CGC_CTRL__UVD_SC_MODE_MASK
| UVD_SUVD_CGC_CTRL__ENT_MODE_MASK
| UVD_SUVD_CGC_CTRL__IME_MODE_MASK
| UVD_SUVD_CGC_CTRL__SITE_MODE_MASK);
WREG32_SOC15(VCN, inst, regUVD_SUVD_CGC_CTRL, data);
return;
}
/**
* vcn_v4_0_start_dpg_mode - VCN start with dpg mode
*
* @adev: amdgpu_device pointer
* @inst_idx: instance number index
* @indirect: indirectly write sram
*
* Start VCN block with dpg mode
*/
static int vcn_v4_0_start_dpg_mode(struct amdgpu_device *adev, int inst_idx, bool indirect)
{
volatile struct amdgpu_vcn4_fw_shared *fw_shared = adev->vcn.inst[inst_idx].fw_shared.cpu_addr;
struct amdgpu_ring *ring;
uint32_t tmp;
/* disable register anti-hang mechanism */
WREG32_P(SOC15_REG_OFFSET(VCN, inst_idx, regUVD_POWER_STATUS), 1,
~UVD_POWER_STATUS__UVD_POWER_STATUS_MASK);
/* enable dynamic power gating mode */
tmp = RREG32_SOC15(VCN, inst_idx, regUVD_POWER_STATUS);
tmp |= UVD_POWER_STATUS__UVD_PG_MODE_MASK;
tmp |= UVD_POWER_STATUS__UVD_PG_EN_MASK;
WREG32_SOC15(VCN, inst_idx, regUVD_POWER_STATUS, tmp);
if (indirect)
adev->vcn.inst[inst_idx].dpg_sram_curr_addr = (uint32_t *)adev->vcn.inst[inst_idx].dpg_sram_cpu_addr;
/* enable clock gating */
vcn_v4_0_disable_clock_gating_dpg_mode(adev, 0, inst_idx, indirect);
/* enable VCPU clock */
tmp = (0xFF << UVD_VCPU_CNTL__PRB_TIMEOUT_VAL__SHIFT);
tmp |= UVD_VCPU_CNTL__CLK_EN_MASK | UVD_VCPU_CNTL__BLK_RST_MASK;
WREG32_SOC15_DPG_MODE(inst_idx, SOC15_DPG_MODE_OFFSET(
VCN, inst_idx, regUVD_VCPU_CNTL), tmp, 0, indirect);
/* disable master interupt */
WREG32_SOC15_DPG_MODE(inst_idx, SOC15_DPG_MODE_OFFSET(
VCN, inst_idx, regUVD_MASTINT_EN), 0, 0, indirect);
/* setup regUVD_LMI_CTRL */
tmp = (UVD_LMI_CTRL__WRITE_CLEAN_TIMER_EN_MASK |
UVD_LMI_CTRL__REQ_MODE_MASK |
UVD_LMI_CTRL__CRC_RESET_MASK |
UVD_LMI_CTRL__MASK_MC_URGENT_MASK |
UVD_LMI_CTRL__DATA_COHERENCY_EN_MASK |
UVD_LMI_CTRL__VCPU_DATA_COHERENCY_EN_MASK |
(8 << UVD_LMI_CTRL__WRITE_CLEAN_TIMER__SHIFT) |
0x00100000L);
WREG32_SOC15_DPG_MODE(inst_idx, SOC15_DPG_MODE_OFFSET(
VCN, inst_idx, regUVD_LMI_CTRL), tmp, 0, indirect);
WREG32_SOC15_DPG_MODE(inst_idx, SOC15_DPG_MODE_OFFSET(
VCN, inst_idx, regUVD_MPC_CNTL),
0x2 << UVD_MPC_CNTL__REPLACEMENT_MODE__SHIFT, 0, indirect);
WREG32_SOC15_DPG_MODE(inst_idx, SOC15_DPG_MODE_OFFSET(
VCN, inst_idx, regUVD_MPC_SET_MUXA0),
((0x1 << UVD_MPC_SET_MUXA0__VARA_1__SHIFT) |
(0x2 << UVD_MPC_SET_MUXA0__VARA_2__SHIFT) |
(0x3 << UVD_MPC_SET_MUXA0__VARA_3__SHIFT) |
(0x4 << UVD_MPC_SET_MUXA0__VARA_4__SHIFT)), 0, indirect);
WREG32_SOC15_DPG_MODE(inst_idx, SOC15_DPG_MODE_OFFSET(
VCN, inst_idx, regUVD_MPC_SET_MUXB0),
((0x1 << UVD_MPC_SET_MUXB0__VARB_1__SHIFT) |
(0x2 << UVD_MPC_SET_MUXB0__VARB_2__SHIFT) |
(0x3 << UVD_MPC_SET_MUXB0__VARB_3__SHIFT) |
(0x4 << UVD_MPC_SET_MUXB0__VARB_4__SHIFT)), 0, indirect);
WREG32_SOC15_DPG_MODE(inst_idx, SOC15_DPG_MODE_OFFSET(
VCN, inst_idx, regUVD_MPC_SET_MUX),
((0x0 << UVD_MPC_SET_MUX__SET_0__SHIFT) |
(0x1 << UVD_MPC_SET_MUX__SET_1__SHIFT) |
(0x2 << UVD_MPC_SET_MUX__SET_2__SHIFT)), 0, indirect);
vcn_v4_0_mc_resume_dpg_mode(adev, inst_idx, indirect);
tmp = (0xFF << UVD_VCPU_CNTL__PRB_TIMEOUT_VAL__SHIFT);
tmp |= UVD_VCPU_CNTL__CLK_EN_MASK;
WREG32_SOC15_DPG_MODE(inst_idx, SOC15_DPG_MODE_OFFSET(
VCN, inst_idx, regUVD_VCPU_CNTL), tmp, 0, indirect);
/* enable LMI MC and UMC channels */
tmp = 0x1f << UVD_LMI_CTRL2__RE_OFLD_MIF_WR_REQ_NUM__SHIFT;
WREG32_SOC15_DPG_MODE(inst_idx, SOC15_DPG_MODE_OFFSET(
VCN, inst_idx, regUVD_LMI_CTRL2), tmp, 0, indirect);
/* enable master interrupt */
WREG32_SOC15_DPG_MODE(inst_idx, SOC15_DPG_MODE_OFFSET(
VCN, inst_idx, regUVD_MASTINT_EN),
UVD_MASTINT_EN__VCPU_EN_MASK, 0, indirect);
if (indirect)
psp_update_vcn_sram(adev, inst_idx, adev->vcn.inst[inst_idx].dpg_sram_gpu_addr,
(uint32_t)((uintptr_t)adev->vcn.inst[inst_idx].dpg_sram_curr_addr -
(uintptr_t)adev->vcn.inst[inst_idx].dpg_sram_cpu_addr));
ring = &adev->vcn.inst[inst_idx].ring_enc[0];
WREG32_SOC15(VCN, inst_idx, regUVD_RB_BASE_LO, ring->gpu_addr);
WREG32_SOC15(VCN, inst_idx, regUVD_RB_BASE_HI, upper_32_bits(ring->gpu_addr));
WREG32_SOC15(VCN, inst_idx, regUVD_RB_SIZE, ring->ring_size / 4);
tmp = RREG32_SOC15(VCN, inst_idx, regVCN_RB_ENABLE);
tmp &= ~(VCN_RB_ENABLE__RB1_EN_MASK);
WREG32_SOC15(VCN, inst_idx, regVCN_RB_ENABLE, tmp);
fw_shared->sq.queue_mode |= FW_QUEUE_RING_RESET;
WREG32_SOC15(VCN, inst_idx, regUVD_RB_RPTR, 0);
WREG32_SOC15(VCN, inst_idx, regUVD_RB_WPTR, 0);
tmp = RREG32_SOC15(VCN, inst_idx, regUVD_RB_RPTR);
WREG32_SOC15(VCN, inst_idx, regUVD_RB_WPTR, tmp);
ring->wptr = RREG32_SOC15(VCN, inst_idx, regUVD_RB_WPTR);
tmp = RREG32_SOC15(VCN, inst_idx, regVCN_RB_ENABLE);
tmp |= VCN_RB_ENABLE__RB1_EN_MASK;
WREG32_SOC15(VCN, inst_idx, regVCN_RB_ENABLE, tmp);
fw_shared->sq.queue_mode &= ~(FW_QUEUE_RING_RESET | FW_QUEUE_DPG_HOLD_OFF);
WREG32_SOC15(VCN, inst_idx, regVCN_RB1_DB_CTRL,
ring->doorbell_index << VCN_RB1_DB_CTRL__OFFSET__SHIFT |
VCN_RB1_DB_CTRL__EN_MASK);
return 0;
}
/**
* vcn_v4_0_start - VCN start
*
* @adev: amdgpu_device pointer
*
* Start VCN block
*/
static int vcn_v4_0_start(struct amdgpu_device *adev)
{
volatile struct amdgpu_vcn4_fw_shared *fw_shared;
struct amdgpu_ring *ring;
uint32_t tmp;
int i, j, k, r;
if (adev->pm.dpm_enabled)
amdgpu_dpm_enable_uvd(adev, true);
for (i = 0; i < adev->vcn.num_vcn_inst; ++i) {
fw_shared = adev->vcn.inst[i].fw_shared.cpu_addr;
if (adev->pg_flags & AMD_PG_SUPPORT_VCN_DPG) {
r = vcn_v4_0_start_dpg_mode(adev, i, adev->vcn.indirect_sram);
continue;
}
/* disable VCN power gating */
vcn_v4_0_disable_static_power_gating(adev, i);
/* set VCN status busy */
tmp = RREG32_SOC15(VCN, i, regUVD_STATUS) | UVD_STATUS__UVD_BUSY;
WREG32_SOC15(VCN, i, regUVD_STATUS, tmp);
/*SW clock gating */
vcn_v4_0_disable_clock_gating(adev, i);
/* enable VCPU clock */
WREG32_P(SOC15_REG_OFFSET(VCN, i, regUVD_VCPU_CNTL),
UVD_VCPU_CNTL__CLK_EN_MASK, ~UVD_VCPU_CNTL__CLK_EN_MASK);
/* disable master interrupt */
WREG32_P(SOC15_REG_OFFSET(VCN, i, regUVD_MASTINT_EN), 0,
~UVD_MASTINT_EN__VCPU_EN_MASK);
/* enable LMI MC and UMC channels */
WREG32_P(SOC15_REG_OFFSET(VCN, i, regUVD_LMI_CTRL2), 0,
~UVD_LMI_CTRL2__STALL_ARB_UMC_MASK);
tmp = RREG32_SOC15(VCN, i, regUVD_SOFT_RESET);
tmp &= ~UVD_SOFT_RESET__LMI_SOFT_RESET_MASK;
tmp &= ~UVD_SOFT_RESET__LMI_UMC_SOFT_RESET_MASK;
WREG32_SOC15(VCN, i, regUVD_SOFT_RESET, tmp);
/* setup regUVD_LMI_CTRL */
tmp = RREG32_SOC15(VCN, i, regUVD_LMI_CTRL);
WREG32_SOC15(VCN, i, regUVD_LMI_CTRL, tmp |
UVD_LMI_CTRL__WRITE_CLEAN_TIMER_EN_MASK |
UVD_LMI_CTRL__MASK_MC_URGENT_MASK |
UVD_LMI_CTRL__DATA_COHERENCY_EN_MASK |
UVD_LMI_CTRL__VCPU_DATA_COHERENCY_EN_MASK);
/* setup regUVD_MPC_CNTL */
tmp = RREG32_SOC15(VCN, i, regUVD_MPC_CNTL);
tmp &= ~UVD_MPC_CNTL__REPLACEMENT_MODE_MASK;
tmp |= 0x2 << UVD_MPC_CNTL__REPLACEMENT_MODE__SHIFT;
WREG32_SOC15(VCN, i, regUVD_MPC_CNTL, tmp);
/* setup UVD_MPC_SET_MUXA0 */
WREG32_SOC15(VCN, i, regUVD_MPC_SET_MUXA0,
((0x1 << UVD_MPC_SET_MUXA0__VARA_1__SHIFT) |
(0x2 << UVD_MPC_SET_MUXA0__VARA_2__SHIFT) |
(0x3 << UVD_MPC_SET_MUXA0__VARA_3__SHIFT) |
(0x4 << UVD_MPC_SET_MUXA0__VARA_4__SHIFT)));
/* setup UVD_MPC_SET_MUXB0 */
WREG32_SOC15(VCN, i, regUVD_MPC_SET_MUXB0,
((0x1 << UVD_MPC_SET_MUXB0__VARB_1__SHIFT) |
(0x2 << UVD_MPC_SET_MUXB0__VARB_2__SHIFT) |
(0x3 << UVD_MPC_SET_MUXB0__VARB_3__SHIFT) |
(0x4 << UVD_MPC_SET_MUXB0__VARB_4__SHIFT)));
/* setup UVD_MPC_SET_MUX */
WREG32_SOC15(VCN, i, regUVD_MPC_SET_MUX,
((0x0 << UVD_MPC_SET_MUX__SET_0__SHIFT) |
(0x1 << UVD_MPC_SET_MUX__SET_1__SHIFT) |
(0x2 << UVD_MPC_SET_MUX__SET_2__SHIFT)));
vcn_v4_0_mc_resume(adev, i);
/* VCN global tiling registers */
WREG32_SOC15(VCN, i, regUVD_GFX10_ADDR_CONFIG,
adev->gfx.config.gb_addr_config);
/* unblock VCPU register access */
WREG32_P(SOC15_REG_OFFSET(VCN, i, regUVD_RB_ARB_CTRL), 0,
~UVD_RB_ARB_CTRL__VCPU_DIS_MASK);
/* release VCPU reset to boot */
WREG32_P(SOC15_REG_OFFSET(VCN, i, regUVD_VCPU_CNTL), 0,
~UVD_VCPU_CNTL__BLK_RST_MASK);
for (j = 0; j < 10; ++j) {
uint32_t status;
for (k = 0; k < 100; ++k) {
status = RREG32_SOC15(VCN, i, regUVD_STATUS);
if (status & 2)
break;
mdelay(10);
if (amdgpu_emu_mode==1)
drm_msleep(1);
}
if (amdgpu_emu_mode==1) {
r = -1;
if (status & 2) {
r = 0;
break;
}
} else {
r = 0;
if (status & 2)
break;
dev_err(adev->dev, "VCN[%d] is not responding, trying to reset the VCPU!!!\n", i);
WREG32_P(SOC15_REG_OFFSET(VCN, i, regUVD_VCPU_CNTL),
UVD_VCPU_CNTL__BLK_RST_MASK,
~UVD_VCPU_CNTL__BLK_RST_MASK);
mdelay(10);
WREG32_P(SOC15_REG_OFFSET(VCN, i, regUVD_VCPU_CNTL), 0,
~UVD_VCPU_CNTL__BLK_RST_MASK);
mdelay(10);
r = -1;
}
}
if (r) {
dev_err(adev->dev, "VCN[%d] is not responding, giving up!!!\n", i);
return r;
}
/* enable master interrupt */
WREG32_P(SOC15_REG_OFFSET(VCN, i, regUVD_MASTINT_EN),
UVD_MASTINT_EN__VCPU_EN_MASK,
~UVD_MASTINT_EN__VCPU_EN_MASK);
/* clear the busy bit of VCN_STATUS */
WREG32_P(SOC15_REG_OFFSET(VCN, i, regUVD_STATUS), 0,
~(2 << UVD_STATUS__VCPU_REPORT__SHIFT));
ring = &adev->vcn.inst[i].ring_enc[0];
WREG32_SOC15(VCN, i, regVCN_RB1_DB_CTRL,
ring->doorbell_index << VCN_RB1_DB_CTRL__OFFSET__SHIFT |
VCN_RB1_DB_CTRL__EN_MASK);
WREG32_SOC15(VCN, i, regUVD_RB_BASE_LO, ring->gpu_addr);
WREG32_SOC15(VCN, i, regUVD_RB_BASE_HI, upper_32_bits(ring->gpu_addr));
WREG32_SOC15(VCN, i, regUVD_RB_SIZE, ring->ring_size / 4);
tmp = RREG32_SOC15(VCN, i, regVCN_RB_ENABLE);
tmp &= ~(VCN_RB_ENABLE__RB1_EN_MASK);
WREG32_SOC15(VCN, i, regVCN_RB_ENABLE, tmp);
fw_shared->sq.queue_mode |= FW_QUEUE_RING_RESET;
WREG32_SOC15(VCN, i, regUVD_RB_RPTR, 0);
WREG32_SOC15(VCN, i, regUVD_RB_WPTR, 0);
tmp = RREG32_SOC15(VCN, i, regUVD_RB_RPTR);
WREG32_SOC15(VCN, i, regUVD_RB_WPTR, tmp);
ring->wptr = RREG32_SOC15(VCN, i, regUVD_RB_WPTR);
tmp = RREG32_SOC15(VCN, i, regVCN_RB_ENABLE);
tmp |= VCN_RB_ENABLE__RB1_EN_MASK;
WREG32_SOC15(VCN, i, regVCN_RB_ENABLE, tmp);
fw_shared->sq.queue_mode &= ~(FW_QUEUE_RING_RESET | FW_QUEUE_DPG_HOLD_OFF);
}
return 0;
}
static int vcn_v4_0_start_sriov(struct amdgpu_device *adev)
{
int i;
struct amdgpu_ring *ring_enc;
uint64_t cache_addr;
uint64_t rb_enc_addr;
uint64_t ctx_addr;
uint32_t param, resp, expected;
uint32_t offset, cache_size;
uint32_t tmp, timeout;
struct amdgpu_mm_table *table = &adev->virt.mm_table;
uint32_t *table_loc;
uint32_t table_size;
uint32_t size, size_dw;
uint32_t init_status;
uint32_t enabled_vcn;
struct mmsch_v4_0_cmd_direct_write
direct_wt = { {0} };
struct mmsch_v4_0_cmd_direct_read_modify_write
direct_rd_mod_wt = { {0} };
struct mmsch_v4_0_cmd_end end = { {0} };
struct mmsch_v4_0_init_header header;
volatile struct amdgpu_vcn4_fw_shared *fw_shared;
volatile struct amdgpu_fw_shared_rb_setup *rb_setup;
direct_wt.cmd_header.command_type =
MMSCH_COMMAND__DIRECT_REG_WRITE;
direct_rd_mod_wt.cmd_header.command_type =
MMSCH_COMMAND__DIRECT_REG_READ_MODIFY_WRITE;
end.cmd_header.command_type =
MMSCH_COMMAND__END;
header.version = MMSCH_VERSION;
header.total_size = sizeof(struct mmsch_v4_0_init_header) >> 2;
for (i = 0; i < AMDGPU_MAX_VCN_INSTANCES; i++) {
header.inst[i].init_status = 0;
header.inst[i].table_offset = 0;
header.inst[i].table_size = 0;
}
table_loc = (uint32_t *)table->cpu_addr;
table_loc += header.total_size;
for (i = 0; i < adev->vcn.num_vcn_inst; i++) {
if (adev->vcn.harvest_config & (1 << i))
continue;
table_size = 0;
MMSCH_V4_0_INSERT_DIRECT_RD_MOD_WT(SOC15_REG_OFFSET(VCN, i,
regUVD_STATUS),
~UVD_STATUS__UVD_BUSY, UVD_STATUS__UVD_BUSY);
cache_size = AMDGPU_GPU_PAGE_ALIGN(adev->vcn.fw->size + 4);
if (adev->firmware.load_type == AMDGPU_FW_LOAD_PSP) {
MMSCH_V4_0_INSERT_DIRECT_WT(SOC15_REG_OFFSET(VCN, i,
regUVD_LMI_VCPU_CACHE_64BIT_BAR_LOW),
adev->firmware.ucode[AMDGPU_UCODE_ID_VCN + i].tmr_mc_addr_lo);
MMSCH_V4_0_INSERT_DIRECT_WT(SOC15_REG_OFFSET(VCN, i,
regUVD_LMI_VCPU_CACHE_64BIT_BAR_HIGH),
adev->firmware.ucode[AMDGPU_UCODE_ID_VCN + i].tmr_mc_addr_hi);
offset = 0;
MMSCH_V4_0_INSERT_DIRECT_WT(SOC15_REG_OFFSET(VCN, i,
regUVD_VCPU_CACHE_OFFSET0),
0);
} else {
MMSCH_V4_0_INSERT_DIRECT_WT(SOC15_REG_OFFSET(VCN, i,
regUVD_LMI_VCPU_CACHE_64BIT_BAR_LOW),
lower_32_bits(adev->vcn.inst[i].gpu_addr));
MMSCH_V4_0_INSERT_DIRECT_WT(SOC15_REG_OFFSET(VCN, i,
regUVD_LMI_VCPU_CACHE_64BIT_BAR_HIGH),
upper_32_bits(adev->vcn.inst[i].gpu_addr));
offset = cache_size;
MMSCH_V4_0_INSERT_DIRECT_WT(SOC15_REG_OFFSET(VCN, i,
regUVD_VCPU_CACHE_OFFSET0),
AMDGPU_UVD_FIRMWARE_OFFSET >> 3);
}
MMSCH_V4_0_INSERT_DIRECT_WT(SOC15_REG_OFFSET(VCN, i,
regUVD_VCPU_CACHE_SIZE0),
cache_size);
cache_addr = adev->vcn.inst[i].gpu_addr + offset;
MMSCH_V4_0_INSERT_DIRECT_WT(SOC15_REG_OFFSET(VCN, i,
regUVD_LMI_VCPU_CACHE1_64BIT_BAR_LOW),
lower_32_bits(cache_addr));
MMSCH_V4_0_INSERT_DIRECT_WT(SOC15_REG_OFFSET(VCN, i,
regUVD_LMI_VCPU_CACHE1_64BIT_BAR_HIGH),
upper_32_bits(cache_addr));
MMSCH_V4_0_INSERT_DIRECT_WT(SOC15_REG_OFFSET(VCN, i,
regUVD_VCPU_CACHE_OFFSET1),
0);
MMSCH_V4_0_INSERT_DIRECT_WT(SOC15_REG_OFFSET(VCN, i,
regUVD_VCPU_CACHE_SIZE1),
AMDGPU_VCN_STACK_SIZE);
cache_addr = adev->vcn.inst[i].gpu_addr + offset +
AMDGPU_VCN_STACK_SIZE;
MMSCH_V4_0_INSERT_DIRECT_WT(SOC15_REG_OFFSET(VCN, i,
regUVD_LMI_VCPU_CACHE2_64BIT_BAR_LOW),
lower_32_bits(cache_addr));
MMSCH_V4_0_INSERT_DIRECT_WT(SOC15_REG_OFFSET(VCN, i,
regUVD_LMI_VCPU_CACHE2_64BIT_BAR_HIGH),
upper_32_bits(cache_addr));
MMSCH_V4_0_INSERT_DIRECT_WT(SOC15_REG_OFFSET(VCN, i,
regUVD_VCPU_CACHE_OFFSET2),
0);
MMSCH_V4_0_INSERT_DIRECT_WT(SOC15_REG_OFFSET(VCN, i,
regUVD_VCPU_CACHE_SIZE2),
AMDGPU_VCN_CONTEXT_SIZE);
fw_shared = adev->vcn.inst[i].fw_shared.cpu_addr;
rb_setup = &fw_shared->rb_setup;
ring_enc = &adev->vcn.inst[i].ring_enc[0];
ring_enc->wptr = 0;
rb_enc_addr = ring_enc->gpu_addr;
rb_setup->is_rb_enabled_flags |= RB_ENABLED;
rb_setup->rb_addr_lo = lower_32_bits(rb_enc_addr);
rb_setup->rb_addr_hi = upper_32_bits(rb_enc_addr);
rb_setup->rb_size = ring_enc->ring_size / 4;
fw_shared->present_flag_0 |= cpu_to_le32(AMDGPU_VCN_VF_RB_SETUP_FLAG);
MMSCH_V4_0_INSERT_DIRECT_WT(SOC15_REG_OFFSET(VCN, i,
regUVD_LMI_VCPU_NC0_64BIT_BAR_LOW),
lower_32_bits(adev->vcn.inst[i].fw_shared.gpu_addr));
MMSCH_V4_0_INSERT_DIRECT_WT(SOC15_REG_OFFSET(VCN, i,
regUVD_LMI_VCPU_NC0_64BIT_BAR_HIGH),
upper_32_bits(adev->vcn.inst[i].fw_shared.gpu_addr));
MMSCH_V4_0_INSERT_DIRECT_WT(SOC15_REG_OFFSET(VCN, i,
regUVD_VCPU_NONCACHE_SIZE0),
AMDGPU_GPU_PAGE_ALIGN(sizeof(struct amdgpu_vcn4_fw_shared)));
/* add end packet */
MMSCH_V4_0_INSERT_END();
/* refine header */
header.inst[i].init_status = 0;
header.inst[i].table_offset = header.total_size;
header.inst[i].table_size = table_size;
header.total_size += table_size;
}
/* Update init table header in memory */
size = sizeof(struct mmsch_v4_0_init_header);
table_loc = (uint32_t *)table->cpu_addr;
memcpy((void *)table_loc, &header, size);
/* message MMSCH (in VCN[0]) to initialize this client
* 1, write to mmsch_vf_ctx_addr_lo/hi register with GPU mc addr
* of memory descriptor location
*/
ctx_addr = table->gpu_addr;
WREG32_SOC15(VCN, 0, regMMSCH_VF_CTX_ADDR_LO, lower_32_bits(ctx_addr));
WREG32_SOC15(VCN, 0, regMMSCH_VF_CTX_ADDR_HI, upper_32_bits(ctx_addr));
/* 2, update vmid of descriptor */
tmp = RREG32_SOC15(VCN, 0, regMMSCH_VF_VMID);
tmp &= ~MMSCH_VF_VMID__VF_CTX_VMID_MASK;
/* use domain0 for MM scheduler */
tmp |= (0 << MMSCH_VF_VMID__VF_CTX_VMID__SHIFT);
WREG32_SOC15(VCN, 0, regMMSCH_VF_VMID, tmp);
/* 3, notify mmsch about the size of this descriptor */
size = header.total_size;
WREG32_SOC15(VCN, 0, regMMSCH_VF_CTX_SIZE, size);
/* 4, set resp to zero */
WREG32_SOC15(VCN, 0, regMMSCH_VF_MAILBOX_RESP, 0);
/* 5, kick off the initialization and wait until
* MMSCH_VF_MAILBOX_RESP becomes non-zero
*/
param = 0x00000001;
WREG32_SOC15(VCN, 0, regMMSCH_VF_MAILBOX_HOST, param);
tmp = 0;
timeout = 1000;
resp = 0;
expected = MMSCH_VF_MAILBOX_RESP__OK;
while (resp != expected) {
resp = RREG32_SOC15(VCN, 0, regMMSCH_VF_MAILBOX_RESP);
if (resp != 0)
break;
udelay(10);
tmp = tmp + 10;
if (tmp >= timeout) {
DRM_ERROR("failed to init MMSCH. TIME-OUT after %d usec"\
" waiting for regMMSCH_VF_MAILBOX_RESP "\
"(expected=0x%08x, readback=0x%08x)\n",
tmp, expected, resp);
return -EBUSY;
}
}
enabled_vcn = amdgpu_vcn_is_disabled_vcn(adev, VCN_DECODE_RING, 0) ? 1 : 0;
init_status = ((struct mmsch_v4_0_init_header *)(table_loc))->inst[enabled_vcn].init_status;
if (resp != expected && resp != MMSCH_VF_MAILBOX_RESP__INCOMPLETE
&& init_status != MMSCH_VF_ENGINE_STATUS__PASS)
DRM_ERROR("MMSCH init status is incorrect! readback=0x%08x, header init "\
"status for VCN%x: 0x%x\n", resp, enabled_vcn, init_status);
return 0;
}
/**
* vcn_v4_0_stop_dpg_mode - VCN stop with dpg mode
*
* @adev: amdgpu_device pointer
* @inst_idx: instance number index
*
* Stop VCN block with dpg mode
*/
static void vcn_v4_0_stop_dpg_mode(struct amdgpu_device *adev, int inst_idx)
{
uint32_t tmp;
/* Wait for power status to be 1 */
SOC15_WAIT_ON_RREG(VCN, inst_idx, regUVD_POWER_STATUS, 1,
UVD_POWER_STATUS__UVD_POWER_STATUS_MASK);
/* wait for read ptr to be equal to write ptr */
tmp = RREG32_SOC15(VCN, inst_idx, regUVD_RB_WPTR);
SOC15_WAIT_ON_RREG(VCN, inst_idx, regUVD_RB_RPTR, tmp, 0xFFFFFFFF);
SOC15_WAIT_ON_RREG(VCN, inst_idx, regUVD_POWER_STATUS, 1,
UVD_POWER_STATUS__UVD_POWER_STATUS_MASK);
/* disable dynamic power gating mode */
WREG32_P(SOC15_REG_OFFSET(VCN, inst_idx, regUVD_POWER_STATUS), 0,
~UVD_POWER_STATUS__UVD_PG_MODE_MASK);
}
/**
* vcn_v4_0_stop - VCN stop
*
* @adev: amdgpu_device pointer
*
* Stop VCN block
*/
static int vcn_v4_0_stop(struct amdgpu_device *adev)
{
volatile struct amdgpu_vcn4_fw_shared *fw_shared;
uint32_t tmp;
int i, r = 0;
for (i = 0; i < adev->vcn.num_vcn_inst; ++i) {
fw_shared = adev->vcn.inst[i].fw_shared.cpu_addr;
fw_shared->sq.queue_mode |= FW_QUEUE_DPG_HOLD_OFF;
if (adev->pg_flags & AMD_PG_SUPPORT_VCN_DPG) {
vcn_v4_0_stop_dpg_mode(adev, i);
continue;
}
/* wait for vcn idle */
r = SOC15_WAIT_ON_RREG(VCN, i, regUVD_STATUS, UVD_STATUS__IDLE, 0x7);
if (r)
return r;
tmp = UVD_LMI_STATUS__VCPU_LMI_WRITE_CLEAN_MASK |
UVD_LMI_STATUS__READ_CLEAN_MASK |
UVD_LMI_STATUS__WRITE_CLEAN_MASK |
UVD_LMI_STATUS__WRITE_CLEAN_RAW_MASK;
r = SOC15_WAIT_ON_RREG(VCN, i, regUVD_LMI_STATUS, tmp, tmp);
if (r)
return r;
/* disable LMI UMC channel */
tmp = RREG32_SOC15(VCN, i, regUVD_LMI_CTRL2);
tmp |= UVD_LMI_CTRL2__STALL_ARB_UMC_MASK;
WREG32_SOC15(VCN, i, regUVD_LMI_CTRL2, tmp);
tmp = UVD_LMI_STATUS__UMC_READ_CLEAN_RAW_MASK |
UVD_LMI_STATUS__UMC_WRITE_CLEAN_RAW_MASK;
r = SOC15_WAIT_ON_RREG(VCN, i, regUVD_LMI_STATUS, tmp, tmp);
if (r)
return r;
/* block VCPU register access */
WREG32_P(SOC15_REG_OFFSET(VCN, i, regUVD_RB_ARB_CTRL),
UVD_RB_ARB_CTRL__VCPU_DIS_MASK,
~UVD_RB_ARB_CTRL__VCPU_DIS_MASK);
/* reset VCPU */
WREG32_P(SOC15_REG_OFFSET(VCN, i, regUVD_VCPU_CNTL),
UVD_VCPU_CNTL__BLK_RST_MASK,
~UVD_VCPU_CNTL__BLK_RST_MASK);
/* disable VCPU clock */
WREG32_P(SOC15_REG_OFFSET(VCN, i, regUVD_VCPU_CNTL), 0,
~(UVD_VCPU_CNTL__CLK_EN_MASK));
/* apply soft reset */
tmp = RREG32_SOC15(VCN, i, regUVD_SOFT_RESET);
tmp |= UVD_SOFT_RESET__LMI_UMC_SOFT_RESET_MASK;
WREG32_SOC15(VCN, i, regUVD_SOFT_RESET, tmp);
tmp = RREG32_SOC15(VCN, i, regUVD_SOFT_RESET);
tmp |= UVD_SOFT_RESET__LMI_SOFT_RESET_MASK;
WREG32_SOC15(VCN, i, regUVD_SOFT_RESET, tmp);
/* clear status */
WREG32_SOC15(VCN, i, regUVD_STATUS, 0);
/* apply HW clock gating */
vcn_v4_0_enable_clock_gating(adev, i);
/* enable VCN power gating */
vcn_v4_0_enable_static_power_gating(adev, i);
}
if (adev->pm.dpm_enabled)
amdgpu_dpm_enable_uvd(adev, false);
return 0;
}
/**
* vcn_v4_0_pause_dpg_mode - VCN pause with dpg mode
*
* @adev: amdgpu_device pointer
* @inst_idx: instance number index
* @new_state: pause state
*
* Pause dpg mode for VCN block
*/
static int vcn_v4_0_pause_dpg_mode(struct amdgpu_device *adev, int inst_idx,
struct dpg_pause_state *new_state)
{
uint32_t reg_data = 0;
int ret_code;
/* pause/unpause if state is changed */
if (adev->vcn.inst[inst_idx].pause_state.fw_based != new_state->fw_based) {
DRM_DEV_DEBUG(adev->dev, "dpg pause state changed %d -> %d",
adev->vcn.inst[inst_idx].pause_state.fw_based, new_state->fw_based);
reg_data = RREG32_SOC15(VCN, inst_idx, regUVD_DPG_PAUSE) &
(~UVD_DPG_PAUSE__NJ_PAUSE_DPG_ACK_MASK);
if (new_state->fw_based == VCN_DPG_STATE__PAUSE) {
ret_code = SOC15_WAIT_ON_RREG(VCN, inst_idx, regUVD_POWER_STATUS, 0x1,
UVD_POWER_STATUS__UVD_POWER_STATUS_MASK);
if (!ret_code) {
/* pause DPG */
reg_data |= UVD_DPG_PAUSE__NJ_PAUSE_DPG_REQ_MASK;
WREG32_SOC15(VCN, inst_idx, regUVD_DPG_PAUSE, reg_data);
/* wait for ACK */
SOC15_WAIT_ON_RREG(VCN, inst_idx, regUVD_DPG_PAUSE,
UVD_DPG_PAUSE__NJ_PAUSE_DPG_ACK_MASK,
UVD_DPG_PAUSE__NJ_PAUSE_DPG_ACK_MASK);
SOC15_WAIT_ON_RREG(VCN, inst_idx, regUVD_POWER_STATUS,
UVD_PGFSM_CONFIG__UVDM_UVDU_PWR_ON, UVD_POWER_STATUS__UVD_POWER_STATUS_MASK);
}
} else {
/* unpause dpg, no need to wait */
reg_data &= ~UVD_DPG_PAUSE__NJ_PAUSE_DPG_REQ_MASK;
WREG32_SOC15(VCN, inst_idx, regUVD_DPG_PAUSE, reg_data);
}
adev->vcn.inst[inst_idx].pause_state.fw_based = new_state->fw_based;
}
return 0;
}
/**
* vcn_v4_0_unified_ring_get_rptr - get unified read pointer
*
* @ring: amdgpu_ring pointer
*
* Returns the current hardware unified read pointer
*/
static uint64_t vcn_v4_0_unified_ring_get_rptr(struct amdgpu_ring *ring)
{
struct amdgpu_device *adev = ring->adev;
if (ring != &adev->vcn.inst[ring->me].ring_enc[0])
DRM_ERROR("wrong ring id is identified in %s", __func__);
return RREG32_SOC15(VCN, ring->me, regUVD_RB_RPTR);
}
/**
* vcn_v4_0_unified_ring_get_wptr - get unified write pointer
*
* @ring: amdgpu_ring pointer
*
* Returns the current hardware unified write pointer
*/
static uint64_t vcn_v4_0_unified_ring_get_wptr(struct amdgpu_ring *ring)
{
struct amdgpu_device *adev = ring->adev;
if (ring != &adev->vcn.inst[ring->me].ring_enc[0])
DRM_ERROR("wrong ring id is identified in %s", __func__);
if (ring->use_doorbell)
return *ring->wptr_cpu_addr;
else
return RREG32_SOC15(VCN, ring->me, regUVD_RB_WPTR);
}
/**
* vcn_v4_0_unified_ring_set_wptr - set enc write pointer
*
* @ring: amdgpu_ring pointer
*
* Commits the enc write pointer to the hardware
*/
static void vcn_v4_0_unified_ring_set_wptr(struct amdgpu_ring *ring)
{
struct amdgpu_device *adev = ring->adev;
if (ring != &adev->vcn.inst[ring->me].ring_enc[0])
DRM_ERROR("wrong ring id is identified in %s", __func__);
if (ring->use_doorbell) {
*ring->wptr_cpu_addr = lower_32_bits(ring->wptr);
WDOORBELL32(ring->doorbell_index, lower_32_bits(ring->wptr));
} else {
WREG32_SOC15(VCN, ring->me, regUVD_RB_WPTR, lower_32_bits(ring->wptr));
}
}
static int vcn_v4_0_limit_sched(struct amdgpu_cs_parser *p,
struct amdgpu_job *job)
{
struct drm_gpu_scheduler **scheds;
/* The create msg must be in the first IB submitted */
if (atomic_read(&job->base.entity->fence_seq))
return -EINVAL;
scheds = p->adev->gpu_sched[AMDGPU_HW_IP_VCN_ENC]
[AMDGPU_RING_PRIO_0].sched;
drm_sched_entity_modify_sched(job->base.entity, scheds, 1);
return 0;
}
static int vcn_v4_0_dec_msg(struct amdgpu_cs_parser *p, struct amdgpu_job *job,
uint64_t addr)
{
struct ttm_operation_ctx ctx = { false, false };
struct amdgpu_bo_va_mapping *map;
uint32_t *msg, num_buffers;
struct amdgpu_bo *bo;
uint64_t start, end;
unsigned int i;
void *ptr;
int r;
addr &= AMDGPU_GMC_HOLE_MASK;
r = amdgpu_cs_find_mapping(p, addr, &bo, &map);
if (r) {
DRM_ERROR("Can't find BO for addr 0x%08llx\n", addr);
return r;
}
start = map->start * AMDGPU_GPU_PAGE_SIZE;
end = (map->last + 1) * AMDGPU_GPU_PAGE_SIZE;
if (addr & 0x7) {
DRM_ERROR("VCN messages must be 8 byte aligned!\n");
return -EINVAL;
}
bo->flags |= AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED;
amdgpu_bo_placement_from_domain(bo, bo->allowed_domains);
r = ttm_bo_validate(&bo->tbo, &bo->placement, &ctx);
if (r) {
DRM_ERROR("Failed validating the VCN message BO (%d)!\n", r);
return r;
}
r = amdgpu_bo_kmap(bo, &ptr);
if (r) {
DRM_ERROR("Failed mapping the VCN message (%d)!\n", r);
return r;
}
msg = ptr + addr - start;
/* Check length */
if (msg[1] > end - addr) {
r = -EINVAL;
goto out;
}
if (msg[3] != RDECODE_MSG_CREATE)
goto out;
num_buffers = msg[2];
for (i = 0, msg = &msg[6]; i < num_buffers; ++i, msg += 4) {
uint32_t offset, size, *create;
if (msg[0] != RDECODE_MESSAGE_CREATE)
continue;
offset = msg[1];
size = msg[2];
if (offset + size > end) {
r = -EINVAL;
goto out;
}
create = ptr + addr + offset - start;
/* H246, HEVC and VP9 can run on any instance */
if (create[0] == 0x7 || create[0] == 0x10 || create[0] == 0x11)
continue;
r = vcn_v4_0_limit_sched(p, job);
if (r)
goto out;
}
out:
amdgpu_bo_kunmap(bo);
return r;
}
#define RADEON_VCN_ENGINE_TYPE_DECODE (0x00000003)
static int vcn_v4_0_ring_patch_cs_in_place(struct amdgpu_cs_parser *p,
struct amdgpu_job *job,
struct amdgpu_ib *ib)
{
struct amdgpu_ring *ring = amdgpu_job_ring(job);
struct amdgpu_vcn_decode_buffer *decode_buffer;
uint64_t addr;
uint32_t val;
/* The first instance can decode anything */
if (!ring->me)
return 0;
/* unified queue ib header has 8 double words. */
if (ib->length_dw < 8)
return 0;
val = amdgpu_ib_get_value(ib, 6); //RADEON_VCN_ENGINE_TYPE
if (val != RADEON_VCN_ENGINE_TYPE_DECODE)
return 0;
decode_buffer = (struct amdgpu_vcn_decode_buffer *)&ib->ptr[10];
if (!(decode_buffer->valid_buf_flag & 0x1))
return 0;
addr = ((u64)decode_buffer->msg_buffer_address_hi) << 32 |
decode_buffer->msg_buffer_address_lo;
return vcn_v4_0_dec_msg(p, job, addr);
}
static const struct amdgpu_ring_funcs vcn_v4_0_unified_ring_vm_funcs = {
.type = AMDGPU_RING_TYPE_VCN_ENC,
.align_mask = 0x3f,
.nop = VCN_ENC_CMD_NO_OP,
.vmhub = AMDGPU_MMHUB_0,
.get_rptr = vcn_v4_0_unified_ring_get_rptr,
.get_wptr = vcn_v4_0_unified_ring_get_wptr,
.set_wptr = vcn_v4_0_unified_ring_set_wptr,
.patch_cs_in_place = vcn_v4_0_ring_patch_cs_in_place,
.emit_frame_size =
SOC15_FLUSH_GPU_TLB_NUM_WREG * 3 +
SOC15_FLUSH_GPU_TLB_NUM_REG_WAIT * 4 +
4 + /* vcn_v2_0_enc_ring_emit_vm_flush */
5 + 5 + /* vcn_v2_0_enc_ring_emit_fence x2 vm fence */
1, /* vcn_v2_0_enc_ring_insert_end */
.emit_ib_size = 5, /* vcn_v2_0_enc_ring_emit_ib */
.emit_ib = vcn_v2_0_enc_ring_emit_ib,
.emit_fence = vcn_v2_0_enc_ring_emit_fence,
.emit_vm_flush = vcn_v2_0_enc_ring_emit_vm_flush,
.test_ring = amdgpu_vcn_enc_ring_test_ring,
.test_ib = amdgpu_vcn_unified_ring_test_ib,
.insert_nop = amdgpu_ring_insert_nop,
.insert_end = vcn_v2_0_enc_ring_insert_end,
.pad_ib = amdgpu_ring_generic_pad_ib,
.begin_use = amdgpu_vcn_ring_begin_use,
.end_use = amdgpu_vcn_ring_end_use,
.emit_wreg = vcn_v2_0_enc_ring_emit_wreg,
.emit_reg_wait = vcn_v2_0_enc_ring_emit_reg_wait,
.emit_reg_write_reg_wait = amdgpu_ring_emit_reg_write_reg_wait_helper,
};
/**
* vcn_v4_0_set_unified_ring_funcs - set unified ring functions
*
* @adev: amdgpu_device pointer
*
* Set unified ring functions
*/
static void vcn_v4_0_set_unified_ring_funcs(struct amdgpu_device *adev)
{
int i;
for (i = 0; i < adev->vcn.num_vcn_inst; ++i) {
if (adev->vcn.harvest_config & (1 << i))
continue;
adev->vcn.inst[i].ring_enc[0].funcs = &vcn_v4_0_unified_ring_vm_funcs;
adev->vcn.inst[i].ring_enc[0].me = i;
DRM_INFO("VCN(%d) encode/decode are enabled in VM mode\n", i);
}
}
/**
* vcn_v4_0_is_idle - check VCN block is idle
*
* @handle: amdgpu_device pointer
*
* Check whether VCN block is idle
*/
static bool vcn_v4_0_is_idle(void *handle)
{
struct amdgpu_device *adev = (struct amdgpu_device *)handle;
int i, ret = 1;
for (i = 0; i < adev->vcn.num_vcn_inst; ++i) {
if (adev->vcn.harvest_config & (1 << i))
continue;
ret &= (RREG32_SOC15(VCN, i, regUVD_STATUS) == UVD_STATUS__IDLE);
}
return ret;
}
/**
* vcn_v4_0_wait_for_idle - wait for VCN block idle
*
* @handle: amdgpu_device pointer
*
* Wait for VCN block idle
*/
static int vcn_v4_0_wait_for_idle(void *handle)
{
struct amdgpu_device *adev = (struct amdgpu_device *)handle;
int i, ret = 0;
for (i = 0; i < adev->vcn.num_vcn_inst; ++i) {
if (adev->vcn.harvest_config & (1 << i))
continue;
ret = SOC15_WAIT_ON_RREG(VCN, i, regUVD_STATUS, UVD_STATUS__IDLE,
UVD_STATUS__IDLE);
if (ret)
return ret;
}
return ret;
}
/**
* vcn_v4_0_set_clockgating_state - set VCN block clockgating state
*
* @handle: amdgpu_device pointer
* @state: clock gating state
*
* Set VCN block clockgating state
*/
static int vcn_v4_0_set_clockgating_state(void *handle, enum amd_clockgating_state state)
{
struct amdgpu_device *adev = (struct amdgpu_device *)handle;
bool enable = (state == AMD_CG_STATE_GATE) ? true : false;
int i;
for (i = 0; i < adev->vcn.num_vcn_inst; ++i) {
if (adev->vcn.harvest_config & (1 << i))
continue;
if (enable) {
if (RREG32_SOC15(VCN, i, regUVD_STATUS) != UVD_STATUS__IDLE)
return -EBUSY;
vcn_v4_0_enable_clock_gating(adev, i);
} else {
vcn_v4_0_disable_clock_gating(adev, i);
}
}
return 0;
}
/**
* vcn_v4_0_set_powergating_state - set VCN block powergating state
*
* @handle: amdgpu_device pointer
* @state: power gating state
*
* Set VCN block powergating state
*/
static int vcn_v4_0_set_powergating_state(void *handle, enum amd_powergating_state state)
{
struct amdgpu_device *adev = (struct amdgpu_device *)handle;
int ret;
/* for SRIOV, guest should not control VCN Power-gating
* MMSCH FW should control Power-gating and clock-gating
* guest should avoid touching CGC and PG
*/
if (amdgpu_sriov_vf(adev)) {
adev->vcn.cur_state = AMD_PG_STATE_UNGATE;
return 0;
}
if(state == adev->vcn.cur_state)
return 0;
if (state == AMD_PG_STATE_GATE)
ret = vcn_v4_0_stop(adev);
else
ret = vcn_v4_0_start(adev);
if(!ret)
adev->vcn.cur_state = state;
return ret;
}
/**
* vcn_v4_0_set_interrupt_state - set VCN block interrupt state
*
* @adev: amdgpu_device pointer
* @source: interrupt sources
* @type: interrupt types
* @state: interrupt states
*
* Set VCN block interrupt state
*/
static int vcn_v4_0_set_interrupt_state(struct amdgpu_device *adev, struct amdgpu_irq_src *source,
unsigned type, enum amdgpu_interrupt_state state)
{
return 0;
}
/**
* vcn_v4_0_process_interrupt - process VCN block interrupt
*
* @adev: amdgpu_device pointer
* @source: interrupt sources
* @entry: interrupt entry from clients and sources
*
* Process VCN block interrupt
*/
static int vcn_v4_0_process_interrupt(struct amdgpu_device *adev, struct amdgpu_irq_src *source,
struct amdgpu_iv_entry *entry)
{
uint32_t ip_instance;
switch (entry->client_id) {
case SOC15_IH_CLIENTID_VCN:
ip_instance = 0;
break;
case SOC15_IH_CLIENTID_VCN1:
ip_instance = 1;
break;
default:
DRM_ERROR("Unhandled client id: %d\n", entry->client_id);
return 0;
}
DRM_DEBUG("IH: VCN TRAP\n");
switch (entry->src_id) {
case VCN_4_0__SRCID__UVD_ENC_GENERAL_PURPOSE:
amdgpu_fence_process(&adev->vcn.inst[ip_instance].ring_enc[0]);
break;
default:
DRM_ERROR("Unhandled interrupt: %d %d\n",
entry->src_id, entry->src_data[0]);
break;
}
return 0;
}
static const struct amdgpu_irq_src_funcs vcn_v4_0_irq_funcs = {
.set = vcn_v4_0_set_interrupt_state,
.process = vcn_v4_0_process_interrupt,
};
/**
* vcn_v4_0_set_irq_funcs - set VCN block interrupt irq functions
*
* @adev: amdgpu_device pointer
*
* Set VCN block interrupt irq functions
*/
static void vcn_v4_0_set_irq_funcs(struct amdgpu_device *adev)
{
int i;
for (i = 0; i < adev->vcn.num_vcn_inst; ++i) {
if (adev->vcn.harvest_config & (1 << i))
continue;
adev->vcn.inst[i].irq.num_types = adev->vcn.num_enc_rings + 1;
adev->vcn.inst[i].irq.funcs = &vcn_v4_0_irq_funcs;
}
}
static const struct amd_ip_funcs vcn_v4_0_ip_funcs = {
.name = "vcn_v4_0",
.early_init = vcn_v4_0_early_init,
.late_init = NULL,
.sw_init = vcn_v4_0_sw_init,
.sw_fini = vcn_v4_0_sw_fini,
.hw_init = vcn_v4_0_hw_init,
.hw_fini = vcn_v4_0_hw_fini,
.suspend = vcn_v4_0_suspend,
.resume = vcn_v4_0_resume,
.is_idle = vcn_v4_0_is_idle,
.wait_for_idle = vcn_v4_0_wait_for_idle,
.check_soft_reset = NULL,
.pre_soft_reset = NULL,
.soft_reset = NULL,
.post_soft_reset = NULL,
.set_clockgating_state = vcn_v4_0_set_clockgating_state,
.set_powergating_state = vcn_v4_0_set_powergating_state,
};
const struct amdgpu_ip_block_version vcn_v4_0_ip_block =
{
.type = AMD_IP_BLOCK_TYPE_VCN,
.major = 4,
.minor = 0,
.rev = 0,
.funcs = &vcn_v4_0_ip_funcs,
};
|
ac58648ba09c570131e8b8329420e7f3cec52cfd
|
af8f0aa9dc8cfc33e686d7f2545639eaf286219b
|
/lbdex/input/config.h
|
a0f3efb431a7cef9ca59d19021bad31b767a2202
|
[] |
no_license
|
Jonathan2251/lbd
|
abb6bfa78cabede1c9401e5bfd4f8f52a0644e0f
|
a62a7cbb11571efec52ba18e920d530dd8b7f453
|
refs/heads/master
| 2023-08-31T13:20:56.051526
| 2023-08-26T22:53:11
| 2023-08-26T22:53:11
| 43,113,474
| 280
| 67
| null | 2022-07-26T23:26:01
| 2015-09-25T06:27:04
|
C++
|
UTF-8
|
C
| false
| false
| 475
|
h
|
config.h
|
#ifndef _CONFIG_H_
#define _CONFIG_H_
// defined in cpu0.v
#define IOADDR 0xff000000
// $sp begin at mem less than MEMSIZE of cpu0.v
#define INIT_SP \
asm("addiu $sp, $zero, 0x0000"); \
asm("lui $sp, 0xff");
// default test part of 1 in 10 for udivmoddi4_test.c
//#define TEST_FULL
//#define TEST_HALF
// TEST_FULL in udivmoddi4_test.c
#ifdef TEST_FULL
#define PART_2_IN_10
#define PART_HALF
#else
#ifdef TEST_HALF
#define PART_HALF
#endif
#endif
#endif
|
01a892c0888568c9dda2a638c6d1105c0fcec446
|
7aeaa1edebceae34cf66713981229b1441e03635
|
/src/rbnf/io.h
|
028b79e746f00d7bcf7b840f6c7df62e5530fb9e
|
[
"BSD-2-Clause"
] |
permissive
|
katef/kgt
|
a57dbe55b88a035ba45db621cbaf14d840cbf684
|
dc881796aa691f1fddb1d01ec77216b34fe8134d
|
refs/heads/main
| 2023-08-16T03:21:44.094138
| 2023-06-01T07:27:12
| 2023-06-03T16:30:09
| 80,591,696
| 539
| 30
|
BSD-2-Clause
| 2023-06-03T16:30:12
| 2017-02-01T05:13:03
|
C
|
UTF-8
|
C
| false
| false
| 498
|
h
|
io.h
|
/*
* Copyright 2014-2017 Katherine Flavel
*
* See LICENCE for the full copyright terms.
*/
#ifndef KGT_RBNF_IO_H
#define KGT_RBNF_IO_H
#include "../compiler_specific.h"
#include "../parsing_error.h"
struct ast_rule;
#define rbnf_ast_unsupported (FEATURE_AST_CI_LITERAL | FEATURE_AST_BINARY | FEATURE_AST_INVISIBLE)
struct ast_rule *
rbnf_input(int (*f)(void *opaque), void *opaque, parsing_error_queue* errors);
WARN_UNUSED_RESULT
int
rbnf_output(const struct ast_rule *grammar);
#endif
|
b72347b61e327adb49c13f57da42a00b1d01110d
|
5f86fc385c7dcfcb5b166cdea7c8b13057b8bb5f
|
/include/openenclave/internal/sgxkeys.h
|
10cdc1abba833f2ab89608274002cc8ee27a4ec5
|
[
"MIT"
] |
permissive
|
openenclave/openenclave
|
54a38e12d9aa73357d9f438a07cd8c07ffe5e6df
|
cdeb95c1ec163117de409295333b6b2702013e08
|
refs/heads/master
| 2023-08-14T16:43:32.049533
| 2023-07-21T15:58:54
| 2023-07-21T15:58:54
| 101,804,230
| 800
| 372
|
MIT
| 2023-09-12T20:26:02
| 2017-08-29T20:31:38
|
C
|
UTF-8
|
C
| false
| false
| 1,463
|
h
|
sgxkeys.h
|
// Copyright (c) Open Enclave SDK contributors.
// Licensed under the MIT License.
#ifndef _OE_KEYS_H
#define _OE_KEYS_H
#include <openenclave/bits/defs.h>
#include <openenclave/bits/result.h>
#include <openenclave/bits/sgx/sgxtypes.h>
#include <openenclave/bits/types.h>
OE_EXTERNC_BEGIN
/**
* Get a secret SGX key.
*
* Call this function to get a secret SGX key from processor.
*
* @param sgx_key_request The parameter points to the KEYREQUEST structure that
* describes which key and how it should be derived. This parameter must point
* to a readable memory block inside enclave.
* @param sgx_key The parameter points to sgx_key_t structure where the key will
* be
* returned. This parameter must point to a writable memory block inside
* enclave. It will not be changed if this function fails.
*
* @retval OE_OK Request succeeded and the key is written to **sgx_key**.
* **sgx_key** is not modified if the return value is not OE_OK.
* @retval OE_INVALID_CPUSVN **sgx_key_request** contains an invalid CPUSVN.
* @retval OE_INVALID_ISVSVN **sgx_key_request** contains an invalid ISVSVN.
* @retval OE_INVALID_KEYNAME **sgx_key_request** contains an invalid KEYNAME.
* @retval OE_INVALID_PARAMETER Any other invalid parameter was specified.
* @retval OE_UNEXPECTED An unexpected error occurred.
*
*/
oe_result_t oe_get_key(
const sgx_key_request_t* sgx_key_request,
sgx_key_t* sgx_key);
OE_EXTERNC_END
#endif /* _OE_KEYS_H */
|
d2ab14fb92318cb0b0f6788717176dd29919901d
|
e73547787354afd9b717ea57fe8dd0695d161821
|
/src/world/area_obk/obk_08/obk_08_3_cabinets.c
|
8fc01296e2672f31dd25f9f85007b389c102a261
|
[] |
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
| 11,934
|
c
|
obk_08_3_cabinets.c
|
#include "obk_08.h"
#include "effects.h"
#include "sprite/player.h"
#include "sprite/npc/WorldGoombario.h"
#include "sprite/npc/WorldKooper.h"
#include "sprite/npc/WorldBombette.h"
#include "sprite/npc/WorldParakarry.h"
#include "sprite/npc/WorldBow.h"
#include "sprite/npc/WorldWatt.h"
#include "sprite/npc/WorldSushie.h"
#include "sprite/npc/WorldLakilester.h"
#define KNOCK_DOWN_MAP_VAR MV_Knockdown
#include "world/common/complete/KnockDownPlayer.inc.c"
API_CALLABLE(N(DamagePlayer1HP)) {
if (gPlayerData.curHP <= 1) {
return ApiStatus_DONE2;
}
gPlayerData.curHP--;
return ApiStatus_DONE2;
}
EvtScript N(EVS_GetPartnerInUseAnims) = {
EVT_CALL(GetCurrentPartnerID, LVar0)
EVT_SWITCH(LVar0)
EVT_CASE_EQ(PARTNER_GOOMBARIO)
EVT_SET(LVarA, ANIM_WorldGoombario_Run)
EVT_SET(LVarB, ANIM_WorldGoombario_Idle)
EVT_CASE_EQ(PARTNER_KOOPER)
EVT_SET(LVarA, ANIM_WorldKooper_Run)
EVT_SET(LVarB, ANIM_WorldKooper_Idle)
EVT_CASE_EQ(PARTNER_BOMBETTE)
EVT_SET(LVarA, ANIM_WorldBombette_Run)
EVT_SET(LVarB, ANIM_WorldBombette_Idle)
EVT_CASE_EQ(PARTNER_PARAKARRY)
EVT_SET(LVarA, ANIM_WorldParakarry_Run)
EVT_SET(LVarB, ANIM_WorldParakarry_Idle)
EVT_CASE_EQ(PARTNER_BOW)
EVT_SET(LVarA, ANIM_WorldBow_Run)
EVT_SET(LVarB, ANIM_WorldBow_Idle)
EVT_CASE_EQ(PARTNER_WATT)
EVT_SET(LVarA, ANIM_WorldWatt_Run)
EVT_SET(LVarB, ANIM_WorldWatt_Idle)
EVT_CASE_EQ(PARTNER_SUSHIE)
EVT_SET(LVarA, ANIM_WorldSushie_Run)
EVT_SET(LVarB, ANIM_WorldSushie_Idle)
EVT_CASE_EQ(PARTNER_LAKILESTER)
EVT_SET(LVarA, ANIM_WorldLakilester_Run)
EVT_SET(LVarB, ANIM_WorldLakilester_Idle)
EVT_END_SWITCH
EVT_RETURN
EVT_END
};
EvtScript N(EVS_CrushPlayer) = {
EVT_THREAD
EVT_CALL(DisablePartnerAI, 0)
EVT_CALL(SetNpcFlagBits, NPC_PARTNER, NPC_FLAG_IGNORE_PLAYER_COLLISION, TRUE)
EVT_CALL(GetNpcPos, NPC_PARTNER, LVar0, LVar1, LVar2)
EVT_EXEC_WAIT(N(EVS_GetPartnerInUseAnims))
EVT_CALL(SetNpcAnimation, NPC_PARTNER, LVarA)
EVT_CALL(NpcMoveTo, NPC_PARTNER, -93, LVar2, 15)
EVT_EXEC_WAIT(N(EVS_GetPartnerInUseAnims))
EVT_CALL(SetNpcAnimation, NPC_PARTNER, LVarB)
EVT_WAIT(15)
EVT_CALL(SetNpcFlagBits, NPC_PARTNER, NPC_FLAG_IGNORE_PLAYER_COLLISION, FALSE)
EVT_CALL(InterpNpcYaw, NPC_PARTNER, 270, 0)
EVT_END_THREAD
EVT_CALL(DisablePlayerPhysics, TRUE)
EVT_WAIT(8)
EVT_CALL(SetPlayerAnimation, ANIM_Mario1_Flail)
EVT_WAIT(13)
EVT_CALL(GetPlayerPos, MV_KnockdownPosX, MV_KnockdownPosY, MV_KnockdownPosZ)
EVT_CALL(N(KnockdownCreate), SPR_Mario1, 37) //TODO hardcoded player raster ID
EVT_CALL(N(KnockdownSetPos), MV_KnockdownPosX, MV_KnockdownPosY, MV_KnockdownPosZ)
EVT_WAIT(1)
EVT_CALL(SetPlayerPos, 0, 1000, 0) // unusual dispose location
EVT_CALL(MakeLerp, 0, 90, 10, EASING_QUADRATIC_IN)
EVT_LABEL(0)
EVT_CALL(UpdateLerp)
EVT_CALL(N(KnockdownSetRot), LVar0, 0, 0)
EVT_WAIT(1)
EVT_IF_EQ(LVar1, 1)
EVT_GOTO(0)
EVT_END_IF
EVT_ADD(MV_KnockdownPosY, 3)
EVT_CALL(N(KnockdownSetPos), MV_KnockdownPosX, MV_KnockdownPosY, MV_KnockdownPosZ)
EVT_CALL(N(DamagePlayer1HP))
EVT_RETURN
EVT_END
};
EvtScript N(EVS_RestorePlayer) = {
EVT_CALL(SetPlayerAnimation, ANIM_Mario1_Idle)
EVT_CALL(InterpPlayerYaw, 270, 0)
EVT_WAIT(15)
EVT_SUB(MV_KnockdownPosY, 3)
EVT_CALL(N(KnockdownSetPos), MV_KnockdownPosX, MV_KnockdownPosY, MV_KnockdownPosZ)
EVT_CALL(MakeLerp, 90, 0, 15, EASING_QUADRATIC_OUT)
EVT_LABEL(1)
EVT_CALL(UpdateLerp)
EVT_CALL(N(KnockdownSetRot), LVar0, 0, 0)
EVT_WAIT(1)
EVT_IF_EQ(LVar1, 1)
EVT_GOTO(1)
EVT_END_IF
EVT_CALL(N(KnockdownDestroy))
EVT_CALL(SetPlayerPos, MV_KnockdownPosX, MV_KnockdownPosY, MV_KnockdownPosZ)
EVT_WAIT(10)
EVT_CALL(SetPlayerAnimation, ANIM_MarioW3_ShakeHeadHard)
EVT_WAIT(25)
EVT_CALL(SetPlayerAnimation, ANIM_Mario1_Idle)
EVT_CALL(EnablePartnerAI)
EVT_CALL(DisablePlayerPhysics, FALSE)
EVT_RETURN
EVT_END
};
Vec2i N(DustEmitters_FarCabinet)[] = {
{ -220, -140 },
{ -220, -115 },
{ -220, -90 },
{ -220, -65 },
{ -220, -40 },
{ -195, -40 },
{ -170, -40 },
{ -145, -40 },
{ -120, -140 },
{ -120, -115 },
{ -120, -90 },
{ -120, -65 },
{ -120, -40 },
{ -145, -40 },
{ -170, -40 },
{ -195, -40 },
};
Vec2i N(DustEmitters_NearCabinet)[] = {
{ -220, 60 },
{ -220, 85 },
{ -220, 110 },
{ -220, 135 },
{ -220, 160 },
{ -195, 160 },
{ -170, 160 },
{ -145, 160 },
{ -120, 60 },
{ -120, 85 },
{ -120, 110 },
{ -120, 135 },
{ -120, 160 },
{ -145, 160 },
{ -170, 160 },
{ -195, 160 },
};
EvtScript N(EVS_MiddleCabinet_OpenDoors) = {
EVT_CALL(PlaySoundAtCollider, COLLIDER_tansu2, SOUND_OBK_CHECK_CABINET, SOUND_SPACE_DEFAULT)
EVT_CALL(MakeLerp, 0, 120, 15, EASING_QUARTIC_IN)
EVT_LOOP(0)
EVT_CALL(UpdateLerp)
EVT_CALL(RotateModel, MODEL_t_1, LVar0, 0, -1, 0)
EVT_CALL(RotateModel, MODEL_t_2, LVar0, 0, 1, 0)
EVT_WAIT(1)
EVT_IF_EQ(LVar1, 0)
EVT_BREAK_LOOP
EVT_END_IF
EVT_END_LOOP
EVT_RETURN
EVT_END
};
EvtScript N(EVS_MiddleCabinet_CloseDoors) = {
EVT_CALL(MakeLerp, 120, 0, 15, EASING_QUARTIC_IN)
EVT_LOOP(0)
EVT_CALL(UpdateLerp)
EVT_CALL(RotateModel, MODEL_t_1, LVar0, 0, -1, 0)
EVT_CALL(RotateModel, MODEL_t_2, LVar0, 0, 1, 0)
EVT_WAIT(1)
EVT_IF_EQ(LVar1, 0)
EVT_BREAK_LOOP
EVT_END_IF
EVT_END_LOOP
EVT_CALL(PlaySoundAtCollider, COLLIDER_tansu2, SOUND_OBK_CHECK_CABINET, SOUND_SPACE_DEFAULT)
EVT_RETURN
EVT_END
};
EvtScript N(EVS_Interact_MiddleCabinet) = {
EVT_IF_LT(GB_StoryProgress, STORY_CH3_GOT_RECORD)
EVT_CALL(DeleteTrigger, MV_Trigger_NearCabinet)
EVT_CALL(DeleteTrigger, MV_Trigger_MidCabinet)
EVT_CALL(DeleteTrigger, MV_Trigger_FarCabinet)
EVT_EXEC(N(EVS_Scene_BoosUnleashed))
EVT_EXEC_WAIT(N(EVS_MiddleCabinet_OpenDoors))
EVT_SET(AF_OBK08_KeepAwayStarted, TRUE)
EVT_WAIT(50)
EVT_EXEC_WAIT(N(EVS_MiddleCabinet_CloseDoors))
EVT_ELSE
EVT_CALL(DisablePlayerInput, TRUE)
EVT_CALL(InterruptUsePartner)
EVT_EXEC_WAIT(N(EVS_MiddleCabinet_OpenDoors))
EVT_WAIT(20)
EVT_EXEC_WAIT(N(EVS_MiddleCabinet_CloseDoors))
EVT_CALL(DisablePlayerInput, FALSE)
EVT_END_IF
EVT_RETURN
EVT_END
};
EvtScript N(EVS_Interact_NearCabinet) = {
EVT_LABEL(3)
EVT_CALL(DisablePlayerInput, TRUE)
EVT_CALL(InterruptUsePartner)
EVT_LOOP(3)
EVT_CALL(PlaySoundAtCollider, COLLIDER_tansu1, SOUND_OBK_CHECK_CABINET, SOUND_SPACE_DEFAULT)
EVT_CALL(RotateModel, MODEL_tansu1, -1, 1, 0, 0)
EVT_WAIT(2)
EVT_CALL(RotateModel, MODEL_tansu1, 0, 1, 0, 0)
EVT_WAIT(1)
EVT_CALL(PlaySoundAtCollider, COLLIDER_tansu1, SOUND_OBK_CHECK_CABINET, SOUND_SPACE_DEFAULT)
EVT_CALL(TranslateModel, MODEL_tansu1, 0, 0, 100)
EVT_CALL(RotateModel, MODEL_tansu1, 1, 1, 0, 0)
EVT_CALL(TranslateModel, MODEL_tansu1, 0, 0, -100)
EVT_WAIT(2)
EVT_CALL(RotateModel, MODEL_tansu1, 0, 1, 0, 0)
EVT_WAIT(1)
EVT_END_LOOP
EVT_EXEC(N(EVS_CrushPlayer))
EVT_CALL(MakeLerp, 0, -90, 30, EASING_QUARTIC_IN)
EVT_LABEL(10)
EVT_CALL(UpdateLerp)
EVT_CALL(RotateModel, MODEL_tansu1, LVar0, 0, 0, 1)
EVT_CALL(UpdateColliderTransform, COLLIDER_tansu1)
EVT_CALL(UpdateColliderTransform, COLLIDER_o372)
EVT_WAIT(1)
EVT_IF_EQ(LVar1, 1)
EVT_GOTO(10)
EVT_END_IF
EVT_CALL(PlaySoundAtCollider, COLLIDER_tansu1, SOUND_OBK_CABINET_CRASH, SOUND_SPACE_DEFAULT)
EVT_THREAD
EVT_CALL(ShakeCam, CAM_DEFAULT, 0, 30, EVT_FLOAT(1.5))
EVT_END_THREAD
EVT_USE_BUF(EVT_PTR(N(DustEmitters_NearCabinet)))
EVT_LOOP(16)
EVT_BUF_READ2(LVar0, LVar1)
EVT_PLAY_EFFECT(EFFECT_LANDING_DUST, 2, LVar0, 0, LVar1, 0)
EVT_END_LOOP
EVT_WAIT(60)
EVT_CALL(MakeLerp, -90, 0, 10, EASING_LINEAR)
EVT_LABEL(15)
EVT_CALL(UpdateLerp)
EVT_CALL(RotateModel, MODEL_tansu1, LVar0, 0, 0, 1)
EVT_CALL(UpdateColliderTransform, COLLIDER_tansu1)
EVT_CALL(UpdateColliderTransform, COLLIDER_o372)
EVT_WAIT(1)
EVT_IF_EQ(LVar1, 1)
EVT_GOTO(15)
EVT_END_IF
EVT_EXEC_WAIT(N(EVS_RestorePlayer))
EVT_CALL(DisablePlayerInput, FALSE)
EVT_RETURN
EVT_END
};
EvtScript N(EVS_Interact_FarCabinet) = {
EVT_LABEL(5)
EVT_CALL(DisablePlayerInput, TRUE)
EVT_CALL(InterruptUsePartner)
EVT_LOOP(5)
EVT_CALL(PlaySoundAtCollider, COLLIDER_tansu3, SOUND_OBK_CHECK_CABINET, SOUND_SPACE_DEFAULT)
EVT_CALL(RotateModel, MODEL_tansu3, -1, 1, 0, 0)
EVT_WAIT(2)
EVT_CALL(RotateModel, MODEL_tansu3, 0, 1, 0, 0)
EVT_WAIT(1)
EVT_CALL(PlaySoundAtCollider, COLLIDER_tansu3, SOUND_OBK_CHECK_CABINET, SOUND_SPACE_DEFAULT)
EVT_CALL(TranslateModel, MODEL_tansu3, 0, 0, 100)
EVT_CALL(RotateModel, MODEL_tansu3, 1, 1, 0, 0)
EVT_CALL(TranslateModel, MODEL_tansu3, 0, 0, -100)
EVT_WAIT(2)
EVT_CALL(RotateModel, MODEL_tansu3, 0, 1, 0, 0)
EVT_WAIT(1)
EVT_END_LOOP
EVT_EXEC(N(EVS_CrushPlayer))
EVT_CALL(MakeLerp, 0, -90, 30, EASING_QUARTIC_IN)
EVT_LABEL(20)
EVT_CALL(UpdateLerp)
EVT_CALL(RotateModel, MODEL_tansu3, LVar0, 0, 0, 1)
EVT_CALL(UpdateColliderTransform, COLLIDER_tansu3)
EVT_CALL(UpdateColliderTransform, COLLIDER_o373)
EVT_WAIT(1)
EVT_IF_EQ(LVar1, 1)
EVT_GOTO(20)
EVT_END_IF
EVT_CALL(PlaySoundAtCollider, COLLIDER_tansu3, SOUND_OBK_CABINET_CRASH, SOUND_SPACE_DEFAULT)
EVT_THREAD
EVT_CALL(ShakeCam, CAM_DEFAULT, 0, 30, EVT_FLOAT(1.5))
EVT_END_THREAD
EVT_USE_BUF(EVT_PTR(N(DustEmitters_FarCabinet)))
EVT_LOOP(16)
EVT_BUF_READ2(LVar0, LVar1)
EVT_PLAY_EFFECT(EFFECT_LANDING_DUST, 2, LVar0, 0, LVar1, 0)
EVT_END_LOOP
EVT_WAIT(60)
EVT_CALL(MakeLerp, -90, 0, 10, EASING_LINEAR)
EVT_LABEL(25)
EVT_CALL(UpdateLerp)
EVT_CALL(RotateModel, MODEL_tansu3, LVar0, 0, 0, 1)
EVT_CALL(UpdateColliderTransform, COLLIDER_tansu3)
EVT_CALL(UpdateColliderTransform, COLLIDER_o373)
EVT_WAIT(1)
EVT_IF_EQ(LVar1, 1)
EVT_GOTO(25)
EVT_END_IF
EVT_EXEC_WAIT(N(EVS_RestorePlayer))
EVT_CALL(DisablePlayerInput, FALSE)
EVT_RETURN
EVT_END
};
EvtScript N(EVS_SetupCabinets) = {
EVT_CALL(ParentColliderToModel, COLLIDER_tansu1, MODEL_tansu1)
EVT_CALL(ParentColliderToModel, COLLIDER_o372, MODEL_tansu1)
EVT_CALL(ParentColliderToModel, COLLIDER_tansu3, MODEL_tansu3)
EVT_CALL(ParentColliderToModel, COLLIDER_o373, MODEL_tansu3)
EVT_BIND_TRIGGER(EVT_PTR(N(EVS_Interact_NearCabinet)), TRIGGER_WALL_PRESS_A, COLLIDER_tansu1, 1, MV_Trigger_NearCabinet)
EVT_BIND_TRIGGER(EVT_PTR(N(EVS_Interact_MiddleCabinet)), TRIGGER_WALL_PRESS_A, COLLIDER_tansu2, 1, MV_Trigger_MidCabinet)
EVT_BIND_TRIGGER(EVT_PTR(N(EVS_Interact_FarCabinet)), TRIGGER_WALL_PRESS_A, COLLIDER_tansu3, 1, MV_Trigger_FarCabinet)
EVT_RETURN
EVT_END
};
EvtScript N(EVS_BindCabinetTriggers) = {
EVT_BIND_TRIGGER(EVT_PTR(N(EVS_Interact_NearCabinet)), TRIGGER_WALL_PRESS_A, COLLIDER_tansu1, 1, MV_Trigger_NearCabinet)
EVT_BIND_TRIGGER(EVT_PTR(N(EVS_Interact_MiddleCabinet)), TRIGGER_WALL_PRESS_A, COLLIDER_tansu2, 1, MV_Trigger_MidCabinet)
EVT_BIND_TRIGGER(EVT_PTR(N(EVS_Interact_FarCabinet)), TRIGGER_WALL_PRESS_A, COLLIDER_tansu3, 1, MV_Trigger_FarCabinet)
EVT_RETURN
EVT_END
};
|
ddd4e8a2ccc11a9c4e77858fc923f44bd29ec827
|
fb163f40559d19d2791ad657b1a1e737f03aaed1
|
/source/arm9/dldi/dldi.c
|
909a0fb5ad6606da7076ae3134bd36e89a61c5d8
|
[
"Zlib"
] |
permissive
|
devkitPro/libnds
|
0fbc567493b61c6336d3df6dd9ffd4110c0b51d2
|
6cfbd4494d94a16982b8e7cefb7c63155a3d894b
|
refs/heads/master
| 2023-07-25T12:35:51.616995
| 2023-07-09T16:14:18
| 2023-07-09T16:14:18
| 28,190,585
| 288
| 90
|
NOASSERTION
| 2023-09-14T21:07:56
| 2014-12-18T16:07:36
|
C
|
UTF-8
|
C
| false
| false
| 6,443
|
c
|
dldi.c
|
/*
disc.c
Interface to the low level disc functions. Used by the higher level
file system code.
Based on code originally written by MightyMax
Copyright (c) 2006 Michael "Chishm" Chisholm
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <nds/arm9/dldi.h>
#include <nds/memory.h>
#include <nds/system.h>
#include <string.h>
#include <malloc.h>
#include <unistd.h>
#include <sys/fcntl.h>
const u32 DLDI_MAGIC_NUMBER =
0xBF8DA5ED;
// Stored backwards to prevent it being picked up by DLDI patchers
const char DLDI_MAGIC_STRING_BACKWARDS [DLDI_MAGIC_STRING_LEN] =
{'\0', 'm', 'h', 's', 'i', 'h', 'C', ' '} ;
// The only built in driver
extern DLDI_INTERFACE _io_dldi_stub;
const DLDI_INTERFACE* io_dldi_data = &_io_dldi_stub;
const DISC_INTERFACE* dldiGetInternal (void) {
if (_io_dldi_stub.ioInterface.features & FEATURE_SLOT_GBA) {
sysSetCartOwner(BUS_OWNER_ARM9);
}
if (_io_dldi_stub.ioInterface.features & FEATURE_SLOT_NDS) {
sysSetCardOwner(BUS_OWNER_ARM9);
}
return &_io_dldi_stub.ioInterface;
}
bool dldiIsValid (const DLDI_INTERFACE* io) {
int i;
if (io->magicNumber != DLDI_MAGIC_NUMBER) {
return false;
}
for (i = 0; i < DLDI_MAGIC_STRING_LEN; i++) {
if (io->magicString[i] != DLDI_MAGIC_STRING_BACKWARDS [DLDI_MAGIC_STRING_LEN - 1 - i]) {
return false;
}
}
return true;
}
void dldiFixDriverAddresses (DLDI_INTERFACE* io) {
u32 offset;
u8** address;
u8* oldStart;
u8* oldEnd;
offset = (char*)io - (char*)(io->dldiStart);
oldStart = io->dldiStart;
oldEnd = io->dldiEnd;
// Correct all pointers to the offsets from the location of this interface
io->dldiStart = (char*)io->dldiStart + offset;
io->dldiEnd = (char*)io->dldiEnd + offset;
io->interworkStart = (char*)io->interworkStart + offset;
io->interworkEnd = (char*)io->interworkEnd + offset;
io->gotStart = (char*)io->gotStart + offset;
io->gotEnd = (char*)io->gotEnd + offset;
io->bssStart = (char*)io->bssStart + offset;
io->bssEnd = (char*)io->bssEnd + offset;
io->ioInterface.startup = (FN_MEDIUM_STARTUP) ((intptr_t)io->ioInterface.startup + offset);
io->ioInterface.isInserted = (FN_MEDIUM_ISINSERTED) ((intptr_t)io->ioInterface.isInserted + offset);
io->ioInterface.readSectors = (FN_MEDIUM_READSECTORS) ((intptr_t)io->ioInterface.readSectors + offset);
io->ioInterface.writeSectors = (FN_MEDIUM_WRITESECTORS) ((intptr_t)io->ioInterface.writeSectors + offset);
io->ioInterface.clearStatus = (FN_MEDIUM_CLEARSTATUS) ((intptr_t)io->ioInterface.clearStatus + offset);
io->ioInterface.shutdown = (FN_MEDIUM_SHUTDOWN) ((intptr_t)io->ioInterface.shutdown + offset);
// Fix all addresses with in the DLDI
if (io->fixSectionsFlags & FIX_ALL) {
for (address = (u8**)io->dldiStart; address < (u8**)io->dldiEnd; address++) {
if (oldStart <= *address && *address < oldEnd) {
*address += offset;
}
}
}
// Fix the interworking glue section
if (io->fixSectionsFlags & FIX_GLUE) {
for (address = (u8**)io->interworkStart; address < (u8**)io->interworkEnd; address++) {
if (oldStart <= *address && *address < oldEnd) {
*address += offset;
}
}
}
// Fix the global offset table section
if (io->fixSectionsFlags & FIX_GOT) {
for (address = (u8**)io->gotStart; address < (u8**)io->gotEnd; address++) {
if (oldStart <= *address && *address < oldEnd) {
*address += offset;
}
}
}
// Initialise the BSS to 0
if (io->fixSectionsFlags & FIX_BSS) {
memset (io->bssStart, 0, (u8*)io->bssEnd - (u8*)io->bssStart);
}
}
DLDI_INTERFACE* dldiLoadFromFile (const char* path) {
DLDI_INTERFACE* device;
int fd;
size_t dldiSize;
// Read in the DLDI header
if ((fd = open (path, O_RDONLY, 0)) < 0) {
return NULL;
}
if ((device = malloc (sizeof(DLDI_INTERFACE))) == NULL) {
close (fd);
return NULL;
}
if (read (fd, device, sizeof(DLDI_INTERFACE)) < sizeof(DLDI_INTERFACE)) {
free (device);
close (fd);
return NULL;
}
// Check that it is a valid DLDI
if (!dldiIsValid (device)) {
free (device);
close (fd);
return NULL;
}
// Calculate actual size of DLDI
// Although the file may only go to the dldiEnd, the BSS section can extend past that
if (device->dldiEnd > device->bssEnd) {
dldiSize = (char*)device->dldiEnd - (char*)device->dldiStart;
} else {
dldiSize = (char*)device->bssEnd - (char*)device->dldiStart;
}
dldiSize = (dldiSize + 0x03) & ~0x03; // Round up to nearest integer multiple
// Load entire DLDI
free (device);
if ((device = malloc (dldiSize)) == NULL) {
close (fd);
return NULL;
}
memset (device, 0, dldiSize);
lseek (fd, 0, SEEK_SET);
read (fd, device, dldiSize);
close (fd);
dldiFixDriverAddresses (device);
if (device->ioInterface.features & FEATURE_SLOT_GBA) {
sysSetCartOwner(BUS_OWNER_ARM9);
}
if (device->ioInterface.features & FEATURE_SLOT_NDS) {
sysSetCardOwner(BUS_OWNER_ARM9);
}
return device;
}
void dldiFree (DLDI_INTERFACE* dldi) {
free(dldi);
}
extern const DISC_INTERFACE __io_dsisd;
const DISC_INTERFACE* get_io_dsisd (void) {
return (isDSiMode() && __NDSHeader->unitCode ) ? &__io_dsisd : NULL;
}
|
a5150695fb37a94c67f8b14de279cd8b0e916185
|
3bd385b466cb035fecd2b0c11ae054d42bf44fc2
|
/src/core/fasta_reader.c
|
7391518a906f6a0520a1cb12fa4b86ce4bcd49e0
|
[
"LicenseRef-scancode-unknown-license-reference",
"ISC",
"BSD-2-Clause",
"LicenseRef-scancode-mit-old-style",
"Zlib",
"MIT",
"BSD-3-Clause",
"bzip2-1.0.6"
] |
permissive
|
genometools/genometools
|
c366dff04f6baa887f6b3be3ec55bce824b2bae1
|
df1df94b8c05a9c9bf848ffc6755c87b58573da5
|
refs/heads/master
| 2023-04-13T13:57:18.748796
| 2023-04-09T21:29:53
| 2023-04-09T21:29:53
| 11,177,980
| 237
| 63
|
NOASSERTION
| 2023-04-09T21:29:54
| 2013-07-04T13:39:38
|
C
|
UTF-8
|
C
| false
| false
| 1,976
|
c
|
fasta_reader.c
|
/*
Copyright (c) 2008 Gordon Gremme <gordon@gremme.org>
Copyright (c) 2008 Center for Bioinformatics, University of Hamburg
Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include "core/fasta_reader_rep.h"
#include "core/ma_api.h"
#include "core/unused_api.h"
GtFastaReader* gt_fasta_reader_create(const GtFastaReaderClass *frc)
{
GtFastaReader *fr;
gt_assert(frc && frc->size);
fr = gt_calloc(1, frc->size);
fr->c_class = frc;
return fr;
}
void gt_fasta_reader_delete(GtFastaReader *fr)
{
if (!fr) return;
gt_assert(fr->c_class && fr->c_class->free);
fr->c_class->free(fr);
gt_free(fr);
}
int gt_fasta_reader_run(GtFastaReader *fr,
GtFastaReaderProcDescription proc_description,
GtFastaReaderProcSequencePart proc_sequence_part,
GtFastaReaderProcSequenceLength proc_sequence_length,
void *data, GtError *err)
{
gt_error_check(err);
gt_assert(fr && fr->c_class && fr->c_class->run);
return fr->c_class->run(fr, proc_description, proc_sequence_part,
proc_sequence_length, data, err);
}
void* gt_fasta_reader_cast(GT_UNUSED const GtFastaReaderClass *frc,
GtFastaReader *fr)
{
gt_assert(frc && fr && fr->c_class == frc);
return fr;
}
|
0425b0049e3afb46d5fd606c74280d5a0c01e468
|
eecd5e4c50d8b78a769bcc2675250576bed34066
|
/src/mat/impls/aij/mpi/mpb_aij.c
|
ec5093dcc588da425a48e06dacc1febf383eb952
|
[
"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
| 3,726
|
c
|
mpb_aij.c
|
#include <../src/mat/impls/aij/mpi/mpiaij.h>
PetscErrorCode MatGetMultiProcBlock_MPIAIJ(Mat mat, MPI_Comm subComm, MatReuse scall, Mat *subMat)
{
Mat_MPIAIJ *aij = (Mat_MPIAIJ *)mat->data;
Mat_SeqAIJ *aijB = (Mat_SeqAIJ *)aij->B->data;
PetscMPIInt subCommSize, subCommRank;
PetscMPIInt *commRankMap, subRank, rank, commRank;
PetscInt *garrayCMap, col, i, j, *nnz, newRow, newCol;
PetscFunctionBegin;
PetscCallMPI(MPI_Comm_size(subComm, &subCommSize));
PetscCallMPI(MPI_Comm_rank(subComm, &subCommRank));
PetscCallMPI(MPI_Comm_rank(PetscObjectComm((PetscObject)mat), &commRank));
/* create subMat object with the relevant layout */
if (scall == MAT_INITIAL_MATRIX) {
PetscCall(MatCreate(subComm, subMat));
PetscCall(MatSetType(*subMat, MATMPIAIJ));
PetscCall(MatSetSizes(*subMat, mat->rmap->n, mat->cmap->n, PETSC_DECIDE, PETSC_DECIDE));
PetscCall(MatSetBlockSizesFromMats(*subMat, mat, mat));
/* need to setup rmap and cmap before Preallocation */
PetscCall(PetscLayoutSetUp((*subMat)->rmap));
PetscCall(PetscLayoutSetUp((*subMat)->cmap));
}
/* create a map of comm_rank from subComm to comm - should commRankMap and garrayCMap be kept for reused? */
PetscCall(PetscMalloc1(subCommSize, &commRankMap));
PetscCallMPI(MPI_Allgather(&commRank, 1, MPI_INT, commRankMap, 1, MPI_INT, subComm));
/* Traverse garray and identify column indices [of offdiag mat] that
should be discarded. For the ones not discarded, store the newCol+1
value in garrayCMap */
PetscCall(PetscCalloc1(aij->B->cmap->n, &garrayCMap));
for (i = 0; i < aij->B->cmap->n; i++) {
col = aij->garray[i];
for (subRank = 0; subRank < subCommSize; subRank++) {
rank = commRankMap[subRank];
if ((col >= mat->cmap->range[rank]) && (col < mat->cmap->range[rank + 1])) {
garrayCMap[i] = (*subMat)->cmap->range[subRank] + col - mat->cmap->range[rank] + 1;
break;
}
}
}
if (scall == MAT_INITIAL_MATRIX) {
/* Compute preallocation for the offdiag mat */
PetscCall(PetscCalloc1(aij->B->rmap->n, &nnz));
for (i = 0; i < aij->B->rmap->n; i++) {
for (j = aijB->i[i]; j < aijB->i[i + 1]; j++) {
if (garrayCMap[aijB->j[j]]) nnz[i]++;
}
}
PetscCall(MatMPIAIJSetPreallocation(*(subMat), 0, NULL, 0, nnz));
/* reuse diag block with the new submat */
PetscCall(MatDestroy(&((Mat_MPIAIJ *)((*subMat)->data))->A));
((Mat_MPIAIJ *)((*subMat)->data))->A = aij->A;
PetscCall(PetscObjectReference((PetscObject)aij->A));
} else if (((Mat_MPIAIJ *)(*subMat)->data)->A != aij->A) {
PetscObject obj = (PetscObject)((Mat_MPIAIJ *)((*subMat)->data))->A;
PetscCall(PetscObjectReference((PetscObject)obj));
((Mat_MPIAIJ *)((*subMat)->data))->A = aij->A;
PetscCall(PetscObjectReference((PetscObject)aij->A));
}
/* Traverse aij->B and insert values into subMat */
if ((*subMat)->assembled) {
(*subMat)->was_assembled = PETSC_TRUE;
(*subMat)->assembled = PETSC_FALSE;
}
for (i = 0; i < aij->B->rmap->n; i++) {
newRow = (*subMat)->rmap->range[subCommRank] + i;
for (j = aijB->i[i]; j < aijB->i[i + 1]; j++) {
newCol = garrayCMap[aijB->j[j]];
if (newCol) {
newCol--; /* remove the increment */
PetscCall(MatSetValues_MPIAIJ(*subMat, 1, &newRow, 1, &newCol, (aijB->a + j), INSERT_VALUES));
}
}
}
PetscCall(MatAssemblyBegin(*subMat, MAT_FINAL_ASSEMBLY));
PetscCall(MatAssemblyEnd(*subMat, MAT_FINAL_ASSEMBLY));
/* deallocate temporary data */
PetscCall(PetscFree(commRankMap));
PetscCall(PetscFree(garrayCMap));
if (scall == MAT_INITIAL_MATRIX) PetscCall(PetscFree(nnz));
PetscFunctionReturn(PETSC_SUCCESS);
}
|
77dcfbeaf94575d028ef701229461a07a78b0004
|
a209da157b4911a999eaab36ab007dc1e788a77d
|
/src/owl.c
|
f3e7aa6c3ac4a2ff5f7bc50f9d2a4b947071ebe8
|
[
"MIT"
] |
permissive
|
ianh/owl
|
dccdde2bd34405236a52f96c877138e5d837bdd1
|
27fca39aa8d2e4c40e5d6f13170463bb21e3acaa
|
refs/heads/master
| 2023-08-15T21:28:28.522128
| 2023-07-19T23:00:15
| 2023-07-19T23:00:15
| 142,875,118
| 715
| 32
|
MIT
| 2023-06-13T21:41:01
| 2018-07-30T12:51:28
|
C
|
UTF-8
|
C
| false
| false
| 15,874
|
c
|
owl.c
|
#include "1-parse.h"
#include "2-build.h"
#include "4-check-for-ambiguity.h"
#include "5-determinize.h"
#include "6a-generate.h"
#include "6b-interpret.h"
#include "alloc.h"
#include "terminal.h"
#include "test.h"
#include <stdio.h>
#include <string.h>
static FILE *output_file = 0;
static struct terminal_info get_terminal_info(int fileno);
static FILE *fopen_or_error(const char *filename, const char *mode);
static char *read_string(FILE *file);
static void write_to_output(const char *string, size_t len);
static const char *version_string = "owl.v4";
static const char *compatible_versions[] = {
"owl.v1",
"owl.v2",
"owl.v3",
"owl.v4",
};
int main(int argc, char *argv[])
{
// This useless-looking call to memset is important for the Try Owl web
// tool, which re-runs main repeatedly without clearing static variables.
memset(&error, 0, sizeof(error));
// Parse arguments.
bool needs_help = false;
char *input_filename = 0;
char *output_filename = 0;
char *grammar_string = 0;
// May be different if the grammar is in "test format".
char *grammar_string_to_free = 0;
char *prefix_string = 0;
char *input_string = 0;
bool compile = false;
bool test_format = false;
enum {
NO_PARAMETER,
INPUT_FILE_PARAMETER,
OUTPUT_FILE_PARAMETER,
GRAMMAR_TEXT_PARAMETER,
PREFIX_PARAMETER,
} parameter_state = NO_PARAMETER;
for (int i = 1; i < argc; ++i) {
const char *short_name = "";
const char *long_name = "";
if (argv[i][0] == '-') {
if (argv[i][1] == '-')
long_name = argv[i] + 2;
else
short_name = argv[i] + 1;
}
switch (parameter_state) {
case NO_PARAMETER:
if (!strcmp(short_name, "h") || !strcmp(long_name, "help"))
needs_help = true;
else if (!strcmp(short_name, "V") || !strcmp(long_name, "version")) {
fprintf(stderr, "%s\n", version_string);
return 0;
} else if (!strcmp(short_name, "i") || !strcmp(long_name, "input")) {
if (input_filename)
exit_with_errorf("multiple input filenames");
parameter_state = INPUT_FILE_PARAMETER;
} else if (!strcmp(short_name, "o") ||
!strcmp(long_name, "output")) {
if (output_filename)
exit_with_errorf("multiple output filenames");
parameter_state = OUTPUT_FILE_PARAMETER;
} else if (!strcmp(short_name, "g") ||
!strcmp(long_name, "grammar")) {
if (grammar_string)
exit_with_errorf("owl only supports one grammar at a time");
parameter_state = GRAMMAR_TEXT_PARAMETER;
} else if (!strcmp(short_name, "p") ||
!strcmp(long_name, "prefix")) {
if (prefix_string)
exit_with_errorf("multiple prefixes specified on the command line");
parameter_state = PREFIX_PARAMETER;
} else if (!strcmp(short_name, "T") ||
!strcmp(long_name, "test-format"))
test_format = true;
else if (!strcmp(short_name, "c") ||
!strcmp(long_name, "compile"))
compile = true;
else if (!strcmp(short_name, "C") || !strcmp(long_name, "color"))
force_terminal_colors = true;
else if (long_name[0] || short_name[0]) {
errorf("unknown option: %s%s", long_name[0] ? "--" : "-",
long_name[0] ? long_name : short_name);
print_error();
needs_help = true;
} else if (!grammar_string) {
FILE *grammar_file = fopen_or_error(argv[i], "r");
grammar_string = read_string(grammar_file);
grammar_string_to_free = grammar_string;
fclose(grammar_file);
} else
exit_with_errorf("owl only supports one grammar at a time");
break;
case INPUT_FILE_PARAMETER:
if (short_name[0] || long_name[0]) {
errorf("missing input filename");
print_error();
needs_help = true;
break;
}
input_filename = argv[i];
parameter_state = NO_PARAMETER;
break;
case OUTPUT_FILE_PARAMETER:
if (short_name[0] || long_name[0]) {
errorf("missing output filename");
print_error();
needs_help = true;
break;
}
output_filename = argv[i];
parameter_state = NO_PARAMETER;
break;
case GRAMMAR_TEXT_PARAMETER: {
if (short_name[0] || long_name[0]) {
errorf("missing grammar text");
print_error();
needs_help = true;
break;
}
size_t len = strlen(argv[i]);
if (len + 1 < len)
abort();
grammar_string = malloc(len + 1);
memcpy(grammar_string, argv[i], len + 1);
parameter_state = NO_PARAMETER;
break;
case PREFIX_PARAMETER:
if (short_name[0] || long_name[0]) {
errorf("missing prefix");
print_error();
needs_help = true;
break;
}
prefix_string = argv[i];
parameter_state = NO_PARAMETER;
break;
}
}
if (needs_help)
break;
}
switch (parameter_state) {
case INPUT_FILE_PARAMETER:
errorf("missing input filename");
print_error();
needs_help = true;
break;
case OUTPUT_FILE_PARAMETER:
errorf("missing output filename");
print_error();
needs_help = true;
break;
case GRAMMAR_TEXT_PARAMETER:
errorf("missing grammar text");
print_error();
needs_help = true;
break;
case PREFIX_PARAMETER:
errorf("missing prefix");
print_error();
needs_help = true;
break;
case NO_PARAMETER:
break;
}
if (!needs_help && !grammar_string) {
errorf("missing grammar");
print_error();
needs_help = true;
}
if (needs_help) {
fprintf(stderr, "usage: owl [options] grammar.owl\n");
fprintf(stderr, " -i file --input file read from file instead of standard input\n");
fprintf(stderr, " -o file --output file write to file instead of standard output\n");
fprintf(stderr, " -c --compile output a C header file instead of parsing input\n");
fprintf(stderr, " -g grammar --grammar grammar specify the grammar text on the command line\n");
fprintf(stderr, " -p prefix --prefix prefix output prefix_ instead of owl_ and parsed_\n");
fprintf(stderr, " -T --test-format use test format with combined input and grammar\n");
fprintf(stderr, " -C --color force 256-color parse tree output\n");
fprintf(stderr, " -V --version print version info and exit\n");
fprintf(stderr, " -h --help output this help text\n");
return 1;
}
if (test_format) {
size_t i = 0;
int dash_count = 0;
for (; grammar_string[i]; ++i) {
if (grammar_string[i] == '-')
dash_count++;
else
dash_count = 0;
if (dash_count == 3)
break;
}
if (grammar_string[i] == '\0') {
exit_with_errorf("a file in test format requires the string '---' "
"to separate input from grammars");
}
input_string = malloc(i - 1);
strncpy(input_string, grammar_string, i - 2);
input_string[i - 2] = '\0';
grammar_string += i + 1;
}
error_in_string = grammar_string;
// Check to see if the version is compatible.
size_t using_length = strlen("#using ");
bool compatible_version = false;
struct grammar_version version = {
.string = version_string,
};
if (strncmp(grammar_string, "#using ", using_length)) {
compatible_version = true;
if (compile && !test_format) {
errorf("compiling a grammar without a version string");
error.level = WARNING;
print_error();
error = (struct error){0};
fprintf(stderr, "\n Owl's grammar format may change between "
"versions. Add the string\n\n");
fprintf(stderr, " #using %s\n\n", version_string);
fprintf(stderr, " to the top of your grammar file to lock in "
"this version.\n\n");
}
} else for (size_t i = 0; i < sizeof(compatible_versions) /
sizeof(compatible_versions[0]); ++i) {
size_t version_length = strlen(compatible_versions[i]);
size_t j = using_length;
size_t end = j + version_length;
if (strncmp(grammar_string + j, compatible_versions[i], version_length)
|| !(grammar_string[end] == '\r' || grammar_string[end] == '\n'))
continue;
version.string = compatible_versions[i];
version.range.start = j;
version.range.end = end;
compatible_version = true;
}
if (!compatible_version) {
size_t i = using_length;
error.ranges[0].start = i;
while (grammar_string[i] != '\0' && grammar_string[i] != '\r' &&
grammar_string[i] != '\n')
i++;
error.ranges[0].end = i;
exit_with_errorf("incompatible version");
}
int output_fileno = -1;
if (output_filename)
output_file = fopen_or_error(output_filename, "w");
else {
output_file = stdout;
output_fileno = STDOUT_FILENO;
}
// This is the part where things actually happen.
struct owl_tree *tree;
tree = owl_tree_create_from_string(grammar_string);
switch (owl_tree_get_error(tree, &error.ranges[0])) {
case ERROR_INVALID_TOKEN: {
char *s = grammar_string + error.ranges[0].start;
if (s[0] == '-' && s[1] == '-' && s[2] == '-') {
error.ranges[0].end = error.ranges[0].start + 3;
exit_with_errorf("to interpret a grammar in test format, use -T");
}
exit_with_errorf("'%.*s' isn't a valid token",
(int)(error.ranges[0].end - error.ranges[0].start),
grammar_string + error.ranges[0].start);
}
case ERROR_UNEXPECTED_TOKEN:
exit_with_errorf("unexpected token '%.*s' while parsing grammar",
(int)(error.ranges[0].end - error.ranges[0].start),
grammar_string + error.ranges[0].start);
case ERROR_MORE_INPUT_NEEDED:
exit_with_errorf("expected more text at the end of the grammar");
default:
break;
}
struct grammar grammar = {0};
build(&grammar, tree, version);
struct combined_grammar combined = {0};
combine(&combined, &grammar);
#if 0
automaton_print(&combined.automaton);
automaton_print(&combined.bracket_automaton);
for (uint32_t i = 0; i < combined.number_of_tokens; ++i) {
printf("token %x: %.*s\n", i, (int)combined.tokens[i].length,
combined.tokens[i].string);
}
#endif
struct ambiguity ambiguity = {0};
check_for_ambiguity(&combined, &ambiguity);
if (ambiguity.has_ambiguity) {
struct interpreter interpreter = {
.grammar = &grammar,
.combined = &combined,
.terminal_info = get_terminal_info(STDERR_FILENO),
.version = version,
};
output_ambiguity(&interpreter, &ambiguity, stderr);
return 3;
}
struct deterministic_grammar deterministic = {0};
determinize(&combined, &deterministic);
if (compile) {
#ifndef NOT_UNIX
struct test_compilation test;
// If -T is specified, test the code generator.
if (test_format) {
if (!output_filename) {
exit_with_errorf("-T -c must include -o -- an executable will "
"be written to the output path");
}
test.executable_filename = output_filename;
output_filename = 0;
fclose(output_file);
begin_test_compilation(&test);
output_file = test.file;
}
#endif
struct generator generator = {
.output = write_to_output,
.grammar = &grammar,
.combined = &combined,
.deterministic = &deterministic,
.version = version,
.prefix = prefix_string,
};
generate(&generator);
#ifndef NOT_UNIX
if (test_format) {
finish_test_compilation(&test, input_string);
output_file = 0;
}
#endif
} else {
if (!input_string) {
FILE *input_file = stdin;
if (input_filename)
input_file = fopen_or_error(input_filename, "r");
input_string = read_string(input_file);
if (input_filename)
fclose(input_file);
}
struct interpreter interpreter = {
.grammar = &grammar,
.combined = &combined,
.deterministic = &deterministic,
.terminal_info = get_terminal_info(output_fileno),
.version = version,
};
error_in_string = input_string;
interpret(&interpreter, input_string, output_file);
}
if (output_filename)
fclose(output_file);
deterministic_grammar_destroy(&deterministic);
combined_grammar_destroy(&combined);
grammar_destroy(&grammar);
owl_tree_destroy(tree);
free(input_string);
free(grammar_string_to_free);
return 0;
}
static const char *colors_8[] = {
"\033[31m",
"\033[32m",
"\033[33m",
"\033[34m",
"\033[35m",
"\033[36m",
};
static const char *colors_256[] = {
"\033[38;5;168m",
"\033[38;5;113m",
"\033[38;5;68m",
"\033[38;5;214m",
"\033[38;5;97m",
};
static struct terminal_info get_terminal_info(int fileno)
{
struct terminal_info info = {0};
info.columns = terminal_columns(fileno);
if (info.columns <= 0)
info.columns = 80;
int colors = terminal_colors(fileno);
if (colors >= 256) {
info.reset = "\033[0m";
info.line_indicator = "\033[90m";
info.row_colors = colors_256;
info.number_of_row_colors = sizeof(colors_256) / sizeof(colors_256[0]);
} else if (colors >= 8) {
info.reset = "\033[0m";
info.line_indicator = "\033[90m";
info.row_colors = colors_8;
info.number_of_row_colors = sizeof(colors_8) / sizeof(colors_8[0]);
}
return info;
}
static FILE *fopen_or_error(const char *filename, const char *mode)
{
FILE *file = fopen(filename, mode);
if (file)
return file;
errorf("couldn't open file:");
print_error();
fprintf(stderr, "\n %s\n\n", filename);
exit(-1);
}
static char *read_string(FILE *file)
{
char *string = 0;
uint32_t len = 0;
uint32_t offset = 0;
while (true) {
string = grow_array(string, &len, (size_t)len + 256);
uint32_t n = (uint32_t)fread(string + offset, 1, len - offset, file);
if (n < len - offset) {
string[offset + n] = '\0';
return string;
}
offset += n;
}
}
static void write_to_output(const char *string, size_t len)
{
if (len > 0 && fwrite(string, len, 1, output_file) != 1) {
fputs("critical error: write to output file failed\n", stderr);
exit(-1);
}
}
|
6bfbe1efc146901fa21ba9f63850229c6929ac7e
|
7eaf54a78c9e2117247cb2ab6d3a0c20719ba700
|
/SOFTWARE/A64-TERES/linux-a64/drivers/acpi/acpi_pad.c
|
27bb6a91de5f6cf257fd85562fb12bcc033baecc
|
[
"LicenseRef-scancode-free-unknown",
"Apache-2.0",
"Linux-syscall-note",
"GPL-2.0-only",
"GPL-1.0-or-later"
] |
permissive
|
OLIMEX/DIY-LAPTOP
|
ae82f4ee79c641d9aee444db9a75f3f6709afa92
|
a3fafd1309135650bab27f5eafc0c32bc3ca74ee
|
refs/heads/rel3
| 2023-08-04T01:54:19.483792
| 2023-04-03T07:18:12
| 2023-04-03T07:18:12
| 80,094,055
| 507
| 92
|
Apache-2.0
| 2023-04-03T07:05:59
| 2017-01-26T07:25:50
|
C
|
UTF-8
|
C
| false
| false
| 13,689
|
c
|
acpi_pad.c
|
/*
* acpi_pad.c ACPI Processor Aggregator Driver
*
* Copyright (c) 2009, Intel Corporation.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
*
*/
#include <linux/kernel.h>
#include <linux/cpumask.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/types.h>
#include <linux/kthread.h>
#include <linux/freezer.h>
#include <linux/cpu.h>
#include <linux/clockchips.h>
#include <linux/slab.h>
#include <acpi/acpi_bus.h>
#include <acpi/acpi_drivers.h>
#include <asm/mwait.h>
#define ACPI_PROCESSOR_AGGREGATOR_CLASS "acpi_pad"
#define ACPI_PROCESSOR_AGGREGATOR_DEVICE_NAME "Processor Aggregator"
#define ACPI_PROCESSOR_AGGREGATOR_NOTIFY 0x80
static DEFINE_MUTEX(isolated_cpus_lock);
static DEFINE_MUTEX(round_robin_lock);
static unsigned long power_saving_mwait_eax;
static unsigned char tsc_detected_unstable;
static unsigned char tsc_marked_unstable;
static unsigned char lapic_detected_unstable;
static unsigned char lapic_marked_unstable;
static void power_saving_mwait_init(void)
{
unsigned int eax, ebx, ecx, edx;
unsigned int highest_cstate = 0;
unsigned int highest_subcstate = 0;
int i;
if (!boot_cpu_has(X86_FEATURE_MWAIT))
return;
if (boot_cpu_data.cpuid_level < CPUID_MWAIT_LEAF)
return;
cpuid(CPUID_MWAIT_LEAF, &eax, &ebx, &ecx, &edx);
if (!(ecx & CPUID5_ECX_EXTENSIONS_SUPPORTED) ||
!(ecx & CPUID5_ECX_INTERRUPT_BREAK))
return;
edx >>= MWAIT_SUBSTATE_SIZE;
for (i = 0; i < 7 && edx; i++, edx >>= MWAIT_SUBSTATE_SIZE) {
if (edx & MWAIT_SUBSTATE_MASK) {
highest_cstate = i;
highest_subcstate = edx & MWAIT_SUBSTATE_MASK;
}
}
power_saving_mwait_eax = (highest_cstate << MWAIT_SUBSTATE_SIZE) |
(highest_subcstate - 1);
#if defined(CONFIG_X86)
switch (boot_cpu_data.x86_vendor) {
case X86_VENDOR_AMD:
case X86_VENDOR_INTEL:
/*
* AMD Fam10h TSC will tick in all
* C/P/S0/S1 states when this bit is set.
*/
if (!boot_cpu_has(X86_FEATURE_NONSTOP_TSC))
tsc_detected_unstable = 1;
if (!boot_cpu_has(X86_FEATURE_ARAT))
lapic_detected_unstable = 1;
break;
default:
/* TSC & LAPIC could halt in idle */
tsc_detected_unstable = 1;
lapic_detected_unstable = 1;
}
#endif
}
static unsigned long cpu_weight[NR_CPUS];
static int tsk_in_cpu[NR_CPUS] = {[0 ... NR_CPUS-1] = -1};
static DECLARE_BITMAP(pad_busy_cpus_bits, NR_CPUS);
static void round_robin_cpu(unsigned int tsk_index)
{
struct cpumask *pad_busy_cpus = to_cpumask(pad_busy_cpus_bits);
cpumask_var_t tmp;
int cpu;
unsigned long min_weight = -1;
unsigned long uninitialized_var(preferred_cpu);
if (!alloc_cpumask_var(&tmp, GFP_KERNEL))
return;
mutex_lock(&round_robin_lock);
cpumask_clear(tmp);
for_each_cpu(cpu, pad_busy_cpus)
cpumask_or(tmp, tmp, topology_thread_cpumask(cpu));
cpumask_andnot(tmp, cpu_online_mask, tmp);
/* avoid HT sibilings if possible */
if (cpumask_empty(tmp))
cpumask_andnot(tmp, cpu_online_mask, pad_busy_cpus);
if (cpumask_empty(tmp)) {
mutex_unlock(&round_robin_lock);
return;
}
for_each_cpu(cpu, tmp) {
if (cpu_weight[cpu] < min_weight) {
min_weight = cpu_weight[cpu];
preferred_cpu = cpu;
}
}
if (tsk_in_cpu[tsk_index] != -1)
cpumask_clear_cpu(tsk_in_cpu[tsk_index], pad_busy_cpus);
tsk_in_cpu[tsk_index] = preferred_cpu;
cpumask_set_cpu(preferred_cpu, pad_busy_cpus);
cpu_weight[preferred_cpu]++;
mutex_unlock(&round_robin_lock);
set_cpus_allowed_ptr(current, cpumask_of(preferred_cpu));
}
static void exit_round_robin(unsigned int tsk_index)
{
struct cpumask *pad_busy_cpus = to_cpumask(pad_busy_cpus_bits);
cpumask_clear_cpu(tsk_in_cpu[tsk_index], pad_busy_cpus);
tsk_in_cpu[tsk_index] = -1;
}
static unsigned int idle_pct = 5; /* percentage */
static unsigned int round_robin_time = 1; /* second */
static int power_saving_thread(void *data)
{
struct sched_param param = {.sched_priority = 1};
int do_sleep;
unsigned int tsk_index = (unsigned long)data;
u64 last_jiffies = 0;
sched_setscheduler(current, SCHED_RR, ¶m);
while (!kthread_should_stop()) {
int cpu;
u64 expire_time;
try_to_freeze();
/* round robin to cpus */
if (last_jiffies + round_robin_time * HZ < jiffies) {
last_jiffies = jiffies;
round_robin_cpu(tsk_index);
}
do_sleep = 0;
expire_time = jiffies + HZ * (100 - idle_pct) / 100;
while (!need_resched()) {
if (tsc_detected_unstable && !tsc_marked_unstable) {
/* TSC could halt in idle, so notify users */
mark_tsc_unstable("TSC halts in idle");
tsc_marked_unstable = 1;
}
if (lapic_detected_unstable && !lapic_marked_unstable) {
int i;
/* LAPIC could halt in idle, so notify users */
for_each_online_cpu(i)
clockevents_notify(
CLOCK_EVT_NOTIFY_BROADCAST_ON,
&i);
lapic_marked_unstable = 1;
}
local_irq_disable();
cpu = smp_processor_id();
if (lapic_marked_unstable)
clockevents_notify(
CLOCK_EVT_NOTIFY_BROADCAST_ENTER, &cpu);
stop_critical_timings();
__monitor((void *)¤t_thread_info()->flags, 0, 0);
smp_mb();
if (!need_resched())
__mwait(power_saving_mwait_eax, 1);
start_critical_timings();
if (lapic_marked_unstable)
clockevents_notify(
CLOCK_EVT_NOTIFY_BROADCAST_EXIT, &cpu);
local_irq_enable();
if (jiffies > expire_time) {
do_sleep = 1;
break;
}
}
/*
* current sched_rt has threshold for rt task running time.
* When a rt task uses 95% CPU time, the rt thread will be
* scheduled out for 5% CPU time to not starve other tasks. But
* the mechanism only works when all CPUs have RT task running,
* as if one CPU hasn't RT task, RT task from other CPUs will
* borrow CPU time from this CPU and cause RT task use > 95%
* CPU time. To make 'avoid starvation' work, takes a nap here.
*/
if (do_sleep)
schedule_timeout_killable(HZ * idle_pct / 100);
}
exit_round_robin(tsk_index);
return 0;
}
static struct task_struct *ps_tsks[NR_CPUS];
static unsigned int ps_tsk_num;
static int create_power_saving_task(void)
{
int rc = -ENOMEM;
ps_tsks[ps_tsk_num] = kthread_run(power_saving_thread,
(void *)(unsigned long)ps_tsk_num,
"acpi_pad/%d", ps_tsk_num);
rc = PTR_RET(ps_tsks[ps_tsk_num]);
if (!rc)
ps_tsk_num++;
else
ps_tsks[ps_tsk_num] = NULL;
return rc;
}
static void destroy_power_saving_task(void)
{
if (ps_tsk_num > 0) {
ps_tsk_num--;
kthread_stop(ps_tsks[ps_tsk_num]);
ps_tsks[ps_tsk_num] = NULL;
}
}
static void set_power_saving_task_num(unsigned int num)
{
if (num > ps_tsk_num) {
while (ps_tsk_num < num) {
if (create_power_saving_task())
return;
}
} else if (num < ps_tsk_num) {
while (ps_tsk_num > num)
destroy_power_saving_task();
}
}
static void acpi_pad_idle_cpus(unsigned int num_cpus)
{
get_online_cpus();
num_cpus = min_t(unsigned int, num_cpus, num_online_cpus());
set_power_saving_task_num(num_cpus);
put_online_cpus();
}
static uint32_t acpi_pad_idle_cpus_num(void)
{
return ps_tsk_num;
}
static ssize_t acpi_pad_rrtime_store(struct device *dev,
struct device_attribute *attr, const char *buf, size_t count)
{
unsigned long num;
if (kstrtoul(buf, 0, &num))
return -EINVAL;
if (num < 1 || num >= 100)
return -EINVAL;
mutex_lock(&isolated_cpus_lock);
round_robin_time = num;
mutex_unlock(&isolated_cpus_lock);
return count;
}
static ssize_t acpi_pad_rrtime_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
return scnprintf(buf, PAGE_SIZE, "%d\n", round_robin_time);
}
static DEVICE_ATTR(rrtime, S_IRUGO|S_IWUSR,
acpi_pad_rrtime_show,
acpi_pad_rrtime_store);
static ssize_t acpi_pad_idlepct_store(struct device *dev,
struct device_attribute *attr, const char *buf, size_t count)
{
unsigned long num;
if (kstrtoul(buf, 0, &num))
return -EINVAL;
if (num < 1 || num >= 100)
return -EINVAL;
mutex_lock(&isolated_cpus_lock);
idle_pct = num;
mutex_unlock(&isolated_cpus_lock);
return count;
}
static ssize_t acpi_pad_idlepct_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
return scnprintf(buf, PAGE_SIZE, "%d\n", idle_pct);
}
static DEVICE_ATTR(idlepct, S_IRUGO|S_IWUSR,
acpi_pad_idlepct_show,
acpi_pad_idlepct_store);
static ssize_t acpi_pad_idlecpus_store(struct device *dev,
struct device_attribute *attr, const char *buf, size_t count)
{
unsigned long num;
if (kstrtoul(buf, 0, &num))
return -EINVAL;
mutex_lock(&isolated_cpus_lock);
acpi_pad_idle_cpus(num);
mutex_unlock(&isolated_cpus_lock);
return count;
}
static ssize_t acpi_pad_idlecpus_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
int n = 0;
n = cpumask_scnprintf(buf, PAGE_SIZE-2, to_cpumask(pad_busy_cpus_bits));
buf[n++] = '\n';
buf[n] = '\0';
return n;
}
static DEVICE_ATTR(idlecpus, S_IRUGO|S_IWUSR,
acpi_pad_idlecpus_show,
acpi_pad_idlecpus_store);
static int acpi_pad_add_sysfs(struct acpi_device *device)
{
int result;
result = device_create_file(&device->dev, &dev_attr_idlecpus);
if (result)
return -ENODEV;
result = device_create_file(&device->dev, &dev_attr_idlepct);
if (result) {
device_remove_file(&device->dev, &dev_attr_idlecpus);
return -ENODEV;
}
result = device_create_file(&device->dev, &dev_attr_rrtime);
if (result) {
device_remove_file(&device->dev, &dev_attr_idlecpus);
device_remove_file(&device->dev, &dev_attr_idlepct);
return -ENODEV;
}
return 0;
}
static void acpi_pad_remove_sysfs(struct acpi_device *device)
{
device_remove_file(&device->dev, &dev_attr_idlecpus);
device_remove_file(&device->dev, &dev_attr_idlepct);
device_remove_file(&device->dev, &dev_attr_rrtime);
}
/*
* Query firmware how many CPUs should be idle
* return -1 on failure
*/
static int acpi_pad_pur(acpi_handle handle)
{
struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
union acpi_object *package;
int num = -1;
if (ACPI_FAILURE(acpi_evaluate_object(handle, "_PUR", NULL, &buffer)))
return num;
if (!buffer.length || !buffer.pointer)
return num;
package = buffer.pointer;
if (package->type == ACPI_TYPE_PACKAGE &&
package->package.count == 2 &&
package->package.elements[0].integer.value == 1) /* rev 1 */
num = package->package.elements[1].integer.value;
kfree(buffer.pointer);
return num;
}
/* Notify firmware how many CPUs are idle */
static void acpi_pad_ost(acpi_handle handle, int stat,
uint32_t idle_cpus)
{
union acpi_object params[3] = {
{.type = ACPI_TYPE_INTEGER,},
{.type = ACPI_TYPE_INTEGER,},
{.type = ACPI_TYPE_BUFFER,},
};
struct acpi_object_list arg_list = {3, params};
params[0].integer.value = ACPI_PROCESSOR_AGGREGATOR_NOTIFY;
params[1].integer.value = stat;
params[2].buffer.length = 4;
params[2].buffer.pointer = (void *)&idle_cpus;
acpi_evaluate_object(handle, "_OST", &arg_list, NULL);
}
static void acpi_pad_handle_notify(acpi_handle handle)
{
int num_cpus;
uint32_t idle_cpus;
mutex_lock(&isolated_cpus_lock);
num_cpus = acpi_pad_pur(handle);
if (num_cpus < 0) {
mutex_unlock(&isolated_cpus_lock);
return;
}
acpi_pad_idle_cpus(num_cpus);
idle_cpus = acpi_pad_idle_cpus_num();
acpi_pad_ost(handle, 0, idle_cpus);
mutex_unlock(&isolated_cpus_lock);
}
static void acpi_pad_notify(acpi_handle handle, u32 event,
void *data)
{
struct acpi_device *device = data;
switch (event) {
case ACPI_PROCESSOR_AGGREGATOR_NOTIFY:
acpi_pad_handle_notify(handle);
acpi_bus_generate_proc_event(device, event, 0);
acpi_bus_generate_netlink_event(device->pnp.device_class,
dev_name(&device->dev), event, 0);
break;
default:
pr_warn("Unsupported event [0x%x]\n", event);
break;
}
}
static int acpi_pad_add(struct acpi_device *device)
{
acpi_status status;
strcpy(acpi_device_name(device), ACPI_PROCESSOR_AGGREGATOR_DEVICE_NAME);
strcpy(acpi_device_class(device), ACPI_PROCESSOR_AGGREGATOR_CLASS);
if (acpi_pad_add_sysfs(device))
return -ENODEV;
status = acpi_install_notify_handler(device->handle,
ACPI_DEVICE_NOTIFY, acpi_pad_notify, device);
if (ACPI_FAILURE(status)) {
acpi_pad_remove_sysfs(device);
return -ENODEV;
}
return 0;
}
static int acpi_pad_remove(struct acpi_device *device)
{
mutex_lock(&isolated_cpus_lock);
acpi_pad_idle_cpus(0);
mutex_unlock(&isolated_cpus_lock);
acpi_remove_notify_handler(device->handle,
ACPI_DEVICE_NOTIFY, acpi_pad_notify);
acpi_pad_remove_sysfs(device);
return 0;
}
static const struct acpi_device_id pad_device_ids[] = {
{"ACPI000C", 0},
{"", 0},
};
MODULE_DEVICE_TABLE(acpi, pad_device_ids);
static struct acpi_driver acpi_pad_driver = {
.name = "processor_aggregator",
.class = ACPI_PROCESSOR_AGGREGATOR_CLASS,
.ids = pad_device_ids,
.ops = {
.add = acpi_pad_add,
.remove = acpi_pad_remove,
},
};
static int __init acpi_pad_init(void)
{
power_saving_mwait_init();
if (power_saving_mwait_eax == 0)
return -EINVAL;
return acpi_bus_register_driver(&acpi_pad_driver);
}
static void __exit acpi_pad_exit(void)
{
acpi_bus_unregister_driver(&acpi_pad_driver);
}
module_init(acpi_pad_init);
module_exit(acpi_pad_exit);
MODULE_AUTHOR("Shaohua Li<shaohua.li@intel.com>");
MODULE_DESCRIPTION("ACPI Processor Aggregator Driver");
MODULE_LICENSE("GPL");
|
2c4100b43cb7c25b699f6330719a4c6a9ccd7c16
|
8f3bf2d3f72e9c7022b3e2efde3d787c9ca354fc
|
/src/tss2-fapi/ifapi_profiles.c
|
2dfaa29d4344be18a584e1d0149a65d1a21636f7
|
[
"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
| 21,592
|
c
|
ifapi_profiles.c
|
/* SPDX-License-Identifier: BSD-2-Clause */
/*******************************************************************************
* Copyright 2018-2019, Fraunhofer SIT sponsored by Infineon Technologies AG
* All rights reserved.
*******************************************************************************/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include "tss2_common.h"
#include "ifapi_profiles.h"
#include "tpm_json_deserialize.h"
#include "ifapi_policy_json_deserialize.h"
#include "ifapi_json_deserialize.h"
#include "ifapi_helpers.h"
#define LOGMODULE fapi
#include "util/log.h"
#include "util/aux_util.h"
#include "ifapi_macros.h"
#define PROFILES_EXTENSION ".json"
#define PROFILES_PREFIX "P_"
static TSS2_RC
ifapi_profile_json_deserialize(
json_object *jso,
IFAPI_PROFILE *profile);
static TSS2_RC
ifapi_profile_checkpcrs(const TPML_PCR_SELECTION *pcr_profile);
/** Initialize the profiles information in the context in an asynchronous way
*
* Load the profile information from disk, fill the dictionary of loaded profiles and fill
* the default profile information into the context.
*
* Call ifapi_profiles_initialize_finish to complete the operation.
*
* @param[in,out] profiles The context for the profiles information.
* @param[in,out] io The input/output context being used for file I/O.
* @param[in] profilesdir The directory to load profile information from.
* @param[in] defaultprofile The name of the default profile to use.
* @retval TSS2_RC_SUCCESS on success.
* @retval TSS2_FAPI_RC_BAD_REFERENCE if NULL pointers were passed in.
* @retval TSS2_FAPI_RC_BAD_VALUE if the profilesdir does not exist or is empty.
* @retval TSS2_FAPI_RC_IO_ERROR if creation of log_dir failed or log_dir is not writable.
* @retval TSS2_FAPI_RC_MEMORY if memory allocation failed.
*/
TSS2_RC
ifapi_profiles_initialize_async(
IFAPI_PROFILES *profiles,
IFAPI_IO *io,
const char *profilesdir,
const char *defaultprofile)
{
TSS2_RC r;
char *tmp;
size_t i, j;
check_not_null(profiles);
check_not_null(profilesdir);
memset(profiles, 0, sizeof(*profiles));
profiles->default_name = strdup(defaultprofile);
check_oom(profiles->default_name);
r = ifapi_io_dirfiles(profilesdir, &profiles->filenames, &profiles->num_profiles);
return_if_error(r, "Reading profiles from profiles dir");
profiles->profiles = calloc(profiles->num_profiles, sizeof(profiles->profiles[0]));
check_oom(profiles->profiles);
/* Clean up list of files to only include those that match our filename pattern
Expand the filenames with the directory
Set the names in the dictionary */
for (i = 0; i < profiles->num_profiles; ) {
char *ext = strstr(profiles->filenames[i], PROFILES_EXTENSION);
/* Path the filename with the expected pattern */
if (ext != NULL && strlen(ext) == strlen(PROFILES_EXTENSION) &&
strncmp(profiles->filenames[i], PROFILES_PREFIX, strlen(PROFILES_PREFIX)) == 0)
{
LOG_TRACE("Using file %s in profiles directory", profiles->filenames[i]);
/* Add the profile name */
profiles->profiles[i].name = strndup(profiles->filenames[i],
ext - profiles->filenames[i]);
check_oom(profiles->profiles[i].name);
/* Expand the filename with the directory */
tmp = profiles->filenames[i];
r = ifapi_asprintf(&profiles->filenames[i], "%s/%s", profilesdir, tmp);
return_if_error(r, "Out of memory");
LOG_TRACE("Added profile-entry %s for file %s based on direntry %s",
profiles->profiles[i].name, profiles->filenames[i], tmp);
/* Cleanup and continue */
free(tmp);
i++;
} else {
LOG_TRACE("Skipping file %s in profiles directory", profiles->filenames[i]);
free(profiles->filenames[i]);
profiles->num_profiles -= 1;
for (j = i; j < profiles->num_profiles; j++) {
profiles->filenames[j] = profiles->filenames[j + 1];
}
}
}
if (profiles->num_profiles == 0) {
LOG_ERROR("No files found in profile dir %s that match the pattern %s*%s",
profilesdir, PROFILES_PREFIX, PROFILES_EXTENSION);
return TSS2_FAPI_RC_BAD_VALUE;
}
#ifdef HAVE_REALLOCARRAY
profiles->profiles = reallocarray(profiles->profiles, profiles->num_profiles,
sizeof(profiles->profiles[0]));
profiles->filenames = reallocarray(profiles->filenames, profiles->num_profiles,
sizeof(profiles->filenames[0]));
#else /* HAVE_REALLOCARRAY */
profiles->profiles = realloc(profiles->profiles, profiles->num_profiles *
sizeof(profiles->profiles[0]));
profiles->filenames = realloc(profiles->filenames, profiles->num_profiles *
sizeof(profiles->filenames[0]));
#endif /* HAVE_REALLOCARRAY */
/* No need for OOM checks, since num_profiles may only have become smaller */
r = ifapi_io_read_async(io, profiles->filenames[profiles->profiles_idx]);
return_if_error2(r, "Reading profile %s", profiles->filenames[profiles->profiles_idx]);
return TSS2_RC_SUCCESS;
}
/** Initialize the profiles information in the context in an asynchronous way
*
* Call after ifapi_profiles_initialize_async to complete the operation.
*
* @param[in,out] profiles The context for the profiles information.
* @param[in,out] io The input/output context being used for file I/O.
* @retval TSS2_RC_SUCCESS on success.
* @retval TSS2_FAPI_RC_BAD_REFERENCE if NULL pointers were passed in.
* @retval TSS2_FAPI_RC_BAD_VALUE if a profile could not be loaded.
* @retval TSS2_FAPI_RC_IO_ERROR if creation of log_dir failed or log_dir is not writable.
* @retval TSS2_FAPI_RC_MEMORY if memory allocation failed.
* @retval TSS2_FAPI_RC_TRY_AGAIN if the I/O operation is not finished yet and this function needs
* to be called again.
*/
TSS2_RC
ifapi_profiles_initialize_finish(
IFAPI_PROFILES *profiles,
IFAPI_IO *io)
{
TSS2_RC r;
uint8_t *buffer;
size_t i;
json_object *jso;
check_not_null(profiles);
check_not_null(io);
r = ifapi_io_read_finish(io, &buffer, NULL);
return_if_error(r, "Reading profile failed");
jso = ifapi_parse_json((char *) buffer);
free(buffer);
if (jso == NULL) {
LOG_ERROR("Failed to parse profile %s", profiles->filenames[profiles->profiles_idx]);
r = TSS2_FAPI_RC_BAD_VALUE;
goto error;
}
r = ifapi_profile_json_deserialize(jso,
&profiles->profiles[profiles->profiles_idx].profile);
json_object_put(jso);
goto_if_error2(r, "Parsing profile %s failed", error,
profiles->filenames[profiles->profiles_idx]);
r = ifapi_profile_checkpcrs(&profiles->profiles[profiles->profiles_idx].profile.pcr_selection);
goto_if_error2(r, "Malformed profile pcr selection for profile %s", error,
profiles->filenames[profiles->profiles_idx]);
profiles->profiles_idx += 1;
if (profiles->profiles_idx < profiles->num_profiles) {
r = ifapi_io_read_async(io, profiles->filenames[profiles->profiles_idx]);
goto_if_error2(r, "Reading profile %s", error,
profiles->filenames[profiles->profiles_idx]);
return TSS2_FAPI_RC_TRY_AGAIN;
}
/* Get the data of the default profile into the respective variable */
for (i = 0; i < profiles->num_profiles; i++) {
if (strcmp(profiles->default_name, profiles->profiles[i].name) == 0) {
profiles->default_profile = profiles->profiles[i].profile;
break;
}
}
if (i == profiles->num_profiles) {
LOG_ERROR("Default profile %s not in the list of loaded profiles",
profiles->default_name);
r = TSS2_FAPI_RC_BAD_VALUE;
goto error;
}
for (i = 0; i < profiles->num_profiles; i++) {
free(profiles->filenames[i]);
}
SAFE_FREE(profiles->filenames);
return TSS2_RC_SUCCESS;
error:
for (i = 0; i < profiles->num_profiles; i++) {
SAFE_FREE(profiles->filenames[i]);
}
SAFE_FREE(profiles->filenames);
ifapi_profiles_finalize(profiles);
return r;
}
/** Return the profile data for a given profile name.
*
* Returns a (const, not to be free'd) pointer to the profile data for a requested profile.
* If a NULL profile is requesten, then the default profile is returned.
* If a keypath is passed in, then the prefix is analysed. If that keypath starts with a profile
* then this profile is returned. Otherwise the default profile is returned.
*
* @param[in] profiles The profiles context
* @param[in] name The name of the profile or the keypath
* @param[out] profile The pointer to the profile data.
* @retval TSS2_RC_SUCCESS on success.
* @retval TSS2_FAPI_RC_BAD_REFERENCE if NULL pointers were passed in.
* @retval TSS2_FAPI_RC_BAD_VALUE if a profile is not found.
*/
TSS2_RC
ifapi_profiles_get(
const IFAPI_PROFILES *profiles,
const char *name,
const IFAPI_PROFILE **profile)
{
check_not_null(profiles);
check_not_null(name);
check_not_null(profile);
char *split;
size_t len;
/* if no name or nor profile prefix is given, use the default profile */
if (!name || !(strncmp(name, "P_", 2) == 0 || strncmp(name, "/P_", 3) == 0)) {
*profile = &profiles->default_profile;
return TSS2_RC_SUCCESS;
}
/* Search for path delimiter */
split = strchr(name, IFAPI_FILE_DELIM_CHAR);
/* If the path beging with delimiters, skip over those */
if (name == split) {
name += 1;
split = strchr(name, IFAPI_FILE_DELIM_CHAR);
}
if (split == NULL)
len = strlen(name);
else
len = split - name;
for (size_t i = 0; i < profiles->num_profiles; i++) {
if (len == strlen(profiles->profiles[i].name) &&
strncmp(name, profiles->profiles[i].name, len) == 0) {
*profile = &profiles->profiles[i].profile;
return TSS2_RC_SUCCESS;
}
}
LOG_ERROR("Profile %s not in the list of loaded profiles", name);
return TSS2_FAPI_RC_BAD_VALUE;
}
/** Sanitizes and frees internal data structures of loaded profiles' information.
*
* @param[in,out] profiles The context for the profiles information.
*/
void
ifapi_profiles_finalize(
IFAPI_PROFILES *profiles)
{
size_t i;
if (!profiles) {
LOG_ERROR("Called with bad reference");
return;
}
SAFE_FREE(profiles->default_name);
for (i = 0; i < profiles->num_profiles; i++) {
IFAPI_PROFILE_ENTRY * entry = &profiles->profiles[i];
SAFE_FREE(profiles->profiles[i].name);
IFAPI_PROFILE * profile = &entry->profile;
SAFE_FREE(profile->srk_template);
SAFE_FREE(profile->ek_template);
SAFE_FREE(profile->srk_description);
SAFE_FREE(profile->ek_description);
ifapi_cleanup_policy(profile->eh_policy);
SAFE_FREE(profile->eh_policy);
ifapi_cleanup_policy(profile->ek_policy);
SAFE_FREE(profile->ek_policy);
ifapi_cleanup_policy(profile->sh_policy);
SAFE_FREE(profile->sh_policy);
}
SAFE_FREE(profiles->profiles);
memset(profiles, 0, sizeof(*profiles));
}
/** Deserialize a IFAPI_KEY_PROFILE json object.
*
* @param[in] jso the json object to be deserialized.
* @param[out] out the deserialzed binary object.
* @retval TSS2_RC_SUCCESS if the function call was a success.
* @retval TSS2_FAPI_RC_BAD_VALUE if the json object can't be deserialized.
* @retval TSS2_FAPI_RC_BAD_REFERENCE a invalid null pointer is passed.
* @retval TSS2_FAPI_RC_IO_ERROR if an error occurred while accessing the
* object store.
* @retval TSS2_FAPI_RC_MEMORY if not enough memory can be allocated.
*/
static TSS2_RC
ifapi_profile_json_deserialize(
json_object *jso,
IFAPI_PROFILE *out)
{
json_object *jso2;
TSS2_RC r;
const TPMT_SYM_DEF session_symmetric_default = {
.algorithm = TPM2_ALG_AES,
.keyBits = {.aes = 128},
.mode = {.aes = TPM2_ALG_CFB}
};
LOG_TRACE("call");
memset(out, 0, sizeof(IFAPI_PROFILE));
return_if_null(out, "Bad reference.", TSS2_FAPI_RC_BAD_REFERENCE);
if (!ifapi_get_sub_object(jso, "type", &jso2)) {
LOG_ERROR("Field \"type\" not found.");
return TSS2_FAPI_RC_BAD_VALUE;
}
r = ifapi_json_TPMI_ALG_PUBLIC_deserialize(jso2, &out->type);
return_if_error(r, "Bad value for field \"type\".");
if (!ifapi_get_sub_object(jso, "srk_template", &jso2)) {
LOG_ERROR("Field \"srk_template\" not found.");
return TSS2_FAPI_RC_BAD_VALUE;
}
out->srk_template = strdup(json_object_get_string(jso2));
return_if_null(out->srk_template, "Out of memory.", TSS2_FAPI_RC_MEMORY);
if (!ifapi_get_sub_object(jso, "srk_description", &jso2)) {
out->srk_description = NULL;
} else {
out->srk_description = strdup(json_object_get_string(jso2));
return_if_null(out->srk_description, "Out of memory.", TSS2_FAPI_RC_MEMORY);
}
if (!ifapi_get_sub_object(jso, "ek_template", &jso2)) {
LOG_ERROR("Field \"ek_template\" not found.");
return TSS2_FAPI_RC_BAD_VALUE;
}
out->ek_template = strdup(json_object_get_string(jso2));
return_if_null(out->ek_template, "Out of memory.", TSS2_FAPI_RC_MEMORY);
if (!ifapi_get_sub_object(jso, "ek_description", &jso2)) {
out->ek_description = NULL;
} else {
out->ek_description = strdup(json_object_get_string(jso2));
return_if_null(out->ek_description, "Out of memory.", TSS2_FAPI_RC_MEMORY);
}
if (!ifapi_get_sub_object(jso, "ecc_signing_scheme", &jso2)) {
memset(&out->ecc_signing_scheme, 0, sizeof(TPMT_SIG_SCHEME));
} else {
r = ifapi_json_TPMT_SIG_SCHEME_deserialize(jso2, &out->ecc_signing_scheme);
return_if_error(r, "Bad value for field \"ecc_signing_scheme\".");
}
if (!ifapi_get_sub_object(jso, "rsa_signing_scheme", &jso2)) {
memset(&out->rsa_signing_scheme, 0, sizeof(TPMT_SIG_SCHEME));
} else {
r = ifapi_json_TPMT_SIG_SCHEME_deserialize(jso2, &out->rsa_signing_scheme);
return_if_error(r, "Bad value for field \"rsa_signing_scheme\".");
}
if (!ifapi_get_sub_object(jso, "rsa_decrypt_scheme", &jso2)) {
memset(&out->rsa_decrypt_scheme, 0, sizeof(TPMT_RSA_DECRYPT));
} else {
r = ifapi_json_TPMT_RSA_DECRYPT_deserialize(jso2, &out->rsa_decrypt_scheme);
return_if_error(r, "Bad value for field \"rsa_decrypt_scheme\".");
}
if (!ifapi_get_sub_object(jso, "sym_mode", &jso2)) {
LOG_ERROR("Field \"sym_mode\" not found.");
return TSS2_FAPI_RC_BAD_VALUE;
}
r = ifapi_json_TPMI_ALG_CIPHER_MODE_deserialize(jso2, &out->sym_mode);
return_if_error(r, "Bad value for field \"sym_mode\".");
if (!ifapi_get_sub_object(jso, "sym_parameters", &jso2)) {
LOG_ERROR("Field \"sym_parameters\" not found.");
return TSS2_FAPI_RC_BAD_VALUE;
}
r = ifapi_json_TPMT_SYM_DEF_OBJECT_deserialize(jso2, &out->sym_parameters);
return_if_error(r, "Bad value for field \"sym_parameters\".");
if (!ifapi_get_sub_object(jso, "sym_block_size", &jso2)) {
LOG_ERROR("Field \"sym_block_size\" not found.");
return TSS2_FAPI_RC_BAD_VALUE;
}
r = ifapi_json_UINT16_deserialize(jso2, &out->sym_block_size);
return_if_error(r, "Bad value for field \"sym_block_size\".");
if (!ifapi_get_sub_object(jso, "pcr_selection", &jso2)) {
LOG_ERROR("Field \"pcr_selection\" not found.");
return TSS2_FAPI_RC_BAD_VALUE;
}
r = ifapi_json_TPML_PCR_SELECTION_deserialize(jso2, &out->pcr_selection);
return_if_error(r, "Bad value for field \"pcr_selection\".");
if (!ifapi_get_sub_object(jso, "nameAlg", &jso2)) {
LOG_ERROR("Field \"nameAlg\" not found.");
return TSS2_FAPI_RC_BAD_VALUE;
}
r = ifapi_json_TPMI_ALG_HASH_deserialize(jso2, &out->nameAlg);
return_if_error(r, "Bad value for field \"nameAlg\".");
if (out->type == TPM2_ALG_RSA) {
if (!ifapi_get_sub_object(jso, "exponent", &jso2)) {
LOG_ERROR("Field \"exponent\" not found.");
return TSS2_FAPI_RC_BAD_VALUE;
}
r = ifapi_json_UINT32_deserialize(jso2, &out->exponent);
return_if_error(r, "Bad value for field \"exponent\".");
if (!ifapi_get_sub_object(jso, "keyBits", &jso2)) {
LOG_ERROR("Field \"keyBits\" not found.");
return TSS2_FAPI_RC_BAD_VALUE;
}
r = ifapi_json_TPMI_RSA_KEY_BITS_deserialize(jso2, &out->keyBits);
return_if_error(r, "Bad value for field \"keyBits\".");
} else if (out->type == TPM2_ALG_ECC) {
if (!ifapi_get_sub_object(jso, "curveID", &jso2)) {
LOG_ERROR("Field \"curveID\" not found.");
return TSS2_FAPI_RC_BAD_VALUE;
}
r = ifapi_json_TPMI_ECC_CURVE_deserialize(jso2, &out->curveID);
return_if_error(r, "Bad value for field \"curveID\".");
}
if (!ifapi_get_sub_object(jso, "session_symmetric", &jso2)) {
out->session_symmetric = session_symmetric_default;
} else {
r = ifapi_json_TPMT_SYM_DEF_deserialize(jso2, &out->session_symmetric);
return_if_error(r, "Bad value for field \"session_symmetric\".");
}
if (ifapi_get_sub_object(jso, "eh_policy", &jso2)) {
out->eh_policy = calloc(1, sizeof(TPMS_POLICY));
goto_if_null2(out->eh_policy, "Out of memory.", r, TSS2_FAPI_RC_MEMORY,
cleanup);
r = ifapi_json_TPMS_POLICY_deserialize(jso2, out->eh_policy);
goto_if_error(r, "Deserialize policy.", cleanup);
}
if (ifapi_get_sub_object(jso, "sh_policy", &jso2)) {
out->sh_policy = calloc(1, sizeof(TPMS_POLICY));
goto_if_null2(out->sh_policy, "Out of memory.", r, TSS2_FAPI_RC_MEMORY,
cleanup);
r = ifapi_json_TPMS_POLICY_deserialize(jso2, out->sh_policy);
goto_if_error(r, "Deserialize policy.", cleanup);
}
if (ifapi_get_sub_object(jso, "ek_policy", &jso2)) {
out->ek_policy = calloc(1, sizeof(TPMS_POLICY));
goto_if_null2(out->ek_policy, "Out of memory.", r, TSS2_FAPI_RC_MEMORY,
cleanup);
r = ifapi_json_TPMS_POLICY_deserialize(jso2, out->ek_policy);
goto_if_error(r, "Deserialize policy.", cleanup);
}
if (ifapi_get_sub_object(jso, "srk_policy", &jso2)) {
out->srk_policy = calloc(1, sizeof(TPMS_POLICY));
goto_if_null2(out->srk_policy, "Out of memory.", r, TSS2_FAPI_RC_MEMORY,
cleanup);
r = ifapi_json_TPMS_POLICY_deserialize(jso2, out->srk_policy);
goto_if_error(r, "Deserialize policy.", cleanup);
}
if (ifapi_get_sub_object(jso, "lockout_policy", &jso2)) {
out->lockout_policy = calloc(1, sizeof(TPMS_POLICY));
goto_if_null2(out->lockout_policy, "Out of memory.", r, TSS2_FAPI_RC_MEMORY,
cleanup);
r = ifapi_json_TPMS_POLICY_deserialize(jso2, out->lockout_policy);
goto_if_error(r, "Deserialize policy.", cleanup);
}
if (!ifapi_get_sub_object(jso, "newMaxTries", &jso2)) {
out->newMaxTries = 5;
} else {
r = ifapi_json_UINT32_deserialize(jso2, &out->newMaxTries);
return_if_error(r, "Bad value for field \"newMaxTries\".");
}
if (!ifapi_get_sub_object(jso, "newRecoveryTime", &jso2)) {
out->newRecoveryTime = 1000;
} else {
r = ifapi_json_UINT32_deserialize(jso2, &out->newRecoveryTime);
return_if_error(r, "Bad value for field \"newRecoveryTime\".");
}
if (!ifapi_get_sub_object(jso, "lockoutRecovery", &jso2)) {
out->lockoutRecovery = 1000;
} else {
r = ifapi_json_UINT32_deserialize(jso2, &out->lockoutRecovery);
return_if_error(r, "Bad value for field \"lockoutRecovery\".");
}
if (ifapi_get_sub_object(jso, "ignore_ek_template", &jso2)) {
r = ifapi_json_TPMI_YES_NO_deserialize(jso2, &out->ignore_ek_template);
return_if_error(r, "Bad value for field \"ignore_ek_template\".");
} else {
out->ignore_ek_template = TPM2_NO;
}
LOG_TRACE("true");
return TSS2_RC_SUCCESS;
cleanup:
SAFE_FREE(out->eh_policy);
return r;
}
/**
* Check whether PCRs with muliple banks are defined in profile.
*
* This case is not allowed by FAPI.
*/
static TSS2_RC
ifapi_profile_checkpcrs(const TPML_PCR_SELECTION *pcr_profile)
{
size_t i, j, byte_idx;
for (i = 0; i < pcr_profile->count - 1; i++) {
for (j = i + 1; j < pcr_profile->count; j++) {
for (byte_idx = 0; byte_idx < 3; byte_idx++) {
/* Check whether a PCR register flag does occur in two different banks. */
if (pcr_profile->pcrSelections[i].pcrSelect[byte_idx] &
pcr_profile->pcrSelections[j].pcrSelect[byte_idx]) {
return_error2(TSS2_FAPI_RC_BAD_VALUE,
"More than one bank selected for a PCR register.");
}
}
}
}
return TSS2_RC_SUCCESS;
}
|
5170131fb0efefac6e798ae8a1599b433ede7bfa
|
1231e1bf4117cfaaa54bd4752cca1bdb71290cec
|
/ext/stub/constructors/issue1803.zep.c
|
b16eecc55e2128e62fe09eadb55dedcc331827dc
|
[
"MIT"
] |
permissive
|
zephir-lang/zephir
|
ac53ec68e35d19860a4d80224d94f38a6a5e04b5
|
6773f19d9b272cafee96b9a30f9b152c28e982ea
|
refs/heads/development
| 2023-08-31T10:33:38.621586
| 2023-02-28T10:27:43
| 2023-02-28T10:27:43
| 11,478,636
| 291
| 47
|
MIT
| 2023-08-28T22:07:11
| 2013-07-17T14:49:27
|
PHP
|
UTF-8
|
C
| false
| true
| 1,082
|
c
|
issue1803.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/object.h"
#include "kernel/memory.h"
/**
* @issue https://github.com/zephir-lang/zephir/issues/1803
*/
ZEPHIR_INIT_CLASS(Stub_Constructors_Issue1803)
{
ZEPHIR_REGISTER_CLASS(Stub\\Constructors, Issue1803, stub, constructors_issue1803, stub_constructors_issue1803_method_entry, 0);
zend_declare_property_string(stub_constructors_issue1803_ce, SL("value"), "Original value", ZEND_ACC_PUBLIC);
return SUCCESS;
}
PHP_METHOD(Stub_Constructors_Issue1803, Issue1803)
{
zval _0;
zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL;
zval *this_ptr = getThis();
ZVAL_UNDEF(&_0);
ZEPHIR_MM_GROW();
ZEPHIR_INIT_VAR(&_0);
ZEPHIR_INIT_NVAR(&_0);
ZVAL_STRING(&_0, "Value that won't be updated on class init");
zephir_update_property_zval(this_ptr, ZEND_STRL("value"), &_0);
ZEPHIR_MM_RESTORE();
}
|
590df59081bcf74b5c9419e455be789ea57f3014
|
5ab69c8644a936a3d9dec1669a86c7369c911bf8
|
/os/lib/queue.h
|
4ca80495b1b19bd8b002077997a8fba59fd2c13e
|
[
"BSD-3-Clause"
] |
permissive
|
contiki-ng/contiki-ng
|
393d36f68b98f5ee3544ea32502cf662ffb2fe9f
|
31fcaadf7a0dc8ceea07f438cd69db73174879e6
|
refs/heads/develop
| 2023-09-01T20:10:30.000765
| 2023-09-01T14:37:12
| 2023-09-01T14:37:12
| 91,191,972
| 1,242
| 788
|
BSD-3-Clause
| 2023-09-14T19:08:35
| 2017-05-13T17:37:59
|
C
|
UTF-8
|
C
| false
| false
| 5,102
|
h
|
queue.h
|
/*
* Copyright (c) 2017, George Oikonomou - http://www.spd.gr
* Copyright (c) 2017, James Pope
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*---------------------------------------------------------------------------*/
/**
* \addtogroup data
* @{
*
* \defgroup queue Queue library
*
* This library provides functions for the creation and manipulation of
* queues. The library is implemented as a wrapper around the list library.
*
* A queue is declared using the QUEUE macro. Queue elements must be
* allocated by the calling code and must be of a C struct datatype. In this
* struct, the first field must be a pointer called \e next. This field will
* be used by the library to maintain the queue. Application code must not
* modify this field directly.
*
* This library is not safe to be used within an interrupt context.
* @{
*/
/*---------------------------------------------------------------------------*/
#ifndef QUEUE_H_
#define QUEUE_H_
/*---------------------------------------------------------------------------*/
#include "contiki.h"
#include "lib/list.h"
#include <stdbool.h>
/*---------------------------------------------------------------------------*/
/**
* \brief The queue data type
*/
typedef list_t queue_t;
/*---------------------------------------------------------------------------*/
/**
* \brief Define a queue.
*
* This macro defines a queue.
*
* The datatype for elements must be a C struct. The struct's first member must
* be a pointer called \e next. This is used internally by the library to
* maintain data structure integrity and must not be modified directly by
* application code.
*
* \param name The name of the queue.
*/
#define QUEUE(name) LIST(name)
/*---------------------------------------------------------------------------*/
struct queue {
struct queue *next;
};
/*---------------------------------------------------------------------------*/
/**
* \brief Initialise a queue
* \param queue The queue
*/
static inline void
queue_init(queue_t queue)
{
list_init(queue);
}
/*---------------------------------------------------------------------------*/
/**
* \brief Adds an element to the tail of the queue
* \param queue The queue
* \param element A pointer to the element to be added
*/
static inline void
queue_enqueue(queue_t queue, void *element)
{
list_add(queue, element);
}
/*---------------------------------------------------------------------------*/
/**
* \brief Removes the element at the front of the queue
* \param queue The queue
* \return A pointer to the element removed
*
* If this function returns NULL if the queue was empty (queue underflow)
*/
static inline void *
queue_dequeue(queue_t queue)
{
return list_pop(queue);
}
/*---------------------------------------------------------------------------*/
/**
* \brief Returns the front element of the queue, without removing it
* \param queue The queue
* \return A pointer to the element at the front of the queue
*/
static inline void *
queue_peek(queue_t queue)
{
return list_head(queue);
}
/*---------------------------------------------------------------------------*/
/**
* \brief Check if a queue is empty
* \param queue The queue
* \retval true The queue is empty
* \retval false The queue has at least one element
*/
static inline bool
queue_is_empty(queue_t queue)
{
return *queue == NULL ? true : false;
}
/*---------------------------------------------------------------------------*/
#endif /* QUEUE_H_ */
/*---------------------------------------------------------------------------*/
/**
* @}
* @}
*/
|
ddc3cf32ffc8f760435bef4410cb18282692bbcc
|
79d343002bb63a44f8ab0dbac0c9f4ec54078c3a
|
/lib/libc/wasi/libc-top-half/musl/src/math/atanh.c
|
63a035d7063ae2d5df2c31728e10e5d471209c79
|
[
"MIT",
"LLVM-exception",
"Apache-2.0",
"NCSA",
"BSD-2-Clause",
"BSD-3-Clause",
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-other-permissive",
"LicenseRef-scancode-musl-exception"
] |
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
| 577
|
c
|
atanh.c
|
#include "libm.h"
/* atanh(x) = log((1+x)/(1-x))/2 = log1p(2x/(1-x))/2 ~= x + x^3/3 + o(x^5) */
double atanh(double x)
{
union {double f; uint64_t i;} u = {.f = x};
unsigned e = u.i >> 52 & 0x7ff;
unsigned s = u.i >> 63;
double_t y;
/* |x| */
u.i &= (uint64_t)-1/2;
y = u.f;
if (e < 0x3ff - 1) {
if (e < 0x3ff - 32) {
/* handle underflow */
if (e == 0)
FORCE_EVAL((float)y);
} else {
/* |x| < 0.5, up to 1.7ulp error */
y = 0.5*log1p(2*y + 2*y*y/(1-y));
}
} else {
/* avoid overflow */
y = 0.5*log1p(2*(y/(1-y)));
}
return s ? -y : y;
}
|
6644dda89b01133cf4f72626fdd304285a446dce
|
10a8580aa44d33b7458429023c00de8c01ceda98
|
/agent/tests/test_zval.c
|
630cdd2587ccd262b14bff0a216192615b68d95f
|
[
"LicenseRef-scancode-unknown-license-reference",
"Apache-2.0"
] |
permissive
|
newrelic/newrelic-php-agent
|
87ad20e0a5abf0d2855e7d27a25c36454ae4389a
|
dfb359f0dbb53e4cbc5106b52c8f3807c7fc8d42
|
refs/heads/main
| 2023-08-15T10:28:24.372352
| 2023-08-14T17:29:31
| 2023-08-14T17:29:31
| 302,112,572
| 116
| 67
|
Apache-2.0
| 2023-09-13T18:33:47
| 2020-10-07T17:35:01
|
C
|
UTF-8
|
C
| false
| false
| 3,700
|
c
|
test_zval.c
|
/*
* Copyright 2020 New Relic Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/
#include "tlib_php.h"
#include "php_agent.h"
#include "php_zval.h"
tlib_parallel_info_t parallel_info
= {.suggested_nthreads = -1, .state_size = 0};
static void test_valid_callable(const char* expr TSRMLS_DC) {
zval* zv = tlib_php_request_eval_expr(expr TSRMLS_CC);
tlib_fail_if_int_equal(expr, 0, nr_php_is_zval_valid_callable(zv TSRMLS_CC));
nr_php_zval_free(&zv);
}
static void test_is_zval_null(TSRMLS_D) {
zval* value = NULL;
zval* helper = NULL;
tlib_php_request_start();
tlib_php_request_eval(
"class NewrelicTestZvalHelper { "
" public $foo; "
" public function getExplicitNull() { "
" $value = null;"
" return $value;"
" } "
" public function getUndefinedNull() { "
" return @$value; "
" } "
" public function getDefined() { "
" $value = 'foo';"
" return $value; "
" } "
" public function getNeverDefinedObjectProperty() { "
" return $this->foo; "
" } "
"} " TSRMLS_CC);
helper = tlib_php_request_eval_expr("new \\NewrelicTestZvalHelper" TSRMLS_CC);
value = nr_php_call(helper, "getDefined");
tlib_pass_if_false("Testing with Defined Value", nr_php_is_zval_null(value),
"Expected false, returned true");
nr_php_zval_free(&value);
value = nr_php_call(helper, "getExplicitNull");
tlib_pass_if_true("Testing with Explicit NULL", nr_php_is_zval_null(value),
"Expected true, returned false");
nr_php_zval_free(&value);
value = nr_php_call(helper, "getUndefinedNull");
tlib_pass_if_true("Testing with Undefined Value", nr_php_is_zval_null(value),
"Expected true, returned false");
nr_php_zval_free(&value);
value = nr_php_call(helper, "getNeverDefinedObjectProperty");
tlib_pass_if_true("Testing with Undefined Object Property",
nr_php_is_zval_null(value),
"Expected true, returned false");
nr_php_zval_free(&value);
nr_php_zval_free(&helper);
tlib_php_request_end();
}
static void test_is_zval_valid_callable(TSRMLS_D) {
size_t i;
zval** invalid_zvals;
tlib_php_request_start();
tlib_pass_if_int_equal("NULL zval", 0,
nr_php_is_zval_valid_callable(NULL TSRMLS_CC));
invalid_zvals = tlib_php_zvals_of_all_types(TSRMLS_C);
for (i = 0; invalid_zvals[i]; i++) {
tlib_pass_if_int_equal(
"non-callable zval", 0,
nr_php_is_zval_valid_callable(invalid_zvals[i] TSRMLS_CC));
}
tlib_php_free_zval_array(&invalid_zvals);
test_valid_callable("'date'" TSRMLS_CC);
test_valid_callable(
"array(new ReflectionFunction('date'), 'isDisabled')" TSRMLS_CC);
#ifdef PHP8
test_valid_callable("array('ReflectionReference', 'fromArrayElement')" TSRMLS_CC);
test_valid_callable("'ReflectionReference::fromArrayElement'" TSRMLS_CC);
#else
test_valid_callable("array('ReflectionFunction', 'export')" TSRMLS_CC);
test_valid_callable("'ReflectionFunction::export'" TSRMLS_CC);
#endif
test_valid_callable("function () {}" TSRMLS_CC);
#if ZEND_MODULE_API_NO >= ZEND_7_0_X_API_NO /* PHP 7.0+ */
test_valid_callable("new class { function __invoke() {} }" TSRMLS_CC);
#endif /* PHP 7.0+ */
tlib_php_request_end();
}
void test_main(void* p NRUNUSED) {
#if defined(ZTS) && !defined(PHP7)
void*** tsrm_ls = NULL;
#endif /* ZTS && !PHP7 */
tlib_php_engine_create("" PTSRMLS_CC);
test_is_zval_valid_callable(TSRMLS_C);
test_is_zval_null(TSRMLS_C);
tlib_php_engine_destroy(TSRMLS_C);
}
|
f7fbc93029f148c2e9394f2b2880df6ca4750c69
|
167c6226bc77c5daaedab007dfdad4377f588ef4
|
/cpp/ql/test/library-tests/builtins/functions_file/test.c
|
a73061e4eaba8b1767662e7403a0c83606bbdaaa
|
[
"LicenseRef-scancode-public-domain",
"MIT"
] |
permissive
|
github/codeql
|
1eebb449a34f774db9e881b52cb8f7a1b1a53612
|
d109637e2d7ab3b819812eb960c05cb31d9d2168
|
refs/heads/main
| 2023-08-20T11:32:39.162059
| 2023-08-18T14:33:32
| 2023-08-18T14:33:32
| 143,040,428
| 5,987
| 1,363
|
MIT
| 2023-09-14T19:36:50
| 2018-07-31T16:35:51
|
CodeQL
|
UTF-8
|
C
| false
| false
| 701
|
c
|
test.c
|
long f(int a, int b, int c) {
// A builtin from the builtin_functions_file.
int i1 = __builtin_foobar(a);
// A builtin that's not in the file, but the extractor should handle, given the
// --gnu_version flag we pass in.
int i2;
__builtin_add_overflow(a, b, &i2);
// A builtin that would normally be defined by the extractor with a type
// expecting it to be called like this:
//void* x = __builtin_malloc(a);
// But we override the type in the builtin_functions_file so it's called like
// this:
float f1, f2;
f1 = __builtin_malloc(a, b, c, &f2);
return 42;
}
// semmle-extractor-options: --gnu_version 50100 --edg --builtin_functions_file --edg ${testdir}/builtins.txt
|
103cee4674c944236990df332903bcfd1c31ca50
|
2c052c996d4267623276a681308bf87ea7388f60
|
/test/runtime/netsock.c
|
f30df6f99b6bfb8e0c066f1b4b98c5260519d505
|
[
"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
| 31,517
|
c
|
netsock.c
|
#define _GNU_SOURCE
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <net/if.h>
#include <poll.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <unistd.h>
#include <errno.h>
#include <sys/epoll.h>
#include <runtime.h>
#define FAULT_ADDR ((void *)0xBADF0000)
#define NETSOCK_TEST_BASIC_PORT 1233
#define NETSOCK_TEST_FAULT_PORT 1237
#define NETSOCK_TEST_FIO_COUNT 8
#define NETSOCK_TEST_PEEK_COUNT 8
#define test_assert(expr) do { \
if (!(expr)) { \
printf("Error: %s -- failed at %s:%d\n", #expr, __FILE__, __LINE__); \
exit(EXIT_FAILURE); \
} \
} while (0)
static inline void timespec_sub(struct timespec *a, struct timespec *b, struct timespec *r)
{
r->tv_sec = a->tv_sec - b->tv_sec;
r->tv_nsec = a->tv_nsec - b->tv_nsec;
if (a->tv_nsec < b->tv_nsec) {
r->tv_sec--;
r->tv_nsec += 1000000000ull;
}
}
static void *netsock_test_basic_thread(void *arg)
{
int sock_type = (long)arg;
int fd;
struct sockaddr_in addr;
uint8_t rx_buf[8 * KB];
int rx;
fd = socket(AF_INET, sock_type, 0);
test_assert(fd > 0);
addr.sin_family = AF_INET;
addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
addr.sin_port = htons(NETSOCK_TEST_BASIC_PORT);
test_assert(connect(fd, (struct sockaddr *)&addr, sizeof(addr)) == 0);
do {
rx = read(fd, rx_buf, sizeof(rx_buf));
test_assert(rx >= 0);
} while (rx > 0);
test_assert(close(fd) == 0);
if (sock_type == SOCK_STREAM) {
/* Create a new connection to the server, to test resource deallocation for the new
* connection when the server socket is closed without an accept() call. */
fd = socket(AF_INET, sock_type, 0);
test_assert(fd > 0);
test_assert(connect(fd, (struct sockaddr *)&addr, sizeof(addr)) == 0);
test_assert(close(fd) == 0);
}
return NULL;
}
static inline void netsock_toggle_and_check_sockopt(int fd, int level, int optname, int val)
{
int v;
socklen_t len = sizeof(v);
test_assert(getsockopt(fd, level, optname, &v, &len) == 0 && v == !val);
v = val;
test_assert(setsockopt(fd, level, optname, &v, len) == 0);
test_assert(getsockopt(fd, level, optname, &v, &len) == 0 && v == val);
}
static void netsock_test_basic(int sock_type)
{
int fd, tx_fd;
struct pollfd pfd;
struct sockaddr_in addr;
socklen_t addr_len;
pthread_t pt;
int ret;
struct timespec start, end, elapsed;
const int tx_total = 8 * MB;
uint8_t tx_buf[32 * KB];
int tx = 0;
unsigned long long ns;
fd = socket(AF_INET, sock_type, 0);
test_assert(fd > 0);
pfd.fd = fd;
pfd.events = POLLIN | POLLOUT;
ret = poll(&pfd, 1, -1);
test_assert(ret == 1);
test_assert(pfd.revents == ((sock_type == SOCK_STREAM) ? (POLLHUP | POLLOUT) : POLLOUT));
addr.sin_family = AF_INET;
addr.sin_addr.s_addr = htonl(INADDR_ANY);
addr.sin_port = htons(NETSOCK_TEST_BASIC_PORT);
test_assert(bind(fd, (struct sockaddr *)&addr, sizeof(addr)) == 0);
if (sock_type == SOCK_STREAM) {
int val;
socklen_t len = sizeof(val);
test_assert(getsockopt(fd, SOL_SOCKET, SO_ACCEPTCONN, &val, &len) == 0 && val == 0);
netsock_toggle_and_check_sockopt(fd, SOL_SOCKET, SO_REUSEADDR, 1);
netsock_toggle_and_check_sockopt(fd, SOL_SOCKET, SO_KEEPALIVE, 1);
test_assert(listen(fd, 1) == 0);
test_assert(listen(fd, 1) == 0); /* test listen() call on already listening socket */
test_assert(getsockopt(fd, SOL_SOCKET, SO_ACCEPTCONN, &val, &len) == 0 && val == 1);
ret = pthread_create(&pt, NULL, netsock_test_basic_thread, (void *)(long)sock_type);
test_assert(ret == 0);
/* Change a TCP option on the listening socket and verify that the option is inherited by
* the accepted socket. */
netsock_toggle_and_check_sockopt(fd, IPPROTO_TCP, TCP_NODELAY, 1);
tx_fd = accept(fd, NULL, NULL);
test_assert(tx_fd > 0);
test_assert(getsockopt(tx_fd, IPPROTO_TCP, TCP_NODELAY, &val, &len) == 0 && val == 1);
/* Also validate that SO_REUSEADDR and SO_KEEPALIVE are inherited. Linux follows this
* behavior, and it is explicitly supported by lwIP (see SOF_INHERITED). */
test_assert(getsockopt(tx_fd, SOL_SOCKET, SO_REUSEADDR, &val, &len) == 0 && val == 1);
test_assert(getsockopt(tx_fd, SOL_SOCKET, SO_KEEPALIVE, &val, &len) == 0 && val == 1);
val = 0;
test_assert(setsockopt(tx_fd, IPPROTO_TCP, TCP_NODELAY, &val, len) == 0);
test_assert(getsockopt(tx_fd, SOL_SOCKET, SO_ACCEPTCONN, &val, &len) == 0 && val == 0);
test_assert(getsockopt(tx_fd, IPPROTO_TCP, TCP_MAXSEG, &val, &len) == 0 && val > 0);
} else {
netsock_toggle_and_check_sockopt(fd, SOL_SOCKET, SO_BROADCAST, 1);
netsock_toggle_and_check_sockopt(fd, SOL_SOCKET, SO_BROADCAST, 0);
tx_fd = fd;
/* Test that writing to an unconnected datagram socket gives an error. */
test_assert(write(tx_fd, &ret, sizeof(ret)) < 0 && errno == EDESTADDRREQ);
test_assert(connect(tx_fd, (struct sockaddr *)&addr, sizeof(addr)) == 0);
}
addr_len = sizeof(addr);
test_assert((getpeername(tx_fd, FAULT_ADDR, &addr_len) == -1) && (errno == EFAULT));
test_assert((getpeername(tx_fd, &addr, FAULT_ADDR) == -1) && (errno == EFAULT));
test_assert((write(tx_fd, FAULT_ADDR, sizeof(tx_buf)) == -1) && (errno == EFAULT));
test_assert((recv(tx_fd, tx_buf, sizeof(tx_buf), MSG_DONTWAIT) == -1) && (errno == EAGAIN));
test_assert(clock_gettime(CLOCK_MONOTONIC, &start) == 0);
do {
ret = write(tx_fd, tx_buf, sizeof(tx_buf));
test_assert(ret > 0);
tx += ret;
} while (tx < tx_total);
test_assert(clock_gettime(CLOCK_MONOTONIC, &end) == 0);
timespec_sub(&end, &start, &elapsed);
ns = elapsed.tv_sec * 1000000000ull + elapsed.tv_nsec;
printf("%s(%d): transmitted %d bytes in %ld.%.9ld seconds (%lld KB/s)\n", __func__, sock_type,
tx_total, elapsed.tv_sec, elapsed.tv_nsec, (1000000000ull / KB) * tx_total / ns);
test_assert(close(tx_fd) == 0);
if (sock_type == SOCK_STREAM) {
test_assert(pthread_join(pt, NULL) == 0);
/* close() should clean up a pending connection that has not been accept()ed */
test_assert(close(fd) == 0);
}
}
static void *netsock_test_fionread_thread(void *arg)
{
int port = (long)arg;
int fd;
struct sockaddr_in addr;
uint8_t buf[NETSOCK_TEST_FIO_COUNT];
fd = socket(AF_INET, SOCK_STREAM, 0);
test_assert(fd > 0);
addr.sin_family = AF_INET;
addr.sin_port = htons(port);
addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
test_assert(connect(fd, (struct sockaddr *)&addr, sizeof(addr)) == 0);
test_assert(write(fd, buf, sizeof(buf)) == sizeof(buf));
return (void *)(long)fd;
}
static void netsock_test_fionread(void)
{
int fd, conn_fd;
int nbytes;
struct sockaddr_in addr;
const int port = 1234;
pthread_t pt;
int ret;
void *thread_ret;
uint8_t buf[NETSOCK_TEST_FIO_COUNT];
fd = socket(AF_INET, SOCK_STREAM, 0);
test_assert(fd > 0);
addr.sin_family = AF_INET;
addr.sin_port = htons(port);
addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
test_assert(bind(fd, (struct sockaddr *)&addr, sizeof(addr)) == 0);
test_assert((ioctl(fd, FIONREAD, &nbytes) == 0) && (nbytes == 0));
test_assert(listen(fd, 1) == 0);
ret = pthread_create(&pt, NULL, netsock_test_fionread_thread,
(void *)(long)port);
test_assert(ret == 0);
/* Wait for client to connect. */
conn_fd = accept(fd, NULL, NULL);
test_assert(conn_fd > 0);
/* Wait for client to send data. */
test_assert(pthread_join(pt, &thread_ret) == 0);
test_assert(ioctl(conn_fd, FIONREAD, &nbytes) == 0);
test_assert(nbytes == NETSOCK_TEST_FIO_COUNT);
test_assert(close((long)thread_ret) == 0); /* TCP client socket */
test_assert(close(conn_fd) == 0);
test_assert(close(fd) == 0);
fd = socket(AF_INET, SOCK_DGRAM, 0);
test_assert(fd > 0);
test_assert(bind(fd, (struct sockaddr *)&addr, sizeof(addr)) == 0);
test_assert((ioctl(fd, FIONREAD, &nbytes) == 0) && (nbytes == 0));
ret = sendto(fd, buf, sizeof(buf), 0, (struct sockaddr *)&addr,
sizeof(addr));
test_assert(ret == sizeof(buf));
test_assert((ioctl(fd, FIONREAD, &nbytes) == 0) && (nbytes == sizeof(buf)));
test_assert(close(fd) == 0);
}
/* Connect to TCP server and then close connection right away. */
static void *netsock_test_connclose_thread(void *arg)
{
int port = (long)arg;
int fd;
struct sockaddr_in addr;
fd = socket(AF_INET, SOCK_STREAM, 0);
test_assert(fd > 0);
addr.sin_family = AF_INET;
addr.sin_port = htons(port);
addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
test_assert(connect(fd, (struct sockaddr *)&addr, sizeof(addr)) == 0);
test_assert(close(fd) == 0);
return NULL;
}
/* Connect to TCP server and wait for connection to be closed. */
static void *netsock_test_connwait_thread(void *arg)
{
int port = (long)arg;
int fd;
struct sockaddr_in addr;
uint8_t buf[8];
fd = socket(AF_INET, SOCK_STREAM, 0);
test_assert(fd > 0);
addr.sin_family = AF_INET;
addr.sin_port = htons(port);
addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
test_assert(connect(fd, (struct sockaddr *)&addr, sizeof(addr)) == 0);
test_assert(read(fd, buf, sizeof(buf)) == 0);
test_assert(close(fd) == 0);
return NULL;
}
/* Tests behavior of syscalls invoked on a socket after the connection has been closed. */
static void netsock_test_connclosed(void)
{
int fd, conn_fd;
struct sockaddr_in addr;
socklen_t addr_len;
const int port = 1234;
struct pollfd pfd;
pthread_t pt;
uint8_t buf[8];
struct iovec iov;
struct msghdr msg;
int ret;
fd = socket(AF_INET, SOCK_STREAM, 0);
test_assert(fd > 0);
addr.sin_family = AF_INET;
addr.sin_port = htons(port);
addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
test_assert(bind(fd, (struct sockaddr *)&addr, sizeof(addr)) == 0);
test_assert(listen(fd, 1) == 0);
/* Test connection closed by peer. */
ret = pthread_create(&pt, NULL, netsock_test_connclose_thread,
(void *)(long)port);
test_assert(ret == 0);
conn_fd = accept(fd, NULL, NULL);
test_assert(conn_fd > 0);
test_assert(read(conn_fd, buf, sizeof(buf)) == 0);
test_assert(recv(conn_fd, buf, sizeof(buf), 0) == 0);
test_assert(recvfrom(conn_fd, buf, sizeof(buf), 0, NULL, 0) == 0);
memset(&iov, 0, sizeof(iov));
memset(&msg, 0, sizeof(msg));
msg.msg_iov = &iov;
msg.msg_iovlen = 1;
test_assert(recvmsg(conn_fd, &msg, 0) == 0);
pfd.fd = conn_fd;
pfd.events = POLLIN | POLLOUT;
ret = poll(&pfd, 1, -1);
test_assert((ret == 1) && (pfd.revents == (POLLIN | POLLOUT)));
test_assert(pthread_join(pt, NULL) == 0);
test_assert(close(conn_fd) == 0);
/* Test connection closed via shutdown(). */
ret = pthread_create(&pt, NULL, netsock_test_connwait_thread,
(void *)(long)port);
test_assert(ret == 0);
conn_fd = accept(fd, NULL, NULL);
test_assert(conn_fd > 0);
test_assert(shutdown(conn_fd, SHUT_RDWR) == 0);
test_assert(read(conn_fd, buf, sizeof(buf)) == 0);
test_assert(recv(conn_fd, buf, sizeof(buf), 0) == 0);
test_assert(recvfrom(conn_fd, buf, sizeof(buf), 0, NULL, 0) == 0);
memset(&iov, 0, sizeof(iov));
memset(&msg, 0, sizeof(msg));
msg.msg_iov = &iov;
msg.msg_iovlen = 1;
test_assert(recvmsg(conn_fd, &msg, 0) == 0);
test_assert(pthread_join(pt, NULL) == 0);
test_assert((listen(conn_fd, 1) == -1) && (errno == EINVAL));
addr_len = sizeof(addr);
test_assert(getsockname(conn_fd, (struct sockaddr *)&addr, &addr_len) == 0);
test_assert(addr_len == sizeof(addr));
test_assert(getpeername(conn_fd, (struct sockaddr *)&addr, &addr_len) == -1);
test_assert(errno == ENOTCONN);
test_assert(close(conn_fd) == 0);
test_assert(close(fd) == 0);
}
static void *netsock_test_udpblock(void *arg)
{
int fd;
struct sockaddr_in addr;
const int port = 1237;
u8 buf[1];
fd = (int)(long)arg;
addr.sin_family = AF_INET;
addr.sin_port = htons(port);
addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
test_assert(bind(fd, (struct sockaddr *)&addr, sizeof(addr)) == 0);
test_assert(recv(fd, &buf, 1, 0) == 0);
return 0;
}
static void netsock_test_udpshutdown(void)
{
pthread_t pt;
int ret;
struct timespec ts;
int fd;
fd = socket(AF_INET, SOCK_DGRAM, 0);
test_assert(fd > 0);
ret = pthread_create(&pt, NULL, netsock_test_udpblock, (void *)(long)fd);
/* allow time for the child thread to block on recv */
usleep(1000 * 50);
shutdown(fd, SHUT_RDWR);
clock_gettime(CLOCK_REALTIME, &ts);
ts.tv_sec += 1;
test_assert(pthread_timedjoin_np(pt, (void *)&ret, &ts) == 0);
test_assert(close(fd) == 0);
}
static void *netsock_test_nonblocking_connect_thread(void *arg)
{
int port = (long)arg;
int fd, efd, err;
socklen_t slen;
struct sockaddr_in addr;
struct epoll_event event;
struct epoll_event events[1];
/* Connect with SOCK_NONBLOCK and verify that EINPROGRESS is returned. */
fd = socket(AF_INET, SOCK_STREAM | SOCK_NONBLOCK, 0);
test_assert(fd > 0);
addr.sin_family = AF_INET;
addr.sin_port = htons(port);
addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
test_assert((connect(fd, (struct sockaddr *)&addr, sizeof(addr)) == -1 && errno == EINPROGRESS));
/* Validate reporting of EPOLLOUT. */
efd = epoll_create1(0);
test_assert(efd > 0);
event.data.fd = fd;
event.events = EPOLLOUT;
test_assert(epoll_ctl(efd, EPOLL_CTL_ADD, fd, &event) == 0);
test_assert(epoll_wait(efd, events, 1, 1000 /* 1s */) == 1);
test_assert((events[0].events & EPOLLOUT));
slen = sizeof(err);
test_assert(getsockopt(fd, SOL_SOCKET, SO_ERROR, &err, &slen) == 0);
test_assert(slen == sizeof(err) && err == 0);
test_assert(close(fd) == 0);
test_assert(close(efd) == 0);
return EXIT_SUCCESS;
}
static void netsock_test_nonblocking_connect(void)
{
int fd, conn_fd;
struct sockaddr_in addr;
const int port = 1235;
pthread_t pt;
int ret;
void *thread_ret;
fd = socket(AF_INET, SOCK_STREAM, 0);
test_assert(fd > 0);
addr.sin_family = AF_INET;
addr.sin_port = htons(port);
addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
test_assert(bind(fd, (struct sockaddr *)&addr, sizeof(addr)) == 0);
test_assert(listen(fd, 1) == 0);
ret = pthread_create(&pt, NULL, netsock_test_nonblocking_connect_thread,
(void *)(long)port);
test_assert(ret == 0);
/* Wait for client to connect and return. */
conn_fd = accept(fd, NULL, NULL);
test_assert(conn_fd > 0);
test_assert(pthread_join(pt, &thread_ret) == 0);
if (thread_ret != EXIT_SUCCESS)
exit((long)thread_ret);
test_assert(close(fd) == 0);
}
static void *netsock_test_peek_thread(void *arg)
{
int port = (long)arg;
int fd;
struct sockaddr_in addr;
uint8_t buf[NETSOCK_TEST_PEEK_COUNT];
fd = socket(AF_INET, SOCK_STREAM, 0);
test_assert(fd > 0);
addr.sin_family = AF_INET;
addr.sin_port = htons(port);
addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
test_assert(connect(fd, (struct sockaddr *)&addr, sizeof(addr)) == 0);
for (int i = 0; i < sizeof(buf); i++)
buf[i] = i;
test_assert(write(fd, buf, sizeof(buf)) == sizeof(buf));
return (void *)(long)fd;
}
static void netsock_test_peek(void)
{
int fd, conn_fd;
struct sockaddr_in addr;
const int port = 1236;
pthread_t pt;
void *thread_ret;
uint8_t buf[NETSOCK_TEST_PEEK_COUNT];
fd = socket(AF_INET, SOCK_STREAM, 0);
test_assert(fd > 0);
addr.sin_family = AF_INET;
addr.sin_port = htons(port);
addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
test_assert(bind(fd, (struct sockaddr *)&addr, sizeof(addr)) == 0);
test_assert(listen(fd, 1) == 0);
test_assert(pthread_create(&pt, NULL, netsock_test_peek_thread, (void *)(long)port) == 0);
/* Wait for client to connect. */
conn_fd = accept(fd, NULL, NULL);
test_assert(conn_fd > 0);
/* Wait for client to send data. */
test_assert(pthread_join(pt, &thread_ret) == 0);
/* Read client data twice, the first time without removing it from the socket incoming data. */
test_assert(recv(conn_fd, buf, sizeof(buf), MSG_PEEK) == sizeof(buf));
for (int i = 0; i < sizeof(buf); i++)
test_assert(buf[i] == i);
memset(buf, 0, sizeof(buf));
test_assert(read(conn_fd, buf, sizeof(buf)) == sizeof(buf));
for (int i = 0; i < sizeof(buf); i++)
test_assert(buf[i] == i);
test_assert(close((long)thread_ret) == 0); /* TCP client socket */
test_assert(close(conn_fd) == 0);
test_assert(close(fd) == 0);
}
static void netsock_test_rcvbuf(void)
{
int tx_fd, rx_fd;
struct sockaddr_in addr;
int rcvbuf;
socklen_t optval;
uint8_t pkt[KB];
const int xfer_size = 80 * KB;
const int pkt_count = xfer_size / sizeof(pkt);
int rx_avail, rx_count;
tx_fd = socket(AF_INET, SOCK_DGRAM, 0);
test_assert(tx_fd > 0);
rx_fd = socket(AF_INET, SOCK_DGRAM, 0);
test_assert(rx_fd > 0);
addr.sin_family = AF_INET;
addr.sin_port = htons(1234);
addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
test_assert(bind(rx_fd, (struct sockaddr *)&addr, sizeof(addr)) == 0);
optval = sizeof(rcvbuf);
test_assert(getsockopt(rx_fd, SOL_SOCKET, SO_RCVBUF, &rcvbuf, &optval) == 0);
test_assert((optval == sizeof(rcvbuf)) && (rcvbuf > 0));
test_assert(connect(tx_fd, (struct sockaddr *)&addr, sizeof(addr)) == 0);
for (int i = 0; i < pkt_count; i++)
test_assert(send(tx_fd, pkt, sizeof(pkt), 0) == sizeof(pkt));
rx_count = 0;
do {
test_assert(recv(rx_fd, pkt, sizeof(pkt), 0) == sizeof(pkt));
rx_count += sizeof(pkt);
test_assert(ioctl(rx_fd, FIONREAD, &rx_avail) == 0);
} while (rx_avail > 0);
test_assert(rx_count == MIN(xfer_size, rcvbuf));
test_assert((close(tx_fd) == 0) && (close(rx_fd) == 0));
}
static void netsock_test_netconf(void)
{
/* SIOC?IF* ioctls aren't netsock-specific - in fact, netdevice(7)
declares that they may be performed on any socket "regardless of the
family or type" (and we'll use AF_UNIX here just to test this
assertion) - but here is as good a place as any to stash tests for
them. */
struct ifreq ifr;
int fd = socket(AF_UNIX, SOCK_STREAM, 0);
test_assert(fd > 0);
memset(&ifr, 0, sizeof(ifr));
ifr.ifr_ifindex = 1;
test_assert(ioctl(fd, SIOCGIFNAME, &ifr) == 0);
}
static int iov_compare(struct iovec *iov1, unsigned int len1,
struct iovec *iov2, unsigned int len2, unsigned int total_len)
{
unsigned int offset = 0;
unsigned int index1 = 0, index2 = 0;
unsigned int offset1 = 0, offset2 = 0;
while ((offset < total_len) && (index1 < len1) && (index2 < len2)) {
unsigned int l = MIN(iov1[index1].iov_len - offset1, iov2[index2].iov_len - offset2);
int cmp = memcmp(iov1[index1].iov_base + offset1, iov2[index2].iov_base + offset2, l);
if (cmp)
return cmp;
offset += l;
offset1 += l;
if (offset1 == iov1[index1].iov_len) {
index1++;
offset1 = 0;
}
offset2 += l;
if (offset2 == iov2[index2].iov_len) {
index2++;
offset2 = 0;
}
}
if (offset == total_len)
return 0;
else if (index1 == len1)
return -1;
else
return 1;
}
static void netsock_test_msg(int sock_type)
{
int listen_fd = -1, tx_fd, rx_fd;
struct sockaddr_in addr;
struct iovec iov1[2], iov2[2], iov3[2], iov4[2];
struct msghdr msg1, msg2;
struct mmsghdr mmsg1[2], mmsg2[2];
int total_len;
char tx_buf[4 * KB], rx_buf[4 * KB];
tx_fd = socket(AF_INET, sock_type, 0);
test_assert(tx_fd > 0);
addr.sin_family = AF_INET;
addr.sin_port = htons(1236);
addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
if (sock_type == SOCK_STREAM) {
listen_fd = socket(AF_INET, sock_type, 0);
test_assert(listen_fd > 0);
test_assert(bind(listen_fd, (struct sockaddr *)&addr, sizeof(addr)) == 0);
test_assert(listen(listen_fd, 1) == 0);
} else {
rx_fd = socket(AF_INET, sock_type, 0);
test_assert(rx_fd > 0);
test_assert(bind(rx_fd, (struct sockaddr *)&addr, sizeof(addr)) == 0);
}
test_assert(connect(tx_fd, (struct sockaddr *)&addr, sizeof(addr)) == 0);
if (sock_type == SOCK_STREAM) {
rx_fd = accept(listen_fd, NULL, NULL);
test_assert(rx_fd > 0);
}
memset(&msg1, 0, sizeof(msg1));
iov1[0].iov_base = "abc";
iov1[0].iov_len = 3;
iov1[1].iov_base = "de";
iov1[1].iov_len = 2;
msg1.msg_iov = iov1;
msg1.msg_iovlen = 2;
total_len = iov1[0].iov_len + iov1[1].iov_len;
test_assert(sendmsg(tx_fd, &msg1, 0) == total_len);
memset(&msg2, 0, sizeof(msg2));
iov2[0].iov_base = rx_buf;
iov2[0].iov_len = 2;
iov2[1].iov_base = rx_buf + sizeof(rx_buf) / 2;
iov2[1].iov_len = sizeof(rx_buf) / 2;
msg2.msg_iov = iov2;
msg2.msg_iovlen = 2;
test_assert((recvmsg(rx_fd, &msg2, 0) == total_len) && (msg2.msg_flags == 0));
test_assert(!iov_compare(iov1, 2, iov2, 2, total_len));
test_assert(sendmmsg(tx_fd, mmsg1, 0, 0) == 0); /* dummy sendmmsg() */
test_assert(recvmmsg(rx_fd, mmsg2, 0, 0, NULL) == 0); /* dummy recvmmsg() */
if (sock_type == SOCK_DGRAM) {
/* test reception of truncated messages */
test_assert(sendmsg(tx_fd, &msg1, 0) == total_len);
test_assert(sendmsg(tx_fd, &msg1, 0) == total_len);
msg2.msg_iovlen = 1;
test_assert(recvmsg(rx_fd, &msg2, 0) == msg2.msg_iov[0].iov_len);
test_assert(msg2.msg_flags == MSG_TRUNC);
test_assert(recvmsg(rx_fd, &msg2, MSG_TRUNC) == total_len);
test_assert(msg2.msg_flags == MSG_TRUNC);
}
memset(&mmsg1, 0, sizeof(mmsg1));
iov1[0].iov_base = tx_buf;
iov1[0].iov_len = 4;
iov1[1].iov_base = tx_buf + 4;
iov1[1].iov_len = sizeof(tx_buf) / 2 - 4;
mmsg1[0].msg_hdr.msg_iov = iov1;
mmsg1[0].msg_hdr.msg_iovlen = 2;
iov2[0].iov_base = tx_buf + sizeof(tx_buf) / 2;
iov2[0].iov_len = 6;
iov2[1].iov_base = tx_buf + sizeof(tx_buf) / 2 + 6;
iov2[1].iov_len = sizeof(tx_buf) / 2 - 6;
mmsg1[1].msg_hdr.msg_iov = iov2;
mmsg1[1].msg_hdr.msg_iovlen = 2;
test_assert(sendmmsg(tx_fd, mmsg1, 2, 0) == 2);
test_assert(mmsg1[0].msg_len == iov1[0].iov_len + iov1[1].iov_len);
test_assert(mmsg1[1].msg_len == iov2[0].iov_len + iov2[1].iov_len);
total_len = mmsg1[0].msg_len + mmsg1[1].msg_len;
if (sock_type == SOCK_STREAM) {
/* test a dummy recvmsg(), which should not consume any data available in the socket */
msg2.msg_iovlen = 0;
test_assert(recvmsg(rx_fd, &msg2, 0) == 0);
}
memset(&mmsg2, 0, sizeof(mmsg2));
iov3[0].iov_base = rx_buf;
iov3[0].iov_len = 1;
iov3[1].iov_base = rx_buf + 1;
iov3[1].iov_len = sizeof(rx_buf) / 2 - 1;
mmsg2[0].msg_hdr.msg_iov = iov3;
mmsg2[0].msg_hdr.msg_iovlen = 2;
iov4[0].iov_base = rx_buf + sizeof(rx_buf) / 2;
iov4[0].iov_len = 9;
iov4[1].iov_base = rx_buf + sizeof(rx_buf) / 2 + 9;
iov4[1].iov_len = sizeof(rx_buf) / 2 - 9;
mmsg2[1].msg_hdr.msg_iov = iov4;
mmsg2[1].msg_hdr.msg_iovlen = 2;
test_assert(recvmmsg(rx_fd, mmsg2, 2, 0, NULL) == 2);
test_assert(mmsg2[0].msg_len == iov3[0].iov_len + iov3[1].iov_len);
test_assert(!iov_compare(iov1, 2, iov3, 2, mmsg2[0].msg_len));
test_assert(mmsg2[1].msg_len == iov4[0].iov_len + iov4[1].iov_len);
test_assert(!iov_compare(iov2, 2, iov4, 2, mmsg2[1].msg_len));
test_assert(mmsg2[0].msg_len + mmsg2[1].msg_len == total_len);
test_assert(sendmmsg(tx_fd, mmsg1, 1, 0) == 1);
test_assert(recvmmsg(rx_fd, mmsg2, 2, MSG_WAITFORONE, NULL) == 1);
test_assert((close(tx_fd) == 0) && (close(rx_fd) == 0));
if (sock_type == SOCK_STREAM)
test_assert(close(listen_fd) == 0);
}
static void *netsock_test_fault_udp_thread(void *arg)
{
int fd;
struct sockaddr_in addr;
u8 buf[8];
fd = socket(AF_INET, SOCK_DGRAM, 0);
test_assert(fd > 0);
test_assert(connect(fd, (struct sockaddr *)FAULT_ADDR, sizeof(addr)) == -1);
test_assert(errno == EFAULT);
addr.sin_family = AF_INET;
addr.sin_port = htons(NETSOCK_TEST_FAULT_PORT);
addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
test_assert(connect(fd, (struct sockaddr *)&addr, sizeof(addr)) == 0);
usleep(1000 * 10); /* wait for the main thread to block */
test_assert(munmap(arg, PAGESIZE) == 0);
test_assert(write(fd, buf, sizeof(buf)) == sizeof(buf));
close(fd);
return NULL;
}
static int netsock_test_fault_udp_setup(pthread_t *pt, void **fault_addr)
{
int fd;
struct sockaddr_in addr;
*fault_addr = mmap(0, PAGESIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
test_assert(*fault_addr != MAP_FAILED);
fd = socket(AF_INET, SOCK_DGRAM, 0);
test_assert(fd > 0);
addr.sin_family = AF_INET;
addr.sin_port = htons(NETSOCK_TEST_FAULT_PORT);
addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
test_assert((bind(fd, (struct sockaddr *)FAULT_ADDR, sizeof(addr)) == -1) && (errno == EFAULT));
test_assert(bind(fd, (struct sockaddr *)&addr, sizeof(addr)) == 0);
test_assert(pthread_create(pt, NULL, netsock_test_fault_udp_thread, *fault_addr) == 0);
return fd;
}
static void *netsock_test_fault_tcp_thread(void *arg)
{
int fd;
struct sockaddr_in addr;
fd = socket(AF_INET, SOCK_STREAM | SOCK_NONBLOCK, 0);
test_assert(fd > 0);
usleep(1000 * 10); /* wait for the main thread to block */
test_assert(munmap(arg, PAGESIZE) == 0);
addr.sin_family = AF_INET;
addr.sin_port = htons(NETSOCK_TEST_FAULT_PORT);
addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
connect(fd, (struct sockaddr *)&addr, sizeof(addr));
close(fd);
return NULL;
}
static void netsock_test_fault(void)
{
int fd;
void *fault_addr;
u8 buf[KB];
struct iovec iov;
struct msghdr *msg;
struct mmsghdr *mmsg;
struct sockaddr_in addr;
socklen_t len;
pthread_t pt;
struct ifconf ifconf;
/* recvmsg()/sendmsg() with faulting struct msghdr */
fd = netsock_test_fault_udp_setup(&pt, &fault_addr);
iov.iov_base = buf;
iov.iov_len = sizeof(buf);
msg = fault_addr;
memset(msg, 0, sizeof(*msg));
msg->msg_iov = &iov;
msg->msg_iovlen = 1;
test_assert((recvmsg(fd, msg, 0) == -1) && (errno == EFAULT));
test_assert(pthread_join(pt, NULL) == 0);
test_assert((sendmsg(fd, msg, 0) == -1) && (errno == EFAULT));
close(fd);
/* recvmmsg()/sendmmsg() with faulting struct mmsghdr */
fd = netsock_test_fault_udp_setup(&pt, &fault_addr);
mmsg = fault_addr;
mmsg->msg_hdr.msg_iov = &iov;
mmsg->msg_hdr.msg_iovlen = 1;
test_assert((recvmmsg(fd, mmsg, 1, 0, NULL) == -1) && (errno == EFAULT));
test_assert(pthread_join(pt, NULL) == 0);
test_assert((sendmmsg(fd, mmsg, 1, 0) == -1) && (errno == EFAULT));
close(fd);
/* read() with faulting buffer */
fd = netsock_test_fault_udp_setup(&pt, &fault_addr);
test_assert((read(fd, fault_addr, PAGESIZE) == -1) && (errno == EFAULT));
test_assert(pthread_join(pt, NULL) == 0);
close(fd);
/* recvfrom()/sendto() with faulting address */
fd = netsock_test_fault_udp_setup(&pt, &fault_addr);
len = sizeof(addr);
test_assert((recvfrom(fd, buf, sizeof(buf), 0, fault_addr, &len) == -1) && (errno == EFAULT));
test_assert(pthread_join(pt, NULL) == 0);
test_assert(sendto(fd, buf, sizeof(buf), 0, fault_addr, sizeof(addr)) == -1);
test_assert(errno == EFAULT);
close(fd);
/* recvfrom() with faulting address length */
fd = netsock_test_fault_udp_setup(&pt, &fault_addr);
*(socklen_t *)fault_addr = sizeof(addr);
test_assert((recvfrom(fd, buf, sizeof(buf), 0, &addr, fault_addr) == -1) && (errno == EFAULT));
test_assert(pthread_join(pt, NULL) == 0);
test_assert((ioctl(fd, SIOCGIFCONF, fault_addr) == -1) && (errno == EFAULT));
ifconf.ifc_len = sizeof(struct ifreq);
ifconf.ifc_req = fault_addr;
test_assert((ioctl(fd, SIOCGIFCONF, &ifconf) == -1) && (errno == EFAULT));
test_assert((ioctl(fd, SIOCGIFNAME, fault_addr) == -1) && (errno == EFAULT));
test_assert((ioctl(fd, SIOCGIFFLAGS, fault_addr) == -1) && (errno == EFAULT));
test_assert((ioctl(fd, SIOCSIFFLAGS, fault_addr) == -1) && (errno == EFAULT));
test_assert((ioctl(fd, SIOCGIFADDR, fault_addr) == -1) && (errno == EFAULT));
test_assert((ioctl(fd, SIOCSIFADDR, fault_addr) == -1) && (errno == EFAULT));
test_assert((ioctl(fd, SIOCGIFNETMASK, fault_addr) == -1) && (errno == EFAULT));
test_assert((ioctl(fd, SIOCSIFNETMASK, fault_addr) == -1) && (errno == EFAULT));
test_assert((ioctl(fd, SIOCGIFMTU, fault_addr) == -1) && (errno == EFAULT));
test_assert((ioctl(fd, SIOCSIFMTU, fault_addr) == -1) && (errno == EFAULT));
test_assert((ioctl(fd, SIOCGIFINDEX, fault_addr) == -1) && (errno == EFAULT));
test_assert((ioctl(fd, FIONREAD, fault_addr) == -1) && (errno == EFAULT));
len = sizeof(addr);
test_assert((getsockname(fd, fault_addr, &len) == -1) && (errno == EFAULT));
test_assert((getsockname(fd, &addr, fault_addr) == -1) && (errno == EFAULT));
test_assert(setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, fault_addr, sizeof(int)) == -1);
test_assert(errno == EFAULT);
len = sizeof(int);
test_assert((getsockopt(fd, SOL_SOCKET, SO_TYPE, fault_addr, &len) == -1) && (errno == EFAULT));
close(fd);
/* accept() with faulting address */
fault_addr = mmap(0, PAGESIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
test_assert(fault_addr != MAP_FAILED);
fd = socket(AF_INET, SOCK_STREAM, 0);
test_assert(fd > 0);
addr.sin_family = AF_INET;
addr.sin_port = htons(NETSOCK_TEST_FAULT_PORT);
addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
test_assert(bind(fd, (struct sockaddr *)&addr, sizeof(addr)) == 0);
test_assert(listen(fd, 1) == 0);
test_assert(pthread_create(&pt, NULL, netsock_test_fault_tcp_thread, fault_addr) == 0);
len = sizeof(addr);
test_assert((accept(fd, fault_addr, &len) == -1) && (errno == EFAULT));
test_assert(pthread_join(pt, NULL) == 0);
close(fd);
}
int main(int argc, char **argv)
{
netsock_test_basic(SOCK_STREAM);
netsock_test_basic(SOCK_DGRAM);
netsock_test_fionread();
netsock_test_connclosed();
netsock_test_udpshutdown();
netsock_test_nonblocking_connect();
netsock_test_peek();
netsock_test_rcvbuf();
netsock_test_netconf();
netsock_test_msg(SOCK_STREAM);
netsock_test_msg(SOCK_DGRAM);
netsock_test_fault();
printf("Network socket tests OK\n");
return EXIT_SUCCESS;
}
|
04f1cbe4ca4e59c4c635fd42aeda8b710b105270
|
28d0f8c01599f8f6c711bdde0b59f9c2cd221203
|
/sys/dev/pcmcia/if_sm_pcmcia.c
|
f2181deb81da8aec8a93af80519355f936099832
|
[] |
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
| 7,335
|
c
|
if_sm_pcmcia.c
|
/* $NetBSD: if_sm_pcmcia.c,v 1.57 2018/02/08 09:05:20 dholland Exp $ */
/*-
* Copyright (c) 1997, 1998, 2000, 2004 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
* NASA Ames Research Center, and by Charles M. Hannum.
*
* 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 <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: if_sm_pcmcia.c,v 1.57 2018/02/08 09:05:20 dholland Exp $");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/mbuf.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <sys/errno.h>
#include <sys/syslog.h>
#include <sys/select.h>
#include <sys/device.h>
#include <net/if.h>
#include <net/if_dl.h>
#include <net/if_ether.h>
#include <net/if_media.h>
#include <sys/intr.h>
#include <sys/bus.h>
#include <dev/mii/mii.h>
#include <dev/mii/miivar.h>
#include <dev/ic/smc91cxxreg.h>
#include <dev/ic/smc91cxxvar.h>
#include <dev/pcmcia/pcmciareg.h>
#include <dev/pcmcia/pcmciavar.h>
#include <dev/pcmcia/pcmciadevs.h>
int sm_pcmcia_match(device_t, cfdata_t, void *);
int sm_pcmcia_validate_config(struct pcmcia_config_entry *);
void sm_pcmcia_attach(device_t, device_t, void *);
int sm_pcmcia_detach(device_t, int);
struct sm_pcmcia_softc {
struct smc91cxx_softc sc_smc; /* real "smc" softc */
struct pcmcia_function *sc_pf; /* our PCMCIA function */
void *sc_ih; /* interrupt cookie */
int sc_state;
#define SM_PCMCIA_ATTACHED 3
};
CFATTACH_DECL_NEW(sm_pcmcia, sizeof(struct sm_pcmcia_softc),
sm_pcmcia_match, sm_pcmcia_attach, sm_pcmcia_detach, smc91cxx_activate);
int sm_pcmcia_enable(struct smc91cxx_softc *);
void sm_pcmcia_disable(struct smc91cxx_softc *);
int sm_pcmcia_ascii_enaddr(const char *, u_int8_t *);
const struct pcmcia_product sm_pcmcia_products[] = {
{ PCMCIA_VENDOR_MEGAHERTZ2, PCMCIA_PRODUCT_MEGAHERTZ2_EM1144,
PCMCIA_CIS_INVALID },
{ PCMCIA_VENDOR_MEGAHERTZ2, PCMCIA_PRODUCT_MEGAHERTZ2_XJACK,
PCMCIA_CIS_INVALID },
{ PCMCIA_VENDOR_NEWMEDIA, PCMCIA_PRODUCT_NEWMEDIA_BASICS,
PCMCIA_CIS_INVALID },
#if 0
{ PCMCIA_VENDOR_SMC, PCMCIA_PRODUCT_SMC_8020BT,
PCMCIA_CIS_INVALID },
#endif
{ PCMCIA_VENDOR_PSION, PCMCIA_PRODUCT_PSION_GOLDCARD,
PCMCIA_CIS_INVALID },
};
const size_t sm_pcmcia_nproducts =
sizeof(sm_pcmcia_products) / sizeof(sm_pcmcia_products[0]);
int
sm_pcmcia_match(device_t parent, cfdata_t match,
void *aux)
{
struct pcmcia_attach_args *pa = aux;
/* This is to differentiate the serial function of some cards. */
if (pa->pf->function != PCMCIA_FUNCTION_NETWORK)
return (0);
if (pcmcia_product_lookup(pa, sm_pcmcia_products, sm_pcmcia_nproducts,
sizeof(sm_pcmcia_products[0]), NULL))
return (1);
return (0);
}
int
sm_pcmcia_validate_config(struct pcmcia_config_entry *cfe)
{
if (cfe->iftype != PCMCIA_IFTYPE_IO ||
cfe->num_memspace != 0 ||
cfe->num_iospace != 1 ||
cfe->iospace[0].length < SMC_IOSIZE)
return (EINVAL);
return (0);
}
void
sm_pcmcia_attach(device_t parent, device_t self, void *aux)
{
struct sm_pcmcia_softc *psc = device_private(self);
struct smc91cxx_softc *sc = &psc->sc_smc;
struct pcmcia_attach_args *pa = aux;
struct pcmcia_config_entry *cfe;
u_int8_t enaddr[ETHER_ADDR_LEN];
int error;
sc->sc_dev = self;
psc->sc_pf = pa->pf;
error = pcmcia_function_configure(pa->pf, sm_pcmcia_validate_config);
if (error) {
aprint_error_dev(self, "configure failed, error=%d\n", error);
return;
}
cfe = pa->pf->cfe;
sc->sc_bst = cfe->iospace[0].handle.iot;
sc->sc_bsh = cfe->iospace[0].handle.ioh;
error = sm_pcmcia_enable(sc);
if (error)
goto fail;
sc->sc_enable = sm_pcmcia_enable;
sc->sc_disable = sm_pcmcia_disable;
/*
* First try to get the Ethernet address from FUNCE/LANNID tuple.
* If that fails, try one of the CIS info strings.
*/
if (pa->pf->pf_funce_lan_nidlen == ETHER_ADDR_LEN) {
memcpy(enaddr, pa->pf->pf_funce_lan_nid, ETHER_ADDR_LEN);
} else {
if (!sm_pcmcia_ascii_enaddr(pa->pf->sc->card.cis1_info[3], enaddr) &&
!sm_pcmcia_ascii_enaddr(pa->pf->sc->card.cis1_info[2], enaddr))
aprint_error_dev(self,
"unable to get Ethernet address\n");
}
/* Perform generic initialization. */
smc91cxx_attach(sc, enaddr);
psc->sc_state = SM_PCMCIA_ATTACHED;
sm_pcmcia_disable(sc);
return;
fail:
pcmcia_function_unconfigure(pa->pf);
}
int
sm_pcmcia_detach(device_t self, int flags)
{
struct sm_pcmcia_softc *psc = device_private(self);
int error;
if (psc->sc_state != SM_PCMCIA_ATTACHED)
return (0);
error = smc91cxx_detach((device_t)&psc->sc_smc, flags);
if (error)
return (error);
pcmcia_function_unconfigure(psc->sc_pf);
return (0);
}
int
sm_pcmcia_ascii_enaddr(const char *cisstr, u_int8_t *myla)
{
u_int8_t digit;
int i;
/* No CIS string. */
if (cisstr == 0)
return (0);
memset(myla, 0, ETHER_ADDR_LEN);
for (i = 0, digit = 0; i < (ETHER_ADDR_LEN * 2); i++) {
if (cisstr[i] >= '0' && cisstr[i] <= '9')
digit |= cisstr[i] - '0';
else if (cisstr[i] >= 'a' && cisstr[i] <= 'f')
digit |= (cisstr[i] - 'a') + 10;
else if (cisstr[i] >= 'A' && cisstr[i] <= 'F')
digit |= (cisstr[i] - 'A') + 10;
else {
/* Bogus digit!! */
return (0);
}
/* Compensate for ordering of digits. */
if (i & 1) {
myla[i >> 1] = digit;
digit = 0;
} else
digit <<= 4;
}
return (1);
}
int
sm_pcmcia_enable(struct smc91cxx_softc *sc)
{
struct sm_pcmcia_softc *psc = (struct sm_pcmcia_softc *)sc;
int error;
/* Establish the interrupt handler. */
psc->sc_ih = pcmcia_intr_establish(psc->sc_pf, IPL_NET, smc91cxx_intr,
sc);
if (!psc->sc_ih)
return (EIO);
error = pcmcia_function_enable(psc->sc_pf);
if (error) {
pcmcia_intr_disestablish(psc->sc_pf, psc->sc_ih);
psc->sc_ih = 0;
}
return (error);
}
void
sm_pcmcia_disable(struct smc91cxx_softc *sc)
{
struct sm_pcmcia_softc *psc = (struct sm_pcmcia_softc *)sc;
pcmcia_function_disable(psc->sc_pf);
pcmcia_intr_disestablish(psc->sc_pf, psc->sc_ih);
psc->sc_ih = 0;
}
|
ff65fd9ab6088b88c17ae3e6ea093b51d7b5fd30
|
d1a6e586e0ad50da88ac3cf176d40bb9facb6bf6
|
/source/utility/vector.c
|
887d4d385bb01b42f89eaff5d1bc6b7976eaf47d
|
[
"Apache-2.0"
] |
permissive
|
OAID/Tengine
|
025d2521040c863300ee08b0800010587b72192b
|
c73708ceb4322ae7c438e4d468178b737fa44cd0
|
refs/heads/tengine-lite
| 2023-09-03T19:15:08.100078
| 2023-05-18T06:17:39
| 2023-05-18T06:17:39
| 115,765,590
| 5,323
| 1,216
|
Apache-2.0
| 2023-09-05T06:25:47
| 2017-12-30T01:21:41
|
C++
|
UTF-8
|
C
| false
| false
| 5,286
|
c
|
vector.c
|
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* License); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/*
* Copyright (c) 2021, OPEN AI LAB
* Author: haitao@openailab.com
* Revised: lswang@openailab.com
*/
#include "utility/vector.h"
#include "defines.h"
#include "utility/sys_port.h"
#include "utility/math.h"
#include <string.h>
typedef struct vector_entry
{
int valid;
unsigned char data[];
} vector_entry_t;
static inline vector_entry_t* get_vector_entry(vector_t* v, int idx)
{
return (vector_entry_t*)((char*)v->mem + v->entry_size * idx);
}
static inline void free_vector_data_resource(vector_t* v, int idx)
{
vector_entry_t* e = get_vector_entry(v, idx);
if (e->valid && v->free_func)
{
v->free_func(e->data);
}
e->valid = 0;
}
static inline void remove_vector_data_not_tail(vector_t* v, int idx)
{
vector_entry_t* entry_ptr = NULL;
void* start_data_ptr;
int remaining_elements_count;
free_vector_data_resource(v, idx);
start_data_ptr = (char*)v->mem + idx * v->entry_size;
remaining_elements_count = v->elem_num - 1 - idx;
memmove(start_data_ptr, (char*)start_data_ptr + v->entry_size, (size_t)remaining_elements_count * v->entry_size);
v->elem_num--;
// clear the valid flag
entry_ptr = get_vector_entry(v, v->elem_num);
entry_ptr->valid = 0;
}
vector_t* create_vector(int elem_size, void (*free_data)(void*))
{
vector_t* v = (vector_t*)sys_malloc(sizeof(vector_t));
if (v == NULL)
{
return NULL;
}
v->elem_num = 0;
v->elem_size = elem_size;
v->free_func = free_data;
v->entry_size = align(elem_size + (int)sizeof(vector_entry_t), TE_VECTOR_ALIGN_SIZE);
v->ahead_num = 8;
v->space_num = v->ahead_num;
v->real_mem = sys_malloc(v->entry_size * v->space_num + TE_VECTOR_ALIGN_SIZE);
v->mem = align_address(v->real_mem, TE_VECTOR_ALIGN_SIZE);
for (int i = 0; i < v->space_num; i++)
{
vector_entry_t* e = get_vector_entry(v, i);
e->valid = 0;
}
return v;
}
void release_vector(vector_t* v)
{
for (int i = 0; i < v->elem_num; i++)
{
free_vector_data_resource(v, i);
}
sys_free(v->real_mem);
sys_free(v);
}
int get_vector_num(vector_t* v)
{
if (NULL != v)
{
return v->elem_num;
}
return 0;
}
int resize_vector(vector_t* v, int new_size)
{
void* new_mem = NULL;
/* need to free the reduced element */
if (new_size < v->elem_num)
{
for (int i = v->elem_num - 1; i > new_size - 1; i--)
{
remove_vector_via_index(v, i);
}
return 0;
}
if (new_size <= v->space_num)
{
v->elem_num = new_size;
return 0;
}
new_mem = sys_realloc(v->real_mem, new_size * v->entry_size + TE_VECTOR_ALIGN_SIZE);
if (new_mem == NULL)
{
return -1;
}
v->real_mem = new_mem;
v->mem = (void*)(((size_t)(v->real_mem)) & (~(TE_VECTOR_ALIGN_SIZE - 1)));
for (int i = v->space_num; i < new_size; i++)
{
vector_entry_t* e = get_vector_entry(v, i);
e->valid = 0;
}
v->space_num = new_size;
return 0;
}
int push_vector_data(vector_t* v, void* data)
{
if (v->elem_num == v->space_num && resize_vector(v, v->elem_num + v->ahead_num) < 0)
{
return -1;
}
v->elem_num++;
set_vector_data(v, v->elem_num - 1, data);
return 0;
}
int set_vector_data(vector_t* v, int idx, void* data)
{
vector_entry_t* e = NULL;
if (idx >= v->elem_num)
return -1;
free_vector_data_resource(v, idx);
e = get_vector_entry(v, idx);
e->valid = 1;
memcpy(e->data, data, v->elem_size);
return 0;
}
void* get_vector_data(vector_t* v, int index)
{
if (index >= v->elem_num)
{
return NULL;
}
vector_entry_t* e = get_vector_entry(v, index);
return e->data;
}
int remove_vector_via_pointer(vector_t* v, void* data)
{
const int count = v->elem_num;
int index;
for (index = 0; index < count; index++)
{
void* content = get_vector_data(v, index);
if (memcmp(content, data, v->elem_size) == 0)
{
break;
}
}
if (count == index)
{
return -1;
}
remove_vector_via_index(v, index);
return 0;
}
void remove_vector_via_index(vector_t* v, int idx)
{
// the last one
if (idx == v->elem_num - 1)
{
free_vector_data_resource(v, idx);
v->elem_num--;
return;
}
remove_vector_data_not_tail(v, idx);
}
|
a7c05fe0caa11b79be44f282d2aab86fd7c9cd6d
|
2d6d132baaa8c9ce1863c0f1f67e3e86af7010c6
|
/src/ext/history.c
|
5ff1f45bb981d52db587caaee1178705789e47ee
|
[
"MIT"
] |
permissive
|
nesbox/TIC-80
|
4adfaeec1dfc2b61ac3251789293311bc8770832
|
c3b90f951bf9022032abbb79cb31d2c67116bf6d
|
refs/heads/main
| 2023-09-05T08:35:51.043700
| 2023-09-02T08:23:59
| 2023-09-02T08:23:59
| 77,920,383
| 4,412
| 589
|
MIT
| 2023-09-13T00:47:55
| 2017-01-03T13:40:19
|
C
|
UTF-8
|
C
| false
| false
| 4,255
|
c
|
history.c
|
// MIT License
// Copyright (c) 2017 Vadim Grigoruk @nesbox // grigoruk@gmail.com
// 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 "history.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
typedef struct
{
u8* buffer;
u32 start;
u32 end;
} Data;
typedef struct Item Item;
struct Item
{
Item* next;
Item* prev;
Data data;
};
static void list_delete(Item* list, Item* from)
{
Item* it = from;
while(it)
{
Item* next = it->next;
if(it->data.buffer) free(it->data.buffer);
free(it);
it = next;
}
}
static Item* list_insert(Item* list, Data* data)
{
Item* item = (Item*)malloc(sizeof(Item));
item->next = NULL;
item->prev = NULL;
item->data = *data;
if(list)
{
list_delete(list, list->next);
list->next = item;
item->prev = list;
}
return item;
}
static Item* list_first(Item* list)
{
Item* it = list;
while(it->prev) it = it->prev;
return it;
}
struct History
{
Item* list;
u32 size;
u8* state;
void* data;
};
History* history_create(void* data, u32 size)
{
History* history = (History*)malloc(sizeof(History));
history->data = data;
history->list = NULL;
history->size = size;
history->state = malloc(size);
memcpy(history->state, data, history->size);
// empty diff
history->list = list_insert(history->list, &(Data){NULL, 0, 0});
return history;
}
void history_delete(History* history)
{
if(history)
{
free(history->state);
list_delete(history->list, list_first(history->list));
free(history);
}
}
static void history_diff(History* history, Data* data)
{
for (u32 i = data->start, k = 0; i < data->end; ++i, ++k)
history->state[i] ^= data->buffer[k];
}
static u32 trim_left(u8* data, u32 size)
{
for(u32 i = 0; i < size; i++)
if(data[i]) return i;
return size;
}
static u32 trim_right(u8* data, u32 size)
{
for(u32 i = 0; i < size; i++)
if(data[size - i - 1]) return size - i;
return 0;
}
bool history_add(History* history)
{
if (memcmp(history->state, history->data, history->size) == 0) return false;
history_diff(history, &(Data){history->data, 0, history->size});
{
Data data;
data.start = trim_left(history->state, history->size);
data.end = trim_right(history->state, history->size);
u32 size = data.end - data.start;
data.buffer = malloc(size);
memcpy(data.buffer, (u8*)history->state + data.start, size);
history->list = list_insert(history->list, &data);
}
memcpy(history->state, history->data, history->size);
return true;
}
void history_undo(History* history)
{
if(history->list->prev)
{
history_diff(history, &history->list->data);
history->list = history->list->prev;
}
memcpy(history->data, history->state, history->size);
}
void history_redo(History* history)
{
if(history->list->next)
{
history->list = history->list->next;
history_diff(history, &history->list->data);
}
memcpy(history->data, history->state, history->size);
}
|
f18217cb705b0876e9966dbe76c292e4361d5772
|
fdbb74a95924e2677466614f6ab6e2bb13b2a95a
|
/libc/stdio/rdrand.c
|
60079b8fbf329cb13bf9455783db591964fa3ed9
|
[
"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
| 3,554
|
c
|
rdrand.c
|
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
╞══════════════════════════════════════════════════════════════════════════════╡
│ Copyright 2020 Justine Alexandra Roberts Tunney │
│ │
│ Permission to use, copy, modify, and/or distribute this software for │
│ any purpose with or without fee is hereby granted, provided that the │
│ above copyright notice and this permission notice appear in all copies. │
│ │
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
│ PERFORMANCE OF THIS SOFTWARE. │
╚─────────────────────────────────────────────────────────────────────────────*/
#include "libc/errno.h"
#include "libc/intrin/asmflag.h"
#include "libc/nexgen32e/x86feature.h"
#include "libc/stdio/rand.h"
#include "libc/sysv/consts/grnd.h"
__static_yoink("rdrand_init");
static dontinline uint64_t rdrand_failover(void) {
int f;
size_t i;
ssize_t r;
volatile uint64_t b;
register uint64_t x;
for (f = GRND_RANDOM | GRND_NONBLOCK, i = 0; i < 8; i += r) {
if ((r = getrandom((char *)&b + i, 8 - i, f)) <= 0) {
if (r == -1 && errno == EINTR) {
r = 0;
} else if (r == -1 && errno == EAGAIN) {
r = 0;
f = 0;
} else {
return _rand64();
}
}
}
x = b;
b = 0;
return x;
}
/**
* Retrieves 64-bits of hardware random data from RDRAND instruction.
*
* If RDRAND isn't available (we check CPUID and we also disable it
* automatically for microarchitectures where it's slow or buggy) then
* we try getrandom(), RtlGenRandom(), or sysctl(KERN_ARND). If those
* aren't available then we try /dev/urandom and if that fails, we try
* getauxval(AT_RANDOM), and if not we finally use RDTSC and getpid().
*
* @note this function could block a nontrivial time on old computers
* @note this function is indeed intended for cryptography
* @note this function takes around 300 cycles
* @see rngset(), rdseed(), _rand64()
* @asyncsignalsafe
* @vforksafe
*/
uint64_t rdrand(void) {
int i;
char cf;
uint64_t x;
if (X86_HAVE(RDRND)) {
for (i = 0; i < 10; ++i) {
asm volatile(CFLAG_ASM("rdrand\t%1")
: CFLAG_CONSTRAINT(cf), "=r"(x)
: /* no inputs */
: "cc");
if (cf) return x;
asm volatile("pause");
}
}
return rdrand_failover();
}
|
fa1115dec975239fe52e9b576afc995610e97db9
|
a00848241e497586fa7bd5e45d3fab7dd204b940
|
/gba/examples/disable_channels/source/main.c
|
458fcfbeb34c308147fb00b4ae875b68cba8eba3
|
[
"MIT"
] |
permissive
|
AntonioND/gbt-player
|
33c21fe1275854dce644ff35bbdcf8f8daecb08f
|
4ee745f848d1aa610529aca0043f91cbc7d9ef6f
|
refs/heads/master
| 2023-04-29T01:25:50.349009
| 2023-03-26T22:38:32
| 2023-03-26T22:38:32
| 19,330,221
| 275
| 30
|
MIT
| 2023-03-26T22:38:33
| 2014-04-30T23:20:26
|
C
|
UTF-8
|
C
| false
| false
| 1,873
|
c
|
main.c
|
// SPDX-License-Identifier: MIT
//
// Copyright (c) 2022 Antonio Niño Díaz <antonio_nd@outlook.com>
// Example that shows how to play sound effects while GBT Player is playing a
// song. It does that by disabling the channel in GBT Player.
#include <stdio.h>
#include <gba.h>
#include "gbt_player/gbt_player.h"
#include "sfx.h"
extern const uint8_t *template[];
int main(int argc, char *argv[])
{
irqInit();
irqSet(IRQ_VBLANK, gbt_update);
irqEnable(IRQ_VBLANK);
consoleDemoInit();
iprintf("Channel 2 enabled \n");
iprintf("\n");
iprintf("A: Enable channel 2 in GBT\n");
iprintf("B: Disable channel 2 in GBT\n");
iprintf("L: Play sound on left side\n");
iprintf("R: Play sound on right side\n");
iprintf("START: Start song\n");
iprintf("SELECT: Stop song\n");
iprintf("\n");
iprintf("If the sound is played before\n");
iprintf("disabling channel 2, it will\n");
iprintf("be interrupted by the song\n");
iprintf("playback.");
while (1)
{
scanKeys();
int keys = keysDown();
if (keys & KEY_A)
{
gbt_enable_channels(GBT_ENABLE_CH_ALL);
iprintf("\x1b[0;0HChannel 2 enabled ");
}
if (keys & KEY_B)
{
gbt_enable_channels(GBT_ENABLE_CH_ALL & ~GBT_ENABLE_CH2);
// Disabling a channel will leave it playing whatever note was being
// played before disabling it. It is needed to silence it manually.
sfx_channel2_silence();
iprintf("\x1b[0;0HChannel 2 disabled");
}
if (keys & KEY_L)
sfx_channel2_left();
if (keys & KEY_R)
sfx_channel2_right();
if (keys & KEY_START)
gbt_play(template, -1);
if (keys & KEY_SELECT)
gbt_stop();
VBlankIntrWait();
}
}
|
159ad2c344ce59a4264b1fbc8999ef0ab5f1ec0a
|
9f14c14c5a99cd79a917658e36db4232d1a41405
|
/compiler/test/compilable/imports/asmmerge.c
|
b58d995d2952476bb7b8f5df4e5fbdf4300dd524
|
[
"BSL-1.0"
] |
permissive
|
dlang/dmd
|
643941ef957949ec1bc62d8e431406afd64375b8
|
25d2741b86b1060ec43d80dbcc8dc190d5453322
|
refs/heads/master
| 2023-08-31T03:02:46.324487
| 2023-08-20T17:02:46
| 2023-08-30T09:27:23
| 1,257,070
| 2,074
| 486
|
BSL-1.0
| 2023-09-14T20:55:15
| 2011-01-15T06:53:53
|
D
|
UTF-8
|
C
| false
| false
| 88
|
c
|
asmmerge.c
|
void fun22() asm ("test1");
void fun22()
{
}
extern int xs[] asm("test2");
int xs[1];
|
22fdba90ed819fd6c036cc31a6285a7da188ebf0
|
59864cbd213b5da6f50d6255b0a021564b3d5bd4
|
/challenges/Square_Rabbit/src/cgc_deck.h
|
ce98b2224934c0c185e6c01ec4a6ee62099851ec
|
[
"MIT",
"BSD-3-Clause",
"LicenseRef-scancode-unknown",
"BSD-2-Clause"
] |
permissive
|
trailofbits/cb-multios
|
8af96a4fbc3b34644367faa135347f88e0e0d0a3
|
810d7b24b1f62f56ef49b148fe155b0d0629cad2
|
refs/heads/master
| 2023-09-05T03:56:20.229403
| 2022-12-27T15:47:54
| 2022-12-27T15:47:54
| 41,688,943
| 522
| 133
|
MIT
| 2023-06-29T02:47:13
| 2015-08-31T17:04:31
|
C
|
UTF-8
|
C
| false
| false
| 462
|
h
|
cgc_deck.h
|
#ifndef DECK_H_
#define DECK_H_
#include "cgc_card.h"
#define CARDS_PER_SUIT 13
#define NUM_SUITS 4
#define NUM_CARDS (CARDS_PER_SUIT * NUM_SUITS)
#define RESHUFFLE_CARD (int)(.65 * NUM_CARDS)
typedef struct deck
{
card_t cards[NUM_CARDS];
int top_of_deck;
} deck_t;
void cgc_init_deck(deck_t *d, unsigned int *seed);
int cgc_shuffle_deck(deck_t *d);
int cgc_shuffle_deck_if_needed(deck_t *d);
card_t *cgc_draw_card(deck_t *d);
#endif /* DECK_H_ */
|
82cdab68d693a60ebc504c4abb26e158bc743d8c
|
2a70a8b7b82ab266d7b130a07daf117143d0e2ab
|
/Common/TimeUtil.h
|
8da84aeecabb6eb6e49692ce46e98ec8ec38b663
|
[
"MIT"
] |
permissive
|
xtne6f/EDCB
|
151df41a818c7b29b416a11c518ad5bcf1151e84
|
c8955e67689df2be1ff1a7ae0acc3322ed8a9d70
|
refs/heads/work-plus-s
| 2023-08-28T09:48:25.636478
| 2023-08-22T14:35:29
| 2023-08-22T14:35:29
| 9,693,839
| 164
| 77
|
NOASSERTION
| 2023-05-26T14:47:35
| 2013-04-26T11:35:32
|
C++
|
UTF-8
|
C
| false
| false
| 466
|
h
|
TimeUtil.h
|
#ifndef INCLUDE_TIME_UTIL_H
#define INCLUDE_TIME_UTIL_H
#define I64_1SEC ((LONGLONG)10000000)
#define I64_UTIL_TIMEZONE (9 * 3600 * I64_1SEC)
LPCWSTR GetDayOfWeekName( WORD wDayOfWeek );
DWORD GetU32Tick();
LONGLONG GetNowI64Time();
LONGLONG ConvertI64Time(SYSTEMTIME Time);
bool ConvertSystemTime(LONGLONG i64Time, SYSTEMTIME* Time);
LPCSTR GetTimeMacroName(int index);
wstring GetTimeMacroValue(int index, SYSTEMTIME Time);
#endif
|
c7ce8ba33ef99d30a94102924ecadaf5a3d98d36
|
f4ea6db9183b38e0cb1af1d317b0a02db24455d1
|
/test/t-language/inh/a.c
|
dbc1cd697a52b88eb6b8b8ff24bf417850a4999e
|
[
"BSD-3-Clause",
"LicenseRef-scancode-public-domain",
"BSD-2-Clause"
] |
permissive
|
ldmud/ldmud
|
1446ff7101f5a47ee1dfa4cfb97d5a326f2edcce
|
f1cfc9a8d911412d854055058889bb32432da2db
|
refs/heads/master
| 2023-05-25T00:36:28.318383
| 2023-02-14T21:07:35
| 2023-02-18T10:20:44
| 1,085,012
| 124
| 71
|
NOASSERTION
| 2023-09-01T16:54:48
| 2010-11-16T12:13:17
|
C
|
UTF-8
|
C
| false
| false
| 222
|
c
|
a.c
|
public string a_var = "a";
public string a_fun()
{
return "a";
}
public string get_a_var()
{
return a_var;
}
public void set_a_var(string v)
{
a_var = v;
}
public string get_a_fun()
{
return a_fun();
}
|
61a8e87b513b73a32f83e99dda37c732e37de1c7
|
b732361d6b3405c3e79ac0a7d8361cf5b329b015
|
/ext/phalcon/logger/loggerfactory.zep.h
|
fab301ba45757b28ff3bb4a9c684c137210e9834
|
[
"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
| 2,117
|
h
|
loggerfactory.zep.h
|
extern zend_class_entry *phalcon_logger_loggerfactory_ce;
ZEPHIR_INIT_CLASS(Phalcon_Logger_LoggerFactory);
PHP_METHOD(Phalcon_Logger_LoggerFactory, __construct);
PHP_METHOD(Phalcon_Logger_LoggerFactory, load);
PHP_METHOD(Phalcon_Logger_LoggerFactory, newInstance);
PHP_METHOD(Phalcon_Logger_LoggerFactory, getArrVal);
PHP_METHOD(Phalcon_Logger_LoggerFactory, getExceptionClass);
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_logger_loggerfactory___construct, 0, 0, 1)
ZEND_ARG_OBJ_INFO(0, factory, Phalcon\\Logger\\AdapterFactory, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_phalcon_logger_loggerfactory_load, 0, 1, Phalcon\\Logger\\Logger, 0)
ZEND_ARG_INFO(0, config)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_phalcon_logger_loggerfactory_newinstance, 0, 1, Phalcon\\Logger\\Logger, 0)
ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0)
#if PHP_VERSION_ID >= 80000
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, adapters, IS_ARRAY, 0, "[]")
#else
ZEND_ARG_ARRAY_INFO(0, adapters, 0)
#endif
ZEND_ARG_OBJ_INFO(0, timezone, DateTimeZone, 1)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_logger_loggerfactory_getarrval, 0, 0, 2)
ZEND_ARG_ARRAY_INFO(0, collection, 0)
ZEND_ARG_INFO(0, index)
ZEND_ARG_INFO(0, defaultValue)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_phalcon_logger_loggerfactory_getexceptionclass, 0, 0, IS_STRING, 0)
ZEND_END_ARG_INFO()
ZEPHIR_INIT_FUNCS(phalcon_logger_loggerfactory_method_entry) {
PHP_ME(Phalcon_Logger_LoggerFactory, __construct, arginfo_phalcon_logger_loggerfactory___construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
PHP_ME(Phalcon_Logger_LoggerFactory, load, arginfo_phalcon_logger_loggerfactory_load, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Logger_LoggerFactory, newInstance, arginfo_phalcon_logger_loggerfactory_newinstance, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Logger_LoggerFactory, getArrVal, arginfo_phalcon_logger_loggerfactory_getarrval, ZEND_ACC_PROTECTED)
PHP_ME(Phalcon_Logger_LoggerFactory, getExceptionClass, arginfo_phalcon_logger_loggerfactory_getexceptionclass, ZEND_ACC_PROTECTED)
PHP_FE_END
};
|
7b1110d8d098182a491d9bde7b7f59bdf01450b8
|
0744dcc5394cebf57ebcba343747af6871b67017
|
/external/iotivity/iotivity_1.2-rel/resource/csdk/security/provisioning/src/secureresourceprovider.c
|
797d0203230a2e9769c47fab2deef25c9cdcdd5a
|
[
"Apache-2.0",
"GPL-2.0-only",
"MIT",
"BSD-3-Clause"
] |
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
| 105,496
|
c
|
secureresourceprovider.c
|
/* *****************************************************************
*
* Copyright 2015 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.
*
* *****************************************************************/
#include "iotivity_config.h"
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include "ocprovisioningmanager.h"
#include "secureresourceprovider.h"
#include "logger.h"
#include "oic_malloc.h"
#include "oic_string.h"
#include "aclresource.h"
#include "pstatresource.h"
#include "srmresourcestrings.h"
#include "credresource.h"
#include "doxmresource.h"
#include "pconfresource.h"
#include "credentialgenerator.h"
#include "cainterface.h"
#if defined (__TIZENRT__)
#include <json/cJSON.h>
#else
#include "cJSON.h"
#endif
#include "pmtypes.h"
#include "pmutility.h"
#include "srmutility.h"
#include "provisioningdatabasemanager.h"
#include "base64.h"
#include "utlist.h"
#include "ocpayload.h"
#ifdef __WITH_DTLS__
#include "crlresource.h"
#endif // WITH_X509__
#define TAG "OIC_SRPAPI"
/**
* Macro to verify argument is not equal to NULL.
* eg: VERIFY_NON_NULL_RET(TAG, ptrData, ERROR,OC_STACK_ERROR);
*/
#define VERIFY_NON_NULL_RET(tag, arg, logLevel, retValue) { if (NULL == (arg)) \
{ OIC_LOG((logLevel), tag, #arg " is NULL"); return retValue; } }
/**
* Macro to verify success of operation.
* eg: VERIFY_SUCCESS_RET(TAG, OC_STACK_OK == foo(), ERROR, OC_STACK_ERROR);
*/
#define VERIFY_SUCCESS_RET(tag, op, logLevel, retValue) { if (!(op)) \
{OIC_LOG((logLevel), tag, #op " failed!!"); return retValue;} }
trustCertChainContext_t g_trustCertChainNotifier;
/**
* Structure to carry credential data to callback.
*/
typedef struct CredentialData CredentialData_t;
struct CredentialData
{
void *ctx; /**< Pointer to user context.**/
const OCProvisionDev_t *deviceInfo1; /**< Pointer to OCProvisionDev_t.**/
const OCProvisionDev_t *deviceInfo2; /**< Pointer to OCProvisionDev_t.**/
OicSecCred_t *credInfo; /**< Pointer to OicSecCred_t.**/
OicSecCred_t *credInfoFirst; /**< Pointer to OicSecCred_t.**/
OCProvisionResultCB resultCallback; /**< Pointer to result callback.**/
OCProvisionResult_t *resArr; /**< Result array.**/
int numOfResults; /**< Number of results in result array.**/
};
/**
* Structure to carry ACL provision API data to callback.
*/
typedef struct ACLData ACLData_t;
struct ACLData
{
void *ctx; /**< Pointer to user context.**/
const OCProvisionDev_t *deviceInfo; /**< Pointer to PMDevInfo_t.**/
OCProvisionResultCB resultCallback; /**< Pointer to result callback.**/
OCProvisionResult_t *resArr; /**< Result array.**/
int numOfResults; /**< Number of results in result array.**/
};
// Structure to carry get security resource APIs data to callback.
typedef struct GetSecData GetSecData_t;
struct GetSecData {
void *ctx;
const OCProvisionDev_t *deviceInfo; /**< Pointer to PMDevInfo_t.**/
OCProvisionResultCB resultCallback; /**< Pointer to result callback.**/
OCProvisionResult_t *resArr; /**< Result array.**/
int numOfResults; /**< Number of results in result array.**/
};
/**
* Structure to carry PCONF provision API data to callback.
*/
typedef struct PconfData PconfData_t;
struct PconfData
{
void *ctx; /**< Pointer to user context.**/
const OCProvisionDev_t *deviceInfo; /**< Pointer to PMDevInfo_t.**/
OCProvisionResultCB resultCallback; /**< Pointer to result callback.**/
OCProvisionResult_t *resArr; /**< Result array.**/
int numOfResults; /**< Number of results in result array.**/
};
// Enum type index for unlink callback.
typedef enum {
IDX_FIRST_DEVICE_RES = 0, // index for resulf of the first device
IDX_SECOND_DEVICE_RES, // index for result of the second device
IDX_DB_UPDATE_RES // index for result of updating provisioning database.
} IdxUnlinkRes_t;
// Structure to carry unlink APIs data to callback.
typedef struct UnlinkData UnlinkData_t;
struct UnlinkData {
void *ctx;
OCProvisionDev_t* unlinkDev; /**< Pointer to OCProvisionDev_t to be unlinked.**/
OCProvisionResult_t* unlinkRes; /**< Result array.**/
OCProvisionResultCB resultCallback; /**< Pointer to result callback.**/
int numOfResults; /**< Number of results in result array.**/
};
//Example of DELETE cred request -> coaps://0.0.0.0:5684/oic/sec/cred?sub=(BASE64 ENCODED UUID)
const char * SRP_FORM_DELETE_CREDENTIAL = "coaps://[%s]:%d%s?%s=%s";
const char * SRP_FORM_DELETE_CREDENTIAL_TCP = "coaps+tcp://[%s]:%d%s?%s=%s";
// Structure to carry remove APIs data to callback.
typedef struct RemoveData RemoveData_t;
struct RemoveData {
void *ctx;
OCProvisionDev_t* revokeTargetDev; /**< Device which is going to be revoked..**/
OCProvisionDev_t* linkedDevList; /**< A list of devices which have invalid credential.**/
OCProvisionResult_t* removeRes; /**< Result array.**/
OCProvisionResultCB resultCallback; /**< Pointer to result callback.**/
size_t numOfResults; /**< Number of results in result array.**/
size_t sizeOfResArray;
bool hasError;
};
/**
* Function prototype
*/
static OCStackResult provisionCredentials(const OicSecCred_t *cred,
const OCProvisionDev_t *deviceInfo, CredentialData_t *credData,
OCClientResponseHandler responseHandler);
/**
* Internal function to update result in result array.
*/
static void registerResultForCredProvisioning(CredentialData_t *credData,
OCStackResult stackresult, int cause)
{
OIC_LOG_V(INFO,TAG,"value of credData->numOfResults is %d",credData->numOfResults);
if(1 == cause)
{
memcpy(credData->resArr[(credData->numOfResults)].deviceId.id,
credData->deviceInfo1->doxm->deviceID.id,UUID_LENGTH);
}
else
{
memcpy(credData->resArr[(credData->numOfResults)].deviceId.id,
credData->deviceInfo2->doxm->deviceID.id,UUID_LENGTH);
}
credData->resArr[(credData->numOfResults)].res = stackresult;
++(credData->numOfResults);
}
/**
* Callback handler for handling callback of provisioning device 2.
*
* @param[in] ctx ctx value passed to callback from calling function.
* @param[in] UNUSED handle to an invocation
* @param[in] clientResponse Response from queries to remote servers.
* @return OC_STACK_DELETE_TRANSACTION to delete the transaction
* and OC_STACK_KEEP_TRANSACTION to keep it.
*/
static OCStackApplicationResult provisionCredentialCB2(void *ctx, OCDoHandle UNUSED,
OCClientResponse *clientResponse)
{
VERIFY_NON_NULL_RET(TAG, ctx, ERROR, OC_STACK_DELETE_TRANSACTION);
CredentialData_t *credData = (CredentialData_t *) ctx;
(void)UNUSED;
OCProvisionResultCB resultCallback = credData->resultCallback;
OIC_LOG(INFO, TAG, "provisionCredentialCB2 called");
if (clientResponse)
{
if(OC_STACK_RESOURCE_CHANGED == clientResponse->result)
{
registerResultForCredProvisioning(credData, OC_STACK_RESOURCE_CHANGED, 2);
OCStackResult res = PDMLinkDevices(&credData->deviceInfo1->doxm->deviceID,
&credData->deviceInfo2->doxm->deviceID);
if (OC_STACK_OK != res)
{
OIC_LOG(ERROR, TAG, "Error occured on PDMLinkDevices");
return OC_STACK_DELETE_TRANSACTION;
}
OIC_LOG(INFO, TAG, "Link created successfully");
((OCProvisionResultCB)(resultCallback))(credData->ctx, credData->numOfResults,
credData->resArr,
false);
OICFree(credData->resArr);
OICFree(credData);
return OC_STACK_DELETE_TRANSACTION;
}
}
OIC_LOG(INFO, TAG, "provisionCredentialCB2 received Null clientResponse");
registerResultForCredProvisioning(credData, OC_STACK_ERROR, 2);
((OCProvisionResultCB)(resultCallback))(credData->ctx, credData->numOfResults,
credData->resArr,
true);
OICFree(credData->resArr);
OICFree(credData);
return OC_STACK_DELETE_TRANSACTION;
}
/**
* Callback handler for handling callback of provisioning device 1.
*
* @param[in] ctx ctx value passed to callback from calling function.
* @param[in] UNUSED handle to an invocation
* @param[in] clientResponse Response from queries to remote servers.
* @return OC_STACK_DELETE_TRANSACTION to delete the transaction
* and OC_STACK_KEEP_TRANSACTION to keep it.
*/
static OCStackApplicationResult provisionCredentialCB1(void *ctx, OCDoHandle UNUSED,
OCClientResponse *clientResponse)
{
VERIFY_NON_NULL_RET(TAG, ctx, ERROR, OC_STACK_DELETE_TRANSACTION);
(void)UNUSED;
CredentialData_t* credData = (CredentialData_t*) ctx;
OICFree(credData->credInfoFirst);
const OCProvisionDev_t *deviceInfo = credData->deviceInfo2;
OicSecCred_t *credInfo = credData->credInfo;
const OCProvisionResultCB resultCallback = credData->resultCallback;
if (clientResponse)
{
if (OC_STACK_RESOURCE_CHANGED == clientResponse->result)
{
// send credentials to second device
registerResultForCredProvisioning(credData, OC_STACK_RESOURCE_CHANGED,1);
OCStackResult res = provisionCredentials(credInfo, deviceInfo, credData,
provisionCredentialCB2);
DeleteCredList(credInfo);
if (OC_STACK_OK != res)
{
registerResultForCredProvisioning(credData, res,2);
((OCProvisionResultCB)(resultCallback))(credData->ctx, credData->numOfResults,
credData->resArr,
true);
OICFree(credData->resArr);
OICFree(credData);
credData = NULL;
}
}
else
{
registerResultForCredProvisioning(credData, OC_STACK_ERROR,1);
((OCProvisionResultCB)(resultCallback))(credData->ctx, credData->numOfResults,
credData->resArr,
true);
OICFree(credData->resArr);
OICFree(credData);
credData = NULL;
}
}
else
{
OIC_LOG(INFO, TAG, "provisionCredentialCB received Null clientResponse for first device");
registerResultForCredProvisioning(credData, OC_STACK_ERROR,1);
((OCProvisionResultCB)(resultCallback))(credData->ctx, credData->numOfResults,
credData->resArr,
true);
DeleteCredList(credInfo);
OICFree(credData->resArr);
OICFree(credData);
credData = NULL;
}
return OC_STACK_DELETE_TRANSACTION;
}
/**
* Internal function for handling credential generation and sending credential to resource server.
*
* @param[in] cred Instance of cred resource.
* @param[in] deviceInfo information about device to which credential is to be provisioned.
* @param[in] responseHandler callbak called by OC stack when request API receives response.
* @return OC_STACK_OK in case of success and other value otherwise.
*/
static OCStackResult provisionCredentials(const OicSecCred_t *cred,
const OCProvisionDev_t *deviceInfo, CredentialData_t *credData,
OCClientResponseHandler responseHandler)
{
OCSecurityPayload* secPayload = (OCSecurityPayload*)OICCalloc(1, sizeof(OCSecurityPayload));
if (!secPayload)
{
OIC_LOG(ERROR, TAG, "Failed to memory allocation");
return OC_STACK_NO_MEMORY;
}
secPayload->base.type = PAYLOAD_TYPE_SECURITY;
int secureFlag = 0;
OCStackResult res = CredToCBORPayload(cred, &secPayload->securityData,
&secPayload->payloadSize, secureFlag);
if((OC_STACK_OK != res) && (NULL == secPayload->securityData))
{
OCPayloadDestroy((OCPayload *)secPayload);
OIC_LOG(ERROR, TAG, "Failed to CredToCBORPayload");
return OC_STACK_NO_MEMORY;
}
OIC_LOG(DEBUG, TAG, "Created payload for Cred:");
OIC_LOG_BUFFER(DEBUG, TAG, secPayload->securityData, secPayload->payloadSize);
char query[MAX_URI_LENGTH + MAX_QUERY_LENGTH] = {0};
if(!PMGenerateQuery(true,
deviceInfo->endpoint.addr,
deviceInfo->securePort,
deviceInfo->connType,
query, sizeof(query), OIC_RSRC_CRED_URI))
{
OIC_LOG(ERROR, TAG, "DeviceDiscoveryHandler : Failed to generate query");
OCPayloadDestroy((OCPayload *)secPayload);
return OC_STACK_ERROR;
}
OIC_LOG_V(DEBUG, TAG, "Query=%s", query);
OCCallbackData cbData = {.context=NULL, .cb=NULL, .cd=NULL};
cbData.cb = responseHandler;
cbData.context = (void *) credData;
cbData.cd = NULL;
OCDoHandle handle = NULL;
OCMethod method = OC_REST_POST;
OCStackResult ret = OCDoResource(&handle, method, query, 0, (OCPayload*)secPayload,
deviceInfo->connType, OC_HIGH_QOS, &cbData, NULL, 0);
OIC_LOG_V(INFO, TAG, "OCDoResource::Credential provisioning returned : %d",ret);
if (ret != OC_STACK_OK)
{
OIC_LOG(ERROR, TAG, "OCStack resource error");
return ret;
}
return OC_STACK_OK;
}
#if defined(__WITH_DTLS__) || defined(__WITH_TLS__)
/**
* Structure to carry certificate data to callback.
*/
typedef struct CertificateData CertData_t;
struct CertificateData
{
void *ctx; /**< Pointer to user context.**/
const OCProvisionDev_t *deviceInfo; /**< Pointer to OCProvisionDev_t.**/
OicSecCred_t *credInfo; /**< Pointer to OicSecCred_t.**/
OCProvisionResultCB resultCallback; /**< Pointer to result callback.**/
OCProvisionResult_t *resArr; /**< Result array.**/
int numOfResults; /**< Number of results in result array.**/
};
/**
* Internal function to update result in result array.
*/
static void registerResultForCertProvisioning(CertData_t *certData,
OCStackResult stackresult)
{
OIC_LOG_V(INFO,TAG,"value of credData->numOfResults is %d",certData->numOfResults);
memcpy(certData->resArr[(certData->numOfResults)].deviceId.id,
certData->deviceInfo->doxm->deviceID.id,UUID_LENGTH);
certData->resArr[(certData->numOfResults)].res = stackresult;
++(certData->numOfResults);
}
OCStackResult SRPRegisterTrustCertChainNotifier(void *ctx, TrustCertChainChangeCB callback)
{
if (g_trustCertChainNotifier.callback)
{
OIC_LOG(ERROR, TAG, "Can't register Notifier, Unregister previous one");
return OC_STACK_ERROR;
}
g_trustCertChainNotifier.callback = callback;
g_trustCertChainNotifier.context = ctx;
return OC_STACK_OK;
}
void SRPRemoveTrustCertChainNotifier()
{
g_trustCertChainNotifier.callback = NULL;
g_trustCertChainNotifier.context = NULL;
return;
}
/**
* Callback handler for handling callback of certificate provisioning device.
*
* @param[in] ctx ctx value passed to callback from calling function.
* @param[in] UNUSED handle to an invocation
* @param[in] clientResponse Response from queries to remote servers.
* @return OC_STACK_DELETE_TRANSACTION to delete the transaction
* and OC_STACK_KEEP_TRANSACTION to keep it.
*/
static OCStackApplicationResult provisionCertCB(void *ctx, OCDoHandle UNUSED,
OCClientResponse *clientResponse)
{
VERIFY_NON_NULL_RET(TAG, ctx, ERROR, OC_STACK_DELETE_TRANSACTION);
CertData_t *certData = (CertData_t *) ctx;
(void)UNUSED;
OCProvisionResultCB resultCallback = certData->resultCallback;
OIC_LOG(INFO, TAG, "provisionCertCB called");
if (clientResponse)
{
if(OC_STACK_RESOURCE_CHANGED == clientResponse->result)
{
registerResultForCertProvisioning(certData, OC_STACK_RESOURCE_CHANGED);
((OCProvisionResultCB)(resultCallback))(certData->ctx, certData->numOfResults,
certData->resArr,
false);
OICFree(certData->resArr);
OICFree(certData);
return OC_STACK_DELETE_TRANSACTION;
}
}
OIC_LOG(INFO, TAG, "provisionCertCredCB received Null clientResponse");
registerResultForCertProvisioning(certData, OC_STACK_ERROR);
((OCProvisionResultCB)(resultCallback))(certData->ctx, certData->numOfResults,
certData->resArr,
true);
OICFree(certData->resArr);
OICFree(certData);
return OC_STACK_DELETE_TRANSACTION;
}
OCStackResult SRPProvisionTrustCertChain(void *ctx, OicSecCredType_t type, uint16_t credId,
const OCProvisionDev_t *selectedDeviceInfo, OCProvisionResultCB resultCallback)
{
OIC_LOG(INFO, TAG, "In SRPProvisionTrustCertChain");
VERIFY_NON_NULL_RET(TAG, selectedDeviceInfo, ERROR, OC_STACK_INVALID_PARAM);
VERIFY_NON_NULL_RET(TAG, resultCallback, ERROR, OC_STACK_INVALID_CALLBACK);
if (SIGNED_ASYMMETRIC_KEY != type)
{
OIC_LOG(INFO, TAG, "Invalid key type");
return OC_STACK_INVALID_PARAM;
}
OicSecCred_t *trustCertChainCred = GetCredEntryByCredId(credId);
if(NULL == trustCertChainCred)
{
OIC_LOG(ERROR, TAG, "Can not find matched Trust Cert. Chain.");
return OC_STACK_NO_RESOURCE;
}
OCSecurityPayload* secPayload = (OCSecurityPayload*)OICCalloc(1, sizeof(OCSecurityPayload));
if(!secPayload)
{
DeleteCredList(trustCertChainCred);
OIC_LOG(ERROR, TAG, "Failed to memory allocation");
return OC_STACK_NO_MEMORY;
}
secPayload->base.type = PAYLOAD_TYPE_SECURITY;
int secureFlag = 0;
if(OC_STACK_OK != CredToCBORPayload(trustCertChainCred, &secPayload->securityData, &secPayload->payloadSize, secureFlag))
{
DeleteCredList(trustCertChainCred);
OCPayloadDestroy((OCPayload *)secPayload);
OIC_LOG(ERROR, TAG, "Failed to CredToCBORPayload");
return OC_STACK_NO_MEMORY;
}
DeleteCredList(trustCertChainCred);
OIC_LOG(DEBUG, TAG, "Created payload for Cred:");
OIC_LOG_BUFFER(DEBUG, TAG, secPayload->securityData, secPayload->payloadSize);
char query[MAX_URI_LENGTH + MAX_QUERY_LENGTH] = {0};
if(!PMGenerateQuery(true,
selectedDeviceInfo->endpoint.addr,
selectedDeviceInfo->securePort,
selectedDeviceInfo->connType,
query, sizeof(query), OIC_RSRC_CRED_URI))
{
OIC_LOG(ERROR, TAG, "SRPProvisionTrustCertChain : Failed to generate query");
OCPayloadDestroy((OCPayload *)secPayload);
return OC_STACK_ERROR;
}
OIC_LOG_V(DEBUG, TAG, "Query=%s", query);
OCCallbackData cbData = {.context=NULL, .cb=NULL, .cd=NULL};
cbData.cb = &provisionCertCB;
CertData_t *certData = (CertData_t *) OICCalloc(1, sizeof(CertData_t));
if (NULL == certData)
{
OIC_LOG(ERROR, TAG, "Memory allocation problem");
OCPayloadDestroy((OCPayload *)secPayload);
return OC_STACK_NO_MEMORY;
}
certData->deviceInfo = selectedDeviceInfo;
certData->resultCallback = resultCallback;
certData->credInfo = NULL; //credInfo not used in the response handler
certData->numOfResults=0;
certData->ctx = ctx;
int noOfRiCalls = 1;
certData->resArr = (OCProvisionResult_t*)OICCalloc(noOfRiCalls, sizeof(OCProvisionResult_t));
if (certData->resArr == NULL)
{
OICFree(certData);
OCPayloadDestroy((OCPayload *)secPayload);
OIC_LOG(ERROR, TAG, "Unable to allocate memory");
return OC_STACK_NO_MEMORY;
}
cbData.context = (void *)certData;
cbData.cd = NULL;
OCMethod method = OC_REST_POST;
OCDoHandle handle = NULL;
OIC_LOG(DEBUG, TAG, "Sending Cred info to resource server");
OCStackResult ret = OCDoResource(&handle, method, query,
&selectedDeviceInfo->endpoint, (OCPayload*)secPayload,
selectedDeviceInfo->connType, OC_HIGH_QOS, &cbData, NULL, 0);
if (ret != OC_STACK_OK)
{
OICFree(certData->resArr);
OICFree(certData);
}
VERIFY_SUCCESS_RET(TAG, (OC_STACK_OK == ret), ERROR, OC_STACK_ERROR);
return OC_STACK_OK;
}
OCStackResult SRPSaveTrustCertChain(uint8_t *trustCertChain, size_t chainSize,
OicEncodingType_t encodingType, uint16_t *credId)
{
OIC_LOG(DEBUG, TAG, "IN SRPSaveTrustCertChain");
VERIFY_NON_NULL_RET(TAG, trustCertChain, ERROR, OC_STACK_INVALID_PARAM);
VERIFY_NON_NULL_RET(TAG, credId, ERROR, OC_STACK_INVALID_PARAM);
OCStackResult res = OC_STACK_ERROR;
OicSecCred_t *cred = (OicSecCred_t *)OICCalloc(1, sizeof(*cred));
VERIFY_NON_NULL_RET(TAG, cred, ERROR, OC_STACK_NO_MEMORY);
res = GetDoxmDeviceID(&cred->subject);
if (OC_STACK_OK != res)
{
OIC_LOG(ERROR, TAG, "Cann't get the device id(GetDoxmDeviceID)");
DeleteCredList(cred);
return res;
}
cred->credUsage= (char *)OICCalloc(1, strlen(TRUST_CA)+1 );
VERIFY_NON_NULL_RET(TAG, cred->credUsage, ERROR, OC_STACK_NO_MEMORY);
OICStrcpy(cred->credUsage, strlen(TRUST_CA) + 1, TRUST_CA);
cred->credType = SIGNED_ASYMMETRIC_KEY;
if (encodingType == OIC_ENCODING_PEM)
{
cred->optionalData.data = (uint8_t *)OICCalloc(1, chainSize + 1);
VERIFY_NON_NULL_RET(TAG, cred->optionalData.data, ERROR, OC_STACK_NO_MEMORY);
cred->optionalData.len = chainSize + 1;
}
else
{
cred->optionalData.data = (uint8_t *)OICCalloc(1, chainSize);
VERIFY_NON_NULL_RET(TAG, cred->optionalData.data, ERROR, OC_STACK_NO_MEMORY);
cred->optionalData.len = chainSize;
}
memcpy(cred->optionalData.data, trustCertChain, chainSize);
cred->optionalData.encoding = encodingType;
cred->optionalData.revstat = false;
res = AddCredential(cred);
if(res != OC_STACK_OK)
{
DeleteCredList(cred);
return res;
}
*credId = cred->credId;
if (g_trustCertChainNotifier.callback)
{
uint8_t *certChain = (uint8_t*)OICCalloc(1, sizeof(uint8_t) * chainSize);
VERIFY_NON_NULL_RET(TAG, certChain, ERROR, OC_STACK_NO_MEMORY);
memcpy(certChain, trustCertChain, chainSize);
g_trustCertChainNotifier.callback(g_trustCertChainNotifier.context, *credId,
certChain, chainSize);
OICFree(certChain);
}
OIC_LOG(DEBUG, TAG, "OUT SRPSaveTrustCertChain");
return res;
}
OCStackResult SRPSaveOwnCertChain(OicSecKey_t * cert, OicSecKey_t * key, uint16_t *credId)
{
OIC_LOG_V(DEBUG, TAG, "In %s", __func__);
VERIFY_NON_NULL_RET(TAG, cert, ERROR, OC_STACK_INVALID_PARAM);
VERIFY_NON_NULL_RET(TAG, cert->data, ERROR, OC_STACK_INVALID_PARAM);
VERIFY_NON_NULL_RET(TAG, key, ERROR, OC_STACK_INVALID_PARAM);
VERIFY_NON_NULL_RET(TAG, key->data, ERROR, OC_STACK_INVALID_PARAM);
VERIFY_NON_NULL_RET(TAG, credId, ERROR, OC_STACK_INVALID_PARAM);
OCStackResult res = OC_STACK_ERROR;
OicSecCred_t *cred = (OicSecCred_t *)OICCalloc(1, sizeof(*cred));
VERIFY_NON_NULL_RET(TAG, cred, ERROR, OC_STACK_NO_MEMORY);
OIC_LOG_V(DEBUG, TAG, "IN: %s", __func__);
res = GetDoxmDeviceID(&cred->subject);
if (OC_STACK_OK != res)
{
OIC_LOG(ERROR, TAG, "Cann't get the device id(GetDoxmDeviceID)");
DeleteCredList(cred);
return res;
}
cred->credUsage= (char *)OICCalloc(1, strlen(PRIMARY_CERT)+1 );
VERIFY_NON_NULL_RET(TAG, cred->credUsage, ERROR, OC_STACK_NO_MEMORY);
OICStrcpy(cred->credUsage, strlen(PRIMARY_CERT) + 1, PRIMARY_CERT) ;
cred->credType = SIGNED_ASYMMETRIC_KEY;
OicSecKey_t *publicData = &cred->publicData;
publicData->data = (uint8_t *)OICCalloc(1, cert->len);
VERIFY_NON_NULL_RET(TAG, publicData->data, ERROR, OC_STACK_NO_MEMORY);
memcpy(publicData->data, cert->data, cert->len);
publicData->len = cert->len;
publicData->encoding = cert->encoding;
OicSecKey_t *privateData = &cred->privateData;
privateData->data = (uint8_t *)OICCalloc(1, key->len);
VERIFY_NON_NULL_RET(TAG, privateData->data, ERROR, OC_STACK_NO_MEMORY);
memcpy(privateData->data, key->data, key->len);
privateData->len = key->len;
privateData->encoding = key->encoding;
res = AddCredential(cred);
if(res != OC_STACK_OK)
{
DeleteCredList(cred);
return res;
}
*credId = cred->credId;
OIC_LOG_V(DEBUG, TAG, "Out %s", __func__);
return res;
}
#endif // __WITH_DTLS__ || __WITH_TLS__
OCStackResult SRPProvisionCredentials(void *ctx, OicSecCredType_t type, size_t keySize,
const OCProvisionDev_t *pDev1,
const OCProvisionDev_t *pDev2,
OCProvisionResultCB resultCallback)
{
VERIFY_NON_NULL_RET(TAG, pDev1, ERROR, OC_STACK_INVALID_PARAM);
if (SYMMETRIC_PAIR_WISE_KEY == type)
{
VERIFY_NON_NULL_RET(TAG, pDev2, ERROR, OC_STACK_INVALID_PARAM);
}
if (!resultCallback)
{
OIC_LOG(INFO, TAG, "SRPUnlinkDevices : NULL Callback");
return OC_STACK_INVALID_CALLBACK;
}
if (SYMMETRIC_PAIR_WISE_KEY == type &&
0 == memcmp(&pDev1->doxm->deviceID, &pDev2->doxm->deviceID, sizeof(OicUuid_t)))
{
OIC_LOG(INFO, TAG, "SRPUnlinkDevices : Same device ID");
return OC_STACK_INVALID_PARAM;
}
if (SYMMETRIC_PAIR_WISE_KEY == type &&
!(OWNER_PSK_LENGTH_128 == keySize || OWNER_PSK_LENGTH_256 == keySize))
{
OIC_LOG(INFO, TAG, "Invalid key size");
return OC_STACK_INVALID_PARAM;
}
OIC_LOG(INFO, TAG, "In SRPProvisionCredentials");
if (SYMMETRIC_PAIR_WISE_KEY == type)
{
bool linkExisits = true;
OCStackResult res = PDMIsLinkExists(&pDev1->doxm->deviceID, &pDev2->doxm->deviceID, &linkExisits);
if (res != OC_STACK_OK)
{
OIC_LOG(ERROR, TAG, "Internal error occured");
return res;
}
if (linkExisits)
{
OIC_LOG(ERROR, TAG, "Link already exists");
return OC_STACK_INVALID_PARAM;
}
}
OicUuid_t provTooldeviceID = {{0,}};
if (OC_STACK_OK != GetDoxmDeviceID(&provTooldeviceID))
{
OIC_LOG(ERROR, TAG, "Error while retrieving provisioning tool's device ID");
return OC_STACK_ERROR;
}
OIC_LOG(INFO, TAG, "retrieved deviceid");
switch (type)
{
case SYMMETRIC_PAIR_WISE_KEY:
{
const OCProvisionDev_t *firstDevice = pDev1;
const OCProvisionDev_t *secondDevice = pDev2;
OicSecCred_t *firstCred = NULL;
OicSecCred_t *secondCred = NULL;
OCStackResult res = PMGeneratePairWiseCredentials(type, keySize, &provTooldeviceID,
&firstDevice->doxm->deviceID, &secondDevice->doxm->deviceID,
&firstCred, &secondCred);
VERIFY_SUCCESS_RET(TAG, (res==OC_STACK_OK), ERROR, OC_STACK_ERROR);
OIC_LOG(INFO, TAG, "Credentials generated successfully");
CredentialData_t *credData =
(CredentialData_t *) OICCalloc(1, sizeof(CredentialData_t));
if (NULL == credData)
{
OICFree(firstCred);
OICFree(secondCred);
OIC_LOG(ERROR, TAG, "Memory allocation problem");
return OC_STACK_NO_MEMORY;
}
credData->deviceInfo1 = firstDevice;
credData->deviceInfo2 = secondDevice;
credData->credInfo = secondCred;
credData->ctx = ctx;
credData->credInfoFirst = firstCred;
credData->numOfResults = 0;
credData->resultCallback = resultCallback;
// first call to provision creds to device1.
// second call to provision creds to device2.
int noOfRiCalls = 2;
credData->resArr =
(OCProvisionResult_t*)OICCalloc(noOfRiCalls, sizeof(OCProvisionResult_t));
if (NULL == credData->resArr)
{
OICFree(firstCred);
OICFree(secondCred);
OICFree(credData);
OIC_LOG(ERROR, TAG, "Memory allocation problem");
return OC_STACK_NO_MEMORY;
}
res = provisionCredentials(firstCred, firstDevice, credData, &provisionCredentialCB1);
if (OC_STACK_OK != res)
{
DeleteCredList(firstCred);
DeleteCredList(secondCred);
OICFree(credData->resArr);
OICFree(credData);
}
OIC_LOG_V(INFO, TAG, "provisionCredentials returned: %d",res);
VERIFY_SUCCESS_RET(TAG, (res==OC_STACK_OK), ERROR, OC_STACK_ERROR);
return res;
}
default:
{
OIC_LOG(ERROR, TAG, "Invalid option.");
return OC_STACK_INVALID_PARAM;
}
}
return OC_STACK_ERROR;
}
/**
* Internal Function to store results in result array during ACL provisioning.
*/
static void registerResultForACLProvisioning(ACLData_t *aclData,
OCStackResult stackresult)
{
OIC_LOG_V(INFO, TAG, "Inside registerResultForACLProvisioning aclData->numOfResults is %d\n",
aclData->numOfResults);
memcpy(aclData->resArr[(aclData->numOfResults)].deviceId.id,
aclData->deviceInfo->doxm->deviceID.id, UUID_LENGTH);
aclData->resArr[(aclData->numOfResults)].res = stackresult;
++(aclData->numOfResults);
}
/**
* Callback handler of SRPProvisionACL.
*
* @param[in] ctx ctx value passed to callback from calling function.
* @param[in] UNUSED handle to an invocation
* @param[in] clientResponse Response from queries to remote servers.
* @return OC_STACK_DELETE_TRANSACTION to delete the transaction
* and OC_STACK_KEEP_TRANSACTION to keep it.
*/
static OCStackApplicationResult SRPProvisionACLCB(void *ctx, OCDoHandle UNUSED,
OCClientResponse *clientResponse)
{
OIC_LOG_V(INFO, TAG, "Inside SRPProvisionACLCB.");
(void)UNUSED;
VERIFY_NON_NULL_RET(TAG, ctx, ERROR, OC_STACK_DELETE_TRANSACTION);
ACLData_t *aclData = (ACLData_t*)ctx;
OCProvisionResultCB resultCallback = aclData->resultCallback;
if (clientResponse)
{
if(OC_STACK_RESOURCE_CHANGED == clientResponse->result)
{
registerResultForACLProvisioning(aclData, OC_STACK_RESOURCE_CHANGED);
((OCProvisionResultCB)(resultCallback))(aclData->ctx, aclData->numOfResults,
aclData->resArr,
false);
OICFree(aclData->resArr);
OICFree(aclData);
return OC_STACK_DELETE_TRANSACTION;
}
}
registerResultForACLProvisioning(aclData, OC_STACK_ERROR);
((OCProvisionResultCB)(resultCallback))(aclData->ctx, aclData->numOfResults,
aclData->resArr,
true);
OIC_LOG_V(ERROR, TAG, "SRPProvisionACLCB received Null clientResponse");
OICFree(aclData->resArr);
OICFree(aclData);
return OC_STACK_DELETE_TRANSACTION;
}
OCStackResult SRPProvisionACL(void *ctx, const OCProvisionDev_t *selectedDeviceInfo,
OicSecAcl_t *acl, OCProvisionResultCB resultCallback)
{
VERIFY_NON_NULL_RET(TAG, selectedDeviceInfo, ERROR, OC_STACK_INVALID_PARAM);
VERIFY_NON_NULL_RET(TAG, acl, ERROR, OC_STACK_INVALID_PARAM);
VERIFY_NON_NULL_RET(TAG, resultCallback, ERROR, OC_STACK_INVALID_CALLBACK);
// if rowneruuid is empty, set it to device ID
OicUuid_t emptyOwner = {.id = {0} };
if (memcmp(&(acl->rownerID.id), &emptyOwner, UUID_IDENTITY_SIZE) == 0)
{
OIC_LOG(DEBUG, TAG, "Set Rowner to PT's deviceId, because Rowner of ACL is empty");
OicUuid_t oicUuid;
if (OC_STACK_OK == GetDoxmDeviceID(&oicUuid))
{
memcpy(&(acl->rownerID.id), &oicUuid, UUID_IDENTITY_SIZE);
}
else
{
OIC_LOG(DEBUG, TAG, "Failed to set Rowner to PT's deviceID\
becuase it failed to retrieve Doxm DeviceID");
return OC_STACK_ERROR;
}
}
OCSecurityPayload* secPayload = (OCSecurityPayload*)OICCalloc(1, sizeof(OCSecurityPayload));
if(!secPayload)
{
OIC_LOG(ERROR, TAG, "Failed to memory allocation");
return OC_STACK_NO_MEMORY;
}
secPayload->base.type = PAYLOAD_TYPE_SECURITY;
if(OC_STACK_OK != AclToCBORPayload(acl, &secPayload->securityData, &secPayload->payloadSize))
{
OCPayloadDestroy((OCPayload *)secPayload);
OIC_LOG(ERROR, TAG, "Failed to AclToCBORPayload");
return OC_STACK_NO_MEMORY;
}
OIC_LOG(DEBUG, TAG, "Created payload for ACL:");
OIC_LOG_BUFFER(DEBUG, TAG, secPayload->securityData, secPayload->payloadSize);
char query[MAX_URI_LENGTH + MAX_QUERY_LENGTH] = {0};
if(!PMGenerateQuery(true,
selectedDeviceInfo->endpoint.addr,
selectedDeviceInfo->securePort,
selectedDeviceInfo->connType,
query, sizeof(query), OIC_RSRC_ACL_URI))
{
OIC_LOG(ERROR, TAG, "DeviceDiscoveryHandler : Failed to generate query");
return OC_STACK_ERROR;
}
OIC_LOG_V(DEBUG, TAG, "Query=%s", query);
OCCallbackData cbData = {.context=NULL, .cb=NULL, .cd=NULL};
cbData.cb = &SRPProvisionACLCB;
ACLData_t *aclData = (ACLData_t *) OICCalloc(1, sizeof(ACLData_t));
if (aclData == NULL)
{
OCPayloadDestroy((OCPayload *)secPayload);
OIC_LOG(ERROR, TAG, "Unable to allocate memory");
return OC_STACK_NO_MEMORY;
}
aclData->deviceInfo = selectedDeviceInfo;
aclData->resultCallback = resultCallback;
aclData->numOfResults=0;
aclData->ctx = ctx;
// call to provision ACL to device1.
int noOfRiCalls = 1;
aclData->resArr = (OCProvisionResult_t*)OICCalloc(noOfRiCalls, sizeof(OCProvisionResult_t));
if (aclData->resArr == NULL)
{
OICFree(aclData);
OCPayloadDestroy((OCPayload *)secPayload);
OIC_LOG(ERROR, TAG, "Unable to allocate memory");
return OC_STACK_NO_MEMORY;
}
cbData.context = (void *)aclData;
cbData.cd = NULL;
OCMethod method = OC_REST_POST;
OCDoHandle handle = NULL;
OIC_LOG(DEBUG, TAG, "Sending ACL info to resource server");
OCStackResult ret = OCDoResource(&handle, method, query,
&selectedDeviceInfo->endpoint, (OCPayload*)secPayload,
selectedDeviceInfo->connType, OC_HIGH_QOS, &cbData, NULL, 0);
if (ret != OC_STACK_OK)
{
OICFree(aclData->resArr);
OICFree(aclData);
}
VERIFY_SUCCESS_RET(TAG, (OC_STACK_OK == ret), ERROR, OC_STACK_ERROR);
return OC_STACK_OK;
}
OCStackResult SRPSaveACL(const OicSecAcl_t *acl)
{
OIC_LOG(DEBUG, TAG, "IN SRPSaveACL");
VERIFY_NON_NULL_RET(TAG, acl, ERROR, OC_STACK_INVALID_PARAM);
OCStackResult res = InstallACL(acl);
OIC_LOG(DEBUG, TAG, "OUT SRPSaveACL");
return res;
}
/**
* Internal Function to store results in result array during Direct-Pairing provisioning.
*/
static void registerResultForDirectPairingProvisioning(PconfData_t *pconfData,
OCStackResult stackresult)
{
OIC_LOG_V(INFO, TAG, "Inside registerResultForDirectPairingProvisioning "
"pconfData->numOfResults is %d\n", pconfData->numOfResults);
memcpy(pconfData->resArr[(pconfData->numOfResults)].deviceId.id,
pconfData->deviceInfo->doxm->deviceID.id, UUID_LENGTH);
pconfData->resArr[(pconfData->numOfResults)].res = stackresult;
++(pconfData->numOfResults);
}
/**
* Callback handler of SRPProvisionDirectPairing.
*
* @param[in] ctx ctx value passed to callback from calling function.
* @param[in] UNUSED handle to an invocation
* @param[in] clientResponse Response from queries to remote servers.
* @return OC_STACK_DELETE_TRANSACTION to delete the transaction
* and OC_STACK_KEEP_TRANSACTION to keep it.
*/
static OCStackApplicationResult SRPProvisionDirectPairingCB(void *ctx, OCDoHandle UNUSED,
OCClientResponse *clientResponse)
{
OIC_LOG_V(INFO, TAG, "Inside SRPProvisionDirectPairingCB.");
(void)UNUSED;
VERIFY_NON_NULL_RET(TAG, ctx, ERROR, OC_STACK_DELETE_TRANSACTION);
PconfData_t *pconfData = (PconfData_t*)ctx;
OCProvisionResultCB resultCallback = pconfData->resultCallback;
if (clientResponse)
{
if(OC_STACK_RESOURCE_CHANGED == clientResponse->result)
{
registerResultForDirectPairingProvisioning(pconfData, OC_STACK_OK);
((OCProvisionResultCB)(resultCallback))(pconfData->ctx, pconfData->numOfResults,
pconfData->resArr,
false);
OICFree(pconfData->resArr);
OICFree(pconfData);
return OC_STACK_DELETE_TRANSACTION;
}
}
registerResultForDirectPairingProvisioning(pconfData, OC_STACK_ERROR);
((OCProvisionResultCB)(resultCallback))(pconfData->ctx, pconfData->numOfResults,
pconfData->resArr,
true);
OIC_LOG_V(ERROR, TAG, "SRPProvisionDirectPairingCB received Null clientResponse");
OICFree(pconfData->resArr);
OICFree(pconfData);
return OC_STACK_DELETE_TRANSACTION;
}
OCStackResult SRPProvisionDirectPairing(void *ctx, const OCProvisionDev_t *selectedDeviceInfo,
OicSecPconf_t *pconf, OCProvisionResultCB resultCallback)
{
VERIFY_NON_NULL_RET(TAG, selectedDeviceInfo, ERROR, OC_STACK_INVALID_PARAM);
VERIFY_NON_NULL_RET(TAG, pconf, ERROR, OC_STACK_INVALID_PARAM);
VERIFY_NON_NULL_RET(TAG, resultCallback, ERROR, OC_STACK_INVALID_CALLBACK);
// check direct-pairing capability
if (true != selectedDeviceInfo->doxm->dpc)
{
OIC_LOG(ERROR, TAG, "Resouce server does not have Direct-Pairing Capability ");
return OC_STACK_UNAUTHORIZED_REQ;
}
OicUuid_t provTooldeviceID = {.id={0}};
if (OC_STACK_OK != GetDoxmDeviceID(&provTooldeviceID))
{
OIC_LOG(ERROR, TAG, "Error while retrieving provisioning tool's device ID");
return OC_STACK_ERROR;
}
memcpy(&pconf->rownerID, &provTooldeviceID, sizeof(OicUuid_t));
OCSecurityPayload* secPayload = (OCSecurityPayload*)OICCalloc(1, sizeof(OCSecurityPayload));
if(!secPayload)
{
OIC_LOG(ERROR, TAG, "Failed to memory allocation");
return OC_STACK_NO_MEMORY;
}
secPayload->base.type = PAYLOAD_TYPE_SECURITY;
if (OC_STACK_OK != PconfToCBORPayload(pconf, &(secPayload->securityData),
&(secPayload->payloadSize)))
{
OCPayloadDestroy((OCPayload*)secPayload);
OIC_LOG(ERROR, TAG, "Failed to PconfToCborPayload");
return OC_STACK_NO_MEMORY;
}
OIC_LOG(DEBUG, TAG, "Created payload for pconf set");
OIC_LOG_BUFFER(DEBUG, TAG, secPayload->securityData, secPayload->payloadSize);
char query[MAX_URI_LENGTH + MAX_QUERY_LENGTH] = {0};
if(!PMGenerateQuery(true,
selectedDeviceInfo->endpoint.addr,
selectedDeviceInfo->securePort,
selectedDeviceInfo->connType,
query, sizeof(query), OIC_RSRC_PCONF_URI))
{
OIC_LOG(ERROR, TAG, "SRPProvisionDirectPairing : Failed to generate query");
return OC_STACK_ERROR;
}
OIC_LOG_V(DEBUG, TAG, "Query=%s", query);
OCCallbackData cbData = {.context=NULL, .cb=NULL, .cd=NULL};
cbData.cb = &SRPProvisionDirectPairingCB;
PconfData_t *pconfData = (PconfData_t *) OICCalloc(1, sizeof(PconfData_t));
if (NULL == pconfData)
{
OCPayloadDestroy((OCPayload*)secPayload);
OIC_LOG(ERROR, TAG, "Unable to allocate memory");
return OC_STACK_NO_MEMORY;
}
pconfData->deviceInfo = selectedDeviceInfo;
pconfData->resultCallback = resultCallback;
pconfData->numOfResults=0;
pconfData->ctx = ctx;
// call to provision PCONF to device1.
int noOfRiCalls = 1;
pconfData->resArr = (OCProvisionResult_t*)OICCalloc(noOfRiCalls, sizeof(OCProvisionResult_t));
if (NULL == pconfData->resArr)
{
OICFree(pconfData);
OCPayloadDestroy((OCPayload*)secPayload);
OIC_LOG(ERROR, TAG, "Unable to allocate memory");
return OC_STACK_NO_MEMORY;
}
cbData.context = (void *)pconfData;
cbData.cd = NULL;
OCMethod method = OC_REST_POST;
OCDoHandle handle = NULL;
OIC_LOG(DEBUG, TAG, "Sending PCONF info to resource server");
OCStackResult ret = OCDoResource(&handle, method, query,
&selectedDeviceInfo->endpoint, (OCPayload*)secPayload,
selectedDeviceInfo->connType, OC_HIGH_QOS, &cbData, NULL, 0);
if (OC_STACK_OK != ret)
{
OICFree(pconfData->resArr);
OICFree(pconfData);
}
VERIFY_SUCCESS_RET(TAG, (OC_STACK_OK == ret), ERROR, OC_STACK_ERROR);
return OC_STACK_OK;
}
static void DeleteUnlinkData_t(UnlinkData_t *unlinkData)
{
if (unlinkData)
{
OICFree(unlinkData->unlinkDev);
OICFree(unlinkData->unlinkRes);
OICFree(unlinkData);
}
}
static void registerResultForUnlinkDevices(UnlinkData_t *unlinkData, OCStackResult stackresult,
IdxUnlinkRes_t idx)
{
if (NULL != unlinkData)
{
OIC_LOG_V(INFO, TAG, "Inside registerResultForUnlinkDevices unlinkData->numOfResults is %d\n",
unlinkData->numOfResults);
OIC_LOG_V(INFO, TAG, "Stack result :: %d", stackresult);
OicUuid_t *pUuid = &unlinkData->unlinkRes[(unlinkData->numOfResults)].deviceId;
// Set result in the result array according to the position (devNum).
if (idx != IDX_DB_UPDATE_RES)
{
memcpy(pUuid->id, unlinkData->unlinkDev[idx].doxm->deviceID.id, sizeof(pUuid->id));
}
else
{ // When deivce ID is 000... this means it's the result of database update.
memset(pUuid->id, 0, sizeof(pUuid->id));
}
unlinkData->unlinkRes[(unlinkData->numOfResults)].res = stackresult;
++(unlinkData->numOfResults);
OIC_LOG (INFO, TAG, "Out registerResultForUnlinkDevices");
}
}
static OCStackResult SendDeleteCredentialRequest(void* ctx,
OCClientResponseHandler respHandler,
const OCProvisionDev_t* revokedDev,
const OCProvisionDev_t* destDev)
{
OIC_LOG(DEBUG, TAG, "IN SendDeleteCredentialRequest");
if (NULL == ctx || NULL == respHandler || NULL == revokedDev || NULL == destDev)
{
return OC_STACK_INVALID_PARAM;
}
char *subID = NULL;
OCStackResult ret = ConvertUuidToStr(&revokedDev->doxm->deviceID, &subID);
if(OC_STACK_OK != ret)
{
OIC_LOG(ERROR, TAG, "SendDeleteCredentialRequest : Failed to canonical UUID encoding");
return OC_STACK_ERROR;
}
char addressEncoded[CA_MAX_URI_LENGTH] = {0};
OCStackResult result = OCEncodeAddressForRFC6874(addressEncoded,
sizeof(addressEncoded),
destDev->endpoint.addr);
if (OC_STACK_OK != result)
{
OIC_LOG_V(ERROR, TAG, "SendDeleteCredentialRequest : encoding error %d\n", result);
return OC_STACK_ERROR;
}
char reqBuf[MAX_URI_LENGTH + MAX_QUERY_LENGTH] = {0};
int snRet = 0;
//coaps://0.0.0.0:5684/oic/sec/cred?subjectid=(Canonical ENCODED UUID)
const char *srpUri = SRP_FORM_DELETE_CREDENTIAL;
#ifdef __WITH_TLS__
if(CA_ADAPTER_TCP == destDev->endpoint.adapter)
{
srpUri = SRP_FORM_DELETE_CREDENTIAL_TCP;
}
#endif
snRet = snprintf(reqBuf, sizeof(reqBuf), srpUri, addressEncoded,
destDev->securePort, OIC_RSRC_CRED_URI, OIC_JSON_SUBJECTID_NAME, subID);
OICFree(subID);
if (snRet < 0)
{
OIC_LOG_V(ERROR, TAG, "SendDeleteCredentialRequest : Error (snprintf) %d\n", snRet);
return OC_STACK_ERROR;
}
else if ((size_t)snRet >= sizeof(reqBuf))
{
OIC_LOG_V(ERROR, TAG, "SendDeleteCredentialRequest : Truncated (snprintf) %d\n", snRet);
return OC_STACK_ERROR;
}
OCCallbackData cbData;
memset(&cbData, 0, sizeof(cbData));
cbData.context = ctx;
cbData.cb = respHandler;
cbData.cd = NULL;
OIC_LOG_V(INFO, TAG, "URI: %s",reqBuf);
OIC_LOG(DEBUG, TAG, "Sending remove credential request to resource server");
ret = OCDoResource(NULL, OC_REST_DELETE, reqBuf,
&destDev->endpoint, NULL,
CT_ADAPTER_IP, OC_HIGH_QOS, &cbData, NULL, 0);
if (OC_STACK_OK != ret)
{
OIC_LOG_V(ERROR, TAG, "SendDeleteCredentialRequest : Error in OCDoResource %d", ret);
}
OIC_LOG(DEBUG, TAG, "OUT SendDeleteCredentialRequest");
return ret;
}
static OCStackResult SendDeleteACLRequest(void* ctx,
OCClientResponseHandler respHandler,
const OCProvisionDev_t* revokedDev,
const OCProvisionDev_t* destDev)
{
OIC_LOG(DEBUG, TAG, "IN SendDeleteACLRequest");
if (NULL == ctx || NULL == respHandler || NULL == revokedDev || NULL == destDev)
{
return OC_STACK_INVALID_PARAM;
}
char *subID = NULL;
OCStackResult ret = ConvertUuidToStr(&revokedDev->doxm->deviceID, &subID);
if(OC_STACK_OK != ret)
{
OIC_LOG(ERROR, TAG, "SendDeleteACLRequest : Failed to canonical UUID encoding");
return OC_STACK_ERROR;
}
char addressEncoded[CA_MAX_URI_LENGTH] = {0};
OCStackResult result = OCEncodeAddressForRFC6874(addressEncoded,
sizeof(addressEncoded),
destDev->endpoint.addr);
if (OC_STACK_OK != result)
{
OIC_LOG_V(ERROR, TAG, "SendDeleteCredentialRequest : encoding error %d\n", result);
return OC_STACK_ERROR;
}
char reqBuf[MAX_URI_LENGTH + MAX_QUERY_LENGTH] = {0};
int snRet = 0;
//coaps://0.0.0.0:5684/oic/sec/acl?subjectuuid=(Canonical ENCODED UUID)
snRet = snprintf(reqBuf, sizeof(reqBuf), SRP_FORM_DELETE_CREDENTIAL, addressEncoded,
destDev->securePort, OIC_RSRC_ACL_URI, OIC_JSON_SUBJECTID_NAME, subID);
OICFree(subID);
if (snRet < 0)
{
OIC_LOG_V(ERROR, TAG, "SendDeleteACLRequest : Error (snprintf) %d\n", snRet);
return OC_STACK_ERROR;
}
else if ((size_t)snRet >= sizeof(reqBuf))
{
OIC_LOG_V(ERROR, TAG, "SendDeleteACLRequest : Truncated (snprintf) %d\n", snRet);
return OC_STACK_ERROR;
}
OCCallbackData cbData;
memset(&cbData, 0, sizeof(cbData));
cbData.context = ctx;
cbData.cb = respHandler;
cbData.cd = NULL;
OIC_LOG_V(INFO, TAG, "URI: %s",reqBuf);
OIC_LOG(DEBUG, TAG, "Sending remove ACL request to resource server");
ret = OCDoResource(NULL, OC_REST_DELETE, reqBuf,
&destDev->endpoint, NULL,
CT_ADAPTER_IP, OC_HIGH_QOS, &cbData, NULL, 0);
if (OC_STACK_OK != ret)
{
OIC_LOG_V(ERROR, TAG, "SendDeleteACLRequest : Error in OCDoResource %d", ret);
}
OIC_LOG(DEBUG, TAG, "OUT SendDeleteACLRequest");
return ret;
}
/**
* Callback handler of unlink second device.
*
* @param[in] ctx ctx value passed to callback from calling function.
* @param[in] handle handle to an invocation
* @param[in] clientResponse Response from queries to remote servers.
* @return OC_STACK_DELETE_TRANSACTION to delete the transaction and
* OC_STACK_KEEP_TRANSACTION to keep it.
*/
static OCStackApplicationResult SRPUnlinkDevice2CB(void *unlinkCtx, OCDoHandle handle,
OCClientResponse *clientResponse)
{
(void) handle;
OIC_LOG(DEBUG, TAG, "IN SRPUnlinkDevice2CB");
VERIFY_NON_NULL_RET(TAG, unlinkCtx, ERROR, OC_STACK_DELETE_TRANSACTION);
UnlinkData_t* unlinkData = (UnlinkData_t*)unlinkCtx;
if (clientResponse)
{
OIC_LOG(DEBUG, TAG, "Valid client response for device 2");
registerResultForUnlinkDevices(unlinkData, clientResponse->result, IDX_SECOND_DEVICE_RES);
if (OC_STACK_RESOURCE_DELETED == clientResponse->result)
{
OIC_LOG(DEBUG, TAG, "Credential of device2 revoked");
}
else
{
OIC_LOG(ERROR, TAG, "Unable to delete credential information from device 2");
unlinkData->resultCallback(unlinkData->ctx,
unlinkData->numOfResults, unlinkData->unlinkRes, true);
goto error;
}
}
else
{
registerResultForUnlinkDevices(unlinkData, OC_STACK_INVALID_REQUEST_HANDLE,
IDX_SECOND_DEVICE_RES);
unlinkData->resultCallback(unlinkData->ctx,
unlinkData->numOfResults, unlinkData->unlinkRes, true);
OIC_LOG(ERROR, TAG, "SRPUnlinkDevice2CB received Null clientResponse");
goto error;
}
//Update provisioning DB when succes case.
if (OC_STACK_OK != PDMUnlinkDevices(&unlinkData->unlinkDev[0].doxm->deviceID,
&unlinkData->unlinkDev[1].doxm->deviceID))
{
OIC_LOG(FATAL, TAG, "All requests are successfully done but update provisioning DB FAILED.");
registerResultForUnlinkDevices(unlinkData, OC_STACK_INCONSISTENT_DB, IDX_DB_UPDATE_RES);
unlinkData->resultCallback(unlinkData->ctx,
unlinkData->numOfResults, unlinkData->unlinkRes, true);
goto error;
}
unlinkData->resultCallback(unlinkData->ctx, unlinkData->numOfResults, unlinkData->unlinkRes,
false);
error:
DeleteUnlinkData_t(unlinkData);
OIC_LOG(DEBUG, TAG, "OUT SRPUnlinkDevice2CB");
return OC_STACK_DELETE_TRANSACTION;
}
/**
* Callback handler of unlink first device.
*
* @param[in] ctx ctx value passed to callback from calling function.
* @param[in] handle handle to an invocation
* @param[in] clientResponse Response from queries to remote servers.
* @return OC_STACK_DELETE_TRANSACTION to delete the transaction and
* OC_STACK_KEEP_TRANSACTION to keep it.
*/
static OCStackApplicationResult SRPUnlinkDevice1CB(void *unlinkCtx, OCDoHandle handle,
OCClientResponse *clientResponse)
{
OIC_LOG_V(INFO, TAG, "Inside SRPUnlinkDevice1CB ");
VERIFY_NON_NULL_RET(TAG, unlinkCtx, ERROR, OC_STACK_DELETE_TRANSACTION);
UnlinkData_t* unlinkData = (UnlinkData_t*)unlinkCtx;
(void) handle;
if (clientResponse)
{
OIC_LOG(DEBUG, TAG, "Valid client response for device 1");
registerResultForUnlinkDevices(unlinkData, clientResponse->result, IDX_FIRST_DEVICE_RES);
if (OC_STACK_RESOURCE_DELETED == clientResponse->result)
{
OIC_LOG(DEBUG, TAG, "Credential of device 1 is revoked");
// Second revocation request to second device.
OCStackResult res = SendDeleteCredentialRequest((void*)unlinkData, &SRPUnlinkDevice2CB,
&unlinkData->unlinkDev[0],
&unlinkData->unlinkDev[1] /*Dest*/);
OIC_LOG_V(DEBUG, TAG, "Credential revocation request device 2, result :: %d",res);
if (OC_STACK_OK != res)
{
OIC_LOG(ERROR, TAG, "Error while sending revocation request for device 2");
registerResultForUnlinkDevices(unlinkData, OC_STACK_INVALID_REQUEST_HANDLE,
IDX_SECOND_DEVICE_RES);
unlinkData->resultCallback(unlinkData->ctx,
unlinkData->numOfResults, unlinkData->unlinkRes, true);
goto error;
}
else
{
OIC_LOG(DEBUG, TAG, "Request for credential revocation successfully sent");
return OC_STACK_DELETE_TRANSACTION;
}
}
else
{
OIC_LOG(ERROR, TAG, "Unable to delete credential information from device 1");
unlinkData->resultCallback(unlinkData->ctx, unlinkData->numOfResults,
unlinkData->unlinkRes, true);
goto error;
}
}
else
{
OIC_LOG(DEBUG, TAG, "Invalid response from server");
registerResultForUnlinkDevices(unlinkData, OC_STACK_INVALID_REQUEST_HANDLE,
IDX_FIRST_DEVICE_RES );
unlinkData->resultCallback(unlinkData->ctx,
unlinkData->numOfResults, unlinkData->unlinkRes,
true);
OIC_LOG(ERROR, TAG, "SRPUnlinkDevice1CB received Null clientResponse");
}
error:
OIC_LOG_V(INFO, TAG, "Out SRPUnlinkDevice1CB");
DeleteUnlinkData_t(unlinkData);
return OC_STACK_DELETE_TRANSACTION;
}
/*
* Function to unlink devices.
* This function will remove the credential & relationship between the two devices.
*
* @param[in] ctx Application context would be returned in result callback
* @param[in] pTargetDev1 first device information to be unlinked.
* @param[in] pTargetDev2 second device information to be unlinked.
* @param[in] resultCallback callback provided by API user, callback will be called when
* device unlink is finished.
* @return OC_STACK_OK in case of success and other value otherwise.
*/
OCStackResult SRPUnlinkDevices(void* ctx,
const OCProvisionDev_t* pTargetDev1,
const OCProvisionDev_t* pTargetDev2,
OCProvisionResultCB resultCallback)
{
OIC_LOG(INFO, TAG, "IN SRPUnlinkDevices");
if (!pTargetDev1 || !pTargetDev2 || !pTargetDev1->doxm || !pTargetDev2->doxm)
{
OIC_LOG(INFO, TAG, "SRPUnlinkDevices : NULL parameters");
return OC_STACK_INVALID_PARAM;
}
if (!resultCallback)
{
OIC_LOG(INFO, TAG, "SRPUnlinkDevices : NULL Callback");
return OC_STACK_INVALID_CALLBACK;
}
if (0 == memcmp(&pTargetDev1->doxm->deviceID, &pTargetDev2->doxm->deviceID, sizeof(OicUuid_t)))
{
OIC_LOG(INFO, TAG, "SRPUnlinkDevices : Same device ID");
return OC_STACK_INVALID_PARAM;
}
OIC_LOG(INFO, TAG, "Unlinking following devices: ");
PMPrintOCProvisionDev(pTargetDev1);
PMPrintOCProvisionDev(pTargetDev2);
// Mark the link status stale
OCStackResult res = PDMSetLinkStale(&pTargetDev1->doxm->deviceID, &pTargetDev2->doxm->deviceID);
if (OC_STACK_OK != res)
{
OIC_LOG(FATAL, TAG, "unable to update DB. Try again.");
return res;
}
UnlinkData_t* unlinkData = (UnlinkData_t*)OICCalloc(1, sizeof(UnlinkData_t));
VERIFY_NON_NULL_RET(TAG, unlinkData, ERROR, OC_STACK_NO_MEMORY);
//Initialize unlink data
unlinkData->ctx = ctx;
unlinkData->unlinkDev = (OCProvisionDev_t*)OICCalloc(2, sizeof(OCProvisionDev_t));
if (NULL == unlinkData->unlinkDev)
{
OIC_LOG(ERROR, TAG, "Memory allocation failed");
res = OC_STACK_NO_MEMORY;
goto error;
}
unlinkData->unlinkRes = (OCProvisionResult_t*)OICCalloc(3, sizeof(OCProvisionResult_t));
if (NULL == unlinkData->unlinkRes)
{
OIC_LOG(ERROR, TAG, "Memory allocation failed");
res = OC_STACK_NO_MEMORY;
goto error;
}
memcpy(&unlinkData->unlinkDev[0], pTargetDev1, sizeof(OCProvisionDev_t));
memcpy(&unlinkData->unlinkDev[1], pTargetDev2, sizeof(OCProvisionDev_t));
unlinkData->numOfResults = 0;
unlinkData->resultCallback = resultCallback;
res = SendDeleteCredentialRequest((void*)unlinkData, &SRPUnlinkDevice1CB,
&unlinkData->unlinkDev[1], &unlinkData->unlinkDev[0]);
if (OC_STACK_OK != res)
{
OIC_LOG(ERROR, TAG, "SRPUnlinkDevices : SendDeleteCredentialRequest failed");
goto error;
}
return res;
error:
OIC_LOG(INFO, TAG, "OUT SRPUnlinkDevices");
DeleteUnlinkData_t(unlinkData);
return res;
}
static void DeleteRemoveData_t(RemoveData_t* pRemoveData)
{
if (pRemoveData)
{
OICFree(pRemoveData->revokeTargetDev);
OCDeleteDiscoveredDevices(pRemoveData->linkedDevList);
OICFree(pRemoveData->removeRes);
OICFree(pRemoveData);
}
}
static void registerResultForRemoveDevice(RemoveData_t *removeData, OicUuid_t *pLinkedDevId,
OCStackResult stackresult, bool hasError)
{
OIC_LOG_V(INFO, TAG, "Inside registerResultForRemoveDevice removeData->numOfResults is %zu\n",
removeData->numOfResults + 1);
if (pLinkedDevId)
{
memcpy(removeData->removeRes[(removeData->numOfResults)].deviceId.id,
&pLinkedDevId->id, sizeof(pLinkedDevId->id));
}
else
{
memset(removeData->removeRes[(removeData->numOfResults)].deviceId.id,
0, sizeof(pLinkedDevId->id) );
}
removeData->removeRes[(removeData->numOfResults)].res = stackresult;
removeData->hasError = hasError;
++(removeData->numOfResults);
// If we get suffcient result from linked devices, we have to call user callback and do free
if (removeData->sizeOfResArray == removeData->numOfResults)
{
if(!removeData->hasError)
{
// Remove device info from prvisioning database
if (OC_STACK_OK != PDMDeleteDevice(&removeData->revokeTargetDev->doxm->deviceID))
{
OIC_LOG(ERROR, TAG, "ResultForRemoveDevice : Failed to remove device in PDM.");
removeData->hasError = true;
}
}
removeData->resultCallback(removeData->ctx, removeData->numOfResults, removeData->removeRes,
removeData->hasError);
DeleteRemoveData_t(removeData);
}
}
static void registerResultForResetDevice(RemoveData_t *removeData, OicUuid_t *pLinkedDevId,
OCStackResult stackresult, bool hasError)
{
OIC_LOG_V(INFO, TAG, "Inside registerResultForResetDevice removeData->numOfResults is %zu\n",
removeData->numOfResults + 1);
if (pLinkedDevId)
{
memcpy(removeData->removeRes[(removeData->numOfResults)].deviceId.id,
&pLinkedDevId->id, sizeof(pLinkedDevId->id));
}
else
{
memset(removeData->removeRes[(removeData->numOfResults)].deviceId.id,
0, sizeof(pLinkedDevId->id) );
}
removeData->removeRes[(removeData->numOfResults)].res = stackresult;
removeData->hasError = hasError;
++(removeData->numOfResults);
// If we get suffcient result from linked devices, we have to call user callback and do free
if (removeData->sizeOfResArray == removeData->numOfResults)
{
removeData->resultCallback(removeData->ctx, removeData->numOfResults, removeData->removeRes,
removeData->hasError);
DeleteRemoveData_t(removeData);
}
}
/**
* Callback handler of unlink first device.
*
* @param[in] ctx ctx value passed to callback from calling function.
* @param[in] handle handle to an invocation
* @param[in] clientResponse Response from queries to remote servers.
* @return OC_STACK_DELETE_TRANSACTION to delete the transaction
* and OC_STACK_KEEP_TRANSACTION to keep it.
*/
static OCStackApplicationResult SRPRemoveDeviceCB(void *delDevCtx, OCDoHandle handle,
OCClientResponse *clientResponse)
{
//Update the delete credential into delete device context
//Save the deleted status in delDevCtx
(void)handle;
OIC_LOG_V(INFO, TAG, "Inside SRPRemoveDeviceCB.");
VERIFY_NON_NULL_RET(TAG, delDevCtx, ERROR, OC_STACK_DELETE_TRANSACTION);
OCStackResult res = OC_STACK_ERROR;
RemoveData_t* removeData = (RemoveData_t*)delDevCtx;
if (clientResponse)
{
OicUuid_t revDevUuid = {.id={0}};
if(UUID_LENGTH == clientResponse->identity.id_length)
{
memcpy(revDevUuid.id, clientResponse->identity.id, sizeof(revDevUuid.id));
if (OC_STACK_RESOURCE_DELETED == clientResponse->result)
{
res = PDMUnlinkDevices(&removeData->revokeTargetDev->doxm->deviceID, &revDevUuid);
if (OC_STACK_OK != res)
{
OIC_LOG(ERROR, TAG, "PDMSetLinkStale() FAIL: PDB is an obsolete one.");
registerResultForRemoveDevice(removeData, &revDevUuid,
OC_STACK_INCONSISTENT_DB, true);
return OC_STACK_DELETE_TRANSACTION;
}
registerResultForRemoveDevice(removeData, &revDevUuid,
OC_STACK_RESOURCE_DELETED, false);
}
else
{
registerResultForRemoveDevice(removeData, &revDevUuid,
clientResponse->result, true);
OIC_LOG(ERROR, TAG, "Unexpected result from DELETE credential request!");
}
}
else
{
OIC_LOG_V(WARNING, TAG, "Incorrect length of device UUID was sent from %s:%d",
clientResponse->devAddr.addr, clientResponse->devAddr.port);
if (OC_STACK_RESOURCE_DELETED == clientResponse->result)
{
/**
* Since server's credential was deleted,
* register result as OC_STACK_INCONSISTENT_DB with NULL UUID.
*/
OIC_LOG_V(ERROR, TAG, "But server's credential was deleted.");
registerResultForRemoveDevice(removeData, NULL, OC_STACK_INCONSISTENT_DB, true);
}
else
{
registerResultForRemoveDevice(removeData, NULL, clientResponse->result, true);
}
}
}
else
{
registerResultForRemoveDevice(removeData, NULL, OC_STACK_ERROR, true);
OIC_LOG(ERROR, TAG, "SRPRemoveDevices received Null clientResponse");
}
return OC_STACK_DELETE_TRANSACTION;
}
/**
* Callback handler of reset device.
*
* @param[in] ctx ctx value passed to callback from calling function.
* @param[in] handle handle to an invocation
* @param[in] clientResponse Response from queries to remote servers.
* @return OC_STACK_DELETE_TRANSACTION to delete the transaction
* and OC_STACK_KEEP_TRANSACTION to keep it.
*/
static OCStackApplicationResult SRPSyncDeviceCredCB(void *delDevCtx, OCDoHandle handle,
OCClientResponse *clientResponse)
{
//Update the delete credential into delete device context
//Save the deleted status in delDevCtx
(void)handle;
OIC_LOG_V(INFO, TAG, "Inside SRPSyncDeviceCredCB.");
VERIFY_NON_NULL_RET(TAG, delDevCtx, ERROR, OC_STACK_DELETE_TRANSACTION);
OCStackResult res = OC_STACK_ERROR;
RemoveData_t* removeData = (RemoveData_t*)delDevCtx;
OCProvisionDev_t * pTargetDev = PMCloneOCProvisionDev(removeData->revokeTargetDev);
OCProvisionResultCB resultCallback = removeData->resultCallback;
if (clientResponse)
{
OicUuid_t revDevUuid = {.id={0}};
if(UUID_LENGTH == clientResponse->identity.id_length)
{
memcpy(revDevUuid.id, clientResponse->identity.id, sizeof(revDevUuid.id));
if (OC_STACK_RESOURCE_DELETED == clientResponse->result)
{
res = PDMUnlinkDevices(&removeData->revokeTargetDev->doxm->deviceID, &revDevUuid);
if (OC_STACK_OK != res)
{
OIC_LOG(ERROR, TAG, "PDMSetLinkStale() FAIL: PDB is an obsolete one.");
registerResultForResetDevice(removeData, &revDevUuid,
OC_STACK_INCONSISTENT_DB, true);
return OC_STACK_DELETE_TRANSACTION;
}
registerResultForResetDevice(removeData, &revDevUuid,
OC_STACK_RESOURCE_DELETED, false);
}
else
{
registerResultForResetDevice(removeData, &revDevUuid,
clientResponse->result, false);
OIC_LOG(ERROR, TAG, "Unexpected result from DELETE credential request!");
}
}
else
{
OIC_LOG_V(WARNING, TAG, "Incorrect length of device UUID was sent from %s:%d",
clientResponse->devAddr.addr, clientResponse->devAddr.port);
if (OC_STACK_RESOURCE_DELETED == clientResponse->result)
{
/**
* Since server's credential was deleted,
* register result as OC_STACK_INCONSISTENT_DB with NULL UUID.
*/
OIC_LOG_V(ERROR, TAG, "But server's credential was deleted.");
registerResultForResetDevice(removeData, NULL, OC_STACK_INCONSISTENT_DB, true);
}
else
{
registerResultForResetDevice(removeData, NULL, clientResponse->result, true);
}
}
}
else
{
registerResultForResetDevice(removeData, NULL, OC_STACK_ERROR, true);
OIC_LOG(ERROR, TAG, "SRPSyncDevice received Null clientResponse");
}
SRPResetDevice(pTargetDev, resultCallback);
return OC_STACK_DELETE_TRANSACTION;
}
/**
* Callback handler of reset device sync-up
*
* @param[in] ctx ctx value passed to callback from calling function.
* @param[in] handle handle to an invocation
* @param[in] clientResponse Response from queries to remote servers.
* @return OC_STACK_DELETE_TRANSACTION to delete the transaction
* and OC_STACK_KEEP_TRANSACTION to keep it.
*/
static OCStackApplicationResult SRPSyncDeviceACLCB(void *ctx, OCDoHandle UNUSED,
OCClientResponse *clientResponse)
{
(void)ctx;
(void)UNUSED;
(void)clientResponse;
return OC_STACK_DELETE_TRANSACTION;
}
/**
* Callback handler of device remote reset.
*
* @param[in] ctx ctx value passed to callback from calling function.
* @param[in] UNUSED handle to an invocation
* @param[in] clientResponse Response from queries to remote servers.
* @return OC_STACK_DELETE_TRANSACTION to delete the transaction
* and OC_STACK_KEEP_TRANSACTION to keep it.
*/
static OCStackApplicationResult SRPResetDeviceCB(void *ctx, OCDoHandle UNUSED,
OCClientResponse *clientResponse)
{
OIC_LOG(DEBUG, TAG, "IN SRPResetDeviceCB");
(void)UNUSED;
if(OC_STACK_OK == clientResponse->result)
{
OIC_LOG(DEBUG, TAG, "Change Target Device Pstat Cm SUCCEEDED");
}
// Delete Cred and ACL related to the target device.
const OicSecCred_t *cred = NULL;
OCProvisionDev_t * pTargetDev = (OCProvisionDev_t *)ctx;
cred = GetCredResourceData(&pTargetDev->doxm->deviceID);
if (cred == NULL)
{
OIC_LOG(ERROR, TAG, "OCResetDevice : Failed to get credential of target device.");
goto error;
}
OCStackResult res = RemoveCredential(&cred->subject);
if (res != OC_STACK_RESOURCE_DELETED && res != OC_STACK_NO_RESOURCE)
{
OIC_LOG(ERROR, TAG, "OCResetDevice : Failed to remove credential.");
goto error;
}
res = RemoveACE(&cred->subject, NULL);
if (res != OC_STACK_RESOURCE_DELETED && res != OC_STACK_NO_RESOURCE)
{
OIC_LOG(ERROR, TAG, "OCResetDevice : Failed to remove ACL.");
goto error;
}
if (OC_STACK_OK != PDMDeleteDevice(&pTargetDev->doxm->deviceID))
{
OIC_LOG(ERROR, TAG, "OCResetDevice : Failed to delete device from PDM");
}
//Close the DTLS session of the reset device.
CAEndpoint_t* endpoint = (CAEndpoint_t *)&clientResponse->devAddr;
CAResult_t caResult = CAcloseSslSession(endpoint);
if(CA_STATUS_OK != caResult)
{
OIC_LOG_V(WARNING, TAG, "OCResetDevice : Failed to close DTLS session : %d", caResult);
}
/**
* If there is no linked device, PM does not send any request.
* So we should directly invoke the result callback to inform the result of OCResetDevice.
*/
if(OC_STACK_NO_RESOURCE == res)
{
res = OC_STACK_OK;
}
error:
OICFree(pTargetDev);
return OC_STACK_DELETE_TRANSACTION;
}
static OCStackResult GetListofDevToReqDeleteCred(const OCProvisionDev_t* pRevokeTargetDev,
const OCProvisionDev_t* pOwnedDevList,
OCUuidList_t* pLinkedUuidList,
OCProvisionDev_t** ppLinkedDevList,
size_t *numOfLinkedDev)
{
// pOwnedDevList could be NULL. It means no alived and owned device now.
if (pRevokeTargetDev == NULL || pLinkedUuidList == NULL ||\
ppLinkedDevList == NULL || numOfLinkedDev == NULL)
{
return OC_STACK_INVALID_PARAM;
}
size_t cnt = 0;
OCUuidList_t *curUuid = NULL, *tmpUuid = NULL;
LL_FOREACH_SAFE(pLinkedUuidList, curUuid, tmpUuid)
{
// Mark the link status stale.
OCStackResult res = PDMSetLinkStale(&curUuid->dev, &pRevokeTargetDev->doxm->deviceID);
if (OC_STACK_OK != res)
{
OIC_LOG(FATAL, TAG, "PDMSetLinkStale() FAIL: PDB is an obsolete one.");
return OC_STACK_SVR_DB_NOT_EXIST;
}
if (pOwnedDevList)
{
// If this linked device is alive (power-on), add the deivce to the list.
const OCProvisionDev_t *curDev = NULL;
const OCProvisionDev_t *tmpDev = NULL;
LL_FOREACH_SAFE(pOwnedDevList, curDev, tmpDev)
{
if (memcmp(curDev->doxm->deviceID.id, curUuid->dev.id, sizeof(curUuid->dev.id)) == 0)
{
OCProvisionDev_t* targetDev = PMCloneOCProvisionDev(curDev);
if (NULL == targetDev)
{
OIC_LOG(ERROR, TAG, "SRPRemoveDevice : Cloning OCProvisionDev_t Failed.");
return OC_STACK_NO_MEMORY;
}
LL_PREPEND(*ppLinkedDevList, targetDev);
cnt++;
break;
}
}
}
}
*numOfLinkedDev = cnt;
return OC_STACK_OK;
}
/*
* Function to device revocation
* This function will remove credential of target device from all devices in subnet.
*
* @param[in] ctx Application context would be returned in result callback
* @param[in] waitTimeForOwnedDeviceDiscovery Maximum wait time for owned device discovery.(seconds)
* @param[in] pTargetDev Device information to be revoked.
* @param[in] resultCallback callback provided by API user, callback will be called when
* credential revocation is finished.
* @return OC_STACK_OK in case of success and other value otherwise.
* If OC_STACK_OK is returned, the caller of this API should wait for callback.
* OC_STACK_CONTINUE means operation is success but no request is need to be initiated.
*/
OCStackResult SRPRemoveDevice(void* ctx, unsigned short waitTimeForOwnedDeviceDiscovery,
const OCProvisionDev_t* pTargetDev, OCProvisionResultCB resultCallback)
{
OIC_LOG(INFO, TAG, "IN SRPRemoveDevice");
if (!pTargetDev || 0 == waitTimeForOwnedDeviceDiscovery)
{
OIC_LOG(INFO, TAG, "SRPRemoveDevice : NULL parameters");
return OC_STACK_INVALID_PARAM;
}
if (!resultCallback)
{
OIC_LOG(INFO, TAG, "SRPRemoveDevice : NULL Callback");
return OC_STACK_INVALID_CALLBACK;
}
// Declare variables in here to handle error cases with goto statement.
OCProvisionDev_t* pOwnedDevList = NULL;
OCProvisionDev_t* pLinkedDevList = NULL;
RemoveData_t* removeData = NULL;
//1. Find all devices that has a credential of the revoked device
OCUuidList_t* pLinkedUuidList = NULL;
size_t numOfDevices = 0;
OCStackResult res = OC_STACK_ERROR;
res = PDMGetLinkedDevices(&pTargetDev->doxm->deviceID, &pLinkedUuidList, &numOfDevices);
if (OC_STACK_OK != res)
{
OIC_LOG(ERROR, TAG, "SRPRemoveDevice : Failed to get linked devices information");
return res;
}
// if there is no related device, we can skip further process.
if (0 == numOfDevices)
{
OIC_LOG(DEBUG, TAG, "SRPRemoveDevice : No linked device found.");
res = OC_STACK_CONTINUE;
goto error;
}
//2. Find owned device from the network
res = PMDeviceDiscovery(waitTimeForOwnedDeviceDiscovery, true, &pOwnedDevList);
if (OC_STACK_OK != res)
{
OIC_LOG(ERROR, TAG, "SRPRemoveDevice : Failed to PMDeviceDiscovery");
goto error;
}
//3. Make a list of devices to send DELETE credential request
// by comparing owned devices from provisioning database with mutlicast discovery result.
size_t numOfLinkedDev = 0;
res = GetListofDevToReqDeleteCred(pTargetDev, pOwnedDevList, pLinkedUuidList,
&pLinkedDevList, &numOfLinkedDev);
if (OC_STACK_OK != res)
{
OIC_LOG(ERROR, TAG, "SRPRemoveDevice : GetListofDevToReqDeleteCred() failed");
goto error;
}
if (0 == numOfLinkedDev) // This case means, there is linked device but it's not alive now.
{ // So we don't have to send request message.
OIC_LOG(DEBUG, TAG, "SRPRemoveDevice : No alived & linked device found.");
res = OC_STACK_CONTINUE;
goto error;
}
// 4. Prepare RemoveData Context data.
removeData = (RemoveData_t*)OICCalloc(1, sizeof(RemoveData_t));
if (!removeData)
{
OIC_LOG(ERROR, TAG, "SRPRemoveDevices : Failed to memory allocation");
res = OC_STACK_NO_MEMORY;
goto error;
}
removeData->revokeTargetDev = PMCloneOCProvisionDev(pTargetDev);
if (!removeData->revokeTargetDev)
{
OIC_LOG(ERROR, TAG, "SRPRemoveDevices : PMCloneOCProvisionDev Failed");
res = OC_STACK_NO_MEMORY;
goto error;
}
removeData->removeRes =
(OCProvisionResult_t*)OICCalloc(numOfLinkedDev, sizeof(OCProvisionResult_t));
if (!removeData->removeRes)
{
OIC_LOG(ERROR, TAG, "SRPRemoveDevices : Failed to memory allocation");
res = OC_STACK_NO_MEMORY;
goto error;
}
removeData->ctx = ctx;
removeData->linkedDevList = pLinkedDevList;
removeData->resultCallback = resultCallback;
removeData->numOfResults = 0;
removeData->sizeOfResArray = numOfLinkedDev;
removeData->hasError = false;
// 5. Send DELETE credential request to linked devices.
OCProvisionDev_t *curDev = NULL, *tmpDev = NULL;
OCStackResult totalRes = OC_STACK_ERROR; /* variable for checking request is sent or not */
LL_FOREACH_SAFE(pLinkedDevList, curDev, tmpDev)
{
res = SendDeleteCredentialRequest((void*)removeData, &SRPRemoveDeviceCB,
removeData->revokeTargetDev, curDev);
if (OC_STACK_OK != res)
{
OIC_LOG_V(ERROR, TAG, "SRPRemoveDevice : Fail to send the DELETE credential request to\
%s:%u", curDev->endpoint.addr, curDev->endpoint.port);
}
else
{
totalRes = OC_STACK_OK; // This means at least one request is successfully sent.
}
}
PDMDestoryOicUuidLinkList(pLinkedUuidList); //TODO: Modify API name to have unified convention.
PMDeleteDeviceList(pOwnedDevList);
OIC_LOG(INFO, TAG, "OUT SRPRemoveDevice");
return totalRes; // Caller of this API should wait callback if totalRes == OC_STACK_OK.
error:
PDMDestoryOicUuidLinkList(pLinkedUuidList);
PMDeleteDeviceList(pOwnedDevList);
PMDeleteDeviceList(pLinkedDevList);
if (removeData)
{
OICFree(removeData->revokeTargetDev);
OICFree(removeData->removeRes);
OICFree(removeData);
}
OIC_LOG(INFO, TAG, "OUT ERROR case SRPRemoveDevice");
return res;
}
/*
* Function to device revocation
* This function will remove credential of target device from all devices in subnet.
*
* @param[in] ctx Application context would be returned in result callback
* @param[in] pOwnedDevList List of owned devices
* @param[in] pTargetDev Device information to be revoked.
* @param[in] resultCallback callback provided by API user, callback will be called when
* credential revocation is finished.
* @return OC_STACK_OK in case of success and other value otherwise.
* If OC_STACK_OK is returned, the caller of this API should wait for callback.
* OC_STACK_CONTINUE means operation is success but no request is need to be initiated.
*/
OCStackResult SRPRemoveDeviceWithoutDiscovery(void* ctx, const OCProvisionDev_t* pOwnedDevList,
const OCProvisionDev_t* pTargetDev, OCProvisionResultCB resultCallback)
{
OIC_LOG(INFO, TAG, "IN SRPRemoveDeviceWithoutDiscovery");
if (!pOwnedDevList)
{
OIC_LOG(WARNING, TAG, "SRPRemoveDeviceWithoutDiscovery : Owned Device List is empty");
return OC_STACK_CONTINUE;
}
if (!pTargetDev)
{
OIC_LOG(INFO, TAG, "SRPRemoveDeviceWithoutDiscovery : NULL parameters");
return OC_STACK_INVALID_PARAM;
}
if (!resultCallback)
{
OIC_LOG(INFO, TAG, "SRPRemoveDeviceWithoutDiscovery : NULL Callback");
return OC_STACK_INVALID_CALLBACK;
}
// Declare variables in here to handle error cases with goto statement.
OCProvisionDev_t* pLinkedDevList = NULL;
RemoveData_t* removeData = NULL;
//1. Find all devices that has a credential of the revoked device
OCUuidList_t* pLinkedUuidList = NULL;
size_t numOfDevices = 0;
OCStackResult res = OC_STACK_ERROR;
res = PDMGetLinkedDevices(&pTargetDev->doxm->deviceID, &pLinkedUuidList, &numOfDevices);
if (OC_STACK_OK != res)
{
OIC_LOG(WARNING, TAG, "SRPRemoveDeviceWithoutDiscovery : Failed to get linked devices information");
return OC_STACK_CONTINUE;
}
// if there is no related device, we can skip further process.
if (0 == numOfDevices)
{
OIC_LOG(WARNING, TAG, "SRPRemoveDeviceWithoutDiscovery : No linked device found.");
return OC_STACK_CONTINUE;
}
//2. Make a list of devices to send DELETE credential request
// by comparing owned devices from provisioning database with mutlicast discovery result.
size_t numOfLinkedDev = 0;
res = GetListofDevToReqDeleteCred(pTargetDev, pOwnedDevList, pLinkedUuidList,
&pLinkedDevList, &numOfLinkedDev);
if (OC_STACK_OK != res)
{
OIC_LOG(ERROR, TAG, "SRPRemoveDeviceWithoutDiscovery : GetListofDevToReqDeleteCred() failed");
goto error;
}
if (0 == numOfLinkedDev) // This case means, there is linked device but it's not alive now.
{ // So we don't have to send request message.
OIC_LOG(DEBUG, TAG, "SRPRemoveDeviceWithoutDiscovery : No alived & linked device found.");
return OC_STACK_CONTINUE;
}
// 3. Prepare RemoveData Context data.
removeData = (RemoveData_t*)OICCalloc(1, sizeof(RemoveData_t));
if (!removeData)
{
OIC_LOG(ERROR, TAG, "SRPRemoveDeviceWithoutDiscovery : Failed to memory allocation");
res = OC_STACK_NO_MEMORY;
goto error;
}
removeData->revokeTargetDev = PMCloneOCProvisionDev(pTargetDev);
if (!removeData->revokeTargetDev)
{
OIC_LOG(ERROR, TAG, "SRPRemoveDeviceWithoutDiscovery : PMCloneOCProvisionDev Failed");
res = OC_STACK_NO_MEMORY;
goto error;
}
removeData->removeRes =
(OCProvisionResult_t*)OICCalloc(numOfLinkedDev, sizeof(OCProvisionResult_t));
if (!removeData->removeRes)
{
OIC_LOG(ERROR, TAG, "SRPRemoveDeviceWithoutDiscovery : Failed to memory allocation");
res = OC_STACK_NO_MEMORY;
goto error;
}
removeData->ctx = ctx;
removeData->linkedDevList = pLinkedDevList;
removeData->resultCallback = resultCallback;
removeData->numOfResults = 0;
removeData->sizeOfResArray = numOfLinkedDev;
removeData->hasError = false;
// 5. Send DELETE credential request to linked devices.
OCProvisionDev_t *curDev = NULL, *tmpDev = NULL;
OCStackResult totalRes = OC_STACK_ERROR; /* variable for checking request is sent or not */
LL_FOREACH_SAFE(pLinkedDevList, curDev, tmpDev)
{
res = SendDeleteCredentialRequest((void*)removeData, &SRPRemoveDeviceCB,
removeData->revokeTargetDev, curDev);
if (OC_STACK_OK != res)
{
OIC_LOG_V(ERROR, TAG, "SRPRemoveDeviceWithoutDiscovery : Fail to send the DELETE credential request to\
%s:%u", curDev->endpoint.addr, curDev->endpoint.port);
}
else
{
totalRes = OC_STACK_OK; // This means at least one request is successfully sent.
}
}
PDMDestoryOicUuidLinkList(pLinkedUuidList); //TODO: Modify API name to have unified convention.
OIC_LOG(INFO, TAG, "OUT SRPRemoveDeviceWithoutDiscovery");
return totalRes; // Caller of this API should wait callback if totalRes == OC_STACK_OK.
error:
PDMDestoryOicUuidLinkList(pLinkedUuidList);
PMDeleteDeviceList(pLinkedDevList);
if (removeData)
{
OICFree(removeData->revokeTargetDev);
OICFree(removeData->removeRes);
OICFree(removeData);
}
OIC_LOG(INFO, TAG, "OUT ERROR case SRPRemoveDeviceWithoutDiscovery");
return res;
}
/*
* Function to sync-up credential and ACL of the target device.
* This function will remove credential and ACL of target device from all devices in subnet.
*
* @param[in] ctx Application context would be returned in result callback
* @param[in] waitTimeForOwnedDeviceDiscovery Maximum wait time for owned device discovery.(seconds)
* @param[in] pTargetDev Device information to be revoked.
* @param[in] resultCallback callback provided by API user, callback will be called when
* credential revocation is finished.
* when there is an error, this user callback is called immediately.
* @return OC_STACK_OK in case of success and other value otherwise.
* If OC_STACK_OK is returned, the caller of this API should wait for callback.
* OC_STACK_CONTINUE means operation is success but no request is need to be initiated.
*/
OCStackResult SRPSyncDevice(void* ctx, unsigned short waitTimeForOwnedDeviceDiscovery,
const OCProvisionDev_t* pTargetDev, OCProvisionResultCB resultCallback)
{
OIC_LOG(INFO, TAG, "IN SRPSyncDevice");
if (!pTargetDev || 0 == waitTimeForOwnedDeviceDiscovery)
{
OIC_LOG(INFO, TAG, "SRPSyncDevice : NULL parameters");
return OC_STACK_INVALID_PARAM;
}
if (!resultCallback)
{
OIC_LOG(INFO, TAG, "SRPSyncDevice : NULL Callback");
return OC_STACK_INVALID_CALLBACK;
}
// Declare variables in here to handle error cases with goto statement.
OCProvisionDev_t* pOwnedDevList = NULL;
OCProvisionDev_t* pLinkedDevList = NULL;
RemoveData_t* removeData = NULL;
//1. Find all devices that has a credential of the revoked device
OCUuidList_t* pLinkedUuidList = NULL;
size_t numOfDevices = 0;
OCStackResult res = OC_STACK_ERROR;
res = PDMGetLinkedDevices(&pTargetDev->doxm->deviceID, &pLinkedUuidList, &numOfDevices);
if (OC_STACK_OK != res)
{
OIC_LOG(ERROR, TAG, "SRPSyncDevice : Failed to get linked devices information");
return res;
}
// if there is no related device, we can skip further process.
if (0 == numOfDevices)
{
OIC_LOG(DEBUG, TAG, "SRPSyncDevice : No linked device found.");
res = OC_STACK_CONTINUE;
goto error;
}
//2. Find owned device from the network
res = PMDeviceDiscovery(waitTimeForOwnedDeviceDiscovery, true, &pOwnedDevList);
if (OC_STACK_OK != res)
{
OIC_LOG(ERROR, TAG, "SRPSyncDevice : Failed to PMDeviceDiscovery");
goto error;
}
//3. Make a list of devices to send DELETE credential request
// by comparing owned devices from provisioning database with mutlicast discovery result.
size_t numOfLinkedDev = 0;
res = GetListofDevToReqDeleteCred(pTargetDev, pOwnedDevList, pLinkedUuidList,
&pLinkedDevList, &numOfLinkedDev);
if (OC_STACK_OK != res)
{
OIC_LOG(ERROR, TAG, "SRPSyncDevice : GetListofDevToReqDeleteCred() failed");
goto error;
}
if (0 == numOfLinkedDev) // This case means, there is linked device but it's not alive now.
{ // So we don't have to send request message.
OIC_LOG(DEBUG, TAG, "SRPSyncDevice : No alived & linked device found.");
res = OC_STACK_CONTINUE;
goto error;
}
// 4. Prepare RemoveData Context data.
removeData = (RemoveData_t*)OICCalloc(1, sizeof(RemoveData_t));
if (!removeData)
{
OIC_LOG(ERROR, TAG, "SRPSyncDevice : Failed to memory allocation");
res = OC_STACK_NO_MEMORY;
goto error;
}
removeData->revokeTargetDev = PMCloneOCProvisionDev(pTargetDev);
if (!removeData->revokeTargetDev)
{
OIC_LOG(ERROR, TAG, "SRPSyncDevice : PMCloneOCProvisionDev Failed");
res = OC_STACK_NO_MEMORY;
goto error;
}
removeData->removeRes =
(OCProvisionResult_t*)OICCalloc(numOfLinkedDev, sizeof(OCProvisionResult_t));
if (!removeData->removeRes)
{
OIC_LOG(ERROR, TAG, "SRPSyncDevice : Failed to allocate memory");
res = OC_STACK_NO_MEMORY;
goto error;
}
removeData->ctx = ctx;
removeData->linkedDevList = pLinkedDevList;
removeData->resultCallback = resultCallback;
removeData->numOfResults = 0;
removeData->sizeOfResArray = numOfLinkedDev;
removeData->hasError = false;
// 5. Send DELETE credential request to linked devices.
OCProvisionDev_t *curDev = NULL, *tmpDev = NULL;
OCStackResult totalRes = OC_STACK_ERROR; /* variable for checking request is sent or not */
LL_FOREACH_SAFE(pLinkedDevList, curDev, tmpDev)
{
res = SendDeleteACLRequest((void*)removeData, &SRPSyncDeviceACLCB,
removeData->revokeTargetDev, curDev);
if (OC_STACK_OK != res)
{
OIC_LOG_V(ERROR, TAG, "SRPSyncDevice : Fail to send the DELETE ACL request to\
%s:%u", curDev->endpoint.addr, curDev->endpoint.port);
goto error;
}
res = SendDeleteCredentialRequest((void*)removeData, &SRPSyncDeviceCredCB,
removeData->revokeTargetDev, curDev);
if (OC_STACK_OK != res)
{
OIC_LOG_V(ERROR, TAG, "SRPSyncDevice : Fail to send the DELETE credential request to\
%s:%u", curDev->endpoint.addr, curDev->endpoint.port);
totalRes = OC_STACK_ERROR;
}
else
{
totalRes = OC_STACK_OK; // This means at least one request is successfully sent.
}
}
PDMDestoryOicUuidLinkList(pLinkedUuidList); //TODO: Modify API name to have unified convention.
PMDeleteDeviceList(pOwnedDevList);
OIC_LOG(INFO, TAG, "OUT SRPSyncDevice");
return totalRes; // Caller of this API should wait callback if totalRes == OC_STACK_OK.
error:
PDMDestoryOicUuidLinkList(pLinkedUuidList);
PMDeleteDeviceList(pOwnedDevList);
PMDeleteDeviceList(pLinkedDevList);
if (removeData)
{
OICFree(removeData->revokeTargetDev);
OICFree(removeData->removeRes);
OICFree(removeData);
}
OIC_LOG(INFO, TAG, "OUT ERROR case SRPSyncDevice");
return res;
}
/*
* Function for remote reset
* This function will send pstat PUT message to the target device to initiate remote reset.
*
* @param[in] pTargetDev Device information to be revoked.
* @param[in] resultCallback callback provided by API user, callback will be called when
* credential revocation is finished.
* when there is an error, this user callback is called immediately.
* @return OC_STACK_OK in case of success and other value otherwise.
* If OC_STACK_OK is returned, the caller of this API should wait for callback.
* OC_STACK_CONTINUE means operation is success but no request is need to be initiated.
*/
OCStackResult SRPResetDevice(const OCProvisionDev_t* pTargetDev,
OCProvisionResultCB resultCallback)
{
OIC_LOG(INFO, TAG, "IN SRPResetDevice");
if (!pTargetDev)
{
OIC_LOG(INFO, TAG, "SRPResetDevice : NULL parameters");
return OC_STACK_INVALID_PARAM;
}
if (!resultCallback)
{
OIC_LOG(INFO, TAG, "SRPResetDevice : NULL Callback");
return OC_STACK_INVALID_CALLBACK;
}
OCStackResult res = OC_STACK_ERROR;
OicSecPstat_t * pstat = (OicSecPstat_t *) OICCalloc(1, sizeof(OicSecPstat_t));
if (!pstat)
{
OIC_LOG(ERROR, TAG, "Failed to allocate memory");
return OC_STACK_NO_MEMORY;
}
pstat->cm = RESET;
pstat->isOp = false;
memcpy(pstat->deviceID.id, pTargetDev->doxm->deviceID.id, sizeof(OicUuid_t));
pstat->tm = TAKE_OWNER;
pstat->om = (OicSecDpom_t)(SINGLE_SERVICE_CLIENT_DRIVEN); // the only mode IoTivity supports currently
pstat->smLen = 1;
pstat->sm = (OicSecDpom_t *) OICCalloc(pstat->smLen, sizeof(OicSecDpom_t));
if (NULL == pstat->sm)
{
OIC_LOG(ERROR, TAG, "Failed to allocate memory");
OICFree(pstat);
return OC_STACK_NO_MEMORY;
}
pstat->sm[0] = (OicSecDpom_t)(SINGLE_SERVICE_CLIENT_DRIVEN); // the only mode IoTivity supports currently
OCSecurityPayload * secPayload = (OCSecurityPayload *) OICCalloc(1, sizeof(OCSecurityPayload));
if (!secPayload)
{
OIC_LOG(ERROR, TAG, "Failed to allocate memory");
res = OC_STACK_NO_MEMORY;
goto error;
}
secPayload->base.type = PAYLOAD_TYPE_SECURITY;
if (OC_STACK_OK != PstatToCBORPayload(pstat, &(secPayload->securityData),
&(secPayload->payloadSize), true))
{
OCPayloadDestroy((OCPayload *) secPayload);
OIC_LOG(ERROR, TAG, "Failed to PstatToCBORPayload");
res = OC_STACK_NO_MEMORY;
goto error;
}
OIC_LOG(DEBUG, TAG, "Created payload for pstat set");
OIC_LOG_BUFFER(DEBUG, TAG, secPayload->securityData, secPayload->payloadSize);
char query[MAX_URI_LENGTH + MAX_QUERY_LENGTH] = {0};
if (!PMGenerateQuery(true,
pTargetDev->endpoint.addr,
pTargetDev->securePort,
pTargetDev->connType,
query, sizeof(query), OIC_RSRC_PSTAT_URI))
{
OIC_LOG(ERROR, TAG, "SRPResetDevice : Failed to generate query");
OCPayloadDestroy((OCPayload *) secPayload);
res = OC_STACK_ERROR;
goto error;
}
OIC_LOG_V(DEBUG, TAG, "Query=%s", query);
OCCallbackData cbData = { .context = NULL, .cb = NULL, .cd = NULL };
OCMethod method = OC_REST_POST;
OCDoHandle handle = NULL;
OCProvisionDev_t * targetDev = PMCloneOCProvisionDev(pTargetDev);
if (NULL == targetDev)
{
OIC_LOG(ERROR, TAG, "target dev is null");
res = OC_STACK_ERROR;
goto error;
}
cbData.cb = &SRPResetDeviceCB;
cbData.context = (void *) targetDev;
cbData.cd = NULL;
OIC_LOG(DEBUG, TAG, "Sending PSTAT info to resource server");
res = OCDoResource(&handle, method, query,
&targetDev->endpoint, (OCPayload *)secPayload,
targetDev->connType, OC_LOW_QOS, &cbData, NULL, 0);\
if (OC_STACK_OK != res)
{
OIC_LOG(ERROR, TAG, "OCStack resource error");
}
error:
OICFree(pstat->sm);
OICFree(pstat);
OIC_LOG(INFO, TAG, "OUT SRPResetDevice");
return res;
}
/**
* Internal Function to store results in result array during GetCredResourceCB.
*/
static void registerResultForGetCredResourceCB(GetSecData_t *GetSecData,
OCStackResult stackresult)
{
OIC_LOG_V(INFO, TAG, "Inside registerResultForGetCredResourceCB "
"GetSecData->numOfResults is %d\n", GetSecData->numOfResults);
memcpy(GetSecData->resArr[(GetSecData->numOfResults)].deviceId.id,
GetSecData->deviceInfo->doxm->deviceID.id, UUID_LENGTH);
GetSecData->resArr[(GetSecData->numOfResults)].res = stackresult;
++(GetSecData->numOfResults);
}
/**
* Callback handler of SRPGetCredResource.
*
* @param[in] ctx ctx value passed to callback from calling function.
* @param[in] UNUSED handle to an invocation
* @param[in] clientResponse Response from queries to remote servers.
* @return OC_STACK_DELETE_TRANSACTION to delete the transaction
* and OC_STACK_KEEP_TRANSACTION to keep it.
*/
static OCStackApplicationResult SRPGetCredResourceCB(void *ctx, OCDoHandle UNUSED,
OCClientResponse *clientResponse)
{
OIC_LOG_V(INFO, TAG, "Inside SRPGetCredResourceCB.");
(void)UNUSED;
VERIFY_NON_NULL_RET(TAG, ctx, ERROR, OC_STACK_DELETE_TRANSACTION);
GetSecData_t *GetSecData = (GetSecData_t*)ctx;
OCProvisionResultCB resultCallback = GetSecData->resultCallback;
if (clientResponse)
{
if(OC_STACK_OK == clientResponse->result)
{
uint8_t *payload = ((OCSecurityPayload*)clientResponse->payload)->securityData;
size_t size = ((OCSecurityPayload*)clientResponse->payload)->payloadSize;
OIC_LOG_BUFFER(DEBUG, TAG, payload, size);
(void)size;
(void)payload;
registerResultForGetCredResourceCB(GetSecData, OC_STACK_OK);
((OCProvisionResultCB)(resultCallback))(GetSecData->ctx, GetSecData->numOfResults,
GetSecData->resArr,
false);
OICFree(GetSecData->resArr);
OICFree(GetSecData);
return OC_STACK_DELETE_TRANSACTION;
}
}
registerResultForGetCredResourceCB(GetSecData, OC_STACK_OK);
((OCProvisionResultCB)(resultCallback))(GetSecData->ctx, GetSecData->numOfResults,
GetSecData->resArr,
false);
OIC_LOG_V(ERROR, TAG, "SRPGetCredResourceCB received Null clientResponse");
OICFree(GetSecData->resArr);
OICFree(GetSecData);
return OC_STACK_DELETE_TRANSACTION;
}
OCStackResult SRPGetCredResource(void *ctx, const OCProvisionDev_t *selectedDeviceInfo,
OCProvisionResultCB resultCallback)
{
VERIFY_NON_NULL_RET(TAG, selectedDeviceInfo, ERROR, OC_STACK_INVALID_PARAM);
VERIFY_NON_NULL_RET(TAG, resultCallback, ERROR, OC_STACK_INVALID_CALLBACK);
char query[MAX_URI_LENGTH + MAX_QUERY_LENGTH] = {0};
if(!PMGenerateQuery(true,
selectedDeviceInfo->endpoint.addr,
selectedDeviceInfo->securePort,
selectedDeviceInfo->connType,
query, sizeof(query), OIC_RSRC_CRED_URI))
{
OIC_LOG(ERROR, TAG, "SRPGetCredResource : Failed to generate query");
return OC_STACK_ERROR;
}
OIC_LOG_V(DEBUG, TAG, "Query=%s", query);
OCCallbackData cbData = {.context=NULL, .cb=NULL, .cd=NULL};
cbData.cb = &SRPGetCredResourceCB;
GetSecData_t* GetSecData = (GetSecData_t*)OICCalloc(1, sizeof(GetSecData_t));
if (NULL == GetSecData)
{
OIC_LOG(ERROR, TAG, "Unable to allocate memory");
return OC_STACK_NO_MEMORY;
}
GetSecData->deviceInfo = selectedDeviceInfo;
GetSecData->resultCallback = resultCallback;
GetSecData->numOfResults=0;
GetSecData->ctx = ctx;
int noOfRiCalls = 1;
GetSecData->resArr = (OCProvisionResult_t*)OICCalloc(noOfRiCalls, sizeof(OCProvisionResult_t));
if (NULL == GetSecData->resArr)
{
OICFree(GetSecData);
OIC_LOG(ERROR, TAG, "Unable to allocate memory");
return OC_STACK_NO_MEMORY;
}
cbData.context = (void *)GetSecData;
cbData.cd = NULL;
OCMethod method = OC_REST_GET;
OCDoHandle handle = NULL;
OIC_LOG(DEBUG, TAG, "Sending Get Cred to resource server");
OCStackResult ret = OCDoResource(&handle, method, query, NULL, NULL,
selectedDeviceInfo->connType, OC_HIGH_QOS, &cbData, NULL, 0);
if (OC_STACK_OK != ret)
{
OIC_LOG(ERROR, TAG, "OCStack resource error");
OICFree(GetSecData->resArr);
OICFree(GetSecData);
}
VERIFY_SUCCESS_RET(TAG, (OC_STACK_OK == ret), ERROR, OC_STACK_ERROR);
OIC_LOG(DEBUG, TAG, "OUT SRPGetCredResource");
return OC_STACK_OK;
}
/**
* Internal Function to store results in result array during GetACLResourceCB.
*/
static void registerResultForGetACLResourceCB(GetSecData_t *GetSecData,
OCStackResult stackresult)
{
OIC_LOG_V(INFO, TAG, "Inside registerResultForGetACLResourceCB "
"GetSecData->numOfResults is %d\n", GetSecData->numOfResults);
memcpy(GetSecData->resArr[(GetSecData->numOfResults)].deviceId.id,
GetSecData->deviceInfo->doxm->deviceID.id, UUID_LENGTH);
GetSecData->resArr[(GetSecData->numOfResults)].res = stackresult;
++(GetSecData->numOfResults);
}
/**
* Callback handler of SRPGetACLResource.
*
* @param[in] ctx ctx value passed to callback from calling function.
* @param[in] UNUSED handle to an invocation
* @param[in] clientResponse Response from queries to remote servers.
* @return OC_STACK_DELETE_TRANSACTION to delete the transaction
* and OC_STACK_KEEP_TRANSACTION to keep it.
*/
static OCStackApplicationResult SRPGetACLResourceCB(void *ctx, OCDoHandle UNUSED,
OCClientResponse *clientResponse)
{
OIC_LOG_V(INFO, TAG, "Inside SRPGetACLResourceCB.");
(void)UNUSED;
VERIFY_NON_NULL_RET(TAG, ctx, ERROR, OC_STACK_DELETE_TRANSACTION);
GetSecData_t *GetSecData = (GetSecData_t*)ctx;
OCProvisionResultCB resultCallback = GetSecData->resultCallback;
if (clientResponse)
{
if(OC_STACK_OK == clientResponse->result)
{
uint8_t *payload = ((OCSecurityPayload*)clientResponse->payload)->securityData;
size_t size = ((OCSecurityPayload*)clientResponse->payload)->payloadSize;
OIC_LOG_BUFFER(DEBUG, TAG, payload, size);
(void)payload;
(void)size;
registerResultForGetACLResourceCB(GetSecData, OC_STACK_OK);
((OCProvisionResultCB)(resultCallback))(GetSecData->ctx, GetSecData->numOfResults,
GetSecData->resArr,
false);
OICFree(GetSecData->resArr);
OICFree(GetSecData);
return OC_STACK_DELETE_TRANSACTION;
}
}
registerResultForGetACLResourceCB(GetSecData, OC_STACK_OK);
((OCProvisionResultCB)(resultCallback))(GetSecData->ctx, GetSecData->numOfResults,
GetSecData->resArr,
false);
OIC_LOG_V(ERROR, TAG, "SRPGetACLResourceCB received Null clientResponse");
OICFree(GetSecData->resArr);
OICFree(GetSecData);
return OC_STACK_DELETE_TRANSACTION;
}
OCStackResult SRPGetACLResource(void *ctx, const OCProvisionDev_t *selectedDeviceInfo,
OCProvisionResultCB resultCallback)
{
VERIFY_NON_NULL_RET(TAG, selectedDeviceInfo, ERROR, OC_STACK_INVALID_PARAM);
VERIFY_NON_NULL_RET(TAG, resultCallback, ERROR, OC_STACK_INVALID_CALLBACK);
char query[MAX_URI_LENGTH + MAX_QUERY_LENGTH] = {0};
if(!PMGenerateQuery(true,
selectedDeviceInfo->endpoint.addr,
selectedDeviceInfo->securePort,
selectedDeviceInfo->connType,
query, sizeof(query), OIC_RSRC_ACL_URI))
{
OIC_LOG(ERROR, TAG, "SRPGetACLResource : Failed to generate query");
return OC_STACK_ERROR;
}
OIC_LOG_V(DEBUG, TAG, "Query=%s", query);
OCCallbackData cbData = {.context=NULL, .cb=NULL, .cd=NULL};
cbData.cb = &SRPGetACLResourceCB;
GetSecData_t* GetSecData = (GetSecData_t*)OICCalloc(1, sizeof(GetSecData_t));
if (NULL == GetSecData)
{
OIC_LOG(ERROR, TAG, "Unable to allocate memory");
return OC_STACK_NO_MEMORY;
}
GetSecData->deviceInfo = selectedDeviceInfo;
GetSecData->resultCallback = resultCallback;
GetSecData->numOfResults=0;
GetSecData->ctx = ctx;
int noOfRiCalls = 1;
GetSecData->resArr = (OCProvisionResult_t*)OICCalloc(noOfRiCalls, sizeof(OCProvisionResult_t));
if (NULL == GetSecData->resArr)
{
OICFree(GetSecData);
OIC_LOG(ERROR, TAG, "Unable to allocate memory");
return OC_STACK_NO_MEMORY;
}
cbData.context = (void *)GetSecData;
cbData.cd = NULL;
OCMethod method = OC_REST_GET;
OCDoHandle handle = NULL;
OIC_LOG(DEBUG, TAG, "Sending Get ACL to resource server");
OCStackResult ret = OCDoResource(&handle, method, query, NULL, NULL,
selectedDeviceInfo->connType, OC_HIGH_QOS, &cbData, NULL, 0);
if (OC_STACK_OK != ret)
{
OIC_LOG(ERROR, TAG, "OCStack resource error");
OICFree(GetSecData->resArr);
OICFree(GetSecData);
}
VERIFY_SUCCESS_RET(TAG, (OC_STACK_OK == ret), ERROR, OC_STACK_ERROR);
OIC_LOG(DEBUG, TAG, "OUT SRPGetACLResource");
return OC_STACK_OK;
}
OCStackResult SRPReadTrustCertChain(uint16_t credId, uint8_t **trustCertChain,
size_t *chainSize)
{
OIC_LOG(DEBUG, TAG, "IN SRPReadTrustCertChain");
OCStackResult res = OC_STACK_ERROR;
int secureFlag = 0;
OicSecCred_t* credData = GetCredEntryByCredId(credId);
if(credData)
{
res = CredToCBORPayload((const OicSecCred_t*) credData, trustCertChain,
chainSize, secureFlag);
if(OC_STACK_OK != res)
{
OIC_LOG(INFO, TAG, "CredToCBORPayload failed");
}
}
DeleteCredList(credData);
return res;
}
|
4dd6b3a1c96e4358c6f9fb73b35778b7a3708d1d
|
676acab8ff535019faff7da3afb8eecc3fa127f5
|
/target/cubepilot/cubeorange/libraries/stm32_lib/CMSIS/DSP/DSP_Lib_TestSuite/Common/src/filtering_tests/biquad_tests.c
|
a6837f773f342caa60c6309921bcb3c4ae1ebcd7
|
[
"Apache-2.0"
] |
permissive
|
Firmament-Autopilot/FMT-Firmware
|
f8c324577245bd7e91af436954b4ce9421acbb41
|
0212fe89820376bfbedaded519552f6b011a7b8a
|
refs/heads/master
| 2023-09-01T11:37:46.194145
| 2023-08-29T06:33:10
| 2023-08-29T06:33:10
| 402,557,689
| 351
| 143
|
Apache-2.0
| 2023-09-12T05:28:39
| 2021-09-02T20:42:56
|
C
|
UTF-8
|
C
| false
| false
| 13,856
|
c
|
biquad_tests.c
|
#include "jtest.h"
#include "filtering_test_data.h"
#include "arr_desc.h"
#include "arm_math.h" /* FUTs */
#include "ref.h" /* Reference Functions */
#include "test_templates.h"
#include "filtering_templates.h"
#include "type_abbrev.h"
#define BIQUAD_DEFINE_TEST(suffix, instance_name, config_suffix, output_type) \
JTEST_DEFINE_TEST(arm_biquad_cascade_##config_suffix##_##suffix##_test, \
arm_biquad_cascade_##config_suffix##_##suffix) \
{ \
instance_name biquad_inst_fut = { 0 }; \
instance_name biquad_inst_ref = { 0 }; \
\
TEMPLATE_DO_ARR_DESC( \
blocksize_idx, uint32_t, blockSize, filtering_blocksizes \
, \
TEMPLATE_DO_ARR_DESC( \
numstages_idx, uint16_t, numStages, filtering_numstages \
, \
/* Initialize the BIQUAD Instances */ \
arm_biquad_cascade_##config_suffix##_init_##suffix( \
&biquad_inst_fut, numStages, \
(output_type*)filtering_coeffs_b_##suffix, \
(void *) filtering_pState); \
\
/* Display test parameter values */ \
JTEST_DUMP_STRF("Block Size: %d\n" \
"Number of Stages: %d\n", \
(int)blockSize, \
(int)numStages); \
\
JTEST_COUNT_CYCLES( \
arm_biquad_cascade_##config_suffix##_##suffix( \
&biquad_inst_fut, \
(void *) filtering_##suffix##_inputs, \
(void *) filtering_output_fut, \
blockSize)); \
\
arm_biquad_cascade_##config_suffix##_init_##suffix( \
&biquad_inst_ref, numStages, \
(output_type*)filtering_coeffs_b_##suffix, \
(void *) filtering_pState); \
\
ref_biquad_cascade_##config_suffix##_##suffix( \
&biquad_inst_ref, \
(void *) filtering_##suffix##_inputs, \
(void *) filtering_output_ref, \
blockSize); \
\
FILTERING_SNR_COMPARE_INTERFACE( \
blockSize, \
output_type))); \
\
return JTEST_TEST_PASSED; \
}
#define BIQUAD_WITH_POSTSHIFT_DEFINE_TEST(suffix, config_suffix, speed, output_type) \
JTEST_DEFINE_TEST(arm_biquad_cascade_##config_suffix##speed##_##suffix##_test, \
arm_biquad_cascade_##config_suffix##speed##_##suffix) \
{ \
arm_biquad_casd_##config_suffix##_inst_##suffix biquad_inst_fut = { 0 }; \
arm_biquad_casd_##config_suffix##_inst_##suffix biquad_inst_ref = { 0 }; \
\
TEMPLATE_DO_ARR_DESC( \
blocksize_idx, uint32_t, blockSize, filtering_blocksizes \
, \
TEMPLATE_DO_ARR_DESC( \
numstages_idx, uint16_t, numStages, filtering_numstages \
, \
TEMPLATE_DO_ARR_DESC( \
postshifts_idx, uint8_t, postShift, filtering_postshifts \
, \
/* Display test parameter values */ \
JTEST_DUMP_STRF("Block Size: %d\n" \
"Number of Stages: %d\n" \
"Post Shift: %d\n", \
(int)blockSize, \
(int)numStages, \
(int)postShift); \
\
/* Initialize the BIQUAD Instances */ \
arm_biquad_cascade_##config_suffix##_init_##suffix( \
&biquad_inst_fut, numStages, \
(output_type*)filtering_coeffs_b_##suffix, \
(void *) filtering_pState, postShift); \
\
JTEST_COUNT_CYCLES( \
arm_biquad_cascade_##config_suffix##speed##_##suffix( \
&biquad_inst_fut, \
(void *) filtering_##suffix##_inputs, \
(void *) filtering_output_fut, \
blockSize)); \
\
arm_biquad_cascade_##config_suffix##_init_##suffix( \
&biquad_inst_ref, numStages, \
(output_type*)filtering_coeffs_b_##suffix, \
(void *) filtering_pState, postShift); \
\
ref_biquad_cascade_##config_suffix##speed##_##suffix( \
&biquad_inst_ref, \
(void *) filtering_##suffix##_inputs, \
(void *) filtering_output_ref, \
blockSize); \
\
FILTERING_SNR_COMPARE_INTERFACE( \
blockSize, \
output_type)))); \
\
return JTEST_TEST_PASSED; \
}
JTEST_DEFINE_TEST(arm_biquad_cas_df1_32x64_q31_test,
arm_biquad_cas_df1_32x64_q31)
{
arm_biquad_cas_df1_32x64_ins_q31 biquad_inst_fut = { 0 };
arm_biquad_cas_df1_32x64_ins_q31 biquad_inst_ref = { 0 };
TEMPLATE_DO_ARR_DESC(
blocksize_idx, uint32_t, blockSize, filtering_blocksizes
,
TEMPLATE_DO_ARR_DESC(
numstages_idx, uint16_t, numStages, filtering_numstages
,
TEMPLATE_DO_ARR_DESC(
postshifts_idx, uint8_t, postShift, filtering_postshifts
,
/* Initialize the BIQUAD Instances */
arm_biquad_cas_df1_32x64_init_q31(
&biquad_inst_fut, numStages,
(q31_t*)filtering_coeffs_b_q31,
(void *) filtering_pState, postShift);
/* Display test parameter values */
JTEST_DUMP_STRF("Block Size: %d\n"
"Number of Stages: %d\n",
(int)blockSize,
(int)numStages);
JTEST_COUNT_CYCLES(
arm_biquad_cas_df1_32x64_q31(
&biquad_inst_fut,
(void *) filtering_q31_inputs,
(void *) filtering_output_fut,
blockSize));
arm_biquad_cas_df1_32x64_init_q31(
&biquad_inst_ref, numStages,
(q31_t*)filtering_coeffs_b_q31,
(void *) filtering_pState, postShift);
ref_biquad_cas_df1_32x64_q31(
&biquad_inst_ref,
(void *) filtering_q31_inputs,
(void *) filtering_output_ref,
blockSize);
FILTERING_SNR_COMPARE_INTERFACE(
blockSize,
q31_t))));
return JTEST_TEST_PASSED;
}
JTEST_DEFINE_TEST(arm_biquad_cascade_df2T_f64_test,
arm_biquad_cascade_df2T_f64)
{
arm_biquad_cascade_df2T_instance_f64 biquad_inst_fut = { 0 };
arm_biquad_cascade_df2T_instance_f64 biquad_inst_ref = { 0 };
TEMPLATE_DO_ARR_DESC(
blocksize_idx, uint32_t, blockSize, filtering_blocksizes
,
TEMPLATE_DO_ARR_DESC(
numstages_idx, uint16_t, numStages, filtering_numstages
,
/* Display test parameter values */
JTEST_DUMP_STRF("Block Size: %d\n"
"Number of Stages: %d\n",
(int)blockSize,
(int)numStages);
/* Initialize the BIQUAD Instances */
arm_biquad_cascade_df2T_init_f64(
&biquad_inst_fut, numStages,
(float64_t*)filtering_coeffs_b_f64,
(void *) filtering_pState);
JTEST_COUNT_CYCLES(
arm_biquad_cascade_df2T_f64(
&biquad_inst_fut,
(void *) filtering_f64_inputs,
(void *) filtering_output_fut,
blockSize));
arm_biquad_cascade_df2T_init_f64(
&biquad_inst_ref, numStages,
(float64_t*)filtering_coeffs_b_f64,
(void *) filtering_pState);
ref_biquad_cascade_df2T_f64(
&biquad_inst_ref,
(void *) filtering_f64_inputs,
(void *) filtering_output_ref,
blockSize);
FILTERING_DBL_SNR_COMPARE_INTERFACE(
blockSize,
float64_t)));
return JTEST_TEST_PASSED;
}
BIQUAD_DEFINE_TEST(f32,arm_biquad_casd_df1_inst_f32, df1,float32_t);
BIQUAD_DEFINE_TEST(f32,arm_biquad_cascade_df2T_instance_f32,df2T,float32_t);
BIQUAD_DEFINE_TEST(f32,arm_biquad_cascade_stereo_df2T_instance_f32,stereo_df2T,float32_t);
BIQUAD_WITH_POSTSHIFT_DEFINE_TEST(q31,df1,,q31_t);
BIQUAD_WITH_POSTSHIFT_DEFINE_TEST(q15,df1,,q15_t);
BIQUAD_WITH_POSTSHIFT_DEFINE_TEST(q31,df1,_fast,q31_t);
BIQUAD_WITH_POSTSHIFT_DEFINE_TEST(q15,df1,_fast,q15_t);
/*--------------------------------------------------------------------------------*/
/* Collect all tests in a group. */
/*--------------------------------------------------------------------------------*/
JTEST_DEFINE_GROUP(biquad_tests)
{
/*
To skip a test, comment it out.
*/
JTEST_TEST_CALL(arm_biquad_cascade_df1_f32_test);
JTEST_TEST_CALL(arm_biquad_cascade_df2T_f32_test);
JTEST_TEST_CALL(arm_biquad_cascade_stereo_df2T_f32_test);
JTEST_TEST_CALL(arm_biquad_cascade_df2T_f64_test);
JTEST_TEST_CALL(arm_biquad_cascade_df1_q31_test);
JTEST_TEST_CALL(arm_biquad_cascade_df1_q15_test);
JTEST_TEST_CALL(arm_biquad_cascade_df1_fast_q31_test);
JTEST_TEST_CALL(arm_biquad_cascade_df1_fast_q15_test);
JTEST_TEST_CALL(arm_biquad_cas_df1_32x64_q31_test);
}
|
c8b1b0ef99fdf6ae9f5a63726ef27ef3816393ad
|
7664f318ed04bd0680f3d82321c18896e3ef6ad5
|
/include/z64actor.h
|
4c1d0ec68ce971a197182dde5a1e471c3c1945e5
|
[] |
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
| 24,324
|
h
|
z64actor.h
|
#ifndef Z64ACTOR_H
#define Z64ACTOR_H
#include "z64dma.h"
#include "z64animation.h"
#include "z64math.h"
#include "z64collision_check.h"
#define ACTOR_NUMBER_MAX 200
#define INVISIBLE_ACTOR_MAX 20
#define MASS_IMMOVABLE 0xFF // Cannot be pushed by OC colliders
#define MASS_HEAVY 0xFE // Can only be pushed by OC colliders from actors with IMMOVABLE or HEAVY mass.
struct Actor;
struct PlayState;
struct Lights;
typedef void (*ActorFunc)(struct Actor*, struct PlayState*);
typedef void (*ActorShadowFunc)(struct Actor*, struct Lights*, struct PlayState*);
typedef u16 (*NpcGetTextIdFunc)(struct PlayState*, struct Actor*);
typedef s16 (*NpcUpdateTalkStateFunc)(struct PlayState*, struct Actor*);
typedef struct {
Vec3f pos;
Vec3s rot;
} PosRot; // size = 0x14
typedef struct {
/* 0x00 */ s16 id;
/* 0x02 */ u8 category; // Classifies actor and determines when it will update or draw
/* 0x04 */ u32 flags;
/* 0x08 */ s16 objectId;
/* 0x0C */ u32 instanceSize;
/* 0x10 */ ActorFunc init; // Constructor
/* 0x14 */ ActorFunc destroy; // Destructor
/* 0x18 */ ActorFunc update; // Update Function
/* 0x1C */ ActorFunc draw; // Draw function
} ActorInit; // size = 0x20
/**
* @see ACTOROVL_ALLOC_ABSOLUTE
*/
#define ACTOROVL_ABSOLUTE_SPACE_SIZE 0x27A0
/**
* The actor overlay should be allocated memory for when loading,
* and the memory deallocated when there is no more actor using the overlay.
*
* `ACTOROVL_ALLOC_` defines indicate how an actor overlay should be loaded.
*
* @note Bitwise or-ing `ACTOROVL_ALLOC_` types is not meaningful.
* The `ACTOROVL_ALLOC_` types are 0, 1, 2 but checked against with a bitwise and.
*
* @see ACTOROVL_ALLOC_ABSOLUTE
* @see ACTOROVL_ALLOC_PERSISTENT
* @see actor_table.h
*/
#define ACTOROVL_ALLOC_NORMAL 0
/**
* The actor overlay should be loaded to "absolute space".
*
* Absolute space is a fixed amount of memory allocated once.
* The overlay will still need to be loaded again if at some point there is no more actor using the overlay.
*
* @note Only one such overlay may be loaded at a time.
* This is not checked: a newly loaded overlay will overwrite the previous one in absolute space,
* even if actors are still relying on the previous one. Actors using absolute-allocated overlays should be deleted
* when another absolute-allocated overlay is about to be used.
*
* @see ACTOROVL_ABSOLUTE_SPACE_SIZE
* @see ActorContext.absoluteSpace
* @see ACTOROVL_ALLOC_NORMAL
*/
#define ACTOROVL_ALLOC_ABSOLUTE (1 << 0)
/**
* The actor overlay should be loaded persistently.
* It will stay loaded until the current game state instance ends.
*
* @see ACTOROVL_ALLOC_NORMAL
*/
#define ACTOROVL_ALLOC_PERSISTENT (1 << 1)
typedef struct {
/* 0x00 */ uintptr_t vromStart;
/* 0x04 */ uintptr_t vromEnd;
/* 0x08 */ void* vramStart;
/* 0x0C */ void* vramEnd;
/* 0x10 */ void* loadedRamAddr; // original name: "allocp"
/* 0x14 */ ActorInit* initInfo;
/* 0x18 */ char* name;
/* 0x1C */ u16 allocType; // See `ACTOROVL_ALLOC_` defines
/* 0x1E */ s8 numLoaded; // original name: "clients"
} ActorOverlay; // size = 0x20
typedef struct {
u8 table[32];
} DamageTable;
typedef struct {
/* 0x00 */ u8 health;
/* 0x02 */ s16 cylRadius;
/* 0x04 */ s16 cylHeight;
/* 0x06 */ u8 mass;
} CollisionCheckInfoInit;
typedef struct {
/* 0x00 */ u8 health;
/* 0x02 */ s16 cylRadius;
/* 0x04 */ s16 cylHeight;
/* 0x06 */ s16 cylYShift;
/* 0x08 */ u8 mass;
} CollisionCheckInfoInit2;
typedef struct {
/* 0x00 */ DamageTable* damageTable;
/* 0x04 */ Vec3f displacement; // Amount to correct actor velocity by when colliding into a body
/* 0x10 */ s16 cylRadius; // Used for various purposes
/* 0x12 */ s16 cylHeight; // Used for various purposes
/* 0x14 */ s16 cylYShift; // Unused. Purpose inferred from Cylinder16 and CollisionCheck_CylSideVsLineSeg
/* 0x16 */ u8 mass; // Used to compute displacement for OC collisions
/* 0x17 */ u8 health; // Note: some actors may use their own health variable instead of this one
/* 0x18 */ u8 damage; // Amount to decrement health by
/* 0x19 */ u8 damageEffect; // Stores what effect should occur when hit by a weapon
/* 0x1A */ u8 atHitEffect; // Stores what effect should occur when AT connects with an AC
/* 0x1B */ u8 acHitEffect; // Stores what effect should occur when AC is touched by an AT
} CollisionCheckInfo; // size = 0x1C
typedef struct {
/* 0x00 */ Vec3s rot; // Current actor shape rotation
/* 0x06 */ s16 face; // Used to index eyebrow/eye/mouth textures. Only used by player
/* 0x08 */ f32 yOffset; // Model y axis offset. Represents model space units
/* 0x0C */ ActorShadowFunc shadowDraw; // Shadow draw function
/* 0x10 */ f32 shadowScale; // Changes the size of the shadow
/* 0x14 */ u8 shadowAlpha; // Default is 255
/* 0x15 */ u8 feetFloorFlag; // 0 if actor or feet aren't on ground, or 1 or 2 depending on feet positions
/* 0x18 */ Vec3f feetPos[2]; // Update by using `Actor_SetFeetPos` in PostLimbDraw
} ActorShape; // size = 0x30
#define ACTOR_FLAG_0 (1 << 0)
#define ACTOR_FLAG_2 (1 << 2)
#define ACTOR_FLAG_3 (1 << 3)
#define ACTOR_FLAG_4 (1 << 4)
#define ACTOR_FLAG_5 (1 << 5)
#define ACTOR_FLAG_6 (1 << 6)
#define ACTOR_FLAG_7 (1 << 7)
#define ACTOR_FLAG_8 (1 << 8)
#define ACTOR_FLAG_9 (1 << 9)
#define ACTOR_FLAG_10 (1 << 10)
#define ACTOR_FLAG_ENKUSA_CUT (1 << 11)
#define ACTOR_FLAG_IGNORE_QUAKE (1 << 12) // actor will not shake when a quake occurs
#define ACTOR_FLAG_13 (1 << 13)
#define ACTOR_FLAG_14 (1 << 14)
#define ACTOR_FLAG_15 (1 << 15)
#define ACTOR_FLAG_16 (1 << 16)
#define ACTOR_FLAG_17 (1 << 17)
#define ACTOR_FLAG_18 (1 << 18)
#define ACTOR_FLAG_19 (1 << 19)
#define ACTOR_FLAG_20 (1 << 20)
#define ACTOR_FLAG_21 (1 << 21)
#define ACTOR_FLAG_22 (1 << 22)
#define ACTOR_FLAG_23 (1 << 23)
#define ACTOR_FLAG_24 (1 << 24)
#define ACTOR_FLAG_25 (1 << 25)
#define ACTOR_FLAG_26 (1 << 26)
#define ACTOR_FLAG_27 (1 << 27)
#define ACTOR_FLAG_28 (1 << 28)
#define COLORFILTER_GET_COLORINTENSITY(colorFilterParams) (((colorFilterParams) & 0x1F00) >> 5)
#define COLORFILTER_GET_DURATION(colorFilterParams) ((colorFilterParams) & 0xFF)
#define COLORFILTER_COLORFLAG_GRAY 0x8000
#define COLORFILTER_COLORFLAG_RED 0x4000
#define COLORFILTER_COLORFLAG_BLUE 0x0000
#define COLORFILTER_INTENSITY_FLAG 0x8000
#define COLORFILTER_BUFFLAG_XLU 0x2000
#define COLORFILTER_BUFFLAG_OPA 0x0000
#define BGCHECKFLAG_GROUND (1 << 0) // Standing on the ground
#define BGCHECKFLAG_GROUND_TOUCH (1 << 1) // Has touched the ground (only active for 1 frame)
#define BGCHECKFLAG_GROUND_LEAVE (1 << 2) // Has left the ground (only active for 1 frame)
#define BGCHECKFLAG_WALL (1 << 3) // Touching a wall
#define BGCHECKFLAG_CEILING (1 << 4) // Touching a ceiling
#define BGCHECKFLAG_WATER (1 << 5) // In water
#define BGCHECKFLAG_WATER_TOUCH (1 << 6) // Has touched water (reset when leaving water)
#define BGCHECKFLAG_GROUND_STRICT (1 << 7) // Strictly on ground (BGCHECKFLAG_GROUND has some leeway)
#define BGCHECKFLAG_CRUSHED (1 << 8) // Crushed between a floor and ceiling (triggers a void for player)
#define BGCHECKFLAG_PLAYER_WALL_INTERACT (1 << 9) // Only set/used by player, related to interacting with walls
typedef struct Actor {
/* 0x000 */ s16 id; // Actor ID
/* 0x002 */ u8 category; // Actor category. Refer to the corresponding enum for values
/* 0x003 */ s8 room; // Room number the actor is in. -1 denotes that the actor won't despawn on a room change
/* 0x004 */ u32 flags; // Flags used for various purposes
/* 0x008 */ PosRot home; // Initial position/rotation when spawned. Can be used for other purposes
/* 0x01C */ s16 params; // Configurable variable set by the actor's spawn data; original name: "args_data"
/* 0x01E */ s8 objBankIndex; // Object bank index of the actor's object dependency; original name: "bank"
/* 0x01F */ s8 targetMode; // Controls how far the actor can be targeted from and how far it can stay locked on
/* 0x020 */ u16 sfx; // SFX ID to play. Sfx plays when value is set, then is cleared the following update cycle
/* 0x024 */ PosRot world; // Position/rotation in the world
/* 0x038 */ PosRot focus; // Target reticle focuses on this position. For player this represents head pos and rot
/* 0x04C */ f32 targetArrowOffset; // Height offset of the target arrow relative to `focus` position
/* 0x050 */ Vec3f scale; // Scale of the actor in each axis
/* 0x05C */ Vec3f velocity; // Velocity of the actor in each axis
/* 0x068 */ f32 speed; // Context dependent speed value. Can be used for XZ or XYZ depending on which move function is used
/* 0x06C */ f32 gravity; // Acceleration due to gravity. Value is added to Y velocity every frame
/* 0x070 */ f32 minVelocityY; // Sets the lower bounds cap for velocity along the Y axis. Only relevant when moved with gravity.
/* 0x074 */ CollisionPoly* wallPoly; // Wall polygon the actor is touching
/* 0x078 */ CollisionPoly* floorPoly; // Floor polygon directly below the actor
/* 0x07C */ u8 wallBgId; // Bg ID of the wall polygon the actor is touching
/* 0x07D */ u8 floorBgId; // Bg ID of the floor polygon directly below the actor
/* 0x07E */ s16 wallYaw; // Y rotation of the wall polygon the actor is touching
/* 0x080 */ f32 floorHeight; // Y position of the floor polygon directly below the actor
/* 0x084 */ f32 yDistToWater; // Distance to the surface of active waterbox. Negative value means above water
/* 0x088 */ u16 bgCheckFlags; // Flags indicating how the actor is interacting with collision
/* 0x08A */ s16 yawTowardsPlayer; // Y rotation difference between the actor and the player
/* 0x08C */ f32 xyzDistToPlayerSq; // Squared distance between the actor and the player
/* 0x090 */ f32 xzDistToPlayer; // Distance between the actor and the player in the XZ plane
/* 0x094 */ f32 yDistToPlayer; // Dist is negative if the actor is above the player
/* 0x098 */ CollisionCheckInfo colChkInfo; // Variables related to the Collision Check system
/* 0x0B4 */ ActorShape shape; // Variables related to the physical shape of the actor
/* 0x0E4 */ Vec3f projectedPos; // Position of the actor in projected space
/* 0x0F0 */ f32 projectedW; // w component of the projected actor position
/* 0x0F4 */ f32 uncullZoneForward; // Amount to increase the uncull zone forward by (in projected space)
/* 0x0F8 */ f32 uncullZoneScale; // Amount to increase the uncull zone scale by (in projected space)
/* 0x0FC */ f32 uncullZoneDownward; // Amount to increase uncull zone downward by (in projected space)
/* 0x100 */ Vec3f prevPos; // World position from the previous update cycle
/* 0x10C */ u8 isTargeted; // Set to true if the actor is currently being targeted by the player
/* 0x10D */ u8 targetPriority; // Lower values have higher priority. Resets to 0 when player stops targeting
/* 0x10E */ u16 textId; // Text ID to pass to player/display when interacting with the actor
/* 0x110 */ u16 freezeTimer; // Actor does not update when set. Timer decrements automatically
/* 0x112 */ u16 colorFilterParams; // Set color filter to red, blue, or white. Toggle opa or xlu
/* 0x114 */ u8 colorFilterTimer; // A non-zero value enables the color filter. Decrements automatically
/* 0x115 */ u8 isDrawn; // Set to true if the actor is currently being drawn. Always stays false for lens actors
/* 0x116 */ u8 dropFlag; // Configures what item is dropped by the actor from `Item_DropCollectibleRandom`
/* 0x117 */ u8 naviEnemyId; // Sets what 0600 dialog to display when talking to navi. Default 0xFF
/* 0x118 */ struct Actor* parent; // Usage is actor specific. Set if actor is spawned via `Actor_SpawnAsChild`
/* 0x11C */ struct Actor* child; // Usage is actor specific. Set if actor is spawned via `Actor_SpawnAsChild`
/* 0x120 */ struct Actor* prev; // Previous actor of this category
/* 0x124 */ struct Actor* next; // Next actor of this category
/* 0x128 */ ActorFunc init; // Initialization Routine. Called by `Actor_Init` or `Actor_UpdateAll`
/* 0x12C */ ActorFunc destroy; // Destruction Routine. Called by `Actor_Destroy`
/* 0x130 */ ActorFunc update; // Update Routine. Called by `Actor_UpdateAll`
/* 0x134 */ ActorFunc draw; // Draw Routine. Called by `Actor_Draw`
/* 0x138 */ ActorOverlay* overlayEntry; // Pointer to the overlay table entry for this actor
/* 0x13C */ char dbgPad[0x10]; // Padding that only exists in the debug rom
} Actor; // size = 0x14C
typedef enum {
/* 0 */ FOOT_LEFT,
/* 1 */ FOOT_RIGHT
} ActorFootIndex;
/*
colorFilterParams WIP documentation
& 0x8000 : white
& 0x4000 : red
if neither of the above are set : blue
(& 0x1F00 >> 5) | 7 : color intensity
0x2000 : translucent, else opaque
*/
#define DYNA_TRANSFORM_POS (1 << 0) // Position of the actors on top follows the dynapoly actor's movement.
#define DYNA_TRANSFORM_ROT_Y (1 << 1) // The Y rotation of the actors on top follows the dynapoly actor's Y rotation.
#define DYNA_INTERACT_ACTOR_ON_TOP (1 << 0) // There is an actor standing on the collision of the dynapoly actor
#define DYNA_INTERACT_PLAYER_ON_TOP (1 << 1) // The player actor is standing on the collision of the dynapoly actor
#define DYNA_INTERACT_PLAYER_ABOVE (1 << 2) // The player is directly above the collision of the dynapoly actor (any distance above)
#define DYNA_INTERACT_3 (1 << 3) // Like the ACTOR_ON_TOP flag but only actors with ACTOR_FLAG_26
typedef struct DynaPolyActor {
/* 0x000 */ struct Actor actor;
/* 0x14C */ s32 bgId;
/* 0x150 */ f32 unk_150;
/* 0x154 */ f32 unk_154;
/* 0x158 */ s16 unk_158; // y rotation?
/* 0x15C */ u32 transformFlags;
/* 0x160 */ u8 interactFlags;
/* 0x162 */ s16 unk_162;
} DynaPolyActor; // size = 0x164
typedef struct {
/* 0x00 */ MtxF* matrices;
/* 0x04 */ s16* objectIds;
/* 0x08 */ s16 count;
/* 0x0C */ Gfx** dLists;
/* 0x10 */ s32 val; // used for various purposes: both a status indicator and counter
/* 0x14 */ s32 prevLimbIndex;
} BodyBreak;
#define BODYBREAK_OBJECT_DEFAULT -1 // use the same object as the actor
#define BODYBREAK_STATUS_READY -1
#define BODYBREAK_STATUS_FINISHED 0
typedef enum {
/* 0x00 */ ITEM00_RUPEE_GREEN,
/* 0x01 */ ITEM00_RUPEE_BLUE,
/* 0x02 */ ITEM00_RUPEE_RED,
/* 0x03 */ ITEM00_RECOVERY_HEART,
/* 0x04 */ ITEM00_BOMBS_A,
/* 0x05 */ ITEM00_ARROWS_SINGLE,
/* 0x06 */ ITEM00_HEART_PIECE,
/* 0x07 */ ITEM00_HEART_CONTAINER,
/* 0x08 */ ITEM00_ARROWS_SMALL,
/* 0x09 */ ITEM00_ARROWS_MEDIUM,
/* 0x0A */ ITEM00_ARROWS_LARGE,
/* 0x0B */ ITEM00_BOMBS_B,
/* 0x0C */ ITEM00_NUTS,
/* 0x0D */ ITEM00_STICK,
/* 0x0E */ ITEM00_MAGIC_LARGE,
/* 0x0F */ ITEM00_MAGIC_SMALL,
/* 0x10 */ ITEM00_SEEDS,
/* 0x11 */ ITEM00_SMALL_KEY,
/* 0x12 */ ITEM00_FLEXIBLE,
/* 0x13 */ ITEM00_RUPEE_ORANGE,
/* 0x14 */ ITEM00_RUPEE_PURPLE,
/* 0x15 */ ITEM00_SHIELD_DEKU,
/* 0x16 */ ITEM00_SHIELD_HYLIAN,
/* 0x17 */ ITEM00_TUNIC_ZORA,
/* 0x18 */ ITEM00_TUNIC_GORON,
/* 0x19 */ ITEM00_BOMBS_SPECIAL,
/* 0x1A */ ITEM00_MAX,
/* 0xFF */ ITEM00_NONE = 0xFF
} Item00Type;
struct EnItem00;
typedef void (*EnItem00ActionFunc)(struct EnItem00*, struct PlayState*);
typedef struct EnItem00 {
/* 0x000 */ Actor actor;
/* 0x14C */ EnItem00ActionFunc actionFunc;
/* 0x150 */ s16 collectibleFlag;
/* 0x152 */ s16 getItemId;
/* 0x154 */ s16 unk_154;
/* 0x156 */ s16 unk_156;
/* 0x158 */ s16 unk_158;
/* 0x15A */ s16 despawnTimer;
/* 0x15C */ f32 scale;
/* 0x160 */ ColliderCylinder collider;
} EnItem00; // size = 0x1AC
// Only A_OBJ_SIGNPOST_OBLONG and A_OBJ_SIGNPOST_ARROW are used in room files.
typedef enum {
/* 0x00 */ A_OBJ_BLOCK_SMALL,
/* 0x01 */ A_OBJ_BLOCK_LARGE,
/* 0x02 */ A_OBJ_BLOCK_HUGE,
/* 0x03 */ A_OBJ_BLOCK_SMALL_ROT,
/* 0x04 */ A_OBJ_BLOCK_LARGE_ROT,
/* 0x05 */ A_OBJ_CUBE_SMALL,
/* 0x06 */ A_OBJ_UNKNOWN_6,
/* 0x07 */ A_OBJ_GRASS_CLUMP,
/* 0x08 */ A_OBJ_TREE_STUMP,
/* 0x09 */ A_OBJ_SIGNPOST_OBLONG,
/* 0x0A */ A_OBJ_SIGNPOST_ARROW,
/* 0x0B */ A_OBJ_BOULDER_FRAGMENT,
/* 0x0C */ A_OBJ_MAX
} AObjType;
struct EnAObj;
typedef void (*EnAObjActionFunc)(struct EnAObj*, struct PlayState*);
typedef struct EnAObj {
/* 0x000 */ DynaPolyActor dyna;
/* 0x164 */ EnAObjActionFunc actionFunc;
/* 0x168 */ s32 rotateWaitTimer;
/* 0x16C */ s16 textId;
/* 0x16E */ s16 rotateState;
/* 0x170 */ s16 rotateForTimer;
/* 0x172 */ s16 rotSpeedY;
/* 0x174 */ s16 rotSpeedX;
/* 0x178 */ f32 focusYoffset;
/* 0x17C */ ColliderCylinder collider;
} EnAObj; // size = 0x1C8
typedef enum {
/* 0x00 */ ACTORCAT_SWITCH,
/* 0x01 */ ACTORCAT_BG,
/* 0x02 */ ACTORCAT_PLAYER,
/* 0x03 */ ACTORCAT_EXPLOSIVE,
/* 0x04 */ ACTORCAT_NPC,
/* 0x05 */ ACTORCAT_ENEMY,
/* 0x06 */ ACTORCAT_PROP,
/* 0x07 */ ACTORCAT_ITEMACTION,
/* 0x08 */ ACTORCAT_MISC,
/* 0x09 */ ACTORCAT_BOSS,
/* 0x0A */ ACTORCAT_DOOR,
/* 0x0B */ ACTORCAT_CHEST,
/* 0x0C */ ACTORCAT_MAX
} ActorCategory;
#define DEFINE_ACTOR(_0, enum, _2, _3) enum,
#define DEFINE_ACTOR_INTERNAL(_0, enum, _2, _3) enum,
#define DEFINE_ACTOR_UNSET(enum) enum,
typedef enum {
#include "tables/actor_table.h"
/* 0x0192 */ ACTOR_ID_MAX // originally "ACTOR_DLF_MAX"
} ActorID;
#undef DEFINE_ACTOR
#undef DEFINE_ACTOR_INTERNAL
#undef DEFINE_ACTOR_UNSET
typedef enum {
DOORLOCK_NORMAL,
DOORLOCK_BOSS,
DOORLOCK_NORMAL_SPIRIT
} DoorLockType;
typedef enum {
/* 0x00 */ NAVI_ENEMY_DEFAULT,
/* 0x01 */ NAVI_ENEMY_GOHMA,
/* 0x02 */ NAVI_ENEMY_GOHMA_EGG,
/* 0x03 */ NAVI_ENEMY_GOHMA_LARVA,
/* 0x04 */ NAVI_ENEMY_SKULLTULA,
/* 0x05 */ NAVI_ENEMY_BIG_SKULLTULA,
/* 0x06 */ NAVI_ENEMY_TAILPASARAN,
/* 0x07 */ NAVI_ENEMY_DEKU_BABA,
/* 0x08 */ NAVI_ENEMY_BIG_DEKU_BABA,
/* 0x09 */ NAVI_ENEMY_WITHERED_DEKU_BABA,
/* 0x0A */ NAVI_ENEMY_DEKU_SCRUB,
/* 0x0B */ NAVI_ENEMY_UNUSED_B,
/* 0x0C */ NAVI_ENEMY_KING_DODONGO,
/* 0x0D */ NAVI_ENEMY_DODONGO,
/* 0x0E */ NAVI_ENEMY_BABY_DODONGO,
/* 0x0F */ NAVI_ENEMY_LIZALFOS,
/* 0x10 */ NAVI_ENEMY_DINOLFOS,
/* 0x11 */ NAVI_ENEMY_FIRE_KEESE,
/* 0x12 */ NAVI_ENEMY_KEESE,
/* 0x13 */ NAVI_ENEMY_ARMOS,
/* 0x14 */ NAVI_ENEMY_BARINADE,
/* 0x15 */ NAVI_ENEMY_PARASITIC_TENTACLE,
/* 0x16 */ NAVI_ENEMY_SHABOM,
/* 0x17 */ NAVI_ENEMY_BIRI,
/* 0x18 */ NAVI_ENEMY_BARI,
/* 0x19 */ NAVI_ENEMY_STINGER,
/* 0x1A */ NAVI_ENEMY_PHANTOM_GANON_PHASE_2,
/* 0x1B */ NAVI_ENEMY_STALFOS,
/* 0x1C */ NAVI_ENEMY_BLUE_BUBBLE,
/* 0x1D */ NAVI_ENEMY_WHITE_BUBBLE,
/* 0x1E */ NAVI_ENEMY_GREEN_BUBBLE,
/* 0x1F */ NAVI_ENEMY_SKULLWALLTULA,
/* 0x20 */ NAVI_ENEMY_GOLD_SKULLTULA,
/* 0x21 */ NAVI_ENEMY_VOLVAGIA,
/* 0x22 */ NAVI_ENEMY_FLARE_DANCER,
/* 0x23 */ NAVI_ENEMY_TORCH_SLUG,
/* 0x24 */ NAVI_ENEMY_RED_BUBBLE,
/* 0x25 */ NAVI_ENEMY_MORPHA,
/* 0x26 */ NAVI_ENEMY_DARK_LINK,
/* 0x27 */ NAVI_ENEMY_SHELL_BLADE,
/* 0x28 */ NAVI_ENEMY_SPIKE,
/* 0x29 */ NAVI_ENEMY_BONGO_BONGO,
/* 0x2A */ NAVI_ENEMY_REDEAD,
/* 0x2B */ NAVI_ENEMY_PHANTOM_GANON_PHASE_1,
/* 0x2C */ NAVI_ENEMY_UNUSED_2C,
/* 0x2D */ NAVI_ENEMY_GIBDO,
/* 0x2E */ NAVI_ENEMY_DEAD_HANDS_HAND,
/* 0x2F */ NAVI_ENEMY_DEAD_HAND,
/* 0x30 */ NAVI_ENEMY_WALLMASTER,
/* 0x31 */ NAVI_ENEMY_FLOORMASTER,
/* 0x32 */ NAVI_ENEMY_TWINROVA_KOUME,
/* 0x33 */ NAVI_ENEMY_TWINROVA_KOTAKE,
/* 0x34 */ NAVI_ENEMY_IRON_KNUCKLE_NABOORU,
/* 0x35 */ NAVI_ENEMY_IRON_KNUCKLE,
/* 0x36 */ NAVI_ENEMY_SKULL_KID_ADULT,
/* 0x37 */ NAVI_ENEMY_LIKE_LIKE,
/* 0x38 */ NAVI_ENEMY_UNUSED_38,
/* 0x39 */ NAVI_ENEMY_BEAMOS,
/* 0x3A */ NAVI_ENEMY_ANUBIS,
/* 0x3B */ NAVI_ENEMY_FREEZARD,
/* 0x3C */ NAVI_ENEMY_UNUSED_3C,
/* 0x3D */ NAVI_ENEMY_GANONDORF,
/* 0x3E */ NAVI_ENEMY_GANON,
/* 0x3F */ NAVI_ENEMY_SKULL_KID,
/* 0x40 */ NAVI_ENEMY_SKULL_KID_FRIENDLY,
/* 0x41 */ NAVI_ENEMY_SKULL_KID_MASK,
/* 0x42 */ NAVI_ENEMY_OCTOROK,
/* 0x43 */ NAVI_ENEMY_POE_COMPOSER,
/* 0x44 */ NAVI_ENEMY_POE,
/* 0x45 */ NAVI_ENEMY_RED_TEKTITE,
/* 0x46 */ NAVI_ENEMY_BLUE_TEKTITE,
/* 0x47 */ NAVI_ENEMY_LEEVER,
/* 0x48 */ NAVI_ENEMY_PEAHAT,
/* 0x49 */ NAVI_ENEMY_PEAHAT_LARVA,
/* 0x4A */ NAVI_ENEMY_MOBLIN,
/* 0x4B */ NAVI_ENEMY_MOBLIN_CLUB,
/* 0x4C */ NAVI_ENEMY_WOLFOS,
/* 0x4D */ NAVI_ENEMY_MAD_SCRUB,
/* 0x4E */ NAVI_ENEMY_BUSINESS_SCRUB,
/* 0x4F */ NAVI_ENEMY_DAMPES_GHOST,
/* 0x50 */ NAVI_ENEMY_POE_SISTER_MEG,
/* 0x51 */ NAVI_ENEMY_POE_SISTER_JOELLE,
/* 0x52 */ NAVI_ENEMY_POE_SISTER_BETH,
/* 0x53 */ NAVI_ENEMY_POE_SISTER_AMY,
/* 0x54 */ NAVI_ENEMY_GERUDO_THIEF,
/* 0x55 */ NAVI_ENEMY_STALCHILD,
/* 0x56 */ NAVI_ENEMY_ICE_KEESE,
/* 0x57 */ NAVI_ENEMY_WHITE_WOLFOS,
/* 0x58 */ NAVI_ENEMY_GUAY,
/* 0x59 */ NAVI_ENEMY_BIGOCTO,
/* 0x5A */ NAVI_ENEMY_BIG_POE,
/* 0x5B */ NAVI_ENEMY_TWINROVA,
/* 0x5C */ NAVI_ENEMY_POE_WASTELAND,
/* 0xFF */ NAVI_ENEMY_NONE = 0xFF
} NaviEnemy;
#define TRANSITION_ACTOR_PARAMS_INDEX_SHIFT 10
#define GET_TRANSITION_ACTOR_INDEX(actor) ((u16)(actor)->params >> TRANSITION_ACTOR_PARAMS_INDEX_SHIFT)
// EnDoor and DoorKiller share openAnim and playerIsOpening
// Due to alignment, a substruct cannot be used in the structs of these actors.
#define DOOR_ACTOR_BASE \
/* 0x0000 */ Actor actor; \
/* 0x014C */ SkelAnime skelAnime; \
/* 0x0190 */ u8 openAnim; \
/* 0x0191 */ u8 playerIsOpening
typedef struct DoorActorBase {
/* 0x0000 */ DOOR_ACTOR_BASE;
} DoorActorBase;
// DoorShutter and DoorGerudo share isActive
// Due to alignment, a substruct cannot be used in the structs of these actors.
#define SLIDING_DOOR_ACTOR_BASE \
/* 0x0000 */ DynaPolyActor dyna; \
/* 0x0164 */ s16 isActive // Set to true by player when using the door. Also a timer for niche cases in DoorShutter
typedef struct SlidingDoorActorBase {
/* 0x0000 */ SLIDING_DOOR_ACTOR_BASE;
} SlidingDoorActorBase;
typedef enum {
/* 0x00 */ DOOR_OPEN_ANIM_ADULT_L,
/* 0x01 */ DOOR_OPEN_ANIM_CHILD_L,
/* 0x02 */ DOOR_OPEN_ANIM_ADULT_R,
/* 0x03 */ DOOR_OPEN_ANIM_CHILD_R,
/* 0x04 */ DOOR_OPEN_ANIM_MAX
} DoorOpenAnim;
#define UPDBGCHECKINFO_FLAG_0 (1 << 0) // check wall
#define UPDBGCHECKINFO_FLAG_1 (1 << 1) // check ceiling
#define UPDBGCHECKINFO_FLAG_2 (1 << 2) // check floor and water
#define UPDBGCHECKINFO_FLAG_3 (1 << 3)
#define UPDBGCHECKINFO_FLAG_4 (1 << 4)
#define UPDBGCHECKINFO_FLAG_5 (1 << 5) // unused
#define UPDBGCHECKINFO_FLAG_6 (1 << 6) // disable water ripples
#define UPDBGCHECKINFO_FLAG_7 (1 << 7) // alternate wall check?
typedef enum {
/* 0x0 */ NPC_TALK_STATE_IDLE, // NPC not currently talking to player
/* 0x1 */ NPC_TALK_STATE_TALKING, // NPC is currently talking to player
/* 0x2 */ NPC_TALK_STATE_ACTION, // An NPC-defined action triggered in the conversation
/* 0x3 */ NPC_TALK_STATE_ITEM_GIVEN // NPC finished giving an item and text box is done
} NpcTalkState;
typedef enum {
/* 0x0 */ NPC_TRACKING_PLAYER_AUTO_TURN, // Determine tracking mode based on player position, see Npc_UpdateAutoTurn
/* 0x1 */ NPC_TRACKING_NONE, // Don't track the target (usually the player)
/* 0x2 */ NPC_TRACKING_HEAD_AND_TORSO, // Track target by turning the head and the torso
/* 0x3 */ NPC_TRACKING_HEAD, // Track target by turning the head
/* 0x4 */ NPC_TRACKING_FULL_BODY // Track target by turning the body, torso and head
} NpcTrackingMode;
typedef struct {
/* 0x00 */ s16 talkState;
/* 0x02 */ s16 trackingMode;
/* 0x04 */ s16 autoTurnTimer;
/* 0x06 */ s16 autoTurnState;
/* 0x08 */ Vec3s headRot;
/* 0x0E */ Vec3s torsoRot;
/* 0x14 */ f32 yOffset; // Y position offset to add to actor position when calculating angle to target
/* 0x18 */ Vec3f trackPos;
/* 0x24 */ char unk_24[0x4];
} NpcInteractInfo; // size = 0x28
#endif
|
6aad24aaa00fe630761aff889e02d19d50e87b7e
|
7f6c235b0598353549959c18f69eefd20b766907
|
/libsrc/_DEVELOPMENT/EXAMPLES/zxn/dot-command/ls/128/options.c
|
3e34b9ecd2ad022ca3fbce3db4b86539585e0d07
|
[
"ClArtistic"
] |
permissive
|
z88dk/z88dk
|
46dfd4905f36d99333173cadd0a660839befc9f0
|
8b07f37cc43c5d9ffe69b563c80763491d8faff7
|
refs/heads/master
| 2023-09-04T19:29:49.254958
| 2023-09-03T20:51:24
| 2023-09-03T20:51:24
| 54,035,569
| 820
| 263
|
NOASSERTION
| 2023-09-05T11:09:04
| 2016-03-16T13:48:16
|
Assembly
|
UTF-8
|
C
| false
| false
| 6,717
|
c
|
options.c
|
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <errno.h>
#include "date.h"
#include "errors.h"
#include "ls.h"
#include "options.h"
#include "sort.h"
// option arguments
static unsigned char *option_next_arg(unsigned char *idx, int argc, char **argv)
{
if (++*idx < (unsigned char)argc) return argv[*idx];
return 0;
}
static unsigned char *option_equal_arg(unsigned char *p)
{
return strrstrip(strstrip(p));
}
// option exec
unsigned int option_exec_a(void)
{
flags.file_filter = (flags.file_filter & (~FLAG_FILE_FILTER_ALMOST_ALL)) | FLAG_FILE_FILTER_ALL;
return OPT_ACTION_OK;
}
unsigned int option_exec_A(void)
{
flags.file_filter = (flags.file_filter & (~FLAG_FILE_FILTER_ALL)) | FLAG_FILE_FILTER_ALMOST_ALL;
return OPT_ACTION_OK;
}
unsigned int option_exec_B(void)
{
flags.file_filter |= FLAG_FILE_FILTER_BACKUP;
return OPT_ACTION_OK;
}
struct block_size
{
unsigned char *symbol;
uint32_t divisor;
};
static struct block_size block_sizes[] = {
{ "K", 1024UL },
{ "M", 1048576UL },
{ "KB", 1000UL },
{ "MB", 1000000UL },
};
unsigned int option_exec_block_size_helper(unsigned char *p)
{
if (p && *p)
{
unsigned int num;
static unsigned char *endp;
// leading number
flags.size_divisor = 1UL;
errno = 0;
num = _strtou_(p, &endp, 0);
if (errno == 0)
{
flags.size_divisor = num;
p = endp;
}
// trailing suffix
for (unsigned char i = 0; i != sizeof(block_sizes) / sizeof(*block_sizes); ++i)
{
if (stricmp(block_sizes[i].symbol, p) == 0)
{
*p = 0;
flags.size_divisor *= block_sizes[i].divisor;
break;
}
}
// successful ?
if (*p == 0)
return OPT_ACTION_OK;
}
return (unsigned int)err_invalid_parameter;
}
unsigned int option_exec_block_size(unsigned char *idx, int argc, char **argv)
{
return option_exec_block_size_helper(option_equal_arg(argv[*idx] + strlen("--block-size=")));
}
unsigned int option_exec_h(void)
{
flags.size_type = FLAG_SIZE_TYPE_HUMAN;
return OPT_ACTION_OK;
}
unsigned int option_exec_si(void)
{
flags.size_type = FLAG_SIZE_TYPE_SI;
return OPT_ACTION_OK;
}
unsigned int option_exec_s(void)
{
flags.disp_size = 1;
return OPT_ACTION_OK;
}
unsigned int option_exec_t(void)
{
flags.sort_func = (void*)sort_cmp_file_by_time;
return OPT_ACTION_OK;
}
unsigned int option_exec_gdf(void)
{
flags.sort_mod |= FLAG_SORT_MOD_GDF;
return OPT_ACTION_OK;
}
unsigned int option_exec_r(void)
{
flags.sort_mod |= FLAG_SORT_MOD_REVERSE;
return OPT_ACTION_OK;
}
unsigned int option_exec_S(void)
{
flags.sort_func = (void*)sort_cmp_file_by_size;
return OPT_ACTION_OK;
}
unsigned int option_exec_U(void)
{
flags.sort_func = 0;
return OPT_ACTION_OK;
}
unsigned int option_exec_X(void)
{
flags.sort_func = (void*)sort_cmp_file_by_extension;
return OPT_ACTION_OK;
}
unsigned int option_exec_time_long_iso(void)
{
flags.date_func = date_fmt_long_iso;
return OPT_ACTION_OK;
}
unsigned int option_exec_time_iso(void)
{
flags.date_func = date_fmt_iso;
return OPT_ACTION_OK;
}
unsigned int option_exec_time_locale(void)
{
flags.date_func = date_fmt_locale;
return OPT_ACTION_OK;
}
unsigned int option_exec_color_never(void)
{
flags.name_fmt_mod &= ~FLAG_NAME_FMT_MOD_COLOR;
return OPT_ACTION_OK;
}
unsigned int option_exec_color_always(void)
{
flags.name_fmt_mod |= FLAG_NAME_FMT_MOD_COLOR;
return OPT_ACTION_OK;
}
unsigned int option_exec_F(void)
{
flags.name_fmt_classify = FLAG_NAME_FMT_CLASSIFY_ALL;
return OPT_ACTION_OK;
}
unsigned int option_exec_file_type(void)
{
flags.name_fmt_classify = FLAG_NAME_FMT_CLASSIFY_ALL & (~FLAG_NAME_FMT_CLASSIFY_EXE);
return OPT_ACTION_OK;
}
unsigned int option_exec_indicator_style_none(void)
{
flags.name_fmt_classify = FLAG_NAME_FMT_CLASSIFY_NONE;
return OPT_ACTION_OK;
}
unsigned int option_exec_p(void)
{
flags.name_fmt_classify = FLAG_NAME_FMT_CLASSIFY_DIR;
return OPT_ACTION_OK;
}
unsigned int option_exec_Q(void)
{
flags.name_fmt_mod |= FLAG_NAME_FMT_MOD_QUOTE;
return OPT_ACTION_OK;
}
unsigned int option_exec_C(void)
{
flags.disp_fmt = FLAG_DISP_FMT_COLUMN;
return OPT_ACTION_OK;
}
unsigned int option_exec_x(void)
{
flags.disp_fmt = FLAG_DISP_FMT_ACROSS;
return OPT_ACTION_OK;
}
unsigned int option_exec_m(void)
{
flags.disp_fmt = FLAG_DISP_FMT_COMMAS;
return OPT_ACTION_OK;
}
unsigned int option_exec_l(void)
{
flags.disp_fmt = FLAG_DISP_FMT_LONG;
return OPT_ACTION_OK;
}
unsigned int option_exec_one(void)
{
flags.disp_fmt = FLAG_DISP_FMT_PER_LINE;
return OPT_ACTION_OK;
}
unsigned int option_exec_w_helper(unsigned char *p)
{
if (p)
{
unsigned int res;
static unsigned char *endp;
errno = 0;
res = _strtou_(p, &endp, 0);
if ((errno == 0) && (*endp == 0) && (res < 256)) // there is a -1 option so eliminate negative values
{
flags.disp_width = res;
return OPT_ACTION_OK;
}
}
return (unsigned int)err_invalid_parameter;
}
unsigned int option_exec_w(unsigned char *idx, int argc, char **argv)
{
return option_exec_w_helper(option_next_arg(idx, argc, argv));
}
unsigned int option_exec_width(unsigned char *idx, int argc, char **argv)
{
return option_exec_w_helper(option_equal_arg(argv[*idx] + strlen("--width=")));
}
unsigned int option_exec_d(void)
{
flags.dir_type = FLAG_DIR_TYPE_LIST;
return OPT_ACTION_OK;
}
unsigned int option_exec_R(void)
{
flags.dir_type = FLAG_DIR_TYPE_RECURSIVE;
return OPT_ACTION_OK;
}
unsigned int option_exec_system(void)
{
flags.sys = 1;
return OPT_ACTION_OK;
}
unsigned int option_exec_help(void)
{
flags.help = 1;
return OPT_ACTION_OK;
}
unsigned int option_exec_version(void)
{
flags.version = 1;
return OPT_ACTION_OK;
}
unsigned int option_exec_lfn_on(void)
{
flags.name_fmt_mod = (flags.name_fmt_mod & ~(FLAG_NAME_FMT_MOD_SFN | FLAG_NAME_FMT_MOD_LFN | FLAG_NAME_FMT_MOD_AUTO)) | FLAG_NAME_FMT_MOD_LFN;
return OPT_ACTION_OK;
}
unsigned int option_exec_lfn_off(void)
{
flags.name_fmt_mod = (flags.name_fmt_mod & ~(FLAG_NAME_FMT_MOD_SFN | FLAG_NAME_FMT_MOD_LFN | FLAG_NAME_FMT_MOD_AUTO)) | FLAG_NAME_FMT_MOD_SFN;
return OPT_ACTION_OK;
}
unsigned int option_exec_lfn_both(void)
{
flags.name_fmt_mod = (flags.name_fmt_mod & ~(FLAG_NAME_FMT_MOD_SFN | FLAG_NAME_FMT_MOD_LFN | FLAG_NAME_FMT_MOD_AUTO)) | FLAG_NAME_FMT_MOD_SFN | FLAG_NAME_FMT_MOD_LFN;
return OPT_ACTION_OK;
}
|
6a3d8826dab584ddfc11e975b4beb07a2ab94e55
|
d0dc556f8b1d18ecbadef182bafd97b632dd3104
|
/ch12/smart_fan/lib/aws/app_aws.h
|
cfe86c6bb3d0904475e4e2b291d77c2238a8c7fa
|
[
"MIT"
] |
permissive
|
PacktPublishing/Internet-of-Things-with-ESP32
|
da3f2c57e2bd871b134b22841fd275c51f88d487
|
3ada8b905e53961940511636991a839059de7cd1
|
refs/heads/main
| 2023-02-08T13:58:32.585403
| 2023-01-30T10:03:23
| 2023-01-30T10:03:23
| 315,618,086
| 114
| 36
| null | null | null | null |
UTF-8
|
C
| false
| false
| 252
|
h
|
app_aws.h
|
#ifndef app_aws_h_
#define app_aws_h_
#include <stdint.h>
#define AWS_THING_NAME "myhome_fan1"
typedef void (*fan_state_changed_f)(uint8_t);
void appaws_init(fan_state_changed_f);
void appaws_connect(void *);
void appaws_publish(uint8_t);
#endif
|
0b31b48540e10b22d50fdfdf5205238f69a44d73
|
a3e7088f055ba6630811109725eacf2c848beb74
|
/GameGuru Core/GameGuru/Include/Common.h
|
03c693a0b5b21cba21e301fb50c9a87bc6aaa448
|
[] |
no_license
|
TheGameCreators/GameGuruRepo
|
36482fae506c248430028257b4c06680a9530e18
|
a1ea066e6b57c02b067bdaad4db22399095aa710
|
refs/heads/master
| 2023-07-08T03:17:06.712299
| 2023-06-19T11:45:06
| 2023-06-19T11:45:06
| 117,701,801
| 158
| 62
| null | 2023-06-29T05:57:55
| 2018-01-16T15:29:09
|
C++
|
UTF-8
|
C
| false
| false
| 2,694
|
h
|
Common.h
|
//----------------------------------------------------
//--- GAMEGURU - Common
//----------------------------------------------------
#include "cstr.h"
const char *pestrcasestr(const char *arg1, const char *arg2);
void common_init_globals ( void );
void common_init ( void );
void common_autoupdatecheck ( void );
void common_loop_logic(void);
void common_finish(void);
int common_isserialcodevalid ( LPSTR pCode, LPSTR pOptionalUserName );
void common_writeserialcode ( LPSTR pCode, LPSTR pOptionalUserName );
void FPSC_SetDefaults ( void );
void FPSC_LoadSETUPINI ( bool bUseMySystemFolder );
void FPSC_Full_Data_Init ( void );
void common_switchtomysystemfolder ( void );
void FPSC_VeryEarlySetup(void);
void FPSC_Setup ( void );
LPSTR FindFileFromEntityBank ( LPSTR pFindThisFilename );
void common_loadfonts ( void );
void common_loadcommonassets ( int iShowScreenPrompts );
void common_hide_mouse ( void );
void common_show_mouse ( void );
void common_vectorsinit ( void );
void common_wipeeffectifnotexist ( void );
void common_makeeffecttextureset ( void );
void common_justbeforeend ( void );
//void version_commandlineprompt ( void );
//void version_endofinit ( void );
void version_splashtext_statusupdate ( void );
//void version_splashtext ( void );
void version_onscreenlogos ( void );
void version_permittestgame ( void );
//void version_resourcewarning ( void );
void version_universe_saveELEandLGT ( void );
void version_universe_construct ( void );
void version_buildgame ( void );
void version_main_game_buildexe ( void );
//void common_refreshDisplaySize ( void );
void popup_text_close ( void );
void loadresource ( void );
void saveresource ( void );
int openresource ( char* name_s );
int closeresource ( void );
void resetfilecollection ( void );
void addfiletocollection ( char* filename_s );
void addallfilestocollection ( char* folder_s );
void hide3d ( void );
void show3d ( void );
void debugfilename ( char* tfile_s, char* desc_s );
void debugstring ( char* tfile_s, char* desc_s );
void debugseevar ( int var );
void debugviewactivate ( int mode );
void debugviewprogressmax ( int progressmax );
void debugviewtext ( int progress, char* gamedebugviewtext_s );
void printvalue ( int x, int y, int value );
int loadinternalmesh ( char* tfile_s );
char* browseropen_s ( int browsemode );
void loadscreenpromptassets ( int iUseVRTest );
void printscreenprompt ( char* screenprompt_s );
int mod ( int num, int modulus );
void GGBoxGradient ( int iLeft, int iTop, int iRight, int iBottom, DWORD dw1, DWORD dw2, DWORD dw3, DWORD dw4 );
void InkEx ( int r, int g, int b );
void BoxEx ( int x1, int y1, int x2, int y2 );
void LineEx ( int x1, int y1, int x2, int y2 );
|
551381e1eb69d71af0901d0380888f6daff931ef
|
88ae8695987ada722184307301e221e1ba3cc2fa
|
/third_party/xnnpack/src/src/f16-gemm/gen/f16-gemminc-1x16-minmax-neonfp16arith-ld64.c
|
2abfcf81525c4479c5efca005866d97ca32170f5
|
[
"Apache-2.0",
"LGPL-2.0-or-later",
"MIT",
"GPL-1.0-or-later",
"BSD-3-Clause",
"LicenseRef-scancode-generic-cla"
] |
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
| 5,980
|
c
|
f16-gemminc-1x16-minmax-neonfp16arith-ld64.c
|
// Auto-generated file. Do not edit!
// Template: src/f16-gemm/neonfp16arith-ld64.c.in
// Generator: tools/xngen
//
// Copyright 2020 Google LLC
//
// This source code is licensed under the BSD-style license found in the
// LICENSE file in the root directory of this source tree.
#include <assert.h>
#include <arm_neon.h>
#include <xnnpack/common.h>
#include <xnnpack/gemm.h>
#include <xnnpack/intrinsics-polyfill.h>
void xnn_f16_gemminc_minmax_ukernel_1x16__neonfp16arith_ld64(
size_t mr,
size_t nc,
size_t kc,
const void* restrict a,
size_t a_stride,
const void* restrict w,
void* restrict c,
size_t cm_stride,
size_t cn_stride,
const void*restrict acc,
const union xnn_f16_minmax_params params[restrict XNN_MIN_ELEMENTS(1)])
{
assert(mr != 0);
assert(mr <= 1);
assert(nc != 0);
assert(kc != 0);
assert(kc % sizeof(uint16_t) == 0);
assert(a != NULL);
assert(w != NULL);
assert(c != NULL);
assert(acc != NULL);
const uint16_t* a0 = (const uint16_t*) a;
uint16_t* c0 = (uint16_t*) c;
do {
float16x8_t vacc0x01234567 = vreinterpretq_f16_u16(vld1q_u16(acc)); acc = (const void*) ((uintptr_t) acc + sizeof(float16x8_t));
float16x8_t vacc0x89ABCDEF = vreinterpretq_f16_u16(vld1q_u16(acc)); acc = (const void*) ((uintptr_t) acc + sizeof(float16x8_t));
size_t k = kc;
while (k >= 4 * sizeof(uint16_t)) {
const float16x4_t va0 = vreinterpret_f16_u16(vld1_u16(a0)); a0 += 4;
const float16x8_t vb01234567c0 = vreinterpretq_f16_u16(vld1q_u16(w)); w = (const void*) ((uintptr_t) w + sizeof(float16x8_t));
const float16x8_t vb89ABCDEFc0 = vreinterpretq_f16_u16(vld1q_u16(w)); w = (const void*) ((uintptr_t) w + sizeof(float16x8_t));
#if XNN_ARCH_ARM64
vacc0x01234567 = vfmaq_lane_f16(vacc0x01234567, vb01234567c0, va0, 0);
vacc0x89ABCDEF = vfmaq_lane_f16(vacc0x89ABCDEF, vb89ABCDEFc0, va0, 0);
#else
vacc0x01234567 = vmlaq_lane_f16(vacc0x01234567, vb01234567c0, va0, 0);
vacc0x89ABCDEF = vmlaq_lane_f16(vacc0x89ABCDEF, vb89ABCDEFc0, va0, 0);
#endif
const float16x8_t vb01234567c1 = vreinterpretq_f16_u16(vld1q_u16(w)); w = (const void*) ((uintptr_t) w + sizeof(float16x8_t));
const float16x8_t vb89ABCDEFc1 = vreinterpretq_f16_u16(vld1q_u16(w)); w = (const void*) ((uintptr_t) w + sizeof(float16x8_t));
#if XNN_ARCH_ARM64
vacc0x01234567 = vfmaq_lane_f16(vacc0x01234567, vb01234567c1, va0, 1);
vacc0x89ABCDEF = vfmaq_lane_f16(vacc0x89ABCDEF, vb89ABCDEFc1, va0, 1);
#else
vacc0x01234567 = vmlaq_lane_f16(vacc0x01234567, vb01234567c1, va0, 1);
vacc0x89ABCDEF = vmlaq_lane_f16(vacc0x89ABCDEF, vb89ABCDEFc1, va0, 1);
#endif
const float16x8_t vb01234567c2 = vreinterpretq_f16_u16(vld1q_u16(w)); w = (const void*) ((uintptr_t) w + sizeof(float16x8_t));
const float16x8_t vb89ABCDEFc2 = vreinterpretq_f16_u16(vld1q_u16(w)); w = (const void*) ((uintptr_t) w + sizeof(float16x8_t));
#if XNN_ARCH_ARM64
vacc0x01234567 = vfmaq_lane_f16(vacc0x01234567, vb01234567c2, va0, 2);
vacc0x89ABCDEF = vfmaq_lane_f16(vacc0x89ABCDEF, vb89ABCDEFc2, va0, 2);
#else
vacc0x01234567 = vmlaq_lane_f16(vacc0x01234567, vb01234567c2, va0, 2);
vacc0x89ABCDEF = vmlaq_lane_f16(vacc0x89ABCDEF, vb89ABCDEFc2, va0, 2);
#endif
const float16x8_t vb01234567c3 = vreinterpretq_f16_u16(vld1q_u16(w)); w = (const void*) ((uintptr_t) w + sizeof(float16x8_t));
const float16x8_t vb89ABCDEFc3 = vreinterpretq_f16_u16(vld1q_u16(w)); w = (const void*) ((uintptr_t) w + sizeof(float16x8_t));
#if XNN_ARCH_ARM64
vacc0x01234567 = vfmaq_lane_f16(vacc0x01234567, vb01234567c3, va0, 3);
vacc0x89ABCDEF = vfmaq_lane_f16(vacc0x89ABCDEF, vb89ABCDEFc3, va0, 3);
#else
vacc0x01234567 = vmlaq_lane_f16(vacc0x01234567, vb01234567c3, va0, 3);
vacc0x89ABCDEF = vmlaq_lane_f16(vacc0x89ABCDEF, vb89ABCDEFc3, va0, 3);
#endif
k -= 4 * sizeof(uint16_t);
}
if XNN_UNLIKELY(k != 0) {
do {
const float16x8_t va0 = vreinterpretq_f16_u16(vld1q_dup_u16(a0)); a0 += 1;
const float16x8_t vb01234567 = vreinterpretq_f16_u16(vld1q_u16(w)); w = (const void*) ((uintptr_t) w + sizeof(float16x8_t));
const float16x8_t vb89ABCDEF = vreinterpretq_f16_u16(vld1q_u16(w)); w = (const void*) ((uintptr_t) w + sizeof(float16x8_t));
vacc0x01234567 = vfmaq_f16(vacc0x01234567, va0, vb01234567);
vacc0x89ABCDEF = vfmaq_f16(vacc0x89ABCDEF, va0, vb89ABCDEF);
k -= sizeof(uint16_t);
} while (k != 0);
}
const float16x8_t vmin = vreinterpretq_f16_u16(vld1q_dup_u16(¶ms->fp16arith.min));
vacc0x01234567 = vmaxq_f16(vacc0x01234567, vmin);
vacc0x89ABCDEF = vmaxq_f16(vacc0x89ABCDEF, vmin);
const float16x8_t vmax = vreinterpretq_f16_u16(vld1q_dup_u16(¶ms->fp16arith.max));
vacc0x01234567 = vminq_f16(vacc0x01234567, vmax);
vacc0x89ABCDEF = vminq_f16(vacc0x89ABCDEF, vmax);
if XNN_LIKELY(nc >= 16) {
vst1q_u16(c0, vreinterpretq_u16_f16(vacc0x01234567));
vst1q_u16(c0 + 8, vreinterpretq_u16_f16(vacc0x89ABCDEF));
c0 = (uint16_t*) ((uintptr_t) c0 + cn_stride);
a0 = (const uint16_t*) ((uintptr_t) a0 - kc);
nc -= 16;
} else {
if (nc & 8) {
vst1q_u16(c0, vreinterpretq_u16_f16(vacc0x01234567)); c0 += 8;
vacc0x01234567 = vacc0x89ABCDEF;
}
float16x4_t vacc0x0123 = vget_low_f16(vacc0x01234567);
if (nc & 4) {
vst1_u16(c0, vreinterpret_u16_f16(vacc0x0123)); c0 += 4;
vacc0x0123 = vget_high_f16(vacc0x01234567);
}
if (nc & 2) {
vst1_lane_u32((void*) c0, vreinterpret_u32_f16(vacc0x0123), 0); c0 += 2;
vacc0x0123 = vext_f16(vacc0x0123, vacc0x0123, 2);
}
if (nc & 1) {
vst1_lane_u16(c0, vreinterpret_u16_f16(vacc0x0123), 0);
}
nc = 0;
}
} while (nc != 0);
}
|
e4791ea4245a238f9b9a1c97d80699069205e7fa
|
f8cc1dd4b1378490386def2e0571561fab10b275
|
/src/libstddjb/stralloc_append.c
|
a51db369f7d21bc626d8a5fedfb29c6ce7098831
|
[
"ISC"
] |
permissive
|
skarnet/skalibs
|
b1eb2a0e38663cbfa918ee0a7916f56227bd7c2d
|
1f2d5f95684e93f8523e369ef1fed7a75c444082
|
refs/heads/master
| 2023-08-23T07:33:20.996016
| 2023-08-08T09:39:15
| 2023-08-08T09:39:15
| 31,461,366
| 104
| 32
|
ISC
| 2021-04-11T10:10:54
| 2015-02-28T12:01:41
|
C
|
UTF-8
|
C
| false
| false
| 134
|
c
|
stralloc_append.c
|
/* ISC license. */
#include <skalibs/stralloc.h>
int stralloc_append (stralloc *sa, char c)
{
return stralloc_catb(sa, &c, 1) ;
}
|
fea5edf6c5ee94767b7cd39031fad630509b82e8
|
a37180e6d95ed830b4b41ae75338f76c73a3652e
|
/Firmware/radio/AES/GenerateDecryptionKey.c
|
091c32b42ecec51c907ae60efa80cde0fa63bbd8
|
[] |
permissive
|
ArduPilot/SiK
|
86620e4fa74ca970c0cc75e28774d6e555309f8c
|
ec1d5e8947581e31edcecd1d5c8423ba244ea2d3
|
refs/heads/master
| 2023-08-05T08:37:55.486220
| 2023-07-07T21:40:45
| 2023-07-11T02:45:36
| 2,713,719
| 155
| 110
|
BSD-2-Clause
| 2023-08-01T09:48:40
| 2011-11-05T03:34:08
|
C
|
UTF-8
|
C
| false
| false
| 8,614
|
c
|
GenerateDecryptionKey.c
|
//=============================================================================
// GenerateDecryptionKey.c
//=============================================================================
// Copyright 2011 Silicon Laboratories, Inc.
// http://www.silabs.com
//
// C File Description:
//
//
// Target:
// Si102x/3x
//
// IDE:
// Silicon Laboratories IDE
//
// Tool Chains:
// Keil
// SDCC
// Raisonance
//
// Project Name:
// Si102x/3x AES Code Examples
//
// This software must be used in accordance with the End User License Agreement.
//
//=============================================================================
//-----------------------------------------------------------------------------
// uncomment pragma SRC to generate assembly code
//-----------------------------------------------------------------------------
//#pragma SRC
//=============================================================================
// Includes
//=============================================================================
#include <compiler_defs.h>
#include <Si1020_defs.h>
#include "GenerateDecryptionKey.h"
#include "AES_defs.h"
#include "DMA_defs.h"
//=============================================================================
// Function Prototypes
//=============================================================================
//-----------------------------------------------------------------------------
// GenerateDecryptionKey()
//
// parameters:
// encryptionKey - xdata pointer to encryption key data source
// decryptionKey - xdata pointer to decryption key data destination
// keySize - enumerated type for key size 0/1/2 = 128/192/256
//
// returns:
// status - 0 for success
// - 1 for ERROR - Invalid Key size parameter.
//
// description:
//
// This function will generate a decryption key corresponding to a
// given encryption key.
//
// The encryption key must be stored in xdata prior to calling
// the GenerateDecryptionKey function.
//
// The encryption key must be used for all encryption operations and the
// decryption key must be used for all decryption operations.
// (Except CTR Mode which uses the encryption key for both operations.)
//
// The AES code examples uses four channels as defined in the DMA_defs.h file.
// The channel assignments are static and fixed at compile time. They are
// not assigned dynamically.
//
// This function puts the MCU core into idle mode while encryption operation
// is in process. This function is blocking. The function does not return
// until after the encrpytion operation has completed.
//
// A interrupt is needed to wake up from Idle mode. This requires that the
// global interrupts are enabled. Also, a small DMA ISR that disables EIE2
// bit 5 is required in the main module.
//
// Note that the extended portion of the extended keys comes out first,
// before the first 16 bytes. So two DMA operations are used for the
// AESYOUT channel for an extended key.
//
//-----------------------------------------------------------------------------
GENERATE_DECRYPTION_KEY_STATUS
GenerateDecryptionKey (
VARIABLE_SEGMENT_POINTER(encryptionKey, U8, SEG_XDATA),
VARIABLE_SEGMENT_POINTER(decryptionKey, U8, SEG_XDATA),
GENERATE_DECRYPTION_KEY_SIZE keySize)
{
// unions used for compiler independent endianness.
UU16 addr; // Union used to access pointer bytes.
U8 keyLength; // Used to calculate key length in bytes.
// check first for valid operation
if(keySize >= KEY_SIZE_UNDEFINED)
{
return ERROR_INVALID_PARAMETER;
}
else
{
// Calculate key length in bytes based on operation parameter.
keyLength = ((keySize + 2) << 3);
}
SFRPAGE = DPPE_PAGE;
AES0BCFG = 0x00; // disable, for now
AES0DCFG = 0x00; // disable for now
// Disable AES0KIN, AES0BIN, & AES0YOUT channels.
DMA0EN &= ~AES0_KBY_MASK;
// Configure AES key input channel using key pointer.
// Set length to calculated key length.
// Clear DMA0NMD to disable Key wrapping.
// Generating the decryption key only requires encrypting one block.
DMA0SEL = AES0KIN_CHANNEL;
DMA0NCF = AES0KIN_PERIPHERAL_REQUEST;
DMA0NMD = NO_WRAPPING;
addr.U16 = (U16)(encryptionKey);
DMA0NBAL = addr.U8[LSB];
DMA0NBAH = addr.U8[MSB];
DMA0NSZH = 0;
DMA0NSZL = keyLength;
DMA0NAOL = 0;
DMA0NAOH = 0;
// Configure AES Block input channel.
// Since the input data does not matter, the base address is set to
// 0x0000 and the first 16 bytes of data in xram are used.
// Set length to 16.
// Clear DMA0NMD to disable Key wrapping.
DMA0SEL = AES0BIN_CHANNEL;
DMA0NCF = AES0BIN_PERIPHERAL_REQUEST;
DMA0NMD = NO_WRAPPING;
DMA0NBAL = 0x00;
DMA0NBAH = 0x00;
DMA0NSZH = 0;
DMA0NSZL = 16; // one block
DMA0NAOL = 0;
DMA0NAOH = 0;
// Configure AES Y output channel for decryption key.
// Enable DMA interrupt
// Set length to calculated key length.
// Clear DMA0NMD to disable Key wrapping.
DMA0SEL = AES0YOUT_CHANNEL;
DMA0NCF = AES0YOUT_PERIPHERAL_REQUEST|DMA_INT_EN;
DMA0NMD = NO_WRAPPING;
addr.U16 = (U16)(decryptionKey);
DMA0NBAL = addr.U8[LSB];
DMA0NBAH = addr.U8[MSB];
DMA0NSZH = 0;
DMA0NSZL = keyLength;
DMA0NAOH = 0;
// Configure starting address offset to byte 16 if extended key is used.
if (keySize> KEY_SIZE_128_BITS) // if extended key
DMA0NAOL = 0x10; // point to extended portion
else
DMA0NAOL = 0x00; // else point to start
// Clear KBY (Key, Block, and Y out) bits in DMA0INT sfr using mask.
DMA0INT &= ~AES0_KBY_MASK;
// Set KBY (Key, Block, and Y out) bits in DMA0EN sfr using mask.
// This enables the DMA. But the encyption/decryption operation
// won't start until the AES block is enabled.
DMA0EN |= AES0_KBY_MASK;
// Configure AES0DCFG to send inverse key to AES0YOUT
AES0DCFG = INVERSE_KEY;
// Set AES0BCFG according to keySize parameter.
AES0BCFG = keySize;
// Generating the decryption key always uses encryption mode.
AES0BCFG |= ENCRYPTION_MODE;
// Enabled AES module to start encryption operation.
AES0BCFG |= AES_ENABLE;
// enable DMA interrupt to terminate Idle mode
EIE2 |= 0x20;
// This do...while loop ensures that the CPU will remain in Idle mode
// until AES0YOUT DMA channel transfer is complete.
do
{
#ifdef DMA_TRANSFERS_USE_IDLE
PCON |= 0x01; // go to Idle mode
#endif
} while((DMA0INT & AES0YOUT_MASK)==0);
if (keySize> KEY_SIZE_128_BITS) // if extended key
{
// It is reccomended to pause the AES DMA channels
// while changing the DMA setup. The AES block cannot
// be disabled or the rest of the key would be lost.
// Pause DMA channels used by AES block.
DMA0EN &= ~AES0_KBY_MASK;
DMA0SEL = AES0YOUT_CHANNEL; // select AES0YOUT DMA ch
DMA0NAOL = 0; // reset pointer
DMA0NSZL = 0x10; // set length to 16 (128-bits)
// Clear KBXY (Key, Block, and Y out) bits in DMA0INT sfr using mask.
DMA0INT &= ~AES0_KBXY_MASK;
// Set AES0YOUT DMA enable bit only in DMA0EN sfr using mask.
// This enables the DMA and the rest of the key will be written out.
DMA0EN |= AES0YOUT_MASK;
// enable DMA interrupt to terminate Idle mode
EIE2 |= 0x20;
// This do...while loop ensures that the CPU will remain in Idle mode
// until AES0YOUT DMA channel transfer is complete.
do
{
#ifdef DMA_TRANSFERS_USE_IDLE
PCON |= 0x01; // go to Idle mode
#endif
} while((DMA0INT & AES0YOUT_MASK)==0);
}
//Clear AES Block
AES0BCFG = 0x00;
AES0DCFG = 0x00;
// Clear KBY (Key, Block, and Y out) bits in DMA0EN sfr using mask.
DMA0EN &= ~AES0_KBY_MASK;
// Clear KBY (Key, Block, and Y out) bits in DMA0INT sfr using mask.
DMA0INT &= ~AES0_KBY_MASK;
return SUCCESS;
}
//=============================================================================
// End of file
//=============================================================================
|
63f4d1dedd841467447f1fc196c0883db945944a
|
19a9f2c19bcb81c4a14ba17831d3098de7731fb5
|
/ni/src/lib/nfp/omcalc_ccmW.c
|
40b1c9b1b7e5e7fc30023bb4b368a97467b580f2
|
[
"Apache-2.0"
] |
permissive
|
NCAR/ncl
|
243c30eaefce642d53373aa583b73df72eb59f22
|
8a96101fe14d0cf0f5ed66a5e6b1733084bc69df
|
refs/heads/develop
| 2023-03-17T07:53:18.883458
| 2022-05-11T16:01:03
| 2022-05-11T16:01:03
| 67,087,395
| 254
| 68
|
NOASSERTION
| 2022-10-08T07:20:06
| 2016-09-01T01:34:28
|
C
|
UTF-8
|
C
| false
| false
| 13,308
|
c
|
omcalc_ccmW.c
|
#include <stdio.h>
#include <math.h>
#include "wrapper.h"
extern void NGCALLF(omcalcccm,OMCALCCCM)(double *u, double *v,
double *d, double *dpsl,
double *dpsm, double *pmid,
double *pdel, double *psfc,
double *hybd, double *hybm,
int *nprlev, double *omega,
int *ilon, int *jlat, int *klev);
NhlErrorTypes omega_ccm_W( void )
{
/*
* Input array variables
*/
void *u, *v, *div, *dpsl, *dpsm, *pmid, *pdel, *psfc, *hybd, *hybm;
int *nprlev;
double *tmp_u, *tmp_v, *tmp_div, *tmp_dpsl, *tmp_dpsm;
double *tmp_pmid, *tmp_pdel, *tmp_psfc, *tmp_hybd, *tmp_hybm;
int ndims_u, ndims_v, ndims_div, ndims_dpsl, ndims_dpsm;
int ndims_pmid, ndims_pdel, ndims_psfc, ndims_hybd, ndims_hybm;
ng_size_t dsizes_u[NCL_MAX_DIMENSIONS], dsizes_v[NCL_MAX_DIMENSIONS];
ng_size_t dsizes_div[NCL_MAX_DIMENSIONS], dsizes_dpsl[NCL_MAX_DIMENSIONS];
ng_size_t dsizes_dpsm[NCL_MAX_DIMENSIONS], dsizes_pmid[NCL_MAX_DIMENSIONS];
ng_size_t dsizes_pdel[NCL_MAX_DIMENSIONS], dsizes_psfc[NCL_MAX_DIMENSIONS];
ng_size_t dsizes_hybd[1], dsizes_hybm[1];
NclBasicDataTypes type_u, type_v, type_div, type_dpsl, type_dpsm;
NclBasicDataTypes type_pmid, type_pdel, type_psfc, type_hybd, type_hybm;
/*
* Output array variables
*/
void *omega;
double *tmp_omega;
NclBasicDataTypes type_omega;
/*
* Declare various variables for random purposes.
*/
ng_size_t i, nt, nlat, nlon, nlev, ntim, nlatlon, nlevlatlon, size_omega;
ng_size_t index_u, index_psfc;
int inlon, inlat, inlev;
/*
* Retrieve parameters
*
* Note that any of the pointer parameters can be set to NULL,
* which implies you don't care about its value.
*
*/
u = (void*)NclGetArgValue(
0,
11,
&ndims_u,
dsizes_u,
NULL,
NULL,
&type_u,
DONT_CARE);
v = (void*)NclGetArgValue(
1,
11,
&ndims_v,
dsizes_v,
NULL,
NULL,
&type_v,
DONT_CARE);
div = (void*)NclGetArgValue(
2,
11,
&ndims_div,
dsizes_div,
NULL,
NULL,
&type_div,
DONT_CARE);
dpsl = (void*)NclGetArgValue(
3,
11,
&ndims_dpsl,
dsizes_dpsl,
NULL,
NULL,
&type_dpsl,
DONT_CARE);
dpsm = (void*)NclGetArgValue(
4,
11,
&ndims_dpsm,
dsizes_dpsm,
NULL,
NULL,
&type_dpsm,
DONT_CARE);
pmid = (void*)NclGetArgValue(
5,
11,
&ndims_pmid,
dsizes_pmid,
NULL,
NULL,
&type_pmid,
DONT_CARE);
pdel = (void*)NclGetArgValue(
6,
11,
&ndims_pdel,
dsizes_pdel,
NULL,
NULL,
&type_pdel,
DONT_CARE);
psfc = (void*)NclGetArgValue(
7,
11,
&ndims_psfc,
dsizes_psfc,
NULL,
NULL,
&type_psfc,
DONT_CARE);
hybd = (void*)NclGetArgValue(
8,
11,
&ndims_hybd,
dsizes_hybd,
NULL,
NULL,
&type_hybd,
DONT_CARE);
hybm = (void*)NclGetArgValue(
9,
11,
&ndims_hybm,
dsizes_hybm,
NULL,
NULL,
&type_hybm,
DONT_CARE);
nprlev = (int*)NclGetArgValue(
10,
11,
NULL,
NULL,
NULL,
NULL,
NULL,
DONT_CARE);
/*
* Check the input dimension sizes.
*/
if(ndims_u != 3 && ndims_u != 4) {
NhlPError(NhlFATAL,NhlEUNKNOWN,"omega_ccm: 'u' must be a 3 or 4 dimensional array");
return(NhlFATAL);
}
if(ndims_v != 3 && ndims_v != 4) {
NhlPError(NhlFATAL,NhlEUNKNOWN,"omega_ccm: 'v' must be a 3 or 4 dimensional array");
return(NhlFATAL);
}
if(ndims_div != 3 && ndims_div != 4) {
NhlPError(NhlFATAL,NhlEUNKNOWN,"omega_ccm: 'div' must be a 3 or 4 dimensional array");
return(NhlFATAL);
}
if(ndims_pmid != 3 && ndims_pmid != 4) {
NhlPError(NhlFATAL,NhlEUNKNOWN,"omega_ccm: 'pmid' must be a 3 or 4 dimensional array");
return(NhlFATAL);
}
if(ndims_pdel != 3 && ndims_pdel != 4) {
NhlPError(NhlFATAL,NhlEUNKNOWN,"omega_ccm: 'pdel' must be a 3 or 4 dimensional array");
return(NhlFATAL);
}
/*
* Now check that the dimension sizes are equal to each other.
*/
if(ndims_u != ndims_v || ndims_u != ndims_div ||
ndims_u != ndims_pmid || ndims_u != ndims_pdel) {
NhlPError(NhlFATAL,NhlEUNKNOWN,"omega_ccm: the first seven input variables must be the same dimensionality");
return(NhlFATAL);
}
for(i = 0; i < ndims_u; i++) {
if(dsizes_u[i] != dsizes_v[i] || dsizes_u[i] != dsizes_div[i] ||
dsizes_u[i] != dsizes_pmid[i] || dsizes_u[i] != dsizes_pdel[i]) {
NhlPError(NhlFATAL,NhlEUNKNOWN,"omega_ccm: u, v, div, pmid, and pdel must be the same dimensionality");
return(NhlFATAL);
}
}
nlev = dsizes_u[ndims_u-3];
nlat = dsizes_u[ndims_u-2];
nlon = dsizes_u[ndims_u-1];
if(ndims_u == 4) {
ntim = dsizes_u[ndims_u-4];
}
else {
ntim = 1;
}
/*
* Test input dimension sizes.
*/
if((nlon > INT_MAX) || (nlat > INT_MAX) || (nlev > INT_MAX)) {
NhlPError(NhlFATAL,NhlEUNKNOWN,"omega_ccm: one or more input dimension sizes is greater than INT_MAX");
return(NhlFATAL);
}
inlon = (int) nlon;
inlat = (int) nlat;
inlev = (int) nlev;
/*
* Test the sizes of 'dpsl', 'dpsm', and 'psfc' which should be one
* dimension smaller than the others.
*/
if(ndims_u == 3 && ndims_dpsl != 2) {
NhlPError(NhlFATAL,NhlEUNKNOWN,"omega_ccm: 'dpsl' must be a 2 dimensional array if the other input arguments are 3 dimensional");
return(NhlFATAL);
}
if(ndims_u == 4 && ndims_dpsl != 3) {
NhlPError(NhlFATAL,NhlEUNKNOWN,"omega_ccm: 'dpsl' must be a 3 dimensional array if the other input arguments are 4 dimensional");
return(NhlFATAL);
}
if(ndims_u == 3 && ndims_dpsm != 2) {
NhlPError(NhlFATAL,NhlEUNKNOWN,"omega_ccm: 'dpsm' must be a 2 dimensional array if the other input arguments are 3 dimensional");
return(NhlFATAL);
}
if(ndims_u == 4 && ndims_dpsm != 3) {
NhlPError(NhlFATAL,NhlEUNKNOWN,"omega_ccm: 'dpsm' must be a 3 dimensional array if the other input arguments are 4 dimensional");
return(NhlFATAL);
}
if(ndims_u == 3 && ndims_psfc != 2) {
NhlPError(NhlFATAL,NhlEUNKNOWN,"omega_ccm: 'psfc' must be a 2 dimensional array if the other input arguments are 3 dimensional");
return(NhlFATAL);
}
if(ndims_u == 4 && ndims_psfc != 3) {
NhlPError(NhlFATAL,NhlEUNKNOWN,"omega_ccm: 'psfc' must be a 3 dimensional array if the other input arguments are 4 dimensional");
return(NhlFATAL);
}
/*
* Make sure dpsl, dpsm, and psfc are the correct dimension sizes,
* depending on whether they are 2D or 3D.
*/
if(ndims_dpsl == 2) {
if(dsizes_dpsl[0] != nlat || dsizes_dpsl[1] != nlon) {
NhlPError(NhlFATAL,NhlEUNKNOWN,"omega_ccm: 'dpsl' must be dimensioned time x lat x lon or lat x lon");
return(NhlFATAL);
}
if(dsizes_dpsm[0] != nlat || dsizes_dpsm[1] != nlon) {
NhlPError(NhlFATAL,NhlEUNKNOWN,"omega_ccm: 'dpsm' must be dimensioned time x lat x lon or lat x lon");
return(NhlFATAL);
}
if(dsizes_psfc[0] != nlat || dsizes_psfc[1] != nlon) {
NhlPError(NhlFATAL,NhlEUNKNOWN,"omega_ccm: 'psfc' must be dimensioned time x lat x lon or lat x lon");
return(NhlFATAL);
}
}
else {
if(dsizes_dpsl[0] != ntim || dsizes_dpsl[1] != nlat ||
dsizes_dpsl[2] != nlon) {
NhlPError(NhlFATAL,NhlEUNKNOWN,"omega_ccm: 'dpsl' must be dimensioned time x lat x lon or lat x lon");
return(NhlFATAL);
}
if(dsizes_dpsm[0] != ntim || dsizes_dpsm[1] != nlat ||
dsizes_dpsm[2] != nlon) {
NhlPError(NhlFATAL,NhlEUNKNOWN,"omega_ccm: 'dpsm' must be dimensioned time x lat x lon or lat x lon");
return(NhlFATAL);
}
if(dsizes_psfc[0] != ntim || dsizes_psfc[1] != nlat ||
dsizes_psfc[2] != nlon) {
NhlPError(NhlFATAL,NhlEUNKNOWN,"omega_ccm: 'psfc' must be dimensioned time x lat x lon or lat x lon");
return(NhlFATAL);
}
}
/*
* Test the sizes of 'hybd' and 'hybm', which must be 1D of length nlev.
*/
if(dsizes_hybd[0] != nlev || dsizes_hybm[0] != nlev) {
NhlPError(NhlFATAL,NhlEUNKNOWN,"omega_ccm: 'hybd' and 'hybm' must be of length 'nlev'");
return(NhlFATAL);
}
/*
* Make sure nprlev is greater than 0.
*/
if(*nprlev < 0) {
NhlPError(NhlFATAL,NhlEUNKNOWN,"omega_ccm: 'nprlev' must be greater than zero");
return(NhlFATAL);
}
/*
* Coerce (first subset) of input to double, if necessary.
*/
nlatlon = nlat * nlon;
nlevlatlon = nlatlon * nlev;
tmp_u = coerce_input_double(u,type_u,nlevlatlon,0,NULL,NULL);
tmp_v = coerce_input_double(v,type_v,nlevlatlon,0,NULL,NULL);
tmp_div = coerce_input_double(div,type_div,nlevlatlon,0,NULL,NULL);
tmp_pmid = coerce_input_double(pmid,type_pmid,nlevlatlon,0,NULL,NULL);
tmp_pdel = coerce_input_double(pdel,type_pdel,nlevlatlon,0,NULL,NULL);
tmp_dpsl = coerce_input_double(dpsl,type_dpsl,nlatlon,0,NULL,NULL);
tmp_dpsm = coerce_input_double(dpsm,type_dpsm,nlatlon,0,NULL,NULL);
tmp_psfc = coerce_input_double(psfc,type_psfc,nlatlon,0,NULL,NULL);
tmp_hybd = coerce_input_double(hybd,type_hybd,nlev,0,NULL,NULL);
tmp_hybm = coerce_input_double(hybm,type_hybm,nlev,0,NULL,NULL);
if( tmp_u == NULL || tmp_v == NULL || tmp_div == NULL ||
tmp_dpsl == NULL || tmp_dpsm == NULL || tmp_pmid == NULL ||
tmp_pdel == NULL || tmp_psfc == NULL || tmp_hybd == NULL ||
tmp_hybm == NULL) {
NhlPError(NhlFATAL,NhlEUNKNOWN,"omega_ccm: Unable to coerce input variables to double precision");
return(NhlFATAL);
}
/*
* Allocate space for output array.
*
* Also, set size for output array (omega).
*/
size_omega = nlevlatlon * ntim;
if(type_u == NCL_double || type_v == NCL_double) {
type_omega = NCL_double;
omega = (void*)calloc(size_omega,sizeof(double));
}
else {
type_omega = NCL_float;
omega = (void*)calloc(size_omega,sizeof(float));
}
tmp_omega = coerce_output_double(omega,type_omega,nlevlatlon);
if(omega == NULL || tmp_omega == NULL) {
NhlPError(NhlFATAL,NhlEUNKNOWN,"omega_ccm: Unable to allocate memory for output variable");
return(NhlFATAL);
}
/*
* Call the Fortran routine.
*/
index_u = index_psfc = 0;
for(nt = 0; nt < ntim; nt++) {
/*
* The first timestep has already been coerced, so skip it.
*/
if(nt > 0) {
coerce_subset_input_double(u,tmp_u,index_u,type_u,
nlevlatlon,0,NULL,NULL);
coerce_subset_input_double(v,tmp_v,index_u,type_v,
nlevlatlon,0,NULL,NULL);
coerce_subset_input_double(div,tmp_div,index_u,type_div,
nlevlatlon,0,NULL,NULL);
coerce_subset_input_double(pmid,tmp_pmid,index_u,type_pmid,
nlevlatlon,0,NULL,NULL);
coerce_subset_input_double(pdel,tmp_pdel,index_u,type_pdel,
nlevlatlon,0,NULL,NULL);
coerce_subset_input_double(dpsl,tmp_dpsl,index_psfc,type_dpsl,
nlatlon,0,NULL,NULL);
coerce_subset_input_double(dpsm,tmp_dpsm,index_psfc,type_dpsm,
nlatlon,0,NULL,NULL);
coerce_subset_input_double(psfc,tmp_psfc,index_psfc,type_psfc,
nlatlon,0,NULL,NULL);
}
if(type_omega == NCL_double) {
/*
* Point tmp_omega to appropriate location in omega
*/
tmp_omega = &((double*)omega)[index_u];
}
NGCALLF(omcalcccm,OMCALCCCM)(tmp_u, tmp_v, tmp_div, tmp_dpsl, tmp_dpsm,
tmp_pmid, tmp_pdel, tmp_psfc, tmp_hybd,
tmp_hybm, nprlev, tmp_omega, &inlon, &inlat,
&inlev);
/*
* If the output is to be float, then do the coercion here.
*/
if(type_omega == NCL_float) {
coerce_output_float_only(omega,tmp_omega,nlevlatlon,index_u);
}
/*
* Implement the pointers into the arrays.
*/
index_u += nlevlatlon;
index_psfc += nlatlon;
}
/*
* Free memory.
*/
if(type_u != NCL_double) NclFree(tmp_u);
if(type_v != NCL_double) NclFree(tmp_v);
if(type_div != NCL_double) NclFree(tmp_div);
if(type_dpsl != NCL_double) NclFree(tmp_dpsl);
if(type_dpsm != NCL_double) NclFree(tmp_dpsm);
if(type_pmid != NCL_double) NclFree(tmp_pmid);
if(type_pdel != NCL_double) NclFree(tmp_pdel);
if(type_psfc != NCL_double) NclFree(tmp_psfc);
if(type_hybd != NCL_double) NclFree(tmp_hybd);
if(type_hybm != NCL_double) NclFree(tmp_hybm);
if(type_omega != NCL_double) NclFree(tmp_omega);
/*
* Set up variable to return.
*/
return(NclReturnValue(omega,ndims_u,dsizes_u,NULL,type_omega,0));
}
|
b0bbb9ae7b3e0817c2bf9327fa9bd9581a5b0078
|
07aeb5740a8dae36edf24e2686ff67e2959758fe
|
/programs/subprojects/doom/net_packet.h
|
ced4e43588537d2e2d53c655eec00d6fcfd14d04
|
[
"MIT"
] |
permissive
|
codyd51/axle
|
59e992987bb871296aeadc69fc7244798090f3b1
|
96ae8852f15ad5c0a77c621c323ba47b4a7bdc69
|
refs/heads/paging-demo
| 2023-06-08T11:31:19.429032
| 2023-05-30T06:45:30
| 2023-05-30T06:45:30
| 58,590,685
| 597
| 61
|
MIT
| 2023-02-21T06:02:34
| 2016-05-11T23:41:08
|
C
|
UTF-8
|
C
| false
| false
| 1,527
|
h
|
net_packet.h
|
//
// Copyright(C) 2005-2014 Simon Howard
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// DESCRIPTION:
// Definitions for use in networking code.
//
#ifndef NET_PACKET_H
#define NET_PACKET_H
#include "net_defs.h"
net_packet_t *NET_NewPacket(int initial_size);
net_packet_t *NET_PacketDup(net_packet_t *packet);
void NET_FreePacket(net_packet_t *packet);
boolean NET_ReadInt8(net_packet_t *packet, unsigned int *data);
boolean NET_ReadInt16(net_packet_t *packet, unsigned int *data);
boolean NET_ReadInt32(net_packet_t *packet, unsigned int *data);
boolean NET_ReadSInt8(net_packet_t *packet, signed int *data);
boolean NET_ReadSInt16(net_packet_t *packet, signed int *data);
boolean NET_ReadSInt32(net_packet_t *packet, signed int *data);
char *NET_ReadString(net_packet_t *packet);
void NET_WriteInt8(net_packet_t *packet, unsigned int i);
void NET_WriteInt16(net_packet_t *packet, unsigned int i);
void NET_WriteInt32(net_packet_t *packet, unsigned int i);
void NET_WriteString(net_packet_t *packet, char *string);
#endif /* #ifndef NET_PACKET_H */
|
d6d9bff2cfc116c948e14730f580a31d2d1d2932
|
28d0f8c01599f8f6c711bdde0b59f9c2cd221203
|
/sys/dev/i2c/lm_i2c.c
|
dbbe0a7e77ed3d561a181589e21be5a4295bdfd0
|
[] |
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,134
|
c
|
lm_i2c.c
|
/* $NetBSD: lm_i2c.c,v 1.7 2021/06/13 09:48:44 mlelstv Exp $ */
/*-
* Copyright (c) 2000 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Bill Squier.
*
* 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 <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: lm_i2c.c,v 1.7 2021/06/13 09:48:44 mlelstv Exp $");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/device.h>
#include <sys/conf.h>
#include <sys/kmem.h>
#include <dev/i2c/i2cvar.h>
#include <dev/sysmon/sysmonvar.h>
#include <dev/ic/nslm7xvar.h>
int lm_i2c_match(device_t, cfdata_t, void *);
void lm_i2c_attach(device_t, device_t, void *);
int lm_i2c_detach(device_t, int);
uint8_t lm_i2c_readreg(struct lm_softc *, int);
void lm_i2c_writereg(struct lm_softc *, int, uint8_t);
struct lm_i2c_softc {
struct lm_softc sc_lmsc;
i2c_tag_t sc_tag;
i2c_addr_t sc_addr;
};
CFATTACH_DECL_NEW(lm_iic, sizeof(struct lm_i2c_softc),
lm_i2c_match, lm_i2c_attach, lm_i2c_detach, NULL);
int
lm_i2c_match(device_t parent, cfdata_t match, void *aux)
{
struct i2c_attach_args *ia = aux;
int rv = 0;
struct lm_i2c_softc *sc;
/* Must supply an address */
if (ia->ia_addr < 1)
return 0;
/* XXXJRT filter addresses //at all// please? */
/* Bus independent probe */
sc = kmem_zalloc(sizeof(*sc), KM_SLEEP);
sc->sc_lmsc.lm_writereg = lm_i2c_writereg;
sc->sc_lmsc.lm_readreg = lm_i2c_readreg;
sc->sc_tag = ia->ia_tag;
sc->sc_addr = ia->ia_addr;
rv = lm_match(&sc->sc_lmsc);
kmem_free(sc, sizeof(*sc));
return rv ? I2C_MATCH_ADDRESS_AND_PROBE : 0;
}
void
lm_i2c_attach(device_t parent, device_t self, void *aux)
{
struct lm_i2c_softc *sc = device_private(self);
struct i2c_attach_args *ia = aux;
sc->sc_tag = ia->ia_tag;
sc->sc_addr = ia->ia_addr;
/* Bus-independent attachment */
sc->sc_lmsc.sc_dev = self;
sc->sc_lmsc.lm_writereg = lm_i2c_writereg;
sc->sc_lmsc.lm_readreg = lm_i2c_readreg;
lm_attach(&sc->sc_lmsc);
}
int
lm_i2c_detach(device_t self, int flags)
{
struct lm_i2c_softc *sc = device_private(self);
lm_detach(&sc->sc_lmsc);
return 0;
}
uint8_t
lm_i2c_readreg(struct lm_softc *lmsc, int reg)
{
struct lm_i2c_softc *sc = (struct lm_i2c_softc *)lmsc;
uint8_t cmd, data;
if (iic_acquire_bus(sc->sc_tag, 0))
return 0;
cmd = reg;
iic_exec(sc->sc_tag, I2C_OP_READ_WITH_STOP,
sc->sc_addr, &cmd, sizeof cmd, &data, sizeof data, 0);
iic_release_bus(sc->sc_tag, 0);
return data;
}
void
lm_i2c_writereg(struct lm_softc *lmsc, int reg, uint8_t val)
{
struct lm_i2c_softc *sc = (struct lm_i2c_softc *)lmsc;
uint8_t cmd, data;
if (iic_acquire_bus(sc->sc_tag, 0))
return;
cmd = reg;
data = val;
iic_exec(sc->sc_tag, I2C_OP_WRITE_WITH_STOP,
sc->sc_addr, &cmd, sizeof cmd, &data, sizeof data, 0);
iic_release_bus(sc->sc_tag, 0);
}
|
a93fedcdd5d69c3ce0b282bff6930759cf38388c
|
8838eb997879add5759b6dfb23f9a646464e53ca
|
/src/drivers/clock/riscv_clk/riscv_clk.c
|
2a7c48bc7d47406119f9530c7c36a09e22a2df6d
|
[
"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
| 1,169
|
c
|
riscv_clk.c
|
/**
* @file
*
* @brief RISC-V build-in timer
*
* @date 12.12.2019
* @author Anastasia Nizharadze
*/
#include <errno.h>
#include <asm/regs.h>
#include <asm/interrupts.h>
#include <hal/clock.h>
#include <hal/system.h>
#include <hal/reg.h>
#include <kernel/irq.h>
#include <kernel/time/clock_source.h>
#include <embox/unit.h>
#define HZ 1000
#define COUNT_OFFSET (RTC_CLOCK / HZ)
#define RTC_CLOCK OPTION_GET(NUMBER, rtc_freq)
#define MTIME OPTION_GET(NUMBER, base_mtime)
#define MTIMECMP OPTION_GET(NUMBER, base_mtimecmp)
static int clock_handler(unsigned int irq_nr, void *dev_id) {
REG64_STORE(MTIMECMP, REG64_LOAD(MTIME) + COUNT_OFFSET);
clock_tick_handler(dev_id);
return IRQ_HANDLED;
}
static int riscv_clock_setup(struct clock_source *cs) {
REG64_STORE(MTIMECMP, REG64_LOAD(MTIME) + COUNT_OFFSET);
enable_timer_interrupts();
return ENOERR;
}
static struct time_event_device riscv_event_device = {
.set_periodic = riscv_clock_setup,
.name = "riscv_clk",
.irq_nr = IRQ_MACHINE_TIMER
};
CLOCK_SOURCE_DEF(riscv_clk, NULL, NULL,
&riscv_event_device, NULL);
RISCV_TIMER_IRQ_DEF(clock_handler, &CLOCK_SOURCE_NAME(riscv_clk));
|
ff83305ead79de75569c9acc29a30afaf0e20ff3
|
33bbf5ec9c25a08cdc2ea9b404fef066f48b91e6
|
/i18n/vi/dictionary.h
|
02bfd425e4c11a9b21d48fd2068dc61bfe0d5937
|
[
"BSD-2-Clause"
] |
permissive
|
gabordemooij/citrine
|
2cf1102851461b273158e6731a68e35fe7123c88
|
135beb4c417e006028b3affb264c1bd554ae28f1
|
refs/heads/master
| 2023-08-28T01:10:20.952764
| 2023-07-08T10:02:04
| 2023-07-08T10:02:04
| 23,259,816
| 110
| 23
|
BSD-2-Clause
| 2023-07-08T10:02:08
| 2014-08-23T15:55:48
|
C
|
UTF-8
|
C
| false
| false
| 9,882
|
h
|
dictionary.h
|
#define CTR_DICT_CODEGEN_MAP_NEW "(Sách mới) "
#define CTR_DICT_CODEGEN_MAP_PUT "đặt:"
#define CTR_DICT_CODEGEN_MAP_PUT_AT " tại:"
#define CTR_DICT_CODEGEN_ARRAY_NEW "Loạt mới "
#define CTR_DICT_CODEGEN_ARRAY_NEW_PUSH "Loạt ← "
#define CTR_DICT_END_OF_LINE "."
#define CTR_DICT_NIL "Không"
#define CTR_DICT_BOOLEAN "Boolean"
#define CTR_DICT_TRUE "Thật"
#define CTR_DICT_FALSE "Sai"
#define CTR_DICT_NUMBER "Con số"
#define CTR_DICT_STRING "Văn bản"
#define CTR_DICT_TASK "Mã"
#define CTR_DICT_OBJECT "Vật"
#define CTR_DICT_ARRAY_OBJECT "Loạt"
#define CTR_DICT_MAP_OBJECT "Sách"
#define CTR_DICT_PROGRAM "Chương trình"
#define CTR_DICT_FILE "Tập tin"
#define CTR_DICT_MOMENT "Chốc lát"
#define CTR_DICT_VAR_ICON "☞"
#define CTR_DICT_ME_ICON "⛏"
#define CTR_DICT_MY_ICON "⚿"
#define CTR_DICT_BULLET "•"
#define CTR_DICT_SYMBOL_EQUALS "="
#define CTR_DICT_PLUS "+"
#define CTR_DICT_MINUS "-"
#define CTR_DICT_MULTIPLIER "×"
#define CTR_DICT_DIVISION "÷"
#define CTR_DICT_GREATER ">"
#define CTR_DICT_LESS "<"
#define CTR_DICT_AT_SYMBOL "?"
#define CTR_DICT_PEN_ICON "✎"
#define CTR_DICT_NEW_ARRAY_AND_PUSH_SYMBOL "←"
#define CTR_DICT_GREATER_OR_EQUAL_SYMBOL "≥"
#define CTR_DICT_LESS_OR_EQUAL_SYMBOL "≤"
#define CTR_DICT_UNEQUALS_SYMBOL "≠"
#define CTR_DICT_NEW "mới"
#define CTR_DICT_EQUALS "bằng:"
#define CTR_DICT_AND "và:"
#define CTR_DICT_OR "hoặc là:"
#define CTR_DICT_MODULO "modulo:"
#define CTR_DICT_NOR "cũng không:"
#define CTR_DICT_ONDO "trên:làm:"
#define CTR_DICT_TYPE "kiểu"
#define CTR_DICT_ISNIL "không?"
#define CTR_DICT_MYSELF "riêng tôi"
#define CTR_DICT_DO "làm"
#define CTR_DICT_DONE "làm xong"
#define CTR_DICT_IFFALSE "sai:"
#define CTR_DICT_IFTRUE "thật:"
#define CTR_DICT_WHILE "trong khi:"
#define CTR_DICT_MESSAGEARGS "tin nhắn:đối số:"
#define CTR_DICT_MESSAGE "thông điệp:"
#define CTR_DICT_LEARN "học:có nghĩa là:"
#define CTR_DICT_BREAK "phá vỡ"
#define CTR_DICT_CONTINUE "tiếp tục"
#define CTR_DICT_ELSE "khác:"
#define CTR_DICT_NOT "không phải"
#define CTR_DICT_TONUMBER "con số"
#define CTR_DICT_ITONUMBER "số quốc tế"
#define CTR_DICT_TOSTRING "văn bản"
#define CTR_DICT_CHAR_AT_SET "tính cách:"
#define CTR_DICT_EITHEROR "hoặc:hoặc:"
#define CTR_DICT_BY_SET "bởi:"
#define CTR_DICT_FLOOR "làm tròn xuống"
#define CTR_DICT_CEIL "làm tròn trở lên"
#define CTR_DICT_ROUND "làm tròn"
#define CTR_DICT_ABS "tuyệt đối"
#define CTR_DICT_SQRT "căn bậc hai"
#define CTR_DICT_POWER "quyền lực:"
#define CTR_DICT_MIN "tối thiểu"
#define CTR_DICT_MAX "tối đa"
#define CTR_DICT_ODD "số lẻ?"
#define CTR_DICT_EVEN "số chẵn?"
#define CTR_DICT_POS "tích cực?"
#define CTR_DICT_NEG "tiêu cực?"
#define CTR_DICT_TOBOOL "boolean"
#define CTR_DICT_RANDOM_NUM_BETWEEN "giữa:và:"
#define CTR_DICT_LENGTH "chiều dài"
#define CTR_DICT_FROM_LENGTH "từ:chiều dài:"
#define CTR_DICT_TRIM "loại bỏ không gian xung quanh"
#define CTR_DICT_AT "tại:"
#define CTR_DICT_POSITION_SET "chức vụ:"
#define CTR_DICT_INDEX_OF "tìm thấy:"
#define CTR_DICT_LAST_INDEX_OF "cuối cùng:"
#define CTR_DICT_REPLACE_WITH "thay:thế bằng:"
#define CTR_DICT_SPLIT "chia nhỏ:"
#define CTR_DICT_SKIP "bù lại:"
#define CTR_DICT_RUN "Bắt đầu"
#define CTR_DICT_APPLY_TO "ứng dụng:"
#define CTR_DICT_APPLY_TO_AND "áp dụng:và:"
#define CTR_DICT_VALUE_SET "đặt:giá trị:"
#define CTR_DICT_ERROR "lỗi:"
#define CTR_DICT_CATCH "nắm lấy:"
#define CTR_DICT_PUSH_SYMBOL ";"
#define CTR_DICT_SHIFT "lấy phần tử đầu tiên"
#define CTR_DICT_COUNT "đếm"
#define CTR_DICT_JOIN "tham gia:"
#define CTR_DICT_POP "lấy phần tử cuối cùng"
#define CTR_DICT_SORT "sắp xếp:"
#define CTR_DICT_PUT_AT "đặt:tại:"
#define CTR_DICT_MAP "sách:"
#define CTR_DICT_EACH "mỗi:"
#define CTR_DICT_WRITE "viết:"
#define CTR_DICT_PATH "con đường"
#define CTR_DICT_READ "đọc"
#define CTR_DICT_APPEND "nối thêm:"
#define CTR_DICT_PREPEND "trả trước:"
#define CTR_DICT_EXISTS "tồn tại"
#define CTR_DICT_SIZE "kích thước"
#define CTR_DICT_DELETE "xóa bỏ"
#define CTR_DICT_USE_SET "sử dụng:"
#define CTR_DICT_ARRAY "loạt:"
#define CTR_DICT_END "kết thúc"
#define CTR_DICT_ARGUMENT "tranh luận:"
#define CTR_DICT_ARGUMENT_COUNT "tranh luận"
#define CTR_DICT_WAIT_FOR_PASSW "hỏi mật khẩu"
#define CTR_DICT_WAIT_FOR_INPUT "hỏi"
#define CTR_DICT_INPUT "đầu vào"
#define CTR_DICT_FLUSH "tuôn ra"
#define CTR_DICT_WAIT "chờ đợi:"
#define CTR_DICT_TIME "thời gian"
#define CTR_DICT_RESPOND_TO "trả lời:"
#define CTR_DICT_RESPOND_TO_AND "trả lời:và:"
#define CTR_DICT_SHELL "lệnh hệ thống:"
#define CTR_DICT_SWEEP "làm sạch bộ nhớ"
#define CTR_DICT_MEMORY_LIMIT "ký ức:"
#define CTR_DICT_MEMORY "ký ức"
#define CTR_DICT_GC_MODE "gọn gàng:"
#define CTR_DICT_HASH_WITH_KEY "băm:"
#define CTR_DICT_CHARACTERS "nhân vật"
#define CTR_DICT_QUALIFIER_SET "đủ điều kiện:"
#define CTR_DICT_QUALIFIER "trình độ chuyên môn"
#define CTR_DICT_NEW_SET "mới:"
#define CTR_DICT_HOUR "giờ"
#define CTR_DICT_HOUR_SET "giờ:"
#define CTR_DICT_MINUTE_SET "phút:"
#define CTR_DICT_MINUTE "phút"
#define CTR_DICT_SECOND_SET "thứ hai:"
#define CTR_DICT_SECOND "thứ hai"
#define CTR_DICT_DAY "ngày"
#define CTR_DICT_DAY_SET "ngày:"
#define CTR_DICT_WEEK "tuần"
#define CTR_DICT_WEEK_SET "tuần:"
#define CTR_DICT_MONTH "tháng"
#define CTR_DICT_MONTH_SET "tháng:"
#define CTR_DICT_YEAR "năm"
#define CTR_DICT_RAW "nguyên"
#define CTR_DICT_YEAR_SET "năm:"
#define CTR_DICT_WEEK_DAY "các ngày trong tuần"
#define CTR_DICT_YEAR_DAY "ngày trong năm"
#define CTR_DICT_ZONE "vùng"
#define CTR_DICT_ZONE_SET "vùng:"
#define CTR_DICT_ADD_SET "thêm vào:"
#define CTR_DICT_SUBTRACT_SET "trừ:"
#define CTR_DICT_MULTIPLIER_SET "nhân với:"
#define CTR_DICT_DIVIDER_SET "chia cho:"
#define CTR_DICT_LAST "cuối cùng"
#define CTR_DICT_FIRST "Đầu tiên"
#define CTR_DICT_SECOND_LAST "thứ hai cuối cùng"
#define CTR_DICT_FILL_WITH "điền:với:"
#define CTR_DICT_SPLICE "thay thế:chiều dài:bằng:"
#define CTR_DICT_VALUES "giá trị"
#define CTR_DICT_ENTRIES "mục"
#define CTR_DICT_COMPARE_SET "đối chiếu:"
#define CTR_DICT_HAS "có:"
#define CTR_DICT_COPY "bản sao"
#define CTR_DICT_CASE_DO "trường hợp:làm:"
#define CTR_DICT_STOP "dừng lại"
#define CTR_DICT_ASCII_UPPER_CASE "chữ hoa"
#define CTR_DICT_ASCII_LOWER_CASE "chữ thường"
#define CTR_DICT_CONTAINS "chứa đựng:"
#define CTR_DICT_APPLY_TO_AND_AND "áp dụng:và:và:"
#define CTR_DICT_ENVIRONMENT_VARIABLE "cài đặt:"
#define CTR_DICT_SET_ENVIRONMENT_VARIABLE "cài đặt:là:"
#define CTR_DICT_RESPOND_TO_AND_AND "trả lời:và:và:"
#define CTR_DICT_RESPOND_TO_AND_AND_AND "trả lời:và:và:và:"
#define CTR_DICT_CURRENT_TASK "khối mã này"
#define CTR_DICT_NUM_DEC_SEP ","
#define CTR_DICT_NUM_THO_SEP "."
#define CTR_DICT_QUOT_OPEN "‘"
#define CTR_DICT_QUOT_CLOSE "’"
#define CTR_DICT_MESSAGE_CHAIN ","
#define CTR_DICT_ASSIGN "≔"
#define CTR_DICT_PAREN_OPEN "("
#define CTR_DICT_PAREN_CLOSE ")"
#define CTR_DICT_BLOCK_START "{"
#define CTR_DICT_BLOCK_END "}"
#define CTR_DICT_PARAMETER_PREFIX ":"
#define CTR_DICT_RETURN "↲"
#define CTR_DICT_CODE "viết"
#define CTR_DICT_PROCEDURE "thủ tục"
#define CTR_DICT_TOOBJECT "vật"
#define CTR_DICT_PATH_OBJECT "Địa điểm"
#define CTR_DICT_CMD_OBJECT "Hướng dẫn"
#define CTR_DICT_RECURSIVE "đệ quy"
|
e46e0329d21ec6d0c2a9cb370f40010dec0ade27
|
ef3f32be7b34d7f3cbb166cd3f66200ef33f4268
|
/src/main/client/admin.c
|
ec6c321eceff8fcb34f5908692a4618267882292
|
[
"Apache-2.0"
] |
permissive
|
aerospike/aerospike-client-python
|
8fa67b82d0d699b5c06e5b408d4b06985e6b3935
|
03853b63b824da488f651e0a375a7ed90730ed8e
|
refs/heads/master
| 2023-08-23T15:39:01.169857
| 2023-08-21T19:12:16
| 2023-08-21T19:12:16
| 21,751,897
| 121
| 106
|
Apache-2.0
| 2023-09-14T21:34:29
| 2014-07-11T21:24:56
|
Python
|
UTF-8
|
C
| false
| false
| 64,904
|
c
|
admin.c
|
/*******************************************************************************
* Copyright 2013-2021 Aerospike, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
#include <Python.h>
#include <stdbool.h>
#include <aerospike/aerospike.h>
#include <aerospike/as_address.h>
#include <aerospike/as_admin.h>
#include <aerospike/as_config.h>
#include <aerospike/as_error.h>
#include <aerospike/as_policy.h>
#include "admin.h"
#include "client.h"
#include "conversions.h"
#include "exceptions.h"
#include "policy.h"
#include "global_hosts.h"
/**
*******************************************************************************************************
* Create a user in the Aerospike DB.
*
* @param self AerospikeClient object
* @param args The args is a tuple object containing an argument
* list passed from Python to a C function
* @param kwds Dictionary of keywords
*
* Returns an integer status. 0(Zero) is success value.
* In case of error,appropriate exceptions will be raised.
*******************************************************************************************************
*/
PyObject *AerospikeClient_Admin_Create_User(AerospikeClient *self,
PyObject *args, PyObject *kwds)
{
// Initialize error
as_error err;
as_error_init(&err);
// Python Function Arguments
PyObject *py_policy = NULL;
PyObject *py_user = NULL;
PyObject *py_password = NULL;
PyObject *py_roles = NULL;
as_policy_admin admin_policy;
as_policy_admin *admin_policy_p = NULL;
// Python Function Keyword Arguments
static char *kwlist[] = {"user", "password", "roles", "policy", NULL};
// Python Function Argument Parsing
if (PyArg_ParseTupleAndKeywords(args, kwds, "OOO|O:admin_create_user",
kwlist, &py_user, &py_password, &py_roles,
&py_policy) == false) {
return NULL;
}
// Aerospike Operation Arguments
int roles_size = 0;
char **roles = NULL;
const char *user, *password;
if (!self || !self->as) {
as_error_update(&err, AEROSPIKE_ERR_PARAM, "Invalid aerospike object");
goto CLEANUP;
}
if (!self->is_conn_16) {
as_error_update(&err, AEROSPIKE_ERR_CLUSTER,
"No connection to aerospike cluster");
goto CLEANUP;
}
// Convert python object to an array of roles
if (PyList_Check(py_roles)) {
roles_size = PyList_Size(py_roles);
roles = alloca(sizeof(char *) * roles_size);
for (int i = 0; i < roles_size; i++) {
roles[i] = cf_malloc(sizeof(char) * AS_ROLE_SIZE);
memset(roles[i], 0, sizeof(char) * AS_ROLE_SIZE);
}
}
else {
as_error_update(&err, AEROSPIKE_ERR_PARAM, "Roles should be a list");
goto CLEANUP;
}
pyobject_to_strArray(&err, py_roles, roles, AS_ROLE_SIZE);
if (err.code != AEROSPIKE_OK) {
goto CLEANUP;
}
// Convert python objects to username and password strings
if (!PyUnicode_Check(py_user)) {
as_error_update(&err, AEROSPIKE_ERR_PARAM,
"Username should be a string");
goto CLEANUP;
}
user = PyUnicode_AsUTF8(py_user);
if (!PyUnicode_Check(py_password)) {
as_error_update(&err, AEROSPIKE_ERR_PARAM,
"Password should be a string");
goto CLEANUP;
}
password = PyUnicode_AsUTF8(py_password);
// Convert python object to policy_admin
pyobject_to_policy_admin(self, &err, py_policy, &admin_policy,
&admin_policy_p, &self->as->config.policies.admin);
if (err.code != AEROSPIKE_OK) {
goto CLEANUP;
}
// Invoke operation
Py_BEGIN_ALLOW_THREADS
aerospike_create_user(self->as, &err, admin_policy_p, user, password,
(const char **)roles, roles_size);
Py_END_ALLOW_THREADS
if (err.code != AEROSPIKE_OK) {
as_error_update(&err, err.code, NULL);
goto CLEANUP;
}
CLEANUP:
for (int i = 0; i < roles_size; i++) {
if (roles[i])
cf_free(roles[i]);
}
if (err.code != AEROSPIKE_OK) {
raise_exception(&err);
return NULL;
}
return PyLong_FromLong(0);
}
/**
*******************************************************************************************************
* Drops a user from the Aerospike DB.
*
* @param self AerospikeClient object
* @param args The args is a tuple object containing an argument
* list passed from Python to a C function
* @param kwds Dictionary of keywords
*
* Returns an integer status. 0(Zero) is success value.
* In case of error,appropriate exceptions will be raised.
*******************************************************************************************************
*/
PyObject *AerospikeClient_Admin_Drop_User(AerospikeClient *self, PyObject *args,
PyObject *kwds)
{
// Initialize error
as_error err;
as_error_init(&err);
// Python Function Arguments
PyObject *py_policy = NULL;
PyObject *py_user = NULL;
as_policy_admin admin_policy;
as_policy_admin *admin_policy_p = NULL;
// Python Function Keyword Arguments
static char *kwlist[] = {"user", "policy", NULL};
// Python Function Argument Parsing
if (PyArg_ParseTupleAndKeywords(args, kwds, "O|O:admin_drop_user", kwlist,
&py_user, &py_policy) == false) {
return NULL;
}
if (!self || !self->as) {
as_error_update(&err, AEROSPIKE_ERR_PARAM, "Invalid aerospike object");
goto CLEANUP;
}
if (!self->is_conn_16) {
as_error_update(&err, AEROSPIKE_ERR_CLUSTER,
"No connection to aerospike cluster");
goto CLEANUP;
}
// Aerospike Operation Arguments
const char *user;
// Convert python object to policy_admin
pyobject_to_policy_admin(self, &err, py_policy, &admin_policy,
&admin_policy_p, &self->as->config.policies.admin);
if (err.code != AEROSPIKE_OK) {
goto CLEANUP;
}
// Convert python object to username string
if (!PyUnicode_Check(py_user)) {
as_error_update(&err, AEROSPIKE_ERR_PARAM,
"Username should be a string");
goto CLEANUP;
}
user = PyUnicode_AsUTF8(py_user);
//Invoke operation
Py_BEGIN_ALLOW_THREADS
aerospike_drop_user(self->as, &err, admin_policy_p, user);
Py_END_ALLOW_THREADS
char *alias_to_search = NULL;
alias_to_search = return_search_string(self->as);
PyObject *py_persistent_item = NULL;
py_persistent_item = PyDict_GetItemString(py_global_hosts, alias_to_search);
if (py_persistent_item) {
PyDict_DelItemString(py_global_hosts, alias_to_search);
AerospikeGlobalHosts_Del(py_persistent_item);
}
PyMem_Free(alias_to_search);
alias_to_search = NULL;
if (err.code != AEROSPIKE_OK) {
as_error_update(&err, err.code, NULL);
goto CLEANUP;
}
CLEANUP:
if (err.code != AEROSPIKE_OK) {
raise_exception(&err);
return NULL;
}
return PyLong_FromLong(0);
}
/**
*******************************************************************************************************
* Sets the password of a particular user in the Aerospike DB.
*
* @param self AerospikeClient object
* @param args The args is a tuple object containing an argument
* list passed from Python to a C function
* @param kwds Dictionary of keywords
*
* Returns an integer status. 0(Zero) is success value.
* In case of error,appropriate exceptions will be raised.
*******************************************************************************************************
*/
PyObject *AerospikeClient_Admin_Set_Password(AerospikeClient *self,
PyObject *args, PyObject *kwds)
{
// Initialize error
as_error err;
as_error_init(&err);
// Python Function Arguments
PyObject *py_policy = NULL;
PyObject *py_user = NULL;
PyObject *py_password = NULL;
as_policy_admin admin_policy;
as_policy_admin *admin_policy_p = NULL;
// Python Function Keyword Arguments
static char *kwlist[] = {"user", "password", "policy", NULL};
// Python Function Argument Parsing
if (PyArg_ParseTupleAndKeywords(args, kwds, "OO|O:admin_set_password",
kwlist, &py_user, &py_password,
&py_policy) == false) {
return NULL;
}
if (!self || !self->as) {
as_error_update(&err, AEROSPIKE_ERR_PARAM, "Invalid aerospike object");
goto CLEANUP;
}
if (!self->is_conn_16) {
as_error_update(&err, AEROSPIKE_ERR_CLUSTER,
"No connection to aerospike cluster");
goto CLEANUP;
}
// Aerospike Operation Arguments
const char *user, *password;
// Convert python object to policy_admin
pyobject_to_policy_admin(self, &err, py_policy, &admin_policy,
&admin_policy_p, &self->as->config.policies.admin);
if (err.code != AEROSPIKE_OK) {
goto CLEANUP;
}
// Convert python objects into username and password strings
if (!PyUnicode_Check(py_user)) {
as_error_update(&err, AEROSPIKE_ERR_PARAM,
"Username should be a string");
goto CLEANUP;
}
user = PyUnicode_AsUTF8(py_user);
if (!PyUnicode_Check(py_password)) {
as_error_update(&err, AEROSPIKE_ERR_PARAM,
"Password should be a string");
goto CLEANUP;
}
password = PyUnicode_AsUTF8(py_password);
// Invoke operation
Py_BEGIN_ALLOW_THREADS
aerospike_set_password(self->as, &err, admin_policy_p, user, password);
Py_END_ALLOW_THREADS
if (err.code != AEROSPIKE_OK) {
as_error_update(&err, err.code, NULL);
goto CLEANUP;
}
CLEANUP:
if (err.code != AEROSPIKE_OK) {
raise_exception(&err);
return NULL;
}
return PyLong_FromLong(0);
}
/**
*******************************************************************************************************
* Changes the password of a particular user in the Aerospike DB.
*
* @param self AerospikeClient object
* @param args The args is a tuple object containing an argument
* list passed from Python to a C function
* @param kwds Dictionary of keywords
*
* Returns an integer status. 0(Zero) is success value.
* In case of error,appropriate exceptions will be raised.
*******************************************************************************************************
*/
PyObject *AerospikeClient_Admin_Change_Password(AerospikeClient *self,
PyObject *args, PyObject *kwds)
{
// Initialize error
as_error err;
as_error_init(&err);
// Python Function Arguments
PyObject *py_policy = NULL;
PyObject *py_user = NULL;
PyObject *py_password = NULL;
as_policy_admin admin_policy;
as_policy_admin *admin_policy_p = NULL;
// Python Function Keyword Arguments
static char *kwlist[] = {"user", "password", "policy", NULL};
// Python Function Argument Parsing
if (PyArg_ParseTupleAndKeywords(args, kwds, "OO|O:admin_change_password",
kwlist, &py_user, &py_password,
&py_policy) == false) {
return NULL;
}
if (!self || !self->as) {
as_error_update(&err, AEROSPIKE_ERR_PARAM, "Invalid aerospike object");
goto CLEANUP;
}
if (!self->is_conn_16) {
as_error_update(&err, AEROSPIKE_ERR_CLUSTER,
"No connection to aerospike cluster");
goto CLEANUP;
}
// Aerospike Operation Arguments
const char *user, *password;
// Convert python object to policy_admin
pyobject_to_policy_admin(self, &err, py_policy, &admin_policy,
&admin_policy_p, &self->as->config.policies.admin);
if (err.code != AEROSPIKE_OK) {
goto CLEANUP;
}
// Convert python objects into username and password strings
if (!PyUnicode_Check(py_user)) {
as_error_update(&err, AEROSPIKE_ERR_PARAM,
"Username should be a string");
goto CLEANUP;
}
user = PyUnicode_AsUTF8(py_user);
if (!PyUnicode_Check(py_password)) {
as_error_update(&err, AEROSPIKE_ERR_PARAM,
"Password should be a string");
goto CLEANUP;
}
password = PyUnicode_AsUTF8(py_password);
// Invoke operation
Py_BEGIN_ALLOW_THREADS
aerospike_change_password(self->as, &err, admin_policy_p, user, password);
Py_END_ALLOW_THREADS
char *alias_to_search = NULL;
alias_to_search = return_search_string(self->as);
PyObject *py_persistent_item = NULL;
py_persistent_item = PyDict_GetItemString(py_global_hosts, alias_to_search);
if (py_persistent_item) {
PyDict_DelItemString(py_global_hosts, alias_to_search);
AerospikeGlobalHosts_Del(py_persistent_item);
}
PyMem_Free(alias_to_search);
alias_to_search = NULL;
if (err.code != AEROSPIKE_OK) {
as_error_update(&err, err.code, NULL);
goto CLEANUP;
}
CLEANUP:
if (err.code != AEROSPIKE_OK) {
raise_exception(&err);
return NULL;
}
return PyLong_FromLong(0);
}
/**
*******************************************************************************************************
* Grants a role to a user in the Aerospike DB.
*
* @param self AerospikeClient object
* @param args The args is a tuple object containing an argument
* list passed from Python to a C function
* @param kwds Dictionary of keywords
*
* Returns an integer status. 0(Zero) is success value.
* In case of error,appropriate exceptions will be raised.
*******************************************************************************************************
*/
PyObject *AerospikeClient_Admin_Grant_Roles(AerospikeClient *self,
PyObject *args, PyObject *kwds)
{
// Initialize error
as_error err;
as_error_init(&err);
// Python Function Arguments
PyObject *py_policy = NULL;
PyObject *py_user = NULL;
PyObject *py_roles = NULL;
as_policy_admin admin_policy;
as_policy_admin *admin_policy_p = NULL;
// Python Function Keyword Arguments
static char *kwlist[] = {"user", "roles", "policy", NULL};
// Python Function Argument Parsing
if (PyArg_ParseTupleAndKeywords(args, kwds, "OO|O:admin_grant_roles",
kwlist, &py_user, &py_roles,
&py_policy) == false) {
return NULL;
}
// Aerospike Operation Arguments
int roles_size = 0;
char **roles = NULL;
const char *user;
if (!self || !self->as) {
as_error_update(&err, AEROSPIKE_ERR_PARAM, "Invalid aerospike object");
goto CLEANUP;
}
if (!self->is_conn_16) {
as_error_update(&err, AEROSPIKE_ERR_CLUSTER,
"No connection to aerospike cluster");
goto CLEANUP;
}
// Convert python object to array of roles
if (PyList_Check(py_roles)) {
roles_size = PyList_Size(py_roles);
roles = alloca(sizeof(char *) * roles_size);
for (int i = 0; i < roles_size; i++) {
roles[i] = cf_malloc(sizeof(char) * AS_ROLE_SIZE);
memset(roles[i], 0, sizeof(char) * AS_ROLE_SIZE);
}
}
pyobject_to_strArray(&err, py_roles, roles, AS_ROLE_SIZE);
if (err.code != AEROSPIKE_OK) {
goto CLEANUP;
}
// Convert python object into username string
if (!PyUnicode_Check(py_user)) {
as_error_update(&err, AEROSPIKE_ERR_PARAM,
"Username should be a string");
goto CLEANUP;
}
user = PyUnicode_AsUTF8(py_user);
// Convert python object to policy_admin
pyobject_to_policy_admin(self, &err, py_policy, &admin_policy,
&admin_policy_p, &self->as->config.policies.admin);
if (err.code != AEROSPIKE_OK) {
goto CLEANUP;
}
// Invoke operation
Py_BEGIN_ALLOW_THREADS
aerospike_grant_roles(self->as, &err, admin_policy_p, user,
(const char **)roles, roles_size);
Py_END_ALLOW_THREADS
if (err.code != AEROSPIKE_OK) {
as_error_update(&err, err.code, NULL);
goto CLEANUP;
}
CLEANUP:
for (int i = 0; i < roles_size; i++) {
if (roles[i])
cf_free(roles[i]);
}
if (err.code != AEROSPIKE_OK) {
raise_exception(&err);
return NULL;
}
return PyLong_FromLong(0);
}
/**
*******************************************************************************************************
* Revokes roles of a user in the Aerospike DB.
*
* @param self AerospikeClient object
* @param args The args is a tuple object containing an argument
* list passed from Python to a C function
* @param kwds Dictionary of keywords
*
* Returns an integer status. 0(Zero) is success value.
* In case of error,appropriate exceptions will be raised.
*******************************************************************************************************
*/
PyObject *AerospikeClient_Admin_Revoke_Roles(AerospikeClient *self,
PyObject *args, PyObject *kwds)
{
// Initialize error
as_error err;
as_error_init(&err);
// Python Function Arguments
PyObject *py_policy = NULL;
PyObject *py_user = NULL;
PyObject *py_roles = NULL;
as_policy_admin admin_policy;
as_policy_admin *admin_policy_p = NULL;
// Python Function Keyword Arguments
static char *kwlist[] = {"user", "roles", "policy", NULL};
// Python Function Argument Parsing
if (PyArg_ParseTupleAndKeywords(args, kwds, "OO|O:admin_revoke_roles",
kwlist, &py_user, &py_roles,
&py_policy) == false) {
return NULL;
}
// Aerospike Operation Arguments
const char *user;
int roles_size = 0;
char **roles = NULL;
if (!self || !self->as) {
as_error_update(&err, AEROSPIKE_ERR_PARAM, "Invalid aerospike object");
goto CLEANUP;
}
if (!self->is_conn_16) {
as_error_update(&err, AEROSPIKE_ERR_CLUSTER,
"No connection to aerospike cluster");
goto CLEANUP;
}
// Convert python object to array of roles
if (PyList_Check(py_roles)) {
roles_size = PyList_Size(py_roles);
roles = alloca(sizeof(char *) * roles_size);
for (int i = 0; i < roles_size; i++) {
roles[i] = cf_malloc(sizeof(char) * AS_ROLE_SIZE);
memset(roles[i], 0, sizeof(char) * AS_ROLE_SIZE);
}
}
pyobject_to_strArray(&err, py_roles, roles, AS_ROLE_SIZE);
if (err.code != AEROSPIKE_OK) {
goto CLEANUP;
}
if (py_policy == Py_None) {
py_policy = PyDict_New();
}
// Convert python object to username string
if (!PyUnicode_Check(py_user)) {
as_error_update(&err, AEROSPIKE_ERR_PARAM,
"Username should be a string");
goto CLEANUP;
}
user = PyUnicode_AsUTF8(py_user);
// Convert python object to policy_admin
pyobject_to_policy_admin(self, &err, py_policy, &admin_policy,
&admin_policy_p, &self->as->config.policies.admin);
if (err.code != AEROSPIKE_OK) {
goto CLEANUP;
}
// Invoke operation
Py_BEGIN_ALLOW_THREADS
aerospike_revoke_roles(self->as, &err, admin_policy_p, user,
(const char **)roles, roles_size);
Py_END_ALLOW_THREADS
if (err.code != AEROSPIKE_OK) {
as_error_update(&err, err.code, NULL);
goto CLEANUP;
}
CLEANUP:
for (int i = 0; i < roles_size; i++) {
if (roles[i])
cf_free(roles[i]);
}
if (err.code != AEROSPIKE_OK) {
raise_exception(&err);
return NULL;
}
return PyLong_FromLong(0);
}
/**
*******************************************************************************************************
* Queries a user in the Aerospike DB.
*
* @param self AerospikeClient object
* @param args The args is a tuple object containing an argument
* list passed from Python to a C function
* @param kwds Dictionary of keywords
*
* Returns an integer status. 0(Zero) is success value.
* In case of error,appropriate exceptions will be raised.
*******************************************************************************************************
*/
PyObject *AerospikeClient_Admin_Query_User(AerospikeClient *self,
PyObject *args, PyObject *kwds)
{
// Initialize error
as_error err;
as_error_init(&err);
// Python Function Arguments
PyObject *py_policy = NULL;
PyObject *py_user_name = NULL;
// Python Function Result
PyObject *py_user = NULL;
as_policy_admin admin_policy;
as_policy_admin *admin_policy_p = NULL;
// Python Function Keyword Arguments
static char *kwlist[] = {"user", "policy", NULL};
// Python Function Argument Parsing
if (PyArg_ParseTupleAndKeywords(args, kwds, "O|O:admin_query_user", kwlist,
&py_user_name, &py_policy) == false) {
return NULL;
}
// Aerospike Operation Arguments
const char *user_name;
as_user *user = NULL;
if (!self || !self->as) {
as_error_update(&err, AEROSPIKE_ERR_PARAM, "Invalid aerospike object");
goto CLEANUP;
}
if (!self->is_conn_16) {
as_error_update(&err, AEROSPIKE_ERR_CLUSTER,
"No connection to aerospike cluster");
goto CLEANUP;
}
// Convert python object to policy_admin
pyobject_to_policy_admin(self, &err, py_policy, &admin_policy,
&admin_policy_p, &self->as->config.policies.admin);
if (err.code != AEROSPIKE_OK) {
goto CLEANUP;
}
// Convert python object to username string
if (!PyUnicode_Check(py_user_name)) {
as_error_update(&err, AEROSPIKE_ERR_PARAM,
"Username should be a string");
goto CLEANUP;
}
user_name = PyUnicode_AsUTF8(py_user_name);
// Invoke operation
Py_BEGIN_ALLOW_THREADS
aerospike_query_user(self->as, &err, admin_policy_p, user_name, &user);
Py_END_ALLOW_THREADS
if (err.code != AEROSPIKE_OK) {
as_error_update(&err, err.code, NULL);
goto CLEANUP;
}
// Convert returned as_user struct to python object
as_user_to_pyobject(&err, user, &py_user);
if (err.code != AEROSPIKE_OK) {
as_error_update(&err, err.code, NULL);
goto CLEANUP;
}
CLEANUP:
if (user) {
as_user_destroy(user);
}
if (err.code != AEROSPIKE_OK) {
raise_exception(&err);
return NULL;
}
return py_user;
}
/**
*******************************************************************************************************
* Queries a user's info in the Aerospike DB.
*
* @param self AerospikeClient object
* @param args The args is a tuple object containing an argument
* list passed from Python to a C function
* @param kwds Dictionary of keywords
*
* Returns an integer status. 0(Zero) is success value.
* In case of error,appropriate exceptions will be raised.
*******************************************************************************************************
*/
PyObject *AerospikeClient_Admin_Query_User_Info(AerospikeClient *self,
PyObject *args, PyObject *kwds)
{
// Initialize error
as_error err;
as_error_init(&err);
// Python Function Arguments
PyObject *py_policy = NULL;
PyObject *py_user_name = NULL;
// Python Function Result
PyObject *py_user = NULL;
as_policy_admin admin_policy;
as_policy_admin *admin_policy_p = NULL;
// Python Function Keyword Arguments
static char *kwlist[] = {"user", "policy", NULL};
// Python Function Argument Parsing
if (PyArg_ParseTupleAndKeywords(args, kwds, "O|O:admin_query_user_info",
kwlist, &py_user_name,
&py_policy) == false) {
return NULL;
}
// Aerospike Operation Arguments
const char *user_name;
as_user *user = NULL;
if (!self || !self->as) {
as_error_update(&err, AEROSPIKE_ERR_PARAM, "Invalid aerospike object");
goto CLEANUP;
}
if (!self->is_conn_16) {
as_error_update(&err, AEROSPIKE_ERR_CLUSTER,
"No connection to aerospike cluster");
goto CLEANUP;
}
// Convert python object to policy_admin
pyobject_to_policy_admin(self, &err, py_policy, &admin_policy,
&admin_policy_p, &self->as->config.policies.admin);
if (err.code != AEROSPIKE_OK) {
goto CLEANUP;
}
// Convert python object to username string
if (!PyUnicode_Check(py_user_name)) {
as_error_update(&err, AEROSPIKE_ERR_PARAM,
"Username should be a string");
goto CLEANUP;
}
user_name = PyUnicode_AsUTF8(py_user_name);
// Invoke operation
Py_BEGIN_ALLOW_THREADS
aerospike_query_user(self->as, &err, admin_policy_p, user_name, &user);
Py_END_ALLOW_THREADS
if (err.code != AEROSPIKE_OK) {
as_error_update(&err, err.code, NULL);
goto CLEANUP;
}
// Convert returned as_user struct to python object
as_user_info_to_pyobject(&err, user, &py_user);
if (err.code != AEROSPIKE_OK) {
as_error_update(&err, err.code, NULL);
goto CLEANUP;
}
CLEANUP:
if (user) {
as_user_destroy(user);
}
if (err.code != AEROSPIKE_OK) {
raise_exception(&err);
return NULL;
}
return py_user;
}
/**
*******************************************************************************************************
* Queries all users in the Aerospike DB.
*
* @param self AerospikeClient object
* @param args The args is a tuple object containing an argument
* list passed from Python to a C function
* @param kwds Dictionary of keywords
*
* Returns an integer status. 0(Zero) is success value.
* In case of error,appropriate exceptions will be raised.
*******************************************************************************************************
*/
PyObject *AerospikeClient_Admin_Query_Users(AerospikeClient *self,
PyObject *args, PyObject *kwds)
{
// Initialize error
as_error err;
as_error_init(&err);
// Python Function Arguments
PyObject *py_policy = NULL;
// Python Function Result
PyObject *py_users = NULL;
as_policy_admin admin_policy;
as_policy_admin *admin_policy_p = NULL;
// Python Function Keyword Arguments
static char *kwlist[] = {"policy", NULL};
// Python Function Argument Parsing
if (PyArg_ParseTupleAndKeywords(args, kwds, "|O:admin_query_users", kwlist,
&py_policy) == false) {
return NULL;
}
// Aerospike Operation Arguments
int users_size = 0;
as_user **users = NULL;
if (!self || !self->as) {
as_error_update(&err, AEROSPIKE_ERR_PARAM, "Invalid aerospike object");
goto CLEANUP;
}
if (!self->is_conn_16) {
as_error_update(&err, AEROSPIKE_ERR_CLUSTER,
"No connection to aerospike cluster");
goto CLEANUP;
}
// Convert python object to policy_admin
pyobject_to_policy_admin(self, &err, py_policy, &admin_policy,
&admin_policy_p, &self->as->config.policies.admin);
if (err.code != AEROSPIKE_OK) {
goto CLEANUP;
}
// Invoke operation
Py_BEGIN_ALLOW_THREADS
aerospike_query_users(self->as, &err, admin_policy_p, &users, &users_size);
Py_END_ALLOW_THREADS
if (err.code != AEROSPIKE_OK) {
as_error_update(&err, err.code, NULL);
goto CLEANUP;
}
// Convert returned array of as_user structs into python object;
as_user_array_to_pyobject(&err, users, &py_users, users_size);
if (err.code != AEROSPIKE_OK) {
as_error_update(&err, err.code, NULL);
goto CLEANUP;
}
CLEANUP:
if (users) {
as_users_destroy(users, users_size);
}
if (err.code != AEROSPIKE_OK) {
raise_exception(&err);
return NULL;
}
return py_users;
}
/**
*******************************************************************************************************
* Queries all users info in the Aerospike DB.
*
* @param self AerospikeClient object
* @param args The args is a tuple object containing an argument
* list passed from Python to a C function
* @param kwds Dictionary of keywords
*
* Returns an integer status. 0(Zero) is success value.
* In case of error,appropriate exceptions will be raised.
*******************************************************************************************************
*/
PyObject *AerospikeClient_Admin_Query_Users_Info(AerospikeClient *self,
PyObject *args, PyObject *kwds)
{
// Initialize error
as_error err;
as_error_init(&err);
// Python Function Arguments
PyObject *py_policy = NULL;
// Python Function Result
PyObject *py_users = NULL;
as_policy_admin admin_policy;
as_policy_admin *admin_policy_p = NULL;
// Python Function Keyword Arguments
static char *kwlist[] = {"policy", NULL};
// Python Function Argument Parsing
if (PyArg_ParseTupleAndKeywords(args, kwds, "|O:admin_query_users_info",
kwlist, &py_policy) == false) {
return NULL;
}
// Aerospike Operation Arguments
int users_size = 0;
as_user **users = NULL;
if (!self || !self->as) {
as_error_update(&err, AEROSPIKE_ERR_PARAM, "Invalid aerospike object");
goto CLEANUP;
}
if (!self->is_conn_16) {
as_error_update(&err, AEROSPIKE_ERR_CLUSTER,
"No connection to aerospike cluster");
goto CLEANUP;
}
// Convert python object to policy_admin
pyobject_to_policy_admin(self, &err, py_policy, &admin_policy,
&admin_policy_p, &self->as->config.policies.admin);
if (err.code != AEROSPIKE_OK) {
goto CLEANUP;
}
// Invoke operation
Py_BEGIN_ALLOW_THREADS
aerospike_query_users(self->as, &err, admin_policy_p, &users, &users_size);
Py_END_ALLOW_THREADS
if (err.code != AEROSPIKE_OK) {
as_error_update(&err, err.code, NULL);
goto CLEANUP;
}
// Convert returned array of as_user structs into python object;
as_user_info_array_to_pyobject(&err, users, &py_users, users_size);
if (err.code != AEROSPIKE_OK) {
as_error_update(&err, err.code, NULL);
goto CLEANUP;
}
CLEANUP:
if (users) {
as_users_destroy(users, users_size);
}
if (err.code != AEROSPIKE_OK) {
raise_exception(&err);
return NULL;
}
return py_users;
}
/**
*******************************************************************************************************
* Create a role in the Aerospike DB.
*
* @param self AerospikeClient object
* @param args The args is a tuple object containing an argument
* list passed from Python to a C function
* @param kwds Dictionary of keywords
*
* Returns an integer status. 0(Zero) is success value.
* In case of error,appropriate exceptions will be raised.
*******************************************************************************************************
*/
PyObject *AerospikeClient_Admin_Create_Role(AerospikeClient *self,
PyObject *args, PyObject *kwds)
{
// Initialize error.
as_error err;
as_error_init(&err);
// Python Function Arguments.
PyObject *py_role = NULL;
PyObject *py_privileges = NULL;
PyObject *py_policy = NULL;
PyObject *py_whitelist = NULL;
PyObject *py_read_quota = NULL;
PyObject *py_write_quota = NULL;
// Aerospike Operation Arguments.
int privileges_size = 0;
int whitelist_size = 0;
as_privilege **privileges = NULL;
char **whitelist = NULL;
// Python Function Keyword Arguments.
static char *kwlist[] = {"role", "privileges", "policy", "whitelist",
"read_quota", "write_quota", NULL};
// Python Function Argument Parsing.
if (PyArg_ParseTupleAndKeywords(args, kwds, "O|OOOOO:admin_create_role",
kwlist, &py_role, &py_privileges,
&py_policy, &py_whitelist, &py_read_quota,
&py_write_quota) == false) {
return NULL;
}
// sanity connection checks.
if (!self || !self->as) {
as_error_update(&err, AEROSPIKE_ERR_PARAM, "Invalid aerospike object");
goto CLEANUP;
}
if (!self->is_conn_16) {
as_error_update(&err, AEROSPIKE_ERR_CLUSTER,
"No connection to aerospike cluster");
goto CLEANUP;
}
const char *role;
if (PyUnicode_Check(py_role)) {
role = PyUnicode_AsUTF8(py_role);
}
else {
as_error_update(&err, AEROSPIKE_ERR_PARAM,
"Role name should be a string");
goto CLEANUP;
}
// Convert python object to an array of privileges.
if (py_privileges != NULL) {
if (!PyList_Check(py_privileges)) {
as_error_update(&err, AEROSPIKE_ERR_PARAM,
"Privileges should be a list");
goto CLEANUP;
}
privileges_size = PyList_Size(py_privileges);
privileges = (as_privilege **)cf_malloc(sizeof(as_privilege *) *
privileges_size);
for (int i = 0; i < privileges_size; ++i) {
privileges[i] = (as_privilege *)cf_malloc(sizeof(as_privilege));
}
if (pyobject_to_as_privileges(&err, py_privileges, privileges,
privileges_size) != AEROSPIKE_OK) {
goto CLEANUP;
}
}
// Convert python object to an admin policy.
as_policy_admin admin_policy;
as_policy_admin *admin_policy_p = NULL;
if (pyobject_to_policy_admin(
self, &err, py_policy, &admin_policy, &admin_policy_p,
&self->as->config.policies.admin) != AEROSPIKE_OK) {
goto CLEANUP;
}
if (py_whitelist != NULL) {
if (!PyList_Check(py_whitelist)) {
as_error_update(&err, AEROSPIKE_ERR_PARAM,
"Whitelist must be a list of IP strings.");
goto CLEANUP;
}
whitelist_size = PyList_Size(py_whitelist);
whitelist = (char **)cf_malloc(sizeof(char *) * whitelist_size);
for (int i = 0; i < whitelist_size; i++) {
whitelist[i] = cf_malloc(sizeof(char) * AS_IP_ADDRESS_SIZE);
}
if (pyobject_to_strArray(&err, py_whitelist, whitelist,
AS_IP_ADDRESS_SIZE) != AEROSPIKE_OK) {
goto CLEANUP;
}
}
int read_quota = 0;
if (py_read_quota != NULL) {
get_int_from_py_int(&err, py_read_quota, &read_quota, "py_read_quota");
}
int write_quota = 0;
if (py_write_quota != NULL) {
get_int_from_py_int(&err, py_write_quota, &write_quota,
"py_write_quota");
}
Py_BEGIN_ALLOW_THREADS
aerospike_create_role_quotas(
self->as, &err, admin_policy_p, role, privileges, privileges_size,
(const char **)whitelist, whitelist_size, read_quota, write_quota);
Py_END_ALLOW_THREADS
CLEANUP:
if (privileges) {
for (int i = 0; i < privileges_size; i++) {
if (privileges[i])
cf_free(privileges[i]);
}
cf_free(privileges);
}
if (whitelist) {
for (int i = 0; i < whitelist_size; i++) {
if (whitelist[i])
cf_free(whitelist[i]);
}
cf_free(whitelist);
}
if (err.code != AEROSPIKE_OK) {
raise_exception(&err);
return NULL;
}
return PyLong_FromLong(0);
}
/**
*******************************************************************************************************
* Add whitelist to a role in the Aerospike DB.
*
* @param self AerospikeClient object
* @param args The args is a tuple object containing an argument
* list passed from Python to a C function
* @param kwds Dictionary of keywords
*
* Returns an integer status. 0(Zero) is success value.
* In case of error,appropriate exceptions will be raised.
*******************************************************************************************************
*/
PyObject *AerospikeClient_Admin_Set_Whitelist(AerospikeClient *self,
PyObject *args, PyObject *kwds)
{
// Initialize error.
as_error err;
as_error_init(&err);
// Python Function Arguments.
PyObject *py_role = NULL;
PyObject *py_whitelist = NULL;
PyObject *py_policy = NULL;
// C API args.
char **whitelist = NULL;
// Sanity connection checks.
if (!self || !self->as) {
as_error_update(&err, AEROSPIKE_ERR_PARAM, "Invalid aerospike object.");
goto CLEANUP;
}
if (!self->is_conn_16) {
as_error_update(&err, AEROSPIKE_ERR_CLUSTER,
"No connection to aerospike cluster.");
goto CLEANUP;
}
// Python Function Keyword Arguments.
static char *kwlist[] = {"role", "whitelist", "policy", NULL};
// Python Function Argument Parsing.
if (PyArg_ParseTupleAndKeywords(args, kwds, "OO|O:admin_set_whitelist",
kwlist, &py_role, &py_whitelist,
&py_policy) == false) {
return NULL;
}
const char *role;
if (PyUnicode_Check(py_role)) {
role = PyUnicode_AsUTF8(py_role);
}
else {
as_error_update(&err, AEROSPIKE_ERR_PARAM,
"Role name should be a string.");
goto CLEANUP;
}
int whitelist_size = 0;
if (PyList_Check(py_whitelist)) {
whitelist_size = PyList_Size(py_whitelist);
whitelist = (char **)cf_malloc(sizeof(char *) * whitelist_size);
for (int i = 0; i < whitelist_size; i++) {
whitelist[i] = cf_malloc(sizeof(char) * AS_IP_ADDRESS_SIZE);
}
if (pyobject_to_strArray(&err, py_whitelist, whitelist,
AS_IP_ADDRESS_SIZE) != AEROSPIKE_OK) {
goto CLEANUP;
}
}
else if (py_whitelist == Py_None) {
whitelist_size = 0;
}
else {
as_error_update(&err, AEROSPIKE_ERR_PARAM,
"Whitelist must be a list of IP strings, or None.");
goto CLEANUP;
}
as_policy_admin admin_policy;
as_policy_admin *admin_policy_p = NULL;
pyobject_to_policy_admin(self, &err, py_policy, &admin_policy,
&admin_policy_p, &self->as->config.policies.admin);
if (err.code != AEROSPIKE_OK) {
goto CLEANUP;
}
// Invoke operation.
Py_BEGIN_ALLOW_THREADS
aerospike_set_whitelist(self->as, &err, admin_policy_p, role,
(const char **)whitelist, whitelist_size);
Py_END_ALLOW_THREADS
CLEANUP:
if (whitelist != NULL) {
for (int i = 0; i < whitelist_size; i++) {
if (whitelist[i])
cf_free(whitelist[i]);
}
cf_free(whitelist);
}
if (err.code != AEROSPIKE_OK) {
raise_exception(&err);
return NULL;
}
return PyLong_FromLong(0);
}
/**
*******************************************************************************************************
* Add quotas to a role in the Aerospike DB.
*
* @param self AerospikeClient object
* @param args The args is a tuple object containing an argument
* list passed from Python to a C function
* @param kwds Dictionary of keywords
*
* Returns an integer status. 0(Zero) is success value.
* In case of error,appropriate exceptions will be raised.
*******************************************************************************************************
*/
PyObject *AerospikeClient_Admin_Set_Quotas(AerospikeClient *self,
PyObject *args, PyObject *kwds)
{
// Initialize error.
as_error err;
as_error_init(&err);
// Python Function Arguments.
PyObject *py_role = NULL;
PyObject *py_read_quota = NULL;
PyObject *py_write_quota = NULL;
PyObject *py_policy = NULL;
// Sanity connection checks.
if (!self || !self->as) {
as_error_update(&err, AEROSPIKE_ERR_PARAM, "Invalid aerospike object.");
goto CLEANUP;
}
if (!self->is_conn_16) {
as_error_update(&err, AEROSPIKE_ERR_CLUSTER,
"No connection to aerospike cluster.");
goto CLEANUP;
}
// Python Function Keyword Arguments.
static char *kwlist[] = {"role", "read_quota", "write_quota", "policy",
NULL};
// Python Function Argument Parsing.
if (PyArg_ParseTupleAndKeywords(args, kwds, "O|OOO:admin_set_quotas",
kwlist, &py_role, &py_read_quota,
&py_write_quota, &py_policy) == false) {
return NULL;
}
const char *role;
if (PyUnicode_Check(py_role)) {
role = PyUnicode_AsUTF8(py_role);
}
else {
as_error_update(&err, AEROSPIKE_ERR_PARAM,
"Role name should be a string.");
goto CLEANUP;
}
int read_quota = -1;
if (py_read_quota != NULL) {
get_int_from_py_int(&err, py_read_quota, &read_quota, "py_read_quota");
}
if (err.code != AEROSPIKE_OK) {
goto CLEANUP;
}
int write_quota = -1;
if (py_write_quota != NULL) {
get_int_from_py_int(&err, py_write_quota, &write_quota,
"py_write_quota");
}
if (err.code != AEROSPIKE_OK) {
goto CLEANUP;
}
as_policy_admin admin_policy;
as_policy_admin *admin_policy_p = NULL;
pyobject_to_policy_admin(self, &err, py_policy, &admin_policy,
&admin_policy_p, &self->as->config.policies.admin);
if (err.code != AEROSPIKE_OK) {
goto CLEANUP;
}
// Invoke operation.
Py_BEGIN_ALLOW_THREADS
aerospike_set_quotas(self->as, &err, admin_policy_p, role, read_quota,
write_quota);
Py_END_ALLOW_THREADS
CLEANUP:
if (err.code != AEROSPIKE_OK) {
raise_exception(&err);
return NULL;
}
return PyLong_FromLong(0);
}
/**
*******************************************************************************************************
* Drop a role in the Aerospike DB.
*
* @param self AerospikeClient object
* @param args The args is a tuple object containing an argument
* list passed from Python to a C function
* @param kwds Dictionary of keywords
*
* Returns an integer status. 0(Zero) is success value.
* In case of error,appropriate exceptions will be raised.
*******************************************************************************************************
*/
PyObject *AerospikeClient_Admin_Drop_Role(AerospikeClient *self, PyObject *args,
PyObject *kwds)
{
// Initialize error
as_error err;
as_error_init(&err);
// Python Function Arguments
PyObject *py_policy = NULL;
PyObject *py_role = NULL;
as_policy_admin admin_policy;
as_policy_admin *admin_policy_p = NULL;
// Python Function Keyword Arguments
static char *kwlist[] = {"role", "policy", NULL};
// Python Function Argument Parsing
if (PyArg_ParseTupleAndKeywords(args, kwds, "O|O:admin_drop_role", kwlist,
&py_role, &py_policy) == false) {
return NULL;
}
if (!self || !self->as) {
as_error_update(&err, AEROSPIKE_ERR_PARAM, "Invalid aerospike object");
goto CLEANUP;
}
if (!self->is_conn_16) {
as_error_update(&err, AEROSPIKE_ERR_CLUSTER,
"No connection to aerospike cluster");
goto CLEANUP;
}
pyobject_to_policy_admin(self, &err, py_policy, &admin_policy,
&admin_policy_p, &self->as->config.policies.admin);
if (err.code != AEROSPIKE_OK) {
goto CLEANUP;
}
const char *role;
if (PyUnicode_Check(py_role)) {
role = PyUnicode_AsUTF8(py_role);
}
else {
as_error_update(&err, AEROSPIKE_ERR_PARAM,
"Role name should be a string");
goto CLEANUP;
}
// Invoke operation
Py_BEGIN_ALLOW_THREADS
aerospike_drop_role(self->as, &err, admin_policy_p, role);
Py_END_ALLOW_THREADS
CLEANUP:
if (err.code != AEROSPIKE_OK) {
raise_exception(&err);
return NULL;
}
return PyLong_FromLong(0);
}
/**
*******************************************************************************************************
* Add privileges to a role in the Aerospike DB.
*
* @param self AerospikeClient object
* @param args The args is a tuple object containing an argument
* list passed from Python to a C function
* @param kwds Dictionary of keywords
*
* Returns an integer status. 0(Zero) is success value.
* In case of error,appropriate exceptions will be raised.
*******************************************************************************************************
*/
PyObject *AerospikeClient_Admin_Grant_Privileges(AerospikeClient *self,
PyObject *args, PyObject *kwds)
{
// Initialize error
as_error err;
as_error_init(&err);
// Python Function Arguments
PyObject *py_policy = NULL;
PyObject *py_role = NULL;
PyObject *py_privileges = NULL;
as_policy_admin admin_policy;
as_policy_admin *admin_policy_p = NULL;
// Python Function Keyword Arguments
static char *kwlist[] = {"role", "privileges", "policy", NULL};
// Python Function Argument Parsing
if (PyArg_ParseTupleAndKeywords(args, kwds, "OO|O:admin_grant_privileges",
kwlist, &py_role, &py_privileges,
&py_policy) == false) {
return NULL;
}
// Aerospike Operation Arguments
int privileges_size = 0;
as_privilege **privileges = NULL;
if (!self || !self->as) {
as_error_update(&err, AEROSPIKE_ERR_PARAM, "Invalid aerospike object");
goto CLEANUP;
}
if (!self->is_conn_16) {
as_error_update(&err, AEROSPIKE_ERR_CLUSTER,
"No connection to aerospike cluster");
goto CLEANUP;
}
// Convert python object to an array of privileges
if (!PyList_Check(py_privileges)) {
as_error_update(&err, AEROSPIKE_ERR_PARAM,
"Privileges should be a list");
goto CLEANUP;
}
privileges_size = PyList_Size(py_privileges);
privileges =
(as_privilege **)cf_malloc(sizeof(as_privilege *) * privileges_size);
for (int i = 0; i < privileges_size; ++i) {
privileges[i] = (as_privilege *)cf_malloc(sizeof(as_privilege));
}
pyobject_to_as_privileges(&err, py_privileges, privileges, privileges_size);
pyobject_to_policy_admin(self, &err, py_policy, &admin_policy,
&admin_policy_p, &self->as->config.policies.admin);
if (err.code != AEROSPIKE_OK) {
goto CLEANUP;
}
const char *role;
if (PyUnicode_Check(py_role)) {
role = PyUnicode_AsUTF8(py_role);
}
else {
as_error_update(&err, AEROSPIKE_ERR_PARAM,
"Role name should be a string");
goto CLEANUP;
}
// Invoke operation
Py_BEGIN_ALLOW_THREADS
aerospike_grant_privileges(self->as, &err, admin_policy_p, role, privileges,
privileges_size);
Py_END_ALLOW_THREADS
CLEANUP:
if (privileges != NULL) {
for (int i = 0; i < privileges_size; i++) {
if (privileges[i])
cf_free(privileges[i]);
}
cf_free(privileges);
}
if (err.code != AEROSPIKE_OK) {
raise_exception(&err);
return NULL;
}
return PyLong_FromLong(0);
}
/**
*******************************************************************************************************
* Revoke privileges to a role in the Aerospike DB.
*
* @param self AerospikeClient object
* @param args The args is a tuple object containing an argument
* list passed from Python to a C function
* @param kwds Dictionary of keywords
*
* Returns an integer status. 0(Zero) is success value.
* In case of error,appropriate exceptions will be raised.
*******************************************************************************************************
*/
PyObject *AerospikeClient_Admin_Revoke_Privileges(AerospikeClient *self,
PyObject *args,
PyObject *kwds)
{
// Initialize error
as_error err;
as_error_init(&err);
// Python Function Arguments
PyObject *py_policy = NULL;
PyObject *py_role = NULL;
PyObject *py_privileges = NULL;
as_policy_admin admin_policy;
as_policy_admin *admin_policy_p = NULL;
// Python Function Keyword Arguments
static char *kwlist[] = {"role", "privileges", "policy", NULL};
// Python Function Argument Parsing
if (PyArg_ParseTupleAndKeywords(args, kwds, "OO|O:admin_revoke_privileges",
kwlist, &py_role, &py_privileges,
&py_policy) == false) {
return NULL;
}
// Aerospike Operation Arguments
int privileges_size = 0;
as_privilege **privileges = NULL;
if (!self || !self->as) {
as_error_update(&err, AEROSPIKE_ERR_PARAM, "Invalid aerospike object");
goto CLEANUP;
}
if (!self->is_conn_16) {
as_error_update(&err, AEROSPIKE_ERR_CLUSTER,
"No connection to aerospike cluster");
goto CLEANUP;
}
// Convert python object to an array of privileges
if (!PyList_Check(py_privileges)) {
as_error_update(&err, AEROSPIKE_ERR_PARAM,
"Privileges should be a list");
goto CLEANUP;
}
privileges_size = PyList_Size(py_privileges);
privileges =
(as_privilege **)cf_malloc(sizeof(as_privilege *) * privileges_size);
for (int i = 0; i < privileges_size; ++i) {
privileges[i] = (as_privilege *)cf_malloc(sizeof(as_privilege));
}
pyobject_to_as_privileges(&err, py_privileges, privileges, privileges_size);
pyobject_to_policy_admin(self, &err, py_policy, &admin_policy,
&admin_policy_p, &self->as->config.policies.admin);
if (err.code != AEROSPIKE_OK) {
goto CLEANUP;
}
const char *role;
if (PyUnicode_Check(py_role)) {
role = PyUnicode_AsUTF8(py_role);
}
else {
as_error_update(&err, AEROSPIKE_ERR_PARAM,
"Role name should be a string");
goto CLEANUP;
}
// Invoke operation
Py_BEGIN_ALLOW_THREADS
aerospike_revoke_privileges(self->as, &err, admin_policy_p, role,
privileges, privileges_size);
Py_END_ALLOW_THREADS
CLEANUP:
if (privileges != NULL) {
for (int i = 0; i < privileges_size; i++) {
if (privileges[i])
cf_free(privileges[i]);
}
cf_free(privileges);
}
if (err.code != AEROSPIKE_OK) {
raise_exception(&err);
return NULL;
}
return PyLong_FromLong(0);
}
/**
*******************************************************************************************************
* Query a role in the Aerospike DB.
*
* @param self AerospikeClient object
* @param args The args is a tuple object containing an argument
* list passed from Python to a C function
* @param kwds Dictionary of keywords
*
* Returns data of a particular role on success.
* In case of error,appropriate exceptions will be raised.
*******************************************************************************************************
*/
PyObject *AerospikeClient_Admin_Query_Role(AerospikeClient *self,
PyObject *args, PyObject *kwds)
{
// Initialize error
as_error err;
as_error_init(&err);
// Python Function Arguments
PyObject *py_policy = NULL;
PyObject *py_role = NULL;
PyObject *py_ret_role = NULL;
as_policy_admin admin_policy;
as_policy_admin *admin_policy_p = NULL;
as_role *ret_role = NULL;
// Python Function Keyword Arguments
static char *kwlist[] = {"role", "policy", NULL};
// Python Function Argument Parsing
if (PyArg_ParseTupleAndKeywords(args, kwds, "O|O:admin_query_role", kwlist,
&py_role, &py_policy) == false) {
return NULL;
}
if (!self || !self->as) {
as_error_update(&err, AEROSPIKE_ERR_PARAM, "Invalid aerospike object");
goto CLEANUP;
}
if (!self->is_conn_16) {
as_error_update(&err, AEROSPIKE_ERR_CLUSTER,
"No connection to aerospike cluster");
goto CLEANUP;
}
pyobject_to_policy_admin(self, &err, py_policy, &admin_policy,
&admin_policy_p, &self->as->config.policies.admin);
if (err.code != AEROSPIKE_OK) {
goto CLEANUP;
}
const char *role;
if (PyUnicode_Check(py_role)) {
role = PyUnicode_AsUTF8(py_role);
}
else {
as_error_update(&err, AEROSPIKE_ERR_PARAM,
"Role name should be a string");
goto CLEANUP;
}
// Invoke operation
Py_BEGIN_ALLOW_THREADS
aerospike_query_role(self->as, &err, admin_policy_p, role, &ret_role);
Py_END_ALLOW_THREADS
if (err.code != AEROSPIKE_OK) {
goto CLEANUP;
}
as_role_to_pyobject_old(&err, ret_role, &py_ret_role);
CLEANUP:
if (ret_role != NULL) {
as_role_destroy(ret_role);
}
if (err.code != AEROSPIKE_OK) {
raise_exception(&err);
return NULL;
}
return py_ret_role;
}
/**
*******************************************************************************************************
* Query all roles in the Aerospike DB.
*
* @param self AerospikeClient object
* @param args The args is a tuple object containing an argument
* list passed from Python to a C function
* @param kwds Dictionary of keywords
*
* Returns data of all roles on success.
* In case of error,appropriate exceptions will be raised.
*******************************************************************************************************
*/
PyObject *AerospikeClient_Admin_Query_Roles(AerospikeClient *self,
PyObject *args, PyObject *kwds)
{
// Initialize error
as_error err;
as_error_init(&err);
// Python Function Arguments
PyObject *py_policy = NULL;
PyObject *py_ret_role = NULL;
as_policy_admin admin_policy;
as_policy_admin *admin_policy_p = NULL;
as_role **ret_role = NULL;
int ret_role_size = 0;
// Python Function Keyword Arguments
static char *kwlist[] = {"policy", NULL};
// Python Function Argument Parsing
if (PyArg_ParseTupleAndKeywords(args, kwds, "|O:admin_query_roles", kwlist,
&py_policy) == false) {
return NULL;
}
if (!self || !self->as) {
as_error_update(&err, AEROSPIKE_ERR_PARAM, "Invalid aerospike object");
goto CLEANUP;
}
if (!self->is_conn_16) {
as_error_update(&err, AEROSPIKE_ERR_CLUSTER,
"No connection to aerospike cluster");
goto CLEANUP;
}
pyobject_to_policy_admin(self, &err, py_policy, &admin_policy,
&admin_policy_p, &self->as->config.policies.admin);
if (err.code != AEROSPIKE_OK) {
goto CLEANUP;
}
// Invoke operation
Py_BEGIN_ALLOW_THREADS
aerospike_query_roles(self->as, &err, admin_policy_p, &ret_role,
&ret_role_size);
Py_END_ALLOW_THREADS
if (err.code != AEROSPIKE_OK) {
goto CLEANUP;
}
as_role_array_to_pyobject_old(&err, ret_role, &py_ret_role, ret_role_size);
CLEANUP:
if (ret_role) {
as_roles_destroy(ret_role, ret_role_size);
}
if (err.code != AEROSPIKE_OK) {
raise_exception(&err);
return NULL;
}
return py_ret_role;
}
/**
*******************************************************************************************************
* Query a role in the Aerospike DB.
*
* @param self AerospikeClient object
* @param args The args is a tuple object containing an argument
* list passed from Python to a C function
* @param kwds Dictionary of keywords
*
* Returns data of a particular role on success.
* In case of error,appropriate exceptions will be raised.
*******************************************************************************************************
*/
PyObject *AerospikeClient_Admin_Get_Role(AerospikeClient *self, PyObject *args,
PyObject *kwds)
{
// Initialize error
as_error err;
as_error_init(&err);
// Python Function Arguments
PyObject *py_policy = NULL;
PyObject *py_role = NULL;
PyObject *py_ret_role = NULL;
as_policy_admin admin_policy;
as_policy_admin *admin_policy_p = NULL;
as_role *ret_role = NULL;
// Python Function Keyword Arguments
static char *kwlist[] = {"role", "policy", NULL};
// Python Function Argument Parsing
if (PyArg_ParseTupleAndKeywords(args, kwds, "O|O:admin_get_role", kwlist,
&py_role, &py_policy) == false) {
return NULL;
}
if (!self || !self->as) {
as_error_update(&err, AEROSPIKE_ERR_PARAM, "Invalid aerospike object");
goto CLEANUP;
}
if (!self->is_conn_16) {
as_error_update(&err, AEROSPIKE_ERR_CLUSTER,
"No connection to aerospike cluster");
goto CLEANUP;
}
pyobject_to_policy_admin(self, &err, py_policy, &admin_policy,
&admin_policy_p, &self->as->config.policies.admin);
if (err.code != AEROSPIKE_OK) {
goto CLEANUP;
}
const char *role;
if (PyUnicode_Check(py_role)) {
role = PyUnicode_AsUTF8(py_role);
}
else {
as_error_update(&err, AEROSPIKE_ERR_PARAM,
"Role name should be a string");
goto CLEANUP;
}
// Invoke operation
Py_BEGIN_ALLOW_THREADS
aerospike_query_role(self->as, &err, admin_policy_p, role, &ret_role);
Py_END_ALLOW_THREADS
if (err.code != AEROSPIKE_OK) {
goto CLEANUP;
}
py_ret_role = PyDict_New();
if (py_ret_role == NULL) {
as_error_update(&err, AEROSPIKE_ERR_CLIENT,
"Failed to create py_ret_role.");
goto CLEANUP;
}
as_role_to_pyobject(&err, ret_role, py_ret_role);
CLEANUP:
if (ret_role) {
as_role_destroy(ret_role);
}
if (err.code != AEROSPIKE_OK) {
raise_exception(&err);
return NULL;
}
return py_ret_role;
}
/**
*******************************************************************************************************
* Query all roles in the Aerospike DB.
*
* @param self AerospikeClient object
* @param args The args is a tuple object containing an argument
* list passed from Python to a C function
* @param kwds Dictionary of keywords
*
* Returns data of all roles on success.
* In case of error,appropriate exceptions will be raised.
*******************************************************************************************************
*/
PyObject *AerospikeClient_Admin_Get_Roles(AerospikeClient *self, PyObject *args,
PyObject *kwds)
{
// Initialize error
as_error err;
as_error_init(&err);
// Python Function Arguments
PyObject *py_policy = NULL;
PyObject *py_ret_role = NULL;
as_policy_admin admin_policy;
as_policy_admin *admin_policy_p = NULL;
as_role **ret_role = NULL;
int ret_role_size = 0;
// Python Function Keyword Arguments
static char *kwlist[] = {"policy", NULL};
// Python Function Argument Parsing
if (PyArg_ParseTupleAndKeywords(args, kwds, "|O:admin_get_roles", kwlist,
&py_policy) == false) {
return NULL;
}
if (!self || !self->as) {
as_error_update(&err, AEROSPIKE_ERR_PARAM, "Invalid aerospike object");
goto CLEANUP;
}
if (!self->is_conn_16) {
as_error_update(&err, AEROSPIKE_ERR_CLUSTER,
"No connection to aerospike cluster");
goto CLEANUP;
}
pyobject_to_policy_admin(self, &err, py_policy, &admin_policy,
&admin_policy_p, &self->as->config.policies.admin);
if (err.code != AEROSPIKE_OK) {
goto CLEANUP;
}
// Invoke operation
Py_BEGIN_ALLOW_THREADS
aerospike_query_roles(self->as, &err, admin_policy_p, &ret_role,
&ret_role_size);
Py_END_ALLOW_THREADS
if (err.code != AEROSPIKE_OK) {
goto CLEANUP;
}
as_role_array_to_pyobject(&err, ret_role, &py_ret_role, ret_role_size);
CLEANUP:
if (ret_role) {
as_roles_destroy(ret_role, ret_role_size);
}
if (err.code != AEROSPIKE_OK) {
raise_exception(&err);
return NULL;
}
return py_ret_role;
}
|
401e692dc3dd2293093dde434ba105c02f44ed86
|
0744dcc5394cebf57ebcba343747af6871b67017
|
/os/board/rtl8730e/src/component/network/rtsp/rtsp_api.c
|
281debb60490e8ca2e3db12273730aa9fb401947
|
[
"GPL-1.0-or-later",
"BSD-3-Clause",
"ISC",
"MIT",
"LicenseRef-scancode-warranty-disclaimer",
"LicenseRef-scancode-other-permissive",
"Apache-2.0"
] |
permissive
|
Samsung/TizenRT
|
96abf62f1853f61fcf91ff14671a5e0c6ca48fdb
|
1a5c2e00a4b1bbf4c505bbf5cc6a8259e926f686
|
refs/heads/master
| 2023-08-31T08:59:33.327998
| 2023-08-08T06:09:20
| 2023-08-31T04:38:20
| 82,517,252
| 590
| 719
|
Apache-2.0
| 2023-09-14T06:54:49
| 2017-02-20T04:38:30
|
C
|
UTF-8
|
C
| false
| false
| 66,246
|
c
|
rtsp_api.c
|
#include "FreeRTOS.h"
#include "task.h"
#include "platform_stdlib.h"
#include "rtsp/rtsp_api.h"
#if defined(CONFIG_PLATFORM_8195A)
#include "mmf_dbg.h"
#endif
#if defined(CONFIG_PLATFORM_8195BHP) || defined(CONFIG_PLATFORM_8721D) || defined(CONFIG_PLATFORM_8735B)
#include "mmf2_dbg.h"
#endif
#include "wifi_conf.h"
#include "lwip_netconf.h" // for LwIP_GetMAC
#include "rtw_wifi_constants.h"// for _htons
#define RTSP_CTX_ID_BASE 0
static uint32_t rtsp_ctx_id_bitmap = 0;
_mutex rtsp_ctx_id_bitmap_lock = NULL;
unsigned portBASE_TYPE rtsp_service_priority = RTSP_SERVICE_PRIORITY;
static char *plid_string = NULL;
static char *sps_string = NULL;
static char *pps_string = NULL;
unsigned char h264_flag_adjust = 0;//for h264 time delay
unsigned char aac_flag_adjust = 0;//for aac time delay
char AmebaCam_device_name[256] = {0};
uint32_t rtp_drop_threshold = 500;
uint8_t flag_show_ts_diff = 0;
#if 0
void set_change_rate_enable(struct stream_context *stream_ctx, uint32_t en)
{
stream_ctx->framecontrol.h264_change_rate_control = en;
stream_ctx->framecontrol.change_rate_frequency = 5000;
stream_ctx->framecontrol.change_rate_threshold1 = (stream_ctx->framecontrol.change_rate_frequency / stream_ctx->framerate) / 2;
stream_ctx->framecontrol.change_rate_threshold2 = (stream_ctx->framecontrol.change_rate_frequency / stream_ctx->framerate) * 2 / 3;
}
#endif
void set_drop_frame_enable(struct stream_context *stream_ctx, uint32_t en)
{
stream_ctx->framecontrol.drop_frame_enable = en;
}
void set_drop_frame_forcei(struct stream_context *stream_ctx, uint32_t forcei)
{
stream_ctx->framecontrol.drop_frame_use_forcei = forcei;
}
void set_h264_ctx(struct stream_context *stream_ctx, void *h264_ctx)
{
stream_ctx->framecontrol.h264_ctx = h264_ctx;
}
void set_rtp_drop_threshold(struct stream_context *stream_ctx, uint32_t drop_ms)
{
stream_ctx->framecontrol.rtp_drop_threshold = drop_ms;
}
void set_packet_retry(struct stream_context *stream_ctx, uint32_t retry)
{
stream_ctx->framecontrol.packet_retry = retry;
}
uint32_t get_rtp_drop_threshold(struct stream_context *stream_ctx)
{
return stream_ctx->framecontrol.rtp_drop_threshold;
}
void set_show_timestamp_diff(uint8_t action)
{
flag_show_ts_diff = action;
}
uint32_t get_show_timestamp_diff(void)
{
return flag_show_ts_diff;
}
void set_prefilter_packet(struct rtsp_context *rtsp_ctx, uint32_t num)
{
rtsp_ctx->pre_filter_packet = num;
}
void time_sync_disable(void)
{
h264_flag_adjust = 0;
aac_flag_adjust = 0;
printf("time_sync_disable\r\n");
}
void time_sync_enable(void)
{
h264_flag_adjust = 1;
aac_flag_adjust = 1;
printf("time_sync_enable\r\n");
}
void set_rtsp_url(struct rtsp_context *rtsp_ctx, char *url)
{
memset(rtsp_ctx->rtsp_url, 0, RTSP_URL_LEN);
memcpy(rtsp_ctx->rtsp_url, url, strlen(url));
printf("set_rtsp_url = %s\r\n", rtsp_ctx->rtsp_url);
}
int check_rtsp_url(struct rtsp_context *rtsp_ctx)
{
printf("check_rtsp_url\r\n");
if (rtsp_ctx->rtsp_url[0] == 0) {
printf("No config\r\n");
return 0;
} else if (rtsp_ctx->rtsp_url[0] != 0) {
if (rtsp_ctx->rtsp_url_config) {
printf("rtsp config successful\r\n");
return 0;
} else {
printf("rtsp config fail\r\n");
return -1;
}
}
return 0;
}
uint32_t rtsp_get_timestamp(struct stream_context *stream_ctx, uint32_t current_clock_tick)
{
uint32_t rtsp_clock_hz = stream_ctx->codec->clock_rate;
uint32_t delta_clock_tick;
if (!rtsp_clock_hz) {
RTSP_DBG_ERROR("stream clock_rate not set! Cannot get correct tick!");
return 0;
}
if (stream_ctx->use_rtp_tick_inc) {
stream_ctx->rtp_timestamp += stream_ctx->statistics.rtp_tick_inc;
} else {
delta_clock_tick = current_clock_tick - stream_ctx->old_depend_clock_tick;
stream_ctx->old_depend_clock_tick = current_clock_tick;
stream_ctx->rtp_timestamp += (delta_clock_tick * rtsp_clock_hz) / RTSP_DEPEND_CLK_HZ;
}
return stream_ctx->rtp_timestamp;
}
int rtsp_get_number(int number_base, uint32_t *number_bitmap, _mutex *bitmap_lock)
{
int number = -1;
int i;
rtw_mutex_get(bitmap_lock);
for (i = 0; i < 32; i ++) {
if (!((1 << i)&*number_bitmap)) {
break;
}
}
if (i == 32) {
RTSP_DBG_ERROR("no more bitmap available!");
rtw_mutex_put(bitmap_lock);
return number;
}
*number_bitmap |= 1 << i;
number = number_base + i;
rtw_mutex_put(bitmap_lock);
return number;
}
void rtsp_put_number(int number, int number_base, uint32_t *number_bitmap, _mutex *bitmap_lock)
{
int i = number - number_base;
rtw_mutex_get(bitmap_lock);
*number_bitmap &= ~(1 << i);
rtw_mutex_put(bitmap_lock);
}
int rtsp_parse_stream_media_type(struct codec_info *codec)
{
switch (codec->codec_id) {
case (AV_CODEC_ID_MJPEG):
case (AV_CODEC_ID_H264):
case (AV_CODEC_ID_H265):
case (AV_CODEC_ID_MP4V_ES):
return AVMEDIA_TYPE_VIDEO;
case (AV_CODEC_ID_PCMU):
case (AV_CODEC_ID_PCMA):
case (AV_CODEC_ID_MP4A_LATM):
case (AV_CODEC_ID_OPUS):
return AVMEDIA_TYPE_AUDIO;
default:
return AVMEDIA_TYPE_UNKNOWN;
}
}
int rtsp_connect_ctx_init(struct rtsp_context *rtsp_ctx)
{
struct connect_context *connect_ctx = &rtsp_ctx->connect_ctx;
connect_ctx->server_ip = LwIP_GetIP(rtsp_ctx->interface);
connect_ctx->socket_id = socket(AF_INET, SOCK_STREAM, 0);
if (connect_ctx->socket_id < 0) {
RTSP_DBG_ERROR("rtsp server socket create failed!");
return -EINVAL;
}
return 0;
}
void rtsp_transport_init(struct rtsp_context *rtsp_ctx)
{
struct rtsp_transport *transport = &rtsp_ctx->transport[0];
for (int i = 0; i < RTSP_MAX_STREAM_NUM; i++) {
transport += i;
transport->serverport_low = rtsp_ctx->id * 2 + RTP_SERVER_PORT_BASE;
transport->serverport_high = rtsp_ctx->id * 2 + RTP_SERVER_PORT_BASE + 1;
transport->port_low = rtsp_ctx->id * 2 + RTP_PORT_BASE;
transport->port_high = rtsp_ctx->id * 2 + RTP_PORT_BASE + 1;
transport->clientport_low = rtsp_ctx->id * 2 + RTP_CLIENT_PORT_BASE;
transport->clientport_high = rtsp_ctx->id * 2 + RTP_CLIENT_PORT_BASE + 1;
transport->isRtp = 1;
transport->isTcp = 0;
transport->castMode = UNICAST_UDP_MODE;
transport->ttl = 0;
}
}
void rtsp_session_init(struct rtsp_context *rtsp_ctx)
{
struct rtsp_session *session = &rtsp_ctx->session;
session->id = 0;
session->version = 0;
session->start_time = 0;
session->end_time = 0;
session->name = (uint8_t *)"ameba";
session->user = (uint8_t *)"-";
}
void rtsp_stream_context_init(struct rtsp_context *rtsp_ctx, struct stream_context *stream_ctx)
{
stream_ctx->parent = rtsp_ctx;
stream_ctx->stream_id = -1;
INIT_LIST_HEAD(&stream_ctx->input_queue);
INIT_LIST_HEAD(&stream_ctx->output_queue);
rtw_mutex_init(&stream_ctx->input_lock);
rtw_mutex_init(&stream_ctx->output_lock);
stream_ctx->codec = NULL;
stream_ctx->media_type = AVMEDIA_TYPE_UNKNOWN;
stream_ctx->framerate = 0;
stream_ctx->channel = 0;
stream_ctx->use_rtp_tick_inc = 0;
//initialize rtp statistics
memset(&stream_ctx->statistics, 0, sizeof(struct rtp_statistics));
memset(&stream_ctx->periodic_report, 0, sizeof(struct rtp_periodic_report_s));
stream_ctx->periodic_report.period = 1000; // default report period 1s
stream_ctx->setup_done = 0;
//frame control
memset(&stream_ctx->framecontrol, 0, sizeof(struct rtp_frame_control_s));
stream_ctx->framecontrol.drop_frame_enable = 1;
stream_ctx->framecontrol.rtp_drop_threshold = 600;
stream_ctx->framecontrol.packet_retry = 3;
}
void rtsp_stream_context_clear(struct stream_context *stream_ctx)
{
stream_ctx->parent = NULL;
stream_ctx->stream_id = -1;
INIT_LIST_HEAD(&stream_ctx->input_queue);
INIT_LIST_HEAD(&stream_ctx->output_queue);
rtw_mutex_free(&stream_ctx->input_lock);
rtw_mutex_free(&stream_ctx->output_lock);
stream_ctx->codec = NULL;
stream_ctx->media_type = AVMEDIA_TYPE_UNKNOWN;
stream_ctx->framerate = 0;
//initialize rtp statistics
memset(&stream_ctx->statistics, 0, sizeof(struct rtp_statistics));
stream_ctx->setup_done = 0;
}
void rtp_stream_statistics_sync(struct stream_context *stream_ctx)
{
//video & audio stream should be differentiated
memset(&stream_ctx->statistics, 0, sizeof(struct rtp_statistics));
stream_ctx->statistics.do_start_check = 1;
switch (stream_ctx->media_type) {
case (AVMEDIA_TYPE_VIDEO):
stream_ctx->statistics.rtp_tick_inc = stream_ctx->codec->clock_rate / stream_ctx->framerate;
stream_ctx->statistics.delay_threshold = RTSP_DEPEND_CLK_HZ / stream_ctx->framerate;
break;
case (AVMEDIA_TYPE_AUDIO):
switch (stream_ctx->codec->codec_id) {
case (AV_CODEC_ID_PCMU):
case (AV_CODEC_ID_PCMA):
stream_ctx->statistics.rtp_tick_inc = stream_ctx->tsin_by_fs;
stream_ctx->statistics.delay_threshold = (stream_ctx->statistics.rtp_tick_inc * RTSP_DEPEND_CLK_HZ) / stream_ctx->samplerate;
break;
case (AV_CODEC_ID_MP4A_LATM):
stream_ctx->statistics.rtp_tick_inc = 1024;
stream_ctx->statistics.delay_threshold = (1024 * RTSP_DEPEND_CLK_HZ) / stream_ctx->samplerate;
break;
case (AV_CODEC_ID_OPUS):
stream_ctx->statistics.rtp_tick_inc = stream_ctx->tsin_by_fs;
stream_ctx->statistics.delay_threshold = (stream_ctx->statistics.rtp_tick_inc * RTSP_DEPEND_CLK_HZ) / stream_ctx->samplerate;
break;
}
break;
default:
RTSP_DBG_ERROR("stream media type unsupported!");
return;
}
}
struct rtsp_context *rtsp_context_create(uint8_t nb_streams)
{
int i;
struct rtsp_context *rtsp_ctx = malloc(sizeof(struct rtsp_context));
if (rtsp_ctx == NULL) {
RTSP_DBG_ERROR("allocate rtsp context failed");
return NULL;
}
memset(rtsp_ctx, 0, sizeof(struct rtsp_context));
rtsp_ctx->response = malloc(RTSP_RESPONSE_BUF_SIZE);
if (rtsp_ctx->response == NULL) {
RTSP_DBG_ERROR("allocate rtsp response failed");
free(rtsp_ctx);
return NULL;
}
rtsp_ctx->connect_ctx.remote_ip = malloc(4);
if (rtsp_ctx->connect_ctx.remote_ip == NULL) {
RTSP_DBG_ERROR("allocate remote ip memory failed");
free(rtsp_ctx->response);
free(rtsp_ctx);
return NULL;
}
if (rtsp_ctx_id_bitmap_lock == NULL) {
rtw_mutex_init(&rtsp_ctx_id_bitmap_lock);
}
rtsp_ctx->id = rtsp_get_number(RTSP_CTX_ID_BASE, &rtsp_ctx_id_bitmap, &rtsp_ctx_id_bitmap_lock);
rtsp_ctx->allow_stream = 0;
rtsp_ctx->state = RTSP_INIT;
rtsp_transport_init(rtsp_ctx);
rtsp_session_init(rtsp_ctx);
rtsp_ctx->is_rtsp_start = 0;
rtw_init_sema(&rtsp_ctx->start_rtsp_sema, 0);
rtsp_ctx->is_rtp_start = 0;
rtw_init_sema(&rtsp_ctx->start_rtp_sema, 0);
rtsp_ctx->rtp_service_handle = NULL;
rtsp_ctx->pre_filter_packet = 12;//filter the unstable timestamp
rtw_init_sema(&rtsp_ctx->rtp_input_sema, 0);
rtw_init_sema(&rtsp_ctx->rtp_output_sema, 0);
h264_flag_adjust = 0;//disable h264 time delay
aac_flag_adjust = 0;//disable aac time delay
#if ENABLE_PROXY_SEVER
rtw_init_sema(&rtsp_ctx->start_proxy_connect_sema, 0);
#endif
#ifdef SUPPORT_RTCP
rtsp_ctx->is_rtcp_start = 0;
rtw_init_sema(&rtsp_ctx->start_rtcp_sema, 0);
rtsp_ctx->rtcp_service_handle = NULL;
#endif
rtsp_ctx->nb_streams_setup = 0;
if (nb_streams > RTSP_MAX_STREAM_NUM) {
RTSP_DBG_ERROR("number of streams exceed MAX!");
nb_streams = RTSP_MAX_STREAM_NUM;
}
rtsp_ctx->nb_streams = nb_streams;
rtsp_ctx->stream_ctx = malloc(nb_streams * sizeof(struct stream_context));
if (rtsp_ctx->stream_ctx == NULL) {
RTSP_DBG_ERROR("allocate rtsp stream context failed");
free(rtsp_ctx->connect_ctx.remote_ip);
free(rtsp_ctx->response);
free(rtsp_ctx);
return NULL;
}
for (i = 0; i < nb_streams; i++) {
rtsp_ctx->rtpseq[i] = 0;
rtsp_ctx->stream_ctx[i].index = i;
rtsp_stream_context_init(rtsp_ctx, &rtsp_ctx->stream_ctx[i]);
}
memset(rtsp_ctx->rtsp_url, 0, RTSP_URL_LEN);
rtw_mutex_init(&rtsp_ctx->socket_lock);
return rtsp_ctx;
}
void rtsp_context_free(struct rtsp_context *rtsp_ctx)
{
int i;
for (i = 0; i < rtsp_ctx->nb_streams; i++) {
rtsp_stream_context_clear(&rtsp_ctx->stream_ctx[i]);
}
free(rtsp_ctx->stream_ctx);
free(rtsp_ctx->response);
free(rtsp_ctx->connect_ctx.remote_ip);
rtw_free_sema(&rtsp_ctx->start_rtp_sema);
rtw_free_sema(&rtsp_ctx->rtp_input_sema);
rtw_free_sema(&rtsp_ctx->rtp_output_sema);
rtw_free_sema(&rtsp_ctx->start_rtsp_sema);
#if ENABLE_PROXY_SEVER
rtw_free_sema(&rtsp_ctx->start_proxy_connect_sema);
#endif
#ifdef SUPPORT_RTCP
rtw_free_sema(&rtsp_ctx->start_rtcp_sema);
#endif
rtsp_put_number(rtsp_ctx->id, RTSP_CTX_ID_BASE, &rtsp_ctx_id_bitmap, &rtsp_ctx_id_bitmap_lock);
if (rtsp_ctx_id_bitmap == 0) {
rtw_mutex_free(&rtsp_ctx_id_bitmap_lock);
}
free(rtsp_ctx);
rtw_mutex_free(&rtsp_ctx->socket_lock);
}
uint32_t rtsp_get_request_len(char *request)
{
char *ptr = request;
uint8_t end = 0;
uint32_t len = 0;
while (*ptr != 0) {
len ++;
if ((*ptr == '\r') && (end == 0)) {
end = 1;
} else if ((*ptr == '\n') && (end == 1)) {
end = 2;
} else if ((*ptr == '\r') && (end == 2)) {
end = 3;
} else if ((*ptr == '\n') && (end == 3)) {
break;
} else {
end = 0;
}
ptr++;
}
if (*ptr == 0) {
return len;
}
*(request + len) = '\0';
return len;
}
char *rtsp_parse_header_line(struct rtsp_context *rtsp_ctx, char *header)
{
char *ptr = header;
int len = 0;
int end = 0;
char method[16] = {0};
while ((*ptr != ' ') && (*ptr != '\0')) {
ptr ++;
len ++;
}
if (*ptr == '\0') {
rtsp_ctx->request_type = 0;
return ptr;
}
memcpy(method, header, len);
method[len] = '\0';
if (!strcmp(method, "OPTIONS")) {
rtsp_ctx->request_type = REQUEST_OPTIONS;
//set_rtsp_url(rtsp_ctx,url);
if (rtsp_ctx->rtsp_url[0] != 0) {
char *start = header + 8;
char *search = NULL;
search = strstr(start, (char *)rtsp_ctx->rtsp_url);
//printf("search = %s\r\n",search);
//printf("rtsp_url = %s\r\n",rtsp_ctx->rtsp_url);
if (search != NULL) {
if (search[strlen((char *)rtsp_ctx->rtsp_url)] != ' ') {
rtsp_ctx->rtsp_url_config = 0;
printf("search error = %x\r\n", search[strlen((char *)rtsp_ctx->rtsp_url)]);
} else {
rtsp_ctx->rtsp_url_config = 1;
}
} else {
rtsp_ctx->rtsp_url_config = 0;
}
}
} else if (!strcmp(method, "DESCRIBE")) {
rtsp_ctx->request_type = REQUEST_DESCRIBE;
} else if (!strcmp(method, "SETUP")) {
rtsp_ctx->request_type = REQUEST_SETUP;
rtsp_ctx->setup_stream_index = -1;
char *start, *end, *mov;
start = end = header + 5;
int offset = 0;
char temp[64] = {0};
end++; //skip ' '
start = end;
while ((*end != '\n') && (*end != '\0')) {
while ((*end != '/') && (*end != '\r')) {
end++;
}
offset = end - start;
memcpy(temp, start, offset);
temp[offset] = '\0';
if (!strncmp(temp, "streamid=", 9)) {
start = start + 9;
mov = start;
while ((*mov != ' ') && (*mov != '\r')) {
mov++;
}
offset = mov - start;
memset(temp, 0, 64);
memcpy(temp, start, offset);
temp[offset] = '\0';
int stream_id = atoi(temp);
for (int i = 0; i < rtsp_ctx->nb_streams; i++) {
if (rtsp_ctx->stream_ctx[i].stream_id == stream_id) {
rtsp_ctx->setup_stream_index = i;
break;
}
}
break;
}
end++;
start = end;
}
} else if (!strcmp(method, "TEARDOWN")) {
rtsp_ctx->request_type = REQUEST_TEARDOWN;
} else if (!strcmp(method, "PLAY")) {
rtsp_ctx->request_type = REQUEST_PLAY;
} else if (!strcmp(method, "PAUSE")) {
rtsp_ctx->request_type = REQUEST_PAUSE;
} else if (!strcmp(method, "GET_PARAMETER")) {
rtsp_ctx->request_type = REQUEST_GET_PARAM;
} else {
rtsp_ctx->request_type = 0; //unknown cmd type
}
if (rtsp_ctx->request_type == 0) {
return header;
}
//turn on to parse URL
#if 0
//to do...
#else
while (*ptr != '\0') {
ptr++;
if ((*ptr == '\r') && (end == 0)) {
end = 1;
} else if ((*ptr == '\n') && (end == 1)) {
ptr++;
return ptr;
} else {
end = 0;
}
}
return ptr;
#endif
}
char *rtsp_parse_body_line(struct rtsp_context *rtsp_ctx, char *body)
{
char *start, *end, *mov;
start = end = body;
int offset = 0;
char temp[64] = {0};
//return if we parse to the end of the message body(\r\n\r\n)
if ((*end == '\r') || (*end == '\n')) {
while (*end != '\0') {
end++;
}
return end;
}
//parse field
while ((*end != ' ') && (*end != '\0')) {
end++;
}
offset = end - start;
memcpy(temp, start, offset - 1); //ignore ':'
temp[offset - 1] = '\0';
if (!strcmp(temp, "CSeq")) { //parse CSeq
rtsp_ctx->request_incomplete = 0;
memset(temp, 0, 64);
end++; //skip ' '
start = end;
while ((*end != '\n') && (*end != '\0')) {
while ((*end != ';') && (*end != '\r')) {
end++;
}
offset = end - start;
memcpy(temp, start, offset);
temp[offset] = '\0';
rtsp_ctx->CSeq = atoi(temp);
end++; //skip '\r' or ';'
break;
}
} else if (!strcmp(temp, "Transport")) { //parse Transport (SETUP)
if (rtsp_ctx->setup_stream_index < 0) {//no "stream_id=n" in SETUP
rtsp_ctx->request_type = 0; //unknown cmd type
while (*end != '\0') {
end++;
}
return end;
}
end++;
start = end;
while ((*end != '\n') && (*end != '\0')) {
while ((*end != ';') && (*end != '\r')) {
end++;
}
offset = end - start;
memcpy(temp, start, offset);
temp[offset] = '\0';
if (!strncmp(temp, "RTP/AVP/TCP", 11)) {
rtsp_ctx->transport[rtsp_ctx->setup_stream_index].isRtp = 1;
rtsp_ctx->transport[rtsp_ctx->setup_stream_index].isTcp = 1;//default udp to be lower transport protocol
} else if (!strncmp(temp, "RTP/AVP", 7)) {
rtsp_ctx->transport[rtsp_ctx->setup_stream_index].isRtp = 1;
rtsp_ctx->transport[rtsp_ctx->setup_stream_index].isTcp = 0; //default udp to be lower transport protocol
} else if (!strncmp(temp, "unicast", 7)) {
if (rtsp_ctx->transport[rtsp_ctx->setup_stream_index].isTcp) {
rtsp_ctx->transport[rtsp_ctx->setup_stream_index].castMode = UNICAST_TCP_MODE;
} else {
rtsp_ctx->transport[rtsp_ctx->setup_stream_index].castMode = UNICAST_UDP_MODE;
}
} else if (!strncmp(temp, "multicast", 9)) {
rtsp_ctx->transport[rtsp_ctx->setup_stream_index].castMode = MULTICAST_MODE;
rtsp_ctx->transport[rtsp_ctx->setup_stream_index].isTcp = 0;
} else if (!strncmp(temp, "ttl=", 4)) {
start = start + 4;
mov = start;
while ((*mov != ';') && (*mov != '\r')) {
mov++;
}
offset = mov - start;
memset(temp, 0, 64);
memcpy(temp, start, offset);
temp[offset] = '\0';
rtsp_ctx->transport[rtsp_ctx->setup_stream_index].ttl = atoi(temp);
} else if (!strncmp(temp, "client_port=", 12)) {
start = start + 12;
mov = start;
while (*mov != '-') {
mov++;
}
offset = mov - start;
memset(temp, 0, 64);
memcpy(temp, start, offset);
temp[offset] = '\0';
rtsp_ctx->transport[rtsp_ctx->setup_stream_index].clientport_low = atoi(temp);
mov++;
start = mov;
while ((*mov != ';') && (*mov != '\r')) {
mov++;
}
offset = mov - start;
memset(temp, 0, 64);
memcpy(temp, start, offset);
temp[offset] = '\0';
rtsp_ctx->transport[rtsp_ctx->setup_stream_index].clientport_high = atoi(temp);
} else if (!strncmp(temp, "interleaved=", 12)) {
start = start + 12;
mov = start;
while (*mov != '-') {
mov++;
}
offset = mov - start;
memset(temp, 0, 64);
memcpy(temp, start, offset);
temp[offset] = '\0';
rtsp_ctx->transport[rtsp_ctx->nb_streams_setup].interleaved_low = atoi(temp);
mov++;
start = mov;
while ((*mov != ';') && (*mov != '\r')) {
mov++;
}
offset = mov - start;
memset(temp, 0, 64);
memcpy(temp, start, offset);
temp[offset] = '\0';
rtsp_ctx->transport[rtsp_ctx->nb_streams_setup].interleaved_high = atoi(temp);
}
memset(temp, 0, 64);
end++;
start = end;
}
} else {
while ((*end != '\n') && (*end != '\0')) {
end++;
}
}
if (*end == '\0') {
return end;
} else {
end++;
return end;
}
}
void rtsp_parse_request(struct rtsp_context *rtsp_ctx, char *request)
{
rtsp_ctx->request_incomplete = 1;
if (*request == '\0') {
rtsp_ctx->request_type = 0;
return;
}
char *pstart = request;
char *pbody = NULL;
int len = rtsp_get_request_len(request);
pbody = rtsp_parse_header_line(rtsp_ctx, pstart);
while (*pbody != '\0') {
pbody = rtsp_parse_body_line(rtsp_ctx, pbody);
}
}
uint8_t rtsp_response_ok(struct rtsp_context *rtsp_ctx)
{
return ((!strncmp("RTSP/1.0 200 OK", rtsp_ctx->response, 15)) ? 1 : 0);
}
static void new_session_id(uint32_t *session_id)
{
uint32_t rand = rtw_get_current_time();
if (rand < 10000000) {
rand = rand + 10000000;
}
*session_id = rand;
}
/* -------------------------------- start of sdp ----------------------------------------*/
static uint8_t *data_to_hex(uint8_t *buff, uint8_t *src, int s, int lowercase)
{
int i;
static const char hex_table_uc[16] = { '0', '1', '2', '3',
'4', '5', '6', '7',
'8', '9', 'A', 'B',
'C', 'D', 'E', 'F'
};
static const char hex_table_lc[16] = { '0', '1', '2', '3',
'4', '5', '6', '7',
'8', '9', 'a', 'b',
'c', 'd', 'e', 'f'
};
const char *hex_table = lowercase ? hex_table_lc : hex_table_uc;
for (i = 0; i < s; i++) {
buff[i * 2] = hex_table[src[i] >> 4];
buff[i * 2 + 1] = hex_table[src[i] & 0xF];
}
return buff;
}
static uint8_t *extradata2config(void *extra)
{
uint8_t *config;
if (strlen(extra) > 1024) {
RTSP_DBG_ERROR("too much extra data!");
return NULL;
}
config = malloc(10 + strlen(extra) * 2);
if (config == NULL) {
RTSP_DBG_ERROR("allocate config memory failed");
return NULL;
}
memcpy(config, "; config=", 9);
data_to_hex(config + 9, extra, strlen(extra), 1);
config[9 + strlen(extra) * 2] = 0;
return config;
}
void set_profile_lv_string(char *plid) //called before rtsp_open()
{
plid_string = plid;
return;
}
void set_sps_string(char *sps) //called before rtsp_open()
{
sps_string = sps;
return;
}
void set_pps_string(char *pps) //called before rtsp_open()
{
pps_string = pps;
return;
}
#if !defined(CONFIG_PLATFORM_8721D)
extern char base64_sps[128];
extern char base64_pps[64];
extern char plid[4];
#endif
static void create_sdp_a_string(char *string, struct stream_context *s, void *extra)
{
char spspps_string[256];
uint8_t *config = NULL;
if (extra != NULL) {
config = extradata2config(extra);
}
switch (s->codec->codec_id) {
case (AV_CODEC_ID_MJPEG):
sprintf(string, "a=rtpmap:%d JPEG/%d" CRLF \
"a=control:streamid=%d" CRLF \
"a=framerate:%d" CRLF \
, s->codec->pt, s->codec->clock_rate, s->stream_id, s->framerate);
break;
#if !defined(CONFIG_PLATFORM_8721D)
case (AV_CODEC_ID_H264):
if (base64_sps[0] != 0) {
set_profile_lv_string(plid);
set_sps_string(base64_sps);
set_pps_string(base64_pps);
}
if (plid_string != NULL) {
strcat(spspps_string, ";profile-level-id=");
strcat(spspps_string, plid_string);
}
if (sps_string != NULL) {
strcat(spspps_string, ";sprop-parameter-sets=");
strcat(spspps_string, sps_string);
if (pps_string != NULL) {
strcat(spspps_string, ",");
strcat(spspps_string, pps_string);
}
}
sprintf(string, "a=rtpmap:%d H264/%d" CRLF \
"a=control:streamid=%d" CRLF \
"a=fmtp:%d packetization-mode=0%s%s" CRLF \
, (s->codec->pt + s->stream_id), s->codec->clock_rate, s->stream_id, (s->codec->pt + s->stream_id), config ? (char *)config : "", spspps_string);
break;
case (AV_CODEC_ID_H265):
if (base64_sps[0] != 0) {
set_profile_lv_string(plid);
set_sps_string(base64_sps);
set_pps_string(base64_pps);
}
if (plid_string != NULL) {
strcat(spspps_string, ";profile-level-id=");
strcat(spspps_string, plid_string);
}
if (sps_string != NULL) {
strcat(spspps_string, ";sprop-parameter-sets=");
strcat(spspps_string, sps_string);
if (pps_string != NULL) {
strcat(spspps_string, ",");
strcat(spspps_string, pps_string);
}
}
sprintf(string, "a=rtpmap:%d H265/%d" CRLF \
"a=control:streamid=%d" CRLF \
"a=fmtp:%d packetization-mode=0%s%s" CRLF \
, (s->codec->pt + s->stream_id), s->codec->clock_rate, s->stream_id, (s->codec->pt + s->stream_id), config ? (char *)config : "", spspps_string);
break;
#endif
case (AV_CODEC_ID_PCMU):
sprintf(string, "a=rtpmap:%d PCMU/%d" CRLF \
"a=ptime:20" CRLF \
"a=control:streamid=%d" CRLF \
, s->codec->pt, s->samplerate, s->stream_id);
break;
case (AV_CODEC_ID_PCMA):
sprintf(string, "a=rtpmap:%d PCMA/%d" CRLF \
"a=ptime:20" CRLF \
"a=control:streamid=%d" CRLF \
, s->codec->pt, s->samplerate, s->stream_id);
break;
case (AV_CODEC_ID_MP4A_LATM):
sprintf(string, "a=rtpmap:%d mpeg4-generic/%d/%d" CRLF \
"a=fmtp:%d streamtype=5; profile-level-id=15; mode=AAC-hbr%s; sizeLength=13; indexLength=3; indexDeltaLength=3; constantDuration=1024; Profile=1" CRLF \
"a=control:streamid=%d" CRLF \
/* "a=type:broadcast" CRLF \*/
, (s->codec->pt + s->stream_id), s->samplerate, s->channel, (s->codec->pt + s->stream_id), config ? (char *)config : "", s->stream_id);
break;
case (AV_CODEC_ID_MP4V_ES):
sprintf(string, "a=rtpmap:%d MPEG4-ES/%d" CRLF \
"a=control:streamid=%d" CRLF \
"a=fmtp:%d profile-level-id=1%s" CRLF \
, (s->codec->pt + s->stream_id), s->codec->clock_rate, s->stream_id, (s->codec->pt + s->stream_id), config ? (char *)config : "");
break;
case (AV_CODEC_ID_OPUS):
sprintf(string, "a=rtpmap:%d opus/%d/%d" CRLF \
"a=fmtp:%d maxplaybackrate=%d; stereo=%d; useinbandfec=1; usedtx=0" CRLF \
"a=ptime:20" CRLF \
"a=maxptime:60" CRLF \
"a=control:streamid=%d" CRLF \
, (s->codec->pt + s->stream_id), s->codec->clock_rate, s->codec->audio_channels, (s->codec->pt + s->stream_id), s->samplerate, s->channel, s->stream_id);
//printf("OPUS\r\n%s\r\n",string);
/*
16000 Hz clock rate, maximum packet size of 40 ms,
recommended packet size of 40 ms, maximum average bitrate of 20000
bit/s, prefers to receive stereo but only plans to send mono, FEC is
desired, DTX is not desired
m=audio 54312 RTP/AVP 101
a=rtpmap:101 opus/48000/2
a=fmtp:101 maxplaybackrate=16000; sprop-maxcapturerate=16000;
maxaveragebitrate=20000; stereo=1; useinbandfec=1; usedtx=0
a=ptime:40
a=maxptime:40
*/
break;
default:
break;
}
free(config);
}
static int get_frequency_index(int samplerate)
{
uint32_t freq_idx_map[] = {96000, 88200, 64000, 48000, 44100, 32000, 24000, 22050, 16000, 12000, 11025, 8000, 7350};
for (int i = 0; i < sizeof(freq_idx_map) / sizeof(freq_idx_map[0]); i++) {
if (samplerate == freq_idx_map[i]) {
return i;
}
}
return 0xf; // 15: frequency is written explictly
}
void rtsp_create_sdp(struct rtsp_context *rtsp_ctx, char *sdp_buf, int max_len)
{
int i;
struct stream_context *stream;
char attr_buf[MAX_SDP_SIZE];
//sdp session level
uint8_t *unicast_addr, *connection_addr;
uint8_t *extra = NULL;
uint8_t nettype[] = "IN";
uint8_t addrtype[] = "IP4";
unicast_addr = rtsp_ctx->connect_ctx.server_ip;
connection_addr = rtsp_ctx->connect_ctx.remote_ip;
/* fill Protocol Version -- only have Version 0 for now*/
sprintf(sdp_buf, "v=0" CRLF);
sdp_fill_o_field(sdp_buf, max_len, rtsp_ctx->session.user, rtsp_ctx->session.id, rtsp_ctx->session.version, nettype, addrtype, unicast_addr);
sdp_fill_s_field(sdp_buf, max_len, rtsp_ctx->session.name);
sdp_fill_c_field(sdp_buf, max_len, nettype, addrtype, connection_addr, /*rtsp_ctx->transport.ttl*/0);//should change ttl if not unicast
sdp_fill_t_field(sdp_buf, max_len, rtsp_ctx->session.start_time, rtsp_ctx->session.end_time);
//sdp media level
for (i = 0; i < rtsp_ctx->nb_streams; i++) {
stream = &rtsp_ctx->stream_ctx[i];
if (stream->stream_id >= 0) {
if (stream->codec->pt >= RTP_PT_DYN_BASE) {
sdp_fill_m_field(sdp_buf, max_len, stream->media_type, 0, (stream->codec->pt + stream->stream_id));
} else {
sdp_fill_m_field(sdp_buf, max_len, stream->media_type, 0, stream->codec->pt);
}
if (stream->codec->codec_id == AV_CODEC_ID_MP4A_LATM) {
uint16_t config;
int freq_idx = get_frequency_index(stream->samplerate);
config = (0x2 << 11) | (freq_idx << 7) | (stream->channel << 3) | 0x0;
extra = malloc(3);
memset(extra, 0, 3);
//form AAC generic config: object type (5 bit) frequency index (4 bit) channel config (4 bit) + 3 bit zero
/* 44.1khz LLC LC stereo -- config = 0x1210*/
/* 16khz LLC LC stereo -- config = 0x1410*/
if ((freq_idx <= 12) && (stream->channel != 0)) {
*extra = (config >> 8) & 0xFF;
*(extra + 1) = config & 0xFF;
} else {
*extra = 0x14;
*(extra + 1) = 0x10;
}
*(extra + 2) = 0x00;// '\0'
}
memset(attr_buf, 0, MAX_SDP_SIZE);
create_sdp_a_string(attr_buf, stream, extra);
if (extra != NULL) {
free(extra);
extra = NULL;
}
sdp_strcat(sdp_buf, max_len, attr_buf);
}
}
}
/* -------------------------------- END of sdp ------------------------------------------*/
#if ENABLE_PROXY_SEVER
void rtsp_cmd_register(struct rtsp_context *rtsp_ctx, char *request, char *proxy_suffix)
{
memset(request, 0, RTSP_REQUEST_BUF_SIZE);
sprintf(request, "REGISTER rtsp://%d.%d.%d.%d:%d/ RTSP/1.0" CRLF \
"CSeq: %d" CRLF \
"Transport: reuse_connection;" \
"preferred_delivery_protocol=udp;" \
"proxy_url_suffix=%s" CRLF \
CRLF, (uint8_t)rtsp_ctx->connect_ctx.server_ip[0], (uint8_t)rtsp_ctx->connect_ctx.server_ip[1], (uint8_t)rtsp_ctx->connect_ctx.server_ip[2],
(uint8_t)rtsp_ctx->connect_ctx.server_ip[3], rtsp_ctx->connect_ctx.server_port, ++rtsp_ctx->CSeq, proxy_suffix);
}
void rtsp_cmd_deregister(struct rtsp_context *rtsp_ctx, char *request, char *proxy_suffix)
{
memset(request, 0, RTSP_REQUEST_BUF_SIZE);
sprintf(request, "DEREGISTER rtsp://%d.%d.%d.%d:%d/ RTSP/1.0" CRLF \
"CSeq: %d" CRLF \
"Transport: proxy_url_suffix=%s" CRLF \
CRLF, (uint8_t)rtsp_ctx->connect_ctx.server_ip[0], (uint8_t)rtsp_ctx->connect_ctx.server_ip[1], (uint8_t)rtsp_ctx->connect_ctx.server_ip[2],
(uint8_t)rtsp_ctx->connect_ctx.server_ip[3], rtsp_ctx->connect_ctx.server_port, ++rtsp_ctx->CSeq, proxy_suffix);
}
#endif
void rtsp_cmd_options(struct rtsp_context *rtsp_ctx)
{
memset(rtsp_ctx->response, 0, RTSP_RESPONSE_BUF_SIZE);
sprintf(rtsp_ctx->response, "RTSP/1.0 200 OK" CRLF \
"CSeq: %d" CRLF \
"Public: OPTIONS, DESCRIBE, SETUP, TEARDOWN, PLAY, PAUSE, GET_PARAMETER" CRLF \
CRLF, rtsp_ctx->CSeq);
}
void rtsp_cmd_getparm(struct rtsp_context *rtsp_ctx)
{
memset(rtsp_ctx->response, 0, RTSP_RESPONSE_BUF_SIZE);
sprintf(rtsp_ctx->response, "RTSP/1.0 200 OK" CRLF \
"CSeq: %d" CRLF \
"Session: %d;timeout=60" CRLF \
CRLF, rtsp_ctx->CSeq, rtsp_ctx->session.id);
}
void rtsp_cmd_describe(struct rtsp_context *rtsp_ctx)
{
memset(rtsp_ctx->response, 0, RTSP_RESPONSE_BUF_SIZE);
char sdp_buffer[MAX_SDP_SIZE] = {0};
int sdp_content_len = 0;
new_session_id(&rtsp_ctx->session.id);
rtsp_create_sdp(rtsp_ctx, sdp_buffer, MAX_SDP_SIZE - 1);
sdp_content_len = strlen(sdp_buffer);
sprintf(rtsp_ctx->response, "RTSP/1.0 200 OK" CRLF \
"CSeq: %d" CRLF \
"Content-Type: application/sdp" CRLF \
"Content-Base: rtsp://%d.%d.%d.%d:%d" CRLF \
"Content-Length: %d" CRLF \
CRLF \
"%s", rtsp_ctx->CSeq, (uint8_t)rtsp_ctx->connect_ctx.server_ip[0], (uint8_t)rtsp_ctx->connect_ctx.server_ip[1], (uint8_t)rtsp_ctx->connect_ctx.server_ip[2],
(uint8_t)rtsp_ctx->connect_ctx.server_ip[3], rtsp_ctx->connect_ctx.server_port, sdp_content_len, sdp_buffer);
}
void rtsp_cmd_setup(struct rtsp_context *rtsp_ctx)
{
memset(rtsp_ctx->response, 0, RTSP_RESPONSE_BUF_SIZE);
const char *castmode;
switch (rtsp_ctx->transport[rtsp_ctx->nb_streams_setup].castMode) {
case (UNICAST_TCP_MODE):
case (UNICAST_UDP_MODE):
castmode = "unicast";
break;
case (MULTICAST_MODE):
castmode = "multicast";
break;
default:
castmode = "unknown";
}
if (rtsp_ctx->transport[rtsp_ctx->nb_streams_setup].castMode == UNICAST_UDP_MODE) {
sprintf(rtsp_ctx->response, "RTSP/1.0 200 OK" CRLF \
"CSeq: %d" CRLF \
"Session: %d;timeout=60" CRLF \
"Transport: RTP/AVP/UDP;%s;client_port=%d-%d;server_port=%d-%d" CRLF \
CRLF, rtsp_ctx->CSeq, rtsp_ctx->session.id, castmode, rtsp_ctx->transport[rtsp_ctx->nb_streams_setup].clientport_low,
rtsp_ctx->transport[rtsp_ctx->nb_streams_setup].clientport_high, rtsp_ctx->transport[rtsp_ctx->nb_streams_setup].serverport_low,
rtsp_ctx->transport[rtsp_ctx->nb_streams_setup].serverport_high);
} else if (rtsp_ctx->transport[rtsp_ctx->nb_streams_setup].castMode == UNICAST_TCP_MODE) {
sprintf(rtsp_ctx->response, "RTSP/1.0 200 OK" CRLF \
"CSeq: %d" CRLF \
"Session: %d" CRLF \
"Transport: RTP/AVP/TCP;%s;interleaved=%d-%d" CRLF \
CRLF, rtsp_ctx->CSeq, rtsp_ctx->session.id, castmode, rtsp_ctx->transport[rtsp_ctx->nb_streams_setup].interleaved_low,
rtsp_ctx->transport[rtsp_ctx->nb_streams_setup].interleaved_high);
} else if (rtsp_ctx->transport[rtsp_ctx->nb_streams_setup].castMode == MULTICAST_MODE) {
sprintf(rtsp_ctx->response, "RTSP/1.0 200 OK" CRLF \
"CSeq: %d" CRLF \
"Session: %d" CRLF \
"Transport: RTP/AVP/UDP;%s;port=%d-%d;ttl=%d" CRLF \
CRLF, rtsp_ctx->CSeq, rtsp_ctx->session.id, castmode, rtsp_ctx->transport[rtsp_ctx->nb_streams_setup].port_low,
rtsp_ctx->transport[rtsp_ctx->nb_streams_setup].port_high, rtsp_ctx->transport[rtsp_ctx->nb_streams_setup].ttl);
}
}
void rtsp_cmd_play(struct rtsp_context *rtsp_ctx)
{
memset(rtsp_ctx->response, 0, RTSP_RESPONSE_BUF_SIZE);
sprintf(rtsp_ctx->response, "RTSP/1.0 200 OK" CRLF \
"CSeq: %d" CRLF \
"Session: %d" CRLF \
CRLF, rtsp_ctx->CSeq, rtsp_ctx->session.id);
}
void rtsp_cmd_pause(struct rtsp_context *rtsp_ctx)
{
memset(rtsp_ctx->response, 0, RTSP_RESPONSE_BUF_SIZE);
sprintf(rtsp_ctx->response, "RTSP/1.0 200 OK" CRLF \
"CSeq: %d" CRLF \
"Session: %d" CRLF \
CRLF, rtsp_ctx->CSeq, rtsp_ctx->session.id);
}
void rtsp_cmd_teardown(struct rtsp_context *rtsp_ctx)
{
memset(rtsp_ctx->response, 0, RTSP_RESPONSE_BUF_SIZE);
sprintf(rtsp_ctx->response, "RTSP/1.0 200 OK" CRLF \
"CSeq: %d" CRLF \
"Session: %d" CRLF \
CRLF, rtsp_ctx->CSeq, rtsp_ctx->session.id);
}
void rtsp_cmd_error(struct rtsp_context *rtsp_ctx)
{
memset(rtsp_ctx->response, 0, RTSP_RESPONSE_BUF_SIZE);
sprintf(rtsp_ctx->response, "RTSP/1.0 400" CRLF \
"CSeq: %d" CRLF \
CRLF, rtsp_ctx->CSeq);
}
void rtsp_cmd_unsupported_transport(struct rtsp_context *rtsp_ctx)
{
memset(rtsp_ctx->response, 0, RTSP_RESPONSE_BUF_SIZE);
sprintf(rtsp_ctx->response, "RTSP/1.0 461" CRLF \
"CSeq: %d" CRLF \
CRLF, rtsp_ctx->CSeq);
}
void rtsp_cmd_destination_unreachable(struct rtsp_context *rtsp_ctx)
{
memset(rtsp_ctx->response, 0, RTSP_RESPONSE_BUF_SIZE);
sprintf(rtsp_ctx->response, "RTSP/1.0 462" CRLF \
"CSeq: %d" CRLF \
CRLF, rtsp_ctx->CSeq);
}
void rtsp_enable_stream(struct rtsp_context *rtsp_ctx)
{
rtsp_ctx->allow_stream = 1;
}
void rtsp_disable_stream(struct rtsp_context *rtsp_ctx)
{
rtsp_ctx->allow_stream = 0;
}
int rtsp_is_stream_enabled(struct rtsp_context *rtsp_ctx)
{
return rtsp_ctx->allow_stream;
}
void rtsp_enable_service(struct rtsp_context *rtsp_ctx)
{
rtsp_ctx->is_rtsp_start = 1;
}
void rtsp_disable_service(struct rtsp_context *rtsp_ctx)
{
rtsp_ctx->is_rtsp_start = 0;
}
int rtsp_is_service_enabled(struct rtsp_context *rtsp_ctx)
{
return rtsp_ctx->is_rtsp_start;
}
void rtsp_close_service(struct rtsp_context *rtsp_ctx)
{
rtsp_disable_stream(rtsp_ctx);
rtsp_disable_service(rtsp_ctx);
}
void show_result_statistics(struct rtsp_context *rtsp_ctx)
{
int i = 0;
struct stream_context *stream = NULL;
for (i = 0; i < rtsp_ctx->nb_streams_setup; i++) {
stream = &rtsp_ctx->stream_ctx[i];
if ((stream->statistics.sent_packet == 0) && (stream->statistics.drop_packet == 0)) {
printf("\n\rch = %d sf:%d df:%d l:0%%", i, stream->statistics.sent_packet, stream->statistics.drop_packet);
} else
printf("\n\rch = %d sf:%d df:%d l:%d%%", i, stream->statistics.sent_packet, stream->statistics.drop_packet, \
(stream->statistics.drop_packet * 100) / (stream->statistics.sent_packet + stream->statistics.drop_packet));
}
printf("\n\r");
}
#if ENABLE_PROXY_SEVER
uint8_t send_deregister_command(struct rtsp_context *rtsp_ctx)
{
uint8_t proxy_suffix[256];
memset(proxy_suffix, 0, 256);
sprintf(proxy_suffix, "%s_%d", AmebaCam_device_name, rtsp_ctx->id);
uint8_t *request = malloc(RTSP_REQUEST_BUF_SIZE);
int ok;
while (1) {
printf("[Proxy] DEREGISTER %s\n\r", proxy_suffix);
rtsp_cmd_deregister(rtsp_ctx, request, proxy_suffix);
RTSP_DBG_INFO("%s\n\r", request);
rtw_mutex_get(&rtsp_ctx->socket_lock);
ok = write(rtsp_ctx->proxy_socket, request, strlen(request));
rtw_mutex_put(&rtsp_ctx->socket_lock);
if (ok <= 0) {
RTSP_DBG_ERROR("send DEREGISTER command failed!\n\r");
goto error_exit;
}
memset(rtsp_ctx->response, 0, RTSP_RESPONSE_BUF_SIZE);
rtw_mutex_get(&rtsp_ctx->socket_lock);
read(rtsp_ctx->proxy_socket, rtsp_ctx->response, RTSP_RESPONSE_BUF_SIZE);
rtw_mutex_put(&rtsp_ctx->socket_lock);
ok = rtsp_response_ok(rtsp_ctx);
if (ok) {
break;
} else {
RTSP_DBG_ERROR("[Proxy] DEREGISTER command response: %s\n\r", rtsp_ctx->response);
}
}
free(request);
return 1;
error_exit:
close(rtsp_ctx->proxy_socket);
free(request);
return 0;
}
uint8_t send_register_command(struct rtsp_context *rtsp_ctx)
{
uint8_t proxy_suffix[256];
memset(proxy_suffix, 0, 256);
sprintf(proxy_suffix, "%s_%d", AmebaCam_device_name, rtsp_ctx->id);
uint8_t *request = malloc(RTSP_REQUEST_BUF_SIZE);
int ok;
if (request == NULL) {
RTSP_DBG_ERROR("allocate request buffer failed\n\r");
return 0;
}
while (1) {
printf("[Proxy] REGISTER %s\n\r", proxy_suffix);
rtsp_cmd_register(rtsp_ctx, request, proxy_suffix);
RTSP_DBG_INFO("%s\n\r", request);
rtw_mutex_get(&rtsp_ctx->socket_lock);
ok = write(rtsp_ctx->proxy_socket, request, strlen(request));
rtw_mutex_put(&rtsp_ctx->socket_lock);
if (ok <= 0) {
RTSP_DBG_ERROR("send REGISTER command failed!\n\r");
goto error_exit;
}
memset(rtsp_ctx->response, 0, RTSP_RESPONSE_BUF_SIZE);
rtw_mutex_get(&rtsp_ctx->socket_lock);
read(rtsp_ctx->proxy_socket, rtsp_ctx->response, RTSP_RESPONSE_BUF_SIZE);
rtw_mutex_put(&rtsp_ctx->socket_lock);
ok = rtsp_response_ok(rtsp_ctx);
if (ok) {
break;
}
ok = send_deregister_command(rtsp_ctx);
if (!ok) {
goto error_exit;
}
}
if (request) {
free(request);
}
return 1;
error_exit:
close(rtsp_ctx->proxy_socket);
if (request) {
free(request);
}
return 0;
}
#endif
#if ENABLE_PROXY_SEVER
uint8_t connecting_proxy = 0;
void proxy_connect_thread(void *param)
{
struct rtsp_context *rtsp_ctx = (struct rtsp_context *) param;
// Proxy Server setting
struct sockaddr_in proxy_addr;
int proxy_addr_len = sizeof(proxy_addr);
rtsp_ctx->proxy_port = PROXY_SERVER_PORT;
memset(&proxy_addr, 0, proxy_addr_len);
proxy_addr.sin_family = AF_INET;
proxy_addr.sin_port = htons(rtsp_ctx->proxy_port);
proxy_addr.sin_addr.s_addr = inet_addr(PROXY_SERVER_IP);
int ok = 0;
while (rtsp_is_service_enabled(rtsp_ctx)) {
if (rtw_down_timeout_sema(&rtsp_ctx->start_proxy_connect_sema, 1000)) {
printf("proxy_connect_thread_running\n\r");
connecting_proxy = 1;
do {
// connect to proxy server
rtsp_ctx->proxy_socket = socket(AF_INET, SOCK_STREAM, 0);
if (rtsp_ctx->proxy_socket < 0) {
RTSP_DBG_ERROR("rtsp server proxy socket create failed!\n\r");
break;
}
if (connect(rtsp_ctx->proxy_socket, (struct sockaddr *)&proxy_addr, proxy_addr_len) < 0) {
//RTSP_DBG_ERROR("\n\r[ERROR] %s: Connect to Proxy Server failed\n\r",__func__);
close(rtsp_ctx->proxy_socket);
break;
}
printf("[Proxy] Connect to Proxy Server successfully\n\r");
ok = send_register_command(rtsp_ctx);
if (!ok) {
RTSP_DBG_ERROR("send register command to Proxy Server fail\n\r");
close(rtsp_ctx->proxy_socket);
break;
}
rtsp_ctx->is_connected_to_proxy = 1;
} while (0);
connecting_proxy = 0;
}
}
vTaskDelete(NULL);
}
#endif
#define WLAN0_NAME "wlan0"
void rtsp_start_service(struct rtsp_context *rtsp_ctx)
{
char *request, *request_concat_buf;
int mode = 0;
rtw_wifi_setting_t setting = {0};
struct sockaddr_in server_addr, client_addr;
socklen_t client_addr_len = sizeof(struct sockaddr_in);
fd_set server_read_fds, client_read_fds;
struct timeval s_listen_timeout, c_listen_timeout;
int ok;
int opt = 1;
#ifdef KEEPALIVE_TIMEOUT_ENABLE
uint32_t keep_alive_time = 0;
#endif
uint8_t enter_rtsp_request_loop = 0;
request = malloc(RTSP_REQUEST_BUF_SIZE);
request_concat_buf = malloc(RTSP_REQUEST_BUF_SIZE);
if (request == NULL || request_concat_buf == NULL) {
RTSP_DBG_ERROR("allocate request buffer failed");
return;
}
Redo:
while (rtsp_is_service_enabled(rtsp_ctx)) {
vTaskDelay(1);
if (!rtsp_is_service_enabled(rtsp_ctx)) {
RTSP_DBG_ERROR("rtsp service disabled while waiting for wifi Tx/Rx ready...");
return;
}
if (rtsp_ctx->interface <= 1) {
if (wifi_is_running(0) > 0) {
wifi_get_setting(WLAN0_IDX, &setting);
mode = setting.mode;
if (((wifi_get_join_status() == RTW_JOINSTATUS_SUCCESS) && (*(u32 *)LwIP_GetIP(0) != IP_ADDR_INVALID)) && (mode == RTW_MODE_STA)) {
printf("connect successful sta mode\r\n");
break;
}
if (wifi_is_running(WLAN0_IDX) && (mode == RTW_MODE_AP)) {
printf("connect successful ap mode\r\n");
break;
}
}
} else {
//Check the dhcp wifi connection
unsigned char *ip;
ip = LwIP_GetIP(rtsp_ctx->interface);
if (ip[0] == 0 && ip[1] == 0 && ip[2] == 0 && ip[3] == 0) {
continue;
} else if (ip[0] == 192 && ip[1] == 168 && ip[2] == 1 && ip[3] == 80) {
continue;
} else {
printf("ip = %d.%d.%d.%d\r\n", ip[0], ip[1], ip[2], ip[3]);
break;
}
}
}
rtw_interface_t interface = (mode == RTW_MODE_STA) ? RTW_STA_INTERFACE : RTW_AP_INTERFACE;
if (rtsp_connect_ctx_init(rtsp_ctx) < 0) {
RTSP_DBG_ERROR("rtsp connect context init failed");
return;
}
uint8_t *mac = (uint8_t *) LwIP_GetMAC(rtsp_ctx->interface);
memset(AmebaCam_device_name, 0, 256);
sprintf(AmebaCam_device_name, "Ameba_%02x%02x%02x", mac[3], mac[4], mac[5]);
#if ENABLE_PROXY_SEVER
// Proxy Server setting
struct sockaddr_in proxy_addr;
int proxy_addr_len = sizeof(proxy_addr);
rtsp_ctx->proxy_port = PROXY_SERVER_PORT;
memset(&proxy_addr, 0, proxy_addr_len);
proxy_addr.sin_family = AF_INET;
proxy_addr.sin_port = htons(rtsp_ctx->proxy_port);
proxy_addr.sin_addr.s_addr = inet_addr(PROXY_SERVER_IP);
if (xTaskCreate(proxy_connect_thread, ((const signed char *)"rtsp_proxy"), 512, (void *)rtsp_ctx, RTSP_SERVICE_PRIORITY, NULL) != pdPASS) {
RTSP_DBG_ERROR("rtp_start_service: Create Task Error\n");
goto error;
}
#endif
// Ameba Local RTSP server setting
if ((setsockopt(rtsp_ctx->connect_ctx.socket_id, SOL_SOCKET, SO_REUSEADDR, (const char *)&opt, sizeof(opt))) < 0) {
RTSP_DBG_ERROR("Error on setting socket option");
goto error;
}
server_addr.sin_family = AF_INET;
server_addr.sin_addr.s_addr = *(uint32_t *)(rtsp_ctx->connect_ctx.server_ip)/*_htonl(INADDR_ANY)*/;
server_addr.sin_port = _htons(rtsp_ctx->connect_ctx.server_port);
if (bind(rtsp_ctx->connect_ctx.socket_id, (struct sockaddr *)&server_addr, sizeof(server_addr)) < 0) {
RTSP_DBG_ERROR("Cannot bind stream socket");
goto error;
}
listen(rtsp_ctx->connect_ctx.socket_id, 1);
printf("\n\rrtsp stream enabled");
//enter service loop
while (rtsp_is_stream_enabled(rtsp_ctx)) {
enter_rtsp_request_loop = 0;
FD_ZERO(&server_read_fds);
s_listen_timeout.tv_sec = 1;
s_listen_timeout.tv_usec = 0;
FD_SET(rtsp_ctx->connect_ctx.socket_id, &server_read_fds);
if (select(RTSP_SELECT_SOCK, &server_read_fds, NULL, NULL, &s_listen_timeout)) {
rtsp_ctx->client_socket = accept(rtsp_ctx->connect_ctx.socket_id, (struct sockaddr *)&client_addr, &client_addr_len);
if (rtsp_ctx->client_socket < 0) {
RTSP_DBG_ERROR("rtsp_ctx->client_socket accept error");
close(rtsp_ctx->client_socket);
continue;
}
*(rtsp_ctx->connect_ctx.remote_ip + 3) = (unsigned char)(client_addr.sin_addr.s_addr >> 24);
*(rtsp_ctx->connect_ctx.remote_ip + 2) = (unsigned char)(client_addr.sin_addr.s_addr >> 16);
*(rtsp_ctx->connect_ctx.remote_ip + 1) = (unsigned char)(client_addr.sin_addr.s_addr >> 8);
*(rtsp_ctx->connect_ctx.remote_ip) = (unsigned char)(client_addr.sin_addr.s_addr);
#if ENABLE_PROXY_SEVER
if (client_addr.sin_addr.s_addr == proxy_addr.sin_addr.s_addr) {
rtsp_ctx->is_connected_to_proxy = 1;
printf("\n\r[Proxy] Connect to Proxy Server %d.%d.%d.%d\n\r", (uint8_t)rtsp_ctx->connect_ctx.remote_ip[0], (uint8_t)rtsp_ctx->connect_ctx.remote_ip[1],
(uint8_t)rtsp_ctx->connect_ctx.remote_ip[2], (uint8_t)rtsp_ctx->connect_ctx.remote_ip[3]);
} else
#endif
{
rtsp_ctx->is_connected_to_proxy = 0;
printf("\n\r[Local] Connected by %d.%d.%d.%d\n\r", (uint8_t)rtsp_ctx->connect_ctx.remote_ip[0], (uint8_t)rtsp_ctx->connect_ctx.remote_ip[1],
(uint8_t)rtsp_ctx->connect_ctx.remote_ip[2], (uint8_t)rtsp_ctx->connect_ctx.remote_ip[3]);
}
enter_rtsp_request_loop = 1;
}
#if ENABLE_PROXY_SEVER
else {
if (rtsp_ctx->is_connected_to_proxy == 1) {
rtsp_ctx->client_socket = rtsp_ctx->proxy_socket;
*(rtsp_ctx->connect_ctx.remote_ip + 3) = (unsigned char)(proxy_addr.sin_addr.s_addr >> 24);
*(rtsp_ctx->connect_ctx.remote_ip + 2) = (unsigned char)(proxy_addr.sin_addr.s_addr >> 16);
*(rtsp_ctx->connect_ctx.remote_ip + 1) = (unsigned char)(proxy_addr.sin_addr.s_addr >> 8);
*(rtsp_ctx->connect_ctx.remote_ip) = (unsigned char)(proxy_addr.sin_addr.s_addr);
enter_rtsp_request_loop = 1;
} else if (connecting_proxy == 0) {
rtw_up_sema(&rtsp_ctx->start_proxy_connect_sema);
} else {
// rtsp_ctx->is_connected_to_proxy = 0, connecting_proxy = 1
// do nothing, proxy_connect_thread is working
}
}
#endif
if (enter_rtsp_request_loop) {
printf("[%s] Enter rtsp request_loop\n\r", (rtsp_ctx->is_connected_to_proxy == 1) ? "Proxy" : "Local");
memset(request_concat_buf, 0, RTSP_REQUEST_BUF_SIZE);
uint32_t concat_buf_len = 0;
while (rtsp_is_stream_enabled(rtsp_ctx)) {
#if ENABLE_PROXY_SEVER
if (rtsp_ctx->is_connected_to_proxy == 1) {
// check every time before processing new request from proxy server
FD_ZERO(&server_read_fds);
s_listen_timeout.tv_sec = 1;
s_listen_timeout.tv_usec = 0;
FD_SET(rtsp_ctx->connect_ctx.socket_id, &server_read_fds);
if (select(RTSP_SELECT_SOCK, &server_read_fds, NULL, NULL, &s_listen_timeout)) {
int lan_client_socket = accept(rtsp_ctx->connect_ctx.socket_id, (struct sockaddr *)&client_addr, &client_addr_len);
if (lan_client_socket >= 0) {
*(rtsp_ctx->connect_ctx.remote_ip + 3) = (unsigned char)(client_addr.sin_addr.s_addr >> 24);
*(rtsp_ctx->connect_ctx.remote_ip + 2) = (unsigned char)(client_addr.sin_addr.s_addr >> 16);
*(rtsp_ctx->connect_ctx.remote_ip + 1) = (unsigned char)(client_addr.sin_addr.s_addr >> 8);
*(rtsp_ctx->connect_ctx.remote_ip) = (unsigned char)(client_addr.sin_addr.s_addr);
// disconnect proxy connection
printf("[Proxy] LAN connection established, disconnect proxy\n\r");
//send_deregister_command(rtsp_ctx);
close(rtsp_ctx->proxy_socket);
printf("[Local] Connected by %d.%d.%d.%d\n\r", (uint8_t)rtsp_ctx->connect_ctx.remote_ip[0], (uint8_t)rtsp_ctx->connect_ctx.remote_ip[1],
(uint8_t)rtsp_ctx->connect_ctx.remote_ip[2], (uint8_t)rtsp_ctx->connect_ctx.remote_ip[3]);
rtsp_ctx->is_connected_to_proxy = 0;
rtsp_ctx->state = RTSP_INIT;
keep_alive_time = 0;
rtsp_ctx->nb_streams_setup = 0;
rtsp_ctx->client_socket = lan_client_socket;
} else {
RTSP_DBG_ERROR("RTSP client socket accept error\n\r");
close(lan_client_socket);
}
}
}
#endif
FD_ZERO(&client_read_fds);
c_listen_timeout.tv_sec = 0;
c_listen_timeout.tv_usec = 1000;//10000;
FD_SET(rtsp_ctx->client_socket, &client_read_fds);
#ifdef KEEPALIVE_TIMEOUT_ENABLE
if (keep_alive_time != 0) {
if (rtw_get_current_time() - keep_alive_time > 120000) {
RTSP_DBG_ERROR("keepalive timeout\n\r");
goto out;
}
}
#endif
if (select(RTSP_SELECT_SOCK, &client_read_fds, NULL, NULL, &c_listen_timeout)) {
#ifdef KEEPALIVE_TIMEOUT_ENABLE
keep_alive_time = rtw_get_current_time();
#endif
memset(request, 0, RTSP_REQUEST_BUF_SIZE);
int read_len = 0;
rtw_mutex_get(&rtsp_ctx->socket_lock);
read_len = read(rtsp_ctx->client_socket, request, RTSP_REQUEST_BUF_SIZE);
rtw_mutex_put(&rtsp_ctx->socket_lock);
request[RTSP_REQUEST_BUF_SIZE - 1] = '\0';
if (read_len <= 0) {
RTSP_DBG_ERROR("Receive request len <=0, close socket\n\r");
goto out;
}
if (concat_buf_len == 0) { // complete frame or 1st segment
if (*request == '$') {
rtsp_ctx->request_type = RTSP_INTERLEAVED_FRAME;
uint32_t rtsp_interleaved_len = 4 + ntohs(*(uint16_t *)(request + 2));
rtsp_ctx->request_incomplete = (read_len < rtsp_interleaved_len) ? 1 : 0;
if (read_len < rtsp_interleaved_len) {
rtsp_ctx->request_incomplete = 1;
} else {
rtsp_ctx->request_incomplete = 0;
}
} else {
rtsp_parse_request(rtsp_ctx, request);
}
}
// rtsp_ctx->request_incomplete is updated by rtsp_parse_request();
if (rtsp_ctx->request_incomplete) {
uint32_t copy_len = (concat_buf_len + read_len <= RTSP_REQUEST_BUF_SIZE - 1) ? read_len : (RTSP_REQUEST_BUF_SIZE - 1 - concat_buf_len);
memcpy(request_concat_buf + concat_buf_len, request, copy_len);
concat_buf_len += copy_len;
if (concat_buf_len == copy_len) { // 1st segment, just copy
continue;
} else {
if (rtsp_ctx->request_type == RTSP_INTERLEAVED_FRAME) {
uint32_t rtsp_interleaved_len = 4 + ntohs(*(uint16_t *)(request + 2));
rtsp_ctx->request_incomplete = (concat_buf_len < rtsp_interleaved_len) ? 1 : 0;
} else {
rtsp_parse_request(rtsp_ctx, request_concat_buf);
}
if (rtsp_ctx->request_incomplete) {
continue;
} else {
memcpy(request, request_concat_buf, concat_buf_len);
memset(request_concat_buf, 0, RTSP_REQUEST_BUF_SIZE);
concat_buf_len = 0;
}
}
}
// complete frame
if (rtsp_ctx->request_type != RTSP_INTERLEAVED_FRAME) {
RTSP_DBG_INFO("[%s] request:\n\r%s\n\r", (rtsp_ctx->is_connected_to_proxy == 1) ? "Proxy" : "Local", request);
}
switch (rtsp_ctx->request_type) {
case (REQUEST_OPTIONS):
RTSP_DBG_INFO("[%s] REQUEST_OPTIONS\n\r", (rtsp_ctx->is_connected_to_proxy == 1) ? "Proxy" : "Local");
if (check_rtsp_url(rtsp_ctx) >= 0) {
rtsp_cmd_options(rtsp_ctx);
printf("rtsp_cmd_options\r\n");
} else {
rtsp_cmd_destination_unreachable(rtsp_ctx);
printf("rtsp_cmd_destination_unreachable\r\n");
}
//rtsp_cmd_destination_unreachable(rtsp_ctx);
rtw_mutex_get(&rtsp_ctx->socket_lock);
ok = write(rtsp_ctx->client_socket, rtsp_ctx->response, strlen(rtsp_ctx->response));
rtw_mutex_put(&rtsp_ctx->socket_lock);
if (ok <= 0) {
RTSP_DBG_ERROR("send OPTIONS response failed!");
goto out;
}
break;
case (REQUEST_DESCRIBE):
RTSP_DBG_INFO("[%s] REQUEST_DESCRIBE\n\r", (rtsp_ctx->is_connected_to_proxy == 1) ? "Proxy" : "Local");
if (rtsp_ctx->state != RTSP_INIT) {
goto out;
}
if (check_rtsp_url(rtsp_ctx) >= 0) {
rtsp_cmd_describe(rtsp_ctx);
printf("rtsp_cmd_describe\r\n");
} else {
rtsp_cmd_destination_unreachable(rtsp_ctx);
printf("rtsp_cmd_destination_unreachable\r\n");
}
//rtsp_cmd_destination_unreachable(rtsp_ctx);
rtw_mutex_get(&rtsp_ctx->socket_lock);
ok = write(rtsp_ctx->client_socket, rtsp_ctx->response, strlen(rtsp_ctx->response));
rtw_mutex_put(&rtsp_ctx->socket_lock);
if (ok <= 0) {
RTSP_DBG_ERROR("send DESCRIBE response failed!");
goto out;
}
break;
case (REQUEST_GET_PARAM):
RTSP_DBG_INFO("[%s] REQUEST_GET_PARAM\n\r", (rtsp_ctx->is_connected_to_proxy == 1) ? "Proxy" : "Local");
rtsp_cmd_getparm(rtsp_ctx);
#ifdef KEEPALIVE_TIMEOUT_ENABLE
keep_alive_time = rtw_get_current_time();
#endif
rtw_mutex_get(&rtsp_ctx->socket_lock);
ok = write(rtsp_ctx->client_socket, rtsp_ctx->response, strlen(rtsp_ctx->response));
rtw_mutex_put(&rtsp_ctx->socket_lock);
if (ok <= 0) {
RTSP_DBG_ERROR("send REQUEST_GET_PARAM response failed!");
goto out;
}
show_result_statistics(rtsp_ctx);
if (rtsp_ctx->cb_custom) {
rtsp_ctx->cb_custom(NULL);
}
break;
case (REQUEST_SETUP):
RTSP_DBG_INFO("[%s] REQUEST_SETUP\n\r", (rtsp_ctx->is_connected_to_proxy == 1) ? "Proxy" : "Local");
if ((rtsp_ctx->state != RTSP_INIT) && (rtsp_ctx->nb_streams_setup >= rtsp_ctx->nb_streams)) {
goto out;
}
#if 0 // set to 1: disable RTSP over TCP
if (rtsp_ctx->transport[rtsp_ctx->setup_stream_index].castMode == UNICAST_TCP_MODE) {
rtsp_cmd_unsupported_transport(rtsp_ctx);
RTSP_DBG_ERROR("RTP over TCP not supported");
break;
}
#endif
rtsp_cmd_setup(rtsp_ctx);
rtw_mutex_get(&rtsp_ctx->socket_lock);
ok = write(rtsp_ctx->client_socket, rtsp_ctx->response, strlen(rtsp_ctx->response));
rtw_mutex_put(&rtsp_ctx->socket_lock);
if (ok <= 0) {
RTSP_DBG_ERROR("send SETUP response failed!");
goto out;
}
rtsp_ctx->state = RTSP_READY;
rtsp_ctx->stream_ctx[rtsp_ctx->setup_stream_index].setup_done = 1;
rtsp_ctx->nb_streams_setup++;
RTSP_DBG_INFO("state changed from RTSP_INIT to RTSP_READY");
break;
case (REQUEST_TEARDOWN):
printf("[%s] REQUEST_TEARDOWN\n\r", (rtsp_ctx->is_connected_to_proxy == 1) ? "Proxy" : "Local");
rtsp_ctx->state = RTSP_INIT;
rtsp_cmd_teardown(rtsp_ctx);
rtw_mutex_get(&rtsp_ctx->socket_lock);
ok = write(rtsp_ctx->client_socket, rtsp_ctx->response, strlen(rtsp_ctx->response));
rtw_mutex_put(&rtsp_ctx->socket_lock);
if (ok <= 0) {
RTSP_DBG_ERROR("send TEARDOWN response failed!");
goto out;
}
RTSP_DBG_INFO("streaming teardown, state changed back to RTSP_INIT");
show_result_statistics(rtsp_ctx);
/*wait for rtp/rtcp server reinit*/
if (rtsp_ctx->cb_stop) {
rtsp_ctx->cb_stop(NULL);
}
//vTaskDelay(1000);
goto out;
break;
case (REQUEST_PLAY):
printf("[%s] REQUEST_PLAY\n\r", (rtsp_ctx->is_connected_to_proxy == 1) ? "Proxy" : "Local");
if (rtsp_ctx->state != RTSP_READY) {
break;
}
rtsp_cmd_play(rtsp_ctx);
rtw_mutex_get(&rtsp_ctx->socket_lock);
ok = write(rtsp_ctx->client_socket, rtsp_ctx->response, strlen(rtsp_ctx->response));
rtw_mutex_put(&rtsp_ctx->socket_lock);
if (ok <= 0) {
RTSP_DBG_ERROR("send PLAY response failed!");
goto out;
}
rtsp_ctx->state = RTSP_PLAYING;
//here to start rtp/rtcp service
rtw_up_sema(&rtsp_ctx->start_rtp_sema);
#ifdef SUPPORT_RTCP
rtw_up_sema(&rtsp_ctx->start_rtcp_sema);
#endif
if (rtsp_ctx->cb_start) {
rtsp_ctx->cb_start(NULL);
}
break;
case (REQUEST_PAUSE):
printf("[%s] REQUEST_PAUSE\n\r", (rtsp_ctx->is_connected_to_proxy == 1) ? "Proxy" : "Local");
if (rtsp_ctx->state != RTSP_PLAYING) {
goto out;
}
rtsp_cmd_pause(rtsp_ctx);
rtw_mutex_get(&rtsp_ctx->socket_lock);
ok = write(rtsp_ctx->client_socket, rtsp_ctx->response, strlen(rtsp_ctx->response));
rtw_mutex_put(&rtsp_ctx->socket_lock);
if (ok <= 0) {
RTSP_DBG_ERROR("send PAUSE response failed!");
goto out;
}
rtsp_ctx->state = RTSP_READY;
if (rtsp_ctx->cb_pause) {
rtsp_ctx->cb_pause(NULL);
}
RTSP_DBG_INFO("state changed from RTSP_PLAYING to RTSP_READY");
break;
case (RTSP_INTERLEAVED_FRAME):
RTSP_DBG_INFO("[%s] RTSP_INTERLEAVED_FRAME\n\r", (rtsp_ctx->is_connected_to_proxy == 1) ? "Proxy" : "Local");
break;
default:
RTSP_DBG_ERROR("Receive invalid command!");
RTSP_DBG_ERROR("REQUEST:\n\r%s\n\r", request);
rtsp_ctx->state = RTSP_INIT;
rtsp_cmd_error(rtsp_ctx);
rtw_mutex_get(&rtsp_ctx->socket_lock);
ok = write(rtsp_ctx->client_socket, rtsp_ctx->response, strlen(rtsp_ctx->response));
rtw_mutex_put(&rtsp_ctx->socket_lock);
if (ok <= 0) {
RTSP_DBG_ERROR("send ERROR response failed!");
goto out;
}
}
if (rtsp_ctx->request_type != RTSP_INTERLEAVED_FRAME) {
RTSP_DBG_INFO("[%s] response:\n\r%s\n\r", (rtsp_ctx->is_connected_to_proxy == 1) ? "Proxy" : "Local", rtsp_ctx->response);
}
}
if (rtsp_ctx->interface <= 1) {
if (mode == RTW_MODE_STA) {
if (!((wifi_get_join_status() == RTW_JOINSTATUS_SUCCESS) && (*(u32 *)LwIP_GetIP(0) != IP_ADDR_INVALID))) {
goto out;
}
} else if (mode == RTW_MODE_AP) {
if (wifi_is_running(WLAN0_IDX) == 0) {
goto out;
}
} else {
goto out;
}
} else {
//For ethernet mode
}
} //while(rtsp_is_stream_enabled(rtsp_ctx))
out:
rtsp_ctx->state = RTSP_INIT;
#ifdef KEEPALIVE_TIMEOUT_ENABLE
keep_alive_time = 0;
#endif
printf("[%s] Socket closed\n\r", (rtsp_ctx->is_connected_to_proxy == 1) ? "Proxy" : "Local");
rtsp_ctx->is_connected_to_proxy = 0;
//wait rtp_service_unicast done
do {
vTaskDelay(2000);
} while (rtsp_ctx->is_rtp_start);
close(rtsp_ctx->client_socket);
//refresh number of streams been set up
rtsp_ctx->nb_streams_setup = 0;
for (int i = 0; i < rtsp_ctx->nb_streams; i++) {
rtsp_ctx->rtpseq[i] = 0;
rtsp_ctx->stream_ctx[i].setup_done = 0;
}
}
if (rtsp_ctx->interface <= 1) {
if (mode == RTW_MODE_STA) {
if (!((wifi_get_join_status() == RTW_JOINSTATUS_SUCCESS) && (*(u32 *)LwIP_GetIP(0) != IP_ADDR_INVALID))) {
RTSP_DBG_ERROR("wifi Tx/Rx broke! rtsp service cannot stream");
close(rtsp_ctx->connect_ctx.socket_id);
RTSP_DBG_ERROR("RTSP Reconnect!");
goto Redo;
}
} else if (mode == RTW_MODE_AP) {
if (wifi_is_running(WLAN0_IDX) == 0) {
RTSP_DBG_ERROR("wifi Tx/Rx broke! rtsp service cannot stream");
close(rtsp_ctx->connect_ctx.socket_id);
RTSP_DBG_ERROR("RTSP Reconnect!");
goto Redo;
}
} else {
goto error;
}
} else {
// For ethernet
// printf("Go to out %d\r\n",__LINE__);
//goto error;
}
}
error:
rtsp_disable_stream(rtsp_ctx);
close(rtsp_ctx->connect_ctx.socket_id);
if (request) {
free(request);
}
if (request_concat_buf);
free(request_concat_buf);
printf("\n\rrtsp service stop");
}
static void rtp_service_unicast(struct rtsp_context *rtsp_ctx)
{
int cast_mode = rtsp_ctx->transport[0].castMode;
struct rtp_object *payload;
struct stream_context *stream;
int i, ret;
unsigned int filter_count = 0;
int rtp_socket;
if (cast_mode == UNICAST_TCP_MODE) {
/* reuse RTSP socket (TCP) to send RTP packet */
rtp_socket = rtsp_ctx->client_socket;
} else { // UNICAST_UDP_MODE
/* init rtp socket (UDP) */
rtp_socket = socket(AF_INET, SOCK_DGRAM, 0);
int rtp_port = rtsp_ctx->transport[0].serverport_low;
struct sockaddr_in rtp_addr;
socklen_t addrlen = sizeof(struct sockaddr_in);
memset(&rtp_addr, 0, addrlen);
rtp_addr.sin_family = AF_INET;
rtp_addr.sin_addr.s_addr = *(uint32_t *)(rtsp_ctx->connect_ctx.server_ip);
rtp_addr.sin_port = _htons((u16)rtp_port);
if (bind(rtp_socket, (struct sockaddr *)&rtp_addr, addrlen) < 0) {
RTSP_DBG_ERROR("bind failed\r\n");
goto exit;
}
}
rtsp_ctx->is_rtp_start = 1;
printf("\n\rrtp started (%s)\n\r", (cast_mode == UNICAST_TCP_MODE) ? "TCP" : "UDP");
restart:
while ((rtsp_ctx->state == RTSP_PLAYING) && (rtsp_is_stream_enabled(rtsp_ctx))) {
if (rtw_down_timeout_sema(&rtsp_ctx->rtp_input_sema, 33)) {
for (i = 0; i < rtsp_ctx->nb_streams; i++) {
stream = &rtsp_ctx->stream_ctx[i];
if (!list_empty(&stream->input_queue)) {
rtw_mutex_get(&stream->input_lock);
payload = list_first_entry(&stream->input_queue, struct rtp_object, rtp_list);
list_del_init(&payload->rtp_list);
rtw_mutex_put(&stream->input_lock);
if (stream->setup_done) {
if (payload->state == RTP_OBJECT_READY) {
payload->state = RTP_OBJECT_INUSE;
payload->connect_ctx.socket_id = rtp_socket;
if (cast_mode == UNICAST_UDP_MODE) {
payload->connect_ctx.remote_port = (u16)rtsp_ctx->transport[i].clientport_low;
payload->connect_ctx.server_ip = rtsp_ctx->connect_ctx.server_ip;
payload->connect_ctx.remote_ip = rtsp_ctx->connect_ctx.remote_ip;
}
ret = 0;
//if(filter_count < rtsp_ctx->pre_filter_packet)//end condition
// filter_count++;
//else
#ifndef ENABLE_SIP_MMFV2
ret = payload->rtp_object_handler(stream, payload);
#endif
if (ret < 0) {
if (ret == -EAGAIN) { //means packet drop
stream->statistics.drop_packet++;
} else {
RTSP_DBG_ERROR("payload->rtp_object_handler(stream, payload) ret=%d\n\r", ret);
}
} else {
if (stream->statistics.base_timestamp == 0) {
stream->statistics.base_timestamp = payload->timestamp;
RTSP_DBG_INFO("base ts:%d", stream->statistics.base_timestamp);
}
stream->statistics.sent_packet++;
}
payload->state = RTP_OBJECT_USED;
} else {
payload->state = RTP_OBJECT_IDLE;
}
}
rtw_mutex_get(&stream->output_lock);
list_add_tail(&payload->rtp_list, &stream->output_queue);
rtw_mutex_put(&stream->output_lock);
rtw_up_sema(&rtsp_ctx->rtp_output_sema);
}
}
}
}
vTaskDelay(10);
if (rtsp_ctx->state == RTSP_READY) {
filter_count = 0;//for pause
goto restart;
}
exit:
rtsp_ctx->is_rtp_start = 0;
if (cast_mode == UNICAST_UDP_MODE) {
close(rtp_socket);
}
printf("\n\rrtp stopped (%s)\n\r", (cast_mode == UNICAST_TCP_MODE) ? "TCP" : "UDP");
}
void rtp_service_init(void *param)
{
struct rtsp_context *rtsp_ctx = (struct rtsp_context *) param;
int i;
struct stream_context *stream;
while (rtsp_is_service_enabled(rtsp_ctx)) {
if (rtw_down_timeout_sema(&rtsp_ctx->start_rtp_sema, 100)) {
for (i = 0; i < rtsp_ctx->nb_streams; i++) {
stream = &rtsp_ctx->stream_ctx[i];
if (stream->setup_done) {
rtp_stream_statistics_sync(stream);
}
}
switch (rtsp_ctx->transport[0].castMode) {
case (UNICAST_UDP_MODE):
case (UNICAST_TCP_MODE):
rtsp_ctx->rtp_service_handle = rtp_service_unicast;
rtsp_ctx->rtp_service_handle(rtsp_ctx);
break;
case (MULTICAST_MODE):
//to do
break;
default:
break;
}
}
}
rtsp_ctx->is_rtp_start = 0;
vTaskDelete(NULL);
}
#ifdef SUPPORT_RTCP
void rtcp_service_init(void *param)
{
struct rtsp_context *rtsp_ctx = (struct rtsp_context *) param;
rtsp_ctx->is_rtcp_start = 1;
while (rtsp_is_service_enabled(rtsp_ctx)) {
if (rtw_down_timeout_sema(&rtsp_ctx->start_rtcp_sema, 10)) {
//to do
}
}
vTaskDelete(NULL);
}
#endif
void rtsp_service_init(void *param)
{
struct rtsp_context *rtsp_ctx = (struct rtsp_context *) param;
rtsp_enable_service(rtsp_ctx);
while (rtsp_is_service_enabled(rtsp_ctx)) {
if (rtw_down_timeout_sema(&rtsp_ctx->start_rtsp_sema, 100)) {
//rtsp start stream
rtsp_start_service(rtsp_ctx);
}
}
RTSP_DBG_ERROR("rtsp service closed");
vTaskDelete(NULL);
}
/* ----------------------------------------------- user space interface ---------------------------------------------------------*/
int rtsp_open(struct rtsp_context *rtsp_ctx)
{
if (xTaskCreate(rtsp_service_init, ((const char *)"rtsp_service_init"), 2048, (void *)rtsp_ctx, RTSP_SERVICE_PRIORITY, NULL) != pdPASS) {
RTSP_DBG_ERROR("rtp_start_service: Create Task Error\n");
goto error;
}
//rtsp_service_priority = uxTaskPriorityGet(NULL);
if (xTaskCreate(rtp_service_init, ((const char *)"rtp_service_init"), 1024, (void *)rtsp_ctx, RTSP_SERVICE_PRIORITY, NULL) != pdPASS) {
RTSP_DBG_ERROR("rtp_start_service: Create Task Error\n");
goto error;
}
#ifdef SUPPORT_RTCP
if (xTaskCreate(rtcp_service_init, ((const char *)"rtcp_service_init"), 512, (void *)rtsp_ctx, RTSP_SERVICE_PRIORITY, NULL) != pdPASS) {
RTSP_DBG_ERROR("rtp_start_service: Create Task Error\n");
goto error;
}
#endif
return 0;
error:
rtsp_close_service(rtsp_ctx);
return -1;
}
void rtsp_start(struct rtsp_context *rtsp_ctx)
{
//check if more than 1 src stream registered in rtsp context
int i;
for (i = 0; i < rtsp_ctx->nb_streams; i++) {
INIT_LIST_HEAD(&rtsp_ctx->stream_ctx[i].input_queue);
INIT_LIST_HEAD(&rtsp_ctx->stream_ctx[i].output_queue);
}
if (rtsp_ctx->connect_ctx.server_port == 0) {
rtsp_ctx->connect_ctx.server_port = rtsp_ctx->id + DEF_RTSP_PORT;
}
printf("\n\rRTSP[%d] port: %d\n\r", rtsp_ctx->id, rtsp_ctx->connect_ctx.server_port);
rtsp_ctx->state = RTSP_INIT;
rtsp_ctx->nb_streams_setup = 0;
rtsp_enable_stream(rtsp_ctx);
rtw_up_sema(&rtsp_ctx->start_rtsp_sema);
}
void rtsp_stop(struct rtsp_context *rtsp_ctx)
{
rtsp_disable_stream(rtsp_ctx);
}
void rtsp_close(struct rtsp_context *rtsp_ctx)
{
rtsp_close_service(rtsp_ctx);
}
void rtp_object_in_stream_queue(struct rtp_object *payload, struct stream_context *stream_ctx)
{
struct rtsp_context *rtsp_ctx = stream_ctx->parent;
rtw_mutex_get(&stream_ctx->input_lock);
list_add_tail(&payload->rtp_list, &stream_ctx->input_queue);
rtw_mutex_put(&stream_ctx->input_lock);
rtw_up_sema(&rtsp_ctx->rtp_input_sema);
}
struct rtp_object *rtp_object_out_stream_queue(struct stream_context *stream_ctx)
{
rtw_down_sema(&stream_ctx->parent->rtp_output_sema);
struct rtp_object *payload = NULL;
if (!list_empty(&stream_ctx->output_queue)) {
rtw_mutex_get(&stream_ctx->output_lock);
payload = list_first_entry(&stream_ctx->output_queue, struct rtp_object, rtp_list);
list_del_init(&payload->rtp_list);
rtw_mutex_put(&stream_ctx->output_lock);
}
return payload;
}
|
dcd70bca521828efdb68263d9cb0457dabb7a749
|
b6ed57db11d13e986e01d4dcc6b7fb5f1713ea00
|
/include/kvec.h
|
efa0107a17078738c631465d18aeb64c53a2a4b0
|
[
"MIT"
] |
permissive
|
Kray-G/kinx
|
c60fd22a51a1d83aa8510558073f0b9a52282e58
|
5f80f6e9f53c3bde8bf1532eadc99128531d09e4
|
refs/heads/main
| 2022-12-13T21:20:22.609327
| 2022-12-06T02:09:06
| 2022-12-06T02:09:06
| 224,545,404
| 254
| 18
|
MIT
| 2022-01-05T12:20:29
| 2019-11-28T01:20:27
|
C
|
UTF-8
|
C
| false
| false
| 5,255
|
h
|
kvec.h
|
/* The MIT License
Copyright (c) 2008, by Attractive Chaos <attractor@live.co.uk>
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
/*
An example:
#include "kvec.h"
int main() {
kvec_t(int) array;
kv_init(array);
kv_push(int, array, 10); // append
kv_a(int, array, 20) = 5; // dynamic
kv_A(array, 20) = 4; // static
kv_destroy(array);
return 0;
}
*/
/*
2008-09-22 (0.1.0):
* The initial version.
*/
#ifndef AC_KVEC_H
#define AC_KVEC_H
#include <stdlib.h>
#define kv_roundup32(x) (--(x), (x)|=(x)>>1, (x)|=(x)>>2, (x)|=(x)>>4, (x)|=(x)>>8, (x)|=(x)>>16, ++(x))
#define kvec_init_t(type) typedef struct kvtype_##type##_ { size_t n, m; type *a; } kvtype_##type
#define kvec_init_pt(type) typedef struct kvtype_##type##_p_ { size_t n, m; type* *a; } kvtype_##type##_p
#define kvec_t(type) kvtype_##type
#define kvec_pt(type) kvtype_##type##_p
#define kvec_nt(type) struct { size_t n, m; type *a; }
#define kv_init(v) ((v).n = (v).m = 0, (v).a = 0)
#define kv_destroy(v) kx_free((v).a)
#define kv_A(v, i) ((v).a[(i)])
#define kv_head(v) ((v).a[0])
#define kv_last(v) ((v).a[((v).n)-1])
#define kv_last_by(v, d) ((v).a[((v).n)-(d)])
#define kv_remove_last(v) (--(v).n)
#define kv_pop(v) ((v).a[--(v).n])
#define kv_size(v) ((v).n)
#define kv_max(v) ((v).m)
#define kv_shrinkto(v, d) (((v).n) = d)
#define kv_shrink(v, d) (((v).n) -= d)
#define kv_zero(type, v) (memset((v).a, 0, sizeof(type) * (v).m))
#define kv_resize(type, v, s) ((v).m = (s), (v).a = ((v).a ? (type*)kx_realloc((v).a, sizeof(type) * (v).m) : (type*)kx_calloc((v).m, sizeof(type))))
#define kv_resize_if(type, v, s) if ((v).m < (s)) ((v).m = (s), (v).a = ((v).a ? (type*)kx_realloc((v).a, sizeof(type) * (v).m) : (type*)kx_calloc((v).m, sizeof(type))))
#define kv_expand(type, v, e) ((v).m = ((v).n+(s)), (v).a = (type*)kx_realloc((v).a, sizeof(type) * (v).m))
#define kv_expand_if(type, v, e) if ((v).m < ((v).n+(e))) ((v).m = ((v).n+(e)), (v).a = (type*)kx_realloc((v).a, sizeof(type) * (v).m))
#define kv_sort(type, v, comp) qsort((v).a, kv_size(v), sizeof(type), comp)
#define kv_copy(type, v1, v0) do { \
if ((v1).m < (v0).n) kv_resize(type, v1, (v0).n); \
(v1).n = (v0).n; \
memcpy((v1).a, (v0).a, sizeof(type) * (v0).n); \
} while (0) \
#define kv_push(type, v, x) do { \
if ((v).n == (v).m) { \
(v).m = (v).m? (v).m<<1 : 64; \
(v).a = (type*)kx_realloc((v).a, sizeof(type) * (v).m); \
} \
(v).a[(v).n++] = (x); \
} while (0)
#define kv_push_unchk(v, x) (v).a[((v).n)++] = (x)
#define kv_push_undef(v) ((v).a[((v).n)++])
#define kv_pushp(type, v) ((((v).n >= (v).m)? \
((v).m = ((v).m? (v).m<<1 : 64), \
(v).a = (type*)kx_realloc((v).a, sizeof(type) * (v).m), 0) \
: 0), ((v).a + ((v).n++)))
#define kv_a(type, v, i) (((v).m <= (size_t)(i)? \
((v).m = (v).n = (i) + 1, kv_roundup32((v).m), \
(v).a = (type*)kx_realloc((v).a, sizeof(type) * (v).m), 0) \
: (v).n <= (size_t)(i)? (v).n = (i) + 1 \
: 0)), (v).a[(i)]
#define kv_append(type, v1, v0) do { \
int v1n = (v1).n; \
if (((v1).n + (v0).n) >= (v1).m) { \
(v1).n = (v1).n + (v0).n; \
(v1).m = (v1).n<<1; \
(v1).a = (type*)kx_realloc((v1).a, sizeof(type) * (v1).m); \
} else { \
(v1).n = (v1).n + (v0).n; \
} \
memcpy((v1).a + v1n, (v0).a, sizeof(type) * (v0).n); \
} while (0)
#define kv_prepend(type, v1, v0) do { \
int v1n = (v1).n; \
if (((v1).n + (v0).n) >= (v1).m) { \
(v1).n = (v1).n + (v0).n; \
(v1).m = (v1).n<<1; \
(v1).a = (type*)kx_realloc((v1).a, sizeof(type) * (v1).m); \
} else { \
(v1).n = (v1).n + (v0).n; \
} \
memmove((v1).a + (v0).n, (v1).a, sizeof(type) * v1n); \
memcpy((v1).a, (v0).a, sizeof(type) * (v0).n); \
} while (0)
#define kv_shift(type, v1) do { \
memmove((v1).a, (v1).a + 1, sizeof(type) * (--(v1).n)); \
} while (0)
#endif
|
45b27306bd2e053881de09e1142bb12a7866e592
|
e73547787354afd9b717ea57fe8dd0695d161821
|
/src/world/dead/area_flo/flo_11/flo_11_4_entity.c
|
a0b15ab008cdd12190a57b238fd4fe877d87ebc9
|
[] |
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
| 252
|
c
|
flo_11_4_entity.c
|
#include "flo_11.h"
#include "entity.h"
EvtScript N(EVS_MakeEntities) = {
EVT_CALL(MakeEntity, EVT_PTR(Entity_MulticoinBlock), -220, 60, -75, 0, MAKE_ENTITY_END)
EVT_CALL(AssignBlockFlag, GF_FLO11_MultiCoinBrick)
EVT_RETURN
EVT_END
};
|
21136a9319e812b30f4bb37164bf6d449f8eac3a
|
a3cf3ed7895b6168fe0864770f944d0a25d5ad74
|
/tests/gen/gtest.c
|
140407943b6da585623d48cc3da24823c6d1e532
|
[
"BSD-2-Clause"
] |
permissive
|
katef/libfsm
|
32269415d8ab61778bef9bfdb3c14c61117216d4
|
479d103357f4e1a8596437895bbc6ddf237a1da0
|
refs/heads/main
| 2023-08-12T06:21:35.611111
| 2023-06-03T22:17:25
| 2023-06-15T20:40:54
| 80,573,145
| 918
| 66
|
BSD-2-Clause
| 2023-09-12T13:31:36
| 2017-01-31T23:31:36
|
C
|
UTF-8
|
C
| false
| false
| 3,319
|
c
|
gtest.c
|
/*
* Copyright 2021 Scott Vokes
*
* See LICENCE for the full copyright terms.
*/
#include "gtest.h"
#include <assert.h>
#include <string.h>
#include <fsm/options.h>
#include <fsm/bool.h>
/* Note: not "gentest" because then this matches the gen* pattern and
* the Makefile tries to build this as a standalone test runner. */
/* Should never need this many for any of the tests. */
#define MAX_STEPS 10000
void
gtest_init_matches(struct exp_matches *ms)
{
for (size_t m_i = 0; m_i < ms->count; m_i++) {
struct exp_match *m = &ms->matches[m_i];
m->length = strlen(m->s);
}
}
enum fsm_generate_matches_cb_res
gtest_matches_cb(const struct fsm *fsm,
size_t depth, size_t match_count, size_t steps,
const char *input, size_t input_length,
fsm_state_t end_state, void *opaque)
{
(void)depth;
(void)match_count;
(void)steps;
if (steps == MAX_STEPS) {
return FSM_GENERATE_MATCHES_CB_RES_HALT;
}
if (getenv("VERBOSE")) {
fprintf(stderr,
"gtest_matches_cb: depth %zu, match_count %zu, steps %zu, input \"%s\"(%zu), end_state %d\n",
depth, match_count, steps, input, input_length, end_state);
}
struct exp_matches *ms = opaque;
assert(ms != NULL);
assert(ms->magic == EXP_MATCHES_MAGIC);
for (size_t m_i = 0; m_i < ms->count; m_i++) {
struct exp_match *m = &ms->matches[m_i];
if (m->length == input_length
&& 0 == strncmp(m->s, input, input_length)) {
m->found = true;
#define ID_BUF_COUNT 1
fsm_end_id_t id_buf[ID_BUF_COUNT];
size_t written;
enum fsm_getendids_res gres = fsm_getendids(fsm,
end_state, ID_BUF_COUNT, id_buf, &written);
if (gres != FSM_GETENDIDS_FOUND) {
fprintf(stderr,
"ERROR: fsm_getendids: returned %d\n",
gres);
return FSM_GENERATE_MATCHES_CB_RES_HALT;
}
if (written != 1 || id_buf[0] != m_i) {
fprintf(stderr, "ERROR: endid mismatch, expected %zu, got %u\n",
m_i, id_buf[0]);
return FSM_GENERATE_MATCHES_CB_RES_HALT;
}
return m->prune
? FSM_GENERATE_MATCHES_CB_RES_PRUNE
: FSM_GENERATE_MATCHES_CB_RES_CONTINUE;
}
}
fprintf(stderr, "ERROR: unexpected input: \"%s\"(%zu)\n",
input, input_length);
return FSM_GENERATE_MATCHES_CB_RES_HALT;
}
static const struct fsm_options options; /* use defaults */
struct fsm *
gtest_fsm_of_matches(const struct exp_matches *ms)
{
struct fsm *res = NULL;
for (size_t m_i = 0; m_i < ms->count; m_i++) {
const struct exp_match *m = &ms->matches[m_i];
struct fsm *fsm = fsm_new(&options);
assert(fsm != NULL);
if (!fsm_addstate_bulk(fsm, m->length + 1)) {
return NULL;
}
fsm_setstart(fsm, 0);
for (size_t i = 0; i < m->length; i++) {
if (!fsm_addedge_literal(fsm,
i, i + 1, m->s[i])) {
return NULL;
}
}
fsm_setend(fsm, m->length, 1);
fsm_setendid(fsm, m_i);
if (res == NULL) {
res = fsm;
} else {
res = fsm_union(res, fsm, NULL);
assert(res != NULL);
}
}
if (!fsm_determinise(res)) {
return NULL;
}
return res;
}
bool
gtest_all_found(const struct exp_matches *ms, FILE *f)
{
bool res = true;
for (size_t i = 0; i < ms->count; i++) {
const struct exp_match *m = &ms->matches[i];
if (!m->found) {
res = false;
if (f != NULL) {
fprintf(f, "NOT FOUND: \"%s\"(%zu)\n",
m->s, m->length);
}
}
}
return res;
}
|
1ff74ebb12459d0da99ac7c4c2a3576d5580a9c2
|
3837a03fceb06dbe8d4546366750cf5c5478819d
|
/src/gst/elements/batch_create/batch_create.h
|
58be8adc8e1d7af6d12c4cc736c8116bddf312c2
|
[
"MIT"
] |
permissive
|
dlstreamer/dlstreamer
|
b1453b1a79437cf74eaf0438e38f809dd82afae2
|
20f2bb6a0be2cfdb351ab2297a4ac7c4db090ed8
|
refs/heads/master
| 2023-08-18T14:54:36.496564
| 2023-03-03T20:31:16
| 2023-03-03T20:51:34
| 175,417,729
| 135
| 53
|
MIT
| 2023-02-07T14:59:51
| 2019-03-13T12:35:56
|
C++
|
UTF-8
|
C
| false
| false
| 473
|
h
|
batch_create.h
|
/*******************************************************************************
* Copyright (C) 2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
******************************************************************************/
#pragma once
#include <gst/base/gstbasetransform.h>
#define BATCH_CREATE_DESCRIPTION "Accumulate multiple buffers into single buffer with multiple GstMemory"
G_BEGIN_DECLS
GST_EXPORT GType batch_create_get_type(void);
G_END_DECLS
|
9596626a75d9b1fdde84e339096a4145b9801273
|
e65a4dbfbfb0e54e59787ba7741efee12f7687f3
|
/security/opencryptoki/files/patch-usr-lib-api-socket_client.c
|
9d989df6b181ae56e67b344404cd03073b116e6e
|
[
"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
| 370
|
c
|
patch-usr-lib-api-socket_client.c
|
--- usr/lib/api/socket_client.c.orig 2022-04-25 11:04:51 UTC
+++ usr/lib/api/socket_client.c
@@ -49,7 +49,7 @@ int connect_socket(const char *file_path)
return -1;
}
- grp = getgrnam("pkcs11");
+ grp = getgrnam(PKCS11GROUP);
if (!grp) {
OCK_SYSLOG(LOG_ERR,
"connect_socket: pkcs11 group does not exist, errno=%d",
|
839f896c9889ef2596f9c4eb98853bc40c17b16f
|
4d3c17ec8de8c414e23c7c45fb4d10be5b136c17
|
/source/client/filesearch.h
|
37f1f963951d90f99543d3820af7018e4660efc7
|
[] |
no_license
|
Visgean/Zeus
|
683cc608668a19c9ae91306992e3f1d1c4f17e0e
|
c55a9fa8c8564ec196604a59111708fa8415f020
|
refs/heads/translation
| 2022-06-28T10:25:06.929828
| 2014-02-23T11:34:47
| 2014-02-23T11:34:47
| 1,745,628
| 1,224
| 671
| null | 2020-12-09T18:14:29
| 2011-05-13T22:18:30
|
C
|
WINDOWS-1251
|
C
| false
| false
| 228
|
h
|
filesearch.h
|
/*
Поиск файлов.
*/
#pragma once
/*namespace FileSearch
{
In In bool StartThread (LOADERSPYDATA * plsd);
In In bool AddQuest (LPSTR pExts, DWORD dwSize);
In In bool RemoveQuest (LPSTR pExts, DWORD dwSize);
};*/
|
7c460c9a2d4ed72322a8bc780427d039a5944fb2
|
3d7b16da8617cb0dd4c33dc8be4ef392e90687a4
|
/include/ardrone_autonomy/ardrone_sdk.h
|
080c425e0b387193fc1e37e270a2ea7a02cb6b91
|
[
"BSD-3-Clause"
] |
permissive
|
AutonomyLab/ardrone_autonomy
|
cb04fff01aec6949235010ad718d5da7bf47366d
|
d35607beb211f56d8ce4aafa45115a1be34c97c2
|
refs/heads/indigo-devel
| 2023-08-28T07:59:35.234708
| 2016-12-07T04:58:51
| 2016-12-07T04:58:51
| 4,341,280
| 283
| 207
|
BSD-3-Clause
| 2017-11-30T03:26:50
| 2012-05-15T22:17:54
|
C
|
UTF-8
|
C
| false
| false
| 3,242
|
h
|
ardrone_sdk.h
|
/**
Software License Agreement (BSD)
\file ardrone_sdk.h
\authors Mani Monajjemi <mmonajje@sfu.ca>
\copyright Copyright (c) 2012, Autonomy Lab (Simon Fraser University), All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that
the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the
following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
following disclaimer in the documentation and/or other materials provided with the distribution.
* Neither the name of Autonomy Lab 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 WAR-
RANTIES, 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, IN-
DIRECT, 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 ARDRONE_AUTONOMY_ARDRONE_SDK_H
#define ARDRONE_AUTONOMY_ARDRONE_SDK_H
// TODO(mani-monaj): Move these two defines to CMake
#ifndef FFMPEG_SUPPORT
#define FFMPEG_SUPPORT
#endif
#ifndef USE_LINUX
#define USE_LINUX
#endif
// TODO(mani-monaj): Research more on this issue, move the flag to CMake
// The FFMPEG library INT macros fix
#if defined __cplusplus
# define __STDC_CONSTANT_MACROS
#endif
#include <stdint.h>
#ifndef UINT64_C
#define UINT64_C(c) (c ## ULL)
#endif
extern "C"
{
#include <config.h>
#include <utils/ardrone_gen_ids.h>
#include <ardrone_tool/ardrone_version.h>
#include <ardrone_tool/ardrone_tool.h>
#include <ardrone_tool/ardrone_tool_configuration.h>
#include <ardrone_tool/Com/config_com.h>
#include <ardrone_tool/UI/ardrone_input.h>
#include <ardrone_tool/Video/video_com_stage.h>
#include <ardrone_tool/Control/ardrone_control.h>
#include <ardrone_tool/Navdata/ardrone_navdata_client.h>
#include <ardrone_tool/Video/video_stage.h>
#include <ardrone_tool/Video/video_recorder_pipeline.h>
#include <ardrone_tool/Video/video_stage_latency_estimation.h>
extern video_decoder_config_t vec;
}
#include <ardrone_autonomy/ardrone_driver.h>
#define NB_DRIVER_POST_STAGES 10
extern ARDroneDriver *ros_driver;
extern const navdata_unpacked_t* shared_raw_navdata_ptr;
extern ros::Time shared_navdata_receive_time;
extern vp_os_mutex_t navdata_lock;
extern vp_os_mutex_t video_lock;
extern vp_os_mutex_t twist_lock;
extern int32_t looprate;
extern bool realtime_navdata;
extern bool realtime_video;
extern int32_t should_exit;
#endif // ARDRONE_AUTONOMY_ARDRONE_SDK_H
|
2ec06e2c5cd4c0da5ad8bcf0c271896de1508d93
|
99bdb3251fecee538e0630f15f6574054dfc1468
|
/components/libc/posix/pthreads/sched.c
|
833d70e8f092e2956e089e6dbb4623064d552d21
|
[
"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
| 985
|
c
|
sched.c
|
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
*/
#include <sched.h>
int sched_yield(void)
{
rt_thread_yield();
return 0;
}
RTM_EXPORT(sched_yield);
int sched_get_priority_min(int policy)
{
if (policy != SCHED_FIFO && policy != SCHED_RR)
return EINVAL;
return 0;
}
RTM_EXPORT(sched_get_priority_min);
int sched_get_priority_max(int policy)
{
if (policy != SCHED_FIFO && policy != SCHED_RR)
return EINVAL;
return RT_THREAD_PRIORITY_MAX - 1;
}
RTM_EXPORT(sched_get_priority_max);
int sched_setscheduler(pid_t pid, int policy)
{
return EOPNOTSUPP;
}
RTM_EXPORT(sched_setscheduler);
int sched_rr_get_interval(pid_t pid, struct timespec *tp)
{
if(pid != 0)
{
return EINVAL;
}
rt_set_errno(-EINVAL);
/* course model, don't support */
// TODO
return -1;
}
RTM_EXPORT(sched_rr_get_interval);
|
a252cf915941d544a1acc9ceb1b3895291317596
|
fdbb74a95924e2677466614f6ab6e2bb13b2a95a
|
/third_party/regex/tre-mem.c
|
3f5a6dee83508483fb43f32ee571f68ac8a48ca5
|
[
"ISC",
"MIT",
"BSD-2-Clause"
] |
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
| 8,039
|
c
|
tre-mem.c
|
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
╚──────────────────────────────────────────────────────────────────────────────╝
│ │
│ tre-mem.c - TRE memory allocator │
│ │
│ Copyright (c) 2001-2009 Ville Laurikari <vl@iki.fi> │
│ 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 HOLDER 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. │
│ │
│──────────────────────────────────────────────────────────────────────────────│
│ │
│ Musl Libc │
│ Copyright © 2005-2014 Rich Felker, et al. │
│ │
│ 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 "third_party/regex/tre.inc"
/*
This memory allocator is for allocating small memory blocks efficiently
in terms of memory overhead and execution speed. The allocated blocks
cannot be freed individually, only all at once. There can be multiple
allocators, though.
*/
/*
This memory allocator is for allocating small memory blocks efficiently
in terms of memory overhead and execution speed. The allocated blocks
cannot be freed individually, only all at once. There can be multiple
allocators, though.
*/
/* Returns a new memory allocator or NULL if out of memory. */
tre_mem_t tre_mem_new_impl(int provided, void *provided_block) {
tre_mem_t mem;
if (provided) {
mem = provided_block;
bzero(mem, sizeof(*mem));
} else
mem = calloc(1, sizeof(*mem));
if (mem == NULL) return NULL;
return mem;
}
/* Frees the memory allocator and all memory allocated with it. */
void tre_mem_destroy(tre_mem_t mem) {
tre_list_t *tmp, *l = mem->blocks;
while (l != NULL) {
free(l->data), l->data = NULL;
tmp = l->next;
free(l), l = tmp;
}
free(mem), mem = NULL;
}
/* Allocates a block of `size' bytes from `mem'. Returns a pointer to the
allocated block or NULL if an underlying malloc() failed. */
void *tre_mem_alloc_impl(tre_mem_t mem, int provided, void *provided_block,
int zero, size_t size) {
void *ptr;
if (mem->failed) {
return NULL;
}
if (mem->n < size) {
/* We need more memory than is available in the current block.
Allocate a new block. */
tre_list_t *l;
if (provided) {
if (provided_block == NULL) {
mem->failed = 1;
return NULL;
}
mem->ptr = provided_block;
mem->n = TRE_MEM_BLOCK_SIZE;
} else {
int block_size;
if (size * 8 > TRE_MEM_BLOCK_SIZE)
block_size = size * 8;
else
block_size = TRE_MEM_BLOCK_SIZE;
l = malloc(sizeof(*l));
if (l == NULL) {
mem->failed = 1;
return NULL;
}
l->data = malloc(block_size);
if (l->data == NULL) {
free(l), l = NULL;
mem->failed = 1;
return NULL;
}
l->next = NULL;
if (mem->current != NULL) mem->current->next = l;
if (mem->blocks == NULL) mem->blocks = l;
mem->current = l;
mem->ptr = l->data;
mem->n = block_size;
}
}
/* Make sure the next pointer will be aligned. */
size += ALIGN(mem->ptr + size, long);
/* Allocate from current block. */
ptr = mem->ptr;
mem->ptr += size;
mem->n -= size;
/* Set to zero if needed. */
if (zero) bzero(ptr, size);
return ptr;
}
|
456b12360f57c180200d4f7afdaba3b95ccf0347
|
7eaf54a78c9e2117247cb2ab6d3a0c20719ba700
|
/SOFTWARE/A64-TERES/linux-a64/drivers/tty/serial/pnx8xxx_uart.c
|
7e277a5384a7679d22a64dd92234d3b5c9e17c43
|
[
"LicenseRef-scancode-free-unknown",
"Apache-2.0",
"Linux-syscall-note",
"GPL-2.0-only",
"GPL-1.0-or-later"
] |
permissive
|
OLIMEX/DIY-LAPTOP
|
ae82f4ee79c641d9aee444db9a75f3f6709afa92
|
a3fafd1309135650bab27f5eafc0c32bc3ca74ee
|
refs/heads/rel3
| 2023-08-04T01:54:19.483792
| 2023-04-03T07:18:12
| 2023-04-03T07:18:12
| 80,094,055
| 507
| 92
|
Apache-2.0
| 2023-04-03T07:05:59
| 2017-01-26T07:25:50
|
C
|
UTF-8
|
C
| false
| false
| 21,328
|
c
|
pnx8xxx_uart.c
|
/*
* UART driver for PNX8XXX SoCs
*
* Author: Per Hallsmark per.hallsmark@mvista.com
* Ported to 2.6 kernel by EmbeddedAlley
* Reworked by Vitaly Wool <vitalywool@gmail.com>
*
* Based on drivers/char/serial.c, by Linus Torvalds, Theodore Ts'o.
* Copyright (C) 2000 Deep Blue Solutions Ltd.
*
* This file is licensed under the terms of the GNU General Public License
* version 2. This program is licensed "as is" without any warranty of
* any kind, whether express or implied.
*
*/
#if defined(CONFIG_SERIAL_PNX8XXX_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
#define SUPPORT_SYSRQ
#endif
#include <linux/module.h>
#include <linux/ioport.h>
#include <linux/init.h>
#include <linux/console.h>
#include <linux/sysrq.h>
#include <linux/device.h>
#include <linux/platform_device.h>
#include <linux/tty.h>
#include <linux/tty_flip.h>
#include <linux/serial_core.h>
#include <linux/serial.h>
#include <linux/serial_pnx8xxx.h>
#include <asm/io.h>
#include <asm/irq.h>
/* We'll be using StrongARM sa1100 serial port major/minor */
#define SERIAL_PNX8XXX_MAJOR 204
#define MINOR_START 5
#define NR_PORTS 2
#define PNX8XXX_ISR_PASS_LIMIT 256
/*
* Convert from ignore_status_mask or read_status_mask to FIFO
* and interrupt status bits
*/
#define SM_TO_FIFO(x) ((x) >> 10)
#define SM_TO_ISTAT(x) ((x) & 0x000001ff)
#define FIFO_TO_SM(x) ((x) << 10)
#define ISTAT_TO_SM(x) ((x) & 0x000001ff)
/*
* This is the size of our serial port register set.
*/
#define UART_PORT_SIZE 0x1000
/*
* This determines how often we check the modem status signals
* for any change. They generally aren't connected to an IRQ
* so we have to poll them. We also check immediately before
* filling the TX fifo incase CTS has been dropped.
*/
#define MCTRL_TIMEOUT (250*HZ/1000)
extern struct pnx8xxx_port pnx8xxx_ports[];
static inline int serial_in(struct pnx8xxx_port *sport, int offset)
{
return (__raw_readl(sport->port.membase + offset));
}
static inline void serial_out(struct pnx8xxx_port *sport, int offset, int value)
{
__raw_writel(value, sport->port.membase + offset);
}
/*
* Handle any change of modem status signal since we were last called.
*/
static void pnx8xxx_mctrl_check(struct pnx8xxx_port *sport)
{
unsigned int status, changed;
status = sport->port.ops->get_mctrl(&sport->port);
changed = status ^ sport->old_status;
if (changed == 0)
return;
sport->old_status = status;
if (changed & TIOCM_RI)
sport->port.icount.rng++;
if (changed & TIOCM_DSR)
sport->port.icount.dsr++;
if (changed & TIOCM_CAR)
uart_handle_dcd_change(&sport->port, status & TIOCM_CAR);
if (changed & TIOCM_CTS)
uart_handle_cts_change(&sport->port, status & TIOCM_CTS);
wake_up_interruptible(&sport->port.state->port.delta_msr_wait);
}
/*
* This is our per-port timeout handler, for checking the
* modem status signals.
*/
static void pnx8xxx_timeout(unsigned long data)
{
struct pnx8xxx_port *sport = (struct pnx8xxx_port *)data;
unsigned long flags;
if (sport->port.state) {
spin_lock_irqsave(&sport->port.lock, flags);
pnx8xxx_mctrl_check(sport);
spin_unlock_irqrestore(&sport->port.lock, flags);
mod_timer(&sport->timer, jiffies + MCTRL_TIMEOUT);
}
}
/*
* interrupts disabled on entry
*/
static void pnx8xxx_stop_tx(struct uart_port *port)
{
struct pnx8xxx_port *sport = (struct pnx8xxx_port *)port;
u32 ien;
/* Disable TX intr */
ien = serial_in(sport, PNX8XXX_IEN);
serial_out(sport, PNX8XXX_IEN, ien & ~PNX8XXX_UART_INT_ALLTX);
/* Clear all pending TX intr */
serial_out(sport, PNX8XXX_ICLR, PNX8XXX_UART_INT_ALLTX);
}
/*
* interrupts may not be disabled on entry
*/
static void pnx8xxx_start_tx(struct uart_port *port)
{
struct pnx8xxx_port *sport = (struct pnx8xxx_port *)port;
u32 ien;
/* Clear all pending TX intr */
serial_out(sport, PNX8XXX_ICLR, PNX8XXX_UART_INT_ALLTX);
/* Enable TX intr */
ien = serial_in(sport, PNX8XXX_IEN);
serial_out(sport, PNX8XXX_IEN, ien | PNX8XXX_UART_INT_ALLTX);
}
/*
* Interrupts enabled
*/
static void pnx8xxx_stop_rx(struct uart_port *port)
{
struct pnx8xxx_port *sport = (struct pnx8xxx_port *)port;
u32 ien;
/* Disable RX intr */
ien = serial_in(sport, PNX8XXX_IEN);
serial_out(sport, PNX8XXX_IEN, ien & ~PNX8XXX_UART_INT_ALLRX);
/* Clear all pending RX intr */
serial_out(sport, PNX8XXX_ICLR, PNX8XXX_UART_INT_ALLRX);
}
/*
* Set the modem control timer to fire immediately.
*/
static void pnx8xxx_enable_ms(struct uart_port *port)
{
struct pnx8xxx_port *sport = (struct pnx8xxx_port *)port;
mod_timer(&sport->timer, jiffies);
}
static void pnx8xxx_rx_chars(struct pnx8xxx_port *sport)
{
unsigned int status, ch, flg;
status = FIFO_TO_SM(serial_in(sport, PNX8XXX_FIFO)) |
ISTAT_TO_SM(serial_in(sport, PNX8XXX_ISTAT));
while (status & FIFO_TO_SM(PNX8XXX_UART_FIFO_RXFIFO)) {
ch = serial_in(sport, PNX8XXX_FIFO) & 0xff;
sport->port.icount.rx++;
flg = TTY_NORMAL;
/*
* note that the error handling code is
* out of the main execution path
*/
if (status & (FIFO_TO_SM(PNX8XXX_UART_FIFO_RXFE |
PNX8XXX_UART_FIFO_RXPAR |
PNX8XXX_UART_FIFO_RXBRK) |
ISTAT_TO_SM(PNX8XXX_UART_INT_RXOVRN))) {
if (status & FIFO_TO_SM(PNX8XXX_UART_FIFO_RXBRK)) {
status &= ~(FIFO_TO_SM(PNX8XXX_UART_FIFO_RXFE) |
FIFO_TO_SM(PNX8XXX_UART_FIFO_RXPAR));
sport->port.icount.brk++;
if (uart_handle_break(&sport->port))
goto ignore_char;
} else if (status & FIFO_TO_SM(PNX8XXX_UART_FIFO_RXPAR))
sport->port.icount.parity++;
else if (status & FIFO_TO_SM(PNX8XXX_UART_FIFO_RXFE))
sport->port.icount.frame++;
if (status & ISTAT_TO_SM(PNX8XXX_UART_INT_RXOVRN))
sport->port.icount.overrun++;
status &= sport->port.read_status_mask;
if (status & FIFO_TO_SM(PNX8XXX_UART_FIFO_RXPAR))
flg = TTY_PARITY;
else if (status & FIFO_TO_SM(PNX8XXX_UART_FIFO_RXFE))
flg = TTY_FRAME;
#ifdef SUPPORT_SYSRQ
sport->port.sysrq = 0;
#endif
}
if (uart_handle_sysrq_char(&sport->port, ch))
goto ignore_char;
uart_insert_char(&sport->port, status,
ISTAT_TO_SM(PNX8XXX_UART_INT_RXOVRN), ch, flg);
ignore_char:
serial_out(sport, PNX8XXX_LCR, serial_in(sport, PNX8XXX_LCR) |
PNX8XXX_UART_LCR_RX_NEXT);
status = FIFO_TO_SM(serial_in(sport, PNX8XXX_FIFO)) |
ISTAT_TO_SM(serial_in(sport, PNX8XXX_ISTAT));
}
tty_flip_buffer_push(&sport->port.state->port);
}
static void pnx8xxx_tx_chars(struct pnx8xxx_port *sport)
{
struct circ_buf *xmit = &sport->port.state->xmit;
if (sport->port.x_char) {
serial_out(sport, PNX8XXX_FIFO, sport->port.x_char);
sport->port.icount.tx++;
sport->port.x_char = 0;
return;
}
/*
* Check the modem control lines before
* transmitting anything.
*/
pnx8xxx_mctrl_check(sport);
if (uart_circ_empty(xmit) || uart_tx_stopped(&sport->port)) {
pnx8xxx_stop_tx(&sport->port);
return;
}
/*
* TX while bytes available
*/
while (((serial_in(sport, PNX8XXX_FIFO) &
PNX8XXX_UART_FIFO_TXFIFO) >> 16) < 16) {
serial_out(sport, PNX8XXX_FIFO, xmit->buf[xmit->tail]);
xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
sport->port.icount.tx++;
if (uart_circ_empty(xmit))
break;
}
if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
uart_write_wakeup(&sport->port);
if (uart_circ_empty(xmit))
pnx8xxx_stop_tx(&sport->port);
}
static irqreturn_t pnx8xxx_int(int irq, void *dev_id)
{
struct pnx8xxx_port *sport = dev_id;
unsigned int status;
spin_lock(&sport->port.lock);
/* Get the interrupts */
status = serial_in(sport, PNX8XXX_ISTAT) & serial_in(sport, PNX8XXX_IEN);
/* Byte or break signal received */
if (status & (PNX8XXX_UART_INT_RX | PNX8XXX_UART_INT_BREAK))
pnx8xxx_rx_chars(sport);
/* TX holding register empty - transmit a byte */
if (status & PNX8XXX_UART_INT_TX)
pnx8xxx_tx_chars(sport);
/* Clear the ISTAT register */
serial_out(sport, PNX8XXX_ICLR, status);
spin_unlock(&sport->port.lock);
return IRQ_HANDLED;
}
/*
* Return TIOCSER_TEMT when transmitter is not busy.
*/
static unsigned int pnx8xxx_tx_empty(struct uart_port *port)
{
struct pnx8xxx_port *sport = (struct pnx8xxx_port *)port;
return serial_in(sport, PNX8XXX_FIFO) & PNX8XXX_UART_FIFO_TXFIFO_STA ? 0 : TIOCSER_TEMT;
}
static unsigned int pnx8xxx_get_mctrl(struct uart_port *port)
{
struct pnx8xxx_port *sport = (struct pnx8xxx_port *)port;
unsigned int mctrl = TIOCM_DSR;
unsigned int msr;
/* REVISIT */
msr = serial_in(sport, PNX8XXX_MCR);
mctrl |= msr & PNX8XXX_UART_MCR_CTS ? TIOCM_CTS : 0;
mctrl |= msr & PNX8XXX_UART_MCR_DCD ? TIOCM_CAR : 0;
return mctrl;
}
static void pnx8xxx_set_mctrl(struct uart_port *port, unsigned int mctrl)
{
#if 0 /* FIXME */
struct pnx8xxx_port *sport = (struct pnx8xxx_port *)port;
unsigned int msr;
#endif
}
/*
* Interrupts always disabled.
*/
static void pnx8xxx_break_ctl(struct uart_port *port, int break_state)
{
struct pnx8xxx_port *sport = (struct pnx8xxx_port *)port;
unsigned long flags;
unsigned int lcr;
spin_lock_irqsave(&sport->port.lock, flags);
lcr = serial_in(sport, PNX8XXX_LCR);
if (break_state == -1)
lcr |= PNX8XXX_UART_LCR_TXBREAK;
else
lcr &= ~PNX8XXX_UART_LCR_TXBREAK;
serial_out(sport, PNX8XXX_LCR, lcr);
spin_unlock_irqrestore(&sport->port.lock, flags);
}
static int pnx8xxx_startup(struct uart_port *port)
{
struct pnx8xxx_port *sport = (struct pnx8xxx_port *)port;
int retval;
/*
* Allocate the IRQ
*/
retval = request_irq(sport->port.irq, pnx8xxx_int, 0,
"pnx8xxx-uart", sport);
if (retval)
return retval;
/*
* Finally, clear and enable interrupts
*/
serial_out(sport, PNX8XXX_ICLR, PNX8XXX_UART_INT_ALLRX |
PNX8XXX_UART_INT_ALLTX);
serial_out(sport, PNX8XXX_IEN, serial_in(sport, PNX8XXX_IEN) |
PNX8XXX_UART_INT_ALLRX |
PNX8XXX_UART_INT_ALLTX);
/*
* Enable modem status interrupts
*/
spin_lock_irq(&sport->port.lock);
pnx8xxx_enable_ms(&sport->port);
spin_unlock_irq(&sport->port.lock);
return 0;
}
static void pnx8xxx_shutdown(struct uart_port *port)
{
struct pnx8xxx_port *sport = (struct pnx8xxx_port *)port;
int lcr;
/*
* Stop our timer.
*/
del_timer_sync(&sport->timer);
/*
* Disable all interrupts
*/
serial_out(sport, PNX8XXX_IEN, 0);
/*
* Reset the Tx and Rx FIFOS, disable the break condition
*/
lcr = serial_in(sport, PNX8XXX_LCR);
lcr &= ~PNX8XXX_UART_LCR_TXBREAK;
lcr |= PNX8XXX_UART_LCR_TX_RST | PNX8XXX_UART_LCR_RX_RST;
serial_out(sport, PNX8XXX_LCR, lcr);
/*
* Clear all interrupts
*/
serial_out(sport, PNX8XXX_ICLR, PNX8XXX_UART_INT_ALLRX |
PNX8XXX_UART_INT_ALLTX);
/*
* Free the interrupt
*/
free_irq(sport->port.irq, sport);
}
static void
pnx8xxx_set_termios(struct uart_port *port, struct ktermios *termios,
struct ktermios *old)
{
struct pnx8xxx_port *sport = (struct pnx8xxx_port *)port;
unsigned long flags;
unsigned int lcr_fcr, old_ien, baud, quot;
unsigned int old_csize = old ? old->c_cflag & CSIZE : CS8;
/*
* We only support CS7 and CS8.
*/
while ((termios->c_cflag & CSIZE) != CS7 &&
(termios->c_cflag & CSIZE) != CS8) {
termios->c_cflag &= ~CSIZE;
termios->c_cflag |= old_csize;
old_csize = CS8;
}
if ((termios->c_cflag & CSIZE) == CS8)
lcr_fcr = PNX8XXX_UART_LCR_8BIT;
else
lcr_fcr = 0;
if (termios->c_cflag & CSTOPB)
lcr_fcr |= PNX8XXX_UART_LCR_2STOPB;
if (termios->c_cflag & PARENB) {
lcr_fcr |= PNX8XXX_UART_LCR_PAREN;
if (!(termios->c_cflag & PARODD))
lcr_fcr |= PNX8XXX_UART_LCR_PAREVN;
}
/*
* Ask the core to calculate the divisor for us.
*/
baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk/16);
quot = uart_get_divisor(port, baud);
spin_lock_irqsave(&sport->port.lock, flags);
sport->port.read_status_mask = ISTAT_TO_SM(PNX8XXX_UART_INT_RXOVRN) |
ISTAT_TO_SM(PNX8XXX_UART_INT_EMPTY) |
ISTAT_TO_SM(PNX8XXX_UART_INT_RX);
if (termios->c_iflag & INPCK)
sport->port.read_status_mask |=
FIFO_TO_SM(PNX8XXX_UART_FIFO_RXFE) |
FIFO_TO_SM(PNX8XXX_UART_FIFO_RXPAR);
if (termios->c_iflag & (BRKINT | PARMRK))
sport->port.read_status_mask |=
ISTAT_TO_SM(PNX8XXX_UART_INT_BREAK);
/*
* Characters to ignore
*/
sport->port.ignore_status_mask = 0;
if (termios->c_iflag & IGNPAR)
sport->port.ignore_status_mask |=
FIFO_TO_SM(PNX8XXX_UART_FIFO_RXFE) |
FIFO_TO_SM(PNX8XXX_UART_FIFO_RXPAR);
if (termios->c_iflag & IGNBRK) {
sport->port.ignore_status_mask |=
ISTAT_TO_SM(PNX8XXX_UART_INT_BREAK);
/*
* If we're ignoring parity and break indicators,
* ignore overruns too (for real raw support).
*/
if (termios->c_iflag & IGNPAR)
sport->port.ignore_status_mask |=
ISTAT_TO_SM(PNX8XXX_UART_INT_RXOVRN);
}
/*
* ignore all characters if CREAD is not set
*/
if ((termios->c_cflag & CREAD) == 0)
sport->port.ignore_status_mask |=
ISTAT_TO_SM(PNX8XXX_UART_INT_RX);
del_timer_sync(&sport->timer);
/*
* Update the per-port timeout.
*/
uart_update_timeout(port, termios->c_cflag, baud);
/*
* disable interrupts and drain transmitter
*/
old_ien = serial_in(sport, PNX8XXX_IEN);
serial_out(sport, PNX8XXX_IEN, old_ien & ~(PNX8XXX_UART_INT_ALLTX |
PNX8XXX_UART_INT_ALLRX));
while (serial_in(sport, PNX8XXX_FIFO) & PNX8XXX_UART_FIFO_TXFIFO_STA)
barrier();
/* then, disable everything */
serial_out(sport, PNX8XXX_IEN, 0);
/* Reset the Rx and Tx FIFOs too */
lcr_fcr |= PNX8XXX_UART_LCR_TX_RST;
lcr_fcr |= PNX8XXX_UART_LCR_RX_RST;
/* set the parity, stop bits and data size */
serial_out(sport, PNX8XXX_LCR, lcr_fcr);
/* set the baud rate */
quot -= 1;
serial_out(sport, PNX8XXX_BAUD, quot);
serial_out(sport, PNX8XXX_ICLR, -1);
serial_out(sport, PNX8XXX_IEN, old_ien);
if (UART_ENABLE_MS(&sport->port, termios->c_cflag))
pnx8xxx_enable_ms(&sport->port);
spin_unlock_irqrestore(&sport->port.lock, flags);
}
static const char *pnx8xxx_type(struct uart_port *port)
{
struct pnx8xxx_port *sport = (struct pnx8xxx_port *)port;
return sport->port.type == PORT_PNX8XXX ? "PNX8XXX" : NULL;
}
/*
* Release the memory region(s) being used by 'port'.
*/
static void pnx8xxx_release_port(struct uart_port *port)
{
struct pnx8xxx_port *sport = (struct pnx8xxx_port *)port;
release_mem_region(sport->port.mapbase, UART_PORT_SIZE);
}
/*
* Request the memory region(s) being used by 'port'.
*/
static int pnx8xxx_request_port(struct uart_port *port)
{
struct pnx8xxx_port *sport = (struct pnx8xxx_port *)port;
return request_mem_region(sport->port.mapbase, UART_PORT_SIZE,
"pnx8xxx-uart") != NULL ? 0 : -EBUSY;
}
/*
* Configure/autoconfigure the port.
*/
static void pnx8xxx_config_port(struct uart_port *port, int flags)
{
struct pnx8xxx_port *sport = (struct pnx8xxx_port *)port;
if (flags & UART_CONFIG_TYPE &&
pnx8xxx_request_port(&sport->port) == 0)
sport->port.type = PORT_PNX8XXX;
}
/*
* Verify the new serial_struct (for TIOCSSERIAL).
* The only change we allow are to the flags and type, and
* even then only between PORT_PNX8XXX and PORT_UNKNOWN
*/
static int
pnx8xxx_verify_port(struct uart_port *port, struct serial_struct *ser)
{
struct pnx8xxx_port *sport = (struct pnx8xxx_port *)port;
int ret = 0;
if (ser->type != PORT_UNKNOWN && ser->type != PORT_PNX8XXX)
ret = -EINVAL;
if (sport->port.irq != ser->irq)
ret = -EINVAL;
if (ser->io_type != SERIAL_IO_MEM)
ret = -EINVAL;
if (sport->port.uartclk / 16 != ser->baud_base)
ret = -EINVAL;
if ((void *)sport->port.mapbase != ser->iomem_base)
ret = -EINVAL;
if (sport->port.iobase != ser->port)
ret = -EINVAL;
if (ser->hub6 != 0)
ret = -EINVAL;
return ret;
}
static struct uart_ops pnx8xxx_pops = {
.tx_empty = pnx8xxx_tx_empty,
.set_mctrl = pnx8xxx_set_mctrl,
.get_mctrl = pnx8xxx_get_mctrl,
.stop_tx = pnx8xxx_stop_tx,
.start_tx = pnx8xxx_start_tx,
.stop_rx = pnx8xxx_stop_rx,
.enable_ms = pnx8xxx_enable_ms,
.break_ctl = pnx8xxx_break_ctl,
.startup = pnx8xxx_startup,
.shutdown = pnx8xxx_shutdown,
.set_termios = pnx8xxx_set_termios,
.type = pnx8xxx_type,
.release_port = pnx8xxx_release_port,
.request_port = pnx8xxx_request_port,
.config_port = pnx8xxx_config_port,
.verify_port = pnx8xxx_verify_port,
};
/*
* Setup the PNX8XXX serial ports.
*
* Note also that we support "console=ttySx" where "x" is either 0 or 1.
*/
static void __init pnx8xxx_init_ports(void)
{
static int first = 1;
int i;
if (!first)
return;
first = 0;
for (i = 0; i < NR_PORTS; i++) {
init_timer(&pnx8xxx_ports[i].timer);
pnx8xxx_ports[i].timer.function = pnx8xxx_timeout;
pnx8xxx_ports[i].timer.data = (unsigned long)&pnx8xxx_ports[i];
pnx8xxx_ports[i].port.ops = &pnx8xxx_pops;
}
}
#ifdef CONFIG_SERIAL_PNX8XXX_CONSOLE
static void pnx8xxx_console_putchar(struct uart_port *port, int ch)
{
struct pnx8xxx_port *sport = (struct pnx8xxx_port *)port;
int status;
do {
/* Wait for UART_TX register to empty */
status = serial_in(sport, PNX8XXX_FIFO);
} while (status & PNX8XXX_UART_FIFO_TXFIFO);
serial_out(sport, PNX8XXX_FIFO, ch);
}
/*
* Interrupts are disabled on entering
*/static void
pnx8xxx_console_write(struct console *co, const char *s, unsigned int count)
{
struct pnx8xxx_port *sport = &pnx8xxx_ports[co->index];
unsigned int old_ien, status;
/*
* First, save IEN and then disable interrupts
*/
old_ien = serial_in(sport, PNX8XXX_IEN);
serial_out(sport, PNX8XXX_IEN, old_ien & ~(PNX8XXX_UART_INT_ALLTX |
PNX8XXX_UART_INT_ALLRX));
uart_console_write(&sport->port, s, count, pnx8xxx_console_putchar);
/*
* Finally, wait for transmitter to become empty
* and restore IEN
*/
do {
/* Wait for UART_TX register to empty */
status = serial_in(sport, PNX8XXX_FIFO);
} while (status & PNX8XXX_UART_FIFO_TXFIFO);
/* Clear TX and EMPTY interrupt */
serial_out(sport, PNX8XXX_ICLR, PNX8XXX_UART_INT_TX |
PNX8XXX_UART_INT_EMPTY);
serial_out(sport, PNX8XXX_IEN, old_ien);
}
static int __init
pnx8xxx_console_setup(struct console *co, char *options)
{
struct pnx8xxx_port *sport;
int baud = 38400;
int bits = 8;
int parity = 'n';
int flow = 'n';
/*
* Check whether an invalid uart number has been specified, and
* if so, search for the first available port that does have
* console support.
*/
if (co->index == -1 || co->index >= NR_PORTS)
co->index = 0;
sport = &pnx8xxx_ports[co->index];
if (options)
uart_parse_options(options, &baud, &parity, &bits, &flow);
return uart_set_options(&sport->port, co, baud, parity, bits, flow);
}
static struct uart_driver pnx8xxx_reg;
static struct console pnx8xxx_console = {
.name = "ttyS",
.write = pnx8xxx_console_write,
.device = uart_console_device,
.setup = pnx8xxx_console_setup,
.flags = CON_PRINTBUFFER,
.index = -1,
.data = &pnx8xxx_reg,
};
static int __init pnx8xxx_rs_console_init(void)
{
pnx8xxx_init_ports();
register_console(&pnx8xxx_console);
return 0;
}
console_initcall(pnx8xxx_rs_console_init);
#define PNX8XXX_CONSOLE &pnx8xxx_console
#else
#define PNX8XXX_CONSOLE NULL
#endif
static struct uart_driver pnx8xxx_reg = {
.owner = THIS_MODULE,
.driver_name = "ttyS",
.dev_name = "ttyS",
.major = SERIAL_PNX8XXX_MAJOR,
.minor = MINOR_START,
.nr = NR_PORTS,
.cons = PNX8XXX_CONSOLE,
};
static int pnx8xxx_serial_suspend(struct platform_device *pdev, pm_message_t state)
{
struct pnx8xxx_port *sport = platform_get_drvdata(pdev);
return uart_suspend_port(&pnx8xxx_reg, &sport->port);
}
static int pnx8xxx_serial_resume(struct platform_device *pdev)
{
struct pnx8xxx_port *sport = platform_get_drvdata(pdev);
return uart_resume_port(&pnx8xxx_reg, &sport->port);
}
static int pnx8xxx_serial_probe(struct platform_device *pdev)
{
struct resource *res = pdev->resource;
int i;
for (i = 0; i < pdev->num_resources; i++, res++) {
if (!(res->flags & IORESOURCE_MEM))
continue;
for (i = 0; i < NR_PORTS; i++) {
if (pnx8xxx_ports[i].port.mapbase != res->start)
continue;
pnx8xxx_ports[i].port.dev = &pdev->dev;
uart_add_one_port(&pnx8xxx_reg, &pnx8xxx_ports[i].port);
platform_set_drvdata(pdev, &pnx8xxx_ports[i]);
break;
}
}
return 0;
}
static int pnx8xxx_serial_remove(struct platform_device *pdev)
{
struct pnx8xxx_port *sport = platform_get_drvdata(pdev);
platform_set_drvdata(pdev, NULL);
if (sport)
uart_remove_one_port(&pnx8xxx_reg, &sport->port);
return 0;
}
static struct platform_driver pnx8xxx_serial_driver = {
.driver = {
.name = "pnx8xxx-uart",
.owner = THIS_MODULE,
},
.probe = pnx8xxx_serial_probe,
.remove = pnx8xxx_serial_remove,
.suspend = pnx8xxx_serial_suspend,
.resume = pnx8xxx_serial_resume,
};
static int __init pnx8xxx_serial_init(void)
{
int ret;
printk(KERN_INFO "Serial: PNX8XXX driver\n");
pnx8xxx_init_ports();
ret = uart_register_driver(&pnx8xxx_reg);
if (ret == 0) {
ret = platform_driver_register(&pnx8xxx_serial_driver);
if (ret)
uart_unregister_driver(&pnx8xxx_reg);
}
return ret;
}
static void __exit pnx8xxx_serial_exit(void)
{
platform_driver_unregister(&pnx8xxx_serial_driver);
uart_unregister_driver(&pnx8xxx_reg);
}
module_init(pnx8xxx_serial_init);
module_exit(pnx8xxx_serial_exit);
MODULE_AUTHOR("Embedded Alley Solutions, Inc.");
MODULE_DESCRIPTION("PNX8XXX SoCs serial port driver");
MODULE_LICENSE("GPL");
MODULE_ALIAS_CHARDEV_MAJOR(SERIAL_PNX8XXX_MAJOR);
MODULE_ALIAS("platform:pnx8xxx-uart");
|
ff7324a0fda4b9b59c2dc3753c12d0b16f841d70
|
7eaf54a78c9e2117247cb2ab6d3a0c20719ba700
|
/SOFTWARE/A64-TERES/linux-a64/arch/powerpc/include/asm/shmparam.h
|
5cda42a6d39ed411a801d7fe231216cbd1c578aa
|
[
"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
| 167
|
h
|
shmparam.h
|
#ifndef _ASM_POWERPC_SHMPARAM_H
#define _ASM_POWERPC_SHMPARAM_H
#define SHMLBA PAGE_SIZE /* attach addr a multiple of this */
#endif /* _ASM_POWERPC_SHMPARAM_H */
|
1576a079538bcead05ab7952fa131070df73ee50
|
a3cf3ed7895b6168fe0864770f944d0a25d5ad74
|
/theft/type_info_fsm_literal.h
|
4aeb1cba98bee0c4a5eaf85bb4c4dda94a4a8b1e
|
[
"BSD-2-Clause"
] |
permissive
|
katef/libfsm
|
32269415d8ab61778bef9bfdb3c14c61117216d4
|
479d103357f4e1a8596437895bbc6ddf237a1da0
|
refs/heads/main
| 2023-08-12T06:21:35.611111
| 2023-06-03T22:17:25
| 2023-06-15T20:40:54
| 80,573,145
| 918
| 66
|
BSD-2-Clause
| 2023-09-12T13:31:36
| 2017-01-31T23:31:36
|
C
|
UTF-8
|
C
| false
| false
| 581
|
h
|
type_info_fsm_literal.h
|
/*
* Copyright 2017 Scott Vokes
*
* See LICENCE for the full copyright terms.
*/
#ifndef TYPE_INFO_FSM_LITERAL_H
#define TYPE_INFO_FSM_LITERAL_H
#include "theft_libfsm.h"
/* This will allocate up to this many literal strings. */
#define FSM_MAX_LITERALS 64
/* An array of string literals.
* All strings are unique and zero terminated, but can also contain
* zeroes within the body of the string. */
struct fsm_literal_scen {
char tag;
uint8_t verbosity;
size_t count;
struct string_pair pairs[];
};
extern const struct theft_type_info type_info_fsm_literal;
#endif
|
f69e184edc8a09b77bf2fec688b4604e7fad727d
|
de21f9075f55640514c29ef0f1fe3f0690845764
|
/regression/goto-instrument/enable-pragmas/main.c
|
40275584d8e266aff0e72b026d28551d97ae3188
|
[
"BSD-2-Clause",
"LicenseRef-scancode-unknown-license-reference",
"BSD-4-Clause"
] |
permissive
|
diffblue/cbmc
|
975a074ac445febb3b5715f8792beb545522dc18
|
decd2839c2f51a54b2ad0f3e89fdc1b4bf78cd16
|
refs/heads/develop
| 2023-08-31T05:52:05.342195
| 2023-08-30T13:31:51
| 2023-08-30T13:31:51
| 51,877,056
| 589
| 309
|
NOASSERTION
| 2023-09-14T18:49:17
| 2016-02-16T23:03:52
|
C++
|
UTF-8
|
C
| false
| false
| 155
|
c
|
main.c
|
void main()
{
int a[2];
#pragma CPROVER check push
#pragma CPROVER check enable "bounds"
a[0] = 1;
a[1] = 2;
a[2] = 3;
#pragma CPROVER check pop
}
|
0f1b267e2e306b5ec06f55d29fb537c8de920574
|
3d144a23e67c839a4df1c073c6a2c842508f16b2
|
/test/ClangImporter/Inputs/chained-unit-test-bridging-header-to-pch.h
|
810736b1f8420f6532241401ebbda9df59be4ae1
|
[
"Apache-2.0",
"Swift-exception"
] |
permissive
|
apple/swift
|
c2724e388959f6623cf6e4ad6dc1cdd875fd0592
|
98ada1b200a43d090311b72eb45fe8ecebc97f81
|
refs/heads/main
| 2023-08-16T10:48:25.985330
| 2023-08-16T09:00:42
| 2023-08-16T09:00:42
| 44,838,949
| 78,897
| 15,074
|
Apache-2.0
| 2023-09-14T21:19:23
| 2015-10-23T21:15:07
|
C++
|
UTF-8
|
C
| false
| false
| 219
|
h
|
chained-unit-test-bridging-header-to-pch.h
|
#ifndef chained_unit_test_bridging_header_to_pch_h
#define chained_unit_test_bridging_header_to_pch_h
#include "app-bridging-header-to-pch.h"
static inline int unit_test_function(int x) {
return x + 28;
}
#endif
|
4a70564c2179e0fd6ac53e5d6692501cfabed27d
|
7eaf54a78c9e2117247cb2ab6d3a0c20719ba700
|
/SOFTWARE/A64-TERES/u-boot_new/arch/arm/include/asm/arch-mx25/gpio.h
|
81d95ea48580b05821cccaa4c569f5aae318f6ad
|
[
"LicenseRef-scancode-free-unknown",
"Apache-2.0",
"GPL-2.0-or-later"
] |
permissive
|
OLIMEX/DIY-LAPTOP
|
ae82f4ee79c641d9aee444db9a75f3f6709afa92
|
a3fafd1309135650bab27f5eafc0c32bc3ca74ee
|
refs/heads/rel3
| 2023-08-04T01:54:19.483792
| 2023-04-03T07:18:12
| 2023-04-03T07:18:12
| 80,094,055
| 507
| 92
|
Apache-2.0
| 2023-04-03T07:05:59
| 2017-01-26T07:25:50
|
C
|
UTF-8
|
C
| false
| false
| 237
|
h
|
gpio.h
|
/*
* Copyright (C) 2011
* Stefano Babic, DENX Software Engineering, <sbabic@denx.de>
*
* SPDX-License-Identifier: GPL-2.0+
*/
#ifndef __ASM_ARCH_MX25_GPIO_H
#define __ASM_ARCH_MX25_GPIO_H
#include <asm/imx-common/gpio.h>
#endif
|
773de85bfb2d66ccfe858f823af1d03a1e36ffd6
|
fbe68d84e97262d6d26dd65c704a7b50af2b3943
|
/third_party/virtualbox/src/VBox/Devices/EFI/Firmware/MdeModulePkg/Include/Library/RecoveryLib.h
|
dbe4083c4b5a391b243c8614dff0141a3d162716
|
[
"MIT",
"BSD-2-Clause",
"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"
] |
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
| 1,040
|
h
|
RecoveryLib.h
|
/** @file
Recovery library class defines a set of methods related recovery boot mode.
This library class is no longer used and modules using this library should
directly locate EFI_PEI_RECOVERY_MODULE_PPI, defined in the PI 1.2 specification.
Copyright (c) 2005 - 2010, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials are licensed and made available under
the terms and conditions of the BSD License that accompanies this distribution.
The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php.
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#ifndef __RECOVERY_LIB_H__
#define __RECOVERY_LIB_H__
/**
Calling this function causes the system to carry out a recovery boot path.
@retval EFI_SUCCESS Recovery boot path succeeded.
@retval Others Recovery boot path failure.
**/
EFI_STATUS
EFIAPI
PeiRecoverFirmware (
VOID
);
#endif
|
fe0a01ed68e0907a059c787e91e6ca9d513b12b2
|
971b2cea2d1c3001aadc8ca1a48110b7db1ed5f2
|
/deps/abc/src/proof/acec/acecRe.c
|
785058db6e4f110fed9a4370beea5df40a62c607
|
[
"MIT-Modern-Variant",
"LicenseRef-scancode-warranty-disclaimer",
"MIT"
] |
permissive
|
emsec/hal
|
70ad2921739967d914dd458984bd7d6d497d3b0a
|
e4fae37bec9168a61100eacfda37a1f291b4d0be
|
refs/heads/master
| 2023-09-02T20:27:32.909426
| 2023-09-01T13:03:24
| 2023-09-01T13:03:24
| 169,076,171
| 510
| 72
|
MIT
| 2023-09-01T13:03:26
| 2019-02-04T12:37:20
|
C++
|
UTF-8
|
C
| false
| false
| 20,624
|
c
|
acecRe.c
|
/**CFile****************************************************************
FileName [acecRe.c]
SystemName [ABC: Logic synthesis and verification system.]
PackageName [CEC for arithmetic circuits.]
Synopsis [Core procedures.]
Author [Alan Mishchenko]
Affiliation [UC Berkeley]
Date [Ver. 1.0. Started - June 20, 2005.]
Revision [$Id: acecRe.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
***********************************************************************/
#include "acecInt.h"
#include "misc/vec/vecHash.h"
#include "misc/util/utilTruth.h"
ABC_NAMESPACE_IMPL_START
////////////////////////////////////////////////////////////////////////
/// DECLARATIONS ///
////////////////////////////////////////////////////////////////////////
#define Ree_ForEachCut( pList, pCut, i ) for ( i = 0, pCut = pList + 1; i < pList[0]; i++, pCut += pCut[0] + 2 )
////////////////////////////////////////////////////////////////////////
/// FUNCTION DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
/**Function*************************************************************
Synopsis [Detecting FADDs in the AIG.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Ree_TruthPrecompute()
{
word Truths[8] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77 };
word Truth;
int i;
for ( i = 0; i < 8; i++ )
{
Truth = Truths[i];
Truth = Abc_Tt6SwapAdjacent( Truth, 1 );
Abc_TtPrintHexRev( stdout, &Truth, 3 );
printf( "\n" );
}
printf( "\n" );
for ( i = 0; i < 8; i++ )
{
Truth = Truths[i];
Truth = Abc_Tt6SwapAdjacent( Truth, 1 );
Truth = Abc_Tt6SwapAdjacent( Truth, 0 );
Abc_TtPrintHexRev( stdout, &Truth, 3 );
printf( "\n" );
}
printf( "\n" );
}
void Ree_TruthPrecompute2()
{
int i, b;
for ( i = 0; i < 8; i++ )
{
word Truth = 0xE8;
for ( b = 0; b < 3; b++ )
if ( (i >> b) & 1 )
Truth = Abc_Tt6Flip( Truth, b );
printf( "%d = %X\n", i, 0xFF & (int)Truth );
}
}
/**Function*************************************************************
Synopsis [Detecting FADDs in the AIG.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
static inline int Ree_ManCutMergeOne( int * pCut0, int * pCut1, int * pCut )
{
int i, k;
for ( k = 0; k <= pCut1[0]; k++ )
pCut[k] = pCut1[k];
for ( i = 1; i <= pCut0[0]; i++ )
{
for ( k = 1; k <= pCut1[0]; k++ )
if ( pCut0[i] == pCut1[k] )
break;
if ( k <= pCut1[0] )
continue;
if ( pCut[0] == 3 )
return 0;
pCut[1+pCut[0]++] = pCut0[i];
}
assert( pCut[0] == 2 || pCut[0] == 3 );
if ( pCut[1] > pCut[2] )
ABC_SWAP( int, pCut[1], pCut[2] );
assert( pCut[1] < pCut[2] );
if ( pCut[0] == 2 )
return 1;
if ( pCut[2] > pCut[3] )
ABC_SWAP( int, pCut[2], pCut[3] );
if ( pCut[1] > pCut[2] )
ABC_SWAP( int, pCut[1], pCut[2] );
assert( pCut[1] < pCut[2] );
assert( pCut[2] < pCut[3] );
return 1;
}
static inline int Ree_ManCutCheckEqual( Vec_Int_t * vCuts, int * pCutNew )
{
int * pList = Vec_IntArray( vCuts );
int i, k, * pCut;
Ree_ForEachCut( pList, pCut, i )
{
for ( k = 0; k <= pCut[0]; k++ )
if ( pCut[k] != pCutNew[k] )
break;
if ( k > pCut[0] )
return 1;
}
return 0;
}
static inline int Ree_ManCutFind( int iObj, int * pCut )
{
if ( pCut[1] == iObj ) return 0;
if ( pCut[2] == iObj ) return 1;
if ( pCut[3] == iObj ) return 2;
assert( 0 );
return -1;
}
static inline int Ree_ManCutNotFind( int iObj1, int iObj2, int * pCut )
{
assert( pCut[0] == 3 );
if ( pCut[3] != iObj1 && pCut[3] != iObj2 ) return 0;
if ( pCut[2] != iObj1 && pCut[2] != iObj2 ) return 1;
if ( pCut[1] != iObj1 && pCut[1] != iObj2 ) return 2;
assert( 0 );
return -1;
}
static inline int Ree_ManCutTruthOne( int * pCut0, int * pCut )
{
int Truth0 = pCut0[pCut0[0]+1];
int fComp0 = (Truth0 >> 7) & 1;
if ( pCut0[0] == 3 )
return Truth0;
Truth0 = fComp0 ? ~Truth0 : Truth0;
if ( pCut0[0] == 2 )
{
if ( pCut[0] == 3 )
{
int Truths[3][8] = {
{ 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77 }, // {0,1,-}
{ 0x00, 0x05, 0x0A, 0x0F, 0x50, 0x55, 0x5A, 0x5F }, // {0,-,1}
{ 0x00, 0x03, 0x0C, 0x0F, 0x30, 0x33, 0x3C, 0x3F } // {-,0,1}
};
int Truth = Truths[Ree_ManCutNotFind(pCut0[1], pCut0[2], pCut)][Truth0 & 0x7];
return 0xFF & (fComp0 ? ~Truth : Truth);
}
assert( pCut[0] == 2 );
assert( pCut[1] == pCut0[1] && pCut[2] == pCut0[2] );
return pCut0[pCut0[0]+1];
}
if ( pCut0[0] == 1 )
{
int Truths[3] = { 0x55, 0x33, 0x0F };
int Truth = Truths[Ree_ManCutFind(pCut0[1], pCut)];
return 0xFF & (fComp0 ? ~Truth : Truth);
}
assert( 0 );
return -1;
}
static inline int Ree_ManCutTruth( Gia_Obj_t * pObj, int * pCut0, int * pCut1, int * pCut )
{
int Truth0 = Ree_ManCutTruthOne( pCut0, pCut );
int Truth1 = Ree_ManCutTruthOne( pCut1, pCut );
Truth0 = Gia_ObjFaninC0(pObj) ? ~Truth0 : Truth0;
Truth1 = Gia_ObjFaninC1(pObj) ? ~Truth1 : Truth1;
return 0xFF & (Gia_ObjIsXor(pObj) ? Truth0 ^ Truth1 : Truth0 & Truth1);
}
#if 0
int Ree_ObjComputeTruth_rec( Gia_Obj_t * pObj )
{
int Truth0, Truth1;
if ( pObj->Value )
return pObj->Value;
assert( Gia_ObjIsAnd(pObj) );
Truth0 = Ree_ObjComputeTruth_rec( Gia_ObjFanin0(pObj) );
Truth1 = Ree_ObjComputeTruth_rec( Gia_ObjFanin1(pObj) );
if ( Gia_ObjIsXor(pObj) )
return (pObj->Value = (Gia_ObjFaninC0(pObj) ? ~Truth0 : Truth0) ^ (Gia_ObjFaninC1(pObj) ? ~Truth1 : Truth1));
else
return (pObj->Value = (Gia_ObjFaninC0(pObj) ? ~Truth0 : Truth0) & (Gia_ObjFaninC1(pObj) ? ~Truth1 : Truth1));
}
void Ree_ObjCleanTruth_rec( Gia_Obj_t * pObj )
{
if ( !pObj->Value )
return;
pObj->Value = 0;
if ( !Gia_ObjIsAnd(pObj) )
return;
Ree_ObjCleanTruth_rec( Gia_ObjFanin0(pObj) );
Ree_ObjCleanTruth_rec( Gia_ObjFanin1(pObj) );
}
int Ree_ObjComputeTruth( Gia_Man_t * p, int iObj, int * pCut )
{
unsigned Truth, Truths[3] = { 0xAA, 0xCC, 0xF0 }; int i;
for ( i = 1; i <= pCut[0]; i++ )
Gia_ManObj(p, pCut[i])->Value = Truths[i-1];
Truth = 0xFF & Ree_ObjComputeTruth_rec( Gia_ManObj(p, iObj) );
Ree_ObjCleanTruth_rec( Gia_ManObj(p, iObj) );
return Truth;
}
#endif
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Ree_ManCutPrint( int * pCut, int Count, word Truth, int iObj )
{
int c;
printf( "%d : %d : ", Count, iObj );
for ( c = 1; c <= pCut[0]; c++ )
printf( "%3d ", pCut[c] );
for ( ; c <= 4; c++ )
printf( " " );
printf( "0x" );
Abc_TtPrintHexRev( stdout, &Truth, 3 );
printf( "\n" );
}
void Ree_ManCutMerge( Gia_Man_t * p, int iObj, int * pList0, int * pList1, Vec_Int_t * vCuts, Hash_IntMan_t * pHash, Vec_Int_t * vData, Vec_Int_t * vXors )
{
int fVerbose = 0;
int i, k, c, Value, Truth, TruthC, * pCut0, * pCut1, pCut[6], Count = 0;
int iXor2 = -1, iXor3 = -1;
if ( fVerbose )
printf( "Object %d\n", iObj );
Vec_IntFill( vCuts, 2, 1 );
Vec_IntPush( vCuts, iObj );
Vec_IntPush( vCuts, 0xAA );
Ree_ForEachCut( pList0, pCut0, i )
Ree_ForEachCut( pList1, pCut1, k )
{
if ( !Ree_ManCutMergeOne(pCut0, pCut1, pCut) )
continue;
if ( Ree_ManCutCheckEqual(vCuts, pCut) )
continue;
Truth = TruthC = Ree_ManCutTruth(Gia_ManObj(p, iObj), pCut0, pCut1, pCut);
//assert( Truth == Ree_ObjComputeTruth(p, iObj, pCut) );
if ( Truth & 0x80 )
Truth = 0xFF & ~Truth;
if ( Truth == 0x66 && iXor2 == -1 )
iXor2 = Vec_IntSize(vCuts);
else if ( Truth == 0x69 && iXor3 == -1 )
iXor3 = Vec_IntSize(vCuts);
Vec_IntAddToEntry( vCuts, 0, 1 );
for ( c = 0; c <= pCut[0]; c++ )
Vec_IntPush( vCuts, pCut[c] );
Vec_IntPush( vCuts, TruthC );
if ( (Truth == 0x66 || Truth == 0x11 || Truth == 0x22 || Truth == 0x44 || Truth == 0x77) && pCut[0] == 2 )
{
assert( pCut[0] == 2 );
Value = Hsh_Int3ManInsert( pHash, pCut[1], pCut[2], 0 );
Vec_IntPushThree( vData, iObj, Value, TruthC );
}
else if ( Truth == 0x69 || Truth == 0x17 || Truth == 0x2B || Truth == 0x4D || Truth == 0x71 )
{
assert( pCut[0] == 3 );
Value = Hsh_Int3ManInsert( pHash, pCut[1], pCut[2], pCut[3] );
Vec_IntPushThree( vData, iObj, Value, TruthC );
}
if ( fVerbose )
Ree_ManCutPrint( pCut, ++Count, TruthC, iObj );
}
if ( !vXors )
return;
if ( iXor2 > 0 )
pCut0 = Vec_IntEntryP( vCuts, iXor2 );
else if ( iXor3 > 0 )
pCut0 = Vec_IntEntryP( vCuts, iXor3 );
else
return;
Vec_IntPush( vXors, iObj );
for ( c = 1; c <= pCut0[0]; c++ )
Vec_IntPush( vXors, pCut0[c] );
if ( pCut0[0] == 2 )
Vec_IntPush( vXors, 0 );
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
Vec_Int_t * Ree_ManDeriveAdds( Hash_IntMan_t * p, Vec_Int_t * vData, int fVerbose )
{
int i, j, k, iObj, iObj2, Value, Truth, Truth2, CountX, CountM, Index = 0;
int nEntries = Hash_IntManEntryNum(p);
Vec_Int_t * vAdds = Vec_IntAlloc( 1000 );
Vec_Int_t * vXors = Vec_IntStart( nEntries + 1 );
Vec_Int_t * vMajs = Vec_IntStart( nEntries + 1 );
Vec_Int_t * vIndex = Vec_IntStartFull( nEntries + 1 );
Vec_Int_t * vIndexRev = Vec_IntAlloc( 1000 );
Vec_Wec_t * vXorMap, * vMajMap;
Vec_IntForEachEntryTriple( vData, iObj, Value, Truth, i )
{
assert( Value <= nEntries );
if ( Truth == 0x66 || Truth == 0x99 || Truth == 0x69 || Truth == 0x96 )
Vec_IntAddToEntry( vXors, Value, 1 );
else
Vec_IntAddToEntry( vMajs, Value, 1 );
}
// remap these into indexes
Vec_IntForEachEntryTwo( vXors, vMajs, CountX, CountM, i )
if ( CountX && CountM )
{
Vec_IntPush( vIndexRev, i );
Vec_IntWriteEntry( vIndex, i, Index++ );
}
Vec_IntFree( vXors );
Vec_IntFree( vMajs );
//if ( fVerbose )
// printf( "Detected %d shared cuts among %d hashed cuts.\n", Index, nEntries );
// collect nodes
vXorMap = Vec_WecStart( Index );
vMajMap = Vec_WecStart( Index );
Vec_IntForEachEntryTriple( vData, iObj, Value, Truth, i )
{
Index = Vec_IntEntry( vIndex, Value );
if ( Index == -1 )
continue;
if ( Truth == 0x66 || Truth == 0x99 || Truth == 0x69 || Truth == 0x96 )
Vec_IntPushTwo( Vec_WecEntry(vXorMap, Index), iObj, Truth );
else
Vec_IntPushTwo( Vec_WecEntry(vMajMap, Index), iObj, Truth );
}
Vec_IntFree( vIndex );
// create pairs
Vec_IntForEachEntry( vIndexRev, Value, i )
{
Vec_Int_t * vXorOne = Vec_WecEntry( vXorMap, i );
Vec_Int_t * vMajOne = Vec_WecEntry( vMajMap, i );
Hash_IntObj_t * pObj = Hash_IntObj( p, Value );
Vec_IntForEachEntryDouble( vXorOne, iObj, Truth, j )
Vec_IntForEachEntryDouble( vMajOne, iObj2, Truth2, k )
{
int SignAnd[8] = {0x88, 0x44, 0x22, 0x11, 0x77, 0xBB, 0xDD, 0xEE};
int SignMaj[8] = {0xE8, 0xD4, 0xB2, 0x71, 0x8E, 0x4D, 0x2B, 0x17};
int n, SignXor = (Truth == 0x99 || Truth == 0x69) << 3;
for ( n = 0; n < 8; n++ )
if ( Truth2 == SignMaj[n] )
break;
if ( n == 8 )
for ( n = 0; n < 8; n++ )
if ( Truth2 == SignAnd[n] )
break;
assert( n < 8 );
Vec_IntPushThree( vAdds, pObj->iData0, pObj->iData1, pObj->iData2 );
Vec_IntPushThree( vAdds, iObj, iObj2, SignXor | n );
}
}
Vec_IntFree( vIndexRev );
Vec_WecFree( vXorMap );
Vec_WecFree( vMajMap );
return vAdds;
}
int Ree_ManCompare( int * pCut0, int * pCut1 )
{
if ( pCut0[3] < pCut1[3] ) return -1;
if ( pCut0[3] > pCut1[3] ) return 1;
if ( pCut0[4] < pCut1[4] ) return -1;
if ( pCut0[4] > pCut1[4] ) return 1;
return 0;
}
Vec_Int_t * Ree_ManComputeCuts( Gia_Man_t * p, Vec_Int_t ** pvXors, int fVerbose )
{
extern void Ree_ManRemoveTrivial( Gia_Man_t * p, Vec_Int_t * vAdds );
extern void Ree_ManRemoveContained( Gia_Man_t * p, Vec_Int_t * vAdds );
Gia_Obj_t * pObj;
int * pList0, * pList1, i, nCuts = 0;
Hash_IntMan_t * pHash = Hash_IntManStart( 1000 );
Vec_Int_t * vAdds;
Vec_Int_t * vTemp = Vec_IntAlloc( 1000 );
Vec_Int_t * vData = Vec_IntAlloc( 1000 );
Vec_Int_t * vCuts = Vec_IntAlloc( 30 * Gia_ManAndNum(p) );
Vec_IntFill( vCuts, Gia_ManObjNum(p), 0 );
Gia_ManCleanValue( p );
Gia_ManForEachCi( p, pObj, i )
{
Vec_IntWriteEntry( vCuts, Gia_ObjId(p, pObj), Vec_IntSize(vCuts) );
Vec_IntPush( vCuts, 1 );
Vec_IntPush( vCuts, 1 );
Vec_IntPush( vCuts, Gia_ObjId(p, pObj) );
Vec_IntPush( vCuts, 0xAA );
}
if ( pvXors ) *pvXors = Vec_IntAlloc( 1000 );
Gia_ManForEachAnd( p, pObj, i )
{
pList0 = Vec_IntEntryP( vCuts, Vec_IntEntry(vCuts, Gia_ObjFaninId0(pObj, i)) );
pList1 = Vec_IntEntryP( vCuts, Vec_IntEntry(vCuts, Gia_ObjFaninId1(pObj, i)) );
Ree_ManCutMerge( p, i, pList0, pList1, vTemp, pHash, vData, pvXors ? *pvXors : NULL );
Vec_IntWriteEntry( vCuts, i, Vec_IntSize(vCuts) );
Vec_IntAppend( vCuts, vTemp );
nCuts += Vec_IntEntry( vTemp, 0 );
}
if ( fVerbose )
printf( "AIG nodes = %d. Cuts = %d. Cuts/Node = %.2f. Ints/Node = %.2f.\n",
Gia_ManAndNum(p), nCuts, 1.0*nCuts/Gia_ManAndNum(p), 1.0*Vec_IntSize(vCuts)/Gia_ManAndNum(p) );
Vec_IntFree( vTemp );
Vec_IntFree( vCuts );
vAdds = Ree_ManDeriveAdds( pHash, vData, fVerbose );
qsort( Vec_IntArray(vAdds), (size_t)(Vec_IntSize(vAdds)/6), 24, (int (*)(const void *, const void *))Ree_ManCompare );
if ( fVerbose )
printf( "Adders = %d. Total cuts = %d. Hashed cuts = %d. Hashed/Adders = %.2f.\n",
Vec_IntSize(vAdds)/6, Vec_IntSize(vData)/3, Hash_IntManEntryNum(pHash), 6.0*Hash_IntManEntryNum(pHash)/Vec_IntSize(vAdds) );
Vec_IntFree( vData );
Hash_IntManStop( pHash );
Ree_ManRemoveTrivial( p, vAdds );
Ree_ManRemoveContained( p, vAdds );
//Ree_ManPrintAdders( vAdds, 1 );
return vAdds;
}
/**Function*************************************************************
Synopsis [Highlight nodes inside FAs.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Ree_CollectInsiders_rec( Gia_Man_t * pGia, int iObj, Vec_Bit_t * vVisited, Vec_Bit_t * vInsiders )
{
if ( Vec_BitEntry(vVisited, iObj) )
return;
Vec_BitSetEntry( vVisited, iObj, 1 );
Ree_CollectInsiders_rec( pGia, Gia_ObjFaninId0p(pGia, Gia_ManObj(pGia, iObj)), vVisited, vInsiders );
Ree_CollectInsiders_rec( pGia, Gia_ObjFaninId1p(pGia, Gia_ManObj(pGia, iObj)), vVisited, vInsiders );
Vec_BitSetEntry( vInsiders, iObj, 1 );
}
Vec_Bit_t * Ree_CollectInsiders( Gia_Man_t * pGia, Vec_Int_t * vAdds )
{
Vec_Bit_t * vVisited = Vec_BitStart( Gia_ManObjNum(pGia) );
Vec_Bit_t * vInsiders = Vec_BitStart( Gia_ManObjNum(pGia) );
int i, Entry1, Entry2, Entry3;
for ( i = 0; 6*i < Vec_IntSize(vAdds); i++ )
{
if ( Vec_IntEntry(vAdds, 6*i+2) == 0 ) // HADD
continue;
// mark inputs
Entry1 = Vec_IntEntry( vAdds, 6*i + 0 );
Entry2 = Vec_IntEntry( vAdds, 6*i + 1 );
Entry3 = Vec_IntEntry( vAdds, 6*i + 2 );
Vec_BitWriteEntry( vVisited, Entry1, 1 );
Vec_BitWriteEntry( vVisited, Entry2, 1 );
Vec_BitWriteEntry( vVisited, Entry3, 1 );
// traverse from outputs
Entry1 = Vec_IntEntry( vAdds, 6*i + 3 );
Entry2 = Vec_IntEntry( vAdds, 6*i + 4 );
Ree_CollectInsiders_rec( pGia, Entry1, vVisited, vInsiders );
Ree_CollectInsiders_rec( pGia, Entry2, vVisited, vInsiders );
}
Vec_BitFree( vVisited );
return vInsiders;
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
// removes HAs whose AND2 is part of XOR2 without additional fanout
void Ree_ManRemoveTrivial( Gia_Man_t * p, Vec_Int_t * vAdds )
{
Gia_Obj_t * pObjX, * pObjM;
int i, k = 0;
ABC_FREE( p->pRefs );
Gia_ManCreateRefs( p );
for ( i = 0; 6*i < Vec_IntSize(vAdds); i++ )
{
if ( Vec_IntEntry(vAdds, 6*i+2) == 0 ) // HADD
{
pObjX = Gia_ManObj( p, Vec_IntEntry(vAdds, 6*i+3) );
pObjM = Gia_ManObj( p, Vec_IntEntry(vAdds, 6*i+4) );
// rule out if MAJ is a fanout of XOR
//if ( pObjX == Gia_ObjFanin0(pObjM) || pObjX == Gia_ObjFanin1(pObjM) )
// continue;
// rule out if MAJ is a fanin of XOR and has no other fanouts
if ( (pObjM == Gia_ObjFanin0(pObjX) || pObjM == Gia_ObjFanin1(pObjX)) && Gia_ObjRefNum(p, pObjM) == 1 )
continue;
}
memmove( Vec_IntArray(vAdds) + 6*k++, Vec_IntArray(vAdds) + 6*i, 6*sizeof(int) );
}
assert( k <= i );
Vec_IntShrink( vAdds, 6*k );
}
// removes HAs fully contained inside FAs
void Ree_ManRemoveContained( Gia_Man_t * p, Vec_Int_t * vAdds )
{
Vec_Bit_t * vInsiders = Ree_CollectInsiders( p, vAdds );
int i, k = 0;
for ( i = 0; 6*i < Vec_IntSize(vAdds); i++ )
{
if ( Vec_IntEntry(vAdds, 6*i+2) == 0 ) // HADD
if ( Vec_BitEntry(vInsiders, Vec_IntEntry(vAdds, 6*i+3)) && Vec_BitEntry(vInsiders, Vec_IntEntry(vAdds, 6*i+4)) )
continue;
memmove( Vec_IntArray(vAdds) + 6*k++, Vec_IntArray(vAdds) + 6*i, 6*sizeof(int) );
}
assert( k <= i );
Vec_IntShrink( vAdds, 6*k );
Vec_BitFree( vInsiders );
}
int Ree_ManCountFadds( Vec_Int_t * vAdds )
{
int i, Count = 0;
for ( i = 0; 6*i < Vec_IntSize(vAdds); i++ )
if ( Vec_IntEntry(vAdds, 6*i+2) != 0 )
Count++;
return Count;
}
void Ree_ManPrintAdders( Vec_Int_t * vAdds, int fVerbose )
{
int i;
for ( i = 0; 6*i < Vec_IntSize(vAdds); i++ )
{
//if ( Vec_IntEntry(vAdds, 6*i+2) == 0 )
// continue;
if ( !fVerbose )
continue;
printf( "%6d : ", i );
printf( "%6d ", Vec_IntEntry(vAdds, 6*i+0) );
printf( "%6d ", Vec_IntEntry(vAdds, 6*i+1) );
printf( "%6d ", Vec_IntEntry(vAdds, 6*i+2) );
printf( " -> " );
printf( "%6d ", Vec_IntEntry(vAdds, 6*i+3) );
printf( "%6d ", Vec_IntEntry(vAdds, 6*i+4) );
printf( " (%d)", Vec_IntEntry(vAdds, 6*i+5) );
printf( "\n" );
}
}
void Ree_ManComputeCutsTest( Gia_Man_t * p )
{
abctime clk = Abc_Clock();
Vec_Int_t * vAdds = Ree_ManComputeCuts( p, NULL, 1 );
int nFadds = Ree_ManCountFadds( vAdds );
Ree_ManPrintAdders( vAdds, 1 );
printf( "Detected %d FAs and %d HAs. ", nFadds, Vec_IntSize(vAdds)/6-nFadds );
Vec_IntFree( vAdds );
Abc_PrintTime( 1, "Time", Abc_Clock() - clk );
}
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////
ABC_NAMESPACE_IMPL_END
|
4065a9b61a7e68ea1f8b8c606adbf782b58ca9f3
|
50dd46b8ece33f3cdd174284b15d1d51f89669d4
|
/2017/quals/2017-re-counting/src/compiler.c
|
01e47efc7e7e1accdcc75d89d749bb050d8858db
|
[
"LicenseRef-scancode-generic-cla",
"Apache-2.0"
] |
permissive
|
google/google-ctf
|
f99da1ee07729bbccb869fff1cbaed6a80e43bcc
|
df02323eaf945d15e124801c74abaadca2749dc7
|
refs/heads/master
| 2023-08-31T14:30:27.548081
| 2023-08-29T13:04:20
| 2023-08-29T13:04:20
| 131,317,137
| 4,136
| 607
|
Apache-2.0
| 2023-08-30T22:17:02
| 2018-04-27T15:56:03
|
Go
|
UTF-8
|
C
| false
| false
| 8,208
|
c
|
compiler.c
|
/*
* Copyright 2018 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define INC 0
#define DECJMP 1
#define FRA 2
typedef unsigned char byte;
struct incIns {
byte r;
unsigned int next;
};
struct decJmpIns {
byte r;
unsigned int nextNonZ;
unsigned int nextZ;
};
struct fraIns {
// This is the amount of nodes to save when coming back from the new frame.
unsigned int amo;
// This is the node to jump to for the new frame.
unsigned int frameNext;
unsigned int next;
};
union inst {
struct incIns inc;
struct decJmpIns decJmp;
struct fraIns fra;
};
struct node {
unsigned int type;
union inst ins;
};
typedef struct mapNode *MapNode;
struct mapNode {
MapNode next[27];
int hasOne;
};
int numLines;
char lines[1000][100];
int firstNode[1000];
char unres[1000][100];
int upTo;
struct node outputNodes[100000];
MapNode rootNode;
int beginsWith(char *line, char *str) {
return strncmp(line, str, strlen(str)) == 0;
}
MapNode newMapNode() {
MapNode n = malloc(sizeof (struct mapNode));
int i;
for (i = 0; i < 27; i++) {
n->next[i] = NULL;
}
n->hasOne = -1;
return n;
}
void addToMap(int at) {
MapNode cur = rootNode;
char *name = &lines[at][1];
int i;
for (i = 0; (name[i] >= 'a' && name[i] <= 'z') || name[i] == '_'; i++) {
int v = name[i] - 'a';
if (name[i] == '_') {
v = 26;
}
if (cur->next[v] == NULL) {
cur->next[v] = newMapNode();
}
cur = cur->next[v];
}
if (cur->hasOne != -1) {
printf ("Multiple defined names: %d\n", at);
return;
}
cur->hasOne = at;
}
int getName(char *name) {
MapNode at = rootNode;
int i;
for (i = 0; (name[i] >= 'a' && name[i] <= 'z') || name[i] == '_'; i++) {
int v = name[i] - 'a';
if (name[i] == '_') {
v = 26;
}
if (at->next[v] == NULL) {
return -1;
}
at = at->next[v];
}
return at->hasOne;
}
void addInc(int at) {
char *line = lines[at];
char r;
if (sscanf (line, "inc %c ", &r) != 1) {
printf("Could not parse inc: %d\n", at);
return;
}
if (r < 'a' || r > 'z') {
printf ("Invalid reg %d\n", at);
return;
}
firstNode[at] = upTo;
struct node *n = &outputNodes[upTo++];
n->type = INC;
n->ins.inc.r = r - 'a';
}
void addDecJmp(int at) {
char *line = lines[at];
char r;
if (sscanf (line, "decjmp %c %s ", &r, unres[at]) != 2) {
printf("Could not parse decjmp: %d\n", at);
return;
}
if (r < 'a' || r > 'z') {
printf ("Invalid reg %d\n", at);
return;
}
firstNode[at] = upTo;
struct node *n = &outputNodes[upTo++];
n->type = DECJMP;
n->ins.decJmp.r = r - 'a';
}
void addCall(int at) {
char *line = lines[at];
int numS;
if (sscanf (line, "call %d %s ", &numS, unres[at]) != 2) {
printf("Could not parse call: %d\n", at);
return;
}
if (numS < 0 || numS > 26) {
printf ("Invalid num sav %d\n", at);
return;
}
firstNode[at] = upTo;
struct node *n = &outputNodes[upTo++];
n->type = FRA;
n->ins.fra.amo = numS;
}
void addRet(int at) {
firstNode[at] = -1;
}
void addClr(int at) {
char *line = lines[at];
char r;
if (sscanf (line, "clr %c ", &r) != 1) {
printf("Could not parse clr: %d\n", at);
return;
}
if (r < 'a' || r > 'z') {
printf ("Invalid reg %d\n", at);
return;
}
firstNode[at] = upTo;
struct node *n = &outputNodes[upTo++];
n->type = DECJMP;
n->ins.decJmp.r = r - 'a';
n->ins.decJmp.nextNonZ = firstNode[at];
}
void addJmp(int at) {
char *line = lines[at];
if (sscanf (line, "jmp %s ", unres[at]) != 1) {
printf("Could not parse jmp: %d\n", at);
return;
}
firstNode[at] = upTo;
struct node *n = &outputNodes[upTo++];
n->type = DECJMP;
n->ins.decJmp.r = 25;
n->ins.decJmp.nextNonZ = 0;
}
void addAdd(int at) {
char *line = lines[at];
char r1;
char r2;
if (sscanf (line, "add %c %c ", &r1, &r2) != 2) {
printf("Could not parse add: %d\n", at);
return;
}
if (r1 < 'a' || r1 > 'z' || r2 < 'a' || r2 > 'z') {
printf ("Invalid reg %d\n", at);
return;
}
firstNode[at] = upTo;
struct node *n1 = &outputNodes[upTo++];
struct node *n2 = &outputNodes[upTo++];
n1->type = DECJMP;
n1->ins.decJmp.r = r2 - 'a';
n1->ins.decJmp.nextNonZ = firstNode[at] + 1;
n2->type = INC;
n2->ins.inc.r = r1 - 'a';
n2->ins.inc.next = firstNode[at];
}
void fillInLine(int at) {
char *line = lines[at];
if (line[0] == ':') {
addToMap(at);
firstNode[at] = -2;
return;
}
if (line[0] == '#') {
firstNode[at] = -2;
return;
}
if (beginsWith(line, "inc")) {
addInc(at);
} else if (beginsWith(line, "decjmp")) {
addDecJmp(at);
} else if (beginsWith(line, "call")) {
addCall(at);
} else if (beginsWith(line, "ret")) {
addRet(at);
} else if (beginsWith(line, "clr")) {
addClr(at);
} else if (beginsWith(line, "jmp")) {
addJmp(at);
} else if (beginsWith(line, "add")) {
addAdd(at);
} else {
printf ("Unknown line: %d\n", at);
return;
}
}
void fixUpLine(int at) {
char *line = lines[at];
if (line[0] == ':' || line[0] == '#') {
return;
}
int goTo = firstNode[at + 1];
if (goTo == -1) {
goTo = upTo;
}
if (beginsWith(line, "inc")) {
outputNodes[firstNode[at]].ins.inc.next = goTo;
} else if (beginsWith(line, "decjmp")) {
int bit = getName(unres[at]);
if (bit == -1) {
printf ("Could not resolve name for %d\n", at);
return;
}
bit = firstNode[bit];
if (bit == -1) {
bit = upTo;
}
outputNodes[firstNode[at]].ins.decJmp.nextZ = bit;
outputNodes[firstNode[at]].ins.decJmp.nextNonZ = goTo;
} else if (beginsWith(line, "call")) {
int bit = getName(unres[at]);
if (bit == -1) {
printf ("Could not resolve name for %d\n", at);
return;
}
bit = firstNode[bit];
if (bit == -1) {
bit = upTo;
}
outputNodes[firstNode[at]].ins.fra.frameNext = bit;
outputNodes[firstNode[at]].ins.fra.next = goTo;
} else if (beginsWith(line, "clr")) {
outputNodes[firstNode[at]].ins.decJmp.nextZ = goTo;
} else if (beginsWith(line, "jmp")) {
int bit = getName(unres[at]);
if (bit == -1) {
printf ("Could not resolve name for %d\n", at);
return;
}
bit = firstNode[bit];
if (bit == -1) {
bit = upTo;
}
outputNodes[firstNode[at]].ins.decJmp.nextZ = bit;
} else if (beginsWith(line, "add")) {
outputNodes[firstNode[at]].ins.decJmp.nextZ = goTo;
}
}
int main() {
while (!feof(stdin)) {
fgets(lines[numLines++], 100, stdin);
if (lines[numLines - 1][0] == '\n' || lines[numLines - 1][0] == 0) {
numLines--;
}
}
int i;
rootNode = newMapNode();
for (i = 0; i < numLines; i++) {
fillInLine(i);
}
for (i = numLines - 1; i >= 0; i--) {
if (firstNode[i] == -2) {
firstNode[i] = firstNode[i + 1];
}
}
for (i = 0; i < numLines; i++) {
fixUpLine(i);
}
unsigned int numNodes = upTo;
FILE* f = fopen("code", "wb");
fwrite(&numNodes, 4, 1, f);
for (i = 0; i < numNodes; i++) {
fwrite(&outputNodes[i], sizeof (struct node), 1, f);
}
fclose(f);
/*
for (i = 0; i < numNodes; i++) {
struct node *n = &outputNodes[i];
if (n->type == INC) {
printf ("%d inc %d %d\n", i, n->ins.inc.r, n->ins.inc.next);
}
if (n->type == DECJMP) {
printf ("%d decjmp %d %d %d\n", i, n->ins.decJmp.r, n->ins.decJmp.nextNonZ, n->ins.decJmp.nextZ);
}
if (n->type == FRA) {
printf ("%d fra %d %d %d\n", i, n->ins.fra.amo, n->ins.fra.frameNext, n->ins.fra.next);
}
}
*/
return 0;
}
|
501d18f6e1fd1bd123894daf02d620ee9fb337da
|
9de18ef120a8ae68483b866c1d4c7b9c2fbef46e
|
/third_party/libcutils/include/cutils/sockets.h
|
be21a8f7f752b69aec55879ab44c7d9f7e97fea1
|
[
"Apache-2.0",
"BSD-2-Clause",
"LicenseRef-scancode-free-unknown"
] |
permissive
|
google/orbit
|
02a5b4556cd2f979f377b87c24dd2b0a90dff1e2
|
68c4ae85a6fe7b91047d020259234f7e4961361c
|
refs/heads/main
| 2023-09-03T13:14:49.830576
| 2023-08-25T06:28:36
| 2023-08-25T06:28:36
| 104,358,587
| 2,680
| 325
|
BSD-2-Clause
| 2023-08-25T06:28:37
| 2017-09-21T14:28:35
|
C++
|
UTF-8
|
C
| false
| false
| 4,405
|
h
|
sockets.h
|
/*
* Copyright (C) 2006 The Android Open Source Project
*
* 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.
*/
#pragma once
#include <errno.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#if defined(_WIN32)
#include <winsock2.h>
#include <ws2tcpip.h>
typedef int socklen_t;
typedef SOCKET cutils_socket_t;
#else
#include <sys/socket.h>
#include <netinet/in.h>
typedef int cutils_socket_t;
#define INVALID_SOCKET (-1)
#endif
#define ANDROID_SOCKET_ENV_PREFIX "ANDROID_SOCKET_"
#define ANDROID_SOCKET_DIR "/dev/socket"
#ifdef __cplusplus
extern "C" {
#endif
/*
* android_get_control_socket - simple helper function to get the file
* descriptor of our init-managed Unix domain socket. `name' is the name of the
* socket, as given in init.rc. Returns -1 on error.
*/
int android_get_control_socket(const char* name);
/*
* See also android.os.LocalSocketAddress.Namespace
*/
// Linux "abstract" (non-filesystem) namespace
#define ANDROID_SOCKET_NAMESPACE_ABSTRACT 0
// Android "reserved" (/dev/socket) namespace
#define ANDROID_SOCKET_NAMESPACE_RESERVED 1
// Normal filesystem namespace
#define ANDROID_SOCKET_NAMESPACE_FILESYSTEM 2
/*
* Functions to create sockets for some common usages.
*
* All these functions are implemented for Unix, but only a few are implemented
* for Windows. Those which are can be identified by the cutils_socket_t
* return type. The idea is to be able to use this return value with the
* standard Unix socket functions on any platform.
*
* On Unix the returned cutils_socket_t is a standard int file descriptor and
* can always be used as normal with all file descriptor functions.
*
* On Windows utils_socket_t is an unsigned int pointer, and is only valid
* with functions that specifically take a socket, e.g. send(), sendto(),
* recv(), and recvfrom(). General file descriptor functions such as read(),
* write(), and close() will not work with utils_socket_t and will require
* special handling.
*
* These functions return INVALID_SOCKET (-1) on failure for all platforms.
*/
cutils_socket_t socket_network_client(const char* host, int port, int type);
int socket_network_client_timeout(const char* host, int port, int type,
int timeout, int* getaddrinfo_error);
int socket_local_server(const char* name, int namespaceId, int type);
int socket_local_server_bind(int s, const char* name, int namespaceId);
int socket_local_client_connect(int fd, const char *name, int namespaceId,
int type);
int socket_local_client(const char* name, int namespaceId, int type);
cutils_socket_t socket_inaddr_any_server(int port, int type);
/*
* Closes a cutils_socket_t. Windows doesn't allow calling close() on a socket
* so this is a cross-platform way to close a cutils_socket_t.
*
* Returns 0 on success.
*/
int socket_close(cutils_socket_t sock);
/*
* Returns the local port the socket is bound to or -1 on error.
*/
int socket_get_local_port(cutils_socket_t sock);
/*
* Sends to a socket from multiple buffers; wraps writev() on Unix or WSASend()
* on Windows. This can give significant speedup compared to calling send()
* multiple times.
*
* Example usage:
* cutils_socket_buffer_t buffers[2] = { {data0, len0}, {data1, len1} };
* socket_send_buffers(sock, buffers, 2);
*
* If you try to pass more than SOCKET_SEND_BUFFERS_MAX_BUFFERS buffers into
* this function it will return -1 without sending anything.
*
* Returns the number of bytes written or -1 on error.
*/
typedef struct {
const void* data;
size_t length;
} cutils_socket_buffer_t;
#define SOCKET_SEND_BUFFERS_MAX_BUFFERS 16
ssize_t socket_send_buffers(cutils_socket_t sock,
const cutils_socket_buffer_t* buffers,
size_t num_buffers);
#ifdef __cplusplus
}
#endif
|
57c73233d5633e3590487f70cf41000dce026ba6
|
2dfc2beac0ad497f8fc59201921097a412f0df7f
|
/trunk/3rdparty/openssl-1.1-fit/include/internal/cryptlib.h
|
6e7291ae41bc35ad4dab4f6df14e859f3d959dd2
|
[
"OpenSSL",
"JSON",
"Apache-2.0",
"LicenseRef-scancode-mulanpsl-2.0-en",
"MIT",
"MulanPSL-2.0",
"LicenseRef-scancode-unknown-license-reference"
] |
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
| 2,982
|
h
|
cryptlib.h
|
/*
* Copyright 1995-2019 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/
#ifndef OSSL_INTERNAL_CRYPTLIB_H
# define OSSL_INTERNAL_CRYPTLIB_H
# include <stdlib.h>
# include <string.h>
# ifdef OPENSSL_USE_APPLINK
# undef BIO_FLAGS_UPLINK
# define BIO_FLAGS_UPLINK 0x8000
# include "ms/uplink.h"
# endif
# include <openssl/crypto.h>
# include <openssl/buffer.h>
# include <openssl/bio.h>
# include <openssl/err.h>
# include "internal/nelem.h"
#ifdef NDEBUG
# define ossl_assert(x) ((x) != 0)
#else
__owur static ossl_inline int ossl_assert_int(int expr, const char *exprstr,
const char *file, int line)
{
if (!expr)
OPENSSL_die(exprstr, file, line);
return expr;
}
# define ossl_assert(x) ossl_assert_int((x) != 0, "Assertion failed: "#x, \
__FILE__, __LINE__)
#endif
typedef struct ex_callback_st EX_CALLBACK;
DEFINE_STACK_OF(EX_CALLBACK)
typedef struct app_mem_info_st APP_INFO;
typedef struct mem_st MEM;
DEFINE_LHASH_OF(MEM);
# define OPENSSL_CONF "openssl.cnf"
# ifndef OPENSSL_SYS_VMS
# define X509_CERT_AREA OPENSSLDIR
# define X509_CERT_DIR OPENSSLDIR "/certs"
# define X509_CERT_FILE OPENSSLDIR "/cert.pem"
# define X509_PRIVATE_DIR OPENSSLDIR "/private"
# define CTLOG_FILE OPENSSLDIR "/ct_log_list.cnf"
# else
# define X509_CERT_AREA "OSSL$DATAROOT:[000000]"
# define X509_CERT_DIR "OSSL$DATAROOT:[CERTS]"
# define X509_CERT_FILE "OSSL$DATAROOT:[000000]cert.pem"
# define X509_PRIVATE_DIR "OSSL$DATAROOT:[PRIVATE]"
# define CTLOG_FILE "OSSL$DATAROOT:[000000]ct_log_list.cnf"
# endif
# define X509_CERT_DIR_EVP "SSL_CERT_DIR"
# define X509_CERT_FILE_EVP "SSL_CERT_FILE"
# define CTLOG_FILE_EVP "CTLOG_FILE"
/* size of string representations */
# define DECIMAL_SIZE(type) ((sizeof(type)*8+2)/3+1)
# define HEX_SIZE(type) (sizeof(type)*2)
void OPENSSL_cpuid_setup(void);
extern unsigned int OPENSSL_ia32cap_P[];
void OPENSSL_showfatal(const char *fmta, ...);
void crypto_cleanup_all_ex_data_int(void);
int openssl_init_fork_handlers(void);
int openssl_get_fork_id(void);
char *ossl_safe_getenv(const char *name);
extern CRYPTO_RWLOCK *memdbg_lock;
int openssl_strerror_r(int errnum, char *buf, size_t buflen);
# if !defined(OPENSSL_NO_STDIO)
FILE *openssl_fopen(const char *filename, const char *mode);
# else
void *openssl_fopen(const char *filename, const char *mode);
# endif
uint32_t OPENSSL_rdtsc(void);
size_t OPENSSL_instrument_bus(unsigned int *, size_t);
size_t OPENSSL_instrument_bus2(unsigned int *, size_t, size_t);
#endif
|
3f76b3400aade72bdf93ac8550266571e42dc726
|
99bdb3251fecee538e0630f15f6574054dfc1468
|
/bsp/wch/risc-v/Libraries/ch32v30x_libraries/ch32v307_hal/source/ch32v30x_flash.c
|
8a5baa4836ae13477b4d8fb19f760426e73272b3
|
[
"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
| 27,133
|
c
|
ch32v30x_flash.c
|
/********************************** (C) COPYRIGHT *******************************
* File Name : ch32v30x_flash.c
* Author : WCH
* Version : V1.0.0
* Date : 2021/06/06
* Description : This file provides all the FLASH firmware functions.
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* SPDX-License-Identifier: Apache-2.0
***************************************************************************************/
#include "ch32v30x_flash.h"
/* Flash Control Register bits */
#define CR_PG_Set ((uint32_t)0x00000001)
#define CR_PG_Reset ((uint32_t)0x00001FFE)
#define CR_PER_Set ((uint32_t)0x00000002)
#define CR_PER_Reset ((uint32_t)0x00001FFD)
#define CR_MER_Set ((uint32_t)0x00000004)
#define CR_MER_Reset ((uint32_t)0x00001FFB)
#define CR_OPTPG_Set ((uint32_t)0x00000010)
#define CR_OPTPG_Reset ((uint32_t)0x00001FEF)
#define CR_OPTER_Set ((uint32_t)0x00000020)
#define CR_OPTER_Reset ((uint32_t)0x00001FDF)
#define CR_STRT_Set ((uint32_t)0x00000040)
#define CR_LOCK_Set ((uint32_t)0x00000080)
#define CR_FAST_LOCK_Set ((uint32_t)0x00008000)
#define CR_PAGE_PG ((uint32_t)0x00010000)
#define CR_PAGE_ER ((uint32_t)0x00020000)
#define CR_BER32 ((uint32_t)0x00040000)
#define CR_BER64 ((uint32_t)0x00080000)
#define CR_PG_STRT ((uint32_t)0x00200000)
/* FLASH Status Register bits */
#define SR_BSY ((uint32_t)0x00000001)
#define SR_WR_BSY ((uint32_t)0x00000002)
#define SR_WRPRTERR ((uint32_t)0x00000010)
#define SR_EOP ((uint32_t)0x00000020)
/* FLASH Mask */
#define RDPRT_Mask ((uint32_t)0x00000002)
#define WRP0_Mask ((uint32_t)0x000000FF)
#define WRP1_Mask ((uint32_t)0x0000FF00)
#define WRP2_Mask ((uint32_t)0x00FF0000)
#define WRP3_Mask ((uint32_t)0xFF000000)
#define OB_USER_BFB2 ((uint16_t)0x0008)
/* FLASH Keys */
#define RDP_Key ((uint16_t)0x00A5)
#define FLASH_KEY1 ((uint32_t)0x45670123)
#define FLASH_KEY2 ((uint32_t)0xCDEF89AB)
/* FLASH BANK address */
#define FLASH_BANK1_END_ADDRESS ((uint32_t)0x807FFFF)
/* Delay definition */
#define EraseTimeout ((uint32_t)0x000B0000)
#define ProgramTimeout ((uint32_t)0x00005000)
/*********************************************************************
* @fn FLASH_Unlock
*
* @brief Unlocks the FLASH Program Erase Controller.
*
* @return none
*/
void FLASH_Unlock(void)
{
/* Authorize the FPEC of Bank1 Access */
FLASH->KEYR = FLASH_KEY1;
FLASH->KEYR = FLASH_KEY2;
}
/*********************************************************************
* @fn FLASH_UnlockBank1
*
* @brief Unlocks the FLASH Bank1 Program Erase Controller.
* equivalent to FLASH_Unlock function.
*
* @return none
*/
void FLASH_UnlockBank1(void)
{
FLASH->KEYR = FLASH_KEY1;
FLASH->KEYR = FLASH_KEY2;
}
/*********************************************************************
* @fn FLASH_Lock
*
* @brief Locks the FLASH Program Erase Controller.
*
* @return none
*/
void FLASH_Lock(void)
{
FLASH->CTLR |= CR_LOCK_Set;
}
/*********************************************************************
* @fn FLASH_LockBank1
*
* @brief Locks the FLASH Bank1 Program Erase Controller.
*
* @return none
*/
void FLASH_LockBank1(void)
{
FLASH->CTLR |= CR_LOCK_Set;
}
/*********************************************************************
* @fn FLASH_ErasePage
*
* @brief Erases a specified FLASH page(page size 4KB).
*
* @param Page_Address - The page address to be erased.
*
* @return FLASH Status - The returned value can be: FLASH_BUSY, FLASH_ERROR_PG,
* FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
*/
FLASH_Status FLASH_ErasePage(uint32_t Page_Address)
{
FLASH_Status status = FLASH_COMPLETE;
status = FLASH_WaitForLastOperation(EraseTimeout);
if(status == FLASH_COMPLETE)
{
FLASH->CTLR |= CR_PER_Set;
FLASH->ADDR = Page_Address;
FLASH->CTLR |= CR_STRT_Set;
status = FLASH_WaitForLastOperation(EraseTimeout);
FLASH->CTLR &= CR_PER_Reset;
}
return status;
}
/*********************************************************************
* @fn FLASH_EraseAllPages
*
* @brief Erases all FLASH pages.
*
* @return FLASH Status - The returned value can be: FLASH_BUSY, FLASH_ERROR_PG,
* FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
*/
FLASH_Status FLASH_EraseAllPages(void)
{
FLASH_Status status = FLASH_COMPLETE;
status = FLASH_WaitForLastOperation(EraseTimeout);
if(status == FLASH_COMPLETE)
{
FLASH->CTLR |= CR_MER_Set;
FLASH->CTLR |= CR_STRT_Set;
status = FLASH_WaitForLastOperation(EraseTimeout);
FLASH->CTLR &= CR_MER_Reset;
}
return status;
}
/*********************************************************************
* @fn FLASH_EraseAllBank1Pages
*
* @brief Erases all Bank1 FLASH pages.
*
* @return FLASH Status - The returned value can be: FLASH_BUSY, FLASH_ERROR_PG,
* FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
*/
FLASH_Status FLASH_EraseAllBank1Pages(void)
{
FLASH_Status status = FLASH_COMPLETE;
status = FLASH_WaitForLastBank1Operation(EraseTimeout);
if(status == FLASH_COMPLETE)
{
FLASH->CTLR |= CR_MER_Set;
FLASH->CTLR |= CR_STRT_Set;
status = FLASH_WaitForLastBank1Operation(EraseTimeout);
FLASH->CTLR &= CR_MER_Reset;
}
return status;
}
/*********************************************************************
* @fn FLASH_EraseOptionBytes
*
* @brief Erases the FLASH option bytes.
*
* @return FLASH Status - The returned value can be: FLASH_BUSY, FLASH_ERROR_PG,
* FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
*/
FLASH_Status FLASH_EraseOptionBytes(void)
{
uint16_t rdptmp = RDP_Key;
uint32_t Address = 0x1FFFF800;
__IO uint8_t i;
FLASH_Status status = FLASH_COMPLETE;
if(FLASH_GetReadOutProtectionStatus() != RESET)
{
rdptmp = 0x00;
}
status = FLASH_WaitForLastOperation(EraseTimeout);
if(status == FLASH_COMPLETE)
{
FLASH->OBKEYR = FLASH_KEY1;
FLASH->OBKEYR = FLASH_KEY2;
FLASH->CTLR |= CR_OPTER_Set;
FLASH->CTLR |= CR_STRT_Set;
status = FLASH_WaitForLastOperation(EraseTimeout);
if(status == FLASH_COMPLETE)
{
FLASH->CTLR &= CR_OPTER_Reset;
FLASH->CTLR |= CR_OPTPG_Set;
OB->RDPR = (uint16_t)rdptmp;
status = FLASH_WaitForLastOperation(ProgramTimeout);
if(status != FLASH_TIMEOUT)
{
FLASH->CTLR &= CR_OPTPG_Reset;
}
}
else
{
if(status != FLASH_TIMEOUT)
{
FLASH->CTLR &= CR_OPTPG_Reset;
}
}
/* Write 0xFF */
FLASH->CTLR |= CR_OPTPG_Set;
for(i = 0; i < 8; i++)
{
*(uint16_t *)(Address + 2 * i) = 0x00FF;
while(FLASH->STATR & SR_BSY)
;
}
FLASH->CTLR &= ~CR_OPTPG_Set;
}
return status;
}
/*********************************************************************
* @fn FLASH_ProgramWord
*
* @brief Programs a word at a specified address.
*
* @param Address - specifies the address to be programmed.
* Data - specifies the data to be programmed.
*
* @return FLASH Status - The returned value can be: FLASH_BUSY, FLASH_ERROR_PG,
* FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
*/
FLASH_Status FLASH_ProgramWord(uint32_t Address, uint32_t Data)
{
FLASH_Status status = FLASH_COMPLETE;
__IO uint32_t tmp = 0;
status = FLASH_WaitForLastOperation(ProgramTimeout);
if(status == FLASH_COMPLETE)
{
FLASH->CTLR |= CR_PG_Set;
*(__IO uint16_t *)Address = (uint16_t)Data;
status = FLASH_WaitForLastOperation(ProgramTimeout);
if(status == FLASH_COMPLETE)
{
tmp = Address + 2;
*(__IO uint16_t *)tmp = Data >> 16;
status = FLASH_WaitForLastOperation(ProgramTimeout);
FLASH->CTLR &= CR_PG_Reset;
}
else
{
FLASH->CTLR &= CR_PG_Reset;
}
}
return status;
}
/*********************************************************************
* @fn FLASH_ProgramHalfWord
*
* @brief Programs a half word at a specified address.
*
* @param Address - specifies the address to be programmed.
* Data - specifies the data to be programmed.
*
* @return FLASH Status - The returned value can be: FLASH_BUSY, FLASH_ERROR_PG,
* FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
*/
FLASH_Status FLASH_ProgramHalfWord(uint32_t Address, uint16_t Data)
{
FLASH_Status status = FLASH_COMPLETE;
status = FLASH_WaitForLastOperation(ProgramTimeout);
if(status == FLASH_COMPLETE)
{
FLASH->CTLR |= CR_PG_Set;
*(__IO uint16_t *)Address = Data;
status = FLASH_WaitForLastOperation(ProgramTimeout);
FLASH->CTLR &= CR_PG_Reset;
}
return status;
}
/*********************************************************************
* @fn FLASH_ProgramOptionByteData
*
* @brief Programs a half word at a specified Option Byte Data address.
*
* @param Address - specifies the address to be programmed.
* Data - specifies the data to be programmed.
*
* @return FLASH Status - The returned value can be: FLASH_BUSY, FLASH_ERROR_PG,
* FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
*/
FLASH_Status FLASH_ProgramOptionByteData(uint32_t Address, uint8_t Data)
{
FLASH_Status status = FLASH_COMPLETE;
uint32_t Addr = 0x1FFFF800;
__IO uint8_t i;
uint16_t pbuf[8];
status = FLASH_WaitForLastOperation(ProgramTimeout);
if(status == FLASH_COMPLETE)
{
FLASH->OBKEYR = FLASH_KEY1;
FLASH->OBKEYR = FLASH_KEY2;
/* Read optionbytes */
for(i = 0; i < 8; i++)
{
pbuf[i] = *(uint16_t *)(Addr + 2 * i);
}
/* Erase optionbytes */
FLASH->CTLR |= CR_OPTER_Set;
FLASH->CTLR |= CR_STRT_Set;
while(FLASH->STATR & SR_BSY)
;
FLASH->CTLR &= ~CR_OPTER_Set;
/* Write optionbytes */
pbuf[((Address - 0x1FFFF800) / 2)] = ((((uint16_t) ~(Data)) << 8) | ((uint16_t)Data));
FLASH->CTLR |= CR_OPTPG_Set;
for(i = 0; i < 8; i++)
{
*(uint16_t *)(Addr + 2 * i) = pbuf[i];
while(FLASH->STATR & SR_BSY)
;
}
FLASH->CTLR &= ~CR_OPTPG_Set;
}
return status;
}
/*********************************************************************
* @fn FLASH_EnableWriteProtection
*
* @brief Write protects the desired sectors
*
* @param FLASH_Sectors - specifies the address of the pages to be write protected.
*
* @return FLASH Status - The returned value can be: FLASH_BUSY, FLASH_ERROR_PG,
* FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
*/
FLASH_Status FLASH_EnableWriteProtection(uint32_t FLASH_Sectors)
{
uint16_t WRP0_Data = 0xFFFF, WRP1_Data = 0xFFFF, WRP2_Data = 0xFFFF, WRP3_Data = 0xFFFF;
FLASH_Status status = FLASH_COMPLETE;
uint32_t Addr = 0x1FFFF800;
__IO uint8_t i;
uint16_t pbuf[8];
FLASH_Sectors = (uint32_t)(~FLASH_Sectors);
WRP0_Data = (uint16_t)(FLASH_Sectors & WRP0_Mask);
WRP1_Data = (uint16_t)((FLASH_Sectors & WRP1_Mask) >> 8);
WRP2_Data = (uint16_t)((FLASH_Sectors & WRP2_Mask) >> 16);
WRP3_Data = (uint16_t)((FLASH_Sectors & WRP3_Mask) >> 24);
status = FLASH_WaitForLastOperation(ProgramTimeout);
if(status == FLASH_COMPLETE)
{
FLASH->OBKEYR = FLASH_KEY1;
FLASH->OBKEYR = FLASH_KEY2;
/* Read optionbytes */
for(i = 0; i < 8; i++)
{
pbuf[i] = *(uint16_t *)(Addr + 2 * i);
}
/* Erase optionbytes */
FLASH->CTLR |= CR_OPTER_Set;
FLASH->CTLR |= CR_STRT_Set;
while(FLASH->STATR & SR_BSY)
;
FLASH->CTLR &= ~CR_OPTER_Set;
/* Write optionbytes */
pbuf[4] = WRP0_Data;
pbuf[5] = WRP1_Data;
pbuf[6] = WRP2_Data;
pbuf[7] = WRP3_Data;
FLASH->CTLR |= CR_OPTPG_Set;
for(i = 0; i < 8; i++)
{
*(uint16_t *)(Addr + 2 * i) = pbuf[i];
while(FLASH->STATR & SR_BSY)
;
}
FLASH->CTLR &= ~CR_OPTPG_Set;
}
return status;
}
/*********************************************************************
* @fn FLASH_ReadOutProtection
*
* @brief Enables or disables the read out protection.
*
* @param Newstate - new state of the ReadOut Protection(ENABLE or DISABLE).
*
* @return FLASH Status - The returned value can be: FLASH_BUSY, FLASH_ERROR_PG,
* FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
*/
FLASH_Status FLASH_ReadOutProtection(FunctionalState NewState)
{
FLASH_Status status = FLASH_COMPLETE;
uint32_t Addr = 0x1FFFF800;
__IO uint8_t i;
uint16_t pbuf[8];
status = FLASH_WaitForLastOperation(EraseTimeout);
if(status == FLASH_COMPLETE)
{
FLASH->OBKEYR = FLASH_KEY1;
FLASH->OBKEYR = FLASH_KEY2;
/* Read optionbytes */
for(i = 0; i < 8; i++)
{
pbuf[i] = *(uint16_t *)(Addr + 2 * i);
}
/* Erase optionbytes */
FLASH->CTLR |= CR_OPTER_Set;
FLASH->CTLR |= CR_STRT_Set;
while(FLASH->STATR & SR_BSY)
;
FLASH->CTLR &= ~CR_OPTER_Set;
/* Write optionbytes */
if(NewState == DISABLE)
pbuf[0] = 0x5AA5;
else
pbuf[0] = 0x00FF;
FLASH->CTLR |= CR_OPTPG_Set;
for(i = 0; i < 8; i++)
{
*(uint16_t *)(Addr + 2 * i) = pbuf[i];
while(FLASH->STATR & SR_BSY)
;
}
FLASH->CTLR &= ~CR_OPTPG_Set;
}
return status;
}
/*********************************************************************
* @fn FLASH_UserOptionByteConfig
*
* @brief Programs the FLASH User Option Byte - IWDG_SW / RST_STOP / RST_STDBY.
*
* @param OB_IWDG - Selects the IWDG mode
* OB_IWDG_SW - Software IWDG selected
* OB_IWDG_HW - Hardware IWDG selected
* OB_STOP - Reset event when entering STOP mode.
* OB_STOP_NoRST - No reset generated when entering in STOP
* OB_STOP_RST - Reset generated when entering in STOP
* OB_STDBY - Reset event when entering Standby mode.
* OB_STDBY_NoRST - No reset generated when entering in STANDBY
* OB_STDBY_RST - Reset generated when entering in STANDBY
*
* @return FLASH Status - The returned value can be: FLASH_BUSY, FLASH_ERROR_PG,
* FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
*/
FLASH_Status FLASH_UserOptionByteConfig(uint16_t OB_IWDG, uint16_t OB_STOP, uint16_t OB_STDBY)
{
FLASH_Status status = FLASH_COMPLETE;
uint32_t Addr = 0x1FFFF800;
__IO uint8_t i;
uint16_t pbuf[8];
FLASH->OBKEYR = FLASH_KEY1;
FLASH->OBKEYR = FLASH_KEY2;
status = FLASH_WaitForLastOperation(ProgramTimeout);
if(status == FLASH_COMPLETE)
{
/* Read optionbytes */
for(i = 0; i < 8; i++)
{
pbuf[i] = *(uint16_t *)(Addr + 2 * i);
}
/* Erase optionbytes */
FLASH->CTLR |= CR_OPTER_Set;
FLASH->CTLR |= CR_STRT_Set;
while(FLASH->STATR & SR_BSY)
;
FLASH->CTLR &= ~CR_OPTER_Set;
/* Write optionbytes */
pbuf[1] = OB_IWDG | (uint16_t)(OB_STOP | (uint16_t)(OB_STDBY | ((uint16_t)0xF8)));
FLASH->CTLR |= CR_OPTPG_Set;
for(i = 0; i < 8; i++)
{
*(uint16_t *)(Addr + 2 * i) = pbuf[i];
while(FLASH->STATR & SR_BSY)
;
}
FLASH->CTLR &= ~CR_OPTPG_Set;
}
return status;
}
/*********************************************************************
* @fn FLASH_GetUserOptionByte
*
* @brief Returns the FLASH User Option Bytes values.
*
* @return The FLASH User Option Bytes values:IWDG_SW(Bit0), RST_STOP(Bit1)
* and RST_STDBY(Bit2).
*/
uint32_t FLASH_GetUserOptionByte(void)
{
return (uint32_t)(FLASH->OBR >> 2);
}
/*********************************************************************
* @fn FLASH_GetWriteProtectionOptionByte
*
* @brief Returns the FLASH Write Protection Option Bytes Register value.
*
* @return The FLASH Write Protection Option Bytes Register value.
*/
uint32_t FLASH_GetWriteProtectionOptionByte(void)
{
return (uint32_t)(FLASH->WPR);
}
/*********************************************************************
* @fn FLASH_GetReadOutProtectionStatus
*
* @brief Checks whether the FLASH Read Out Protection Status is set or not.
*
* @return FLASH ReadOut Protection Status(SET or RESET)
*/
FlagStatus FLASH_GetReadOutProtectionStatus(void)
{
FlagStatus readoutstatus = RESET;
if((FLASH->OBR & RDPRT_Mask) != (uint32_t)RESET)
{
readoutstatus = SET;
}
else
{
readoutstatus = RESET;
}
return readoutstatus;
}
/*********************************************************************
* @fn FLASH_ITConfig
*
* @brief Enables or disables the specified FLASH interrupts.
*
* @param FLASH_IT - specifies the FLASH interrupt sources to be enabled or disabled.
* FLASH_IT_ERROR - FLASH Error Interrupt
* FLASH_IT_EOP - FLASH end of operation Interrupt
* NewState - new state of the specified Flash interrupts(ENABLE or DISABLE).
*
* @return FLASH Prefetch Buffer Status (SET or RESET).
*/
void FLASH_ITConfig(uint32_t FLASH_IT, FunctionalState NewState)
{
if(NewState != DISABLE)
{
FLASH->CTLR |= FLASH_IT;
}
else
{
FLASH->CTLR &= ~(uint32_t)FLASH_IT;
}
}
/*********************************************************************
* @fn FLASH_GetFlagStatus
*
* @brief Checks whether the specified FLASH flag is set or not.
*
* @param FLASH_FLAG - specifies the FLASH flag to check.
* FLASH_FLAG_BSY - FLASH Busy flag
* FLASH_FLAG_PGERR - FLASH Program error flag
* FLASH_FLAG_WRPRTERR - FLASH Write protected error flag
* FLASH_FLAG_EOP - FLASH End of Operation flag
* FLASH_FLAG_OPTERR - FLASH Option Byte error flag
*
* @return The new state of FLASH_FLAG (SET or RESET).
*/
FlagStatus FLASH_GetFlagStatus(uint32_t FLASH_FLAG)
{
FlagStatus bitstatus = RESET;
if(FLASH_FLAG == FLASH_FLAG_OPTERR)
{
if((FLASH->OBR & FLASH_FLAG_OPTERR) != (uint32_t)RESET)
{
bitstatus = SET;
}
else
{
bitstatus = RESET;
}
}
else
{
if((FLASH->STATR & FLASH_FLAG) != (uint32_t)RESET)
{
bitstatus = SET;
}
else
{
bitstatus = RESET;
}
}
return bitstatus;
}
/*********************************************************************
* @fn FLASH_ClearFlag
*
* @brief Clears the FLASH's pending flags.
*
* @param FLASH_FLAG - specifies the FLASH flags to clear.
* FLASH_FLAG_PGERR - FLASH Program error flag
* FLASH_FLAG_WRPRTERR - FLASH Write protected error flag
* FLASH_FLAG_EOP - FLASH End of Operation flag
*
* @return none
*/
void FLASH_ClearFlag(uint32_t FLASH_FLAG)
{
FLASH->STATR = FLASH_FLAG;
}
/*********************************************************************
* @fn FLASH_GetStatus
*
* @brief Returns the FLASH Status.
*
* @return FLASH Status - The returned value can be: FLASH_BUSY, FLASH_ERROR_PG,
* FLASH_ERROR_WRP or FLASH_COMPLETE.
*/
FLASH_Status FLASH_GetStatus(void)
{
FLASH_Status flashstatus = FLASH_COMPLETE;
if((FLASH->STATR & FLASH_FLAG_BSY) == FLASH_FLAG_BSY)
{
flashstatus = FLASH_BUSY;
}
else
{
if((FLASH->STATR & FLASH_FLAG_PGERR) != 0)
{
flashstatus = FLASH_ERROR_PG;
}
else
{
if((FLASH->STATR & FLASH_FLAG_WRPRTERR) != 0)
{
flashstatus = FLASH_ERROR_WRP;
}
else
{
flashstatus = FLASH_COMPLETE;
}
}
}
return flashstatus;
}
/*********************************************************************
* @fn FLASH_GetBank1Status
*
* @brief Returns the FLASH Bank1 Status.
*
* @return FLASH Status - The returned value can be: FLASH_BUSY, FLASH_ERROR_PG,
* FLASH_ERROR_WRP or FLASH_COMPLETE.
*/
FLASH_Status FLASH_GetBank1Status(void)
{
FLASH_Status flashstatus = FLASH_COMPLETE;
if((FLASH->STATR & FLASH_FLAG_BANK1_BSY) == FLASH_FLAG_BSY)
{
flashstatus = FLASH_BUSY;
}
else
{
if((FLASH->STATR & FLASH_FLAG_BANK1_PGERR) != 0)
{
flashstatus = FLASH_ERROR_PG;
}
else
{
if((FLASH->STATR & FLASH_FLAG_BANK1_WRPRTERR) != 0)
{
flashstatus = FLASH_ERROR_WRP;
}
else
{
flashstatus = FLASH_COMPLETE;
}
}
}
return flashstatus;
}
/*********************************************************************
* @fn FLASH_WaitForLastOperation
*
* @brief Waits for a Flash operation to complete or a TIMEOUT to occur.
*
* @param Timeout - FLASH programming Timeout
*
* @return FLASH Status - The returned value can be: FLASH_BUSY, FLASH_ERROR_PG,
* FLASH_ERROR_WRP or FLASH_COMPLETE.
*/
FLASH_Status FLASH_WaitForLastOperation(uint32_t Timeout)
{
FLASH_Status status = FLASH_COMPLETE;
status = FLASH_GetBank1Status();
while((status == FLASH_BUSY) && (Timeout != 0x00))
{
status = FLASH_GetBank1Status();
Timeout--;
}
if(Timeout == 0x00)
{
status = FLASH_TIMEOUT;
}
return status;
}
/*********************************************************************
* @fn FLASH_WaitForLastBank1Operation
*
* @brief Waits for a Flash operation on Bank1 to complete or a TIMEOUT to occur.
*
* @param Timeout - FLASH programming Timeout
*
* @return FLASH Status - The returned value can be: FLASH_BUSY, FLASH_ERROR_PG,
* FLASH_ERROR_WRP or FLASH_COMPLETE.
*/
FLASH_Status FLASH_WaitForLastBank1Operation(uint32_t Timeout)
{
FLASH_Status status = FLASH_COMPLETE;
status = FLASH_GetBank1Status();
while((status == FLASH_FLAG_BANK1_BSY) && (Timeout != 0x00))
{
status = FLASH_GetBank1Status();
Timeout--;
}
if(Timeout == 0x00)
{
status = FLASH_TIMEOUT;
}
return status;
}
/*********************************************************************
* @fn FLASH_Unlock_Fast
*
* @brief Unlocks the Fast Program Erase Mode.
*
* @return none
*/
void FLASH_Unlock_Fast(void)
{
/* Authorize the FPEC of Bank1 Access */
FLASH->KEYR = FLASH_KEY1;
FLASH->KEYR = FLASH_KEY2;
/* Fast program mode unlock */
FLASH->MODEKEYR = FLASH_KEY1;
FLASH->MODEKEYR = FLASH_KEY2;
}
/*********************************************************************
* @fn FLASH_Lock_Fast
*
* @brief Locks the Fast Program Erase Mode.
*
* @return none
*/
void FLASH_Lock_Fast(void)
{
FLASH->CTLR |= CR_LOCK_Set;
}
/*********************************************************************
* @fn FLASH_ErasePage_Fast
*
* @brief Erases a specified FLASH page (1page = 256Byte).
*
* @param Page_Address - The page address to be erased.
*
* @return none
*/
void FLASH_ErasePage_Fast(uint32_t Page_Address)
{
Page_Address &= 0xFFFFFF00;
FLASH->CTLR |= CR_PAGE_ER;
FLASH->ADDR = Page_Address;
FLASH->CTLR |= CR_STRT_Set;
while(FLASH->STATR & SR_BSY)
;
FLASH->CTLR &= ~CR_PAGE_ER;
}
/*********************************************************************
* @fn FLASH_EraseBlock_32K_Fast
*
* @brief Erases a specified FLASH Block (1Block = 32KByte).
*
* @param Block_Address - The block address to be erased.
*
* @return none
*/
void FLASH_EraseBlock_32K_Fast(uint32_t Block_Address)
{
Block_Address &= 0xFFFF8000;
FLASH->CTLR |= CR_BER32;
FLASH->ADDR = Block_Address;
FLASH->CTLR |= CR_STRT_Set;
while(FLASH->STATR & SR_BSY)
;
FLASH->CTLR &= ~CR_BER32;
}
/*********************************************************************
* @fn FLASH_EraseBlock_64K_Fast
*
* @brief Erases a specified FLASH Block (1Block = 64KByte).
*
* @param Block_Address - The block address to be erased.
*
* @return none
*/
void FLASH_EraseBlock_64K_Fast(uint32_t Block_Address)
{
Block_Address &= 0xFFFF0000;
FLASH->CTLR |= CR_BER64;
FLASH->ADDR = Block_Address;
FLASH->CTLR |= CR_STRT_Set;
while(FLASH->STATR & SR_BSY)
;
FLASH->CTLR &= ~CR_BER64;
}
/*********************************************************************
* @fn FLASH_ProgramPage_Fast
*
* @brief Program a specified FLASH page (1page = 256Byte).
*
* @param Page_Address - The page address to be programed.
*
* @return none
*/
void FLASH_ProgramPage_Fast(uint32_t Page_Address, uint32_t *pbuf)
{
uint8_t size = 64;
Page_Address &= 0xFFFFFF00;
FLASH->CTLR |= CR_PAGE_PG;
while(FLASH->STATR & SR_BSY)
;
while(FLASH->STATR & SR_WR_BSY)
;
while(size)
{
*(uint32_t *)Page_Address = *(uint32_t *)pbuf;
Page_Address += 4;
pbuf += 1;
size -= 1;
while(FLASH->STATR & SR_WR_BSY)
;
}
FLASH->CTLR |= CR_PG_STRT;
while(FLASH->STATR & SR_BSY)
;
FLASH->CTLR &= ~CR_PAGE_PG;
}
/*********************************************************************
* @fn FLASH_Enhance_Mode
*
* @brief Read FLASH Enhance Mode
*
* @param FLASH_Enhance_CLK -
* FLASH_Enhance_SYSTEM_HALF - System clock/2
* FLASH_Enhance_SYSTEM - System clock
* Newstate - new state of the ReadOut Protection(ENABLE or DISABLE).
*
* @return none
*/
void FLASH_Enhance_Mode(uint32_t FLASH_Enhance_CLK, FunctionalState NewState)
{
FLASH->CTLR &= ~(1 << 25);
FLASH->CTLR |= FLASH_Enhance_CLK;
if(NewState)
{
FLASH->CTLR |= (1 << 24);
}
else
{
FLASH->CTLR &= ~(1 << 24);
FLASH->CTLR |= (1 << 22);
}
}
|
12f9e8cf9fbfd4046cc9b856d6b131674d90e072
|
7eaf54a78c9e2117247cb2ab6d3a0c20719ba700
|
/SOFTWARE/A64-TERES/linux-a64/drivers/tty/ipwireless/network.h
|
561f765b333419fa1aa4a48095efe734b89efd8e
|
[
"LicenseRef-scancode-free-unknown",
"Apache-2.0",
"Linux-syscall-note",
"GPL-2.0-only",
"GPL-1.0-or-later"
] |
permissive
|
OLIMEX/DIY-LAPTOP
|
ae82f4ee79c641d9aee444db9a75f3f6709afa92
|
a3fafd1309135650bab27f5eafc0c32bc3ca74ee
|
refs/heads/rel3
| 2023-08-04T01:54:19.483792
| 2023-04-03T07:18:12
| 2023-04-03T07:18:12
| 80,094,055
| 507
| 92
|
Apache-2.0
| 2023-04-03T07:05:59
| 2017-01-26T07:25:50
|
C
|
UTF-8
|
C
| false
| false
| 1,686
|
h
|
network.h
|
/*
* IPWireless 3G PCMCIA Network Driver
*
* Original code
* by Stephen Blackheath <stephen@blacksapphire.com>,
* Ben Martel <benm@symmetric.co.nz>
*
* Copyrighted as follows:
* Copyright (C) 2004 by Symmetric Systems Ltd (NZ)
*
* Various driver changes and rewrites, port to new kernels
* Copyright (C) 2006-2007 Jiri Kosina
*
* Misc code cleanups and updates
* Copyright (C) 2007 David Sterba
*/
#ifndef _IPWIRELESS_CS_NETWORK_H_
#define _IPWIRELESS_CS_NETWORK_H_
#include <linux/types.h>
struct ipw_network;
struct ipw_tty;
struct ipw_hardware;
/* Definitions of the different channels on the PCMCIA UE */
#define IPW_CHANNEL_RAS 0
#define IPW_CHANNEL_DIALLER 1
#define IPW_CHANNEL_CONSOLE 2
#define NO_OF_IPW_CHANNELS 5
void ipwireless_network_notify_control_line_change(struct ipw_network *net,
unsigned int channel_idx, unsigned int control_lines,
unsigned int control_mask);
void ipwireless_network_packet_received(struct ipw_network *net,
unsigned int channel_idx, unsigned char *data,
unsigned int length);
struct ipw_network *ipwireless_network_create(struct ipw_hardware *hw);
void ipwireless_network_free(struct ipw_network *net);
void ipwireless_associate_network_tty(struct ipw_network *net,
unsigned int channel_idx, struct ipw_tty *tty);
void ipwireless_disassociate_network_ttys(struct ipw_network *net,
unsigned int channel_idx);
void ipwireless_ppp_open(struct ipw_network *net);
void ipwireless_ppp_close(struct ipw_network *net);
int ipwireless_ppp_channel_index(struct ipw_network *net);
int ipwireless_ppp_unit_number(struct ipw_network *net);
int ipwireless_ppp_mru(const struct ipw_network *net);
#endif
|
54992cb5cbccce2c510de2eb68d749e525351ef3
|
00c64e0967d197d8c6fc3427954e2d0b2ff13ca0
|
/clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/overloaded/vluxseg2ei8.c
|
ea741e829cbc0fe5b1ba1843a858604825c755f1
|
[
"Apache-2.0",
"LLVM-exception",
"NCSA",
"LicenseRef-scancode-unknown-license-reference"
] |
permissive
|
triSYCL/sycl
|
893048e80158cf3359c1ad8912da9ccf493faf69
|
5a95a7136a11b75f01ef839d9229780032bbeecf
|
refs/heads/sycl/unified/master
| 2023-08-23T22:06:46.238209
| 2023-05-24T22:54:31
| 2023-05-24T22:54:31
| 178,923,006
| 103
| 17
|
NOASSERTION
| 2023-09-12T20:03:26
| 2019-04-01T18:29:01
| null |
UTF-8
|
C
| false
| false
| 296,523
|
c
|
vluxseg2ei8.c
|
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
// REQUIRES: riscv-registered-target
// RUN: %clang_cc1 -triple riscv64 -target-feature +v -target-feature +zfh \
// RUN: -target-feature +experimental-zvfh -disable-O0-optnone \
// RUN: -emit-llvm %s -o - | opt -S -passes=mem2reg | \
// RUN: FileCheck --check-prefix=CHECK-RV64 %s
#include <riscv_vector.h>
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_f16mf4_tu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 1 x half>, <vscale x 1 x half> } @llvm.riscv.vluxseg2.nxv1f16.nxv1i8.i64(<vscale x 1 x half> [[MASKEDOFF0:%.*]], <vscale x 1 x half> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 1 x i8> [[BINDEX:%.*]], i64 [[VL:%.*]])
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 1 x half>, <vscale x 1 x half> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 1 x half> [[TMP1]], ptr [[V0:%.*]], align 2
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 1 x half>, <vscale x 1 x half> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 1 x half> [[TMP2]], ptr [[V1:%.*]], align 2
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_f16mf4_tu(vfloat16mf4_t *v0, vfloat16mf4_t *v1, vfloat16mf4_t maskedoff0, vfloat16mf4_t maskedoff1, const _Float16 *base, vuint8mf8_t bindex, size_t vl) {
return vluxseg2ei8_tu(v0, v1, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_f16mf2_tu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 2 x half>, <vscale x 2 x half> } @llvm.riscv.vluxseg2.nxv2f16.nxv2i8.i64(<vscale x 2 x half> [[MASKEDOFF0:%.*]], <vscale x 2 x half> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 2 x i8> [[BINDEX:%.*]], i64 [[VL:%.*]])
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 2 x half>, <vscale x 2 x half> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 2 x half> [[TMP1]], ptr [[V0:%.*]], align 2
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 2 x half>, <vscale x 2 x half> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 2 x half> [[TMP2]], ptr [[V1:%.*]], align 2
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_f16mf2_tu(vfloat16mf2_t *v0, vfloat16mf2_t *v1, vfloat16mf2_t maskedoff0, vfloat16mf2_t maskedoff1, const _Float16 *base, vuint8mf4_t bindex, size_t vl) {
return vluxseg2ei8_tu(v0, v1, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_f16m1_tu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 4 x half>, <vscale x 4 x half> } @llvm.riscv.vluxseg2.nxv4f16.nxv4i8.i64(<vscale x 4 x half> [[MASKEDOFF0:%.*]], <vscale x 4 x half> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 4 x i8> [[BINDEX:%.*]], i64 [[VL:%.*]])
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 4 x half>, <vscale x 4 x half> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 4 x half> [[TMP1]], ptr [[V0:%.*]], align 2
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 4 x half>, <vscale x 4 x half> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 4 x half> [[TMP2]], ptr [[V1:%.*]], align 2
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_f16m1_tu(vfloat16m1_t *v0, vfloat16m1_t *v1, vfloat16m1_t maskedoff0, vfloat16m1_t maskedoff1, const _Float16 *base, vuint8mf2_t bindex, size_t vl) {
return vluxseg2ei8_tu(v0, v1, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_f16m2_tu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 8 x half>, <vscale x 8 x half> } @llvm.riscv.vluxseg2.nxv8f16.nxv8i8.i64(<vscale x 8 x half> [[MASKEDOFF0:%.*]], <vscale x 8 x half> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 8 x i8> [[BINDEX:%.*]], i64 [[VL:%.*]])
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 8 x half>, <vscale x 8 x half> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 8 x half> [[TMP1]], ptr [[V0:%.*]], align 2
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 8 x half>, <vscale x 8 x half> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 8 x half> [[TMP2]], ptr [[V1:%.*]], align 2
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_f16m2_tu(vfloat16m2_t *v0, vfloat16m2_t *v1, vfloat16m2_t maskedoff0, vfloat16m2_t maskedoff1, const _Float16 *base, vuint8m1_t bindex, size_t vl) {
return vluxseg2ei8_tu(v0, v1, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_f16m4_tu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 16 x half>, <vscale x 16 x half> } @llvm.riscv.vluxseg2.nxv16f16.nxv16i8.i64(<vscale x 16 x half> [[MASKEDOFF0:%.*]], <vscale x 16 x half> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 16 x i8> [[BINDEX:%.*]], i64 [[VL:%.*]])
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 16 x half>, <vscale x 16 x half> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 16 x half> [[TMP1]], ptr [[V0:%.*]], align 2
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 16 x half>, <vscale x 16 x half> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 16 x half> [[TMP2]], ptr [[V1:%.*]], align 2
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_f16m4_tu(vfloat16m4_t *v0, vfloat16m4_t *v1, vfloat16m4_t maskedoff0, vfloat16m4_t maskedoff1, const _Float16 *base, vuint8m2_t bindex, size_t vl) {
return vluxseg2ei8_tu(v0, v1, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_f32mf2_tu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 1 x float>, <vscale x 1 x float> } @llvm.riscv.vluxseg2.nxv1f32.nxv1i8.i64(<vscale x 1 x float> [[MASKEDOFF0:%.*]], <vscale x 1 x float> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 1 x i8> [[BINDEX:%.*]], i64 [[VL:%.*]])
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 1 x float>, <vscale x 1 x float> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 1 x float> [[TMP1]], ptr [[V0:%.*]], align 4
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 1 x float>, <vscale x 1 x float> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 1 x float> [[TMP2]], ptr [[V1:%.*]], align 4
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_f32mf2_tu(vfloat32mf2_t *v0, vfloat32mf2_t *v1, vfloat32mf2_t maskedoff0, vfloat32mf2_t maskedoff1, const float *base, vuint8mf8_t bindex, size_t vl) {
return vluxseg2ei8_tu(v0, v1, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_f32m1_tu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 2 x float>, <vscale x 2 x float> } @llvm.riscv.vluxseg2.nxv2f32.nxv2i8.i64(<vscale x 2 x float> [[MASKEDOFF0:%.*]], <vscale x 2 x float> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 2 x i8> [[BINDEX:%.*]], i64 [[VL:%.*]])
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 2 x float>, <vscale x 2 x float> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 2 x float> [[TMP1]], ptr [[V0:%.*]], align 4
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 2 x float>, <vscale x 2 x float> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 2 x float> [[TMP2]], ptr [[V1:%.*]], align 4
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_f32m1_tu(vfloat32m1_t *v0, vfloat32m1_t *v1, vfloat32m1_t maskedoff0, vfloat32m1_t maskedoff1, const float *base, vuint8mf4_t bindex, size_t vl) {
return vluxseg2ei8_tu(v0, v1, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_f32m2_tu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 4 x float>, <vscale x 4 x float> } @llvm.riscv.vluxseg2.nxv4f32.nxv4i8.i64(<vscale x 4 x float> [[MASKEDOFF0:%.*]], <vscale x 4 x float> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 4 x i8> [[BINDEX:%.*]], i64 [[VL:%.*]])
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 4 x float>, <vscale x 4 x float> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 4 x float> [[TMP1]], ptr [[V0:%.*]], align 4
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 4 x float>, <vscale x 4 x float> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 4 x float> [[TMP2]], ptr [[V1:%.*]], align 4
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_f32m2_tu(vfloat32m2_t *v0, vfloat32m2_t *v1, vfloat32m2_t maskedoff0, vfloat32m2_t maskedoff1, const float *base, vuint8mf2_t bindex, size_t vl) {
return vluxseg2ei8_tu(v0, v1, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_f32m4_tu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 8 x float>, <vscale x 8 x float> } @llvm.riscv.vluxseg2.nxv8f32.nxv8i8.i64(<vscale x 8 x float> [[MASKEDOFF0:%.*]], <vscale x 8 x float> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 8 x i8> [[BINDEX:%.*]], i64 [[VL:%.*]])
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 8 x float>, <vscale x 8 x float> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 8 x float> [[TMP1]], ptr [[V0:%.*]], align 4
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 8 x float>, <vscale x 8 x float> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 8 x float> [[TMP2]], ptr [[V1:%.*]], align 4
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_f32m4_tu(vfloat32m4_t *v0, vfloat32m4_t *v1, vfloat32m4_t maskedoff0, vfloat32m4_t maskedoff1, const float *base, vuint8m1_t bindex, size_t vl) {
return vluxseg2ei8_tu(v0, v1, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_f64m1_tu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 1 x double>, <vscale x 1 x double> } @llvm.riscv.vluxseg2.nxv1f64.nxv1i8.i64(<vscale x 1 x double> [[MASKEDOFF0:%.*]], <vscale x 1 x double> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 1 x i8> [[BINDEX:%.*]], i64 [[VL:%.*]])
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 1 x double>, <vscale x 1 x double> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 1 x double> [[TMP1]], ptr [[V0:%.*]], align 8
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 1 x double>, <vscale x 1 x double> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 1 x double> [[TMP2]], ptr [[V1:%.*]], align 8
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_f64m1_tu(vfloat64m1_t *v0, vfloat64m1_t *v1, vfloat64m1_t maskedoff0, vfloat64m1_t maskedoff1, const double *base, vuint8mf8_t bindex, size_t vl) {
return vluxseg2ei8_tu(v0, v1, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_f64m2_tu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 2 x double>, <vscale x 2 x double> } @llvm.riscv.vluxseg2.nxv2f64.nxv2i8.i64(<vscale x 2 x double> [[MASKEDOFF0:%.*]], <vscale x 2 x double> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 2 x i8> [[BINDEX:%.*]], i64 [[VL:%.*]])
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 2 x double>, <vscale x 2 x double> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 2 x double> [[TMP1]], ptr [[V0:%.*]], align 8
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 2 x double>, <vscale x 2 x double> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 2 x double> [[TMP2]], ptr [[V1:%.*]], align 8
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_f64m2_tu(vfloat64m2_t *v0, vfloat64m2_t *v1, vfloat64m2_t maskedoff0, vfloat64m2_t maskedoff1, const double *base, vuint8mf4_t bindex, size_t vl) {
return vluxseg2ei8_tu(v0, v1, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_f64m4_tu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 4 x double>, <vscale x 4 x double> } @llvm.riscv.vluxseg2.nxv4f64.nxv4i8.i64(<vscale x 4 x double> [[MASKEDOFF0:%.*]], <vscale x 4 x double> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 4 x i8> [[BINDEX:%.*]], i64 [[VL:%.*]])
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 4 x double>, <vscale x 4 x double> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 4 x double> [[TMP1]], ptr [[V0:%.*]], align 8
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 4 x double>, <vscale x 4 x double> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 4 x double> [[TMP2]], ptr [[V1:%.*]], align 8
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_f64m4_tu(vfloat64m4_t *v0, vfloat64m4_t *v1, vfloat64m4_t maskedoff0, vfloat64m4_t maskedoff1, const double *base, vuint8mf2_t bindex, size_t vl) {
return vluxseg2ei8_tu(v0, v1, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i8mf8_tu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 1 x i8>, <vscale x 1 x i8> } @llvm.riscv.vluxseg2.nxv1i8.nxv1i8.i64(<vscale x 1 x i8> [[MASKEDOFF0:%.*]], <vscale x 1 x i8> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 1 x i8> [[BINDEX:%.*]], i64 [[VL:%.*]])
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 1 x i8>, <vscale x 1 x i8> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 1 x i8> [[TMP1]], ptr [[V0:%.*]], align 1
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 1 x i8>, <vscale x 1 x i8> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 1 x i8> [[TMP2]], ptr [[V1:%.*]], align 1
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i8mf8_tu(vint8mf8_t *v0, vint8mf8_t *v1, vint8mf8_t maskedoff0, vint8mf8_t maskedoff1, const int8_t *base, vuint8mf8_t bindex, size_t vl) {
return vluxseg2ei8_tu(v0, v1, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i8mf4_tu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 2 x i8>, <vscale x 2 x i8> } @llvm.riscv.vluxseg2.nxv2i8.nxv2i8.i64(<vscale x 2 x i8> [[MASKEDOFF0:%.*]], <vscale x 2 x i8> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 2 x i8> [[BINDEX:%.*]], i64 [[VL:%.*]])
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 2 x i8>, <vscale x 2 x i8> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 2 x i8> [[TMP1]], ptr [[V0:%.*]], align 1
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 2 x i8>, <vscale x 2 x i8> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 2 x i8> [[TMP2]], ptr [[V1:%.*]], align 1
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i8mf4_tu(vint8mf4_t *v0, vint8mf4_t *v1, vint8mf4_t maskedoff0, vint8mf4_t maskedoff1, const int8_t *base, vuint8mf4_t bindex, size_t vl) {
return vluxseg2ei8_tu(v0, v1, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i8mf2_tu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 4 x i8>, <vscale x 4 x i8> } @llvm.riscv.vluxseg2.nxv4i8.nxv4i8.i64(<vscale x 4 x i8> [[MASKEDOFF0:%.*]], <vscale x 4 x i8> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 4 x i8> [[BINDEX:%.*]], i64 [[VL:%.*]])
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 4 x i8>, <vscale x 4 x i8> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 4 x i8> [[TMP1]], ptr [[V0:%.*]], align 1
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 4 x i8>, <vscale x 4 x i8> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 4 x i8> [[TMP2]], ptr [[V1:%.*]], align 1
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i8mf2_tu(vint8mf2_t *v0, vint8mf2_t *v1, vint8mf2_t maskedoff0, vint8mf2_t maskedoff1, const int8_t *base, vuint8mf2_t bindex, size_t vl) {
return vluxseg2ei8_tu(v0, v1, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i8m1_tu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 8 x i8>, <vscale x 8 x i8> } @llvm.riscv.vluxseg2.nxv8i8.nxv8i8.i64(<vscale x 8 x i8> [[MASKEDOFF0:%.*]], <vscale x 8 x i8> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 8 x i8> [[BINDEX:%.*]], i64 [[VL:%.*]])
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 8 x i8>, <vscale x 8 x i8> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 8 x i8> [[TMP1]], ptr [[V0:%.*]], align 1
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 8 x i8>, <vscale x 8 x i8> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 8 x i8> [[TMP2]], ptr [[V1:%.*]], align 1
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i8m1_tu(vint8m1_t *v0, vint8m1_t *v1, vint8m1_t maskedoff0, vint8m1_t maskedoff1, const int8_t *base, vuint8m1_t bindex, size_t vl) {
return vluxseg2ei8_tu(v0, v1, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i8m2_tu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 16 x i8>, <vscale x 16 x i8> } @llvm.riscv.vluxseg2.nxv16i8.nxv16i8.i64(<vscale x 16 x i8> [[MASKEDOFF0:%.*]], <vscale x 16 x i8> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 16 x i8> [[BINDEX:%.*]], i64 [[VL:%.*]])
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 16 x i8>, <vscale x 16 x i8> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 16 x i8> [[TMP1]], ptr [[V0:%.*]], align 1
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 16 x i8>, <vscale x 16 x i8> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 16 x i8> [[TMP2]], ptr [[V1:%.*]], align 1
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i8m2_tu(vint8m2_t *v0, vint8m2_t *v1, vint8m2_t maskedoff0, vint8m2_t maskedoff1, const int8_t *base, vuint8m2_t bindex, size_t vl) {
return vluxseg2ei8_tu(v0, v1, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i8m4_tu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 32 x i8>, <vscale x 32 x i8> } @llvm.riscv.vluxseg2.nxv32i8.nxv32i8.i64(<vscale x 32 x i8> [[MASKEDOFF0:%.*]], <vscale x 32 x i8> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 32 x i8> [[BINDEX:%.*]], i64 [[VL:%.*]])
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 32 x i8>, <vscale x 32 x i8> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 32 x i8> [[TMP1]], ptr [[V0:%.*]], align 1
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 32 x i8>, <vscale x 32 x i8> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 32 x i8> [[TMP2]], ptr [[V1:%.*]], align 1
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i8m4_tu(vint8m4_t *v0, vint8m4_t *v1, vint8m4_t maskedoff0, vint8m4_t maskedoff1, const int8_t *base, vuint8m4_t bindex, size_t vl) {
return vluxseg2ei8_tu(v0, v1, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i16mf4_tu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 1 x i16>, <vscale x 1 x i16> } @llvm.riscv.vluxseg2.nxv1i16.nxv1i8.i64(<vscale x 1 x i16> [[MASKEDOFF0:%.*]], <vscale x 1 x i16> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 1 x i8> [[BINDEX:%.*]], i64 [[VL:%.*]])
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 1 x i16>, <vscale x 1 x i16> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 1 x i16> [[TMP1]], ptr [[V0:%.*]], align 2
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 1 x i16>, <vscale x 1 x i16> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 1 x i16> [[TMP2]], ptr [[V1:%.*]], align 2
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i16mf4_tu(vint16mf4_t *v0, vint16mf4_t *v1, vint16mf4_t maskedoff0, vint16mf4_t maskedoff1, const int16_t *base, vuint8mf8_t bindex, size_t vl) {
return vluxseg2ei8_tu(v0, v1, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i16mf2_tu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 2 x i16>, <vscale x 2 x i16> } @llvm.riscv.vluxseg2.nxv2i16.nxv2i8.i64(<vscale x 2 x i16> [[MASKEDOFF0:%.*]], <vscale x 2 x i16> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 2 x i8> [[BINDEX:%.*]], i64 [[VL:%.*]])
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 2 x i16>, <vscale x 2 x i16> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 2 x i16> [[TMP1]], ptr [[V0:%.*]], align 2
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 2 x i16>, <vscale x 2 x i16> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 2 x i16> [[TMP2]], ptr [[V1:%.*]], align 2
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i16mf2_tu(vint16mf2_t *v0, vint16mf2_t *v1, vint16mf2_t maskedoff0, vint16mf2_t maskedoff1, const int16_t *base, vuint8mf4_t bindex, size_t vl) {
return vluxseg2ei8_tu(v0, v1, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i16m1_tu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 4 x i16>, <vscale x 4 x i16> } @llvm.riscv.vluxseg2.nxv4i16.nxv4i8.i64(<vscale x 4 x i16> [[MASKEDOFF0:%.*]], <vscale x 4 x i16> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 4 x i8> [[BINDEX:%.*]], i64 [[VL:%.*]])
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 4 x i16>, <vscale x 4 x i16> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 4 x i16> [[TMP1]], ptr [[V0:%.*]], align 2
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 4 x i16>, <vscale x 4 x i16> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 4 x i16> [[TMP2]], ptr [[V1:%.*]], align 2
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i16m1_tu(vint16m1_t *v0, vint16m1_t *v1, vint16m1_t maskedoff0, vint16m1_t maskedoff1, const int16_t *base, vuint8mf2_t bindex, size_t vl) {
return vluxseg2ei8_tu(v0, v1, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i16m2_tu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 8 x i16>, <vscale x 8 x i16> } @llvm.riscv.vluxseg2.nxv8i16.nxv8i8.i64(<vscale x 8 x i16> [[MASKEDOFF0:%.*]], <vscale x 8 x i16> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 8 x i8> [[BINDEX:%.*]], i64 [[VL:%.*]])
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 8 x i16>, <vscale x 8 x i16> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 8 x i16> [[TMP1]], ptr [[V0:%.*]], align 2
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 8 x i16>, <vscale x 8 x i16> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 8 x i16> [[TMP2]], ptr [[V1:%.*]], align 2
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i16m2_tu(vint16m2_t *v0, vint16m2_t *v1, vint16m2_t maskedoff0, vint16m2_t maskedoff1, const int16_t *base, vuint8m1_t bindex, size_t vl) {
return vluxseg2ei8_tu(v0, v1, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i16m4_tu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 16 x i16>, <vscale x 16 x i16> } @llvm.riscv.vluxseg2.nxv16i16.nxv16i8.i64(<vscale x 16 x i16> [[MASKEDOFF0:%.*]], <vscale x 16 x i16> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 16 x i8> [[BINDEX:%.*]], i64 [[VL:%.*]])
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 16 x i16>, <vscale x 16 x i16> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 16 x i16> [[TMP1]], ptr [[V0:%.*]], align 2
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 16 x i16>, <vscale x 16 x i16> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 16 x i16> [[TMP2]], ptr [[V1:%.*]], align 2
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i16m4_tu(vint16m4_t *v0, vint16m4_t *v1, vint16m4_t maskedoff0, vint16m4_t maskedoff1, const int16_t *base, vuint8m2_t bindex, size_t vl) {
return vluxseg2ei8_tu(v0, v1, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i32mf2_tu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 1 x i32>, <vscale x 1 x i32> } @llvm.riscv.vluxseg2.nxv1i32.nxv1i8.i64(<vscale x 1 x i32> [[MASKEDOFF0:%.*]], <vscale x 1 x i32> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 1 x i8> [[BINDEX:%.*]], i64 [[VL:%.*]])
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 1 x i32>, <vscale x 1 x i32> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 1 x i32> [[TMP1]], ptr [[V0:%.*]], align 4
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 1 x i32>, <vscale x 1 x i32> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 1 x i32> [[TMP2]], ptr [[V1:%.*]], align 4
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i32mf2_tu(vint32mf2_t *v0, vint32mf2_t *v1, vint32mf2_t maskedoff0, vint32mf2_t maskedoff1, const int32_t *base, vuint8mf8_t bindex, size_t vl) {
return vluxseg2ei8_tu(v0, v1, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i32m1_tu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 2 x i32>, <vscale x 2 x i32> } @llvm.riscv.vluxseg2.nxv2i32.nxv2i8.i64(<vscale x 2 x i32> [[MASKEDOFF0:%.*]], <vscale x 2 x i32> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 2 x i8> [[BINDEX:%.*]], i64 [[VL:%.*]])
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 2 x i32>, <vscale x 2 x i32> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 2 x i32> [[TMP1]], ptr [[V0:%.*]], align 4
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 2 x i32>, <vscale x 2 x i32> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 2 x i32> [[TMP2]], ptr [[V1:%.*]], align 4
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i32m1_tu(vint32m1_t *v0, vint32m1_t *v1, vint32m1_t maskedoff0, vint32m1_t maskedoff1, const int32_t *base, vuint8mf4_t bindex, size_t vl) {
return vluxseg2ei8_tu(v0, v1, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i32m2_tu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 4 x i32>, <vscale x 4 x i32> } @llvm.riscv.vluxseg2.nxv4i32.nxv4i8.i64(<vscale x 4 x i32> [[MASKEDOFF0:%.*]], <vscale x 4 x i32> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 4 x i8> [[BINDEX:%.*]], i64 [[VL:%.*]])
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 4 x i32>, <vscale x 4 x i32> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 4 x i32> [[TMP1]], ptr [[V0:%.*]], align 4
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 4 x i32>, <vscale x 4 x i32> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 4 x i32> [[TMP2]], ptr [[V1:%.*]], align 4
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i32m2_tu(vint32m2_t *v0, vint32m2_t *v1, vint32m2_t maskedoff0, vint32m2_t maskedoff1, const int32_t *base, vuint8mf2_t bindex, size_t vl) {
return vluxseg2ei8_tu(v0, v1, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i32m4_tu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 8 x i32>, <vscale x 8 x i32> } @llvm.riscv.vluxseg2.nxv8i32.nxv8i8.i64(<vscale x 8 x i32> [[MASKEDOFF0:%.*]], <vscale x 8 x i32> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 8 x i8> [[BINDEX:%.*]], i64 [[VL:%.*]])
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 8 x i32>, <vscale x 8 x i32> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 8 x i32> [[TMP1]], ptr [[V0:%.*]], align 4
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 8 x i32>, <vscale x 8 x i32> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 8 x i32> [[TMP2]], ptr [[V1:%.*]], align 4
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i32m4_tu(vint32m4_t *v0, vint32m4_t *v1, vint32m4_t maskedoff0, vint32m4_t maskedoff1, const int32_t *base, vuint8m1_t bindex, size_t vl) {
return vluxseg2ei8_tu(v0, v1, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i64m1_tu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 1 x i64>, <vscale x 1 x i64> } @llvm.riscv.vluxseg2.nxv1i64.nxv1i8.i64(<vscale x 1 x i64> [[MASKEDOFF0:%.*]], <vscale x 1 x i64> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 1 x i8> [[BINDEX:%.*]], i64 [[VL:%.*]])
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 1 x i64>, <vscale x 1 x i64> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 1 x i64> [[TMP1]], ptr [[V0:%.*]], align 8
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 1 x i64>, <vscale x 1 x i64> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 1 x i64> [[TMP2]], ptr [[V1:%.*]], align 8
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i64m1_tu(vint64m1_t *v0, vint64m1_t *v1, vint64m1_t maskedoff0, vint64m1_t maskedoff1, const int64_t *base, vuint8mf8_t bindex, size_t vl) {
return vluxseg2ei8_tu(v0, v1, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i64m2_tu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 2 x i64>, <vscale x 2 x i64> } @llvm.riscv.vluxseg2.nxv2i64.nxv2i8.i64(<vscale x 2 x i64> [[MASKEDOFF0:%.*]], <vscale x 2 x i64> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 2 x i8> [[BINDEX:%.*]], i64 [[VL:%.*]])
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 2 x i64>, <vscale x 2 x i64> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 2 x i64> [[TMP1]], ptr [[V0:%.*]], align 8
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 2 x i64>, <vscale x 2 x i64> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 2 x i64> [[TMP2]], ptr [[V1:%.*]], align 8
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i64m2_tu(vint64m2_t *v0, vint64m2_t *v1, vint64m2_t maskedoff0, vint64m2_t maskedoff1, const int64_t *base, vuint8mf4_t bindex, size_t vl) {
return vluxseg2ei8_tu(v0, v1, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i64m4_tu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 4 x i64>, <vscale x 4 x i64> } @llvm.riscv.vluxseg2.nxv4i64.nxv4i8.i64(<vscale x 4 x i64> [[MASKEDOFF0:%.*]], <vscale x 4 x i64> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 4 x i8> [[BINDEX:%.*]], i64 [[VL:%.*]])
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 4 x i64>, <vscale x 4 x i64> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 4 x i64> [[TMP1]], ptr [[V0:%.*]], align 8
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 4 x i64>, <vscale x 4 x i64> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 4 x i64> [[TMP2]], ptr [[V1:%.*]], align 8
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i64m4_tu(vint64m4_t *v0, vint64m4_t *v1, vint64m4_t maskedoff0, vint64m4_t maskedoff1, const int64_t *base, vuint8mf2_t bindex, size_t vl) {
return vluxseg2ei8_tu(v0, v1, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u8mf8_tu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 1 x i8>, <vscale x 1 x i8> } @llvm.riscv.vluxseg2.nxv1i8.nxv1i8.i64(<vscale x 1 x i8> [[MASKEDOFF0:%.*]], <vscale x 1 x i8> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 1 x i8> [[BINDEX:%.*]], i64 [[VL:%.*]])
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 1 x i8>, <vscale x 1 x i8> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 1 x i8> [[TMP1]], ptr [[V0:%.*]], align 1
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 1 x i8>, <vscale x 1 x i8> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 1 x i8> [[TMP2]], ptr [[V1:%.*]], align 1
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u8mf8_tu(vuint8mf8_t *v0, vuint8mf8_t *v1, vuint8mf8_t maskedoff0, vuint8mf8_t maskedoff1, const uint8_t *base, vuint8mf8_t bindex, size_t vl) {
return vluxseg2ei8_tu(v0, v1, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u8mf4_tu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 2 x i8>, <vscale x 2 x i8> } @llvm.riscv.vluxseg2.nxv2i8.nxv2i8.i64(<vscale x 2 x i8> [[MASKEDOFF0:%.*]], <vscale x 2 x i8> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 2 x i8> [[BINDEX:%.*]], i64 [[VL:%.*]])
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 2 x i8>, <vscale x 2 x i8> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 2 x i8> [[TMP1]], ptr [[V0:%.*]], align 1
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 2 x i8>, <vscale x 2 x i8> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 2 x i8> [[TMP2]], ptr [[V1:%.*]], align 1
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u8mf4_tu(vuint8mf4_t *v0, vuint8mf4_t *v1, vuint8mf4_t maskedoff0, vuint8mf4_t maskedoff1, const uint8_t *base, vuint8mf4_t bindex, size_t vl) {
return vluxseg2ei8_tu(v0, v1, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u8mf2_tu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 4 x i8>, <vscale x 4 x i8> } @llvm.riscv.vluxseg2.nxv4i8.nxv4i8.i64(<vscale x 4 x i8> [[MASKEDOFF0:%.*]], <vscale x 4 x i8> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 4 x i8> [[BINDEX:%.*]], i64 [[VL:%.*]])
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 4 x i8>, <vscale x 4 x i8> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 4 x i8> [[TMP1]], ptr [[V0:%.*]], align 1
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 4 x i8>, <vscale x 4 x i8> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 4 x i8> [[TMP2]], ptr [[V1:%.*]], align 1
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u8mf2_tu(vuint8mf2_t *v0, vuint8mf2_t *v1, vuint8mf2_t maskedoff0, vuint8mf2_t maskedoff1, const uint8_t *base, vuint8mf2_t bindex, size_t vl) {
return vluxseg2ei8_tu(v0, v1, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u8m1_tu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 8 x i8>, <vscale x 8 x i8> } @llvm.riscv.vluxseg2.nxv8i8.nxv8i8.i64(<vscale x 8 x i8> [[MASKEDOFF0:%.*]], <vscale x 8 x i8> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 8 x i8> [[BINDEX:%.*]], i64 [[VL:%.*]])
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 8 x i8>, <vscale x 8 x i8> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 8 x i8> [[TMP1]], ptr [[V0:%.*]], align 1
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 8 x i8>, <vscale x 8 x i8> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 8 x i8> [[TMP2]], ptr [[V1:%.*]], align 1
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u8m1_tu(vuint8m1_t *v0, vuint8m1_t *v1, vuint8m1_t maskedoff0, vuint8m1_t maskedoff1, const uint8_t *base, vuint8m1_t bindex, size_t vl) {
return vluxseg2ei8_tu(v0, v1, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u8m2_tu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 16 x i8>, <vscale x 16 x i8> } @llvm.riscv.vluxseg2.nxv16i8.nxv16i8.i64(<vscale x 16 x i8> [[MASKEDOFF0:%.*]], <vscale x 16 x i8> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 16 x i8> [[BINDEX:%.*]], i64 [[VL:%.*]])
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 16 x i8>, <vscale x 16 x i8> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 16 x i8> [[TMP1]], ptr [[V0:%.*]], align 1
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 16 x i8>, <vscale x 16 x i8> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 16 x i8> [[TMP2]], ptr [[V1:%.*]], align 1
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u8m2_tu(vuint8m2_t *v0, vuint8m2_t *v1, vuint8m2_t maskedoff0, vuint8m2_t maskedoff1, const uint8_t *base, vuint8m2_t bindex, size_t vl) {
return vluxseg2ei8_tu(v0, v1, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u8m4_tu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 32 x i8>, <vscale x 32 x i8> } @llvm.riscv.vluxseg2.nxv32i8.nxv32i8.i64(<vscale x 32 x i8> [[MASKEDOFF0:%.*]], <vscale x 32 x i8> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 32 x i8> [[BINDEX:%.*]], i64 [[VL:%.*]])
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 32 x i8>, <vscale x 32 x i8> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 32 x i8> [[TMP1]], ptr [[V0:%.*]], align 1
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 32 x i8>, <vscale x 32 x i8> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 32 x i8> [[TMP2]], ptr [[V1:%.*]], align 1
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u8m4_tu(vuint8m4_t *v0, vuint8m4_t *v1, vuint8m4_t maskedoff0, vuint8m4_t maskedoff1, const uint8_t *base, vuint8m4_t bindex, size_t vl) {
return vluxseg2ei8_tu(v0, v1, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u16mf4_tu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 1 x i16>, <vscale x 1 x i16> } @llvm.riscv.vluxseg2.nxv1i16.nxv1i8.i64(<vscale x 1 x i16> [[MASKEDOFF0:%.*]], <vscale x 1 x i16> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 1 x i8> [[BINDEX:%.*]], i64 [[VL:%.*]])
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 1 x i16>, <vscale x 1 x i16> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 1 x i16> [[TMP1]], ptr [[V0:%.*]], align 2
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 1 x i16>, <vscale x 1 x i16> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 1 x i16> [[TMP2]], ptr [[V1:%.*]], align 2
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u16mf4_tu(vuint16mf4_t *v0, vuint16mf4_t *v1, vuint16mf4_t maskedoff0, vuint16mf4_t maskedoff1, const uint16_t *base, vuint8mf8_t bindex, size_t vl) {
return vluxseg2ei8_tu(v0, v1, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u16mf2_tu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 2 x i16>, <vscale x 2 x i16> } @llvm.riscv.vluxseg2.nxv2i16.nxv2i8.i64(<vscale x 2 x i16> [[MASKEDOFF0:%.*]], <vscale x 2 x i16> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 2 x i8> [[BINDEX:%.*]], i64 [[VL:%.*]])
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 2 x i16>, <vscale x 2 x i16> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 2 x i16> [[TMP1]], ptr [[V0:%.*]], align 2
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 2 x i16>, <vscale x 2 x i16> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 2 x i16> [[TMP2]], ptr [[V1:%.*]], align 2
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u16mf2_tu(vuint16mf2_t *v0, vuint16mf2_t *v1, vuint16mf2_t maskedoff0, vuint16mf2_t maskedoff1, const uint16_t *base, vuint8mf4_t bindex, size_t vl) {
return vluxseg2ei8_tu(v0, v1, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u16m1_tu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 4 x i16>, <vscale x 4 x i16> } @llvm.riscv.vluxseg2.nxv4i16.nxv4i8.i64(<vscale x 4 x i16> [[MASKEDOFF0:%.*]], <vscale x 4 x i16> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 4 x i8> [[BINDEX:%.*]], i64 [[VL:%.*]])
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 4 x i16>, <vscale x 4 x i16> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 4 x i16> [[TMP1]], ptr [[V0:%.*]], align 2
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 4 x i16>, <vscale x 4 x i16> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 4 x i16> [[TMP2]], ptr [[V1:%.*]], align 2
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u16m1_tu(vuint16m1_t *v0, vuint16m1_t *v1, vuint16m1_t maskedoff0, vuint16m1_t maskedoff1, const uint16_t *base, vuint8mf2_t bindex, size_t vl) {
return vluxseg2ei8_tu(v0, v1, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u16m2_tu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 8 x i16>, <vscale x 8 x i16> } @llvm.riscv.vluxseg2.nxv8i16.nxv8i8.i64(<vscale x 8 x i16> [[MASKEDOFF0:%.*]], <vscale x 8 x i16> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 8 x i8> [[BINDEX:%.*]], i64 [[VL:%.*]])
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 8 x i16>, <vscale x 8 x i16> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 8 x i16> [[TMP1]], ptr [[V0:%.*]], align 2
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 8 x i16>, <vscale x 8 x i16> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 8 x i16> [[TMP2]], ptr [[V1:%.*]], align 2
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u16m2_tu(vuint16m2_t *v0, vuint16m2_t *v1, vuint16m2_t maskedoff0, vuint16m2_t maskedoff1, const uint16_t *base, vuint8m1_t bindex, size_t vl) {
return vluxseg2ei8_tu(v0, v1, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u16m4_tu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 16 x i16>, <vscale x 16 x i16> } @llvm.riscv.vluxseg2.nxv16i16.nxv16i8.i64(<vscale x 16 x i16> [[MASKEDOFF0:%.*]], <vscale x 16 x i16> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 16 x i8> [[BINDEX:%.*]], i64 [[VL:%.*]])
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 16 x i16>, <vscale x 16 x i16> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 16 x i16> [[TMP1]], ptr [[V0:%.*]], align 2
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 16 x i16>, <vscale x 16 x i16> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 16 x i16> [[TMP2]], ptr [[V1:%.*]], align 2
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u16m4_tu(vuint16m4_t *v0, vuint16m4_t *v1, vuint16m4_t maskedoff0, vuint16m4_t maskedoff1, const uint16_t *base, vuint8m2_t bindex, size_t vl) {
return vluxseg2ei8_tu(v0, v1, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u32mf2_tu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 1 x i32>, <vscale x 1 x i32> } @llvm.riscv.vluxseg2.nxv1i32.nxv1i8.i64(<vscale x 1 x i32> [[MASKEDOFF0:%.*]], <vscale x 1 x i32> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 1 x i8> [[BINDEX:%.*]], i64 [[VL:%.*]])
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 1 x i32>, <vscale x 1 x i32> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 1 x i32> [[TMP1]], ptr [[V0:%.*]], align 4
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 1 x i32>, <vscale x 1 x i32> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 1 x i32> [[TMP2]], ptr [[V1:%.*]], align 4
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u32mf2_tu(vuint32mf2_t *v0, vuint32mf2_t *v1, vuint32mf2_t maskedoff0, vuint32mf2_t maskedoff1, const uint32_t *base, vuint8mf8_t bindex, size_t vl) {
return vluxseg2ei8_tu(v0, v1, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u32m1_tu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 2 x i32>, <vscale x 2 x i32> } @llvm.riscv.vluxseg2.nxv2i32.nxv2i8.i64(<vscale x 2 x i32> [[MASKEDOFF0:%.*]], <vscale x 2 x i32> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 2 x i8> [[BINDEX:%.*]], i64 [[VL:%.*]])
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 2 x i32>, <vscale x 2 x i32> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 2 x i32> [[TMP1]], ptr [[V0:%.*]], align 4
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 2 x i32>, <vscale x 2 x i32> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 2 x i32> [[TMP2]], ptr [[V1:%.*]], align 4
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u32m1_tu(vuint32m1_t *v0, vuint32m1_t *v1, vuint32m1_t maskedoff0, vuint32m1_t maskedoff1, const uint32_t *base, vuint8mf4_t bindex, size_t vl) {
return vluxseg2ei8_tu(v0, v1, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u32m2_tu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 4 x i32>, <vscale x 4 x i32> } @llvm.riscv.vluxseg2.nxv4i32.nxv4i8.i64(<vscale x 4 x i32> [[MASKEDOFF0:%.*]], <vscale x 4 x i32> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 4 x i8> [[BINDEX:%.*]], i64 [[VL:%.*]])
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 4 x i32>, <vscale x 4 x i32> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 4 x i32> [[TMP1]], ptr [[V0:%.*]], align 4
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 4 x i32>, <vscale x 4 x i32> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 4 x i32> [[TMP2]], ptr [[V1:%.*]], align 4
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u32m2_tu(vuint32m2_t *v0, vuint32m2_t *v1, vuint32m2_t maskedoff0, vuint32m2_t maskedoff1, const uint32_t *base, vuint8mf2_t bindex, size_t vl) {
return vluxseg2ei8_tu(v0, v1, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u32m4_tu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 8 x i32>, <vscale x 8 x i32> } @llvm.riscv.vluxseg2.nxv8i32.nxv8i8.i64(<vscale x 8 x i32> [[MASKEDOFF0:%.*]], <vscale x 8 x i32> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 8 x i8> [[BINDEX:%.*]], i64 [[VL:%.*]])
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 8 x i32>, <vscale x 8 x i32> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 8 x i32> [[TMP1]], ptr [[V0:%.*]], align 4
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 8 x i32>, <vscale x 8 x i32> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 8 x i32> [[TMP2]], ptr [[V1:%.*]], align 4
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u32m4_tu(vuint32m4_t *v0, vuint32m4_t *v1, vuint32m4_t maskedoff0, vuint32m4_t maskedoff1, const uint32_t *base, vuint8m1_t bindex, size_t vl) {
return vluxseg2ei8_tu(v0, v1, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u64m1_tu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 1 x i64>, <vscale x 1 x i64> } @llvm.riscv.vluxseg2.nxv1i64.nxv1i8.i64(<vscale x 1 x i64> [[MASKEDOFF0:%.*]], <vscale x 1 x i64> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 1 x i8> [[BINDEX:%.*]], i64 [[VL:%.*]])
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 1 x i64>, <vscale x 1 x i64> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 1 x i64> [[TMP1]], ptr [[V0:%.*]], align 8
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 1 x i64>, <vscale x 1 x i64> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 1 x i64> [[TMP2]], ptr [[V1:%.*]], align 8
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u64m1_tu(vuint64m1_t *v0, vuint64m1_t *v1, vuint64m1_t maskedoff0, vuint64m1_t maskedoff1, const uint64_t *base, vuint8mf8_t bindex, size_t vl) {
return vluxseg2ei8_tu(v0, v1, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u64m2_tu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 2 x i64>, <vscale x 2 x i64> } @llvm.riscv.vluxseg2.nxv2i64.nxv2i8.i64(<vscale x 2 x i64> [[MASKEDOFF0:%.*]], <vscale x 2 x i64> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 2 x i8> [[BINDEX:%.*]], i64 [[VL:%.*]])
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 2 x i64>, <vscale x 2 x i64> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 2 x i64> [[TMP1]], ptr [[V0:%.*]], align 8
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 2 x i64>, <vscale x 2 x i64> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 2 x i64> [[TMP2]], ptr [[V1:%.*]], align 8
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u64m2_tu(vuint64m2_t *v0, vuint64m2_t *v1, vuint64m2_t maskedoff0, vuint64m2_t maskedoff1, const uint64_t *base, vuint8mf4_t bindex, size_t vl) {
return vluxseg2ei8_tu(v0, v1, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u64m4_tu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 4 x i64>, <vscale x 4 x i64> } @llvm.riscv.vluxseg2.nxv4i64.nxv4i8.i64(<vscale x 4 x i64> [[MASKEDOFF0:%.*]], <vscale x 4 x i64> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 4 x i8> [[BINDEX:%.*]], i64 [[VL:%.*]])
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 4 x i64>, <vscale x 4 x i64> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 4 x i64> [[TMP1]], ptr [[V0:%.*]], align 8
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 4 x i64>, <vscale x 4 x i64> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 4 x i64> [[TMP2]], ptr [[V1:%.*]], align 8
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u64m4_tu(vuint64m4_t *v0, vuint64m4_t *v1, vuint64m4_t maskedoff0, vuint64m4_t maskedoff1, const uint64_t *base, vuint8mf2_t bindex, size_t vl) {
return vluxseg2ei8_tu(v0, v1, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_f16mf4_ta(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 1 x half>, <vscale x 1 x half> } @llvm.riscv.vluxseg2.nxv1f16.nxv1i8.i64(<vscale x 1 x half> poison, <vscale x 1 x half> poison, ptr [[BASE:%.*]], <vscale x 1 x i8> [[BINDEX:%.*]], i64 [[VL:%.*]])
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 1 x half>, <vscale x 1 x half> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 1 x half> [[TMP1]], ptr [[V0:%.*]], align 2
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 1 x half>, <vscale x 1 x half> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 1 x half> [[TMP2]], ptr [[V1:%.*]], align 2
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_f16mf4_ta(vfloat16mf4_t *v0, vfloat16mf4_t *v1, const _Float16 *base, vuint8mf8_t bindex, size_t vl) {
return vluxseg2ei8_ta(v0, v1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_f16mf2_ta(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 2 x half>, <vscale x 2 x half> } @llvm.riscv.vluxseg2.nxv2f16.nxv2i8.i64(<vscale x 2 x half> poison, <vscale x 2 x half> poison, ptr [[BASE:%.*]], <vscale x 2 x i8> [[BINDEX:%.*]], i64 [[VL:%.*]])
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 2 x half>, <vscale x 2 x half> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 2 x half> [[TMP1]], ptr [[V0:%.*]], align 2
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 2 x half>, <vscale x 2 x half> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 2 x half> [[TMP2]], ptr [[V1:%.*]], align 2
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_f16mf2_ta(vfloat16mf2_t *v0, vfloat16mf2_t *v1, const _Float16 *base, vuint8mf4_t bindex, size_t vl) {
return vluxseg2ei8_ta(v0, v1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_f16m1_ta(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 4 x half>, <vscale x 4 x half> } @llvm.riscv.vluxseg2.nxv4f16.nxv4i8.i64(<vscale x 4 x half> poison, <vscale x 4 x half> poison, ptr [[BASE:%.*]], <vscale x 4 x i8> [[BINDEX:%.*]], i64 [[VL:%.*]])
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 4 x half>, <vscale x 4 x half> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 4 x half> [[TMP1]], ptr [[V0:%.*]], align 2
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 4 x half>, <vscale x 4 x half> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 4 x half> [[TMP2]], ptr [[V1:%.*]], align 2
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_f16m1_ta(vfloat16m1_t *v0, vfloat16m1_t *v1, const _Float16 *base, vuint8mf2_t bindex, size_t vl) {
return vluxseg2ei8_ta(v0, v1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_f16m2_ta(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 8 x half>, <vscale x 8 x half> } @llvm.riscv.vluxseg2.nxv8f16.nxv8i8.i64(<vscale x 8 x half> poison, <vscale x 8 x half> poison, ptr [[BASE:%.*]], <vscale x 8 x i8> [[BINDEX:%.*]], i64 [[VL:%.*]])
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 8 x half>, <vscale x 8 x half> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 8 x half> [[TMP1]], ptr [[V0:%.*]], align 2
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 8 x half>, <vscale x 8 x half> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 8 x half> [[TMP2]], ptr [[V1:%.*]], align 2
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_f16m2_ta(vfloat16m2_t *v0, vfloat16m2_t *v1, const _Float16 *base, vuint8m1_t bindex, size_t vl) {
return vluxseg2ei8_ta(v0, v1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_f16m4_ta(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 16 x half>, <vscale x 16 x half> } @llvm.riscv.vluxseg2.nxv16f16.nxv16i8.i64(<vscale x 16 x half> poison, <vscale x 16 x half> poison, ptr [[BASE:%.*]], <vscale x 16 x i8> [[BINDEX:%.*]], i64 [[VL:%.*]])
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 16 x half>, <vscale x 16 x half> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 16 x half> [[TMP1]], ptr [[V0:%.*]], align 2
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 16 x half>, <vscale x 16 x half> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 16 x half> [[TMP2]], ptr [[V1:%.*]], align 2
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_f16m4_ta(vfloat16m4_t *v0, vfloat16m4_t *v1, const _Float16 *base, vuint8m2_t bindex, size_t vl) {
return vluxseg2ei8_ta(v0, v1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_f32mf2_ta(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 1 x float>, <vscale x 1 x float> } @llvm.riscv.vluxseg2.nxv1f32.nxv1i8.i64(<vscale x 1 x float> poison, <vscale x 1 x float> poison, ptr [[BASE:%.*]], <vscale x 1 x i8> [[BINDEX:%.*]], i64 [[VL:%.*]])
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 1 x float>, <vscale x 1 x float> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 1 x float> [[TMP1]], ptr [[V0:%.*]], align 4
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 1 x float>, <vscale x 1 x float> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 1 x float> [[TMP2]], ptr [[V1:%.*]], align 4
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_f32mf2_ta(vfloat32mf2_t *v0, vfloat32mf2_t *v1, const float *base, vuint8mf8_t bindex, size_t vl) {
return vluxseg2ei8_ta(v0, v1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_f32m1_ta(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 2 x float>, <vscale x 2 x float> } @llvm.riscv.vluxseg2.nxv2f32.nxv2i8.i64(<vscale x 2 x float> poison, <vscale x 2 x float> poison, ptr [[BASE:%.*]], <vscale x 2 x i8> [[BINDEX:%.*]], i64 [[VL:%.*]])
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 2 x float>, <vscale x 2 x float> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 2 x float> [[TMP1]], ptr [[V0:%.*]], align 4
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 2 x float>, <vscale x 2 x float> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 2 x float> [[TMP2]], ptr [[V1:%.*]], align 4
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_f32m1_ta(vfloat32m1_t *v0, vfloat32m1_t *v1, const float *base, vuint8mf4_t bindex, size_t vl) {
return vluxseg2ei8_ta(v0, v1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_f32m2_ta(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 4 x float>, <vscale x 4 x float> } @llvm.riscv.vluxseg2.nxv4f32.nxv4i8.i64(<vscale x 4 x float> poison, <vscale x 4 x float> poison, ptr [[BASE:%.*]], <vscale x 4 x i8> [[BINDEX:%.*]], i64 [[VL:%.*]])
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 4 x float>, <vscale x 4 x float> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 4 x float> [[TMP1]], ptr [[V0:%.*]], align 4
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 4 x float>, <vscale x 4 x float> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 4 x float> [[TMP2]], ptr [[V1:%.*]], align 4
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_f32m2_ta(vfloat32m2_t *v0, vfloat32m2_t *v1, const float *base, vuint8mf2_t bindex, size_t vl) {
return vluxseg2ei8_ta(v0, v1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_f32m4_ta(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 8 x float>, <vscale x 8 x float> } @llvm.riscv.vluxseg2.nxv8f32.nxv8i8.i64(<vscale x 8 x float> poison, <vscale x 8 x float> poison, ptr [[BASE:%.*]], <vscale x 8 x i8> [[BINDEX:%.*]], i64 [[VL:%.*]])
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 8 x float>, <vscale x 8 x float> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 8 x float> [[TMP1]], ptr [[V0:%.*]], align 4
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 8 x float>, <vscale x 8 x float> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 8 x float> [[TMP2]], ptr [[V1:%.*]], align 4
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_f32m4_ta(vfloat32m4_t *v0, vfloat32m4_t *v1, const float *base, vuint8m1_t bindex, size_t vl) {
return vluxseg2ei8_ta(v0, v1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_f64m1_ta(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 1 x double>, <vscale x 1 x double> } @llvm.riscv.vluxseg2.nxv1f64.nxv1i8.i64(<vscale x 1 x double> poison, <vscale x 1 x double> poison, ptr [[BASE:%.*]], <vscale x 1 x i8> [[BINDEX:%.*]], i64 [[VL:%.*]])
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 1 x double>, <vscale x 1 x double> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 1 x double> [[TMP1]], ptr [[V0:%.*]], align 8
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 1 x double>, <vscale x 1 x double> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 1 x double> [[TMP2]], ptr [[V1:%.*]], align 8
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_f64m1_ta(vfloat64m1_t *v0, vfloat64m1_t *v1, const double *base, vuint8mf8_t bindex, size_t vl) {
return vluxseg2ei8_ta(v0, v1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_f64m2_ta(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 2 x double>, <vscale x 2 x double> } @llvm.riscv.vluxseg2.nxv2f64.nxv2i8.i64(<vscale x 2 x double> poison, <vscale x 2 x double> poison, ptr [[BASE:%.*]], <vscale x 2 x i8> [[BINDEX:%.*]], i64 [[VL:%.*]])
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 2 x double>, <vscale x 2 x double> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 2 x double> [[TMP1]], ptr [[V0:%.*]], align 8
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 2 x double>, <vscale x 2 x double> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 2 x double> [[TMP2]], ptr [[V1:%.*]], align 8
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_f64m2_ta(vfloat64m2_t *v0, vfloat64m2_t *v1, const double *base, vuint8mf4_t bindex, size_t vl) {
return vluxseg2ei8_ta(v0, v1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_f64m4_ta(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 4 x double>, <vscale x 4 x double> } @llvm.riscv.vluxseg2.nxv4f64.nxv4i8.i64(<vscale x 4 x double> poison, <vscale x 4 x double> poison, ptr [[BASE:%.*]], <vscale x 4 x i8> [[BINDEX:%.*]], i64 [[VL:%.*]])
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 4 x double>, <vscale x 4 x double> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 4 x double> [[TMP1]], ptr [[V0:%.*]], align 8
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 4 x double>, <vscale x 4 x double> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 4 x double> [[TMP2]], ptr [[V1:%.*]], align 8
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_f64m4_ta(vfloat64m4_t *v0, vfloat64m4_t *v1, const double *base, vuint8mf2_t bindex, size_t vl) {
return vluxseg2ei8_ta(v0, v1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i8mf8_ta(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 1 x i8>, <vscale x 1 x i8> } @llvm.riscv.vluxseg2.nxv1i8.nxv1i8.i64(<vscale x 1 x i8> poison, <vscale x 1 x i8> poison, ptr [[BASE:%.*]], <vscale x 1 x i8> [[BINDEX:%.*]], i64 [[VL:%.*]])
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 1 x i8>, <vscale x 1 x i8> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 1 x i8> [[TMP1]], ptr [[V0:%.*]], align 1
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 1 x i8>, <vscale x 1 x i8> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 1 x i8> [[TMP2]], ptr [[V1:%.*]], align 1
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i8mf8_ta(vint8mf8_t *v0, vint8mf8_t *v1, const int8_t *base, vuint8mf8_t bindex, size_t vl) {
return vluxseg2ei8_ta(v0, v1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i8mf4_ta(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 2 x i8>, <vscale x 2 x i8> } @llvm.riscv.vluxseg2.nxv2i8.nxv2i8.i64(<vscale x 2 x i8> poison, <vscale x 2 x i8> poison, ptr [[BASE:%.*]], <vscale x 2 x i8> [[BINDEX:%.*]], i64 [[VL:%.*]])
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 2 x i8>, <vscale x 2 x i8> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 2 x i8> [[TMP1]], ptr [[V0:%.*]], align 1
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 2 x i8>, <vscale x 2 x i8> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 2 x i8> [[TMP2]], ptr [[V1:%.*]], align 1
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i8mf4_ta(vint8mf4_t *v0, vint8mf4_t *v1, const int8_t *base, vuint8mf4_t bindex, size_t vl) {
return vluxseg2ei8_ta(v0, v1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i8mf2_ta(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 4 x i8>, <vscale x 4 x i8> } @llvm.riscv.vluxseg2.nxv4i8.nxv4i8.i64(<vscale x 4 x i8> poison, <vscale x 4 x i8> poison, ptr [[BASE:%.*]], <vscale x 4 x i8> [[BINDEX:%.*]], i64 [[VL:%.*]])
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 4 x i8>, <vscale x 4 x i8> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 4 x i8> [[TMP1]], ptr [[V0:%.*]], align 1
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 4 x i8>, <vscale x 4 x i8> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 4 x i8> [[TMP2]], ptr [[V1:%.*]], align 1
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i8mf2_ta(vint8mf2_t *v0, vint8mf2_t *v1, const int8_t *base, vuint8mf2_t bindex, size_t vl) {
return vluxseg2ei8_ta(v0, v1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i8m1_ta(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 8 x i8>, <vscale x 8 x i8> } @llvm.riscv.vluxseg2.nxv8i8.nxv8i8.i64(<vscale x 8 x i8> poison, <vscale x 8 x i8> poison, ptr [[BASE:%.*]], <vscale x 8 x i8> [[BINDEX:%.*]], i64 [[VL:%.*]])
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 8 x i8>, <vscale x 8 x i8> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 8 x i8> [[TMP1]], ptr [[V0:%.*]], align 1
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 8 x i8>, <vscale x 8 x i8> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 8 x i8> [[TMP2]], ptr [[V1:%.*]], align 1
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i8m1_ta(vint8m1_t *v0, vint8m1_t *v1, const int8_t *base, vuint8m1_t bindex, size_t vl) {
return vluxseg2ei8_ta(v0, v1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i8m2_ta(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 16 x i8>, <vscale x 16 x i8> } @llvm.riscv.vluxseg2.nxv16i8.nxv16i8.i64(<vscale x 16 x i8> poison, <vscale x 16 x i8> poison, ptr [[BASE:%.*]], <vscale x 16 x i8> [[BINDEX:%.*]], i64 [[VL:%.*]])
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 16 x i8>, <vscale x 16 x i8> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 16 x i8> [[TMP1]], ptr [[V0:%.*]], align 1
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 16 x i8>, <vscale x 16 x i8> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 16 x i8> [[TMP2]], ptr [[V1:%.*]], align 1
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i8m2_ta(vint8m2_t *v0, vint8m2_t *v1, const int8_t *base, vuint8m2_t bindex, size_t vl) {
return vluxseg2ei8_ta(v0, v1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i8m4_ta(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 32 x i8>, <vscale x 32 x i8> } @llvm.riscv.vluxseg2.nxv32i8.nxv32i8.i64(<vscale x 32 x i8> poison, <vscale x 32 x i8> poison, ptr [[BASE:%.*]], <vscale x 32 x i8> [[BINDEX:%.*]], i64 [[VL:%.*]])
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 32 x i8>, <vscale x 32 x i8> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 32 x i8> [[TMP1]], ptr [[V0:%.*]], align 1
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 32 x i8>, <vscale x 32 x i8> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 32 x i8> [[TMP2]], ptr [[V1:%.*]], align 1
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i8m4_ta(vint8m4_t *v0, vint8m4_t *v1, const int8_t *base, vuint8m4_t bindex, size_t vl) {
return vluxseg2ei8_ta(v0, v1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i16mf4_ta(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 1 x i16>, <vscale x 1 x i16> } @llvm.riscv.vluxseg2.nxv1i16.nxv1i8.i64(<vscale x 1 x i16> poison, <vscale x 1 x i16> poison, ptr [[BASE:%.*]], <vscale x 1 x i8> [[BINDEX:%.*]], i64 [[VL:%.*]])
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 1 x i16>, <vscale x 1 x i16> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 1 x i16> [[TMP1]], ptr [[V0:%.*]], align 2
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 1 x i16>, <vscale x 1 x i16> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 1 x i16> [[TMP2]], ptr [[V1:%.*]], align 2
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i16mf4_ta(vint16mf4_t *v0, vint16mf4_t *v1, const int16_t *base, vuint8mf8_t bindex, size_t vl) {
return vluxseg2ei8_ta(v0, v1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i16mf2_ta(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 2 x i16>, <vscale x 2 x i16> } @llvm.riscv.vluxseg2.nxv2i16.nxv2i8.i64(<vscale x 2 x i16> poison, <vscale x 2 x i16> poison, ptr [[BASE:%.*]], <vscale x 2 x i8> [[BINDEX:%.*]], i64 [[VL:%.*]])
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 2 x i16>, <vscale x 2 x i16> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 2 x i16> [[TMP1]], ptr [[V0:%.*]], align 2
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 2 x i16>, <vscale x 2 x i16> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 2 x i16> [[TMP2]], ptr [[V1:%.*]], align 2
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i16mf2_ta(vint16mf2_t *v0, vint16mf2_t *v1, const int16_t *base, vuint8mf4_t bindex, size_t vl) {
return vluxseg2ei8_ta(v0, v1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i16m1_ta(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 4 x i16>, <vscale x 4 x i16> } @llvm.riscv.vluxseg2.nxv4i16.nxv4i8.i64(<vscale x 4 x i16> poison, <vscale x 4 x i16> poison, ptr [[BASE:%.*]], <vscale x 4 x i8> [[BINDEX:%.*]], i64 [[VL:%.*]])
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 4 x i16>, <vscale x 4 x i16> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 4 x i16> [[TMP1]], ptr [[V0:%.*]], align 2
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 4 x i16>, <vscale x 4 x i16> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 4 x i16> [[TMP2]], ptr [[V1:%.*]], align 2
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i16m1_ta(vint16m1_t *v0, vint16m1_t *v1, const int16_t *base, vuint8mf2_t bindex, size_t vl) {
return vluxseg2ei8_ta(v0, v1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i16m2_ta(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 8 x i16>, <vscale x 8 x i16> } @llvm.riscv.vluxseg2.nxv8i16.nxv8i8.i64(<vscale x 8 x i16> poison, <vscale x 8 x i16> poison, ptr [[BASE:%.*]], <vscale x 8 x i8> [[BINDEX:%.*]], i64 [[VL:%.*]])
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 8 x i16>, <vscale x 8 x i16> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 8 x i16> [[TMP1]], ptr [[V0:%.*]], align 2
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 8 x i16>, <vscale x 8 x i16> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 8 x i16> [[TMP2]], ptr [[V1:%.*]], align 2
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i16m2_ta(vint16m2_t *v0, vint16m2_t *v1, const int16_t *base, vuint8m1_t bindex, size_t vl) {
return vluxseg2ei8_ta(v0, v1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i16m4_ta(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 16 x i16>, <vscale x 16 x i16> } @llvm.riscv.vluxseg2.nxv16i16.nxv16i8.i64(<vscale x 16 x i16> poison, <vscale x 16 x i16> poison, ptr [[BASE:%.*]], <vscale x 16 x i8> [[BINDEX:%.*]], i64 [[VL:%.*]])
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 16 x i16>, <vscale x 16 x i16> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 16 x i16> [[TMP1]], ptr [[V0:%.*]], align 2
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 16 x i16>, <vscale x 16 x i16> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 16 x i16> [[TMP2]], ptr [[V1:%.*]], align 2
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i16m4_ta(vint16m4_t *v0, vint16m4_t *v1, const int16_t *base, vuint8m2_t bindex, size_t vl) {
return vluxseg2ei8_ta(v0, v1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i32mf2_ta(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 1 x i32>, <vscale x 1 x i32> } @llvm.riscv.vluxseg2.nxv1i32.nxv1i8.i64(<vscale x 1 x i32> poison, <vscale x 1 x i32> poison, ptr [[BASE:%.*]], <vscale x 1 x i8> [[BINDEX:%.*]], i64 [[VL:%.*]])
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 1 x i32>, <vscale x 1 x i32> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 1 x i32> [[TMP1]], ptr [[V0:%.*]], align 4
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 1 x i32>, <vscale x 1 x i32> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 1 x i32> [[TMP2]], ptr [[V1:%.*]], align 4
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i32mf2_ta(vint32mf2_t *v0, vint32mf2_t *v1, const int32_t *base, vuint8mf8_t bindex, size_t vl) {
return vluxseg2ei8_ta(v0, v1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i32m1_ta(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 2 x i32>, <vscale x 2 x i32> } @llvm.riscv.vluxseg2.nxv2i32.nxv2i8.i64(<vscale x 2 x i32> poison, <vscale x 2 x i32> poison, ptr [[BASE:%.*]], <vscale x 2 x i8> [[BINDEX:%.*]], i64 [[VL:%.*]])
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 2 x i32>, <vscale x 2 x i32> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 2 x i32> [[TMP1]], ptr [[V0:%.*]], align 4
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 2 x i32>, <vscale x 2 x i32> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 2 x i32> [[TMP2]], ptr [[V1:%.*]], align 4
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i32m1_ta(vint32m1_t *v0, vint32m1_t *v1, const int32_t *base, vuint8mf4_t bindex, size_t vl) {
return vluxseg2ei8_ta(v0, v1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i32m2_ta(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 4 x i32>, <vscale x 4 x i32> } @llvm.riscv.vluxseg2.nxv4i32.nxv4i8.i64(<vscale x 4 x i32> poison, <vscale x 4 x i32> poison, ptr [[BASE:%.*]], <vscale x 4 x i8> [[BINDEX:%.*]], i64 [[VL:%.*]])
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 4 x i32>, <vscale x 4 x i32> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 4 x i32> [[TMP1]], ptr [[V0:%.*]], align 4
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 4 x i32>, <vscale x 4 x i32> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 4 x i32> [[TMP2]], ptr [[V1:%.*]], align 4
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i32m2_ta(vint32m2_t *v0, vint32m2_t *v1, const int32_t *base, vuint8mf2_t bindex, size_t vl) {
return vluxseg2ei8_ta(v0, v1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i32m4_ta(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 8 x i32>, <vscale x 8 x i32> } @llvm.riscv.vluxseg2.nxv8i32.nxv8i8.i64(<vscale x 8 x i32> poison, <vscale x 8 x i32> poison, ptr [[BASE:%.*]], <vscale x 8 x i8> [[BINDEX:%.*]], i64 [[VL:%.*]])
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 8 x i32>, <vscale x 8 x i32> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 8 x i32> [[TMP1]], ptr [[V0:%.*]], align 4
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 8 x i32>, <vscale x 8 x i32> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 8 x i32> [[TMP2]], ptr [[V1:%.*]], align 4
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i32m4_ta(vint32m4_t *v0, vint32m4_t *v1, const int32_t *base, vuint8m1_t bindex, size_t vl) {
return vluxseg2ei8_ta(v0, v1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i64m1_ta(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 1 x i64>, <vscale x 1 x i64> } @llvm.riscv.vluxseg2.nxv1i64.nxv1i8.i64(<vscale x 1 x i64> poison, <vscale x 1 x i64> poison, ptr [[BASE:%.*]], <vscale x 1 x i8> [[BINDEX:%.*]], i64 [[VL:%.*]])
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 1 x i64>, <vscale x 1 x i64> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 1 x i64> [[TMP1]], ptr [[V0:%.*]], align 8
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 1 x i64>, <vscale x 1 x i64> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 1 x i64> [[TMP2]], ptr [[V1:%.*]], align 8
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i64m1_ta(vint64m1_t *v0, vint64m1_t *v1, const int64_t *base, vuint8mf8_t bindex, size_t vl) {
return vluxseg2ei8_ta(v0, v1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i64m2_ta(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 2 x i64>, <vscale x 2 x i64> } @llvm.riscv.vluxseg2.nxv2i64.nxv2i8.i64(<vscale x 2 x i64> poison, <vscale x 2 x i64> poison, ptr [[BASE:%.*]], <vscale x 2 x i8> [[BINDEX:%.*]], i64 [[VL:%.*]])
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 2 x i64>, <vscale x 2 x i64> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 2 x i64> [[TMP1]], ptr [[V0:%.*]], align 8
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 2 x i64>, <vscale x 2 x i64> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 2 x i64> [[TMP2]], ptr [[V1:%.*]], align 8
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i64m2_ta(vint64m2_t *v0, vint64m2_t *v1, const int64_t *base, vuint8mf4_t bindex, size_t vl) {
return vluxseg2ei8_ta(v0, v1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i64m4_ta(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 4 x i64>, <vscale x 4 x i64> } @llvm.riscv.vluxseg2.nxv4i64.nxv4i8.i64(<vscale x 4 x i64> poison, <vscale x 4 x i64> poison, ptr [[BASE:%.*]], <vscale x 4 x i8> [[BINDEX:%.*]], i64 [[VL:%.*]])
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 4 x i64>, <vscale x 4 x i64> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 4 x i64> [[TMP1]], ptr [[V0:%.*]], align 8
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 4 x i64>, <vscale x 4 x i64> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 4 x i64> [[TMP2]], ptr [[V1:%.*]], align 8
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i64m4_ta(vint64m4_t *v0, vint64m4_t *v1, const int64_t *base, vuint8mf2_t bindex, size_t vl) {
return vluxseg2ei8_ta(v0, v1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u8mf8_ta(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 1 x i8>, <vscale x 1 x i8> } @llvm.riscv.vluxseg2.nxv1i8.nxv1i8.i64(<vscale x 1 x i8> poison, <vscale x 1 x i8> poison, ptr [[BASE:%.*]], <vscale x 1 x i8> [[BINDEX:%.*]], i64 [[VL:%.*]])
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 1 x i8>, <vscale x 1 x i8> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 1 x i8> [[TMP1]], ptr [[V0:%.*]], align 1
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 1 x i8>, <vscale x 1 x i8> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 1 x i8> [[TMP2]], ptr [[V1:%.*]], align 1
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u8mf8_ta(vuint8mf8_t *v0, vuint8mf8_t *v1, const uint8_t *base, vuint8mf8_t bindex, size_t vl) {
return vluxseg2ei8_ta(v0, v1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u8mf4_ta(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 2 x i8>, <vscale x 2 x i8> } @llvm.riscv.vluxseg2.nxv2i8.nxv2i8.i64(<vscale x 2 x i8> poison, <vscale x 2 x i8> poison, ptr [[BASE:%.*]], <vscale x 2 x i8> [[BINDEX:%.*]], i64 [[VL:%.*]])
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 2 x i8>, <vscale x 2 x i8> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 2 x i8> [[TMP1]], ptr [[V0:%.*]], align 1
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 2 x i8>, <vscale x 2 x i8> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 2 x i8> [[TMP2]], ptr [[V1:%.*]], align 1
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u8mf4_ta(vuint8mf4_t *v0, vuint8mf4_t *v1, const uint8_t *base, vuint8mf4_t bindex, size_t vl) {
return vluxseg2ei8_ta(v0, v1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u8mf2_ta(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 4 x i8>, <vscale x 4 x i8> } @llvm.riscv.vluxseg2.nxv4i8.nxv4i8.i64(<vscale x 4 x i8> poison, <vscale x 4 x i8> poison, ptr [[BASE:%.*]], <vscale x 4 x i8> [[BINDEX:%.*]], i64 [[VL:%.*]])
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 4 x i8>, <vscale x 4 x i8> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 4 x i8> [[TMP1]], ptr [[V0:%.*]], align 1
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 4 x i8>, <vscale x 4 x i8> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 4 x i8> [[TMP2]], ptr [[V1:%.*]], align 1
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u8mf2_ta(vuint8mf2_t *v0, vuint8mf2_t *v1, const uint8_t *base, vuint8mf2_t bindex, size_t vl) {
return vluxseg2ei8_ta(v0, v1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u8m1_ta(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 8 x i8>, <vscale x 8 x i8> } @llvm.riscv.vluxseg2.nxv8i8.nxv8i8.i64(<vscale x 8 x i8> poison, <vscale x 8 x i8> poison, ptr [[BASE:%.*]], <vscale x 8 x i8> [[BINDEX:%.*]], i64 [[VL:%.*]])
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 8 x i8>, <vscale x 8 x i8> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 8 x i8> [[TMP1]], ptr [[V0:%.*]], align 1
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 8 x i8>, <vscale x 8 x i8> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 8 x i8> [[TMP2]], ptr [[V1:%.*]], align 1
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u8m1_ta(vuint8m1_t *v0, vuint8m1_t *v1, const uint8_t *base, vuint8m1_t bindex, size_t vl) {
return vluxseg2ei8_ta(v0, v1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u8m2_ta(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 16 x i8>, <vscale x 16 x i8> } @llvm.riscv.vluxseg2.nxv16i8.nxv16i8.i64(<vscale x 16 x i8> poison, <vscale x 16 x i8> poison, ptr [[BASE:%.*]], <vscale x 16 x i8> [[BINDEX:%.*]], i64 [[VL:%.*]])
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 16 x i8>, <vscale x 16 x i8> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 16 x i8> [[TMP1]], ptr [[V0:%.*]], align 1
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 16 x i8>, <vscale x 16 x i8> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 16 x i8> [[TMP2]], ptr [[V1:%.*]], align 1
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u8m2_ta(vuint8m2_t *v0, vuint8m2_t *v1, const uint8_t *base, vuint8m2_t bindex, size_t vl) {
return vluxseg2ei8_ta(v0, v1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u8m4_ta(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 32 x i8>, <vscale x 32 x i8> } @llvm.riscv.vluxseg2.nxv32i8.nxv32i8.i64(<vscale x 32 x i8> poison, <vscale x 32 x i8> poison, ptr [[BASE:%.*]], <vscale x 32 x i8> [[BINDEX:%.*]], i64 [[VL:%.*]])
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 32 x i8>, <vscale x 32 x i8> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 32 x i8> [[TMP1]], ptr [[V0:%.*]], align 1
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 32 x i8>, <vscale x 32 x i8> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 32 x i8> [[TMP2]], ptr [[V1:%.*]], align 1
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u8m4_ta(vuint8m4_t *v0, vuint8m4_t *v1, const uint8_t *base, vuint8m4_t bindex, size_t vl) {
return vluxseg2ei8_ta(v0, v1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u16mf4_ta(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 1 x i16>, <vscale x 1 x i16> } @llvm.riscv.vluxseg2.nxv1i16.nxv1i8.i64(<vscale x 1 x i16> poison, <vscale x 1 x i16> poison, ptr [[BASE:%.*]], <vscale x 1 x i8> [[BINDEX:%.*]], i64 [[VL:%.*]])
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 1 x i16>, <vscale x 1 x i16> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 1 x i16> [[TMP1]], ptr [[V0:%.*]], align 2
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 1 x i16>, <vscale x 1 x i16> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 1 x i16> [[TMP2]], ptr [[V1:%.*]], align 2
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u16mf4_ta(vuint16mf4_t *v0, vuint16mf4_t *v1, const uint16_t *base, vuint8mf8_t bindex, size_t vl) {
return vluxseg2ei8_ta(v0, v1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u16mf2_ta(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 2 x i16>, <vscale x 2 x i16> } @llvm.riscv.vluxseg2.nxv2i16.nxv2i8.i64(<vscale x 2 x i16> poison, <vscale x 2 x i16> poison, ptr [[BASE:%.*]], <vscale x 2 x i8> [[BINDEX:%.*]], i64 [[VL:%.*]])
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 2 x i16>, <vscale x 2 x i16> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 2 x i16> [[TMP1]], ptr [[V0:%.*]], align 2
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 2 x i16>, <vscale x 2 x i16> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 2 x i16> [[TMP2]], ptr [[V1:%.*]], align 2
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u16mf2_ta(vuint16mf2_t *v0, vuint16mf2_t *v1, const uint16_t *base, vuint8mf4_t bindex, size_t vl) {
return vluxseg2ei8_ta(v0, v1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u16m1_ta(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 4 x i16>, <vscale x 4 x i16> } @llvm.riscv.vluxseg2.nxv4i16.nxv4i8.i64(<vscale x 4 x i16> poison, <vscale x 4 x i16> poison, ptr [[BASE:%.*]], <vscale x 4 x i8> [[BINDEX:%.*]], i64 [[VL:%.*]])
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 4 x i16>, <vscale x 4 x i16> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 4 x i16> [[TMP1]], ptr [[V0:%.*]], align 2
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 4 x i16>, <vscale x 4 x i16> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 4 x i16> [[TMP2]], ptr [[V1:%.*]], align 2
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u16m1_ta(vuint16m1_t *v0, vuint16m1_t *v1, const uint16_t *base, vuint8mf2_t bindex, size_t vl) {
return vluxseg2ei8_ta(v0, v1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u16m2_ta(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 8 x i16>, <vscale x 8 x i16> } @llvm.riscv.vluxseg2.nxv8i16.nxv8i8.i64(<vscale x 8 x i16> poison, <vscale x 8 x i16> poison, ptr [[BASE:%.*]], <vscale x 8 x i8> [[BINDEX:%.*]], i64 [[VL:%.*]])
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 8 x i16>, <vscale x 8 x i16> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 8 x i16> [[TMP1]], ptr [[V0:%.*]], align 2
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 8 x i16>, <vscale x 8 x i16> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 8 x i16> [[TMP2]], ptr [[V1:%.*]], align 2
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u16m2_ta(vuint16m2_t *v0, vuint16m2_t *v1, const uint16_t *base, vuint8m1_t bindex, size_t vl) {
return vluxseg2ei8_ta(v0, v1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u16m4_ta(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 16 x i16>, <vscale x 16 x i16> } @llvm.riscv.vluxseg2.nxv16i16.nxv16i8.i64(<vscale x 16 x i16> poison, <vscale x 16 x i16> poison, ptr [[BASE:%.*]], <vscale x 16 x i8> [[BINDEX:%.*]], i64 [[VL:%.*]])
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 16 x i16>, <vscale x 16 x i16> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 16 x i16> [[TMP1]], ptr [[V0:%.*]], align 2
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 16 x i16>, <vscale x 16 x i16> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 16 x i16> [[TMP2]], ptr [[V1:%.*]], align 2
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u16m4_ta(vuint16m4_t *v0, vuint16m4_t *v1, const uint16_t *base, vuint8m2_t bindex, size_t vl) {
return vluxseg2ei8_ta(v0, v1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u32mf2_ta(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 1 x i32>, <vscale x 1 x i32> } @llvm.riscv.vluxseg2.nxv1i32.nxv1i8.i64(<vscale x 1 x i32> poison, <vscale x 1 x i32> poison, ptr [[BASE:%.*]], <vscale x 1 x i8> [[BINDEX:%.*]], i64 [[VL:%.*]])
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 1 x i32>, <vscale x 1 x i32> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 1 x i32> [[TMP1]], ptr [[V0:%.*]], align 4
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 1 x i32>, <vscale x 1 x i32> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 1 x i32> [[TMP2]], ptr [[V1:%.*]], align 4
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u32mf2_ta(vuint32mf2_t *v0, vuint32mf2_t *v1, const uint32_t *base, vuint8mf8_t bindex, size_t vl) {
return vluxseg2ei8_ta(v0, v1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u32m1_ta(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 2 x i32>, <vscale x 2 x i32> } @llvm.riscv.vluxseg2.nxv2i32.nxv2i8.i64(<vscale x 2 x i32> poison, <vscale x 2 x i32> poison, ptr [[BASE:%.*]], <vscale x 2 x i8> [[BINDEX:%.*]], i64 [[VL:%.*]])
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 2 x i32>, <vscale x 2 x i32> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 2 x i32> [[TMP1]], ptr [[V0:%.*]], align 4
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 2 x i32>, <vscale x 2 x i32> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 2 x i32> [[TMP2]], ptr [[V1:%.*]], align 4
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u32m1_ta(vuint32m1_t *v0, vuint32m1_t *v1, const uint32_t *base, vuint8mf4_t bindex, size_t vl) {
return vluxseg2ei8_ta(v0, v1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u32m2_ta(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 4 x i32>, <vscale x 4 x i32> } @llvm.riscv.vluxseg2.nxv4i32.nxv4i8.i64(<vscale x 4 x i32> poison, <vscale x 4 x i32> poison, ptr [[BASE:%.*]], <vscale x 4 x i8> [[BINDEX:%.*]], i64 [[VL:%.*]])
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 4 x i32>, <vscale x 4 x i32> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 4 x i32> [[TMP1]], ptr [[V0:%.*]], align 4
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 4 x i32>, <vscale x 4 x i32> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 4 x i32> [[TMP2]], ptr [[V1:%.*]], align 4
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u32m2_ta(vuint32m2_t *v0, vuint32m2_t *v1, const uint32_t *base, vuint8mf2_t bindex, size_t vl) {
return vluxseg2ei8_ta(v0, v1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u32m4_ta(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 8 x i32>, <vscale x 8 x i32> } @llvm.riscv.vluxseg2.nxv8i32.nxv8i8.i64(<vscale x 8 x i32> poison, <vscale x 8 x i32> poison, ptr [[BASE:%.*]], <vscale x 8 x i8> [[BINDEX:%.*]], i64 [[VL:%.*]])
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 8 x i32>, <vscale x 8 x i32> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 8 x i32> [[TMP1]], ptr [[V0:%.*]], align 4
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 8 x i32>, <vscale x 8 x i32> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 8 x i32> [[TMP2]], ptr [[V1:%.*]], align 4
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u32m4_ta(vuint32m4_t *v0, vuint32m4_t *v1, const uint32_t *base, vuint8m1_t bindex, size_t vl) {
return vluxseg2ei8_ta(v0, v1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u64m1_ta(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 1 x i64>, <vscale x 1 x i64> } @llvm.riscv.vluxseg2.nxv1i64.nxv1i8.i64(<vscale x 1 x i64> poison, <vscale x 1 x i64> poison, ptr [[BASE:%.*]], <vscale x 1 x i8> [[BINDEX:%.*]], i64 [[VL:%.*]])
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 1 x i64>, <vscale x 1 x i64> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 1 x i64> [[TMP1]], ptr [[V0:%.*]], align 8
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 1 x i64>, <vscale x 1 x i64> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 1 x i64> [[TMP2]], ptr [[V1:%.*]], align 8
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u64m1_ta(vuint64m1_t *v0, vuint64m1_t *v1, const uint64_t *base, vuint8mf8_t bindex, size_t vl) {
return vluxseg2ei8_ta(v0, v1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u64m2_ta(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 2 x i64>, <vscale x 2 x i64> } @llvm.riscv.vluxseg2.nxv2i64.nxv2i8.i64(<vscale x 2 x i64> poison, <vscale x 2 x i64> poison, ptr [[BASE:%.*]], <vscale x 2 x i8> [[BINDEX:%.*]], i64 [[VL:%.*]])
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 2 x i64>, <vscale x 2 x i64> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 2 x i64> [[TMP1]], ptr [[V0:%.*]], align 8
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 2 x i64>, <vscale x 2 x i64> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 2 x i64> [[TMP2]], ptr [[V1:%.*]], align 8
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u64m2_ta(vuint64m2_t *v0, vuint64m2_t *v1, const uint64_t *base, vuint8mf4_t bindex, size_t vl) {
return vluxseg2ei8_ta(v0, v1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u64m4_ta(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 4 x i64>, <vscale x 4 x i64> } @llvm.riscv.vluxseg2.nxv4i64.nxv4i8.i64(<vscale x 4 x i64> poison, <vscale x 4 x i64> poison, ptr [[BASE:%.*]], <vscale x 4 x i8> [[BINDEX:%.*]], i64 [[VL:%.*]])
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 4 x i64>, <vscale x 4 x i64> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 4 x i64> [[TMP1]], ptr [[V0:%.*]], align 8
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 4 x i64>, <vscale x 4 x i64> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 4 x i64> [[TMP2]], ptr [[V1:%.*]], align 8
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u64m4_ta(vuint64m4_t *v0, vuint64m4_t *v1, const uint64_t *base, vuint8mf2_t bindex, size_t vl) {
return vluxseg2ei8_ta(v0, v1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_f16mf4_tuma(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 1 x half>, <vscale x 1 x half> } @llvm.riscv.vluxseg2.mask.nxv1f16.nxv1i8.i64(<vscale x 1 x half> [[MASKEDOFF0:%.*]], <vscale x 1 x half> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 1 x i8> [[BINDEX:%.*]], <vscale x 1 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 2)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 1 x half>, <vscale x 1 x half> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 1 x half> [[TMP1]], ptr [[V0:%.*]], align 2
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 1 x half>, <vscale x 1 x half> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 1 x half> [[TMP2]], ptr [[V1:%.*]], align 2
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_f16mf4_tuma(vfloat16mf4_t *v0, vfloat16mf4_t *v1, vbool64_t mask, vfloat16mf4_t maskedoff0, vfloat16mf4_t maskedoff1, const _Float16 *base, vuint8mf8_t bindex, size_t vl) {
return vluxseg2ei8_tuma(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_f16mf2_tuma(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 2 x half>, <vscale x 2 x half> } @llvm.riscv.vluxseg2.mask.nxv2f16.nxv2i8.i64(<vscale x 2 x half> [[MASKEDOFF0:%.*]], <vscale x 2 x half> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 2 x i8> [[BINDEX:%.*]], <vscale x 2 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 2)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 2 x half>, <vscale x 2 x half> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 2 x half> [[TMP1]], ptr [[V0:%.*]], align 2
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 2 x half>, <vscale x 2 x half> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 2 x half> [[TMP2]], ptr [[V1:%.*]], align 2
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_f16mf2_tuma(vfloat16mf2_t *v0, vfloat16mf2_t *v1, vbool32_t mask, vfloat16mf2_t maskedoff0, vfloat16mf2_t maskedoff1, const _Float16 *base, vuint8mf4_t bindex, size_t vl) {
return vluxseg2ei8_tuma(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_f16m1_tuma(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 4 x half>, <vscale x 4 x half> } @llvm.riscv.vluxseg2.mask.nxv4f16.nxv4i8.i64(<vscale x 4 x half> [[MASKEDOFF0:%.*]], <vscale x 4 x half> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 4 x i8> [[BINDEX:%.*]], <vscale x 4 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 2)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 4 x half>, <vscale x 4 x half> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 4 x half> [[TMP1]], ptr [[V0:%.*]], align 2
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 4 x half>, <vscale x 4 x half> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 4 x half> [[TMP2]], ptr [[V1:%.*]], align 2
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_f16m1_tuma(vfloat16m1_t *v0, vfloat16m1_t *v1, vbool16_t mask, vfloat16m1_t maskedoff0, vfloat16m1_t maskedoff1, const _Float16 *base, vuint8mf2_t bindex, size_t vl) {
return vluxseg2ei8_tuma(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_f16m2_tuma(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 8 x half>, <vscale x 8 x half> } @llvm.riscv.vluxseg2.mask.nxv8f16.nxv8i8.i64(<vscale x 8 x half> [[MASKEDOFF0:%.*]], <vscale x 8 x half> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 8 x i8> [[BINDEX:%.*]], <vscale x 8 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 2)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 8 x half>, <vscale x 8 x half> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 8 x half> [[TMP1]], ptr [[V0:%.*]], align 2
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 8 x half>, <vscale x 8 x half> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 8 x half> [[TMP2]], ptr [[V1:%.*]], align 2
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_f16m2_tuma(vfloat16m2_t *v0, vfloat16m2_t *v1, vbool8_t mask, vfloat16m2_t maskedoff0, vfloat16m2_t maskedoff1, const _Float16 *base, vuint8m1_t bindex, size_t vl) {
return vluxseg2ei8_tuma(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_f16m4_tuma(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 16 x half>, <vscale x 16 x half> } @llvm.riscv.vluxseg2.mask.nxv16f16.nxv16i8.i64(<vscale x 16 x half> [[MASKEDOFF0:%.*]], <vscale x 16 x half> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 16 x i8> [[BINDEX:%.*]], <vscale x 16 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 2)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 16 x half>, <vscale x 16 x half> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 16 x half> [[TMP1]], ptr [[V0:%.*]], align 2
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 16 x half>, <vscale x 16 x half> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 16 x half> [[TMP2]], ptr [[V1:%.*]], align 2
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_f16m4_tuma(vfloat16m4_t *v0, vfloat16m4_t *v1, vbool4_t mask, vfloat16m4_t maskedoff0, vfloat16m4_t maskedoff1, const _Float16 *base, vuint8m2_t bindex, size_t vl) {
return vluxseg2ei8_tuma(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_f32mf2_tuma(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 1 x float>, <vscale x 1 x float> } @llvm.riscv.vluxseg2.mask.nxv1f32.nxv1i8.i64(<vscale x 1 x float> [[MASKEDOFF0:%.*]], <vscale x 1 x float> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 1 x i8> [[BINDEX:%.*]], <vscale x 1 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 2)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 1 x float>, <vscale x 1 x float> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 1 x float> [[TMP1]], ptr [[V0:%.*]], align 4
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 1 x float>, <vscale x 1 x float> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 1 x float> [[TMP2]], ptr [[V1:%.*]], align 4
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_f32mf2_tuma(vfloat32mf2_t *v0, vfloat32mf2_t *v1, vbool64_t mask, vfloat32mf2_t maskedoff0, vfloat32mf2_t maskedoff1, const float *base, vuint8mf8_t bindex, size_t vl) {
return vluxseg2ei8_tuma(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_f32m1_tuma(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 2 x float>, <vscale x 2 x float> } @llvm.riscv.vluxseg2.mask.nxv2f32.nxv2i8.i64(<vscale x 2 x float> [[MASKEDOFF0:%.*]], <vscale x 2 x float> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 2 x i8> [[BINDEX:%.*]], <vscale x 2 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 2)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 2 x float>, <vscale x 2 x float> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 2 x float> [[TMP1]], ptr [[V0:%.*]], align 4
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 2 x float>, <vscale x 2 x float> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 2 x float> [[TMP2]], ptr [[V1:%.*]], align 4
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_f32m1_tuma(vfloat32m1_t *v0, vfloat32m1_t *v1, vbool32_t mask, vfloat32m1_t maskedoff0, vfloat32m1_t maskedoff1, const float *base, vuint8mf4_t bindex, size_t vl) {
return vluxseg2ei8_tuma(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_f32m2_tuma(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 4 x float>, <vscale x 4 x float> } @llvm.riscv.vluxseg2.mask.nxv4f32.nxv4i8.i64(<vscale x 4 x float> [[MASKEDOFF0:%.*]], <vscale x 4 x float> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 4 x i8> [[BINDEX:%.*]], <vscale x 4 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 2)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 4 x float>, <vscale x 4 x float> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 4 x float> [[TMP1]], ptr [[V0:%.*]], align 4
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 4 x float>, <vscale x 4 x float> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 4 x float> [[TMP2]], ptr [[V1:%.*]], align 4
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_f32m2_tuma(vfloat32m2_t *v0, vfloat32m2_t *v1, vbool16_t mask, vfloat32m2_t maskedoff0, vfloat32m2_t maskedoff1, const float *base, vuint8mf2_t bindex, size_t vl) {
return vluxseg2ei8_tuma(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_f32m4_tuma(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 8 x float>, <vscale x 8 x float> } @llvm.riscv.vluxseg2.mask.nxv8f32.nxv8i8.i64(<vscale x 8 x float> [[MASKEDOFF0:%.*]], <vscale x 8 x float> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 8 x i8> [[BINDEX:%.*]], <vscale x 8 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 2)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 8 x float>, <vscale x 8 x float> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 8 x float> [[TMP1]], ptr [[V0:%.*]], align 4
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 8 x float>, <vscale x 8 x float> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 8 x float> [[TMP2]], ptr [[V1:%.*]], align 4
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_f32m4_tuma(vfloat32m4_t *v0, vfloat32m4_t *v1, vbool8_t mask, vfloat32m4_t maskedoff0, vfloat32m4_t maskedoff1, const float *base, vuint8m1_t bindex, size_t vl) {
return vluxseg2ei8_tuma(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_f64m1_tuma(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 1 x double>, <vscale x 1 x double> } @llvm.riscv.vluxseg2.mask.nxv1f64.nxv1i8.i64(<vscale x 1 x double> [[MASKEDOFF0:%.*]], <vscale x 1 x double> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 1 x i8> [[BINDEX:%.*]], <vscale x 1 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 2)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 1 x double>, <vscale x 1 x double> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 1 x double> [[TMP1]], ptr [[V0:%.*]], align 8
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 1 x double>, <vscale x 1 x double> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 1 x double> [[TMP2]], ptr [[V1:%.*]], align 8
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_f64m1_tuma(vfloat64m1_t *v0, vfloat64m1_t *v1, vbool64_t mask, vfloat64m1_t maskedoff0, vfloat64m1_t maskedoff1, const double *base, vuint8mf8_t bindex, size_t vl) {
return vluxseg2ei8_tuma(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_f64m2_tuma(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 2 x double>, <vscale x 2 x double> } @llvm.riscv.vluxseg2.mask.nxv2f64.nxv2i8.i64(<vscale x 2 x double> [[MASKEDOFF0:%.*]], <vscale x 2 x double> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 2 x i8> [[BINDEX:%.*]], <vscale x 2 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 2)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 2 x double>, <vscale x 2 x double> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 2 x double> [[TMP1]], ptr [[V0:%.*]], align 8
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 2 x double>, <vscale x 2 x double> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 2 x double> [[TMP2]], ptr [[V1:%.*]], align 8
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_f64m2_tuma(vfloat64m2_t *v0, vfloat64m2_t *v1, vbool32_t mask, vfloat64m2_t maskedoff0, vfloat64m2_t maskedoff1, const double *base, vuint8mf4_t bindex, size_t vl) {
return vluxseg2ei8_tuma(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_f64m4_tuma(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 4 x double>, <vscale x 4 x double> } @llvm.riscv.vluxseg2.mask.nxv4f64.nxv4i8.i64(<vscale x 4 x double> [[MASKEDOFF0:%.*]], <vscale x 4 x double> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 4 x i8> [[BINDEX:%.*]], <vscale x 4 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 2)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 4 x double>, <vscale x 4 x double> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 4 x double> [[TMP1]], ptr [[V0:%.*]], align 8
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 4 x double>, <vscale x 4 x double> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 4 x double> [[TMP2]], ptr [[V1:%.*]], align 8
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_f64m4_tuma(vfloat64m4_t *v0, vfloat64m4_t *v1, vbool16_t mask, vfloat64m4_t maskedoff0, vfloat64m4_t maskedoff1, const double *base, vuint8mf2_t bindex, size_t vl) {
return vluxseg2ei8_tuma(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i8mf8_tuma(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 1 x i8>, <vscale x 1 x i8> } @llvm.riscv.vluxseg2.mask.nxv1i8.nxv1i8.i64(<vscale x 1 x i8> [[MASKEDOFF0:%.*]], <vscale x 1 x i8> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 1 x i8> [[BINDEX:%.*]], <vscale x 1 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 2)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 1 x i8>, <vscale x 1 x i8> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 1 x i8> [[TMP1]], ptr [[V0:%.*]], align 1
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 1 x i8>, <vscale x 1 x i8> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 1 x i8> [[TMP2]], ptr [[V1:%.*]], align 1
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i8mf8_tuma(vint8mf8_t *v0, vint8mf8_t *v1, vbool64_t mask, vint8mf8_t maskedoff0, vint8mf8_t maskedoff1, const int8_t *base, vuint8mf8_t bindex, size_t vl) {
return vluxseg2ei8_tuma(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i8mf4_tuma(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 2 x i8>, <vscale x 2 x i8> } @llvm.riscv.vluxseg2.mask.nxv2i8.nxv2i8.i64(<vscale x 2 x i8> [[MASKEDOFF0:%.*]], <vscale x 2 x i8> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 2 x i8> [[BINDEX:%.*]], <vscale x 2 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 2)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 2 x i8>, <vscale x 2 x i8> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 2 x i8> [[TMP1]], ptr [[V0:%.*]], align 1
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 2 x i8>, <vscale x 2 x i8> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 2 x i8> [[TMP2]], ptr [[V1:%.*]], align 1
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i8mf4_tuma(vint8mf4_t *v0, vint8mf4_t *v1, vbool32_t mask, vint8mf4_t maskedoff0, vint8mf4_t maskedoff1, const int8_t *base, vuint8mf4_t bindex, size_t vl) {
return vluxseg2ei8_tuma(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i8mf2_tuma(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 4 x i8>, <vscale x 4 x i8> } @llvm.riscv.vluxseg2.mask.nxv4i8.nxv4i8.i64(<vscale x 4 x i8> [[MASKEDOFF0:%.*]], <vscale x 4 x i8> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 4 x i8> [[BINDEX:%.*]], <vscale x 4 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 2)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 4 x i8>, <vscale x 4 x i8> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 4 x i8> [[TMP1]], ptr [[V0:%.*]], align 1
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 4 x i8>, <vscale x 4 x i8> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 4 x i8> [[TMP2]], ptr [[V1:%.*]], align 1
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i8mf2_tuma(vint8mf2_t *v0, vint8mf2_t *v1, vbool16_t mask, vint8mf2_t maskedoff0, vint8mf2_t maskedoff1, const int8_t *base, vuint8mf2_t bindex, size_t vl) {
return vluxseg2ei8_tuma(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i8m1_tuma(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 8 x i8>, <vscale x 8 x i8> } @llvm.riscv.vluxseg2.mask.nxv8i8.nxv8i8.i64(<vscale x 8 x i8> [[MASKEDOFF0:%.*]], <vscale x 8 x i8> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 8 x i8> [[BINDEX:%.*]], <vscale x 8 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 2)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 8 x i8>, <vscale x 8 x i8> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 8 x i8> [[TMP1]], ptr [[V0:%.*]], align 1
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 8 x i8>, <vscale x 8 x i8> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 8 x i8> [[TMP2]], ptr [[V1:%.*]], align 1
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i8m1_tuma(vint8m1_t *v0, vint8m1_t *v1, vbool8_t mask, vint8m1_t maskedoff0, vint8m1_t maskedoff1, const int8_t *base, vuint8m1_t bindex, size_t vl) {
return vluxseg2ei8_tuma(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i8m2_tuma(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 16 x i8>, <vscale x 16 x i8> } @llvm.riscv.vluxseg2.mask.nxv16i8.nxv16i8.i64(<vscale x 16 x i8> [[MASKEDOFF0:%.*]], <vscale x 16 x i8> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 16 x i8> [[BINDEX:%.*]], <vscale x 16 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 2)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 16 x i8>, <vscale x 16 x i8> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 16 x i8> [[TMP1]], ptr [[V0:%.*]], align 1
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 16 x i8>, <vscale x 16 x i8> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 16 x i8> [[TMP2]], ptr [[V1:%.*]], align 1
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i8m2_tuma(vint8m2_t *v0, vint8m2_t *v1, vbool4_t mask, vint8m2_t maskedoff0, vint8m2_t maskedoff1, const int8_t *base, vuint8m2_t bindex, size_t vl) {
return vluxseg2ei8_tuma(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i8m4_tuma(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 32 x i8>, <vscale x 32 x i8> } @llvm.riscv.vluxseg2.mask.nxv32i8.nxv32i8.i64(<vscale x 32 x i8> [[MASKEDOFF0:%.*]], <vscale x 32 x i8> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 32 x i8> [[BINDEX:%.*]], <vscale x 32 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 2)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 32 x i8>, <vscale x 32 x i8> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 32 x i8> [[TMP1]], ptr [[V0:%.*]], align 1
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 32 x i8>, <vscale x 32 x i8> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 32 x i8> [[TMP2]], ptr [[V1:%.*]], align 1
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i8m4_tuma(vint8m4_t *v0, vint8m4_t *v1, vbool2_t mask, vint8m4_t maskedoff0, vint8m4_t maskedoff1, const int8_t *base, vuint8m4_t bindex, size_t vl) {
return vluxseg2ei8_tuma(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i16mf4_tuma(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 1 x i16>, <vscale x 1 x i16> } @llvm.riscv.vluxseg2.mask.nxv1i16.nxv1i8.i64(<vscale x 1 x i16> [[MASKEDOFF0:%.*]], <vscale x 1 x i16> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 1 x i8> [[BINDEX:%.*]], <vscale x 1 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 2)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 1 x i16>, <vscale x 1 x i16> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 1 x i16> [[TMP1]], ptr [[V0:%.*]], align 2
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 1 x i16>, <vscale x 1 x i16> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 1 x i16> [[TMP2]], ptr [[V1:%.*]], align 2
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i16mf4_tuma(vint16mf4_t *v0, vint16mf4_t *v1, vbool64_t mask, vint16mf4_t maskedoff0, vint16mf4_t maskedoff1, const int16_t *base, vuint8mf8_t bindex, size_t vl) {
return vluxseg2ei8_tuma(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i16mf2_tuma(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 2 x i16>, <vscale x 2 x i16> } @llvm.riscv.vluxseg2.mask.nxv2i16.nxv2i8.i64(<vscale x 2 x i16> [[MASKEDOFF0:%.*]], <vscale x 2 x i16> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 2 x i8> [[BINDEX:%.*]], <vscale x 2 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 2)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 2 x i16>, <vscale x 2 x i16> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 2 x i16> [[TMP1]], ptr [[V0:%.*]], align 2
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 2 x i16>, <vscale x 2 x i16> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 2 x i16> [[TMP2]], ptr [[V1:%.*]], align 2
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i16mf2_tuma(vint16mf2_t *v0, vint16mf2_t *v1, vbool32_t mask, vint16mf2_t maskedoff0, vint16mf2_t maskedoff1, const int16_t *base, vuint8mf4_t bindex, size_t vl) {
return vluxseg2ei8_tuma(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i16m1_tuma(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 4 x i16>, <vscale x 4 x i16> } @llvm.riscv.vluxseg2.mask.nxv4i16.nxv4i8.i64(<vscale x 4 x i16> [[MASKEDOFF0:%.*]], <vscale x 4 x i16> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 4 x i8> [[BINDEX:%.*]], <vscale x 4 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 2)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 4 x i16>, <vscale x 4 x i16> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 4 x i16> [[TMP1]], ptr [[V0:%.*]], align 2
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 4 x i16>, <vscale x 4 x i16> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 4 x i16> [[TMP2]], ptr [[V1:%.*]], align 2
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i16m1_tuma(vint16m1_t *v0, vint16m1_t *v1, vbool16_t mask, vint16m1_t maskedoff0, vint16m1_t maskedoff1, const int16_t *base, vuint8mf2_t bindex, size_t vl) {
return vluxseg2ei8_tuma(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i16m2_tuma(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 8 x i16>, <vscale x 8 x i16> } @llvm.riscv.vluxseg2.mask.nxv8i16.nxv8i8.i64(<vscale x 8 x i16> [[MASKEDOFF0:%.*]], <vscale x 8 x i16> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 8 x i8> [[BINDEX:%.*]], <vscale x 8 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 2)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 8 x i16>, <vscale x 8 x i16> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 8 x i16> [[TMP1]], ptr [[V0:%.*]], align 2
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 8 x i16>, <vscale x 8 x i16> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 8 x i16> [[TMP2]], ptr [[V1:%.*]], align 2
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i16m2_tuma(vint16m2_t *v0, vint16m2_t *v1, vbool8_t mask, vint16m2_t maskedoff0, vint16m2_t maskedoff1, const int16_t *base, vuint8m1_t bindex, size_t vl) {
return vluxseg2ei8_tuma(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i16m4_tuma(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 16 x i16>, <vscale x 16 x i16> } @llvm.riscv.vluxseg2.mask.nxv16i16.nxv16i8.i64(<vscale x 16 x i16> [[MASKEDOFF0:%.*]], <vscale x 16 x i16> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 16 x i8> [[BINDEX:%.*]], <vscale x 16 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 2)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 16 x i16>, <vscale x 16 x i16> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 16 x i16> [[TMP1]], ptr [[V0:%.*]], align 2
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 16 x i16>, <vscale x 16 x i16> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 16 x i16> [[TMP2]], ptr [[V1:%.*]], align 2
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i16m4_tuma(vint16m4_t *v0, vint16m4_t *v1, vbool4_t mask, vint16m4_t maskedoff0, vint16m4_t maskedoff1, const int16_t *base, vuint8m2_t bindex, size_t vl) {
return vluxseg2ei8_tuma(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i32mf2_tuma(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 1 x i32>, <vscale x 1 x i32> } @llvm.riscv.vluxseg2.mask.nxv1i32.nxv1i8.i64(<vscale x 1 x i32> [[MASKEDOFF0:%.*]], <vscale x 1 x i32> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 1 x i8> [[BINDEX:%.*]], <vscale x 1 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 2)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 1 x i32>, <vscale x 1 x i32> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 1 x i32> [[TMP1]], ptr [[V0:%.*]], align 4
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 1 x i32>, <vscale x 1 x i32> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 1 x i32> [[TMP2]], ptr [[V1:%.*]], align 4
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i32mf2_tuma(vint32mf2_t *v0, vint32mf2_t *v1, vbool64_t mask, vint32mf2_t maskedoff0, vint32mf2_t maskedoff1, const int32_t *base, vuint8mf8_t bindex, size_t vl) {
return vluxseg2ei8_tuma(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i32m1_tuma(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 2 x i32>, <vscale x 2 x i32> } @llvm.riscv.vluxseg2.mask.nxv2i32.nxv2i8.i64(<vscale x 2 x i32> [[MASKEDOFF0:%.*]], <vscale x 2 x i32> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 2 x i8> [[BINDEX:%.*]], <vscale x 2 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 2)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 2 x i32>, <vscale x 2 x i32> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 2 x i32> [[TMP1]], ptr [[V0:%.*]], align 4
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 2 x i32>, <vscale x 2 x i32> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 2 x i32> [[TMP2]], ptr [[V1:%.*]], align 4
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i32m1_tuma(vint32m1_t *v0, vint32m1_t *v1, vbool32_t mask, vint32m1_t maskedoff0, vint32m1_t maskedoff1, const int32_t *base, vuint8mf4_t bindex, size_t vl) {
return vluxseg2ei8_tuma(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i32m2_tuma(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 4 x i32>, <vscale x 4 x i32> } @llvm.riscv.vluxseg2.mask.nxv4i32.nxv4i8.i64(<vscale x 4 x i32> [[MASKEDOFF0:%.*]], <vscale x 4 x i32> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 4 x i8> [[BINDEX:%.*]], <vscale x 4 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 2)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 4 x i32>, <vscale x 4 x i32> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 4 x i32> [[TMP1]], ptr [[V0:%.*]], align 4
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 4 x i32>, <vscale x 4 x i32> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 4 x i32> [[TMP2]], ptr [[V1:%.*]], align 4
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i32m2_tuma(vint32m2_t *v0, vint32m2_t *v1, vbool16_t mask, vint32m2_t maskedoff0, vint32m2_t maskedoff1, const int32_t *base, vuint8mf2_t bindex, size_t vl) {
return vluxseg2ei8_tuma(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i32m4_tuma(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 8 x i32>, <vscale x 8 x i32> } @llvm.riscv.vluxseg2.mask.nxv8i32.nxv8i8.i64(<vscale x 8 x i32> [[MASKEDOFF0:%.*]], <vscale x 8 x i32> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 8 x i8> [[BINDEX:%.*]], <vscale x 8 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 2)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 8 x i32>, <vscale x 8 x i32> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 8 x i32> [[TMP1]], ptr [[V0:%.*]], align 4
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 8 x i32>, <vscale x 8 x i32> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 8 x i32> [[TMP2]], ptr [[V1:%.*]], align 4
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i32m4_tuma(vint32m4_t *v0, vint32m4_t *v1, vbool8_t mask, vint32m4_t maskedoff0, vint32m4_t maskedoff1, const int32_t *base, vuint8m1_t bindex, size_t vl) {
return vluxseg2ei8_tuma(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i64m1_tuma(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 1 x i64>, <vscale x 1 x i64> } @llvm.riscv.vluxseg2.mask.nxv1i64.nxv1i8.i64(<vscale x 1 x i64> [[MASKEDOFF0:%.*]], <vscale x 1 x i64> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 1 x i8> [[BINDEX:%.*]], <vscale x 1 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 2)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 1 x i64>, <vscale x 1 x i64> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 1 x i64> [[TMP1]], ptr [[V0:%.*]], align 8
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 1 x i64>, <vscale x 1 x i64> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 1 x i64> [[TMP2]], ptr [[V1:%.*]], align 8
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i64m1_tuma(vint64m1_t *v0, vint64m1_t *v1, vbool64_t mask, vint64m1_t maskedoff0, vint64m1_t maskedoff1, const int64_t *base, vuint8mf8_t bindex, size_t vl) {
return vluxseg2ei8_tuma(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i64m2_tuma(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 2 x i64>, <vscale x 2 x i64> } @llvm.riscv.vluxseg2.mask.nxv2i64.nxv2i8.i64(<vscale x 2 x i64> [[MASKEDOFF0:%.*]], <vscale x 2 x i64> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 2 x i8> [[BINDEX:%.*]], <vscale x 2 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 2)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 2 x i64>, <vscale x 2 x i64> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 2 x i64> [[TMP1]], ptr [[V0:%.*]], align 8
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 2 x i64>, <vscale x 2 x i64> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 2 x i64> [[TMP2]], ptr [[V1:%.*]], align 8
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i64m2_tuma(vint64m2_t *v0, vint64m2_t *v1, vbool32_t mask, vint64m2_t maskedoff0, vint64m2_t maskedoff1, const int64_t *base, vuint8mf4_t bindex, size_t vl) {
return vluxseg2ei8_tuma(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i64m4_tuma(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 4 x i64>, <vscale x 4 x i64> } @llvm.riscv.vluxseg2.mask.nxv4i64.nxv4i8.i64(<vscale x 4 x i64> [[MASKEDOFF0:%.*]], <vscale x 4 x i64> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 4 x i8> [[BINDEX:%.*]], <vscale x 4 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 2)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 4 x i64>, <vscale x 4 x i64> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 4 x i64> [[TMP1]], ptr [[V0:%.*]], align 8
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 4 x i64>, <vscale x 4 x i64> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 4 x i64> [[TMP2]], ptr [[V1:%.*]], align 8
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i64m4_tuma(vint64m4_t *v0, vint64m4_t *v1, vbool16_t mask, vint64m4_t maskedoff0, vint64m4_t maskedoff1, const int64_t *base, vuint8mf2_t bindex, size_t vl) {
return vluxseg2ei8_tuma(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u8mf8_tuma(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 1 x i8>, <vscale x 1 x i8> } @llvm.riscv.vluxseg2.mask.nxv1i8.nxv1i8.i64(<vscale x 1 x i8> [[MASKEDOFF0:%.*]], <vscale x 1 x i8> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 1 x i8> [[BINDEX:%.*]], <vscale x 1 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 2)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 1 x i8>, <vscale x 1 x i8> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 1 x i8> [[TMP1]], ptr [[V0:%.*]], align 1
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 1 x i8>, <vscale x 1 x i8> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 1 x i8> [[TMP2]], ptr [[V1:%.*]], align 1
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u8mf8_tuma(vuint8mf8_t *v0, vuint8mf8_t *v1, vbool64_t mask, vuint8mf8_t maskedoff0, vuint8mf8_t maskedoff1, const uint8_t *base, vuint8mf8_t bindex, size_t vl) {
return vluxseg2ei8_tuma(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u8mf4_tuma(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 2 x i8>, <vscale x 2 x i8> } @llvm.riscv.vluxseg2.mask.nxv2i8.nxv2i8.i64(<vscale x 2 x i8> [[MASKEDOFF0:%.*]], <vscale x 2 x i8> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 2 x i8> [[BINDEX:%.*]], <vscale x 2 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 2)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 2 x i8>, <vscale x 2 x i8> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 2 x i8> [[TMP1]], ptr [[V0:%.*]], align 1
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 2 x i8>, <vscale x 2 x i8> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 2 x i8> [[TMP2]], ptr [[V1:%.*]], align 1
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u8mf4_tuma(vuint8mf4_t *v0, vuint8mf4_t *v1, vbool32_t mask, vuint8mf4_t maskedoff0, vuint8mf4_t maskedoff1, const uint8_t *base, vuint8mf4_t bindex, size_t vl) {
return vluxseg2ei8_tuma(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u8mf2_tuma(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 4 x i8>, <vscale x 4 x i8> } @llvm.riscv.vluxseg2.mask.nxv4i8.nxv4i8.i64(<vscale x 4 x i8> [[MASKEDOFF0:%.*]], <vscale x 4 x i8> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 4 x i8> [[BINDEX:%.*]], <vscale x 4 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 2)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 4 x i8>, <vscale x 4 x i8> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 4 x i8> [[TMP1]], ptr [[V0:%.*]], align 1
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 4 x i8>, <vscale x 4 x i8> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 4 x i8> [[TMP2]], ptr [[V1:%.*]], align 1
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u8mf2_tuma(vuint8mf2_t *v0, vuint8mf2_t *v1, vbool16_t mask, vuint8mf2_t maskedoff0, vuint8mf2_t maskedoff1, const uint8_t *base, vuint8mf2_t bindex, size_t vl) {
return vluxseg2ei8_tuma(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u8m1_tuma(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 8 x i8>, <vscale x 8 x i8> } @llvm.riscv.vluxseg2.mask.nxv8i8.nxv8i8.i64(<vscale x 8 x i8> [[MASKEDOFF0:%.*]], <vscale x 8 x i8> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 8 x i8> [[BINDEX:%.*]], <vscale x 8 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 2)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 8 x i8>, <vscale x 8 x i8> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 8 x i8> [[TMP1]], ptr [[V0:%.*]], align 1
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 8 x i8>, <vscale x 8 x i8> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 8 x i8> [[TMP2]], ptr [[V1:%.*]], align 1
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u8m1_tuma(vuint8m1_t *v0, vuint8m1_t *v1, vbool8_t mask, vuint8m1_t maskedoff0, vuint8m1_t maskedoff1, const uint8_t *base, vuint8m1_t bindex, size_t vl) {
return vluxseg2ei8_tuma(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u8m2_tuma(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 16 x i8>, <vscale x 16 x i8> } @llvm.riscv.vluxseg2.mask.nxv16i8.nxv16i8.i64(<vscale x 16 x i8> [[MASKEDOFF0:%.*]], <vscale x 16 x i8> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 16 x i8> [[BINDEX:%.*]], <vscale x 16 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 2)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 16 x i8>, <vscale x 16 x i8> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 16 x i8> [[TMP1]], ptr [[V0:%.*]], align 1
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 16 x i8>, <vscale x 16 x i8> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 16 x i8> [[TMP2]], ptr [[V1:%.*]], align 1
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u8m2_tuma(vuint8m2_t *v0, vuint8m2_t *v1, vbool4_t mask, vuint8m2_t maskedoff0, vuint8m2_t maskedoff1, const uint8_t *base, vuint8m2_t bindex, size_t vl) {
return vluxseg2ei8_tuma(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u8m4_tuma(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 32 x i8>, <vscale x 32 x i8> } @llvm.riscv.vluxseg2.mask.nxv32i8.nxv32i8.i64(<vscale x 32 x i8> [[MASKEDOFF0:%.*]], <vscale x 32 x i8> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 32 x i8> [[BINDEX:%.*]], <vscale x 32 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 2)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 32 x i8>, <vscale x 32 x i8> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 32 x i8> [[TMP1]], ptr [[V0:%.*]], align 1
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 32 x i8>, <vscale x 32 x i8> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 32 x i8> [[TMP2]], ptr [[V1:%.*]], align 1
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u8m4_tuma(vuint8m4_t *v0, vuint8m4_t *v1, vbool2_t mask, vuint8m4_t maskedoff0, vuint8m4_t maskedoff1, const uint8_t *base, vuint8m4_t bindex, size_t vl) {
return vluxseg2ei8_tuma(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u16mf4_tuma(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 1 x i16>, <vscale x 1 x i16> } @llvm.riscv.vluxseg2.mask.nxv1i16.nxv1i8.i64(<vscale x 1 x i16> [[MASKEDOFF0:%.*]], <vscale x 1 x i16> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 1 x i8> [[BINDEX:%.*]], <vscale x 1 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 2)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 1 x i16>, <vscale x 1 x i16> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 1 x i16> [[TMP1]], ptr [[V0:%.*]], align 2
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 1 x i16>, <vscale x 1 x i16> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 1 x i16> [[TMP2]], ptr [[V1:%.*]], align 2
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u16mf4_tuma(vuint16mf4_t *v0, vuint16mf4_t *v1, vbool64_t mask, vuint16mf4_t maskedoff0, vuint16mf4_t maskedoff1, const uint16_t *base, vuint8mf8_t bindex, size_t vl) {
return vluxseg2ei8_tuma(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u16mf2_tuma(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 2 x i16>, <vscale x 2 x i16> } @llvm.riscv.vluxseg2.mask.nxv2i16.nxv2i8.i64(<vscale x 2 x i16> [[MASKEDOFF0:%.*]], <vscale x 2 x i16> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 2 x i8> [[BINDEX:%.*]], <vscale x 2 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 2)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 2 x i16>, <vscale x 2 x i16> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 2 x i16> [[TMP1]], ptr [[V0:%.*]], align 2
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 2 x i16>, <vscale x 2 x i16> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 2 x i16> [[TMP2]], ptr [[V1:%.*]], align 2
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u16mf2_tuma(vuint16mf2_t *v0, vuint16mf2_t *v1, vbool32_t mask, vuint16mf2_t maskedoff0, vuint16mf2_t maskedoff1, const uint16_t *base, vuint8mf4_t bindex, size_t vl) {
return vluxseg2ei8_tuma(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u16m1_tuma(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 4 x i16>, <vscale x 4 x i16> } @llvm.riscv.vluxseg2.mask.nxv4i16.nxv4i8.i64(<vscale x 4 x i16> [[MASKEDOFF0:%.*]], <vscale x 4 x i16> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 4 x i8> [[BINDEX:%.*]], <vscale x 4 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 2)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 4 x i16>, <vscale x 4 x i16> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 4 x i16> [[TMP1]], ptr [[V0:%.*]], align 2
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 4 x i16>, <vscale x 4 x i16> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 4 x i16> [[TMP2]], ptr [[V1:%.*]], align 2
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u16m1_tuma(vuint16m1_t *v0, vuint16m1_t *v1, vbool16_t mask, vuint16m1_t maskedoff0, vuint16m1_t maskedoff1, const uint16_t *base, vuint8mf2_t bindex, size_t vl) {
return vluxseg2ei8_tuma(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u16m2_tuma(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 8 x i16>, <vscale x 8 x i16> } @llvm.riscv.vluxseg2.mask.nxv8i16.nxv8i8.i64(<vscale x 8 x i16> [[MASKEDOFF0:%.*]], <vscale x 8 x i16> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 8 x i8> [[BINDEX:%.*]], <vscale x 8 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 2)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 8 x i16>, <vscale x 8 x i16> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 8 x i16> [[TMP1]], ptr [[V0:%.*]], align 2
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 8 x i16>, <vscale x 8 x i16> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 8 x i16> [[TMP2]], ptr [[V1:%.*]], align 2
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u16m2_tuma(vuint16m2_t *v0, vuint16m2_t *v1, vbool8_t mask, vuint16m2_t maskedoff0, vuint16m2_t maskedoff1, const uint16_t *base, vuint8m1_t bindex, size_t vl) {
return vluxseg2ei8_tuma(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u16m4_tuma(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 16 x i16>, <vscale x 16 x i16> } @llvm.riscv.vluxseg2.mask.nxv16i16.nxv16i8.i64(<vscale x 16 x i16> [[MASKEDOFF0:%.*]], <vscale x 16 x i16> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 16 x i8> [[BINDEX:%.*]], <vscale x 16 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 2)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 16 x i16>, <vscale x 16 x i16> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 16 x i16> [[TMP1]], ptr [[V0:%.*]], align 2
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 16 x i16>, <vscale x 16 x i16> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 16 x i16> [[TMP2]], ptr [[V1:%.*]], align 2
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u16m4_tuma(vuint16m4_t *v0, vuint16m4_t *v1, vbool4_t mask, vuint16m4_t maskedoff0, vuint16m4_t maskedoff1, const uint16_t *base, vuint8m2_t bindex, size_t vl) {
return vluxseg2ei8_tuma(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u32mf2_tuma(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 1 x i32>, <vscale x 1 x i32> } @llvm.riscv.vluxseg2.mask.nxv1i32.nxv1i8.i64(<vscale x 1 x i32> [[MASKEDOFF0:%.*]], <vscale x 1 x i32> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 1 x i8> [[BINDEX:%.*]], <vscale x 1 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 2)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 1 x i32>, <vscale x 1 x i32> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 1 x i32> [[TMP1]], ptr [[V0:%.*]], align 4
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 1 x i32>, <vscale x 1 x i32> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 1 x i32> [[TMP2]], ptr [[V1:%.*]], align 4
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u32mf2_tuma(vuint32mf2_t *v0, vuint32mf2_t *v1, vbool64_t mask, vuint32mf2_t maskedoff0, vuint32mf2_t maskedoff1, const uint32_t *base, vuint8mf8_t bindex, size_t vl) {
return vluxseg2ei8_tuma(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u32m1_tuma(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 2 x i32>, <vscale x 2 x i32> } @llvm.riscv.vluxseg2.mask.nxv2i32.nxv2i8.i64(<vscale x 2 x i32> [[MASKEDOFF0:%.*]], <vscale x 2 x i32> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 2 x i8> [[BINDEX:%.*]], <vscale x 2 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 2)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 2 x i32>, <vscale x 2 x i32> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 2 x i32> [[TMP1]], ptr [[V0:%.*]], align 4
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 2 x i32>, <vscale x 2 x i32> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 2 x i32> [[TMP2]], ptr [[V1:%.*]], align 4
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u32m1_tuma(vuint32m1_t *v0, vuint32m1_t *v1, vbool32_t mask, vuint32m1_t maskedoff0, vuint32m1_t maskedoff1, const uint32_t *base, vuint8mf4_t bindex, size_t vl) {
return vluxseg2ei8_tuma(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u32m2_tuma(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 4 x i32>, <vscale x 4 x i32> } @llvm.riscv.vluxseg2.mask.nxv4i32.nxv4i8.i64(<vscale x 4 x i32> [[MASKEDOFF0:%.*]], <vscale x 4 x i32> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 4 x i8> [[BINDEX:%.*]], <vscale x 4 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 2)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 4 x i32>, <vscale x 4 x i32> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 4 x i32> [[TMP1]], ptr [[V0:%.*]], align 4
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 4 x i32>, <vscale x 4 x i32> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 4 x i32> [[TMP2]], ptr [[V1:%.*]], align 4
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u32m2_tuma(vuint32m2_t *v0, vuint32m2_t *v1, vbool16_t mask, vuint32m2_t maskedoff0, vuint32m2_t maskedoff1, const uint32_t *base, vuint8mf2_t bindex, size_t vl) {
return vluxseg2ei8_tuma(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u32m4_tuma(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 8 x i32>, <vscale x 8 x i32> } @llvm.riscv.vluxseg2.mask.nxv8i32.nxv8i8.i64(<vscale x 8 x i32> [[MASKEDOFF0:%.*]], <vscale x 8 x i32> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 8 x i8> [[BINDEX:%.*]], <vscale x 8 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 2)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 8 x i32>, <vscale x 8 x i32> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 8 x i32> [[TMP1]], ptr [[V0:%.*]], align 4
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 8 x i32>, <vscale x 8 x i32> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 8 x i32> [[TMP2]], ptr [[V1:%.*]], align 4
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u32m4_tuma(vuint32m4_t *v0, vuint32m4_t *v1, vbool8_t mask, vuint32m4_t maskedoff0, vuint32m4_t maskedoff1, const uint32_t *base, vuint8m1_t bindex, size_t vl) {
return vluxseg2ei8_tuma(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u64m1_tuma(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 1 x i64>, <vscale x 1 x i64> } @llvm.riscv.vluxseg2.mask.nxv1i64.nxv1i8.i64(<vscale x 1 x i64> [[MASKEDOFF0:%.*]], <vscale x 1 x i64> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 1 x i8> [[BINDEX:%.*]], <vscale x 1 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 2)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 1 x i64>, <vscale x 1 x i64> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 1 x i64> [[TMP1]], ptr [[V0:%.*]], align 8
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 1 x i64>, <vscale x 1 x i64> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 1 x i64> [[TMP2]], ptr [[V1:%.*]], align 8
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u64m1_tuma(vuint64m1_t *v0, vuint64m1_t *v1, vbool64_t mask, vuint64m1_t maskedoff0, vuint64m1_t maskedoff1, const uint64_t *base, vuint8mf8_t bindex, size_t vl) {
return vluxseg2ei8_tuma(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u64m2_tuma(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 2 x i64>, <vscale x 2 x i64> } @llvm.riscv.vluxseg2.mask.nxv2i64.nxv2i8.i64(<vscale x 2 x i64> [[MASKEDOFF0:%.*]], <vscale x 2 x i64> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 2 x i8> [[BINDEX:%.*]], <vscale x 2 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 2)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 2 x i64>, <vscale x 2 x i64> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 2 x i64> [[TMP1]], ptr [[V0:%.*]], align 8
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 2 x i64>, <vscale x 2 x i64> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 2 x i64> [[TMP2]], ptr [[V1:%.*]], align 8
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u64m2_tuma(vuint64m2_t *v0, vuint64m2_t *v1, vbool32_t mask, vuint64m2_t maskedoff0, vuint64m2_t maskedoff1, const uint64_t *base, vuint8mf4_t bindex, size_t vl) {
return vluxseg2ei8_tuma(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u64m4_tuma(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 4 x i64>, <vscale x 4 x i64> } @llvm.riscv.vluxseg2.mask.nxv4i64.nxv4i8.i64(<vscale x 4 x i64> [[MASKEDOFF0:%.*]], <vscale x 4 x i64> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 4 x i8> [[BINDEX:%.*]], <vscale x 4 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 2)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 4 x i64>, <vscale x 4 x i64> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 4 x i64> [[TMP1]], ptr [[V0:%.*]], align 8
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 4 x i64>, <vscale x 4 x i64> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 4 x i64> [[TMP2]], ptr [[V1:%.*]], align 8
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u64m4_tuma(vuint64m4_t *v0, vuint64m4_t *v1, vbool16_t mask, vuint64m4_t maskedoff0, vuint64m4_t maskedoff1, const uint64_t *base, vuint8mf2_t bindex, size_t vl) {
return vluxseg2ei8_tuma(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_f16mf4_tumu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 1 x half>, <vscale x 1 x half> } @llvm.riscv.vluxseg2.mask.nxv1f16.nxv1i8.i64(<vscale x 1 x half> [[MASKEDOFF0:%.*]], <vscale x 1 x half> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 1 x i8> [[BINDEX:%.*]], <vscale x 1 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 0)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 1 x half>, <vscale x 1 x half> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 1 x half> [[TMP1]], ptr [[V0:%.*]], align 2
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 1 x half>, <vscale x 1 x half> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 1 x half> [[TMP2]], ptr [[V1:%.*]], align 2
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_f16mf4_tumu(vfloat16mf4_t *v0, vfloat16mf4_t *v1, vbool64_t mask, vfloat16mf4_t maskedoff0, vfloat16mf4_t maskedoff1, const _Float16 *base, vuint8mf8_t bindex, size_t vl) {
return vluxseg2ei8_tumu(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_f16mf2_tumu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 2 x half>, <vscale x 2 x half> } @llvm.riscv.vluxseg2.mask.nxv2f16.nxv2i8.i64(<vscale x 2 x half> [[MASKEDOFF0:%.*]], <vscale x 2 x half> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 2 x i8> [[BINDEX:%.*]], <vscale x 2 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 0)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 2 x half>, <vscale x 2 x half> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 2 x half> [[TMP1]], ptr [[V0:%.*]], align 2
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 2 x half>, <vscale x 2 x half> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 2 x half> [[TMP2]], ptr [[V1:%.*]], align 2
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_f16mf2_tumu(vfloat16mf2_t *v0, vfloat16mf2_t *v1, vbool32_t mask, vfloat16mf2_t maskedoff0, vfloat16mf2_t maskedoff1, const _Float16 *base, vuint8mf4_t bindex, size_t vl) {
return vluxseg2ei8_tumu(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_f16m1_tumu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 4 x half>, <vscale x 4 x half> } @llvm.riscv.vluxseg2.mask.nxv4f16.nxv4i8.i64(<vscale x 4 x half> [[MASKEDOFF0:%.*]], <vscale x 4 x half> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 4 x i8> [[BINDEX:%.*]], <vscale x 4 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 0)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 4 x half>, <vscale x 4 x half> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 4 x half> [[TMP1]], ptr [[V0:%.*]], align 2
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 4 x half>, <vscale x 4 x half> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 4 x half> [[TMP2]], ptr [[V1:%.*]], align 2
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_f16m1_tumu(vfloat16m1_t *v0, vfloat16m1_t *v1, vbool16_t mask, vfloat16m1_t maskedoff0, vfloat16m1_t maskedoff1, const _Float16 *base, vuint8mf2_t bindex, size_t vl) {
return vluxseg2ei8_tumu(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_f16m2_tumu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 8 x half>, <vscale x 8 x half> } @llvm.riscv.vluxseg2.mask.nxv8f16.nxv8i8.i64(<vscale x 8 x half> [[MASKEDOFF0:%.*]], <vscale x 8 x half> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 8 x i8> [[BINDEX:%.*]], <vscale x 8 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 0)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 8 x half>, <vscale x 8 x half> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 8 x half> [[TMP1]], ptr [[V0:%.*]], align 2
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 8 x half>, <vscale x 8 x half> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 8 x half> [[TMP2]], ptr [[V1:%.*]], align 2
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_f16m2_tumu(vfloat16m2_t *v0, vfloat16m2_t *v1, vbool8_t mask, vfloat16m2_t maskedoff0, vfloat16m2_t maskedoff1, const _Float16 *base, vuint8m1_t bindex, size_t vl) {
return vluxseg2ei8_tumu(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_f16m4_tumu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 16 x half>, <vscale x 16 x half> } @llvm.riscv.vluxseg2.mask.nxv16f16.nxv16i8.i64(<vscale x 16 x half> [[MASKEDOFF0:%.*]], <vscale x 16 x half> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 16 x i8> [[BINDEX:%.*]], <vscale x 16 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 0)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 16 x half>, <vscale x 16 x half> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 16 x half> [[TMP1]], ptr [[V0:%.*]], align 2
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 16 x half>, <vscale x 16 x half> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 16 x half> [[TMP2]], ptr [[V1:%.*]], align 2
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_f16m4_tumu(vfloat16m4_t *v0, vfloat16m4_t *v1, vbool4_t mask, vfloat16m4_t maskedoff0, vfloat16m4_t maskedoff1, const _Float16 *base, vuint8m2_t bindex, size_t vl) {
return vluxseg2ei8_tumu(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_f32mf2_tumu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 1 x float>, <vscale x 1 x float> } @llvm.riscv.vluxseg2.mask.nxv1f32.nxv1i8.i64(<vscale x 1 x float> [[MASKEDOFF0:%.*]], <vscale x 1 x float> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 1 x i8> [[BINDEX:%.*]], <vscale x 1 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 0)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 1 x float>, <vscale x 1 x float> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 1 x float> [[TMP1]], ptr [[V0:%.*]], align 4
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 1 x float>, <vscale x 1 x float> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 1 x float> [[TMP2]], ptr [[V1:%.*]], align 4
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_f32mf2_tumu(vfloat32mf2_t *v0, vfloat32mf2_t *v1, vbool64_t mask, vfloat32mf2_t maskedoff0, vfloat32mf2_t maskedoff1, const float *base, vuint8mf8_t bindex, size_t vl) {
return vluxseg2ei8_tumu(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_f32m1_tumu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 2 x float>, <vscale x 2 x float> } @llvm.riscv.vluxseg2.mask.nxv2f32.nxv2i8.i64(<vscale x 2 x float> [[MASKEDOFF0:%.*]], <vscale x 2 x float> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 2 x i8> [[BINDEX:%.*]], <vscale x 2 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 0)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 2 x float>, <vscale x 2 x float> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 2 x float> [[TMP1]], ptr [[V0:%.*]], align 4
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 2 x float>, <vscale x 2 x float> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 2 x float> [[TMP2]], ptr [[V1:%.*]], align 4
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_f32m1_tumu(vfloat32m1_t *v0, vfloat32m1_t *v1, vbool32_t mask, vfloat32m1_t maskedoff0, vfloat32m1_t maskedoff1, const float *base, vuint8mf4_t bindex, size_t vl) {
return vluxseg2ei8_tumu(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_f32m2_tumu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 4 x float>, <vscale x 4 x float> } @llvm.riscv.vluxseg2.mask.nxv4f32.nxv4i8.i64(<vscale x 4 x float> [[MASKEDOFF0:%.*]], <vscale x 4 x float> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 4 x i8> [[BINDEX:%.*]], <vscale x 4 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 0)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 4 x float>, <vscale x 4 x float> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 4 x float> [[TMP1]], ptr [[V0:%.*]], align 4
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 4 x float>, <vscale x 4 x float> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 4 x float> [[TMP2]], ptr [[V1:%.*]], align 4
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_f32m2_tumu(vfloat32m2_t *v0, vfloat32m2_t *v1, vbool16_t mask, vfloat32m2_t maskedoff0, vfloat32m2_t maskedoff1, const float *base, vuint8mf2_t bindex, size_t vl) {
return vluxseg2ei8_tumu(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_f32m4_tumu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 8 x float>, <vscale x 8 x float> } @llvm.riscv.vluxseg2.mask.nxv8f32.nxv8i8.i64(<vscale x 8 x float> [[MASKEDOFF0:%.*]], <vscale x 8 x float> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 8 x i8> [[BINDEX:%.*]], <vscale x 8 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 0)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 8 x float>, <vscale x 8 x float> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 8 x float> [[TMP1]], ptr [[V0:%.*]], align 4
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 8 x float>, <vscale x 8 x float> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 8 x float> [[TMP2]], ptr [[V1:%.*]], align 4
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_f32m4_tumu(vfloat32m4_t *v0, vfloat32m4_t *v1, vbool8_t mask, vfloat32m4_t maskedoff0, vfloat32m4_t maskedoff1, const float *base, vuint8m1_t bindex, size_t vl) {
return vluxseg2ei8_tumu(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_f64m1_tumu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 1 x double>, <vscale x 1 x double> } @llvm.riscv.vluxseg2.mask.nxv1f64.nxv1i8.i64(<vscale x 1 x double> [[MASKEDOFF0:%.*]], <vscale x 1 x double> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 1 x i8> [[BINDEX:%.*]], <vscale x 1 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 0)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 1 x double>, <vscale x 1 x double> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 1 x double> [[TMP1]], ptr [[V0:%.*]], align 8
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 1 x double>, <vscale x 1 x double> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 1 x double> [[TMP2]], ptr [[V1:%.*]], align 8
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_f64m1_tumu(vfloat64m1_t *v0, vfloat64m1_t *v1, vbool64_t mask, vfloat64m1_t maskedoff0, vfloat64m1_t maskedoff1, const double *base, vuint8mf8_t bindex, size_t vl) {
return vluxseg2ei8_tumu(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_f64m2_tumu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 2 x double>, <vscale x 2 x double> } @llvm.riscv.vluxseg2.mask.nxv2f64.nxv2i8.i64(<vscale x 2 x double> [[MASKEDOFF0:%.*]], <vscale x 2 x double> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 2 x i8> [[BINDEX:%.*]], <vscale x 2 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 0)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 2 x double>, <vscale x 2 x double> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 2 x double> [[TMP1]], ptr [[V0:%.*]], align 8
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 2 x double>, <vscale x 2 x double> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 2 x double> [[TMP2]], ptr [[V1:%.*]], align 8
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_f64m2_tumu(vfloat64m2_t *v0, vfloat64m2_t *v1, vbool32_t mask, vfloat64m2_t maskedoff0, vfloat64m2_t maskedoff1, const double *base, vuint8mf4_t bindex, size_t vl) {
return vluxseg2ei8_tumu(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_f64m4_tumu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 4 x double>, <vscale x 4 x double> } @llvm.riscv.vluxseg2.mask.nxv4f64.nxv4i8.i64(<vscale x 4 x double> [[MASKEDOFF0:%.*]], <vscale x 4 x double> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 4 x i8> [[BINDEX:%.*]], <vscale x 4 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 0)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 4 x double>, <vscale x 4 x double> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 4 x double> [[TMP1]], ptr [[V0:%.*]], align 8
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 4 x double>, <vscale x 4 x double> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 4 x double> [[TMP2]], ptr [[V1:%.*]], align 8
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_f64m4_tumu(vfloat64m4_t *v0, vfloat64m4_t *v1, vbool16_t mask, vfloat64m4_t maskedoff0, vfloat64m4_t maskedoff1, const double *base, vuint8mf2_t bindex, size_t vl) {
return vluxseg2ei8_tumu(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i8mf8_tumu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 1 x i8>, <vscale x 1 x i8> } @llvm.riscv.vluxseg2.mask.nxv1i8.nxv1i8.i64(<vscale x 1 x i8> [[MASKEDOFF0:%.*]], <vscale x 1 x i8> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 1 x i8> [[BINDEX:%.*]], <vscale x 1 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 0)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 1 x i8>, <vscale x 1 x i8> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 1 x i8> [[TMP1]], ptr [[V0:%.*]], align 1
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 1 x i8>, <vscale x 1 x i8> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 1 x i8> [[TMP2]], ptr [[V1:%.*]], align 1
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i8mf8_tumu(vint8mf8_t *v0, vint8mf8_t *v1, vbool64_t mask, vint8mf8_t maskedoff0, vint8mf8_t maskedoff1, const int8_t *base, vuint8mf8_t bindex, size_t vl) {
return vluxseg2ei8_tumu(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i8mf4_tumu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 2 x i8>, <vscale x 2 x i8> } @llvm.riscv.vluxseg2.mask.nxv2i8.nxv2i8.i64(<vscale x 2 x i8> [[MASKEDOFF0:%.*]], <vscale x 2 x i8> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 2 x i8> [[BINDEX:%.*]], <vscale x 2 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 0)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 2 x i8>, <vscale x 2 x i8> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 2 x i8> [[TMP1]], ptr [[V0:%.*]], align 1
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 2 x i8>, <vscale x 2 x i8> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 2 x i8> [[TMP2]], ptr [[V1:%.*]], align 1
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i8mf4_tumu(vint8mf4_t *v0, vint8mf4_t *v1, vbool32_t mask, vint8mf4_t maskedoff0, vint8mf4_t maskedoff1, const int8_t *base, vuint8mf4_t bindex, size_t vl) {
return vluxseg2ei8_tumu(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i8mf2_tumu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 4 x i8>, <vscale x 4 x i8> } @llvm.riscv.vluxseg2.mask.nxv4i8.nxv4i8.i64(<vscale x 4 x i8> [[MASKEDOFF0:%.*]], <vscale x 4 x i8> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 4 x i8> [[BINDEX:%.*]], <vscale x 4 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 0)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 4 x i8>, <vscale x 4 x i8> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 4 x i8> [[TMP1]], ptr [[V0:%.*]], align 1
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 4 x i8>, <vscale x 4 x i8> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 4 x i8> [[TMP2]], ptr [[V1:%.*]], align 1
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i8mf2_tumu(vint8mf2_t *v0, vint8mf2_t *v1, vbool16_t mask, vint8mf2_t maskedoff0, vint8mf2_t maskedoff1, const int8_t *base, vuint8mf2_t bindex, size_t vl) {
return vluxseg2ei8_tumu(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i8m1_tumu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 8 x i8>, <vscale x 8 x i8> } @llvm.riscv.vluxseg2.mask.nxv8i8.nxv8i8.i64(<vscale x 8 x i8> [[MASKEDOFF0:%.*]], <vscale x 8 x i8> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 8 x i8> [[BINDEX:%.*]], <vscale x 8 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 0)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 8 x i8>, <vscale x 8 x i8> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 8 x i8> [[TMP1]], ptr [[V0:%.*]], align 1
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 8 x i8>, <vscale x 8 x i8> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 8 x i8> [[TMP2]], ptr [[V1:%.*]], align 1
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i8m1_tumu(vint8m1_t *v0, vint8m1_t *v1, vbool8_t mask, vint8m1_t maskedoff0, vint8m1_t maskedoff1, const int8_t *base, vuint8m1_t bindex, size_t vl) {
return vluxseg2ei8_tumu(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i8m2_tumu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 16 x i8>, <vscale x 16 x i8> } @llvm.riscv.vluxseg2.mask.nxv16i8.nxv16i8.i64(<vscale x 16 x i8> [[MASKEDOFF0:%.*]], <vscale x 16 x i8> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 16 x i8> [[BINDEX:%.*]], <vscale x 16 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 0)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 16 x i8>, <vscale x 16 x i8> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 16 x i8> [[TMP1]], ptr [[V0:%.*]], align 1
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 16 x i8>, <vscale x 16 x i8> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 16 x i8> [[TMP2]], ptr [[V1:%.*]], align 1
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i8m2_tumu(vint8m2_t *v0, vint8m2_t *v1, vbool4_t mask, vint8m2_t maskedoff0, vint8m2_t maskedoff1, const int8_t *base, vuint8m2_t bindex, size_t vl) {
return vluxseg2ei8_tumu(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i8m4_tumu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 32 x i8>, <vscale x 32 x i8> } @llvm.riscv.vluxseg2.mask.nxv32i8.nxv32i8.i64(<vscale x 32 x i8> [[MASKEDOFF0:%.*]], <vscale x 32 x i8> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 32 x i8> [[BINDEX:%.*]], <vscale x 32 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 0)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 32 x i8>, <vscale x 32 x i8> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 32 x i8> [[TMP1]], ptr [[V0:%.*]], align 1
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 32 x i8>, <vscale x 32 x i8> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 32 x i8> [[TMP2]], ptr [[V1:%.*]], align 1
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i8m4_tumu(vint8m4_t *v0, vint8m4_t *v1, vbool2_t mask, vint8m4_t maskedoff0, vint8m4_t maskedoff1, const int8_t *base, vuint8m4_t bindex, size_t vl) {
return vluxseg2ei8_tumu(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i16mf4_tumu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 1 x i16>, <vscale x 1 x i16> } @llvm.riscv.vluxseg2.mask.nxv1i16.nxv1i8.i64(<vscale x 1 x i16> [[MASKEDOFF0:%.*]], <vscale x 1 x i16> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 1 x i8> [[BINDEX:%.*]], <vscale x 1 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 0)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 1 x i16>, <vscale x 1 x i16> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 1 x i16> [[TMP1]], ptr [[V0:%.*]], align 2
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 1 x i16>, <vscale x 1 x i16> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 1 x i16> [[TMP2]], ptr [[V1:%.*]], align 2
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i16mf4_tumu(vint16mf4_t *v0, vint16mf4_t *v1, vbool64_t mask, vint16mf4_t maskedoff0, vint16mf4_t maskedoff1, const int16_t *base, vuint8mf8_t bindex, size_t vl) {
return vluxseg2ei8_tumu(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i16mf2_tumu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 2 x i16>, <vscale x 2 x i16> } @llvm.riscv.vluxseg2.mask.nxv2i16.nxv2i8.i64(<vscale x 2 x i16> [[MASKEDOFF0:%.*]], <vscale x 2 x i16> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 2 x i8> [[BINDEX:%.*]], <vscale x 2 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 0)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 2 x i16>, <vscale x 2 x i16> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 2 x i16> [[TMP1]], ptr [[V0:%.*]], align 2
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 2 x i16>, <vscale x 2 x i16> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 2 x i16> [[TMP2]], ptr [[V1:%.*]], align 2
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i16mf2_tumu(vint16mf2_t *v0, vint16mf2_t *v1, vbool32_t mask, vint16mf2_t maskedoff0, vint16mf2_t maskedoff1, const int16_t *base, vuint8mf4_t bindex, size_t vl) {
return vluxseg2ei8_tumu(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i16m1_tumu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 4 x i16>, <vscale x 4 x i16> } @llvm.riscv.vluxseg2.mask.nxv4i16.nxv4i8.i64(<vscale x 4 x i16> [[MASKEDOFF0:%.*]], <vscale x 4 x i16> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 4 x i8> [[BINDEX:%.*]], <vscale x 4 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 0)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 4 x i16>, <vscale x 4 x i16> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 4 x i16> [[TMP1]], ptr [[V0:%.*]], align 2
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 4 x i16>, <vscale x 4 x i16> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 4 x i16> [[TMP2]], ptr [[V1:%.*]], align 2
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i16m1_tumu(vint16m1_t *v0, vint16m1_t *v1, vbool16_t mask, vint16m1_t maskedoff0, vint16m1_t maskedoff1, const int16_t *base, vuint8mf2_t bindex, size_t vl) {
return vluxseg2ei8_tumu(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i16m2_tumu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 8 x i16>, <vscale x 8 x i16> } @llvm.riscv.vluxseg2.mask.nxv8i16.nxv8i8.i64(<vscale x 8 x i16> [[MASKEDOFF0:%.*]], <vscale x 8 x i16> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 8 x i8> [[BINDEX:%.*]], <vscale x 8 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 0)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 8 x i16>, <vscale x 8 x i16> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 8 x i16> [[TMP1]], ptr [[V0:%.*]], align 2
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 8 x i16>, <vscale x 8 x i16> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 8 x i16> [[TMP2]], ptr [[V1:%.*]], align 2
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i16m2_tumu(vint16m2_t *v0, vint16m2_t *v1, vbool8_t mask, vint16m2_t maskedoff0, vint16m2_t maskedoff1, const int16_t *base, vuint8m1_t bindex, size_t vl) {
return vluxseg2ei8_tumu(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i16m4_tumu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 16 x i16>, <vscale x 16 x i16> } @llvm.riscv.vluxseg2.mask.nxv16i16.nxv16i8.i64(<vscale x 16 x i16> [[MASKEDOFF0:%.*]], <vscale x 16 x i16> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 16 x i8> [[BINDEX:%.*]], <vscale x 16 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 0)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 16 x i16>, <vscale x 16 x i16> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 16 x i16> [[TMP1]], ptr [[V0:%.*]], align 2
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 16 x i16>, <vscale x 16 x i16> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 16 x i16> [[TMP2]], ptr [[V1:%.*]], align 2
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i16m4_tumu(vint16m4_t *v0, vint16m4_t *v1, vbool4_t mask, vint16m4_t maskedoff0, vint16m4_t maskedoff1, const int16_t *base, vuint8m2_t bindex, size_t vl) {
return vluxseg2ei8_tumu(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i32mf2_tumu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 1 x i32>, <vscale x 1 x i32> } @llvm.riscv.vluxseg2.mask.nxv1i32.nxv1i8.i64(<vscale x 1 x i32> [[MASKEDOFF0:%.*]], <vscale x 1 x i32> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 1 x i8> [[BINDEX:%.*]], <vscale x 1 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 0)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 1 x i32>, <vscale x 1 x i32> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 1 x i32> [[TMP1]], ptr [[V0:%.*]], align 4
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 1 x i32>, <vscale x 1 x i32> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 1 x i32> [[TMP2]], ptr [[V1:%.*]], align 4
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i32mf2_tumu(vint32mf2_t *v0, vint32mf2_t *v1, vbool64_t mask, vint32mf2_t maskedoff0, vint32mf2_t maskedoff1, const int32_t *base, vuint8mf8_t bindex, size_t vl) {
return vluxseg2ei8_tumu(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i32m1_tumu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 2 x i32>, <vscale x 2 x i32> } @llvm.riscv.vluxseg2.mask.nxv2i32.nxv2i8.i64(<vscale x 2 x i32> [[MASKEDOFF0:%.*]], <vscale x 2 x i32> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 2 x i8> [[BINDEX:%.*]], <vscale x 2 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 0)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 2 x i32>, <vscale x 2 x i32> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 2 x i32> [[TMP1]], ptr [[V0:%.*]], align 4
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 2 x i32>, <vscale x 2 x i32> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 2 x i32> [[TMP2]], ptr [[V1:%.*]], align 4
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i32m1_tumu(vint32m1_t *v0, vint32m1_t *v1, vbool32_t mask, vint32m1_t maskedoff0, vint32m1_t maskedoff1, const int32_t *base, vuint8mf4_t bindex, size_t vl) {
return vluxseg2ei8_tumu(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i32m2_tumu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 4 x i32>, <vscale x 4 x i32> } @llvm.riscv.vluxseg2.mask.nxv4i32.nxv4i8.i64(<vscale x 4 x i32> [[MASKEDOFF0:%.*]], <vscale x 4 x i32> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 4 x i8> [[BINDEX:%.*]], <vscale x 4 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 0)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 4 x i32>, <vscale x 4 x i32> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 4 x i32> [[TMP1]], ptr [[V0:%.*]], align 4
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 4 x i32>, <vscale x 4 x i32> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 4 x i32> [[TMP2]], ptr [[V1:%.*]], align 4
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i32m2_tumu(vint32m2_t *v0, vint32m2_t *v1, vbool16_t mask, vint32m2_t maskedoff0, vint32m2_t maskedoff1, const int32_t *base, vuint8mf2_t bindex, size_t vl) {
return vluxseg2ei8_tumu(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i32m4_tumu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 8 x i32>, <vscale x 8 x i32> } @llvm.riscv.vluxseg2.mask.nxv8i32.nxv8i8.i64(<vscale x 8 x i32> [[MASKEDOFF0:%.*]], <vscale x 8 x i32> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 8 x i8> [[BINDEX:%.*]], <vscale x 8 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 0)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 8 x i32>, <vscale x 8 x i32> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 8 x i32> [[TMP1]], ptr [[V0:%.*]], align 4
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 8 x i32>, <vscale x 8 x i32> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 8 x i32> [[TMP2]], ptr [[V1:%.*]], align 4
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i32m4_tumu(vint32m4_t *v0, vint32m4_t *v1, vbool8_t mask, vint32m4_t maskedoff0, vint32m4_t maskedoff1, const int32_t *base, vuint8m1_t bindex, size_t vl) {
return vluxseg2ei8_tumu(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i64m1_tumu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 1 x i64>, <vscale x 1 x i64> } @llvm.riscv.vluxseg2.mask.nxv1i64.nxv1i8.i64(<vscale x 1 x i64> [[MASKEDOFF0:%.*]], <vscale x 1 x i64> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 1 x i8> [[BINDEX:%.*]], <vscale x 1 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 0)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 1 x i64>, <vscale x 1 x i64> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 1 x i64> [[TMP1]], ptr [[V0:%.*]], align 8
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 1 x i64>, <vscale x 1 x i64> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 1 x i64> [[TMP2]], ptr [[V1:%.*]], align 8
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i64m1_tumu(vint64m1_t *v0, vint64m1_t *v1, vbool64_t mask, vint64m1_t maskedoff0, vint64m1_t maskedoff1, const int64_t *base, vuint8mf8_t bindex, size_t vl) {
return vluxseg2ei8_tumu(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i64m2_tumu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 2 x i64>, <vscale x 2 x i64> } @llvm.riscv.vluxseg2.mask.nxv2i64.nxv2i8.i64(<vscale x 2 x i64> [[MASKEDOFF0:%.*]], <vscale x 2 x i64> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 2 x i8> [[BINDEX:%.*]], <vscale x 2 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 0)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 2 x i64>, <vscale x 2 x i64> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 2 x i64> [[TMP1]], ptr [[V0:%.*]], align 8
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 2 x i64>, <vscale x 2 x i64> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 2 x i64> [[TMP2]], ptr [[V1:%.*]], align 8
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i64m2_tumu(vint64m2_t *v0, vint64m2_t *v1, vbool32_t mask, vint64m2_t maskedoff0, vint64m2_t maskedoff1, const int64_t *base, vuint8mf4_t bindex, size_t vl) {
return vluxseg2ei8_tumu(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i64m4_tumu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 4 x i64>, <vscale x 4 x i64> } @llvm.riscv.vluxseg2.mask.nxv4i64.nxv4i8.i64(<vscale x 4 x i64> [[MASKEDOFF0:%.*]], <vscale x 4 x i64> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 4 x i8> [[BINDEX:%.*]], <vscale x 4 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 0)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 4 x i64>, <vscale x 4 x i64> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 4 x i64> [[TMP1]], ptr [[V0:%.*]], align 8
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 4 x i64>, <vscale x 4 x i64> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 4 x i64> [[TMP2]], ptr [[V1:%.*]], align 8
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i64m4_tumu(vint64m4_t *v0, vint64m4_t *v1, vbool16_t mask, vint64m4_t maskedoff0, vint64m4_t maskedoff1, const int64_t *base, vuint8mf2_t bindex, size_t vl) {
return vluxseg2ei8_tumu(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u8mf8_tumu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 1 x i8>, <vscale x 1 x i8> } @llvm.riscv.vluxseg2.mask.nxv1i8.nxv1i8.i64(<vscale x 1 x i8> [[MASKEDOFF0:%.*]], <vscale x 1 x i8> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 1 x i8> [[BINDEX:%.*]], <vscale x 1 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 0)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 1 x i8>, <vscale x 1 x i8> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 1 x i8> [[TMP1]], ptr [[V0:%.*]], align 1
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 1 x i8>, <vscale x 1 x i8> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 1 x i8> [[TMP2]], ptr [[V1:%.*]], align 1
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u8mf8_tumu(vuint8mf8_t *v0, vuint8mf8_t *v1, vbool64_t mask, vuint8mf8_t maskedoff0, vuint8mf8_t maskedoff1, const uint8_t *base, vuint8mf8_t bindex, size_t vl) {
return vluxseg2ei8_tumu(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u8mf4_tumu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 2 x i8>, <vscale x 2 x i8> } @llvm.riscv.vluxseg2.mask.nxv2i8.nxv2i8.i64(<vscale x 2 x i8> [[MASKEDOFF0:%.*]], <vscale x 2 x i8> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 2 x i8> [[BINDEX:%.*]], <vscale x 2 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 0)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 2 x i8>, <vscale x 2 x i8> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 2 x i8> [[TMP1]], ptr [[V0:%.*]], align 1
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 2 x i8>, <vscale x 2 x i8> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 2 x i8> [[TMP2]], ptr [[V1:%.*]], align 1
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u8mf4_tumu(vuint8mf4_t *v0, vuint8mf4_t *v1, vbool32_t mask, vuint8mf4_t maskedoff0, vuint8mf4_t maskedoff1, const uint8_t *base, vuint8mf4_t bindex, size_t vl) {
return vluxseg2ei8_tumu(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u8mf2_tumu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 4 x i8>, <vscale x 4 x i8> } @llvm.riscv.vluxseg2.mask.nxv4i8.nxv4i8.i64(<vscale x 4 x i8> [[MASKEDOFF0:%.*]], <vscale x 4 x i8> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 4 x i8> [[BINDEX:%.*]], <vscale x 4 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 0)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 4 x i8>, <vscale x 4 x i8> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 4 x i8> [[TMP1]], ptr [[V0:%.*]], align 1
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 4 x i8>, <vscale x 4 x i8> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 4 x i8> [[TMP2]], ptr [[V1:%.*]], align 1
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u8mf2_tumu(vuint8mf2_t *v0, vuint8mf2_t *v1, vbool16_t mask, vuint8mf2_t maskedoff0, vuint8mf2_t maskedoff1, const uint8_t *base, vuint8mf2_t bindex, size_t vl) {
return vluxseg2ei8_tumu(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u8m1_tumu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 8 x i8>, <vscale x 8 x i8> } @llvm.riscv.vluxseg2.mask.nxv8i8.nxv8i8.i64(<vscale x 8 x i8> [[MASKEDOFF0:%.*]], <vscale x 8 x i8> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 8 x i8> [[BINDEX:%.*]], <vscale x 8 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 0)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 8 x i8>, <vscale x 8 x i8> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 8 x i8> [[TMP1]], ptr [[V0:%.*]], align 1
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 8 x i8>, <vscale x 8 x i8> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 8 x i8> [[TMP2]], ptr [[V1:%.*]], align 1
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u8m1_tumu(vuint8m1_t *v0, vuint8m1_t *v1, vbool8_t mask, vuint8m1_t maskedoff0, vuint8m1_t maskedoff1, const uint8_t *base, vuint8m1_t bindex, size_t vl) {
return vluxseg2ei8_tumu(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u8m2_tumu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 16 x i8>, <vscale x 16 x i8> } @llvm.riscv.vluxseg2.mask.nxv16i8.nxv16i8.i64(<vscale x 16 x i8> [[MASKEDOFF0:%.*]], <vscale x 16 x i8> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 16 x i8> [[BINDEX:%.*]], <vscale x 16 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 0)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 16 x i8>, <vscale x 16 x i8> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 16 x i8> [[TMP1]], ptr [[V0:%.*]], align 1
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 16 x i8>, <vscale x 16 x i8> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 16 x i8> [[TMP2]], ptr [[V1:%.*]], align 1
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u8m2_tumu(vuint8m2_t *v0, vuint8m2_t *v1, vbool4_t mask, vuint8m2_t maskedoff0, vuint8m2_t maskedoff1, const uint8_t *base, vuint8m2_t bindex, size_t vl) {
return vluxseg2ei8_tumu(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u8m4_tumu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 32 x i8>, <vscale x 32 x i8> } @llvm.riscv.vluxseg2.mask.nxv32i8.nxv32i8.i64(<vscale x 32 x i8> [[MASKEDOFF0:%.*]], <vscale x 32 x i8> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 32 x i8> [[BINDEX:%.*]], <vscale x 32 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 0)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 32 x i8>, <vscale x 32 x i8> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 32 x i8> [[TMP1]], ptr [[V0:%.*]], align 1
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 32 x i8>, <vscale x 32 x i8> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 32 x i8> [[TMP2]], ptr [[V1:%.*]], align 1
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u8m4_tumu(vuint8m4_t *v0, vuint8m4_t *v1, vbool2_t mask, vuint8m4_t maskedoff0, vuint8m4_t maskedoff1, const uint8_t *base, vuint8m4_t bindex, size_t vl) {
return vluxseg2ei8_tumu(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u16mf4_tumu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 1 x i16>, <vscale x 1 x i16> } @llvm.riscv.vluxseg2.mask.nxv1i16.nxv1i8.i64(<vscale x 1 x i16> [[MASKEDOFF0:%.*]], <vscale x 1 x i16> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 1 x i8> [[BINDEX:%.*]], <vscale x 1 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 0)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 1 x i16>, <vscale x 1 x i16> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 1 x i16> [[TMP1]], ptr [[V0:%.*]], align 2
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 1 x i16>, <vscale x 1 x i16> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 1 x i16> [[TMP2]], ptr [[V1:%.*]], align 2
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u16mf4_tumu(vuint16mf4_t *v0, vuint16mf4_t *v1, vbool64_t mask, vuint16mf4_t maskedoff0, vuint16mf4_t maskedoff1, const uint16_t *base, vuint8mf8_t bindex, size_t vl) {
return vluxseg2ei8_tumu(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u16mf2_tumu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 2 x i16>, <vscale x 2 x i16> } @llvm.riscv.vluxseg2.mask.nxv2i16.nxv2i8.i64(<vscale x 2 x i16> [[MASKEDOFF0:%.*]], <vscale x 2 x i16> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 2 x i8> [[BINDEX:%.*]], <vscale x 2 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 0)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 2 x i16>, <vscale x 2 x i16> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 2 x i16> [[TMP1]], ptr [[V0:%.*]], align 2
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 2 x i16>, <vscale x 2 x i16> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 2 x i16> [[TMP2]], ptr [[V1:%.*]], align 2
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u16mf2_tumu(vuint16mf2_t *v0, vuint16mf2_t *v1, vbool32_t mask, vuint16mf2_t maskedoff0, vuint16mf2_t maskedoff1, const uint16_t *base, vuint8mf4_t bindex, size_t vl) {
return vluxseg2ei8_tumu(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u16m1_tumu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 4 x i16>, <vscale x 4 x i16> } @llvm.riscv.vluxseg2.mask.nxv4i16.nxv4i8.i64(<vscale x 4 x i16> [[MASKEDOFF0:%.*]], <vscale x 4 x i16> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 4 x i8> [[BINDEX:%.*]], <vscale x 4 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 0)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 4 x i16>, <vscale x 4 x i16> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 4 x i16> [[TMP1]], ptr [[V0:%.*]], align 2
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 4 x i16>, <vscale x 4 x i16> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 4 x i16> [[TMP2]], ptr [[V1:%.*]], align 2
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u16m1_tumu(vuint16m1_t *v0, vuint16m1_t *v1, vbool16_t mask, vuint16m1_t maskedoff0, vuint16m1_t maskedoff1, const uint16_t *base, vuint8mf2_t bindex, size_t vl) {
return vluxseg2ei8_tumu(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u16m2_tumu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 8 x i16>, <vscale x 8 x i16> } @llvm.riscv.vluxseg2.mask.nxv8i16.nxv8i8.i64(<vscale x 8 x i16> [[MASKEDOFF0:%.*]], <vscale x 8 x i16> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 8 x i8> [[BINDEX:%.*]], <vscale x 8 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 0)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 8 x i16>, <vscale x 8 x i16> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 8 x i16> [[TMP1]], ptr [[V0:%.*]], align 2
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 8 x i16>, <vscale x 8 x i16> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 8 x i16> [[TMP2]], ptr [[V1:%.*]], align 2
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u16m2_tumu(vuint16m2_t *v0, vuint16m2_t *v1, vbool8_t mask, vuint16m2_t maskedoff0, vuint16m2_t maskedoff1, const uint16_t *base, vuint8m1_t bindex, size_t vl) {
return vluxseg2ei8_tumu(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u16m4_tumu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 16 x i16>, <vscale x 16 x i16> } @llvm.riscv.vluxseg2.mask.nxv16i16.nxv16i8.i64(<vscale x 16 x i16> [[MASKEDOFF0:%.*]], <vscale x 16 x i16> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 16 x i8> [[BINDEX:%.*]], <vscale x 16 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 0)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 16 x i16>, <vscale x 16 x i16> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 16 x i16> [[TMP1]], ptr [[V0:%.*]], align 2
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 16 x i16>, <vscale x 16 x i16> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 16 x i16> [[TMP2]], ptr [[V1:%.*]], align 2
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u16m4_tumu(vuint16m4_t *v0, vuint16m4_t *v1, vbool4_t mask, vuint16m4_t maskedoff0, vuint16m4_t maskedoff1, const uint16_t *base, vuint8m2_t bindex, size_t vl) {
return vluxseg2ei8_tumu(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u32mf2_tumu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 1 x i32>, <vscale x 1 x i32> } @llvm.riscv.vluxseg2.mask.nxv1i32.nxv1i8.i64(<vscale x 1 x i32> [[MASKEDOFF0:%.*]], <vscale x 1 x i32> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 1 x i8> [[BINDEX:%.*]], <vscale x 1 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 0)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 1 x i32>, <vscale x 1 x i32> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 1 x i32> [[TMP1]], ptr [[V0:%.*]], align 4
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 1 x i32>, <vscale x 1 x i32> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 1 x i32> [[TMP2]], ptr [[V1:%.*]], align 4
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u32mf2_tumu(vuint32mf2_t *v0, vuint32mf2_t *v1, vbool64_t mask, vuint32mf2_t maskedoff0, vuint32mf2_t maskedoff1, const uint32_t *base, vuint8mf8_t bindex, size_t vl) {
return vluxseg2ei8_tumu(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u32m1_tumu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 2 x i32>, <vscale x 2 x i32> } @llvm.riscv.vluxseg2.mask.nxv2i32.nxv2i8.i64(<vscale x 2 x i32> [[MASKEDOFF0:%.*]], <vscale x 2 x i32> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 2 x i8> [[BINDEX:%.*]], <vscale x 2 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 0)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 2 x i32>, <vscale x 2 x i32> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 2 x i32> [[TMP1]], ptr [[V0:%.*]], align 4
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 2 x i32>, <vscale x 2 x i32> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 2 x i32> [[TMP2]], ptr [[V1:%.*]], align 4
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u32m1_tumu(vuint32m1_t *v0, vuint32m1_t *v1, vbool32_t mask, vuint32m1_t maskedoff0, vuint32m1_t maskedoff1, const uint32_t *base, vuint8mf4_t bindex, size_t vl) {
return vluxseg2ei8_tumu(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u32m2_tumu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 4 x i32>, <vscale x 4 x i32> } @llvm.riscv.vluxseg2.mask.nxv4i32.nxv4i8.i64(<vscale x 4 x i32> [[MASKEDOFF0:%.*]], <vscale x 4 x i32> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 4 x i8> [[BINDEX:%.*]], <vscale x 4 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 0)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 4 x i32>, <vscale x 4 x i32> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 4 x i32> [[TMP1]], ptr [[V0:%.*]], align 4
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 4 x i32>, <vscale x 4 x i32> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 4 x i32> [[TMP2]], ptr [[V1:%.*]], align 4
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u32m2_tumu(vuint32m2_t *v0, vuint32m2_t *v1, vbool16_t mask, vuint32m2_t maskedoff0, vuint32m2_t maskedoff1, const uint32_t *base, vuint8mf2_t bindex, size_t vl) {
return vluxseg2ei8_tumu(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u32m4_tumu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 8 x i32>, <vscale x 8 x i32> } @llvm.riscv.vluxseg2.mask.nxv8i32.nxv8i8.i64(<vscale x 8 x i32> [[MASKEDOFF0:%.*]], <vscale x 8 x i32> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 8 x i8> [[BINDEX:%.*]], <vscale x 8 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 0)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 8 x i32>, <vscale x 8 x i32> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 8 x i32> [[TMP1]], ptr [[V0:%.*]], align 4
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 8 x i32>, <vscale x 8 x i32> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 8 x i32> [[TMP2]], ptr [[V1:%.*]], align 4
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u32m4_tumu(vuint32m4_t *v0, vuint32m4_t *v1, vbool8_t mask, vuint32m4_t maskedoff0, vuint32m4_t maskedoff1, const uint32_t *base, vuint8m1_t bindex, size_t vl) {
return vluxseg2ei8_tumu(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u64m1_tumu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 1 x i64>, <vscale x 1 x i64> } @llvm.riscv.vluxseg2.mask.nxv1i64.nxv1i8.i64(<vscale x 1 x i64> [[MASKEDOFF0:%.*]], <vscale x 1 x i64> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 1 x i8> [[BINDEX:%.*]], <vscale x 1 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 0)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 1 x i64>, <vscale x 1 x i64> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 1 x i64> [[TMP1]], ptr [[V0:%.*]], align 8
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 1 x i64>, <vscale x 1 x i64> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 1 x i64> [[TMP2]], ptr [[V1:%.*]], align 8
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u64m1_tumu(vuint64m1_t *v0, vuint64m1_t *v1, vbool64_t mask, vuint64m1_t maskedoff0, vuint64m1_t maskedoff1, const uint64_t *base, vuint8mf8_t bindex, size_t vl) {
return vluxseg2ei8_tumu(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u64m2_tumu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 2 x i64>, <vscale x 2 x i64> } @llvm.riscv.vluxseg2.mask.nxv2i64.nxv2i8.i64(<vscale x 2 x i64> [[MASKEDOFF0:%.*]], <vscale x 2 x i64> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 2 x i8> [[BINDEX:%.*]], <vscale x 2 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 0)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 2 x i64>, <vscale x 2 x i64> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 2 x i64> [[TMP1]], ptr [[V0:%.*]], align 8
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 2 x i64>, <vscale x 2 x i64> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 2 x i64> [[TMP2]], ptr [[V1:%.*]], align 8
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u64m2_tumu(vuint64m2_t *v0, vuint64m2_t *v1, vbool32_t mask, vuint64m2_t maskedoff0, vuint64m2_t maskedoff1, const uint64_t *base, vuint8mf4_t bindex, size_t vl) {
return vluxseg2ei8_tumu(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u64m4_tumu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 4 x i64>, <vscale x 4 x i64> } @llvm.riscv.vluxseg2.mask.nxv4i64.nxv4i8.i64(<vscale x 4 x i64> [[MASKEDOFF0:%.*]], <vscale x 4 x i64> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 4 x i8> [[BINDEX:%.*]], <vscale x 4 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 0)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 4 x i64>, <vscale x 4 x i64> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 4 x i64> [[TMP1]], ptr [[V0:%.*]], align 8
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 4 x i64>, <vscale x 4 x i64> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 4 x i64> [[TMP2]], ptr [[V1:%.*]], align 8
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u64m4_tumu(vuint64m4_t *v0, vuint64m4_t *v1, vbool16_t mask, vuint64m4_t maskedoff0, vuint64m4_t maskedoff1, const uint64_t *base, vuint8mf2_t bindex, size_t vl) {
return vluxseg2ei8_tumu(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_f16mf4_tama(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 1 x half>, <vscale x 1 x half> } @llvm.riscv.vluxseg2.mask.nxv1f16.nxv1i8.i64(<vscale x 1 x half> poison, <vscale x 1 x half> poison, ptr [[BASE:%.*]], <vscale x 1 x i8> [[BINDEX:%.*]], <vscale x 1 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 3)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 1 x half>, <vscale x 1 x half> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 1 x half> [[TMP1]], ptr [[V0:%.*]], align 2
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 1 x half>, <vscale x 1 x half> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 1 x half> [[TMP2]], ptr [[V1:%.*]], align 2
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_f16mf4_tama(vfloat16mf4_t *v0, vfloat16mf4_t *v1, vbool64_t mask, const _Float16 *base, vuint8mf8_t bindex, size_t vl) {
return vluxseg2ei8_tama(v0, v1, mask, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_f16mf2_tama(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 2 x half>, <vscale x 2 x half> } @llvm.riscv.vluxseg2.mask.nxv2f16.nxv2i8.i64(<vscale x 2 x half> poison, <vscale x 2 x half> poison, ptr [[BASE:%.*]], <vscale x 2 x i8> [[BINDEX:%.*]], <vscale x 2 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 3)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 2 x half>, <vscale x 2 x half> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 2 x half> [[TMP1]], ptr [[V0:%.*]], align 2
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 2 x half>, <vscale x 2 x half> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 2 x half> [[TMP2]], ptr [[V1:%.*]], align 2
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_f16mf2_tama(vfloat16mf2_t *v0, vfloat16mf2_t *v1, vbool32_t mask, const _Float16 *base, vuint8mf4_t bindex, size_t vl) {
return vluxseg2ei8_tama(v0, v1, mask, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_f16m1_tama(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 4 x half>, <vscale x 4 x half> } @llvm.riscv.vluxseg2.mask.nxv4f16.nxv4i8.i64(<vscale x 4 x half> poison, <vscale x 4 x half> poison, ptr [[BASE:%.*]], <vscale x 4 x i8> [[BINDEX:%.*]], <vscale x 4 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 3)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 4 x half>, <vscale x 4 x half> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 4 x half> [[TMP1]], ptr [[V0:%.*]], align 2
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 4 x half>, <vscale x 4 x half> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 4 x half> [[TMP2]], ptr [[V1:%.*]], align 2
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_f16m1_tama(vfloat16m1_t *v0, vfloat16m1_t *v1, vbool16_t mask, const _Float16 *base, vuint8mf2_t bindex, size_t vl) {
return vluxseg2ei8_tama(v0, v1, mask, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_f16m2_tama(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 8 x half>, <vscale x 8 x half> } @llvm.riscv.vluxseg2.mask.nxv8f16.nxv8i8.i64(<vscale x 8 x half> poison, <vscale x 8 x half> poison, ptr [[BASE:%.*]], <vscale x 8 x i8> [[BINDEX:%.*]], <vscale x 8 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 3)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 8 x half>, <vscale x 8 x half> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 8 x half> [[TMP1]], ptr [[V0:%.*]], align 2
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 8 x half>, <vscale x 8 x half> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 8 x half> [[TMP2]], ptr [[V1:%.*]], align 2
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_f16m2_tama(vfloat16m2_t *v0, vfloat16m2_t *v1, vbool8_t mask, const _Float16 *base, vuint8m1_t bindex, size_t vl) {
return vluxseg2ei8_tama(v0, v1, mask, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_f16m4_tama(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 16 x half>, <vscale x 16 x half> } @llvm.riscv.vluxseg2.mask.nxv16f16.nxv16i8.i64(<vscale x 16 x half> poison, <vscale x 16 x half> poison, ptr [[BASE:%.*]], <vscale x 16 x i8> [[BINDEX:%.*]], <vscale x 16 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 3)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 16 x half>, <vscale x 16 x half> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 16 x half> [[TMP1]], ptr [[V0:%.*]], align 2
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 16 x half>, <vscale x 16 x half> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 16 x half> [[TMP2]], ptr [[V1:%.*]], align 2
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_f16m4_tama(vfloat16m4_t *v0, vfloat16m4_t *v1, vbool4_t mask, const _Float16 *base, vuint8m2_t bindex, size_t vl) {
return vluxseg2ei8_tama(v0, v1, mask, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_f32mf2_tama(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 1 x float>, <vscale x 1 x float> } @llvm.riscv.vluxseg2.mask.nxv1f32.nxv1i8.i64(<vscale x 1 x float> poison, <vscale x 1 x float> poison, ptr [[BASE:%.*]], <vscale x 1 x i8> [[BINDEX:%.*]], <vscale x 1 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 3)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 1 x float>, <vscale x 1 x float> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 1 x float> [[TMP1]], ptr [[V0:%.*]], align 4
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 1 x float>, <vscale x 1 x float> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 1 x float> [[TMP2]], ptr [[V1:%.*]], align 4
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_f32mf2_tama(vfloat32mf2_t *v0, vfloat32mf2_t *v1, vbool64_t mask, const float *base, vuint8mf8_t bindex, size_t vl) {
return vluxseg2ei8_tama(v0, v1, mask, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_f32m1_tama(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 2 x float>, <vscale x 2 x float> } @llvm.riscv.vluxseg2.mask.nxv2f32.nxv2i8.i64(<vscale x 2 x float> poison, <vscale x 2 x float> poison, ptr [[BASE:%.*]], <vscale x 2 x i8> [[BINDEX:%.*]], <vscale x 2 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 3)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 2 x float>, <vscale x 2 x float> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 2 x float> [[TMP1]], ptr [[V0:%.*]], align 4
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 2 x float>, <vscale x 2 x float> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 2 x float> [[TMP2]], ptr [[V1:%.*]], align 4
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_f32m1_tama(vfloat32m1_t *v0, vfloat32m1_t *v1, vbool32_t mask, const float *base, vuint8mf4_t bindex, size_t vl) {
return vluxseg2ei8_tama(v0, v1, mask, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_f32m2_tama(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 4 x float>, <vscale x 4 x float> } @llvm.riscv.vluxseg2.mask.nxv4f32.nxv4i8.i64(<vscale x 4 x float> poison, <vscale x 4 x float> poison, ptr [[BASE:%.*]], <vscale x 4 x i8> [[BINDEX:%.*]], <vscale x 4 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 3)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 4 x float>, <vscale x 4 x float> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 4 x float> [[TMP1]], ptr [[V0:%.*]], align 4
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 4 x float>, <vscale x 4 x float> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 4 x float> [[TMP2]], ptr [[V1:%.*]], align 4
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_f32m2_tama(vfloat32m2_t *v0, vfloat32m2_t *v1, vbool16_t mask, const float *base, vuint8mf2_t bindex, size_t vl) {
return vluxseg2ei8_tama(v0, v1, mask, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_f32m4_tama(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 8 x float>, <vscale x 8 x float> } @llvm.riscv.vluxseg2.mask.nxv8f32.nxv8i8.i64(<vscale x 8 x float> poison, <vscale x 8 x float> poison, ptr [[BASE:%.*]], <vscale x 8 x i8> [[BINDEX:%.*]], <vscale x 8 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 3)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 8 x float>, <vscale x 8 x float> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 8 x float> [[TMP1]], ptr [[V0:%.*]], align 4
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 8 x float>, <vscale x 8 x float> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 8 x float> [[TMP2]], ptr [[V1:%.*]], align 4
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_f32m4_tama(vfloat32m4_t *v0, vfloat32m4_t *v1, vbool8_t mask, const float *base, vuint8m1_t bindex, size_t vl) {
return vluxseg2ei8_tama(v0, v1, mask, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_f64m1_tama(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 1 x double>, <vscale x 1 x double> } @llvm.riscv.vluxseg2.mask.nxv1f64.nxv1i8.i64(<vscale x 1 x double> poison, <vscale x 1 x double> poison, ptr [[BASE:%.*]], <vscale x 1 x i8> [[BINDEX:%.*]], <vscale x 1 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 3)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 1 x double>, <vscale x 1 x double> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 1 x double> [[TMP1]], ptr [[V0:%.*]], align 8
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 1 x double>, <vscale x 1 x double> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 1 x double> [[TMP2]], ptr [[V1:%.*]], align 8
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_f64m1_tama(vfloat64m1_t *v0, vfloat64m1_t *v1, vbool64_t mask, const double *base, vuint8mf8_t bindex, size_t vl) {
return vluxseg2ei8_tama(v0, v1, mask, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_f64m2_tama(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 2 x double>, <vscale x 2 x double> } @llvm.riscv.vluxseg2.mask.nxv2f64.nxv2i8.i64(<vscale x 2 x double> poison, <vscale x 2 x double> poison, ptr [[BASE:%.*]], <vscale x 2 x i8> [[BINDEX:%.*]], <vscale x 2 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 3)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 2 x double>, <vscale x 2 x double> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 2 x double> [[TMP1]], ptr [[V0:%.*]], align 8
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 2 x double>, <vscale x 2 x double> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 2 x double> [[TMP2]], ptr [[V1:%.*]], align 8
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_f64m2_tama(vfloat64m2_t *v0, vfloat64m2_t *v1, vbool32_t mask, const double *base, vuint8mf4_t bindex, size_t vl) {
return vluxseg2ei8_tama(v0, v1, mask, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_f64m4_tama(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 4 x double>, <vscale x 4 x double> } @llvm.riscv.vluxseg2.mask.nxv4f64.nxv4i8.i64(<vscale x 4 x double> poison, <vscale x 4 x double> poison, ptr [[BASE:%.*]], <vscale x 4 x i8> [[BINDEX:%.*]], <vscale x 4 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 3)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 4 x double>, <vscale x 4 x double> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 4 x double> [[TMP1]], ptr [[V0:%.*]], align 8
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 4 x double>, <vscale x 4 x double> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 4 x double> [[TMP2]], ptr [[V1:%.*]], align 8
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_f64m4_tama(vfloat64m4_t *v0, vfloat64m4_t *v1, vbool16_t mask, const double *base, vuint8mf2_t bindex, size_t vl) {
return vluxseg2ei8_tama(v0, v1, mask, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i8mf8_tama(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 1 x i8>, <vscale x 1 x i8> } @llvm.riscv.vluxseg2.mask.nxv1i8.nxv1i8.i64(<vscale x 1 x i8> poison, <vscale x 1 x i8> poison, ptr [[BASE:%.*]], <vscale x 1 x i8> [[BINDEX:%.*]], <vscale x 1 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 3)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 1 x i8>, <vscale x 1 x i8> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 1 x i8> [[TMP1]], ptr [[V0:%.*]], align 1
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 1 x i8>, <vscale x 1 x i8> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 1 x i8> [[TMP2]], ptr [[V1:%.*]], align 1
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i8mf8_tama(vint8mf8_t *v0, vint8mf8_t *v1, vbool64_t mask, const int8_t *base, vuint8mf8_t bindex, size_t vl) {
return vluxseg2ei8_tama(v0, v1, mask, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i8mf4_tama(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 2 x i8>, <vscale x 2 x i8> } @llvm.riscv.vluxseg2.mask.nxv2i8.nxv2i8.i64(<vscale x 2 x i8> poison, <vscale x 2 x i8> poison, ptr [[BASE:%.*]], <vscale x 2 x i8> [[BINDEX:%.*]], <vscale x 2 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 3)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 2 x i8>, <vscale x 2 x i8> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 2 x i8> [[TMP1]], ptr [[V0:%.*]], align 1
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 2 x i8>, <vscale x 2 x i8> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 2 x i8> [[TMP2]], ptr [[V1:%.*]], align 1
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i8mf4_tama(vint8mf4_t *v0, vint8mf4_t *v1, vbool32_t mask, const int8_t *base, vuint8mf4_t bindex, size_t vl) {
return vluxseg2ei8_tama(v0, v1, mask, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i8mf2_tama(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 4 x i8>, <vscale x 4 x i8> } @llvm.riscv.vluxseg2.mask.nxv4i8.nxv4i8.i64(<vscale x 4 x i8> poison, <vscale x 4 x i8> poison, ptr [[BASE:%.*]], <vscale x 4 x i8> [[BINDEX:%.*]], <vscale x 4 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 3)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 4 x i8>, <vscale x 4 x i8> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 4 x i8> [[TMP1]], ptr [[V0:%.*]], align 1
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 4 x i8>, <vscale x 4 x i8> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 4 x i8> [[TMP2]], ptr [[V1:%.*]], align 1
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i8mf2_tama(vint8mf2_t *v0, vint8mf2_t *v1, vbool16_t mask, const int8_t *base, vuint8mf2_t bindex, size_t vl) {
return vluxseg2ei8_tama(v0, v1, mask, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i8m1_tama(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 8 x i8>, <vscale x 8 x i8> } @llvm.riscv.vluxseg2.mask.nxv8i8.nxv8i8.i64(<vscale x 8 x i8> poison, <vscale x 8 x i8> poison, ptr [[BASE:%.*]], <vscale x 8 x i8> [[BINDEX:%.*]], <vscale x 8 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 3)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 8 x i8>, <vscale x 8 x i8> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 8 x i8> [[TMP1]], ptr [[V0:%.*]], align 1
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 8 x i8>, <vscale x 8 x i8> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 8 x i8> [[TMP2]], ptr [[V1:%.*]], align 1
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i8m1_tama(vint8m1_t *v0, vint8m1_t *v1, vbool8_t mask, const int8_t *base, vuint8m1_t bindex, size_t vl) {
return vluxseg2ei8_tama(v0, v1, mask, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i8m2_tama(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 16 x i8>, <vscale x 16 x i8> } @llvm.riscv.vluxseg2.mask.nxv16i8.nxv16i8.i64(<vscale x 16 x i8> poison, <vscale x 16 x i8> poison, ptr [[BASE:%.*]], <vscale x 16 x i8> [[BINDEX:%.*]], <vscale x 16 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 3)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 16 x i8>, <vscale x 16 x i8> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 16 x i8> [[TMP1]], ptr [[V0:%.*]], align 1
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 16 x i8>, <vscale x 16 x i8> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 16 x i8> [[TMP2]], ptr [[V1:%.*]], align 1
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i8m2_tama(vint8m2_t *v0, vint8m2_t *v1, vbool4_t mask, const int8_t *base, vuint8m2_t bindex, size_t vl) {
return vluxseg2ei8_tama(v0, v1, mask, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i8m4_tama(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 32 x i8>, <vscale x 32 x i8> } @llvm.riscv.vluxseg2.mask.nxv32i8.nxv32i8.i64(<vscale x 32 x i8> poison, <vscale x 32 x i8> poison, ptr [[BASE:%.*]], <vscale x 32 x i8> [[BINDEX:%.*]], <vscale x 32 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 3)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 32 x i8>, <vscale x 32 x i8> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 32 x i8> [[TMP1]], ptr [[V0:%.*]], align 1
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 32 x i8>, <vscale x 32 x i8> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 32 x i8> [[TMP2]], ptr [[V1:%.*]], align 1
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i8m4_tama(vint8m4_t *v0, vint8m4_t *v1, vbool2_t mask, const int8_t *base, vuint8m4_t bindex, size_t vl) {
return vluxseg2ei8_tama(v0, v1, mask, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i16mf4_tama(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 1 x i16>, <vscale x 1 x i16> } @llvm.riscv.vluxseg2.mask.nxv1i16.nxv1i8.i64(<vscale x 1 x i16> poison, <vscale x 1 x i16> poison, ptr [[BASE:%.*]], <vscale x 1 x i8> [[BINDEX:%.*]], <vscale x 1 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 3)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 1 x i16>, <vscale x 1 x i16> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 1 x i16> [[TMP1]], ptr [[V0:%.*]], align 2
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 1 x i16>, <vscale x 1 x i16> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 1 x i16> [[TMP2]], ptr [[V1:%.*]], align 2
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i16mf4_tama(vint16mf4_t *v0, vint16mf4_t *v1, vbool64_t mask, const int16_t *base, vuint8mf8_t bindex, size_t vl) {
return vluxseg2ei8_tama(v0, v1, mask, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i16mf2_tama(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 2 x i16>, <vscale x 2 x i16> } @llvm.riscv.vluxseg2.mask.nxv2i16.nxv2i8.i64(<vscale x 2 x i16> poison, <vscale x 2 x i16> poison, ptr [[BASE:%.*]], <vscale x 2 x i8> [[BINDEX:%.*]], <vscale x 2 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 3)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 2 x i16>, <vscale x 2 x i16> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 2 x i16> [[TMP1]], ptr [[V0:%.*]], align 2
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 2 x i16>, <vscale x 2 x i16> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 2 x i16> [[TMP2]], ptr [[V1:%.*]], align 2
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i16mf2_tama(vint16mf2_t *v0, vint16mf2_t *v1, vbool32_t mask, const int16_t *base, vuint8mf4_t bindex, size_t vl) {
return vluxseg2ei8_tama(v0, v1, mask, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i16m1_tama(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 4 x i16>, <vscale x 4 x i16> } @llvm.riscv.vluxseg2.mask.nxv4i16.nxv4i8.i64(<vscale x 4 x i16> poison, <vscale x 4 x i16> poison, ptr [[BASE:%.*]], <vscale x 4 x i8> [[BINDEX:%.*]], <vscale x 4 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 3)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 4 x i16>, <vscale x 4 x i16> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 4 x i16> [[TMP1]], ptr [[V0:%.*]], align 2
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 4 x i16>, <vscale x 4 x i16> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 4 x i16> [[TMP2]], ptr [[V1:%.*]], align 2
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i16m1_tama(vint16m1_t *v0, vint16m1_t *v1, vbool16_t mask, const int16_t *base, vuint8mf2_t bindex, size_t vl) {
return vluxseg2ei8_tama(v0, v1, mask, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i16m2_tama(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 8 x i16>, <vscale x 8 x i16> } @llvm.riscv.vluxseg2.mask.nxv8i16.nxv8i8.i64(<vscale x 8 x i16> poison, <vscale x 8 x i16> poison, ptr [[BASE:%.*]], <vscale x 8 x i8> [[BINDEX:%.*]], <vscale x 8 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 3)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 8 x i16>, <vscale x 8 x i16> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 8 x i16> [[TMP1]], ptr [[V0:%.*]], align 2
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 8 x i16>, <vscale x 8 x i16> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 8 x i16> [[TMP2]], ptr [[V1:%.*]], align 2
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i16m2_tama(vint16m2_t *v0, vint16m2_t *v1, vbool8_t mask, const int16_t *base, vuint8m1_t bindex, size_t vl) {
return vluxseg2ei8_tama(v0, v1, mask, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i16m4_tama(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 16 x i16>, <vscale x 16 x i16> } @llvm.riscv.vluxseg2.mask.nxv16i16.nxv16i8.i64(<vscale x 16 x i16> poison, <vscale x 16 x i16> poison, ptr [[BASE:%.*]], <vscale x 16 x i8> [[BINDEX:%.*]], <vscale x 16 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 3)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 16 x i16>, <vscale x 16 x i16> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 16 x i16> [[TMP1]], ptr [[V0:%.*]], align 2
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 16 x i16>, <vscale x 16 x i16> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 16 x i16> [[TMP2]], ptr [[V1:%.*]], align 2
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i16m4_tama(vint16m4_t *v0, vint16m4_t *v1, vbool4_t mask, const int16_t *base, vuint8m2_t bindex, size_t vl) {
return vluxseg2ei8_tama(v0, v1, mask, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i32mf2_tama(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 1 x i32>, <vscale x 1 x i32> } @llvm.riscv.vluxseg2.mask.nxv1i32.nxv1i8.i64(<vscale x 1 x i32> poison, <vscale x 1 x i32> poison, ptr [[BASE:%.*]], <vscale x 1 x i8> [[BINDEX:%.*]], <vscale x 1 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 3)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 1 x i32>, <vscale x 1 x i32> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 1 x i32> [[TMP1]], ptr [[V0:%.*]], align 4
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 1 x i32>, <vscale x 1 x i32> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 1 x i32> [[TMP2]], ptr [[V1:%.*]], align 4
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i32mf2_tama(vint32mf2_t *v0, vint32mf2_t *v1, vbool64_t mask, const int32_t *base, vuint8mf8_t bindex, size_t vl) {
return vluxseg2ei8_tama(v0, v1, mask, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i32m1_tama(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 2 x i32>, <vscale x 2 x i32> } @llvm.riscv.vluxseg2.mask.nxv2i32.nxv2i8.i64(<vscale x 2 x i32> poison, <vscale x 2 x i32> poison, ptr [[BASE:%.*]], <vscale x 2 x i8> [[BINDEX:%.*]], <vscale x 2 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 3)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 2 x i32>, <vscale x 2 x i32> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 2 x i32> [[TMP1]], ptr [[V0:%.*]], align 4
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 2 x i32>, <vscale x 2 x i32> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 2 x i32> [[TMP2]], ptr [[V1:%.*]], align 4
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i32m1_tama(vint32m1_t *v0, vint32m1_t *v1, vbool32_t mask, const int32_t *base, vuint8mf4_t bindex, size_t vl) {
return vluxseg2ei8_tama(v0, v1, mask, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i32m2_tama(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 4 x i32>, <vscale x 4 x i32> } @llvm.riscv.vluxseg2.mask.nxv4i32.nxv4i8.i64(<vscale x 4 x i32> poison, <vscale x 4 x i32> poison, ptr [[BASE:%.*]], <vscale x 4 x i8> [[BINDEX:%.*]], <vscale x 4 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 3)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 4 x i32>, <vscale x 4 x i32> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 4 x i32> [[TMP1]], ptr [[V0:%.*]], align 4
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 4 x i32>, <vscale x 4 x i32> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 4 x i32> [[TMP2]], ptr [[V1:%.*]], align 4
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i32m2_tama(vint32m2_t *v0, vint32m2_t *v1, vbool16_t mask, const int32_t *base, vuint8mf2_t bindex, size_t vl) {
return vluxseg2ei8_tama(v0, v1, mask, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i32m4_tama(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 8 x i32>, <vscale x 8 x i32> } @llvm.riscv.vluxseg2.mask.nxv8i32.nxv8i8.i64(<vscale x 8 x i32> poison, <vscale x 8 x i32> poison, ptr [[BASE:%.*]], <vscale x 8 x i8> [[BINDEX:%.*]], <vscale x 8 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 3)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 8 x i32>, <vscale x 8 x i32> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 8 x i32> [[TMP1]], ptr [[V0:%.*]], align 4
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 8 x i32>, <vscale x 8 x i32> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 8 x i32> [[TMP2]], ptr [[V1:%.*]], align 4
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i32m4_tama(vint32m4_t *v0, vint32m4_t *v1, vbool8_t mask, const int32_t *base, vuint8m1_t bindex, size_t vl) {
return vluxseg2ei8_tama(v0, v1, mask, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i64m1_tama(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 1 x i64>, <vscale x 1 x i64> } @llvm.riscv.vluxseg2.mask.nxv1i64.nxv1i8.i64(<vscale x 1 x i64> poison, <vscale x 1 x i64> poison, ptr [[BASE:%.*]], <vscale x 1 x i8> [[BINDEX:%.*]], <vscale x 1 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 3)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 1 x i64>, <vscale x 1 x i64> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 1 x i64> [[TMP1]], ptr [[V0:%.*]], align 8
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 1 x i64>, <vscale x 1 x i64> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 1 x i64> [[TMP2]], ptr [[V1:%.*]], align 8
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i64m1_tama(vint64m1_t *v0, vint64m1_t *v1, vbool64_t mask, const int64_t *base, vuint8mf8_t bindex, size_t vl) {
return vluxseg2ei8_tama(v0, v1, mask, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i64m2_tama(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 2 x i64>, <vscale x 2 x i64> } @llvm.riscv.vluxseg2.mask.nxv2i64.nxv2i8.i64(<vscale x 2 x i64> poison, <vscale x 2 x i64> poison, ptr [[BASE:%.*]], <vscale x 2 x i8> [[BINDEX:%.*]], <vscale x 2 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 3)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 2 x i64>, <vscale x 2 x i64> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 2 x i64> [[TMP1]], ptr [[V0:%.*]], align 8
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 2 x i64>, <vscale x 2 x i64> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 2 x i64> [[TMP2]], ptr [[V1:%.*]], align 8
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i64m2_tama(vint64m2_t *v0, vint64m2_t *v1, vbool32_t mask, const int64_t *base, vuint8mf4_t bindex, size_t vl) {
return vluxseg2ei8_tama(v0, v1, mask, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i64m4_tama(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 4 x i64>, <vscale x 4 x i64> } @llvm.riscv.vluxseg2.mask.nxv4i64.nxv4i8.i64(<vscale x 4 x i64> poison, <vscale x 4 x i64> poison, ptr [[BASE:%.*]], <vscale x 4 x i8> [[BINDEX:%.*]], <vscale x 4 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 3)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 4 x i64>, <vscale x 4 x i64> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 4 x i64> [[TMP1]], ptr [[V0:%.*]], align 8
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 4 x i64>, <vscale x 4 x i64> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 4 x i64> [[TMP2]], ptr [[V1:%.*]], align 8
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i64m4_tama(vint64m4_t *v0, vint64m4_t *v1, vbool16_t mask, const int64_t *base, vuint8mf2_t bindex, size_t vl) {
return vluxseg2ei8_tama(v0, v1, mask, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u8mf8_tama(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 1 x i8>, <vscale x 1 x i8> } @llvm.riscv.vluxseg2.mask.nxv1i8.nxv1i8.i64(<vscale x 1 x i8> poison, <vscale x 1 x i8> poison, ptr [[BASE:%.*]], <vscale x 1 x i8> [[BINDEX:%.*]], <vscale x 1 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 3)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 1 x i8>, <vscale x 1 x i8> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 1 x i8> [[TMP1]], ptr [[V0:%.*]], align 1
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 1 x i8>, <vscale x 1 x i8> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 1 x i8> [[TMP2]], ptr [[V1:%.*]], align 1
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u8mf8_tama(vuint8mf8_t *v0, vuint8mf8_t *v1, vbool64_t mask, const uint8_t *base, vuint8mf8_t bindex, size_t vl) {
return vluxseg2ei8_tama(v0, v1, mask, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u8mf4_tama(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 2 x i8>, <vscale x 2 x i8> } @llvm.riscv.vluxseg2.mask.nxv2i8.nxv2i8.i64(<vscale x 2 x i8> poison, <vscale x 2 x i8> poison, ptr [[BASE:%.*]], <vscale x 2 x i8> [[BINDEX:%.*]], <vscale x 2 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 3)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 2 x i8>, <vscale x 2 x i8> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 2 x i8> [[TMP1]], ptr [[V0:%.*]], align 1
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 2 x i8>, <vscale x 2 x i8> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 2 x i8> [[TMP2]], ptr [[V1:%.*]], align 1
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u8mf4_tama(vuint8mf4_t *v0, vuint8mf4_t *v1, vbool32_t mask, const uint8_t *base, vuint8mf4_t bindex, size_t vl) {
return vluxseg2ei8_tama(v0, v1, mask, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u8mf2_tama(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 4 x i8>, <vscale x 4 x i8> } @llvm.riscv.vluxseg2.mask.nxv4i8.nxv4i8.i64(<vscale x 4 x i8> poison, <vscale x 4 x i8> poison, ptr [[BASE:%.*]], <vscale x 4 x i8> [[BINDEX:%.*]], <vscale x 4 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 3)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 4 x i8>, <vscale x 4 x i8> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 4 x i8> [[TMP1]], ptr [[V0:%.*]], align 1
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 4 x i8>, <vscale x 4 x i8> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 4 x i8> [[TMP2]], ptr [[V1:%.*]], align 1
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u8mf2_tama(vuint8mf2_t *v0, vuint8mf2_t *v1, vbool16_t mask, const uint8_t *base, vuint8mf2_t bindex, size_t vl) {
return vluxseg2ei8_tama(v0, v1, mask, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u8m1_tama(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 8 x i8>, <vscale x 8 x i8> } @llvm.riscv.vluxseg2.mask.nxv8i8.nxv8i8.i64(<vscale x 8 x i8> poison, <vscale x 8 x i8> poison, ptr [[BASE:%.*]], <vscale x 8 x i8> [[BINDEX:%.*]], <vscale x 8 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 3)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 8 x i8>, <vscale x 8 x i8> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 8 x i8> [[TMP1]], ptr [[V0:%.*]], align 1
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 8 x i8>, <vscale x 8 x i8> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 8 x i8> [[TMP2]], ptr [[V1:%.*]], align 1
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u8m1_tama(vuint8m1_t *v0, vuint8m1_t *v1, vbool8_t mask, const uint8_t *base, vuint8m1_t bindex, size_t vl) {
return vluxseg2ei8_tama(v0, v1, mask, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u8m2_tama(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 16 x i8>, <vscale x 16 x i8> } @llvm.riscv.vluxseg2.mask.nxv16i8.nxv16i8.i64(<vscale x 16 x i8> poison, <vscale x 16 x i8> poison, ptr [[BASE:%.*]], <vscale x 16 x i8> [[BINDEX:%.*]], <vscale x 16 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 3)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 16 x i8>, <vscale x 16 x i8> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 16 x i8> [[TMP1]], ptr [[V0:%.*]], align 1
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 16 x i8>, <vscale x 16 x i8> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 16 x i8> [[TMP2]], ptr [[V1:%.*]], align 1
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u8m2_tama(vuint8m2_t *v0, vuint8m2_t *v1, vbool4_t mask, const uint8_t *base, vuint8m2_t bindex, size_t vl) {
return vluxseg2ei8_tama(v0, v1, mask, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u8m4_tama(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 32 x i8>, <vscale x 32 x i8> } @llvm.riscv.vluxseg2.mask.nxv32i8.nxv32i8.i64(<vscale x 32 x i8> poison, <vscale x 32 x i8> poison, ptr [[BASE:%.*]], <vscale x 32 x i8> [[BINDEX:%.*]], <vscale x 32 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 3)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 32 x i8>, <vscale x 32 x i8> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 32 x i8> [[TMP1]], ptr [[V0:%.*]], align 1
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 32 x i8>, <vscale x 32 x i8> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 32 x i8> [[TMP2]], ptr [[V1:%.*]], align 1
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u8m4_tama(vuint8m4_t *v0, vuint8m4_t *v1, vbool2_t mask, const uint8_t *base, vuint8m4_t bindex, size_t vl) {
return vluxseg2ei8_tama(v0, v1, mask, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u16mf4_tama(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 1 x i16>, <vscale x 1 x i16> } @llvm.riscv.vluxseg2.mask.nxv1i16.nxv1i8.i64(<vscale x 1 x i16> poison, <vscale x 1 x i16> poison, ptr [[BASE:%.*]], <vscale x 1 x i8> [[BINDEX:%.*]], <vscale x 1 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 3)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 1 x i16>, <vscale x 1 x i16> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 1 x i16> [[TMP1]], ptr [[V0:%.*]], align 2
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 1 x i16>, <vscale x 1 x i16> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 1 x i16> [[TMP2]], ptr [[V1:%.*]], align 2
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u16mf4_tama(vuint16mf4_t *v0, vuint16mf4_t *v1, vbool64_t mask, const uint16_t *base, vuint8mf8_t bindex, size_t vl) {
return vluxseg2ei8_tama(v0, v1, mask, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u16mf2_tama(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 2 x i16>, <vscale x 2 x i16> } @llvm.riscv.vluxseg2.mask.nxv2i16.nxv2i8.i64(<vscale x 2 x i16> poison, <vscale x 2 x i16> poison, ptr [[BASE:%.*]], <vscale x 2 x i8> [[BINDEX:%.*]], <vscale x 2 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 3)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 2 x i16>, <vscale x 2 x i16> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 2 x i16> [[TMP1]], ptr [[V0:%.*]], align 2
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 2 x i16>, <vscale x 2 x i16> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 2 x i16> [[TMP2]], ptr [[V1:%.*]], align 2
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u16mf2_tama(vuint16mf2_t *v0, vuint16mf2_t *v1, vbool32_t mask, const uint16_t *base, vuint8mf4_t bindex, size_t vl) {
return vluxseg2ei8_tama(v0, v1, mask, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u16m1_tama(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 4 x i16>, <vscale x 4 x i16> } @llvm.riscv.vluxseg2.mask.nxv4i16.nxv4i8.i64(<vscale x 4 x i16> poison, <vscale x 4 x i16> poison, ptr [[BASE:%.*]], <vscale x 4 x i8> [[BINDEX:%.*]], <vscale x 4 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 3)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 4 x i16>, <vscale x 4 x i16> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 4 x i16> [[TMP1]], ptr [[V0:%.*]], align 2
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 4 x i16>, <vscale x 4 x i16> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 4 x i16> [[TMP2]], ptr [[V1:%.*]], align 2
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u16m1_tama(vuint16m1_t *v0, vuint16m1_t *v1, vbool16_t mask, const uint16_t *base, vuint8mf2_t bindex, size_t vl) {
return vluxseg2ei8_tama(v0, v1, mask, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u16m2_tama(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 8 x i16>, <vscale x 8 x i16> } @llvm.riscv.vluxseg2.mask.nxv8i16.nxv8i8.i64(<vscale x 8 x i16> poison, <vscale x 8 x i16> poison, ptr [[BASE:%.*]], <vscale x 8 x i8> [[BINDEX:%.*]], <vscale x 8 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 3)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 8 x i16>, <vscale x 8 x i16> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 8 x i16> [[TMP1]], ptr [[V0:%.*]], align 2
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 8 x i16>, <vscale x 8 x i16> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 8 x i16> [[TMP2]], ptr [[V1:%.*]], align 2
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u16m2_tama(vuint16m2_t *v0, vuint16m2_t *v1, vbool8_t mask, const uint16_t *base, vuint8m1_t bindex, size_t vl) {
return vluxseg2ei8_tama(v0, v1, mask, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u16m4_tama(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 16 x i16>, <vscale x 16 x i16> } @llvm.riscv.vluxseg2.mask.nxv16i16.nxv16i8.i64(<vscale x 16 x i16> poison, <vscale x 16 x i16> poison, ptr [[BASE:%.*]], <vscale x 16 x i8> [[BINDEX:%.*]], <vscale x 16 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 3)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 16 x i16>, <vscale x 16 x i16> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 16 x i16> [[TMP1]], ptr [[V0:%.*]], align 2
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 16 x i16>, <vscale x 16 x i16> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 16 x i16> [[TMP2]], ptr [[V1:%.*]], align 2
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u16m4_tama(vuint16m4_t *v0, vuint16m4_t *v1, vbool4_t mask, const uint16_t *base, vuint8m2_t bindex, size_t vl) {
return vluxseg2ei8_tama(v0, v1, mask, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u32mf2_tama(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 1 x i32>, <vscale x 1 x i32> } @llvm.riscv.vluxseg2.mask.nxv1i32.nxv1i8.i64(<vscale x 1 x i32> poison, <vscale x 1 x i32> poison, ptr [[BASE:%.*]], <vscale x 1 x i8> [[BINDEX:%.*]], <vscale x 1 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 3)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 1 x i32>, <vscale x 1 x i32> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 1 x i32> [[TMP1]], ptr [[V0:%.*]], align 4
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 1 x i32>, <vscale x 1 x i32> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 1 x i32> [[TMP2]], ptr [[V1:%.*]], align 4
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u32mf2_tama(vuint32mf2_t *v0, vuint32mf2_t *v1, vbool64_t mask, const uint32_t *base, vuint8mf8_t bindex, size_t vl) {
return vluxseg2ei8_tama(v0, v1, mask, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u32m1_tama(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 2 x i32>, <vscale x 2 x i32> } @llvm.riscv.vluxseg2.mask.nxv2i32.nxv2i8.i64(<vscale x 2 x i32> poison, <vscale x 2 x i32> poison, ptr [[BASE:%.*]], <vscale x 2 x i8> [[BINDEX:%.*]], <vscale x 2 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 3)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 2 x i32>, <vscale x 2 x i32> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 2 x i32> [[TMP1]], ptr [[V0:%.*]], align 4
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 2 x i32>, <vscale x 2 x i32> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 2 x i32> [[TMP2]], ptr [[V1:%.*]], align 4
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u32m1_tama(vuint32m1_t *v0, vuint32m1_t *v1, vbool32_t mask, const uint32_t *base, vuint8mf4_t bindex, size_t vl) {
return vluxseg2ei8_tama(v0, v1, mask, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u32m2_tama(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 4 x i32>, <vscale x 4 x i32> } @llvm.riscv.vluxseg2.mask.nxv4i32.nxv4i8.i64(<vscale x 4 x i32> poison, <vscale x 4 x i32> poison, ptr [[BASE:%.*]], <vscale x 4 x i8> [[BINDEX:%.*]], <vscale x 4 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 3)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 4 x i32>, <vscale x 4 x i32> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 4 x i32> [[TMP1]], ptr [[V0:%.*]], align 4
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 4 x i32>, <vscale x 4 x i32> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 4 x i32> [[TMP2]], ptr [[V1:%.*]], align 4
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u32m2_tama(vuint32m2_t *v0, vuint32m2_t *v1, vbool16_t mask, const uint32_t *base, vuint8mf2_t bindex, size_t vl) {
return vluxseg2ei8_tama(v0, v1, mask, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u32m4_tama(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 8 x i32>, <vscale x 8 x i32> } @llvm.riscv.vluxseg2.mask.nxv8i32.nxv8i8.i64(<vscale x 8 x i32> poison, <vscale x 8 x i32> poison, ptr [[BASE:%.*]], <vscale x 8 x i8> [[BINDEX:%.*]], <vscale x 8 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 3)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 8 x i32>, <vscale x 8 x i32> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 8 x i32> [[TMP1]], ptr [[V0:%.*]], align 4
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 8 x i32>, <vscale x 8 x i32> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 8 x i32> [[TMP2]], ptr [[V1:%.*]], align 4
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u32m4_tama(vuint32m4_t *v0, vuint32m4_t *v1, vbool8_t mask, const uint32_t *base, vuint8m1_t bindex, size_t vl) {
return vluxseg2ei8_tama(v0, v1, mask, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u64m1_tama(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 1 x i64>, <vscale x 1 x i64> } @llvm.riscv.vluxseg2.mask.nxv1i64.nxv1i8.i64(<vscale x 1 x i64> poison, <vscale x 1 x i64> poison, ptr [[BASE:%.*]], <vscale x 1 x i8> [[BINDEX:%.*]], <vscale x 1 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 3)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 1 x i64>, <vscale x 1 x i64> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 1 x i64> [[TMP1]], ptr [[V0:%.*]], align 8
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 1 x i64>, <vscale x 1 x i64> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 1 x i64> [[TMP2]], ptr [[V1:%.*]], align 8
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u64m1_tama(vuint64m1_t *v0, vuint64m1_t *v1, vbool64_t mask, const uint64_t *base, vuint8mf8_t bindex, size_t vl) {
return vluxseg2ei8_tama(v0, v1, mask, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u64m2_tama(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 2 x i64>, <vscale x 2 x i64> } @llvm.riscv.vluxseg2.mask.nxv2i64.nxv2i8.i64(<vscale x 2 x i64> poison, <vscale x 2 x i64> poison, ptr [[BASE:%.*]], <vscale x 2 x i8> [[BINDEX:%.*]], <vscale x 2 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 3)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 2 x i64>, <vscale x 2 x i64> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 2 x i64> [[TMP1]], ptr [[V0:%.*]], align 8
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 2 x i64>, <vscale x 2 x i64> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 2 x i64> [[TMP2]], ptr [[V1:%.*]], align 8
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u64m2_tama(vuint64m2_t *v0, vuint64m2_t *v1, vbool32_t mask, const uint64_t *base, vuint8mf4_t bindex, size_t vl) {
return vluxseg2ei8_tama(v0, v1, mask, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u64m4_tama(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 4 x i64>, <vscale x 4 x i64> } @llvm.riscv.vluxseg2.mask.nxv4i64.nxv4i8.i64(<vscale x 4 x i64> poison, <vscale x 4 x i64> poison, ptr [[BASE:%.*]], <vscale x 4 x i8> [[BINDEX:%.*]], <vscale x 4 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 3)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 4 x i64>, <vscale x 4 x i64> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 4 x i64> [[TMP1]], ptr [[V0:%.*]], align 8
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 4 x i64>, <vscale x 4 x i64> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 4 x i64> [[TMP2]], ptr [[V1:%.*]], align 8
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u64m4_tama(vuint64m4_t *v0, vuint64m4_t *v1, vbool16_t mask, const uint64_t *base, vuint8mf2_t bindex, size_t vl) {
return vluxseg2ei8_tama(v0, v1, mask, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_f16mf4_tamu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 1 x half>, <vscale x 1 x half> } @llvm.riscv.vluxseg2.mask.nxv1f16.nxv1i8.i64(<vscale x 1 x half> [[MASKEDOFF0:%.*]], <vscale x 1 x half> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 1 x i8> [[BINDEX:%.*]], <vscale x 1 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 1)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 1 x half>, <vscale x 1 x half> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 1 x half> [[TMP1]], ptr [[V0:%.*]], align 2
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 1 x half>, <vscale x 1 x half> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 1 x half> [[TMP2]], ptr [[V1:%.*]], align 2
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_f16mf4_tamu(vfloat16mf4_t *v0, vfloat16mf4_t *v1, vbool64_t mask, vfloat16mf4_t maskedoff0, vfloat16mf4_t maskedoff1, const _Float16 *base, vuint8mf8_t bindex, size_t vl) {
return vluxseg2ei8_tamu(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_f16mf2_tamu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 2 x half>, <vscale x 2 x half> } @llvm.riscv.vluxseg2.mask.nxv2f16.nxv2i8.i64(<vscale x 2 x half> [[MASKEDOFF0:%.*]], <vscale x 2 x half> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 2 x i8> [[BINDEX:%.*]], <vscale x 2 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 1)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 2 x half>, <vscale x 2 x half> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 2 x half> [[TMP1]], ptr [[V0:%.*]], align 2
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 2 x half>, <vscale x 2 x half> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 2 x half> [[TMP2]], ptr [[V1:%.*]], align 2
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_f16mf2_tamu(vfloat16mf2_t *v0, vfloat16mf2_t *v1, vbool32_t mask, vfloat16mf2_t maskedoff0, vfloat16mf2_t maskedoff1, const _Float16 *base, vuint8mf4_t bindex, size_t vl) {
return vluxseg2ei8_tamu(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_f16m1_tamu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 4 x half>, <vscale x 4 x half> } @llvm.riscv.vluxseg2.mask.nxv4f16.nxv4i8.i64(<vscale x 4 x half> [[MASKEDOFF0:%.*]], <vscale x 4 x half> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 4 x i8> [[BINDEX:%.*]], <vscale x 4 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 1)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 4 x half>, <vscale x 4 x half> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 4 x half> [[TMP1]], ptr [[V0:%.*]], align 2
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 4 x half>, <vscale x 4 x half> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 4 x half> [[TMP2]], ptr [[V1:%.*]], align 2
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_f16m1_tamu(vfloat16m1_t *v0, vfloat16m1_t *v1, vbool16_t mask, vfloat16m1_t maskedoff0, vfloat16m1_t maskedoff1, const _Float16 *base, vuint8mf2_t bindex, size_t vl) {
return vluxseg2ei8_tamu(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_f16m2_tamu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 8 x half>, <vscale x 8 x half> } @llvm.riscv.vluxseg2.mask.nxv8f16.nxv8i8.i64(<vscale x 8 x half> [[MASKEDOFF0:%.*]], <vscale x 8 x half> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 8 x i8> [[BINDEX:%.*]], <vscale x 8 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 1)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 8 x half>, <vscale x 8 x half> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 8 x half> [[TMP1]], ptr [[V0:%.*]], align 2
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 8 x half>, <vscale x 8 x half> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 8 x half> [[TMP2]], ptr [[V1:%.*]], align 2
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_f16m2_tamu(vfloat16m2_t *v0, vfloat16m2_t *v1, vbool8_t mask, vfloat16m2_t maskedoff0, vfloat16m2_t maskedoff1, const _Float16 *base, vuint8m1_t bindex, size_t vl) {
return vluxseg2ei8_tamu(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_f16m4_tamu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 16 x half>, <vscale x 16 x half> } @llvm.riscv.vluxseg2.mask.nxv16f16.nxv16i8.i64(<vscale x 16 x half> [[MASKEDOFF0:%.*]], <vscale x 16 x half> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 16 x i8> [[BINDEX:%.*]], <vscale x 16 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 1)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 16 x half>, <vscale x 16 x half> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 16 x half> [[TMP1]], ptr [[V0:%.*]], align 2
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 16 x half>, <vscale x 16 x half> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 16 x half> [[TMP2]], ptr [[V1:%.*]], align 2
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_f16m4_tamu(vfloat16m4_t *v0, vfloat16m4_t *v1, vbool4_t mask, vfloat16m4_t maskedoff0, vfloat16m4_t maskedoff1, const _Float16 *base, vuint8m2_t bindex, size_t vl) {
return vluxseg2ei8_tamu(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_f32mf2_tamu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 1 x float>, <vscale x 1 x float> } @llvm.riscv.vluxseg2.mask.nxv1f32.nxv1i8.i64(<vscale x 1 x float> [[MASKEDOFF0:%.*]], <vscale x 1 x float> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 1 x i8> [[BINDEX:%.*]], <vscale x 1 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 1)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 1 x float>, <vscale x 1 x float> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 1 x float> [[TMP1]], ptr [[V0:%.*]], align 4
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 1 x float>, <vscale x 1 x float> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 1 x float> [[TMP2]], ptr [[V1:%.*]], align 4
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_f32mf2_tamu(vfloat32mf2_t *v0, vfloat32mf2_t *v1, vbool64_t mask, vfloat32mf2_t maskedoff0, vfloat32mf2_t maskedoff1, const float *base, vuint8mf8_t bindex, size_t vl) {
return vluxseg2ei8_tamu(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_f32m1_tamu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 2 x float>, <vscale x 2 x float> } @llvm.riscv.vluxseg2.mask.nxv2f32.nxv2i8.i64(<vscale x 2 x float> [[MASKEDOFF0:%.*]], <vscale x 2 x float> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 2 x i8> [[BINDEX:%.*]], <vscale x 2 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 1)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 2 x float>, <vscale x 2 x float> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 2 x float> [[TMP1]], ptr [[V0:%.*]], align 4
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 2 x float>, <vscale x 2 x float> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 2 x float> [[TMP2]], ptr [[V1:%.*]], align 4
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_f32m1_tamu(vfloat32m1_t *v0, vfloat32m1_t *v1, vbool32_t mask, vfloat32m1_t maskedoff0, vfloat32m1_t maskedoff1, const float *base, vuint8mf4_t bindex, size_t vl) {
return vluxseg2ei8_tamu(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_f32m2_tamu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 4 x float>, <vscale x 4 x float> } @llvm.riscv.vluxseg2.mask.nxv4f32.nxv4i8.i64(<vscale x 4 x float> [[MASKEDOFF0:%.*]], <vscale x 4 x float> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 4 x i8> [[BINDEX:%.*]], <vscale x 4 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 1)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 4 x float>, <vscale x 4 x float> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 4 x float> [[TMP1]], ptr [[V0:%.*]], align 4
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 4 x float>, <vscale x 4 x float> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 4 x float> [[TMP2]], ptr [[V1:%.*]], align 4
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_f32m2_tamu(vfloat32m2_t *v0, vfloat32m2_t *v1, vbool16_t mask, vfloat32m2_t maskedoff0, vfloat32m2_t maskedoff1, const float *base, vuint8mf2_t bindex, size_t vl) {
return vluxseg2ei8_tamu(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_f32m4_tamu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 8 x float>, <vscale x 8 x float> } @llvm.riscv.vluxseg2.mask.nxv8f32.nxv8i8.i64(<vscale x 8 x float> [[MASKEDOFF0:%.*]], <vscale x 8 x float> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 8 x i8> [[BINDEX:%.*]], <vscale x 8 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 1)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 8 x float>, <vscale x 8 x float> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 8 x float> [[TMP1]], ptr [[V0:%.*]], align 4
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 8 x float>, <vscale x 8 x float> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 8 x float> [[TMP2]], ptr [[V1:%.*]], align 4
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_f32m4_tamu(vfloat32m4_t *v0, vfloat32m4_t *v1, vbool8_t mask, vfloat32m4_t maskedoff0, vfloat32m4_t maskedoff1, const float *base, vuint8m1_t bindex, size_t vl) {
return vluxseg2ei8_tamu(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_f64m1_tamu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 1 x double>, <vscale x 1 x double> } @llvm.riscv.vluxseg2.mask.nxv1f64.nxv1i8.i64(<vscale x 1 x double> [[MASKEDOFF0:%.*]], <vscale x 1 x double> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 1 x i8> [[BINDEX:%.*]], <vscale x 1 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 1)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 1 x double>, <vscale x 1 x double> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 1 x double> [[TMP1]], ptr [[V0:%.*]], align 8
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 1 x double>, <vscale x 1 x double> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 1 x double> [[TMP2]], ptr [[V1:%.*]], align 8
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_f64m1_tamu(vfloat64m1_t *v0, vfloat64m1_t *v1, vbool64_t mask, vfloat64m1_t maskedoff0, vfloat64m1_t maskedoff1, const double *base, vuint8mf8_t bindex, size_t vl) {
return vluxseg2ei8_tamu(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_f64m2_tamu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 2 x double>, <vscale x 2 x double> } @llvm.riscv.vluxseg2.mask.nxv2f64.nxv2i8.i64(<vscale x 2 x double> [[MASKEDOFF0:%.*]], <vscale x 2 x double> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 2 x i8> [[BINDEX:%.*]], <vscale x 2 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 1)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 2 x double>, <vscale x 2 x double> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 2 x double> [[TMP1]], ptr [[V0:%.*]], align 8
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 2 x double>, <vscale x 2 x double> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 2 x double> [[TMP2]], ptr [[V1:%.*]], align 8
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_f64m2_tamu(vfloat64m2_t *v0, vfloat64m2_t *v1, vbool32_t mask, vfloat64m2_t maskedoff0, vfloat64m2_t maskedoff1, const double *base, vuint8mf4_t bindex, size_t vl) {
return vluxseg2ei8_tamu(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_f64m4_tamu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 4 x double>, <vscale x 4 x double> } @llvm.riscv.vluxseg2.mask.nxv4f64.nxv4i8.i64(<vscale x 4 x double> [[MASKEDOFF0:%.*]], <vscale x 4 x double> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 4 x i8> [[BINDEX:%.*]], <vscale x 4 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 1)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 4 x double>, <vscale x 4 x double> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 4 x double> [[TMP1]], ptr [[V0:%.*]], align 8
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 4 x double>, <vscale x 4 x double> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 4 x double> [[TMP2]], ptr [[V1:%.*]], align 8
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_f64m4_tamu(vfloat64m4_t *v0, vfloat64m4_t *v1, vbool16_t mask, vfloat64m4_t maskedoff0, vfloat64m4_t maskedoff1, const double *base, vuint8mf2_t bindex, size_t vl) {
return vluxseg2ei8_tamu(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i8mf8_tamu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 1 x i8>, <vscale x 1 x i8> } @llvm.riscv.vluxseg2.mask.nxv1i8.nxv1i8.i64(<vscale x 1 x i8> [[MASKEDOFF0:%.*]], <vscale x 1 x i8> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 1 x i8> [[BINDEX:%.*]], <vscale x 1 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 1)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 1 x i8>, <vscale x 1 x i8> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 1 x i8> [[TMP1]], ptr [[V0:%.*]], align 1
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 1 x i8>, <vscale x 1 x i8> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 1 x i8> [[TMP2]], ptr [[V1:%.*]], align 1
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i8mf8_tamu(vint8mf8_t *v0, vint8mf8_t *v1, vbool64_t mask, vint8mf8_t maskedoff0, vint8mf8_t maskedoff1, const int8_t *base, vuint8mf8_t bindex, size_t vl) {
return vluxseg2ei8_tamu(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i8mf4_tamu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 2 x i8>, <vscale x 2 x i8> } @llvm.riscv.vluxseg2.mask.nxv2i8.nxv2i8.i64(<vscale x 2 x i8> [[MASKEDOFF0:%.*]], <vscale x 2 x i8> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 2 x i8> [[BINDEX:%.*]], <vscale x 2 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 1)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 2 x i8>, <vscale x 2 x i8> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 2 x i8> [[TMP1]], ptr [[V0:%.*]], align 1
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 2 x i8>, <vscale x 2 x i8> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 2 x i8> [[TMP2]], ptr [[V1:%.*]], align 1
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i8mf4_tamu(vint8mf4_t *v0, vint8mf4_t *v1, vbool32_t mask, vint8mf4_t maskedoff0, vint8mf4_t maskedoff1, const int8_t *base, vuint8mf4_t bindex, size_t vl) {
return vluxseg2ei8_tamu(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i8mf2_tamu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 4 x i8>, <vscale x 4 x i8> } @llvm.riscv.vluxseg2.mask.nxv4i8.nxv4i8.i64(<vscale x 4 x i8> [[MASKEDOFF0:%.*]], <vscale x 4 x i8> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 4 x i8> [[BINDEX:%.*]], <vscale x 4 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 1)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 4 x i8>, <vscale x 4 x i8> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 4 x i8> [[TMP1]], ptr [[V0:%.*]], align 1
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 4 x i8>, <vscale x 4 x i8> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 4 x i8> [[TMP2]], ptr [[V1:%.*]], align 1
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i8mf2_tamu(vint8mf2_t *v0, vint8mf2_t *v1, vbool16_t mask, vint8mf2_t maskedoff0, vint8mf2_t maskedoff1, const int8_t *base, vuint8mf2_t bindex, size_t vl) {
return vluxseg2ei8_tamu(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i8m1_tamu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 8 x i8>, <vscale x 8 x i8> } @llvm.riscv.vluxseg2.mask.nxv8i8.nxv8i8.i64(<vscale x 8 x i8> [[MASKEDOFF0:%.*]], <vscale x 8 x i8> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 8 x i8> [[BINDEX:%.*]], <vscale x 8 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 1)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 8 x i8>, <vscale x 8 x i8> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 8 x i8> [[TMP1]], ptr [[V0:%.*]], align 1
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 8 x i8>, <vscale x 8 x i8> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 8 x i8> [[TMP2]], ptr [[V1:%.*]], align 1
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i8m1_tamu(vint8m1_t *v0, vint8m1_t *v1, vbool8_t mask, vint8m1_t maskedoff0, vint8m1_t maskedoff1, const int8_t *base, vuint8m1_t bindex, size_t vl) {
return vluxseg2ei8_tamu(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i8m2_tamu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 16 x i8>, <vscale x 16 x i8> } @llvm.riscv.vluxseg2.mask.nxv16i8.nxv16i8.i64(<vscale x 16 x i8> [[MASKEDOFF0:%.*]], <vscale x 16 x i8> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 16 x i8> [[BINDEX:%.*]], <vscale x 16 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 1)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 16 x i8>, <vscale x 16 x i8> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 16 x i8> [[TMP1]], ptr [[V0:%.*]], align 1
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 16 x i8>, <vscale x 16 x i8> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 16 x i8> [[TMP2]], ptr [[V1:%.*]], align 1
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i8m2_tamu(vint8m2_t *v0, vint8m2_t *v1, vbool4_t mask, vint8m2_t maskedoff0, vint8m2_t maskedoff1, const int8_t *base, vuint8m2_t bindex, size_t vl) {
return vluxseg2ei8_tamu(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i8m4_tamu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 32 x i8>, <vscale x 32 x i8> } @llvm.riscv.vluxseg2.mask.nxv32i8.nxv32i8.i64(<vscale x 32 x i8> [[MASKEDOFF0:%.*]], <vscale x 32 x i8> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 32 x i8> [[BINDEX:%.*]], <vscale x 32 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 1)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 32 x i8>, <vscale x 32 x i8> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 32 x i8> [[TMP1]], ptr [[V0:%.*]], align 1
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 32 x i8>, <vscale x 32 x i8> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 32 x i8> [[TMP2]], ptr [[V1:%.*]], align 1
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i8m4_tamu(vint8m4_t *v0, vint8m4_t *v1, vbool2_t mask, vint8m4_t maskedoff0, vint8m4_t maskedoff1, const int8_t *base, vuint8m4_t bindex, size_t vl) {
return vluxseg2ei8_tamu(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i16mf4_tamu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 1 x i16>, <vscale x 1 x i16> } @llvm.riscv.vluxseg2.mask.nxv1i16.nxv1i8.i64(<vscale x 1 x i16> [[MASKEDOFF0:%.*]], <vscale x 1 x i16> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 1 x i8> [[BINDEX:%.*]], <vscale x 1 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 1)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 1 x i16>, <vscale x 1 x i16> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 1 x i16> [[TMP1]], ptr [[V0:%.*]], align 2
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 1 x i16>, <vscale x 1 x i16> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 1 x i16> [[TMP2]], ptr [[V1:%.*]], align 2
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i16mf4_tamu(vint16mf4_t *v0, vint16mf4_t *v1, vbool64_t mask, vint16mf4_t maskedoff0, vint16mf4_t maskedoff1, const int16_t *base, vuint8mf8_t bindex, size_t vl) {
return vluxseg2ei8_tamu(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i16mf2_tamu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 2 x i16>, <vscale x 2 x i16> } @llvm.riscv.vluxseg2.mask.nxv2i16.nxv2i8.i64(<vscale x 2 x i16> [[MASKEDOFF0:%.*]], <vscale x 2 x i16> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 2 x i8> [[BINDEX:%.*]], <vscale x 2 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 1)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 2 x i16>, <vscale x 2 x i16> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 2 x i16> [[TMP1]], ptr [[V0:%.*]], align 2
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 2 x i16>, <vscale x 2 x i16> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 2 x i16> [[TMP2]], ptr [[V1:%.*]], align 2
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i16mf2_tamu(vint16mf2_t *v0, vint16mf2_t *v1, vbool32_t mask, vint16mf2_t maskedoff0, vint16mf2_t maskedoff1, const int16_t *base, vuint8mf4_t bindex, size_t vl) {
return vluxseg2ei8_tamu(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i16m1_tamu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 4 x i16>, <vscale x 4 x i16> } @llvm.riscv.vluxseg2.mask.nxv4i16.nxv4i8.i64(<vscale x 4 x i16> [[MASKEDOFF0:%.*]], <vscale x 4 x i16> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 4 x i8> [[BINDEX:%.*]], <vscale x 4 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 1)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 4 x i16>, <vscale x 4 x i16> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 4 x i16> [[TMP1]], ptr [[V0:%.*]], align 2
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 4 x i16>, <vscale x 4 x i16> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 4 x i16> [[TMP2]], ptr [[V1:%.*]], align 2
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i16m1_tamu(vint16m1_t *v0, vint16m1_t *v1, vbool16_t mask, vint16m1_t maskedoff0, vint16m1_t maskedoff1, const int16_t *base, vuint8mf2_t bindex, size_t vl) {
return vluxseg2ei8_tamu(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i16m2_tamu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 8 x i16>, <vscale x 8 x i16> } @llvm.riscv.vluxseg2.mask.nxv8i16.nxv8i8.i64(<vscale x 8 x i16> [[MASKEDOFF0:%.*]], <vscale x 8 x i16> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 8 x i8> [[BINDEX:%.*]], <vscale x 8 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 1)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 8 x i16>, <vscale x 8 x i16> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 8 x i16> [[TMP1]], ptr [[V0:%.*]], align 2
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 8 x i16>, <vscale x 8 x i16> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 8 x i16> [[TMP2]], ptr [[V1:%.*]], align 2
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i16m2_tamu(vint16m2_t *v0, vint16m2_t *v1, vbool8_t mask, vint16m2_t maskedoff0, vint16m2_t maskedoff1, const int16_t *base, vuint8m1_t bindex, size_t vl) {
return vluxseg2ei8_tamu(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i16m4_tamu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 16 x i16>, <vscale x 16 x i16> } @llvm.riscv.vluxseg2.mask.nxv16i16.nxv16i8.i64(<vscale x 16 x i16> [[MASKEDOFF0:%.*]], <vscale x 16 x i16> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 16 x i8> [[BINDEX:%.*]], <vscale x 16 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 1)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 16 x i16>, <vscale x 16 x i16> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 16 x i16> [[TMP1]], ptr [[V0:%.*]], align 2
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 16 x i16>, <vscale x 16 x i16> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 16 x i16> [[TMP2]], ptr [[V1:%.*]], align 2
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i16m4_tamu(vint16m4_t *v0, vint16m4_t *v1, vbool4_t mask, vint16m4_t maskedoff0, vint16m4_t maskedoff1, const int16_t *base, vuint8m2_t bindex, size_t vl) {
return vluxseg2ei8_tamu(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i32mf2_tamu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 1 x i32>, <vscale x 1 x i32> } @llvm.riscv.vluxseg2.mask.nxv1i32.nxv1i8.i64(<vscale x 1 x i32> [[MASKEDOFF0:%.*]], <vscale x 1 x i32> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 1 x i8> [[BINDEX:%.*]], <vscale x 1 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 1)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 1 x i32>, <vscale x 1 x i32> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 1 x i32> [[TMP1]], ptr [[V0:%.*]], align 4
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 1 x i32>, <vscale x 1 x i32> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 1 x i32> [[TMP2]], ptr [[V1:%.*]], align 4
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i32mf2_tamu(vint32mf2_t *v0, vint32mf2_t *v1, vbool64_t mask, vint32mf2_t maskedoff0, vint32mf2_t maskedoff1, const int32_t *base, vuint8mf8_t bindex, size_t vl) {
return vluxseg2ei8_tamu(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i32m1_tamu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 2 x i32>, <vscale x 2 x i32> } @llvm.riscv.vluxseg2.mask.nxv2i32.nxv2i8.i64(<vscale x 2 x i32> [[MASKEDOFF0:%.*]], <vscale x 2 x i32> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 2 x i8> [[BINDEX:%.*]], <vscale x 2 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 1)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 2 x i32>, <vscale x 2 x i32> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 2 x i32> [[TMP1]], ptr [[V0:%.*]], align 4
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 2 x i32>, <vscale x 2 x i32> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 2 x i32> [[TMP2]], ptr [[V1:%.*]], align 4
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i32m1_tamu(vint32m1_t *v0, vint32m1_t *v1, vbool32_t mask, vint32m1_t maskedoff0, vint32m1_t maskedoff1, const int32_t *base, vuint8mf4_t bindex, size_t vl) {
return vluxseg2ei8_tamu(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i32m2_tamu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 4 x i32>, <vscale x 4 x i32> } @llvm.riscv.vluxseg2.mask.nxv4i32.nxv4i8.i64(<vscale x 4 x i32> [[MASKEDOFF0:%.*]], <vscale x 4 x i32> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 4 x i8> [[BINDEX:%.*]], <vscale x 4 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 1)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 4 x i32>, <vscale x 4 x i32> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 4 x i32> [[TMP1]], ptr [[V0:%.*]], align 4
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 4 x i32>, <vscale x 4 x i32> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 4 x i32> [[TMP2]], ptr [[V1:%.*]], align 4
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i32m2_tamu(vint32m2_t *v0, vint32m2_t *v1, vbool16_t mask, vint32m2_t maskedoff0, vint32m2_t maskedoff1, const int32_t *base, vuint8mf2_t bindex, size_t vl) {
return vluxseg2ei8_tamu(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i32m4_tamu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 8 x i32>, <vscale x 8 x i32> } @llvm.riscv.vluxseg2.mask.nxv8i32.nxv8i8.i64(<vscale x 8 x i32> [[MASKEDOFF0:%.*]], <vscale x 8 x i32> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 8 x i8> [[BINDEX:%.*]], <vscale x 8 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 1)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 8 x i32>, <vscale x 8 x i32> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 8 x i32> [[TMP1]], ptr [[V0:%.*]], align 4
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 8 x i32>, <vscale x 8 x i32> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 8 x i32> [[TMP2]], ptr [[V1:%.*]], align 4
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i32m4_tamu(vint32m4_t *v0, vint32m4_t *v1, vbool8_t mask, vint32m4_t maskedoff0, vint32m4_t maskedoff1, const int32_t *base, vuint8m1_t bindex, size_t vl) {
return vluxseg2ei8_tamu(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i64m1_tamu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 1 x i64>, <vscale x 1 x i64> } @llvm.riscv.vluxseg2.mask.nxv1i64.nxv1i8.i64(<vscale x 1 x i64> [[MASKEDOFF0:%.*]], <vscale x 1 x i64> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 1 x i8> [[BINDEX:%.*]], <vscale x 1 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 1)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 1 x i64>, <vscale x 1 x i64> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 1 x i64> [[TMP1]], ptr [[V0:%.*]], align 8
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 1 x i64>, <vscale x 1 x i64> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 1 x i64> [[TMP2]], ptr [[V1:%.*]], align 8
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i64m1_tamu(vint64m1_t *v0, vint64m1_t *v1, vbool64_t mask, vint64m1_t maskedoff0, vint64m1_t maskedoff1, const int64_t *base, vuint8mf8_t bindex, size_t vl) {
return vluxseg2ei8_tamu(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i64m2_tamu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 2 x i64>, <vscale x 2 x i64> } @llvm.riscv.vluxseg2.mask.nxv2i64.nxv2i8.i64(<vscale x 2 x i64> [[MASKEDOFF0:%.*]], <vscale x 2 x i64> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 2 x i8> [[BINDEX:%.*]], <vscale x 2 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 1)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 2 x i64>, <vscale x 2 x i64> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 2 x i64> [[TMP1]], ptr [[V0:%.*]], align 8
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 2 x i64>, <vscale x 2 x i64> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 2 x i64> [[TMP2]], ptr [[V1:%.*]], align 8
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i64m2_tamu(vint64m2_t *v0, vint64m2_t *v1, vbool32_t mask, vint64m2_t maskedoff0, vint64m2_t maskedoff1, const int64_t *base, vuint8mf4_t bindex, size_t vl) {
return vluxseg2ei8_tamu(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_i64m4_tamu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 4 x i64>, <vscale x 4 x i64> } @llvm.riscv.vluxseg2.mask.nxv4i64.nxv4i8.i64(<vscale x 4 x i64> [[MASKEDOFF0:%.*]], <vscale x 4 x i64> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 4 x i8> [[BINDEX:%.*]], <vscale x 4 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 1)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 4 x i64>, <vscale x 4 x i64> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 4 x i64> [[TMP1]], ptr [[V0:%.*]], align 8
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 4 x i64>, <vscale x 4 x i64> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 4 x i64> [[TMP2]], ptr [[V1:%.*]], align 8
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_i64m4_tamu(vint64m4_t *v0, vint64m4_t *v1, vbool16_t mask, vint64m4_t maskedoff0, vint64m4_t maskedoff1, const int64_t *base, vuint8mf2_t bindex, size_t vl) {
return vluxseg2ei8_tamu(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u8mf8_tamu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 1 x i8>, <vscale x 1 x i8> } @llvm.riscv.vluxseg2.mask.nxv1i8.nxv1i8.i64(<vscale x 1 x i8> [[MASKEDOFF0:%.*]], <vscale x 1 x i8> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 1 x i8> [[BINDEX:%.*]], <vscale x 1 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 1)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 1 x i8>, <vscale x 1 x i8> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 1 x i8> [[TMP1]], ptr [[V0:%.*]], align 1
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 1 x i8>, <vscale x 1 x i8> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 1 x i8> [[TMP2]], ptr [[V1:%.*]], align 1
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u8mf8_tamu(vuint8mf8_t *v0, vuint8mf8_t *v1, vbool64_t mask, vuint8mf8_t maskedoff0, vuint8mf8_t maskedoff1, const uint8_t *base, vuint8mf8_t bindex, size_t vl) {
return vluxseg2ei8_tamu(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u8mf4_tamu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 2 x i8>, <vscale x 2 x i8> } @llvm.riscv.vluxseg2.mask.nxv2i8.nxv2i8.i64(<vscale x 2 x i8> [[MASKEDOFF0:%.*]], <vscale x 2 x i8> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 2 x i8> [[BINDEX:%.*]], <vscale x 2 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 1)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 2 x i8>, <vscale x 2 x i8> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 2 x i8> [[TMP1]], ptr [[V0:%.*]], align 1
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 2 x i8>, <vscale x 2 x i8> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 2 x i8> [[TMP2]], ptr [[V1:%.*]], align 1
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u8mf4_tamu(vuint8mf4_t *v0, vuint8mf4_t *v1, vbool32_t mask, vuint8mf4_t maskedoff0, vuint8mf4_t maskedoff1, const uint8_t *base, vuint8mf4_t bindex, size_t vl) {
return vluxseg2ei8_tamu(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u8mf2_tamu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 4 x i8>, <vscale x 4 x i8> } @llvm.riscv.vluxseg2.mask.nxv4i8.nxv4i8.i64(<vscale x 4 x i8> [[MASKEDOFF0:%.*]], <vscale x 4 x i8> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 4 x i8> [[BINDEX:%.*]], <vscale x 4 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 1)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 4 x i8>, <vscale x 4 x i8> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 4 x i8> [[TMP1]], ptr [[V0:%.*]], align 1
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 4 x i8>, <vscale x 4 x i8> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 4 x i8> [[TMP2]], ptr [[V1:%.*]], align 1
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u8mf2_tamu(vuint8mf2_t *v0, vuint8mf2_t *v1, vbool16_t mask, vuint8mf2_t maskedoff0, vuint8mf2_t maskedoff1, const uint8_t *base, vuint8mf2_t bindex, size_t vl) {
return vluxseg2ei8_tamu(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u8m1_tamu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 8 x i8>, <vscale x 8 x i8> } @llvm.riscv.vluxseg2.mask.nxv8i8.nxv8i8.i64(<vscale x 8 x i8> [[MASKEDOFF0:%.*]], <vscale x 8 x i8> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 8 x i8> [[BINDEX:%.*]], <vscale x 8 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 1)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 8 x i8>, <vscale x 8 x i8> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 8 x i8> [[TMP1]], ptr [[V0:%.*]], align 1
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 8 x i8>, <vscale x 8 x i8> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 8 x i8> [[TMP2]], ptr [[V1:%.*]], align 1
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u8m1_tamu(vuint8m1_t *v0, vuint8m1_t *v1, vbool8_t mask, vuint8m1_t maskedoff0, vuint8m1_t maskedoff1, const uint8_t *base, vuint8m1_t bindex, size_t vl) {
return vluxseg2ei8_tamu(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u8m2_tamu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 16 x i8>, <vscale x 16 x i8> } @llvm.riscv.vluxseg2.mask.nxv16i8.nxv16i8.i64(<vscale x 16 x i8> [[MASKEDOFF0:%.*]], <vscale x 16 x i8> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 16 x i8> [[BINDEX:%.*]], <vscale x 16 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 1)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 16 x i8>, <vscale x 16 x i8> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 16 x i8> [[TMP1]], ptr [[V0:%.*]], align 1
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 16 x i8>, <vscale x 16 x i8> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 16 x i8> [[TMP2]], ptr [[V1:%.*]], align 1
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u8m2_tamu(vuint8m2_t *v0, vuint8m2_t *v1, vbool4_t mask, vuint8m2_t maskedoff0, vuint8m2_t maskedoff1, const uint8_t *base, vuint8m2_t bindex, size_t vl) {
return vluxseg2ei8_tamu(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u8m4_tamu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 32 x i8>, <vscale x 32 x i8> } @llvm.riscv.vluxseg2.mask.nxv32i8.nxv32i8.i64(<vscale x 32 x i8> [[MASKEDOFF0:%.*]], <vscale x 32 x i8> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 32 x i8> [[BINDEX:%.*]], <vscale x 32 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 1)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 32 x i8>, <vscale x 32 x i8> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 32 x i8> [[TMP1]], ptr [[V0:%.*]], align 1
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 32 x i8>, <vscale x 32 x i8> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 32 x i8> [[TMP2]], ptr [[V1:%.*]], align 1
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u8m4_tamu(vuint8m4_t *v0, vuint8m4_t *v1, vbool2_t mask, vuint8m4_t maskedoff0, vuint8m4_t maskedoff1, const uint8_t *base, vuint8m4_t bindex, size_t vl) {
return vluxseg2ei8_tamu(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u16mf4_tamu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 1 x i16>, <vscale x 1 x i16> } @llvm.riscv.vluxseg2.mask.nxv1i16.nxv1i8.i64(<vscale x 1 x i16> [[MASKEDOFF0:%.*]], <vscale x 1 x i16> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 1 x i8> [[BINDEX:%.*]], <vscale x 1 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 1)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 1 x i16>, <vscale x 1 x i16> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 1 x i16> [[TMP1]], ptr [[V0:%.*]], align 2
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 1 x i16>, <vscale x 1 x i16> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 1 x i16> [[TMP2]], ptr [[V1:%.*]], align 2
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u16mf4_tamu(vuint16mf4_t *v0, vuint16mf4_t *v1, vbool64_t mask, vuint16mf4_t maskedoff0, vuint16mf4_t maskedoff1, const uint16_t *base, vuint8mf8_t bindex, size_t vl) {
return vluxseg2ei8_tamu(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u16mf2_tamu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 2 x i16>, <vscale x 2 x i16> } @llvm.riscv.vluxseg2.mask.nxv2i16.nxv2i8.i64(<vscale x 2 x i16> [[MASKEDOFF0:%.*]], <vscale x 2 x i16> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 2 x i8> [[BINDEX:%.*]], <vscale x 2 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 1)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 2 x i16>, <vscale x 2 x i16> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 2 x i16> [[TMP1]], ptr [[V0:%.*]], align 2
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 2 x i16>, <vscale x 2 x i16> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 2 x i16> [[TMP2]], ptr [[V1:%.*]], align 2
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u16mf2_tamu(vuint16mf2_t *v0, vuint16mf2_t *v1, vbool32_t mask, vuint16mf2_t maskedoff0, vuint16mf2_t maskedoff1, const uint16_t *base, vuint8mf4_t bindex, size_t vl) {
return vluxseg2ei8_tamu(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u16m1_tamu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 4 x i16>, <vscale x 4 x i16> } @llvm.riscv.vluxseg2.mask.nxv4i16.nxv4i8.i64(<vscale x 4 x i16> [[MASKEDOFF0:%.*]], <vscale x 4 x i16> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 4 x i8> [[BINDEX:%.*]], <vscale x 4 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 1)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 4 x i16>, <vscale x 4 x i16> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 4 x i16> [[TMP1]], ptr [[V0:%.*]], align 2
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 4 x i16>, <vscale x 4 x i16> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 4 x i16> [[TMP2]], ptr [[V1:%.*]], align 2
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u16m1_tamu(vuint16m1_t *v0, vuint16m1_t *v1, vbool16_t mask, vuint16m1_t maskedoff0, vuint16m1_t maskedoff1, const uint16_t *base, vuint8mf2_t bindex, size_t vl) {
return vluxseg2ei8_tamu(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u16m2_tamu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 8 x i16>, <vscale x 8 x i16> } @llvm.riscv.vluxseg2.mask.nxv8i16.nxv8i8.i64(<vscale x 8 x i16> [[MASKEDOFF0:%.*]], <vscale x 8 x i16> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 8 x i8> [[BINDEX:%.*]], <vscale x 8 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 1)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 8 x i16>, <vscale x 8 x i16> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 8 x i16> [[TMP1]], ptr [[V0:%.*]], align 2
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 8 x i16>, <vscale x 8 x i16> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 8 x i16> [[TMP2]], ptr [[V1:%.*]], align 2
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u16m2_tamu(vuint16m2_t *v0, vuint16m2_t *v1, vbool8_t mask, vuint16m2_t maskedoff0, vuint16m2_t maskedoff1, const uint16_t *base, vuint8m1_t bindex, size_t vl) {
return vluxseg2ei8_tamu(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u16m4_tamu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 16 x i16>, <vscale x 16 x i16> } @llvm.riscv.vluxseg2.mask.nxv16i16.nxv16i8.i64(<vscale x 16 x i16> [[MASKEDOFF0:%.*]], <vscale x 16 x i16> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 16 x i8> [[BINDEX:%.*]], <vscale x 16 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 1)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 16 x i16>, <vscale x 16 x i16> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 16 x i16> [[TMP1]], ptr [[V0:%.*]], align 2
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 16 x i16>, <vscale x 16 x i16> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 16 x i16> [[TMP2]], ptr [[V1:%.*]], align 2
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u16m4_tamu(vuint16m4_t *v0, vuint16m4_t *v1, vbool4_t mask, vuint16m4_t maskedoff0, vuint16m4_t maskedoff1, const uint16_t *base, vuint8m2_t bindex, size_t vl) {
return vluxseg2ei8_tamu(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u32mf2_tamu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 1 x i32>, <vscale x 1 x i32> } @llvm.riscv.vluxseg2.mask.nxv1i32.nxv1i8.i64(<vscale x 1 x i32> [[MASKEDOFF0:%.*]], <vscale x 1 x i32> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 1 x i8> [[BINDEX:%.*]], <vscale x 1 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 1)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 1 x i32>, <vscale x 1 x i32> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 1 x i32> [[TMP1]], ptr [[V0:%.*]], align 4
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 1 x i32>, <vscale x 1 x i32> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 1 x i32> [[TMP2]], ptr [[V1:%.*]], align 4
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u32mf2_tamu(vuint32mf2_t *v0, vuint32mf2_t *v1, vbool64_t mask, vuint32mf2_t maskedoff0, vuint32mf2_t maskedoff1, const uint32_t *base, vuint8mf8_t bindex, size_t vl) {
return vluxseg2ei8_tamu(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u32m1_tamu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 2 x i32>, <vscale x 2 x i32> } @llvm.riscv.vluxseg2.mask.nxv2i32.nxv2i8.i64(<vscale x 2 x i32> [[MASKEDOFF0:%.*]], <vscale x 2 x i32> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 2 x i8> [[BINDEX:%.*]], <vscale x 2 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 1)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 2 x i32>, <vscale x 2 x i32> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 2 x i32> [[TMP1]], ptr [[V0:%.*]], align 4
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 2 x i32>, <vscale x 2 x i32> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 2 x i32> [[TMP2]], ptr [[V1:%.*]], align 4
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u32m1_tamu(vuint32m1_t *v0, vuint32m1_t *v1, vbool32_t mask, vuint32m1_t maskedoff0, vuint32m1_t maskedoff1, const uint32_t *base, vuint8mf4_t bindex, size_t vl) {
return vluxseg2ei8_tamu(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u32m2_tamu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 4 x i32>, <vscale x 4 x i32> } @llvm.riscv.vluxseg2.mask.nxv4i32.nxv4i8.i64(<vscale x 4 x i32> [[MASKEDOFF0:%.*]], <vscale x 4 x i32> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 4 x i8> [[BINDEX:%.*]], <vscale x 4 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 1)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 4 x i32>, <vscale x 4 x i32> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 4 x i32> [[TMP1]], ptr [[V0:%.*]], align 4
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 4 x i32>, <vscale x 4 x i32> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 4 x i32> [[TMP2]], ptr [[V1:%.*]], align 4
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u32m2_tamu(vuint32m2_t *v0, vuint32m2_t *v1, vbool16_t mask, vuint32m2_t maskedoff0, vuint32m2_t maskedoff1, const uint32_t *base, vuint8mf2_t bindex, size_t vl) {
return vluxseg2ei8_tamu(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u32m4_tamu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 8 x i32>, <vscale x 8 x i32> } @llvm.riscv.vluxseg2.mask.nxv8i32.nxv8i8.i64(<vscale x 8 x i32> [[MASKEDOFF0:%.*]], <vscale x 8 x i32> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 8 x i8> [[BINDEX:%.*]], <vscale x 8 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 1)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 8 x i32>, <vscale x 8 x i32> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 8 x i32> [[TMP1]], ptr [[V0:%.*]], align 4
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 8 x i32>, <vscale x 8 x i32> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 8 x i32> [[TMP2]], ptr [[V1:%.*]], align 4
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u32m4_tamu(vuint32m4_t *v0, vuint32m4_t *v1, vbool8_t mask, vuint32m4_t maskedoff0, vuint32m4_t maskedoff1, const uint32_t *base, vuint8m1_t bindex, size_t vl) {
return vluxseg2ei8_tamu(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u64m1_tamu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 1 x i64>, <vscale x 1 x i64> } @llvm.riscv.vluxseg2.mask.nxv1i64.nxv1i8.i64(<vscale x 1 x i64> [[MASKEDOFF0:%.*]], <vscale x 1 x i64> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 1 x i8> [[BINDEX:%.*]], <vscale x 1 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 1)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 1 x i64>, <vscale x 1 x i64> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 1 x i64> [[TMP1]], ptr [[V0:%.*]], align 8
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 1 x i64>, <vscale x 1 x i64> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 1 x i64> [[TMP2]], ptr [[V1:%.*]], align 8
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u64m1_tamu(vuint64m1_t *v0, vuint64m1_t *v1, vbool64_t mask, vuint64m1_t maskedoff0, vuint64m1_t maskedoff1, const uint64_t *base, vuint8mf8_t bindex, size_t vl) {
return vluxseg2ei8_tamu(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u64m2_tamu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 2 x i64>, <vscale x 2 x i64> } @llvm.riscv.vluxseg2.mask.nxv2i64.nxv2i8.i64(<vscale x 2 x i64> [[MASKEDOFF0:%.*]], <vscale x 2 x i64> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 2 x i8> [[BINDEX:%.*]], <vscale x 2 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 1)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 2 x i64>, <vscale x 2 x i64> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 2 x i64> [[TMP1]], ptr [[V0:%.*]], align 8
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 2 x i64>, <vscale x 2 x i64> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 2 x i64> [[TMP2]], ptr [[V1:%.*]], align 8
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u64m2_tamu(vuint64m2_t *v0, vuint64m2_t *v1, vbool32_t mask, vuint64m2_t maskedoff0, vuint64m2_t maskedoff1, const uint64_t *base, vuint8mf4_t bindex, size_t vl) {
return vluxseg2ei8_tamu(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
// CHECK-RV64-LABEL: @test_vluxseg2ei8_v_u64m4_tamu(
// CHECK-RV64-NEXT: entry:
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call { <vscale x 4 x i64>, <vscale x 4 x i64> } @llvm.riscv.vluxseg2.mask.nxv4i64.nxv4i8.i64(<vscale x 4 x i64> [[MASKEDOFF0:%.*]], <vscale x 4 x i64> [[MASKEDOFF1:%.*]], ptr [[BASE:%.*]], <vscale x 4 x i8> [[BINDEX:%.*]], <vscale x 4 x i1> [[MASK:%.*]], i64 [[VL:%.*]], i64 1)
// CHECK-RV64-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 4 x i64>, <vscale x 4 x i64> } [[TMP0]], 0
// CHECK-RV64-NEXT: store <vscale x 4 x i64> [[TMP1]], ptr [[V0:%.*]], align 8
// CHECK-RV64-NEXT: [[TMP2:%.*]] = extractvalue { <vscale x 4 x i64>, <vscale x 4 x i64> } [[TMP0]], 1
// CHECK-RV64-NEXT: store <vscale x 4 x i64> [[TMP2]], ptr [[V1:%.*]], align 8
// CHECK-RV64-NEXT: ret void
//
void test_vluxseg2ei8_v_u64m4_tamu(vuint64m4_t *v0, vuint64m4_t *v1, vbool16_t mask, vuint64m4_t maskedoff0, vuint64m4_t maskedoff1, const uint64_t *base, vuint8mf2_t bindex, size_t vl) {
return vluxseg2ei8_tamu(v0, v1, mask, maskedoff0, maskedoff1, base, bindex, vl);
}
|
a64f3e1e744148077876264ea5aa169171c01d5e
|
f3eed0234b4d0ad2bbb2abd700cf1e2c7a0e8a1d
|
/AKWF-c/AKWF_0018/AKWF_1758.h
|
492f10d1a92398d013e583b88698552390116389
|
[
"CC0-1.0"
] |
permissive
|
KristofferKarlAxelEkstrand/AKWF-FREE
|
b2defa1a2d389d309be6dd2e9f968923daf80d1b
|
cf8171df36e9fec25416b5f568b72a6e2cb69194
|
refs/heads/master
| 2023-07-23T18:22:36.939705
| 2023-07-10T17:14:40
| 2023-07-10T17:14:40
| 145,817,187
| 359
| 59
|
CC0-1.0
| 2023-07-10T17:14:41
| 2018-08-23T07:26:56
| null |
UTF-8
|
C
| false
| false
| 4,672
|
h
|
AKWF_1758.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_1758 256 samples
+-----------------------------------------------------------------------------------------------------------------+
| ** ***** ******** |
| **** ** ** |
| ** **** *** |
| ** ** |
|** ** |
|* *** |
| ** |
| *** ** *|
| ** *** **|
| ** ***** ** ** ** |
| ** *** *** ** *** ********* * |
| ** *** ***** ** **** ******** |
| ***** ** ** |
| ** ** |
| *** *** |
+-----------------------------------------------------------------------------------------------------------------+
*/
const uint16_t AKWF_1758 [] = {
33249, 35452, 37757, 40001, 42160, 44173, 46022, 47635, 49043, 50193, 51126, 51800, 52265, 52496, 52550, 52406,
52130, 51737, 51303, 50849, 50455, 50153, 50003, 50023, 50248, 50677, 51308, 52092, 52903, 53774, 54714, 55666,
56586, 57440, 58212, 58884, 59429, 59857, 60171, 60393, 60534, 60607, 60612, 60547, 60387, 60124, 59750, 59321,
58873, 58453, 58087, 57812, 57642, 57599, 57663, 57827, 58070, 58348, 58627, 58858, 59017, 59066, 59001, 58806,
58516, 58142, 57742, 57342, 57003, 56734, 56575, 56512, 56531, 56522, 56470, 56289, 55977, 55465, 54784, 53918,
52923, 51797, 50694, 50678, 50686, 50149, 49361, 48244, 46970, 45510, 44002, 42434, 40932, 39487, 38165, 36940,
35819, 34741, 33682, 32603, 31483, 30307, 29079, 27813, 26513, 25190, 23850, 22496, 21123, 19742, 18351, 16990,
15676, 14467, 13404, 12536, 11901, 11530, 11406, 11512, 11792, 12171, 12549, 12846, 13118, 13451, 13886, 14450,
15136, 15934, 16816, 17752, 18700, 19611, 20443, 21159, 21730, 22132, 22358, 22401, 22276, 21976, 21524, 20948,
20285, 19575, 18865, 18204, 17634, 17165, 16816, 16571, 16403, 16272, 16121, 15889, 15509, 14947, 14176, 13208,
12047, 10745, 9346, 7915, 6477, 5109, 3832, 2718, 1768, 1037, 497, 166, 9, 36, 217, 551,
1028, 1655, 2436, 3355, 4433, 5627, 6981, 8417, 10002, 11628, 13396, 15168, 17074, 18929, 20894, 22724,
24593, 26190, 27730, 28809, 29837, 29423, 25154, 21883, 20323, 18617, 17379, 17230, 17204, 16696, 16227, 15521,
15188, 16004, 16900, 17429, 17922, 18206, 18460, 18543, 18585, 18489, 18371, 18187, 18037, 17896, 17810, 17749,
17719, 17680, 17618, 17520, 17375, 17200, 17014, 16840, 16680, 16540, 16410, 16260, 16059, 15776, 15405, 14947,
14451, 13973, 13607, 13438, 13555, 14020, 14869, 16114, 17719, 19667, 21875, 24207, 25529, 26993, 28831, 30987,
};
|
58928c78b63aa436ed1bdae1f6f5e9e8923eebaf
|
e7aa99ad96c6e4516be82d4fc041298f5cdc662a
|
/ext/oj/strict.c
|
b592aef4ccfe61ea9660697fa00246e26ab56aa6
|
[
"MIT"
] |
permissive
|
ohler55/oj
|
50ace2672999ba8aacdc77ce9e9f4f8047ac2b27
|
b399b8adf7adc95a4844e73520f2ae24dda5639e
|
refs/heads/develop
| 2023-08-31T14:53:20.780013
| 2023-08-16T23:09:55
| 2023-08-16T23:09:55
| 3,468,618
| 2,294
| 262
|
MIT
| 2023-09-11T10:35:24
| 2012-02-17T09:30:32
|
C
|
UTF-8
|
C
| false
| false
| 5,944
|
c
|
strict.c
|
// Copyright (c) 2012 Peter Ohler. All rights reserved.
// Licensed under the MIT License. See LICENSE file in the project root for license details.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "encode.h"
#include "err.h"
#include "intern.h"
#include "oj.h"
#include "parse.h"
#include "trace.h"
VALUE oj_cstr_to_value(const char *str, size_t len, size_t cache_str) {
volatile VALUE rstr = Qnil;
if (len < cache_str) {
rstr = oj_str_intern(str, len);
} else {
rstr = rb_str_new(str, len);
rstr = oj_encode(rstr);
}
return rstr;
}
VALUE oj_calc_hash_key(ParseInfo pi, Val parent) {
volatile VALUE rkey = parent->key_val;
if (Qundef != rkey) {
return rkey;
}
if (Yes != pi->options.cache_keys) {
if (Yes == pi->options.sym_key) {
rkey = ID2SYM(rb_intern3(parent->key, parent->klen, oj_utf8_encoding));
} else {
rkey = rb_str_new(parent->key, parent->klen);
rkey = oj_encode(rkey);
OBJ_FREEZE(rkey); // frozen when used as a Hash key anyway
}
return rkey;
}
if (Yes == pi->options.sym_key) {
rkey = oj_sym_intern(parent->key, parent->klen);
} else {
rkey = oj_str_intern(parent->key, parent->klen);
}
return rkey;
}
static void hash_end(ParseInfo pi) {
TRACE_PARSE_HASH_END(pi->options.trace, pi);
}
static void array_end(ParseInfo pi) {
TRACE_PARSE_ARRAY_END(pi->options.trace, pi);
}
static VALUE noop_hash_key(ParseInfo pi, const char *key, size_t klen) {
return Qundef;
}
static void add_value(ParseInfo pi, VALUE val) {
TRACE_PARSE_CALL(pi->options.trace, "add_value", pi, val);
pi->stack.head->val = val;
}
static void add_cstr(ParseInfo pi, const char *str, size_t len, const char *orig) {
volatile VALUE rstr = oj_cstr_to_value(str, len, (size_t)pi->options.cache_str);
pi->stack.head->val = rstr;
TRACE_PARSE_CALL(pi->options.trace, "add_string", pi, rstr);
}
static void add_num(ParseInfo pi, NumInfo ni) {
if (ni->infinity || ni->nan) {
oj_set_error_at(pi, oj_parse_error_class, __FILE__, __LINE__, "not a number or other value");
}
pi->stack.head->val = oj_num_as_value(ni);
TRACE_PARSE_CALL(pi->options.trace, "add_number", pi, pi->stack.head->val);
}
static VALUE start_hash(ParseInfo pi) {
if (Qnil != pi->options.hash_class) {
return rb_class_new_instance(0, NULL, pi->options.hash_class);
}
TRACE_PARSE_IN(pi->options.trace, "start_hash", pi);
return rb_hash_new();
}
static void hash_set_cstr(ParseInfo pi, Val parent, const char *str, size_t len, const char *orig) {
volatile VALUE rstr = oj_cstr_to_value(str, len, (size_t)pi->options.cache_str);
rb_hash_aset(stack_peek(&pi->stack)->val, oj_calc_hash_key(pi, parent), rstr);
TRACE_PARSE_CALL(pi->options.trace, "set_string", pi, rstr);
}
static void hash_set_num(ParseInfo pi, Val parent, NumInfo ni) {
volatile VALUE v;
if (ni->infinity || ni->nan) {
oj_set_error_at(pi, oj_parse_error_class, __FILE__, __LINE__, "not a number or other value");
}
v = oj_num_as_value(ni);
rb_hash_aset(stack_peek(&pi->stack)->val, oj_calc_hash_key(pi, parent), v);
TRACE_PARSE_CALL(pi->options.trace, "set_number", pi, v);
}
static void hash_set_value(ParseInfo pi, Val parent, VALUE value) {
rb_hash_aset(stack_peek(&pi->stack)->val, oj_calc_hash_key(pi, parent), value);
TRACE_PARSE_CALL(pi->options.trace, "set_value", pi, value);
}
static VALUE start_array(ParseInfo pi) {
TRACE_PARSE_IN(pi->options.trace, "start_array", pi);
return rb_ary_new();
}
static void array_append_cstr(ParseInfo pi, const char *str, size_t len, const char *orig) {
volatile VALUE rstr = oj_cstr_to_value(str, len, (size_t)pi->options.cache_str);
rb_ary_push(stack_peek(&pi->stack)->val, rstr);
TRACE_PARSE_CALL(pi->options.trace, "append_string", pi, rstr);
}
static void array_append_num(ParseInfo pi, NumInfo ni) {
volatile VALUE v;
if (ni->infinity || ni->nan) {
oj_set_error_at(pi, oj_parse_error_class, __FILE__, __LINE__, "not a number or other value");
}
v = oj_num_as_value(ni);
rb_ary_push(stack_peek(&pi->stack)->val, v);
TRACE_PARSE_CALL(pi->options.trace, "append_number", pi, v);
}
static void array_append_value(ParseInfo pi, VALUE value) {
rb_ary_push(stack_peek(&pi->stack)->val, value);
TRACE_PARSE_CALL(pi->options.trace, "append_value", pi, value);
}
void oj_set_strict_callbacks(ParseInfo pi) {
pi->start_hash = start_hash;
pi->end_hash = hash_end;
pi->hash_key = noop_hash_key;
pi->hash_set_cstr = hash_set_cstr;
pi->hash_set_num = hash_set_num;
pi->hash_set_value = hash_set_value;
pi->start_array = start_array;
pi->end_array = array_end;
pi->array_append_cstr = array_append_cstr;
pi->array_append_num = array_append_num;
pi->array_append_value = array_append_value;
pi->add_cstr = add_cstr;
pi->add_num = add_num;
pi->add_value = add_value;
pi->expect_value = 1;
}
VALUE
oj_strict_parse(int argc, VALUE *argv, VALUE self) {
struct _parseInfo pi;
parse_info_init(&pi);
pi.options = oj_default_options;
pi.handler = Qnil;
pi.err_class = Qnil;
oj_set_strict_callbacks(&pi);
if (T_STRING == rb_type(*argv)) {
return oj_pi_parse(argc, argv, &pi, 0, 0, true);
} else {
return oj_pi_sparse(argc, argv, &pi, 0);
}
}
VALUE
oj_strict_parse_cstr(int argc, VALUE *argv, char *json, size_t len) {
struct _parseInfo pi;
parse_info_init(&pi);
pi.options = oj_default_options;
pi.handler = Qnil;
pi.err_class = Qnil;
oj_set_strict_callbacks(&pi);
return oj_pi_parse(argc, argv, &pi, json, len, true);
}
|
8dbd1a6e6d9a1362a209b85ac83f8157df51c331
|
7fcb614a59a138019b2845a6e493f9d22c44852d
|
/MCUME_teensy/teensyuae/cpu4.c
|
8c0d46c9b41508a59055517c1069d13b8a8d3f4f
|
[] |
no_license
|
Jean-MarcHarvengt/MCUME
|
9180feaf8195c6a0a38eba6c12733c987fa98062
|
fe1280985d9a86bfb2166842a56c8eec768aa666
|
refs/heads/master
| 2023-06-09T23:11:04.216374
| 2023-05-28T15:24:02
| 2023-05-28T15:24:02
| 203,546,040
| 318
| 43
| null | 2023-03-21T13:19:51
| 2019-08-21T08:58:23
|
C
|
UTF-8
|
C
| false
| false
| 75,062
|
c
|
cpu4.c
|
#include "shared.h"
#include "memory.h"
#include "custom.h"
#include "newcpu.h"
#include "cputbl.h"
void op_4000(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ BYTE src = regs.d[srcreg];
{ src += regs.x;
{ULONG dst = ((BYTE)(0)) - ((BYTE)(src));
{ int flgs = ((BYTE)(src)) < 0;
int flgo = ((BYTE)(0)) < 0;
int flgn = ((BYTE)(dst)) < 0;
ZFLG = ((BYTE)(dst)) == 0;
VFLG = (flgs != flgo) && (flgn != flgo);
CFLG = regs.x = ((UBYTE)(src)) > ((UBYTE)(0));
NFLG = flgn != 0;
regs.d[srcreg] &= ~0xff; regs.d[srcreg] |= (dst) & 0xff;
}}}}}}
void op_4010(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ CPTR srca = regs.a[srcreg];
BYTE src = get_byte(srca);
{ src += regs.x;
{ULONG dst = ((BYTE)(0)) - ((BYTE)(src));
{ int flgs = ((BYTE)(src)) < 0;
int flgo = ((BYTE)(0)) < 0;
int flgn = ((BYTE)(dst)) < 0;
ZFLG = ((BYTE)(dst)) == 0;
VFLG = (flgs != flgo) && (flgn != flgo);
CFLG = regs.x = ((UBYTE)(src)) > ((UBYTE)(0));
NFLG = flgn != 0;
put_byte(srca,dst);
}}}}}}
void op_4018(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ CPTR srca = regs.a[srcreg];
BYTE src = get_byte(srca);
{ regs.a[srcreg] += areg_byteinc[srcreg];
{ src += regs.x;
{ULONG dst = ((BYTE)(0)) - ((BYTE)(src));
{ int flgs = ((BYTE)(src)) < 0;
int flgo = ((BYTE)(0)) < 0;
int flgn = ((BYTE)(dst)) < 0;
ZFLG = ((BYTE)(dst)) == 0;
VFLG = (flgs != flgo) && (flgn != flgo);
CFLG = regs.x = ((UBYTE)(src)) > ((UBYTE)(0));
NFLG = flgn != 0;
put_byte(srca,dst);
}}}}}}}
void op_4020(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ regs.a[srcreg] -= areg_byteinc[srcreg];
{ CPTR srca = regs.a[srcreg];
BYTE src = get_byte(srca);
{ src += regs.x;
{ULONG dst = ((BYTE)(0)) - ((BYTE)(src));
{ int flgs = ((BYTE)(src)) < 0;
int flgo = ((BYTE)(0)) < 0;
int flgn = ((BYTE)(dst)) < 0;
ZFLG = ((BYTE)(dst)) == 0;
VFLG = (flgs != flgo) && (flgn != flgo);
CFLG = regs.x = ((UBYTE)(src)) > ((UBYTE)(0));
NFLG = flgn != 0;
put_byte(srca,dst);
}}}}}}}
void op_4028(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ CPTR srca = regs.a[srcreg] + (LONG)(WORD)nextiword();
BYTE src = get_byte(srca);
{ src += regs.x;
{ULONG dst = ((BYTE)(0)) - ((BYTE)(src));
{ int flgs = ((BYTE)(src)) < 0;
int flgo = ((BYTE)(0)) < 0;
int flgn = ((BYTE)(dst)) < 0;
ZFLG = ((BYTE)(dst)) == 0;
VFLG = (flgs != flgo) && (flgn != flgo);
CFLG = regs.x = ((UBYTE)(src)) > ((UBYTE)(0));
NFLG = flgn != 0;
put_byte(srca,dst);
}}}}}}
void op_4030(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ CPTR srca = regs.a[srcreg];
srca = get_disp_ea (srca, nextiword());
{ BYTE src = get_byte(srca);
{ src += regs.x;
{ULONG dst = ((BYTE)(0)) - ((BYTE)(src));
{ int flgs = ((BYTE)(src)) < 0;
int flgo = ((BYTE)(0)) < 0;
int flgn = ((BYTE)(dst)) < 0;
ZFLG = ((BYTE)(dst)) == 0;
VFLG = (flgs != flgo) && (flgn != flgo);
CFLG = regs.x = ((UBYTE)(src)) > ((UBYTE)(0));
NFLG = flgn != 0;
put_byte(srca,dst);
}}}}}}}
void op_4038(ULONG opcode)
{
{{ CPTR srca = (LONG)(WORD)nextiword();
BYTE src = get_byte(srca);
{ src += regs.x;
{ULONG dst = ((BYTE)(0)) - ((BYTE)(src));
{ int flgs = ((BYTE)(src)) < 0;
int flgo = ((BYTE)(0)) < 0;
int flgn = ((BYTE)(dst)) < 0;
ZFLG = ((BYTE)(dst)) == 0;
VFLG = (flgs != flgo) && (flgn != flgo);
CFLG = regs.x = ((UBYTE)(src)) > ((UBYTE)(0));
NFLG = flgn != 0;
put_byte(srca,dst);
}}}}}}
void op_4039(ULONG opcode)
{
{{ CPTR srca = nextilong();
BYTE src = get_byte(srca);
{ src += regs.x;
{ULONG dst = ((BYTE)(0)) - ((BYTE)(src));
{ int flgs = ((BYTE)(src)) < 0;
int flgo = ((BYTE)(0)) < 0;
int flgn = ((BYTE)(dst)) < 0;
ZFLG = ((BYTE)(dst)) == 0;
VFLG = (flgs != flgo) && (flgn != flgo);
CFLG = regs.x = ((UBYTE)(src)) > ((UBYTE)(0));
NFLG = flgn != 0;
put_byte(srca,dst);
}}}}}}
void op_4040(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ WORD src = regs.d[srcreg];
{ src += regs.x;
{ULONG dst = ((WORD)(0)) - ((WORD)(src));
{ int flgs = ((WORD)(src)) < 0;
int flgo = ((WORD)(0)) < 0;
int flgn = ((WORD)(dst)) < 0;
ZFLG = ((WORD)(dst)) == 0;
VFLG = (flgs != flgo) && (flgn != flgo);
CFLG = regs.x = ((UWORD)(src)) > ((UWORD)(0));
NFLG = flgn != 0;
regs.d[srcreg] &= ~0xffff; regs.d[srcreg] |= (dst) & 0xffff;
}}}}}}
void op_4050(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ CPTR srca = regs.a[srcreg];
WORD src = get_word(srca);
{ src += regs.x;
{ULONG dst = ((WORD)(0)) - ((WORD)(src));
{ int flgs = ((WORD)(src)) < 0;
int flgo = ((WORD)(0)) < 0;
int flgn = ((WORD)(dst)) < 0;
ZFLG = ((WORD)(dst)) == 0;
VFLG = (flgs != flgo) && (flgn != flgo);
CFLG = regs.x = ((UWORD)(src)) > ((UWORD)(0));
NFLG = flgn != 0;
put_word(srca,dst);
}}}}}}
void op_4058(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ CPTR srca = regs.a[srcreg];
WORD src = get_word(srca);
{ regs.a[srcreg] += 2;
{ src += regs.x;
{ULONG dst = ((WORD)(0)) - ((WORD)(src));
{ int flgs = ((WORD)(src)) < 0;
int flgo = ((WORD)(0)) < 0;
int flgn = ((WORD)(dst)) < 0;
ZFLG = ((WORD)(dst)) == 0;
VFLG = (flgs != flgo) && (flgn != flgo);
CFLG = regs.x = ((UWORD)(src)) > ((UWORD)(0));
NFLG = flgn != 0;
put_word(srca,dst);
}}}}}}}
void op_4060(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ regs.a[srcreg] -= 2;
{ CPTR srca = regs.a[srcreg];
WORD src = get_word(srca);
{ src += regs.x;
{ULONG dst = ((WORD)(0)) - ((WORD)(src));
{ int flgs = ((WORD)(src)) < 0;
int flgo = ((WORD)(0)) < 0;
int flgn = ((WORD)(dst)) < 0;
ZFLG = ((WORD)(dst)) == 0;
VFLG = (flgs != flgo) && (flgn != flgo);
CFLG = regs.x = ((UWORD)(src)) > ((UWORD)(0));
NFLG = flgn != 0;
put_word(srca,dst);
}}}}}}}
void op_4068(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ CPTR srca = regs.a[srcreg] + (LONG)(WORD)nextiword();
WORD src = get_word(srca);
{ src += regs.x;
{ULONG dst = ((WORD)(0)) - ((WORD)(src));
{ int flgs = ((WORD)(src)) < 0;
int flgo = ((WORD)(0)) < 0;
int flgn = ((WORD)(dst)) < 0;
ZFLG = ((WORD)(dst)) == 0;
VFLG = (flgs != flgo) && (flgn != flgo);
CFLG = regs.x = ((UWORD)(src)) > ((UWORD)(0));
NFLG = flgn != 0;
put_word(srca,dst);
}}}}}}
void op_4070(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ CPTR srca = regs.a[srcreg];
srca = get_disp_ea (srca, nextiword());
{ WORD src = get_word(srca);
{ src += regs.x;
{ULONG dst = ((WORD)(0)) - ((WORD)(src));
{ int flgs = ((WORD)(src)) < 0;
int flgo = ((WORD)(0)) < 0;
int flgn = ((WORD)(dst)) < 0;
ZFLG = ((WORD)(dst)) == 0;
VFLG = (flgs != flgo) && (flgn != flgo);
CFLG = regs.x = ((UWORD)(src)) > ((UWORD)(0));
NFLG = flgn != 0;
put_word(srca,dst);
}}}}}}}
void op_4078(ULONG opcode)
{
{{ CPTR srca = (LONG)(WORD)nextiword();
WORD src = get_word(srca);
{ src += regs.x;
{ULONG dst = ((WORD)(0)) - ((WORD)(src));
{ int flgs = ((WORD)(src)) < 0;
int flgo = ((WORD)(0)) < 0;
int flgn = ((WORD)(dst)) < 0;
ZFLG = ((WORD)(dst)) == 0;
VFLG = (flgs != flgo) && (flgn != flgo);
CFLG = regs.x = ((UWORD)(src)) > ((UWORD)(0));
NFLG = flgn != 0;
put_word(srca,dst);
}}}}}}
void op_4079(ULONG opcode)
{
{{ CPTR srca = nextilong();
WORD src = get_word(srca);
{ src += regs.x;
{ULONG dst = ((WORD)(0)) - ((WORD)(src));
{ int flgs = ((WORD)(src)) < 0;
int flgo = ((WORD)(0)) < 0;
int flgn = ((WORD)(dst)) < 0;
ZFLG = ((WORD)(dst)) == 0;
VFLG = (flgs != flgo) && (flgn != flgo);
CFLG = regs.x = ((UWORD)(src)) > ((UWORD)(0));
NFLG = flgn != 0;
put_word(srca,dst);
}}}}}}
void op_4080(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ LONG src = regs.d[srcreg];
{ src += regs.x;
{ULONG dst = ((LONG)(0)) - ((LONG)(src));
{ int flgs = ((LONG)(src)) < 0;
int flgo = ((LONG)(0)) < 0;
int flgn = ((LONG)(dst)) < 0;
ZFLG = ((LONG)(dst)) == 0;
VFLG = (flgs != flgo) && (flgn != flgo);
CFLG = regs.x = ((ULONG)(src)) > ((ULONG)(0));
NFLG = flgn != 0;
regs.d[srcreg] = (dst);
}}}}}}
void op_4090(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ CPTR srca = regs.a[srcreg];
LONG src = get_long(srca);
{ src += regs.x;
{ULONG dst = ((LONG)(0)) - ((LONG)(src));
{ int flgs = ((LONG)(src)) < 0;
int flgo = ((LONG)(0)) < 0;
int flgn = ((LONG)(dst)) < 0;
ZFLG = ((LONG)(dst)) == 0;
VFLG = (flgs != flgo) && (flgn != flgo);
CFLG = regs.x = ((ULONG)(src)) > ((ULONG)(0));
NFLG = flgn != 0;
put_long(srca,dst);
}}}}}}
void op_4098(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ CPTR srca = regs.a[srcreg];
LONG src = get_long(srca);
{ regs.a[srcreg] += 4;
{ src += regs.x;
{ULONG dst = ((LONG)(0)) - ((LONG)(src));
{ int flgs = ((LONG)(src)) < 0;
int flgo = ((LONG)(0)) < 0;
int flgn = ((LONG)(dst)) < 0;
ZFLG = ((LONG)(dst)) == 0;
VFLG = (flgs != flgo) && (flgn != flgo);
CFLG = regs.x = ((ULONG)(src)) > ((ULONG)(0));
NFLG = flgn != 0;
put_long(srca,dst);
}}}}}}}
void op_40a0(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ regs.a[srcreg] -= 4;
{ CPTR srca = regs.a[srcreg];
LONG src = get_long(srca);
{ src += regs.x;
{ULONG dst = ((LONG)(0)) - ((LONG)(src));
{ int flgs = ((LONG)(src)) < 0;
int flgo = ((LONG)(0)) < 0;
int flgn = ((LONG)(dst)) < 0;
ZFLG = ((LONG)(dst)) == 0;
VFLG = (flgs != flgo) && (flgn != flgo);
CFLG = regs.x = ((ULONG)(src)) > ((ULONG)(0));
NFLG = flgn != 0;
put_long(srca,dst);
}}}}}}}
void op_40a8(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ CPTR srca = regs.a[srcreg] + (LONG)(WORD)nextiword();
LONG src = get_long(srca);
{ src += regs.x;
{ULONG dst = ((LONG)(0)) - ((LONG)(src));
{ int flgs = ((LONG)(src)) < 0;
int flgo = ((LONG)(0)) < 0;
int flgn = ((LONG)(dst)) < 0;
ZFLG = ((LONG)(dst)) == 0;
VFLG = (flgs != flgo) && (flgn != flgo);
CFLG = regs.x = ((ULONG)(src)) > ((ULONG)(0));
NFLG = flgn != 0;
put_long(srca,dst);
}}}}}}
void op_40b0(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ CPTR srca = regs.a[srcreg];
srca = get_disp_ea (srca, nextiword());
{ LONG src = get_long(srca);
{ src += regs.x;
{ULONG dst = ((LONG)(0)) - ((LONG)(src));
{ int flgs = ((LONG)(src)) < 0;
int flgo = ((LONG)(0)) < 0;
int flgn = ((LONG)(dst)) < 0;
ZFLG = ((LONG)(dst)) == 0;
VFLG = (flgs != flgo) && (flgn != flgo);
CFLG = regs.x = ((ULONG)(src)) > ((ULONG)(0));
NFLG = flgn != 0;
put_long(srca,dst);
}}}}}}}
void op_40b8(ULONG opcode)
{
{{ CPTR srca = (LONG)(WORD)nextiword();
LONG src = get_long(srca);
{ src += regs.x;
{ULONG dst = ((LONG)(0)) - ((LONG)(src));
{ int flgs = ((LONG)(src)) < 0;
int flgo = ((LONG)(0)) < 0;
int flgn = ((LONG)(dst)) < 0;
ZFLG = ((LONG)(dst)) == 0;
VFLG = (flgs != flgo) && (flgn != flgo);
CFLG = regs.x = ((ULONG)(src)) > ((ULONG)(0));
NFLG = flgn != 0;
put_long(srca,dst);
}}}}}}
void op_40b9(ULONG opcode)
{
{{ CPTR srca = nextilong();
LONG src = get_long(srca);
{ src += regs.x;
{ULONG dst = ((LONG)(0)) - ((LONG)(src));
{ int flgs = ((LONG)(src)) < 0;
int flgo = ((LONG)(0)) < 0;
int flgn = ((LONG)(dst)) < 0;
ZFLG = ((LONG)(dst)) == 0;
VFLG = (flgs != flgo) && (flgn != flgo);
CFLG = regs.x = ((ULONG)(src)) > ((ULONG)(0));
NFLG = flgn != 0;
put_long(srca,dst);
}}}}}}
void op_40c0(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ MakeSR();
regs.d[srcreg] &= ~0xffff; regs.d[srcreg] |= (regs.sr) & 0xffff;
}}}
void op_40d0(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ CPTR srca = regs.a[srcreg];
MakeSR();
put_word(srca,regs.sr);
}}}
void op_40d8(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ CPTR srca = regs.a[srcreg];
{ regs.a[srcreg] += 2;
MakeSR();
put_word(srca,regs.sr);
}}}}
void op_40e0(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ regs.a[srcreg] -= 2;
{ CPTR srca = regs.a[srcreg];
MakeSR();
put_word(srca,regs.sr);
}}}}
void op_40e8(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ CPTR srca = regs.a[srcreg] + (LONG)(WORD)nextiword();
MakeSR();
put_word(srca,regs.sr);
}}}
void op_40f0(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ CPTR srca = regs.a[srcreg];
srca = get_disp_ea (srca, nextiword());
MakeSR();
put_word(srca,regs.sr);
}}}
void op_40f8(ULONG opcode)
{
{{ CPTR srca = (LONG)(WORD)nextiword();
MakeSR();
put_word(srca,regs.sr);
}}}
void op_40f9(ULONG opcode)
{
{{ CPTR srca = nextilong();
MakeSR();
put_word(srca,regs.sr);
}}}
void op_4180(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
ULONG dstreg = (opcode & 3584) >> 9;
{{ WORD src = regs.d[srcreg];
{ WORD dst = regs.d[dstreg];
if ((WORD)dst < 0) { NFLG=1; Exception(6); }
else if ((WORD)dst > (WORD)src) { NFLG=0; Exception(6); }
}}}}
void op_4188(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
ULONG dstreg = (opcode & 3584) >> 9;
{{ WORD src = regs.a[srcreg];
{ WORD dst = regs.d[dstreg];
if ((WORD)dst < 0) { NFLG=1; Exception(6); }
else if ((WORD)dst > (WORD)src) { NFLG=0; Exception(6); }
}}}}
void op_4190(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
ULONG dstreg = (opcode & 3584) >> 9;
{{ CPTR srca = regs.a[srcreg];
WORD src = get_word(srca);
{ WORD dst = regs.d[dstreg];
if ((WORD)dst < 0) { NFLG=1; Exception(6); }
else if ((WORD)dst > (WORD)src) { NFLG=0; Exception(6); }
}}}}
void op_4198(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
ULONG dstreg = (opcode & 3584) >> 9;
{{ CPTR srca = regs.a[srcreg];
WORD src = get_word(srca);
{ regs.a[srcreg] += 2;
{ WORD dst = regs.d[dstreg];
if ((WORD)dst < 0) { NFLG=1; Exception(6); }
else if ((WORD)dst > (WORD)src) { NFLG=0; Exception(6); }
}}}}}
void op_41a0(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
ULONG dstreg = (opcode & 3584) >> 9;
{{ regs.a[srcreg] -= 2;
{ CPTR srca = regs.a[srcreg];
WORD src = get_word(srca);
{ WORD dst = regs.d[dstreg];
if ((WORD)dst < 0) { NFLG=1; Exception(6); }
else if ((WORD)dst > (WORD)src) { NFLG=0; Exception(6); }
}}}}}
void op_41a8(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
ULONG dstreg = (opcode & 3584) >> 9;
{{ CPTR srca = regs.a[srcreg] + (LONG)(WORD)nextiword();
WORD src = get_word(srca);
{ WORD dst = regs.d[dstreg];
if ((WORD)dst < 0) { NFLG=1; Exception(6); }
else if ((WORD)dst > (WORD)src) { NFLG=0; Exception(6); }
}}}}
void op_41b0(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
ULONG dstreg = (opcode & 3584) >> 9;
{{ CPTR srca = regs.a[srcreg];
srca = get_disp_ea (srca, nextiword());
{ WORD src = get_word(srca);
{ WORD dst = regs.d[dstreg];
if ((WORD)dst < 0) { NFLG=1; Exception(6); }
else if ((WORD)dst > (WORD)src) { NFLG=0; Exception(6); }
}}}}}
void op_41b8(ULONG opcode)
{
ULONG dstreg = (opcode & 3584) >> 9;
{{ CPTR srca = (LONG)(WORD)nextiword();
WORD src = get_word(srca);
{ WORD dst = regs.d[dstreg];
if ((WORD)dst < 0) { NFLG=1; Exception(6); }
else if ((WORD)dst > (WORD)src) { NFLG=0; Exception(6); }
}}}}
void op_41b9(ULONG opcode)
{
ULONG dstreg = (opcode & 3584) >> 9;
{{ CPTR srca = nextilong();
WORD src = get_word(srca);
{ WORD dst = regs.d[dstreg];
if ((WORD)dst < 0) { NFLG=1; Exception(6); }
else if ((WORD)dst > (WORD)src) { NFLG=0; Exception(6); }
}}}}
void op_41ba(ULONG opcode)
{
ULONG dstreg = (opcode & 3584) >> 9;
{{ CPTR srca = m68k_getpc();
srca += (LONG)(WORD)nextiword();
{ WORD src = get_word(srca);
{ WORD dst = regs.d[dstreg];
if ((WORD)dst < 0) { NFLG=1; Exception(6); }
else if ((WORD)dst > (WORD)src) { NFLG=0; Exception(6); }
}}}}}
void op_41bb(ULONG opcode)
{
ULONG dstreg = (opcode & 3584) >> 9;
{{ CPTR srca = m68k_getpc();
srca = get_disp_ea (srca, nextiword());
{ WORD src = get_word(srca);
{ WORD dst = regs.d[dstreg];
if ((WORD)dst < 0) { NFLG=1; Exception(6); }
else if ((WORD)dst > (WORD)src) { NFLG=0; Exception(6); }
}}}}}
void op_41bc(ULONG opcode)
{
ULONG dstreg = (opcode & 3584) >> 9;
{{ WORD src = nextiword();
{ WORD dst = regs.d[dstreg];
if ((WORD)dst < 0) { NFLG=1; Exception(6); }
else if ((WORD)dst > (WORD)src) { NFLG=0; Exception(6); }
}}}}
void op_41d0(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
ULONG dstreg = (opcode & 3584) >> 9;
{{ CPTR srca = regs.a[srcreg];
{ regs.a[dstreg] = (srca);
}}}}
void op_41d8(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
ULONG dstreg = (opcode & 3584) >> 9;
{{ CPTR srca = regs.a[srcreg];
{ regs.a[srcreg] += 4;
{ regs.a[dstreg] = (srca);
}}}}}
void op_41e0(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
ULONG dstreg = (opcode & 3584) >> 9;
{{ regs.a[srcreg] -= 4;
{ CPTR srca = regs.a[srcreg];
{ regs.a[dstreg] = (srca);
}}}}}
void op_41e8(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
ULONG dstreg = (opcode & 3584) >> 9;
{{ CPTR srca = regs.a[srcreg] + (LONG)(WORD)nextiword();
{ regs.a[dstreg] = (srca);
}}}}
void op_41f0(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
ULONG dstreg = (opcode & 3584) >> 9;
{{ CPTR srca = regs.a[srcreg];
srca = get_disp_ea (srca, nextiword());
{ regs.a[dstreg] = (srca);
}}}}
void op_41f8(ULONG opcode)
{
ULONG dstreg = (opcode & 3584) >> 9;
{{ CPTR srca = (LONG)(WORD)nextiword();
{ regs.a[dstreg] = (srca);
}}}}
void op_41f9(ULONG opcode)
{
ULONG dstreg = (opcode & 3584) >> 9;
{{ CPTR srca = nextilong();
{ regs.a[dstreg] = (srca);
}}}}
void op_41fa(ULONG opcode)
{
ULONG dstreg = (opcode & 3584) >> 9;
{{ CPTR srca = m68k_getpc();
srca += (LONG)(WORD)nextiword();
{ regs.a[dstreg] = (srca);
}}}}
void op_41fb(ULONG opcode)
{
ULONG dstreg = (opcode & 3584) >> 9;
{{ CPTR srca = m68k_getpc();
srca = get_disp_ea (srca, nextiword());
{ regs.a[dstreg] = (srca);
}}}}
void op_4200(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ VFLG = CFLG = 0;
ZFLG = ((BYTE)(0)) == 0;
NFLG = ((BYTE)(0)) < 0;
regs.d[srcreg] &= ~0xff; regs.d[srcreg] |= (0) & 0xff;
}}}
void op_4210(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ CPTR srca = regs.a[srcreg];
VFLG = CFLG = 0;
ZFLG = ((BYTE)(0)) == 0;
NFLG = ((BYTE)(0)) < 0;
put_byte(srca,0);
}}}
void op_4218(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ CPTR srca = regs.a[srcreg];
{ regs.a[srcreg] += areg_byteinc[srcreg];
VFLG = CFLG = 0;
ZFLG = ((BYTE)(0)) == 0;
NFLG = ((BYTE)(0)) < 0;
put_byte(srca,0);
}}}}
void op_4220(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ regs.a[srcreg] -= areg_byteinc[srcreg];
{ CPTR srca = regs.a[srcreg];
VFLG = CFLG = 0;
ZFLG = ((BYTE)(0)) == 0;
NFLG = ((BYTE)(0)) < 0;
put_byte(srca,0);
}}}}
void op_4228(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ CPTR srca = regs.a[srcreg] + (LONG)(WORD)nextiword();
VFLG = CFLG = 0;
ZFLG = ((BYTE)(0)) == 0;
NFLG = ((BYTE)(0)) < 0;
put_byte(srca,0);
}}}
void op_4230(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ CPTR srca = regs.a[srcreg];
srca = get_disp_ea (srca, nextiword());
VFLG = CFLG = 0;
ZFLG = ((BYTE)(0)) == 0;
NFLG = ((BYTE)(0)) < 0;
put_byte(srca,0);
}}}
void op_4238(ULONG opcode)
{
{{ CPTR srca = (LONG)(WORD)nextiword();
VFLG = CFLG = 0;
ZFLG = ((BYTE)(0)) == 0;
NFLG = ((BYTE)(0)) < 0;
put_byte(srca,0);
}}}
void op_4239(ULONG opcode)
{
{{ CPTR srca = nextilong();
VFLG = CFLG = 0;
ZFLG = ((BYTE)(0)) == 0;
NFLG = ((BYTE)(0)) < 0;
put_byte(srca,0);
}}}
void op_4240(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ VFLG = CFLG = 0;
ZFLG = ((WORD)(0)) == 0;
NFLG = ((WORD)(0)) < 0;
regs.d[srcreg] &= ~0xffff; regs.d[srcreg] |= (0) & 0xffff;
}}}
void op_4250(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ CPTR srca = regs.a[srcreg];
VFLG = CFLG = 0;
ZFLG = ((WORD)(0)) == 0;
NFLG = ((WORD)(0)) < 0;
put_word(srca,0);
}}}
void op_4258(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ CPTR srca = regs.a[srcreg];
{ regs.a[srcreg] += 2;
VFLG = CFLG = 0;
ZFLG = ((WORD)(0)) == 0;
NFLG = ((WORD)(0)) < 0;
put_word(srca,0);
}}}}
void op_4260(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ regs.a[srcreg] -= 2;
{ CPTR srca = regs.a[srcreg];
VFLG = CFLG = 0;
ZFLG = ((WORD)(0)) == 0;
NFLG = ((WORD)(0)) < 0;
put_word(srca,0);
}}}}
void op_4268(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ CPTR srca = regs.a[srcreg] + (LONG)(WORD)nextiword();
VFLG = CFLG = 0;
ZFLG = ((WORD)(0)) == 0;
NFLG = ((WORD)(0)) < 0;
put_word(srca,0);
}}}
void op_4270(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ CPTR srca = regs.a[srcreg];
srca = get_disp_ea (srca, nextiword());
VFLG = CFLG = 0;
ZFLG = ((WORD)(0)) == 0;
NFLG = ((WORD)(0)) < 0;
put_word(srca,0);
}}}
void op_4278(ULONG opcode)
{
{{ CPTR srca = (LONG)(WORD)nextiword();
VFLG = CFLG = 0;
ZFLG = ((WORD)(0)) == 0;
NFLG = ((WORD)(0)) < 0;
put_word(srca,0);
}}}
void op_4279(ULONG opcode)
{
{{ CPTR srca = nextilong();
VFLG = CFLG = 0;
ZFLG = ((WORD)(0)) == 0;
NFLG = ((WORD)(0)) < 0;
put_word(srca,0);
}}}
void op_4280(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ VFLG = CFLG = 0;
ZFLG = ((LONG)(0)) == 0;
NFLG = ((LONG)(0)) < 0;
regs.d[srcreg] = (0);
}}}
void op_4290(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ CPTR srca = regs.a[srcreg];
VFLG = CFLG = 0;
ZFLG = ((LONG)(0)) == 0;
NFLG = ((LONG)(0)) < 0;
put_long(srca,0);
}}}
void op_4298(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ CPTR srca = regs.a[srcreg];
{ regs.a[srcreg] += 4;
VFLG = CFLG = 0;
ZFLG = ((LONG)(0)) == 0;
NFLG = ((LONG)(0)) < 0;
put_long(srca,0);
}}}}
void op_42a0(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ regs.a[srcreg] -= 4;
{ CPTR srca = regs.a[srcreg];
VFLG = CFLG = 0;
ZFLG = ((LONG)(0)) == 0;
NFLG = ((LONG)(0)) < 0;
put_long(srca,0);
}}}}
void op_42a8(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ CPTR srca = regs.a[srcreg] + (LONG)(WORD)nextiword();
VFLG = CFLG = 0;
ZFLG = ((LONG)(0)) == 0;
NFLG = ((LONG)(0)) < 0;
put_long(srca,0);
}}}
void op_42b0(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ CPTR srca = regs.a[srcreg];
srca = get_disp_ea (srca, nextiword());
VFLG = CFLG = 0;
ZFLG = ((LONG)(0)) == 0;
NFLG = ((LONG)(0)) < 0;
put_long(srca,0);
}}}
void op_42b8(ULONG opcode)
{
{{ CPTR srca = (LONG)(WORD)nextiword();
VFLG = CFLG = 0;
ZFLG = ((LONG)(0)) == 0;
NFLG = ((LONG)(0)) < 0;
put_long(srca,0);
}}}
void op_42b9(ULONG opcode)
{
{{ CPTR srca = nextilong();
VFLG = CFLG = 0;
ZFLG = ((LONG)(0)) == 0;
NFLG = ((LONG)(0)) < 0;
put_long(srca,0);
}}}
void op_4400(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ BYTE src = regs.d[srcreg];
{{ULONG dst = ((BYTE)(0)) - ((BYTE)(src));
{ int flgs = ((BYTE)(src)) < 0;
int flgo = ((BYTE)(0)) < 0;
int flgn = ((BYTE)(dst)) < 0;
ZFLG = ((BYTE)(dst)) == 0;
VFLG = (flgs != flgo) && (flgn != flgo);
CFLG = regs.x = ((UBYTE)(src)) > ((UBYTE)(0));
NFLG = flgn != 0;
regs.d[srcreg] &= ~0xff; regs.d[srcreg] |= (dst) & 0xff;
}}}}}}
void op_4410(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ CPTR srca = regs.a[srcreg];
BYTE src = get_byte(srca);
{{ULONG dst = ((BYTE)(0)) - ((BYTE)(src));
{ int flgs = ((BYTE)(src)) < 0;
int flgo = ((BYTE)(0)) < 0;
int flgn = ((BYTE)(dst)) < 0;
ZFLG = ((BYTE)(dst)) == 0;
VFLG = (flgs != flgo) && (flgn != flgo);
CFLG = regs.x = ((UBYTE)(src)) > ((UBYTE)(0));
NFLG = flgn != 0;
put_byte(srca,dst);
}}}}}}
void op_4418(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ CPTR srca = regs.a[srcreg];
BYTE src = get_byte(srca);
{ regs.a[srcreg] += areg_byteinc[srcreg];
{{ULONG dst = ((BYTE)(0)) - ((BYTE)(src));
{ int flgs = ((BYTE)(src)) < 0;
int flgo = ((BYTE)(0)) < 0;
int flgn = ((BYTE)(dst)) < 0;
ZFLG = ((BYTE)(dst)) == 0;
VFLG = (flgs != flgo) && (flgn != flgo);
CFLG = regs.x = ((UBYTE)(src)) > ((UBYTE)(0));
NFLG = flgn != 0;
put_byte(srca,dst);
}}}}}}}
void op_4420(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ regs.a[srcreg] -= areg_byteinc[srcreg];
{ CPTR srca = regs.a[srcreg];
BYTE src = get_byte(srca);
{{ULONG dst = ((BYTE)(0)) - ((BYTE)(src));
{ int flgs = ((BYTE)(src)) < 0;
int flgo = ((BYTE)(0)) < 0;
int flgn = ((BYTE)(dst)) < 0;
ZFLG = ((BYTE)(dst)) == 0;
VFLG = (flgs != flgo) && (flgn != flgo);
CFLG = regs.x = ((UBYTE)(src)) > ((UBYTE)(0));
NFLG = flgn != 0;
put_byte(srca,dst);
}}}}}}}
void op_4428(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ CPTR srca = regs.a[srcreg] + (LONG)(WORD)nextiword();
BYTE src = get_byte(srca);
{{ULONG dst = ((BYTE)(0)) - ((BYTE)(src));
{ int flgs = ((BYTE)(src)) < 0;
int flgo = ((BYTE)(0)) < 0;
int flgn = ((BYTE)(dst)) < 0;
ZFLG = ((BYTE)(dst)) == 0;
VFLG = (flgs != flgo) && (flgn != flgo);
CFLG = regs.x = ((UBYTE)(src)) > ((UBYTE)(0));
NFLG = flgn != 0;
put_byte(srca,dst);
}}}}}}
void op_4430(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ CPTR srca = regs.a[srcreg];
srca = get_disp_ea (srca, nextiword());
{ BYTE src = get_byte(srca);
{{ULONG dst = ((BYTE)(0)) - ((BYTE)(src));
{ int flgs = ((BYTE)(src)) < 0;
int flgo = ((BYTE)(0)) < 0;
int flgn = ((BYTE)(dst)) < 0;
ZFLG = ((BYTE)(dst)) == 0;
VFLG = (flgs != flgo) && (flgn != flgo);
CFLG = regs.x = ((UBYTE)(src)) > ((UBYTE)(0));
NFLG = flgn != 0;
put_byte(srca,dst);
}}}}}}}
void op_4438(ULONG opcode)
{
{{ CPTR srca = (LONG)(WORD)nextiword();
BYTE src = get_byte(srca);
{{ULONG dst = ((BYTE)(0)) - ((BYTE)(src));
{ int flgs = ((BYTE)(src)) < 0;
int flgo = ((BYTE)(0)) < 0;
int flgn = ((BYTE)(dst)) < 0;
ZFLG = ((BYTE)(dst)) == 0;
VFLG = (flgs != flgo) && (flgn != flgo);
CFLG = regs.x = ((UBYTE)(src)) > ((UBYTE)(0));
NFLG = flgn != 0;
put_byte(srca,dst);
}}}}}}
void op_4439(ULONG opcode)
{
{{ CPTR srca = nextilong();
BYTE src = get_byte(srca);
{{ULONG dst = ((BYTE)(0)) - ((BYTE)(src));
{ int flgs = ((BYTE)(src)) < 0;
int flgo = ((BYTE)(0)) < 0;
int flgn = ((BYTE)(dst)) < 0;
ZFLG = ((BYTE)(dst)) == 0;
VFLG = (flgs != flgo) && (flgn != flgo);
CFLG = regs.x = ((UBYTE)(src)) > ((UBYTE)(0));
NFLG = flgn != 0;
put_byte(srca,dst);
}}}}}}
void op_4440(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ WORD src = regs.d[srcreg];
{{ULONG dst = ((WORD)(0)) - ((WORD)(src));
{ int flgs = ((WORD)(src)) < 0;
int flgo = ((WORD)(0)) < 0;
int flgn = ((WORD)(dst)) < 0;
ZFLG = ((WORD)(dst)) == 0;
VFLG = (flgs != flgo) && (flgn != flgo);
CFLG = regs.x = ((UWORD)(src)) > ((UWORD)(0));
NFLG = flgn != 0;
regs.d[srcreg] &= ~0xffff; regs.d[srcreg] |= (dst) & 0xffff;
}}}}}}
void op_4450(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ CPTR srca = regs.a[srcreg];
WORD src = get_word(srca);
{{ULONG dst = ((WORD)(0)) - ((WORD)(src));
{ int flgs = ((WORD)(src)) < 0;
int flgo = ((WORD)(0)) < 0;
int flgn = ((WORD)(dst)) < 0;
ZFLG = ((WORD)(dst)) == 0;
VFLG = (flgs != flgo) && (flgn != flgo);
CFLG = regs.x = ((UWORD)(src)) > ((UWORD)(0));
NFLG = flgn != 0;
put_word(srca,dst);
}}}}}}
void op_4458(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ CPTR srca = regs.a[srcreg];
WORD src = get_word(srca);
{ regs.a[srcreg] += 2;
{{ULONG dst = ((WORD)(0)) - ((WORD)(src));
{ int flgs = ((WORD)(src)) < 0;
int flgo = ((WORD)(0)) < 0;
int flgn = ((WORD)(dst)) < 0;
ZFLG = ((WORD)(dst)) == 0;
VFLG = (flgs != flgo) && (flgn != flgo);
CFLG = regs.x = ((UWORD)(src)) > ((UWORD)(0));
NFLG = flgn != 0;
put_word(srca,dst);
}}}}}}}
void op_4460(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ regs.a[srcreg] -= 2;
{ CPTR srca = regs.a[srcreg];
WORD src = get_word(srca);
{{ULONG dst = ((WORD)(0)) - ((WORD)(src));
{ int flgs = ((WORD)(src)) < 0;
int flgo = ((WORD)(0)) < 0;
int flgn = ((WORD)(dst)) < 0;
ZFLG = ((WORD)(dst)) == 0;
VFLG = (flgs != flgo) && (flgn != flgo);
CFLG = regs.x = ((UWORD)(src)) > ((UWORD)(0));
NFLG = flgn != 0;
put_word(srca,dst);
}}}}}}}
void op_4468(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ CPTR srca = regs.a[srcreg] + (LONG)(WORD)nextiword();
WORD src = get_word(srca);
{{ULONG dst = ((WORD)(0)) - ((WORD)(src));
{ int flgs = ((WORD)(src)) < 0;
int flgo = ((WORD)(0)) < 0;
int flgn = ((WORD)(dst)) < 0;
ZFLG = ((WORD)(dst)) == 0;
VFLG = (flgs != flgo) && (flgn != flgo);
CFLG = regs.x = ((UWORD)(src)) > ((UWORD)(0));
NFLG = flgn != 0;
put_word(srca,dst);
}}}}}}
void op_4470(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ CPTR srca = regs.a[srcreg];
srca = get_disp_ea (srca, nextiword());
{ WORD src = get_word(srca);
{{ULONG dst = ((WORD)(0)) - ((WORD)(src));
{ int flgs = ((WORD)(src)) < 0;
int flgo = ((WORD)(0)) < 0;
int flgn = ((WORD)(dst)) < 0;
ZFLG = ((WORD)(dst)) == 0;
VFLG = (flgs != flgo) && (flgn != flgo);
CFLG = regs.x = ((UWORD)(src)) > ((UWORD)(0));
NFLG = flgn != 0;
put_word(srca,dst);
}}}}}}}
void op_4478(ULONG opcode)
{
{{ CPTR srca = (LONG)(WORD)nextiword();
WORD src = get_word(srca);
{{ULONG dst = ((WORD)(0)) - ((WORD)(src));
{ int flgs = ((WORD)(src)) < 0;
int flgo = ((WORD)(0)) < 0;
int flgn = ((WORD)(dst)) < 0;
ZFLG = ((WORD)(dst)) == 0;
VFLG = (flgs != flgo) && (flgn != flgo);
CFLG = regs.x = ((UWORD)(src)) > ((UWORD)(0));
NFLG = flgn != 0;
put_word(srca,dst);
}}}}}}
void op_4479(ULONG opcode)
{
{{ CPTR srca = nextilong();
WORD src = get_word(srca);
{{ULONG dst = ((WORD)(0)) - ((WORD)(src));
{ int flgs = ((WORD)(src)) < 0;
int flgo = ((WORD)(0)) < 0;
int flgn = ((WORD)(dst)) < 0;
ZFLG = ((WORD)(dst)) == 0;
VFLG = (flgs != flgo) && (flgn != flgo);
CFLG = regs.x = ((UWORD)(src)) > ((UWORD)(0));
NFLG = flgn != 0;
put_word(srca,dst);
}}}}}}
void op_4480(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ LONG src = regs.d[srcreg];
{{ULONG dst = ((LONG)(0)) - ((LONG)(src));
{ int flgs = ((LONG)(src)) < 0;
int flgo = ((LONG)(0)) < 0;
int flgn = ((LONG)(dst)) < 0;
ZFLG = ((LONG)(dst)) == 0;
VFLG = (flgs != flgo) && (flgn != flgo);
CFLG = regs.x = ((ULONG)(src)) > ((ULONG)(0));
NFLG = flgn != 0;
regs.d[srcreg] = (dst);
}}}}}}
void op_4490(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ CPTR srca = regs.a[srcreg];
LONG src = get_long(srca);
{{ULONG dst = ((LONG)(0)) - ((LONG)(src));
{ int flgs = ((LONG)(src)) < 0;
int flgo = ((LONG)(0)) < 0;
int flgn = ((LONG)(dst)) < 0;
ZFLG = ((LONG)(dst)) == 0;
VFLG = (flgs != flgo) && (flgn != flgo);
CFLG = regs.x = ((ULONG)(src)) > ((ULONG)(0));
NFLG = flgn != 0;
put_long(srca,dst);
}}}}}}
void op_4498(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ CPTR srca = regs.a[srcreg];
LONG src = get_long(srca);
{ regs.a[srcreg] += 4;
{{ULONG dst = ((LONG)(0)) - ((LONG)(src));
{ int flgs = ((LONG)(src)) < 0;
int flgo = ((LONG)(0)) < 0;
int flgn = ((LONG)(dst)) < 0;
ZFLG = ((LONG)(dst)) == 0;
VFLG = (flgs != flgo) && (flgn != flgo);
CFLG = regs.x = ((ULONG)(src)) > ((ULONG)(0));
NFLG = flgn != 0;
put_long(srca,dst);
}}}}}}}
void op_44a0(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ regs.a[srcreg] -= 4;
{ CPTR srca = regs.a[srcreg];
LONG src = get_long(srca);
{{ULONG dst = ((LONG)(0)) - ((LONG)(src));
{ int flgs = ((LONG)(src)) < 0;
int flgo = ((LONG)(0)) < 0;
int flgn = ((LONG)(dst)) < 0;
ZFLG = ((LONG)(dst)) == 0;
VFLG = (flgs != flgo) && (flgn != flgo);
CFLG = regs.x = ((ULONG)(src)) > ((ULONG)(0));
NFLG = flgn != 0;
put_long(srca,dst);
}}}}}}}
void op_44a8(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ CPTR srca = regs.a[srcreg] + (LONG)(WORD)nextiword();
LONG src = get_long(srca);
{{ULONG dst = ((LONG)(0)) - ((LONG)(src));
{ int flgs = ((LONG)(src)) < 0;
int flgo = ((LONG)(0)) < 0;
int flgn = ((LONG)(dst)) < 0;
ZFLG = ((LONG)(dst)) == 0;
VFLG = (flgs != flgo) && (flgn != flgo);
CFLG = regs.x = ((ULONG)(src)) > ((ULONG)(0));
NFLG = flgn != 0;
put_long(srca,dst);
}}}}}}
void op_44b0(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ CPTR srca = regs.a[srcreg];
srca = get_disp_ea (srca, nextiword());
{ LONG src = get_long(srca);
{{ULONG dst = ((LONG)(0)) - ((LONG)(src));
{ int flgs = ((LONG)(src)) < 0;
int flgo = ((LONG)(0)) < 0;
int flgn = ((LONG)(dst)) < 0;
ZFLG = ((LONG)(dst)) == 0;
VFLG = (flgs != flgo) && (flgn != flgo);
CFLG = regs.x = ((ULONG)(src)) > ((ULONG)(0));
NFLG = flgn != 0;
put_long(srca,dst);
}}}}}}}
void op_44b8(ULONG opcode)
{
{{ CPTR srca = (LONG)(WORD)nextiword();
LONG src = get_long(srca);
{{ULONG dst = ((LONG)(0)) - ((LONG)(src));
{ int flgs = ((LONG)(src)) < 0;
int flgo = ((LONG)(0)) < 0;
int flgn = ((LONG)(dst)) < 0;
ZFLG = ((LONG)(dst)) == 0;
VFLG = (flgs != flgo) && (flgn != flgo);
CFLG = regs.x = ((ULONG)(src)) > ((ULONG)(0));
NFLG = flgn != 0;
put_long(srca,dst);
}}}}}}
void op_44b9(ULONG opcode)
{
{{ CPTR srca = nextilong();
LONG src = get_long(srca);
{{ULONG dst = ((LONG)(0)) - ((LONG)(src));
{ int flgs = ((LONG)(src)) < 0;
int flgo = ((LONG)(0)) < 0;
int flgn = ((LONG)(dst)) < 0;
ZFLG = ((LONG)(dst)) == 0;
VFLG = (flgs != flgo) && (flgn != flgo);
CFLG = regs.x = ((ULONG)(src)) > ((ULONG)(0));
NFLG = flgn != 0;
put_long(srca,dst);
}}}}}}
void op_44c0(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ BYTE src = regs.d[srcreg];
MakeSR();
regs.sr &= 0xFF00;
regs.sr |= src & 0xFF;
MakeFromSR();
}}}
void op_44d0(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ CPTR srca = regs.a[srcreg];
BYTE src = get_byte(srca);
MakeSR();
regs.sr &= 0xFF00;
regs.sr |= src & 0xFF;
MakeFromSR();
}}}
void op_44d8(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ CPTR srca = regs.a[srcreg];
BYTE src = get_byte(srca);
{ regs.a[srcreg] += areg_byteinc[srcreg];
MakeSR();
regs.sr &= 0xFF00;
regs.sr |= src & 0xFF;
MakeFromSR();
}}}}
void op_44e0(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ regs.a[srcreg] -= areg_byteinc[srcreg];
{ CPTR srca = regs.a[srcreg];
BYTE src = get_byte(srca);
MakeSR();
regs.sr &= 0xFF00;
regs.sr |= src & 0xFF;
MakeFromSR();
}}}}
void op_44e8(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ CPTR srca = regs.a[srcreg] + (LONG)(WORD)nextiword();
BYTE src = get_byte(srca);
MakeSR();
regs.sr &= 0xFF00;
regs.sr |= src & 0xFF;
MakeFromSR();
}}}
void op_44f0(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ CPTR srca = regs.a[srcreg];
srca = get_disp_ea (srca, nextiword());
{ BYTE src = get_byte(srca);
MakeSR();
regs.sr &= 0xFF00;
regs.sr |= src & 0xFF;
MakeFromSR();
}}}}
void op_44f8(ULONG opcode)
{
{{ CPTR srca = (LONG)(WORD)nextiword();
BYTE src = get_byte(srca);
MakeSR();
regs.sr &= 0xFF00;
regs.sr |= src & 0xFF;
MakeFromSR();
}}}
void op_44f9(ULONG opcode)
{
{{ CPTR srca = nextilong();
BYTE src = get_byte(srca);
MakeSR();
regs.sr &= 0xFF00;
regs.sr |= src & 0xFF;
MakeFromSR();
}}}
void op_44fa(ULONG opcode)
{
{{ CPTR srca = m68k_getpc();
srca += (LONG)(WORD)nextiword();
{ BYTE src = get_byte(srca);
MakeSR();
regs.sr &= 0xFF00;
regs.sr |= src & 0xFF;
MakeFromSR();
}}}}
void op_44fb(ULONG opcode)
{
{{ CPTR srca = m68k_getpc();
srca = get_disp_ea (srca, nextiword());
{ BYTE src = get_byte(srca);
MakeSR();
regs.sr &= 0xFF00;
regs.sr |= src & 0xFF;
MakeFromSR();
}}}}
void op_44fc(ULONG opcode)
{
{{ BYTE src = nextiword();
MakeSR();
regs.sr &= 0xFF00;
regs.sr |= src & 0xFF;
MakeFromSR();
}}}
void op_4600(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ BYTE src = regs.d[srcreg];
{ ULONG dst = ~src;
VFLG = CFLG = 0;
ZFLG = ((BYTE)(dst)) == 0;
NFLG = ((BYTE)(dst)) < 0;
regs.d[srcreg] &= ~0xff; regs.d[srcreg] |= (dst) & 0xff;
}}}}
void op_4610(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ CPTR srca = regs.a[srcreg];
BYTE src = get_byte(srca);
{ ULONG dst = ~src;
VFLG = CFLG = 0;
ZFLG = ((BYTE)(dst)) == 0;
NFLG = ((BYTE)(dst)) < 0;
put_byte(srca,dst);
}}}}
void op_4618(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ CPTR srca = regs.a[srcreg];
BYTE src = get_byte(srca);
{ regs.a[srcreg] += areg_byteinc[srcreg];
{ ULONG dst = ~src;
VFLG = CFLG = 0;
ZFLG = ((BYTE)(dst)) == 0;
NFLG = ((BYTE)(dst)) < 0;
put_byte(srca,dst);
}}}}}
void op_4620(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ regs.a[srcreg] -= areg_byteinc[srcreg];
{ CPTR srca = regs.a[srcreg];
BYTE src = get_byte(srca);
{ ULONG dst = ~src;
VFLG = CFLG = 0;
ZFLG = ((BYTE)(dst)) == 0;
NFLG = ((BYTE)(dst)) < 0;
put_byte(srca,dst);
}}}}}
void op_4628(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ CPTR srca = regs.a[srcreg] + (LONG)(WORD)nextiword();
BYTE src = get_byte(srca);
{ ULONG dst = ~src;
VFLG = CFLG = 0;
ZFLG = ((BYTE)(dst)) == 0;
NFLG = ((BYTE)(dst)) < 0;
put_byte(srca,dst);
}}}}
void op_4630(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ CPTR srca = regs.a[srcreg];
srca = get_disp_ea (srca, nextiword());
{ BYTE src = get_byte(srca);
{ ULONG dst = ~src;
VFLG = CFLG = 0;
ZFLG = ((BYTE)(dst)) == 0;
NFLG = ((BYTE)(dst)) < 0;
put_byte(srca,dst);
}}}}}
void op_4638(ULONG opcode)
{
{{ CPTR srca = (LONG)(WORD)nextiword();
BYTE src = get_byte(srca);
{ ULONG dst = ~src;
VFLG = CFLG = 0;
ZFLG = ((BYTE)(dst)) == 0;
NFLG = ((BYTE)(dst)) < 0;
put_byte(srca,dst);
}}}}
void op_4639(ULONG opcode)
{
{{ CPTR srca = nextilong();
BYTE src = get_byte(srca);
{ ULONG dst = ~src;
VFLG = CFLG = 0;
ZFLG = ((BYTE)(dst)) == 0;
NFLG = ((BYTE)(dst)) < 0;
put_byte(srca,dst);
}}}}
void op_4640(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ WORD src = regs.d[srcreg];
{ ULONG dst = ~src;
VFLG = CFLG = 0;
ZFLG = ((WORD)(dst)) == 0;
NFLG = ((WORD)(dst)) < 0;
regs.d[srcreg] &= ~0xffff; regs.d[srcreg] |= (dst) & 0xffff;
}}}}
void op_4650(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ CPTR srca = regs.a[srcreg];
WORD src = get_word(srca);
{ ULONG dst = ~src;
VFLG = CFLG = 0;
ZFLG = ((WORD)(dst)) == 0;
NFLG = ((WORD)(dst)) < 0;
put_word(srca,dst);
}}}}
void op_4658(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ CPTR srca = regs.a[srcreg];
WORD src = get_word(srca);
{ regs.a[srcreg] += 2;
{ ULONG dst = ~src;
VFLG = CFLG = 0;
ZFLG = ((WORD)(dst)) == 0;
NFLG = ((WORD)(dst)) < 0;
put_word(srca,dst);
}}}}}
void op_4660(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ regs.a[srcreg] -= 2;
{ CPTR srca = regs.a[srcreg];
WORD src = get_word(srca);
{ ULONG dst = ~src;
VFLG = CFLG = 0;
ZFLG = ((WORD)(dst)) == 0;
NFLG = ((WORD)(dst)) < 0;
put_word(srca,dst);
}}}}}
void op_4668(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ CPTR srca = regs.a[srcreg] + (LONG)(WORD)nextiword();
WORD src = get_word(srca);
{ ULONG dst = ~src;
VFLG = CFLG = 0;
ZFLG = ((WORD)(dst)) == 0;
NFLG = ((WORD)(dst)) < 0;
put_word(srca,dst);
}}}}
void op_4670(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ CPTR srca = regs.a[srcreg];
srca = get_disp_ea (srca, nextiword());
{ WORD src = get_word(srca);
{ ULONG dst = ~src;
VFLG = CFLG = 0;
ZFLG = ((WORD)(dst)) == 0;
NFLG = ((WORD)(dst)) < 0;
put_word(srca,dst);
}}}}}
void op_4678(ULONG opcode)
{
{{ CPTR srca = (LONG)(WORD)nextiword();
WORD src = get_word(srca);
{ ULONG dst = ~src;
VFLG = CFLG = 0;
ZFLG = ((WORD)(dst)) == 0;
NFLG = ((WORD)(dst)) < 0;
put_word(srca,dst);
}}}}
void op_4679(ULONG opcode)
{
{{ CPTR srca = nextilong();
WORD src = get_word(srca);
{ ULONG dst = ~src;
VFLG = CFLG = 0;
ZFLG = ((WORD)(dst)) == 0;
NFLG = ((WORD)(dst)) < 0;
put_word(srca,dst);
}}}}
void op_4680(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ LONG src = regs.d[srcreg];
{ ULONG dst = ~src;
VFLG = CFLG = 0;
ZFLG = ((LONG)(dst)) == 0;
NFLG = ((LONG)(dst)) < 0;
regs.d[srcreg] = (dst);
}}}}
void op_4690(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ CPTR srca = regs.a[srcreg];
LONG src = get_long(srca);
{ ULONG dst = ~src;
VFLG = CFLG = 0;
ZFLG = ((LONG)(dst)) == 0;
NFLG = ((LONG)(dst)) < 0;
put_long(srca,dst);
}}}}
void op_4698(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ CPTR srca = regs.a[srcreg];
LONG src = get_long(srca);
{ regs.a[srcreg] += 4;
{ ULONG dst = ~src;
VFLG = CFLG = 0;
ZFLG = ((LONG)(dst)) == 0;
NFLG = ((LONG)(dst)) < 0;
put_long(srca,dst);
}}}}}
void op_46a0(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ regs.a[srcreg] -= 4;
{ CPTR srca = regs.a[srcreg];
LONG src = get_long(srca);
{ ULONG dst = ~src;
VFLG = CFLG = 0;
ZFLG = ((LONG)(dst)) == 0;
NFLG = ((LONG)(dst)) < 0;
put_long(srca,dst);
}}}}}
void op_46a8(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ CPTR srca = regs.a[srcreg] + (LONG)(WORD)nextiword();
LONG src = get_long(srca);
{ ULONG dst = ~src;
VFLG = CFLG = 0;
ZFLG = ((LONG)(dst)) == 0;
NFLG = ((LONG)(dst)) < 0;
put_long(srca,dst);
}}}}
void op_46b0(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ CPTR srca = regs.a[srcreg];
srca = get_disp_ea (srca, nextiword());
{ LONG src = get_long(srca);
{ ULONG dst = ~src;
VFLG = CFLG = 0;
ZFLG = ((LONG)(dst)) == 0;
NFLG = ((LONG)(dst)) < 0;
put_long(srca,dst);
}}}}}
void op_46b8(ULONG opcode)
{
{{ CPTR srca = (LONG)(WORD)nextiword();
LONG src = get_long(srca);
{ ULONG dst = ~src;
VFLG = CFLG = 0;
ZFLG = ((LONG)(dst)) == 0;
NFLG = ((LONG)(dst)) < 0;
put_long(srca,dst);
}}}}
void op_46b9(ULONG opcode)
{
{{ CPTR srca = nextilong();
LONG src = get_long(srca);
{ ULONG dst = ~src;
VFLG = CFLG = 0;
ZFLG = ((LONG)(dst)) == 0;
NFLG = ((LONG)(dst)) < 0;
put_long(srca,dst);
}}}}
void op_46c0(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{if (!regs.s) { regs.pc_p--; Exception(8); } else
{{ WORD src = regs.d[srcreg];
regs.sr = src;
MakeFromSR();
}}}}
void op_46d0(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{if (!regs.s) { regs.pc_p--; Exception(8); } else
{{ CPTR srca = regs.a[srcreg];
WORD src = get_word(srca);
regs.sr = src;
MakeFromSR();
}}}}
void op_46d8(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{if (!regs.s) { regs.pc_p--; Exception(8); } else
{{ CPTR srca = regs.a[srcreg];
WORD src = get_word(srca);
{ regs.a[srcreg] += 2;
regs.sr = src;
MakeFromSR();
}}}}}
void op_46e0(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{if (!regs.s) { regs.pc_p--; Exception(8); } else
{{ regs.a[srcreg] -= 2;
{ CPTR srca = regs.a[srcreg];
WORD src = get_word(srca);
regs.sr = src;
MakeFromSR();
}}}}}
void op_46e8(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{if (!regs.s) { regs.pc_p--; Exception(8); } else
{{ CPTR srca = regs.a[srcreg] + (LONG)(WORD)nextiword();
WORD src = get_word(srca);
regs.sr = src;
MakeFromSR();
}}}}
void op_46f0(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{if (!regs.s) { regs.pc_p--; Exception(8); } else
{{ CPTR srca = regs.a[srcreg];
srca = get_disp_ea (srca, nextiword());
{ WORD src = get_word(srca);
regs.sr = src;
MakeFromSR();
}}}}}
void op_46f8(ULONG opcode)
{
{if (!regs.s) { regs.pc_p--; Exception(8); } else
{{ CPTR srca = (LONG)(WORD)nextiword();
WORD src = get_word(srca);
regs.sr = src;
MakeFromSR();
}}}}
void op_46f9(ULONG opcode)
{
{if (!regs.s) { regs.pc_p--; Exception(8); } else
{{ CPTR srca = nextilong();
WORD src = get_word(srca);
regs.sr = src;
MakeFromSR();
}}}}
void op_46fa(ULONG opcode)
{
{if (!regs.s) { regs.pc_p--; Exception(8); } else
{{ CPTR srca = m68k_getpc();
srca += (LONG)(WORD)nextiword();
{ WORD src = get_word(srca);
regs.sr = src;
MakeFromSR();
}}}}}
void op_46fb(ULONG opcode)
{
{if (!regs.s) { regs.pc_p--; Exception(8); } else
{{ CPTR srca = m68k_getpc();
srca = get_disp_ea (srca, nextiword());
{ WORD src = get_word(srca);
regs.sr = src;
MakeFromSR();
}}}}}
void op_46fc(ULONG opcode)
{
{if (!regs.s) { regs.pc_p--; Exception(8); } else
{{ WORD src = nextiword();
regs.sr = src;
MakeFromSR();
}}}}
void op_4800(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ BYTE src = regs.d[srcreg];
{ UWORD newv_lo = - (src & 0xF) - regs.x;
UWORD newv_hi = - (src & 0xF0);
UWORD newv;
if (newv_lo > 9) { newv_lo-=6; newv_hi-=0x10; }
newv = newv_hi + (newv_lo & 0xF); CFLG = regs.x = (newv_hi & 0x1F0) > 0x90;
if (CFLG) newv -= 0x60;
if (newv != 0) ZFLG = 0;
regs.d[srcreg] &= ~0xff; regs.d[srcreg] |= (newv) & 0xff;
}}}}
void op_4810(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ CPTR srca = regs.a[srcreg];
BYTE src = get_byte(srca);
{ UWORD newv_lo = - (src & 0xF) - regs.x;
UWORD newv_hi = - (src & 0xF0);
UWORD newv;
if (newv_lo > 9) { newv_lo-=6; newv_hi-=0x10; }
newv = newv_hi + (newv_lo & 0xF); CFLG = regs.x = (newv_hi & 0x1F0) > 0x90;
if (CFLG) newv -= 0x60;
if (newv != 0) ZFLG = 0;
put_byte(srca,newv);
}}}}
void op_4818(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ CPTR srca = regs.a[srcreg];
BYTE src = get_byte(srca);
{ regs.a[srcreg] += areg_byteinc[srcreg];
{ UWORD newv_lo = - (src & 0xF) - regs.x;
UWORD newv_hi = - (src & 0xF0);
UWORD newv;
if (newv_lo > 9) { newv_lo-=6; newv_hi-=0x10; }
newv = newv_hi + (newv_lo & 0xF); CFLG = regs.x = (newv_hi & 0x1F0) > 0x90;
if (CFLG) newv -= 0x60;
if (newv != 0) ZFLG = 0;
put_byte(srca,newv);
}}}}}
void op_4820(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ regs.a[srcreg] -= areg_byteinc[srcreg];
{ CPTR srca = regs.a[srcreg];
BYTE src = get_byte(srca);
{ UWORD newv_lo = - (src & 0xF) - regs.x;
UWORD newv_hi = - (src & 0xF0);
UWORD newv;
if (newv_lo > 9) { newv_lo-=6; newv_hi-=0x10; }
newv = newv_hi + (newv_lo & 0xF); CFLG = regs.x = (newv_hi & 0x1F0) > 0x90;
if (CFLG) newv -= 0x60;
if (newv != 0) ZFLG = 0;
put_byte(srca,newv);
}}}}}
void op_4828(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ CPTR srca = regs.a[srcreg] + (LONG)(WORD)nextiword();
BYTE src = get_byte(srca);
{ UWORD newv_lo = - (src & 0xF) - regs.x;
UWORD newv_hi = - (src & 0xF0);
UWORD newv;
if (newv_lo > 9) { newv_lo-=6; newv_hi-=0x10; }
newv = newv_hi + (newv_lo & 0xF); CFLG = regs.x = (newv_hi & 0x1F0) > 0x90;
if (CFLG) newv -= 0x60;
if (newv != 0) ZFLG = 0;
put_byte(srca,newv);
}}}}
void op_4830(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ CPTR srca = regs.a[srcreg];
srca = get_disp_ea (srca, nextiword());
{ BYTE src = get_byte(srca);
{ UWORD newv_lo = - (src & 0xF) - regs.x;
UWORD newv_hi = - (src & 0xF0);
UWORD newv;
if (newv_lo > 9) { newv_lo-=6; newv_hi-=0x10; }
newv = newv_hi + (newv_lo & 0xF); CFLG = regs.x = (newv_hi & 0x1F0) > 0x90;
if (CFLG) newv -= 0x60;
if (newv != 0) ZFLG = 0;
put_byte(srca,newv);
}}}}}
void op_4838(ULONG opcode)
{
{{ CPTR srca = (LONG)(WORD)nextiword();
BYTE src = get_byte(srca);
{ UWORD newv_lo = - (src & 0xF) - regs.x;
UWORD newv_hi = - (src & 0xF0);
UWORD newv;
if (newv_lo > 9) { newv_lo-=6; newv_hi-=0x10; }
newv = newv_hi + (newv_lo & 0xF); CFLG = regs.x = (newv_hi & 0x1F0) > 0x90;
if (CFLG) newv -= 0x60;
if (newv != 0) ZFLG = 0;
put_byte(srca,newv);
}}}}
void op_4839(ULONG opcode)
{
{{ CPTR srca = nextilong();
BYTE src = get_byte(srca);
{ UWORD newv_lo = - (src & 0xF) - regs.x;
UWORD newv_hi = - (src & 0xF0);
UWORD newv;
if (newv_lo > 9) { newv_lo-=6; newv_hi-=0x10; }
newv = newv_hi + (newv_lo & 0xF); CFLG = regs.x = (newv_hi & 0x1F0) > 0x90;
if (CFLG) newv -= 0x60;
if (newv != 0) ZFLG = 0;
put_byte(srca,newv);
}}}}
void op_4840(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ LONG src = regs.d[srcreg];
{ ULONG dst = ((src >> 16)&0xFFFF) | ((src&0xFFFF)<<16);
VFLG = CFLG = 0;
ZFLG = ((LONG)(dst)) == 0;
NFLG = ((LONG)(dst)) < 0;
regs.d[srcreg] = (dst);
}}}}
void op_4850(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ CPTR srca = regs.a[srcreg];
{ regs.a[7] -= 4;
{ CPTR dsta = regs.a[7];
put_long(dsta,srca);
}}}}}
void op_4858(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ CPTR srca = regs.a[srcreg];
{ regs.a[srcreg] += 4;
{ regs.a[7] -= 4;
{ CPTR dsta = regs.a[7];
put_long(dsta,srca);
}}}}}}
void op_4860(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ regs.a[srcreg] -= 4;
{ CPTR srca = regs.a[srcreg];
{ regs.a[7] -= 4;
{ CPTR dsta = regs.a[7];
put_long(dsta,srca);
}}}}}}
void op_4868(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ CPTR srca = regs.a[srcreg] + (LONG)(WORD)nextiword();
{ regs.a[7] -= 4;
{ CPTR dsta = regs.a[7];
put_long(dsta,srca);
}}}}}
void op_4870(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ CPTR srca = regs.a[srcreg];
srca = get_disp_ea (srca, nextiword());
{ regs.a[7] -= 4;
{ CPTR dsta = regs.a[7];
put_long(dsta,srca);
}}}}}
void op_4878(ULONG opcode)
{
{{ CPTR srca = (LONG)(WORD)nextiword();
{ regs.a[7] -= 4;
{ CPTR dsta = regs.a[7];
put_long(dsta,srca);
}}}}}
void op_4879(ULONG opcode)
{
{{ CPTR srca = nextilong();
{ regs.a[7] -= 4;
{ CPTR dsta = regs.a[7];
put_long(dsta,srca);
}}}}}
void op_487a(ULONG opcode)
{
{{ CPTR srca = m68k_getpc();
srca += (LONG)(WORD)nextiword();
{ regs.a[7] -= 4;
{ CPTR dsta = regs.a[7];
put_long(dsta,srca);
}}}}}
void op_487b(ULONG opcode)
{
{{ CPTR srca = m68k_getpc();
srca = get_disp_ea (srca, nextiword());
{ regs.a[7] -= 4;
{ CPTR dsta = regs.a[7];
put_long(dsta,srca);
}}}}}
void op_4880(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ WORD src = regs.d[srcreg];
{ ULONG dst = (LONG)(BYTE)src;
VFLG = CFLG = 0;
ZFLG = ((WORD)(dst)) == 0;
NFLG = ((WORD)(dst)) < 0;
regs.d[srcreg] &= ~0xffff; regs.d[srcreg] |= (dst) & 0xffff;
}}}}
void op_4890(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{ UWORD mask = nextiword(), bitmask = mask;
{ CPTR srca = regs.a[srcreg];
{ int i, bitcnt = 0;
ULONG rd[8], ra[8];
for(i=0;i<16;i++) { bitcnt += bitmask & 1; bitmask >>= 1; }
for(i=0;i<8;i++) { rd[i] = regs.d[i]; ra[i] = regs.a[i]; }
for(i=0;i<8;i++) { if (mask & 1) { put_word(srca, rd[i]); srca += 2; } mask >>= 1; }
for(i=0;i<8;i++) { if (mask & 1) { put_word(srca, ra[i]); srca += 2; } mask >>= 1; }
}}}}
void op_4898(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{ UWORD mask = nextiword(), bitmask = mask;
{ CPTR srca = regs.a[srcreg];
{ int i, bitcnt = 0;
ULONG rd[8], ra[8];
for(i=0;i<16;i++) { bitcnt += bitmask & 1; bitmask >>= 1; }
for(i=0;i<8;i++) { rd[i] = regs.d[i]; ra[i] = regs.a[i]; }
for(i=0;i<8;i++) { if (mask & 1) { put_word(srca, rd[i]); srca += 2; } mask >>= 1; }
for(i=0;i<8;i++) { if (mask & 1) { put_word(srca, ra[i]); srca += 2; } mask >>= 1; }
}}}}
void op_48a0(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{ UWORD mask = nextiword(), bitmask = mask;
{{ CPTR srca = regs.a[srcreg];
{ int i, bitcnt = 0;
ULONG rd[8], ra[8];
for(i=0;i<16;i++) { bitcnt += bitmask & 1; bitmask >>= 1; }
for(i=0;i<8;i++) { rd[i] = regs.d[i]; ra[i] = regs.a[i]; }
srca -= 2*bitcnt;
regs.a[srcreg] = srca;
for(i=0;i<8;i++) { if (mask & 32768) { put_word(srca, rd[i]); srca += 2; } mask <<= 1; }
for(i=0;i<8;i++) { if (mask & 32768) { put_word(srca, ra[i]); srca += 2; } mask <<= 1; }
}}}}}
void op_48a8(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{ UWORD mask = nextiword(), bitmask = mask;
{ CPTR srca = regs.a[srcreg] + (LONG)(WORD)nextiword();
{ int i, bitcnt = 0;
ULONG rd[8], ra[8];
for(i=0;i<16;i++) { bitcnt += bitmask & 1; bitmask >>= 1; }
for(i=0;i<8;i++) { rd[i] = regs.d[i]; ra[i] = regs.a[i]; }
for(i=0;i<8;i++) { if (mask & 1) { put_word(srca, rd[i]); srca += 2; } mask >>= 1; }
for(i=0;i<8;i++) { if (mask & 1) { put_word(srca, ra[i]); srca += 2; } mask >>= 1; }
}}}}
void op_48b0(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{ UWORD mask = nextiword(), bitmask = mask;
{ CPTR srca = regs.a[srcreg];
srca = get_disp_ea (srca, nextiword());
{ int i, bitcnt = 0;
ULONG rd[8], ra[8];
for(i=0;i<16;i++) { bitcnt += bitmask & 1; bitmask >>= 1; }
for(i=0;i<8;i++) { rd[i] = regs.d[i]; ra[i] = regs.a[i]; }
for(i=0;i<8;i++) { if (mask & 1) { put_word(srca, rd[i]); srca += 2; } mask >>= 1; }
for(i=0;i<8;i++) { if (mask & 1) { put_word(srca, ra[i]); srca += 2; } mask >>= 1; }
}}}}
void op_48b8(ULONG opcode)
{
{ UWORD mask = nextiword(), bitmask = mask;
{ CPTR srca = (LONG)(WORD)nextiword();
{ int i, bitcnt = 0;
ULONG rd[8], ra[8];
for(i=0;i<16;i++) { bitcnt += bitmask & 1; bitmask >>= 1; }
for(i=0;i<8;i++) { rd[i] = regs.d[i]; ra[i] = regs.a[i]; }
for(i=0;i<8;i++) { if (mask & 1) { put_word(srca, rd[i]); srca += 2; } mask >>= 1; }
for(i=0;i<8;i++) { if (mask & 1) { put_word(srca, ra[i]); srca += 2; } mask >>= 1; }
}}}}
void op_48b9(ULONG opcode)
{
{ UWORD mask = nextiword(), bitmask = mask;
{ CPTR srca = nextilong();
{ int i, bitcnt = 0;
ULONG rd[8], ra[8];
for(i=0;i<16;i++) { bitcnt += bitmask & 1; bitmask >>= 1; }
for(i=0;i<8;i++) { rd[i] = regs.d[i]; ra[i] = regs.a[i]; }
for(i=0;i<8;i++) { if (mask & 1) { put_word(srca, rd[i]); srca += 2; } mask >>= 1; }
for(i=0;i<8;i++) { if (mask & 1) { put_word(srca, ra[i]); srca += 2; } mask >>= 1; }
}}}}
void op_48c0(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ LONG src = regs.d[srcreg];
{ ULONG dst = (LONG)(WORD)src;
VFLG = CFLG = 0;
ZFLG = ((LONG)(dst)) == 0;
NFLG = ((LONG)(dst)) < 0;
regs.d[srcreg] = (dst);
}}}}
void op_48d0(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{ UWORD mask = nextiword(), bitmask = mask;
{ CPTR srca = regs.a[srcreg];
{ int i, bitcnt = 0;
ULONG rd[8], ra[8];
for(i=0;i<16;i++) { bitcnt += bitmask & 1; bitmask >>= 1; }
for(i=0;i<8;i++) { rd[i] = regs.d[i]; ra[i] = regs.a[i]; }
for(i=0;i<8;i++) { if (mask & 1) { put_long(srca, rd[i]); srca += 4; } mask >>= 1; }
for(i=0;i<8;i++) { if (mask & 1) { put_long(srca, ra[i]); srca += 4; } mask >>= 1; }
}}}}
void op_48d8(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{ UWORD mask = nextiword(), bitmask = mask;
{ CPTR srca = regs.a[srcreg];
{ int i, bitcnt = 0;
ULONG rd[8], ra[8];
for(i=0;i<16;i++) { bitcnt += bitmask & 1; bitmask >>= 1; }
for(i=0;i<8;i++) { rd[i] = regs.d[i]; ra[i] = regs.a[i]; }
for(i=0;i<8;i++) { if (mask & 1) { put_long(srca, rd[i]); srca += 4; } mask >>= 1; }
for(i=0;i<8;i++) { if (mask & 1) { put_long(srca, ra[i]); srca += 4; } mask >>= 1; }
}}}}
void op_48e0(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{ UWORD mask = nextiword(), bitmask = mask;
{{ CPTR srca = regs.a[srcreg];
{ int i, bitcnt = 0;
ULONG rd[8], ra[8];
for(i=0;i<16;i++) { bitcnt += bitmask & 1; bitmask >>= 1; }
for(i=0;i<8;i++) { rd[i] = regs.d[i]; ra[i] = regs.a[i]; }
srca -= 4*bitcnt;
regs.a[srcreg] = srca;
for(i=0;i<8;i++) { if (mask & 32768) { put_long(srca, rd[i]); srca += 4; } mask <<= 1; }
for(i=0;i<8;i++) { if (mask & 32768) { put_long(srca, ra[i]); srca += 4; } mask <<= 1; }
}}}}}
void op_48e8(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{ UWORD mask = nextiword(), bitmask = mask;
{ CPTR srca = regs.a[srcreg] + (LONG)(WORD)nextiword();
{ int i, bitcnt = 0;
ULONG rd[8], ra[8];
for(i=0;i<16;i++) { bitcnt += bitmask & 1; bitmask >>= 1; }
for(i=0;i<8;i++) { rd[i] = regs.d[i]; ra[i] = regs.a[i]; }
for(i=0;i<8;i++) { if (mask & 1) { put_long(srca, rd[i]); srca += 4; } mask >>= 1; }
for(i=0;i<8;i++) { if (mask & 1) { put_long(srca, ra[i]); srca += 4; } mask >>= 1; }
}}}}
void op_48f0(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{ UWORD mask = nextiword(), bitmask = mask;
{ CPTR srca = regs.a[srcreg];
srca = get_disp_ea (srca, nextiword());
{ int i, bitcnt = 0;
ULONG rd[8], ra[8];
for(i=0;i<16;i++) { bitcnt += bitmask & 1; bitmask >>= 1; }
for(i=0;i<8;i++) { rd[i] = regs.d[i]; ra[i] = regs.a[i]; }
for(i=0;i<8;i++) { if (mask & 1) { put_long(srca, rd[i]); srca += 4; } mask >>= 1; }
for(i=0;i<8;i++) { if (mask & 1) { put_long(srca, ra[i]); srca += 4; } mask >>= 1; }
}}}}
void op_48f8(ULONG opcode)
{
{ UWORD mask = nextiword(), bitmask = mask;
{ CPTR srca = (LONG)(WORD)nextiword();
{ int i, bitcnt = 0;
ULONG rd[8], ra[8];
for(i=0;i<16;i++) { bitcnt += bitmask & 1; bitmask >>= 1; }
for(i=0;i<8;i++) { rd[i] = regs.d[i]; ra[i] = regs.a[i]; }
for(i=0;i<8;i++) { if (mask & 1) { put_long(srca, rd[i]); srca += 4; } mask >>= 1; }
for(i=0;i<8;i++) { if (mask & 1) { put_long(srca, ra[i]); srca += 4; } mask >>= 1; }
}}}}
void op_48f9(ULONG opcode)
{
{ UWORD mask = nextiword(), bitmask = mask;
{ CPTR srca = nextilong();
{ int i, bitcnt = 0;
ULONG rd[8], ra[8];
for(i=0;i<16;i++) { bitcnt += bitmask & 1; bitmask >>= 1; }
for(i=0;i<8;i++) { rd[i] = regs.d[i]; ra[i] = regs.a[i]; }
for(i=0;i<8;i++) { if (mask & 1) { put_long(srca, rd[i]); srca += 4; } mask >>= 1; }
for(i=0;i<8;i++) { if (mask & 1) { put_long(srca, ra[i]); srca += 4; } mask >>= 1; }
}}}}
void op_4a00(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ BYTE src = regs.d[srcreg];
VFLG = CFLG = 0;
ZFLG = ((BYTE)(src)) == 0;
NFLG = ((BYTE)(src)) < 0;
}}}
void op_4a10(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ CPTR srca = regs.a[srcreg];
BYTE src = get_byte(srca);
VFLG = CFLG = 0;
ZFLG = ((BYTE)(src)) == 0;
NFLG = ((BYTE)(src)) < 0;
}}}
void op_4a18(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ CPTR srca = regs.a[srcreg];
BYTE src = get_byte(srca);
{ regs.a[srcreg] += areg_byteinc[srcreg];
VFLG = CFLG = 0;
ZFLG = ((BYTE)(src)) == 0;
NFLG = ((BYTE)(src)) < 0;
}}}}
void op_4a20(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ regs.a[srcreg] -= areg_byteinc[srcreg];
{ CPTR srca = regs.a[srcreg];
BYTE src = get_byte(srca);
VFLG = CFLG = 0;
ZFLG = ((BYTE)(src)) == 0;
NFLG = ((BYTE)(src)) < 0;
}}}}
void op_4a28(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ CPTR srca = regs.a[srcreg] + (LONG)(WORD)nextiword();
BYTE src = get_byte(srca);
VFLG = CFLG = 0;
ZFLG = ((BYTE)(src)) == 0;
NFLG = ((BYTE)(src)) < 0;
}}}
void op_4a30(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ CPTR srca = regs.a[srcreg];
srca = get_disp_ea (srca, nextiword());
{ BYTE src = get_byte(srca);
VFLG = CFLG = 0;
ZFLG = ((BYTE)(src)) == 0;
NFLG = ((BYTE)(src)) < 0;
}}}}
void op_4a38(ULONG opcode)
{
{{ CPTR srca = (LONG)(WORD)nextiword();
BYTE src = get_byte(srca);
VFLG = CFLG = 0;
ZFLG = ((BYTE)(src)) == 0;
NFLG = ((BYTE)(src)) < 0;
}}}
void op_4a39(ULONG opcode)
{
{{ CPTR srca = nextilong();
BYTE src = get_byte(srca);
VFLG = CFLG = 0;
ZFLG = ((BYTE)(src)) == 0;
NFLG = ((BYTE)(src)) < 0;
}}}
void op_4a40(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ WORD src = regs.d[srcreg];
VFLG = CFLG = 0;
ZFLG = ((WORD)(src)) == 0;
NFLG = ((WORD)(src)) < 0;
}}}
void op_4a48(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ WORD src = regs.a[srcreg];
VFLG = CFLG = 0;
ZFLG = ((WORD)(src)) == 0;
NFLG = ((WORD)(src)) < 0;
}}}
void op_4a50(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ CPTR srca = regs.a[srcreg];
WORD src = get_word(srca);
VFLG = CFLG = 0;
ZFLG = ((WORD)(src)) == 0;
NFLG = ((WORD)(src)) < 0;
}}}
void op_4a58(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ CPTR srca = regs.a[srcreg];
WORD src = get_word(srca);
{ regs.a[srcreg] += 2;
VFLG = CFLG = 0;
ZFLG = ((WORD)(src)) == 0;
NFLG = ((WORD)(src)) < 0;
}}}}
void op_4a60(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ regs.a[srcreg] -= 2;
{ CPTR srca = regs.a[srcreg];
WORD src = get_word(srca);
VFLG = CFLG = 0;
ZFLG = ((WORD)(src)) == 0;
NFLG = ((WORD)(src)) < 0;
}}}}
void op_4a68(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ CPTR srca = regs.a[srcreg] + (LONG)(WORD)nextiword();
WORD src = get_word(srca);
VFLG = CFLG = 0;
ZFLG = ((WORD)(src)) == 0;
NFLG = ((WORD)(src)) < 0;
}}}
void op_4a70(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ CPTR srca = regs.a[srcreg];
srca = get_disp_ea (srca, nextiword());
{ WORD src = get_word(srca);
VFLG = CFLG = 0;
ZFLG = ((WORD)(src)) == 0;
NFLG = ((WORD)(src)) < 0;
}}}}
void op_4a78(ULONG opcode)
{
{{ CPTR srca = (LONG)(WORD)nextiword();
WORD src = get_word(srca);
VFLG = CFLG = 0;
ZFLG = ((WORD)(src)) == 0;
NFLG = ((WORD)(src)) < 0;
}}}
void op_4a79(ULONG opcode)
{
{{ CPTR srca = nextilong();
WORD src = get_word(srca);
VFLG = CFLG = 0;
ZFLG = ((WORD)(src)) == 0;
NFLG = ((WORD)(src)) < 0;
}}}
void op_4a80(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ LONG src = regs.d[srcreg];
VFLG = CFLG = 0;
ZFLG = ((LONG)(src)) == 0;
NFLG = ((LONG)(src)) < 0;
}}}
void op_4a88(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ LONG src = regs.a[srcreg];
VFLG = CFLG = 0;
ZFLG = ((LONG)(src)) == 0;
NFLG = ((LONG)(src)) < 0;
}}}
void op_4a90(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ CPTR srca = regs.a[srcreg];
LONG src = get_long(srca);
VFLG = CFLG = 0;
ZFLG = ((LONG)(src)) == 0;
NFLG = ((LONG)(src)) < 0;
}}}
void op_4a98(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ CPTR srca = regs.a[srcreg];
LONG src = get_long(srca);
{ regs.a[srcreg] += 4;
VFLG = CFLG = 0;
ZFLG = ((LONG)(src)) == 0;
NFLG = ((LONG)(src)) < 0;
}}}}
void op_4aa0(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ regs.a[srcreg] -= 4;
{ CPTR srca = regs.a[srcreg];
LONG src = get_long(srca);
VFLG = CFLG = 0;
ZFLG = ((LONG)(src)) == 0;
NFLG = ((LONG)(src)) < 0;
}}}}
void op_4aa8(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ CPTR srca = regs.a[srcreg] + (LONG)(WORD)nextiword();
LONG src = get_long(srca);
VFLG = CFLG = 0;
ZFLG = ((LONG)(src)) == 0;
NFLG = ((LONG)(src)) < 0;
}}}
void op_4ab0(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ CPTR srca = regs.a[srcreg];
srca = get_disp_ea (srca, nextiword());
{ LONG src = get_long(srca);
VFLG = CFLG = 0;
ZFLG = ((LONG)(src)) == 0;
NFLG = ((LONG)(src)) < 0;
}}}}
void op_4ab8(ULONG opcode)
{
{{ CPTR srca = (LONG)(WORD)nextiword();
LONG src = get_long(srca);
VFLG = CFLG = 0;
ZFLG = ((LONG)(src)) == 0;
NFLG = ((LONG)(src)) < 0;
}}}
void op_4ab9(ULONG opcode)
{
{{ CPTR srca = nextilong();
LONG src = get_long(srca);
VFLG = CFLG = 0;
ZFLG = ((LONG)(src)) == 0;
NFLG = ((LONG)(src)) < 0;
}}}
void op_4c90(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{ UWORD mask = nextiword(), bitmask = mask;
{ CPTR srca = regs.a[srcreg];
{ int i, bitcnt = 0;
for(i=0;i<16;i++) { bitcnt += bitmask & 1; bitmask >>= 1; }
for(i=0;i<8;i++) { if (mask & 1) { regs.d[i] = (LONG)(WORD)get_word(srca); srca += 2; } mask >>= 1; }
for(i=0;i<8;i++) { if (mask & 1) { regs.a[i] = (LONG)(WORD)get_word(srca); srca += 2; } mask >>= 1; }
}}}}
void op_4c98(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{ UWORD mask = nextiword(), bitmask = mask;
{ CPTR srca = regs.a[srcreg];
{ int i, bitcnt = 0;
for(i=0;i<16;i++) { bitcnt += bitmask & 1; bitmask >>= 1; }
for(i=0;i<8;i++) { if (mask & 1) { regs.d[i] = (LONG)(WORD)get_word(srca); srca += 2; } mask >>= 1; }
for(i=0;i<8;i++) { if (mask & 1) { regs.a[i] = (LONG)(WORD)get_word(srca); srca += 2; } mask >>= 1; }
regs.a[srcreg] = srca;
}}}}
void op_4ca0(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{ UWORD mask = nextiword(), bitmask = mask;
{{ CPTR srca = regs.a[srcreg];
{ int i, bitcnt = 0;
for(i=0;i<16;i++) { bitcnt += bitmask & 1; bitmask >>= 1; }
for(i=0;i<8;i++) { if (mask & 1) { regs.d[i] = (LONG)(WORD)get_word(srca); srca += 2; } mask >>= 1; }
for(i=0;i<8;i++) { if (mask & 1) { regs.a[i] = (LONG)(WORD)get_word(srca); srca += 2; } mask >>= 1; }
}}}}}
void op_4ca8(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{ UWORD mask = nextiword(), bitmask = mask;
{ CPTR srca = regs.a[srcreg] + (LONG)(WORD)nextiword();
{ int i, bitcnt = 0;
for(i=0;i<16;i++) { bitcnt += bitmask & 1; bitmask >>= 1; }
for(i=0;i<8;i++) { if (mask & 1) { regs.d[i] = (LONG)(WORD)get_word(srca); srca += 2; } mask >>= 1; }
for(i=0;i<8;i++) { if (mask & 1) { regs.a[i] = (LONG)(WORD)get_word(srca); srca += 2; } mask >>= 1; }
}}}}
void op_4cb0(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{ UWORD mask = nextiword(), bitmask = mask;
{ CPTR srca = regs.a[srcreg];
srca = get_disp_ea (srca, nextiword());
{ int i, bitcnt = 0;
for(i=0;i<16;i++) { bitcnt += bitmask & 1; bitmask >>= 1; }
for(i=0;i<8;i++) { if (mask & 1) { regs.d[i] = (LONG)(WORD)get_word(srca); srca += 2; } mask >>= 1; }
for(i=0;i<8;i++) { if (mask & 1) { regs.a[i] = (LONG)(WORD)get_word(srca); srca += 2; } mask >>= 1; }
}}}}
void op_4cb8(ULONG opcode)
{
{ UWORD mask = nextiword(), bitmask = mask;
{ CPTR srca = (LONG)(WORD)nextiword();
{ int i, bitcnt = 0;
for(i=0;i<16;i++) { bitcnt += bitmask & 1; bitmask >>= 1; }
for(i=0;i<8;i++) { if (mask & 1) { regs.d[i] = (LONG)(WORD)get_word(srca); srca += 2; } mask >>= 1; }
for(i=0;i<8;i++) { if (mask & 1) { regs.a[i] = (LONG)(WORD)get_word(srca); srca += 2; } mask >>= 1; }
}}}}
void op_4cb9(ULONG opcode)
{
{ UWORD mask = nextiword(), bitmask = mask;
{ CPTR srca = nextilong();
{ int i, bitcnt = 0;
for(i=0;i<16;i++) { bitcnt += bitmask & 1; bitmask >>= 1; }
for(i=0;i<8;i++) { if (mask & 1) { regs.d[i] = (LONG)(WORD)get_word(srca); srca += 2; } mask >>= 1; }
for(i=0;i<8;i++) { if (mask & 1) { regs.a[i] = (LONG)(WORD)get_word(srca); srca += 2; } mask >>= 1; }
}}}}
void op_4cba(ULONG opcode)
{
{ UWORD mask = nextiword(), bitmask = mask;
{ CPTR srca = m68k_getpc();
srca += (LONG)(WORD)nextiword();
{ int i, bitcnt = 0;
for(i=0;i<16;i++) { bitcnt += bitmask & 1; bitmask >>= 1; }
for(i=0;i<8;i++) { if (mask & 1) { regs.d[i] = (LONG)(WORD)get_word(srca); srca += 2; } mask >>= 1; }
for(i=0;i<8;i++) { if (mask & 1) { regs.a[i] = (LONG)(WORD)get_word(srca); srca += 2; } mask >>= 1; }
}}}}
void op_4cbb(ULONG opcode)
{
{ UWORD mask = nextiword(), bitmask = mask;
{ CPTR srca = m68k_getpc();
srca = get_disp_ea (srca, nextiword());
{ int i, bitcnt = 0;
for(i=0;i<16;i++) { bitcnt += bitmask & 1; bitmask >>= 1; }
for(i=0;i<8;i++) { if (mask & 1) { regs.d[i] = (LONG)(WORD)get_word(srca); srca += 2; } mask >>= 1; }
for(i=0;i<8;i++) { if (mask & 1) { regs.a[i] = (LONG)(WORD)get_word(srca); srca += 2; } mask >>= 1; }
}}}}
void op_4cd0(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{ UWORD mask = nextiword(), bitmask = mask;
{ CPTR srca = regs.a[srcreg];
{ int i, bitcnt = 0;
for(i=0;i<16;i++) { bitcnt += bitmask & 1; bitmask >>= 1; }
for(i=0;i<8;i++) { if (mask & 1) { regs.d[i] = get_long(srca); srca += 4; } mask >>= 1; }
for(i=0;i<8;i++) { if (mask & 1) { regs.a[i] = get_long(srca); srca += 4; } mask >>= 1; }
}}}}
void op_4cd8(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{ UWORD mask = nextiword(), bitmask = mask;
{ CPTR srca = regs.a[srcreg];
{ int i, bitcnt = 0;
for(i=0;i<16;i++) { bitcnt += bitmask & 1; bitmask >>= 1; }
for(i=0;i<8;i++) { if (mask & 1) { regs.d[i] = get_long(srca); srca += 4; } mask >>= 1; }
for(i=0;i<8;i++) { if (mask & 1) { regs.a[i] = get_long(srca); srca += 4; } mask >>= 1; }
regs.a[srcreg] = srca;
}}}}
void op_4ce0(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{ UWORD mask = nextiword(), bitmask = mask;
{{ CPTR srca = regs.a[srcreg];
{ int i, bitcnt = 0;
for(i=0;i<16;i++) { bitcnt += bitmask & 1; bitmask >>= 1; }
for(i=0;i<8;i++) { if (mask & 1) { regs.d[i] = get_long(srca); srca += 4; } mask >>= 1; }
for(i=0;i<8;i++) { if (mask & 1) { regs.a[i] = get_long(srca); srca += 4; } mask >>= 1; }
}}}}}
void op_4ce8(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{ UWORD mask = nextiword(), bitmask = mask;
{ CPTR srca = regs.a[srcreg] + (LONG)(WORD)nextiword();
{ int i, bitcnt = 0;
for(i=0;i<16;i++) { bitcnt += bitmask & 1; bitmask >>= 1; }
for(i=0;i<8;i++) { if (mask & 1) { regs.d[i] = get_long(srca); srca += 4; } mask >>= 1; }
for(i=0;i<8;i++) { if (mask & 1) { regs.a[i] = get_long(srca); srca += 4; } mask >>= 1; }
}}}}
void op_4cf0(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{ UWORD mask = nextiword(), bitmask = mask;
{ CPTR srca = regs.a[srcreg];
srca = get_disp_ea (srca, nextiword());
{ int i, bitcnt = 0;
for(i=0;i<16;i++) { bitcnt += bitmask & 1; bitmask >>= 1; }
for(i=0;i<8;i++) { if (mask & 1) { regs.d[i] = get_long(srca); srca += 4; } mask >>= 1; }
for(i=0;i<8;i++) { if (mask & 1) { regs.a[i] = get_long(srca); srca += 4; } mask >>= 1; }
}}}}
void op_4cf8(ULONG opcode)
{
{ UWORD mask = nextiword(), bitmask = mask;
{ CPTR srca = (LONG)(WORD)nextiword();
{ int i, bitcnt = 0;
for(i=0;i<16;i++) { bitcnt += bitmask & 1; bitmask >>= 1; }
for(i=0;i<8;i++) { if (mask & 1) { regs.d[i] = get_long(srca); srca += 4; } mask >>= 1; }
for(i=0;i<8;i++) { if (mask & 1) { regs.a[i] = get_long(srca); srca += 4; } mask >>= 1; }
}}}}
void op_4cf9(ULONG opcode)
{
{ UWORD mask = nextiword(), bitmask = mask;
{ CPTR srca = nextilong();
{ int i, bitcnt = 0;
for(i=0;i<16;i++) { bitcnt += bitmask & 1; bitmask >>= 1; }
for(i=0;i<8;i++) { if (mask & 1) { regs.d[i] = get_long(srca); srca += 4; } mask >>= 1; }
for(i=0;i<8;i++) { if (mask & 1) { regs.a[i] = get_long(srca); srca += 4; } mask >>= 1; }
}}}}
void op_4cfa(ULONG opcode)
{
{ UWORD mask = nextiword(), bitmask = mask;
{ CPTR srca = m68k_getpc();
srca += (LONG)(WORD)nextiword();
{ int i, bitcnt = 0;
for(i=0;i<16;i++) { bitcnt += bitmask & 1; bitmask >>= 1; }
for(i=0;i<8;i++) { if (mask & 1) { regs.d[i] = get_long(srca); srca += 4; } mask >>= 1; }
for(i=0;i<8;i++) { if (mask & 1) { regs.a[i] = get_long(srca); srca += 4; } mask >>= 1; }
}}}}
void op_4cfb(ULONG opcode)
{
{ UWORD mask = nextiword(), bitmask = mask;
{ CPTR srca = m68k_getpc();
srca = get_disp_ea (srca, nextiword());
{ int i, bitcnt = 0;
for(i=0;i<16;i++) { bitcnt += bitmask & 1; bitmask >>= 1; }
for(i=0;i<8;i++) { if (mask & 1) { regs.d[i] = get_long(srca); srca += 4; } mask >>= 1; }
for(i=0;i<8;i++) { if (mask & 1) { regs.a[i] = get_long(srca); srca += 4; } mask >>= 1; }
}}}}
void op_4e40(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 15) >> 0);
{{ ULONG src = srcreg;
Exception(src+32);
}}}
void op_4e50(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ regs.a[7] -= 4;
{ CPTR olda = regs.a[7];
{ LONG src = regs.a[srcreg];
put_long(olda,src);
regs.a[srcreg] = (regs.a[7]);
{ WORD offs = nextiword();
regs.a[7] += offs;
}}}}}}
void op_4e58(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ LONG src = regs.a[srcreg];
regs.a[7] = src;
{ CPTR olda = regs.a[7];
LONG old = get_long(olda);
{ regs.a[7] += 4;
regs.a[srcreg] = (old);
}}}}}
void op_4e60(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{if (!regs.s) { regs.pc_p--; Exception(8); } else
{{ LONG src = regs.a[srcreg];
regs.usp = src;
}}}}
void op_4e68(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{if (!regs.s) { regs.pc_p--; Exception(8); } else
{{ regs.a[srcreg] = (regs.usp);
}}}}
void op_4e70(ULONG opcode)
{
{if (!regs.s) { regs.pc_p--; Exception(8); } else
{ customreset();
}}}
void op_4e71(ULONG opcode)
{
{}}
void op_4e72(ULONG opcode)
{
{if (!regs.s) { regs.pc_p--; Exception(8); } else
{{ WORD src = nextiword();
regs.sr = src;
MakeFromSR();
m68k_setstopped(1);
}}}}
void op_4e73(ULONG opcode)
{
{if (!regs.s) { regs.pc_p--; Exception(8); } else
{{ CPTR sra = regs.a[7];
WORD sr = get_word(sra);
{ regs.a[7] += 2;
{ CPTR pca = regs.a[7];
LONG pc = get_long(pca);
{ regs.a[7] += 4;
regs.sr = sr; m68k_setpc(pc);
MakeFromSR();
}}}}}}}
void op_4e74(ULONG opcode)
{
{}}
void op_4e75(ULONG opcode)
{
{{ CPTR pca = regs.a[7];
LONG pc = get_long(pca);
{ regs.a[7] += 4;
m68k_setpc(pc);
}}}}
void op_4e76(ULONG opcode)
{
{ if(VFLG) Exception(7);
}}
void op_4e77(ULONG opcode)
{
{ MakeSR();
{ CPTR sra = regs.a[7];
WORD sr = get_word(sra);
{ regs.a[7] += 2;
{ CPTR pca = regs.a[7];
LONG pc = get_long(pca);
{ regs.a[7] += 4;
regs.sr &= 0xFF00; sr &= 0xFF;
regs.sr |= sr; m68k_setpc(pc);
MakeFromSR();
}}}}}}
void op_4e90(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ CPTR srca = regs.a[srcreg];
{ regs.a[7] -= 4;
{ CPTR spa = regs.a[7];
put_long(spa,m68k_getpc());
m68k_setpc(srca);
}}}}}
void op_4e98(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ CPTR srca = regs.a[srcreg];
{ regs.a[srcreg] += 4;
{ regs.a[7] -= 4;
{ CPTR spa = regs.a[7];
put_long(spa,m68k_getpc());
m68k_setpc(srca);
}}}}}}
void op_4ea0(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ regs.a[srcreg] -= 4;
{ CPTR srca = regs.a[srcreg];
{ regs.a[7] -= 4;
{ CPTR spa = regs.a[7];
put_long(spa,m68k_getpc());
m68k_setpc(srca);
}}}}}}
void op_4ea8(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ CPTR srca = regs.a[srcreg] + (LONG)(WORD)nextiword();
{ regs.a[7] -= 4;
{ CPTR spa = regs.a[7];
put_long(spa,m68k_getpc());
m68k_setpc(srca);
}}}}}
void op_4eb0(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ CPTR srca = regs.a[srcreg];
srca = get_disp_ea (srca, nextiword());
{ regs.a[7] -= 4;
{ CPTR spa = regs.a[7];
put_long(spa,m68k_getpc());
m68k_setpc(srca);
}}}}}
void op_4eb8(ULONG opcode)
{
{{ CPTR srca = (LONG)(WORD)nextiword();
{ regs.a[7] -= 4;
{ CPTR spa = regs.a[7];
put_long(spa,m68k_getpc());
m68k_setpc(srca);
}}}}}
void op_4eb9(ULONG opcode)
{
{{ CPTR srca = nextilong();
{ regs.a[7] -= 4;
{ CPTR spa = regs.a[7];
put_long(spa,m68k_getpc());
m68k_setpc(srca);
}}}}}
void op_4eba(ULONG opcode)
{
{{ CPTR srca = m68k_getpc();
srca += (LONG)(WORD)nextiword();
{ regs.a[7] -= 4;
{ CPTR spa = regs.a[7];
put_long(spa,m68k_getpc());
m68k_setpc(srca);
}}}}}
void op_4ebb(ULONG opcode)
{
{{ CPTR srca = m68k_getpc();
srca = get_disp_ea (srca, nextiword());
{ regs.a[7] -= 4;
{ CPTR spa = regs.a[7];
put_long(spa,m68k_getpc());
m68k_setpc(srca);
}}}}}
void op_4ed0(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ CPTR srca = regs.a[srcreg];
m68k_setpc(srca);
}}}
void op_4ed8(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ CPTR srca = regs.a[srcreg];
{ regs.a[srcreg] += 4;
m68k_setpc(srca);
}}}}
void op_4ee0(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ regs.a[srcreg] -= 4;
{ CPTR srca = regs.a[srcreg];
m68k_setpc(srca);
}}}}
void op_4ee8(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ CPTR srca = regs.a[srcreg] + (LONG)(WORD)nextiword();
m68k_setpc(srca);
}}}
void op_4ef0(ULONG opcode)
{
ULONG srcreg = (LONG)(BYTE)((opcode & 7) >> 0);
{{ CPTR srca = regs.a[srcreg];
srca = get_disp_ea (srca, nextiword());
m68k_setpc(srca);
}}}
void op_4ef8(ULONG opcode)
{
{{ CPTR srca = (LONG)(WORD)nextiword();
m68k_setpc(srca);
}}}
void op_4ef9(ULONG opcode)
{
{{ CPTR srca = nextilong();
m68k_setpc(srca);
}}}
void op_4efa(ULONG opcode)
{
{{ CPTR srca = m68k_getpc();
srca += (LONG)(WORD)nextiword();
m68k_setpc(srca);
}}}
void op_4efb(ULONG opcode)
{
{{ CPTR srca = m68k_getpc();
srca = get_disp_ea (srca, nextiword());
m68k_setpc(srca);
}}}
|
5826d9218e86fc328cc7b5c15602d3ef1f270c3b
|
28d0f8c01599f8f6c711bdde0b59f9c2cd221203
|
/lib/libc/sys/sched.c
|
337439b01c91d042c4883ce7a9c6b2b1dcaff9d3
|
[] |
no_license
|
NetBSD/src
|
1a9cbc22ed778be638b37869ed4fb5c8dd616166
|
23ee83f7c0aea0777bd89d8ebd7f0cde9880d13c
|
refs/heads/trunk
| 2023-08-31T13:24:58.105962
| 2023-08-27T15:50:47
| 2023-08-27T15:50:47
| 88,439,547
| 656
| 348
| null | 2023-07-20T20:07:24
| 2017-04-16T20:03:43
| null |
UTF-8
|
C
| false
| false
| 3,735
|
c
|
sched.c
|
/* $NetBSD: sched.c,v 1.6 2018/01/04 20:57:29 kamil Exp $ */
/*
* Copyright (c) 2008, Mindaugas Rasiukevicius <rmind at NetBSD org>
* 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 AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: sched.c,v 1.6 2018/01/04 20:57:29 kamil Exp $");
#include "namespace.h"
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <sched.h>
#include <signal.h>
#include <sys/param.h>
#include <sys/types.h>
/* All LWPs in the process */
#define P_ALL_LWPS 0
/*
* Scheduling parameters.
*/
int
sched_setparam(pid_t pid, const struct sched_param *param)
{
struct sched_param sp;
memset(&sp, 0, sizeof(struct sched_param));
sp.sched_priority = param->sched_priority;
return _sched_setparam(pid, P_ALL_LWPS, SCHED_NONE, &sp);
}
int
sched_getparam(pid_t pid, struct sched_param *param)
{
return _sched_getparam(pid, P_ALL_LWPS, NULL, param);
}
int
sched_setscheduler(pid_t pid, int policy, const struct sched_param *param)
{
struct sched_param sp;
int ret, old_policy;
ret = _sched_getparam(pid, P_ALL_LWPS, &old_policy, &sp);
if (ret < 0)
return ret;
memset(&sp, 0, sizeof(struct sched_param));
sp.sched_priority = param->sched_priority;
ret = _sched_setparam(pid, P_ALL_LWPS, policy, &sp);
if (ret < 0)
return ret;
return old_policy;
}
int
sched_getscheduler(pid_t pid)
{
struct sched_param sp;
int ret, policy;
ret = _sched_getparam(pid, P_ALL_LWPS, &policy, &sp);
if (ret < 0)
return ret;
return policy;
}
/*
* Scheduling priorities.
*/
int
sched_get_priority_max(int policy)
{
switch (policy) {
case SCHED_OTHER:
return PRI_NONE;
case SCHED_RR:
case SCHED_FIFO:
return (int)sysconf(_SC_SCHED_PRI_MAX);
default:
errno = EINVAL;
return -1;
}
}
int
sched_get_priority_min(int policy)
{
switch (policy) {
case SCHED_OTHER:
return PRI_NONE;
case SCHED_RR:
case SCHED_FIFO:
return (int)sysconf(_SC_SCHED_PRI_MIN);
default:
errno = EINVAL;
return -1;
}
}
int
/*ARGSUSED*/
sched_rr_get_interval(pid_t pid, struct timespec *interval)
{
if (pid && kill(pid, 0) == -1)
return -1;
interval->tv_sec = 0;
interval->tv_nsec = sysconf(_SC_SCHED_RT_TS) * 1000;
return 0;
}
/*
* Process affinity.
*/
int
sched_getaffinity_np(pid_t pid, size_t size, cpuset_t *cpuset)
{
return _sched_getaffinity(pid, P_ALL_LWPS, size, cpuset);
}
int
sched_setaffinity_np(pid_t pid, size_t size, cpuset_t *cpuset)
{
return _sched_setaffinity(pid, P_ALL_LWPS, size, cpuset);
}
|
6c21562ce8a30d7f7b2f988655c3e15bd925255f
|
65089dbc386e1184983c15fe3a2282763ae65960
|
/gear-lib/libptcp/gqueue.c
|
2cf6d0199fd503a4443697d4d25b56f54303fb9f
|
[
"MIT"
] |
permissive
|
gozfree/gear-lib
|
9f4db1bce799ded1cf1f3411cb51bdfbcbe7c7bc
|
bffbfd25af4ff7b04ebfafdab391b55270b0273e
|
refs/heads/master
| 2023-08-14T16:01:29.449910
| 2023-07-24T16:08:47
| 2023-07-24T16:09:41
| 40,359,871
| 1,771
| 488
|
MIT
| 2023-05-27T11:08:46
| 2015-08-07T12:41:05
|
C
|
UTF-8
|
C
| false
| false
| 23,128
|
c
|
gqueue.c
|
/* GLIB - Library of useful routines for C programming
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
*
* GQueue: Double ended queue implementation, piggy backed on GList.
* Copyright (C) 1998 Tim Janik
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
*/
/*
* MT safe
*/
/**
* SECTION:queue
* @Title: Double-ended Queues
* @Short_description: double-ended queue data structure
*
* The #GQueue structure and its associated functions provide a standard
* queue data structure. Internally, GQueue uses the same data structure
* as #GList to store elements.
*
* The data contained in each element can be either integer values, by
* using one of the [Type Conversion Macros][glib-Type-Conversion-Macros],
* or simply pointers to any type of data.
*
* To create a new GQueue, use g_queue_new().
*
* To initialize a statically-allocated GQueue, use #G_QUEUE_INIT or
* g_queue_init().
*
* To add elements, use g_queue_push_head(), g_queue_push_head_link(),
* g_queue_push_tail() and g_queue_push_tail_link().
*
* To remove elements, use g_queue_pop_head() and g_queue_pop_tail().
*
* To free the entire queue, use g_queue_free().
*/
//#include "config.h"
#include "gqueue.h"
//#include "gtestutils.h"
//#include "gslice.h"
/**
* g_queue_new:
*
* Creates a new #GQueue.
*
* Returns: a newly allocated #GQueue
**/
GQueue *
g_queue_new (void)
{
return g_slice_new0 (GQueue);
}
/**
* g_queue_free:
* @queue: a #GQueue
*
* Frees the memory allocated for the #GQueue. Only call this function
* if @queue was created with g_queue_new(). If queue elements contain
* dynamically-allocated memory, they should be freed first.
*
* If queue elements contain dynamically-allocated memory, you should
* either use g_queue_free_full() or free them manually first.
**/
void
g_queue_free (GQueue *queue)
{
g_return_if_fail (queue != NULL);
g_list_free (queue->head);
g_slice_free (GQueue, queue);
}
/**
* g_queue_free_full:
* @queue: a pointer to a #GQueue
* @free_func: the function to be called to free each element's data
*
* Convenience method, which frees all the memory used by a #GQueue,
* and calls the specified destroy function on every element's data.
*
* Since: 2.32
*/
void
g_queue_free_full (GQueue *queue,
GDestroyNotify free_func)
{
g_queue_foreach (queue, (GFunc) free_func, NULL);
g_queue_free (queue);
}
/**
* g_queue_init:
* @queue: an uninitialized #GQueue
*
* A statically-allocated #GQueue must be initialized with this function
* before it can be used. Alternatively you can initialize it with
* #G_QUEUE_INIT. It is not necessary to initialize queues created with
* g_queue_new().
*
* Since: 2.14
*/
void
g_queue_init (GQueue *queue)
{
g_return_if_fail (queue != NULL);
queue->head = queue->tail = NULL;
queue->length = 0;
}
/**
* g_queue_clear:
* @queue: a #GQueue
*
* Removes all the elements in @queue. If queue elements contain
* dynamically-allocated memory, they should be freed first.
*
* Since: 2.14
*/
void
g_queue_clear (GQueue *queue)
{
g_return_if_fail (queue != NULL);
g_list_free (queue->head);
g_queue_init (queue);
}
/**
* g_queue_is_empty:
* @queue: a #GQueue.
*
* Returns %TRUE if the queue is empty.
*
* Returns: %TRUE if the queue is empty
*/
gboolean
g_queue_is_empty (GQueue *queue)
{
g_return_val_if_fail (queue != NULL, TRUE);
return queue->head == NULL;
}
/**
* g_queue_get_length:
* @queue: a #GQueue
*
* Returns the number of items in @queue.
*
* Returns: the number of items in @queue
*
* Since: 2.4
*/
guint
g_queue_get_length (GQueue *queue)
{
g_return_val_if_fail (queue != NULL, 0);
return queue->length;
}
/**
* g_queue_reverse:
* @queue: a #GQueue
*
* Reverses the order of the items in @queue.
*
* Since: 2.4
*/
void
g_queue_reverse (GQueue *queue)
{
g_return_if_fail (queue != NULL);
queue->tail = queue->head;
queue->head = g_list_reverse (queue->head);
}
/**
* g_queue_copy:
* @queue: a #GQueue
*
* Copies a @queue. Note that is a shallow copy. If the elements in the
* queue consist of pointers to data, the pointers are copied, but the
* actual data is not.
*
* Returns: a copy of @queue
*
* Since: 2.4
*/
GQueue *
g_queue_copy (GQueue *queue)
{
GQueue *result;
GList *list;
g_return_val_if_fail (queue != NULL, NULL);
result = g_queue_new ();
for (list = queue->head; list != NULL; list = list->next)
g_queue_push_tail (result, list->data);
return result;
}
/**
* g_queue_foreach:
* @queue: a #GQueue
* @func: the function to call for each element's data
* @user_data: user data to pass to @func
*
* Calls @func for each element in the queue passing @user_data to the
* function.
*
* Since: 2.4
*/
void
g_queue_foreach (GQueue *queue,
GFunc func,
gpointer user_data)
{
GList *list;
g_return_if_fail (queue != NULL);
g_return_if_fail (func != NULL);
list = queue->head;
while (list)
{
GList *next = list->next;
func (list->data, user_data);
list = next;
}
}
/**
* g_queue_find:
* @queue: a #GQueue
* @data: data to find
*
* Finds the first link in @queue which contains @data.
*
* Returns: the first link in @queue which contains @data
*
* Since: 2.4
*/
GList *
g_queue_find (GQueue *queue,
gconstpointer data)
{
g_return_val_if_fail (queue != NULL, NULL);
return g_list_find (queue->head, data);
}
/**
* g_queue_find_custom:
* @queue: a #GQueue
* @data: user data passed to @func
* @func: a #GCompareFunc to call for each element. It should return 0
* when the desired element is found
*
* Finds an element in a #GQueue, using a supplied function to find the
* desired element. It iterates over the queue, calling the given function
* which should return 0 when the desired element is found. The function
* takes two gconstpointer arguments, the #GQueue element's data as the
* first argument and the given user data as the second argument.
*
* Returns: the found link, or %NULL if it wasn't found
*
* Since: 2.4
*/
GList *
g_queue_find_custom (GQueue *queue,
gconstpointer data,
GCompareFunc func)
{
g_return_val_if_fail (queue != NULL, NULL);
g_return_val_if_fail (func != NULL, NULL);
return g_list_find_custom (queue->head, data, func);
}
/**
* g_queue_sort:
* @queue: a #GQueue
* @compare_func: the #GCompareDataFunc used to sort @queue. This function
* is passed two elements of the queue and should return 0 if they are
* equal, a negative value if the first comes before the second, and
* a positive value if the second comes before the first.
* @user_data: user data passed to @compare_func
*
* Sorts @queue using @compare_func.
*
* Since: 2.4
*/
void
g_queue_sort (GQueue *queue,
GCompareDataFunc compare_func,
gpointer user_data)
{
g_return_if_fail (queue != NULL);
g_return_if_fail (compare_func != NULL);
queue->head = g_list_sort_with_data (queue->head, compare_func, user_data);
queue->tail = g_list_last (queue->head);
}
/**
* g_queue_push_head:
* @queue: a #GQueue.
* @data: the data for the new element.
*
* Adds a new element at the head of the queue.
*/
void
g_queue_push_head (GQueue *queue,
gpointer data)
{
g_return_if_fail (queue != NULL);
queue->head = g_list_prepend (queue->head, data);
if (!queue->tail)
queue->tail = queue->head;
queue->length++;
}
/**
* g_queue_push_nth:
* @queue: a #GQueue
* @data: the data for the new element
* @n: the position to insert the new element. If @n is negative or
* larger than the number of elements in the @queue, the element is
* added to the end of the queue.
*
* Inserts a new element into @queue at the given position.
*
* Since: 2.4
*/
void
g_queue_push_nth (GQueue *queue,
gpointer data,
gint n)
{
g_return_if_fail (queue != NULL);
if (n < 0 || n >= queue->length)
{
g_queue_push_tail (queue, data);
return;
}
g_queue_insert_before (queue, g_queue_peek_nth_link (queue, n), data);
}
/**
* g_queue_push_head_link:
* @queue: a #GQueue
* @link_: a single #GList element, not a list with more than one element
*
* Adds a new element at the head of the queue.
*/
void
g_queue_push_head_link (GQueue *queue,
GList *link)
{
g_return_if_fail (queue != NULL);
g_return_if_fail (link != NULL);
g_return_if_fail (link->prev == NULL);
g_return_if_fail (link->next == NULL);
link->next = queue->head;
if (queue->head)
queue->head->prev = link;
else
queue->tail = link;
queue->head = link;
queue->length++;
}
/**
* g_queue_push_tail:
* @queue: a #GQueue
* @data: the data for the new element
*
* Adds a new element at the tail of the queue.
*/
void
g_queue_push_tail (GQueue *queue,
gpointer data)
{
g_return_if_fail (queue != NULL);
queue->tail = g_list_append (queue->tail, data);
if (queue->tail->next)
queue->tail = queue->tail->next;
else
queue->head = queue->tail;
queue->length++;
}
/**
* g_queue_push_tail_link:
* @queue: a #GQueue
* @link_: a single #GList element, not a list with more than one element
*
* Adds a new element at the tail of the queue.
*/
void
g_queue_push_tail_link (GQueue *queue,
GList *link)
{
g_return_if_fail (queue != NULL);
g_return_if_fail (link != NULL);
g_return_if_fail (link->prev == NULL);
g_return_if_fail (link->next == NULL);
link->prev = queue->tail;
if (queue->tail)
queue->tail->next = link;
else
queue->head = link;
queue->tail = link;
queue->length++;
}
/**
* g_queue_push_nth_link:
* @queue: a #GQueue
* @n: the position to insert the link. If this is negative or larger than
* the number of elements in @queue, the link is added to the end of
* @queue.
* @link_: the link to add to @queue
*
* Inserts @link into @queue at the given position.
*
* Since: 2.4
*/
void
g_queue_push_nth_link (GQueue *queue,
gint n,
GList *link_)
{
GList *next;
GList *prev;
g_return_if_fail (queue != NULL);
g_return_if_fail (link_ != NULL);
if (n < 0 || n >= queue->length)
{
g_queue_push_tail_link (queue, link_);
return;
}
g_assert (queue->head);
g_assert (queue->tail);
next = g_queue_peek_nth_link (queue, n);
prev = next->prev;
if (prev)
prev->next = link_;
next->prev = link_;
link_->next = next;
link_->prev = prev;
if (queue->head->prev)
queue->head = queue->head->prev;
if (queue->tail->next)
queue->tail = queue->tail->next;
queue->length++;
}
/**
* g_queue_pop_head:
* @queue: a #GQueue
*
* Removes the first element of the queue and returns its data.
*
* Returns: the data of the first element in the queue, or %NULL
* if the queue is empty
*/
gpointer
g_queue_pop_head (GQueue *queue)
{
g_return_val_if_fail (queue != NULL, NULL);
if (queue->head)
{
GList *node = queue->head;
gpointer data = node->data;
queue->head = node->next;
if (queue->head)
queue->head->prev = NULL;
else
queue->tail = NULL;
g_list_free_1 (node);
queue->length--;
return data;
}
return NULL;
}
/**
* g_queue_pop_head_link:
* @queue: a #GQueue
*
* Removes and returns the first element of the queue.
*
* Returns: the #GList element at the head of the queue, or %NULL
* if the queue is empty
*/
GList *
g_queue_pop_head_link (GQueue *queue)
{
g_return_val_if_fail (queue != NULL, NULL);
if (queue->head)
{
GList *node = queue->head;
queue->head = node->next;
if (queue->head)
{
queue->head->prev = NULL;
node->next = NULL;
}
else
queue->tail = NULL;
queue->length--;
return node;
}
return NULL;
}
/**
* g_queue_peek_head_link:
* @queue: a #GQueue
*
* Returns the first link in @queue.
*
* Returns: the first link in @queue, or %NULL if @queue is empty
*
* Since: 2.4
*/
GList *
g_queue_peek_head_link (GQueue *queue)
{
g_return_val_if_fail (queue != NULL, NULL);
return queue->head;
}
/**
* g_queue_peek_tail_link:
* @queue: a #GQueue
*
* Returns the last link in @queue.
*
* Returns: the last link in @queue, or %NULL if @queue is empty
*
* Since: 2.4
*/
GList *
g_queue_peek_tail_link (GQueue *queue)
{
g_return_val_if_fail (queue != NULL, NULL);
return queue->tail;
}
/**
* g_queue_pop_tail:
* @queue: a #GQueue
*
* Removes the last element of the queue and returns its data.
*
* Returns: the data of the last element in the queue, or %NULL
* if the queue is empty
*/
gpointer
g_queue_pop_tail (GQueue *queue)
{
g_return_val_if_fail (queue != NULL, NULL);
if (queue->tail)
{
GList *node = queue->tail;
gpointer data = node->data;
queue->tail = node->prev;
if (queue->tail)
queue->tail->next = NULL;
else
queue->head = NULL;
queue->length--;
g_list_free_1 (node);
return data;
}
return NULL;
}
/**
* g_queue_pop_nth:
* @queue: a #GQueue
* @n: the position of the element
*
* Removes the @n'th element of @queue and returns its data.
*
* Returns: the element's data, or %NULL if @n is off the end of @queue
*
* Since: 2.4
*/
gpointer
g_queue_pop_nth (GQueue *queue,
guint n)
{
GList *nth_link;
gpointer result;
g_return_val_if_fail (queue != NULL, NULL);
if (n >= queue->length)
return NULL;
nth_link = g_queue_peek_nth_link (queue, n);
result = nth_link->data;
g_queue_delete_link (queue, nth_link);
return result;
}
/**
* g_queue_pop_tail_link:
* @queue: a #GQueue
*
* Removes and returns the last element of the queue.
*
* Returns: the #GList element at the tail of the queue, or %NULL
* if the queue is empty
*/
GList *
g_queue_pop_tail_link (GQueue *queue)
{
g_return_val_if_fail (queue != NULL, NULL);
if (queue->tail)
{
GList *node = queue->tail;
queue->tail = node->prev;
if (queue->tail)
{
queue->tail->next = NULL;
node->prev = NULL;
}
else
queue->head = NULL;
queue->length--;
return node;
}
return NULL;
}
/**
* g_queue_pop_nth_link:
* @queue: a #GQueue
* @n: the link's position
*
* Removes and returns the link at the given position.
*
* Returns: the @n'th link, or %NULL if @n is off the end of @queue
*
* Since: 2.4
*/
GList*
g_queue_pop_nth_link (GQueue *queue,
guint n)
{
GList *link;
g_return_val_if_fail (queue != NULL, NULL);
if (n >= queue->length)
return NULL;
link = g_queue_peek_nth_link (queue, n);
g_queue_unlink (queue, link);
return link;
}
/**
* g_queue_peek_nth_link:
* @queue: a #GQueue
* @n: the position of the link
*
* Returns the link at the given position
*
* Returns: the link at the @n'th position, or %NULL
* if @n is off the end of the list
*
* Since: 2.4
*/
GList *
g_queue_peek_nth_link (GQueue *queue,
guint n)
{
GList *link;
gint i;
g_return_val_if_fail (queue != NULL, NULL);
if (n >= queue->length)
return NULL;
if (n > queue->length / 2)
{
n = queue->length - n - 1;
link = queue->tail;
for (i = 0; i < n; ++i)
link = link->prev;
}
else
{
link = queue->head;
for (i = 0; i < n; ++i)
link = link->next;
}
return link;
}
/**
* g_queue_link_index:
* @queue: a #GQueue
* @link_: a #GList link
*
* Returns the position of @link_ in @queue.
*
* Returns: the position of @link_, or -1 if the link is
* not part of @queue
*
* Since: 2.4
*/
gint
g_queue_link_index (GQueue *queue,
GList *link_)
{
g_return_val_if_fail (queue != NULL, -1);
return g_list_position (queue->head, link_);
}
/**
* g_queue_unlink:
* @queue: a #GQueue
* @link_: a #GList link that must be part of @queue
*
* Unlinks @link_ so that it will no longer be part of @queue.
* The link is not freed.
*
* @link_ must be part of @queue.
*
* Since: 2.4
*/
void
g_queue_unlink (GQueue *queue,
GList *link_)
{
g_return_if_fail (queue != NULL);
g_return_if_fail (link_ != NULL);
if (link_ == queue->tail)
queue->tail = queue->tail->prev;
queue->head = g_list_remove_link (queue->head, link_);
queue->length--;
}
/**
* g_queue_delete_link:
* @queue: a #GQueue
* @link_: a #GList link that must be part of @queue
*
* Removes @link_ from @queue and frees it.
*
* @link_ must be part of @queue.
*
* Since: 2.4
*/
void
g_queue_delete_link (GQueue *queue,
GList *link_)
{
g_return_if_fail (queue != NULL);
g_return_if_fail (link_ != NULL);
g_queue_unlink (queue, link_);
g_list_free (link_);
}
/**
* g_queue_peek_head:
* @queue: a #GQueue
*
* Returns the first element of the queue.
*
* Returns: the data of the first element in the queue, or %NULL
* if the queue is empty
*/
gpointer
g_queue_peek_head (GQueue *queue)
{
g_return_val_if_fail (queue != NULL, NULL);
return queue->head ? queue->head->data : NULL;
}
/**
* g_queue_peek_tail:
* @queue: a #GQueue
*
* Returns the last element of the queue.
*
* Returns: the data of the last element in the queue, or %NULL
* if the queue is empty
*/
gpointer
g_queue_peek_tail (GQueue *queue)
{
g_return_val_if_fail (queue != NULL, NULL);
return queue->tail ? queue->tail->data : NULL;
}
/**
* g_queue_peek_nth:
* @queue: a #GQueue
* @n: the position of the element
*
* Returns the @n'th element of @queue.
*
* Returns: the data for the @n'th element of @queue,
* or %NULL if @n is off the end of @queue
*
* Since: 2.4
*/
gpointer
g_queue_peek_nth (GQueue *queue,
guint n)
{
GList *link;
g_return_val_if_fail (queue != NULL, NULL);
link = g_queue_peek_nth_link (queue, n);
if (link)
return link->data;
return NULL;
}
/**
* g_queue_index:
* @queue: a #GQueue
* @data: the data to find
*
* Returns the position of the first element in @queue which contains @data.
*
* Returns: the position of the first element in @queue which
* contains @data, or -1 if no element in @queue contains @data
*
* Since: 2.4
*/
gint
g_queue_index (GQueue *queue,
gconstpointer data)
{
g_return_val_if_fail (queue != NULL, -1);
return g_list_index (queue->head, data);
}
/**
* g_queue_remove:
* @queue: a #GQueue
* @data: the data to remove
*
* Removes the first element in @queue that contains @data.
*
* Returns: %TRUE if @data was found and removed from @queue
*
* Since: 2.4
*/
gboolean
g_queue_remove (GQueue *queue,
gconstpointer data)
{
GList *link;
g_return_val_if_fail (queue != NULL, FALSE);
link = g_list_find (queue->head, data);
if (link)
g_queue_delete_link (queue, link);
return (link != NULL);
}
/**
* g_queue_remove_all:
* @queue: a #GQueue
* @data: the data to remove
*
* Remove all elements whose data equals @data from @queue.
*
* Returns: the number of elements removed from @queue
*
* Since: 2.4
*/
guint
g_queue_remove_all (GQueue *queue,
gconstpointer data)
{
GList *list;
guint old_length;
g_return_val_if_fail (queue != NULL, 0);
old_length = queue->length;
list = queue->head;
while (list)
{
GList *next = list->next;
if (list->data == data)
g_queue_delete_link (queue, list);
list = next;
}
return (old_length - queue->length);
}
/**
* g_queue_insert_before:
* @queue: a #GQueue
* @sibling: (nullable): a #GList link that must be part of @queue, or %NULL to
* push at the tail of the queue.
* @data: the data to insert
*
* Inserts @data into @queue before @sibling.
*
* @sibling must be part of @queue. Since GLib 2.44 a %NULL sibling pushes the
* data at the tail of the queue.
*
* Since: 2.4
*/
void
g_queue_insert_before (GQueue *queue,
GList *sibling,
gpointer data)
{
g_return_if_fail (queue != NULL);
if (sibling == NULL)
{
/* We don't use g_list_insert_before() with a NULL sibling because it
* would be a O(n) operation and we would need to update manually the tail
* pointer.
*/
g_queue_push_tail (queue, data);
}
else
{
queue->head = g_list_insert_before (queue->head, sibling, data);
queue->length++;
}
}
/**
* g_queue_insert_after:
* @queue: a #GQueue
* @sibling: (nullable): a #GList link that must be part of @queue, or %NULL to
* push at the head of the queue.
* @data: the data to insert
*
* Inserts @data into @queue after @sibling.
*
* @sibling must be part of @queue. Since GLib 2.44 a %NULL sibling pushes the
* data at the head of the queue.
*
* Since: 2.4
*/
void
g_queue_insert_after (GQueue *queue,
GList *sibling,
gpointer data)
{
g_return_if_fail (queue != NULL);
if (sibling == NULL)
g_queue_push_head (queue, data);
else
g_queue_insert_before (queue, sibling->next, data);
}
/**
* g_queue_insert_sorted:
* @queue: a #GQueue
* @data: the data to insert
* @func: the #GCompareDataFunc used to compare elements in the queue. It is
* called with two elements of the @queue and @user_data. It should
* return 0 if the elements are equal, a negative value if the first
* element comes before the second, and a positive value if the second
* element comes before the first.
* @user_data: user data passed to @func
*
* Inserts @data into @queue using @func to determine the new position.
*
* Since: 2.4
*/
void
g_queue_insert_sorted (GQueue *queue,
gpointer data,
GCompareDataFunc func,
gpointer user_data)
{
GList *list;
g_return_if_fail (queue != NULL);
list = queue->head;
while (list && func (list->data, data, user_data) < 0)
list = list->next;
g_queue_insert_before (queue, list, data);
}
|
02245dcc9ceb6cacecad5e84f469ad31461fcc18
|
e1d9c54e9925e30e388a255b53a93cccad0b94cb
|
/kubernetes/unit-test/test_v1_self_subject_rules_review.c
|
2c122aa6251e57d436b09436705632f531208b9a
|
[
"Apache-2.0",
"curl"
] |
permissive
|
kubernetes-client/c
|
dd4fd8095485c083e0f40f2b48159b1609a6141b
|
5ac5ff25e9809a92a48111b1f77574b6d040b711
|
refs/heads/master
| 2023-08-13T10:51:03.702497
| 2023-08-07T19:18:32
| 2023-08-07T19:18:32
| 247,958,425
| 127
| 47
|
Apache-2.0
| 2023-09-07T20:07:00
| 2020-03-17T11:59:05
|
C
|
UTF-8
|
C
| false
| false
| 2,482
|
c
|
test_v1_self_subject_rules_review.c
|
#ifndef v1_self_subject_rules_review_TEST
#define v1_self_subject_rules_review_TEST
// the following is to include only the main from the first c file
#ifndef TEST_MAIN
#define TEST_MAIN
#define v1_self_subject_rules_review_MAIN
#endif // TEST_MAIN
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <stdbool.h>
#include "../external/cJSON.h"
#include "../model/v1_self_subject_rules_review.h"
v1_self_subject_rules_review_t* instantiate_v1_self_subject_rules_review(int include_optional);
#include "test_v1_object_meta.c"
#include "test_v1_self_subject_rules_review_spec.c"
#include "test_v1_subject_rules_review_status.c"
v1_self_subject_rules_review_t* instantiate_v1_self_subject_rules_review(int include_optional) {
v1_self_subject_rules_review_t* v1_self_subject_rules_review = NULL;
if (include_optional) {
v1_self_subject_rules_review = v1_self_subject_rules_review_create(
"0",
"0",
// false, not to have infinite recursion
instantiate_v1_object_meta(0),
// false, not to have infinite recursion
instantiate_v1_self_subject_rules_review_spec(0),
// false, not to have infinite recursion
instantiate_v1_subject_rules_review_status(0)
);
} else {
v1_self_subject_rules_review = v1_self_subject_rules_review_create(
"0",
"0",
NULL,
NULL,
NULL
);
}
return v1_self_subject_rules_review;
}
#ifdef v1_self_subject_rules_review_MAIN
void test_v1_self_subject_rules_review(int include_optional) {
v1_self_subject_rules_review_t* v1_self_subject_rules_review_1 = instantiate_v1_self_subject_rules_review(include_optional);
cJSON* jsonv1_self_subject_rules_review_1 = v1_self_subject_rules_review_convertToJSON(v1_self_subject_rules_review_1);
printf("v1_self_subject_rules_review :\n%s\n", cJSON_Print(jsonv1_self_subject_rules_review_1));
v1_self_subject_rules_review_t* v1_self_subject_rules_review_2 = v1_self_subject_rules_review_parseFromJSON(jsonv1_self_subject_rules_review_1);
cJSON* jsonv1_self_subject_rules_review_2 = v1_self_subject_rules_review_convertToJSON(v1_self_subject_rules_review_2);
printf("repeating v1_self_subject_rules_review:\n%s\n", cJSON_Print(jsonv1_self_subject_rules_review_2));
}
int main() {
test_v1_self_subject_rules_review(1);
test_v1_self_subject_rules_review(0);
printf("Hello world \n");
return 0;
}
#endif // v1_self_subject_rules_review_MAIN
#endif // v1_self_subject_rules_review_TEST
|
fd7fe614ccc56550758f852b8d412d6f1ab80321
|
ea401c3e792a50364fe11f7cea0f35f99e8f4bde
|
/released_plugins/v3d_plugins/neurontracing_neutube/src_neutube/neurolabi/c/tz_complex.h
|
a46c939e0ea8a676fd55e644c379d76e9b14a29c
|
[
"BSD-2-Clause",
"MIT",
"GPL-1.0-or-later",
"LicenseRef-scancode-unknown-license-reference",
"GPL-2.0-only"
] |
permissive
|
Vaa3D/vaa3d_tools
|
edb696aa3b9b59acaf83d6d27c6ae0a14bf75fe9
|
e6974d5223ae70474efaa85e1253f5df1814fae8
|
refs/heads/master
| 2023-08-03T06:12:01.013752
| 2023-08-02T07:26:01
| 2023-08-02T07:26:01
| 50,527,925
| 107
| 86
|
MIT
| 2023-05-22T23:43:48
| 2016-01-27T18:19:17
|
C++
|
UTF-8
|
C
| false
| false
| 940
|
h
|
tz_complex.h
|
/**@file tz_complex.h
* @brief complex number
* @author Ting Zhao
*/
#ifndef _TZ_COMPLEX_H_
#define _TZ_COMPLEX_H_
#include "tz_fftw_header.h"
/* Complex operation routines */
/*
* The functions include:
*
* Add, subtract or multiply two an array and a constant;
* Add, subtrace or multiply two arrays;
* Conjugate of a complex number or array;
* print an array.
*/
#define COMPLEX_DEFINE_API(X, C) \
void X(add)(C c1,const C c2); \
void X(csub)(C c1,const C c2); \
void X(cmul)(C c1,const C c2); \
void X(conjg)(C c); \
C* X(cadd_array)(C* c1,C* c2,long length); \
C* X(csub_array)(C* c1,C* c2,long length); \
C* X(cmul_array)(C* c1,C* c2,long length); \
C* X(conjg_array)(C* c,long length); \
void X(print)(C *c,long length);
/* end of COMPLEX_DEFINE_API macro */
COMPLEX_DEFINE_API(FFTW_MANGLE_DOUBLE,fftw_complex)
COMPLEX_DEFINE_API(FFTW_MANGLE_FLOAT,fftwf_complex)
#endif
|
76d6edf3c403a9029195f5956d0dbfef925f5e63
|
5268ffdcab74cf5d9f42039908e3d50fe4dd46db
|
/pgwaitevent.c
|
bc9640291fd4e964cb5cabdc00e9ada00f0fc08d
|
[
"PostgreSQL"
] |
permissive
|
gleu/pgstats
|
fd87b24ad72f587142f2a20a5d196d7efd52b696
|
ea1242361057550397aefca40c0f0398ee49f40f
|
refs/heads/master
| 2023-07-09T20:48:53.398056
| 2023-06-28T20:28:49
| 2023-06-29T06:19:05
| 1,406,321
| 112
| 17
|
NOASSERTION
| 2023-06-29T06:21:12
| 2011-02-24T11:02:34
|
C
|
UTF-8
|
C
| false
| false
| 18,472
|
c
|
pgwaitevent.c
|
/*
* pgwaitevent, a PostgreSQL app to gather statistical informations
* on wait events of PostgreSQL PID backend.
*
* This software is released under the PostgreSQL Licence.
*
* Guillaume Lelarge, guillaume@lelarge.info, 2019-2023.
*
* pgstats/pgwaitevent.c
*/
/*
* Headers
*/
#include "postgres_fe.h"
#include "common/string.h"
#include <err.h>
#include <sys/ioctl.h>
#include <sys/signal.h>
#include <sys/stat.h>
#include <unistd.h>
#ifdef HAVE_GETOPT_H
#include <getopt.h>
#endif
#include "postgres_fe.h"
#include "common/username.h"
#include "common/logging.h"
#include "fe_utils/cancel.h"
#include "fe_utils/connect_utils.h"
#include "fe_utils/option_utils.h"
#include "fe_utils/query_utils.h"
#include "fe_utils/simple_list.h"
#include "fe_utils/string_utils.h"
#include "libpq-fe.h"
#include "libpq/pqsignal.h"
/*
* Defines
*/
#define PGWAITEVENT_VERSION "1.2.0"
#define PGWAITEVENT_DEFAULT_LINES 20
#define PGWAITEVENT_DEFAULT_STRING_SIZE 2048
/*
* Structs
*/
/* these are the options structure for command line parameters */
struct options
{
/* misc */
bool verbose;
/* connection parameters */
char *dbname;
char *hostname;
char *port;
char *username;
/* version number */
int major;
int minor;
/* pid */
int pid;
/* include leader and workers PIDs */
bool includeleaderworkers;
/* frequency */
float interval;
/* query and trace timestamps */
char *query_start;
char *trace_start;
};
/*
* Global variables
*/
PGconn *conn;
struct options *opts;
extern char *optarg;
/*
* Function prototypes
*/
static void help(const char *progname);
void get_opts(int, char **);
#ifndef FE_MEMUTILS_H
void *pg_malloc(size_t size);
char *pg_strdup(const char *in);
#endif
void fetch_version(void);
bool backend_minimum_version(int major, int minor);
void build_env(void);
bool active_session(void);
void handle_current_query(void);
void drop_env(void);
static void quit_properly(SIGNAL_ARGS);
/*
* Print help message
*/
static void
help(const char *progname)
{
printf("%s gathers every wait events from a specific PID, grouping them by queries.\n\n"
"Usage:\n"
" %s [OPTIONS] PID\n"
"\nGeneral options:\n"
" -g include leader and workers (parallel queries) [v13+]\n"
" -i interval (default is 1s)\n"
" -v verbose\n"
" -?|--help show this help, then exit\n"
" -V|--version output version information, then exit\n"
"\nConnection options:\n"
" -h HOSTNAME database server host or socket directory\n"
" -p PORT database server port number\n"
" -U USER connect as specified database user\n"
" -d DBNAME database to connect to\n\n"
"Report bugs to <guillaume@lelarge.info>.\n",
progname, progname);
}
/*
* Parse command line options and check for some usage errors
*/
void
get_opts(int argc, char **argv)
{
int c;
const char *progname;
progname = get_progname(argv[0]);
/* set the defaults */
opts->verbose = false;
opts->dbname = NULL;
opts->hostname = NULL;
opts->port = NULL;
opts->username = NULL;
opts->pid = 0;
opts->includeleaderworkers = false;
opts->interval = 1;
/* we should deal quickly with help and version */
if (argc > 1)
{
if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
{
help(progname);
exit(0);
}
if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
{
puts("pgwaitevent " PGWAITEVENT_VERSION " (compiled with PostgreSQL " PG_VERSION ")");
exit(0);
}
}
/* get options */
while ((c = getopt(argc, argv, "h:p:U:d:i:gv")) != -1)
{
switch (c)
{
/* specify the database */
case 'd':
opts->dbname = pg_strdup(optarg);
break;
/* host to connect to */
case 'h':
opts->hostname = pg_strdup(optarg);
break;
/* parallel queries */
case 'g':
opts->includeleaderworkers = true;
break;
/* interval */
case 'i':
opts->interval = atof(optarg);
break;
/* port to connect to on remote host */
case 'p':
opts->port = pg_strdup(optarg);
break;
/* username */
case 'U':
opts->username = pg_strdup(optarg);
break;
/* get verbose */
case 'v':
opts->verbose = true;
break;
default:
pg_log_error("Try \"%s --help\" for more information.\n", progname);
exit(EXIT_FAILURE);
}
}
/* get PID to monitor */
if (optind < argc)
{
opts->pid = atoi(argv[optind]);
}
else
{
pg_log_error("PID required.\n");
pg_log_info("Try \"%s --help\" for more information.\n", progname);
exit(EXIT_FAILURE);
}
/* set dbname if unset */
if (opts->dbname == NULL)
{
/*
* We want to use dbname for possible error reports later,
* and in case someone has set and is using PGDATABASE
* in its environment, preserve that name for later usage
*/
if (!getenv("PGDATABASE"))
opts->dbname = "postgres";
else
opts->dbname = getenv("PGDATABASE");
}
}
#ifndef FE_MEMUTILS_H
/*
* "Safe" wrapper around malloc().
*/
void *
pg_malloc(size_t size)
{
void *tmp;
/* Avoid unportable behavior of malloc(0) */
if (size == 0)
size = 1;
tmp = malloc(size);
if (!tmp)
{
pg_log_error("out of memory (pg_malloc)\n");
exit(EXIT_FAILURE);
}
return tmp;
}
/*
* "Safe" wrapper around strdup().
*/
char *
pg_strdup(const char *in)
{
char *tmp;
if (!in)
{
pg_log_error("cannot duplicate null pointer (internal error)\n");
exit(EXIT_FAILURE);
}
tmp = strdup(in);
if (!tmp)
{
pg_log_error("out of memory (pg_strdup)\n");
exit(EXIT_FAILURE);
}
return tmp;
}
#endif
/*
* Fetch PostgreSQL major and minor numbers
*/
void
fetch_version()
{
char sql[PGWAITEVENT_DEFAULT_STRING_SIZE];
PGresult *res;
/* get the cluster version */
snprintf(sql, sizeof(sql), "SELECT version()");
/* make the call */
res = PQexec(conn, sql);
/* check and deal with errors */
if (!res || PQresultStatus(res) > 2)
{
pg_log_error("query failed: %s", PQerrorMessage(conn));
pg_log_info("query was: %s", sql);
PQclear(res);
PQfinish(conn);
exit(EXIT_FAILURE);
}
/* get the only row, and parse it to get major and minor numbers */
sscanf(PQgetvalue(res, 0, 0), "%*s %d.%d", &(opts->major), &(opts->minor));
/* print version */
if (opts->verbose)
printf("Detected release: %d.%d\n", opts->major, opts->minor);
/* cleanup */
PQclear(res);
}
/*
* Compare given major and minor numbers to the one of the connected server
*/
bool
backend_minimum_version(int major, int minor)
{
return opts->major > major || (opts->major == major && opts->minor >= minor);
}
/*
* Close the PostgreSQL connection, and quit
*/
static void
quit_properly(SIGNAL_ARGS)
{
drop_env();
PQfinish(conn);
exit(EXIT_FAILURE);
}
/*
* Create function
*/
void
build_env()
{
char sql[PGWAITEVENT_DEFAULT_STRING_SIZE];
PGresult *res;
/* build the DDL query */
snprintf(sql, sizeof(sql),
"CREATE TEMPORARY TABLE waitevents (we text, wet text, o integer);\n"
"ALTER TABLE waitevents ADD UNIQUE(we, wet);\n");
/* make the call */
res = PQexec(conn, sql);
/* check and deal with errors */
if (!res || PQresultStatus(res) > 2)
{
pg_log_error("query failed: %s", PQerrorMessage(conn));
pg_log_info("query was: %s", sql);
PQclear(res);
PQfinish(conn);
exit(EXIT_FAILURE);
}
/* print verbose */
if (opts->verbose)
printf("Temporary table created\n");
/* cleanup */
PQclear(res);
/* build the DDL query */
snprintf(sql, sizeof(sql), "CREATE SCHEMA pgwaitevent;");
/* make the call */
res = PQexec(conn, sql);
/* check and deal with errors */
if (!res || PQresultStatus(res) > 2)
{
pg_log_error("query failed: %s", PQerrorMessage(conn));
pg_log_info("query was: %s", sql);
PQclear(res);
PQfinish(conn);
exit(EXIT_FAILURE);
}
/* print verbose */
if (opts->verbose)
printf("Schema created\n");
/* build the DDL query */
snprintf(sql, sizeof(sql),
"CREATE OR REPLACE FUNCTION pgwaitevent.trace_wait_events_for_pid(p integer, leader boolean, s numeric default 1)\n"
"RETURNS TABLE (wait_event text, wait_event_type text, occurences integer, percent numeric(5,2))\n"
"LANGUAGE plpgsql\n"
"AS $$\n"
"DECLARE\n"
" q text;\n"
" r record;\n"
"BEGIN\n"
" -- check it is a backend\n"
" SELECT query INTO q FROM pg_stat_activity\n"
" WHERE pid=p AND backend_type='client backend' AND state='active';\n"
"\n"
" IF NOT FOUND THEN\n"
" RAISE EXCEPTION 'PID %% doesn''t appear to be an active backend', p\n"
" USING HINT = 'Check the PID and its state';\n"
" END IF;\n"
"\n"
" -- logging\n"
" RAISE LOG 'Tracing PID %%, sampling at %%s', p, s;\n"
" RAISE LOG 'Query is <%%>', q;\n"
"\n"
" -- drop if exists, then create temp table\n"
" TRUNCATE waitevents;\n"
"\n"
" -- loop till the end of the query\n"
" LOOP\n"
" -- get wait event\n"
" IF leader THEN\n"
" SELECT COALESCE(psa.wait_event, '[Running]') AS wait_event,\n"
" COALESCE(psa.wait_event_type, '') AS wait_event_type\n"
" INTO r\n"
" FROM pg_stat_activity psa\n"
" WHERE pid=p OR leader_pid=p;\n"
" ELSE\n"
" SELECT COALESCE(psa.wait_event, '[Running]') AS wait_event,\n"
" COALESCE(psa.wait_event_type, '') AS wait_event_type\n"
" INTO r\n"
" FROM pg_stat_activity psa\n"
" WHERE pid=p;\n"
" END IF;\n"
"\n"
" -- loop control\n"
" EXIT WHEN r.wait_event = 'ClientRead';\n"
"\n"
" -- update wait events stats\n"
" INSERT INTO waitevents VALUES (r.wait_event, r.wait_event_type, 1)\n"
" ON CONFLICT (we,wet) DO UPDATE SET o = waitevents.o+1;\n"
"\n"
" -- sleep a bit\n"
" PERFORM pg_sleep(s);\n"
" END LOOP;\n"
"\n"
" -- return stats\n"
" RETURN QUERY\n"
" SELECT we, wet, o, (o*100./sum(o) over ())::numeric(5,2)\n"
" FROM waitevents\n"
" ORDER BY o DESC;\n"
"END\n"
"$$;\n");
/* make the call */
res = PQexec(conn, sql);
/* check and deal with errors */
if (!res || PQresultStatus(res) > 2)
{
pg_log_error("query failed: %s", PQerrorMessage(conn));
pg_log_info("query was: %s", sql);
PQclear(res);
PQfinish(conn);
exit(EXIT_FAILURE);
}
/* print verbose */
if (opts->verbose)
printf("Function created\n");
/* cleanup */
PQclear(res);
}
/*
* Is PID an active session?
*/
bool
active_session()
{
char sql[PGWAITEVENT_DEFAULT_STRING_SIZE];
PGresult *res;
bool active = false;
/* build the query */
snprintf(sql, sizeof(sql),
"SELECT state, query, query_start, now() FROM pg_stat_activity\n"
"WHERE backend_type='client backend'\n"
"AND pid=%d",
opts->pid);
/* make the call */
res = PQexec(conn, sql);
/* check and deal with errors */
if (!res || PQresultStatus(res) > 2)
{
pg_log_error("query failed: %s", PQerrorMessage(conn));
pg_log_info("query was: %s", sql);
PQclear(res);
PQfinish(conn);
exit(EXIT_FAILURE);
}
/* if zero row, then PID is gone */
if (PQntuples(res) == 0)
{
printf("\nNo more session with PID %d, exiting...\n", opts->pid);
drop_env();
PQfinish(conn);
exit(2);
}
/* if one row, we found the good one */
if (PQntuples(res) == 1)
{
if (!strncmp(PQgetvalue(res, 0, 0), "active", 6))
{
active = true;
printf("\nNew query: %s\n", PQgetvalue(res, 0, 1));
opts->query_start = pg_strdup(PQgetvalue(res, 0, 2));
opts->trace_start = pg_strdup(PQgetvalue(res, 0, 3));
}
}
/* this also means that in case of multiple rows, we treat it as no rows */
/* cleanup */
PQclear(res);
return active;
}
/*
* Handle query
*/
void
handle_current_query()
{
char sql[PGWAITEVENT_DEFAULT_STRING_SIZE];
PGresult *workers_res;
PGresult *trace_res;
PGresult *duration_res;
int nrows;
int row;
int nworkers = 0;
if (opts->includeleaderworkers)
{
/* build the workers query if the user asked to include leader and workers */
snprintf(sql, sizeof(sql), "SELECT count(*) FROM pg_stat_activity "
"WHERE pid=%d OR leader_pid=%d",
opts->pid, opts->pid);
/* execute it */
workers_res = PQexec(conn, sql);
/* check and deal with errors */
if (!workers_res || PQresultStatus(workers_res) > 2)
{
pg_log_error("query failed: %s", PQerrorMessage(conn));
pg_log_info("query was: %s", sql);
PQclear(workers_res);
PQfinish(conn);
exit(EXIT_FAILURE);
}
/* get the number of leader and workers */
nworkers = atoi(PQgetvalue(workers_res, 0, 0));
/* clean up */
PQclear(workers_res);
}
/* build the trace query */
snprintf(sql, sizeof(sql), "SELECT * FROM pgwaitevent.trace_wait_events_for_pid(%d, %s, %f);",
opts->pid, opts->includeleaderworkers ? "'t'" : "'f'", opts->interval);
/* execute it */
trace_res = PQexec(conn, sql);
/* check and deal with errors */
if (!trace_res || PQresultStatus(trace_res) > 2)
{
pg_log_error("query failed: %s", PQerrorMessage(conn));
pg_log_info("query was: %s", sql);
PQclear(trace_res);
PQfinish(conn);
exit(EXIT_FAILURE);
}
/* build the duration query */
snprintf(sql, sizeof(sql), "SELECT now()-'%s'::timestamptz, now()-'%s'::timestamptz;",
opts->query_start, opts->trace_start);
/* execute it */
duration_res = PQexec(conn, sql);
/* check and deal with errors */
if (!duration_res || PQresultStatus(duration_res) > 2)
{
pg_log_error("query failed: %s", PQerrorMessage(conn));
pg_log_info("query was: %s", sql);
PQclear(duration_res);
PQfinish(conn);
exit(EXIT_FAILURE);
}
/* show durations */
(void)printf("Query duration: %s\n", PQgetvalue(duration_res, 0, 0));
(void)printf("Trace duration: %s\n", PQgetvalue(duration_res, 0, 1));
/* show number of workers */
if (opts->includeleaderworkers)
{
(void)printf("Number of processes: %d\n", nworkers);
}
/* get the number of rows */
nrows = PQntuples(trace_res);
/* print headers */
(void)printf(
"┌───────────────────────────────────┬───────────┬────────────┬─────────┐\n"
"│ Wait event │ WE type │ Occurences │ Percent │\n"
"├───────────────────────────────────┼───────────┼────────────┼─────────┤\n");
/* for each row, print all columns in a row */
for (row = 0; row < nrows; row++)
{
(void)printf("│ %-33s │ %-9s │ %10ld │ %6.2f │\n",
PQgetvalue(trace_res, row, 0),
PQgetvalue(trace_res, row, 1),
atol(PQgetvalue(trace_res, row, 2)),
atof(PQgetvalue(trace_res, row, 3))
);
}
/* print footers */
(void)printf(
"└───────────────────────────────────┴───────────┴────────────┴─────────┘\n");
/* cleanup */
PQclear(duration_res);
PQclear(trace_res);
}
/*
* Drop env
*/
void
drop_env()
{
char sql[PGWAITEVENT_DEFAULT_STRING_SIZE];
PGresult *res;
/* no need to drop the temp table */
/* drop function */
snprintf(sql, sizeof(sql),
"DROP FUNCTION pgwaitevent.trace_wait_events_for_pid(integer, boolean, numeric)");
/* make the call */
res = PQexec(conn, sql);
/* check and deal with errors */
if (!res || PQresultStatus(res) > 2)
{
pg_log_error("query failed: %s", PQerrorMessage(conn));
pg_log_info("query was: %s", sql);
PQclear(res);
PQfinish(conn);
exit(EXIT_FAILURE);
}
/* print verbose */
if (opts->verbose)
printf("Function dropped\n");
/* drop function */
snprintf(sql, sizeof(sql),
"DROP SCHEMA pgwaitevent");
/* make the call */
res = PQexec(conn, sql);
/* check and deal with errors */
if (!res || PQresultStatus(res) > 2)
{
pg_log_error("query failed: %s", PQerrorMessage(conn));
pg_log_info("query was: %s", sql);
PQclear(res);
PQfinish(conn);
exit(EXIT_FAILURE);
}
/* print verbose */
if (opts->verbose)
printf("Schema dropped\n");
/* cleanup */
PQclear(res);
}
/*
* Main function
*/
int
main(int argc, char **argv)
{
const char *progname;
ConnParams cparams;
/*
* If the user stops the program,
* quit nicely.
*/
pqsignal(SIGINT, quit_properly);
/* Initialize the logging interface */
pg_logging_init(argv[0]);
/* Get the program name */
progname = get_progname(argv[0]);
/* Allocate the options struct */
opts = (struct options *) pg_malloc(sizeof(struct options));
/* Parse the options */
get_opts(argc, argv);
/* Set the connection struct */
cparams.pghost = opts->hostname;
cparams.pgport = opts->port;
cparams.pguser = opts->username;
cparams.dbname = opts->dbname;
cparams.prompt_password = TRI_DEFAULT;
cparams.override_dbname = NULL;
/* Connect to the database */
conn = connectDatabase(&cparams, progname, false, false, false);
/* Fetch version */
fetch_version();
/* Check options */
if (opts->includeleaderworkers && !backend_minimum_version(13, 0))
{
pg_log_error("You need at least v13 to include workers' wait events.");
exit(EXIT_FAILURE);
}
/* Create the trace_wait_events_for_pid function */
build_env();
/* show what we're doing */
printf("Tracing wait events for PID %d, sampling at %.3fs, %s\n",
opts->pid,
opts->interval,
opts->includeleaderworkers ? "including leader and workers" : "PID only");
while(true)
{
if (active_session())
{
/* Handle query currently executed */
handle_current_query();
}
/* wait 100ms */
(void)usleep(100000);
}
/* Drop the function */
drop_env();
PQfinish(conn);
return 0;
}
|
8f857c0a221c598ce454d8a358d3d1124f2fdc93
|
d325e0d8d87128cc86e975a822516604a71294e9
|
/drivers/SAMD21/grblHAL_MKRZERO/src/trinamic/tmc2209.c
|
6b84c953fe57331ee8e09758cd4298c23e75e638
|
[] |
no_license
|
terjeio/grblHAL
|
12b93d229b046bc09c87902c3569767337dd270a
|
cd693465a8d7b9dabf1d85acdf3eba40a0994db1
|
refs/heads/master
| 2022-01-27T19:09:19.281567
| 2021-12-27T06:34:25
| 2021-12-27T06:34:25
| 142,401,894
| 251
| 104
| null | 2021-03-18T06:16:59
| 2018-07-26T07:00:52
|
C
|
UTF-8
|
C
| false
| false
| 12,355
|
c
|
tmc2209.c
|
/*
* tmc2209.c - interface for Trinamic TMC2209 stepper driver
*
* v0.0.2 / 2020-12-26 / (c) Io Engineering / Terje
*/
/*
Copyright (c) 2020, Terje Io
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
* Neither the name of the copyright holder nor the names of its contributors may
be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 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.
*/
/*
* Reference for calculations:
* https://www.trinamic.com/fileadmin/assets/Products/ICs_Documents/TMC5130_TMC2209_TMC2100_Calculations.xlsx
*
*/
#include <string.h>
#include "tmc2209.h"
static const TMC2209_t tmc2209_defaults = {
.config.f_clk = TMC2209_F_CLK,
.config.cool_step_enabled = TMC2209_COOLSTEP_ENABLE,
.config.r_sense = TMC2209_R_SENSE,
.config.current = TMC2209_CURRENT,
.config.hold_current_pct = TMC2209_HOLD_CURRENT_PCT,
.config.microsteps = TMC2209_MICROSTEPS,
// register adresses
.gconf.addr.reg = TMC2209Reg_GCONF,
.stat.addr.reg = TMC2209Reg_GSTAT,
.ifcnt.addr.reg = TMC2209Reg_IFCNT,
.slaveconf.addr.reg = TMC2209Reg_SLAVECONF,
.otp_prog.addr.reg = TMC2209Reg_OTP_PROG,
.otp_read.addr.reg = TMC2209Reg_OTP_READ,
.ioin.addr.reg = TMC2209Reg_IOIN,
.factory_conf.addr.reg = TMC2209Reg_FACTORY_CONF,
.ihold_irun.addr.reg = TMC2209Reg_IHOLD_IRUN,
.tpowerdown.addr.reg = TMC2209Reg_TPOWERDOWN,
.tpowerdown.reg.tpowerdown = 20,
.tstep.addr.reg = TMC2209Reg_TSTEP,
.tpwmthrs.addr.reg = TMC2209Reg_TPWMTHRS,
.tpwmthrs.addr.reg = TMC2209Reg_TPWMTHRS,
.vactual.addr.reg = TMC2209Reg_VACTUAL,
.tcoolthrs.addr.reg = TMC2209Reg_TCOOLTHRS,
.sgthrs.addr.reg = TMC2209Reg_SGTHRS,
.sg_result.addr.reg = TMC2209Reg_SG_RESULT,
.coolconf.addr.reg = TMC2209Reg_COOLCONF,
.mscnt.addr.reg = TMC2209Reg_MSCNT,
.mscuract.addr.reg = TMC2209Reg_MSCURACT,
.chopconf.addr.reg = TMC2209Reg_CHOPCONF,
.chopconf.reg.value = 0x10000053,
.drv_status.addr.reg = TMC2209Reg_DRV_STATUS,
.pwmconf.addr.reg = TMC2209Reg_PWMCONF,
.pwmconf.reg.value = 0xC10D0024,
.pwm_scale.addr.reg = TMC2209Reg_PWM_SCALE,
.pwm_auto.addr.reg = TMC2209Reg_PWM_AUTO
};
static void set_tfd (TMC2209_chopconf_reg_t *chopconf, uint8_t fast_decay_time)
{
//! chopconf->chm = 1;
//! chopconf->fd3 = (fast_decay_time & 0x8) >> 3;
chopconf->hstrt = fast_decay_time & 0x7;
}
void TMC2209_SetDefaults (TMC2209_t *driver)
{
memcpy(driver, &tmc2209_defaults, sizeof(TMC2209_t));
driver->chopconf.reg.mres = tmc_microsteps_to_mres(driver->config.microsteps);
}
bool TMC2209_Init (TMC2209_t *driver)
{
// Perform a status register read to clear reset flag and read OTP defaults
// If no or bad response from driver return with error.
if(!TMC2209_ReadRegister(driver, (TMC2209_datagram_t *)&driver->stat))
return false;
// TMC2209_ReadRegister(driver, (TMC2209_datagram_t *)&driver->otp_read);
// driver->gconf.reg.internal_Rsense = driver->otp_read.reg.otp0_6;
TMC2209_ReadRegister(driver, (TMC2209_datagram_t *)&driver->chopconf);
TMC2209_ReadRegister(driver, (TMC2209_datagram_t *)&driver->gconf);
driver->gconf.reg.pdn_disable = 1;
driver->gconf.reg.mstep_reg_select = 1;
// driver->gconf.reg.I_scale_analog = 1;
// driver->gconf.reg.internal_Rsense = 0;
// driver->gconf.reg.en_spreadcycle = 0;
// driver->gconf.reg.multistep_filt = 1;
TMC2209_ReadRegister(driver, (TMC2209_datagram_t *)&driver->ifcnt);
uint8_t ifcnt = driver->ifcnt.reg.count;
TMC2209_WriteRegister(driver, (TMC2209_datagram_t *)&driver->gconf);
driver->chopconf.reg.mres = tmc_microsteps_to_mres(driver->config.microsteps);
TMC2209_WriteRegister(driver, (TMC2209_datagram_t *)&driver->chopconf);
driver->ihold_irun.reg.iholddelay = 1; // otp
TMC2209_WriteRegister(driver, (TMC2209_datagram_t *)&driver->ihold_irun);
TMC2209_WriteRegister(driver, (TMC2209_datagram_t *)&driver->tpowerdown);
TMC2209_WriteRegister(driver, (TMC2209_datagram_t *)&driver->pwmconf);
/* TMC2209_WriteRegister(driver, (TMC2209_datagram_t *)&driver->coolconf);
TMC2209_WriteRegister(driver, (TMC2209_datagram_t *)&driver->ihold_irun);
TMC2209_WriteRegister(driver, (TMC2209_datagram_t *)&driver->tpwmthrs);
TMC2209_SetCurrent(driver, driver->current, driver->hold_current_pct); */
//set to a conservative start value
//TMC2209_SetConstantOffTimeChopper(driver, 5, 24, 13, 12, true); // move to default values
TMC2209_ReadRegister(driver, (TMC2209_datagram_t *)&driver->ifcnt);
return driver->ifcnt.reg.count - ifcnt == 5;
}
uint16_t TMC2209_GetCurrent (TMC2209_t *driver)
{
return (uint16_t)((float)(driver->ihold_irun.reg.irun + 1) / 32.0f * (driver->chopconf.reg.vsense ? 180.0f : 325.0f) / (float)(driver->config.r_sense + 20) / 1.41421f * 1000.0f);
}
// r_sense = mOhm, Vsense = mV, current = mA (RMS)
void TMC2209_SetCurrent (TMC2209_t *driver, uint16_t mA, uint8_t hold_pct)
{
driver->config.current = mA;
driver->config.hold_current_pct = hold_pct;
float maxv = (((float)(driver->config.r_sense + 20)) * (float)(32UL * driver->config.current)) * 1.41421f / 1000.0f;
uint8_t current_scaling = (uint8_t)(maxv / 325.0f) - 1;
// If the current scaling is too low set the vsense bit and recalculate the current setting
if ((driver->chopconf.reg.vsense = (current_scaling < 16)))
current_scaling = (uint8_t)(maxv / 180.0f) - 1;
driver->ihold_irun.reg.irun = current_scaling > 31 ? 31 : current_scaling;
driver->ihold_irun.reg.ihold = (driver->ihold_irun.reg.irun * driver->config.hold_current_pct) / 100;
TMC2209_WriteRegister(driver, (TMC2209_datagram_t *)&driver->chopconf);
TMC2209_WriteRegister(driver, (TMC2209_datagram_t *)&driver->ihold_irun);
}
uint32_t TMC2209_GetTPWMTHRS (TMC2209_t *driver, float stpmm)
{
return (uint32_t)((driver->config.microsteps * TMC2209_F_CLK) / (256 * driver->tpwmthrs.reg.tpwmthrs * stpmm));
}
void TMC2209_SetTPWMTHRS (TMC2209_t *driver, uint32_t velocity, float stpmm)
{
driver->tpwmthrs.reg.tpwmthrs = (uint32_t)((driver->config.microsteps * TMC2209_F_CLK) / (256 * velocity * stpmm));
}
// threshold = velocity in mm/s
void TMC2209_SetHybridThreshold (TMC2209_t *driver, uint32_t threshold, float steps_mm)
{
driver->tpwmthrs.reg.tpwmthrs = threshold == 0.0f ? 0UL : driver->config.f_clk * driver->config.microsteps / (256 * (uint32_t)((float)threshold * steps_mm));
TMC2209_WriteRegister(driver, (TMC2209_datagram_t *)&driver->tpwmthrs);
}
void TMC2209_SetTHIGH (TMC2209_t *driver, float mm_sec, float steps_mm) // -> pwm threshold
{
// driver->thigh.reg.thigh = tmc_calc_tstep(driver, mm_sec, steps_mm);
// TMC2209_WriteRegister(driver, (TMC2209_datagram_t *)&driver->thigh);
}
void TMC2209_SetTCOOLTHRS (TMC2209_t *driver, float mm_sec, float steps_mm) // -> pwm threshold
{
driver->tcoolthrs.reg.tcoolthrs = tmc_calc_tstep(&driver->config, mm_sec, steps_mm);
TMC2209_WriteRegister(driver, (TMC2209_datagram_t *)&driver->tcoolthrs);
}
// 1 - 256 in steps of 2^value is valid for TMC2209
bool TMC2209_MicrostepsIsValid (uint16_t usteps)
{
return tmc_microsteps_validate(usteps);
}
void TMC2209_SetMicrosteps (TMC2209_t *driver, tmc2209_microsteps_t msteps)
{
driver->chopconf.reg.mres = tmc_microsteps_to_mres(msteps);
driver->config.microsteps = (tmc2209_microsteps_t)(1 << (8 - driver->chopconf.reg.mres));
// TODO: recalc and set hybrid threshold if enabled?
TMC2209_WriteRegister(driver, (TMC2209_datagram_t *)&driver->chopconf);
}
void TMC2209_SetConstantOffTimeChopper (TMC2209_t *driver, uint8_t constant_off_time, uint8_t blank_time, uint8_t fast_decay_time, int8_t sine_wave_offset, bool use_current_comparator)
{
//calculate the value acc to the clock cycles
if (blank_time >= 54)
blank_time = 3;
else if (blank_time >= 36)
blank_time = 2;
else if (blank_time >= 24)
blank_time = 1;
else
blank_time = 0;
if (fast_decay_time > 15)
fast_decay_time = 15;
set_tfd(&driver->chopconf.reg, fast_decay_time);
driver->chopconf.reg.tbl = blank_time;
driver->chopconf.reg.toff = constant_off_time < 2 ? 2 : (constant_off_time > 15 ? 15 : constant_off_time);
driver->chopconf.reg.hend = (sine_wave_offset < -3 ? -3 : (sine_wave_offset > 12 ? 12 : sine_wave_offset)) + 3;
//! driver->chopconf.reg.rndtf = !use_current_comparator;
TMC2209_WriteRegister(driver, (TMC2209_datagram_t *)&driver->chopconf);
}
static void calcCRC (uint8_t *datagram, uint8_t datagramLength)
{
int i,j;
uint8_t *crc = datagram + (datagramLength - 1); // CRC located in last byte of message
uint8_t currentByte;
*crc = 0;
for (i = 0; i < (datagramLength - 1); i++) { // Execute for all bytes of a message
currentByte = datagram[i]; // Retrieve a byte to be sent from Array
for (j = 0; j < 8; j++) {
if ((*crc >> 7) ^ (currentByte & 0x01)) // update CRC based result of XOR operation
*crc = (*crc << 1) ^ 0x07;
else
*crc = (*crc << 1);
currentByte = currentByte >> 1;
} // for CRC bit
}
}
static void byteswap (uint8_t data[4])
{
uint8_t tmp;
tmp = data[0];
data[0] = data[3];
data[3] = tmp;
tmp = data[1];
data[1] = data[2];
data[2] = tmp;
}
bool TMC2209_WriteRegister (TMC2209_t *driver, TMC2209_datagram_t *reg)
{
TMC_uart_write_datagram_t datagram;
datagram.msg.sync = 0x05;
datagram.msg.slave = driver->config.addr;
datagram.msg.addr.value = reg->addr.value;
datagram.msg.addr.write = 1;
datagram.msg.payload.value = reg->payload.value;
byteswap(datagram.msg.payload.data);
calcCRC(datagram.data, sizeof(TMC_uart_write_datagram_t));
tmc_uart_write(driver->motor, &datagram);
// TODO: add check for ok'ed?
return true;
}
bool TMC2209_ReadRegister (TMC2209_t *driver, TMC2209_datagram_t *reg)
{
bool ok = false;
TMC_uart_read_datagram_t datagram;
TMC_uart_write_datagram_t *res;
datagram.msg.sync = 0x05;
datagram.msg.slave = driver->config.addr;
datagram.msg.addr.value = reg->addr.value;
datagram.msg.addr.write = 0;
calcCRC(datagram.data, sizeof(TMC_uart_read_datagram_t));
res = tmc_uart_read(driver->motor, &datagram);
if(res->msg.slave == 0xFF && res->msg.addr.value == datagram.msg.addr.value) {
uint8_t crc = res->msg.crc;
calcCRC(res->data, sizeof(TMC_uart_write_datagram_t));
if((ok = crc == res->msg.crc)) {
reg->payload.value = res->msg.payload.value;
byteswap(reg->payload.data);
}
}
return ok;
}
// Returns pointer to shadow register or NULL if not found
TMC2209_datagram_t *TMC2209_GetRegPtr (TMC2209_t *driver, tmc2209_regaddr_t reg)
{
TMC2209_datagram_t *ptr = (TMC2209_datagram_t *)driver;
while(ptr && ptr->addr.reg != reg) {
ptr++;
if(ptr->addr.reg == TMC2209Reg_LAST_ADDR && ptr->addr.reg != reg)
ptr = NULL;
}
return ptr;
}
|
dc837f6fd42edc15b991e184714c1896b5c8bc91
|
61418f2d5ad2a04ac6dfa585d2407c5ae218a836
|
/include/vsg/vk/vulkan.h
|
b25ab3a9c5223baa3bc1a09a835278f5f8bcfa44
|
[
"MIT",
"Apache-2.0"
] |
permissive
|
vsg-dev/VulkanSceneGraph
|
e6840572c6b141671f64525c37cf6929ed9fceb7
|
62b2e8e5b6886be486d5d5002b8ff7f89be089e8
|
refs/heads/master
| 2023-09-04T09:41:54.342443
| 2023-09-03T09:22:09
| 2023-09-03T09:22:09
| 148,609,004
| 962
| 190
|
MIT
| 2023-09-10T15:38:12
| 2018-09-13T08:43:58
|
C++
|
UTF-8
|
C
| false
| false
| 32,611
|
h
|
vulkan.h
|
#pragma once
// clang-format off
/* <editor-fold desc="Apache-2.0 License">
** Copyright (c) 2015-2020 The Khronos Group Inc.
**
** SPDX-License-Identifier: Apache-2.0
</editor-fold> */
//
// Include Vulkan headers that are available in the system.
//
#include <vulkan/vulkan.h>
//
// Then add definitions not provided by older headers below.
//
// Workaround for cppcheck
#ifndef VK_DEFINE_NON_DISPATCHABLE_HANDLE
#if (VK_USE_64_BIT_PTR_DEFINES==1)
#define VK_DEFINE_NON_DISPATCHABLE_HANDLE(object) typedef struct object##_T *object;
#else
#define VK_DEFINE_NON_DISPATCHABLE_HANDLE(object) typedef uint64_t object;
#endif
#endif
////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Definitions not provided prior to 1.1.77
//
#if VK_HEADER_VERSION < 77
# define VK_EXT_DESCRIPTOR_INDEXING_EXTENSION_NAME "VK_EXT_descriptor_indexing"
#endif
////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Definitions not provided prior to 1.1.82
//
#if VK_HEADER_VERSION < 82
# define VK_KHR_create_renderpass2 1
# define VK_KHR_CREATE_RENDERPASS_2_SPEC_VERSION 1
# define VK_KHR_CREATE_RENDERPASS_2_EXTENSION_NAME "VK_KHR_create_renderpass2"
typedef struct VkAttachmentDescription2KHR
{
VkStructureType sType;
const void* pNext;
VkAttachmentDescriptionFlags flags;
VkFormat format;
VkSampleCountFlagBits samples;
VkAttachmentLoadOp loadOp;
VkAttachmentStoreOp storeOp;
VkAttachmentLoadOp stencilLoadOp;
VkAttachmentStoreOp stencilStoreOp;
VkImageLayout initialLayout;
VkImageLayout finalLayout;
} VkAttachmentDescription2KHR;
typedef struct VkAttachmentReference2KHR
{
VkStructureType sType;
const void* pNext;
uint32_t attachment;
VkImageLayout layout;
VkImageAspectFlags aspectMask;
} VkAttachmentReference2KHR;
typedef struct VkSubpassDescription2KHR
{
VkStructureType sType;
const void* pNext;
VkSubpassDescriptionFlags flags;
VkPipelineBindPoint pipelineBindPoint;
uint32_t viewMask;
uint32_t inputAttachmentCount;
const VkAttachmentReference2KHR* pInputAttachments;
uint32_t colorAttachmentCount;
const VkAttachmentReference2KHR* pColorAttachments;
const VkAttachmentReference2KHR* pResolveAttachments;
const VkAttachmentReference2KHR* pDepthStencilAttachment;
uint32_t preserveAttachmentCount;
const uint32_t* pPreserveAttachments;
} VkSubpassDescription2KHR;
typedef struct VkSubpassDependency2KHR
{
VkStructureType sType;
const void* pNext;
uint32_t srcSubpass;
uint32_t dstSubpass;
VkPipelineStageFlags srcStageMask;
VkPipelineStageFlags dstStageMask;
VkAccessFlags srcAccessMask;
VkAccessFlags dstAccessMask;
VkDependencyFlags dependencyFlags;
int32_t viewOffset;
} VkSubpassDependency2KHR;
typedef struct VkRenderPassCreateInfo2KHR
{
VkStructureType sType;
const void* pNext;
VkRenderPassCreateFlags flags;
uint32_t attachmentCount;
const VkAttachmentDescription2KHR* pAttachments;
uint32_t subpassCount;
const VkSubpassDescription2KHR* pSubpasses;
uint32_t dependencyCount;
const VkSubpassDependency2KHR* pDependencies;
uint32_t correlatedViewMaskCount;
const uint32_t* pCorrelatedViewMasks;
} VkRenderPassCreateInfo2KHR;
#endif
////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Definitions not provided prior to 1.1.216
//
#if VK_HEADER_VERSION < 216
# define VK_KHR_fragment_shader_barycentric 1
# define VK_KHR_FRAGMENT_SHADER_BARYCENTRIC_SPEC_VERSION 1
# define VK_KHR_FRAGMENT_SHADER_BARYCENTRIC_EXTENSION_NAME "VK_KHR_fragment_shader_barycentric"
# define VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FRAGMENT_SHADER_BARYCENTRIC_FEATURES_KHR VkStructureType(1000203000)
# define VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FRAGMENT_SHADER_BARYCENTRIC_FEATURES_EXT VkStructureType(1000203000)
typedef struct VkPhysicalDeviceFragmentShaderBarycentricFeaturesKHR
{
VkStructureType sType;
void* pNext;
VkBool32 fragmentShaderBarycentric;
} VkPhysicalDeviceFragmentShaderBarycentricFeaturesKHR;
#endif
////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Definitions not provided prior to 1.1.231
//
#if VK_HEADER_VERSION < 231
# define VK_EXT_mesh_shader 1
# define VK_EXT_MESH_SHADER_SPEC_VERSION 1
# define VK_EXT_MESH_SHADER_EXTENSION_NAME "VK_EXT_mesh_shader"
# define VK_SHADER_STAGE_TASK_BIT_EXT VkShaderStageFlagBits(0x00000040)
# define VK_SHADER_STAGE_MESH_BIT_EXT VkShaderStageFlagBits(0x00000080)
# define VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MESH_SHADER_FEATURES_EXT VkStructureType(1000202000)
# define VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MESH_SHADER_PROPERTIES_EXT VkStructureType(1000202001)
typedef struct VkPhysicalDeviceMeshShaderFeaturesEXT {
VkStructureType sType;
void* pNext;
VkBool32 taskShader;
VkBool32 meshShader;
VkBool32 multiviewMeshShader;
VkBool32 primitiveFragmentShadingRateMeshShader;
VkBool32 meshShaderQueries;
} VkPhysicalDeviceMeshShaderFeaturesEXT;
typedef struct VkPhysicalDeviceMeshShaderPropertiesEXT {
VkStructureType sType;
void* pNext;
uint32_t maxTaskWorkGroupTotalCount;
uint32_t maxTaskWorkGroupCount[3];
uint32_t maxTaskWorkGroupInvocations;
uint32_t maxTaskWorkGroupSize[3];
uint32_t maxTaskPayloadSize;
uint32_t maxTaskSharedMemorySize;
uint32_t maxTaskPayloadAndSharedMemorySize;
uint32_t maxMeshWorkGroupTotalCount;
uint32_t maxMeshWorkGroupCount[3];
uint32_t maxMeshWorkGroupInvocations;
uint32_t maxMeshWorkGroupSize[3];
uint32_t maxMeshSharedMemorySize;
uint32_t maxMeshPayloadAndSharedMemorySize;
uint32_t maxMeshOutputMemorySize;
uint32_t maxMeshPayloadAndOutputMemorySize;
uint32_t maxMeshOutputComponents;
uint32_t maxMeshOutputVertices;
uint32_t maxMeshOutputPrimitives;
uint32_t maxMeshOutputLayers;
uint32_t maxMeshMultiviewViewCount;
uint32_t meshOutputPerVertexGranularity;
uint32_t meshOutputPerPrimitiveGranularity;
uint32_t maxPreferredTaskWorkGroupInvocations;
uint32_t maxPreferredMeshWorkGroupInvocations;
VkBool32 prefersLocalInvocationVertexOutput;
VkBool32 prefersLocalInvocationPrimitiveOutput;
VkBool32 prefersCompactVertexOutput;
VkBool32 prefersCompactPrimitiveOutput;
} VkPhysicalDeviceMeshShaderPropertiesEXT;
typedef struct VkDrawMeshTasksIndirectCommandEXT {
uint32_t groupCountX;
uint32_t groupCountY;
uint32_t groupCountZ;
} VkDrawMeshTasksIndirectCommandEXT;
typedef void (VKAPI_PTR *PFN_vkCmdDrawMeshTasksEXT)(VkCommandBuffer commandBuffer, uint32_t groupCountX, uint32_t groupCountY, uint32_t groupCountZ);
typedef void (VKAPI_PTR *PFN_vkCmdDrawMeshTasksIndirectEXT)(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t drawCount, uint32_t stride);
typedef void (VKAPI_PTR *PFN_vkCmdDrawMeshTasksIndirectCountEXT)(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount, uint32_t stride);
#endif
////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Definitions not provided prior to 1.1.97
//
#if VK_HEADER_VERSION < 97
typedef uint64_t VkDeviceAddress;
# define VK_KHR_shader_float_controls 1
# define VK_KHR_SHADER_FLOAT_CONTROLS_SPEC_VERSION 1
# define VK_KHR_SHADER_FLOAT_CONTROLS_EXTENSION_NAME "VK_KHR_shader_float_controls"
typedef struct VkPhysicalDeviceFloatControlsPropertiesKHR
{
VkStructureType sType;
void* pNext;
VkBool32 separateDenormSettings;
VkBool32 separateRoundingModeSettings;
VkBool32 shaderSignedZeroInfNanPreserveFloat16;
VkBool32 shaderSignedZeroInfNanPreserveFloat32;
VkBool32 shaderSignedZeroInfNanPreserveFloat64;
VkBool32 shaderDenormPreserveFloat16;
VkBool32 shaderDenormPreserveFloat32;
VkBool32 shaderDenormPreserveFloat64;
VkBool32 shaderDenormFlushToZeroFloat16;
VkBool32 shaderDenormFlushToZeroFloat32;
VkBool32 shaderDenormFlushToZeroFloat64;
VkBool32 shaderRoundingModeRTEFloat16;
VkBool32 shaderRoundingModeRTEFloat32;
VkBool32 shaderRoundingModeRTEFloat64;
VkBool32 shaderRoundingModeRTZFloat16;
VkBool32 shaderRoundingModeRTZFloat32;
VkBool32 shaderRoundingModeRTZFloat64;
} VkPhysicalDeviceFloatControlsPropertiesKHR;
#endif
////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Definitions not provided prior to 1.1.106
//
#if VK_HEADER_VERSION < 106
# define VK_EXT_buffer_device_address 1
# define VK_EXT_BUFFER_DEVICE_ADDRESS_SPEC_VERSION 2
# define VK_EXT_BUFFER_DEVICE_ADDRESS_EXTENSION_NAME "VK_EXT_buffer_device_address"
typedef struct VkPhysicalDeviceBufferDeviceAddressFeaturesEXT
{
VkStructureType sType;
void* pNext;
VkBool32 bufferDeviceAddress;
VkBool32 bufferDeviceAddressCaptureReplay;
VkBool32 bufferDeviceAddressMultiDevice;
} VkPhysicalDeviceBufferDeviceAddressFeaturesEXT;
#endif
////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Definitions not provided prior to 1.2.131
//
#if VK_HEADER_VERSION < 121
#define VK_EXT_host_query_reset 1
#define VK_EXT_HOST_QUERY_RESET_SPEC_VERSION 1
#define VK_EXT_HOST_QUERY_RESET_EXTENSION_NAME "VK_EXT_host_query_reset"
typedef struct VkPhysicalDeviceHostQueryResetFeaturesEXT {
VkStructureType sType;
void* pNext;
VkBool32 hostQueryReset;
} VkPhysicalDeviceHostQueryResetFeaturesEXT;
typedef void (VKAPI_PTR *PFN_vkResetQueryPoolEXT)(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery, uint32_t queryCount);
#endif
////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Definitions not provided prior to 1.2.131
//
#if VK_HEADER_VERSION < 131
# define VK_API_VERSION_1_2 VK_MAKE_VERSION(1, 2, 0)
# define VK_KHR_depth_stencil_resolve 1
# define VK_KHR_DEPTH_STENCIL_RESOLVE_SPEC_VERSION 1
# define VK_KHR_DEPTH_STENCIL_RESOLVE_EXTENSION_NAME "VK_KHR_depth_stencil_resolve"
# define VK_KHR_buffer_device_address 1
# define VK_KHR_BUFFER_DEVICE_ADDRESS_SPEC_VERSION 1
# define VK_KHR_BUFFER_DEVICE_ADDRESS_EXTENSION_NAME "VK_KHR_buffer_device_address"
# define VK_KHR_spirv_1_4 1
# define VK_KHR_SPIRV_1_4_SPEC_VERSION 1
# define VK_KHR_SPIRV_1_4_EXTENSION_NAME "VK_KHR_spirv_1_4"
# define VK_ERROR_UNKNOWN VkResult(-13)
# define VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT VkBufferUsageFlagBits(0x00020000)
# define VK_STRUCTURE_TYPE_BUFFER_DEVICE_ADDRESS_INFO VkStructureType(1000244001)
# define VK_STRUCTURE_TYPE_ATTACHMENT_DESCRIPTION_2 VkStructureType(1000109000)
# define VK_STRUCTURE_TYPE_ATTACHMENT_REFERENCE_2 VkStructureType(1000109001)
# define VK_STRUCTURE_TYPE_SUBPASS_DESCRIPTION_2 VkStructureType(1000109002)
# define VK_STRUCTURE_TYPE_SUBPASS_DEPENDENCY_2 VkStructureType(1000109003)
# define VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO_2 VkStructureType(1000109004)
# define VK_STRUCTURE_TYPE_SUBPASS_DESCRIPTION_DEPTH_STENCIL_RESOLVE VkStructureType(1000199001)
# define VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEPTH_STENCIL_RESOLVE_PROPERTIES VkStructureType(1000199000)
# define VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BUFFER_DEVICE_ADDRESS_FEATURES VkStructureType(1000257000)
typedef enum VkResolveModeFlagBits
{
VK_RESOLVE_MODE_NONE = 0,
VK_RESOLVE_MODE_SAMPLE_ZERO_BIT = 0x00000001,
VK_RESOLVE_MODE_AVERAGE_BIT = 0x00000002,
VK_RESOLVE_MODE_MIN_BIT = 0x00000004,
VK_RESOLVE_MODE_MAX_BIT = 0x00000008,
VK_RESOLVE_MODE_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF
} VkResolveModeFlagBits;
typedef VkFlags VkResolveModeFlags;
typedef struct VkAttachmentDescription2
{
VkStructureType sType;
const void* pNext;
VkAttachmentDescriptionFlags flags;
VkFormat format;
VkSampleCountFlagBits samples;
VkAttachmentLoadOp loadOp;
VkAttachmentStoreOp storeOp;
VkAttachmentLoadOp stencilLoadOp;
VkAttachmentStoreOp stencilStoreOp;
VkImageLayout initialLayout;
VkImageLayout finalLayout;
} VkAttachmentDescription2;
typedef struct VkAttachmentReference2
{
VkStructureType sType;
const void* pNext;
uint32_t attachment;
VkImageLayout layout;
VkImageAspectFlags aspectMask;
} VkAttachmentReference2;
typedef struct VkSubpassDescription2
{
VkStructureType sType;
const void* pNext;
VkSubpassDescriptionFlags flags;
VkPipelineBindPoint pipelineBindPoint;
uint32_t viewMask;
uint32_t inputAttachmentCount;
const VkAttachmentReference2* pInputAttachments;
uint32_t colorAttachmentCount;
const VkAttachmentReference2* pColorAttachments;
const VkAttachmentReference2* pResolveAttachments;
const VkAttachmentReference2* pDepthStencilAttachment;
uint32_t preserveAttachmentCount;
const uint32_t* pPreserveAttachments;
} VkSubpassDescription2;
typedef struct VkSubpassDependency2
{
VkStructureType sType;
const void* pNext;
uint32_t srcSubpass;
uint32_t dstSubpass;
VkPipelineStageFlags srcStageMask;
VkPipelineStageFlags dstStageMask;
VkAccessFlags srcAccessMask;
VkAccessFlags dstAccessMask;
VkDependencyFlags dependencyFlags;
int32_t viewOffset;
} VkSubpassDependency2;
typedef struct VkRenderPassCreateInfo2
{
VkStructureType sType;
const void* pNext;
VkRenderPassCreateFlags flags;
uint32_t attachmentCount;
const VkAttachmentDescription2* pAttachments;
uint32_t subpassCount;
const VkSubpassDescription2* pSubpasses;
uint32_t dependencyCount;
const VkSubpassDependency2* pDependencies;
uint32_t correlatedViewMaskCount;
const uint32_t* pCorrelatedViewMasks;
} VkRenderPassCreateInfo2;
typedef struct VkSubpassDescriptionDepthStencilResolve
{
VkStructureType sType;
const void* pNext;
VkResolveModeFlagBits depthResolveMode;
VkResolveModeFlagBits stencilResolveMode;
const VkAttachmentReference2* pDepthStencilResolveAttachment;
} VkSubpassDescriptionDepthStencilResolve;
# if 1
typedef struct VkPhysicalDeviceDepthStencilResolveProperties
{
VkStructureType sType;
void* pNext;
VkResolveModeFlags supportedDepthResolveModes;
VkResolveModeFlags supportedStencilResolveModes;
VkBool32 independentResolveNone;
VkBool32 independentResolve;
} VkPhysicalDeviceDepthStencilResolveProperties;
# endif
typedef struct VkBufferDeviceAddressInfo
{
VkStructureType sType;
const void* pNext;
VkBuffer buffer;
} VkBufferDeviceAddressInfo;
#endif
////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Definitions not provided prior to 1.2.135
//
#if VK_HEADER_VERSION < 135
# define VK_SHADER_UNUSED_KHR (~0U)
VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkAccelerationStructureKHR)
typedef VkFlags VkBuildAccelerationStructureFlagsKHR;
typedef VkFlags VkGeometryFlagsKHR;
typedef enum VkGeometryTypeKHR
{ // 135
VK_GEOMETRY_TYPE_TRIANGLES_KHR = 0,
VK_GEOMETRY_TYPE_AABBS_KHR = 1,
VK_GEOMETRY_TYPE_INSTANCES_KHR = 2,
} VkGeometryTypeKHR;
typedef struct VkWriteDescriptorSetAccelerationStructureKHR
{ // 135
VkStructureType sType;
const void* pNext;
uint32_t accelerationStructureCount;
const VkAccelerationStructureKHR* pAccelerationStructures;
} VkWriteDescriptorSetAccelerationStructureKHR;
typedef enum VkGeometryFlagBitsKHR
{
VK_GEOMETRY_OPAQUE_BIT_KHR = 0x00000001,
VK_GEOMETRY_NO_DUPLICATE_ANY_HIT_INVOCATION_BIT_KHR = 0x00000002,
VK_GEOMETRY_FLAG_BITS_MAX_ENUM_KHR = 0x7FFFFFFF
} VkGeometryFlagBitsKHR;
typedef enum VkGeometryInstanceFlagBitsKHR
{
VK_GEOMETRY_INSTANCE_TRIANGLE_FACING_CULL_DISABLE_BIT_KHR = 0x00000001,
VK_GEOMETRY_INSTANCE_TRIANGLE_FRONT_COUNTERCLOCKWISE_BIT_KHR = 0x00000002,
VK_GEOMETRY_INSTANCE_FORCE_OPAQUE_BIT_KHR = 0x00000004,
VK_GEOMETRY_INSTANCE_FORCE_NO_OPAQUE_BIT_KHR = 0x00000008,
VK_GEOMETRY_INSTANCE_FLAG_BITS_MAX_ENUM_KHR = 0x7FFFFFFF
} VkGeometryInstanceFlagBitsKHR;
typedef enum VkBuildAccelerationStructureFlagBitsKHR
{
VK_BUILD_ACCELERATION_STRUCTURE_ALLOW_UPDATE_BIT_KHR = 0x00000001,
VK_BUILD_ACCELERATION_STRUCTURE_ALLOW_COMPACTION_BIT_KHR = 0x00000002,
VK_BUILD_ACCELERATION_STRUCTURE_PREFER_FAST_TRACE_BIT_KHR = 0x00000004,
VK_BUILD_ACCELERATION_STRUCTURE_PREFER_FAST_BUILD_BIT_KHR = 0x00000008,
VK_BUILD_ACCELERATION_STRUCTURE_LOW_MEMORY_BIT_KHR = 0x00000010,
VK_BUILD_ACCELERATION_STRUCTURE_FLAG_BITS_MAX_ENUM_KHR = 0x7FFFFFFF
} VkBuildAccelerationStructureFlagBitsKHR;
typedef enum VkAccelerationStructureTypeKHR
{
VK_ACCELERATION_STRUCTURE_TYPE_TOP_LEVEL_KHR = 0,
VK_ACCELERATION_STRUCTURE_TYPE_BOTTOM_LEVEL_KHR = 1,
VK_ACCELERATION_STRUCTURE_TYPE_GENERIC_KHR = 2,
VK_ACCELERATION_STRUCTURE_TYPE_MAX_ENUM_KHR = 0x7FFFFFFF
} VkAccelerationStructureTypeKHR;
typedef enum VkRayTracingShaderGroupTypeKHR
{
VK_RAY_TRACING_SHADER_GROUP_TYPE_GENERAL_KHR = 0,
VK_RAY_TRACING_SHADER_GROUP_TYPE_TRIANGLES_HIT_GROUP_KHR = 1,
VK_RAY_TRACING_SHADER_GROUP_TYPE_PROCEDURAL_HIT_GROUP_KHR = 2,
VK_RAY_TRACING_SHADER_GROUP_TYPE_MAX_ENUM_KHR = 0x7FFFFFFF
} VkRayTracingShaderGroupTypeKHR;
#define VK_KHR_shader_non_semantic_info 1
#define VK_KHR_SHADER_NON_SEMANTIC_INFO_SPEC_VERSION 1
#define VK_KHR_SHADER_NON_SEMANTIC_INFO_EXTENSION_NAME "VK_KHR_shader_non_semantic_info"
#endif
////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Definitions not provided prior to 1.2.162
//
#if VK_HEADER_VERSION < 162
# define VK_KHR_ray_tracing_pipeline 1
# define VK_KHR_RAY_TRACING_PIPELINE_SPEC_VERSION 1
# define VK_KHR_RAY_TRACING_PIPELINE_EXTENSION_NAME "VK_KHR_ray_tracing_pipeline"
# define VK_KHR_acceleration_structure 1
# define VK_KHR_ACCELERATION_STRUCTURE_SPEC_VERSION 11
# define VK_KHR_ACCELERATION_STRUCTURE_EXTENSION_NAME "VK_KHR_acceleration_structure"
# define VK_KHR_DEFERRED_HOST_OPERATIONS_EXTENSION_NAME "VK_KHR_deferred_host_operations"
typedef VkFlags VkAccelerationStructureCreateFlagsKHR;
# define VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR VkDescriptorType(1000150000)
# define VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_TRACING_PIPELINE_PROPERTIES_KHR VkStructureType(1000347001)
# define VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_GEOMETRY_INSTANCES_DATA_KHR VkStructureType(1000150004)
# define VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET_ACCELERATION_STRUCTURE_KHR VkStructureType(1000150007)
# define VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_GEOMETRY_KHR VkStructureType(1000150006)
# define VK_STRUCTURE_TYPE_RAY_TRACING_PIPELINE_CREATE_INFO_KHR VkStructureType(1000150015)
# define VK_STRUCTURE_TYPE_RAY_TRACING_SHADER_GROUP_CREATE_INFO_KHR VkStructureType(1000150016)
# define VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_DEVICE_ADDRESS_INFO_KHR VkStructureType(1000150002)
# define VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_BUILD_SIZES_INFO_KHR VkStructureType(1000150020)
# define VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_BUILD_GEOMETRY_INFO_KHR VkStructureType(1000150000)
# define VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_CREATE_INFO_KHR VkStructureType(1000150017)
# define VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_GEOMETRY_TRIANGLES_DATA_KHR VkStructureType(1000150005)
# define VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ACCELERATION_STRUCTURE_FEATURES_KHR VkStructureType(1000150013)
# define VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_TRACING_PIPELINE_FEATURES_KHR VkStructureType(1000347000)
# define VK_BUFFER_USAGE_ACCELERATION_STRUCTURE_STORAGE_BIT_KHR VkBufferUsageFlagBits(0x00100000)
# define VK_BUFFER_USAGE_SHADER_BINDING_TABLE_BIT_KHR VkBufferUsageFlagBits(0x00000400)
# define VK_BUFFER_USAGE_ACCELERATION_STRUCTURE_BUILD_INPUT_READ_ONLY_BIT_KHR VkBufferUsageFlagBits(0x00080000)
# define VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR VkPipelineBindPoint(1000165000)
# define VK_PIPELINE_STAGE_ACCELERATION_STRUCTURE_BUILD_BIT_KHR VkPipelineStageFlagBits(0x02000000)
# define VK_ACCESS_ACCELERATION_STRUCTURE_READ_BIT_KHR VkAccessFlagBits(0x00200000)
# define VK_ACCESS_ACCELERATION_STRUCTURE_WRITE_BIT_KHR VkAccessFlagBits(0x00400000)
# define VK_SHADER_STAGE_RAYGEN_BIT_KHR VkShaderStageFlagBits(0x00000100)
# define VK_SHADER_STAGE_ANY_HIT_BIT_KHR VkShaderStageFlagBits(0x00000200)
# define VK_SHADER_STAGE_CLOSEST_HIT_BIT_KHR VkShaderStageFlagBits(0x00000400)
# define VK_SHADER_STAGE_MISS_BIT_KHR VkShaderStageFlagBits(0x00000800)
# define VK_SHADER_STAGE_INTERSECTION_BIT_KHR VkShaderStageFlagBits(0x00001000)
# define VK_SHADER_STAGE_CALLABLE_BIT_KHR VkShaderStageFlagBits(0x00002000)
VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkDeferredOperationKHR)
typedef enum VkBuildAccelerationStructureModeKHR
{
VK_BUILD_ACCELERATION_STRUCTURE_MODE_BUILD_KHR = 0,
VK_BUILD_ACCELERATION_STRUCTURE_MODE_UPDATE_KHR = 1,
VK_BUILD_ACCELERATION_STRUCTURE_MODE_MAX_ENUM_KHR = 0x7FFFFFFF
} VkBuildAccelerationStructureModeKHR;
typedef enum VkAccelerationStructureBuildTypeKHR
{
VK_ACCELERATION_STRUCTURE_BUILD_TYPE_HOST_KHR = 0,
VK_ACCELERATION_STRUCTURE_BUILD_TYPE_DEVICE_KHR = 1,
VK_ACCELERATION_STRUCTURE_BUILD_TYPE_HOST_OR_DEVICE_KHR = 2,
VK_ACCELERATION_STRUCTURE_BUILD_TYPE_MAX_ENUM_KHR = 0x7FFFFFFF
} VkAccelerationStructureBuildTypeKHR;
typedef struct VkPhysicalDeviceRayTracingPipelineFeaturesKHR
{
VkStructureType sType;
void* pNext;
VkBool32 rayTracingPipeline;
VkBool32 rayTracingPipelineShaderGroupHandleCaptureReplay;
VkBool32 rayTracingPipelineShaderGroupHandleCaptureReplayMixed;
VkBool32 rayTracingPipelineTraceRaysIndirect;
VkBool32 rayTraversalPrimitiveCulling;
} VkPhysicalDeviceRayTracingPipelineFeaturesKHR;
typedef struct VkPhysicalDeviceAccelerationStructureFeaturesKHR
{
VkStructureType sType;
void* pNext;
VkBool32 accelerationStructure;
VkBool32 accelerationStructureCaptureReplay;
VkBool32 accelerationStructureIndirectBuild;
VkBool32 accelerationStructureHostCommands;
VkBool32 descriptorBindingAccelerationStructureUpdateAfterBind;
} VkPhysicalDeviceAccelerationStructureFeaturesKHR;
typedef struct VkPhysicalDeviceRayTracingPipelinePropertiesKHR
{
VkStructureType sType;
void* pNext;
uint32_t shaderGroupHandleSize;
uint32_t maxRayRecursionDepth;
uint32_t maxShaderGroupStride;
uint32_t shaderGroupBaseAlignment;
uint32_t shaderGroupHandleCaptureReplaySize;
uint32_t maxRayDispatchInvocationCount;
uint32_t shaderGroupHandleAlignment;
uint32_t maxRayHitAttributeSize;
} VkPhysicalDeviceRayTracingPipelinePropertiesKHR;
typedef union VkDeviceOrHostAddressKHR
{
VkDeviceAddress deviceAddress;
void* hostAddress;
} VkDeviceOrHostAddressKHR;
typedef union VkDeviceOrHostAddressConstKHR
{
VkDeviceAddress deviceAddress;
const void* hostAddress;
} VkDeviceOrHostAddressConstKHR;
typedef struct VkAccelerationStructureBuildRangeInfoKHR
{
uint32_t primitiveCount;
uint32_t primitiveOffset;
uint32_t firstVertex;
uint32_t transformOffset;
} VkAccelerationStructureBuildRangeInfoKHR;
typedef struct VkAccelerationStructureGeometryTrianglesDataKHR
{
VkStructureType sType;
const void* pNext;
VkFormat vertexFormat;
VkDeviceOrHostAddressConstKHR vertexData;
VkDeviceSize vertexStride;
uint32_t maxVertex;
VkIndexType indexType;
VkDeviceOrHostAddressConstKHR indexData;
VkDeviceOrHostAddressConstKHR transformData;
} VkAccelerationStructureGeometryTrianglesDataKHR;
typedef struct VkAccelerationStructureGeometryAabbsDataKHR
{
VkStructureType sType;
const void* pNext;
VkDeviceOrHostAddressConstKHR data;
VkDeviceSize stride;
} VkAccelerationStructureGeometryAabbsDataKHR;
typedef struct VkAccelerationStructureGeometryInstancesDataKHR
{
VkStructureType sType;
const void* pNext;
VkBool32 arrayOfPointers;
VkDeviceOrHostAddressConstKHR data;
} VkAccelerationStructureGeometryInstancesDataKHR;
typedef union VkAccelerationStructureGeometryDataKHR
{
VkAccelerationStructureGeometryTrianglesDataKHR triangles;
VkAccelerationStructureGeometryAabbsDataKHR aabbs;
VkAccelerationStructureGeometryInstancesDataKHR instances;
} VkAccelerationStructureGeometryDataKHR;
typedef struct VkAccelerationStructureGeometryKHR
{
VkStructureType sType;
const void* pNext;
VkGeometryTypeKHR geometryType;
VkAccelerationStructureGeometryDataKHR geometry;
VkGeometryFlagsKHR flags;
} VkAccelerationStructureGeometryKHR;
typedef struct VkAccelerationStructureCreateInfoKHR
{
VkStructureType sType;
const void* pNext;
VkAccelerationStructureCreateFlagsKHR createFlags;
VkBuffer buffer;
VkDeviceSize offset;
VkDeviceSize size;
VkAccelerationStructureTypeKHR type;
VkDeviceAddress deviceAddress;
} VkAccelerationStructureCreateInfoKHR;
typedef struct VkAccelerationStructureBuildGeometryInfoKHR
{
VkStructureType sType;
const void* pNext;
VkAccelerationStructureTypeKHR type;
VkBuildAccelerationStructureFlagsKHR flags;
VkBuildAccelerationStructureModeKHR mode;
VkAccelerationStructureKHR srcAccelerationStructure;
VkAccelerationStructureKHR dstAccelerationStructure;
uint32_t geometryCount;
const VkAccelerationStructureGeometryKHR* pGeometries;
const VkAccelerationStructureGeometryKHR* const* ppGeometries;
VkDeviceOrHostAddressKHR scratchData;
} VkAccelerationStructureBuildGeometryInfoKHR;
typedef struct VkStridedDeviceAddressRegionKHR
{
VkDeviceAddress deviceAddress;
VkDeviceSize stride;
VkDeviceSize size;
} VkStridedDeviceAddressRegionKHR;
typedef struct VkPipelineLibraryCreateInfoKHR
{
VkStructureType sType;
const void* pNext;
uint32_t libraryCount;
const VkPipeline* pLibraries;
} VkPipelineLibraryCreateInfoKHR;
typedef struct VkRayTracingPipelineInterfaceCreateInfoKHR
{
VkStructureType sType;
const void* pNext;
uint32_t maxPipelineRayPayloadSize;
uint32_t maxPipelineRayHitAttributeSize;
} VkRayTracingPipelineInterfaceCreateInfoKHR;
typedef struct VkAccelerationStructureDeviceAddressInfoKHR
{
VkStructureType sType;
const void* pNext;
VkAccelerationStructureKHR accelerationStructure;
} VkAccelerationStructureDeviceAddressInfoKHR;
typedef struct VkAccelerationStructureBuildSizesInfoKHR
{
VkStructureType sType;
const void* pNext;
VkDeviceSize accelerationStructureSize;
VkDeviceSize updateScratchSize;
VkDeviceSize buildScratchSize;
} VkAccelerationStructureBuildSizesInfoKHR;
typedef struct VkRayTracingShaderGroupCreateInfoKHR
{
VkStructureType sType;
const void* pNext;
VkRayTracingShaderGroupTypeKHR type;
uint32_t generalShader;
uint32_t closestHitShader;
uint32_t anyHitShader;
uint32_t intersectionShader;
const void* pShaderGroupCaptureReplayHandle;
} VkRayTracingShaderGroupCreateInfoKHR;
typedef struct VkRayTracingPipelineCreateInfoKHR
{
VkStructureType sType;
const void* pNext;
VkPipelineCreateFlags flags;
uint32_t stageCount;
const VkPipelineShaderStageCreateInfo* pStages;
uint32_t groupCount;
const VkRayTracingShaderGroupCreateInfoKHR* pGroups;
uint32_t maxPipelineRayRecursionDepth;
const VkPipelineLibraryCreateInfoKHR* pLibraryInfo;
const VkRayTracingPipelineInterfaceCreateInfoKHR* pLibraryInterface;
const VkPipelineDynamicStateCreateInfo* pDynamicState;
VkPipelineLayout layout;
VkPipeline basePipelineHandle;
int32_t basePipelineIndex;
} VkRayTracingPipelineCreateInfoKHR;
typedef VkResult(VKAPI_PTR* PFN_vkCreateAccelerationStructureKHR)(VkDevice device, const VkAccelerationStructureCreateInfoKHR* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkAccelerationStructureKHR* pAccelerationStructure);
typedef void(VKAPI_PTR* PFN_vkDestroyAccelerationStructureKHR)(VkDevice device, VkAccelerationStructureKHR accelerationStructure, const VkAllocationCallbacks* pAllocator);
typedef void(VKAPI_PTR* PFN_vkCmdBuildAccelerationStructuresKHR)(VkCommandBuffer commandBuffer, uint32_t infoCount, const VkAccelerationStructureBuildGeometryInfoKHR* pInfos, const VkAccelerationStructureBuildRangeInfoKHR* const* ppBuildRangeInfos);
typedef VkDeviceAddress(VKAPI_PTR* PFN_vkGetAccelerationStructureDeviceAddressKHR)(VkDevice device, const VkAccelerationStructureDeviceAddressInfoKHR* pInfo);
typedef void(VKAPI_PTR* PFN_vkGetAccelerationStructureBuildSizesKHR)(VkDevice device, VkAccelerationStructureBuildTypeKHR buildType, const VkAccelerationStructureBuildGeometryInfoKHR* pBuildInfo, const uint32_t* pMaxPrimitiveCounts, VkAccelerationStructureBuildSizesInfoKHR* pSizeInfo);
typedef VkResult(VKAPI_PTR* PFN_vkCreateRayTracingPipelinesKHR)(VkDevice device, VkDeferredOperationKHR deferredOperation, VkPipelineCache pipelineCache, uint32_t createInfoCount, const VkRayTracingPipelineCreateInfoKHR* pCreateInfos, const VkAllocationCallbacks* pAllocator, VkPipeline* pPipelines);
typedef VkResult(VKAPI_PTR* PFN_vkGetRayTracingShaderGroupHandlesKHR)(VkDevice device, VkPipeline pipeline, uint32_t firstGroup, uint32_t groupCount, size_t dataSize, void* pData);
typedef void(VKAPI_PTR* PFN_vkCmdTraceRaysKHR)(VkCommandBuffer commandBuffer, const VkStridedDeviceAddressRegionKHR* pRaygenShaderBindingTable, const VkStridedDeviceAddressRegionKHR* pMissShaderBindingTable, const VkStridedDeviceAddressRegionKHR* pHitShaderBindingTable, const VkStridedDeviceAddressRegionKHR* pCallableShaderBindingTable, uint32_t width, uint32_t height, uint32_t depth);
#endif
//
// Provide *_Compatibility function definitions to workaround different function definitions across different vulkan_core.h versions.
//
typedef VkResult(VKAPI_PTR* PFN_vkCreateRenderPass2KHR_Compatibility)(VkDevice device, const VkRenderPassCreateInfo2* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkRenderPass* pRenderPass);
typedef VkDeviceAddress(VKAPI_PTR* PFN_vkGetBufferDeviceAddressKHR_Compatibility)(VkDevice device, const VkBufferDeviceAddressInfo* pInfo);
//
// Definitions not provided prior to 1.3.211
//
#if VK_HEADER_VERSION < 211
typedef enum VkInstanceCreateFlagBits {
VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR = 0x00000001,
VK_INSTANCE_CREATE_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF
} VkInstanceCreateFlagBits;
typedef VkFlags VkInstanceCreateFlags;
#define VK_KHR_portability_enumeration 1
#define VK_KHR_PORTABILITY_ENUMERATION_SPEC_VERSION 1
#define VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME "VK_KHR_portability_enumeration"
#endif
//
// Provide VK_KHR_portability_subset from vulkan_beta.h
//
#ifndef VK_KHR_portability_subset
#define VK_KHR_portability_subset 1
#define VK_KHR_PORTABILITY_SUBSET_SPEC_VERSION 1
#define VK_KHR_PORTABILITY_SUBSET_EXTENSION_NAME "VK_KHR_portability_subset"
typedef struct VkPhysicalDevicePortabilitySubsetFeaturesKHR {
VkStructureType sType;
void* pNext;
VkBool32 constantAlphaColorBlendFactors;
VkBool32 events;
VkBool32 imageViewFormatReinterpretation;
VkBool32 imageViewFormatSwizzle;
VkBool32 imageView2DOn3DImage;
VkBool32 multisampleArrayImage;
VkBool32 mutableComparisonSamplers;
VkBool32 pointPolygons;
VkBool32 samplerMipLodBias;
VkBool32 separateStencilMaskRef;
VkBool32 shaderSampleRateInterpolationFunctions;
VkBool32 tessellationIsolines;
VkBool32 tessellationPointMode;
VkBool32 triangleFans;
VkBool32 vertexAttributeAccessBeyondStride;
} VkPhysicalDevicePortabilitySubsetFeaturesKHR;
typedef struct VkPhysicalDevicePortabilitySubsetPropertiesKHR {
VkStructureType sType;
void* pNext;
uint32_t minVertexInputBindingStrideAlignment;
} VkPhysicalDevicePortabilitySubsetPropertiesKHR;
#endif
|
1ae166436696b5ab01006d95f807519ae1687b8f
|
7bd29008f8d2a394294ba254bd326ecfc8b223ac
|
/test/SDL_app/SDL-1.2.15/include/SDL_joystick.h
|
708d1a9f09617aae39eb3819c9cb8e2acfd54995
|
[
"LicenseRef-scancode-warranty-disclaimer",
"LGPL-2.1-only",
"LicenseRef-scancode-other-copyleft",
"GPL-1.0-or-later",
"LGPL-2.1-or-later",
"LGPL-2.0-or-later",
"GPL-2.0-only",
"LGPL-2.0-only",
"LicenseRef-scancode-public-domain",
"MIT"
] |
permissive
|
valentingalea/vml
|
50f510520d659abbc829cc289d76dfeb37ec28d1
|
23ae9766e552f96dfcebe9a561b40002ccdeb942
|
refs/heads/master
| 2022-01-22T21:05:37.597321
| 2022-01-16T19:18:22
| 2022-01-16T19:18:22
| 26,855,325
| 181
| 4
|
MIT
| 2022-01-15T11:30:57
| 2014-11-19T10:03:04
|
C++
|
UTF-8
|
C
| false
| false
| 5,532
|
h
|
SDL_joystick.h
|
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997-2012 Sam Lantinga
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
Sam Lantinga
slouken@libsdl.org
*/
/** @file SDL_joystick.h
* Include file for SDL joystick event handling
*/
#ifndef _SDL_joystick_h
#define _SDL_joystick_h
#include "SDL_stdinc.h"
#include "SDL_error.h"
#include "begin_code.h"
/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
extern "C" {
#endif
/** @file SDL_joystick.h
* @note In order to use these functions, SDL_Init() must have been called
* with the SDL_INIT_JOYSTICK flag. This causes SDL to scan the system
* for joysticks, and load appropriate drivers.
*/
/** The joystick structure used to identify an SDL joystick */
struct _SDL_Joystick;
typedef struct _SDL_Joystick SDL_Joystick;
/* Function prototypes */
/**
* Count the number of joysticks attached to the system
*/
extern DECLSPEC int SDLCALL SDL_NumJoysticks(void);
/**
* Get the implementation dependent name of a joystick.
*
* This can be called before any joysticks are opened.
* If no name can be found, this function returns NULL.
*/
extern DECLSPEC const char * SDLCALL SDL_JoystickName(int device_index);
/**
* Open a joystick for use.
*
* @param[in] device_index
* The index passed as an argument refers to
* the N'th joystick on the system. This index is the value which will
* identify this joystick in future joystick events.
*
* @return This function returns a joystick identifier, or NULL if an error occurred.
*/
extern DECLSPEC SDL_Joystick * SDLCALL SDL_JoystickOpen(int device_index);
/**
* Returns 1 if the joystick has been opened, or 0 if it has not.
*/
extern DECLSPEC int SDLCALL SDL_JoystickOpened(int device_index);
/**
* Get the device index of an opened joystick.
*/
extern DECLSPEC int SDLCALL SDL_JoystickIndex(SDL_Joystick *joystick);
/**
* Get the number of general axis controls on a joystick
*/
extern DECLSPEC int SDLCALL SDL_JoystickNumAxes(SDL_Joystick *joystick);
/**
* Get the number of trackballs on a joystick
*
* Joystick trackballs have only relative motion events associated
* with them and their state cannot be polled.
*/
extern DECLSPEC int SDLCALL SDL_JoystickNumBalls(SDL_Joystick *joystick);
/**
* Get the number of POV hats on a joystick
*/
extern DECLSPEC int SDLCALL SDL_JoystickNumHats(SDL_Joystick *joystick);
/**
* Get the number of buttons on a joystick
*/
extern DECLSPEC int SDLCALL SDL_JoystickNumButtons(SDL_Joystick *joystick);
/**
* Update the current state of the open joysticks.
*
* This is called automatically by the event loop if any joystick
* events are enabled.
*/
extern DECLSPEC void SDLCALL SDL_JoystickUpdate(void);
/**
* Enable/disable joystick event polling.
*
* If joystick events are disabled, you must call SDL_JoystickUpdate()
* yourself and check the state of the joystick when you want joystick
* information.
*
* @param[in] state The state can be one of SDL_QUERY, SDL_ENABLE or SDL_IGNORE.
*/
extern DECLSPEC int SDLCALL SDL_JoystickEventState(int state);
/**
* Get the current state of an axis control on a joystick
*
* @param[in] axis The axis indices start at index 0.
*
* @return The state is a value ranging from -32768 to 32767.
*/
extern DECLSPEC Sint16 SDLCALL SDL_JoystickGetAxis(SDL_Joystick *joystick, int axis);
/**
* @name Hat Positions
* The return value of SDL_JoystickGetHat() is one of the following positions:
*/
/*@{*/
#define SDL_HAT_CENTERED 0x00
#define SDL_HAT_UP 0x01
#define SDL_HAT_RIGHT 0x02
#define SDL_HAT_DOWN 0x04
#define SDL_HAT_LEFT 0x08
#define SDL_HAT_RIGHTUP (SDL_HAT_RIGHT|SDL_HAT_UP)
#define SDL_HAT_RIGHTDOWN (SDL_HAT_RIGHT|SDL_HAT_DOWN)
#define SDL_HAT_LEFTUP (SDL_HAT_LEFT|SDL_HAT_UP)
#define SDL_HAT_LEFTDOWN (SDL_HAT_LEFT|SDL_HAT_DOWN)
/*@}*/
/**
* Get the current state of a POV hat on a joystick
*
* @param[in] hat The hat indices start at index 0.
*/
extern DECLSPEC Uint8 SDLCALL SDL_JoystickGetHat(SDL_Joystick *joystick, int hat);
/**
* Get the ball axis change since the last poll
*
* @param[in] ball The ball indices start at index 0.
*
* @return This returns 0, or -1 if you passed it invalid parameters.
*/
extern DECLSPEC int SDLCALL SDL_JoystickGetBall(SDL_Joystick *joystick, int ball, int *dx, int *dy);
/**
* Get the current state of a button on a joystick
*
* @param[in] button The button indices start at index 0.
*/
extern DECLSPEC Uint8 SDLCALL SDL_JoystickGetButton(SDL_Joystick *joystick, int button);
/**
* Close a joystick previously opened with SDL_JoystickOpen()
*/
extern DECLSPEC void SDLCALL SDL_JoystickClose(SDL_Joystick *joystick);
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
}
#endif
#include "close_code.h"
#endif /* _SDL_joystick_h */
|
618b24000128864b621ad68bdd8a3d7ab4259f89
|
7eaf54a78c9e2117247cb2ab6d3a0c20719ba700
|
/SOFTWARE/A64-TERES/linux-a64/lib/dynamic_debug.c
|
99fec3ae405aa2e785c66605044d715633b894ac
|
[
"LicenseRef-scancode-free-unknown",
"Apache-2.0",
"Linux-syscall-note",
"GPL-2.0-only",
"GPL-1.0-or-later"
] |
permissive
|
OLIMEX/DIY-LAPTOP
|
ae82f4ee79c641d9aee444db9a75f3f6709afa92
|
a3fafd1309135650bab27f5eafc0c32bc3ca74ee
|
refs/heads/rel3
| 2023-08-04T01:54:19.483792
| 2023-04-03T07:18:12
| 2023-04-03T07:18:12
| 80,094,055
| 507
| 92
|
Apache-2.0
| 2023-04-03T07:05:59
| 2017-01-26T07:25:50
|
C
|
UTF-8
|
C
| false
| false
| 25,912
|
c
|
dynamic_debug.c
|
/*
* lib/dynamic_debug.c
*
* make pr_debug()/dev_dbg() calls runtime configurable based upon their
* source module.
*
* Copyright (C) 2008 Jason Baron <jbaron@redhat.com>
* By Greg Banks <gnb@melbourne.sgi.com>
* Copyright (c) 2008 Silicon Graphics Inc. All Rights Reserved.
* Copyright (C) 2011 Bart Van Assche. All Rights Reserved.
*/
#define pr_fmt(fmt) KBUILD_MODNAME ":%s: " fmt, __func__
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/kallsyms.h>
#include <linux/types.h>
#include <linux/mutex.h>
#include <linux/proc_fs.h>
#include <linux/seq_file.h>
#include <linux/list.h>
#include <linux/sysctl.h>
#include <linux/ctype.h>
#include <linux/string.h>
#include <linux/string_helpers.h>
#include <linux/uaccess.h>
#include <linux/dynamic_debug.h>
#include <linux/debugfs.h>
#include <linux/slab.h>
#include <linux/jump_label.h>
#include <linux/hardirq.h>
#include <linux/sched.h>
#include <linux/device.h>
#include <linux/netdevice.h>
extern struct _ddebug __start___verbose[];
extern struct _ddebug __stop___verbose[];
struct ddebug_table {
struct list_head link;
char *mod_name;
unsigned int num_ddebugs;
struct _ddebug *ddebugs;
};
struct ddebug_query {
const char *filename;
const char *module;
const char *function;
const char *format;
unsigned int first_lineno, last_lineno;
};
struct ddebug_iter {
struct ddebug_table *table;
unsigned int idx;
};
static DEFINE_MUTEX(ddebug_lock);
static LIST_HEAD(ddebug_tables);
static int verbose;
module_param(verbose, int, 0644);
/* Return the path relative to source root */
static inline const char *trim_prefix(const char *path)
{
int skip = strlen(__FILE__) - strlen("lib/dynamic_debug.c");
if (strncmp(path, __FILE__, skip))
skip = 0; /* prefix mismatch, don't skip */
return path + skip;
}
static struct { unsigned flag:8; char opt_char; } opt_array[] = {
{ _DPRINTK_FLAGS_PRINT, 'p' },
{ _DPRINTK_FLAGS_INCL_MODNAME, 'm' },
{ _DPRINTK_FLAGS_INCL_FUNCNAME, 'f' },
{ _DPRINTK_FLAGS_INCL_LINENO, 'l' },
{ _DPRINTK_FLAGS_INCL_TID, 't' },
{ _DPRINTK_FLAGS_NONE, '_' },
};
/* format a string into buf[] which describes the _ddebug's flags */
static char *ddebug_describe_flags(struct _ddebug *dp, char *buf,
size_t maxlen)
{
char *p = buf;
int i;
BUG_ON(maxlen < 6);
for (i = 0; i < ARRAY_SIZE(opt_array); ++i)
if (dp->flags & opt_array[i].flag)
*p++ = opt_array[i].opt_char;
if (p == buf)
*p++ = '_';
*p = '\0';
return buf;
}
#define vpr_info(fmt, ...) \
do { \
if (verbose) \
pr_info(fmt, ##__VA_ARGS__); \
} while (0)
static void vpr_info_dq(const struct ddebug_query *query, const char *msg)
{
/* trim any trailing newlines */
int fmtlen = 0;
if (query->format) {
fmtlen = strlen(query->format);
while (fmtlen && query->format[fmtlen - 1] == '\n')
fmtlen--;
}
vpr_info("%s: func=\"%s\" file=\"%s\" module=\"%s\" format=\"%.*s\" lineno=%u-%u\n",
msg,
query->function ? query->function : "",
query->filename ? query->filename : "",
query->module ? query->module : "",
fmtlen, query->format ? query->format : "",
query->first_lineno, query->last_lineno);
}
/*
* Search the tables for _ddebug's which match the given `query' and
* apply the `flags' and `mask' to them. Returns number of matching
* callsites, normally the same as number of changes. If verbose,
* logs the changes. Takes ddebug_lock.
*/
static int ddebug_change(const struct ddebug_query *query,
unsigned int flags, unsigned int mask)
{
int i;
struct ddebug_table *dt;
unsigned int newflags;
unsigned int nfound = 0;
char flagbuf[10];
/* search for matching ddebugs */
mutex_lock(&ddebug_lock);
list_for_each_entry(dt, &ddebug_tables, link) {
/* match against the module name */
if (query->module && strcmp(query->module, dt->mod_name))
continue;
for (i = 0; i < dt->num_ddebugs; i++) {
struct _ddebug *dp = &dt->ddebugs[i];
/* match against the source filename */
if (query->filename &&
strcmp(query->filename, dp->filename) &&
strcmp(query->filename, kbasename(dp->filename)) &&
strcmp(query->filename, trim_prefix(dp->filename)))
continue;
/* match against the function */
if (query->function &&
strcmp(query->function, dp->function))
continue;
/* match against the format */
if (query->format &&
!strstr(dp->format, query->format))
continue;
/* match against the line number range */
if (query->first_lineno &&
dp->lineno < query->first_lineno)
continue;
if (query->last_lineno &&
dp->lineno > query->last_lineno)
continue;
nfound++;
newflags = (dp->flags & mask) | flags;
if (newflags == dp->flags)
continue;
dp->flags = newflags;
vpr_info("changed %s:%d [%s]%s =%s\n",
trim_prefix(dp->filename), dp->lineno,
dt->mod_name, dp->function,
ddebug_describe_flags(dp, flagbuf,
sizeof(flagbuf)));
}
}
mutex_unlock(&ddebug_lock);
if (!nfound && verbose)
pr_info("no matches for query\n");
return nfound;
}
/*
* Split the buffer `buf' into space-separated words.
* Handles simple " and ' quoting, i.e. without nested,
* embedded or escaped \". Return the number of words
* or <0 on error.
*/
static int ddebug_tokenize(char *buf, char *words[], int maxwords)
{
int nwords = 0;
while (*buf) {
char *end;
/* Skip leading whitespace */
buf = skip_spaces(buf);
if (!*buf)
break; /* oh, it was trailing whitespace */
if (*buf == '#')
break; /* token starts comment, skip rest of line */
/* find `end' of word, whitespace separated or quoted */
if (*buf == '"' || *buf == '\'') {
int quote = *buf++;
for (end = buf; *end && *end != quote; end++)
;
if (!*end) {
pr_err("unclosed quote: %s\n", buf);
return -EINVAL; /* unclosed quote */
}
} else {
for (end = buf; *end && !isspace(*end); end++)
;
BUG_ON(end == buf);
}
/* `buf' is start of word, `end' is one past its end */
if (nwords == maxwords) {
pr_err("too many words, legal max <=%d\n", maxwords);
return -EINVAL; /* ran out of words[] before bytes */
}
if (*end)
*end++ = '\0'; /* terminate the word */
words[nwords++] = buf;
buf = end;
}
if (verbose) {
int i;
pr_info("split into words:");
for (i = 0; i < nwords; i++)
pr_cont(" \"%s\"", words[i]);
pr_cont("\n");
}
return nwords;
}
/*
* Parse a single line number. Note that the empty string ""
* is treated as a special case and converted to zero, which
* is later treated as a "don't care" value.
*/
static inline int parse_lineno(const char *str, unsigned int *val)
{
char *end = NULL;
BUG_ON(str == NULL);
if (*str == '\0') {
*val = 0;
return 0;
}
*val = simple_strtoul(str, &end, 10);
if (end == NULL || end == str || *end != '\0') {
pr_err("bad line-number: %s\n", str);
return -EINVAL;
}
return 0;
}
static int check_set(const char **dest, char *src, char *name)
{
int rc = 0;
if (*dest) {
rc = -EINVAL;
pr_err("match-spec:%s val:%s overridden by %s\n",
name, *dest, src);
}
*dest = src;
return rc;
}
/*
* Parse words[] as a ddebug query specification, which is a series
* of (keyword, value) pairs chosen from these possibilities:
*
* func <function-name>
* file <full-pathname>
* file <base-filename>
* module <module-name>
* format <escaped-string-to-find-in-format>
* line <lineno>
* line <first-lineno>-<last-lineno> // where either may be empty
*
* Only 1 of each type is allowed.
* Returns 0 on success, <0 on error.
*/
static int ddebug_parse_query(char *words[], int nwords,
struct ddebug_query *query, const char *modname)
{
unsigned int i;
int rc;
/* check we have an even number of words */
if (nwords % 2 != 0) {
pr_err("expecting pairs of match-spec <value>\n");
return -EINVAL;
}
memset(query, 0, sizeof(*query));
if (modname)
/* support $modname.dyndbg=<multiple queries> */
query->module = modname;
for (i = 0; i < nwords; i += 2) {
if (!strcmp(words[i], "func")) {
rc = check_set(&query->function, words[i+1], "func");
} else if (!strcmp(words[i], "file")) {
rc = check_set(&query->filename, words[i+1], "file");
} else if (!strcmp(words[i], "module")) {
rc = check_set(&query->module, words[i+1], "module");
} else if (!strcmp(words[i], "format")) {
string_unescape_inplace(words[i+1], UNESCAPE_SPACE |
UNESCAPE_OCTAL |
UNESCAPE_SPECIAL);
rc = check_set(&query->format, words[i+1], "format");
} else if (!strcmp(words[i], "line")) {
char *first = words[i+1];
char *last = strchr(first, '-');
if (query->first_lineno || query->last_lineno) {
pr_err("match-spec: line used 2x\n");
return -EINVAL;
}
if (last)
*last++ = '\0';
if (parse_lineno(first, &query->first_lineno) < 0) {
pr_err("line-number is <0\n");
return -EINVAL;
}
if (last) {
/* range <first>-<last> */
if (parse_lineno(last, &query->last_lineno)
< query->first_lineno) {
pr_err("last-line:%d < 1st-line:%d\n",
query->last_lineno,
query->first_lineno);
return -EINVAL;
}
} else {
query->last_lineno = query->first_lineno;
}
} else {
pr_err("unknown keyword \"%s\"\n", words[i]);
return -EINVAL;
}
if (rc)
return rc;
}
vpr_info_dq(query, "parsed");
return 0;
}
/*
* Parse `str' as a flags specification, format [-+=][p]+.
* Sets up *maskp and *flagsp to be used when changing the
* flags fields of matched _ddebug's. Returns 0 on success
* or <0 on error.
*/
static int ddebug_parse_flags(const char *str, unsigned int *flagsp,
unsigned int *maskp)
{
unsigned flags = 0;
int op = '=', i;
switch (*str) {
case '+':
case '-':
case '=':
op = *str++;
break;
default:
pr_err("bad flag-op %c, at start of %s\n", *str, str);
return -EINVAL;
}
vpr_info("op='%c'\n", op);
for (; *str ; ++str) {
for (i = ARRAY_SIZE(opt_array) - 1; i >= 0; i--) {
if (*str == opt_array[i].opt_char) {
flags |= opt_array[i].flag;
break;
}
}
if (i < 0) {
pr_err("unknown flag '%c' in \"%s\"\n", *str, str);
return -EINVAL;
}
}
vpr_info("flags=0x%x\n", flags);
/* calculate final *flagsp, *maskp according to mask and op */
switch (op) {
case '=':
*maskp = 0;
*flagsp = flags;
break;
case '+':
*maskp = ~0U;
*flagsp = flags;
break;
case '-':
*maskp = ~flags;
*flagsp = 0;
break;
}
vpr_info("*flagsp=0x%x *maskp=0x%x\n", *flagsp, *maskp);
return 0;
}
static int ddebug_exec_query(char *query_string, const char *modname)
{
unsigned int flags = 0, mask = 0;
struct ddebug_query query;
#define MAXWORDS 9
int nwords, nfound;
char *words[MAXWORDS];
nwords = ddebug_tokenize(query_string, words, MAXWORDS);
if (nwords <= 0) {
pr_err("tokenize failed\n");
return -EINVAL;
}
/* check flags 1st (last arg) so query is pairs of spec,val */
if (ddebug_parse_flags(words[nwords-1], &flags, &mask)) {
pr_err("flags parse failed\n");
return -EINVAL;
}
if (ddebug_parse_query(words, nwords-1, &query, modname)) {
pr_err("query parse failed\n");
return -EINVAL;
}
/* actually go and implement the change */
nfound = ddebug_change(&query, flags, mask);
vpr_info_dq(&query, nfound ? "applied" : "no-match");
return nfound;
}
/* handle multiple queries in query string, continue on error, return
last error or number of matching callsites. Module name is either
in param (for boot arg) or perhaps in query string.
*/
static int ddebug_exec_queries(char *query, const char *modname)
{
char *split;
int i, errs = 0, exitcode = 0, rc, nfound = 0;
for (i = 0; query; query = split) {
split = strpbrk(query, ";\n");
if (split)
*split++ = '\0';
query = skip_spaces(query);
if (!query || !*query || *query == '#')
continue;
vpr_info("query %d: \"%s\"\n", i, query);
rc = ddebug_exec_query(query, modname);
if (rc < 0) {
errs++;
exitcode = rc;
} else {
nfound += rc;
}
i++;
}
vpr_info("processed %d queries, with %d matches, %d errs\n",
i, nfound, errs);
if (exitcode)
return exitcode;
return nfound;
}
#define PREFIX_SIZE 64
static int remaining(int wrote)
{
if (PREFIX_SIZE - wrote > 0)
return PREFIX_SIZE - wrote;
return 0;
}
static char *dynamic_emit_prefix(const struct _ddebug *desc, char *buf)
{
int pos_after_tid;
int pos = 0;
*buf = '\0';
if (desc->flags & _DPRINTK_FLAGS_INCL_TID) {
if (in_interrupt())
pos += snprintf(buf + pos, remaining(pos), "<intr> ");
else
pos += snprintf(buf + pos, remaining(pos), "[%d] ",
task_pid_vnr(current));
}
pos_after_tid = pos;
if (desc->flags & _DPRINTK_FLAGS_INCL_MODNAME)
pos += snprintf(buf + pos, remaining(pos), "%s:",
desc->modname);
if (desc->flags & _DPRINTK_FLAGS_INCL_FUNCNAME)
pos += snprintf(buf + pos, remaining(pos), "%s:",
desc->function);
if (desc->flags & _DPRINTK_FLAGS_INCL_LINENO)
pos += snprintf(buf + pos, remaining(pos), "%d:",
desc->lineno);
if (pos - pos_after_tid)
pos += snprintf(buf + pos, remaining(pos), " ");
if (pos >= PREFIX_SIZE)
buf[PREFIX_SIZE - 1] = '\0';
return buf;
}
int __dynamic_pr_debug(struct _ddebug *descriptor, const char *fmt, ...)
{
va_list args;
int res;
struct va_format vaf;
char buf[PREFIX_SIZE];
BUG_ON(!descriptor);
BUG_ON(!fmt);
va_start(args, fmt);
vaf.fmt = fmt;
vaf.va = &args;
res = printk(KERN_DEBUG "%s%pV",
dynamic_emit_prefix(descriptor, buf), &vaf);
va_end(args);
return res;
}
EXPORT_SYMBOL(__dynamic_pr_debug);
int __dynamic_dev_dbg(struct _ddebug *descriptor,
const struct device *dev, const char *fmt, ...)
{
struct va_format vaf;
va_list args;
int res;
BUG_ON(!descriptor);
BUG_ON(!fmt);
va_start(args, fmt);
vaf.fmt = fmt;
vaf.va = &args;
if (!dev) {
res = printk(KERN_DEBUG "(NULL device *): %pV", &vaf);
} else {
char buf[PREFIX_SIZE];
res = dev_printk_emit(7, dev, "%s%s %s: %pV",
dynamic_emit_prefix(descriptor, buf),
dev_driver_string(dev), dev_name(dev),
&vaf);
}
va_end(args);
return res;
}
EXPORT_SYMBOL(__dynamic_dev_dbg);
#ifdef CONFIG_NET
int __dynamic_netdev_dbg(struct _ddebug *descriptor,
const struct net_device *dev, const char *fmt, ...)
{
struct va_format vaf;
va_list args;
int res;
BUG_ON(!descriptor);
BUG_ON(!fmt);
va_start(args, fmt);
vaf.fmt = fmt;
vaf.va = &args;
if (dev && dev->dev.parent) {
char buf[PREFIX_SIZE];
res = dev_printk_emit(7, dev->dev.parent,
"%s%s %s %s: %pV",
dynamic_emit_prefix(descriptor, buf),
dev_driver_string(dev->dev.parent),
dev_name(dev->dev.parent),
netdev_name(dev), &vaf);
} else if (dev) {
res = printk(KERN_DEBUG "%s: %pV", netdev_name(dev), &vaf);
} else {
res = printk(KERN_DEBUG "(NULL net_device): %pV", &vaf);
}
va_end(args);
return res;
}
EXPORT_SYMBOL(__dynamic_netdev_dbg);
#endif
#define DDEBUG_STRING_SIZE 1024
static __initdata char ddebug_setup_string[DDEBUG_STRING_SIZE];
static __init int ddebug_setup_query(char *str)
{
if (strlen(str) >= DDEBUG_STRING_SIZE) {
pr_warn("ddebug boot param string too large\n");
return 0;
}
strlcpy(ddebug_setup_string, str, DDEBUG_STRING_SIZE);
return 1;
}
__setup("ddebug_query=", ddebug_setup_query);
/*
* File_ops->write method for <debugfs>/dynamic_debug/conrol. Gathers the
* command text from userspace, parses and executes it.
*/
#define USER_BUF_PAGE 4096
static ssize_t ddebug_proc_write(struct file *file, const char __user *ubuf,
size_t len, loff_t *offp)
{
char *tmpbuf;
int ret;
if (len == 0)
return 0;
if (len > USER_BUF_PAGE - 1) {
pr_warn("expected <%d bytes into control\n", USER_BUF_PAGE);
return -E2BIG;
}
tmpbuf = kmalloc(len + 1, GFP_KERNEL);
if (!tmpbuf)
return -ENOMEM;
if (copy_from_user(tmpbuf, ubuf, len)) {
kfree(tmpbuf);
return -EFAULT;
}
tmpbuf[len] = '\0';
vpr_info("read %d bytes from userspace\n", (int)len);
ret = ddebug_exec_queries(tmpbuf, NULL);
kfree(tmpbuf);
if (ret < 0)
return ret;
*offp += len;
return len;
}
/*
* Set the iterator to point to the first _ddebug object
* and return a pointer to that first object. Returns
* NULL if there are no _ddebugs at all.
*/
static struct _ddebug *ddebug_iter_first(struct ddebug_iter *iter)
{
if (list_empty(&ddebug_tables)) {
iter->table = NULL;
iter->idx = 0;
return NULL;
}
iter->table = list_entry(ddebug_tables.next,
struct ddebug_table, link);
iter->idx = 0;
return &iter->table->ddebugs[iter->idx];
}
/*
* Advance the iterator to point to the next _ddebug
* object from the one the iterator currently points at,
* and returns a pointer to the new _ddebug. Returns
* NULL if the iterator has seen all the _ddebugs.
*/
static struct _ddebug *ddebug_iter_next(struct ddebug_iter *iter)
{
if (iter->table == NULL)
return NULL;
if (++iter->idx == iter->table->num_ddebugs) {
/* iterate to next table */
iter->idx = 0;
if (list_is_last(&iter->table->link, &ddebug_tables)) {
iter->table = NULL;
return NULL;
}
iter->table = list_entry(iter->table->link.next,
struct ddebug_table, link);
}
return &iter->table->ddebugs[iter->idx];
}
/*
* Seq_ops start method. Called at the start of every
* read() call from userspace. Takes the ddebug_lock and
* seeks the seq_file's iterator to the given position.
*/
static void *ddebug_proc_start(struct seq_file *m, loff_t *pos)
{
struct ddebug_iter *iter = m->private;
struct _ddebug *dp;
int n = *pos;
vpr_info("called m=%p *pos=%lld\n", m, (unsigned long long)*pos);
mutex_lock(&ddebug_lock);
if (!n)
return SEQ_START_TOKEN;
if (n < 0)
return NULL;
dp = ddebug_iter_first(iter);
while (dp != NULL && --n > 0)
dp = ddebug_iter_next(iter);
return dp;
}
/*
* Seq_ops next method. Called several times within a read()
* call from userspace, with ddebug_lock held. Walks to the
* next _ddebug object with a special case for the header line.
*/
static void *ddebug_proc_next(struct seq_file *m, void *p, loff_t *pos)
{
struct ddebug_iter *iter = m->private;
struct _ddebug *dp;
vpr_info("called m=%p p=%p *pos=%lld\n",
m, p, (unsigned long long)*pos);
if (p == SEQ_START_TOKEN)
dp = ddebug_iter_first(iter);
else
dp = ddebug_iter_next(iter);
++*pos;
return dp;
}
/*
* Seq_ops show method. Called several times within a read()
* call from userspace, with ddebug_lock held. Formats the
* current _ddebug as a single human-readable line, with a
* special case for the header line.
*/
static int ddebug_proc_show(struct seq_file *m, void *p)
{
struct ddebug_iter *iter = m->private;
struct _ddebug *dp = p;
char flagsbuf[10];
vpr_info("called m=%p p=%p\n", m, p);
if (p == SEQ_START_TOKEN) {
seq_puts(m,
"# filename:lineno [module]function flags format\n");
return 0;
}
seq_printf(m, "%s:%u [%s]%s =%s \"",
trim_prefix(dp->filename), dp->lineno,
iter->table->mod_name, dp->function,
ddebug_describe_flags(dp, flagsbuf, sizeof(flagsbuf)));
seq_escape(m, dp->format, "\t\r\n\"");
seq_puts(m, "\"\n");
return 0;
}
/*
* Seq_ops stop method. Called at the end of each read()
* call from userspace. Drops ddebug_lock.
*/
static void ddebug_proc_stop(struct seq_file *m, void *p)
{
vpr_info("called m=%p p=%p\n", m, p);
mutex_unlock(&ddebug_lock);
}
static const struct seq_operations ddebug_proc_seqops = {
.start = ddebug_proc_start,
.next = ddebug_proc_next,
.show = ddebug_proc_show,
.stop = ddebug_proc_stop
};
/*
* File_ops->open method for <debugfs>/dynamic_debug/control. Does
* the seq_file setup dance, and also creates an iterator to walk the
* _ddebugs. Note that we create a seq_file always, even for O_WRONLY
* files where it's not needed, as doing so simplifies the ->release
* method.
*/
static int ddebug_proc_open(struct inode *inode, struct file *file)
{
struct ddebug_iter *iter;
int err;
vpr_info("called\n");
iter = kzalloc(sizeof(*iter), GFP_KERNEL);
if (iter == NULL)
return -ENOMEM;
err = seq_open(file, &ddebug_proc_seqops);
if (err) {
kfree(iter);
return err;
}
((struct seq_file *)file->private_data)->private = iter;
return 0;
}
static const struct file_operations ddebug_proc_fops = {
.owner = THIS_MODULE,
.open = ddebug_proc_open,
.read = seq_read,
.llseek = seq_lseek,
.release = seq_release_private,
.write = ddebug_proc_write
};
/*
* Allocate a new ddebug_table for the given module
* and add it to the global list.
*/
int ddebug_add_module(struct _ddebug *tab, unsigned int n,
const char *name)
{
struct ddebug_table *dt;
char *new_name;
dt = kzalloc(sizeof(*dt), GFP_KERNEL);
if (dt == NULL)
return -ENOMEM;
new_name = kstrdup(name, GFP_KERNEL);
if (new_name == NULL) {
kfree(dt);
return -ENOMEM;
}
dt->mod_name = new_name;
dt->num_ddebugs = n;
dt->ddebugs = tab;
mutex_lock(&ddebug_lock);
list_add_tail(&dt->link, &ddebug_tables);
mutex_unlock(&ddebug_lock);
vpr_info("%u debug prints in module %s\n", n, dt->mod_name);
return 0;
}
EXPORT_SYMBOL_GPL(ddebug_add_module);
/* helper for ddebug_dyndbg_(boot|module)_param_cb */
static int ddebug_dyndbg_param_cb(char *param, char *val,
const char *modname, int on_err)
{
char *sep;
sep = strchr(param, '.');
if (sep) {
/* needed only for ddebug_dyndbg_boot_param_cb */
*sep = '\0';
modname = param;
param = sep + 1;
}
if (strcmp(param, "dyndbg"))
return on_err; /* determined by caller */
ddebug_exec_queries((val ? val : "+p"), modname);
return 0; /* query failure shouldnt stop module load */
}
/* handle both dyndbg and $module.dyndbg params at boot */
static int ddebug_dyndbg_boot_param_cb(char *param, char *val,
const char *unused)
{
vpr_info("%s=\"%s\"\n", param, val);
return ddebug_dyndbg_param_cb(param, val, NULL, 0);
}
/*
* modprobe foo finds foo.params in boot-args, strips "foo.", and
* passes them to load_module(). This callback gets unknown params,
* processes dyndbg params, rejects others.
*/
int ddebug_dyndbg_module_param_cb(char *param, char *val, const char *module)
{
vpr_info("module: %s %s=\"%s\"\n", module, param, val);
return ddebug_dyndbg_param_cb(param, val, module, -ENOENT);
}
static void ddebug_table_free(struct ddebug_table *dt)
{
list_del_init(&dt->link);
kfree(dt->mod_name);
kfree(dt);
}
/*
* Called in response to a module being unloaded. Removes
* any ddebug_table's which point at the module.
*/
int ddebug_remove_module(const char *mod_name)
{
struct ddebug_table *dt, *nextdt;
int ret = -ENOENT;
vpr_info("removing module \"%s\"\n", mod_name);
mutex_lock(&ddebug_lock);
list_for_each_entry_safe(dt, nextdt, &ddebug_tables, link) {
if (!strcmp(dt->mod_name, mod_name)) {
ddebug_table_free(dt);
ret = 0;
}
}
mutex_unlock(&ddebug_lock);
return ret;
}
EXPORT_SYMBOL_GPL(ddebug_remove_module);
static void ddebug_remove_all_tables(void)
{
mutex_lock(&ddebug_lock);
while (!list_empty(&ddebug_tables)) {
struct ddebug_table *dt = list_entry(ddebug_tables.next,
struct ddebug_table,
link);
ddebug_table_free(dt);
}
mutex_unlock(&ddebug_lock);
}
static __initdata int ddebug_init_success;
static int __init dynamic_debug_init_debugfs(void)
{
struct dentry *dir, *file;
if (!ddebug_init_success)
return -ENODEV;
dir = debugfs_create_dir("dynamic_debug", NULL);
if (!dir)
return -ENOMEM;
file = debugfs_create_file("control", 0644, dir, NULL,
&ddebug_proc_fops);
if (!file) {
debugfs_remove(dir);
return -ENOMEM;
}
return 0;
}
static int __init dynamic_debug_init(void)
{
struct _ddebug *iter, *iter_start;
const char *modname = NULL;
char *cmdline;
int ret = 0;
int n = 0, entries = 0, modct = 0;
int verbose_bytes = 0;
if (__start___verbose == __stop___verbose) {
pr_warn("_ddebug table is empty in a CONFIG_DYNAMIC_DEBUG build\n");
return 1;
}
iter = __start___verbose;
modname = iter->modname;
iter_start = iter;
for (; iter < __stop___verbose; iter++) {
entries++;
verbose_bytes += strlen(iter->modname) + strlen(iter->function)
+ strlen(iter->filename) + strlen(iter->format);
if (strcmp(modname, iter->modname)) {
modct++;
ret = ddebug_add_module(iter_start, n, modname);
if (ret)
goto out_err;
n = 0;
modname = iter->modname;
iter_start = iter;
}
n++;
}
ret = ddebug_add_module(iter_start, n, modname);
if (ret)
goto out_err;
ddebug_init_success = 1;
vpr_info("%d modules, %d entries and %d bytes in ddebug tables, %d bytes in (readonly) verbose section\n",
modct, entries, (int)(modct * sizeof(struct ddebug_table)),
verbose_bytes + (int)(__stop___verbose - __start___verbose));
/* apply ddebug_query boot param, dont unload tables on err */
if (ddebug_setup_string[0] != '\0') {
pr_warn("ddebug_query param name is deprecated, change it to dyndbg\n");
ret = ddebug_exec_queries(ddebug_setup_string, NULL);
if (ret < 0)
pr_warn("Invalid ddebug boot param %s\n",
ddebug_setup_string);
else
pr_info("%d changes by ddebug_query\n", ret);
}
/* now that ddebug tables are loaded, process all boot args
* again to find and activate queries given in dyndbg params.
* While this has already been done for known boot params, it
* ignored the unknown ones (dyndbg in particular). Reusing
* parse_args avoids ad-hoc parsing. This will also attempt
* to activate queries for not-yet-loaded modules, which is
* slightly noisy if verbose, but harmless.
*/
cmdline = kstrdup(saved_command_line, GFP_KERNEL);
parse_args("dyndbg params", cmdline, NULL,
0, 0, 0, &ddebug_dyndbg_boot_param_cb);
kfree(cmdline);
return 0;
out_err:
ddebug_remove_all_tables();
return 0;
}
/* Allow early initialization for boot messages via boot param */
early_initcall(dynamic_debug_init);
/* Debugfs setup must be done later */
fs_initcall(dynamic_debug_init_debugfs);
|
e4da5381db409015c780a5fb14ec6f6a11a69b0a
|
b6acd6eed2b8946c1c1e19fa30081cbab0a2954f
|
/starry_fmu/Framework/source/Console/mavlink_console.c
|
c09607ca472c05010f98a9072a40d7acb811422d
|
[
"BSD-3-Clause"
] |
permissive
|
JcZou/StarryPilot
|
7ce1ed454f133ccd30d71916811e2bf23196d2eb
|
97af0338a54e1eeece877c72222aeaf4b7e80ad7
|
refs/heads/master
| 2023-03-12T19:10:17.225314
| 2021-11-27T19:44:26
| 2021-11-27T19:44:26
| 137,048,745
| 304
| 172
|
BSD-3-Clause
| 2020-08-26T07:34:49
| 2018-06-12T09:27:59
|
C
|
UTF-8
|
C
| false
| false
| 4,782
|
c
|
mavlink_console.c
|
#include <rtthread.h>
#include <rtdevice.h>
#include "mavproxy.h"
static struct rt_device mavlink_console_dev;
/* RT-Thread Device Interface */
/*
* This function initializes mavlink_console device.
*/
static rt_err_t rt_mavlink_console_init(struct rt_device *dev)
{
rt_err_t result = RT_EOK;
RT_ASSERT(dev != RT_NULL);
return result;
}
static rt_err_t rt_mavlink_console_open(struct rt_device *dev, rt_uint16_t oflag)
{
RT_ASSERT(dev != RT_NULL);
/* check device flag with the open flag */
if ((oflag & RT_DEVICE_FLAG_DMA_RX) && !(dev->flag & RT_DEVICE_FLAG_DMA_RX))
return -RT_EIO;
if ((oflag & RT_DEVICE_FLAG_DMA_TX) && !(dev->flag & RT_DEVICE_FLAG_DMA_TX))
return -RT_EIO;
if ((oflag & RT_DEVICE_FLAG_INT_RX) && !(dev->flag & RT_DEVICE_FLAG_INT_RX))
return -RT_EIO;
if ((oflag & RT_DEVICE_FLAG_INT_TX) && !(dev->flag & RT_DEVICE_FLAG_INT_TX))
return -RT_EIO;
/* get open flags */
dev->open_flag = oflag & 0xFFFF;
/* initialize the Rx/Tx structure according to open flag */
if (oflag & RT_DEVICE_FLAG_DMA_RX)
{
dev->open_flag |= RT_DEVICE_FLAG_DMA_RX;
}
else if (oflag & RT_DEVICE_FLAG_INT_RX)
{
dev->open_flag |= RT_DEVICE_FLAG_INT_RX;
}
if (oflag & RT_DEVICE_FLAG_DMA_TX)
{
dev->open_flag |= RT_DEVICE_FLAG_DMA_TX;
}
else if (oflag & RT_DEVICE_FLAG_INT_TX)
{
dev->open_flag |= RT_DEVICE_FLAG_INT_TX;
}
return RT_EOK;
}
static rt_err_t rt_mavlink_console_close(struct rt_device *dev)
{
RT_ASSERT(dev != RT_NULL);
/* this device has more reference count */
if (dev->ref_count > 1) return RT_EOK;
if (dev->open_flag & RT_DEVICE_FLAG_INT_RX)
{
dev->open_flag &= ~RT_DEVICE_FLAG_INT_RX;
}
else if (dev->open_flag & RT_DEVICE_FLAG_DMA_RX)
{
dev->open_flag &= ~RT_DEVICE_FLAG_DMA_RX;
}
if (dev->open_flag & RT_DEVICE_FLAG_INT_TX)
{
dev->open_flag &= ~RT_DEVICE_FLAG_INT_TX;
}
else if (dev->open_flag & RT_DEVICE_FLAG_DMA_TX)
{
dev->open_flag &= ~RT_DEVICE_FLAG_DMA_TX;
}
return RT_EOK;
}
static rt_size_t rt_mavlink_console_read(struct rt_device *dev,
rt_off_t pos,
void *buffer,
rt_size_t size)
{
RT_ASSERT(dev != RT_NULL);
if (size == 0) return 0;
return mavproxy_msg_serial_control_read((uint8_t *)buffer, size);
}
static rt_size_t rt_mavlink_console_write(struct rt_device *dev,
rt_off_t pos,
const void *buffer,
rt_size_t size)
{
rt_size_t len;
rt_size_t left = size;
uint8_t *ptr = buffer;
RT_ASSERT(dev != RT_NULL);
if (size == 0) return 0;
while (left) {
len = left < 70 ? left : 70;
if (mavproxy_msg_serial_control_send((uint8_t *)buffer, len)) {
break;
}
left -= len;
}
return size - left;
}
static rt_err_t rt_mavlink_console_control(struct rt_device *dev,
rt_uint8_t cmd,
void *args)
{
RT_ASSERT(dev != RT_NULL);
switch (cmd)
{
case RT_DEVICE_CTRL_SUSPEND:
/* suspend device */
dev->flag |= RT_DEVICE_FLAG_SUSPENDED;
break;
case RT_DEVICE_CTRL_RESUME:
/* resume device */
dev->flag &= ~RT_DEVICE_FLAG_SUSPENDED;
break;
case RT_DEVICE_CTRL_CONFIG:
/* configure device */
break;
case RT_DEVICE_CTRL_GET_INT:
break;
default :
break;
}
return RT_EOK;
}
/*
* mavlink console register
*/
rt_err_t rt_hw_mavlink_console_init(void)
{
struct rt_device *device;
device = &mavlink_console_dev;
device->type = RT_Device_Class_Char;
device->rx_indicate = RT_NULL;
device->tx_complete = RT_NULL;
device->init = rt_mavlink_console_init;
device->open = rt_mavlink_console_open;
device->close = rt_mavlink_console_close;
device->read = rt_mavlink_console_read;
device->write = rt_mavlink_console_write;
device->control = rt_mavlink_console_control;
device->user_data = RT_NULL;
/* register a character device */
return rt_device_register(device, "mav", RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX);
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.