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
|
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
55b75e7839c3b5f3e1eb09d245334967fe4f5c2d
|
95ae7dfa9ee578f1b24a65986ff78bf77ceca0c5
|
/Engine/lib/curl/tests/libtest/lib1939.c
|
1c88f68a85060362c568b60abbb0096d347b062e
|
[
"curl",
"MIT",
"LicenseRef-scancode-unknown"
] |
permissive
|
TorqueGameEngines/Torque3D
|
4e1f6a05cc0928980c8c7c20bcdd680eaa6dcee8
|
a445a4364664e299196bd551d213844486080145
|
refs/heads/development
| 2023-09-03T12:40:40.658487
| 2023-08-24T14:44:43
| 2023-08-24T14:44:43
| 267,440,108
| 1,192
| 178
|
MIT
| 2023-09-13T14:28:16
| 2020-05-27T22:35:54
|
C++
|
UTF-8
|
C
| false
| false
| 2,311
|
c
|
lib1939.c
|
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2022, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.haxx.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "test.h"
#include "memdebug.h"
int test(char *URL)
{
CURLM *multi;
CURL *easy;
int running_handles;
curl_global_init(CURL_GLOBAL_DEFAULT);
multi = curl_multi_init();
if(multi) {
easy = curl_easy_init();
if(easy) {
CURLcode c;
CURLMcode m;
/* Crash only happens when using HTTPS */
c = curl_easy_setopt(easy, CURLOPT_URL, URL);
if(!c)
/* Any old HTTP tunneling proxy will do here */
c = curl_easy_setopt(easy, CURLOPT_PROXY, libtest_arg2);
if(!c) {
/* We're going to drive the transfer using multi interface here,
because we want to stop during the middle. */
m = curl_multi_add_handle(multi, easy);
if(!m)
/* Run the multi handle once, just enough to start establishing an
HTTPS connection. */
m = curl_multi_perform(multi, &running_handles);
if(m)
fprintf(stderr, "curl_multi_perform failed\n");
}
/* Close the easy handle *before* the multi handle. Doing it the other
way around avoids the issue. */
curl_easy_cleanup(easy);
}
curl_multi_cleanup(multi); /* double-free happens here */
}
curl_global_cleanup();
return CURLE_OK;
}
|
fb7dda12f061265fbd99355ed647b58a44363c4e
|
99bdb3251fecee538e0630f15f6574054dfc1468
|
/bsp/at32/libraries/AT32F403A_407_Firmware_Library/drivers/src/at32f403a_407_bpr.c
|
08e1922e1f070949d1d224bd4628375d41060550
|
[
"Zlib",
"LicenseRef-scancode-proprietary-license",
"MIT",
"BSD-3-Clause",
"X11",
"BSD-4-Clause-UC",
"LicenseRef-scancode-unknown-license-reference",
"Apache-2.0"
] |
permissive
|
RT-Thread/rt-thread
|
03a7c52c2aeb1b06a544143b0e803d72f47d1ece
|
3602f891211904a27dcbd51e5ba72fefce7326b2
|
refs/heads/master
| 2023-09-01T04:10:20.295801
| 2023-08-31T16:20:55
| 2023-08-31T16:20:55
| 7,408,108
| 9,599
| 5,805
|
Apache-2.0
| 2023-09-14T13:37:26
| 2013-01-02T14:49:21
|
C
|
UTF-8
|
C
| false
| false
| 5,577
|
c
|
at32f403a_407_bpr.c
|
/**
**************************************************************************
* @file at32f403a_407_bpr.c
* @version v2.0.9
* @date 2022-04-25
* @brief contains all the functions for the bpr firmware library
**************************************************************************
* 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.
*
**************************************************************************
*/
#include "at32f403a_407_conf.h"
/** @addtogroup AT32F403A_407_periph_driver
* @{
*/
/** @defgroup BPR
* @brief BPR driver modules
* @{
*/
#ifdef BPR_MODULE_ENABLED
/** @defgroup BPR_private_functions
* @{
*/
/**
* @brief bpr reset by crm reset register
* @param none
* @retval none
*/
void bpr_reset(void)
{
crm_battery_powered_domain_reset(TRUE);
crm_battery_powered_domain_reset(FALSE);
}
/**
* @brief bpr event flag get, for tamper event flag
* @param flag: specifies the flag to check.
* this parameter can be one of the following values:
* - BPR_TAMPER_INTERRUPT_FLAG: tamper interrupt flag
* - BPR_TAMPER_EVENT_FLAG: tamper event flag
* @retval state of tamper event flag
*/
flag_status bpr_flag_get(uint32_t flag)
{
if(flag == BPR_TAMPER_INTERRUPT_FLAG)
{
return (flag_status)(BPR->ctrlsts_bit.tpif);
}
else
{
return (flag_status)(BPR->ctrlsts_bit.tpef);
}
}
/**
* @brief clear bpr tamper flag
* @param flag: specifies the flag to clear.
* this parameter can be one of the following values:
* - BPR_TAMPER_INTERRUPT_FLAG: tamper interrupt flag
* - BPR_TAMPER_EVENT_FLAG: tamper event flag
* @retval none
*/
void bpr_flag_clear(uint32_t flag)
{
if(flag == BPR_TAMPER_INTERRUPT_FLAG)
{
BPR->ctrlsts_bit.tpifclr = TRUE;
}
else
{
BPR->ctrlsts_bit.tpefclr = TRUE;
}
}
/**
* @brief enable or disable bpr tamper interrupt
* @param new_state (TRUE or FALSE)
* @retval none
*/
void bpr_interrupt_enable(confirm_state new_state)
{
BPR->ctrlsts_bit.tpien = new_state;
}
/**
* @brief read bpr bpr data
* @param bpr_data
* this parameter can be one of the following values:
* - BPR_DATA1
* - BPR_DATA2
* ...
* - BPR_DATA41
* - BPR_DATA42
* @retval none
*/
uint16_t bpr_data_read(bpr_data_type bpr_data)
{
return (*(__IO uint16_t *)(BPR_BASE + bpr_data));
}
/**
* @brief write bpr data
* @param bpr_data
* this parameter can be one of the following values:
* - BPR_DATA1
* - BPR_DATA2
* ...
* - BPR_DATA41
* - BPR_DATA42
* @param data_value (0x0000~0xFFFF)
* @retval none
*/
void bpr_data_write(bpr_data_type bpr_data, uint16_t data_value)
{
(*(__IO uint32_t *)(BPR_BASE + bpr_data)) = data_value;
}
/**
* @brief select bpr rtc output
* @param output_source
* this parameter can be one of the following values:
* - BPR_RTC_OUTPUT_NONE: output disable.
* - BPR_RTC_OUTPUT_CLOCK_CAL_BEFORE: output clock before calibration.
* - BPR_RTC_OUTPUT_ALARM: output alarm event with pluse mode.
* - BPR_RTC_OUTPUT_SECOND: output second event with pluse mode.
* - BPR_RTC_OUTPUT_CLOCK_CAL_AFTER: output clock after calibration.
* - BPR_RTC_OUTPUT_ALARM_TOGGLE: output alarm event with toggle mode.
* - BPR_RTC_OUTPUT_SECOND_TOGGLE: output second event with toggle mode.
* @retval none
*/
void bpr_rtc_output_select(bpr_rtc_output_type output_source)
{
/* clear cco,asoe,asos,ccos,togen bits */
BPR->rtccal &= (uint32_t)~0x0F80;
/* set output_source value */
BPR->rtccal |= output_source;
}
/**
* @brief set rtc clock calibration value
* @param calibration_value (0x00~0x7f)
* @retval none
*/
void bpr_rtc_clock_calibration_value_set(uint8_t calibration_value)
{
/* set rtc clock calibration value */
BPR->rtccal_bit.calval= calibration_value;
}
/**
* @brief enable or disable bpr tamper pin
* @param new_state (TRUE or FALSE)
* @retval none
*/
void bpr_tamper_pin_enable(confirm_state new_state)
{
BPR->ctrl_bit.tpen = new_state;
}
/**
* @brief set bpr tamper pin active level
* @param active_level
* this parameter can be one of the following values:
* - BPR_TAMPER_PIN_ACTIVE_HIGH: tamper pin input active level is high.
* - BPR_TAMPER_PIN_ACTIVE_LOW: tamper pin input active level is low.
* @retval none
*/
void bpr_tamper_pin_active_level_set(bpr_tamper_pin_active_level_type active_level)
{
BPR->ctrl_bit.tpp = active_level;
}
/**
* @}
*/
#endif
/**
* @}
*/
/**
* @}
*/
|
ae3f74f10b1634059f5a88ece915c34e746007cc
|
9de0cec678bc4a3bec2b4adabef9f39ff5b4afac
|
/PWGLF/FORWARD/analysis2/corrs/CorrDrawer.C
|
88ee95d8b4870f353f385565448ab921ed8f4d62
|
[] |
permissive
|
alisw/AliPhysics
|
91bf1bd01ab2af656a25ff10b25e618a63667d3e
|
5df28b2b415e78e81273b0d9bf5c1b99feda3348
|
refs/heads/master
| 2023-08-31T20:41:44.927176
| 2023-08-31T14:51:12
| 2023-08-31T14:51:12
| 61,661,378
| 129
| 1,150
|
BSD-3-Clause
| 2023-09-14T18:48:45
| 2016-06-21T19:31:29
|
C++
|
UTF-8
|
C
| false
| false
| 34,218
|
c
|
CorrDrawer.C
|
#ifndef __CINT__
# include "SummaryDrawer.C"
# include "AliFMDCorrAcceptance.h"
# include "AliFMDCorrSecondaryMap.h"
# include "AliFMDCorrELossFit.h"
# include "AliFMDCorrNoiseGain.h"
# include "AliForwardUtil.h"
# include "AliForwardCorrectionManager.h"
# include "AliLog.h"
# include <TString.h>
# include <TError.h>
#else
class SummaryDrawer;
class TObject;
// class TAxis;
class AliFMDCorrAcceptance;
class AliFMDCorrSecondaryMap;
class AliFMDCorrELossFit;
class AliFMDCorrNoiseGain;
#include <TString.h>
#endif
class CorrDrawer : public SummaryDrawer
{
public:
TString fELossExtra;
UShort_t fMinQuality;
/**
* Constructor
*/
CorrDrawer()
{
fELossExtra = ""; // forward_eloss.root";
fMinQuality = AliFMDCorrELossFit::kDefaultQuality;
}
/**
* Destructor. Closes the PDF
*/
~CorrDrawer()
{
CloseCanvas();
}
/**
* Create output file name
*
* @param out Output file name on return
* @param prefix Prefix of the file name
*/
static void MakeFileName(TString& out,
const TString& prefix)
{
out = TString::Format("forward_%s.pdf", prefix.Data());
}
/**
* Run the correction drawer, fetching information from extra file
*
* @param what What to draw
* @param extra Extra file
* @param options Options
* @param local Local DB
*/
void Run(const Char_t* what,
const Char_t* extra,
Option_t* options="",
const Char_t* local="")
{
Run(AliForwardCorrectionManager::ParseFields(what),
extra, options, local);
}
/**
* Run the correction drawer, fetching information from extra file
*
* @param what What to draw
* @param extra Extra file
* @param options Options
* @param local Local DB
*/
void Run(UShort_t what,
const Char_t* extra,
Option_t* options="",
const Char_t* local="")
{
fELossExtra = extra;
ULong_t runNo = 0;
UShort_t sys = 0;
UShort_t sNN = 0;
Short_t fld = 0;
Bool_t mc = false;
Bool_t sat = false;
if (!GetInformation(runNo, sys, sNN, fld, mc, sat)) return;
Run(what, runNo, sys, sNN, fld, mc, sat, options, local);
}
/**
* Draw corrections using the correction manager to get them
*
* @param what What to draw
* @param runNo Run Number
* @param sys Collision system
* @param sNN Center of mass energy
* @param field L3 Field
* @param mc Simulations or not
* @param sat Satellite interactions or not
* @param options Options
* @param local Local database file
*/
void Run(const Char_t* what,
ULong_t runNo,
const Char_t* sys,
UShort_t sNN,
UShort_t field,
Bool_t mc=false,
Bool_t sat=false,
Option_t* options="",
const char* local="")
{
Run(AliForwardCorrectionManager::ParseFields(what),
runNo, AliForwardUtil::ParseCollisionSystem(sys),
sNN, field, mc, sat, options, local);
}
/**
* Draw corrections using the correction manager to get them
*
* @param what What to draw
* @param runNo Run Number
* @param sys Collision system
* @param sNN Center of mass energy
* @param field L3 Field
* @param mc Simulations or not
* @param sat Satellite interactions or not
* @param options Options
* @param local Local database file
*/
void Run(UShort_t what,
ULong_t runNo,
UShort_t sys,
UShort_t sNN,
UShort_t field,
Bool_t mc=false,
Bool_t sat=false,
Option_t* options="",
const char* local="")
{
AliForwardCorrectionManager& mgr = AliForwardCorrectionManager::Instance();
mgr.SetDebug(true);
// Set local prefix
if (local) mgr.SetPrefix(gSystem->DirName(local));
// Get output file name
TString name;
if (what & AliForwardCorrectionManager::kSecondaryMap)
AppendName(name, AliForwardCorrectionManager::kSecondaryMap);
if (what & AliForwardCorrectionManager::kAcceptance)
AppendName(name, AliForwardCorrectionManager::kAcceptance);
if (what & AliForwardCorrectionManager::kELossFits)
AppendName(name, AliForwardCorrectionManager::kELossFits);
if (what & AliForwardCorrectionManager::kNoiseGain)
AppendName(name, AliForwardCorrectionManager::kNoiseGain);
if (what & AliForwardCorrectionManager::kVertexBias)
Warning("CorrDrawer","Vertex bias not implemented yet");
if (what & AliForwardCorrectionManager::kDoubleHit)
Warning("CorrDrawer","Double hit not implemented yet");
if (what & AliForwardCorrectionManager::kMergingEfficiency)
Warning("CorrDrawer","Merging efficiency not implemented yet");
// Filter the ones we can handle
UShort_t flags = what & (AliForwardCorrectionManager::kELossFits|
AliForwardCorrectionManager::kAcceptance|
AliForwardCorrectionManager::kSecondaryMap|
AliForwardCorrectionManager::kNoiseGain);
if (!mgr.Init(runNo, sys, sNN, field, mc, sat, flags, true)) {
Error("CorrDrawer", "Failed to initialize for flags=0x%02x"
"run=%lu, sys=%hu, sNN=%hu, field=%hd, mc=%d, sat=%d",
flags, runNo, sys, sNN, field, mc, sat);
return;
}
TString out;
MakeFileName(out, name); // , runNo, sys, sNN, field, mc, sat);
TString opts(options);
opts.ToUpper();
Bool_t landscape = opts.Contains("LANDSCAPE");
Bool_t few = opts.Contains("FEW");
Bool_t details = !opts.Contains("SINGLE");
if (opts.Contains("PORTRAIT")) landscape = false;
CreateCanvas(out, landscape);
fBody->cd();
if (details) {
Double_t y = .8;
DrawParameter(y, "Run #", Form("%lu", runNo));
DrawParameter(y, "System", AliForwardUtil::CollisionSystemString(sys));
DrawParameter(y, "#sqrt{s_{NN}}",
AliForwardUtil::CenterOfMassEnergyString(sNN));
DrawParameter(y, "L3 field", AliForwardUtil::MagneticFieldString(field));
DrawParameter(y, "Simulation", Form("%s", mc ? "yes" : "no"));
DrawParameter(y, "Satellite", Form("%s", sat ? "yes" : "no"));
PrintCanvas("Title");
}
if (what & AliForwardCorrectionManager::kSecondaryMap)
DrawIt(mgr.GetSecondaryMap(), details);
if (what & AliForwardCorrectionManager::kAcceptance)
DrawIt(mgr.GetAcceptance(), details);
if (what & AliForwardCorrectionManager::kELossFits)
DrawIt(mgr.GetELossFit(), details, few);
if (what & AliForwardCorrectionManager::kNoiseGain)
DrawIt(mgr.GetNoiseGain(), details);
// Done
CloseCanvas();
}
/**
* Fall-back method
*
* @param o Object to draw
*/
virtual void Draw(const TObject* o)
{
if (!o) return;
Warning("CorrDrawer", "Don't know how to draw a %s object",
o->ClassName());
}
/**
* Draw a single plot of the mean acceptance correction
*
* @param acc Acceptance correction
*/
virtual void Draw(const AliFMDCorrAcceptance* acc) { Summarize(acc, false); }
/**
* Draw a single plot of the mean secondary correction
*
* @param sec Secondary correction
*/
virtual void Draw(const AliFMDCorrSecondaryMap* sec) { Summarize(sec, false);}
/**
* Draw a single plot summarizing the energy loss fits
*
* @param fits Energy loss fits
*/
virtual void Draw(const AliFMDCorrELossFit* fits) { Summarize(fits, false); }
/**
* A generalized entry to the summarization functions
*
* @param what What to show - only one field
* @param runNo Run number
* @param sys System
* @param sNN Center of mass energy in GeV
* @param field L3 magnetic field
* @param mc Simulation flag
* @param sat Satellite interaction flag
* @param options Options
* @param local Local storage
*
* @deprecated See Run instead
*/
virtual void Summarize(const TString& what,
ULong_t runNo,
const Char_t* sys,
UShort_t sNN,
Short_t field,
Bool_t mc=false,
Bool_t sat=false,
Option_t* options="",
const char* local="")
{
Summarize(AliForwardCorrectionManager::ParseFields(what),
runNo, AliForwardUtil::ParseCollisionSystem(sys),
sNN, field, mc, sat, options, local);
}
/**
* A generalized entry to the summarization functions
*
* @param what What to show - only one field
* @param runNo Run number
* @param sys System
* @param sNN Center of mass energy in GeV
* @param field L3 magnetic field
* @param mc Simulation flag
* @param sat Satellite interaction flag
* @param options Options
* @param local Local storage
*
* @deprecated See Run instead
*/
virtual void Summarize(UShort_t what,
ULong_t runNo,
UShort_t sys,
UShort_t sNN,
Short_t field,
Bool_t mc=false,
Bool_t sat=false,
Option_t* options="",
const char* local="")
{
Run(what, runNo, sys, sNN, field, mc, sat, options, local);
}
/**
* Fall-back method
*
* @param o Object to draw
* @param pdf Not used
*/
virtual void Summarize(const TObject* o, Bool_t pdf=true)
{
if (!o) return;
Warning("CorrDrawer", "Don't know how to draw a %s object (PDF: %s)",
o->ClassName(), pdf ? "yes" : "no");
}
/**
* Draw a single summary plot or multiple plots of the acceptance
* correction. A new Canvas is created for this.
*
* @param acc Acceptance correction
* @param pdf If true, do multiple plots. Otherwise a single summary plot
*/
virtual void Summarize(const AliFMDCorrAcceptance* acc, Bool_t pdf=true)
{
CreateCanvas(CanvasName("acceptance.pdf"), false, pdf);
DrawIt(acc, pdf);
if (pdf) CloseCanvas();
}
/**
* Draw a single summary plot multiple plots of the secondary
* correction. A new canvas is created for this.
*
* @param sec Secondary correction
* @param pdf If true, do multiple plots. Otherwise a single summary plot
*/
virtual void Summarize(const AliFMDCorrSecondaryMap* sec, Bool_t pdf=true)
{
CreateCanvas(CanvasName("secondarymap.pdf"), false, pdf);
DrawIt(sec, pdf);
if (pdf) CloseCanvas();
}
/**
* Draw a single summary plot multiple plots of the energy loss
* fits. A new canvas is created for this.
*
* @param corr Energy loss fits
* @param pdf If true, do multiple plots. Otherwise a single summary plot
*/
virtual void Summarize(const AliFMDCorrNoiseGain* corr, Bool_t pdf=true)
{
CreateCanvas(CanvasName("noisegain.pdf"), true, pdf);
DrawIt(corr, pdf);
if (pdf) CloseCanvas();
}
/**
* Draw a single summary plot multiple plots of the energy loss
* fits. A new canvas is created for this.
*
* @param fits Energy loss fits
* @param pdf If true, do multiple plots. Otherwise a single summary plot
*/
virtual void Summarize(const AliFMDCorrELossFit* fits, Bool_t pdf=true)
{
CreateCanvas(CanvasName("elossfits.pdf"), true, pdf);
DrawIt(fits, pdf);
if (pdf) CloseCanvas();
}
/**
* Draw a single summary plot/multiple plots of the correction.
* A new canvas is created for this.
*
* @param what What to plot
* @param output Output of correction pass (must exist)
* @param local Local storage of correction
* @param options Various options
*
* @deprecated Use Run instead
*/
static void Summarize(const TString& what = "",
Bool_t /*mc*/ = false,
const TString& output = "",
const TString& local = "fmd_corrections.root",
Option_t* options= "")
{
CorrDrawer* drawer = new CorrDrawer;
drawer->Run(AliForwardCorrectionManager::ParseFields(what),
output, local, options);
}
/**
* Draw a single summary plot/multiple plots of the correction.
* A new canvas is created for this.
*
* @param what What to plot
* @param output Output of correction pass (must exist)
* @param local Local storage of correction
* @param options Various options
*
* @deprecated Use Run instead
*/
static void Summarize(UShort_t what,
Bool_t /*mc*/ = false,
const TString& output = "",
const TString& local = "fmd_corrections.root",
Option_t* options= "")
{
CorrDrawer* drawer = new CorrDrawer;
drawer->Run(what, output, options, local);
}
protected:
/**
* Append a name to output prefix
*
* @param what What to append to
* @param which Which string to append
*/
void AppendName(TString& what, UShort_t which)
{
if (!what.IsNull()) what.Append("_");
switch (which) {
case AliForwardCorrectionManager::kSecondaryMap:
what.Append("secondary"); break;
case AliForwardCorrectionManager::kAcceptance:
what.Append("acceptance"); break;
case AliForwardCorrectionManager::kELossFits:
what.Append("elossfits"); break;
case AliForwardCorrectionManager::kNoiseGain:
what.Append("noisegain"); break;
default:
what.Append("unknown"); break;
}
}
/**
* Get information from auxillary file
*
* @param runNo On return, the run number
* @param sys On return, the collision system
* @param sNN On return, the collision energy
* @param fld On return, the L3 magnetic field
* @param mc On return, true for MC input
* @param sat On return, true for satellite input enabled
*
* @return true on success, false otherwise
*/
virtual Bool_t GetInformation(ULong_t& runNo,
UShort_t& sys,
UShort_t& sNN,
Short_t& fld,
Bool_t& mc,
Bool_t& sat)
{
TFile* fout = TFile::Open(fELossExtra, "READ");
if (!fout) {
Warning("SummarizeELoss", "Correction task output \"%s\" not found",
fELossExtra.Data());
return false;
}
Bool_t ret = false;
try {
TCollection* forward = GetCollection(fout, "ForwardELossSums");
if (!forward) {
forward = GetCollection(fout, "forwardQAResults");
if (!forward) throw false;
}
TCollection* eventInsp = GetCollection(forward, "fmdEventInspector");
if (!eventInsp) throw false;
if (!GetParameter(eventInsp, "sys", sys)) throw false;
if (!GetParameter(eventInsp, "sNN", sNN)) throw false;
if (!GetParameter(eventInsp, "field", fld)) throw false;
if (!GetParameter(eventInsp, "satellite", sat)) throw false;
if (!GetParameter(eventInsp, "runNo", runNo)) throw false;
if (!GetParameter(eventInsp, "mc", mc)) throw false;
ret = true;
}
catch (bool e) {
ret = e;
}
if (fout) fout->Close();
return ret;
}
/**
* Get the canvas name. If the auxillary file has been set, use
* that as the base of the canvas name. Otherwise use @a def.
*
* @param def Default value
*
* @return Canvas name
*/
virtual TString CanvasName(const char* def)
{
TString canName(def);
if (!fELossExtra.IsNull()) {
canName = gSystem->BaseName(fELossExtra.Data());
canName.ReplaceAll(".root", ".pdf");
}
return canName;
}
/**
* Fall-back method
*
* @param o Object to summarize
*/
virtual void DrawIt(const TObject* o)
{
if (!o) return;
Warning("CorrDrawer", "Don't know how to summarize a %s object",
o->ClassName());
}
/**
* Draw the acceptance correction
*
* @param corr Correction
* @param details If true, make a multipage PDF, otherwise plot the mean.
*/
virtual void DrawIt(const AliFMDCorrAcceptance* corr, Bool_t details=true)
{
if (!corr) {
Warning("CorrDrawer","No acceptance available");
return;
}
if (!fCanvas) {
Warning("CorrDrawer", "No canvas");
return;
}
// --- Get vertex axis ---------------------------------------------
const TAxis& vtxAxis = corr->GetVertexAxis();
Int_t nVtx = vtxAxis.GetNbins();
// --- Create stacks for summaries ---------------------------------
TObjArray* stacks = CreateVtxStacks(vtxAxis);
TObjArray* stacks2 = (corr->HasOverflow() && details
? CreateVtxStacks(vtxAxis) : 0);
//__________________________________________________________________
// Create a title page
if (details) {
fBody->cd();
TLatex* ll = new TLatex(.5,.8, fCanvas->GetTitle());
ll->SetTextAlign(22);
ll->SetTextSize(0.03);
ll->SetNDC();
ll->Draw();
TLatex* l = new TLatex(.5,.8, "");
l->SetNDC();
l->SetTextSize(0.03);
l->SetTextFont(132);
l->SetTextAlign(12);
l->DrawLatex(0.2, 0.70, "Acceptance due to dead channels");
l->SetTextAlign(22);
l->DrawLatex(0.5, 0.55, "c_{v,r}(#eta,#phi) = #frac{"
"#sum active strips #in (#eta,#phi)}{"
"#sum strips #in (#eta,#phi)}");
PrintCanvas("Acceptance");
}
// --- Loop over vertex ------------------------------------------
for (UShort_t v=1; v <= nVtx; v++) {
Double_t vzMin = vtxAxis.GetBinLowEdge(v);
Double_t vzMax = vtxAxis.GetBinUpEdge(v);
if (details) DivideForRings(true, true);
// --- Loop over detectors -------------------------------------
for (UShort_t d = 1; d <= 3; d++) {
UShort_t nQ = (d == 1 ? 1 : 2);
for (UShort_t q = 0; q < nQ; q++) {
Char_t r = (q == 0 ? 'I' : 'O');
TH2* h2 = corr->GetCorrection(d, r, v);
if (!h2) {
Warning("DrawCorrAcc", "No correction for FMD%d%c, v=%d", d, r, v);
corr->ls();
continue;
}
if (details) DrawInRingPad(d, r, h2, "colz");
Int_t nY = h2->GetNbinsY();
TH1* hh = h2->ProjectionX(Form("FMD%d%c", d, r), 1, nY);
hh->Scale(1. / nY);
hh->SetDirectory(0);
hh->SetMarkerColor(AliForwardUtil::RingColor(d, r));
hh->SetLineColor(AliForwardUtil::RingColor(d, r));
hh->SetFillColor(AliForwardUtil::RingColor(d, r));
hh->SetFillStyle(3001);
THStack* stack = static_cast<THStack*>(stacks->At(v-1));
if (!stack) {
Error("", "No stack at v=%d", v-1);
continue;
}
stack->Add(hh);
if (!stacks2) {
Warning("", "No phi acceptance defined");
continue;
}
stack = static_cast<THStack*>(stacks2->At(v-1));
if (!stack) {
Error("", "No stack at v=%d", v-1);
continue;
}
TH1* hp = corr->GetPhiAcceptance(d, r, v);
if (!hp) {
Error("", "No phi acceptance at v=%d", v-1);
continue;
}
hp->SetDirectory(0);
hp->SetMarkerColor(AliForwardUtil::RingColor(d, r));
hp->SetLineColor(AliForwardUtil::RingColor(d, r));
hp->SetFillColor(AliForwardUtil::RingColor(d, r));
hp->SetFillStyle(3001);
// Info("", "Adding phi acceptance plot %d", Int_t(hp->GetEntries()));
stack->Add(hp);
}
}
if (details)
PrintCanvas(Form("%+5.1fcm<IP_{z}<%+5.1fcm", vzMin, vzMax));
}
if (DrawVtxStacks(stacks2, 1.2)) {
PrintCanvas("#phi acceptance");
}
if (DrawVtxStacks(stacks, 1.2)) {
PrintCanvas("#LTacceptance#GT");
}
}
/**
* Draw the secondary correction
*
* @param corr Correction
* @param details If true, make a multipage PDF, otherwise plot the mean.
*/
virtual void DrawIt(const AliFMDCorrSecondaryMap* corr, bool details)
{
if (!corr) {
Warning("CorrDrawer","No secondary map available");
return;
}
if (!fCanvas) {
Warning("CorrDrawer", "No canvas");
return;
}
const TAxis& vtxAxis = corr->GetVertexAxis();
Int_t nVtx = vtxAxis.GetNbins();
TObjArray* stacks = CreateVtxStacks(vtxAxis);
//__________________________________________________________________
// Create a title page
if (details) {
fBody->cd();
TLatex* ll = new TLatex(.5,.8, fCanvas->GetTitle());
ll->SetTextAlign(22);
ll->SetTextSize(0.03);
ll->SetNDC();
ll->Draw();
TLatex* l = new TLatex(.5,.8, "");
l->SetNDC();
l->SetTextSize(0.03);
l->SetTextFont(132);
l->SetTextAlign(12);
l->DrawLatex(0.2, 0.70, "Secondary map");
l->SetTextAlign(22);
l->DrawLatex(0.5, 0.60, "c_{v,r}(#eta,#phi)=#frac{"
"#sum N_{ch,primary,i}(#eta,#phi)}{"
"#sum N_{ch,FMD,i}(#eta,#phi)}");
l->SetTextAlign(12);
l->DrawLatex(0.2, 0.50, "N: Number of events");
l->DrawLatex(0.2, 0.45, "N_{ch,primary,i}(#eta,#phi): Number of charged, "
"primary particles in (#eta,#phi) bin");
l->DrawLatex(0.2, 0.40, "N_{ch,primary,i}(#eta,#phi): Number of charged, "
"particles that hit the FMD in (#eta,#phi) bin");
l->DrawLatex(0.2, 0.35, "All quantities determined in MC");
PrintCanvas("Secondary maps");
}
// --- Loop over vertex ------------------------------------------
for (UShort_t v=1; v <= nVtx; v++) {
Double_t vzMin = vtxAxis.GetBinLowEdge(v);
Double_t vzMax = vtxAxis.GetBinUpEdge(v);
if (details) DivideForRings(true, true);
// --- Loop over detectors -------------------------------------
for (UShort_t d = 1; d <= 3; d++) {
UShort_t nQ = (d == 1 ? 1 : 2);
for (UShort_t q = 0; q < nQ; q++) {
Char_t r = (q == 0 ? 'I' : 'O');
TH2* h2 = corr->GetCorrection(d, r, v);
if (!h2) {
Warning("DrawCorrSec", "No correction for FMD%d%c, v=%d", d, r, v);
continue;
}
if (details) DrawInRingPad(d, r, h2, "colz");
Int_t nY = h2->GetNbinsY();
TH1* hh = h2->ProjectionX(Form("FMD%d%c", d, r), 1, nY);
hh->Scale(1. / nY);
hh->SetDirectory(0);
hh->SetMarkerColor(AliForwardUtil::RingColor(d, r));
hh->SetLineColor(AliForwardUtil::RingColor(d, r));
hh->SetFillColor(AliForwardUtil::RingColor(d, r));
hh->SetFillStyle(3001);
THStack* stack = static_cast<THStack*>(stacks->At(v-1));
if (!stack) {
Error("", "No stack at v=%d", v-1);
continue;
}
stack->Add(hh);
}
}
if (details)
PrintCanvas(Form("%+5.1fcm<IP_{z}<%+5.1fcm", vzMin, vzMax));
}
if (DrawVtxStacks(stacks, 3.5)) {
PrintCanvas("#LTsecondary map#GT");
}
}
virtual void DrawIt(const AliFMDCorrNoiseGain* corr, bool /*details*/)
{
if (!corr) {
Warning("CorrDrawer","No noise-gain correction available");
return;
}
if (!fCanvas) {
Warning("CorrDrawer", "No canvas");
return;
}
DivideForRings(false,false);
for (UShort_t d = 1; d <= 3; d++) {
UShort_t nQ = d == 1 ? 1 : 2;
for (UShort_t q = 0; q < nQ; q++) {
Char_t r = q == 0 ? 'I' : 'O';
UShort_t nS = q == 0 ? 20 : 40;
UShort_t nT = q == 0 ? 512 : 256;
TH2* h = new TH2D(Form("fmd%d%c", d, r),
Form("FMD%d%c", d, r),
nT, -.5, nT-.5, nS, -.5, nS-.5);
h->SetDirectory(0);
h->SetXTitle("Strip");
h->SetYTitle("Sector");
for (UShort_t s = 0; s < nS; s++) {
for (UShort_t t = 0; t < nT; t++) {
Float_t c = corr->Get(d,r,s,t);
h->Fill(t,s,c);
}
}
h->GetZaxis()->SetRangeUser(0,0.05);
DrawInRingPad(d,r,h,"COLZ");
}
}
PrintCanvas("Noise correction");
}
/**
* Draw the energy loss fits correction
*
* @param corr Correction
* @param details If true, make a multipage PDF,
* otherwise plot the parameters.
* @param few Only a few
*/
virtual void DrawIt(const AliFMDCorrELossFit* corr, bool details,
bool few=true)
{
if (!corr) {
Warning("CorrDrawer","No energy loss fits available");
return;
}
if (!fCanvas) {
Warning("CorrDrawer", "No canvas");
return;
}
AliFMDCorrELossFit* fits = const_cast<AliFMDCorrELossFit*>(corr);
fits->CacheBins(8);
fits->Print("C");
TList* fitter = 0;
if (details) {
TFile* hists = 0;
TDirectory* savDir = gDirectory;
if (!gSystem->AccessPathName(fELossExtra.Data())) {
hists = TFile::Open(fELossExtra, "READ");
Info("", "Opened %s -> %p", fELossExtra.Data(), hists);
}
else
Warning("", "Couldn't open %s", fELossExtra.Data());
if (hists) {
TList* fr = static_cast<TList*>(hists->Get("ForwardELossResults"));
if (!fr)
fr = static_cast<TList*>(hists->Get("forwardQAResults"));
// Info("", "Got forward results -> %p", fr);
if (fr) {
fitter = static_cast<TList*>(fr->FindObject("fmdEnergyFitter"));
// Info("", "Got fitter -> %p", fitter);
// fr->ls();
DrawEventInspector(fr);
}
hists->Close();
savDir->cd();
}
fBody->cd();
TLatex* ll = new TLatex(.5,.9, "ESD #rightarrow #Delta-fits"
/* fCanvas->GetTitle() */);
ll->SetTextAlign(22);
ll->SetTextSize(0.05);
ll->SetNDC();
ll->Draw();
const Double_t fontSize = 0.03;
#define DL(X,Y,T) do { l->DrawLatex(X,Y,T); Y -= fontSize; } while (false)
TLatex* l = new TLatex(.5,.8, "");
l->SetNDC();
l->SetTextSize(fontSize);
l->SetTextFont(132);
l->SetTextAlign(12);
Double_t y = 0.80;
Double_t x = 0.20;
Double_t z = 0.30;
DL(x,y,"1^{st} page is a summary of fit parameters");
DL(x,y,"2^{nd} page is a summary of relative errors");
DL(x,y,"Subsequent pages shows the fitted functions");
y -= 0.01;
DL(z,y,"Black line is the full fitted function");
DL(z,y,"Coloured lines are the individual N-mip comp.");
DL(x,y,"Each component has the form");
y -= 0.02;
DL(z,y,"f_{n}(x; #Delta, #xi, #sigma') = "
"#int_{-#infty}^{+#infty}dx' "
"landau(x'; #Delta, #xi)gaus(x'; x, #sigma')");
y -= 0.02;
DL(x,y,"The full function is given by");
y -= 0.02;
DL(z,y,"f_{N}(x; #Delta, #xi, #sigma', #bf{a}) = "
"C #sum_{i=1}^{N} a_{i} "
"f_{i}(x; #Delta_{i}, #xi_{i}, #sigma_{i}')");
y -= 0.03;
DL(z,y,"#Delta_{i} = i (#Delta_{1} + #xi_{1} log(i)) +#delta_{i}");
DL(z,y,"#xi_{i} = i #xi_{1}");
DL(z,y,"#sigma_{i} = #sqrt{i} #sigma_{1}");
DL(z,y,"#sigma_{n} #dot{=} 0");
DL(z,y,"#sigma_{i}'^{2} = #sigma^{2}_{n} + #sigma_{i}^{2}");
DL(z,y,"#delta_{i} = c#sigmau/(1+1/i)^{pu#sqrt{u}}");
DL(z,y,"u = #sigma/#xi");
DL(z,y,"a_{1} #dot{=} 1");
y -= 0.02;
DL(z,y,Form("Least quality: %d", fMinQuality));
y -= 0.02;
if (fitter) {
TObject* refit = fitter->FindObject("refitted");
if (refit) DL(z,y, "Refitted distributions");//.10
}
PrintCanvas("Energy loss fits");
}
if (details && fitter) {
// Draw parameter from the fitter
fBody->cd();
Double_t y = 0.90;
Double_t s = fParName->GetTextSize();
Double_t t = fParVal->GetTextSize();
fParName->SetTextSize(0.04);
fParVal->SetTextSize(0.04);
DrawTParameter<double>(y, fitter, "lowCut");
DrawTParameter<int> (y, fitter, "nParticles");
DrawTParameter<int> (y, fitter, "minEntries");
DrawTParameter<int> (y, fitter, "subtractBins");
DrawTParameter<bool> (y, fitter, "doFits");
DrawTParameter<double>(y, fitter, "maxE");
DrawTParameter<int> (y, fitter, "nEbins");
DrawTParameter<bool> (y, fitter, "increasingBins");
DrawTParameter<double>(y, fitter, "maxRelPerError");
DrawTParameter<double>(y, fitter, "maxChi2PerNDF");
DrawTParameter<double>(y, fitter, "minWeight");
DrawTParameter<double>(y, fitter, "regCut");
DrawParameter(y,"Use #delta#Delta(#sigma/#xi)",
Form("%s",
fits->TestBit(AliFMDCorrELossFit::kHasShift)
? "yes" : "no"));
PrintCanvas("Fitter settings");
fParName->SetTextSize(s);
fParVal->SetTextSize(t);
}
fBody->cd();
fits->Draw("error good");
PrintCanvas("Fit overview");
if (!details) return;
//__________________________________________________________________
// Draw relative parameter errors
fBody->cd();
fits->Draw("relative good");
PrintCanvas("Relative parameter errors");
//__________________________________________________________________
// Draw all fits individually
for (UShort_t d=1; d<=3; d++) {
UShort_t nQ = (d == 1 ? 1 : 2);
for (UShort_t q = 0; q < nQ; q++) {
Char_t r = (q == 0 ? 'I' : 'O');
TList* dists = 0;
TList* resis = 0;
if (fitter) {
// Info("", "Fitter: %s", fitter->GetName());
TList* dl =
static_cast<TList*>(fitter->FindObject(Form("FMD%d%c",d,r)));
// Info("", "Got detector list -> %p", dl);
if (dl) {
// Info("", "Detector list: %s", dl->GetName());
dists = static_cast<TList*>(dl->FindObject("elossDists"));
// Info("", "Got distributions -> %p", dists);
resis = static_cast<TList*>(dl->FindObject("elossResiduals"));
// Info("", "Got residuals -> %p", resis);
}
}
printf("FMD%d%c ", d, r);
ClearCanvas();
TObjArray* ra = fits->GetRingArray(d, r);
if (!ra) continue;
DrawELossFits(d, r, ra, dists, resis, few);
}
}
}
/**
* CINT does too much when optimizing on a loop, so we take this out
* to force CINT to not optimize the third nested loop.
*
* @param d Detector
* @param r Ring
* @param ra Ring array
* @param dists Distributions (optional)
* @param resis Residuals (optional)
* @param few A few
*/
void DrawELossFits(UShort_t d, Char_t r, TObjArray* ra,
TList* dists, TList* resis, bool few)
{
Int_t nRow = 3;
Int_t nCol = (few ? 1 : 2);
Int_t nPad = nRow * nCol;
AliFMDCorrELossFit::ELossFit* fit = 0;
TIter next(ra);
Int_t i = 0;
Int_t j = 0;
DividedPad divided(fBody, fLandscape, nCol, nRow);
while ((fit = static_cast<AliFMDCorrELossFit::ELossFit*>(next()))) {
j = i % nPad;
Bool_t last = j == nPad-1;
if (j == 0) divided.Divide(true, true);
Bool_t same = false;
TVirtualPad* drawPad = divided.GetPad(j); // fBody->GetPad(j+1);
Int_t subPad = 0;
// fBody->ls();
// Info("", "Now in sub-pad %d of %d: %p", j, nPad, drawPad);
// Info("", "Pad %s", drawPad->GetName());
if (dists) {
// Info("", "Distributions: %s", dists->GetName());
TString hName(Form("FMD%d%c_etabin%03d", d,r,fit->GetBin()));
TH1* dist = static_cast<TH1*>(dists->FindObject(hName));
TH1* resi = 0;
if (resis) resi = static_cast<TH1*>(resis->FindObject(hName));
// Info("", "Got histogram -> %p", dist);
if (resi) {
Bool_t err = resi->GetUniqueID() <= 1;
drawPad->SetGridx();
if (err) {
resi->SetYTitle("#chi^{2}_{bin}=(h-f)^{2}/#delta^{2}h");
for (Int_t k=1; k<=resi->GetNbinsX(); k++) {
Double_t c = resi->GetBinContent(k);
Double_t e = resi->GetBinError(k);
if (e <= 0) continue;
c *= c;
c /= (e*e);
resi->SetBinContent(k, c);
resi->SetBinError(k, 0);
}
}
drawPad->Divide(1,2,0,0);
DrawInPad(drawPad, 2, resi, "HIST", kGridx);
subPad = 1;
Double_t red = fit->GetNu() > 0 ? fit->GetChi2() / fit->GetNu() : 0;
if (red > 0) {
drawPad->cd(2);
TLine* l = new TLine(resi->GetXaxis()->GetXmin(), red,
resi->GetXaxis()->GetXmax(), red);
l->SetLineWidth(2);
l->SetLineStyle(2);
l->Draw();
TLatex* cltx = new TLatex(0.5, 0.5,
Form("#chi^{2}/#nu=%6.2f", red));
cltx->SetNDC();
cltx->SetTextAlign(22);
cltx->SetTextFont(42);
cltx->SetTextSize(0.07);
cltx->Draw();
cltx->DrawLatex(0.5,0.4,Form("%g", dist->GetEntries()));
}
}
if (dist) {
// Info("", "Histogram: %s", dist->GetName());
dist->SetFillStyle(3001);
dist->SetMarkerStyle(0);
DrawInPad(drawPad, subPad, dist, "HIST E", (subPad * kGridx) + kLogy);
same = true;
}
}
// if (same)
DrawInPad(drawPad, subPad, fit,
Form("comp good values legend peak %s", (same ? "same" : "")),
kLogy);
if (fit->GetQuality() < fMinQuality) {
TLatex* ltx = new TLatex(.2, .2, "NOT USED");
ltx->SetNDC();
ltx->SetTextFont(62);
ltx->SetTextColor(kRed+1);
ltx->SetTextAngle(30);
ltx->SetTextSize(0.2);
DrawInPad(fBody, j+1, ltx, "", 0);
// ltx->Draw();
}
// else
// DrawInPad(fBody, j+1, fit, "comp good values legend", kLogy);
printf(".");
if (last)
PrintCanvas(Form("FMD%d%c page %d", d, r, (i/nPad)+1));
i++;
}
j = i % nPad;
if (j != 0)
PrintCanvas(Form("FMD%d%c page %d", d, r, (i/nPad)+1));
printf(" done\n");
}
/**
* Create an array of per-vertex bin stacks
*
* @param vtxAxis Vertex axis
*
* @return Array of stacks
*/
TObjArray* CreateVtxStacks(const TAxis& vtxAxis)
{
// --- Create stacks for summaries ---------------------------------
Int_t nVtx = vtxAxis.GetNbins();
TObjArray* stacks = new TObjArray(nVtx);
for (UShort_t v = 1; v <= nVtx; v++) {
THStack* stack = new THStack(Form("vtx%02d", v),
Form("%+5.1f<v_{z}<%+5.1f",
vtxAxis.GetBinLowEdge(v),
vtxAxis.GetBinUpEdge(v)));
stacks->AddAt(stack, v-1);
}
return stacks;
}
/**
* Draw the vertex stacks in the canvas
*
* @param stacks Stacks to draw
* @param max Possible maximum of the stacks
*
* @return true on success
*/
Bool_t DrawVtxStacks(TObjArray* stacks, Double_t max=-1)
{
if (!stacks) return false;
// --- Make summary page -------------------------------------------
Int_t nVtx = stacks->GetEntries();
fBody->Divide(3, (nVtx+2)/3, 0, 0);
Int_t ipad = 0;
for (UShort_t v = 1; v <= nVtx; v++) {
ipad++;
if (nVtx == 10 && (ipad == 1 || ipad == 12)) ipad++;
THStack* stack = static_cast<THStack*>(stacks->At(v-1));
if (!stack) {
Error("", "No stack at v=%d", v-1);
continue;
}
TVirtualPad* pad = fBody->cd(ipad);
if (!pad) {
Error("", "No pad at %d", ipad);
continue;
}
pad->SetFillColor(kWhite);
if (max > 0) stack->SetMaximum(max);
stack->Draw("nostack hist");
}
return true;
}
};
//
// EOF
//
|
f1e32a67f9c98cc4e9feb04f8f8f99400f3f3ee1
|
23b65138d1103544d0670ee2098996a3c90fc88d
|
/hardwares/keyboard/45RStandard/default/qmk_firmware/quantum/quantum.h
|
e6adf974aba58aa006a876c58d00f2d19d6099c7
|
[
"Apache-2.0"
] |
permissive
|
suliveevil/Capslock
|
c0fbfe84ad09df6c61e87f755ec9011b9efac628
|
1d28b8d9de5700b4b73bbda26686a6fc6f1172b8
|
refs/heads/master
| 2022-11-13T01:22:33.002440
| 2022-10-27T19:46:35
| 2022-10-27T19:46:35
| 162,542,491
| 159
| 31
| null | 2021-12-15T00:04:50
| 2018-12-20T07:26:11
|
C
|
UTF-8
|
C
| false
| false
| 2,617
|
h
|
quantum.h
|
#ifndef QUANTUM_H
#define QUANTUM_H
#if defined(__AVR__)
#include <avr/pgmspace.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#endif
#include "wait.h"
#include "matrix.h"
#include "keymap.h"
#ifdef BACKLIGHT_ENABLE
#include "backlight.h"
#endif
#ifdef RGBLIGHT_ENABLE
#include "rgblight.h"
#endif
#include "action_layer.h"
#include "eeconfig.h"
#include <stddef.h>
#include "bootloader.h"
#include "timer.h"
#include "config_common.h"
#include "led.h"
#include "action_util.h"
#include <stdlib.h>
#include "print.h"
extern uint32_t default_layer_state;
#ifndef NO_ACTION_LAYER
extern uint32_t layer_state;
#endif
#ifdef MIDI_ENABLE
#include <lufa.h>
#include "process_midi.h"
#endif
#ifdef AUDIO_ENABLE
#include "audio.h"
#include "process_music.h"
#endif
#ifndef DISABLE_LEADER
#include "process_leader.h"
#endif
#define DISABLE_CHORDING
#ifndef DISABLE_CHORDING
#include "process_chording.h"
#endif
#ifdef UNICODE_ENABLE
#include "process_unicode.h"
#endif
#include "process_tap_dance.h"
#ifdef PRINTING_ENABLE
#include "process_printer.h"
#endif
#define SEND_STRING(str) send_string(PSTR(str))
void send_string(const char *str);
// For tri-layer
void update_tri_layer(uint8_t layer1, uint8_t layer2, uint8_t layer3);
void tap_random_base64(void);
#define IS_LAYER_ON(layer) (layer_state & (1UL << (layer)))
#define IS_LAYER_OFF(layer) (~layer_state & (1UL << (layer)))
void matrix_init_kb(void);
void matrix_scan_kb(void);
void matrix_init_user(void);
void matrix_scan_user(void);
bool process_action_kb(keyrecord_t *record);
bool process_record_kb(uint16_t keycode, keyrecord_t *record);
bool process_record_user(uint16_t keycode, keyrecord_t *record);
void reset_keyboard(void);
void startup_user(void);
void shutdown_user(void);
void register_code16 (uint16_t code);
void unregister_code16 (uint16_t code);
#ifdef BACKLIGHT_ENABLE
void backlight_init_ports(void);
#ifdef BACKLIGHT_BREATHING
void breathing_enable(void);
void breathing_pulse(void);
void breathing_disable(void);
void breathing_self_disable(void);
void breathing_toggle(void);
bool is_breathing(void);
void breathing_defaults(void);
void breathing_intensity_default(void);
void breathing_speed_default(void);
void breathing_speed_set(uint8_t value);
void breathing_speed_inc(uint8_t value);
void breathing_speed_dec(uint8_t value);
#endif
#endif
void send_dword(uint32_t number);
void send_word(uint16_t number);
void send_byte(uint8_t number);
void send_nibble(uint8_t number);
void led_set_user(uint8_t usb_led);
void led_set_kb(uint8_t usb_led);
void api_send_unicode(uint32_t unicode);
#endif
|
7d382d67b1b885edbdc03a5c3ad57bfe91ff1f04
|
7eaf54a78c9e2117247cb2ab6d3a0c20719ba700
|
/SOFTWARE/A64-TERES/u-boot_new/board/tqc/tqm8xx/tqm8xx.c
|
9ce2a5739f321b936c884d29f6f7621661fbf4d2
|
[
"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
| 18,827
|
c
|
tqm8xx.c
|
/*
* (C) Copyright 2000-2008
* Wolfgang Denk, DENX Software Engineering, wd@denx.de.
*
* SPDX-License-Identifier: GPL-2.0+
*/
#include <common.h>
#include <hwconfig.h>
#include <mpc8xx.h>
#ifdef CONFIG_PS2MULT
#include <ps2mult.h>
#endif
#if defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_OF_LIBFDT)
#include <libfdt.h>
#endif
extern flash_info_t flash_info[]; /* FLASH chips info */
DECLARE_GLOBAL_DATA_PTR;
static long int dram_size (long int, long int *, long int);
#define _NOT_USED_ 0xFFFFFFFF
/* UPM initialization table for SDRAM: 40, 50, 66 MHz CLKOUT @ CAS latency 2, tWR=2 */
const uint sdram_table[] =
{
/*
* Single Read. (Offset 0 in UPMA RAM)
*/
0x1F0DFC04, 0xEEAFBC04, 0x11AF7C04, 0xEFBAFC00,
0x1FF5FC47, /* last */
/*
* SDRAM Initialization (offset 5 in UPMA RAM)
*
* This is no UPM entry point. The following definition uses
* the remaining space to establish an initialization
* sequence, which is executed by a RUN command.
*
*/
0x1FF5FC34, 0xEFEABC34, 0x1FB57C35, /* last */
/*
* Burst Read. (Offset 8 in UPMA RAM)
*/
0x1F0DFC04, 0xEEAFBC04, 0x10AF7C04, 0xF0AFFC00,
0xF0AFFC00, 0xF1AFFC00, 0xEFBAFC00, 0x1FF5FC47, /* last */
_NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
_NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
/*
* Single Write. (Offset 18 in UPMA RAM)
*/
0x1F0DFC04, 0xEEABBC00, 0x11B77C04, 0xEFFAFC44,
0x1FF5FC47, /* last */
_NOT_USED_, _NOT_USED_, _NOT_USED_,
/*
* Burst Write. (Offset 20 in UPMA RAM)
*/
0x1F0DFC04, 0xEEABBC00, 0x10A77C00, 0xF0AFFC00,
0xF0AFFC00, 0xF0AFFC04, 0xE1BAFC44, 0x1FF5FC47, /* last */
_NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
_NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
/*
* Refresh (Offset 30 in UPMA RAM)
*/
0x1FFD7C84, 0xFFFFFC04, 0xFFFFFC04, 0xFFFFFC04,
0xFFFFFC84, 0xFFFFFC07, /* last */
_NOT_USED_, _NOT_USED_,
_NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
/*
* Exception. (Offset 3c in UPMA RAM)
*/
0xFFFFFC07, /* last */
_NOT_USED_, _NOT_USED_, _NOT_USED_,
};
/* ------------------------------------------------------------------------- */
/*
* Check Board Identity:
*
* Test TQ ID string (TQM8xx...)
* If present, check for "L" type (no second DRAM bank),
* otherwise "L" type is assumed as default.
*
* Set board_type to 'L' for "L" type, 'M' for "M" type, 0 else.
*/
int checkboard (void)
{
char buf[64];
int i;
int l = getenv_f("serial#", buf, sizeof(buf));
puts ("Board: ");
if (l < 0 || strncmp(buf, "TQM8", 4)) {
puts ("### No HW ID - assuming TQM8xxL\n");
return (0);
}
if ((buf[6] == 'L')) { /* a TQM8xxL type */
gd->board_type = 'L';
}
if ((buf[6] == 'M')) { /* a TQM8xxM type */
gd->board_type = 'M';
}
if ((buf[6] == 'D')) { /* a TQM885D type */
gd->board_type = 'D';
}
for (i = 0; i < l; ++i) {
if (buf[i] == ' ')
break;
putc (buf[i]);
}
#ifdef CONFIG_VIRTLAB2
puts (" (Virtlab2)");
#endif
putc ('\n');
return (0);
}
/* ------------------------------------------------------------------------- */
phys_size_t initdram (int board_type)
{
volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
volatile memctl8xx_t *memctl = &immap->im_memctl;
long int size8, size9, size10;
long int size_b0 = 0;
long int size_b1 = 0;
upmconfig (UPMA, (uint *) sdram_table,
sizeof (sdram_table) / sizeof (uint));
/*
* Preliminary prescaler for refresh (depends on number of
* banks): This value is selected for four cycles every 62.4 us
* with two SDRAM banks or four cycles every 31.2 us with one
* bank. It will be adjusted after memory sizing.
*/
memctl->memc_mptpr = CONFIG_SYS_MPTPR_2BK_8K;
/*
* The following value is used as an address (i.e. opcode) for
* the LOAD MODE REGISTER COMMAND during SDRAM initialisation. If
* the port size is 32bit the SDRAM does NOT "see" the lower two
* address lines, i.e. mar=0x00000088 -> opcode=0x00000022 for
* MICRON SDRAMs:
* -> 0 00 010 0 010
* | | | | +- Burst Length = 4
* | | | +----- Burst Type = Sequential
* | | +------- CAS Latency = 2
* | +----------- Operating Mode = Standard
* +-------------- Write Burst Mode = Programmed Burst Length
*/
memctl->memc_mar = 0x00000088;
/*
* Map controller banks 2 and 3 to the SDRAM banks 2 and 3 at
* preliminary addresses - these have to be modified after the
* SDRAM size has been determined.
*/
memctl->memc_or2 = CONFIG_SYS_OR2_PRELIM;
memctl->memc_br2 = CONFIG_SYS_BR2_PRELIM;
#ifndef CONFIG_CAN_DRIVER
if ((board_type != 'L') &&
(board_type != 'M') &&
(board_type != 'D') ) { /* only one SDRAM bank on L, M and D modules */
memctl->memc_or3 = CONFIG_SYS_OR3_PRELIM;
memctl->memc_br3 = CONFIG_SYS_BR3_PRELIM;
}
#endif /* CONFIG_CAN_DRIVER */
memctl->memc_mamr = CONFIG_SYS_MAMR_8COL & (~(MAMR_PTAE)); /* no refresh yet */
udelay (200);
/* perform SDRAM initializsation sequence */
memctl->memc_mcr = 0x80004105; /* SDRAM bank 0 */
udelay (1);
memctl->memc_mcr = 0x80004230; /* SDRAM bank 0 - execute twice */
udelay (1);
#ifndef CONFIG_CAN_DRIVER
if ((board_type != 'L') &&
(board_type != 'M') &&
(board_type != 'D') ) { /* only one SDRAM bank on L, M and D modules */
memctl->memc_mcr = 0x80006105; /* SDRAM bank 1 */
udelay (1);
memctl->memc_mcr = 0x80006230; /* SDRAM bank 1 - execute twice */
udelay (1);
}
#endif /* CONFIG_CAN_DRIVER */
memctl->memc_mamr |= MAMR_PTAE; /* enable refresh */
udelay (1000);
/*
* Check Bank 0 Memory Size for re-configuration
*
* try 8 column mode
*/
size8 = dram_size (CONFIG_SYS_MAMR_8COL, SDRAM_BASE2_PRELIM, SDRAM_MAX_SIZE);
debug ("SDRAM Bank 0 in 8 column mode: %ld MB\n", size8 >> 20);
udelay (1000);
/*
* try 9 column mode
*/
size9 = dram_size (CONFIG_SYS_MAMR_9COL, SDRAM_BASE2_PRELIM, SDRAM_MAX_SIZE);
debug ("SDRAM Bank 0 in 9 column mode: %ld MB\n", size9 >> 20);
udelay(1000);
#if defined(CONFIG_SYS_MAMR_10COL)
/*
* try 10 column mode
*/
size10 = dram_size (CONFIG_SYS_MAMR_10COL, SDRAM_BASE2_PRELIM, SDRAM_MAX_SIZE);
debug ("SDRAM Bank 0 in 10 column mode: %ld MB\n", size10 >> 20);
#else
size10 = 0;
#endif /* CONFIG_SYS_MAMR_10COL */
if ((size8 < size10) && (size9 < size10)) {
size_b0 = size10;
} else if ((size8 < size9) && (size10 < size9)) {
size_b0 = size9;
memctl->memc_mamr = CONFIG_SYS_MAMR_9COL;
udelay (500);
} else {
size_b0 = size8;
memctl->memc_mamr = CONFIG_SYS_MAMR_8COL;
udelay (500);
}
debug ("SDRAM Bank 0: %ld MB\n", size_b0 >> 20);
#ifndef CONFIG_CAN_DRIVER
if ((board_type != 'L') &&
(board_type != 'M') &&
(board_type != 'D') ) { /* only one SDRAM bank on L, M and D modules */
/*
* Check Bank 1 Memory Size
* use current column settings
* [9 column SDRAM may also be used in 8 column mode,
* but then only half the real size will be used.]
*/
size_b1 = dram_size (memctl->memc_mamr, (long int *)SDRAM_BASE3_PRELIM,
SDRAM_MAX_SIZE);
debug ("SDRAM Bank 1: %ld MB\n", size_b1 >> 20);
} else {
size_b1 = 0;
}
#endif /* CONFIG_CAN_DRIVER */
udelay (1000);
/*
* Adjust refresh rate depending on SDRAM type, both banks
* For types > 128 MBit leave it at the current (fast) rate
*/
if ((size_b0 < 0x02000000) && (size_b1 < 0x02000000)) {
/* reduce to 15.6 us (62.4 us / quad) */
memctl->memc_mptpr = CONFIG_SYS_MPTPR_2BK_4K;
udelay (1000);
}
/*
* Final mapping: map bigger bank first
*/
if (size_b1 > size_b0) { /* SDRAM Bank 1 is bigger - map first */
memctl->memc_or3 = ((-size_b1) & 0xFFFF0000) | CONFIG_SYS_OR_TIMING_SDRAM;
memctl->memc_br3 = (CONFIG_SYS_SDRAM_BASE & BR_BA_MSK) | BR_MS_UPMA | BR_V;
if (size_b0 > 0) {
/*
* Position Bank 0 immediately above Bank 1
*/
memctl->memc_or2 = ((-size_b0) & 0xFFFF0000) | CONFIG_SYS_OR_TIMING_SDRAM;
memctl->memc_br2 = ((CONFIG_SYS_SDRAM_BASE & BR_BA_MSK) | BR_MS_UPMA | BR_V)
+ size_b1;
} else {
unsigned long reg;
/*
* No bank 0
*
* invalidate bank
*/
memctl->memc_br2 = 0;
/* adjust refresh rate depending on SDRAM type, one bank */
reg = memctl->memc_mptpr;
reg >>= 1; /* reduce to CONFIG_SYS_MPTPR_1BK_8K / _4K */
memctl->memc_mptpr = reg;
}
} else { /* SDRAM Bank 0 is bigger - map first */
memctl->memc_or2 = ((-size_b0) & 0xFFFF0000) | CONFIG_SYS_OR_TIMING_SDRAM;
memctl->memc_br2 =
(CONFIG_SYS_SDRAM_BASE & BR_BA_MSK) | BR_MS_UPMA | BR_V;
if (size_b1 > 0) {
/*
* Position Bank 1 immediately above Bank 0
*/
memctl->memc_or3 =
((-size_b1) & 0xFFFF0000) | CONFIG_SYS_OR_TIMING_SDRAM;
memctl->memc_br3 =
((CONFIG_SYS_SDRAM_BASE & BR_BA_MSK) | BR_MS_UPMA | BR_V)
+ size_b0;
} else {
unsigned long reg;
#ifndef CONFIG_CAN_DRIVER
/*
* No bank 1
*
* invalidate bank
*/
memctl->memc_br3 = 0;
#endif /* CONFIG_CAN_DRIVER */
/* adjust refresh rate depending on SDRAM type, one bank */
reg = memctl->memc_mptpr;
reg >>= 1; /* reduce to CONFIG_SYS_MPTPR_1BK_8K / _4K */
memctl->memc_mptpr = reg;
}
}
udelay (10000);
#ifdef CONFIG_CAN_DRIVER
/* UPM initialization for CAN @ CLKOUT <= 66 MHz */
/* Initialize OR3 / BR3 */
memctl->memc_or3 = CONFIG_SYS_OR3_CAN;
memctl->memc_br3 = CONFIG_SYS_BR3_CAN;
/* Initialize MBMR */
memctl->memc_mbmr = MBMR_GPL_B4DIS; /* GPL_B4 ouput line Disable */
/* Initialize UPMB for CAN: single read */
memctl->memc_mdr = 0xFFFFCC04;
memctl->memc_mcr = 0x0100 | UPMB;
memctl->memc_mdr = 0x0FFFD004;
memctl->memc_mcr = 0x0101 | UPMB;
memctl->memc_mdr = 0x0FFFC000;
memctl->memc_mcr = 0x0102 | UPMB;
memctl->memc_mdr = 0x3FFFC004;
memctl->memc_mcr = 0x0103 | UPMB;
memctl->memc_mdr = 0xFFFFDC07;
memctl->memc_mcr = 0x0104 | UPMB;
/* Initialize UPMB for CAN: single write */
memctl->memc_mdr = 0xFFFCCC04;
memctl->memc_mcr = 0x0118 | UPMB;
memctl->memc_mdr = 0xCFFCDC04;
memctl->memc_mcr = 0x0119 | UPMB;
memctl->memc_mdr = 0x3FFCC000;
memctl->memc_mcr = 0x011A | UPMB;
memctl->memc_mdr = 0xFFFCC004;
memctl->memc_mcr = 0x011B | UPMB;
memctl->memc_mdr = 0xFFFDC405;
memctl->memc_mcr = 0x011C | UPMB;
#endif /* CONFIG_CAN_DRIVER */
#ifdef CONFIG_ISP1362_USB
/* Initialize OR5 / BR5 */
memctl->memc_or5 = CONFIG_SYS_OR5_ISP1362;
memctl->memc_br5 = CONFIG_SYS_BR5_ISP1362;
#endif /* CONFIG_ISP1362_USB */
return (size_b0 + size_b1);
}
/* ------------------------------------------------------------------------- */
/*
* Check memory range for valid RAM. A simple memory test determines
* the actually available RAM size between addresses `base' and
* `base + maxsize'. Some (not all) hardware errors are detected:
* - short between address lines
* - short between data lines
*/
static long int dram_size (long int mamr_value, long int *base, long int maxsize)
{
volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
volatile memctl8xx_t *memctl = &immap->im_memctl;
memctl->memc_mamr = mamr_value;
return (get_ram_size(base, maxsize));
}
/* ------------------------------------------------------------------------- */
#ifdef CONFIG_MISC_INIT_R
extern void load_sernum_ethaddr(void);
int misc_init_r (void)
{
volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
volatile memctl8xx_t *memctl = &immap->im_memctl;
load_sernum_ethaddr();
#ifdef CONFIG_SYS_OR_TIMING_FLASH_AT_50MHZ
int scy, trlx, flash_or_timing, clk_diff;
scy = (CONFIG_SYS_OR_TIMING_FLASH_AT_50MHZ & OR_SCY_MSK) >> 4;
if (CONFIG_SYS_OR_TIMING_FLASH_AT_50MHZ & OR_TRLX) {
trlx = OR_TRLX;
scy *= 2;
} else {
trlx = 0;
}
/*
* We assume that each 10MHz of bus clock require 1-clk SCY
* adjustment.
*/
clk_diff = (gd->bus_clk / 1000000) - 50;
/*
* We need proper rounding here. This is what the "+5" and "-5"
* are here for.
*/
if (clk_diff >= 0)
scy += (clk_diff + 5) / 10;
else
scy += (clk_diff - 5) / 10;
/*
* For bus frequencies above 50MHz, we want to use relaxed timing
* (OR_TRLX).
*/
if (gd->bus_clk >= 50000000)
trlx = OR_TRLX;
else
trlx = 0;
if (trlx)
scy /= 2;
if (scy > 0xf)
scy = 0xf;
if (scy < 1)
scy = 1;
flash_or_timing = (scy << 4) | trlx |
(CONFIG_SYS_OR_TIMING_FLASH_AT_50MHZ & ~(OR_TRLX | OR_SCY_MSK));
memctl->memc_or0 =
flash_or_timing | (-flash_info[0].size & OR_AM_MSK);
#else
memctl->memc_or0 =
CONFIG_SYS_OR_TIMING_FLASH | (-flash_info[0].size & OR_AM_MSK);
#endif
memctl->memc_br0 = (CONFIG_SYS_FLASH_BASE & BR_BA_MSK) | BR_MS_GPCM | BR_V;
debug ("## BR0: 0x%08x OR0: 0x%08x\n",
memctl->memc_br0, memctl->memc_or0);
if (flash_info[1].size) {
#ifdef CONFIG_SYS_OR_TIMING_FLASH_AT_50MHZ
memctl->memc_or1 = flash_or_timing |
(-flash_info[1].size & 0xFFFF8000);
#else
memctl->memc_or1 = CONFIG_SYS_OR_TIMING_FLASH |
(-flash_info[1].size & 0xFFFF8000);
#endif
memctl->memc_br1 =
((CONFIG_SYS_FLASH_BASE +
flash_info[0].
size) & BR_BA_MSK) | BR_MS_GPCM | BR_V;
debug ("## BR1: 0x%08x OR1: 0x%08x\n",
memctl->memc_br1, memctl->memc_or1);
} else {
memctl->memc_br1 = 0; /* invalidate bank */
debug ("## DISABLE BR1: 0x%08x OR1: 0x%08x\n",
memctl->memc_br1, memctl->memc_or1);
}
# ifdef CONFIG_IDE_LED
/* Configure PA15 as output port */
immap->im_ioport.iop_padir |= 0x0001;
immap->im_ioport.iop_paodr |= 0x0001;
immap->im_ioport.iop_papar &= ~0x0001;
immap->im_ioport.iop_padat &= ~0x0001; /* turn it off */
# endif
#ifdef CONFIG_NSCU
/* wake up ethernet module */
immap->im_ioport.iop_pcpar &= ~0x0004; /* GPIO pin */
immap->im_ioport.iop_pcdir |= 0x0004; /* output */
immap->im_ioport.iop_pcso &= ~0x0004; /* for clarity */
immap->im_ioport.iop_pcdat |= 0x0004; /* enable */
#endif /* CONFIG_NSCU */
return (0);
}
#endif /* CONFIG_MISC_INIT_R */
# ifdef CONFIG_IDE_LED
void ide_led (uchar led, uchar status)
{
volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
/* We have one led for both pcmcia slots */
if (status) { /* led on */
immap->im_ioport.iop_padat |= 0x0001;
} else {
immap->im_ioport.iop_padat &= ~0x0001;
}
}
# endif
#ifdef CONFIG_LCD_INFO
#include <lcd.h>
#include <version.h>
#include <timestamp.h>
void lcd_show_board_info(void)
{
char temp[32];
lcd_printf ("%s (%s - %s)\n", U_BOOT_VERSION, U_BOOT_DATE, U_BOOT_TIME);
lcd_printf ("(C) 2008 DENX Software Engineering GmbH\n");
lcd_printf (" Wolfgang DENK, wd@denx.de\n");
#ifdef CONFIG_LCD_INFO_BELOW_LOGO
lcd_printf ("MPC823 CPU at %s MHz\n",
strmhz(temp, gd->cpu_clk));
lcd_printf (" %ld MB RAM, %ld MB Flash\n",
gd->ram_size >> 20,
gd->bd->bi_flashsize >> 20 );
#else
/* leave one blank line */
lcd_printf ("\nMPC823 CPU at %s MHz, %ld MB RAM, %ld MB Flash\n",
strmhz(temp, gd->cpu_clk),
gd->ram_size >> 20,
gd->bd->bi_flashsize >> 20 );
#endif /* CONFIG_LCD_INFO_BELOW_LOGO */
}
#endif /* CONFIG_LCD_INFO */
/*
* Device Tree Support
*/
#if defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_OF_LIBFDT)
int fdt_set_node_and_value (void *blob,
char *nodename,
char *regname,
void *var,
int size)
{
int ret = 0;
int nodeoffset = 0;
nodeoffset = fdt_path_offset (blob, nodename);
if (nodeoffset >= 0) {
ret = fdt_setprop (blob, nodeoffset, regname, var,
size);
if (ret < 0) {
printf("ft_blob_update(): "
"cannot set %s/%s property; err: %s\n",
nodename, regname, fdt_strerror (ret));
}
} else {
printf("ft_blob_update(): "
"cannot find %s node err:%s\n",
nodename, fdt_strerror (nodeoffset));
}
return ret;
}
int fdt_del_node_name (void *blob, char *nodename)
{
int ret = 0;
int nodeoffset = 0;
nodeoffset = fdt_path_offset (blob, nodename);
if (nodeoffset >= 0) {
ret = fdt_del_node (blob, nodeoffset);
if (ret < 0) {
printf("%s: cannot delete %s; err: %s\n",
__func__, nodename, fdt_strerror (ret));
}
} else {
printf("%s: cannot find %s node err:%s\n",
__func__, nodename, fdt_strerror (nodeoffset));
}
return ret;
}
int fdt_del_prop_name (void *blob, char *nodename, char *propname)
{
int ret = 0;
int nodeoffset = 0;
nodeoffset = fdt_path_offset (blob, nodename);
if (nodeoffset >= 0) {
ret = fdt_delprop (blob, nodeoffset, propname);
if (ret < 0) {
printf("%s: cannot delete %s %s; err: %s\n",
__func__, nodename, propname,
fdt_strerror (ret));
}
} else {
printf("%s: cannot find %s node err:%s\n",
__func__, nodename, fdt_strerror (nodeoffset));
}
return ret;
}
/*
* update "brg" property in the blob
*/
void ft_blob_update (void *blob, bd_t *bd)
{
uchar enetaddr[6];
ulong brg_data = 0;
/* BRG */
brg_data = cpu_to_be32(bd->bi_busfreq);
fdt_set_node_and_value(blob,
"/soc/cpm", "brg-frequency",
&brg_data, sizeof(brg_data));
/* MAC addr */
if (eth_getenv_enetaddr("ethaddr", enetaddr)) {
fdt_set_node_and_value(blob,
"ethernet0", "local-mac-address",
enetaddr, sizeof(u8) * 6);
}
if (hwconfig_arg_cmp("fec", "off")) {
/* no FEC on this plattform, delete DTS nodes */
fdt_del_node_name (blob, "ethernet1");
fdt_del_node_name (blob, "mdio1");
/* also the aliases entries */
fdt_del_prop_name (blob, "/aliases", "ethernet1");
fdt_del_prop_name (blob, "/aliases", "mdio1");
} else {
/* adjust local-mac-address for FEC ethernet */
if (eth_getenv_enetaddr("eth1addr", enetaddr)) {
fdt_set_node_and_value(blob,
"ethernet1", "local-mac-address",
enetaddr, sizeof(u8) * 6);
}
}
}
void ft_board_setup(void *blob, bd_t *bd)
{
ft_cpu_setup(blob, bd);
ft_blob_update(blob, bd);
}
#endif /* defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_OF_LIBFDT) */
/* ---------------------------------------------------------------------------- */
/* TK885D specific initializaion */
/* ---------------------------------------------------------------------------- */
#ifdef CONFIG_TK885D
#include <miiphy.h>
int last_stage_init(void)
{
const unsigned char phy[] = {CONFIG_FEC1_PHY, CONFIG_FEC2_PHY};
unsigned short reg;
int ret, i = 100;
char *s;
mii_init();
/* Without this delay 0xff is read from the UART buffer later in
* abortboot() and autoboot is aborted */
udelay(10000);
while (tstc() && i--)
(void)getc();
/* Check if auto-negotiation is prohibited */
s = getenv("phy_auto_nego");
if (!s || !strcmp(s, "on"))
/* Nothing to do - autonegotiation by default */
return 0;
for (i = 0; i < 2; i++) {
ret = miiphy_read("FEC", phy[i], MII_BMCR, ®);
if (ret) {
printf("Cannot read BMCR on PHY %d\n", phy[i]);
return 0;
}
/* Auto-negotiation off, hard set full duplex, 100Mbps */
ret = miiphy_write("FEC", phy[i],
MII_BMCR, (reg | BMCR_SPEED100 |
BMCR_FULLDPLX) & ~BMCR_ANENABLE);
if (ret) {
printf("Cannot write BMCR on PHY %d\n", phy[i]);
return 0;
}
}
return 0;
}
#endif
|
0181899820cbde6e53d22ed2064b7e6922b6f816
|
4ec22f6861e3acb6f400dcaa8de5751330476aa2
|
/src/markup.h
|
e3d26afef8f1f84d750ef28abe24a203adeaa19f
|
[
"BSD-3-Clause",
"LicenseRef-scancode-unknown-license-reference"
] |
permissive
|
dunst-project/dunst
|
5b5e23c996f1cff828ad0d7a3bc72d374b5ae9b9
|
a8b265094189661004fd100bcdc04321a868ca86
|
refs/heads/master
| 2023-08-27T11:58:12.092780
| 2023-08-11T18:31:06
| 2023-08-19T17:55:52
| 2,341,146
| 3,597
| 409
|
NOASSERTION
| 2023-09-14T12:01:45
| 2011-09-07T11:36:06
|
C
|
UTF-8
|
C
| false
| false
| 1,493
|
h
|
markup.h
|
/* copyright 2013 Sascha Kruse and contributors (see LICENSE for licensing information) */
#ifndef DUNST_MARKUP_H
#define DUNST_MARKUP_H
enum markup_mode {
MARKUP_NULL,
MARKUP_NO,
MARKUP_STRIP,
MARKUP_FULL
};
/**
* Strip any markup from text; turn it in to plain text.
*
* For well-formed markup, the following two commands should be
* roughly equivalent:
*
* out = markup_strip(in);
* pango_parse_markup(in, -1, 0, NULL, &out, NULL, NULL);
*
* However, `pango_parse_markup()` balks at invalid markup;
* `markup_strip()` shouldn't care if there is invalid markup.
*/
char *markup_strip(char *str);
/**
* Remove HTML hyperlinks of a string.
*
* @param str The string to replace a tags
* @param urls (nullable) If any href-attributes found, an `\n` concatenated
* string of the URLs in format `[<text between tags>] <href>`
*/
void markup_strip_a(char **str, char **urls);
/**
* Remove img-tags of a string. If alt attribute given, use this as replacement.
*
* @param str The string to replace img tags
* @param urls (nullable) If any src-attributes found, an `\n` concatenated string of
* the URLs in format `[<alt>] <src>`
*/
void markup_strip_img(char **str, char **urls);
/**
* Transform the string in accordance with `markup_mode` and
* `settings.ignore_newline`
*/
char *markup_transform(char *str, enum markup_mode markup_mode);
#endif
/* vim: set ft=c tabstop=8 shiftwidth=8 expandtab textwidth=0: */
|
9431a6cfeed0fedb008ea22ac4c97487f84e761c
|
8551168c7b71c31eebad0f9b0c71eebbcc743000
|
/src/lib/ultra/io/conteepwrite.c
|
45e8da79bd6a91e8a94992c979d033e7a02dbf3b
|
[
"MIT"
] |
permissive
|
n64decomp/perfect_dark
|
0db80e8ecba74741b959962e55c835a91c920f44
|
0235a971d6fb1a0d4421856d5a65aa8067bd4658
|
refs/heads/master
| 2023-08-31T04:27:53.864767
| 2023-08-29T11:36:58
| 2023-08-29T11:36:58
| 241,214,589
| 452
| 47
|
MIT
| 2023-08-21T08:53:40
| 2020-02-17T21:46:45
|
C
|
UTF-8
|
C
| false
| false
| 3,371
|
c
|
conteepwrite.c
|
#include <os_internal.h>
#include "controller.h"
#include "siint.h"
#include <rcp.h>
void __osPackEepWriteData(u8 address, u8 *buffer);
s32 osEepromWrite(OSMesgQueue *mq, u8 address, u8 *buffer)
{
s32 ret;
u16 type;
u8 *ptr;
__OSContEepromFormat eepromformat;
OSContStatus sdata;
ret = 0;
ptr = (u8 *)&__osEepPifRam.ramarray;
__osSiGetAccess();
ret = __osEepStatus(mq, &sdata);
type = sdata.type & (CONT_EEPROM | CONT_EEP16K);
if (ret == 0) {
switch (type) {
case CONT_EEPROM:
// @bug: Should be > EEPROM_MAXBLOCKS
if (address >= EEPROM_MAXBLOCKS) {
ret = -1;
}
break;
case CONT_EEPROM | CONT_EEP16K:
// @bug: Should be > EEP16K_MAXBLOCKS
if (address >= EEP16K_MAXBLOCKS) {
ret = -1;
}
break;
default:
if (1);
ret = CONT_NO_RESPONSE_ERROR;
break;
}
}
if (ret != 0) {
__osSiRelAccess();
return ret;
}
while (sdata.status & CONT_EEPROM_BUSY) {
__osEepStatus(mq, &sdata);
}
__osPackEepWriteData(address, buffer);
ret = __osSiRawStartDma(OS_WRITE, &__osEepPifRam);
osRecvMesg(mq, NULL, OS_MESG_BLOCK);
ret = __osSiRawStartDma(OS_READ, &__osEepPifRam);
__osContLastCmd = CONT_CMD_WRITE_EEPROM;
osRecvMesg(mq, NULL, OS_MESG_BLOCK);
ptr += 4;
eepromformat = *(__OSContEepromFormat *)ptr;
ret = CHNL_ERR(eepromformat);
__osSiRelAccess();
return ret;
}
void __osPackEepWriteData(u8 address, u8 *buffer)
{
u8 *ptr;
__OSContEepromFormat eepromformat;
int i;
ptr = (u8 *)&__osEepPifRam.ramarray;
__osEepPifRam.pifstatus = CONT_CMD_EXE;
eepromformat.txsize = CONT_CMD_WRITE_EEPROM_TX;
eepromformat.rxsize = CONT_CMD_WRITE_EEPROM_RX;
eepromformat.cmd = CONT_CMD_WRITE_EEPROM;
eepromformat.address = address;
for (i = 0; i < ARRLEN(eepromformat.data); i++) {
eepromformat.data[i] = *buffer++;
}
for (i = 0; i < 4; i++) {
*ptr++ = 0;
}
*(__OSContEepromFormat *)(ptr) = eepromformat;
ptr += sizeof(__OSContEepromFormat);
ptr[0] = CONT_CMD_END;
}
s32 __osEepStatus(OSMesgQueue *mq, OSContStatus *data)
{
s32 ret;
int i;
u8 *ptr;
__OSContRequestFormat requestformat;
ret = 0;
ptr = (u8 *)__osEepPifRam.ramarray;
for (i = 0; i < ARRLEN(__osEepPifRam.ramarray) + 1; i++) {
__osEepPifRam.ramarray[i] = 0;
}
__osEepPifRam.pifstatus = CONT_CMD_EXE;
ptr = (u8 *)__osEepPifRam.ramarray;
for (i = 0; i < 4; i++) {
*ptr++ = 0;
}
requestformat.dummy = CONT_CMD_NOP;
requestformat.txsize = CONT_CMD_REQUEST_STATUS_TX;
requestformat.rxsize = CONT_CMD_REQUEST_STATUS_RX;
requestformat.cmd = CONT_CMD_REQUEST_STATUS;
requestformat.typeh = CONT_CMD_NOP;
requestformat.typel = CONT_CMD_NOP;
requestformat.status = CONT_CMD_NOP;
requestformat.dummy1 = CONT_CMD_NOP;
*(__OSContRequestFormat *)ptr = requestformat;
ptr += sizeof(__OSContRequestFormat);
*ptr = CONT_CMD_END;
ret = __osSiRawStartDma(OS_WRITE, &__osEepPifRam);
osRecvMesg(mq, NULL, OS_MESG_BLOCK);
__osContLastCmd = CONT_CMD_END;
ret = __osSiRawStartDma(OS_READ, &__osEepPifRam);
osRecvMesg(mq, NULL, OS_MESG_BLOCK);
if (ret != 0) {
return ret;
}
ptr = (u8 *)&__osEepPifRam;
for (i = 0; i < 4; i++) {
*ptr++ = 0;
}
requestformat = *(__OSContRequestFormat *)ptr;
data->errno = CHNL_ERR(requestformat);
data->type = (requestformat.typel << 8) | requestformat.typeh;
data->status = requestformat.status;
if (data->errno != 0) {
return data->errno;
}
return 0;
}
|
db9d2996aedb784c8bff774b16b3adecc0c6b1d9
|
a65e2aac013b48ddfe5d6a7d108c2b84855d1148
|
/boot/zephyr/arm_cleanup.c
|
3b6c71ace7e6b0f80f91546c6d0f78ff78f25975
|
[
"Apache-2.0",
"BSD-3-Clause"
] |
permissive
|
mcu-tools/mcuboot
|
25ccdee3b1d319e09c9381cd00bc854efdc0142b
|
e188dbb0e1c1e2e2cecd627fbf2e13042222b1da
|
refs/heads/main
| 2023-08-30T09:17:10.520597
| 2023-08-29T06:43:16
| 2023-08-29T14:01:02
| 76,305,806
| 623
| 320
|
Apache-2.0
| 2023-09-13T11:46:03
| 2016-12-12T23:53:39
|
C
|
UTF-8
|
C
| false
| false
| 1,122
|
c
|
arm_cleanup.c
|
/*
* Copyright (c) 2020 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr/toolchain.h>
#include <cmsis_core.h>
#if CONFIG_CPU_HAS_NXP_MPU
#include <fsl_sysmpu.h>
#endif
void cleanup_arm_nvic(void) {
/* Allow any pending interrupts to be recognized */
__ISB();
__disable_irq();
/* Disable NVIC interrupts */
for (uint8_t i = 0; i < ARRAY_SIZE(NVIC->ICER); i++) {
NVIC->ICER[i] = 0xFFFFFFFF;
}
/* Clear pending NVIC interrupts */
for (uint8_t i = 0; i < ARRAY_SIZE(NVIC->ICPR); i++) {
NVIC->ICPR[i] = 0xFFFFFFFF;
}
}
#if CONFIG_CPU_HAS_ARM_MPU
__weak void z_arm_clear_arm_mpu_config(void)
{
int i;
int num_regions =
((MPU->TYPE & MPU_TYPE_DREGION_Msk) >> MPU_TYPE_DREGION_Pos);
for (i = 0; i < num_regions; i++) {
ARM_MPU_ClrRegion(i);
}
}
#elif CONFIG_CPU_HAS_NXP_MPU
__weak void z_arm_clear_arm_mpu_config(void)
{
int i;
int num_regions = FSL_FEATURE_SYSMPU_DESCRIPTOR_COUNT;
SYSMPU_Enable(SYSMPU, false);
/* NXP MPU region 0 is reserved for the debugger */
for (i = 1; i < num_regions; i++) {
SYSMPU_RegionEnable(SYSMPU, i, false);
}
}
#endif
|
fc00dc6cdd728dc5d35506733b32f3743d4d01e9
|
035660e8cc10571ebbd0d4393fef063bb7eb98f6
|
/src/overlays/actors/ovl_Obj_Makeoshihiki/z_obj_makeoshihiki.h
|
fbe8c1283d30006a1b0b7626ce5b585ef1b9b931
|
[] |
no_license
|
zeldaret/mm
|
f163a5e7c4314105777369fa7671ce9c2a99922a
|
4ae00e909e74044f05155683b49d2561f91de7ba
|
refs/heads/master
| 2023-08-06T07:22:04.912966
| 2023-08-04T20:36:03
| 2023-08-04T20:36:03
| 247,875,852
| 915
| 328
| null | 2023-09-14T11:48:59
| 2020-03-17T04:03:07
|
C
|
UTF-8
|
C
| false
| false
| 529
|
h
|
z_obj_makeoshihiki.h
|
#ifndef Z_OBJ_MAKEOSHIHIKI_H
#define Z_OBJ_MAKEOSHIHIKI_H
#include "global.h"
struct ObjMakeoshihiki;
#define OBJMAKEOSHIHIKI_GET_PATH_INDEX(thisx) (((thisx)->params >> 7) & 0x7F)
#define OBJMAKEOSHIHIKI_GET_SWITCHFLAG_1(thisx) ((thisx)->home.rot.z & 0x7F)
#define OBJMAKEOSHIHIKI_GET_SWITCHFLAG_2(thisx) ((thisx)->params & 0x7F)
typedef struct ObjMakeoshihiki {
/* 0x000 */ Actor actor;
/* 0x144 */ Vec3s* pathPoints;
/* 0x148 */ s32 pathCount;
} ObjMakeoshihiki; // size = 0x14C
#endif // Z_OBJ_MAKEOSHIHIKI_H
|
e1effea45d22f276ddb1f262ed5411f99bc6fa24
|
66f993723f09163d2ebfcc93b6b803238af841ff
|
/av1/decoder/detokenize.h
|
ba406660372fde945fcf2faff01cf6adc0dfe6cd
|
[
"BSD-2-Clause"
] |
permissive
|
mozilla/aom
|
e83efb7a6409048a2c6d87c1c2a10016c1c8c55f
|
46b7bb243b39929c02d6decc1bdb2e39e11540d6
|
refs/heads/master
| 2023-07-04T02:23:11.547136
| 2019-04-01T03:33:42
| 2019-04-01T03:33:42
| 96,821,694
| 160
| 36
|
NOASSERTION
| 2019-04-01T03:33:43
| 2017-07-10T21:11:39
|
C
|
UTF-8
|
C
| false
| false
| 1,331
|
h
|
detokenize.h
|
/*
* Copyright (c) 2016, Alliance for Open Media. All rights reserved
*
* This source code is subject to the terms of the BSD 2 Clause License and
* the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
* was not distributed with this source code in the LICENSE file, you can
* obtain it at www.aomedia.org/license/software. If the Alliance for Open
* Media Patent License 1.0 was not distributed with this source code in the
* PATENTS file, you can obtain it at www.aomedia.org/license/patent.
*/
#ifndef AV1_DECODER_DETOKENIZE_H_
#define AV1_DECODER_DETOKENIZE_H_
#include "./aom_config.h"
#if !CONFIG_PVQ || CONFIG_VAR_TX
#include "av1/decoder/decoder.h"
#include "av1/common/scan.h"
#endif // !CONFIG_PVQ
#ifdef __cplusplus
extern "C" {
#endif
#if CONFIG_PALETTE
void av1_decode_palette_tokens(MACROBLOCKD *const xd, int plane, aom_reader *r);
#endif // CONFIG_PALETTE
#if !CONFIG_PVQ || CONFIG_VAR_TX
int av1_decode_block_tokens(AV1_COMMON *cm, MACROBLOCKD *const xd, int plane,
const SCAN_ORDER *sc, int x, int y, TX_SIZE tx_size,
TX_TYPE tx_type, int16_t *max_scan_line,
aom_reader *r, int seg_id);
#endif // !CONFIG_PVQ
#ifdef __cplusplus
} // extern "C"
#endif
#endif // AV1_DECODER_DETOKENIZE_H_
|
68cb23985f109d3401f1d4b8a2a31d07168f2652
|
7eaf54a78c9e2117247cb2ab6d3a0c20719ba700
|
/SOFTWARE/A64-TERES/u-boot_new/include/linux/compiler-gcc4.h
|
27d11ca7b08f398b68a372104748384248d0b1db
|
[
"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
| 2,157
|
h
|
compiler-gcc4.h
|
#ifndef __LINUX_COMPILER_H
#error "Please don't include <linux/compiler-gcc4.h> directly, include <linux/compiler.h> instead."
#endif
/* GCC 4.1.[01] miscompiles __weak */
#ifdef __KERNEL__
# if __GNUC_MINOR__ == 1 && __GNUC_PATCHLEVEL__ <= 1
# error Your version of gcc miscompiles the __weak directive
# endif
#endif
#define __used __attribute__((__used__))
#define __must_check __attribute__((warn_unused_result))
#define __compiler_offsetof(a,b) __builtin_offsetof(a,b)
#ifndef __always_inline
# define __always_inline inline __attribute__((always_inline))
#endif
/*
* A trick to suppress uninitialized variable warning without generating any
* code
*/
#define uninitialized_var(x) x = x
#if __GNUC_MINOR__ >= 3
/* Mark functions as cold. gcc will assume any path leading to a call
to them will be unlikely. This means a lot of manual unlikely()s
are unnecessary now for any paths leading to the usual suspects
like BUG(), printk(), panic() etc. [but let's keep them for now for
older compilers]
Early snapshots of gcc 4.3 don't support this and we can't detect this
in the preprocessor, but we can live with this because they're unreleased.
Maketime probing would be overkill here.
gcc also has a __attribute__((__hot__)) to move hot functions into
a special section, but I don't see any sense in this right now in
the kernel context */
#define __cold __attribute__((__cold__))
#if __GNUC_MINOR__ >= 5
/*
* Mark a position in code as unreachable. This can be used to
* suppress control flow warnings after asm blocks that transfer
* control elsewhere.
*
* Early snapshots of gcc 4.5 don't support this and we can't detect
* this in the preprocessor, but we can live with this because they're
* unreleased. Really, we need to have autoconf for the kernel.
*/
#define unreachable() __builtin_unreachable()
#endif
#endif
#if __GNUC_MINOR__ > 0
#define __compiletime_object_size(obj) __builtin_object_size(obj, 0)
#endif
#if __GNUC_MINOR__ >= 4
#define __compiletime_warning(message) __attribute__((warning(message)))
#define __compiletime_error(message) __attribute__((error(message)))
#endif
|
a0d5e30ab51e3102d021ab2eee1bbcaaac7d4080
|
6ae7fd6dda212072ff85eb7881863ece252b8569
|
/src/src_sinc.c
|
716c4a40b4c841bcb99de50e427b98100bb9bdb1
|
[
"BSD-2-Clause"
] |
permissive
|
libsndfile/libsamplerate
|
f0017d0cbf557c8cd670023ea94e7b77922b9f03
|
22bd06eb114850ebe31981eb794d150a95439fef
|
refs/heads/master
| 2023-04-27T10:13:53.575259
| 2023-04-18T06:22:28
| 2023-04-18T07:42:04
| 27,333,447
| 268
| 72
|
BSD-2-Clause
| 2023-04-18T06:23:39
| 2014-11-30T11:34:03
|
C
|
UTF-8
|
C
| false
| false
| 41,498
|
c
|
src_sinc.c
|
/*
** Copyright (c) 2002-2021, Erik de Castro Lopo <erikd@mega-nerd.com>
** All rights reserved.
**
** This code is released under 2-clause BSD license. Please see the
** file at : https://github.com/libsndfile/libsamplerate/blob/master/COPYING
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include "common.h"
#define SINC_MAGIC_MARKER MAKE_MAGIC (' ', 's', 'i', 'n', 'c', ' ')
/*========================================================================================
*/
#define MAKE_INCREMENT_T(x) ((increment_t) (x))
#define SHIFT_BITS 12
#define FP_ONE ((double) (((increment_t) 1) << SHIFT_BITS))
#define INV_FP_ONE (1.0 / FP_ONE)
/* Customixe max channls from Kconfig. */
#ifndef CONFIG_CHAN_NR
#define MAX_CHANNELS 128
#else
#define MAX_CHANNELS CONFIG_CHAN_NR
#endif
/*========================================================================================
*/
typedef int32_t increment_t ;
typedef float coeff_t ;
typedef int _CHECK_SHIFT_BITS[2 * (SHIFT_BITS < sizeof (increment_t) * 8 - 1) - 1]; /* sanity check. */
#ifdef ENABLE_SINC_FAST_CONVERTER
#include "fastest_coeffs.h"
#endif
#ifdef ENABLE_SINC_MEDIUM_CONVERTER
#include "mid_qual_coeffs.h"
#endif
#ifdef ENABLE_SINC_BEST_CONVERTER
#include "high_qual_coeffs.h"
#endif
typedef struct
{ int sinc_magic_marker ;
long in_count, in_used ;
long out_count, out_gen ;
int coeff_half_len, index_inc ;
double src_ratio, input_index ;
coeff_t const *coeffs ;
int b_current, b_end, b_real_end, b_len ;
/* Sure hope noone does more than 128 channels at once. */
double left_calc [MAX_CHANNELS], right_calc [MAX_CHANNELS] ;
float *buffer ;
} SINC_FILTER ;
static SRC_ERROR sinc_multichan_vari_process (SRC_STATE *state, SRC_DATA *data) ;
static SRC_ERROR sinc_hex_vari_process (SRC_STATE *state, SRC_DATA *data) ;
static SRC_ERROR sinc_quad_vari_process (SRC_STATE *state, SRC_DATA *data) ;
static SRC_ERROR sinc_stereo_vari_process (SRC_STATE *state, SRC_DATA *data) ;
static SRC_ERROR sinc_mono_vari_process (SRC_STATE *state, SRC_DATA *data) ;
static SRC_ERROR prepare_data (SINC_FILTER *filter, int channels, SRC_DATA *data, int half_filter_chan_len) WARN_UNUSED ;
static void sinc_reset (SRC_STATE *state) ;
static SRC_STATE *sinc_copy (SRC_STATE *state) ;
static void sinc_close (SRC_STATE *state) ;
static SRC_STATE_VT sinc_multichan_state_vt =
{
sinc_multichan_vari_process,
sinc_multichan_vari_process,
sinc_reset,
sinc_copy,
sinc_close
} ;
static SRC_STATE_VT sinc_hex_state_vt =
{
sinc_hex_vari_process,
sinc_hex_vari_process,
sinc_reset,
sinc_copy,
sinc_close
} ;
static SRC_STATE_VT sinc_quad_state_vt =
{
sinc_quad_vari_process,
sinc_quad_vari_process,
sinc_reset,
sinc_copy,
sinc_close
} ;
static SRC_STATE_VT sinc_stereo_state_vt =
{
sinc_stereo_vari_process,
sinc_stereo_vari_process,
sinc_reset,
sinc_copy,
sinc_close
} ;
static SRC_STATE_VT sinc_mono_state_vt =
{
sinc_mono_vari_process,
sinc_mono_vari_process,
sinc_reset,
sinc_copy,
sinc_close
} ;
static inline increment_t
double_to_fp (double x)
{ return (increment_t) (psf_lrint ((x) * FP_ONE)) ;
} /* double_to_fp */
static inline increment_t
int_to_fp (int x)
{ return (((increment_t) (x)) << SHIFT_BITS) ;
} /* int_to_fp */
static inline int
fp_to_int (increment_t x)
{ return (((x) >> SHIFT_BITS)) ;
} /* fp_to_int */
static inline increment_t
fp_fraction_part (increment_t x)
{ return ((x) & ((((increment_t) 1) << SHIFT_BITS) - 1)) ;
} /* fp_fraction_part */
static inline double
fp_to_double (increment_t x)
{ return fp_fraction_part (x) * INV_FP_ONE ;
} /* fp_to_double */
static inline int
int_div_ceil (int divident, int divisor) /* == (int) ceil ((float) divident / divisor) */
{ assert (divident >= 0 && divisor > 0) ; /* For positive numbers only */
return (divident + (divisor - 1)) / divisor ;
}
/*----------------------------------------------------------------------------------------
*/
LIBSAMPLERATE_DLL_PRIVATE const char*
sinc_get_name (int src_enum)
{
switch (src_enum)
{ case SRC_SINC_BEST_QUALITY :
return "Best Sinc Interpolator" ;
case SRC_SINC_MEDIUM_QUALITY :
return "Medium Sinc Interpolator" ;
case SRC_SINC_FASTEST :
return "Fastest Sinc Interpolator" ;
default: break ;
} ;
return NULL ;
} /* sinc_get_descrition */
LIBSAMPLERATE_DLL_PRIVATE const char*
sinc_get_description (int src_enum)
{
switch (src_enum)
{ case SRC_SINC_FASTEST :
return "Band limited sinc interpolation, fastest, 97dB SNR, 80% BW." ;
case SRC_SINC_MEDIUM_QUALITY :
return "Band limited sinc interpolation, medium quality, 121dB SNR, 90% BW." ;
case SRC_SINC_BEST_QUALITY :
return "Band limited sinc interpolation, best quality, 144dB SNR, 96% BW." ;
default :
break ;
} ;
return NULL ;
} /* sinc_get_descrition */
static SINC_FILTER *
sinc_filter_new (int converter_type, int channels)
{
assert (converter_type == SRC_SINC_FASTEST ||
converter_type == SRC_SINC_MEDIUM_QUALITY ||
converter_type == SRC_SINC_BEST_QUALITY) ;
assert (channels > 0 && channels <= MAX_CHANNELS) ;
SINC_FILTER *priv = (SINC_FILTER *) calloc (1, sizeof (SINC_FILTER)) ;
if (priv)
{
priv->sinc_magic_marker = SINC_MAGIC_MARKER ;
switch (converter_type)
{
#ifdef ENABLE_SINC_FAST_CONVERTER
case SRC_SINC_FASTEST :
priv->coeffs = fastest_coeffs.coeffs ;
priv->coeff_half_len = ARRAY_LEN (fastest_coeffs.coeffs) - 2 ;
priv->index_inc = fastest_coeffs.increment ;
break ;
#endif
#ifdef ENABLE_SINC_MEDIUM_CONVERTER
case SRC_SINC_MEDIUM_QUALITY :
priv->coeffs = slow_mid_qual_coeffs.coeffs ;
priv->coeff_half_len = ARRAY_LEN (slow_mid_qual_coeffs.coeffs) - 2 ;
priv->index_inc = slow_mid_qual_coeffs.increment ;
break ;
#endif
#ifdef ENABLE_SINC_BEST_CONVERTER
case SRC_SINC_BEST_QUALITY :
priv->coeffs = slow_high_qual_coeffs.coeffs ;
priv->coeff_half_len = ARRAY_LEN (slow_high_qual_coeffs.coeffs) - 2 ;
priv->index_inc = slow_high_qual_coeffs.increment ;
break ;
#endif
}
priv->b_len = 3 * (int) psf_lrint ((priv->coeff_half_len + 2.0) / priv->index_inc * SRC_MAX_RATIO + 1) ;
priv->b_len = MAX (priv->b_len, 4096) ;
priv->b_len *= channels ;
priv->b_len += 1 ; // There is a <= check against samples_in_hand requiring a buffer bigger than the calculation above
priv->buffer = (float *) calloc (priv->b_len + channels, sizeof (float)) ;
if (!priv->buffer)
{
free (priv) ;
priv = NULL ;
}
}
return priv ;
}
LIBSAMPLERATE_DLL_PRIVATE SRC_STATE *
sinc_state_new (int converter_type, int channels, SRC_ERROR *error)
{
assert (converter_type == SRC_SINC_FASTEST ||
converter_type == SRC_SINC_MEDIUM_QUALITY ||
converter_type == SRC_SINC_BEST_QUALITY) ;
assert (channels > 0) ;
assert (error != NULL) ;
if (channels > MAX_CHANNELS)
{
*error = SRC_ERR_BAD_CHANNEL_COUNT ;
return NULL ;
}
SRC_STATE *state = (SRC_STATE *) calloc (1, sizeof (SRC_STATE)) ;
if (!state)
{
*error = SRC_ERR_MALLOC_FAILED ;
return NULL ;
}
state->channels = channels ;
state->mode = SRC_MODE_PROCESS ;
if (state->channels == 1)
state->vt = &sinc_mono_state_vt ;
else if (state->channels == 2)
state->vt = &sinc_stereo_state_vt ;
else if (state->channels == 4)
state->vt = &sinc_quad_state_vt ;
else if (state->channels == 6)
state->vt = &sinc_hex_state_vt ;
else
state->vt = &sinc_multichan_state_vt ;
state->private_data = sinc_filter_new (converter_type, state->channels) ;
if (!state->private_data)
{
free (state) ;
*error = SRC_ERR_MALLOC_FAILED ;
return NULL ;
}
sinc_reset (state) ;
*error = SRC_ERR_NO_ERROR ;
return state ;
}
static void
sinc_reset (SRC_STATE *state)
{ SINC_FILTER *filter ;
filter = (SINC_FILTER*) state->private_data ;
if (filter == NULL)
return ;
filter->b_current = filter->b_end = 0 ;
filter->b_real_end = -1 ;
filter->src_ratio = filter->input_index = 0.0 ;
memset (filter->buffer, 0, filter->b_len * sizeof (filter->buffer [0])) ;
/* Set this for a sanity check */
memset (filter->buffer + filter->b_len, 0xAA, state->channels * sizeof (filter->buffer [0])) ;
} /* sinc_reset */
static SRC_STATE *
sinc_copy (SRC_STATE *state)
{
assert (state != NULL) ;
if (state->private_data == NULL)
return NULL ;
SRC_STATE *to = (SRC_STATE *) calloc (1, sizeof (SRC_STATE)) ;
if (!to)
return NULL ;
memcpy (to, state, sizeof (SRC_STATE)) ;
SINC_FILTER* from_filter = (SINC_FILTER*) state->private_data ;
SINC_FILTER *to_filter = (SINC_FILTER *) calloc (1, sizeof (SINC_FILTER)) ;
if (!to_filter)
{
free (to) ;
return NULL ;
}
memcpy (to_filter, from_filter, sizeof (SINC_FILTER)) ;
to_filter->buffer = (float *) malloc (sizeof (float) * (from_filter->b_len + state->channels)) ;
if (!to_filter->buffer)
{
free (to) ;
free (to_filter) ;
return NULL ;
}
memcpy (to_filter->buffer, from_filter->buffer, sizeof (float) * (from_filter->b_len + state->channels)) ;
to->private_data = to_filter ;
return to ;
} /* sinc_copy */
/*========================================================================================
** Beware all ye who dare pass this point. There be dragons here.
*/
static inline double
calc_output_single (SINC_FILTER *filter, increment_t increment, increment_t start_filter_index)
{ double fraction, left, right, icoeff ;
increment_t filter_index, max_filter_index ;
int data_index, coeff_count, indx ;
/* Convert input parameters into fixed point. */
max_filter_index = int_to_fp (filter->coeff_half_len) ;
/* First apply the left half of the filter. */
filter_index = start_filter_index ;
coeff_count = (max_filter_index - filter_index) / increment ;
filter_index = filter_index + coeff_count * increment ;
data_index = filter->b_current - coeff_count ;
if (data_index < 0) /* Avoid underflow access to filter->buffer. */
{ int steps = -data_index ;
/* If the assert triggers we would have to take care not to underflow/overflow */
assert (steps <= int_div_ceil (filter_index, increment)) ;
filter_index -= increment * steps ;
data_index += steps ;
}
left = 0.0 ;
while (filter_index >= MAKE_INCREMENT_T (0))
{ fraction = fp_to_double (filter_index) ;
indx = fp_to_int (filter_index) ;
assert (indx >= 0 && indx + 1 < filter->coeff_half_len + 2) ;
icoeff = filter->coeffs [indx] + fraction * (filter->coeffs [indx + 1] - filter->coeffs [indx]) ;
assert (data_index >= 0 && data_index < filter->b_len) ;
assert (data_index < filter->b_end) ;
left += icoeff * filter->buffer [data_index] ;
filter_index -= increment ;
data_index = data_index + 1 ;
} ;
/* Now apply the right half of the filter. */
filter_index = increment - start_filter_index ;
coeff_count = (max_filter_index - filter_index) / increment ;
filter_index = filter_index + coeff_count * increment ;
data_index = filter->b_current + 1 + coeff_count ;
right = 0.0 ;
do
{ fraction = fp_to_double (filter_index) ;
indx = fp_to_int (filter_index) ;
assert (indx < filter->coeff_half_len + 2) ;
icoeff = filter->coeffs [indx] + fraction * (filter->coeffs [indx + 1] - filter->coeffs [indx]) ;
assert (data_index >= 0 && data_index < filter->b_len) ;
assert (data_index < filter->b_end) ;
right += icoeff * filter->buffer [data_index] ;
filter_index -= increment ;
data_index = data_index - 1 ;
}
while (filter_index > MAKE_INCREMENT_T (0)) ;
return (left + right) ;
} /* calc_output_single */
static SRC_ERROR
sinc_mono_vari_process (SRC_STATE *state, SRC_DATA *data)
{ SINC_FILTER *filter ;
double input_index, src_ratio, count, float_increment, terminate, rem ;
increment_t increment, start_filter_index ;
int half_filter_chan_len, samples_in_hand ;
if (state->private_data == NULL)
return SRC_ERR_NO_PRIVATE ;
filter = (SINC_FILTER*) state->private_data ;
/* If there is not a problem, this will be optimised out. */
if (sizeof (filter->buffer [0]) != sizeof (data->data_in [0]))
return SRC_ERR_SIZE_INCOMPATIBILITY ;
filter->in_count = data->input_frames * state->channels ;
filter->out_count = data->output_frames * state->channels ;
filter->in_used = filter->out_gen = 0 ;
src_ratio = state->last_ratio ;
if (is_bad_src_ratio (src_ratio))
return SRC_ERR_BAD_INTERNAL_STATE ;
/* Check the sample rate ratio wrt the buffer len. */
count = (filter->coeff_half_len + 2.0) / filter->index_inc ;
if (MIN (state->last_ratio, data->src_ratio) < 1.0)
count /= MIN (state->last_ratio, data->src_ratio) ;
/* Maximum coefficientson either side of center point. */
half_filter_chan_len = state->channels * (int) (psf_lrint (count) + 1) ;
input_index = state->last_position ;
rem = fmod_one (input_index) ;
filter->b_current = (filter->b_current + state->channels * psf_lrint (input_index - rem)) % filter->b_len ;
input_index = rem ;
terminate = 1.0 / src_ratio + 1e-20 ;
/* Main processing loop. */
while (filter->out_gen < filter->out_count)
{
/* Need to reload buffer? */
samples_in_hand = (filter->b_end - filter->b_current + filter->b_len) % filter->b_len ;
if (samples_in_hand <= half_filter_chan_len)
{ if ((state->error = prepare_data (filter, state->channels, data, half_filter_chan_len)) != 0)
return state->error ;
samples_in_hand = (filter->b_end - filter->b_current + filter->b_len) % filter->b_len ;
if (samples_in_hand <= half_filter_chan_len)
break ;
} ;
/* This is the termination condition. */
if (filter->b_real_end >= 0)
{ if (filter->b_current + input_index + terminate > filter->b_real_end)
break ;
} ;
if (filter->out_count > 0 && fabs (state->last_ratio - data->src_ratio) > 1e-10)
src_ratio = state->last_ratio + filter->out_gen * (data->src_ratio - state->last_ratio) / filter->out_count ;
float_increment = filter->index_inc * (src_ratio < 1.0 ? src_ratio : 1.0) ;
increment = double_to_fp (float_increment) ;
start_filter_index = double_to_fp (input_index * float_increment) ;
data->data_out [filter->out_gen] = (float) ((float_increment / filter->index_inc) *
calc_output_single (filter, increment, start_filter_index)) ;
filter->out_gen ++ ;
/* Figure out the next index. */
input_index += 1.0 / src_ratio ;
rem = fmod_one (input_index) ;
filter->b_current = (filter->b_current + state->channels * psf_lrint (input_index - rem)) % filter->b_len ;
input_index = rem ;
} ;
state->last_position = input_index ;
/* Save current ratio rather then target ratio. */
state->last_ratio = src_ratio ;
data->input_frames_used = filter->in_used / state->channels ;
data->output_frames_gen = filter->out_gen / state->channels ;
return SRC_ERR_NO_ERROR ;
} /* sinc_mono_vari_process */
static inline void
calc_output_stereo (SINC_FILTER *filter, int channels, increment_t increment, increment_t start_filter_index, double scale, float * output)
{ double fraction, left [2], right [2], icoeff ;
increment_t filter_index, max_filter_index ;
int data_index, coeff_count, indx ;
/* Convert input parameters into fixed point. */
max_filter_index = int_to_fp (filter->coeff_half_len) ;
/* First apply the left half of the filter. */
filter_index = start_filter_index ;
coeff_count = (max_filter_index - filter_index) / increment ;
filter_index = filter_index + coeff_count * increment ;
data_index = filter->b_current - channels * coeff_count ;
if (data_index < 0) /* Avoid underflow access to filter->buffer. */
{ int steps = int_div_ceil (-data_index, 2) ;
/* If the assert triggers we would have to take care not to underflow/overflow */
assert (steps <= int_div_ceil (filter_index, increment)) ;
filter_index -= increment * steps ;
data_index += steps * 2;
}
left [0] = left [1] = 0.0 ;
while (filter_index >= MAKE_INCREMENT_T (0))
{ fraction = fp_to_double (filter_index) ;
indx = fp_to_int (filter_index) ;
assert (indx >= 0 && indx + 1 < filter->coeff_half_len + 2) ;
icoeff = filter->coeffs [indx] + fraction * (filter->coeffs [indx + 1] - filter->coeffs [indx]) ;
assert (data_index >= 0 && data_index + 1 < filter->b_len) ;
assert (data_index + 1 < filter->b_end) ;
for (int ch = 0; ch < 2; ch++)
left [ch] += icoeff * filter->buffer [data_index + ch] ;
filter_index -= increment ;
data_index = data_index + 2 ;
} ;
/* Now apply the right half of the filter. */
filter_index = increment - start_filter_index ;
coeff_count = (max_filter_index - filter_index) / increment ;
filter_index = filter_index + coeff_count * increment ;
data_index = filter->b_current + channels * (1 + coeff_count) ;
right [0] = right [1] = 0.0 ;
do
{ fraction = fp_to_double (filter_index) ;
indx = fp_to_int (filter_index) ;
assert (indx >= 0 && indx + 1 < filter->coeff_half_len + 2) ;
icoeff = filter->coeffs [indx] + fraction * (filter->coeffs [indx + 1] - filter->coeffs [indx]) ;
assert (data_index >= 0 && data_index + 1 < filter->b_len) ;
assert (data_index + 1 < filter->b_end) ;
for (int ch = 0; ch < 2; ch++)
right [ch] += icoeff * filter->buffer [data_index + ch] ;
filter_index -= increment ;
data_index = data_index - 2 ;
}
while (filter_index > MAKE_INCREMENT_T (0)) ;
for (int ch = 0; ch < 2; ch++)
output [ch] = (float) (scale * (left [ch] + right [ch])) ;
} /* calc_output_stereo */
SRC_ERROR
sinc_stereo_vari_process (SRC_STATE *state, SRC_DATA *data)
{ SINC_FILTER *filter ;
double input_index, src_ratio, count, float_increment, terminate, rem ;
increment_t increment, start_filter_index ;
int half_filter_chan_len, samples_in_hand ;
if (state->private_data == NULL)
return SRC_ERR_NO_PRIVATE ;
filter = (SINC_FILTER*) state->private_data ;
/* If there is not a problem, this will be optimised out. */
if (sizeof (filter->buffer [0]) != sizeof (data->data_in [0]))
return SRC_ERR_SIZE_INCOMPATIBILITY ;
filter->in_count = data->input_frames * state->channels ;
filter->out_count = data->output_frames * state->channels ;
filter->in_used = filter->out_gen = 0 ;
src_ratio = state->last_ratio ;
if (is_bad_src_ratio (src_ratio))
return SRC_ERR_BAD_INTERNAL_STATE ;
/* Check the sample rate ratio wrt the buffer len. */
count = (filter->coeff_half_len + 2.0) / filter->index_inc ;
if (MIN (state->last_ratio, data->src_ratio) < 1.0)
count /= MIN (state->last_ratio, data->src_ratio) ;
/* Maximum coefficientson either side of center point. */
half_filter_chan_len = state->channels * (int) (psf_lrint (count) + 1) ;
input_index = state->last_position ;
rem = fmod_one (input_index) ;
filter->b_current = (filter->b_current + state->channels * psf_lrint (input_index - rem)) % filter->b_len ;
input_index = rem ;
terminate = 1.0 / src_ratio + 1e-20 ;
/* Main processing loop. */
while (filter->out_gen < filter->out_count)
{
/* Need to reload buffer? */
samples_in_hand = (filter->b_end - filter->b_current + filter->b_len) % filter->b_len ;
if (samples_in_hand <= half_filter_chan_len)
{ if ((state->error = prepare_data (filter, state->channels, data, half_filter_chan_len)) != 0)
return state->error ;
samples_in_hand = (filter->b_end - filter->b_current + filter->b_len) % filter->b_len ;
if (samples_in_hand <= half_filter_chan_len)
break ;
} ;
/* This is the termination condition. */
if (filter->b_real_end >= 0)
{ if (filter->b_current + input_index + terminate >= filter->b_real_end)
break ;
} ;
if (filter->out_count > 0 && fabs (state->last_ratio - data->src_ratio) > 1e-10)
src_ratio = state->last_ratio + filter->out_gen * (data->src_ratio - state->last_ratio) / filter->out_count ;
float_increment = filter->index_inc * (src_ratio < 1.0 ? src_ratio : 1.0) ;
increment = double_to_fp (float_increment) ;
start_filter_index = double_to_fp (input_index * float_increment) ;
calc_output_stereo (filter, state->channels, increment, start_filter_index, float_increment / filter->index_inc, data->data_out + filter->out_gen) ;
filter->out_gen += 2 ;
/* Figure out the next index. */
input_index += 1.0 / src_ratio ;
rem = fmod_one (input_index) ;
filter->b_current = (filter->b_current + state->channels * psf_lrint (input_index - rem)) % filter->b_len ;
input_index = rem ;
} ;
state->last_position = input_index ;
/* Save current ratio rather then target ratio. */
state->last_ratio = src_ratio ;
data->input_frames_used = filter->in_used / state->channels ;
data->output_frames_gen = filter->out_gen / state->channels ;
return SRC_ERR_NO_ERROR ;
} /* sinc_stereo_vari_process */
static inline void
calc_output_quad (SINC_FILTER *filter, int channels, increment_t increment, increment_t start_filter_index, double scale, float * output)
{ double fraction, left [4], right [4], icoeff ;
increment_t filter_index, max_filter_index ;
int data_index, coeff_count, indx ;
/* Convert input parameters into fixed point. */
max_filter_index = int_to_fp (filter->coeff_half_len) ;
/* First apply the left half of the filter. */
filter_index = start_filter_index ;
coeff_count = (max_filter_index - filter_index) / increment ;
filter_index = filter_index + coeff_count * increment ;
data_index = filter->b_current - channels * coeff_count ;
if (data_index < 0) /* Avoid underflow access to filter->buffer. */
{ int steps = int_div_ceil (-data_index, 4) ;
/* If the assert triggers we would have to take care not to underflow/overflow */
assert (steps <= int_div_ceil (filter_index, increment)) ;
filter_index -= increment * steps ;
data_index += steps * 4;
}
left [0] = left [1] = left [2] = left [3] = 0.0 ;
while (filter_index >= MAKE_INCREMENT_T (0))
{ fraction = fp_to_double (filter_index) ;
indx = fp_to_int (filter_index) ;
assert (indx >= 0 && indx + 1 < filter->coeff_half_len + 2) ;
icoeff = filter->coeffs [indx] + fraction * (filter->coeffs [indx + 1] - filter->coeffs [indx]) ;
assert (data_index >= 0 && data_index + 3 < filter->b_len) ;
assert (data_index + 3 < filter->b_end) ;
for (int ch = 0; ch < 4; ch++)
left [ch] += icoeff * filter->buffer [data_index + ch] ;
filter_index -= increment ;
data_index = data_index + 4 ;
} ;
/* Now apply the right half of the filter. */
filter_index = increment - start_filter_index ;
coeff_count = (max_filter_index - filter_index) / increment ;
filter_index = filter_index + coeff_count * increment ;
data_index = filter->b_current + channels * (1 + coeff_count) ;
right [0] = right [1] = right [2] = right [3] = 0.0 ;
do
{ fraction = fp_to_double (filter_index) ;
indx = fp_to_int (filter_index) ;
assert (indx >= 0 && indx + 1 < filter->coeff_half_len + 2) ;
icoeff = filter->coeffs [indx] + fraction * (filter->coeffs [indx + 1] - filter->coeffs [indx]) ;
assert (data_index >= 0 && data_index + 3 < filter->b_len) ;
assert (data_index + 3 < filter->b_end) ;
for (int ch = 0; ch < 4; ch++)
right [ch] += icoeff * filter->buffer [data_index + ch] ;
filter_index -= increment ;
data_index = data_index - 4 ;
}
while (filter_index > MAKE_INCREMENT_T (0)) ;
for (int ch = 0; ch < 4; ch++)
output [ch] = (float) (scale * (left [ch] + right [ch])) ;
} /* calc_output_quad */
SRC_ERROR
sinc_quad_vari_process (SRC_STATE *state, SRC_DATA *data)
{ SINC_FILTER *filter ;
double input_index, src_ratio, count, float_increment, terminate, rem ;
increment_t increment, start_filter_index ;
int half_filter_chan_len, samples_in_hand ;
if (state->private_data == NULL)
return SRC_ERR_NO_PRIVATE ;
filter = (SINC_FILTER*) state->private_data ;
/* If there is not a problem, this will be optimised out. */
if (sizeof (filter->buffer [0]) != sizeof (data->data_in [0]))
return SRC_ERR_SIZE_INCOMPATIBILITY ;
filter->in_count = data->input_frames * state->channels ;
filter->out_count = data->output_frames * state->channels ;
filter->in_used = filter->out_gen = 0 ;
src_ratio = state->last_ratio ;
if (is_bad_src_ratio (src_ratio))
return SRC_ERR_BAD_INTERNAL_STATE ;
/* Check the sample rate ratio wrt the buffer len. */
count = (filter->coeff_half_len + 2.0) / filter->index_inc ;
if (MIN (state->last_ratio, data->src_ratio) < 1.0)
count /= MIN (state->last_ratio, data->src_ratio) ;
/* Maximum coefficientson either side of center point. */
half_filter_chan_len = state->channels * (int) (psf_lrint (count) + 1) ;
input_index = state->last_position ;
rem = fmod_one (input_index) ;
filter->b_current = (filter->b_current + state->channels * psf_lrint (input_index - rem)) % filter->b_len ;
input_index = rem ;
terminate = 1.0 / src_ratio + 1e-20 ;
/* Main processing loop. */
while (filter->out_gen < filter->out_count)
{
/* Need to reload buffer? */
samples_in_hand = (filter->b_end - filter->b_current + filter->b_len) % filter->b_len ;
if (samples_in_hand <= half_filter_chan_len)
{ if ((state->error = prepare_data (filter, state->channels, data, half_filter_chan_len)) != 0)
return state->error ;
samples_in_hand = (filter->b_end - filter->b_current + filter->b_len) % filter->b_len ;
if (samples_in_hand <= half_filter_chan_len)
break ;
} ;
/* This is the termination condition. */
if (filter->b_real_end >= 0)
{ if (filter->b_current + input_index + terminate >= filter->b_real_end)
break ;
} ;
if (filter->out_count > 0 && fabs (state->last_ratio - data->src_ratio) > 1e-10)
src_ratio = state->last_ratio + filter->out_gen * (data->src_ratio - state->last_ratio) / filter->out_count ;
float_increment = filter->index_inc * (src_ratio < 1.0 ? src_ratio : 1.0) ;
increment = double_to_fp (float_increment) ;
start_filter_index = double_to_fp (input_index * float_increment) ;
calc_output_quad (filter, state->channels, increment, start_filter_index, float_increment / filter->index_inc, data->data_out + filter->out_gen) ;
filter->out_gen += 4 ;
/* Figure out the next index. */
input_index += 1.0 / src_ratio ;
rem = fmod_one (input_index) ;
filter->b_current = (filter->b_current + state->channels * psf_lrint (input_index - rem)) % filter->b_len ;
input_index = rem ;
} ;
state->last_position = input_index ;
/* Save current ratio rather then target ratio. */
state->last_ratio = src_ratio ;
data->input_frames_used = filter->in_used / state->channels ;
data->output_frames_gen = filter->out_gen / state->channels ;
return SRC_ERR_NO_ERROR ;
} /* sinc_quad_vari_process */
static inline void
calc_output_hex (SINC_FILTER *filter, int channels, increment_t increment, increment_t start_filter_index, double scale, float * output)
{ double fraction, left [6], right [6], icoeff ;
increment_t filter_index, max_filter_index ;
int data_index, coeff_count, indx ;
/* Convert input parameters into fixed point. */
max_filter_index = int_to_fp (filter->coeff_half_len) ;
/* First apply the left half of the filter. */
filter_index = start_filter_index ;
coeff_count = (max_filter_index - filter_index) / increment ;
filter_index = filter_index + coeff_count * increment ;
data_index = filter->b_current - channels * coeff_count ;
if (data_index < 0) /* Avoid underflow access to filter->buffer. */
{ int steps = int_div_ceil (-data_index, 6) ;
/* If the assert triggers we would have to take care not to underflow/overflow */
assert (steps <= int_div_ceil (filter_index, increment)) ;
filter_index -= increment * steps ;
data_index += steps * 6;
}
left [0] = left [1] = left [2] = left [3] = left [4] = left [5] = 0.0 ;
while (filter_index >= MAKE_INCREMENT_T (0))
{ fraction = fp_to_double (filter_index) ;
indx = fp_to_int (filter_index) ;
assert (indx >= 0 && indx + 1 < filter->coeff_half_len + 2) ;
icoeff = filter->coeffs [indx] + fraction * (filter->coeffs [indx + 1] - filter->coeffs [indx]) ;
assert (data_index >= 0 && data_index + 5 < filter->b_len) ;
assert (data_index + 5 < filter->b_end) ;
for (int ch = 0; ch < 6; ch++)
left [ch] += icoeff * filter->buffer [data_index + ch] ;
filter_index -= increment ;
data_index = data_index + 6 ;
} ;
/* Now apply the right half of the filter. */
filter_index = increment - start_filter_index ;
coeff_count = (max_filter_index - filter_index) / increment ;
filter_index = filter_index + coeff_count * increment ;
data_index = filter->b_current + channels * (1 + coeff_count) ;
right [0] = right [1] = right [2] = right [3] = right [4] = right [5] = 0.0 ;
do
{ fraction = fp_to_double (filter_index) ;
indx = fp_to_int (filter_index) ;
assert (indx >= 0 && indx + 1 < filter->coeff_half_len + 2) ;
icoeff = filter->coeffs [indx] + fraction * (filter->coeffs [indx + 1] - filter->coeffs [indx]) ;
assert (data_index >= 0 && data_index + 5 < filter->b_len) ;
assert (data_index + 5 < filter->b_end) ;
for (int ch = 0; ch < 6; ch++)
right [ch] += icoeff * filter->buffer [data_index + ch] ;
filter_index -= increment ;
data_index = data_index - 6 ;
}
while (filter_index > MAKE_INCREMENT_T (0)) ;
for (int ch = 0; ch < 6; ch++)
output [ch] = (float) (scale * (left [ch] + right [ch])) ;
} /* calc_output_hex */
SRC_ERROR
sinc_hex_vari_process (SRC_STATE *state, SRC_DATA *data)
{ SINC_FILTER *filter ;
double input_index, src_ratio, count, float_increment, terminate, rem ;
increment_t increment, start_filter_index ;
int half_filter_chan_len, samples_in_hand ;
if (state->private_data == NULL)
return SRC_ERR_NO_PRIVATE ;
filter = (SINC_FILTER*) state->private_data ;
/* If there is not a problem, this will be optimised out. */
if (sizeof (filter->buffer [0]) != sizeof (data->data_in [0]))
return SRC_ERR_SIZE_INCOMPATIBILITY ;
filter->in_count = data->input_frames * state->channels ;
filter->out_count = data->output_frames * state->channels ;
filter->in_used = filter->out_gen = 0 ;
src_ratio = state->last_ratio ;
if (is_bad_src_ratio (src_ratio))
return SRC_ERR_BAD_INTERNAL_STATE ;
/* Check the sample rate ratio wrt the buffer len. */
count = (filter->coeff_half_len + 2.0) / filter->index_inc ;
if (MIN (state->last_ratio, data->src_ratio) < 1.0)
count /= MIN (state->last_ratio, data->src_ratio) ;
/* Maximum coefficientson either side of center point. */
half_filter_chan_len = state->channels * (int) (psf_lrint (count) + 1) ;
input_index = state->last_position ;
rem = fmod_one (input_index) ;
filter->b_current = (filter->b_current + state->channels * psf_lrint (input_index - rem)) % filter->b_len ;
input_index = rem ;
terminate = 1.0 / src_ratio + 1e-20 ;
/* Main processing loop. */
while (filter->out_gen < filter->out_count)
{
/* Need to reload buffer? */
samples_in_hand = (filter->b_end - filter->b_current + filter->b_len) % filter->b_len ;
if (samples_in_hand <= half_filter_chan_len)
{ if ((state->error = prepare_data (filter, state->channels, data, half_filter_chan_len)) != 0)
return state->error ;
samples_in_hand = (filter->b_end - filter->b_current + filter->b_len) % filter->b_len ;
if (samples_in_hand <= half_filter_chan_len)
break ;
} ;
/* This is the termination condition. */
if (filter->b_real_end >= 0)
{ if (filter->b_current + input_index + terminate >= filter->b_real_end)
break ;
} ;
if (filter->out_count > 0 && fabs (state->last_ratio - data->src_ratio) > 1e-10)
src_ratio = state->last_ratio + filter->out_gen * (data->src_ratio - state->last_ratio) / filter->out_count ;
float_increment = filter->index_inc * (src_ratio < 1.0 ? src_ratio : 1.0) ;
increment = double_to_fp (float_increment) ;
start_filter_index = double_to_fp (input_index * float_increment) ;
calc_output_hex (filter, state->channels, increment, start_filter_index, float_increment / filter->index_inc, data->data_out + filter->out_gen) ;
filter->out_gen += 6 ;
/* Figure out the next index. */
input_index += 1.0 / src_ratio ;
rem = fmod_one (input_index) ;
filter->b_current = (filter->b_current + state->channels * psf_lrint (input_index - rem)) % filter->b_len ;
input_index = rem ;
} ;
state->last_position = input_index ;
/* Save current ratio rather then target ratio. */
state->last_ratio = src_ratio ;
data->input_frames_used = filter->in_used / state->channels ;
data->output_frames_gen = filter->out_gen / state->channels ;
return SRC_ERR_NO_ERROR ;
} /* sinc_hex_vari_process */
static inline void
calc_output_multi (SINC_FILTER *filter, increment_t increment, increment_t start_filter_index, int channels, double scale, float * output)
{ double fraction, icoeff ;
/* The following line is 1999 ISO Standard C. If your compiler complains, get a better compiler. */
double *left, *right ;
increment_t filter_index, max_filter_index ;
int data_index, coeff_count, indx ;
left = filter->left_calc ;
right = filter->right_calc ;
/* Convert input parameters into fixed point. */
max_filter_index = int_to_fp (filter->coeff_half_len) ;
/* First apply the left half of the filter. */
filter_index = start_filter_index ;
coeff_count = (max_filter_index - filter_index) / increment ;
filter_index = filter_index + coeff_count * increment ;
data_index = filter->b_current - channels * coeff_count ;
if (data_index < 0) /* Avoid underflow access to filter->buffer. */
{ int steps = int_div_ceil (-data_index, channels) ;
/* If the assert triggers we would have to take care not to underflow/overflow */
assert (steps <= int_div_ceil (filter_index, increment)) ;
filter_index -= increment * steps ;
data_index += steps * channels ;
}
memset (left, 0, sizeof (left [0]) * channels) ;
while (filter_index >= MAKE_INCREMENT_T (0))
{ fraction = fp_to_double (filter_index) ;
indx = fp_to_int (filter_index) ;
assert (indx >= 0 && indx + 1 < filter->coeff_half_len + 2) ;
icoeff = filter->coeffs [indx] + fraction * (filter->coeffs [indx + 1] - filter->coeffs [indx]) ;
assert (data_index >= 0 && data_index + channels - 1 < filter->b_len) ;
assert (data_index + channels - 1 < filter->b_end) ;
for (int ch = 0; ch < channels; ch++)
left [ch] += icoeff * filter->buffer [data_index + ch] ;
filter_index -= increment ;
data_index = data_index + channels ;
} ;
/* Now apply the right half of the filter. */
filter_index = increment - start_filter_index ;
coeff_count = (max_filter_index - filter_index) / increment ;
filter_index = filter_index + coeff_count * increment ;
data_index = filter->b_current + channels * (1 + coeff_count) ;
memset (right, 0, sizeof (right [0]) * channels) ;
do
{ fraction = fp_to_double (filter_index) ;
indx = fp_to_int (filter_index) ;
assert (indx >= 0 && indx + 1 < filter->coeff_half_len + 2) ;
icoeff = filter->coeffs [indx] + fraction * (filter->coeffs [indx + 1] - filter->coeffs [indx]) ;
assert (data_index >= 0 && data_index + channels - 1 < filter->b_len) ;
assert (data_index + channels - 1 < filter->b_end) ;
for (int ch = 0; ch < channels; ch++)
right [ch] += icoeff * filter->buffer [data_index + ch] ;
filter_index -= increment ;
data_index = data_index - channels ;
}
while (filter_index > MAKE_INCREMENT_T (0)) ;
for(int ch = 0; ch < channels; ch++)
output [ch] = (float) (scale * (left [ch] + right [ch])) ;
return ;
} /* calc_output_multi */
static SRC_ERROR
sinc_multichan_vari_process (SRC_STATE *state, SRC_DATA *data)
{ SINC_FILTER *filter ;
double input_index, src_ratio, count, float_increment, terminate, rem ;
increment_t increment, start_filter_index ;
int half_filter_chan_len, samples_in_hand ;
if (state->private_data == NULL)
return SRC_ERR_NO_PRIVATE ;
filter = (SINC_FILTER*) state->private_data ;
/* If there is not a problem, this will be optimised out. */
if (sizeof (filter->buffer [0]) != sizeof (data->data_in [0]))
return SRC_ERR_SIZE_INCOMPATIBILITY ;
filter->in_count = data->input_frames * state->channels ;
filter->out_count = data->output_frames * state->channels ;
filter->in_used = filter->out_gen = 0 ;
src_ratio = state->last_ratio ;
if (is_bad_src_ratio (src_ratio))
return SRC_ERR_BAD_INTERNAL_STATE ;
/* Check the sample rate ratio wrt the buffer len. */
count = (filter->coeff_half_len + 2.0) / filter->index_inc ;
if (MIN (state->last_ratio, data->src_ratio) < 1.0)
count /= MIN (state->last_ratio, data->src_ratio) ;
/* Maximum coefficientson either side of center point. */
half_filter_chan_len = state->channels * (int) (psf_lrint (count) + 1) ;
input_index = state->last_position ;
rem = fmod_one (input_index) ;
filter->b_current = (filter->b_current + state->channels * psf_lrint (input_index - rem)) % filter->b_len ;
input_index = rem ;
terminate = 1.0 / src_ratio + 1e-20 ;
/* Main processing loop. */
while (filter->out_gen < filter->out_count)
{
/* Need to reload buffer? */
samples_in_hand = (filter->b_end - filter->b_current + filter->b_len) % filter->b_len ;
if (samples_in_hand <= half_filter_chan_len)
{ if ((state->error = prepare_data (filter, state->channels, data, half_filter_chan_len)) != 0)
return state->error ;
samples_in_hand = (filter->b_end - filter->b_current + filter->b_len) % filter->b_len ;
if (samples_in_hand <= half_filter_chan_len)
break ;
} ;
/* This is the termination condition. */
if (filter->b_real_end >= 0)
{ if (filter->b_current + input_index + terminate >= filter->b_real_end)
break ;
} ;
if (filter->out_count > 0 && fabs (state->last_ratio - data->src_ratio) > 1e-10)
src_ratio = state->last_ratio + filter->out_gen * (data->src_ratio - state->last_ratio) / filter->out_count ;
float_increment = filter->index_inc * (src_ratio < 1.0 ? src_ratio : 1.0) ;
increment = double_to_fp (float_increment) ;
start_filter_index = double_to_fp (input_index * float_increment) ;
calc_output_multi (filter, increment, start_filter_index, state->channels, float_increment / filter->index_inc, data->data_out + filter->out_gen) ;
filter->out_gen += state->channels ;
/* Figure out the next index. */
input_index += 1.0 / src_ratio ;
rem = fmod_one (input_index) ;
filter->b_current = (filter->b_current + state->channels * psf_lrint (input_index - rem)) % filter->b_len ;
input_index = rem ;
} ;
state->last_position = input_index ;
/* Save current ratio rather then target ratio. */
state->last_ratio = src_ratio ;
data->input_frames_used = filter->in_used / state->channels ;
data->output_frames_gen = filter->out_gen / state->channels ;
return SRC_ERR_NO_ERROR ;
} /* sinc_multichan_vari_process */
/*----------------------------------------------------------------------------------------
*/
static SRC_ERROR
prepare_data (SINC_FILTER *filter, int channels, SRC_DATA *data, int half_filter_chan_len)
{ int len = 0 ;
if (filter->b_real_end >= 0)
return SRC_ERR_NO_ERROR ; /* Should be terminating. Just return. */
if (data->data_in == NULL)
return SRC_ERR_NO_ERROR ;
if (filter->b_current == 0)
{ /* Initial state. Set up zeros at the start of the buffer and
** then load new data after that.
*/
len = filter->b_len - 2 * half_filter_chan_len ;
filter->b_current = filter->b_end = half_filter_chan_len ;
}
else if (filter->b_end + half_filter_chan_len + channels < filter->b_len)
{ /* Load data at current end position. */
len = MAX (filter->b_len - filter->b_current - half_filter_chan_len, 0) ;
}
else
{ /* Move data at end of buffer back to the start of the buffer. */
len = filter->b_end - filter->b_current ;
memmove (filter->buffer, filter->buffer + filter->b_current - half_filter_chan_len,
(half_filter_chan_len + len) * sizeof (filter->buffer [0])) ;
filter->b_current = half_filter_chan_len ;
filter->b_end = filter->b_current + len ;
/* Now load data at current end of buffer. */
len = MAX (filter->b_len - filter->b_current - half_filter_chan_len, 0) ;
} ;
len = MIN ((int) (filter->in_count - filter->in_used), len) ;
len -= (len % channels) ;
if (len < 0 || filter->b_end + len > filter->b_len)
return SRC_ERR_SINC_PREPARE_DATA_BAD_LEN ;
memcpy (filter->buffer + filter->b_end, data->data_in + filter->in_used,
len * sizeof (filter->buffer [0])) ;
filter->b_end += len ;
filter->in_used += len ;
if (filter->in_used == filter->in_count &&
filter->b_end - filter->b_current < 2 * half_filter_chan_len && data->end_of_input)
{ /* Handle the case where all data in the current buffer has been
** consumed and this is the last buffer.
*/
if (filter->b_len - filter->b_end < half_filter_chan_len + 5)
{ /* If necessary, move data down to the start of the buffer. */
len = filter->b_end - filter->b_current ;
memmove (filter->buffer, filter->buffer + filter->b_current - half_filter_chan_len,
(half_filter_chan_len + len) * sizeof (filter->buffer [0])) ;
filter->b_current = half_filter_chan_len ;
filter->b_end = filter->b_current + len ;
} ;
filter->b_real_end = filter->b_end ;
len = half_filter_chan_len + 5 ;
if (len < 0 || filter->b_end + len > filter->b_len)
len = filter->b_len - filter->b_end ;
memset (filter->buffer + filter->b_end, 0, len * sizeof (filter->buffer [0])) ;
filter->b_end += len ;
} ;
return SRC_ERR_NO_ERROR ;
} /* prepare_data */
static void
sinc_close (SRC_STATE *state)
{
if (state)
{
SINC_FILTER *sinc = (SINC_FILTER *) state->private_data ;
if (sinc)
{
if (sinc->buffer)
{
free (sinc->buffer) ;
sinc->buffer = NULL ;
}
free (sinc) ;
sinc = NULL ;
}
free (state) ;
state = NULL ;
}
} /* sinc_close */
|
0f95efd9bdc9c1d395cb62236a572b500be43e09
|
2a70a8b7b82ab266d7b130a07daf117143d0e2ab
|
/ini/Tools/tsidmove/stdafx.h
|
df0c9804352127854d7c95256efa2758b2912387
|
[
"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
| 80
|
h
|
stdafx.h
|
#pragma once
#include <sdkddkver.h>
#include "../../../Common/Common.h"
|
309fc74a4b2fdbd197fb8cf5030a13d594013f6e
|
68e115d504decf90cf8adaf1c373a220c059d8d7
|
/Driver/SpmiDxe/Driver.c
|
f5e08f049d247ebc8963ce7e9988f5fdb5ee45ca
|
[
"GPL-1.0-or-later",
"GPL-2.0-only",
"BSD-2-Clause"
] |
permissive
|
WOA-Project/Lumia950XLPkg
|
24fcad187d71488270b853d08fcdff542bbac5a2
|
0e7e24adb2ac80672ade1e56f9b538d99941328f
|
refs/heads/master
| 2023-08-11T09:20:00.600571
| 2022-09-14T09:09:51
| 2022-09-14T09:09:51
| 132,070,715
| 264
| 64
|
BSD-2-Clause
| 2022-12-18T20:27:21
| 2018-05-04T01:44:48
|
C
|
UTF-8
|
C
| false
| false
| 460
|
c
|
Driver.c
|
#include <PiDxe.h>
#include <Library/LKEnvLib.h>
#include <Library/QcomSpmiLib.h>
#include <Library/UefiBootServicesTableLib.h>
EFI_STATUS
EFIAPI
SpmiDxeInitialize(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
{
EFI_HANDLE Handle = NULL;
EFI_STATUS Status;
SpmiImplLibInitialize();
Status = gBS->InstallMultipleProtocolInterfaces(
&Handle, &gQcomSpmiProtocolGuid, gSpmi, NULL);
ASSERT_EFI_ERROR(Status);
return Status;
}
|
2698183f7beb3f7ffc4b94c1c6bae7d8e3614b7e
|
28d0f8c01599f8f6c711bdde0b59f9c2cd221203
|
/sys/dev/i2c/sgsmix.c
|
d6a50b24634f924efef124ed2310eb6134203dee
|
[] |
no_license
|
NetBSD/src
|
1a9cbc22ed778be638b37869ed4fb5c8dd616166
|
23ee83f7c0aea0777bd89d8ebd7f0cde9880d13c
|
refs/heads/trunk
| 2023-08-31T13:24:58.105962
| 2023-08-27T15:50:47
| 2023-08-27T15:50:47
| 88,439,547
| 656
| 348
| null | 2023-07-20T20:07:24
| 2017-04-16T20:03:43
| null |
UTF-8
|
C
| false
| false
| 5,837
|
c
|
sgsmix.c
|
/* $NetBSD: sgsmix.c,v 1.10 2021/01/30 01:23:08 thorpej Exp $ */
/*-
* Copyright (C) 2005 Michael Lorenz.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* a driver for the SGS TDA7433 mixer chip found in Beige PowerMac G3 and
* probably others
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: sgsmix.c,v 1.10 2021/01/30 01:23:08 thorpej Exp $");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/device.h>
#include <sys/malloc.h>
#include <sys/sysctl.h>
#include <dev/i2c/i2cvar.h>
#include <dev/i2c/sgsmixvar.h>
#include "opt_sgsmix.h"
#ifdef SGSMIX_DEBUG
#define DPRINTF printf
#else
#define DPRINTF while (0) printf
#endif
struct sgsmix_softc {
device_t sc_dev;
device_t sc_parent;
i2c_tag_t sc_i2c;
int sc_node, sc_address;
uint8_t sc_regs[7];
};
#define SGSREG_INPUT_SELECT 0
#define SGSREG_MASTER_GAIN 1
#define SGSREG_BASS_TREBLE 2
#define SGSREG_SPEAKER_L 3
#define SGSREG_HEADPHONES_L 4
#define SGSREG_SPEAKER_R 5
#define SGSREG_HEADPHONES_R 6
static void sgsmix_attach(device_t, device_t, void *);
static int sgsmix_match(device_t, cfdata_t, void *);
static void sgsmix_setup(struct sgsmix_softc *);
static void sgsmix_writereg(struct sgsmix_softc *, int, uint8_t);
CFATTACH_DECL_NEW(sgsmix, sizeof(struct sgsmix_softc),
sgsmix_match, sgsmix_attach, NULL, NULL);
static const struct device_compatible_entry compat_data[] = {
{ .compat = "st,tda7433" },
DEVICE_COMPAT_EOL
};
static int
sgsmix_match(device_t parent, cfdata_t cf, void *aux)
{
struct i2c_attach_args *args = aux;
int ret = -1;
uint8_t out[2] = {1, 0x20};
int match_result;
if (iic_use_direct_match(args, cf, compat_data, &match_result))
return match_result;
/* see if we can talk to something at address 0x8a */
if (args->ia_addr != 0x8a)
return 0;
iic_acquire_bus(args->ia_tag, 0);
ret = iic_exec(args->ia_tag, I2C_OP_WRITE, args->ia_addr,
out, 2, NULL, 0, 0);
iic_release_bus(args->ia_tag, 0);
return (ret >= 0) ? I2C_MATCH_ADDRESS_AND_PROBE : 0;
}
static void
sgsmix_attach(device_t parent, device_t self, void *aux)
{
struct sgsmix_softc *sc = device_private(self);
struct i2c_attach_args *args = aux;
sc->sc_dev = self;
sc->sc_parent = parent;
sc->sc_address = args->ia_addr;
aprint_normal(": SGS TDA7433 Basic Audio Processor\n");
sc->sc_i2c = args->ia_tag;
sgsmix_setup(sc);
}
static void
sgsmix_setup(struct sgsmix_softc *sc)
{
int i;
uint8_t out[2];
sc->sc_regs[0] = 9; /* input 1 */
sc->sc_regs[1] = 0x20; /* master gain 0dB */
sc->sc_regs[2] = 0x77; /* flat bass / treble */
sc->sc_regs[3] = 0; /* all speakers full volume */
sc->sc_regs[4] = 0;
sc->sc_regs[5] = 0;
sc->sc_regs[6] = 0;
iic_acquire_bus(sc->sc_i2c, 0);
for (i = 0; i < 7; i++) {
out[0] = i;
out[1] = sc->sc_regs[i];
iic_exec(sc->sc_i2c, I2C_OP_WRITE, sc->sc_address, out, 2,
NULL, 0, 0);
}
iic_release_bus(sc->sc_i2c, 0);
}
static void
sgsmix_writereg(struct sgsmix_softc *sc, int reg, uint8_t val)
{
uint8_t out[2] = {reg, val};
if ((reg < 0) || (reg >= 7))
return;
if (sc->sc_regs[reg] == val)
return;
if (iic_exec(sc->sc_i2c, I2C_OP_WRITE, sc->sc_address, out, 2, NULL,
0, 0) == 0) {
sc->sc_regs[reg] = val;
}
}
void
sgsmix_set_speaker_vol(void *cookie, int left, int right)
{
struct sgsmix_softc *sc = device_private((device_t)cookie);
DPRINTF("%s: speaker %d %d\n", device_xname(sc->sc_dev), left, right);
if (left == 0) {
sgsmix_writereg(sc, SGSREG_SPEAKER_L, 0x20);
} else {
sgsmix_writereg(sc, SGSREG_SPEAKER_L,
((255 - left) >> 3) & 0x1f);
}
if (right == 0) {
sgsmix_writereg(sc, SGSREG_SPEAKER_R, 0x20);
} else {
sgsmix_writereg(sc, SGSREG_SPEAKER_R,
((255 - right) >> 3) & 0x1f);
}
}
void
sgsmix_set_headphone_vol(void *cookie, int left, int right)
{
struct sgsmix_softc *sc = device_private((device_t)cookie);
DPRINTF("%s: headphones %d %d\n", device_xname(sc->sc_dev), left, right);
if (left == 0) {
sgsmix_writereg(sc, SGSREG_HEADPHONES_L, 0x20);
} else {
sgsmix_writereg(sc, SGSREG_HEADPHONES_L,
((255 - left) >> 3) & 0x1f);
}
if (right == 0) {
sgsmix_writereg(sc, SGSREG_HEADPHONES_R, 0x20);
} else {
sgsmix_writereg(sc, SGSREG_HEADPHONES_R,
((255 - right) >> 3) & 0x1f);
}
}
void
sgsmix_set_bass_treble(void *cookie, int bass, int treble)
{
struct sgsmix_softc *sc = device_private((device_t)cookie);
uint8_t b, t;
t = (treble >> 4) & 0xf;
if (t & 0x8)
t ^= 7;
b = bass & 0xf0;
if (b & 0x80)
b ^= 0x70;
DPRINTF("%s: bass/treble %02x %02x\n", device_xname(sc->sc_dev), b, t);
sgsmix_writereg(sc, SGSREG_BASS_TREBLE, b | t);
}
|
fbef0354dd7bcbac7da0b15a3edd9b61fb0b97bc
|
e69d771800a1f58cc8933f27fd289e7383454c19
|
/code/apps/examples/build-test-nomath.c
|
dca840abfb54b6e4130b3e80f750db1ec79d12b1
|
[
"BSD-3-Clause",
"Unlicense",
"LicenseRef-scancode-unknown-license-reference"
] |
permissive
|
zpl-c/zpl
|
14436d45ec19b206ead913f859071ecd2d52c0e1
|
f9fd92383670706dca27f372c05541a1dcbe09eb
|
refs/heads/master
| 2023-07-26T12:18:19.853108
| 2023-07-24T10:18:23
| 2023-07-24T10:18:23
| 96,797,726
| 974
| 48
|
NOASSERTION
| 2023-07-24T09:39:26
| 2017-07-10T16:17:42
|
C
|
UTF-8
|
C
| false
| false
| 96
|
c
|
build-test-nomath.c
|
#define ZPL_IMPLEMENTATION
#define ZPL_NO_MATH_H
#include <zpl.h>
int main() {
return 0;
}
|
74a0b83bafec8a2381c8140d041fde229ad3570f
|
28d0f8c01599f8f6c711bdde0b59f9c2cd221203
|
/sys/stand/efiboot/efiboot.h
|
4f5cf58b132aaf42370747f339521b0ac88c9fba
|
[] |
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,178
|
h
|
efiboot.h
|
/* $NetBSD: efiboot.h,v 1.20 2022/08/14 11:26:41 jmcneill Exp $ */
/*-
* Copyright (c) 2016 Kimihiro Nonaka <nonaka@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 REGENTS 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 REGENTS 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 <efi.h>
#include <efilib.h>
#include <lib/libsa/stand.h>
#include <lib/libkern/libkern.h>
#include <loadfile.h>
#include <net.h>
#include "efiboot_machdep.h"
struct boot_command {
const char *c_name;
void (*c_fn)(char *);
const char *c_help;
};
int arch_prepare_boot(const char *, const char *, u_long *);
void arch_cleanup_boot(void);
size_t arch_alloc_size(void);
void arch_set_virtual_address_map(EFI_MEMORY_DESCRIPTOR *, UINTN, UINTN, UINTN, UINT32);
/* conf.c */
extern struct fs_ops null_fs_ops;
extern struct fs_ops tftp_fs_ops;
extern struct fs_ops nfs_fs_ops;
/* boot.c */
void boot(void);
void clearit(void);
extern const struct boot_command commands[];
void command_help(char *);
void command_printtab(const char *, const char *, ...);
int set_default_device(const char *);
char *get_default_device(void);
void set_default_fstype(int);
int get_default_fstype(void);
int set_initrd_path(const char *);
char *get_initrd_path(void);
int set_dtb_path(const char *);
char *get_dtb_path(void);
int set_rndseed_path(const char *);
char *get_rndseed_path(void);
/* console.c */
int ischar(void);
/* efiboot.c */
extern EFI_HANDLE IH;
extern EFI_DEVICE_PATH *efi_bootdp;
extern EFI_LOADED_IMAGE *efi_li;
void efi_cleanup(void);
void efi_exit(void);
void efi_delay(int);
void efi_reboot(void);
void efi_progress(const char *, ...);
extern int howto;
/* efichar.c */
size_t ucs2len(const CHAR16 *);
int ucs2_to_utf8(const CHAR16 *, char **);
int utf8_to_ucs2(const char *, CHAR16 **, size_t *);
/* efidev.c */
int efi_device_path_depth(EFI_DEVICE_PATH *, int);
int efi_device_path_count(EFI_DEVICE_PATH *);
int efi_device_path_ncmp(EFI_DEVICE_PATH *, EFI_DEVICE_PATH *, int);
/* efinet.c */
struct efi_net_if {
const char *if_name;
uint8_t if_mac[6];
};
int efi_net_open(struct open_file *, ...);
void efi_net_probe(void);
void efi_net_show(void);
int efi_net_get_booted_interface_unit(void);
int efi_net_get_booted_macaddr(uint8_t *);
extern struct netif_driver efinetif;
/* efipxe.c */
void efi_pxe_probe(void);
bool efi_pxe_match_booted_interface(const EFI_MAC_ADDRESS *, UINT32);
/* efiwatchdog.c */
void efi_set_watchdog(uint32_t, uint64_t);
/* efigop.c */
void efi_gop_probe(void);
void efi_gop_show(void);
void efi_gop_dump(void);
void efi_gop_setmode(UINT32);
/* exec.c */
int load_file(const char *, u_long, bool, EFI_PHYSICAL_ADDRESS *, u_long *);
int exec_netbsd(const char *, const char *);
/* panic.c */
__dead VOID Panic(IN CHAR16 *, ...);
__dead void reboot(void);
/* prompt.c */
char *gettrailer(char *);
void docommand(char *);
char awaitkey(int, int);
__dead void bootprompt(void);
/* userconf.c */
void userconf_add(const char *);
void userconf_foreach(void (*)(const char *));
|
92b7f1ef2833e6b6c2f3c6f9fc7f9aea682759d7
|
e73547787354afd9b717ea57fe8dd0695d161821
|
/src/battle/area/dig/script/dig_02.c
|
b86357184385ddc79661213e810b2bb9fcab49a5
|
[] |
no_license
|
pmret/papermario
|
8b514b19653cef8d6145e47499b3636b8c474a37
|
9774b26d93f1045dd2a67e502b6efc9599fb6c31
|
refs/heads/main
| 2023-08-31T07:09:48.951514
| 2023-08-21T18:07:08
| 2023-08-21T18:07:08
| 287,151,133
| 904
| 139
| null | 2023-09-14T02:44:23
| 2020-08-13T01:22:57
|
C
|
UTF-8
|
C
| false
| false
| 1,316
|
c
|
dig_02.c
|
#include "../area.h"
#define NAMESPACE A(dig_02_script)
API_CALLABLE(N(SetupDemoPlayerMove)) {
BattleStatus* battleStatus = &gBattleStatus;
Actor* player = battleStatus->playerActor;
SelectableTarget* selectableTarget;
battleStatus->moveCategory = BTL_MENU_TYPE_JUMP;
battleStatus->selectedMoveID = MOVE_POWER_BOUNCE;
battleStatus->moveArgument = gCurrentEncounter.hitTier;
battleStatus->curTargetListFlags = gMoveTable[MOVE_POWER_BOUNCE].flags;
player_create_target_list(player);
player->selectedTargetIndex = 1;
selectableTarget = &player->targetData[player->targetIndexList[player->selectedTargetIndex]];
player->targetActorID = selectableTarget->actorID;
player->targetPartIndex = selectableTarget->partID;
return ApiStatus_DONE2;
}
EvtScript NAMESPACE = {
EVT_CALL(UseBattleCamPreset, BTL_CAM_DEFAULT)
EVT_CALL(MoveBattleCamOver, 1)
EVT_WAIT(3)
EVT_CALL(SetCamViewport, CAM_BATTLE, 29, 20, 262, 177)
EVT_CALL(EnableBattleStatusBar, FALSE)
EVT_CALL(WaitForState, BATTLE_STATE_PLAYER_MENU)
EVT_CALL(N(SetupDemoPlayerMove))
EVT_CALL(SetBattleState, BATTLE_STATE_PLAYER_MOVE)
EVT_WAIT(130)
EVT_LOOP(30)
EVT_CALL(SetCommandAutoSuccess, FALSE)
EVT_WAIT(1)
EVT_END_LOOP
EVT_RETURN
EVT_END
};
|
3c797fd0abc8b48b086216cd3c6484de727ddda2
|
7eaf54a78c9e2117247cb2ab6d3a0c20719ba700
|
/SOFTWARE/A64-TERES/linux-a64/arch/tile/include/hv/drv_xgbe_intf.h
|
2a20b266d94469d6329a7a41793ef15c07c53b2a
|
[
"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
| 22,751
|
h
|
drv_xgbe_intf.h
|
/*
* Copyright 2010 Tilera Corporation. All Rights Reserved.
*
* 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.
*
* 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, GOOD TITLE or
* NON INFRINGEMENT. See the GNU General Public License for
* more details.
*/
/**
* @file drv_xgbe_intf.h
* Interface to the hypervisor XGBE driver.
*/
#ifndef __DRV_XGBE_INTF_H__
#define __DRV_XGBE_INTF_H__
/**
* An object for forwarding VAs and PAs to the hypervisor.
* @ingroup types
*
* This allows the supervisor to specify a number of areas of memory to
* store packet buffers.
*/
typedef struct
{
/** The physical address of the memory. */
HV_PhysAddr pa;
/** Page table entry for the memory. This is only used to derive the
* memory's caching mode; the PA bits are ignored. */
HV_PTE pte;
/** The virtual address of the memory. */
HV_VirtAddr va;
/** Size (in bytes) of the memory area. */
int size;
}
netio_ipp_address_t;
/** The various pread/pwrite offsets into the hypervisor-level driver.
* @ingroup types
*/
typedef enum
{
/** Inform the Linux driver of the address of the NetIO arena memory.
* This offset is actually only used to convey information from netio
* to the Linux driver; it never makes it from there to the hypervisor.
* Write-only; takes a uint32_t specifying the VA address. */
NETIO_FIXED_ADDR = 0x5000000000000000ULL,
/** Inform the Linux driver of the size of the NetIO arena memory.
* This offset is actually only used to convey information from netio
* to the Linux driver; it never makes it from there to the hypervisor.
* Write-only; takes a uint32_t specifying the VA size. */
NETIO_FIXED_SIZE = 0x5100000000000000ULL,
/** Register current tile with IPP. Write then read: write, takes a
* netio_input_config_t, read returns a pointer to a netio_queue_impl_t. */
NETIO_IPP_INPUT_REGISTER_OFF = 0x6000000000000000ULL,
/** Unregister current tile from IPP. Write-only, takes a dummy argument. */
NETIO_IPP_INPUT_UNREGISTER_OFF = 0x6100000000000000ULL,
/** Start packets flowing. Write-only, takes a dummy argument. */
NETIO_IPP_INPUT_INIT_OFF = 0x6200000000000000ULL,
/** Stop packets flowing. Write-only, takes a dummy argument. */
NETIO_IPP_INPUT_UNINIT_OFF = 0x6300000000000000ULL,
/** Configure group (typically we group on VLAN). Write-only: takes an
* array of netio_group_t's, low 24 bits of the offset is the base group
* number times the size of a netio_group_t. */
NETIO_IPP_INPUT_GROUP_CFG_OFF = 0x6400000000000000ULL,
/** Configure bucket. Write-only: takes an array of netio_bucket_t's, low
* 24 bits of the offset is the base bucket number times the size of a
* netio_bucket_t. */
NETIO_IPP_INPUT_BUCKET_CFG_OFF = 0x6500000000000000ULL,
/** Get/set a parameter. Read or write: read or write data is the parameter
* value, low 32 bits of the offset is a __netio_getset_offset_t. */
NETIO_IPP_PARAM_OFF = 0x6600000000000000ULL,
/** Get fast I/O index. Read-only; returns a 4-byte base index value. */
NETIO_IPP_GET_FASTIO_OFF = 0x6700000000000000ULL,
/** Configure hijack IP address. Packets with this IPv4 dest address
* go to bucket NETIO_NUM_BUCKETS - 1. Write-only: takes an IP address
* in some standard form. FIXME: Define the form! */
NETIO_IPP_INPUT_HIJACK_CFG_OFF = 0x6800000000000000ULL,
/**
* Offsets beyond this point are reserved for the supervisor (although that
* enforcement must be done by the supervisor driver itself).
*/
NETIO_IPP_USER_MAX_OFF = 0x6FFFFFFFFFFFFFFFULL,
/** Register I/O memory. Write-only, takes a netio_ipp_address_t. */
NETIO_IPP_IOMEM_REGISTER_OFF = 0x7000000000000000ULL,
/** Unregister I/O memory. Write-only, takes a netio_ipp_address_t. */
NETIO_IPP_IOMEM_UNREGISTER_OFF = 0x7100000000000000ULL,
/* Offsets greater than 0x7FFFFFFF can't be used directly from Linux
* userspace code due to limitations in the pread/pwrite syscalls. */
/** Drain LIPP buffers. */
NETIO_IPP_DRAIN_OFF = 0xFA00000000000000ULL,
/** Supply a netio_ipp_address_t to be used as shared memory for the
* LEPP command queue. */
NETIO_EPP_SHM_OFF = 0xFB00000000000000ULL,
/* 0xFC... is currently unused. */
/** Stop IPP/EPP tiles. Write-only, takes a dummy argument. */
NETIO_IPP_STOP_SHIM_OFF = 0xFD00000000000000ULL,
/** Start IPP/EPP tiles. Write-only, takes a dummy argument. */
NETIO_IPP_START_SHIM_OFF = 0xFE00000000000000ULL,
/** Supply packet arena. Write-only, takes an array of
* netio_ipp_address_t values. */
NETIO_IPP_ADDRESS_OFF = 0xFF00000000000000ULL,
} netio_hv_offset_t;
/** Extract the base offset from an offset */
#define NETIO_BASE_OFFSET(off) ((off) & 0xFF00000000000000ULL)
/** Extract the local offset from an offset */
#define NETIO_LOCAL_OFFSET(off) ((off) & 0x00FFFFFFFFFFFFFFULL)
/**
* Get/set offset.
*/
typedef union
{
struct
{
uint64_t addr:48; /**< Class-specific address */
unsigned int class:8; /**< Class (e.g., NETIO_PARAM) */
unsigned int opcode:8; /**< High 8 bits of NETIO_IPP_PARAM_OFF */
}
bits; /**< Bitfields */
uint64_t word; /**< Aggregated value to use as the offset */
}
__netio_getset_offset_t;
/**
* Fast I/O index offsets (must be contiguous).
*/
typedef enum
{
NETIO_FASTIO_ALLOCATE = 0, /**< Get empty packet buffer */
NETIO_FASTIO_FREE_BUFFER = 1, /**< Give buffer back to IPP */
NETIO_FASTIO_RETURN_CREDITS = 2, /**< Give credits to IPP */
NETIO_FASTIO_SEND_PKT_NOCK = 3, /**< Send a packet, no checksum */
NETIO_FASTIO_SEND_PKT_CK = 4, /**< Send a packet, with checksum */
NETIO_FASTIO_SEND_PKT_VEC = 5, /**< Send a vector of packets */
NETIO_FASTIO_SENDV_PKT = 6, /**< Sendv one packet */
NETIO_FASTIO_NUM_INDEX = 7, /**< Total number of fast I/O indices */
} netio_fastio_index_t;
/** 3-word return type for Fast I/O call. */
typedef struct
{
int err; /**< Error code. */
uint32_t val0; /**< Value. Meaning depends upon the specific call. */
uint32_t val1; /**< Value. Meaning depends upon the specific call. */
} netio_fastio_rv3_t;
/** 0-argument fast I/O call */
int __netio_fastio0(uint32_t fastio_index);
/** 1-argument fast I/O call */
int __netio_fastio1(uint32_t fastio_index, uint32_t arg0);
/** 3-argument fast I/O call, 2-word return value */
netio_fastio_rv3_t __netio_fastio3_rv3(uint32_t fastio_index, uint32_t arg0,
uint32_t arg1, uint32_t arg2);
/** 4-argument fast I/O call */
int __netio_fastio4(uint32_t fastio_index, uint32_t arg0, uint32_t arg1,
uint32_t arg2, uint32_t arg3);
/** 6-argument fast I/O call */
int __netio_fastio6(uint32_t fastio_index, uint32_t arg0, uint32_t arg1,
uint32_t arg2, uint32_t arg3, uint32_t arg4, uint32_t arg5);
/** 9-argument fast I/O call */
int __netio_fastio9(uint32_t fastio_index, uint32_t arg0, uint32_t arg1,
uint32_t arg2, uint32_t arg3, uint32_t arg4, uint32_t arg5,
uint32_t arg6, uint32_t arg7, uint32_t arg8);
/** Allocate an empty packet.
* @param fastio_index Fast I/O index.
* @param size Size of the packet to allocate.
*/
#define __netio_fastio_allocate(fastio_index, size) \
__netio_fastio1((fastio_index) + NETIO_FASTIO_ALLOCATE, size)
/** Free a buffer.
* @param fastio_index Fast I/O index.
* @param handle Handle for the packet to free.
*/
#define __netio_fastio_free_buffer(fastio_index, handle) \
__netio_fastio1((fastio_index) + NETIO_FASTIO_FREE_BUFFER, handle)
/** Increment our receive credits.
* @param fastio_index Fast I/O index.
* @param credits Number of credits to add.
*/
#define __netio_fastio_return_credits(fastio_index, credits) \
__netio_fastio1((fastio_index) + NETIO_FASTIO_RETURN_CREDITS, credits)
/** Send packet, no checksum.
* @param fastio_index Fast I/O index.
* @param ackflag Nonzero if we want an ack.
* @param size Size of the packet.
* @param va Virtual address of start of packet.
* @param handle Packet handle.
*/
#define __netio_fastio_send_pkt_nock(fastio_index, ackflag, size, va, handle) \
__netio_fastio4((fastio_index) + NETIO_FASTIO_SEND_PKT_NOCK, ackflag, \
size, va, handle)
/** Send packet, calculate checksum.
* @param fastio_index Fast I/O index.
* @param ackflag Nonzero if we want an ack.
* @param size Size of the packet.
* @param va Virtual address of start of packet.
* @param handle Packet handle.
* @param csum0 Shim checksum header.
* @param csum1 Checksum seed.
*/
#define __netio_fastio_send_pkt_ck(fastio_index, ackflag, size, va, handle, \
csum0, csum1) \
__netio_fastio6((fastio_index) + NETIO_FASTIO_SEND_PKT_CK, ackflag, \
size, va, handle, csum0, csum1)
/** Format for the "csum0" argument to the __netio_fastio_send routines
* and LEPP. Note that this is currently exactly identical to the
* ShimProtocolOffloadHeader.
*/
typedef union
{
struct
{
unsigned int start_byte:7; /**< The first byte to be checksummed */
unsigned int count:14; /**< Number of bytes to be checksummed. */
unsigned int destination_byte:7; /**< The byte to write the checksum to. */
unsigned int reserved:4; /**< Reserved. */
} bits; /**< Decomposed method of access. */
unsigned int word; /**< To send out the IDN. */
} __netio_checksum_header_t;
/** Sendv packet with 1 or 2 segments.
* @param fastio_index Fast I/O index.
* @param flags Ack/csum/notify flags in low 3 bits; number of segments minus
* 1 in next 2 bits; expected checksum in high 16 bits.
* @param confno Confirmation number to request, if notify flag set.
* @param csum0 Checksum descriptor; if zero, no checksum.
* @param va_F Virtual address of first segment.
* @param va_L Virtual address of last segment, if 2 segments.
* @param len_F_L Length of first segment in low 16 bits; length of last
* segment, if 2 segments, in high 16 bits.
*/
#define __netio_fastio_sendv_pkt_1_2(fastio_index, flags, confno, csum0, \
va_F, va_L, len_F_L) \
__netio_fastio6((fastio_index) + NETIO_FASTIO_SENDV_PKT, flags, confno, \
csum0, va_F, va_L, len_F_L)
/** Send packet on PCIe interface.
* @param fastio_index Fast I/O index.
* @param flags Ack/csum/notify flags in low 3 bits.
* @param confno Confirmation number to request, if notify flag set.
* @param csum0 Checksum descriptor; Hard wired 0, not needed for PCIe.
* @param va_F Virtual address of the packet buffer.
* @param va_L Virtual address of last segment, if 2 segments. Hard wired 0.
* @param len_F_L Length of the packet buffer in low 16 bits.
*/
#define __netio_fastio_send_pcie_pkt(fastio_index, flags, confno, csum0, \
va_F, va_L, len_F_L) \
__netio_fastio6((fastio_index) + PCIE_FASTIO_SENDV_PKT, flags, confno, \
csum0, va_F, va_L, len_F_L)
/** Sendv packet with 3 or 4 segments.
* @param fastio_index Fast I/O index.
* @param flags Ack/csum/notify flags in low 3 bits; number of segments minus
* 1 in next 2 bits; expected checksum in high 16 bits.
* @param confno Confirmation number to request, if notify flag set.
* @param csum0 Checksum descriptor; if zero, no checksum.
* @param va_F Virtual address of first segment.
* @param va_L Virtual address of last segment (third segment if 3 segments,
* fourth segment if 4 segments).
* @param len_F_L Length of first segment in low 16 bits; length of last
* segment in high 16 bits.
* @param va_M0 Virtual address of "middle 0" segment; this segment is sent
* second when there are three segments, and third if there are four.
* @param va_M1 Virtual address of "middle 1" segment; this segment is sent
* second when there are four segments.
* @param len_M0_M1 Length of middle 0 segment in low 16 bits; length of middle
* 1 segment, if 4 segments, in high 16 bits.
*/
#define __netio_fastio_sendv_pkt_3_4(fastio_index, flags, confno, csum0, va_F, \
va_L, len_F_L, va_M0, va_M1, len_M0_M1) \
__netio_fastio9((fastio_index) + NETIO_FASTIO_SENDV_PKT, flags, confno, \
csum0, va_F, va_L, len_F_L, va_M0, va_M1, len_M0_M1)
/** Send vector of packets.
* @param fastio_index Fast I/O index.
* @param seqno Number of packets transmitted so far on this interface;
* used to decide which packets should be acknowledged.
* @param nentries Number of entries in vector.
* @param va Virtual address of start of vector entry array.
* @return 3-word netio_fastio_rv3_t structure. The structure's err member
* is an error code, or zero if no error. The val0 member is the
* updated value of seqno; it has been incremented by 1 for each
* packet sent. That increment may be less than nentries if an
* error occurred, or if some of the entries in the vector contain
* handles equal to NETIO_PKT_HANDLE_NONE. The val1 member is the
* updated value of nentries; it has been decremented by 1 for each
* vector entry processed. Again, that decrement may be less than
* nentries (leaving the returned value positive) if an error
* occurred.
*/
#define __netio_fastio_send_pkt_vec(fastio_index, seqno, nentries, va) \
__netio_fastio3_rv3((fastio_index) + NETIO_FASTIO_SEND_PKT_VEC, seqno, \
nentries, va)
/** An egress DMA command for LEPP. */
typedef struct
{
/** Is this a TSO transfer?
*
* NOTE: This field is always 0, to distinguish it from
* lepp_tso_cmd_t. It must come first!
*/
uint8_t tso : 1;
/** Unused padding bits. */
uint8_t _unused : 3;
/** Should this packet be sent directly from caches instead of DRAM,
* using hash-for-home to locate the packet data?
*/
uint8_t hash_for_home : 1;
/** Should we compute a checksum? */
uint8_t compute_checksum : 1;
/** Is this the final buffer for this packet?
*
* A single packet can be split over several input buffers (a "gather"
* operation). This flag indicates that this is the last buffer
* in a packet.
*/
uint8_t end_of_packet : 1;
/** Should LEPP advance 'comp_busy' when this DMA is fully finished? */
uint8_t send_completion : 1;
/** High bits of Client Physical Address of the start of the buffer
* to be egressed.
*
* NOTE: Only 6 bits are actually needed here, as CPAs are
* currently 38 bits. So two bits could be scavenged from this.
*/
uint8_t cpa_hi;
/** The number of bytes to be egressed. */
uint16_t length;
/** Low 32 bits of Client Physical Address of the start of the buffer
* to be egressed.
*/
uint32_t cpa_lo;
/** Checksum information (only used if 'compute_checksum'). */
__netio_checksum_header_t checksum_data;
} lepp_cmd_t;
/** A chunk of physical memory for a TSO egress. */
typedef struct
{
/** The low bits of the CPA. */
uint32_t cpa_lo;
/** The high bits of the CPA. */
uint16_t cpa_hi : 15;
/** Should this packet be sent directly from caches instead of DRAM,
* using hash-for-home to locate the packet data?
*/
uint16_t hash_for_home : 1;
/** The length in bytes. */
uint16_t length;
} lepp_frag_t;
/** An LEPP command that handles TSO. */
typedef struct
{
/** Is this a TSO transfer?
*
* NOTE: This field is always 1, to distinguish it from
* lepp_cmd_t. It must come first!
*/
uint8_t tso : 1;
/** Unused padding bits. */
uint8_t _unused : 7;
/** Size of the header[] array in bytes. It must be in the range
* [40, 127], which are the smallest header for a TCP packet over
* Ethernet and the maximum possible prepend size supported by
* hardware, respectively. Note that the array storage must be
* padded out to a multiple of four bytes so that the following
* LEPP command is aligned properly.
*/
uint8_t header_size;
/** Byte offset of the IP header in header[]. */
uint8_t ip_offset;
/** Byte offset of the TCP header in header[]. */
uint8_t tcp_offset;
/** The number of bytes to use for the payload of each packet,
* except of course the last one, which may not have enough bytes.
* This means that each Ethernet packet except the last will have a
* size of header_size + payload_size.
*/
uint16_t payload_size;
/** The length of the 'frags' array that follows this struct. */
uint16_t num_frags;
/** The actual frags. */
lepp_frag_t frags[0 /* Variable-sized; num_frags entries. */];
/*
* The packet header template logically follows frags[],
* but you can't declare that in C.
*
* uint32_t header[header_size_in_words_rounded_up];
*/
} lepp_tso_cmd_t;
/** An LEPP completion ring entry. */
typedef void* lepp_comp_t;
/** Maximum number of frags for one TSO command. This is adapted from
* linux's "MAX_SKB_FRAGS", and presumably over-estimates by one, for
* our page size of exactly 65536. We add one for a "body" fragment.
*/
#define LEPP_MAX_FRAGS (65536 / HV_DEFAULT_PAGE_SIZE_SMALL + 2 + 1)
/** Total number of bytes needed for an lepp_tso_cmd_t. */
#define LEPP_TSO_CMD_SIZE(num_frags, header_size) \
(sizeof(lepp_tso_cmd_t) + \
(num_frags) * sizeof(lepp_frag_t) + \
(((header_size) + 3) & -4))
/** The size of the lepp "cmd" queue. */
#define LEPP_CMD_QUEUE_BYTES \
(((CHIP_L2_CACHE_SIZE() - 2 * CHIP_L2_LINE_SIZE()) / \
(sizeof(lepp_cmd_t) + sizeof(lepp_comp_t))) * sizeof(lepp_cmd_t))
/** The largest possible command that can go in lepp_queue_t::cmds[]. */
#define LEPP_MAX_CMD_SIZE LEPP_TSO_CMD_SIZE(LEPP_MAX_FRAGS, 128)
/** The largest possible value of lepp_queue_t::cmd_{head, tail} (inclusive).
*/
#define LEPP_CMD_LIMIT \
(LEPP_CMD_QUEUE_BYTES - LEPP_MAX_CMD_SIZE)
/** The maximum number of completions in an LEPP queue. */
#define LEPP_COMP_QUEUE_SIZE \
((LEPP_CMD_LIMIT + sizeof(lepp_cmd_t) - 1) / sizeof(lepp_cmd_t))
/** Increment an index modulo the queue size. */
#define LEPP_QINC(var) \
(var = __insn_mnz(var - (LEPP_COMP_QUEUE_SIZE - 1), var + 1))
/** A queue used to convey egress commands from the client to LEPP. */
typedef struct
{
/** Index of first completion not yet processed by user code.
* If this is equal to comp_busy, there are no such completions.
*
* NOTE: This is only read/written by the user.
*/
unsigned int comp_head;
/** Index of first completion record not yet completed.
* If this is equal to comp_tail, there are no such completions.
* This index gets advanced (modulo LEPP_QUEUE_SIZE) whenever
* a command with the 'completion' bit set is finished.
*
* NOTE: This is only written by LEPP, only read by the user.
*/
volatile unsigned int comp_busy;
/** Index of the first empty slot in the completion ring.
* Entries from this up to but not including comp_head (in ring order)
* can be filled in with completion data.
*
* NOTE: This is only read/written by the user.
*/
unsigned int comp_tail;
/** Byte index of first command enqueued for LEPP but not yet processed.
*
* This is always divisible by sizeof(void*) and always <= LEPP_CMD_LIMIT.
*
* NOTE: LEPP advances this counter as soon as it no longer needs
* the cmds[] storage for this entry, but the transfer is not actually
* complete (i.e. the buffer pointed to by the command is no longer
* needed) until comp_busy advances.
*
* If this is equal to cmd_tail, the ring is empty.
*
* NOTE: This is only written by LEPP, only read by the user.
*/
volatile unsigned int cmd_head;
/** Byte index of first empty slot in the command ring. This field can
* be incremented up to but not equal to cmd_head (because that would
* mean the ring is empty).
*
* This is always divisible by sizeof(void*) and always <= LEPP_CMD_LIMIT.
*
* NOTE: This is read/written by the user, only read by LEPP.
*/
volatile unsigned int cmd_tail;
/** A ring of variable-sized egress DMA commands.
*
* NOTE: Only written by the user, only read by LEPP.
*/
char cmds[LEPP_CMD_QUEUE_BYTES]
__attribute__((aligned(CHIP_L2_LINE_SIZE())));
/** A ring of user completion data.
* NOTE: Only read/written by the user.
*/
lepp_comp_t comps[LEPP_COMP_QUEUE_SIZE]
__attribute__((aligned(CHIP_L2_LINE_SIZE())));
} lepp_queue_t;
/** An internal helper function for determining the number of entries
* available in a ring buffer, given that there is one sentinel.
*/
static inline unsigned int
_lepp_num_free_slots(unsigned int head, unsigned int tail)
{
/*
* One entry is reserved for use as a sentinel, to distinguish
* "empty" from "full". So we compute
* (head - tail - 1) % LEPP_QUEUE_SIZE, but without using a slow % operation.
*/
return (head - tail - 1) + ((head <= tail) ? LEPP_COMP_QUEUE_SIZE : 0);
}
/** Returns how many new comp entries can be enqueued. */
static inline unsigned int
lepp_num_free_comp_slots(const lepp_queue_t* q)
{
return _lepp_num_free_slots(q->comp_head, q->comp_tail);
}
static inline int
lepp_qsub(int v1, int v2)
{
int delta = v1 - v2;
return delta + ((delta >> 31) & LEPP_COMP_QUEUE_SIZE);
}
/** FIXME: Check this from linux, via a new "pwrite()" call. */
#define LIPP_VERSION 1
/** We use exactly two bytes of alignment padding. */
#define LIPP_PACKET_PADDING 2
/** The minimum size of a "small" buffer (including the padding). */
#define LIPP_SMALL_PACKET_SIZE 128
/*
* NOTE: The following two values should total to less than around
* 13582, to keep the total size used for "lipp_state_t" below 64K.
*/
/** The maximum number of "small" buffers.
* This is enough for 53 network cpus with 128 credits. Note that
* if these are exhausted, we will fall back to using large buffers.
*/
#define LIPP_SMALL_BUFFERS 6785
/** The maximum number of "large" buffers.
* This is enough for 53 network cpus with 128 credits.
*/
#define LIPP_LARGE_BUFFERS 6785
#endif /* __DRV_XGBE_INTF_H__ */
|
b4fa9065cd20ea993ef4f2205e759f1c7db3504c
|
90beaf6c9e091f5aaa40c3b24bff498a0ed5055a
|
/compiler/include/byteir/Dialect/Lace/LaceDialect.h
|
79a384419e9dff85fad765b2c470f9a2a3cadf8b
|
[
"Apache-2.0",
"NCSA",
"LicenseRef-scancode-generic-cla",
"LLVM-exception",
"BSD-2-Clause",
"MIT"
] |
permissive
|
bytedance/byteir
|
cf1d9bc27ec8e9f7ea92ff449cbedf470f90115c
|
0e7673074c9d9a299717bb3379cb774c9921f72c
|
refs/heads/main
| 2023-08-31T04:42:44.536710
| 2023-08-30T20:14:22
| 2023-08-30T20:14:22
| 598,267,148
| 208
| 16
|
NOASSERTION
| 2023-09-13T21:50:19
| 2023-02-06T18:51:31
|
MLIR
|
UTF-8
|
C
| false
| false
| 1,237
|
h
|
LaceDialect.h
|
//===- LaceDialect.h - MLIR Dialect for Mhlo Extension --------*--- C++ -*-===//
//
// Copyright 2022 ByteDance Ltd. and/or its affiliates. All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//===----------------------------------------------------------------------===//
#ifndef BYTEIR_DIALECT_LACE_LACEDIALECT_H
#define BYTEIR_DIALECT_LACE_LACEDIALECT_H
#include "mlir/IR/BuiltinTypes.h"
#include "mlir/Interfaces/SideEffectInterfaces.h"
#include "mlir/Interfaces/ViewLikeInterface.h"
#include "byteir/Dialect/Lace/LaceOpInterfaces.h.inc"
#include "byteir/Dialect/Lace/LaceOpsDialect.h.inc"
#define GET_OP_CLASSES
#include "byteir/Dialect/Lace/LaceOps.h.inc"
#endif // BYTEIR_DIALECT_LACE_LACEDIALECT_H
|
7ce310dda12bd0244a3189b6713286cbc3cb587f
|
5f86fc385c7dcfcb5b166cdea7c8b13057b8bb5f
|
/tests/sgx/wrfsbase/host/host.c
|
5dbdda5ddd3fcebd2c9927addfba7cf15cf913f8
|
[
"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,428
|
c
|
host.c
|
// Copyright (c) Open Enclave SDK contributors.
// Licensed under the MIT License.
#include <openenclave/host.h>
#include <openenclave/internal/error.h>
#include <openenclave/internal/tests.h>
#include <stdio.h>
#include "wrfsbase_u.h"
oe_enclave_t* enclave;
void host_dummy()
{
}
int main(int argc, const char* argv[])
{
oe_result_t result;
if (argc != 3)
{
fprintf(
stderr,
"Usage: %s ENCLAVE_PATH testname negative_test(boolean)\n",
argv[0]);
return 1;
}
const uint32_t flags = oe_get_create_flags();
int simulation_mode = 0;
int negative_test = atoi(argv[2]);
if (flags & OE_ENCLAVE_FLAG_SIMULATE)
simulation_mode = 1;
if ((result = oe_create_wrfsbase_enclave(
argv[1], OE_ENCLAVE_TYPE_SGX, flags, NULL, 0, &enclave)) != OE_OK)
oe_put_err("oe_create_enclave(): result=%u", result);
if (!negative_test)
{
result = enc_wrfsbase(enclave, simulation_mode, 0);
if (result != OE_OK)
oe_put_err("oe_call_enclave() failed: result=%u", result);
OE_TEST(oe_terminate_enclave(enclave) == OE_OK);
}
else
{
result = enc_wrfsbase(enclave, simulation_mode, 1);
if (result != OE_ENCLAVE_ABORTING)
oe_put_err("oe_call_enclave() failed: result=%u", result);
}
printf("=== passed all tests (wrfsbase)\n");
return 0;
}
|
0676cce7a326d1c9b027f6b17d711a9be63e798f
|
25146d3cc79fd1fbb6578d2c64249fdbd6bfac65
|
/certmanager/certverify.c
|
d4fe9fa2a5a436574159f26928fa5ef2f61b36b7
|
[] |
no_license
|
wolfSSL/wolfssl-examples
|
5bb55c47be03bf55dfa1552f6b391557b6b31d90
|
7d373b14fe9a4283f9d70818fafab8b5ff863de1
|
refs/heads/master
| 2023-08-17T07:09:39.061991
| 2023-08-15T15:13:27
| 2023-08-15T15:13:27
| 21,290,295
| 237
| 191
| null | 2023-09-12T22:57:33
| 2014-06-27T21:50:12
|
C
|
UTF-8
|
C
| false
| false
| 3,130
|
c
|
certverify.c
|
/* certverify.c
*
* Copyright (C) 2006-2018 wolfSSL Inc.
*
* This file is part of wolfSSL.
*
* wolfSSL 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.
*
* wolfSSL is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
*/
#include <stdio.h>
#include <wolfssl/options.h>
#include <wolfssl/ssl.h>
#include <wolfssl/wolfcrypt/error-crypt.h>
#include <wolfssl/test.h>
int main(void)
{
int ret;
WOLFSSL_CERT_MANAGER* cm = NULL;
const char* caCert = "../certs/ca-cert.pem";
const char* verifyCert = "../certs/server-cert.pem";
#ifdef HAVE_CRL
const char* crlPem = "../certs/crl/crl.pem";
const char* caCertDer = "../certs/ca-cert.der";
FILE* file;
byte buf[4096];
int bufSz;
#endif
wolfSSL_Init();
#ifdef DEBUG_WOLFSSL
wolfSSL_Debugging_ON();
#endif
cm = wolfSSL_CertManagerNew();
if (cm == NULL) {
printf("wolfSSL_CertManagerNew() failed\n");
return -1;
}
wolfSSL_CertManagerSetVerify(cm, myVerify);
ret = wolfSSL_CertManagerLoadCA(cm, caCert, NULL);
if (ret != WOLFSSL_SUCCESS) {
printf("wolfSSL_CertManagerLoadCA() failed (%d): %s\n",
ret, wolfSSL_ERR_reason_error_string(ret));
ret = -1; goto exit;
}
ret = wolfSSL_CertManagerVerify(cm, verifyCert, WOLFSSL_FILETYPE_PEM);
if (ret != WOLFSSL_SUCCESS) {
printf("wolfSSL_CertManagerVerify() failed (%d): %s\n",
ret, wolfSSL_ERR_reason_error_string(ret));
ret = -1; goto exit;
}
printf("Verification Successful!\n");
#ifdef HAVE_CRL
file = fopen(crlPem, "rb");
if (file == NULL) {
ret = -1; goto exit;
}
bufSz = fread(buf, 1, sizeof(buf), file);
fclose(file);
ret = wolfSSL_CertManagerLoadCRLBuffer(cm, buf, bufSz, WOLFSSL_FILETYPE_PEM);
if (ret != WOLFSSL_SUCCESS) {
printf("wolfSSL_CertManagerLoadCRLBuffer() failed (%d): %s\n",
ret, wolfSSL_ERR_reason_error_string(ret));
ret = -1; goto exit;
}
file = fopen(caCertDer, "rb");
if (file == NULL) {
ret = -1; goto exit;
}
bufSz = fread(buf, 1, sizeof(buf), file);
fclose(file);
ret = wolfSSL_CertManagerCheckCRL(cm, buf, bufSz);
if (ret != WOLFSSL_SUCCESS) {
printf("wolfSSL_CertManagerCheckCRL() failed (%d): %s\n",
ret, wolfSSL_ERR_reason_error_string(ret));
ret = -1; goto exit;
}
printf("CRL Verification Successful!\n");
#endif
exit:
wolfSSL_CertManagerFree(cm);
wolfSSL_Cleanup();
return ret;
}
|
940afb7dac7c58ec83d623ad8b8e928579730b9e
|
8c2e6410771ecd17b9c5c4ec3170ac08137a53f2
|
/src/lists.h
|
c6f55de9355428afb846e7173ac56c19139f3e3f
|
[
"MIT"
] |
permissive
|
ryanlayer/giggle
|
f09b8f982010dee5ef26d4f6c581e0b2d5a2c991
|
4071cb773f8af74aa3e3a2db1c22cca551409b70
|
refs/heads/master
| 2022-12-22T19:20:13.269573
| 2022-12-12T17:09:14
| 2022-12-12T17:09:14
| 47,425,454
| 219
| 30
|
MIT
| 2022-12-12T17:09:16
| 2015-12-04T19:48:08
|
C
|
UTF-8
|
C
| false
| false
| 6,704
|
h
|
lists.h
|
#ifndef __LISTS_H__
#define __LISTS_H__
#include <stdint.h>
#include <htslib/khash.h>
#include "disk_store.h"
// BITMAP
struct bit_map
{
uint64_t num_bits;
uint32_t num_ints;
uint32_t *bm;
};
struct bit_map *bit_map_init(uint64_t bits);
struct bit_map *bit_map_load(FILE *f, char *file_name);
void bit_map_store(struct bit_map *b, FILE *f, char *file_name);
void bit_map_destroy(struct bit_map **b);
void bit_map_set(struct bit_map *b, uint64_t i);
uint32_t bit_map_get(struct bit_map *b, uint64_t q);
// INDEXED LIST
struct indexed_list
{
char *data;
uint64_t size;
uint32_t element_size;
struct bit_map *bm;
};
struct indexed_list *indexed_list_init(uint64_t init_size,
uint32_t element_size);
void indexed_list_destroy(struct indexed_list **il);
uint32_t indexed_list_add(struct indexed_list *il,
uint64_t index,
void *data);
void *indexed_list_get(struct indexed_list *il, uint64_t index);
void indexed_list_write(struct indexed_list *il, FILE *f, char *file_name);
struct indexed_list *indexed_list_load(FILE *f, char *file_name);
struct offset_size_pair
{
long offset;
uint32_t size;
};
// HASH LIST
struct hash_list
{
void *hash;
};
struct hash_list *hash_list_init();
uint32_t hash_list_add(struct hash_list *il,
uint32_t index,
void *data,
uint32_t data_size);
void *hash_list_get(struct hash_list *il,
uint32_t index);
void hash_list_write(struct indexed_list *il, FILE *f, char *file_name);
void *hash_list_remove(struct hash_list *il,
uint32_t index);
void hash_list_destroy(struct hash_list **hashl);
void hash_list_value_cache_handler_pair_destroy(struct hash_list **hashl);
// UNORDERD LIST
struct unordered_list
{
void **data;
uint32_t num, size;
};
struct unordered_list *unordered_list_init(uint32_t init_size);
void unordered_list_destroy(struct unordered_list **ul,
void (*free_data)(void **data));
uint32_t unordered_list_add(struct unordered_list *ul,
void *data);
void *unordered_list_get(struct unordered_list *ul, uint32_t i);
struct unordered_list *unordered_list_load(
FILE *f,
char *file_name,
void *(*ul_load)(FILE *f, char *file_name));
void unordered_list_store(struct unordered_list *ul,
FILE *f,
char *file_name,
void (*ul_store)(void *v, FILE *f, char *file_name));
// ORDERD SET
struct ordered_set
{
void **data;
uint32_t num, size;
int (*sort_element_cmp)(const void *a, const void *b);
int (*search_element_cmp)(const void *a, const void *b);
int (*search_key_cmp)(const void *a, const void *b);
};
struct ordered_set
*ordered_set_init(
uint32_t init_size,
int (*sort_element_cmp)(const void *a, const void *b),
int (*search_element_cmp)(const void *a, const void *b),
int (*search_key_cmp)(const void *a, const void *b));
struct ordered_set
*ordered_set_load(
FILE *f,
char *file_name,
void *(*os_load)(FILE *f, char *file_name),
int (*sort_element_cmp)(const void *a, const void *b),
int (*search_element_cmp)(const void *a, const void *b),
int (*search_key_cmp)(const void *a, const void *b));
void ordered_set_destroy(struct ordered_set **os,
void (*free_data)(void **data));
void *ordered_set_add(struct ordered_set *os,
void *data);
void *ordered_set_get(struct ordered_set *os, void *key);
void ordered_set_store(struct ordered_set *os,
FILE *f,
char *file_name,
void (*os_store)(void *v, FILE *f, char *file_name));
struct str_uint_pair
{
char *str;
uint32_t uint;
};
int str_uint_pair_sort_element_cmp(const void *a, const void *b);
int str_uint_pair_search_element_cmp(const void *a, const void *b);
int str_uint_pair_search_key_cmp(const void *a, const void *b);
void str_uint_pair_store(void *v, FILE *f, char *file_name);
void *str_uint_pair_load(FILE *f, char *file_name);
void str_uint_pair_free(void **v);
struct pointer_uint_pair
{
void *pointer;
uint32_t uint;
};
int pointer_uint_pair_sort_element_cmp(const void *a, const void *b);
int pointer_uint_pair_search_element_cmp(const void *a, const void *b);
int pointer_uint_pair_search_key_cmp(const void *a, const void *b);
struct uint_offset_size_pair
{
uint32_t uint,size;
long offset;
};
int uint_offset_size_pair_sort_element_cmp(const void *a, const void *b);
int uint_offset_size_pair_search_element_cmp(const void *a, const void *b);
int uint_offset_size_pair_search_key_cmp(const void *a, const void *b);
struct uint_pair
{
uint32_t first,second;
};
int uint_pair_sort_by_first_element_cmp(const void *a, const void *b);
int uint_pair_search_by_first_element_cmp(const void *a, const void *b);
int uint_pair_search_by_first_key_cmp(const void *a, const void *b);
// FIFO Q
struct fifo_q_element
{
void *val;
struct fifo_q_element *next;
};
struct fifo_q
{
struct fifo_q_element *head, *tail;
};
void fifo_q_push(struct fifo_q **q, void *val);
void *fifo_q_pop(struct fifo_q **q);
void *fifo_q_peek(struct fifo_q *q);
// BYTE ARRAY
struct byte_array
{
char *data;
uint32_t num, size;
};
struct byte_array *byte_array_init(uint32_t init_size);
void byte_array_destory(struct byte_array **ba);
void byte_array_append(struct byte_array *ba, void *data, uint32_t size);
void byte_array_append_zeros(struct byte_array *ba, uint32_t size);
// UINT32 ARRAY
struct uint32_t_array
{
uint32_t num, size, *data;
};
struct uint32_t_array *uint32_t_array_init(uint32_t init_size);
void uint32_t_array_destroy(struct uint32_t_array **ua);
uint32_t uint32_t_array_add(struct uint32_t_array *ua, uint32_t val);
uint32_t uint32_t_array_set(struct uint32_t_array *ua,
uint32_t val,
uint32_t index);
uint32_t *uint32_t_array_get(struct uint32_t_array *ua, uint32_t index);
// UINT64 ARRAY
struct uint64_t_array
{
uint64_t num, size, *data;
};
struct uint64_t_array *uint64_t_array_init(uint64_t init_size);
void uint64_t_array_destroy(struct uint64_t_array **ua);
uint64_t uint64_t_array_add(struct uint64_t_array *ua, uint64_t val);
uint64_t *uint64_t_array_get(struct uint64_t_array *ua, uint64_t index);
#endif
|
3d067b28aadd87f6abce058c681b41178e5c28d2
|
25b7cd3e4b750803565c374e59f8179c8aab276d
|
/h3m/h3mlib/h3m_parsing/parse_od_quest_guard.c
|
6d8fdd1be3a4fb95be0667eed97e396756a829f0
|
[
"MIT"
] |
permissive
|
potmdehex/homm3tools
|
320ce70e0d22dc597df440ec7c63fde9844f7dbe
|
6b36d1f92ea67f5ad6d4847aeaf2dfb1766d3cc5
|
refs/heads/master
| 2023-08-06T02:56:53.534443
| 2022-09-19T12:42:50
| 2022-09-19T12:42:50
| 40,399,205
| 141
| 29
|
MIT
| 2019-12-06T12:11:43
| 2015-08-08T10:15:08
|
C
|
UTF-8
|
C
| false
| false
| 861
|
c
|
parse_od_quest_guard.c
|
// Created by John Åkerblom 2014-11-22
#include "parse_od.h"
#include "parsing_common.h"
int parse_od_quest_guard(struct H3MLIB_CTX *ctx,
struct H3M_OD_ENTRY *od_entry, struct META_OD_ENTRY *meta_od_entry)
{
struct H3M *p = &ctx->h3m;
struct H3MLIB_PARSING *parsing = &ctx->parsing;
const uint32_t fm = p->format;
struct H3M_OD_BODY_DYNAMIC_QUEST_GUARD *body = NULL;
size_t n = 0;
od_entry->body = calloc(1, sizeof(*body));
body = (struct H3M_OD_BODY_DYNAMIC_QUEST_GUARD *)od_entry->body;
meta_od_entry->binary_compatible = 0;
meta_od_entry->body_size = sizeof(*body);
SAFE_READ_SIZEOF(&body->quest_type, parsing)
if (0x00 != body->quest_type) {
if (0 != parse_od_ext_quest(ctx, body->quest_type, &body->quest,
meta_od_entry)) {
return 1;
}
}
return 0;
}
|
c1ba7c9f73e27d6ef77c2681730695a52aa761c5
|
7eaf54a78c9e2117247cb2ab6d3a0c20719ba700
|
/SOFTWARE/A64-TERES/linux-a64/arch/arm/mach-imx/devices-imx27.h
|
130962519751ea0e4c4ad8aa752cc818c8487602
|
[
"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
| 3,463
|
h
|
devices-imx27.h
|
/*
* Copyright (C) 2010 Pengutronix
* Uwe Kleine-Koenig <u.kleine-koenig@pengutronix.de>
*
* 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 "devices/devices-common.h"
extern const struct imx_fec_data imx27_fec_data;
#define imx27_add_fec(pdata) \
imx_add_fec(&imx27_fec_data, pdata)
extern const struct imx_fsl_usb2_udc_data imx27_fsl_usb2_udc_data;
#define imx27_add_fsl_usb2_udc(pdata) \
imx_add_fsl_usb2_udc(&imx27_fsl_usb2_udc_data, pdata)
extern const struct imx_imx27_coda_data imx27_coda_data;
#define imx27_add_coda() \
imx_add_imx27_coda(&imx27_coda_data)
extern const struct imx_imx2_wdt_data imx27_imx2_wdt_data;
#define imx27_add_imx2_wdt() \
imx_add_imx2_wdt(&imx27_imx2_wdt_data)
extern const struct imx_imx_fb_data imx27_imx_fb_data;
#define imx27_add_imx_fb(pdata) \
imx_add_imx_fb(&imx27_imx_fb_data, pdata)
extern const struct imx_imx_i2c_data imx27_imx_i2c_data[];
#define imx27_add_imx_i2c(id, pdata) \
imx_add_imx_i2c(&imx27_imx_i2c_data[id], pdata)
extern const struct imx_imx_keypad_data imx27_imx_keypad_data;
#define imx27_add_imx_keypad(pdata) \
imx_add_imx_keypad(&imx27_imx_keypad_data, pdata)
extern const struct imx_imx_ssi_data imx27_imx_ssi_data[];
#define imx27_add_imx_ssi(id, pdata) \
imx_add_imx_ssi(&imx27_imx_ssi_data[id], pdata)
extern const struct imx_imx_uart_1irq_data imx27_imx_uart_data[];
#define imx27_add_imx_uart(id, pdata) \
imx_add_imx_uart_1irq(&imx27_imx_uart_data[id], pdata)
#define imx27_add_imx_uart0(pdata) imx27_add_imx_uart(0, pdata)
#define imx27_add_imx_uart1(pdata) imx27_add_imx_uart(1, pdata)
#define imx27_add_imx_uart2(pdata) imx27_add_imx_uart(2, pdata)
#define imx27_add_imx_uart3(pdata) imx27_add_imx_uart(3, pdata)
#define imx27_add_imx_uart4(pdata) imx27_add_imx_uart(4, pdata)
#define imx27_add_imx_uart5(pdata) imx27_add_imx_uart(5, pdata)
extern const struct imx_mx2_camera_data imx27_mx2_camera_data;
#define imx27_add_mx2_camera(pdata) \
imx_add_mx2_camera(&imx27_mx2_camera_data, pdata)
extern const struct imx_mx2_emma_data imx27_mx2_emmaprp_data;
#define imx27_add_mx2_emmaprp() \
imx_add_mx2_emmaprp(&imx27_mx2_emmaprp_data)
extern const struct imx_mxc_ehci_data imx27_mxc_ehci_otg_data;
#define imx27_add_mxc_ehci_otg(pdata) \
imx_add_mxc_ehci(&imx27_mxc_ehci_otg_data, pdata)
extern const struct imx_mxc_ehci_data imx27_mxc_ehci_hs_data[];
#define imx27_add_mxc_ehci_hs(id, pdata) \
imx_add_mxc_ehci(&imx27_mxc_ehci_hs_data[id - 1], pdata)
extern const struct imx_mxc_mmc_data imx27_mxc_mmc_data[];
#define imx27_add_mxc_mmc(id, pdata) \
imx_add_mxc_mmc(&imx27_mxc_mmc_data[id], pdata)
extern const struct imx_mxc_nand_data imx27_mxc_nand_data;
#define imx27_add_mxc_nand(pdata) \
imx_add_mxc_nand(&imx27_mxc_nand_data, pdata)
extern const struct imx_mxc_w1_data imx27_mxc_w1_data;
#define imx27_add_mxc_w1() \
imx_add_mxc_w1(&imx27_mxc_w1_data)
extern const struct imx_spi_imx_data imx27_cspi_data[];
#define imx27_add_cspi(id, pdata) \
imx_add_spi_imx(&imx27_cspi_data[id], pdata)
#define imx27_add_spi_imx0(pdata) imx27_add_cspi(0, pdata)
#define imx27_add_spi_imx1(pdata) imx27_add_cspi(1, pdata)
#define imx27_add_spi_imx2(pdata) imx27_add_cspi(2, pdata)
extern const struct imx_pata_imx_data imx27_pata_imx_data;
#define imx27_add_pata_imx() \
imx_add_pata_imx(&imx27_pata_imx_data)
|
7da0d17d008ea07790f4703650f3491e897d205b
|
99bdb3251fecee538e0630f15f6574054dfc1468
|
/bsp/imxrt/libraries/MIMXRT1064/MIMXRT1064/utilities/io/swo/fsl_swo.c
|
2166b2c799800d2b54159f0c702e4bf754fde329
|
[
"Zlib",
"LicenseRef-scancode-proprietary-license",
"MIT",
"BSD-3-Clause",
"X11",
"BSD-4-Clause-UC",
"LicenseRef-scancode-unknown-license-reference",
"Apache-2.0"
] |
permissive
|
RT-Thread/rt-thread
|
03a7c52c2aeb1b06a544143b0e803d72f47d1ece
|
3602f891211904a27dcbd51e5ba72fefce7326b2
|
refs/heads/master
| 2023-09-01T04:10:20.295801
| 2023-08-31T16:20:55
| 2023-08-31T16:20:55
| 7,408,108
| 9,599
| 5,805
|
Apache-2.0
| 2023-09-14T13:37:26
| 2013-01-02T14:49:21
|
C
|
UTF-8
|
C
| false
| false
| 2,598
|
c
|
fsl_swo.c
|
/*
* Copyright 2018 NXP
* All rights reserved.
*
*
* SPDX-License-Identifier: BSD-3-Clause
*
*/
#include "fsl_swo.h"
/*******************************************************************************
* Definitions
******************************************************************************/
/* SWO encoding protocol definition */
#ifndef FSL_DEBUG_CONSOLE_SWO_PROTOCOL
#define FSL_DEBUG_CONSOLE_SWO_PROTOCOL kSWO_ProtocolNrz
#endif
/*******************************************************************************
* Variables
******************************************************************************/
/*******************************************************************************
* Code
******************************************************************************/
status_t SWO_Init(uint32_t port, uint32_t baudRate, uint32_t clkSrcFreq)
{
assert(baudRate <= clkSrcFreq);
assert((clkSrcFreq / baudRate) <= TPI_ACPR_PRESCALER_Msk);
assert((TPI->DEVID & (kSWO_ProtocolNrz | kSWO_ProtocolManchester)) != 0U);
uint32_t prescaler = clkSrcFreq / baudRate - 1U;
/* enable the ITM and DWT units */
CoreDebug->DEMCR = CoreDebug_DEMCR_TRCENA_Msk;
if ((CoreDebug->DEMCR & CoreDebug_DEMCR_TRCENA_Msk) == 0U)
{
return kStatus_Fail;
}
/* Lock access */
ITM->LAR = 0xC5ACCE55U;
/* Disable ITM */
ITM->TER &= ~(1U << port);
ITM->TCR = 0U;
/* select SWO encoding protocol */
TPI->SPPR = FSL_DEBUG_CONSOLE_SWO_PROTOCOL;
/* select asynchronous clock prescaler */
TPI->ACPR = prescaler & 0xFFFFU;
/* allow unprivilege access */
ITM->TPR = 0U;
/* enable ITM */
ITM->TCR =
ITM_TCR_ITMENA_Msk | ITM_TCR_SYNCENA_Msk | ITM_TCR_TraceBusID_Msk | ITM_TCR_SWOENA_Msk | ITM_TCR_DWTENA_Msk;
/* enable the port bits */
ITM->TER = 1U << port;
return kStatus_Success;
}
void SWO_Deinit(uint32_t port)
{
/* disable ITM */
ITM->TER &= ~(1U << port);
}
status_t SWO_SendBlocking(uint32_t port, uint8_t *ch, size_t size)
{
assert(ch != NULL);
assert((ITM->TCR & ITM_TCR_ITMENA_Msk) != 0U);
assert((ITM->TER & (1U << port)) != 0U);
uint16_t *strAddr = (uint16_t *)ch;
while (size)
{
/* wait FIFO ready */
while (ITM->PORT[port].u32 == 0U)
{
}
if (size >= 2U)
{
size -= 2U;
ITM->PORT[port].u16 = *strAddr;
}
else
{
size -= 1U;
ITM->PORT[port].u8 = *((uint8_t *)strAddr);
}
strAddr++;
}
return kStatus_Success;
}
|
ac252ff3d002752f30a2dbd9a76ce444bd247599
|
28d0f8c01599f8f6c711bdde0b59f9c2cd221203
|
/sys/arch/m68k/include/setjmp.h
|
28a296e8bebfec57bd6fdf65052567274af75971
|
[] |
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
| 194
|
h
|
setjmp.h
|
/* $NetBSD: setjmp.h,v 1.2 1998/09/15 23:06:41 thorpej Exp $ */
/*
* machine/setjmp.h: machine dependent setjmp-related information.
*/
#define _JBLEN 21 /* size, in longs, of a jmp_buf */
|
88cda915f3d1232088a160249eabf4c1e26d9cbb
|
5c1625afdb9a9964cca81d0e1a9c44e70f5e769a
|
/tests/externals/tinyssh/crypto_hash_sha512.h
|
7b1d1acb59d96aab02de2181303844a9998093c2
|
[
"BSD-3-Clause",
"CC0-1.0",
"LicenseRef-scancode-public-domain",
"BSD-2-Clause"
] |
permissive
|
LoupVaillant/Monocypher
|
6a225147b3fd3671c1e3c9caf1fa2828bc3d874a
|
3a9557427201e78026048547988bbb582fe64f4a
|
refs/heads/master
| 2023-09-06T07:21:54.777041
| 2023-09-05T21:02:44
| 2023-09-05T21:02:44
| 97,625,830
| 583
| 87
|
NOASSERTION
| 2023-02-25T12:42:47
| 2017-07-18T17:28:53
|
C
|
UTF-8
|
C
| false
| false
| 422
|
h
|
crypto_hash_sha512.h
|
#ifndef crypto_hash_sha512_H
#define crypto_hash_sha512_H
#define crypto_hash_sha512_tinyssh_BYTES 64
extern int crypto_hash_sha512_tinyssh(unsigned char *, const unsigned char *, unsigned long long);
#define crypto_hash_sha512 crypto_hash_sha512_tinyssh
#define crypto_hash_sha512_BYTES crypto_hash_sha512_tinyssh_BYTES
#define crypto_hash_sha512_IMPLEMENTATION "tinyssh"
#define crypto_hash_sha512_VERSION "-"
#endif
|
079d20554521ef976291bd5da7e4dcf73950f15e
|
73b0f9c30d07993ad74f7f2bcbc0fe61f1d1a3ce
|
/native/iosTest/Pods/Headers/Public/RCT-Folly/folly/fibers/ForEach-inl.h
|
9e6d2d527ef90b06f953744c7d6a6cd4a2ac4b44
|
[
"MIT"
] |
permissive
|
Nozbe/WatermelonDB
|
84771a637e2c93474220fadee442e5c4ade40f7e
|
fd41fe279e229e9b5013b1dddf777cd7919e1d2d
|
refs/heads/master
| 2023-08-16T18:24:04.893973
| 2023-08-11T11:44:46
| 2023-08-11T11:44:46
| 146,468,829
| 9,358
| 670
|
MIT
| 2023-09-10T08:04:55
| 2018-08-28T15:32:05
|
JavaScript
|
UTF-8
|
C
| false
| false
| 51
|
h
|
ForEach-inl.h
|
../../../../../RCT-Folly/folly/fibers/ForEach-inl.h
|
a11ee586f10f1e71508246b9884a45523d7081d6
|
3c883e1084f0a61e558c2d210bb1b4ae8a5e6a06
|
/third_party/nvxs-1.0.2/CLAPACK/TESTING/EIG/zlarfy.c
|
41d89d2cfcaf305cca24b02fd38cd3332502e4c6
|
[
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference",
"Python-2.0",
"BSD-3-Clause"
] |
permissive
|
nya3jp/python-animeface
|
7e48aa333c9f365a80acdf43e5d516edc8d0b189
|
15caf8b1ca29847f0dceb54e4b91c77726c4111c
|
refs/heads/main
| 2022-04-29T20:17:01.198810
| 2022-04-04T10:17:59
| 2022-04-04T10:17:59
| 10,998,381
| 150
| 14
|
Apache-2.0
| 2022-04-03T07:18:40
| 2013-06-27T14:06:08
|
C
|
UTF-8
|
C
| false
| false
| 3,984
|
c
|
zlarfy.c
|
#include "f2c.h"
#include "blaswrap.h"
/* Table of constant values */
static doublecomplex c_b1 = {1.,0.};
static doublecomplex c_b2 = {0.,0.};
static integer c__1 = 1;
/* Subroutine */ int zlarfy_(char *uplo, integer *n, doublecomplex *v,
integer *incv, doublecomplex *tau, doublecomplex *c__, integer *ldc,
doublecomplex *work)
{
/* System generated locals */
integer c_dim1, c_offset;
doublecomplex z__1, z__2, z__3, z__4;
/* Local variables */
extern /* Subroutine */ int zher2_(char *, integer *, doublecomplex *,
doublecomplex *, integer *, doublecomplex *, integer *,
doublecomplex *, integer *);
doublecomplex alpha;
extern /* Double Complex */ VOID zdotc_(doublecomplex *, integer *,
doublecomplex *, integer *, doublecomplex *, integer *);
extern /* Subroutine */ int zhemv_(char *, integer *, doublecomplex *,
doublecomplex *, integer *, doublecomplex *, integer *,
doublecomplex *, doublecomplex *, integer *), zaxpy_(
integer *, doublecomplex *, doublecomplex *, integer *,
doublecomplex *, integer *);
/* -- LAPACK auxiliary test routine (version 3.1) -- */
/* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
/* November 2006 */
/* .. Scalar Arguments .. */
/* .. */
/* .. Array Arguments .. */
/* .. */
/* Purpose */
/* ======= */
/* ZLARFY applies an elementary reflector, or Householder matrix, H, */
/* to an n x n Hermitian matrix C, from both the left and the right. */
/* H is represented in the form */
/* H = I - tau * v * v' */
/* where tau is a scalar and v is a vector. */
/* If tau is zero, then H is taken to be the unit matrix. */
/* Arguments */
/* ========= */
/* UPLO (input) CHARACTER*1 */
/* Specifies whether the upper or lower triangular part of the */
/* Hermitian matrix C is stored. */
/* = 'U': Upper triangle */
/* = 'L': Lower triangle */
/* N (input) INTEGER */
/* The number of rows and columns of the matrix C. N >= 0. */
/* V (input) COMPLEX*16 array, dimension */
/* (1 + (N-1)*abs(INCV)) */
/* The vector v as described above. */
/* INCV (input) INTEGER */
/* The increment between successive elements of v. INCV must */
/* not be zero. */
/* TAU (input) COMPLEX*16 */
/* The value tau as described above. */
/* C (input/output) COMPLEX*16 array, dimension (LDC, N) */
/* On entry, the matrix C. */
/* On exit, C is overwritten by H * C * H'. */
/* LDC (input) INTEGER */
/* The leading dimension of the array C. LDC >= max( 1, N ). */
/* WORK (workspace) COMPLEX*16 array, dimension (N) */
/* ===================================================================== */
/* .. Parameters .. */
/* .. */
/* .. Local Scalars .. */
/* .. */
/* .. External Subroutines .. */
/* .. */
/* .. External Functions .. */
/* .. */
/* .. Executable Statements .. */
/* Parameter adjustments */
--v;
c_dim1 = *ldc;
c_offset = 1 + c_dim1;
c__ -= c_offset;
--work;
/* Function Body */
if (tau->r == 0. && tau->i == 0.) {
return 0;
}
/* Form w:= C * v */
zhemv_(uplo, n, &c_b1, &c__[c_offset], ldc, &v[1], incv, &c_b2, &work[1],
&c__1);
z__3.r = -.5, z__3.i = -0.;
z__2.r = z__3.r * tau->r - z__3.i * tau->i, z__2.i = z__3.r * tau->i +
z__3.i * tau->r;
zdotc_(&z__4, n, &work[1], &c__1, &v[1], incv);
z__1.r = z__2.r * z__4.r - z__2.i * z__4.i, z__1.i = z__2.r * z__4.i +
z__2.i * z__4.r;
alpha.r = z__1.r, alpha.i = z__1.i;
zaxpy_(n, &alpha, &v[1], incv, &work[1], &c__1);
/* C := C - v * w' - w * v' */
z__1.r = -tau->r, z__1.i = -tau->i;
zher2_(uplo, n, &z__1, &v[1], incv, &work[1], &c__1, &c__[c_offset], ldc);
return 0;
/* End of ZLARFY */
} /* zlarfy_ */
|
680fed92229be4748861f5631b814e2496baafc8
|
3cd3872acbc8b1a79a70b89b2fd58a171e7adc82
|
/vpx_dsp/loongarch/vpx_convolve8_vert_lsx.c
|
6022e43c83417daa6e26d2369e71d469c5b14429
|
[] |
permissive
|
webmproject/libvpx
|
58ab97861063cb521ec0d00ef9cb222ca97873b1
|
6fd360c684736e351160b131827dfbb207841164
|
refs/heads/main
| 2023-04-09T15:32:34.688724
| 2023-04-07T22:19:18
| 2023-04-07T22:19:18
| 22,927,608
| 889
| 376
|
BSD-3-Clause
| 2023-03-24T13:37:34
| 2014-08-13T19:03:21
|
C
|
UTF-8
|
C
| false
| false
| 32,903
|
c
|
vpx_convolve8_vert_lsx.c
|
/*
* Copyright (c) 2022 The WebM project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include <assert.h>
#include "./vpx_dsp_rtcd.h"
#include "vpx_dsp/loongarch/vpx_convolve_lsx.h"
static void common_vt_8t_4w_lsx(const uint8_t *src, int32_t src_stride,
uint8_t *dst, int32_t dst_stride,
int8_t *filter, int32_t height) {
uint32_t loop_cnt = height >> 2;
int32_t src_stride2 = src_stride << 1;
int32_t src_stride3 = src_stride + src_stride2;
int32_t src_stride4 = src_stride2 << 1;
__m128i src0, src1, src2, src3, src4, src5, src6, src7, src8, src9, src10;
__m128i tmp0, tmp1, tmp2, tmp3, tmp4, tmp5;
__m128i reg0, reg1, reg2, reg3, reg4;
__m128i filter0, filter1, filter2, filter3;
__m128i out0, out1;
uint8_t *_src = (uint8_t *)src - src_stride3;
DUP4_ARG2(__lsx_vldrepl_h, filter, 0, filter, 2, filter, 4, filter, 6,
filter0, filter1, filter2, filter3);
src0 = __lsx_vld(_src, 0);
DUP2_ARG2(__lsx_vldx, _src, src_stride, _src, src_stride2, src1, src2);
src3 = __lsx_vldx(_src, src_stride3);
_src += src_stride4;
src4 = __lsx_vld(_src, 0);
DUP2_ARG2(__lsx_vldx, _src, src_stride, _src, src_stride2, src5, src6);
_src += src_stride3;
DUP4_ARG2(__lsx_vilvl_b, src1, src0, src3, src2, src5, src4, src2, src1, tmp0,
tmp1, tmp2, tmp3);
DUP2_ARG2(__lsx_vilvl_b, src4, src3, src6, src5, tmp4, tmp5);
DUP2_ARG2(__lsx_vilvl_d, tmp3, tmp0, tmp4, tmp1, reg0, reg1);
reg2 = __lsx_vilvl_d(tmp5, tmp2);
DUP2_ARG2(__lsx_vxori_b, reg0, 128, reg1, 128, reg0, reg1);
reg2 = __lsx_vxori_b(reg2, 128);
for (; loop_cnt--;) {
src7 = __lsx_vld(_src, 0);
DUP2_ARG2(__lsx_vldx, _src, src_stride, _src, src_stride2, src8, src9);
src10 = __lsx_vldx(_src, src_stride3);
_src += src_stride4;
DUP4_ARG2(__lsx_vilvl_b, src7, src6, src8, src7, src9, src8, src10, src9,
tmp0, tmp1, tmp2, tmp3);
DUP2_ARG2(__lsx_vilvl_d, tmp1, tmp0, tmp3, tmp2, reg3, reg4);
DUP2_ARG2(__lsx_vxori_b, reg3, 128, reg4, 128, reg3, reg4);
out0 = filt_8tap_dpadd_s_h(reg0, reg1, reg2, reg3, filter0, filter1,
filter2, filter3);
out1 = filt_8tap_dpadd_s_h(reg1, reg2, reg3, reg4, filter0, filter1,
filter2, filter3);
out0 = __lsx_vssrarni_b_h(out1, out0, 7);
out0 = __lsx_vxori_b(out0, 128);
__lsx_vstelm_w(out0, dst, 0, 0);
dst += dst_stride;
__lsx_vstelm_w(out0, dst, 0, 1);
dst += dst_stride;
__lsx_vstelm_w(out0, dst, 0, 2);
dst += dst_stride;
__lsx_vstelm_w(out0, dst, 0, 3);
dst += dst_stride;
reg0 = reg2;
reg1 = reg3;
reg2 = reg4;
src6 = src10;
}
}
static void common_vt_8t_8w_lsx(const uint8_t *src, int32_t src_stride,
uint8_t *dst, int32_t dst_stride,
int8_t *filter, int32_t height) {
uint32_t loop_cnt = height >> 2;
__m128i src0, src1, src2, src3, src4, src5, src6, src7, src8, src9, src10;
__m128i tmp0, tmp1, tmp2, tmp3;
__m128i reg0, reg1, reg2, reg3, reg4, reg5;
__m128i filter0, filter1, filter2, filter3;
__m128i out0, out1, out2, out3;
int32_t src_stride2 = src_stride << 1;
int32_t src_stride3 = src_stride + src_stride2;
int32_t src_stride4 = src_stride2 << 1;
src = src - src_stride3;
DUP4_ARG2(__lsx_vldrepl_h, filter, 0, filter, 2, filter, 4, filter, 6,
filter0, filter1, filter2, filter3);
src0 = __lsx_vld(src, 0);
DUP2_ARG2(__lsx_vldx, src, src_stride, src, src_stride2, src1, src2);
src3 = __lsx_vldx(src, src_stride3);
src += src_stride4;
src4 = __lsx_vld(src, 0);
DUP2_ARG2(__lsx_vldx, src, src_stride, src, src_stride2, src5, src6);
src += src_stride3;
DUP4_ARG2(__lsx_vxori_b, src0, 128, src1, 128, src2, 128, src3, 128, src0,
src1, src2, src3);
DUP2_ARG2(__lsx_vxori_b, src4, 128, src5, 128, src4, src5);
src6 = __lsx_vxori_b(src6, 128);
DUP4_ARG2(__lsx_vilvl_b, src1, src0, src3, src2, src5, src4, src2, src1, reg0,
reg1, reg2, reg3);
DUP2_ARG2(__lsx_vilvl_b, src4, src3, src6, src5, reg4, reg5);
for (; loop_cnt--;) {
src7 = __lsx_vld(src, 0);
DUP2_ARG2(__lsx_vldx, src, src_stride, src, src_stride2, src8, src9);
src10 = __lsx_vldx(src, src_stride3);
src += src_stride4;
DUP4_ARG2(__lsx_vxori_b, src7, 128, src8, 128, src9, 128, src10, 128, src7,
src8, src9, src10);
DUP4_ARG2(__lsx_vilvl_b, src7, src6, src8, src7, src9, src8, src10, src9,
tmp0, tmp1, tmp2, tmp3);
out0 = filt_8tap_dpadd_s_h(reg0, reg1, reg2, tmp0, filter0, filter1,
filter2, filter3);
out1 = filt_8tap_dpadd_s_h(reg3, reg4, reg5, tmp1, filter0, filter1,
filter2, filter3);
out2 = filt_8tap_dpadd_s_h(reg1, reg2, tmp0, tmp2, filter0, filter1,
filter2, filter3);
out3 = filt_8tap_dpadd_s_h(reg4, reg5, tmp1, tmp3, filter0, filter1,
filter2, filter3);
DUP2_ARG3(__lsx_vssrarni_b_h, out1, out0, 7, out3, out2, 7, out0, out1);
DUP2_ARG2(__lsx_vxori_b, out0, 128, out1, 128, out0, out1);
__lsx_vstelm_d(out0, dst, 0, 0);
dst += dst_stride;
__lsx_vstelm_d(out0, dst, 0, 1);
dst += dst_stride;
__lsx_vstelm_d(out1, dst, 0, 0);
dst += dst_stride;
__lsx_vstelm_d(out1, dst, 0, 1);
dst += dst_stride;
reg0 = reg2;
reg1 = tmp0;
reg2 = tmp2;
reg3 = reg5;
reg4 = tmp1;
reg5 = tmp3;
src6 = src10;
}
}
static void common_vt_8t_16w_lsx(const uint8_t *src, int32_t src_stride,
uint8_t *dst, int32_t dst_stride,
int8_t *filter, int32_t height) {
uint32_t loop_cnt = height >> 2;
__m128i src0, src1, src2, src3, src4, src5, src6, src7, src8, src9, src10;
__m128i filter0, filter1, filter2, filter3;
__m128i reg0, reg1, reg2, reg3, reg4, reg5;
__m128i reg6, reg7, reg8, reg9, reg10, reg11;
__m128i tmp0, tmp1, tmp2, tmp3;
int32_t src_stride2 = src_stride << 1;
int32_t src_stride3 = src_stride + src_stride2;
int32_t src_stride4 = src_stride2 << 1;
// uint8_t *_src = (uint8_t *)src - src_stride3;
src -= src_stride3;
DUP4_ARG2(__lsx_vldrepl_h, filter, 0, filter, 2, filter, 4, filter, 6,
filter0, filter1, filter2, filter3);
src0 = __lsx_vld(src, 0);
DUP4_ARG2(__lsx_vldx, src, src_stride, src, src_stride2, src, src_stride3,
src, src_stride4, src1, src2, src3, src4);
src += src_stride4;
DUP2_ARG2(__lsx_vldx, src, src_stride, src, src_stride2, src5, src6);
src += src_stride3;
DUP4_ARG2(__lsx_vxori_b, src0, 128, src1, 128, src2, 128, src3, 128, src0,
src1, src2, src3);
DUP2_ARG2(__lsx_vxori_b, src4, 128, src5, 128, src4, src5);
src6 = __lsx_vxori_b(src6, 128);
DUP4_ARG2(__lsx_vilvl_b, src1, src0, src3, src2, src5, src4, src2, src1, reg0,
reg1, reg2, reg3);
DUP2_ARG2(__lsx_vilvl_b, src4, src3, src6, src5, reg4, reg5);
DUP4_ARG2(__lsx_vilvh_b, src1, src0, src3, src2, src5, src4, src2, src1, reg6,
reg7, reg8, reg9);
DUP2_ARG2(__lsx_vilvh_b, src4, src3, src6, src5, reg10, reg11);
for (; loop_cnt--;) {
src7 = __lsx_vld(src, 0);
DUP2_ARG2(__lsx_vldx, src, src_stride, src, src_stride2, src8, src9);
src10 = __lsx_vldx(src, src_stride3);
src += src_stride4;
DUP4_ARG2(__lsx_vxori_b, src7, 128, src8, 128, src9, 128, src10, 128, src7,
src8, src9, src10);
DUP4_ARG2(__lsx_vilvl_b, src7, src6, src8, src7, src9, src8, src10, src9,
src0, src1, src2, src3);
DUP4_ARG2(__lsx_vilvh_b, src7, src6, src8, src7, src9, src8, src10, src9,
src4, src5, src7, src8);
tmp0 = filt_8tap_dpadd_s_h(reg0, reg1, reg2, src0, filter0, filter1,
filter2, filter3);
tmp1 = filt_8tap_dpadd_s_h(reg3, reg4, reg5, src1, filter0, filter1,
filter2, filter3);
tmp2 = filt_8tap_dpadd_s_h(reg6, reg7, reg8, src4, filter0, filter1,
filter2, filter3);
tmp3 = filt_8tap_dpadd_s_h(reg9, reg10, reg11, src5, filter0, filter1,
filter2, filter3);
DUP2_ARG3(__lsx_vssrarni_b_h, tmp2, tmp0, 7, tmp3, tmp1, 7, tmp0, tmp1);
DUP2_ARG2(__lsx_vxori_b, tmp0, 128, tmp1, 128, tmp0, tmp1);
__lsx_vst(tmp0, dst, 0);
dst += dst_stride;
__lsx_vst(tmp1, dst, 0);
dst += dst_stride;
tmp0 = filt_8tap_dpadd_s_h(reg1, reg2, src0, src2, filter0, filter1,
filter2, filter3);
tmp1 = filt_8tap_dpadd_s_h(reg4, reg5, src1, src3, filter0, filter1,
filter2, filter3);
tmp2 = filt_8tap_dpadd_s_h(reg7, reg8, src4, src7, filter0, filter1,
filter2, filter3);
tmp3 = filt_8tap_dpadd_s_h(reg10, reg11, src5, src8, filter0, filter1,
filter2, filter3);
DUP2_ARG3(__lsx_vssrarni_b_h, tmp2, tmp0, 7, tmp3, tmp1, 7, tmp0, tmp1);
DUP2_ARG2(__lsx_vxori_b, tmp0, 128, tmp1, 128, tmp0, tmp1);
__lsx_vst(tmp0, dst, 0);
dst += dst_stride;
__lsx_vst(tmp1, dst, 0);
dst += dst_stride;
reg0 = reg2;
reg1 = src0;
reg2 = src2;
reg3 = reg5;
reg4 = src1;
reg5 = src3;
reg6 = reg8;
reg7 = src4;
reg8 = src7;
reg9 = reg11;
reg10 = src5;
reg11 = src8;
src6 = src10;
}
}
static void common_vt_8t_16w_mult_lsx(const uint8_t *src, int32_t src_stride,
uint8_t *dst, int32_t dst_stride,
int8_t *filter, int32_t height,
int32_t width) {
uint8_t *src_tmp;
uint8_t *dst_tmp;
uint32_t cnt = width >> 4;
__m128i src0, src1, src2, src3, src4, src5, src6, src7, src8, src9, src10;
__m128i filter0, filter1, filter2, filter3;
__m128i reg0, reg1, reg2, reg3, reg4, reg5;
__m128i reg6, reg7, reg8, reg9, reg10, reg11;
__m128i tmp0, tmp1, tmp2, tmp3;
int32_t src_stride2 = src_stride << 1;
int32_t src_stride3 = src_stride + src_stride2;
int32_t src_stride4 = src_stride2 << 1;
int32_t dst_stride2 = dst_stride << 1;
int32_t dst_stride3 = dst_stride2 + dst_stride;
int32_t dst_stride4 = dst_stride2 << 1;
src -= src_stride3;
DUP4_ARG2(__lsx_vldrepl_h, filter, 0, filter, 2, filter, 4, filter, 6,
filter0, filter1, filter2, filter3);
for (; cnt--;) {
uint32_t loop_cnt = height >> 2;
src_tmp = src;
dst_tmp = dst;
src0 = __lsx_vld(src_tmp, 0);
DUP2_ARG2(__lsx_vldx, src_tmp, src_stride, src_tmp, src_stride2, src1,
src2);
src3 = __lsx_vldx(src_tmp, src_stride3);
src_tmp += src_stride4;
src4 = __lsx_vld(src_tmp, 0);
DUP2_ARG2(__lsx_vldx, src_tmp, src_stride, src_tmp, src_stride2, src5,
src6);
src_tmp += src_stride3;
DUP4_ARG2(__lsx_vxori_b, src0, 128, src1, 128, src2, 128, src3, 128, src0,
src1, src2, src3);
DUP2_ARG2(__lsx_vxori_b, src4, 128, src5, 128, src4, src5);
src6 = __lsx_vxori_b(src6, 128);
DUP4_ARG2(__lsx_vilvl_b, src1, src0, src3, src2, src5, src4, src2, src1,
reg0, reg1, reg2, reg3);
DUP2_ARG2(__lsx_vilvl_b, src4, src3, src6, src5, reg4, reg5);
DUP4_ARG2(__lsx_vilvh_b, src1, src0, src3, src2, src5, src4, src2, src1,
reg6, reg7, reg8, reg9);
DUP2_ARG2(__lsx_vilvh_b, src4, src3, src6, src5, reg10, reg11);
for (; loop_cnt--;) {
src7 = __lsx_vld(src_tmp, 0);
DUP2_ARG2(__lsx_vldx, src_tmp, src_stride, src_tmp, src_stride2, src8,
src9);
src10 = __lsx_vldx(src_tmp, src_stride3);
src_tmp += src_stride4;
DUP4_ARG2(__lsx_vxori_b, src7, 128, src8, 128, src9, 128, src10, 128,
src7, src8, src9, src10);
DUP4_ARG2(__lsx_vilvl_b, src7, src6, src8, src7, src9, src8, src10, src9,
src0, src1, src2, src3);
DUP4_ARG2(__lsx_vilvh_b, src7, src6, src8, src7, src9, src8, src10, src9,
src4, src5, src7, src8);
tmp0 = filt_8tap_dpadd_s_h(reg0, reg1, reg2, src0, filter0, filter1,
filter2, filter3);
tmp1 = filt_8tap_dpadd_s_h(reg3, reg4, reg5, src1, filter0, filter1,
filter2, filter3);
tmp2 = filt_8tap_dpadd_s_h(reg6, reg7, reg8, src4, filter0, filter1,
filter2, filter3);
tmp3 = filt_8tap_dpadd_s_h(reg9, reg10, reg11, src5, filter0, filter1,
filter2, filter3);
DUP2_ARG3(__lsx_vssrarni_b_h, tmp2, tmp0, 7, tmp3, tmp1, 7, tmp0, tmp1);
DUP2_ARG2(__lsx_vxori_b, tmp0, 128, tmp1, 128, tmp0, tmp1);
__lsx_vst(tmp0, dst_tmp, 0);
__lsx_vstx(tmp1, dst_tmp, dst_stride);
tmp0 = filt_8tap_dpadd_s_h(reg1, reg2, src0, src2, filter0, filter1,
filter2, filter3);
tmp1 = filt_8tap_dpadd_s_h(reg4, reg5, src1, src3, filter0, filter1,
filter2, filter3);
tmp2 = filt_8tap_dpadd_s_h(reg7, reg8, src4, src7, filter0, filter1,
filter2, filter3);
tmp3 = filt_8tap_dpadd_s_h(reg10, reg11, src5, src8, filter0, filter1,
filter2, filter3);
DUP2_ARG3(__lsx_vssrarni_b_h, tmp2, tmp0, 7, tmp3, tmp1, 7, tmp0, tmp1);
DUP2_ARG2(__lsx_vxori_b, tmp0, 128, tmp1, 128, tmp0, tmp1);
__lsx_vstx(tmp0, dst_tmp, dst_stride2);
__lsx_vstx(tmp1, dst_tmp, dst_stride3);
dst_tmp += dst_stride4;
reg0 = reg2;
reg1 = src0;
reg2 = src2;
reg3 = reg5;
reg4 = src1;
reg5 = src3;
reg6 = reg8;
reg7 = src4;
reg8 = src7;
reg9 = reg11;
reg10 = src5;
reg11 = src8;
src6 = src10;
}
src += 16;
dst += 16;
}
}
static void common_vt_8t_32w_lsx(const uint8_t *src, int32_t src_stride,
uint8_t *dst, int32_t dst_stride,
int8_t *filter, int32_t height) {
common_vt_8t_16w_mult_lsx(src, src_stride, dst, dst_stride, filter, height,
32);
}
static void common_vt_8t_64w_lsx(const uint8_t *src, int32_t src_stride,
uint8_t *dst, int32_t dst_stride,
int8_t *filter, int32_t height) {
common_vt_8t_16w_mult_lsx(src, src_stride, dst, dst_stride, filter, height,
64);
}
static void common_vt_2t_4x4_lsx(const uint8_t *src, int32_t src_stride,
uint8_t *dst, int32_t dst_stride,
int8_t *filter) {
__m128i src0, src1, src2, src3, src4;
__m128i vec0, vec1, vec2, vec3, vec4, vec5;
__m128i filt0, tmp0, tmp1;
int32_t src_stride2 = src_stride << 1;
int32_t src_stride3 = src_stride2 + src_stride;
int32_t src_stride4 = src_stride2 << 1;
int32_t dst_stride2 = dst_stride << 1;
int32_t dst_stride3 = dst_stride2 + dst_stride;
filt0 = __lsx_vldrepl_h(filter, 0);
src0 = __lsx_vld(src, 0);
DUP4_ARG2(__lsx_vldx, src, src_stride, src, src_stride2, src, src_stride3,
src, src_stride4, src1, src2, src3, src4);
src += (src_stride4 + src_stride);
DUP4_ARG2(__lsx_vilvl_b, src1, src0, src2, src1, src3, src2, src4, src3, vec0,
vec1, vec2, vec3);
DUP2_ARG2(__lsx_vilvl_d, vec1, vec0, vec3, vec2, vec4, vec5);
DUP2_ARG2(__lsx_vdp2_h_bu, vec4, filt0, vec5, filt0, tmp0, tmp1);
tmp0 = __lsx_vssrarni_bu_h(tmp1, tmp0, FILTER_BITS);
__lsx_vstelm_w(tmp0, dst, 0, 0);
__lsx_vstelm_w(tmp0, dst + dst_stride, 0, 1);
__lsx_vstelm_w(tmp0, dst + dst_stride2, 0, 2);
__lsx_vstelm_w(tmp0, dst + dst_stride3, 0, 3);
}
static void common_vt_2t_4x8_lsx(const uint8_t *src, int32_t src_stride,
uint8_t *dst, int32_t dst_stride,
int8_t *filter) {
__m128i src0, src1, src2, src3, src4, src5, src6, src7, src8;
__m128i vec0, vec1, vec2, vec3, vec4, vec5;
__m128i vec6, vec7, vec8, vec9, vec10, vec11;
__m128i tmp0, tmp1, tmp2, tmp3;
__m128i filt0;
int32_t src_stride2 = src_stride << 1;
int32_t src_stride3 = src_stride2 + src_stride;
int32_t src_stride4 = src_stride2 << 1;
int32_t dst_stride2 = dst_stride << 1;
int32_t dst_stride3 = dst_stride2 + dst_stride;
int32_t dst_stride4 = dst_stride2 << 1;
uint8_t *dst_tmp1 = dst + dst_stride4;
filt0 = __lsx_vldrepl_h(filter, 0);
src0 = __lsx_vld(src, 0);
DUP4_ARG2(__lsx_vldx, src, src_stride, src, src_stride2, src, src_stride3,
src, src_stride4, src1, src2, src3, src4);
src += src_stride4;
DUP4_ARG2(__lsx_vldx, src, src_stride, src, src_stride2, src, src_stride3,
src, src_stride4, src5, src6, src7, src8);
src += (src_stride4 + src_stride);
DUP4_ARG2(__lsx_vilvl_b, src1, src0, src2, src1, src3, src2, src4, src3, vec0,
vec1, vec2, vec3);
DUP4_ARG2(__lsx_vilvl_b, src5, src4, src6, src5, src7, src6, src8, src7, vec4,
vec5, vec6, vec7);
DUP4_ARG2(__lsx_vilvl_d, vec1, vec0, vec3, vec2, vec5, vec4, vec7, vec6, vec8,
vec9, vec10, vec11);
DUP4_ARG2(__lsx_vdp2_h_bu, vec8, filt0, vec9, filt0, vec10, filt0, vec11,
filt0, tmp0, tmp1, tmp2, tmp3);
DUP2_ARG3(__lsx_vssrarni_bu_h, tmp1, tmp0, FILTER_BITS, tmp3, tmp2,
FILTER_BITS, tmp0, tmp1);
__lsx_vstelm_w(tmp0, dst, 0, 0);
__lsx_vstelm_w(tmp0, dst + dst_stride, 0, 1);
__lsx_vstelm_w(tmp0, dst + dst_stride2, 0, 2);
__lsx_vstelm_w(tmp0, dst + dst_stride3, 0, 3);
__lsx_vstelm_w(tmp1, dst_tmp1, 0, 0);
__lsx_vstelm_w(tmp1, dst_tmp1 + dst_stride, 0, 1);
__lsx_vstelm_w(tmp1, dst_tmp1 + dst_stride2, 0, 2);
__lsx_vstelm_w(tmp1, dst_tmp1 + dst_stride3, 0, 3);
}
static void common_vt_2t_4w_lsx(const uint8_t *src, int32_t src_stride,
uint8_t *dst, int32_t dst_stride,
int8_t *filter, int32_t height) {
if (height == 4) {
common_vt_2t_4x4_lsx(src, src_stride, dst, dst_stride, filter);
} else if (height == 8) {
common_vt_2t_4x8_lsx(src, src_stride, dst, dst_stride, filter);
}
}
static void common_vt_2t_8x4_lsx(const uint8_t *src, int32_t src_stride,
uint8_t *dst, int32_t dst_stride,
int8_t *filter) {
__m128i src0, src1, src2, src3, src4, vec0, vec1, vec2, vec3, filt0;
__m128i out0, out1, tmp0, tmp1, tmp2, tmp3;
int32_t src_stride2 = src_stride << 1;
int32_t src_stride3 = src_stride2 + src_stride;
int32_t src_stride4 = src_stride2 << 1;
int32_t dst_stride2 = dst_stride << 1;
int32_t dst_stride3 = dst_stride2 + dst_stride;
filt0 = __lsx_vldrepl_h(filter, 0);
src0 = __lsx_vld(src, 0);
DUP4_ARG2(__lsx_vldx, src, src_stride, src, src_stride2, src, src_stride3,
src, src_stride4, src1, src2, src3, src4);
DUP4_ARG2(__lsx_vilvl_b, src1, src0, src2, src1, src3, src2, src4, src3, vec0,
vec1, vec2, vec3);
DUP4_ARG2(__lsx_vdp2_h_bu, vec0, filt0, vec1, filt0, vec2, filt0, vec3, filt0,
tmp0, tmp1, tmp2, tmp3);
DUP2_ARG3(__lsx_vssrarni_bu_h, tmp1, tmp0, FILTER_BITS, tmp3, tmp2,
FILTER_BITS, out0, out1);
__lsx_vstelm_d(out0, dst, 0, 0);
__lsx_vstelm_d(out0, dst + dst_stride, 0, 1);
__lsx_vstelm_d(out1, dst + dst_stride2, 0, 0);
__lsx_vstelm_d(out1, dst + dst_stride3, 0, 1);
}
static void common_vt_2t_8x8mult_lsx(const uint8_t *src, int32_t src_stride,
uint8_t *dst, int32_t dst_stride,
int8_t *filter, int32_t height) {
uint32_t loop_cnt = (height >> 3);
__m128i src0, src1, src2, src3, src4, src5, src6, src7, src8;
__m128i vec0, vec1, vec2, vec3, vec4, vec5, vec6, vec7, filt0;
__m128i out0, out1, tmp0, tmp1, tmp2, tmp3;
int32_t src_stride2 = src_stride << 1;
int32_t src_stride3 = src_stride2 + src_stride;
int32_t src_stride4 = src_stride2 << 1;
int32_t dst_stride2 = dst_stride << 1;
int32_t dst_stride3 = dst_stride2 + dst_stride;
int32_t dst_stride4 = dst_stride2 << 1;
filt0 = __lsx_vldrepl_h(filter, 0);
src0 = __lsx_vld(src, 0);
src += src_stride;
for (; loop_cnt--;) {
src1 = __lsx_vld(src, 0);
DUP2_ARG2(__lsx_vldx, src, src_stride, src, src_stride2, src2, src3);
src4 = __lsx_vldx(src, src_stride3);
src += src_stride4;
src5 = __lsx_vld(src, 0);
DUP2_ARG2(__lsx_vldx, src, src_stride, src, src_stride2, src6, src7)
src8 = __lsx_vldx(src, src_stride3);
src += src_stride4;
DUP4_ARG2(__lsx_vilvl_b, src1, src0, src2, src1, src3, src2, src4, src3,
vec0, vec1, vec2, vec3);
DUP4_ARG2(__lsx_vilvl_b, src5, src4, src6, src5, src7, src6, src8, src7,
vec4, vec5, vec6, vec7);
DUP4_ARG2(__lsx_vdp2_h_bu, vec0, filt0, vec1, filt0, vec2, filt0, vec3,
filt0, tmp0, tmp1, tmp2, tmp3);
DUP2_ARG3(__lsx_vssrarni_bu_h, tmp1, tmp0, FILTER_BITS, tmp3, tmp2,
FILTER_BITS, out0, out1);
__lsx_vstelm_d(out0, dst, 0, 0);
__lsx_vstelm_d(out0, dst + dst_stride, 0, 1);
__lsx_vstelm_d(out1, dst + dst_stride2, 0, 0);
__lsx_vstelm_d(out1, dst + dst_stride3, 0, 1);
dst += dst_stride4;
DUP4_ARG2(__lsx_vdp2_h_bu, vec4, filt0, vec5, filt0, vec6, filt0, vec7,
filt0, tmp0, tmp1, tmp2, tmp3);
DUP2_ARG3(__lsx_vssrarni_bu_h, tmp1, tmp0, FILTER_BITS, tmp3, tmp2,
FILTER_BITS, out0, out1);
__lsx_vstelm_d(out0, dst, 0, 0);
__lsx_vstelm_d(out0, dst + dst_stride, 0, 1);
__lsx_vstelm_d(out1, dst + dst_stride2, 0, 0);
__lsx_vstelm_d(out1, dst + dst_stride3, 0, 1);
dst += dst_stride4;
src0 = src8;
}
}
static void common_vt_2t_8w_lsx(const uint8_t *src, int32_t src_stride,
uint8_t *dst, int32_t dst_stride,
int8_t *filter, int32_t height) {
if (height == 4) {
common_vt_2t_8x4_lsx(src, src_stride, dst, dst_stride, filter);
} else {
common_vt_2t_8x8mult_lsx(src, src_stride, dst, dst_stride, filter, height);
}
}
static void common_vt_2t_16w_lsx(const uint8_t *src, int32_t src_stride,
uint8_t *dst, int32_t dst_stride,
int8_t *filter, int32_t height) {
uint32_t loop_cnt = (height >> 2);
__m128i src0, src1, src2, src3, src4, tmp, tmp0, tmp1;
__m128i vec0, vec1, vec2, vec3, vec4, vec5, vec6, vec7, filt0;
int32_t src_stride2 = src_stride << 1;
int32_t src_stride3 = src_stride2 + src_stride;
int32_t src_stride4 = src_stride2 << 1;
filt0 = __lsx_vldrepl_h(filter, 0);
src0 = __lsx_vld(src, 0);
src += src_stride;
for (; loop_cnt--;) {
src1 = __lsx_vld(src, 0);
DUP2_ARG2(__lsx_vldx, src, src_stride, src, src_stride2, src2, src3);
src4 = __lsx_vldx(src, src_stride3);
src += src_stride4;
DUP2_ARG2(__lsx_vilvl_b, src1, src0, src2, src1, vec0, vec2);
DUP2_ARG2(__lsx_vilvh_b, src1, src0, src2, src1, vec1, vec3);
DUP2_ARG2(__lsx_vdp2_h_bu, vec0, filt0, vec1, filt0, tmp0, tmp1);
tmp = __lsx_vssrarni_bu_h(tmp1, tmp0, FILTER_BITS);
__lsx_vst(tmp, dst, 0);
dst += dst_stride;
DUP2_ARG2(__lsx_vilvl_b, src3, src2, src4, src3, vec4, vec6);
DUP2_ARG2(__lsx_vilvh_b, src3, src2, src4, src3, vec5, vec7);
DUP2_ARG2(__lsx_vdp2_h_bu, vec2, filt0, vec3, filt0, tmp0, tmp1);
tmp = __lsx_vssrarni_bu_h(tmp1, tmp0, FILTER_BITS);
__lsx_vst(tmp, dst, 0);
dst += dst_stride;
DUP2_ARG2(__lsx_vdp2_h_bu, vec4, filt0, vec5, filt0, tmp0, tmp1);
tmp = __lsx_vssrarni_bu_h(tmp1, tmp0, FILTER_BITS);
__lsx_vst(tmp, dst, 0);
dst += dst_stride;
DUP2_ARG2(__lsx_vdp2_h_bu, vec6, filt0, vec7, filt0, tmp0, tmp1);
tmp = __lsx_vssrarni_bu_h(tmp1, tmp0, FILTER_BITS);
__lsx_vst(tmp, dst, 0);
dst += dst_stride;
src0 = src4;
}
}
static void common_vt_2t_32w_lsx(const uint8_t *src, int32_t src_stride,
uint8_t *dst, int32_t dst_stride,
int8_t *filter, int32_t height) {
uint32_t loop_cnt = (height >> 2);
__m128i src0, src1, src2, src3, src4, src5, src6, src7, src8, src9;
__m128i vec0, vec1, vec2, vec3, vec4, vec5, vec6, vec7, filt0;
__m128i tmp, tmp0, tmp1;
int32_t src_stride2 = src_stride << 1;
int32_t src_stride3 = src_stride2 + src_stride;
int32_t src_stride4 = src_stride2 << 1;
int32_t dst_stride2 = dst_stride << 1;
int32_t dst_stride3 = dst_stride2 + dst_stride;
uint8_t *src_tmp;
filt0 = __lsx_vldrepl_h(filter, 0);
DUP2_ARG2(__lsx_vld, src, 0, src, 16, src0, src5);
src += src_stride;
src_tmp = src + 16;
for (; loop_cnt--;) {
DUP2_ARG2(__lsx_vld, src, 0, src_tmp, 0, src1, src6);
DUP4_ARG2(__lsx_vldx, src, src_stride, src_tmp, src_stride, src,
src_stride2, src_tmp, src_stride2, src2, src7, src3, src8);
DUP2_ARG2(__lsx_vldx, src, src_stride3, src_tmp, src_stride3, src4, src9);
DUP2_ARG2(__lsx_vilvl_b, src1, src0, src2, src1, vec0, vec2);
DUP2_ARG2(__lsx_vilvh_b, src1, src0, src2, src1, vec1, vec3);
src += src_stride4;
src_tmp += src_stride4;
DUP2_ARG2(__lsx_vdp2_h_bu, vec0, filt0, vec1, filt0, tmp0, tmp1);
tmp = __lsx_vssrarni_bu_h(tmp1, tmp0, FILTER_BITS);
__lsx_vst(tmp, dst, 0);
DUP2_ARG2(__lsx_vdp2_h_bu, vec2, filt0, vec3, filt0, tmp0, tmp1);
tmp = __lsx_vssrarni_bu_h(tmp1, tmp0, FILTER_BITS);
__lsx_vstx(tmp, dst, dst_stride);
DUP2_ARG2(__lsx_vilvl_b, src3, src2, src4, src3, vec4, vec6);
DUP2_ARG2(__lsx_vilvh_b, src3, src2, src4, src3, vec5, vec7);
DUP2_ARG2(__lsx_vdp2_h_bu, vec4, filt0, vec5, filt0, tmp0, tmp1);
tmp = __lsx_vssrarni_bu_h(tmp1, tmp0, FILTER_BITS);
__lsx_vstx(tmp, dst, dst_stride2);
DUP2_ARG2(__lsx_vdp2_h_bu, vec6, filt0, vec7, filt0, tmp0, tmp1);
tmp = __lsx_vssrarni_bu_h(tmp1, tmp0, FILTER_BITS);
__lsx_vstx(tmp, dst, dst_stride3);
DUP2_ARG2(__lsx_vilvl_b, src6, src5, src7, src6, vec0, vec2);
DUP2_ARG2(__lsx_vilvh_b, src6, src5, src7, src6, vec1, vec3);
DUP2_ARG2(__lsx_vdp2_h_bu, vec0, filt0, vec1, filt0, tmp0, tmp1);
tmp = __lsx_vssrarni_bu_h(tmp1, tmp0, FILTER_BITS);
__lsx_vst(tmp, dst, 16);
DUP2_ARG2(__lsx_vdp2_h_bu, vec2, filt0, vec3, filt0, tmp0, tmp1);
tmp = __lsx_vssrarni_bu_h(tmp1, tmp0, FILTER_BITS);
dst += dst_stride;
__lsx_vst(tmp, dst, 16);
DUP2_ARG2(__lsx_vilvl_b, src8, src7, src9, src8, vec4, vec6);
DUP2_ARG2(__lsx_vilvh_b, src8, src7, src9, src8, vec5, vec7);
DUP2_ARG2(__lsx_vdp2_h_bu, vec4, filt0, vec5, filt0, tmp0, tmp1);
tmp = __lsx_vssrarni_bu_h(tmp1, tmp0, FILTER_BITS);
dst += dst_stride;
__lsx_vst(tmp, dst, 16);
DUP2_ARG2(__lsx_vdp2_h_bu, vec6, filt0, vec7, filt0, tmp0, tmp1);
tmp = __lsx_vssrarni_bu_h(tmp1, tmp0, FILTER_BITS);
dst += dst_stride;
__lsx_vst(tmp, dst, 16);
dst += dst_stride;
src0 = src4;
src5 = src9;
}
}
static void common_vt_2t_64w_lsx(const uint8_t *src, int32_t src_stride,
uint8_t *dst, int32_t dst_stride,
int8_t *filter, int32_t height) {
uint32_t loop_cnt = (height >> 1);
__m128i src0, src1, src2, src3, src4, src5, src6, src7, src8, src9, src10;
__m128i src11, vec0, vec1, vec2, vec3, vec4, vec5, vec6, vec7, filt0;
__m128i tmp, tmp0, tmp1;
int32_t src_stride2 = src_stride << 1;
int32_t dst_stride2 = dst_stride << 1;
uint8_t *dst_tmp1 = dst + dst_stride;
filt0 = __lsx_vldrepl_h(filter, 0);
DUP4_ARG2(__lsx_vld, src, 0, src, 16, src, 32, src, 48, src0, src3, src6,
src9);
src += src_stride;
for (; loop_cnt--;) {
uint8_t *src_tmp0 = src + src_stride;
DUP4_ARG2(__lsx_vld, src, 0, src, 16, src, 32, src, 48, src1, src4, src7,
src10);
DUP4_ARG2(__lsx_vld, src_tmp0, 0, src_tmp0, 16, src_tmp0, 32, src_tmp0, 48,
src2, src5, src8, src11);
src += src_stride2;
DUP2_ARG2(__lsx_vilvl_b, src1, src0, src2, src1, vec0, vec2);
DUP2_ARG2(__lsx_vilvh_b, src1, src0, src2, src1, vec1, vec3);
DUP2_ARG2(__lsx_vdp2_h_bu, vec0, filt0, vec1, filt0, tmp0, tmp1);
tmp = __lsx_vssrarni_bu_h(tmp1, tmp0, FILTER_BITS);
__lsx_vst(tmp, dst, 0);
DUP2_ARG2(__lsx_vdp2_h_bu, vec2, filt0, vec3, filt0, tmp0, tmp1);
tmp = __lsx_vssrarni_bu_h(tmp1, tmp0, FILTER_BITS);
__lsx_vst(tmp, dst_tmp1, 0);
DUP2_ARG2(__lsx_vilvl_b, src4, src3, src5, src4, vec4, vec6);
DUP2_ARG2(__lsx_vilvh_b, src4, src3, src5, src4, vec5, vec7);
DUP2_ARG2(__lsx_vdp2_h_bu, vec4, filt0, vec5, filt0, tmp0, tmp1);
tmp = __lsx_vssrarni_bu_h(tmp1, tmp0, FILTER_BITS);
__lsx_vst(tmp, dst, 16);
DUP2_ARG2(__lsx_vdp2_h_bu, vec6, filt0, vec7, filt0, tmp0, tmp1);
tmp = __lsx_vssrarni_bu_h(tmp1, tmp0, FILTER_BITS);
__lsx_vst(tmp, dst_tmp1, 16);
DUP2_ARG2(__lsx_vilvl_b, src7, src6, src8, src7, vec0, vec2);
DUP2_ARG2(__lsx_vilvh_b, src7, src6, src8, src7, vec1, vec3);
DUP2_ARG2(__lsx_vdp2_h_bu, vec0, filt0, vec1, filt0, tmp0, tmp1);
tmp = __lsx_vssrarni_bu_h(tmp1, tmp0, FILTER_BITS);
__lsx_vst(tmp, dst, 32);
DUP2_ARG2(__lsx_vdp2_h_bu, vec2, filt0, vec3, filt0, tmp0, tmp1);
tmp = __lsx_vssrarni_bu_h(tmp1, tmp0, FILTER_BITS);
__lsx_vst(tmp, dst_tmp1, 32);
DUP2_ARG2(__lsx_vilvl_b, src10, src9, src11, src10, vec4, vec6);
DUP2_ARG2(__lsx_vilvh_b, src10, src9, src11, src10, vec5, vec7);
DUP2_ARG2(__lsx_vdp2_h_bu, vec4, filt0, vec5, filt0, tmp0, tmp1);
tmp = __lsx_vssrarni_bu_h(tmp1, tmp0, FILTER_BITS);
__lsx_vst(tmp, dst, 48);
DUP2_ARG2(__lsx_vdp2_h_bu, vec6, filt0, vec7, filt0, tmp0, tmp1);
tmp = __lsx_vssrarni_bu_h(tmp1, tmp0, FILTER_BITS);
__lsx_vst(tmp, dst_tmp1, 48);
dst += dst_stride2;
dst_tmp1 += dst_stride2;
src0 = src2;
src3 = src5;
src6 = src8;
src9 = src11;
}
}
void vpx_convolve8_vert_lsx(const uint8_t *src, ptrdiff_t src_stride,
uint8_t *dst, ptrdiff_t dst_stride,
const InterpKernel *filter, int x0_q4,
int32_t x_step_q4, int y0_q4, int y_step_q4, int w,
int h) {
const int16_t *const filter_y = filter[y0_q4];
int8_t cnt, filt_ver[8];
assert(y_step_q4 == 16);
assert(((const int32_t *)filter_y)[1] != 0x800000);
for (cnt = 8; cnt--;) {
filt_ver[cnt] = filter_y[cnt];
}
if (vpx_get_filter_taps(filter_y) == 2) {
switch (w) {
case 4:
common_vt_2t_4w_lsx(src, (int32_t)src_stride, dst, (int32_t)dst_stride,
&filt_ver[3], h);
break;
case 8:
common_vt_2t_8w_lsx(src, (int32_t)src_stride, dst, (int32_t)dst_stride,
&filt_ver[3], h);
break;
case 16:
common_vt_2t_16w_lsx(src, (int32_t)src_stride, dst, (int32_t)dst_stride,
&filt_ver[3], h);
break;
case 32:
common_vt_2t_32w_lsx(src, (int32_t)src_stride, dst, (int32_t)dst_stride,
&filt_ver[3], h);
break;
case 64:
common_vt_2t_64w_lsx(src, (int32_t)src_stride, dst, (int32_t)dst_stride,
&filt_ver[3], h);
break;
default:
vpx_convolve8_vert_c(src, src_stride, dst, dst_stride, filter, x0_q4,
x_step_q4, y0_q4, y_step_q4, w, h);
break;
}
} else {
switch (w) {
case 4:
common_vt_8t_4w_lsx(src, (int32_t)src_stride, dst, (int32_t)dst_stride,
filt_ver, h);
break;
case 8:
common_vt_8t_8w_lsx(src, (int32_t)src_stride, dst, (int32_t)dst_stride,
filt_ver, h);
break;
case 16:
common_vt_8t_16w_lsx(src, (int32_t)src_stride, dst, (int32_t)dst_stride,
filt_ver, h);
break;
case 32:
common_vt_8t_32w_lsx(src, (int32_t)src_stride, dst, (int32_t)dst_stride,
filt_ver, h);
break;
case 64:
common_vt_8t_64w_lsx(src, (int32_t)src_stride, dst, (int32_t)dst_stride,
filt_ver, h);
break;
default:
vpx_convolve8_vert_c(src, src_stride, dst, dst_stride, filter, x0_q4,
x_step_q4, y0_q4, y_step_q4, w, h);
break;
}
}
}
|
b19e1feb28b1e91d80e2032c8adf6d30d039feef
|
0744dcc5394cebf57ebcba343747af6871b67017
|
/framework/src/arastorage/aql_exec.c
|
1aae9979b9755b7a91b8add73cb46cb877aa6612
|
[
"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
| 8,752
|
c
|
aql_exec.c
|
/****************************************************************************
*
* Copyright 2016 Samsung Electronics All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*
****************************************************************************/
/*
* Copyright (c) 2010, Swedish Institute of Computer Science
* 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 Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE 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 INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* This file is part of the Contiki operating system.
*
*/
/**
* \file
* Query execution functions for AQL.
* \author
* Nicolas Tsiftes <nvt@sics.se>
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include "db_debug.h"
#include "storage.h"
#include "relation.h"
#include "result.h"
#include "aql.h"
/****************************************************************************
* Private Functions
****************************************************************************/
db_result_t aql_init_handle(db_handle_t **handle)
{
*handle = NULL;
*handle = (db_handle_t *)malloc(sizeof(db_handle_t));
if (*handle == NULL) {
return DB_ALLOCATION_ERROR;
}
memset((*handle), 0, sizeof(db_handle_t));
DB_LOG_D("init handle!\n");
return DB_OK;
}
db_result_t aql_deinit_handle(db_handle_t **handle)
{
db_result_t res;
if (handle == NULL || *handle == NULL) {
return DB_ARGUMENT_ERROR;
}
res = DB_OK;
if ((*handle)->rel != NULL) {
res = relation_release((*handle)->rel);
if (DB_ERROR(res)) {
return res;
}
}
if ((*handle)->result_rel != NULL) {
res = relation_release((*handle)->result_rel);
if (DB_ERROR(res)) {
return res;
}
}
if ((*handle)->tuple != NULL) {
free((*handle)->tuple);
(*handle)->tuple = NULL;
}
if ((*handle)->lvm_instance != NULL) {
free((*handle)->lvm_instance);
(*handle)->lvm_instance = NULL;
}
if ((*handle)->attr_map != NULL) {
free((*handle)->attr_map);
(*handle)->attr_map = NULL;
}
free(*handle);
*handle = NULL;
DB_LOG_D("deinit handle!\n");
return res;
}
/****************************************************************************
* Public Functions
****************************************************************************/
db_result_t aql_get_parse_result(char *format, aql_adt_t *adt)
{
if (format == NULL) {
return DB_ARGUMENT_ERROR;
}
if (AQL_ERROR(aql_parse(adt, format))) {
return DB_PARSING_ERROR;
}
return DB_OK;
}
relation_t *aql_get_relation(aql_adt_t *adt)
{
int first_rel_arg;
/* If the ASSIGN flag is set, the first relation in the array is
the desired result relation. */
first_rel_arg = ! !(adt->flags & AQL_FLAG_ASSIGN);
return relation_load(adt->relations[first_rel_arg]);
}
db_result_t db_exec(char *format)
{
db_result_t res;
aql_adt_t adt;
relation_t *rel = NULL;
aql_attribute_t *attr;
attribute_t *relattr = NULL;
uint32_t optype;
res = aql_get_parse_result(format, &adt);
if (DB_ERROR(res)) {
DB_LOG_E("DB : Parsing Error in db_create : %d\n", res);
return DB_PARSING_ERROR;
}
optype = AQL_GET_OP_TYPE(AQL_GET_TYPE(&adt));
if (optype == AQL_OP_TYPE_QUERY) {
DB_LOG_E("DB : AQL OP TYPE Error \n");
return DB_ARGUMENT_ERROR;
}
optype = AQL_GET_EXEC_TYPE(AQL_GET_TYPE(&adt));
if (optype != AQL_TYPE_CREATE_RELATION) {
rel = aql_get_relation(&adt);
if (rel == NULL) {
DB_LOG_E("DB : get relation Failed\n");
return DB_RELATIONAL_ERROR;
}
}
res = DB_RELATIONAL_ERROR;
switch (optype) {
case AQL_TYPE_CREATE_ATTRIBUTE:
attr = &(adt.attributes[0]);
if (relation_attribute_add(rel, DB_STORAGE, attr->name, attr->domain, attr->element_size) != NULL) {
res = DB_OK;
}
break;
case AQL_TYPE_CREATE_INDEX:
relattr = relation_attribute_get(rel, adt.attributes[0].name);
if (relattr == NULL) {
res = DB_NAME_ERROR;
break;
}
res = index_create(AQL_GET_INDEX_TYPE(&adt), rel, relattr);
break;
case AQL_TYPE_CREATE_RELATION:
if (relation_create(adt.relations[0], DB_STORAGE) != NULL) {
res = DB_OK;
}
break;
case AQL_TYPE_INSERT:
if (relation_cardinality(rel) < DB_TUPLE_LIMIT) {
res = relation_insert(rel, adt.values);
if (DB_SUCCESS(res)) {
res = DB_OK;
}
} else {
res = DB_LIMIT_ERROR;
}
break;
case AQL_TYPE_REMOVE_ATTRIBUTE:
res = relation_attribute_remove(rel, adt.attributes[0].name);
break;
case AQL_TYPE_REMOVE_INDEX:
relattr = relation_attribute_get(rel, adt.attributes[0].name);
if (relattr != NULL) {
index_load(rel, relattr);
if (relattr->index != NULL) {
res = index_destroy(relattr->index);
} else {
res = DB_OK;
}
} else {
res = DB_NAME_ERROR;
}
break;
case AQL_TYPE_REMOVE_RELATION:
res = relation_remove(rel, 1);
break;
default:
break;
}
if (rel != NULL) {
relation_release(rel);
}
return res;
}
db_cursor_t *db_query(char *format)
{
aql_adt_t adt;
relation_t *rel;
uint32_t optype;
db_handle_t *handler;
attribute_t *attr_ptr;
db_cursor_t *cursor;
handler = NULL;
cursor = NULL;
if (DB_ERROR(aql_get_parse_result(format, &adt))) {
DB_LOG_E("DB : Parsing Error in db_create\n");
return NULL;
}
optype = AQL_GET_OP_TYPE(AQL_GET_TYPE(&adt));
if (optype != AQL_OP_TYPE_QUERY) {
DB_LOG_E("DB : AQL OP TYPE Error \n");
return NULL;
}
#ifdef CONFIG_ARASTORAGE_ENABLE_WRITE_BUFFER
if (DB_SUCCESS(storage_flush_insert_buffer())) {
DB_LOG_D("DB : flush insert buffer!!\n");
}
#endif
rel = aql_get_relation(&adt);
if (rel == NULL) {
return NULL;
}
optype = AQL_GET_EXEC_TYPE(AQL_GET_TYPE(&adt));
switch (optype) {
case AQL_TYPE_REMOVE_TUPLES:
/* Overwrite the attribute array with a full copy of the original
relation's attributes. */
adt.attribute_count = 0;
for (attr_ptr = list_head(rel->attributes); attr_ptr != NULL; attr_ptr = attr_ptr->next) {
AQL_ADD_ATTRIBUTE(&adt, attr_ptr->name, DOMAIN_UNSPECIFIED, 0);
}
/* FALLTHROUGH */
case AQL_TYPE_SELECT:
if (DB_ERROR(aql_init_handle(&handler))) {
DB_LOG_E("DB: Init handle failed\n");
goto errout;
}
if (DB_ERROR(relation_select(&handler, rel, &adt))) {
DB_LOG_E("DB: Failed relation_select\n");
goto errout;
}
cursor = relation_process_result(handler);
if (cursor == NULL) {
DB_LOG_E("DB: Failed to process cursor tuples\n");
goto errout;
}
break;
case AQL_TYPE_FLUSH:
//TODO flush operation will be implemented later
default:
break;
}
if (rel != NULL) {
if (handler == NULL || !(handler->flags & DB_HANDLE_FLAG_PROCESSING)) {
relation_release(rel);
}
}
aql_deinit_handle(&handler);
return cursor;
errout:
if (rel != NULL) {
relation_release(rel);
}
aql_deinit_handle(&handler);
return NULL;
}
|
7dd39aff6749913765ecee4871b19abcbb802b06
|
88ae8695987ada722184307301e221e1ba3cc2fa
|
/third_party/ffmpeg/libavcodec/mips/aacdec_mips.c
|
cd357cedbc70f933c2b662f921d51f95e58a6f48
|
[
"Apache-2.0",
"LGPL-2.0-or-later",
"MIT",
"GPL-1.0-or-later",
"BSD-3-Clause",
"LGPL-2.1-only",
"LGPL-3.0-only",
"GPL-2.0-only",
"LGPL-2.1-or-later",
"GPL-3.0-or-later",
"LGPL-3.0-or-later",
"IJG",
"LicenseRef-scancode-other-permissive",
"GPL-2.0-or-later",
"GPL-3.0-only"
] |
permissive
|
iridium-browser/iridium-browser
|
71d9c5ff76e014e6900b825f67389ab0ccd01329
|
5ee297f53dc7f8e70183031cff62f37b0f19d25f
|
refs/heads/master
| 2023-08-03T16:44:16.844552
| 2023-07-20T15:17:00
| 2023-07-23T16:09:30
| 220,016,632
| 341
| 40
|
BSD-3-Clause
| 2021-08-13T13:54:45
| 2019-11-06T14:32:31
| null |
UTF-8
|
C
| false
| false
| 18,988
|
c
|
aacdec_mips.c
|
/*
* Copyright (c) 2012
* MIPS Technologies, Inc., California.
*
* 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 MIPS Technologies, Inc., 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 MIPS TECHNOLOGIES, INC. ``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 MIPS TECHNOLOGIES, INC. 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.
*
* Authors: Darko Laus (darko@mips.com)
* Djordje Pesut (djordje@mips.com)
* Mirjana Vulin (mvulin@mips.com)
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file
* Reference: libavcodec/aacdec.c
*/
#include "libavutil/attributes.h"
#include "libavcodec/aac.h"
#include "aacdec_mips.h"
#include "libavcodec/aactab.h"
#include "libavcodec/sinewin.h"
#include "libavutil/mips/asmdefs.h"
#if HAVE_INLINE_ASM
#if HAVE_MIPSFPU
static av_always_inline void float_copy(float *dst, const float *src, int count)
{
// Copy 'count' floats from src to dst
const float *loop_end = src + count;
int temp[8];
// count must be a multiple of 8
av_assert2(count % 8 == 0);
// loop unrolled 8 times
__asm__ volatile (
".set push \n\t"
".set noreorder \n\t"
"1: \n\t"
"lw %[temp0], 0(%[src]) \n\t"
"lw %[temp1], 4(%[src]) \n\t"
"lw %[temp2], 8(%[src]) \n\t"
"lw %[temp3], 12(%[src]) \n\t"
"lw %[temp4], 16(%[src]) \n\t"
"lw %[temp5], 20(%[src]) \n\t"
"lw %[temp6], 24(%[src]) \n\t"
"lw %[temp7], 28(%[src]) \n\t"
PTR_ADDIU "%[src], %[src], 32 \n\t"
"sw %[temp0], 0(%[dst]) \n\t"
"sw %[temp1], 4(%[dst]) \n\t"
"sw %[temp2], 8(%[dst]) \n\t"
"sw %[temp3], 12(%[dst]) \n\t"
"sw %[temp4], 16(%[dst]) \n\t"
"sw %[temp5], 20(%[dst]) \n\t"
"sw %[temp6], 24(%[dst]) \n\t"
"sw %[temp7], 28(%[dst]) \n\t"
"bne %[src], %[loop_end], 1b \n\t"
PTR_ADDIU "%[dst], %[dst], 32 \n\t"
".set pop \n\t"
: [temp0]"=&r"(temp[0]), [temp1]"=&r"(temp[1]),
[temp2]"=&r"(temp[2]), [temp3]"=&r"(temp[3]),
[temp4]"=&r"(temp[4]), [temp5]"=&r"(temp[5]),
[temp6]"=&r"(temp[6]), [temp7]"=&r"(temp[7]),
[src]"+r"(src), [dst]"+r"(dst)
: [loop_end]"r"(loop_end)
: "memory"
);
}
static av_always_inline int lcg_random(unsigned previous_val)
{
union { unsigned u; int s; } v = { previous_val * 1664525u + 1013904223 };
return v.s;
}
static void imdct_and_windowing_mips(AACContext *ac, SingleChannelElement *sce)
{
IndividualChannelStream *ics = &sce->ics;
float *in = sce->coeffs;
float *out = sce->ret;
float *saved = sce->saved;
const float *swindow = ics->use_kb_window[0] ? ff_aac_kbd_short_128 : ff_sine_128;
const float *lwindow_prev = ics->use_kb_window[1] ? ff_aac_kbd_long_1024 : ff_sine_1024;
const float *swindow_prev = ics->use_kb_window[1] ? ff_aac_kbd_short_128 : ff_sine_128;
float *buf = ac->buf_mdct;
int i;
if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) {
for (i = 0; i < 1024; i += 128)
ac->mdct128_fn(ac->mdct128, buf + i, in + i, sizeof(float));
} else
ac->mdct1024_fn(ac->mdct1024, buf, in, sizeof(float));
/* window overlapping
* NOTE: To simplify the overlapping code, all 'meaningless' short to long
* and long to short transitions are considered to be short to short
* transitions. This leaves just two cases (long to long and short to short)
* with a little special sauce for EIGHT_SHORT_SEQUENCE.
*/
if ((ics->window_sequence[1] == ONLY_LONG_SEQUENCE || ics->window_sequence[1] == LONG_STOP_SEQUENCE) &&
(ics->window_sequence[0] == ONLY_LONG_SEQUENCE || ics->window_sequence[0] == LONG_START_SEQUENCE)) {
ac->fdsp->vector_fmul_window( out, saved, buf, lwindow_prev, 512);
} else {
float_copy(out, saved, 448);
if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) {
{
float wi;
float wj;
int i;
float temp0, temp1, temp2, temp3;
float *dst0 = out + 448 + 0*128;
float *dst1 = dst0 + 64 + 63;
float *dst2 = saved + 63;
float *win0 = (float*)swindow;
float *win1 = win0 + 64 + 63;
float *win0_prev = (float*)swindow_prev;
float *win1_prev = win0_prev + 64 + 63;
float *src0_prev = saved + 448;
float *src1_prev = buf + 0*128 + 63;
float *src0 = buf + 0*128 + 64;
float *src1 = buf + 1*128 + 63;
for(i = 0; i < 64; i++)
{
temp0 = src0_prev[0];
temp1 = src1_prev[0];
wi = *win0_prev;
wj = *win1_prev;
temp2 = src0[0];
temp3 = src1[0];
dst0[0] = temp0 * wj - temp1 * wi;
dst1[0] = temp0 * wi + temp1 * wj;
wi = *win0;
wj = *win1;
temp0 = src0[128];
temp1 = src1[128];
dst0[128] = temp2 * wj - temp3 * wi;
dst1[128] = temp2 * wi + temp3 * wj;
temp2 = src0[256];
temp3 = src1[256];
dst0[256] = temp0 * wj - temp1 * wi;
dst1[256] = temp0 * wi + temp1 * wj;
dst0[384] = temp2 * wj - temp3 * wi;
dst1[384] = temp2 * wi + temp3 * wj;
temp0 = src0[384];
temp1 = src1[384];
dst0[512] = temp0 * wj - temp1 * wi;
dst2[0] = temp0 * wi + temp1 * wj;
src0++;
src1--;
src0_prev++;
src1_prev--;
win0++;
win1--;
win0_prev++;
win1_prev--;
dst0++;
dst1--;
dst2--;
}
}
} else {
ac->fdsp->vector_fmul_window(out + 448, saved + 448, buf, swindow_prev, 64);
float_copy(out + 576, buf + 64, 448);
}
}
// buffer update
if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) {
ac->fdsp->vector_fmul_window(saved + 64, buf + 4*128 + 64, buf + 5*128, swindow, 64);
ac->fdsp->vector_fmul_window(saved + 192, buf + 5*128 + 64, buf + 6*128, swindow, 64);
ac->fdsp->vector_fmul_window(saved + 320, buf + 6*128 + 64, buf + 7*128, swindow, 64);
float_copy(saved + 448, buf + 7*128 + 64, 64);
} else if (ics->window_sequence[0] == LONG_START_SEQUENCE) {
float_copy(saved, buf + 512, 448);
float_copy(saved + 448, buf + 7*128 + 64, 64);
} else { // LONG_STOP or ONLY_LONG
float_copy(saved, buf + 512, 512);
}
}
static void apply_ltp_mips(AACContext *ac, SingleChannelElement *sce)
{
const LongTermPrediction *ltp = &sce->ics.ltp;
const uint16_t *offsets = sce->ics.swb_offset;
int i, sfb;
int j, k;
if (sce->ics.window_sequence[0] != EIGHT_SHORT_SEQUENCE) {
float *predTime = sce->ret;
float *predFreq = ac->buf_mdct;
float *p_predTime;
int16_t num_samples = 2048;
if (ltp->lag < 1024)
num_samples = ltp->lag + 1024;
j = (2048 - num_samples) >> 2;
k = (2048 - num_samples) & 3;
p_predTime = &predTime[num_samples];
for (i = 0; i < num_samples; i++)
predTime[i] = sce->ltp_state[i + 2048 - ltp->lag] * ltp->coef;
for (i = 0; i < j; i++) {
/* loop unrolled 4 times */
__asm__ volatile (
"sw $0, 0(%[p_predTime]) \n\t"
"sw $0, 4(%[p_predTime]) \n\t"
"sw $0, 8(%[p_predTime]) \n\t"
"sw $0, 12(%[p_predTime]) \n\t"
PTR_ADDIU "%[p_predTime], %[p_predTime], 16 \n\t"
: [p_predTime]"+r"(p_predTime)
:
: "memory"
);
}
for (i = 0; i < k; i++) {
__asm__ volatile (
"sw $0, 0(%[p_predTime]) \n\t"
PTR_ADDIU "%[p_predTime], %[p_predTime], 4 \n\t"
: [p_predTime]"+r"(p_predTime)
:
: "memory"
);
}
ac->windowing_and_mdct_ltp(ac, predFreq, predTime, &sce->ics);
if (sce->tns.present)
ac->apply_tns(predFreq, &sce->tns, &sce->ics, 0);
for (sfb = 0; sfb < FFMIN(sce->ics.max_sfb, MAX_LTP_LONG_SFB); sfb++)
if (ltp->used[sfb])
for (i = offsets[sfb]; i < offsets[sfb + 1]; i++)
sce->coeffs[i] += predFreq[i];
}
}
static av_always_inline void fmul_and_reverse(float *dst, const float *src0, const float *src1, int count)
{
/* Multiply 'count' floats in src0 by src1 and store the results in dst in reverse */
/* This should be equivalent to a normal fmul, followed by reversing dst */
// count must be a multiple of 4
av_assert2(count % 4 == 0);
// move src0 and src1 to the last element of their arrays
src0 += count - 1;
src1 += count - 1;
for (; count > 0; count -= 4){
float temp[12];
/* loop unrolled 4 times */
__asm__ volatile (
"lwc1 %[temp0], 0(%[ptr2]) \n\t"
"lwc1 %[temp1], -4(%[ptr2]) \n\t"
"lwc1 %[temp2], -8(%[ptr2]) \n\t"
"lwc1 %[temp3], -12(%[ptr2]) \n\t"
"lwc1 %[temp4], 0(%[ptr3]) \n\t"
"lwc1 %[temp5], -4(%[ptr3]) \n\t"
"lwc1 %[temp6], -8(%[ptr3]) \n\t"
"lwc1 %[temp7], -12(%[ptr3]) \n\t"
"mul.s %[temp8], %[temp0], %[temp4] \n\t"
"mul.s %[temp9], %[temp1], %[temp5] \n\t"
"mul.s %[temp10], %[temp2], %[temp6] \n\t"
"mul.s %[temp11], %[temp3], %[temp7] \n\t"
"swc1 %[temp8], 0(%[ptr1]) \n\t"
"swc1 %[temp9], 4(%[ptr1]) \n\t"
"swc1 %[temp10], 8(%[ptr1]) \n\t"
"swc1 %[temp11], 12(%[ptr1]) \n\t"
PTR_ADDIU "%[ptr1], %[ptr1], 16 \n\t"
PTR_ADDIU "%[ptr2], %[ptr2], -16 \n\t"
PTR_ADDIU "%[ptr3], %[ptr3], -16 \n\t"
: [temp0]"=&f"(temp[0]), [temp1]"=&f"(temp[1]),
[temp2]"=&f"(temp[2]), [temp3]"=&f"(temp[3]),
[temp4]"=&f"(temp[4]), [temp5]"=&f"(temp[5]),
[temp6]"=&f"(temp[6]), [temp7]"=&f"(temp[7]),
[temp8]"=&f"(temp[8]), [temp9]"=&f"(temp[9]),
[temp10]"=&f"(temp[10]), [temp11]"=&f"(temp[11]),
[ptr1]"+r"(dst), [ptr2]"+r"(src0), [ptr3]"+r"(src1)
:
: "memory"
);
}
}
static void update_ltp_mips(AACContext *ac, SingleChannelElement *sce)
{
IndividualChannelStream *ics = &sce->ics;
float *saved = sce->saved;
float *saved_ltp = sce->coeffs;
const float *lwindow = ics->use_kb_window[0] ? ff_aac_kbd_long_1024 : ff_sine_1024;
const float *swindow = ics->use_kb_window[0] ? ff_aac_kbd_short_128 : ff_sine_128;
uint32_t temp0, temp1, temp2, temp3, temp4, temp5, temp6, temp7;
if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) {
float *p_saved_ltp = saved_ltp + 576;
float *loop_end1 = p_saved_ltp + 448;
float_copy(saved_ltp, saved, 512);
/* loop unrolled 8 times */
__asm__ volatile (
"1: \n\t"
"sw $0, 0(%[p_saved_ltp]) \n\t"
"sw $0, 4(%[p_saved_ltp]) \n\t"
"sw $0, 8(%[p_saved_ltp]) \n\t"
"sw $0, 12(%[p_saved_ltp]) \n\t"
"sw $0, 16(%[p_saved_ltp]) \n\t"
"sw $0, 20(%[p_saved_ltp]) \n\t"
"sw $0, 24(%[p_saved_ltp]) \n\t"
"sw $0, 28(%[p_saved_ltp]) \n\t"
PTR_ADDIU "%[p_saved_ltp],%[p_saved_ltp], 32 \n\t"
"bne %[p_saved_ltp], %[loop_end1], 1b \n\t"
: [p_saved_ltp]"+r"(p_saved_ltp)
: [loop_end1]"r"(loop_end1)
: "memory"
);
ac->fdsp->vector_fmul_reverse(saved_ltp + 448, ac->buf_mdct + 960, &swindow[64], 64);
fmul_and_reverse(saved_ltp + 512, ac->buf_mdct + 960, swindow, 64);
} else if (ics->window_sequence[0] == LONG_START_SEQUENCE) {
float *buff0 = saved;
float *buff1 = saved_ltp;
float *loop_end = saved + 448;
/* loop unrolled 8 times */
__asm__ volatile (
".set push \n\t"
".set noreorder \n\t"
"1: \n\t"
"lw %[temp0], 0(%[src]) \n\t"
"lw %[temp1], 4(%[src]) \n\t"
"lw %[temp2], 8(%[src]) \n\t"
"lw %[temp3], 12(%[src]) \n\t"
"lw %[temp4], 16(%[src]) \n\t"
"lw %[temp5], 20(%[src]) \n\t"
"lw %[temp6], 24(%[src]) \n\t"
"lw %[temp7], 28(%[src]) \n\t"
PTR_ADDIU "%[src], %[src], 32 \n\t"
"sw %[temp0], 0(%[dst]) \n\t"
"sw %[temp1], 4(%[dst]) \n\t"
"sw %[temp2], 8(%[dst]) \n\t"
"sw %[temp3], 12(%[dst]) \n\t"
"sw %[temp4], 16(%[dst]) \n\t"
"sw %[temp5], 20(%[dst]) \n\t"
"sw %[temp6], 24(%[dst]) \n\t"
"sw %[temp7], 28(%[dst]) \n\t"
"sw $0, 2304(%[dst]) \n\t"
"sw $0, 2308(%[dst]) \n\t"
"sw $0, 2312(%[dst]) \n\t"
"sw $0, 2316(%[dst]) \n\t"
"sw $0, 2320(%[dst]) \n\t"
"sw $0, 2324(%[dst]) \n\t"
"sw $0, 2328(%[dst]) \n\t"
"sw $0, 2332(%[dst]) \n\t"
"bne %[src], %[loop_end], 1b \n\t"
PTR_ADDIU "%[dst], %[dst], 32 \n\t"
".set pop \n\t"
: [temp0]"=&r"(temp0), [temp1]"=&r"(temp1),
[temp2]"=&r"(temp2), [temp3]"=&r"(temp3),
[temp4]"=&r"(temp4), [temp5]"=&r"(temp5),
[temp6]"=&r"(temp6), [temp7]"=&r"(temp7),
[src]"+r"(buff0), [dst]"+r"(buff1)
: [loop_end]"r"(loop_end)
: "memory"
);
ac->fdsp->vector_fmul_reverse(saved_ltp + 448, ac->buf_mdct + 960, &swindow[64], 64);
fmul_and_reverse(saved_ltp + 512, ac->buf_mdct + 960, swindow, 64);
} else { // LONG_STOP or ONLY_LONG
ac->fdsp->vector_fmul_reverse(saved_ltp, ac->buf_mdct + 512, &lwindow[512], 512);
fmul_and_reverse(saved_ltp + 512, ac->buf_mdct + 512, lwindow, 512);
}
float_copy(sce->ltp_state, sce->ltp_state + 1024, 1024);
float_copy(sce->ltp_state + 1024, sce->ret, 1024);
float_copy(sce->ltp_state + 2048, saved_ltp, 1024);
}
#endif /* HAVE_MIPSFPU */
#endif /* HAVE_INLINE_ASM */
void ff_aacdec_init_mips(AACContext *c)
{
#if HAVE_INLINE_ASM
#if HAVE_MIPSFPU
c->imdct_and_windowing = imdct_and_windowing_mips;
c->apply_ltp = apply_ltp_mips;
c->update_ltp = update_ltp_mips;
#endif /* HAVE_MIPSFPU */
#endif /* HAVE_INLINE_ASM */
}
|
a56a17d3e84729e5382af57bc51a259f804503da
|
89db60818afeb3dc7c3b7abe9ceae155f074f7f2
|
/src/cmd/tee.c
|
83db8a08f399dada560e4a6136c023593f056a84
|
[
"bzip2-1.0.6",
"LPL-1.02",
"MIT"
] |
permissive
|
9fans/plan9port
|
63c3d01928c6f8a8617d3ea6ecc05bac72391132
|
65c090346a38a8c30cb242d345aa71060116340c
|
refs/heads/master
| 2023-08-25T17:14:26.233105
| 2023-08-23T13:21:37
| 2023-08-23T18:47:08
| 26,095,474
| 1,645
| 468
|
NOASSERTION
| 2023-09-05T16:55:41
| 2014-11-02T22:40:13
|
C
|
UTF-8
|
C
| false
| false
| 1,062
|
c
|
tee.c
|
/*
* tee-- pipe fitting
*/
#include <u.h>
#include <libc.h>
int uflag;
int aflag;
int openf[100];
char in[8192];
int intignore(void*, char*);
void
main(int argc, char **argv)
{
int i;
int r, n;
ARGBEGIN {
case 'a':
aflag++;
break;
case 'i':
atnotify(intignore, 1);
break;
case 'u':
uflag++;
/* uflag is ignored and undocumented; it's a relic from Unix */
break;
default:
fprint(2, "usage: tee [-ai] [file ...]\n");
exits("usage");
} ARGEND
USED(argc);
n = 0;
while(*argv) {
if(aflag) {
openf[n] = open(argv[0], OWRITE);
if(openf[n] < 0)
openf[n] = create(argv[0], OWRITE, 0666);
seek(openf[n], 0L, 2);
} else
openf[n] = create(argv[0], OWRITE, 0666);
if(openf[n] < 0) {
fprint(2, "tee: cannot open %s: %r\n", argv[0]);
} else
n++;
argv++;
}
openf[n++] = 1;
for(;;) {
r = read(0, in, sizeof in);
if(r <= 0)
exits(nil);
for(i=0; i<n; i++)
write(openf[i], in, r);
}
}
int
intignore(void *a, char *msg)
{
USED(a);
if(strcmp(msg, "interrupt") == 0)
return 1;
return 0;
}
|
89f13685ada9bbb1b4c26f2c95ff3a24a71869b4
|
1231379e557a3094413045721b4c65ce9bae568b
|
/src/generated/linux/path.c.clog.h
|
23f70922add410283c0149decaa398dbbf9fa03e
|
[
"MIT"
] |
permissive
|
microsoft/msquic
|
a63982f1b7d017fb0497e2dce56f1ef527bd6eaa
|
f91ccc2f975225a278bc68238555ed0923e676ba
|
refs/heads/main
| 2023-09-04T01:25:39.133074
| 2023-08-28T18:04:51
| 2023-08-28T18:04:51
| 217,654,199
| 3,641
| 521
|
MIT
| 2023-09-14T14:36:09
| 2019-10-26T04:10:24
|
C
|
UTF-8
|
C
| false
| false
| 4,576
|
h
|
path.c.clog.h
|
#ifndef CLOG_DO_NOT_INCLUDE_HEADER
#include <clog.h>
#endif
#undef TRACEPOINT_PROVIDER
#define TRACEPOINT_PROVIDER CLOG_PATH_C
#undef TRACEPOINT_PROBE_DYNAMIC_LINKAGE
#define TRACEPOINT_PROBE_DYNAMIC_LINKAGE
#undef TRACEPOINT_INCLUDE
#define TRACEPOINT_INCLUDE "path.c.clog.h.lttng.h"
#if !defined(DEF_CLOG_PATH_C) || defined(TRACEPOINT_HEADER_MULTI_READ)
#define DEF_CLOG_PATH_C
#include <lttng/tracepoint.h>
#define __int64 __int64_t
#include "path.c.clog.h.lttng.h"
#endif
#include <lttng/tracepoint-event.h>
#ifndef _clog_MACRO_QuicTraceLogConnInfo
#define _clog_MACRO_QuicTraceLogConnInfo 1
#define QuicTraceLogConnInfo(a, ...) _clog_CAT(_clog_ARGN_SELECTOR(__VA_ARGS__), _clog_CAT(_,a(#a, __VA_ARGS__)))
#endif
#ifdef __cplusplus
extern "C" {
#endif
/*----------------------------------------------------------
// Decoder Ring for PathInitialized
// [conn][%p] Path[%hhu] Initialized
// QuicTraceLogConnInfo(
PathInitialized,
Connection,
"Path[%hhu] Initialized",
Path->ID);
// arg1 = arg1 = Connection = arg1
// arg3 = arg3 = Path->ID = arg3
----------------------------------------------------------*/
#ifndef _clog_4_ARGS_TRACE_PathInitialized
#define _clog_4_ARGS_TRACE_PathInitialized(uniqueId, arg1, encoded_arg_string, arg3)\
tracepoint(CLOG_PATH_C, PathInitialized , arg1, arg3);\
#endif
/*----------------------------------------------------------
// Decoder Ring for PathRemoved
// [conn][%p] Path[%hhu] Removed
// QuicTraceLogConnInfo(
PathRemoved,
Connection,
"Path[%hhu] Removed",
Path->ID);
// arg1 = arg1 = Connection = arg1
// arg3 = arg3 = Path->ID = arg3
----------------------------------------------------------*/
#ifndef _clog_4_ARGS_TRACE_PathRemoved
#define _clog_4_ARGS_TRACE_PathRemoved(uniqueId, arg1, encoded_arg_string, arg3)\
tracepoint(CLOG_PATH_C, PathRemoved , arg1, arg3);\
#endif
/*----------------------------------------------------------
// Decoder Ring for PathValidated
// [conn][%p] Path[%hhu] Validated (%s)
// QuicTraceLogConnInfo(
PathValidated,
Connection,
"Path[%hhu] Validated (%s)",
Path->ID,
ReasonStrings[Reason]);
// arg1 = arg1 = Connection = arg1
// arg3 = arg3 = Path->ID = arg3
// arg4 = arg4 = ReasonStrings[Reason] = arg4
----------------------------------------------------------*/
#ifndef _clog_5_ARGS_TRACE_PathValidated
#define _clog_5_ARGS_TRACE_PathValidated(uniqueId, arg1, encoded_arg_string, arg3, arg4)\
tracepoint(CLOG_PATH_C, PathValidated , arg1, arg3, arg4);\
#endif
/*----------------------------------------------------------
// Decoder Ring for PathActive
// [conn][%p] Path[%hhu] Set active (rebind=%hhu)
// QuicTraceLogConnInfo(
PathActive,
Connection,
"Path[%hhu] Set active (rebind=%hhu)",
Connection->Paths[0].ID,
UdpPortChangeOnly);
// arg1 = arg1 = Connection = arg1
// arg3 = arg3 = Connection->Paths[0].ID = arg3
// arg4 = arg4 = UdpPortChangeOnly = arg4
----------------------------------------------------------*/
#ifndef _clog_5_ARGS_TRACE_PathActive
#define _clog_5_ARGS_TRACE_PathActive(uniqueId, arg1, encoded_arg_string, arg3, arg4)\
tracepoint(CLOG_PATH_C, PathActive , arg1, arg3, arg4);\
#endif
/*----------------------------------------------------------
// Decoder Ring for PathQeoEnabled
// [conn][%p] Path[%hhu] QEO enabled
// QuicTraceLogConnInfo(
PathQeoEnabled,
Connection,
"Path[%hhu] QEO enabled",
Path->ID);
// arg1 = arg1 = Connection = arg1
// arg3 = arg3 = Path->ID = arg3
----------------------------------------------------------*/
#ifndef _clog_4_ARGS_TRACE_PathQeoEnabled
#define _clog_4_ARGS_TRACE_PathQeoEnabled(uniqueId, arg1, encoded_arg_string, arg3)\
tracepoint(CLOG_PATH_C, PathQeoEnabled , arg1, arg3);\
#endif
/*----------------------------------------------------------
// Decoder Ring for PathQeoDisabled
// [conn][%p] Path[%hhu] QEO disabled
// QuicTraceLogConnInfo(
PathQeoDisabled,
Connection,
"Path[%hhu] QEO disabled",
Path->ID);
// arg1 = arg1 = Connection = arg1
// arg3 = arg3 = Path->ID = arg3
----------------------------------------------------------*/
#ifndef _clog_4_ARGS_TRACE_PathQeoDisabled
#define _clog_4_ARGS_TRACE_PathQeoDisabled(uniqueId, arg1, encoded_arg_string, arg3)\
tracepoint(CLOG_PATH_C, PathQeoDisabled , arg1, arg3);\
#endif
#ifdef __cplusplus
}
#endif
#ifdef CLOG_INLINE_IMPLEMENTATION
#include "quic.clog_path.c.clog.h.c"
#endif
|
a39fb241ce5cb0b4c7ca247508d59360c975e54c
|
702de4da7e33dd3197638aa86d54bbf494948657
|
/src/node.c
|
c5a3bfd7b309fb5e1c2890e64154a7bf7a387467
|
[
"MIT",
"FSFAP"
] |
permissive
|
c9s/r3
|
086c3f6ec90a352dc069e0f11f1104c3bdf29a0f
|
91405adda5dadf87e5d884b6cae3ed362caaf11b
|
refs/heads/2.0
| 2023-02-17T21:48:29.714210
| 2023-02-12T02:52:51
| 2023-02-12T02:52:51
| 19,679,590
| 389
| 70
|
MIT
| 2023-09-06T07:07:02
| 2014-05-11T22:52:44
|
C
|
UTF-8
|
C
| false
| false
| 30,607
|
c
|
node.c
|
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <ctype.h>
#include <netinet/in.h>
#include <arpa/inet.h>
// PCRE
#include <pcre.h>
#include "r3.h"
#include "r3_slug.h"
#include "slug.h"
#include "str.h"
#include "r3_debug.h"
#ifdef __GNUC__
# define likely(x) __builtin_expect(!!(x), 1)
# define unlikely(x) __builtin_expect(!!(x), 0)
#else
# define likely(x) !!(x)
# define unlikely(x) !!(x)
#endif
#define CHECK_PTR(ptr) if (ptr == NULL) return NULL;
// String value as the index http://judy.sourceforge.net/doc/JudySL_3x.htm
static int strndiff(const char * d1, const char * d2, unsigned int n) {
const char * o = d1;
while ( *d1 == *d2 && n-- > 0 ) {
d1++;
d2++;
}
return d1 - o;
}
/*
static int strdiff(char * d1, char * d2) {
char * o = d1;
while( *d1 == *d2 ) {
d1++;
d2++;
}
return d1 - o;
}
*/
/**
* Create a node object
*/
R3Node * r3_tree_create(int cap) {
R3Node * n = r3_mem_alloc( sizeof(R3Node) );
memset(n, 0, sizeof(*n));
r3_vector_reserve(&n->edges, n->edges.size + cap);
r3_vector_reserve(&n->routes, n->routes.size + 1);
n->compare_type = NODE_COMPARE_PCRE;
return n;
}
void r3_tree_free(R3Node * tree) {
for (int j=0;j<tree->edges.size;j++) {
r3_edge_free(tree->edges.entries + j);
}
free(tree->edges.entries);
for (int k=0;k<tree->routes.size;k++) {
r3_route_free(tree->routes.entries + k);
}
free(tree->routes.entries);
if (tree->pcre_pattern) {
pcre_free(tree->pcre_pattern);
}
#ifdef PCRE_STUDY_JIT_COMPILE
if (tree->pcre_extra) {
pcre_free_study(tree->pcre_extra);
}
#endif
free(tree->combined_pattern);
free(tree);
tree = NULL;
}
/**
* Connect two node objects, and create an edge object between them.
*/
R3Edge * r3_node_connectl(R3Node * n, const char * pat, int len, int dupl, R3Node *child) {
// find the same sub-pattern, if it does not exist, create one
R3Edge * e;
e = r3_node_find_edge(n, pat, len);
if (e) {
return e;
}
if (dupl) {
pat = strndup(pat, len);
}
// e = r3_edge_createl(pat, len, child);
e = r3_node_append_edge(n);
r3_edge_initl(e, pat, len, child);
// CHECK_PTR(e);
return e;
}
R3Edge * r3_node_append_edge(R3Node *n)
{
r3_vector_reserve(&n->edges, n->edges.size + 1);
R3Edge *new_e = n->edges.entries + n->edges.size++;
memset(new_e, 0, sizeof(*new_e));
return new_e;
}
/**
* Find the existing edge with specified pattern (include slug)
*
* if "pat" is a slug, we should compare with the specified pattern.
*/
R3Edge * r3_node_find_edge(const R3Node * n, const char * pat, unsigned int pat_len) {
R3Edge *edge_entries = n->edges.entries;
R3Edge *e;
unsigned int i;
for (i = 0 ; i < n->edges.size ; i++ ) {
e = edge_entries + i;
// there is a case: "{foo}" vs "{foo:xxx}",
// we should return the match result: full-match or partial-match
if (e->pattern.len == pat_len &&
!strncmp(e->pattern.base, pat, e->pattern.len)) {
return e;
}
}
return NULL;
}
int r3_tree_compile(R3Node *n, char **errstr)
{
unsigned int i;
int ret = 0;
// bool use_slug = r3_node_has_slug_edges(n);
if ( r3_node_has_slug_edges(n) ) {
if (( ret = r3_tree_compile_patterns(n, errstr) )) {
return ret;
}
} else {
// use normal text matching...
n->combined_pattern = NULL;
}
for (i = 0 ; i < n->edges.size ; i++ ) {
if ((ret = r3_tree_compile(n->edges.entries[i].child, errstr))) {
return ret; // stop here if error occurs
}
}
return 0;
}
/**
* This function combines ['/foo', '/bar', '/{slug}'] into (/foo)|(/bar)|/([^/]+)}
*
* Return -1 if error occurs
* Return 0 if success
*/
int r3_tree_compile_patterns(R3Node * n, char **errstr) {
R3Edge *e;
char * p;
char * cpat = calloc(1, sizeof(char) * 64 * 3); // XXX
if (!cpat) {
int r = asprintf(errstr, "Can not allocate memory");
if (r) {};
return -1;
}
p = cpat;
int opcode_cnt = 0;
unsigned int i = 0;
for (; i < n->edges.size ; i++) {
e = n->edges.entries + i;
if (e->opcode) {
opcode_cnt++;
}
if (e->has_slug) {
// compile "foo/{slug}" to "foo/[^/]+"
char * slug_pat = r3_slug_compile(e->pattern.base, e->pattern.len);
info("slug_pat for pattern: %s\n",slug_pat);
strcat(p, slug_pat);
free(slug_pat);
info("temp pattern: %s\n",cpat);
} else {
strncat(p,"^(", 2);
p += 2;
strncat(p, e->pattern.base, e->pattern.len);
p += e->pattern.len;
strncat(p++,")", 1);
}
if ( i + 1 < n->edges.size && n->edges.size > 1 ) {
strncat(p++,"|",1);
}
}
info("pattern: %s\n",cpat);
// if all edges use opcode, we should skip the combined_pattern.
if ( opcode_cnt == n->edges.size ) {
// free(cpat);
n->compare_type = NODE_COMPARE_OPCODE;
} else {
n->compare_type = NODE_COMPARE_PCRE;
}
info("COMPARE_TYPE: %d\n",n->compare_type);
free(n->combined_pattern);
n->combined_pattern = cpat;
const char *pcre_error = NULL;
int pcre_erroffset = 0;
unsigned int option_bits = 0;
n->ov_cnt = (1 + n->edges.size) * 3;
if (n->pcre_pattern) {
pcre_free(n->pcre_pattern);
}
n->pcre_pattern = pcre_compile(
n->combined_pattern, /* the pattern */
option_bits, /* default options */
&pcre_error, /* for error message */
&pcre_erroffset, /* for error offset */
NULL); /* use default character tables */
if (n->pcre_pattern == NULL) {
if (errstr) {
int r = asprintf(errstr, "PCRE compilation failed at offset %d: %s, pattern: %s", pcre_erroffset, pcre_error, n->combined_pattern);
if (r) {};
}
return -1;
}
#ifdef PCRE_STUDY_JIT_COMPILE
if (n->pcre_extra) {
pcre_free_study(n->pcre_extra);
}
n->pcre_extra = pcre_study(n->pcre_pattern, 0, &pcre_error);
if (!n->pcre_extra && pcre_error) {
if (errstr) {
int r = asprintf(errstr, "PCRE study failed at offset %s, pattern: %s", pcre_error, n->combined_pattern);
if (r) {};
}
return -1;
}
#endif
return 0;
}
static R3Node * r3_tree_matchl_base(const R3Node * n, const char * path,
unsigned int path_len, match_entry * entry, int is_end) {
info("try matching: %s\n", path);
R3Edge *e;
unsigned int i;
unsigned int restlen;
const char *pp;
const char *pp_end;
info("n->compare_type: %d\n", n->compare_type);
info("n->pcre_pattern: %s\n", (char *)n->pcre_pattern);
if (n->compare_type == NODE_COMPARE_OPCODE) {
info("NODE_COMPARE_OPCODE\n");
pp_end = path + path_len;
e = n->edges.entries;
unsigned int cies = n->edges.size;
for (i = 0; i < cies; i++) {
pp = path;
switch(e->opcode) {
case OP_EXPECT_NOSLASH:
while (*pp != '/' && pp < pp_end) pp++;
break;
case OP_EXPECT_MORE_ALPHA:
while ( isalpha(*pp) && pp < pp_end) pp++;
break;
case OP_EXPECT_MORE_DIGITS:
while ( isdigit(*pp) && pp < pp_end) pp++;
break;
case OP_EXPECT_MORE_WORDS:
while ( (isdigit(*pp) || isalpha(*pp)) && pp < pp_end) pp++;
break;
case OP_EXPECT_NODASH:
while (*pp != '-' && pp < pp_end) pp++;
break;
case OP_GREEDY_ANY:
while (*pp != '\n' && pp < pp_end) pp++;
break;
}
// check match
if (e->opcode != OP_GREEDY_ANY) {
if ((pp - path) > 0) {
if (entry) {
str_array_append(&entry->vars , path, pp - path);
}
restlen = pp_end - pp;
if (!restlen) {
return e->child && e->child->endpoint ? e->child : NULL;
}
return r3_tree_matchl(e->child, pp, restlen, entry);
}
} else {
if (entry) {
str_array_append(&entry->vars , path, pp - path);
}
restlen = pp_end - pp;
if (!restlen) {
return e->child && e->child->endpoint ? e->child : NULL;
}
return r3_tree_matchl_base(e->child, pp, restlen, entry, is_end);
}
e++;
}
}
// if the pcre_pattern is found, and the pointer is not NULL, then it's
// pcre pattern node, we use pcre_exec to match the nodes
if (n->pcre_pattern) {
info("COMPARE PCRE_PATTERN\n");
const char *substring_start = 0;
int substring_length = 0;
int ov[ n->ov_cnt ];
int rc;
info("pcre matching %s on [%s]\n", n->combined_pattern, path);
rc = pcre_exec(
n->pcre_pattern, /* the compiled pattern */
n->pcre_extra,
path, /* the subject string */
path_len, /* the length of the subject */
0, /* start at offset 0 in the subject */
0, /* default options */
ov, /* output vector for substring information */
n->ov_cnt); /* number of elements in the output vector */
// does not match all edges, return NULL;
if (rc < 0) {
#ifdef DEBUG
printf("pcre rc: %d\n", rc );
switch(rc)
{
case PCRE_ERROR_NOMATCH:
printf("pcre: no match '%s' on pattern '%s'\n", path, n->combined_pattern);
break;
// Handle other special cases if you like
default:
printf("pcre matching error '%d' '%s' on pattern '%s'\n", rc, path, n->combined_pattern);
break;
}
#endif
return NULL;
}
restlen = path_len - ov[1]; // if it's fully matched to the end (rest string length)
int *inv = ov + 2;
if (!restlen) {
// Check the substring to decide we should go deeper on which edge
for (i = 1; i < rc; i++)
{
substring_length = *(inv+1) - *inv;
// if it's not matched for this edge, just skip them quickly
if (!is_end && !substring_length) {
inv += 2;
continue;
}
substring_start = path + *inv;
e = n->edges.entries + i - 1;
if (entry && e->has_slug) {
// append captured token to entry
str_array_append(&entry->vars, substring_start, substring_length);
}
// since restlen == 0 return the edge quickly.
return e->child && e->child->endpoint ? e->child : NULL;
}
}
// Check the substring to decide we should go deeper on which edge
inv = ov + 2;
for (i = 1; i < rc; i++)
{
substring_length = *(inv+1) - *inv;
// if it's not matched for this edge, just skip them quickly
if (!is_end && !substring_length) {
inv += 2;
continue;
}
substring_start = path + *inv;
e = n->edges.entries + i - 1;
if (entry && e->has_slug) {
// append captured token to entry
str_array_append(&entry->vars , substring_start, substring_length);
}
// get the length of orginal string: $0
return r3_tree_matchl_base( e->child, path + (ov[1] - ov[0]), restlen, entry, is_end);
}
// does not match
return NULL;
}
info("COMPARE COMPARE_STR\n");
if ((e = r3_node_find_edge_str(n, path, path_len))) {
restlen = path_len - e->pattern.len;
if (!restlen) {
if (is_end) {
return e->child && e->child->endpoint ? e->child : NULL;
}
R3Node *n = r3_tree_matchl_base(e->child, path + e->pattern.len, restlen, entry, 1);
if (n == NULL) {
return e->child && e->child->endpoint ? e->child : NULL;
}
return n;
}
return r3_tree_matchl_base(e->child, path + e->pattern.len, restlen, entry, is_end);
}
return NULL;
}
/**
* This function matches the URL path and return the left node
*
* r3_tree_matchl returns NULL when the path does not match. returns *node when the path matches.
*
* @param node n the root of the tree
* @param char* path the URL path to dispatch
* @param int path_len the length of the URL path.
* @param match_entry* entry match_entry is used for saving the captured dynamic strings from pcre result.
*/
R3Node * r3_tree_matchl(const R3Node * n, const char * path,
unsigned int path_len, match_entry * entry) {
return r3_tree_matchl_base(n, path, path_len, entry, 0);
}
R3Route * r3_tree_match_route(const R3Node *tree, match_entry * entry) {
R3Node *n;
R3Route *r;
n = r3_tree_match_entry(tree, entry);
unsigned int i, irs;
if (n && (irs = n->routes.size)) {
r = n->routes.entries;
for (i = 0; irs - i; i++) {
if ( r3_route_cmp(r, entry) == 0 ) {
// Add slugs from found route to match_entry
entry->vars.slugs.entries = r->slugs.entries;
entry->vars.slugs.size = r->slugs.size;
return r;
}
r++;
}
}
return NULL;
}
inline R3Edge * r3_node_find_edge_str(const R3Node * n, const char * str, int str_len) {
R3Edge *e;
unsigned int i, cst = *str;
e = n->edges.entries;
unsigned int ies = n->edges.size;
for (i = 0; ies - i; i++ ) {
if (cst == *e->pattern.base) {
if (!strncmp(e->pattern.base, str, e->pattern.len)) {
return e;
}
return NULL;
}
e++;
}
return NULL;
}
// R3Node * r3_node_create() {
// R3Node * n = (R3Node*) malloc( sizeof(R3Node) );
// CHECK_PTR(n);
// n->edges = NULL;
// n->edge_len = 0;
// n->edge_cap = 0;
// n->routes = NULL;
// n->route_len = 0;
// n->route_cap = 0;
// n->endpoint = 0;
// n->combined_pattern = NULL;
// n->pcre_pattern = NULL;
// n->pcre_extra = NULL;
// n->data = NULL;
// return n;
// }
void r3_route_free(R3Route * route) {
assert(route);
free(route->slugs.entries);
}
// static bool router_slugs_full(const R3Route * route) {
// return route->slugs_len >= route->slugs_cap;
// }
// static bool router_slugs_resize(R3Route * route, int new_cap) {
// route->slugs = realloc(route->slugs, sizeof(char**) * new_cap);
// route->slugs_cap = new_cap;
// return route->slugs != NULL;
// }
static r3_iovec_t* router_append_slug(R3Route * route, const char * slug, unsigned int len) {
r3_iovec_t *temp;
r3_vector_reserve(&route->slugs, route->slugs.size + 1);
temp = route->slugs.entries + route->slugs.size++;
temp->base = slug;
temp->len = len;
return temp;
}
static void get_slugs(R3Route * route, const char * path, int path_len) {
const char *plh = path;
const char *name;
unsigned int plhl, namel;
while (plh < (path + path_len)) {
plh = r3_slug_find_placeholder(plh, path_len-(plh-path), &plhl);
if (!plh) break;
name = r3_slug_find_name(plh, plhl, &namel);
if (name) {
router_append_slug(route, name, namel);
}
plh += plhl;
}
}
R3Route * r3_node_append_route(R3Node *tree, const char * path, int path_len, int method, void *data) {
r3_vector_reserve(&tree->routes, tree->routes.size + 1);
R3Route *info = tree->routes.entries + tree->routes.size++;
memset(info, 0, sizeof(*info));
r3_vector_reserve(&info->slugs, info->slugs.size + 3);
info->path.base = (char*) path;
info->path.len = path_len;
info->request_method = method; // ALLOW GET OR POST METHOD
info("\tinfo router path is: %s, with len: %d\n", path, path_len);
info("\troutes size is: %d\n", tree->routes.size);
info->data = data;
return info;
}
/**
* Helper function for creating routes from request URI path and request method
*
* method (int): METHOD_GET, METHOD_POST, METHOD_PUT, METHOD_DELETE ...
*/
R3Route * r3_tree_insert_routel_ex(R3Node *tree, int method, const char *path, int path_len, void *data, char **errstr) {
R3Node * ret = r3_tree_insert_pathl_ex(tree, path, path_len, method, 1, data, errstr);
if (ret == NULL) {
return NULL;
}
R3Route *router = ret->routes.entries + (ret->routes.size - 1);
get_slugs(router, path, path_len);
return router;
}
/**
* Find common prefix from the edges of the node.
*
* Some cases of the common prefix:
*
* 1. "/foo/{slug}" vs "/foo/bar" => common prefix = "/foo/"
* 2. "{slug}/hate" vs "{slug}/bar" => common prefix = "{slug}/"
* 2. "/z/{slug}/hate" vs "/z/{slog}/bar" => common prefix = "/z/"
* 3. "{slug:xxx}/hate" vs "{slug:yyy}/bar" => common prefix = ""
* 4. "aaa{slug:xxx}/hate" vs "aab{slug:yyy}/bar" => common prefix = "aa"
* 5. "/foo/{slug}/hate" vs "/fo{slug}/bar" => common prefix = "/fo"
*/
R3Edge * r3_node_find_common_prefix(R3Node *n, const char *path, int path_len, int *prefix_len, char **errstr) {
unsigned int i = 0;
int edge_prefix, prefix = 0;
*prefix_len = 0;
R3Edge *e = NULL;
// Check all edges to find the most common prefix
for(i = 0; i < n->edges.size; i++) {
// ignore all edges with slug
edge_prefix = strndiff( (char*) path, n->edges.entries[i].pattern.base, n->edges.entries[i].pattern.len);
// no common, consider insert a new edge
if (edge_prefix > prefix) {
prefix = edge_prefix;
e = n->edges.entries + i;
}
}
// found common prefix edge
if (prefix > 0) {
r3_slug_t *slug;
int ret = 0;
const char *offset = path;
const char *p = path + prefix;
slug = r3_slug_new(path, path_len);
do {
ret = r3_slug_parse(slug, path, path_len, offset, errstr);
// found slug
if (ret == 1) {
// inside slug, backtrace to the begin of the slug
if ( p >= slug->begin && p <= slug->end ) {
prefix = slug->begin - path - 1;
break;
} else if ( p < slug->begin ) {
break;
} else if ( p >= slug->end && p < (path + path_len) ) {
offset = slug->end + 1;
prefix = p - path;
continue;
} else {
break;
}
} else if (ret == -1) {
r3_slug_free(slug);
return NULL;
} else {
break;
}
} while(ret == 1);
// free the slug
r3_slug_free(slug);
}
*prefix_len = prefix;
return e;
}
/**
* Return the last inserted node.
*/
R3Node * r3_tree_insert_pathl_ex(R3Node *tree, const char *path, unsigned int path_len, int method, unsigned int router, void * data, char **errstr)
{
R3Node * n = tree;
// common edge
R3Edge * e = NULL;
// If there is no path to insert at the node, we just increase the mount
// point on the node and append the route.
if (path_len == 0) {
tree->endpoint++;
if (router) {
r3_node_append_route(tree, path, path_len, method, data);
info("tree router path is: %s, with len: %d\n", path, path_len);
}
tree->data = data;
return tree;
}
/* length of common prefix */
int prefix_len = 0;
char *err = NULL;
e = r3_node_find_common_prefix(tree, path, path_len, &prefix_len, &err);
if (err) {
if (errstr) {
// copy the error message pointer
*errstr = err;
} else {
free(err);
}
return NULL;
}
const char * subpath = path + prefix_len;
const int subpath_len = path_len - prefix_len;
// common prefix not found, insert a new edge for this pattern
if ( !prefix_len ) {
// there are two more slugs, we should break them into several parts
int slug_cnt = r3_slug_count(path, path_len, errstr);
if (slug_cnt == -1) {
return NULL;
}
info("slug_cnt: %d\n",slug_cnt);
if ( slug_cnt > 1 ) {
unsigned int slug_len;
const char *p = r3_slug_find_placeholder(path, path_len, &slug_len);
assert(p);
// find the next one '{', then break there
p = r3_slug_find_placeholder(p + slug_len + 1, path_len - slug_len - 1, NULL);
assert(p);
// insert the first one edge, and break at "p"
R3Node * child = r3_tree_create(3);
r3_node_connectl(n, path, p - path, 0, child); // no duplicate
// and insert the rest part to the child
return r3_tree_insert_pathl_ex(child, p, path_len - (int)(p - path), method, 1, data, errstr);
} else {
if (slug_cnt == 1) {
// there is one slug, let's see if it's optimiz-able by opcode
unsigned int slug_len = 0;
const char *slug_p = r3_slug_find_placeholder(path, path_len, &slug_len);
assert(slug_p);
unsigned int slug_pattern_len = 0;
const char *slug_pattern = r3_slug_find_pattern(slug_p, slug_len, &slug_pattern_len);
int opcode = 0;
// if there is a pattern defined.
if (slug_pattern_len) {
char *cpattern = r3_slug_compile(slug_pattern, slug_pattern_len);
info("cpattern: %s\n", cpattern);
opcode = r3_pattern_to_opcode(cpattern, strlen(cpattern));
info("opcode: %d\n", opcode);
free(cpattern);
} else {
opcode = OP_EXPECT_NOSLASH;
}
// if the slug starts after one+ charactor, for example foo{slug}
R3Node *c1;
if (slug_p > path) {
c1 = r3_tree_create(3);
r3_node_connectl(n, path, slug_p - path, 0, c1); // no duplicate
} else {
c1 = n;
}
R3Node * c2 = r3_tree_create(3);
R3Edge * op_edge = r3_node_connectl(c1, slug_p, slug_len , 0, c2);
if(opcode) {
op_edge->opcode = opcode;
}
int restlen = path_len - ((slug_p - path) + slug_len);
if (restlen) {
return r3_tree_insert_pathl_ex(c2, slug_p + slug_len, restlen, method, 1, data, errstr);
}
c2->data = data;
c2->endpoint++;
if (router) {
// route->data = data;
r3_node_append_route(c2, path, path_len, method, data);
info("c2 router path is: %s, with len: %d\n", path, path_len);
}
return c2;
}
// only one slug
R3Node * child = r3_tree_create(3);
child->endpoint++;
if (data)
child->data = data;
r3_node_connectl(n, path, path_len, 0, child);
if (router) {
r3_node_append_route(child, path, path_len, method, data);
info("child router path is: %s, with len: %d\n", path, path_len);
}
return child;
}
} else if ( prefix_len == e->pattern.len ) { // fully-equal to the pattern of the edge
// there are something more we can insert
if ( subpath_len > 0 ) {
return r3_tree_insert_pathl_ex(e->child, subpath, subpath_len, method, 1, data, errstr);
} else {
// there are no more path to insert
// see if there is an endpoint already, we should n't overwrite the data on child.
// but we still need to append the route.
if (router) {
// route->data = data;
r3_node_append_route(e->child, path, path_len, method, data);
info("e->child router path is: %s, with len: %d\n", path, path_len);
e->child->endpoint++; // make it as an endpoint
return e->child;
}
// insertion without route
if (e->child->endpoint > 0) {
// TODO: return an error code instead of NULL
return NULL;
}
e->child->endpoint++; // make it as an endpoint
e->child->data = data; // set data
return e->child;
}
} else if ( prefix_len < e->pattern.len ) {
/* it's partially matched with the pattern,
* we should split the end point and make a branch here...
*/
r3_edge_branch(e, prefix_len);
return r3_tree_insert_pathl_ex(e->child, subpath, subpath_len, method, 1, data, errstr);
} else {
fprintf(stderr, "unexpected route.");
return NULL;
}
return n;
}
bool r3_node_has_slug_edges(const R3Node *n) {
bool found = false;
R3Edge *edge_entries = n->edges.entries;
R3Edge *e;
unsigned int i;
for ( i = 0 ; i < n->edges.size ; i++ ) {
e = edge_entries + i;
e->has_slug = r3_path_contains_slug_char(e->pattern.base, e->pattern.len);
if (e->has_slug)
found = true;
}
return found;
}
void r3_tree_dump(const R3Node * n, int level) {
print_indent(level);
printf("(o)");
printf(" compare_type:%d", n->compare_type);
if ( n->combined_pattern ) {
printf(" regexp:%s", n->combined_pattern);
}
printf(" endpoint:%d", n->endpoint);
if (n->data) {
printf(" data:%p", n->data);
}
printf("\n");
for ( int i = 0 ; i < n->edges.size ; i++ ) {
R3Edge * e = n->edges.entries + i;
print_indent(level + 1);
printf("|-\"%*.*s\"", e->pattern.len, e->pattern.len, e->pattern.base);
if (e->opcode ) {
printf(" opcode:%d", e->opcode);
}
printf("\n");
print_indent(level + 1);
printf("||-routes num: |%d|", n->routes.size);
for ( int j = 0 ; j < n->routes.size ; j++ ) {
R3Route * rr = n->routes.entries + j;
printf(" route path: |%*.*s|", rr->path.len,rr->path.len,rr->path.base);
}
printf("\n");
if ( e->child ) {
printf("\n");
r3_tree_dump( e->child, level + 1);
}
printf("\n");
}
}
/**
* return 0 == equal
*
* -1 == different route
*/
inline int r3_route_cmp(const R3Route *r1, const match_entry *r2) {
if (r1->request_method && r2->request_method) {
if (0 == (r1->request_method & r2->request_method) ) {
return -1;
}
}
if (r1->http_scheme) {
if (0 == (r1->http_scheme & r2->http_scheme) ) {
return -1;
}
}
if ( r1->host.len && r2->host.len ) {
if (r1->host.len > r2->host.len) {
return -1;
}
int r1_i = r1->host.len - 1;
int r2_i = r2->host.len - 1;
for(; r1_i >= 0 ; r1_i--, r2_i--) {
if (r1_i == 0 && r1->host.base[0] == '*') {
break;
}
if (r2->host.base[r2_i] != r1->host.base[r1_i]) {
return -1;
}
}
}
if (r1->remote_addr_pattern.len && r2->remote_addr.len) {
if ( strncmp(r1->remote_addr_pattern.base, r2->remote_addr.base, r2->remote_addr.len) ) {
return -1;
}
}
if (r1->remote_addr_v4_bits > 0) {
if (!r2->remote_addr.base) {
return -1;
}
uint32_t addr;
if(inet_pton(AF_INET, r2->remote_addr.base, (void *)&addr) != 1) {
return -1;
}
unsigned int r2_addr = ntohl(addr);
int bits = 32 - r1->remote_addr_v4_bits;
if (r1->remote_addr_v4 >> bits != r2_addr >> bits) {
return -1;
}
}
info("r1 v6_bits[0]: %d\n", r1->remote_addr_v6_bits[0]);
if (r1->remote_addr_v6_bits[0] > 0) {
if (!r2->remote_addr.base) {
return -1;
}
struct in6_addr addr6;
if(inet_pton(AF_INET6, r2->remote_addr.base, (void *)&addr6) != 1) {
return -1;
}
for (int i = 0; i < 4; i++) {
int bits = 32 - r1->remote_addr_v6_bits[i];
if (bits == 32) {
continue;
}
unsigned int r2_addr = ntohl(addr6.__in6_u.__u6_addr32[i]);
if (r1->remote_addr_v6[i] >> bits != r2_addr >> bits) {
return -1;
}
}
}
return 0;
}
/**
*
*/
// void r3_node_append_route(R3Node * n, R3Route * r)
// {
// r3_vector_reserve(&n->routes, n->routes.size + 1);
// memset(n->routes.entries + 1, 0, sizeof(*n->routes.entries));
// if (n->routes == NULL) {
// n->route_cap = 3;
// n->routes = malloc(sizeof(R3Route) * n->route_cap);
// }
// if (n->route_len >= n->route_cap) {
// n->route_cap *= 2;
// n->routes = realloc(n->routes, sizeof(R3Route) * n->route_cap);
// }
// n->routes[ n->route_len++ ] = r;
// }
|
a5443d48c9ba46aed6468812eb785a4635ffe7e7
|
e73547787354afd9b717ea57fe8dd0695d161821
|
/src/world/area_tst/tst_12/tst_12_1_main.c
|
5454495d1096625472d450a8cb3e4b5fa27c686e
|
[] |
no_license
|
pmret/papermario
|
8b514b19653cef8d6145e47499b3636b8c474a37
|
9774b26d93f1045dd2a67e502b6efc9599fb6c31
|
refs/heads/main
| 2023-08-31T07:09:48.951514
| 2023-08-21T18:07:08
| 2023-08-21T18:07:08
| 287,151,133
| 904
| 139
| null | 2023-09-14T02:44:23
| 2020-08-13T01:22:57
|
C
|
UTF-8
|
C
| false
| false
| 2,122
|
c
|
tst_12_1_main.c
|
#include "tst_12.h"
#include "effects.h"
extern EvtScript N(EVS_Main);
EntryList N(Entrances) = {
[tst_12_ENTRY_0] { 416.0, 0.0, 76.0, 90.0 },
};
MapSettings N(settings) = {
.main = &N(EVS_Main),
.entryList = &N(Entrances),
.entryCount = ENTRY_COUNT(N(Entrances)),
.background = &gBackgroundImage,
};
EvtScript N(D_80240050_B1D340) = {
EVT_SET_GROUP(EVT_GROUP_0B)
EVT_SET(LVarA, LVar0)
EVT_SET(LVarB, LVar1)
EVT_SET(LVarC, LVar2)
EVT_SET(LVarD, LVar3)
EVT_SET(LVarE, LVar4)
EVT_SUB(LVarC, LVar0)
EVT_SUB(LVarD, LVar1)
EVT_SETF(LVar0, LVarC)
EVT_DIVF(LVar0, EVT_FLOAT(100.0))
EVT_SETF(LVarF, EVT_FLOAT(100.0))
EVT_DIVF(LVarF, LVar0)
EVT_ADD(LVarF, 11)
EVT_SET(LVar5, 200)
EVT_DIV(LVar5, LVarF)
EVT_ADD(LVar5, 1)
EVT_LOOP(LVar5)
EVT_CALL(RandInt, LVarC, LVar0)
EVT_CALL(RandInt, LVarD, LVar1)
EVT_CALL(RandInt, 199, LVar2)
EVT_SET(LVar3, 210)
EVT_SUB(LVar3, LVar2)
EVT_ADD(LVar0, LVarA)
EVT_ADD(LVar1, LVarB)
EVT_ADD(LVar2, LVarE)
EVT_PLAY_EFFECT(EFFECT_FLOATING_FLOWER, LVar0, LVar2, LVar1, LVar3)
EVT_END_LOOP
EVT_WAIT(LVarF)
EVT_LABEL(0)
EVT_CALL(RandInt, LVarC, LVar0)
EVT_CALL(RandInt, LVarD, LVar1)
EVT_ADD(LVar0, LVarA)
EVT_ADD(LVar1, LVarB)
EVT_PLAY_EFFECT(EFFECT_FLOATING_FLOWER, LVar0, LVarE, LVar1, 200)
EVT_WAIT(LVarF)
EVT_GOTO(0)
EVT_RETURN
EVT_END
};
EvtScript N(EVS_Main) = {
EVT_SET(GB_WorldLocation, LOCATION_TESTING)
EVT_CALL(SetSpriteShading, SHADING_NONE)
EVT_SETUP_CAMERA_DEFAULT()
EVT_CALL(ModifyColliderFlags, MODIFY_COLLIDER_FLAGS_SET_SURFACE, COLLIDER_o92, SURFACE_TYPE_FLOWERS)
EVT_SET(LVar0, 544)
EVT_SET(LVar1, 0)
EVT_SET(LVar2, 100)
EVT_SET(LVar3, 386)
EVT_SET(LVar4, 174)
EVT_SET(LVar5, 40)
EVT_EXEC(N(D_80240050_B1D340))
EVT_SET(LVar0, 327)
EVT_SET(LVar1, 0)
EVT_SET(LVar2, 24)
EVT_SET(LVar3, 89)
EVT_SET(LVar4, 252)
EVT_SET(LVar5, 40)
EVT_EXEC(N(D_80240050_B1D340))
EVT_RETURN
EVT_END
};
|
d1455e633cdc9dc90a6f71323397f482d54b7f94
|
5766e87192d8449d9819b4796156ef1093a35097
|
/src/mlvpn.c
|
eab059567cf380c47abbcf5eb876a021b735cb06
|
[
"LicenseRef-scancode-unknown-license-reference"
] |
permissive
|
zehome/MLVPN
|
ac7aec616d958dc60ef6a56638e582c0e54a9493
|
b934d4953d480cbbd43128d01150b829fa8839df
|
refs/heads/master
| 2023-08-05T18:51:18.329977
| 2022-08-04T14:42:15
| 2022-08-04T14:42:15
| 2,819,004
| 501
| 139
|
BSD-2-Clause
| 2022-08-04T14:42:16
| 2011-11-21T10:14:19
|
C
|
UTF-8
|
C
| false
| false
| 50,729
|
c
|
mlvpn.c
|
/*
* Copyright (c) 2015, Laurent COUSTET <ed@zehome.com>
*
* All rights reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS AND 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 <stdint.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <signal.h>
#include <stdio.h>
#include <fcntl.h>
#include <errno.h>
#include <time.h>
#include <getopt.h>
#include <pwd.h>
#include <sys/types.h>
#include <sys/select.h>
#include <sys/time.h>
#include <sys/un.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <netdb.h>
#include <ev.h>
#include "includes.h"
#include "mlvpn.h"
#include "tool.h"
#include "setproctitle.h"
#include "crypto.h"
#ifdef ENABLE_CONTROL
#include "control.h"
#endif
#include "tuntap_generic.h"
/* Linux specific things */
#ifdef HAVE_LINUX
#include <sys/prctl.h>
#include "systemd.h"
#endif
#ifdef HAVE_FREEBSD
#define _NSIG _SIG_MAXSIG
#include <sys/endian.h>
#endif
#ifdef HAVE_DARWIN
#include <libkern/OSByteOrder.h>
#define be16toh OSSwapBigToHostInt16
#define be32toh OSSwapBigToHostInt32
#define be64toh OSSwapBigToHostInt64
#define htobe16 OSSwapHostToBigInt16
#define htobe32 OSSwapHostToBigInt32
#define htobe64 OSSwapHostToBigInt64
#endif
/* GLOBALS */
struct tuntap_s tuntap;
char *_progname;
static char **saved_argv;
struct ev_loop *loop;
static ev_timer reorder_drain_timeout;
static ev_timer reorder_adjust_rtt_timeout;
struct rtunhead rtuns;
char *status_command = NULL;
char *process_title = NULL;
int logdebug = 0;
static uint64_t data_seq = 0;
struct mlvpn_status_s mlvpn_status = {
.start_time = 0,
.last_reload = 0,
.fallback_mode = 0,
.connected = 0,
.initialized = 0
};
struct mlvpn_options_s mlvpn_options = {
.change_process_title = 1,
.process_name = "mlvpn",
.control_unix_path = "",
.control_bind_host = "",
.control_bind_port = "",
.ip4 = "",
.ip6 = "",
.ip4_gateway = "",
.ip6_gateway = "",
.ip4_routes = "",
.ip6_routes = "",
.mtu = 0,
.config_path = "mlvpn.conf",
.config_fd = -1,
.debug = 0,
.verbose = 2,
.unpriv_user = "mlvpn",
.cleartext_data = 1,
.root_allowed = 0,
.reorder_buffer_size = 0
};
#ifdef HAVE_FILTERS
struct mlvpn_filters_s mlvpn_filters = {
.count = 0
};
#endif
struct mlvpn_reorder_buffer *reorder_buffer;
freebuffer_t *freebuf;
static char *optstr = "c:n:u:hvVD:";
static struct option long_options[] = {
{"config", required_argument, 0, 'c' },
{"debug", no_argument, 0, 2 },
{"name", required_argument, 0, 'n' },
{"natural-title", no_argument, 0, 1 },
{"help", no_argument, 0, 'h' },
{"user", required_argument, 0, 'u' },
{"verbose", no_argument, 0, 'v' },
{"quiet", no_argument, 0, 'q' },
{"version", no_argument, 0, 'V' },
{"yes-run-as-root",no_argument, 0, 3 },
{0, 0, 0, 0 }
};
static int mlvpn_rtun_start(mlvpn_tunnel_t *t);
static void mlvpn_rtun_read(EV_P_ ev_io *w, int revents);
static void mlvpn_rtun_write(EV_P_ ev_io *w, int revents);
static uint32_t mlvpn_rtun_reorder_drain(uint32_t reorder);
static void mlvpn_rtun_reorder_drain_timeout(EV_P_ ev_timer *w, int revents);
static void mlvpn_rtun_check_timeout(EV_P_ ev_timer *w, int revents);
static void mlvpn_rtun_adjust_reorder_timeout(EV_P_ ev_timer *w, int revents);
static void mlvpn_rtun_send_keepalive(ev_tstamp now, mlvpn_tunnel_t *t);
static void mlvpn_rtun_send_disconnect(mlvpn_tunnel_t *t);
static int mlvpn_rtun_send(mlvpn_tunnel_t *tun, circular_buffer_t *pktbuf);
static void mlvpn_rtun_send_auth(mlvpn_tunnel_t *t);
static void mlvpn_rtun_status_up(mlvpn_tunnel_t *t);
static void mlvpn_rtun_tick_connect(mlvpn_tunnel_t *t);
static void mlvpn_rtun_recalc_weight();
static void mlvpn_update_status();
static int mlvpn_rtun_bind(mlvpn_tunnel_t *t);
static void update_process_title();
static void mlvpn_tuntap_init();
static int
mlvpn_protocol_read(mlvpn_tunnel_t *tun,
mlvpn_pkt_t *rawpkt,
mlvpn_pkt_t *decap_pkt);
static void
usage(char **argv)
{
fprintf(stderr,
"usage: %s [options]\n\n"
"Options:\n"
" -c, --config [path] path to config file (ex. /etc/mlvpn.conf)\n"
" --debug don't use syslog, print to stdout\n"
" --natural-title do not change process title\n"
" -n, --name change process-title and include 'name'\n"
" -h, --help this help\n"
" -u, --user [username] drop privileges to user 'username'\n"
" --yes-run-as-root ! please do not use !\n"
" -v --verbose increase verbosity\n"
" -q --quiet decrease verbosity\n"
" -V, --version output version information and exit\n"
"\n"
"For more details see mlvpn(1) and mlvpn.conf(5).\n", argv[0]);
exit(2);
}
int
mlvpn_sock_set_nonblocking(int fd)
{
int ret = 0;
int fl = fcntl(fd, F_GETFL);
if (fl < 0)
{
log_warn(NULL, "fcntl");
ret = -1;
} else {
fl |= O_NONBLOCK;
if ( (ret = fcntl(fd, F_SETFL, fl)) < 0)
log_warn(NULL, "Unable to set socket %d non blocking",
fd);
}
return ret;
}
inline static
void mlvpn_rtun_tick(mlvpn_tunnel_t *t) {
t->last_activity = ev_now(EV_DEFAULT_UC);
}
/* Inject the packet to the tuntap device (real network) */
inline static
void mlvpn_rtun_inject_tuntap(mlvpn_pkt_t *pkt)
{
mlvpn_pkt_t *tuntap_pkt = mlvpn_pktbuffer_write(tuntap.sbuf);
tuntap_pkt->len = pkt->len;
memcpy(tuntap_pkt->data, pkt->data, tuntap_pkt->len);
/* Send the packet back into the LAN */
if (!ev_is_active(&tuntap.io_write)) {
ev_io_start(EV_A_ &tuntap.io_write);
}
}
static void
mlvpn_rtun_reorder_drain_timeout(EV_P_ ev_timer *w, int revents)
{
log_debug("reorder", "reorder timeout. Packet loss?");
mlvpn_rtun_reorder_drain(0);
if (freebuf->used == 0) {
ev_timer_stop(EV_A_ w);
}
}
static uint32_t
mlvpn_rtun_reorder_drain(uint32_t reorder)
{
int i;
uint32_t drained = 0;
mlvpn_pkt_t *drained_pkts[1024];
mlvpn_pkt_t *pkt;
/* Try to drain packets */
if (reorder) {
drained = mlvpn_reorder_drain(reorder_buffer, drained_pkts, 1024);
for(i = 0; i < drained; i++) {
pkt = drained_pkts[i];
mlvpn_rtun_inject_tuntap(pkt);
mlvpn_freebuffer_free(freebuf, drained_pkts[i]);
}
} else {
while ((pkt = mlvpn_freebuffer_drain_used(freebuf)) != NULL) {
drained++;
mlvpn_rtun_inject_tuntap(pkt);
}
mlvpn_freebuffer_reset(freebuf);
mlvpn_reorder_reset(reorder_buffer);
}
if (freebuf->used == 0) {
ev_timer_stop(EV_A_ &reorder_drain_timeout);
}
return drained;
}
/* Count the loss on the last 64 packets */
static void
mlvpn_loss_update(mlvpn_tunnel_t *tun, uint64_t seq)
{
if (seq > tun->seq_last + 64) {
/* consider a connection reset. */
tun->seq_vect = (uint64_t) -1;
tun->seq_last = seq;
} else if (seq > tun->seq_last) {
/* new sequence number -- recent message arrive */
tun->seq_vect <<= seq - tun->seq_last;
tun->seq_vect |= 1;
tun->seq_last = seq;
} else if (seq >= tun->seq_last - 63) {
tun->seq_vect |= (1 << (tun->seq_last - seq));
}
}
int
mlvpn_loss_ratio(mlvpn_tunnel_t *tun)
{
int loss = 0;
int i;
/* Count zeroes */
for (i = 0; i < 64; i++) {
if (! (1 & (tun->seq_vect >> i))) {
loss++;
}
}
return loss * 100 / 64;
}
static int
mlvpn_rtun_recv_data(mlvpn_tunnel_t *tun, mlvpn_pkt_t *inpkt)
{
int ret;
uint32_t drained;
if (reorder_buffer == NULL || !inpkt->reorder) {
mlvpn_rtun_inject_tuntap(inpkt);
return 1;
} else {
mlvpn_pkt_t *pkt = mlvpn_freebuffer_get(freebuf);
if (!pkt) {
log_warnx("reorder", "freebuffer full: reorder_buffer_size must be increased.");
mlvpn_rtun_inject_tuntap(inpkt);
return 1;
}
memcpy(pkt, inpkt, sizeof(mlvpn_pkt_t));
ret = mlvpn_reorder_insert(reorder_buffer, pkt);
if (ret == -1) {
log_warnx("net", "reorder_buffer_insert failed: %d", ret);
mlvpn_reorder_reset(reorder_buffer);
drained = mlvpn_rtun_reorder_drain(0);
} else if (ret == -2) {
/* We have received a packet out of order just
* after the forced drain (packet loss)
* Just inject the packet as is
*/
mlvpn_rtun_inject_tuntap(inpkt);
return 1;
} else {
drained = mlvpn_rtun_reorder_drain(1);
}
if (freebuf->used > 0) {
ev_timer_again(EV_A_ &reorder_drain_timeout);
}
//log_debug("reorder", "drained %d packets", drained);
}
return drained;
}
/* read from the rtunnel => write directly to the tap send buffer */
static void
mlvpn_rtun_read(EV_P_ ev_io *w, int revents)
{
mlvpn_tunnel_t *tun = w->data;
ssize_t len;
struct sockaddr_storage clientaddr;
socklen_t addrlen = sizeof(clientaddr);
mlvpn_pkt_t pkt;
len = recvfrom(tun->fd, pkt.data,
sizeof(pkt.data),
MSG_DONTWAIT, (struct sockaddr *)&clientaddr, &addrlen);
if (len < 0) {
if (errno != EAGAIN && errno != EWOULDBLOCK) {
log_warn("net", "%s read error", tun->name);
mlvpn_rtun_status_down(tun);
}
} else if (len == 0) {
log_info("protocol", "%s peer closed the connection", tun->name);
} else {
pkt.len = len;
mlvpn_pkt_t decap_pkt;
/* validate the received packet */
if (mlvpn_protocol_read(tun, &pkt, &decap_pkt) < 0) {
return;
}
tun->recvbytes += len;
tun->recvpackets += 1;
if (! tun->addrinfo)
fatalx("tun->addrinfo is NULL!");
if ((tun->addrinfo->ai_addrlen != addrlen) ||
(memcmp(tun->addrinfo->ai_addr, &clientaddr, addrlen) != 0)) {
if (! tun->status >= MLVPN_AUTHOK) {
log_warnx("protocol", "%s rejected non authenticated connection",
tun->name);
return;
}
char clienthost[NI_MAXHOST];
char clientport[NI_MAXSERV];
int ret;
if ( (ret = getnameinfo((struct sockaddr *)&clientaddr, addrlen,
clienthost, sizeof(clienthost),
clientport, sizeof(clientport),
NI_NUMERICHOST|NI_NUMERICSERV)) < 0) {
log_warn("protocol", "%s error in getnameinfo: %d",
tun->name, ret);
} else {
log_info("protocol", "%s new connection -> %s:%s",
tun->name, clienthost, clientport);
memcpy(tun->addrinfo->ai_addr, &clientaddr, addrlen);
}
}
log_debug("net", "< %s recv %d bytes (type=%d, seq=%"PRIu64", reorder=%d)",
tun->name, (int)len, decap_pkt.type, decap_pkt.seq, decap_pkt.reorder);
if (decap_pkt.type == MLVPN_PKT_DATA) {
if (tun->status >= MLVPN_AUTHOK) {
mlvpn_rtun_tick(tun);
mlvpn_rtun_recv_data(tun, &decap_pkt);
} else {
log_debug("protocol", "%s ignoring non authenticated packet",
tun->name);
}
} else if (decap_pkt.type == MLVPN_PKT_KEEPALIVE &&
tun->status >= MLVPN_AUTHOK) {
log_debug("protocol", "%s keepalive received", tun->name);
mlvpn_rtun_tick(tun);
tun->last_keepalive_ack = ev_now(EV_DEFAULT_UC);
/* Avoid flooding the network if multiple packets are queued */
if (tun->last_keepalive_ack_sent + 1 < tun->last_keepalive_ack) {
tun->last_keepalive_ack_sent = tun->last_keepalive_ack;
mlvpn_rtun_send_keepalive(tun->last_keepalive_ack, tun);
}
} else if (decap_pkt.type == MLVPN_PKT_DISCONNECT &&
tun->status >= MLVPN_AUTHOK) {
log_info("protocol", "%s disconnect received", tun->name);
mlvpn_rtun_status_down(tun);
} else if (decap_pkt.type == MLVPN_PKT_AUTH ||
decap_pkt.type == MLVPN_PKT_AUTH_OK) {
mlvpn_rtun_send_auth(tun);
}
}
}
static int
mlvpn_protocol_read(
mlvpn_tunnel_t *tun, mlvpn_pkt_t *pkt,
mlvpn_pkt_t *decap_pkt)
{
unsigned char nonce[crypto_NONCEBYTES];
int ret;
uint16_t rlen;
mlvpn_proto_t proto;
uint64_t now64 = mlvpn_timestamp64(ev_now(EV_DEFAULT_UC));
/* Overkill */
memset(&proto, 0, sizeof(proto));
memset(decap_pkt, 0, sizeof(*decap_pkt));
/* pkt->data contains mlvpn_proto_t struct */
if (pkt->len > sizeof(pkt->data) || pkt->len > sizeof(proto) ||
pkt->len < (PKTHDRSIZ(proto))) {
log_warnx("protocol", "%s received invalid packet of %d bytes",
tun->name, pkt->len);
goto fail;
}
memcpy(&proto, pkt->data, pkt->len);
rlen = be16toh(proto.len);
if (rlen == 0 || rlen > sizeof(proto.data)) {
log_warnx("protocol", "%s invalid packet size: %d", tun->name, rlen);
goto fail;
}
proto.seq = be64toh(proto.seq);
proto.timestamp = be16toh(proto.timestamp);
proto.timestamp_reply = be16toh(proto.timestamp_reply);
proto.flow_id = be32toh(proto.flow_id);
/* now auth the packet using libsodium before further checks */
#ifdef ENABLE_CRYPTO
if (mlvpn_options.cleartext_data && proto.flags == MLVPN_PKT_DATA) {
memcpy(decap_pkt->data, &proto.data, rlen);
} else {
sodium_memzero(nonce, sizeof(nonce));
memcpy(nonce, &proto.seq, sizeof(proto.seq));
memcpy(nonce + sizeof(proto.seq), &proto.flow_id, sizeof(proto.flow_id));
if ((ret = crypto_decrypt((unsigned char *)decap_pkt->data,
(const unsigned char *)&proto.data, rlen,
nonce)) != 0) {
log_warnx("protocol", "%s crypto_decrypt failed: %d",
tun->name, ret);
goto fail;
}
rlen -= crypto_PADSIZE;
}
#else
memcpy(decap_pkt->data, &proto.data, rlen);
#endif
decap_pkt->len = rlen;
decap_pkt->type = proto.flags;
if (proto.version >= 1) {
decap_pkt->reorder = proto.reorder;
decap_pkt->seq = be64toh(proto.data_seq);
mlvpn_loss_update(tun, proto.seq);
} else {
decap_pkt->reorder = 0;
decap_pkt->seq = 0;
}
if (proto.timestamp != (uint16_t)-1) {
tun->saved_timestamp = proto.timestamp;
tun->saved_timestamp_received_at = now64;
}
if (proto.timestamp_reply != (uint16_t)-1) {
uint16_t now16 = mlvpn_timestamp16(now64);
double R = mlvpn_timestamp16_diff(now16, proto.timestamp_reply);
if (R < 5000) { /* ignore large values, e.g. server was Ctrl-Zed */
if (!tun->rtt_hit) { /* first measurement */
tun->srtt = R;
tun->rttvar = R / 2;
tun->rtt_hit = 1;
} else {
const double alpha = 1.0 / 8.0;
const double beta = 1.0 / 4.0;
tun->rttvar = (1 - beta) * tun->rttvar + (beta * fabs(tun->srtt - R));
tun->srtt = (1 - alpha) * tun->srtt + (alpha * R);
}
}
log_debug("rtt", "%s %ums srtt %ums loss ratio: %d seqvect: %016lx",
tun->name, (unsigned int)R, (unsigned int)tun->srtt,
mlvpn_loss_ratio(tun), tun->seq_vect);
}
return 0;
fail:
return -1;
}
static int
mlvpn_rtun_send(mlvpn_tunnel_t *tun, circular_buffer_t *pktbuf)
{
unsigned char nonce[crypto_NONCEBYTES];
ssize_t ret;
size_t wlen;
mlvpn_proto_t proto;
uint64_t now64 = mlvpn_timestamp64(ev_now(EV_DEFAULT_UC));
memset(&proto, 0, sizeof(proto));
mlvpn_pkt_t *pkt = mlvpn_pktbuffer_read(pktbuf);
pkt->reorder = 1;
if (pkt->type == MLVPN_PKT_DATA && pkt->reorder) {
proto.data_seq = data_seq++;
}
wlen = PKTHDRSIZ(proto) + pkt->len;
proto.len = pkt->len;
proto.flags = pkt->type;
if (pkt->reorder) {
proto.seq = tun->seq++;
}
proto.flow_id = tun->flow_id;
proto.version = MLVPN_PROTOCOL_VERSION;
proto.reorder = pkt->reorder;
/* we have a recent received timestamp */
if (now64 - tun->saved_timestamp_received_at < 1000 ) {
/* send "corrected" timestamp advanced by how long we held it */
/* Cast to uint16_t there intentional */
proto.timestamp_reply = tun->saved_timestamp + (now64 - tun->saved_timestamp_received_at);
tun->saved_timestamp = -1;
tun->saved_timestamp_received_at = 0;
} else {
proto.timestamp_reply = -1;
}
proto.timestamp = mlvpn_timestamp16(now64);
#ifdef ENABLE_CRYPTO
if (mlvpn_options.cleartext_data && pkt->type == MLVPN_PKT_DATA) {
memcpy(&proto.data, &pkt->data, pkt->len);
} else {
if (wlen + crypto_PADSIZE > sizeof(proto.data)) {
log_warnx("protocol", "%s packet too long: %u/%d (packet=%d)",
tun->name,
(unsigned int)wlen + crypto_PADSIZE,
(unsigned int)sizeof(proto.data),
pkt->len);
return -1;
}
sodium_memzero(nonce, sizeof(nonce));
memcpy(nonce, &proto.seq, sizeof(proto.seq));
memcpy(nonce + sizeof(proto.seq), &proto.flow_id, sizeof(proto.flow_id));
if ((ret = crypto_encrypt((unsigned char *)&proto.data,
(const unsigned char *)&pkt->data, pkt->len,
nonce)) != 0) {
log_warnx("protocol", "%s crypto_encrypt failed: %d incorrect password?",
tun->name, (int)ret);
return -1;
}
proto.len += crypto_PADSIZE;
wlen += crypto_PADSIZE;
}
#else
memcpy(&proto.data, &pkt->data, pkt->len);
#endif
proto.len = htobe16(proto.len);
proto.seq = htobe64(proto.seq);
proto.data_seq = htobe64(proto.data_seq);
proto.flow_id = htobe32(proto.flow_id);
proto.timestamp = htobe16(proto.timestamp);
proto.timestamp_reply = htobe16(proto.timestamp_reply);
ret = sendto(tun->fd, &proto, wlen, MSG_DONTWAIT,
tun->addrinfo->ai_addr, tun->addrinfo->ai_addrlen);
if (ret < 0)
{
if (errno != EAGAIN && errno != EWOULDBLOCK) {
log_warn("net", "%s write error", tun->name);
mlvpn_rtun_status_down(tun);
}
} else {
tun->sentpackets++;
tun->sentbytes += ret;
if (wlen != ret)
{
log_warnx("net", "%s write error %d/%u",
tun->name, (int)ret, (unsigned int)wlen);
} else {
log_debug("net", "> %s sent %d bytes (size=%d, type=%d, seq=%"PRIu64", reorder=%d)",
tun->name, (int)ret, pkt->len, pkt->type, pkt->seq, pkt->reorder);
}
}
if (ev_is_active(&tun->io_write) && mlvpn_cb_is_empty(pktbuf)) {
ev_io_stop(EV_A_ &tun->io_write);
}
return ret;
}
static void
mlvpn_rtun_write(EV_P_ ev_io *w, int revents)
{
mlvpn_tunnel_t *tun = w->data;
if (! mlvpn_cb_is_empty(tun->hpsbuf)) {
mlvpn_rtun_send(tun, tun->hpsbuf);
}
if (! mlvpn_cb_is_empty(tun->sbuf)) {
mlvpn_rtun_send(tun, tun->sbuf);
}
}
mlvpn_tunnel_t *
mlvpn_rtun_new(const char *name,
const char *bindaddr, const char *bindport, uint32_t bindfib,
const char *destaddr, const char *destport,
int server_mode, uint32_t timeout,
int fallback_only, uint32_t bandwidth,
uint32_t loss_tolerence, uint32_t latency_tolerence)
{
mlvpn_tunnel_t *new;
/* Some basic checks */
if (server_mode)
{
if (bindport == NULL)
{
log_warnx(NULL,
"cannot initialize socket without bindport");
return NULL;
}
} else {
if (destaddr == NULL || destport == NULL)
{
log_warnx(NULL,
"cannot initialize socket without destaddr or destport");
return NULL;
}
}
new = (mlvpn_tunnel_t *)calloc(1, sizeof(mlvpn_tunnel_t));
if (! new)
fatal(NULL, "calloc failed");
/* other values are enforced by calloc to 0/NULL */
new->name = strdup(name);
new->fd = -1;
new->server_mode = server_mode;
new->weight = 1;
new->status = MLVPN_DISCONNECTED;
new->addrinfo = NULL;
new->sentpackets = 0;
new->sentbytes = 0;
new->recvbytes = 0;
new->seq = 0;
new->expected_receiver_seq = 0;
new->saved_timestamp = -1;
new->saved_timestamp_received_at = 0;
new->srtt = 1000;
new->rttvar = 500;
new->rtt_hit = 0;
new->seq_last = 0;
new->seq_vect = (uint64_t) -1;
new->flow_id = crypto_nonce_random();
new->bandwidth = bandwidth;
new->fallback_only = fallback_only;
new->loss_tolerence = loss_tolerence;
new->latency_tolerence = latency_tolerence;
if (bindaddr)
strlcpy(new->bindaddr, bindaddr, sizeof(new->bindaddr));
if (bindport)
strlcpy(new->bindport, bindport, sizeof(new->bindport));
new->bindfib = bindfib;
if (destaddr)
strlcpy(new->destaddr, destaddr, sizeof(new->destaddr));
if (destport)
strlcpy(new->destport, destport, sizeof(new->destport));
new->sbuf = mlvpn_pktbuffer_init(PKTBUFSIZE);
new->hpsbuf = mlvpn_pktbuffer_init(PKTBUFSIZE);
mlvpn_rtun_tick(new);
new->timeout = timeout;
new->next_keepalive = 0;
LIST_INSERT_HEAD(&rtuns, new, entries);
new->io_read.data = new;
new->io_write.data = new;
new->io_timeout.data = new;
ev_init(&new->io_read, mlvpn_rtun_read);
ev_init(&new->io_write, mlvpn_rtun_write);
ev_timer_init(&new->io_timeout, mlvpn_rtun_check_timeout,
0., MLVPN_IO_TIMEOUT_DEFAULT);
ev_timer_start(EV_A_ &new->io_timeout);
update_process_title();
return new;
}
void
mlvpn_rtun_drop(mlvpn_tunnel_t *t)
{
mlvpn_tunnel_t *tmp;
mlvpn_rtun_send_disconnect(t);
mlvpn_rtun_status_down(t);
ev_timer_stop(EV_A_ &t->io_timeout);
ev_io_stop(EV_A_ &t->io_read);
LIST_FOREACH(tmp, &rtuns, entries)
{
if (mystr_eq(tmp->name, t->name))
{
LIST_REMOVE(tmp, entries);
if (tmp->name)
free(tmp->name);
if (tmp->addrinfo)
freeaddrinfo(tmp->addrinfo);
mlvpn_pktbuffer_free(tmp->sbuf);
mlvpn_pktbuffer_free(tmp->hpsbuf);
/* Safety */
tmp->name = NULL;
break;
}
}
update_process_title();
}
/* Based on tunnel bandwidth, compute a "weight" value
* to balance correctly the round robin rtun_choose.
*/
static void
mlvpn_rtun_recalc_weight()
{
mlvpn_tunnel_t *t;
uint32_t bandwidth_total = 0;
int warned = 0;
/* If the bandwidth limit is not set on all interfaces, then
* it's impossible to balance correctly! */
LIST_FOREACH(t, &rtuns, entries)
{
if (t->bandwidth == 0)
warned++;
bandwidth_total += t->bandwidth;
}
if (warned && bandwidth_total > 0) {
log_warnx("config", "you must set the bandwidth on every tunnel");
}
if (warned == 0)
{
LIST_FOREACH(t, &rtuns, entries)
{
/* useless, but we want to be sure not to divide by 0 ! */
if (t->bandwidth > 0 && bandwidth_total > 0)
{
t->weight = (((double)t->bandwidth /
(double)bandwidth_total) * 100.0);
log_debug("wrr", "%s weight = %f (%u %u)", t->name, t->weight,
t->bandwidth, bandwidth_total);
}
}
}
}
static int
mlvpn_rtun_bind(mlvpn_tunnel_t *t)
{
struct addrinfo hints, *res;
int n, fd;
memset(&hints, 0, sizeof(hints));
/* AI_PASSIVE flag: the resulting address is used to bind
to a socket for accepting incoming connections.
So, when the hostname==NULL, getaddrinfo function will
return one entry per allowed protocol family containing
the unspecified address for that family. */
hints.ai_flags = AI_PASSIVE;
hints.ai_family = AF_UNSPEC;
fd = t->fd;
hints.ai_socktype = SOCK_DGRAM;
n = priv_getaddrinfo(t->bindaddr, t->bindport, &res, &hints);
if (n <= 0)
{
log_warnx(NULL, "%s getaddrinfo error: %s", t->name, gai_strerror(n));
return -1;
}
/* Try open socket with each address getaddrinfo returned,
until getting a valid listening socket. */
log_info(NULL, "%s bind to %s", t->name, *t->bindaddr ? t->bindaddr : "any");
n = bind(fd, res->ai_addr, res->ai_addrlen);
freeaddrinfo(res);
if (n < 0)
{
log_warn(NULL, "%s bind error", t->name);
return -1;
}
return 0;
}
static int
mlvpn_rtun_start(mlvpn_tunnel_t *t)
{
int ret, fd = -1;
char *addr, *port;
struct addrinfo hints, *res;
#if defined(HAVE_FREEBSD) || defined(HAVE_OPENBSD)
int fib = t->bindfib;
#endif
fd = t->fd;
if (t->server_mode)
{
addr = t->bindaddr;
port = t->bindport;
} else {
addr = t->destaddr;
port = t->destport;
}
/* Initialize hints */
memset(&hints, 0, sizeof(hints));
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_DGRAM;
ret = priv_getaddrinfo(addr, port, &t->addrinfo, &hints);
if (ret <= 0 || !t->addrinfo)
{
log_warnx("dns", "%s getaddrinfo(%s,%s) failed: %s",
t->name, addr, port, gai_strerror(ret));
return -1;
}
res = t->addrinfo;
while (res)
{
/* creation de la socket(2) */
if ( (fd = socket(t->addrinfo->ai_family,
t->addrinfo->ai_socktype,
t->addrinfo->ai_protocol)) < 0)
{
log_warn(NULL, "%s socket creation error",
t->name);
} else {
/* Setting fib/routing-table is supported on FreeBSD and OpenBSD only */
#if defined(HAVE_FREEBSD)
if (fib > 0 && setsockopt(fd, SOL_SOCKET, SO_SETFIB, &fib, sizeof(fib)) < 0)
#elif defined(HAVE_OPENBSD)
if (fib > 0 && setsockopt(fd, SOL_SOCKET, SO_RTABLE, &fib, sizeof(fib)) < 0)
{
log_warn(NULL, "Cannot set FIB %d for kernel socket", fib);
goto error;
}
#endif
t->fd = fd;
break;
}
res = res->ai_next;
}
if (fd < 0) {
log_warnx("dns", "%s connection failed. Check DNS?",
t->name);
goto error;
}
/* setup non blocking sockets */
socklen_t val = 1;
if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(socklen_t)) < 0) {
log_warn(NULL, "%s setsockopt SO_REUSEADDR failed", t->name);
goto error;
}
if (*t->bindaddr) {
if (mlvpn_rtun_bind(t) < 0) {
goto error;
}
}
/* set non blocking after connect... May lockup the entiere process */
mlvpn_sock_set_nonblocking(fd);
mlvpn_rtun_tick(t);
ev_io_set(&t->io_read, fd, EV_READ);
ev_io_set(&t->io_write, fd, EV_WRITE);
ev_io_start(EV_A_ &t->io_read);
t->io_timeout.repeat = MLVPN_IO_TIMEOUT_DEFAULT;
return 0;
error:
if (t->fd > 0) {
close(t->fd);
t->fd = -1;
}
if (t->io_timeout.repeat < MLVPN_IO_TIMEOUT_MAXIMUM)
t->io_timeout.repeat *= MLVPN_IO_TIMEOUT_INCREMENT;
return -1;
}
static void
mlvpn_script_get_env(int *env_len, char ***env) {
char **envp;
int arglen;
*env_len = 8;
*env = (char **)calloc(*env_len + 1, sizeof(char *));
if (! *env)
fatal(NULL, "out of memory");
envp = *env;
arglen = sizeof(mlvpn_options.ip4) + 4;
envp[0] = calloc(1, arglen + 1);
if (snprintf(envp[0], arglen, "IP4=%s", mlvpn_options.ip4) < 0)
log_warn(NULL, "snprintf IP4= failed");
arglen = sizeof(mlvpn_options.ip6) + 4;
envp[1] = calloc(1, arglen + 1);
if (snprintf(envp[1], arglen, "IP6=%s", mlvpn_options.ip6) < 0)
log_warn(NULL, "snprintf IP6= failed");
arglen = sizeof(mlvpn_options.ip4_gateway) + 12;
envp[2] = calloc(1, arglen + 1);
if (snprintf(envp[2], arglen, "IP4_GATEWAY=%s", mlvpn_options.ip4_gateway) < 0)
log_warn(NULL, "snprintf IP4_GATEWAY= failed");
arglen = sizeof(mlvpn_options.ip6_gateway) + 12;
envp[3] = calloc(1, arglen + 1);
if (snprintf(envp[3], arglen, "IP6_GATEWAY=%s", mlvpn_options.ip6_gateway) < 0)
log_warn(NULL, "snprintf IP6_GATEWAY= failed");
arglen = sizeof(mlvpn_options.ip4_routes) + 11;
envp[4] = calloc(1, arglen + 1);
if (snprintf(envp[4], arglen, "IP4_ROUTES=%s", mlvpn_options.ip4_routes) < 0)
log_warn(NULL, "snprintf IP4_ROUTES= failed");
arglen = sizeof(mlvpn_options.ip6_routes) + 11;
envp[5] = calloc(1, arglen + 1);
if (snprintf(envp[5], arglen, "IP6_ROUTES=%s", mlvpn_options.ip6_routes) < 0)
log_warn(NULL, "snprintf IP6_ROUTES= failed");
arglen = sizeof(tuntap.devname) + 7;
envp[6] = calloc(1, arglen + 1);
if (snprintf(envp[6], arglen, "DEVICE=%s", tuntap.devname) < 0)
log_warn(NULL, "snprintf DEVICE= failed");
envp[7] = calloc(1, 16);
if (snprintf(envp[7], 15, "MTU=%d", mlvpn_options.mtu) < 0)
log_warn(NULL, "snprintf MTU= failed");
envp[8] = NULL;
}
static void
mlvpn_free_script_env(char **env)
{
char **envp = env;
while (*envp) {
free(*envp);
envp++;
}
free(env);
}
static void
mlvpn_rtun_status_up(mlvpn_tunnel_t *t)
{
char *cmdargs[4] = {tuntap.devname, "rtun_up", t->name, NULL};
char **env;
int env_len;
ev_tstamp now = ev_now(EV_DEFAULT_UC);
t->status = MLVPN_AUTHOK;
t->next_keepalive = NEXT_KEEPALIVE(now, t);
t->last_activity = now;
t->last_keepalive_ack = now;
t->last_keepalive_ack_sent = now;
mlvpn_update_status();
mlvpn_rtun_wrr_reset(&rtuns, mlvpn_status.fallback_mode);
mlvpn_script_get_env(&env_len, &env);
priv_run_script(3, cmdargs, env_len, env);
if (mlvpn_status.connected > 0 && mlvpn_status.initialized == 0) {
cmdargs[0] = tuntap.devname;
cmdargs[1] = "tuntap_up";
cmdargs[2] = NULL;
priv_run_script(2, cmdargs, env_len, env);
mlvpn_status.initialized = 1;
if (reorder_buffer != NULL) {
mlvpn_rtun_reorder_drain(0);
mlvpn_reorder_reset(reorder_buffer);
}
}
mlvpn_free_script_env(env);
update_process_title();
}
void
mlvpn_rtun_status_down(mlvpn_tunnel_t *t)
{
char *cmdargs[4] = {tuntap.devname, "rtun_down", t->name, NULL};
char **env;
int env_len;
enum chap_status old_status = t->status;
t->status = MLVPN_DISCONNECTED;
t->disconnects++;
mlvpn_pktbuffer_reset(t->sbuf);
mlvpn_pktbuffer_reset(t->hpsbuf);
if (ev_is_active(&t->io_write)) {
ev_io_stop(EV_A_ &t->io_write);
}
mlvpn_update_status();
if (old_status >= MLVPN_AUTHOK)
{
mlvpn_script_get_env(&env_len, &env);
priv_run_script(3, cmdargs, env_len, env);
/* Re-initialize weight round robin */
mlvpn_rtun_wrr_reset(&rtuns, mlvpn_status.fallback_mode);
if (mlvpn_status.connected == 0 && mlvpn_status.initialized == 1) {
cmdargs[0] = tuntap.devname;
cmdargs[1] = "tuntap_down";
cmdargs[2] = NULL;
priv_run_script(2, cmdargs, env_len, env);
mlvpn_status.initialized = 0;
}
mlvpn_free_script_env(env);
if (reorder_buffer != NULL) {
mlvpn_rtun_reorder_drain(0);
mlvpn_reorder_reset(reorder_buffer);
}
}
update_process_title();
}
static void
mlvpn_update_status()
{
mlvpn_tunnel_t *t;
mlvpn_status.fallback_mode = mlvpn_options.fallback_available;
mlvpn_status.connected = 0;
LIST_FOREACH(t, &rtuns, entries)
{
if (t->status >= MLVPN_AUTHOK) {
if (!t->fallback_only)
mlvpn_status.fallback_mode = 0;
mlvpn_status.connected++;
}
}
}
static void
mlvpn_rtun_challenge_send(mlvpn_tunnel_t *t)
{
mlvpn_pkt_t *pkt;
if (mlvpn_cb_is_full(t->hpsbuf))
log_warnx("net", "%s high priority buffer: overflow", t->name);
pkt = mlvpn_pktbuffer_write(t->hpsbuf);
pkt->data[0] = 'A';
pkt->data[1] = 'U';
pkt->len = 2;
pkt->type = MLVPN_PKT_AUTH;
t->status = MLVPN_AUTHSENT;
log_debug("protocol", "%s mlvpn_rtun_challenge_send", t->name);
}
static void
mlvpn_rtun_send_auth(mlvpn_tunnel_t *t)
{
mlvpn_pkt_t *pkt;
if (t->server_mode)
{
/* server side */
if (t->status == MLVPN_DISCONNECTED || t->status >= MLVPN_AUTHOK)
{
if (mlvpn_cb_is_full(t->hpsbuf)) {
log_warnx("net", "%s high priority buffer: overflow", t->name);
mlvpn_cb_reset(t->hpsbuf);
}
pkt = mlvpn_pktbuffer_write(t->hpsbuf);
pkt->data[0] = 'O';
pkt->data[1] = 'K';
pkt->len = 2;
pkt->type = MLVPN_PKT_AUTH_OK;
if (t->status < MLVPN_AUTHOK)
t->status = MLVPN_AUTHSENT;
log_debug("protocol", "%s sending 'OK'", t->name);
log_info("protocol", "%s authenticated", t->name);
mlvpn_rtun_tick(t);
mlvpn_rtun_status_up(t);
if (!ev_is_active(&t->io_write)) {
ev_io_start(EV_A_ &t->io_write);
}
}
} else {
/* client side */
if (t->status == MLVPN_AUTHSENT) {
log_info("protocol", "%s authenticated", t->name);
mlvpn_rtun_tick(t);
mlvpn_rtun_status_up(t);
}
}
}
static void
mlvpn_rtun_tick_connect(mlvpn_tunnel_t *t)
{
ev_tstamp now = ev_now(EV_DEFAULT_UC);
if (t->server_mode) {
if (t->fd < 0) {
if (mlvpn_rtun_start(t) == 0) {
t->conn_attempts = 0;
} else {
return;
}
}
} else {
if (t->status < MLVPN_AUTHOK) {
t->conn_attempts++;
t->last_connection_attempt = now;
if (t->fd < 0) {
if (mlvpn_rtun_start(t) == 0) {
t->conn_attempts = 0;
} else {
return;
}
}
}
mlvpn_rtun_challenge_send(t);
}
}
mlvpn_tunnel_t *
mlvpn_rtun_choose()
{
mlvpn_tunnel_t *tun;
tun = mlvpn_rtun_wrr_choose();
return tun;
}
static void
mlvpn_rtun_send_keepalive(ev_tstamp now, mlvpn_tunnel_t *t)
{
mlvpn_pkt_t *pkt;
if (mlvpn_cb_is_full(t->hpsbuf))
log_warnx("net", "%s high priority buffer: overflow", t->name);
else {
log_debug("protocol", "%s sending keepalive", t->name);
pkt = mlvpn_pktbuffer_write(t->hpsbuf);
pkt->type = MLVPN_PKT_KEEPALIVE;
}
t->next_keepalive = NEXT_KEEPALIVE(now, t);
}
static void
mlvpn_rtun_send_disconnect(mlvpn_tunnel_t *t)
{
mlvpn_pkt_t *pkt;
if (mlvpn_cb_is_full(t->hpsbuf))
log_warnx("net", "%s high priority buffer: overflow", t->name);
else {
log_debug("protocol", "%s sending disconnect", t->name);
pkt = mlvpn_pktbuffer_write(t->hpsbuf);
pkt->type = MLVPN_PKT_DISCONNECT;
}
mlvpn_rtun_send(t, t->hpsbuf);
}
static void
switch_to_fallback_if_necessary() {
mlvpn_tunnel_t *t;
LIST_FOREACH(t, &rtuns, entries) {
if (! t->fallback_only && t->status != MLVPN_HIGH_LATENCY && t->status != MLVPN_LOSSY) {
mlvpn_status.fallback_mode = 0;
mlvpn_rtun_wrr_reset(&rtuns, mlvpn_status.fallback_mode);
return;
}
}
if (mlvpn_options.fallback_available) {
log_info(NULL, "all tunnels are down, lossy or too slow, switch fallback mode");
mlvpn_status.fallback_mode = 1;
mlvpn_rtun_wrr_reset(&rtuns, mlvpn_status.fallback_mode);
} else {
log_info(NULL, "all tunnels are down, lossy or too slow but fallback is not available");
}
}
static void
mlvpn_rtun_check_lossy(mlvpn_tunnel_t *tun)
{
int loss = mlvpn_loss_ratio(tun);
int status_changed = 0;
if (loss >= tun->loss_tolerence && tun->status == MLVPN_AUTHOK) {
log_info("rtt", "%s packet loss reached threashold: %d%%/%d%%",
tun->name, loss, tun->loss_tolerence);
tun->status = MLVPN_LOSSY;
status_changed = 1;
} else if (loss < tun->loss_tolerence && tun->status == MLVPN_LOSSY) {
log_info("rtt", "%s packet loss acceptable again: %d%%/%d%%",
tun->name, loss, tun->loss_tolerence);
tun->status = MLVPN_AUTHOK;
status_changed = 1;
}
/* are all links in high latency or lossy mode ? switch to fallback ? */
if (status_changed) {
switch_to_fallback_if_necessary();
}
}
static void
mlvpn_rtun_check_slow(mlvpn_tunnel_t *tun)
{
if(tun->latency_tolerence == 1000) {
return;
}
int status_changed = 0;
if (tun->srtt >= tun->latency_tolerence && tun->status == MLVPN_AUTHOK) {
log_info("rtt", "%s latency reached threashold: %fms/%dms",
tun->name, tun->srtt, tun->latency_tolerence);
tun->status = MLVPN_HIGH_LATENCY;
status_changed = 1;
} else if (tun->srtt < tun->latency_tolerence && tun->status == MLVPN_HIGH_LATENCY) {
log_info("rtt", "%s latency acceptable again: %fms/%dms",
tun->name, tun->srtt, tun->latency_tolerence);
tun->status = MLVPN_AUTHOK;
status_changed = 1;
}
/* are all links in high latency or lossy mode ? switch to fallback ? */
if (status_changed) {
switch_to_fallback_if_necessary();
}
}
static void
mlvpn_rtun_check_timeout(EV_P_ ev_timer *w, int revents)
{
mlvpn_tunnel_t *t = w->data;
ev_tstamp now = ev_now(EV_DEFAULT_UC);
if (t->status >= MLVPN_AUTHOK && t->timeout > 0) {
if ((t->last_keepalive_ack != 0) && (t->last_keepalive_ack + t->timeout) < now) {
log_info("protocol", "%s timeout", t->name);
mlvpn_rtun_status_down(t);
} else {
if (now > t->next_keepalive)
mlvpn_rtun_send_keepalive(now, t);
}
} else if (t->status < MLVPN_AUTHOK) {
mlvpn_rtun_tick_connect(t);
}
if (!ev_is_active(&t->io_write) && ! mlvpn_cb_is_empty(t->hpsbuf)) {
ev_io_start(EV_A_ &t->io_write);
}
mlvpn_rtun_check_lossy(t);
mlvpn_rtun_check_slow(t);
}
static void
mlvpn_rtun_adjust_reorder_timeout(EV_P_ ev_timer *w, int revents)
{
mlvpn_tunnel_t *t;
double max_srtt = 0.0;
double tmp;
LIST_FOREACH(t, &rtuns, entries)
{
if (t->status >= MLVPN_AUTHOK) {
/* We don't want to monitor fallback only links inside the
* reorder timeout algorithm
*/
if (!t->fallback_only && t->rtt_hit) {
tmp = t->srtt + (4 * t->rttvar);
max_srtt = max_srtt > tmp ? max_srtt : tmp;
}
}
}
/* Update the reorder algorithm */
if (max_srtt > 0) {
/* Apply a factor to the srtt in order to get a window */
max_srtt *= 2.2;
log_debug("reorder", "adjusting reordering drain timeout to %.0fms",
max_srtt);
reorder_drain_timeout.repeat = max_srtt / 1000.0;
} else {
reorder_drain_timeout.repeat = 0.8; /* Conservative 800ms shot */
}
}
static void
tuntap_io_event(EV_P_ ev_io *w, int revents)
{
if (revents & EV_READ) {
mlvpn_tuntap_read(&tuntap);
} else if (revents & EV_WRITE) {
mlvpn_tuntap_write(&tuntap);
/* Nothing else to read */
if (mlvpn_cb_is_empty(tuntap.sbuf)) {
ev_io_stop(EV_A_ &tuntap.io_write);
}
}
}
static void
mlvpn_tuntap_init()
{
mlvpn_proto_t proto;
memset(&tuntap, 0, sizeof(tuntap));
snprintf(tuntap.devname, MLVPN_IFNAMSIZ-1, "%s", "mlvpn0");
tuntap.maxmtu = 1500 - PKTHDRSIZ(proto) - IP4_UDP_OVERHEAD;
log_debug(NULL, "absolute maximum mtu: %d", tuntap.maxmtu);
tuntap.type = MLVPN_TUNTAPMODE_TUN;
tuntap.sbuf = mlvpn_pktbuffer_init(PKTBUFSIZE);
ev_init(&tuntap.io_read, tuntap_io_event);
ev_init(&tuntap.io_write, tuntap_io_event);
}
static void
update_process_title()
{
if (! process_title)
return;
char title[1024];
char *s;
mlvpn_tunnel_t *t;
char status[32];
int len;
memset(title, 0, sizeof(title));
if (*process_title)
strlcat(title, process_title, sizeof(title));
LIST_FOREACH(t, &rtuns, entries)
{
switch(t->status) {
case MLVPN_AUTHOK:
s = "@";
break;
case MLVPN_HIGH_LATENCY:
case MLVPN_LOSSY:
s = "~";
break;
default:
s = "!";
break;
}
len = snprintf(status, sizeof(status) - 1, " %s%s", s, t->name);
if (len) {
status[len] = 0;
strlcat(title, status, sizeof(title));
}
}
setproctitle("%s", title);
}
static void
mlvpn_config_reload(EV_P_ ev_signal *w, int revents)
{
log_info("config", "reload (SIGHUP)");
priv_reload_resolver();
/* configuration file path does not matter after
* the first intialization.
*/
int config_fd = priv_open_config("");
if (config_fd > 0)
{
if (mlvpn_config(config_fd, 0) != 0) {
log_warn("config", "reload failed");
} else {
if (time(&mlvpn_status.last_reload) == -1)
log_warn("config", "last_reload time set failed");
mlvpn_rtun_recalc_weight();
}
} else {
log_warn("config", "open failed");
}
}
static void
mlvpn_quit(EV_P_ ev_signal *w, int revents)
{
mlvpn_tunnel_t *t;
log_info(NULL, "killed by signal SIGTERM, SIGQUIT or SIGINT");
LIST_FOREACH(t, &rtuns, entries)
{
ev_timer_stop(EV_A_ &t->io_timeout);
ev_io_stop(EV_A_ &t->io_read);
if (t->status >= MLVPN_AUTHOK) {
mlvpn_rtun_send_disconnect(t);
}
}
ev_break(EV_A_ EVBREAK_ALL);
}
int
main(int argc, char **argv)
{
int i, c, option_index, config_fd;
struct stat st;
ev_signal signal_hup;
ev_signal signal_sigquit, signal_sigint, signal_sigterm;
extern char *__progname;
#ifdef ENABLE_CONTROL
struct mlvpn_control control;
#endif
/* uptime statistics */
if (time(&mlvpn_status.start_time) == -1)
log_warn(NULL, "start_time time() failed");
if (time(&mlvpn_status.last_reload) == -1)
log_warn(NULL, "last_reload time() failed");
log_init(1, 2, "mlvpn");
_progname = strdup(__progname);
saved_argv = calloc(argc + 1, sizeof(*saved_argv));
for(i = 0; i < argc; i++) {
saved_argv[i] = strdup(argv[i]);
}
saved_argv[i] = NULL;
compat_init_setproctitle(argc, argv);
argv = saved_argv;
/* Parse the command line quickly for config file name.
* This is needed for priv_init to know where the config
* file is.
*
* priv_init will not allow to change the config file path.
*/
while(1)
{
c = getopt_long(argc, saved_argv, optstr,
long_options, &option_index);
if (c == -1)
break;
switch (c)
{
case 1: /* --natural-title */
mlvpn_options.change_process_title = 0;
break;
case 2: /* --debug */
mlvpn_options.debug = 1;
break;
case 3: /* --yes-run-as-root */
mlvpn_options.root_allowed = 1;
break;
case 'c': /* --config */
strlcpy(mlvpn_options.config_path, optarg,
sizeof(mlvpn_options.config_path));
break;
case 'D': /* debug= */
mlvpn_options.debug = 1;
log_accept(optarg);
break;
case 'n': /* --name */
strlcpy(mlvpn_options.process_name, optarg,
sizeof(mlvpn_options.process_name));
break;
case 'u': /* --user */
strlcpy(mlvpn_options.unpriv_user, optarg,
sizeof(mlvpn_options.unpriv_user));
break;
case 'v': /* --verbose */
mlvpn_options.verbose++;
break;
case 'V': /* --version */
printf("mlvpn version %s.\n", VERSION);
_exit(0);
break;
case 'q': /* --quiet */
mlvpn_options.verbose--;
break;
case 'h': /* --help */
default:
usage(argv);
}
}
/* Config file check */
if (access(mlvpn_options.config_path, R_OK) != 0) {
log_warnx("config", "unable to read config file %s",
mlvpn_options.config_path);
}
if (stat(mlvpn_options.config_path, &st) < 0) {
fatal("config", "unable to open file");
} else if (st.st_mode & (S_IRWXG|S_IRWXO)) {
fatal("config", "file is group/other accessible");
}
/* Some common checks */
if (getuid() == 0)
{
void *pw = getpwnam(mlvpn_options.unpriv_user);
if (!mlvpn_options.root_allowed && ! pw)
fatal(NULL, "you are not allowed to run this program as root. "
"please specify a valid user with --user option");
if (! pw)
fatal(NULL, "invalid unprivilged username");
}
#ifdef HAVE_LINUX
if (access("/dev/net/tun", R_OK|W_OK) != 0)
{
fatal(NULL, "unable to open /dev/net/tun");
}
#endif
if (mlvpn_options.change_process_title)
{
__progname = "mlvpn";
if (*mlvpn_options.process_name)
{
process_title = mlvpn_options.process_name;
setproctitle("%s [priv]", mlvpn_options.process_name);
} else {
process_title = "";
setproctitle("[priv]");
}
}
if (crypto_init() == -1)
fatal(NULL, "libsodium initialization failed");
log_init(mlvpn_options.debug, mlvpn_options.verbose, mlvpn_options.process_name);
#ifdef HAVE_LINUX
mlvpn_systemd_notify();
#endif
LIST_INIT(&rtuns);
priv_init(argv, mlvpn_options.unpriv_user);
if (mlvpn_options.change_process_title)
update_process_title();
freebuf = mlvpn_freebuffer_init(512);
/* Kill me if my root process dies ! */
#ifdef HAVE_LINUX
prctl(PR_SET_PDEATHSIG, SIGCHLD);
#endif
/* Config file opening / parsing */
config_fd = priv_open_config(mlvpn_options.config_path);
if (config_fd < 0)
fatalx("cannot open config file");
if (! (loop = ev_default_loop(EVFLAG_AUTO)))
fatal(NULL, "cannot initialize libev. check LIBEV_FLAGS?");
/* tun/tap initialization */
mlvpn_tuntap_init();
if (mlvpn_config(config_fd, 1) != 0)
fatalx("cannot open config file");
if (mlvpn_tuntap_alloc(&tuntap) <= 0)
fatalx("cannot create tunnel device");
else
log_info(NULL, "created interface `%s'", tuntap.devname);
mlvpn_sock_set_nonblocking(tuntap.fd);
/* This is a dummy value which will be overwritten when the first
* SRTT values will be available
*/
ev_init(&reorder_drain_timeout, &mlvpn_rtun_reorder_drain_timeout);
ev_io_set(&tuntap.io_read, tuntap.fd, EV_READ);
ev_io_set(&tuntap.io_write, tuntap.fd, EV_WRITE);
ev_io_start(loop, &tuntap.io_read);
ev_timer_init(&reorder_adjust_rtt_timeout,
mlvpn_rtun_adjust_reorder_timeout, 0., 1.0);
ev_timer_start(EV_A_ &reorder_adjust_rtt_timeout);
priv_set_running_state();
#ifdef ENABLE_CONTROL
/* Initialize mlvpn remote control system */
strlcpy(control.fifo_path, mlvpn_options.control_unix_path,
sizeof(control.fifo_path));
control.mode = MLVPN_CONTROL_READWRITE;
control.fifo_mode = 0600;
control.bindaddr = strdup(mlvpn_options.control_bind_host);
control.bindport = strdup(mlvpn_options.control_bind_port);
mlvpn_control_init(&control);
#endif
/* re-compute rtun weight based on bandwidth allocation */
mlvpn_rtun_recalc_weight();
/* Last check before running */
if (getppid() == 1)
fatalx("Privileged process died");
ev_signal_init(&signal_hup, mlvpn_config_reload, SIGHUP);
ev_signal_init(&signal_sigint, mlvpn_quit, SIGINT);
ev_signal_init(&signal_sigquit, mlvpn_quit, SIGQUIT);
ev_signal_init(&signal_sigterm, mlvpn_quit, SIGTERM);
ev_signal_start(loop, &signal_hup);
ev_signal_start(loop, &signal_sigint);
ev_signal_start(loop, &signal_sigquit);
ev_signal_start(loop, &signal_sigterm);
ev_run(loop, 0);
free(_progname);
return 0;
}
|
a4123e76564489093ccd0d27a862198ff1ae5a1f
|
f6e5f3c038fb15cb1bfd2e0a6e8038324656bd28
|
/3rdparty/openssl-win32/openssl/e_os.h
|
1b84e10939085dc6dae8dcd9e6bd89e97337c357
|
[
"OpenSSL",
"MIT"
] |
permissive
|
vslavik/winsparkle
|
c838830255f0fc0d0d1c4c6251e450ebf0eb9a45
|
415acf557e8c15a12d8168d298b3b577fdbc6d54
|
refs/heads/master
| 2023-09-01T13:39:55.053989
| 2023-08-31T16:20:45
| 2023-08-31T17:17:37
| 467,582
| 1,105
| 279
|
NOASSERTION
| 2023-09-13T21:46:13
| 2010-01-11T16:13:10
|
C++
|
UTF-8
|
C
| false
| false
| 32
|
h
|
e_os.h
|
#include "../../openssl/e_os.h"
|
aa43dc994f1cad628837110df4cc25193bfdfba7
|
89db60818afeb3dc7c3b7abe9ceae155f074f7f2
|
/src/cmd/acid/list.c
|
af9f77ae6c7c498fa96c0fc39e74ca30828acd79
|
[
"bzip2-1.0.6",
"LPL-1.02",
"MIT"
] |
permissive
|
9fans/plan9port
|
63c3d01928c6f8a8617d3ea6ecc05bac72391132
|
65c090346a38a8c30cb242d345aa71060116340c
|
refs/heads/master
| 2023-08-25T17:14:26.233105
| 2023-08-23T13:21:37
| 2023-08-23T18:47:08
| 26,095,474
| 1,645
| 468
|
NOASSERTION
| 2023-09-05T16:55:41
| 2014-11-02T22:40:13
|
C
|
UTF-8
|
C
| false
| false
| 4,520
|
c
|
list.c
|
#include <u.h>
#include <libc.h>
#include <bio.h>
#include <ctype.h>
#include <mach.h>
#define Extern extern
#include "acid.h"
static List **tail;
List*
construct(Node *l)
{
List *lh, **save;
save = tail;
lh = 0;
tail = &lh;
build(l);
tail = save;
return lh;
}
int
listlen(List *l)
{
int len;
len = 0;
while(l) {
len++;
l = l->next;
}
return len;
}
void
build(Node *n)
{
List *l;
Node res;
if(n == 0)
return;
switch(n->op) {
case OLIST:
build(n->left);
build(n->right);
return;
default:
expr(n, &res);
l = al(res.type);
l->store = res.store;
*tail = l;
tail = &l->next;
}
}
List*
addlist(List *l, List *r)
{
List *f;
if(l == 0)
return r;
for(f = l; f->next; f = f->next)
;
f->next = r;
return l;
}
void
append(Node *r, Node *list, Node *val)
{
List *l, *f;
l = al(val->type);
l->store = val->store;
l->next = 0;
r->op = OCONST;
r->type = TLIST;
if(list->store.u.l == 0) {
list->store.u.l = l;
r->store.u.l = l;
return;
}
for(f = list->store.u.l; f->next; f = f->next)
;
f->next = l;
r->store.u.l = list->store.u.l;
}
int
listcmp(List *l, List *r)
{
if(l == r)
return 1;
while(l) {
if(r == 0)
return 0;
if(l->type != r->type)
return 0;
switch(l->type) {
case TINT:
if(l->store.u.ival != r->store.u.ival)
return 0;
break;
case TFLOAT:
if(l->store.u.fval != r->store.u.fval)
return 0;
break;
case TSTRING:
if(scmp(l->store.u.string, r->store.u.string) == 0)
return 0;
break;
case TLIST:
if(listcmp(l->store.u.l, r->store.u.l) == 0)
return 0;
break;
}
l = l->next;
r = r->next;
}
if(l != r)
return 0;
return 1;
}
void
nthelem(List *l, int n, Node *res)
{
if(n < 0)
error("negative index in []");
while(l && n--)
l = l->next;
res->op = OCONST;
if(l == 0) {
res->type = TLIST;
res->store.u.l = 0;
return;
}
res->type = l->type;
res->store = l->store;
}
void
delete(List *l, int n, Node *res)
{
List **tl;
if(n < 0)
error("negative index in delete");
res->op = OCONST;
res->type = TLIST;
res->store.u.l = l;
for(tl = &res->store.u.l; l && n--; l = l->next)
tl = &l->next;
if(l == 0)
error("element beyond end of list");
*tl = l->next;
}
List*
listvar(char *s, long v)
{
List *l, *tl;
tl = al(TLIST);
l = al(TSTRING);
tl->store.u.l = l;
l->store.fmt = 's';
l->store.u.string = strnode(s);
l->next = al(TINT);
l = l->next;
l->store.fmt = 'X';
l->store.u.ival = v;
return tl;
}
static List*
listregisters(Map *map, Regs *regs)
{
List **tail, *l2, *l;
Regdesc *rp;
u64int v;
l2 = 0;
tail = &l2;
for(rp=mach->reglist; rp->name; rp++){
if(rget(regs, rp->name, &v) < 0)
continue;
l = al(TSTRING);
l->store.fmt = 's';
l->store.u.string = strnode(rp->name);
*tail = l;
tail = &l->next;
l = al(TINT);
l->store.fmt = 'X';
l->store.u.ival = v;
*tail = l;
tail = &l->next;
}
return l2;
}
static List*
listlocals(Map *map, Regs *regs, Symbol *fn, int class)
{
int i;
u32int val;
Symbol s;
List **tail, *l2;
l2 = 0;
tail = &l2;
if(fn == nil)
return l2;
for(i = 0; indexlsym(fn, i, &s)>=0; i++) {
if(s.class != class)
continue;
if(class == CAUTO && (s.name==0 || s.name[0] == '.'))
continue;
if(lget4(map, regs, s.loc, &val) < 0)
continue;
*tail = listvar(s.name, val);
tail = &(*tail)->next;
}
return l2;
}
static List*
listparams(Map *map, Regs *regs, Symbol *fn)
{
return listlocals(map, regs, fn, CPARAM);
}
static List*
listautos(Map *map, Regs *regs, Symbol *fn)
{
return listlocals(map, regs, fn, CAUTO);
}
int
trlist(Map *map, Regs *regs, u64int pc, u64int callerpc, Symbol *sym, int depth)
{
List *q, *l;
static List **tail;
if (tracelist == 0) /* first time */
tail = &tracelist;
q = al(TLIST);
*tail = q;
tail = &q->next;
l = al(TINT); /* Function address */
q->store.u.l = l;
l->store.u.ival = sym ? sym->loc.addr : pc;
l->store.fmt = 'X';
l->next = al(TINT); /* actual pc address */
l = l->next;
l->store.u.ival = pc;
l->store.fmt = 'X';
l->next = al(TINT); /* called from address */
l = l->next;
l->store.u.ival = callerpc;
l->store.fmt = 'X';
l->next = al(TLIST); /* make list of params */
l = l->next;
if(sym)
l->store.u.l = listparams(map, regs, sym);
l->next = al(TLIST); /* make list of locals */
l = l->next;
if(sym)
l->store.u.l = listautos(map, regs, sym);
l->next = al(TLIST); /* make list of registers */
l = l->next;
l->store.u.l = listregisters(map, regs);
return depth<40;
}
|
9914f88761264f3b6076ddd9b838e6810b8e6db9
|
ee3fbae790f72a9a95ff7a85749c466ca105a58b
|
/Sources/GtkCHelpers/gtk_dialog.c
|
27c2aad2dcc9e3910854a6cfa3a184abce73058b
|
[
"BSD-2-Clause"
] |
permissive
|
rhx/SwiftGtk
|
0eab7bbdfd80e6ccc9eb9ed371c5647a4d67fc4f
|
91ba88b4c240089327a1125b58ca86c083f29679
|
refs/heads/main
| 2023-08-31T22:07:00.921723
| 2023-07-29T07:57:58
| 2023-07-29T07:57:58
| 60,699,564
| 315
| 36
|
BSD-2-Clause
| 2021-01-27T19:47:07
| 2016-06-08T13:23:23
|
Swift
|
UTF-8
|
C
| false
| false
| 9,300
|
c
|
gtk_dialog.c
|
#include "gtk_dialog.h"
/// Convenience function to create a dialog with a single button.
/// This creates a new GtkDialog with title `title` (or `NULL` for the default title; see gtk_window_set_title())
/// and transient parent parent (or NULL for none; see gtk_window_set_transient_for()).
/// The `flags` argument can be used to make the dialog modal (GTK_DIALOG_MODAL)
/// and/or to have it destroyed along with its transient parent (GTK_DIALOG_DESTROY_WITH_PARENT).
/// After `flags`, the button text and response ID pairs should be listed.
/// The button text can be an arbitrary text.
/// If the user clicks the dialog button, `GtkDialog` will emit the "response" signal
/// with the corresponding response ID.
/// If a GtkDialog receives the “delete-event” signal, it will emit ::response
/// with a response ID of `GTK_RESPONSE_DELETE_EVENT`.
/// However, destroying a dialog does not emit the ::response signal;
/// so be careful relying on ::response when using the `GTK_DIALOG_DESTROY_WITH_PARENT` flag.
/// Buttons are from left to right, so the first button in the list will be the leftmost button in the dialog.
/// @param title Title of the dialog
/// @param parent parent window
/// @param flags flags to use such as `GTK_DIALOG_MODAL`
/// @param first_button_text text to display for the button
/// @param response_type any positive number, or one of the values in the `GtkResponseType` enumeration.
GtkWidget *gtk_c_helper_dialog_new_with_button(const gchar *title, GtkWindow *parent, GtkDialogFlags flags, const gchar *first_button_text, GtkResponseType response_type)
{
return gtk_dialog_new_with_buttons(title, parent, flags, first_button_text, response_type, NULL);
}
/// Convenience function to create a dialog with two buttons.
/// This creates a new GtkDialog with title `title` (or NULL for the default title; see gtk_window_set_title())
/// and transient parent parent (or NULL for none; see gtk_window_set_transient_for()).
/// The `flags` argument can be used to make the dialog modal (GTK_DIALOG_MODAL)
/// and/or to have it destroyed along with its transient parent (GTK_DIALOG_DESTROY_WITH_PARENT).
/// After `flags`, the button text and response ID pairs should be listed.
/// Each button text can be an arbitrary text.
/// If the user clicks the dialog button, `GtkDialog` will emit the "response" signal
/// with the corresponding response ID.
/// If a GtkDialog receives the “delete-event” signal, it will emit ::response
/// with a response ID of `GTK_RESPONSE_DELETE_EVENT`.
/// However, destroying a dialog does not emit the ::response signal;
/// so be careful relying on ::response when using the `GTK_DIALOG_DESTROY_WITH_PARENT` flag.
/// Buttons are from left to right, so the first button in the list will be the leftmost button in the dialog.
/// @param title Title of the dialog
/// @param parent parent window
/// @param flags flags to use such as `GTK_DIALOG_MODAL`
/// @param first_button_text text to display for the first button
/// @param first_response_type any positive number, or one of the values in the `GtkResponseType` enumeration.
/// @param second_button_text text to display for the second button
/// @param second_response_type any positive number, or one of the values in the `GtkResponseType` enumeration.
GtkWidget *gtk_c_helper_dialog_new_with_two_buttons(const gchar *title, GtkWindow *parent, GtkDialogFlags flags, const gchar *first_button_text, GtkResponseType first_response_type, const gchar *second_button_text, GtkResponseType second_response_type)
{
return gtk_dialog_new_with_buttons(title, parent, flags, first_button_text, first_response_type, second_button_text, second_response_type, NULL);
}
/// Convenience function to create a dialog with three buttons.
/// This creates a new GtkDialog with title `title` (or NULL for the default title; see gtk_window_set_title())
/// and transient parent parent (or NULL for none; see gtk_window_set_transient_for()).
/// The `flags` argument can be used to make the dialog modal (GTK_DIALOG_MODAL)
/// and/or to have it destroyed along with its transient parent (GTK_DIALOG_DESTROY_WITH_PARENT).
/// After `flags`, the button text and response ID pairs should be listed.
/// Each button text can be an arbitrary text.
/// If the user clicks the dialog button, `GtkDialog` will emit the "response" signal
/// with the corresponding response ID.
/// If a GtkDialog receives the “delete-event” signal, it will emit ::response
/// with a response ID of `GTK_RESPONSE_DELETE_EVENT`.
/// However, destroying a dialog does not emit the ::response signal;
/// so be careful relying on ::response when using the `GTK_DIALOG_DESTROY_WITH_PARENT` flag.
/// Buttons are from left to right, so the first button in the list will be the leftmost button in the dialog.
/// @param title Title of the dialog
/// @param parent parent window
/// @param flags flags to use such as `GTK_DIALOG_MODAL`
/// @param first_button_text text to display for the first button
/// @param first_response_type any positive number, or one of the values in the `GtkResponseType` enumeration.
/// @param second_button_text text to display for the second button
/// @param second_response_type any positive number, or one of the values in the `GtkResponseType` enumeration.
/// @param third_button_text text to display for the second button
/// @param third_response_type any positive number, or one of the values in the `GtkResponseType` enumeration.
GtkWidget *gtk_c_helper_dialog_new_with_three_buttons(const gchar *title, GtkWindow *parent, GtkDialogFlags flags, const gchar *first_button_text, GtkResponseType first_response_type, const gchar *second_button_text, GtkResponseType second_response_type, const gchar *third_button_text, GtkResponseType third_response_type)
{
return gtk_dialog_new_with_buttons(title, parent, flags, first_button_text, first_response_type, second_button_text, second_response_type, third_button_text, third_response_type, NULL);
}
/// Creates a new message dialog,
/// which is a simple dialog with some text the user may want to see.
/// When the user clicks a button a “response” signal is emitted
/// with response IDs from `GtkResponseType` corresponding to the buttons.
/// See GtkDialog for more details.
/// @param parent parent window or `nil`
/// @param flags flags to use such as `GTK_DIALOG_MODAL`
/// @param type message type such as `GTK_MESSAGE_INFO`
/// @param buttons button types, such as `GTK_BUTTONS_OK_CANCEL`
/// @param text content text
GtkWidget *gtk_c_helper_message_dialog_new_with_button(GtkWindow *parent, GtkDialogFlags flags, GtkMessageType type, GtkButtonsType buttons, const gchar *text)
{
return gtk_message_dialog_new(parent, flags, type, buttons, "%s", text);
}
/// Creates a new message dialog,
/// which is a simple dialog with some Pango markup the user may want to see.
/// When the user clicks a button a “response” signal is emitted
/// with response IDs from `GtkResponseType` corresponding to the buttons.
/// See GtkDialog for more details.
/// @param parent parent window or `nil`
/// @param flags flags to use such as `GTK_DIALOG_MODAL`
/// @param type message type such as `GTK_MESSAGE_INFO`
/// @param buttons button types, such as `GTK_BUTTONS_OK_CANCEL`
/// @param markup content markup
GtkWidget *gtk_c_helper_message_dialog_new_markup_with_button(GtkWindow *parent, GtkDialogFlags flags, GtkMessageType type, GtkButtonsType buttons, const gchar *markup)
{
return gtk_message_dialog_new_with_markup(parent, flags, type, buttons, "%s", markup);
}
/// Convenience function to set the secondary text for a message dialog.
/// @param message_dialog message dialog to set the secondary text for
/// @param text secondary text to display
void gtk_c_helper_message_dialog_set_secondary_text(GtkMessageDialog *message_dialog, const gchar *text) {
gtk_message_dialog_format_secondary_text(message_dialog, "%s", text);
}
/// Convenience function to set the secondary markup for a message dialog.
/// @param message_dialog message dialog to set the secondary text for
/// @param text secondary text to display
void gtk_c_helper_message_dialog_set_secondary_markup(GtkMessageDialog *message_dialog, const gchar *text) {
gtk_message_dialog_format_secondary_markup(message_dialog, "%s", text);
}
/// Convenience method to create a file chooser dialog with two buttons.
/// @param title title of the dialog
/// @param parent parent window or `nil`
/// @param action file chooser action such as `GTK_FILE_CHOOSER_ACTION_OPEN`
/// @param first_button_text title of the first button
/// @param first_response_type any positive number, or one of the values in the `GtkResponseType` enumeration.
/// @param second_button_text title of the second button
/// @param second_response_type any positive number, or one of the values in the `GtkResponseType` enumeration.
GtkWidget *gtk_c_helper_file_chooser_dialog_new_with_two_buttons(const gchar *title, GtkWindow *parent, GtkFileChooserAction action, const gchar *first_button_text, GtkResponseType first_response_type, const gchar *second_button_text, GtkResponseType second_response_type)
{
return gtk_file_chooser_dialog_new(title, parent, action, first_button_text, first_response_type, second_button_text, second_response_type, NULL);
}
|
86c2237b4c58b871d1a86a63aff1666aec4e04d5
|
9907672fcd81ab73ac63b2a83422a82bf31eadde
|
/aizu/tyama_aizu2503.c
|
7da59ac47894555afdaa6ee2158a368deb7d61e0
|
[
"0BSD"
] |
permissive
|
cielavenir/procon
|
bbe1974b9bddb51b76d58722a0686a5b477c4456
|
746e1a91f574f20647e8aaaac0d9e6173f741176
|
refs/heads/master
| 2023-06-21T23:11:24.562546
| 2023-06-11T13:15:15
| 2023-06-11T13:15:15
| 7,557,464
| 137
| 136
| null | 2020-10-20T09:35:52
| 2013-01-11T09:40:26
|
C++
|
UTF-8
|
C
| false
| false
| 298
|
c
|
tyama_aizu2503.c
|
z[999][999],d[999],n,m,a,b,i;
int D(c){
if(d[c]>=0)return d[c];
int i=0,x=0,y;
for(;i<n;i++)if(z[i][c]){
y=D(i)+z[i][c];
if(x<y)x=y;
}
return d[c]=x;
}
main(x){
for(scanf("%d%d",&n,&m);i<m;i++)scanf("%d%d%d",&a,&b,&x),z[a][b]=x;
for(i=1;i<n;i++)d[i]=-1;
printf("%d\n",D(n-1));exit(0);
}
|
2ec3bb4396aac2b44c282bd7cad1d6912c86d0ba
|
fff6d13af91db925a94b3e3474108fafd519bba0
|
/src/Win95/stdComm.h
|
6ec093fdf5346cc01133b463c8eca696b8bc76fd
|
[
"LicenseRef-scancode-warranty-disclaimer"
] |
no_license
|
shinyquagsire23/OpenJKDF2
|
94f1364628924ac944466107606b91c6faeec3df
|
b79b8c210878b6f276ed3d1a5dad91d9219e6ce1
|
refs/heads/master
| 2023-07-08T16:41:38.986577
| 2023-06-28T08:47:39
| 2023-06-28T08:47:39
| 139,542,792
| 381
| 34
|
NOASSERTION
| 2023-06-28T08:47:40
| 2018-07-03T07:09:45
|
C
|
UTF-8
|
C
| false
| false
| 6,849
|
h
|
stdComm.h
|
#ifndef _WIN95_STDCOMM_H
#define _WIN95_STDCOMM_H
#ifdef __cplusplus
extern "C" {
#endif
#include "types.h"
#include "globals.h"
#include "Platform/Networking/Basic/stdComm_basic.h"
#include "Platform/Networking/GNS/stdComm_GNS.h"
#include "Platform/Networking/None/stdComm_none.h"
#define stdComm_Startup_ADDR (0x004C9530)
#define stdComm_Shutdown_ADDR (0x004C9550)
#define stdComm_OpenConnection_ADDR (0x004C9570)
#define stdComm_CloseConnection_ADDR (0x004C95B0)
#define stdComm_EnumSessions_ADDR (0x004C9600)
#define stdComm_EnumSessions2_ADDR (0x004C9620)
#define stdComm_EnumPlayers_ADDR (0x004C9630)
#define stdComm_SendToPlayer_ADDR (0x004C9640)
#define stdComm_Recv_ADDR (0x004C9710)
#define stdComm_Open_ADDR (0x004C97A0)
#define stdComm_Close_ADDR (0x004C9820)
#define stdComm_CreatePlayer_ADDR (0x004C9850)
#define stdComm_seed_idk_ADDR (0x004C98D0)
#define stdComm_EarlyInit_ADDR (0x004C9930)
#define stdComm_DoReceive_ADDR (0x004C99B0)
#define stdComm_cogMsg_SendEnumPlayers_ADDR (0x004C99E0)
#define stdComm_cogMsg_HandleEnumPlayers_ADDR (0x004C9A40)
#define DirectPlay_EarlyInit_ADDR (0x0042F840)
#define DirectPlay_Startup_ADDR (0x0042FA40)
#define DirectPlay_Destroy_ADDR (0x0042FAB0)
#define DirectPlay_InitConnection_ADDR (0x0042FB10)
#define DirectPlay_CloseConnection_ADDR (0x0042FB80)
#define DirectPlay_Send_ADDR (0x0042FBB0)
#define DirectPlay_Receive_ADDR (0x0042FBE0)
#define DirectPlay_OpenHost_ADDR (0x0042FC90)
#define DirectPlay_GetSession_passwordidk_ADDR (0x0042FDC0)
#define DirectPlay_IdkSessionDesc_ADDR (0x0042FEE0)
#define DirectPlay_SetSessionFlagidk_ADDR (0x0042FF50)
#define DirectPlay_SetSessionDesc_ADDR (0x0042FFF0)
#define DirectPlay_Open_ADDR (0x004300D0)
#define DirectPlay_Close_ADDR (0x00430180)
#define DirectPlay_StartSession_ADDR (0x004301A0)
#define DirectPlay_GetCaps_ADDR (0x004302E0)
#define DirectPlay_EnumPlayers_ADDR (0x00430330)
#define DirectPlay_EnumSessions_ADDR (0x004303C0)
#define DirectPlay_EnumSessions2_ADDR (0x00430470)
#define DirectPlay_CreatePlayer_ADDR (0x004304E0)
#define DirectPlay_DestroyPlayer_ADDR (0x00430530)
#define DirectPlay_CreateGroup_ADDR (0x00430550)
#define DirectPlay_AddPlayerToGroup_ADDR (0x00430570)
#define DirectPlay_DeletePlayerFromGroup_ADDR (0x00430590)
#define DirectPlay_EnumGroupPlayers_ADDR (0x004305B0)
#define DirectPlay_SendLobbyMessage_ADDR (0x004305E0)
#define DirectPlay_EnumConnectionsCallback_ADDR (0x004306E0)
#define DirectPlay_EnumSessionsCallback_ADDR (0x004307C0)
#define DirectPlay_EnumPlayersCallback_ADDR (0x00430810)
#define DirectPlay_sub_4308C0_ADDR (0x004308C0)
#define DirectPlay_parseSessionDescidk_ADDR (0x004308F0)
int stdComm_Startup();
void stdComm_Shutdown();
HRESULT stdComm_EnumSessions2(void);
int stdComm_seed_idk(jkMultiEntry *pEntry);
int stdComm_CreatePlayer(jkMultiEntry *pEntry);
int stdComm_Recv(sithCogMsg *msg);
int stdComm_DoReceive();
int stdComm_SendToPlayer(sithCogMsg *msg, int sendto_id);
int DirectPlay_EnumPlayersCallback(DPID dpId, DWORD dwPlayerType, LPCDPNAME lpName, DWORD dwFlags, LPVOID lpContext);
void stdComm_cogMsg_SendEnumPlayers(int sendtoId);
int stdComm_cogMsg_HandleEnumPlayers(sithCogMsg *msg);
int stdComm_EarlyInit();
//static void (*stdComm_Shutdown)() = (void*)stdComm_Shutdown_ADDR;
//static int (*stdComm_Startup)() = (void*)stdComm_Startup_ADDR;
//static void (*stdComm_EnumSessions2)() = (void*)stdComm_EnumSessions2_ADDR;
#ifdef WIN32_BLOBS
static int (*DirectPlay_Startup)() = (void*)DirectPlay_Startup_ADDR;
static int (*DirectPlay_EarlyInit)(wchar_t*, wchar_t*) = (void*)DirectPlay_EarlyInit_ADDR;
//static int (*stdComm_EarlyInit)() = (void*)stdComm_EarlyInit_ADDR;
static int (*stdComm_Open)(int idx, wchar_t* pwPassword) = (void*)stdComm_Open_ADDR;
static int (*stdComm_OpenConnection)(void* a) = (void*)stdComm_OpenConnection_ADDR;
static void (*stdComm_CloseConnection)() = (void*)stdComm_CloseConnection_ADDR;
//static int (*stdComm_seed_idk)(void*) = (void*)stdComm_seed_idk_ADDR;
//static int (*stdComm_CreatePlayer)(void*) = (void*)stdComm_CreatePlayer_ADDR;
//static int (*stdComm_DoReceive)() = (void*)stdComm_DoReceive_ADDR;
static void (*stdComm_Close)() = (void*)stdComm_Close_ADDR;
//static BOOL (*stdComm_SendToPlayer)(void *a1, int sendto_id) = (void*)stdComm_SendToPlayer_ADDR;
static int (*DirectPlay_SendLobbyMessage)(void*, uint32_t) = (void*)DirectPlay_SendLobbyMessage_ADDR;
static int (*DirectPlay_EnumSessions2)() = (void*)DirectPlay_EnumSessions2_ADDR;
static int (*DirectPlay_Receive)(int *pIdOut, int *pMsgIdOut, int *pLenOut) = (void*)DirectPlay_Receive_ADDR;
static BOOL (*DirectPlay_Send)(DPID idFrom, DPID idTo, void *lpData, DWORD dwDataSize) = (void*)DirectPlay_Send_ADDR;
static int (*DirectPlay_SetSessionFlagidk)(int) = (void*)DirectPlay_SetSessionFlagidk_ADDR;
static wchar_t* (*DirectPlay_SetSessionDesc)(int a1, DWORD a2) = (void*)DirectPlay_SetSessionDesc_ADDR;
static DPID (*DirectPlay_CreatePlayer)(wchar_t*, int) = (void*)DirectPlay_CreatePlayer_ADDR;
static void (*DirectPlay_Close)() = (void*)DirectPlay_Close_ADDR;
static int (*DirectPlay_OpenHost)(void*) = (void*)DirectPlay_OpenHost_ADDR;
static int (*DirectPlay_GetSession_passwordidk)(void*) = (void*)DirectPlay_GetSession_passwordidk_ADDR;
static int (*stdComm_EnumSessions)(int, void*) = (void*)stdComm_EnumSessions_ADDR;
static void (*DirectPlay_EnumPlayers)(int a) = (void*)DirectPlay_EnumPlayers_ADDR;
static int (*DirectPlay_StartSession)(void*, void*) = (void*)DirectPlay_StartSession_ADDR;
static void (*DirectPlay_Destroy)() = (void*)DirectPlay_Destroy_ADDR;
static int (*DirectPlay_IdkSessionDesc)(jkMultiEntry* pEntry) = (void*)DirectPlay_IdkSessionDesc_ADDR;
#else
int stdComm_OpenConnection(void* a);
void stdComm_CloseConnection();
int stdComm_Open(int idx, wchar_t* pwPassword);
//int stdComm_seed_idk(void* a);
//int stdComm_CreatePlayer(void* a);
//int stdComm_DoReceive();
void stdComm_Close();
//BOOL stdComm_SendToPlayer(void *a1, int sendto_id);
int DirectPlay_SendLobbyMessage(void* pPkt, uint32_t pktLen);
int DirectPlay_EnumSessions2();
int DirectPlay_Receive(int *pIdOut, int *pMsgIdOut, int *pLenOut);
BOOL DirectPlay_Send(DPID idFrom, DPID idTo, void *lpData, DWORD dwDataSize);
void DirectPlay_SetSessionDesc(const char* a1, DWORD maxPlayers);
BOOL DirectPlay_SetSessionFlagidk(int a1);
BOOL DirectPlay_Startup();
int DirectPlay_EarlyInit(wchar_t* pwIdk, wchar_t* pwPlayerName);
DPID DirectPlay_CreatePlayer(wchar_t* pwIdk, int idk2);
void DirectPlay_Close();
int DirectPlay_OpenHost(jkMultiEntry* a);
int DirectPlay_GetSession_passwordidk(jkMultiEntry* a);
int stdComm_EnumSessions(int a, void* b);
void DirectPlay_EnumPlayers(int a);
int DirectPlay_StartSession(void* a, void* b);
void DirectPlay_Destroy();
int DirectPlay_IdkSessionDesc(jkMultiEntry* pEntry);
#endif
#ifdef __cplusplus
}
#endif
#endif // _WIN95_STDCOMM_H
|
6649b1a5a4486fdc6c09915164df0263d0cd2cb2
|
0ab22620ebb8b0301c353bd09a4d4c2108f6b109
|
/unittests/general/Several/bin32/firebird/examples/api/api16.c
|
3bd81d3d32af35853ce7d75786f9dd3d35d27228
|
[
"Apache-2.0"
] |
permissive
|
danieleteti/delphimvcframework
|
f31bd2964f61251b63f54bcd0454c96b22fa951d
|
03b0463ca2116779433288b1ef4b2c8d2cdfbb90
|
refs/heads/master
| 2023-09-04T11:54:06.720380
| 2023-09-04T09:34:18
| 2023-09-04T09:34:18
| 36,435,897
| 1,238
| 444
|
Apache-2.0
| 2023-09-04T09:34:37
| 2015-05-28T12:08:43
|
Pascal
|
UTF-8
|
C
| false
| false
| 6,505
|
c
|
api16.c
|
/********************************************************************8
**
** Program type: API
**
** Description: This program does an asynchronous event wait
** on a trigger set up in employee.sales.
** Somebody must add a new sales order to alert
** this program. That role can be accomplished
** by running programs stat12t or api16t at the
** same time.
**
** When the event is fired, this program selects
** back any new records and updates (current) those
** records to status "open". The entire program runs
** in a single read-committed (wait, no version)
** transaction, so transaction doesn't need to be started
** after an event.
* The contents of this file are subject to the Interbase Public
* License Version 1.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.Inprise.com/IPL.html
*
* Software distributed under the License is distributed on an
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
* or implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code was created by Inprise Corporation
* and its predecessors. Portions created by Inprise Corporation are
* Copyright (C) Inprise Corporation.
*
* All Rights Reserved.
* Contributor(s): ______________________________________.
*/
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "example.h"
#include <ibase.h>
/* Sleep for Windows is a stupid loop with I/O */
#if defined _MSC_VER
#include <windows.h>
#define SLEEP(x) Sleep(x * 1000 )
#else
#define SLEEP(x) sleep(x)
#endif
short event_flag = 0;
void ast_routine (void *, USHORT, const UCHAR *);
int main(int argc, char** argv)
{
isc_db_handle DB = NULL; /* database handle */
isc_tr_handle trans = NULL; /* transaction handle */
isc_stmt_handle stmt = NULL; /* transaction handle */
ISC_STATUS_ARRAY status; /* status vector */
char * event_buffer;
char * result_buffer;
long event_id;
short length;
char dbname[128];
char po_number[9];
XSQLDA * sqlda;
short nullind = 0;
char query[128], update[128];
long count[2], i = 0;
ISC_STATUS_ARRAY Vector;
char ids[2][15];
int first = 1;
int ret = 0;
/* Transaction parameter block for read committed */
static char isc_tpb[5] = {isc_tpb_version1,
isc_tpb_write,
isc_tpb_read_committed,
isc_tpb_wait,
isc_tpb_no_rec_version};
if (argc > 1)
strcpy(dbname, argv[1]);
else
strcpy(dbname, "employee.fdb");
strcpy (ids[0], "new_order");
strcpy (ids[1], "change_order");
count[0] = 0;
count[1] = 0;
sqlda = (XSQLDA *) malloc(XSQLDA_LENGTH(1));
sqlda->sqln = 1;
sqlda->version = 1;
sqlda->sqlvar[0].sqldata = po_number;
sqlda->sqlvar[0].sqlind = &nullind;
if (isc_attach_database (status, 0, dbname, &DB, 0, NULL))
{ERREXIT(status, 1)}
/* SET TRANSACTION ISOLATION LEVEL READ COMMITTED */
if (isc_start_transaction (status, &trans, 1, &DB, 5, isc_tpb))
{ERREXIT(status, 1)}
/* Prepare the query to look at the result tables */
strcpy(query, " SELECT po_number FROM sales \
WHERE order_status = 'new' FOR UPDATE");
/* This is for the update where current of */
strcpy(update,
"UPDATE sales SET order_status = 'open' WHERE CURRENT OF C");
isc_dsql_allocate_statement(status, &DB, &stmt);
if (isc_dsql_prepare(status, &trans, &stmt, 0, query, 1, sqlda))
{ERREXIT(status, 1)};
/* Call the cursor "C" */
isc_dsql_set_cursor_name(status, &stmt, "C", 0);
/* Allocate an event block and initialize its values
** This will wait on two named events
*/
length = (short) isc_event_block((char **) &event_buffer,
(char **) &result_buffer,
2, ids[0], ids[1], 0);
/* Request the server to notify us of our events of interest.
** When one of the two named events is triggered, the ast_routine
** will be called with event_buffer, an updated buffer and length
** que_events returns ast_returns value
*/
if(isc_que_events(status, &DB, &event_id, length,
event_buffer, ast_routine, result_buffer))
{ERREXIT(status, 1)}
while (!ret)
{
i++;
/* If the event was triggered, reset the buffer and re-queue */
if (event_flag)
{
/* Check for first ast_call. isc_que_events fires
each event to get processing started */
if ( first )
{
first = 0;
event_flag = 0;
}
else
{
event_flag = 0;
/* event_counts will compare the various events
** listed in the two buffers and update the
** appropriate count_array elements with the difference
** in the counts in the two buffers.
*/
isc_event_counts(Vector, length, (char *) event_buffer,
(char *) result_buffer);
/* Look through the count array */
count[0] += Vector[0];
count[1] += Vector[1];
/* Select query to look at triggered events */
if (isc_dsql_execute(status, &trans, &stmt, 1, NULL))
{ERREXIT(status, 1)}
while (!isc_dsql_fetch(status, &stmt, 1, sqlda))
{
po_number[8] = 0;
printf("api16: %s\n", po_number);
/* exit on processing the last example record*/
if (!strncmp(po_number, "VNEW4", 5))
ret = 1;
/* Update current row */
if(isc_dsql_execute_immediate(status, &DB,
&trans, 0, update, 1, NULL))
{ERREXIT(status, 1)}
}
/* Close cursor */
isc_dsql_free_statement(status, &stmt, DSQL_close);
}
/* Re-queue for the next event */
if (isc_que_events(status, &DB, &event_id, length,
event_buffer, ast_routine, result_buffer))
{ERREXIT(status, 1)}
}
/* This does not block, but as a sample program there is nothing
** else for us to do, so we will take a nap
*/
SLEEP(1);
}
isc_commit_transaction(status, &trans);
isc_detach_database (status, &DB);
printf("Event complete, exiting\n");
free( sqlda);
return 0;
}
/*
** The called routine is always called with these three buffers. Any
** event will land us here . PLus we get called once when the
** program first starts.
*/
void ast_routine(void *result, USHORT length, /*const*/ UCHAR *updated)
{
/* Set the global event flag */
event_flag++;
printf("ast routine was called\n");
/* Copy the updated buffer to the result buffer */
while (length--)
*(UCHAR*)result++ = *updated++;
}
|
445bb60c6563806d7bcc652d324c6cc358a6cb87
|
07327b5e8b2831b12352bf7c6426bfda60129da7
|
/Include/10.0.16299.0/km/ucx/1.3/ucxglobals.h
|
eb0a5afc3d03af794fef7448da406b6d9b5f07ba
|
[] |
no_license
|
tpn/winsdk-10
|
ca279df0fce03f92036e90fb04196d6282a264b7
|
9b69fd26ac0c7d0b83d378dba01080e93349c2ed
|
refs/heads/master
| 2021-01-10T01:56:18.586459
| 2018-02-19T21:26:31
| 2018-02-19T21:29:50
| 44,352,845
| 218
| 432
| null | null | null | null |
UTF-8
|
C
| false
| false
| 1,407
|
h
|
ucxglobals.h
|
/*++
Copyright (c) Microsoft Corporation. All rights reserved.
Module Name:
UcxGlobals.h
Abstract:
UCX global definitions.
Environment:
Kernel-mode only.
--*/
//
// NOTE: This header is generated by stubwork. Please make any
// modifications to the corresponding template files
// (.x or .y) and use stubwork to regenerate the header
//
#ifndef _UCXGLOBALS_H_
#define _UCXGLOBALS_H_
#ifndef WDF_EXTERN_C
#ifdef __cplusplus
#define WDF_EXTERN_C extern "C"
#define WDF_EXTERN_C_START extern "C" {
#define WDF_EXTERN_C_END }
#else
#define WDF_EXTERN_C
#define WDF_EXTERN_C_START
#define WDF_EXTERN_C_END
#endif
#endif
WDF_EXTERN_C_START
typedef struct _UCX_DRIVER_GLOBALS {
//
// Size in bytes of this structure
//
ULONG Size;
//
// Client's WdfDriverGlobals
//
PWDF_DRIVER_GLOBALS WdfDriverGlobals;
} UCX_DRIVER_GLOBALS, *PUCX_DRIVER_GLOBALS;
//
// The UCX_DRIVER_GLOBALS struct used to be named UCX_GLOBALS in a previous version
// of this header. Typedef that name to prevent breaking compilation of any existing clients
// that may have been using that name.
//
typedef UCX_DRIVER_GLOBALS UCX_GLOBALS;
typedef PUCX_DRIVER_GLOBALS PUCX_GLOBALS;
WDF_EXTERN_C_END
#endif // _UCXGLOBALS_H_
|
0f9c29743a0b3d186f6250e76d949eefe49072a5
|
e7330ee2de6543531b820b42dca701c9da1ff5e0
|
/CSFML/src/Graphics/Rect.h
|
a6be6f8c7a8d6eaae0cb627267962d936a636c0b
|
[
"Zlib"
] |
permissive
|
jeremyletang/rust-sfml
|
8481d6de2f12bbdf00cd079d5fb8144bf66d8605
|
477770dae502134fdbdee29883c3015764f62ad6
|
refs/heads/master
| 2023-08-20T07:53:44.441209
| 2023-08-19T13:27:10
| 2023-08-19T13:27:10
| 10,364,009
| 597
| 123
|
NOASSERTION
| 2023-08-19T13:27:11
| 2013-05-29T16:25:42
|
Rust
|
UTF-8
|
C
| false
| false
| 251
|
h
|
Rect.h
|
#ifndef SFML_RECT_H
#define SFML_RECT_H
typedef struct
{
float left;
float top;
float width;
float height;
} sfFloatRect;
typedef struct
{
int left;
int top;
int width;
int height;
} sfIntRect;
#endif // SFML_RECT_H
|
b1cdec23cf3615e3a2cbc05602ed35a60d0cf9ce
|
7eaf54a78c9e2117247cb2ab6d3a0c20719ba700
|
/SOFTWARE/A64-TERES/u-boot_new/fs/jffs2/mini_inflate.c
|
2f13412f98b01df041b562cb1a7abab95abebb67
|
[
"LicenseRef-scancode-free-unknown",
"Apache-2.0",
"GPL-2.0-or-later",
"mif-exception"
] |
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
| 11,473
|
c
|
mini_inflate.c
|
/*-------------------------------------------------------------------------
* Filename: mini_inflate.c
* Version: $Id: mini_inflate.c,v 1.3 2002/01/24 22:58:42 rfeany Exp $
* Copyright: Copyright (C) 2001, Russ Dill
* Author: Russ Dill <Russ.Dill@asu.edu>
* Description: Mini inflate implementation (RFC 1951)
*-----------------------------------------------------------------------*/
/*
* SPDX-License-Identifier: GPL-2.0+
*/
#include <config.h>
#include <jffs2/mini_inflate.h>
/* The order that the code lengths in section 3.2.7 are in */
static unsigned char huffman_order[] = {16, 17, 18, 0, 8, 7, 9, 6, 10, 5,
11, 4, 12, 3, 13, 2, 14, 1, 15};
inline void cramfs_memset(int *s, const int c, size n)
{
n--;
for (;n > 0; n--) s[n] = c;
s[0] = c;
}
/* associate a stream with a block of data and reset the stream */
static void init_stream(struct bitstream *stream, unsigned char *data,
void *(*inflate_memcpy)(void *, const void *, size))
{
stream->error = NO_ERROR;
stream->memcpy = inflate_memcpy;
stream->decoded = 0;
stream->data = data;
stream->bit = 0; /* The first bit of the stream is the lsb of the
* first byte */
/* really sorry about all this initialization, think of a better way,
* let me know and it will get cleaned up */
stream->codes.bits = 8;
stream->codes.num_symbols = 19;
stream->codes.lengths = stream->code_lengths;
stream->codes.symbols = stream->code_symbols;
stream->codes.count = stream->code_count;
stream->codes.first = stream->code_first;
stream->codes.pos = stream->code_pos;
stream->lengths.bits = 16;
stream->lengths.num_symbols = 288;
stream->lengths.lengths = stream->length_lengths;
stream->lengths.symbols = stream->length_symbols;
stream->lengths.count = stream->length_count;
stream->lengths.first = stream->length_first;
stream->lengths.pos = stream->length_pos;
stream->distance.bits = 16;
stream->distance.num_symbols = 32;
stream->distance.lengths = stream->distance_lengths;
stream->distance.symbols = stream->distance_symbols;
stream->distance.count = stream->distance_count;
stream->distance.first = stream->distance_first;
stream->distance.pos = stream->distance_pos;
}
/* pull 'bits' bits out of the stream. The last bit pulled it returned as the
* msb. (section 3.1.1)
*/
inline unsigned long pull_bits(struct bitstream *stream,
const unsigned int bits)
{
unsigned long ret;
int i;
ret = 0;
for (i = 0; i < bits; i++) {
ret += ((*(stream->data) >> stream->bit) & 1) << i;
/* if, before incrementing, we are on bit 7,
* go to the lsb of the next byte */
if (stream->bit++ == 7) {
stream->bit = 0;
stream->data++;
}
}
return ret;
}
inline int pull_bit(struct bitstream *stream)
{
int ret = ((*(stream->data) >> stream->bit) & 1);
if (stream->bit++ == 7) {
stream->bit = 0;
stream->data++;
}
return ret;
}
/* discard bits up to the next whole byte */
static void discard_bits(struct bitstream *stream)
{
if (stream->bit != 0) {
stream->bit = 0;
stream->data++;
}
}
/* No decompression, the data is all literals (section 3.2.4) */
static void decompress_none(struct bitstream *stream, unsigned char *dest)
{
unsigned int length;
discard_bits(stream);
length = *(stream->data++);
length += *(stream->data++) << 8;
pull_bits(stream, 16); /* throw away the inverse of the size */
stream->decoded += length;
stream->memcpy(dest, stream->data, length);
stream->data += length;
}
/* Read in a symbol from the stream (section 3.2.2) */
static int read_symbol(struct bitstream *stream, struct huffman_set *set)
{
int bits = 0;
int code = 0;
while (!(set->count[bits] && code < set->first[bits] +
set->count[bits])) {
code = (code << 1) + pull_bit(stream);
if (++bits > set->bits) {
/* error decoding (corrupted data?) */
stream->error = CODE_NOT_FOUND;
return -1;
}
}
return set->symbols[set->pos[bits] + code - set->first[bits]];
}
/* decompress a stream of data encoded with the passed length and distance
* huffman codes */
static void decompress_huffman(struct bitstream *stream, unsigned char *dest)
{
struct huffman_set *lengths = &(stream->lengths);
struct huffman_set *distance = &(stream->distance);
int symbol, length, dist, i;
do {
if ((symbol = read_symbol(stream, lengths)) < 0) return;
if (symbol < 256) {
*(dest++) = symbol; /* symbol is a literal */
stream->decoded++;
} else if (symbol > 256) {
/* Determine the length of the repitition
* (section 3.2.5) */
if (symbol < 265) length = symbol - 254;
else if (symbol == 285) length = 258;
else {
length = pull_bits(stream, (symbol - 261) >> 2);
length += (4 << ((symbol - 261) >> 2)) + 3;
length += ((symbol - 1) % 4) <<
((symbol - 261) >> 2);
}
/* Determine how far back to go */
if ((symbol = read_symbol(stream, distance)) < 0)
return;
if (symbol < 4) dist = symbol + 1;
else {
dist = pull_bits(stream, (symbol - 2) >> 1);
dist += (2 << ((symbol - 2) >> 1)) + 1;
dist += (symbol % 2) << ((symbol - 2) >> 1);
}
stream->decoded += length;
for (i = 0; i < length; i++) {
*dest = dest[-dist];
dest++;
}
}
} while (symbol != 256); /* 256 is the end of the data block */
}
/* Fill the lookup tables (section 3.2.2) */
static void fill_code_tables(struct huffman_set *set)
{
int code = 0, i, length;
/* fill in the first code of each bit length, and the pos pointer */
set->pos[0] = 0;
for (i = 1; i < set->bits; i++) {
code = (code + set->count[i - 1]) << 1;
set->first[i] = code;
set->pos[i] = set->pos[i - 1] + set->count[i - 1];
}
/* Fill in the table of symbols in order of their huffman code */
for (i = 0; i < set->num_symbols; i++) {
if ((length = set->lengths[i]))
set->symbols[set->pos[length]++] = i;
}
/* reset the pos pointer */
for (i = 1; i < set->bits; i++) set->pos[i] -= set->count[i];
}
static void init_code_tables(struct huffman_set *set)
{
cramfs_memset(set->lengths, 0, set->num_symbols);
cramfs_memset(set->count, 0, set->bits);
cramfs_memset(set->first, 0, set->bits);
}
/* read in the huffman codes for dynamic decoding (section 3.2.7) */
static void decompress_dynamic(struct bitstream *stream, unsigned char *dest)
{
/* I tried my best to minimize the memory footprint here, while still
* keeping up performance. I really dislike the _lengths[] tables, but
* I see no way of eliminating them without a sizable performance
* impact. The first struct table keeps track of stats on each bit
* length. The _length table keeps a record of the bit length of each
* symbol. The _symbols table is for looking up symbols by the huffman
* code (the pos element points to the first place in the symbol table
* where that bit length occurs). I also hate the initization of these
* structs, if someone knows how to compact these, lemme know. */
struct huffman_set *codes = &(stream->codes);
struct huffman_set *lengths = &(stream->lengths);
struct huffman_set *distance = &(stream->distance);
int hlit = pull_bits(stream, 5) + 257;
int hdist = pull_bits(stream, 5) + 1;
int hclen = pull_bits(stream, 4) + 4;
int length, curr_code, symbol, i, last_code;
last_code = 0;
init_code_tables(codes);
init_code_tables(lengths);
init_code_tables(distance);
/* fill in the count of each bit length' as well as the lengths
* table */
for (i = 0; i < hclen; i++) {
length = pull_bits(stream, 3);
codes->lengths[huffman_order[i]] = length;
if (length) codes->count[length]++;
}
fill_code_tables(codes);
/* Do the same for the length codes, being carefull of wrap through
* to the distance table */
curr_code = 0;
while (curr_code < hlit) {
if ((symbol = read_symbol(stream, codes)) < 0) return;
if (symbol == 0) {
curr_code++;
last_code = 0;
} else if (symbol < 16) { /* Literal length */
lengths->lengths[curr_code] = last_code = symbol;
lengths->count[symbol]++;
curr_code++;
} else if (symbol == 16) { /* repeat the last symbol 3 - 6
* times */
length = 3 + pull_bits(stream, 2);
for (;length; length--, curr_code++)
if (curr_code < hlit) {
lengths->lengths[curr_code] =
last_code;
lengths->count[last_code]++;
} else { /* wrap to the distance table */
distance->lengths[curr_code - hlit] =
last_code;
distance->count[last_code]++;
}
} else if (symbol == 17) { /* repeat a bit length 0 */
curr_code += 3 + pull_bits(stream, 3);
last_code = 0;
} else { /* same, but more times */
curr_code += 11 + pull_bits(stream, 7);
last_code = 0;
}
}
fill_code_tables(lengths);
/* Fill the distance table, don't need to worry about wrapthrough
* here */
curr_code -= hlit;
while (curr_code < hdist) {
if ((symbol = read_symbol(stream, codes)) < 0) return;
if (symbol == 0) {
curr_code++;
last_code = 0;
} else if (symbol < 16) {
distance->lengths[curr_code] = last_code = symbol;
distance->count[symbol]++;
curr_code++;
} else if (symbol == 16) {
length = 3 + pull_bits(stream, 2);
for (;length; length--, curr_code++) {
distance->lengths[curr_code] =
last_code;
distance->count[last_code]++;
}
} else if (symbol == 17) {
curr_code += 3 + pull_bits(stream, 3);
last_code = 0;
} else {
curr_code += 11 + pull_bits(stream, 7);
last_code = 0;
}
}
fill_code_tables(distance);
decompress_huffman(stream, dest);
}
/* fill in the length and distance huffman codes for fixed encoding
* (section 3.2.6) */
static void decompress_fixed(struct bitstream *stream, unsigned char *dest)
{
/* let gcc fill in the initial values */
struct huffman_set *lengths = &(stream->lengths);
struct huffman_set *distance = &(stream->distance);
cramfs_memset(lengths->count, 0, 16);
cramfs_memset(lengths->first, 0, 16);
cramfs_memset(lengths->lengths, 8, 144);
cramfs_memset(lengths->lengths + 144, 9, 112);
cramfs_memset(lengths->lengths + 256, 7, 24);
cramfs_memset(lengths->lengths + 280, 8, 8);
lengths->count[7] = 24;
lengths->count[8] = 152;
lengths->count[9] = 112;
cramfs_memset(distance->count, 0, 16);
cramfs_memset(distance->first, 0, 16);
cramfs_memset(distance->lengths, 5, 32);
distance->count[5] = 32;
fill_code_tables(lengths);
fill_code_tables(distance);
decompress_huffman(stream, dest);
}
/* returns the number of bytes decoded, < 0 if there was an error. Note that
* this function assumes that the block starts on a byte boundry
* (non-compliant, but I don't see where this would happen). section 3.2.3 */
long decompress_block(unsigned char *dest, unsigned char *source,
void *(*inflate_memcpy)(void *, const void *, size))
{
int bfinal, btype;
struct bitstream stream;
init_stream(&stream, source, inflate_memcpy);
do {
bfinal = pull_bit(&stream);
btype = pull_bits(&stream, 2);
if (btype == NO_COMP) decompress_none(&stream, dest + stream.decoded);
else if (btype == DYNAMIC_COMP)
decompress_dynamic(&stream, dest + stream.decoded);
else if (btype == FIXED_COMP) decompress_fixed(&stream, dest + stream.decoded);
else stream.error = COMP_UNKNOWN;
} while (!bfinal && !stream.error);
#if 0
putstr("decompress_block start\r\n");
putLabeledWord("stream.error = ",stream.error);
putLabeledWord("stream.decoded = ",stream.decoded);
putLabeledWord("dest = ",dest);
putstr("decompress_block end\r\n");
#endif
return stream.error ? -stream.error : stream.decoded;
}
|
f79170c5bea3058e77f7667a261a84f6498988b2
|
6f247f5400c6a840b6dfcb12388116dc3bb7bd49
|
/nvhw/chipset.c
|
299f7ce312b27a73e9acc3f804b67ae3b8bcda47
|
[
"MIT"
] |
permissive
|
envytools/envytools
|
c062fbc3b8af90d3df9c6e0f57e9abbfc5690d01
|
e11d670a70ae0455261ead53cdd09c321974cc64
|
refs/heads/master
| 2023-08-26T23:44:47.131591
| 2022-04-30T21:15:56
| 2022-04-30T21:15:56
| 11,620,001
| 402
| 103
|
MIT
| 2022-12-07T01:35:18
| 2013-07-23T21:43:43
|
C
|
UTF-8
|
C
| false
| false
| 5,462
|
c
|
chipset.c
|
/*
* Copyright (C) 2012 Marcelina Kościelnicka <mwk@0x04.net>
* 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 (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#include "nvhw/chipset.h"
#include "cgen/gpu.h"
#include <stdlib.h>
#include <string.h>
static bool pmc_id_flipped(uint32_t pmc_id) {
/*
* For determining endianness, there are four cases:
*
* - pre-NV10 card: always little endian, bits 7 and 31 are guaranteed
* to be 0 (they're high bits of fields that never got big values)
* - NV10+ little-endian card: bit 7 is guaranteed to be 1 (MSB of
* stepping, which is always 0xaX or 0xbX), bit 31 is guaranteed
* to be 0
* - NV10+ big-endian card: like above, but with byteswapping - bit 7
* is 0, bit 31 is 1
* - something is broken with BAR0 access and ID returns 0xffffffff
* - both bit 7 and bit 31 are set. This can happen on later cards, so
* in this case we can rely on bits 8-11 to be zero without
* byteswapping
*/
if (pmc_id & 0x80000000) {
if (!(pmc_id & 0x00000080)) /* bit 7 is 0, we're flipped */
return true;
else /* bits 31 and 7 are both 1, rely on 8-11 instead */
return !!(pmc_id & 0x00000F00);
}
return false;
}
int parse_pmc_id(uint32_t pmc_id, struct chipset_info *info) {
/* First, detect PMC_ID format and endianness */
memset(info, 0, sizeof *info);
info->endian = 0;
info->gpu = GPU_UNKNOWN;
info->gpu_desc = 0;
if (pmc_id_flipped(pmc_id)) {
/* bit 31 set - set endian flag and byteswap */
info->endian = 1;
pmc_id = (pmc_id & 0x0000ffff) << 16 | (pmc_id & 0xffff0000) >> 16;
pmc_id = (pmc_id & 0x00ff00ff) << 8 | (pmc_id & 0xff00ff00) >> 8;
}
info->pmc_id = pmc_id;
if (pmc_id & 0x80000000 && pmc_id & 0x00000F00) {
/* bit 31 still set - ie. old bit 7 was set, and bits 8-11 are
* still nonzero - BAR0 is broken */
return -1;
}
if (pmc_id & 0x80) {
/* NV10+ */
info->chipset = pmc_id >> 20 & 0x1ff;
info->card_type = info->chipset & 0x1f0;
if (info->card_type == 0x60) {
info->card_type = 0x40;
} else if (info->card_type >= 0x80 && info->card_type <= 0xa0) {
info->card_type = 0x50;
} else if (info->card_type >= 0xc0 && info->card_type <= 0x100) {
info->card_type = 0xc0;
}
for (int i = 0; i < NUM_GPU; i++) {
if (gpu_list[i].id_valid && gpu_list[i].id == info->chipset) {
info->gpu = i;
}
}
} else {
/* pre-NV10 */
if (pmc_id & 0xf000) {
if (pmc_id & 0xf00000) {
info->chipset = 5;
info->gpu = GPU_NV5;
} else {
info->chipset = 4;
info->gpu = GPU_NV4;
}
info->card_type = 4;
} else {
info->chipset = pmc_id >> 16 & 0xf;
info->card_type = info->chipset;
if (info->chipset == 1) {
info->gpu = GPU_NV1;
} else if (info->chipset == 3) {
if ((pmc_id & 0xff) >= 0x20) {
info->gpu = GPU_NV3T;
} else {
info->gpu = GPU_NV3;
}
}
}
}
if (info->gpu != GPU_UNKNOWN) {
info->gpu_desc = &gpu_list[info->gpu];
return 0;
} else {
return -1;
}
}
int is_igp(int chipset) {
switch (chipset) {
case 0x0a:
case 0x1a:
case 0x1f:
case 0x2a:
case 0x4e:
case 0x4c:
case 0x67:
case 0x68:
case 0x63:
case 0xaa:
case 0xac:
case 0xaf:
return 1;
default:
return 0;
}
}
int is_g7x(int chipset) {
if (chipset < 0x46 || chipset == 0x4a || chipset == 0x4e || chipset == 0x50 || chipset >= 0x70)
return 0;
return 1;
}
int pfb_type(int chipset) {
if (chipset <3)
return PFB_NV01;
if (chipset < 0x10)
return PFB_NV03;
if (chipset < 0x1a || chipset == 0x34)
return PFB_NV10;
if (chipset < 0x20)
return PFB_NONE; /* IGP */
if (chipset < 0x40)
return PFB_NV20;
if (chipset == 0x40 || chipset == 0x45)
return PFB_NV40;
if (chipset != 0x44 && chipset != 0x46 && chipset != 0x4a && chipset < 0x4c)
return PFB_NV41;
if (chipset != 0x50 && chipset < 0x80)
return PFB_NV44;
if (chipset < 0xc0)
return PFB_NV50;
return PFB_NVC0;
}
int get_maxparts(int chipset) {
switch (chipset) {
case 0x1a:
case 0x1f:
case 0x2a:
case 0x4e:
case 0x4c:
case 0x67:
case 0x68:
case 0x63:
return 0;
case 0x10:
case 0x15:
case 0x11:
case 0x17:
case 0x18:
case 0x20:
case 0x25:
case 0x28:
case 0x30:
case 0x35:
case 0x40:
case 0x41:
case 0x42:
case 0x47:
case 0x49:
return 4;
case 0x31:
case 0x36:
case 0x43:
case 0x4b:
return 2;
case 0x44:
case 0x4a:
case 0x46:
return 1;
default:
abort();
}
}
|
605462aeaae44c1aa83c4446e4dd9c750a5b13d9
|
e683a0b8dbb87c7ceb99e0d06896174a559d2c67
|
/Tools/swat/cmd.h
|
0df041573343e305e96aeb9b9ba7cc0c4a6aee69
|
[
"Apache-2.0"
] |
permissive
|
bluewaysw/pcgeos
|
f093d79567d977d992f47065056d14d5a04b9f14
|
c6ae4c8e77b54b9ff654c3916f2191f8b1a1b65d
|
refs/heads/master
| 2023-08-31T00:17:54.481175
| 2023-08-29T19:00:49
| 2023-08-29T19:00:49
| 157,968,410
| 603
| 88
|
Apache-2.0
| 2023-09-13T07:44:06
| 2018-11-17T09:09:55
|
Assembly
|
UTF-8
|
C
| false
| false
| 2,802
|
h
|
cmd.h
|
/***********************************************************************
*
* Copyright (c) Berkeley Softworks 1988 -- All Rights Reserved
*
* PROJECT: PCGEOS
* MODULE: Swat -- Header File for commands
* FILE: cmd.h
*
* AUTHOR: Adam de Boor: Mar 23, 1989
*
* REVISION HISTORY:
* Date Name Description
* ---- ---- -----------
* 3/23/89 ardeb Initial version
*
* DESCRIPTION:
* Declarations for Cmd module
*
*
* $Id: cmd.h,v 4.5 96/05/20 18:44:23 dbaumann Exp $
*
***********************************************************************/
#ifndef _CMD_H
#define _CMD_H
#include "sym.h"
#define CmdSubRec Tcl_SubCommandRec
#define CmdRec Tcl_CommandRec
#define CMD_ANY TCL_CMD_ANY
#define CMD_NOCHECK TCL_CMD_NOCHECK
extern void Cmd_Init (void);
extern int Cmd_PrintArg (Sym sym, int *firstPtr);
extern int Cmd_PrintSym (Sym sym, ClientData clientData);
extern int Cmd_PrintArgValue (Sym sym, ClientData clientData);
#define Cmd_Create(cmdRec) Tcl_CreateCommandByRec(interp, cmdRec)
/*
* DEFCMD is used to create a CmdRec for entering a command into the
* interpreter. It creates a function <FuncPref>Cmd to handle the command,
* and <FuncPref>CmdRec whose address should be passed off to Cmd_Create to
* install the command and its help string. The CmdRec isn't static so
* certain commands whose modules don't have an initialization function
* can be installed by Cmd_Init...
*
* cmdData should be NULL or the address of a CmdData record describing the
* arguments the command expects.
*
* The helpString does not actually reside in Swat's memory. Rather, it is
* extracted by the makedoc program and placed in the documentation file
* in swat's library directory.
*
* XXX: HighC doesn't take to "static Tcl_CmdProc FuncPref##Cmd;", mistaking it
* for a function definition, when it's actually a forward-reference sort of
* thing. However, it also doesn't bitch if we declare the thing external and
* then static, so...
*/
#if defined(__HIGHC__)
#define DEFCMD(string,FuncPref,flgs,cmdData,class,helpString) \
extern Tcl_CmdProc FuncPref##Cmd; \
const Tcl_CommandRec FuncPref##CmdRec = { #string, #class, FuncPref##Cmd, NoDelProc, cmdData, flgs }; \
static int \
FuncPref##Cmd(ClientData clientData, Tcl_Interp *interp, int argc, char **argv)
#else
#define DEFCMD(string,FuncPref,flgs,cmdData,class,helpString) \
static Tcl_CmdProc FuncPref##Cmd; \
const Tcl_CommandRec FuncPref##CmdRec = { #string, #class, FuncPref##Cmd, NoDelProc, cmdData, flgs }; \
static int \
FuncPref##Cmd(ClientData clientData, Tcl_Interp *interp, int argc, char **argv)
#endif
/*
* DEFCMDNOPROC is used to provide help that's not tied to any actual command.
*/
#define DEFCMDNOPROC(string,FuncPref,flgs,cmdData,class,helpString)
#endif _CMD_H
|
fad279672996b3a08cbfcce3df4c670112806219
|
515a17dfa8acffb7dbc076dca5be7ef3ddc2952f
|
/tools/external/fasterq-dump/cleanup_task.c
|
62c024a3ace29f0077ab3ba78dc1354a5b2713c2
|
[
"LicenseRef-scancode-ncbi",
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-us-govt-public-domain"
] |
permissive
|
ncbi/sra-tools
|
d54d2fe00214d9471b6dbd0b90c2fe0062f87cdd
|
1bb9cd2f317a232eb8f1e1d33cfc3582c71b3eec
|
refs/heads/master
| 2023-09-01T11:46:59.189830
| 2023-08-29T16:34:24
| 2023-08-29T16:34:24
| 23,203,598
| 991
| 271
|
NOASSERTION
| 2023-09-14T19:43:38
| 2014-08-21T21:25:38
|
C
|
UTF-8
|
C
| false
| false
| 7,466
|
c
|
cleanup_task.c
|
/*===========================================================================
*
* PUBLIC DOMAIN NOTICE
* National Center for Biotechnology Information
*
* This software/database is a "United States Government Work" under the
* terms of the United States Copyright Act. It was written as part of
* the author's official duties as a United States Government employee and
* thus cannot be copyrighted. This software/database is freely available
* to the public for use. The National Library of Medicine and the U.S.
* Government have not placed any restriction on its use or reproduction.
*
* Although all reasonable efforts have been taken to ensure the accuracy
* and reliability of the software and data, the NLM and the U.S.
* Government do not and cannot warrant the performance or results that
* may be obtained by using this software or data. The NLM and the U.S.
* Government disclaim all warranties, express or implied, including
* warranties of performance, merchantability or fitness for any particular
* purpose.
*
* Please cite the author in any work or product based on this material.
*
* ===========================================================================
*
*/
struct CleanupTask_t;
#define KTASK_IMPL struct CleanupTask_t
#include <kproc/impl.h>
#ifndef _h_klib_rc_
#include <klib/rc.h>
#endif
#ifndef _h_klib_out_
#include <klib/out.h>
#endif
#ifndef _h_kproc_procmgr_
#include <kproc/procmgr.h>
#endif
#ifndef _h_err_msg_
#include "err_msg.h"
#endif
#ifndef _h_locked_file_list_
#include "locked_file_list.h"
#endif
typedef struct CleanupTask_t {
KTask dad;
locked_file_list_t files_to_clean;
locked_file_list_t dirs_to_clean;
KTaskTicket ticket;
bool details;
} CleanupTask_t;
static rc_t clt_destroy( CleanupTask_t * self ) {
locked_file_list_release( & ( self -> files_to_clean ), NULL, self -> details ); /* helper.c */
locked_file_list_release( & ( self -> dirs_to_clean ), NULL, self -> details ); /* helper.c */
free( self );
return 0;
}
static rc_t clt_execute( CleanupTask_t * self ) {
KDirectory * dir;
rc_t rc;
if ( self -> details ) { InfoMsg( "CleanupTask: executing..." ); }
rc = KDirectoryNativeDir( &dir );
if ( 0 != rc ) {
ErrMsg( "clt_execute().KDirectoryNativeDir() -> %R", rc );
} else {
rc = locked_file_list_delete_files( dir, &self -> files_to_clean, self -> details ); /* helper.c */
if ( 0 == rc ) {
rc = locked_file_list_delete_dirs( dir, &self -> dirs_to_clean, self -> details ); /* helper.c */
}
{
rc_t rc2 = KDirectoryRelease( dir );
if ( 0 != rc2 ) {
ErrMsg( "clt_execute().KDirectoryRelease() -> %R", rc );
rc = ( 0 == rc ) ? rc2 : rc;
}
}
}
return rc;
}
static KTask_vt_v1 vtCleanupTask = {
/* version 1.0 */
1, 0,
/* start minor version 0 methods */
clt_destroy,
clt_execute
/* end minor version 0 methods */
};
static rc_t clt_add_task_to_proc_mgr( CleanupTask_t * task ) {
struct KProcMgr * proc_mgr;
rc_t rc = KProcMgrMakeSingleton ( &proc_mgr );
if ( 0 != rc ) {
ErrMsg( "clt_add_task_to_proc_mgr(): cannot access process-manager" );
} else {
rc = KProcMgrAddCleanupTask ( proc_mgr, &( task -> ticket ), ( KTask * )task );
if ( 0 != rc ) {
rc_t rc2 = KTaskRelease ( ( KTask * ) task );
if ( 0 != rc2 ) {
ErrMsg( "clt_add_task_to_proc_mgr().KTaskRelease() -> %R", rc2 );
}
} else if ( task -> details ) {
InfoMsg( "CleanupTask: added to ProcManager" );
}
{
rc_t rc2 = KProcMgrRelease ( proc_mgr );
if ( 0 != rc2 ) {
ErrMsg( "clt_add_task_to_proc_mgr().KProcMgrRelease() -> %R", rc2 );
rc = ( 0 == rc ) ? rc2 : rc;
}
}
}
return rc;
}
rc_t clt_create( struct CleanupTask_t **task, bool details ) {
rc_t rc = 0;
CleanupTask_t * t = malloc ( sizeof * t );
if ( NULL == t ) {
rc = RC ( rcPS, rcMgr, rcInitializing, rcMemory, rcExhausted );
} else {
t -> details = details;
if ( details ) { InfoMsg( "CleanupTask: creating..." ); }
rc = locked_file_list_init( &( t -> files_to_clean ), 25 ); /* helper.c */
if ( 0 == rc ) {
rc = locked_file_list_init( &( t -> dirs_to_clean ), 5 ); /* helper.c */
}
if ( 0 == rc ) {
rc = KTaskInit ( &t -> dad,
(const union KTask_vt *)&vtCleanupTask,
"CleanupTask",
"CleanupTask" );
if ( 0 == rc ) {
*task = ( CleanupTask_t * ) &t -> dad;
} else {
ErrMsg( "clt_create().KTaskInit() -> %R", rc );
}
}
if ( 0 != rc ) {
locked_file_list_release( &( t -> files_to_clean ), NULL, details ); /* helper.c */
locked_file_list_release( &( t -> dirs_to_clean ), NULL, details ); /* helper.c */
free( ( void * ) t );
} else {
rc = clt_add_task_to_proc_mgr( *task ); /* above */
}
}
return rc;
}
rc_t clt_add_file( struct CleanupTask_t * self, const char * filename ) {
rc_t rc = 0;
if ( NULL == self || NULL == filename ) {
rc = RC ( rcPS, rcMgr, rcInitializing, rcParam, rcInvalid );
ErrMsg( "clt_add_file() : %R", rc );
} else {
rc = locked_file_list_append( &( self -> files_to_clean ), filename ); /* helper.c */
if ( self -> details ) { InfoMsg( "clt_add_file( '%s' )", filename ); }
}
return rc;
}
rc_t clt_add_directory( struct CleanupTask_t * self, const char * dirname ) {
rc_t rc = 0;
if ( self == NULL || dirname == NULL ) {
rc = RC ( rcPS, rcMgr, rcInitializing, rcParam, rcInvalid );
ErrMsg( "clt_add_directory() : %R", rc );
} else {
rc = locked_file_list_append( &( self -> dirs_to_clean ), dirname ); /* helper.c */
if ( self -> details ) { InfoMsg( "clt_add_directory( '%s' )", dirname ); }
}
return rc;
}
rc_t clt_terminate( struct CleanupTask_t * self ) {
rc_t rc = 0;
if ( NULL == self ) {
rc = RC ( rcPS, rcMgr, rcInitializing, rcParam, rcInvalid );
ErrMsg( "clt_terminate() : %R", rc );
} else {
struct KProcMgr * proc_mgr;
rc = KProcMgrMakeSingleton ( &proc_mgr );
if ( rc != 0 ) {
ErrMsg( "clt_terminate(): cannot access process-manager" );
} else {
rc = KProcMgrRemoveCleanupTask ( proc_mgr, &( self -> ticket ) );
if ( 0 != rc ) {
ErrMsg( "clt_terminate().KProcMgrRemoveCleanupTask() -> %R", rc );
}
else if ( self -> details ) {
InfoMsg( "CleanupTask: terminating ..." );
}
{
rc_t rc2 = KProcMgrRelease ( proc_mgr );
if ( 0 != rc2 ) {
ErrMsg( "clt_terminate().KProcMgrRelease() -> %R", rc2 );
rc = ( 0 == rc ) ? rc2 : rc;
}
}
}
}
if ( 0 == rc ) {
rc = KTaskRelease ( ( KTask * )self );
if ( 0 != rc ) {
ErrMsg( "clt_terminate().KTaskRelease() -> %R", rc );
}
}
return rc;
}
|
0a849b3246637243ecb069fe486ea2b9cbee9fa4
|
8a51a96f61699f0318315ccc89cef39f6866f2b5
|
/src/backend/catalog/pg_largeobject.c
|
5bc8b763e274181c58a3a31a7c69ba5c5ad34d86
|
[
"PostgreSQL"
] |
permissive
|
postgres/postgres
|
979febf2b41c00090d1256228f768f33e7ef3b6f
|
b5934bfd6071fed3a38cea0cfaa93afda63d9c0c
|
refs/heads/master
| 2023-08-31T00:10:01.373472
| 2023-08-30T23:07:48
| 2023-08-30T23:07:48
| 927,442
| 13,691
| 4,807
|
NOASSERTION
| 2023-09-09T13:59:15
| 2010-09-21T11:35:45
|
C
|
UTF-8
|
C
| false
| false
| 4,706
|
c
|
pg_largeobject.c
|
/*-------------------------------------------------------------------------
*
* pg_largeobject.c
* routines to support manipulation of the pg_largeobject relation
*
* Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
*
* IDENTIFICATION
* src/backend/catalog/pg_largeobject.c
*
*-------------------------------------------------------------------------
*/
#include "postgres.h"
#include "access/genam.h"
#include "access/htup_details.h"
#include "access/sysattr.h"
#include "access/table.h"
#include "catalog/catalog.h"
#include "catalog/dependency.h"
#include "catalog/indexing.h"
#include "catalog/pg_largeobject.h"
#include "catalog/pg_largeobject_metadata.h"
#include "miscadmin.h"
#include "utils/acl.h"
#include "utils/fmgroids.h"
#include "utils/rel.h"
/*
* Create a large object having the given LO identifier.
*
* We create a new large object by inserting an entry into
* pg_largeobject_metadata without any data pages, so that the object
* will appear to exist with size 0.
*/
Oid
LargeObjectCreate(Oid loid)
{
Relation pg_lo_meta;
HeapTuple ntup;
Oid loid_new;
Datum values[Natts_pg_largeobject_metadata];
bool nulls[Natts_pg_largeobject_metadata];
pg_lo_meta = table_open(LargeObjectMetadataRelationId,
RowExclusiveLock);
/*
* Insert metadata of the largeobject
*/
memset(values, 0, sizeof(values));
memset(nulls, false, sizeof(nulls));
if (OidIsValid(loid))
loid_new = loid;
else
loid_new = GetNewOidWithIndex(pg_lo_meta,
LargeObjectMetadataOidIndexId,
Anum_pg_largeobject_metadata_oid);
values[Anum_pg_largeobject_metadata_oid - 1] = ObjectIdGetDatum(loid_new);
values[Anum_pg_largeobject_metadata_lomowner - 1]
= ObjectIdGetDatum(GetUserId());
nulls[Anum_pg_largeobject_metadata_lomacl - 1] = true;
ntup = heap_form_tuple(RelationGetDescr(pg_lo_meta),
values, nulls);
CatalogTupleInsert(pg_lo_meta, ntup);
heap_freetuple(ntup);
table_close(pg_lo_meta, RowExclusiveLock);
return loid_new;
}
/*
* Drop a large object having the given LO identifier. Both the data pages
* and metadata must be dropped.
*/
void
LargeObjectDrop(Oid loid)
{
Relation pg_lo_meta;
Relation pg_largeobject;
ScanKeyData skey[1];
SysScanDesc scan;
HeapTuple tuple;
pg_lo_meta = table_open(LargeObjectMetadataRelationId,
RowExclusiveLock);
pg_largeobject = table_open(LargeObjectRelationId,
RowExclusiveLock);
/*
* Delete an entry from pg_largeobject_metadata
*/
ScanKeyInit(&skey[0],
Anum_pg_largeobject_metadata_oid,
BTEqualStrategyNumber, F_OIDEQ,
ObjectIdGetDatum(loid));
scan = systable_beginscan(pg_lo_meta,
LargeObjectMetadataOidIndexId, true,
NULL, 1, skey);
tuple = systable_getnext(scan);
if (!HeapTupleIsValid(tuple))
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("large object %u does not exist", loid)));
CatalogTupleDelete(pg_lo_meta, &tuple->t_self);
systable_endscan(scan);
/*
* Delete all the associated entries from pg_largeobject
*/
ScanKeyInit(&skey[0],
Anum_pg_largeobject_loid,
BTEqualStrategyNumber, F_OIDEQ,
ObjectIdGetDatum(loid));
scan = systable_beginscan(pg_largeobject,
LargeObjectLOidPNIndexId, true,
NULL, 1, skey);
while (HeapTupleIsValid(tuple = systable_getnext(scan)))
{
CatalogTupleDelete(pg_largeobject, &tuple->t_self);
}
systable_endscan(scan);
table_close(pg_largeobject, RowExclusiveLock);
table_close(pg_lo_meta, RowExclusiveLock);
}
/*
* LargeObjectExists
*
* We don't use the system cache for large object metadata, for fear of
* using too much local memory.
*
* This function always scans the system catalog using an up-to-date snapshot,
* so it should not be used when a large object is opened in read-only mode
* (because large objects opened in read only mode are supposed to be viewed
* relative to the caller's snapshot, whereas in read-write mode they are
* relative to a current snapshot).
*/
bool
LargeObjectExists(Oid loid)
{
Relation pg_lo_meta;
ScanKeyData skey[1];
SysScanDesc sd;
HeapTuple tuple;
bool retval = false;
ScanKeyInit(&skey[0],
Anum_pg_largeobject_metadata_oid,
BTEqualStrategyNumber, F_OIDEQ,
ObjectIdGetDatum(loid));
pg_lo_meta = table_open(LargeObjectMetadataRelationId,
AccessShareLock);
sd = systable_beginscan(pg_lo_meta,
LargeObjectMetadataOidIndexId, true,
NULL, 1, skey);
tuple = systable_getnext(sd);
if (HeapTupleIsValid(tuple))
retval = true;
systable_endscan(sd);
table_close(pg_lo_meta, AccessShareLock);
return retval;
}
|
21aea2d434b03853763bf91375e91185f65583f9
|
cb55c180ed2259447653d32886f0104824973f6c
|
/libs/STM32_USB-FS-Device_Lib_V4.0.0/Libraries/STM32L1xx_StdPeriph_Driver/src/stm32l1xx_opamp.c
|
7d5d4589e3d8b4de320b68aa8f08a1bcc8d86cdf
|
[
"MIT"
] |
permissive
|
avem-labs/Avem
|
45542576f7323cca85d77225399aa5a31771e970
|
9d3f6a4158cebba2aad9ef369662ca81835ac52b
|
refs/heads/develop
| 2023-06-16T11:12:27.527248
| 2018-01-28T11:59:46
| 2018-01-28T11:59:46
| 65,394,199
| 1,362
| 410
|
MIT
| 2023-07-03T10:13:36
| 2016-08-10T15:31:26
|
C
|
UTF-8
|
C
| false
| false
| 20,235
|
c
|
stm32l1xx_opamp.c
|
/**
******************************************************************************
* @file stm32l1xx_opamp.c
* @author MCD Application Team
* @version V1.1.1
* @date 05-March-2012
* @brief This file provides firmware functions to manage the following
* functionalities of the operational amplifiers (opamp) peripheral:
* + Initialization and configuration
* + Calibration management
*
* @verbatim
==============================================================================
##### How to use this driver #####
==============================================================================
[..] The device integrates three independent rail-to-rail operational amplifiers
OPAMP1, OPAMP2 and OPAMP3:
(+) Internal connections to the ADC.
(+) Internal connections to the DAC.
(+) Internal connection to COMP1 (only OPAMP3).
(+) Internal connection for unity gain (voltage follower) configuration.
(+) Calibration capability.
(+) Selectable gain-bandwidth (2MHz in normal mode, 500KHz in low power mode).
[..]
(#) COMP AHB clock must be enabled to get write access
to OPAMP registers using
(#) RCC_APB1PeriphClockCmd(RCC_APB1Periph_COMP, ENABLE)
(#) Configure the corresponding GPIO to OPAMPx INP, OPAMPx_INN (if used)
and OPAMPx_OUT in analog mode.
(#) Configure (close/open) the OPAMP switches using OPAMP_SwitchCmd()
(#) Enable the OPAMP peripheral using OPAMP_Cmd()
-@- In order to use OPAMP outputs as ADC inputs, the opamps must be enabled
and the ADC must use the OPAMP output channel number:
(+@) OPAMP1 output is connected to ADC channel 3.
(+@) OPAMP2 output is connected to ADC channel 8.
(+@) OPAMP3 output is connected to ADC channel 13 (SW1 switch must be closed).
* @endverbatim
*
******************************************************************************
* @attention
*
* <h2><center>© COPYRIGHT 2012 STMicroelectronics</center></h2>
*
* Licensed under MCD-ST Liberty SW License Agreement V2, (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.st.com/software_license_agreement_liberty_v2
*
* 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.
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "stm32l1xx_opamp.h"
/** @addtogroup STM32L1xx_StdPeriph_Driver
* @{
*/
/** @defgroup OPAMP
* @brief OPAMP driver modules
* @{
*/
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
/** @defgroup OPAMP_Private_Functions
* @{
*/
/** @defgroup OPAMP_Group1 Initialization and configuration
* @brief Initialization and configuration
*
@verbatim
===============================================================================
##### Initialization and configuration #####
===============================================================================
@endverbatim
* @{
*/
/**
* @brief Deinitialize the OPAMPs register to its default reset value.
* @note At startup, OTR and LPOTR registers are set to factory programmed values.
* @param None.
* @retval None.
*/
void OPAMP_DeInit(void)
{
/*!< Set OPAMP_CSR register to reset value */
OPAMP->CSR = 0x00010101;
/*!< Set OPAMP_OTR register to reset value */
OPAMP->OTR = (uint32_t)(* (uint32_t*)FLASH_R_BASE + 0x00000038);
/*!< Set OPAMP_LPOTR register to reset value */
OPAMP->LPOTR = (uint32_t)(* (uint32_t*)FLASH_R_BASE + 0x0000003C);
}
/**
* @brief Close or Open the OPAMP switches.
* @param OPAMP_OPAMPxSwitchy: selects the OPAMPx switch.
* This parameter can be any combinations of the following values:
* @arg OPAMP_OPAMP1Switch3: used to connect internally OPAMP1 output to
* OPAMP1 negative input (internal follower)
* @arg OPAMP_OPAMP1Switch4: used to connect PA2 to OPAMP1 negative input
* @arg OPAMP_OPAMP1Switch5: used to connect PA1 to OPAMP1 positive input
* @arg OPAMP_OPAMP1Switch6: used to connect DAC_OUT1 to OPAMP1 positive input
* @arg OPAMP_OPAMP1SwitchANA: used to meet 1 nA input leakage
* @arg OPAMP_OPAMP2Switch3: used to connect internally OPAMP2 output to
* OPAMP2 negative input (internal follower)
* @arg OPAMP_OPAMP2Switch4: used to connect PA7 to OPAMP2 negative input
* @arg OPAMP_OPAMP2Switch5: used to connect PA6 to OPAMP2 positive input
* @arg OPAMP_OPAMP2Switch6: used to connect DAC_OUT1 to OPAMP2 positive input
* @arg OPAMP_OPAMP2Switch7: used to connect DAC_OUT2 to OPAMP2 positive input
* @arg OPAMP_OPAMP2SwitchANA: used to meet 1 nA input leakage
* @arg OPAMP_OPAMP3Switch3: used to connect internally OPAMP3 output to
* OPAMP3 negative input (internal follower)
* @arg OPAMP_OPAMP3Switch4: used to connect PC2 to OPAMP3 negative input
* @arg OPAMP_OPAMP3Switch5: used to connect PC1 to OPAMP3 positive input
* @arg OPAMP_OPAMP3Switch6: used to connect DAC_OUT1 to OPAMP3 positive input
* @arg OPAMP_OPAMP3SwitchANA: used to meet 1 nA input leakage on negative input
*
* @param NewState: New state of the OPAMP switch.
* This parameter can be:
* ENABLE to close the OPAMP switch
* or DISABLE to open the OPAMP switch
* @note OPAMP_OPAMP2Switch6 and OPAMP_OPAMP2Switch7 mustn't be closed together.
* @retval None
*/
void OPAMP_SwitchCmd(uint32_t OPAMP_OPAMPxSwitchy, FunctionalState NewState)
{
/* Check the parameter */
assert_param(IS_OPAMP_SWITCH(OPAMP_OPAMPxSwitchy));
assert_param(IS_FUNCTIONAL_STATE(NewState));
if (NewState != DISABLE)
{
/* Close the selected switches */
OPAMP->CSR |= (uint32_t) OPAMP_OPAMPxSwitchy;
}
else
{
/* Open the selected switches */
OPAMP->CSR &= (~(uint32_t)OPAMP_OPAMPxSwitchy);
}
}
/**
* @brief Enable or disable the OPAMP peripheral.
* @param OPAMP_Selection: the selected OPAMP.
* This parameter can be one of the following values:
* @arg OPAMP_Selection_OPAMP1: OPAMP1 is selected
* @arg OPAMP_Selection_OPAMP2: OPAMP2 is selected
* @arg OPAMP_Selection_OPAMP3: OPAMP3 is selected
* @param NewState: new state of the selected OPAMP peripheral.
* This parameter can be: ENABLE or DISABLE.
* @retval None
*/
void OPAMP_Cmd(uint32_t OPAMP_Selection, FunctionalState NewState)
{
/* Check the parameter */
assert_param(IS_OPAMP_ALL_PERIPH(OPAMP_Selection));
assert_param(IS_FUNCTIONAL_STATE(NewState));
if (NewState != DISABLE)
{
/* Enable the selected OPAMP */
OPAMP->CSR &= (~(uint32_t) OPAMP_Selection);
}
else
{
/* Disable the selected OPAMP */
OPAMP->CSR |= (uint32_t) OPAMP_Selection;
}
}
/**
* @brief Enable or disable the low power mode for OPAMP peripheral.
* @param OPAMP_Selection: the selected OPAMP.
* This parameter can be one of the following values:
* @arg OPAMP_Selection_OPAMP1: OPAMP1 selected
* @arg OPAMP_Selection_OPAMP2: OPAMP2 selected
* @arg OPAMP_Selection_OPAMP3: OPAMP3 selected
* @param NewState: new low power state of the selected OPAMP peripheral.
* This parameter can be: ENABLE or DISABLE.
* @retval None
*/
void OPAMP_LowPowerCmd(uint32_t OPAMP_Selection, FunctionalState NewState)
{
/* Check the parameter */
assert_param(IS_OPAMP_ALL_PERIPH(OPAMP_Selection));
assert_param(IS_FUNCTIONAL_STATE(NewState));
if (NewState != DISABLE)
{
/* Set the selected OPAMP in low power mode */
OPAMP->CSR |= (uint32_t) (OPAMP_Selection << 7);
}
else
{
/* Disable the low power mode for the selected OPAMP */
OPAMP->CSR &= (~(uint32_t) (OPAMP_Selection << 7));
}
}
/**
* @brief Select the OPAMP power range.
* @note The OPAMP power range selection must be performed while OPAMPs are powered down.
* @param OPAMP_Range: the selected OPAMP power range.
* This parameter can be one of the following values:
* @arg OPAMP_PowerRange_Low: Low power range is selected (VDDA is lower than 2.4V).
* @arg OPAMP_PowerRange_High: High power range is selected (VDDA is higher than 2.4V).
* @retval None
*/
void OPAMP_PowerRangeSelect(uint32_t OPAMP_PowerRange)
{
/* Check the parameter */
assert_param(IS_OPAMP_RANGE(OPAMP_PowerRange));
/* Reset the OPAMP range bit */
OPAMP->CSR &= (~(uint32_t) (OPAMP_CSR_AOP_RANGE));
/* Select the OPAMP power range */
OPAMP->CSR |= OPAMP_PowerRange;
}
/**
* @}
*/
/** @defgroup OPAMP_Group2 Calibration functions
* @brief Calibration functions
*
@verbatim
===============================================================================
##### Calibration functions #####
===============================================================================
@endverbatim
* @{
*/
/**
* @brief Select the trimming mode.
* @param OffsetTrimming: the selected offset trimming mode.
* This parameter can be one of the following values:
* @arg OffsetTrimming_Factory: factory trimming values are used for offset
* calibration.
* @arg OffsetTrimming_User: user trimming values are used for offset
* calibration.
* @note When OffsetTrimming_User is selected, use OPAMP_OffsetTrimConfig()
* function or OPAMP_OffsetTrimLowPowerConfig() function to adjust
* trimming value.
* @retval None
*/
void OPAMP_OffsetTrimmingModeSelect(uint32_t OPAMP_Trimming)
{
/* Check the parameter */
assert_param(IS_OPAMP_TRIMMING(OPAMP_Trimming));
/* Reset the OPAMP_OTR range bit */
OPAMP->CSR &= (~(uint32_t) (OPAMP_OTR_OT_USER));
/* Select the OPAMP offset trimming */
OPAMP->CSR |= OPAMP_Trimming;
}
/**
* @brief Configure the trimming value of OPAMPs in normal mode.
* @param OPAMP_Selection: the selected OPAMP.
* This parameter can be one of the following values:
* @arg OPAMP_Selection_OPAMP1: OPAMP1 is selected to configure the trimming value.
* @arg OPAMP_Selection_OPAMP2: OPAMP2 is selected to configure the trimming value.
* @arg OPAMP_Selection_OPAMP3: OPAMP3 is selected to configure the trimming value.
* @param OPAMP_Input: the selected OPAMP input.
* This parameter can be one of the following values:
* @arg OPAMP_Input_NMOS: NMOS input is selected to configure the trimming value.
* @arg OPAMP_Input_PMOS: PMOS input is selected to configure the trimming value.
* @param OPAMP_TrimValue: the trimming value. This parameter can be any value lower
* or equal to 0x0000001F.
* @retval None
*/
void OPAMP_OffsetTrimConfig(uint32_t OPAMP_Selection, uint32_t OPAMP_Input, uint32_t OPAMP_TrimValue)
{
uint32_t tmpreg = 0;
/* Check the parameter */
assert_param(IS_OPAMP_ALL_PERIPH(OPAMP_Selection));
assert_param(IS_OPAMP_INPUT(OPAMP_Input));
assert_param(IS_OPAMP_TRIMMINGVALUE(OPAMP_TrimValue));
/* Get the OPAMP_OTR value */
tmpreg = OPAMP->OTR;
if(OPAMP_Selection == OPAMP_Selection_OPAMP1)
{
/* Reset the OPAMP inputs selection */
tmpreg &= (uint32_t)~(OPAMP_CSR_OPA1CAL_L | OPAMP_CSR_OPA1CAL_H);
/* Select the OPAMP input */
tmpreg |= OPAMP_Input;
if(OPAMP_Input == OPAMP_Input_PMOS)
{
/* Reset the trimming value corresponding to OPAMP1 PMOS input */
tmpreg &= (0xFFFFFFE0);
/* Set the new trimming value corresponding to OPAMP1 PMOS input */
tmpreg |= (OPAMP_TrimValue);
}
else
{
/* Reset the trimming value corresponding to OPAMP1 NMOS input */
tmpreg &= (0xFFFFFC1F);
/* Set the new trimming value corresponding to OPAMP1 NMOS input */
tmpreg |= (OPAMP_TrimValue<<5);
}
}
else if (OPAMP_Selection == OPAMP_Selection_OPAMP2)
{
/* Reset the OPAMP inputs selection */
tmpreg &= (uint32_t)~(OPAMP_CSR_OPA2CAL_L | OPAMP_CSR_OPA2CAL_H);
/* Select the OPAMP input */
tmpreg |= (uint32_t)(OPAMP_Input<<8);
if(OPAMP_Input == OPAMP_Input_PMOS)
{
/* Reset the trimming value corresponding to OPAMP2 PMOS input */
tmpreg &= (0xFFFF83FF);
/* Set the new trimming value corresponding to OPAMP2 PMOS input */
tmpreg |= (OPAMP_TrimValue<<10);
}
else
{
/* Reset the trimming value corresponding to OPAMP2 NMOS input */
tmpreg &= (0xFFF07FFF);
/* Set the new trimming value corresponding to OPAMP2 NMOS input */
tmpreg |= (OPAMP_TrimValue<<15);
}
}
else
{
/* Reset the OPAMP inputs selection */
tmpreg &= (uint32_t)~(OPAMP_CSR_OPA3CAL_L | OPAMP_CSR_OPA3CAL_H);
/* Select the OPAMP input */
tmpreg |= (uint32_t)(OPAMP_Input<<16);
if(OPAMP_Input == OPAMP_Input_PMOS)
{
/* Reset the trimming value corresponding to OPAMP3 PMOS input */
tmpreg &= (0xFE0FFFFF);
/* Set the new trimming value corresponding to OPAMP3 PMOS input */
tmpreg |= (OPAMP_TrimValue<<20);
}
else
{
/* Reset the trimming value corresponding to OPAMP3 NMOS input */
tmpreg &= (0xC1FFFFFF);
/* Set the new trimming value corresponding to OPAMP3 NMOS input */
tmpreg |= (OPAMP_TrimValue<<25);
}
}
/* Set the OPAMP_OTR register */
OPAMP->OTR = tmpreg;
}
/**
* @brief Configure the trimming value of OPAMPs in low power mode.
* @param OPAMP_Selection: the selected OPAMP.
* This parameter can be one of the following values:
* @arg OPAMP_Selection_OPAMP1: OPAMP1 is selected to configure the trimming value.
* @arg OPAMP_Selection_OPAMP2: OPAMP2 is selected to configure the trimming value.
* @arg OPAMP_Selection_OPAMP3: OPAMP3 is selected to configure the trimming value.
* @param OPAMP_Input: the selected OPAMP input.
* This parameter can be one of the following values:
* @arg OPAMP_Input_NMOS: NMOS input is selected to configure the trimming value.
* @arg OPAMP_Input_PMOS: PMOS input is selected to configure the trimming value.
* @param OPAMP_TrimValue: the trimming value.
* This parameter can be any value lower or equal to 0x0000001F.
* @retval None
*/
void OPAMP_OffsetTrimLowPowerConfig(uint32_t OPAMP_Selection, uint32_t OPAMP_Input, uint32_t OPAMP_TrimValue)
{
uint32_t tmpreg = 0;
/* Check the parameter */
assert_param(IS_OPAMP_ALL_PERIPH(OPAMP_Selection));
assert_param(IS_OPAMP_INPUT(OPAMP_Input));
assert_param(IS_OPAMP_TRIMMINGVALUE(OPAMP_TrimValue));
/* Get the OPAMP_LPOTR value */
tmpreg = OPAMP->LPOTR;
if(OPAMP_Selection == OPAMP_Selection_OPAMP1)
{
/* Reset the OPAMP inputs selection */
tmpreg &= (uint32_t)~(OPAMP_CSR_OPA1CAL_L | OPAMP_CSR_OPA1CAL_H);
/* Select the OPAMP input */
tmpreg |= OPAMP_Input;
if(OPAMP_Input == OPAMP_Input_PMOS)
{
/* Reset the trimming value corresponding to OPAMP1 PMOS input */
tmpreg &= (0xFFFFFFE0);
/* Set the new trimming value corresponding to OPAMP1 PMOS input */
tmpreg |= (OPAMP_TrimValue);
}
else
{
/* Reset the trimming value corresponding to OPAMP1 NMOS input */
tmpreg &= (0xFFFFFC1F);
/* Set the new trimming value corresponding to OPAMP1 NMOS input */
tmpreg |= (OPAMP_TrimValue<<5);
}
}
else if (OPAMP_Selection == OPAMP_Selection_OPAMP2)
{
/* Reset the OPAMP inputs selection */
tmpreg &= (uint32_t)~(OPAMP_CSR_OPA2CAL_L | OPAMP_CSR_OPA2CAL_H);
/* Select the OPAMP input */
tmpreg |= (uint32_t)(OPAMP_Input<<8);
if(OPAMP_Input == OPAMP_Input_PMOS)
{
/* Reset the trimming value corresponding to OPAMP2 PMOS input */
tmpreg &= (0xFFFF83FF);
/* Set the new trimming value corresponding to OPAMP2 PMOS input */
tmpreg |= (OPAMP_TrimValue<<10);
}
else
{
/* Reset the trimming value corresponding to OPAMP2 NMOS input */
tmpreg &= (0xFFF07FFF);
/* Set the new trimming value corresponding to OPAMP2 NMOS input */
tmpreg |= (OPAMP_TrimValue<<15);
}
}
else
{
/* Reset the OPAMP inputs selection */
tmpreg &= (uint32_t)~(OPAMP_CSR_OPA3CAL_L | OPAMP_CSR_OPA3CAL_H);
/* Select the OPAMP input */
tmpreg |= (uint32_t)(OPAMP_Input<<16);
if(OPAMP_Input == OPAMP_Input_PMOS)
{
/* Reset the trimming value corresponding to OPAMP3 PMOS input */
tmpreg &= (0xFE0FFFFF);
/* Set the new trimming value corresponding to OPAMP3 PMOS input */
tmpreg |= (OPAMP_TrimValue<<20);
}
else
{
/* Reset the trimming value corresponding to OPAMP3 NMOS input */
tmpreg &= (0xC1FFFFFF);
/* Set the new trimming value corresponding to OPAMP3 NMOS input */
tmpreg |= (OPAMP_TrimValue<<25);
}
}
/* Set the OPAMP_LPOTR register */
OPAMP->LPOTR = tmpreg;
}
/**
* @brief Checks whether the specified OPAMP calibration flag is set or not.
* @note User should wait until calibration flag change the value when changing
* the trimming value.
* @param OPAMP_Selection: the selected OPAMP.
* This parameter can be one of the following values:
* @arg OPAMP_Selection_OPAMP1: OPAMP1 is selected.
* @arg OPAMP_Selection_OPAMP2: OPAMP2 is selected.
* @arg OPAMP_Selection_OPAMP3: OPAMP3 is selected.
* @retval The new state of the OPAMP calibration flag (SET or RESET).
*/
FlagStatus OPAMP_GetFlagStatus(uint32_t OPAMP_Selection)
{
FlagStatus bitstatus = RESET;
uint32_t tmpreg = 0;
/* Check the parameter */
assert_param(IS_OPAMP_ALL_PERIPH(OPAMP_Selection));
/* Get the CSR register value */
tmpreg = OPAMP->CSR;
/* Check if OPAMP1 is selected */
if(OPAMP_Selection == OPAMP_Selection_OPAMP1)
{
/* Check OPAMP1 CAL bit status */
if ((tmpreg & OPAMP_CSR_OPA1CALOUT) != (uint32_t)RESET)
{
bitstatus = SET;
}
else
{
bitstatus = RESET;
}
}
/* Check if OPAMP2 is selected */
else if(OPAMP_Selection == OPAMP_Selection_OPAMP2)
{
/* Check OPAMP2 CAL bit status */
if ((tmpreg & OPAMP_CSR_OPA2CALOUT) != (uint32_t)RESET)
{
bitstatus = SET;
}
else
{
bitstatus = RESET;
}
}
else
{
/* Check OPAMP3 CAL bit status */
if ((tmpreg & OPAMP_CSR_OPA3CALOUT) != (uint32_t)RESET)
{
bitstatus = SET;
}
else
{
bitstatus = RESET;
}
}
return bitstatus;
}
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
2c0ed897506dcb5f91d9c526ece149573a623467
|
8b98cd47f934d2a4a8d0b2842d3277b01f3fb7fa
|
/thirdparty/caltech/pgplot/drivers/ptk/tkConfig.h
|
2e844d27af53b542670eb93bea39663a1227e240
|
[] |
no_license
|
Starlink/starlink
|
1cc03b85eb78330a3622003b26b69c1733df50fe
|
2c374b3e97c9cebcc8f3bd2f8b4bb326eefe061a
|
refs/heads/master
| 2023-07-26T09:32:27.987319
| 2023-07-05T23:56:27
| 2023-07-05T23:56:27
| 5,169,323
| 139
| 45
| null | 2022-11-18T13:29:32
| 2012-07-24T18:15:25
|
Fortran
|
UTF-8
|
C
| false
| false
| 296
|
h
|
tkConfig.h
|
#ifndef _TKCONFIG
#define _TKCONFIG
#define ANSI_SIGNED_CHAR 1
#define HAS_STDARG 1
#define HAVE_LIMITS_H 1
#define HAVE_SYS_SELECT_H 1
#define HAVE_SYS_TIME_H 1
#define HAVE_UNISTD_H 1
#define SELECT_MASK fd_set
#define TIMEOFDAY_TZ 1
#define TIME_WITH_SYS_TIME 1
#define USE_PROTOTYPE 1
#endif
|
aab0a818cc83af30db7efa8ae227c1ef9dc5af9c
|
a2b20597759990445081057d35d113434cfcf970
|
/source/hack_parallel/hack_parallel/third-party/lz4/lz4hc.h
|
431f7c87c863f203f3cb08bc9cf471203899bbb4
|
[
"MIT",
"BSD-2-Clause",
"BSD-3-Clause"
] |
permissive
|
facebook/pyre-check
|
34059599c02b65605c574f13555229f3b931fd4e
|
fe8ccedc572cc1faa1fd01e9138f65e982875002
|
refs/heads/main
| 2023-09-03T19:10:11.587028
| 2023-09-02T07:40:35
| 2023-09-02T07:40:35
| 110,274,488
| 6,703
| 575
|
MIT
| 2023-09-13T17:02:32
| 2017-11-10T17:31:36
|
OCaml
|
UTF-8
|
C
| false
| false
| 9,618
|
h
|
lz4hc.h
|
/*
LZ4 HC - High Compression Mode of LZ4
Header File
Copyright (C) 2011-2015, Yann Collet.
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
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.
You can contact the author at :
- LZ4 source repository : https://github.com/Cyan4973/lz4
- LZ4 public forum : https://groups.google.com/forum/#!forum/lz4c
*/
#pragma once
#if defined (__cplusplus)
extern "C" {
#endif
/*****************************
* Includes
*****************************/
#include <stddef.h> /* size_t */
/**************************************
* Block Compression
**************************************/
int LZ4_compress_HC (const char* src, char* dst, int srcSize, int maxDstSize, int compressionLevel);
/*
LZ4_compress_HC :
Destination buffer 'dst' must be already allocated.
Compression completion is guaranteed if 'dst' buffer is sized to handle worst circumstances (data not compressible)
Worst size evaluation is provided by function LZ4_compressBound() (see "lz4.h")
srcSize : Max supported value is LZ4_MAX_INPUT_SIZE (see "lz4.h")
compressionLevel : Recommended values are between 4 and 9, although any value between 0 and 16 will work.
0 means "use default value" (see lz4hc.c).
Values >16 behave the same as 16.
return : the number of bytes written into buffer 'dst'
or 0 if compression fails.
*/
/* Note :
Decompression functions are provided within LZ4 source code (see "lz4.h") (BSD license)
*/
int LZ4_sizeofStateHC(void);
int LZ4_compress_HC_extStateHC(void* state, const char* src, char* dst, int srcSize, int maxDstSize, int compressionLevel);
/*
LZ4_compress_HC_extStateHC() :
Use this function if you prefer to manually allocate memory for compression tables.
To know how much memory must be allocated for the compression tables, use :
int LZ4_sizeofStateHC();
Allocated memory must be aligned on 8-bytes boundaries (which a normal malloc() will do properly).
The allocated memory can then be provided to the compression functions using 'void* state' parameter.
LZ4_compress_HC_extStateHC() is equivalent to previously described function.
It just uses externally allocated memory for stateHC.
*/
/**************************************
* Streaming Compression
**************************************/
#define LZ4_STREAMHCSIZE 262192
#define LZ4_STREAMHCSIZE_SIZET (LZ4_STREAMHCSIZE / sizeof(size_t))
typedef struct { size_t table[LZ4_STREAMHCSIZE_SIZET]; } LZ4_streamHC_t;
/*
LZ4_streamHC_t
This structure allows static allocation of LZ4 HC streaming state.
State must then be initialized using LZ4_resetStreamHC() before first use.
Static allocation should only be used in combination with static linking.
If you want to use LZ4 as a DLL, please use construction functions below, which are future-proof.
*/
LZ4_streamHC_t* LZ4_createStreamHC(void);
int LZ4_freeStreamHC (LZ4_streamHC_t* streamHCPtr);
/*
These functions create and release memory for LZ4 HC streaming state.
Newly created states are already initialized.
Existing state space can be re-used anytime using LZ4_resetStreamHC().
If you use LZ4 as a DLL, use these functions instead of static structure allocation,
to avoid size mismatch between different versions.
*/
void LZ4_resetStreamHC (LZ4_streamHC_t* streamHCPtr, int compressionLevel);
int LZ4_loadDictHC (LZ4_streamHC_t* streamHCPtr, const char* dictionary, int dictSize);
int LZ4_compress_HC_continue (LZ4_streamHC_t* streamHCPtr, const char* src, char* dst, int srcSize, int maxDstSize);
int LZ4_saveDictHC (LZ4_streamHC_t* streamHCPtr, char* safeBuffer, int maxDictSize);
/*
These functions compress data in successive blocks of any size, using previous blocks as dictionary.
One key assumption is that previous blocks (up to 64 KB) remain read-accessible while compressing next blocks.
There is an exception for ring buffers, which can be smaller 64 KB.
Such case is automatically detected and correctly handled by LZ4_compress_HC_continue().
Before starting compression, state must be properly initialized, using LZ4_resetStreamHC().
A first "fictional block" can then be designated as initial dictionary, using LZ4_loadDictHC() (Optional).
Then, use LZ4_compress_HC_continue() to compress each successive block.
It works like LZ4_compress_HC(), but use previous memory blocks as dictionary to improve compression.
Previous memory blocks (including initial dictionary when present) must remain accessible and unmodified during compression.
As a reminder, size 'dst' buffer to handle worst cases, using LZ4_compressBound(), to ensure success of compression operation.
If, for any reason, previous data blocks can't be preserved unmodified in memory during next compression block,
you must save it to a safer memory space, using LZ4_saveDictHC().
Return value of LZ4_saveDictHC() is the size of dictionary effectively saved into 'safeBuffer'.
*/
/**************************************
* Deprecated Functions
**************************************/
/* Deprecate Warnings */
/* Should these warnings messages be a problem,
it is generally possible to disable them,
with -Wno-deprecated-declarations for gcc
or _CRT_SECURE_NO_WARNINGS in Visual for example.
You can also define LZ4_DEPRECATE_WARNING_DEFBLOCK. */
#ifndef LZ4_DEPRECATE_WARNING_DEFBLOCK
# define LZ4_DEPRECATE_WARNING_DEFBLOCK
# define LZ4_GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__)
# if (LZ4_GCC_VERSION >= 405) || defined(__clang__)
# define LZ4_DEPRECATED(message) __attribute__((deprecated(message)))
# elif (LZ4_GCC_VERSION >= 301)
# define LZ4_DEPRECATED(message) __attribute__((deprecated))
# elif defined(_MSC_VER)
# define LZ4_DEPRECATED(message) __declspec(deprecated(message))
# else
# pragma message("WARNING: You need to implement LZ4_DEPRECATED for this compiler")
# define LZ4_DEPRECATED(message)
# endif
#endif // LZ4_DEPRECATE_WARNING_DEFBLOCK
/* compression functions */
/* these functions are planned to trigger warning messages by r131 approximately */
int LZ4_compressHC (const char* source, char* dest, int inputSize);
int LZ4_compressHC_limitedOutput (const char* source, char* dest, int inputSize, int maxOutputSize);
int LZ4_compressHC2 (const char* source, char* dest, int inputSize, int compressionLevel);
int LZ4_compressHC2_limitedOutput (const char* source, char* dest, int inputSize, int maxOutputSize, int compressionLevel);
int LZ4_compressHC_withStateHC (void* state, const char* source, char* dest, int inputSize);
int LZ4_compressHC_limitedOutput_withStateHC (void* state, const char* source, char* dest, int inputSize, int maxOutputSize);
int LZ4_compressHC2_withStateHC (void* state, const char* source, char* dest, int inputSize, int compressionLevel);
int LZ4_compressHC2_limitedOutput_withStateHC(void* state, const char* source, char* dest, int inputSize, int maxOutputSize, int compressionLevel);
int LZ4_compressHC_continue (LZ4_streamHC_t* LZ4_streamHCPtr, const char* source, char* dest, int inputSize);
int LZ4_compressHC_limitedOutput_continue (LZ4_streamHC_t* LZ4_streamHCPtr, const char* source, char* dest, int inputSize, int maxOutputSize);
/* Streaming functions following the older model; should no longer be used */
LZ4_DEPRECATED("use LZ4_createStreamHC() instead") void* LZ4_createHC (char* inputBuffer);
LZ4_DEPRECATED("use LZ4_saveDictHC() instead") char* LZ4_slideInputBufferHC (void* LZ4HC_Data);
LZ4_DEPRECATED("use LZ4_freeStreamHC() instead") int LZ4_freeHC (void* LZ4HC_Data);
LZ4_DEPRECATED("use LZ4_compress_HC_continue() instead") int LZ4_compressHC2_continue (void* LZ4HC_Data, const char* source, char* dest, int inputSize, int compressionLevel);
LZ4_DEPRECATED("use LZ4_compress_HC_continue() instead") int LZ4_compressHC2_limitedOutput_continue (void* LZ4HC_Data, const char* source, char* dest, int inputSize, int maxOutputSize, int compressionLevel);
LZ4_DEPRECATED("use LZ4_createStreamHC() instead") int LZ4_sizeofStreamStateHC(void);
LZ4_DEPRECATED("use LZ4_resetStreamHC() instead") int LZ4_resetStreamStateHC(void* state, char* inputBuffer);
#if defined (__cplusplus)
}
#endif
|
262e04d2508ac0ff1f860427d3b365cf5dd8af01
|
642ba1746fed0b722a127b8426eca987df6efc61
|
/src/sundials/shared/smalldense.c
|
407945aa4ee18eeb87ee4bf5196677b7d1678aec
|
[
"BSD-3-Clause"
] |
permissive
|
neuronsimulator/nrn
|
23781d978fe9253b0e3543f41e27252532b35459
|
b786c36d715ba0f6da1ba8bdf5d2338c939ecf51
|
refs/heads/master
| 2023-08-09T00:13:11.123525
| 2023-08-04T13:11:02
| 2023-08-04T13:11:02
| 71,627,569
| 313
| 171
|
NOASSERTION
| 2023-09-14T17:48:03
| 2016-10-22T08:47:37
|
C++
|
UTF-8
|
C
| false
| false
| 5,082
|
c
|
smalldense.c
|
/*
* -----------------------------------------------------------------
* $Revision: 855 $
* $Date: 2005-02-10 00:15:46 +0100 (Thu, 10 Feb 2005) $
* -----------------------------------------------------------------
* Programmer(s): Scott D. Cohen and Alan C. Hindmarsh @ LLNL
* -----------------------------------------------------------------
* Copyright (c) 2002, The Regents of the University of California.
* Produced at the Lawrence Livermore National Laboratory.
* All rights reserved.
* For details, see sundials/shared/LICENSE.
* -----------------------------------------------------------------
* This is the implementation file for a generic DENSE linear
* solver package, intended for small dense matrices.
* -----------------------------------------------------------------
*/
#include <stdio.h>
#include <stdlib.h>
#include "smalldense.h"
#include "sundialsmath.h"
#include "sundialstypes.h"
#define ZERO RCONST(0.0)
#define ONE RCONST(1.0)
/* Implementation */
realtype **denalloc(long int n)
{
long int j;
realtype **a;
if (n <= 0) return(NULL);
a = (realtype **) malloc(n * sizeof(realtype *));
if (a == NULL) return(NULL);
a[0] = (realtype *) malloc(n * n * sizeof(realtype));
if (a[0] == NULL) {
free(a);
return(NULL);
}
for (j=1; j < n; j++) a[j] = a[0] + j * n;
return(a);
}
long int *denallocpiv(long int n)
{
if (n <= 0) return(NULL);
return((long int *) malloc(n * sizeof(long int)));
}
long int gefa(realtype **a, long int n, long int *p)
{
long int i, j, k, l;
realtype *col_j, *col_k, *diag_k;
realtype temp, mult, a_kj;
booleantype swap;
/* k = elimination step number */
for (k=0; k < n-1; k++, p++) {
col_k = a[k];
diag_k = col_k + k;
/* find l = pivot row number */
l=k;
for (i=k+1; i < n; i++)
if (ABS(col_k[i]) > ABS(col_k[l])) l=i;
*p = l;
/* check for zero pivot element */
if (col_k[l] == ZERO) return(k+1);
/* swap a(l,k) and a(k,k) if necessary */
if ( (swap = (l != k) )) {
temp = col_k[l];
col_k[l] = *diag_k;
*diag_k = temp;
}
/* Scale the elements below the diagonal in */
/* column k by -1.0 / a(k,k). After the above swap, */
/* a(k,k) holds the pivot element. This scaling */
/* stores the pivot row multipliers -a(i,k)/a(k,k) */
/* in a(i,k), i=k+1, ..., n-1. */
mult = -ONE / (*diag_k);
for(i=k+1; i < n; i++)
col_k[i] *= mult;
/* row_i = row_i - [a(i,k)/a(k,k)] row_k, i=k+1, ..., n-1 */
/* row k is the pivot row after swapping with row l. */
/* The computation is done one column at a time, */
/* column j=k+1, ..., n-1. */
for (j=k+1; j < n; j++) {
col_j = a[j];
a_kj = col_j[l];
/* Swap the elements a(k,j) and a(k,l) if l!=k. */
if (swap) {
col_j[l] = col_j[k];
col_j[k] = a_kj;
}
/* a(i,j) = a(i,j) - [a(i,k)/a(k,k)]*a(k,j) */
/* a_kj = a(k,j), col_k[i] = - a(i,k)/a(k,k) */
if (a_kj != ZERO) {
for (i=k+1; i < n; i++)
col_j[i] += a_kj * col_k[i];
}
}
}
/* set the last pivot row to be n-1 and check for a zero pivot */
*p = n-1;
if (a[n-1][n-1] == ZERO) return(n);
/* return 0 to indicate success */
return(0);
}
void gesl(realtype **a, long int n, long int *p, realtype *b)
{
long int k, l, i;
realtype mult, *col_k;
/* Solve Ly = Pb, store solution y in b */
for (k=0; k < n-1; k++) {
l = p[k];
mult = b[l];
if (l != k) {
b[l] = b[k];
b[k] = mult;
}
col_k = a[k];
for (i=k+1; i < n; i++)
b[i] += mult*col_k[i];
}
/* Solve Ux = y, store solution x in b */
for (k=n-1; k >= 0; k--) {
col_k = a[k];
b[k] /= col_k[k];
mult = -b[k];
for (i=0; i < k; i++)
b[i] += mult*col_k[i];
}
}
void denzero(realtype **a, long int n)
{
long int i, j;
realtype *col_j;
for (j=0; j < n; j++) {
col_j = a[j];
for (i=0; i < n; i++)
col_j[i] = ZERO;
}
}
void dencopy(realtype **a, realtype **b, long int n)
{
long int i, j;
realtype *a_col_j, *b_col_j;
for (j=0; j < n; j++) {
a_col_j = a[j];
b_col_j = b[j];
for (i=0; i < n; i++)
b_col_j[i] = a_col_j[i];
}
}
void denscale(realtype c, realtype **a, long int n)
{
long int i, j;
realtype *col_j;
for (j=0; j < n; j++) {
col_j = a[j];
for (i=0; i < n; i++)
col_j[i] *= c;
}
}
void denaddI(realtype **a, long int n)
{
long int i;
for (i=0; i < n; i++) a[i][i] += ONE;
}
void denfreepiv(long int *p)
{
free(p);
}
void denfree(realtype **a)
{
free(a[0]);
free(a);
}
void denprint(realtype **a, long int n)
{
long int i, j;
printf("\n");
for (i=0; i < n; i++) {
for (j=0; j < n; j++) {
#if defined(SUNDIALS_EXTENDED_PRECISION)
printf("%10Lg", a[j][i]);
#elif defined(SUNDIALS_DOUBLE_PRECISION)
printf("%10lg", a[j][i]);
#else
printf("%10g", a[j][i]);
#endif
}
printf("\n");
}
printf("\n");
}
|
85a26a00a72ee9a6d00e1c897954cd1b4510181f
|
99bdb3251fecee538e0630f15f6574054dfc1468
|
/bsp/gd32vf103v-eval/libraries/GD32VF103_standard_peripheral/Source/gd32vf103_adc.c
|
8a48676bc4ce117080d7d3107869110c098f570a
|
[
"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
| 39,280
|
c
|
gd32vf103_adc.c
|
/*!
\file gd32vf103_adc.c
\brief ADC driver
\version 2019-6-5, V1.0.0, firmware for GD32VF103
*/
/*
Copyright (c) 2019, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#include "gd32vf103_adc.h"
/* discontinuous mode macro*/
#define ADC_CHANNEL_LENGTH_SUBTRACT_ONE ((uint8_t)1U)
/* ADC regular channel macro */
#define ADC_REGULAR_CHANNEL_RANK_SIX ((uint8_t)6U)
#define ADC_REGULAR_CHANNEL_RANK_TWELVE ((uint8_t)12U)
#define ADC_REGULAR_CHANNEL_RANK_SIXTEEN ((uint8_t)16U)
#define ADC_REGULAR_CHANNEL_RANK_LENGTH ((uint8_t)5U)
/* ADC sampling time macro */
#define ADC_CHANNEL_SAMPLE_TEN ((uint8_t)10U)
#define ADC_CHANNEL_SAMPLE_EIGHTEEN ((uint8_t)18U)
#define ADC_CHANNEL_SAMPLE_LENGTH ((uint8_t)3U)
/* ADC inserted channel macro */
#define ADC_INSERTED_CHANNEL_RANK_LENGTH ((uint8_t)5U)
#define ADC_INSERTED_CHANNEL_SHIFT_LENGTH ((uint8_t)15U)
/* ADC inserted channel offset macro */
#define ADC_OFFSET_LENGTH ((uint8_t)3U)
#define ADC_OFFSET_SHIFT_LENGTH ((uint8_t)4U)
/*!
\brief reset ADC
\param[in] adc_periph: ADCx, x=0,1
\param[out] none
\retval none
*/
void adc_deinit(uint32_t adc_periph)
{
switch(adc_periph){
case ADC0:
/* reset ADC0 */
rcu_periph_reset_enable(RCU_ADC0RST);
rcu_periph_reset_disable(RCU_ADC0RST);
break;
case ADC1:
/* reset ADC1 */
rcu_periph_reset_enable(RCU_ADC1RST);
rcu_periph_reset_disable(RCU_ADC1RST);
break;
default:
break;
}
}
/*!
\brief configure the ADC sync mode
\param[in] mode: ADC mode
only one parameter can be selected which is shown as below:
\arg ADC_MODE_FREE: all the ADCs work independently
\arg ADC_DAUL_REGULAL_PARALLEL_INSERTED_PARALLEL: ADC0 and ADC1 work in combined regular parallel + inserted parallel mode
\arg ADC_DAUL_REGULAL_PARALLEL_INSERTED_ROTATION: ADC0 and ADC1 work in combined regular parallel + trigger rotation mode
\arg ADC_DAUL_INSERTED_PARALLEL_REGULAL_FOLLOWUP_FAST: ADC0 and ADC1 work in combined inserted parallel + follow-up fast mode
\arg ADC_DAUL_INSERTED_PARALLEL_REGULAL_FOLLOWUP_SLOW: ADC0 and ADC1 work in combined inserted parallel + follow-up slow mode
\arg ADC_DAUL_INSERTED_PARALLEL: ADC0 and ADC1 work in inserted parallel mode only
\arg ADC_DAUL_REGULAL_PARALLEL: ADC0 and ADC1 work in regular parallel mode only
\arg ADC_DAUL_REGULAL_FOLLOWUP_FAST: ADC0 and ADC1 work in follow-up fast mode only
\arg ADC_DAUL_REGULAL_FOLLOWUP_SLOW: ADC0 and ADC1 work in follow-up slow mode only
\arg ADC_DAUL_INSERTED_TRIGGER_ROTATION: ADC0 and ADC1 work in trigger rotation mode only
\param[out] none
\retval none
*/
void adc_mode_config(uint32_t mode)
{
ADC_CTL0(ADC0) &= ~(ADC_CTL0_SYNCM);
ADC_CTL0(ADC0) |= mode;
}
/*!
\brief enable or disable ADC special function
\param[in] adc_periph: ADCx, x=0,1
\param[in] function: the function to config
only one parameter can be selected which is shown as below:
\arg ADC_SCAN_MODE: scan mode select
\arg ADC_INSERTED_CHANNEL_AUTO: inserted channel group convert automatically
\arg ADC_CONTINUOUS_MODE: continuous mode select
\param[in] newvalue: ENABLE or DISABLE
\param[out] none
\retval none
*/
void adc_special_function_config(uint32_t adc_periph, uint32_t function, ControlStatus newvalue)
{
if(newvalue){
if(0U != (function & ADC_SCAN_MODE)){
/* enable scan mode */
ADC_CTL0(adc_periph) |= ADC_SCAN_MODE;
}
if(0U != (function & ADC_INSERTED_CHANNEL_AUTO)){
/* enable inserted channel group convert automatically */
ADC_CTL0(adc_periph) |= ADC_INSERTED_CHANNEL_AUTO;
}
if(0U != (function & ADC_CONTINUOUS_MODE)){
/* enable continuous mode */
ADC_CTL1(adc_periph) |= ADC_CONTINUOUS_MODE;
}
}else{
if(0U != (function & ADC_SCAN_MODE)){
/* disable scan mode */
ADC_CTL0(adc_periph) &= ~ADC_SCAN_MODE;
}
if(0U != (function & ADC_INSERTED_CHANNEL_AUTO)){
/* disable inserted channel group convert automatically */
ADC_CTL0(adc_periph) &= ~ADC_INSERTED_CHANNEL_AUTO;
}
if(0U != (function & ADC_CONTINUOUS_MODE)){
/* disable continuous mode */
ADC_CTL1(adc_periph) &= ~ADC_CONTINUOUS_MODE;
}
}
}
/*!
\brief configure ADC data alignment
\param[in] adc_periph: ADCx, x=0,1
\param[in] data_alignment: data alignment select
only one parameter can be selected which is shown as below:
\arg ADC_DATAALIGN_RIGHT: LSB alignment
\arg ADC_DATAALIGN_LEFT: MSB alignment
\param[out] none
\retval none
*/
void adc_data_alignment_config(uint32_t adc_periph, uint32_t data_alignment)
{
if(ADC_DATAALIGN_RIGHT != data_alignment){
/* MSB alignment */
ADC_CTL1(adc_periph) |= ADC_CTL1_DAL;
}else{
/* LSB alignment */
ADC_CTL1(adc_periph) &= ~((uint32_t)ADC_CTL1_DAL);
}
}
/*!
\brief enable ADC interface
\param[in] adc_periph: ADCx, x=0,1
\param[out] none
\retval none
*/
void adc_enable(uint32_t adc_periph)
{
if(RESET == (ADC_CTL1(adc_periph) & ADC_CTL1_ADCON)){
/* enable ADC */
ADC_CTL1(adc_periph) |= (uint32_t)ADC_CTL1_ADCON;
}
}
/*!
\brief disable ADC interface
\param[in] adc_periph: ADCx, x=0,1
\param[out] none
\retval none
*/
void adc_disable(uint32_t adc_periph)
{
/* disable ADC */
ADC_CTL1(adc_periph) &= ~((uint32_t)ADC_CTL1_ADCON);
}
/*!
\brief ADC calibration and reset calibration
\param[in] adc_periph: ADCx, x=0,1
\param[out] none
\retval none
*/
void adc_calibration_enable(uint32_t adc_periph)
{
/* reset the selected ADC1 calibration registers */
ADC_CTL1(adc_periph) |= (uint32_t) ADC_CTL1_RSTCLB;
/* check the RSTCLB bit state */
while(RESET != (ADC_CTL1(adc_periph) & ADC_CTL1_RSTCLB)){
}
/* enable ADC calibration process */
ADC_CTL1(adc_periph) |= ADC_CTL1_CLB;
/* check the CLB bit state */
while(RESET != (ADC_CTL1(adc_periph) & ADC_CTL1_CLB)){
}
}
/*!
\brief enable the temperature sensor and Vrefint channel
\param[in] none
\param[out] none
\retval none
*/
void adc_tempsensor_vrefint_enable(void)
{
/* enable the temperature sensor and Vrefint channel */
ADC_CTL1(ADC0) |= ADC_CTL1_TSVREN;
}
/*!
\brief disable the temperature sensor and Vrefint channel
\param[in] none
\param[out] none
\retval none
*/
void adc_tempsensor_vrefint_disable(void)
{
/* disable the temperature sensor and Vrefint channel */
ADC_CTL1(ADC0) &= ~ADC_CTL1_TSVREN;
}
/*!
\brief enable DMA request
\param[in] adc_periph: ADCx, x=0,1
\param[out] none
\retval none
*/
void adc_dma_mode_enable(uint32_t adc_periph)
{
/* enable DMA request */
ADC_CTL1(adc_periph) |= (uint32_t)(ADC_CTL1_DMA);
}
/*!
\brief disable DMA request
\param[in] adc_periph: ADCx, x=0,1
\param[out] none
\retval none
*/
void adc_dma_mode_disable(uint32_t adc_periph)
{
/* disable DMA request */
ADC_CTL1(adc_periph) &= ~((uint32_t)ADC_CTL1_DMA);
}
/*!
\brief configure ADC discontinuous mode
\param[in] adc_periph: ADCx, x=0,1
\param[in] adc_channel_group: select the channel group
only one parameter can be selected which is shown as below:
\arg ADC_REGULAR_CHANNEL: regular channel group
\arg ADC_INSERTED_CHANNEL: inserted channel group
\arg ADC_CHANNEL_DISCON_DISABLE: disable discontinuous mode of regular & inserted channel
\param[in] length: number of conversions in discontinuous mode,the number can be 1..8
for regular channel, the number has no effect for inserted channel
\param[out] none
\retval none
*/
void adc_discontinuous_mode_config(uint32_t adc_periph, uint8_t adc_channel_group, uint8_t length)
{
/* disable discontinuous mode of regular & inserted channel */
ADC_CTL0(adc_periph) &= ~((uint32_t)(ADC_CTL0_DISRC | ADC_CTL0_DISIC));
switch(adc_channel_group){
case ADC_REGULAR_CHANNEL:
/* config the number of conversions in discontinuous mode */
ADC_CTL0(adc_periph) &= ~((uint32_t)ADC_CTL0_DISNUM);
ADC_CTL0(adc_periph) |= CTL0_DISNUM(((uint32_t)length - ADC_CHANNEL_LENGTH_SUBTRACT_ONE));
/* enable regular channel group discontinuous mode */
ADC_CTL0(adc_periph) |= (uint32_t)ADC_CTL0_DISRC;
break;
case ADC_INSERTED_CHANNEL:
/* enable inserted channel group discontinuous mode */
ADC_CTL0(adc_periph) |= (uint32_t)ADC_CTL0_DISIC;
break;
case ADC_CHANNEL_DISCON_DISABLE:
/* disable discontinuous mode of regular & inserted channel */
default:
break;
}
}
/*!
\brief configure the length of regular channel group or inserted channel group
\param[in] adc_periph: ADCx, x=0,1
\param[in] adc_channel_group: select the channel group
only one parameter can be selected which is shown as below:
\arg ADC_REGULAR_CHANNEL: regular channel group
\arg ADC_INSERTED_CHANNEL: inserted channel group
\param[in] length: the length of the channel
regular channel 1-16
inserted channel 1-4
\param[out] none
\retval none
*/
void adc_channel_length_config(uint32_t adc_periph, uint8_t adc_channel_group, uint32_t length)
{
switch(adc_channel_group){
case ADC_REGULAR_CHANNEL:
/* configure the length of regular channel group */
ADC_RSQ0(adc_periph) &= ~((uint32_t)ADC_RSQ0_RL);
ADC_RSQ0(adc_periph) |= RSQ0_RL((uint32_t)(length-ADC_CHANNEL_LENGTH_SUBTRACT_ONE));
break;
case ADC_INSERTED_CHANNEL:
/* configure the length of inserted channel group */
ADC_ISQ(adc_periph) &= ~((uint32_t)ADC_ISQ_IL);
ADC_ISQ(adc_periph) |= ISQ_IL((uint32_t)(length-ADC_CHANNEL_LENGTH_SUBTRACT_ONE));
break;
default:
break;
}
}
/*!
\brief configure ADC regular channel
\param[in] adc_periph: ADCx, x=0,1
\param[in] rank: the regular group sequence rank,this parameter must be between 0 to 15
\param[in] adc_channel: the selected ADC channel
only one parameter can be selected which is shown as below:
\arg ADC_CHANNEL_x(x=0..17)(x=16 and x=17 are only for ADC0): ADC Channelx
\param[in] sample_time: the sample time value
only one parameter can be selected which is shown as below:
\arg ADC_SAMPLETIME_1POINT5: 1.5 cycles
\arg ADC_SAMPLETIME_7POINT5: 7.5 cycles
\arg ADC_SAMPLETIME_13POINT5: 13.5 cycles
\arg ADC_SAMPLETIME_28POINT5: 28.5 cycles
\arg ADC_SAMPLETIME_41POINT5: 41.5 cycles
\arg ADC_SAMPLETIME_55POINT5: 55.5 cycles
\arg ADC_SAMPLETIME_71POINT5: 71.5 cycles
\arg ADC_SAMPLETIME_239POINT5: 239.5 cycles
\param[out] none
\retval none
*/
void adc_regular_channel_config(uint32_t adc_periph, uint8_t rank, uint8_t adc_channel, uint32_t sample_time)
{
uint32_t rsq,sampt;
/* ADC regular sequence config */
if(rank < ADC_REGULAR_CHANNEL_RANK_SIX){
/* the regular group sequence rank is smaller than six */
rsq = ADC_RSQ2(adc_periph);
rsq &= ~((uint32_t)(ADC_RSQX_RSQN << (ADC_REGULAR_CHANNEL_RANK_LENGTH*rank)));
/* the channel number is written to these bits to select a channel as the nth conversion in the regular channel group */
rsq |= ((uint32_t)adc_channel << (ADC_REGULAR_CHANNEL_RANK_LENGTH*rank));
ADC_RSQ2(adc_periph) = rsq;
}else if(rank < ADC_REGULAR_CHANNEL_RANK_TWELVE){
/* the regular group sequence rank is smaller than twelve */
rsq = ADC_RSQ1(adc_periph);
rsq &= ~((uint32_t)(ADC_RSQX_RSQN << (ADC_REGULAR_CHANNEL_RANK_LENGTH*(rank-ADC_REGULAR_CHANNEL_RANK_SIX))));
/* the channel number is written to these bits to select a channel as the nth conversion in the regular channel group */
rsq |= ((uint32_t)adc_channel << (ADC_REGULAR_CHANNEL_RANK_LENGTH*(rank-ADC_REGULAR_CHANNEL_RANK_SIX)));
ADC_RSQ1(adc_periph) = rsq;
}else if(rank < ADC_REGULAR_CHANNEL_RANK_SIXTEEN){
/* the regular group sequence rank is smaller than sixteen */
rsq = ADC_RSQ0(adc_periph);
rsq &= ~((uint32_t)(ADC_RSQX_RSQN << (ADC_REGULAR_CHANNEL_RANK_LENGTH*(rank-ADC_REGULAR_CHANNEL_RANK_TWELVE))));
/* the channel number is written to these bits to select a channel as the nth conversion in the regular channel group */
rsq |= ((uint32_t)adc_channel << (ADC_REGULAR_CHANNEL_RANK_LENGTH*(rank-ADC_REGULAR_CHANNEL_RANK_TWELVE)));
ADC_RSQ0(adc_periph) = rsq;
}else{
}
/* ADC sampling time config */
if(adc_channel < ADC_CHANNEL_SAMPLE_TEN){
/* the regular group sequence rank is smaller than ten */
sampt = ADC_SAMPT1(adc_periph);
sampt &= ~((uint32_t)(ADC_SAMPTX_SPTN << (ADC_CHANNEL_SAMPLE_LENGTH*adc_channel)));
/* channel sample time set*/
sampt |= (uint32_t)(sample_time << (ADC_CHANNEL_SAMPLE_LENGTH*adc_channel));
ADC_SAMPT1(adc_periph) = sampt;
}else if(adc_channel < ADC_CHANNEL_SAMPLE_EIGHTEEN){
/* the regular group sequence rank is smaller than eighteen */
sampt = ADC_SAMPT0(adc_periph);
sampt &= ~((uint32_t)(ADC_SAMPTX_SPTN << (ADC_CHANNEL_SAMPLE_LENGTH*(adc_channel-ADC_CHANNEL_SAMPLE_TEN))));
/* channel sample time set*/
sampt |= (uint32_t)(sample_time << (ADC_CHANNEL_SAMPLE_LENGTH*(adc_channel-ADC_CHANNEL_SAMPLE_TEN)));
ADC_SAMPT0(adc_periph) = sampt;
}else{
}
}
/*!
\brief configure ADC inserted channel
\param[in] adc_periph: ADCx, x=0,1
\param[in] rank: the inserted group sequencer rank,this parameter must be between 0 to 3
\param[in] adc_channel: the selected ADC channel
only one parameter can be selected which is shown as below:
\arg ADC_CHANNEL_x(x=0..17)(x=16 and x=17 are only for ADC0): ADC Channelx
\param[in] sample_time: The sample time value
only one parameter can be selected which is shown as below:
\arg ADC_SAMPLETIME_1POINT5: 1.5 cycles
\arg ADC_SAMPLETIME_7POINT5: 7.5 cycles
\arg ADC_SAMPLETIME_13POINT5: 13.5 cycles
\arg ADC_SAMPLETIME_28POINT5: 28.5 cycles
\arg ADC_SAMPLETIME_41POINT5: 41.5 cycles
\arg ADC_SAMPLETIME_55POINT5: 55.5 cycles
\arg ADC_SAMPLETIME_71POINT5: 71.5 cycles
\arg ADC_SAMPLETIME_239POINT5: 239.5 cycles
\param[out] none
\retval none
*/
void adc_inserted_channel_config(uint32_t adc_periph, uint8_t rank, uint8_t adc_channel, uint32_t sample_time)
{
uint8_t inserted_length;
uint32_t isq,sampt;
/* get inserted channel group length */
inserted_length = (uint8_t)GET_BITS(ADC_ISQ(adc_periph) , 20U , 21U);
/* the channel number is written to these bits to select a channel as the nth conversion in the inserted channel group */
isq = ADC_ISQ(adc_periph);
isq &= ~((uint32_t)(ADC_ISQ_ISQN << (ADC_INSERTED_CHANNEL_SHIFT_LENGTH-(inserted_length-rank)*ADC_INSERTED_CHANNEL_RANK_LENGTH)));
isq |= ((uint32_t)adc_channel << (ADC_INSERTED_CHANNEL_SHIFT_LENGTH-(inserted_length-rank)*ADC_INSERTED_CHANNEL_RANK_LENGTH));
ADC_ISQ(adc_periph) = isq;
/* ADC sampling time config */
if(adc_channel < ADC_CHANNEL_SAMPLE_TEN){
/* the inserted group sequence rank is smaller than ten */
sampt = ADC_SAMPT1(adc_periph);
sampt &= ~((uint32_t)(ADC_SAMPTX_SPTN << (ADC_CHANNEL_SAMPLE_LENGTH*adc_channel)));
/* channel sample time set*/
sampt |= (uint32_t) sample_time << (ADC_CHANNEL_SAMPLE_LENGTH*adc_channel);
ADC_SAMPT1(adc_periph) = sampt;
}else if(adc_channel < ADC_CHANNEL_SAMPLE_EIGHTEEN){
/* the inserted group sequence rank is smaller than eighteen */
sampt = ADC_SAMPT0(adc_periph);
sampt &= ~((uint32_t)(ADC_SAMPTX_SPTN << (ADC_CHANNEL_SAMPLE_LENGTH*(adc_channel-ADC_CHANNEL_SAMPLE_TEN))));
/* channel sample time set*/
sampt |= ((uint32_t)sample_time << (ADC_CHANNEL_SAMPLE_LENGTH*(adc_channel-ADC_CHANNEL_SAMPLE_TEN)));
ADC_SAMPT0(adc_periph) = sampt;
}else{
}
}
/*!
\brief configure ADC inserted channel offset
\param[in] adc_periph: ADCx, x=0,1
\param[in] inserted_channel: insert channel select
only one parameter can be selected
\arg ADC_INSERTED_CHANNEL_0: inserted channel0
\arg ADC_INSERTED_CHANNEL_1: inserted channel1
\arg ADC_INSERTED_CHANNEL_2: inserted channel2
\arg ADC_INSERTED_CHANNEL_3: inserted channel3
\param[in] offset: the offset data
\param[out] none
\retval none
*/
void adc_inserted_channel_offset_config(uint32_t adc_periph, uint8_t inserted_channel, uint16_t offset)
{
uint8_t inserted_length;
uint32_t num = 0U;
inserted_length = (uint8_t)GET_BITS(ADC_ISQ(adc_periph) , 20U , 21U);
num = ((uint32_t)ADC_OFFSET_LENGTH - ((uint32_t)inserted_length - (uint32_t)inserted_channel));
if(num <= ADC_OFFSET_LENGTH){
/* calculate the offset of the register */
num = num * ADC_OFFSET_SHIFT_LENGTH;
/* config the offset of the selected channels */
REG32((adc_periph) + 0x14U + num) = IOFFX_IOFF((uint32_t)offset);
}
}
/*!
\brief configure ADC external trigger source
\param[in] adc_periph: ADCx, x=0,1
\param[in] adc_channel_group: select the channel group
only one parameter can be selected which is shown as below:
\arg ADC_REGULAR_CHANNEL: regular channel group
\arg ADC_INSERTED_CHANNEL: inserted channel group
\param[in] external_trigger_source: regular or inserted group trigger source
only one parameter can be selected
for regular channel:
\arg ADC0_1_EXTTRIG_REGULAR_T0_CH0: TIMER0 CH0 event select
\arg ADC0_1_EXTTRIG_REGULAR_T0_CH1: TIMER0 CH1 event select
\arg ADC0_1_EXTTRIG_REGULAR_T0_CH2: TIMER0 CH2 event select
\arg ADC0_1_EXTTRIG_REGULAR_T1_CH1: TIMER1 CH1 event select
\arg ADC0_1_EXTTRIG_REGULAR_T2_TRGO: TIMER2 TRGO event select
\arg ADC0_1_EXTTRIG_REGULAR_T3_CH3: TIMER3 CH3 event select
\arg ADC0_1_EXTTRIG_REGULAR_EXTI_11: external interrupt line 11
\arg ADC0_1_EXTTRIG_REGULAR_NONE: software trigger
for inserted channel:
\arg ADC0_1_EXTTRIG_INSERTED_T0_TRGO: TIMER0 TRGO event select
\arg ADC0_1_EXTTRIG_INSERTED_T0_CH3: TIMER0 CH3 event select
\arg ADC0_1_EXTTRIG_INSERTED_T1_TRGO: TIMER1 TRGO event select
\arg ADC0_1_EXTTRIG_INSERTED_T1_CH0: TIMER1 CH0 event select
\arg ADC0_1_EXTTRIG_INSERTED_T2_CH3: TIMER2 CH3 event select
\arg ADC0_1_EXTTRIG_INSERTED_T3_TRGO: TIMER3 TRGO event select
\arg ADC0_1_EXTTRIG_INSERTED_EXTI_15: external interrupt line 15
\arg ADC0_1_EXTTRIG_INSERTED_NONE: software trigger
\param[out] none
\retval none
*/
void adc_external_trigger_source_config(uint32_t adc_periph, uint8_t adc_channel_group, uint32_t external_trigger_source)
{
switch(adc_channel_group){
case ADC_REGULAR_CHANNEL:
/* configure ADC regular group external trigger source */
ADC_CTL1(adc_periph) &= ~((uint32_t)ADC_CTL1_ETSRC);
ADC_CTL1(adc_periph) |= (uint32_t)external_trigger_source;
break;
case ADC_INSERTED_CHANNEL:
/* configure ADC inserted group external trigger source */
ADC_CTL1(adc_periph) &= ~((uint32_t)ADC_CTL1_ETSIC);
ADC_CTL1(adc_periph) |= (uint32_t)external_trigger_source;
break;
default:
break;
}
}
/*!
\brief configure ADC external trigger
\param[in] adc_periph: ADCx, x=0,1
\param[in] adc_channel_group: select the channel group
one or more parameters can be selected which are shown as below:
\arg ADC_REGULAR_CHANNEL: regular channel group
\arg ADC_INSERTED_CHANNEL: inserted channel group
\param[in] newvalue: ENABLE or DISABLE
\param[out] none
\retval none
*/
void adc_external_trigger_config(uint32_t adc_periph, uint8_t adc_channel_group, ControlStatus newvalue)
{
if(newvalue){
if(0U != (adc_channel_group & ADC_REGULAR_CHANNEL)){
/* enable ADC regular channel group external trigger */
ADC_CTL1(adc_periph) |= ADC_CTL1_ETERC;
}
if(0U != (adc_channel_group & ADC_INSERTED_CHANNEL)){
/* enable ADC inserted channel group external trigger */
ADC_CTL1(adc_periph) |= ADC_CTL1_ETEIC;
}
}else{
if(0U != (adc_channel_group & ADC_REGULAR_CHANNEL)){
/* disable ADC regular channel group external trigger */
ADC_CTL1(adc_periph) &= ~ADC_CTL1_ETERC;
}
if(0U != (adc_channel_group & ADC_INSERTED_CHANNEL)){
/* disable ADC regular channel group external trigger */
ADC_CTL1(adc_periph) &= ~ADC_CTL1_ETEIC;
}
}
}
/*!
\brief enable ADC software trigger
\param[in] adc_periph: ADCx, x=0,1
\param[in] adc_channel_group: select the channel group
one or more parameters can be selected which are shown as below:
\arg ADC_REGULAR_CHANNEL: regular channel group
\arg ADC_INSERTED_CHANNEL: inserted channel group
\param[out] none
\retval none
*/
void adc_software_trigger_enable(uint32_t adc_periph, uint8_t adc_channel_group)
{
if(0U != (adc_channel_group & ADC_REGULAR_CHANNEL)){
/* enable ADC regular channel group software trigger */
ADC_CTL1(adc_periph) |= ADC_CTL1_SWRCST;
}
if(0U != (adc_channel_group & ADC_INSERTED_CHANNEL)){
/* enable ADC inserted channel group software trigger */
ADC_CTL1(adc_periph) |= ADC_CTL1_SWICST;
}
}
/*!
\brief read ADC regular group data register
\param[in] adc_periph: ADCx, x=0,1
\param[in] none
\param[out] none
\retval the conversion value
*/
uint16_t adc_regular_data_read(uint32_t adc_periph)
{
return (uint16_t)(ADC_RDATA(adc_periph));
}
/*!
\brief read ADC inserted group data register
\param[in] adc_periph: ADCx, x=0,1
\param[in] inserted_channel: insert channel select
only one parameter can be selected
\arg ADC_INSERTED_CHANNEL_0: inserted Channel0
\arg ADC_INSERTED_CHANNEL_1: inserted channel1
\arg ADC_INSERTED_CHANNEL_2: inserted Channel2
\arg ADC_INSERTED_CHANNEL_3: inserted Channel3
\param[out] none
\retval the conversion value
*/
uint16_t adc_inserted_data_read(uint32_t adc_periph, uint8_t inserted_channel)
{
uint32_t idata;
/* read the data of the selected channel */
switch(inserted_channel){
case ADC_INSERTED_CHANNEL_0:
/* read the data of channel 0 */
idata = ADC_IDATA0(adc_periph);
break;
case ADC_INSERTED_CHANNEL_1:
/* read the data of channel 1 */
idata = ADC_IDATA1(adc_periph);
break;
case ADC_INSERTED_CHANNEL_2:
/* read the data of channel 2 */
idata = ADC_IDATA2(adc_periph);
break;
case ADC_INSERTED_CHANNEL_3:
/* read the data of channel 3 */
idata = ADC_IDATA3(adc_periph);
break;
default:
idata = 0U;
break;
}
return (uint16_t)idata;
}
/*!
\brief read the last ADC0 and ADC1 conversion result data in sync mode
\param[in] none
\param[out] none
\retval the conversion value
*/
uint32_t adc_sync_mode_convert_value_read(void)
{
/* return conversion value */
return ADC_RDATA(ADC0);
}
/*!
\brief configure ADC analog watchdog single channel
\param[in] adc_periph: ADCx, x=0,1
\param[in] adc_channel: the selected ADC channel
only one parameter can be selected which is shown as below:
\arg ADC_CHANNEL_x: ADC Channelx(x=0..17)(x=16 and x=17 are only for ADC0)
\param[out] none
\retval none
*/
void adc_watchdog_single_channel_enable(uint32_t adc_periph, uint8_t adc_channel)
{
ADC_CTL0(adc_periph) &= (uint32_t)~(ADC_CTL0_RWDEN | ADC_CTL0_IWDEN | ADC_CTL0_WDSC | ADC_CTL0_WDCHSEL);
/* analog watchdog channel select */
ADC_CTL0(adc_periph) |= (uint32_t)adc_channel;
ADC_CTL0(adc_periph) |= (uint32_t)(ADC_CTL0_RWDEN | ADC_CTL0_IWDEN | ADC_CTL0_WDSC);
}
/*!
\brief configure ADC analog watchdog group channel
\param[in] adc_periph: ADCx, x=0,1
\param[in] adc_channel_group: the channel group use analog watchdog
only one parameter can be selected which is shown as below:
\arg ADC_REGULAR_CHANNEL: regular channel group
\arg ADC_INSERTED_CHANNEL: inserted channel group
\arg ADC_REGULAR_INSERTED_CHANNEL: both regular and inserted group
\param[out] none
\retval none
*/
void adc_watchdog_group_channel_enable(uint32_t adc_periph, uint8_t adc_channel_group)
{
ADC_CTL0(adc_periph) &= (uint32_t)~(ADC_CTL0_RWDEN | ADC_CTL0_IWDEN | ADC_CTL0_WDSC);
/* select the group */
switch(adc_channel_group){
case ADC_REGULAR_CHANNEL:
/* regular channel analog watchdog enable */
ADC_CTL0(adc_periph) |= (uint32_t) ADC_CTL0_RWDEN;
break;
case ADC_INSERTED_CHANNEL:
/* inserted channel analog watchdog enable */
ADC_CTL0(adc_periph) |= (uint32_t) ADC_CTL0_IWDEN;
break;
case ADC_REGULAR_INSERTED_CHANNEL:
/* regular and inserted channel analog watchdog enable */
ADC_CTL0(adc_periph) |= (uint32_t)(ADC_CTL0_RWDEN | ADC_CTL0_IWDEN);
break;
default:
break;
}
}
/*!
\brief disable ADC analog watchdog
\param[in] adc_periph: ADCx, x=0,1
\param[out] none
\retval none
*/
void adc_watchdog_disable(uint32_t adc_periph)
{
ADC_CTL0(adc_periph) &= (uint32_t)~(ADC_CTL0_RWDEN | ADC_CTL0_IWDEN | ADC_CTL0_WDSC | ADC_CTL0_WDCHSEL);
}
/*!
\brief configure ADC analog watchdog threshold
\param[in] adc_periph: ADCx, x=0,1
\param[in] low_threshold: analog watchdog low threshold, 0..4095
\param[in] high_threshold: analog watchdog high threshold, 0..4095
\param[out] none
\retval none
*/
void adc_watchdog_threshold_config(uint32_t adc_periph, uint16_t low_threshold, uint16_t high_threshold)
{
ADC_WDLT(adc_periph) = (uint32_t)WDLT_WDLT(low_threshold);
ADC_WDHT(adc_periph) = (uint32_t)WDHT_WDHT(high_threshold);
}
/*!
\brief get the ADC flag bits
\param[in] adc_periph: ADCx, x=0,1
\param[in] adc_flag: the adc flag bits
only one parameter can be selected which is shown as below:
\arg ADC_FLAG_WDE: analog watchdog event flag
\arg ADC_FLAG_EOC: end of group conversion flag
\arg ADC_FLAG_EOIC: end of inserted group conversion flag
\arg ADC_FLAG_STIC: start flag of inserted channel group
\arg ADC_FLAG_STRC: start flag of regular channel group
\param[out] none
\retval FlagStatus: SET or RESET
*/
FlagStatus adc_flag_get(uint32_t adc_periph, uint32_t adc_flag)
{
FlagStatus reval = RESET;
if(ADC_STAT(adc_periph) & adc_flag){
reval = SET;
}
return reval;
}
/*!
\brief clear the ADC flag bits
\param[in] adc_periph: ADCx, x=0,1
\param[in] adc_flag: the adc flag bits
one or more parameters can be selected which are shown as below:
\arg ADC_FLAG_WDE: analog watchdog event flag
\arg ADC_FLAG_EOC: end of group conversion flag
\arg ADC_FLAG_EOIC: end of inserted group conversion flag
\arg ADC_FLAG_STIC: start flag of inserted channel group
\arg ADC_FLAG_STRC: start flag of regular channel group
\param[out] none
\retval none
*/
void adc_flag_clear(uint32_t adc_periph, uint32_t adc_flag)
{
ADC_STAT(adc_periph) &= ~((uint32_t)adc_flag);
}
/*!
\brief get the bit state of ADCx software start conversion
\param[in] adc_periph: ADCx, x=0,1
\param[in] none
\param[out] none
\retval FlagStatus: SET or RESET
*/
FlagStatus adc_regular_software_startconv_flag_get(uint32_t adc_periph)
{
FlagStatus reval = RESET;
if((uint32_t)RESET != (ADC_CTL1(adc_periph) & ADC_CTL1_SWRCST)){
reval = SET;
}
return reval;
}
/*!
\brief get the bit state of ADCx software inserted channel start conversion
\param[in] adc_periph: ADCx, x=0,1
\param[in] none
\param[out] none
\retval FlagStatus: SET or RESET
*/
FlagStatus adc_inserted_software_startconv_flag_get(uint32_t adc_periph)
{
FlagStatus reval = RESET;
if((uint32_t)RESET != (ADC_CTL1(adc_periph) & ADC_CTL1_SWICST)){
reval = SET;
}
return reval;
}
/*!
\brief get the ADC interrupt bits
\param[in] adc_periph: ADCx, x=0,1
\param[in] adc_interrupt: the adc interrupt bits
only one parameter can be selected which is shown as below:
\arg ADC_INT_FLAG_WDE: analog watchdog interrupt
\arg ADC_INT_FLAG_EOC: end of group conversion interrupt
\arg ADC_INT_FLAG_EOIC: end of inserted group conversion interrupt
\param[out] none
\retval FlagStatus: SET or RESET
*/
FlagStatus adc_interrupt_flag_get(uint32_t adc_periph, uint32_t adc_interrupt)
{
FlagStatus interrupt_flag = RESET;
uint32_t state;
/* check the interrupt bits */
switch(adc_interrupt){
case ADC_INT_FLAG_WDE:
/* get the ADC analog watchdog interrupt bits */
state = ADC_STAT(adc_periph) & ADC_STAT_WDE;
if((ADC_CTL0(adc_periph) & ADC_CTL0_WDEIE) && state){
interrupt_flag = SET;
}
break;
case ADC_INT_FLAG_EOC:
/* get the ADC end of group conversion interrupt bits */
state = ADC_STAT(adc_periph) & ADC_STAT_EOC;
if((ADC_CTL0(adc_periph) & ADC_CTL0_EOCIE) && state){
interrupt_flag = SET;
}
break;
case ADC_INT_FLAG_EOIC:
/* get the ADC end of inserted group conversion interrupt bits */
state = ADC_STAT(adc_periph) & ADC_STAT_EOIC;
if((ADC_CTL0(adc_periph) & ADC_CTL0_EOICIE) && state){
interrupt_flag = SET;
}
break;
default:
break;
}
return interrupt_flag;
}
/*!
\brief clear the ADC flag
\param[in] adc_periph: ADCx, x=0,1
\param[in] adc_interrupt: the adc status flag
one or more parameters can be selected which are shown as below:
\arg ADC_INT_FLAG_WDE: analog watchdog interrupt
\arg ADC_INT_FLAG_EOC: end of group conversion interrupt
\arg ADC_INT_FLAG_EOIC: end of inserted group conversion interrupt
\param[out] none
\retval none
*/
void adc_interrupt_flag_clear(uint32_t adc_periph, uint32_t adc_interrupt)
{
ADC_STAT(adc_periph) &= ~((uint32_t)adc_interrupt);
}
/*!
\brief enable ADC interrupt
\param[in] adc_periph: ADCx, x=0,1
\param[in] adc_interrupt: the adc interrupt
one or more parameters can be selected which are shown as below:
\arg ADC_INT_WDE: analog watchdog interrupt flag
\arg ADC_INT_EOC: end of group conversion interrupt flag
\arg ADC_INT_EOIC: end of inserted group conversion interrupt flag
\param[out] none
\retval none
*/
void adc_interrupt_enable(uint32_t adc_periph, uint32_t adc_interrupt)
{
/* enable ADC analog watchdog interrupt */
if(0U != (adc_interrupt & ADC_INT_WDE)){
ADC_CTL0(adc_periph) |= (uint32_t) ADC_CTL0_WDEIE;
}
/* enable ADC end of group conversion interrupt */
if(0U != (adc_interrupt & ADC_INT_EOC)){
ADC_CTL0(adc_periph) |= (uint32_t) ADC_CTL0_EOCIE;
}
/* enable ADC end of inserted group conversion interrupt */
if(0U != (adc_interrupt & ADC_INT_EOIC)){
ADC_CTL0(adc_periph) |= (uint32_t) ADC_CTL0_EOICIE;
}
}
/*!
\brief disable ADC interrupt
\param[in] adc_periph: ADCx, x=0,1
\param[in] adc_interrupt: the adc interrupt flag
one or more parameters can be selected which are shown as below:
\arg ADC_INT_WDE: analog watchdog interrupt flag
\arg ADC_INT_EOC: end of group conversion interrupt flag
\arg ADC_INT_EOIC: end of inserted group conversion interrupt flag
\param[out] none
\retval none
*/
void adc_interrupt_disable(uint32_t adc_periph, uint32_t adc_interrupt)
{
/* disable ADC analog watchdog interrupt */
if(0U != (adc_interrupt & ADC_INT_WDE)){
ADC_CTL0(adc_periph) &= ~(uint32_t) ADC_CTL0_WDEIE;
}
/* disable ADC end of group conversion interrupt */
if(0U != (adc_interrupt & ADC_INT_EOC)){
ADC_CTL0(adc_periph) &= ~(uint32_t) ADC_CTL0_EOCIE;
}
/* disable ADC end of inserted group conversion interrupt */
if(0U != (adc_interrupt & ADC_INT_EOIC)){
ADC_CTL0(adc_periph) &= ~(uint32_t) ADC_CTL0_EOICIE;
}
}
/*!
\brief adc resolution config
\param[in] adc_periph: ADCx, x=0,1
\param[in] resolution: ADC resolution
only one parameter can be selected which is shown as below:
\arg ADC_RESOLUTION_12B: 12-bit ADC resolution
\arg ADC_RESOLUTION_10B: 10-bit ADC resolution
\arg ADC_RESOLUTION_8B: 8-bit ADC resolution
\arg ADC_RESOLUTION_6B: 6-bit ADC resolution
\param[out] none
\retval none
*/
void adc_resolution_config(uint32_t adc_periph, uint32_t resolution)
{
ADC_OVSCR(adc_periph) &= ~((uint32_t)ADC_OVSCR_DRES);
ADC_OVSCR(adc_periph) |= (uint32_t)resolution;
}
/*!
\brief adc oversample mode config
\param[in] adc_periph: ADCx, x=0,1
\param[in] mode: ADC oversampling mode
only one parameter can be selected which is shown as below:
\arg ADC_OVERSAMPLING_ALL_CONVERT: all oversampled conversions for a channel
are done consecutively after a trigger
\arg ADC_OVERSAMPLING_ONE_CONVERT: each oversampled conversion for a channel
needs a trigger
\param[in] shift: ADC oversampling shift
only one parameter can be selected which is shown as below:
\arg ADC_OVERSAMPLING_SHIFT_NONE: no oversampling shift
\arg ADC_OVERSAMPLING_SHIFT_1B: 1-bit oversampling shift
\arg ADC_OVERSAMPLING_SHIFT_2B: 2-bit oversampling shift
\arg ADC_OVERSAMPLING_SHIFT_3B: 3-bit oversampling shift
\arg ADC_OVERSAMPLING_SHIFT_4B: 3-bit oversampling shift
\arg ADC_OVERSAMPLING_SHIFT_5B: 5-bit oversampling shift
\arg ADC_OVERSAMPLING_SHIFT_6B: 6-bit oversampling shift
\arg ADC_OVERSAMPLING_SHIFT_7B: 7-bit oversampling shift
\arg ADC_OVERSAMPLING_SHIFT_8B: 8-bit oversampling shift
\param[in] ratio: ADC oversampling ratio
only one parameter can be selected which is shown as below:
\arg ADC_OVERSAMPLING_RATIO_MUL2: oversampling ratio X2
\arg ADC_OVERSAMPLING_RATIO_MUL4: oversampling ratio X4
\arg ADC_OVERSAMPLING_RATIO_MUL8: oversampling ratio X8
\arg ADC_OVERSAMPLING_RATIO_MUL16: oversampling ratio X16
\arg ADC_OVERSAMPLING_RATIO_MUL32: oversampling ratio X32
\arg ADC_OVERSAMPLING_RATIO_MUL64: oversampling ratio X64
\arg ADC_OVERSAMPLING_RATIO_MUL128: oversampling ratio X128
\arg ADC_OVERSAMPLING_RATIO_MUL256: oversampling ratio X256
\param[out] none
\retval none
*/
void adc_oversample_mode_config(uint32_t adc_periph, uint8_t mode, uint16_t shift,uint8_t ratio)
{
if(mode){
ADC_OVSCR(adc_periph) |= (uint32_t)ADC_OVSCR_TOVS;
}else{
ADC_OVSCR(adc_periph) &= ~((uint32_t)ADC_OVSCR_TOVS);
}
/* config the shift and ratio */
ADC_OVSCR(adc_periph) &= ~((uint32_t)(ADC_OVSCR_OVSR | ADC_OVSCR_OVSS));
ADC_OVSCR(adc_periph) |= ((uint32_t)shift | (uint32_t)ratio);
}
/*!
\brief enable ADC oversample mode
\param[in] adc_periph: ADCx, x=0,1
\param[out] none
\retval none
*/
void adc_oversample_mode_enable(uint32_t adc_periph)
{
ADC_OVSCR(adc_periph) |= ADC_OVSCR_OVSEN;
}
/*!
\brief disable ADC oversample mode
\param[in] adc_periph: ADCx, x=0,1
\param[out] none
\retval none
*/
void adc_oversample_mode_disable(uint32_t adc_periph)
{
ADC_OVSCR(adc_periph) &= ~((uint32_t)ADC_OVSCR_OVSEN);
}
|
4039aa0c51f17098e85c6d2fed5d538dcb0832b5
|
7eaf54a78c9e2117247cb2ab6d3a0c20719ba700
|
/SOFTWARE/A64-TERES/linux-a64/drivers/net/wireless/rtl8723cs/hal/phydm/phydm_antdiv.c
|
866013da756fa9f87ad2605b2a9cf2558459903b
|
[
"GPL-1.0-or-later",
"LicenseRef-scancode-warranty-disclaimer",
"LicenseRef-scancode-free-unknown",
"Apache-2.0",
"Linux-syscall-note",
"GPL-2.0-only"
] |
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
| 162,944
|
c
|
phydm_antdiv.c
|
/******************************************************************************
*
* Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of version 2 of the GNU General Public License as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* 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 Street, Fifth Floor, Boston, MA 02110, USA
*
*
******************************************************************************/
//============================================================
// include files
//============================================================
#include "mp_precomp.h"
#include "phydm_precomp.h"
//======================================================
// when antenna test utility is on or some testing need to disable antenna diversity
// call this function to disable all ODM related mechanisms which will switch antenna.
//======================================================
VOID
ODM_StopAntennaSwitchDm(
IN PVOID pDM_VOID
)
{
PDM_ODM_T pDM_Odm = (PDM_ODM_T)pDM_VOID;
// disable ODM antenna diversity
pDM_Odm->SupportAbility &= ~ODM_BB_ANT_DIV;
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("STOP Antenna Diversity \n"));
}
VOID
ODM_SetAntConfig(
IN PVOID pDM_VOID,
IN u1Byte antSetting // 0=A, 1=B, 2=C, ....
)
{
PDM_ODM_T pDM_Odm = (PDM_ODM_T)pDM_VOID;
if(pDM_Odm->SupportICType == ODM_RTL8723B)
{
if(antSetting == 0) // ant A
ODM_SetBBReg(pDM_Odm, 0x948, bMaskDWord, 0x00000000);
else if(antSetting == 1)
ODM_SetBBReg(pDM_Odm, 0x948, bMaskDWord, 0x00000280);
}
}
//======================================================
VOID
ODM_SwAntDivRestAfterLink(
IN PVOID pDM_VOID
)
{
PDM_ODM_T pDM_Odm = (PDM_ODM_T)pDM_VOID;
pSWAT_T pDM_SWAT_Table = &pDM_Odm->DM_SWAT_Table;
pFAT_T pDM_FatTable = &pDM_Odm->DM_FatTable;
u4Byte i;
if (pDM_Odm->SupportICType & (ODM_RTL8723B|ODM_RTL8821)) {
pDM_SWAT_Table->try_flag = 0xff;
pDM_SWAT_Table->RSSI_Trying = 0;
pDM_SWAT_Table->Double_chk_flag= 0;
pDM_FatTable->RxIdleAnt=MAIN_ANT;
for (i=0; i<ODM_ASSOCIATE_ENTRY_NUM; i++)
{
pDM_FatTable->MainAnt_Sum[i] = 0;
pDM_FatTable->AuxAnt_Sum[i] = 0;
pDM_FatTable->MainAnt_Cnt[i] = 0;
pDM_FatTable->AuxAnt_Cnt[i] = 0;
}
}
}
#if (defined(CONFIG_PHYDM_ANTENNA_DIVERSITY))
VOID
odm_AntDiv_on_off(
IN PVOID pDM_VOID ,
IN u1Byte swch
)
{
PDM_ODM_T pDM_Odm = (PDM_ODM_T)pDM_VOID;
pFAT_T pDM_FatTable = &pDM_Odm->DM_FatTable;
if(pDM_FatTable->AntDiv_OnOff != swch)
{
if(pDM_Odm->AntDivType==S0S1_SW_ANTDIV || pDM_Odm->AntDivType==CGCS_RX_SW_ANTDIV)
return;
if(pDM_Odm->SupportICType & ODM_N_ANTDIV_SUPPORT)
{
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("(( Turn %s )) N-Series HW-AntDiv block\n",(swch==ANTDIV_ON)?"ON" : "OFF"));
ODM_SetBBReg(pDM_Odm, 0xc50 , BIT7, swch); //OFDM AntDiv function block enable
ODM_SetBBReg(pDM_Odm, 0xa00 , BIT15, swch); //CCK AntDiv function block enable
}
else if(pDM_Odm->SupportICType & ODM_AC_ANTDIV_SUPPORT)
{
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("(( Turn %s )) AC-Series HW-AntDiv block\n",(swch==ANTDIV_ON)?"ON" : "OFF"));
if (pDM_Odm->SupportICType == ODM_RTL8812) {
ODM_SetBBReg(pDM_Odm, 0xc50 , BIT7, swch); //OFDM AntDiv function block enable
ODM_SetBBReg(pDM_Odm, 0xa00 , BIT15, swch); //CCK AntDiv function block enable
} else {
ODM_SetBBReg(pDM_Odm, 0x8D4 , BIT24, swch); //OFDM AntDiv function block enable
if( (pDM_Odm->CutVersion >= ODM_CUT_C) && (pDM_Odm->SupportICType == ODM_RTL8821) && ( pDM_Odm->AntDivType != S0S1_SW_ANTDIV))
{
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("(( Turn %s )) CCK HW-AntDiv block\n",(swch==ANTDIV_ON)?"ON" : "OFF"));
ODM_SetBBReg(pDM_Odm, 0x800 , BIT25, swch);
ODM_SetBBReg(pDM_Odm, 0xA00 , BIT15, swch); //CCK AntDiv function block enable
}
}
}
}
pDM_FatTable->AntDiv_OnOff =swch;
}
VOID
phydm_FastTraining_enable(
IN PVOID pDM_VOID,
IN u1Byte swch
)
{
PDM_ODM_T pDM_Odm = (PDM_ODM_T)pDM_VOID;
u1Byte enable;
if (swch == FAT_ON)
enable=1;
else
enable=0;
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("Fast Ant Training_en = ((%d))\n", enable));
if (pDM_Odm->SupportICType == ODM_RTL8188E) {
ODM_SetBBReg(pDM_Odm, 0xe08 , BIT16, enable); /*enable fast training*/
/**/
} else if (pDM_Odm->SupportICType == ODM_RTL8192E) {
ODM_SetBBReg(pDM_Odm, 0xB34 , BIT28, enable); /*enable fast training (path-A)*/
/*ODM_SetBBReg(pDM_Odm, 0xB34 , BIT29, enable);*/ /*enable fast training (path-B)*/
} else if (pDM_Odm->SupportICType == ODM_RTL8821) {
ODM_SetBBReg(pDM_Odm, 0x900 , BIT19, enable); /*enable fast training */
/**/
}
}
VOID
odm_Tx_By_TxDesc_or_Reg(
IN PVOID pDM_VOID,
IN u1Byte swch
)
{
PDM_ODM_T pDM_Odm = (PDM_ODM_T)pDM_VOID;
u1Byte enable;
if( swch== TX_BY_DESC)
enable=1;
else
enable=0;
if(pDM_Odm->AntDivType != CGCS_RX_HW_ANTDIV)
{
if(pDM_Odm->SupportICType & ODM_N_ANTDIV_SUPPORT)
{
ODM_SetBBReg(pDM_Odm, 0x80c , BIT21, enable);
}
else if(pDM_Odm->SupportICType & ODM_AC_ANTDIV_SUPPORT)
{
ODM_SetBBReg(pDM_Odm, 0x900 , BIT18, enable);
}
}
}
u1Byte
phydm_traffic_load_decision(
IN PVOID pDM_VOID
)
{
PDM_ODM_T pDM_Odm = (PDM_ODM_T)pDM_VOID;
pSWAT_T pDM_SWAT_Table = &pDM_Odm->DM_SWAT_Table;
u8Byte curTxOkCnt = 0, curRxOkCnt = 0;
u1Byte traffic;
/*---trafic load decision---*/
curTxOkCnt = *(pDM_Odm->pNumTxBytesUnicast) - pDM_SWAT_Table->lastTxOkCnt;
curRxOkCnt = *(pDM_Odm->pNumRxBytesUnicast) - pDM_SWAT_Table->lastRxOkCnt;
pDM_SWAT_Table->lastTxOkCnt = *(pDM_Odm->pNumTxBytesUnicast);
pDM_SWAT_Table->lastRxOkCnt = *(pDM_Odm->pNumRxBytesUnicast);
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("TxOkCnt=(( %llu )), RxOkCnt=(( %llu ))\n",
curTxOkCnt, curRxOkCnt));
if (curTxOkCnt > 1875000 || curRxOkCnt > 1875000) {/*if(PlatformDivision64(curTxOkCnt+curRxOkCnt, 2) > 1875000) ( 1.875M * 8bit ) / 2= 7.5M bits /sec )*/
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("[HIGH Traffic]\n"));
traffic = TRAFFIC_HIGH;
} else if (curTxOkCnt > 300000 || curRxOkCnt > 300000) { /*( 0.3M * 8bit ) / 2 = 1.2M bits /sec )*/
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("[MID Traffic]\n"));
traffic = TRAFFIC_MID;
} else if (curTxOkCnt > 125000 || curRxOkCnt > 125000) { /*( 0.125M * 8bit ) / 2 = 0.5M bits /sec )*/
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("[Low Traffic]\n"));
traffic = TRAFFIC_LOW;
} else {
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("[Ultra-Low Traffic]\n"));
traffic = TRAFFIC_ULTRA_LOW;
}
return traffic;
}
VOID
ODM_UpdateRxIdleAnt(
IN PVOID pDM_VOID,
IN u1Byte Ant
)
{
PDM_ODM_T pDM_Odm = (PDM_ODM_T)pDM_VOID;
pFAT_T pDM_FatTable = &pDM_Odm->DM_FatTable;
u4Byte DefaultAnt, OptionalAnt,value32;
if(pDM_FatTable->RxIdleAnt != Ant)
{
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("[ Update Rx-Idle-Ant ] RxIdleAnt =%s\n",(Ant==MAIN_ANT)?"MAIN_ANT":"AUX_ANT"));
if(!(pDM_Odm->SupportICType & ODM_RTL8723B))
pDM_FatTable->RxIdleAnt = Ant;
if(Ant == MAIN_ANT)
{
DefaultAnt = ANT1_2G;
OptionalAnt = ANT2_2G;
}
else
{
DefaultAnt = ANT2_2G;
OptionalAnt = ANT1_2G;
}
if(pDM_Odm->SupportICType & ODM_N_ANTDIV_SUPPORT)
{
if(pDM_Odm->SupportICType==ODM_RTL8192E)
{
ODM_SetBBReg(pDM_Odm, 0xB38 , BIT5|BIT4|BIT3, DefaultAnt); //Default RX
ODM_SetBBReg(pDM_Odm, 0xB38 , BIT8|BIT7|BIT6, OptionalAnt);//Optional RX
ODM_SetBBReg(pDM_Odm, 0x860, BIT14|BIT13|BIT12, DefaultAnt);//Default TX
}
#if (RTL8723B_SUPPORT == 1)
else if(pDM_Odm->SupportICType==ODM_RTL8723B)
{
value32 = ODM_GetBBReg(pDM_Odm, 0x948, 0xFFF);
if(value32 !=0x280)
ODM_UpdateRxIdleAnt_8723B(pDM_Odm, Ant, DefaultAnt, OptionalAnt);
else
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("[ Update Rx-Idle-Ant ] 8723B: Fail to set RX antenna due to 0x948 = 0x280\n"));
}
#endif
else //88E
{
ODM_SetBBReg(pDM_Odm, 0x864 , BIT5|BIT4|BIT3, DefaultAnt); //Default RX
ODM_SetBBReg(pDM_Odm, 0x864 , BIT8|BIT7|BIT6, OptionalAnt); //Optional RX
ODM_SetBBReg(pDM_Odm, 0x860, BIT14|BIT13|BIT12, DefaultAnt); //Default TX
}
}
else if(pDM_Odm->SupportICType & ODM_AC_ANTDIV_SUPPORT)
{
u2Byte value16 = ODM_Read2Byte(pDM_Odm, ODM_REG_TRMUX_11AC+2);
//
// 2014/01/14 MH/Luke.Lee Add direct write for register 0xc0a to prevnt
// incorrect 0xc08 bit0-15 .We still not know why it is changed.
//
value16 &= ~(BIT11|BIT10|BIT9|BIT8|BIT7|BIT6|BIT5|BIT4|BIT3);
value16 |= ((u2Byte)DefaultAnt <<3);
value16 |= ((u2Byte)OptionalAnt <<6);
value16 |= ((u2Byte)DefaultAnt <<9);
ODM_Write2Byte(pDM_Odm, ODM_REG_TRMUX_11AC+2, value16);
/*
ODM_SetBBReg(pDM_Odm, ODM_REG_TRMUX_11AC , BIT21|BIT20|BIT19, DefaultAnt); //Default RX
ODM_SetBBReg(pDM_Odm, ODM_REG_TRMUX_11AC , BIT24|BIT23|BIT22, OptionalAnt);//Optional RX
ODM_SetBBReg(pDM_Odm, ODM_REG_TRMUX_11AC , BIT27|BIT26|BIT25, DefaultAnt); //Default TX
*/
}
if(pDM_Odm->SupportICType==ODM_RTL8188E)
{
ODM_SetMACReg(pDM_Odm, 0x6D8 , BIT7|BIT6, DefaultAnt); //PathA Resp Tx
}
else
{
ODM_SetMACReg(pDM_Odm, 0x6D8 , BIT10|BIT9|BIT8, DefaultAnt); //PathA Resp Tx
}
}
else// pDM_FatTable->RxIdleAnt == Ant
{
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("[ Stay in Ori-Ant ] RxIdleAnt =%s\n",(Ant==MAIN_ANT)?"MAIN_ANT":"AUX_ANT"));
pDM_FatTable->RxIdleAnt = Ant;
}
}
VOID
odm_UpdateTxAnt(
IN PVOID pDM_VOID,
IN u1Byte Ant,
IN u4Byte MacId
)
{
PDM_ODM_T pDM_Odm = (PDM_ODM_T)pDM_VOID;
pFAT_T pDM_FatTable = &pDM_Odm->DM_FatTable;
u1Byte TxAnt;
if (pDM_Odm->AntDivType==CG_TRX_SMART_ANTDIV)
{
TxAnt=Ant;
}
else
{
if(Ant == MAIN_ANT)
TxAnt = ANT1_2G;
else
TxAnt = ANT2_2G;
}
pDM_FatTable->antsel_a[MacId] = TxAnt&BIT0;
pDM_FatTable->antsel_b[MacId] = (TxAnt&BIT1)>>1;
pDM_FatTable->antsel_c[MacId] = (TxAnt&BIT2)>>2;
//ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("[Tx from TxInfo]: MacID:(( %d )), TxAnt = (( %s ))\n", MacId,(Ant==MAIN_ANT)?"MAIN_ANT":"AUX_ANT"));
//ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD,("antsel_tr_mux=(( 3'b%d%d%d ))\n",pDM_FatTable->antsel_c[MacId] , pDM_FatTable->antsel_b[MacId] , pDM_FatTable->antsel_a[MacId] ));
}
#ifdef BEAMFORMING_SUPPORT
#if(DM_ODM_SUPPORT_TYPE == ODM_AP)
VOID
odm_BDC_Init(
IN PVOID pDM_VOID
)
{
PDM_ODM_T pDM_Odm = (PDM_ODM_T)pDM_VOID;
pBDC_T pDM_BdcTable=&pDM_Odm->DM_BdcTable;
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("\n[ BDC Initialization......] \n"));
pDM_BdcTable->BDC_state=BDC_DIV_TRAIN_STATE;
pDM_BdcTable->BDC_Mode=BDC_MODE_NULL;
pDM_BdcTable->BDC_Try_flag=0;
pDM_BdcTable->BDCcoexType_wBfer=0;
pDM_Odm->bdc_holdstate=0xff;
if(pDM_Odm->SupportICType == ODM_RTL8192E)
{
ODM_SetBBReg(pDM_Odm, 0xd7c , 0x0FFFFFFF, 0x1081008);
ODM_SetBBReg(pDM_Odm, 0xd80 , 0x0FFFFFFF, 0);
}
else if(pDM_Odm->SupportICType == ODM_RTL8812)
{
ODM_SetBBReg(pDM_Odm, 0x9b0 , 0x0FFFFFFF, 0x1081008); //0x9b0[30:0] = 01081008
ODM_SetBBReg(pDM_Odm, 0x9b4 , 0x0FFFFFFF, 0); //0x9b4[31:0] = 00000000
}
}
VOID
odm_CSI_on_off(
IN PVOID pDM_VOID,
IN u1Byte CSI_en
)
{
PDM_ODM_T pDM_Odm = (PDM_ODM_T)pDM_VOID;
if(CSI_en==CSI_ON)
{
if(pDM_Odm->SupportICType == ODM_RTL8192E)
{
ODM_SetMACReg(pDM_Odm, 0xd84 , BIT11, 1); //0xd84[11]=1
}
else if(pDM_Odm->SupportICType == ODM_RTL8812)
{
ODM_SetMACReg(pDM_Odm, 0x9b0 , BIT31, 1); //0x9b0[31]=1
}
}
else if(CSI_en==CSI_OFF)
{
if(pDM_Odm->SupportICType == ODM_RTL8192E)
{
ODM_SetMACReg(pDM_Odm, 0xd84 , BIT11, 0); //0xd84[11]=0
}
else if(pDM_Odm->SupportICType == ODM_RTL8812)
{
ODM_SetMACReg(pDM_Odm, 0x9b0 , BIT31, 0); //0x9b0[31]=0
}
}
}
VOID
odm_BDCcoexType_withBferClient(
IN PVOID pDM_VOID,
IN u1Byte swch
)
{
PDM_ODM_T pDM_Odm = (PDM_ODM_T)pDM_VOID;
pBDC_T pDM_BdcTable = &pDM_Odm->DM_BdcTable;
u1Byte BDCcoexType_wBfer;
if(swch==DIVON_CSIOFF)
{
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("[BDCcoexType: 1] {DIV,CSI} ={1,0} \n"));
BDCcoexType_wBfer=1;
if(BDCcoexType_wBfer != pDM_BdcTable->BDCcoexType_wBfer)
{
odm_AntDiv_on_off(pDM_Odm, ANTDIV_ON);
odm_CSI_on_off(pDM_Odm,CSI_OFF);
pDM_BdcTable->BDCcoexType_wBfer=1;
}
}
else if(swch==DIVOFF_CSION)
{
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("[BDCcoexType: 2] {DIV,CSI} ={0,1}\n"));
BDCcoexType_wBfer=2;
if(BDCcoexType_wBfer != pDM_BdcTable->BDCcoexType_wBfer)
{
odm_AntDiv_on_off(pDM_Odm, ANTDIV_OFF);
odm_CSI_on_off(pDM_Odm,CSI_ON);
pDM_BdcTable->BDCcoexType_wBfer=2;
}
}
}
VOID
odm_BF_AntDiv_ModeArbitration(
IN PVOID pDM_VOID
)
{
PDM_ODM_T pDM_Odm = (PDM_ODM_T)pDM_VOID;
pBDC_T pDM_BdcTable = &pDM_Odm->DM_BdcTable;
u1Byte current_BDC_Mode;
#if(DM_ODM_SUPPORT_TYPE == ODM_AP)
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("\n"));
//2 Mode 1
if((pDM_BdcTable->num_Txbfee_Client !=0) && (pDM_BdcTable->num_Txbfer_Client == 0))
{
current_BDC_Mode=BDC_MODE_1;
if(current_BDC_Mode != pDM_BdcTable->BDC_Mode)
{
pDM_BdcTable->BDC_Mode=BDC_MODE_1;
odm_BDCcoexType_withBferClient( pDM_Odm, DIVON_CSIOFF);
pDM_BdcTable->BDC_RxIdleUpdate_counter=1;
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("Change to (( Mode1 ))\n"));
}
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("[Antdiv + BF coextance Mode] : (( Mode1 ))\n"));
}
//2 Mode 2
else if((pDM_BdcTable->num_Txbfee_Client ==0) && (pDM_BdcTable->num_Txbfer_Client != 0))
{
current_BDC_Mode=BDC_MODE_2;
if(current_BDC_Mode != pDM_BdcTable->BDC_Mode)
{
pDM_BdcTable->BDC_Mode=BDC_MODE_2;
pDM_BdcTable->BDC_state=BDC_DIV_TRAIN_STATE;
pDM_BdcTable->BDC_Try_flag=0;
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("Change to (( Mode2 ))\n"));
}
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("[Antdiv + BF coextance Mode] : (( Mode2 ))\n"));
}
//2 Mode 3
else if((pDM_BdcTable->num_Txbfee_Client !=0) && (pDM_BdcTable->num_Txbfer_Client != 0))
{
current_BDC_Mode=BDC_MODE_3;
if(current_BDC_Mode != pDM_BdcTable->BDC_Mode)
{
pDM_BdcTable->BDC_Mode=BDC_MODE_3;
pDM_BdcTable->BDC_state=BDC_DIV_TRAIN_STATE;
pDM_BdcTable->BDC_Try_flag=0;
pDM_BdcTable->BDC_RxIdleUpdate_counter=1;
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("Change to (( Mode3 ))\n"));
}
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("[Antdiv + BF coextance Mode] : (( Mode3 ))\n"));
}
//2 Mode 4
else if((pDM_BdcTable->num_Txbfee_Client ==0) && (pDM_BdcTable->num_Txbfer_Client == 0))
{
current_BDC_Mode=BDC_MODE_4;
if(current_BDC_Mode != pDM_BdcTable->BDC_Mode)
{
pDM_BdcTable->BDC_Mode=BDC_MODE_4;
odm_BDCcoexType_withBferClient( pDM_Odm, DIVON_CSIOFF);
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("Change to (( Mode4 ))\n"));
}
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("[Antdiv + BF coextance Mode] : (( Mode4 ))\n"));
}
#endif
}
VOID
odm_DivTrainState_setting(
IN PVOID pDM_VOID
)
{
PDM_ODM_T pDM_Odm = (PDM_ODM_T)pDM_VOID;
pBDC_T pDM_BdcTable=&pDM_Odm->DM_BdcTable;
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("\n*****[S T A R T ]***** [2-0. DIV_TRAIN_STATE] \n"));
pDM_BdcTable->BDC_Try_counter =2;
pDM_BdcTable->BDC_Try_flag=1;
pDM_BdcTable->BDC_state=BDC_BFer_TRAIN_STATE;
odm_BDCcoexType_withBferClient( pDM_Odm, DIVON_CSIOFF);
}
VOID
odm_BDCcoex_BFeeRxDiv_Arbitration(
IN PVOID pDM_VOID
)
{
PDM_ODM_T pDM_Odm = (PDM_ODM_T)pDM_VOID;
pBDC_T pDM_BdcTable = &pDM_Odm->DM_BdcTable;
BOOLEAN StopBF_flag;
u1Byte BDC_active_Mode;
#if(DM_ODM_SUPPORT_TYPE == ODM_AP)
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("***{ num_BFee, num_BFer , num_Client} = (( %d , %d , %d)) \n",pDM_BdcTable->num_Txbfee_Client,pDM_BdcTable->num_Txbfer_Client,pDM_BdcTable->num_Client));
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("***{ num_BF_tars, num_DIV_tars } = (( %d , %d )) \n",pDM_BdcTable->num_BfTar , pDM_BdcTable->num_DivTar ));
//2 [ MIB control ]
if (pDM_Odm->bdc_holdstate==2)
{
odm_BDCcoexType_withBferClient( pDM_Odm, DIVOFF_CSION);
pDM_BdcTable->BDC_state=BDC_BF_HOLD_STATE;
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("Force in [ BF STATE] \n"));
return;
}
else if (pDM_Odm->bdc_holdstate==1)
{
pDM_BdcTable->BDC_state=BDC_DIV_HOLD_STATE;
odm_BDCcoexType_withBferClient( pDM_Odm, DIVON_CSIOFF);
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("Force in [ DIV STATE] \n"));
return;
}
//------------------------------------------------------------
//2 Mode 2 & 3
if(pDM_BdcTable->BDC_Mode==BDC_MODE_2 ||pDM_BdcTable->BDC_Mode==BDC_MODE_3)
{
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("\n{ Try_flag , Try_counter } = { %d , %d } \n",pDM_BdcTable->BDC_Try_flag,pDM_BdcTable->BDC_Try_counter));
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("BDCcoexType = (( %d )) \n\n", pDM_BdcTable->BDCcoexType_wBfer));
// All Client have Bfer-Cap-------------------------------
if(pDM_BdcTable->num_Txbfer_Client == pDM_BdcTable->num_Client) //BFer STA Only?: yes
{
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("BFer STA only? (( Yes ))\n"));
pDM_BdcTable->BDC_Try_flag=0;
pDM_BdcTable->BDC_state=BDC_DIV_TRAIN_STATE;
odm_BDCcoexType_withBferClient( pDM_Odm, DIVOFF_CSION);
return;
}
else
{
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("BFer STA only? (( No ))\n"));
}
//
if(pDM_BdcTable->bAll_BFSta_Idle==FALSE && pDM_BdcTable->bAll_DivSta_Idle==TRUE)
{
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("All DIV-STA are idle, but BF-STA not\n"));
pDM_BdcTable->BDC_Try_flag=0;
pDM_BdcTable->BDC_state=BDC_BFer_TRAIN_STATE;
odm_BDCcoexType_withBferClient( pDM_Odm, DIVOFF_CSION);
return;
}
else if(pDM_BdcTable->bAll_BFSta_Idle==TRUE && pDM_BdcTable->bAll_DivSta_Idle==FALSE)
{
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("All BF-STA are idle, but DIV-STA not\n"));
pDM_BdcTable->BDC_Try_flag=0;
pDM_BdcTable->BDC_state=BDC_DIV_TRAIN_STATE;
odm_BDCcoexType_withBferClient( pDM_Odm, DIVON_CSIOFF);
return;
}
//Select active mode--------------------------------------
if(pDM_BdcTable->num_BfTar ==0) // Selsect_1, Selsect_2
{
if(pDM_BdcTable->num_DivTar ==0) // Selsect_3
{
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("Select active mode (( 1 )) \n"));
pDM_BdcTable->BDC_active_Mode=1;
}
else
{
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("Select active mode (( 2 ))\n"));
pDM_BdcTable->BDC_active_Mode=2;
}
pDM_BdcTable->BDC_Try_flag=0;
pDM_BdcTable->BDC_state=BDC_DIV_TRAIN_STATE;
odm_BDCcoexType_withBferClient( pDM_Odm, DIVON_CSIOFF);
return;
}
else // num_BfTar > 0
{
if(pDM_BdcTable->num_DivTar ==0) // Selsect_3
{
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("Select active mode (( 3 ))\n"));
pDM_BdcTable->BDC_active_Mode=3;
pDM_BdcTable->BDC_Try_flag=0;
pDM_BdcTable->BDC_state=BDC_BFer_TRAIN_STATE;
odm_BDCcoexType_withBferClient( pDM_Odm, DIVOFF_CSION);
return;
}
else // Selsect_4
{
BDC_active_Mode=4;
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("Select active mode (( 4 ))\n"));
if(BDC_active_Mode!=pDM_BdcTable->BDC_active_Mode)
{
pDM_BdcTable->BDC_active_Mode=4;
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("Change to active mode (( 4 )) & return!!! \n"));
return;
}
}
}
#if 1
if (pDM_Odm->bdc_holdstate==0xff)
{
pDM_BdcTable->BDC_state=BDC_DIV_HOLD_STATE;
odm_BDCcoexType_withBferClient( pDM_Odm, DIVON_CSIOFF);
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("Force in [ DIV STATE] \n"));
return;
}
#endif
// Does Client number changed ? -------------------------------
if(pDM_BdcTable->num_Client !=pDM_BdcTable->pre_num_Client)
{
pDM_BdcTable->BDC_Try_flag=0;
pDM_BdcTable->BDC_state=BDC_DIV_TRAIN_STATE;
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("[ The number of client has been changed !!!] return to (( BDC_DIV_TRAIN_STATE )) \n"));
}
pDM_BdcTable->pre_num_Client=pDM_BdcTable->num_Client;
if( pDM_BdcTable->BDC_Try_flag==0)
{
//2 DIV_TRAIN_STATE (Mode 2-0)
if(pDM_BdcTable->BDC_state==BDC_DIV_TRAIN_STATE)
{
odm_DivTrainState_setting( pDM_Odm);
}
//2 BFer_TRAIN_STATE (Mode 2-1)
else if(pDM_BdcTable->BDC_state==BDC_BFer_TRAIN_STATE)
{
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("*****[2-1. BFer_TRAIN_STATE ]***** \n"));
//if(pDM_BdcTable->num_BfTar==0)
//{
// ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("BF_tars exist? : (( No )), [ BDC_BFer_TRAIN_STATE ] >> [BDC_DIV_TRAIN_STATE] \n"));
// odm_DivTrainState_setting( pDM_Odm);
//}
//else //num_BfTar != 0
//{
pDM_BdcTable->BDC_Try_counter=2;
pDM_BdcTable->BDC_Try_flag=1;
pDM_BdcTable->BDC_state=BDC_DECISION_STATE;
odm_BDCcoexType_withBferClient( pDM_Odm, DIVOFF_CSION);
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("BF_tars exist? : (( Yes )), [ BDC_BFer_TRAIN_STATE ] >> [BDC_DECISION_STATE] \n"));
//}
}
//2 DECISION_STATE (Mode 2-2)
else if(pDM_BdcTable->BDC_state==BDC_DECISION_STATE)
{
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("*****[2-2. DECISION_STATE]***** \n"));
//if(pDM_BdcTable->num_BfTar==0)
//{
// ODM_AntDiv_Printk(("BF_tars exist? : (( No )), [ DECISION_STATE ] >> [BDC_DIV_TRAIN_STATE] \n"));
// odm_DivTrainState_setting( pDM_Odm);
//}
//else //num_BfTar != 0
//{
if(pDM_BdcTable->BF_pass==FALSE || pDM_BdcTable->DIV_pass == FALSE)
StopBF_flag=TRUE;
else
StopBF_flag=FALSE;
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("BF_tars exist? : (( Yes )), {BF_pass, DIV_pass, StopBF_flag } = { %d, %d, %d } \n" ,pDM_BdcTable->BF_pass,pDM_BdcTable->DIV_pass,StopBF_flag));
if(StopBF_flag==TRUE) //DIV_en
{
pDM_BdcTable->BDC_Hold_counter=10; //20
odm_BDCcoexType_withBferClient( pDM_Odm, DIVON_CSIOFF);
pDM_BdcTable->BDC_state=BDC_DIV_HOLD_STATE;
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("[ StopBF_flag= ((TRUE)), BDC_DECISION_STATE ] >> [BDC_DIV_HOLD_STATE] \n"));
}
else //BF_en
{
pDM_BdcTable->BDC_Hold_counter=10; //20
odm_BDCcoexType_withBferClient( pDM_Odm, DIVOFF_CSION);
pDM_BdcTable->BDC_state=BDC_BF_HOLD_STATE;
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("[StopBF_flag= ((FALSE)), BDC_DECISION_STATE ] >> [BDC_BF_HOLD_STATE] \n"));
}
//}
}
//2 BF-HOLD_STATE (Mode 2-3)
else if(pDM_BdcTable->BDC_state==BDC_BF_HOLD_STATE)
{
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("*****[2-3. BF_HOLD_STATE ]*****\n"));
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("BDC_Hold_counter = (( %d )) \n",pDM_BdcTable->BDC_Hold_counter ));
if(pDM_BdcTable->BDC_Hold_counter==1)
{
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("[ BDC_BF_HOLD_STATE ] >> [BDC_DIV_TRAIN_STATE] \n"));
odm_DivTrainState_setting( pDM_Odm);
}
else
{
pDM_BdcTable->BDC_Hold_counter--;
//if(pDM_BdcTable->num_BfTar==0)
//{
// ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("BF_tars exist? : (( No )), [ BDC_BF_HOLD_STATE ] >> [BDC_DIV_TRAIN_STATE] \n"));
// odm_DivTrainState_setting( pDM_Odm);
//}
//else //num_BfTar != 0
//{
//ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("BF_tars exist? : (( Yes ))\n"));
pDM_BdcTable->BDC_state=BDC_BF_HOLD_STATE;
odm_BDCcoexType_withBferClient( pDM_Odm, DIVOFF_CSION);
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("[ BDC_BF_HOLD_STATE ] >> [BDC_BF_HOLD_STATE] \n"));
//}
}
}
//2 DIV-HOLD_STATE (Mode 2-4)
else if(pDM_BdcTable->BDC_state==BDC_DIV_HOLD_STATE)
{
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("*****[2-4. DIV_HOLD_STATE ]*****\n"));
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("BDC_Hold_counter = (( %d )) \n",pDM_BdcTable->BDC_Hold_counter ));
if(pDM_BdcTable->BDC_Hold_counter==1)
{
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("[ BDC_DIV_HOLD_STATE ] >> [BDC_DIV_TRAIN_STATE] \n"));
odm_DivTrainState_setting( pDM_Odm);
}
else
{
pDM_BdcTable->BDC_Hold_counter--;
pDM_BdcTable->BDC_state=BDC_DIV_HOLD_STATE;
odm_BDCcoexType_withBferClient( pDM_Odm, DIVON_CSIOFF);
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("[ BDC_DIV_HOLD_STATE ] >> [BDC_DIV_HOLD_STATE] \n"));
}
}
}
else if( pDM_BdcTable->BDC_Try_flag==1)
{
//2 Set Training Counter
if(pDM_BdcTable->BDC_Try_counter >1)
{
pDM_BdcTable->BDC_Try_counter--;
if(pDM_BdcTable->BDC_Try_counter ==1)
pDM_BdcTable->BDC_Try_flag=0;
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("Training !!\n"));
//return ;
}
}
}
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("\n[end]\n"));
#endif //#if(DM_ODM_SUPPORT_TYPE == ODM_AP)
}
#endif
#endif //#ifdef BEAMFORMING_SUPPORT
#if (RTL8188E_SUPPORT == 1)
VOID
odm_RX_HWAntDiv_Init_88E(
IN PVOID pDM_VOID
)
{
PDM_ODM_T pDM_Odm = (PDM_ODM_T)pDM_VOID;
u4Byte value32;
pFAT_T pDM_FatTable = &pDM_Odm->DM_FatTable;
if(pDM_Odm->mp_mode == TRUE)
{
pDM_Odm->AntDivType = CGCS_RX_SW_ANTDIV;
ODM_SetBBReg(pDM_Odm, ODM_REG_IGI_A_11N , BIT7, 0); // disable HW AntDiv
ODM_SetBBReg(pDM_Odm, ODM_REG_LNA_SWITCH_11N , BIT31, 1); // 1:CG, 0:CS
return;
}
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("***8188E AntDiv_Init => AntDivType=[CGCS_RX_HW_ANTDIV]\n"));
//MAC Setting
value32 = ODM_GetMACReg(pDM_Odm, ODM_REG_ANTSEL_PIN_11N, bMaskDWord);
ODM_SetMACReg(pDM_Odm, ODM_REG_ANTSEL_PIN_11N, bMaskDWord, value32|(BIT23|BIT25)); //Reg4C[25]=1, Reg4C[23]=1 for pin output
//Pin Settings
ODM_SetBBReg(pDM_Odm, ODM_REG_PIN_CTRL_11N , BIT9|BIT8, 0);//Reg870[8]=1'b0, Reg870[9]=1'b0 //antsel antselb by HW
ODM_SetBBReg(pDM_Odm, ODM_REG_RX_ANT_CTRL_11N , BIT10, 0); //Reg864[10]=1'b0 //antsel2 by HW
ODM_SetBBReg(pDM_Odm, ODM_REG_LNA_SWITCH_11N , BIT22, 1); //Regb2c[22]=1'b0 //disable CS/CG switch
ODM_SetBBReg(pDM_Odm, ODM_REG_LNA_SWITCH_11N , BIT31, 1); //Regb2c[31]=1'b1 //output at CG only
//OFDM Settings
ODM_SetBBReg(pDM_Odm, ODM_REG_ANTDIV_PARA1_11N , bMaskDWord, 0x000000a0);
//CCK Settings
ODM_SetBBReg(pDM_Odm, ODM_REG_BB_PWR_SAV4_11N , BIT7, 1); //Fix CCK PHY status report issue
ODM_SetBBReg(pDM_Odm, ODM_REG_CCK_ANTDIV_PARA2_11N , BIT4, 1); //CCK complete HW AntDiv within 64 samples
ODM_SetBBReg(pDM_Odm, ODM_REG_ANT_MAPPING1_11N , 0xFFFF, 0x0001); //antenna mapping table
pDM_FatTable->enable_ctrl_frame_antdiv = 1;
}
VOID
odm_TRX_HWAntDiv_Init_88E(
IN PVOID pDM_VOID
)
{
PDM_ODM_T pDM_Odm = (PDM_ODM_T)pDM_VOID;
u4Byte value32;
pFAT_T pDM_FatTable = &pDM_Odm->DM_FatTable;
if(pDM_Odm->mp_mode == TRUE)
{
pDM_Odm->AntDivType = CGCS_RX_SW_ANTDIV;
ODM_SetBBReg(pDM_Odm, ODM_REG_IGI_A_11N , BIT7, 0); // disable HW AntDiv
ODM_SetBBReg(pDM_Odm, ODM_REG_RX_ANT_CTRL_11N , BIT5|BIT4|BIT3, 0); //Default RX (0/1)
return;
}
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("***8188E AntDiv_Init => AntDivType=[CG_TRX_HW_ANTDIV (SPDT)]\n"));
//MAC Setting
value32 = ODM_GetMACReg(pDM_Odm, ODM_REG_ANTSEL_PIN_11N, bMaskDWord);
ODM_SetMACReg(pDM_Odm, ODM_REG_ANTSEL_PIN_11N, bMaskDWord, value32|(BIT23|BIT25)); //Reg4C[25]=1, Reg4C[23]=1 for pin output
//Pin Settings
ODM_SetBBReg(pDM_Odm, ODM_REG_PIN_CTRL_11N , BIT9|BIT8, 0);//Reg870[8]=1'b0, Reg870[9]=1'b0 //antsel antselb by HW
ODM_SetBBReg(pDM_Odm, ODM_REG_RX_ANT_CTRL_11N , BIT10, 0); //Reg864[10]=1'b0 //antsel2 by HW
ODM_SetBBReg(pDM_Odm, ODM_REG_LNA_SWITCH_11N , BIT22, 0); //Regb2c[22]=1'b0 //disable CS/CG switch
ODM_SetBBReg(pDM_Odm, ODM_REG_LNA_SWITCH_11N , BIT31, 1); //Regb2c[31]=1'b1 //output at CG only
//OFDM Settings
ODM_SetBBReg(pDM_Odm, ODM_REG_ANTDIV_PARA1_11N , bMaskDWord, 0x000000a0);
//CCK Settings
ODM_SetBBReg(pDM_Odm, ODM_REG_BB_PWR_SAV4_11N , BIT7, 1); //Fix CCK PHY status report issue
ODM_SetBBReg(pDM_Odm, ODM_REG_CCK_ANTDIV_PARA2_11N , BIT4, 1); //CCK complete HW AntDiv within 64 samples
//antenna mapping table
if(!pDM_Odm->bIsMPChip) //testchip
{
ODM_SetBBReg(pDM_Odm, ODM_REG_RX_DEFUALT_A_11N , BIT10|BIT9|BIT8, 1); //Reg858[10:8]=3'b001
ODM_SetBBReg(pDM_Odm, ODM_REG_RX_DEFUALT_A_11N , BIT13|BIT12|BIT11, 2); //Reg858[13:11]=3'b010
}
else //MPchip
ODM_SetBBReg(pDM_Odm, ODM_REG_ANT_MAPPING1_11N , bMaskDWord, 0x0201); /*Reg914=3'b010, Reg915=3'b001*/
pDM_FatTable->enable_ctrl_frame_antdiv = 1;
}
#if( defined(CONFIG_5G_CG_SMART_ANT_DIVERSITY) ) ||( defined(CONFIG_2G_CG_SMART_ANT_DIVERSITY) )
VOID
odm_Smart_HWAntDiv_Init_88E(
IN PVOID pDM_VOID
)
{
PDM_ODM_T pDM_Odm = (PDM_ODM_T)pDM_VOID;
u4Byte value32, i;
pFAT_T pDM_FatTable = &pDM_Odm->DM_FatTable;
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("***8188E AntDiv_Init => AntDivType=[CG_TRX_SMART_ANTDIV]\n"));
if(pDM_Odm->mp_mode == TRUE)
{
ODM_RT_TRACE(pDM_Odm, ODM_COMP_INIT, ODM_DBG_LOUD, ("pDM_Odm->AntDivType: %d\n", pDM_Odm->AntDivType));
return;
}
pDM_FatTable->TrainIdx = 0;
pDM_FatTable->FAT_State = FAT_PREPARE_STATE;
pDM_Odm->fat_comb_a=5;
pDM_Odm->antdiv_intvl = 0x64; // 100ms
for(i=0; i<6; i++)
{
pDM_FatTable->Bssid[i] = 0;
}
for(i=0; i< (pDM_Odm->fat_comb_a) ; i++)
{
pDM_FatTable->antSumRSSI[i] = 0;
pDM_FatTable->antRSSIcnt[i] = 0;
pDM_FatTable->antAveRSSI[i] = 0;
}
//MAC Setting
value32 = ODM_GetMACReg(pDM_Odm, 0x4c, bMaskDWord);
ODM_SetMACReg(pDM_Odm, 0x4c, bMaskDWord, value32|(BIT23|BIT25)); //Reg4C[25]=1, Reg4C[23]=1 for pin output
value32 = ODM_GetMACReg(pDM_Odm, 0x7B4, bMaskDWord);
ODM_SetMACReg(pDM_Odm, 0x7b4, bMaskDWord, value32|(BIT16|BIT17)); //Reg7B4[16]=1 enable antenna training, Reg7B4[17]=1 enable A2 match
//value32 = PlatformEFIORead4Byte(Adapter, 0x7B4);
//PlatformEFIOWrite4Byte(Adapter, 0x7b4, value32|BIT18); //append MACID in reponse packet
//Match MAC ADDR
ODM_SetMACReg(pDM_Odm, 0x7b4, 0xFFFF, 0);
ODM_SetMACReg(pDM_Odm, 0x7b0, bMaskDWord, 0);
ODM_SetBBReg(pDM_Odm, 0x870 , BIT9|BIT8, 0);//Reg870[8]=1'b0, Reg870[9]=1'b0 //antsel antselb by HW
ODM_SetBBReg(pDM_Odm, 0x864 , BIT10, 0); //Reg864[10]=1'b0 //antsel2 by HW
ODM_SetBBReg(pDM_Odm, 0xb2c , BIT22, 0); //Regb2c[22]=1'b0 //disable CS/CG switch
ODM_SetBBReg(pDM_Odm, 0xb2c , BIT31, 0); //Regb2c[31]=1'b1 //output at CS only
ODM_SetBBReg(pDM_Odm, 0xca4 , bMaskDWord, 0x000000a0);
//antenna mapping table
if(pDM_Odm->fat_comb_a == 2)
{
if(!pDM_Odm->bIsMPChip) //testchip
{
ODM_SetBBReg(pDM_Odm, 0x858 , BIT10|BIT9|BIT8, 1); //Reg858[10:8]=3'b001
ODM_SetBBReg(pDM_Odm, 0x858 , BIT13|BIT12|BIT11, 2); //Reg858[13:11]=3'b010
}
else //MPchip
{
ODM_SetBBReg(pDM_Odm, 0x914 , bMaskByte0, 1);
ODM_SetBBReg(pDM_Odm, 0x914 , bMaskByte1, 2);
}
}
else
{
if(!pDM_Odm->bIsMPChip) //testchip
{
ODM_SetBBReg(pDM_Odm, 0x858 , BIT10|BIT9|BIT8, 0); //Reg858[10:8]=3'b000
ODM_SetBBReg(pDM_Odm, 0x858 , BIT13|BIT12|BIT11, 1); //Reg858[13:11]=3'b001
ODM_SetBBReg(pDM_Odm, 0x878 , BIT16, 0);
ODM_SetBBReg(pDM_Odm, 0x858 , BIT15|BIT14, 2); //(Reg878[0],Reg858[14:15])=3'b010
ODM_SetBBReg(pDM_Odm, 0x878 , BIT19|BIT18|BIT17, 3);//Reg878[3:1]=3b'011
ODM_SetBBReg(pDM_Odm, 0x878 , BIT22|BIT21|BIT20, 4);//Reg878[6:4]=3b'100
ODM_SetBBReg(pDM_Odm, 0x878 , BIT25|BIT24|BIT23, 5);//Reg878[9:7]=3b'101
ODM_SetBBReg(pDM_Odm, 0x878 , BIT28|BIT27|BIT26, 6);//Reg878[12:10]=3b'110
ODM_SetBBReg(pDM_Odm, 0x878 , BIT31|BIT30|BIT29, 7);//Reg878[15:13]=3b'111
}
else //MPchip
{
ODM_SetBBReg(pDM_Odm, 0x914 , bMaskByte0, 4); // 0: 3b'000
ODM_SetBBReg(pDM_Odm, 0x914 , bMaskByte1, 2); // 1: 3b'001
ODM_SetBBReg(pDM_Odm, 0x914 , bMaskByte2, 0); // 2: 3b'010
ODM_SetBBReg(pDM_Odm, 0x914 , bMaskByte3, 1); // 3: 3b'011
ODM_SetBBReg(pDM_Odm, 0x918 , bMaskByte0, 3); // 4: 3b'100
ODM_SetBBReg(pDM_Odm, 0x918 , bMaskByte1, 5); // 5: 3b'101
ODM_SetBBReg(pDM_Odm, 0x918 , bMaskByte2, 6); // 6: 3b'110
ODM_SetBBReg(pDM_Odm, 0x918 , bMaskByte3, 255); // 7: 3b'111
}
}
//Default Ant Setting when no fast training
ODM_SetBBReg(pDM_Odm, 0x864 , BIT5|BIT4|BIT3, 0); //Default RX
ODM_SetBBReg(pDM_Odm, 0x864 , BIT8|BIT7|BIT6, 1); //Optional RX
ODM_SetBBReg(pDM_Odm, 0x860 , BIT14|BIT13|BIT12, 0);//Default TX
//Enter Traing state
ODM_SetBBReg(pDM_Odm, 0x864 , BIT2|BIT1|BIT0, (pDM_Odm->fat_comb_a-1)); //Reg864[2:0]=3'd6 //ant combination=reg864[2:0]+1
//SW Control
//PHY_SetBBReg(Adapter, 0x864 , BIT10, 1);
//PHY_SetBBReg(Adapter, 0x870 , BIT9, 1);
//PHY_SetBBReg(Adapter, 0x870 , BIT8, 1);
//PHY_SetBBReg(Adapter, 0x864 , BIT11, 1);
//PHY_SetBBReg(Adapter, 0x860 , BIT9, 0);
//PHY_SetBBReg(Adapter, 0x860 , BIT8, 0);
}
#endif
#endif //#if (RTL8188E_SUPPORT == 1)
#if (RTL8192E_SUPPORT == 1)
VOID
odm_RX_HWAntDiv_Init_92E(
IN PVOID pDM_VOID
)
{
PDM_ODM_T pDM_Odm = (PDM_ODM_T)pDM_VOID;
pFAT_T pDM_FatTable = &pDM_Odm->DM_FatTable;
if(pDM_Odm->mp_mode == TRUE)
{
//pDM_Odm->AntDivType = CGCS_RX_SW_ANTDIV;
odm_AntDiv_on_off(pDM_Odm, ANTDIV_OFF);
ODM_SetBBReg(pDM_Odm, 0xc50 , BIT8, 0); //r_rxdiv_enable_anta Regc50[8]=1'b0 0: control by c50[9]
ODM_SetBBReg(pDM_Odm, 0xc50 , BIT9, 1); // 1:CG, 0:CS
return;
}
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("***8192E AntDiv_Init => AntDivType=[CGCS_RX_HW_ANTDIV]\n"));
//Pin Settings
ODM_SetBBReg(pDM_Odm, 0x870 , BIT8, 0);//Reg870[8]=1'b0, // "antsel" is controled by HWs
ODM_SetBBReg(pDM_Odm, 0xc50 , BIT8, 1); //Regc50[8]=1'b1 //" CS/CG switching" is controled by HWs
//Mapping table
ODM_SetBBReg(pDM_Odm, 0x914 , 0xFFFF, 0x0100); //antenna mapping table
//OFDM Settings
ODM_SetBBReg(pDM_Odm, 0xca4 , 0x7FF, 0xA0); //thershold
ODM_SetBBReg(pDM_Odm, 0xca4 , 0x7FF000, 0x0); //bias
//CCK Settings
ODM_SetBBReg(pDM_Odm, 0xa04 , 0xF000000, 0); //Select which path to receive for CCK_1 & CCK_2
ODM_SetBBReg(pDM_Odm, 0xb34 , BIT30, 0); //(92E) ANTSEL_CCK_opt = r_en_antsel_cck? ANTSEL_CCK: 1'b0
ODM_SetBBReg(pDM_Odm, 0xa74 , BIT7, 1); //Fix CCK PHY status report issue
ODM_SetBBReg(pDM_Odm, 0xa0c , BIT4, 1); //CCK complete HW AntDiv within 64 samples
#ifdef ODM_EVM_ENHANCE_ANTDIV
//EVM enhance AntDiv method init----------------------------------------------------------------------
pDM_FatTable->EVM_method_enable=0;
pDM_FatTable->FAT_State = NORMAL_STATE_MIAN;
pDM_Odm->antdiv_intvl = 0x64;
ODM_SetBBReg(pDM_Odm, 0x910 , 0x3f, 0xf );
pDM_Odm->antdiv_evm_en=1;
//pDM_Odm->antdiv_period=1;
#endif
}
VOID
odm_TRX_HWAntDiv_Init_92E(
IN PVOID pDM_VOID
)
{
PDM_ODM_T pDM_Odm = (PDM_ODM_T)pDM_VOID;
pFAT_T pDM_FatTable = &pDM_Odm->DM_FatTable;
if(pDM_Odm->mp_mode == TRUE)
{
//pDM_Odm->AntDivType = CGCS_RX_SW_ANTDIV;
odm_AntDiv_on_off(pDM_Odm, ANTDIV_OFF);
ODM_SetBBReg(pDM_Odm, 0xc50 , BIT8, 0); //r_rxdiv_enable_anta Regc50[8]=1'b0 0: control by c50[9]
ODM_SetBBReg(pDM_Odm, 0xc50 , BIT9, 1); // 1:CG, 0:CS
return;
}
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("***8192E AntDiv_Init => AntDivType=[ Only for DIR605, CG_TRX_HW_ANTDIV]\n"));
//3 --RFE pin setting---------
//[MAC]
ODM_SetMACReg(pDM_Odm, 0x38, BIT11, 1); //DBG PAD Driving control (GPIO 8)
ODM_SetMACReg(pDM_Odm, 0x4c, BIT23, 0); //path-A , RFE_CTRL_3
ODM_SetMACReg(pDM_Odm, 0x4c, BIT29, 1); //path-A , RFE_CTRL_8
//[BB]
ODM_SetBBReg(pDM_Odm, 0x944 , BIT3, 1); //RFE_buffer
ODM_SetBBReg(pDM_Odm, 0x944 , BIT8, 1);
ODM_SetBBReg(pDM_Odm, 0x940 , BIT7|BIT6, 0x0); // r_rfe_path_sel_ (RFE_CTRL_3)
ODM_SetBBReg(pDM_Odm, 0x940 , BIT17|BIT16, 0x0); // r_rfe_path_sel_ (RFE_CTRL_8)
ODM_SetBBReg(pDM_Odm, 0x944 , BIT31, 0); //RFE_buffer
ODM_SetBBReg(pDM_Odm, 0x92C , BIT3, 0); //rfe_inv (RFE_CTRL_3)
ODM_SetBBReg(pDM_Odm, 0x92C , BIT8, 1); //rfe_inv (RFE_CTRL_8)
ODM_SetBBReg(pDM_Odm, 0x930 , 0xF000, 0x8); //path-A , RFE_CTRL_3
ODM_SetBBReg(pDM_Odm, 0x934 , 0xF, 0x8); //path-A , RFE_CTRL_8
//3 -------------------------
//Pin Settings
ODM_SetBBReg(pDM_Odm, 0xC50 , BIT8, 0); //path-A //disable CS/CG switch
/* Let it follows PHY_REG for bit9 setting
if(pDM_Odm->priv->pshare->rf_ft_var.use_ext_pa || pDM_Odm->priv->pshare->rf_ft_var.use_ext_lna)
ODM_SetBBReg(pDM_Odm, 0xC50 , BIT9, 1);//path-A //output at CS
else
ODM_SetBBReg(pDM_Odm, 0xC50 , BIT9, 0); //path-A //output at CG ->normal power
*/
ODM_SetBBReg(pDM_Odm, 0x870 , BIT9|BIT8, 0); //path-A //antsel antselb by HW
ODM_SetBBReg(pDM_Odm, 0xB38 , BIT10, 0); //path-A //antsel2 by HW
//Mapping table
ODM_SetBBReg(pDM_Odm, 0x914 , 0xFFFF, 0x0100); //antenna mapping table
//OFDM Settings
ODM_SetBBReg(pDM_Odm, 0xca4 , 0x7FF, 0xA0); //thershold
ODM_SetBBReg(pDM_Odm, 0xca4 , 0x7FF000, 0x0); //bias
//CCK Settings
ODM_SetBBReg(pDM_Odm, 0xa04 , 0xF000000, 0); //Select which path to receive for CCK_1 & CCK_2
ODM_SetBBReg(pDM_Odm, 0xb34 , BIT30, 0); //(92E) ANTSEL_CCK_opt = r_en_antsel_cck? ANTSEL_CCK: 1'b0
ODM_SetBBReg(pDM_Odm, 0xa74 , BIT7, 1); //Fix CCK PHY status report issue
ODM_SetBBReg(pDM_Odm, 0xa0c , BIT4, 1); //CCK complete HW AntDiv within 64 samples
//Timming issue
ODM_SetBBReg(pDM_Odm, 0xE20 , BIT23|BIT22|BIT21|BIT20, 8); //keep antidx after tx for ACK ( unit x 32 mu sec)
#ifdef ODM_EVM_ENHANCE_ANTDIV
//EVM enhance AntDiv method init----------------------------------------------------------------------
pDM_FatTable->EVM_method_enable=0;
pDM_FatTable->FAT_State = NORMAL_STATE_MIAN;
pDM_Odm->antdiv_intvl = 0x64;
ODM_SetBBReg(pDM_Odm, 0x910 , 0x3f, 0xf );
pDM_Odm->antdiv_evm_en=1;
//pDM_Odm->antdiv_period=1;
#endif
}
#if( defined(CONFIG_5G_CG_SMART_ANT_DIVERSITY) ) ||( defined(CONFIG_2G_CG_SMART_ANT_DIVERSITY) )
VOID
odm_Smart_HWAntDiv_Init_92E(
IN PVOID pDM_VOID
)
{
PDM_ODM_T pDM_Odm = (PDM_ODM_T)pDM_VOID;
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("***8192E AntDiv_Init => AntDivType=[CG_TRX_SMART_ANTDIV]\n"));
}
#endif
#endif //#if (RTL8192E_SUPPORT == 1)
#if (RTL8723B_SUPPORT == 1)
VOID
odm_TRX_HWAntDiv_Init_8723B(
IN PVOID pDM_VOID
)
{
PDM_ODM_T pDM_Odm = (PDM_ODM_T)pDM_VOID;
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("***8723B AntDiv_Init => AntDivType=[CG_TRX_HW_ANTDIV(DPDT)]\n"));
//Mapping Table
ODM_SetBBReg(pDM_Odm, 0x914 , bMaskByte0, 0);
ODM_SetBBReg(pDM_Odm, 0x914 , bMaskByte1, 1);
//OFDM HW AntDiv Parameters
ODM_SetBBReg(pDM_Odm, 0xCA4 , 0x7FF, 0xa0); //thershold
ODM_SetBBReg(pDM_Odm, 0xCA4 , 0x7FF000, 0x00); //bias
//CCK HW AntDiv Parameters
ODM_SetBBReg(pDM_Odm, 0xA74 , BIT7, 1); //patch for clk from 88M to 80M
ODM_SetBBReg(pDM_Odm, 0xA0C , BIT4, 1); //do 64 samples
//BT Coexistence
ODM_SetBBReg(pDM_Odm, 0x864, BIT12, 0); //keep antsel_map when GNT_BT = 1
ODM_SetBBReg(pDM_Odm, 0x874 , BIT23, 0); //Disable hw antsw & fast_train.antsw when GNT_BT=1
//Output Pin Settings
ODM_SetBBReg(pDM_Odm, 0x870 , BIT8, 0); //
ODM_SetBBReg(pDM_Odm, 0x948 , BIT6, 0); //WL_BB_SEL_BTG_TRXG_anta, (1: HW CTRL 0: SW CTRL)
ODM_SetBBReg(pDM_Odm, 0x948 , BIT7, 0);
ODM_SetMACReg(pDM_Odm, 0x40 , BIT3, 1);
ODM_SetMACReg(pDM_Odm, 0x38 , BIT11, 1);
ODM_SetMACReg(pDM_Odm, 0x4C , BIT24|BIT23, 2); //select DPDT_P and DPDT_N as output pin
ODM_SetBBReg(pDM_Odm, 0x944 , BIT0|BIT1, 3); //in/out
ODM_SetBBReg(pDM_Odm, 0x944 , BIT31, 0); //
ODM_SetBBReg(pDM_Odm, 0x92C , BIT1, 0); //DPDT_P non-inverse
ODM_SetBBReg(pDM_Odm, 0x92C , BIT0, 1); //DPDT_N inverse
ODM_SetBBReg(pDM_Odm, 0x930 , 0xF0, 8); // DPDT_P = ANTSEL[0]
ODM_SetBBReg(pDM_Odm, 0x930 , 0xF, 8); // DPDT_N = ANTSEL[0]
//Timming issue
ODM_SetBBReg(pDM_Odm, 0xE20 , BIT23|BIT22|BIT21|BIT20, 8); //keep antidx after tx for ACK ( unit x 32 mu sec)
//2 [--For HW Bug Setting]
if(pDM_Odm->AntType == ODM_AUTO_ANT)
ODM_SetBBReg(pDM_Odm, 0xA00 , BIT15, 0); //CCK AntDiv function block enable
}
VOID
odm_S0S1_SWAntDiv_Init_8723B(
IN PVOID pDM_VOID
)
{
PDM_ODM_T pDM_Odm = (PDM_ODM_T)pDM_VOID;
pSWAT_T pDM_SWAT_Table = &pDM_Odm->DM_SWAT_Table;
pFAT_T pDM_FatTable = &pDM_Odm->DM_FatTable;
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("***8723B AntDiv_Init => AntDivType=[ S0S1_SW_AntDiv] \n"));
//Mapping Table
ODM_SetBBReg(pDM_Odm, 0x914 , bMaskByte0, 0);
ODM_SetBBReg(pDM_Odm, 0x914 , bMaskByte1, 1);
//Output Pin Settings
//ODM_SetBBReg(pDM_Odm, 0x948 , BIT6, 0x1);
ODM_SetBBReg(pDM_Odm, 0x870 , BIT9|BIT8, 0);
pDM_FatTable->bBecomeLinked =FALSE;
pDM_SWAT_Table->try_flag = 0xff;
pDM_SWAT_Table->Double_chk_flag = 0;
pDM_SWAT_Table->TrafficLoad = TRAFFIC_LOW;
//Timming issue
ODM_SetBBReg(pDM_Odm, 0xE20 , BIT23|BIT22|BIT21|BIT20, 8); //keep antidx after tx for ACK ( unit x 32 mu sec)
//2 [--For HW Bug Setting]
ODM_SetBBReg(pDM_Odm, 0x80C , BIT21, 0); //TX Ant by Reg
}
VOID
odm_S0S1_SWAntDiv_Reset_8723B(
IN PVOID pDM_VOID
)
{
PDM_ODM_T pDM_Odm = (PDM_ODM_T)pDM_VOID;
pSWAT_T pDM_SWAT_Table = &pDM_Odm->DM_SWAT_Table;
pFAT_T pDM_FatTable = &pDM_Odm->DM_FatTable;
pDM_FatTable->bBecomeLinked =FALSE;
pDM_SWAT_Table->try_flag = 0xff;
pDM_SWAT_Table->Double_chk_flag = 0;
pDM_SWAT_Table->TrafficLoad = TRAFFIC_LOW;
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("odm_S0S1_SWAntDiv_Reset_8723B(): pDM_FatTable->bBecomeLinked = %d\n", pDM_FatTable->bBecomeLinked));
}
VOID
ODM_UpdateRxIdleAnt_8723B(
IN PVOID pDM_VOID,
IN u1Byte Ant,
IN u4Byte DefaultAnt,
IN u4Byte OptionalAnt
)
{
PDM_ODM_T pDM_Odm = (PDM_ODM_T)pDM_VOID;
pFAT_T pDM_FatTable = &pDM_Odm->DM_FatTable;
PADAPTER pAdapter = pDM_Odm->Adapter;
HAL_DATA_TYPE *pHalData = GET_HAL_DATA(pAdapter);
u1Byte count=0;
u1Byte u1Temp;
u1Byte H2C_Parameter;
if(!pDM_Odm->bLinked)
{
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("[ Update Rx-Idle-Ant ] 8723B: Fail to set RX antenna due to no link\n"));
return;
}
#if 0
// Send H2C command to FW
// Enable wifi calibration
H2C_Parameter = TRUE;
ODM_FillH2CCmd(pDM_Odm, ODM_H2C_WIFI_CALIBRATION, 1, &H2C_Parameter);
// Check if H2C command sucess or not (0x1e6)
u1Temp = ODM_Read1Byte(pDM_Odm, 0x1e6);
while((u1Temp != 0x1) && (count < 100))
{
ODM_delay_us(10);
u1Temp = ODM_Read1Byte(pDM_Odm, 0x1e6);
count++;
}
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("[ Update Rx-Idle-Ant ] 8723B: H2C command status = %d, count = %d\n", u1Temp, count));
if(u1Temp == 0x1)
{
// Check if BT is doing IQK (0x1e7)
count = 0;
u1Temp = ODM_Read1Byte(pDM_Odm, 0x1e7);
while((!(u1Temp & BIT0)) && (count < 100))
{
ODM_delay_us(50);
u1Temp = ODM_Read1Byte(pDM_Odm, 0x1e7);
count++;
}
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("[ Update Rx-Idle-Ant ] 8723B: BT IQK status = %d, count = %d\n", u1Temp, count));
if(u1Temp & BIT0)
{
ODM_SetBBReg(pDM_Odm, 0x948 , BIT6, 0x1);
ODM_SetBBReg(pDM_Odm, 0x948 , BIT9, DefaultAnt);
ODM_SetBBReg(pDM_Odm, 0x864 , BIT5|BIT4|BIT3, DefaultAnt); //Default RX
ODM_SetBBReg(pDM_Odm, 0x864 , BIT8|BIT7|BIT6, OptionalAnt); //Optional RX
ODM_SetBBReg(pDM_Odm, 0x860, BIT14|BIT13|BIT12, DefaultAnt); //Default TX
pDM_FatTable->RxIdleAnt = Ant;
// Set TX AGC by S0/S1
// Need to consider Linux driver
#if (DM_ODM_SUPPORT_TYPE == ODM_WIN)
pAdapter->HalFunc.SetTxPowerLevelHandler(pAdapter, pHalData->CurrentChannel);
#elif(DM_ODM_SUPPORT_TYPE == ODM_CE)
rtw_hal_set_tx_power_level(pAdapter, pHalData->CurrentChannel);
#endif
// Set IQC by S0/S1
ODM_SetIQCbyRFpath(pDM_Odm,DefaultAnt);
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("[ Update Rx-Idle-Ant ] 8723B: Sucess to set RX antenna\n"));
}
else
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("[ Update Rx-Idle-Ant ] 8723B: Fail to set RX antenna due to BT IQK\n"));
}
else
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("[ Update Rx-Idle-Ant ] 8723B: Fail to set RX antenna due to H2C command fail\n"));
// Send H2C command to FW
// Disable wifi calibration
H2C_Parameter = FALSE;
ODM_FillH2CCmd(pDM_Odm, ODM_H2C_WIFI_CALIBRATION, 1, &H2C_Parameter);
#else
ODM_SetBBReg(pDM_Odm, 0x948 , BIT6, 0x1);
ODM_SetBBReg(pDM_Odm, 0x948 , BIT9, DefaultAnt);
ODM_SetBBReg(pDM_Odm, 0x864 , BIT5|BIT4|BIT3, DefaultAnt); /*Default RX*/
ODM_SetBBReg(pDM_Odm, 0x864 , BIT8|BIT7|BIT6, OptionalAnt); /*Optional RX*/
ODM_SetBBReg(pDM_Odm, 0x860, BIT14|BIT13|BIT12, DefaultAnt); /*Default TX*/
pDM_FatTable->RxIdleAnt = Ant;
/* Set TX AGC by S0/S1 */
/* Need to consider Linux driver */
#if (DM_ODM_SUPPORT_TYPE == ODM_WIN)
pAdapter->HalFunc.SetTxPowerLevelHandler(pAdapter, pHalData->CurrentChannel);
#elif(DM_ODM_SUPPORT_TYPE == ODM_CE)
rtw_hal_set_tx_power_level(pAdapter, pHalData->CurrentChannel);
#endif
/* Set IQC by S0/S1 */
ODM_SetIQCbyRFpath(pDM_Odm, DefaultAnt);
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("[ Update Rx-Idle-Ant ] 8723B: Success to set RX antenna\n"));
#endif
}
BOOLEAN
phydm_IsBtEnable_8723b(
IN PVOID pDM_VOID
)
{
PDM_ODM_T pDM_Odm = (PDM_ODM_T)pDM_VOID;
u4Byte bt_state;
/*u4Byte reg75;*/
/*reg75 = ODM_GetBBReg(pDM_Odm, 0x74 , BIT8);*/
/*ODM_SetBBReg(pDM_Odm, 0x74 , BIT8, 0x0);*/
ODM_SetBBReg(pDM_Odm, 0xa0 , BIT24|BIT25|BIT26, 0x5);
bt_state = ODM_GetBBReg(pDM_Odm, 0xa0 , (BIT3|BIT2|BIT1|BIT0));
/*ODM_SetBBReg(pDM_Odm, 0x74 , BIT8, reg75);*/
if ((bt_state == 4) || (bt_state == 7) || (bt_state == 9) || (bt_state == 13))
return TRUE;
else
return FALSE;
}
#else /*#if (RTL8723B_SUPPORT == 1)*/
VOID
ODM_UpdateRxIdleAnt_8723B(
IN PVOID pDM_VOID,
IN u1Byte Ant,
IN u4Byte DefaultAnt,
IN u4Byte OptionalAnt
){}
#endif //#if (RTL8723B_SUPPORT == 1)
#if (RTL8821A_SUPPORT == 1)
#ifdef CONFIG_HL_SMART_ANTENNA_TYPE1
VOID
phydm_hl_smart_ant_type1_init_8821a(
IN PVOID pDM_VOID
)
{
PDM_ODM_T pDM_Odm = (PDM_ODM_T)pDM_VOID;
pSAT_T pdm_sat_table = &(pDM_Odm->dm_sat_table);
pFAT_T pDM_FatTable = &pDM_Odm->DM_FatTable;
u4Byte value32;
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("***8821A SmartAnt_Init => AntDivType=[Hong-Lin Smart Ant Type1]\n"));
/*----------------------------------------
GPIO 2-3 for Beam control
reg0x66[2]=0
reg0x44[27:26] = 0
reg0x44[23:16] //enable_output for P_GPIO[7:0]
reg0x44[15:8] //output_value for P_GPIO[7:0]
reg0x40[1:0] = 0 //GPIO function
------------------------------------------*/
/*GPIO Setting*/
ODM_SetMACReg(pDM_Odm, 0x64 , BIT18, 0);
ODM_SetMACReg(pDM_Odm, 0x44 , BIT27|BIT26, 0);
ODM_SetMACReg(pDM_Odm, 0x44 , BIT19|BIT18, 0x3); /*enable_output for P_GPIO[3:2]*/
/*ODM_SetMACReg(pDM_Odm, 0x44 , BIT11|BIT10, 0);*/ /*output value*/
ODM_SetMACReg(pDM_Odm, 0x40 , BIT1|BIT0, 0); /*GPIO function*/
/*Hong_lin smart antenna HW Setting*/
pdm_sat_table->data_codeword_bit_num = 24;/*max=32*/
pdm_sat_table->beam_patten_num_each_ant = 4;
#if DEV_BUS_TYPE == RT_SDIO_INTERFACE
pdm_sat_table->latch_time = 100; /*mu sec*/
#elif DEV_BUS_TYPE == RT_USB_INTERFACE
pdm_sat_table->latch_time = 100; /*mu sec*/
#endif
pdm_sat_table->pkt_skip_statistic_en = 0;
pdm_sat_table->ant_num = 2;/*max=8*/
pdm_sat_table->fix_beam_pattern_en = 0;
pdm_sat_table->decision_holding_period = 0;
/*beam training setting*/
pdm_sat_table->pkt_counter = 0;
pdm_sat_table->per_beam_training_pkt_num = 10;
/*set default beam*/
pdm_sat_table->fast_training_beam_num = 0;
pdm_sat_table->pre_fast_training_beam_num = pdm_sat_table->fast_training_beam_num;
phydm_set_all_ant_same_beam_num(pDM_Odm);
pDM_FatTable->FAT_State = FAT_BEFORE_LINK_STATE;
/*[BB] FAT Setting*/
ODM_SetBBReg(pDM_Odm, 0xc08 , BIT18|BIT17|BIT16, pdm_sat_table->ant_num);
ODM_SetBBReg(pDM_Odm, 0xc08 , BIT31, 0); /*increase ant num every FAT period 0:+1, 1+2*/
ODM_SetBBReg(pDM_Odm, 0x8c4 , BIT2|BIT1, 1); /*change cca antenna timming threshold if no CCA occurred: 0:200ms / 1:100ms / 2:no use / 3: 300*/
ODM_SetBBReg(pDM_Odm, 0x8c4 , BIT0, 1); /*FAT_watchdog_en*/
value32 = ODM_GetMACReg(pDM_Odm, 0x7B4, bMaskDWord);
ODM_SetMACReg(pDM_Odm, 0x7b4, bMaskDWord, value32|(BIT16|BIT17)); /*Reg7B4[16]=1 enable antenna training */
/*Reg7B4[17]=1 enable match MAC Addr*/
ODM_SetMACReg(pDM_Odm, 0x7b4, 0xFFFF, 0);/*Match MAC ADDR*/
ODM_SetMACReg(pDM_Odm, 0x7b0, bMaskDWord, 0);
}
#endif
VOID
odm_TRX_HWAntDiv_Init_8821A(
IN PVOID pDM_VOID
)
{
PDM_ODM_T pDM_Odm = (PDM_ODM_T)pDM_VOID;
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("***8821A AntDiv_Init => AntDivType=[ CG_TRX_HW_ANTDIV (DPDT)] \n"));
//Output Pin Settings
ODM_SetMACReg(pDM_Odm, 0x4C , BIT25, 0);
ODM_SetMACReg(pDM_Odm, 0x64 , BIT29, 1); //PAPE by WLAN control
ODM_SetMACReg(pDM_Odm, 0x64 , BIT28, 1); //LNAON by WLAN control
ODM_SetBBReg(pDM_Odm, 0xCB0 , bMaskDWord, 0x77775745);
ODM_SetBBReg(pDM_Odm, 0xCB8 , BIT16, 0);
ODM_SetMACReg(pDM_Odm, 0x4C , BIT23, 0); //select DPDT_P and DPDT_N as output pin
ODM_SetMACReg(pDM_Odm, 0x4C , BIT24, 1); //by WLAN control
ODM_SetBBReg(pDM_Odm, 0xCB4 , 0xF, 8); // DPDT_P = ANTSEL[0]
ODM_SetBBReg(pDM_Odm, 0xCB4 , 0xF0, 8); // DPDT_N = ANTSEL[0]
ODM_SetBBReg(pDM_Odm, 0xCB4 , BIT29, 0); //DPDT_P non-inverse
ODM_SetBBReg(pDM_Odm, 0xCB4 , BIT28, 1); //DPDT_N inverse
//Mapping Table
ODM_SetBBReg(pDM_Odm, 0xCA4 , bMaskByte0, 0);
ODM_SetBBReg(pDM_Odm, 0xCA4 , bMaskByte1, 1);
//OFDM HW AntDiv Parameters
ODM_SetBBReg(pDM_Odm, 0x8D4 , 0x7FF, 0xA0); //thershold
ODM_SetBBReg(pDM_Odm, 0x8D4 , 0x7FF000, 0x10); //bias
//CCK HW AntDiv Parameters
ODM_SetBBReg(pDM_Odm, 0xA74 , BIT7, 1); //patch for clk from 88M to 80M
ODM_SetBBReg(pDM_Odm, 0xA0C , BIT4, 1); //do 64 samples
ODM_SetBBReg(pDM_Odm, 0x800 , BIT25, 0); //ANTSEL_CCK sent to the smart_antenna circuit
ODM_SetBBReg(pDM_Odm, 0xA00 , BIT15, 0); //CCK AntDiv function block enable
//BT Coexistence
ODM_SetBBReg(pDM_Odm, 0xCAC , BIT9, 1); //keep antsel_map when GNT_BT = 1
ODM_SetBBReg(pDM_Odm, 0x804 , BIT4, 1); //Disable hw antsw & fast_train.antsw when GNT_BT=1
//Timming issue
ODM_SetBBReg(pDM_Odm, 0x818 , BIT23|BIT22|BIT21|BIT20, 8); //keep antidx after tx for ACK ( unit x 32 mu sec)
ODM_SetBBReg(pDM_Odm, 0x8CC , BIT20|BIT19|BIT18, 3); //settling time of antdiv by RF LNA = 100ns
//response TX ant by RX ant
ODM_SetMACReg(pDM_Odm, 0x668 , BIT3, 1);
}
VOID
odm_S0S1_SWAntDiv_Init_8821A(
IN PVOID pDM_VOID
)
{
PDM_ODM_T pDM_Odm = (PDM_ODM_T)pDM_VOID;
pSWAT_T pDM_SWAT_Table = &pDM_Odm->DM_SWAT_Table;
pFAT_T pDM_FatTable = &pDM_Odm->DM_FatTable;
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("***8821A AntDiv_Init => AntDivType=[ S0S1_SW_AntDiv] \n"));
//Output Pin Settings
ODM_SetMACReg(pDM_Odm, 0x4C , BIT25, 0);
ODM_SetMACReg(pDM_Odm, 0x64 , BIT29, 1); //PAPE by WLAN control
ODM_SetMACReg(pDM_Odm, 0x64 , BIT28, 1); //LNAON by WLAN control
ODM_SetBBReg(pDM_Odm, 0xCB0 , bMaskDWord, 0x77775745);
ODM_SetBBReg(pDM_Odm, 0xCB8 , BIT16, 0);
ODM_SetMACReg(pDM_Odm, 0x4C , BIT23, 0); //select DPDT_P and DPDT_N as output pin
ODM_SetMACReg(pDM_Odm, 0x4C , BIT24, 1); //by WLAN control
ODM_SetBBReg(pDM_Odm, 0xCB4 , 0xF, 8); // DPDT_P = ANTSEL[0]
ODM_SetBBReg(pDM_Odm, 0xCB4 , 0xF0, 8); // DPDT_N = ANTSEL[0]
ODM_SetBBReg(pDM_Odm, 0xCB4 , BIT29, 0); //DPDT_P non-inverse
ODM_SetBBReg(pDM_Odm, 0xCB4 , BIT28, 1); //DPDT_N inverse
//Mapping Table
ODM_SetBBReg(pDM_Odm, 0xCA4 , bMaskByte0, 0);
ODM_SetBBReg(pDM_Odm, 0xCA4 , bMaskByte1, 1);
//OFDM HW AntDiv Parameters
ODM_SetBBReg(pDM_Odm, 0x8D4 , 0x7FF, 0xA0); //thershold
ODM_SetBBReg(pDM_Odm, 0x8D4 , 0x7FF000, 0x10); //bias
//CCK HW AntDiv Parameters
ODM_SetBBReg(pDM_Odm, 0xA74 , BIT7, 1); //patch for clk from 88M to 80M
ODM_SetBBReg(pDM_Odm, 0xA0C , BIT4, 1); //do 64 samples
ODM_SetBBReg(pDM_Odm, 0x800 , BIT25, 0); //ANTSEL_CCK sent to the smart_antenna circuit
ODM_SetBBReg(pDM_Odm, 0xA00 , BIT15, 0); //CCK AntDiv function block enable
//BT Coexistence
ODM_SetBBReg(pDM_Odm, 0xCAC , BIT9, 1); //keep antsel_map when GNT_BT = 1
ODM_SetBBReg(pDM_Odm, 0x804 , BIT4, 1); //Disable hw antsw & fast_train.antsw when GNT_BT=1
//Timming issue
ODM_SetBBReg(pDM_Odm, 0x818 , BIT23|BIT22|BIT21|BIT20, 8); //keep antidx after tx for ACK ( unit x 32 mu sec)
ODM_SetBBReg(pDM_Odm, 0x8CC , BIT20|BIT19|BIT18, 3); //settling time of antdiv by RF LNA = 100ns
//response TX ant by RX ant
ODM_SetMACReg(pDM_Odm, 0x668 , BIT3, 1);
ODM_SetBBReg(pDM_Odm, 0x900 , BIT18, 0);
pDM_SWAT_Table->try_flag = 0xff;
pDM_SWAT_Table->Double_chk_flag = 0;
pDM_SWAT_Table->TrafficLoad = TRAFFIC_LOW;
pDM_SWAT_Table->CurAntenna = MAIN_ANT;
pDM_SWAT_Table->PreAntenna = MAIN_ANT;
pDM_SWAT_Table->SWAS_NoLink_State = 0;
}
#endif //#if (RTL8821A_SUPPORT == 1)
#if (RTL8881A_SUPPORT == 1)
VOID
odm_RX_HWAntDiv_Init_8881A(
IN PVOID pDM_VOID
)
{
PDM_ODM_T pDM_Odm = (PDM_ODM_T)pDM_VOID;
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("***8881A AntDiv_Init => AntDivType=[ CGCS_RX_HW_ANTDIV] \n"));
}
VOID
odm_TRX_HWAntDiv_Init_8881A(
IN PVOID pDM_VOID
)
{
PDM_ODM_T pDM_Odm = (PDM_ODM_T)pDM_VOID;
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("***8881A AntDiv_Init => AntDivType=[ CG_TRX_HW_ANTDIV (SPDT)] \n"));
//Output Pin Settings
// [SPDT related]
ODM_SetMACReg(pDM_Odm, 0x4C , BIT25, 0);
ODM_SetMACReg(pDM_Odm, 0x4C , BIT26, 0);
ODM_SetBBReg(pDM_Odm, 0xCB4 , BIT31, 0); //delay buffer
ODM_SetBBReg(pDM_Odm, 0xCB4 , BIT22, 0);
ODM_SetBBReg(pDM_Odm, 0xCB4 , BIT24, 1);
ODM_SetBBReg(pDM_Odm, 0xCB0 , 0xF00, 8); // DPDT_P = ANTSEL[0]
ODM_SetBBReg(pDM_Odm, 0xCB0 , 0xF0000, 8); // DPDT_N = ANTSEL[0]
//Mapping Table
ODM_SetBBReg(pDM_Odm, 0xCA4 , bMaskByte0, 0);
ODM_SetBBReg(pDM_Odm, 0xCA4 , bMaskByte1, 1);
//OFDM HW AntDiv Parameters
ODM_SetBBReg(pDM_Odm, 0x8D4 , 0x7FF, 0xA0); //thershold
ODM_SetBBReg(pDM_Odm, 0x8D4 , 0x7FF000, 0x0); //bias
ODM_SetBBReg(pDM_Odm, 0x8CC , BIT20|BIT19|BIT18, 3); //settling time of antdiv by RF LNA = 100ns
//CCK HW AntDiv Parameters
ODM_SetBBReg(pDM_Odm, 0xA74 , BIT7, 1); //patch for clk from 88M to 80M
ODM_SetBBReg(pDM_Odm, 0xA0C , BIT4, 1); //do 64 samples
//Timming issue
ODM_SetBBReg(pDM_Odm, 0x818 , BIT23|BIT22|BIT21|BIT20, 8); //keep antidx after tx for ACK ( unit x 32 mu sec)
//2 [--For HW Bug Setting]
ODM_SetBBReg(pDM_Odm, 0x900 , BIT18, 0); //TX Ant by Reg // A-cut bug
}
#endif //#if (RTL8881A_SUPPORT == 1)
#if (RTL8812A_SUPPORT == 1)
VOID
odm_TRX_HWAntDiv_Init_8812A(
IN PVOID pDM_VOID
)
{
PDM_ODM_T pDM_Odm = (PDM_ODM_T)pDM_VOID;
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("***8812A AntDiv_Init => AntDivType=[ CG_TRX_HW_ANTDIV (SPDT)] \n"));
//3 //3 --RFE pin setting---------
//[BB]
ODM_SetBBReg(pDM_Odm, 0x900 , BIT10|BIT9|BIT8, 0x0); //disable SW switch
ODM_SetBBReg(pDM_Odm, 0x900 , BIT17|BIT16, 0x0);
ODM_SetBBReg(pDM_Odm, 0x974 , BIT7|BIT6, 0x3); // in/out
ODM_SetBBReg(pDM_Odm, 0xCB4 , BIT31, 0); //delay buffer
ODM_SetBBReg(pDM_Odm, 0xCB4 , BIT26, 0);
ODM_SetBBReg(pDM_Odm, 0xCB4 , BIT27, 1);
ODM_SetBBReg(pDM_Odm, 0xCB0 , 0xF000000, 8); // DPDT_P = ANTSEL[0]
ODM_SetBBReg(pDM_Odm, 0xCB0 , 0xF0000000, 8); // DPDT_N = ANTSEL[0]
//3 -------------------------
//Mapping Table
ODM_SetBBReg(pDM_Odm, 0xCA4 , bMaskByte0, 0);
ODM_SetBBReg(pDM_Odm, 0xCA4 , bMaskByte1, 1);
//OFDM HW AntDiv Parameters
ODM_SetBBReg(pDM_Odm, 0x8D4 , 0x7FF, 0xA0); //thershold
ODM_SetBBReg(pDM_Odm, 0x8D4 , 0x7FF000, 0x0); //bias
ODM_SetBBReg(pDM_Odm, 0x8CC , BIT20|BIT19|BIT18, 3); //settling time of antdiv by RF LNA = 100ns
//CCK HW AntDiv Parameters
ODM_SetBBReg(pDM_Odm, 0xA74 , BIT7, 1); //patch for clk from 88M to 80M
ODM_SetBBReg(pDM_Odm, 0xA0C , BIT4, 1); //do 64 samples
//Timming issue
ODM_SetBBReg(pDM_Odm, 0x818 , BIT23|BIT22|BIT21|BIT20, 8); //keep antidx after tx for ACK ( unit x 32 mu sec)
//2 [--For HW Bug Setting]
ODM_SetBBReg(pDM_Odm, 0x900 , BIT18, 0); //TX Ant by Reg // A-cut bug
}
#endif //#if (RTL8812A_SUPPORT == 1)
#ifdef ODM_EVM_ENHANCE_ANTDIV
VOID
odm_EVM_FastAnt_Reset(
IN PVOID pDM_VOID
)
{
PDM_ODM_T pDM_Odm = (PDM_ODM_T)pDM_VOID;
pFAT_T pDM_FatTable = &pDM_Odm->DM_FatTable;
pDM_FatTable->EVM_method_enable=0;
odm_AntDiv_on_off(pDM_Odm, ANTDIV_ON);
pDM_FatTable->FAT_State = NORMAL_STATE_MIAN;
pDM_Odm->antdiv_period=0;
ODM_SetMACReg(pDM_Odm, 0x608, BIT8, 0);
}
VOID
odm_EVM_Enhance_AntDiv(
IN PVOID pDM_VOID
)
{
PDM_ODM_T pDM_Odm = (PDM_ODM_T)pDM_VOID;
u4Byte Main_RSSI, Aux_RSSI ;
u4Byte Main_CRC_utility=0,Aux_CRC_utility=0,utility_ratio=1;
u4Byte Main_EVM, Aux_EVM,Diff_RSSI=0,diff_EVM=0;
u1Byte score_EVM=0,score_CRC=0;
pFAT_T pDM_FatTable = &pDM_Odm->DM_FatTable;
u4Byte value32, i;
BOOLEAN Main_above1=FALSE,Aux_above1=FALSE;
BOOLEAN Force_antenna=FALSE;
PSTA_INFO_T pEntry;
pDM_FatTable->TargetAnt_enhance=0xFF;
if((pDM_Odm->SupportICType & ODM_EVM_ENHANCE_ANTDIV_SUPPORT_IC))
{
if(pDM_Odm->bOneEntryOnly)
{
//ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("[One Client only] \n"));
i = pDM_Odm->OneEntry_MACID;
Main_RSSI = (pDM_FatTable->MainAnt_Cnt[i]!=0)?(pDM_FatTable->MainAnt_Sum[i]/pDM_FatTable->MainAnt_Cnt[i]):0;
Aux_RSSI = (pDM_FatTable->AuxAnt_Cnt[i]!=0)?(pDM_FatTable->AuxAnt_Sum[i]/pDM_FatTable->AuxAnt_Cnt[i]):0;
if((Main_RSSI==0 && Aux_RSSI !=0 && Aux_RSSI>=FORCE_RSSI_DIFF) || (Main_RSSI!=0 && Aux_RSSI==0 && Main_RSSI>=FORCE_RSSI_DIFF))
{
Diff_RSSI=FORCE_RSSI_DIFF;
}
else if(Main_RSSI!=0 && Aux_RSSI !=0)
{
Diff_RSSI = (Main_RSSI>=Aux_RSSI)?(Main_RSSI-Aux_RSSI):(Aux_RSSI-Main_RSSI);
}
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, (" Main_Cnt = (( %d )) , Main_RSSI= (( %d )) \n", pDM_FatTable->MainAnt_Cnt[i], Main_RSSI));
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, (" Aux_Cnt = (( %d )) , Aux_RSSI = (( %d )) \n" , pDM_FatTable->AuxAnt_Cnt[i] , Aux_RSSI));
if( ((Main_RSSI>=Evm_RSSI_TH_High||Aux_RSSI>=Evm_RSSI_TH_High )|| (pDM_FatTable->EVM_method_enable==1) )
//&& (Diff_RSSI <= FORCE_RSSI_DIFF + 1)
)
{
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("[> TH_H || EVM_method_enable==1] && "));
if(((Main_RSSI>=Evm_RSSI_TH_Low)||(Aux_RSSI>=Evm_RSSI_TH_Low) ))
{
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("[> TH_L ] \n"));
//2 [ Normal state Main]
if(pDM_FatTable->FAT_State == NORMAL_STATE_MIAN)
{
pDM_FatTable->EVM_method_enable=1;
odm_AntDiv_on_off(pDM_Odm, ANTDIV_OFF);
pDM_Odm->antdiv_period=3;
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("[ start training: MIAN] \n"));
pDM_FatTable->MainAntEVM_Sum[i] = 0;
pDM_FatTable->AuxAntEVM_Sum[i] = 0;
pDM_FatTable->MainAntEVM_Cnt[i] = 0;
pDM_FatTable->AuxAntEVM_Cnt[i] = 0;
pDM_FatTable->FAT_State = NORMAL_STATE_AUX;
ODM_SetMACReg(pDM_Odm, 0x608, BIT8, 1); //Accept CRC32 Error packets.
ODM_UpdateRxIdleAnt(pDM_Odm, MAIN_ANT);
pDM_FatTable->CRC32_Ok_Cnt=0;
pDM_FatTable->CRC32_Fail_Cnt=0;
ODM_SetTimer(pDM_Odm,&pDM_Odm->EVM_FastAntTrainingTimer, pDM_Odm->antdiv_intvl ); //m
}
//2 [ Normal state Aux ]
else if(pDM_FatTable->FAT_State == NORMAL_STATE_AUX)
{
pDM_FatTable->MainCRC32_Ok_Cnt=pDM_FatTable->CRC32_Ok_Cnt;
pDM_FatTable->MainCRC32_Fail_Cnt=pDM_FatTable->CRC32_Fail_Cnt;
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("[ start training: AUX] \n"));
pDM_FatTable->FAT_State = TRAINING_STATE;
ODM_UpdateRxIdleAnt(pDM_Odm, AUX_ANT);
pDM_FatTable->CRC32_Ok_Cnt=0;
pDM_FatTable->CRC32_Fail_Cnt=0;
ODM_SetTimer(pDM_Odm,&pDM_Odm->EVM_FastAntTrainingTimer, pDM_Odm->antdiv_intvl ); //ms
}
else if(pDM_FatTable->FAT_State == TRAINING_STATE)
{
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("[Training state ] \n"));
pDM_FatTable->FAT_State = NORMAL_STATE_MIAN;
//3 [CRC32 statistic]
pDM_FatTable->AuxCRC32_Ok_Cnt=pDM_FatTable->CRC32_Ok_Cnt;
pDM_FatTable->AuxCRC32_Fail_Cnt=pDM_FatTable->CRC32_Fail_Cnt;
if( (pDM_FatTable->MainCRC32_Ok_Cnt >= ((pDM_FatTable->AuxCRC32_Ok_Cnt)<<1)) || (Diff_RSSI>=18))
{
pDM_FatTable->TargetAnt_CRC32=MAIN_ANT;
Force_antenna=TRUE;
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("CRC32 Force Main \n"));
}
else if((pDM_FatTable->AuxCRC32_Ok_Cnt >= ((pDM_FatTable->MainCRC32_Ok_Cnt)<<1)) || (Diff_RSSI>=18))
{
pDM_FatTable->TargetAnt_CRC32=AUX_ANT;
Force_antenna=TRUE;
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("CRC32 Force Aux \n"));
}
else
{
if(pDM_FatTable->MainCRC32_Fail_Cnt<=5)
pDM_FatTable->MainCRC32_Fail_Cnt=5;
if(pDM_FatTable->AuxCRC32_Fail_Cnt<=5)
pDM_FatTable->AuxCRC32_Fail_Cnt=5;
if(pDM_FatTable->MainCRC32_Ok_Cnt >pDM_FatTable->MainCRC32_Fail_Cnt )
Main_above1=TRUE;
if(pDM_FatTable->AuxCRC32_Ok_Cnt >pDM_FatTable->AuxCRC32_Fail_Cnt )
Aux_above1=TRUE;
if(Main_above1==TRUE && Aux_above1==FALSE)
{
Force_antenna=TRUE;
pDM_FatTable->TargetAnt_CRC32=MAIN_ANT;
}
else if(Main_above1==FALSE && Aux_above1==TRUE)
{
Force_antenna=TRUE;
pDM_FatTable->TargetAnt_CRC32=AUX_ANT;
}
else if(Main_above1==TRUE && Aux_above1==TRUE)
{
Main_CRC_utility=((pDM_FatTable->MainCRC32_Ok_Cnt)<<7)/pDM_FatTable->MainCRC32_Fail_Cnt;
Aux_CRC_utility=((pDM_FatTable->AuxCRC32_Ok_Cnt)<<7)/pDM_FatTable->AuxCRC32_Fail_Cnt;
pDM_FatTable->TargetAnt_CRC32 = (Main_CRC_utility==Aux_CRC_utility)?(pDM_FatTable->pre_TargetAnt_enhance):((Main_CRC_utility>=Aux_CRC_utility)?MAIN_ANT:AUX_ANT);
if(Main_CRC_utility!=0 && Aux_CRC_utility!=0)
{
if(Main_CRC_utility>=Aux_CRC_utility)
utility_ratio=(Main_CRC_utility<<1)/Aux_CRC_utility;
else
utility_ratio=(Aux_CRC_utility<<1)/Main_CRC_utility;
}
}
else if(Main_above1==FALSE && Aux_above1==FALSE)
{
if(pDM_FatTable->MainCRC32_Ok_Cnt==0)
pDM_FatTable->MainCRC32_Ok_Cnt=1;
if(pDM_FatTable->AuxCRC32_Ok_Cnt==0)
pDM_FatTable->AuxCRC32_Ok_Cnt=1;
Main_CRC_utility=((pDM_FatTable->MainCRC32_Fail_Cnt)<<7)/pDM_FatTable->MainCRC32_Ok_Cnt;
Aux_CRC_utility=((pDM_FatTable->AuxCRC32_Fail_Cnt)<<7)/pDM_FatTable->AuxCRC32_Ok_Cnt;
pDM_FatTable->TargetAnt_CRC32 = (Main_CRC_utility==Aux_CRC_utility)?(pDM_FatTable->pre_TargetAnt_enhance):((Main_CRC_utility<=Aux_CRC_utility)?MAIN_ANT:AUX_ANT);
if(Main_CRC_utility!=0 && Aux_CRC_utility!=0)
{
if(Main_CRC_utility>=Aux_CRC_utility)
utility_ratio=(Main_CRC_utility<<1)/(Aux_CRC_utility);
else
utility_ratio=(Aux_CRC_utility<<1)/(Main_CRC_utility);
}
}
}
ODM_SetMACReg(pDM_Odm, 0x608, BIT8, 0);//NOT Accept CRC32 Error packets.
//3 [EVM statistic]
Main_EVM = (pDM_FatTable->MainAntEVM_Cnt[i]!=0)?(pDM_FatTable->MainAntEVM_Sum[i]/pDM_FatTable->MainAntEVM_Cnt[i]):0;
Aux_EVM = (pDM_FatTable->AuxAntEVM_Cnt[i]!=0)?(pDM_FatTable->AuxAntEVM_Sum[i]/pDM_FatTable->AuxAntEVM_Cnt[i]):0;
pDM_FatTable->TargetAnt_EVM = (Main_EVM==Aux_EVM)?(pDM_FatTable->pre_TargetAnt_enhance):((Main_EVM>=Aux_EVM)?MAIN_ANT:AUX_ANT);
if((Main_EVM==0 || Aux_EVM==0))
diff_EVM=0;
else if(Main_EVM>=Aux_EVM)
diff_EVM=Main_EVM-Aux_EVM;
else
diff_EVM=Aux_EVM-Main_EVM;
//2 [ Decision state ]
if(pDM_FatTable->TargetAnt_EVM ==pDM_FatTable->TargetAnt_CRC32 )
{
if( (utility_ratio<2 && Force_antenna==FALSE) && diff_EVM<=2)
pDM_FatTable->TargetAnt_enhance=pDM_FatTable->pre_TargetAnt_enhance;
else
pDM_FatTable->TargetAnt_enhance=pDM_FatTable->TargetAnt_EVM;
}
else if(diff_EVM<=2 && (utility_ratio > 4 && Force_antenna==FALSE))
{
pDM_FatTable->TargetAnt_enhance=pDM_FatTable->TargetAnt_CRC32;
}
else if(diff_EVM>=20) //
{
pDM_FatTable->TargetAnt_enhance=pDM_FatTable->TargetAnt_EVM;
}
else if(utility_ratio>=6 && Force_antenna==FALSE) // utility_ratio>3
{
pDM_FatTable->TargetAnt_enhance=pDM_FatTable->TargetAnt_CRC32;
}
else
{
if(Force_antenna==TRUE)
score_CRC=3;
else if(utility_ratio>=4) //>2
score_CRC=2;
else if(utility_ratio>=3) //>1.5
score_CRC=1;
else
score_CRC=0;
if(diff_EVM>=10)
score_EVM=2;
else if(diff_EVM>=5)
score_EVM=1;
else
score_EVM=0;
if(score_CRC>score_EVM)
pDM_FatTable->TargetAnt_enhance=pDM_FatTable->TargetAnt_CRC32;
else if(score_CRC<score_EVM)
pDM_FatTable->TargetAnt_enhance=pDM_FatTable->TargetAnt_EVM;
else
pDM_FatTable->TargetAnt_enhance=pDM_FatTable->pre_TargetAnt_enhance;
}
pDM_FatTable->pre_TargetAnt_enhance=pDM_FatTable->TargetAnt_enhance;
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("*** Client[ %d ] : MainEVM_Cnt = (( %d )) , Main_EVM= (( %d )) \n",i, pDM_FatTable->MainAntEVM_Cnt[i], Main_EVM));
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("*** Client[ %d ] : AuxEVM_Cnt = (( %d )) , Aux_EVM = (( %d )) \n" ,i, pDM_FatTable->AuxAntEVM_Cnt[i] , Aux_EVM));
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("*** TargetAnt_EVM = (( %s ))\n", ( pDM_FatTable->TargetAnt_EVM ==MAIN_ANT)?"MAIN_ANT":"AUX_ANT"));
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("M_CRC_Ok = (( %d )) , M_CRC_Fail = (( %d )), Main_CRC_utility = (( %d )) \n" , pDM_FatTable->MainCRC32_Ok_Cnt, pDM_FatTable->MainCRC32_Fail_Cnt,Main_CRC_utility));
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("A_CRC_Ok = (( %d )) , A_CRC_Fail = (( %d )), Aux_CRC_utility = (( %d )) \n" , pDM_FatTable->AuxCRC32_Ok_Cnt, pDM_FatTable->AuxCRC32_Fail_Cnt,Aux_CRC_utility));
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("*** TargetAnt_CRC32 = (( %s ))\n", ( pDM_FatTable->TargetAnt_CRC32 ==MAIN_ANT)?"MAIN_ANT":"AUX_ANT"));
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("****** TargetAnt_enhance = (( %s ))******\n", ( pDM_FatTable->TargetAnt_enhance ==MAIN_ANT)?"MAIN_ANT":"AUX_ANT"));
}
}
else // RSSI< = Evm_RSSI_TH_Low
{
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("[ <TH_L: escape from > TH_L ] \n"));
odm_EVM_FastAnt_Reset(pDM_Odm);
}
}
else
{
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("[escape from> TH_H || EVM_method_enable==1] \n"));
odm_EVM_FastAnt_Reset(pDM_Odm);
}
}
else
{
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("[multi-Client] \n"));
odm_EVM_FastAnt_Reset(pDM_Odm);
}
}
}
VOID
odm_EVM_FastAntTrainingCallback(
IN PVOID pDM_VOID
)
{
PDM_ODM_T pDM_Odm = (PDM_ODM_T)pDM_VOID;
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("******odm_EVM_FastAntTrainingCallback****** \n"));
odm_HW_AntDiv(pDM_Odm);
}
#endif
VOID
odm_HW_AntDiv(
IN PVOID pDM_VOID
)
{
PDM_ODM_T pDM_Odm = (PDM_ODM_T)pDM_VOID;
u4Byte i,MinMaxRSSI=0xFF, AntDivMaxRSSI=0, MaxRSSI=0, LocalMaxRSSI;
u4Byte Main_RSSI, Aux_RSSI;
pFAT_T pDM_FatTable = &pDM_Odm->DM_FatTable;
u1Byte RxIdleAnt = pDM_FatTable->RxIdleAnt, TargetAnt = 7;
pDIG_T pDM_DigTable = &pDM_Odm->DM_DigTable;
PSTA_INFO_T pEntry;
#ifdef BEAMFORMING_SUPPORT
#if(DM_ODM_SUPPORT_TYPE == ODM_AP)
pBDC_T pDM_BdcTable = &pDM_Odm->DM_BdcTable;
u4Byte TH1=500000;
u4Byte TH2=10000000;
u4Byte MA_rx_Temp, degrade_TP_temp, improve_TP_temp;
u1Byte Monitor_RSSI_threshold=30;
pDM_BdcTable->BF_pass=TRUE;
pDM_BdcTable->DIV_pass=TRUE;
pDM_BdcTable->bAll_DivSta_Idle=TRUE;
pDM_BdcTable->bAll_BFSta_Idle=TRUE;
pDM_BdcTable->num_BfTar=0 ;
pDM_BdcTable->num_DivTar=0;
pDM_BdcTable->num_Client=0;
#endif
#endif
if(!pDM_Odm->bLinked) //bLinked==False
{
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("[No Link!!!]\n"));
if(pDM_FatTable->bBecomeLinked == TRUE)
{
odm_AntDiv_on_off(pDM_Odm, ANTDIV_OFF);
ODM_UpdateRxIdleAnt(pDM_Odm, MAIN_ANT);
odm_Tx_By_TxDesc_or_Reg(pDM_Odm , REG);
pDM_Odm->antdiv_period=0;
pDM_FatTable->bBecomeLinked = pDM_Odm->bLinked;
}
return;
}
else
{
if(pDM_FatTable->bBecomeLinked ==FALSE)
{
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("[Linked !!!]\n"));
odm_AntDiv_on_off(pDM_Odm, ANTDIV_ON);
odm_Tx_By_TxDesc_or_Reg(pDM_Odm , TX_BY_DESC);
//if(pDM_Odm->SupportICType == ODM_RTL8821 )
//ODM_SetBBReg(pDM_Odm, 0x800 , BIT25, 0); //CCK AntDiv function disable
//#if(DM_ODM_SUPPORT_TYPE == ODM_AP)
//else if(pDM_Odm->SupportICType == ODM_RTL8881A)
// ODM_SetBBReg(pDM_Odm, 0x800 , BIT25, 0); //CCK AntDiv function disable
//#endif
//else if(pDM_Odm->SupportICType == ODM_RTL8723B ||pDM_Odm->SupportICType == ODM_RTL8812)
//ODM_SetBBReg(pDM_Odm, 0xA00 , BIT15, 0); //CCK AntDiv function disable
pDM_FatTable->bBecomeLinked = pDM_Odm->bLinked;
if(pDM_Odm->SupportICType==ODM_RTL8723B && pDM_Odm->AntDivType == CG_TRX_HW_ANTDIV)
{
ODM_SetBBReg(pDM_Odm, 0x930 , 0xF0, 8); // DPDT_P = ANTSEL[0] // for 8723B AntDiv function patch. BB Dino 130412
ODM_SetBBReg(pDM_Odm, 0x930 , 0xF, 8); // DPDT_N = ANTSEL[0]
}
//2 BDC Init
#ifdef BEAMFORMING_SUPPORT
#if(DM_ODM_SUPPORT_TYPE == ODM_AP)
odm_BDC_Init(pDM_Odm);
#endif
#endif
#ifdef ODM_EVM_ENHANCE_ANTDIV
odm_EVM_FastAnt_Reset(pDM_Odm);
#endif
}
}
//ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("\n AntDiv Start =>\n"));
#ifdef ODM_EVM_ENHANCE_ANTDIV
if(pDM_Odm->antdiv_evm_en==1)
{
odm_EVM_Enhance_AntDiv(pDM_Odm);
if(pDM_FatTable->FAT_State !=NORMAL_STATE_MIAN)
return;
}
else
{
odm_EVM_FastAnt_Reset(pDM_Odm);
}
#endif
//2 BDC Mode Arbitration
#ifdef BEAMFORMING_SUPPORT
#if(DM_ODM_SUPPORT_TYPE == ODM_AP)
if(pDM_Odm->antdiv_evm_en == 0 ||pDM_FatTable->EVM_method_enable==0)
{
odm_BF_AntDiv_ModeArbitration(pDM_Odm);
}
#endif
#endif
for (i=0; i<ODM_ASSOCIATE_ENTRY_NUM; i++)
{
pEntry = pDM_Odm->pODM_StaInfo[i];
if(IS_STA_VALID(pEntry))
{
//2 Caculate RSSI per Antenna
Main_RSSI = (pDM_FatTable->MainAnt_Cnt[i]!=0)?(pDM_FatTable->MainAnt_Sum[i]/pDM_FatTable->MainAnt_Cnt[i]):0;
Aux_RSSI = (pDM_FatTable->AuxAnt_Cnt[i]!=0)?(pDM_FatTable->AuxAnt_Sum[i]/pDM_FatTable->AuxAnt_Cnt[i]):0;
TargetAnt = (Main_RSSI==Aux_RSSI)?pDM_FatTable->RxIdleAnt:((Main_RSSI>=Aux_RSSI)?MAIN_ANT:AUX_ANT);
//ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV,ODM_DBG_LOUD,("*** SupportICType=[%d] \n",pDM_Odm->SupportICType));
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("*** Client[ %d ] : Main_Cnt = (( %d )) , Main_RSSI= (( %d )) \n",i, pDM_FatTable->MainAnt_Cnt[i], Main_RSSI));
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("*** Client[ %d ] : Aux_Cnt = (( %d )) , Aux_RSSI = (( %d )) \n" ,i, pDM_FatTable->AuxAnt_Cnt[i] , Aux_RSSI));
//ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("*** MAC ID:[ %d ] , TargetAnt = (( %s )) \n", i ,( TargetAnt ==MAIN_ANT)?"MAIN_ANT":"AUX_ANT"));
//ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV,ODM_DBG_LOUD,("*** Phy_AntSel_A=[ %d, %d, %d] \n",((pDM_Odm->DM_FatTable.antsel_rx_keep_0)&BIT2)>>2,
// ((pDM_Odm->DM_FatTable.antsel_rx_keep_0)&BIT1) >>1, ((pDM_Odm->DM_FatTable.antsel_rx_keep_0)&BIT0)));
LocalMaxRSSI = (Main_RSSI>Aux_RSSI)?Main_RSSI:Aux_RSSI;
//2 Select MaxRSSI for DIG
if((LocalMaxRSSI > AntDivMaxRSSI) && (LocalMaxRSSI < 40))
AntDivMaxRSSI = LocalMaxRSSI;
if(LocalMaxRSSI > MaxRSSI)
MaxRSSI = LocalMaxRSSI;
//2 Select RX Idle Antenna
if ( (LocalMaxRSSI != 0) && (LocalMaxRSSI < MinMaxRSSI) )
{
RxIdleAnt = TargetAnt;
MinMaxRSSI = LocalMaxRSSI;
}
#ifdef ODM_EVM_ENHANCE_ANTDIV
if(pDM_Odm->antdiv_evm_en==1)
{
if(pDM_FatTable->TargetAnt_enhance!=0xFF)
{
TargetAnt=pDM_FatTable->TargetAnt_enhance;
RxIdleAnt = pDM_FatTable->TargetAnt_enhance;
}
}
#endif
//2 Select TX Antenna
if(pDM_Odm->AntDivType != CGCS_RX_HW_ANTDIV)
{
#ifdef BEAMFORMING_SUPPORT
#if(DM_ODM_SUPPORT_TYPE == ODM_AP)
if(pDM_BdcTable->w_BFee_Client[i]==0)
#endif
#endif
{
odm_UpdateTxAnt(pDM_Odm, TargetAnt, i);
}
}
//------------------------------------------------------------
#ifdef BEAMFORMING_SUPPORT
#if(DM_ODM_SUPPORT_TYPE == ODM_AP)
pDM_BdcTable->num_Client++;
if(pDM_BdcTable->BDC_Mode==BDC_MODE_2 ||pDM_BdcTable->BDC_Mode==BDC_MODE_3)
{
//2 Byte Counter
MA_rx_Temp= (pEntry->rx_byte_cnt_LowMAW)<<3 ; // RX TP ( bit /sec)
if(pDM_BdcTable->BDC_state==BDC_BFer_TRAIN_STATE)
{
pDM_BdcTable->MA_rx_TP_DIV[i]= MA_rx_Temp ;
}
else
{
pDM_BdcTable->MA_rx_TP[i] =MA_rx_Temp ;
}
if( (MA_rx_Temp < TH2) && (MA_rx_Temp > TH1) && (LocalMaxRSSI<=Monitor_RSSI_threshold))
{
if(pDM_BdcTable->w_BFer_Client[i]==1) // Bfer_Target
{
pDM_BdcTable->num_BfTar++;
if(pDM_BdcTable->BDC_state==BDC_DECISION_STATE && pDM_BdcTable->BDC_Try_flag==0)
{
improve_TP_temp = (pDM_BdcTable->MA_rx_TP_DIV[i] * 9)>>3 ; //* 1.125
pDM_BdcTable->BF_pass = (pDM_BdcTable->MA_rx_TP[i] > improve_TP_temp)?TRUE:FALSE;
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("*** Client[ %d ] : { MA_rx_TP,improve_TP_temp , MA_rx_TP_DIV, BF_pass}={ %d, %d, %d , %d } \n" ,i,pDM_BdcTable->MA_rx_TP[i],improve_TP_temp,pDM_BdcTable->MA_rx_TP_DIV[i], pDM_BdcTable->BF_pass ));
}
}
else// DIV_Target
{
pDM_BdcTable->num_DivTar++;
if(pDM_BdcTable->BDC_state==BDC_DECISION_STATE && pDM_BdcTable->BDC_Try_flag==0)
{
degrade_TP_temp=(pDM_BdcTable->MA_rx_TP_DIV[i]*5)>>3;//* 0.625
pDM_BdcTable->DIV_pass = (pDM_BdcTable->MA_rx_TP[i] >degrade_TP_temp)?TRUE:FALSE;
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("*** Client[ %d ] : { MA_rx_TP, degrade_TP_temp , MA_rx_TP_DIV, DIV_pass}=\n{ %d, %d, %d , %d } \n" ,i,pDM_BdcTable->MA_rx_TP[i],degrade_TP_temp,pDM_BdcTable->MA_rx_TP_DIV[i], pDM_BdcTable->DIV_pass ));
}
}
}
if(MA_rx_Temp > TH1)
{
if(pDM_BdcTable->w_BFer_Client[i]==1) // Bfer_Target
{
pDM_BdcTable->bAll_BFSta_Idle=FALSE;
}
else// DIV_Target
{
pDM_BdcTable->bAll_DivSta_Idle=FALSE;
}
}
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("*** Client[ %d ] : { BFmeeCap , BFmerCap} = { %d , %d } \n" ,i, pDM_BdcTable->w_BFee_Client[i] , pDM_BdcTable->w_BFer_Client[i]));
if(pDM_BdcTable->BDC_state==BDC_BFer_TRAIN_STATE)
{
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("*** Client[ %d ] : MA_rx_TP_DIV = (( %d )) \n",i,pDM_BdcTable->MA_rx_TP_DIV[i] ));
}
else
{
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("*** Client[ %d ] : MA_rx_TP = (( %d )) \n",i,pDM_BdcTable->MA_rx_TP[i] ));
}
}
#endif
#endif
}
#ifdef BEAMFORMING_SUPPORT
#if(DM_ODM_SUPPORT_TYPE == ODM_AP)
if(pDM_BdcTable->BDC_Try_flag==0)
#endif
#endif
{
pDM_FatTable->MainAnt_Sum[i] = 0;
pDM_FatTable->AuxAnt_Sum[i] = 0;
pDM_FatTable->MainAnt_Cnt[i] = 0;
pDM_FatTable->AuxAnt_Cnt[i] = 0;
}
}
//2 Set RX Idle Antenna & TX Antenna(Because of HW Bug )
#if(DM_ODM_SUPPORT_TYPE == ODM_AP )
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("*** RxIdleAnt = (( %s ))\n\n", ( RxIdleAnt ==MAIN_ANT)?"MAIN_ANT":"AUX_ANT"));
#ifdef BEAMFORMING_SUPPORT
#if(DM_ODM_SUPPORT_TYPE == ODM_AP)
if(pDM_BdcTable->BDC_Mode==BDC_MODE_1 ||pDM_BdcTable->BDC_Mode==BDC_MODE_3)
{
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("*** BDC_RxIdleUpdate_counter = (( %d ))\n", pDM_BdcTable->BDC_RxIdleUpdate_counter));
if(pDM_BdcTable->BDC_RxIdleUpdate_counter==1)
{
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("***Update RxIdle Antenna!!! \n"));
pDM_BdcTable->BDC_RxIdleUpdate_counter=30;
ODM_UpdateRxIdleAnt(pDM_Odm, RxIdleAnt);
}
else
{
pDM_BdcTable->BDC_RxIdleUpdate_counter--;
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("***NOT update RxIdle Antenna because of BF ( need to fix TX-ant)\n"));
}
}
else
#endif
#endif
ODM_UpdateRxIdleAnt(pDM_Odm, RxIdleAnt);
#else
ODM_UpdateRxIdleAnt(pDM_Odm, RxIdleAnt);
#endif//#if(DM_ODM_SUPPORT_TYPE == ODM_AP)
//2 BDC Main Algorithm
#ifdef BEAMFORMING_SUPPORT
#if(DM_ODM_SUPPORT_TYPE == ODM_AP)
if(pDM_Odm->antdiv_evm_en ==0 ||pDM_FatTable->EVM_method_enable==0)
{
odm_BDCcoex_BFeeRxDiv_Arbitration(pDM_Odm);
}
#endif
#endif
if(AntDivMaxRSSI == 0)
pDM_DigTable->AntDiv_RSSI_max = pDM_Odm->RSSI_Min;
else
pDM_DigTable->AntDiv_RSSI_max = AntDivMaxRSSI;
pDM_DigTable->RSSI_max = MaxRSSI;
}
#ifdef CONFIG_S0S1_SW_ANTENNA_DIVERSITY
VOID
odm_S0S1_SwAntDiv(
IN PVOID pDM_VOID,
IN u1Byte Step
)
{
PDM_ODM_T pDM_Odm = (PDM_ODM_T)pDM_VOID;
u4Byte i,MinMaxRSSI=0xFF, LocalMaxRSSI,LocalMinRSSI;
u4Byte Main_RSSI, Aux_RSSI;
u1Byte reset_period=10, SWAntDiv_threshold=35;
u1Byte HighTraffic_TrainTime_U=0x32,HighTraffic_TrainTime_L=0,Train_time_temp;
u1Byte LowTraffic_TrainTime_U=200,LowTraffic_TrainTime_L=0;
pSWAT_T pDM_SWAT_Table = &pDM_Odm->DM_SWAT_Table;
pFAT_T pDM_FatTable = &pDM_Odm->DM_FatTable;
u1Byte RxIdleAnt = pDM_SWAT_Table->PreAntenna, TargetAnt, nextAnt=0;
PSTA_INFO_T pEntry=NULL;
//static u1Byte reset_idx;
u4Byte value32;
PADAPTER Adapter = pDM_Odm->Adapter;
u8Byte curTxOkCnt=0, curRxOkCnt=0,TxCntOffset, RxCntOffset;
if(!pDM_Odm->bLinked) //bLinked==False
{
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("[No Link!!!]\n"));
if(pDM_FatTable->bBecomeLinked == TRUE)
{
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("Set REG 948[9:6]=0x0 \n"));
if(pDM_Odm->SupportICType == ODM_RTL8723B)
ODM_SetBBReg(pDM_Odm, 0x948 , BIT9|BIT8|BIT7|BIT6, 0x0);
pDM_FatTable->bBecomeLinked = pDM_Odm->bLinked;
}
return;
}
else
{
if(pDM_FatTable->bBecomeLinked ==FALSE)
{
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("[Linked !!!]\n"));
if(pDM_Odm->SupportICType == ODM_RTL8723B)
{
value32 = ODM_GetBBReg(pDM_Odm, 0x864, BIT5|BIT4|BIT3);
if (value32==0x0)
ODM_UpdateRxIdleAnt_8723B(pDM_Odm, MAIN_ANT, ANT1_2G, ANT2_2G);
else if (value32==0x1)
ODM_UpdateRxIdleAnt_8723B(pDM_Odm, AUX_ANT, ANT2_2G, ANT1_2G);
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("8723B: First link! Force antenna to %s\n",(value32 == 0x0?"MAIN":"AUX") ));
}
pDM_SWAT_Table->lastTxOkCnt = 0;
pDM_SWAT_Table->lastRxOkCnt =0;
TxCntOffset = *(pDM_Odm->pNumTxBytesUnicast);
RxCntOffset = *(pDM_Odm->pNumRxBytesUnicast);
pDM_FatTable->bBecomeLinked = pDM_Odm->bLinked;
}
else
{
TxCntOffset = 0;
RxCntOffset = 0;
}
}
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("[%d] { try_flag=(( %d )), Step=(( %d )), Double_chk_flag = (( %d )) }\n",
__LINE__,pDM_SWAT_Table->try_flag,Step,pDM_SWAT_Table->Double_chk_flag));
// Handling step mismatch condition.
// Peak step is not finished at last time. Recover the variable and check again.
if( Step != pDM_SWAT_Table->try_flag )
{
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("[Step != try_flag] Need to Reset After Link\n"));
ODM_SwAntDivRestAfterLink(pDM_Odm);
}
if(pDM_SWAT_Table->try_flag == 0xff)
{
pDM_SWAT_Table->try_flag = 0;
pDM_SWAT_Table->Train_time_flag=0;
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD,("[set try_flag = 0] Prepare for peak!\n\n"));
return;
}
else//if( try_flag != 0xff )
{
//1 Normal State (Begin Trying)
if(pDM_SWAT_Table->try_flag == 0)
{
//---trafic decision---
curTxOkCnt = *(pDM_Odm->pNumTxBytesUnicast) - pDM_SWAT_Table->lastTxOkCnt - TxCntOffset;
curRxOkCnt = *(pDM_Odm->pNumRxBytesUnicast) - pDM_SWAT_Table->lastRxOkCnt - RxCntOffset;
pDM_SWAT_Table->lastTxOkCnt = *(pDM_Odm->pNumTxBytesUnicast);
pDM_SWAT_Table->lastRxOkCnt = *(pDM_Odm->pNumRxBytesUnicast);
if (curTxOkCnt > 1875000 || curRxOkCnt > 1875000)//if(PlatformDivision64(curTxOkCnt+curRxOkCnt, 2) > 1875000) ( 1.875M * 8bit ) / 2= 7.5M bits /sec )
{
pDM_SWAT_Table->TrafficLoad = TRAFFIC_HIGH;
Train_time_temp = pDM_SWAT_Table->Train_time ;
if(pDM_SWAT_Table->Train_time_flag==3)
{
HighTraffic_TrainTime_L=0xa;
if(Train_time_temp<=16)
Train_time_temp=HighTraffic_TrainTime_L;
else
Train_time_temp-=16;
}
else if(pDM_SWAT_Table->Train_time_flag==2)
{
Train_time_temp-=8;
HighTraffic_TrainTime_L=0xf;
}
else if(pDM_SWAT_Table->Train_time_flag==1)
{
Train_time_temp-=4;
HighTraffic_TrainTime_L=0x1e;
}
else if(pDM_SWAT_Table->Train_time_flag==0)
{
Train_time_temp+=8;
HighTraffic_TrainTime_L=0x28;
}
//ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("*** Train_time_temp = ((%d))\n",Train_time_temp));
//--
if(Train_time_temp > HighTraffic_TrainTime_U)
Train_time_temp=HighTraffic_TrainTime_U;
else if(Train_time_temp < HighTraffic_TrainTime_L)
Train_time_temp=HighTraffic_TrainTime_L;
pDM_SWAT_Table->Train_time = Train_time_temp; //50ms~10ms
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD,(" Train_time_flag=((%d)) , Train_time=((%d)) \n",pDM_SWAT_Table->Train_time_flag, pDM_SWAT_Table->Train_time));
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, (" [HIGH Traffic] \n" ));
}
else if (curTxOkCnt > 125000 || curRxOkCnt > 125000) // ( 0.125M * 8bit ) / 2 = 0.5M bits /sec )
{
pDM_SWAT_Table->TrafficLoad = TRAFFIC_LOW;
Train_time_temp=pDM_SWAT_Table->Train_time ;
if(pDM_SWAT_Table->Train_time_flag==3)
{
LowTraffic_TrainTime_L=10;
if(Train_time_temp<50)
Train_time_temp=LowTraffic_TrainTime_L;
else
Train_time_temp-=50;
}
else if(pDM_SWAT_Table->Train_time_flag==2)
{
Train_time_temp-=30;
LowTraffic_TrainTime_L=36;
}
else if(pDM_SWAT_Table->Train_time_flag==1)
{
Train_time_temp-=10;
LowTraffic_TrainTime_L=40;
}
else
Train_time_temp+=10;
//--
if(Train_time_temp >= LowTraffic_TrainTime_U)
Train_time_temp=LowTraffic_TrainTime_U;
else if(Train_time_temp <= LowTraffic_TrainTime_L)
Train_time_temp=LowTraffic_TrainTime_L;
pDM_SWAT_Table->Train_time = Train_time_temp; //50ms~20ms
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("Train_time_flag=((%d)) , Train_time=((%d))\n", pDM_SWAT_Table->Train_time_flag, pDM_SWAT_Table->Train_time));
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("[Low Traffic]\n"));
}
else
{
pDM_SWAT_Table->TrafficLoad = TRAFFIC_ULTRA_LOW;
pDM_SWAT_Table->Train_time = 0xc8; //200ms
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("[Ultra-Low Traffic]\n"));
}
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("TxOkCnt=(( %llu )), RxOkCnt=(( %llu ))\n",
curTxOkCnt ,curRxOkCnt ));
//-----------------
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD,(" Current MinMaxRSSI is ((%d)) \n",pDM_FatTable->MinMaxRSSI));
//---reset index---
if(pDM_SWAT_Table->reset_idx>=reset_period)
{
pDM_FatTable->MinMaxRSSI=0; //
pDM_SWAT_Table->reset_idx=0;
}
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("reset_idx = (( %d )) \n",pDM_SWAT_Table->reset_idx ));
//ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD,("reset_idx=%d\n",pDM_SWAT_Table->reset_idx));
pDM_SWAT_Table->reset_idx++;
//---double check flag---
if(pDM_FatTable->MinMaxRSSI > SWAntDiv_threshold && pDM_SWAT_Table->Double_chk_flag== 0)
{
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD,(" MinMaxRSSI is ((%d)), and > %d \n",
pDM_FatTable->MinMaxRSSI,SWAntDiv_threshold));
pDM_SWAT_Table->Double_chk_flag =1;
pDM_SWAT_Table->try_flag = 1;
pDM_SWAT_Table->RSSI_Trying = 0;
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, (" Test the current Ant for (( %d )) ms again \n", pDM_SWAT_Table->Train_time));
ODM_UpdateRxIdleAnt(pDM_Odm, pDM_FatTable->RxIdleAnt);
ODM_SetTimer(pDM_Odm,&pDM_SWAT_Table->SwAntennaSwitchTimer_8723B, pDM_SWAT_Table->Train_time ); //ms
return;
}
nextAnt = (pDM_FatTable->RxIdleAnt == MAIN_ANT)? AUX_ANT : MAIN_ANT;
pDM_SWAT_Table->try_flag = 1;
if(pDM_SWAT_Table->reset_idx<=1)
pDM_SWAT_Table->RSSI_Trying = 2;
else
pDM_SWAT_Table->RSSI_Trying = 1;
odm_S0S1_SwAntDivByCtrlFrame(pDM_Odm, SWAW_STEP_PEEK);
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("[set try_flag=1] Normal State: Begin Trying!!\n"));
}
else if(pDM_SWAT_Table->try_flag == 1 && pDM_SWAT_Table->Double_chk_flag== 0)
{
nextAnt = (pDM_FatTable->RxIdleAnt == MAIN_ANT)? AUX_ANT : MAIN_ANT;
pDM_SWAT_Table->RSSI_Trying--;
}
//1 Decision State
if((pDM_SWAT_Table->try_flag == 1)&&(pDM_SWAT_Table->RSSI_Trying == 0) )
{
BOOLEAN bByCtrlFrame = FALSE;
u8Byte pkt_cnt_total = 0;
for (i=0; i<ODM_ASSOCIATE_ENTRY_NUM; i++)
{
pEntry = pDM_Odm->pODM_StaInfo[i];
if(IS_STA_VALID(pEntry))
{
//2 Caculate RSSI per Antenna
Main_RSSI = (pDM_FatTable->MainAnt_Cnt[i]!=0)?(pDM_FatTable->MainAnt_Sum[i]/pDM_FatTable->MainAnt_Cnt[i]):0;
Aux_RSSI = (pDM_FatTable->AuxAnt_Cnt[i]!=0)?(pDM_FatTable->AuxAnt_Sum[i]/pDM_FatTable->AuxAnt_Cnt[i]):0;
if(pDM_FatTable->MainAnt_Cnt[i]<=1 && pDM_FatTable->CCK_counter_main>=1)
Main_RSSI=0;
if(pDM_FatTable->AuxAnt_Cnt[i]<=1 && pDM_FatTable->CCK_counter_aux>=1)
Aux_RSSI=0;
TargetAnt = (Main_RSSI==Aux_RSSI)?pDM_SWAT_Table->PreAntenna:((Main_RSSI>=Aux_RSSI)?MAIN_ANT:AUX_ANT);
LocalMaxRSSI = (Main_RSSI>=Aux_RSSI) ? Main_RSSI : Aux_RSSI;
LocalMinRSSI = (Main_RSSI>=Aux_RSSI) ? Aux_RSSI : Main_RSSI;
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("*** CCK_counter_main = (( %d )) , CCK_counter_aux= (( %d )) \n", pDM_FatTable->CCK_counter_main, pDM_FatTable->CCK_counter_aux));
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("*** OFDM_counter_main = (( %d )) , OFDM_counter_aux= (( %d )) \n", pDM_FatTable->OFDM_counter_main, pDM_FatTable->OFDM_counter_aux));
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("*** Main_Cnt = (( %d )) , Main_RSSI= (( %d )) \n", pDM_FatTable->MainAnt_Cnt[i], Main_RSSI));
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("*** Aux_Cnt = (( %d )) , Aux_RSSI = (( %d )) \n", pDM_FatTable->AuxAnt_Cnt[i] , Aux_RSSI ));
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("*** MAC ID:[ %d ] , TargetAnt = (( %s )) \n", i ,( TargetAnt ==MAIN_ANT)?"MAIN_ANT":"AUX_ANT"));
//2 Select RX Idle Antenna
if (LocalMaxRSSI != 0 && LocalMaxRSSI < MinMaxRSSI)
{
RxIdleAnt = TargetAnt;
MinMaxRSSI = LocalMaxRSSI;
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("*** LocalMaxRSSI-LocalMinRSSI = ((%d))\n",(LocalMaxRSSI-LocalMinRSSI)));
if((LocalMaxRSSI-LocalMinRSSI)>8)
{
if(LocalMinRSSI != 0)
pDM_SWAT_Table->Train_time_flag=3;
else
{
if(MinMaxRSSI > SWAntDiv_threshold)
pDM_SWAT_Table->Train_time_flag=0;
else
pDM_SWAT_Table->Train_time_flag=3;
}
}
else if((LocalMaxRSSI-LocalMinRSSI)>5)
pDM_SWAT_Table->Train_time_flag=2;
else if((LocalMaxRSSI-LocalMinRSSI)>2)
pDM_SWAT_Table->Train_time_flag=1;
else
pDM_SWAT_Table->Train_time_flag=0;
}
//2 Select TX Antenna
if(TargetAnt == MAIN_ANT)
pDM_FatTable->antsel_a[i] = ANT1_2G;
else
pDM_FatTable->antsel_a[i] = ANT2_2G;
}
pDM_FatTable->MainAnt_Sum[i] = 0;
pDM_FatTable->AuxAnt_Sum[i] = 0;
pDM_FatTable->MainAnt_Cnt[i] = 0;
pDM_FatTable->AuxAnt_Cnt[i] = 0;
}
if(pDM_SWAT_Table->bSWAntDivByCtrlFrame)
{
odm_S0S1_SwAntDivByCtrlFrame(pDM_Odm, SWAW_STEP_DETERMINE);
bByCtrlFrame = TRUE;
}
pkt_cnt_total = pDM_FatTable->CCK_counter_main + pDM_FatTable->CCK_counter_aux +
pDM_FatTable->OFDM_counter_main + pDM_FatTable->OFDM_counter_aux;
pDM_FatTable->CCK_counter_main=0;
pDM_FatTable->CCK_counter_aux=0;
pDM_FatTable->OFDM_counter_main=0;
pDM_FatTable->OFDM_counter_aux=0;
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD,("Control frame packet counter = %d, Data frame packet counter = %llu\n",
pDM_SWAT_Table->PktCnt_SWAntDivByCtrlFrame, pkt_cnt_total));
if(MinMaxRSSI == 0xff || ((pkt_cnt_total < (pDM_SWAT_Table->PktCnt_SWAntDivByCtrlFrame >> 1)) && pDM_Odm->PhyDbgInfo.NumQryBeaconPkt < 2))
{
MinMaxRSSI = 0;
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD,("Check RSSI of control frame because MinMaxRSSI == 0xff\n"));
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD,("bByCtrlFrame = %d\n", bByCtrlFrame));
if(bByCtrlFrame)
{
Main_RSSI = (pDM_FatTable->MainAnt_CtrlFrame_Cnt!=0)?(pDM_FatTable->MainAnt_CtrlFrame_Sum/pDM_FatTable->MainAnt_CtrlFrame_Cnt):0;
Aux_RSSI = (pDM_FatTable->AuxAnt_CtrlFrame_Cnt!=0)?(pDM_FatTable->AuxAnt_CtrlFrame_Sum/pDM_FatTable->AuxAnt_CtrlFrame_Cnt):0;
if(pDM_FatTable->MainAnt_CtrlFrame_Cnt<=1 && pDM_FatTable->CCK_CtrlFrame_Cnt_main>=1)
Main_RSSI=0;
if(pDM_FatTable->AuxAnt_CtrlFrame_Cnt<=1 && pDM_FatTable->CCK_CtrlFrame_Cnt_aux>=1)
Aux_RSSI=0;
if (Main_RSSI != 0 || Aux_RSSI != 0)
{
RxIdleAnt = (Main_RSSI==Aux_RSSI)?pDM_SWAT_Table->PreAntenna:((Main_RSSI>=Aux_RSSI)?MAIN_ANT:AUX_ANT);
LocalMaxRSSI = (Main_RSSI>=Aux_RSSI) ? Main_RSSI : Aux_RSSI;
LocalMinRSSI = (Main_RSSI>=Aux_RSSI) ? Aux_RSSI : Main_RSSI;
if((LocalMaxRSSI-LocalMinRSSI)>8)
pDM_SWAT_Table->Train_time_flag=3;
else if((LocalMaxRSSI-LocalMinRSSI)>5)
pDM_SWAT_Table->Train_time_flag=2;
else if((LocalMaxRSSI-LocalMinRSSI)>2)
pDM_SWAT_Table->Train_time_flag=1;
else
pDM_SWAT_Table->Train_time_flag=0;
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD,("Control frame: Main_RSSI = %d, Aux_RSSI = %d\n", Main_RSSI, Aux_RSSI));
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD,("RxIdleAnt decided by control frame = %s\n", (RxIdleAnt == MAIN_ANT?"MAIN":"AUX")));
}
}
}
pDM_FatTable->MinMaxRSSI = MinMaxRSSI;
pDM_SWAT_Table->try_flag = 0;
if( pDM_SWAT_Table->Double_chk_flag==1)
{
pDM_SWAT_Table->Double_chk_flag=0;
if(pDM_FatTable->MinMaxRSSI > SWAntDiv_threshold)
{
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD,(" [Double check] MinMaxRSSI ((%d)) > %d again!! \n",
pDM_FatTable->MinMaxRSSI,SWAntDiv_threshold));
ODM_UpdateRxIdleAnt(pDM_Odm, RxIdleAnt);
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD,("[reset try_flag = 0] Training accomplished !!!] \n\n\n"));
return;
}
else
{
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD,(" [Double check] MinMaxRSSI ((%d)) <= %d !! \n",
pDM_FatTable->MinMaxRSSI,SWAntDiv_threshold));
nextAnt = (pDM_FatTable->RxIdleAnt == MAIN_ANT)? AUX_ANT : MAIN_ANT;
pDM_SWAT_Table->try_flag = 0;
pDM_SWAT_Table->reset_idx=reset_period;
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD,("[set try_flag=0] Normal State: Need to tryg again!! \n\n\n"));
return;
}
}
else
{
if(pDM_FatTable->MinMaxRSSI < SWAntDiv_threshold)
pDM_SWAT_Table->reset_idx=reset_period;
pDM_SWAT_Table->PreAntenna =RxIdleAnt;
ODM_UpdateRxIdleAnt(pDM_Odm, RxIdleAnt );
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD,("[reset try_flag = 0] Training accomplished !!!] \n\n\n"));
return;
}
}
}
//1 4.Change TRX antenna
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("RSSI_Trying = (( %d )), Ant: (( %s )) >>> (( %s )) \n",
pDM_SWAT_Table->RSSI_Trying, (pDM_FatTable->RxIdleAnt == MAIN_ANT?"MAIN":"AUX"),(nextAnt == MAIN_ANT?"MAIN":"AUX")));
ODM_UpdateRxIdleAnt(pDM_Odm, nextAnt);
//1 5.Reset Statistics
pDM_FatTable->RxIdleAnt = nextAnt;
//1 6.Set next timer (Trying State)
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, (" Test ((%s)) Ant for (( %d )) ms \n", (nextAnt == MAIN_ANT?"MAIN":"AUX"), pDM_SWAT_Table->Train_time));
ODM_SetTimer(pDM_Odm,&pDM_SWAT_Table->SwAntennaSwitchTimer_8723B, pDM_SWAT_Table->Train_time ); //ms
}
#if (DM_ODM_SUPPORT_TYPE == ODM_WIN)
VOID
ODM_SW_AntDiv_Callback(
PRT_TIMER pTimer
)
{
PADAPTER Adapter = (PADAPTER)pTimer->Adapter;
HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
pSWAT_T pDM_SWAT_Table = &pHalData->DM_OutSrc.DM_SWAT_Table;
#if DEV_BUS_TYPE==RT_PCI_INTERFACE
#if USE_WORKITEM
ODM_ScheduleWorkItem(&pDM_SWAT_Table->SwAntennaSwitchWorkitem_8723B);
#else
{
//DbgPrint("SW_antdiv_Callback");
odm_S0S1_SwAntDiv(&pHalData->DM_OutSrc, SWAW_STEP_DETERMINE);
}
#endif
#else
ODM_ScheduleWorkItem(&pDM_SWAT_Table->SwAntennaSwitchWorkitem_8723B);
#endif
}
VOID
ODM_SW_AntDiv_WorkitemCallback(
IN PVOID pContext
)
{
PADAPTER pAdapter = (PADAPTER)pContext;
HAL_DATA_TYPE *pHalData = GET_HAL_DATA(pAdapter);
//DbgPrint("SW_antdiv_Workitem_Callback");
odm_S0S1_SwAntDiv(&pHalData->DM_OutSrc, SWAW_STEP_DETERMINE);
}
#elif (DM_ODM_SUPPORT_TYPE == ODM_CE)
VOID
ODM_SW_AntDiv_WorkitemCallback(
IN PVOID pContext
)
{
PADAPTER
pAdapter = (PADAPTER)pContext;
HAL_DATA_TYPE
*pHalData = GET_HAL_DATA(pAdapter);
/*DbgPrint("SW_antdiv_Workitem_Callback");*/
odm_S0S1_SwAntDiv(&pHalData->odmpriv, SWAW_STEP_DETERMINE);
}
VOID
ODM_SW_AntDiv_Callback(void *FunctionContext)
{
PDM_ODM_T pDM_Odm= (PDM_ODM_T)FunctionContext;
PADAPTER padapter = pDM_Odm->Adapter;
if(padapter->net_closed == _TRUE)
return;
#if 0 /* Can't do I/O in timer callback*/
odm_S0S1_SwAntDiv(pDM_Odm, SWAW_STEP_DETERMINE);
#else
rtw_run_in_thread_cmd(padapter, ODM_SW_AntDiv_WorkitemCallback, padapter);
#endif
}
#endif
VOID
odm_S0S1_SwAntDivByCtrlFrame(
IN PVOID pDM_VOID,
IN u1Byte Step
)
{
PDM_ODM_T pDM_Odm = (PDM_ODM_T)pDM_VOID;
pSWAT_T pDM_SWAT_Table = &pDM_Odm->DM_SWAT_Table;
pFAT_T pDM_FatTable = &pDM_Odm->DM_FatTable;
switch(Step)
{
case SWAW_STEP_PEEK:
pDM_SWAT_Table->PktCnt_SWAntDivByCtrlFrame = 0;
pDM_SWAT_Table->bSWAntDivByCtrlFrame = TRUE;
pDM_FatTable->MainAnt_CtrlFrame_Cnt = 0;
pDM_FatTable->AuxAnt_CtrlFrame_Cnt = 0;
pDM_FatTable->MainAnt_CtrlFrame_Sum = 0;
pDM_FatTable->AuxAnt_CtrlFrame_Sum = 0;
pDM_FatTable->CCK_CtrlFrame_Cnt_main = 0;
pDM_FatTable->CCK_CtrlFrame_Cnt_aux = 0;
pDM_FatTable->OFDM_CtrlFrame_Cnt_main = 0;
pDM_FatTable->OFDM_CtrlFrame_Cnt_aux = 0;
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD,("odm_S0S1_SwAntDivForAPMode(): Start peak and reset counter\n"));
break;
case SWAW_STEP_DETERMINE:
pDM_SWAT_Table->bSWAntDivByCtrlFrame = FALSE;
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD,("odm_S0S1_SwAntDivForAPMode(): Stop peak\n"));
break;
default:
pDM_SWAT_Table->bSWAntDivByCtrlFrame = FALSE;
break;
}
}
VOID
odm_AntselStatisticsOfCtrlFrame(
IN PVOID pDM_VOID,
IN u1Byte antsel_tr_mux,
IN u4Byte RxPWDBAll
)
{
PDM_ODM_T pDM_Odm = (PDM_ODM_T)pDM_VOID;
pFAT_T pDM_FatTable = &pDM_Odm->DM_FatTable;
if(antsel_tr_mux == ANT1_2G)
{
pDM_FatTable->MainAnt_CtrlFrame_Sum+=RxPWDBAll;
pDM_FatTable->MainAnt_CtrlFrame_Cnt++;
}
else
{
pDM_FatTable->AuxAnt_CtrlFrame_Sum+=RxPWDBAll;
pDM_FatTable->AuxAnt_CtrlFrame_Cnt++;
}
}
VOID
odm_S0S1_SwAntDivByCtrlFrame_ProcessRSSI(
IN PVOID pDM_VOID,
IN PVOID p_phy_info_void,
IN PVOID p_pkt_info_void
//IN PODM_PHY_INFO_T pPhyInfo,
//IN PODM_PACKET_INFO_T pPktinfo
)
{
PDM_ODM_T pDM_Odm = (PDM_ODM_T)pDM_VOID;
PODM_PHY_INFO_T pPhyInfo=(PODM_PHY_INFO_T)p_phy_info_void;
PODM_PACKET_INFO_T pPktinfo=(PODM_PACKET_INFO_T)p_pkt_info_void;
pSWAT_T pDM_SWAT_Table = &pDM_Odm->DM_SWAT_Table;
pFAT_T pDM_FatTable = &pDM_Odm->DM_FatTable;
BOOLEAN isCCKrate;
if(!(pDM_Odm->SupportAbility & ODM_BB_ANT_DIV))
return;
if(pDM_Odm->AntDivType != S0S1_SW_ANTDIV)
return;
// In try state
if(!pDM_SWAT_Table->bSWAntDivByCtrlFrame)
return;
// No HW error and match receiver address
if(!pPktinfo->bToSelf)
return;
pDM_SWAT_Table->PktCnt_SWAntDivByCtrlFrame++;
isCCKrate = ((pPktinfo->DataRate >= DESC_RATE1M ) && (pPktinfo->DataRate <= DESC_RATE11M ))?TRUE :FALSE;
if(isCCKrate)
{
pDM_FatTable->antsel_rx_keep_0 = (pDM_FatTable->RxIdleAnt == MAIN_ANT) ? ANT1_2G : ANT2_2G;
if(pDM_FatTable->antsel_rx_keep_0==ANT1_2G)
pDM_FatTable->CCK_CtrlFrame_Cnt_main++;
else
pDM_FatTable->CCK_CtrlFrame_Cnt_aux++;
odm_AntselStatisticsOfCtrlFrame(pDM_Odm, pDM_FatTable->antsel_rx_keep_0, pPhyInfo->RxMIMOSignalStrength[ODM_RF_PATH_A]);
}
else
{
if(pDM_FatTable->antsel_rx_keep_0==ANT1_2G)
pDM_FatTable->OFDM_CtrlFrame_Cnt_main++;
else
pDM_FatTable->OFDM_CtrlFrame_Cnt_aux++;
odm_AntselStatisticsOfCtrlFrame(pDM_Odm, pDM_FatTable->antsel_rx_keep_0, pPhyInfo->RxPWDBAll);
}
}
#endif //#if (RTL8723B_SUPPORT == 1)||(RTL8821A_SUPPORT == 1)
VOID
odm_SetNextMACAddrTarget(
IN PVOID pDM_VOID
)
{
PDM_ODM_T pDM_Odm = (PDM_ODM_T)pDM_VOID;
pFAT_T pDM_FatTable = &pDM_Odm->DM_FatTable;
PSTA_INFO_T pEntry;
u4Byte value32, i;
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("odm_SetNextMACAddrTarget() ==>\n"));
if (pDM_Odm->bLinked)
{
for (i = 0; i < ODM_ASSOCIATE_ENTRY_NUM; i++) {
if ((pDM_FatTable->TrainIdx+1) == ODM_ASSOCIATE_ENTRY_NUM)
pDM_FatTable->TrainIdx = 0;
else
pDM_FatTable->TrainIdx++;
pEntry = pDM_Odm->pODM_StaInfo[pDM_FatTable->TrainIdx];
if (IS_STA_VALID(pEntry)) {
/*Match MAC ADDR*/
#if (DM_ODM_SUPPORT_TYPE & (ODM_AP | ODM_CE))
value32 = (pEntry->hwaddr[5]<<8)|pEntry->hwaddr[4];
#else
value32 = (pEntry->MacAddr[5]<<8)|pEntry->MacAddr[4];
#endif
ODM_SetMACReg(pDM_Odm, 0x7b4, 0xFFFF, value32);/*0x7b4~0x7b5*/
#if (DM_ODM_SUPPORT_TYPE & (ODM_AP | ODM_CE))
value32 = (pEntry->hwaddr[3]<<24)|(pEntry->hwaddr[2]<<16) |(pEntry->hwaddr[1]<<8) |pEntry->hwaddr[0];
#else
value32 = (pEntry->MacAddr[3]<<24)|(pEntry->MacAddr[2]<<16) |(pEntry->MacAddr[1]<<8) |pEntry->MacAddr[0];
#endif
ODM_SetMACReg(pDM_Odm, 0x7b0, bMaskDWord, value32);/*0x7b0~0x7b3*/
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("pDM_FatTable->TrainIdx=%d\n", pDM_FatTable->TrainIdx));
#if (DM_ODM_SUPPORT_TYPE & (ODM_AP | ODM_CE))
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("Training MAC Addr = %x:%x:%x:%x:%x:%x\n",
pEntry->hwaddr[5], pEntry->hwaddr[4], pEntry->hwaddr[3], pEntry->hwaddr[2], pEntry->hwaddr[1], pEntry->hwaddr[0]));
#else
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("Training MAC Addr = %x:%x:%x:%x:%x:%x\n",
pEntry->MacAddr[5], pEntry->MacAddr[4], pEntry->MacAddr[3], pEntry->MacAddr[2], pEntry->MacAddr[1], pEntry->MacAddr[0]));
#endif
break;
}
}
}
#if 0
//
//2012.03.26 LukeLee: This should be removed later, the MAC address is changed according to MACID in turn
//
#if( DM_ODM_SUPPORT_TYPE & ODM_WIN)
{
PADAPTER Adapter = pDM_Odm->Adapter;
PMGNT_INFO pMgntInfo = &Adapter->MgntInfo;
for (i=0; i<6; i++)
{
Bssid[i] = pMgntInfo->Bssid[i];
//DbgPrint("Bssid[%d]=%x\n", i, Bssid[i]);
}
}
#endif
//odm_SetNextMACAddrTarget(pDM_Odm);
//1 Select MAC Address Filter
for (i=0; i<6; i++)
{
if(Bssid[i] != pDM_FatTable->Bssid[i])
{
bMatchBSSID = FALSE;
break;
}
}
if(bMatchBSSID == FALSE)
{
//Match MAC ADDR
value32 = (Bssid[5]<<8)|Bssid[4];
ODM_SetMACReg(pDM_Odm, 0x7b4, 0xFFFF, value32);
value32 = (Bssid[3]<<24)|(Bssid[2]<<16) |(Bssid[1]<<8) |Bssid[0];
ODM_SetMACReg(pDM_Odm, 0x7b0, bMaskDWord, value32);
}
return bMatchBSSID;
#endif
}
#if (defined(CONFIG_5G_CG_SMART_ANT_DIVERSITY)) || (defined(CONFIG_2G_CG_SMART_ANT_DIVERSITY))
VOID
odm_FastAntTraining(
IN PVOID pDM_VOID
)
{
PDM_ODM_T pDM_Odm = (PDM_ODM_T)pDM_VOID;
pFAT_T pDM_FatTable = &pDM_Odm->DM_FatTable;
u4Byte MaxRSSI_pathA=0, Pckcnt_pathA=0;
u1Byte i,TargetAnt_pathA=0;
BOOLEAN bPktFilterMacth_pathA = FALSE;
#if(RTL8192E_SUPPORT == 1)
u4Byte MaxRSSI_pathB=0, Pckcnt_pathB=0;
u1Byte TargetAnt_pathB=0;
BOOLEAN bPktFilterMacth_pathB = FALSE;
#endif
if(!pDM_Odm->bLinked) //bLinked==False
{
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("[No Link!!!]\n"));
if(pDM_FatTable->bBecomeLinked == TRUE)
{
odm_AntDiv_on_off(pDM_Odm, ANTDIV_OFF);
phydm_FastTraining_enable(pDM_Odm , FAT_OFF);
odm_Tx_By_TxDesc_or_Reg(pDM_Odm , REG);
pDM_FatTable->bBecomeLinked = pDM_Odm->bLinked;
}
return;
}
else
{
if(pDM_FatTable->bBecomeLinked ==FALSE)
{
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("[Linked!!!]\n"));
odm_Tx_By_TxDesc_or_Reg(pDM_Odm , TX_BY_DESC);
pDM_FatTable->bBecomeLinked = pDM_Odm->bLinked;
}
}
if(pDM_Odm->SupportICType == ODM_RTL8188E)
{
ODM_SetBBReg(pDM_Odm, 0x864 , BIT2|BIT1|BIT0, ((pDM_Odm->fat_comb_a)-1));
}
#if(RTL8192E_SUPPORT == 1)
else if(pDM_Odm->SupportICType == ODM_RTL8192E)
{
ODM_SetBBReg(pDM_Odm, 0xB38 , BIT2|BIT1|BIT0, ((pDM_Odm->fat_comb_a)-1) ); //path-A // ant combination=regB38[2:0]+1
ODM_SetBBReg(pDM_Odm, 0xB38 , BIT18|BIT17|BIT16, ((pDM_Odm->fat_comb_b)-1) ); //path-B // ant combination=regB38[18:16]+1
}
#endif
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("==>odm_FastAntTraining()\n"));
//1 TRAINING STATE
if(pDM_FatTable->FAT_State == FAT_TRAINING_STATE)
{
//2 Caculate RSSI per Antenna
//3 [path-A]---------------------------
for (i=0; i<(pDM_Odm->fat_comb_a); i++) // i : antenna index
{
if(pDM_FatTable->antRSSIcnt[i] == 0)
pDM_FatTable->antAveRSSI[i] = 0;
else
{
pDM_FatTable->antAveRSSI[i] = pDM_FatTable->antSumRSSI[i] /pDM_FatTable->antRSSIcnt[i];
bPktFilterMacth_pathA = TRUE;
}
if(pDM_FatTable->antAveRSSI[i] > MaxRSSI_pathA)
{
MaxRSSI_pathA = pDM_FatTable->antAveRSSI[i];
Pckcnt_pathA = pDM_FatTable ->antRSSIcnt[i];
TargetAnt_pathA = i ;
}
else if(pDM_FatTable->antAveRSSI[i] == MaxRSSI_pathA)
{
if( (pDM_FatTable->antRSSIcnt[i] ) > Pckcnt_pathA)
{
MaxRSSI_pathA = pDM_FatTable->antAveRSSI[i];
Pckcnt_pathA = pDM_FatTable ->antRSSIcnt[i];
TargetAnt_pathA = i ;
}
}
ODM_RT_TRACE("*** Ant-Index : [ %d ], Counter = (( %d )), Avg RSSI = (( %d )) \n", i, pDM_FatTable->antRSSIcnt[i], pDM_FatTable->antAveRSSI[i] );
}
/*
#if(RTL8192E_SUPPORT == 1)
//3 [path-B]---------------------------
for (i=0; i<(pDM_Odm->fat_comb_b); i++)
{
if(pDM_FatTable->antRSSIcnt_pathB[i] == 0)
pDM_FatTable->antAveRSSI_pathB[i] = 0;
else // (antRSSIcnt[i] != 0)
{
pDM_FatTable->antAveRSSI_pathB[i] = pDM_FatTable->antSumRSSI_pathB[i] /pDM_FatTable->antRSSIcnt_pathB[i];
bPktFilterMacth_pathB = TRUE;
}
if(pDM_FatTable->antAveRSSI_pathB[i] > MaxRSSI_pathB)
{
MaxRSSI_pathB = pDM_FatTable->antAveRSSI_pathB[i];
Pckcnt_pathB = pDM_FatTable ->antRSSIcnt_pathB[i];
TargetAnt_pathB = (u1Byte) i;
}
if(pDM_FatTable->antAveRSSI_pathB[i] == MaxRSSI_pathB)
{
if(pDM_FatTable ->antRSSIcnt_pathB > Pckcnt_pathB)
{
MaxRSSI_pathB = pDM_FatTable->antAveRSSI_pathB[i];
TargetAnt_pathB = (u1Byte) i;
}
}
if (pDM_Odm->fat_print_rssi==1)
{
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("***{Path-B}: Sum RSSI[%d] = (( %d )), cnt RSSI [%d] = (( %d )), Avg RSSI[%d] = (( %d )) \n",
i, pDM_FatTable->antSumRSSI_pathB[i], i, pDM_FatTable->antRSSIcnt_pathB[i], i, pDM_FatTable->antAveRSSI_pathB[i]));
}
}
#endif
*/
//1 DECISION STATE
//2 Select TRX Antenna
phydm_FastTraining_enable(pDM_Odm, FAT_OFF);
//3 [path-A]---------------------------
if(bPktFilterMacth_pathA == FALSE)
{
//ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("{Path-A}: None Packet is matched\n"));
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("{Path-A}: None Packet is matched\n"));
odm_AntDiv_on_off(pDM_Odm, ANTDIV_OFF);
}
else
{
ODM_RT_TRACE("TargetAnt_pathA = (( %d )) , MaxRSSI_pathA = (( %d )) \n",TargetAnt_pathA,MaxRSSI_pathA);
//3 [ update RX-optional ant ] Default RX is Omni, Optional RX is the best decision by FAT
if(pDM_Odm->SupportICType == ODM_RTL8188E)
{
ODM_SetBBReg(pDM_Odm, 0x864 , BIT8|BIT7|BIT6, TargetAnt_pathA);
}
else if(pDM_Odm->SupportICType == ODM_RTL8192E)
{
ODM_SetBBReg(pDM_Odm, 0xB38 , BIT8|BIT7|BIT6, TargetAnt_pathA);//Optional RX [pth-A]
}
//3 [ update TX ant ]
odm_UpdateTxAnt(pDM_Odm, TargetAnt_pathA, (pDM_FatTable->TrainIdx));
if(TargetAnt_pathA == 0)
odm_AntDiv_on_off(pDM_Odm, ANTDIV_OFF);
}
/*
#if(RTL8192E_SUPPORT == 1)
//3 [path-B]---------------------------
if(bPktFilterMacth_pathB == FALSE)
{
if (pDM_Odm->fat_print_rssi==1)
{
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("***[%d]{Path-B}: None Packet is matched\n\n\n",__LINE__));
}
}
else
{
if (pDM_Odm->fat_print_rssi==1)
{
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD,
(" ***TargetAnt_pathB = (( %d )) *** MaxRSSI = (( %d ))***\n\n\n",TargetAnt_pathB,MaxRSSI_pathB));
}
ODM_SetBBReg(pDM_Odm, 0xB38 , BIT21|BIT20|BIT19, TargetAnt_pathB); //Default RX is Omni, Optional RX is the best decision by FAT
ODM_SetBBReg(pDM_Odm, 0x80c , BIT21, 1); //Reg80c[21]=1'b1 //from TX Info
pDM_FatTable->antsel_pathB[pDM_FatTable->TrainIdx] = TargetAnt_pathB;
}
#endif
*/
//2 Reset Counter
for(i=0; i<(pDM_Odm->fat_comb_a); i++)
{
pDM_FatTable->antSumRSSI[i] = 0;
pDM_FatTable->antRSSIcnt[i] = 0;
}
/*
#if(RTL8192E_SUPPORT == 1)
for(i=0; i<=(pDM_Odm->fat_comb_b); i++)
{
pDM_FatTable->antSumRSSI_pathB[i] = 0;
pDM_FatTable->antRSSIcnt_pathB[i] = 0;
}
#endif
*/
pDM_FatTable->FAT_State = FAT_PREPARE_STATE;
return;
}
//1 NORMAL STATE
if (pDM_FatTable->FAT_State == FAT_PREPARE_STATE)
{
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("[ Start Prepare State ]\n"));
odm_SetNextMACAddrTarget(pDM_Odm);
//2 Prepare Training
pDM_FatTable->FAT_State = FAT_TRAINING_STATE;
phydm_FastTraining_enable(pDM_Odm , FAT_ON);
odm_AntDiv_on_off(pDM_Odm, ANTDIV_ON); //enable HW AntDiv
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("[Start Training State]\n"));
ODM_SetTimer(pDM_Odm,&pDM_Odm->FastAntTrainingTimer, pDM_Odm->antdiv_intvl ); //ms
}
}
VOID
odm_FastAntTrainingCallback(
IN PVOID pDM_VOID
)
{
PDM_ODM_T pDM_Odm = (PDM_ODM_T)pDM_VOID;
#if (DM_ODM_SUPPORT_TYPE == ODM_CE)
PADAPTER padapter = pDM_Odm->Adapter;
if(padapter->net_closed == _TRUE)
return;
//if(*pDM_Odm->pbNet_closed == TRUE)
// return;
#endif
#if USE_WORKITEM
ODM_ScheduleWorkItem(&pDM_Odm->FastAntTrainingWorkitem);
#else
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("******odm_FastAntTrainingCallback****** \n"));
odm_FastAntTraining(pDM_Odm);
#endif
}
VOID
odm_FastAntTrainingWorkItemCallback(
IN PVOID pDM_VOID
)
{
PDM_ODM_T pDM_Odm = (PDM_ODM_T)pDM_VOID;
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("******odm_FastAntTrainingWorkItemCallback****** \n"));
odm_FastAntTraining(pDM_Odm);
}
#endif
#ifdef CONFIG_HL_SMART_ANTENNA_TYPE1
u4Byte
phydm_construct_hl_beam_codeword(
IN PVOID pDM_VOID,
IN u4Byte *beam_pattern_idx,
IN u4Byte ant_num
)
{
PDM_ODM_T pDM_Odm = (PDM_ODM_T)pDM_VOID;
u4Byte codeword = 0;
u4Byte data_tmp;
u1Byte i;
if (ant_num < 8) {
for (i = 0; i < ant_num; i++) {
/*ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("beam_pattern_num[%x] = %x\n",i,beam_pattern_num[i] ));*/
if (beam_pattern_idx[i] == 0) {
data_tmp = 0x1;
/**/
} else if (beam_pattern_idx[i] == 1) {
data_tmp = 0x2;
/**/
} else if (beam_pattern_idx[i] == 2) {
data_tmp = 0x4;
/**/
} else if (beam_pattern_idx[i] == 3) {
data_tmp = 0x8;
/**/
}
codeword |= (data_tmp<<(i*4));
}
}
return codeword;
}
VOID
phydm_update_beam_pattern(
IN PVOID pDM_VOID,
IN u4Byte codeword,
IN u4Byte codeword_length
)
{
PDM_ODM_T pDM_Odm = (PDM_ODM_T)pDM_VOID;
pSAT_T pdm_sat_table = &(pDM_Odm->dm_sat_table);
u1Byte i;
BOOLEAN beam_ctrl_signal;
u4Byte one = 0x1;
u4Byte reg44_tmp_p, reg44_tmp_n, reg44_ori;
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("[ SmartAnt ] Set Beam Pattern =0x%x\n", codeword));
reg44_ori = ODM_GetMACReg(pDM_Odm, 0x44, bMaskDWord);
/*ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("reg44_ori =0x%x\n", reg44_ori));*/
for (i = 0; i <= (codeword_length-1); i++) {
beam_ctrl_signal = (BOOLEAN)((codeword&BIT(i)) >> i);
if (pDM_Odm->DebugComponents & ODM_COMP_ANT_DIV) {
if (i == (codeword_length-1)) {
DbgPrint("%d ]\n", beam_ctrl_signal);
/**/
} else if (i == 0) {
DbgPrint("Send codeword[1:24] ---> [ %d ", beam_ctrl_signal);
/**/
} else if ((i % 4) == 3) {
DbgPrint("%d | ", beam_ctrl_signal);
/**/
} else {
DbgPrint("%d ", beam_ctrl_signal);
/**/
}
}
#if 1
reg44_tmp_p = reg44_ori & (~(BIT11|BIT10)); /*clean bit 10 & 11*/
reg44_tmp_p |= ((1<<11) | (beam_ctrl_signal<<10));
reg44_tmp_n = reg44_ori & (~(BIT11|BIT10));
/*ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("reg44_tmp_p =(( 0x%x )), reg44_tmp_n = (( 0x%x ))\n", reg44_tmp_p, reg44_tmp_n));*/
ODM_SetMACReg(pDM_Odm, 0x44 , bMaskDWord, reg44_tmp_p);
ODM_SetMACReg(pDM_Odm, 0x44 , bMaskDWord, reg44_tmp_n);
#else
ODM_SetMACReg(pDM_Odm, 0x44 , BIT11|BIT10, ((1<<1) | beam_ctrl_signal));
ODM_SetMACReg(pDM_Odm, 0x44 , BIT11, 0);
#endif
}
}
VOID
phydm_update_rx_idle_beam(
IN PVOID pDM_VOID
)
{
PDM_ODM_T pDM_Odm = (PDM_ODM_T)pDM_VOID;
pFAT_T pDM_FatTable = &pDM_Odm->DM_FatTable;
pSAT_T pdm_sat_table = &(pDM_Odm->dm_sat_table);
u4Byte i;
pdm_sat_table->update_beam_codeword = phydm_construct_hl_beam_codeword(pDM_Odm, &(pdm_sat_table->rx_idle_beam[0]), pdm_sat_table->ant_num);
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("Set target beam_pattern codeword = (( 0x%x ))\n", pdm_sat_table->update_beam_codeword));
for (i = 0; i < (pdm_sat_table->ant_num); i++) {
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("[ Update Rx-Idle-Beam ] RxIdleBeam[%d] =%d\n", i, pdm_sat_table->rx_idle_beam[i]));
/**/
}
#if DEV_BUS_TYPE == RT_PCI_INTERFACE
phydm_update_beam_pattern(pDM_Odm, pdm_sat_table->update_beam_codeword, pdm_sat_table->data_codeword_bit_num);
#else
ODM_ScheduleWorkItem(&pdm_sat_table->hl_smart_antenna_workitem);
/*ODM_StallExecution(1);*/
#endif
pdm_sat_table->pre_codeword = pdm_sat_table->update_beam_codeword;
}
VOID
phydm_hl_smart_ant_cmd(
IN PVOID pDM_VOID,
IN u4Byte *const dm_value,
IN u4Byte *_used,
OUT char *output,
IN u4Byte *_out_len
)
{
PDM_ODM_T pDM_Odm = (PDM_ODM_T)pDM_VOID;
pSAT_T pdm_sat_table = &(pDM_Odm->dm_sat_table);
u4Byte used = *_used;
u4Byte out_len = *_out_len;
u4Byte one = 0x1;
u4Byte codeword_length = pdm_sat_table->data_codeword_bit_num;
u4Byte beam_ctrl_signal, i;
if (dm_value[0] == 1) { /*fix beam pattern*/
pdm_sat_table->fix_beam_pattern_en = dm_value[1];
if (pdm_sat_table->fix_beam_pattern_en == 1) {
pdm_sat_table->fix_beam_pattern_codeword = dm_value[2];
if (pdm_sat_table->fix_beam_pattern_codeword > (one<<codeword_length)) {
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("[ SmartAnt ] Codeword overflow, Current codeword is ((0x%x)), and should be less than ((%d))bit\n",
pdm_sat_table->fix_beam_pattern_codeword, codeword_length));
(pdm_sat_table->fix_beam_pattern_codeword) &= 0xffffff;
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("[ SmartAnt ] Auto modify to (0x%x)\n", pdm_sat_table->fix_beam_pattern_codeword));
}
pdm_sat_table->update_beam_codeword = pdm_sat_table->fix_beam_pattern_codeword;
/*---------------------------------------------------------*/
PHYDM_SNPRINTF((output+used, out_len-used, "Fix Beam Pattern\n"));
for (i = 0; i <= (codeword_length-1); i++) {
beam_ctrl_signal = (BOOLEAN)((pdm_sat_table->update_beam_codeword&BIT(i)) >> i);
if (i == (codeword_length-1)) {
PHYDM_SNPRINTF((output+used, out_len-used, "%d]\n", beam_ctrl_signal));
/**/
} else if (i == 0) {
PHYDM_SNPRINTF((output+used, out_len-used, "Send Codeword[1:24] to RFU -> [%d", beam_ctrl_signal));
/**/
} else if ((i % 4) == 3) {
PHYDM_SNPRINTF((output+used, out_len-used, "%d|", beam_ctrl_signal));
/**/
} else {
PHYDM_SNPRINTF((output+used, out_len-used, "%d", beam_ctrl_signal));
/**/
}
}
/*---------------------------------------------------------*/
#if DEV_BUS_TYPE == RT_PCI_INTERFACE
phydm_update_beam_pattern(pDM_Odm, pdm_sat_table->update_beam_codeword, pdm_sat_table->data_codeword_bit_num);
#else
ODM_ScheduleWorkItem(&pdm_sat_table->hl_smart_antenna_workitem);
/*ODM_StallExecution(1);*/
#endif
} else if (pdm_sat_table->fix_beam_pattern_en == 0) {
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("[ SmartAnt ] Smart Antenna: Enable\n"));
}
} else if (dm_value[0] == 2) { /*set latch time*/
pdm_sat_table->latch_time = dm_value[1];
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("[ SmartAnt ] latch_time =0x%x\n", pdm_sat_table->latch_time));
} else if (dm_value[0] == 3) {
pdm_sat_table->fix_training_num_en = dm_value[1];
if (pdm_sat_table->fix_training_num_en == 1) {
pdm_sat_table->per_beam_training_pkt_num = dm_value[2];
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("[ SmartAnt ] Fix per_beam_training_pkt_num = (( 0x%x ))\n", pdm_sat_table->per_beam_training_pkt_num));
} else if (pdm_sat_table->fix_training_num_en == 0) {
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("[ SmartAnt ] AUTO per_beam_training_pkt_num\n"));
/**/
}
}
}
void
phydm_set_all_ant_same_beam_num(
IN PVOID pDM_VOID
)
{
PDM_ODM_T pDM_Odm = (PDM_ODM_T)pDM_VOID;
pSAT_T pdm_sat_table = &(pDM_Odm->dm_sat_table);
if (pDM_Odm->AntDivType == HL_SW_SMART_ANT_TYPE1) { /*2Ant for 8821A*/
pdm_sat_table->rx_idle_beam[0] = pdm_sat_table->fast_training_beam_num;
pdm_sat_table->rx_idle_beam[1] = pdm_sat_table->fast_training_beam_num;
}
pdm_sat_table->update_beam_codeword = phydm_construct_hl_beam_codeword(pDM_Odm, &(pdm_sat_table->rx_idle_beam[0]), pdm_sat_table->ant_num);
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("[ SmartAnt ] Set all ant beam_pattern: codeword = (( 0x%x ))\n", pdm_sat_table->update_beam_codeword));
#if DEV_BUS_TYPE == RT_PCI_INTERFACE
phydm_update_beam_pattern(pDM_Odm, pdm_sat_table->update_beam_codeword, pdm_sat_table->data_codeword_bit_num);
#else
ODM_ScheduleWorkItem(&pdm_sat_table->hl_smart_antenna_workitem);
/*ODM_StallExecution(1);*/
#endif
}
#if 0
void
phydm_hl_smart_antenna_test(
IN PVOID pDM_VOID
)
{
PDM_ODM_T pDM_Odm = (PDM_ODM_T)pDM_VOID;
pSAT_T pdm_sat_table = &(pDM_Odm->dm_sat_table);
pFAT_T pDM_FatTable = &(pDM_Odm->DM_FatTable);
pSWAT_T pDM_SWAT_Table = &pDM_Odm->DM_SWAT_Table;
pdm_sat_table->rx_idle_beam[0] = 0;
pdm_sat_table->rx_idle_beam[1] = 0;
codeword = phydm_construct_hl_beam_codeword(pDM_Odm, &(pdm_sat_table->rx_idle_beam[0]), pdm_sat_table->ant_num);
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("1-beam_pattern = %x\n", codeword));
phydm_update_beam_pattern(pDM_Odm, codeword, pdm_sat_table->data_codeword_bit_num);
pdm_sat_table->rx_idle_beam[0] = 1;
pdm_sat_table->rx_idle_beam[1] = 1;
codeword = phydm_construct_hl_beam_codeword(pDM_Odm, &(pdm_sat_table->rx_idle_beam[0]), pdm_sat_table->ant_num);
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("2-beam_pattern = %x\n", codeword));
phydm_update_beam_pattern(pDM_Odm, codeword, pdm_sat_table->data_codeword_bit_num);
pdm_sat_table->rx_idle_beam[0] = 2;
pdm_sat_table->rx_idle_beam[1] = 2;
codeword = phydm_construct_hl_beam_codeword(pDM_Odm, &(pdm_sat_table->rx_idle_beam[0]), pdm_sat_table->ant_num);
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("3-beam_pattern = %x\n", codeword));
phydm_update_beam_pattern(pDM_Odm, codeword, pdm_sat_table->data_codeword_bit_num);
pdm_sat_table->rx_idle_beam[0] = 3;
pdm_sat_table->rx_idle_beam[1] = 3;
codeword = phydm_construct_hl_beam_codeword(pDM_Odm, &(pdm_sat_table->rx_idle_beam[0]), pdm_sat_table->ant_num);
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("4-beam_pattern = %x\n", codeword));
phydm_update_beam_pattern(pDM_Odm, codeword, pdm_sat_table->data_codeword_bit_num);
}
#endif
VOID
odm_FastAntTraining_hl_smart_antenna_type1(
IN PVOID pDM_VOID
)
{
PDM_ODM_T pDM_Odm = (PDM_ODM_T)pDM_VOID;
pSAT_T pdm_sat_table = &(pDM_Odm->dm_sat_table);
pFAT_T pDM_FatTable = &(pDM_Odm->DM_FatTable);
pSWAT_T pDM_SWAT_Table = &pDM_Odm->DM_SWAT_Table;
u4Byte codeword = 0, i, j;
u4Byte TargetAnt;
u4Byte avg_rssi_tmp;
u4Byte target_ant_beam_max_rssi[SUPPORT_RF_PATH_NUM] = {0};
u4Byte max_beam_ant_rssi = 0;
u4Byte target_ant_beam[SUPPORT_RF_PATH_NUM] = {0};
u4Byte beam_tmp;
u1Byte traffic_state;
if (!pDM_Odm->bLinked) {
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("[No Link!!!]\n"));
if (pDM_FatTable->bBecomeLinked == TRUE) {
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("Link -> no Link\n"));
pDM_FatTable->FAT_State = FAT_BEFORE_LINK_STATE;
odm_AntDiv_on_off(pDM_Odm, ANTDIV_OFF);
odm_Tx_By_TxDesc_or_Reg(pDM_Odm , REG);
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("change to (( %d )) FAT_state\n", pDM_FatTable->FAT_State));
pDM_FatTable->bBecomeLinked = pDM_Odm->bLinked;
}
return;
} else {
if (pDM_FatTable->bBecomeLinked == FALSE) {
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("[Linked !!!]\n"));
pDM_FatTable->FAT_State = FAT_PREPARE_STATE;
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("change to (( %d )) FAT_state\n", pDM_FatTable->FAT_State));
/*pdm_sat_table->fast_training_beam_num = 0;*/
/*phydm_set_all_ant_same_beam_num(pDM_Odm);*/
odm_Tx_By_TxDesc_or_Reg(pDM_Odm, TX_BY_DESC);
pDM_SWAT_Table->lastTxOkCnt = *(pDM_Odm->pNumTxBytesUnicast);
pDM_SWAT_Table->lastRxOkCnt = *(pDM_Odm->pNumRxBytesUnicast);
pDM_FatTable->bBecomeLinked = pDM_Odm->bLinked;
}
}
/*ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("HL Smart Ant Training: State (( %d ))\n", pDM_FatTable->FAT_State));*/
/* [DECISION STATE] */
/*=======================================================================================*/
if (pDM_FatTable->FAT_State == FAT_DECISION_STATE) {
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("[ 3. In Decision State]\n"));
phydm_FastTraining_enable(pDM_Odm , FAT_OFF);
/*compute target beam in each antenna*/
for (i = 0; i < (pdm_sat_table->ant_num); i++) {
for (j = 0; j < (pdm_sat_table->beam_patten_num_each_ant); j++) {
if (pdm_sat_table->pkt_rssi_cnt[i][j] == 0) {
avg_rssi_tmp = pdm_sat_table->pkt_rssi_pre[i][j];
/**/
} else {
avg_rssi_tmp = (pdm_sat_table->pkt_rssi_sum[i][j]) / (pdm_sat_table->pkt_rssi_cnt[i][j]);
pdm_sat_table->pkt_rssi_pre[i][j] = avg_rssi_tmp;
/**/
}
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("Ant[%d], Beam[%d]: pkt_num=(( %d )), avg_rssi=(( %d ))\n", i, j, pdm_sat_table->pkt_rssi_cnt[i][j], avg_rssi_tmp));
if (avg_rssi_tmp > target_ant_beam_max_rssi[i]) {
target_ant_beam[i] = j;
target_ant_beam_max_rssi[i] = avg_rssi_tmp;
}
/*reset counter value*/
pdm_sat_table->pkt_rssi_sum[i][j] = 0;
pdm_sat_table->pkt_rssi_cnt[i][j] = 0;
}
pdm_sat_table->rx_idle_beam[i] = target_ant_beam[i];
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("---------> Target of Ant[%d]: Beam_num-(( %d )) RSSI= ((%d))\n",
i, target_ant_beam[i], target_ant_beam_max_rssi[i]));
if (target_ant_beam_max_rssi[i] > max_beam_ant_rssi) {
TargetAnt = i;
max_beam_ant_rssi = target_ant_beam_max_rssi[i];
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("Target of Ant = (( %d )) max_beam_ant_rssi = (( %d ))\n",
TargetAnt, max_beam_ant_rssi));
}
}
if (TargetAnt == 0)
TargetAnt = MAIN_ANT;
else if (TargetAnt == 1)
TargetAnt = AUX_ANT;
/* [ update RX ant ]*/
ODM_UpdateRxIdleAnt(pDM_Odm, (u1Byte)TargetAnt);
/* [ update TX ant ]*/
odm_UpdateTxAnt(pDM_Odm, (u1Byte)TargetAnt, (pDM_FatTable->TrainIdx));
/*set beam in each antenna*/
phydm_update_rx_idle_beam(pDM_Odm);
phydm_FastTraining_enable(pDM_Odm , FAT_OFF);
odm_AntDiv_on_off(pDM_Odm, ANTDIV_ON);
pDM_FatTable->FAT_State = FAT_PREPARE_STATE;
}
/* [TRAINING STATE] */
else if (pDM_FatTable->FAT_State == FAT_TRAINING_STATE) {
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("[ 2. In Training State]\n"));
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("fat_beam_n = (( %d )), pre_fat_beam_n = (( %d ))\n",
pdm_sat_table->fast_training_beam_num, pdm_sat_table->pre_fast_training_beam_num));
if (pdm_sat_table->fast_training_beam_num > pdm_sat_table->pre_fast_training_beam_num) {
pdm_sat_table->force_update_beam_en = 0;
} else {
pdm_sat_table->force_update_beam_en = 1;
pdm_sat_table->pkt_counter = 0;
beam_tmp = pdm_sat_table->fast_training_beam_num;
if (pdm_sat_table->fast_training_beam_num >= (pdm_sat_table->beam_patten_num_each_ant-1)) {
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("[Timeout Update] Beam_num (( %d )) -> (( decision ))\n", pdm_sat_table->fast_training_beam_num));
phydm_FastTraining_enable(pDM_Odm , FAT_OFF);
pDM_FatTable->FAT_State = FAT_DECISION_STATE;
odm_FastAntTraining_hl_smart_antenna_type1(pDM_Odm);
} else {
pdm_sat_table->fast_training_beam_num++;
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("[Timeout Update] Beam_num (( %d )) -> (( %d ))\n", beam_tmp, pdm_sat_table->fast_training_beam_num));
phydm_set_all_ant_same_beam_num(pDM_Odm);
pDM_FatTable->FAT_State = FAT_TRAINING_STATE;
}
}
pdm_sat_table->pre_fast_training_beam_num = pdm_sat_table->fast_training_beam_num;
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("Update Pre_Beam =(( %d ))\n", pdm_sat_table->pre_fast_training_beam_num));
}
/* [Prepare State] */
/*=======================================================================================*/
else if (pDM_FatTable->FAT_State == FAT_PREPARE_STATE) {
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("\n\n[ 1. In Prepare State]\n"));
traffic_state = phydm_traffic_load_decision(pDM_Odm);
if (pdm_sat_table->pre_traffic_state == traffic_state) {
if (pdm_sat_table->decision_holding_period != 0) {
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("Holding_period = (( %d )), return!!!\n", pdm_sat_table->decision_holding_period));
pdm_sat_table->decision_holding_period--;
return;
}
}
pdm_sat_table->pre_traffic_state = traffic_state;
/* Set training packet number*/
if (pdm_sat_table->fix_training_num_en == 0) {
switch (traffic_state) {
case TRAFFIC_HIGH:
pdm_sat_table->per_beam_training_pkt_num = 20;
pdm_sat_table->decision_holding_period = 0;
break;
case TRAFFIC_MID:
pdm_sat_table->per_beam_training_pkt_num = 10;
pdm_sat_table->decision_holding_period = 1;
break;
case TRAFFIC_LOW:
pdm_sat_table->per_beam_training_pkt_num = 5; /*ping 60000*/
pdm_sat_table->decision_holding_period = 3;
break;
case TRAFFIC_ULTRA_LOW:
pdm_sat_table->per_beam_training_pkt_num = 2;
pdm_sat_table->decision_holding_period = 5;
break;
default:
break;
}
}
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("Fix_training_num = (( %d )), per_beam_training_pkt_num = (( %d ))\n",
pdm_sat_table->fix_training_num_en , pdm_sat_table->per_beam_training_pkt_num));
/* Set training MAC Addr. of target */
odm_SetNextMACAddrTarget(pDM_Odm);
phydm_FastTraining_enable(pDM_Odm , FAT_ON);
odm_AntDiv_on_off(pDM_Odm, ANTDIV_OFF);
pdm_sat_table->pkt_counter = 0;
pdm_sat_table->fast_training_beam_num = 0;
phydm_set_all_ant_same_beam_num(pDM_Odm);
pdm_sat_table->pre_fast_training_beam_num = pdm_sat_table->fast_training_beam_num;
pDM_FatTable->FAT_State = FAT_TRAINING_STATE;
}
}
#if (DM_ODM_SUPPORT_TYPE == ODM_WIN)
VOID
phydm_beam_switch_workitem_callback(
IN PVOID pContext
)
{
PADAPTER pAdapter = (PADAPTER)pContext;
HAL_DATA_TYPE *pHalData = GET_HAL_DATA(pAdapter);
PDM_ODM_T pDM_Odm = &pHalData->DM_OutSrc;
pSAT_T pdm_sat_table = &(pDM_Odm->dm_sat_table);
#if DEV_BUS_TYPE != RT_PCI_INTERFACE
pdm_sat_table->pkt_skip_statistic_en = 1;
#endif
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("[ SmartAnt ] Beam Switch Workitem Callback, pkt_skip_statistic_en = (( %d ))\n", pdm_sat_table->pkt_skip_statistic_en));
phydm_update_beam_pattern(pDM_Odm, pdm_sat_table->update_beam_codeword, pdm_sat_table->data_codeword_bit_num);
#if DEV_BUS_TYPE != RT_PCI_INTERFACE
/*ODM_StallExecution(pdm_sat_table->latch_time);*/
pdm_sat_table->pkt_skip_statistic_en = 0;
#endif
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("pkt_skip_statistic_en = (( %d )), latch_time = (( %d ))\n", pdm_sat_table->pkt_skip_statistic_en, pdm_sat_table->latch_time));
}
VOID
phydm_beam_decision_workitem_callback(
IN PVOID pContext
)
{
PADAPTER pAdapter = (PADAPTER)pContext;
HAL_DATA_TYPE *pHalData = GET_HAL_DATA(pAdapter);
PDM_ODM_T pDM_Odm = &pHalData->DM_OutSrc;
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("[ SmartAnt ] Beam decision Workitem Callback\n"));
odm_FastAntTraining_hl_smart_antenna_type1(pDM_Odm);
}
#endif
#endif /*#ifdef CONFIG_HL_SMART_ANTENNA_TYPE1*/
VOID
ODM_AntDivInit(
IN PVOID pDM_VOID
)
{
PDM_ODM_T pDM_Odm = (PDM_ODM_T)pDM_VOID;
pFAT_T pDM_FatTable = &pDM_Odm->DM_FatTable;
pSWAT_T pDM_SWAT_Table = &pDM_Odm->DM_SWAT_Table;
if(!(pDM_Odm->SupportAbility & ODM_BB_ANT_DIV))
{
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV,ODM_DBG_LOUD,("[Return!!!] Not Support Antenna Diversity Function\n"));
return;
}
//---
#if (DM_ODM_SUPPORT_TYPE == ODM_AP)
if(pDM_FatTable->AntDiv_2G_5G == ODM_ANTDIV_2G)
{
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV,ODM_DBG_LOUD,("[2G AntDiv Init]: Only Support 2G Antenna Diversity Function\n"));
if(!(pDM_Odm->SupportICType & ODM_ANTDIV_2G_SUPPORT_IC))
return;
}
else if(pDM_FatTable->AntDiv_2G_5G == ODM_ANTDIV_5G)
{
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV,ODM_DBG_LOUD,("[5G AntDiv Init]: Only Support 5G Antenna Diversity Function\n"));
if(!(pDM_Odm->SupportICType & ODM_ANTDIV_5G_SUPPORT_IC))
return;
}
else if(pDM_FatTable->AntDiv_2G_5G == (ODM_ANTDIV_2G|ODM_ANTDIV_5G))
{
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV,ODM_DBG_LOUD,("[2G & 5G AntDiv Init]:Support Both 2G & 5G Antenna Diversity Function\n"));
}
#endif
//---
//2 [--General---]
pDM_Odm->antdiv_period=0;
pDM_FatTable->bBecomeLinked =FALSE;
pDM_FatTable->AntDiv_OnOff =0xff;
//3 - AP -
#if (DM_ODM_SUPPORT_TYPE == ODM_AP)
#ifdef BEAMFORMING_SUPPORT
#if(DM_ODM_SUPPORT_TYPE == ODM_AP)
odm_BDC_Init(pDM_Odm);
#endif
#endif
//3 - WIN -
#elif (DM_ODM_SUPPORT_TYPE == ODM_WIN)
pDM_SWAT_Table->Ant5G = MAIN_ANT;
pDM_SWAT_Table->Ant2G = MAIN_ANT;
pDM_FatTable->CCK_counter_main=0;
pDM_FatTable->CCK_counter_aux=0;
pDM_FatTable->OFDM_counter_main=0;
pDM_FatTable->OFDM_counter_aux=0;
#endif
//2 [---Set MAIN_ANT as default antenna if Auto-Ant enable---]
odm_AntDiv_on_off(pDM_Odm, ANTDIV_OFF);
pDM_Odm->AntType = ODM_AUTO_ANT;
pDM_FatTable->RxIdleAnt = ANTDIV_INIT;
ODM_UpdateRxIdleAnt(pDM_Odm, MAIN_ANT);
//2 [---Set TX Antenna---]
odm_Tx_By_TxDesc_or_Reg(pDM_Odm , REG);
//2 [--88E---]
if(pDM_Odm->SupportICType == ODM_RTL8188E)
{
#if (RTL8188E_SUPPORT == 1)
//pDM_Odm->AntDivType = CGCS_RX_HW_ANTDIV;
//pDM_Odm->AntDivType = CG_TRX_HW_ANTDIV;
//pDM_Odm->AntDivType = CG_TRX_SMART_ANTDIV;
if( (pDM_Odm->AntDivType != CGCS_RX_HW_ANTDIV) && (pDM_Odm->AntDivType != CG_TRX_HW_ANTDIV) && (pDM_Odm->AntDivType != CG_TRX_SMART_ANTDIV))
{
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV,ODM_DBG_LOUD,("[Return!!!] 88E Not Supprrt This AntDiv Type\n"));
pDM_Odm->SupportAbility &= ~(ODM_BB_ANT_DIV);
return;
}
if(pDM_Odm->AntDivType == CGCS_RX_HW_ANTDIV)
odm_RX_HWAntDiv_Init_88E(pDM_Odm);
else if(pDM_Odm->AntDivType == CG_TRX_HW_ANTDIV)
odm_TRX_HWAntDiv_Init_88E(pDM_Odm);
#if( defined(CONFIG_5G_CG_SMART_ANT_DIVERSITY) ) ||( defined(CONFIG_2G_CG_SMART_ANT_DIVERSITY) )
else if(pDM_Odm->AntDivType == CG_TRX_SMART_ANTDIV)
odm_Smart_HWAntDiv_Init_88E(pDM_Odm);
#endif
#endif
}
//2 [--92E---]
#if (RTL8192E_SUPPORT == 1)
else if(pDM_Odm->SupportICType == ODM_RTL8192E)
{
//pDM_Odm->AntDivType = CGCS_RX_HW_ANTDIV;
//pDM_Odm->AntDivType = CG_TRX_HW_ANTDIV;
//pDM_Odm->AntDivType = CG_TRX_SMART_ANTDIV;
if( (pDM_Odm->AntDivType != CGCS_RX_HW_ANTDIV) && (pDM_Odm->AntDivType != CG_TRX_HW_ANTDIV) && (pDM_Odm->AntDivType != CG_TRX_SMART_ANTDIV))
{
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV,ODM_DBG_LOUD,("[Return!!!] 8192E Not Supprrt This AntDiv Type\n"));
pDM_Odm->SupportAbility &= ~(ODM_BB_ANT_DIV);
return;
}
if(pDM_Odm->AntDivType == CGCS_RX_HW_ANTDIV)
odm_RX_HWAntDiv_Init_92E(pDM_Odm);
else if(pDM_Odm->AntDivType == CG_TRX_HW_ANTDIV)
odm_TRX_HWAntDiv_Init_92E(pDM_Odm);
#if( defined(CONFIG_5G_CG_SMART_ANT_DIVERSITY) ) ||( defined(CONFIG_2G_CG_SMART_ANT_DIVERSITY) )
else if(pDM_Odm->AntDivType == CG_TRX_SMART_ANTDIV)
odm_Smart_HWAntDiv_Init_92E(pDM_Odm);
#endif
}
#endif
//2 [--8723B---]
#if (RTL8723B_SUPPORT == 1)
else if(pDM_Odm->SupportICType == ODM_RTL8723B)
{
//pDM_Odm->AntDivType = S0S1_SW_ANTDIV;
//pDM_Odm->AntDivType = CG_TRX_HW_ANTDIV;
if(pDM_Odm->AntDivType != S0S1_SW_ANTDIV && pDM_Odm->AntDivType != CG_TRX_HW_ANTDIV)
{
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV,ODM_DBG_LOUD,("[Return!!!] 8723B Not Supprrt This AntDiv Type\n"));
pDM_Odm->SupportAbility &= ~(ODM_BB_ANT_DIV);
return;
}
if( pDM_Odm->AntDivType==S0S1_SW_ANTDIV)
odm_S0S1_SWAntDiv_Init_8723B(pDM_Odm);
else if(pDM_Odm->AntDivType==CG_TRX_HW_ANTDIV)
odm_TRX_HWAntDiv_Init_8723B(pDM_Odm);
}
#endif
//2 [--8811A 8821A---]
#if (RTL8821A_SUPPORT == 1)
else if(pDM_Odm->SupportICType == ODM_RTL8821)
{
#ifdef CONFIG_HL_SMART_ANTENNA_TYPE1
pDM_Odm->AntDivType = HL_SW_SMART_ANT_TYPE1;
if (pDM_Odm->AntDivType == HL_SW_SMART_ANT_TYPE1) {
odm_TRX_HWAntDiv_Init_8821A(pDM_Odm);
phydm_hl_smart_ant_type1_init_8821a(pDM_Odm);
} else
#endif
{
/*pDM_Odm->AntDivType = CG_TRX_HW_ANTDIV;*/
pDM_Odm->AntDivType = S0S1_SW_ANTDIV;
if (pDM_Odm->AntDivType != CG_TRX_HW_ANTDIV && pDM_Odm->AntDivType != S0S1_SW_ANTDIV) {
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("[Return!!!] 8821A & 8811A Not Supprrt This AntDiv Type\n"));
pDM_Odm->SupportAbility &= ~(ODM_BB_ANT_DIV);
return;
}
if (pDM_Odm->AntDivType == CG_TRX_HW_ANTDIV)
odm_TRX_HWAntDiv_Init_8821A(pDM_Odm);
else if (pDM_Odm->AntDivType == S0S1_SW_ANTDIV)
odm_S0S1_SWAntDiv_Init_8821A(pDM_Odm);
}
}
#endif
//2 [--8881A---]
#if (RTL8881A_SUPPORT == 1)
else if(pDM_Odm->SupportICType == ODM_RTL8881A)
{
//pDM_Odm->AntDivType = CGCS_RX_HW_ANTDIV;
//pDM_Odm->AntDivType = CG_TRX_HW_ANTDIV;
if(pDM_Odm->AntDivType != CGCS_RX_HW_ANTDIV && pDM_Odm->AntDivType != CG_TRX_HW_ANTDIV)
{
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV,ODM_DBG_LOUD,("[Return!!!] 8881A Not Supprrt This AntDiv Type\n"));
pDM_Odm->SupportAbility &= ~(ODM_BB_ANT_DIV);
return;
}
if(pDM_Odm->AntDivType == CGCS_RX_HW_ANTDIV)
odm_RX_HWAntDiv_Init_8881A(pDM_Odm);
else if(pDM_Odm->AntDivType == CG_TRX_HW_ANTDIV)
odm_TRX_HWAntDiv_Init_8881A(pDM_Odm);
}
#endif
//2 [--8812---]
#if (RTL8812A_SUPPORT == 1)
else if(pDM_Odm->SupportICType == ODM_RTL8812)
{
//pDM_Odm->AntDivType = CG_TRX_HW_ANTDIV;
if( pDM_Odm->AntDivType != CG_TRX_HW_ANTDIV)
{
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV,ODM_DBG_LOUD,("[Return!!!] 8812A Not Supprrt This AntDiv Type\n"));
pDM_Odm->SupportAbility &= ~(ODM_BB_ANT_DIV);
return;
}
odm_TRX_HWAntDiv_Init_8812A(pDM_Odm);
}
#endif
//ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV,ODM_DBG_LOUD,("*** SupportICType=[%lu] \n",pDM_Odm->SupportICType));
//ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV,ODM_DBG_LOUD,("*** AntDiv SupportAbility=[%lu] \n",(pDM_Odm->SupportAbility & ODM_BB_ANT_DIV)>>6));
//ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV,ODM_DBG_LOUD,("*** AntDiv Type=[%d] \n",pDM_Odm->AntDivType));
}
VOID
ODM_AntDiv(
IN PVOID pDM_VOID
)
{
PDM_ODM_T pDM_Odm = (PDM_ODM_T)pDM_VOID;
PADAPTER pAdapter = pDM_Odm->Adapter;
pFAT_T pDM_FatTable = &pDM_Odm->DM_FatTable;
#ifdef CONFIG_HL_SMART_ANTENNA_TYPE1
pSAT_T pdm_sat_table = &(pDM_Odm->dm_sat_table);
#endif
if(*pDM_Odm->pBandType == ODM_BAND_5G )
{
if(pDM_FatTable->idx_AntDiv_counter_5G < pDM_Odm->antdiv_period )
{
pDM_FatTable->idx_AntDiv_counter_5G++;
return;
}
else
pDM_FatTable->idx_AntDiv_counter_5G=0;
}
else if(*pDM_Odm->pBandType == ODM_BAND_2_4G )
{
if(pDM_FatTable->idx_AntDiv_counter_2G < pDM_Odm->antdiv_period )
{
pDM_FatTable->idx_AntDiv_counter_2G++;
return;
}
else
pDM_FatTable->idx_AntDiv_counter_2G=0;
}
//----------
if(!(pDM_Odm->SupportAbility & ODM_BB_ANT_DIV))
{
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV,ODM_DBG_LOUD,("[Return!!!] Not Support Antenna Diversity Function\n"));
return;
}
//----------
#if (DM_ODM_SUPPORT_TYPE == ODM_WIN)
if (pDM_FatTable->enable_ctrl_frame_antdiv) {
if ((pDM_Odm->data_frame_num <= 10) && (pDM_Odm->bLinked))
pDM_FatTable->use_ctrl_frame_antdiv = 1;
else
pDM_FatTable->use_ctrl_frame_antdiv = 0;
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("use_ctrl_frame_antdiv = (( %d )), data_frame_num = (( %d ))\n", pDM_FatTable->use_ctrl_frame_antdiv, pDM_Odm->data_frame_num));
pDM_Odm->data_frame_num = 0;
}
if(pAdapter->MgntInfo.AntennaTest)
return;
{
#if (BEAMFORMING_SUPPORT == 1)
BEAMFORMING_CAP BeamformCap = (pDM_Odm->BeamformingInfo.BeamformCap);
if( BeamformCap & BEAMFORMEE_CAP ) // BFmee On && Div On -> Div Off
{
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV,ODM_DBG_LOUD,("[ AntDiv : OFF ] BFmee ==1 \n"));
if(pDM_FatTable->fix_ant_bfee == 0)
{
odm_AntDiv_on_off(pDM_Odm, ANTDIV_OFF);
pDM_FatTable->fix_ant_bfee = 1;
}
return;
}
else // BFmee Off && Div Off -> Div On
{
if((pDM_FatTable->fix_ant_bfee == 1) && pDM_Odm->bLinked)
{
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("[ AntDiv : ON ] BFmee ==0\n"));
if((pDM_Odm->AntDivType!=S0S1_SW_ANTDIV) )
odm_AntDiv_on_off(pDM_Odm, ANTDIV_ON);
pDM_FatTable->fix_ant_bfee = 0;
}
}
#endif
}
#elif (DM_ODM_SUPPORT_TYPE == ODM_AP)
//----------just for fool proof
if(pDM_Odm->antdiv_rssi)
pDM_Odm->DebugComponents |= ODM_COMP_ANT_DIV;
else
pDM_Odm->DebugComponents &= ~ODM_COMP_ANT_DIV;
if(pDM_FatTable->AntDiv_2G_5G == ODM_ANTDIV_2G)
{
//ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV,ODM_DBG_LOUD,("[ 2G AntDiv Running ]\n"));
if(!(pDM_Odm->SupportICType & ODM_ANTDIV_2G_SUPPORT_IC))
return;
}
else if(pDM_FatTable->AntDiv_2G_5G == ODM_ANTDIV_5G)
{
//ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV,ODM_DBG_LOUD,("[ 5G AntDiv Running ]\n"));
if(!(pDM_Odm->SupportICType & ODM_ANTDIV_5G_SUPPORT_IC))
return;
}
//else if(pDM_FatTable->AntDiv_2G_5G == (ODM_ANTDIV_2G|ODM_ANTDIV_5G))
//{
//ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV,ODM_DBG_LOUD,("[ 2G & 5G AntDiv Running ]\n"));
//}
#endif
//----------
if (pDM_Odm->antdiv_select==1)
pDM_Odm->AntType = ODM_FIX_MAIN_ANT;
else if (pDM_Odm->antdiv_select==2)
pDM_Odm->AntType = ODM_FIX_AUX_ANT;
else //if (pDM_Odm->antdiv_select==0)
pDM_Odm->AntType = ODM_AUTO_ANT;
//ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV,ODM_DBG_LOUD,("AntType= (( %d )) , pre_AntType= (( %d )) \n",pDM_Odm->AntType,pDM_Odm->pre_AntType));
if(pDM_Odm->AntType != ODM_AUTO_ANT)
{
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("Fix Antenna at (( %s ))\n",(pDM_Odm->AntType == ODM_FIX_MAIN_ANT)?"MAIN":"AUX"));
if(pDM_Odm->AntType != pDM_Odm->pre_AntType)
{
odm_AntDiv_on_off(pDM_Odm, ANTDIV_OFF);
odm_Tx_By_TxDesc_or_Reg(pDM_Odm , REG);
if(pDM_Odm->AntType == ODM_FIX_MAIN_ANT)
ODM_UpdateRxIdleAnt(pDM_Odm, MAIN_ANT);
else if(pDM_Odm->AntType == ODM_FIX_AUX_ANT)
ODM_UpdateRxIdleAnt(pDM_Odm, AUX_ANT);
}
pDM_Odm->pre_AntType=pDM_Odm->AntType;
return;
}
else
{
if(pDM_Odm->AntType != pDM_Odm->pre_AntType)
{
odm_AntDiv_on_off(pDM_Odm, ANTDIV_ON);
odm_Tx_By_TxDesc_or_Reg(pDM_Odm , TX_BY_DESC);
}
pDM_Odm->pre_AntType=pDM_Odm->AntType;
}
//3 -----------------------------------------------------------------------------------------------------------
//2 [--88E---]
if(pDM_Odm->SupportICType == ODM_RTL8188E)
{
#if (RTL8188E_SUPPORT == 1)
if(pDM_Odm->AntDivType==CG_TRX_HW_ANTDIV ||pDM_Odm->AntDivType==CGCS_RX_HW_ANTDIV)
odm_HW_AntDiv(pDM_Odm);
#if( defined(CONFIG_5G_CG_SMART_ANT_DIVERSITY) ) ||( defined(CONFIG_2G_CG_SMART_ANT_DIVERSITY) )
else if (pDM_Odm->AntDivType==CG_TRX_SMART_ANTDIV)
odm_FastAntTraining(pDM_Odm);
#endif
#endif
}
//2 [--92E---]
#if (RTL8192E_SUPPORT == 1)
else if(pDM_Odm->SupportICType == ODM_RTL8192E)
{
if(pDM_Odm->AntDivType==CGCS_RX_HW_ANTDIV || pDM_Odm->AntDivType==CG_TRX_HW_ANTDIV)
odm_HW_AntDiv(pDM_Odm);
#if( defined(CONFIG_5G_CG_SMART_ANT_DIVERSITY) ) ||( defined(CONFIG_2G_CG_SMART_ANT_DIVERSITY) )
else if (pDM_Odm->AntDivType==CG_TRX_SMART_ANTDIV)
odm_FastAntTraining(pDM_Odm);
#endif
}
#endif
#if (RTL8723B_SUPPORT == 1)
//2 [--8723B---]
else if(pDM_Odm->SupportICType == ODM_RTL8723B)
{
if (phydm_IsBtEnable_8723b(pDM_Odm)) {
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("[BT is enable!!!] AntDiv: OFF\n"));
if (pDM_FatTable->bBecomeLinked == TRUE) {
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("Set REG 948[9:6]=0x0\n"));
if (pDM_Odm->SupportICType == ODM_RTL8723B)
ODM_SetBBReg(pDM_Odm, 0x948 , BIT9|BIT8|BIT7|BIT6, 0x0);
pDM_FatTable->bBecomeLinked = FALSE;
}
} else {
if (pDM_Odm->AntDivType == S0S1_SW_ANTDIV) {
#ifdef CONFIG_S0S1_SW_ANTENNA_DIVERSITY
odm_S0S1_SwAntDiv(pDM_Odm, SWAW_STEP_PEEK);
#endif
} else if (pDM_Odm->AntDivType == CG_TRX_HW_ANTDIV)
odm_HW_AntDiv(pDM_Odm);
}
}
#endif
//2 [--8821A---]
#if (RTL8821A_SUPPORT == 1)
else if (pDM_Odm->SupportICType == ODM_RTL8821)
{
#ifdef CONFIG_HL_SMART_ANTENNA_TYPE1
if (pDM_Odm->AntDivType == HL_SW_SMART_ANT_TYPE1) {
if (pdm_sat_table->fix_beam_pattern_en != 0) {
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, (" [ SmartAnt ] Fix SmartAnt Pattern = 0x%x\n", pdm_sat_table->fix_beam_pattern_codeword));
/*return;*/
} else {
/*ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("[ SmartAnt ] AntDivType = HL_SW_SMART_ANT_TYPE1\n"));*/
odm_FastAntTraining_hl_smart_antenna_type1(pDM_Odm);
}
} else
#endif
{
if (!pDM_Odm->bBtEnabled) /*BT disabled*/
{
if (pDM_Odm->AntDivType == S0S1_SW_ANTDIV) {
pDM_Odm->AntDivType = CG_TRX_HW_ANTDIV;
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, (" [S0S1_SW_ANTDIV] -> [CG_TRX_HW_ANTDIV]\n"));
/*ODM_SetBBReg(pDM_Odm, 0x8D4 , BIT24, 1); */
if (pDM_FatTable->bBecomeLinked == TRUE)
odm_AntDiv_on_off(pDM_Odm, ANTDIV_ON);
}
} else { /*BT enabled*/
if (pDM_Odm->AntDivType == CG_TRX_HW_ANTDIV) {
pDM_Odm->AntDivType = S0S1_SW_ANTDIV;
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, (" [CG_TRX_HW_ANTDIV] -> [S0S1_SW_ANTDIV]\n"));
/*ODM_SetBBReg(pDM_Odm, 0x8D4 , BIT24, 0);*/
odm_AntDiv_on_off(pDM_Odm, ANTDIV_OFF);
}
}
if (pDM_Odm->AntDivType == S0S1_SW_ANTDIV) {
#ifdef CONFIG_S0S1_SW_ANTENNA_DIVERSITY
odm_S0S1_SwAntDiv(pDM_Odm, SWAW_STEP_PEEK);
#endif
} else if (pDM_Odm->AntDivType == CG_TRX_HW_ANTDIV)
odm_HW_AntDiv(pDM_Odm);
}
}
#endif
//2 [--8881A---]
#if (RTL8881A_SUPPORT == 1)
else if(pDM_Odm->SupportICType == ODM_RTL8881A)
odm_HW_AntDiv(pDM_Odm);
#endif
//2 [--8812A---]
#if (RTL8812A_SUPPORT == 1)
else if(pDM_Odm->SupportICType == ODM_RTL8812)
odm_HW_AntDiv(pDM_Odm);
#endif
}
VOID
odm_AntselStatistics(
IN PVOID pDM_VOID,
IN u1Byte antsel_tr_mux,
IN u4Byte MacId,
IN u4Byte utility,
IN u1Byte method
)
{
PDM_ODM_T pDM_Odm = (PDM_ODM_T)pDM_VOID;
pFAT_T pDM_FatTable = &pDM_Odm->DM_FatTable;
if(method==RSSI_METHOD)
{
if(antsel_tr_mux == ANT1_2G)
{
pDM_FatTable->MainAnt_Sum[MacId]+=utility;
pDM_FatTable->MainAnt_Cnt[MacId]++;
}
else
{
pDM_FatTable->AuxAnt_Sum[MacId]+=utility;
pDM_FatTable->AuxAnt_Cnt[MacId]++;
}
}
#ifdef ODM_EVM_ENHANCE_ANTDIV
else if(method==EVM_METHOD)
{
if(antsel_tr_mux == ANT1_2G)
{
pDM_FatTable->MainAntEVM_Sum[MacId]+=(utility<<5);
pDM_FatTable->MainAntEVM_Cnt[MacId]++;
}
else
{
pDM_FatTable->AuxAntEVM_Sum[MacId]+=(utility<<5);
pDM_FatTable->AuxAntEVM_Cnt[MacId]++;
}
}
else if(method==CRC32_METHOD)
{
if(utility==0)
pDM_FatTable->CRC32_Fail_Cnt++;
else
pDM_FatTable->CRC32_Ok_Cnt+=utility;
}
#endif
}
VOID
ODM_Process_RSSIForAntDiv(
IN OUT PVOID pDM_VOID,
IN PVOID p_phy_info_void,
IN PVOID p_pkt_info_void
//IN PODM_PHY_INFO_T pPhyInfo,
//IN PODM_PACKET_INFO_T pPktinfo
)
{
PDM_ODM_T pDM_Odm = (PDM_ODM_T)pDM_VOID;
PODM_PHY_INFO_T pPhyInfo=(PODM_PHY_INFO_T)p_phy_info_void;
PODM_PACKET_INFO_T pPktinfo=(PODM_PACKET_INFO_T)p_pkt_info_void;
u1Byte isCCKrate=0,CCKMaxRate=ODM_RATE11M;
pFAT_T pDM_FatTable = &pDM_Odm->DM_FatTable;
#ifdef CONFIG_HL_SMART_ANTENNA_TYPE1
pSAT_T pdm_sat_table = &(pDM_Odm->dm_sat_table);
u4Byte beam_tmp;
#endif
#if (DM_ODM_SUPPORT_TYPE & (ODM_WIN))
u4Byte RxPower_Ant0, RxPower_Ant1;
u4Byte RxEVM_Ant0, RxEVM_Ant1;
#else
u1Byte RxPower_Ant0, RxPower_Ant1;
u1Byte RxEVM_Ant0, RxEVM_Ant1;
#endif
CCKMaxRate=ODM_RATE11M;
isCCKrate = (pPktinfo->DataRate <= CCKMaxRate)?TRUE:FALSE;
if ((pDM_Odm->SupportICType & (ODM_RTL8192E|ODM_RTL8812)) && (pPktinfo->DataRate > CCKMaxRate))
{
RxPower_Ant0 = pPhyInfo->RxMIMOSignalStrength[0];
RxPower_Ant1= pPhyInfo->RxMIMOSignalStrength[1];
RxEVM_Ant0 =pPhyInfo->RxMIMOSignalQuality[0];
RxEVM_Ant1 =pPhyInfo->RxMIMOSignalQuality[1];
}
else
RxPower_Ant0=pPhyInfo->RxPWDBAll;
#ifdef CONFIG_HL_SMART_ANTENNA_TYPE1
if (pDM_Odm->AntDivType == HL_SW_SMART_ANT_TYPE1)
{
if ((pDM_Odm->SupportICType & ODM_HL_SMART_ANT_TYPE1_SUPPORT) &&
(pPktinfo->bPacketToSelf) &&
(pDM_FatTable->FAT_State == FAT_TRAINING_STATE)
) {
if (pdm_sat_table->pkt_skip_statistic_en == 0) {
/*
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("StaID[%d]: antsel_pathA = ((%d)), hw_antsw_occur = ((%d)), Beam_num = ((%d)), RSSI = ((%d))\n",
pPktinfo->StationID, pDM_FatTable->antsel_rx_keep_0, pDM_FatTable->hw_antsw_occur, pdm_sat_table->fast_training_beam_num, RxPower_Ant0));
*/
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("StaID[%d]: antsel_pathA = ((%d)), bPacketToSelf = ((%d)), Beam_num = ((%d)), RSSI = ((%d))\n",
pPktinfo->StationID, pDM_FatTable->antsel_rx_keep_0, pPktinfo->bPacketToSelf, pdm_sat_table->fast_training_beam_num, RxPower_Ant0));
pdm_sat_table->pkt_rssi_sum[pDM_FatTable->antsel_rx_keep_0][pdm_sat_table->fast_training_beam_num] += RxPower_Ant0;
pdm_sat_table->pkt_rssi_cnt[pDM_FatTable->antsel_rx_keep_0][pdm_sat_table->fast_training_beam_num]++;
pdm_sat_table->pkt_counter++;
/*swich beam every N pkt*/
if ((pdm_sat_table->pkt_counter) >= (pdm_sat_table->per_beam_training_pkt_num)) {
pdm_sat_table->pkt_counter = 0;
beam_tmp = pdm_sat_table->fast_training_beam_num;
if (pdm_sat_table->fast_training_beam_num >= (pdm_sat_table->beam_patten_num_each_ant-1)) {
pDM_FatTable->FAT_State = FAT_DECISION_STATE;
#if DEV_BUS_TYPE == RT_PCI_INTERFACE
odm_FastAntTraining_hl_smart_antenna_type1(pDM_Odm);
#else
ODM_ScheduleWorkItem(&pdm_sat_table->hl_smart_antenna_decision_workitem);
#endif
} else {
pdm_sat_table->fast_training_beam_num++;
phydm_set_all_ant_same_beam_num(pDM_Odm);
pDM_FatTable->FAT_State = FAT_TRAINING_STATE;
ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("Update Beam_num (( %d )) -> (( %d ))\n", beam_tmp, pdm_sat_table->fast_training_beam_num));
}
}
}
}
} else
#endif
if (pDM_Odm->AntDivType == CG_TRX_SMART_ANTDIV) {
if( (pDM_Odm->SupportICType & ODM_SMART_ANT_SUPPORT) && (pPktinfo->bPacketToSelf) && (pDM_FatTable->FAT_State == FAT_TRAINING_STATE) )//(pPktinfo->bPacketMatchBSSID && (!pPktinfo->bPacketBeacon))
{
u1Byte antsel_tr_mux;
antsel_tr_mux = (pDM_FatTable->antsel_rx_keep_2<<2) |(pDM_FatTable->antsel_rx_keep_1 <<1) |pDM_FatTable->antsel_rx_keep_0;
pDM_FatTable->antSumRSSI[antsel_tr_mux] += RxPower_Ant0;
pDM_FatTable->antRSSIcnt[antsel_tr_mux]++;
}
}
else //AntDivType != CG_TRX_SMART_ANTDIV
{
if ((pDM_Odm->SupportICType & ODM_ANTDIV_SUPPORT) && (pPktinfo->bPacketToSelf || pDM_FatTable->use_ctrl_frame_antdiv))
{
if(pDM_Odm->SupportICType == ODM_RTL8188E || pDM_Odm->SupportICType == ODM_RTL8192E)
{
odm_AntselStatistics(pDM_Odm, pDM_FatTable->antsel_rx_keep_0, pPktinfo->StationID,RxPower_Ant0,RSSI_METHOD);
#ifdef ODM_EVM_ENHANCE_ANTDIV
if(!isCCKrate)
{
odm_AntselStatistics(pDM_Odm, pDM_FatTable->antsel_rx_keep_0, pPktinfo->StationID,RxEVM_Ant0,EVM_METHOD);
}
#endif
}
else// SupportICType == ODM_RTL8821 and ODM_RTL8723B and ODM_RTL8812)
{
if(isCCKrate && (pDM_Odm->AntDivType == S0S1_SW_ANTDIV))
{
pDM_FatTable->antsel_rx_keep_0 = (pDM_FatTable->RxIdleAnt == MAIN_ANT) ? ANT1_2G : ANT2_2G;
if(pDM_FatTable->antsel_rx_keep_0==ANT1_2G)
pDM_FatTable->CCK_counter_main++;
else// if(pDM_FatTable->antsel_rx_keep_0==ANT2_2G)
pDM_FatTable->CCK_counter_aux++;
odm_AntselStatistics(pDM_Odm, pDM_FatTable->antsel_rx_keep_0, pPktinfo->StationID, RxPower_Ant0,RSSI_METHOD);
}
else
{
if(pDM_FatTable->antsel_rx_keep_0==ANT1_2G)
pDM_FatTable->OFDM_counter_main++;
else// if(pDM_FatTable->antsel_rx_keep_0==ANT2_2G)
pDM_FatTable->OFDM_counter_aux++;
odm_AntselStatistics(pDM_Odm, pDM_FatTable->antsel_rx_keep_0, pPktinfo->StationID, RxPower_Ant0,RSSI_METHOD);
}
}
}
}
//ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD,("isCCKrate=%d, PWDB_ALL=%d\n",isCCKrate, pPhyInfo->RxPWDBAll));
//ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD,("antsel_tr_mux=3'b%d%d%d\n",pDM_FatTable->antsel_rx_keep_2, pDM_FatTable->antsel_rx_keep_1, pDM_FatTable->antsel_rx_keep_0));
}
#if (DM_ODM_SUPPORT_TYPE & (ODM_WIN|ODM_CE))
VOID
ODM_SetTxAntByTxInfo(
IN PVOID pDM_VOID,
IN pu1Byte pDesc,
IN u1Byte macId
)
{
PDM_ODM_T pDM_Odm = (PDM_ODM_T)pDM_VOID;
pFAT_T pDM_FatTable = &pDM_Odm->DM_FatTable;
if (!(pDM_Odm->SupportAbility & ODM_BB_ANT_DIV))
return;
if (pDM_Odm->AntDivType == CGCS_RX_HW_ANTDIV)
return;
if (pDM_Odm->SupportICType == ODM_RTL8723B) {
#if (RTL8723B_SUPPORT == 1)
SET_TX_DESC_ANTSEL_A_8723B(pDesc, pDM_FatTable->antsel_a[macId]);
/*ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("[8723B] SetTxAntByTxInfo_WIN: MacID=%d, antsel_tr_mux=3'b%d%d%d\n",
macId, pDM_FatTable->antsel_c[macId], pDM_FatTable->antsel_b[macId], pDM_FatTable->antsel_a[macId]));*/
#endif
} else if (pDM_Odm->SupportICType == ODM_RTL8821) {
#if (RTL8821A_SUPPORT == 1)
SET_TX_DESC_ANTSEL_A_8812(pDesc, pDM_FatTable->antsel_a[macId]);
/*ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("[8821A] SetTxAntByTxInfo_WIN: MacID=%d, antsel_tr_mux=3'b%d%d%d\n",
macId, pDM_FatTable->antsel_c[macId], pDM_FatTable->antsel_b[macId], pDM_FatTable->antsel_a[macId]));*/
#endif
} else if (pDM_Odm->SupportICType == ODM_RTL8188E) {
#if (RTL8188E_SUPPORT == 1)
SET_TX_DESC_ANTSEL_A_88E(pDesc, pDM_FatTable->antsel_a[macId]);
SET_TX_DESC_ANTSEL_B_88E(pDesc, pDM_FatTable->antsel_b[macId]);
SET_TX_DESC_ANTSEL_C_88E(pDesc, pDM_FatTable->antsel_c[macId]);
/*ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("[8188E] SetTxAntByTxInfo_WIN: MacID=%d, antsel_tr_mux=3'b%d%d%d\n",
macId, pDM_FatTable->antsel_c[macId], pDM_FatTable->antsel_b[macId], pDM_FatTable->antsel_a[macId]));*/
#endif
}
}
#elif(DM_ODM_SUPPORT_TYPE == ODM_AP)
VOID
ODM_SetTxAntByTxInfo(
struct rtl8192cd_priv *priv,
struct tx_desc *pdesc,
unsigned short aid
)
{
pFAT_T pDM_FatTable = &priv->pshare->_dmODM.DM_FatTable;
u4Byte SupportICType = priv->pshare->_dmODM.SupportICType;
if (SupportICType == ODM_RTL8881A) {
/*panic_printk("[%s] [%d] ******ODM_SetTxAntByTxInfo_8881E******\n",__FUNCTION__,__LINE__); */
pdesc->Dword6 &= set_desc(~(BIT(18)|BIT(17)|BIT(16)));
pdesc->Dword6 |= set_desc(pDM_FatTable->antsel_a[aid]<<16);
} else if (SupportICType == ODM_RTL8192E) {
/*panic_printk("[%s] [%d] ******ODM_SetTxAntByTxInfo_8192E******\n",__FUNCTION__,__LINE__); */
pdesc->Dword6 &= set_desc(~(BIT(18)|BIT(17)|BIT(16)));
pdesc->Dword6 |= set_desc(pDM_FatTable->antsel_a[aid]<<16);
} else if (SupportICType == ODM_RTL8188E) {
/*panic_printk("[%s] [%d] ******ODM_SetTxAntByTxInfo_8188E******\n",__FUNCTION__,__LINE__);*/
pdesc->Dword2 &= set_desc(~BIT(24));
pdesc->Dword2 &= set_desc(~BIT(25));
pdesc->Dword7 &= set_desc(~BIT(29));
pdesc->Dword2 |= set_desc(pDM_FatTable->antsel_a[aid]<<24);
pdesc->Dword2 |= set_desc(pDM_FatTable->antsel_b[aid]<<25);
pdesc->Dword7 |= set_desc(pDM_FatTable->antsel_c[aid]<<29);
} else if (SupportICType == ODM_RTL8812) {
/*[path-A]*/
/*panic_printk("[%s] [%d] ******ODM_SetTxAntByTxInfo_8881E******\n",__FUNCTION__,__LINE__);*/
pdesc->Dword6 &= set_desc(~BIT(16));
pdesc->Dword6 &= set_desc(~BIT(17));
pdesc->Dword6 &= set_desc(~BIT(18));
pdesc->Dword6 |= set_desc(pDM_FatTable->antsel_a[aid]<<16);
pdesc->Dword6 |= set_desc(pDM_FatTable->antsel_b[aid]<<17);
pdesc->Dword6 |= set_desc(pDM_FatTable->antsel_c[aid]<<18);
}
}
#endif
VOID
ODM_AntDiv_Config(
IN PVOID pDM_VOID
)
{
PDM_ODM_T pDM_Odm = (PDM_ODM_T)pDM_VOID;
pFAT_T pDM_FatTable = &pDM_Odm->DM_FatTable;
#if (DM_ODM_SUPPORT_TYPE & (ODM_WIN))
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("WIN Config Antenna Diversity\n"));
if(pDM_Odm->SupportICType==ODM_RTL8723B)
{
if((!pDM_Odm->DM_SWAT_Table.ANTA_ON || !pDM_Odm->DM_SWAT_Table.ANTB_ON))
pDM_Odm->SupportAbility &= ~(ODM_BB_ANT_DIV);
}
#elif (DM_ODM_SUPPORT_TYPE & (ODM_CE))
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("CE Config Antenna Diversity\n"));
if(pDM_Odm->SupportICType & ODM_ANTDIV_SUPPORT)
{
pDM_Odm->SupportAbility |= ODM_BB_ANT_DIV;
}
if(pDM_Odm->SupportICType==ODM_RTL8723B)
{
pDM_Odm->AntDivType = S0S1_SW_ANTDIV;
}
#elif (DM_ODM_SUPPORT_TYPE & (ODM_AP))
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("AP Config Antenna Diversity\n"));
//2 [ NOT_SUPPORT_ANTDIV ]
#if(defined(CONFIG_NOT_SUPPORT_ANTDIV))
pDM_Odm->SupportAbility &= ~(ODM_BB_ANT_DIV);
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("[ Disable AntDiv function] : Not Support 2.4G & 5G Antenna Diversity\n"));
//2 [ 2G&5G_SUPPORT_ANTDIV ]
#elif(defined(CONFIG_2G5G_SUPPORT_ANTDIV))
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("[ Enable AntDiv function] : 2.4G & 5G Support Antenna Diversity Simultaneously \n"));
pDM_FatTable->AntDiv_2G_5G = (ODM_ANTDIV_2G|ODM_ANTDIV_5G);
if(pDM_Odm->SupportICType & ODM_ANTDIV_SUPPORT)
pDM_Odm->SupportAbility |= ODM_BB_ANT_DIV;
if(*pDM_Odm->pBandType == ODM_BAND_5G )
{
#if ( defined(CONFIG_5G_CGCS_RX_DIVERSITY) )
pDM_Odm->AntDivType = CGCS_RX_HW_ANTDIV;
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("[ 5G] : AntDiv Type = CGCS_RX_HW_ANTDIV\n"));
panic_printk("[ 5G] : AntDiv Type = CGCS_RX_HW_ANTDIV\n");
#elif( defined(CONFIG_5G_CG_TRX_DIVERSITY)||defined(CONFIG_2G5G_CG_TRX_DIVERSITY_8881A))
pDM_Odm->AntDivType = CG_TRX_HW_ANTDIV;
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("[ 5G] : AntDiv Type = CG_TRX_HW_ANTDIV\n"));
panic_printk("[ 5G] : AntDiv Type = CG_TRX_HW_ANTDIV\n");
#elif( defined(CONFIG_5G_CG_SMART_ANT_DIVERSITY) )
pDM_Odm->AntDivType = CG_TRX_SMART_ANTDIV;
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("[ 5G] : AntDiv Type = CG_SMART_ANTDIV\n"));
#elif( defined(CONFIG_5G_S0S1_SW_ANT_DIVERSITY) )
pDM_Odm->AntDivType = S0S1_SW_ANTDIV;
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("[ 5G] : AntDiv Type = S0S1_SW_ANTDIV\n"));
#endif
}
else if(*pDM_Odm->pBandType == ODM_BAND_2_4G )
{
#if ( defined(CONFIG_2G_CGCS_RX_DIVERSITY) )
pDM_Odm->AntDivType = CGCS_RX_HW_ANTDIV;
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("[ 2.4G] : AntDiv Type = CGCS_RX_HW_ANTDIV\n"));
#elif( defined(CONFIG_2G_CG_TRX_DIVERSITY) || defined(CONFIG_2G5G_CG_TRX_DIVERSITY_8881A))
pDM_Odm->AntDivType = CG_TRX_HW_ANTDIV;
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("[ 2.4G] : AntDiv Type = CG_TRX_HW_ANTDIV\n"));
#elif( defined(CONFIG_2G_CG_SMART_ANT_DIVERSITY) )
pDM_Odm->AntDivType = CG_TRX_SMART_ANTDIV;
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("[ 2.4G] : AntDiv Type = CG_SMART_ANTDIV\n"));
#elif( defined(CONFIG_2G_S0S1_SW_ANT_DIVERSITY) )
pDM_Odm->AntDivType = S0S1_SW_ANTDIV;
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("[ 2.4G] : AntDiv Type = S0S1_SW_ANTDIV\n"));
#endif
}
//2 [ 5G_SUPPORT_ANTDIV ]
#elif(defined(CONFIG_5G_SUPPORT_ANTDIV))
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("[ Enable AntDiv function] : Only 5G Support Antenna Diversity\n"));
panic_printk("[ Enable AntDiv function] : Only 5G Support Antenna Diversity\n");
pDM_FatTable->AntDiv_2G_5G = (ODM_ANTDIV_5G);
if(*pDM_Odm->pBandType == ODM_BAND_5G )
{
if(pDM_Odm->SupportICType & ODM_ANTDIV_5G_SUPPORT_IC)
pDM_Odm->SupportAbility |= ODM_BB_ANT_DIV;
#if ( defined(CONFIG_5G_CGCS_RX_DIVERSITY) )
pDM_Odm->AntDivType = CGCS_RX_HW_ANTDIV;
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("[ 5G] : AntDiv Type = CGCS_RX_HW_ANTDIV\n"));
panic_printk("[ 5G] : AntDiv Type = CGCS_RX_HW_ANTDIV\n");
#elif( defined(CONFIG_5G_CG_TRX_DIVERSITY) )
pDM_Odm->AntDivType = CG_TRX_HW_ANTDIV;
panic_printk("[ 5G] : AntDiv Type = CG_TRX_HW_ANTDIV\n");
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("[ 5G] : AntDiv Type = CG_TRX_HW_ANTDIV\n"));
#elif( defined(CONFIG_5G_CG_SMART_ANT_DIVERSITY) )
pDM_Odm->AntDivType = CG_TRX_SMART_ANTDIV;
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("[ 5G] : AntDiv Type = CG_SMART_ANTDIV\n"));
#elif( defined(CONFIG_5G_S0S1_SW_ANT_DIVERSITY) )
pDM_Odm->AntDivType = S0S1_SW_ANTDIV;
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("[ 5G] : AntDiv Type = S0S1_SW_ANTDIV\n"));
#endif
}
else if(*pDM_Odm->pBandType == ODM_BAND_2_4G )
{
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD,("Not Support 2G AntDivType\n"));
pDM_Odm->SupportAbility &= ~(ODM_BB_ANT_DIV);
}
//2 [ 2G_SUPPORT_ANTDIV ]
#elif(defined(CONFIG_2G_SUPPORT_ANTDIV))
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("[ Enable AntDiv function] : Only 2.4G Support Antenna Diversity\n"));
pDM_FatTable->AntDiv_2G_5G = (ODM_ANTDIV_2G);
if(*pDM_Odm->pBandType == ODM_BAND_2_4G )
{
if(pDM_Odm->SupportICType & ODM_ANTDIV_2G_SUPPORT_IC)
pDM_Odm->SupportAbility |= ODM_BB_ANT_DIV;
#if ( defined(CONFIG_2G_CGCS_RX_DIVERSITY) )
pDM_Odm->AntDivType = CGCS_RX_HW_ANTDIV;
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("[ 2.4G] : AntDiv Type = CGCS_RX_HW_ANTDIV\n"));
#elif( defined(CONFIG_2G_CG_TRX_DIVERSITY) )
pDM_Odm->AntDivType = CG_TRX_HW_ANTDIV;
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("[ 2.4G] : AntDiv Type = CG_TRX_HW_ANTDIV\n"));
#elif( defined(CONFIG_2G_CG_SMART_ANT_DIVERSITY) )
pDM_Odm->AntDivType = CG_TRX_SMART_ANTDIV;
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("[ 2.4G] : AntDiv Type = CG_SMART_ANTDIV\n"));
#elif( defined(CONFIG_2G_S0S1_SW_ANT_DIVERSITY) )
pDM_Odm->AntDivType = S0S1_SW_ANTDIV;
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("[ 2.4G] : AntDiv Type = S0S1_SW_ANTDIV\n"));
#endif
}
else if(*pDM_Odm->pBandType == ODM_BAND_5G )
{
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD,("Not Support 5G AntDivType\n"));
pDM_Odm->SupportAbility &= ~(ODM_BB_ANT_DIV);
}
#endif
#endif
ODM_RT_TRACE(pDM_Odm,ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("SupportAbility = (( %x ))\n", pDM_Odm->SupportAbility ));
}
VOID
ODM_AntDivTimers(
IN PVOID pDM_VOID,
IN u1Byte state
)
{
PDM_ODM_T pDM_Odm = (PDM_ODM_T)pDM_VOID;
if(state==INIT_ANTDIV_TIMMER)
{
#ifdef CONFIG_S0S1_SW_ANTENNA_DIVERSITY
ODM_InitializeTimer(pDM_Odm,&pDM_Odm->DM_SWAT_Table.SwAntennaSwitchTimer_8723B,
(RT_TIMER_CALL_BACK)ODM_SW_AntDiv_Callback, NULL, "SwAntennaSwitchTimer_8723B");
#elif ( defined(CONFIG_5G_CG_SMART_ANT_DIVERSITY) ) ||( defined(CONFIG_2G_CG_SMART_ANT_DIVERSITY) )
ODM_InitializeTimer(pDM_Odm,&pDM_Odm->FastAntTrainingTimer,
(RT_TIMER_CALL_BACK)odm_FastAntTrainingCallback, NULL, "FastAntTrainingTimer");
#endif
#ifdef ODM_EVM_ENHANCE_ANTDIV
ODM_InitializeTimer(pDM_Odm,&pDM_Odm->EVM_FastAntTrainingTimer,
(RT_TIMER_CALL_BACK)odm_EVM_FastAntTrainingCallback, NULL, "EVM_FastAntTrainingTimer");
#endif
}
else if(state==CANCEL_ANTDIV_TIMMER)
{
#ifdef CONFIG_S0S1_SW_ANTENNA_DIVERSITY
ODM_CancelTimer(pDM_Odm,&pDM_Odm->DM_SWAT_Table.SwAntennaSwitchTimer_8723B);
#elif ( defined(CONFIG_5G_CG_SMART_ANT_DIVERSITY) ) ||( defined(CONFIG_2G_CG_SMART_ANT_DIVERSITY) )
ODM_CancelTimer(pDM_Odm,&pDM_Odm->FastAntTrainingTimer);
#endif
#ifdef ODM_EVM_ENHANCE_ANTDIV
ODM_CancelTimer(pDM_Odm,&pDM_Odm->EVM_FastAntTrainingTimer);
#endif
}
else if(state==RELEASE_ANTDIV_TIMMER)
{
#ifdef CONFIG_S0S1_SW_ANTENNA_DIVERSITY
ODM_ReleaseTimer(pDM_Odm,&pDM_Odm->DM_SWAT_Table.SwAntennaSwitchTimer_8723B);
#elif ( defined(CONFIG_5G_CG_SMART_ANT_DIVERSITY) ) ||( defined(CONFIG_2G_CG_SMART_ANT_DIVERSITY) )
ODM_ReleaseTimer(pDM_Odm,&pDM_Odm->FastAntTrainingTimer);
#endif
#ifdef ODM_EVM_ENHANCE_ANTDIV
ODM_ReleaseTimer(pDM_Odm,&pDM_Odm->EVM_FastAntTrainingTimer);
#endif
}
}
#endif /*#if (defined(CONFIG_PHYDM_ANTENNA_DIVERSITY))*/
VOID
ODM_AntDivReset(
IN PVOID pDM_VOID
)
{
PDM_ODM_T pDM_Odm = (PDM_ODM_T)pDM_VOID;
//2 [--8723B---]
#if (RTL8723B_SUPPORT == 1)
if(pDM_Odm->SupportICType == ODM_RTL8723B)
{
#if (defined(CONFIG_PHYDM_ANTENNA_DIVERSITY))
odm_S0S1_SWAntDiv_Reset_8723B(pDM_Odm);
#endif
}
#endif
}
VOID
odm_AntennaDiversityInit(
IN PVOID pDM_VOID
)
{
PDM_ODM_T pDM_Odm = (PDM_ODM_T)pDM_VOID;
if(pDM_Odm->mp_mode == TRUE)
return;
#if (defined(CONFIG_PHYDM_ANTENNA_DIVERSITY))
ODM_AntDiv_Config(pDM_Odm);
ODM_AntDivInit(pDM_Odm);
#endif
}
VOID
odm_AntennaDiversity(
IN PVOID pDM_VOID
)
{
PDM_ODM_T pDM_Odm = (PDM_ODM_T)pDM_VOID;
if(pDM_Odm->mp_mode == TRUE)
return;
#if (defined(CONFIG_PHYDM_ANTENNA_DIVERSITY))
ODM_AntDiv(pDM_Odm);
#endif
}
|
77ac2c4628dcf3603fe57df970beb4a1c4c4610a
|
b732361d6b3405c3e79ac0a7d8361cf5b329b015
|
/ext/phalcon/filter/sanitize/remove.zep.h
|
4393c1657b3f17069175934e44c9f684a05eb3d4
|
[
"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
| 519
|
h
|
remove.zep.h
|
extern zend_class_entry *phalcon_filter_sanitize_remove_ce;
ZEPHIR_INIT_CLASS(Phalcon_Filter_Sanitize_Remove);
PHP_METHOD(Phalcon_Filter_Sanitize_Remove, __invoke);
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_filter_sanitize_remove___invoke, 0, 0, 2)
ZEND_ARG_INFO(0, input)
ZEND_ARG_INFO(0, replace)
ZEND_END_ARG_INFO()
ZEPHIR_INIT_FUNCS(phalcon_filter_sanitize_remove_method_entry) {
PHP_ME(Phalcon_Filter_Sanitize_Remove, __invoke, arginfo_phalcon_filter_sanitize_remove___invoke, ZEND_ACC_PUBLIC)
PHP_FE_END
};
|
13ebdb9c26f53c1a29ee3707ce02e6d9509437f8
|
6f286be4a4e16867cc6e488080b8e3eced1dcd62
|
/src/cppVISUAL/cppVISUAL_global.h
|
2f1c251ce8652907ac69f4b332e27edd96ef2a3f
|
[
"MIT"
] |
permissive
|
imgag/ngs-bits
|
3587404be01687d52c5a77b933874ca77faf8e6b
|
0597c96f6bc09067598c2364877d11091350bed8
|
refs/heads/master
| 2023-09-03T20:20:16.975954
| 2023-09-01T13:17:35
| 2023-09-01T13:17:35
| 38,034,492
| 110
| 36
|
MIT
| 2023-09-12T14:21:59
| 2015-06-25T07:23:55
|
C++
|
UTF-8
|
C
| false
| false
| 252
|
h
|
cppVISUAL_global.h
|
#ifndef CPPVISUAL_GLOBAL_H
#define CPPVISUAL_GLOBAL_H
#include <QtCore/qglobal.h>
#if defined(CPPVISUAL_LIBRARY)
# define CPPVISUALSHARED_EXPORT Q_DECL_EXPORT
#else
# define CPPVISUALSHARED_EXPORT Q_DECL_IMPORT
#endif
#endif // CPPVISUAL_GLOBAL_H
|
f43aa6cb0b2eff91a174cea0a75431cbb21e0b91
|
cf35a104dabc3d3647df66aff9db32d18b002e1b
|
/lib/libstuff/util/strcasestr.c
|
ed243eee5a8ea3e26e2b6cd3992640a28792f10b
|
[
"MIT"
] |
permissive
|
0intro/wmii
|
ba2dff4be1a049c7d4475218a914585a3f810ab5
|
024f29d1058b58aa4ee6b956500a78f69355fb53
|
refs/heads/main
| 2023-07-11T18:08:43.660898
| 2023-06-25T18:57:45
| 2023-06-25T18:57:45
| 74,551,919
| 110
| 17
| null | null | null | null |
UTF-8
|
C
| false
| false
| 548
|
c
|
strcasestr.c
|
/* Written by Kris Maglione <maglione.k at Gmail> */
/* Public domain */
#include <ctype.h>
#include <stdint.h>
#include <string.h>
#include <strings.h>
#include "util.h"
/* TODO: Make this UTF-8 compliant. */
char*
strcasestr(const char *dst, const char *src) {
int len, dc, sc;
if(src[0] == '\0')
return (char*)(uintptr_t)dst;
len = strlen(src) - 1;
sc = tolower(src[0]);
for(; (dc = *dst); dst++) {
dc = tolower(dc);
if(sc == dc && (len == 0 || !strncasecmp(dst+1, src+1, len)))
return (char*)(uintptr_t)dst;
}
return nil;
}
|
d717409c261d3bce34a11a41f4a684420ef10264
|
5eff7a36d9a9917dce9111f0c3074375fe6f7656
|
/lib/mesa/generated/src/mesa/format_info.h
|
60c80da1e259209be6589bfb385c2ed3921af814
|
[] |
no_license
|
openbsd/xenocara
|
cb392d02ebba06f6ff7d826fd8a89aa3b8401779
|
a012b5de33ea0b977095d77316a521195b26cc6b
|
refs/heads/master
| 2023-08-25T12:16:58.862008
| 2023-08-12T16:16:25
| 2023-08-12T16:16:25
| 66,967,384
| 177
| 66
| null | 2023-07-22T18:12:37
| 2016-08-30T18:36:01
|
C
|
UTF-8
|
C
| false
| false
| 161,632
|
h
|
format_info.h
|
/*
* Mesa 3-D graphics library
*
* Copyright (c) 2014 Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
/*
* This file is AUTOGENERATED by format_info.py. Do not edit it
* manually or commit it into version control.
*/
static const struct mesa_format_info format_info[MESA_FORMAT_COUNT] =
{
[MESA_FORMAT_NONE] = {
.Name = MESA_FORMAT_NONE,
.StrName = "MESA_FORMAT_NONE",
.Layout = MESA_FORMAT_LAYOUT_OTHER,
.BaseFormat = GL_NONE,
.DataType = GL_NONE,
.RedBits = 0, .GreenBits = 0, .BlueBits = 0, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 1,
.Swizzle = { 4, 4, 4, 5 },
.ArrayFormat = 0,
},
[MESA_FORMAT_A8B8G8R8_UNORM] = {
.Name = MESA_FORMAT_A8B8G8R8_UNORM,
.StrName = "MESA_FORMAT_A8B8G8R8_UNORM",
.Layout = MESA_FORMAT_LAYOUT_PACKED,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 8, .GreenBits = 8, .BlueBits = 8, .AlphaBits = 8,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 4,
.Swizzle = { 3, 2, 1, 0 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 1, 0, 0, 1, 4, 3, 2, 1, 0),
},
[MESA_FORMAT_X8B8G8R8_UNORM] = {
.Name = MESA_FORMAT_X8B8G8R8_UNORM,
.StrName = "MESA_FORMAT_X8B8G8R8_UNORM",
.Layout = MESA_FORMAT_LAYOUT_PACKED,
.BaseFormat = GL_RGB,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 8, .GreenBits = 8, .BlueBits = 8, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 4,
.Swizzle = { 3, 2, 1, 5 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 1, 0, 0, 1, 4, 3, 2, 1, 5),
},
[MESA_FORMAT_R8G8B8A8_UNORM] = {
.Name = MESA_FORMAT_R8G8B8A8_UNORM,
.StrName = "MESA_FORMAT_R8G8B8A8_UNORM",
.Layout = MESA_FORMAT_LAYOUT_PACKED,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 8, .GreenBits = 8, .BlueBits = 8, .AlphaBits = 8,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 4,
.Swizzle = { 0, 1, 2, 3 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 1, 0, 0, 1, 4, 0, 1, 2, 3),
},
[MESA_FORMAT_R8G8B8X8_UNORM] = {
.Name = MESA_FORMAT_R8G8B8X8_UNORM,
.StrName = "MESA_FORMAT_R8G8B8X8_UNORM",
.Layout = MESA_FORMAT_LAYOUT_PACKED,
.BaseFormat = GL_RGB,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 8, .GreenBits = 8, .BlueBits = 8, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 4,
.Swizzle = { 0, 1, 2, 5 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 1, 0, 0, 1, 4, 0, 1, 2, 5),
},
[MESA_FORMAT_B8G8R8A8_UNORM] = {
.Name = MESA_FORMAT_B8G8R8A8_UNORM,
.StrName = "MESA_FORMAT_B8G8R8A8_UNORM",
.Layout = MESA_FORMAT_LAYOUT_PACKED,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 8, .GreenBits = 8, .BlueBits = 8, .AlphaBits = 8,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 4,
.Swizzle = { 2, 1, 0, 3 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 1, 0, 0, 1, 4, 2, 1, 0, 3),
},
[MESA_FORMAT_B8G8R8X8_UNORM] = {
.Name = MESA_FORMAT_B8G8R8X8_UNORM,
.StrName = "MESA_FORMAT_B8G8R8X8_UNORM",
.Layout = MESA_FORMAT_LAYOUT_PACKED,
.BaseFormat = GL_RGB,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 8, .GreenBits = 8, .BlueBits = 8, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 4,
.Swizzle = { 2, 1, 0, 5 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 1, 0, 0, 1, 4, 2, 1, 0, 5),
},
[MESA_FORMAT_A8R8G8B8_UNORM] = {
.Name = MESA_FORMAT_A8R8G8B8_UNORM,
.StrName = "MESA_FORMAT_A8R8G8B8_UNORM",
.Layout = MESA_FORMAT_LAYOUT_PACKED,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 8, .GreenBits = 8, .BlueBits = 8, .AlphaBits = 8,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 4,
.Swizzle = { 1, 2, 3, 0 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 1, 0, 0, 1, 4, 1, 2, 3, 0),
},
[MESA_FORMAT_X8R8G8B8_UNORM] = {
.Name = MESA_FORMAT_X8R8G8B8_UNORM,
.StrName = "MESA_FORMAT_X8R8G8B8_UNORM",
.Layout = MESA_FORMAT_LAYOUT_PACKED,
.BaseFormat = GL_RGB,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 8, .GreenBits = 8, .BlueBits = 8, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 4,
.Swizzle = { 1, 2, 3, 5 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 1, 0, 0, 1, 4, 1, 2, 3, 5),
},
[MESA_FORMAT_B5G6R5_UNORM] = {
.Name = MESA_FORMAT_B5G6R5_UNORM,
.StrName = "MESA_FORMAT_B5G6R5_UNORM",
.Layout = MESA_FORMAT_LAYOUT_PACKED,
.BaseFormat = GL_RGB,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 5, .GreenBits = 6, .BlueBits = 5, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 2,
.Swizzle = { 2, 1, 0, 5 },
.ArrayFormat = 0,
},
[MESA_FORMAT_R5G6B5_UNORM] = {
.Name = MESA_FORMAT_R5G6B5_UNORM,
.StrName = "MESA_FORMAT_R5G6B5_UNORM",
.Layout = MESA_FORMAT_LAYOUT_PACKED,
.BaseFormat = GL_RGB,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 5, .GreenBits = 6, .BlueBits = 5, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 2,
.Swizzle = { 0, 1, 2, 5 },
.ArrayFormat = 0,
},
[MESA_FORMAT_B4G4R4A4_UNORM] = {
.Name = MESA_FORMAT_B4G4R4A4_UNORM,
.StrName = "MESA_FORMAT_B4G4R4A4_UNORM",
.Layout = MESA_FORMAT_LAYOUT_PACKED,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 4, .GreenBits = 4, .BlueBits = 4, .AlphaBits = 4,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 2,
.Swizzle = { 2, 1, 0, 3 },
.ArrayFormat = 0,
},
[MESA_FORMAT_B4G4R4X4_UNORM] = {
.Name = MESA_FORMAT_B4G4R4X4_UNORM,
.StrName = "MESA_FORMAT_B4G4R4X4_UNORM",
.Layout = MESA_FORMAT_LAYOUT_PACKED,
.BaseFormat = GL_RGB,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 4, .GreenBits = 4, .BlueBits = 4, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 2,
.Swizzle = { 2, 1, 0, 5 },
.ArrayFormat = 0,
},
[MESA_FORMAT_A4R4G4B4_UNORM] = {
.Name = MESA_FORMAT_A4R4G4B4_UNORM,
.StrName = "MESA_FORMAT_A4R4G4B4_UNORM",
.Layout = MESA_FORMAT_LAYOUT_PACKED,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 4, .GreenBits = 4, .BlueBits = 4, .AlphaBits = 4,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 2,
.Swizzle = { 1, 2, 3, 0 },
.ArrayFormat = 0,
},
[MESA_FORMAT_A1B5G5R5_UNORM] = {
.Name = MESA_FORMAT_A1B5G5R5_UNORM,
.StrName = "MESA_FORMAT_A1B5G5R5_UNORM",
.Layout = MESA_FORMAT_LAYOUT_PACKED,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 5, .GreenBits = 5, .BlueBits = 5, .AlphaBits = 1,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 2,
.Swizzle = { 3, 2, 1, 0 },
.ArrayFormat = 0,
},
[MESA_FORMAT_X1B5G5R5_UNORM] = {
.Name = MESA_FORMAT_X1B5G5R5_UNORM,
.StrName = "MESA_FORMAT_X1B5G5R5_UNORM",
.Layout = MESA_FORMAT_LAYOUT_PACKED,
.BaseFormat = GL_RGB,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 5, .GreenBits = 5, .BlueBits = 5, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 2,
.Swizzle = { 3, 2, 1, 5 },
.ArrayFormat = 0,
},
[MESA_FORMAT_B5G5R5A1_UNORM] = {
.Name = MESA_FORMAT_B5G5R5A1_UNORM,
.StrName = "MESA_FORMAT_B5G5R5A1_UNORM",
.Layout = MESA_FORMAT_LAYOUT_PACKED,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 5, .GreenBits = 5, .BlueBits = 5, .AlphaBits = 1,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 2,
.Swizzle = { 2, 1, 0, 3 },
.ArrayFormat = 0,
},
[MESA_FORMAT_B5G5R5X1_UNORM] = {
.Name = MESA_FORMAT_B5G5R5X1_UNORM,
.StrName = "MESA_FORMAT_B5G5R5X1_UNORM",
.Layout = MESA_FORMAT_LAYOUT_PACKED,
.BaseFormat = GL_RGB,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 5, .GreenBits = 5, .BlueBits = 5, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 2,
.Swizzle = { 2, 1, 0, 5 },
.ArrayFormat = 0,
},
[MESA_FORMAT_A1R5G5B5_UNORM] = {
.Name = MESA_FORMAT_A1R5G5B5_UNORM,
.StrName = "MESA_FORMAT_A1R5G5B5_UNORM",
.Layout = MESA_FORMAT_LAYOUT_PACKED,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 5, .GreenBits = 5, .BlueBits = 5, .AlphaBits = 1,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 2,
.Swizzle = { 1, 2, 3, 0 },
.ArrayFormat = 0,
},
[MESA_FORMAT_L4A4_UNORM] = {
.Name = MESA_FORMAT_L4A4_UNORM,
.StrName = "MESA_FORMAT_L4A4_UNORM",
.Layout = MESA_FORMAT_LAYOUT_PACKED,
.BaseFormat = GL_LUMINANCE_ALPHA,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 0, .GreenBits = 0, .BlueBits = 0, .AlphaBits = 4,
.LuminanceBits = 4, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 1,
.Swizzle = { 0, 0, 0, 1 },
.ArrayFormat = 0,
},
[MESA_FORMAT_B2G3R3_UNORM] = {
.Name = MESA_FORMAT_B2G3R3_UNORM,
.StrName = "MESA_FORMAT_B2G3R3_UNORM",
.Layout = MESA_FORMAT_LAYOUT_PACKED,
.BaseFormat = GL_RGB,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 3, .GreenBits = 3, .BlueBits = 2, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 1,
.Swizzle = { 2, 1, 0, 5 },
.ArrayFormat = 0,
},
[MESA_FORMAT_B10G10R10A2_UNORM] = {
.Name = MESA_FORMAT_B10G10R10A2_UNORM,
.StrName = "MESA_FORMAT_B10G10R10A2_UNORM",
.Layout = MESA_FORMAT_LAYOUT_PACKED,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 10, .GreenBits = 10, .BlueBits = 10, .AlphaBits = 2,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 4,
.Swizzle = { 2, 1, 0, 3 },
.ArrayFormat = 0,
},
[MESA_FORMAT_B10G10R10X2_UNORM] = {
.Name = MESA_FORMAT_B10G10R10X2_UNORM,
.StrName = "MESA_FORMAT_B10G10R10X2_UNORM",
.Layout = MESA_FORMAT_LAYOUT_PACKED,
.BaseFormat = GL_RGB,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 10, .GreenBits = 10, .BlueBits = 10, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 4,
.Swizzle = { 2, 1, 0, 5 },
.ArrayFormat = 0,
},
[MESA_FORMAT_R10G10B10A2_UNORM] = {
.Name = MESA_FORMAT_R10G10B10A2_UNORM,
.StrName = "MESA_FORMAT_R10G10B10A2_UNORM",
.Layout = MESA_FORMAT_LAYOUT_PACKED,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 10, .GreenBits = 10, .BlueBits = 10, .AlphaBits = 2,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 4,
.Swizzle = { 0, 1, 2, 3 },
.ArrayFormat = 0,
},
[MESA_FORMAT_R10G10B10X2_UNORM] = {
.Name = MESA_FORMAT_R10G10B10X2_UNORM,
.StrName = "MESA_FORMAT_R10G10B10X2_UNORM",
.Layout = MESA_FORMAT_LAYOUT_PACKED,
.BaseFormat = GL_RGB,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 10, .GreenBits = 10, .BlueBits = 10, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 4,
.Swizzle = { 0, 1, 2, 5 },
.ArrayFormat = 0,
},
[MESA_FORMAT_S8_UINT_Z24_UNORM] = {
.Name = MESA_FORMAT_S8_UINT_Z24_UNORM,
.StrName = "MESA_FORMAT_S8_UINT_Z24_UNORM",
.Layout = MESA_FORMAT_LAYOUT_PACKED,
.BaseFormat = GL_DEPTH_STENCIL,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 0, .GreenBits = 0, .BlueBits = 0, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 24, .StencilBits = 8,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 4,
.Swizzle = { 0, 1, 6, 6 },
.ArrayFormat = 0,
},
[MESA_FORMAT_X8_UINT_Z24_UNORM] = {
.Name = MESA_FORMAT_X8_UINT_Z24_UNORM,
.StrName = "MESA_FORMAT_X8_UINT_Z24_UNORM",
.Layout = MESA_FORMAT_LAYOUT_PACKED,
.BaseFormat = GL_DEPTH_COMPONENT,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 0, .GreenBits = 0, .BlueBits = 0, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 24, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 4,
.Swizzle = { 0, 6, 6, 6 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_DEPTH, 3, 0, 0, 1, 2, 0, 6, 6, 6),
},
[MESA_FORMAT_Z24_UNORM_S8_UINT] = {
.Name = MESA_FORMAT_Z24_UNORM_S8_UINT,
.StrName = "MESA_FORMAT_Z24_UNORM_S8_UINT",
.Layout = MESA_FORMAT_LAYOUT_PACKED,
.BaseFormat = GL_DEPTH_STENCIL,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 0, .GreenBits = 0, .BlueBits = 0, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 24, .StencilBits = 8,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 4,
.Swizzle = { 1, 0, 6, 6 },
.ArrayFormat = 0,
},
[MESA_FORMAT_Z24_UNORM_X8_UINT] = {
.Name = MESA_FORMAT_Z24_UNORM_X8_UINT,
.StrName = "MESA_FORMAT_Z24_UNORM_X8_UINT",
.Layout = MESA_FORMAT_LAYOUT_PACKED,
.BaseFormat = GL_DEPTH_COMPONENT,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 0, .GreenBits = 0, .BlueBits = 0, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 24, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 4,
.Swizzle = { 1, 6, 6, 6 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_DEPTH, 3, 0, 0, 1, 2, 1, 6, 6, 6),
},
[MESA_FORMAT_R3G3B2_UNORM] = {
.Name = MESA_FORMAT_R3G3B2_UNORM,
.StrName = "MESA_FORMAT_R3G3B2_UNORM",
.Layout = MESA_FORMAT_LAYOUT_PACKED,
.BaseFormat = GL_RGB,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 3, .GreenBits = 3, .BlueBits = 2, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 1,
.Swizzle = { 0, 1, 2, 5 },
.ArrayFormat = 0,
},
[MESA_FORMAT_A4B4G4R4_UNORM] = {
.Name = MESA_FORMAT_A4B4G4R4_UNORM,
.StrName = "MESA_FORMAT_A4B4G4R4_UNORM",
.Layout = MESA_FORMAT_LAYOUT_PACKED,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 4, .GreenBits = 4, .BlueBits = 4, .AlphaBits = 4,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 2,
.Swizzle = { 3, 2, 1, 0 },
.ArrayFormat = 0,
},
[MESA_FORMAT_R4G4B4A4_UNORM] = {
.Name = MESA_FORMAT_R4G4B4A4_UNORM,
.StrName = "MESA_FORMAT_R4G4B4A4_UNORM",
.Layout = MESA_FORMAT_LAYOUT_PACKED,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 4, .GreenBits = 4, .BlueBits = 4, .AlphaBits = 4,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 2,
.Swizzle = { 0, 1, 2, 3 },
.ArrayFormat = 0,
},
[MESA_FORMAT_R5G5B5A1_UNORM] = {
.Name = MESA_FORMAT_R5G5B5A1_UNORM,
.StrName = "MESA_FORMAT_R5G5B5A1_UNORM",
.Layout = MESA_FORMAT_LAYOUT_PACKED,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 5, .GreenBits = 5, .BlueBits = 5, .AlphaBits = 1,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 2,
.Swizzle = { 0, 1, 2, 3 },
.ArrayFormat = 0,
},
[MESA_FORMAT_A2B10G10R10_UNORM] = {
.Name = MESA_FORMAT_A2B10G10R10_UNORM,
.StrName = "MESA_FORMAT_A2B10G10R10_UNORM",
.Layout = MESA_FORMAT_LAYOUT_PACKED,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 10, .GreenBits = 10, .BlueBits = 10, .AlphaBits = 2,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 4,
.Swizzle = { 3, 2, 1, 0 },
.ArrayFormat = 0,
},
[MESA_FORMAT_A2R10G10B10_UNORM] = {
.Name = MESA_FORMAT_A2R10G10B10_UNORM,
.StrName = "MESA_FORMAT_A2R10G10B10_UNORM",
.Layout = MESA_FORMAT_LAYOUT_PACKED,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 10, .GreenBits = 10, .BlueBits = 10, .AlphaBits = 2,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 4,
.Swizzle = { 1, 2, 3, 0 },
.ArrayFormat = 0,
},
[MESA_FORMAT_YCBCR] = {
.Name = MESA_FORMAT_YCBCR,
.StrName = "MESA_FORMAT_YCBCR",
.Layout = MESA_FORMAT_LAYOUT_OTHER,
.BaseFormat = GL_YCBCR_MESA,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 0, .GreenBits = 0, .BlueBits = 0, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 2,
.Swizzle = { 0, 1, 2, 3 },
.ArrayFormat = 0,
},
[MESA_FORMAT_YCBCR_REV] = {
.Name = MESA_FORMAT_YCBCR_REV,
.StrName = "MESA_FORMAT_YCBCR_REV",
.Layout = MESA_FORMAT_LAYOUT_OTHER,
.BaseFormat = GL_YCBCR_MESA,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 0, .GreenBits = 0, .BlueBits = 0, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 2,
.Swizzle = { 0, 1, 2, 3 },
.ArrayFormat = 0,
},
[MESA_FORMAT_RG_RB_UNORM8] = {
.Name = MESA_FORMAT_RG_RB_UNORM8,
.StrName = "MESA_FORMAT_RG_RB_UNORM8",
.Layout = MESA_FORMAT_LAYOUT_OTHER,
.BaseFormat = GL_RGB,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 8, .GreenBits = 8, .BlueBits = 8, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 2, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 2,
.Swizzle = { 0, 1, 2, 5 },
.ArrayFormat = 0,
},
[MESA_FORMAT_GR_BR_UNORM8] = {
.Name = MESA_FORMAT_GR_BR_UNORM8,
.StrName = "MESA_FORMAT_GR_BR_UNORM8",
.Layout = MESA_FORMAT_LAYOUT_OTHER,
.BaseFormat = GL_RGB,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 8, .GreenBits = 8, .BlueBits = 8, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 2, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 2,
.Swizzle = { 0, 1, 2, 5 },
.ArrayFormat = 0,
},
[MESA_FORMAT_A_UNORM8] = {
.Name = MESA_FORMAT_A_UNORM8,
.StrName = "MESA_FORMAT_A_UNORM8",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_ALPHA,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 0, .GreenBits = 0, .BlueBits = 0, .AlphaBits = 8,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 1,
.Swizzle = { 4, 4, 4, 0 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 1, 0, 0, 1, 1, 4, 4, 4, 0),
},
[MESA_FORMAT_A_UNORM16] = {
.Name = MESA_FORMAT_A_UNORM16,
.StrName = "MESA_FORMAT_A_UNORM16",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_ALPHA,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 0, .GreenBits = 0, .BlueBits = 0, .AlphaBits = 16,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 2,
.Swizzle = { 4, 4, 4, 0 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 2, 0, 0, 1, 1, 4, 4, 4, 0),
},
[MESA_FORMAT_L_UNORM8] = {
.Name = MESA_FORMAT_L_UNORM8,
.StrName = "MESA_FORMAT_L_UNORM8",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_LUMINANCE,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 0, .GreenBits = 0, .BlueBits = 0, .AlphaBits = 0,
.LuminanceBits = 8, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 1,
.Swizzle = { 0, 0, 0, 5 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 1, 0, 0, 1, 1, 0, 0, 0, 5),
},
[MESA_FORMAT_L_UNORM16] = {
.Name = MESA_FORMAT_L_UNORM16,
.StrName = "MESA_FORMAT_L_UNORM16",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_LUMINANCE,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 0, .GreenBits = 0, .BlueBits = 0, .AlphaBits = 0,
.LuminanceBits = 16, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 2,
.Swizzle = { 0, 0, 0, 5 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 2, 0, 0, 1, 1, 0, 0, 0, 5),
},
[MESA_FORMAT_LA_UNORM8] = {
.Name = MESA_FORMAT_LA_UNORM8,
.StrName = "MESA_FORMAT_LA_UNORM8",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_LUMINANCE_ALPHA,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 0, .GreenBits = 0, .BlueBits = 0, .AlphaBits = 8,
.LuminanceBits = 8, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 2,
.Swizzle = { 0, 0, 0, 1 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 1, 0, 0, 1, 2, 0, 0, 0, 1),
},
[MESA_FORMAT_LA_UNORM16] = {
.Name = MESA_FORMAT_LA_UNORM16,
.StrName = "MESA_FORMAT_LA_UNORM16",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_LUMINANCE_ALPHA,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 0, .GreenBits = 0, .BlueBits = 0, .AlphaBits = 16,
.LuminanceBits = 16, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 4,
.Swizzle = { 0, 0, 0, 1 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 2, 0, 0, 1, 2, 0, 0, 0, 1),
},
[MESA_FORMAT_I_UNORM8] = {
.Name = MESA_FORMAT_I_UNORM8,
.StrName = "MESA_FORMAT_I_UNORM8",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_INTENSITY,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 0, .GreenBits = 0, .BlueBits = 0, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 8, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 1,
.Swizzle = { 0, 0, 0, 0 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 1, 0, 0, 1, 1, 0, 0, 0, 0),
},
[MESA_FORMAT_I_UNORM16] = {
.Name = MESA_FORMAT_I_UNORM16,
.StrName = "MESA_FORMAT_I_UNORM16",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_INTENSITY,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 0, .GreenBits = 0, .BlueBits = 0, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 16, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 2,
.Swizzle = { 0, 0, 0, 0 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 2, 0, 0, 1, 1, 0, 0, 0, 0),
},
[MESA_FORMAT_R_UNORM8] = {
.Name = MESA_FORMAT_R_UNORM8,
.StrName = "MESA_FORMAT_R_UNORM8",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_RED,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 8, .GreenBits = 0, .BlueBits = 0, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 1,
.Swizzle = { 0, 4, 4, 5 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 1, 0, 0, 1, 1, 0, 4, 4, 5),
},
[MESA_FORMAT_R_UNORM16] = {
.Name = MESA_FORMAT_R_UNORM16,
.StrName = "MESA_FORMAT_R_UNORM16",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_RED,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 16, .GreenBits = 0, .BlueBits = 0, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 2,
.Swizzle = { 0, 4, 4, 5 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 2, 0, 0, 1, 1, 0, 4, 4, 5),
},
[MESA_FORMAT_RG_UNORM8] = {
.Name = MESA_FORMAT_RG_UNORM8,
.StrName = "MESA_FORMAT_RG_UNORM8",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_RG,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 8, .GreenBits = 8, .BlueBits = 0, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 2,
.Swizzle = { 0, 1, 4, 5 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 1, 0, 0, 1, 2, 0, 1, 4, 5),
},
[MESA_FORMAT_RG_UNORM16] = {
.Name = MESA_FORMAT_RG_UNORM16,
.StrName = "MESA_FORMAT_RG_UNORM16",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_RG,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 16, .GreenBits = 16, .BlueBits = 0, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 4,
.Swizzle = { 0, 1, 4, 5 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 2, 0, 0, 1, 2, 0, 1, 4, 5),
},
[MESA_FORMAT_BGR_UNORM8] = {
.Name = MESA_FORMAT_BGR_UNORM8,
.StrName = "MESA_FORMAT_BGR_UNORM8",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_RGB,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 8, .GreenBits = 8, .BlueBits = 8, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 3,
.Swizzle = { 2, 1, 0, 5 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 1, 0, 0, 1, 3, 2, 1, 0, 5),
},
[MESA_FORMAT_RGB_UNORM8] = {
.Name = MESA_FORMAT_RGB_UNORM8,
.StrName = "MESA_FORMAT_RGB_UNORM8",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_RGB,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 8, .GreenBits = 8, .BlueBits = 8, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 3,
.Swizzle = { 0, 1, 2, 5 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 1, 0, 0, 1, 3, 0, 1, 2, 5),
},
[MESA_FORMAT_RGBA_UNORM16] = {
.Name = MESA_FORMAT_RGBA_UNORM16,
.StrName = "MESA_FORMAT_RGBA_UNORM16",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 16, .GreenBits = 16, .BlueBits = 16, .AlphaBits = 16,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 8,
.Swizzle = { 0, 1, 2, 3 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 2, 0, 0, 1, 4, 0, 1, 2, 3),
},
[MESA_FORMAT_RGBX_UNORM16] = {
.Name = MESA_FORMAT_RGBX_UNORM16,
.StrName = "MESA_FORMAT_RGBX_UNORM16",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_RGB,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 16, .GreenBits = 16, .BlueBits = 16, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 8,
.Swizzle = { 0, 1, 2, 5 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 2, 0, 0, 1, 4, 0, 1, 2, 5),
},
[MESA_FORMAT_Z_UNORM16] = {
.Name = MESA_FORMAT_Z_UNORM16,
.StrName = "MESA_FORMAT_Z_UNORM16",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_DEPTH_COMPONENT,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 0, .GreenBits = 0, .BlueBits = 0, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 16, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 2,
.Swizzle = { 0, 6, 6, 6 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_DEPTH, 2, 0, 0, 1, 1, 0, 6, 6, 6),
},
[MESA_FORMAT_Z_UNORM32] = {
.Name = MESA_FORMAT_Z_UNORM32,
.StrName = "MESA_FORMAT_Z_UNORM32",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_DEPTH_COMPONENT,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 0, .GreenBits = 0, .BlueBits = 0, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 32, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 4,
.Swizzle = { 0, 6, 6, 6 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_DEPTH, 4, 0, 0, 1, 1, 0, 6, 6, 6),
},
[MESA_FORMAT_S_UINT8] = {
.Name = MESA_FORMAT_S_UINT8,
.StrName = "MESA_FORMAT_S_UINT8",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_STENCIL_INDEX,
.DataType = GL_UNSIGNED_INT,
.RedBits = 0, .GreenBits = 0, .BlueBits = 0, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 8,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 1,
.Swizzle = { 6, 0, 6, 6 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_STENCIL, 1, 0, 0, 0, 1, 6, 0, 6, 6),
},
[MESA_FORMAT_A8B8G8R8_SNORM] = {
.Name = MESA_FORMAT_A8B8G8R8_SNORM,
.StrName = "MESA_FORMAT_A8B8G8R8_SNORM",
.Layout = MESA_FORMAT_LAYOUT_PACKED,
.BaseFormat = GL_RGBA,
.DataType = GL_SIGNED_NORMALIZED,
.RedBits = 8, .GreenBits = 8, .BlueBits = 8, .AlphaBits = 8,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 4,
.Swizzle = { 3, 2, 1, 0 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 1, 1, 0, 1, 4, 3, 2, 1, 0),
},
[MESA_FORMAT_X8B8G8R8_SNORM] = {
.Name = MESA_FORMAT_X8B8G8R8_SNORM,
.StrName = "MESA_FORMAT_X8B8G8R8_SNORM",
.Layout = MESA_FORMAT_LAYOUT_PACKED,
.BaseFormat = GL_RGB,
.DataType = GL_SIGNED_NORMALIZED,
.RedBits = 8, .GreenBits = 8, .BlueBits = 8, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 4,
.Swizzle = { 3, 2, 1, 5 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 1, 1, 0, 1, 4, 3, 2, 1, 5),
},
[MESA_FORMAT_R8G8B8A8_SNORM] = {
.Name = MESA_FORMAT_R8G8B8A8_SNORM,
.StrName = "MESA_FORMAT_R8G8B8A8_SNORM",
.Layout = MESA_FORMAT_LAYOUT_PACKED,
.BaseFormat = GL_RGBA,
.DataType = GL_SIGNED_NORMALIZED,
.RedBits = 8, .GreenBits = 8, .BlueBits = 8, .AlphaBits = 8,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 4,
.Swizzle = { 0, 1, 2, 3 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 1, 1, 0, 1, 4, 0, 1, 2, 3),
},
[MESA_FORMAT_R8G8B8X8_SNORM] = {
.Name = MESA_FORMAT_R8G8B8X8_SNORM,
.StrName = "MESA_FORMAT_R8G8B8X8_SNORM",
.Layout = MESA_FORMAT_LAYOUT_PACKED,
.BaseFormat = GL_RGB,
.DataType = GL_SIGNED_NORMALIZED,
.RedBits = 8, .GreenBits = 8, .BlueBits = 8, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 4,
.Swizzle = { 0, 1, 2, 5 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 1, 1, 0, 1, 4, 0, 1, 2, 5),
},
[MESA_FORMAT_A_SNORM8] = {
.Name = MESA_FORMAT_A_SNORM8,
.StrName = "MESA_FORMAT_A_SNORM8",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_ALPHA,
.DataType = GL_SIGNED_NORMALIZED,
.RedBits = 0, .GreenBits = 0, .BlueBits = 0, .AlphaBits = 8,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 1,
.Swizzle = { 4, 4, 4, 0 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 1, 1, 0, 1, 1, 4, 4, 4, 0),
},
[MESA_FORMAT_A_SNORM16] = {
.Name = MESA_FORMAT_A_SNORM16,
.StrName = "MESA_FORMAT_A_SNORM16",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_ALPHA,
.DataType = GL_SIGNED_NORMALIZED,
.RedBits = 0, .GreenBits = 0, .BlueBits = 0, .AlphaBits = 16,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 2,
.Swizzle = { 4, 4, 4, 0 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 2, 1, 0, 1, 1, 4, 4, 4, 0),
},
[MESA_FORMAT_L_SNORM8] = {
.Name = MESA_FORMAT_L_SNORM8,
.StrName = "MESA_FORMAT_L_SNORM8",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_LUMINANCE,
.DataType = GL_SIGNED_NORMALIZED,
.RedBits = 0, .GreenBits = 0, .BlueBits = 0, .AlphaBits = 0,
.LuminanceBits = 8, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 1,
.Swizzle = { 0, 0, 0, 5 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 1, 1, 0, 1, 1, 0, 0, 0, 5),
},
[MESA_FORMAT_L_SNORM16] = {
.Name = MESA_FORMAT_L_SNORM16,
.StrName = "MESA_FORMAT_L_SNORM16",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_LUMINANCE,
.DataType = GL_SIGNED_NORMALIZED,
.RedBits = 0, .GreenBits = 0, .BlueBits = 0, .AlphaBits = 0,
.LuminanceBits = 16, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 2,
.Swizzle = { 0, 0, 0, 5 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 2, 1, 0, 1, 1, 0, 0, 0, 5),
},
[MESA_FORMAT_I_SNORM8] = {
.Name = MESA_FORMAT_I_SNORM8,
.StrName = "MESA_FORMAT_I_SNORM8",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_INTENSITY,
.DataType = GL_SIGNED_NORMALIZED,
.RedBits = 0, .GreenBits = 0, .BlueBits = 0, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 8, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 1,
.Swizzle = { 0, 0, 0, 0 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 1, 1, 0, 1, 1, 0, 0, 0, 0),
},
[MESA_FORMAT_I_SNORM16] = {
.Name = MESA_FORMAT_I_SNORM16,
.StrName = "MESA_FORMAT_I_SNORM16",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_INTENSITY,
.DataType = GL_SIGNED_NORMALIZED,
.RedBits = 0, .GreenBits = 0, .BlueBits = 0, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 16, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 2,
.Swizzle = { 0, 0, 0, 0 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 2, 1, 0, 1, 1, 0, 0, 0, 0),
},
[MESA_FORMAT_R_SNORM8] = {
.Name = MESA_FORMAT_R_SNORM8,
.StrName = "MESA_FORMAT_R_SNORM8",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_RED,
.DataType = GL_SIGNED_NORMALIZED,
.RedBits = 8, .GreenBits = 0, .BlueBits = 0, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 1,
.Swizzle = { 0, 4, 4, 5 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 1, 1, 0, 1, 1, 0, 4, 4, 5),
},
[MESA_FORMAT_R_SNORM16] = {
.Name = MESA_FORMAT_R_SNORM16,
.StrName = "MESA_FORMAT_R_SNORM16",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_RED,
.DataType = GL_SIGNED_NORMALIZED,
.RedBits = 16, .GreenBits = 0, .BlueBits = 0, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 2,
.Swizzle = { 0, 4, 4, 5 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 2, 1, 0, 1, 1, 0, 4, 4, 5),
},
[MESA_FORMAT_LA_SNORM8] = {
.Name = MESA_FORMAT_LA_SNORM8,
.StrName = "MESA_FORMAT_LA_SNORM8",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_LUMINANCE_ALPHA,
.DataType = GL_SIGNED_NORMALIZED,
.RedBits = 0, .GreenBits = 0, .BlueBits = 0, .AlphaBits = 8,
.LuminanceBits = 8, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 2,
.Swizzle = { 0, 0, 0, 1 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 1, 1, 0, 1, 2, 0, 0, 0, 1),
},
[MESA_FORMAT_LA_SNORM16] = {
.Name = MESA_FORMAT_LA_SNORM16,
.StrName = "MESA_FORMAT_LA_SNORM16",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_LUMINANCE_ALPHA,
.DataType = GL_SIGNED_NORMALIZED,
.RedBits = 0, .GreenBits = 0, .BlueBits = 0, .AlphaBits = 16,
.LuminanceBits = 16, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 4,
.Swizzle = { 0, 0, 0, 1 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 2, 1, 0, 1, 2, 0, 0, 0, 1),
},
[MESA_FORMAT_RG_SNORM8] = {
.Name = MESA_FORMAT_RG_SNORM8,
.StrName = "MESA_FORMAT_RG_SNORM8",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_RG,
.DataType = GL_SIGNED_NORMALIZED,
.RedBits = 8, .GreenBits = 8, .BlueBits = 0, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 2,
.Swizzle = { 0, 1, 4, 5 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 1, 1, 0, 1, 2, 0, 1, 4, 5),
},
[MESA_FORMAT_RG_SNORM16] = {
.Name = MESA_FORMAT_RG_SNORM16,
.StrName = "MESA_FORMAT_RG_SNORM16",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_RG,
.DataType = GL_SIGNED_NORMALIZED,
.RedBits = 16, .GreenBits = 16, .BlueBits = 0, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 4,
.Swizzle = { 0, 1, 4, 5 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 2, 1, 0, 1, 2, 0, 1, 4, 5),
},
[MESA_FORMAT_RGB_SNORM16] = {
.Name = MESA_FORMAT_RGB_SNORM16,
.StrName = "MESA_FORMAT_RGB_SNORM16",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_RGB,
.DataType = GL_SIGNED_NORMALIZED,
.RedBits = 16, .GreenBits = 16, .BlueBits = 16, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 6,
.Swizzle = { 0, 1, 2, 5 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 2, 1, 0, 1, 3, 0, 1, 2, 5),
},
[MESA_FORMAT_RGBA_SNORM16] = {
.Name = MESA_FORMAT_RGBA_SNORM16,
.StrName = "MESA_FORMAT_RGBA_SNORM16",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_RGBA,
.DataType = GL_SIGNED_NORMALIZED,
.RedBits = 16, .GreenBits = 16, .BlueBits = 16, .AlphaBits = 16,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 8,
.Swizzle = { 0, 1, 2, 3 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 2, 1, 0, 1, 4, 0, 1, 2, 3),
},
[MESA_FORMAT_RGBX_SNORM16] = {
.Name = MESA_FORMAT_RGBX_SNORM16,
.StrName = "MESA_FORMAT_RGBX_SNORM16",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_RGB,
.DataType = GL_SIGNED_NORMALIZED,
.RedBits = 16, .GreenBits = 16, .BlueBits = 16, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 8,
.Swizzle = { 0, 1, 2, 5 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 2, 1, 0, 1, 4, 0, 1, 2, 5),
},
[MESA_FORMAT_A8B8G8R8_SRGB] = {
.Name = MESA_FORMAT_A8B8G8R8_SRGB,
.StrName = "MESA_FORMAT_A8B8G8R8_SRGB",
.Layout = MESA_FORMAT_LAYOUT_PACKED,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 8, .GreenBits = 8, .BlueBits = 8, .AlphaBits = 8,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 1,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 4,
.Swizzle = { 3, 2, 1, 0 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 1, 0, 0, 1, 4, 3, 2, 1, 0),
},
[MESA_FORMAT_B8G8R8A8_SRGB] = {
.Name = MESA_FORMAT_B8G8R8A8_SRGB,
.StrName = "MESA_FORMAT_B8G8R8A8_SRGB",
.Layout = MESA_FORMAT_LAYOUT_PACKED,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 8, .GreenBits = 8, .BlueBits = 8, .AlphaBits = 8,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 1,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 4,
.Swizzle = { 2, 1, 0, 3 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 1, 0, 0, 1, 4, 2, 1, 0, 3),
},
[MESA_FORMAT_A8R8G8B8_SRGB] = {
.Name = MESA_FORMAT_A8R8G8B8_SRGB,
.StrName = "MESA_FORMAT_A8R8G8B8_SRGB",
.Layout = MESA_FORMAT_LAYOUT_PACKED,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 8, .GreenBits = 8, .BlueBits = 8, .AlphaBits = 8,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 1,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 4,
.Swizzle = { 1, 2, 3, 0 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 1, 0, 0, 1, 4, 1, 2, 3, 0),
},
[MESA_FORMAT_B8G8R8X8_SRGB] = {
.Name = MESA_FORMAT_B8G8R8X8_SRGB,
.StrName = "MESA_FORMAT_B8G8R8X8_SRGB",
.Layout = MESA_FORMAT_LAYOUT_PACKED,
.BaseFormat = GL_RGB,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 8, .GreenBits = 8, .BlueBits = 8, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 1,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 4,
.Swizzle = { 2, 1, 0, 5 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 1, 0, 0, 1, 4, 2, 1, 0, 5),
},
[MESA_FORMAT_X8R8G8B8_SRGB] = {
.Name = MESA_FORMAT_X8R8G8B8_SRGB,
.StrName = "MESA_FORMAT_X8R8G8B8_SRGB",
.Layout = MESA_FORMAT_LAYOUT_PACKED,
.BaseFormat = GL_RGB,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 8, .GreenBits = 8, .BlueBits = 8, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 1,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 4,
.Swizzle = { 1, 2, 3, 5 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 1, 0, 0, 1, 4, 1, 2, 3, 5),
},
[MESA_FORMAT_R8G8B8A8_SRGB] = {
.Name = MESA_FORMAT_R8G8B8A8_SRGB,
.StrName = "MESA_FORMAT_R8G8B8A8_SRGB",
.Layout = MESA_FORMAT_LAYOUT_PACKED,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 8, .GreenBits = 8, .BlueBits = 8, .AlphaBits = 8,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 1,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 4,
.Swizzle = { 0, 1, 2, 3 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 1, 0, 0, 1, 4, 0, 1, 2, 3),
},
[MESA_FORMAT_R8G8B8X8_SRGB] = {
.Name = MESA_FORMAT_R8G8B8X8_SRGB,
.StrName = "MESA_FORMAT_R8G8B8X8_SRGB",
.Layout = MESA_FORMAT_LAYOUT_PACKED,
.BaseFormat = GL_RGB,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 8, .GreenBits = 8, .BlueBits = 8, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 1,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 4,
.Swizzle = { 0, 1, 2, 5 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 1, 0, 0, 1, 4, 0, 1, 2, 5),
},
[MESA_FORMAT_X8B8G8R8_SRGB] = {
.Name = MESA_FORMAT_X8B8G8R8_SRGB,
.StrName = "MESA_FORMAT_X8B8G8R8_SRGB",
.Layout = MESA_FORMAT_LAYOUT_PACKED,
.BaseFormat = GL_RGB,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 8, .GreenBits = 8, .BlueBits = 8, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 1,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 4,
.Swizzle = { 3, 2, 1, 5 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 1, 0, 0, 1, 4, 3, 2, 1, 5),
},
[MESA_FORMAT_R_SRGB8] = {
.Name = MESA_FORMAT_R_SRGB8,
.StrName = "MESA_FORMAT_R_SRGB8",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_RED,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 8, .GreenBits = 0, .BlueBits = 0, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 1,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 1,
.Swizzle = { 0, 4, 4, 5 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 1, 0, 0, 1, 1, 0, 4, 4, 5),
},
[MESA_FORMAT_L_SRGB8] = {
.Name = MESA_FORMAT_L_SRGB8,
.StrName = "MESA_FORMAT_L_SRGB8",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_LUMINANCE,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 0, .GreenBits = 0, .BlueBits = 0, .AlphaBits = 0,
.LuminanceBits = 8, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 1,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 1,
.Swizzle = { 0, 0, 0, 5 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 1, 0, 0, 1, 1, 0, 0, 0, 5),
},
[MESA_FORMAT_RG_SRGB8] = {
.Name = MESA_FORMAT_RG_SRGB8,
.StrName = "MESA_FORMAT_RG_SRGB8",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_RG,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 8, .GreenBits = 8, .BlueBits = 0, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 1,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 2,
.Swizzle = { 0, 1, 4, 5 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 1, 0, 0, 1, 2, 0, 1, 4, 5),
},
[MESA_FORMAT_LA_SRGB8] = {
.Name = MESA_FORMAT_LA_SRGB8,
.StrName = "MESA_FORMAT_LA_SRGB8",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_LUMINANCE_ALPHA,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 0, .GreenBits = 0, .BlueBits = 0, .AlphaBits = 8,
.LuminanceBits = 8, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 1,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 2,
.Swizzle = { 0, 0, 0, 1 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 1, 0, 0, 1, 2, 0, 0, 0, 1),
},
[MESA_FORMAT_BGR_SRGB8] = {
.Name = MESA_FORMAT_BGR_SRGB8,
.StrName = "MESA_FORMAT_BGR_SRGB8",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_RGB,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 8, .GreenBits = 8, .BlueBits = 8, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 1,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 3,
.Swizzle = { 2, 1, 0, 5 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 1, 0, 0, 1, 3, 2, 1, 0, 5),
},
[MESA_FORMAT_R9G9B9E5_FLOAT] = {
.Name = MESA_FORMAT_R9G9B9E5_FLOAT,
.StrName = "MESA_FORMAT_R9G9B9E5_FLOAT",
.Layout = MESA_FORMAT_LAYOUT_OTHER,
.BaseFormat = GL_RGB,
.DataType = GL_FLOAT,
.RedBits = 9, .GreenBits = 9, .BlueBits = 9, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 4,
.Swizzle = { 0, 1, 2, 5 },
.ArrayFormat = 0,
},
[MESA_FORMAT_R11G11B10_FLOAT] = {
.Name = MESA_FORMAT_R11G11B10_FLOAT,
.StrName = "MESA_FORMAT_R11G11B10_FLOAT",
.Layout = MESA_FORMAT_LAYOUT_PACKED,
.BaseFormat = GL_RGB,
.DataType = GL_FLOAT,
.RedBits = 11, .GreenBits = 11, .BlueBits = 10, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 4,
.Swizzle = { 0, 1, 2, 5 },
.ArrayFormat = 0,
},
[MESA_FORMAT_Z32_FLOAT_S8X24_UINT] = {
.Name = MESA_FORMAT_Z32_FLOAT_S8X24_UINT,
.StrName = "MESA_FORMAT_Z32_FLOAT_S8X24_UINT",
.Layout = MESA_FORMAT_LAYOUT_PACKED,
.BaseFormat = GL_DEPTH_STENCIL,
.DataType = GL_FLOAT,
.RedBits = 0, .GreenBits = 0, .BlueBits = 0, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 32, .StencilBits = 8,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 8,
.Swizzle = { 2, 0, 6, 6 },
.ArrayFormat = 0,
},
[MESA_FORMAT_A_FLOAT16] = {
.Name = MESA_FORMAT_A_FLOAT16,
.StrName = "MESA_FORMAT_A_FLOAT16",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_ALPHA,
.DataType = GL_FLOAT,
.RedBits = 0, .GreenBits = 0, .BlueBits = 0, .AlphaBits = 16,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 2,
.Swizzle = { 4, 4, 4, 0 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 2, 1, 1, 1, 1, 4, 4, 4, 0),
},
[MESA_FORMAT_A_FLOAT32] = {
.Name = MESA_FORMAT_A_FLOAT32,
.StrName = "MESA_FORMAT_A_FLOAT32",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_ALPHA,
.DataType = GL_FLOAT,
.RedBits = 0, .GreenBits = 0, .BlueBits = 0, .AlphaBits = 32,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 4,
.Swizzle = { 4, 4, 4, 0 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 4, 1, 1, 1, 1, 4, 4, 4, 0),
},
[MESA_FORMAT_L_FLOAT16] = {
.Name = MESA_FORMAT_L_FLOAT16,
.StrName = "MESA_FORMAT_L_FLOAT16",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_LUMINANCE,
.DataType = GL_FLOAT,
.RedBits = 0, .GreenBits = 0, .BlueBits = 0, .AlphaBits = 0,
.LuminanceBits = 16, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 2,
.Swizzle = { 0, 0, 0, 5 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 2, 1, 1, 1, 1, 0, 0, 0, 5),
},
[MESA_FORMAT_L_FLOAT32] = {
.Name = MESA_FORMAT_L_FLOAT32,
.StrName = "MESA_FORMAT_L_FLOAT32",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_LUMINANCE,
.DataType = GL_FLOAT,
.RedBits = 0, .GreenBits = 0, .BlueBits = 0, .AlphaBits = 0,
.LuminanceBits = 32, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 4,
.Swizzle = { 0, 0, 0, 5 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 4, 1, 1, 1, 1, 0, 0, 0, 5),
},
[MESA_FORMAT_LA_FLOAT16] = {
.Name = MESA_FORMAT_LA_FLOAT16,
.StrName = "MESA_FORMAT_LA_FLOAT16",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_LUMINANCE_ALPHA,
.DataType = GL_FLOAT,
.RedBits = 0, .GreenBits = 0, .BlueBits = 0, .AlphaBits = 16,
.LuminanceBits = 16, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 4,
.Swizzle = { 0, 0, 0, 1 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 2, 1, 1, 1, 2, 0, 0, 0, 1),
},
[MESA_FORMAT_LA_FLOAT32] = {
.Name = MESA_FORMAT_LA_FLOAT32,
.StrName = "MESA_FORMAT_LA_FLOAT32",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_LUMINANCE_ALPHA,
.DataType = GL_FLOAT,
.RedBits = 0, .GreenBits = 0, .BlueBits = 0, .AlphaBits = 32,
.LuminanceBits = 32, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 8,
.Swizzle = { 0, 0, 0, 1 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 4, 1, 1, 1, 2, 0, 0, 0, 1),
},
[MESA_FORMAT_I_FLOAT16] = {
.Name = MESA_FORMAT_I_FLOAT16,
.StrName = "MESA_FORMAT_I_FLOAT16",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_INTENSITY,
.DataType = GL_FLOAT,
.RedBits = 0, .GreenBits = 0, .BlueBits = 0, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 16, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 2,
.Swizzle = { 0, 0, 0, 0 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 2, 1, 1, 1, 1, 0, 0, 0, 0),
},
[MESA_FORMAT_I_FLOAT32] = {
.Name = MESA_FORMAT_I_FLOAT32,
.StrName = "MESA_FORMAT_I_FLOAT32",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_INTENSITY,
.DataType = GL_FLOAT,
.RedBits = 0, .GreenBits = 0, .BlueBits = 0, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 32, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 4,
.Swizzle = { 0, 0, 0, 0 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 4, 1, 1, 1, 1, 0, 0, 0, 0),
},
[MESA_FORMAT_R_FLOAT16] = {
.Name = MESA_FORMAT_R_FLOAT16,
.StrName = "MESA_FORMAT_R_FLOAT16",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_RED,
.DataType = GL_FLOAT,
.RedBits = 16, .GreenBits = 0, .BlueBits = 0, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 2,
.Swizzle = { 0, 4, 4, 5 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 2, 1, 1, 1, 1, 0, 4, 4, 5),
},
[MESA_FORMAT_R_FLOAT32] = {
.Name = MESA_FORMAT_R_FLOAT32,
.StrName = "MESA_FORMAT_R_FLOAT32",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_RED,
.DataType = GL_FLOAT,
.RedBits = 32, .GreenBits = 0, .BlueBits = 0, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 4,
.Swizzle = { 0, 4, 4, 5 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 4, 1, 1, 1, 1, 0, 4, 4, 5),
},
[MESA_FORMAT_RG_FLOAT16] = {
.Name = MESA_FORMAT_RG_FLOAT16,
.StrName = "MESA_FORMAT_RG_FLOAT16",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_RG,
.DataType = GL_FLOAT,
.RedBits = 16, .GreenBits = 16, .BlueBits = 0, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 4,
.Swizzle = { 0, 1, 4, 5 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 2, 1, 1, 1, 2, 0, 1, 4, 5),
},
[MESA_FORMAT_RG_FLOAT32] = {
.Name = MESA_FORMAT_RG_FLOAT32,
.StrName = "MESA_FORMAT_RG_FLOAT32",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_RG,
.DataType = GL_FLOAT,
.RedBits = 32, .GreenBits = 32, .BlueBits = 0, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 8,
.Swizzle = { 0, 1, 4, 5 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 4, 1, 1, 1, 2, 0, 1, 4, 5),
},
[MESA_FORMAT_RGB_FLOAT16] = {
.Name = MESA_FORMAT_RGB_FLOAT16,
.StrName = "MESA_FORMAT_RGB_FLOAT16",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_RGB,
.DataType = GL_FLOAT,
.RedBits = 16, .GreenBits = 16, .BlueBits = 16, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 6,
.Swizzle = { 0, 1, 2, 5 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 2, 1, 1, 1, 3, 0, 1, 2, 5),
},
[MESA_FORMAT_RGB_FLOAT32] = {
.Name = MESA_FORMAT_RGB_FLOAT32,
.StrName = "MESA_FORMAT_RGB_FLOAT32",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_RGB,
.DataType = GL_FLOAT,
.RedBits = 32, .GreenBits = 32, .BlueBits = 32, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 12,
.Swizzle = { 0, 1, 2, 5 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 4, 1, 1, 1, 3, 0, 1, 2, 5),
},
[MESA_FORMAT_RGBA_FLOAT16] = {
.Name = MESA_FORMAT_RGBA_FLOAT16,
.StrName = "MESA_FORMAT_RGBA_FLOAT16",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_RGBA,
.DataType = GL_FLOAT,
.RedBits = 16, .GreenBits = 16, .BlueBits = 16, .AlphaBits = 16,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 8,
.Swizzle = { 0, 1, 2, 3 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 2, 1, 1, 1, 4, 0, 1, 2, 3),
},
[MESA_FORMAT_RGBA_FLOAT32] = {
.Name = MESA_FORMAT_RGBA_FLOAT32,
.StrName = "MESA_FORMAT_RGBA_FLOAT32",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_RGBA,
.DataType = GL_FLOAT,
.RedBits = 32, .GreenBits = 32, .BlueBits = 32, .AlphaBits = 32,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 16,
.Swizzle = { 0, 1, 2, 3 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 4, 1, 1, 1, 4, 0, 1, 2, 3),
},
[MESA_FORMAT_RGBX_FLOAT16] = {
.Name = MESA_FORMAT_RGBX_FLOAT16,
.StrName = "MESA_FORMAT_RGBX_FLOAT16",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_RGB,
.DataType = GL_FLOAT,
.RedBits = 16, .GreenBits = 16, .BlueBits = 16, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 8,
.Swizzle = { 0, 1, 2, 5 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 2, 1, 1, 1, 4, 0, 1, 2, 5),
},
[MESA_FORMAT_RGBX_FLOAT32] = {
.Name = MESA_FORMAT_RGBX_FLOAT32,
.StrName = "MESA_FORMAT_RGBX_FLOAT32",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_RGB,
.DataType = GL_FLOAT,
.RedBits = 32, .GreenBits = 32, .BlueBits = 32, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 16,
.Swizzle = { 0, 1, 2, 5 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 4, 1, 1, 1, 4, 0, 1, 2, 5),
},
[MESA_FORMAT_Z_FLOAT32] = {
.Name = MESA_FORMAT_Z_FLOAT32,
.StrName = "MESA_FORMAT_Z_FLOAT32",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_DEPTH_COMPONENT,
.DataType = GL_FLOAT,
.RedBits = 0, .GreenBits = 0, .BlueBits = 0, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 32, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 4,
.Swizzle = { 0, 6, 6, 6 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_DEPTH, 4, 1, 1, 1, 1, 0, 6, 6, 6),
},
[MESA_FORMAT_A8B8G8R8_UINT] = {
.Name = MESA_FORMAT_A8B8G8R8_UINT,
.StrName = "MESA_FORMAT_A8B8G8R8_UINT",
.Layout = MESA_FORMAT_LAYOUT_PACKED,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_INT,
.RedBits = 8, .GreenBits = 8, .BlueBits = 8, .AlphaBits = 8,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 4,
.Swizzle = { 3, 2, 1, 0 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 1, 0, 0, 0, 4, 3, 2, 1, 0),
},
[MESA_FORMAT_A8R8G8B8_UINT] = {
.Name = MESA_FORMAT_A8R8G8B8_UINT,
.StrName = "MESA_FORMAT_A8R8G8B8_UINT",
.Layout = MESA_FORMAT_LAYOUT_PACKED,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_INT,
.RedBits = 8, .GreenBits = 8, .BlueBits = 8, .AlphaBits = 8,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 4,
.Swizzle = { 1, 2, 3, 0 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 1, 0, 0, 0, 4, 1, 2, 3, 0),
},
[MESA_FORMAT_R8G8B8A8_UINT] = {
.Name = MESA_FORMAT_R8G8B8A8_UINT,
.StrName = "MESA_FORMAT_R8G8B8A8_UINT",
.Layout = MESA_FORMAT_LAYOUT_PACKED,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_INT,
.RedBits = 8, .GreenBits = 8, .BlueBits = 8, .AlphaBits = 8,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 4,
.Swizzle = { 0, 1, 2, 3 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 1, 0, 0, 0, 4, 0, 1, 2, 3),
},
[MESA_FORMAT_B8G8R8A8_UINT] = {
.Name = MESA_FORMAT_B8G8R8A8_UINT,
.StrName = "MESA_FORMAT_B8G8R8A8_UINT",
.Layout = MESA_FORMAT_LAYOUT_PACKED,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_INT,
.RedBits = 8, .GreenBits = 8, .BlueBits = 8, .AlphaBits = 8,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 4,
.Swizzle = { 2, 1, 0, 3 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 1, 0, 0, 0, 4, 2, 1, 0, 3),
},
[MESA_FORMAT_B10G10R10A2_UINT] = {
.Name = MESA_FORMAT_B10G10R10A2_UINT,
.StrName = "MESA_FORMAT_B10G10R10A2_UINT",
.Layout = MESA_FORMAT_LAYOUT_PACKED,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_INT,
.RedBits = 10, .GreenBits = 10, .BlueBits = 10, .AlphaBits = 2,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 4,
.Swizzle = { 2, 1, 0, 3 },
.ArrayFormat = 0,
},
[MESA_FORMAT_R10G10B10A2_UINT] = {
.Name = MESA_FORMAT_R10G10B10A2_UINT,
.StrName = "MESA_FORMAT_R10G10B10A2_UINT",
.Layout = MESA_FORMAT_LAYOUT_PACKED,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_INT,
.RedBits = 10, .GreenBits = 10, .BlueBits = 10, .AlphaBits = 2,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 4,
.Swizzle = { 0, 1, 2, 3 },
.ArrayFormat = 0,
},
[MESA_FORMAT_A2B10G10R10_UINT] = {
.Name = MESA_FORMAT_A2B10G10R10_UINT,
.StrName = "MESA_FORMAT_A2B10G10R10_UINT",
.Layout = MESA_FORMAT_LAYOUT_PACKED,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_INT,
.RedBits = 10, .GreenBits = 10, .BlueBits = 10, .AlphaBits = 2,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 4,
.Swizzle = { 3, 2, 1, 0 },
.ArrayFormat = 0,
},
[MESA_FORMAT_A2R10G10B10_UINT] = {
.Name = MESA_FORMAT_A2R10G10B10_UINT,
.StrName = "MESA_FORMAT_A2R10G10B10_UINT",
.Layout = MESA_FORMAT_LAYOUT_PACKED,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_INT,
.RedBits = 10, .GreenBits = 10, .BlueBits = 10, .AlphaBits = 2,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 4,
.Swizzle = { 1, 2, 3, 0 },
.ArrayFormat = 0,
},
[MESA_FORMAT_B5G6R5_UINT] = {
.Name = MESA_FORMAT_B5G6R5_UINT,
.StrName = "MESA_FORMAT_B5G6R5_UINT",
.Layout = MESA_FORMAT_LAYOUT_PACKED,
.BaseFormat = GL_RGB,
.DataType = GL_UNSIGNED_INT,
.RedBits = 5, .GreenBits = 6, .BlueBits = 5, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 2,
.Swizzle = { 2, 1, 0, 5 },
.ArrayFormat = 0,
},
[MESA_FORMAT_R5G6B5_UINT] = {
.Name = MESA_FORMAT_R5G6B5_UINT,
.StrName = "MESA_FORMAT_R5G6B5_UINT",
.Layout = MESA_FORMAT_LAYOUT_PACKED,
.BaseFormat = GL_RGB,
.DataType = GL_UNSIGNED_INT,
.RedBits = 5, .GreenBits = 6, .BlueBits = 5, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 2,
.Swizzle = { 0, 1, 2, 5 },
.ArrayFormat = 0,
},
[MESA_FORMAT_B2G3R3_UINT] = {
.Name = MESA_FORMAT_B2G3R3_UINT,
.StrName = "MESA_FORMAT_B2G3R3_UINT",
.Layout = MESA_FORMAT_LAYOUT_PACKED,
.BaseFormat = GL_RGB,
.DataType = GL_UNSIGNED_INT,
.RedBits = 3, .GreenBits = 3, .BlueBits = 2, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 1,
.Swizzle = { 2, 1, 0, 5 },
.ArrayFormat = 0,
},
[MESA_FORMAT_R3G3B2_UINT] = {
.Name = MESA_FORMAT_R3G3B2_UINT,
.StrName = "MESA_FORMAT_R3G3B2_UINT",
.Layout = MESA_FORMAT_LAYOUT_PACKED,
.BaseFormat = GL_RGB,
.DataType = GL_UNSIGNED_INT,
.RedBits = 3, .GreenBits = 3, .BlueBits = 2, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 1,
.Swizzle = { 0, 1, 2, 5 },
.ArrayFormat = 0,
},
[MESA_FORMAT_A4B4G4R4_UINT] = {
.Name = MESA_FORMAT_A4B4G4R4_UINT,
.StrName = "MESA_FORMAT_A4B4G4R4_UINT",
.Layout = MESA_FORMAT_LAYOUT_PACKED,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_INT,
.RedBits = 4, .GreenBits = 4, .BlueBits = 4, .AlphaBits = 4,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 2,
.Swizzle = { 3, 2, 1, 0 },
.ArrayFormat = 0,
},
[MESA_FORMAT_R4G4B4A4_UINT] = {
.Name = MESA_FORMAT_R4G4B4A4_UINT,
.StrName = "MESA_FORMAT_R4G4B4A4_UINT",
.Layout = MESA_FORMAT_LAYOUT_PACKED,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_INT,
.RedBits = 4, .GreenBits = 4, .BlueBits = 4, .AlphaBits = 4,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 2,
.Swizzle = { 0, 1, 2, 3 },
.ArrayFormat = 0,
},
[MESA_FORMAT_B4G4R4A4_UINT] = {
.Name = MESA_FORMAT_B4G4R4A4_UINT,
.StrName = "MESA_FORMAT_B4G4R4A4_UINT",
.Layout = MESA_FORMAT_LAYOUT_PACKED,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_INT,
.RedBits = 4, .GreenBits = 4, .BlueBits = 4, .AlphaBits = 4,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 2,
.Swizzle = { 2, 1, 0, 3 },
.ArrayFormat = 0,
},
[MESA_FORMAT_A4R4G4B4_UINT] = {
.Name = MESA_FORMAT_A4R4G4B4_UINT,
.StrName = "MESA_FORMAT_A4R4G4B4_UINT",
.Layout = MESA_FORMAT_LAYOUT_PACKED,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_INT,
.RedBits = 4, .GreenBits = 4, .BlueBits = 4, .AlphaBits = 4,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 2,
.Swizzle = { 1, 2, 3, 0 },
.ArrayFormat = 0,
},
[MESA_FORMAT_A1B5G5R5_UINT] = {
.Name = MESA_FORMAT_A1B5G5R5_UINT,
.StrName = "MESA_FORMAT_A1B5G5R5_UINT",
.Layout = MESA_FORMAT_LAYOUT_PACKED,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_INT,
.RedBits = 5, .GreenBits = 5, .BlueBits = 5, .AlphaBits = 1,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 2,
.Swizzle = { 3, 2, 1, 0 },
.ArrayFormat = 0,
},
[MESA_FORMAT_B5G5R5A1_UINT] = {
.Name = MESA_FORMAT_B5G5R5A1_UINT,
.StrName = "MESA_FORMAT_B5G5R5A1_UINT",
.Layout = MESA_FORMAT_LAYOUT_PACKED,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_INT,
.RedBits = 5, .GreenBits = 5, .BlueBits = 5, .AlphaBits = 1,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 2,
.Swizzle = { 2, 1, 0, 3 },
.ArrayFormat = 0,
},
[MESA_FORMAT_A1R5G5B5_UINT] = {
.Name = MESA_FORMAT_A1R5G5B5_UINT,
.StrName = "MESA_FORMAT_A1R5G5B5_UINT",
.Layout = MESA_FORMAT_LAYOUT_PACKED,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_INT,
.RedBits = 5, .GreenBits = 5, .BlueBits = 5, .AlphaBits = 1,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 2,
.Swizzle = { 1, 2, 3, 0 },
.ArrayFormat = 0,
},
[MESA_FORMAT_R5G5B5A1_UINT] = {
.Name = MESA_FORMAT_R5G5B5A1_UINT,
.StrName = "MESA_FORMAT_R5G5B5A1_UINT",
.Layout = MESA_FORMAT_LAYOUT_PACKED,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_INT,
.RedBits = 5, .GreenBits = 5, .BlueBits = 5, .AlphaBits = 1,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 2,
.Swizzle = { 0, 1, 2, 3 },
.ArrayFormat = 0,
},
[MESA_FORMAT_A_UINT8] = {
.Name = MESA_FORMAT_A_UINT8,
.StrName = "MESA_FORMAT_A_UINT8",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_ALPHA,
.DataType = GL_UNSIGNED_INT,
.RedBits = 0, .GreenBits = 0, .BlueBits = 0, .AlphaBits = 8,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 1,
.Swizzle = { 4, 4, 4, 0 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 1, 0, 0, 0, 1, 4, 4, 4, 0),
},
[MESA_FORMAT_A_UINT16] = {
.Name = MESA_FORMAT_A_UINT16,
.StrName = "MESA_FORMAT_A_UINT16",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_ALPHA,
.DataType = GL_UNSIGNED_INT,
.RedBits = 0, .GreenBits = 0, .BlueBits = 0, .AlphaBits = 16,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 2,
.Swizzle = { 4, 4, 4, 0 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 2, 0, 0, 0, 1, 4, 4, 4, 0),
},
[MESA_FORMAT_A_UINT32] = {
.Name = MESA_FORMAT_A_UINT32,
.StrName = "MESA_FORMAT_A_UINT32",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_ALPHA,
.DataType = GL_UNSIGNED_INT,
.RedBits = 0, .GreenBits = 0, .BlueBits = 0, .AlphaBits = 32,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 4,
.Swizzle = { 4, 4, 4, 0 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 4, 0, 0, 0, 1, 4, 4, 4, 0),
},
[MESA_FORMAT_A_SINT8] = {
.Name = MESA_FORMAT_A_SINT8,
.StrName = "MESA_FORMAT_A_SINT8",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_ALPHA,
.DataType = GL_INT,
.RedBits = 0, .GreenBits = 0, .BlueBits = 0, .AlphaBits = 8,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 1,
.Swizzle = { 4, 4, 4, 0 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 1, 1, 0, 0, 1, 4, 4, 4, 0),
},
[MESA_FORMAT_A_SINT16] = {
.Name = MESA_FORMAT_A_SINT16,
.StrName = "MESA_FORMAT_A_SINT16",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_ALPHA,
.DataType = GL_INT,
.RedBits = 0, .GreenBits = 0, .BlueBits = 0, .AlphaBits = 16,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 2,
.Swizzle = { 4, 4, 4, 0 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 2, 1, 0, 0, 1, 4, 4, 4, 0),
},
[MESA_FORMAT_A_SINT32] = {
.Name = MESA_FORMAT_A_SINT32,
.StrName = "MESA_FORMAT_A_SINT32",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_ALPHA,
.DataType = GL_INT,
.RedBits = 0, .GreenBits = 0, .BlueBits = 0, .AlphaBits = 32,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 4,
.Swizzle = { 4, 4, 4, 0 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 4, 1, 0, 0, 1, 4, 4, 4, 0),
},
[MESA_FORMAT_I_UINT8] = {
.Name = MESA_FORMAT_I_UINT8,
.StrName = "MESA_FORMAT_I_UINT8",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_INTENSITY,
.DataType = GL_UNSIGNED_INT,
.RedBits = 0, .GreenBits = 0, .BlueBits = 0, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 8, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 1,
.Swizzle = { 0, 0, 0, 0 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 1, 0, 0, 0, 1, 0, 0, 0, 0),
},
[MESA_FORMAT_I_UINT16] = {
.Name = MESA_FORMAT_I_UINT16,
.StrName = "MESA_FORMAT_I_UINT16",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_INTENSITY,
.DataType = GL_UNSIGNED_INT,
.RedBits = 0, .GreenBits = 0, .BlueBits = 0, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 16, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 2,
.Swizzle = { 0, 0, 0, 0 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 2, 0, 0, 0, 1, 0, 0, 0, 0),
},
[MESA_FORMAT_I_UINT32] = {
.Name = MESA_FORMAT_I_UINT32,
.StrName = "MESA_FORMAT_I_UINT32",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_INTENSITY,
.DataType = GL_UNSIGNED_INT,
.RedBits = 0, .GreenBits = 0, .BlueBits = 0, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 32, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 4,
.Swizzle = { 0, 0, 0, 0 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 4, 0, 0, 0, 1, 0, 0, 0, 0),
},
[MESA_FORMAT_I_SINT8] = {
.Name = MESA_FORMAT_I_SINT8,
.StrName = "MESA_FORMAT_I_SINT8",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_INTENSITY,
.DataType = GL_INT,
.RedBits = 0, .GreenBits = 0, .BlueBits = 0, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 8, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 1,
.Swizzle = { 0, 0, 0, 0 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 1, 1, 0, 0, 1, 0, 0, 0, 0),
},
[MESA_FORMAT_I_SINT16] = {
.Name = MESA_FORMAT_I_SINT16,
.StrName = "MESA_FORMAT_I_SINT16",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_INTENSITY,
.DataType = GL_INT,
.RedBits = 0, .GreenBits = 0, .BlueBits = 0, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 16, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 2,
.Swizzle = { 0, 0, 0, 0 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 2, 1, 0, 0, 1, 0, 0, 0, 0),
},
[MESA_FORMAT_I_SINT32] = {
.Name = MESA_FORMAT_I_SINT32,
.StrName = "MESA_FORMAT_I_SINT32",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_INTENSITY,
.DataType = GL_INT,
.RedBits = 0, .GreenBits = 0, .BlueBits = 0, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 32, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 4,
.Swizzle = { 0, 0, 0, 0 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 4, 1, 0, 0, 1, 0, 0, 0, 0),
},
[MESA_FORMAT_L_UINT8] = {
.Name = MESA_FORMAT_L_UINT8,
.StrName = "MESA_FORMAT_L_UINT8",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_LUMINANCE,
.DataType = GL_UNSIGNED_INT,
.RedBits = 0, .GreenBits = 0, .BlueBits = 0, .AlphaBits = 0,
.LuminanceBits = 8, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 1,
.Swizzle = { 0, 0, 0, 5 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 1, 0, 0, 0, 1, 0, 0, 0, 5),
},
[MESA_FORMAT_L_UINT16] = {
.Name = MESA_FORMAT_L_UINT16,
.StrName = "MESA_FORMAT_L_UINT16",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_LUMINANCE,
.DataType = GL_UNSIGNED_INT,
.RedBits = 0, .GreenBits = 0, .BlueBits = 0, .AlphaBits = 0,
.LuminanceBits = 16, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 2,
.Swizzle = { 0, 0, 0, 5 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 2, 0, 0, 0, 1, 0, 0, 0, 5),
},
[MESA_FORMAT_L_UINT32] = {
.Name = MESA_FORMAT_L_UINT32,
.StrName = "MESA_FORMAT_L_UINT32",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_LUMINANCE,
.DataType = GL_UNSIGNED_INT,
.RedBits = 0, .GreenBits = 0, .BlueBits = 0, .AlphaBits = 0,
.LuminanceBits = 32, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 4,
.Swizzle = { 0, 0, 0, 5 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 4, 0, 0, 0, 1, 0, 0, 0, 5),
},
[MESA_FORMAT_L_SINT8] = {
.Name = MESA_FORMAT_L_SINT8,
.StrName = "MESA_FORMAT_L_SINT8",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_LUMINANCE,
.DataType = GL_INT,
.RedBits = 0, .GreenBits = 0, .BlueBits = 0, .AlphaBits = 0,
.LuminanceBits = 8, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 1,
.Swizzle = { 0, 0, 0, 5 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 1, 1, 0, 0, 1, 0, 0, 0, 5),
},
[MESA_FORMAT_L_SINT16] = {
.Name = MESA_FORMAT_L_SINT16,
.StrName = "MESA_FORMAT_L_SINT16",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_LUMINANCE,
.DataType = GL_INT,
.RedBits = 0, .GreenBits = 0, .BlueBits = 0, .AlphaBits = 0,
.LuminanceBits = 16, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 2,
.Swizzle = { 0, 0, 0, 5 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 2, 1, 0, 0, 1, 0, 0, 0, 5),
},
[MESA_FORMAT_L_SINT32] = {
.Name = MESA_FORMAT_L_SINT32,
.StrName = "MESA_FORMAT_L_SINT32",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_LUMINANCE,
.DataType = GL_INT,
.RedBits = 0, .GreenBits = 0, .BlueBits = 0, .AlphaBits = 0,
.LuminanceBits = 32, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 4,
.Swizzle = { 0, 0, 0, 5 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 4, 1, 0, 0, 1, 0, 0, 0, 5),
},
[MESA_FORMAT_LA_UINT8] = {
.Name = MESA_FORMAT_LA_UINT8,
.StrName = "MESA_FORMAT_LA_UINT8",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_LUMINANCE_ALPHA,
.DataType = GL_UNSIGNED_INT,
.RedBits = 0, .GreenBits = 0, .BlueBits = 0, .AlphaBits = 8,
.LuminanceBits = 8, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 2,
.Swizzle = { 0, 0, 0, 1 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 1, 0, 0, 0, 2, 0, 0, 0, 1),
},
[MESA_FORMAT_LA_UINT16] = {
.Name = MESA_FORMAT_LA_UINT16,
.StrName = "MESA_FORMAT_LA_UINT16",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_LUMINANCE_ALPHA,
.DataType = GL_UNSIGNED_INT,
.RedBits = 0, .GreenBits = 0, .BlueBits = 0, .AlphaBits = 16,
.LuminanceBits = 16, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 4,
.Swizzle = { 0, 0, 0, 1 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 2, 0, 0, 0, 2, 0, 0, 0, 1),
},
[MESA_FORMAT_LA_UINT32] = {
.Name = MESA_FORMAT_LA_UINT32,
.StrName = "MESA_FORMAT_LA_UINT32",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_LUMINANCE_ALPHA,
.DataType = GL_UNSIGNED_INT,
.RedBits = 0, .GreenBits = 0, .BlueBits = 0, .AlphaBits = 32,
.LuminanceBits = 32, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 8,
.Swizzle = { 0, 0, 0, 1 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 4, 0, 0, 0, 2, 0, 0, 0, 1),
},
[MESA_FORMAT_LA_SINT8] = {
.Name = MESA_FORMAT_LA_SINT8,
.StrName = "MESA_FORMAT_LA_SINT8",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_LUMINANCE_ALPHA,
.DataType = GL_INT,
.RedBits = 0, .GreenBits = 0, .BlueBits = 0, .AlphaBits = 8,
.LuminanceBits = 8, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 2,
.Swizzle = { 0, 0, 0, 1 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 1, 1, 0, 0, 2, 0, 0, 0, 1),
},
[MESA_FORMAT_LA_SINT16] = {
.Name = MESA_FORMAT_LA_SINT16,
.StrName = "MESA_FORMAT_LA_SINT16",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_LUMINANCE_ALPHA,
.DataType = GL_INT,
.RedBits = 0, .GreenBits = 0, .BlueBits = 0, .AlphaBits = 16,
.LuminanceBits = 16, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 4,
.Swizzle = { 0, 0, 0, 1 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 2, 1, 0, 0, 2, 0, 0, 0, 1),
},
[MESA_FORMAT_LA_SINT32] = {
.Name = MESA_FORMAT_LA_SINT32,
.StrName = "MESA_FORMAT_LA_SINT32",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_LUMINANCE_ALPHA,
.DataType = GL_INT,
.RedBits = 0, .GreenBits = 0, .BlueBits = 0, .AlphaBits = 32,
.LuminanceBits = 32, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 8,
.Swizzle = { 0, 0, 0, 1 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 4, 1, 0, 0, 2, 0, 0, 0, 1),
},
[MESA_FORMAT_R_UINT8] = {
.Name = MESA_FORMAT_R_UINT8,
.StrName = "MESA_FORMAT_R_UINT8",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_RED,
.DataType = GL_UNSIGNED_INT,
.RedBits = 8, .GreenBits = 0, .BlueBits = 0, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 1,
.Swizzle = { 0, 4, 4, 5 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 1, 0, 0, 0, 1, 0, 4, 4, 5),
},
[MESA_FORMAT_R_UINT16] = {
.Name = MESA_FORMAT_R_UINT16,
.StrName = "MESA_FORMAT_R_UINT16",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_RED,
.DataType = GL_UNSIGNED_INT,
.RedBits = 16, .GreenBits = 0, .BlueBits = 0, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 2,
.Swizzle = { 0, 4, 4, 5 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 2, 0, 0, 0, 1, 0, 4, 4, 5),
},
[MESA_FORMAT_R_UINT32] = {
.Name = MESA_FORMAT_R_UINT32,
.StrName = "MESA_FORMAT_R_UINT32",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_RED,
.DataType = GL_UNSIGNED_INT,
.RedBits = 32, .GreenBits = 0, .BlueBits = 0, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 4,
.Swizzle = { 0, 4, 4, 5 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 4, 0, 0, 0, 1, 0, 4, 4, 5),
},
[MESA_FORMAT_R_SINT8] = {
.Name = MESA_FORMAT_R_SINT8,
.StrName = "MESA_FORMAT_R_SINT8",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_RED,
.DataType = GL_INT,
.RedBits = 8, .GreenBits = 0, .BlueBits = 0, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 1,
.Swizzle = { 0, 4, 4, 5 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 1, 1, 0, 0, 1, 0, 4, 4, 5),
},
[MESA_FORMAT_R_SINT16] = {
.Name = MESA_FORMAT_R_SINT16,
.StrName = "MESA_FORMAT_R_SINT16",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_RED,
.DataType = GL_INT,
.RedBits = 16, .GreenBits = 0, .BlueBits = 0, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 2,
.Swizzle = { 0, 4, 4, 5 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 2, 1, 0, 0, 1, 0, 4, 4, 5),
},
[MESA_FORMAT_R_SINT32] = {
.Name = MESA_FORMAT_R_SINT32,
.StrName = "MESA_FORMAT_R_SINT32",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_RED,
.DataType = GL_INT,
.RedBits = 32, .GreenBits = 0, .BlueBits = 0, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 4,
.Swizzle = { 0, 4, 4, 5 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 4, 1, 0, 0, 1, 0, 4, 4, 5),
},
[MESA_FORMAT_RG_UINT8] = {
.Name = MESA_FORMAT_RG_UINT8,
.StrName = "MESA_FORMAT_RG_UINT8",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_RG,
.DataType = GL_UNSIGNED_INT,
.RedBits = 8, .GreenBits = 8, .BlueBits = 0, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 2,
.Swizzle = { 0, 1, 4, 5 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 1, 0, 0, 0, 2, 0, 1, 4, 5),
},
[MESA_FORMAT_RG_UINT16] = {
.Name = MESA_FORMAT_RG_UINT16,
.StrName = "MESA_FORMAT_RG_UINT16",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_RG,
.DataType = GL_UNSIGNED_INT,
.RedBits = 16, .GreenBits = 16, .BlueBits = 0, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 4,
.Swizzle = { 0, 1, 4, 5 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 2, 0, 0, 0, 2, 0, 1, 4, 5),
},
[MESA_FORMAT_RG_UINT32] = {
.Name = MESA_FORMAT_RG_UINT32,
.StrName = "MESA_FORMAT_RG_UINT32",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_RG,
.DataType = GL_UNSIGNED_INT,
.RedBits = 32, .GreenBits = 32, .BlueBits = 0, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 8,
.Swizzle = { 0, 1, 4, 5 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 4, 0, 0, 0, 2, 0, 1, 4, 5),
},
[MESA_FORMAT_RG_SINT8] = {
.Name = MESA_FORMAT_RG_SINT8,
.StrName = "MESA_FORMAT_RG_SINT8",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_RG,
.DataType = GL_INT,
.RedBits = 8, .GreenBits = 8, .BlueBits = 0, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 2,
.Swizzle = { 0, 1, 4, 5 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 1, 1, 0, 0, 2, 0, 1, 4, 5),
},
[MESA_FORMAT_RG_SINT16] = {
.Name = MESA_FORMAT_RG_SINT16,
.StrName = "MESA_FORMAT_RG_SINT16",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_RG,
.DataType = GL_INT,
.RedBits = 16, .GreenBits = 16, .BlueBits = 0, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 4,
.Swizzle = { 0, 1, 4, 5 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 2, 1, 0, 0, 2, 0, 1, 4, 5),
},
[MESA_FORMAT_RG_SINT32] = {
.Name = MESA_FORMAT_RG_SINT32,
.StrName = "MESA_FORMAT_RG_SINT32",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_RG,
.DataType = GL_INT,
.RedBits = 32, .GreenBits = 32, .BlueBits = 0, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 8,
.Swizzle = { 0, 1, 4, 5 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 4, 1, 0, 0, 2, 0, 1, 4, 5),
},
[MESA_FORMAT_RGB_UINT8] = {
.Name = MESA_FORMAT_RGB_UINT8,
.StrName = "MESA_FORMAT_RGB_UINT8",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_RGB,
.DataType = GL_UNSIGNED_INT,
.RedBits = 8, .GreenBits = 8, .BlueBits = 8, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 3,
.Swizzle = { 0, 1, 2, 5 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 1, 0, 0, 0, 3, 0, 1, 2, 5),
},
[MESA_FORMAT_RGB_UINT16] = {
.Name = MESA_FORMAT_RGB_UINT16,
.StrName = "MESA_FORMAT_RGB_UINT16",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_RGB,
.DataType = GL_UNSIGNED_INT,
.RedBits = 16, .GreenBits = 16, .BlueBits = 16, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 6,
.Swizzle = { 0, 1, 2, 5 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 2, 0, 0, 0, 3, 0, 1, 2, 5),
},
[MESA_FORMAT_RGB_UINT32] = {
.Name = MESA_FORMAT_RGB_UINT32,
.StrName = "MESA_FORMAT_RGB_UINT32",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_RGB,
.DataType = GL_UNSIGNED_INT,
.RedBits = 32, .GreenBits = 32, .BlueBits = 32, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 12,
.Swizzle = { 0, 1, 2, 5 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 4, 0, 0, 0, 3, 0, 1, 2, 5),
},
[MESA_FORMAT_RGB_SINT8] = {
.Name = MESA_FORMAT_RGB_SINT8,
.StrName = "MESA_FORMAT_RGB_SINT8",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_RGB,
.DataType = GL_INT,
.RedBits = 8, .GreenBits = 8, .BlueBits = 8, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 3,
.Swizzle = { 0, 1, 2, 5 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 1, 1, 0, 0, 3, 0, 1, 2, 5),
},
[MESA_FORMAT_RGB_SINT16] = {
.Name = MESA_FORMAT_RGB_SINT16,
.StrName = "MESA_FORMAT_RGB_SINT16",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_RGB,
.DataType = GL_INT,
.RedBits = 16, .GreenBits = 16, .BlueBits = 16, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 6,
.Swizzle = { 0, 1, 2, 5 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 2, 1, 0, 0, 3, 0, 1, 2, 5),
},
[MESA_FORMAT_RGB_SINT32] = {
.Name = MESA_FORMAT_RGB_SINT32,
.StrName = "MESA_FORMAT_RGB_SINT32",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_RGB,
.DataType = GL_INT,
.RedBits = 32, .GreenBits = 32, .BlueBits = 32, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 12,
.Swizzle = { 0, 1, 2, 5 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 4, 1, 0, 0, 3, 0, 1, 2, 5),
},
[MESA_FORMAT_RGBA_UINT16] = {
.Name = MESA_FORMAT_RGBA_UINT16,
.StrName = "MESA_FORMAT_RGBA_UINT16",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_INT,
.RedBits = 16, .GreenBits = 16, .BlueBits = 16, .AlphaBits = 16,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 8,
.Swizzle = { 0, 1, 2, 3 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 2, 0, 0, 0, 4, 0, 1, 2, 3),
},
[MESA_FORMAT_RGBA_UINT32] = {
.Name = MESA_FORMAT_RGBA_UINT32,
.StrName = "MESA_FORMAT_RGBA_UINT32",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_INT,
.RedBits = 32, .GreenBits = 32, .BlueBits = 32, .AlphaBits = 32,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 16,
.Swizzle = { 0, 1, 2, 3 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 4, 0, 0, 0, 4, 0, 1, 2, 3),
},
[MESA_FORMAT_RGBA_SINT8] = {
.Name = MESA_FORMAT_RGBA_SINT8,
.StrName = "MESA_FORMAT_RGBA_SINT8",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_RGBA,
.DataType = GL_INT,
.RedBits = 8, .GreenBits = 8, .BlueBits = 8, .AlphaBits = 8,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 4,
.Swizzle = { 0, 1, 2, 3 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 1, 1, 0, 0, 4, 0, 1, 2, 3),
},
[MESA_FORMAT_RGBA_SINT16] = {
.Name = MESA_FORMAT_RGBA_SINT16,
.StrName = "MESA_FORMAT_RGBA_SINT16",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_RGBA,
.DataType = GL_INT,
.RedBits = 16, .GreenBits = 16, .BlueBits = 16, .AlphaBits = 16,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 8,
.Swizzle = { 0, 1, 2, 3 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 2, 1, 0, 0, 4, 0, 1, 2, 3),
},
[MESA_FORMAT_RGBA_SINT32] = {
.Name = MESA_FORMAT_RGBA_SINT32,
.StrName = "MESA_FORMAT_RGBA_SINT32",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_RGBA,
.DataType = GL_INT,
.RedBits = 32, .GreenBits = 32, .BlueBits = 32, .AlphaBits = 32,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 16,
.Swizzle = { 0, 1, 2, 3 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 4, 1, 0, 0, 4, 0, 1, 2, 3),
},
[MESA_FORMAT_RGBX_UINT8] = {
.Name = MESA_FORMAT_RGBX_UINT8,
.StrName = "MESA_FORMAT_RGBX_UINT8",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_RGB,
.DataType = GL_UNSIGNED_INT,
.RedBits = 8, .GreenBits = 8, .BlueBits = 8, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 4,
.Swizzle = { 0, 1, 2, 5 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 1, 0, 0, 0, 4, 0, 1, 2, 5),
},
[MESA_FORMAT_RGBX_UINT16] = {
.Name = MESA_FORMAT_RGBX_UINT16,
.StrName = "MESA_FORMAT_RGBX_UINT16",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_RGB,
.DataType = GL_UNSIGNED_INT,
.RedBits = 16, .GreenBits = 16, .BlueBits = 16, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 8,
.Swizzle = { 0, 1, 2, 5 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 2, 0, 0, 0, 4, 0, 1, 2, 5),
},
[MESA_FORMAT_RGBX_UINT32] = {
.Name = MESA_FORMAT_RGBX_UINT32,
.StrName = "MESA_FORMAT_RGBX_UINT32",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_RGB,
.DataType = GL_UNSIGNED_INT,
.RedBits = 32, .GreenBits = 32, .BlueBits = 32, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 16,
.Swizzle = { 0, 1, 2, 5 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 4, 0, 0, 0, 4, 0, 1, 2, 5),
},
[MESA_FORMAT_RGBX_SINT8] = {
.Name = MESA_FORMAT_RGBX_SINT8,
.StrName = "MESA_FORMAT_RGBX_SINT8",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_RGB,
.DataType = GL_INT,
.RedBits = 8, .GreenBits = 8, .BlueBits = 8, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 4,
.Swizzle = { 0, 1, 2, 5 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 1, 1, 0, 0, 4, 0, 1, 2, 5),
},
[MESA_FORMAT_RGBX_SINT16] = {
.Name = MESA_FORMAT_RGBX_SINT16,
.StrName = "MESA_FORMAT_RGBX_SINT16",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_RGB,
.DataType = GL_INT,
.RedBits = 16, .GreenBits = 16, .BlueBits = 16, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 8,
.Swizzle = { 0, 1, 2, 5 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 2, 1, 0, 0, 4, 0, 1, 2, 5),
},
[MESA_FORMAT_RGBX_SINT32] = {
.Name = MESA_FORMAT_RGBX_SINT32,
.StrName = "MESA_FORMAT_RGBX_SINT32",
.Layout = MESA_FORMAT_LAYOUT_ARRAY,
.BaseFormat = GL_RGB,
.DataType = GL_INT,
.RedBits = 32, .GreenBits = 32, .BlueBits = 32, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 1, .BlockHeight = 1, .BlockDepth = 1,
.BytesPerBlock = 16,
.Swizzle = { 0, 1, 2, 5 },
.ArrayFormat = MESA_ARRAY_FORMAT(MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS, 4, 1, 0, 0, 4, 0, 1, 2, 5),
},
[MESA_FORMAT_RGB_DXT1] = {
.Name = MESA_FORMAT_RGB_DXT1,
.StrName = "MESA_FORMAT_RGB_DXT1",
.Layout = MESA_FORMAT_LAYOUT_S3TC,
.BaseFormat = GL_RGB,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 4, .GreenBits = 4, .BlueBits = 4, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 4, .BlockHeight = 4, .BlockDepth = 1,
.BytesPerBlock = 8,
.Swizzle = { 0, 1, 2, 5 },
.ArrayFormat = 0,
},
[MESA_FORMAT_RGBA_DXT1] = {
.Name = MESA_FORMAT_RGBA_DXT1,
.StrName = "MESA_FORMAT_RGBA_DXT1",
.Layout = MESA_FORMAT_LAYOUT_S3TC,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 4, .GreenBits = 4, .BlueBits = 4, .AlphaBits = 4,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 4, .BlockHeight = 4, .BlockDepth = 1,
.BytesPerBlock = 8,
.Swizzle = { 0, 1, 2, 3 },
.ArrayFormat = 0,
},
[MESA_FORMAT_RGBA_DXT3] = {
.Name = MESA_FORMAT_RGBA_DXT3,
.StrName = "MESA_FORMAT_RGBA_DXT3",
.Layout = MESA_FORMAT_LAYOUT_S3TC,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 4, .GreenBits = 4, .BlueBits = 4, .AlphaBits = 4,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 4, .BlockHeight = 4, .BlockDepth = 1,
.BytesPerBlock = 16,
.Swizzle = { 0, 1, 2, 3 },
.ArrayFormat = 0,
},
[MESA_FORMAT_RGBA_DXT5] = {
.Name = MESA_FORMAT_RGBA_DXT5,
.StrName = "MESA_FORMAT_RGBA_DXT5",
.Layout = MESA_FORMAT_LAYOUT_S3TC,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 4, .GreenBits = 4, .BlueBits = 4, .AlphaBits = 4,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 4, .BlockHeight = 4, .BlockDepth = 1,
.BytesPerBlock = 16,
.Swizzle = { 0, 1, 2, 3 },
.ArrayFormat = 0,
},
[MESA_FORMAT_SRGB_DXT1] = {
.Name = MESA_FORMAT_SRGB_DXT1,
.StrName = "MESA_FORMAT_SRGB_DXT1",
.Layout = MESA_FORMAT_LAYOUT_S3TC,
.BaseFormat = GL_RGB,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 4, .GreenBits = 4, .BlueBits = 4, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 1,
.BlockWidth = 4, .BlockHeight = 4, .BlockDepth = 1,
.BytesPerBlock = 8,
.Swizzle = { 0, 1, 2, 5 },
.ArrayFormat = 0,
},
[MESA_FORMAT_SRGBA_DXT1] = {
.Name = MESA_FORMAT_SRGBA_DXT1,
.StrName = "MESA_FORMAT_SRGBA_DXT1",
.Layout = MESA_FORMAT_LAYOUT_S3TC,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 4, .GreenBits = 4, .BlueBits = 4, .AlphaBits = 4,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 1,
.BlockWidth = 4, .BlockHeight = 4, .BlockDepth = 1,
.BytesPerBlock = 8,
.Swizzle = { 0, 1, 2, 3 },
.ArrayFormat = 0,
},
[MESA_FORMAT_SRGBA_DXT3] = {
.Name = MESA_FORMAT_SRGBA_DXT3,
.StrName = "MESA_FORMAT_SRGBA_DXT3",
.Layout = MESA_FORMAT_LAYOUT_S3TC,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 4, .GreenBits = 4, .BlueBits = 4, .AlphaBits = 4,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 1,
.BlockWidth = 4, .BlockHeight = 4, .BlockDepth = 1,
.BytesPerBlock = 16,
.Swizzle = { 0, 1, 2, 3 },
.ArrayFormat = 0,
},
[MESA_FORMAT_SRGBA_DXT5] = {
.Name = MESA_FORMAT_SRGBA_DXT5,
.StrName = "MESA_FORMAT_SRGBA_DXT5",
.Layout = MESA_FORMAT_LAYOUT_S3TC,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 4, .GreenBits = 4, .BlueBits = 4, .AlphaBits = 4,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 1,
.BlockWidth = 4, .BlockHeight = 4, .BlockDepth = 1,
.BytesPerBlock = 16,
.Swizzle = { 0, 1, 2, 3 },
.ArrayFormat = 0,
},
[MESA_FORMAT_RGB_FXT1] = {
.Name = MESA_FORMAT_RGB_FXT1,
.StrName = "MESA_FORMAT_RGB_FXT1",
.Layout = MESA_FORMAT_LAYOUT_FXT1,
.BaseFormat = GL_RGB,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 4, .GreenBits = 4, .BlueBits = 4, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 8, .BlockHeight = 4, .BlockDepth = 1,
.BytesPerBlock = 16,
.Swizzle = { 0, 1, 2, 5 },
.ArrayFormat = 0,
},
[MESA_FORMAT_RGBA_FXT1] = {
.Name = MESA_FORMAT_RGBA_FXT1,
.StrName = "MESA_FORMAT_RGBA_FXT1",
.Layout = MESA_FORMAT_LAYOUT_FXT1,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 4, .GreenBits = 4, .BlueBits = 4, .AlphaBits = 1,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 8, .BlockHeight = 4, .BlockDepth = 1,
.BytesPerBlock = 16,
.Swizzle = { 0, 1, 2, 3 },
.ArrayFormat = 0,
},
[MESA_FORMAT_R_RGTC1_UNORM] = {
.Name = MESA_FORMAT_R_RGTC1_UNORM,
.StrName = "MESA_FORMAT_R_RGTC1_UNORM",
.Layout = MESA_FORMAT_LAYOUT_RGTC,
.BaseFormat = GL_RED,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 8, .GreenBits = 0, .BlueBits = 0, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 4, .BlockHeight = 4, .BlockDepth = 1,
.BytesPerBlock = 8,
.Swizzle = { 0, 4, 4, 5 },
.ArrayFormat = 0,
},
[MESA_FORMAT_R_RGTC1_SNORM] = {
.Name = MESA_FORMAT_R_RGTC1_SNORM,
.StrName = "MESA_FORMAT_R_RGTC1_SNORM",
.Layout = MESA_FORMAT_LAYOUT_RGTC,
.BaseFormat = GL_RED,
.DataType = GL_SIGNED_NORMALIZED,
.RedBits = 8, .GreenBits = 0, .BlueBits = 0, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 4, .BlockHeight = 4, .BlockDepth = 1,
.BytesPerBlock = 8,
.Swizzle = { 0, 4, 4, 5 },
.ArrayFormat = 0,
},
[MESA_FORMAT_RG_RGTC2_UNORM] = {
.Name = MESA_FORMAT_RG_RGTC2_UNORM,
.StrName = "MESA_FORMAT_RG_RGTC2_UNORM",
.Layout = MESA_FORMAT_LAYOUT_RGTC,
.BaseFormat = GL_RG,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 8, .GreenBits = 8, .BlueBits = 0, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 4, .BlockHeight = 4, .BlockDepth = 1,
.BytesPerBlock = 16,
.Swizzle = { 0, 1, 4, 5 },
.ArrayFormat = 0,
},
[MESA_FORMAT_RG_RGTC2_SNORM] = {
.Name = MESA_FORMAT_RG_RGTC2_SNORM,
.StrName = "MESA_FORMAT_RG_RGTC2_SNORM",
.Layout = MESA_FORMAT_LAYOUT_RGTC,
.BaseFormat = GL_RG,
.DataType = GL_SIGNED_NORMALIZED,
.RedBits = 8, .GreenBits = 8, .BlueBits = 0, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 4, .BlockHeight = 4, .BlockDepth = 1,
.BytesPerBlock = 16,
.Swizzle = { 0, 1, 4, 5 },
.ArrayFormat = 0,
},
[MESA_FORMAT_L_LATC1_UNORM] = {
.Name = MESA_FORMAT_L_LATC1_UNORM,
.StrName = "MESA_FORMAT_L_LATC1_UNORM",
.Layout = MESA_FORMAT_LAYOUT_LATC,
.BaseFormat = GL_LUMINANCE,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 0, .GreenBits = 0, .BlueBits = 0, .AlphaBits = 0,
.LuminanceBits = 8, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 4, .BlockHeight = 4, .BlockDepth = 1,
.BytesPerBlock = 8,
.Swizzle = { 0, 0, 0, 5 },
.ArrayFormat = 0,
},
[MESA_FORMAT_L_LATC1_SNORM] = {
.Name = MESA_FORMAT_L_LATC1_SNORM,
.StrName = "MESA_FORMAT_L_LATC1_SNORM",
.Layout = MESA_FORMAT_LAYOUT_LATC,
.BaseFormat = GL_LUMINANCE,
.DataType = GL_SIGNED_NORMALIZED,
.RedBits = 0, .GreenBits = 0, .BlueBits = 0, .AlphaBits = 0,
.LuminanceBits = 8, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 4, .BlockHeight = 4, .BlockDepth = 1,
.BytesPerBlock = 8,
.Swizzle = { 0, 0, 0, 5 },
.ArrayFormat = 0,
},
[MESA_FORMAT_LA_LATC2_UNORM] = {
.Name = MESA_FORMAT_LA_LATC2_UNORM,
.StrName = "MESA_FORMAT_LA_LATC2_UNORM",
.Layout = MESA_FORMAT_LAYOUT_LATC,
.BaseFormat = GL_LUMINANCE_ALPHA,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 0, .GreenBits = 0, .BlueBits = 0, .AlphaBits = 8,
.LuminanceBits = 8, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 4, .BlockHeight = 4, .BlockDepth = 1,
.BytesPerBlock = 16,
.Swizzle = { 0, 0, 0, 1 },
.ArrayFormat = 0,
},
[MESA_FORMAT_LA_LATC2_SNORM] = {
.Name = MESA_FORMAT_LA_LATC2_SNORM,
.StrName = "MESA_FORMAT_LA_LATC2_SNORM",
.Layout = MESA_FORMAT_LAYOUT_LATC,
.BaseFormat = GL_LUMINANCE_ALPHA,
.DataType = GL_SIGNED_NORMALIZED,
.RedBits = 0, .GreenBits = 0, .BlueBits = 0, .AlphaBits = 8,
.LuminanceBits = 8, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 4, .BlockHeight = 4, .BlockDepth = 1,
.BytesPerBlock = 16,
.Swizzle = { 0, 0, 0, 1 },
.ArrayFormat = 0,
},
[MESA_FORMAT_ETC1_RGB8] = {
.Name = MESA_FORMAT_ETC1_RGB8,
.StrName = "MESA_FORMAT_ETC1_RGB8",
.Layout = MESA_FORMAT_LAYOUT_ETC1,
.BaseFormat = GL_RGB,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 8, .GreenBits = 8, .BlueBits = 8, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 4, .BlockHeight = 4, .BlockDepth = 1,
.BytesPerBlock = 8,
.Swizzle = { 0, 1, 2, 5 },
.ArrayFormat = 0,
},
[MESA_FORMAT_ETC2_RGB8] = {
.Name = MESA_FORMAT_ETC2_RGB8,
.StrName = "MESA_FORMAT_ETC2_RGB8",
.Layout = MESA_FORMAT_LAYOUT_ETC2,
.BaseFormat = GL_RGB,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 8, .GreenBits = 8, .BlueBits = 8, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 4, .BlockHeight = 4, .BlockDepth = 1,
.BytesPerBlock = 8,
.Swizzle = { 0, 1, 2, 5 },
.ArrayFormat = 0,
},
[MESA_FORMAT_ETC2_SRGB8] = {
.Name = MESA_FORMAT_ETC2_SRGB8,
.StrName = "MESA_FORMAT_ETC2_SRGB8",
.Layout = MESA_FORMAT_LAYOUT_ETC2,
.BaseFormat = GL_RGB,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 8, .GreenBits = 8, .BlueBits = 8, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 1,
.BlockWidth = 4, .BlockHeight = 4, .BlockDepth = 1,
.BytesPerBlock = 8,
.Swizzle = { 0, 1, 2, 5 },
.ArrayFormat = 0,
},
[MESA_FORMAT_ETC2_RGBA8_EAC] = {
.Name = MESA_FORMAT_ETC2_RGBA8_EAC,
.StrName = "MESA_FORMAT_ETC2_RGBA8_EAC",
.Layout = MESA_FORMAT_LAYOUT_ETC2,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 8, .GreenBits = 8, .BlueBits = 8, .AlphaBits = 8,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 4, .BlockHeight = 4, .BlockDepth = 1,
.BytesPerBlock = 16,
.Swizzle = { 0, 1, 2, 3 },
.ArrayFormat = 0,
},
[MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC] = {
.Name = MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC,
.StrName = "MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC",
.Layout = MESA_FORMAT_LAYOUT_ETC2,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 8, .GreenBits = 8, .BlueBits = 8, .AlphaBits = 8,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 1,
.BlockWidth = 4, .BlockHeight = 4, .BlockDepth = 1,
.BytesPerBlock = 16,
.Swizzle = { 0, 1, 2, 3 },
.ArrayFormat = 0,
},
[MESA_FORMAT_ETC2_R11_EAC] = {
.Name = MESA_FORMAT_ETC2_R11_EAC,
.StrName = "MESA_FORMAT_ETC2_R11_EAC",
.Layout = MESA_FORMAT_LAYOUT_ETC2,
.BaseFormat = GL_RED,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 11, .GreenBits = 0, .BlueBits = 0, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 4, .BlockHeight = 4, .BlockDepth = 1,
.BytesPerBlock = 8,
.Swizzle = { 0, 4, 4, 5 },
.ArrayFormat = 0,
},
[MESA_FORMAT_ETC2_RG11_EAC] = {
.Name = MESA_FORMAT_ETC2_RG11_EAC,
.StrName = "MESA_FORMAT_ETC2_RG11_EAC",
.Layout = MESA_FORMAT_LAYOUT_ETC2,
.BaseFormat = GL_RG,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 11, .GreenBits = 11, .BlueBits = 0, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 4, .BlockHeight = 4, .BlockDepth = 1,
.BytesPerBlock = 16,
.Swizzle = { 0, 1, 4, 5 },
.ArrayFormat = 0,
},
[MESA_FORMAT_ETC2_SIGNED_R11_EAC] = {
.Name = MESA_FORMAT_ETC2_SIGNED_R11_EAC,
.StrName = "MESA_FORMAT_ETC2_SIGNED_R11_EAC",
.Layout = MESA_FORMAT_LAYOUT_ETC2,
.BaseFormat = GL_RED,
.DataType = GL_SIGNED_NORMALIZED,
.RedBits = 11, .GreenBits = 0, .BlueBits = 0, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 4, .BlockHeight = 4, .BlockDepth = 1,
.BytesPerBlock = 8,
.Swizzle = { 0, 4, 4, 5 },
.ArrayFormat = 0,
},
[MESA_FORMAT_ETC2_SIGNED_RG11_EAC] = {
.Name = MESA_FORMAT_ETC2_SIGNED_RG11_EAC,
.StrName = "MESA_FORMAT_ETC2_SIGNED_RG11_EAC",
.Layout = MESA_FORMAT_LAYOUT_ETC2,
.BaseFormat = GL_RG,
.DataType = GL_SIGNED_NORMALIZED,
.RedBits = 11, .GreenBits = 11, .BlueBits = 0, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 4, .BlockHeight = 4, .BlockDepth = 1,
.BytesPerBlock = 16,
.Swizzle = { 0, 1, 4, 5 },
.ArrayFormat = 0,
},
[MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1] = {
.Name = MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1,
.StrName = "MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1",
.Layout = MESA_FORMAT_LAYOUT_ETC2,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 8, .GreenBits = 8, .BlueBits = 8, .AlphaBits = 1,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 4, .BlockHeight = 4, .BlockDepth = 1,
.BytesPerBlock = 8,
.Swizzle = { 0, 1, 2, 3 },
.ArrayFormat = 0,
},
[MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1] = {
.Name = MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1,
.StrName = "MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1",
.Layout = MESA_FORMAT_LAYOUT_ETC2,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 8, .GreenBits = 8, .BlueBits = 8, .AlphaBits = 1,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 1,
.BlockWidth = 4, .BlockHeight = 4, .BlockDepth = 1,
.BytesPerBlock = 8,
.Swizzle = { 0, 1, 2, 3 },
.ArrayFormat = 0,
},
[MESA_FORMAT_BPTC_RGBA_UNORM] = {
.Name = MESA_FORMAT_BPTC_RGBA_UNORM,
.StrName = "MESA_FORMAT_BPTC_RGBA_UNORM",
.Layout = MESA_FORMAT_LAYOUT_BPTC,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 8, .GreenBits = 8, .BlueBits = 8, .AlphaBits = 8,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 4, .BlockHeight = 4, .BlockDepth = 1,
.BytesPerBlock = 16,
.Swizzle = { 0, 1, 2, 3 },
.ArrayFormat = 0,
},
[MESA_FORMAT_BPTC_SRGB_ALPHA_UNORM] = {
.Name = MESA_FORMAT_BPTC_SRGB_ALPHA_UNORM,
.StrName = "MESA_FORMAT_BPTC_SRGB_ALPHA_UNORM",
.Layout = MESA_FORMAT_LAYOUT_BPTC,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 8, .GreenBits = 8, .BlueBits = 8, .AlphaBits = 8,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 1,
.BlockWidth = 4, .BlockHeight = 4, .BlockDepth = 1,
.BytesPerBlock = 16,
.Swizzle = { 0, 1, 2, 3 },
.ArrayFormat = 0,
},
[MESA_FORMAT_BPTC_RGB_SIGNED_FLOAT] = {
.Name = MESA_FORMAT_BPTC_RGB_SIGNED_FLOAT,
.StrName = "MESA_FORMAT_BPTC_RGB_SIGNED_FLOAT",
.Layout = MESA_FORMAT_LAYOUT_BPTC,
.BaseFormat = GL_RGB,
.DataType = GL_FLOAT,
.RedBits = 16, .GreenBits = 16, .BlueBits = 16, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 4, .BlockHeight = 4, .BlockDepth = 1,
.BytesPerBlock = 16,
.Swizzle = { 0, 1, 2, 5 },
.ArrayFormat = 0,
},
[MESA_FORMAT_BPTC_RGB_UNSIGNED_FLOAT] = {
.Name = MESA_FORMAT_BPTC_RGB_UNSIGNED_FLOAT,
.StrName = "MESA_FORMAT_BPTC_RGB_UNSIGNED_FLOAT",
.Layout = MESA_FORMAT_LAYOUT_BPTC,
.BaseFormat = GL_RGB,
.DataType = GL_FLOAT,
.RedBits = 16, .GreenBits = 16, .BlueBits = 16, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 4, .BlockHeight = 4, .BlockDepth = 1,
.BytesPerBlock = 16,
.Swizzle = { 0, 1, 2, 5 },
.ArrayFormat = 0,
},
[MESA_FORMAT_RGBA_ASTC_4x4] = {
.Name = MESA_FORMAT_RGBA_ASTC_4x4,
.StrName = "MESA_FORMAT_RGBA_ASTC_4x4",
.Layout = MESA_FORMAT_LAYOUT_ASTC,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 16, .GreenBits = 16, .BlueBits = 16, .AlphaBits = 16,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 4, .BlockHeight = 4, .BlockDepth = 1,
.BytesPerBlock = 16,
.Swizzle = { 0, 1, 2, 3 },
.ArrayFormat = 0,
},
[MESA_FORMAT_RGBA_ASTC_5x4] = {
.Name = MESA_FORMAT_RGBA_ASTC_5x4,
.StrName = "MESA_FORMAT_RGBA_ASTC_5x4",
.Layout = MESA_FORMAT_LAYOUT_ASTC,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 16, .GreenBits = 16, .BlueBits = 16, .AlphaBits = 16,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 5, .BlockHeight = 4, .BlockDepth = 1,
.BytesPerBlock = 16,
.Swizzle = { 0, 1, 2, 3 },
.ArrayFormat = 0,
},
[MESA_FORMAT_RGBA_ASTC_5x5] = {
.Name = MESA_FORMAT_RGBA_ASTC_5x5,
.StrName = "MESA_FORMAT_RGBA_ASTC_5x5",
.Layout = MESA_FORMAT_LAYOUT_ASTC,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 16, .GreenBits = 16, .BlueBits = 16, .AlphaBits = 16,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 5, .BlockHeight = 5, .BlockDepth = 1,
.BytesPerBlock = 16,
.Swizzle = { 0, 1, 2, 3 },
.ArrayFormat = 0,
},
[MESA_FORMAT_RGBA_ASTC_6x5] = {
.Name = MESA_FORMAT_RGBA_ASTC_6x5,
.StrName = "MESA_FORMAT_RGBA_ASTC_6x5",
.Layout = MESA_FORMAT_LAYOUT_ASTC,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 16, .GreenBits = 16, .BlueBits = 16, .AlphaBits = 16,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 6, .BlockHeight = 5, .BlockDepth = 1,
.BytesPerBlock = 16,
.Swizzle = { 0, 1, 2, 3 },
.ArrayFormat = 0,
},
[MESA_FORMAT_RGBA_ASTC_6x6] = {
.Name = MESA_FORMAT_RGBA_ASTC_6x6,
.StrName = "MESA_FORMAT_RGBA_ASTC_6x6",
.Layout = MESA_FORMAT_LAYOUT_ASTC,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 16, .GreenBits = 16, .BlueBits = 16, .AlphaBits = 16,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 6, .BlockHeight = 6, .BlockDepth = 1,
.BytesPerBlock = 16,
.Swizzle = { 0, 1, 2, 3 },
.ArrayFormat = 0,
},
[MESA_FORMAT_RGBA_ASTC_8x5] = {
.Name = MESA_FORMAT_RGBA_ASTC_8x5,
.StrName = "MESA_FORMAT_RGBA_ASTC_8x5",
.Layout = MESA_FORMAT_LAYOUT_ASTC,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 16, .GreenBits = 16, .BlueBits = 16, .AlphaBits = 16,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 8, .BlockHeight = 5, .BlockDepth = 1,
.BytesPerBlock = 16,
.Swizzle = { 0, 1, 2, 3 },
.ArrayFormat = 0,
},
[MESA_FORMAT_RGBA_ASTC_8x6] = {
.Name = MESA_FORMAT_RGBA_ASTC_8x6,
.StrName = "MESA_FORMAT_RGBA_ASTC_8x6",
.Layout = MESA_FORMAT_LAYOUT_ASTC,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 16, .GreenBits = 16, .BlueBits = 16, .AlphaBits = 16,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 8, .BlockHeight = 6, .BlockDepth = 1,
.BytesPerBlock = 16,
.Swizzle = { 0, 1, 2, 3 },
.ArrayFormat = 0,
},
[MESA_FORMAT_RGBA_ASTC_8x8] = {
.Name = MESA_FORMAT_RGBA_ASTC_8x8,
.StrName = "MESA_FORMAT_RGBA_ASTC_8x8",
.Layout = MESA_FORMAT_LAYOUT_ASTC,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 16, .GreenBits = 16, .BlueBits = 16, .AlphaBits = 16,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 8, .BlockHeight = 8, .BlockDepth = 1,
.BytesPerBlock = 16,
.Swizzle = { 0, 1, 2, 3 },
.ArrayFormat = 0,
},
[MESA_FORMAT_RGBA_ASTC_10x5] = {
.Name = MESA_FORMAT_RGBA_ASTC_10x5,
.StrName = "MESA_FORMAT_RGBA_ASTC_10x5",
.Layout = MESA_FORMAT_LAYOUT_ASTC,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 16, .GreenBits = 16, .BlueBits = 16, .AlphaBits = 16,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 10, .BlockHeight = 5, .BlockDepth = 1,
.BytesPerBlock = 16,
.Swizzle = { 0, 1, 2, 3 },
.ArrayFormat = 0,
},
[MESA_FORMAT_RGBA_ASTC_10x6] = {
.Name = MESA_FORMAT_RGBA_ASTC_10x6,
.StrName = "MESA_FORMAT_RGBA_ASTC_10x6",
.Layout = MESA_FORMAT_LAYOUT_ASTC,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 16, .GreenBits = 16, .BlueBits = 16, .AlphaBits = 16,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 10, .BlockHeight = 6, .BlockDepth = 1,
.BytesPerBlock = 16,
.Swizzle = { 0, 1, 2, 3 },
.ArrayFormat = 0,
},
[MESA_FORMAT_RGBA_ASTC_10x8] = {
.Name = MESA_FORMAT_RGBA_ASTC_10x8,
.StrName = "MESA_FORMAT_RGBA_ASTC_10x8",
.Layout = MESA_FORMAT_LAYOUT_ASTC,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 16, .GreenBits = 16, .BlueBits = 16, .AlphaBits = 16,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 10, .BlockHeight = 8, .BlockDepth = 1,
.BytesPerBlock = 16,
.Swizzle = { 0, 1, 2, 3 },
.ArrayFormat = 0,
},
[MESA_FORMAT_RGBA_ASTC_10x10] = {
.Name = MESA_FORMAT_RGBA_ASTC_10x10,
.StrName = "MESA_FORMAT_RGBA_ASTC_10x10",
.Layout = MESA_FORMAT_LAYOUT_ASTC,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 16, .GreenBits = 16, .BlueBits = 16, .AlphaBits = 16,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 10, .BlockHeight = 10, .BlockDepth = 1,
.BytesPerBlock = 16,
.Swizzle = { 0, 1, 2, 3 },
.ArrayFormat = 0,
},
[MESA_FORMAT_RGBA_ASTC_12x10] = {
.Name = MESA_FORMAT_RGBA_ASTC_12x10,
.StrName = "MESA_FORMAT_RGBA_ASTC_12x10",
.Layout = MESA_FORMAT_LAYOUT_ASTC,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 16, .GreenBits = 16, .BlueBits = 16, .AlphaBits = 16,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 12, .BlockHeight = 10, .BlockDepth = 1,
.BytesPerBlock = 16,
.Swizzle = { 0, 1, 2, 3 },
.ArrayFormat = 0,
},
[MESA_FORMAT_RGBA_ASTC_12x12] = {
.Name = MESA_FORMAT_RGBA_ASTC_12x12,
.StrName = "MESA_FORMAT_RGBA_ASTC_12x12",
.Layout = MESA_FORMAT_LAYOUT_ASTC,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 16, .GreenBits = 16, .BlueBits = 16, .AlphaBits = 16,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 12, .BlockHeight = 12, .BlockDepth = 1,
.BytesPerBlock = 16,
.Swizzle = { 0, 1, 2, 3 },
.ArrayFormat = 0,
},
[MESA_FORMAT_SRGB8_ALPHA8_ASTC_4x4] = {
.Name = MESA_FORMAT_SRGB8_ALPHA8_ASTC_4x4,
.StrName = "MESA_FORMAT_SRGB8_ALPHA8_ASTC_4x4",
.Layout = MESA_FORMAT_LAYOUT_ASTC,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 8, .GreenBits = 8, .BlueBits = 8, .AlphaBits = 8,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 1,
.BlockWidth = 4, .BlockHeight = 4, .BlockDepth = 1,
.BytesPerBlock = 16,
.Swizzle = { 0, 1, 2, 3 },
.ArrayFormat = 0,
},
[MESA_FORMAT_SRGB8_ALPHA8_ASTC_5x4] = {
.Name = MESA_FORMAT_SRGB8_ALPHA8_ASTC_5x4,
.StrName = "MESA_FORMAT_SRGB8_ALPHA8_ASTC_5x4",
.Layout = MESA_FORMAT_LAYOUT_ASTC,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 8, .GreenBits = 8, .BlueBits = 8, .AlphaBits = 8,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 1,
.BlockWidth = 5, .BlockHeight = 4, .BlockDepth = 1,
.BytesPerBlock = 16,
.Swizzle = { 0, 1, 2, 3 },
.ArrayFormat = 0,
},
[MESA_FORMAT_SRGB8_ALPHA8_ASTC_5x5] = {
.Name = MESA_FORMAT_SRGB8_ALPHA8_ASTC_5x5,
.StrName = "MESA_FORMAT_SRGB8_ALPHA8_ASTC_5x5",
.Layout = MESA_FORMAT_LAYOUT_ASTC,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 8, .GreenBits = 8, .BlueBits = 8, .AlphaBits = 8,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 1,
.BlockWidth = 5, .BlockHeight = 5, .BlockDepth = 1,
.BytesPerBlock = 16,
.Swizzle = { 0, 1, 2, 3 },
.ArrayFormat = 0,
},
[MESA_FORMAT_SRGB8_ALPHA8_ASTC_6x5] = {
.Name = MESA_FORMAT_SRGB8_ALPHA8_ASTC_6x5,
.StrName = "MESA_FORMAT_SRGB8_ALPHA8_ASTC_6x5",
.Layout = MESA_FORMAT_LAYOUT_ASTC,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 8, .GreenBits = 8, .BlueBits = 8, .AlphaBits = 8,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 1,
.BlockWidth = 6, .BlockHeight = 5, .BlockDepth = 1,
.BytesPerBlock = 16,
.Swizzle = { 0, 1, 2, 3 },
.ArrayFormat = 0,
},
[MESA_FORMAT_SRGB8_ALPHA8_ASTC_6x6] = {
.Name = MESA_FORMAT_SRGB8_ALPHA8_ASTC_6x6,
.StrName = "MESA_FORMAT_SRGB8_ALPHA8_ASTC_6x6",
.Layout = MESA_FORMAT_LAYOUT_ASTC,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 8, .GreenBits = 8, .BlueBits = 8, .AlphaBits = 8,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 1,
.BlockWidth = 6, .BlockHeight = 6, .BlockDepth = 1,
.BytesPerBlock = 16,
.Swizzle = { 0, 1, 2, 3 },
.ArrayFormat = 0,
},
[MESA_FORMAT_SRGB8_ALPHA8_ASTC_8x5] = {
.Name = MESA_FORMAT_SRGB8_ALPHA8_ASTC_8x5,
.StrName = "MESA_FORMAT_SRGB8_ALPHA8_ASTC_8x5",
.Layout = MESA_FORMAT_LAYOUT_ASTC,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 8, .GreenBits = 8, .BlueBits = 8, .AlphaBits = 8,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 1,
.BlockWidth = 8, .BlockHeight = 5, .BlockDepth = 1,
.BytesPerBlock = 16,
.Swizzle = { 0, 1, 2, 3 },
.ArrayFormat = 0,
},
[MESA_FORMAT_SRGB8_ALPHA8_ASTC_8x6] = {
.Name = MESA_FORMAT_SRGB8_ALPHA8_ASTC_8x6,
.StrName = "MESA_FORMAT_SRGB8_ALPHA8_ASTC_8x6",
.Layout = MESA_FORMAT_LAYOUT_ASTC,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 8, .GreenBits = 8, .BlueBits = 8, .AlphaBits = 8,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 1,
.BlockWidth = 8, .BlockHeight = 6, .BlockDepth = 1,
.BytesPerBlock = 16,
.Swizzle = { 0, 1, 2, 3 },
.ArrayFormat = 0,
},
[MESA_FORMAT_SRGB8_ALPHA8_ASTC_8x8] = {
.Name = MESA_FORMAT_SRGB8_ALPHA8_ASTC_8x8,
.StrName = "MESA_FORMAT_SRGB8_ALPHA8_ASTC_8x8",
.Layout = MESA_FORMAT_LAYOUT_ASTC,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 8, .GreenBits = 8, .BlueBits = 8, .AlphaBits = 8,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 1,
.BlockWidth = 8, .BlockHeight = 8, .BlockDepth = 1,
.BytesPerBlock = 16,
.Swizzle = { 0, 1, 2, 3 },
.ArrayFormat = 0,
},
[MESA_FORMAT_SRGB8_ALPHA8_ASTC_10x5] = {
.Name = MESA_FORMAT_SRGB8_ALPHA8_ASTC_10x5,
.StrName = "MESA_FORMAT_SRGB8_ALPHA8_ASTC_10x5",
.Layout = MESA_FORMAT_LAYOUT_ASTC,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 8, .GreenBits = 8, .BlueBits = 8, .AlphaBits = 8,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 1,
.BlockWidth = 10, .BlockHeight = 5, .BlockDepth = 1,
.BytesPerBlock = 16,
.Swizzle = { 0, 1, 2, 3 },
.ArrayFormat = 0,
},
[MESA_FORMAT_SRGB8_ALPHA8_ASTC_10x6] = {
.Name = MESA_FORMAT_SRGB8_ALPHA8_ASTC_10x6,
.StrName = "MESA_FORMAT_SRGB8_ALPHA8_ASTC_10x6",
.Layout = MESA_FORMAT_LAYOUT_ASTC,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 8, .GreenBits = 8, .BlueBits = 8, .AlphaBits = 8,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 1,
.BlockWidth = 10, .BlockHeight = 6, .BlockDepth = 1,
.BytesPerBlock = 16,
.Swizzle = { 0, 1, 2, 3 },
.ArrayFormat = 0,
},
[MESA_FORMAT_SRGB8_ALPHA8_ASTC_10x8] = {
.Name = MESA_FORMAT_SRGB8_ALPHA8_ASTC_10x8,
.StrName = "MESA_FORMAT_SRGB8_ALPHA8_ASTC_10x8",
.Layout = MESA_FORMAT_LAYOUT_ASTC,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 8, .GreenBits = 8, .BlueBits = 8, .AlphaBits = 8,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 1,
.BlockWidth = 10, .BlockHeight = 8, .BlockDepth = 1,
.BytesPerBlock = 16,
.Swizzle = { 0, 1, 2, 3 },
.ArrayFormat = 0,
},
[MESA_FORMAT_SRGB8_ALPHA8_ASTC_10x10] = {
.Name = MESA_FORMAT_SRGB8_ALPHA8_ASTC_10x10,
.StrName = "MESA_FORMAT_SRGB8_ALPHA8_ASTC_10x10",
.Layout = MESA_FORMAT_LAYOUT_ASTC,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 8, .GreenBits = 8, .BlueBits = 8, .AlphaBits = 8,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 1,
.BlockWidth = 10, .BlockHeight = 10, .BlockDepth = 1,
.BytesPerBlock = 16,
.Swizzle = { 0, 1, 2, 3 },
.ArrayFormat = 0,
},
[MESA_FORMAT_SRGB8_ALPHA8_ASTC_12x10] = {
.Name = MESA_FORMAT_SRGB8_ALPHA8_ASTC_12x10,
.StrName = "MESA_FORMAT_SRGB8_ALPHA8_ASTC_12x10",
.Layout = MESA_FORMAT_LAYOUT_ASTC,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 8, .GreenBits = 8, .BlueBits = 8, .AlphaBits = 8,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 1,
.BlockWidth = 12, .BlockHeight = 10, .BlockDepth = 1,
.BytesPerBlock = 16,
.Swizzle = { 0, 1, 2, 3 },
.ArrayFormat = 0,
},
[MESA_FORMAT_SRGB8_ALPHA8_ASTC_12x12] = {
.Name = MESA_FORMAT_SRGB8_ALPHA8_ASTC_12x12,
.StrName = "MESA_FORMAT_SRGB8_ALPHA8_ASTC_12x12",
.Layout = MESA_FORMAT_LAYOUT_ASTC,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 8, .GreenBits = 8, .BlueBits = 8, .AlphaBits = 8,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 1,
.BlockWidth = 12, .BlockHeight = 12, .BlockDepth = 1,
.BytesPerBlock = 16,
.Swizzle = { 0, 1, 2, 3 },
.ArrayFormat = 0,
},
[MESA_FORMAT_RGBA_ASTC_3x3x3] = {
.Name = MESA_FORMAT_RGBA_ASTC_3x3x3,
.StrName = "MESA_FORMAT_RGBA_ASTC_3x3x3",
.Layout = MESA_FORMAT_LAYOUT_ASTC,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 16, .GreenBits = 16, .BlueBits = 16, .AlphaBits = 16,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 3, .BlockHeight = 3, .BlockDepth = 3,
.BytesPerBlock = 16,
.Swizzle = { 0, 1, 2, 3 },
.ArrayFormat = 0,
},
[MESA_FORMAT_RGBA_ASTC_4x3x3] = {
.Name = MESA_FORMAT_RGBA_ASTC_4x3x3,
.StrName = "MESA_FORMAT_RGBA_ASTC_4x3x3",
.Layout = MESA_FORMAT_LAYOUT_ASTC,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 16, .GreenBits = 16, .BlueBits = 16, .AlphaBits = 16,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 4, .BlockHeight = 3, .BlockDepth = 3,
.BytesPerBlock = 16,
.Swizzle = { 0, 1, 2, 3 },
.ArrayFormat = 0,
},
[MESA_FORMAT_RGBA_ASTC_4x4x3] = {
.Name = MESA_FORMAT_RGBA_ASTC_4x4x3,
.StrName = "MESA_FORMAT_RGBA_ASTC_4x4x3",
.Layout = MESA_FORMAT_LAYOUT_ASTC,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 16, .GreenBits = 16, .BlueBits = 16, .AlphaBits = 16,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 4, .BlockHeight = 4, .BlockDepth = 3,
.BytesPerBlock = 16,
.Swizzle = { 0, 1, 2, 3 },
.ArrayFormat = 0,
},
[MESA_FORMAT_RGBA_ASTC_4x4x4] = {
.Name = MESA_FORMAT_RGBA_ASTC_4x4x4,
.StrName = "MESA_FORMAT_RGBA_ASTC_4x4x4",
.Layout = MESA_FORMAT_LAYOUT_ASTC,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 16, .GreenBits = 16, .BlueBits = 16, .AlphaBits = 16,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 4, .BlockHeight = 4, .BlockDepth = 4,
.BytesPerBlock = 16,
.Swizzle = { 0, 1, 2, 3 },
.ArrayFormat = 0,
},
[MESA_FORMAT_RGBA_ASTC_5x4x4] = {
.Name = MESA_FORMAT_RGBA_ASTC_5x4x4,
.StrName = "MESA_FORMAT_RGBA_ASTC_5x4x4",
.Layout = MESA_FORMAT_LAYOUT_ASTC,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 16, .GreenBits = 16, .BlueBits = 16, .AlphaBits = 16,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 5, .BlockHeight = 4, .BlockDepth = 4,
.BytesPerBlock = 16,
.Swizzle = { 0, 1, 2, 3 },
.ArrayFormat = 0,
},
[MESA_FORMAT_RGBA_ASTC_5x5x4] = {
.Name = MESA_FORMAT_RGBA_ASTC_5x5x4,
.StrName = "MESA_FORMAT_RGBA_ASTC_5x5x4",
.Layout = MESA_FORMAT_LAYOUT_ASTC,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 16, .GreenBits = 16, .BlueBits = 16, .AlphaBits = 16,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 5, .BlockHeight = 5, .BlockDepth = 4,
.BytesPerBlock = 16,
.Swizzle = { 0, 1, 2, 3 },
.ArrayFormat = 0,
},
[MESA_FORMAT_RGBA_ASTC_5x5x5] = {
.Name = MESA_FORMAT_RGBA_ASTC_5x5x5,
.StrName = "MESA_FORMAT_RGBA_ASTC_5x5x5",
.Layout = MESA_FORMAT_LAYOUT_ASTC,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 16, .GreenBits = 16, .BlueBits = 16, .AlphaBits = 16,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 5, .BlockHeight = 5, .BlockDepth = 5,
.BytesPerBlock = 16,
.Swizzle = { 0, 1, 2, 3 },
.ArrayFormat = 0,
},
[MESA_FORMAT_RGBA_ASTC_6x5x5] = {
.Name = MESA_FORMAT_RGBA_ASTC_6x5x5,
.StrName = "MESA_FORMAT_RGBA_ASTC_6x5x5",
.Layout = MESA_FORMAT_LAYOUT_ASTC,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 16, .GreenBits = 16, .BlueBits = 16, .AlphaBits = 16,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 6, .BlockHeight = 5, .BlockDepth = 5,
.BytesPerBlock = 16,
.Swizzle = { 0, 1, 2, 3 },
.ArrayFormat = 0,
},
[MESA_FORMAT_RGBA_ASTC_6x6x5] = {
.Name = MESA_FORMAT_RGBA_ASTC_6x6x5,
.StrName = "MESA_FORMAT_RGBA_ASTC_6x6x5",
.Layout = MESA_FORMAT_LAYOUT_ASTC,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 16, .GreenBits = 16, .BlueBits = 16, .AlphaBits = 16,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 6, .BlockHeight = 6, .BlockDepth = 5,
.BytesPerBlock = 16,
.Swizzle = { 0, 1, 2, 3 },
.ArrayFormat = 0,
},
[MESA_FORMAT_RGBA_ASTC_6x6x6] = {
.Name = MESA_FORMAT_RGBA_ASTC_6x6x6,
.StrName = "MESA_FORMAT_RGBA_ASTC_6x6x6",
.Layout = MESA_FORMAT_LAYOUT_ASTC,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 16, .GreenBits = 16, .BlueBits = 16, .AlphaBits = 16,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 6, .BlockHeight = 6, .BlockDepth = 6,
.BytesPerBlock = 16,
.Swizzle = { 0, 1, 2, 3 },
.ArrayFormat = 0,
},
[MESA_FORMAT_SRGB8_ALPHA8_ASTC_3x3x3] = {
.Name = MESA_FORMAT_SRGB8_ALPHA8_ASTC_3x3x3,
.StrName = "MESA_FORMAT_SRGB8_ALPHA8_ASTC_3x3x3",
.Layout = MESA_FORMAT_LAYOUT_ASTC,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 8, .GreenBits = 8, .BlueBits = 8, .AlphaBits = 8,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 1,
.BlockWidth = 3, .BlockHeight = 3, .BlockDepth = 3,
.BytesPerBlock = 16,
.Swizzle = { 0, 1, 2, 3 },
.ArrayFormat = 0,
},
[MESA_FORMAT_SRGB8_ALPHA8_ASTC_4x3x3] = {
.Name = MESA_FORMAT_SRGB8_ALPHA8_ASTC_4x3x3,
.StrName = "MESA_FORMAT_SRGB8_ALPHA8_ASTC_4x3x3",
.Layout = MESA_FORMAT_LAYOUT_ASTC,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 8, .GreenBits = 8, .BlueBits = 8, .AlphaBits = 8,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 1,
.BlockWidth = 4, .BlockHeight = 3, .BlockDepth = 3,
.BytesPerBlock = 16,
.Swizzle = { 0, 1, 2, 3 },
.ArrayFormat = 0,
},
[MESA_FORMAT_SRGB8_ALPHA8_ASTC_4x4x3] = {
.Name = MESA_FORMAT_SRGB8_ALPHA8_ASTC_4x4x3,
.StrName = "MESA_FORMAT_SRGB8_ALPHA8_ASTC_4x4x3",
.Layout = MESA_FORMAT_LAYOUT_ASTC,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 8, .GreenBits = 8, .BlueBits = 8, .AlphaBits = 8,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 1,
.BlockWidth = 4, .BlockHeight = 4, .BlockDepth = 3,
.BytesPerBlock = 16,
.Swizzle = { 0, 1, 2, 3 },
.ArrayFormat = 0,
},
[MESA_FORMAT_SRGB8_ALPHA8_ASTC_4x4x4] = {
.Name = MESA_FORMAT_SRGB8_ALPHA8_ASTC_4x4x4,
.StrName = "MESA_FORMAT_SRGB8_ALPHA8_ASTC_4x4x4",
.Layout = MESA_FORMAT_LAYOUT_ASTC,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 8, .GreenBits = 8, .BlueBits = 8, .AlphaBits = 8,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 1,
.BlockWidth = 4, .BlockHeight = 4, .BlockDepth = 4,
.BytesPerBlock = 16,
.Swizzle = { 0, 1, 2, 3 },
.ArrayFormat = 0,
},
[MESA_FORMAT_SRGB8_ALPHA8_ASTC_5x4x4] = {
.Name = MESA_FORMAT_SRGB8_ALPHA8_ASTC_5x4x4,
.StrName = "MESA_FORMAT_SRGB8_ALPHA8_ASTC_5x4x4",
.Layout = MESA_FORMAT_LAYOUT_ASTC,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 8, .GreenBits = 8, .BlueBits = 8, .AlphaBits = 8,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 1,
.BlockWidth = 5, .BlockHeight = 4, .BlockDepth = 4,
.BytesPerBlock = 16,
.Swizzle = { 0, 1, 2, 3 },
.ArrayFormat = 0,
},
[MESA_FORMAT_SRGB8_ALPHA8_ASTC_5x5x4] = {
.Name = MESA_FORMAT_SRGB8_ALPHA8_ASTC_5x5x4,
.StrName = "MESA_FORMAT_SRGB8_ALPHA8_ASTC_5x5x4",
.Layout = MESA_FORMAT_LAYOUT_ASTC,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 8, .GreenBits = 8, .BlueBits = 8, .AlphaBits = 8,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 1,
.BlockWidth = 5, .BlockHeight = 5, .BlockDepth = 4,
.BytesPerBlock = 16,
.Swizzle = { 0, 1, 2, 3 },
.ArrayFormat = 0,
},
[MESA_FORMAT_SRGB8_ALPHA8_ASTC_5x5x5] = {
.Name = MESA_FORMAT_SRGB8_ALPHA8_ASTC_5x5x5,
.StrName = "MESA_FORMAT_SRGB8_ALPHA8_ASTC_5x5x5",
.Layout = MESA_FORMAT_LAYOUT_ASTC,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 8, .GreenBits = 8, .BlueBits = 8, .AlphaBits = 8,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 1,
.BlockWidth = 5, .BlockHeight = 5, .BlockDepth = 5,
.BytesPerBlock = 16,
.Swizzle = { 0, 1, 2, 3 },
.ArrayFormat = 0,
},
[MESA_FORMAT_SRGB8_ALPHA8_ASTC_6x5x5] = {
.Name = MESA_FORMAT_SRGB8_ALPHA8_ASTC_6x5x5,
.StrName = "MESA_FORMAT_SRGB8_ALPHA8_ASTC_6x5x5",
.Layout = MESA_FORMAT_LAYOUT_ASTC,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 8, .GreenBits = 8, .BlueBits = 8, .AlphaBits = 8,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 1,
.BlockWidth = 6, .BlockHeight = 5, .BlockDepth = 5,
.BytesPerBlock = 16,
.Swizzle = { 0, 1, 2, 3 },
.ArrayFormat = 0,
},
[MESA_FORMAT_SRGB8_ALPHA8_ASTC_6x6x5] = {
.Name = MESA_FORMAT_SRGB8_ALPHA8_ASTC_6x6x5,
.StrName = "MESA_FORMAT_SRGB8_ALPHA8_ASTC_6x6x5",
.Layout = MESA_FORMAT_LAYOUT_ASTC,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 8, .GreenBits = 8, .BlueBits = 8, .AlphaBits = 8,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 1,
.BlockWidth = 6, .BlockHeight = 6, .BlockDepth = 5,
.BytesPerBlock = 16,
.Swizzle = { 0, 1, 2, 3 },
.ArrayFormat = 0,
},
[MESA_FORMAT_SRGB8_ALPHA8_ASTC_6x6x6] = {
.Name = MESA_FORMAT_SRGB8_ALPHA8_ASTC_6x6x6,
.StrName = "MESA_FORMAT_SRGB8_ALPHA8_ASTC_6x6x6",
.Layout = MESA_FORMAT_LAYOUT_ASTC,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 8, .GreenBits = 8, .BlueBits = 8, .AlphaBits = 8,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 1,
.BlockWidth = 6, .BlockHeight = 6, .BlockDepth = 6,
.BytesPerBlock = 16,
.Swizzle = { 0, 1, 2, 3 },
.ArrayFormat = 0,
},
[MESA_FORMAT_ATC_RGB] = {
.Name = MESA_FORMAT_ATC_RGB,
.StrName = "MESA_FORMAT_ATC_RGB",
.Layout = MESA_FORMAT_LAYOUT_ATC,
.BaseFormat = GL_RGB,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 8, .GreenBits = 8, .BlueBits = 8, .AlphaBits = 0,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 4, .BlockHeight = 4, .BlockDepth = 1,
.BytesPerBlock = 8,
.Swizzle = { 0, 1, 2, 5 },
.ArrayFormat = 0,
},
[MESA_FORMAT_ATC_RGBA_EXPLICIT] = {
.Name = MESA_FORMAT_ATC_RGBA_EXPLICIT,
.StrName = "MESA_FORMAT_ATC_RGBA_EXPLICIT",
.Layout = MESA_FORMAT_LAYOUT_ATC,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 8, .GreenBits = 8, .BlueBits = 8, .AlphaBits = 8,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 4, .BlockHeight = 4, .BlockDepth = 1,
.BytesPerBlock = 16,
.Swizzle = { 0, 1, 2, 3 },
.ArrayFormat = 0,
},
[MESA_FORMAT_ATC_RGBA_INTERPOLATED] = {
.Name = MESA_FORMAT_ATC_RGBA_INTERPOLATED,
.StrName = "MESA_FORMAT_ATC_RGBA_INTERPOLATED",
.Layout = MESA_FORMAT_LAYOUT_ATC,
.BaseFormat = GL_RGBA,
.DataType = GL_UNSIGNED_NORMALIZED,
.RedBits = 8, .GreenBits = 8, .BlueBits = 8, .AlphaBits = 8,
.LuminanceBits = 0, .IntensityBits = 0, .DepthBits = 0, .StencilBits = 0,
.IsSRGBFormat = 0,
.BlockWidth = 4, .BlockHeight = 4, .BlockDepth = 1,
.BytesPerBlock = 16,
.Swizzle = { 0, 1, 2, 3 },
.ArrayFormat = 0,
},
};
|
cfe5a659961aa0e1bad63f94e45f9e59b6f6da71
|
8b98cd47f934d2a4a8d0b2842d3277b01f3fb7fa
|
/applications/obsolete/asterix/lib/ast_main_ft.c
|
ee11652ddd86364f9043e63fe053d1e51cb69ccf
|
[] |
no_license
|
Starlink/starlink
|
1cc03b85eb78330a3622003b26b69c1733df50fe
|
2c374b3e97c9cebcc8f3bd2f8b4bb326eefe061a
|
refs/heads/master
| 2023-07-26T09:32:27.987319
| 2023-07-05T23:56:27
| 2023-07-05T23:56:27
| 5,169,323
| 139
| 45
| null | 2022-11-18T13:29:32
| 2012-07-24T18:15:25
|
Fortran
|
UTF-8
|
C
| false
| false
| 427
|
c
|
ast_main_ft.c
|
/*
filename: ast_ftool_main.c
purpose: c - wrapper for host ftool task
author: DJA
*/
#include <stdio.h>
#include "f77.h"
#include "sae_par.h"
#ifdef unix
#define RETURN 0
#endif
#ifdef vms
#define RETURN 1
#endif
#ifdef sun4
int MAIN_; /* work around SunOS 4.1.3 bug */
#endif
main (argc,argv)
int argc;
char **argv;
{
OpenDefaultPF(argc, argv);
F77_CALL(ast_ftool_applic)();
CloseDefaultPF();
return(RETURN);
}
|
651cb4c90b26169a8dbddc0463add8c555147a03
|
da1500e0d3040497614d5327d2461a22e934b4d8
|
/third_party/llvm-project/compiler-rt/test/builtins/Unit/powixf2_test.c
|
ec9bc04db4b2bfb1a218975ee50fd3fb3e18402f
|
[
"NCSA",
"MIT",
"LLVM-exception",
"Apache-2.0",
"BSD-3-Clause",
"GPL-1.0-or-later",
"LGPL-2.0-or-later"
] |
permissive
|
youtube/cobalt
|
34085fc93972ebe05b988b15410e99845efd1968
|
acefdaaadd3ef46f10f63d1acae2259e4024d383
|
refs/heads/main
| 2023-09-01T13:09:47.225174
| 2023-09-01T08:54:54
| 2023-09-01T08:54:54
| 50,049,789
| 169
| 80
|
BSD-3-Clause
| 2023-09-14T21:50:50
| 2016-01-20T18:11:34
| null |
UTF-8
|
C
| false
| false
| 5,875
|
c
|
powixf2_test.c
|
// RUN: %clang_builtins %s %librt -o %t && %run %t
// REQUIRES: librt_has_powixf2
// UNSUPPORTED: target=powerpc64{{.*}}
// REQUIRES: x86-target-arch
#if !_ARCH_PPC
#include "int_lib.h"
#include <stdio.h>
#include <math.h>
// Returns: a ^ b
COMPILER_RT_ABI long double __powixf2(long double a, int b);
int test__powixf2(long double a, int b, long double expected)
{
long double x = __powixf2(a, b);
int correct = (x == expected) && (signbit(x) == signbit(expected));
if (!correct)
printf("error in __powixf2(%Lf, %d) = %Lf, expected %Lf\n",
a, b, x, expected);
return !correct;
}
#endif
int main()
{
#if !_ARCH_PPC
if (test__powixf2(0, 0, 1))
return 1;
if (test__powixf2(1, 0, 1))
return 1;
if (test__powixf2(1.5, 0, 1))
return 1;
if (test__powixf2(2, 0, 1))
return 1;
if (test__powixf2(INFINITY, 0, 1))
return 1;
if (test__powixf2(-0., 0, 1))
return 1;
if (test__powixf2(-1, 0, 1))
return 1;
if (test__powixf2(-1.5, 0, 1))
return 1;
if (test__powixf2(-2, 0, 1))
return 1;
if (test__powixf2(-INFINITY, 0, 1))
return 1;
if (test__powixf2(0, 1, 0))
return 1;
if (test__powixf2(0, 2, 0))
return 1;
if (test__powixf2(0, 3, 0))
return 1;
if (test__powixf2(0, 4, 0))
return 1;
if (test__powixf2(0, INT_MAX - 1, 0))
return 1;
if (test__powixf2(0, INT_MAX, 0))
return 1;
if (test__powixf2(-0., 1, -0.))
return 1;
if (test__powixf2(-0., 2, 0))
return 1;
if (test__powixf2(-0., 3, -0.))
return 1;
if (test__powixf2(-0., 4, 0))
return 1;
if (test__powixf2(-0., INT_MAX - 1, 0))
return 1;
if (test__powixf2(-0., INT_MAX, -0.))
return 1;
if (test__powixf2(1, 1, 1))
return 1;
if (test__powixf2(1, 2, 1))
return 1;
if (test__powixf2(1, 3, 1))
return 1;
if (test__powixf2(1, 4, 1))
return 1;
if (test__powixf2(1, INT_MAX - 1, 1))
return 1;
if (test__powixf2(1, INT_MAX, 1))
return 1;
if (test__powixf2(INFINITY, 1, INFINITY))
return 1;
if (test__powixf2(INFINITY, 2, INFINITY))
return 1;
if (test__powixf2(INFINITY, 3, INFINITY))
return 1;
if (test__powixf2(INFINITY, 4, INFINITY))
return 1;
if (test__powixf2(INFINITY, INT_MAX - 1, INFINITY))
return 1;
if (test__powixf2(INFINITY, INT_MAX, INFINITY))
return 1;
if (test__powixf2(-INFINITY, 1, -INFINITY))
return 1;
if (test__powixf2(-INFINITY, 2, INFINITY))
return 1;
if (test__powixf2(-INFINITY, 3, -INFINITY))
return 1;
if (test__powixf2(-INFINITY, 4, INFINITY))
return 1;
if (test__powixf2(-INFINITY, INT_MAX - 1, INFINITY))
return 1;
if (test__powixf2(-INFINITY, INT_MAX, -INFINITY))
return 1;
if (test__powixf2(0, -1, INFINITY))
return 1;
if (test__powixf2(0, -2, INFINITY))
return 1;
if (test__powixf2(0, -3, INFINITY))
return 1;
if (test__powixf2(0, -4, INFINITY))
return 1;
if (test__powixf2(0, INT_MIN + 2, INFINITY))
return 1;
if (test__powixf2(0, INT_MIN + 1, INFINITY))
return 1;
if (test__powixf2(0, INT_MIN, INFINITY))
return 1;
if (test__powixf2(-0., -1, -INFINITY))
return 1;
if (test__powixf2(-0., -2, INFINITY))
return 1;
if (test__powixf2(-0., -3, -INFINITY))
return 1;
if (test__powixf2(-0., -4, INFINITY))
return 1;
if (test__powixf2(-0., INT_MIN + 2, INFINITY))
return 1;
if (test__powixf2(-0., INT_MIN + 1, -INFINITY))
return 1;
if (test__powixf2(-0., INT_MIN, INFINITY))
return 1;
if (test__powixf2(1, -1, 1))
return 1;
if (test__powixf2(1, -2, 1))
return 1;
if (test__powixf2(1, -3, 1))
return 1;
if (test__powixf2(1, -4, 1))
return 1;
if (test__powixf2(1, INT_MIN + 2, 1))
return 1;
if (test__powixf2(1, INT_MIN + 1, 1))
return 1;
if (test__powixf2(1, INT_MIN, 1))
return 1;
if (test__powixf2(INFINITY, -1, 0))
return 1;
if (test__powixf2(INFINITY, -2, 0))
return 1;
if (test__powixf2(INFINITY, -3, 0))
return 1;
if (test__powixf2(INFINITY, -4, 0))
return 1;
if (test__powixf2(INFINITY, INT_MIN + 2, 0))
return 1;
if (test__powixf2(INFINITY, INT_MIN + 1, 0))
return 1;
if (test__powixf2(INFINITY, INT_MIN, 0))
return 1;
if (test__powixf2(-INFINITY, -1, -0.))
return 1;
if (test__powixf2(-INFINITY, -2, 0))
return 1;
if (test__powixf2(-INFINITY, -3, -0.))
return 1;
if (test__powixf2(-INFINITY, -4, 0))
return 1;
if (test__powixf2(-INFINITY, INT_MIN + 2, 0))
return 1;
if (test__powixf2(-INFINITY, INT_MIN + 1, -0.))
return 1;
if (test__powixf2(-INFINITY, INT_MIN, 0))
return 1;
if (test__powixf2(2, 10, 1024.))
return 1;
if (test__powixf2(-2, 10, 1024.))
return 1;
if (test__powixf2(2, -10, 1/1024.))
return 1;
if (test__powixf2(-2, -10, 1/1024.))
return 1;
if (test__powixf2(2, 19, 524288.))
return 1;
if (test__powixf2(-2, 19, -524288.))
return 1;
if (test__powixf2(2, -19, 1/524288.))
return 1;
if (test__powixf2(-2, -19, -1/524288.))
return 1;
if (test__powixf2(2, 31, 2147483648.))
return 1;
if (test__powixf2(-2, 31, -2147483648.))
return 1;
if (test__powixf2(2, -31, 1/2147483648.))
return 1;
if (test__powixf2(-2, -31, -1/2147483648.))
return 1;
#else
printf("skipped\n");
#endif
return 0;
}
|
0841d9f63523c458663f2e7369f76e889f1d4dee
|
d61b532db0d3e08818338cfaac530a1ced1ffe3b
|
/mach/vax4/libbsd4_1a/exit.c
|
8f5f9a8476b099c3630e4d927eccd3ea7230ff9c
|
[
"LicenseRef-scancode-other-permissive"
] |
permissive
|
davidgiven/ack
|
61049c7a8e95ff61a77b1edd3c22bb290720e276
|
db5a32c68c4a60ca26a3927a799ea662b5b2b0e5
|
refs/heads/default
| 2023-08-29T07:33:12.771205
| 2023-07-08T20:17:27
| 2023-07-08T20:17:27
| 37,686,316
| 376
| 74
|
NOASSERTION
| 2023-07-08T20:17:28
| 2015-06-18T21:33:42
|
C
|
UTF-8
|
C
| false
| false
| 44
|
c
|
exit.c
|
exit(code)
{
_cleanup() ;
_exit(code) ;
}
|
5e19e06af0def07ec0a7b0052e7c040ebeca97b2
|
88ae8695987ada722184307301e221e1ba3cc2fa
|
/third_party/wayland-protocols/gtk/gtk/gtkcssimagescaled.c
|
6dd3b05b4e5b1d7e568c6f890d047e7c1cc9c8b7
|
[
"Apache-2.0",
"LGPL-2.0-or-later",
"MIT",
"GPL-1.0-or-later",
"BSD-3-Clause",
"LGPL-2.0-only",
"LGPL-2.1-only"
] |
permissive
|
iridium-browser/iridium-browser
|
71d9c5ff76e014e6900b825f67389ab0ccd01329
|
5ee297f53dc7f8e70183031cff62f37b0f19d25f
|
refs/heads/master
| 2023-08-03T16:44:16.844552
| 2023-07-20T15:17:00
| 2023-07-23T16:09:30
| 220,016,632
| 341
| 40
|
BSD-3-Clause
| 2021-08-13T13:54:45
| 2019-11-06T14:32:31
| null |
UTF-8
|
C
| false
| false
| 6,952
|
c
|
gtkcssimagescaled.c
|
/*
* Copyright © 2013 Red Hat Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
* Authors: Alexander Larsson <alexl@gnome.org>
*/
#include "config.h"
#include "gtkcssimagescaledprivate.h"
#include "gtkstyleproviderprivate.h"
G_DEFINE_TYPE (GtkCssImageScaled, _gtk_css_image_scaled, GTK_TYPE_CSS_IMAGE)
static int
gtk_css_image_scaled_get_width (GtkCssImage *image)
{
GtkCssImageScaled *scaled = GTK_CSS_IMAGE_SCALED (image);
return _gtk_css_image_get_width (scaled->images[0])/scaled->scales[0];
}
static int
gtk_css_image_scaled_get_height (GtkCssImage *image)
{
GtkCssImageScaled *scaled = GTK_CSS_IMAGE_SCALED (image);
return _gtk_css_image_get_height (scaled->images[0])/scaled->scales[0];
}
static double
gtk_css_image_scaled_get_aspect_ratio (GtkCssImage *image)
{
GtkCssImageScaled *scaled = GTK_CSS_IMAGE_SCALED (image);
return _gtk_css_image_get_aspect_ratio (scaled->images[0]);
}
static void
gtk_css_image_scaled_snapshot (GtkCssImage *image,
GtkSnapshot *snapshot,
double width,
double height)
{
GtkCssImageScaled *scaled = GTK_CSS_IMAGE_SCALED (image);
gtk_css_image_snapshot (scaled->images[0], snapshot, width, height);
// FIXME apply scale
}
static void
gtk_css_image_scaled_print (GtkCssImage *image,
GString *string)
{
GtkCssImageScaled *scaled = GTK_CSS_IMAGE_SCALED (image);
int i;
g_string_append (string, "-gtk-scaled(");
for (i = 0; i < scaled->n_images; i++)
{
_gtk_css_image_print (scaled->images[i], string);
g_string_append_printf (string, ",%d", scaled->scales[i]);
if (i != scaled->n_images - 1)
g_string_append (string, ",");
}
g_string_append (string, ")");
}
static void
gtk_css_image_scaled_dispose (GObject *object)
{
GtkCssImageScaled *scaled = GTK_CSS_IMAGE_SCALED (object);
int i;
for (i = 0; i < scaled->n_images; i++)
g_object_unref (scaled->images[i]);
g_free (scaled->images);
scaled->images = NULL;
g_free (scaled->scales);
scaled->scales = NULL;
G_OBJECT_CLASS (_gtk_css_image_scaled_parent_class)->dispose (object);
}
static GtkCssImage *
gtk_css_image_scaled_compute (GtkCssImage *image,
guint property_id,
GtkStyleProvider *provider,
GtkCssStyle *style,
GtkCssStyle *parent_style)
{
GtkCssImageScaled *scaled = GTK_CSS_IMAGE_SCALED (image);
int scale;
GtkCssImageScaled *res;
int i;
int best;
scale = gtk_style_provider_get_scale (provider);
scale = MAX(scale, 1);
best = 0;
for (i = 0; i < scaled->n_images; i++)
{
if (scaled->scales[i] == scale)
{
best = i;
break;
}
else if ((scaled->scales[best] < scaled->scales[i] && scaled->scales[i] < scale) ||
(scale < scaled->scales[i] && scaled->scales[i] < scaled->scales[best]) ||
(scaled->scales[best] < scale && scaled->scales[i] > scale))
{
best = i;
}
}
res = g_object_new (GTK_TYPE_CSS_IMAGE_SCALED, NULL);
res->n_images = 1;
res->images = g_new (GtkCssImage *, 1);
res->scales = g_new (int, 1);
res->images[0] = _gtk_css_image_compute (scaled->images[best],
property_id,
provider,
style,
parent_style);
res->scales[0] = scaled->scales[best];
return GTK_CSS_IMAGE (res);
}
typedef struct
{
GPtrArray *images;
GArray *scales;
} GtkCssImageScaledParseData;
static guint
gtk_css_image_scaled_parse_arg (GtkCssParser *parser,
guint arg,
gpointer data_)
{
GtkCssImageScaledParseData *data = data_;
GtkCssImage *child;
int scale;
child = _gtk_css_image_new_parse (parser);
if (child == NULL)
return 0;
if (!gtk_css_parser_has_integer (parser))
scale = arg > 0 ? g_array_index (data->scales, int, arg - 1) + 1 : 1;
else if (!gtk_css_parser_consume_integer (parser, &scale))
return 0;
g_ptr_array_add (data->images, child);
g_array_append_val (data->scales, scale);
return 1;
}
static gboolean
gtk_css_image_scaled_parse (GtkCssImage *image,
GtkCssParser *parser)
{
GtkCssImageScaled *self = GTK_CSS_IMAGE_SCALED (image);
GtkCssImageScaledParseData data;
if (!gtk_css_parser_has_function (parser, "-gtk-scaled"))
{
gtk_css_parser_error_syntax (parser, "Expected '-gtk-scaled('");
return FALSE;
}
data.images = g_ptr_array_new_with_free_func (g_object_unref);
data.scales = g_array_new (FALSE, FALSE, sizeof (int));
if (!gtk_css_parser_consume_function (parser, 1, G_MAXUINT, gtk_css_image_scaled_parse_arg, &data))
{
g_ptr_array_unref (data.images);
g_array_unref (data.scales);
return FALSE;
}
self->n_images = data.images->len;
self->images = (GtkCssImage **) g_ptr_array_free (data.images, FALSE);
self->scales = (int *) g_array_free (data.scales, FALSE);
return TRUE;
}
static gboolean
gtk_css_image_scaled_is_computed (GtkCssImage *image)
{
GtkCssImageScaled *self = GTK_CSS_IMAGE_SCALED (image);
return self->n_images == 1 &&
gtk_css_image_is_computed (self->images[0]);
}
static void
_gtk_css_image_scaled_class_init (GtkCssImageScaledClass *klass)
{
GtkCssImageClass *image_class = GTK_CSS_IMAGE_CLASS (klass);
GObjectClass *object_class = G_OBJECT_CLASS (klass);
image_class->get_width = gtk_css_image_scaled_get_width;
image_class->get_height = gtk_css_image_scaled_get_height;
image_class->get_aspect_ratio = gtk_css_image_scaled_get_aspect_ratio;
image_class->snapshot = gtk_css_image_scaled_snapshot;
image_class->parse = gtk_css_image_scaled_parse;
image_class->compute = gtk_css_image_scaled_compute;
image_class->print = gtk_css_image_scaled_print;
image_class->is_computed = gtk_css_image_scaled_is_computed;
object_class->dispose = gtk_css_image_scaled_dispose;
}
static void
_gtk_css_image_scaled_init (GtkCssImageScaled *image_scaled)
{
}
|
e70458b6c98422eb571e4832e6395ec10b572361
|
b63fae70900031ab7e9de73d59e335b8fa3e4107
|
/libNative/src/main/jni/code-self/common/GlobalMacro.h
|
d4fae09ce619771485576b7a521c8cdbea0c7489
|
[
"Apache-2.0"
] |
permissive
|
yocn/AndroidMediaCodec
|
d12e8e918ebf6e00905c3e51226be2df230499fc
|
85db839b3dabf8e1e41e54aa4d46f330d3bdd9b5
|
refs/heads/master
| 2023-03-08T12:36:03.001295
| 2023-02-27T12:12:15
| 2023-02-27T12:12:15
| 200,152,483
| 110
| 44
| null | 2021-08-14T14:49:56
| 2019-08-02T02:42:37
|
C
|
UTF-8
|
C
| false
| false
| 346
|
h
|
GlobalMacro.h
|
//
// Created by 赵英坤 on 8/17/21.
//
#ifndef ANDROIDMEDIACODEC_GLOBALMACRO_H
#define ANDROIDMEDIACODEC_GLOBALMACRO_H
extern "C" {
#include <jni.h>
#include <android/log.h>
}
#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, "LogUtil", __VA_ARGS__)
#define LOGCATE LOGE
#define LOGI LOGE
#endif //ANDROIDMEDIACODEC_GLOBALMACRO_H
|
6fddb8e7a16f8e7cc8e9d1b1afbeb35752a5f57b
|
bb82a5f977bef455714c16e24e2d8254e2d0faa5
|
/src/vendor/duktape-2.7.0/src-input/duk_bi_buffer.c
|
65ee5e96b97d07360963e68227bba0d8bd53ec86
|
[
"Unlicense",
"MIT",
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] |
permissive
|
pqrs-org/Karabiner-Elements
|
4ae307d82f8b67547c161c7d46d2083a0fd07630
|
d05057d7c769e2ff35638282e888a6d5eca566be
|
refs/heads/main
| 2023-09-01T03:11:08.474417
| 2023-09-01T00:44:19
| 2023-09-01T00:44:19
| 63,037,806
| 8,197
| 389
|
Unlicense
| 2023-09-01T00:11:00
| 2016-07-11T04:57:55
|
C++
|
UTF-8
|
C
| false
| false
| 95,670
|
c
|
duk_bi_buffer.c
|
/*
* ES2015 TypedArray and Node.js Buffer built-ins
*/
#include "duk_internal.h"
/*
* Helpers for buffer handling, enabled with DUK_USE_BUFFEROBJECT_SUPPORT.
*/
#if defined(DUK_USE_BUFFEROBJECT_SUPPORT)
/* Map class number (minus DUK_HOBJECT_CLASS_BUFOBJ_MIN) to a bidx for the
* default internal prototype.
*/
static const duk_uint8_t duk__buffer_proto_from_classnum[] = {
DUK_BIDX_ARRAYBUFFER_PROTOTYPE, DUK_BIDX_DATAVIEW_PROTOTYPE, DUK_BIDX_INT8ARRAY_PROTOTYPE,
DUK_BIDX_UINT8ARRAY_PROTOTYPE, DUK_BIDX_UINT8CLAMPEDARRAY_PROTOTYPE, DUK_BIDX_INT16ARRAY_PROTOTYPE,
DUK_BIDX_UINT16ARRAY_PROTOTYPE, DUK_BIDX_INT32ARRAY_PROTOTYPE, DUK_BIDX_UINT32ARRAY_PROTOTYPE,
DUK_BIDX_FLOAT32ARRAY_PROTOTYPE, DUK_BIDX_FLOAT64ARRAY_PROTOTYPE
};
/* Map DUK_HBUFOBJ_ELEM_xxx to duk_hobject class number.
* Sync with duk_hbufobj.h and duk_hobject.h.
*/
static const duk_uint8_t duk__buffer_class_from_elemtype[9] = { DUK_HOBJECT_CLASS_UINT8ARRAY, DUK_HOBJECT_CLASS_UINT8CLAMPEDARRAY,
DUK_HOBJECT_CLASS_INT8ARRAY, DUK_HOBJECT_CLASS_UINT16ARRAY,
DUK_HOBJECT_CLASS_INT16ARRAY, DUK_HOBJECT_CLASS_UINT32ARRAY,
DUK_HOBJECT_CLASS_INT32ARRAY, DUK_HOBJECT_CLASS_FLOAT32ARRAY,
DUK_HOBJECT_CLASS_FLOAT64ARRAY };
/* Map DUK_HBUFOBJ_ELEM_xxx to prototype object built-in index.
* Sync with duk_hbufobj.h.
*/
static const duk_uint8_t duk__buffer_proto_from_elemtype[9] = {
DUK_BIDX_UINT8ARRAY_PROTOTYPE, DUK_BIDX_UINT8CLAMPEDARRAY_PROTOTYPE, DUK_BIDX_INT8ARRAY_PROTOTYPE,
DUK_BIDX_UINT16ARRAY_PROTOTYPE, DUK_BIDX_INT16ARRAY_PROTOTYPE, DUK_BIDX_UINT32ARRAY_PROTOTYPE,
DUK_BIDX_INT32ARRAY_PROTOTYPE, DUK_BIDX_FLOAT32ARRAY_PROTOTYPE, DUK_BIDX_FLOAT64ARRAY_PROTOTYPE
};
/* Map DUK__FLD_xxx to byte size. */
static const duk_uint8_t duk__buffer_nbytes_from_fldtype[6] = {
1, /* DUK__FLD_8BIT */
2, /* DUK__FLD_16BIT */
4, /* DUK__FLD_32BIT */
4, /* DUK__FLD_FLOAT */
8, /* DUK__FLD_DOUBLE */
0 /* DUK__FLD_VARINT; not relevant here */
};
/* Bitfield for each DUK_HBUFOBJ_ELEM_xxx indicating which element types
* are compatible with a blind byte copy for the TypedArray set() method (also
* used for TypedArray constructor). Array index is target buffer elem type,
* bitfield indicates compatible source types. The types must have same byte
* size and they must be coercion compatible.
*/
#if !defined(DUK_USE_PREFER_SIZE)
static duk_uint16_t duk__buffer_elemtype_copy_compatible[9] = {
/* xxx -> DUK_HBUFOBJ_ELEM_UINT8 */
(1U << DUK_HBUFOBJ_ELEM_UINT8) | (1U << DUK_HBUFOBJ_ELEM_UINT8CLAMPED) | (1U << DUK_HBUFOBJ_ELEM_INT8),
/* xxx -> DUK_HBUFOBJ_ELEM_UINT8CLAMPED
* Note: INT8 is -not- copy compatible, e.g. -1 would coerce to 0x00.
*/
(1U << DUK_HBUFOBJ_ELEM_UINT8) | (1U << DUK_HBUFOBJ_ELEM_UINT8CLAMPED),
/* xxx -> DUK_HBUFOBJ_ELEM_INT8 */
(1U << DUK_HBUFOBJ_ELEM_UINT8) | (1U << DUK_HBUFOBJ_ELEM_UINT8CLAMPED) | (1U << DUK_HBUFOBJ_ELEM_INT8),
/* xxx -> DUK_HBUFOBJ_ELEM_UINT16 */
(1U << DUK_HBUFOBJ_ELEM_UINT16) | (1U << DUK_HBUFOBJ_ELEM_INT16),
/* xxx -> DUK_HBUFOBJ_ELEM_INT16 */
(1U << DUK_HBUFOBJ_ELEM_UINT16) | (1U << DUK_HBUFOBJ_ELEM_INT16),
/* xxx -> DUK_HBUFOBJ_ELEM_UINT32 */
(1U << DUK_HBUFOBJ_ELEM_UINT32) | (1U << DUK_HBUFOBJ_ELEM_INT32),
/* xxx -> DUK_HBUFOBJ_ELEM_INT32 */
(1U << DUK_HBUFOBJ_ELEM_UINT32) | (1U << DUK_HBUFOBJ_ELEM_INT32),
/* xxx -> DUK_HBUFOBJ_ELEM_FLOAT32 */
(1U << DUK_HBUFOBJ_ELEM_FLOAT32),
/* xxx -> DUK_HBUFOBJ_ELEM_FLOAT64 */
(1U << DUK_HBUFOBJ_ELEM_FLOAT64)
};
#endif /* !DUK_USE_PREFER_SIZE */
DUK_LOCAL duk_hbufobj *duk__hbufobj_promote_this(duk_hthread *thr) {
duk_tval *tv_dst;
duk_hbufobj *res;
duk_push_this(thr);
DUK_ASSERT(duk_is_buffer(thr, -1));
res = (duk_hbufobj *) duk_to_hobject(thr, -1);
DUK_HBUFOBJ_ASSERT_VALID(res);
DUK_DD(DUK_DDPRINT("promoted 'this' automatically to an ArrayBuffer: %!iT", duk_get_tval(thr, -1)));
tv_dst = duk_get_borrowed_this_tval(thr);
DUK_TVAL_SET_OBJECT_UPDREF(thr, tv_dst, (duk_hobject *) res);
duk_pop(thr);
return res;
}
#define DUK__BUFOBJ_FLAG_THROW (1 << 0)
#define DUK__BUFOBJ_FLAG_PROMOTE (1 << 1)
/* Shared helper. When DUK__BUFOBJ_FLAG_PROMOTE is given, the return value is
* always a duk_hbufobj *. Without the flag the return value can also be a
* plain buffer, and the caller must check for it using DUK_HEAPHDR_IS_BUFFER().
*/
DUK_LOCAL duk_heaphdr *duk__getrequire_bufobj_this(duk_hthread *thr, duk_small_uint_t flags) {
duk_tval *tv;
duk_hbufobj *h_this;
DUK_ASSERT(thr != NULL);
tv = duk_get_borrowed_this_tval(thr);
DUK_ASSERT(tv != NULL);
if (DUK_TVAL_IS_OBJECT(tv)) {
h_this = (duk_hbufobj *) DUK_TVAL_GET_OBJECT(tv);
DUK_ASSERT(h_this != NULL);
if (DUK_HOBJECT_IS_BUFOBJ((duk_hobject *) h_this)) {
DUK_HBUFOBJ_ASSERT_VALID(h_this);
return (duk_heaphdr *) h_this;
}
} else if (DUK_TVAL_IS_BUFFER(tv)) {
if (flags & DUK__BUFOBJ_FLAG_PROMOTE) {
/* Promote a plain buffer to a Uint8Array. This is very
* inefficient but allows plain buffer to be used wherever an
* Uint8Array is used with very small cost; hot path functions
* like index read/write calls should provide direct buffer
* support to avoid promotion.
*/
/* XXX: make this conditional to a flag if call sites need it? */
h_this = duk__hbufobj_promote_this(thr);
DUK_ASSERT(h_this != NULL);
DUK_HBUFOBJ_ASSERT_VALID(h_this);
return (duk_heaphdr *) h_this;
} else {
/* XXX: ugly, share return pointer for duk_hbuffer. */
return (duk_heaphdr *) DUK_TVAL_GET_BUFFER(tv);
}
}
if (flags & DUK__BUFOBJ_FLAG_THROW) {
DUK_ERROR_TYPE(thr, DUK_STR_NOT_BUFFER);
DUK_WO_NORETURN(return NULL;);
}
return NULL;
}
/* Check that 'this' is a duk_hbufobj and return a pointer to it. */
DUK_LOCAL duk_hbufobj *duk__get_bufobj_this(duk_hthread *thr) {
return (duk_hbufobj *) duk__getrequire_bufobj_this(thr, DUK__BUFOBJ_FLAG_PROMOTE);
}
/* Check that 'this' is a duk_hbufobj and return a pointer to it
* (NULL if not).
*/
DUK_LOCAL duk_hbufobj *duk__require_bufobj_this(duk_hthread *thr) {
return (duk_hbufobj *) duk__getrequire_bufobj_this(thr, DUK__BUFOBJ_FLAG_THROW | DUK__BUFOBJ_FLAG_PROMOTE);
}
/* Check that value is a duk_hbufobj and return a pointer to it. */
DUK_LOCAL duk_hbufobj *duk__require_bufobj_value(duk_hthread *thr, duk_idx_t idx) {
duk_tval *tv;
duk_hbufobj *h_obj;
/* Don't accept relative indices now. */
DUK_ASSERT(idx >= 0);
tv = duk_require_tval(thr, idx);
DUK_ASSERT(tv != NULL);
if (DUK_TVAL_IS_OBJECT(tv)) {
h_obj = (duk_hbufobj *) DUK_TVAL_GET_OBJECT(tv);
DUK_ASSERT(h_obj != NULL);
if (DUK_HOBJECT_IS_BUFOBJ((duk_hobject *) h_obj)) {
DUK_HBUFOBJ_ASSERT_VALID(h_obj);
return h_obj;
}
} else if (DUK_TVAL_IS_BUFFER(tv)) {
h_obj = (duk_hbufobj *) duk_to_hobject(thr, idx);
DUK_ASSERT(h_obj != NULL);
DUK_HBUFOBJ_ASSERT_VALID(h_obj);
return h_obj;
}
DUK_ERROR_TYPE(thr, DUK_STR_NOT_BUFFER);
DUK_WO_NORETURN(return NULL;);
}
DUK_LOCAL void duk__set_bufobj_buffer(duk_hthread *thr, duk_hbufobj *h_bufobj, duk_hbuffer *h_val) {
DUK_ASSERT(thr != NULL);
DUK_ASSERT(h_bufobj != NULL);
DUK_ASSERT(h_bufobj->buf == NULL); /* no need to decref */
DUK_ASSERT(h_val != NULL);
DUK_HBUFOBJ_ASSERT_VALID(h_bufobj);
DUK_UNREF(thr);
h_bufobj->buf = h_val;
DUK_HBUFFER_INCREF(thr, h_val);
h_bufobj->length = (duk_uint_t) DUK_HBUFFER_GET_SIZE(h_val);
DUK_ASSERT(h_bufobj->shift == 0);
DUK_ASSERT(h_bufobj->elem_type == DUK_HBUFOBJ_ELEM_UINT8);
DUK_ASSERT(h_bufobj->is_typedarray == 0);
DUK_HBUFOBJ_ASSERT_VALID(h_bufobj);
}
/* Shared offset/length coercion helper. */
DUK_LOCAL void duk__resolve_offset_opt_length(duk_hthread *thr,
duk_hbufobj *h_bufarg,
duk_idx_t idx_offset,
duk_idx_t idx_length,
duk_uint_t *out_offset,
duk_uint_t *out_length,
duk_bool_t throw_flag) {
duk_int_t offset_signed;
duk_int_t length_signed;
duk_uint_t offset;
duk_uint_t length;
offset_signed = duk_to_int(thr, idx_offset);
if (offset_signed < 0) {
goto fail_range;
}
offset = (duk_uint_t) offset_signed;
if (offset > h_bufarg->length) {
goto fail_range;
}
DUK_ASSERT_DISABLE(offset >= 0); /* unsigned */
DUK_ASSERT(offset <= h_bufarg->length);
if (duk_is_undefined(thr, idx_length)) {
DUK_ASSERT(h_bufarg->length >= offset);
length = h_bufarg->length - offset; /* >= 0 */
} else {
length_signed = duk_to_int(thr, idx_length);
if (length_signed < 0) {
goto fail_range;
}
length = (duk_uint_t) length_signed;
DUK_ASSERT(h_bufarg->length >= offset);
if (length > h_bufarg->length - offset) {
/* Unlike for negative arguments, some call sites
* want length to be clamped if it's positive.
*/
if (throw_flag) {
goto fail_range;
} else {
length = h_bufarg->length - offset;
}
}
}
DUK_ASSERT_DISABLE(length >= 0); /* unsigned */
DUK_ASSERT(offset + length <= h_bufarg->length);
*out_offset = offset;
*out_length = length;
return;
fail_range:
DUK_ERROR_RANGE(thr, DUK_STR_INVALID_ARGS);
DUK_WO_NORETURN(return;);
}
/* Shared lenient buffer length clamping helper. No negative indices, no
* element/byte shifting.
*/
DUK_LOCAL void duk__clamp_startend_nonegidx_noshift(duk_hthread *thr,
duk_int_t buffer_length,
duk_idx_t idx_start,
duk_idx_t idx_end,
duk_int_t *out_start_offset,
duk_int_t *out_end_offset) {
duk_int_t start_offset;
duk_int_t end_offset;
DUK_ASSERT(out_start_offset != NULL);
DUK_ASSERT(out_end_offset != NULL);
/* undefined coerces to zero which is correct */
start_offset = duk_to_int_clamped(thr, idx_start, 0, buffer_length);
if (duk_is_undefined(thr, idx_end)) {
end_offset = buffer_length;
} else {
end_offset = duk_to_int_clamped(thr, idx_end, start_offset, buffer_length);
}
DUK_ASSERT(start_offset >= 0);
DUK_ASSERT(start_offset <= buffer_length);
DUK_ASSERT(end_offset >= 0);
DUK_ASSERT(end_offset <= buffer_length);
DUK_ASSERT(start_offset <= end_offset);
*out_start_offset = start_offset;
*out_end_offset = end_offset;
}
/* Shared lenient buffer length clamping helper. Indices are treated as
* element indices (though output values are byte offsets) which only
* really matters for TypedArray views as other buffer object have a zero
* shift. Negative indices are counted from end of input slice; crossed
* indices are clamped to zero length; and final indices are clamped
* against input slice. Used for e.g. ArrayBuffer slice().
*/
DUK_LOCAL void duk__clamp_startend_negidx_shifted(duk_hthread *thr,
duk_int_t buffer_length,
duk_uint8_t buffer_shift,
duk_idx_t idx_start,
duk_idx_t idx_end,
duk_int_t *out_start_offset,
duk_int_t *out_end_offset) {
duk_int_t start_offset;
duk_int_t end_offset;
DUK_ASSERT(out_start_offset != NULL);
DUK_ASSERT(out_end_offset != NULL);
buffer_length >>= buffer_shift; /* as (full) elements */
/* Resolve start/end offset as element indices first; arguments
* at idx_start/idx_end are element offsets. Working with element
* indices first also avoids potential for wrapping.
*/
start_offset = duk_to_int(thr, idx_start);
if (start_offset < 0) {
start_offset = buffer_length + start_offset;
}
if (duk_is_undefined(thr, idx_end)) {
end_offset = buffer_length;
} else {
end_offset = duk_to_int(thr, idx_end);
if (end_offset < 0) {
end_offset = buffer_length + end_offset;
}
}
/* Note: start_offset/end_offset can still be < 0 here. */
if (start_offset < 0) {
start_offset = 0;
} else if (start_offset > buffer_length) {
start_offset = buffer_length;
}
if (end_offset < start_offset) {
end_offset = start_offset;
} else if (end_offset > buffer_length) {
end_offset = buffer_length;
}
DUK_ASSERT(start_offset >= 0);
DUK_ASSERT(start_offset <= buffer_length);
DUK_ASSERT(end_offset >= 0);
DUK_ASSERT(end_offset <= buffer_length);
DUK_ASSERT(start_offset <= end_offset);
/* Convert indices to byte offsets. */
start_offset <<= buffer_shift;
end_offset <<= buffer_shift;
*out_start_offset = start_offset;
*out_end_offset = end_offset;
}
DUK_INTERNAL void duk_hbufobj_promote_plain(duk_hthread *thr, duk_idx_t idx) {
if (duk_is_buffer(thr, idx)) {
duk_to_object(thr, idx);
}
}
DUK_INTERNAL void duk_hbufobj_push_uint8array_from_plain(duk_hthread *thr, duk_hbuffer *h_buf) {
/* Push Uint8Array which will share the same underlying buffer as
* the plain buffer argument. Also create an ArrayBuffer with the
* same backing for the result .buffer property.
*/
duk_push_hbuffer(thr, h_buf);
duk_push_buffer_object(thr, -1, 0, (duk_size_t) DUK_HBUFFER_GET_SIZE(h_buf), DUK_BUFOBJ_UINT8ARRAY);
duk_remove_m2(thr);
#if 0
/* More verbose equivalent; maybe useful if e.g. .buffer is omitted. */
h_bufobj = duk_push_bufobj_raw(thr,
DUK_HOBJECT_FLAG_EXTENSIBLE |
DUK_HOBJECT_FLAG_BUFOBJ |
DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_UINT8ARRAY),
DUK_BIDX_UINT8ARRAY_PROTOTYPE);
DUK_ASSERT(h_bufobj != NULL);
duk__set_bufobj_buffer(thr, h_bufobj, h_buf);
h_bufobj->is_typedarray = 1;
DUK_HBUFOBJ_ASSERT_VALID(h_bufobj);
h_arrbuf = duk_push_bufobj_raw(thr,
DUK_HOBJECT_FLAG_EXTENSIBLE |
DUK_HOBJECT_FLAG_BUFOBJ |
DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_ARRAYBUFFER),
DUK_BIDX_ARRAYBUFFER_PROTOTYPE);
DUK_ASSERT(h_arrbuf != NULL);
duk__set_bufobj_buffer(thr, h_arrbuf, h_buf);
DUK_ASSERT(h_arrbuf->is_typedarray == 0);
DUK_HBUFOBJ_ASSERT_VALID(h_arrbuf);
DUK_ASSERT(h_bufobj->buf_prop == NULL);
h_bufobj->buf_prop = (duk_hobject *) h_arrbuf;
DUK_ASSERT(h_arrbuf != NULL);
DUK_HBUFOBJ_INCREF(thr, h_arrbuf);
duk_pop(thr);
#endif
}
/* Indexed read helper for buffer objects, also called from outside this file. */
DUK_INTERNAL void duk_hbufobj_push_validated_read(duk_hthread *thr,
duk_hbufobj *h_bufobj,
duk_uint8_t *p,
duk_small_uint_t elem_size) {
duk_double_union du;
DUK_ASSERT(elem_size > 0);
duk_memcpy((void *) du.uc, (const void *) p, (size_t) elem_size);
switch (h_bufobj->elem_type) {
case DUK_HBUFOBJ_ELEM_UINT8:
case DUK_HBUFOBJ_ELEM_UINT8CLAMPED:
duk_push_uint(thr, (duk_uint_t) du.uc[0]);
break;
case DUK_HBUFOBJ_ELEM_INT8:
duk_push_int(thr, (duk_int_t) (duk_int8_t) du.uc[0]);
break;
case DUK_HBUFOBJ_ELEM_UINT16:
duk_push_uint(thr, (duk_uint_t) du.us[0]);
break;
case DUK_HBUFOBJ_ELEM_INT16:
duk_push_int(thr, (duk_int_t) (duk_int16_t) du.us[0]);
break;
case DUK_HBUFOBJ_ELEM_UINT32:
duk_push_uint(thr, (duk_uint_t) du.ui[0]);
break;
case DUK_HBUFOBJ_ELEM_INT32:
duk_push_int(thr, (duk_int_t) (duk_int32_t) du.ui[0]);
break;
case DUK_HBUFOBJ_ELEM_FLOAT32:
duk_push_number(thr, (duk_double_t) du.f[0]);
break;
case DUK_HBUFOBJ_ELEM_FLOAT64:
duk_push_number(thr, (duk_double_t) du.d);
break;
default:
DUK_UNREACHABLE();
}
}
/* Indexed write helper for buffer objects, also called from outside this file. */
DUK_INTERNAL void duk_hbufobj_validated_write(duk_hthread *thr, duk_hbufobj *h_bufobj, duk_uint8_t *p, duk_small_uint_t elem_size) {
duk_double_union du;
/* NOTE! Caller must ensure that any side effects from the
* coercions below are safe. If that cannot be guaranteed
* (which is normally the case), caller must coerce the
* argument using duk_to_number() before any pointer
* validations; the result of duk_to_number() always coerces
* without side effects here.
*/
switch (h_bufobj->elem_type) {
case DUK_HBUFOBJ_ELEM_UINT8:
du.uc[0] = (duk_uint8_t) duk_to_uint32(thr, -1);
break;
case DUK_HBUFOBJ_ELEM_UINT8CLAMPED:
du.uc[0] = (duk_uint8_t) duk_to_uint8clamped(thr, -1);
break;
case DUK_HBUFOBJ_ELEM_INT8:
du.uc[0] = (duk_uint8_t) duk_to_int32(thr, -1);
break;
case DUK_HBUFOBJ_ELEM_UINT16:
du.us[0] = (duk_uint16_t) duk_to_uint32(thr, -1);
break;
case DUK_HBUFOBJ_ELEM_INT16:
du.us[0] = (duk_uint16_t) duk_to_int32(thr, -1);
break;
case DUK_HBUFOBJ_ELEM_UINT32:
du.ui[0] = (duk_uint32_t) duk_to_uint32(thr, -1);
break;
case DUK_HBUFOBJ_ELEM_INT32:
du.ui[0] = (duk_uint32_t) duk_to_int32(thr, -1);
break;
case DUK_HBUFOBJ_ELEM_FLOAT32:
/* A double-to-float cast is undefined behavior in C99 if
* the cast is out-of-range, so use a helper. Example:
* runtime error: value -1e+100 is outside the range of representable values of type 'float'
*/
du.f[0] = duk_double_to_float_t(duk_to_number_m1(thr));
break;
case DUK_HBUFOBJ_ELEM_FLOAT64:
du.d = (duk_double_t) duk_to_number_m1(thr);
break;
default:
DUK_UNREACHABLE();
}
DUK_ASSERT(elem_size > 0);
duk_memcpy((void *) p, (const void *) du.uc, (size_t) elem_size);
}
/* Helper to create a fixed buffer from argument value at index 0.
* Node.js and allocPlain() compatible.
*/
DUK_LOCAL duk_hbuffer *duk__hbufobj_fixed_from_argvalue(duk_hthread *thr) {
duk_int_t len;
duk_int_t i;
duk_size_t buf_size;
duk_uint8_t *buf;
switch (duk_get_type(thr, 0)) {
case DUK_TYPE_NUMBER: {
len = duk_to_int_clamped(thr, 0, 0, DUK_INT_MAX);
(void) duk_push_fixed_buffer_zero(thr, (duk_size_t) len);
break;
}
case DUK_TYPE_BUFFER: { /* Treat like Uint8Array. */
goto slow_copy;
}
case DUK_TYPE_OBJECT: {
duk_hobject *h;
duk_hbufobj *h_bufobj;
/* For Node.js Buffers "Passing an ArrayBuffer returns a Buffer
* that shares allocated memory with the given ArrayBuffer."
* https://nodejs.org/api/buffer.html#buffer_buffer_from_buffer_alloc_and_buffer_allocunsafe
*/
h = duk_known_hobject(thr, 0);
if (DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_ARRAYBUFFER) {
DUK_ASSERT(DUK_HOBJECT_IS_BUFOBJ(h));
h_bufobj = (duk_hbufobj *) h;
if (DUK_UNLIKELY(h_bufobj->buf == NULL)) {
DUK_ERROR_TYPE_INVALID_ARGS(thr);
DUK_WO_NORETURN(return NULL;);
}
if (DUK_UNLIKELY(h_bufobj->offset != 0 || h_bufobj->length != DUK_HBUFFER_GET_SIZE(h_bufobj->buf))) {
/* No support for ArrayBuffers with slice
* offset/length.
*/
DUK_ERROR_TYPE_INVALID_ARGS(thr);
DUK_WO_NORETURN(return NULL;);
}
duk_push_hbuffer(thr, h_bufobj->buf);
return h_bufobj->buf;
}
goto slow_copy;
}
case DUK_TYPE_STRING: {
/* ignore encoding for now */
duk_require_hstring_notsymbol(thr, 0);
duk_dup_0(thr);
(void) duk_to_buffer(thr, -1, &buf_size);
break;
}
default:
DUK_ERROR_TYPE_INVALID_ARGS(thr);
DUK_WO_NORETURN(return NULL;);
}
done:
DUK_ASSERT(duk_is_buffer(thr, -1));
return duk_known_hbuffer(thr, -1);
slow_copy:
/* XXX: fast path for typed arrays and other buffer objects? */
(void) duk_get_prop_stridx_short(thr, 0, DUK_STRIDX_LENGTH);
len = duk_to_int_clamped(thr, -1, 0, DUK_INT_MAX);
duk_pop(thr);
buf = (duk_uint8_t *) duk_push_fixed_buffer_nozero(thr, (duk_size_t) len); /* no zeroing, all indices get initialized */
for (i = 0; i < len; i++) {
/* XXX: fast path for array or buffer arguments? */
duk_get_prop_index(thr, 0, (duk_uarridx_t) i);
buf[i] = (duk_uint8_t) (duk_to_uint32(thr, -1) & 0xffU);
duk_pop(thr);
}
goto done;
}
#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */
/*
* Node.js Buffer constructor
*
* Node.js Buffers are just Uint8Arrays with internal prototype set to
* Buffer.prototype so they're handled otherwise the same as Uint8Array.
* However, the constructor arguments are very different so a separate
* constructor entry point is used.
*/
#if defined(DUK_USE_BUFFEROBJECT_SUPPORT)
DUK_INTERNAL duk_ret_t duk_bi_nodejs_buffer_constructor(duk_hthread *thr) {
duk_hbuffer *h_buf;
h_buf = duk__hbufobj_fixed_from_argvalue(thr);
DUK_ASSERT(h_buf != NULL);
duk_push_buffer_object(thr, -1, 0, DUK_HBUFFER_FIXED_GET_SIZE((duk_hbuffer_fixed *) (void *) h_buf), DUK_BUFOBJ_UINT8ARRAY);
duk_push_hobject_bidx(thr, DUK_BIDX_NODEJS_BUFFER_PROTOTYPE);
duk_set_prototype(thr, -2);
/* XXX: a more direct implementation */
return 1;
}
#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */
/*
* ArrayBuffer, DataView, and TypedArray constructors
*/
#if defined(DUK_USE_BUFFEROBJECT_SUPPORT)
DUK_INTERNAL duk_ret_t duk_bi_arraybuffer_constructor(duk_hthread *thr) {
duk_hbufobj *h_bufobj;
duk_hbuffer *h_val;
duk_int_t len;
DUK_CTX_ASSERT_VALID(thr);
duk_require_constructor_call(thr);
len = duk_to_int(thr, 0);
if (len < 0) {
goto fail_length;
}
(void) duk_push_fixed_buffer_zero(thr, (duk_size_t) len);
h_val = (duk_hbuffer *) duk_known_hbuffer(thr, -1);
h_bufobj = duk_push_bufobj_raw(thr,
DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_BUFOBJ |
DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_ARRAYBUFFER),
DUK_BIDX_ARRAYBUFFER_PROTOTYPE);
DUK_ASSERT(h_bufobj != NULL);
duk__set_bufobj_buffer(thr, h_bufobj, h_val);
DUK_HBUFOBJ_ASSERT_VALID(h_bufobj);
return 1;
fail_length:
DUK_DCERROR_RANGE_INVALID_LENGTH(thr);
}
#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */
/* Format of magic, bits:
* 0...1: elem size shift (0-3)
* 2...5: elem type (DUK_HBUFOBJ_ELEM_xxx)
*
* XXX: add prototype bidx explicitly to magic instead of using a mapping?
*/
#if defined(DUK_USE_BUFFEROBJECT_SUPPORT)
DUK_INTERNAL duk_ret_t duk_bi_typedarray_constructor(duk_hthread *thr) {
duk_tval *tv;
duk_hobject *h_obj;
duk_hbufobj *h_bufobj = NULL;
duk_hbufobj *h_bufarg = NULL;
duk_hbuffer *h_val;
duk_small_uint_t magic;
duk_small_uint_t shift;
duk_small_uint_t elem_type;
duk_small_uint_t elem_size;
duk_small_uint_t class_num;
duk_small_uint_t proto_bidx;
duk_uint_t align_mask;
duk_uint_t elem_length;
duk_int_t elem_length_signed;
duk_uint_t byte_length;
duk_small_uint_t copy_mode;
/* XXX: The same copy helpers could be shared with at least some
* buffer functions.
*/
duk_require_constructor_call(thr);
/* We could fit built-in index into magic but that'd make the magic
* number dependent on built-in numbering (genbuiltins.py doesn't
* handle that yet). So map both class and prototype from the
* element type.
*/
magic = (duk_small_uint_t) duk_get_current_magic(thr);
shift = magic & 0x03U; /* bits 0...1: shift */
elem_type = (magic >> 2) & 0x0fU; /* bits 2...5: type */
elem_size = 1U << shift;
align_mask = elem_size - 1;
DUK_ASSERT(elem_type < sizeof(duk__buffer_proto_from_elemtype) / sizeof(duk_uint8_t));
proto_bidx = duk__buffer_proto_from_elemtype[elem_type];
DUK_ASSERT(proto_bidx < DUK_NUM_BUILTINS);
DUK_ASSERT(elem_type < sizeof(duk__buffer_class_from_elemtype) / sizeof(duk_uint8_t));
class_num = duk__buffer_class_from_elemtype[elem_type];
DUK_DD(DUK_DDPRINT("typedarray constructor, magic=%d, shift=%d, elem_type=%d, "
"elem_size=%d, proto_bidx=%d, class_num=%d",
(int) magic,
(int) shift,
(int) elem_type,
(int) elem_size,
(int) proto_bidx,
(int) class_num));
/* Argument variants. When the argument is an ArrayBuffer a view to
* the same buffer is created; otherwise a new ArrayBuffer is always
* created.
*/
/* XXX: initial iteration to treat a plain buffer like an ArrayBuffer:
* coerce to an ArrayBuffer object and use that as .buffer. The underlying
* buffer will be the same but result .buffer !== inputPlainBuffer.
*/
duk_hbufobj_promote_plain(thr, 0);
tv = duk_get_tval(thr, 0);
DUK_ASSERT(tv != NULL); /* arg count */
if (DUK_TVAL_IS_OBJECT(tv)) {
h_obj = DUK_TVAL_GET_OBJECT(tv);
DUK_ASSERT(h_obj != NULL);
if (DUK_HOBJECT_GET_CLASS_NUMBER(h_obj) == DUK_HOBJECT_CLASS_ARRAYBUFFER) {
/* ArrayBuffer: unlike any other argument variant, create
* a view into the existing buffer.
*/
duk_int_t byte_offset_signed;
duk_uint_t byte_offset;
h_bufarg = (duk_hbufobj *) h_obj;
byte_offset_signed = duk_to_int(thr, 1);
if (byte_offset_signed < 0) {
goto fail_arguments;
}
byte_offset = (duk_uint_t) byte_offset_signed;
if (byte_offset > h_bufarg->length || (byte_offset & align_mask) != 0) {
/* Must be >= 0 and multiple of element size. */
goto fail_arguments;
}
if (duk_is_undefined(thr, 2)) {
DUK_ASSERT(h_bufarg->length >= byte_offset);
byte_length = h_bufarg->length - byte_offset;
if ((byte_length & align_mask) != 0) {
/* Must be element size multiple from
* start offset to end of buffer.
*/
goto fail_arguments;
}
elem_length = (byte_length >> shift);
} else {
elem_length_signed = duk_to_int(thr, 2);
if (elem_length_signed < 0) {
goto fail_arguments;
}
elem_length = (duk_uint_t) elem_length_signed;
byte_length = elem_length << shift;
if ((byte_length >> shift) != elem_length) {
/* Byte length would overflow. */
/* XXX: easier check with less code? */
goto fail_arguments;
}
DUK_ASSERT(h_bufarg->length >= byte_offset);
if (byte_length > h_bufarg->length - byte_offset) {
/* Not enough data. */
goto fail_arguments;
}
}
DUK_UNREF(elem_length);
DUK_ASSERT_DISABLE(byte_offset >= 0);
DUK_ASSERT(byte_offset <= h_bufarg->length);
DUK_ASSERT_DISABLE(byte_length >= 0);
DUK_ASSERT(byte_offset + byte_length <= h_bufarg->length);
DUK_ASSERT((elem_length << shift) == byte_length);
h_bufobj = duk_push_bufobj_raw(thr,
DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_BUFOBJ |
DUK_HOBJECT_CLASS_AS_FLAGS(class_num),
(duk_small_int_t) proto_bidx);
h_val = h_bufarg->buf;
if (h_val == NULL) {
DUK_DCERROR_TYPE_INVALID_ARGS(thr);
}
h_bufobj->buf = h_val;
DUK_HBUFFER_INCREF(thr, h_val);
h_bufobj->offset = h_bufarg->offset + byte_offset;
h_bufobj->length = byte_length;
h_bufobj->shift = (duk_uint8_t) shift;
h_bufobj->elem_type = (duk_uint8_t) elem_type;
h_bufobj->is_typedarray = 1;
DUK_HBUFOBJ_ASSERT_VALID(h_bufobj);
/* Set .buffer to the argument ArrayBuffer. */
DUK_ASSERT(h_bufobj->buf_prop == NULL);
h_bufobj->buf_prop = (duk_hobject *) h_bufarg;
DUK_ASSERT(h_bufarg != NULL);
DUK_HBUFOBJ_INCREF(thr, h_bufarg);
return 1;
} else if (DUK_HOBJECT_IS_BUFOBJ(h_obj)) {
/* TypedArray (or other non-ArrayBuffer duk_hbufobj).
* Conceptually same behavior as for an Array-like argument,
* with a few fast paths.
*/
h_bufarg = (duk_hbufobj *) h_obj;
DUK_HBUFOBJ_ASSERT_VALID(h_bufarg);
elem_length_signed = (duk_int_t) (h_bufarg->length >> h_bufarg->shift);
if (h_bufarg->buf == NULL) {
DUK_DCERROR_TYPE_INVALID_ARGS(thr);
}
/* Select copy mode. Must take into account element
* compatibility and validity of the underlying source
* buffer.
*/
DUK_DDD(DUK_DDDPRINT("selecting copy mode for bufobj arg, "
"src byte_length=%ld, src shift=%d, "
"src/dst elem_length=%ld; "
"dst shift=%d -> dst byte_length=%ld",
(long) h_bufarg->length,
(int) h_bufarg->shift,
(long) elem_length_signed,
(int) shift,
(long) (elem_length_signed << shift)));
copy_mode = 2; /* default is explicit index read/write copy */
#if !defined(DUK_USE_PREFER_SIZE)
/* With a size optimized build copy_mode 2 is enough.
* Modes 0 and 1 are faster but conceptually the same.
*/
DUK_ASSERT(elem_type < sizeof(duk__buffer_elemtype_copy_compatible) / sizeof(duk_uint16_t));
if (DUK_HBUFOBJ_VALID_SLICE(h_bufarg)) {
if ((duk__buffer_elemtype_copy_compatible[elem_type] & (1 << h_bufarg->elem_type)) != 0) {
DUK_DDD(DUK_DDDPRINT("source/target are copy compatible, memcpy"));
DUK_ASSERT(shift == h_bufarg->shift); /* byte sizes will match */
copy_mode = 0;
} else {
DUK_DDD(DUK_DDDPRINT("source/target not copy compatible but valid, fast copy"));
copy_mode = 1;
}
}
#endif /* !DUK_USE_PREFER_SIZE */
} else {
/* Array or Array-like */
elem_length_signed = (duk_int_t) duk_get_length(thr, 0);
copy_mode = 2;
}
} else {
/* Non-object argument is simply int coerced, matches
* V8 behavior (except for "null", which we coerce to
* 0 but V8 TypeErrors).
*/
elem_length_signed = duk_to_int(thr, 0);
copy_mode = 3;
}
if (elem_length_signed < 0) {
goto fail_arguments;
}
elem_length = (duk_uint_t) elem_length_signed;
byte_length = (duk_uint_t) (elem_length << shift);
if ((byte_length >> shift) != elem_length) {
/* Byte length would overflow. */
/* XXX: easier check with less code? */
goto fail_arguments;
}
DUK_DDD(DUK_DDDPRINT("elem_length=%ld, byte_length=%ld", (long) elem_length, (long) byte_length));
/* ArrayBuffer argument is handled specially above; the rest of the
* argument variants are handled by shared code below.
*
* ArrayBuffer in h_bufobj->buf_prop is intentionally left unset.
* It will be automatically created by the .buffer accessor on
* first access.
*/
/* Push the resulting view object on top of a plain fixed buffer. */
(void) duk_push_fixed_buffer(thr, byte_length);
h_val = duk_known_hbuffer(thr, -1);
DUK_ASSERT(h_val != NULL);
h_bufobj =
duk_push_bufobj_raw(thr,
DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_BUFOBJ | DUK_HOBJECT_CLASS_AS_FLAGS(class_num),
(duk_small_int_t) proto_bidx);
h_bufobj->buf = h_val;
DUK_HBUFFER_INCREF(thr, h_val);
DUK_ASSERT(h_bufobj->offset == 0);
h_bufobj->length = byte_length;
h_bufobj->shift = (duk_uint8_t) shift;
h_bufobj->elem_type = (duk_uint8_t) elem_type;
h_bufobj->is_typedarray = 1;
DUK_HBUFOBJ_ASSERT_VALID(h_bufobj);
/* Copy values, the copy method depends on the arguments.
*
* Copy mode decision may depend on the validity of the underlying
* buffer of the source argument; there must be no harmful side effects
* from there to here for copy_mode to still be valid.
*/
DUK_DDD(DUK_DDDPRINT("copy mode: %d", (int) copy_mode));
switch (copy_mode) {
/* Copy modes 0 and 1 can be omitted in size optimized build,
* copy mode 2 handles them (but more slowly).
*/
#if !defined(DUK_USE_PREFER_SIZE)
case 0: {
/* Use byte copy. */
duk_uint8_t *p_src;
duk_uint8_t *p_dst;
DUK_ASSERT(h_bufobj != NULL);
DUK_ASSERT(h_bufobj->buf != NULL);
DUK_ASSERT(DUK_HBUFOBJ_VALID_SLICE(h_bufobj));
DUK_ASSERT(h_bufarg != NULL);
DUK_ASSERT(h_bufarg->buf != NULL);
DUK_ASSERT(DUK_HBUFOBJ_VALID_SLICE(h_bufarg));
p_dst = DUK_HBUFOBJ_GET_SLICE_BASE(thr->heap, h_bufobj);
p_src = DUK_HBUFOBJ_GET_SLICE_BASE(thr->heap, h_bufarg);
DUK_DDD(DUK_DDDPRINT("using memcpy: p_src=%p, p_dst=%p, byte_length=%ld",
(void *) p_src,
(void *) p_dst,
(long) byte_length));
duk_memcpy_unsafe((void *) p_dst, (const void *) p_src, (size_t) byte_length);
break;
}
case 1: {
/* Copy values through direct validated reads and writes. */
duk_small_uint_t src_elem_size;
duk_small_uint_t dst_elem_size;
duk_uint8_t *p_src;
duk_uint8_t *p_src_end;
duk_uint8_t *p_dst;
DUK_ASSERT(h_bufobj != NULL);
DUK_ASSERT(h_bufobj->buf != NULL);
DUK_ASSERT(DUK_HBUFOBJ_VALID_SLICE(h_bufobj));
DUK_ASSERT(h_bufarg != NULL);
DUK_ASSERT(h_bufarg->buf != NULL);
DUK_ASSERT(DUK_HBUFOBJ_VALID_SLICE(h_bufarg));
src_elem_size = (duk_small_uint_t) (1U << h_bufarg->shift);
dst_elem_size = elem_size;
p_src = DUK_HBUFOBJ_GET_SLICE_BASE(thr->heap, h_bufarg);
p_dst = DUK_HBUFOBJ_GET_SLICE_BASE(thr->heap, h_bufobj);
p_src_end = p_src + h_bufarg->length;
DUK_DDD(DUK_DDDPRINT("using fast copy: p_src=%p, p_src_end=%p, p_dst=%p, "
"src_elem_size=%d, dst_elem_size=%d",
(void *) p_src,
(void *) p_src_end,
(void *) p_dst,
(int) src_elem_size,
(int) dst_elem_size));
while (p_src != p_src_end) {
DUK_DDD(DUK_DDDPRINT("fast path per element copy loop: "
"p_src=%p, p_src_end=%p, p_dst=%p",
(void *) p_src,
(void *) p_src_end,
(void *) p_dst));
/* A validated read() is always a number, so it's write coercion
* is always side effect free an won't invalidate pointers etc.
*/
duk_hbufobj_push_validated_read(thr, h_bufarg, p_src, src_elem_size);
duk_hbufobj_validated_write(thr, h_bufobj, p_dst, dst_elem_size);
duk_pop(thr);
p_src += src_elem_size;
p_dst += dst_elem_size;
}
break;
}
#endif /* !DUK_USE_PREFER_SIZE */
case 2: {
/* Copy values by index reads and writes. Let virtual
* property handling take care of coercion.
*/
duk_uint_t i;
DUK_DDD(DUK_DDDPRINT("using slow copy"));
for (i = 0; i < elem_length; i++) {
duk_get_prop_index(thr, 0, (duk_uarridx_t) i);
duk_put_prop_index(thr, -2, (duk_uarridx_t) i);
}
break;
}
default:
case 3: {
/* No copy, leave zero bytes in the buffer. There's no
* ambiguity with Float32/Float64 because zero bytes also
* represent 0.0.
*/
DUK_DDD(DUK_DDDPRINT("using no copy"));
break;
}
}
return 1;
fail_arguments:
DUK_DCERROR_RANGE_INVALID_ARGS(thr);
}
#else /* DUK_USE_BUFFEROBJECT_SUPPORT */
/* When bufferobject support is disabled, new Uint8Array() could still be
* supported to create a plain fixed buffer. Disabled for now.
*/
#if 0
DUK_INTERNAL duk_ret_t duk_bi_typedarray_constructor(duk_hthread *thr) {
duk_int_t elem_length_signed;
duk_uint_t byte_length;
/* XXX: The same copy helpers could be shared with at least some
* buffer functions.
*/
duk_require_constructor_call(thr);
elem_length_signed = duk_require_int(thr, 0);
if (elem_length_signed < 0) {
goto fail_arguments;
}
byte_length = (duk_uint_t) elem_length_signed;
(void) duk_push_fixed_buffer_zero(thr, (duk_size_t) byte_length);
return 1;
fail_arguments:
DUK_DCERROR_RANGE_INVALID_ARGS(thr);
}
#endif /* 0 */
#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */
#if defined(DUK_USE_BUFFEROBJECT_SUPPORT)
DUK_INTERNAL duk_ret_t duk_bi_dataview_constructor(duk_hthread *thr) {
duk_hbufobj *h_bufarg;
duk_hbufobj *h_bufobj;
duk_hbuffer *h_val;
duk_uint_t offset;
duk_uint_t length;
duk_require_constructor_call(thr);
h_bufarg = duk__require_bufobj_value(thr, 0);
DUK_ASSERT(h_bufarg != NULL);
if (DUK_HOBJECT_GET_CLASS_NUMBER((duk_hobject *) h_bufarg) != DUK_HOBJECT_CLASS_ARRAYBUFFER) {
DUK_DCERROR_TYPE_INVALID_ARGS(thr);
}
duk__resolve_offset_opt_length(thr, h_bufarg, 1, 2, &offset, &length, 1 /*throw_flag*/);
DUK_ASSERT(offset <= h_bufarg->length);
DUK_ASSERT(offset + length <= h_bufarg->length);
h_bufobj = duk_push_bufobj_raw(thr,
DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_BUFOBJ |
DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_DATAVIEW),
DUK_BIDX_DATAVIEW_PROTOTYPE);
h_val = h_bufarg->buf;
if (h_val == NULL) {
DUK_DCERROR_TYPE_INVALID_ARGS(thr);
}
h_bufobj->buf = h_val;
DUK_HBUFFER_INCREF(thr, h_val);
h_bufobj->offset = h_bufarg->offset + offset;
h_bufobj->length = length;
DUK_ASSERT(h_bufobj->shift == 0);
DUK_ASSERT(h_bufobj->elem_type == DUK_HBUFOBJ_ELEM_UINT8);
DUK_ASSERT(h_bufobj->is_typedarray == 0);
DUK_ASSERT(h_bufobj->buf_prop == NULL);
h_bufobj->buf_prop = (duk_hobject *) h_bufarg;
DUK_ASSERT(h_bufarg != NULL);
DUK_HBUFOBJ_INCREF(thr, h_bufarg);
DUK_HBUFOBJ_ASSERT_VALID(h_bufobj);
return 1;
}
#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */
/*
* ArrayBuffer.isView()
*/
#if defined(DUK_USE_BUFFEROBJECT_SUPPORT)
DUK_INTERNAL duk_ret_t duk_bi_arraybuffer_isview(duk_hthread *thr) {
duk_hobject *h_obj;
duk_bool_t ret = 0;
if (duk_is_buffer(thr, 0)) {
ret = 1;
} else {
h_obj = duk_get_hobject(thr, 0);
if (h_obj != NULL && DUK_HOBJECT_IS_BUFOBJ(h_obj)) {
/* DataView needs special casing: ArrayBuffer.isView() is
* true, but ->is_typedarray is 0.
*/
ret = ((duk_hbufobj *) h_obj)->is_typedarray ||
(DUK_HOBJECT_GET_CLASS_NUMBER(h_obj) == DUK_HOBJECT_CLASS_DATAVIEW);
}
}
duk_push_boolean(thr, ret);
return 1;
}
#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */
/*
* Uint8Array.allocPlain()
*/
#if defined(DUK_USE_BUFFEROBJECT_SUPPORT)
DUK_INTERNAL duk_ret_t duk_bi_uint8array_allocplain(duk_hthread *thr) {
duk__hbufobj_fixed_from_argvalue(thr);
return 1;
}
#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */
/*
* Uint8Array.plainOf()
*/
#if defined(DUK_USE_BUFFEROBJECT_SUPPORT)
DUK_INTERNAL duk_ret_t duk_bi_uint8array_plainof(duk_hthread *thr) {
duk_hbufobj *h_bufobj;
#if !defined(DUK_USE_PREFER_SIZE)
/* Avoid churn if argument is already a plain buffer. */
if (duk_is_buffer(thr, 0)) {
return 1;
}
#endif
/* Promotes plain buffers to ArrayBuffers, so for a plain buffer
* argument we'll create a pointless temporary (but still work
* correctly).
*/
h_bufobj = duk__require_bufobj_value(thr, 0);
if (h_bufobj->buf == NULL) {
duk_push_undefined(thr);
} else {
duk_push_hbuffer(thr, h_bufobj->buf);
}
return 1;
}
#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */
/*
* Node.js Buffer: toString([encoding], [start], [end])
*/
#if defined(DUK_USE_BUFFEROBJECT_SUPPORT)
DUK_INTERNAL duk_ret_t duk_bi_nodejs_buffer_tostring(duk_hthread *thr) {
duk_hbufobj *h_this;
duk_int_t start_offset, end_offset;
duk_uint8_t *buf_slice;
duk_size_t slice_length;
h_this = duk__get_bufobj_this(thr);
if (h_this == NULL) {
/* XXX: happens e.g. when evaluating: String(Buffer.prototype). */
duk_push_literal(thr, "[object Object]");
return 1;
}
DUK_HBUFOBJ_ASSERT_VALID(h_this);
/* Ignore encoding for now. */
duk__clamp_startend_nonegidx_noshift(thr,
(duk_int_t) h_this->length,
1 /*idx_start*/,
2 /*idx_end*/,
&start_offset,
&end_offset);
slice_length = (duk_size_t) (end_offset - start_offset);
buf_slice = (duk_uint8_t *) duk_push_fixed_buffer_nozero(thr, slice_length); /* all bytes initialized below */
DUK_ASSERT(buf_slice != NULL);
/* Neutered or uncovered, TypeError. */
if (h_this->buf == NULL || !DUK_HBUFOBJ_VALID_BYTEOFFSET_EXCL(h_this, (duk_size_t) start_offset + slice_length)) {
DUK_DCERROR_TYPE_INVALID_ARGS(thr);
}
/* XXX: ideally we wouldn't make a copy but a view into the buffer for the
* decoding process. Or the decoding helper could be changed to accept
* the slice info (a buffer pointer is NOT a good approach because guaranteeing
* its stability is difficult).
*/
DUK_ASSERT(DUK_HBUFOBJ_VALID_BYTEOFFSET_EXCL(h_this, (duk_size_t) start_offset + slice_length));
duk_memcpy_unsafe((void *) buf_slice,
(const void *) (DUK_HBUFOBJ_GET_SLICE_BASE(thr->heap, h_this) + start_offset),
(size_t) slice_length);
/* Use the equivalent of: new TextEncoder().encode(this) to convert the
* string. Result will be valid UTF-8; non-CESU-8 inputs are currently
* interpreted loosely. Value stack convention is a bit odd for now.
*/
duk_replace(thr, 0);
duk_set_top(thr, 1);
return duk_textdecoder_decode_utf8_nodejs(thr);
}
#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */
/*
* Node.js Buffer.prototype: toJSON()
*/
#if defined(DUK_USE_BUFFEROBJECT_SUPPORT)
DUK_INTERNAL duk_ret_t duk_bi_nodejs_buffer_tojson(duk_hthread *thr) {
duk_hbufobj *h_this;
duk_uint8_t *buf;
duk_uint_t i, n;
duk_tval *tv;
h_this = duk__require_bufobj_this(thr);
DUK_ASSERT(h_this != NULL);
if (h_this->buf == NULL || !DUK_HBUFOBJ_VALID_SLICE(h_this)) {
/* Serialize uncovered backing buffer as a null; doesn't
* really matter as long we're memory safe.
*/
duk_push_null(thr);
return 1;
}
duk_push_object(thr);
duk_push_hstring_stridx(thr, DUK_STRIDX_UC_BUFFER);
duk_put_prop_stridx_short(thr, -2, DUK_STRIDX_TYPE);
/* XXX: uninitialized would be OK */
DUK_ASSERT_DISABLE((duk_size_t) h_this->length <= (duk_size_t) DUK_UINT32_MAX);
tv = duk_push_harray_with_size_outptr(thr, (duk_uint32_t) h_this->length); /* XXX: needs revision with >4G buffers */
DUK_ASSERT(!duk_is_bare_object(thr, -1));
DUK_ASSERT(h_this->buf != NULL);
buf = DUK_HBUFOBJ_GET_SLICE_BASE(thr->heap, h_this);
for (i = 0, n = h_this->length; i < n; i++) {
DUK_TVAL_SET_U32(tv + i, (duk_uint32_t) buf[i]); /* no need for decref or incref */
}
duk_put_prop_stridx_short(thr, -2, DUK_STRIDX_DATA);
return 1;
}
#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */
/*
* Node.js Buffer.prototype.equals()
* Node.js Buffer.prototype.compare()
* Node.js Buffer.compare()
*/
#if defined(DUK_USE_BUFFEROBJECT_SUPPORT)
DUK_INTERNAL duk_ret_t duk_bi_buffer_compare_shared(duk_hthread *thr) {
duk_small_uint_t magic;
duk_hbufobj *h_bufarg1;
duk_hbufobj *h_bufarg2;
duk_small_int_t comp_res;
/* XXX: keep support for plain buffers and non-Node.js buffers? */
magic = (duk_small_uint_t) duk_get_current_magic(thr);
if (magic & 0x02U) {
/* Static call style. */
h_bufarg1 = duk__require_bufobj_value(thr, 0);
h_bufarg2 = duk__require_bufobj_value(thr, 1);
} else {
h_bufarg1 = duk__require_bufobj_this(thr);
h_bufarg2 = duk__require_bufobj_value(thr, 0);
}
DUK_ASSERT(h_bufarg1 != NULL);
DUK_ASSERT(h_bufarg2 != NULL);
/* We want to compare the slice/view areas of the arguments.
* If either slice/view is invalid (underlying buffer is shorter)
* ensure equals() is false, but otherwise the only thing that
* matters is to be memory safe.
*/
if (DUK_HBUFOBJ_VALID_SLICE(h_bufarg1) && DUK_HBUFOBJ_VALID_SLICE(h_bufarg2)) {
comp_res = duk_js_data_compare(
(const duk_uint8_t *) DUK_HBUFFER_GET_DATA_PTR(thr->heap, h_bufarg1->buf) + h_bufarg1->offset,
(const duk_uint8_t *) DUK_HBUFFER_GET_DATA_PTR(thr->heap, h_bufarg2->buf) + h_bufarg2->offset,
(duk_size_t) h_bufarg1->length,
(duk_size_t) h_bufarg2->length);
} else {
comp_res = -1; /* either nonzero value is ok */
}
if (magic & 0x01U) {
/* compare: similar to string comparison but for buffer data. */
duk_push_int(thr, comp_res);
} else {
/* equals */
duk_push_boolean(thr, (comp_res == 0));
}
return 1;
}
#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */
/*
* Node.js Buffer.prototype.fill()
*/
#if defined(DUK_USE_BUFFEROBJECT_SUPPORT)
DUK_INTERNAL duk_ret_t duk_bi_nodejs_buffer_fill(duk_hthread *thr) {
duk_hbufobj *h_this;
const duk_uint8_t *fill_str_ptr;
duk_size_t fill_str_len;
duk_uint8_t fill_value;
duk_int_t fill_offset;
duk_int_t fill_end;
duk_size_t fill_length;
duk_uint8_t *p;
h_this = duk__require_bufobj_this(thr);
DUK_ASSERT(h_this != NULL);
if (h_this->buf == NULL) {
DUK_DCERROR_TYPE_INVALID_ARGS(thr);
}
/* [ value offset end ] */
if (duk_is_string_notsymbol(thr, 0)) {
fill_str_ptr = (const duk_uint8_t *) duk_get_lstring(thr, 0, &fill_str_len);
DUK_ASSERT(fill_str_ptr != NULL);
} else {
/* Symbols get ToNumber() coerced and cause TypeError. */
fill_value = (duk_uint8_t) duk_to_uint32(thr, 0);
fill_str_ptr = (const duk_uint8_t *) &fill_value;
fill_str_len = 1;
}
/* Fill offset handling is more lenient than in Node.js. */
duk__clamp_startend_nonegidx_noshift(thr,
(duk_int_t) h_this->length,
1 /*idx_start*/,
2 /*idx_end*/,
&fill_offset,
&fill_end);
DUK_DDD(DUK_DDDPRINT("fill: fill_value=%02x, fill_offset=%ld, fill_end=%ld, view length=%ld",
(unsigned int) fill_value,
(long) fill_offset,
(long) fill_end,
(long) h_this->length));
DUK_ASSERT(fill_end - fill_offset >= 0);
DUK_ASSERT(h_this->buf != NULL);
p = (DUK_HBUFOBJ_GET_SLICE_BASE(thr->heap, h_this) + fill_offset);
fill_length = (duk_size_t) (fill_end - fill_offset);
if (fill_str_len == 1) {
/* Handle single character fills as memset() even when
* the fill data comes from a one-char argument.
*/
duk_memset_unsafe((void *) p, (int) fill_str_ptr[0], (size_t) fill_length);
} else if (fill_str_len > 1) {
duk_size_t i, n, t;
for (i = 0, n = (duk_size_t) (fill_end - fill_offset), t = 0; i < n; i++) {
p[i] = fill_str_ptr[t++];
if (t >= fill_str_len) {
t = 0;
}
}
} else {
DUK_DDD(DUK_DDDPRINT("zero size fill pattern, ignore silently"));
}
/* Return the Buffer to allow chaining: b.fill(0x11).fill(0x22, 3, 5).toString() */
duk_push_this(thr);
return 1;
}
#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */
/*
* Node.js Buffer.prototype.write(string, [offset], [length], [encoding])
*/
#if defined(DUK_USE_BUFFEROBJECT_SUPPORT)
DUK_INTERNAL duk_ret_t duk_bi_nodejs_buffer_write(duk_hthread *thr) {
duk_hbufobj *h_this;
duk_uint_t offset;
duk_uint_t length;
const duk_uint8_t *str_data;
duk_size_t str_len;
/* XXX: very inefficient support for plain buffers */
h_this = duk__require_bufobj_this(thr);
DUK_ASSERT(h_this != NULL);
/* Argument must be a string, e.g. a buffer is not allowed. */
str_data = (const duk_uint8_t *) duk_require_lstring_notsymbol(thr, 0, &str_len);
duk__resolve_offset_opt_length(thr, h_this, 1, 2, &offset, &length, 0 /*throw_flag*/);
DUK_ASSERT(offset <= h_this->length);
DUK_ASSERT(offset + length <= h_this->length);
/* XXX: encoding is ignored now. */
if (length > str_len) {
length = (duk_uint_t) str_len;
}
if (DUK_HBUFOBJ_VALID_SLICE(h_this)) {
/* Cannot overlap. */
duk_memcpy_unsafe((void *) (DUK_HBUFOBJ_GET_SLICE_BASE(thr->heap, h_this) + offset),
(const void *) str_data,
(size_t) length);
} else {
DUK_DDD(DUK_DDDPRINT("write() target buffer is not covered, silent ignore"));
}
duk_push_uint(thr, length);
return 1;
}
#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */
/*
* Node.js Buffer.prototype.copy()
*/
#if defined(DUK_USE_BUFFEROBJECT_SUPPORT)
DUK_INTERNAL duk_ret_t duk_bi_nodejs_buffer_copy(duk_hthread *thr) {
duk_hbufobj *h_this;
duk_hbufobj *h_bufarg;
duk_int_t source_length;
duk_int_t target_length;
duk_int_t target_start, source_start, source_end;
duk_uint_t target_ustart, source_ustart, source_uend;
duk_uint_t copy_size = 0;
/* [ targetBuffer targetStart sourceStart sourceEnd ] */
h_this = duk__require_bufobj_this(thr);
h_bufarg = duk__require_bufobj_value(thr, 0);
DUK_ASSERT(h_this != NULL);
DUK_ASSERT(h_bufarg != NULL);
source_length = (duk_int_t) h_this->length;
target_length = (duk_int_t) h_bufarg->length;
target_start = duk_to_int(thr, 1);
source_start = duk_to_int(thr, 2);
if (duk_is_undefined(thr, 3)) {
source_end = source_length;
} else {
source_end = duk_to_int(thr, 3);
}
DUK_DDD(DUK_DDDPRINT("checking copy args: target_start=%ld, target_length=%ld, "
"source_start=%ld, source_end=%ld, source_length=%ld",
(long) target_start,
(long) h_bufarg->length,
(long) source_start,
(long) source_end,
(long) source_length));
/* This behavior mostly mimics Node.js now. */
if (source_start < 0 || source_end < 0 || target_start < 0) {
/* Negative offsets cause a RangeError. */
goto fail_bounds;
}
source_ustart = (duk_uint_t) source_start;
source_uend = (duk_uint_t) source_end;
target_ustart = (duk_uint_t) target_start;
if (source_ustart >= source_uend || /* crossed offsets or zero size */
source_ustart >= (duk_uint_t) source_length || /* source out-of-bounds (but positive) */
target_ustart >= (duk_uint_t) target_length) { /* target out-of-bounds (but positive) */
goto silent_ignore;
}
if (source_uend >= (duk_uint_t) source_length) {
/* Source end clamped silently to available length. */
source_uend = (duk_uint_t) source_length;
}
copy_size = source_uend - source_ustart;
if (target_ustart + copy_size > (duk_uint_t) target_length) {
/* Clamp to target's end if too long.
*
* NOTE: there's no overflow possibility in the comparison;
* both target_ustart and copy_size are >= 0 and based on
* values in duk_int_t range. Adding them as duk_uint_t
* values is then guaranteed not to overflow.
*/
DUK_ASSERT(target_ustart + copy_size >= target_ustart); /* no overflow */
DUK_ASSERT(target_ustart + copy_size >= copy_size); /* no overflow */
copy_size = (duk_uint_t) target_length - target_ustart;
}
DUK_DDD(DUK_DDDPRINT("making copy: target_ustart=%lu source_ustart=%lu copy_size=%lu",
(unsigned long) target_ustart,
(unsigned long) source_ustart,
(unsigned long) copy_size));
DUK_ASSERT(copy_size >= 1);
DUK_ASSERT(source_ustart <= (duk_uint_t) source_length);
DUK_ASSERT(source_ustart + copy_size <= (duk_uint_t) source_length);
DUK_ASSERT(target_ustart <= (duk_uint_t) target_length);
DUK_ASSERT(target_ustart + copy_size <= (duk_uint_t) target_length);
/* Ensure copy is covered by underlying buffers. */
DUK_ASSERT(h_bufarg->buf != NULL); /* length check */
DUK_ASSERT(h_this->buf != NULL); /* length check */
if (DUK_HBUFOBJ_VALID_BYTEOFFSET_EXCL(h_bufarg, target_ustart + copy_size) &&
DUK_HBUFOBJ_VALID_BYTEOFFSET_EXCL(h_this, source_ustart + copy_size)) {
/* Must use memmove() because copy area may overlap (source and target
* buffer may be the same, or from different slices.
*/
duk_memmove_unsafe((void *) (DUK_HBUFOBJ_GET_SLICE_BASE(thr->heap, h_bufarg) + target_ustart),
(const void *) (DUK_HBUFOBJ_GET_SLICE_BASE(thr->heap, h_this) + source_ustart),
(size_t) copy_size);
} else {
DUK_DDD(DUK_DDDPRINT("buffer copy not covered by underlying buffer(s), ignoring"));
}
silent_ignore:
/* Return value is like write(), number of bytes written.
* The return value matters because of code like:
* "off += buf.copy(...)".
*/
duk_push_uint(thr, copy_size);
return 1;
fail_bounds:
DUK_DCERROR_RANGE_INVALID_ARGS(thr);
}
#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */
/*
* TypedArray.prototype.set()
*
* TypedArray set() is pretty interesting to implement because:
*
* - The source argument may be a plain array or a typedarray. If the
* source is a TypedArray, values are decoded and re-encoded into the
* target (not as a plain byte copy). This may happen even when the
* element byte size is the same, e.g. integer values may be re-encoded
* into floats.
*
* - Source and target may refer to the same underlying buffer, so that
* the set() operation may overlap. The specification requires that this
* must work as if a copy was made before the operation. Note that this
* is NOT a simple memmove() situation because the source and target
* byte sizes may be different -- e.g. a 4-byte source (Int8Array) may
* expand to a 16-byte target (Uint32Array) so that the target overlaps
* the source both from beginning and the end (unlike in typical memmove).
*
* - Even if 'buf' pointers of the source and target differ, there's no
* guarantee that their memory areas don't overlap. This may be the
* case with external buffers.
*
* Even so, it is nice to optimize for the common case:
*
* - Source and target separate buffers or non-overlapping.
*
* - Source and target have a compatible type so that a plain byte copy
* is possible. Note that while e.g. uint8 and int8 are compatible
* (coercion one way or another doesn't change the byte representation),
* e.g. int8 and uint8clamped are NOT compatible when writing int8
* values into uint8clamped typedarray (-1 would clamp to 0 for instance).
*
* See test-bi-typedarray-proto-set.js.
*/
#if defined(DUK_USE_BUFFEROBJECT_SUPPORT)
DUK_INTERNAL duk_ret_t duk_bi_typedarray_set(duk_hthread *thr) {
duk_hbufobj *h_this;
duk_hobject *h_obj;
duk_uarridx_t i, n;
duk_int_t offset_signed;
duk_uint_t offset_elems;
duk_uint_t offset_bytes;
h_this = duk__require_bufobj_this(thr);
DUK_ASSERT(h_this != NULL);
DUK_HBUFOBJ_ASSERT_VALID(h_this);
if (h_this->buf == NULL) {
DUK_DDD(DUK_DDDPRINT("source neutered, skip copy"));
return 0;
}
duk_hbufobj_promote_plain(thr, 0);
h_obj = duk_require_hobject(thr, 0);
/* XXX: V8 throws a TypeError for negative values. Would it
* be more useful to interpret negative offsets here from the
* end of the buffer too?
*/
offset_signed = duk_to_int(thr, 1);
if (offset_signed < 0) {
/* For some reason this is a TypeError (at least in V8). */
DUK_DCERROR_TYPE_INVALID_ARGS(thr);
}
offset_elems = (duk_uint_t) offset_signed;
offset_bytes = offset_elems << h_this->shift;
if ((offset_bytes >> h_this->shift) != offset_elems) {
/* Byte length would overflow. */
/* XXX: easier check with less code? */
goto fail_args;
}
if (offset_bytes > h_this->length) {
/* Equality may be OK but >length not. Checking
* this explicitly avoids some overflow cases
* below.
*/
goto fail_args;
}
DUK_ASSERT(offset_bytes <= h_this->length);
/* Fast path: source is a TypedArray (or any bufobj). */
if (DUK_HOBJECT_IS_BUFOBJ(h_obj)) {
duk_hbufobj *h_bufarg;
#if !defined(DUK_USE_PREFER_SIZE)
duk_uint16_t comp_mask;
#endif
duk_small_int_t no_overlap = 0;
duk_uint_t src_length;
duk_uint_t dst_length;
duk_uint_t dst_length_elems;
duk_uint8_t *p_src_base;
duk_uint8_t *p_src_end;
duk_uint8_t *p_src;
duk_uint8_t *p_dst_base;
duk_uint8_t *p_dst;
duk_small_uint_t src_elem_size;
duk_small_uint_t dst_elem_size;
h_bufarg = (duk_hbufobj *) h_obj;
DUK_HBUFOBJ_ASSERT_VALID(h_bufarg);
if (h_bufarg->buf == NULL) {
DUK_DDD(DUK_DDDPRINT("target neutered, skip copy"));
return 0;
}
/* Nominal size check. */
src_length = h_bufarg->length; /* bytes in source */
dst_length_elems = (src_length >> h_bufarg->shift); /* elems in source and dest */
dst_length = dst_length_elems << h_this->shift; /* bytes in dest */
if ((dst_length >> h_this->shift) != dst_length_elems) {
/* Byte length would overflow. */
/* XXX: easier check with less code? */
goto fail_args;
}
DUK_DDD(DUK_DDDPRINT("nominal size check: src_length=%ld, dst_length=%ld", (long) src_length, (long) dst_length));
DUK_ASSERT(offset_bytes <= h_this->length);
if (dst_length > h_this->length - offset_bytes) {
/* Overflow not an issue because subtraction is used on the right
* side and guaranteed to be >= 0.
*/
DUK_DDD(DUK_DDDPRINT("copy exceeds target buffer nominal length"));
goto fail_args;
}
if (!DUK_HBUFOBJ_VALID_BYTEOFFSET_EXCL(h_this, offset_bytes + dst_length)) {
DUK_DDD(DUK_DDDPRINT("copy not covered by underlying target buffer, ignore"));
return 0;
}
p_src_base = DUK_HBUFOBJ_GET_SLICE_BASE(thr->heap, h_bufarg);
p_dst_base = DUK_HBUFOBJ_GET_SLICE_BASE(thr->heap, h_this) + offset_bytes;
/* Check actual underlying buffers for validity and that they
* cover the copy. No side effects are allowed after the check
* so that the validity status doesn't change.
*/
if (!DUK_HBUFOBJ_VALID_SLICE(h_this) || !DUK_HBUFOBJ_VALID_SLICE(h_bufarg)) {
/* The condition could be more narrow and check for the
* copy area only, but there's no need for fine grained
* behavior when the underlying buffer is misconfigured.
*/
DUK_DDD(DUK_DDDPRINT("source and/or target not covered by underlying buffer, skip copy"));
return 0;
}
/* We want to do a straight memory copy if possible: this is
* an important operation because .set() is the TypedArray
* way to copy chunks of memory. However, because set()
* conceptually works in terms of elements, not all views are
* compatible with direct byte copying.
*
* If we do manage a direct copy, the "overlap issue" handled
* below can just be solved using memmove() because the source
* and destination element sizes are necessarily equal.
*/
#if !defined(DUK_USE_PREFER_SIZE)
DUK_ASSERT(h_this->elem_type < sizeof(duk__buffer_elemtype_copy_compatible) / sizeof(duk_uint16_t));
comp_mask = duk__buffer_elemtype_copy_compatible[h_this->elem_type];
if (comp_mask & (1 << h_bufarg->elem_type)) {
DUK_ASSERT(src_length == dst_length);
DUK_DDD(DUK_DDDPRINT("fast path: able to use memmove() because views are compatible"));
duk_memmove_unsafe((void *) p_dst_base, (const void *) p_src_base, (size_t) dst_length);
return 0;
}
DUK_DDD(DUK_DDDPRINT("fast path: views are not compatible with a byte copy, copy by item"));
#endif /* !DUK_USE_PREFER_SIZE */
/* We want to avoid making a copy to process set() but that's
* not always possible: the source and the target may overlap
* and because element sizes are different, the overlap cannot
* always be handled with a memmove() or choosing the copy
* direction in a certain way. For example, if source type is
* uint8 and target type is uint32, the target area may exceed
* the source area from both ends!
*
* Note that because external buffers may point to the same
* memory areas, we must ultimately make this check using
* pointers.
*
* NOTE: careful with side effects: any side effect may cause
* a buffer resize (or external buffer pointer/length update)!
*/
DUK_DDD(DUK_DDDPRINT("overlap check: p_src_base=%p, src_length=%ld, "
"p_dst_base=%p, dst_length=%ld",
(void *) p_src_base,
(long) src_length,
(void *) p_dst_base,
(long) dst_length));
if (p_src_base >= p_dst_base + dst_length || /* source starts after dest ends */
p_src_base + src_length <= p_dst_base) { /* source ends before dest starts */
no_overlap = 1;
}
if (!no_overlap) {
/* There's overlap: the desired end result is that
* conceptually a copy is made to avoid "trampling"
* of source data by destination writes. We make
* an actual temporary copy to handle this case.
*/
duk_uint8_t *p_src_copy;
DUK_DDD(DUK_DDDPRINT("there is overlap, make a copy of the source"));
p_src_copy = (duk_uint8_t *) duk_push_fixed_buffer_nozero(thr, src_length);
DUK_ASSERT(p_src_copy != NULL);
duk_memcpy_unsafe((void *) p_src_copy, (const void *) p_src_base, (size_t) src_length);
p_src_base = p_src_copy; /* use p_src_base from now on */
}
/* Value stack intentionally mixed size here. */
DUK_DDD(DUK_DDDPRINT("after overlap check: p_src_base=%p, src_length=%ld, "
"p_dst_base=%p, dst_length=%ld, valstack top=%ld",
(void *) p_src_base,
(long) src_length,
(void *) p_dst_base,
(long) dst_length,
(long) duk_get_top(thr)));
/* Ready to make the copy. We must proceed element by element
* and must avoid any side effects that might cause the buffer
* validity check above to become invalid.
*
* Although we work through the value stack here, only plain
* numbers are handled which should be side effect safe.
*/
src_elem_size = (duk_small_uint_t) (1U << h_bufarg->shift);
dst_elem_size = (duk_small_uint_t) (1U << h_this->shift);
p_src = p_src_base;
p_dst = p_dst_base;
p_src_end = p_src_base + src_length;
while (p_src != p_src_end) {
DUK_DDD(DUK_DDDPRINT("fast path per element copy loop: "
"p_src=%p, p_src_end=%p, p_dst=%p",
(void *) p_src,
(void *) p_src_end,
(void *) p_dst));
/* A validated read() is always a number, so it's write coercion
* is always side effect free an won't invalidate pointers etc.
*/
duk_hbufobj_push_validated_read(thr, h_bufarg, p_src, src_elem_size);
duk_hbufobj_validated_write(thr, h_this, p_dst, dst_elem_size);
duk_pop(thr);
p_src += src_elem_size;
p_dst += dst_elem_size;
}
return 0;
} else {
/* Slow path: quite slow, but we save space by using the property code
* to write coerce target values. We don't need to worry about overlap
* here because the source is not a TypedArray.
*
* We could use the bufobj write coercion helper but since the
* property read may have arbitrary side effects, full validity checks
* would be needed for every element anyway.
*/
n = (duk_uarridx_t) duk_get_length(thr, 0);
DUK_ASSERT(offset_bytes <= h_this->length);
if ((n << h_this->shift) > h_this->length - offset_bytes) {
/* Overflow not an issue because subtraction is used on the right
* side and guaranteed to be >= 0.
*/
DUK_DDD(DUK_DDDPRINT("copy exceeds target buffer nominal length"));
goto fail_args;
}
/* There's no need to check for buffer validity status for the
* target here: the property access code will do that for each
* element. Moreover, if we did check the validity here, side
* effects from reading the source argument might invalidate
* the results anyway.
*/
DUK_ASSERT_TOP(thr, 2);
duk_push_this(thr);
for (i = 0; i < n; i++) {
duk_get_prop_index(thr, 0, i);
duk_put_prop_index(thr, 2, offset_elems + i);
}
}
return 0;
fail_args:
DUK_DCERROR_RANGE_INVALID_ARGS(thr);
}
#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */
/*
* Node.js Buffer.prototype.slice([start], [end])
* ArrayBuffer.prototype.slice(begin, [end])
* TypedArray.prototype.subarray(begin, [end])
*
* The API calls are almost identical; negative indices are counted from end
* of buffer, and final indices are clamped (allowing crossed indices). Main
* differences:
*
* - Copy/view behavior; Node.js .slice() and TypedArray .subarray() create
* views, ArrayBuffer .slice() creates a copy
*
* - Resulting object has a different class and prototype depending on the
* call (or 'this' argument)
*
* - TypedArray .subarray() arguments are element indices, not byte offsets
*
* - Plain buffer argument creates a plain buffer slice
*/
#if defined(DUK_USE_BUFFEROBJECT_SUPPORT)
DUK_LOCAL void duk__arraybuffer_plain_slice(duk_hthread *thr, duk_hbuffer *h_val) {
duk_int_t start_offset, end_offset;
duk_uint_t slice_length;
duk_uint8_t *p_copy;
duk_size_t copy_length;
duk__clamp_startend_negidx_shifted(thr,
(duk_int_t) DUK_HBUFFER_GET_SIZE(h_val),
0 /*buffer_shift*/,
0 /*idx_start*/,
1 /*idx_end*/,
&start_offset,
&end_offset);
DUK_ASSERT(end_offset <= (duk_int_t) DUK_HBUFFER_GET_SIZE(h_val));
DUK_ASSERT(start_offset >= 0);
DUK_ASSERT(end_offset >= start_offset);
slice_length = (duk_uint_t) (end_offset - start_offset);
p_copy = (duk_uint8_t *) duk_push_fixed_buffer_nozero(thr, (duk_size_t) slice_length);
DUK_ASSERT(p_copy != NULL);
copy_length = slice_length;
duk_memcpy_unsafe((void *) p_copy,
(const void *) ((duk_uint8_t *) DUK_HBUFFER_GET_DATA_PTR(thr->heap, h_val) + start_offset),
copy_length);
}
#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */
#if defined(DUK_USE_BUFFEROBJECT_SUPPORT)
/* Shared helper for slice/subarray operation.
* Magic: 0x01=isView, 0x02=copy, 0x04=Node.js Buffer special handling.
*/
DUK_INTERNAL duk_ret_t duk_bi_buffer_slice_shared(duk_hthread *thr) {
duk_small_int_t magic;
duk_small_uint_t res_class_num;
duk_small_int_t res_proto_bidx;
duk_hbufobj *h_this;
duk_hbufobj *h_bufobj;
duk_hbuffer *h_val;
duk_int_t start_offset, end_offset;
duk_uint_t slice_length;
duk_tval *tv;
/* [ start end ] */
magic = duk_get_current_magic(thr);
tv = duk_get_borrowed_this_tval(thr);
DUK_ASSERT(tv != NULL);
if (DUK_TVAL_IS_BUFFER(tv)) {
/* For plain buffers return a plain buffer slice. */
h_val = DUK_TVAL_GET_BUFFER(tv);
DUK_ASSERT(h_val != NULL);
if (magic & 0x02) {
/* Make copy: ArrayBuffer.prototype.slice() uses this. */
duk__arraybuffer_plain_slice(thr, h_val);
return 1;
} else {
/* View into existing buffer: cannot be done if the
* result is a plain buffer because there's no slice
* info. So return an ArrayBuffer instance; coerce
* the 'this' binding into an object and behave as if
* the original call was for an Object-coerced plain
* buffer (handled automatically by duk__require_bufobj_this()).
*/
DUK_DDD(DUK_DDDPRINT("slice() doesn't handle view into plain buffer, coerce 'this' to ArrayBuffer object"));
/* fall through */
}
}
tv = NULL; /* No longer valid nor needed. */
h_this = duk__require_bufobj_this(thr);
/* Slice offsets are element (not byte) offsets, which only matters
* for TypedArray views, Node.js Buffer and ArrayBuffer have shift
* zero so byte and element offsets are the same. Negative indices
* are counted from end of slice, crossed indices are allowed (and
* result in zero length result), and final values are clamped
* against the current slice. There's intentionally no check
* against the underlying buffer here.
*/
duk__clamp_startend_negidx_shifted(thr,
(duk_int_t) h_this->length,
(duk_uint8_t) h_this->shift,
0 /*idx_start*/,
1 /*idx_end*/,
&start_offset,
&end_offset);
DUK_ASSERT(end_offset >= start_offset);
DUK_ASSERT(start_offset >= 0);
DUK_ASSERT(end_offset >= 0);
slice_length = (duk_uint_t) (end_offset - start_offset);
/* The resulting buffer object gets the same class and prototype as
* the buffer in 'this', e.g. if the input is a Uint8Array the
* result is a Uint8Array; if the input is a Float32Array, the
* result is a Float32Array. The result internal prototype should
* be the default prototype for the class (e.g. initial value of
* Uint8Array.prototype), not copied from the argument (Duktape 1.x
* did that).
*
* Node.js Buffers have special handling: they're Uint8Arrays as far
* as the internal class is concerned, so the new Buffer should also
* be an Uint8Array but inherit from Buffer.prototype.
*/
res_class_num = DUK_HOBJECT_GET_CLASS_NUMBER((duk_hobject *) h_this);
DUK_ASSERT(res_class_num >= DUK_HOBJECT_CLASS_BUFOBJ_MIN); /* type check guarantees */
DUK_ASSERT(res_class_num <= DUK_HOBJECT_CLASS_BUFOBJ_MAX);
res_proto_bidx = duk__buffer_proto_from_classnum[res_class_num - DUK_HOBJECT_CLASS_BUFOBJ_MIN];
if (magic & 0x04) {
res_proto_bidx = DUK_BIDX_NODEJS_BUFFER_PROTOTYPE;
}
h_bufobj =
duk_push_bufobj_raw(thr,
DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_BUFOBJ | DUK_HOBJECT_CLASS_AS_FLAGS(res_class_num),
res_proto_bidx);
DUK_ASSERT(h_bufobj != NULL);
DUK_ASSERT(h_bufobj->length == 0);
h_bufobj->shift = h_this->shift; /* inherit */
h_bufobj->elem_type = h_this->elem_type; /* inherit */
h_bufobj->is_typedarray = magic & 0x01;
DUK_ASSERT(h_bufobj->is_typedarray == 0 || h_bufobj->is_typedarray == 1);
h_val = h_this->buf;
if (h_val == NULL) {
DUK_DCERROR_TYPE_INVALID_ARGS(thr);
}
if (magic & 0x02) {
/* non-zero: make copy */
duk_uint8_t *p_copy;
duk_size_t copy_length;
p_copy = (duk_uint8_t *) duk_push_fixed_buffer_zero(
thr,
(duk_size_t) slice_length); /* must be zeroed, not all bytes always copied */
DUK_ASSERT(p_copy != NULL);
/* Copy slice, respecting underlying buffer limits; remainder
* is left as zero.
*/
copy_length = DUK_HBUFOBJ_CLAMP_BYTELENGTH(h_this, slice_length);
duk_memcpy_unsafe((void *) p_copy,
(const void *) (DUK_HBUFOBJ_GET_SLICE_BASE(thr->heap, h_this) + start_offset),
copy_length);
h_val = duk_known_hbuffer(thr, -1);
h_bufobj->buf = h_val;
DUK_HBUFFER_INCREF(thr, h_val);
h_bufobj->length = slice_length;
DUK_ASSERT(h_bufobj->offset == 0);
duk_pop(thr); /* reachable so pop OK */
} else {
h_bufobj->buf = h_val;
DUK_HBUFFER_INCREF(thr, h_val);
h_bufobj->length = slice_length;
h_bufobj->offset = h_this->offset + (duk_uint_t) start_offset;
/* Copy the .buffer property, needed for TypedArray.prototype.subarray().
*
* XXX: limit copy only for TypedArray classes specifically?
*/
DUK_ASSERT(h_bufobj->buf_prop == NULL);
h_bufobj->buf_prop = h_this->buf_prop; /* may be NULL */
DUK_HOBJECT_INCREF_ALLOWNULL(thr, (duk_hobject *) h_bufobj->buf_prop);
}
/* unbalanced stack on purpose */
DUK_HBUFOBJ_ASSERT_VALID(h_bufobj);
return 1;
}
#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */
/*
* Node.js Buffer.isEncoding()
*/
#if defined(DUK_USE_BUFFEROBJECT_SUPPORT)
DUK_INTERNAL duk_ret_t duk_bi_nodejs_buffer_is_encoding(duk_hthread *thr) {
const char *encoding;
/* only accept lowercase 'utf8' now. */
encoding = duk_to_string(thr, 0);
DUK_ASSERT(duk_is_string(thr, 0)); /* guaranteed by duk_to_string() */
duk_push_boolean(thr, DUK_STRCMP(encoding, "utf8") == 0);
return 1;
}
#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */
/*
* Node.js Buffer.isBuffer()
*/
#if defined(DUK_USE_BUFFEROBJECT_SUPPORT)
DUK_INTERNAL duk_ret_t duk_bi_nodejs_buffer_is_buffer(duk_hthread *thr) {
duk_hobject *h;
duk_hobject *h_proto;
duk_bool_t ret = 0;
DUK_ASSERT(duk_get_top(thr) >= 1); /* nargs */
h = duk_get_hobject(thr, 0);
if (h != NULL) {
h_proto = thr->builtins[DUK_BIDX_NODEJS_BUFFER_PROTOTYPE];
DUK_ASSERT(h_proto != NULL);
h = DUK_HOBJECT_GET_PROTOTYPE(thr->heap, h);
if (h != NULL) {
ret = duk_hobject_prototype_chain_contains(thr, h, h_proto, 0 /*ignore_loop*/);
}
}
duk_push_boolean(thr, ret);
return 1;
}
#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */
/*
* Node.js Buffer.byteLength()
*/
#if defined(DUK_USE_BUFFEROBJECT_SUPPORT)
DUK_INTERNAL duk_ret_t duk_bi_nodejs_buffer_byte_length(duk_hthread *thr) {
const char *str;
duk_size_t len;
/* At the moment Buffer(<str>) will just use the string bytes as
* is (ignoring encoding), so we return the string length here
* unconditionally.
*/
/* XXX: to be revised; Old Node.js behavior just coerces any buffer
* values to string:
* $ node
* > Buffer.byteLength(new Uint32Array(10))
* 20
* > Buffer.byteLength(new Uint32Array(100))
* 20
* (The 20 comes from '[object Uint32Array]'.length
*/
str = duk_to_lstring(thr, 0, &len);
DUK_UNREF(str);
duk_push_size_t(thr, len);
return 1;
}
#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */
/*
* Node.js Buffer.concat()
*/
#if defined(DUK_USE_BUFFEROBJECT_SUPPORT)
DUK_INTERNAL duk_ret_t duk_bi_nodejs_buffer_concat(duk_hthread *thr) {
duk_hobject *h_arg;
duk_uint_t total_length;
duk_hbufobj *h_bufobj;
duk_hbufobj *h_bufres;
duk_hbuffer *h_val;
duk_uint_t i, n;
duk_uint8_t *p;
duk_size_t space_left;
duk_size_t copy_size;
/* Node.js accepts only actual Arrays. */
h_arg = duk_require_hobject(thr, 0);
if (DUK_HOBJECT_GET_CLASS_NUMBER(h_arg) != DUK_HOBJECT_CLASS_ARRAY) {
DUK_DCERROR_TYPE_INVALID_ARGS(thr);
}
/* Compute result length and validate argument buffers. */
n = (duk_uint_t) duk_get_length(thr, 0);
total_length = 0;
for (i = 0; i < n; i++) {
/* Neutered checks not necessary here: neutered buffers have
* zero 'length' so we'll effectively skip them.
*/
DUK_ASSERT_TOP(thr, 2); /* [ array totalLength ] */
duk_get_prop_index(thr, 0, (duk_uarridx_t) i); /* -> [ array totalLength buf ] */
h_bufobj = duk__require_bufobj_value(thr, 2);
DUK_ASSERT(h_bufobj != NULL);
total_length += h_bufobj->length;
if (DUK_UNLIKELY(total_length < h_bufobj->length)) {
DUK_DCERROR_RANGE_INVALID_ARGS(thr); /* Wrapped. */
}
duk_pop(thr);
}
/* In Node.js v0.12.1 a 1-element array is special and won't create a
* copy, this was fixed later so an explicit check no longer needed.
*/
/* User totalLength overrides a computed length, but we'll check
* every copy in the copy loop. Note that duk_to_int() can
* technically have arbitrary side effects so we need to recheck
* the buffers in the copy loop.
*/
if (!duk_is_undefined(thr, 1) && n > 0) {
/* For n == 0, Node.js ignores totalLength argument and
* returns a zero length buffer.
*/
duk_int_t total_length_signed;
total_length_signed = duk_to_int(thr, 1);
if (total_length_signed < 0) {
DUK_DCERROR_RANGE_INVALID_ARGS(thr);
}
total_length = (duk_uint_t) total_length_signed;
}
h_bufres = duk_push_bufobj_raw(thr,
DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_BUFOBJ |
DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_UINT8ARRAY),
DUK_BIDX_NODEJS_BUFFER_PROTOTYPE);
DUK_ASSERT(h_bufres != NULL);
p = (duk_uint8_t *) duk_push_fixed_buffer_zero(thr,
total_length); /* must be zeroed, all bytes not necessarily written over */
DUK_ASSERT(p != NULL);
space_left = (duk_size_t) total_length;
for (i = 0; i < n; i++) {
DUK_ASSERT_TOP(thr, 4); /* [ array totalLength bufres buf ] */
duk_get_prop_index(thr, 0, (duk_uarridx_t) i);
h_bufobj = duk__require_bufobj_value(thr, 4);
DUK_ASSERT(h_bufobj != NULL);
copy_size = h_bufobj->length;
if (copy_size > space_left) {
copy_size = space_left;
}
if (h_bufobj->buf != NULL && DUK_HBUFOBJ_VALID_SLICE(h_bufobj)) {
duk_memcpy_unsafe((void *) p, (const void *) DUK_HBUFOBJ_GET_SLICE_BASE(thr->heap, h_bufobj), copy_size);
} else {
/* Just skip, leaving zeroes in the result. */
;
}
p += copy_size;
space_left -= copy_size;
duk_pop(thr);
}
h_val = duk_known_hbuffer(thr, -1);
duk__set_bufobj_buffer(thr, h_bufres, h_val);
h_bufres->is_typedarray = 1;
DUK_HBUFOBJ_ASSERT_VALID(h_bufres);
duk_pop(thr); /* pop plain buffer, now reachable through h_bufres */
return 1; /* return h_bufres */
}
#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */
/*
* Shared readfield and writefield methods
*
* The readfield/writefield methods need support for endianness and field
* types. All offsets are byte based so no offset shifting is needed.
*/
#if defined(DUK_USE_BUFFEROBJECT_SUPPORT)
/* Format of magic, bits:
* 0...1: field type; 0=uint8, 1=uint16, 2=uint32, 3=float, 4=double, 5=unused, 6=unused, 7=unused
* 3: endianness: 0=little, 1=big
* 4: signed: 1=yes, 0=no
* 5: typedarray: 1=yes, 0=no
*/
#define DUK__FLD_8BIT 0
#define DUK__FLD_16BIT 1
#define DUK__FLD_32BIT 2
#define DUK__FLD_FLOAT 3
#define DUK__FLD_DOUBLE 4
#define DUK__FLD_VARINT 5
#define DUK__FLD_BIGENDIAN (1 << 3)
#define DUK__FLD_SIGNED (1 << 4)
#define DUK__FLD_TYPEDARRAY (1 << 5)
/* XXX: split into separate functions for each field type? */
DUK_INTERNAL duk_ret_t duk_bi_buffer_readfield(duk_hthread *thr) {
duk_small_uint_t magic = (duk_small_uint_t) duk_get_current_magic(thr);
duk_small_uint_t magic_ftype;
duk_small_uint_t magic_bigendian;
duk_small_uint_t magic_signed;
duk_small_uint_t magic_typedarray;
duk_small_uint_t endswap;
duk_hbufobj *h_this;
duk_bool_t no_assert;
duk_int_t offset_signed;
duk_uint_t offset;
duk_uint_t buffer_length;
duk_uint_t check_length;
duk_uint8_t *buf;
duk_double_union du;
magic_ftype = magic & 0x0007U;
magic_bigendian = magic & 0x0008U;
magic_signed = magic & 0x0010U;
magic_typedarray = magic & 0x0020U;
h_this = duk__require_bufobj_this(thr); /* XXX: very inefficient for plain buffers */
DUK_ASSERT(h_this != NULL);
buffer_length = h_this->length;
/* [ offset noAssert ], when ftype != DUK__FLD_VARINT */
/* [ offset fieldByteLength noAssert ], when ftype == DUK__FLD_VARINT */
/* [ offset littleEndian ], when DUK__FLD_TYPEDARRAY (regardless of ftype) */
/* Handle TypedArray vs. Node.js Buffer arg differences */
if (magic_typedarray) {
no_assert = 0;
#if defined(DUK_USE_INTEGER_LE)
endswap = !duk_to_boolean(thr, 1); /* 1=little endian */
#else
endswap = duk_to_boolean(thr, 1); /* 1=little endian */
#endif
} else {
no_assert = duk_to_boolean(thr, (magic_ftype == DUK__FLD_VARINT) ? 2 : 1);
#if defined(DUK_USE_INTEGER_LE)
endswap = magic_bigendian;
#else
endswap = !magic_bigendian;
#endif
}
/* Offset is coerced first to signed integer range and then to unsigned.
* This ensures we can add a small byte length (1-8) to the offset in
* bound checks and not wrap.
*/
offset_signed = duk_to_int(thr, 0);
offset = (duk_uint_t) offset_signed;
if (offset_signed < 0) {
goto fail_bounds;
}
DUK_DDD(DUK_DDDPRINT("readfield, buffer_length=%ld, offset=%ld, no_assert=%d, "
"magic=%04x, magic_fieldtype=%d, magic_bigendian=%d, magic_signed=%d, "
"endswap=%u",
(long) buffer_length,
(long) offset,
(int) no_assert,
(unsigned int) magic,
(int) magic_ftype,
(int) (magic_bigendian >> 3),
(int) (magic_signed >> 4),
(int) endswap));
/* Update 'buffer_length' to be the effective, safe limit which
* takes into account the underlying buffer. This value will be
* potentially invalidated by any side effect.
*/
check_length = DUK_HBUFOBJ_CLAMP_BYTELENGTH(h_this, buffer_length);
DUK_DDD(DUK_DDDPRINT("buffer_length=%ld, check_length=%ld", (long) buffer_length, (long) check_length));
if (h_this->buf) {
buf = DUK_HBUFOBJ_GET_SLICE_BASE(thr->heap, h_this);
} else {
/* Neutered. We could go into the switch-case safely with
* buf == NULL because check_length == 0. To avoid scanbuild
* warnings, fail directly instead.
*/
DUK_ASSERT(check_length == 0);
goto fail_neutered;
}
DUK_ASSERT(buf != NULL);
switch (magic_ftype) {
case DUK__FLD_8BIT: {
duk_uint8_t tmp;
if (offset + 1U > check_length) {
goto fail_bounds;
}
tmp = buf[offset];
if (magic_signed) {
duk_push_int(thr, (duk_int_t) ((duk_int8_t) tmp));
} else {
duk_push_uint(thr, (duk_uint_t) tmp);
}
break;
}
case DUK__FLD_16BIT: {
duk_uint16_t tmp;
if (offset + 2U > check_length) {
goto fail_bounds;
}
duk_memcpy((void *) du.uc, (const void *) (buf + offset), 2);
tmp = du.us[0];
if (endswap) {
tmp = DUK_BSWAP16(tmp);
}
if (magic_signed) {
duk_push_int(thr, (duk_int_t) ((duk_int16_t) tmp));
} else {
duk_push_uint(thr, (duk_uint_t) tmp);
}
break;
}
case DUK__FLD_32BIT: {
duk_uint32_t tmp;
if (offset + 4U > check_length) {
goto fail_bounds;
}
duk_memcpy((void *) du.uc, (const void *) (buf + offset), 4);
tmp = du.ui[0];
if (endswap) {
tmp = DUK_BSWAP32(tmp);
}
if (magic_signed) {
duk_push_int(thr, (duk_int_t) ((duk_int32_t) tmp));
} else {
duk_push_uint(thr, (duk_uint_t) tmp);
}
break;
}
case DUK__FLD_FLOAT: {
duk_uint32_t tmp;
if (offset + 4U > check_length) {
goto fail_bounds;
}
duk_memcpy((void *) du.uc, (const void *) (buf + offset), 4);
if (endswap) {
tmp = du.ui[0];
tmp = DUK_BSWAP32(tmp);
du.ui[0] = tmp;
}
duk_push_number(thr, (duk_double_t) du.f[0]);
break;
}
case DUK__FLD_DOUBLE: {
if (offset + 8U > check_length) {
goto fail_bounds;
}
duk_memcpy((void *) du.uc, (const void *) (buf + offset), 8);
if (endswap) {
DUK_DBLUNION_BSWAP64(&du);
}
duk_push_number(thr, (duk_double_t) du.d);
break;
}
case DUK__FLD_VARINT: {
/* Node.js Buffer variable width integer field. We don't really
* care about speed here, so aim for shortest algorithm.
*/
duk_int_t field_bytelen;
duk_int_t i, i_step, i_end;
#if defined(DUK_USE_64BIT_OPS)
duk_int64_t tmp;
duk_small_uint_t shift_tmp;
#else
duk_double_t tmp;
duk_small_int_t highbyte;
#endif
const duk_uint8_t *p;
field_bytelen = duk_get_int(thr, 1); /* avoid side effects! */
if (field_bytelen < 1 || field_bytelen > 6) {
goto fail_field_length;
}
if (offset + (duk_uint_t) field_bytelen > check_length) {
goto fail_bounds;
}
p = (const duk_uint8_t *) (buf + offset);
/* Slow gathering of value using either 64-bit arithmetic
* or IEEE doubles if 64-bit types not available. Handling
* of negative numbers is a bit non-obvious in both cases.
*/
if (magic_bigendian) {
/* Gather in big endian */
i = 0;
i_step = 1;
i_end = field_bytelen; /* one i_step over */
} else {
/* Gather in little endian */
i = field_bytelen - 1;
i_step = -1;
i_end = -1; /* one i_step over */
}
#if defined(DUK_USE_64BIT_OPS)
tmp = 0;
do {
DUK_ASSERT(i >= 0 && i < field_bytelen);
tmp = (tmp << 8) + (duk_int64_t) p[i];
i += i_step;
} while (i != i_end);
if (magic_signed) {
/* Shift to sign extend. Left shift must be unsigned
* to avoid undefined behavior; right shift must be
* signed to sign extend properly.
*/
shift_tmp = (duk_small_uint_t) (64U - (duk_small_uint_t) field_bytelen * 8U);
tmp = (duk_int64_t) ((duk_uint64_t) tmp << shift_tmp) >> shift_tmp;
}
duk_push_i64(thr, tmp);
#else
highbyte = p[i];
if (magic_signed && (highbyte & 0x80) != 0) {
/* 0xff => 255 - 256 = -1; 0x80 => 128 - 256 = -128 */
tmp = (duk_double_t) (highbyte - 256);
} else {
tmp = (duk_double_t) highbyte;
}
for (;;) {
i += i_step;
if (i == i_end) {
break;
}
DUK_ASSERT(i >= 0 && i < field_bytelen);
tmp = (tmp * 256.0) + (duk_double_t) p[i];
}
duk_push_number(thr, tmp);
#endif
break;
}
default: { /* should never happen but default here */
goto fail_bounds;
}
}
return 1;
fail_neutered:
fail_field_length:
fail_bounds:
if (no_assert) {
/* Node.js return value for noAssert out-of-bounds reads is
* usually (but not always) NaN. Return NaN consistently.
*/
duk_push_nan(thr);
return 1;
}
DUK_DCERROR_RANGE_INVALID_ARGS(thr);
}
#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */
#if defined(DUK_USE_BUFFEROBJECT_SUPPORT)
/* XXX: split into separate functions for each field type? */
DUK_INTERNAL duk_ret_t duk_bi_buffer_writefield(duk_hthread *thr) {
duk_small_uint_t magic = (duk_small_uint_t) duk_get_current_magic(thr);
duk_small_uint_t magic_ftype;
duk_small_uint_t magic_bigendian;
duk_small_uint_t magic_signed;
duk_small_uint_t magic_typedarray;
duk_small_uint_t endswap;
duk_hbufobj *h_this;
duk_bool_t no_assert;
duk_int_t offset_signed;
duk_uint_t offset;
duk_uint_t buffer_length;
duk_uint_t check_length;
duk_uint8_t *buf;
duk_double_union du;
duk_int_t nbytes = 0;
magic_ftype = magic & 0x0007U;
magic_bigendian = magic & 0x0008U;
magic_signed = magic & 0x0010U;
magic_typedarray = magic & 0x0020U;
DUK_UNREF(magic_signed);
h_this = duk__require_bufobj_this(thr); /* XXX: very inefficient for plain buffers */
DUK_ASSERT(h_this != NULL);
buffer_length = h_this->length;
/* [ value offset noAssert ], when ftype != DUK__FLD_VARINT */
/* [ value offset fieldByteLength noAssert ], when ftype == DUK__FLD_VARINT */
/* [ offset value littleEndian ], when DUK__FLD_TYPEDARRAY (regardless of ftype) */
/* Handle TypedArray vs. Node.js Buffer arg differences */
if (magic_typedarray) {
no_assert = 0;
#if defined(DUK_USE_INTEGER_LE)
endswap = !duk_to_boolean(thr, 2); /* 1=little endian */
#else
endswap = duk_to_boolean(thr, 2); /* 1=little endian */
#endif
duk_swap(thr, 0, 1); /* offset/value order different from Node.js */
} else {
no_assert = duk_to_boolean(thr, (magic_ftype == DUK__FLD_VARINT) ? 3 : 2);
#if defined(DUK_USE_INTEGER_LE)
endswap = magic_bigendian;
#else
endswap = !magic_bigendian;
#endif
}
/* Offset is coerced first to signed integer range and then to unsigned.
* This ensures we can add a small byte length (1-8) to the offset in
* bound checks and not wrap.
*/
offset_signed = duk_to_int(thr, 1);
offset = (duk_uint_t) offset_signed;
/* We need 'nbytes' even for a failed offset; return value must be
* (offset + nbytes) even when write fails due to invalid offset.
*/
if (magic_ftype != DUK__FLD_VARINT) {
DUK_ASSERT(magic_ftype < (duk_small_uint_t) (sizeof(duk__buffer_nbytes_from_fldtype) / sizeof(duk_uint8_t)));
nbytes = duk__buffer_nbytes_from_fldtype[magic_ftype];
} else {
nbytes = duk_get_int(thr, 2);
if (nbytes < 1 || nbytes > 6) {
goto fail_field_length;
}
}
DUK_ASSERT(nbytes >= 1 && nbytes <= 8);
/* Now we can check offset validity. */
if (offset_signed < 0) {
goto fail_bounds;
}
DUK_DDD(DUK_DDDPRINT("writefield, value=%!T, buffer_length=%ld, offset=%ld, no_assert=%d, "
"magic=%04x, magic_fieldtype=%d, magic_bigendian=%d, magic_signed=%d, "
"endswap=%u",
duk_get_tval(thr, 0),
(long) buffer_length,
(long) offset,
(int) no_assert,
(unsigned int) magic,
(int) magic_ftype,
(int) (magic_bigendian >> 3),
(int) (magic_signed >> 4),
(int) endswap));
/* Coerce value to a number before computing check_length, so that
* the field type specific coercion below can't have side effects
* that would invalidate check_length.
*/
duk_to_number(thr, 0);
/* Update 'buffer_length' to be the effective, safe limit which
* takes into account the underlying buffer. This value will be
* potentially invalidated by any side effect.
*/
check_length = DUK_HBUFOBJ_CLAMP_BYTELENGTH(h_this, buffer_length);
DUK_DDD(DUK_DDDPRINT("buffer_length=%ld, check_length=%ld", (long) buffer_length, (long) check_length));
if (h_this->buf) {
buf = DUK_HBUFOBJ_GET_SLICE_BASE(thr->heap, h_this);
} else {
/* Neutered. We could go into the switch-case safely with
* buf == NULL because check_length == 0. To avoid scanbuild
* warnings, fail directly instead.
*/
DUK_ASSERT(check_length == 0);
goto fail_neutered;
}
DUK_ASSERT(buf != NULL);
switch (magic_ftype) {
case DUK__FLD_8BIT: {
if (offset + 1U > check_length) {
goto fail_bounds;
}
/* sign doesn't matter when writing */
buf[offset] = (duk_uint8_t) duk_to_uint32(thr, 0);
break;
}
case DUK__FLD_16BIT: {
duk_uint16_t tmp;
if (offset + 2U > check_length) {
goto fail_bounds;
}
tmp = (duk_uint16_t) duk_to_uint32(thr, 0);
if (endswap) {
tmp = DUK_BSWAP16(tmp);
}
du.us[0] = tmp;
/* sign doesn't matter when writing */
duk_memcpy((void *) (buf + offset), (const void *) du.uc, 2);
break;
}
case DUK__FLD_32BIT: {
duk_uint32_t tmp;
if (offset + 4U > check_length) {
goto fail_bounds;
}
tmp = (duk_uint32_t) duk_to_uint32(thr, 0);
if (endswap) {
tmp = DUK_BSWAP32(tmp);
}
du.ui[0] = tmp;
/* sign doesn't matter when writing */
duk_memcpy((void *) (buf + offset), (const void *) du.uc, 4);
break;
}
case DUK__FLD_FLOAT: {
duk_uint32_t tmp;
if (offset + 4U > check_length) {
goto fail_bounds;
}
du.f[0] = (duk_float_t) duk_to_number(thr, 0);
if (endswap) {
tmp = du.ui[0];
tmp = DUK_BSWAP32(tmp);
du.ui[0] = tmp;
}
/* sign doesn't matter when writing */
duk_memcpy((void *) (buf + offset), (const void *) du.uc, 4);
break;
}
case DUK__FLD_DOUBLE: {
if (offset + 8U > check_length) {
goto fail_bounds;
}
du.d = (duk_double_t) duk_to_number(thr, 0);
if (endswap) {
DUK_DBLUNION_BSWAP64(&du);
}
/* sign doesn't matter when writing */
duk_memcpy((void *) (buf + offset), (const void *) du.uc, 8);
break;
}
case DUK__FLD_VARINT: {
/* Node.js Buffer variable width integer field. We don't really
* care about speed here, so aim for shortest algorithm.
*/
duk_int_t field_bytelen;
duk_int_t i, i_step, i_end;
#if defined(DUK_USE_64BIT_OPS)
duk_int64_t tmp;
#else
duk_double_t tmp;
#endif
duk_uint8_t *p;
field_bytelen = (duk_int_t) nbytes;
if (offset + (duk_uint_t) field_bytelen > check_length) {
goto fail_bounds;
}
/* Slow writing of value using either 64-bit arithmetic
* or IEEE doubles if 64-bit types not available. There's
* no special sign handling when writing varints.
*/
if (magic_bigendian) {
/* Write in big endian */
i = field_bytelen; /* one i_step added at top of loop */
i_step = -1;
i_end = 0;
} else {
/* Write in little endian */
i = -1; /* one i_step added at top of loop */
i_step = 1;
i_end = field_bytelen - 1;
}
/* XXX: The duk_to_number() cast followed by integer coercion
* is platform specific so NaN, +/- Infinity, and out-of-bounds
* values result in platform specific output now.
* See: test-bi-nodejs-buffer-proto-varint-special.js
*/
#if defined(DUK_USE_64BIT_OPS)
tmp = (duk_int64_t) duk_to_number(thr, 0);
p = (duk_uint8_t *) (buf + offset);
do {
i += i_step;
DUK_ASSERT(i >= 0 && i < field_bytelen);
p[i] = (duk_uint8_t) (tmp & 0xff);
tmp = tmp >> 8; /* unnecessary shift for last byte */
} while (i != i_end);
#else
tmp = duk_to_number(thr, 0);
p = (duk_uint8_t *) (buf + offset);
do {
i += i_step;
tmp = DUK_FLOOR(tmp);
DUK_ASSERT(i >= 0 && i < field_bytelen);
p[i] = (duk_uint8_t) (DUK_FMOD(tmp, 256.0));
tmp = tmp / 256.0; /* unnecessary div for last byte */
} while (i != i_end);
#endif
break;
}
default: { /* should never happen but default here */
goto fail_bounds;
}
}
/* Node.js Buffer: return offset + #bytes written (i.e. next
* write offset).
*/
if (magic_typedarray) {
/* For TypedArrays 'undefined' return value is specified
* by ES2015 (matches V8).
*/
return 0;
}
duk_push_uint(thr, offset + (duk_uint_t) nbytes);
return 1;
fail_neutered:
fail_field_length:
fail_bounds:
if (no_assert) {
/* Node.js return value for failed writes is offset + #bytes
* that would have been written.
*/
/* XXX: for negative input offsets, 'offset' will be a large
* positive value so the result here is confusing.
*/
if (magic_typedarray) {
return 0;
}
duk_push_uint(thr, offset + (duk_uint_t) nbytes);
return 1;
}
DUK_DCERROR_RANGE_INVALID_ARGS(thr);
}
#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */
/*
* Accessors for .buffer, .byteLength, .byteOffset
*/
#if defined(DUK_USE_BUFFEROBJECT_SUPPORT)
DUK_LOCAL duk_hbufobj *duk__autospawn_arraybuffer(duk_hthread *thr, duk_hbuffer *h_buf) {
duk_hbufobj *h_res;
h_res = duk_push_bufobj_raw(thr,
DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_BUFOBJ |
DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_ARRAYBUFFER),
DUK_BIDX_ARRAYBUFFER_PROTOTYPE);
DUK_ASSERT(h_res != NULL);
DUK_UNREF(h_res);
duk__set_bufobj_buffer(thr, h_res, h_buf);
DUK_HBUFOBJ_ASSERT_VALID(h_res);
DUK_ASSERT(h_res->buf_prop == NULL);
return h_res;
}
DUK_INTERNAL duk_ret_t duk_bi_typedarray_buffer_getter(duk_hthread *thr) {
duk_hbufobj *h_bufobj;
h_bufobj = (duk_hbufobj *) duk__getrequire_bufobj_this(thr, DUK__BUFOBJ_FLAG_THROW /*flags*/);
DUK_ASSERT(h_bufobj != NULL);
if (DUK_HEAPHDR_IS_BUFFER((duk_heaphdr *) h_bufobj)) {
DUK_DD(DUK_DDPRINT("autospawn ArrayBuffer for plain buffer"));
(void) duk__autospawn_arraybuffer(thr, (duk_hbuffer *) h_bufobj);
return 1;
} else {
if (h_bufobj->buf_prop == NULL &&
DUK_HOBJECT_GET_CLASS_NUMBER((duk_hobject *) h_bufobj) != DUK_HOBJECT_CLASS_ARRAYBUFFER &&
h_bufobj->buf != NULL) {
duk_hbufobj *h_arrbuf;
DUK_DD(DUK_DDPRINT("autospawn ArrayBuffer for typed array or DataView"));
h_arrbuf = duk__autospawn_arraybuffer(thr, h_bufobj->buf);
if (h_bufobj->buf_prop == NULL) {
/* Must recheck buf_prop, in case ArrayBuffer
* alloc had a side effect which already filled
* it!
*/
/* Set ArrayBuffer's .byteOffset and .byteLength based
* on the view so that Arraybuffer[view.byteOffset]
* matches view[0].
*/
h_arrbuf->offset = 0;
DUK_ASSERT(h_bufobj->offset + h_bufobj->length >= h_bufobj->offset); /* Wrap check on creation. */
h_arrbuf->length = h_bufobj->offset + h_bufobj->length;
DUK_ASSERT(h_arrbuf->buf_prop == NULL);
DUK_ASSERT(h_bufobj->buf_prop == NULL);
h_bufobj->buf_prop = (duk_hobject *) h_arrbuf;
DUK_HBUFOBJ_INCREF(thr, h_arrbuf); /* Now reachable and accounted for. */
}
/* Left on stack; pushed for the second time below (OK). */
}
if (h_bufobj->buf_prop) {
duk_push_hobject(thr, h_bufobj->buf_prop);
return 1;
}
}
return 0;
}
DUK_INTERNAL duk_ret_t duk_bi_typedarray_byteoffset_getter(duk_hthread *thr) {
duk_hbufobj *h_bufobj;
h_bufobj = (duk_hbufobj *) duk__getrequire_bufobj_this(thr, DUK__BUFOBJ_FLAG_THROW /*flags*/);
DUK_ASSERT(h_bufobj != NULL);
if (DUK_HEAPHDR_IS_BUFFER((duk_heaphdr *) h_bufobj)) {
duk_push_uint(thr, 0);
} else {
/* If neutered must return 0; offset is zeroed during
* neutering.
*/
duk_push_uint(thr, h_bufobj->offset);
}
return 1;
}
DUK_INTERNAL duk_ret_t duk_bi_typedarray_bytelength_getter(duk_hthread *thr) {
duk_hbufobj *h_bufobj;
h_bufobj = (duk_hbufobj *) duk__getrequire_bufobj_this(thr, DUK__BUFOBJ_FLAG_THROW /*flags*/);
DUK_ASSERT(h_bufobj != NULL);
if (DUK_HEAPHDR_IS_BUFFER((duk_heaphdr *) h_bufobj)) {
duk_hbuffer *h_buf;
h_buf = (duk_hbuffer *) h_bufobj;
DUK_ASSERT(DUK_HBUFFER_GET_SIZE(h_buf) <= DUK_UINT_MAX); /* Buffer limits. */
duk_push_uint(thr, (duk_uint_t) DUK_HBUFFER_GET_SIZE(h_buf));
} else {
/* If neutered must return 0; length is zeroed during
* neutering.
*/
duk_push_uint(thr, h_bufobj->length);
}
return 1;
}
#else /* DUK_USE_BUFFEROBJECT_SUPPORT */
/* No .buffer getter without ArrayBuffer support. */
#if 0
DUK_INTERNAL duk_ret_t duk_bi_typedarray_buffer_getter(duk_hthread *thr) {
return 0;
}
#endif
DUK_INTERNAL duk_ret_t duk_bi_typedarray_byteoffset_getter(duk_hthread *thr) {
duk_push_uint(thr, 0);
return 1;
}
DUK_INTERNAL duk_ret_t duk_bi_typedarray_bytelength_getter(duk_hthread *thr) {
duk_hbuffer *h_buf;
/* XXX: helper? */
duk_push_this(thr);
h_buf = duk_require_hbuffer(thr, -1);
duk_push_uint(thr, DUK_HBUFFER_GET_SIZE(h_buf));
return 1;
}
#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */
|
60f8e94dcf3256398296bf489ae4bb85224eb30c
|
b0f08154e3eebc7d8465efc57597e52d08d69c18
|
/src/base/memory_hash.c
|
0f235058687f048c7a9765b7e6650fbd49badd07
|
[
"BSD-3-Clause",
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference"
] |
permissive
|
CUBRID/cubrid
|
8f71a0010243b72e43ba887d229210650f4e901e
|
3b952af33230839a1b561a78ecd4b773374b66f8
|
refs/heads/develop
| 2023-08-18T19:16:30.987583
| 2023-08-18T08:18:05
| 2023-08-18T08:18:05
| 52,080,367
| 287
| 294
|
NOASSERTION
| 2023-09-14T21:29:09
| 2016-02-19T10:25:32
|
C
|
UTF-8
|
C
| false
| false
| 69,125
|
c
|
memory_hash.c
|
/*
* Copyright 2008 Search Solution Corporation
* Copyright 2016 CUBRID Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
/*
* memory_hash.c - memory hash table
*/
#ident "$Id$"
/*
* The structure of the hash table is approximately as follows;
*
* Hash Table header
* -----------------
* |hash_fun |
* |cmp_fun |
* |table_name |
* |Ptr to entries-----> The entries
* |size | -------------------
* |rehash_at | | key, data, next |--> ... -> key, data, next
* |num_entries | | . |
* |num_collisions | | . |
* ----------------- | . |
* -------------------
*/
#include "config.h"
#include <stdio.h>
#include <assert.h>
#include "memory_hash.h"
#include "chartype.h"
#include "misc_string.h"
#include "error_manager.h"
#include "memory_alloc.h"
#include "message_catalog.h"
#include "environment_variable.h"
#include "set_object.h"
#include "language_support.h"
#include "intl_support.h"
#include "object_primitive.h"
#include "dbtype.h"
#if __WORDSIZE == 32
#define GET_PTR_FOR_HASH(key) ((unsigned int)(key))
#else
#define GET_PTR_FOR_HASH(key) (((UINT64)(key)) & 0xFFFFFFFFUL)
#endif
/* constants for rehash */
static const float MHT_REHASH_TRESHOLD = 0.7f;
static const float MHT_REHASH_FACTOR = 1.3f;
/* options for mht_put() */
enum mht_put_opt
{
MHT_OPT_DEFAULT = 0,
MHT_OPT_KEEP_KEY = 1,
MHT_OPT_INSERT_ONLY = 2,
MHT_OPT_INSERT_IF_NOT_EXISTS = 4
};
typedef enum mht_put_opt MHT_PUT_OPT;
/*
* A table of prime numbers.
*
* Some prime numbers which were picked randomly.
* This table contains more smaller prime numbers.
* Some of the prime numbers included are:
* between 1000 and 2000, prime numbers that are farther than 50 units.
* between 2000 and 7000, prime numbers that are farther than 100 units.
* between 7000 and 12000, prime numbers that are farther than 200 units.
* between 12000 and 17000, prime numbers that are farther than 400 units.
* between 17000 and 22000, prime numbers that are farther than 800 units.
* above 22000, prime numbers that are farther than 1000 units.
*
* Note: if x is a prime number, the n is prime if X**(n-1) mod n == 1
*/
static unsigned int mht_1str_pseudo_key (const void *key, int key_size);
static unsigned int mht_3str_pseudo_key (const void *key, int key_size, const unsigned int max_value);
static unsigned int mht_4str_pseudo_key (const void *key, int key_size);
static unsigned int mht_5str_pseudo_key (const void *key, int key_size);
static int mht_rehash (MHT_TABLE * ht);
static const void *mht_put_internal (MHT_TABLE * ht, const void *key, void *data, MHT_PUT_OPT opt);
static const void *mht_put2_internal (MHT_TABLE * ht, const void *key, void *data, MHT_PUT_OPT opt);
static const void *mht_put_hls_internal (MHT_HLS_TABLE * ht, const void *key, void *data, MHT_PUT_OPT opt);
static unsigned int mht_get_shiftmult32 (unsigned int key, const unsigned int ht_size);
#if defined (ENABLE_UNUSED_FUNCTION)
static unsigned int mht_get32_next_power_of_2 (unsigned int const ht_size);
static unsigned int mht_get_linear_hash32 (const unsigned int key, const unsigned int ht_size);
#endif /* ENABLE_UNUSED_FUNCTION */
/*
* Several hasing functions for different data types
*/
/*
* mht_1str_pseudo_key() - hash string key into pseudo integer key
* return: pseudo integer key
* key(in): string key to hash
* key_size(in): size of key or -1 when unknown
*
* Note: It generates a pseudo integer key based on Gosling's emacs hash
* function.
*/
static unsigned int
mht_1str_pseudo_key (const void *key, int key_size)
{
unsigned const char *byte_p = (unsigned char *) key;
unsigned int pseudo_key;
assert (key != NULL);
for (pseudo_key = 0;; byte_p++)
{
if (key_size == -1)
{
if (!(*byte_p))
{
break;
}
}
else
{
if (key_size <= 0)
{
break;
}
}
pseudo_key = (pseudo_key << 5) - pseudo_key + *byte_p;
if (key_size > 0)
{
key_size--;
}
}
return pseudo_key;
}
/*
* mht_2str_pseudo_key() - hash string key into pseudo integer key
* return: pseudo integer key
* key(in): string key to hash
* key_size(in): size of key or -1 when unknown
*
* Note: It generates a pseudo integer key based on hash function from
* Aho, Sethi, and Ullman's dragon book; pp. 436.
* This function can handles strings when they are binary different.
* For collation dependent function use 'mht2str'.
*/
unsigned int
mht_2str_pseudo_key (const void *key, int key_size)
{
unsigned const char *byte_p = (unsigned char *) key;
unsigned int pseudo_key;
unsigned int i;
assert (key != NULL);
for (pseudo_key = 0;; byte_p++)
{
if (key_size == -1)
{
if (!(*byte_p))
{
break;
}
}
else
{
if (key_size <= 0)
{
break;
}
}
pseudo_key = (pseudo_key << 4) + *byte_p;
i = pseudo_key & 0xf0000000;
if (i != 0)
{
pseudo_key ^= i >> 24;
pseudo_key ^= i;
}
if (key_size > 0)
{
key_size--;
}
}
return pseudo_key;
}
/*
* mht_3str_pseudo_key() - hash string key into pseudo integer key
* return: pseudo integer key
* key(in): string key to hash
* key_size(in): size of key or -1 when unknown
* max_value(in) : generally a prime number which represents the size of hash
* table
*
* Note: It generates a pseudo integer key based on hash function from
* Sedgewick's Algorithm book. The function needs a prime number for
* the range. This prime number is usually the hash table size.
*/
static unsigned int
mht_3str_pseudo_key (const void *key, int key_size, const unsigned int max_value)
{
unsigned const char *byte_p = (unsigned char *) key;
unsigned int pseudo_key = 0;
assert (key != NULL);
for (pseudo_key = 0;; byte_p++)
{
if (key_size == -1)
{
if (!(*byte_p))
{
break;
}
}
else
{
if (key_size <= 0)
{
break;
}
}
pseudo_key = (pseudo_key * 32 + *byte_p++) % max_value;
if (key_size > 0)
{
key_size--;
}
}
return pseudo_key;
}
/*
* mht_4str_pseudo_key() - hash string key into pseudo integer key
* return: pseudo integer key
* key(in): string key to hash
* key_size(in): size of key or -1 when unknown
*
* Note: It generates four values between 0 and 255, concatenate them,
* and returns the result.
* Based on Fast Hashing of Variable-Length Text Strings
* by Peter K. Pearson Communications of the ACM, June 1990.
*/
static unsigned int
mht_4str_pseudo_key (const void *key, int key_size)
{
/* a permutation of values 0 to 255 */
unsigned char tbl[] = {
166, 231, 148, 061, 050, 131, 000, 057, 126, 223,
044, 245, 138, 251, 24, 113, 86, 215, 196, 173,
226, 115, 48, 169, 46, 207, 92, 101, 58, 235,
72, 225, 6, 199, 244, 29, 146, 99, 96, 25,
222, 191, 140, 213, 234, 219, 120, 81, 182, 183,
36, 141, 66, 83, 144, 137, 142, 175, 188, 69,
154, 203, 168, 193, 102, 167, 84, 253, 242, 67,
192, 249, 62, 159, 236, 181, 74, 187, 216, 49,
22, 151, 132, 109, 162, 51, 240, 105, 238, 143,
28, 37, 250, 171, 8, 161, 198, 135, 180, 221,
82, 35, 32, 217, 158, 127, 76, 149, 170, 155,
56, 17, 118, 119, 228, 77, 2, 19, 80, 73, 78,
111, 124, 5, 90, 139, 104, 129, 38, 103, 20,
189, 178, 3, 128, 185, 254, 95, 172, 117, 10,
123, 152, 241, 214, 87, 68, 45, 98, 243, 176,
41, 174, 79, 220, 229, 186, 107, 200, 97, 134,
71, 116, 157, 18, 227, 224, 153, 94, 63, 12,
85, 106, 91, 248, 209, 54, 55, 164, 13, 194,
211, 16, 9, 14, 47, 60, 197, 26, 75, 40,
65, 230, 39, 212, 125, 114, 195, 64, 121, 190,
31, 108, 53, 202, 59, 88, 177, 150, 23, 4,
237, 34, 179, 112, 233, 110, 15, 156, 165, 122,
43, 136, 33, 70, 7, 52, 93, 210, 163, 160,
89, 30, 255, 204, 21, 42, 27, 184, 145, 246,
247, 100, 205, 130, 147, 208, 201, 206, 239, 252,
133, 218, 11, 232, 1, 0
};
unsigned int byte1, byte2, byte3, byte4;
unsigned const char *byte_p = (unsigned char *) key;
assert (key != NULL);
byte1 = tbl[*byte_p];
byte2 = tbl[(unsigned int) (*byte_p + 1) % 256];
byte3 = tbl[(unsigned int) (*byte_p + 2) % 256];
byte4 = tbl[(unsigned int) (*byte_p + 3) % 256];
if (key_size == -1)
{
if (*byte_p)
{
byte_p++;
}
}
else if (key_size > 0)
{
byte_p++;
key_size--;
}
for (;; byte_p++)
{
if (key_size == -1)
{
if (!(*byte_p))
{
break;
}
}
else
{
if (key_size <= 0)
{
break;
}
}
/*
* Each of the following hash values,
* generates a value between 0 and 255
*/
byte1 = tbl[byte1 ^ *byte_p];
byte2 = tbl[byte2 ^ *byte_p];
byte3 = tbl[byte3 ^ *byte_p];
byte4 = tbl[byte4 ^ *byte_p];
if (key_size > 0)
{
key_size--;
}
}
/* Concatenate all the values */
return (byte1 | (byte2 << 8) | (byte3 << 16) | (byte4 << 24));
}
/*
* mht_5str_pseudo_key() - hash string key into pseudo integer key
* return: pseudo integer key
* key(in): string key to hash
* key_size(in): size of key or -1 when unknown
*
* Note: Based on hash method reported by Diniel J. Bernstein.
*/
static unsigned int
mht_5str_pseudo_key (const void *key, int key_size)
{
unsigned int hash = 5381;
int i = 0;
char *k;
assert (key != NULL);
k = (char *) key;
if (key_size == -1)
{
int c;
while ((c = *(k + i++)) != 0)
{
hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
}
}
else
{
for (; i < key_size; i++)
{
hash = ((hash << 5) + hash) + *(k + i);
}
}
hash += ~(hash << 9);
hash ^= ((hash >> 14) | (i << 18)); /* >>> */
hash += (hash << 4);
hash ^= ((hash >> 10) | (i << 22)); /* >>> */
return hash;
}
/*
* mht_1strlowerhash - hash a string key (in lowercase)
* return: hash value
* key(in): key to hash
* ht_size(in): size of hash table
*
* Note: Taken from Gosling's emacs
* This handles only ASCII characters; for charset-independent version
* use 'intl_identifier_mht_1strlowerhash'
*/
unsigned int
mht_1strlowerhash (const void *key, const unsigned int ht_size)
{
unsigned int hash;
unsigned const char *byte_p = (unsigned char *) key;
unsigned int ch;
assert (key != NULL);
for (hash = 0; *byte_p; byte_p++)
{
/* TODO: Original comment originally this way but due to compiler problems on the PC, it doesn't always work
* consistently: hash = (hash << 5) - hash + tolower(*key++); */
ch = char_tolower (*byte_p);
hash = (hash << 5) - hash + ch;
}
return hash % ht_size;
}
/*
* mht_1strhash - hash a string key
* return: hash value
* key(in): key to hash
* ht_size(in): size of hash table
*
* Note: Taken from Gosling's emacs
*/
unsigned int
mht_1strhash (const void *key, const unsigned int ht_size)
{
assert (key != NULL);
return mht_1str_pseudo_key (key, -1) % ht_size;
}
/*
* mht_2strhash - hash a string key
* return: hash value
* key(in): key to hash
* ht_size(in): size of hash table
*
* Note: Form to hash strings.
* Taken from Aho, Sethi, and Ullman's dragon book; pp. 436.
* This function uses 'mht_2str_pseudo_key'.
* For collation dependent function use 'mht2str'.
*/
unsigned int
mht_2strhash (const void *key, const unsigned int ht_size)
{
assert (key != NULL);
return mht_2str_pseudo_key (key, -1) % ht_size;
}
/*
* mht_3strhash - hash a string key
* return: hash value
* key(in): key to hash
* ht_size(in): size of hash table
*
* Note: Form to hash strings.
* Taken from Sedgewick's Algorithm book
*/
unsigned int
mht_3strhash (const void *key, const unsigned int ht_size)
{
assert (key != NULL);
return mht_3str_pseudo_key (key, -1, ht_size);
}
/*
* mht_4strhash - hash a string key
* return: hash value
* key(in): key to hash
* ht_size(in): size of hash table
*
* Note: Form to hash strings.
* It generates four values between 0 and 255, concatenate them
* and applies the mod.
*
* Based on Fast Hashing of Variable-Length Text Strings
* by Peter K. Pearson
* Communications of the ACM, June 1990.
*/
unsigned int
mht_4strhash (const void *key, const unsigned int ht_size)
{
assert (key != NULL);
return mht_4str_pseudo_key (key, -1) % ht_size;
}
/*
* mht_5strhash - hash a string key
* return: hash value
* key(in): key to hash
* ht_size(in): size of hash table
*
* Note: Based on hash method reported by Diniel J. Bernstein.
*/
unsigned int
mht_5strhash (const void *key, const unsigned int ht_size)
{
return mht_5str_pseudo_key (key, -1) % ht_size;
}
/*
* mht_numash - hash an integer key
* return: hash value
* key(in): void pointer to integer key to hash
* ht_size(in): size of hash table
*/
unsigned int
mht_numhash (const void *key, const unsigned int ht_size)
{
assert (key != NULL);
return (*(const unsigned int *) key) % ht_size;
}
/*
* mht_ptrhash - hash a pointer key (hash memory pointers)
* return: hash value
* key(in): pointer value key to hash
* ht_size(in): size of hash table
*/
unsigned int
mht_ptrhash (const void *key, const unsigned int ht_size)
{
assert (key != NULL);
return GET_PTR_FOR_HASH (key) % ht_size;
}
/*
* mht_valhash - hash a DB_VALUE key
* return: hash value
* key(in): pointer to DB_VALUE key to hash
* ht_size(in): size of hash table
*/
unsigned int
mht_valhash (const void *key, const unsigned int ht_size)
{
unsigned int hash = 0;
const DB_VALUE *val = (const DB_VALUE *) key;
int t_n;
DB_VALUE t_val;
if (key != NULL)
{
switch (db_value_type (val))
{
case DB_TYPE_NULL:
hash = 0;
break;
case DB_TYPE_INTEGER:
hash = (unsigned int) db_get_int (val);
break;
case DB_TYPE_SHORT:
hash = (unsigned int) db_get_short (val);
break;
case DB_TYPE_BIGINT:
{
DB_BIGINT bigint;
unsigned int x, y;
bigint = db_get_bigint (val);
x = bigint >> 32;
y = (unsigned int) bigint;
hash = x ^ y;
break;
}
case DB_TYPE_FLOAT:
hash = (unsigned int) db_get_float (val);
break;
case DB_TYPE_DOUBLE:
hash = (unsigned int) db_get_double (val);
break;
case DB_TYPE_NUMERIC:
hash = mht_1str_pseudo_key (db_get_numeric (val), -1);
break;
case DB_TYPE_CHAR:
case DB_TYPE_NCHAR:
case DB_TYPE_VARCHAR:
case DB_TYPE_VARNCHAR:
hash = mht_1str_pseudo_key (db_get_string (val), db_get_string_size (val));
break;
case DB_TYPE_BIT:
case DB_TYPE_VARBIT:
hash = mht_1str_pseudo_key (db_get_bit (val, &t_n), -1);
break;
case DB_TYPE_TIME:
{
unsigned int *time = db_get_time (val);
hash = (unsigned int) (*time);
break;
}
case DB_TYPE_TIMESTAMP:
case DB_TYPE_TIMESTAMPLTZ:
{
DB_TIMESTAMP *time_st = db_get_timestamp (val);
hash = (unsigned int) (*time_st);
break;
}
case DB_TYPE_TIMESTAMPTZ:
{
DB_TIMESTAMPTZ *ts_tz = db_get_timestamptz (val);
hash = (unsigned int) (ts_tz->timestamp);
}
break;
case DB_TYPE_DATETIME:
case DB_TYPE_DATETIMELTZ:
{
DB_DATETIME *datetime;
datetime = db_get_datetime (val);
hash = (unsigned int) (datetime->date ^ datetime->time);
}
break;
case DB_TYPE_DATETIMETZ:
{
DB_DATETIMETZ *dt_tz;
dt_tz = db_get_datetimetz (val);
hash = (unsigned int) (dt_tz->datetime.date ^ dt_tz->datetime.time);
}
break;
case DB_TYPE_DATE:
{
DB_DATE *date = db_get_date (val);
hash = (unsigned int) (*date);
break;
}
case DB_TYPE_MONETARY:
{
DB_MONETARY *mon = db_get_monetary (val);
hash = (unsigned int) mon->amount;
break;
}
case DB_TYPE_SET:
case DB_TYPE_MULTISET:
case DB_TYPE_SEQUENCE:
db_make_null (&t_val);
{
DB_SET *set;
set = db_get_set (val);
if (set_get_element (set, 0, &t_val) == NO_ERROR)
{
hash = mht_valhash (&t_val, ht_size);
(void) pr_clear_value (&t_val);
t_n = set_size (set);
if ((t_n > 0) && set_get_element (set, t_n - 1, &t_val) == NO_ERROR)
{
hash += mht_valhash (&t_val, ht_size);
(void) pr_clear_value (&t_val);
}
}
}
break;
case DB_TYPE_OBJECT:
hash = GET_PTR_FOR_HASH (db_get_object (val));
break;
case DB_TYPE_OID:
hash = (unsigned int) OID_PSEUDO_KEY (db_get_oid (val));
break;
case DB_TYPE_MIDXKEY:
db_make_null (&t_val);
{
DB_MIDXKEY *midxkey;
midxkey = db_get_midxkey (val);
if (pr_midxkey_get_element_nocopy (midxkey, 0, &t_val, NULL, NULL) == NO_ERROR)
{
hash = mht_valhash (&t_val, ht_size);
t_n = midxkey->size;
if (t_n > 0 && pr_midxkey_get_element_nocopy (midxkey, t_n - 1, &t_val, NULL, NULL) == NO_ERROR)
{
hash += mht_valhash (&t_val, ht_size);
}
}
}
break;
case DB_TYPE_POINTER:
hash = GET_PTR_FOR_HASH (db_get_pointer (val));
break;
case DB_TYPE_BLOB:
case DB_TYPE_CLOB:
case DB_TYPE_SUB:
case DB_TYPE_ERROR:
case DB_TYPE_VOBJ:
case DB_TYPE_DB_VALUE:
case DB_TYPE_RESULTSET:
case DB_TYPE_TABLE:
default:
hash = GET_PTR_FOR_HASH (val);
break;
}
}
return hash % ht_size;
}
/*
* Compare functions for datatypes
*/
/*
* mht_compare_ints_are_equal - compare two integer keys
* return: 0 or 1 (key1 == key2)
* key1(in): pointer to integer key1
* key2(in): pointer to integer key2
*/
int
mht_compare_ints_are_equal (const void *key1, const void *key2)
{
return ((*(const int *) key1 == *(const int *) key2));
}
/*
* mht_logpageid_compare_equal - compare two LOG_PAGEID keys
* return: 0 or 1 (key1 == key2)
* key1(in): pointer to LOG_PAGEID key1
* key2(in): pointer to LOG_PAGEID key2
*/
int
mht_compare_logpageids_are_equal (const void *key1, const void *key2)
{
return ((*(const LOG_PAGEID *) key1 == *(const LOG_PAGEID *) key2));
}
/*
* mht_compare_identifiers_equal - compare two identifiers keys (ignoring case)
* return: 0 or 1 (key1 == key2)
* key1(in): pointer to string key1
* key2(in): pointer to string key2
*/
int
mht_compare_identifiers_equal (const void *key1, const void *key2)
{
return ((intl_identifier_casecmp ((const char *) key1, (const char *) key2)) == 0);
}
/*
* mht_compare_strings_are_equal - compare two string keys (case sensitive)
* return: 0 or 1 (key1 == key2)
* key1(in): pointer to string key1
* key2(in): pointer to string key2
*/
int
mht_compare_strings_are_equal (const void *key1, const void *key2)
{
return ((strcmp ((const char *) key1, (const char *) key2)) == 0);
}
/*
* mht_compare_ptrs_are_equal - compare two pointer keys
* return: 0 or 1 (key1 == key2)
* key1(in): pointer key1
* key2(in): pointer key2
*/
int
mht_compare_ptrs_are_equal (const void *key1, const void *key2)
{
return (key1 == key2);
}
/*
* mht_compare_dbvalues_are_equal - compare two DB_VALUEs
* return: 0 or 1 (key1 == key2)
* key1(in): pointer to DB_VALUE key1
* key2(in): pointer to DB_VALUE key2
*/
int
mht_compare_dbvalues_are_equal (const void *key1, const void *key2)
{
return ((key1 == key2) || (tp_value_compare ((DB_VALUE *) key1, (DB_VALUE *) key2, 1, 1) == DB_EQ));
}
/*
* mht_calculate_htsize - find a good hash table size
* return: adjusted hash table size
* ht_size(in): given hash table size
*
* Note: Find a good size for a hash table. A prime number is the best
* size for a hash table, unfortunately prime numbers are
* difficult to found. If the given htsize, falls among the
* prime numbers known by this module, a close prime number to
* the given htsize value is returned, otherwise, a power of two
* is returned.
*/
#define NPRIMES 170
static const unsigned int mht_Primes[NPRIMES] = {
11, 23, 37, 53, 67, 79, 97, 109, 127, 149,
167, 191, 211, 227, 251, 269, 293, 311, 331, 349,
367, 389, 409, 431, 449, 467, 487, 509, 541, 563,
587, 607, 631, 653, 673, 521, 541, 557, 569, 587,
599, 613, 641, 673, 701, 727, 751, 787, 821, 853,
881, 907, 941, 977, 1039, 1087, 1129, 1171, 1213, 1259,
1301, 1361, 1409, 1471, 1523, 1579, 1637, 1693, 1747, 1777,
1823, 1867, 1913, 1973, 2017, 2129, 2237, 2339, 2441, 2543,
2647, 2749, 2851, 2953, 3061, 3163, 3271, 3373, 3491, 3593,
3697, 3803, 3907, 4013, 4177, 4337, 4493, 4649, 4801, 4957,
5059, 5167, 5273, 5381, 5483, 5591, 5693, 5801, 5903, 6007,
6113, 6217, 6317, 6421, 6521, 6637, 6737, 6841, 6847, 7057,
7283, 7487, 7687, 7901, 8101, 8311, 8513, 8713, 8923, 9127,
9337, 9539, 9739, 9941, 10141, 10343, 10559, 10771, 10973, 11177,
11383, 11587, 11789, 12007, 12409, 12809, 13217, 13619, 14029, 14431,
14831, 15233, 15641, 16057, 16477, 16879, 17291, 18097, 18899, 19699,
20507, 21313, 22123, 23131, 24133, 25147, 26153, 27179, 28181, 29123
};
unsigned int
mht_calculate_htsize (unsigned int ht_size)
{
int left, right, middle; /* indices for binary search */
if (ht_size > mht_Primes[NPRIMES - 1])
{
/* get a power of two */
if (!((ht_size & (ht_size - 1)) == 0))
{
/* Turn off some bits but the left most one */
while (!(ht_size & (ht_size - 1)))
{
ht_size &= (ht_size - 1);
}
ht_size <<= 1;
}
}
else
{
/* we can assign a primary number; binary search */
for (middle = 0, left = 0, right = NPRIMES - 1; left <= right;)
{
middle = CEIL_PTVDIV ((left + right), 2);
if (ht_size == mht_Primes[middle])
{
break;
}
else if (ht_size > mht_Primes[middle])
{
left = middle + 1;
}
else
{
right = middle - 1;
}
}
/* If we didn't find the size, get the larger size and not the small one */
if (ht_size > mht_Primes[middle] && middle < (NPRIMES - 1))
{
middle++;
}
ht_size = mht_Primes[middle];
}
return ht_size;
}
/*
* mht_create - create a hash table
* return: hash table
* name(in): name of hash table
* est_size(in): estimated number of entries
* hash_func(in): hash function
* cmp_func(in): key compare function
*
* Note: Create a new hash table. The estimated number of entries for
* the hash table may be adjusted (to a prime number) in order to
* obtain certain favorable circumstances when the table is
* created, when the table is almost full and there are at least
* 5% of collisions. 'hash_func' must return an integer between 0 and
* table_size - 1. 'cmp_func' must return TRUE if key1 = key2,
* otherwise, FALSE.
*/
MHT_TABLE *
mht_create (const char *name, int est_size, unsigned int (*hash_func) (const void *key, unsigned int ht_size),
int (*cmp_func) (const void *key1, const void *key2))
{
MHT_TABLE *ht;
HENTRY_PTR *hvector; /* Entries of hash table */
unsigned int ht_estsize;
size_t size;
assert (hash_func != NULL && cmp_func != NULL);
/* Get a good number of entries for hash table */
if (est_size <= 0)
{
est_size = 2;
}
ht_estsize = mht_calculate_htsize ((unsigned int) est_size);
/* Allocate the header information for hash table */
ht = (MHT_TABLE *) malloc (DB_SIZEOF (MHT_TABLE));
if (ht == NULL)
{
er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_OUT_OF_VIRTUAL_MEMORY, 1, DB_SIZEOF (MHT_TABLE));
return NULL;
}
/* Initialize the chunky memory manager */
ht->heap_id = db_create_fixed_heap (DB_SIZEOF (HENTRY), MAX (2, ht_estsize / 2 + 1));
if (ht->heap_id == 0)
{
er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_OUT_OF_VIRTUAL_MEMORY, 1, DB_SIZEOF (HENTRY));
free_and_init (ht);
return NULL;
}
/* Allocate the hash table entry pointers */
size = ht_estsize * DB_SIZEOF (*hvector);
hvector = (HENTRY_PTR *) malloc (size);
if (hvector == NULL)
{
er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_OUT_OF_VIRTUAL_MEMORY, 1, size);
db_destroy_fixed_heap (ht->heap_id);
free_and_init (ht);
return NULL;
}
ht->hash_func = hash_func;
ht->cmp_func = cmp_func;
ht->name = name;
ht->table = hvector;
ht->act_head = NULL;
ht->act_tail = NULL;
ht->lru_head = NULL;
ht->lru_tail = NULL;
ht->prealloc_entries = NULL;
ht->size = ht_estsize;
ht->rehash_at = (unsigned int) (ht_estsize * MHT_REHASH_TRESHOLD);
ht->nentries = 0;
ht->nprealloc_entries = 0;
ht->ncollisions = 0;
ht->build_lru_list = false;
/* Initialize each of the hash entries */
for (; ht_estsize > 0; ht_estsize--)
{
*hvector++ = NULL;
}
return ht;
}
/*
* mht_create_hls - create a hash table
* return: hash table
* name(in): name of hash table
* est_size(in): estimated number of entries
* hash_func(in): hash function
* cmp_func(in): key compare function
*
* Note: Create a new hash table for HASH LIST SCAN.
* The estimated number of entries for the hash table is fixed in HASH LIST SCAN.
* rehashing hash table is not needed becaues of that.
* key comparison is performed in executor.
*/
MHT_HLS_TABLE *
mht_create_hls (const char *name, int est_size, unsigned int (*hash_func) (const void *key, unsigned int ht_size),
int (*cmp_func) (const void *key1, const void *key2))
{
MHT_HLS_TABLE *ht;
HENTRY_HLS_PTR *hvector; /* Entries of hash table */
unsigned int ht_estsize;
size_t size;
/* Get a good number of entries for hash table */
if (est_size <= 0)
{
est_size = 2;
}
ht_estsize = mht_calculate_htsize ((unsigned int) est_size);
/* Allocate the header information for hash table */
ht = (MHT_HLS_TABLE *) malloc (DB_SIZEOF (MHT_HLS_TABLE));
if (ht == NULL)
{
er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_OUT_OF_VIRTUAL_MEMORY, 1, DB_SIZEOF (MHT_HLS_TABLE));
return NULL;
}
/* Initialize the chunky memory manager */
ht->heap_id = db_create_fixed_heap (DB_SIZEOF (HENTRY_HLS), MAX (2, ht_estsize / 2 + 1));
if (ht->heap_id == 0)
{
er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_OUT_OF_VIRTUAL_MEMORY, 1, DB_SIZEOF (HENTRY_HLS));
free_and_init (ht);
return NULL;
}
/* Allocate the hash table entry pointers */
size = ht_estsize * DB_SIZEOF (*hvector);
hvector = (HENTRY_HLS_PTR *) malloc (size);
if (hvector == NULL)
{
er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_OUT_OF_VIRTUAL_MEMORY, 1, size);
db_destroy_fixed_heap (ht->heap_id);
free_and_init (ht);
return NULL;
}
ht->hash_func = hash_func;
ht->cmp_func = cmp_func;
ht->name = name;
ht->table = hvector;
ht->prealloc_entries = NULL;
ht->size = ht_estsize;
ht->nentries = 0;
ht->nprealloc_entries = 0;
ht->ncollisions = 0;
ht->build_lru_list = false;
/* Initialize each of the hash entries */
for (; ht_estsize > 0; ht_estsize--)
{
*hvector++ = NULL;
}
return ht;
}
/*
* mht_rehash - rehash all entires of a hash table
* return: error code
* ht(in/out): hash table to rehash
*
* Note: Expand a hash table. All entries are rehashed onto a larger
* hash table of entries.
*/
static int
mht_rehash (MHT_TABLE * ht)
{
HENTRY_PTR *new_hvector; /* New entries of hash table */
HENTRY_PTR *hvector; /* Entries of hash table */
HENTRY_PTR hentry; /* A hash table entry. linked list */
HENTRY_PTR next_hentry = NULL; /* Next element in linked list */
float rehash_factor;
unsigned int hash;
unsigned int est_size;
size_t size;
unsigned int i;
/* Find an estimated size for hash table entries */
rehash_factor = (float) (1.0 + ((float) ht->ncollisions / (float) ht->nentries));
if (MHT_REHASH_FACTOR > rehash_factor)
{
est_size = (unsigned int) (ht->size * MHT_REHASH_FACTOR);
}
else
{
est_size = (unsigned int) (ht->size * rehash_factor);
}
est_size = mht_calculate_htsize (est_size);
/* Allocate a new vector to keep the estimated hash entries */
size = est_size * DB_SIZEOF (*hvector);
new_hvector = (HENTRY_PTR *) malloc (size);
if (new_hvector == NULL)
{
er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_OUT_OF_VIRTUAL_MEMORY, 1, size);
return ER_OUT_OF_VIRTUAL_MEMORY;
}
/* Initialize all entries */
memset (new_hvector, 0x00, size);
/* Now rehash the current entries onto the vector of hash entries table */
for (ht->ncollisions = 0, hvector = ht->table, i = 0; i < ht->size; hvector++, i++)
{
/* Go over each linked list */
for (hentry = *hvector; hentry != NULL; hentry = next_hentry)
{
next_hentry = hentry->next;
hash = (*ht->hash_func) (hentry->key, est_size);
if (hash >= est_size)
{
hash %= est_size;
}
/* Link the new entry with any previous elements */
hentry->next = new_hvector[hash];
if (hentry->next != NULL)
{
ht->ncollisions++;
}
new_hvector[hash] = hentry;
}
}
/* Now move to new vector of entries */
free_and_init (ht->table);
ht->table = new_hvector;
ht->size = est_size;
ht->rehash_at = (int) (est_size * MHT_REHASH_TRESHOLD);
return NO_ERROR;
}
/*
* mht_destroy - destroy a hash table
* return: void
* ht(in/out): hash table
*
* Note: ht is set as a side effect
*/
void
mht_destroy (MHT_TABLE * ht)
{
assert (ht != NULL);
free_and_init (ht->table);
/* release hash table entry storage */
db_destroy_fixed_heap (ht->heap_id);
free_and_init (ht);
}
/*
* mht_destroy_hls - destroy a hash table
* return: void
* ht(in/out): hash table
*
* Note: ht is set as a side effect
*/
void
mht_destroy_hls (MHT_HLS_TABLE * ht)
{
assert (ht != NULL);
free_and_init (ht->table);
/* release hash table entry storage */
db_destroy_fixed_heap (ht->heap_id);
free_and_init (ht);
}
/*
* mht_clear - remove and free all entries of hash table
* return: error code
* ht(in/out): hash table
* rem_func(in): removal function
* func_args(in): removal function arguments
*/
int
mht_clear (MHT_TABLE * ht, int (*rem_func) (const void *key, void *data, void *args), void *func_args)
{
HENTRY_PTR *hvector; /* Entries of hash table */
HENTRY_PTR hentry; /* A hash table entry. linked list */
HENTRY_PTR next_hentry = NULL; /* Next element in linked list */
unsigned int i, error_code;
assert (ht != NULL);
/*
* Go over the hash table, removing all entries and setting the vector
* entries to NULL.
*/
for (hvector = ht->table, i = 0; i < ht->size; hvector++, i++)
{
/* Go over the linked list for this hash table entry */
for (hentry = *hvector; hentry != NULL; hentry = next_hentry)
{
/* free */
if (rem_func)
{
error_code = (*rem_func) (hentry->key, hentry->data, func_args);
if (error_code != NO_ERROR)
{
return error_code;
}
hentry->key = NULL;
hentry->data = NULL;
}
next_hentry = hentry->next;
/* Save the entries for future insertions */
ht->nprealloc_entries++;
hentry->next = ht->prealloc_entries;
ht->prealloc_entries = hentry;
}
*hvector = NULL;
}
ht->act_head = NULL;
ht->act_tail = NULL;
ht->lru_head = NULL;
ht->lru_tail = NULL;
ht->ncollisions = 0;
ht->nentries = 0;
return NO_ERROR;
}
/*
* mht_hls_clear - remove and free all entries of hash table
* return: error code
* ht(in/out): hash table
* rem_func(in): removal function
* func_args(in): removal function arguments
*/
int
mht_clear_hls (MHT_HLS_TABLE * ht, int (*rem_func) (const void *key, void *data, void *args), void *func_args)
{
HENTRY_HLS_PTR *hvector; /* Entries of hash table */
HENTRY_HLS_PTR hentry; /* A hash table entry. linked list */
HENTRY_HLS_PTR next_hentry = NULL; /* Next element in linked list */
unsigned int i, error_code;
assert (ht != NULL);
/*
* Go over the hash table, removing all entries and setting the vector
* entries to NULL.
*/
for (hvector = ht->table, i = 0; i < ht->size; hvector++, i++)
{
/* Go over the linked list for this hash table entry */
for (hentry = *hvector; hentry != NULL; hentry = next_hentry)
{
/* free */
if (rem_func)
{
error_code = (*rem_func) (NULL, hentry->data, func_args);
if (error_code != NO_ERROR)
{
return error_code;
}
hentry->data = NULL;
}
next_hentry = hentry->next;
/* Save the entries for future insertions */
ht->nprealloc_entries++;
hentry->next = ht->prealloc_entries;
ht->prealloc_entries = hentry;
}
*hvector = NULL;
}
ht->ncollisions = 0;
ht->nentries = 0;
return NO_ERROR;
}
/*
* mht_dump - display all entries of hash table
* return: TRUE/FALSE
* out_fp(in): FILE stream where to dump; if NULL, stdout
* ht(in): hash table to print
* print_id_opt(in): option for printing hash index vector id
* print_func(in): supplied printing function
* func_args(in): arguments to be passed to print_func
*
* Note: Dump the header of hash table, and for each entry in hash table,
* call function "print_func" on three arguments: the key of the entry,
* the data associated with the key, and args, in order to print the entry
* print_id_opt - Print hash index ? Will run faster if we do not need to
* print this information
*/
int
mht_dump (THREAD_ENTRY * thread_p, FILE * out_fp, const MHT_TABLE * ht, const int print_id_opt,
int (*print_func) (THREAD_ENTRY * thread_p, FILE * fp, const void *key, void *data, void *args),
void *func_args)
{
HENTRY_PTR *hvector; /* Entries of hash table */
HENTRY_PTR hentry; /* A hash table entry. linked list */
unsigned int i;
int cont = TRUE;
assert (ht != NULL);
if (out_fp == NULL)
{
out_fp = stdout;
}
fprintf (out_fp,
"HTABLE NAME = %s, SIZE = %d, REHASH_AT = %d,\n" "NENTRIES = %d, NPREALLOC = %d, NCOLLISIONS = %d\n\n",
ht->name, ht->size, ht->rehash_at, ht->nentries, ht->nprealloc_entries, ht->ncollisions);
if (print_id_opt == -1)
{
/* noting to do */
}
else if (print_id_opt)
{
/* Need to print the index vector id. Therefore, scan the whole table */
for (hvector = ht->table, i = 0; i < ht->size; hvector++, i++)
{
if (*hvector != NULL)
{
fprintf (out_fp, "HASH AT %d\n", i);
/* Go over the linked list */
for (hentry = *hvector; cont == TRUE && hentry != NULL; hentry = hentry->next)
{
cont = (*print_func) (thread_p, out_fp, hentry->key, hentry->data, func_args);
}
}
}
}
else
{
/* Quick scan by following only the active entries */
for (hentry = ht->act_head; cont == TRUE && hentry != NULL; hentry = hentry->act_next)
{
cont = (*print_func) (thread_p, out_fp, hentry->key, hentry->data, func_args);
}
}
fprintf (out_fp, "\n");
return (cont);
}
/*
* mht_dump_hls - display all entries of hash table for HASH LIST SCAN
* return: TRUE/FALSE
* out_fp(in): FILE stream where to dump; if NULL, stdout
* ht(in): hash table to print
* print_id_opt(in): option for printing hash index vector id
* print_func(in): supplied printing function
* func_args(in): arguments to be passed to print_func
*
* Note: Dump the header of hash table, and for each entry in hash table,
* call function "print_func" on three arguments: the key of the entry,
* the data associated with the key, and args, in order to print the entry
* print_id_opt - Print hash index ? Will run faster if we do not need to
* print this information
*/
int
mht_dump_hls (THREAD_ENTRY * thread_p, FILE * out_fp, const MHT_HLS_TABLE * ht, const int print_id_opt,
int (*print_func) (THREAD_ENTRY * thread_p, FILE * fp, const void *data, void *args), void *func_args)
{
HENTRY_HLS_PTR *hvector; /* Entries of hash table */
HENTRY_HLS_PTR hentry; /* A hash table entry. linked list */
unsigned int i;
int cont = TRUE;
assert (ht != NULL);
if (out_fp == NULL)
{
out_fp = stdout;
}
fprintf (out_fp,
"HTABLE NAME = %s, SIZE = %d,\n" "NENTRIES = %d, NPREALLOC = %d, NCOLLISIONS = %d\n\n",
ht->name, ht->size, ht->nentries, ht->nprealloc_entries, ht->ncollisions);
if (print_id_opt)
{
/* Need to print the index vector id. Therefore, scan the whole table */
for (hvector = ht->table, i = 0; i < ht->size; hvector++, i++)
{
if (*hvector != NULL)
{
fprintf (out_fp, "HASH AT %d\n", i);
/* Go over the linked list */
for (hentry = *hvector; cont == TRUE && hentry != NULL; hentry = hentry->next)
{
cont = (*print_func) (thread_p, out_fp, hentry->data, func_args);
}
}
}
}
fprintf (out_fp, "\n");
return (cont);
}
/*
* mht_get - find data associated with key
* return: the data associated with the key, or NULL if not found
* ht(in): hash table
* key(in): hashing key
*
* Note: Find the entry in hash table whose key is the value of the given key
*/
void *
mht_get (MHT_TABLE * ht, const void *key)
{
unsigned int hash;
HENTRY_PTR hentry;
assert (ht != NULL);
assert (key != NULL);
/*
* Hash the key and make sure that the return value is between 0 and size
* of hash table
*/
hash = (*ht->hash_func) (key, ht->size);
if (hash >= ht->size)
{
hash %= ht->size;
}
/* now search the linked list */
for (hentry = ht->table[hash]; hentry != NULL; hentry = hentry->next)
{
if (hentry->key == key || (*ht->cmp_func) (hentry->key, key))
{
mht_adjust_lru_list (ht, hentry);
/* return value */
return hentry->data;
}
}
return NULL;
}
/*
* mht_adjust_lru_list -
* ht(in): hash table
* hentry(in): hash entry
*/
int
mht_adjust_lru_list (MHT_TABLE * ht, HENTRY_PTR hentry)
{
assert (ht && hentry);
if (ht && hentry && ht->build_lru_list && ht->lru_tail != hentry)
{
if (ht->lru_head == hentry)
{
ht->lru_head = hentry->lru_next;
}
/* unlink */
hentry->lru_next->lru_prev = hentry->lru_prev;
if (hentry->lru_prev)
{
hentry->lru_prev->lru_next = hentry->lru_next;
}
/* add at end */
ht->lru_tail->lru_next = hentry;
hentry->lru_prev = ht->lru_tail;
hentry->lru_next = NULL;
ht->lru_tail = hentry;
}
return NO_ERROR;
}
/*
* mht_get2 - Find the next data associated with the key; Search the entry next
* to the last result
* return: the data associated with the key, or NULL if not found
* ht(in):
* key(in):
* last(in/out):
*
* NOTE: This call does not affect the LRU list.
*/
void *
mht_get2 (const MHT_TABLE * ht, const void *key, void **last)
{
unsigned int hash;
HENTRY_PTR hentry;
assert (ht != NULL && key != NULL);
/*
* Hash the key and make sure that the return value is between 0 and size
* of hash table
*/
hash = (*ht->hash_func) (key, ht->size);
if (hash >= ht->size)
{
hash %= ht->size;
}
/* now search the linked list */
for (hentry = ht->table[hash]; hentry != NULL; hentry = hentry->next)
{
if (hentry->key == key || (*ht->cmp_func) (hentry->key, key))
{
if (last == NULL)
{
return hentry->data;
}
else if (*((HENTRY_PTR *) last) == NULL)
{
*((HENTRY_PTR *) last) = hentry;
return hentry->data;
}
else if (*((HENTRY_PTR *) last) == hentry)
{
/* found the last result; go forward one more step to get next the above 'if' will be true when the next
* one is found */
*((HENTRY_PTR *) last) = NULL;
}
}
}
return NULL;
}
/*
* mht_get_hls - Find the data associated with the key;
* return: the data associated with the key, or NULL if not found
* ht(in):
* key(in):
* last(in/out):
*
* NOTE: This call does not affect the LRU list.
*/
void *
mht_get_hls (const MHT_HLS_TABLE * ht, const void *key, void **last)
{
unsigned int hash, hash_idx;
HENTRY_HLS_PTR hentry;
assert (ht != NULL && key != NULL);
/*
* Hash the key and make sure that the return value is between 0 and size of hash table
*/
hash = *((unsigned int *) key);
if (hash >= ht->size)
{
hash_idx = hash % ht->size;
}
else
{
hash_idx = hash;
}
/* In HASH LIST SCAN, only hash key comparison is performed. */
for (hentry = ht->table[hash_idx]; hentry != NULL; hentry = hentry->next)
{
if (hentry->key == hash)
{
*((HENTRY_HLS_PTR *) last) = hentry;
return hentry->data;
}
}
return NULL;
}
/*
* mht_get_next_hls - Search the entry next to the last result
* return: the data associated with the key, or NULL if not found
* ht(in):
* key(in):
* last(in/out):
*
* NOTE: This call does not affect the LRU list.
*/
void *
mht_get_next_hls (const MHT_HLS_TABLE * ht, const void *key, void **last)
{
unsigned int hash;
HENTRY_HLS_PTR hentry;
assert (ht != NULL && key != NULL && last != NULL);
if ((*(HENTRY_HLS_PTR *) last)->next == NULL)
{
return NULL;
}
/* Hash the key and make sure that the return value is between 0 and size of hash table */
hash = *((unsigned int *) key);
for (hentry = (*(HENTRY_HLS_PTR *) last)->next; hentry != NULL; hentry = hentry->next)
{
if (hentry->key == hash)
{
*((HENTRY_HLS_PTR *) last) = hentry;
return hentry->data;
}
}
return NULL;
}
/*
* mht_put_internal - internal function for mht_put(), mht_put_new(), and
* mht_put_data();
* insert an entry associating key with data
* return:
* For option MHT_OPT_DEFAULT, MHT_OPT_KEEP_KEY, MHT_OPT_INSERT_ONLY,
* returns key if insertion was OK, otherwise, it returns NULL.
* For option MHT_OPT_INSERT_IF_NOT_EXISTS,
* returns existing data if duplicated key was found, or return
* inserted data if insertion was OK, otherwise, it returns NULL.
* ht(in/out): hash table (set as a side effect)
* key(in): hashing key
* data(in): data associated with hashing key
* opt(in): options;
* MHT_OPT_DEFAULT - change data and the key as given of the hash
* entry; replace the old entry with the new one
* if there is an entry with the same key
* MHT_OPT_KEEP_KEY - change data but the key of the hash entry
* MHT_OPT_INSERT_ONLY - do not replace the existing hash entry
* even if there is an etnry with the same key
* MHT_OPT_INSERT_IF_NOT_EXISTS - only insert if the key not exists,
* do nothing if the same key exists.
*/
static const void *
mht_put_internal (MHT_TABLE * ht, const void *key, void *data, MHT_PUT_OPT opt)
{
unsigned int hash;
HENTRY_PTR hentry;
assert (ht != NULL && key != NULL);
/*
* Hash the key and make sure that the return value is between 0 and size
* of hash table
*/
hash = (*ht->hash_func) (key, ht->size);
if (hash >= ht->size)
{
hash %= ht->size;
}
if (!(opt & MHT_OPT_INSERT_ONLY))
{
/* Now search the linked list.. Is there any entry with the given key ? */
for (hentry = ht->table[hash]; hentry != NULL; hentry = hentry->next)
{
if (hentry->key == key || (*ht->cmp_func) (hentry->key, key))
{
if (opt & MHT_OPT_INSERT_IF_NOT_EXISTS)
{
/* Return data for this option */
return hentry->data;
}
/* Replace the old data with the new one */
if (!(opt & MHT_OPT_KEEP_KEY))
{
hentry->key = key;
}
hentry->data = data;
return key;
}
}
}
/* This is a new entry */
if (ht->nprealloc_entries > 0)
{
ht->nprealloc_entries--;
hentry = ht->prealloc_entries;
ht->prealloc_entries = ht->prealloc_entries->next;
}
else
{
hentry = (HENTRY_PTR) db_fixed_alloc (ht->heap_id, DB_SIZEOF (HENTRY));
if (hentry == NULL)
{
return NULL;
}
}
if (ht->build_lru_list)
{
/* link new entry to LRU list */
hentry->lru_next = NULL;
hentry->lru_prev = ht->lru_tail;
if (ht->lru_tail)
{
ht->lru_tail->lru_next = hentry;
}
ht->lru_tail = hentry;
if (ht->lru_head == NULL)
{
ht->lru_head = hentry;
}
}
/*
* Link the new entry to the double link list of active entries and the
* hash itself. The previous entry should point to new one.
*/
hentry->key = key;
hentry->data = data;
hentry->act_next = NULL;
hentry->act_prev = ht->act_tail;
/* Double link tail entry should point to newly created entry */
if (ht->act_tail != NULL)
{
ht->act_tail->act_next = hentry;
}
ht->act_tail = hentry;
if (ht->act_head == NULL)
{
ht->act_head = hentry;
}
hentry->next = ht->table[hash];
if (hentry->next != NULL)
{
ht->ncollisions++;
}
ht->table[hash] = hentry;
ht->nentries++;
/*
* Rehash if almost all entries of hash table are used and there are at least
* 5% of collisions
*/
if (ht->nentries > ht->rehash_at && ht->ncollisions > (ht->nentries * 0.05))
{
if (mht_rehash (ht) < 0)
{
return NULL;
}
}
return (opt & MHT_OPT_INSERT_IF_NOT_EXISTS) ? data : key;
}
const void *
mht_put_new (MHT_TABLE * ht, const void *key, void *data)
{
assert (ht != NULL && key != NULL);
return mht_put_internal (ht, key, data, MHT_OPT_INSERT_ONLY);
}
const void *
mht_put_hls (MHT_HLS_TABLE * ht, const void *key, void *data)
{
assert (ht != NULL && key != NULL);
return mht_put_hls_internal (ht, key, data, MHT_OPT_INSERT_ONLY);
}
/*
* mht_put_if_not_exists - insert only if the same key not exists.
* return: Return existing data if duplicated key found,
* or return new insertion data if insertion successful,
* otherwise return NULL.
* ht(in/out): hash table
* key(in): hashing key
* data(in): data associated with hashing key
*
* Insert an entry into a hash table only same key not exists.
* Note that this function different with other put functions, do not return key.
*/
const void *
mht_put_if_not_exists (MHT_TABLE * ht, const void *key, void *data)
{
assert (ht != NULL && key != NULL);
return mht_put_internal (ht, key, data, MHT_OPT_INSERT_IF_NOT_EXISTS);
}
const void *
mht_put_data (MHT_TABLE * ht, const void *key, void *data)
{
assert (ht != NULL && key != NULL);
return mht_put_internal (ht, key, data, MHT_OPT_KEEP_KEY);
}
/*
* mht_put - insert an entry associating key with data
* return: Returns key if insertion was OK, otherwise, it returns NULL
* ht(in/out): hash table (set as a side effect)
* key(in): hashing key
* data(in): data associated with hashing key
*
* Note: Insert an entry into a hash table, associating the given key
* with the given data. If the entry is duplicated, that is, if
* the key already exist the new entry replaces the old one.
*
* The key and data are NOT COPIED, only its pointers are copied. The
* user must be aware that changes to the key and value are reflected
* into the hash table
*/
const void *
mht_put (MHT_TABLE * ht, const void *key, void *data)
{
assert (ht != NULL && key != NULL);
return mht_put_internal (ht, key, data, MHT_OPT_DEFAULT);
}
/*
* mht_put2_internal - internal function for mht_put2(), mht_put_new2(), and
* mht_put_data2();
* Insert an entry associating key with data;
* Allow mutiple entries with the same key value
* return: Returns key if insertion was OK, otherwise, it returns NULL
* ht(in/out): hash table (set as a side effect)
* key(in): hashing key
* data(in): data associated with hashing key
* opt(in): options;
* MHT_OPT_DEFAULT - change data and the key as given of the hash
* entry; replace the old entry with the new one
* if there is an entry with the same key
* MHT_OPT_KEEP_KEY - change data but the key of the hash entry
* MHT_OPT_INSERT_ONLY - do not replace the existing hash entry
* even if there is an etnry with the same key
*/
static const void *
mht_put2_internal (MHT_TABLE * ht, const void *key, void *data, MHT_PUT_OPT opt)
{
unsigned int hash;
HENTRY_PTR hentry;
assert (ht != NULL && key != NULL);
/*
* Hash the key and make sure that the return value is between 0 and size
* of hash table
*/
hash = (*ht->hash_func) (key, ht->size);
if (hash >= ht->size)
{
hash %= ht->size;
}
if (!(opt & MHT_OPT_INSERT_ONLY))
{
/* now search the linked list */
for (hentry = ht->table[hash]; hentry != NULL; hentry = hentry->next)
{
if ((hentry->key == key || (*ht->cmp_func) (hentry->key, key)) && hentry->data == data)
{
/* We found the existing entry. Replace the old data with the new one. */
if (!(opt & MHT_OPT_KEEP_KEY))
{
hentry->key = key;
}
hentry->data = data;
return key;
}
}
}
/* get new entry */
if (ht->nprealloc_entries > 0)
{
ht->nprealloc_entries--;
hentry = ht->prealloc_entries;
ht->prealloc_entries = ht->prealloc_entries->next;
}
else
{
hentry = (HENTRY_PTR) db_fixed_alloc (ht->heap_id, DB_SIZEOF (HENTRY));
if (hentry == NULL)
{
return NULL;
}
}
if (ht->build_lru_list)
{
/* link new entry to LRU list */
hentry->lru_next = NULL;
hentry->lru_prev = ht->lru_tail;
if (ht->lru_tail)
{
ht->lru_tail->lru_next = hentry;
}
ht->lru_tail = hentry;
if (ht->lru_head == NULL)
{
ht->lru_head = hentry;
}
}
/* link the new entry to the double link list of active entries */
hentry->key = key;
hentry->data = data;
hentry->act_next = NULL;
hentry->act_prev = ht->act_tail;
if (ht->act_tail != NULL)
{
ht->act_tail->act_next = hentry;
}
ht->act_tail = hentry;
if (ht->act_head == NULL)
{
ht->act_head = hentry;
}
/* and link to the hash itself */
if ((hentry->next = ht->table[hash]) != NULL)
{
ht->ncollisions++;
}
ht->table[hash] = hentry;
ht->nentries++;
/* rehash if almost all entries of hash table are used and there are at least 5% of collisions */
if (ht->nentries > ht->rehash_at && ht->ncollisions > (ht->nentries * 0.05))
{
mht_rehash (ht);
}
return key;
}
const void *
mht_put2_new (MHT_TABLE * ht, const void *key, void *data)
{
assert (ht != NULL && key != NULL);
return mht_put2_internal (ht, key, data, MHT_OPT_INSERT_ONLY);
}
#if defined (ENABLE_UNUSED_FUNCTION)
const void *
mht_put2_data (MHT_TABLE * ht, const void *key, void *data)
{
assert (ht != NULL && key != NULL);
return mht_put2_internal (ht, key, data, MHT_OPT_KEEP_KEY);
}
/*
* mht_put2 - Insert an entry associating key with data;
* Allow mutiple entries with the same key value
* return: Returns key if insertion was OK, otherwise, it returns NULL
* ht(in/out): hash table (set as a side effect)
* key(in): hashing key
* data(in): data associated with hashing key
*
* Note: Insert an entry into a hash table, associating the given key
* with the given data. If the entry is duplicated, that is, if
* the key already exist the new entry replaces the old one.
*
* The key and data are NOT COPIED, only its pointers are copied. The
* user must be aware that changes to the key and value are reflected
* into the hash table
*/
const void *
mht_put2 (MHT_TABLE * ht, const void *key, void *data)
{
assert (ht != NULL && key != NULL);
return mht_put2_internal (ht, key, data, MHT_OPT_DEFAULT);
}
#endif
/*
* mht_rem - remove a hash entry
* return: error code
* ht(in): hash table (set as a side effect)
* key(in): hashing key
* rem_func(in): supplied function to delete the data and key
* func_args(in): arguments to be passed to rem_func
*
* Note: For each entry in hash table, call function 'rem_func' on three
* arguments: the key of the entry, the data associated with the key,
* and the given args, in order to delete the data and key
*/
int
mht_rem (MHT_TABLE * ht, const void *key, int (*rem_func) (const void *key, void *data, void *args), void *func_args)
{
unsigned int hash;
HENTRY_PTR prev_hentry;
HENTRY_PTR hentry;
int error_code = NO_ERROR;
assert (ht != NULL && key != NULL);
/*
* Hash the key and make sure that the return value is between 0 and size
* of hash table
*/
hash = (*ht->hash_func) (key, ht->size);
if (hash >= ht->size)
{
hash %= ht->size;
}
/* Now search the linked list.. Is there any entry with the given key ? */
for (hentry = ht->table[hash], prev_hentry = NULL; hentry != NULL; prev_hentry = hentry, hentry = hentry->next)
{
if (hentry->key == key || (*ht->cmp_func) (hentry->key, key))
{
/*
* We found the entry
* Call "rem_func" (if any) to delete the data and key
* Delete the node from the double link list of active entries.
* Then delete the node from the hash table.
*/
if (rem_func)
{
error_code = (*rem_func) (hentry->key, hentry->data, func_args);
if (error_code != NO_ERROR)
{
return error_code;
}
}
if (ht->build_lru_list)
{
/* remove from LRU list */
if (ht->lru_head == ht->lru_tail)
{
ht->lru_head = ht->lru_tail = NULL;
}
else if (ht->lru_head == hentry)
{
ht->lru_head = hentry->lru_next;
hentry->lru_next->lru_prev = NULL;
}
else if (ht->lru_tail == hentry)
{
ht->lru_tail = hentry->lru_prev;
hentry->lru_prev->lru_next = NULL;
}
else
{
hentry->lru_prev->lru_next = hentry->lru_next;
hentry->lru_next->lru_prev = hentry->lru_prev;
}
}
/* Remove from double link list of active entries */
if (ht->act_head == ht->act_tail)
{
/* Single active element */
ht->act_head = ht->act_tail = NULL;
}
else if (ht->act_head == hentry)
{
/* Deleting from the head */
ht->act_head = hentry->act_next;
hentry->act_next->act_prev = NULL;
}
else if (ht->act_tail == hentry)
{
/* Deleting from the tail */
ht->act_tail = hentry->act_prev;
hentry->act_prev->act_next = NULL;
}
else
{
/* Deleting from the middle */
hentry->act_prev->act_next = hentry->act_next;
hentry->act_next->act_prev = hentry->act_prev;
}
/* Remove from the hash */
if (prev_hentry != NULL)
{
prev_hentry->next = hentry->next;
ht->ncollisions--;
}
else if ((ht->table[hash] = hentry->next) != NULL)
{
ht->ncollisions--;
}
ht->nentries--;
/* Save the entry for future insertions */
ht->nprealloc_entries++;
hentry->next = ht->prealloc_entries;
ht->prealloc_entries = hentry;
return NO_ERROR;
}
}
return ER_FAILED;
}
/*
* mht_rem2 - Remove an hash entry having the specified data
* return: error code
* ht(in): hash table (set as a side effect)
* key(in): hashing key
* data(in):
* rem_func(in): supplied function to delete the data and key
* func_args(in): arguments to be passed to rem_func
*
* Note: For each entry in hash table, call function 'rem_func' on three
* arguments: the key of the entry, the data associated with the key,
* and the given args, in order to delete the data and key
*/
int
mht_rem2 (MHT_TABLE * ht, const void *key, const void *data, int (*rem_func) (const void *key, void *data, void *args),
void *func_args)
{
unsigned int hash;
HENTRY_PTR prev_hentry;
HENTRY_PTR hentry;
int error_code = NO_ERROR;
assert (ht != NULL && key != NULL);
/* hash the key and make sure that the return value is between 0 and size of hash table */
hash = (*ht->hash_func) (key, ht->size);
if (hash >= ht->size)
{
hash %= ht->size;
}
/* now search the linked list */
for (hentry = ht->table[hash], prev_hentry = NULL; hentry != NULL; prev_hentry = hentry, hentry = hentry->next)
{
if ((hentry->key == key || (*ht->cmp_func) (hentry->key, key)) && hentry->data == data)
{
/*
* We found the entry.
* Call "fun" (if any) to delete the data and key.
* Delete the node from the double link list of active entries.
* Then delete the node from the hash table.
*/
if (rem_func)
{
error_code = (*rem_func) (hentry->key, hentry->data, func_args);
if (error_code != NO_ERROR)
{
return error_code;
}
}
if (ht->build_lru_list)
{
/* remove from LRU list */
if (ht->lru_head == ht->lru_tail)
{
ht->lru_head = ht->lru_tail = NULL;
}
else if (ht->lru_head == hentry)
{
ht->lru_head = hentry->lru_next;
hentry->lru_next->lru_prev = NULL;
}
else if (ht->lru_tail == hentry)
{
ht->lru_tail = hentry->lru_prev;
hentry->lru_prev->lru_next = NULL;
}
else
{
hentry->lru_prev->lru_next = hentry->lru_next;
hentry->lru_next->lru_prev = hentry->lru_prev;
}
}
/* remove from double link list of active entries */
if (ht->act_head == ht->act_tail)
{
ht->act_head = ht->act_tail = NULL;
}
else if (ht->act_head == hentry)
{
ht->act_head = hentry->act_next;
hentry->act_next->act_prev = NULL;
}
else if (ht->act_tail == hentry)
{
ht->act_tail = hentry->act_prev;
hentry->act_prev->act_next = NULL;
}
else
{
hentry->act_prev->act_next = hentry->act_next;
hentry->act_next->act_prev = hentry->act_prev;
}
/* remove from the hash */
if (prev_hentry != NULL)
{
prev_hentry->next = hentry->next;
ht->ncollisions--;
}
else if ((ht->table[hash] = hentry->next) != NULL)
{
ht->ncollisions--;
}
ht->nentries--;
/* save the entry for future insertions */
ht->nprealloc_entries++;
hentry->next = ht->prealloc_entries;
ht->prealloc_entries = hentry;
return NO_ERROR;
}
}
return ER_FAILED;
}
/*
* mht_map - map over hash entries
* return: NO_ERROR or error code - the result of user supplied "map_func"
* ht(in): hash table
* map_func(in): user supplied mapping function
* func_args(in): arguments to be passed to rem_func
*
* Note: For each entry in hash table, call function "map_func" on three
* arguments: the key of the entry, the data associated with the key,
* and the given args. The function that is called should not remove
* (other than the current entry being processed) nor insert entries on
* the given hash table, otherwise, the behavior of the _map is
* unpredictable (e.g., a newly inserted entry may or may not be
* included as part of the map. If "map_func" returns FALSE,
* the mapping is stopped.
*/
int
mht_map (const MHT_TABLE * ht, int (*map_func) (const void *key, void *data, void *args), void *func_args)
{
HENTRY_PTR hentry;
HENTRY_PTR next;
int error_code = NO_ERROR;
assert (ht != NULL);
for (hentry = ht->act_head; hentry != NULL; hentry = next)
{
/* Just in case the hentry is removed using mht_rem save the next entry */
next = hentry->act_next;
error_code = (*map_func) (hentry->key, hentry->data, func_args);
if (error_code != NO_ERROR)
{
break;
}
}
return (error_code);
}
/*
* mht_map_no_key - map over hash entries;
* Same as mht_map, but "map_func" is called on two arguments:
* data and arguments.
* return: NO_ERROR or error code - the result of user supplied "map_func"
* ht(in): hash table
* map_func(in): user supplied mapping function
* func_args(in): arguments to be passed to rem_func
*/
int
mht_map_no_key (THREAD_ENTRY * thread_p, const MHT_TABLE * ht,
int (*map_func) (THREAD_ENTRY * thread_p, void *data, void *args), void *func_args)
{
HENTRY_PTR hentry;
HENTRY_PTR next;
int error_code = NO_ERROR;
assert (ht != NULL);
for (hentry = ht->act_head; hentry != NULL; hentry = next)
{
/* Just in case the hentry is removed using mht_rem save the next entry */
next = hentry->act_next;
error_code = (*map_func) (thread_p, hentry->data, func_args);
if (error_code != NO_ERROR)
{
break;
}
}
return (error_code);
}
/*
* mht_count - number of hash entries
* return: number of entries
* ht(in): hash table
*/
unsigned int
mht_count (const MHT_TABLE * ht)
{
assert (ht != NULL);
return ht->nentries;
}
/*
* mht_get_hash_number - get linear hash number or string hash number
* return: the hash value of the hash key
* ht_size(out): hash size
* val(in): DB_VALUE to hash
*
* Note:
*/
unsigned int
mht_get_hash_number (const unsigned int ht_size, const DB_VALUE * val)
{
unsigned int hashcode = 0;
int i, len;
const char *ptr;
if (!val || DB_IS_NULL (val) || ht_size <= 1)
{
hashcode = 0;
}
else
{
switch (db_value_type (val))
{
case DB_TYPE_INTEGER:
hashcode = mht_get_shiftmult32 (val->data.i, ht_size);
break;
case DB_TYPE_SMALLINT:
hashcode = mht_get_shiftmult32 (val->data.sh, ht_size);
break;
case DB_TYPE_BIGINT:
{
DB_BIGINT bigint;
unsigned int x, y;
bigint = db_get_bigint (val);
x = bigint >> 32;
y = (unsigned int) bigint;
hashcode = mht_get_shiftmult32 (x ^ y, ht_size);
break;
}
break;
case DB_TYPE_FLOAT:
{
unsigned int *x, y;
x = (unsigned int *) &val->data.f;
y = (*x) & 0xFFFFFFF0;
hashcode = mht_get_shiftmult32 (y, ht_size);
}
break;
case DB_TYPE_DOUBLE:
case DB_TYPE_MONETARY:
{
unsigned int *x, y, z;
x = (unsigned int *) &val->data.d;
y = (x[0]) & 0xFFFFFFF0;
z = (x[1]) & 0xFFFFFFF0;
hashcode = mht_get_shiftmult32 (y ^ z, ht_size);
}
break;
case DB_TYPE_NUMERIC:
{
unsigned int *buf = (unsigned int *) val->data.num.d.buf;
hashcode = mht_get_shiftmult32 (buf[0] ^ buf[1] ^ buf[2] ^ buf[3], ht_size);
}
break;
case DB_TYPE_DATE:
hashcode = mht_get_shiftmult32 (val->data.date, ht_size);
break;
case DB_TYPE_TIME:
hashcode = mht_get_shiftmult32 (val->data.time, ht_size);
break;
case DB_TYPE_TIMESTAMP:
case DB_TYPE_TIMESTAMPLTZ:
hashcode = mht_get_shiftmult32 (val->data.utime, ht_size);
break;
case DB_TYPE_TIMESTAMPTZ:
hashcode = mht_get_shiftmult32 (val->data.timestamptz.timestamp, ht_size);
break;
case DB_TYPE_DATETIME:
case DB_TYPE_DATETIMELTZ:
hashcode = mht_get_shiftmult32 (val->data.datetime.date ^ val->data.datetime.time, ht_size);
break;
case DB_TYPE_DATETIMETZ:
hashcode =
mht_get_shiftmult32 (val->data.datetimetz.datetime.date ^ val->data.datetimetz.datetime.time, ht_size);
break;
case DB_TYPE_OID:
{
unsigned int x = (val->data.oid.volid << 16) | (val->data.oid.slotid);
unsigned int y = val->data.oid.pageid;
hashcode = mht_get_shiftmult32 (x ^ y, ht_size);
}
break;
case DB_TYPE_BIT:
case DB_TYPE_VARBIT:
case DB_TYPE_CHAR:
case DB_TYPE_VARCHAR:
case DB_TYPE_NCHAR:
case DB_TYPE_VARNCHAR:
ptr = db_get_string (val);
if (ptr)
{
len = db_get_string_size (val);
if (len < 0)
{
len = (int) strlen (ptr);
}
i = len;
for (i--; 0 <= i && ptr[i]; i--)
{
/* only the trailing ASCII space is ignored; the hashing for other characters depend on collation */
if (ptr[i] != 0x20)
{
break;
}
}
i++;
}
if (!ptr || ptr[0] == 0 || i <= 0)
{
hashcode = 0;
}
else
{
hashcode = MHT2STR_COLL (db_get_string_collation (val), (unsigned char *) ptr, i);
hashcode %= ht_size;
}
break;
case DB_TYPE_SET:
case DB_TYPE_MULTISET:
case DB_TYPE_SEQUENCE:
case DB_TYPE_VOBJ:
{
int size = val->data.set->disk_size / 4;
unsigned int x = 0;
int i;
for (i = 0; i < size; i++)
{
x ^= (unsigned int) (val->data.set->disk_set[i * 4]);
}
hashcode = mht_get_shiftmult32 (x, ht_size);
}
break;
case DB_TYPE_ENUMERATION:
hashcode = mht_get_shiftmult32 (val->data.enumeration.short_val, ht_size);
break;
case DB_TYPE_JSON:
{
char *json_body = NULL;
json_body = db_get_json_raw_body (val);
if (json_body == NULL)
{
hashcode = 0;
}
else
{
len = (int) strlen (json_body);
hashcode = MHT2STR_COLL (LANG_COLL_BINARY, (unsigned char *) json_body, len);
hashcode %= ht_size;
db_private_free (NULL, json_body);
}
}
break;
default: /* impossible */
/*
* TODO this is actually possible. See the QA scenario:
* sql/_01_object/_09_partition/_006_prunning/cases/1093.sql
* select * from hash_test where test_int = round(11.57);
* The value has type DB_TYPE_DOUBLE in this case.
*/
er_log_debug (ARG_FILE_LINE, "mht_get_hash_number: ERROR type = %d" " is Unsupported partition column type.",
db_value_type (val));
#if defined(NDEBUG)
hashcode = 0;
#else /* NDEBUG */
/* debugging purpose */
abort ();
#endif /* NDEBUG */
break;
}
}
return hashcode;
}
#if defined (ENABLE_UNUSED_FUNCTION)
/*
* mht_get32_next_power_of_2 -
* return: the next power of 2 greater than ht_size
* ht_size(out): hash size
*
* Note: find first 1's bit of 32bits integer
*/
static unsigned int
mht_get32_next_power_of_2 (const unsigned int ht_size)
{
unsigned int map = 0xffff0000, mapsave;
int mi;
if (ht_size == 0)
{
return 1;
}
if ((map & ht_size) == 0)
{
map ^= 0xffffffff;
}
for (mi = 3; mi >= 0; mi--)
{
mapsave = map;
map = (map << (1 << mi)) & mapsave;
if ((map & ht_size) == 0)
{
map = (map ^ 0xffffffff) & mapsave;
}
}
if (ht_size == map)
{
return map;
}
else
{
return map << 1;
}
}
#endif /* ENABLE_UNUSED_FUNCTION */
/*
* mht_get_shiftmult32 -
* return: new integer hash value
* key(in): hash key value
* ht_size(in): hash size
*
* Note: Robert Jenkin & Thomas Wang algorithm
*/
static unsigned int
mht_get_shiftmult32 (unsigned int key, const unsigned int ht_size)
{
unsigned int c2 = 0x27d4eb2d; /* a prime or an odd constant */
key = (key ^ 61) ^ (key >> 16);
key += (key << 3);
key ^= (key >> 4);
key *= c2;
key ^= (key >> 15);
return (key % ht_size);
}
#if defined (ENABLE_UNUSED_FUNCTION)
/*
* mht_get_linear_hash32 - find the next power of 2 greater than hashsize
* return: linear hash value
* key: hash key value
* ht_size: hash size
*/
static unsigned int
mht_get_linear_hash32 (const unsigned int key, const unsigned int ht_size)
{
unsigned int np, ret;
np = mht_get32_next_power_of_2 (ht_size);
ret = key & (np - 1);
for (ret = key & (np - 1); ret >= ht_size; ret &= (np - 1))
{
if (np % 2)
{
np = np / 2 + 1;
}
else
{
np = np / 2;
}
}
return ret;
}
#endif /* ENABLE_UNUSED_FUNCTION */
/*
* mht_put_hls_internal
* internal function for mht_put_hls()
* put data in the order.
* eliminates unnecessary logic to improve performance for hash list scan.
*
* return: key
* ht(in/out): hash table (set as a side effect)
* key(in): hashing key
* data(in): data associated with hashing key
* opt(in): options;
*/
static const void *
mht_put_hls_internal (MHT_HLS_TABLE * ht, const void *key, void *data, MHT_PUT_OPT opt)
{
unsigned int hash;
HENTRY_HLS_PTR hentry;
assert (ht != NULL && key != NULL);
/* Hash the key and make sure that the return value is between 0 and size of hash table. */
hash = *((unsigned int *) key);
if (hash >= ht->size)
{
hash %= ht->size;
}
/* This is a new entry */
if (ht->nprealloc_entries > 0)
{
ht->nprealloc_entries--;
hentry = ht->prealloc_entries;
ht->prealloc_entries = ht->prealloc_entries->next;
}
else
{
hentry = (HENTRY_HLS_PTR) db_fixed_alloc (ht->heap_id, DB_SIZEOF (HENTRY_HLS));
if (hentry == NULL)
{
return NULL;
}
}
hentry->data = data;
hentry->key = *((unsigned int *) key);
/* To input in order, use the tail node. */
if (ht->table[hash] == NULL)
{
ht->table[hash] = hentry;
}
else
{
ht->table[hash]->tail->next = hentry;
ht->ncollisions++;
}
hentry->next = NULL;
ht->table[hash]->tail = hentry;
ht->nentries++;
return key;
}
|
d9b4c87cbbbcf9f8251775011c5317feaced0db3
|
aa3befea459382dc5c01c925653d54f435b3fb0f
|
/arch/risc-v/src/esp32c3/esp32c3_spiflash.c
|
9cccbe02e350eec4591a89b24bd3333b3a3b5f01
|
[
"MIT-open-group",
"BSD-3-Clause",
"HPND-sell-variant",
"BSD-4-Clause-UC",
"LicenseRef-scancode-warranty-disclaimer",
"MIT-0",
"LicenseRef-scancode-bsd-atmel",
"LicenseRef-scancode-gary-s-brown",
"LicenseRef-scancode-proprietary-license",
"SunPro",
"MIT",
"LicenseRef-scancode-public-domain-disclaimer",
"LicenseRef-scancode-other-permissive",
"HPND",
"ISC",
"Apache-2.0",
"LicenseRef-scancode-public-domain",
"BSD-2-Clause",
"GPL-1.0-or-later",
"CC-BY-2.0",
"CC-BY-4.0"
] |
permissive
|
apache/nuttx
|
14519a7bff4a87935d94fb8fb2b19edb501c7cec
|
606b6d9310fb25c7d92c6f95bf61737e3c79fa0f
|
refs/heads/master
| 2023-08-25T06:55:45.822534
| 2023-08-23T16:03:31
| 2023-08-24T21:25:47
| 228,103,273
| 407
| 241
|
Apache-2.0
| 2023-09-14T18:26:05
| 2019-12-14T23:27:55
|
C
|
UTF-8
|
C
| false
| false
| 11,187
|
c
|
esp32c3_spiflash.c
|
/****************************************************************************
* arch/risc-v/src/esp32c3/esp32c3_spiflash.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdint.h>
#include <assert.h>
#include <debug.h>
#include <string.h>
#include <sys/types.h>
#include <inttypes.h>
#include <errno.h>
#include <nuttx/arch.h>
#include <nuttx/init.h>
#include "esp32c3.h"
#include "esp32c3_spiflash.h"
#include "esp32c3_irq.h"
#include "rom/esp32c3_spiflash.h"
#include "hardware/esp32c3_soc.h"
#include "hardware/esp32c3_interrupt.h"
#include "hardware/extmem_reg.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* RO data page in MMU index */
#define DROM0_PAGES_START (2)
#define DROM0_PAGES_END (128)
/* MMU invalid value */
#define INVALID_MMU_VAL (0x100)
/* MMU page size */
#define SPI_FLASH_MMU_PAGE_SIZE (0x10000)
/* MMU base virtual mapped address */
#define VADDR0_START_ADDR (0x3c020000)
/* Ibus virtual address */
#define IBUS_VADDR_START (0x42000000)
#define IBUS_VADDR_END (0x44000000)
/* Flash MMU table for CPU */
#define MMU_TABLE ((volatile uint32_t *)DR_REG_MMU_TABLE)
#define MMU_ADDR2PAGE(_addr) ((_addr) / SPI_FLASH_MMU_PAGE_SIZE)
#define MMU_ADDR2OFF(_addr) ((_addr) % SPI_FLASH_MMU_PAGE_SIZE)
#define MMU_BYTES2PAGES(_n) (((_n) + SPI_FLASH_MMU_PAGE_SIZE - 1) / \
SPI_FLASH_MMU_PAGE_SIZE)
/****************************************************************************
* Private Types
****************************************************************************/
/* SPI Flash map request data */
struct spiflash_map_req_s
{
/* Request mapping SPI Flash base address */
uint32_t src_addr;
/* Request mapping SPI Flash size */
uint32_t size;
/* Mapped memory pointer */
void *ptr;
/* Mapped started MMU page index */
uint32_t start_page;
/* Mapped MMU page count */
uint32_t page_cnt;
};
/****************************************************************************
* Private Functions Declaration
****************************************************************************/
static void spiflash_start(void);
static void spiflash_end(void);
/****************************************************************************
* Public Functions Declaration
****************************************************************************/
extern int cache_invalidate_addr(uint32_t addr, uint32_t size);
extern uint32_t cache_suspend_icache(void);
extern void cache_resume_icache(uint32_t val);
/****************************************************************************
* Private Data
****************************************************************************/
static struct spiflash_guard_funcs g_spi_flash_guard_funcs =
{
.start = spiflash_start,
.end = spiflash_end,
.op_lock = NULL,
.op_unlock = NULL,
.address_is_safe = NULL,
.yield = NULL,
};
static uint32_t g_icache_value;
static uint32_t g_int_regval;
static uint32_t g_int_unmask;
/****************************************************************************
* Private Functions
****************************************************************************/
static IRAM_ATTR void disable_mask_int(void)
{
uint32_t regval;
g_int_regval = getreg32(INTERRUPT_CPU_INT_ENABLE_REG);
regval = g_int_regval & g_int_unmask;
putreg32(regval, INTERRUPT_CPU_INT_ENABLE_REG);
}
static IRAM_ATTR void enable_mask_int(void)
{
putreg32(g_int_regval, INTERRUPT_CPU_INT_ENABLE_REG);
}
/****************************************************************************
* Name: spiflash_opstart
*
* Description:
* Prepare for an SPIFLASH operation.
*
****************************************************************************/
static IRAM_ATTR void spiflash_start(void)
{
irqstate_t flags;
flags = enter_critical_section();
disable_mask_int();
g_icache_value = cache_suspend_icache() << 16;
leave_critical_section(flags);
}
/****************************************************************************
* Name: spiflash_opdone
*
* Description:
* Undo all the steps of opstart.
*
****************************************************************************/
static IRAM_ATTR void spiflash_end(void)
{
irqstate_t flags;
flags = enter_critical_section();
cache_resume_icache(g_icache_value >> 16);
enable_mask_int();
leave_critical_section(flags);
}
/****************************************************************************
* Name: esp32c3_mmap
*
* Description:
* Mapped SPI Flash address to ESP32-C3's address bus, so that software
* can read SPI Flash data by reading data from memory access.
*
* If SPI Flash hardware encryption is enable, the read from mapped
* address is decrypted.
*
* Input Parameters:
* req - SPI Flash mapping requesting parameters
*
* Returned Value:
* 0 if success or a negative value if fail.
*
****************************************************************************/
static IRAM_ATTR int esp32c3_mmap(struct spiflash_map_req_s *req)
{
int ret;
int i;
int start_page;
int flash_page;
int page_cnt;
uint32_t mapped_addr;
spiflash_start();
for (start_page = DROM0_PAGES_START;
start_page < DROM0_PAGES_END;
++start_page)
{
if (MMU_TABLE[start_page] == INVALID_MMU_VAL)
{
break;
}
}
flash_page = MMU_ADDR2PAGE(req->src_addr);
page_cnt = MMU_BYTES2PAGES(MMU_ADDR2OFF(req->src_addr) + req->size);
if (start_page + page_cnt < DROM0_PAGES_END)
{
mapped_addr = (start_page - DROM0_PAGES_START) *
SPI_FLASH_MMU_PAGE_SIZE +
VADDR0_START_ADDR;
for (i = 0; i < page_cnt; i++)
{
MMU_TABLE[start_page + i] = flash_page + i;
cache_invalidate_addr(mapped_addr + i * SPI_FLASH_MMU_PAGE_SIZE,
SPI_FLASH_MMU_PAGE_SIZE);
}
req->start_page = start_page;
req->page_cnt = page_cnt;
req->ptr = (void *)(mapped_addr + MMU_ADDR2OFF(req->src_addr));
ret = OK;
}
else
{
ret = -ENOBUFS;
}
spiflash_end();
return ret;
}
/****************************************************************************
* Name: esp32c3_ummap
*
* Description:
* Unmap SPI Flash address in ESP32-C3's address bus, and free resource.
*
* Input Parameters:
* req - SPI Flash mapping requesting parameters
*
* Returned Value:
* None.
*
****************************************************************************/
static IRAM_ATTR void esp32c3_ummap(const struct spiflash_map_req_s *req)
{
int i;
spiflash_start();
for (i = req->start_page; i < req->start_page + req->page_cnt; ++i)
{
MMU_TABLE[i] = INVALID_MMU_VAL;
}
spiflash_end();
}
/****************************************************************************
* Name: spi_flash_read_encrypted
*
* Description:
* Read decrypted data from SPI Flash at designated address when
* enable SPI Flash hardware encryption.
*
* Input Parameters:
* addr - target address
* buffer - data buffer pointer
* size - data number
*
* Returned Value:
* OK if success or a negative value if fail.
*
****************************************************************************/
int spi_flash_read_encrypted(uint32_t addr, void *buffer, uint32_t size)
{
int ret;
struct spiflash_map_req_s req =
{
.src_addr = addr,
.size = size
};
ret = esp32c3_mmap(&req);
if (ret < 0)
{
return ret;
}
memcpy(buffer, req.ptr, size);
esp32c3_ummap(&req);
return OK;
}
/****************************************************************************
* Name: esp32c3_icache2phys
*
* Description:
* Get Absolute address in SPI Flash by input function pointer.
*
* Input Parameters:
* func - Function pointer
*
* Returned Value:
* Absolute address if success or negtive value if failed.
*
****************************************************************************/
int32_t esp32c3_icache2phys(const void *func)
{
intptr_t pages;
intptr_t off;
intptr_t c = (intptr_t)func;
off = (c - IBUS_VADDR_START) % SPI_FLASH_MMU_PAGE_SIZE;
pages = (c - IBUS_VADDR_START) / SPI_FLASH_MMU_PAGE_SIZE;
pages += MMU_TABLE[pages];
return pages * SPI_FLASH_MMU_PAGE_SIZE + off;
}
/****************************************************************************
* Name: esp32c3_spiflash_unmask_cpuint
*
* Description:
* Unmask CPU interrupt and keep this interrupt work when read, write,
* erase SPI Flash.
*
* By default, all CPU interrupts are masked.
*
* Input Parameters:
* cpuint - CPU interrupt ID
*
* Returned Value:
* None.
*
****************************************************************************/
void esp32c3_spiflash_unmask_cpuint(int cpuint)
{
g_int_unmask |= 1 << cpuint;
}
/****************************************************************************
* Name: esp32c3_spiflash_unmask_cpuint
*
* Description:
* Mask CPU interrupt and disable this interrupt when read, write,
* erase SPI Flash.
*
* By default, all CPU interrupts are masked.
*
* Input Parameters:
* cpuint - CPU interrupt ID
*
* Returned Value:
* None.
*
****************************************************************************/
void esp32c3_spiflash_mask_cpuint(int cpuint)
{
g_int_unmask &= ~(1 << cpuint);
}
/****************************************************************************
* Name: esp32c3_spiflash_init
*
* Description:
* Initialize ESP32-C3 SPI flash driver.
*
* Returned Value:
* OK if success or a negative value if fail.
*
****************************************************************************/
int esp32c3_spiflash_init(void)
{
spi_flash_guard_set(&g_spi_flash_guard_funcs);
return OK;
}
|
cdb391ee010b0a6163b89c18d9ea49841bce6613
|
9ceacf33fd96913cac7ef15492c126d96cae6911
|
/games/hunt/huntd/execute.c
|
be377c2ccdb2d89d1f7e0638e4018fc7c849d2ca
|
[] |
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
| 13,259
|
c
|
execute.c
|
/* $OpenBSD: execute.c,v 1.14 2017/01/21 08:22:57 krw Exp $ */
/* $NetBSD: execute.c,v 1.2 1997/10/10 16:33:13 lukem Exp $ */
/*
* Copyright (c) 1983-2003, Regents of the University of California.
* 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 University of California, San Francisco nor
* the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/select.h>
#include <stdlib.h>
#include <string.h>
#include <syslog.h>
#include "conf.h"
#include "hunt.h"
#include "server.h"
static void cloak(PLAYER *);
static void face(PLAYER *, int);
static void fire(PLAYER *, int);
static void fire_slime(PLAYER *, int);
static void move_player(PLAYER *, int);
static void pickup(PLAYER *, int, int, int, int);
static void scan(PLAYER *);
/*
* mon_execute:
* Execute a single monitor command
*/
void
mon_execute(PLAYER *pp)
{
char ch;
ch = pp->p_cbuf[pp->p_ncount++];
switch (ch) {
case CTRL('L'):
/* Redraw messed-up screen */
sendcom(pp, REDRAW);
break;
case 'q':
/* Quit client */
(void) strlcpy(pp->p_death, "| Quit |", sizeof pp->p_death);
break;
default:
/* Ignore everything else */
;
}
}
/*
* execute:
* Execute a single command from a player
*/
void
execute(PLAYER *pp)
{
char ch;
ch = pp->p_cbuf[pp->p_ncount++];
/* When flying, only allow refresh and quit. */
if (pp->p_flying >= 0) {
switch (ch) {
case CTRL('L'):
sendcom(pp, REDRAW);
break;
case 'q':
(void) strlcpy(pp->p_death, "| Quit |",
sizeof pp->p_death);
break;
}
return;
}
/* Decode the command character: */
switch (ch) {
case CTRL('L'):
sendcom(pp, REDRAW); /* Refresh */
break;
case 'h':
move_player(pp, LEFTS); /* Move left */
break;
case 'H':
face(pp, LEFTS); /* Face left */
break;
case 'j':
move_player(pp, BELOW); /* Move down */
break;
case 'J':
face(pp, BELOW); /* Face down */
break;
case 'k':
move_player(pp, ABOVE); /* Move up */
break;
case 'K':
face(pp, ABOVE); /* Face up */
break;
case 'l':
move_player(pp, RIGHT); /* Move right */
break;
case 'L':
face(pp, RIGHT); /* Face right */
break;
case 'f':
case '1':
fire(pp, 0); /* SHOT */
break;
case 'g':
case '2':
fire(pp, 1); /* GRENADE */
break;
case 'F':
case '3':
fire(pp, 2); /* SATCHEL */
break;
case 'G':
case '4':
fire(pp, 3); /* 7x7 BOMB */
break;
case '5':
fire(pp, 4); /* 9x9 BOMB */
break;
case '6':
fire(pp, 5); /* 11x11 BOMB */
break;
case '7':
fire(pp, 6); /* 13x13 BOMB */
break;
case '8':
fire(pp, 7); /* 15x15 BOMB */
break;
case '9':
fire(pp, 8); /* 17x17 BOMB */
break;
case '0':
fire(pp, 9); /* 19x19 BOMB */
break;
case '@':
fire(pp, 10); /* 21x21 BOMB */
break;
case 'o':
fire_slime(pp, 0); /* SLIME */
break;
case 'O':
fire_slime(pp, 1); /* SSLIME */
break;
case 'p':
fire_slime(pp, 2); /* large slime */
break;
case 'P':
fire_slime(pp, 3); /* very large slime */
break;
case 's': /* start scanning */
scan(pp);
break;
case 'c': /* start cloaking */
cloak(pp);
break;
case 'q': /* quit */
(void) strlcpy(pp->p_death, "| Quit |", sizeof pp->p_death);
break;
}
}
/*
* move_player:
* Try to move player 'pp' in direction 'dir'.
*/
static void
move_player(PLAYER *pp, int dir)
{
PLAYER *newp;
int x, y;
FLAG moved;
BULLET *bp;
y = pp->p_y;
x = pp->p_x;
switch (dir) {
case LEFTS:
x--;
break;
case RIGHT:
x++;
break;
case ABOVE:
y--;
break;
case BELOW:
y++;
break;
}
moved = FALSE;
/* What would the player move over: */
switch (Maze[y][x]) {
/* Players can move through spaces and doors, no problem: */
case SPACE:
case DOOR:
moved = TRUE;
break;
/* Can't move through walls: */
case WALL1:
case WALL2:
case WALL3:
case WALL4:
case WALL5:
break;
/* Moving over a mine - try to pick it up: */
case MINE:
case GMINE:
if (dir == pp->p_face)
/* facing it: 2% chance of trip */
pickup(pp, y, x, conf_ptrip_face, Maze[y][x]);
else if (opposite(dir, pp->p_face))
/* facing away: 95% chance of trip */
pickup(pp, y, x, conf_ptrip_back, Maze[y][x]);
else
/* facing sideways: 50% chance of trip */
pickup(pp, y, x, conf_ptrip_side, Maze[y][x]);
/* Remove the mine: */
Maze[y][x] = SPACE;
moved = TRUE;
break;
/* Moving into a bullet: */
case SHOT:
case GRENADE:
case SATCHEL:
case BOMB:
case SLIME:
case DSHOT:
/* Find which bullet: */
bp = is_bullet(y, x);
if (bp != NULL)
/* Detonate it: */
bp->b_expl = TRUE;
/* Remove it: */
Maze[y][x] = SPACE;
moved = TRUE;
break;
/* Moving into another player: */
case LEFTS:
case RIGHT:
case ABOVE:
case BELOW:
if (dir != pp->p_face)
/* Can't walk backwards/sideways into another player: */
sendcom(pp, BELL);
else {
/* Stab the other player */
newp = play_at(y, x);
checkdam(newp, pp, pp->p_ident, conf_stabdam, KNIFE);
}
break;
/* Moving into a player flying overhead: */
case FLYER:
newp = play_at(y, x);
message(newp, "Oooh, there's a short guy waving at you!");
message(pp, "You couldn't quite reach him!");
break;
/* Picking up a boot, or two: */
case BOOT_PAIR:
pp->p_nboots++;
case BOOT:
pp->p_nboots++;
for (newp = Boot; newp < &Boot[NBOOTS]; newp++) {
if (newp->p_flying < 0)
continue;
if (newp->p_y == y && newp->p_x == x) {
newp->p_flying = -1;
if (newp->p_undershot)
fixshots(y, x, newp->p_over);
}
}
if (pp->p_nboots == 2)
message(pp, "Wow! A pair of boots!");
else
message(pp, "You can hobble around on one boot.");
Maze[y][x] = SPACE;
moved = TRUE;
break;
}
/* Can the player be moved? */
if (moved) {
/* Check the gun status: */
if (pp->p_ncshot > 0)
if (--pp->p_ncshot == conf_maxncshot)
outyx(pp, STAT_GUN_ROW, STAT_VALUE_COL, " ok");
/* Check for bullets flying past: */
if (pp->p_undershot) {
fixshots(pp->p_y, pp->p_x, pp->p_over);
pp->p_undershot = FALSE;
}
/* Erase the player: */
drawplayer(pp, FALSE);
/* Save under: */
pp->p_over = Maze[y][x];
/* Move the player: */
pp->p_y = y;
pp->p_x = x;
/* Draw the player in their new position */
drawplayer(pp, TRUE);
}
}
/*
* face:
* Change the direction the player is facing
*/
static void
face(PLAYER *pp, int dir)
{
if (pp->p_face != dir) {
pp->p_face = dir;
drawplayer(pp, TRUE);
}
}
/*
* fire:
* Fire a shot of the given type in the given direction
*/
static void
fire(PLAYER *pp, int req_index)
{
if (pp == NULL)
return;
/* Drop the shot type down until we can afford it: */
while (req_index >= 0 && pp->p_ammo < shot_req[req_index])
req_index--;
/* Can we shoot at all? */
if (req_index < 0) {
message(pp, "Not enough charges.");
return;
}
/* Check if the gun is too hot: */
if (pp->p_ncshot > conf_maxncshot)
return;
/* Heat up the gun: */
if (pp->p_ncshot++ == conf_maxncshot) {
/* The gun has overheated: */
outyx(pp, STAT_GUN_ROW, STAT_VALUE_COL, " ");
}
/* Use up some ammo: */
pp->p_ammo -= shot_req[req_index];
ammo_update(pp);
/* Start the bullet moving: */
add_shot(shot_type[req_index], pp->p_y, pp->p_x, pp->p_face,
shot_req[req_index], pp, FALSE, pp->p_face);
pp->p_undershot = TRUE;
/* Show the bullet to everyone: */
showexpl(pp->p_y, pp->p_x, shot_type[req_index]);
sendcom(ALL_PLAYERS, REFRESH);
}
/*
* fire_slime:
* Fire a slime shot in the given direction
*/
static void
fire_slime(PLAYER *pp, int req_index)
{
if (pp == NULL)
return;
/* Check configuration: */
if (!conf_ooze)
return;
/* Drop the slime type back util we can afford it: */
while (req_index >= 0 && pp->p_ammo < slime_req[req_index])
req_index--;
/* Can we afford to slime at all? */
if (req_index < 0) {
message(pp, "Not enough charges.");
return;
}
/* Is the gun too hot? */
if (pp->p_ncshot > conf_maxncshot)
return;
/* Heat up the gun: */
if (pp->p_ncshot++ == conf_maxncshot) {
/* The gun has overheated: */
outyx(pp, STAT_GUN_ROW, STAT_VALUE_COL, " ");
}
/* Use up some ammo: */
pp->p_ammo -= slime_req[req_index];
ammo_update(pp);
/* Start the slime moving: */
add_shot(SLIME, pp->p_y, pp->p_x, pp->p_face,
slime_req[req_index] * conf_slimefactor, pp, FALSE, pp->p_face);
pp->p_undershot = TRUE;
/* Show the object to everyone: */
showexpl(pp->p_y, pp->p_x, SLIME);
sendcom(ALL_PLAYERS, REFRESH);
}
/*
* add_shot:
* Create a shot with the given properties
*/
void
add_shot(int type, int y, int x, char face, int charge, PLAYER *owner,
int expl, char over)
{
BULLET *bp;
int size;
/* Determine the bullet's size based on its type and charge: */
switch (type) {
case SHOT:
case MINE:
size = 1;
break;
case GRENADE:
case GMINE:
size = 2;
break;
case SATCHEL:
size = 3;
break;
case BOMB:
for (size = 3; size < MAXBOMB; size++)
if (shot_req[size] >= charge)
break;
size++;
break;
default:
size = 0;
break;
}
/* Create the bullet: */
bp = create_shot(type, y, x, face, charge, size, owner,
(owner == NULL) ? NULL : owner->p_ident, expl, over);
/* Insert the bullet into the front of the bullet list: */
bp->b_next = Bullets;
Bullets = bp;
}
/*
* create_shot:
* allocate storage for an (unlinked) bullet structure;
* initialize and return it
*/
BULLET *
create_shot(int type, int y, int x, char face, int charge, int size,
PLAYER *owner, IDENT *score, int expl, char over)
{
BULLET *bp;
bp = malloc(sizeof (BULLET));
if (bp == NULL) {
logit(LOG_ERR, "malloc");
if (owner != NULL)
message(owner, "Out of memory");
return NULL;
}
bp->b_face = face;
bp->b_x = x;
bp->b_y = y;
bp->b_charge = charge;
bp->b_owner = owner;
bp->b_score = score;
bp->b_type = type;
bp->b_size = size;
bp->b_expl = expl;
bp->b_over = over;
bp->b_next = NULL;
return bp;
}
/*
* cloak:
* Turn on or increase length of a cloak
*/
static void
cloak(PLAYER *pp)
{
/* Check configuration: */
if (!conf_cloak)
return;
/* Can we afford it?: */
if (pp->p_ammo <= 0) {
message(pp, "No more charges");
return;
}
/* Can't cloak with boots: */
if (pp->p_nboots > 0) {
message(pp, "Boots are too noisy to cloak!");
return;
}
/* Consume a unit of ammo: */
pp->p_ammo--;
ammo_update(pp);
/* Add to the duration of a cloak: */
pp->p_cloak += conf_cloaklen;
/* Disable scan, if enabled: */
if (pp->p_scan >= 0)
pp->p_scan = -1;
/* Re-draw the player's scan/cloak status: */
showstat(pp);
}
/*
* scan:
* Turn on or increase length of a scan
*/
static void
scan(PLAYER *pp)
{
/* Check configuration: */
if (!conf_scan)
return;
/* Can we afford it?: */
if (pp->p_ammo <= 0) {
message(pp, "No more charges");
return;
}
/* Consume one unit of ammo: */
pp->p_ammo--;
ammo_update(pp);
/* Increase the scan time: */
pp->p_scan += Nplayer * conf_scanlen;
/* Disable cloak, if enabled: */
if (pp->p_cloak >= 0)
pp->p_cloak = -1;
/* Re-draw the player's scan/cloak status: */
showstat(pp);
}
/*
* pickup:
* pick up a mine or grenade, with some probability of it exploding
*/
static void
pickup(PLAYER *pp, int y, int x, int prob, int obj)
{
int req;
/* Figure out how much ammo the player is trying to pick up: */
switch (obj) {
case MINE:
req = BULREQ;
break;
case GMINE:
req = GRENREQ;
break;
default:
#ifdef DIAGNOSTIC
abort();
#endif
return;
}
/* Does it explode? */
if (rand_num(100) < prob)
/* Ooooh, unlucky: (Boom) */
add_shot(obj, y, x, LEFTS, req, (PLAYER *) NULL,
TRUE, pp->p_face);
else {
/* Safely picked it up. Add to player's ammo: */
pp->p_ammo += req;
ammo_update(pp);
}
}
void
ammo_update(PLAYER *pp)
{
outyx(pp, STAT_AMMO_ROW, STAT_VALUE_COL - 1, "%4d", pp->p_ammo);
}
|
cd9fece1d677a5ab2589429e55661fd1a79584d5
|
9ca19ee62e2c985be413bd12e5eb63b44833750d
|
/src/cforth/extend.c
|
3479a8178993cc9dc9b5f011939591957976368b
|
[
"MIT"
] |
permissive
|
MitchBradley/cforth
|
4cb523847c552b2e32e5e50a328b8e263a074d85
|
bae39263f2615e1d260426e3eca0ab32816f54ef
|
refs/heads/master
| 2023-08-31T17:23:00.037535
| 2023-08-17T09:01:57
| 2023-08-17T09:01:57
| 12,050,604
| 142
| 43
|
NOASSERTION
| 2023-08-21T16:36:56
| 2013-08-12T07:50:31
|
C
|
UTF-8
|
C
| false
| false
| 669
|
c
|
extend.c
|
#include "forth.h"
// Here is where you can add your own extensions.
// Add entries to the ccalls table, and create Forth entry points
// for them with ccall.
cell
example1(cell a, cell b) // Returns sum of a and b
{
return(a+b);
}
char *
example2(char *s) // Returns last 9 characters of string s in reverse order
{
char *p;
int i;
static char result[10];
for(p=s; *p; p++)
;
for(i = 0; i < 9 && p > s; i++)
result[i] = *--p;
result[i] = '\0';
return (result);
}
cell ((* const ccalls[])()) = {
C(example1) //c sum { i.a i.b -- i.sum }
C(example2) //c byterev { a.in -- a.out }
// Add your own routines here
};
|
506c918d983b3910c7b5d0b45a473dc71ba2af66
|
79d343002bb63a44f8ab0dbac0c9f4ec54078c3a
|
/lib/libc/wasi/libc-top-half/musl/src/stdio/rewind.c
|
6f4b58b5468900cab60ca6e28c494ac2eea1c645
|
[
"BSD-3-Clause",
"LicenseRef-scancode-public-domain",
"BSD-2-Clause",
"LicenseRef-scancode-other-permissive",
"LicenseRef-scancode-musl-exception",
"MIT",
"LLVM-exception",
"Apache-2.0",
"NCSA"
] |
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
| 131
|
c
|
rewind.c
|
#include "stdio_impl.h"
void rewind(FILE *f)
{
FLOCK(f);
__fseeko_unlocked(f, 0, SEEK_SET);
f->flags &= ~F_ERR;
FUNLOCK(f);
}
|
b140eaf715d52ab7843c3919f4179074bded38ca
|
28d0f8c01599f8f6c711bdde0b59f9c2cd221203
|
/sys/fs/unionfs/unionfs_vnops.c
|
3866afc007beed1347fd5e6744f2a7f585787563
|
[] |
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
| 44,846
|
c
|
unionfs_vnops.c
|
/*-
* Copyright (c) 1992, 1993, 1994, 1995 Jan-Simon Pendry.
* Copyright (c) 1992, 1993, 1994, 1995
* The Regents of the University of California.
* Copyright (c) 2005, 2006 Masanori Ozawa <ozawa@ongs.co.jp>, ONGS Inc.
* Copyright (c) 2006 Daichi Goto <daichi@freebsd.org>
* All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Jan-Simon Pendry.
*
* 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.
* 4. Neither the name of the University 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 REGENTS 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 REGENTS 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.
*
* @(#)union_vnops.c 8.32 (Berkeley) 6/23/95
* $FreeBSD: src/sys/fs/unionfs/union_vnops.c,v 1.152 2008/01/13 14:44:06 attilio Exp $
*
*/
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/conf.h>
#include <sys/kernel.h>
#include <sys/lock.h>
#include <sys/malloc.h>
#include <sys/mount.h>
#include <sys/mutex.h>
#include <sys/namei.h>
#include <sys/sysctl.h>
#include <sys/vnode.h>
#include <sys/buf.h>
#include <sys/fcntl.h>
#include <sys/stat.h>
#include <sys/dirent.h>
#include <sys/proc.h>
#include <fs/unionfs/unionfs.h>
#include <miscfs/genfs/genfs.h>
#include <miscfs/specfs/specdev.h>
#if 0
#define UNIONFS_INTERNAL_DEBUG(msg, args...) printf(msg, ## args)
#define UNIONFS_IDBG_RENAME
#else
#define UNIONFS_INTERNAL_DEBUG(msg, args...)
#endif
static int
unionfs_parsepath(void *v)
{
struct vop_parsepath_args /* {
struct vnode *a_dvp;
const char *a_name;
size_t *a_retval;
} */ *ap = v;
struct unionfs_node *dunp;
struct vnode *upperdvp, *lowerdvp;
size_t upper, lower;
int error;
dunp = VTOUNIONFS(ap->a_dvp);
upperdvp = dunp->un_uppervp;
lowerdvp = dunp->un_lowervp;
error = VOP_PARSEPATH(upperdvp, ap->a_name, &upper);
if (error) {
return error;
}
error = VOP_PARSEPATH(lowerdvp, ap->a_name, &lower);
if (error) {
return error;
}
/*
* If they're different, use the larger one. This is not a
* comprehensive solution, but it's sufficient for the
* non-default cases of parsepath that currently exist.
*/
*ap->a_retval = MAX(upper, lower);
return 0;
}
static int
unionfs_lookup(void *v)
{
struct vop_lookup_v2_args /* {
struct vnodeop_desc *a_desc;
struct vnode *a_dvp;
struct vnode **a_vpp;
struct componentname *a_cnp;
} */ *ap = v;
int iswhiteout;
int error , uerror, lerror;
u_long nameiop;
u_long cnflags, cnflagsbk;
struct unionfs_node *dunp;
struct vnode *dvp, *udvp, *ldvp, *vp, *uvp, *lvp, *dtmpvp;
struct vattr va;
struct componentname *cnp;
iswhiteout = 0;
error = uerror = lerror = ENOENT;
cnp = ap->a_cnp;
nameiop = cnp->cn_nameiop;
cnflags = cnp->cn_flags;
dvp = ap->a_dvp;
dunp = VTOUNIONFS(dvp);
udvp = dunp->un_uppervp;
ldvp = dunp->un_lowervp;
vp = uvp = lvp = NULLVP;
*(ap->a_vpp) = NULLVP;
UNIONFS_INTERNAL_DEBUG("unionfs_lookup: enter: nameiop=%ld, flags=%lx, path=%s\n", nameiop, cnflags, cnp->cn_nameptr);
if (dvp->v_type != VDIR)
return (ENOTDIR);
/*
* If read-only and op is not LOOKUP, will return EROFS.
*/
if ((cnflags & ISLASTCN) &&
(dvp->v_mount->mnt_flag & MNT_RDONLY) &&
LOOKUP != nameiop)
return (EROFS);
/*
* lookup dotdot
*/
if (cnflags & ISDOTDOT) {
if (LOOKUP != nameiop && udvp == NULLVP)
return (EROFS);
if (udvp != NULLVP) {
dtmpvp = udvp;
if (ldvp != NULLVP)
VOP_UNLOCK(ldvp);
}
else
dtmpvp = ldvp;
error = VOP_LOOKUP(dtmpvp, &vp, cnp);
if (dtmpvp == udvp && ldvp != NULLVP) {
VOP_UNLOCK(udvp);
vn_lock(dvp, LK_EXCLUSIVE | LK_RETRY);
}
if (error == 0) {
/*
* Exchange lock and reference from vp to
* dunp->un_dvp. vp is upper/lower vnode, but it
* will need to return the unionfs vnode.
*/
if (nameiop == DELETE || nameiop == RENAME)
VOP_UNLOCK(vp);
vrele(vp);
VOP_UNLOCK(dvp);
*(ap->a_vpp) = dunp->un_dvp;
vref(dunp->un_dvp);
vn_lock(dunp->un_dvp, LK_EXCLUSIVE | LK_RETRY);
vn_lock(dvp, LK_EXCLUSIVE | LK_RETRY);
} else if (error == ENOENT && nameiop != CREATE)
cache_enter(dvp, NULLVP, cnp->cn_nameptr,
cnp->cn_namelen, cnp->cn_flags);
UNIONFS_INTERNAL_DEBUG("unionfs_lookup: leave (%d)\n", error);
return (error);
}
/*
* lookup upper layer
*/
if (udvp != NULLVP) {
uerror = VOP_LOOKUP(udvp, &uvp, cnp);
if (uerror == 0) {
if (udvp == uvp) { /* is dot */
vrele(uvp);
*(ap->a_vpp) = dvp;
vref(dvp);
UNIONFS_INTERNAL_DEBUG("unionfs_lookup: leave (%d)\n", uerror);
return (uerror);
}
}
/* check whiteout */
if (uerror == ENOENT || uerror == EJUSTRETURN)
if (cnp->cn_flags & ISWHITEOUT)
iswhiteout = 1; /* don't lookup lower */
if (iswhiteout == 0 && ldvp != NULLVP)
if (VOP_GETATTR(udvp, &va, cnp->cn_cred) == 0 &&
(va.va_flags & OPAQUE))
iswhiteout = 1; /* don't lookup lower */
#if 0
UNIONFS_INTERNAL_DEBUG("unionfs_lookup: debug: whiteout=%d, path=%s\n", iswhiteout, cnp->cn_nameptr);
#endif
}
/*
* lookup lower layer
*/
if (ldvp != NULLVP && !(cnflags & DOWHITEOUT) && iswhiteout == 0) {
/* always op is LOOKUP */
cnp->cn_nameiop = LOOKUP;
cnflagsbk = cnp->cn_flags;
cnp->cn_flags = cnflags;
lerror = VOP_LOOKUP(ldvp, &lvp, cnp);
cnp->cn_nameiop = nameiop;
if (udvp != NULLVP && (uerror == 0 || uerror == EJUSTRETURN))
cnp->cn_flags = cnflagsbk;
if (lerror == 0) {
if (ldvp == lvp) { /* is dot */
if (uvp != NULLVP)
vrele(uvp); /* no need? */
vrele(lvp);
*(ap->a_vpp) = dvp;
vref(dvp);
UNIONFS_INTERNAL_DEBUG("unionfs_lookup: leave (%d)\n", lerror);
if (uvp != NULL)
VOP_UNLOCK(uvp);
return (lerror);
}
}
}
/*
* check lookup result
*/
if (uvp == NULLVP && lvp == NULLVP) {
UNIONFS_INTERNAL_DEBUG("unionfs_lookup: leave (%d)\n",
(udvp != NULLVP ? uerror : lerror));
return (udvp != NULLVP ? uerror : lerror);
}
/*
* check vnode type
*/
if (uvp != NULLVP && lvp != NULLVP && uvp->v_type != lvp->v_type) {
vput(lvp);
lvp = NULLVP;
}
/*
* check shadow dir
*/
if (uerror != 0 && uerror != EJUSTRETURN && udvp != NULLVP &&
lerror == 0 && lvp != NULLVP && lvp->v_type == VDIR &&
!(dvp->v_mount->mnt_flag & MNT_RDONLY) &&
(1 < cnp->cn_namelen || '.' != *(cnp->cn_nameptr))) {
/* get unionfs vnode in order to create a new shadow dir. */
error = unionfs_nodeget(dvp->v_mount, NULLVP, lvp, dvp, &vp,
cnp);
if (error != 0)
goto unionfs_lookup_out;
error = unionfs_mkshadowdir(MOUNTTOUNIONFSMOUNT(dvp->v_mount),
udvp, VTOUNIONFS(vp), cnp);
if (error != 0) {
UNIONFSDEBUG("unionfs_lookup: Unable to create shadow dir.");
vput(vp);
goto unionfs_lookup_out;
}
}
/*
* get unionfs vnode.
*/
else {
if (uvp != NULLVP)
error = uerror;
else
error = lerror;
if (error != 0)
goto unionfs_lookup_out;
error = unionfs_nodeget(dvp->v_mount, uvp, lvp, dvp, &vp, cnp);
if (error != 0) {
UNIONFSDEBUG("unionfs_lookup: Unable to create unionfs vnode.");
goto unionfs_lookup_out;
}
}
*(ap->a_vpp) = vp;
cache_enter(dvp, vp, cnp->cn_nameptr, cnp->cn_namelen,
cnp->cn_flags);
/* XXXAD lock status on error */
unionfs_lookup_out:
if (uvp != NULLVP)
vrele(uvp);
if (lvp != NULLVP)
vrele(lvp);
if (error == ENOENT && nameiop != CREATE)
cache_enter(dvp, NULLVP, cnp->cn_nameptr, cnp->cn_namelen,
cnp->cn_flags);
UNIONFS_INTERNAL_DEBUG("unionfs_lookup: leave (%d)\n", error);
return (error);
}
static int
unionfs_create(void *v)
{
struct vop_create_v3_args /* {
struct vnode *a_dvp;
struct vnode **a_vpp;
struct componentname *a_cnp;
struct vattr *a_vap;
} */ *ap = v;
struct unionfs_node *dunp;
struct componentname *cnp;
struct vnode *udvp;
struct vnode *vp;
int error;
UNIONFS_INTERNAL_DEBUG("unionfs_create: enter\n");
dunp = VTOUNIONFS(ap->a_dvp);
cnp = ap->a_cnp;
udvp = dunp->un_uppervp;
error = EROFS;
if (udvp != NULLVP) {
if ((error = VOP_CREATE(udvp, &vp, cnp, ap->a_vap)) == 0) {
error = unionfs_nodeget(ap->a_dvp->v_mount, vp, NULLVP,
ap->a_dvp, ap->a_vpp, cnp);
if (error) {
vput(vp);
} else {
vrele(vp);
}
}
}
UNIONFS_INTERNAL_DEBUG("unionfs_create: leave (%d)\n", error);
return (error);
}
static int
unionfs_whiteout(void *v)
{
struct vop_whiteout_args *ap = v;
struct unionfs_node *dunp;
struct componentname *cnp;
struct vnode *udvp;
int error;
UNIONFS_INTERNAL_DEBUG("unionfs_whiteout: enter\n");
dunp = VTOUNIONFS(ap->a_dvp);
cnp = ap->a_cnp;
udvp = dunp->un_uppervp;
error = EOPNOTSUPP;
if (udvp != NULLVP) {
switch (ap->a_flags) {
case CREATE:
case DELETE:
case LOOKUP:
error = VOP_WHITEOUT(udvp, cnp, ap->a_flags);
break;
default:
error = EINVAL;
break;
}
}
UNIONFS_INTERNAL_DEBUG("unionfs_whiteout: leave (%d)\n", error);
return (error);
}
static int
unionfs_mknod(void *v)
{
struct vop_mknod_v3_args /* {
struct vnode *a_dvp;
struct vnode **a_vpp;
struct componentname *a_cnp;
struct vattr *a_vap;
} */ *ap = v;
struct unionfs_node *dunp;
struct componentname *cnp;
struct vnode *udvp;
struct vnode *vp;
int error;
UNIONFS_INTERNAL_DEBUG("unionfs_mknod: enter\n");
dunp = VTOUNIONFS(ap->a_dvp);
cnp = ap->a_cnp;
udvp = dunp->un_uppervp;
error = EROFS;
if (udvp != NULLVP) {
if ((error = VOP_MKNOD(udvp, &vp, cnp, ap->a_vap)) == 0) {
error = unionfs_nodeget(ap->a_dvp->v_mount, vp, NULLVP,
ap->a_dvp, ap->a_vpp, cnp);
if (error) {
vput(vp);
} else {
vrele(vp);
}
}
}
UNIONFS_INTERNAL_DEBUG("unionfs_mknod: leave (%d)\n", error);
return (error);
}
static int
unionfs_open(void *v)
{
struct vop_open_args *ap = v;
int error;
struct unionfs_node *unp;
struct unionfs_node_status *unsp;
struct vnode *uvp;
struct vnode *lvp;
struct vnode *targetvp;
kauth_cred_t cred;
UNIONFS_INTERNAL_DEBUG("unionfs_open: enter\n");
error = 0;
unp = VTOUNIONFS(ap->a_vp);
uvp = unp->un_uppervp;
lvp = unp->un_lowervp;
targetvp = NULLVP;
cred = ap->a_cred;
unionfs_get_node_status(unp, &unsp);
if (unsp->uns_lower_opencnt > 0 || unsp->uns_upper_opencnt > 0) {
/* vnode is already opend. */
if (unsp->uns_upper_opencnt > 0)
targetvp = uvp;
else
targetvp = lvp;
if (targetvp == lvp &&
(ap->a_mode & FWRITE) && lvp->v_type == VREG)
targetvp = NULLVP;
}
if (targetvp == NULLVP) {
if (uvp == NULLVP) {
if ((ap->a_mode & FWRITE) && lvp->v_type == VREG) {
error = unionfs_copyfile(unp,
!(ap->a_mode & O_TRUNC), cred);
if (error != 0)
goto unionfs_open_abort;
targetvp = uvp = unp->un_uppervp;
} else
targetvp = lvp;
} else
targetvp = uvp;
}
error = VOP_OPEN(targetvp, ap->a_mode, cred);
if (error == 0) {
if (targetvp == uvp) {
if (uvp->v_type == VDIR && lvp != NULLVP &&
unsp->uns_lower_opencnt <= 0) {
/* open lower for readdir */
error = VOP_OPEN(lvp, FREAD, cred);
if (error != 0) {
VOP_CLOSE(uvp, ap->a_mode, cred);
goto unionfs_open_abort;
}
unsp->uns_node_flag |= UNS_OPENL_4_READDIR;
unsp->uns_lower_opencnt++;
}
unsp->uns_upper_opencnt++;
} else {
unsp->uns_lower_opencnt++;
unsp->uns_lower_openmode = ap->a_mode;
}
}
unionfs_open_abort:
if (error != 0)
unionfs_tryrem_node_status(unp, unsp);
UNIONFS_INTERNAL_DEBUG("unionfs_open: leave (%d)\n", error);
return (error);
}
static int
unionfs_close(void *v)
{
struct vop_close_args *ap = v;
int error;
struct unionfs_node *unp;
struct unionfs_node_status *unsp;
kauth_cred_t cred;
struct vnode *ovp;
UNIONFS_INTERNAL_DEBUG("unionfs_close: enter\n");
KASSERT(VOP_ISLOCKED(ap->a_vp) == LK_EXCLUSIVE);
unp = VTOUNIONFS(ap->a_vp);
cred = ap->a_cred;
unionfs_get_node_status(unp, &unsp);
if (unsp->uns_lower_opencnt <= 0 && unsp->uns_upper_opencnt <= 0) {
#ifdef DIAGNOSTIC
printf("unionfs_close: warning: open count is 0\n");
#endif
if (unp->un_uppervp != NULLVP)
ovp = unp->un_uppervp;
else
ovp = unp->un_lowervp;
} else if (unsp->uns_upper_opencnt > 0)
ovp = unp->un_uppervp;
else
ovp = unp->un_lowervp;
error = VOP_CLOSE(ovp, ap->a_fflag, cred);
if (error != 0)
goto unionfs_close_abort;
if (ovp == unp->un_uppervp) {
unsp->uns_upper_opencnt--;
if (unsp->uns_upper_opencnt == 0) {
if (unsp->uns_node_flag & UNS_OPENL_4_READDIR) {
VOP_CLOSE(unp->un_lowervp, FREAD, cred);
unsp->uns_node_flag &= ~UNS_OPENL_4_READDIR;
unsp->uns_lower_opencnt--;
}
}
} else
unsp->uns_lower_opencnt--;
unionfs_close_abort:
unionfs_tryrem_node_status(unp, unsp);
UNIONFS_INTERNAL_DEBUG("unionfs_close: leave (%d)\n", error);
return (error);
}
/*
* Check the access mode toward shadow file/dir.
*/
static int
unionfs_check_corrected_access(u_short mode, struct vattr *va, kauth_cred_t cred)
{
uid_t uid; /* upper side vnode's uid */
gid_t gid; /* upper side vnode's gid */
u_short vmode; /* upper side vnode's mode */
u_short mask;
mask = 0;
uid = va->va_uid;
gid = va->va_gid;
vmode = va->va_mode;
/* check owner */
if (kauth_cred_getuid(cred) == uid) {
if (mode & VEXEC)
mask |= S_IXUSR;
if (mode & VREAD)
mask |= S_IRUSR;
if (mode & VWRITE)
mask |= S_IWUSR;
return ((vmode & mask) == mask ? 0 : EACCES);
}
/* check group */
if (kauth_cred_groupmember(cred, gid) == 0) {
if (mode & VEXEC)
mask |= S_IXGRP;
if (mode & VREAD)
mask |= S_IRGRP;
if (mode & VWRITE)
mask |= S_IWGRP;
return ((vmode & mask) == mask ? 0 : EACCES);
}
/* check other */
if (mode & VEXEC)
mask |= S_IXOTH;
if (mode & VREAD)
mask |= S_IROTH;
if (mode & VWRITE)
mask |= S_IWOTH;
return ((vmode & mask) == mask ? 0 : EACCES);
}
static int
unionfs_access(void *v)
{
struct vop_access_args /* {
struct vnodeop_desc *a_desc;
struct vnode *a_vp;
accmode_t a_accmode;
kauth_cred_t a_cred;
} */ *ap = v;
struct unionfs_mount *ump;
struct unionfs_node *unp;
struct vnode *uvp;
struct vnode *lvp;
struct vattr va;
int accmode;
int error;
UNIONFS_INTERNAL_DEBUG("unionfs_access: enter\n");
ump = MOUNTTOUNIONFSMOUNT(ap->a_vp->v_mount);
unp = VTOUNIONFS(ap->a_vp);
uvp = unp->un_uppervp;
lvp = unp->un_lowervp;
accmode = ap->a_accmode;
error = EACCES;
if ((accmode & VWRITE) &&
(ap->a_vp->v_mount->mnt_flag & MNT_RDONLY)) {
switch (ap->a_vp->v_type) {
case VREG:
case VDIR:
case VLNK:
return (EROFS);
default:
break;
}
}
if (uvp != NULLVP) {
error = VOP_ACCESS(uvp, accmode, ap->a_cred);
UNIONFS_INTERNAL_DEBUG("unionfs_access: leave (%d)\n", error);
return (error);
}
if (lvp != NULLVP) {
if (accmode & VWRITE) {
if (ump->um_uppervp->v_mount->mnt_flag & MNT_RDONLY) {
switch (ap->a_vp->v_type) {
case VREG:
case VDIR:
case VLNK:
return (EROFS);
default:
break;
}
} else if (ap->a_vp->v_type == VREG || ap->a_vp->v_type == VDIR) {
/* check shadow file/dir */
if (ump->um_copymode != UNIONFS_TRANSPARENT) {
error = unionfs_create_uppervattr(ump,
lvp, &va, ap->a_cred);
if (error != 0)
return (error);
error = unionfs_check_corrected_access(
accmode, &va, ap->a_cred);
if (error != 0)
return (error);
}
}
accmode &= ~VWRITE;
accmode |= VREAD; /* will copy to upper */
}
error = VOP_ACCESS(lvp, accmode, ap->a_cred);
}
UNIONFS_INTERNAL_DEBUG("unionfs_access: leave (%d)\n", error);
return (error);
}
static int
unionfs_getattr(void *v)
{
struct vop_getattr_args *ap = v;
int error;
struct unionfs_node *unp;
struct unionfs_mount *ump;
struct vnode *uvp;
struct vnode *lvp;
struct vattr va;
UNIONFS_INTERNAL_DEBUG("unionfs_getattr: enter\n");
unp = VTOUNIONFS(ap->a_vp);
ump = MOUNTTOUNIONFSMOUNT(ap->a_vp->v_mount);
uvp = unp->un_uppervp;
lvp = unp->un_lowervp;
if (uvp != NULLVP) {
if ((error = VOP_GETATTR(uvp, ap->a_vap, ap->a_cred)) == 0)
ap->a_vap->va_fsid = ap->a_vp->v_mount->mnt_stat.f_fsid;
UNIONFS_INTERNAL_DEBUG("unionfs_getattr: leave mode=%o, uid=%d, gid=%d (%d)\n",
ap->a_vap->va_mode, ap->a_vap->va_uid,
ap->a_vap->va_gid, error);
return (error);
}
error = VOP_GETATTR(lvp, ap->a_vap, ap->a_cred);
if (error == 0 && !(ump->um_uppervp->v_mount->mnt_flag & MNT_RDONLY)) {
/* correct the attr toward shadow file/dir. */
if (ap->a_vp->v_type == VREG || ap->a_vp->v_type == VDIR) {
unionfs_create_uppervattr_core(ump, ap->a_vap, &va);
ap->a_vap->va_mode = va.va_mode;
ap->a_vap->va_uid = va.va_uid;
ap->a_vap->va_gid = va.va_gid;
}
}
if (error == 0)
ap->a_vap->va_fsid = ap->a_vp->v_mount->mnt_stat.f_fsid;
UNIONFS_INTERNAL_DEBUG("unionfs_getattr: leave mode=%o, uid=%d, gid=%d (%d)\n",
ap->a_vap->va_mode, ap->a_vap->va_uid, ap->a_vap->va_gid, error);
return (error);
}
static int
unionfs_setattr(void *v)
{
struct vop_setattr_args /* {
struct vnode *a_vp;
struct vattr *a_vap;
kauth_cred_t a_cred;
} */ *ap = v;
int error;
struct unionfs_node *unp;
struct vnode *uvp;
struct vnode *lvp;
struct vattr *vap;
UNIONFS_INTERNAL_DEBUG("unionfs_setattr: enter\n");
error = EROFS;
unp = VTOUNIONFS(ap->a_vp);
uvp = unp->un_uppervp;
lvp = unp->un_lowervp;
vap = ap->a_vap;
if ((ap->a_vp->v_mount->mnt_flag & MNT_RDONLY) &&
(vap->va_flags != (unsigned long )VNOVAL ||
vap->va_uid != (uid_t)VNOVAL ||
vap->va_gid != (gid_t)VNOVAL || vap->va_atime.tv_sec != VNOVAL ||
vap->va_mtime.tv_sec != VNOVAL || vap->va_mode != (mode_t)VNOVAL))
return (EROFS);
if (uvp == NULLVP && lvp->v_type == VREG) {
error = unionfs_copyfile(unp, (vap->va_size != 0),
ap->a_cred);
if (error != 0)
return (error);
uvp = unp->un_uppervp;
}
if (uvp != NULLVP)
error = VOP_SETATTR(uvp, vap, ap->a_cred);
UNIONFS_INTERNAL_DEBUG("unionfs_setattr: leave (%d)\n", error);
return (error);
}
static int
unionfs_read(void *v)
{
struct vop_read_args *ap = v;
int error;
struct unionfs_node *unp;
struct vnode *tvp;
/* UNIONFS_INTERNAL_DEBUG("unionfs_read: enter\n"); */
unp = VTOUNIONFS(ap->a_vp);
tvp = (unp->un_uppervp != NULLVP ? unp->un_uppervp : unp->un_lowervp);
error = VOP_READ(tvp, ap->a_uio, ap->a_ioflag, ap->a_cred);
/* UNIONFS_INTERNAL_DEBUG("unionfs_read: leave (%d)\n", error); */
return (error);
}
static int
unionfs_write(void *v)
{
struct vop_write_args *ap = v;
int error;
struct unionfs_node *unp;
struct vnode *tvp;
/* UNIONFS_INTERNAL_DEBUG("unionfs_write: enter\n"); */
unp = VTOUNIONFS(ap->a_vp);
tvp = (unp->un_uppervp != NULLVP ? unp->un_uppervp : unp->un_lowervp);
error = VOP_WRITE(tvp, ap->a_uio, ap->a_ioflag, ap->a_cred);
/* UNIONFS_INTERNAL_DEBUG("unionfs_write: leave (%d)\n", error); */
return (error);
}
static int
unionfs_ioctl(void *v)
{
struct vop_ioctl_args *ap = v;
int error;
struct unionfs_node *unp;
struct unionfs_node_status *unsp;
struct vnode *ovp;
UNIONFS_INTERNAL_DEBUG("unionfs_ioctl: enter\n");
vn_lock(ap->a_vp, LK_EXCLUSIVE | LK_RETRY);
unp = VTOUNIONFS(ap->a_vp);
unionfs_get_node_status(unp, &unsp);
ovp = (unsp->uns_upper_opencnt ? unp->un_uppervp : unp->un_lowervp);
unionfs_tryrem_node_status(unp, unsp);
VOP_UNLOCK(ap->a_vp);
if (ovp == NULLVP)
return (EBADF);
error = VOP_IOCTL(ovp, ap->a_command, ap->a_data, ap->a_fflag,
ap->a_cred);
UNIONFS_INTERNAL_DEBUG("unionfs_ioctl: lease (%d)\n", error);
return (error);
}
static int
unionfs_poll(void *v)
{
struct vop_poll_args *ap = v;
struct unionfs_node *unp;
struct unionfs_node_status *unsp;
struct vnode *ovp;
vn_lock(ap->a_vp, LK_EXCLUSIVE | LK_RETRY);
unp = VTOUNIONFS(ap->a_vp);
unionfs_get_node_status(unp, &unsp);
ovp = (unsp->uns_upper_opencnt ? unp->un_uppervp : unp->un_lowervp);
unionfs_tryrem_node_status(unp, unsp);
VOP_UNLOCK(ap->a_vp);
if (ovp == NULLVP)
return (EBADF);
return (VOP_POLL(ovp, ap->a_events));
}
static int
unionfs_fsync(void *v)
{
struct vop_fsync_args *ap = v;
struct unionfs_node *unp;
struct unionfs_node_status *unsp;
struct vnode *ovp;
unp = VTOUNIONFS(ap->a_vp);
unionfs_get_node_status(unp, &unsp);
ovp = (unsp->uns_upper_opencnt ? unp->un_uppervp : unp->un_lowervp);
unionfs_tryrem_node_status(unp, unsp);
if (ovp == NULLVP)
return (EBADF);
return (VOP_FSYNC(ovp, ap->a_cred, ap->a_flags, ap->a_offlo, ap->a_offhi));
}
static int
unionfs_remove(void *v)
{
struct vop_remove_v3_args *ap = v;
int error;
struct unionfs_node *dunp;
struct unionfs_node *unp;
struct unionfs_mount *ump;
struct vnode *udvp;
struct vnode *uvp;
struct vnode *lvp;
struct componentname *cnp;
UNIONFS_INTERNAL_DEBUG("unionfs_remove: enter\n");
error = 0;
dunp = VTOUNIONFS(ap->a_dvp);
unp = VTOUNIONFS(ap->a_vp);
udvp = dunp->un_uppervp;
uvp = unp->un_uppervp;
lvp = unp->un_lowervp;
cnp = ap->a_cnp;
if (udvp == NULLVP) {
vput(ap->a_vp);
return (EROFS);
}
if (uvp != NULLVP) {
ump = MOUNTTOUNIONFSMOUNT(ap->a_vp->v_mount);
if (ump->um_whitemode == UNIONFS_WHITE_ALWAYS || lvp != NULLVP)
cnp->cn_flags |= DOWHITEOUT;
error = VOP_REMOVE(udvp, uvp, cnp);
} else if (lvp != NULLVP)
error = unionfs_mkwhiteout(udvp, cnp, unp->un_path);
UNIONFS_INTERNAL_DEBUG("unionfs_remove: leave (%d)\n", error);
return (error);
}
static int
unionfs_link(void *v)
{
#if 0
struct vop_link_v2_args *ap = v;
int error;
int needrelookup;
struct unionfs_node *dunp;
struct unionfs_node *unp;
struct vnode *udvp;
struct vnode *uvp;
struct componentname *cnp;
UNIONFS_INTERNAL_DEBUG("unionfs_link: enter\n");
error = 0;
needrelookup = 0;
dunp = VTOUNIONFS(ap->a_tdvp);
unp = NULL;
udvp = dunp->un_uppervp;
uvp = NULLVP;
cnp = ap->a_cnp;
if (udvp == NULLVP)
return (EROFS);
if (ap->a_vp->v_op != unionfs_vnodeop_p)
uvp = ap->a_vp;
else {
unp = VTOUNIONFS(ap->a_vp);
if (unp->un_uppervp == NULLVP) {
if (ap->a_vp->v_type != VREG)
return (EOPNOTSUPP);
error = unionfs_copyfile(unp, 1, cnp->cn_cred);
if (error != 0)
return (error);
needrelookup = 1;
}
uvp = unp->un_uppervp;
}
if (needrelookup != 0)
error = unionfs_relookup_for_create(ap->a_tdvp, cnp);
if (error == 0)
error = VOP_LINK(udvp, uvp, cnp);
UNIONFS_INTERNAL_DEBUG("unionfs_link: leave (%d)\n", error);
return (error);
#else
panic("XXXAD");
return 0;
#endif
}
static int
unionfs_rename(void *v)
{
struct vop_rename_args *ap = v;
int error;
struct vnode *fdvp;
struct vnode *fvp;
struct componentname *fcnp;
struct vnode *tdvp;
struct vnode *tvp;
struct componentname *tcnp;
struct vnode *ltdvp;
struct vnode *ltvp;
/* rename target vnodes */
struct vnode *rfdvp;
struct vnode *rfvp;
struct vnode *rtdvp;
struct vnode *rtvp;
int needrelookup;
struct unionfs_mount *ump;
struct unionfs_node *unp;
UNIONFS_INTERNAL_DEBUG("unionfs_rename: enter\n");
error = 0;
fdvp = ap->a_fdvp;
fvp = ap->a_fvp;
fcnp = ap->a_fcnp;
tdvp = ap->a_tdvp;
tvp = ap->a_tvp;
tcnp = ap->a_tcnp;
ltdvp = NULLVP;
ltvp = NULLVP;
rfdvp = fdvp;
rfvp = fvp;
rtdvp = tdvp;
rtvp = tvp;
needrelookup = 0;
/* check for cross device rename */
if (fvp->v_mount != tdvp->v_mount ||
(tvp != NULLVP && fvp->v_mount != tvp->v_mount)) {
error = EXDEV;
goto unionfs_rename_abort;
}
/* Renaming a file to itself has no effect. */
if (fvp == tvp)
goto unionfs_rename_abort;
/*
* from/to vnode is unionfs node.
*/
unp = VTOUNIONFS(fdvp);
#ifdef UNIONFS_IDBG_RENAME
UNIONFS_INTERNAL_DEBUG("fdvp=%p, ufdvp=%p, lfdvp=%p\n", fdvp, unp->un_uppervp, unp->un_lowervp);
#endif
if (unp->un_uppervp == NULLVP) {
error = ENODEV;
goto unionfs_rename_abort;
}
rfdvp = unp->un_uppervp;
vref(rfdvp);
unp = VTOUNIONFS(fvp);
#ifdef UNIONFS_IDBG_RENAME
UNIONFS_INTERNAL_DEBUG("fvp=%p, ufvp=%p, lfvp=%p\n", fvp, unp->un_uppervp, unp->un_lowervp);
#endif
ump = MOUNTTOUNIONFSMOUNT(fvp->v_mount);
if (unp->un_uppervp == NULLVP) {
switch (fvp->v_type) {
case VREG:
if ((error = vn_lock(fvp, LK_EXCLUSIVE)) != 0)
goto unionfs_rename_abort;
error = unionfs_copyfile(unp, 1, fcnp->cn_cred);
VOP_UNLOCK(fvp);
if (error != 0)
goto unionfs_rename_abort;
break;
case VDIR:
if ((error = vn_lock(fvp, LK_EXCLUSIVE)) != 0)
goto unionfs_rename_abort;
error = unionfs_mkshadowdir(ump, rfdvp, unp, fcnp);
VOP_UNLOCK(fvp);
if (error != 0)
goto unionfs_rename_abort;
break;
default:
error = ENODEV;
goto unionfs_rename_abort;
}
needrelookup = 1;
}
if (unp->un_lowervp != NULLVP)
fcnp->cn_flags |= DOWHITEOUT;
rfvp = unp->un_uppervp;
vref(rfvp);
unp = VTOUNIONFS(tdvp);
#ifdef UNIONFS_IDBG_RENAME
UNIONFS_INTERNAL_DEBUG("tdvp=%p, utdvp=%p, ltdvp=%p\n", tdvp, unp->un_uppervp, unp->un_lowervp);
#endif
if (unp->un_uppervp == NULLVP) {
error = ENODEV;
goto unionfs_rename_abort;
}
rtdvp = unp->un_uppervp;
ltdvp = unp->un_lowervp;
vref(rtdvp);
if (tdvp == tvp) {
rtvp = rtdvp;
vref(rtvp);
} else if (tvp != NULLVP) {
unp = VTOUNIONFS(tvp);
#ifdef UNIONFS_IDBG_RENAME
UNIONFS_INTERNAL_DEBUG("tvp=%p, utvp=%p, ltvp=%p\n", tvp, unp->un_uppervp, unp->un_lowervp);
#endif
if (unp->un_uppervp == NULLVP)
rtvp = NULLVP;
else {
if (tvp->v_type == VDIR) {
error = EINVAL;
goto unionfs_rename_abort;
}
rtvp = unp->un_uppervp;
ltvp = unp->un_lowervp;
vref(rtvp);
}
}
if (needrelookup != 0) {
if ((error = vn_lock(fdvp, LK_EXCLUSIVE)) != 0)
goto unionfs_rename_abort;
error = unionfs_relookup_for_delete(fdvp, fcnp);
VOP_UNLOCK(fdvp);
if (error != 0)
goto unionfs_rename_abort;
/* Locke of tvp is canceled in order to avoid recursive lock. */
if (tvp != NULLVP && tvp != tdvp)
VOP_UNLOCK(tvp);
error = unionfs_relookup_for_rename(tdvp, tcnp);
if (tvp != NULLVP && tvp != tdvp)
vn_lock(tvp, LK_EXCLUSIVE | LK_RETRY);
if (error != 0)
goto unionfs_rename_abort;
}
error = VOP_RENAME(rfdvp, rfvp, fcnp, rtdvp, rtvp, tcnp);
if (error == 0) {
if (rtvp != NULLVP && rtvp->v_type == VDIR)
cache_purge(tdvp);
if (fvp->v_type == VDIR && fdvp != tdvp)
cache_purge(fdvp);
}
if (fdvp != rfdvp)
vrele(fdvp);
if (fvp != rfvp)
vrele(fvp);
if (ltdvp != NULLVP)
VOP_UNLOCK(ltdvp);
if (tdvp != rtdvp)
vrele(tdvp);
if (ltvp != NULLVP)
VOP_UNLOCK(ltvp);
if (tvp != rtvp && tvp != NULLVP) {
if (rtvp == NULLVP)
vput(tvp);
else
vrele(tvp);
}
UNIONFS_INTERNAL_DEBUG("unionfs_rename: leave (%d)\n", error);
return (error);
unionfs_rename_abort:
if (fdvp != rfdvp)
vrele(rfdvp);
if (fvp != rfvp)
vrele(rfvp);
if (tdvp != rtdvp)
vrele(rtdvp);
vput(tdvp);
if (tvp != rtvp && rtvp != NULLVP)
vrele(rtvp);
if (tvp != NULLVP) {
if (tdvp != tvp)
vput(tvp);
else
vrele(tvp);
}
vrele(fdvp);
vrele(fvp);
UNIONFS_INTERNAL_DEBUG("unionfs_rename: leave (%d)\n", error);
return (error);
}
static int
unionfs_mkdir(void *v)
{
struct vop_mkdir_v3_args /* {
struct vnode *a_dvp;
struct vnode **a_vpp;
struct componentname *a_cnp;
struct vattr *a_vap;
} */ *ap = v;
int error;
struct unionfs_node *dunp;
struct componentname *cnp;
struct vnode *udvp;
struct vnode *uvp;
struct vattr va;
UNIONFS_INTERNAL_DEBUG("unionfs_mkdir: enter\n");
error = EROFS;
dunp = VTOUNIONFS(ap->a_dvp);
cnp = ap->a_cnp;
udvp = dunp->un_uppervp;
if (udvp != NULLVP) {
/* check opaque */
if (!(cnp->cn_flags & ISWHITEOUT)) {
error = VOP_GETATTR(udvp, &va, cnp->cn_cred);
if (error != 0)
return (error);
if (va.va_flags & OPAQUE)
cnp->cn_flags |= ISWHITEOUT;
}
if ((error = VOP_MKDIR(udvp, &uvp, cnp, ap->a_vap)) == 0) {
error = unionfs_nodeget(ap->a_dvp->v_mount, uvp, NULLVP,
ap->a_dvp, ap->a_vpp, cnp);
if (error) {
vput(uvp);
} else {
vrele(uvp);
}
}
}
UNIONFS_INTERNAL_DEBUG("unionfs_mkdir: leave (%d)\n", error);
return (error);
}
static int
unionfs_rmdir(void *v)
{
struct vop_rmdir_v2_args *ap = v;
int error;
struct unionfs_node *dunp;
struct unionfs_node *unp;
struct unionfs_mount *ump;
struct componentname *cnp;
struct vnode *udvp;
struct vnode *uvp;
struct vnode *lvp;
UNIONFS_INTERNAL_DEBUG("unionfs_rmdir: enter\n");
error = 0;
dunp = VTOUNIONFS(ap->a_dvp);
unp = VTOUNIONFS(ap->a_vp);
cnp = ap->a_cnp;
udvp = dunp->un_uppervp;
uvp = unp->un_uppervp;
lvp = unp->un_lowervp;
if (udvp == NULLVP) {
vput(ap->a_vp);
return (EROFS);
}
if (udvp == uvp)
return (EOPNOTSUPP);
if (uvp != NULLVP) {
if (lvp != NULLVP) {
error = unionfs_check_rmdir(ap->a_vp, cnp->cn_cred);
if (error != 0)
return (error);
}
ump = MOUNTTOUNIONFSMOUNT(ap->a_vp->v_mount);
if (ump->um_whitemode == UNIONFS_WHITE_ALWAYS || lvp != NULLVP)
cnp->cn_flags |= DOWHITEOUT;
error = VOP_RMDIR(udvp, uvp, cnp);
}
else if (lvp != NULLVP)
error = unionfs_mkwhiteout(udvp, cnp, unp->un_path);
if (error == 0) {
cache_purge(ap->a_dvp);
cache_purge(ap->a_vp);
}
UNIONFS_INTERNAL_DEBUG("unionfs_rmdir: leave (%d)\n", error);
return (error);
}
static int
unionfs_symlink(void *v)
{
struct vop_symlink_v3_args /* {
struct vnode *a_dvp;
struct vnode **a_vpp;
struct componentname *a_cnp;
struct vattr *a_vap;
char *a_target;
} */ *ap = v;
int error;
struct unionfs_node *dunp;
struct componentname *cnp;
struct vnode *udvp;
struct vnode *uvp;
UNIONFS_INTERNAL_DEBUG("unionfs_symlink: enter\n");
error = EROFS;
dunp = VTOUNIONFS(ap->a_dvp);
cnp = ap->a_cnp;
udvp = dunp->un_uppervp;
if (udvp != NULLVP) {
error = VOP_SYMLINK(udvp, &uvp, cnp, ap->a_vap, ap->a_target);
if (error == 0) {
error = unionfs_nodeget(ap->a_dvp->v_mount, uvp, NULLVP,
ap->a_dvp, ap->a_vpp, cnp);
if (error) {
vput(uvp);
} else {
vrele(uvp);
}
}
}
UNIONFS_INTERNAL_DEBUG("unionfs_symlink: leave (%d)\n", error);
return (error);
}
static int
unionfs_readdir(void *v)
{
struct vop_readdir_args *ap = v;
int error;
int eofflag;
struct unionfs_node *unp;
struct unionfs_node_status *unsp;
struct uio *uio;
struct vnode *uvp;
struct vnode *lvp;
struct vattr va;
int ncookies_bk;
off_t *cookies_bk;
UNIONFS_INTERNAL_DEBUG("unionfs_readdir: enter\n");
error = 0;
eofflag = 0;
unp = VTOUNIONFS(ap->a_vp);
uio = ap->a_uio;
uvp = unp->un_uppervp;
lvp = unp->un_lowervp;
ncookies_bk = 0;
cookies_bk = NULL;
if (ap->a_vp->v_type != VDIR)
return (ENOTDIR);
/* check opaque */
if (uvp != NULLVP && lvp != NULLVP) {
if ((error = VOP_GETATTR(uvp, &va, ap->a_cred)) != 0)
goto unionfs_readdir_exit;
if (va.va_flags & OPAQUE)
lvp = NULLVP;
}
/* check the open count. unionfs needs to open before readdir. */
VOP_UNLOCK(ap->a_vp);
vn_lock(ap->a_vp, LK_EXCLUSIVE | LK_RETRY);
unionfs_get_node_status(unp, &unsp);
if ((uvp != NULLVP && unsp->uns_upper_opencnt <= 0) ||
(lvp != NULLVP && unsp->uns_lower_opencnt <= 0)) {
unionfs_tryrem_node_status(unp, unsp);
error = EBADF;
}
if (error != 0)
goto unionfs_readdir_exit;
/* upper only */
if (uvp != NULLVP && lvp == NULLVP) {
error = VOP_READDIR(uvp, uio, ap->a_cred, ap->a_eofflag,
ap->a_cookies, ap->a_ncookies);
unsp->uns_readdir_status = 0;
goto unionfs_readdir_exit;
}
/* lower only */
if (uvp == NULLVP && lvp != NULLVP) {
error = VOP_READDIR(lvp, uio, ap->a_cred, ap->a_eofflag,
ap->a_cookies, ap->a_ncookies);
unsp->uns_readdir_status = 2;
goto unionfs_readdir_exit;
}
/*
* readdir upper and lower
*/
KASSERT(uvp != NULLVP);
KASSERT(lvp != NULLVP);
if (uio->uio_offset == 0)
unsp->uns_readdir_status = 0;
if (unsp->uns_readdir_status == 0) {
/* read upper */
error = VOP_READDIR(uvp, uio, ap->a_cred, &eofflag,
ap->a_cookies, ap->a_ncookies);
if (error != 0 || eofflag == 0)
goto unionfs_readdir_exit;
unsp->uns_readdir_status = 1;
/*
* ufs(and other fs) needs size of uio_resid larger than
* DIRBLKSIZ.
* size of DIRBLKSIZ equals DEV_BSIZE.
* (see: ufs/ufs/ufs_vnops.c ufs_readdir func , ufs/ufs/dir.h)
*/
if (uio->uio_resid <= (uio->uio_resid & (DEV_BSIZE -1)))
goto unionfs_readdir_exit;
/*
* backup cookies
* It prepares to readdir in lower.
*/
if (ap->a_ncookies != NULL) {
ncookies_bk = *(ap->a_ncookies);
*(ap->a_ncookies) = 0;
}
if (ap->a_cookies != NULL) {
cookies_bk = *(ap->a_cookies);
*(ap->a_cookies) = NULL;
}
}
/* initialize for readdir in lower */
if (unsp->uns_readdir_status == 1) {
unsp->uns_readdir_status = 2;
uio->uio_offset = 0;
}
if (lvp == NULLVP) {
error = EBADF;
goto unionfs_readdir_exit;
}
/* read lower */
error = VOP_READDIR(lvp, uio, ap->a_cred, ap->a_eofflag,
ap->a_cookies, ap->a_ncookies);
if (cookies_bk != NULL) {
/* merge cookies */
int size;
off_t *newcookies, *pos;
size = *(ap->a_ncookies) + ncookies_bk;
newcookies = (off_t *) malloc(size * sizeof(off_t),
M_TEMP, M_WAITOK);
pos = newcookies;
memcpy(pos, cookies_bk, ncookies_bk * sizeof(off_t));
pos += ncookies_bk * sizeof(off_t);
memcpy(pos, *(ap->a_cookies), *(ap->a_ncookies) * sizeof(off_t));
free(cookies_bk, M_TEMP);
free(*(ap->a_cookies), M_TEMP);
*(ap->a_ncookies) = size;
*(ap->a_cookies) = newcookies;
}
unionfs_readdir_exit:
if (error != 0 && ap->a_eofflag != NULL)
*(ap->a_eofflag) = 1;
UNIONFS_INTERNAL_DEBUG("unionfs_readdir: leave (%d)\n", error);
return (error);
}
static int
unionfs_readlink(void *v)
{
struct vop_readlink_args *ap = v;
int error;
struct unionfs_node *unp;
struct vnode *vp;
UNIONFS_INTERNAL_DEBUG("unionfs_readlink: enter\n");
unp = VTOUNIONFS(ap->a_vp);
vp = (unp->un_uppervp != NULLVP ? unp->un_uppervp : unp->un_lowervp);
error = VOP_READLINK(vp, ap->a_uio, ap->a_cred);
UNIONFS_INTERNAL_DEBUG("unionfs_readlink: leave (%d)\n", error);
return (error);
}
static int
unionfs_inactive(void *v)
{
struct vop_inactive_v2_args *ap = v;
*ap->a_recycle = true;
return (0);
}
static int
unionfs_reclaim(void *v)
{
struct vop_reclaim_v2_args *ap = v;
/* UNIONFS_INTERNAL_DEBUG("unionfs_reclaim: enter\n"); */
VOP_UNLOCK(ap->a_vp);
unionfs_noderem(ap->a_vp);
/* UNIONFS_INTERNAL_DEBUG("unionfs_reclaim: leave\n"); */
return (0);
}
static int
unionfs_print(void *v)
{
struct vop_print_args *ap = v;
struct unionfs_node *unp;
/* struct unionfs_node_status *unsp; */
unp = VTOUNIONFS(ap->a_vp);
/* unionfs_get_node_status(unp, &unsp); */
printf("unionfs_vp=%p, uppervp=%p, lowervp=%p\n",
ap->a_vp, unp->un_uppervp, unp->un_lowervp);
/*
printf("unionfs opencnt: uppervp=%d, lowervp=%d\n",
unsp->uns_upper_opencnt, unsp->uns_lower_opencnt);
*/
if (unp->un_uppervp != NULLVP)
vprint("unionfs: upper", unp->un_uppervp);
if (unp->un_lowervp != NULLVP)
vprint("unionfs: lower", unp->un_lowervp);
return (0);
}
static int
unionfs_lock(void *v)
{
struct vop_lock_args *ap = v;
int error;
int flags;
struct vnode *lvp;
struct vnode *uvp;
struct unionfs_node *unp;
unp = VTOUNIONFS(ap->a_vp);
lvp = unp->un_lowervp;
uvp = unp->un_uppervp;
flags = ap->a_flags;
error = 0;
if (lvp != NULLVP) {
error = VOP_LOCK(lvp, flags);
}
if (error == 0 && uvp != NULLVP) {
error = VOP_LOCK(uvp, flags);
if (error != 0) {
VOP_UNLOCK(lvp);
}
}
return error;
}
static int
unionfs_unlock(void *v)
{
struct vop_unlock_args *ap = v;
int error;
struct vnode *lvp;
struct vnode *uvp;
struct unionfs_node *unp;
unp = VTOUNIONFS(ap->a_vp);
lvp = unp->un_lowervp;
uvp = unp->un_uppervp;
error = 0;
if (lvp != NULLVP) {
error = VOP_UNLOCK(lvp);
}
if (error == 0 && uvp != NULLVP) {
error = VOP_UNLOCK(uvp);
}
return error;
}
static int
unionfs_pathconf(void *v)
{
struct vop_pathconf_args *ap = v;
struct unionfs_node *unp;
struct vnode *vp;
unp = VTOUNIONFS(ap->a_vp);
vp = (unp->un_uppervp != NULLVP ? unp->un_uppervp : unp->un_lowervp);
return (VOP_PATHCONF(vp, ap->a_name, ap->a_retval));
}
static int
unionfs_advlock(void *v)
{
struct vop_advlock_args *ap = v;
int error;
struct unionfs_node *unp;
struct unionfs_node_status *unsp;
struct vnode *vp;
struct vnode *uvp;
kauth_cred_t cred;
UNIONFS_INTERNAL_DEBUG("unionfs_advlock: enter\n");
vp = ap->a_vp;
cred = kauth_cred_get();
vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
unp = VTOUNIONFS(ap->a_vp);
uvp = unp->un_uppervp;
if (uvp == NULLVP) {
error = unionfs_copyfile(unp, 1, cred);
if (error != 0)
goto unionfs_advlock_abort;
uvp = unp->un_uppervp;
unionfs_get_node_status(unp, &unsp);
if (unsp->uns_lower_opencnt > 0) {
/* try reopen the vnode */
error = VOP_OPEN(uvp, unsp->uns_lower_openmode, cred);
if (error)
goto unionfs_advlock_abort;
unsp->uns_upper_opencnt++;
VOP_CLOSE(unp->un_lowervp, unsp->uns_lower_openmode, cred);
unsp->uns_lower_opencnt--;
} else
unionfs_tryrem_node_status(unp, unsp);
}
VOP_UNLOCK(vp);
error = VOP_ADVLOCK(uvp, ap->a_id, ap->a_op, ap->a_fl, ap->a_flags);
UNIONFS_INTERNAL_DEBUG("unionfs_advlock: leave (%d)\n", error);
return error;
unionfs_advlock_abort:
VOP_UNLOCK(vp);
UNIONFS_INTERNAL_DEBUG("unionfs_advlock: leave (%d)\n", error);
return error;
}
static int
unionfs_strategy(void *v)
{
struct vop_strategy_args *ap = v;
struct unionfs_node *unp;
struct vnode *vp;
unp = VTOUNIONFS(ap->a_vp);
vp = (unp->un_uppervp != NULLVP ? unp->un_uppervp : unp->un_lowervp);
#ifdef DIAGNOSTIC
if (vp == NULLVP)
panic("unionfs_strategy: nullvp");
if ((ap->a_bp->b_flags & B_READ) == 0 && vp == unp->un_lowervp)
panic("unionfs_strategy: writing to lowervp");
#endif
return (VOP_STRATEGY(vp, ap->a_bp));
}
static int
unionfs_kqfilter(void *v)
{
struct vop_kqfilter_args *ap = v;
struct unionfs_node *unp;
struct vnode *tvp;
unp = VTOUNIONFS(ap->a_vp);
tvp = (unp->un_uppervp != NULLVP ? unp->un_uppervp : unp->un_lowervp);
return VOP_KQFILTER(tvp, ap->a_kn);
}
static int
unionfs_bmap(void *v)
{
struct vop_bmap_args *ap = v;
struct unionfs_node *unp;
struct vnode *tvp;
unp = VTOUNIONFS(ap->a_vp);
tvp = (unp->un_uppervp != NULLVP ? unp->un_uppervp : unp->un_lowervp);
return VOP_BMAP(tvp, ap->a_bn, ap->a_vpp, ap->a_bnp, ap->a_runp);
}
static int
unionfs_mmap(void *v)
{
struct vop_mmap_args *ap = v;
struct unionfs_node *unp;
struct vnode *tvp;
unp = VTOUNIONFS(ap->a_vp);
tvp = (unp->un_uppervp != NULLVP ? unp->un_uppervp : unp->un_lowervp);
return VOP_MMAP(tvp, ap->a_prot, ap->a_cred);
}
static int
unionfs_abortop(void *v)
{
struct vop_abortop_args *ap = v;
struct unionfs_node *unp;
struct vnode *tvp;
unp = VTOUNIONFS(ap->a_dvp);
tvp = (unp->un_uppervp != NULLVP ? unp->un_uppervp : unp->un_lowervp);
return VOP_ABORTOP(tvp, ap->a_cnp);
}
static int
unionfs_islocked(void *v)
{
struct vop_islocked_args *ap = v;
struct unionfs_node *unp;
struct vnode *tvp;
unp = VTOUNIONFS(ap->a_vp);
tvp = (unp->un_uppervp != NULLVP ? unp->un_uppervp : unp->un_lowervp);
return VOP_ISLOCKED(tvp);
}
static int
unionfs_seek(void *v)
{
struct vop_seek_args *ap = v;
struct unionfs_node *unp;
struct vnode *tvp;
unp = VTOUNIONFS(ap->a_vp);
tvp = (unp->un_uppervp != NULLVP ? unp->un_uppervp : unp->un_lowervp);
return VOP_SEEK(tvp, ap->a_oldoff, ap->a_newoff, ap->a_cred);
}
static int
unionfs_putpages(void *v)
{
struct vop_putpages_args /* {
struct vnode *a_vp;
voff_t a_offlo;
voff_t a_offhi;
int a_flags;
} */ *ap = v;
struct vnode *vp = ap->a_vp, *tvp;
struct unionfs_node *unp;
KASSERT(rw_lock_held(vp->v_uobj.vmobjlock));
unp = VTOUNIONFS(vp);
tvp = (unp->un_uppervp != NULLVP ? unp->un_uppervp : unp->un_lowervp);
KASSERT(tvp->v_uobj.vmobjlock == vp->v_uobj.vmobjlock);
if (ap->a_flags & PGO_RECLAIM) {
rw_exit(vp->v_uobj.vmobjlock);
return 0;
}
return VOP_PUTPAGES(tvp, ap->a_offlo, ap->a_offhi, ap->a_flags);
}
static int
unionfs_getpages(void *v)
{
struct vop_getpages_args /* {
struct vnode *a_vp;
voff_t a_offset;
struct vm_page **a_m;
int *a_count;
int a_centeridx;
vm_prot_t a_access_type;
int a_advice;
int a_flags;
} */ *ap = v;
struct vnode *vp = ap->a_vp, *tvp;
struct unionfs_node *unp;
KASSERT(rw_lock_held(vp->v_uobj.vmobjlock));
unp = VTOUNIONFS(vp);
tvp = (unp->un_uppervp != NULLVP ? unp->un_uppervp : unp->un_lowervp);
KASSERT(tvp->v_uobj.vmobjlock == vp->v_uobj.vmobjlock);
if (ap->a_flags & PGO_LOCKED) {
return EBUSY;
}
return VOP_GETPAGES(tvp, ap->a_offset, ap->a_m, ap->a_count,
ap->a_centeridx, ap->a_access_type, ap->a_advice, ap->a_flags);
}
static int
unionfs_revoke(void *v)
{
struct vop_revoke_args *ap = v;
struct unionfs_node *unp;
struct vnode *tvp;
int error;
unp = VTOUNIONFS(ap->a_vp);
tvp = (unp->un_uppervp != NULLVP ? unp->un_uppervp : unp->un_lowervp);
error = VOP_REVOKE(tvp, ap->a_flags);
if (error == 0) {
vgone(ap->a_vp); /* ??? */
}
return error;
}
/*
* Global vfs data structures
*/
int (**unionfs_vnodeop_p)(void *);
const struct vnodeopv_entry_desc unionfs_vnodeop_entries[] = {
{ &vop_default_desc, vn_default_error },
{ &vop_parsepath_desc, unionfs_parsepath }, /* parsepath */
{ &vop_lookup_desc, unionfs_lookup }, /* lookup */
{ &vop_create_desc, unionfs_create }, /* create */
{ &vop_whiteout_desc, unionfs_whiteout }, /* whiteout */
{ &vop_mknod_desc, unionfs_mknod }, /* mknod */
{ &vop_open_desc, unionfs_open }, /* open */
{ &vop_close_desc, unionfs_close }, /* close */
{ &vop_access_desc, unionfs_access }, /* access */
{ &vop_accessx_desc, genfs_accessx }, /* accessx */
{ &vop_getattr_desc, unionfs_getattr }, /* getattr */
{ &vop_setattr_desc, unionfs_setattr }, /* setattr */
{ &vop_read_desc, unionfs_read }, /* read */
{ &vop_write_desc, unionfs_write }, /* write */
{ &vop_fallocate_desc, genfs_eopnotsupp }, /* fallocate */
{ &vop_fdiscard_desc, genfs_eopnotsupp }, /* fdiscard */
{ &vop_ioctl_desc, unionfs_ioctl }, /* ioctl */
{ &vop_poll_desc, unionfs_poll }, /* select */
{ &vop_revoke_desc, unionfs_revoke }, /* revoke */
{ &vop_mmap_desc, unionfs_mmap }, /* mmap */
{ &vop_fsync_desc, unionfs_fsync }, /* fsync */
{ &vop_seek_desc, unionfs_seek }, /* seek */
{ &vop_remove_desc, unionfs_remove }, /* remove */
{ &vop_link_desc, unionfs_link }, /* link */
{ &vop_rename_desc, unionfs_rename }, /* rename */
{ &vop_mkdir_desc, unionfs_mkdir }, /* mkdir */
{ &vop_rmdir_desc, unionfs_rmdir }, /* rmdir */
{ &vop_symlink_desc, unionfs_symlink }, /* symlink */
{ &vop_readdir_desc, unionfs_readdir }, /* readdir */
{ &vop_readlink_desc, unionfs_readlink }, /* readlink */
{ &vop_abortop_desc, unionfs_abortop }, /* abortop */
{ &vop_inactive_desc, unionfs_inactive }, /* inactive */
{ &vop_reclaim_desc, unionfs_reclaim }, /* reclaim */
{ &vop_lock_desc, unionfs_lock }, /* lock */
{ &vop_unlock_desc, unionfs_unlock }, /* unlock */
{ &vop_bmap_desc, unionfs_bmap }, /* bmap */
{ &vop_strategy_desc, unionfs_strategy }, /* strategy */
{ &vop_print_desc, unionfs_print }, /* print */
{ &vop_islocked_desc, unionfs_islocked }, /* islocked */
{ &vop_pathconf_desc, unionfs_pathconf }, /* pathconf */
{ &vop_advlock_desc, unionfs_advlock }, /* advlock */
{ &vop_getpages_desc, unionfs_getpages }, /* getpages */
{ &vop_putpages_desc, unionfs_putpages }, /* putpages */
{ &vop_kqfilter_desc, unionfs_kqfilter }, /* kqfilter */
#ifdef notdef
{ &vop_bwrite_desc, unionfs_bwrite }, /* bwrite */
#endif
{ NULL, NULL }
};
const struct vnodeopv_desc unionfs_vnodeop_opv_desc =
{ &unionfs_vnodeop_p, unionfs_vnodeop_entries };
|
9e35fc6032ec60db075319031345bc1a8488637b
|
65089dbc386e1184983c15fe3a2282763ae65960
|
/gear-lib/librpc/socket.c
|
084353e1a501bbd03ee5bdd33691dc211ab3d0ec
|
[
"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
| 7,402
|
c
|
socket.c
|
/******************************************************************************
* Copyright (C) 2014-2020 Zhifeng Gong <gozfree@163.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 "librpc.h"
#include <libgevent.h>
#include <libthread.h>
#include <libsock.h>
#include <libposix.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#define MAX_UUID_LEN (21)
struct socket_ctx {
/* fd:
* server: only for bind and listen, and triggerd when new connect coming
* client: only for connection, and trigger when server response
*/
int fd;
struct hash *hash_fd2conn;
struct sock_connection *connect;
};
static struct sock_connection *find_connection(struct socket_ctx *c, int fd)
{
return hash_get32(c->hash_fd2conn, fd);
}
static void on_error(int fd, void *arg)
{
printf("error: %d\n", errno);
}
static uint32_t create_uuid(int fd, uint32_t ip, uint16_t port)
{
char uuid[MAX_UUID_LEN];
snprintf(uuid, MAX_UUID_LEN, "%08x%08x%04x", fd, ip, port);
return hash_gen32(uuid, sizeof(uuid));
}
static void on_recv(int fd, void *arg)
{
struct rpcs *s = (struct rpcs *)arg;
struct rpc_session *session = hash_get32(s->hash_fd2session, fd);
session->base.fd = fd;
s->on_message(s, session);
}
static void on_xxx(int fd, void *arg)
{
//printf("on_xxx fd=%d\n", fd);
}
static void on_connect_of_server(int fd, void *arg)
{
struct rpc_base *r = (struct rpc_base *)arg;
struct socket_ctx *c = (struct socket_ctx *)r->ctx;
struct rpcs *s = container_of(r, struct rpcs, base);
struct rpc_session *session;
struct sock_connection *conn;
struct gevent *e;
uint32_t uuid;
char ip_str[SOCK_ADDR_LEN];
c->connect = sock_accept_connect(fd);
if (!c->connect) {
printf("sock_accept failed: %d\n", errno);
return;
}
conn = hash_get32(c->hash_fd2conn, c->connect->fd);
if (conn) {
printf("connection of fd=%d seems already exist!\n", c->connect->fd);
return;
}
hash_set32(c->hash_fd2conn, c->connect->fd, c->connect);
e = gevent_create(c->connect->fd, on_recv, on_xxx, on_error, s);
if (-1 == gevent_add(s->base.evbase, &e)) {
printf("event_add failed!\n");
}
da_push_back(r->ev_list, &e);
sock_addr_ntop(ip_str, c->connect->remote.ip);
uuid = create_uuid(fd, c->connect->remote.ip, c->connect->remote.port);
session = s->on_create_session(s, c->connect->fd, uuid);
if (!session) {
printf("create rpc session failed!\n");
}
hash_set32(s->hash_fd2session, c->connect->fd, session);
printf("new connect: %s:%d fd=%d, uuid:0x%08x\n", ip_str, c->connect->remote.port, c->connect->fd, uuid);
}
static int socket_init_server(struct rpc_base *r, const char *host, uint16_t port)
{
struct gevent *e = NULL;
struct socket_ctx *c = calloc(1, sizeof(struct socket_ctx));
if (!c) {
printf("malloc failed!\n");
goto failed;
}
c->hash_fd2conn = hash_create(1024);
c->fd = sock_tcp_bind_listen(NULL, port);
if (c->fd == -1) {
printf("sock_tcp_bind_listen port:%d failed!\n", port);
goto failed;
}
r->fd = c->fd;
r->ctx = c;
e = gevent_create(r->fd, on_connect_of_server, on_xxx, on_error, r);
if (-1 == gevent_add(r->evbase, &e)) {
printf("event_add failed!\n");
goto failed;
}
da_push_back(r->ev_list, &e);
return 0;
failed:
if (-1 != c->fd) {
close(c->fd);
}
free(c);
return -1;
}
static void on_connect_of_client(int fd, void *arg)
{
struct rpc_base *r = (struct rpc_base *)arg;
struct rpc_session *ss = container_of(r, struct rpc_session, base);
struct rpc *rpc = container_of(ss, struct rpc, session);
rpc->on_connect_server(rpc);
}
static int socket_init_client(struct rpc_base *r, const char *host, uint16_t port)
{
struct gevent *e = NULL;
struct socket_ctx *c = calloc(1, sizeof(struct socket_ctx));
if (!c) {
printf("malloc failed!\n");
goto failed;
}
c->hash_fd2conn = hash_create(1024);
c->connect = sock_tcp_connect(host, port);
if (!c->connect) {
printf("connect %s:%d failed!\n", host, port);
goto failed;
}
c->fd = c->connect->fd;
hash_set32(c->hash_fd2conn, c->connect->fd, c->connect);
if (-1 == sock_set_block(c->fd)) {
printf("sock_set_block failed!\n");
}
r->fd = c->fd;
r->ctx = c;
e = gevent_create(r->fd, on_connect_of_client, on_xxx, on_error, r);
if (-1 == gevent_add(r->evbase, &e)) {
printf("event_add failed!\n");
goto failed;
}
thread_lock(r->dispatch_thread);
if (thread_wait(r->dispatch_thread, 2000) == -1) {
printf("%s wait response failed %d:%s\n", __func__, errno, strerror(errno));
}
thread_unlock(r->dispatch_thread);
return 0;
failed:
if (-1 != c->fd) {
close(c->fd);
}
free(c);
return -1;
}
static void socket_deinit(struct rpc_base *r)
{
struct socket_ctx *c = (struct socket_ctx *)r->ctx;
close(c->fd);
free(c);
}
static int socket_send(struct rpc_base *r, const void *buf, size_t len)
{
int ret;
struct socket_ctx *c = (struct socket_ctx *)r->ctx;
struct sock_connection *conn = find_connection(c, r->fd);
if (!conn) {
printf("find connection fd=%d failed!\n", r->fd);
return -1;
}
ret = sock_send(conn->fd, buf, len);
if (ret == -1) {
printf("send failed: %d\n", errno);
}
return ret;
}
static int socket_recv(struct rpc_base *r, void *buf, size_t len)
{
int ret;
struct socket_ctx *c = (struct socket_ctx *)r->ctx;
struct sock_connection *conn = find_connection(c, r->fd);
if (!conn) {
printf("find connection fd=%d failed!\n", r->fd);
return -1;
}
ret = sock_recv(conn->fd, buf, len);
if (ret == -1) {
printf("recv failed fd=%d, rpc_base=%p: %d\n", c->fd, r, errno);
}
return ret;
}
struct rpc_ops socket_ops = {
.init_client = socket_init_client,
.init_server = socket_init_server,
.deinit = socket_deinit,
.send = socket_send,
.recv = socket_recv,
};
|
a0747fbc870812ed79296579a3c2d73f6fdc8216
|
f1ee65fbe1ffc43c2aac45e41515f1987eb534a4
|
/src/third_party/boringssl/err_data.c
|
0243a7e73c7dca5242f295c115304ff3a90cea6f
|
[
"BSD-3-Clause"
] |
permissive
|
klzgrad/naiveproxy
|
6e0d206b6f065b9311d1e12b363109f2d35cc058
|
8ef1cecadfd4e2b5d57e7ea2fa42d05717e51c2e
|
refs/heads/master
| 2023-08-20T22:42:12.511091
| 2023-06-04T03:54:34
| 2023-08-16T23:30:19
| 119,178,893
| 5,710
| 976
|
BSD-3-Clause
| 2023-08-05T10:59:59
| 2018-01-27T16:02:33
|
C++
|
UTF-8
|
C
| false
| false
| 35,828
|
c
|
err_data.c
|
/* Copyright (c) 2015, Google Inc.
*
* 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. */
/* This file was generated by err_data_generate.go. */
#include <openssl/base.h>
#include <openssl/err.h>
#include <assert.h>
static_assert(ERR_LIB_NONE == 1, "library value changed");
static_assert(ERR_LIB_SYS == 2, "library value changed");
static_assert(ERR_LIB_BN == 3, "library value changed");
static_assert(ERR_LIB_RSA == 4, "library value changed");
static_assert(ERR_LIB_DH == 5, "library value changed");
static_assert(ERR_LIB_EVP == 6, "library value changed");
static_assert(ERR_LIB_BUF == 7, "library value changed");
static_assert(ERR_LIB_OBJ == 8, "library value changed");
static_assert(ERR_LIB_PEM == 9, "library value changed");
static_assert(ERR_LIB_DSA == 10, "library value changed");
static_assert(ERR_LIB_X509 == 11, "library value changed");
static_assert(ERR_LIB_ASN1 == 12, "library value changed");
static_assert(ERR_LIB_CONF == 13, "library value changed");
static_assert(ERR_LIB_CRYPTO == 14, "library value changed");
static_assert(ERR_LIB_EC == 15, "library value changed");
static_assert(ERR_LIB_SSL == 16, "library value changed");
static_assert(ERR_LIB_BIO == 17, "library value changed");
static_assert(ERR_LIB_PKCS7 == 18, "library value changed");
static_assert(ERR_LIB_PKCS8 == 19, "library value changed");
static_assert(ERR_LIB_X509V3 == 20, "library value changed");
static_assert(ERR_LIB_RAND == 21, "library value changed");
static_assert(ERR_LIB_ENGINE == 22, "library value changed");
static_assert(ERR_LIB_OCSP == 23, "library value changed");
static_assert(ERR_LIB_UI == 24, "library value changed");
static_assert(ERR_LIB_COMP == 25, "library value changed");
static_assert(ERR_LIB_ECDSA == 26, "library value changed");
static_assert(ERR_LIB_ECDH == 27, "library value changed");
static_assert(ERR_LIB_HMAC == 28, "library value changed");
static_assert(ERR_LIB_DIGEST == 29, "library value changed");
static_assert(ERR_LIB_CIPHER == 30, "library value changed");
static_assert(ERR_LIB_HKDF == 31, "library value changed");
static_assert(ERR_LIB_TRUST_TOKEN == 32, "library value changed");
static_assert(ERR_LIB_USER == 33, "library value changed");
static_assert(ERR_NUM_LIBS == 34, "number of libraries changed");
const uint32_t kOpenSSLReasonValues[] = {
0xc320885,
0xc32889f,
0xc3308ae,
0xc3388be,
0xc3408cd,
0xc3488e6,
0xc3508f2,
0xc35890f,
0xc36092f,
0xc36893d,
0xc37094d,
0xc37895a,
0xc38096a,
0xc388975,
0xc39098b,
0xc39899a,
0xc3a09ae,
0xc3a8892,
0xc3b00f7,
0xc3b8921,
0x10320892,
0x10329641,
0x1033164d,
0x10339666,
0x10341679,
0x10348f93,
0x10350ccc,
0x1035968c,
0x103616b6,
0x103696c9,
0x103716e8,
0x10379701,
0x10381716,
0x10389734,
0x10391743,
0x1039975f,
0x103a177a,
0x103a9789,
0x103b17a5,
0x103b97c0,
0x103c17e6,
0x103c80f7,
0x103d17f7,
0x103d980b,
0x103e182a,
0x103e9839,
0x103f1850,
0x103f9863,
0x10400c90,
0x10409876,
0x10411894,
0x104198a7,
0x104218c1,
0x104298d1,
0x104318e5,
0x104398fb,
0x10441913,
0x10449928,
0x1045193c,
0x1045994e,
0x10460635,
0x1046899a,
0x10471963,
0x1047997a,
0x1048198f,
0x1048999d,
0x10490edf,
0x104997d7,
0x104a16a1,
0x14320c73,
0x14328c81,
0x14330c90,
0x14338ca2,
0x143400b9,
0x143480f7,
0x18320090,
0x18328fe9,
0x183300b9,
0x18338fff,
0x18341013,
0x183480f7,
0x18351032,
0x1835904a,
0x1836105f,
0x18369073,
0x183710ab,
0x183790c1,
0x183810d5,
0x183890e5,
0x18390ac0,
0x183990f5,
0x183a111b,
0x183a9141,
0x183b0ceb,
0x183b9190,
0x183c11a2,
0x183c91ad,
0x183d11bd,
0x183d91ce,
0x183e11df,
0x183e91f1,
0x183f121a,
0x183f9233,
0x1840124b,
0x1840870d,
0x18411164,
0x1841912f,
0x1842114e,
0x18428cd8,
0x1843110a,
0x18439176,
0x18441028,
0x18449097,
0x20321285,
0x20329272,
0x24321291,
0x243289e0,
0x243312a3,
0x243392b0,
0x243412bd,
0x243492cf,
0x243512de,
0x243592fb,
0x24361308,
0x24369316,
0x24371324,
0x24379332,
0x2438133b,
0x24389348,
0x2439135b,
0x28320cc0,
0x28328ceb,
0x28330c90,
0x28338cfe,
0x28340ccc,
0x283480b9,
0x283500f7,
0x28358cd8,
0x2836099a,
0x2c3232e0,
0x2c329372,
0x2c3332ee,
0x2c33b300,
0x2c343314,
0x2c34b326,
0x2c353341,
0x2c35b353,
0x2c363383,
0x2c36833a,
0x2c373390,
0x2c37b3bc,
0x2c3833fa,
0x2c38b411,
0x2c39342f,
0x2c39b43f,
0x2c3a3451,
0x2c3ab465,
0x2c3b3476,
0x2c3bb495,
0x2c3c1384,
0x2c3c939a,
0x2c3d34da,
0x2c3d93b3,
0x2c3e3504,
0x2c3eb512,
0x2c3f352a,
0x2c3fb542,
0x2c40356c,
0x2c409285,
0x2c41357d,
0x2c41b590,
0x2c42124b,
0x2c42b5a1,
0x2c43076d,
0x2c43b487,
0x2c4433cf,
0x2c44b54f,
0x2c453366,
0x2c45b3a2,
0x2c46341f,
0x2c46b4a9,
0x2c4734be,
0x2c47b4f7,
0x2c4833e1,
0x30320000,
0x30328015,
0x3033001f,
0x30338038,
0x30340057,
0x30348071,
0x30350078,
0x30358090,
0x303600a1,
0x303680b9,
0x303700c6,
0x303780d5,
0x303800f7,
0x30388104,
0x30390117,
0x30398132,
0x303a0147,
0x303a815b,
0x303b016f,
0x303b8180,
0x303c0199,
0x303c81b6,
0x303d01c4,
0x303d81d8,
0x303e01e8,
0x303e8201,
0x303f0211,
0x303f8224,
0x30400233,
0x3040823f,
0x30410254,
0x30418264,
0x3042027b,
0x30428288,
0x3043029b,
0x304382aa,
0x304402bf,
0x304482e0,
0x304502f3,
0x30458306,
0x3046031f,
0x3046833a,
0x30470372,
0x30478384,
0x304803a2,
0x304883b3,
0x304903c2,
0x304983da,
0x304a03ec,
0x304a8400,
0x304b0418,
0x304b842b,
0x304c0436,
0x304c8447,
0x304d0453,
0x304d8469,
0x304e0477,
0x304e848d,
0x304f049f,
0x304f84b1,
0x305004d4,
0x305084e7,
0x305104f8,
0x30518508,
0x30520520,
0x30528535,
0x3053054d,
0x30538561,
0x30540579,
0x30548592,
0x305505ab,
0x305585c8,
0x305605d3,
0x305685eb,
0x305705fb,
0x3057860c,
0x3058061f,
0x30588635,
0x3059063e,
0x30598653,
0x305a0666,
0x305a8675,
0x305b0695,
0x305b86a4,
0x305c06c5,
0x305c86e1,
0x305d06ed,
0x305d870d,
0x305e0729,
0x305e874d,
0x305f0763,
0x305f876d,
0x306004c4,
0x3060804a,
0x30610357,
0x3061873a,
0x30620392,
0x34320bb0,
0x34328bc4,
0x34330be1,
0x34338bf4,
0x34340c03,
0x34348c5d,
0x34350c41,
0x34358c20,
0x3c320090,
0x3c328d28,
0x3c330d41,
0x3c338d5c,
0x3c340d79,
0x3c348da3,
0x3c350dbe,
0x3c358de4,
0x3c360dfd,
0x3c368e15,
0x3c370e26,
0x3c378e34,
0x3c380e41,
0x3c388e55,
0x3c390ceb,
0x3c398e78,
0x3c3a0e8c,
0x3c3a895a,
0x3c3b0e9c,
0x3c3b8eb7,
0x3c3c0ec9,
0x3c3c8efc,
0x3c3d0f06,
0x3c3d8f1a,
0x3c3e0f28,
0x3c3e8f4d,
0x3c3f0d14,
0x3c3f8f36,
0x3c4000b9,
0x3c4080f7,
0x3c410d94,
0x3c418dd3,
0x3c420edf,
0x3c428e69,
0x40321a2f,
0x40329a45,
0x40331a73,
0x40339a7d,
0x40341a94,
0x40349ab2,
0x40351ac2,
0x40359ad4,
0x40361ae1,
0x40369aed,
0x40371b02,
0x40379b14,
0x40381b1f,
0x40389b31,
0x40390f93,
0x40399b41,
0x403a1b54,
0x403a9b75,
0x403b1b86,
0x403b9b96,
0x403c0071,
0x403c8090,
0x403d1bf7,
0x403d9c0d,
0x403e1c1c,
0x403e9c54,
0x403f1c6e,
0x403f9c96,
0x40401cab,
0x40409cbf,
0x40411cfa,
0x40419d15,
0x40421d2e,
0x40429d41,
0x40431d55,
0x40439d83,
0x40441d9a,
0x404480b9,
0x40451daf,
0x40459dc1,
0x40461de5,
0x40469e05,
0x40471e13,
0x40479e3a,
0x40481eab,
0x40489f65,
0x40491f7c,
0x40499f96,
0x404a1fad,
0x404a9fcb,
0x404b1fe3,
0x404ba010,
0x404c2026,
0x404ca038,
0x404d2059,
0x404da092,
0x404e20a6,
0x404ea0b3,
0x404f214d,
0x404fa1c3,
0x40502232,
0x4050a246,
0x40512279,
0x40522289,
0x4052a2ad,
0x405322c5,
0x4053a2d8,
0x405422ed,
0x4054a310,
0x4055233b,
0x4055a378,
0x4056239d,
0x4056a3b6,
0x405723ce,
0x4057a3e1,
0x405823f6,
0x4058a41d,
0x4059244c,
0x4059a479,
0x405a248d,
0x405aa49d,
0x405b24b5,
0x405ba4c6,
0x405c24d9,
0x405ca518,
0x405d2525,
0x405da54a,
0x405e2588,
0x405e8afe,
0x405f25a9,
0x405fa5b6,
0x406025c4,
0x4060a5e6,
0x40612647,
0x4061a67f,
0x40622696,
0x4062a6a7,
0x406326f4,
0x4063a709,
0x40642720,
0x4064a74c,
0x40652767,
0x4065a77e,
0x40662796,
0x4066a7c0,
0x406727eb,
0x4067a830,
0x40682878,
0x4068a899,
0x406928cb,
0x4069a8f9,
0x406a291a,
0x406aa93a,
0x406b2ac2,
0x406baae5,
0x406c2afb,
0x406cae05,
0x406d2e34,
0x406dae5c,
0x406e2e8a,
0x406eaed7,
0x406f2f30,
0x406faf68,
0x40702f7b,
0x4070af98,
0x4071084d,
0x4071afaa,
0x40722fbd,
0x4072aff3,
0x4073300b,
0x4073959c,
0x4074301f,
0x4074b039,
0x4075304a,
0x4075b05e,
0x4076306c,
0x40769348,
0x40773091,
0x4077b0d1,
0x407830ec,
0x4078b125,
0x4079313c,
0x4079b152,
0x407a317e,
0x407ab191,
0x407b31a6,
0x407bb1b8,
0x407c31e9,
0x407cb1f2,
0x407d28b4,
0x407da1eb,
0x407e3101,
0x407ea42d,
0x407f1e27,
0x407f9ffa,
0x4080215d,
0x40809e4f,
0x4081229b,
0x4081a101,
0x40822e75,
0x40829ba2,
0x40832408,
0x4083a731,
0x40841e63,
0x4084a465,
0x408524ea,
0x4085a60e,
0x4086256a,
0x4086a205,
0x40872ebb,
0x4087a65c,
0x40881be0,
0x4088a843,
0x40891c2f,
0x40899bbc,
0x408a2b33,
0x408a99b4,
0x408b31cd,
0x408baf45,
0x408c24fa,
0x408c99ec,
0x408d1f4b,
0x408d9e95,
0x408e207b,
0x408ea358,
0x408f2857,
0x408fa62a,
0x4090280c,
0x4090a53c,
0x40912b1b,
0x40919a12,
0x40921c7c,
0x4092aef6,
0x40932fd6,
0x4093a216,
0x40941e77,
0x4094ab4c,
0x409526b8,
0x4095b15e,
0x40962ea2,
0x4096a176,
0x40972261,
0x4097a0ca,
0x40981cdc,
0x4098a6cc,
0x40992f12,
0x4099a385,
0x409a231e,
0x409a99d0,
0x409b1ed1,
0x409b9efc,
0x409c30b3,
0x409c9f24,
0x409d2132,
0x409da117,
0x409e1d6d,
0x409ea1ab,
0x409f2193,
0x409f9ec4,
0x40a021d3,
0x40a0a0e4,
0x41f429ed,
0x41f92a7f,
0x41fe2972,
0x41feac28,
0x41ff2d56,
0x42032a06,
0x42082a28,
0x4208aa64,
0x42092956,
0x4209aa9e,
0x420a29ad,
0x420aa98d,
0x420b29cd,
0x420baa46,
0x420c2d72,
0x420cab5c,
0x420d2c0f,
0x420dac46,
0x42122c79,
0x42172d39,
0x4217acbb,
0x421c2cdd,
0x421f2c98,
0x42212dea,
0x42262d1c,
0x422b2dc8,
0x422babea,
0x422c2daa,
0x422cab9d,
0x422d2b76,
0x422dad89,
0x422e2bc9,
0x42302cf8,
0x4230ac60,
0x44320778,
0x44328787,
0x44330793,
0x443387a1,
0x443407b4,
0x443487c5,
0x443507cc,
0x443587d6,
0x443607e9,
0x443687ff,
0x44370811,
0x4437881e,
0x4438082d,
0x44388835,
0x4439084d,
0x4439885b,
0x443a086e,
0x48321372,
0x48329384,
0x4833139a,
0x483393b3,
0x4c3213f0,
0x4c329400,
0x4c331413,
0x4c339433,
0x4c3400b9,
0x4c3480f7,
0x4c35143f,
0x4c35944d,
0x4c361469,
0x4c36948f,
0x4c37149e,
0x4c3794ac,
0x4c3814c1,
0x4c3894cd,
0x4c3914ed,
0x4c399517,
0x4c3a1530,
0x4c3a9549,
0x4c3b0635,
0x4c3b9562,
0x4c3c1574,
0x4c3c9583,
0x4c3d159c,
0x4c3d8cb3,
0x4c3e1609,
0x4c3e95ab,
0x4c3f162b,
0x4c3f9348,
0x4c4015c1,
0x4c4093dc,
0x4c4115f9,
0x4c41947c,
0x4c4215e5,
0x4c4293c4,
0x503235b3,
0x5032b5c2,
0x503335cd,
0x5033b5dd,
0x503435f6,
0x5034b610,
0x5035361e,
0x5035b634,
0x50363646,
0x5036b65c,
0x50373675,
0x5037b688,
0x503836a0,
0x5038b6b1,
0x503936c6,
0x5039b6da,
0x503a36fa,
0x503ab710,
0x503b3728,
0x503bb73a,
0x503c3756,
0x503cb76d,
0x503d3786,
0x503db79c,
0x503e37a9,
0x503eb7bf,
0x503f37d1,
0x503f83b3,
0x504037e4,
0x5040b7f4,
0x5041380e,
0x5041b81d,
0x50423837,
0x5042b854,
0x50433864,
0x5043b874,
0x50443891,
0x50448469,
0x504538a5,
0x5045b8c3,
0x504638d6,
0x5046b8ec,
0x504738fe,
0x5047b913,
0x50483939,
0x5048b947,
0x5049395a,
0x5049b96f,
0x504a3985,
0x504ab995,
0x504b39b5,
0x504bb9c8,
0x504c39eb,
0x504cba19,
0x504d3a46,
0x504dba63,
0x504e3a7e,
0x504eba9a,
0x504f3aac,
0x504fbac3,
0x50503ad2,
0x50508729,
0x50513ae5,
0x5051b883,
0x50523a2b,
0x58320fd1,
0x68320f93,
0x68328ceb,
0x68330cfe,
0x68338fa1,
0x68340fb1,
0x683480f7,
0x6835099a,
0x6c320f59,
0x6c328ca2,
0x6c330f64,
0x6c338f7d,
0x74320a66,
0x743280b9,
0x74330cb3,
0x783209cb,
0x783289e0,
0x783309ec,
0x78338090,
0x783409fb,
0x78348a10,
0x78350a2f,
0x78358a51,
0x78360a66,
0x78368a7c,
0x78370a8c,
0x78378aad,
0x78380ac0,
0x78388ad2,
0x78390adf,
0x78398afe,
0x783a0b13,
0x783a8b21,
0x783b0b2b,
0x783b8b3f,
0x783c0b56,
0x783c8b6b,
0x783d0b82,
0x783d8b97,
0x783e0aed,
0x783e8a9f,
0x7c321261,
0x8032148f,
0x80328090,
0x803332af,
0x803380b9,
0x803432be,
0x8034b226,
0x80353244,
0x8035b2d2,
0x80363286,
0x8036b235,
0x80373278,
0x8037b213,
0x80383299,
0x8038b255,
0x8039326a,
};
const size_t kOpenSSLReasonValuesLen = sizeof(kOpenSSLReasonValues) / sizeof(kOpenSSLReasonValues[0]);
const char kOpenSSLReasonStringData[] =
"ASN1_LENGTH_MISMATCH\0"
"AUX_ERROR\0"
"BAD_GET_ASN1_OBJECT_CALL\0"
"BAD_OBJECT_HEADER\0"
"BAD_TEMPLATE\0"
"BMPSTRING_IS_WRONG_LENGTH\0"
"BN_LIB\0"
"BOOLEAN_IS_WRONG_LENGTH\0"
"BUFFER_TOO_SMALL\0"
"CONTEXT_NOT_INITIALISED\0"
"DECODE_ERROR\0"
"DEPTH_EXCEEDED\0"
"DIGEST_AND_KEY_TYPE_NOT_SUPPORTED\0"
"ENCODE_ERROR\0"
"ERROR_GETTING_TIME\0"
"EXPECTING_AN_ASN1_SEQUENCE\0"
"EXPECTING_AN_INTEGER\0"
"EXPECTING_AN_OBJECT\0"
"EXPECTING_A_BOOLEAN\0"
"EXPECTING_A_TIME\0"
"EXPLICIT_LENGTH_MISMATCH\0"
"EXPLICIT_TAG_NOT_CONSTRUCTED\0"
"FIELD_MISSING\0"
"FIRST_NUM_TOO_LARGE\0"
"HEADER_TOO_LONG\0"
"ILLEGAL_BITSTRING_FORMAT\0"
"ILLEGAL_BOOLEAN\0"
"ILLEGAL_CHARACTERS\0"
"ILLEGAL_FORMAT\0"
"ILLEGAL_HEX\0"
"ILLEGAL_IMPLICIT_TAG\0"
"ILLEGAL_INTEGER\0"
"ILLEGAL_NESTED_TAGGING\0"
"ILLEGAL_NULL\0"
"ILLEGAL_NULL_VALUE\0"
"ILLEGAL_OBJECT\0"
"ILLEGAL_OPTIONAL_ANY\0"
"ILLEGAL_OPTIONS_ON_ITEM_TEMPLATE\0"
"ILLEGAL_TAGGED_ANY\0"
"ILLEGAL_TIME_VALUE\0"
"INTEGER_NOT_ASCII_FORMAT\0"
"INTEGER_TOO_LARGE_FOR_LONG\0"
"INVALID_BIT_STRING_BITS_LEFT\0"
"INVALID_BIT_STRING_PADDING\0"
"INVALID_BMPSTRING\0"
"INVALID_DIGIT\0"
"INVALID_INTEGER\0"
"INVALID_MODIFIER\0"
"INVALID_NUMBER\0"
"INVALID_OBJECT_ENCODING\0"
"INVALID_SEPARATOR\0"
"INVALID_TIME_FORMAT\0"
"INVALID_UNIVERSALSTRING\0"
"INVALID_UTF8STRING\0"
"LIST_ERROR\0"
"MISSING_ASN1_EOS\0"
"MISSING_EOC\0"
"MISSING_SECOND_NUMBER\0"
"MISSING_VALUE\0"
"MSTRING_NOT_UNIVERSAL\0"
"MSTRING_WRONG_TAG\0"
"NESTED_ASN1_ERROR\0"
"NESTED_ASN1_STRING\0"
"NESTED_TOO_DEEP\0"
"NON_HEX_CHARACTERS\0"
"NOT_ASCII_FORMAT\0"
"NOT_ENOUGH_DATA\0"
"NO_MATCHING_CHOICE_TYPE\0"
"NULL_IS_WRONG_LENGTH\0"
"OBJECT_NOT_ASCII_FORMAT\0"
"ODD_NUMBER_OF_CHARS\0"
"SECOND_NUMBER_TOO_LARGE\0"
"SEQUENCE_LENGTH_MISMATCH\0"
"SEQUENCE_NOT_CONSTRUCTED\0"
"SEQUENCE_OR_SET_NEEDS_CONFIG\0"
"SHORT_LINE\0"
"STREAMING_NOT_SUPPORTED\0"
"STRING_TOO_LONG\0"
"STRING_TOO_SHORT\0"
"TAG_VALUE_TOO_HIGH\0"
"TIME_NOT_ASCII_FORMAT\0"
"TOO_LONG\0"
"TYPE_NOT_CONSTRUCTED\0"
"TYPE_NOT_PRIMITIVE\0"
"UNEXPECTED_EOC\0"
"UNIVERSALSTRING_IS_WRONG_LENGTH\0"
"UNKNOWN_FORMAT\0"
"UNKNOWN_MESSAGE_DIGEST_ALGORITHM\0"
"UNKNOWN_SIGNATURE_ALGORITHM\0"
"UNKNOWN_TAG\0"
"UNSUPPORTED_ANY_DEFINED_BY_TYPE\0"
"UNSUPPORTED_PUBLIC_KEY_TYPE\0"
"UNSUPPORTED_TYPE\0"
"WRONG_INTEGER_TYPE\0"
"WRONG_PUBLIC_KEY_TYPE\0"
"WRONG_TAG\0"
"WRONG_TYPE\0"
"BAD_FOPEN_MODE\0"
"BROKEN_PIPE\0"
"CONNECT_ERROR\0"
"ERROR_SETTING_NBIO\0"
"INVALID_ARGUMENT\0"
"IN_USE\0"
"KEEPALIVE\0"
"NBIO_CONNECT_ERROR\0"
"NO_HOSTNAME_SPECIFIED\0"
"NO_PORT_SPECIFIED\0"
"NO_SUCH_FILE\0"
"NULL_PARAMETER\0"
"SYS_LIB\0"
"UNABLE_TO_CREATE_SOCKET\0"
"UNINITIALIZED\0"
"UNSUPPORTED_METHOD\0"
"WRITE_TO_READ_ONLY_BIO\0"
"ARG2_LT_ARG3\0"
"BAD_ENCODING\0"
"BAD_RECIPROCAL\0"
"BIGNUM_TOO_LONG\0"
"BITS_TOO_SMALL\0"
"CALLED_WITH_EVEN_MODULUS\0"
"DIV_BY_ZERO\0"
"EXPAND_ON_STATIC_BIGNUM_DATA\0"
"INPUT_NOT_REDUCED\0"
"INVALID_INPUT\0"
"INVALID_RANGE\0"
"NEGATIVE_NUMBER\0"
"NOT_A_SQUARE\0"
"NOT_INITIALIZED\0"
"NO_INVERSE\0"
"PRIVATE_KEY_TOO_LARGE\0"
"P_IS_NOT_PRIME\0"
"TOO_MANY_ITERATIONS\0"
"TOO_MANY_TEMPORARY_VARIABLES\0"
"AES_KEY_SETUP_FAILED\0"
"BAD_DECRYPT\0"
"BAD_KEY_LENGTH\0"
"CTRL_NOT_IMPLEMENTED\0"
"CTRL_OPERATION_NOT_IMPLEMENTED\0"
"DATA_NOT_MULTIPLE_OF_BLOCK_LENGTH\0"
"INITIALIZATION_ERROR\0"
"INPUT_NOT_INITIALIZED\0"
"INVALID_AD_SIZE\0"
"INVALID_KEY_LENGTH\0"
"INVALID_NONCE\0"
"INVALID_NONCE_SIZE\0"
"INVALID_OPERATION\0"
"IV_TOO_LARGE\0"
"NO_CIPHER_SET\0"
"NO_DIRECTION_SET\0"
"OUTPUT_ALIASES_INPUT\0"
"TAG_TOO_LARGE\0"
"TOO_LARGE\0"
"UNSUPPORTED_AD_SIZE\0"
"UNSUPPORTED_INPUT_SIZE\0"
"UNSUPPORTED_KEY_SIZE\0"
"UNSUPPORTED_NONCE_SIZE\0"
"UNSUPPORTED_TAG_SIZE\0"
"WRONG_FINAL_BLOCK_LENGTH\0"
"LIST_CANNOT_BE_NULL\0"
"MISSING_CLOSE_SQUARE_BRACKET\0"
"MISSING_EQUAL_SIGN\0"
"NO_CLOSE_BRACE\0"
"UNABLE_TO_CREATE_NEW_SECTION\0"
"VARIABLE_EXPANSION_NOT_SUPPORTED\0"
"VARIABLE_EXPANSION_TOO_LONG\0"
"VARIABLE_HAS_NO_VALUE\0"
"BAD_GENERATOR\0"
"INVALID_PUBKEY\0"
"MODULUS_TOO_LARGE\0"
"NO_PRIVATE_VALUE\0"
"UNKNOWN_HASH\0"
"BAD_Q_VALUE\0"
"BAD_VERSION\0"
"INVALID_PARAMETERS\0"
"MISSING_PARAMETERS\0"
"NEED_NEW_SETUP_VALUES\0"
"BIGNUM_OUT_OF_RANGE\0"
"COORDINATES_OUT_OF_RANGE\0"
"D2I_ECPKPARAMETERS_FAILURE\0"
"EC_GROUP_NEW_BY_NAME_FAILURE\0"
"GROUP2PKPARAMETERS_FAILURE\0"
"GROUP_MISMATCH\0"
"I2D_ECPKPARAMETERS_FAILURE\0"
"INCOMPATIBLE_OBJECTS\0"
"INVALID_COFACTOR\0"
"INVALID_COMPRESSED_POINT\0"
"INVALID_COMPRESSION_BIT\0"
"INVALID_ENCODING\0"
"INVALID_FIELD\0"
"INVALID_FORM\0"
"INVALID_GROUP_ORDER\0"
"INVALID_PRIVATE_KEY\0"
"INVALID_SCALAR\0"
"MISSING_PRIVATE_KEY\0"
"NON_NAMED_CURVE\0"
"PKPARAMETERS2GROUP_FAILURE\0"
"POINT_AT_INFINITY\0"
"POINT_IS_NOT_ON_CURVE\0"
"PUBLIC_KEY_VALIDATION_FAILED\0"
"SLOT_FULL\0"
"UNDEFINED_GENERATOR\0"
"UNKNOWN_GROUP\0"
"UNKNOWN_ORDER\0"
"WRONG_CURVE_PARAMETERS\0"
"WRONG_ORDER\0"
"KDF_FAILED\0"
"POINT_ARITHMETIC_FAILURE\0"
"UNKNOWN_DIGEST_LENGTH\0"
"BAD_SIGNATURE\0"
"NOT_IMPLEMENTED\0"
"RANDOM_NUMBER_GENERATION_FAILED\0"
"OPERATION_NOT_SUPPORTED\0"
"COMMAND_NOT_SUPPORTED\0"
"DIFFERENT_KEY_TYPES\0"
"DIFFERENT_PARAMETERS\0"
"EMPTY_PSK\0"
"EXPECTING_AN_EC_KEY_KEY\0"
"EXPECTING_AN_RSA_KEY\0"
"EXPECTING_A_DSA_KEY\0"
"ILLEGAL_OR_UNSUPPORTED_PADDING_MODE\0"
"INVALID_BUFFER_SIZE\0"
"INVALID_DIGEST_LENGTH\0"
"INVALID_DIGEST_TYPE\0"
"INVALID_KEYBITS\0"
"INVALID_MGF1_MD\0"
"INVALID_PADDING_MODE\0"
"INVALID_PEER_KEY\0"
"INVALID_PSS_SALTLEN\0"
"INVALID_SIGNATURE\0"
"KEYS_NOT_SET\0"
"MEMORY_LIMIT_EXCEEDED\0"
"NOT_A_PRIVATE_KEY\0"
"NOT_XOF_OR_INVALID_LENGTH\0"
"NO_DEFAULT_DIGEST\0"
"NO_KEY_SET\0"
"NO_MDC2_SUPPORT\0"
"NO_NID_FOR_CURVE\0"
"NO_OPERATION_SET\0"
"NO_PARAMETERS_SET\0"
"OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE\0"
"OPERATON_NOT_INITIALIZED\0"
"UNKNOWN_PUBLIC_KEY_TYPE\0"
"UNSUPPORTED_ALGORITHM\0"
"OUTPUT_TOO_LARGE\0"
"INVALID_OID_STRING\0"
"UNKNOWN_NID\0"
"BAD_BASE64_DECODE\0"
"BAD_END_LINE\0"
"BAD_IV_CHARS\0"
"BAD_PASSWORD_READ\0"
"CIPHER_IS_NULL\0"
"ERROR_CONVERTING_PRIVATE_KEY\0"
"NOT_DEK_INFO\0"
"NOT_ENCRYPTED\0"
"NOT_PROC_TYPE\0"
"NO_START_LINE\0"
"READ_KEY\0"
"SHORT_HEADER\0"
"UNSUPPORTED_CIPHER\0"
"UNSUPPORTED_ENCRYPTION\0"
"BAD_PKCS7_VERSION\0"
"NOT_PKCS7_SIGNED_DATA\0"
"NO_CERTIFICATES_INCLUDED\0"
"NO_CRLS_INCLUDED\0"
"AMBIGUOUS_FRIENDLY_NAME\0"
"BAD_ITERATION_COUNT\0"
"BAD_PKCS12_DATA\0"
"BAD_PKCS12_VERSION\0"
"CIPHER_HAS_NO_OBJECT_IDENTIFIER\0"
"CRYPT_ERROR\0"
"ENCRYPT_ERROR\0"
"ERROR_SETTING_CIPHER_PARAMS\0"
"INCORRECT_PASSWORD\0"
"INVALID_CHARACTERS\0"
"KEYGEN_FAILURE\0"
"KEY_GEN_ERROR\0"
"METHOD_NOT_SUPPORTED\0"
"MISSING_MAC\0"
"MULTIPLE_PRIVATE_KEYS_IN_PKCS12\0"
"PKCS12_PUBLIC_KEY_INTEGRITY_NOT_SUPPORTED\0"
"PKCS12_TOO_DEEPLY_NESTED\0"
"PRIVATE_KEY_DECODE_ERROR\0"
"PRIVATE_KEY_ENCODE_ERROR\0"
"UNKNOWN_ALGORITHM\0"
"UNKNOWN_CIPHER\0"
"UNKNOWN_CIPHER_ALGORITHM\0"
"UNKNOWN_DIGEST\0"
"UNSUPPORTED_KEYLENGTH\0"
"UNSUPPORTED_KEY_DERIVATION_FUNCTION\0"
"UNSUPPORTED_OPTIONS\0"
"UNSUPPORTED_PRF\0"
"UNSUPPORTED_PRIVATE_KEY_ALGORITHM\0"
"UNSUPPORTED_SALT_TYPE\0"
"BAD_E_VALUE\0"
"BAD_FIXED_HEADER_DECRYPT\0"
"BAD_PAD_BYTE_COUNT\0"
"BAD_RSA_PARAMETERS\0"
"BLOCK_TYPE_IS_NOT_01\0"
"BLOCK_TYPE_IS_NOT_02\0"
"BN_NOT_INITIALIZED\0"
"CANNOT_RECOVER_MULTI_PRIME_KEY\0"
"CRT_PARAMS_ALREADY_GIVEN\0"
"CRT_VALUES_INCORRECT\0"
"DATA_LEN_NOT_EQUAL_TO_MOD_LEN\0"
"DATA_TOO_LARGE\0"
"DATA_TOO_LARGE_FOR_KEY_SIZE\0"
"DATA_TOO_LARGE_FOR_MODULUS\0"
"DATA_TOO_SMALL\0"
"DATA_TOO_SMALL_FOR_KEY_SIZE\0"
"DIGEST_TOO_BIG_FOR_RSA_KEY\0"
"D_E_NOT_CONGRUENT_TO_1\0"
"D_OUT_OF_RANGE\0"
"EMPTY_PUBLIC_KEY\0"
"FIRST_OCTET_INVALID\0"
"INCONSISTENT_SET_OF_CRT_VALUES\0"
"INTERNAL_ERROR\0"
"INVALID_MESSAGE_LENGTH\0"
"KEY_SIZE_TOO_SMALL\0"
"LAST_OCTET_INVALID\0"
"MUST_HAVE_AT_LEAST_TWO_PRIMES\0"
"NO_PUBLIC_EXPONENT\0"
"NULL_BEFORE_BLOCK_MISSING\0"
"N_NOT_EQUAL_P_Q\0"
"OAEP_DECODING_ERROR\0"
"ONLY_ONE_OF_P_Q_GIVEN\0"
"OUTPUT_BUFFER_TOO_SMALL\0"
"PADDING_CHECK_FAILED\0"
"PKCS_DECODING_ERROR\0"
"SLEN_CHECK_FAILED\0"
"SLEN_RECOVERY_FAILED\0"
"UNKNOWN_ALGORITHM_TYPE\0"
"UNKNOWN_PADDING_TYPE\0"
"VALUE_MISSING\0"
"WRONG_SIGNATURE_LENGTH\0"
"ALPN_MISMATCH_ON_EARLY_DATA\0"
"ALPS_MISMATCH_ON_EARLY_DATA\0"
"APPLICATION_DATA_INSTEAD_OF_HANDSHAKE\0"
"APPLICATION_DATA_ON_SHUTDOWN\0"
"APP_DATA_IN_HANDSHAKE\0"
"ATTEMPT_TO_REUSE_SESSION_IN_DIFFERENT_CONTEXT\0"
"BAD_ALERT\0"
"BAD_CHANGE_CIPHER_SPEC\0"
"BAD_DATA_RETURNED_BY_CALLBACK\0"
"BAD_DH_P_LENGTH\0"
"BAD_DIGEST_LENGTH\0"
"BAD_ECC_CERT\0"
"BAD_ECPOINT\0"
"BAD_HANDSHAKE_RECORD\0"
"BAD_HELLO_REQUEST\0"
"BAD_LENGTH\0"
"BAD_PACKET_LENGTH\0"
"BAD_RSA_ENCRYPT\0"
"BAD_SRTP_MKI_VALUE\0"
"BAD_SRTP_PROTECTION_PROFILE_LIST\0"
"BAD_SSL_FILETYPE\0"
"BAD_WRITE_RETRY\0"
"BIO_NOT_SET\0"
"BLOCK_CIPHER_PAD_IS_WRONG\0"
"CANNOT_HAVE_BOTH_PRIVKEY_AND_METHOD\0"
"CANNOT_PARSE_LEAF_CERT\0"
"CA_DN_LENGTH_MISMATCH\0"
"CA_DN_TOO_LONG\0"
"CCS_RECEIVED_EARLY\0"
"CERTIFICATE_AND_PRIVATE_KEY_MISMATCH\0"
"CERTIFICATE_VERIFY_FAILED\0"
"CERT_CB_ERROR\0"
"CERT_DECOMPRESSION_FAILED\0"
"CERT_LENGTH_MISMATCH\0"
"CHANNEL_ID_NOT_P256\0"
"CHANNEL_ID_SIGNATURE_INVALID\0"
"CIPHER_MISMATCH_ON_EARLY_DATA\0"
"CIPHER_OR_HASH_UNAVAILABLE\0"
"CLIENTHELLO_PARSE_FAILED\0"
"CLIENTHELLO_TLSEXT\0"
"CONNECTION_REJECTED\0"
"CONNECTION_TYPE_NOT_SET\0"
"COULD_NOT_PARSE_HINTS\0"
"CUSTOM_EXTENSION_ERROR\0"
"DATA_LENGTH_TOO_LONG\0"
"DECRYPTION_FAILED\0"
"DECRYPTION_FAILED_OR_BAD_RECORD_MAC\0"
"DH_PUBLIC_VALUE_LENGTH_IS_WRONG\0"
"DH_P_TOO_LONG\0"
"DIGEST_CHECK_FAILED\0"
"DOWNGRADE_DETECTED\0"
"DTLS_MESSAGE_TOO_BIG\0"
"DUPLICATE_EXTENSION\0"
"DUPLICATE_KEY_SHARE\0"
"DUPLICATE_SIGNATURE_ALGORITHM\0"
"EARLY_DATA_NOT_IN_USE\0"
"ECC_CERT_NOT_FOR_SIGNING\0"
"ECH_REJECTED\0"
"ECH_SERVER_CONFIG_AND_PRIVATE_KEY_MISMATCH\0"
"ECH_SERVER_CONFIG_UNSUPPORTED_EXTENSION\0"
"ECH_SERVER_WOULD_HAVE_NO_RETRY_CONFIGS\0"
"EMPTY_HELLO_RETRY_REQUEST\0"
"EMS_STATE_INCONSISTENT\0"
"ENCRYPTED_LENGTH_TOO_LONG\0"
"ERROR_ADDING_EXTENSION\0"
"ERROR_IN_RECEIVED_CIPHER_LIST\0"
"ERROR_PARSING_EXTENSION\0"
"EXCESSIVE_MESSAGE_SIZE\0"
"EXCESS_HANDSHAKE_DATA\0"
"EXTRA_DATA_IN_MESSAGE\0"
"FRAGMENT_MISMATCH\0"
"GOT_NEXT_PROTO_WITHOUT_EXTENSION\0"
"HANDSHAKE_FAILURE_ON_CLIENT_HELLO\0"
"HANDSHAKE_NOT_COMPLETE\0"
"HTTPS_PROXY_REQUEST\0"
"HTTP_REQUEST\0"
"INAPPROPRIATE_FALLBACK\0"
"INCONSISTENT_CLIENT_HELLO\0"
"INCONSISTENT_ECH_NEGOTIATION\0"
"INVALID_ALPN_PROTOCOL\0"
"INVALID_ALPN_PROTOCOL_LIST\0"
"INVALID_CLIENT_HELLO_INNER\0"
"INVALID_COMMAND\0"
"INVALID_COMPRESSION_LIST\0"
"INVALID_DELEGATED_CREDENTIAL\0"
"INVALID_ECH_CONFIG_LIST\0"
"INVALID_ECH_PUBLIC_NAME\0"
"INVALID_MESSAGE\0"
"INVALID_OUTER_EXTENSION\0"
"INVALID_OUTER_RECORD_TYPE\0"
"INVALID_SCT_LIST\0"
"INVALID_SIGNATURE_ALGORITHM\0"
"INVALID_SSL_SESSION\0"
"INVALID_TICKET_KEYS_LENGTH\0"
"KEY_USAGE_BIT_INCORRECT\0"
"LENGTH_MISMATCH\0"
"MISSING_EXTENSION\0"
"MISSING_KEY_SHARE\0"
"MISSING_RSA_CERTIFICATE\0"
"MISSING_TMP_DH_KEY\0"
"MISSING_TMP_ECDH_KEY\0"
"MIXED_SPECIAL_OPERATOR_WITH_GROUPS\0"
"MTU_TOO_SMALL\0"
"NEGOTIATED_ALPS_WITHOUT_ALPN\0"
"NEGOTIATED_BOTH_NPN_AND_ALPN\0"
"NEGOTIATED_TB_WITHOUT_EMS_OR_RI\0"
"NESTED_GROUP\0"
"NO_APPLICATION_PROTOCOL\0"
"NO_CERTIFICATES_RETURNED\0"
"NO_CERTIFICATE_ASSIGNED\0"
"NO_CERTIFICATE_SET\0"
"NO_CIPHERS_AVAILABLE\0"
"NO_CIPHERS_PASSED\0"
"NO_CIPHERS_SPECIFIED\0"
"NO_CIPHER_MATCH\0"
"NO_COMMON_SIGNATURE_ALGORITHMS\0"
"NO_COMPRESSION_SPECIFIED\0"
"NO_GROUPS_SPECIFIED\0"
"NO_METHOD_SPECIFIED\0"
"NO_P256_SUPPORT\0"
"NO_PRIVATE_KEY_ASSIGNED\0"
"NO_RENEGOTIATION\0"
"NO_REQUIRED_DIGEST\0"
"NO_SHARED_CIPHER\0"
"NO_SHARED_GROUP\0"
"NO_SUPPORTED_VERSIONS_ENABLED\0"
"NULL_SSL_CTX\0"
"NULL_SSL_METHOD_PASSED\0"
"OCSP_CB_ERROR\0"
"OLD_SESSION_CIPHER_NOT_RETURNED\0"
"OLD_SESSION_PRF_HASH_MISMATCH\0"
"OLD_SESSION_VERSION_NOT_RETURNED\0"
"PARSE_TLSEXT\0"
"PATH_TOO_LONG\0"
"PEER_DID_NOT_RETURN_A_CERTIFICATE\0"
"PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE\0"
"PRE_SHARED_KEY_MUST_BE_LAST\0"
"PRIVATE_KEY_OPERATION_FAILED\0"
"PROTOCOL_IS_SHUTDOWN\0"
"PSK_IDENTITY_BINDER_COUNT_MISMATCH\0"
"PSK_IDENTITY_NOT_FOUND\0"
"PSK_NO_CLIENT_CB\0"
"PSK_NO_SERVER_CB\0"
"QUIC_INTERNAL_ERROR\0"
"QUIC_TRANSPORT_PARAMETERS_MISCONFIGURED\0"
"READ_TIMEOUT_EXPIRED\0"
"RECORD_LENGTH_MISMATCH\0"
"RECORD_TOO_LARGE\0"
"RENEGOTIATION_EMS_MISMATCH\0"
"RENEGOTIATION_ENCODING_ERR\0"
"RENEGOTIATION_MISMATCH\0"
"REQUIRED_CIPHER_MISSING\0"
"RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION\0"
"RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION\0"
"SCSV_RECEIVED_WHEN_RENEGOTIATING\0"
"SECOND_SERVERHELLO_VERSION_MISMATCH\0"
"SERVERHELLO_TLSEXT\0"
"SERVER_CERT_CHANGED\0"
"SERVER_ECHOED_INVALID_SESSION_ID\0"
"SESSION_ID_CONTEXT_UNINITIALIZED\0"
"SESSION_MAY_NOT_BE_CREATED\0"
"SHUTDOWN_WHILE_IN_INIT\0"
"SIGNATURE_ALGORITHMS_EXTENSION_SENT_BY_SERVER\0"
"SRTP_COULD_NOT_ALLOCATE_PROFILES\0"
"SRTP_UNKNOWN_PROTECTION_PROFILE\0"
"SSL3_EXT_INVALID_SERVERNAME\0"
"SSLV3_ALERT_BAD_CERTIFICATE\0"
"SSLV3_ALERT_BAD_RECORD_MAC\0"
"SSLV3_ALERT_CERTIFICATE_EXPIRED\0"
"SSLV3_ALERT_CERTIFICATE_REVOKED\0"
"SSLV3_ALERT_CERTIFICATE_UNKNOWN\0"
"SSLV3_ALERT_CLOSE_NOTIFY\0"
"SSLV3_ALERT_DECOMPRESSION_FAILURE\0"
"SSLV3_ALERT_HANDSHAKE_FAILURE\0"
"SSLV3_ALERT_ILLEGAL_PARAMETER\0"
"SSLV3_ALERT_NO_CERTIFICATE\0"
"SSLV3_ALERT_UNEXPECTED_MESSAGE\0"
"SSLV3_ALERT_UNSUPPORTED_CERTIFICATE\0"
"SSL_CTX_HAS_NO_DEFAULT_SSL_VERSION\0"
"SSL_HANDSHAKE_FAILURE\0"
"SSL_SESSION_ID_CONTEXT_TOO_LONG\0"
"SSL_SESSION_ID_TOO_LONG\0"
"TICKET_ENCRYPTION_FAILED\0"
"TLS13_DOWNGRADE\0"
"TLSV1_ALERT_ACCESS_DENIED\0"
"TLSV1_ALERT_BAD_CERTIFICATE_HASH_VALUE\0"
"TLSV1_ALERT_BAD_CERTIFICATE_STATUS_RESPONSE\0"
"TLSV1_ALERT_CERTIFICATE_REQUIRED\0"
"TLSV1_ALERT_CERTIFICATE_UNOBTAINABLE\0"
"TLSV1_ALERT_DECODE_ERROR\0"
"TLSV1_ALERT_DECRYPTION_FAILED\0"
"TLSV1_ALERT_DECRYPT_ERROR\0"
"TLSV1_ALERT_ECH_REQUIRED\0"
"TLSV1_ALERT_EXPORT_RESTRICTION\0"
"TLSV1_ALERT_INAPPROPRIATE_FALLBACK\0"
"TLSV1_ALERT_INSUFFICIENT_SECURITY\0"
"TLSV1_ALERT_INTERNAL_ERROR\0"
"TLSV1_ALERT_NO_APPLICATION_PROTOCOL\0"
"TLSV1_ALERT_NO_RENEGOTIATION\0"
"TLSV1_ALERT_PROTOCOL_VERSION\0"
"TLSV1_ALERT_RECORD_OVERFLOW\0"
"TLSV1_ALERT_UNKNOWN_CA\0"
"TLSV1_ALERT_UNKNOWN_PSK_IDENTITY\0"
"TLSV1_ALERT_UNRECOGNIZED_NAME\0"
"TLSV1_ALERT_UNSUPPORTED_EXTENSION\0"
"TLSV1_ALERT_USER_CANCELLED\0"
"TLS_PEER_DID_NOT_RESPOND_WITH_CERTIFICATE_LIST\0"
"TLS_RSA_ENCRYPTED_VALUE_LENGTH_IS_WRONG\0"
"TOO_MANY_EMPTY_FRAGMENTS\0"
"TOO_MANY_KEY_UPDATES\0"
"TOO_MANY_WARNING_ALERTS\0"
"TOO_MUCH_READ_EARLY_DATA\0"
"TOO_MUCH_SKIPPED_EARLY_DATA\0"
"UNABLE_TO_FIND_ECDH_PARAMETERS\0"
"UNCOMPRESSED_CERT_TOO_LARGE\0"
"UNEXPECTED_COMPATIBILITY_MODE\0"
"UNEXPECTED_EXTENSION\0"
"UNEXPECTED_EXTENSION_ON_EARLY_DATA\0"
"UNEXPECTED_MESSAGE\0"
"UNEXPECTED_OPERATOR_IN_GROUP\0"
"UNEXPECTED_RECORD\0"
"UNKNOWN_ALERT_TYPE\0"
"UNKNOWN_CERTIFICATE_TYPE\0"
"UNKNOWN_CERT_COMPRESSION_ALG\0"
"UNKNOWN_CIPHER_RETURNED\0"
"UNKNOWN_CIPHER_TYPE\0"
"UNKNOWN_KEY_EXCHANGE_TYPE\0"
"UNKNOWN_PROTOCOL\0"
"UNKNOWN_SSL_VERSION\0"
"UNKNOWN_STATE\0"
"UNSAFE_LEGACY_RENEGOTIATION_DISABLED\0"
"UNSUPPORTED_COMPRESSION_ALGORITHM\0"
"UNSUPPORTED_ECH_SERVER_CONFIG\0"
"UNSUPPORTED_ELLIPTIC_CURVE\0"
"UNSUPPORTED_PROTOCOL\0"
"UNSUPPORTED_PROTOCOL_FOR_CUSTOM_KEY\0"
"WRONG_CERTIFICATE_TYPE\0"
"WRONG_CIPHER_RETURNED\0"
"WRONG_CURVE\0"
"WRONG_ENCRYPTION_LEVEL_RECEIVED\0"
"WRONG_MESSAGE_TYPE\0"
"WRONG_SIGNATURE_TYPE\0"
"WRONG_SSL_VERSION\0"
"WRONG_VERSION_NUMBER\0"
"WRONG_VERSION_ON_EARLY_DATA\0"
"X509_LIB\0"
"X509_VERIFICATION_SETUP_PROBLEMS\0"
"BAD_VALIDITY_CHECK\0"
"DECODE_FAILURE\0"
"INVALID_KEY_ID\0"
"INVALID_METADATA\0"
"INVALID_METADATA_KEY\0"
"INVALID_PROOF\0"
"INVALID_TOKEN\0"
"NO_KEYS_CONFIGURED\0"
"NO_SRR_KEY_CONFIGURED\0"
"OVER_BATCHSIZE\0"
"SRR_SIGNATURE_ERROR\0"
"TOO_MANY_KEYS\0"
"AKID_MISMATCH\0"
"BAD_X509_FILETYPE\0"
"BASE64_DECODE_ERROR\0"
"CANT_CHECK_DH_KEY\0"
"CERT_ALREADY_IN_HASH_TABLE\0"
"CRL_ALREADY_DELTA\0"
"CRL_VERIFY_FAILURE\0"
"DELTA_CRL_WITHOUT_CRL_NUMBER\0"
"IDP_MISMATCH\0"
"INVALID_DIRECTORY\0"
"INVALID_FIELD_FOR_VERSION\0"
"INVALID_FIELD_NAME\0"
"INVALID_PARAMETER\0"
"INVALID_POLICY_EXTENSION\0"
"INVALID_PSS_PARAMETERS\0"
"INVALID_TRUST\0"
"INVALID_VERSION\0"
"ISSUER_MISMATCH\0"
"KEY_TYPE_MISMATCH\0"
"KEY_VALUES_MISMATCH\0"
"LOADING_CERT_DIR\0"
"LOADING_DEFAULTS\0"
"NAME_TOO_LONG\0"
"NEWER_CRL_NOT_NEWER\0"
"NO_CERTIFICATE_FOUND\0"
"NO_CERTIFICATE_OR_CRL_FOUND\0"
"NO_CERT_SET_FOR_US_TO_VERIFY\0"
"NO_CRL_FOUND\0"
"NO_CRL_NUMBER\0"
"PUBLIC_KEY_DECODE_ERROR\0"
"PUBLIC_KEY_ENCODE_ERROR\0"
"SHOULD_RETRY\0"
"SIGNATURE_ALGORITHM_MISMATCH\0"
"UNKNOWN_KEY_TYPE\0"
"UNKNOWN_PURPOSE_ID\0"
"UNKNOWN_TRUST_ID\0"
"WRONG_LOOKUP_TYPE\0"
"BAD_IP_ADDRESS\0"
"BAD_OBJECT\0"
"BN_DEC2BN_ERROR\0"
"BN_TO_ASN1_INTEGER_ERROR\0"
"CANNOT_FIND_FREE_FUNCTION\0"
"DIRNAME_ERROR\0"
"DISTPOINT_ALREADY_SET\0"
"DUPLICATE_ZONE_ID\0"
"ERROR_CONVERTING_ZONE\0"
"ERROR_CREATING_EXTENSION\0"
"ERROR_IN_EXTENSION\0"
"EXPECTED_A_SECTION_NAME\0"
"EXTENSION_EXISTS\0"
"EXTENSION_NAME_ERROR\0"
"EXTENSION_NOT_FOUND\0"
"EXTENSION_SETTING_NOT_SUPPORTED\0"
"EXTENSION_VALUE_ERROR\0"
"ILLEGAL_EMPTY_EXTENSION\0"
"ILLEGAL_HEX_DIGIT\0"
"INCORRECT_POLICY_SYNTAX_TAG\0"
"INVALID_BOOLEAN_STRING\0"
"INVALID_EXTENSION_STRING\0"
"INVALID_MULTIPLE_RDNS\0"
"INVALID_NAME\0"
"INVALID_NULL_ARGUMENT\0"
"INVALID_NULL_NAME\0"
"INVALID_NULL_VALUE\0"
"INVALID_NUMBERS\0"
"INVALID_OBJECT_IDENTIFIER\0"
"INVALID_OPTION\0"
"INVALID_POLICY_IDENTIFIER\0"
"INVALID_PROXY_POLICY_SETTING\0"
"INVALID_PURPOSE\0"
"INVALID_SECTION\0"
"INVALID_SYNTAX\0"
"INVALID_VALUE\0"
"ISSUER_DECODE_ERROR\0"
"NEED_ORGANIZATION_AND_NUMBERS\0"
"NO_CONFIG_DATABASE\0"
"NO_ISSUER_CERTIFICATE\0"
"NO_ISSUER_DETAILS\0"
"NO_POLICY_IDENTIFIER\0"
"NO_PROXY_CERT_POLICY_LANGUAGE_DEFINED\0"
"NO_PUBLIC_KEY\0"
"NO_SUBJECT_DETAILS\0"
"ODD_NUMBER_OF_DIGITS\0"
"OPERATION_NOT_DEFINED\0"
"OTHERNAME_ERROR\0"
"POLICY_LANGUAGE_ALREADY_DEFINED\0"
"POLICY_PATH_LENGTH\0"
"POLICY_PATH_LENGTH_ALREADY_DEFINED\0"
"POLICY_WHEN_PROXY_LANGUAGE_REQUIRES_NO_POLICY\0"
"SECTION_NOT_FOUND\0"
"TRAILING_DATA_IN_EXTENSION\0"
"UNABLE_TO_GET_ISSUER_DETAILS\0"
"UNABLE_TO_GET_ISSUER_KEYID\0"
"UNKNOWN_BIT_STRING_ARGUMENT\0"
"UNKNOWN_EXTENSION\0"
"UNKNOWN_EXTENSION_NAME\0"
"UNKNOWN_OPTION\0"
"UNSUPPORTED_OPTION\0"
"USER_TOO_LONG\0"
"";
|
33c5d6119c60c8f745b9f737e6c2996c5d7dc444
|
83e7dc1281874779c46dfadcc15b2bb66d8e599c
|
/tests/src/test_cases/test_image_formats.c
|
78e6c08aba0929179bdb9c4b18ad5984668a5b22
|
[
"MIT"
] |
permissive
|
lvgl/lvgl
|
7d51d6774d6ac71df7101fc7ded56fea4b70be01
|
5c984b4a5364b6455966eb3a860153806c51626f
|
refs/heads/master
| 2023-08-30T22:39:20.283922
| 2023-08-30T19:55:29
| 2023-08-30T19:55:29
| 60,667,730
| 9,296
| 2,218
|
MIT
| 2023-09-14T17:59:34
| 2016-06-08T04:14:34
|
C
|
UTF-8
|
C
| false
| false
| 4,268
|
c
|
test_image_formats.c
|
#if LV_BUILD_TEST
#include "../lvgl.h"
#include "unity/unity.h"
void setUp(void)
{
/* Function run before every test */
lv_obj_set_flex_flow(lv_scr_act(), LV_FLEX_FLOW_ROW_WRAP);
lv_obj_set_flex_align(lv_scr_act(), LV_FLEX_ALIGN_SPACE_EVENLY, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_SPACE_EVENLY);
lv_obj_clean(lv_scr_act());
}
void tearDown(void)
{
/* Function run after every test */
}
static void img_create(const char * name, const void * img_src, bool rotate, bool recolor)
{
lv_obj_t * cont = lv_obj_create(lv_scr_act());
lv_obj_set_size(cont, 150, LV_SIZE_CONTENT);
lv_obj_set_style_bg_color(cont, lv_palette_main(LV_PALETTE_LIGHT_BLUE), 0);
lv_obj_set_flex_flow(cont, LV_FLEX_FLOW_COLUMN);
lv_obj_t * img = lv_img_create(cont);
lv_img_set_src(img, img_src);
lv_obj_set_style_img_recolor(img, lv_palette_main(LV_PALETTE_RED), 0); /*For A8*/
if(recolor) lv_obj_set_style_img_recolor_opa(img, LV_OPA_70, 0);
if(rotate) lv_img_set_angle(img, 450);
lv_obj_t * label = lv_label_create(cont);
lv_label_set_text(label, name);
}
void test_image_built_in_decode(void)
{
LV_IMG_DECLARE(test_img_cogwheel_i4);
LV_IMG_DECLARE(test_img_cogwheel_a8);
LV_IMG_DECLARE(test_img_cogwheel_rgb565);
LV_IMG_DECLARE(test_img_cogwheel_rgb565a8);
LV_IMG_DECLARE(test_img_cogwheel_xrgb8888);
LV_IMG_DECLARE(test_img_cogwheel_argb8888);
img_create("I4", &test_img_cogwheel_i4, false, false);
img_create("A8", &test_img_cogwheel_a8, false, false);
img_create("RGB565", &test_img_cogwheel_rgb565, false, false);
img_create("RGB565A8", &test_img_cogwheel_rgb565a8, false, false);
img_create("XRGB8888", &test_img_cogwheel_xrgb8888, false, false);
img_create("ARGB8888", &test_img_cogwheel_argb8888, false, false);
TEST_ASSERT_EQUAL_SCREENSHOT("draw/image_format_simple.png");
}
void test_image_built_in_decode_rotate(void)
{
LV_IMG_DECLARE(test_img_cogwheel_i4);
LV_IMG_DECLARE(test_img_cogwheel_a8);
LV_IMG_DECLARE(test_img_cogwheel_rgb565);
LV_IMG_DECLARE(test_img_cogwheel_rgb565a8);
LV_IMG_DECLARE(test_img_cogwheel_xrgb8888);
LV_IMG_DECLARE(test_img_cogwheel_argb8888);
img_create("I4", &test_img_cogwheel_i4, true, false);
img_create("A8", &test_img_cogwheel_a8, true, false);
img_create("RGB565", &test_img_cogwheel_rgb565, true, false);
img_create("RGB565A8", &test_img_cogwheel_rgb565a8, true, false);
img_create("XRGB8888", &test_img_cogwheel_xrgb8888, true, false);
img_create("ARGB8888", &test_img_cogwheel_argb8888, true, false);
TEST_ASSERT_EQUAL_SCREENSHOT("draw/image_format_rotated.png");
}
void test_image_built_in_decode_recolor(void)
{
LV_IMG_DECLARE(test_img_cogwheel_i4);
LV_IMG_DECLARE(test_img_cogwheel_a8);
LV_IMG_DECLARE(test_img_cogwheel_rgb565);
LV_IMG_DECLARE(test_img_cogwheel_rgb565a8);
LV_IMG_DECLARE(test_img_cogwheel_xrgb8888);
LV_IMG_DECLARE(test_img_cogwheel_argb8888);
img_create("I4", &test_img_cogwheel_i4, false, true);
img_create("A8", &test_img_cogwheel_a8, false, true);
img_create("RGB565", &test_img_cogwheel_rgb565, false, true);
img_create("RGB565A8", &test_img_cogwheel_rgb565a8, false, true);
img_create("XRGB8888", &test_img_cogwheel_xrgb8888, false, true);
img_create("ARGB8888", &test_img_cogwheel_argb8888, false, true);
TEST_ASSERT_EQUAL_SCREENSHOT("draw/image_format_recolor.png");
}
void test_image_built_in_decode_rotate_and_recolor(void)
{
LV_IMG_DECLARE(test_img_cogwheel_i4);
LV_IMG_DECLARE(test_img_cogwheel_a8);
LV_IMG_DECLARE(test_img_cogwheel_rgb565);
LV_IMG_DECLARE(test_img_cogwheel_rgb565a8);
LV_IMG_DECLARE(test_img_cogwheel_xrgb8888);
LV_IMG_DECLARE(test_img_cogwheel_argb8888);
img_create("I4", &test_img_cogwheel_i4, true, true);
img_create("A8", &test_img_cogwheel_a8, true, true);
img_create("RGB565", &test_img_cogwheel_rgb565, true, true);
img_create("RGB565A8", &test_img_cogwheel_rgb565a8, true, true);
img_create("XRGB8888", &test_img_cogwheel_xrgb8888, true, true);
img_create("ARGB8888", &test_img_cogwheel_argb8888, true, true);
TEST_ASSERT_EQUAL_SCREENSHOT("draw/image_format_rotate_and_recolor.png");
}
#endif
|
96273d05a132762e80e086f1bfa6bac38f598caa
|
99bdb3251fecee538e0630f15f6574054dfc1468
|
/components/dfs/dfs_v1/filesystems/nfs/rpc/pmap.c
|
afa2583d090c4196955c19ab3bb7f4f639ecc416
|
[
"Apache-2.0"
] |
permissive
|
RT-Thread/rt-thread
|
03a7c52c2aeb1b06a544143b0e803d72f47d1ece
|
3602f891211904a27dcbd51e5ba72fefce7326b2
|
refs/heads/master
| 2023-09-01T04:10:20.295801
| 2023-08-31T16:20:55
| 2023-08-31T16:20:55
| 7,408,108
| 9,599
| 5,805
|
Apache-2.0
| 2023-09-14T13:37:26
| 2013-01-02T14:49:21
|
C
|
UTF-8
|
C
| false
| false
| 1,761
|
c
|
pmap.c
|
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
*/
#include "pmap.h"
#include "clnt.h"
#include <rpc/rpc.h>
static struct timeval timeout = { 5, 0 };
static struct timeval tottimeout = { 60, 0 };
bool_t xdr_pmap(XDR *xdrs, struct pmap *regs)
{
if (xdr_u_long(xdrs, ®s->pm_prog) &&
xdr_u_long(xdrs, ®s->pm_vers) &&
xdr_u_long(xdrs, ®s->pm_prot))
return (xdr_u_long(xdrs, ®s->pm_port));
return (FALSE);
}
/*
* Find the mapped port for program,version.
* Calls the pmap service remotely to do the lookup.
* Returns 0 if no map exists.
*/
unsigned short pmap_getport(struct sockaddr_in *address, unsigned long program, unsigned long version, unsigned int protocol)
{
unsigned short port = 0;
int socket = -1;
register CLIENT *client = RT_NULL;
struct pmap parms;
address->sin_port = htons((unsigned short)PMAPPORT);
if (protocol == IPPROTO_UDP)
client = clntudp_bufcreate(address, PMAPPROG, PMAPVERS, timeout,
&socket, RPCSMALLMSGSIZE,
RPCSMALLMSGSIZE);
if (client != (CLIENT *) NULL)
{
parms.pm_prog = program;
parms.pm_vers = version;
parms.pm_prot = protocol;
parms.pm_port = 0; /* not needed or used */
if (CLNT_CALL(client, PMAPPROC_GETPORT, (xdrproc_t)xdr_pmap, (char*)&parms,
(xdrproc_t)xdr_u_short, (char*)&port, tottimeout) != RPC_SUCCESS)
{
rt_kprintf("pmap failure\n");
}
CLNT_DESTROY(client);
}
(void) lwip_close(socket);
address->sin_port = 0;
return (port);
}
|
94539efe7ee87cbaf0e1b1fc759b2b215f4cce18
|
6310f8c4a856bb1bbd36ab8cc964cfe393894371
|
/include/clap/factory/draft/plugin-invalidation.h
|
ea698e55a2822531a8b85bca2068ce0a57a9683a
|
[
"MIT"
] |
permissive
|
free-audio/clap
|
9729614a1cda2f6883057955c2db1b34339bbe47
|
41964fa3f44fdbf6feb20df528a9cdf2cc3b05ba
|
refs/heads/main
| 2023-09-03T22:01:43.076327
| 2023-03-13T14:15:02
| 2023-03-13T14:15:02
| 26,473,165
| 1,440
| 103
|
MIT
| 2023-08-19T13:06:26
| 2014-11-11T06:49:32
|
C
|
UTF-8
|
C
| false
| false
| 1,776
|
h
|
plugin-invalidation.h
|
#pragma once
#include "../../private/std.h"
#include "../../private/macros.h"
// Use it to retrieve const clap_plugin_invalidation_factory_t* from
// clap_plugin_entry.get_factory()
static const CLAP_CONSTEXPR char CLAP_PLUGIN_INVALIDATION_FACTORY_ID[] =
"clap.plugin-invalidation-factory/draft0";
#ifdef __cplusplus
extern "C" {
#endif
typedef struct clap_plugin_invalidation_source {
// Directory containing the file(s) to scan, must be absolute
const char *directory;
// globing pattern, in the form *.dll
const char *filename_glob;
// should the directory be scanned recursively?
bool recursive_scan;
} clap_plugin_invalidation_source_t;
// Used to figure out when a plugin needs to be scanned again.
// Imagine a situation with a single entry point: my-plugin.clap which then scans itself
// a set of "sub-plugins". New plugin may be available even if my-plugin.clap file doesn't change.
// This interfaces solves this issue and gives a way to the host to monitor additional files.
typedef struct clap_plugin_invalidation_factory {
// Get the number of invalidation source.
uint32_t(CLAP_ABI *count)(const struct clap_plugin_invalidation_factory *factory);
// Get the invalidation source by its index.
// [thread-safe]
const clap_plugin_invalidation_source_t *(CLAP_ABI *get)(
const struct clap_plugin_invalidation_factory *factory, uint32_t index);
// In case the host detected a invalidation event, it can call refresh() to let the
// plugin_entry update the set of plugins available.
// If the function returned false, then the plugin needs to be reloaded.
bool(CLAP_ABI *refresh)(const struct clap_plugin_invalidation_factory *factory);
} clap_plugin_invalidation_factory_t;
#ifdef __cplusplus
}
#endif
|
5f27ec4600d810891805e58da0af4c984f904dd8
|
010279e2ba272d09e9d2c4e903722e5faba2cf7a
|
/contrib/libs/clapack/stgsna.c
|
d469299e3102dbda2c5ab95ee16822adef821b0c
|
[
"BSD-3-Clause",
"Apache-2.0"
] |
permissive
|
catboost/catboost
|
854c1a1f439a96f1ae6b48e16644be20aa04dba2
|
f5042e35b945aded77b23470ead62d7eacefde92
|
refs/heads/master
| 2023-09-01T12:14:14.174108
| 2023-09-01T10:01:01
| 2023-09-01T10:22:12
| 97,556,265
| 8,012
| 1,425
|
Apache-2.0
| 2023-09-11T03:32:32
| 2017-07-18T05:29:04
|
Python
|
UTF-8
|
C
| false
| false
| 22,850
|
c
|
stgsna.c
|
/* stgsna.f -- translated by f2c (version 20061008).
You must link the resulting object file with libf2c:
on Microsoft Windows system, link with libf2c.lib;
on Linux or Unix systems, link with .../path/to/libf2c.a -lm
or, if you install libf2c.a in a standard place, with -lf2c -lm
-- in that order, at the end of the command line, as in
cc *.o -lf2c -lm
Source for libf2c is in /netlib/f2c/libf2c.zip, e.g.,
http://www.netlib.org/f2c/libf2c.zip
*/
#include "f2c.h"
#include "blaswrap.h"
/* Table of constant values */
static integer c__1 = 1;
static real c_b19 = 1.f;
static real c_b21 = 0.f;
static integer c__2 = 2;
static logical c_false = FALSE_;
static integer c__3 = 3;
/* Subroutine */ int stgsna_(char *job, char *howmny, logical *select,
integer *n, real *a, integer *lda, real *b, integer *ldb, real *vl,
integer *ldvl, real *vr, integer *ldvr, real *s, real *dif, integer *
mm, integer *m, real *work, integer *lwork, integer *iwork, integer *
info)
{
/* System generated locals */
integer a_dim1, a_offset, b_dim1, b_offset, vl_dim1, vl_offset, vr_dim1,
vr_offset, i__1, i__2;
real r__1, r__2;
/* Builtin functions */
double sqrt(doublereal);
/* Local variables */
integer i__, k;
real c1, c2;
integer n1, n2, ks, iz;
real eps, beta, cond;
logical pair;
integer ierr;
real uhav, uhbv;
integer ifst;
real lnrm;
extern doublereal sdot_(integer *, real *, integer *, real *, integer *);
integer ilst;
real rnrm;
extern /* Subroutine */ int slag2_(real *, integer *, real *, integer *,
real *, real *, real *, real *, real *, real *);
extern doublereal snrm2_(integer *, real *, integer *);
real root1, root2, scale;
extern logical lsame_(char *, char *);
real uhavi, uhbvi;
extern /* Subroutine */ int sgemv_(char *, integer *, integer *, real *,
real *, integer *, real *, integer *, real *, real *, integer *);
real tmpii;
integer lwmin;
logical wants;
real tmpir, tmpri, dummy[1], tmprr;
extern doublereal slapy2_(real *, real *);
real dummy1[1], alphai, alphar;
extern doublereal slamch_(char *);
extern /* Subroutine */ int xerbla_(char *, integer *);
logical wantbh, wantdf;
extern /* Subroutine */ int slacpy_(char *, integer *, integer *, real *,
integer *, real *, integer *), stgexc_(logical *, logical
*, integer *, real *, integer *, real *, integer *, real *,
integer *, real *, integer *, integer *, integer *, real *,
integer *, integer *);
logical somcon;
real alprqt, smlnum;
logical lquery;
extern /* Subroutine */ int stgsyl_(char *, integer *, integer *, integer
*, real *, integer *, real *, integer *, real *, integer *, real *
, integer *, real *, integer *, real *, integer *, real *, real *,
real *, integer *, integer *, integer *);
/* -- LAPACK routine (version 3.2) -- */
/* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
/* November 2006 */
/* .. Scalar Arguments .. */
/* .. */
/* .. Array Arguments .. */
/* .. */
/* Purpose */
/* ======= */
/* STGSNA estimates reciprocal condition numbers for specified */
/* eigenvalues and/or eigenvectors of a matrix pair (A, B) in */
/* generalized real Schur canonical form (or of any matrix pair */
/* (Q*A*Z', Q*B*Z') with orthogonal matrices Q and Z, where */
/* Z' denotes the transpose of Z. */
/* (A, B) must be in generalized real Schur form (as returned by SGGES), */
/* i.e. A is block upper triangular with 1-by-1 and 2-by-2 diagonal */
/* blocks. B is upper triangular. */
/* Arguments */
/* ========= */
/* JOB (input) CHARACTER*1 */
/* Specifies whether condition numbers are required for */
/* eigenvalues (S) or eigenvectors (DIF): */
/* = 'E': for eigenvalues only (S); */
/* = 'V': for eigenvectors only (DIF); */
/* = 'B': for both eigenvalues and eigenvectors (S and DIF). */
/* HOWMNY (input) CHARACTER*1 */
/* = 'A': compute condition numbers for all eigenpairs; */
/* = 'S': compute condition numbers for selected eigenpairs */
/* specified by the array SELECT. */
/* SELECT (input) LOGICAL array, dimension (N) */
/* If HOWMNY = 'S', SELECT specifies the eigenpairs for which */
/* condition numbers are required. To select condition numbers */
/* for the eigenpair corresponding to a real eigenvalue w(j), */
/* SELECT(j) must be set to .TRUE.. To select condition numbers */
/* corresponding to a complex conjugate pair of eigenvalues w(j) */
/* and w(j+1), either SELECT(j) or SELECT(j+1) or both, must be */
/* set to .TRUE.. */
/* If HOWMNY = 'A', SELECT is not referenced. */
/* N (input) INTEGER */
/* The order of the square matrix pair (A, B). N >= 0. */
/* A (input) REAL array, dimension (LDA,N) */
/* The upper quasi-triangular matrix A in the pair (A,B). */
/* LDA (input) INTEGER */
/* The leading dimension of the array A. LDA >= max(1,N). */
/* B (input) REAL array, dimension (LDB,N) */
/* The upper triangular matrix B in the pair (A,B). */
/* LDB (input) INTEGER */
/* The leading dimension of the array B. LDB >= max(1,N). */
/* VL (input) REAL array, dimension (LDVL,M) */
/* If JOB = 'E' or 'B', VL must contain left eigenvectors of */
/* (A, B), corresponding to the eigenpairs specified by HOWMNY */
/* and SELECT. The eigenvectors must be stored in consecutive */
/* columns of VL, as returned by STGEVC. */
/* If JOB = 'V', VL is not referenced. */
/* LDVL (input) INTEGER */
/* The leading dimension of the array VL. LDVL >= 1. */
/* If JOB = 'E' or 'B', LDVL >= N. */
/* VR (input) REAL array, dimension (LDVR,M) */
/* If JOB = 'E' or 'B', VR must contain right eigenvectors of */
/* (A, B), corresponding to the eigenpairs specified by HOWMNY */
/* and SELECT. The eigenvectors must be stored in consecutive */
/* columns ov VR, as returned by STGEVC. */
/* If JOB = 'V', VR is not referenced. */
/* LDVR (input) INTEGER */
/* The leading dimension of the array VR. LDVR >= 1. */
/* If JOB = 'E' or 'B', LDVR >= N. */
/* S (output) REAL array, dimension (MM) */
/* If JOB = 'E' or 'B', the reciprocal condition numbers of the */
/* selected eigenvalues, stored in consecutive elements of the */
/* array. For a complex conjugate pair of eigenvalues two */
/* consecutive elements of S are set to the same value. Thus */
/* S(j), DIF(j), and the j-th columns of VL and VR all */
/* correspond to the same eigenpair (but not in general the */
/* j-th eigenpair, unless all eigenpairs are selected). */
/* If JOB = 'V', S is not referenced. */
/* DIF (output) REAL array, dimension (MM) */
/* If JOB = 'V' or 'B', the estimated reciprocal condition */
/* numbers of the selected eigenvectors, stored in consecutive */
/* elements of the array. For a complex eigenvector two */
/* consecutive elements of DIF are set to the same value. If */
/* the eigenvalues cannot be reordered to compute DIF(j), DIF(j) */
/* is set to 0; this can only occur when the true value would be */
/* very small anyway. */
/* If JOB = 'E', DIF is not referenced. */
/* MM (input) INTEGER */
/* The number of elements in the arrays S and DIF. MM >= M. */
/* M (output) INTEGER */
/* The number of elements of the arrays S and DIF used to store */
/* the specified condition numbers; for each selected real */
/* eigenvalue one element is used, and for each selected complex */
/* conjugate pair of eigenvalues, two elements are used. */
/* If HOWMNY = 'A', M is set to N. */
/* WORK (workspace/output) REAL array, dimension (MAX(1,LWORK)) */
/* On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
/* LWORK (input) INTEGER */
/* The dimension of the array WORK. LWORK >= max(1,N). */
/* If JOB = 'V' or 'B' LWORK >= 2*N*(N+2)+16. */
/* If LWORK = -1, then a workspace query is assumed; the routine */
/* only calculates the optimal size of the WORK array, returns */
/* this value as the first entry of the WORK array, and no error */
/* message related to LWORK is issued by XERBLA. */
/* IWORK (workspace) INTEGER array, dimension (N + 6) */
/* If JOB = 'E', IWORK is not referenced. */
/* INFO (output) INTEGER */
/* =0: Successful exit */
/* <0: If INFO = -i, the i-th argument had an illegal value */
/* Further Details */
/* =============== */
/* The reciprocal of the condition number of a generalized eigenvalue */
/* w = (a, b) is defined as */
/* S(w) = (|u'Av|**2 + |u'Bv|**2)**(1/2) / (norm(u)*norm(v)) */
/* where u and v are the left and right eigenvectors of (A, B) */
/* corresponding to w; |z| denotes the absolute value of the complex */
/* number, and norm(u) denotes the 2-norm of the vector u. */
/* The pair (a, b) corresponds to an eigenvalue w = a/b (= u'Av/u'Bv) */
/* of the matrix pair (A, B). If both a and b equal zero, then (A B) is */
/* singular and S(I) = -1 is returned. */
/* An approximate error bound on the chordal distance between the i-th */
/* computed generalized eigenvalue w and the corresponding exact */
/* eigenvalue lambda is */
/* chord(w, lambda) <= EPS * norm(A, B) / S(I) */
/* where EPS is the machine precision. */
/* The reciprocal of the condition number DIF(i) of right eigenvector u */
/* and left eigenvector v corresponding to the generalized eigenvalue w */
/* is defined as follows: */
/* a) If the i-th eigenvalue w = (a,b) is real */
/* Suppose U and V are orthogonal transformations such that */
/* U'*(A, B)*V = (S, T) = ( a * ) ( b * ) 1 */
/* ( 0 S22 ),( 0 T22 ) n-1 */
/* 1 n-1 1 n-1 */
/* Then the reciprocal condition number DIF(i) is */
/* Difl((a, b), (S22, T22)) = sigma-min( Zl ), */
/* where sigma-min(Zl) denotes the smallest singular value of the */
/* 2(n-1)-by-2(n-1) matrix */
/* Zl = [ kron(a, In-1) -kron(1, S22) ] */
/* [ kron(b, In-1) -kron(1, T22) ] . */
/* Here In-1 is the identity matrix of size n-1. kron(X, Y) is the */
/* Kronecker product between the matrices X and Y. */
/* Note that if the default method for computing DIF(i) is wanted */
/* (see SLATDF), then the parameter DIFDRI (see below) should be */
/* changed from 3 to 4 (routine SLATDF(IJOB = 2 will be used)). */
/* See STGSYL for more details. */
/* b) If the i-th and (i+1)-th eigenvalues are complex conjugate pair, */
/* Suppose U and V are orthogonal transformations such that */
/* U'*(A, B)*V = (S, T) = ( S11 * ) ( T11 * ) 2 */
/* ( 0 S22 ),( 0 T22) n-2 */
/* 2 n-2 2 n-2 */
/* and (S11, T11) corresponds to the complex conjugate eigenvalue */
/* pair (w, conjg(w)). There exist unitary matrices U1 and V1 such */
/* that */
/* U1'*S11*V1 = ( s11 s12 ) and U1'*T11*V1 = ( t11 t12 ) */
/* ( 0 s22 ) ( 0 t22 ) */
/* where the generalized eigenvalues w = s11/t11 and */
/* conjg(w) = s22/t22. */
/* Then the reciprocal condition number DIF(i) is bounded by */
/* min( d1, max( 1, |real(s11)/real(s22)| )*d2 ) */
/* where, d1 = Difl((s11, t11), (s22, t22)) = sigma-min(Z1), where */
/* Z1 is the complex 2-by-2 matrix */
/* Z1 = [ s11 -s22 ] */
/* [ t11 -t22 ], */
/* This is done by computing (using real arithmetic) the */
/* roots of the characteristical polynomial det(Z1' * Z1 - lambda I), */
/* where Z1' denotes the conjugate transpose of Z1 and det(X) denotes */
/* the determinant of X. */
/* and d2 is an upper bound on Difl((S11, T11), (S22, T22)), i.e. an */
/* upper bound on sigma-min(Z2), where Z2 is (2n-2)-by-(2n-2) */
/* Z2 = [ kron(S11', In-2) -kron(I2, S22) ] */
/* [ kron(T11', In-2) -kron(I2, T22) ] */
/* Note that if the default method for computing DIF is wanted (see */
/* SLATDF), then the parameter DIFDRI (see below) should be changed */
/* from 3 to 4 (routine SLATDF(IJOB = 2 will be used)). See STGSYL */
/* for more details. */
/* For each eigenvalue/vector specified by SELECT, DIF stores a */
/* Frobenius norm-based estimate of Difl. */
/* An approximate error bound for the i-th computed eigenvector VL(i) or */
/* VR(i) is given by */
/* EPS * norm(A, B) / DIF(i). */
/* See ref. [2-3] for more details and further references. */
/* Based on contributions by */
/* Bo Kagstrom and Peter Poromaa, Department of Computing Science, */
/* Umea University, S-901 87 Umea, Sweden. */
/* References */
/* ========== */
/* [1] B. Kagstrom; A Direct Method for Reordering Eigenvalues in the */
/* Generalized Real Schur Form of a Regular Matrix Pair (A, B), in */
/* M.S. Moonen et al (eds), Linear Algebra for Large Scale and */
/* Real-Time Applications, Kluwer Academic Publ. 1993, pp 195-218. */
/* [2] B. Kagstrom and P. Poromaa; Computing Eigenspaces with Specified */
/* Eigenvalues of a Regular Matrix Pair (A, B) and Condition */
/* Estimation: Theory, Algorithms and Software, */
/* Report UMINF - 94.04, Department of Computing Science, Umea */
/* University, S-901 87 Umea, Sweden, 1994. Also as LAPACK Working */
/* Note 87. To appear in Numerical Algorithms, 1996. */
/* [3] B. Kagstrom and P. Poromaa, LAPACK-Style Algorithms and Software */
/* for Solving the Generalized Sylvester Equation and Estimating the */
/* Separation between Regular Matrix Pairs, Report UMINF - 93.23, */
/* Department of Computing Science, Umea University, S-901 87 Umea, */
/* Sweden, December 1993, Revised April 1994, Also as LAPACK Working */
/* Note 75. To appear in ACM Trans. on Math. Software, Vol 22, */
/* No 1, 1996. */
/* ===================================================================== */
/* .. Parameters .. */
/* .. */
/* .. Local Scalars .. */
/* .. */
/* .. Local Arrays .. */
/* .. */
/* .. External Functions .. */
/* .. */
/* .. External Subroutines .. */
/* .. */
/* .. Intrinsic Functions .. */
/* .. */
/* .. Executable Statements .. */
/* Decode and test the input parameters */
/* Parameter adjustments */
--select;
a_dim1 = *lda;
a_offset = 1 + a_dim1;
a -= a_offset;
b_dim1 = *ldb;
b_offset = 1 + b_dim1;
b -= b_offset;
vl_dim1 = *ldvl;
vl_offset = 1 + vl_dim1;
vl -= vl_offset;
vr_dim1 = *ldvr;
vr_offset = 1 + vr_dim1;
vr -= vr_offset;
--s;
--dif;
--work;
--iwork;
/* Function Body */
wantbh = lsame_(job, "B");
wants = lsame_(job, "E") || wantbh;
wantdf = lsame_(job, "V") || wantbh;
somcon = lsame_(howmny, "S");
*info = 0;
lquery = *lwork == -1;
if (! wants && ! wantdf) {
*info = -1;
} else if (! lsame_(howmny, "A") && ! somcon) {
*info = -2;
} else if (*n < 0) {
*info = -4;
} else if (*lda < max(1,*n)) {
*info = -6;
} else if (*ldb < max(1,*n)) {
*info = -8;
} else if (wants && *ldvl < *n) {
*info = -10;
} else if (wants && *ldvr < *n) {
*info = -12;
} else {
/* Set M to the number of eigenpairs for which condition numbers */
/* are required, and test MM. */
if (somcon) {
*m = 0;
pair = FALSE_;
i__1 = *n;
for (k = 1; k <= i__1; ++k) {
if (pair) {
pair = FALSE_;
} else {
if (k < *n) {
if (a[k + 1 + k * a_dim1] == 0.f) {
if (select[k]) {
++(*m);
}
} else {
pair = TRUE_;
if (select[k] || select[k + 1]) {
*m += 2;
}
}
} else {
if (select[*n]) {
++(*m);
}
}
}
/* L10: */
}
} else {
*m = *n;
}
if (*n == 0) {
lwmin = 1;
} else if (lsame_(job, "V") || lsame_(job,
"B")) {
lwmin = (*n << 1) * (*n + 2) + 16;
} else {
lwmin = *n;
}
work[1] = (real) lwmin;
if (*mm < *m) {
*info = -15;
} else if (*lwork < lwmin && ! lquery) {
*info = -18;
}
}
if (*info != 0) {
i__1 = -(*info);
xerbla_("STGSNA", &i__1);
return 0;
} else if (lquery) {
return 0;
}
/* Quick return if possible */
if (*n == 0) {
return 0;
}
/* Get machine constants */
eps = slamch_("P");
smlnum = slamch_("S") / eps;
ks = 0;
pair = FALSE_;
i__1 = *n;
for (k = 1; k <= i__1; ++k) {
/* Determine whether A(k,k) begins a 1-by-1 or 2-by-2 block. */
if (pair) {
pair = FALSE_;
goto L20;
} else {
if (k < *n) {
pair = a[k + 1 + k * a_dim1] != 0.f;
}
}
/* Determine whether condition numbers are required for the k-th */
/* eigenpair. */
if (somcon) {
if (pair) {
if (! select[k] && ! select[k + 1]) {
goto L20;
}
} else {
if (! select[k]) {
goto L20;
}
}
}
++ks;
if (wants) {
/* Compute the reciprocal condition number of the k-th */
/* eigenvalue. */
if (pair) {
/* Complex eigenvalue pair. */
r__1 = snrm2_(n, &vr[ks * vr_dim1 + 1], &c__1);
r__2 = snrm2_(n, &vr[(ks + 1) * vr_dim1 + 1], &c__1);
rnrm = slapy2_(&r__1, &r__2);
r__1 = snrm2_(n, &vl[ks * vl_dim1 + 1], &c__1);
r__2 = snrm2_(n, &vl[(ks + 1) * vl_dim1 + 1], &c__1);
lnrm = slapy2_(&r__1, &r__2);
sgemv_("N", n, n, &c_b19, &a[a_offset], lda, &vr[ks * vr_dim1
+ 1], &c__1, &c_b21, &work[1], &c__1);
tmprr = sdot_(n, &work[1], &c__1, &vl[ks * vl_dim1 + 1], &
c__1);
tmpri = sdot_(n, &work[1], &c__1, &vl[(ks + 1) * vl_dim1 + 1],
&c__1);
sgemv_("N", n, n, &c_b19, &a[a_offset], lda, &vr[(ks + 1) *
vr_dim1 + 1], &c__1, &c_b21, &work[1], &c__1);
tmpii = sdot_(n, &work[1], &c__1, &vl[(ks + 1) * vl_dim1 + 1],
&c__1);
tmpir = sdot_(n, &work[1], &c__1, &vl[ks * vl_dim1 + 1], &
c__1);
uhav = tmprr + tmpii;
uhavi = tmpir - tmpri;
sgemv_("N", n, n, &c_b19, &b[b_offset], ldb, &vr[ks * vr_dim1
+ 1], &c__1, &c_b21, &work[1], &c__1);
tmprr = sdot_(n, &work[1], &c__1, &vl[ks * vl_dim1 + 1], &
c__1);
tmpri = sdot_(n, &work[1], &c__1, &vl[(ks + 1) * vl_dim1 + 1],
&c__1);
sgemv_("N", n, n, &c_b19, &b[b_offset], ldb, &vr[(ks + 1) *
vr_dim1 + 1], &c__1, &c_b21, &work[1], &c__1);
tmpii = sdot_(n, &work[1], &c__1, &vl[(ks + 1) * vl_dim1 + 1],
&c__1);
tmpir = sdot_(n, &work[1], &c__1, &vl[ks * vl_dim1 + 1], &
c__1);
uhbv = tmprr + tmpii;
uhbvi = tmpir - tmpri;
uhav = slapy2_(&uhav, &uhavi);
uhbv = slapy2_(&uhbv, &uhbvi);
cond = slapy2_(&uhav, &uhbv);
s[ks] = cond / (rnrm * lnrm);
s[ks + 1] = s[ks];
} else {
/* Real eigenvalue. */
rnrm = snrm2_(n, &vr[ks * vr_dim1 + 1], &c__1);
lnrm = snrm2_(n, &vl[ks * vl_dim1 + 1], &c__1);
sgemv_("N", n, n, &c_b19, &a[a_offset], lda, &vr[ks * vr_dim1
+ 1], &c__1, &c_b21, &work[1], &c__1);
uhav = sdot_(n, &work[1], &c__1, &vl[ks * vl_dim1 + 1], &c__1)
;
sgemv_("N", n, n, &c_b19, &b[b_offset], ldb, &vr[ks * vr_dim1
+ 1], &c__1, &c_b21, &work[1], &c__1);
uhbv = sdot_(n, &work[1], &c__1, &vl[ks * vl_dim1 + 1], &c__1)
;
cond = slapy2_(&uhav, &uhbv);
if (cond == 0.f) {
s[ks] = -1.f;
} else {
s[ks] = cond / (rnrm * lnrm);
}
}
}
if (wantdf) {
if (*n == 1) {
dif[ks] = slapy2_(&a[a_dim1 + 1], &b[b_dim1 + 1]);
goto L20;
}
/* Estimate the reciprocal condition number of the k-th */
/* eigenvectors. */
if (pair) {
/* Copy the 2-by 2 pencil beginning at (A(k,k), B(k, k)). */
/* Compute the eigenvalue(s) at position K. */
work[1] = a[k + k * a_dim1];
work[2] = a[k + 1 + k * a_dim1];
work[3] = a[k + (k + 1) * a_dim1];
work[4] = a[k + 1 + (k + 1) * a_dim1];
work[5] = b[k + k * b_dim1];
work[6] = b[k + 1 + k * b_dim1];
work[7] = b[k + (k + 1) * b_dim1];
work[8] = b[k + 1 + (k + 1) * b_dim1];
r__1 = smlnum * eps;
slag2_(&work[1], &c__2, &work[5], &c__2, &r__1, &beta, dummy1,
&alphar, dummy, &alphai);
alprqt = 1.f;
c1 = (alphar * alphar + alphai * alphai + beta * beta) * 2.f;
c2 = beta * 4.f * beta * alphai * alphai;
root1 = c1 + sqrt(c1 * c1 - c2 * 4.f);
root2 = c2 / root1;
root1 /= 2.f;
/* Computing MIN */
r__1 = sqrt(root1), r__2 = sqrt(root2);
cond = dmin(r__1,r__2);
}
/* Copy the matrix (A, B) to the array WORK and swap the */
/* diagonal block beginning at A(k,k) to the (1,1) position. */
slacpy_("Full", n, n, &a[a_offset], lda, &work[1], n);
slacpy_("Full", n, n, &b[b_offset], ldb, &work[*n * *n + 1], n);
ifst = k;
ilst = 1;
i__2 = *lwork - (*n << 1) * *n;
stgexc_(&c_false, &c_false, n, &work[1], n, &work[*n * *n + 1], n,
dummy, &c__1, dummy1, &c__1, &ifst, &ilst, &work[(*n * *
n << 1) + 1], &i__2, &ierr);
if (ierr > 0) {
/* Ill-conditioned problem - swap rejected. */
dif[ks] = 0.f;
} else {
/* Reordering successful, solve generalized Sylvester */
/* equation for R and L, */
/* A22 * R - L * A11 = A12 */
/* B22 * R - L * B11 = B12, */
/* and compute estimate of Difl((A11,B11), (A22, B22)). */
n1 = 1;
if (work[2] != 0.f) {
n1 = 2;
}
n2 = *n - n1;
if (n2 == 0) {
dif[ks] = cond;
} else {
i__ = *n * *n + 1;
iz = (*n << 1) * *n + 1;
i__2 = *lwork - (*n << 1) * *n;
stgsyl_("N", &c__3, &n2, &n1, &work[*n * n1 + n1 + 1], n,
&work[1], n, &work[n1 + 1], n, &work[*n * n1 + n1
+ i__], n, &work[i__], n, &work[n1 + i__], n, &
scale, &dif[ks], &work[iz + 1], &i__2, &iwork[1],
&ierr);
if (pair) {
/* Computing MIN */
r__1 = dmax(1.f,alprqt) * dif[ks];
dif[ks] = dmin(r__1,cond);
}
}
}
if (pair) {
dif[ks + 1] = dif[ks];
}
}
if (pair) {
++ks;
}
L20:
;
}
work[1] = (real) lwmin;
return 0;
/* End of STGSNA */
} /* stgsna_ */
|
3e59b0417fb4abe864fbbfecc7624997d2401262
|
b8a833801aa3f3618a4a68c1936299f8bd270038
|
/src/utilities/gstat/dbaswi.h
|
fee77236a5158e80a254f5daf569ce2c2168ef97
|
[] |
no_license
|
FirebirdSQL/firebird
|
039a84a81ea089852ad36339e44256c85dbf5b10
|
1973d01f396196d18f284114bd2905ac4dcfeb94
|
refs/heads/master
| 2023-09-01T21:34:39.835826
| 2023-08-31T20:13:52
| 2023-08-31T20:13:52
| 54,005,538
| 1,192
| 303
| null | 2023-09-14T16:12:28
| 2016-03-16T06:10:37
|
C++
|
UTF-8
|
C
| false
| false
| 4,739
|
h
|
dbaswi.h
|
/*
* PROGRAM: Database analysis tool
* MODULE: dbaswi.h
* DESCRIPTION: dba switches
*
* The contents of this file are subject to the Interbase Public
* License Version 1.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.Inprise.com/IPL.html
*
* Software distributed under the License is distributed on an
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
* or implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code was created by Inprise Corporation
* and its predecessors. Portions created by Inprise Corporation are
* Copyright (C) Inprise Corporation.
*
* All Rights Reserved.
* Contributor(s): ______________________________________.
*/
#ifndef DBA_DBASWI_H
#define DBA_DBASWI_H
#include "../common/classes/Switches.h"
#include "../jrd/constants.h"
// Switch handling constants. Note that the first IN_SW_DATA_ITEMS
// switch constants refer to data items. The remaining switch constants
// refer to actual switches.
const int IN_SW_DBA_0 = 0; // not a known switch
const int IN_SW_DBA_SYSTEM = 1; // analyze system relations
const int IN_SW_DBA_DATA = 2; // analyze data pages
const int IN_SW_DBA_INDEX = 3; // analyze index leaf pages
const int IN_SW_DBA_VERSION = 4; // display version number
const int IN_SW_DBA_HEADER = 5; // analyze header page
//const int IN_SW_DBA_LOG = 6; // analze log pages
const int IN_SW_DBA_DATAIDX = 7; // analyze data and index pages
const int IN_SW_DBA_USERNAME = 8; // username
const int IN_SW_DBA_PASSWORD = 9; // password
const int IN_SW_DBA_RECORD = 10; // analyze record versions
const int IN_SW_DBA_RELATION = 11; // analyze specific relations
const int IN_SW_DBA_NOCREATION = 12; // don't print creation date
#ifdef TRUSTED_AUTH
const int IN_SW_DBA_TRUSTEDAUTH = 13; // trusted user name
#endif
const int IN_SW_DBA_FETCH_PASS = 14; // fetch password from file
const int IN_SW_DBA_ENCRYPTION = 15; // analyze pages encryption
const int IN_SW_DBA_HELP = 16; // show help
const int IN_SW_DBA_ROLE = 17; // SQL role
const static struct Switches::in_sw_tab_t dba_in_sw_table[] =
{
{IN_SW_DBA_DATAIDX, 0, "ALL", 0,0,0, false, false, 22, 1, NULL}, // msg 22: -a analyze data and index pages
{IN_SW_DBA_DATA, isc_spb_sts_data_pages, "DATA", 0,0,0, false, true, 23, 1, NULL}, // msg 23: -d analyze data pages
{IN_SW_DBA_ENCRYPTION, isc_spb_sts_encryption, "ENCRYPTION", 0,0,0, false, true, 51, 1, NULL}, // msg 51: -e analyze database encryption
{IN_SW_DBA_HEADER, isc_spb_sts_hdr_pages, "HEADER", 0,0,0, false, true, 24, 1, NULL}, // msg 24: -h analyze header page
{IN_SW_DBA_INDEX, isc_spb_sts_idx_pages, "INDEX", 0,0,0, false, true, 25, 1, NULL}, // msg 25: -i analyze index leaf pages
// {IN_SW_DBA_LOG, isc_spb_sts_db_log, "LOG", 0,0,0, false, true, 26, 1, NULL}, // msg 26: -l analyze log page
{IN_SW_DBA_SYSTEM, isc_spb_sts_sys_relations, "SYSTEM", 0,0,0, false, true, 27, 1, NULL}, // msg 27: -s analyze system relations
{IN_SW_DBA_USERNAME, 0, "USERNAME", 0,0,0, false, false, 32, 1, NULL}, // msg 32: -u username
{IN_SW_DBA_PASSWORD, 0, "PASSWORD", 0,0,0, false, false, 33, 1, NULL}, // msg 33: -p password
{IN_SW_DBA_FETCH_PASS, 0, "FETCH_PASSWORD", 0,0,0, false, false, 37, 2, NULL}, // msg 37: -fetch fetch password from file
{IN_SW_DBA_RECORD, isc_spb_sts_record_versions,"RECORD", 0,0,0, false, true, 34, 1, NULL}, // msg 34: -r analyze average record and version length
{IN_SW_DBA_RELATION, isc_spb_sts_table, "TABLE", 0,0,0, false, false, 35, 1, NULL}, // msg 35: -t tablename
{IN_SW_DBA_RELATION, isc_spb_sts_table, "TABLE", 0,0,0, false, true, 0, 1, NULL}, // no msg: let run old buggy code
{IN_SW_DBA_ROLE, 0, "ROLE", 0,0,0, false, false, 57, 1, NULL}, // msg 57: -role SQL role name
// special switch to avoid including creation date, only for tests (no message)
{IN_SW_DBA_NOCREATION, isc_spb_sts_nocreation, "NOCREATION", 0,0,0, false, true, 0, 1, NULL}, // msg (ignored) -n suppress creation date
#ifdef TRUSTED_AUTH
{IN_SW_DBA_TRUSTEDAUTH, 0, "TRUSTED", 0,0,0, false, false, 36, 2, NULL}, // msg 36: -tr use trusted authentication
#endif
{IN_SW_DBA_VERSION, 0, "Z", 0,0,0, false, false, 28, 1, NULL}, // msg 28: -z display version number
{IN_SW_DBA_HELP, 0, "?", 0,0,0, false, false, 0, 1, NULL}, // Help
{IN_SW_DBA_0, 0, NULL, 0,0,0, false, false, 0, 0, NULL} // End of List
};
#endif // DBA_DBASWI_H
|
105151fd78837dce0f5b1caac54d142a99a2981e
|
321d11eaee885ceb3a74db0a062f9bbdf282148c
|
/test/sha_test.c
|
4285e703c58d24dee1e5da458a186021c9592460
|
[
"BSD-3-Clause",
"Apache-2.0",
"OpenSSL",
"LicenseRef-scancode-proprietary-license"
] |
permissive
|
openssl/openssl
|
75691ebaae957793f2ff0673f77545277dfb3988
|
5318c012885a5382eadbf95aa9c1d35664bca819
|
refs/heads/master
| 2023-09-03T15:22:52.727123
| 2023-09-01T07:10:49
| 2023-09-02T14:30:01
| 7,634,677
| 24,148
| 11,569
|
Apache-2.0
| 2023-09-14T19:48:11
| 2013-01-15T22:34:48
|
C
|
UTF-8
|
C
| false
| false
| 3,769
|
c
|
sha_test.c
|
/*
* Copyright 2021 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the Apache License 2.0 (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
*/
#include <string.h>
#include <openssl/sha.h>
#include "testutil.h"
static int test_static_sha_common(const char *input, size_t length,
const unsigned char *out,
unsigned char *(*md)(const unsigned char *d,
size_t n,
unsigned char *md))
{
unsigned char buf[EVP_MAX_MD_SIZE], *sbuf;
const unsigned char *in = (unsigned char *)input;
const size_t in_len = strlen(input);
sbuf = (*md)(in, in_len, buf);
if (!TEST_ptr(sbuf)
|| !TEST_ptr_eq(sbuf, buf)
|| !TEST_mem_eq(sbuf, length, out, length))
return 0;
sbuf = (*md)(in, in_len, NULL);
if (!TEST_ptr(sbuf)
|| !TEST_ptr_ne(sbuf, buf)
|| !TEST_mem_eq(sbuf, length, out, length))
return 0;
return 1;
}
static int test_static_sha1(void)
{
static const unsigned char output[SHA_DIGEST_LENGTH] = {
0xa9, 0x99, 0x3e, 0x36, 0x47, 0x06, 0x81, 0x6a,
0xba, 0x3e, 0x25, 0x71, 0x78, 0x50, 0xc2, 0x6c,
0x9c, 0xd0, 0xd8, 0x9d
};
return test_static_sha_common("abc", SHA_DIGEST_LENGTH, output, &SHA1);
}
static int test_static_sha224(void)
{
static const unsigned char output[SHA224_DIGEST_LENGTH] = {
0x23, 0x09, 0x7d, 0x22, 0x34, 0x05, 0xd8, 0x22,
0x86, 0x42, 0xa4, 0x77, 0xbd, 0xa2, 0x55, 0xb3,
0x2a, 0xad, 0xbc, 0xe4, 0xbd, 0xa0, 0xb3, 0xf7,
0xe3, 0x6c, 0x9d, 0xa7
};
return test_static_sha_common("abc", SHA224_DIGEST_LENGTH, output, &SHA224);
}
static int test_static_sha256(void)
{
static const unsigned char output[SHA256_DIGEST_LENGTH] = {
0xba, 0x78, 0x16, 0xbf, 0x8f, 0x01, 0xcf, 0xea,
0x41, 0x41, 0x40, 0xde, 0x5d, 0xae, 0x22, 0x23,
0xb0, 0x03, 0x61, 0xa3, 0x96, 0x17, 0x7a, 0x9c,
0xb4, 0x10, 0xff, 0x61, 0xf2, 0x00, 0x15, 0xad
};
return test_static_sha_common("abc", SHA256_DIGEST_LENGTH, output, &SHA256);
}
static int test_static_sha384(void)
{
static const unsigned char output[SHA384_DIGEST_LENGTH] = {
0xcb, 0x00, 0x75, 0x3f, 0x45, 0xa3, 0x5e, 0x8b,
0xb5, 0xa0, 0x3d, 0x69, 0x9a, 0xc6, 0x50, 0x07,
0x27, 0x2c, 0x32, 0xab, 0x0e, 0xde, 0xd1, 0x63,
0x1a, 0x8b, 0x60, 0x5a, 0x43, 0xff, 0x5b, 0xed,
0x80, 0x86, 0x07, 0x2b, 0xa1, 0xe7, 0xcc, 0x23,
0x58, 0xba, 0xec, 0xa1, 0x34, 0xc8, 0x25, 0xa7
};
return test_static_sha_common("abc", SHA384_DIGEST_LENGTH, output, &SHA384);
}
static int test_static_sha512(void)
{
static const unsigned char output[SHA512_DIGEST_LENGTH] = {
0xdd, 0xaf, 0x35, 0xa1, 0x93, 0x61, 0x7a, 0xba,
0xcc, 0x41, 0x73, 0x49, 0xae, 0x20, 0x41, 0x31,
0x12, 0xe6, 0xfa, 0x4e, 0x89, 0xa9, 0x7e, 0xa2,
0x0a, 0x9e, 0xee, 0xe6, 0x4b, 0x55, 0xd3, 0x9a,
0x21, 0x92, 0x99, 0x2a, 0x27, 0x4f, 0xc1, 0xa8,
0x36, 0xba, 0x3c, 0x23, 0xa3, 0xfe, 0xeb, 0xbd,
0x45, 0x4d, 0x44, 0x23, 0x64, 0x3c, 0xe8, 0x0e,
0x2a, 0x9a, 0xc9, 0x4f, 0xa5, 0x4c, 0xa4, 0x9f
};
return test_static_sha_common("abc", SHA512_DIGEST_LENGTH, output, &SHA512);
}
int setup_tests(void)
{
ADD_TEST(test_static_sha1);
ADD_TEST(test_static_sha224);
ADD_TEST(test_static_sha256);
ADD_TEST(test_static_sha384);
ADD_TEST(test_static_sha512);
return 1;
}
|
17fe69c30f8526b5f9f3fb61fccf969607d7d08e
|
f8a89dcc018d39eda52f17bd51544837dc4f6ce1
|
/include/PR/os_exception.h
|
2457bdeac725f267274004e321fa7cd2c3f9e293
|
[] |
no_license
|
pret/pokestadium
|
cae99d565ba30a36285ed6a94aefaac992c66540
|
8a192a307d4d0dfa704fc5069c79744995a2fa58
|
refs/heads/master
| 2023-08-15T17:27:07.235493
| 2023-08-15T14:17:38
| 2023-08-15T14:17:38
| 26,101,139
| 113
| 35
| null | 2023-09-04T02:08:44
| 2014-11-03T02:45:35
|
C
|
UTF-8
|
C
| false
| false
| 2,680
|
h
|
os_exception.h
|
/*====================================================================
* os_exception.h
*
* Copyright 1995, Silicon Graphics, Inc.
* All Rights Reserved.
*
* This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics,
* Inc.; the contents of this file may not be disclosed to third
* parties, copied or duplicated in any form, in whole or in part,
* without the prior written permission of Silicon Graphics, Inc.
*
* RESTRICTED RIGHTS LEGEND:
* Use, duplication or disclosure by the Government is subject to
* restrictions as set forth in subdivision (c)(1)(ii) of the Rights
* in Technical Data and Computer Software clause at DFARS
* 252.227-7013, and/or in similar or successor clauses in the FAR,
* DOD or NASA FAR Supplement. Unpublished - rights reserved under the
* Copyright Laws of the United States.
*====================================================================*/
/*---------------------------------------------------------------------*
Copyright (C) 1998 Nintendo. (Originated by SGI)
$RCSfile: os_exception.h,v $
$Revision: 1.1 $
$Date: 1998/10/09 08:01:07 $
*---------------------------------------------------------------------*/
#ifndef _OS_EXCEPTION_H_
#define _OS_EXCEPTION_H_
#ifdef _LANGUAGE_C_PLUS_PLUS
extern "C" {
#endif
#include "ultratypes.h"
#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS)
typedef u32 OSIntMask;
typedef u32 OSHWIntr;
#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */
/* Flags for debugging purpose */
#define OS_FLAG_CPU_BREAK 1 /* Break exception has occurred */
#define OS_FLAG_FAULT 2 /* CPU fault has occurred */
/* Interrupt masks */
#define OS_IM_NONE 0x00000001
#define OS_IM_RCP 0x00000401
#define OS_IM_SW1 0x00000501
#define OS_IM_SW2 0x00000601
#define OS_IM_CART 0x00000c01
#define OS_IM_PRENMI 0x00001401
#define OS_IM_RDBWRITE 0x00002401
#define OS_IM_RDBREAD 0x00004401
#define OS_IM_COUNTER 0x00008401
#define OS_IM_CPU 0x0000ff01
#define OS_IM_SP 0x00010401
#define OS_IM_SI 0x00020401
#define OS_IM_AI 0x00040401
#define OS_IM_VI 0x00080401
#define OS_IM_PI 0x00100401
#define OS_IM_DP 0x00200401
#define OS_IM_ALL 0x003fff01
#define RCP_IMASK 0x003f0000
#define RCP_IMASKSHIFT 16
#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS)
/* Interrupt operations */
extern OSIntMask osGetIntMask(void);
extern OSIntMask osSetIntMask(OSIntMask);
#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */
#ifdef _LANGUAGE_C_PLUS_PLUS
}
#endif
#endif /* !_OS_EXCEPTION_H_ */
|
0b777cee32a1fe40d590d44141d80abdf60d47d6
|
7f6c235b0598353549959c18f69eefd20b766907
|
/libsrc/math/genmath/sqrt.c
|
50061645a0852f1504d305004690861781b97dea
|
[
"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
| 576
|
c
|
sqrt.c
|
#include <math.h>
double sqrt(x)
double x;
{
double extra; /* current approximate root */
char *px; /* points to x */
char *pextra; /* points to extra */
int i; /* loop counter */
if (x == 0.0) return 0.0 ;
if (x < 0.0)
return 0.0 ;
px = &x ;
pextra = &extra ; /* set the pointers */
extra = 0.707 ; /* initialize fraction at sqrt(.5) */
pextra[5] = (px[5]>>1)^64 ; /* answer exponent is half of "x" exponent */
i = 7 ; /* 5 iterations of Newton's algorithm */
while (--i) {
extra += x/extra ;
--pextra[5] ; /* /2 */
}
return extra ;
}
|
288af5ada251202818c8fa283de9b58d55ee66ef
|
7eaf54a78c9e2117247cb2ab6d3a0c20719ba700
|
/SOFTWARE/A64-TERES/linux-a64/arch/sh/kernel/stacktrace.c
|
bf989e063a0cdb8ad27acbf82b6fc4fbf6b3bf39
|
[
"LicenseRef-scancode-free-unknown",
"Apache-2.0",
"Linux-syscall-note",
"GPL-2.0-only",
"GPL-1.0-or-later"
] |
permissive
|
OLIMEX/DIY-LAPTOP
|
ae82f4ee79c641d9aee444db9a75f3f6709afa92
|
a3fafd1309135650bab27f5eafc0c32bc3ca74ee
|
refs/heads/rel3
| 2023-08-04T01:54:19.483792
| 2023-04-03T07:18:12
| 2023-04-03T07:18:12
| 80,094,055
| 507
| 92
|
Apache-2.0
| 2023-04-03T07:05:59
| 2017-01-26T07:25:50
|
C
|
UTF-8
|
C
| false
| false
| 2,180
|
c
|
stacktrace.c
|
/*
* arch/sh/kernel/stacktrace.c
*
* Stack trace management functions
*
* Copyright (C) 2006 - 2008 Paul Mundt
*
* This file is subject to the terms and conditions of the GNU General Public
* License. See the file "COPYING" in the main directory of this archive
* for more details.
*/
#include <linux/sched.h>
#include <linux/stacktrace.h>
#include <linux/thread_info.h>
#include <linux/module.h>
#include <asm/unwinder.h>
#include <asm/ptrace.h>
#include <asm/stacktrace.h>
static int save_stack_stack(void *data, char *name)
{
return 0;
}
/*
* Save stack-backtrace addresses into a stack_trace buffer.
*/
static void save_stack_address(void *data, unsigned long addr, int reliable)
{
struct stack_trace *trace = data;
if (!reliable)
return;
if (trace->skip > 0) {
trace->skip--;
return;
}
if (trace->nr_entries < trace->max_entries)
trace->entries[trace->nr_entries++] = addr;
}
static const struct stacktrace_ops save_stack_ops = {
.stack = save_stack_stack,
.address = save_stack_address,
};
void save_stack_trace(struct stack_trace *trace)
{
unsigned long *sp = (unsigned long *)current_stack_pointer;
unwind_stack(current, NULL, sp, &save_stack_ops, trace);
if (trace->nr_entries < trace->max_entries)
trace->entries[trace->nr_entries++] = ULONG_MAX;
}
EXPORT_SYMBOL_GPL(save_stack_trace);
static void
save_stack_address_nosched(void *data, unsigned long addr, int reliable)
{
struct stack_trace *trace = (struct stack_trace *)data;
if (!reliable)
return;
if (in_sched_functions(addr))
return;
if (trace->skip > 0) {
trace->skip--;
return;
}
if (trace->nr_entries < trace->max_entries)
trace->entries[trace->nr_entries++] = addr;
}
static const struct stacktrace_ops save_stack_ops_nosched = {
.stack = save_stack_stack,
.address = save_stack_address_nosched,
};
void save_stack_trace_tsk(struct task_struct *tsk, struct stack_trace *trace)
{
unsigned long *sp = (unsigned long *)tsk->thread.sp;
unwind_stack(current, NULL, sp, &save_stack_ops_nosched, trace);
if (trace->nr_entries < trace->max_entries)
trace->entries[trace->nr_entries++] = ULONG_MAX;
}
EXPORT_SYMBOL_GPL(save_stack_trace_tsk);
|
f1285969391b26525f86b4757ce45c6ea77ce232
|
94a1ae89fa4fac16b3d2a6c56ca678d6c8af668a
|
/include/ircd/simt/norm.h
|
a20188ed91fba7d75d3e6319baf2a39d7fb6f7e2
|
[
"BSD-3-Clause",
"LicenseRef-scancode-warranty-disclaimer"
] |
permissive
|
matrix-construct/construct
|
99d677d0c2254cac2176d80690bbfd02b18a8658
|
0624b69246878da592d3f5c2c3737ad0b5ff6277
|
refs/heads/master
| 2023-05-28T12:16:23.661446
| 2023-04-28T05:33:46
| 2023-05-01T19:45:37
| 147,328,703
| 356
| 41
|
NOASSERTION
| 2022-07-22T03:45:21
| 2018-09-04T10:26:23
|
C++
|
UTF-8
|
C
| false
| false
| 1,306
|
h
|
norm.h
|
// Matrix Construct
//
// Copyright (C) Matrix Construct Developers, Authors & Contributors
// Copyright (C) 2016-2021 Jason Volk <jason@zemos.net>
//
// 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 is present in all copies. The
// full license for this software is available in the LICENSE file.
#pragma once
#define HAVE_IRCD_SIMT_NORM_H
#ifdef __OPENCL_VERSION__
/// Normalize the input, placing the result in possibly overlapping output.
/// This procedure requires an additional temporary buffer.
inline void
ircd_simt_math_norm_f4lldr(__local float4 *const out,
__local const float4 *const in,
__local float4 *const restrict tmp,
const uint ln,
const uint li)
{
tmp[li] = in[li];
ircd_simt_math_mean_f4lldr(tmp, ln, li);
const float4
sub_mean = in[li] - tmp[li],
sub_mean_sqr = pow(sub_mean, 2);
out[li] = sub_mean_sqr;
ircd_simt_math_mean_f4lldr(out, ln, li);
const float4
epsilon = FLT_EPSILON,
s = native_sqrt(out[li] + epsilon),
res = sub_mean / s;
if(out == in)
barrier(CLK_LOCAL_MEM_FENCE);
out[li] = res;
}
#endif
|
a0bec07b594c482213153c4f9d8b8517a0fbebbf
|
e814383d36a10839104efaa4df277996ab220fa3
|
/opal/mca/btl/self/btl_self_frag.c
|
00f2e62528a9cf71b3df459c99134df95770e190
|
[
"mpich2",
"BSD-3-Clause-Open-MPI"
] |
permissive
|
open-mpi/ompi
|
a1d7483ae1d83dd8fd8ae3ee95e832e0a0ee04e3
|
1edfdb025c4450f694600083ad871cf06c8d45cd
|
refs/heads/main
| 2023-09-01T01:30:02.040705
| 2023-08-29T17:32:18
| 2023-08-29T17:32:18
| 24,107,001
| 2,008
| 973
|
NOASSERTION
| 2023-09-14T20:59:26
| 2014-09-16T16:08:30
|
C
|
UTF-8
|
C
| false
| false
| 2,345
|
c
|
btl_self_frag.c
|
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
/*
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
* University Research and Technology
* Corporation. All rights reserved.
* Copyright (c) 2004-2006 The University of Tennessee and The University
* of Tennessee Research Foundation. All rights
* reserved.
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
* University of Stuttgart. All rights reserved.
* Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 2016 Los Alamos National Security, LLC. All rights
* reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#include "opal_config.h"
#include "btl_self_frag.h"
static inline void mca_btl_self_frag_constructor(mca_btl_self_frag_t *frag)
{
frag->base.des_flags = 0;
frag->segments[0].seg_addr.pval = (void *) frag->data;
frag->segments[0].seg_len = (uint32_t) frag->size;
frag->base.des_segments = frag->segments;
frag->base.des_segment_count = 1;
}
static void mca_btl_self_frag_eager_constructor(mca_btl_self_frag_t *frag)
{
frag->list = &mca_btl_self_component.self_frags_eager;
frag->size = mca_btl_self.btl_eager_limit;
mca_btl_self_frag_constructor(frag);
}
static void mca_btl_self_frag_send_constructor(mca_btl_self_frag_t *frag)
{
frag->list = &mca_btl_self_component.self_frags_send;
frag->size = mca_btl_self.btl_max_send_size;
mca_btl_self_frag_constructor(frag);
}
static void mca_btl_self_frag_rdma_constructor(mca_btl_self_frag_t *frag)
{
frag->list = &mca_btl_self_component.self_frags_rdma;
frag->size = MCA_BTL_SELF_MAX_INLINE_SIZE;
mca_btl_self_frag_constructor(frag);
}
OBJ_CLASS_INSTANCE(mca_btl_self_frag_eager_t, mca_btl_base_descriptor_t,
mca_btl_self_frag_eager_constructor, NULL);
OBJ_CLASS_INSTANCE(mca_btl_self_frag_send_t, mca_btl_base_descriptor_t,
mca_btl_self_frag_send_constructor, NULL);
OBJ_CLASS_INSTANCE(mca_btl_self_frag_rdma_t, mca_btl_base_descriptor_t,
mca_btl_self_frag_rdma_constructor, NULL);
|
0543b1284810ebb77ddb8c4035ea7539b6a55494
|
79d343002bb63a44f8ab0dbac0c9f4ec54078c3a
|
/lib/libc/include/any-linux-any/rdma/ib_user_ioctl_verbs.h
|
3f7fe5a24857d1e4cfd6846c8c314b03434c8338
|
[
"MIT"
] |
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
| 7,914
|
h
|
ib_user_ioctl_verbs.h
|
/* SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR Linux-OpenIB) */
/*
* Copyright (c) 2017-2018, Mellanox Technologies inc. All rights reserved.
*
* This software is available to you under a choice of one of two
* licenses. You may choose to be licensed under the terms of the GNU
* General Public License (GPL) Version 2, available from the file
* COPYING in the main directory of this source tree, or the
* OpenIB.org BSD license below:
*
* 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.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef IB_USER_IOCTL_VERBS_H
#define IB_USER_IOCTL_VERBS_H
#include <linux/types.h>
#include <rdma/ib_user_verbs.h>
#ifndef RDMA_UAPI_PTR
#define RDMA_UAPI_PTR(_type, _name) __aligned_u64 _name
#endif
#define IB_UVERBS_ACCESS_OPTIONAL_FIRST (1 << 20)
#define IB_UVERBS_ACCESS_OPTIONAL_LAST (1 << 29)
enum ib_uverbs_core_support {
IB_UVERBS_CORE_SUPPORT_OPTIONAL_MR_ACCESS = 1 << 0,
};
enum ib_uverbs_access_flags {
IB_UVERBS_ACCESS_LOCAL_WRITE = 1 << 0,
IB_UVERBS_ACCESS_REMOTE_WRITE = 1 << 1,
IB_UVERBS_ACCESS_REMOTE_READ = 1 << 2,
IB_UVERBS_ACCESS_REMOTE_ATOMIC = 1 << 3,
IB_UVERBS_ACCESS_MW_BIND = 1 << 4,
IB_UVERBS_ACCESS_ZERO_BASED = 1 << 5,
IB_UVERBS_ACCESS_ON_DEMAND = 1 << 6,
IB_UVERBS_ACCESS_HUGETLB = 1 << 7,
IB_UVERBS_ACCESS_FLUSH_GLOBAL = 1 << 8,
IB_UVERBS_ACCESS_FLUSH_PERSISTENT = 1 << 9,
IB_UVERBS_ACCESS_RELAXED_ORDERING = IB_UVERBS_ACCESS_OPTIONAL_FIRST,
IB_UVERBS_ACCESS_OPTIONAL_RANGE =
((IB_UVERBS_ACCESS_OPTIONAL_LAST << 1) - 1) &
~(IB_UVERBS_ACCESS_OPTIONAL_FIRST - 1)
};
enum ib_uverbs_srq_type {
IB_UVERBS_SRQT_BASIC,
IB_UVERBS_SRQT_XRC,
IB_UVERBS_SRQT_TM,
};
enum ib_uverbs_wq_type {
IB_UVERBS_WQT_RQ,
};
enum ib_uverbs_wq_flags {
IB_UVERBS_WQ_FLAGS_CVLAN_STRIPPING = 1 << 0,
IB_UVERBS_WQ_FLAGS_SCATTER_FCS = 1 << 1,
IB_UVERBS_WQ_FLAGS_DELAY_DROP = 1 << 2,
IB_UVERBS_WQ_FLAGS_PCI_WRITE_END_PADDING = 1 << 3,
};
enum ib_uverbs_qp_type {
IB_UVERBS_QPT_RC = 2,
IB_UVERBS_QPT_UC,
IB_UVERBS_QPT_UD,
IB_UVERBS_QPT_RAW_PACKET = 8,
IB_UVERBS_QPT_XRC_INI,
IB_UVERBS_QPT_XRC_TGT,
IB_UVERBS_QPT_DRIVER = 0xFF,
};
enum ib_uverbs_qp_create_flags {
IB_UVERBS_QP_CREATE_BLOCK_MULTICAST_LOOPBACK = 1 << 1,
IB_UVERBS_QP_CREATE_SCATTER_FCS = 1 << 8,
IB_UVERBS_QP_CREATE_CVLAN_STRIPPING = 1 << 9,
IB_UVERBS_QP_CREATE_PCI_WRITE_END_PADDING = 1 << 11,
IB_UVERBS_QP_CREATE_SQ_SIG_ALL = 1 << 12,
};
enum ib_uverbs_query_port_cap_flags {
IB_UVERBS_PCF_SM = 1 << 1,
IB_UVERBS_PCF_NOTICE_SUP = 1 << 2,
IB_UVERBS_PCF_TRAP_SUP = 1 << 3,
IB_UVERBS_PCF_OPT_IPD_SUP = 1 << 4,
IB_UVERBS_PCF_AUTO_MIGR_SUP = 1 << 5,
IB_UVERBS_PCF_SL_MAP_SUP = 1 << 6,
IB_UVERBS_PCF_MKEY_NVRAM = 1 << 7,
IB_UVERBS_PCF_PKEY_NVRAM = 1 << 8,
IB_UVERBS_PCF_LED_INFO_SUP = 1 << 9,
IB_UVERBS_PCF_SM_DISABLED = 1 << 10,
IB_UVERBS_PCF_SYS_IMAGE_GUID_SUP = 1 << 11,
IB_UVERBS_PCF_PKEY_SW_EXT_PORT_TRAP_SUP = 1 << 12,
IB_UVERBS_PCF_EXTENDED_SPEEDS_SUP = 1 << 14,
IB_UVERBS_PCF_CM_SUP = 1 << 16,
IB_UVERBS_PCF_SNMP_TUNNEL_SUP = 1 << 17,
IB_UVERBS_PCF_REINIT_SUP = 1 << 18,
IB_UVERBS_PCF_DEVICE_MGMT_SUP = 1 << 19,
IB_UVERBS_PCF_VENDOR_CLASS_SUP = 1 << 20,
IB_UVERBS_PCF_DR_NOTICE_SUP = 1 << 21,
IB_UVERBS_PCF_CAP_MASK_NOTICE_SUP = 1 << 22,
IB_UVERBS_PCF_BOOT_MGMT_SUP = 1 << 23,
IB_UVERBS_PCF_LINK_LATENCY_SUP = 1 << 24,
IB_UVERBS_PCF_CLIENT_REG_SUP = 1 << 25,
/*
* IsOtherLocalChangesNoticeSupported is aliased by IP_BASED_GIDS and
* is inaccessible
*/
IB_UVERBS_PCF_LINK_SPEED_WIDTH_TABLE_SUP = 1 << 27,
IB_UVERBS_PCF_VENDOR_SPECIFIC_MADS_TABLE_SUP = 1 << 28,
IB_UVERBS_PCF_MCAST_PKEY_TRAP_SUPPRESSION_SUP = 1 << 29,
IB_UVERBS_PCF_MCAST_FDB_TOP_SUP = 1 << 30,
IB_UVERBS_PCF_HIERARCHY_INFO_SUP = 1ULL << 31,
/* NOTE this is an internal flag, not an IBA flag */
IB_UVERBS_PCF_IP_BASED_GIDS = 1 << 26,
};
enum ib_uverbs_query_port_flags {
IB_UVERBS_QPF_GRH_REQUIRED = 1 << 0,
};
enum ib_uverbs_flow_action_esp_keymat {
IB_UVERBS_FLOW_ACTION_ESP_KEYMAT_AES_GCM,
};
enum ib_uverbs_flow_action_esp_keymat_aes_gcm_iv_algo {
IB_UVERBS_FLOW_ACTION_IV_ALGO_SEQ,
};
struct ib_uverbs_flow_action_esp_keymat_aes_gcm {
__aligned_u64 iv;
__u32 iv_algo; /* Use enum ib_uverbs_flow_action_esp_keymat_aes_gcm_iv_algo */
__u32 salt;
__u32 icv_len;
__u32 key_len;
__u32 aes_key[256 / 32];
};
enum ib_uverbs_flow_action_esp_replay {
IB_UVERBS_FLOW_ACTION_ESP_REPLAY_NONE,
IB_UVERBS_FLOW_ACTION_ESP_REPLAY_BMP,
};
struct ib_uverbs_flow_action_esp_replay_bmp {
__u32 size;
};
enum ib_uverbs_flow_action_esp_flags {
IB_UVERBS_FLOW_ACTION_ESP_FLAGS_INLINE_CRYPTO = 0UL << 0, /* Default */
IB_UVERBS_FLOW_ACTION_ESP_FLAGS_FULL_OFFLOAD = 1UL << 0,
IB_UVERBS_FLOW_ACTION_ESP_FLAGS_TUNNEL = 0UL << 1, /* Default */
IB_UVERBS_FLOW_ACTION_ESP_FLAGS_TRANSPORT = 1UL << 1,
IB_UVERBS_FLOW_ACTION_ESP_FLAGS_DECRYPT = 0UL << 2, /* Default */
IB_UVERBS_FLOW_ACTION_ESP_FLAGS_ENCRYPT = 1UL << 2,
IB_UVERBS_FLOW_ACTION_ESP_FLAGS_ESN_NEW_WINDOW = 1UL << 3,
};
struct ib_uverbs_flow_action_esp_encap {
/* This struct represents a list of pointers to flow_xxxx_filter that
* encapsulates the payload in ESP tunnel mode.
*/
RDMA_UAPI_PTR(void *, val_ptr); /* pointer to a flow_xxxx_filter */
RDMA_UAPI_PTR(struct ib_uverbs_flow_action_esp_encap *, next_ptr);
__u16 len; /* Len of the filter struct val_ptr points to */
__u16 type; /* Use flow_spec_type enum */
};
struct ib_uverbs_flow_action_esp {
__u32 spi;
__u32 seq;
__u32 tfc_pad;
__u32 flags;
__aligned_u64 hard_limit_pkts;
};
enum ib_uverbs_read_counters_flags {
/* prefer read values from driver cache */
IB_UVERBS_READ_COUNTERS_PREFER_CACHED = 1 << 0,
};
enum ib_uverbs_advise_mr_advice {
IB_UVERBS_ADVISE_MR_ADVICE_PREFETCH,
IB_UVERBS_ADVISE_MR_ADVICE_PREFETCH_WRITE,
IB_UVERBS_ADVISE_MR_ADVICE_PREFETCH_NO_FAULT,
};
enum ib_uverbs_advise_mr_flag {
IB_UVERBS_ADVISE_MR_FLAG_FLUSH = 1 << 0,
};
struct ib_uverbs_query_port_resp_ex {
struct ib_uverbs_query_port_resp legacy_resp;
__u16 port_cap_flags2;
__u8 reserved[6];
};
struct ib_uverbs_qp_cap {
__u32 max_send_wr;
__u32 max_recv_wr;
__u32 max_send_sge;
__u32 max_recv_sge;
__u32 max_inline_data;
};
enum rdma_driver_id {
RDMA_DRIVER_UNKNOWN,
RDMA_DRIVER_MLX5,
RDMA_DRIVER_MLX4,
RDMA_DRIVER_CXGB3,
RDMA_DRIVER_CXGB4,
RDMA_DRIVER_MTHCA,
RDMA_DRIVER_BNXT_RE,
RDMA_DRIVER_OCRDMA,
RDMA_DRIVER_NES,
RDMA_DRIVER_I40IW,
RDMA_DRIVER_IRDMA = RDMA_DRIVER_I40IW,
RDMA_DRIVER_VMW_PVRDMA,
RDMA_DRIVER_QEDR,
RDMA_DRIVER_HNS,
RDMA_DRIVER_USNIC,
RDMA_DRIVER_RXE,
RDMA_DRIVER_HFI1,
RDMA_DRIVER_QIB,
RDMA_DRIVER_EFA,
RDMA_DRIVER_SIW,
RDMA_DRIVER_ERDMA,
RDMA_DRIVER_MANA,
};
enum ib_uverbs_gid_type {
IB_UVERBS_GID_TYPE_IB,
IB_UVERBS_GID_TYPE_ROCE_V1,
IB_UVERBS_GID_TYPE_ROCE_V2,
};
struct ib_uverbs_gid_entry {
__aligned_u64 gid[2];
__u32 gid_index;
__u32 port_num;
__u32 gid_type;
__u32 netdev_ifindex; /* It is 0 if there is no netdev associated with it */
};
#endif
|
4f22ae765a27f43072e8ee6785d71725b2091f36
|
7744859512f027ef0da8b1bde0f8518e631b98eb
|
/soh/assets/scenes/dungeons/ganontika/ganontika_room_13.h
|
1db51803412d9077ad865fdaa2d5bed2102bf8a2
|
[] |
no_license
|
HarbourMasters/Shipwright
|
7f70b9470e4f9a117f3fe2d6e4deb776b8742182
|
0e7c6585239c0d7ea2c039b8b8cb7eaedf8928a9
|
refs/heads/develop
| 2023-08-31T20:50:56.253521
| 2023-08-30T17:34:06
| 2023-08-30T17:34:06
| 472,575,717
| 2,104
| 459
| null | 2023-09-14T20:29:01
| 2022-03-22T01:42:52
|
C
|
UTF-8
|
C
| false
| false
| 2,607
|
h
|
ganontika_room_13.h
|
#pragma once
#include "align_asset_macro.h"
#define dganontika_room_13DL_001260 "__OTR__scenes/nonmq/ganontika_scene/ganontika_room_13DL_001260"
static const ALIGN_ASSET(2) char ganontika_room_13DL_001260[] = dganontika_room_13DL_001260;
#define dganontika_room_13Tex_006B40 "__OTR__scenes/nonmq/ganontika_scene/ganontika_room_13Tex_006B40"
static const ALIGN_ASSET(2) char ganontika_room_13Tex_006B40[] = dganontika_room_13Tex_006B40;
#define dganontika_room_13Tex_006D40 "__OTR__scenes/nonmq/ganontika_scene/ganontika_room_13Tex_006D40"
static const ALIGN_ASSET(2) char ganontika_room_13Tex_006D40[] = dganontika_room_13Tex_006D40;
#define dganontika_room_13Tex_006340 "__OTR__scenes/nonmq/ganontika_scene/ganontika_room_13Tex_006340"
static const ALIGN_ASSET(2) char ganontika_room_13Tex_006340[] = dganontika_room_13Tex_006340;
#define dganontika_room_13Tex_004B40 "__OTR__scenes/nonmq/ganontika_scene/ganontika_room_13Tex_004B40"
static const ALIGN_ASSET(2) char ganontika_room_13Tex_004B40[] = dganontika_room_13Tex_004B40;
#define dganontika_room_13Tex_005B40 "__OTR__scenes/nonmq/ganontika_scene/ganontika_room_13Tex_005B40"
static const ALIGN_ASSET(2) char ganontika_room_13Tex_005B40[] = dganontika_room_13Tex_005B40;
#define dganontika_room_13Tex_004340 "__OTR__scenes/nonmq/ganontika_scene/ganontika_room_13Tex_004340"
static const ALIGN_ASSET(2) char ganontika_room_13Tex_004340[] = dganontika_room_13Tex_004340;
#define dganontika_room_13DL_0024F8 "__OTR__scenes/nonmq/ganontika_scene/ganontika_room_13DL_0024F8"
static const ALIGN_ASSET(2) char ganontika_room_13DL_0024F8[] = dganontika_room_13DL_0024F8;
#define dganontika_room_13Tex_005340 "__OTR__scenes/nonmq/ganontika_scene/ganontika_room_13Tex_005340"
static const ALIGN_ASSET(2) char ganontika_room_13Tex_005340[] = dganontika_room_13Tex_005340;
#define dganontika_room_13DL_002CF0 "__OTR__scenes/nonmq/ganontika_scene/ganontika_room_13DL_002CF0"
static const ALIGN_ASSET(2) char ganontika_room_13DL_002CF0[] = dganontika_room_13DL_002CF0;
#define dganontika_room_13DL_003470 "__OTR__scenes/nonmq/ganontika_scene/ganontika_room_13DL_003470"
static const ALIGN_ASSET(2) char ganontika_room_13DL_003470[] = dganontika_room_13DL_003470;
#define dganontika_room_13DL_003C80 "__OTR__scenes/nonmq/ganontika_scene/ganontika_room_13DL_003C80"
static const ALIGN_ASSET(2) char ganontika_room_13DL_003C80[] = dganontika_room_13DL_003C80;
#define dganontika_room_13DL_004170 "__OTR__scenes/nonmq/ganontika_scene/ganontika_room_13DL_004170"
static const ALIGN_ASSET(2) char ganontika_room_13DL_004170[] = dganontika_room_13DL_004170;
|
927b579959b69c63ba1c303dcb74e309d089aedd
|
64f63e6468d7d1a8239ca8a60cb3a57671d7026e
|
/src/loadcore/interruptController.h
|
179db91218820a663eb8fc4067f194be72bcef4a
|
[
"BSD-3-Clause",
"MIT"
] |
permissive
|
uofw/uofw
|
511c6877af464a4c18cd62405805ed92b15b39c3
|
c517e4cee6679cf2c0ecb24afaa50a86c6460cf1
|
refs/heads/master
| 2023-02-09T17:10:03.719610
| 2023-02-03T13:11:50
| 2023-02-03T13:11:50
| 6,622,246
| 312
| 93
|
NOASSERTION
| 2023-09-05T19:54:15
| 2012-11-09T23:39:19
|
C
|
UTF-8
|
C
| false
| false
| 302
|
h
|
interruptController.h
|
/* Copyright (C) 2011, 2012 The uOFW team
See the file COPYING for copying permission.
*/
#ifndef INTERRUPTCONTROLLER_H
#define INTERRUPTCONTROLLER_H
s32 loadCoreCpuSuspendIntr(void);
void loadCoreCpuResumeIntr(s32 intr);
void sub_00003D84(void);
#endif /* INTERRUPTCONTROLLER_H */
|
e28bcc2460c79b6b42e3fdd7395066fb46800af9
|
95ae7dfa9ee578f1b24a65986ff78bf77ceca0c5
|
/Engine/lib/curl/tests/unit/unit1398.c
|
f68e43ecfa6448094c674d3f28eabcb589fd2abf
|
[
"curl",
"MIT",
"LicenseRef-scancode-unknown"
] |
permissive
|
TorqueGameEngines/Torque3D
|
4e1f6a05cc0928980c8c7c20bcdd680eaa6dcee8
|
a445a4364664e299196bd551d213844486080145
|
refs/heads/development
| 2023-09-03T12:40:40.658487
| 2023-08-24T14:44:43
| 2023-08-24T14:44:43
| 267,440,108
| 1,192
| 178
|
MIT
| 2023-09-13T14:28:16
| 2020-05-27T22:35:54
|
C++
|
UTF-8
|
C
| false
| false
| 3,220
|
c
|
unit1398.c
|
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2022, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "curlcheck.h"
#include "curl/mprintf.h"
static CURLcode unit_setup(void) {return CURLE_OK;}
static void unit_stop(void) {}
UNITTEST_START
int rc;
char buf[3] = {'b', 'u', 'g'};
const char *str = "bug";
int width = 3;
char output[24];
/*#define curl_msnprintf snprintf */
/* without a trailing zero */
rc = curl_msnprintf(output, 4, "%.*s", width, buf);
fail_unless(rc == 3, "return code should be 3");
fail_unless(!strcmp(output, "bug"), "wrong output");
/* with a trailing zero */
rc = curl_msnprintf(output, 4, "%.*s", width, str);
fail_unless(rc == 3, "return code should be 3");
fail_unless(!strcmp(output, "bug"), "wrong output");
width = 2;
/* one byte less */
rc = curl_msnprintf(output, 4, "%.*s", width, buf);
fail_unless(rc == 2, "return code should be 2");
fail_unless(!strcmp(output, "bu"), "wrong output");
/* string with larger precision */
rc = curl_msnprintf(output, 8, "%.8s", str);
fail_unless(rc == 3, "return code should be 3");
fail_unless(!strcmp(output, "bug"), "wrong output");
/* longer string with precision */
rc = curl_msnprintf(output, 8, "%.3s", "0123456789");
fail_unless(rc == 3, "return code should be 3");
fail_unless(!strcmp(output, "012"), "wrong output");
/* negative width */
rc = curl_msnprintf(output, 8, "%-8s", str);
fail_unless(rc == 7, "return code should be 7");
fail_unless(!strcmp(output, "bug "), "wrong output");
/* larger width that string length */
rc = curl_msnprintf(output, 8, "%8s", str);
fail_unless(rc == 7, "return code should be 7");
fail_unless(!strcmp(output, " bu"), "wrong output");
/* output a number in a limited output */
rc = curl_msnprintf(output, 4, "%d", 10240);
fail_unless(rc == 3, "return code should be 3");
fail_unless(!strcmp(output, "102"), "wrong output");
/* padded strings */
rc = curl_msnprintf(output, 16, "%8s%8s", str, str);
fail_unless(rc == 15, "return code should be 15");
fail_unless(!strcmp(output, " bug bu"), "wrong output");
/* padded numbers */
rc = curl_msnprintf(output, 16, "%8d%8d", 1234, 5678);
fail_unless(rc == 15, "return code should be 15");
fail_unless(!strcmp(output, " 1234 567"), "wrong output");
UNITTEST_STOP
|
558594630aa79333316be0d4b6be8f6e29cd6cc8
|
52c8ed39b32ccc7c0673278c1adea3638797c9ff
|
/src/lib/libc/stdio/fclose.c
|
fa82359355ba26bac16ab6e78f2683809125a860
|
[
"MIT"
] |
permissive
|
xboot/xboot
|
0cab7b440b612aa0a4c366025598a53a7ec3adf1
|
6d6b93947b7fcb8c3924fedb0715c23877eedd5e
|
refs/heads/master
| 2023-08-20T05:56:25.149388
| 2023-07-12T07:38:29
| 2023-07-12T07:38:29
| 471,539
| 765
| 296
|
MIT
| 2023-05-25T09:39:01
| 2010-01-14T08:25:12
|
C
|
UTF-8
|
C
| false
| false
| 471
|
c
|
fclose.c
|
/*
* libc/stdio/fclose.c
*/
#include <errno.h>
#include <malloc.h>
#include <stdio.h>
#include <xboot/module.h>
int fclose(FILE * f)
{
int err;
if(!f)
return EINVAL;
if(!f->close)
return EINVAL;
if((err = f->rwflush(f)))
return err;
if((err = f->close(f)))
return err;
if(f->fifo_read)
fifo_free(f->fifo_read);
if(f->fifo_write)
fifo_free(f->fifo_write);
if(f->buf)
free(f->buf);
if(f)
free(f);
return err;
}
EXPORT_SYMBOL(fclose);
|
f3249229b844c43c903b8e37630adba6c7647906
|
085242ce442d9d4ad0cf6df9464b3b35e54bbe4c
|
/src/common/ponyassert.h
|
b3e92ba9d148726a19e029e6b56dc37761876284
|
[
"LicenseRef-scancode-unknown-license-reference",
"BSD-2-Clause"
] |
permissive
|
ponylang/ponyc
|
4c0a0b4a138b4213b4d67424ed313f322d17a87a
|
c393500e8f8222d648f803f78a705baf452bce05
|
refs/heads/main
| 2023-08-19T03:26:37.611328
| 2023-08-18T13:22:12
| 2023-08-18T14:27:49
| 6,667,084
| 4,901
| 572
|
BSD-2-Clause
| 2023-09-12T18:17:34
| 2012-11-13T07:38:25
|
C
|
UTF-8
|
C
| false
| false
| 570
|
h
|
ponyassert.h
|
#ifndef PLATFORM_PONYASSERT_H
#define PLATFORM_PONYASSERT_H
#include "platform.h"
PONY_EXTERN_C_BEGIN
#if !defined(PONY_NDEBUG) && !defined(PONY_ALWAYS_ASSERT) && defined(NDEBUG)
# define PONY_NDEBUG
#endif
#if defined(PONY_NDEBUG)
# define pony_assert(expr) ((void)0)
#else
# define pony_assert(expr) \
((expr) ? (void)0 : \
ponyint_assert_fail(#expr, __FILE__, __LINE__, __func__))
#endif
void ponyint_assert_fail(const char* expr, const char* file, size_t line,
const char* func);
void ponyint_assert_disable_popups();
PONY_EXTERN_C_END
#endif
|
a4b364816a6e2d53fc1c45d4ca64cad654135a28
|
28d0f8c01599f8f6c711bdde0b59f9c2cd221203
|
/sys/arch/hpcarm/include/signal.h
|
0e718f42821d8c6c2d244dbfe63ec48531b612a0
|
[] |
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
| 88
|
h
|
signal.h
|
/* $NetBSD: signal.h,v 1.1 2001/02/23 03:48:19 ichiro Exp $ */
#include <arm/signal.h>
|
24c15ecaaf8a4a9c95bc9a27364024f54c1b7e1f
|
aa3befea459382dc5c01c925653d54f435b3fb0f
|
/arch/renesas/include/sh1/irq.h
|
6ce374cf68078671f59898fc17755f3ee7fe31bc
|
[
"MIT-open-group",
"BSD-3-Clause",
"HPND-sell-variant",
"BSD-4-Clause-UC",
"LicenseRef-scancode-warranty-disclaimer",
"MIT-0",
"LicenseRef-scancode-bsd-atmel",
"LicenseRef-scancode-gary-s-brown",
"LicenseRef-scancode-proprietary-license",
"SunPro",
"MIT",
"LicenseRef-scancode-public-domain-disclaimer",
"LicenseRef-scancode-other-permissive",
"HPND",
"ISC",
"Apache-2.0",
"LicenseRef-scancode-public-domain",
"BSD-2-Clause",
"GPL-1.0-or-later",
"CC-BY-2.0",
"CC-BY-4.0"
] |
permissive
|
apache/nuttx
|
14519a7bff4a87935d94fb8fb2b19edb501c7cec
|
606b6d9310fb25c7d92c6f95bf61737e3c79fa0f
|
refs/heads/master
| 2023-08-25T06:55:45.822534
| 2023-08-23T16:03:31
| 2023-08-24T21:25:47
| 228,103,273
| 407
| 241
|
Apache-2.0
| 2023-09-14T18:26:05
| 2019-12-14T23:27:55
|
C
|
UTF-8
|
C
| false
| false
| 22,221
|
h
|
irq.h
|
/****************************************************************************
* arch/renesas/include/sh1/irq.h
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/* This file should never be included directly but, rather,
* only indirectly through nuttx/irq.h
*/
#ifndef __ARCH_RENESAS_INCLUDE_SH1_IRQ_H
#define __ARCH_RENESAS_INCLUDE_SH1_IRQ_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdint.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* IRQ channels */
/* In the current implementation, CMON catches the following IRQ.
* Support for traps can be provided by simply enabling the following, adding
* vectors in sh1_head.S and adding handlers in sh1_vector.S
*/
/* Illegal instructions / Address errors */
#if 0 /* Handled by CMON */
# define SH1_INVINSTR_IRQ (0) /* General invalid instruction */
# define SH1_INVSLOT_IRQ (1) /* Invalid slot instruction */
# define SH1_BUSERR_IRQ (2) /* CPU bus error */
# define SH1_DMAERR_IRQ (3) /* DMA bus error */
# define SH1_NMI_IRQ (4) /* NMI */
# define SH1_USRBRK_IRQ (6) /* User break */
# define SH1_TRAP_IRQBASE (7)
# define SH1_TRAP0_IRQ SH1_TRAP_IRQBASE /* TRAPA instruction (user break) */
# define SH1_TRAP1_IRQ (SH1_TRAP_IRQBASE+1) /* " " " " " " " " */
# define SH1_TRAP2_IRQ (SH1_TRAP_IRQBASE+2) /* " " " " " " " " */
# define SH1_TRAP3_IRQ (SH1_TRAP_IRQBASE+3) /* " " " " " " " " */
# define SH1_TRAP4_IRQ (SH1_TRAP_IRQBASE+4) /* " " " " " " " " */
# define SH1_TRAP5_IRQ (SH1_TRAP_IRQBASE+5) /* " " " " " " " " */
# define SH1_TRAP6_IRQ (SH1_TRAP_IRQBASE+6) /* " " " " " " " " */
# define SH1_TRAP7_IRQ (SH1_TRAP_IRQBASE+7) /* " " " " " " " " */
# define SH1_TRAP8_IRQ (SH1_TRAP_IRQBASE+8) /* " " " " " " " " */
# define SH1_TRAP9_IRQ (SH1_TRAP_IRQBASE+9) /* " " " " " " " " */
# define SH1_TRAP10_IRQ (SH1_TRAP_IRQBASE+10) /* " " " " " " " " */
# define SH1_TRAP11_IRQ (SH1_TRAP_IRQBASE+11) /* " " " " " " " " */
# define SH1_TRAP12_IRQ (SH1_TRAP_IRQBASE+12) /* " " " " " " " " */
# define SH1_TRAP13_IRQ (SH1_TRAP_IRQBASE+13) /* " " " " " " " " */
# define SH1_TRAP14_IRQ (SH1_TRAP_IRQBASE+14) /* " " " " " " " " */
# define SH1_TRAP15_IRQ (SH1_TRAP_IRQBASE+15) /* " " " " " " " " */
# define SH1_TRAP16_IRQ (SH1_TRAP_IRQBASE+16) /* " " " " " " " " */
# define SH1_TRAP17_IRQ (SH1_TRAP_IRQBASE+17) /* " " " " " " " " */
# define SH1_TRAP18_IRQ (SH1_TRAP_IRQBASE+18) /* " " " " " " " " */
# define SH1_TRAP19_IRQ (SH1_TRAP_IRQBASE+19) /* " " " " " " " " */
# define SH1_TRAP20_IRQ (SH1_TRAP_IRQBASE+20) /* " " " " " " " " */
# define SH1_TRAP21_IRQ (SH1_TRAP_IRQBASE+21) /* " " " " " " " " */
# define SH1_TRAP22_IRQ (SH1_TRAP_IRQBASE+22) /* " " " " " " " " */
# define SH1_TRAP23_IRQ (SH1_TRAP_IRQBASE+23) /* " " " " " " " " */
# define SH1_TRAP24_IRQ (SH1_TRAP_IRQBASE+24) /* " " " " " " " " */
# define SH1_TRAP25_IRQ (SH1_TRAP_IRQBASE+25) /* " " " " " " " " */
# define SH1_TRAP26_IRQ (SH1_TRAP_IRQBASE+26) /* " " " " " " " " */
# define SH1_TRAP27_IRQ (SH1_TRAP_IRQBASE+27) /* " " " " " " " " */
# define SH1_TRAP28_IRQ (SH1_TRAP_IRQBASE+28) /* " " " " " " " " */
# define SH1_TRAP29_IRQ (SH1_TRAP_IRQBASE+29) /* " " " " " " " " */
# define SH1_TRAP30_IRQ (SH1_TRAP_IRQBASE+30) /* " " " " " " " " */
# define SH1_TRAP31_IRQ (SH1_TRAP_IRQBASE+31) /* " " " " " " " " */
# define SH1_IRQ_IRQBASE (SH1_TRAP_IRQBASE+32)
/* Interrupts */
# define SH1_IRQ0_IRQ SH1_IRQ_IRQBASE /* IRQ0 */
# define SH1_IRQ1_IRQ (SH1_IRQ_IRQBASE+1) /* IRQ1 */
# define SH1_IRQ2_IRQ (SH1_IRQ_IRQBASE+2) /* IRQ2 */
# define SH1_IRQ3_IRQ (SH1_IRQ_IRQBASE+3) /* IRQ3 */
# define SH1_IRQ4_IRQ (SH1_IRQ_IRQBASE+4) /* IRQ4 */
# define SH1_IRQ5_IRQ (SH1_IRQ_IRQBASE+5) /* IRQ5 */
# define SH1_IRQ6_IRQ (SH1_IRQ_IRQBASE+6) /* IRQ6 */
# define SH1_IRQ7_IRQ (SH1_IRQ_IRQBASE+7) /* IRQ7 */
# define SH1_CHIP_IRQBASE (SH1_IRQ_IRQBASE+8)
#else
# define SH1_CHIP_IRQBASE (0)
#endif
/* On-chip modules -- The following may be unique to the 7032 */
#ifdef CONFIG_ARCH_CHIP_SH7032
/* DMAC */
#ifdef CONFIG_SH1_DMAC0 /* DMAC0 */
# define SH1_DEI0_IRQ SH1_CHIP_IRQBASE /* DEI0 */
# define SH1_DMAC1_IRQBASE (SH1_CHIP_IRQBASE+1)
#else
# define SH1_DMAC1_IRQBASE SH1_CHIP_IRQBASE
#endif
#ifdef CONFIG_SH1_DMAC1 /* DMAC1 */
# define SH1_DEI1_IRQ SH1_DMAC1_IRQBASE /* DEI1 */
# define SH1_DMAC2_IRQBASE (SH1_DMAC1_IRQBASE+1)
#else
# define SH1_DMAC2_IRQBASE SH1_DMAC1_IRQBASE
#endif
#ifdef CONFIG_SH1_DMAC2 /* DMAC2 */
# define SH1_DEI2_IRQ SH1_DMAC2_IRQBASE /* DEI2 */
# define SH1_DMAC3_IRQBASE (SH1_DMAC2_IRQBASE+1)
#else
# define SH1_DMAC3_IRQBASE SH1_DMAC2_IRQBASE
#endif
#ifdef CONFIG_SH1_DMAC3 /* DMAC3 */
# define SH1_DEI3_IRQ SH1_DMAC3_IRQBASE /* DEI3 */
# define SH1_ITU0_IRQBASE (SH1_DMAC3_IRQBASE+1)
#else
# define SH1_ITU0_IRQBASE SH1_DMAC3_IRQBASE
#endif
/* ITU */
/* ITU0 is the system clock and is always defined */
#define SH1_IMIA0_IRQ SH1_ITU0_IRQBASE /* IMIA0 */
#define SH1_IMIB0_IRQ (SH1_ITU0_IRQBASE+1) /* IMIB0 */
#define SH1_OVI0_IRQ (SH1_ITU0_IRQBASE+2) /* OVI0 */
#define SH1_ITU1_IRQBASE (SH1_ITU0_IRQBASE+3)
#ifdef CONFIG_SH1_ITU1 /* ITU1 */
# define SH1_IMIA1_IRQ SH1_ITU1_IRQBASE /* IMIA1 */
# define SH1_IMIB1_IRQ (SH1_ITU1_IRQBASE+1) /* IMIB1 */
# define SH1_OVI1_IRQ (SH1_ITU1_IRQBASE+2) /* OVI1 */
# define SH1_ITU2_IRQBASE (SH1_ITU1_IRQBASE+3)
#else
# define SH1_ITU2_IRQBASE SH1_ITU1_IRQBASE
#endif
#ifdef CONFIG_SH1_ITU2 /* ITU2 */
# define SH1_IMIA2_IRQ SH1_ITU2_IRQBASE /* IMIA2 */
# define SH1_IMIB2_IRQ (SH1_ITU2_IRQBASE+1) /* IMIB2 */
# define SH1_OVI2_IRQ (SH1_ITU2_IRQBASE+2) /* OVI2 */
# define SH1_ITU3_IRQBASE (SH1_ITU2_IRQBASE+3)
#else
# define SH1_ITU3_IRQBASE SH1_ITU2_IRQBASE
#endif
#ifdef CONFIG_SH1_ITU3 /* ITU3 */
# define SH1_IMIA3_IRQ SH1_ITU3_IRQBASE /* IMIA3 */
# define SH1_IMIB3_IRQ (SH1_ITU3_IRQBASE+1) /* IMIB3 */
# define SH1_OVI3_IRQ (SH1_ITU3_IRQBASE+2) /* OVI3 */
# define SH1_ITU4_IRQBASE (SH1_ITU3_IRQBASE+3)
#else
# define SH1_ITU4_IRQBASE SH1_ITU3_IRQBASE
#endif
#ifdef CONFIG_SH1_ITU4 /* ITU4 */
# define SH1_IMIA4_IRQ SH1_ITU4_IRQBASE /* IMIA4 */
# define SH1_IMIB4_IRQ (SH1_ITU4_IRQBASE+1) /* IMIB4 */
# define SH1_OVI4_IRQ (SH1_ITU4_IRQBASE+2) /* OVI4 */
# define SH1_SCI0_IRQBASE (SH1_ITU4_IRQBASE+3)
#else
# define SH1_SCI0_IRQBASE SH1_ITU4_IRQBASE
#endif
/* SCI */
#define SH1_ERI_IRQ_OFFSET (0) /* ERI0 */
#define SH1_RXI_IRQ_OFFSET (1) /* RxI0 */
#define SH1_TXI_IRQ_OFFSET (2) /* TxI0 */
#define SH1_TEI_IRQ_OFFSET (3) /* TEI0 */
#define SH1_SCI_NIRQS (4)
#ifdef CONFIG_SH1_SCI0 /* SCI0 */
# define SH1_ERI0_IRQ (SH1_SCI0_IRQBASE+SH1_ERI_IRQ_OFFSET) /* ERI0 */
# define SH1_RXI0_IRQ (SH1_SCI0_IRQBASE+SH1_RXI_IRQ_OFFSET) /* RxI0 */
# define SH1_TXI0_IRQ (SH1_SCI0_IRQBASE+SH1_TXI_IRQ_OFFSET) /* TxI0 */
# define SH1_TEI0_IRQ (SH1_SCI0_IRQBASE+SH1_TEI_IRQ_OFFSET) /* TEI0 */
# define SH1_SCI1_IRQBASE (SH1_SCI0_IRQBASE+SH1_SCI_NIRQS)
#else
# define SH1_SCI1_IRQBASE SH1_SCI0_IRQBASE
#endif
#ifdef CONFIG_SH1_SCI1 /* SCI1 */
# define SH1_ERI1_IRQ (SH1_SCI1_IRQBASE+SH1_ERI_IRQ_OFFSET) /* ERI1 */
# define SH1_RXI1_IRQ (SH1_SCI1_IRQBASE+SH1_RXI_IRQ_OFFSET) /* RxI1 */
# define SH1_TXI1_IRQ (SH1_SCI1_IRQBASE+SH1_TXI_IRQ_OFFSET) /* TxI1 */
# define SH1_TEI1_IRQ (SH1_SCI1_IRQBASE+SH1_TEI_IRQ_OFFSET) /* TEI1 */
# define SH1_PEI_IRQBASE (SH1_SCI1_IRQBASE+SH1_SCI_NIRQS)
#else
# define SH1_PEI_IRQBASE SH1_SCI1_IRQBASE
#endif
#ifdef CONFIG_SH1_PCU
# define SH1_PEI_IRQ SH1_PEI_IRQBASE /* Parity control unit PEI */
# define SH1_AD_IRQBASE (SH1_PEI_IRQBASE+1)
#else
# define SH1_AD_IRQBASE SH1_PEI_IRQBASE
#endif
#ifdef CONFIG_SH1_AD
# define SH1_ADITI_IRQ SH1_AD_IRQBASE /* A/D ITI */
# define SH1_WDT_IRQBASE (SH1_AD_IRQBASE+1)
#else
# define SH1_WDT_IRQBASE SH1_AD_IRQBASE
#endif
#ifdef CONFIG_SH1_WDT
# define SH1_WDTITI_IRQ SH1_WDT_IRQBASE /* WDT ITI */
# define SH1_CMI_IRQBASE (SH1_WDT_IRQBASE+1)
#else
# define SH1_CMI_IRQBASE SH1_WDT_IRQBASE
#endif
#ifdef CONFIG_SH1_CMI
# define SH1_CMI_IRQ SH1_CMI_IRQBASE /* REF CMI */
# define NR_IRQS (SH1_CMI_IRQBASE+1) /* Total number of supported IRQs */
#else
# define NR_IRQS SH1_CMI_IRQBASE /* Total number of supported IRQs */
#endif
#define SH1_SYSTIMER_IRQ SH1_IMIA0_IRQ
#endif
/* Vector table offsets *****************************************************/
/* The following provides the vector numbers for each IRQ.
* The IRQ numbers (above) form the densely packet number space used by the
* system to identify IRQs. The following are the (relatively) loosely
* spaced offsets that identify the location of the corresponding vector
* in the vector table.
*
* These offsets are specified as a vector number (suitably for indexing
* an array of uint32_t) but would have to by multiplied by 4 to get
* an addressable, byte offset.
*/
/* Resets */
#define SH1_PWRONPC_VNDX (0) /* 0: Power-on reset (hard, NMI high) PC*/
#define SH1_PWRONSP_VNDX (1) /* 1: Power-on reset (hard, NMI high) SP */
#define SH1_MRESETPC_VNDX (2) /* 2: Power-on reset (hard, NMI high) PC*/
#define SH1_MRESETSP_VNDX (3) /* 3: Power-on reset (hard, NMI high) SP */
/* Illegal instructions / Address errors */
#define SH1_INVINSTR_VNDX (4) /* 4: General invalid instruction */
/* 5: Reserved for system */
#define SH1_INVSLOT_VNDX (6) /* 6: Invalid slot instruction */
/* 7-8: Reserved for system */
#define SH1_BUSERR_VNDX (9) /* 9: CPU bus error */
#define SH1_DMAERR_VNDX (10) /* 10: DMA bus error */
/* NMI, user break */
#define SH1_NMI_VNDX (11) /* 11: NMI */
#define SH1_USRBRK_VNDX (12) /* 12: User break */
/* 13-31: Reserved for system */
/* Trap instruction */
#define SH1_TRAP_VNDX (32) /* 32-63: TRAPA instruction (user break) */
#define SH1_TRAP0_VNDX (32) /* 32: TRAPA instruction (user break) */
#define SH1_TRAP1_VNDX (33) /* 33: " " " " " " " " */
#define SH1_TRAP2_VNDX (34) /* 34: " " " " " " " " */
#define SH1_TRAP3_VNDX (35) /* 35: " " " " " " " " */
#define SH1_TRAP4_VNDX (36) /* 36: " " " " " " " " */
#define SH1_TRAP5_VNDX (37) /* 37: " " " " " " " " */
#define SH1_TRAP6_VNDX (38) /* 38: " " " " " " " " */
#define SH1_TRAP7_VNDX (39) /* 39: " " " " " " " " */
#define SH1_TRAP8_VNDX (40) /* 40: " " " " " " " " */
#define SH1_TRAP9_VNDX (41) /* 41: " " " " " " " " */
#define SH1_TRAP10_VNDX (42) /* 42: " " " " " " " " */
#define SH1_TRAP11_VNDX (43) /* 43: " " " " " " " " */
#define SH1_TRAP12_VNDX (44) /* 44: " " " " " " " " */
#define SH1_TRAP13_VNDX (45) /* 45: " " " " " " " " */
#define SH1_TRAP14_VNDX (46) /* 46: " " " " " " " " */
#define SH1_TRAP15_VNDX (47) /* 47: " " " " " " " " */
#define SH1_TRAP16_VNDX (48) /* 48: " " " " " " " " */
#define SH1_TRAP17_VNDX (49) /* 49: " " " " " " " " */
#define SH1_TRAP18_VNDX (50) /* 50: " " " " " " " " */
#define SH1_TRAP19_VNDX (51) /* 51: " " " " " " " " */
#define SH1_TRAP20_VNDX (52) /* 52: " " " " " " " " */
#define SH1_TRAP21_VNDX (53) /* 53: " " " " " " " " */
#define SH1_TRAP22_VNDX (54) /* 54: " " " " " " " " */
#define SH1_TRAP23_VNDX (55) /* 55: " " " " " " " " */
#define SH1_TRAP24_VNDX (56) /* 56: " " " " " " " " */
#define SH1_TRAP25_VNDX (57) /* 57: " " " " " " " " */
#define SH1_TRAP26_VNDX (58) /* 58: " " " " " " " " */
#define SH1_TRAP27_VNDX (59) /* 59: " " " " " " " " */
#define SH1_TRAP28_VNDX (60) /* 60: " " " " " " " " */
#define SH1_TRAP29_VNDX (61) /* 61: " " " " " " " " */
#define SH1_TRAP30_VNDX (62) /* 62: " " " " " " " " */
#define SH1_TRAP31_VNDX (63) /* 63: " " " " " " " " */
/* Interrupts */
#define SH1_IRQ_VNDX (64) /* 64-71: IRQ0-7 */
#define SH1_IRQ0_VNDX (64) /* 64: IRQ0 */
#define SH1_IRQ1_VNDX (65) /* 65: IRQ1 */
#define SH1_IRQ2_VNDX (66) /* 66: IRQ2 */
#define SH1_IRQ3_VNDX (67) /* 67: IRQ3 */
#define SH1_IRQ4_VNDX (68) /* 68: IRQ4 */
#define SH1_IRQ5_VNDX (69) /* 69: IRQ5 */
#define SH1_IRQ6_VNDX (70) /* 70: IRQ6 */
#define SH1_IRQ7_VNDX (71) /* 71: IRQ7 */
#define SH1_LASTCMN_VNDX (71)
#define SH1_NCMN_VECTORS (72)
/* On-chip modules -- The following may be unique to the 7032 */
#ifdef CONFIG_ARCH_CHIP_SH7032
/* DMAC */
#define SH1_DMAC0_VNDX (72) /* 72-73: DMAC0 */
#define SH1_DEI0_VNDX (72) /* 72: DMAC0 DEI0 */
/* 73: Reserved */
#define SH1_DMAC1_VNDX (74) /* 74-75: DMAC1 */
#define SH1_DEI1_VNDX (74) /* 74: DMAC1 DEI1 */
/* 75: Reserved */
#define SH1_DMAC2_VNDX (76) /* 76-77: DMAC2 */
#define SH1_DEI2_VNDX (76) /* 76: DMAC2 DEI2 */
/* 77: Reserved */
#define SH1_DMAC3_VNDX (78) /* 78-79: DMAC3 */
#define SH1_DEI3_VNDX (78) /* 78: DMAC3 DEI3 */
/* 79: Reserved */
/* ITU */
#define SH1_IMIA0_VNDX (80) /* 80: ITU0 IMIA0 */
#define SH1_IMIB0_VNDX (81) /* 81: IMIB0 */
#define SH1_OVI0_VNDX (82) /* 82: OVI0 */
/* 83: Reserved */
#define SH1_IMIA1_VNDX (84) /* 84: ITU1 IMIA1 */
#define SH1_IMIB1_VNDX (85) /* 85: IMIB1 */
#define SH1_OVI1_VNDX (86) /* 86: OVI1 */
/* 87: Reserved */
#define SH1_IMIA2_VNDX (88) /* 88: ITU2 IMIA2 */
#define SH1_IMIB2_VNDX (89) /* 89: IMIB2 */
#define SH1_OVI2_VNDX (90) /* 90: OVI2 */
/* 91: Reserved */
#define SH1_IMIA3_VNDX (92) /* 92: ITU3 IMIA3 */
#define SH1_IMIB3_VNDX (93) /* 93: IMIB3 */
#define SH1_OVI3_VNDX (94) /* 94: OVI3 */
/* 95: Reserved */
#define SH1_IMIA4_VNDX (96) /* 96: ITU4 IMIA4 */
#define SH1_IMIB4_VNDX (97) /* 97: IMIB4 */
#define SH1_OVI4_VNDX (98) /* 98: OVI4 */
/* 99: Reserved */
/* SCI */
#define SH1_ERI0_VNDX (100) /* 100: SCI0 ERI0 */
#define SH1_RXI0_VNDX (101) /* 101: RxI0 */
#define SH1_TXI0_VNDX (102) /* 102: TxI0 */
#define SH1_TEI0_VNDX (103) /* 103: TEI0 */
#define SH1_ERI1_VNDX (104) /* 104: SCI1 ERI1 */
#define SH1_RXI1_VNDX (105) /* 105: RxI1 */
#define SH1_TXI1_VNDX (106) /* 106: TxI1 */
#define SH1_TEI1_VNDX (107) /* 107: TEI1 */
#define SH1_PEI_VNDX (108) /* 108: Parity control unit PEI */
#define SH1_ADITI_VNDX (109) /* 109: A/D ITI */
/* 110-111: Reserved */
#define SH1_WDTITI_VNDX (112) /* 112: WDT ITI */
#define SH1_CMI_VNDX (113) /* 113: REF CMI */
/* 114-115: Reserved */
/* 116-255 reserved */
#endif
#define SH1_LAST_VNDX (255)
#define SH1_NVECTORS (256)
/* IRQ Stack Frame Format. The SH-1 has a push down stack.
* The PC and SR are pushed by hardware at the time an IRQ is taken.
*/
/* Saved to the stacked by up_vector */
#define REG_R8 (0)
#define REG_R9 (1)
#define REG_R10 (2)
#define REG_R11 (3)
#define REG_R12 (4)
#define REG_R13 (5)
#define REG_R14 (6)
#define REG_PR (7)
#define REG_GBR (8)
/* The value of the stack pointer *before* the interrupt occurred */
#define REG_R15 (9)
#define REG_SP REG_R15
/* These registers do not need to be preserved by up_saveusercontext */
#define REG_MACL (10)
#define REG_MACH (11)
#define REG_R0 (12)
#define REG_R1 (13)
#define REG_R2 (14)
#define REG_R3 (15)
#define REG_R5 (16)
#define REG_R6 (17)
#define REG_R7 (18)
/* Saved to the stack by the trampoline logic */
#define REG_R4 (19)
/* Pushed by hardware when the exception is taken */
#define REG_PC (20)
#define REG_SR (21)
#define XCPTCONTEXT_REGS (22)
#define XCPTCONTEXT_SIZE (4 * XCPTCONTEXT_REGS)
/****************************************************************************
* Public Types
****************************************************************************/
/* This struct defines the way the registers are stored. We need to save: */
#ifndef __ASSEMBLY__
struct xcptcontext
{
/* The following function pointer is non-zero if there are pending signals
* to be processed.
*/
void *sigdeliver; /* Actual type is sig_deliver_t */
/* These are saved copies of LR and SR used during signal processing.
*
* REVISIT: Because there is only one copy of these save areas,
* only a single signal handler can be active. This precludes
* queuing of signal actions. As a result, signals received while
* another signal handler is executing will be ignored!
*/
uint32_t saved_pc;
uint32_t saved_sr;
/* Register save area */
uint32_t regs[XCPTCONTEXT_REGS];
};
#endif
/****************************************************************************
* Public Data
****************************************************************************/
#ifndef __ASSEMBLY__
#ifdef __cplusplus
#define EXTERN extern "C"
extern "C"
{
#else
#define EXTERN extern
#endif
/****************************************************************************
* Inline Functions
****************************************************************************/
#ifndef __ASSEMBLY__
/* Get the current value of the SR */
static inline irqstate_t __getsr(void)
{
irqstate_t flags;
__asm__ __volatile__ ("stc sr, %0" : "=r" (flags));
return flags;
}
/* Set the new value of the SR */
static inline void __setsr(irqstate_t sr)
{
__asm__ __volatile__ ("ldc %0, sr" : : "r" (sr));
}
/* Return the current value of the stack pointer */
static inline uint32_t up_getsp(void)
{
uint32_t sp;
__asm__ __volatile__
(
"mov r15, %0\n\t"
: "=&z" (sp)
:
: "memory"
);
return sp;
}
/* Return the current interrupt enable state and disable interrupts */
static inline irqstate_t up_irq_save(void)
{
irqstate_t flags = __getsr();
__setsr(flags | 0x000000f0);
return flags;
}
/* Disable interrupts */
static inline void up_irq_disable(void)
{
uint32_t flags = __getsr();
__setsr(flags | 0x000000f0);
}
/* Enable interrupts */
static inline void up_irq_enable(void)
{
uint32_t flags = __getsr();
__setsr(flags & ~0x000000f0);
}
/* Restore saved interrupt state */
static inline void up_irq_restore(irqstate_t flags)
{
if ((flags & 0x000000f0) != 0x000000f0)
{
up_irq_enable();
}
else
{
up_irq_disable();
}
}
#endif
/****************************************************************************
* Public Functions Prototypes
****************************************************************************/
#undef EXTERN
#ifdef __cplusplus
}
#endif
#endif
#endif /* __ARCH_RENESAS_INCLUDE_SH1_IRQ_H */
|
45e752d7642147a9d2be1f230fd73a7fd2382175
|
c8b39acfd4a857dc15ed3375e0d93e75fa3f1f64
|
/Engine/Plugins/Experimental/AlembicImporter/Source/ThirdParty/Alembic/hdf5/tools/h5dump/h5dump_xml.c
|
8ad76e6fc1ee50149e855f130e20a185d1432835
|
[
"MIT",
"LicenseRef-scancode-proprietary-license"
] |
permissive
|
windystrife/UnrealEngine_NVIDIAGameWorks
|
c3c7863083653caf1bc67d3ef104fb4b9f302e2a
|
b50e6338a7c5b26374d66306ebc7807541ff815e
|
refs/heads/4.18-GameWorks
| 2023-03-11T02:50:08.471040
| 2022-01-13T20:50:29
| 2022-01-13T20:50:29
| 124,100,479
| 262
| 179
|
MIT
| 2022-12-16T05:36:38
| 2018-03-06T15:44:09
|
C++
|
UTF-8
|
C
| false
| false
| 179,457
|
c
|
h5dump_xml.c
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
* Copyright by the Board of Trustees of the University of Illinois. *
* All rights reserved. *
* *
* This file is part of HDF5. The full HDF5 copyright notice, including *
* terms governing use, modification, and redistribution, is contained in *
* the files COPYING and Copyright.html. COPYING can be found at the root *
* of the source code distribution tree; Copyright.html can be found at the *
* root level of an installed copy of the electronic HDF5 document set and *
* is linked from the top-level documents page. It can also be found at *
* http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have *
* access to either file, you may request a copy from help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include <stdio.h>
#include <stdlib.h>
#include "H5private.h"
#include "h5tools.h"
#include "h5tools_dump.h"
#include "h5tools_utils.h"
#include "h5tools_ref.h"
#include "h5trav.h"
#include "h5dump_extern.h"
#include "h5dump_xml.h"
const char *xmlnsprefix="hdf5:";
/*
* Alternative formating for data dumped to XML
* In general, the numbers are the same, but separators
* except spaces are not used.
*
* Some of these are not used, as some kinds of data are
* dumped in completely new subroutines.
*
* Some of this formatting may yet need to change.
*
* This table only affects XML output.
*/
static h5tool_format_t xml_dataformat = {
0, /*raw */
"", /*fmt_raw */
"%d", /*fmt_int */
"%u", /*fmt_uint */
"%hhd", /*fmt_schar */
"%u", /*fmt_uchar */
"%d", /*fmt_short */
"%u", /*fmt_ushort */
"%ld", /*fmt_long */
"%lu", /*fmt_ulong */
NULL, /*fmt_llong */
NULL, /*fmt_ullong */
"%g", /*fmt_double */
"%g", /*fmt_float */
0, /*ascii */
0, /*str_locale */
0, /*str_repeat */
"", /*arr_pre */
"", /*arr_sep */
"", /*arr_suf */
1, /*arr_linebreak */
"", /*cmpd_name */
"", /*cmpd_sep */
"", /*cmpd_pre */
"", /*cmpd_suf */
"", /*cmpd_end */
" ", /*vlen_sep */
" ", /*vlen_pre */
"", /*vlen_suf */
"", /*vlen_end */
"%s", /*elmt_fmt */
"", /*elmt_suf1 */
" ", /*elmt_suf2 */
"", /*idx_n_fmt */
"", /*idx_sep */
"", /*idx_fmt */
80, /*line_ncols *//*standard default columns */
0, /*line_per_line */
"", /*line_pre */
"%s", /*line_1st */
"%s", /*line_cont */
"", /*line_suf */
"", /*line_sep */
1, /*line_multi_new */
" ", /*line_indent */
1, /*skip_first */
1, /*obj_hidefileno */
" "H5_PRINTF_HADDR_FMT, /*obj_format */
1, /*dset_hidefileno */
"DATASET %s ", /*dset_format */
"%s", /*dset_blockformat_pre */
"%s", /*dset_ptformat_pre */
"%s", /*dset_ptformat */
0, /*array indices */
0 /*escape non printable characters */
};
/* internal functions */
static int xml_name_to_XID(const char *, char *, int , int );
/* internal functions used by XML option */
static void xml_print_datatype(hid_t, unsigned);
static void xml_print_enum(hid_t);
static int xml_print_refs(hid_t, int);
static int xml_print_strs(hid_t, int);
static char *xml_escape_the_string(const char *, int);
static char *xml_escape_the_name(const char *);
/*-------------------------------------------------------------------------
* Function: xml_dump_all_cb
*
* Purpose: function callback called by H5Literate,
* displays everything in the specified object
*
* Return: Success: SUCCEED
*
* Failure: FAIL
*
* Programmer: Ruey-Hsia Li
*
* Modifications:
* RMcG, November 2000
* Added XML support. Also, optionally checks the op_data argument
*
* PVN, May 2008
* Dump external links
*
*-------------------------------------------------------------------------
*/
static herr_t
xml_dump_all_cb(hid_t group, const char *name, const H5L_info_t *linfo, void H5_ATTR_UNUSED *op_data)
{
hid_t obj;
herr_t ret = SUCCEED;
char *obj_path = NULL; /* Full path of object */
h5tools_str_t buffer; /* string into which to render */
h5tools_context_t ctx; /* print context */
h5tool_format_t *outputformat = &xml_dataformat;
h5tool_format_t string_dataformat;
hsize_t curr_pos = 0; /* total data element position */
/* setup */
HDmemset(&buffer, 0, sizeof(h5tools_str_t));
HDmemset(&ctx, 0, sizeof(ctx));
ctx.indent_level = dump_indent/COL;
ctx.cur_column = dump_indent;
string_dataformat = *outputformat;
if (fp_format) {
string_dataformat.fmt_double = fp_format;
string_dataformat.fmt_float = fp_format;
}
if (h5tools_nCols==0) {
string_dataformat.line_ncols = 65535;
string_dataformat.line_per_line = 1;
}
else
string_dataformat.line_ncols = h5tools_nCols;
string_dataformat.do_escape = display_escape;
outputformat = &string_dataformat;
/* Build the object's path name */
obj_path = (char *)HDmalloc(HDstrlen(prefix) + HDstrlen(name) + 2);
if(!obj_path) {
ret = FAIL;
goto done;
}
HDstrcpy(obj_path, prefix);
HDstrcat(obj_path, "/");
HDstrcat(obj_path, name);
if(linfo->type == H5L_TYPE_HARD) {
H5O_info_t oinfo;
/* Stat the object */
if(H5Oget_info_by_name(group, name, &oinfo, H5P_DEFAULT) < 0) {
error_msg("unable to get object information for \"%s\"\n", name);
h5tools_setstatus(EXIT_FAILURE);
ret = FAIL;
goto done;
} /* end if */
switch(oinfo.type) {
case H5O_TYPE_GROUP:
if((obj = H5Gopen2(group, name, H5P_DEFAULT)) < 0) {
error_msg("unable to dump group \"%s\"\n", name);
h5tools_setstatus(EXIT_FAILURE);
ret = FAIL;
}
else {
char *old_prefix; /* Pointer to previous prefix */
/* Keep copy of prefix before iterating into group */
old_prefix = HDstrdup(prefix);
HDassert(old_prefix);
/* Append group name to prefix */
add_prefix(&prefix, &prefix_len, name);
/* Iterate into group */
dump_function_table->dump_group_function(obj, name);
/* Restore old prefix name */
HDstrcpy(prefix, old_prefix);
HDfree(old_prefix);
/* Close group */
H5Gclose(obj);
}
break;
case H5O_TYPE_DATASET:
if((obj = H5Dopen2(group, name, H5P_DEFAULT)) >= 0) {
if(oinfo.rc > 1 || hit_elink) {
obj_t *found_obj; /* Found object */
found_obj = search_obj(dset_table, oinfo.addr);
if(found_obj == NULL) {
ctx.indent_level++;
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "%s \"%s\" %s",
h5tools_dump_header_format->datasetbegin, name,
h5tools_dump_header_format->datasetblockbegin);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
error_msg("internal error (file %s:line %d)\n", __FILE__, __LINE__);
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
if(HDstrlen(h5tools_dump_header_format->datasetblockend)) {
h5tools_str_append(&buffer, "%s", h5tools_dump_header_format->datasetblockend);
if(HDstrlen(h5tools_dump_header_format->datasetend))
h5tools_str_append(&buffer, " ");
}
if(HDstrlen(h5tools_dump_header_format->datasetend))
h5tools_str_append(&buffer, "%s", h5tools_dump_header_format->datasetend);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
ctx.indent_level--;
h5tools_setstatus(EXIT_FAILURE);
ret = FAIL;
H5Dclose(obj);
goto done;
}
else if(found_obj->displayed) {
/* the XML version */
char *t_obj_path = xml_escape_the_name(obj_path);
char *t_prefix = xml_escape_the_name(HDstrcmp(prefix,"") ? prefix : "/");
char *t_name = xml_escape_the_name(name);
char *t_objname = xml_escape_the_name(found_obj->objname);
char dsetxid[100];
char parentxid[100];
char pointerxid[100];
/* Create OBJ-XIDs for the parent and object */
xml_name_to_XID(obj_path, dsetxid, (int)sizeof(dsetxid), 1);
xml_name_to_XID(prefix, parentxid, (int)sizeof(parentxid), 1);
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sDataset Name=\"%s\" OBJ-XID=\"%s-%d\" "
"H5Path=\"%s\" Parents=\"%s\" "
"H5ParentPaths=\"%s\">",
xmlnsprefix,
t_name, /* Dataset Name */
dsetxid, get_next_xid(), /* OBJ-XID */
t_obj_path, /* H5Path */
parentxid, /* Parents */
t_prefix); /* H5ParentPaths */
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
xml_name_to_XID(found_obj->objname, pointerxid, (int)sizeof(pointerxid), 1);
ctx.indent_level++;
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sDatasetPtr OBJ-XID=\"%s\" H5Path=\"%s\"/>",
xmlnsprefix,
pointerxid,t_objname);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
ctx.indent_level--;
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "</%sDataset>", xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
HDfree(t_name);
HDfree(t_obj_path);
HDfree(t_prefix);
HDfree(t_objname);
H5Dclose(obj);
goto done;
}
else {
found_obj->displayed = TRUE;
}
} /* end if */
dump_function_table->dump_dataset_function(obj, name, NULL);
H5Dclose(obj);
}
else {
error_msg("unable to dump dataset \"%s\"\n", name);
h5tools_setstatus(EXIT_FAILURE);
ret = FAIL;
}
break;
case H5O_TYPE_NAMED_DATATYPE:
if((obj = H5Topen2(group, name, H5P_DEFAULT)) < 0) {
error_msg("unable to dump datatype \"%s\"\n", name);
h5tools_setstatus(EXIT_FAILURE);
ret = FAIL;
}
else {
dump_function_table->dump_named_datatype_function(obj, name);
H5Tclose(obj);
}
break;
case H5O_TYPE_UNKNOWN:
case H5O_TYPE_NTYPES:
default:
error_msg("unknown object \"%s\"\n", name);
h5tools_setstatus(EXIT_FAILURE);
ret = FAIL;
}
} /* end if */
else {
char *targbuf;
switch(linfo->type) {
case H5L_TYPE_SOFT:
targbuf = (char *)HDmalloc(linfo->u.val_size);
HDassert(targbuf);
if(H5Lget_val(group, name, targbuf, linfo->u.val_size, H5P_DEFAULT) < 0) {
error_msg("unable to get link value\n");
h5tools_setstatus(EXIT_FAILURE);
ret = FAIL;
}
else {
/* print the value of a soft link */
/* XML */
char linkxid[100];
char parentxid[100];
char targetxid[100];
char *t_prefix = xml_escape_the_name(HDstrcmp(prefix,"") ? prefix : "/");
char *t_name = xml_escape_the_name(name);
char *t_targbuf = xml_escape_the_name(targbuf);
char *t_obj_path = xml_escape_the_name(obj_path);
char *t_link_path;
int res;
t_link_path = (char *)HDmalloc(HDstrlen(prefix) + linfo->u.val_size + 1);
if(targbuf[0] == '/')
HDstrcpy(t_link_path, targbuf);
else {
HDstrcpy(t_link_path, prefix);
HDstrcat(HDstrcat(t_link_path, "/"), targbuf);
} /* end else */
/* Create OBJ-XIDs for the parent and object */
xml_name_to_XID(t_obj_path, linkxid, (int)sizeof(linkxid), 1);
xml_name_to_XID(prefix, parentxid, (int)sizeof(parentxid), 1);
/* Try to create an OBJ-XID for the object pointed to */
res = xml_name_to_XID(t_link_path, targetxid, (int)sizeof(targetxid), 0);
if (res == 0) {
/* target obj found */
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sSoftLink LinkName=\"%s\" "
"OBJ-XID=\"%s\" "
"H5SourcePath=\"%s\" "
"TargetPath=\"%s\" TargetObj=\"%s\" "
"Parents=\"%s\" H5ParentPaths=\"%s\" />",
xmlnsprefix,
t_name, /* LinkName */
linkxid, /* OBJ-XID */
t_obj_path, /* H5SourcePath */
t_targbuf, /* TargetPath */
targetxid, /* TargetObj */
parentxid, /* Parents */
t_prefix); /* H5ParentPaths */
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
}
else {
/* dangling link -- omit from xml attributes */
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sSoftLink LinkName=\"%s\" "
"OBJ-XID=\"%s\" "
"H5SourcePath=\"%s\" "
"TargetPath=\"%s\" "
"Parents=\"%s\" H5ParentPaths=\"%s\" />",
xmlnsprefix,
t_name, /* LinkName */
linkxid, /* OBJ-XID */
t_obj_path, /* H5SourcePath */
t_targbuf, /* TargetPath */
parentxid, /* Parents */
t_prefix); /* H5ParentPaths */
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
}
HDfree(t_prefix);
HDfree(t_name);
HDfree(t_targbuf);
HDfree(t_obj_path);
HDfree(t_link_path);
}
HDfree(targbuf);
break;
case H5L_TYPE_EXTERNAL:
targbuf = (char *)HDmalloc(linfo->u.val_size);
HDassert(targbuf);
if(H5Lget_val(group, name, targbuf, linfo->u.val_size, H5P_DEFAULT) < 0) {
error_msg("unable to get external link value\n");
h5tools_setstatus(EXIT_FAILURE);
ret = FAIL;
} /* end if */
else {
const char *filename;
const char *targname;
if(H5Lunpack_elink_val(targbuf, linfo->u.val_size, NULL, &filename, &targname) < 0) {
error_msg("unable to unpack external link value\n");
h5tools_setstatus(EXIT_FAILURE);
ret = FAIL;
} /* end if */
else {
char linkxid[100];
char parentxid[100];
char *t_name = xml_escape_the_name(name);
char *t_prefix = xml_escape_the_name(HDstrcmp(prefix,"") ? prefix : "/");
char *t_obj_path = xml_escape_the_name(obj_path);
char *t_filename = xml_escape_the_name(filename);
char *t_targname = xml_escape_the_name(targname);
/* Create OBJ-XIDs for the parent and object */
xml_name_to_XID(t_obj_path, linkxid, (int)sizeof(linkxid), 1);
xml_name_to_XID(prefix, parentxid, (int)sizeof(parentxid), 1);
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sExternalLink LinkName=\"%s\" "
"OBJ-XID=\"%s\" "
"H5SourcePath=\"%s\" "
"TargetFilename=\"%s\" "
"TargetPath=\"%s\" "
"Parents=\"%s\" H5ParentPaths=\"%s\" />",
xmlnsprefix,
t_name, /* LinkName */
linkxid, /* OBJ-XID */
t_obj_path, /* H5SourcePath */
filename, /* TargetFilename */
targname, /* TargetPath*/
parentxid, /* Parents */
t_prefix); /* H5ParentPaths */
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
HDfree(t_prefix);
HDfree(t_name);
HDfree(t_filename);
HDfree(t_targname);
HDfree(t_obj_path);
} /* end else */
} /* end else */
HDfree(targbuf);
break;
case H5L_TYPE_ERROR:
case H5L_TYPE_MAX:
HDassert(0);
/* fall through */
case H5L_TYPE_HARD:
default:
{
char linkxid[100];
char parentxid[100];
char *t_name = xml_escape_the_name(name);
char *t_prefix = xml_escape_the_name(HDstrcmp(prefix,"") ? prefix : "/");
char *t_obj_path = xml_escape_the_name(obj_path);
/* Create OBJ-XIDs for the parent and object */
xml_name_to_XID(t_obj_path, linkxid, (int)sizeof(linkxid), 1);
xml_name_to_XID(prefix, parentxid, (int)sizeof(parentxid), 1);
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sUserDefined LinkName=\"%s\" "
"OBJ-XID=\"%s\" "
"H5SourcePath=\"%s\" "
"LinkClass=\"%d\" "
"Parents=\"%s\" H5ParentPaths=\"%s\" />",
xmlnsprefix,
t_name, /* LinkName */
linkxid, /* OBJ-XID */
t_obj_path, /* H5SourcePath */
linfo->type, /* LinkClass */
parentxid, /* Parents */
t_prefix); /* H5ParentPaths */
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
HDfree(t_prefix);
HDfree(t_name);
HDfree(t_obj_path);
}
break;
} /* end switch */
} /* end else */
done:
h5tools_str_close(&buffer);
if(obj_path)
HDfree(obj_path);
return ret;
}
/*
* create a string suitable for and XML NCNAME. Uses the
* object reference to create the string.
*
* 'gen'; 0 - return null if not found
* 1 - generate a fake entry and return fake id.
*/
int
xml_name_to_XID(const char *str , char *outstr, int outlen, int gen)
{
haddr_t objno; /* Object ID for object at path */
if (outlen < 22) return 1;
objno = ref_path_table_lookup(str);
if (objno == HADDR_UNDEF) {
if (HDstrlen(str) == 0) {
objno = ref_path_table_lookup("/");
if (objno == HADDR_UNDEF) {
if (gen) {
objno = ref_path_table_gen_fake(str);
sprintf(outstr, "xid_"H5_PRINTF_HADDR_FMT, objno);
return 0;
}
else {
return 1;
}
}
}
else {
if (gen) {
objno = ref_path_table_gen_fake(str);
sprintf(outstr, "xid_"H5_PRINTF_HADDR_FMT, objno);
return 0;
}
else {
return 1;
}
}
}
sprintf(outstr, "xid_"H5_PRINTF_HADDR_FMT, objno);
return(0);
}
static const char *quote = """;
static const char *amp = "&";
static const char *lt = "<";
static const char *gt = ">";
static const char *apos = "'";
/*-------------------------------------------------------------------------
* Function: xml_escape_the_name
*
* Purpose: Escape XML reserved chars in a name, so HDF5 strings
* and paths can be correctly read back in XML element.
*
* Return: The revised string.
*
* Programmer: REMcG
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
static char *
xml_escape_the_name(const char *str)
{
size_t extra;
size_t len;
size_t i;
const char *cp;
char *ncp;
char *rcp;
size_t ncp_len;
if (!str)
return NULL;
cp = str;
len = HDstrlen(str);
extra = 0;
for (i = 0; i < len; i++) {
if (*cp == '\"')
extra += (HDstrlen(quote) - 1);
else if (*cp == '\'')
extra += (HDstrlen(apos) - 1);
else if (*cp == '<')
extra += (HDstrlen(lt) - 1);
else if (*cp == '>')
extra += (HDstrlen(gt) - 1);
else if (*cp == '&')
extra += (HDstrlen(amp) - 1);
cp++;
}
if (extra == 0)
return HDstrdup(str);
cp = str;
ncp_len = len + extra + 1;
rcp = ncp = (char *)HDmalloc(ncp_len);
if (!ncp)
return NULL; /* ?? */
for (i = 0; i < len; i++) {
size_t esc_len;
HDassert(ncp_len);
if (*cp == '\'') {
HDstrncpy(ncp, apos, ncp_len);
esc_len = HDstrlen(apos);
}
else if (*cp == '<') {
HDstrncpy(ncp, lt, ncp_len);
esc_len = HDstrlen(lt);
}
else if (*cp == '>') {
HDstrncpy(ncp, gt, ncp_len);
esc_len = HDstrlen(gt);
}
else if (*cp == '\"') {
HDstrncpy(ncp, quote, ncp_len);
esc_len = HDstrlen(quote);
}
else if (*cp == '&') {
HDstrncpy(ncp, amp, ncp_len);
esc_len = HDstrlen(amp);
}
else {
*ncp = *cp;
esc_len = 1;
}
ncp += esc_len;
ncp_len -= esc_len;
cp++;
}
*ncp = '\0';
return rcp;
}
/*-------------------------------------------------------------------------
* Function: xml_escape_the_string
*
* Purpose: Escape XML reserved chars in a string, so HDF5 strings
* and paths can be correctly read back in XML CDATA.
*
* Return: The revised string.
*
* Programmer: REMcG
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
static char *
xml_escape_the_string(const char *str, int slen)
{
size_t extra;
size_t len;
size_t i;
const char *cp;
char *ncp;
char *rcp;
size_t ncp_len;
if (!str)
return NULL;
cp = str;
if (slen < 0)
len = HDstrlen(str);
else
len = slen;
extra = 0;
for (i = 0; i < len; i++) {
if (*cp == '\\')
extra++;
else if (*cp == '\"')
extra++;
else if (*cp == '\'')
extra += (HDstrlen(apos) - 1);
else if (*cp == '<')
extra += (HDstrlen(lt) - 1);
else if (*cp == '>')
extra += (HDstrlen(gt) - 1);
else if (*cp == '&')
extra += (HDstrlen(amp) - 1);
cp++;
}
cp = str;
ncp_len = len + extra + 1;
rcp = ncp = (char *) HDcalloc(ncp_len, sizeof(char));
if (ncp == NULL)
return NULL; /* ?? */
for (i = 0; i < len; i++) {
size_t esc_len;
HDassert(ncp_len);
if (*cp == '\\') {
*ncp++ = '\\';
*ncp = *cp;
esc_len = 1;
}
else if (*cp == '\"') {
*ncp++ = '\\';
*ncp = *cp;
esc_len = 1;
}
else if (*cp == '\'') {
HDstrncpy(ncp, apos, ncp_len);
esc_len = HDstrlen(apos);
}
else if (*cp == '<') {
HDstrncpy(ncp, lt, ncp_len);
esc_len = HDstrlen(lt);
}
else if (*cp == '>') {
HDstrncpy(ncp, gt, ncp_len);
esc_len = HDstrlen(gt);
}
else if (*cp == '&') {
HDstrncpy(ncp, amp, ncp_len);
esc_len = HDstrlen(amp);
}
else {
*ncp = *cp;
esc_len = 1;
}
ncp += esc_len;
ncp_len -= esc_len;
cp++;
}
*ncp = '\0';
return rcp;
}
/**
** XML print functions--these replace some functions in the
** h5tools.c suite.
**/
/*-------------------------------------------------------------------------
* Function: xml_print_datatype
*
* Purpose: Print description of a datatype in XML.
* Note: this is called inside a <DataType> element.
*
* Return: void
*
* Programmer: REMcG
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
static void
xml_print_datatype(hid_t type, unsigned in_group)
{
char *mname;
hid_t mtype;
unsigned nmembers;
unsigned ndims;
unsigned i;
size_t size;
hsize_t dims[H5DUMP_MAX_RANK];
H5T_str_t str_pad;
H5T_cset_t cset;
hid_t super;
H5T_order_t ord;
H5T_sign_t sgn;
size_t sz;
size_t spos;
size_t epos;
size_t esize;
size_t mpos;
size_t msize;
int nmembs;
htri_t is_vlstr=FALSE;
h5tools_str_t buffer; /* string into which to render */
h5tools_context_t ctx; /* print context */
h5tool_format_t *outputformat = &xml_dataformat;
h5tool_format_t string_dataformat;
hsize_t curr_pos = 0; /* total data element position */
/* setup */
HDmemset(&buffer, 0, sizeof(h5tools_str_t));
HDmemset(&ctx, 0, sizeof(ctx));
ctx.indent_level = dump_indent/COL;
ctx.cur_column = dump_indent;
string_dataformat = *outputformat;
if (fp_format) {
string_dataformat.fmt_double = fp_format;
string_dataformat.fmt_float = fp_format;
}
if (h5tools_nCols==0) {
string_dataformat.line_ncols = 65535;
string_dataformat.line_per_line = 1;
}
else
string_dataformat.line_ncols = h5tools_nCols;
string_dataformat.do_escape = display_escape;
outputformat = &string_dataformat;
if(!in_group && H5Tcommitted(type) > 0) {
H5O_info_t oinfo;
obj_t *found_obj; /* Found object */
/* detect a shared datatype, output only once */
H5Oget_info(type, &oinfo);
found_obj = search_obj(type_table, oinfo.addr);
if(found_obj) {
/* This should be defined somewhere else */
/* These 2 cases are handled the same right now, but
probably will have something different eventually */
char * dtxid = (char *)HDmalloc((size_t)100);
xml_name_to_XID(found_obj->objname, dtxid, 100, 1);
if (!found_obj->recorded) {
/* 'anonymous' NDT. Use it's object num.
as it's name. */
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sNamedDataTypePtr OBJ-XID=\"/%s\"/>",
xmlnsprefix, dtxid);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
}
else {
/* point to the NDT by name */
char *t_objname = xml_escape_the_name(found_obj->objname);
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sNamedDataTypePtr OBJ-XID=\"%s\" H5Path=\"%s\"/>",
xmlnsprefix, dtxid, t_objname);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
HDfree(t_objname);
}
HDfree(dtxid);
}
else {
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<!-- h5dump error: unknown committed type. -->");
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
h5tools_setstatus(EXIT_FAILURE);
}
}
else {
switch (H5Tget_class(type)) {
case H5T_INTEGER:
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sAtomicType>",xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
ctx.indent_level++;
/* <hdf5:IntegerType ByteOrder="bo" Sign="torf" Size="bytes"/> */
ord = H5Tget_order(type);
sgn = H5Tget_sign(type);
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sIntegerType ByteOrder=\"",xmlnsprefix);
switch (ord) {
case H5T_ORDER_LE:
h5tools_str_append(&buffer, "LE");
break;
case H5T_ORDER_BE:
h5tools_str_append(&buffer, "BE");
break;
case H5T_ORDER_VAX:
case H5T_ORDER_MIXED:
case H5T_ORDER_NONE:
case H5T_ORDER_ERROR:
default:
h5tools_str_append(&buffer, "ERROR_UNKNOWN");
break;
} /* end switch */
h5tools_str_append(&buffer, "\" Sign=\"");
switch (sgn) {
case H5T_SGN_NONE:
h5tools_str_append(&buffer, "false");
break;
case H5T_SGN_2:
h5tools_str_append(&buffer, "true");
break;
case H5T_SGN_ERROR:
case H5T_NSGN:
default:
h5tools_str_append(&buffer, "ERROR_UNKNOWN");
break;
} /* end switch */
h5tools_str_append(&buffer, "\" Size=\"");
sz = H5Tget_size(type);
h5tools_str_append(&buffer, "%lu", (unsigned long)sz);
h5tools_str_append(&buffer, "\" />");
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
ctx.indent_level--;
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "</%sAtomicType>",xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
break;
case H5T_FLOAT:
/* <hdf5:FloatType ByteOrder="bo" Size="bytes"
SignBitLocation="bytes"
ExponentBits="eb" ExponentLocation="el"
MantissaBits="mb" MantissaLocation="ml" /> */
ord = H5Tget_order(type);
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sAtomicType>",xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
ctx.indent_level++;
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sFloatType ByteOrder=\"",xmlnsprefix);
switch (ord) {
case H5T_ORDER_LE:
h5tools_str_append(&buffer, "LE");
break;
case H5T_ORDER_BE:
h5tools_str_append(&buffer, "BE");
break;
case H5T_ORDER_VAX:
h5tools_str_append(&buffer, "VAX");
break;
case H5T_ORDER_MIXED:
case H5T_ORDER_NONE:
case H5T_ORDER_ERROR:
default:
h5tools_str_append(&buffer, "ERROR_UNKNOWN");
} /* end switch */
h5tools_str_append(&buffer, "\" Size=\"");
sz = H5Tget_size(type);
h5tools_str_append(&buffer, "%lu", (unsigned long)sz);
H5Tget_fields(type, &spos, &epos, &esize, &mpos, &msize);
h5tools_str_append(&buffer, "\" SignBitLocation=\"%lu\" ", (unsigned long)spos);
h5tools_str_append(&buffer, "ExponentBits=\"%lu\" ExponentLocation=\"%lu\" ", (unsigned long)esize, (unsigned long)epos);
h5tools_str_append(&buffer, "MantissaBits=\"%lu\" MantissaLocation=\"%lu\" />", (unsigned long)msize, (unsigned long)mpos);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
ctx.indent_level--;
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "</%sAtomicType>",xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
break;
case H5T_TIME:
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sAtomicType>",xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
ctx.indent_level++;
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sTimeType />",xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
h5tools_str_append(&buffer, "<!-- H5T_TIME: not yet implemented -->");
ctx.indent_level--;
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "</%sAtomicType>",xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
break;
case H5T_STRING:
/* <hdf5:StringType Cset="cs" StrSize="chars" StrPad="pad" /> */
size = H5Tget_size(type);
str_pad = H5Tget_strpad(type);
cset = H5Tget_cset(type);
is_vlstr = H5Tis_variable_str(type);
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sAtomicType>",xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
ctx.indent_level++;
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sStringType Cset=\"",xmlnsprefix);
if (cset == H5T_CSET_ASCII) {
h5tools_str_append(&buffer, "H5T_CSET_ASCII\" ");
}
else {
h5tools_str_append(&buffer, "unknown_cset\" ");
}
if(is_vlstr)
h5tools_str_append(&buffer, "StrSize=\"H5T_VARIABLE\" StrPad=\"");
else
h5tools_str_append(&buffer, "StrSize=\"%d\" StrPad=\"", (int) size);
if (str_pad == H5T_STR_NULLTERM) {
h5tools_str_append(&buffer, "H5T_STR_NULLTERM\"/>");
}
else if (str_pad == H5T_STR_NULLPAD) {
h5tools_str_append(&buffer, "H5T_STR_NULLPAD\"/>");
}
else if (str_pad == H5T_STR_SPACEPAD) {
h5tools_str_append(&buffer, "H5T_STR_SPACEPAD\"/>");
}
else {
h5tools_str_append(&buffer, "H5T_STR_ERROR\"/>");
}
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
ctx.indent_level--;
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "</%sAtomicType>",xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
break;
case H5T_BITFIELD:
/* <hdf5:BitfieldType ByteOrder="bo" Size="bytes"/> */
ord = H5Tget_order(type);
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sAtomicType>",xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
ctx.indent_level++;
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sBitfieldType ByteOrder=\"",xmlnsprefix);
switch (ord) {
case H5T_ORDER_LE:
h5tools_str_append(&buffer, "LE");
break;
case H5T_ORDER_BE:
h5tools_str_append(&buffer, "BE");
break;
case H5T_ORDER_VAX:
case H5T_ORDER_MIXED:
case H5T_ORDER_NONE:
case H5T_ORDER_ERROR:
default:
h5tools_str_append(&buffer, "ERROR_UNKNOWN");
} /* end switch */
size = H5Tget_size(type);
h5tools_str_append(&buffer, "\" Size=\"%lu\"/>", (unsigned long)size);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
ctx.indent_level--;
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "</%sAtomicType>",xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
break;
case H5T_OPAQUE:
/* <hdf5:OpaqueType Tag="tag" Size="bytes" /> */
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sAtomicType>",xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
ctx.indent_level++;
mname = H5Tget_tag(type);
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sOpaqueType Tag=\"%s\" ",xmlnsprefix, mname);
H5free_memory(mname);
size = H5Tget_size(type);
h5tools_str_append(&buffer, "Size=\"%lu\"/>", (unsigned long)size);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
ctx.indent_level--;
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "</%sAtomicType>",xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
break;
case H5T_COMPOUND:
/* recursively describe the components of a compound datatype */
/* type of a dataset */
nmembers = H5Tget_nmembers(type);
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sCompoundType>",xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
/* List each member Field of the type */
/* <hdf5:Field FieldName="name" > */
/* <hdf5:DataType > */
ctx.indent_level++;
dump_indent += COL;
for (i = 0; i < nmembers; i++) {
char *t_fname;
mname = H5Tget_member_name(type, i);
mtype = H5Tget_member_type(type, i);
t_fname = xml_escape_the_name(mname);
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sField FieldName=\"%s\">",xmlnsprefix, t_fname);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
H5free_memory(mname);
HDfree(t_fname);
dump_indent += COL;
ctx.indent_level++;
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sDataType>",xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
ctx.indent_level++;
dump_indent += COL;
xml_print_datatype(mtype,0);
dump_indent -= COL;
ctx.indent_level--;
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "</%sDataType>",xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
dump_indent -= COL;
ctx.indent_level--;
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "</%sField>",xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
}
dump_indent -= COL;
ctx.indent_level--;
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "</%sCompoundType>",xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
break;
case H5T_REFERENCE:
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sAtomicType>",xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
ctx.indent_level++;
/* Only Object references supported at this time */
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sReferenceType>",xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
ctx.indent_level++;
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sObjectReferenceType />",xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
ctx.indent_level--;
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "</%sReferenceType>",xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
ctx.indent_level--;
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "</%sAtomicType>",xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
break;
case H5T_ENUM:
/* <hdf5:EnumType Nelems="ne" > list Name, values of enum */
nmembs = H5Tget_nmembers(type);
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sAtomicType>",xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
dump_indent += COL;
ctx.indent_level++;
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sEnumType Nelems=\"%d\">",xmlnsprefix, nmembs);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
xml_print_enum(type);
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "</%sEnumType>",xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
dump_indent -= COL;
ctx.indent_level--;
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "</%sAtomicType>",xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
break;
case H5T_VLEN:
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sVLType>",xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
super = H5Tget_super(type);
dump_indent += COL;
ctx.indent_level++;
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sDataType>",xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
dump_indent += COL;
ctx.indent_level++;
xml_print_datatype(super,0);
dump_indent -= COL;
ctx.indent_level--;
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "</%sDataType>",xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
dump_indent -= COL;
ctx.indent_level--;
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "</%sVLType>",xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
H5Tclose(super);
break;
case H5T_ARRAY:
/* Get array base type */
super = H5Tget_super(type);
/* Print lead-in */
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sArrayType Ndims=\"",xmlnsprefix);
ndims = H5Tget_array_ndims(type);
h5tools_str_append(&buffer, "%u\">", ndims);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
/* Get array information */
H5Tget_array_dims2(type, dims);
/* list of dimensions */
ctx.indent_level++;
for (i = 0; i < ndims; i++) {
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sArrayDimension DimSize=\"%u\"/>", xmlnsprefix, (int) dims[i]);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
}
ctx.indent_level--;
dump_indent += COL;
ctx.indent_level++;
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sDataType>",xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
dump_indent += COL;
ctx.indent_level++;
xml_print_datatype(super,0);
dump_indent -= COL;
ctx.indent_level--;
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "</%sDataType>",xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
dump_indent -= COL;
ctx.indent_level--;
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "</%sArrayType>",xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
/* Close array base type */
H5Tclose(super);
break;
case H5T_NO_CLASS:
case H5T_NCLASSES:
HDassert(0);
/* fall through */
default:
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<!-- unknown datatype -->");
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
h5tools_setstatus(EXIT_FAILURE);
break;
}
} /* end else */
h5tools_str_close(&buffer);
}
/*-------------------------------------------------------------------------
* Function: xml_dump_datatype
*
* Purpose: Dump description of a datatype in XML.
*
* Return: void
*
* Programmer: REMcG
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
void
xml_dump_datatype(hid_t type)
{
h5tools_str_t buffer; /* string into which to render */
h5tools_context_t ctx; /* print context */
h5tool_format_t *outputformat = &xml_dataformat;
h5tool_format_t string_dataformat;
hsize_t curr_pos = 0; /* total data element position */
/* setup */
HDmemset(&buffer, 0, sizeof(h5tools_str_t));
HDmemset(&ctx, 0, sizeof(ctx));
ctx.indent_level = dump_indent/COL;
ctx.cur_column = dump_indent;
string_dataformat = *outputformat;
if (fp_format) {
string_dataformat.fmt_double = fp_format;
string_dataformat.fmt_float = fp_format;
}
if (h5tools_nCols==0) {
string_dataformat.line_ncols = 65535;
string_dataformat.line_per_line = 1;
}
else
string_dataformat.line_ncols = h5tools_nCols;
string_dataformat.do_escape = display_escape;
outputformat = &string_dataformat;
ctx.indent_level++;
dump_indent += COL;
if(H5Tcommitted(type) > 0) {
H5O_info_t oinfo;
obj_t *found_obj; /* Found object */
/* Datatype is a shared or named datatype */
H5Oget_info(type, &oinfo);
found_obj = search_obj(type_table, oinfo.addr);
if(found_obj) {
/* Shared datatype, must be entered as an object */
/* These 2 cases are the same now, but may change */
char *dtxid = (char *)HDmalloc((size_t)100);
xml_name_to_XID(found_obj->objname, dtxid, 100, 1);
if (!found_obj->recorded) {
/* anonymous stored datatype:
following the dumper's current
practice:
use it's object ref as its name
*/
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sNamedDataTypePtr OBJ-XID=\"%s\"/>",
xmlnsprefix, dtxid);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
}
else {
/* pointer to a named datatype already in XML */
char *t_objname = xml_escape_the_name(found_obj->objname);
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sNamedDataTypePtr OBJ-XID=\"%s\" H5Path=\"%s\" />",
xmlnsprefix, dtxid, t_objname);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
HDfree(t_objname);
}
HDfree(dtxid);
}
else {
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<!-- h5dump error: unknown committed type. -->");
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
}
}
else {
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sDataType>", xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
ctx.indent_level++;
dump_indent += COL;
xml_print_datatype(type, 0);
ctx.indent_level--;
dump_indent -= COL;
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "</%sDataType>", xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
}
ctx.indent_level--;
dump_indent -= COL;
h5tools_str_close(&buffer);
}
/*-------------------------------------------------------------------------
* Function: xml_dump_dataspace
*
* Purpose: Dump description of a dataspace in XML.
*
* Return: void
*
* Programmer: REMcG
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
void
xml_dump_dataspace(hid_t space)
{
hsize_t size[H5DUMP_MAX_RANK];
hsize_t maxsize[H5DUMP_MAX_RANK];
int i;
h5tools_str_t buffer; /* string into which to render */
h5tools_context_t ctx; /* print context */
h5tool_format_t *outputformat = &xml_dataformat;
h5tool_format_t string_dataformat;
hsize_t curr_pos = 0; /* total data element position */
int ndims = H5Sget_simple_extent_dims(space, size, maxsize);
H5S_class_t space_type = H5Sget_simple_extent_type(space);
/* setup */
HDmemset(&buffer, 0, sizeof(h5tools_str_t));
HDmemset(&ctx, 0, sizeof(ctx));
ctx.indent_level = dump_indent/COL;
ctx.cur_column = dump_indent;
string_dataformat = *outputformat;
if (fp_format) {
string_dataformat.fmt_double = fp_format;
string_dataformat.fmt_float = fp_format;
}
if (h5tools_nCols==0) {
string_dataformat.line_ncols = 65535;
string_dataformat.line_per_line = 1;
}
else
string_dataformat.line_ncols = h5tools_nCols;
string_dataformat.do_escape = display_escape;
outputformat = &string_dataformat;
ctx.indent_level++;
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sDataspace>", xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
ctx.indent_level++;
switch (space_type) {
case H5S_SCALAR:
/* scalar dataspace (just a tag, no XML attrs. defined */
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sScalarDataspace />",xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
break;
case H5S_SIMPLE:
/* simple dataspace */
/* <hdf5:SimpleDataspace Ndims="nd"> */
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sSimpleDataspace Ndims=\"%d\">",xmlnsprefix, ndims);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
/* print the <hdf5:Dimension> elements */
ctx.indent_level++;
for (i = 0; i < ndims; i++) {
if (maxsize[i] == H5S_UNLIMITED) {
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sDimension DimSize=\"%" H5_PRINTF_LL_WIDTH "u\" MaxDimSize=\"UNLIMITED\"/>",
xmlnsprefix,size[i]);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
}
else if (maxsize[i] == (hsize_t) 0) {
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sDimension DimSize=\"%" H5_PRINTF_LL_WIDTH "u\" MaxDimSize=\"%" H5_PRINTF_LL_WIDTH "u\"/>",
xmlnsprefix,size[i], size[i]);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
}
else {
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sDimension DimSize=\"%" H5_PRINTF_LL_WIDTH "u\" MaxDimSize=\"%" H5_PRINTF_LL_WIDTH "u\"/>",
xmlnsprefix, size[i], maxsize[i]);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
}
}
ctx.indent_level--;
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "</%sSimpleDataspace>", xmlnsprefix );
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
break;
#ifdef TMP
/* Commented out: wait until the schema is updated first */
case H5S_NULL:
/* null dataspace (just a tag, no XML attrs. defined */
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sNullDataspace />",xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
break;
#endif /* TMP */
case H5S_NULL:
case H5S_NO_CLASS:
default:
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<!-- unknown dataspace -->");
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
}
ctx.indent_level--;
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "</%sDataspace>", xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
ctx.indent_level--;
h5tools_str_close(&buffer);
}
/*-------------------------------------------------------------------------
* Function: xml_dump_data
*
* Purpose: Dump description of data in XML.
* Note that this calls the h5dump_xxx calls in
* the h5tools library.
*
* Return: void
*
* Programmer: REMcG
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
void
xml_dump_data(hid_t obj_id, int obj_data, struct subset_t H5_ATTR_UNUSED * sset, int H5_ATTR_UNUSED pindex)
{
hid_t space = -1;
hid_t type = -1;
hid_t p_type = -1;
hsize_t size[64];
hsize_t nelmts = 1;
int ndims;
int i;
int status = -1;
void *buf = NULL;
hsize_t curr_pos = 0; /* total data element position */
h5tools_str_t buffer; /* string into which to render */
h5tools_context_t ctx; /* print context */
h5tool_format_t *outputformat = &xml_dataformat;
h5tool_format_t string_dataformat;
HDmemset(&ctx, 0, sizeof(ctx));
ctx.indent_level = dump_indent/COL;
ctx.cur_column = dump_indent;
/* Print all the values. */
/* setup */
HDmemset(&buffer, 0, sizeof(h5tools_str_t));
string_dataformat = *outputformat;
if (fp_format) {
string_dataformat.fmt_double = fp_format;
string_dataformat.fmt_float = fp_format;
}
if (h5tools_nCols==0) {
string_dataformat.line_ncols = 65535;
string_dataformat.line_per_line = 1;
}
else
string_dataformat.line_ncols = h5tools_nCols;
string_dataformat.cmpd_sep = " ";
string_dataformat.cmpd_pre = "";
string_dataformat.cmpd_suf = "";
string_dataformat.cmpd_end = "";
string_dataformat.arr_linebreak = 0;
string_dataformat.arr_pre = "";
outputformat = &string_dataformat;
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sData>", xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
ctx.indent_level++;
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sDataFromFile>", xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
ctx.indent_level--;
dump_indent += COL;
ctx.indent_level++;
if (obj_data == DATASET_DATA) {
type = H5Dget_type(obj_id);
if (H5Tget_class(type) == H5T_REFERENCE) {
status = xml_print_refs(obj_id, DATASET_DATA);
}
else if (H5Tget_class(type) == H5T_STRING) {
status = xml_print_strs(obj_id, DATASET_DATA);
}
else {
h5tools_context_t datactx;
HDmemset(&datactx, 0, sizeof(datactx));
datactx.need_prefix = TRUE;
datactx.indent_level = ctx.indent_level;
datactx.cur_column = ctx.cur_column;
status = h5tools_dump_dset(rawoutstream, outputformat, &datactx, obj_id, NULL);
}
}
else {
/* Attribute data */
type = H5Aget_type(obj_id);
if (H5Tget_class(type) == H5T_REFERENCE) {
/* references are done differently than
the standard output:
XML dumps a path to the object
referenced.
*/
status = xml_print_refs(obj_id, ATTRIBUTE_DATA);
H5Tclose(type);
}
else if (H5Tget_class(type) == H5T_STRING) {
status = xml_print_strs(obj_id, ATTRIBUTE_DATA);
}
else { /* all other data */
/* VL data special information */
unsigned int vl_data = 0; /* contains VL datatypes */
p_type = h5tools_get_native_type(type);
/* Check if we have VL data in the dataset's datatype */
if (h5tools_detect_vlen(p_type) == TRUE)
vl_data = TRUE;
H5Tclose(type);
space = H5Aget_space(obj_id);
ndims = H5Sget_simple_extent_dims(space, size, NULL);
for (i = 0; i < ndims; i++)
nelmts *= size[i];
buf = HDmalloc((size_t)(nelmts * MAX(H5Tget_size(type), H5Tget_size(p_type))));
HDassert(buf);
if (H5Aread(obj_id, p_type, buf) >= 0) {
h5tools_context_t datactx;
HDmemset(&datactx, 0, sizeof(datactx));
datactx.need_prefix = TRUE;
datactx.indent_level = ctx.indent_level;
datactx.cur_column = ctx.cur_column;
status = h5tools_dump_mem(rawoutstream, outputformat, &datactx, obj_id, p_type, space, buf);
}
/* Reclaim any VL memory, if necessary */
if (vl_data)
H5Dvlen_reclaim(p_type, space, H5P_DEFAULT, buf);
HDfree(buf);
H5Tclose(p_type);
H5Sclose(space);
H5Tclose(type);
}
}
if (status == FAIL) {
ctx.indent_level++;
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "Unable to print data.");
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
ctx.indent_level--;
status = 1;
}
ctx.indent_level--;
dump_indent -= COL;
ctx.indent_level++;
ctx.need_prefix = TRUE;
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "</%sDataFromFile>",xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
ctx.indent_level--;
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "</%sData>", xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
h5tools_str_close(&buffer);
}
/*-------------------------------------------------------------------------
* Function: xml_dump_attr
*
* Purpose: Dump a description of an HDF5 attribute in XML.
*
* Return: herr_t
*
* Programmer: REMcG
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
herr_t
xml_dump_attr(hid_t attr, const char *attr_name, const H5A_info_t H5_ATTR_UNUSED *info,
void H5_ATTR_UNUSED * op_data)
{
hid_t attr_id = -1;
hid_t type = -1;
hid_t space = -1;
H5S_class_t space_type;
hsize_t curr_pos = 0; /* total data element position */
h5tools_str_t buffer; /* string into which to render */
h5tools_context_t ctx; /* print context */
h5tool_format_t *outputformat = &xml_dataformat;
h5tool_format_t string_dataformat;
char *t_aname = xml_escape_the_name(attr_name);
/* setup */
HDmemset(&buffer, 0, sizeof(h5tools_str_t));
HDmemset(&ctx, 0, sizeof(ctx));
ctx.indent_level = dump_indent/COL;
ctx.cur_column = dump_indent;
string_dataformat = *outputformat;
if (fp_format) {
string_dataformat.fmt_double = fp_format;
string_dataformat.fmt_float = fp_format;
}
if (h5tools_nCols==0) {
string_dataformat.line_ncols = 65535;
string_dataformat.line_per_line = 1;
}
else
string_dataformat.line_ncols = h5tools_nCols;
string_dataformat.do_escape = display_escape;
outputformat = &string_dataformat;
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sAttribute Name=\"%s\">", xmlnsprefix, t_aname);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
HDfree(t_aname);
if ((attr_id = H5Aopen(attr, attr_name, H5P_DEFAULT)) >= 0) {
type = H5Aget_type(attr_id);
space = H5Aget_space(attr_id);
space_type = H5Sget_simple_extent_type(space);
dump_function_table->dump_dataspace_function(space);
dump_function_table->dump_datatype_function(type);
ctx.indent_level++;
dump_indent += COL;
if (display_attr_data && space_type != H5S_NULL) {
switch (H5Tget_class(type)) {
case H5T_INTEGER:
case H5T_FLOAT:
case H5T_STRING:
case H5T_BITFIELD:
case H5T_OPAQUE:
case H5T_ENUM:
case H5T_ARRAY:
dump_function_table->dump_data_function(attr_id, ATTRIBUTE_DATA, NULL, 0);
break;
case H5T_TIME:
ctx.indent_level++;
dump_indent += COL;
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sData>", xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<!-- Time data not yet implemented. -->");
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sNoData/>", xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<hdf5:Data>");
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "</%sData>", xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
ctx.indent_level--;
dump_indent -= COL;
break;
case H5T_COMPOUND:
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<!-- Note: format of compound data not specified -->");
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
dump_function_table->dump_data_function(attr_id, ATTRIBUTE_DATA, NULL, 0);
break;
case H5T_REFERENCE:
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sData>", xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
if (!H5Tequal(type, H5T_STD_REF_OBJ)) {
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<!-- Note: Region references not supported -->");
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sNoData />", xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
}
else {
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sDataFromFile>", xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
xml_print_refs(attr_id, ATTRIBUTE_DATA);
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "</%sDataFromFile>", xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
}
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "</%sData>", xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
break;
case H5T_VLEN:
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<!-- Note: format of VL data not specified -->");
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
dump_function_table->dump_data_function(attr_id, ATTRIBUTE_DATA, NULL, 0);
break;
case H5T_NO_CLASS:
case H5T_NCLASSES:
HDassert(0);
/* fall through */
default:
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sData>", xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<!-- Unknown datatype: %d -->", H5Tget_class(type));
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sNoData/>", xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "</%sData>", xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
break;
}
}
else {
/* The case of an attribute never yet written ??
* Or dataspace is H5S_NULL. */
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sData>", xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
ctx.indent_level++;
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sNoData/>", xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
ctx.indent_level--;
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "</%sData>", xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
}
ctx.indent_level--;
dump_indent -= COL;
H5Tclose(type);
H5Sclose(space);
H5Aclose(attr_id);
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "</%sAttribute>", xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
h5tools_str_close(&buffer);
return SUCCEED;
}
else {
/* ?? failed */
ctx.indent_level++;
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<!-- h5dump error: unable to open attribute. -->");
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
ctx.indent_level--;
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "</%sAttribute>", xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
h5tools_str_close(&buffer);
h5tools_setstatus(EXIT_FAILURE);
return FAIL;
}
}
/*-------------------------------------------------------------------------
* Function: xml_dump_named_datatype
*
* Purpose: Dump a description of an HDF5 NDT in XML.
*
* Return: herr_t
*
* Programmer: REMcG
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
void
xml_dump_named_datatype(hid_t type, const char *name)
{
hsize_t curr_pos = 0; /* total data element position */
h5tools_str_t buffer; /* string into which to render */
h5tools_context_t ctx; /* print context */
h5tool_format_t *outputformat = &xml_dataformat;
h5tool_format_t string_dataformat;
char *tmp;
char *dtxid;
char *parentxid;
char *t_tmp;
char *t_prefix;
char *t_name;
tmp = (char *)HDmalloc(HDstrlen(prefix) + HDstrlen(name) + 2);
HDstrcpy(tmp, prefix);
HDstrcat(tmp, "/");
HDstrcat(tmp, name);
/* setup */
HDmemset(&buffer, 0, sizeof(h5tools_str_t));
HDmemset(&ctx, 0, sizeof(ctx));
ctx.indent_level = dump_indent/COL;
ctx.cur_column = dump_indent;
string_dataformat = *outputformat;
if (fp_format) {
string_dataformat.fmt_double = fp_format;
string_dataformat.fmt_float = fp_format;
}
if (h5tools_nCols==0) {
string_dataformat.line_ncols = 65535;
string_dataformat.line_per_line = 1;
}
else
string_dataformat.line_ncols = h5tools_nCols;
string_dataformat.do_escape = display_escape;
outputformat = &string_dataformat;
dtxid = (char *)HDmalloc((size_t)100);
parentxid = (char *)HDmalloc((size_t)100);
t_tmp = xml_escape_the_name(tmp);
t_prefix = xml_escape_the_name(prefix);
t_name = xml_escape_the_name(name);
xml_name_to_XID(tmp, dtxid, 100, 1);
xml_name_to_XID(prefix, parentxid, 100, 1);
if(HDstrncmp(name, "#", (size_t)1) == 0) {
/* Special: this is an 'anonymous' NDT, deleted but
still in use.
We follow the dumper's undocumented practice, and
use its object id as its name.
Exactly the same as normal, but a separate case
in the event we want to do something else in
the future.
*/
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sNamedDataType Name=\"%s\" OBJ-XID=\"%s\" "
"Parents=\"%s\" H5ParentPaths=\"%s\">",
xmlnsprefix,
name, dtxid,
parentxid, HDstrcmp(prefix,"") ? t_prefix : "/");
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
}
else {
H5O_info_t oinfo; /* Object info */
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sNamedDataType Name=\"%s\" OBJ-XID=\"%s\" "
"H5Path=\"%s\" Parents=\"%s\" H5ParentPaths=\"%s\">",
xmlnsprefix,
t_name, dtxid,
t_tmp, parentxid, (HDstrcmp(prefix, "") ? t_prefix : "/"));
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
/* Check uniqueness of named datatype */
H5Oget_info(type, &oinfo);
if(oinfo.rc > 1) {
obj_t *found_obj; /* Found object */
/* Group with more than one link to it... */
found_obj = search_obj(type_table, oinfo.addr);
if (found_obj == NULL) {
indentation(dump_indent);
error_msg("internal error (file %s:line %d)\n", __FILE__, __LINE__);
h5tools_setstatus(EXIT_FAILURE);
goto done;
}
else if(found_obj->displayed) {
/* We have already printed this named datatype, print it as a
* NamedDatatypePtr
*/
char pointerxid[100];
char *t_objname = xml_escape_the_name(found_obj->objname);
ctx.indent_level++;
xml_name_to_XID(found_obj->objname, pointerxid, (int)sizeof(pointerxid), 1);
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sNamedDatatypePtr OBJ-XID=\"%s\" H5Path=\"%s\"/>", xmlnsprefix, pointerxid, t_objname);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
ctx.indent_level--;
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "</%sNamedDataType>", xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
HDfree(t_objname);
goto done;
}
else
found_obj->displayed = TRUE;
}
}
ctx.indent_level++;
dump_indent += COL;
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sDataType>",xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
ctx.indent_level++;
dump_indent += COL;
xml_print_datatype(type,1);
ctx.indent_level--;
dump_indent -= COL;
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "</%sDataType>",xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
ctx.indent_level--;
dump_indent -= COL;
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "</%sNamedDataType>",xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
done:
h5tools_str_close(&buffer);
HDfree(dtxid);
HDfree(parentxid);
HDfree(t_tmp);
HDfree(t_prefix);
HDfree(t_name);
HDfree(tmp);
}
/*-------------------------------------------------------------------------
* Function: xml_dump_group
*
* Purpose: Dump a description of an HDF5 Group (and its members) in XML.
*
* Return: void
*
* Programmer: REMcG
*
* Modifications:
* Pedro Vicente, October 9, 2007
* added parameters to H5A(L)iterate to allow for other iteration orders
*
*-------------------------------------------------------------------------
*/
void
xml_dump_group(hid_t gid, const char *name)
{
H5O_info_t oinfo;
hid_t gcpl_id;
hid_t dset, type;
unsigned crt_order_flags;
unsigned attr_crt_order_flags;
int isRoot = 0;
char type_name[1024];
char *t_objname = NULL;
char *par_name = NULL;
char *cp = NULL;
char *tmp = NULL;
char *par = NULL;
h5tools_str_t buffer; /* string into which to render */
h5tools_context_t ctx; /* print context */
h5tool_format_t *outputformat = &xml_dataformat;
h5tool_format_t string_dataformat;
hsize_t curr_pos = 0; /* total data element position */
if ((gcpl_id = H5Gget_create_plist(gid)) < 0) {
error_msg("error in getting group creation property list ID\n");
h5tools_setstatus(EXIT_FAILURE);
}
/* query the group creation properties for attributes */
if (H5Pget_attr_creation_order(gcpl_id, &attr_crt_order_flags) < 0) {
error_msg("error in getting group creation properties\n");
h5tools_setstatus(EXIT_FAILURE);
}
/* query the group creation properties */
if(H5Pget_link_creation_order(gcpl_id, &crt_order_flags) < 0) {
error_msg("error in getting group creation properties\n");
h5tools_setstatus(EXIT_FAILURE);
}
if(H5Pclose(gcpl_id) < 0) {
error_msg("error in closing group creation property list ID\n");
h5tools_setstatus(EXIT_FAILURE);
}
/* setup */
HDmemset(&buffer, 0, sizeof(h5tools_str_t));
HDmemset(&ctx, 0, sizeof(ctx));
ctx.indent_level = dump_indent/COL;
ctx.cur_column = dump_indent;
string_dataformat = *outputformat;
if (fp_format) {
string_dataformat.fmt_double = fp_format;
string_dataformat.fmt_float = fp_format;
}
if (h5tools_nCols==0) {
string_dataformat.line_ncols = 65535;
string_dataformat.line_per_line = 1;
}
else
string_dataformat.line_ncols = h5tools_nCols;
string_dataformat.do_escape = display_escape;
outputformat = &string_dataformat;
if(HDstrcmp(name, "/") == 0) {
isRoot = 1;
tmp = HDstrdup("/");
}
else {
tmp = (char *)HDmalloc(HDstrlen(prefix) + HDstrlen(name) + 2);
HDstrcpy(tmp, prefix);
par = HDstrdup(tmp);
cp = HDstrrchr(par, '/');
if(cp) {
if((cp == par) && HDstrlen(par) > 1)
*(cp + 1) = '\0';
else
*cp = '\0';
}
}
H5Oget_info(gid, &oinfo);
if(oinfo.rc > 1) {
obj_t *found_obj; /* Found object */
/* Group with more than one link to it... */
found_obj = search_obj(group_table, oinfo.addr);
if (found_obj == NULL) {
indentation(dump_indent);
error_msg("internal error (file %s:line %d)\n", __FILE__, __LINE__);
h5tools_setstatus(EXIT_FAILURE);
}
else {
char *t_name = xml_escape_the_name(name);
char *grpxid = (char *)HDmalloc((size_t)100);
char *parentxid = (char *)HDmalloc((size_t)100);
if(found_obj->displayed) {
char *ptrstr = (char *)HDmalloc((size_t)100);
/* already seen: enter a groupptr */
if(isRoot) {
/* probably can't happen! */
xml_name_to_XID("/", grpxid, 100, 1);
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sRootGroup OBJ-XID=\"%s\" H5Path=\"%s\">",
xmlnsprefix, grpxid, "/");
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
}
else {
t_objname = xml_escape_the_name(found_obj->objname);
par_name = xml_escape_the_name(par);
xml_name_to_XID(tmp, grpxid, 100, 1);
xml_name_to_XID(par, parentxid, 100, 1);
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sGroup Name=\"%s\" OBJ-XID=\"%s-%d\" H5Path=\"%s\" "
"Parents=\"%s\" H5ParentPaths=\"%s\">",
xmlnsprefix,t_name, grpxid, get_next_xid(),
t_objname, parentxid, par_name);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
HDfree(t_objname);
HDfree(par_name);
ctx.indent_level++;
t_objname = xml_escape_the_name(found_obj->objname);/* point to the NDT by name */
par_name = xml_escape_the_name(par);
xml_name_to_XID(found_obj->objname, ptrstr, 100, 1);
xml_name_to_XID(par, parentxid, 100, 1);
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sGroupPtr OBJ-XID=\"%s\" H5Path=\"%s\" "
"Parents=\"%s\" H5ParentPaths=\"%s\" />",
xmlnsprefix,
ptrstr, t_objname, parentxid, par_name);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
ctx.indent_level--;
HDfree(t_objname);
HDfree(par_name);
}
HDfree(ptrstr);
}
else {
/* first time this group has been seen -- describe it */
if(isRoot) {
xml_name_to_XID("/", grpxid, 100, 1);
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sRootGroup OBJ-XID=\"%s\" H5Path=\"%s\">",
xmlnsprefix, grpxid, "/");
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
}
else {
char *t_tmp = xml_escape_the_name(tmp);
par_name = xml_escape_the_name(par);
xml_name_to_XID(tmp, grpxid, 100, 1);
xml_name_to_XID(par, parentxid, 100, 1);
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sGroup Name=\"%s\" OBJ-XID=\"%s\" H5Path=\"%s\" "
"Parents=\"%s\" H5ParentPaths=\"%s\" >",
xmlnsprefix,t_name, grpxid, t_tmp, parentxid, par_name);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
HDfree(t_tmp);
HDfree(par_name);
}
found_obj->displayed = TRUE;
/* 1. do all the attributes of the group */
ctx.indent_level++;
dump_indent += COL;
if((sort_by == H5_INDEX_CRT_ORDER) && (attr_crt_order_flags & H5P_CRT_ORDER_TRACKED)) {
if(H5Aiterate2(gid, sort_by, sort_order, NULL, dump_function_table->dump_attribute_function, NULL) < 0) {
error_msg("error getting attribute information\n");
h5tools_setstatus(EXIT_FAILURE);
} /* end if */
} /* end if */
else {
if(H5Aiterate2(gid, H5_INDEX_NAME, sort_order, NULL, dump_function_table->dump_attribute_function, NULL) < 0) {
error_msg("error getting attribute information\n");
h5tools_setstatus(EXIT_FAILURE);
} /* end if */
} /* end else */
if(isRoot && unamedtype) {
unsigned u;
/* Very special case: dump unamed type in root group */
for(u = 0; u < type_table->nobjs; u++) {
if(!type_table->objs[u].recorded) {
dset = H5Dopen2(gid, type_table->objs[u].objname, H5P_DEFAULT);
type = H5Dget_type(dset);
sprintf(type_name, "#"H5_PRINTF_HADDR_FMT, type_table->objs[u].objno);
dump_function_table->dump_named_datatype_function(type, type_name);
H5Tclose(type);
H5Dclose(dset);
}
}
}
/* iterate through all the links */
if((sort_by == H5_INDEX_CRT_ORDER) && (crt_order_flags & H5P_CRT_ORDER_TRACKED))
H5Literate(gid, sort_by, sort_order, NULL, xml_dump_all_cb, NULL);
else
H5Literate(gid, H5_INDEX_NAME, sort_order, NULL, xml_dump_all_cb, NULL);
dump_indent -= COL;
ctx.indent_level--;
}
HDfree(t_name);
HDfree(grpxid);
HDfree(parentxid);
}
}
else {
/* only link -- must be first time! */
char *t_name = xml_escape_the_name(name);
char *grpxid = (char *)HDmalloc((size_t)100);
char *parentxid = (char *)HDmalloc((size_t)100);
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
if(isRoot) {
xml_name_to_XID("/", grpxid, 100, 1);
h5tools_str_append(&buffer, "<%sRootGroup OBJ-XID=\"%s\" H5Path=\"%s\">", xmlnsprefix, grpxid, "/");
}
else {
char *t_tmp = xml_escape_the_name(tmp);
par_name = xml_escape_the_name(par);
xml_name_to_XID(tmp, grpxid, 100, 1);
xml_name_to_XID(par, parentxid, 100, 1);
h5tools_str_append(&buffer, "<%sGroup Name=\"%s\" OBJ-XID=\"%s\" H5Path=\"%s\" "
"Parents=\"%s\" H5ParentPaths=\"%s\" >",
xmlnsprefix, t_name, grpxid, t_tmp, parentxid, par_name);
HDfree(t_tmp);
HDfree(par_name);
}
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
HDfree(t_name);
HDfree(grpxid);
HDfree(parentxid);
/* 1. do all the attributes of the group */
ctx.indent_level++;
dump_indent += COL;
if((sort_by == H5_INDEX_CRT_ORDER) && (attr_crt_order_flags & H5P_CRT_ORDER_TRACKED)) {
if(H5Aiterate2(gid, sort_by, sort_order, NULL, dump_function_table->dump_attribute_function, NULL) < 0) {
error_msg("error getting attribute information\n");
h5tools_setstatus(EXIT_FAILURE);
} /* end if */
} /* end if */
else {
if(H5Aiterate2(gid, H5_INDEX_NAME, sort_order, NULL, dump_function_table->dump_attribute_function, NULL) < 0) {
error_msg("error getting attribute information\n");
h5tools_setstatus(EXIT_FAILURE);
} /* end if */
} /* end else */
if(isRoot && unamedtype) {
unsigned u;
/* Very special case: dump unamed type in root group */
for(u = 0; u < type_table->nobjs; u++) {
if(!type_table->objs[u].recorded) {
dset = H5Dopen2(gid, type_table->objs[u].objname, H5P_DEFAULT);
type = H5Dget_type(dset);
sprintf(type_name, "#"H5_PRINTF_HADDR_FMT, type_table->objs[u].objno);
dump_function_table->dump_named_datatype_function(type, type_name);
H5Tclose(type);
H5Dclose(dset);
}
}
}
/* iterate through all the links */
if((sort_by == H5_INDEX_CRT_ORDER) && (crt_order_flags & H5P_CRT_ORDER_TRACKED))
H5Literate(gid, sort_by, sort_order, NULL, xml_dump_all_cb, NULL);
else
H5Literate(gid, H5_INDEX_NAME, sort_order, NULL, xml_dump_all_cb, NULL);
dump_indent -= COL;
ctx.indent_level--;
}
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
if(isRoot)
h5tools_str_append(&buffer, "</%sRootGroup>", xmlnsprefix);
else
h5tools_str_append(&buffer, "</%sGroup>", xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
h5tools_str_close(&buffer);
if(par)
HDfree(par);
if(tmp)
HDfree(tmp);
}
/*-------------------------------------------------------------------------
* Function: xml_print_refs
*
* Purpose: Print a path to the objects referenced by HDF5 Referneces.
*
* Return: void
*
* Programmer: REMcG
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
static int
xml_print_refs(hid_t did, int source)
{
herr_t e;
hid_t type = -1;
hid_t space = -1;
hssize_t ssiz = -1;
hsize_t i;
size_t tsiz;
hobj_ref_t *refbuf = NULL;
char *buf = NULL;
h5tools_str_t buffer; /* string into which to render */
h5tools_context_t ctx; /* print context */
h5tool_format_t *outputformat = &xml_dataformat;
h5tool_format_t string_dataformat;
hsize_t curr_pos = 0; /* total data element position */
if (source == DATASET_DATA) {
type = H5Dget_type(did);
}
else if (source == ATTRIBUTE_DATA) {
type = H5Aget_type(did);
}
else {
/* return an error */
return FAIL;
}
if (H5Tget_class(type) != H5T_REFERENCE) {
/* return an error */
goto error;
}
if (!H5Tequal(type, H5T_STD_REF_OBJ)) {
/* region ref not supported yet... */
/* return an error */
goto error;
}
if (source == DATASET_DATA) {
space = H5Dget_space(did);
if ((ssiz = H5Sget_simple_extent_npoints(space)) < 0)
goto error;
if ((tsiz = H5Tget_size(type)) == 0)
goto error;
buf = (char *) HDcalloc((size_t)(ssiz * tsiz), sizeof(char));
if (buf == NULL)
goto error;
e = H5Dread(did, H5T_STD_REF_OBJ, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf);
/* need to check result here */
if (e < 0) {
goto error;
}
}
else if (source == ATTRIBUTE_DATA) {
space = H5Aget_space(did);
if ((ssiz = H5Sget_simple_extent_npoints(space)) < 0)
goto error;
if ((tsiz = H5Tget_size(type)) == 0)
goto error;
buf = (char *) HDcalloc((size_t)(ssiz * tsiz), sizeof(char));
if (buf == NULL) {
goto error;
}
e = H5Aread(did, H5T_STD_REF_OBJ, buf);
/* need to check the result here */
if (e < 0) {
goto error;
}
}
refbuf = (hobj_ref_t *) buf;
/* setup */
HDmemset(&buffer, 0, sizeof(h5tools_str_t));
HDmemset(&ctx, 0, sizeof(ctx));
ctx.indent_level = dump_indent/COL;
ctx.cur_column = dump_indent;
string_dataformat = *outputformat;
if (fp_format) {
string_dataformat.fmt_double = fp_format;
string_dataformat.fmt_float = fp_format;
}
if (h5tools_nCols==0) {
string_dataformat.line_ncols = 65535;
string_dataformat.line_per_line = 1;
}
else
string_dataformat.line_ncols = h5tools_nCols;
string_dataformat.do_escape = display_escape;
outputformat = &string_dataformat;
for (i = 0; i < (hsize_t)ssiz; i++) {
const char *path = lookup_ref_path(*refbuf);
ctx.indent_level++;
if (!path) {
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "\"%s\"", "NULL");
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
}
else {
char *t_path = xml_escape_the_string(path, -1);
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "\"%s\"", t_path);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
HDfree(t_path);
}
ctx.indent_level--;
refbuf++;
}
h5tools_str_close(&buffer);
HDfree(buf);
H5Tclose(type);
H5Sclose(space);
return SUCCEED;
error:
if(buf)
HDfree(buf);
H5E_BEGIN_TRY {
H5Tclose(type);
H5Sclose(space);
} H5E_END_TRY;
return FAIL;
}
/*-------------------------------------------------------------------------
* Function: xml_print_strs
*
* Purpose: Print strings.
*
* Return: void
*
* Programmer: REMcG
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
static int
xml_print_strs(hid_t did, int source)
{
herr_t e;
hid_t type = -1;
hid_t space = -1;
hssize_t ssiz = -1;
htri_t is_vlstr = FALSE;
size_t tsiz = 0;
size_t i;
size_t str_size = 0;
char *bp = NULL;
char *onestring = NULL;
void *buf = NULL;
h5tools_str_t buffer; /* string into which to render */
h5tools_context_t ctx; /* print context */
h5tool_format_t *outputformat = &xml_dataformat;
h5tool_format_t string_dataformat;
hsize_t curr_pos = 0; /* total data element position */
if (source == DATASET_DATA) {
type = H5Dget_type(did);
}
else if (source == ATTRIBUTE_DATA) {
type = H5Aget_type(did);
}
else {
/* return an error */
return FAIL;
}
if (H5Tget_class(type) != H5T_STRING) {
/* return an error */
goto error;
}
/* Check if we have VL data in the dataset's datatype */
is_vlstr = H5Tis_variable_str(type);
if (source == DATASET_DATA) {
space = H5Dget_space(did);
if((ssiz = H5Sget_simple_extent_npoints(space)) < 0)
goto error;
if((tsiz = H5Tget_size(type)) == 0)
goto error;
buf = HDmalloc((size_t)(ssiz * tsiz));
if (buf == NULL)
goto error;
e = H5Dread(did, type, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf);
if (e < 0) {
goto error;
}
}
else if (source == ATTRIBUTE_DATA) {
space = H5Aget_space(did);
if((ssiz = H5Sget_simple_extent_npoints(space)) < 0)
goto error;
if((tsiz = H5Tget_size(type)) == 0)
goto error;
buf = HDmalloc((size_t)(ssiz * tsiz));
if (buf == NULL)
goto error;
e = H5Aread(did, type, buf);
if (e < 0) {
goto error;
}
}
bp = (char*) buf;
if (!is_vlstr)
onestring = (char *) HDcalloc(tsiz, sizeof(char));
/* setup */
HDmemset(&buffer, 0, sizeof(h5tools_str_t));
HDmemset(&ctx, 0, sizeof(ctx));
ctx.indent_level = dump_indent/COL;
ctx.cur_column = dump_indent;
string_dataformat = *outputformat;
if (fp_format) {
string_dataformat.fmt_double = fp_format;
string_dataformat.fmt_float = fp_format;
}
if (h5tools_nCols==0) {
string_dataformat.line_ncols = 65535;
string_dataformat.line_per_line = 1;
}
else
string_dataformat.line_ncols = h5tools_nCols;
string_dataformat.do_escape = display_escape;
outputformat = &string_dataformat;
for (i = 0; i < ssiz; i++) {
if (is_vlstr) {
onestring = *(char **) bp;
if (onestring)
str_size = (size_t) HDstrlen(onestring);
}
else {
HDstrncpy(onestring, bp, tsiz);
str_size = tsiz;
}
if (!onestring) {
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "NULL");
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
}
else {
char *t_onestring = xml_escape_the_string(onestring, (int) str_size);
if (t_onestring) {
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "\"%s\"", t_onestring);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
HDfree(t_onestring);
}
}
bp += tsiz;
}
h5tools_str_close(&buffer);
/* Reclaim any VL memory, if necessary */
if (!is_vlstr)
if (onestring)
HDfree(onestring);
if (buf) {
if (is_vlstr)
H5Dvlen_reclaim(type, space, H5P_DEFAULT, buf);
HDfree(buf);
}
H5Tclose(type);
H5Sclose(space);
return SUCCEED;
error:
if(buf)
HDfree(buf);
H5E_BEGIN_TRY {
H5Tclose(type);
H5Sclose(space);
} H5E_END_TRY;
return FAIL;
}
/*-------------------------------------------------------------------------
* Function: check_filters
*
* Purpose: private function to check for the filters and
* put tags in the XML.
*
* Return: void
*
* Programmer: REMcG
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
static void
check_filters(hid_t dcpl)
{
int nfilt;
int i;
H5Z_filter_t filter;
char namebuf[120];
size_t cd_nelmts = 20;
unsigned int cd_values[20];
unsigned int flags;
h5tools_str_t buffer; /* string into which to render */
h5tools_context_t ctx; /* print context */
h5tool_format_t *outputformat = &xml_dataformat;
h5tool_format_t string_dataformat;
hsize_t curr_pos = 0; /* total data element position */
/* setup */
HDmemset(&buffer, 0, sizeof(h5tools_str_t));
HDmemset(&ctx, 0, sizeof(ctx));
ctx.indent_level = dump_indent/COL;
ctx.cur_column = dump_indent;
string_dataformat = *outputformat;
if (fp_format) {
string_dataformat.fmt_double = fp_format;
string_dataformat.fmt_float = fp_format;
}
if (h5tools_nCols==0) {
string_dataformat.line_ncols = 65535;
string_dataformat.line_per_line = 1;
}
else
string_dataformat.line_ncols = h5tools_nCols;
string_dataformat.do_escape = display_escape;
outputformat = &string_dataformat;
nfilt = H5Pget_nfilters(dcpl);
if (nfilt <= 0)
return;
for (i = 0; i < nfilt; i++) {
filter = H5Pget_filter2(dcpl, (unsigned) i, &flags, (size_t *) &cd_nelmts, cd_values, (size_t)120, namebuf, NULL);
if (filter == H5Z_FILTER_DEFLATE) {
ctx.indent_level++;
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sDeflate Level=\"", xmlnsprefix);
if (cd_nelmts < 1) {
/* not sure what this means? */
h5tools_str_append(&buffer, "6");
}
else {
h5tools_str_append(&buffer, "%d", cd_values[0]);
}
h5tools_str_append(&buffer, "\"/>");
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
ctx.indent_level--;
}
else if (filter == H5Z_FILTER_FLETCHER32) {
ctx.indent_level++;
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sFletcher32 />", xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
ctx.indent_level--;
}
else if (filter == H5Z_FILTER_SHUFFLE) {
ctx.indent_level++;
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sShuffle />", xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
ctx.indent_level--;
}
else if (filter == H5Z_FILTER_SZIP) {
ctx.indent_level++;
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sSZIP ", xmlnsprefix);
if (cd_nelmts < 2) {
/* no pixels ? */
h5tools_str_append(&buffer, "Pixels_per_block=\"-1\" ");
}
else {
h5tools_str_append(&buffer, "Pixels_per_block=\"%d\" ", cd_values[1]);
}
/* analyse the options mask */
if (cd_values[0] & H5_SZIP_CHIP_OPTION_MASK) {
h5tools_str_append(&buffer, "Mode =\"Hardware\" ");
}
else if (cd_values[0] & H5_SZIP_ALLOW_K13_OPTION_MASK) {
h5tools_str_append(&buffer, "Mode =\"K13\" ");
}
h5tools_str_append(&buffer, "Coding=\"");
if (cd_values[0] & H5_SZIP_EC_OPTION_MASK) {
h5tools_str_append(&buffer, "Entropy");
}
else if (cd_values[0] & H5_SZIP_NN_OPTION_MASK) {
h5tools_str_append(&buffer, "NN");
}
h5tools_str_append(&buffer, "\" ");
h5tools_str_append(&buffer, "ByteOrder=\"");
if (cd_values[0] & H5_SZIP_LSB_OPTION_MASK) {
h5tools_str_append(&buffer, "LSB");
}
else if (cd_values[0] & H5_SZIP_MSB_OPTION_MASK) {
h5tools_str_append(&buffer, "MSB");
}
h5tools_str_append(&buffer, "\" ");
if (cd_values[0] & H5_SZIP_RAW_OPTION_MASK) {
h5tools_str_append(&buffer, "Header=\"Raw\"");
}
h5tools_str_append(&buffer, "/>");
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
ctx.indent_level--;
}
else {
/* unknown option */
}
}
h5tools_str_close(&buffer);
}
static void
xml_dump_fill_value(hid_t dcpl, hid_t type)
{
size_t sz;
size_t i;
hsize_t space;
void *buf;
char *name;
h5tools_str_t buffer; /* string into which to render */
h5tools_context_t ctx; /* print context */
h5tool_format_t *outputformat = &xml_dataformat;
h5tool_format_t string_dataformat;
hsize_t curr_pos = 0; /* total data element position */
/* setup */
HDmemset(&buffer, 0, sizeof(h5tools_str_t));
HDmemset(&ctx, 0, sizeof(ctx));
ctx.indent_level = dump_indent/COL;
ctx.cur_column = dump_indent;
string_dataformat = *outputformat;
if (fp_format) {
string_dataformat.fmt_double = fp_format;
string_dataformat.fmt_float = fp_format;
}
if (h5tools_nCols==0) {
string_dataformat.line_ncols = 65535;
string_dataformat.line_per_line = 1;
}
else
string_dataformat.line_ncols = h5tools_nCols;
string_dataformat.do_escape = display_escape;
outputformat = &string_dataformat;
ctx.indent_level++;
dump_indent += COL;
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sData>", xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
ctx.indent_level++;
dump_indent += COL;
space = H5Tget_size(type);
buf = HDmalloc((size_t) space);
H5Pget_fill_value(dcpl, type, buf);
if (H5Tget_class(type) == H5T_REFERENCE) {
const char * path = lookup_ref_path(*(hobj_ref_t *) buf);
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sDataFromFile>", xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
if (!path) {
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "\"%s\"", "NULL");
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
}
else {
char *t_path = xml_escape_the_string(path, -1);
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "\"%s\"", t_path);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
HDfree(t_path);
}
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "</%sDataFromFile>", xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
}
else if (H5Tget_class(type) == H5T_STRING) {
/* ????? */
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<!-- String fill values not yet implemented. -->");
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sNoData />", xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
}
else {
/* all other data */
switch (H5Tget_class(type)) {
case H5T_INTEGER:
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sDataFromFile>", xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "\"%d\"", *(int *) buf);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "</%sDataFromFile>", xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
break;
case H5T_FLOAT:
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sDataFromFile>", xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "\"%f\"", (double)*(float *)buf);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "</%sDataFromFile>", xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
break;
case H5T_BITFIELD:
case H5T_OPAQUE:
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sDataFromFile>", xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
sz = H5Tget_size(type);
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "\"");
for (i = 0; i < sz; i++) {
h5tools_str_append(&buffer, "%x ", *(unsigned int *) buf);
buf = (char *) buf + sizeof(unsigned int);
}
h5tools_str_append(&buffer, "\"");
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "</%sDataFromFile>", xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
break;
case H5T_ENUM:
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sDataFromFile>", xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
name = H5Tget_member_name(type, *(unsigned *) buf);
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "\"%s\"", name);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
if(name)
H5free_memory(name);
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "</%sDataFromFile>", xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
break;
case H5T_ARRAY:
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<!-- Array fill values not yet implemented. -->");
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sNoData />", xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
break;
case H5T_TIME:
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<!-- Time fill not yet implemented. -->");
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sNoData />", xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
break;
case H5T_COMPOUND:
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<!-- Compound fill not yet implemented. -->");
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sNoData />", xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
break;
case H5T_VLEN:
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<!-- VL fill not yet implemented. -->");
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sNoData />", xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
break;
case H5T_NO_CLASS:
case H5T_NCLASSES:
HDassert(0);
/* fall through */
case H5T_STRING:
case H5T_REFERENCE:
default:
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<!-- Unknown fill datatype: %d -->", H5Tget_class(type));
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sNoData/>", xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
break;
}
}
HDfree(buf);
ctx.indent_level--;
dump_indent -= COL;
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "</%sData>", xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
ctx.indent_level--;
dump_indent -= COL;
h5tools_str_close(&buffer);
}
/*-------------------------------------------------------------------------
* Function: xml_dump_dataset
*
* Purpose: Dump a description of an HDF5 dataset in XML.
*
* Return: void
*
* Programmer: REMcG
*
* Modifications:
* Pedro Vicente, October 9, 2007
* added parameters to H5Aiterate2 to allow for other iteration orders
*
*-------------------------------------------------------------------------
*/
void
xml_dump_dataset(hid_t did, const char *name, struct subset_t H5_ATTR_UNUSED * sset)
{
hid_t type;
hid_t space;
hid_t dcpl;
H5D_fill_value_t fvstatus;
int maxdims;
hsize_t *chsize;
int ndims;
int i;
H5D_alloc_time_t at;
H5D_fill_time_t ft;
hsize_t tempi;
char *tmp;
char *t_name;
char *t_tmp;
char *t_prefix;
unsigned attr_crt_order_flags;
h5tools_str_t buffer; /* string into which to render */
h5tools_context_t ctx; /* print context */
h5tool_format_t *outputformat = &xml_dataformat;
h5tool_format_t string_dataformat;
hsize_t curr_pos = 0; /* total data element position */
char *rstr = (char*) HDmalloc((size_t)100);
char *pstr = (char*) HDmalloc((size_t)100);
tmp = (char*) HDmalloc(HDstrlen(prefix) + HDstrlen(name) + 2);
HDstrcpy(tmp, prefix);
HDstrcat(tmp, "/");
HDstrcat(tmp, name);
/* setup */
HDmemset(&buffer, 0, sizeof(h5tools_str_t));
HDmemset(&ctx, 0, sizeof(ctx));
ctx.indent_level = dump_indent/COL;
ctx.cur_column = dump_indent;
t_name = xml_escape_the_name(name);
t_tmp = xml_escape_the_name(tmp);
t_prefix = xml_escape_the_name(prefix);
string_dataformat = *outputformat;
if (fp_format) {
string_dataformat.fmt_double = fp_format;
string_dataformat.fmt_float = fp_format;
}
if (h5tools_nCols==0) {
string_dataformat.line_ncols = 65535;
string_dataformat.line_per_line = 1;
}
else
string_dataformat.line_ncols = h5tools_nCols;
string_dataformat.do_escape = display_escape;
outputformat = &string_dataformat;
xml_name_to_XID(tmp, rstr, 100, 1);
xml_name_to_XID(prefix, pstr, 100, 1);
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sDataset Name=\"%s\" OBJ-XID=\"%s\" H5Path= \"%s\" Parents=\"%s\" H5ParentPaths=\"%s\">",
xmlnsprefix, t_name, rstr, t_tmp, pstr,
strcmp(prefix, "") ? t_prefix : "/");
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
HDfree(t_name);
HDfree(t_tmp);
HDfree(t_prefix);
HDfree(rstr);
HDfree(pstr);
HDfree(tmp);
dcpl = H5Dget_create_plist(did);
type = H5Dget_type(did);
space = H5Dget_space(did);
/* query the creation properties for attributes */
H5Pget_attr_creation_order(dcpl, &attr_crt_order_flags);
/* Print information about storage layout */
if (H5D_CHUNKED == H5Pget_layout(dcpl)) {
maxdims = H5Sget_simple_extent_ndims(space);
HDassert(maxdims >= 0);
chsize = (hsize_t *)HDmalloc((size_t)maxdims * sizeof(hsize_t));
ctx.indent_level++;
dump_indent += COL;
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sStorageLayout>", xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
ctx.indent_level++;
dump_indent += COL;
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sChunkedLayout ", xmlnsprefix);
ndims = H5Pget_chunk(dcpl, maxdims, chsize);
h5tools_str_append(&buffer, "Ndims=\"%d\">", ndims);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
ctx.indent_level++;
dump_indent += COL;
for (i = 0; i < ndims; i++) {
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sChunkDimension DimSize=\"%" H5_PRINTF_LL_WIDTH "u\" />", xmlnsprefix, chsize[i]);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
}
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sRequiredFilter>", xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
ctx.indent_level++;
dump_indent += COL;
check_filters(dcpl);
ctx.indent_level--;
dump_indent -= COL;
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "</%sRequiredFilter>", xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
ctx.indent_level--;
dump_indent -= COL;
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "</%sChunkedLayout>", xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
ctx.indent_level--;
dump_indent -= COL;
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "</%sStorageLayout>", xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
ctx.indent_level--;
dump_indent -= COL;
HDfree(chsize);
}
else if (H5D_CONTIGUOUS == H5Pget_layout(dcpl)) {
ctx.indent_level++;
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sStorageLayout>", xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
ctx.indent_level++;
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sContiguousLayout/>", xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
ctx.indent_level--;
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "</%sStorageLayout>", xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
ctx.indent_level--;
}
else if (H5D_COMPACT == H5Pget_layout(dcpl)) {
ctx.indent_level++;
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sStorageLayout>", xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
ctx.indent_level++;
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sCompactLayout/>", xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
ctx.indent_level--;
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "</%sStorageLayout>", xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
ctx.indent_level--;
}
/* and check for external.... ?? */
/* fill value */
ctx.indent_level++;
dump_indent += COL;
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sFillValueInfo ", xmlnsprefix);
H5Pget_fill_time(dcpl, &ft);
h5tools_str_append(&buffer, "FillTime=\"");
switch (ft) {
case H5D_FILL_TIME_ALLOC:
h5tools_str_append(&buffer, "FillOnAlloc");
break;
case H5D_FILL_TIME_NEVER:
h5tools_str_append(&buffer, "FillNever");
break;
case H5D_FILL_TIME_IFSET:
h5tools_str_append(&buffer, "FillIfSet");
break;
case H5D_FILL_TIME_ERROR:
HDassert(0);
/* fall through */
default:
h5tools_str_append(&buffer, "?");
break;
} /* end switch */
h5tools_str_append(&buffer, "\" ");
H5Pget_alloc_time(dcpl, &at);
h5tools_str_append(&buffer, "AllocationTime=\"");
switch (at) {
case H5D_ALLOC_TIME_EARLY:
h5tools_str_append(&buffer, "Early");
break;
case H5D_ALLOC_TIME_INCR:
h5tools_str_append(&buffer, "Incremental");
break;
case H5D_ALLOC_TIME_LATE:
h5tools_str_append(&buffer, "Late");
break;
case H5D_ALLOC_TIME_DEFAULT:
case H5D_ALLOC_TIME_ERROR:
HDassert(0);
/* fall through */
default:
h5tools_str_append(&buffer, "?");
break;
} /* end switch */
h5tools_str_append(&buffer, "\"");
h5tools_str_append(&buffer, ">");
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
ctx.indent_level++;
dump_indent += COL;
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sFillValue>", xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
H5Pfill_value_defined(dcpl, &fvstatus);
if (fvstatus == H5D_FILL_VALUE_UNDEFINED || (fvstatus == H5D_FILL_VALUE_DEFAULT && ft == H5D_FILL_TIME_IFSET)) {
ctx.indent_level++;
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sNoFill/>", xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
ctx.indent_level--;
}
else {
xml_dump_fill_value(dcpl, type);
}
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "</%sFillValue>", xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
ctx.indent_level--;
dump_indent -= COL;
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "</%sFillValueInfo>", xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
ctx.indent_level--;
dump_indent -= COL;
dump_function_table->dump_dataspace_function(space);
dump_function_table->dump_datatype_function(type);
ctx.indent_level++;
dump_indent += COL;
if ((sort_by == H5_INDEX_CRT_ORDER) && (attr_crt_order_flags & H5P_CRT_ORDER_TRACKED)) {
if (H5Aiterate2(did, sort_by, sort_order, NULL, dump_function_table->dump_attribute_function, NULL) < 0) {
error_msg("error getting attribute information\n");
h5tools_setstatus(EXIT_FAILURE);
} /* end if */
} /* end if */
else {
if (H5Aiterate2(did, H5_INDEX_NAME, sort_order, NULL, dump_function_table->dump_attribute_function, NULL) < 0) {
error_msg("error getting attribute information\n");
h5tools_setstatus(EXIT_FAILURE);
} /* end if */
} /* end else */
ctx.indent_level--;
dump_indent -= COL;
tempi = H5Dget_storage_size(did);
if (display_data && (tempi > 0)) {
switch (H5Tget_class(type)) {
case H5T_INTEGER:
case H5T_FLOAT:
case H5T_STRING:
case H5T_BITFIELD:
case H5T_OPAQUE:
case H5T_ENUM:
case H5T_ARRAY:
ctx.indent_level++;
dump_indent += COL;
dump_function_table->dump_data_function(did, DATASET_DATA, NULL, 0);
ctx.indent_level--;
dump_indent -= COL;
break;
case H5T_TIME:
ctx.indent_level++;
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sData>", xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<!-- Time data not yet implemented. -->");
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sNoData />", xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sData>", xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
ctx.indent_level--;
break;
case H5T_COMPOUND:
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<!-- Note: format of compound data not specified -->");
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
ctx.indent_level++;
dump_indent += COL;
dump_function_table->dump_data_function(did, DATASET_DATA, NULL, 0);
ctx.indent_level--;
dump_indent -= COL;
break;
case H5T_REFERENCE:
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sData>", xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
if (!H5Tequal(type, H5T_STD_REF_OBJ)) {
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<!-- Note: Region references not supported -->");
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sNoData />", xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
}
else {
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sDataFromFile>", xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
xml_print_refs(did, DATASET_DATA);
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "</%sDataFromFile>", xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
}
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "</%sData>", xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
break;
case H5T_VLEN:
ctx.indent_level--;
dump_indent -= COL;
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<!-- Note: format of VL data not specified -->");
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
ctx.indent_level++;
dump_indent += COL;
ctx.indent_level++;
dump_indent += COL;
dump_function_table->dump_data_function(did, DATASET_DATA, NULL, 0);
ctx.indent_level--;
dump_indent -= COL;
break;
case H5T_NO_CLASS:
case H5T_NCLASSES:
HDassert(0);
/* fall through */
default:
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sData>", xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<!-- Unknown datatype: %d -->", H5Tget_class(type));
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sNoData/>", xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "</%sData>", xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
break;
}
}
else {
/* no data written */
ctx.indent_level++;
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sData>", xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
ctx.indent_level++;
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sNoData/>", xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
ctx.indent_level--;
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "</%sData>", xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
ctx.indent_level--;
}
H5Tclose(type);
H5Sclose(space);
H5Pclose(dcpl);
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "</%sDataset>", xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
h5tools_str_close(&buffer);
}
/*-------------------------------------------------------------------------
* Function: xml_print_enum
*
* Purpose: Print the values of an HDF5 ENUM in XML.
* Very similar to regular DDL output.
*
* Return: void
*
* Programmer: REMcG
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
static void
xml_print_enum(hid_t type)
{
char **name = NULL; /*member names */
unsigned char *value = NULL; /*value array */
unsigned nmembs; /*number of members */
hid_t super; /*enum base integer type */
hid_t native = -1; /*native integer datatype */
size_t dst_size; /*destination value type size */
unsigned i; /*miscellaneous counters */
size_t j;
h5tools_str_t buffer; /* string into which to render */
h5tools_context_t ctx; /* print context */
h5tool_format_t *outputformat = &xml_dataformat;
h5tool_format_t string_dataformat;
hsize_t curr_pos = 0; /* total data element position */
/* setup */
HDmemset(&buffer, 0, sizeof(h5tools_str_t));
HDmemset(&ctx, 0, sizeof(ctx));
ctx.indent_level = dump_indent/COL;
ctx.cur_column = dump_indent;
string_dataformat = *outputformat;
if (fp_format) {
string_dataformat.fmt_double = fp_format;
string_dataformat.fmt_float = fp_format;
}
if (h5tools_nCols==0) {
string_dataformat.line_ncols = 65535;
string_dataformat.line_per_line = 1;
}
else
string_dataformat.line_ncols = h5tools_nCols;
string_dataformat.do_escape = display_escape;
outputformat = &string_dataformat;
nmembs = (unsigned)H5Tget_nmembers(type);
super = H5Tget_super(type);
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sDataType>",xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
xml_print_datatype(super,0);
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "</%sDataType>",xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
/*
* Determine what datatype to use for the native values. To simplify
* things we entertain three possibilities:
* 1. long long -- the largest native signed integer
* 2. unsigned long long -- the largest native unsigned integer
* 3. raw format
*/
if (H5Tget_size(type) <= sizeof(long long)) {
dst_size = sizeof(long long);
if (H5T_SGN_NONE == H5Tget_sign(type)) {
native = H5T_NATIVE_ULLONG;
}
else {
native = H5T_NATIVE_LLONG;
}
}
else {
dst_size = H5Tget_size(type);
}
/* Get the names and raw values of all members */
name = (char **)HDcalloc((size_t)nmembs, sizeof(char *));
value = (unsigned char *)HDcalloc((size_t)nmembs, MAX(H5Tget_size(type), dst_size));
for (i = 0; i < nmembs; i++) {
name[i] = H5Tget_member_name(type, i);
H5Tget_member_value(type, i, value + i * H5Tget_size(type));
}
/* Convert values to native datatype */
if (native > 0)
H5Tconvert(super, native, (size_t)nmembs, value, NULL, H5P_DEFAULT);
/* Sort members by increasing value */
/*not implemented yet */
/* Print members */
ctx.indent_level++;
dump_indent += COL;
for (i = 0; i < nmembs; i++) {
char *t_name = xml_escape_the_name(name[i]);
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sEnumElement>",xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
ctx.indent_level++;
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "%s", t_name);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
HDfree(t_name);
ctx.indent_level--;
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "</%sEnumElement>",xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "<%sEnumValue>",xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
ctx.indent_level++;
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
if (native < 0) {
h5tools_str_append(&buffer, "0x");
for (j = 0; j < dst_size; j++)
h5tools_str_append(&buffer, "%02x", value[i * dst_size + j]);
}
else if (H5T_SGN_NONE == H5Tget_sign(native)) {
h5tools_str_append(&buffer,"%" H5_PRINTF_LL_WIDTH "u", *((unsigned long long *)
((void *) (value + i * dst_size))));
}
else {
h5tools_str_append(&buffer,"%" H5_PRINTF_LL_WIDTH "d",
*((long long *) ((void *) (value + i * dst_size))));
}
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
ctx.indent_level--;
ctx.need_prefix = TRUE;
h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0);
/* Render the element */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, "</%sEnumValue>",xmlnsprefix);
h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0);
}
ctx.indent_level--;
dump_indent -= COL;
h5tools_str_close(&buffer);
/* Release resources */
for (i = 0; i < nmembs; i++)
H5free_memory(name[i]);
HDfree(name);
HDfree(value);
H5Tclose(super);
}
|
fdcca1e04ffbebb514068ab008662245b751f017
|
9e9858f53eef684140d7274987606a44d3077eaa
|
/src/layers/nnom_zero_padding.c
|
2352e614ee427033b23c536459f1a9979877d6e7
|
[
"Apache-2.0"
] |
permissive
|
majianjia/nnom
|
1b8d11bd0d9c9c179ac0a9106879f0af7235c648
|
f5dae9307bf8dd4644210117ff0b2b34b34ac777
|
refs/heads/master
| 2023-08-11T14:23:34.514766
| 2023-05-16T01:52:33
| 2023-05-16T01:52:33
| 166,869,630
| 767
| 216
|
Apache-2.0
| 2023-05-16T01:52:35
| 2019-01-21T19:38:30
|
C
|
UTF-8
|
C
| false
| false
| 2,994
|
c
|
nnom_zero_padding.c
|
/*
* Copyright (c) 2018-2020
* Jianjia Ma
* majianjia@live.com
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2019-07-23 Jianjia Ma The first version
*/
#include <stdint.h>
#include <string.h>
#include <stdbool.h>
#include "nnom.h"
#include "nnom_local.h"
#include "nnom_layers.h"
#include "layers/nnom_zero_padding.h"
nnom_layer_t * zeropadding_s(const nnom_zero_padding_config_t* config)
{
nnom_layer_t *layer = ZeroPadding(config->pad);
if(layer)
layer->config = (void*) config;
return (nnom_layer_t*)layer;
}
// Zero padding layer
nnom_layer_t *ZeroPadding(nnom_border_t pad)
{
nnom_zero_padding_layer_t *layer;
nnom_layer_io_t *in, *out;
// apply a block memory for all the sub handles.
size_t mem_size = sizeof(nnom_zero_padding_layer_t) + sizeof(nnom_layer_io_t) * 2;
layer = nnom_mem(mem_size);
if (layer == NULL)
return NULL;
// distribut the memory to sub handles.
in = (void *)((uint8_t*)layer + sizeof(nnom_zero_padding_layer_t));
out = (void *)((uint8_t*)in + sizeof(nnom_layer_io_t));
// set type in layer parent
layer->super.type = NNOM_ZERO_PADDING;
// set buf state
in->type = NNOM_TENSOR_BUF_TEMP;
out->type = NNOM_TENSOR_BUF_TEMP;
// put in & out on the layer.
layer->super.in = io_init(layer, in);
layer->super.out = io_init(layer, out);
// set run and outshape methods
layer->super.run = zero_padding_run;
layer->super.build = zero_padding_build;
// set parameters
layer->pad = pad;
return (nnom_layer_t*)layer;
}
nnom_status_t zero_padding_build(nnom_layer_t* layer)
{
nnom_zero_padding_layer_t *cl = (nnom_zero_padding_layer_t *)layer;
// get the tensor from last layer's output
layer->in->tensor = layer->in->hook.io->tensor;
// create new tensor for output
layer->out->tensor = new_tensor(NNOM_QTYPE_PER_TENSOR, layer->in->tensor->num_dim, tensor_get_num_channel(layer->in->tensor));
// copy then change later.
tensor_cpy_attr(layer->out->tensor, layer->in->tensor);
// see if the activation will change the q format
if(layer->actail)
layer->out->tensor->q_dec[0] = act_get_dec_bit(layer->actail->type, layer->out->tensor->q_dec[0]);
// output shape
layer->out->tensor->dim[1] = layer->in->tensor->dim[1] + cl->pad.left + cl->pad.right;
layer->out->tensor->dim[0] = layer->in->tensor->dim[0] + cl->pad.top + cl->pad.bottom;
layer->out->tensor->dim[2] = layer->in->tensor->dim[2];
return NN_SUCCESS;
}
nnom_status_t zero_padding_run(nnom_layer_t * layer)
{
nnom_zero_padding_layer_t *cl = (nnom_zero_padding_layer_t*)layer;
#ifdef NNOM_USING_CHW
local_zero_padding_CHW_q7(
#else
local_zero_padding_HWC_q7(
#endif
layer->in->tensor->p_data,
layer->in->tensor->dim[1], layer->in->tensor->dim[0], layer->in->tensor->dim[2],
cl->pad.top,
cl->pad.bottom,
cl->pad.left,
cl->pad.right,
layer->out->tensor->p_data,
layer->out->tensor->dim[1], layer->out->tensor->dim[0]);
return NN_SUCCESS;
}
|
06211d134df9bec02f8d734630f975c2270914e5
|
28d0f8c01599f8f6c711bdde0b59f9c2cd221203
|
/sys/arch/pmax/ibus/ibus_3max.c
|
f46878600e01e3da70bdf2ca8a3adb2950df89f7
|
[] |
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
| 2,620
|
c
|
ibus_3max.c
|
/* $NetBSD: ibus_3max.c,v 1.16 2016/11/16 19:37:06 macallan Exp $ */
/*-
* Copyright (c) 1999 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Tohru Nishimura.
*
* 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: ibus_3max.c,v 1.16 2016/11/16 19:37:06 macallan Exp $");
#include <sys/param.h>
#include <sys/device.h>
#include <sys/systm.h>
#include <dev/tc/tcvar.h>
#include <pmax/ibus/ibusvar.h>
#include <pmax/pmax/kn02.h>
static struct ibus_attach_args kn02sys_devs[] = {
{ "mc146818", SYS_DEV_BOGUS, KV(KN02_SYS_CLOCK), 0 },
{ "dc", SYS_DEV_SCC0, KV(KN02_SYS_DZ), 0 },
};
static int kn02sys_match(device_t, cfdata_t, void *);
static void kn02sys_attach(device_t, device_t, void *);
CFATTACH_DECL_NEW(kn02sys, 0,
kn02sys_match, kn02sys_attach, NULL, NULL);
static int
kn02sys_match(device_t parent, cfdata_t cf, void *aux)
{
struct tc_attach_args *ta = aux;
return (strncmp("KN02SYS ", ta->ta_modname, TC_ROM_LLEN) == 0);
}
static void
kn02sys_attach(device_t parent, device_t self, void *aux)
{
struct ibus_dev_attach_args ida;
ida.ida_busname = "ibus";
ida.ida_devs = kn02sys_devs;
ida.ida_ndevs = __arraycount(kn02sys_devs);
ida.ida_memt = normal_memt;
ibusattach(parent, self, &ida);
}
|
50b7391760c6dab5919f0238ca3e25ff62528590
|
810237086aae7600b9ef87a610aec4777b1bf156
|
/Example/Pods/Headers/Private/SJVideoPlayer/SJFullscreenModeStatusBar.h
|
84dbcaa15102cc91278b448972d0ced8179b022e
|
[
"MIT"
] |
permissive
|
changsanjiang/SJVideoPlayer
|
f63f3156d5ad07ec107b0feb481110222dd45a85
|
bff75e1f7f033edc05e07c333ce3557cb289c95c
|
refs/heads/master
| 2022-12-20T22:47:04.095976
| 2022-12-10T08:57:46
| 2022-12-10T08:57:46
| 100,693,284
| 2,680
| 513
|
MIT
| 2022-11-02T11:04:42
| 2017-08-18T08:56:30
|
Objective-C
|
UTF-8
|
C
| false
| false
| 74
|
h
|
SJFullscreenModeStatusBar.h
|
../../../../../SJVideoPlayer/Common/Implements/SJFullscreenModeStatusBar.h
|
7ab634a7686573c065d266b0251b4d8859c1584e
|
7c857119fe1505b1d80d6e62969661c06dc1a2f4
|
/NetworkPkg/TcpDxe/TcpDriver.h
|
1ac412be6386b2a08a44eefed1c537f5d5e864de
|
[
"BSD-2-Clause"
] |
permissive
|
CloverHackyColor/CloverBootloader
|
7042ca7dd6b513d22be591a295e49071ae1482ee
|
2711170df4f60b2ae5aa20add3e00f35cf57b7e5
|
refs/heads/master
| 2023-08-30T22:14:34.590134
| 2023-08-27T19:14:02
| 2023-08-27T19:14:02
| 205,810,121
| 4,734
| 770
|
BSD-2-Clause
| 2023-09-03T12:41:33
| 2019-09-02T08:22:14
|
C
|
UTF-8
|
C
| false
| false
| 10,115
|
h
|
TcpDriver.h
|
/** @file
The prototype of driver binding and service binding protocol for TCP driver.
Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#ifndef _TCP_DRIVER_H_
#define _TCP_DRIVER_H_
#define TCP_DRIVER_SIGNATURE SIGNATURE_32 ('T', 'C', 'P', 'D')
#define TCP_PORT_KNOWN 1024
#define TCP_PORT_USER_RESERVED 65535
typedef struct _TCP_HEARTBEAT_TIMER {
EFI_EVENT TimerEvent;
INTN RefCnt;
} TCP_HEARTBEAT_TIMER;
typedef struct _TCP_SERVICE_DATA {
UINT32 Signature;
EFI_HANDLE ControllerHandle;
EFI_HANDLE DriverBindingHandle;
UINT8 IpVersion;
IP_IO *IpIo;
EFI_SERVICE_BINDING_PROTOCOL ServiceBinding;
LIST_ENTRY SocketList;
} TCP_SERVICE_DATA;
typedef struct _TCP_PROTO_DATA {
TCP_SERVICE_DATA *TcpService;
TCP_CB *TcpPcb;
} TCP_PROTO_DATA;
#define TCP_SERVICE_FROM_THIS(a) \
CR ( \
(a), \
TCP_SERVICE_DATA, \
ServiceBinding, \
TCP_DRIVER_SIGNATURE \
)
//
// Function prototype for the driver's entry point
//
/**
The entry point for Tcp driver, used to install Tcp driver on the ImageHandle.
@param[in] ImageHandle The firmware allocated handle for this driver image.
@param[in] SystemTable Pointer to the EFI system table.
@retval EFI_SUCCESS The driver loaded.
@retval other The driver did not load.
**/
EFI_STATUS
EFIAPI
TcpDriverEntryPoint (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
);
//
// Function prototypes for the Driver Binding Protocol
//
/**
Test to see if this driver supports ControllerHandle.
@param[in] This Protocol instance pointer.
@param[in] ControllerHandle Handle of the device to test.
@param[in] RemainingDevicePath Optional parameter use to pick a specific
child device to start.
@retval EFI_SUCCESS This driver supports this device.
@retval EFI_ALREADY_STARTED This driver is already running on this device.
@retval other This driver does not support this device.
**/
EFI_STATUS
EFIAPI
Tcp4DriverBindingSupported (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
);
/**
Start this driver on ControllerHandle.
@param[in] This Protocol instance pointer.
@param[in] ControllerHandle Handle of device to bind driver to.
@param[in] RemainingDevicePath Optional parameter use to pick a specific child
device to start.
@retval EFI_SUCCESS The driver was added to ControllerHandle.
@retval EFI_OUT_OF_RESOURCES There are not enough resources to start the
driver.
@retval other The driver cannot be added to ControllerHandle.
**/
EFI_STATUS
EFIAPI
Tcp4DriverBindingStart (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
);
/**
Stop this driver on ControllerHandle.
@param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
@param[in] ControllerHandle A handle to the device being stopped. The handle must
support a bus specific I/O protocol for the driver
to use to stop the device.
@param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.
@param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
if NumberOfChildren is 0.
@retval EFI_SUCCESS The device was stopped.
@retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
**/
EFI_STATUS
EFIAPI
Tcp4DriverBindingStop (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN UINTN NumberOfChildren,
IN EFI_HANDLE *ChildHandleBuffer OPTIONAL
);
/**
Test to see if this driver supports ControllerHandle.
@param[in] This Protocol instance pointer.
@param[in] ControllerHandle Handle of the device to test.
@param[in] RemainingDevicePath Optional parameter use to pick a specific
child device to start.
@retval EFI_SUCCESS This driver supports this device.
@retval EFI_ALREADY_STARTED This driver is already running on this device.
@retval other This driver does not support this device.
**/
EFI_STATUS
EFIAPI
Tcp6DriverBindingSupported (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
);
/**
Start this driver on ControllerHandle.
@param[in] This Protocol instance pointer.
@param[in] ControllerHandle Handle of device to bind driver to.
@param[in] RemainingDevicePath Optional parameter use to pick a specific child
device to start.
@retval EFI_SUCCESS The driver was added to ControllerHandle.
@retval EFI_OUT_OF_RESOURCES There are not enough resources to start the
driver.
@retval other The driver cannot be added to ControllerHandle.
**/
EFI_STATUS
EFIAPI
Tcp6DriverBindingStart (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
);
/**
Stop this driver on ControllerHandle.
@param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
@param[in] ControllerHandle A handle to the device being stopped. The handle must
support a bus specific I/O protocol for the driver
to use to stop the device.
@param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.
@param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
if NumberOfChildren is 0.
@retval EFI_SUCCESS The device was stopped.
@retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
**/
EFI_STATUS
EFIAPI
Tcp6DriverBindingStop (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN UINTN NumberOfChildren,
IN EFI_HANDLE *ChildHandleBuffer OPTIONAL
);
/**
The Callback funtion called after the TCP socket is created.
@param[in] This Pointer to the socket just created.
@param[in] Context The context of the socket.
@retval EFI_SUCCESS This protocol is installed successfully.
@retval other An error occured.
**/
EFI_STATUS
TcpCreateSocketCallback (
IN SOCKET *This,
IN VOID *Context
);
/**
The callback function called before the TCP socket is to be destroyed.
@param[in] This The TCP socket to be destroyed.
@param[in] Context The context of the socket.
**/
VOID
TcpDestroySocketCallback (
IN SOCKET *This,
IN VOID *Context
);
//
// Function prototypes for the ServiceBinding Protocol
//
/**
Creates a child handle with a set of TCP services.
The CreateChild() function installs a protocol on ChildHandle.
If ChildHandle is a pointer to NULL, then a new handle is created and returned in ChildHandle.
If ChildHandle is not a pointer to NULL, then the protocol installs on the existing ChildHandle.
@param[in] This Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.
@param[in, out] ChildHandle Pointer to the handle of the child to create.
If it is NULL, then a new handle is created.
If it is a pointer to an existing UEFI handle,
then the protocol is added to the existing UEFI handle.
@retval EFI_SUCCES The protocol was added to ChildHandle.
@retval EFI_INVALID_PARAMETER ChildHandle is NULL.
@retval EFI_OUT_OF_RESOURCES There are not enough resources available to create
the child.
@retval other The child handle was not created.
**/
EFI_STATUS
EFIAPI
TcpServiceBindingCreateChild (
IN EFI_SERVICE_BINDING_PROTOCOL *This,
IN OUT EFI_HANDLE *ChildHandle
);
/**
Destroys a child handle with a set of TCP services.
The DestroyChild() function does the opposite of CreateChild(). It removes a protocol
that was installed by CreateChild() from ChildHandle. If the removed protocol is the
last protocol on ChildHandle, then ChildHandle is destroyed.
@param This Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.
@param ChildHandle Handle of the child to destroy.
@retval EFI_SUCCES The protocol was removed from ChildHandle.
@retval EFI_UNSUPPORTED ChildHandle does not support the protocol that is being removed.
@retval EFI_INVALID_PARAMETER The child handle is NULL.
@retval EFI_ACCESS_DENIED The protocol could not be removed from the ChildHandle
because its services are being used.
@retval other The child handle was not destroyed.
**/
EFI_STATUS
EFIAPI
TcpServiceBindingDestroyChild (
IN EFI_SERVICE_BINDING_PROTOCOL *This,
IN EFI_HANDLE ChildHandle
);
#endif
|
23cb52fd27882f9f26ead6d6db34a5863d833fd3
|
28d0f8c01599f8f6c711bdde0b59f9c2cd221203
|
/sys/arch/mips/include/bus_space_defs.h
|
b752f3344bf1cdb54dd6a4231e0334cf054229f5
|
[] |
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
| 12,112
|
h
|
bus_space_defs.h
|
/* $NetBSD: bus_space_defs.h,v 1.5 2023/03/28 10:54:13 nakayama Exp $ */
/*-
* Copyright (c) 1997, 1998, 2000, 2001 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.
*
* 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.
*/
/*
* Copyright (c) 1996 Carnegie-Mellon University.
* All rights reserved.
*
* Author: Chris G. Demetriou
*
* Permission to use, copy, modify and distribute this software and
* its documentation is hereby granted, provided that both the copyright
* notice and this permission notice appear in all copies of the
* software, derivative works or modified versions, and any portions
* thereof, and that both notices appear in supporting documentation.
*
* CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
* CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
* FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
*
* Carnegie Mellon requests users of this software to return to
*
* Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
* School of Computer Science
* Carnegie Mellon University
* Pittsburgh PA 15213-3890
*
* any improvements or extensions that they make and grant Carnegie the
* rights to redistribute these changes.
*/
#ifndef _MIPS_BUS_SPACE_DEFS_H_
#define _MIPS_BUS_SPACE_DEFS_H_
#include <sys/types.h>
#ifdef _KERNEL
#define __BUS_SPACE_HAS_STREAM_METHODS 1
/*
* Turn on BUS_SPACE_DEBUG if the global DEBUG option is enabled.
*/
#if defined(DEBUG) && !defined(BUS_SPACE_DEBUG)
#define BUS_SPACE_DEBUG
#endif
#ifdef BUS_SPACE_DEBUG
#include <sys/systm.h> /* for printf() prototype */
/*
* Macros for checking the aligned-ness of pointers passed to bus
* space ops. Strict alignment is required by the MIPS architecture,
* and a trap will occur if unaligned access is performed. These
* may aid in the debugging of a broken device driver by displaying
* useful information about the problem.
*/
#define __BUS_SPACE_ALIGNED_ADDRESS(p, t) \
((((u_long)(p)) & (sizeof(t)-1)) == 0)
#define __BUS_SPACE_ADDRESS_SANITY(p, t, d) \
({ \
if (__BUS_SPACE_ALIGNED_ADDRESS((p), t) == 0) { \
printf("%s 0x%lx not aligned to %lu bytes %s:%d\n", \
d, (u_long)(p), (u_long)sizeof(t), \
__FILE__, __LINE__); \
} \
(void) 0; \
})
#define BUS_SPACE_ALIGNED_POINTER(p, t) __BUS_SPACE_ALIGNED_ADDRESS(p, t)
#else
#define __BUS_SPACE_ADDRESS_SANITY(p, t, d) (void) 0
#define BUS_SPACE_ALIGNED_POINTER(p, t) ALIGNED_POINTER(p, t)
#endif /* BUS_SPACE_DEBUG */
#endif /* _KERNEL */
struct mips_bus_space_translation;
/*
* Addresses (in bus space).
*/
#ifdef __mips_n32
typedef int64_t bus_addr_t;
typedef uint64_t bus_size_t;
#define PRIxBUSADDR PRIx64
#define PRIxBUSSIZE PRIx64
#define PRIuBUSSIZE PRIu64
#else
typedef paddr_t bus_addr_t;
typedef psize_t bus_size_t;
#define PRIxBUSADDR PRIxPADDR
#define PRIxBUSSIZE PRIxPSIZE
#define PRIuBUSSIZE PRIuPSIZE
#endif
/*
* Access methods for bus space.
*/
typedef struct mips_bus_space *bus_space_tag_t;
/*
* If we are using the MIPS N32 ABI, allow bus_space_space_t to hold a
* 64-bit quantity which can hold an XKPHYS address.
*/
#if defined(__mips_n32) && defined(_MIPS_PADDR_T_64BIT)
typedef int64_t bus_space_handle_t;
#define PRIxBSH PRIx64
#else
typedef intptr_t bus_space_handle_t;
#define PRIxBSH PRIxPTR
#endif
struct mips_bus_space {
/* cookie */
void *bs_cookie;
/* mapping/unmapping */
int (*bs_map)(void *, bus_addr_t, bus_size_t, int,
bus_space_handle_t *, int);
void (*bs_unmap)(void *, bus_space_handle_t, bus_size_t,
int);
int (*bs_subregion)(void *, bus_space_handle_t, bus_size_t,
bus_size_t, bus_space_handle_t *);
/* MIPS SPECIFIC MAPPING METHOD */
int (*bs_translate)(void *, bus_addr_t, bus_size_t, int,
struct mips_bus_space_translation *);
int (*bs_get_window)(void *, int,
struct mips_bus_space_translation *);
/* allocation/deallocation */
int (*bs_alloc)(void *, bus_addr_t, bus_addr_t,
bus_size_t, bus_size_t, bus_size_t, int,
bus_addr_t *, bus_space_handle_t *);
void (*bs_free)(void *, bus_space_handle_t, bus_size_t);
/* get kernel virtual address */
void * (*bs_vaddr)(void *, bus_space_handle_t);
/* mmap for user */
paddr_t (*bs_mmap)(void *, bus_addr_t, off_t, int, int);
/* barrier */
void (*bs_barrier)(void *, bus_space_handle_t,
bus_size_t, bus_size_t, int);
/* read (single) */
uint8_t (*bs_r_1)(void *, bus_space_handle_t, bus_size_t);
uint16_t (*bs_r_2)(void *, bus_space_handle_t, bus_size_t);
uint32_t (*bs_r_4)(void *, bus_space_handle_t, bus_size_t);
uint64_t (*bs_r_8)(void *, bus_space_handle_t, bus_size_t);
/* read multiple */
void (*bs_rm_1)(void *, bus_space_handle_t, bus_size_t,
uint8_t *, bus_size_t);
void (*bs_rm_2)(void *, bus_space_handle_t, bus_size_t,
uint16_t *, bus_size_t);
void (*bs_rm_4)(void *, bus_space_handle_t, bus_size_t,
uint32_t *, bus_size_t);
void (*bs_rm_8)(void *, bus_space_handle_t, bus_size_t,
uint64_t *, bus_size_t);
/* read region */
void (*bs_rr_1)(void *, bus_space_handle_t, bus_size_t,
uint8_t *, bus_size_t);
void (*bs_rr_2)(void *, bus_space_handle_t, bus_size_t,
uint16_t *, bus_size_t);
void (*bs_rr_4)(void *, bus_space_handle_t, bus_size_t,
uint32_t *, bus_size_t);
void (*bs_rr_8)(void *, bus_space_handle_t, bus_size_t,
uint64_t *, bus_size_t);
/* write (single) */
void (*bs_w_1)(void *, bus_space_handle_t, bus_size_t,
uint8_t);
void (*bs_w_2)(void *, bus_space_handle_t, bus_size_t,
uint16_t);
void (*bs_w_4)(void *, bus_space_handle_t, bus_size_t,
uint32_t);
void (*bs_w_8)(void *, bus_space_handle_t, bus_size_t,
uint64_t);
/* write multiple */
void (*bs_wm_1)(void *, bus_space_handle_t, bus_size_t,
const uint8_t *, bus_size_t);
void (*bs_wm_2)(void *, bus_space_handle_t, bus_size_t,
const uint16_t *, bus_size_t);
void (*bs_wm_4)(void *, bus_space_handle_t, bus_size_t,
const uint32_t *, bus_size_t);
void (*bs_wm_8)(void *, bus_space_handle_t, bus_size_t,
const uint64_t *, bus_size_t);
/* write region */
void (*bs_wr_1)(void *, bus_space_handle_t, bus_size_t,
const uint8_t *, bus_size_t);
void (*bs_wr_2)(void *, bus_space_handle_t, bus_size_t,
const uint16_t *, bus_size_t);
void (*bs_wr_4)(void *, bus_space_handle_t, bus_size_t,
const uint32_t *, bus_size_t);
void (*bs_wr_8)(void *, bus_space_handle_t, bus_size_t,
const uint64_t *, bus_size_t);
/* read (single) stream */
uint8_t (*bs_rs_1)(void *, bus_space_handle_t, bus_size_t);
uint16_t (*bs_rs_2)(void *, bus_space_handle_t, bus_size_t);
uint32_t (*bs_rs_4)(void *, bus_space_handle_t, bus_size_t);
uint64_t (*bs_rs_8)(void *, bus_space_handle_t, bus_size_t);
/* read multiple stream */
void (*bs_rms_1)(void *, bus_space_handle_t, bus_size_t,
uint8_t *, bus_size_t);
void (*bs_rms_2)(void *, bus_space_handle_t, bus_size_t,
uint16_t *, bus_size_t);
void (*bs_rms_4)(void *, bus_space_handle_t, bus_size_t,
uint32_t *, bus_size_t);
void (*bs_rms_8)(void *, bus_space_handle_t, bus_size_t,
uint64_t *, bus_size_t);
/* read region stream */
void (*bs_rrs_1)(void *, bus_space_handle_t, bus_size_t,
uint8_t *, bus_size_t);
void (*bs_rrs_2)(void *, bus_space_handle_t, bus_size_t,
uint16_t *, bus_size_t);
void (*bs_rrs_4)(void *, bus_space_handle_t, bus_size_t,
uint32_t *, bus_size_t);
void (*bs_rrs_8)(void *, bus_space_handle_t, bus_size_t,
uint64_t *, bus_size_t);
/* write (single) stream */
void (*bs_ws_1)(void *, bus_space_handle_t, bus_size_t,
uint8_t);
void (*bs_ws_2)(void *, bus_space_handle_t, bus_size_t,
uint16_t);
void (*bs_ws_4)(void *, bus_space_handle_t, bus_size_t,
uint32_t);
void (*bs_ws_8)(void *, bus_space_handle_t, bus_size_t,
uint64_t);
/* write multiple stream */
void (*bs_wms_1)(void *, bus_space_handle_t, bus_size_t,
const uint8_t *, bus_size_t);
void (*bs_wms_2)(void *, bus_space_handle_t, bus_size_t,
const uint16_t *, bus_size_t);
void (*bs_wms_4)(void *, bus_space_handle_t, bus_size_t,
const uint32_t *, bus_size_t);
void (*bs_wms_8)(void *, bus_space_handle_t, bus_size_t,
const uint64_t *, bus_size_t);
/* write region stream */
void (*bs_wrs_1)(void *, bus_space_handle_t, bus_size_t,
const uint8_t *, bus_size_t);
void (*bs_wrs_2)(void *, bus_space_handle_t, bus_size_t,
const uint16_t *, bus_size_t);
void (*bs_wrs_4)(void *, bus_space_handle_t, bus_size_t,
const uint32_t *, bus_size_t);
void (*bs_wrs_8)(void *, bus_space_handle_t, bus_size_t,
const uint64_t *, bus_size_t);
/* set multiple */
void (*bs_sm_1)(void *, bus_space_handle_t, bus_size_t,
uint8_t, bus_size_t);
void (*bs_sm_2)(void *, bus_space_handle_t, bus_size_t,
uint16_t, bus_size_t);
void (*bs_sm_4)(void *, bus_space_handle_t, bus_size_t,
uint32_t, bus_size_t);
void (*bs_sm_8)(void *, bus_space_handle_t, bus_size_t,
uint64_t, bus_size_t);
/* set region */
void (*bs_sr_1)(void *, bus_space_handle_t, bus_size_t,
uint8_t, bus_size_t);
void (*bs_sr_2)(void *, bus_space_handle_t, bus_size_t,
uint16_t, bus_size_t);
void (*bs_sr_4)(void *, bus_space_handle_t, bus_size_t,
uint32_t, bus_size_t);
void (*bs_sr_8)(void *, bus_space_handle_t, bus_size_t,
uint64_t, bus_size_t);
/* copy */
void (*bs_c_1)(void *, bus_space_handle_t, bus_size_t,
bus_space_handle_t, bus_size_t, bus_size_t);
void (*bs_c_2)(void *, bus_space_handle_t, bus_size_t,
bus_space_handle_t, bus_size_t, bus_size_t);
void (*bs_c_4)(void *, bus_space_handle_t, bus_size_t,
bus_space_handle_t, bus_size_t, bus_size_t);
void (*bs_c_8)(void *, bus_space_handle_t, bus_size_t,
bus_space_handle_t, bus_size_t, bus_size_t);
};
/*
* Translation of an MIPS bus address; INTERNAL USE ONLY.
*/
struct mips_bus_space_translation {
bus_addr_t mbst_bus_start; /* start of bus window */
bus_addr_t mbst_bus_end; /* end of bus window */
paddr_t mbst_sys_start; /* start of sysBus window */
paddr_t mbst_sys_end; /* end of sysBus window */
int mbst_align_stride;/* alignment stride */
int mbst_flags; /* flags; see below */
};
#define BUS_SPACE_MAP_CACHEABLE 0x01
#define BUS_SPACE_MAP_LINEAR 0x02
#define BUS_SPACE_MAP_PREFETCHABLE 0x04
#ifdef _KERNEL
#define BUS_SPACE_BARRIER_READ 0x01
#define BUS_SPACE_BARRIER_WRITE 0x02
#endif /* _KERNEL */
#endif /* _MIPS_BUS_SPACE_DEFS_H_ */
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.